* doc/sdccman.lyx: fixed unmeant removal of spaces
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.4.5 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.5
108 \size footnotesize
109
110 \newline
111 $Date::             $ 
112 \newline
113 $Revision$
114 \end_layout
115
116 \begin_layout Standard
117 \begin_inset Note Note
118 status collapsed
119
120 \begin_layout Standard
121 The above strings enclosed in $ are automatically updated by Subversion
122 \end_layout
123
124 \end_inset
125
126
127 \end_layout
128
129 \begin_layout Standard
130 \begin_inset LatexCommand \tableofcontents{}
131
132 \end_inset
133
134
135 \end_layout
136
137 \begin_layout Chapter
138 Introduction
139 \end_layout
140
141 \begin_layout Section
142 About SDCC
143 \end_layout
144
145 \begin_layout Standard
146
147 \series bold
148 SDCC
149 \series default
150  (
151 \emph on
152 S
153 \emph default
154 mall 
155 \emph on
156 D
157 \emph default
158 evice 
159 \emph on
160 C
161 \emph default
162  
163 \emph on
164 C
165 \emph default
166 ompiler) is free open source, retargettable, optimizing ANSI-C compiler
167  by 
168 \series bold
169 Sandeep Dutta
170 \series default
171  designed for 8 bit Microprocessors.
172  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
173  8051, 8052
174 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
175
176 \end_inset
177
178 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
179  Zilog Z80 based MCUs.
180  It can be retargeted for other microprocessors, support for Microchip PIC,
181  Atmel AVR is under development.
182  The entire source code for the compiler is distributed under GPL.
183  SDCC uses ASXXXX
184 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
185
186 \end_inset
187
188  & ASLINK
189 \begin_inset LatexCommand \index{aslink}
190
191 \end_inset
192
193 , an open source retargetable assembler & linker.
194  SDCC has extensive language extensions suitable for utilizing various microcont
195 rollers and underlying hardware effectively.
196  
197 \newline
198
199 \newline
200 In addition to the MCU specific optimizations SDCC also does a host of
201  standard optimizations like:
202 \end_layout
203
204 \begin_layout Itemize
205 global sub expression elimination, 
206 \end_layout
207
208 \begin_layout Itemize
209 loop optimizations (loop invariant, strength reduction of induction variables
210  and loop reversing), 
211 \end_layout
212
213 \begin_layout Itemize
214 constant folding & propagation, 
215 \end_layout
216
217 \begin_layout Itemize
218 copy propagation, 
219 \end_layout
220
221 \begin_layout Itemize
222 dead code elimination 
223 \end_layout
224
225 \begin_layout Itemize
226 jump tables for 
227 \emph on
228 switch
229 \emph default
230  statements.
231 \end_layout
232
233 \begin_layout Standard
234 For the back-end SDCC uses a global register allocation scheme which should
235  be well suited for other 8 bit MCUs.
236  
237 \newline
238
239 \newline
240 The peep hole optimizer uses a rule based substitution mechanism which
241  is MCU independent.
242  
243 \newline
244
245 \newline
246 Supported data-types are:
247 \end_layout
248
249 \begin_layout Standard
250 \begin_inset Tabular
251 <lyxtabular version="3" rows="8" columns="5">
252 <features>
253 <column alignment="center" valignment="top" leftline="true" width="0">
254 <column alignment="center" valignment="top" leftline="true" width="0">
255 <column alignment="center" valignment="top" leftline="true" width="0">
256 <column alignment="center" valignment="top" leftline="true" width="0">
257 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
258 <row topline="true" bottomline="true">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
260 \begin_inset Text
261
262 \begin_layout Standard
263 type
264 \end_layout
265
266 \end_inset
267 </cell>
268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
269 \begin_inset Text
270
271 \begin_layout Standard
272 width
273 \end_layout
274
275 \end_inset
276 </cell>
277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
278 \begin_inset Text
279
280 \begin_layout Standard
281 default
282 \end_layout
283
284 \end_inset
285 </cell>
286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
287 \begin_inset Text
288
289 \begin_layout Standard
290 signed range
291 \end_layout
292
293 \end_inset
294 </cell>
295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
296 \begin_inset Text
297
298 \begin_layout Standard
299 unsigned range
300 \end_layout
301
302 \end_inset
303 </cell>
304 </row>
305 <row topline="true">
306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
307 \begin_inset Text
308
309 \begin_layout Standard
310 bool
311 \end_layout
312
313 \end_inset
314 </cell>
315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
316 \begin_inset Text
317
318 \begin_layout Standard
319 1 bit
320 \end_layout
321
322 \end_inset
323 </cell>
324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
325 \begin_inset Text
326
327 \begin_layout Standard
328 unsigned
329 \end_layout
330
331 \end_inset
332 </cell>
333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
334 \begin_inset Text
335
336 \begin_layout Standard
337 -
338 \end_layout
339
340 \end_inset
341 </cell>
342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
343 \begin_inset Text
344
345 \begin_layout Standard
346 0, 1
347 \end_layout
348
349 \end_inset
350 </cell>
351 </row>
352 <row topline="true">
353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
354 \begin_inset Text
355
356 \begin_layout Standard
357 char
358 \end_layout
359
360 \end_inset
361 </cell>
362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
363 \begin_inset Text
364
365 \begin_layout Standard
366 8 bits, 1 byte
367 \end_layout
368
369 \end_inset
370 </cell>
371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
372 \begin_inset Text
373
374 \begin_layout Standard
375 signed
376 \end_layout
377
378 \end_inset
379 </cell>
380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
381 \begin_inset Text
382
383 \begin_layout Standard
384 -128, +127
385 \end_layout
386
387 \end_inset
388 </cell>
389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
390 \begin_inset Text
391
392 \begin_layout Standard
393 0, +255
394 \end_layout
395
396 \end_inset
397 </cell>
398 </row>
399 <row topline="true">
400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
401 \begin_inset Text
402
403 \begin_layout Standard
404 short
405 \end_layout
406
407 \end_inset
408 </cell>
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
410 \begin_inset Text
411
412 \begin_layout Standard
413 16 bits, 2 bytes
414 \end_layout
415
416 \end_inset
417 </cell>
418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
419 \begin_inset Text
420
421 \begin_layout Standard
422 signed
423 \end_layout
424
425 \end_inset
426 </cell>
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
428 \begin_inset Text
429
430 \begin_layout Standard
431 -32.768, +32.767
432 \end_layout
433
434 \end_inset
435 </cell>
436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
437 \begin_inset Text
438
439 \begin_layout Standard
440 0, +65.535
441 \end_layout
442
443 \end_inset
444 </cell>
445 </row>
446 <row topline="true">
447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
448 \begin_inset Text
449
450 \begin_layout Standard
451 int
452 \end_layout
453
454 \end_inset
455 </cell>
456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
457 \begin_inset Text
458
459 \begin_layout Standard
460 16 bits, 2 bytes
461 \end_layout
462
463 \end_inset
464 </cell>
465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
466 \begin_inset Text
467
468 \begin_layout Standard
469 signed
470 \end_layout
471
472 \end_inset
473 </cell>
474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
475 \begin_inset Text
476
477 \begin_layout Standard
478 -32.768, +32.767
479 \end_layout
480
481 \end_inset
482 </cell>
483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
484 \begin_inset Text
485
486 \begin_layout Standard
487 0, +65.535
488 \end_layout
489
490 \end_inset
491 </cell>
492 </row>
493 <row topline="true" bottomline="true">
494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
495 \begin_inset Text
496
497 \begin_layout Standard
498 long
499 \end_layout
500
501 \end_inset
502 </cell>
503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
504 \begin_inset Text
505
506 \begin_layout Standard
507 32 bits, 4 bytes
508 \end_layout
509
510 \end_inset
511 </cell>
512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
513 \begin_inset Text
514
515 \begin_layout Standard
516 signed
517 \end_layout
518
519 \end_inset
520 </cell>
521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
522 \begin_inset Text
523
524 \begin_layout Standard
525 -2.147.483.648, +2.147.483.647
526 \end_layout
527
528 \end_inset
529 </cell>
530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
531 \begin_inset Text
532
533 \begin_layout Standard
534 0, +4.294.967.295
535 \end_layout
536
537 \end_inset
538 </cell>
539 </row>
540 <row topline="true" bottomline="true">
541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
542 \begin_inset Text
543
544 \begin_layout Standard
545 float
546 \end_layout
547
548 \end_inset
549 </cell>
550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
551 \begin_inset Text
552
553 \begin_layout Standard
554 4 bytes IEEE 754
555 \end_layout
556
557 \end_inset
558 </cell>
559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
560 \begin_inset Text
561
562 \begin_layout Standard
563 signed
564 \end_layout
565
566 \end_inset
567 </cell>
568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
569 \begin_inset Text
570
571 \begin_layout Standard
572
573 \end_layout
574
575 \end_inset
576 </cell>
577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
578 \begin_inset Text
579
580 \begin_layout Standard
581 1.175494351E-38, 
582 \family roman
583 \series medium
584 \shape up
585 \size normal
586 \emph off
587 \bar no
588 \noun off
589 \color none
590 3.402823466E+38
591 \end_layout
592
593 \end_inset
594 </cell>
595 </row>
596 <row topline="true" bottomline="true">
597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
598 \begin_inset Text
599
600 \begin_layout Standard
601 pointer
602 \end_layout
603
604 \end_inset
605 </cell>
606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
607 \begin_inset Text
608
609 \begin_layout Standard
610 1, 2, 3 or 4 bytes
611 \end_layout
612
613 \end_inset
614 </cell>
615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
616 \begin_inset Text
617
618 \begin_layout Standard
619 generic
620 \end_layout
621
622 \end_inset
623 </cell>
624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
625 \begin_inset Text
626
627 \begin_layout Standard
628
629 \end_layout
630
631 \end_inset
632 </cell>
633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
634 \begin_inset Text
635
636 \begin_layout Standard
637
638 \end_layout
639
640 \end_inset
641 </cell>
642 </row>
643 </lyxtabular>
644
645 \end_inset
646
647
648 \newline
649 The compiler also allows 
650 \emph on
651 inline assembler code
652 \emph default
653  to be embedded anywhere in a function.
654  In addition, routines developed in assembly can also be called.
655 \newline
656
657 \newline
658 SDCC also
659  provides an option (-
660 \begin_inset ERT
661 status collapsed
662
663 \begin_layout Standard
664
665
666 \backslash
667 /
668 \end_layout
669
670 \end_inset
671
672 -cyclomatic) to report the relative complexity of a function.
673  These functions can then be further optimized, or hand coded in assembly
674  if needed.
675  
676 \newline
677
678 \newline
679 SDCC also comes with a companion source level debugger SDCDB.
680  The debugger currently uses ucSim, a free open source simulator for 8051
681  and other micro-controllers.
682 \newline
683
684 \newline
685 The latest SDCC version can be downloaded from
686  
687 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
688
689 \end_inset
690
691 .
692
693 \series bold
694  
695 \series default
696 \emph on
697 Please note: the compiler will probably always be some steps ahead of this
698  documentation
699 \series bold
700 \emph default
701
702 \begin_inset LatexCommand \index{Status of documentation}
703
704 \end_inset
705
706
707 \begin_inset Foot
708 status open
709
710 \begin_layout Standard
711 Obviously this has pros and cons
712 \end_layout
713
714 \end_inset
715
716 .
717 \end_layout
718
719 \begin_layout Section
720 Open Source
721 \end_layout
722
723 \begin_layout Standard
724 All packages used in this compiler system are 
725 \emph on
726 open source
727 \emph default
728  and 
729 \emph on
730 freeware
731 \emph default
732 ; source code for all the sub-packages (pre-processor, assemblers, linkers
733  etc.) is distributed with the package.
734  This documentation is maintained using a free open source word processor
735  (LyX).
736 \newline
737 This program is free software; you can redistribute it and/or modify
738  it under the terms of the GNU General Public License
739 \begin_inset LatexCommand \index{GNU General Public License, GPL}
740
741 \end_inset
742
743  as published by the Free Software Foundation; either version 2, or (at
744  your option) any later version.
745  This program is distributed in the hope that it will be useful, but WITHOUT
746  ANY WARRANTY; without even the implied warranty
747 \begin_inset LatexCommand \index{warranty}
748
749 \end_inset
750
751  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
752  See the GNU General Public License for more details.
753  You should have received a copy of the GNU General Public License along
754  with this program; if not, write to the Free Software Foundation, 59 Temple
755  Place - Suite 330, Boston, MA 02111-1307, USA.
756  In other words, you are welcome to use, share and improve this program.
757  You are forbidden to forbid anyone else to use, share and improve what
758  you give them.
759  Help stamp out software-hoarding! 
760 \end_layout
761
762 \begin_layout Section
763 Typographic conventions
764 \begin_inset LatexCommand \index{Typographic conventions}
765
766 \end_inset
767
768
769 \end_layout
770
771 \begin_layout Standard
772 Throughout this manual, we will use the following convention.
773  Commands you have to type in are printed in 
774 \family sans
775 \series bold
776 "sans serif"
777 \series default
778 .
779
780 \family default
781  Code samples are printed in 
782 \family typewriter
783 typewriter font.
784
785 \family default
786  Interesting items and new terms are printed in 
787 \emph on
788 italic.
789 \end_layout
790
791 \begin_layout Section
792 Compatibility
793 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
794
795 \end_inset
796
797  with previous versions
798 \begin_inset LatexCommand \index{Compatibility with previous versions}
799
800 \end_inset
801
802
803 \end_layout
804
805 \begin_layout Standard
806 Newer versions have usually numerous bug fixes compared with the previous
807  version.
808  But we also sometimes introduce some incompatibilities with older versions.
809  Not just for the fun of it, but to make the compiler more stable, efficient
810  and ANSI compliant
811 \begin_inset LatexCommand \index{ANSI-compliance}
812
813 \end_inset
814
815  (see section 
816 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
817
818 \end_inset
819
820  for ANSI-Compliance).
821  
822 \begin_inset Note Note
823 status collapsed
824
825 \begin_layout Standard
826 It would be fine to add to each item, in which version was it changed.
827 \end_layout
828
829 \end_inset
830
831
832 \newline
833
834 \end_layout
835
836 \begin_layout Itemize
837 short is now equivalent to int (16 bits), it used to be equivalent to char
838  (8 bits) which is not ANSI compliant.
839  To maintain compatibility, old programs may be compiled using the -
840 \begin_inset ERT
841 status collapsed
842
843 \begin_layout Standard
844
845
846 \backslash
847 /
848 \end_layout
849
850 \end_inset
851
852 -short-is-8bits commandline option (see 
853 \begin_inset LatexCommand \vref{lyx:--short-is-8bits}
854
855 \end_inset
856
857 ).
858 \end_layout
859
860 \begin_layout Itemize
861 the default directory for gcc-builds where include, library and documentation
862  files are stored is now in /usr/local/share.
863 \end_layout
864
865 \begin_layout Itemize
866 char type parameters to vararg
867 \begin_inset LatexCommand \index{vararg, va\_arg}
868
869 \end_inset
870
871  functions are casted to int unless explicitly casted
872 \begin_inset Marginal
873 status collapsed
874
875 \begin_layout Standard
876
877 \series bold
878 \InsetSpace ~
879 !
880 \end_layout
881
882 \end_inset
883
884 , e.g.: 
885 \newline
886
887 \family typewriter
888 \InsetSpace ~
889 \InsetSpace ~
890 char a=3;
891 \newline
892 \InsetSpace ~
893 \InsetSpace ~
894 printf ("%d %c
895 \backslash
896 n", a, (char)a);
897 \family default
898
899 \newline
900  will push a as an int and as a char resp.
901 \end_layout
902
903 \begin_layout Itemize
904 option -
905 \begin_inset ERT
906 status collapsed
907
908 \begin_layout Standard
909
910
911 \backslash
912 /
913 \end_layout
914
915 \end_inset
916
917 -regextend has been removed.
918 \end_layout
919
920 \begin_layout Itemize
921 option -
922 \begin_inset ERT
923 status collapsed
924
925 \begin_layout Standard
926
927
928 \backslash
929 /
930 \end_layout
931
932 \end_inset
933
934 -noregparms has been removed.
935 \end_layout
936
937 \begin_layout Itemize
938 option -
939 \begin_inset ERT
940 status collapsed
941
942 \begin_layout Standard
943
944
945 \backslash
946 /
947 \end_layout
948
949 \end_inset
950
951 -stack-after-data has been removed.
952 \end_layout
953
954 \begin_layout Itemize
955 bit
956 \begin_inset LatexCommand \index{bit}
957
958 \end_inset
959
960  and sbit
961 \begin_inset LatexCommand \index{sbit}
962
963 \end_inset
964
965
966 \begin_inset LatexCommand \index{\_\_sbit}
967
968 \end_inset
969
970  types now consistently behave like the C99 _Bool type with respect to type
971  conversion
972 \begin_inset LatexCommand \index{type conversion}
973
974 \end_inset
975
976
977 \begin_inset LatexCommand \index{type promotion}
978
979 \end_inset
980
981 .
982  The most common incompatibility resulting from this change is related to
983  bit toggling
984 \begin_inset LatexCommand \index{Bit toggling}
985
986 \end_inset
987
988  idioms, e.g.:
989 \newline
990
991 \family typewriter
992 \InsetSpace ~
993 \InsetSpace ~
994 bit b;
995 \newline
996 \InsetSpace ~
997 \InsetSpace ~
998 b = ~
999 \begin_inset LatexCommand \index{\~\/ Operator}
1000
1001 \end_inset
1002
1003 b; /* equivalent to b=1 instead of toggling b */
1004 \begin_inset Marginal
1005 status collapsed
1006
1007 \begin_layout Standard
1008
1009 \series bold
1010 \InsetSpace ~
1011 !
1012 \end_layout
1013
1014 \end_inset
1015
1016
1017 \newline
1018 \InsetSpace ~
1019 \InsetSpace ~
1020 b = !b; /* toggles b */
1021 \newline
1022
1023 \family default
1024 In previous versions, both forms would have toggled the bit.
1025 \end_layout
1026
1027 \begin_layout Standard
1028
1029 \emph on
1030 <pending: more incompatibilities?>
1031 \end_layout
1032
1033 \begin_layout Section
1034 System Requirements
1035 \end_layout
1036
1037 \begin_layout Standard
1038 What do you need before you start installation of SDCC? A computer, and
1039  a desire to compute.
1040  The preferred method of installation is to compile SDCC from source using
1041  GNU gcc and make.
1042  For Windows some pre-compiled binary distributions are available for your
1043  convenience.
1044  You should have some experience with command line tools and compiler use.
1045 \end_layout
1046
1047 \begin_layout Section
1048 Other Resources
1049 \end_layout
1050
1051 \begin_layout Standard
1052 The SDCC home page at 
1053 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1054
1055 \end_inset
1056
1057  is a great place to find distribution sets.
1058  You can also find links to the user mailing lists that offer help or discuss
1059  SDCC with other SDCC users.
1060  Web links to other SDCC related sites can also be found here.
1061  This document can be found in the DOC directory of the source package as
1062  a text or HTML file.
1063  A pdf version of this document is available at 
1064 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1065
1066 \end_inset
1067
1068 .
1069  Some of the other tools (simulator and assembler) included with SDCC contain
1070  their own documentation and can be found in the source distribution.
1071  If you want the latest unreleased software, the complete source package
1072  is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1073 sdcc/trunk/sdcc.
1074 \end_layout
1075
1076 \begin_layout Section
1077 Wishes for the future
1078 \end_layout
1079
1080 \begin_layout Standard
1081 There are (and always will be) some things that could be done.
1082  Here are some I can think of:
1083 \newline
1084
1085 \end_layout
1086
1087 \begin_layout Standard
1088
1089 \family typewriter
1090 char KernelFunction3(char p) at 0x340;
1091 \newline
1092
1093 \end_layout
1094
1095 \begin_layout Standard
1096
1097 \family typewriter
1098 better code banking
1099 \begin_inset LatexCommand \index{code banking (limited support)}
1100
1101 \end_inset
1102
1103  support for mcs51
1104 \newline
1105
1106 \newline
1107
1108 \family default
1109 If you can think of some more, please see the section 
1110 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1111
1112 \end_inset
1113
1114  about filing feature requests
1115 \begin_inset LatexCommand \index{Requesting features}
1116
1117 \end_inset
1118
1119
1120 \begin_inset LatexCommand \index{Feature request}
1121
1122 \end_inset
1123
1124 .
1125 \newline
1126
1127 \end_layout
1128
1129 \begin_layout Chapter
1130 Installing SDCC
1131 \begin_inset LatexCommand \index{Installation}
1132
1133 \end_inset
1134
1135
1136 \end_layout
1137
1138 \begin_layout Standard
1139 For most users it is sufficient to skip to either section 
1140 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1141
1142 \end_inset
1143
1144  (Unix) or section 
1145 \begin_inset LatexCommand \ref{sub:Windows-Install}
1146
1147 \end_inset
1148
1149  (Windows).
1150  More detailed instructions follow below.
1151 \end_layout
1152
1153 \begin_layout Section
1154 Configure Options
1155 \begin_inset LatexCommand \index{Options SDCC configuration}
1156
1157 \end_inset
1158
1159
1160 \end_layout
1161
1162 \begin_layout Standard
1163 The install paths, search paths and other options are defined when running
1164  'configure'.
1165  The defaults can be overridden by:
1166 \end_layout
1167
1168 \begin_layout List
1169 \labelwidthstring 00.00.0000
1170 -
1171 \begin_inset ERT
1172 status collapsed
1173
1174 \begin_layout Standard
1175
1176
1177 \backslash
1178 /
1179 \end_layout
1180
1181 \end_inset
1182
1183 -prefix see table below
1184 \end_layout
1185
1186 \begin_layout List
1187 \labelwidthstring 00.00.0000
1188 -
1189 \begin_inset ERT
1190 status collapsed
1191
1192 \begin_layout Standard
1193
1194
1195 \backslash
1196 /
1197 \end_layout
1198
1199 \end_inset
1200
1201 -exec_prefix see table below
1202 \end_layout
1203
1204 \begin_layout List
1205 \labelwidthstring 00.00.0000
1206 -
1207 \begin_inset ERT
1208 status collapsed
1209
1210 \begin_layout Standard
1211
1212
1213 \backslash
1214 /
1215 \end_layout
1216
1217 \end_inset
1218
1219 -bindir see table below
1220 \end_layout
1221
1222 \begin_layout List
1223 \labelwidthstring 00.00.0000
1224 -
1225 \begin_inset ERT
1226 status collapsed
1227
1228 \begin_layout Standard
1229
1230
1231 \backslash
1232 /
1233 \end_layout
1234
1235 \end_inset
1236
1237 -datadir see table below
1238 \end_layout
1239
1240 \begin_layout List
1241 \labelwidthstring 00.00.0000
1242 -
1243 \begin_inset ERT
1244 status collapsed
1245
1246 \begin_layout Standard
1247
1248
1249 \backslash
1250 /
1251 \end_layout
1252
1253 \end_inset
1254
1255 -datarootdir see table below
1256 \newline
1257
1258 \end_layout
1259
1260 \begin_layout List
1261 \labelwidthstring 00.00.0000
1262 \InsetSpace ~
1263 \InsetSpace ~
1264 docdir environment variable, see table below
1265 \end_layout
1266
1267 \begin_layout List
1268 \labelwidthstring 00.00.0000
1269 \InsetSpace ~
1270 \InsetSpace ~
1271 include_dir_suffix environment variable, see table below
1272 \end_layout
1273
1274 \begin_layout List
1275 \labelwidthstring 00.00.0000
1276 \InsetSpace ~
1277 \InsetSpace ~
1278 lib_dir_suffix environment variable, see table below
1279 \end_layout
1280
1281 \begin_layout List
1282 \labelwidthstring 00.00.0000
1283 \InsetSpace ~
1284 \InsetSpace ~
1285 sdccconf_h_dir_separator environment variable, either / or 
1286 \backslash
1287
1288 \backslash
1289  makes sense here.
1290  This character will only be used in sdccconf.h; don't forget it's a C-header,
1291  therefore a double-backslash is needed there.
1292 \newline
1293
1294 \end_layout
1295
1296 \begin_layout List
1297 \labelwidthstring 00.00.0000
1298 -
1299 \begin_inset ERT
1300 status collapsed
1301
1302 \begin_layout Standard
1303
1304
1305 \backslash
1306 /
1307 \end_layout
1308
1309 \end_inset
1310
1311 -disable-mcs51-port Excludes the Intel mcs51 port
1312 \end_layout
1313
1314 \begin_layout List
1315 \labelwidthstring 00.00.0000
1316 -
1317 \begin_inset ERT
1318 status collapsed
1319
1320 \begin_layout Standard
1321
1322
1323 \backslash
1324 /
1325 \end_layout
1326
1327 \end_inset
1328
1329 -disable-gbz80-port Excludes the Gameboy gbz80 port
1330 \end_layout
1331
1332 \begin_layout List
1333 \labelwidthstring 00.00.0000
1334 -
1335 \begin_inset ERT
1336 status collapsed
1337
1338 \begin_layout Standard
1339
1340
1341 \backslash
1342 /
1343 \end_layout
1344
1345 \end_inset
1346
1347 -disable-z80-port Excludes the z80 port
1348 \end_layout
1349
1350 \begin_layout List
1351 \labelwidthstring 00.00.0000
1352 -
1353 \begin_inset ERT
1354 status collapsed
1355
1356 \begin_layout Standard
1357
1358
1359 \backslash
1360 /
1361 \end_layout
1362
1363 \end_inset
1364
1365 -disable-avr-port Excludes the AVR port
1366 \end_layout
1367
1368 \begin_layout List
1369 \labelwidthstring 00.00.0000
1370 -
1371 \begin_inset ERT
1372 status collapsed
1373
1374 \begin_layout Standard
1375
1376
1377 \backslash
1378 /
1379 \end_layout
1380
1381 \end_inset
1382
1383 -disable-ds390-port Excludes the DS390 port
1384 \end_layout
1385
1386 \begin_layout List
1387 \labelwidthstring 00.00.0000
1388 -
1389 \begin_inset ERT
1390 status collapsed
1391
1392 \begin_layout Standard
1393
1394
1395 \backslash
1396 /
1397 \end_layout
1398
1399 \end_inset
1400
1401 -disable-hc08-port Excludes the HC08 port
1402 \end_layout
1403
1404 \begin_layout List
1405 \labelwidthstring 00.00.0000
1406 -
1407 \begin_inset ERT
1408 status collapsed
1409
1410 \begin_layout Standard
1411
1412
1413 \backslash
1414 /
1415 \end_layout
1416
1417 \end_inset
1418
1419 -disable-pic-port Excludes the PIC14 port
1420 \end_layout
1421
1422 \begin_layout List
1423 \labelwidthstring 00.00.0000
1424 -
1425 \begin_inset ERT
1426 status collapsed
1427
1428 \begin_layout Standard
1429
1430
1431 \backslash
1432 /
1433 \end_layout
1434
1435 \end_inset
1436
1437 -disable-pic16-port Excludes the PIC16 port
1438 \end_layout
1439
1440 \begin_layout List
1441 \labelwidthstring 00.00.0000
1442 -
1443 \begin_inset ERT
1444 status collapsed
1445
1446 \begin_layout Standard
1447
1448
1449 \backslash
1450 /
1451 \end_layout
1452
1453 \end_inset
1454
1455 -disable-xa51-port Excludes the XA51 port
1456 \end_layout
1457
1458 \begin_layout List
1459 \labelwidthstring 00.00.0000
1460 -
1461 \begin_inset ERT
1462 status collapsed
1463
1464 \begin_layout Standard
1465
1466
1467 \backslash
1468 /
1469 \end_layout
1470
1471 \end_inset
1472
1473 -disable-ucsim Disables configuring and building of ucsim
1474 \end_layout
1475
1476 \begin_layout List
1477 \labelwidthstring 00.00.0000
1478 -
1479 \begin_inset ERT
1480 status collapsed
1481
1482 \begin_layout Standard
1483
1484
1485 \backslash
1486 /
1487 \end_layout
1488
1489 \end_inset
1490
1491 -disable-device-lib Disables automatically building device libraries
1492 \end_layout
1493
1494 \begin_layout List
1495 \labelwidthstring 00.00.0000
1496 -
1497 \begin_inset ERT
1498 status collapsed
1499
1500 \begin_layout Standard
1501
1502
1503 \backslash
1504 /
1505 \end_layout
1506
1507 \end_inset
1508
1509 -disable-packihx Disables building packihx
1510 \newline
1511
1512 \end_layout
1513
1514 \begin_layout List
1515 \labelwidthstring 00.00.0000
1516 -
1517 \begin_inset ERT
1518 status collapsed
1519
1520 \begin_layout Standard
1521
1522
1523 \backslash
1524 /
1525 \end_layout
1526
1527 \end_inset
1528
1529 -enable-doc Build pdf, html and txt files from the lyx sources
1530 \end_layout
1531
1532 \begin_layout List
1533 \labelwidthstring 00.00.0000
1534 -
1535 \begin_inset ERT
1536 status collapsed
1537
1538 \begin_layout Standard
1539
1540
1541 \backslash
1542 /
1543 \end_layout
1544
1545 \end_inset
1546
1547 -enable-libgc Use the Bohem memory allocator.
1548  Lower runtime footprint.
1549 \end_layout
1550
1551 \begin_layout Standard
1552 Furthermore the environment variables CC, CFLAGS, ...
1553  the tools and their arguments can be influenced.
1554  Please see `configure -
1555 \begin_inset ERT
1556 status collapsed
1557
1558 \begin_layout Standard
1559
1560
1561 \backslash
1562 /
1563 \end_layout
1564
1565 \end_inset
1566
1567 -help' and the man/info pages of `configure' for details.
1568 \newline
1569
1570 \newline
1571 The names of the
1572  standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1573 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1574  SDCC_LIB_NAME are defined by `configure' too.
1575  At the moment it's not possible to change the default settings (it was
1576  simply never required).
1577 \newline
1578
1579 \newline
1580 These configure options are compiled into the binaries,
1581  and can only be changed by rerunning 'configure' and recompiling SDCC.
1582  The configure options are written in 
1583 \emph on
1584 italics
1585 \emph default
1586  to distinguish them from run time environment variables (see section search
1587  paths).
1588 \newline
1589
1590 \newline
1591 The settings for 
1592 \begin_inset Quotes sld
1593 \end_inset
1594
1595 Win32 builds
1596 \begin_inset Quotes srd
1597 \end_inset
1598
1599  are used by the SDCC team to build the official Win32 binaries.
1600  The SDCC team uses Mingw32 to build the official Windows binaries, because
1601  it's
1602 \end_layout
1603
1604 \begin_layout Enumerate
1605 open source, 
1606 \end_layout
1607
1608 \begin_layout Enumerate
1609 a gcc compiler and last but not least
1610 \end_layout
1611
1612 \begin_layout Enumerate
1613 the binaries can be built by cross compiling on SDCC Distributed Compile
1614  Farm.
1615 \end_layout
1616
1617 \begin_layout Standard
1618 See the examples, how to pass the Win32 settings to 'configure'.
1619  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1620  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1621  for Win32.
1622 \newline
1623
1624 \newline
1625 These defaults are:
1626 \newline
1627
1628 \end_layout
1629
1630 \begin_layout Standard
1631 \align center
1632 \begin_inset Tabular
1633 <lyxtabular version="3" rows="9" columns="3">
1634 <features>
1635 <column alignment="block" valignment="top" leftline="true" width="0in">
1636 <column alignment="block" valignment="top" leftline="true" width="0in">
1637 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1638 <row topline="true" bottomline="true">
1639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1640 \begin_inset Text
1641
1642 \begin_layout Standard
1643 Variable
1644 \end_layout
1645
1646 \end_inset
1647 </cell>
1648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1649 \begin_inset Text
1650
1651 \begin_layout Standard
1652 default
1653 \end_layout
1654
1655 \end_inset
1656 </cell>
1657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1658 \begin_inset Text
1659
1660 \begin_layout Standard
1661 Win32 builds
1662 \end_layout
1663
1664 \end_inset
1665 </cell>
1666 </row>
1667 <row topline="true">
1668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1669 \begin_inset Text
1670
1671 \begin_layout Standard
1672
1673 \emph on
1674 PREFIX
1675 \end_layout
1676
1677 \end_inset
1678 </cell>
1679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1680 \begin_inset Text
1681
1682 \begin_layout Standard
1683 /usr/local
1684 \end_layout
1685
1686 \end_inset
1687 </cell>
1688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1689 \begin_inset Text
1690
1691 \begin_layout Standard
1692
1693 \backslash
1694 sdcc
1695 \end_layout
1696
1697 \end_inset
1698 </cell>
1699 </row>
1700 <row topline="true">
1701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1702 \begin_inset Text
1703
1704 \begin_layout Standard
1705
1706 \emph on
1707 EXEC_PREFIX
1708 \end_layout
1709
1710 \end_inset
1711 </cell>
1712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1713 \begin_inset Text
1714
1715 \begin_layout Standard
1716
1717 \emph on
1718 $PREFIX
1719 \end_layout
1720
1721 \end_inset
1722 </cell>
1723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1724 \begin_inset Text
1725
1726 \begin_layout Standard
1727
1728 \emph on
1729 $PREFIX
1730 \end_layout
1731
1732 \end_inset
1733 </cell>
1734 </row>
1735 <row topline="true">
1736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1737 \begin_inset Text
1738
1739 \begin_layout Standard
1740
1741 \emph on
1742 BINDIR
1743 \end_layout
1744
1745 \end_inset
1746 </cell>
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 $EXEC_PREFIX
1754 \emph default
1755 /bin
1756 \end_layout
1757
1758 \end_inset
1759 </cell>
1760 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1761 \begin_inset Text
1762
1763 \begin_layout Standard
1764
1765 \emph on
1766 $EXEC_PREFIX
1767 \emph default
1768
1769 \backslash
1770 bin
1771 \end_layout
1772
1773 \end_inset
1774 </cell>
1775 </row>
1776 <row topline="true">
1777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1778 \begin_inset Text
1779
1780 \begin_layout Standard
1781
1782 \emph on
1783 DATADIR
1784 \end_layout
1785
1786 \end_inset
1787 </cell>
1788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1789 \begin_inset Text
1790
1791 \begin_layout Standard
1792
1793 \emph on
1794 $DATAROOTDIR
1795 \end_layout
1796
1797 \end_inset
1798 </cell>
1799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1800 \begin_inset Text
1801
1802 \begin_layout Standard
1803
1804 \emph on
1805 $DATAROOTDIR
1806 \end_layout
1807
1808 \end_inset
1809 </cell>
1810 </row>
1811 <row topline="true">
1812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1813 \begin_inset Text
1814
1815 \begin_layout Standard
1816
1817 \emph on
1818 DATAROOTDIR
1819 \end_layout
1820
1821 \end_inset
1822 </cell>
1823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1824 \begin_inset Text
1825
1826 \begin_layout Standard
1827
1828 \emph on
1829 $PREFIX
1830 \emph default
1831 /share
1832 \end_layout
1833
1834 \end_inset
1835 </cell>
1836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1837 \begin_inset Text
1838
1839 \begin_layout Standard
1840
1841 \emph on
1842 $PREFIX
1843 \end_layout
1844
1845 \end_inset
1846 </cell>
1847 </row>
1848 <row topline="true">
1849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1850 \begin_inset Text
1851
1852 \begin_layout Standard
1853
1854 \emph on
1855 DOCDIR
1856 \end_layout
1857
1858 \end_inset
1859 </cell>
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 $DATAROOTDIR
1867 \emph default
1868 /sdcc/doc
1869 \end_layout
1870
1871 \end_inset
1872 </cell>
1873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1874 \begin_inset Text
1875
1876 \begin_layout Standard
1877
1878 \emph on
1879 $DATAROOTDIR
1880 \emph default
1881
1882 \backslash
1883 doc
1884 \end_layout
1885
1886 \end_inset
1887 </cell>
1888 </row>
1889 <row topline="true">
1890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1891 \begin_inset Text
1892
1893 \begin_layout Standard
1894
1895 \emph on
1896 INCLUDE_DIR_SUFFIX
1897 \end_layout
1898
1899 \end_inset
1900 </cell>
1901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1902 \begin_inset Text
1903
1904 \begin_layout Standard
1905 sdcc/include
1906 \end_layout
1907
1908 \end_inset
1909 </cell>
1910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1911 \begin_inset Text
1912
1913 \begin_layout Standard
1914 include
1915 \end_layout
1916
1917 \end_inset
1918 </cell>
1919 </row>
1920 <row topline="true" bottomline="true">
1921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1922 \begin_inset Text
1923
1924 \begin_layout Standard
1925
1926 \emph on
1927 LIB_DIR_SUFFIX
1928 \end_layout
1929
1930 \end_inset
1931 </cell>
1932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1933 \begin_inset Text
1934
1935 \begin_layout Standard
1936 sdcc/lib
1937 \end_layout
1938
1939 \end_inset
1940 </cell>
1941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1942 \begin_inset Text
1943
1944 \begin_layout Standard
1945 lib
1946 \end_layout
1947
1948 \end_inset
1949 </cell>
1950 </row>
1951 </lyxtabular>
1952
1953 \end_inset
1954
1955
1956 \newline
1957
1958 \end_layout
1959
1960 \begin_layout Standard
1961 \noindent
1962 'configure' also computes relative paths.
1963  This is needed for full relocatability of a binary package and to complete
1964  search paths (see section search paths below):
1965 \newline
1966  
1967 \end_layout
1968
1969 \begin_layout Standard
1970 \align center
1971 \begin_inset Tabular
1972 <lyxtabular version="3" rows="4" columns="3">
1973 <features>
1974 <column alignment="block" valignment="top" leftline="true" width="0in">
1975 <column alignment="block" valignment="top" leftline="true" width="0in">
1976 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1977 <row topline="true" bottomline="true">
1978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1979 \begin_inset Text
1980
1981 \begin_layout Standard
1982 Variable (computed)
1983 \end_layout
1984
1985 \end_inset
1986 </cell>
1987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1988 \begin_inset Text
1989
1990 \begin_layout Standard
1991 default
1992 \end_layout
1993
1994 \end_inset
1995 </cell>
1996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1997 \begin_inset Text
1998
1999 \begin_layout Standard
2000 Win32 builds
2001 \end_layout
2002
2003 \end_inset
2004 </cell>
2005 </row>
2006 <row topline="true" bottomline="true">
2007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2008 \begin_inset Text
2009
2010 \begin_layout Standard
2011
2012 \emph on
2013 BIN2DATA_DIR
2014 \end_layout
2015
2016 \end_inset
2017 </cell>
2018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2019 \begin_inset Text
2020
2021 \begin_layout Standard
2022 ../share
2023 \end_layout
2024
2025 \end_inset
2026 </cell>
2027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2028 \begin_inset Text
2029
2030 \begin_layout Standard
2031 ..
2032 \end_layout
2033
2034 \end_inset
2035 </cell>
2036 </row>
2037 <row bottomline="true">
2038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2039 \begin_inset Text
2040
2041 \begin_layout Standard
2042
2043 \emph on
2044 PREFIX2BIN_DIR
2045 \end_layout
2046
2047 \end_inset
2048 </cell>
2049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2050 \begin_inset Text
2051
2052 \begin_layout Standard
2053 bin
2054 \end_layout
2055
2056 \end_inset
2057 </cell>
2058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2059 \begin_inset Text
2060
2061 \begin_layout Standard
2062 bin
2063 \end_layout
2064
2065 \end_inset
2066 </cell>
2067 </row>
2068 <row bottomline="true">
2069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2070 \begin_inset Text
2071
2072 \begin_layout Standard
2073
2074 \emph on
2075 PREFIX2DATA_DIR
2076 \end_layout
2077
2078 \end_inset
2079 </cell>
2080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2081 \begin_inset Text
2082
2083 \begin_layout Standard
2084 share/sdcc
2085 \end_layout
2086
2087 \end_inset
2088 </cell>
2089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2090 \begin_inset Text
2091
2092 \begin_layout Standard
2093
2094 \end_layout
2095
2096 \end_inset
2097 </cell>
2098 </row>
2099 </lyxtabular>
2100
2101 \end_inset
2102
2103
2104 \newline
2105
2106 \end_layout
2107
2108 \begin_layout Standard
2109 \noindent
2110 Examples:
2111 \end_layout
2112
2113 \begin_layout LyX-Code
2114 ./configure
2115 \newline
2116 ./configure -
2117 \begin_inset ERT
2118 status collapsed
2119
2120 \begin_layout Standard
2121
2122
2123 \backslash
2124 /
2125 \end_layout
2126
2127 \end_inset
2128
2129 -prefix=
2130 \begin_inset Quotes srd
2131 \end_inset
2132
2133 /usr/bin
2134 \begin_inset Quotes srd
2135 \end_inset
2136
2137  -
2138 \begin_inset ERT
2139 status collapsed
2140
2141 \begin_layout Standard
2142
2143
2144 \backslash
2145 /
2146 \end_layout
2147
2148 \end_inset
2149
2150 -datarootdir=
2151 \begin_inset Quotes srd
2152 \end_inset
2153
2154 /usr/share
2155 \begin_inset Quotes srd
2156 \end_inset
2157
2158
2159 \newline
2160 ./configure -
2161 \begin_inset ERT
2162 status collapsed
2163
2164 \begin_layout Standard
2165
2166
2167 \backslash
2168 /
2169 \end_layout
2170
2171 \end_inset
2172
2173 -disable-avr-port -
2174 \begin_inset ERT
2175 status collapsed
2176
2177 \begin_layout Standard
2178
2179
2180 \backslash
2181 /
2182 \end_layout
2183
2184 \end_inset
2185
2186 -disable-xa51-port
2187 \end_layout
2188
2189 \begin_layout Standard
2190 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2191 32'):
2192 \end_layout
2193
2194 \begin_layout LyX-Code
2195 ./configure 
2196 \backslash
2197
2198 \newline
2199 CC=
2200 \begin_inset Quotes srd
2201 \end_inset
2202
2203 i586-mingw32msvc-gcc
2204 \begin_inset Quotes srd
2205 \end_inset
2206
2207  CXX=
2208 \begin_inset Quotes srd
2209 \end_inset
2210
2211 i586-mingw32msvc-g++
2212 \begin_inset Quotes srd
2213 \end_inset
2214
2215  
2216 \backslash
2217  
2218 \newline
2219 RANLIB=
2220 \begin_inset Quotes srd
2221 \end_inset
2222
2223 i586-mingw32msvc-ranlib
2224 \begin_inset Quotes srd
2225 \end_inset
2226
2227  
2228 \backslash
2229
2230 \newline
2231 STRIP=
2232 \begin_inset Quotes srd
2233 \end_inset
2234
2235 i586-mingw32msvc-strip
2236 \begin_inset Quotes srd
2237 \end_inset
2238
2239  
2240 \backslash
2241
2242 \newline
2243 -
2244 \begin_inset ERT
2245 status collapsed
2246
2247 \begin_layout Standard
2248
2249
2250 \backslash
2251 /
2252 \end_layout
2253
2254 \end_inset
2255
2256 -prefix=
2257 \begin_inset Quotes srd
2258 \end_inset
2259
2260 /sdcc
2261 \begin_inset Quotes srd
2262 \end_inset
2263
2264  
2265 \backslash
2266
2267 \newline
2268 -
2269 \begin_inset ERT
2270 status collapsed
2271
2272 \begin_layout Standard
2273
2274
2275 \backslash
2276 /
2277 \end_layout
2278
2279 \end_inset
2280
2281 -datarootdir=
2282 \begin_inset Quotes srd
2283 \end_inset
2284
2285 /sdcc
2286 \begin_inset Quotes srd
2287 \end_inset
2288
2289  
2290 \backslash
2291
2292 \newline
2293 docdir=
2294 \begin_inset Quotes srd
2295 \end_inset
2296
2297
2298 \backslash
2299 ${datarootdir}/doc
2300 \begin_inset Quotes srd
2301 \end_inset
2302
2303  
2304 \backslash
2305
2306 \newline
2307 include_dir_suffix=
2308 \begin_inset Quotes srd
2309 \end_inset
2310
2311 include
2312 \begin_inset Quotes srd
2313 \end_inset
2314
2315  
2316 \backslash
2317
2318 \newline
2319 lib_dir_suffix=
2320 \begin_inset Quotes srd
2321 \end_inset
2322
2323 lib
2324 \begin_inset Quotes srd
2325 \end_inset
2326
2327  
2328 \backslash
2329
2330 \newline
2331 sdccconf_h_dir_separator=
2332 \begin_inset Quotes srd
2333 \end_inset
2334
2335
2336 \backslash
2337
2338 \backslash
2339
2340 \backslash
2341
2342 \backslash
2343
2344 \begin_inset Quotes srd
2345 \end_inset
2346
2347  
2348 \backslash
2349
2350 \newline
2351 -
2352 \begin_inset ERT
2353 status collapsed
2354
2355 \begin_layout Standard
2356
2357
2358 \backslash
2359 /
2360 \end_layout
2361
2362 \end_inset
2363
2364 -disable-device-lib
2365 \backslash
2366
2367 \newline
2368 -
2369 \begin_inset ERT
2370 status collapsed
2371
2372 \begin_layout Standard
2373
2374
2375 \backslash
2376 /
2377 \end_layout
2378
2379 \end_inset
2380
2381 -host=i586-mingw32msvc
2382 \backslash
2383
2384 \newline
2385 -
2386 \begin_inset ERT
2387 status collapsed
2388
2389 \begin_layout Standard
2390
2391
2392 \backslash
2393 /
2394 \end_layout
2395
2396 \end_inset
2397
2398 -build=unknown-unknown-linux-gnu
2399 \end_layout
2400
2401 \begin_layout Standard
2402 To 
2403 \begin_inset Quotes sld
2404 \end_inset
2405
2406 cross
2407 \begin_inset Quotes srd
2408 \end_inset
2409
2410 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2411 ):
2412 \end_layout
2413
2414 \begin_layout LyX-Code
2415 ./configure -C 
2416 \backslash
2417
2418 \newline
2419 -
2420 \begin_inset ERT
2421 status collapsed
2422
2423 \begin_layout Standard
2424
2425
2426 \backslash
2427 /
2428 \end_layout
2429
2430 \end_inset
2431
2432 -prefix=
2433 \begin_inset Quotes srd
2434 \end_inset
2435
2436 /sdcc
2437 \begin_inset Quotes srd
2438 \end_inset
2439
2440  
2441 \backslash
2442
2443 \newline
2444 -
2445 \begin_inset ERT
2446 status collapsed
2447
2448 \begin_layout Standard
2449
2450
2451 \backslash
2452 /
2453 \end_layout
2454
2455 \end_inset
2456
2457 -datarootdir=
2458 \begin_inset Quotes srd
2459 \end_inset
2460
2461 /sdcc
2462 \begin_inset Quotes srd
2463 \end_inset
2464
2465  
2466 \backslash
2467
2468 \newline
2469 docdir=
2470 \begin_inset Quotes srd
2471 \end_inset
2472
2473
2474 \backslash
2475 ${datarootdir}/doc
2476 \begin_inset Quotes srd
2477 \end_inset
2478
2479  
2480 \backslash
2481  
2482 \newline
2483 include_dir_suffix=
2484 \begin_inset Quotes srd
2485 \end_inset
2486
2487 include
2488 \begin_inset Quotes srd
2489 \end_inset
2490
2491  
2492 \backslash
2493
2494 \newline
2495 lib_dir_suffix=
2496 \begin_inset Quotes srd
2497 \end_inset
2498
2499 lib
2500 \begin_inset Quotes srd
2501 \end_inset
2502
2503  
2504 \backslash
2505
2506 \newline
2507 sdccconf_h_dir_separator=
2508 \begin_inset Quotes srd
2509 \end_inset
2510
2511
2512 \backslash
2513
2514 \backslash
2515
2516 \backslash
2517
2518 \backslash
2519
2520 \begin_inset Quotes srd
2521 \end_inset
2522
2523  
2524 \backslash
2525
2526 \newline
2527 CC=
2528 \begin_inset Quotes srd
2529 \end_inset
2530
2531 gcc -mno-cygwin
2532 \begin_inset Quotes srd
2533 \end_inset
2534
2535  
2536 \backslash
2537
2538 \newline
2539 CXX=
2540 \begin_inset Quotes srd
2541 \end_inset
2542
2543 g++ -mno-cygwin
2544 \begin_inset Quotes srd
2545 \end_inset
2546
2547  
2548 \end_layout
2549
2550 \begin_layout Standard
2551 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2552  The option '-
2553 \begin_inset ERT
2554 status collapsed
2555
2556 \begin_layout Standard
2557
2558
2559 \backslash
2560 /
2561 \end_layout
2562
2563 \end_inset
2564
2565 -C' turns on caching, which gives a little bit extra speed.
2566  However if options are changed, it can be necessary to delete the config.cache
2567  file.
2568 \end_layout
2569
2570 \begin_layout Section
2571 Install paths
2572 \begin_inset LatexCommand \label{sub:Install-paths}
2573
2574 \end_inset
2575
2576
2577 \begin_inset LatexCommand \index{Install paths}
2578
2579 \end_inset
2580
2581
2582 \end_layout
2583
2584 \begin_layout Standard
2585 \begin_inset VSpace medskip
2586 \end_inset
2587
2588
2589 \end_layout
2590
2591 \begin_layout Standard
2592 \align center
2593 \begin_inset Tabular
2594 <lyxtabular version="3" rows="5" columns="4">
2595 <features>
2596 <column alignment="left" valignment="top" leftline="true" width="0">
2597 <column alignment="left" valignment="top" leftline="true" width="0">
2598 <column alignment="left" valignment="top" leftline="true" width="0">
2599 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2600 <row topline="true" bottomline="true">
2601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2602 \begin_inset Text
2603
2604 \begin_layout Standard
2605
2606 \series bold
2607 Description
2608 \end_layout
2609
2610 \end_inset
2611 </cell>
2612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2613 \begin_inset Text
2614
2615 \begin_layout Standard
2616
2617 \series bold
2618 Path
2619 \end_layout
2620
2621 \end_inset
2622 </cell>
2623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2624 \begin_inset Text
2625
2626 \begin_layout Standard
2627
2628 \series bold
2629 Default
2630 \end_layout
2631
2632 \end_inset
2633 </cell>
2634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2635 \begin_inset Text
2636
2637 \begin_layout Standard
2638
2639 \series bold
2640 Win32 builds
2641 \end_layout
2642
2643 \end_inset
2644 </cell>
2645 </row>
2646 <row topline="true">
2647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2648 \begin_inset Text
2649
2650 \begin_layout Standard
2651 Binary files*
2652 \end_layout
2653
2654 \end_inset
2655 </cell>
2656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2657 \begin_inset Text
2658
2659 \begin_layout Standard
2660
2661 \emph on
2662 $EXEC_PREFIX
2663 \end_layout
2664
2665 \end_inset
2666 </cell>
2667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2668 \begin_inset Text
2669
2670 \begin_layout Standard
2671 /usr/local/bin
2672 \end_layout
2673
2674 \end_inset
2675 </cell>
2676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2677 \begin_inset Text
2678
2679 \begin_layout Standard
2680
2681 \backslash
2682 sdcc
2683 \backslash
2684 bin
2685 \end_layout
2686
2687 \end_inset
2688 </cell>
2689 </row>
2690 <row topline="true">
2691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2692 \begin_inset Text
2693
2694 \begin_layout Standard
2695 Include files
2696 \end_layout
2697
2698 \end_inset
2699 </cell>
2700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2701 \begin_inset Text
2702
2703 \begin_layout Standard
2704
2705 \emph on
2706 $DATADIR/ $INCLUDE_DIR_SUFFIX
2707 \end_layout
2708
2709 \end_inset
2710 </cell>
2711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2712 \begin_inset Text
2713
2714 \begin_layout Standard
2715 /usr/local/share/sdcc/include
2716 \end_layout
2717
2718 \end_inset
2719 </cell>
2720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2721 \begin_inset Text
2722
2723 \begin_layout Standard
2724
2725 \backslash
2726 sdcc
2727 \backslash
2728 include
2729 \end_layout
2730
2731 \end_inset
2732 </cell>
2733 </row>
2734 <row topline="true">
2735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2736 \begin_inset Text
2737
2738 \begin_layout Standard
2739 Library file**
2740 \end_layout
2741
2742 \end_inset
2743 </cell>
2744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2745 \begin_inset Text
2746
2747 \begin_layout Standard
2748
2749 \emph on
2750 $DATADIR/$LIB_DIR_SUFFIX
2751 \end_layout
2752
2753 \end_inset
2754 </cell>
2755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2756 \begin_inset Text
2757
2758 \begin_layout Standard
2759 /usr/local/share/sdcc/lib
2760 \end_layout
2761
2762 \end_inset
2763 </cell>
2764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2765 \begin_inset Text
2766
2767 \begin_layout Standard
2768
2769 \backslash
2770 sdcc
2771 \backslash
2772 lib
2773 \end_layout
2774
2775 \end_inset
2776 </cell>
2777 </row>
2778 <row topline="true" bottomline="true">
2779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2780 \begin_inset Text
2781
2782 \begin_layout Standard
2783 Documentation
2784 \end_layout
2785
2786 \end_inset
2787 </cell>
2788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2789 \begin_inset Text
2790
2791 \begin_layout Standard
2792
2793 \emph on
2794 $DOCDIR
2795 \end_layout
2796
2797 \end_inset
2798 </cell>
2799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2800 \begin_inset Text
2801
2802 \begin_layout Standard
2803 /usr/local/share/sdcc/doc
2804 \end_layout
2805
2806 \end_inset
2807 </cell>
2808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2809 \begin_inset Text
2810
2811 \begin_layout Standard
2812
2813 \backslash
2814 sdcc
2815 \backslash
2816 doc
2817 \end_layout
2818
2819 \end_inset
2820 </cell>
2821 </row>
2822 </lyxtabular>
2823
2824 \end_inset
2825
2826
2827 \end_layout
2828
2829 \begin_layout Verse
2830
2831 \size footnotesize
2832 *compiler, preprocessor, assembler, and linker
2833 \newline
2834 **the 
2835 \shape italic
2836 model
2837 \shape default
2838  is auto-appended by the compiler, e.g.
2839  small, large, z80, ds390 etc
2840 \end_layout
2841
2842 \begin_layout Standard
2843 \noindent
2844 The install paths can still be changed during `make install' with e.g.:
2845 \end_layout
2846
2847 \begin_layout LyX-Code
2848 make install prefix=$(HOME)/local/sdcc
2849 \end_layout
2850
2851 \begin_layout Standard
2852 Of course this doesn't change the search paths compiled into the binaries.
2853 \newline
2854
2855 \newline
2856 Moreove
2857 r the install path can be changed by defining DESTDIR
2858 \begin_inset LatexCommand \index{DESTDIR}
2859
2860 \end_inset
2861
2862 :
2863 \end_layout
2864
2865 \begin_layout LyX-Code
2866 make install DESTDIR=$(HOME)/sdcc.rpm/
2867 \end_layout
2868
2869 \begin_layout Standard
2870 Please note that DESTDIR must have a trailing slash!
2871 \end_layout
2872
2873 \begin_layout Section
2874 Search Paths
2875 \begin_inset LatexCommand \label{sub:Search-Paths}
2876
2877 \end_inset
2878
2879
2880 \begin_inset LatexCommand \index{Search path}
2881
2882 \end_inset
2883
2884
2885 \end_layout
2886
2887 \begin_layout Standard
2888 Some search paths or parts of them are determined by configure variables
2889  (in 
2890 \emph on
2891 italics
2892 \emph default
2893 , see section above).
2894  Further search paths are determined by environment variables during runtime.
2895  
2896 \newline
2897 The paths searched when running the compiler are as follows (the first
2898  catch wins):
2899 \newline
2900
2901 \newline
2902 1.
2903  Binary files (preprocessor, assembler and linker)
2904 \newline
2905
2906 \end_layout
2907
2908 \begin_layout Standard
2909 \align center
2910 \begin_inset Tabular
2911 <lyxtabular version="3" rows="4" columns="3">
2912 <features>
2913 <column alignment="block" valignment="top" leftline="true" width="0in">
2914 <column alignment="block" valignment="top" leftline="true" width="0in">
2915 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2916 <row topline="true" bottomline="true">
2917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2918 \begin_inset Text
2919
2920 \begin_layout Standard
2921 Search path
2922 \end_layout
2923
2924 \end_inset
2925 </cell>
2926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2927 \begin_inset Text
2928
2929 \begin_layout Standard
2930 default
2931 \end_layout
2932
2933 \end_inset
2934 </cell>
2935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2936 \begin_inset Text
2937
2938 \begin_layout Standard
2939 Win32 builds
2940 \end_layout
2941
2942 \end_inset
2943 </cell>
2944 </row>
2945 <row topline="true">
2946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2947 \begin_inset Text
2948
2949 \begin_layout Standard
2950 $SDCC_HOME/
2951 \emph on
2952 $PPREFIX2BIN_DIR
2953 \end_layout
2954
2955 \end_inset
2956 </cell>
2957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2958 \begin_inset Text
2959
2960 \begin_layout Standard
2961 $SDCC_HOME/bin
2962 \end_layout
2963
2964 \end_inset
2965 </cell>
2966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2967 \begin_inset Text
2968
2969 \begin_layout Standard
2970 $SDCC_HOME
2971 \backslash
2972 bin
2973 \end_layout
2974
2975 \end_inset
2976 </cell>
2977 </row>
2978 <row topline="true">
2979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2980 \begin_inset Text
2981
2982 \begin_layout Standard
2983 Path of argv[0] (if available)
2984 \end_layout
2985
2986 \end_inset
2987 </cell>
2988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2989 \begin_inset Text
2990
2991 \begin_layout Standard
2992 Path of argv[0]
2993 \end_layout
2994
2995 \end_inset
2996 </cell>
2997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2998 \begin_inset Text
2999
3000 \begin_layout Standard
3001 Path of argv[0]
3002 \end_layout
3003
3004 \end_inset
3005 </cell>
3006 </row>
3007 <row topline="true" bottomline="true">
3008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3009 \begin_inset Text
3010
3011 \begin_layout Standard
3012 $PATH
3013 \end_layout
3014
3015 \end_inset
3016 </cell>
3017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3018 \begin_inset Text
3019
3020 \begin_layout Standard
3021 $PATH
3022 \end_layout
3023
3024 \end_inset
3025 </cell>
3026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3027 \begin_inset Text
3028
3029 \begin_layout Standard
3030 $PATH
3031 \end_layout
3032
3033 \end_inset
3034 </cell>
3035 </row>
3036 </lyxtabular>
3037
3038 \end_inset
3039
3040  
3041 \newline
3042
3043 \end_layout
3044
3045 \begin_layout Standard
3046 \noindent
3047 2.
3048  Include files
3049 \newline
3050
3051 \end_layout
3052
3053 \begin_layout Standard
3054 \align center
3055 \begin_inset Tabular
3056 <lyxtabular version="3" rows="6" columns="3">
3057 <features>
3058 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3059 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3060 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3061 <row topline="true" bottomline="true">
3062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3063 \begin_inset Text
3064
3065 \begin_layout Standard
3066 Search path
3067 \end_layout
3068
3069 \end_inset
3070 </cell>
3071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3072 \begin_inset Text
3073
3074 \begin_layout Standard
3075 default
3076 \end_layout
3077
3078 \end_inset
3079 </cell>
3080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3081 \begin_inset Text
3082
3083 \begin_layout Standard
3084 Win32 builds
3085 \end_layout
3086
3087 \end_inset
3088 </cell>
3089 </row>
3090 <row topline="true">
3091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3092 \begin_inset Text
3093
3094 \begin_layout Standard
3095 -
3096 \begin_inset ERT
3097 status collapsed
3098
3099 \begin_layout Standard
3100
3101
3102 \backslash
3103 /
3104 \end_layout
3105
3106 \end_inset
3107
3108 -I dir
3109 \end_layout
3110
3111 \end_inset
3112 </cell>
3113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3114 \begin_inset Text
3115
3116 \begin_layout Standard
3117 -
3118 \begin_inset ERT
3119 status collapsed
3120
3121 \begin_layout Standard
3122
3123
3124 \backslash
3125 /
3126 \end_layout
3127
3128 \end_inset
3129
3130 -I dir
3131 \end_layout
3132
3133 \end_inset
3134 </cell>
3135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3136 \begin_inset Text
3137
3138 \begin_layout Standard
3139 -
3140 \begin_inset ERT
3141 status collapsed
3142
3143 \begin_layout Standard
3144
3145
3146 \backslash
3147 /
3148 \end_layout
3149
3150 \end_inset
3151
3152 -I dir
3153 \end_layout
3154
3155 \end_inset
3156 </cell>
3157 </row>
3158 <row topline="true">
3159 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3160 \begin_inset Text
3161
3162 \begin_layout Standard
3163 $SDCC_INCLUDE
3164 \end_layout
3165
3166 \end_inset
3167 </cell>
3168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3169 \begin_inset Text
3170
3171 \begin_layout Standard
3172 $SDCC_INCLUDE
3173 \end_layout
3174
3175 \end_inset
3176 </cell>
3177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3178 \begin_inset Text
3179
3180 \begin_layout Standard
3181 $SDCC_INCLUDE
3182 \end_layout
3183
3184 \end_inset
3185 </cell>
3186 </row>
3187 <row topline="true">
3188 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3189 \begin_inset Text
3190
3191 \begin_layout Standard
3192 $SDCC_HOME/
3193 \newline
3194
3195 \emph on
3196 $PREFIX2DATA_DIR/
3197 \newline
3198 $INCLUDE_DIR_SUFFIX
3199 \end_layout
3200
3201 \end_inset
3202 </cell>
3203 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3204 \begin_inset Text
3205
3206 \begin_layout Standard
3207 $SDCC_ HOME/
3208 \newline
3209 share/sdcc/
3210 \newline
3211 include
3212 \end_layout
3213
3214 \end_inset
3215 </cell>
3216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3217 \begin_inset Text
3218
3219 \begin_layout Standard
3220 $SDCC_HOME
3221 \backslash
3222 include
3223 \end_layout
3224
3225 \end_inset
3226 </cell>
3227 </row>
3228 <row topline="true">
3229 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3230 \begin_inset Text
3231
3232 \begin_layout Standard
3233 path(argv[0])/
3234 \newline
3235
3236 \emph on
3237 $BIN2DATADIR/
3238 \emph default
3239
3240 \newline
3241
3242 \emph on
3243 $INCLUDE_DIR_SUFFIX
3244 \end_layout
3245
3246 \end_inset
3247 </cell>
3248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3249 \begin_inset Text
3250
3251 \begin_layout Standard
3252 path(argv[0])/
3253 \newline
3254 ../sdcc/include
3255 \newline
3256 \InsetSpace ~
3257 \InsetSpace ~
3258 \InsetSpace ~
3259 \InsetSpace ~
3260 \InsetSpace ~
3261 \InsetSpace ~
3262 \InsetSpace ~
3263 \InsetSpace ~
3264 \InsetSpace ~
3265 \InsetSpace ~
3266 \InsetSpace ~
3267 \InsetSpace ~
3268 \InsetSpace ~
3269 \InsetSpace ~
3270 \InsetSpace ~
3271 \InsetSpace ~
3272 \InsetSpace ~
3273 \InsetSpace ~
3274 \InsetSpace ~
3275 \InsetSpace ~
3276 \InsetSpace ~
3277 \InsetSpace ~
3278 \InsetSpace ~
3279 \InsetSpace ~
3280 \InsetSpace ~
3281 \InsetSpace ~
3282 \InsetSpace ~
3283 \InsetSpace ~
3284 \InsetSpace ~
3285 \InsetSpace ~
3286 \InsetSpace ~
3287 \InsetSpace ~
3288 \InsetSpace ~
3289 \InsetSpace ~
3290 \InsetSpace ~
3291 \InsetSpace ~
3292 \InsetSpace ~
3293 \InsetSpace ~
3294
3295 \end_layout
3296
3297 \end_inset
3298 </cell>
3299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3300 \begin_inset Text
3301
3302 \begin_layout Standard
3303 path(argv[0])
3304 \backslash
3305 ..
3306 \backslash
3307 include
3308 \end_layout
3309
3310 \end_inset
3311 </cell>
3312 </row>
3313 <row topline="true" bottomline="true">
3314 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3315 \begin_inset Text
3316
3317 \begin_layout Standard
3318
3319 \emph on
3320 $DATADIR/
3321 \emph default
3322
3323 \newline
3324
3325 \emph on
3326 $INCLUDE_DIR_SUFFIX
3327 \end_layout
3328
3329 \end_inset
3330 </cell>
3331 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3332 \begin_inset Text
3333
3334 \begin_layout Standard
3335 /usr/local/share/sdcc/
3336 \newline
3337 include
3338 \end_layout
3339
3340 \end_inset
3341 </cell>
3342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3343 \begin_inset Text
3344
3345 \begin_layout Standard
3346 (not on Win32)
3347 \end_layout
3348
3349 \end_inset
3350 </cell>
3351 </row>
3352 </lyxtabular>
3353
3354 \end_inset
3355
3356  
3357 \newline
3358
3359 \end_layout
3360
3361 \begin_layout Standard
3362 \noindent
3363 The option -
3364 \begin_inset ERT
3365 status collapsed
3366
3367 \begin_layout Standard
3368
3369
3370 \backslash
3371 /
3372 \end_layout
3373
3374 \end_inset
3375
3376 -nostdinc disables the last two search paths.
3377 \newline
3378
3379 \newline
3380 3.
3381  Library files 
3382 \newline
3383
3384 \end_layout
3385
3386 \begin_layout Standard
3387 With the exception of 
3388 \begin_inset Quotes sld
3389 \end_inset
3390
3391 -
3392 \begin_inset ERT
3393 status collapsed
3394
3395 \begin_layout Standard
3396
3397
3398 \backslash
3399 /
3400 \end_layout
3401
3402 \end_inset
3403
3404 -L dir
3405 \begin_inset Quotes srd
3406 \end_inset
3407
3408  the 
3409 \shape italic
3410 model
3411 \shape default
3412  is auto-appended by the compiler (e.g.
3413  small, large, z80, ds390 etc.).
3414  
3415 \newline
3416
3417 \end_layout
3418
3419 \begin_layout Standard
3420 \align center
3421 \begin_inset Tabular
3422 <lyxtabular version="3" rows="6" columns="3">
3423 <features>
3424 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3425 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3426 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3427 <row topline="true" bottomline="true">
3428 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3429 \begin_inset Text
3430
3431 \begin_layout Standard
3432 Search path
3433 \end_layout
3434
3435 \end_inset
3436 </cell>
3437 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3438 \begin_inset Text
3439
3440 \begin_layout Standard
3441 default
3442 \end_layout
3443
3444 \end_inset
3445 </cell>
3446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3447 \begin_inset Text
3448
3449 \begin_layout Standard
3450 Win32 builds
3451 \end_layout
3452
3453 \end_inset
3454 </cell>
3455 </row>
3456 <row topline="true">
3457 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3458 \begin_inset Text
3459
3460 \begin_layout Standard
3461 -
3462 \begin_inset ERT
3463 status collapsed
3464
3465 \begin_layout Standard
3466
3467
3468 \backslash
3469 /
3470 \end_layout
3471
3472 \end_inset
3473
3474 -L dir
3475 \end_layout
3476
3477 \end_inset
3478 </cell>
3479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3480 \begin_inset Text
3481
3482 \begin_layout Standard
3483 -
3484 \begin_inset ERT
3485 status collapsed
3486
3487 \begin_layout Standard
3488
3489
3490 \backslash
3491 /
3492 \end_layout
3493
3494 \end_inset
3495
3496 -L dir
3497 \end_layout
3498
3499 \end_inset
3500 </cell>
3501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3502 \begin_inset Text
3503
3504 \begin_layout Standard
3505 -
3506 \begin_inset ERT
3507 status collapsed
3508
3509 \begin_layout Standard
3510
3511
3512 \backslash
3513 /
3514 \end_layout
3515
3516 \end_inset
3517
3518 -L dir
3519 \end_layout
3520
3521 \end_inset
3522 </cell>
3523 </row>
3524 <row topline="true">
3525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3526 \begin_inset Text
3527
3528 \begin_layout Standard
3529 $SDCC_LIB/
3530 \newline
3531
3532 \emph on
3533 <model>
3534 \end_layout
3535
3536 \end_inset
3537 </cell>
3538 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3539 \begin_inset Text
3540
3541 \begin_layout Standard
3542 $SDCC_LIB/
3543 \newline
3544
3545 \emph on
3546 <model>
3547 \end_layout
3548
3549 \end_inset
3550 </cell>
3551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3552 \begin_inset Text
3553
3554 \begin_layout Standard
3555 $SDCC_LIB
3556 \backslash
3557
3558 \newline
3559
3560 \emph on
3561 <model>
3562 \end_layout
3563
3564 \end_inset
3565 </cell>
3566 </row>
3567 <row topline="true">
3568 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3569 \begin_inset Text
3570
3571 \begin_layout Standard
3572 $SDCC_HOME/
3573 \newline
3574
3575 \emph on
3576 $PREFIX2DATA_DIR/
3577 \newline
3578 $LIB_DIR_SUFFIX/<model>
3579 \end_layout
3580
3581 \end_inset
3582 </cell>
3583 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3584 \begin_inset Text
3585
3586 \begin_layout Standard
3587 $SDCC_HOME/
3588 \newline
3589 share/sdcc/
3590 \newline
3591 lib/
3592 \emph on
3593 <model>
3594 \end_layout
3595
3596 \end_inset
3597 </cell>
3598 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3599 \begin_inset Text
3600
3601 \begin_layout Standard
3602 $SDCC_HOME
3603 \backslash
3604 lib
3605 \backslash
3606
3607 \emph on
3608
3609 \newline
3610 <model>
3611 \end_layout
3612
3613 \end_inset
3614 </cell>
3615 </row>
3616 <row topline="true">
3617 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3618 \begin_inset Text
3619
3620 \begin_layout Standard
3621 path(argv[0])/
3622 \newline
3623
3624 \emph on
3625 $BIN2DATADIR/
3626 \emph default
3627
3628 \newline
3629
3630 \emph on
3631 $LIB_DIR_SUFFIX/<model>
3632 \end_layout
3633
3634 \end_inset
3635 </cell>
3636 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3637 \begin_inset Text
3638
3639 \begin_layout Standard
3640 path(argv[0])/
3641 \newline
3642 ../sdcc/lib/
3643 \emph on
3644 <model>
3645 \newline
3646 \InsetSpace ~
3647 \InsetSpace ~
3648 \InsetSpace ~
3649 \InsetSpace ~
3650 \InsetSpace ~
3651 \InsetSpace ~
3652 \InsetSpace ~
3653 \InsetSpace ~
3654 \InsetSpace ~
3655 \InsetSpace ~
3656 \InsetSpace ~
3657 \InsetSpace ~
3658 \InsetSpace ~
3659 \InsetSpace ~
3660 \InsetSpace ~
3661 \InsetSpace ~
3662 \InsetSpace ~
3663 \InsetSpace ~
3664 \InsetSpace ~
3665 \InsetSpace ~
3666 \InsetSpace ~
3667 \InsetSpace ~
3668 \InsetSpace ~
3669 \InsetSpace ~
3670 \InsetSpace ~
3671 \InsetSpace ~
3672 \InsetSpace ~
3673 \InsetSpace ~
3674 \InsetSpace ~
3675 \InsetSpace ~
3676 \InsetSpace ~
3677 \InsetSpace ~
3678 \InsetSpace ~
3679 \InsetSpace ~
3680 \InsetSpace ~
3681 \InsetSpace ~
3682 \InsetSpace ~
3683 \InsetSpace ~
3684 \InsetSpace ~
3685
3686 \end_layout
3687
3688 \end_inset
3689 </cell>
3690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3691 \begin_inset Text
3692
3693 \begin_layout Standard
3694 path(argv[0])
3695 \backslash
3696
3697 \newline
3698 ..
3699 \backslash
3700 lib
3701 \backslash
3702
3703 \emph on
3704 <model>
3705 \newline
3706 \InsetSpace ~
3707 \InsetSpace ~
3708 \InsetSpace ~
3709 \InsetSpace ~
3710 \InsetSpace ~
3711 \InsetSpace ~
3712 \InsetSpace ~
3713 \InsetSpace ~
3714 \InsetSpace ~
3715 \InsetSpace ~
3716 \InsetSpace ~
3717 \InsetSpace ~
3718 \InsetSpace ~
3719 \InsetSpace ~
3720 \InsetSpace ~
3721 \InsetSpace ~
3722 \InsetSpace ~
3723 \InsetSpace ~
3724 \InsetSpace ~
3725 \InsetSpace ~
3726 \InsetSpace ~
3727 \InsetSpace ~
3728 \InsetSpace ~
3729 \InsetSpace ~
3730 \InsetSpace ~
3731 \InsetSpace ~
3732 \InsetSpace ~
3733 \InsetSpace ~
3734 \InsetSpace ~
3735 \InsetSpace ~
3736 \InsetSpace ~
3737 \InsetSpace ~
3738 \InsetSpace ~
3739 \InsetSpace ~
3740 \InsetSpace ~
3741
3742 \end_layout
3743
3744 \end_inset
3745 </cell>
3746 </row>
3747 <row topline="true" bottomline="true">
3748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3749 \begin_inset Text
3750
3751 \begin_layout Standard
3752
3753 \emph on
3754 $DATADIR/
3755 \newline
3756 $LIB_DIR_SUFFIX/<model>
3757 \end_layout
3758
3759 \end_inset
3760 </cell>
3761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3762 \begin_inset Text
3763
3764 \begin_layout Standard
3765 /usr/local/share/sdcc/
3766 \newline
3767 lib/
3768 \emph on
3769 <model>
3770 \end_layout
3771
3772 \end_inset
3773 </cell>
3774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3775 \begin_inset Text
3776
3777 \begin_layout Standard
3778 (not on Win32)
3779 \end_layout
3780
3781 \end_inset
3782 </cell>
3783 </row>
3784 </lyxtabular>
3785
3786 \end_inset
3787
3788
3789 \newline
3790
3791 \end_layout
3792
3793 \begin_layout Standard
3794 \begin_inset Note Note
3795 status collapsed
3796
3797 \begin_layout Standard
3798 Don't delete any of the stray spaces in the table above without checking
3799  the HTML output (last line)!
3800 \end_layout
3801
3802 \end_inset
3803
3804
3805 \end_layout
3806
3807 \begin_layout Standard
3808 \InsetSpace ~
3809
3810 \newline
3811 The option -
3812 \begin_inset ERT
3813 status collapsed
3814
3815 \begin_layout Standard
3816
3817
3818 \backslash
3819 /
3820 \end_layout
3821
3822 \end_inset
3823
3824 -nostdlib disables the last two search paths.
3825 \end_layout
3826
3827 \begin_layout Section
3828 Building SDCC
3829 \begin_inset LatexCommand \index{Building SDCC}
3830
3831 \end_inset
3832
3833
3834 \end_layout
3835
3836 \begin_layout Subsection
3837 Building SDCC on Linux
3838 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3839
3840 \end_inset
3841
3842
3843 \end_layout
3844
3845 \begin_layout Enumerate
3846
3847 \series medium
3848 Download the source package
3849 \series default
3850  either from the SDCC Subversion repository or from snapshot builds
3851 \series medium
3852 , it will be named something like sdcc
3853 \series default
3854 -src
3855 \series medium
3856 -yyyymmdd-rrrr.t
3857 \series default
3858 ar.
3859 \series medium
3860 bz2
3861 \series default
3862  
3863 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3864
3865 \end_inset
3866
3867 .
3868 \end_layout
3869
3870 \begin_layout Enumerate
3871
3872 \series medium
3873 Bring up a command line terminal, such as xterm.
3874 \end_layout
3875
3876 \begin_layout Enumerate
3877
3878 \series medium
3879 Unpack the file using a command like: 
3880 \family sans
3881 \series bold
3882 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
3883 \begin_inset Quotes srd
3884 \end_inset
3885
3886
3887 \family default
3888 \series medium
3889 , this will create a sub-directory called sdcc with all of the sources.
3890 \end_layout
3891
3892 \begin_layout Enumerate
3893 Change directory into the main SDCC directory, for example type: 
3894 \family sans
3895 \series bold
3896 "cd sdcc
3897 \series default
3898 ".
3899 \end_layout
3900
3901 \begin_layout Enumerate
3902
3903 \series medium
3904 Type 
3905 \family sans
3906 \series bold
3907 "./configure
3908 \family default
3909 \series default
3910 ".
3911  This configures the package for compilation on your system.
3912 \end_layout
3913
3914 \begin_layout Enumerate
3915
3916 \series medium
3917 Type 
3918 \family sans
3919 \series bold
3920 "make
3921 \family default
3922 \series default
3923 "
3924 \series medium
3925 .
3926
3927 \series default
3928  All of the source packages will compile, this can take a while.
3929 \end_layout
3930
3931 \begin_layout Enumerate
3932
3933 \series medium
3934 Type 
3935 \family sans
3936 \series bold
3937 "make install"
3938 \family default
3939 \series default
3940  as root
3941 \series medium
3942 .
3943
3944 \series default
3945  This copies the binary executables, the include files, the libraries and
3946  the documentation to the install directories.
3947  Proceed with section 
3948 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3949
3950 \end_inset
3951
3952 .
3953 \end_layout
3954
3955 \begin_layout Subsection
3956 Building SDCC on Mac OS X
3957 \end_layout
3958
3959 \begin_layout Standard
3960 Follow the instruction for Linux.
3961 \newline
3962
3963 \newline
3964 On Mac OS X 10.2.x it was reported, that the
3965  default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3966  Fortunately there's also gcc 2.9.x installed, which works fine.
3967  This compiler can be selected by running 'configure' with:
3968 \end_layout
3969
3970 \begin_layout LyX-Code
3971 ./configure CC=gcc2 CXX=g++2
3972 \end_layout
3973
3974 \begin_layout Standard
3975 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
3976  Xcode.
3977  Run 'configure' with:
3978 \end_layout
3979
3980 \begin_layout LyX-Code
3981 ./configure 
3982 \backslash
3983
3984 \end_layout
3985
3986 \begin_layout LyX-Code
3987 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
3988  ppc" 
3989 \backslash
3990
3991 \end_layout
3992
3993 \begin_layout LyX-Code
3994 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
3995  ppc" 
3996 \backslash
3997
3998 \end_layout
3999
4000 \begin_layout LyX-Code
4001 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
4002 \end_layout
4003
4004 \begin_layout Subsection
4005 Cross compiling SDCC on Linux for Windows
4006 \end_layout
4007
4008 \begin_layout Standard
4009 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
4010  See section 'Configure Options'.
4011 \end_layout
4012
4013 \begin_layout Subsection
4014 Building SDCC using Cygwin and Mingw32
4015 \end_layout
4016
4017 \begin_layout Standard
4018 For building and installing a Cygwin executable follow the instructions
4019  for Linux.
4020 \newline
4021
4022 \newline
4023 On Cygwin a 
4024 \begin_inset Quotes sld
4025 \end_inset
4026
4027 native
4028 \begin_inset Quotes srd
4029 \end_inset
4030
4031  Win32-binary can be built, which will not need the Cygwin-DLL.
4032  For the necessary 'configure' options see section 'configure options' or
4033  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4034 \newline
4035
4036 \newline
4037 In order to install
4038  Cygwin on Windows download setup.exe from 
4039 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
4040
4041 \end_inset
4042
4043 .
4044  Run it, set the 
4045 \begin_inset Quotes sld
4046 \end_inset
4047
4048 default text file type
4049 \begin_inset Quotes srd
4050 \end_inset
4051
4052  to 
4053 \begin_inset Quotes sld
4054 \end_inset
4055
4056 unix
4057 \begin_inset Quotes srd
4058 \end_inset
4059
4060  and download/install at least the following packages.
4061  Some packages are selected by default, others will be automatically selected
4062  because of dependencies with the manually selected packages.
4063  Never deselect these packages!
4064 \end_layout
4065
4066 \begin_layout Itemize
4067 flex
4068 \end_layout
4069
4070 \begin_layout Itemize
4071 bison
4072 \end_layout
4073
4074 \begin_layout Itemize
4075 gcc ; version 3.x is fine, no need to use the old 2.9x
4076 \end_layout
4077
4078 \begin_layout Itemize
4079 binutils ; selected with gcc
4080 \end_layout
4081
4082 \begin_layout Itemize
4083 make
4084 \end_layout
4085
4086 \begin_layout Itemize
4087 rxvt ; a nice console, which makes life much easier under windoze (see below)
4088 \end_layout
4089
4090 \begin_layout Itemize
4091 man ; not really needed for building SDCC, but you'll miss it sooner or
4092  later
4093 \end_layout
4094
4095 \begin_layout Itemize
4096 less ; not really needed for building SDCC, but you'll miss it sooner or
4097  later
4098 \end_layout
4099
4100 \begin_layout Itemize
4101 svn ; only if you use Subversion access
4102 \end_layout
4103
4104 \begin_layout Standard
4105 If you want to develop something you'll need:
4106 \end_layout
4107
4108 \begin_layout Itemize
4109 python ; for the regression tests
4110 \end_layout
4111
4112 \begin_layout Itemize
4113 gdb ; the gnu debugger, together with the nice GUI 
4114 \begin_inset Quotes sld
4115 \end_inset
4116
4117 insight
4118 \begin_inset Quotes srd
4119 \end_inset
4120
4121
4122 \end_layout
4123
4124 \begin_layout Itemize
4125 openssh ; to access the CF or commit changes
4126 \end_layout
4127
4128 \begin_layout Itemize
4129 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4130  use autoconf-stable!
4131 \end_layout
4132
4133 \begin_layout Standard
4134 rxvt is a nice console with history.
4135  Replace in your cygwin.bat the line
4136 \end_layout
4137
4138 \begin_layout LyX-Code
4139 bash -
4140 \begin_inset ERT
4141 status collapsed
4142
4143 \begin_layout Standard
4144
4145
4146 \backslash
4147 /
4148 \end_layout
4149
4150 \end_inset
4151
4152 -login -i 
4153 \end_layout
4154
4155 \begin_layout Standard
4156 with (one line):
4157 \end_layout
4158
4159 \begin_layout LyX-Code
4160 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4161 \end_layout
4162
4163 \begin_layout LyX-Code
4164      -bg black -fg white -geometry 100x65 -e bash -
4165 \begin_inset ERT
4166 status collapsed
4167
4168 \begin_layout Standard
4169
4170
4171 \backslash
4172 /
4173 \end_layout
4174
4175 \end_inset
4176
4177 -login
4178 \end_layout
4179
4180 \begin_layout Standard
4181 Text selected with the mouse is automatically copied to the clipboard, pasting
4182  works with shift-insert.
4183 \newline
4184
4185 \newline
4186 The other good tip is to make sure you have no //c/-styl
4187 e paths anywhere, use /cygdrive/c/ instead.
4188  Using // invokes a network lookup which is very slow.
4189  If you think 
4190 \begin_inset Quotes sld
4191 \end_inset
4192
4193 cygdrive
4194 \begin_inset Quotes srd
4195 \end_inset
4196
4197  is too long, you can change it with e.g.
4198 \end_layout
4199
4200 \begin_layout LyX-Code
4201 mount -s -u -c /mnt
4202 \end_layout
4203
4204 \begin_layout Standard
4205 SDCC sources use the unix line ending LF.
4206  Life is much easier, if you store the source tree on a drive which is mounted
4207  in binary mode.
4208  And use an editor which can handle LF-only line endings.
4209  Make sure not to commit files with windows line endings.
4210  The tabulator spacing
4211 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4212
4213 \end_inset
4214
4215  used in the project is 8.
4216  Although a tabulator spacing of 8 is a sensible choice for programmers
4217  (it's a power of 2 and allows to display 8/16 bit signed variables without
4218  loosing columns) the plan is to move towards using only spaces in the source.
4219 \end_layout
4220
4221 \begin_layout Subsection
4222 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4223 \end_layout
4224
4225 \begin_layout Standard
4226
4227 \series medium
4228 Download the source package
4229 \series default
4230  either from the SDCC Subversion repository or from the 
4231 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4232
4233 \end_inset
4234
4235
4236 \series medium
4237 , it will be named something like sdcc
4238 \series default
4239 -src
4240 \series medium
4241 -yyyymmdd-rrrr.tar.bz2.
4242
4243 \series default
4244  SDCC is distributed with all the projects, workspaces, and files you need
4245  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4246  The workspace name is 'sdcc.dsw'.
4247  Please note that as it is now, all the executables are created in a folder
4248  called sdcc
4249 \backslash
4250 bin_vc.
4251  Once built you need to copy the executables from sdcc
4252 \backslash
4253 bin_vc to sdcc
4254 \backslash
4255 bin before running SDCC.
4256  
4257 \newline
4258
4259 \newline
4260 WARNING: Visual studio is very picky with line terminations; it expects
4261  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4262  When using the Subversion repository it's easiest to configure the svn
4263  client to convert automatically for you.
4264  If however you are getting a message such as "This makefile was not generated
4265  by Developer Studio etc.
4266  etc.
4267 \begin_inset Quotes srd
4268 \end_inset
4269
4270  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4271  need to convert the Unix style line endings to DOS style line endings.
4272  To do so you can use the 
4273 \begin_inset Quotes sld
4274 \end_inset
4275
4276 unix2dos
4277 \begin_inset Quotes srd
4278 \end_inset
4279
4280  utility freely available on the internet.
4281  Doug Hawkins reported in the sdcc-user list that this works:
4282 \newline
4283
4284 \newline
4285 C:
4286 \backslash
4287 Programming
4288 \backslash
4289 SDCC> unix2dos sdcc.dsw
4290 \newline
4291 C:
4292 \backslash
4293 Programming
4294 \backslash
4295 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4296 \newline
4297
4298 \newline
4299 In order to build SDCC with MSVC
4300  you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4301  One good place to get them is 
4302 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4303
4304 \end_inset
4305
4306
4307 \newline
4308
4309 \newline
4310 Download the file UnxUtils
4311 \begin_inset LatexCommand \index{UnxUtils}
4312
4313 \end_inset
4314
4315 .zip.
4316  Now you have to install the utilities and setup MSVC so it can locate the
4317  required programs.
4318  Here there are two alternatives (choose one!):
4319 \end_layout
4320
4321 \begin_layout Enumerate
4322 The easy way:
4323 \newline
4324
4325 \newline
4326 a) Extract UnxUtils.zip to your C:
4327 \backslash
4328  hard disk PRESERVING the original paths, otherwise bison won't work.
4329  (If you are using WinZip make certain that 'Use folder names' is selected)
4330 \newline
4331
4332 \newline
4333 b)
4334  In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4335  'Show directories for:' select 'Executable files', and in the directories
4336  window add a new path: 'C:
4337 \backslash
4338 user
4339 \backslash
4340 local
4341 \backslash
4342 wbin', click ok.
4343 \newline
4344
4345 \newline
4346 (As a side effect, you get a bunch of Unix utilities that
4347  could be useful, such as diff and patch.)
4348 \end_layout
4349
4350 \begin_layout Enumerate
4351 A more compact way:
4352 \newline
4353
4354 \newline
4355 This one avoids extracting a bunch of files you may not
4356  use, but requires some extra work:
4357 \newline
4358
4359 \newline
4360 a) Create a directory were to put the
4361  tools needed, or use a directory already present.
4362  Say for example 'C:
4363 \backslash
4364 util'.
4365 \newline
4366
4367 \newline
4368 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4369  gawk.exe to such directory WITHOUT preserving the original paths.
4370  (If you are using WinZip make certain that 'Use folder names' is not selected)
4371 \newline
4372
4373 \newline
4374 c
4375 ) Rename bison.exe to '_bison.exe'.
4376 \newline
4377
4378 \newline
4379 d) Create a batch file 'bison.bat' in 'C:
4380 \backslash
4381 util
4382 \backslash
4383 ' and add these lines: 
4384 \newline
4385 \InsetSpace ~
4386 \InsetSpace ~
4387 set BISON_SIMPLE=C:
4388 \backslash
4389 util
4390 \backslash
4391 bison.simple 
4392 \newline
4393 \InsetSpace ~
4394 \InsetSpace ~
4395 set BISON_HAIRY=C:
4396 \backslash
4397 util
4398 \backslash
4399 bison.hairy
4400 \newline
4401 \InsetSpace ~
4402 \InsetSpace ~
4403 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4404 \newline
4405
4406 \newline
4407 Steps 'c' and 'd' are needed
4408  because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4409  reside in some weird Unix directory, '/usr/local/share/' I think.
4410  So it is necessary to tell bison where those files are located if they
4411  are not in such directory.
4412  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4413 \newline
4414
4415 \newline
4416 e
4417 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4418  in 'Show directories for:' select 'Executable files', and in the directories
4419  window add a new path: 'c:
4420 \backslash
4421 util', click ok.
4422  Note that you can use any other path instead of 'c:
4423 \backslash
4424 util', even the path where the Visual C++ tools are, probably: 'C:
4425 \backslash
4426 Program Files
4427 \backslash
4428 Microsoft Visual Studio
4429 \backslash
4430 Common
4431 \backslash
4432 Tools'.
4433  So you don't have to execute step 'e' :)
4434 \end_layout
4435
4436 \begin_layout Standard
4437 That is it.
4438  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4439  the executables from sdcc
4440 \backslash
4441 bin_vc to sdcc
4442 \backslash
4443 bin, and you can compile using SDCC.
4444 \end_layout
4445
4446 \begin_layout Subsection
4447 Building SDCC Using Borland
4448 \end_layout
4449
4450 \begin_layout Enumerate
4451 From the sdcc directory, run the command "make -f Makefile.bcc".
4452  This should regenerate all the .exe files in the bin directory except for
4453  SDCDB and ucSim.
4454 \end_layout
4455
4456 \begin_layout Enumerate
4457 If you modify any source files and need to rebuild, be aware that the dependenci
4458 es may not be correctly calculated.
4459  The safest option is to delete all .obj files and run the build again.
4460  From a Cygwin BASH prompt, this can easily be done with the command (be
4461  sure you are in the sdcc directory):
4462 \newline
4463
4464 \newline
4465
4466 \family sans
4467 \series bold
4468 find .
4469  
4470 \backslash
4471 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
4472 \backslash
4473 ) -print -exec rm {} 
4474 \backslash
4475 ;
4476 \family default
4477 \series default
4478
4479 \newline
4480
4481 \newline
4482 or on Windows NT/2000/XP from the command prompt with the command:
4483 \newline
4484
4485 \family sans
4486 \series bold
4487
4488 \newline
4489 del /s *.obj *.lib *.rul
4490 \family default
4491 \series default
4492  from the sdcc directory.
4493 \end_layout
4494
4495 \begin_layout Subsection
4496 Windows Install Using a ZIP Package
4497 \end_layout
4498
4499 \begin_layout Enumerate
4500 Download the binary zip package from 
4501 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4502
4503 \end_inset
4504
4505  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4506  This should unpack to a group of sub-directories.
4507  An example directory structure after unpacking the mingw32 package is:
4508  c:
4509 \backslash
4510 sdcc
4511 \backslash
4512 bin for the executables, c:
4513 \backslash
4514 sdcc
4515 \backslash
4516 include and c:
4517 \backslash
4518 sdcc
4519 \backslash
4520 lib for the include and libraries.
4521 \end_layout
4522
4523 \begin_layout Enumerate
4524 Adjust your environment variable PATH to include the location of the bin
4525  directory or start sdcc using the full path.
4526 \end_layout
4527
4528 \begin_layout Subsection
4529 Windows Install Using the Setup Program
4530 \begin_inset LatexCommand \label{sub:Windows-Install}
4531
4532 \end_inset
4533
4534
4535 \end_layout
4536
4537 \begin_layout Standard
4538 Download the setup program 
4539 \emph on
4540 sdcc-x.y.z-setup.exe
4541 \emph default
4542  for an official release from 
4543 \newline
4544
4545 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4546
4547 \end_inset
4548
4549  or a setup program for one of the snapshots 
4550 \emph on
4551 sdcc-yyyymmdd-xxxx-setup.exe
4552 \emph default
4553  from 
4554 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4555
4556 \end_inset
4557
4558  and execute it.
4559  A windows typical installer will guide you through the installation process.
4560 \end_layout
4561
4562 \begin_layout Subsection
4563 VPATH
4564 \begin_inset LatexCommand \index{VPATH}
4565
4566 \end_inset
4567
4568  feature
4569 \end_layout
4570
4571 \begin_layout Standard
4572 SDCC supports the VPATH feature provided by configure and make.
4573  It allows to separate the source and build trees.
4574  Here's an example:
4575 \end_layout
4576
4577 \begin_layout Standard
4578
4579 \family typewriter
4580 cd ~\InsetSpace ~
4581 \InsetSpace ~
4582 \InsetSpace ~
4583 \InsetSpace ~
4584 \InsetSpace ~
4585 \InsetSpace ~
4586 \InsetSpace ~
4587 \InsetSpace ~
4588 \InsetSpace ~
4589 \InsetSpace ~
4590 \InsetSpace ~
4591 \InsetSpace ~
4592 \InsetSpace ~
4593 \InsetSpace ~
4594 \InsetSpace ~
4595 \InsetSpace ~
4596 \InsetSpace ~
4597 \InsetSpace ~
4598 \InsetSpace ~
4599 \InsetSpace ~
4600 \InsetSpace ~
4601 # cd $HOME
4602 \end_layout
4603
4604 \begin_layout Standard
4605
4606 \family typewriter
4607 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4608 # extract source to directory sdcc
4609 \end_layout
4610
4611 \begin_layout Standard
4612
4613 \family typewriter
4614 mkdir sdcc.build\InsetSpace ~
4615 \InsetSpace ~
4616 \InsetSpace ~
4617 \InsetSpace ~
4618 \InsetSpace ~
4619 \InsetSpace ~
4620 \InsetSpace ~
4621 \InsetSpace ~
4622 \InsetSpace ~
4623 # put output in sdcc.build
4624 \end_layout
4625
4626 \begin_layout Standard
4627
4628 \family typewriter
4629 cd sdcc.build
4630 \end_layout
4631
4632 \begin_layout Standard
4633
4634 \family typewriter
4635 ../sdcc/configure\InsetSpace ~
4636 \InsetSpace ~
4637 \InsetSpace ~
4638 \InsetSpace ~
4639 \InsetSpace ~
4640 \InsetSpace ~
4641 \InsetSpace ~
4642 \InsetSpace ~
4643 # configure is doing all the magic!
4644 \end_layout
4645
4646 \begin_layout Standard
4647
4648 \family typewriter
4649 make
4650 \end_layout
4651
4652 \begin_layout Standard
4653 \noindent
4654 That's it! 
4655 \series bold
4656 configure
4657 \series default
4658  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4659  It automagically computes the variables srcdir, top_srcdir and top_buildir
4660  for each directory.
4661  After running 
4662 \series bold
4663 make
4664 \series default
4665  the generated files will be in ~/sdcc.build, while the source files stay
4666  in ~/sdcc.
4667 \newline
4668 This is not only usefull for building different binaries, e.g.
4669  when cross compiling.
4670  It also gives you a much better overview in the source tree when all the
4671  generated files are not scattered between the source files.
4672  And the best thing is: if you want to change a file you can leave the original
4673  file untouched in the source directory.
4674  Simply copy it to the build directory, edit it, enter `make clean', `rm
4675  Makefile.dep' and `make'.
4676  
4677 \series bold
4678 make
4679 \series default
4680  will do the rest for you!
4681 \end_layout
4682
4683 \begin_layout Section
4684 Building the Documentation
4685 \end_layout
4686
4687 \begin_layout Standard
4688 Add -
4689 \begin_inset ERT
4690 status collapsed
4691
4692 \begin_layout Standard
4693
4694
4695 \backslash
4696 /
4697 \end_layout
4698
4699 \end_inset
4700
4701 -enable-doc to the configure arguments to build the documentation together
4702  with all the other stuff.
4703  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4704  dvips and makeindex) to get the job done.
4705  Another possibility is to change to the doc directory and to type 
4706 \family sans
4707 \series bold
4708
4709 \begin_inset Quotes srd
4710 \end_inset
4711
4712 make
4713 \begin_inset Quotes srd
4714 \end_inset
4715
4716
4717 \family default
4718 \series default
4719  there.
4720  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4721 x).
4722  Using LyX 
4723 \begin_inset LatexCommand \url{http://www.lyx.org}
4724
4725 \end_inset
4726
4727  as editor is straightforward.
4728  Prebuilt documentation in html and pdf format is available from 
4729 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4730
4731 \end_inset
4732
4733 .
4734 \end_layout
4735
4736 \begin_layout Section
4737 Reading the Documentation
4738 \begin_inset LatexCommand \index{Documentation}
4739
4740 \end_inset
4741
4742
4743 \end_layout
4744
4745 \begin_layout Standard
4746 Currently reading the document in pdf format is recommended, as for unknown
4747  reason the hyperlinks are working there whereas in the html version they
4748  are not
4749 \begin_inset Foot
4750 status open
4751
4752 \begin_layout Standard
4753 If you should know why please drop us a note
4754 \end_layout
4755
4756 \end_inset
4757
4758 .
4759  
4760 \newline
4761 You'll find the pdf version
4762 \begin_inset LatexCommand \index{PDF version of this document}
4763
4764 \end_inset
4765
4766  at 
4767 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4768
4769 \end_inset
4770
4771 .
4772  
4773 \newline
4774 A html version
4775 \begin_inset LatexCommand \index{HTML version of this document}
4776
4777 \end_inset
4778
4779  should be online at 
4780 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4781
4782 \end_inset
4783
4784 .
4785 \newline
4786 This documentation is in some aspects different from a commercial documentation:
4787  
4788 \end_layout
4789
4790 \begin_layout Itemize
4791 It tries to document SDCC for several processor architectures in one document
4792  (commercially these probably would be separate documents/products).
4793  This document
4794 \begin_inset LatexCommand \index{Status of documentation}
4795
4796 \end_inset
4797
4798  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4799 on about f.e.
4800  Z80, PIC14, PIC16 and HC08.
4801 \end_layout
4802
4803 \begin_layout Itemize
4804 There are many references pointing away from this documentation.
4805  Don't let this distract you.
4806  If there f.e.
4807  was a reference like 
4808 \begin_inset LatexCommand \url{http://www.opencores.org}
4809
4810 \end_inset
4811
4812  together with a statement 
4813 \begin_inset Quotes sld
4814 \end_inset
4815
4816 some processors which are targetted by SDCC can be implemented in a 
4817 \emph on
4818 f
4819 \emph default
4820 ield 
4821 \emph on
4822 p
4823 \emph default
4824 rogrammable 
4825 \emph on
4826 g
4827 \emph default
4828 ate 
4829 \emph on
4830 a
4831 \emph default
4832 rray
4833 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4834
4835 \end_inset
4836
4837
4838 \begin_inset Quotes srd
4839 \end_inset
4840
4841  or 
4842 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4843
4844 \end_inset
4845
4846
4847 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4848
4849 \end_inset
4850
4851  
4852 \begin_inset Quotes sld
4853 \end_inset
4854
4855 have you ever heard of an open source compiler that compiles a subset of
4856  C for an FPGA?
4857 \begin_inset Quotes srd
4858 \end_inset
4859
4860  we expect you to have a quick look there and come back.
4861  If you read this you are on the right track.
4862 \end_layout
4863
4864 \begin_layout Itemize
4865 Some sections attribute more space to problems, restrictions and warnings
4866  than to the solution.
4867 \end_layout
4868
4869 \begin_layout Itemize
4870 The installation section and the section about the debugger is intimidating.
4871 \end_layout
4872
4873 \begin_layout Itemize
4874 There are still lots of typos and there are more different writing styles
4875  than pictures.
4876 \end_layout
4877
4878 \begin_layout Section
4879 Testing the SDCC Compiler
4880 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4881
4882 \end_inset
4883
4884
4885 \end_layout
4886
4887 \begin_layout Standard
4888 The first thing you should do after installing your SDCC compiler is to
4889  see if it runs.
4890  Type 
4891 \family sans
4892 \series bold
4893 "sdcc -
4894 \begin_inset ERT
4895 status collapsed
4896
4897 \begin_layout Standard
4898
4899
4900 \backslash
4901 /
4902 \end_layout
4903
4904 \end_inset
4905
4906 -version"
4907 \begin_inset LatexCommand \index{version}
4908
4909 \end_inset
4910
4911
4912 \family default
4913 \series default
4914  at the prompt, and the program should run and output its version like:
4915  
4916 \newline
4917
4918 \family typewriter
4919 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4920  (UNIX)
4921 \end_layout
4922
4923 \begin_layout Standard
4924 If it doesn't run, or gives a message about not finding sdcc program, then
4925  you need to check over your installation.
4926  Make sure that the sdcc bin directory is in your executable search path
4927  defined by the PATH environment setting (
4928 \series medium
4929 see 
4930 \series default
4931 section 
4932 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4933
4934 \end_inset
4935
4936 \InsetSpace ~
4937
4938 \series medium
4939 Install trouble-shooting for suggestions
4940 \series default
4941 ).
4942  Make sure that the sdcc program is in the bin folder, if not perhaps something
4943  did not install correctly.
4944 \newline
4945
4946 \newline
4947
4948 \series medium
4949 SDCC 
4950 \series default
4951 is commonly installed as described in section 
4952 \begin_inset Quotes sld
4953 \end_inset
4954
4955 Install and search paths
4956 \begin_inset Quotes srd
4957 \end_inset
4958
4959 .
4960 \newline
4961
4962 \newline
4963
4964 \series medium
4965 Make sure the compiler works on a very simple example.
4966  Type in the following test.c program using your favorite 
4967 \series default
4968 ASCII 
4969 \series medium
4970 editor:
4971 \end_layout
4972
4973 \begin_layout Verse
4974
4975 \family typewriter
4976 char test;
4977 \newline
4978
4979 \newline
4980 void main(void) {
4981 \newline
4982 \InsetSpace ~
4983 \InsetSpace ~
4984 \InsetSpace ~
4985 \InsetSpace ~
4986 test=0;
4987 \newline
4988 }
4989 \end_layout
4990
4991 \begin_layout Standard
4992
4993 \series medium
4994 Compile this using the following command: 
4995 \family sans
4996 \series bold
4997 "sdcc -c test.c".
4998
4999 \family default
5000 \series default
5001  
5002 \series medium
5003 If all goes well, the compiler will generate a test.asm and test.rel file.
5004  Congratulations, you've just compiled your first program with SDCC.
5005  We used the -c option to tell SDCC not to link the generated code, just
5006  to keep things simple for this step.
5007 \series default
5008
5009 \newline
5010
5011 \newline
5012
5013 \series medium
5014 The next step is to try it with the linker.
5015  Type in 
5016 \family sans
5017 \series bold
5018 "sdcc test.c
5019 \family default
5020 \series default
5021 "
5022 \series medium
5023 .
5024  If all goes well the compiler will link with the libraries and produce
5025  a test.ihx output file.
5026  If this step fails
5027 \series default
5028  
5029 \series medium
5030 (no test.ihx, and the linker generates warnings), then the problem is most
5031  likely that 
5032 \series default
5033 SDCC
5034 \series medium
5035  cannot find the 
5036 \series default
5037 /
5038 \series medium
5039 usr/local/share/sdcc/lib directory
5040 \series default
5041  
5042 \series medium
5043 (see 
5044 \series default
5045 section 
5046 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5047
5048 \end_inset
5049
5050 \InsetSpace ~
5051
5052 \series medium
5053 Install trouble-shooting for suggestions).
5054 \series default
5055
5056 \newline
5057
5058 \newline
5059
5060 \series medium
5061 The final test is to ensure 
5062 \series default
5063 SDCC
5064 \series medium
5065  can use the 
5066 \series default
5067 standard
5068 \series medium
5069  header files and libraries.
5070  Edit test.c and change it to the following:
5071 \end_layout
5072
5073 \begin_layout Verse
5074
5075 \family typewriter
5076 #include <string.h>
5077 \newline
5078
5079 \newline
5080 char str1[10];
5081 \newline
5082
5083 \newline
5084 void main(void) {
5085 \newline
5086 \InsetSpace ~
5087 \InsetSpace ~
5088 strcpy(str1, "testing");
5089 \newline
5090 }
5091 \end_layout
5092
5093 \begin_layout Standard
5094
5095 \series medium
5096 Compile this by typing 
5097 \family sans
5098 \series bold
5099 "sdcc test.c"
5100 \family default
5101 \series medium
5102 .
5103  This should generate a test.ihx output file, and it should give no warnings
5104  such as not finding the string.h file.
5105  If it cannot find the string.h file, then the problem is that 
5106 \series default
5107 SDCC
5108 \series medium
5109  cannot find the /usr/local/share/sdcc/include directory
5110 \series default
5111  
5112 \series medium
5113 (see the 
5114 \series default
5115 section 
5116 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5117
5118 \end_inset
5119
5120 \InsetSpace ~
5121
5122 \series medium
5123 Install trouble-shooting section for suggestions).
5124
5125 \series default
5126  Use option 
5127 \series bold
5128 -
5129 \begin_inset ERT
5130 status collapsed
5131
5132 \begin_layout Standard
5133
5134
5135 \backslash
5136 /
5137 \end_layout
5138
5139 \end_inset
5140
5141 -print-search-dirs
5142 \series default
5143
5144 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5145
5146 \end_inset
5147
5148  to find exactly where SDCC is looking for the include and lib files.
5149 \end_layout
5150
5151 \begin_layout Section
5152 Install Trouble-shooting
5153 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5154
5155 \end_inset
5156
5157
5158 \begin_inset LatexCommand \index{Install trouble-shooting}
5159
5160 \end_inset
5161
5162
5163 \end_layout
5164
5165 \begin_layout Subsection
5166 If SDCC does not build correctly
5167 \end_layout
5168
5169 \begin_layout Standard
5170 A thing to try is starting from scratch by unpacking the .tgz source package
5171  again in an empty directory.
5172  Configure it like:
5173 \newline
5174
5175 \newline
5176
5177 \family sans
5178 \series bold
5179 ./configure 2>&1 | tee configure.log
5180 \family default
5181 \series default
5182
5183 \newline
5184
5185 \newline
5186 and build it like:
5187 \newline
5188
5189 \newline
5190
5191 \family sans
5192 \series bold
5193 make 2>&1 | tee make.log
5194 \family default
5195 \series default
5196
5197 \newline
5198
5199 \newline
5200 If anything goes wrong, you can review the log files to locate the problem.
5201  Or a relevant part of this can be attached to an email that could be helpful
5202  when requesting help from the mailing list.
5203 \end_layout
5204
5205 \begin_layout Subsection
5206 What the 
5207 \begin_inset Quotes sld
5208 \end_inset
5209
5210 ./configure
5211 \begin_inset Quotes srd
5212 \end_inset
5213
5214  does
5215 \end_layout
5216
5217 \begin_layout Standard
5218 The 
5219 \begin_inset Quotes sld
5220 \end_inset
5221
5222 ./configure
5223 \begin_inset Quotes srd
5224 \end_inset
5225
5226  command is a script that analyzes your system and performs some configuration
5227  to ensure the source package compiles on your system.
5228  It will take a few minutes to run, and will compile a few tests to determine
5229  what compiler features are installed.
5230 \end_layout
5231
5232 \begin_layout Subsection
5233 What the 
5234 \begin_inset Quotes sld
5235 \end_inset
5236
5237 make
5238 \begin_inset Quotes srd
5239 \end_inset
5240
5241  does
5242 \end_layout
5243
5244 \begin_layout Standard
5245 This runs the GNU make tool, which automatically compiles all the source
5246  packages into the final installed binary executables.
5247 \end_layout
5248
5249 \begin_layout Subsection
5250 What the 
5251 \begin_inset Quotes sld
5252 \end_inset
5253
5254 make install
5255 \begin_inset Quotes erd
5256 \end_inset
5257
5258  command does.
5259 \end_layout
5260
5261 \begin_layout Standard
5262 This will install the compiler, other executables libraries and include
5263  files into the appropriate directories.
5264  See sections 
5265 \begin_inset LatexCommand \ref{sub:Install-paths}
5266
5267 \end_inset
5268
5269 ,\InsetSpace ~
5270
5271 \begin_inset LatexCommand \ref{sub:Search-Paths}
5272
5273 \end_inset
5274
5275 \InsetSpace ~
5276 about install and search paths.
5277 \newline
5278 On most systems you will need super-user privilege
5279 s to do this.
5280 \end_layout
5281
5282 \begin_layout Section
5283 Components of SDCC
5284 \end_layout
5285
5286 \begin_layout Standard
5287 SDCC is not just a compiler, but a collection of tools by various developers.
5288  These include linkers, assemblers, simulators and other components.
5289  Here is a summary of some of the components.
5290  Note that the included simulator and assembler have separate documentation
5291  which you can find in the source package in their respective directories.
5292  As SDCC grows to include support for other processors, other packages from
5293  various developers are included and may have their own sets of documentation.
5294 \newline
5295
5296 \newline
5297 You
5298  might want to look at the files which are installed in <installdir>.
5299  At the time of this writing, we find the following programs for gcc-builds:
5300 \newline
5301
5302  
5303 \newline
5304 In <installdir>/bin:
5305 \end_layout
5306
5307 \begin_layout Itemize
5308 sdcc - The compiler.
5309 \end_layout
5310
5311 \begin_layout Itemize
5312 sdcpp - The C preprocessor.
5313 \end_layout
5314
5315 \begin_layout Itemize
5316 asx8051 - The assembler for 8051 type processors.
5317 \end_layout
5318
5319 \begin_layout Itemize
5320 as-z80
5321 \series bold
5322
5323 \series default
5324 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5325 \end_layout
5326
5327 \begin_layout Itemize
5328 aslink -The linker for 8051 type processors.
5329 \end_layout
5330
5331 \begin_layout Itemize
5332 link-z80
5333 \series bold
5334
5335 \series default
5336 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5337 \end_layout
5338
5339 \begin_layout Itemize
5340 s51 - The ucSim 8051 simulator.
5341 \end_layout
5342
5343 \begin_layout Itemize
5344 sdcdb - The source debugger.
5345 \end_layout
5346
5347 \begin_layout Itemize
5348 packihx - A tool to pack (compress) Intel hex files.
5349 \end_layout
5350
5351 \begin_layout Standard
5352 In <installdir>/share/sdcc/include
5353 \end_layout
5354
5355 \begin_layout Itemize
5356 the include files
5357 \end_layout
5358
5359 \begin_layout Standard
5360 In <installdir>/share/sdcc/lib
5361 \end_layout
5362
5363 \begin_layout Itemize
5364 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5365  relocatables.
5366 \end_layout
5367
5368 \begin_layout Standard
5369 In <installdir>/share/sdcc/doc
5370 \end_layout
5371
5372 \begin_layout Itemize
5373 the documentation
5374 \end_layout
5375
5376 \begin_layout Standard
5377 As development for other processors proceeds, this list will expand to include
5378  executables to support processors like AVR, PIC, etc.
5379 \end_layout
5380
5381 \begin_layout Subsection
5382 sdcc - The Compiler
5383 \end_layout
5384
5385 \begin_layout Standard
5386 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5387  the assembler and linkage editor.
5388 \end_layout
5389
5390 \begin_layout Subsection
5391 sdcpp - The C-Preprocessor
5392 \end_layout
5393
5394 \begin_layout Standard
5395 The preprocessor
5396 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5397
5398 \end_inset
5399
5400  is a modified version of the GNU cpp
5401 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5402
5403 \end_inset
5404
5405  preprocessor 
5406 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5407
5408 \end_inset
5409
5410 .
5411  The C preprocessor is used to pull in #include sources, process #ifdef
5412  statements, #defines and so on.
5413 \end_layout
5414
5415 \begin_layout Subsection
5416 as
5417 \emph on
5418 xxxx
5419 \emph default
5420 , aslink, link-
5421 \emph on
5422 xxx
5423 \emph default
5424  - The Assemblers and Linkage Editors
5425 \end_layout
5426
5427 \begin_layout Standard
5428 This is retargettable assembler & linkage editor, it was developed by Alan
5429  Baldwin.
5430  John Hartman created the version for 8051, and I (Sandeep) have made some
5431  enhancements and bug fixes for it to work properly with SDCC.
5432 \end_layout
5433
5434 \begin_layout Subsection
5435 s51 - The Simulator
5436 \end_layout
5437
5438 \begin_layout Standard
5439 S51
5440 \begin_inset LatexCommand \index{s51}
5441
5442 \end_inset
5443
5444  is a free open source simulator developed by Daniel Drotos.
5445  The simulator is built as part of the build process.
5446  For more information visit Daniel's web site at: 
5447 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5448
5449 \end_inset
5450
5451 .
5452  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5453  XA51 family.
5454 \end_layout
5455
5456 \begin_layout Subsection
5457 sdcdb - Source Level Debugger
5458 \end_layout
5459
5460 \begin_layout Standard
5461 SDCDB
5462 \begin_inset LatexCommand \index{SDCDB (debugger)}
5463
5464 \end_inset
5465
5466  is the companion source level debugger.
5467  More about SDCDB in section 
5468 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5469
5470 \end_inset
5471
5472 .
5473  The current version of the debugger uses Daniel's Simulator S51
5474 \begin_inset LatexCommand \index{s51}
5475
5476 \end_inset
5477
5478 , but can be easily changed to use other simulators.
5479 \end_layout
5480
5481 \begin_layout Chapter
5482 Using SDCC
5483 \end_layout
5484
5485 \begin_layout Section
5486 Compiling
5487 \end_layout
5488
5489 \begin_layout Subsection
5490 Single Source File Projects
5491 \end_layout
5492
5493 \begin_layout Standard
5494 For single source file 8051 projects the process is very simple.
5495  Compile your programs with the following command 
5496 \family sans
5497 \series bold
5498 "sdcc sourcefile.c".
5499
5500 \family default
5501 \series default
5502  This will compile, assemble and link your source file.
5503  Output files are as follows:
5504 \end_layout
5505
5506 \begin_layout Itemize
5507 sourcefile.asm
5508 \begin_inset LatexCommand \index{<file>.asm}
5509
5510 \end_inset
5511
5512  - Assembler source
5513 \begin_inset LatexCommand \index{Assembler source}
5514
5515 \end_inset
5516
5517  file created by the compiler
5518 \end_layout
5519
5520 \begin_layout Itemize
5521 sourcefile.lst
5522 \begin_inset LatexCommand \index{<file>.lst}
5523
5524 \end_inset
5525
5526  - Assembler listing
5527 \begin_inset LatexCommand \index{Assembler listing}
5528
5529 \end_inset
5530
5531  file created by the Assembler
5532 \end_layout
5533
5534 \begin_layout Itemize
5535 sourcefile.rst
5536 \begin_inset LatexCommand \index{<file>.rst}
5537
5538 \end_inset
5539
5540  - Assembler listing
5541 \begin_inset LatexCommand \index{Assembler listing}
5542
5543 \end_inset
5544
5545  file updated with linkedit information, created by linkage editor
5546 \end_layout
5547
5548 \begin_layout Itemize
5549 sourcefile.sym
5550 \begin_inset LatexCommand \index{<file>.sym}
5551
5552 \end_inset
5553
5554  - symbol listing
5555 \begin_inset LatexCommand \index{Symbol listing}
5556
5557 \end_inset
5558
5559  for the sourcefile, created by the assembler
5560 \end_layout
5561
5562 \begin_layout Itemize
5563 sourcefile.rel
5564 \begin_inset LatexCommand \index{<file>.rel}
5565
5566 \end_inset
5567
5568  or sourcefile.o
5569 \begin_inset LatexCommand \index{<file>.o}
5570
5571 \end_inset
5572
5573  - Object file
5574 \begin_inset LatexCommand \index{Object file}
5575
5576 \end_inset
5577
5578  created by the assembler, input to Linkage editor
5579 \end_layout
5580
5581 \begin_layout Itemize
5582 sourcefile.map
5583 \begin_inset LatexCommand \index{<file>.map}
5584
5585 \end_inset
5586
5587  - The memory map
5588 \begin_inset LatexCommand \index{Memory map}
5589
5590 \end_inset
5591
5592  for the load module, created by the Linker
5593 \end_layout
5594
5595 \begin_layout Itemize
5596 sourcefile.mem
5597 \begin_inset LatexCommand \index{<file>.mem}
5598
5599 \end_inset
5600
5601  - A file with a summary of the memory usage
5602 \end_layout
5603
5604 \begin_layout Itemize
5605 sourcefile.ihx
5606 \begin_inset LatexCommand \index{<file>.ihx}
5607
5608 \end_inset
5609
5610  - The load module in Intel hex format
5611 \begin_inset LatexCommand \index{Intel hex format}
5612
5613 \end_inset
5614
5615  (you can select the Motorola S19 format
5616 \begin_inset LatexCommand \index{Motorola S19 format}
5617
5618 \end_inset
5619
5620  with -
5621 \begin_inset ERT
5622 status collapsed
5623
5624 \begin_layout Standard
5625
5626
5627 \backslash
5628 /
5629 \end_layout
5630
5631 \end_inset
5632
5633 -out-fmt-s19
5634 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5635
5636 \end_inset
5637
5638 .
5639  If you need another format you might want to use 
5640 \family sans
5641 \shape italic
5642 objdump
5643 \family default
5644 \shape default
5645
5646 \begin_inset LatexCommand \index{objdump (tool)}
5647
5648 \end_inset
5649
5650  or
5651 \family sans
5652 \shape italic
5653  srecord
5654 \family default
5655 \shape default
5656
5657 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5658
5659 \end_inset
5660
5661
5662 \begin_inset Note Note
5663 status collapsed
5664
5665 \begin_layout Standard
5666 hyperlinks needed
5667 \end_layout
5668
5669 \end_inset
5670
5671  - see also section 
5672 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5673
5674 \end_inset
5675
5676 ).
5677  Both formats are documented in the documentation of srecord
5678 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5679
5680 \end_inset
5681
5682
5683 \end_layout
5684
5685 \begin_layout Itemize
5686 sourcefile.adb
5687 \begin_inset LatexCommand \index{<file>.adb}
5688
5689 \end_inset
5690
5691  - An intermediate file containing debug information needed to create the
5692  .cdb file (with -
5693 \begin_inset ERT
5694 status collapsed
5695
5696 \begin_layout Standard
5697
5698
5699 \backslash
5700 /
5701 \end_layout
5702
5703 \end_inset
5704
5705 -debug
5706 \begin_inset LatexCommand \index{-\/-debug}
5707
5708 \end_inset
5709
5710
5711 \end_layout
5712
5713 \begin_layout Itemize
5714 sourcefile.cdb
5715 \begin_inset LatexCommand \index{<file>.cdb}
5716
5717 \end_inset
5718
5719  - An optional file (with -
5720 \begin_inset ERT
5721 status collapsed
5722
5723 \begin_layout Standard
5724
5725
5726 \backslash
5727 /
5728 \end_layout
5729
5730 \end_inset
5731
5732 -debug) containing debug information.
5733  The format is documented in cdbfileformat.pdf
5734 \end_layout
5735
5736 \begin_layout Itemize
5737 sourcefile.
5738  - (no extension)
5739 \begin_inset LatexCommand \index{<file> (no extension)}
5740
5741 \end_inset
5742
5743  An optional AOMF or AOMF51
5744 \begin_inset LatexCommand \index{AOMF, AOMF51}
5745
5746 \end_inset
5747
5748  
5749 \begin_inset LatexCommand \label{OMF file}
5750
5751 \end_inset
5752
5753 file containing debug information (generated with option -
5754 \begin_inset ERT
5755 status collapsed
5756
5757 \begin_layout Standard
5758
5759
5760 \backslash
5761 /
5762 \end_layout
5763
5764 \end_inset
5765
5766 -debug).
5767  The (Intel)
5768 \emph on
5769  a
5770 \emph default
5771 bsolute 
5772 \emph on
5773 o
5774 \emph default
5775 bject 
5776 \emph on
5777 m
5778 \emph default
5779 odule 
5780 \emph on
5781 f
5782 \emph default
5783 ormat is a subformat of the OMF51 format and is commonly used by third party
5784  tools (debuggers
5785 \begin_inset LatexCommand \index{Debugger}
5786
5787 \end_inset
5788
5789 , simulators, emulators).
5790 \end_layout
5791
5792 \begin_layout Itemize
5793 sourcefile.dump*
5794 \begin_inset LatexCommand \index{<file>.dump*}
5795
5796 \end_inset
5797
5798  - Dump file to debug the compiler it self (generated with option -
5799 \begin_inset ERT
5800 status collapsed
5801
5802 \begin_layout Standard
5803
5804
5805 \backslash
5806 /
5807 \end_layout
5808
5809 \end_inset
5810
5811 -dumpall) (see section 
5812 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5813
5814 \end_inset
5815
5816 \InsetSpace ~
5817  and section 
5818 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5819
5820 \end_inset
5821
5822 \InsetSpace ~
5823
5824 \begin_inset Quotes sld
5825 \end_inset
5826
5827 Anatomy of the compiler
5828 \begin_inset Quotes srd
5829 \end_inset
5830
5831 ).
5832 \end_layout
5833
5834 \begin_layout Subsection
5835 Postprocessing the Intel Hex
5836 \begin_inset LatexCommand \index{Intel hex format}
5837
5838 \end_inset
5839
5840  file
5841 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5842
5843 \end_inset
5844
5845
5846 \end_layout
5847
5848 \begin_layout Standard
5849 In most cases this won't be needed but the Intel Hex file
5850 \begin_inset LatexCommand \index{<file>.ihx}
5851
5852 \end_inset
5853
5854  which is generated by SDCC might include lines of varying length and the
5855  addresses within the file are not guaranteed to be strictly ascending.
5856  If your toolchain or a bootloader does not like this you can use the tool
5857  
5858 \family typewriter
5859 packihx
5860 \family default
5861
5862 \begin_inset LatexCommand \index{packihx (tool)}
5863
5864 \end_inset
5865
5866  which is part of the SDCC distribution: 
5867 \newline
5868
5869 \newline
5870
5871 \family sans
5872 \series bold
5873  packihx sourcefile.ihx >sourcefile.hex
5874 \family default
5875 \series default
5876
5877 \newline
5878
5879 \newline
5880 The separately available
5881 \emph on
5882  srecord
5883 \emph default
5884
5885 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5886
5887 \end_inset
5888
5889  package additionally allows to set undefined locations to a predefined
5890  value, to insert checksums
5891 \begin_inset LatexCommand \index{checksum}
5892
5893 \end_inset
5894
5895  of various flavours (crc, add, xor) and to perform other manipulations
5896  (convert, split, crop, offset, ...).
5897  
5898 \newline
5899
5900 \newline
5901
5902 \family sans
5903 \series bold
5904 srec_cat\InsetSpace ~
5905 \InsetSpace ~
5906 sourcefile.ihx -intel\InsetSpace ~
5907 \InsetSpace ~
5908 -o sourcefile.hex -intel
5909 \newline
5910
5911 \newline
5912
5913 \family default
5914 \series default
5915 An example for a more complex command line
5916 \begin_inset Foot
5917 status open
5918
5919 \begin_layout Standard
5920 the command backfills
5921 \begin_inset LatexCommand \index{backfill unused memory}
5922
5923 \end_inset
5924
5925  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5926  block is zero.
5927  If the program counter on an mcs51 runs wild the backfill pattern 0x12
5928  will be interpreted as an 
5929 \family typewriter
5930 lcall
5931 \family default
5932  to address 
5933 \family typewriter
5934 0x1212
5935 \family default
5936  (where an emergency routine could sit).
5937 \end_layout
5938
5939 \end_inset
5940
5941  could look like:
5942 \newline
5943
5944 \newline
5945
5946 \family sans
5947 \series bold
5948 \size footnotesize
5949 srec_cat\InsetSpace ~
5950 sourcefile.ihx -intel\InsetSpace ~
5951 \InsetSpace ~
5952 -fill 0x12 0x0000 0xfffe\InsetSpace ~
5953 -little-endian-checksum-nega
5954 tive 0xfffe 0x02 0x02\InsetSpace ~
5955 \InsetSpace ~
5956 -o sourcefile.hex -intel
5957 \size default
5958
5959 \newline
5960
5961 \newline
5962
5963 \family default
5964 \series default
5965 The srecord package is available at 
5966 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5967
5968 \end_inset
5969
5970  .
5971 \end_layout
5972
5973 \begin_layout Subsection
5974 Projects with Multiple Source Files
5975 \end_layout
5976
5977 \begin_layout Standard
5978 SDCC can compile only ONE file at a time.
5979  Let us for example assume that you have a project containing the following
5980  files:
5981 \newline
5982
5983 \newline
5984 foo1.c (contains some functions)
5985 \newline
5986 foo2.c (contains some more functions)
5987 \newline
5988 foomai
5989 n.c (contains more functions and the function main)
5990 \newline
5991
5992 \size footnotesize
5993
5994 \newline
5995
5996 \size default
5997 The first two files will need to be compiled separately with the commands:
5998 \size footnotesize
5999  
6000 \size default
6001
6002 \newline
6003
6004 \newline
6005
6006 \family sans
6007 \series bold
6008 sdcc\InsetSpace ~
6009 -c\InsetSpace ~
6010 foo1.c
6011 \family default
6012 \series default
6013 \size footnotesize
6014
6015 \newline
6016
6017 \family sans
6018 \series bold
6019 \size default
6020 sdcc\InsetSpace ~
6021 -c\InsetSpace ~
6022 foo2.c
6023 \family default
6024 \series default
6025
6026 \newline
6027
6028 \newline
6029 Then compile the source file containing the 
6030 \emph on
6031 main()
6032 \emph default
6033  function and link
6034 \begin_inset LatexCommand \index{Linker}
6035
6036 \end_inset
6037
6038  the files together with the following command: 
6039 \newline
6040
6041 \newline
6042
6043 \family sans
6044 \series bold
6045 sdcc\InsetSpace ~
6046 foomain.c\InsetSpace ~
6047 foo1.rel\InsetSpace ~
6048 foo2.rel
6049 \family default
6050 \series default
6051
6052 \begin_inset LatexCommand \index{<file>.rel}
6053
6054 \end_inset
6055
6056
6057 \newline
6058
6059 \newline
6060 Alternatively, 
6061 \emph on
6062 foomain.c 
6063 \emph default
6064 can be separately compiled as well: 
6065 \family sans
6066 \series bold
6067
6068 \newline
6069
6070 \newline
6071 sdcc\InsetSpace ~
6072 -c\InsetSpace ~
6073 foomain.c
6074 \newline
6075 sdcc foomain.rel foo1.rel foo2.rel
6076 \newline
6077
6078 \newline
6079
6080 \family default
6081 \series default
6082 The file containing the 
6083 \emph on
6084 main()
6085 \emph default
6086  function
6087 \emph on
6088  
6089 \emph default
6090 \noun on
6091 must
6092 \noun default
6093  be the 
6094 \noun on
6095 first
6096 \noun default
6097  file specified in the command line, since the linkage editor processes
6098  file in the order they are presented to it.
6099  The linker is invoked from SDCC using a script file with extension .lnk
6100 \begin_inset LatexCommand \index{<file>.lnk}
6101
6102 \end_inset
6103
6104 .
6105  You can view this file to troubleshoot linking problems such as those arising
6106  from missing libraries.
6107 \end_layout
6108
6109 \begin_layout Subsection
6110 Projects with Additional Libraries
6111 \begin_inset LatexCommand \index{Libraries}
6112
6113 \end_inset
6114
6115
6116 \end_layout
6117
6118 \begin_layout Standard
6119 Some reusable routines may be compiled into a library, see the documentation
6120  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6121  for how to create a 
6122 \emph on
6123 .lib
6124 \begin_inset LatexCommand \index{<file>.lib}
6125
6126 \end_inset
6127
6128
6129 \emph default
6130  library file.
6131  Libraries created in this manner can be included in the command line.
6132  Make sure you include the -L <library-path> option to tell the linker where
6133  to look for these files if they are not in the current directory.
6134  Here is an example, assuming you have the source file 
6135 \emph on
6136 foomain.c
6137 \emph default
6138  and a library
6139 \emph on
6140  foolib.lib
6141 \emph default
6142  in the directory 
6143 \emph on
6144 mylib
6145 \emph default
6146  (if that is not the same as your current project):
6147 \newline
6148
6149 \newline
6150
6151 \family sans
6152 \series bold
6153 sdcc foomain.c foolib.lib -L mylib
6154 \newline
6155
6156 \newline
6157
6158 \family default
6159 \series default
6160 Note here that
6161 \emph on
6162  mylib
6163 \emph default
6164  must be an absolute path name.
6165 \newline
6166
6167 \newline
6168 The most efficient way to use libraries is
6169  to keep separate modules in separate source files.
6170  The lib file now should name all the modules.rel
6171 \begin_inset LatexCommand \index{<file>.rel}
6172
6173 \end_inset
6174
6175  files.
6176  For an example see the standard library file 
6177 \emph on
6178 libsdcc.lib
6179 \emph default
6180  in the directory <installdir>/share/lib/small.
6181 \end_layout
6182
6183 \begin_layout Subsection
6184 Using sdcclib to Create and Manage Libraries
6185 \begin_inset LatexCommand \index{sdcclib}
6186
6187 \end_inset
6188
6189
6190 \end_layout
6191
6192 \begin_layout Standard
6193 Alternatively, instead of having a .rel file for each entry on the library
6194  file as described in the preceding section, sdcclib can be used to embed
6195  all the modules belonging to such library in the library file itself.
6196  This results in a larger library file, but it greatly reduces the number
6197  of disk files accessed by the linker.
6198   Additionally, the packed library file contains an index of all include
6199  modules and symbols that significantly speeds up the linking process.
6200  To display a list of options supported by sdcclib type:
6201 \newline
6202
6203 \end_layout
6204
6205 \begin_layout Standard
6206
6207 \family sans
6208 \series bold
6209 sdcclib -?
6210 \begin_inset LatexCommand \index{sdcclib}
6211
6212 \end_inset
6213
6214
6215 \newline
6216
6217 \newline
6218
6219 \family default
6220 \series default
6221 To create a new library file, start by compiling all the required modules.
6222  For example:
6223 \newline
6224
6225 \end_layout
6226
6227 \begin_layout Standard
6228
6229 \family sans
6230 \series bold
6231 sdcc -c _divsint.c
6232 \end_layout
6233
6234 \begin_layout Standard
6235
6236 \family sans
6237 \series bold
6238 sdcc -c _divuint.c
6239 \end_layout
6240
6241 \begin_layout Standard
6242
6243 \family sans
6244 \series bold
6245 sdcc -c _modsint.c
6246 \end_layout
6247
6248 \begin_layout Standard
6249
6250 \family sans
6251 \series bold
6252 sdcc -c _moduint.c
6253 \end_layout
6254
6255 \begin_layout Standard
6256
6257 \family sans
6258 \series bold
6259 sdcc -c _mulint.c
6260 \newline
6261
6262 \end_layout
6263
6264 \begin_layout Standard
6265 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6266  and _mulint.rel.
6267  The next step is to add the .rel files to the library file:
6268 \newline
6269
6270 \end_layout
6271
6272 \begin_layout Standard
6273
6274 \family sans
6275 \series bold
6276 sdcclib libint.lib _divsint.rel
6277 \family default
6278
6279 \begin_inset LatexCommand \index{sdcclib}
6280
6281 \end_inset
6282
6283
6284 \end_layout
6285
6286 \begin_layout Standard
6287
6288 \family sans
6289 \series bold
6290 sdcclib libint.lib _divuint.rel
6291 \end_layout
6292
6293 \begin_layout Standard
6294
6295 \family sans
6296 \series bold
6297 sdcclib libint.lib _modsint.rel
6298 \end_layout
6299
6300 \begin_layout Standard
6301
6302 \family sans
6303 \series bold
6304 sdcclib libint.lib _moduint.rel
6305 \end_layout
6306
6307 \begin_layout Standard
6308
6309 \family sans
6310 \series bold
6311 sdcclib libint.lib _mulint.rel
6312 \family default
6313 \series default
6314
6315 \newline
6316
6317 \end_layout
6318
6319 \begin_layout Standard
6320 Or, if you preffer:
6321 \family sans
6322 \series bold
6323
6324 \newline
6325
6326 \end_layout
6327
6328 \begin_layout Standard
6329
6330 \family sans
6331 \series bold
6332 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6333 \family default
6334 \series default
6335
6336 \newline
6337
6338 \end_layout
6339
6340 \begin_layout Standard
6341 If the file already exists in the library, it will be replaced.
6342  If a list of .rel files is available, you can tell sdcclib to add those
6343  files to a library.
6344  For example, if the file 'myliblist.txt' contains
6345 \family sans
6346 \series bold
6347
6348 \newline
6349
6350 \end_layout
6351
6352 \begin_layout Standard
6353
6354 \family sans
6355 \series bold
6356 _divsint.rel
6357 \end_layout
6358
6359 \begin_layout Standard
6360
6361 \family sans
6362 \series bold
6363 _divuint.rel
6364 \end_layout
6365
6366 \begin_layout Standard
6367
6368 \family sans
6369 \series bold
6370 _modsint.rel
6371 \end_layout
6372
6373 \begin_layout Standard
6374
6375 \family sans
6376 \series bold
6377 _moduint.rel
6378 \end_layout
6379
6380 \begin_layout Standard
6381
6382 \family sans
6383 \series bold
6384 _mulint.rel
6385 \family default
6386 \series default
6387
6388 \newline
6389
6390 \end_layout
6391
6392 \begin_layout Standard
6393 Use
6394 \family sans
6395 \series bold
6396
6397 \newline
6398
6399 \end_layout
6400
6401 \begin_layout Standard
6402
6403 \family sans
6404 \series bold
6405 sdcclib -l libint.lib myliblist.txt
6406 \family default
6407 \series default
6408
6409 \newline
6410
6411 \end_layout
6412
6413 \begin_layout Standard
6414 Additionally, you can instruct sdcclib to compiles the files before adding
6415  them to the library.
6416  This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6417  For example:
6418 \family sans
6419 \series bold
6420
6421 \newline
6422
6423 \end_layout
6424
6425 \begin_layout Standard
6426
6427 \family sans
6428 \series bold
6429 set SDCCLIB_CC=sdcc -c
6430 \end_layout
6431
6432 \begin_layout Standard
6433
6434 \family sans
6435 \series bold
6436 sdcclib -l libint.lib myliblist.txt
6437 \family default
6438 \series default
6439
6440 \newline
6441
6442 \end_layout
6443
6444 \begin_layout Standard
6445 To see what modules and symbols are included in the library, options -s
6446  and -m are available.
6447  For example:
6448 \newline
6449
6450 \newline
6451
6452 \family sans
6453 \series bold
6454 sdcclib -s libint.lib
6455 \family default
6456
6457 \begin_inset LatexCommand \index{sdcclib}
6458
6459 \end_inset
6460
6461
6462 \newline
6463
6464 \family typewriter
6465 \series default
6466 _divsint.rel:
6467 \end_layout
6468
6469 \begin_layout Standard
6470
6471 \family typewriter
6472 __divsint_a_1_1
6473 \end_layout
6474
6475 \begin_layout Standard
6476
6477 \family typewriter
6478 __divsint_PARM_2
6479 \end_layout
6480
6481 \begin_layout Standard
6482
6483 \family typewriter
6484 __divsint
6485 \newline
6486 _divuint.rel:
6487 \end_layout
6488
6489 \begin_layout Standard
6490
6491 \family typewriter
6492 __divuint_a_1_1
6493 \end_layout
6494
6495 \begin_layout Standard
6496
6497 \family typewriter
6498 __divuint_PARM_2
6499 \end_layout
6500
6501 \begin_layout Standard
6502
6503 \family typewriter
6504 __divuint_reste_1_1
6505 \end_layout
6506
6507 \begin_layout Standard
6508
6509 \family typewriter
6510 __divuint_count_1_1
6511 \end_layout
6512
6513 \begin_layout Standard
6514
6515 \family typewriter
6516 __divuint
6517 \newline
6518 _modsint.rel:
6519 \end_layout
6520
6521 \begin_layout Standard
6522
6523 \family typewriter
6524 __modsint_a_1_1
6525 \end_layout
6526
6527 \begin_layout Standard
6528
6529 \family typewriter
6530 __modsint_PARM_2
6531 \end_layout
6532
6533 \begin_layout Standard
6534
6535 \family typewriter
6536 __modsint
6537 \newline
6538 _moduint.rel:
6539 \end_layout
6540
6541 \begin_layout Standard
6542
6543 \family typewriter
6544 __moduint_a_1_1
6545 \end_layout
6546
6547 \begin_layout Standard
6548
6549 \family typewriter
6550 __moduint_PARM_2
6551 \end_layout
6552
6553 \begin_layout Standard
6554
6555 \family typewriter
6556 __moduint_count_1_1
6557 \end_layout
6558
6559 \begin_layout Standard
6560
6561 \family typewriter
6562 __moduint
6563 \newline
6564 _mulint.rel:
6565 \end_layout
6566
6567 \begin_layout Standard
6568
6569 \family typewriter
6570 __mulint_PARM_2
6571 \end_layout
6572
6573 \begin_layout Standard
6574
6575 \family typewriter
6576 __mulint
6577 \family default
6578 \series bold
6579
6580 \newline
6581
6582 \end_layout
6583
6584 \begin_layout Standard
6585 If the source files are compiled using -
6586 \begin_inset ERT
6587 status collapsed
6588
6589 \begin_layout Standard
6590
6591
6592 \backslash
6593 /
6594 \end_layout
6595
6596 \end_inset
6597
6598 -debug
6599 \begin_inset LatexCommand \index{-\/-debug}
6600
6601 \end_inset
6602
6603 , the corresponding debug information file .adb will be include in the library
6604  file as well.
6605  The library files created with sdcclib are plain text files, so they can
6606  be viewed with a text editor.
6607  It is not recomended to modify a library file created with sdcclib using
6608  a text editor, as there are file indexes numbers located accross the file
6609  used by the linker to quickly locate the required module to link.
6610  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6611  it can be safely deleted, since all the information required for linking
6612  is embedded in the library file itself.
6613  Library files created using sdcclib are used as described in the preceding
6614  sections.
6615 \begin_inset VSpace bigskip
6616 \end_inset
6617
6618
6619 \end_layout
6620
6621 \begin_layout Section
6622 Command Line Options
6623 \begin_inset LatexCommand \index{Command Line Options}
6624
6625 \end_inset
6626
6627
6628 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6629
6630 \end_inset
6631
6632
6633 \end_layout
6634
6635 \begin_layout Subsection
6636 Processor Selection Options
6637 \begin_inset LatexCommand \index{Options processor selection}
6638
6639 \end_inset
6640
6641
6642 \begin_inset LatexCommand \index{Processor selection options}
6643
6644 \end_inset
6645
6646
6647 \end_layout
6648
6649 \begin_layout List
6650 \labelwidthstring 00.00.0000
6651
6652 \series bold
6653 -mmcs51
6654 \begin_inset LatexCommand \index{-mmcs51}
6655
6656 \end_inset
6657
6658
6659 \series default
6660  Generate code for the Intel MCS51
6661 \begin_inset LatexCommand \index{MCS51}
6662
6663 \end_inset
6664
6665  family of processors.
6666  This is the default processor target.
6667 \end_layout
6668
6669 \begin_layout List
6670 \labelwidthstring 00.00.0000
6671
6672 \series bold
6673 -mds390
6674 \begin_inset LatexCommand \index{-mds390}
6675
6676 \end_inset
6677
6678
6679 \series default
6680  Generate code for the Dallas DS80C390
6681 \begin_inset LatexCommand \index{DS80C390}
6682
6683 \end_inset
6684
6685  processor.
6686 \end_layout
6687
6688 \begin_layout List
6689 \labelwidthstring 00.00.0000
6690
6691 \series bold
6692 -mds400
6693 \begin_inset LatexCommand \index{-mds400}
6694
6695 \end_inset
6696
6697
6698 \series default
6699  Generate code for the Dallas DS80C400
6700 \begin_inset LatexCommand \index{DS80C400}
6701
6702 \end_inset
6703
6704  processor.
6705 \end_layout
6706
6707 \begin_layout List
6708 \labelwidthstring 00.00.0000
6709
6710 \series bold
6711 -mhc08
6712 \begin_inset LatexCommand \index{-mhc08}
6713
6714 \end_inset
6715
6716
6717 \series default
6718  Generate code for the Freescale/Motorola HC08
6719 \begin_inset LatexCommand \index{HC08}
6720
6721 \end_inset
6722
6723  family of processors.
6724 \end_layout
6725
6726 \begin_layout List
6727 \labelwidthstring 00.00.0000
6728
6729 \series bold
6730 -mz80
6731 \begin_inset LatexCommand \index{-mz80}
6732
6733 \end_inset
6734
6735
6736 \series default
6737  Generate code for the Zilog Z80
6738 \begin_inset LatexCommand \index{Z80}
6739
6740 \end_inset
6741
6742  family of processors.
6743 \end_layout
6744
6745 \begin_layout List
6746 \labelwidthstring 00.00.0000
6747
6748 \series bold
6749 -mgbz80
6750 \begin_inset LatexCommand \index{-mgbz80}
6751
6752 \end_inset
6753
6754
6755 \series default
6756  Generate code for the GameBoy Z80
6757 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6758
6759 \end_inset
6760
6761  processor (Not actively maintained).
6762 \end_layout
6763
6764 \begin_layout List
6765 \labelwidthstring 00.00.0000
6766
6767 \series bold
6768 -mavr
6769 \begin_inset LatexCommand \index{-mavr}
6770
6771 \end_inset
6772
6773
6774 \series default
6775  Generate code for the Atmel AVR
6776 \begin_inset LatexCommand \index{AVR}
6777
6778 \end_inset
6779
6780  processor (Not maintained, not complete).
6781  AVR users should probably have a look at winavr 
6782 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6783
6784 \end_inset
6785
6786  or 
6787 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6788
6789 \end_inset
6790
6791 , which is based on AVR-port of the gcc compiler.
6792 \end_layout
6793
6794 \begin_layout Standard
6795 \begin_inset Note Note
6796 status collapsed
6797
6798 \begin_layout Standard
6799 I think it is fair to direct users there for now.
6800  Open source is also about avoiding unnecessary work .
6801  But I didn't find the 'official' link.
6802 \end_layout
6803
6804 \end_inset
6805
6806
6807 \end_layout
6808
6809 \begin_layout List
6810 \labelwidthstring 00.00.0000
6811
6812 \series bold
6813 -mpic14
6814 \begin_inset LatexCommand \index{-mpic14}
6815
6816 \end_inset
6817
6818
6819 \series default
6820  Generate code for the Microchip PIC 14
6821 \begin_inset LatexCommand \index{PIC14}
6822
6823 \end_inset
6824
6825 -bit processors (p16f84 and variants.
6826  In development, not complete).
6827 \end_layout
6828
6829 \begin_layout Standard
6830 \begin_inset Note Note
6831 status collapsed
6832
6833 \begin_layout Standard
6834 p16f627 p16f628 p16f84 p16f873 p16f877?
6835 \end_layout
6836
6837 \end_inset
6838
6839
6840 \end_layout
6841
6842 \begin_layout List
6843 \labelwidthstring 00.00.0000
6844
6845 \series bold
6846 -mpic16
6847 \begin_inset LatexCommand \index{-mpic16}
6848
6849 \end_inset
6850
6851
6852 \series default
6853  Generate code for the Microchip PIC 16
6854 \begin_inset LatexCommand \index{PIC16}
6855
6856 \end_inset
6857
6858 -bit processors (p18f452 and variants.
6859  In development, not complete).
6860 \end_layout
6861
6862 \begin_layout List
6863 \labelwidthstring 00.00.0000
6864
6865 \series bold
6866 -mtlcs900h
6867 \series default
6868  Generate code for the Toshiba TLCS-900H
6869 \begin_inset LatexCommand \index{TLCS-900H}
6870
6871 \end_inset
6872
6873  processor (Not maintained, not complete).
6874 \end_layout
6875
6876 \begin_layout List
6877 \labelwidthstring 00.00.0000
6878
6879 \series bold
6880 -mxa51
6881 \begin_inset LatexCommand \index{-mxa51}
6882
6883 \end_inset
6884
6885
6886 \series default
6887  Generate code for the Phillips XA51
6888 \begin_inset LatexCommand \index{XA51}
6889
6890 \end_inset
6891
6892  processor (Not maintained, not complete).
6893 \end_layout
6894
6895 \begin_layout Standard
6896 \begin_inset VSpace bigskip
6897 \end_inset
6898
6899
6900 \end_layout
6901
6902 \begin_layout Subsection
6903 Preprocessor Options
6904 \begin_inset LatexCommand \index{Options preprocessor}
6905
6906 \end_inset
6907
6908
6909 \begin_inset LatexCommand \index{Preprocessor options}
6910
6911 \end_inset
6912
6913
6914 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6915
6916 \end_inset
6917
6918
6919 \end_layout
6920
6921 \begin_layout List
6922 \labelwidthstring 00.00.0000
6923
6924 \series bold
6925 -I<path>
6926 \begin_inset LatexCommand \index{-I<path>}
6927
6928 \end_inset
6929
6930
6931 \series default
6932  The additional location where the preprocessor will look for <..h> or 
6933 \begin_inset Quotes eld
6934 \end_inset
6935
6936 ..h
6937 \begin_inset Quotes erd
6938 \end_inset
6939
6940  files.
6941 \end_layout
6942
6943 \begin_layout List
6944 \labelwidthstring 00.00.0000
6945
6946 \series bold
6947 -D<macro[=value]>
6948 \begin_inset LatexCommand \index{-D<macro[=value]>}
6949
6950 \end_inset
6951
6952
6953 \series default
6954  Command line definition of macros.
6955  Passed to the preprocessor.
6956 \end_layout
6957
6958 \begin_layout List
6959 \labelwidthstring 00.00.0000
6960
6961 \series bold
6962 -M
6963 \begin_inset LatexCommand \index{-M}
6964
6965 \end_inset
6966
6967
6968 \series default
6969  Tell the preprocessor to output a rule suitable for make describing the
6970  dependencies of each object file.
6971  For each source file, the preprocessor outputs one make-rule whose target
6972  is the object file name for that source file and whose dependencies are
6973  all the files `#include'd in it.
6974  This rule may be a single line or may be continued with `
6975 \backslash
6976 '-newline if it is long.
6977  The list of rules is printed on standard output instead of the preprocessed
6978  C program.
6979  `-M' implies `-E
6980 \begin_inset LatexCommand \index{-E}
6981
6982 \end_inset
6983
6984 '.
6985 \end_layout
6986
6987 \begin_layout List
6988 \labelwidthstring 00.00.0000
6989
6990 \series bold
6991 -C
6992 \begin_inset LatexCommand \index{-C}
6993
6994 \end_inset
6995
6996
6997 \series default
6998  Tell the preprocessor not to discard comments.
6999  Used with the `-E' option.
7000 \end_layout
7001
7002 \begin_layout List
7003 \labelwidthstring 00.00.0000
7004
7005 \series bold
7006 -MM
7007 \begin_inset LatexCommand \index{-MM}
7008
7009 \end_inset
7010
7011
7012 \size large
7013 \bar under
7014  
7015 \series default
7016 \size default
7017 \bar default
7018 Like `-M' but the output mentions only the user header files included with
7019  `#include 
7020 \begin_inset Quotes eld
7021 \end_inset
7022
7023 file"'.
7024  System header files included with `#include <file>' are omitted.
7025 \end_layout
7026
7027 \begin_layout List
7028 \labelwidthstring 00.00.0000
7029
7030 \series bold
7031 -Aquestion(answer)
7032 \begin_inset LatexCommand \index{-Aquestion(answer)}
7033
7034 \end_inset
7035
7036
7037 \series default
7038  Assert the answer answer for question, in case it is tested with a preprocessor
7039  conditional such as `#if #question(answer)'.
7040  `-A-' disables the standard assertions that normally describe the target
7041  machine.
7042 \end_layout
7043
7044 \begin_layout List
7045 \labelwidthstring 00.00.0000
7046
7047 \series bold
7048 -Umacro
7049 \begin_inset LatexCommand \index{-Umacro}
7050
7051 \end_inset
7052
7053
7054 \series default
7055  Undefine macro macro.
7056  `-U' options are evaluated after all `-D' options, but before any `-include'
7057  and `-imacros' options.
7058 \end_layout
7059
7060 \begin_layout List
7061 \labelwidthstring 00.00.0000
7062
7063 \series bold
7064 -dM
7065 \begin_inset LatexCommand \index{-dM}
7066
7067 \end_inset
7068
7069
7070 \series default
7071  Tell the preprocessor to output only a list of the macro definitions that
7072  are in effect at the end of preprocessing.
7073  Used with the `-E' option.
7074 \end_layout
7075
7076 \begin_layout List
7077 \labelwidthstring 00.00.0000
7078
7079 \series bold
7080 -dD
7081 \begin_inset LatexCommand \index{-dD}
7082
7083 \end_inset
7084
7085
7086 \series default
7087  Tell the preprocessor to pass all macro definitions into the output, in
7088  their proper sequence in the rest of the output.
7089 \end_layout
7090
7091 \begin_layout List
7092 \labelwidthstring 00.00.0000
7093
7094 \series bold
7095 -dN
7096 \begin_inset LatexCommand \index{-dN}
7097
7098 \end_inset
7099
7100
7101 \size large
7102 \bar under
7103  
7104 \series default
7105 \size default
7106 \bar default
7107 Like `-dD' except that the macro arguments and contents are omitted.
7108  Only `#define name' is included in the output.
7109 \end_layout
7110
7111 \begin_layout List
7112 \labelwidthstring 00.00.0000
7113
7114 \series bold
7115 -pedantic-parse-number
7116 \begin_inset LatexCommand \index{pedantic}
7117
7118 \end_inset
7119
7120
7121 \begin_inset LatexCommand \index{-pedantic-parse-number}
7122
7123 \end_inset
7124
7125
7126 \size large
7127 \bar under
7128
7129 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
7130
7131 \end_inset
7132
7133  
7134 \series default
7135 \size default
7136 \bar default
7137 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7138  and the macro LO_B(3) gets expanded.
7139  See also #pragma pedantic_parse_number 
7140 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
7141
7142 \end_inset
7143
7144  in section
7145 \begin_inset LatexCommand \ref{sec:Pragmas}
7146
7147 \end_inset
7148
7149  
7150 \emph on
7151 Note: this functionality is not in conformance with C99 standard!
7152 \end_layout
7153
7154 \begin_layout List
7155 \labelwidthstring 00.00.0000
7156
7157 \series bold
7158 -Wp\InsetSpace ~
7159 preprocessorOption[,preprocessorOption]
7160 \series default
7161
7162 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
7163
7164 \end_inset
7165
7166 ...
7167  Pass the preprocessorOption to the preprocessor 
7168 \family typewriter
7169 sdcpp
7170 \family default
7171
7172 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7173
7174 \end_inset
7175
7176 .
7177  SDCC uses an adapted version of the preprocessor 
7178 \emph on
7179 cpp
7180 \emph default
7181  of the GNU Compiler Collection
7182 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7183
7184 \end_inset
7185
7186  (
7187 \emph on
7188 gcc
7189 \emph default
7190  
7191 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7192
7193 \end_inset
7194
7195 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7196 4.1.1\InsetSpace ~
7197 CPP\InsetSpace ~
7198 Manual
7199  at 
7200 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7201
7202 \end_inset
7203
7204 .
7205 \end_layout
7206
7207 \begin_layout Standard
7208 \begin_inset VSpace bigskip
7209 \end_inset
7210
7211
7212 \end_layout
7213
7214 \begin_layout Subsection
7215 Linker Options
7216 \begin_inset LatexCommand \index{Options linker}
7217
7218 \end_inset
7219
7220
7221 \begin_inset LatexCommand \index{Linker options}
7222
7223 \end_inset
7224
7225
7226 \end_layout
7227
7228 \begin_layout List
7229 \labelwidthstring 00.00.0000
7230
7231 \series bold
7232 -L\InsetSpace ~
7233 -
7234 \series default
7235
7236 \begin_inset ERT
7237 status collapsed
7238
7239 \begin_layout Standard
7240
7241
7242 \backslash
7243 /
7244 \end_layout
7245
7246 \end_inset
7247
7248
7249 \series bold
7250 -lib-path
7251 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7252
7253 \end_inset
7254
7255
7256 \begin_inset LatexCommand \index{-L -\/-lib-path}
7257
7258 \end_inset
7259
7260
7261 \series default
7262 \InsetSpace ~
7263 <absolute path to additional libraries> This option is passed to the linkage
7264  editor's additional libraries
7265 \begin_inset LatexCommand \index{Libraries}
7266
7267 \end_inset
7268
7269  search path.
7270  The path name must be absolute.
7271  Additional library files may be specified in the command line.
7272  See section Compiling programs for more details.
7273 \end_layout
7274
7275 \begin_layout List
7276 \labelwidthstring 00.00.0000
7277
7278 \series bold
7279 -
7280 \begin_inset ERT
7281 status collapsed
7282
7283 \begin_layout Standard
7284
7285
7286 \backslash
7287 /
7288 \end_layout
7289
7290 \end_inset
7291
7292 -xram-loc
7293 \series default
7294
7295 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7296
7297 \end_inset
7298
7299 \InsetSpace ~
7300 <Value> The start location of the external ram
7301 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7302
7303 \end_inset
7304
7305 , default value is 0.
7306  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7307 \begin_inset ERT
7308 status collapsed
7309
7310 \begin_layout Standard
7311
7312
7313 \backslash
7314 /
7315 \end_layout
7316
7317 \end_inset
7318
7319 -xram-loc 0x8000 or -
7320 \begin_inset ERT
7321 status collapsed
7322
7323 \begin_layout Standard
7324
7325
7326 \backslash
7327 /
7328 \end_layout
7329
7330 \end_inset
7331
7332 -xram-loc 32768.
7333 \end_layout
7334
7335 \begin_layout List
7336 \labelwidthstring 00.00.0000
7337
7338 \series bold
7339 -
7340 \begin_inset ERT
7341 status collapsed
7342
7343 \begin_layout Standard
7344
7345
7346 \backslash
7347 /
7348 \end_layout
7349
7350 \end_inset
7351
7352 -code-loc
7353 \series default
7354
7355 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7356
7357 \end_inset
7358
7359 \InsetSpace ~
7360 <Value> The start location of the code
7361 \begin_inset LatexCommand \index{code}
7362
7363 \end_inset
7364
7365  segment, default value 0.
7366  Note when this option is used the interrupt vector table
7367 \begin_inset LatexCommand \index{interrupt vector table}
7368
7369 \end_inset
7370
7371  is also relocated to the given address.
7372  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7373 \begin_inset ERT
7374 status collapsed
7375
7376 \begin_layout Standard
7377
7378
7379 \backslash
7380 /
7381 \end_layout
7382
7383 \end_inset
7384
7385 -code-loc 0x8000 or -
7386 \begin_inset ERT
7387 status collapsed
7388
7389 \begin_layout Standard
7390
7391
7392 \backslash
7393 /
7394 \end_layout
7395
7396 \end_inset
7397
7398 -code-loc 32768.
7399 \end_layout
7400
7401 \begin_layout List
7402 \labelwidthstring 00.00.0000
7403
7404 \series bold
7405 -
7406 \begin_inset ERT
7407 status collapsed
7408
7409 \begin_layout Standard
7410
7411
7412 \backslash
7413 /
7414 \end_layout
7415
7416 \end_inset
7417
7418 -stack-loc
7419 \series default
7420
7421 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7422
7423 \end_inset
7424
7425 \InsetSpace ~
7426 <Value> By default the stack
7427 \begin_inset LatexCommand \index{stack}
7428
7429 \end_inset
7430
7431  is placed after the data segment.
7432  Using this option the stack can be placed anywhere in the internal memory
7433  space of the 8051.
7434  The value entered can be in Hexadecimal or Decimal format, e.g.
7435  -
7436 \begin_inset ERT
7437 status collapsed
7438
7439 \begin_layout Standard
7440
7441
7442 \backslash
7443 /
7444 \end_layout
7445
7446 \end_inset
7447
7448 -stack-loc 0x20 or -
7449 \begin_inset ERT
7450 status collapsed
7451
7452 \begin_layout Standard
7453
7454
7455 \backslash
7456 /
7457 \end_layout
7458
7459 \end_inset
7460
7461 -stack-loc 32.
7462  Since the sp register is incremented before a push or call, the initial
7463  sp will be set to one byte prior the provided value.
7464  The provided value should not overlap any other memory areas such as used
7465  register banks or the data segment and with enough space for the current
7466  application.
7467  The 
7468 \series bold
7469 -
7470 \begin_inset ERT
7471 status collapsed
7472
7473 \begin_layout Standard
7474
7475
7476 \backslash
7477 /
7478 \end_layout
7479
7480 \end_inset
7481
7482 -pack-iram
7483 \series default
7484 \InsetSpace ~
7485
7486 \begin_inset LatexCommand \index{-\/-pack-iram}
7487
7488 \end_inset
7489
7490  option (which is now a default setting) will override this setting, so
7491  you should also specify the 
7492 \series bold
7493 -
7494 \begin_inset ERT
7495 status collapsed
7496
7497 \begin_layout Standard
7498
7499
7500 \backslash
7501 /
7502 \end_layout
7503
7504 \end_inset
7505
7506 -no-pack-iram
7507 \series default
7508 \InsetSpace ~
7509
7510 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7511
7512 \end_inset
7513
7514  option if you need to manually place the stack.
7515 \end_layout
7516
7517 \begin_layout List
7518 \labelwidthstring 00.00.0000
7519
7520 \series bold
7521 -
7522 \begin_inset ERT
7523 status collapsed
7524
7525 \begin_layout Standard
7526
7527
7528 \backslash
7529 /
7530 \end_layout
7531
7532 \end_inset
7533
7534 -xstack-loc
7535 \series default
7536
7537 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7538
7539 \end_inset
7540
7541 \InsetSpace ~
7542 <Value> By default the external stack
7543 \begin_inset LatexCommand \index{xstack}
7544
7545 \end_inset
7546
7547  is placed after the pdata
7548 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7549
7550 \end_inset
7551
7552  segment.
7553  Using this option the xstack can be placed anywhere in the external memory
7554  space of the 8051.
7555  The value entered can be in Hexadecimal or Decimal format, e.g.
7556  -
7557 \begin_inset ERT
7558 status collapsed
7559
7560 \begin_layout Standard
7561
7562
7563 \backslash
7564 /
7565 \end_layout
7566
7567 \end_inset
7568
7569 -xstack-loc 0x8000 or -
7570 \begin_inset ERT
7571 status collapsed
7572
7573 \begin_layout Standard
7574
7575
7576 \backslash
7577 /
7578 \end_layout
7579
7580 \end_inset
7581
7582 -stack-loc 32768.
7583  The provided value should not overlap any other memory areas such as the
7584  pdata or xdata segment and with enough space for the current application.
7585 \end_layout
7586
7587 \begin_layout List
7588 \labelwidthstring 00.00.0000
7589
7590 \series bold
7591 -
7592 \begin_inset ERT
7593 status collapsed
7594
7595 \begin_layout Standard
7596
7597
7598 \backslash
7599 /
7600 \end_layout
7601
7602 \end_inset
7603
7604 -data-loc
7605 \series default
7606
7607 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7608
7609 \end_inset
7610
7611 \InsetSpace ~
7612 <Value> The start location of the internal ram data
7613 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7614
7615 \end_inset
7616
7617  segment.
7618  The value entered can be in Hexadecimal or Decimal format, eg.
7619  -
7620 \begin_inset ERT
7621 status collapsed
7622
7623 \begin_layout Standard
7624
7625
7626 \backslash
7627 /
7628 \end_layout
7629
7630 \end_inset
7631
7632 -data-loc 0x20 or -
7633 \begin_inset ERT
7634 status collapsed
7635
7636 \begin_layout Standard
7637
7638
7639 \backslash
7640 /
7641 \end_layout
7642
7643 \end_inset
7644
7645 -data-loc 32.
7646  (By default, the start location of the internal ram data segment  is set
7647  as low as possible in memory, taking into account the used register banks
7648  and the bit segment at address 0x20.
7649  For example if register banks 0 and 1 are used without bit variables, the
7650  data segment will be set, if -
7651 \begin_inset ERT
7652 status collapsed
7653
7654 \begin_layout Standard
7655
7656
7657 \backslash
7658 /
7659 \end_layout
7660
7661 \end_inset
7662
7663 -data-loc is not used, to location 0x10.)
7664 \end_layout
7665
7666 \begin_layout List
7667 \labelwidthstring 00.00.0000
7668
7669 \series bold
7670 -
7671 \begin_inset ERT
7672 status collapsed
7673
7674 \begin_layout Standard
7675
7676
7677 \backslash
7678 /
7679 \end_layout
7680
7681 \end_inset
7682
7683 -idata-loc
7684 \series default
7685
7686 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7687
7688 \end_inset
7689
7690 \InsetSpace ~
7691 <Value> The start location of the indirectly addressable internal ram
7692 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7693
7694 \end_inset
7695
7696  of the 8051, default value is 0x80.
7697  The value entered can be in Hexadecimal or Decimal format, eg.
7698  -
7699 \begin_inset ERT
7700 status collapsed
7701
7702 \begin_layout Standard
7703
7704
7705 \backslash
7706 /
7707 \end_layout
7708
7709 \end_inset
7710
7711 -idata-loc 0x88 or -
7712 \begin_inset ERT
7713 status collapsed
7714
7715 \begin_layout Standard
7716
7717
7718 \backslash
7719 /
7720 \end_layout
7721
7722 \end_inset
7723
7724 -idata-loc 136.
7725 \end_layout
7726
7727 \begin_layout List
7728 \labelwidthstring 00.00.0000
7729
7730 \series bold
7731 -
7732 \begin_inset ERT
7733 status collapsed
7734
7735 \begin_layout Standard
7736
7737
7738 \backslash
7739 /
7740 \end_layout
7741
7742 \end_inset
7743
7744 -bit-loc
7745 \series default
7746 \InsetSpace ~
7747 <Value> The start location of the bit
7748 \begin_inset LatexCommand \index{bit}
7749
7750 \end_inset
7751
7752  addressable internal ram of the 8051.
7753  This is 
7754 \emph on
7755 not
7756 \emph default
7757  implemented yet.
7758  Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7759 -bBSEG=<Value>.
7760 \end_layout
7761
7762 \begin_layout List
7763 \labelwidthstring 00.00.0000
7764
7765 \series bold
7766 -
7767 \begin_inset ERT
7768 status collapsed
7769
7770 \begin_layout Standard
7771
7772
7773 \backslash
7774 /
7775 \end_layout
7776
7777 \end_inset
7778
7779 -out-fmt-ihx
7780 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7781
7782 \end_inset
7783
7784
7785 \bar under
7786  
7787 \series default
7788 \bar default
7789 The linker output (final object code) is in Intel Hex format.
7790 \begin_inset LatexCommand \index{Intel hex format}
7791
7792 \end_inset
7793
7794  This is the default option.
7795  The format itself is documented in the documentation of srecord
7796 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7797
7798 \end_inset
7799
7800 .
7801 \end_layout
7802
7803 \begin_layout List
7804 \labelwidthstring 00.00.0000
7805
7806 \series bold
7807 -
7808 \begin_inset ERT
7809 status collapsed
7810
7811 \begin_layout Standard
7812
7813
7814 \backslash
7815 /
7816 \end_layout
7817
7818 \end_inset
7819
7820 -out-fmt-s19
7821 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7822
7823 \end_inset
7824
7825
7826 \bar under
7827  
7828 \series default
7829 \bar default
7830 The linker output (final object code) is in Motorola S19 format
7831 \begin_inset LatexCommand \index{Motorola S19 format}
7832
7833 \end_inset
7834
7835 .
7836  The format itself is documented in the documentation of srecord.
7837 \end_layout
7838
7839 \begin_layout List
7840 \labelwidthstring 00.00.0000
7841
7842 \series bold
7843 -
7844 \begin_inset ERT
7845 status collapsed
7846
7847 \begin_layout Standard
7848
7849
7850 \backslash
7851 /
7852 \end_layout
7853
7854 \end_inset
7855
7856 -out-fmt-elf
7857 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7858
7859 \end_inset
7860
7861
7862 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7863
7864 \end_inset
7865
7866
7867 \bar under
7868  
7869 \series default
7870 \bar default
7871 The linker output (final object code) is in ELF format
7872 \begin_inset LatexCommand \index{ELF format}
7873
7874 \end_inset
7875
7876 .
7877  (Currently only supported for the HC08
7878 \begin_inset LatexCommand \index{HC08}
7879
7880 \end_inset
7881
7882  processors)
7883 \end_layout
7884
7885 \begin_layout List
7886 \labelwidthstring 00.00.0000
7887
7888 \series bold
7889 -Wl\InsetSpace ~
7890 linkOption[,linkOption]
7891 \series default
7892
7893 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7894
7895 \end_inset
7896
7897 ...
7898  Pass the linkOption to the linker.
7899  If a bootloader is used an option like 
7900 \begin_inset Quotes sld
7901 \end_inset
7902
7903 -Wl\InsetSpace ~
7904 -bCSEG=0x1000
7905 \begin_inset Quotes srd
7906 \end_inset
7907
7908  would be typical to set the start of the code segment.
7909  See also #pragma constseg and #pragma codeseg in section 
7910 \begin_inset LatexCommand \ref{sec:Pragmas}
7911
7912 \end_inset
7913
7914  .
7915  File sdcc/as/doc/asxhtm.html has more on linker options.
7916 \end_layout
7917
7918 \begin_layout Standard
7919 \begin_inset VSpace bigskip
7920 \end_inset
7921
7922
7923 \end_layout
7924
7925 \begin_layout Subsection
7926 MCS51 Options
7927 \begin_inset LatexCommand \index{Options MCS51}
7928
7929 \end_inset
7930
7931
7932 \begin_inset LatexCommand \index{MCS51 options}
7933
7934 \end_inset
7935
7936
7937 \end_layout
7938
7939 \begin_layout List
7940 \labelwidthstring 00.00.0000
7941
7942 \series bold
7943 -
7944 \begin_inset ERT
7945 status collapsed
7946
7947 \begin_layout Standard
7948
7949
7950 \backslash
7951 /
7952 \end_layout
7953
7954 \end_inset
7955
7956 -model-small
7957 \begin_inset LatexCommand \index{-\/-model-small}
7958
7959 \end_inset
7960
7961
7962 \series default
7963 \size large
7964 \emph on
7965  
7966 \size default
7967 \emph default
7968 Generate code for Small Model programs, see section Memory Models for more
7969  details.
7970  This is the default model.
7971 \end_layout
7972
7973 \begin_layout List
7974 \labelwidthstring 00.00.0000
7975
7976 \series bold
7977 -
7978 \begin_inset ERT
7979 status collapsed
7980
7981 \begin_layout Standard
7982
7983
7984 \backslash
7985 /
7986 \end_layout
7987
7988 \end_inset
7989
7990 -model-medium
7991 \begin_inset LatexCommand \index{-\/-model-medium}
7992
7993 \end_inset
7994
7995
7996 \series default
7997  Generate code for Medium model programs, see section Memory Models for
7998  more details.
7999  If this option is used all source files in the project have to be compiled
8000  with this option.
8001  It must also be used when invoking the linker.
8002 \end_layout
8003
8004 \begin_layout List
8005 \labelwidthstring 00.00.0000
8006
8007 \series bold
8008 -
8009 \begin_inset ERT
8010 status collapsed
8011
8012 \begin_layout Standard
8013
8014
8015 \backslash
8016 /
8017 \end_layout
8018
8019 \end_inset
8020
8021 -model-large
8022 \begin_inset LatexCommand \index{-\/-model-large}
8023
8024 \end_inset
8025
8026
8027 \series default
8028  Generate code for Large model programs, see section Memory Models for more
8029  details.
8030  If this option is used all source files in the project have to be compiled
8031  with this option.
8032  It must also be used when invoking the linker.
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 -xstack
8053 \begin_inset LatexCommand \index{-\/-xstack}
8054
8055 \end_inset
8056
8057
8058 \series default
8059  Uses a pseudo stack in the pdata
8060 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8061
8062 \end_inset
8063
8064  area (usually the first 256 bytes in the external ram) for allocating variables
8065  and passing parameters.
8066  See section 
8067 \begin_inset LatexCommand \ref{sub:External-Stack}
8068
8069 \end_inset
8070
8071 \InsetSpace ~
8072  External Stack for more details.
8073 \end_layout
8074
8075 \begin_layout List
8076 \labelwidthstring 00.00.0000
8077
8078 \series bold
8079 -
8080 \begin_inset ERT
8081 status collapsed
8082
8083 \begin_layout Standard
8084
8085
8086 \backslash
8087 /
8088 \end_layout
8089
8090 \end_inset
8091
8092 -iram-size
8093 \series default
8094 \InsetSpace ~
8095 <Value>
8096 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
8097
8098 \end_inset
8099
8100  Causes the linker to check if the internal ram usage is within limits of
8101  the given value.
8102 \end_layout
8103
8104 \begin_layout List
8105 \labelwidthstring 00.00.0000
8106
8107 \series bold
8108 -
8109 \begin_inset ERT
8110 status collapsed
8111
8112 \begin_layout Standard
8113
8114
8115 \backslash
8116 /
8117 \end_layout
8118
8119 \end_inset
8120
8121 -xram-size
8122 \series default
8123 \InsetSpace ~
8124 <Value>
8125 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
8126
8127 \end_inset
8128
8129  Causes the linker to check if the external ram usage is within limits of
8130  the given value.
8131 \end_layout
8132
8133 \begin_layout List
8134 \labelwidthstring 00.00.0000
8135
8136 \series bold
8137 -
8138 \begin_inset ERT
8139 status collapsed
8140
8141 \begin_layout Standard
8142
8143
8144 \backslash
8145 /
8146 \end_layout
8147
8148 \end_inset
8149
8150 -code-size
8151 \series default
8152 \InsetSpace ~
8153 <Value>
8154 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8155
8156 \end_inset
8157
8158  Causes the linker to check if the code memory usage is within limits of
8159  the given value.
8160 \end_layout
8161
8162 \begin_layout List
8163 \labelwidthstring 00.00.0000
8164
8165 \series bold
8166 -
8167 \begin_inset ERT
8168 status collapsed
8169
8170 \begin_layout Standard
8171
8172
8173 \backslash
8174 /
8175 \end_layout
8176
8177 \end_inset
8178
8179 -stack-size
8180 \series default
8181 \InsetSpace ~
8182 <Value>
8183 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8184
8185 \end_inset
8186
8187  Causes the linker to check if there is at minimum <Value> bytes for stack.
8188 \end_layout
8189
8190 \begin_layout List
8191 \labelwidthstring 00.00.0000
8192
8193 \series bold
8194 -
8195 \begin_inset ERT
8196 status collapsed
8197
8198 \begin_layout Standard
8199
8200
8201 \backslash
8202 /
8203 \end_layout
8204
8205 \end_inset
8206
8207 -pack-iram
8208 \series default
8209 \InsetSpace ~
8210
8211 \begin_inset LatexCommand \index{-\/-pack-iram}
8212
8213 \end_inset
8214
8215  Causes the linker to use unused register banks for data variables and pack
8216  data, idata and stack together.
8217  This is the default now.
8218 \end_layout
8219
8220 \begin_layout List
8221 \labelwidthstring 00.00.0000
8222
8223 \series bold
8224 -
8225 \begin_inset ERT
8226 status collapsed
8227
8228 \begin_layout Standard
8229
8230
8231 \backslash
8232 /
8233 \end_layout
8234
8235 \end_inset
8236
8237 -no-pack-iram
8238 \series default
8239 \InsetSpace ~
8240
8241 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8242
8243 \end_inset
8244
8245  Causes the linker to use old style for allocating memory areas.
8246 \end_layout
8247
8248 \begin_layout List
8249 \labelwidthstring 00.00.0000
8250
8251 \series bold
8252 -
8253 \begin_inset ERT
8254 status collapsed
8255
8256 \begin_layout Standard
8257
8258
8259 \backslash
8260 /
8261 \end_layout
8262
8263 \end_inset
8264
8265 -acall-ajmp
8266 \series default
8267 \InsetSpace ~
8268
8269 \begin_inset LatexCommand \index{-\/-acall-ajmp}
8270
8271 \end_inset
8272
8273  Replaces the three byte instructions lcall/ljmp with the two byte instructions
8274  acall/ajmp.
8275  Only use this option if your code is in the same 2k block of memory.
8276  You may need to use this option for some 8051 derivatives which lack the
8277  lcall/ljmp instructions..
8278 \end_layout
8279
8280 \begin_layout Standard
8281 \begin_inset VSpace bigskip
8282 \end_inset
8283
8284
8285 \end_layout
8286
8287 \begin_layout Subsection
8288 DS390 / DS400 Options
8289 \begin_inset LatexCommand \index{Options DS390}
8290
8291 \end_inset
8292
8293
8294 \begin_inset LatexCommand \index{DS390}
8295
8296 \end_inset
8297
8298
8299 \end_layout
8300
8301 \begin_layout List
8302 \labelwidthstring 00.00.0000
8303
8304 \series bold
8305 -
8306 \begin_inset ERT
8307 status collapsed
8308
8309 \begin_layout Standard
8310
8311
8312 \backslash
8313 /
8314 \end_layout
8315
8316 \end_inset
8317
8318 -model-flat24
8319 \series default
8320
8321 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8322
8323 \end_inset
8324
8325
8326 \size large
8327 \emph on
8328  
8329 \size default
8330 \emph default
8331 Generate 24-bit flat mode code.
8332  This is the one and only that the ds390 code generator supports right now
8333  and is default when using 
8334 \emph on
8335 -mds390
8336 \emph default
8337 .
8338  See section Memory Models for more details.
8339 \end_layout
8340
8341 \begin_layout List
8342 \labelwidthstring 00.00.0000
8343
8344 \series bold
8345 -
8346 \begin_inset ERT
8347 status collapsed
8348
8349 \begin_layout Standard
8350
8351
8352 \backslash
8353 /
8354 \end_layout
8355
8356 \end_inset
8357
8358 -protect-sp-update
8359 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8360
8361 \end_inset
8362
8363
8364 \series default
8365  disable interrupts during ESP:SP updates.
8366 \end_layout
8367
8368 \begin_layout List
8369 \labelwidthstring 00.00.0000
8370
8371 \series bold
8372 -
8373 \begin_inset ERT
8374 status collapsed
8375
8376 \begin_layout Standard
8377
8378
8379 \backslash
8380 /
8381 \end_layout
8382
8383 \end_inset
8384
8385 -stack-10bit
8386 \series default
8387
8388 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8389
8390 \end_inset
8391
8392  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8393  This is the one and only that the ds390 code generator supports right now
8394  and is default when using 
8395 \emph on
8396 -mds390
8397 \emph default
8398 .
8399  In this mode, the stack is located in the lower 1K of the internal RAM,
8400  which is mapped to 0x400000.
8401  Note that the support is incomplete, since it still uses a single byte
8402  as the stack pointer.
8403  This means that only the lower 256 bytes of the potential 1K stack space
8404  will actually be used.
8405  However, this does allow you to reclaim the precious 256 bytes of low RAM
8406  for use for the DATA and IDATA segments.
8407  The compiler will not generate any code to put the processor into 10 bit
8408  stack mode.
8409  It is important to ensure that the processor is in this mode before calling
8410  any re-entrant functions compiled with this option.
8411  In principle, this should work with the 
8412 \emph on
8413 -
8414 \begin_inset ERT
8415 status collapsed
8416
8417 \begin_layout Standard
8418
8419
8420 \backslash
8421 /
8422 \end_layout
8423
8424 \end_inset
8425
8426 -stack-auto
8427 \begin_inset LatexCommand \index{-\/-stack-auto}
8428
8429 \end_inset
8430
8431
8432 \emph default
8433  option, but that has not been tested.
8434  It is incompatible with the 
8435 \emph on
8436 -
8437 \begin_inset ERT
8438 status collapsed
8439
8440 \begin_layout Standard
8441
8442
8443 \backslash
8444 /
8445 \end_layout
8446
8447 \end_inset
8448
8449 -xstack
8450 \begin_inset LatexCommand \index{-\/-xstack}
8451
8452 \end_inset
8453
8454
8455 \emph default
8456  option.
8457  It also only makes sense if the processor is in 24 bit contiguous addressing
8458  mode (see the 
8459 \emph on
8460 -
8461 \begin_inset ERT
8462 status collapsed
8463
8464 \begin_layout Standard
8465
8466
8467 \backslash
8468 /
8469 \end_layout
8470
8471 \end_inset
8472
8473 -model-flat24 option
8474 \emph default
8475 ).
8476 \series bold
8477
8478 \begin_inset Note Note
8479 status collapsed
8480
8481 \begin_layout List
8482 \labelwidthstring 00.00.0000
8483
8484 \series bold
8485 -
8486 \begin_inset ERT
8487 status open
8488
8489 \begin_layout Standard
8490
8491
8492 \backslash
8493 /
8494 \end_layout
8495
8496 \end_inset
8497
8498 -stack-8-bit - switches off the 10-bit mode
8499 \end_layout
8500
8501 \end_inset
8502
8503
8504 \end_layout
8505
8506 \begin_layout List
8507 \labelwidthstring 00.00.0000
8508
8509 \series bold
8510 -
8511 \begin_inset ERT
8512 status collapsed
8513
8514 \begin_layout Standard
8515
8516
8517 \backslash
8518 /
8519 \end_layout
8520
8521 \end_inset
8522
8523 -stack-probe
8524 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8525
8526 \end_inset
8527
8528
8529 \series default
8530  insert call to function __stack_probe at each function prologue.
8531 \end_layout
8532
8533 \begin_layout List
8534 \labelwidthstring 00.00.0000
8535
8536 \series bold
8537 -
8538 \begin_inset ERT
8539 status open
8540
8541 \begin_layout Standard
8542
8543
8544 \backslash
8545 /
8546 \end_layout
8547
8548 \end_inset
8549
8550 -tini-libid
8551 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8552
8553 \end_inset
8554
8555
8556 \series default
8557  <nnnn> LibraryID used in -mTININative.
8558  
8559 \end_layout
8560
8561 \begin_layout List
8562 \labelwidthstring 00.00.0000
8563
8564 \series bold
8565 -
8566 \begin_inset ERT
8567 status collapsed
8568
8569 \begin_layout Standard
8570
8571
8572 \backslash
8573 /
8574 \end_layout
8575
8576 \end_inset
8577
8578 -use-accelerator
8579 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8580
8581 \end_inset
8582
8583
8584 \series default
8585  generate code for DS390 Arithmetic Accelerator.
8586  
8587 \end_layout
8588
8589 \begin_layout Standard
8590 \begin_inset VSpace bigskip
8591 \end_inset
8592
8593
8594 \end_layout
8595
8596 \begin_layout Subsection
8597 Z80 Options
8598 \begin_inset LatexCommand \index{Options Z80}
8599
8600 \end_inset
8601
8602
8603 \begin_inset LatexCommand \index{Z80}
8604
8605 \end_inset
8606
8607
8608 \end_layout
8609
8610 \begin_layout List
8611 \labelwidthstring 00.00.0000
8612
8613 \series bold
8614 -
8615 \begin_inset ERT
8616 status collapsed
8617
8618 \begin_layout Standard
8619
8620
8621 \backslash
8622 /
8623 \end_layout
8624
8625 \end_inset
8626
8627 -callee-saves-bc
8628 \series default
8629
8630 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8631
8632 \end_inset
8633
8634
8635 \size large
8636 \emph on
8637  
8638 \size default
8639 \emph default
8640 Force a called function to always save BC.
8641 \end_layout
8642
8643 \begin_layout List
8644 \labelwidthstring 00.00.0000
8645
8646 \series bold
8647 -
8648 \begin_inset ERT
8649 status collapsed
8650
8651 \begin_layout Standard
8652
8653
8654 \backslash
8655 /
8656 \end_layout
8657
8658 \end_inset
8659
8660 -no-std-crt0
8661 \series default
8662
8663 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8664
8665 \end_inset
8666
8667  When linking, skip the standard crt0.o object file.
8668  You must provide your own crt0.o for your system when linking.
8669 \end_layout
8670
8671 \begin_layout List
8672 \labelwidthstring 00.00.0000
8673
8674 \series bold
8675 -
8676 \begin_inset ERT
8677 status collapsed
8678
8679 \begin_layout Standard
8680
8681
8682 \backslash
8683 /
8684 \end_layout
8685
8686 \end_inset
8687
8688 -portmode=
8689 \series default
8690 <Value>
8691 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8692
8693 \end_inset
8694
8695  Determinate PORT I/O mode (<Value> is z80 or z180).
8696 \end_layout
8697
8698 \begin_layout List
8699 \labelwidthstring 00.00.0000
8700
8701 \series bold
8702 -
8703 \begin_inset ERT
8704 status collapsed
8705
8706 \begin_layout Standard
8707
8708
8709 \backslash
8710 /
8711 \end_layout
8712
8713 \end_inset
8714
8715 -asm=
8716 \series default
8717 <Value>
8718 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8719
8720 \end_inset
8721
8722  Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8723 \end_layout
8724
8725 \begin_layout List
8726 \labelwidthstring 00.00.0000
8727
8728 \series bold
8729 -
8730 \begin_inset ERT
8731 status collapsed
8732
8733 \begin_layout Standard
8734
8735
8736 \backslash
8737 /
8738 \end_layout
8739
8740 \end_inset
8741
8742 -codeseg
8743 \series default
8744 \InsetSpace ~
8745 <Value>
8746 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8747
8748 \end_inset
8749
8750  Use <Value> for the code segment name.
8751 \end_layout
8752
8753 \begin_layout List
8754 \labelwidthstring 00.00.0000
8755
8756 \series bold
8757 -
8758 \begin_inset ERT
8759 status collapsed
8760
8761 \begin_layout Standard
8762
8763
8764 \backslash
8765 /
8766 \end_layout
8767
8768 \end_inset
8769
8770 -constseg
8771 \series default
8772 \InsetSpace ~
8773 <Value>
8774 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8775
8776 \end_inset
8777
8778  Use <Value> for the const segment name.
8779 \end_layout
8780
8781 \begin_layout List
8782 \labelwidthstring 00.00.0000
8783 \begin_inset VSpace bigskip
8784 \end_inset
8785
8786
8787 \end_layout
8788
8789 \begin_layout Subsection
8790 GBZ80 Options
8791 \begin_inset LatexCommand \index{Options GBZ80}
8792
8793 \end_inset
8794
8795
8796 \begin_inset LatexCommand \index{GBZ80}
8797
8798 \end_inset
8799
8800
8801 \end_layout
8802
8803 \begin_layout List
8804 \labelwidthstring 00.00.0000
8805
8806 \series bold
8807 -
8808 \begin_inset ERT
8809 status collapsed
8810
8811 \begin_layout Standard
8812
8813
8814 \backslash
8815 /
8816 \end_layout
8817
8818 \end_inset
8819
8820 -callee-saves-bc
8821 \series default
8822
8823 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8824
8825 \end_inset
8826
8827
8828 \size large
8829 \emph on
8830  
8831 \size default
8832 \emph default
8833 Force a called function to always save BC.
8834 \end_layout
8835
8836 \begin_layout List
8837 \labelwidthstring 00.00.0000
8838
8839 \series bold
8840 -bo
8841 \series default
8842 \InsetSpace ~
8843 <Num>
8844 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
8845
8846 \end_inset
8847
8848  Use code bank <Num>.
8849 \end_layout
8850
8851 \begin_layout List
8852 \labelwidthstring 00.00.0000
8853
8854 \series bold
8855 -ba
8856 \series default
8857 \InsetSpace ~
8858 <Num>
8859 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
8860
8861 \end_inset
8862
8863  Use data bank <Num>.
8864 \end_layout
8865
8866 \begin_layout List
8867 \labelwidthstring 00.00.0000
8868
8869 \series bold
8870 -
8871 \begin_inset ERT
8872 status collapsed
8873
8874 \begin_layout Standard
8875
8876
8877 \backslash
8878 /
8879 \end_layout
8880
8881 \end_inset
8882
8883 -codeseg
8884 \series default
8885 \InsetSpace ~
8886 <Value>
8887 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
8888
8889 \end_inset
8890
8891  Use <Value> for the code segment name.
8892 \end_layout
8893
8894 \begin_layout List
8895 \labelwidthstring 00.00.0000
8896
8897 \series bold
8898 -
8899 \begin_inset ERT
8900 status collapsed
8901
8902 \begin_layout Standard
8903
8904
8905 \backslash
8906 /
8907 \end_layout
8908
8909 \end_inset
8910
8911 -constseg
8912 \series default
8913 \InsetSpace ~
8914 <Value>
8915 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
8916
8917 \end_inset
8918
8919  Use <Value> for the const segment name.
8920 \end_layout
8921
8922 \begin_layout Standard
8923 \begin_inset VSpace bigskip
8924 \end_inset
8925
8926
8927 \end_layout
8928
8929 \begin_layout Subsection
8930 Optimization Options
8931 \begin_inset LatexCommand \index{Options optimization}
8932
8933 \end_inset
8934
8935
8936 \begin_inset LatexCommand \index{Optimization options}
8937
8938 \end_inset
8939
8940
8941 \end_layout
8942
8943 \begin_layout List
8944 \labelwidthstring 00.00.0000
8945
8946 \series bold
8947 -
8948 \begin_inset ERT
8949 status collapsed
8950
8951 \begin_layout Standard
8952
8953
8954 \backslash
8955 /
8956 \end_layout
8957
8958 \end_inset
8959
8960 -nogcse
8961 \begin_inset LatexCommand \index{-\/-nogcse}
8962
8963 \end_inset
8964
8965
8966 \series default
8967  Will not do global subexpression elimination, this option may be used when
8968  the compiler creates undesirably large stack/data spaces to store compiler
8969  temporaries (
8970 \emph on
8971 s
8972 \emph default
8973 pill 
8974 \emph on
8975 loc
8976 \emph default
8977 ations, sloc
8978 \begin_inset LatexCommand \index{sloc (spill location)}
8979
8980 \end_inset
8981
8982 ).
8983  A warning message will be generated when this happens and the compiler
8984  will indicate the number of extra bytes it allocated.
8985  It is recommended that this option NOT be used, #pragma\InsetSpace ~
8986 nogcse
8987 \begin_inset LatexCommand \index{\#pragma nogcse}
8988
8989 \end_inset
8990
8991  can be used to turn off global subexpression elimination
8992 \begin_inset LatexCommand \index{Subexpression elimination}
8993
8994 \end_inset
8995
8996  for a given function only.
8997 \end_layout
8998
8999 \begin_layout List
9000 \labelwidthstring 00.00.0000
9001
9002 \series bold
9003 -
9004 \begin_inset ERT
9005 status collapsed
9006
9007 \begin_layout Standard
9008
9009
9010 \backslash
9011 /
9012 \end_layout
9013
9014 \end_inset
9015
9016 -noinvariant
9017 \begin_inset LatexCommand \index{-\/-noinvariant}
9018
9019 \end_inset
9020
9021
9022 \series default
9023  Will not do loop invariant optimizations, this may be turned off for reasons
9024  explained for the previous option.
9025  For more details of loop optimizations performed see Loop Invariants in
9026  section 
9027 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
9028
9029 \end_inset
9030
9031 .
9032  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9033 noinvariant
9034 \begin_inset LatexCommand \index{\#pragma noinvariant}
9035
9036 \end_inset
9037
9038  can be used to turn off invariant optimizations for a given function only.
9039 \end_layout
9040
9041 \begin_layout List
9042 \labelwidthstring 00.00.0000
9043
9044 \series bold
9045 -
9046 \begin_inset ERT
9047 status collapsed
9048
9049 \begin_layout Standard
9050
9051
9052 \backslash
9053 /
9054 \end_layout
9055
9056 \end_inset
9057
9058 -noinduction
9059 \begin_inset LatexCommand \index{-\/-noinduction}
9060
9061 \end_inset
9062
9063
9064 \series default
9065  Will not do loop induction optimizations, see section strength reduction
9066  for more details.
9067  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9068 noinduction
9069 \begin_inset LatexCommand \index{\#pragma noinduction}
9070
9071 \end_inset
9072
9073  can be used to turn off induction optimizations for a given function only.
9074 \end_layout
9075
9076 \begin_layout List
9077 \labelwidthstring 00.00.0000
9078
9079 \series bold
9080 -
9081 \begin_inset ERT
9082 status collapsed
9083
9084 \begin_layout Standard
9085
9086
9087 \backslash
9088 /
9089 \end_layout
9090
9091 \end_inset
9092
9093 -nojtbound
9094 \begin_inset LatexCommand \index{-\/-nojtbound}
9095
9096 \end_inset
9097
9098
9099 \size large
9100 \bar under
9101  
9102 \series default
9103 \size default
9104 \bar default
9105  Will not generate boundary condition check when switch statements
9106 \begin_inset LatexCommand \index{switch statement}
9107
9108 \end_inset
9109
9110  are implemented using jump-tables.
9111  See section 
9112 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9113
9114 \end_inset
9115
9116 \InsetSpace ~
9117 Switch Statements for more details.
9118  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9119 nojtbound
9120 \begin_inset LatexCommand \index{\#pragma nojtbound}
9121
9122 \end_inset
9123
9124  can be used to turn off boundary checking for jump tables for a given function
9125  only.
9126 \end_layout
9127
9128 \begin_layout List
9129 \labelwidthstring 00.00.0000
9130
9131 \series bold
9132 -
9133 \begin_inset ERT
9134 status collapsed
9135
9136 \begin_layout Standard
9137
9138
9139 \backslash
9140 /
9141 \end_layout
9142
9143 \end_inset
9144
9145 -noloopreverse
9146 \begin_inset LatexCommand \index{-\/-noloopreverse}
9147
9148 \end_inset
9149
9150
9151 \series default
9152 \size large
9153  
9154 \size default
9155 Will not do loop reversal 
9156 \begin_inset LatexCommand \index{Loop reversing}
9157
9158 \end_inset
9159
9160 optimization.
9161 \end_layout
9162
9163 \begin_layout List
9164 \labelwidthstring 00.00.0000
9165 -
9166 \begin_inset ERT
9167 status collapsed
9168
9169 \begin_layout Standard
9170
9171
9172 \backslash
9173 /
9174 \end_layout
9175
9176 \end_inset
9177
9178 -
9179 \series bold
9180 nolabelopt
9181 \series default
9182  
9183 \begin_inset LatexCommand \index{-\/-nolabelopt }
9184
9185 \end_inset
9186
9187 Will not optimize labels (makes the dumpfiles more readable).
9188 \end_layout
9189
9190 \begin_layout List
9191 \labelwidthstring 00.00.0000
9192
9193 \series bold
9194 -
9195 \begin_inset ERT
9196 status collapsed
9197
9198 \begin_layout Standard
9199
9200
9201 \backslash
9202 /
9203 \end_layout
9204
9205 \end_inset
9206
9207 -no-xinit-opt
9208 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9209
9210 \end_inset
9211
9212
9213 \series default
9214  Will not memcpy initialized data from code space into xdata space.
9215  This saves a few bytes in code space if you don't have initialized data
9216 \begin_inset LatexCommand \index{Variable initialization}
9217
9218 \end_inset
9219
9220 .
9221 \end_layout
9222
9223 \begin_layout List
9224 \labelwidthstring 00.00.0000
9225
9226 \series bold
9227 -
9228 \begin_inset ERT
9229 status collapsed
9230
9231 \begin_layout Standard
9232
9233
9234 \backslash
9235 /
9236 \end_layout
9237
9238 \end_inset
9239
9240 -nooverlay
9241 \begin_inset LatexCommand \index{-\/-nooverlay}
9242
9243 \end_inset
9244
9245
9246 \series default
9247   The compiler will not overlay parameters and local variables of any function,
9248  see section Parameters and local variables for more details.
9249 \end_layout
9250
9251 \begin_layout List
9252 \labelwidthstring 00.00.0000
9253
9254 \series bold
9255 -
9256 \begin_inset ERT
9257 status collapsed
9258
9259 \begin_layout Standard
9260
9261
9262 \backslash
9263 /
9264 \end_layout
9265
9266 \end_inset
9267
9268 -no-peep
9269 \begin_inset LatexCommand \index{-\/-no-peep}
9270
9271 \end_inset
9272
9273
9274 \series default
9275  Disable peep-hole optimization with built-in rules.
9276 \end_layout
9277
9278 \begin_layout List
9279 \labelwidthstring 00.00.0000
9280
9281 \series bold
9282 -
9283 \begin_inset ERT
9284 status collapsed
9285
9286 \begin_layout Standard
9287
9288
9289 \backslash
9290 /
9291 \end_layout
9292
9293 \end_inset
9294
9295 -peep-file
9296 \series default
9297
9298 \begin_inset LatexCommand \index{-\/-peep-file}
9299
9300 \end_inset
9301
9302 \InsetSpace ~
9303 <filename> This option can be used to use additional rules to be used by
9304  the peep hole optimizer.
9305  See section 
9306 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9307
9308 \end_inset
9309
9310 \InsetSpace ~
9311 Peep Hole optimizations for details on how to write these rules.
9312 \end_layout
9313
9314 \begin_layout List
9315 \labelwidthstring 00.00.0000
9316
9317 \series bold
9318 -
9319 \begin_inset ERT
9320 status collapsed
9321
9322 \begin_layout Standard
9323
9324
9325 \backslash
9326 /
9327 \end_layout
9328
9329 \end_inset
9330
9331 -peep-asm
9332 \begin_inset LatexCommand \index{-\/-peep-asm}
9333
9334 \end_inset
9335
9336
9337 \series default
9338  Pass the inline assembler code through the peep hole optimizer.
9339  This can cause unexpected changes to inline assembler code, please go through
9340  the peephole optimizer
9341 \begin_inset LatexCommand \index{Peephole optimizer}
9342
9343 \end_inset
9344
9345  rules defined in the source file tree '<target>/peeph.def' before using
9346  this option.
9347 \end_layout
9348
9349 \begin_layout List
9350 \labelwidthstring 00.00.0000
9351
9352 \series bold
9353 -
9354 \begin_inset ERT
9355 status collapsed
9356
9357 \begin_layout Standard
9358
9359
9360 \backslash
9361 /
9362 \end_layout
9363
9364 \end_inset
9365
9366 -opt-code-speed
9367 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9368
9369 \end_inset
9370
9371
9372 \series default
9373  The compiler will optimize code generation towards fast code, possibly
9374  at the expense of code size.
9375 \end_layout
9376
9377 \begin_layout List
9378 \labelwidthstring 00.00.0000
9379
9380 \series bold
9381 -
9382 \begin_inset ERT
9383 status collapsed
9384
9385 \begin_layout Standard
9386
9387
9388 \backslash
9389 /
9390 \end_layout
9391
9392 \end_inset
9393
9394 -opt-code-size
9395 \begin_inset LatexCommand \index{-\/-opt-code-size}
9396
9397 \end_inset
9398
9399
9400 \series default
9401  The compiler will optimize code generation towards compact code, possibly
9402  at the expense of code speed.
9403 \end_layout
9404
9405 \begin_layout Standard
9406 \begin_inset VSpace bigskip
9407 \end_inset
9408
9409
9410 \end_layout
9411
9412 \begin_layout Subsection
9413 Other Options
9414 \begin_inset LatexCommand \index{Options other}
9415
9416 \end_inset
9417
9418
9419 \end_layout
9420
9421 \begin_layout List
9422 \labelwidthstring 00.00.0000
9423
9424 \series bold
9425 -c\InsetSpace ~
9426 -
9427 \begin_inset ERT
9428 status collapsed
9429
9430 \begin_layout Standard
9431
9432
9433 \backslash
9434 /
9435 \end_layout
9436
9437 \end_inset
9438
9439 -compile-only
9440 \begin_inset LatexCommand \index{-\/-compile-only}
9441
9442 \end_inset
9443
9444
9445 \begin_inset LatexCommand \index{-c -\/-compile-only}
9446
9447 \end_inset
9448
9449
9450 \series default
9451  will compile and assemble the source, but will not call the linkage editor.
9452 \end_layout
9453
9454 \begin_layout List
9455 \labelwidthstring 00.00.0000
9456
9457 \series bold
9458 -
9459 \series default
9460
9461 \begin_inset ERT
9462 status collapsed
9463
9464 \begin_layout Standard
9465
9466
9467 \backslash
9468 /
9469 \end_layout
9470
9471 \end_inset
9472
9473
9474 \series bold
9475 -c1mode
9476 \begin_inset LatexCommand \index{-\/-c1mode}
9477
9478 \end_inset
9479
9480
9481 \series default
9482  reads the preprocessed source from standard input and compiles it.
9483  The file name for the assembler output must be specified using the -o option.
9484 \end_layout
9485
9486 \begin_layout List
9487 \labelwidthstring 00.00.0000
9488
9489 \series bold
9490 -E
9491 \begin_inset LatexCommand \index{-E}
9492
9493 \end_inset
9494
9495
9496 \series default
9497  Run only the C preprocessor.
9498  Preprocess all the C source files specified and output the results to standard
9499  output.
9500 \end_layout
9501
9502 \begin_layout List
9503 \labelwidthstring 00.00.0000
9504
9505 \series bold
9506 -o\InsetSpace ~
9507 <path/file>
9508 \begin_inset LatexCommand \index{-o <path/file>}
9509
9510 \end_inset
9511
9512  
9513 \series default
9514 The output path where everything will be placed or the file name used for
9515  all generated output files.
9516  If the parameter is a path, it must have a trailing slash (or backslash
9517  for the Windows binaries) to be recognized as a path.
9518
9519 \emph on
9520  
9521 \emph default
9522 Note for Windows users: if the path contains spaces, it should be surrounded
9523  by quotes.
9524  The trailing backslash should be doubled in order to prevent escaping the
9525  final quote, for example: 
9526 \emph on
9527 -o 
9528 \begin_inset Quotes sld
9529 \end_inset
9530
9531 F:
9532 \backslash
9533 Projects
9534 \backslash
9535 test3
9536 \backslash
9537 output 1
9538 \backslash
9539
9540 \backslash
9541
9542 \begin_inset Quotes srd
9543 \end_inset
9544
9545
9546 \emph default
9547  or put after the final quote, for example: 
9548 \emph on
9549 -o 
9550 \begin_inset Quotes sld
9551 \end_inset
9552
9553 F:
9554 \backslash
9555 Projects
9556 \backslash
9557 test3
9558 \backslash
9559 output 1
9560 \begin_inset Quotes srd
9561 \end_inset
9562
9563
9564 \backslash
9565
9566 \emph default
9567 .
9568  The path using slashes for directory delimiters can be used too, for example:
9569  
9570 \emph on
9571 -o 
9572 \begin_inset Quotes sld
9573 \end_inset
9574
9575 F:/Projects/test3/output 1/
9576 \begin_inset Quotes srd
9577 \end_inset
9578
9579
9580 \emph default
9581 .
9582 \end_layout
9583
9584 \begin_layout List
9585 \labelwidthstring 00.00.0000
9586
9587 \series bold
9588 -
9589 \begin_inset ERT
9590 status collapsed
9591
9592 \begin_layout Standard
9593
9594
9595 \backslash
9596 /
9597 \end_layout
9598
9599 \end_inset
9600
9601 -stack-auto
9602 \begin_inset LatexCommand \index{-\/-stack-auto}
9603
9604 \end_inset
9605
9606
9607 \series default
9608 \size large
9609 \emph on
9610  
9611 \size default
9612 \emph default
9613 All functions in the source file will be compiled as 
9614 \emph on
9615 reentrant
9616 \emph default
9617
9618 \begin_inset LatexCommand \index{reentrant}
9619
9620 \end_inset
9621
9622 , i.e.
9623  the parameters and local variables will be allocated on the stack
9624 \begin_inset LatexCommand \index{stack}
9625
9626 \end_inset
9627
9628 .
9629  See section 
9630 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9631
9632 \end_inset
9633
9634  Parameters and Local Variables for more details.
9635  If this option is used all source files in the project should be compiled
9636  with this option.
9637  It automatically implies -
9638 \series bold
9639
9640 \begin_inset ERT
9641 status open
9642
9643 \begin_layout Standard
9644
9645
9646 \backslash
9647 /
9648 \end_layout
9649
9650 \end_inset
9651
9652
9653 \series default
9654 -int-long-reent and -
9655 \series bold
9656
9657 \begin_inset ERT
9658 status open
9659
9660 \begin_layout Standard
9661
9662
9663 \backslash
9664 /
9665 \end_layout
9666
9667 \end_inset
9668
9669
9670 \series default
9671 -float-reent.
9672  
9673 \end_layout
9674
9675 \begin_layout List
9676 \labelwidthstring 00.00.0000
9677
9678 \series bold
9679 -
9680 \begin_inset ERT
9681 status collapsed
9682
9683 \begin_layout Standard
9684
9685
9686 \backslash
9687 /
9688 \end_layout
9689
9690 \end_inset
9691
9692 -callee-saves
9693 \begin_inset LatexCommand \index{-\/-callee-saves}
9694
9695 \end_inset
9696
9697  
9698 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9699
9700 \end_inset
9701
9702 function1[,function2][,function3]....
9703
9704 \series default
9705  The compiler by default uses a caller saves convention for register saving
9706  across function calls, however this can cause unnecessary register pushing
9707  and popping when calling small functions from larger functions.
9708  This option can be used to switch the register saving convention for the
9709  function names specified.
9710  The compiler will not save registers when calling these functions, no extra
9711  code will be generated at the entry and exit (function prologue
9712 \series bold
9713
9714 \begin_inset LatexCommand \index{function prologue}
9715
9716 \end_inset
9717
9718
9719 \series default
9720  and epilogue
9721 \series bold
9722
9723 \begin_inset LatexCommand \index{function epilogue}
9724
9725 \end_inset
9726
9727
9728 \series default
9729 ) for these functions to save and restore the registers used by these functions,
9730  this can SUBSTANTIALLY reduce code and improve run time performance of
9731  the generated code.
9732  In the future the compiler (with inter procedural analysis) will be able
9733  to determine the appropriate scheme to use for each function call.
9734  DO NOT use this option for built-in functions such as _mulint..., if this
9735  option is used for a library function the appropriate library function
9736  needs to be recompiled with the same option.
9737  If the project consists of multiple source files then all the source file
9738  should be compiled with the same -
9739 \begin_inset ERT
9740 status collapsed
9741
9742 \begin_layout Standard
9743
9744
9745 \backslash
9746 /
9747 \end_layout
9748
9749 \end_inset
9750
9751 -callee-saves option string.
9752  Also see #pragma\InsetSpace ~
9753 callee_saves 
9754 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9755
9756 \end_inset
9757
9758  
9759 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9760
9761 \end_inset
9762
9763 .
9764 \end_layout
9765
9766 \begin_layout List
9767 \labelwidthstring 00.00.0000
9768
9769 \series bold
9770 -
9771 \begin_inset ERT
9772 status collapsed
9773
9774 \begin_layout Standard
9775
9776
9777 \backslash
9778 /
9779 \end_layout
9780
9781 \end_inset
9782
9783 -all-callee-saves
9784 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9785
9786 \end_inset
9787
9788  
9789 \series default
9790 Function of
9791 \series bold
9792  
9793 \series default
9794 -
9795 \begin_inset ERT
9796 status collapsed
9797
9798 \begin_layout Standard
9799
9800
9801 \backslash
9802 /
9803 \end_layout
9804
9805 \end_inset
9806
9807 -callee-saves will be applied to all functions by default.
9808 \end_layout
9809
9810 \begin_layout List
9811 \labelwidthstring 00.00.0000
9812
9813 \series bold
9814 -
9815 \begin_inset ERT
9816 status collapsed
9817
9818 \begin_layout Standard
9819
9820
9821 \backslash
9822 /
9823 \end_layout
9824
9825 \end_inset
9826
9827 -debug
9828 \begin_inset LatexCommand \index{-\/-debug}
9829
9830 \end_inset
9831
9832
9833 \bar under
9834  
9835 \series default
9836 \bar default
9837 When this option is used the compiler will generate debug information.
9838  The debug information collected in a file with .cdb extension can be used
9839  with the SDCDB.
9840  For more information see documentation for SDCDB.
9841  Another file with no extension contains debug information in AOMF or AOMF51
9842 \begin_inset LatexCommand \index{AOMF, AOMF51}
9843
9844 \end_inset
9845
9846  format which is commonly used by third party tools.
9847 \end_layout
9848
9849 \begin_layout List
9850 \labelwidthstring 00.00.0000
9851
9852 \series bold
9853 -S
9854 \begin_inset LatexCommand \index{-S}
9855
9856 \end_inset
9857
9858
9859 \size large
9860 \bar under
9861  
9862 \series default
9863 \size default
9864 \bar default
9865 Stop after the stage of compilation proper; do not assemble.
9866  The output is an assembler code file for the input file specified.
9867 \end_layout
9868
9869 \begin_layout List
9870 \labelwidthstring 00.00.0000
9871
9872 \series bold
9873 -
9874 \begin_inset ERT
9875 status collapsed
9876
9877 \begin_layout Standard
9878
9879
9880 \backslash
9881 /
9882 \end_layout
9883
9884 \end_inset
9885
9886 -int-long-reent
9887 \begin_inset LatexCommand \index{-\/-int-long-reent}
9888
9889 \end_inset
9890
9891
9892 \series default
9893  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9894  Note by default these libraries are compiled as non-reentrant.
9895  See section Installation for more details.
9896 \end_layout
9897
9898 \begin_layout List
9899 \labelwidthstring 00.00.0000
9900
9901 \series bold
9902 -
9903 \begin_inset ERT
9904 status collapsed
9905
9906 \begin_layout Standard
9907
9908
9909 \backslash
9910 /
9911 \end_layout
9912
9913 \end_inset
9914
9915 -cyclomatic
9916 \begin_inset LatexCommand \index{-\/-cyclomatic}
9917
9918 \end_inset
9919
9920
9921 \bar under
9922  
9923 \series default
9924 \bar default
9925 This option will cause the compiler to generate an information message for
9926  each function in the source file.
9927  The message contains some 
9928 \emph on
9929 important
9930 \emph default
9931  information about the function.
9932  The number of edges and nodes the compiler detected in the control flow
9933  graph of the function, and most importantly the 
9934 \emph on
9935 cyclomatic complexity
9936 \begin_inset LatexCommand \index{Cyclomatic complexity}
9937
9938 \end_inset
9939
9940
9941 \emph default
9942  see section on Cyclomatic Complexity for more details.
9943 \end_layout
9944
9945 \begin_layout List
9946 \labelwidthstring 00.00.0000
9947
9948 \series bold
9949 -
9950 \begin_inset ERT
9951 status collapsed
9952
9953 \begin_layout Standard
9954
9955
9956 \backslash
9957 /
9958 \end_layout
9959
9960 \end_inset
9961
9962 -float-reent
9963 \begin_inset LatexCommand \index{-\/-float-reent}
9964
9965 \end_inset
9966
9967
9968 \series default
9969  Floating point library is compiled as reentrant
9970 \begin_inset LatexCommand \index{reentrant}
9971
9972 \end_inset
9973
9974 .
9975  See section Installation for more details.
9976 \end_layout
9977
9978 \begin_layout List
9979 \labelwidthstring 00.00.0000
9980
9981 \series bold
9982 -
9983 \begin_inset ERT
9984 status collapsed
9985
9986 \begin_layout Standard
9987
9988
9989 \backslash
9990 /
9991 \end_layout
9992
9993 \end_inset
9994
9995 -funsigned-char
9996 \begin_inset LatexCommand \index{-\/-funsigned-char}
9997
9998 \end_inset
9999
10000
10001 \series default
10002  The default signedness for every type is
10003 \family typewriter
10004  signed
10005 \family default
10006 .
10007  In some embedded environments the default signedness of
10008 \family typewriter
10009  char
10010 \family default
10011  is
10012 \family typewriter
10013  unsigned
10014 \family default
10015 .
10016  To set the signess for characters to unsigned, use the option -
10017 \series bold
10018
10019 \begin_inset ERT
10020 status open
10021
10022 \begin_layout Standard
10023
10024
10025 \backslash
10026 /
10027 \end_layout
10028
10029 \end_inset
10030
10031
10032 \series default
10033 -funsigned-char.
10034  If this option is set and no signedness keyword (unsigned/signed) is given,
10035  a char will be signed.
10036  All other types are unaffected.
10037 \end_layout
10038
10039 \begin_layout List
10040 \labelwidthstring 00.00.0000
10041
10042 \series bold
10043 -
10044 \begin_inset ERT
10045 status collapsed
10046
10047 \begin_layout Standard
10048
10049
10050 \backslash
10051 /
10052 \end_layout
10053
10054 \end_inset
10055
10056 -main-return
10057 \begin_inset LatexCommand \index{-\/-main-return}
10058
10059 \end_inset
10060
10061
10062 \series default
10063  This option can be used if the code generated is called by a monitor program
10064  or if the main routine includes an endless loop.
10065  This option results in slightly smaller code and saves two bytes of stack
10066  space.
10067  The return from the 'main'
10068 \begin_inset LatexCommand \index{main return}
10069
10070 \end_inset
10071
10072  function will return to the function calling main.
10073  The default setting is to lock up i.e.
10074  generate a '
10075 \family typewriter
10076 sjmp .
10077 \family default
10078 '.
10079 \end_layout
10080
10081 \begin_layout List
10082 \labelwidthstring 00.00.0000
10083
10084 \series bold
10085 -
10086 \begin_inset ERT
10087 status collapsed
10088
10089 \begin_layout Standard
10090
10091
10092 \backslash
10093 /
10094 \end_layout
10095
10096 \end_inset
10097
10098 -nostdinc
10099 \begin_inset LatexCommand \index{-\/-nostdinc}
10100
10101 \end_inset
10102
10103
10104 \series default
10105  This will prevent the compiler from passing on the default include path
10106  to the preprocessor.
10107 \end_layout
10108
10109 \begin_layout List
10110 \labelwidthstring 00.00.0000
10111
10112 \series bold
10113 -
10114 \begin_inset ERT
10115 status collapsed
10116
10117 \begin_layout Standard
10118
10119
10120 \backslash
10121 /
10122 \end_layout
10123
10124 \end_inset
10125
10126 -nostdlib
10127 \begin_inset LatexCommand \index{-\/-nostdlib}
10128
10129 \end_inset
10130
10131
10132 \series default
10133  This will prevent the compiler from passing on the default library
10134 \begin_inset LatexCommand \index{Libraries}
10135
10136 \end_inset
10137
10138  path to the linker.
10139 \end_layout
10140
10141 \begin_layout List
10142 \labelwidthstring 00.00.0000
10143
10144 \series bold
10145 -
10146 \begin_inset ERT
10147 status collapsed
10148
10149 \begin_layout Standard
10150
10151
10152 \backslash
10153 /
10154 \end_layout
10155
10156 \end_inset
10157
10158 -verbose
10159 \begin_inset LatexCommand \index{-\/-verbose}
10160
10161 \end_inset
10162
10163
10164 \series default
10165  Shows the various actions the compiler is performing.
10166 \end_layout
10167
10168 \begin_layout List
10169 \labelwidthstring 00.00.0000
10170
10171 \series bold
10172 -V
10173 \begin_inset LatexCommand \index{-V}
10174
10175 \end_inset
10176
10177
10178 \series default
10179  Shows the actual commands the compiler is executing.
10180 \end_layout
10181
10182 \begin_layout List
10183 \labelwidthstring 00.00.0000
10184
10185 \series bold
10186 -
10187 \begin_inset ERT
10188 status collapsed
10189
10190 \begin_layout Standard
10191
10192
10193 \backslash
10194 /
10195 \end_layout
10196
10197 \end_inset
10198
10199 -no-c-code-in-asm
10200 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10201
10202 \end_inset
10203
10204
10205 \series default
10206  Hides your ugly and inefficient c-code from the asm file, so you can always
10207  blame the compiler :)
10208 \end_layout
10209
10210 \begin_layout List
10211 \labelwidthstring 00.00.0000
10212
10213 \series bold
10214 -
10215 \begin_inset ERT
10216 status collapsed
10217
10218 \begin_layout Standard
10219
10220
10221 \backslash
10222 /
10223 \end_layout
10224
10225 \end_inset
10226
10227 -fverbose-asm
10228 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10229
10230 \end_inset
10231
10232
10233 \series default
10234  Include code generator and peep-hole comments in the generated asm files.
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 -no-peep-comments
10255 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10256
10257 \end_inset
10258
10259
10260 \series default
10261  Don't include peep-hole comments in the generated asm files even if -
10262 \series bold
10263
10264 \begin_inset ERT
10265 status open
10266
10267 \begin_layout Standard
10268
10269
10270 \backslash
10271 /
10272 \end_layout
10273
10274 \end_inset
10275
10276
10277 \series default
10278 -fverbose-asm option is specified.
10279 \end_layout
10280
10281 \begin_layout List
10282 \labelwidthstring 00.00.0000
10283
10284 \series bold
10285 -
10286 \begin_inset ERT
10287 status collapsed
10288
10289 \begin_layout Standard
10290
10291
10292 \backslash
10293 /
10294 \end_layout
10295
10296 \end_inset
10297
10298 -i-code-in-asm
10299 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10300
10301 \end_inset
10302
10303
10304 \series default
10305  Include i-codes in the asm file.
10306  Sounds like noise but is most helpful for debugging the compiler itself.
10307 \end_layout
10308
10309 \begin_layout List
10310 \labelwidthstring 00.00.0000
10311
10312 \series bold
10313 -
10314 \begin_inset ERT
10315 status collapsed
10316
10317 \begin_layout Standard
10318
10319
10320 \backslash
10321 /
10322 \end_layout
10323
10324 \end_inset
10325
10326 -less-pedantic
10327 \begin_inset LatexCommand \index{pedantic}
10328
10329 \end_inset
10330
10331
10332 \begin_inset LatexCommand \index{-\/-less-pedantic}
10333
10334 \end_inset
10335
10336
10337 \series default
10338
10339 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10340
10341 \end_inset
10342
10343  Disable some of the more pedantic warnings
10344 \begin_inset LatexCommand \index{Warnings}
10345
10346 \end_inset
10347
10348 .
10349  For more details, see the less_pedantic pragma 
10350 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10351
10352 \end_inset
10353
10354 .
10355 \end_layout
10356
10357 \begin_layout List
10358 \labelwidthstring 00.00.0000
10359
10360 \series bold
10361 -
10362 \begin_inset ERT
10363 status collapsed
10364
10365 \begin_layout Standard
10366
10367
10368 \backslash
10369 /
10370 \end_layout
10371
10372 \end_inset
10373
10374 -disable-warning\InsetSpace ~
10375 <nnnn>
10376 \begin_inset LatexCommand \index{-\/-disable-warning}
10377
10378 \end_inset
10379
10380
10381 \series default
10382  Disable specific warning with number <nnnn>.
10383 \end_layout
10384
10385 \begin_layout List
10386 \labelwidthstring 00.00.0000
10387
10388 \series bold
10389 -
10390 \begin_inset ERT
10391 status collapsed
10392
10393 \begin_layout Standard
10394
10395
10396 \backslash
10397 /
10398 \end_layout
10399
10400 \end_inset
10401
10402 -Werror
10403 \begin_inset LatexCommand \index{-\/-Werror}
10404
10405 \end_inset
10406
10407
10408 \series default
10409  Treat all warnings as errors.
10410 \end_layout
10411
10412 \begin_layout List
10413 \labelwidthstring 00.00.0000
10414
10415 \series bold
10416 -
10417 \begin_inset ERT
10418 status collapsed
10419
10420 \begin_layout Standard
10421
10422
10423 \backslash
10424 /
10425 \end_layout
10426
10427 \end_inset
10428
10429 -print-search-dirs
10430 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10431
10432 \end_inset
10433
10434
10435 \series default
10436  Display the directories in the compiler's search path
10437 \end_layout
10438
10439 \begin_layout List
10440 \labelwidthstring 00.00.0000
10441
10442 \series bold
10443 -
10444 \begin_inset ERT
10445 status collapsed
10446
10447 \begin_layout Standard
10448
10449
10450 \backslash
10451 /
10452 \end_layout
10453
10454 \end_inset
10455
10456 -vc
10457 \begin_inset LatexCommand \index{-\/-vc}
10458
10459 \end_inset
10460
10461
10462 \series default
10463  Display errors and warnings using MSVC style, so you can use SDCC with
10464  the visual studio IDE
10465 \begin_inset LatexCommand \index{IDE}
10466
10467 \end_inset
10468
10469 .
10470  With SDCC both offering a GCC-like (the default) and a MSVC-like
10471 \begin_inset LatexCommand \index{MSVC output style}
10472
10473 \end_inset
10474
10475  output style, integration into most programming editors should be straightforwa
10476 rd.
10477 \end_layout
10478
10479 \begin_layout List
10480 \labelwidthstring 00.00.0000
10481
10482 \series bold
10483 -
10484 \begin_inset ERT
10485 status collapsed
10486
10487 \begin_layout Standard
10488
10489
10490 \backslash
10491 /
10492 \end_layout
10493
10494 \end_inset
10495
10496 -use-stdout
10497 \begin_inset LatexCommand \index{-\/-use-stdout}
10498
10499 \end_inset
10500
10501
10502 \series default
10503  Send errors and warnings to stdout instead of stderr.
10504 \end_layout
10505
10506 \begin_layout List
10507 \labelwidthstring 00.00.0000
10508
10509 \series bold
10510 -Wa\InsetSpace ~
10511 asmOption[,asmOption]
10512 \series default
10513
10514 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10515
10516 \end_inset
10517
10518 ...
10519  Pass the asmOption to the assembler
10520 \begin_inset LatexCommand \index{Options assembler}
10521
10522 \end_inset
10523
10524
10525 \begin_inset LatexCommand \index{Assembler options}
10526
10527 \end_inset
10528
10529 .
10530  See file sdcc/as/doc/asxhtm.html for assembler options.cd
10531 \end_layout
10532
10533 \begin_layout List
10534 \labelwidthstring 00.00.0000
10535
10536 \series bold
10537 -
10538 \begin_inset ERT
10539 status collapsed
10540
10541 \begin_layout Standard
10542
10543
10544 \backslash
10545 /
10546 \end_layout
10547
10548 \end_inset
10549
10550 -std-sdcc89
10551 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10552
10553 \end_inset
10554
10555
10556 \series default
10557  Generally follow the C89 standard, but allow SDCC features that conflict
10558  with the standard (default).
10559 \end_layout
10560
10561 \begin_layout List
10562 \labelwidthstring 00.00.0000
10563
10564 \series bold
10565 -
10566 \begin_inset ERT
10567 status collapsed
10568
10569 \begin_layout Standard
10570
10571
10572 \backslash
10573 /
10574 \end_layout
10575
10576 \end_inset
10577
10578 -std-c89
10579 \begin_inset LatexCommand \index{-\/-std-c89}
10580
10581 \end_inset
10582
10583
10584 \series default
10585  Follow the C89 standard and disable SDCC features that conflict with the
10586  standard.
10587 \end_layout
10588
10589 \begin_layout List
10590 \labelwidthstring 00.00.0000
10591
10592 \series bold
10593 -
10594 \begin_inset ERT
10595 status collapsed
10596
10597 \begin_layout Standard
10598
10599
10600 \backslash
10601 /
10602 \end_layout
10603
10604 \end_inset
10605
10606 -std-sdcc99
10607 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10608
10609 \end_inset
10610
10611
10612 \series default
10613  Generally follow the C99 standard, but allow SDCC features that conflict
10614  with the standard (incomplete support).
10615 \end_layout
10616
10617 \begin_layout List
10618 \labelwidthstring 00.00.0000
10619
10620 \series bold
10621 -
10622 \begin_inset ERT
10623 status collapsed
10624
10625 \begin_layout Standard
10626
10627
10628 \backslash
10629 /
10630 \end_layout
10631
10632 \end_inset
10633
10634 -std-c99
10635 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10636
10637 \end_inset
10638
10639
10640 \series default
10641  Follow the C99 standard and disable SDCC features that conflict with the
10642  standard (incomplete support).
10643 \end_layout
10644
10645 \begin_layout List
10646 \labelwidthstring 00.00.0000
10647
10648 \series bold
10649 -
10650 \begin_inset ERT
10651 status collapsed
10652
10653 \begin_layout Standard
10654
10655
10656 \backslash
10657 /
10658 \end_layout
10659
10660 \end_inset
10661
10662 -codeseg
10663 \series default
10664
10665 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10666
10667 \end_inset
10668
10669 \InsetSpace ~
10670 <Name> The name to be used for the code
10671 \begin_inset LatexCommand \index{code}
10672
10673 \end_inset
10674
10675  segment, default CSEG.
10676  This is useful if you need to tell the compiler to put the code in a special
10677  segment so you can later on tell the linker to put this segment in a special
10678  place in memory.
10679  Can be used for instance when using bank switching to put the code in a
10680  bank.
10681 \end_layout
10682
10683 \begin_layout List
10684 \labelwidthstring 00.00.0000
10685
10686 \series bold
10687 -
10688 \begin_inset ERT
10689 status collapsed
10690
10691 \begin_layout Standard
10692
10693
10694 \backslash
10695 /
10696 \end_layout
10697
10698 \end_inset
10699
10700 -constseg
10701 \series default
10702
10703 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10704
10705 \end_inset
10706
10707 \InsetSpace ~
10708 <Name> The name to be used for the const
10709 \begin_inset LatexCommand \index{const}
10710
10711 \end_inset
10712
10713  segment, default CONST.
10714  This is useful if you need to tell the compiler to put the const data in
10715  a special segment so you can later on tell the linker to put this segment
10716  in a special place in memory.
10717  Can be used for instance when using bank switching to put the const data
10718  in a bank.
10719 \end_layout
10720
10721 \begin_layout List
10722 \labelwidthstring 00.00.0000
10723
10724 \series bold
10725 -
10726 \begin_inset ERT
10727 status collapsed
10728
10729 \begin_layout Standard
10730
10731
10732 \backslash
10733 /
10734 \end_layout
10735
10736 \end_inset
10737
10738 -fdollars-in-identifiers
10739 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10740
10741 \end_inset
10742
10743
10744 \series default
10745  Permit '$' as an identifier character.
10746 \end_layout
10747
10748 \begin_layout List
10749 \labelwidthstring 00.00.0000
10750
10751 \series bold
10752 -
10753 \begin_inset ERT
10754 status collapsed
10755
10756 \begin_layout Standard
10757
10758
10759 \backslash
10760 /
10761 \end_layout
10762
10763 \end_inset
10764
10765 -more-pedantic
10766 \series default
10767
10768 \begin_inset LatexCommand \index{-\/-more-pedantic}
10769
10770 \end_inset
10771
10772
10773 \begin_inset LatexCommand \index{pedantic}
10774
10775 \end_inset
10776
10777  Actually this is 
10778 \series bold
10779 \emph on
10780 not
10781 \series default
10782 \emph default
10783  a SDCC compiler option but if you want 
10784 \emph on
10785 more
10786 \emph default
10787  warnings you can use a separate tool dedicated to syntax checking like
10788  splint
10789 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10790
10791 \end_inset
10792
10793
10794 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10795
10796 \end_inset
10797
10798  
10799 \begin_inset LatexCommand \url{http://www.splint.org}
10800
10801 \end_inset
10802
10803 .
10804  To make your source files parseable by splint you will have to include
10805  
10806 \family sans
10807 lint.h
10808 \family default
10809
10810 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10811
10812 \end_inset
10813
10814  in your source file and add brackets around extended keywords (like 
10815 \family sans
10816
10817 \begin_inset Quotes sld
10818 \end_inset
10819
10820 __at\InsetSpace ~
10821
10822 \series bold
10823 (
10824 \series default
10825 0xab
10826 \series bold
10827 )
10828 \series default
10829
10830 \begin_inset Quotes srd
10831 \end_inset
10832
10833
10834 \family default
10835  and 
10836 \family sans
10837
10838 \begin_inset Quotes sld
10839 \end_inset
10840
10841 __interrupt\InsetSpace ~
10842 (2)
10843 \begin_inset Quotes srd
10844 \end_inset
10845
10846
10847 \family default
10848 ).
10849  
10850 \newline
10851 Splint has an excellent on line manual at 
10852 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10853
10854 \end_inset
10855
10856  and it's capabilities go beyond pure syntax checking.
10857  You'll need to tell splint the location of SDCC's include files so a typical
10858  command line could look like this: 
10859 \newline
10860
10861 \family sans
10862 splint\InsetSpace ~
10863 -I\InsetSpace ~
10864 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10865 \InsetSpace ~
10866 myprogram.c
10867 \end_layout
10868
10869 \begin_layout List
10870 \labelwidthstring 00.00.0000
10871
10872 \series bold
10873 -
10874 \begin_inset ERT
10875 status collapsed
10876
10877 \begin_layout Standard
10878
10879
10880 \backslash
10881 /
10882 \end_layout
10883
10884 \end_inset
10885
10886 -short-is-8bits
10887 \series default
10888
10889 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10890
10891 \end_inset
10892
10893
10894 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10895
10896 \end_inset
10897
10898  Treat short as 8-bit (for backward compatibility with older versions of
10899  compiler - see section 
10900 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10901
10902 \end_inset
10903
10904 )
10905 \end_layout
10906
10907 \begin_layout Standard
10908 \begin_inset VSpace bigskip
10909 \end_inset
10910
10911
10912 \end_layout
10913
10914 \begin_layout Subsection
10915 Intermediate Dump Options
10916 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10917
10918 \end_inset
10919
10920
10921 \begin_inset LatexCommand \index{Options intermediate dump}
10922
10923 \end_inset
10924
10925
10926 \begin_inset LatexCommand \index{Intermediate dump options}
10927
10928 \end_inset
10929
10930
10931 \end_layout
10932
10933 \begin_layout Standard
10934 The following options are provided for the purpose of retargetting and debugging
10935  the compiler.
10936  They provide a means to dump the intermediate code (iCode
10937 \begin_inset LatexCommand \index{iCode}
10938
10939 \end_inset
10940
10941 ) generated by the compiler in human readable form at various stages of
10942  the compilation process.
10943  More on iCodes see chapter 
10944 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10945
10946 \end_inset
10947
10948  
10949 \begin_inset Quotes srd
10950 \end_inset
10951
10952 The anatomy of the compiler
10953 \begin_inset Quotes srd
10954 \end_inset
10955
10956 .
10957 \end_layout
10958
10959 \begin_layout List
10960 \labelwidthstring 00.00.0000
10961
10962 \series bold
10963 -
10964 \begin_inset ERT
10965 status collapsed
10966
10967 \begin_layout Standard
10968
10969
10970 \backslash
10971 /
10972 \end_layout
10973
10974 \end_inset
10975
10976 -dumpraw
10977 \begin_inset LatexCommand \index{-\/-dumpraw}
10978
10979 \end_inset
10980
10981
10982 \series default
10983  This option will cause the compiler to dump the intermediate code into
10984  a file of named 
10985 \emph on
10986 <source filename>.dumpraw
10987 \emph default
10988  just after the intermediate code has been generated for a function, i.e.
10989  before any optimizations are done.
10990  The basic blocks
10991 \begin_inset LatexCommand \index{Basic blocks}
10992
10993 \end_inset
10994
10995  at this stage ordered in the depth first number, so they may not be in
10996  sequence of execution.
10997 \end_layout
10998
10999 \begin_layout List
11000 \labelwidthstring 00.00.0000
11001
11002 \series bold
11003 -
11004 \begin_inset ERT
11005 status collapsed
11006
11007 \begin_layout Standard
11008
11009
11010 \backslash
11011 /
11012 \end_layout
11013
11014 \end_inset
11015
11016 -dumpgcse
11017 \begin_inset LatexCommand \index{-\/-dumpgcse}
11018
11019 \end_inset
11020
11021
11022 \series default
11023  Will create a dump of iCodes, after global subexpression elimination
11024 \begin_inset LatexCommand \index{Global subexpression elimination}
11025
11026 \end_inset
11027
11028 , into a file named 
11029 \emph on
11030 <source filename>.dumpgcse.
11031 \end_layout
11032
11033 \begin_layout List
11034 \labelwidthstring 00.00.0000
11035
11036 \series bold
11037 -
11038 \begin_inset ERT
11039 status collapsed
11040
11041 \begin_layout Standard
11042
11043
11044 \backslash
11045 /
11046 \end_layout
11047
11048 \end_inset
11049
11050 -dumpdeadcode
11051 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
11052
11053 \end_inset
11054
11055
11056 \series default
11057  Will create a dump of iCodes, after deadcode elimination
11058 \begin_inset LatexCommand \index{Dead-code elimination}
11059
11060 \end_inset
11061
11062 , into a file named 
11063 \emph on
11064 <source filename>.dumpdeadcode.
11065 \end_layout
11066
11067 \begin_layout List
11068 \labelwidthstring 00.00.0000
11069
11070 \series bold
11071 -
11072 \begin_inset ERT
11073 status collapsed
11074
11075 \begin_layout Standard
11076
11077
11078 \backslash
11079 /
11080 \end_layout
11081
11082 \end_inset
11083
11084 -dumploop
11085 \begin_inset LatexCommand \index{-\/-dumploop}
11086
11087 \end_inset
11088
11089
11090 \series default
11091 \size large
11092  
11093 \size default
11094 Will create a dump of iCodes, after loop optimizations
11095 \begin_inset LatexCommand \index{Loop optimization}
11096
11097 \end_inset
11098
11099 , into a file named 
11100 \emph on
11101 <source filename>.dumploop.
11102 \end_layout
11103
11104 \begin_layout List
11105 \labelwidthstring 00.00.0000
11106
11107 \series bold
11108 -
11109 \begin_inset ERT
11110 status collapsed
11111
11112 \begin_layout Standard
11113
11114
11115 \backslash
11116 /
11117 \end_layout
11118
11119 \end_inset
11120
11121 -dumprange
11122 \begin_inset LatexCommand \index{-\/-dumprange}
11123
11124 \end_inset
11125
11126
11127 \series default
11128 \size large
11129  
11130 \size default
11131 Will create a dump of iCodes, after live range analysis
11132 \begin_inset LatexCommand \index{Live range analysis}
11133
11134 \end_inset
11135
11136 , into a file named 
11137 \emph on
11138 <source filename>.dumprange.
11139 \end_layout
11140
11141 \begin_layout List
11142 \labelwidthstring 00.00.0000
11143
11144 \series bold
11145 -
11146 \begin_inset ERT
11147 status collapsed
11148
11149 \begin_layout Standard
11150
11151
11152 \backslash
11153 /
11154 \end_layout
11155
11156 \end_inset
11157
11158 -dumlrange
11159 \begin_inset LatexCommand \index{-\/-dumlrange}
11160
11161 \end_inset
11162
11163
11164 \series default
11165  Will dump the life ranges
11166 \begin_inset LatexCommand \index{Live range analysis}
11167
11168 \end_inset
11169
11170  for all symbols.
11171 \end_layout
11172
11173 \begin_layout List
11174 \labelwidthstring 00.00.0000
11175
11176 \series bold
11177 -
11178 \begin_inset ERT
11179 status collapsed
11180
11181 \begin_layout Standard
11182
11183
11184 \backslash
11185 /
11186 \end_layout
11187
11188 \end_inset
11189
11190 -dumpregassign
11191 \begin_inset LatexCommand \index{-\/-dumpregassign}
11192
11193 \end_inset
11194
11195
11196 \bar under
11197  
11198 \series default
11199 \bar default
11200 Will create a dump of iCodes, after register assignment
11201 \begin_inset LatexCommand \index{Register assignment}
11202
11203 \end_inset
11204
11205 , into a file named 
11206 \emph on
11207 <source filename>.dumprassgn.
11208 \end_layout
11209
11210 \begin_layout List
11211 \labelwidthstring 00.00.0000
11212
11213 \series bold
11214 -
11215 \begin_inset ERT
11216 status collapsed
11217
11218 \begin_layout Standard
11219
11220
11221 \backslash
11222 /
11223 \end_layout
11224
11225 \end_inset
11226
11227 -dumplrange
11228 \begin_inset LatexCommand \index{-\/-dumplrange}
11229
11230 \end_inset
11231
11232
11233 \series default
11234  Will create a dump of the live ranges of iTemp's
11235 \end_layout
11236
11237 \begin_layout List
11238 \labelwidthstring 00.00.0000
11239
11240 \series bold
11241 -
11242 \begin_inset ERT
11243 status collapsed
11244
11245 \begin_layout Standard
11246
11247
11248 \backslash
11249 /
11250 \end_layout
11251
11252 \end_inset
11253
11254 -dumpall
11255 \begin_inset LatexCommand \index{-\/-dumpall}
11256
11257 \end_inset
11258
11259
11260 \size large
11261 \bar under
11262  
11263 \series default
11264 \size default
11265 \bar default
11266 Will cause all the above mentioned dumps to be created.
11267 \end_layout
11268
11269 \begin_layout Standard
11270 \begin_inset VSpace bigskip
11271 \end_inset
11272
11273
11274 \end_layout
11275
11276 \begin_layout Subsection
11277 Redirecting output on Windows Shells
11278 \end_layout
11279
11280 \begin_layout Standard
11281 By default SDCC writes its error messages to 
11282 \begin_inset Quotes sld
11283 \end_inset
11284
11285 standard error
11286 \begin_inset Quotes srd
11287 \end_inset
11288
11289 .
11290  To force all messages to 
11291 \begin_inset Quotes sld
11292 \end_inset
11293
11294 standard output
11295 \begin_inset Quotes srd
11296 \end_inset
11297
11298  use 
11299 \series bold
11300 -
11301 \series default
11302 \emph on
11303
11304 \begin_inset ERT
11305 status collapsed
11306
11307 \begin_layout Standard
11308
11309
11310 \backslash
11311 /
11312 \end_layout
11313
11314 \end_inset
11315
11316
11317 \series bold
11318 \emph default
11319 -
11320 \series default
11321 use-stdout
11322 \begin_inset LatexCommand \index{-\/-use-stdout}
11323
11324 \end_inset
11325
11326 .
11327  Additionally, if you happen to have visual studio installed in your windows
11328  machine, you can use it to compile your sources using a custom build and
11329  the SDCC -
11330 \emph on
11331
11332 \begin_inset ERT
11333 status collapsed
11334
11335 \begin_layout Standard
11336
11337
11338 \backslash
11339 /
11340 \end_layout
11341
11342 \end_inset
11343
11344
11345 \emph default
11346 -vc
11347 \begin_inset LatexCommand \index{-\/-vc}
11348
11349 \end_inset
11350
11351  option.
11352  Something like this should work:
11353 \newline
11354
11355 \newline
11356
11357 \series bold
11358 c:
11359 \backslash
11360 sdcc
11361 \backslash
11362 bin
11363 \backslash
11364 sdcc.exe -
11365 \series default
11366 \emph on
11367
11368 \begin_inset ERT
11369 status collapsed
11370
11371 \begin_layout Standard
11372
11373
11374 \backslash
11375 /
11376 \end_layout
11377
11378 \end_inset
11379
11380
11381 \series bold
11382 \emph default
11383 -vc -
11384 \series default
11385 \emph on
11386
11387 \begin_inset ERT
11388 status collapsed
11389
11390 \begin_layout Standard
11391
11392
11393 \backslash
11394 /
11395 \end_layout
11396
11397 \end_inset
11398
11399
11400 \series bold
11401 \emph default
11402 -model-large -c $(InputPath)
11403 \series default
11404
11405 \begin_inset VSpace bigskip
11406 \end_inset
11407
11408
11409 \end_layout
11410
11411 \begin_layout Section
11412 Environment variables
11413 \begin_inset LatexCommand \index{Environment variables}
11414
11415 \end_inset
11416
11417
11418 \end_layout
11419
11420 \begin_layout Standard
11421 SDCC recognizes the following environment variables:
11422 \end_layout
11423
11424 \begin_layout List
11425 \labelwidthstring 00.00.0000
11426
11427 \series bold
11428 SDCC_LEAVE_SIGNALS
11429 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11430
11431 \end_inset
11432
11433
11434 \series default
11435  SDCC installs a signal handler
11436 \begin_inset LatexCommand \index{signal handler}
11437
11438 \end_inset
11439
11440  to be able to delete temporary files after an user break (^C) or an exception.
11441  If this environment variable is set, SDCC won't install the signal handler
11442  in order to be able to debug SDCC.
11443 \end_layout
11444
11445 \begin_layout List
11446 \labelwidthstring 00.00.0000
11447
11448 \series bold
11449 TMP,\InsetSpace ~
11450 TEMP,\InsetSpace ~
11451 TMPDIR
11452 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11453
11454 \end_inset
11455
11456
11457 \series default
11458  Path, where temporary files will be created.
11459  The order of the variables is the search order.
11460  In a standard *nix environment these variables are not set, and there's
11461  no need to set them.
11462  On Windows it's recommended to set one of them.
11463 \end_layout
11464
11465 \begin_layout List
11466 \labelwidthstring 00.00.0000
11467
11468 \series bold
11469 SDCC_HOME
11470 \begin_inset LatexCommand \index{SDCC\_HOME}
11471
11472 \end_inset
11473
11474
11475 \series default
11476  Path, see section 
11477 \begin_inset LatexCommand \ref{sub:Install-paths}
11478
11479 \end_inset
11480
11481 \InsetSpace ~
11482
11483 \begin_inset Quotes sld
11484 \end_inset
11485
11486  Install Paths
11487 \begin_inset Quotes srd
11488 \end_inset
11489
11490 .
11491 \end_layout
11492
11493 \begin_layout List
11494 \labelwidthstring 00.00.0000
11495
11496 \series bold
11497 SDCC_INCLUDE
11498 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11499
11500 \end_inset
11501
11502
11503 \series default
11504  Path, see section 
11505 \begin_inset LatexCommand \ref{sub:Search-Paths}
11506
11507 \end_inset
11508
11509 \InsetSpace ~
11510
11511 \begin_inset Quotes sld
11512 \end_inset
11513
11514 Search Paths
11515 \begin_inset Quotes srd
11516 \end_inset
11517
11518 .
11519 \end_layout
11520
11521 \begin_layout List
11522 \labelwidthstring 00.00.0000
11523
11524 \series bold
11525 SDCC_LIB
11526 \begin_inset LatexCommand \index{SDCC\_LIB}
11527
11528 \end_inset
11529
11530
11531 \series default
11532  Path, see section 
11533 \begin_inset LatexCommand \ref{sub:Search-Paths}
11534
11535 \end_inset
11536
11537 \InsetSpace ~
11538
11539 \begin_inset Quotes sld
11540 \end_inset
11541
11542 Search Paths
11543 \begin_inset Quotes srd
11544 \end_inset
11545
11546 ..
11547 \end_layout
11548
11549 \begin_layout Standard
11550 There are some more environment variables recognized by SDCC, but these
11551  are solely used for debugging purposes.
11552  They can change or disappear very quickly, and will never be documented.
11553 \begin_inset VSpace bigskip
11554 \end_inset
11555
11556
11557 \end_layout
11558
11559 \begin_layout Section
11560 Storage Class Language Extensions
11561 \end_layout
11562
11563 \begin_layout Subsection
11564 MCS51/DS390 Storage Class
11565 \begin_inset LatexCommand \index{Storage class}
11566
11567 \end_inset
11568
11569  Language Extensions
11570 \end_layout
11571
11572 \begin_layout Standard
11573 In addition to the ANSI storage classes SDCC allows the following MCS51
11574  specific storage classes:
11575 \end_layout
11576
11577 \begin_layout Subsubsection
11578 data
11579 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11580
11581 \end_inset
11582
11583
11584 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11585
11586 \end_inset
11587
11588  / near
11589 \begin_inset LatexCommand \index{near (storage class)}
11590
11591 \end_inset
11592
11593
11594 \begin_inset LatexCommand \index{\_\_near (storage class)}
11595
11596 \end_inset
11597
11598
11599 \end_layout
11600
11601 \begin_layout Standard
11602 This is the 
11603 \series bold
11604 default
11605 \series default
11606  storage class for the Small Memory model (
11607 \emph on
11608 data
11609 \emph default
11610  and 
11611 \emph on
11612 near
11613 \emph default
11614  or the more ANSI-C compliant forms 
11615 \emph on
11616 __data
11617 \emph default
11618  and 
11619 \emph on
11620 __near
11621 \emph default
11622  can be used synonymously).
11623  Variables declared with this storage class will be allocated in the directly
11624  addressable portion of the internal RAM of a 8051, e.g.:
11625 \end_layout
11626
11627 \begin_layout Verse
11628
11629 \family typewriter
11630 __data unsigned char test_data;
11631 \end_layout
11632
11633 \begin_layout Standard
11634 Writing 0x01 to this variable generates the assembly code:
11635 \end_layout
11636
11637 \begin_layout Verse
11638
11639 \family typewriter
11640 75*00 01\InsetSpace ~
11641 \InsetSpace ~
11642 \InsetSpace ~
11643 mov\InsetSpace ~
11644 \InsetSpace ~
11645 _test_data,#0x01
11646 \end_layout
11647
11648 \begin_layout Subsubsection
11649 xdata
11650 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11651
11652 \end_inset
11653
11654
11655 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11656
11657 \end_inset
11658
11659  / far
11660 \begin_inset LatexCommand \index{far (storage class)}
11661
11662 \end_inset
11663
11664
11665 \begin_inset LatexCommand \index{\_\_far (storage class)}
11666
11667 \end_inset
11668
11669
11670 \end_layout
11671
11672 \begin_layout Standard
11673 Variables declared with this storage class will be placed in the external
11674  RAM.
11675  This is the 
11676 \series bold
11677 default
11678 \series default
11679  storage class for the Large Memory model, e.g.:
11680 \end_layout
11681
11682 \begin_layout Verse
11683
11684 \family typewriter
11685 __xdata unsigned char test_xdata;
11686 \end_layout
11687
11688 \begin_layout Standard
11689 Writing 0x01 to this variable generates the assembly code:
11690 \end_layout
11691
11692 \begin_layout Verse
11693
11694 \family typewriter
11695 90s00r00\InsetSpace ~
11696 \InsetSpace ~
11697 \InsetSpace ~
11698 mov\InsetSpace ~
11699 \InsetSpace ~
11700 dptr,#_test_xdata 
11701 \newline
11702 74\InsetSpace ~
11703 01\InsetSpace ~
11704 \InsetSpace ~
11705 \InsetSpace ~
11706 \InsetSpace ~
11707 \InsetSpace ~
11708 \InsetSpace ~
11709 mov\InsetSpace ~
11710 \InsetSpace ~
11711 a,#0x01 
11712 \newline
11713 F0\InsetSpace ~
11714 \InsetSpace ~
11715 \InsetSpace ~
11716 \InsetSpace ~
11717 \InsetSpace ~
11718 \InsetSpace ~
11719 \InsetSpace ~
11720 \InsetSpace ~
11721 \InsetSpace ~
11722 movx\InsetSpace ~
11723 @dptr,a 
11724 \end_layout
11725
11726 \begin_layout Subsubsection
11727 idata
11728 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11729
11730 \end_inset
11731
11732
11733 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11734
11735 \end_inset
11736
11737
11738 \end_layout
11739
11740 \begin_layout Standard
11741 Variables declared with this storage class will be allocated into the indirectly
11742  addressable portion of the internal ram of a 8051, e.g.:
11743 \end_layout
11744
11745 \begin_layout Verse
11746
11747 \family typewriter
11748 __idata unsigned char test_idata;
11749 \end_layout
11750
11751 \begin_layout Standard
11752 Writing 0x01 to this variable generates the assembly code:
11753 \end_layout
11754
11755 \begin_layout Verse
11756
11757 \family typewriter
11758 78r00\InsetSpace ~
11759 \InsetSpace ~
11760 \InsetSpace ~
11761 \InsetSpace ~
11762 \InsetSpace ~
11763 \InsetSpace ~
11764 \InsetSpace ~
11765 mov\InsetSpace ~
11766 \InsetSpace ~
11767 r0,#_test_idata
11768 \newline
11769 76\InsetSpace ~
11770 01\InsetSpace ~
11771 \InsetSpace ~
11772 \InsetSpace ~
11773 \InsetSpace ~
11774 \InsetSpace ~
11775 \InsetSpace ~
11776 \InsetSpace ~
11777 mov\InsetSpace ~
11778 \InsetSpace ~
11779 @r0,#0x01
11780 \end_layout
11781
11782 \begin_layout Standard
11783 Please note, the first 128 byte of idata physically access the same RAM
11784  as the data memory.
11785  The original 8051 had 128 byte idata memory, nowadays most devices have
11786  256 byte idata memory.
11787  The stack
11788 \begin_inset LatexCommand \index{stack}
11789
11790 \end_inset
11791
11792  is located in idata memory.
11793 \end_layout
11794
11795 \begin_layout Subsubsection
11796 pdata
11797 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11798
11799 \end_inset
11800
11801
11802 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11803
11804 \end_inset
11805
11806
11807 \end_layout
11808
11809 \begin_layout Standard
11810 Paged xdata access is just as straightforward as using the other addressing
11811  modes of a 8051.
11812  It is typically located at the start of xdata and has a maximum size of
11813  256 bytes.
11814  The following example writes 0x01 to the pdata variable.
11815  Please note, pdata access physically accesses xdata memory.
11816  The high byte of the address is determined by port P2 
11817 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11818
11819 \end_inset
11820
11821 (or in case of some 8051 variants by a separate Special Function Register,
11822  see section 
11823 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11824
11825 \end_inset
11826
11827 ).
11828  This is the 
11829 \series bold
11830 default
11831 \series default
11832  storage class for the Medium Memory model, e.g.:
11833 \end_layout
11834
11835 \begin_layout Verse
11836
11837 \family typewriter
11838 __pdata unsigned char test_pdata;
11839 \end_layout
11840
11841 \begin_layout Standard
11842 Writing 0x01 to this variable generates the assembly code:
11843 \end_layout
11844
11845 \begin_layout Verse
11846
11847 \family typewriter
11848 78r00\InsetSpace ~
11849 \InsetSpace ~
11850 \InsetSpace ~
11851 \InsetSpace ~
11852 \InsetSpace ~
11853 \InsetSpace ~
11854 mov r0,#_test_pdata
11855 \newline
11856 74 01\InsetSpace ~
11857 \InsetSpace ~
11858 \InsetSpace ~
11859 \InsetSpace ~
11860 \InsetSpace ~
11861 \InsetSpace ~
11862 mov a,#0x01 
11863 \newline
11864 F2\InsetSpace ~
11865 \InsetSpace ~
11866 \InsetSpace ~
11867 \InsetSpace ~
11868 \InsetSpace ~
11869 \InsetSpace ~
11870 \InsetSpace ~
11871 \InsetSpace ~
11872 \InsetSpace ~
11873 movx @r0,a
11874 \end_layout
11875
11876 \begin_layout Standard
11877 If the -
11878 \begin_inset ERT
11879 status collapsed
11880
11881 \begin_layout Standard
11882
11883
11884 \backslash
11885 /
11886 \end_layout
11887
11888 \end_inset
11889
11890 -xstack
11891 \begin_inset LatexCommand \index{-\/-xstack}
11892
11893 \end_inset
11894
11895  option is used the pdata memory area is followed by the xstack memory area
11896  and the sum of their sizes is limited to 256 bytes.
11897 \end_layout
11898
11899 \begin_layout Subsubsection
11900 code
11901 \begin_inset LatexCommand \index{code}
11902
11903 \end_inset
11904
11905
11906 \begin_inset LatexCommand \index{\_\_code}
11907
11908 \end_inset
11909
11910
11911 \end_layout
11912
11913 \begin_layout Standard
11914 'Variables' declared with this storage class will be placed in the code
11915  memory:
11916 \end_layout
11917
11918 \begin_layout Verse
11919
11920 \family typewriter
11921 __code unsigned char test_code;
11922 \end_layout
11923
11924 \begin_layout Standard
11925 Read access to this variable generates the assembly code:
11926 \end_layout
11927
11928 \begin_layout Verse
11929
11930 \family typewriter
11931 90s00r6F\InsetSpace ~
11932 \InsetSpace ~
11933 \InsetSpace ~
11934 mov dptr,#_test_code
11935 \newline
11936 E4\InsetSpace ~
11937 \InsetSpace ~
11938 \InsetSpace ~
11939 \InsetSpace ~
11940 \InsetSpace ~
11941 \InsetSpace ~
11942 \InsetSpace ~
11943 \InsetSpace ~
11944 \InsetSpace ~
11945 clr a
11946 \newline
11947 93\InsetSpace ~
11948 \InsetSpace ~
11949 \InsetSpace ~
11950 \InsetSpace ~
11951 \InsetSpace ~
11952 \InsetSpace ~
11953 \InsetSpace ~
11954 \InsetSpace ~
11955 \InsetSpace ~
11956 movc a,@a+dptr 
11957 \end_layout
11958
11959 \begin_layout Standard
11960
11961 \family typewriter
11962 char
11963 \family default
11964  indexed arrays of characters in code memory can be accessed efficiently:
11965 \end_layout
11966
11967 \begin_layout Verse
11968
11969 \family typewriter
11970 __code char test_array[] = {'c','h','e','a','p'}; 
11971 \end_layout
11972
11973 \begin_layout Standard
11974 Read access to this array using an 8-bit unsigned index generates the assembly
11975  code:
11976 \end_layout
11977
11978 \begin_layout Verse
11979
11980 \family typewriter
11981 E5*00\InsetSpace ~
11982 \InsetSpace ~
11983 \InsetSpace ~
11984 \InsetSpace ~
11985 \InsetSpace ~
11986 \InsetSpace ~
11987 mov a,_index 
11988 \end_layout
11989
11990 \begin_layout Verse
11991
11992 \family typewriter
11993 90s00r41\InsetSpace ~
11994 \InsetSpace ~
11995 \InsetSpace ~
11996 mov dptr,#_test_array
11997 \end_layout
11998
11999 \begin_layout Verse
12000
12001 \family typewriter
12002 93\InsetSpace ~
12003 \InsetSpace ~
12004 \InsetSpace ~
12005 \InsetSpace ~
12006 \InsetSpace ~
12007 \InsetSpace ~
12008 \InsetSpace ~
12009 \InsetSpace ~
12010 \InsetSpace ~
12011 movc a,@a+dptr 
12012 \end_layout
12013
12014 \begin_layout Subsubsection
12015 bit
12016 \begin_inset LatexCommand \index{bit}
12017
12018 \end_inset
12019
12020
12021 \begin_inset LatexCommand \index{\_\_bit}
12022
12023 \end_inset
12024
12025
12026 \end_layout
12027
12028 \begin_layout Standard
12029 This is a data-type and a storage class specifier.
12030  When a variable is declared as a bit, it is allocated into the bit addressable
12031  memory of 8051, e.g.:
12032 \end_layout
12033
12034 \begin_layout Verse
12035
12036 \family typewriter
12037 __bit test_bit;
12038 \end_layout
12039
12040 \begin_layout Standard
12041 Writing 1 to this variable generates the assembly code:
12042 \end_layout
12043
12044 \begin_layout Verse
12045
12046 \family typewriter
12047 D2*00\InsetSpace ~
12048 \InsetSpace ~
12049 \InsetSpace ~
12050 \InsetSpace ~
12051 \InsetSpace ~
12052 \InsetSpace ~
12053 \InsetSpace ~
12054 setb\InsetSpace ~
12055 _test_bit
12056 \end_layout
12057
12058 \begin_layout Standard
12059 The bit addressable memory consists of 128 bits which are located from 0x20
12060  to 0x2f in data memory.
12061  
12062 \newline
12063 Apart from this 8051 specific storage class most architectures support
12064  ANSI-C bitfields
12065 \begin_inset LatexCommand \index{bitfields}
12066
12067 \end_inset
12068
12069
12070 \begin_inset Foot
12071 status open
12072
12073 \begin_layout Standard
12074 Not really meant as examples, but nevertheless showing what bitfields are
12075  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12076 \end_layout
12077
12078 \end_inset
12079
12080 .
12081  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12082  signed modifier are implemented as unsigned.
12083 \end_layout
12084
12085 \begin_layout Subsubsection
12086 sfr
12087 \begin_inset LatexCommand \index{sfr}
12088
12089 \end_inset
12090
12091
12092 \begin_inset LatexCommand \index{\_\_sfr}
12093
12094 \end_inset
12095
12096  / sfr16
12097 \begin_inset LatexCommand \index{sfr16}
12098
12099 \end_inset
12100
12101
12102 \begin_inset LatexCommand \index{\_\_sfr16}
12103
12104 \end_inset
12105
12106  / sfr32
12107 \begin_inset LatexCommand \index{sfr32}
12108
12109 \end_inset
12110
12111
12112 \begin_inset LatexCommand \index{\_\_sfr32}
12113
12114 \end_inset
12115
12116  / sbit
12117 \begin_inset LatexCommand \index{\_\_sbit}
12118
12119 \end_inset
12120
12121
12122 \begin_inset LatexCommand \index{sbit}
12123
12124 \end_inset
12125
12126
12127 \end_layout
12128
12129 \begin_layout Standard
12130 Like the bit keyword, 
12131 \emph on
12132 sfr / sfr16 / sfr32 / sbit 
12133 \emph default
12134 signify both a data-type and storage class, they are used to describe the
12135  
12136 \emph on
12137 s
12138 \emph default
12139 pecial 
12140 \emph on
12141 f
12142 \emph default
12143 unction 
12144 \emph on
12145 r
12146 \emph default
12147 egisters and 
12148 \emph on
12149 s
12150 \emph default
12151 pecial 
12152 \emph on
12153 bit
12154 \emph default
12155  variables of a 8051, eg:
12156 \end_layout
12157
12158 \begin_layout Verse
12159
12160 \family typewriter
12161 __sfr __at
12162 \begin_inset LatexCommand \index{at}
12163
12164 \end_inset
12165
12166
12167 \begin_inset LatexCommand \index{\_\_at}
12168
12169 \end_inset
12170
12171  (0x80) P0;\InsetSpace ~
12172  /* special function register P0 at location 0x80 */
12173 \newline
12174
12175 \newline
12176 /* 16 bit
12177  special function register combination for timer 0
12178 \newline
12179 \InsetSpace ~
12180 \InsetSpace ~
12181  with the high byte at
12182  location 0x8C and the low byte at location 0x8A */
12183 \newline
12184 __sfr16 __at (0x8C8A)
12185  TMR0;
12186 \newline
12187
12188 \newline
12189 __sbit __at
12190 \begin_inset LatexCommand \index{at}
12191
12192 \end_inset
12193
12194
12195 \begin_inset LatexCommand \index{\_\_at}
12196
12197 \end_inset
12198
12199  (0xd7) CY;\InsetSpace ~
12200  /* CY (Carry Flag
12201 \begin_inset LatexCommand \index{Flags}
12202
12203 \end_inset
12204
12205
12206 \begin_inset LatexCommand \index{Carry flag}
12207
12208 \end_inset
12209
12210 ) */
12211 \end_layout
12212
12213 \begin_layout Standard
12214 Special function registers which are located on an address dividable by
12215  8 are bit-addressable, an
12216 \emph on
12217  sbit
12218 \emph default
12219  addresses a specific bit within these sfr.
12220 \newline
12221 16 Bit and 32 bit special function
12222  register combinations which require a certain access order are better not
12223  declared using 
12224 \emph on
12225 sfr16
12226 \emph default
12227  or 
12228 \emph on
12229 sfr32.
12230
12231 \emph default
12232  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12233  this is not guaranteed.
12234 \newline
12235
12236 \end_layout
12237
12238 \begin_layout Standard
12239 Please note, if you use a header file which was written for another compiler
12240  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12241  likely be 
12242 \emph on
12243 not 
12244 \emph default
12245 compatible.
12246  Specifically the syntax 
12247 \family typewriter
12248 \InsetSpace ~
12249 sfr P0 = 0x80;\InsetSpace ~
12250
12251 \family default
12252  is compiled 
12253 \emph on
12254 without warning
12255 \emph default
12256  by SDCC to an assignment of 0x80 to a variable called P0 
12257 \family typewriter
12258
12259 \begin_inset Marginal
12260 status collapsed
12261
12262 \begin_layout Standard
12263
12264 \series bold
12265 \InsetSpace ~
12266 !
12267 \end_layout
12268
12269 \end_inset
12270
12271 .
12272  
12273 \family default
12274 Nevertheless it is possible to write header files
12275 \begin_inset LatexCommand \index{Header files}
12276
12277 \end_inset
12278
12279
12280 \begin_inset LatexCommand \index{Include files}
12281
12282 \end_inset
12283
12284  which can be shared among different compilers (see section 
12285 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12286
12287 \end_inset
12288
12289 ).
12290  
12291 \end_layout
12292
12293 \begin_layout Subsubsection
12294 Pointers
12295 \begin_inset LatexCommand \index{Pointer}
12296
12297 \end_inset
12298
12299  to MCS51/DS390 specific memory spaces
12300 \end_layout
12301
12302 \begin_layout Standard
12303 SDCC allows (via language extensions) pointers to explicitly point to any
12304  of the memory spaces
12305 \begin_inset LatexCommand \index{Memory model}
12306
12307 \end_inset
12308
12309  of the 8051.
12310  In addition to the explicit pointers, the compiler uses (by default) generic
12311  pointers which can be used to point to any of the memory spaces.
12312 \newline
12313
12314 \newline
12315 Pointer
12316  declaration examples:
12317 \end_layout
12318
12319 \begin_layout Verse
12320
12321 \family typewriter
12322 /* pointer physically in internal ram pointing to object in external ram
12323  */ 
12324 \newline
12325 __xdata unsigned char * __data p;
12326 \newline
12327
12328 \newline
12329 /* pointer physically in external ram
12330  pointing to object in internal ram */ 
12331 \newline
12332 __data unsigned char * __xdata p;
12333 \newline
12334
12335 \newline
12336 /*
12337  pointer physically in code rom pointing to data in xdata space */ 
12338 \newline
12339 __xdata
12340  unsigned char * __code p;
12341 \newline
12342
12343 \newline
12344 /* pointer physically in code space pointing to
12345  data in code space */ 
12346 \newline
12347 __code unsigned char * __code p;
12348 \newline
12349
12350 \newline
12351 /* generic pointer
12352  physically located in xdata space */
12353 \newline
12354 unsigned char * __xdata p;
12355 \newline
12356
12357 \newline
12358 /* generic
12359  pointer physically located in default memory space */
12360 \newline
12361 unsigned char * p;
12362 \newline
12363
12364 \newline
12365 /*
12366  the following is a function pointer
12367 \begin_inset LatexCommand \index{function pointer}
12368
12369 \end_inset
12370
12371  physically located in data space */
12372 \newline
12373 char (* __data fp)(void);
12374 \end_layout
12375
12376 \begin_layout Standard
12377 Well you get the idea.
12378  
12379 \newline
12380
12381 \newline
12382 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
12383 \emph on
12384 generic
12385 \emph default
12386  pointers.
12387  
12388 \size small
12389
12390 \newline
12391
12392 \newline
12393
12394 \size default
12395 The highest order byte of the 
12396 \emph on
12397 generic
12398 \emph default
12399  pointers contains the data space information.
12400  Assembler support routines are called whenever data is stored or retrieved
12401  using 
12402 \emph on
12403 generic
12404 \emph default
12405  pointers.
12406  These are useful for developing reusable library
12407 \begin_inset LatexCommand \index{Libraries}
12408
12409 \end_inset
12410
12411  routines.
12412  Explicitly specifying the pointer
12413 \begin_inset LatexCommand \index{pointer}
12414
12415 \end_inset
12416
12417  type will generate the most efficient code.
12418 \end_layout
12419
12420 \begin_layout Subsubsection
12421 Notes on MCS51 memory
12422 \begin_inset LatexCommand \index{MCS51 memory}
12423
12424 \end_inset
12425
12426  layout
12427 \end_layout
12428
12429 \begin_layout Standard
12430 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12431  RAM memory which is structured as follows:
12432 \newline
12433
12434 \newline
12435 - Bytes 00-1F - 32 bytes to hold
12436  up to 4 banks of the registers R0 to R7, 
12437 \newline
12438 - Bytes 20-2F - 16 bytes to hold
12439  128 bit
12440 \begin_inset LatexCommand \index{bit}
12441
12442 \end_inset
12443
12444  variables and, 
12445 \newline
12446 - Bytes 30-7F - 80 bytes for general purpose use.
12447 \newline
12448
12449 \end_layout
12450
12451 \begin_layout Standard
12452 Additionally some members of the MCS51 family may have up to 128 bytes of
12453  additional, indirectly addressable, internal RAM memory (
12454 \emph on
12455 idata
12456 \emph default
12457
12458 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12459
12460 \end_inset
12461
12462
12463 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12464
12465 \end_inset
12466
12467 ).
12468  Furthermore, some chips may have some built in external memory (
12469 \emph on
12470 xdata
12471 \emph default
12472
12473 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12474
12475 \end_inset
12476
12477
12478 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12479
12480 \end_inset
12481
12482 ) which should not be confused with the internal, directly addressable RAM
12483  memory (
12484 \emph on
12485 data
12486 \emph default
12487
12488 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12489
12490 \end_inset
12491
12492
12493 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12494
12495 \end_inset
12496
12497 ).
12498  Sometimes this built in 
12499 \emph on
12500 xdata
12501 \emph default
12502  memory has to be activated before using it (you can probably find this
12503  information on the datasheet of the microcontroller your are using, see
12504  also section 
12505 \begin_inset LatexCommand \ref{sub:Startup-Code}
12506
12507 \end_inset
12508
12509 \InsetSpace ~
12510 Startup-Code).
12511 \end_layout
12512
12513 \begin_layout Standard
12514 Normally SDCC will only use the first bank
12515 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12516
12517 \end_inset
12518
12519  of registers (register bank 0), but it is possible to specify that other
12520  banks of registers (keyword 
12521 \emph on
12522 using
12523 \emph default
12524  
12525 \emph on
12526
12527 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12528
12529 \end_inset
12530
12531
12532 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12533
12534 \end_inset
12535
12536
12537 \emph default
12538 ) should be used for example in interrupt
12539 \begin_inset LatexCommand \index{interrupt}
12540
12541 \end_inset
12542
12543
12544 \begin_inset LatexCommand \index{\_\_interrupt}
12545
12546 \end_inset
12547
12548  routines.
12549  By default, the compiler will place the stack after the last byte of allocated
12550  memory for variables.
12551  For example, if the first 2 banks of registers are used, and only four
12552  bytes are used for 
12553 \emph on
12554 data
12555 \emph default
12556  variables, it will position the base of the internal stack at address 20
12557  (0x14).
12558  This implies that as the stack
12559 \begin_inset LatexCommand \index{stack}
12560
12561 \end_inset
12562
12563  grows, it will use up the remaining register banks, and the 16 bytes used
12564  by the 128 bit variables, and 80 bytes for general purpose use.
12565  If any bit variables are used, the data variables will be placed in unused
12566  register banks and after the byte holding the last bit variable.
12567  For example, if register banks 0 and 1 are used, and there are 9 bit variables
12568  (two bytes used), 
12569 \emph on
12570 data
12571 \emph default
12572  variables will be placed starting from address 0x10 to 0x20 and continue
12573  at address 0x22.
12574  You can also use -
12575 \begin_inset ERT
12576 status collapsed
12577
12578 \begin_layout Standard
12579
12580
12581 \backslash
12582 /
12583 \end_layout
12584
12585 \end_inset
12586
12587 -data-loc
12588 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12589
12590 \end_inset
12591
12592  to specify the start address of the 
12593 \emph on
12594 data
12595 \emph default
12596  and -
12597 \begin_inset ERT
12598 status collapsed
12599
12600 \begin_layout Standard
12601
12602
12603 \backslash
12604 /
12605 \end_layout
12606
12607 \end_inset
12608
12609 -iram-size
12610 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12611
12612 \end_inset
12613
12614  to specify the size of the total internal RAM (
12615 \emph on
12616 data
12617 \emph default
12618 +
12619 \emph on
12620 idata
12621 \emph default
12622 ).
12623  
12624 \newline
12625
12626 \end_layout
12627
12628 \begin_layout Standard
12629 By default the 8051 linker will place the stack after the last byte of (i)data
12630  variables.
12631  Option -
12632 \begin_inset ERT
12633 status collapsed
12634
12635 \begin_layout Standard
12636
12637
12638 \backslash
12639 /
12640 \end_layout
12641
12642 \end_inset
12643
12644 -stack-loc
12645 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12646
12647 \end_inset
12648
12649  allows you to specify the start of the stack, i.e.
12650  you could start it after any data in the general purpose area.
12651  If your microcontroller has additional indirectly addressable internal
12652  RAM (
12653 \emph on
12654 idata
12655 \emph default
12656 ) you can place the stack on it.
12657  You may also need to use -
12658 \begin_inset ERT
12659 status collapsed
12660
12661 \begin_layout Standard
12662
12663
12664 \backslash
12665 /
12666 \end_layout
12667
12668 \end_inset
12669
12670 -xdata-loc
12671 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12672
12673 \end_inset
12674
12675  to set the start address of the external RAM (
12676 \emph on
12677 xdata
12678 \emph default
12679 ) and -
12680 \begin_inset ERT
12681 status collapsed
12682
12683 \begin_layout Standard
12684
12685
12686 \backslash
12687 /
12688 \end_layout
12689
12690 \end_inset
12691
12692 -xram-size
12693 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12694
12695 \end_inset
12696
12697  to specify its size.
12698  Same goes for the code memory, using -
12699 \begin_inset ERT
12700 status collapsed
12701
12702 \begin_layout Standard
12703
12704
12705 \backslash
12706 /
12707 \end_layout
12708
12709 \end_inset
12710
12711 -code-loc
12712 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12713
12714 \end_inset
12715
12716  and -
12717 \begin_inset ERT
12718 status collapsed
12719
12720 \begin_layout Standard
12721
12722
12723 \backslash
12724 /
12725 \end_layout
12726
12727 \end_inset
12728
12729 -code-size
12730 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12731
12732 \end_inset
12733
12734 .
12735  If in doubt, don't specify any options and see if the resulting memory
12736  layout is appropriate, then you can adjust it.
12737 \end_layout
12738
12739 \begin_layout Standard
12740 The linker generates two files with memory allocation information.
12741  The first, with extension .map
12742 \begin_inset LatexCommand \index{<file>.map}
12743
12744 \end_inset
12745
12746  shows all the variables and segments.
12747  The second with extension .mem
12748 \begin_inset LatexCommand \index{<file>.mem}
12749
12750 \end_inset
12751
12752  shows the final memory layout.
12753  The linker will complain either if memory segments overlap, there is not
12754  enough memory, or there is not enough space for stack.
12755  If you get any linking warnings and/or errors related to stack or segments
12756  allocation, take a look at either the .map or .mem files to find out what
12757  the problem is.
12758  The .mem file may even suggest a solution to the problem.
12759 \begin_inset VSpace bigskip
12760 \end_inset
12761
12762
12763 \end_layout
12764
12765 \begin_layout Subsection
12766 Z80/Z180 Storage Class
12767 \begin_inset LatexCommand \index{Z80!Storage class}
12768
12769 \end_inset
12770
12771  Language Extensions
12772 \end_layout
12773
12774 \begin_layout Subsubsection
12775 sfr
12776 \begin_inset LatexCommand \index{sfr}
12777
12778 \end_inset
12779
12780
12781 \begin_inset LatexCommand \index{\_\_sfr}
12782
12783 \end_inset
12784
12785  (in/out to 8-bit addresses)
12786 \end_layout
12787
12788 \begin_layout Standard
12789 The Z80
12790 \begin_inset LatexCommand \index{Z80}
12791
12792 \end_inset
12793
12794  family has separate address spaces for memory and 
12795 \emph on
12796 i
12797 \emph default
12798 nput/
12799 \emph on
12800 o
12801 \emph default
12802 utput memory.
12803  I/O memory
12804 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12805
12806 \end_inset
12807
12808
12809 \begin_inset LatexCommand \index{Z80!I/O memory}
12810
12811 \end_inset
12812
12813
12814 \begin_inset LatexCommand \index{Z180!I/O memory}
12815
12816 \end_inset
12817
12818  is accessed with special instructions, e.g.:
12819 \end_layout
12820
12821 \begin_layout Verse
12822
12823 \family typewriter
12824 sfr at 0x78 IoPort;\InsetSpace ~
12825 \InsetSpace ~
12826 /* define a var in I/O space at 78h called IoPort */
12827  
12828 \end_layout
12829
12830 \begin_layout Standard
12831 Writing 0x01 to this variable generates the assembly code:
12832 \end_layout
12833
12834 \begin_layout Verse
12835
12836 \family typewriter
12837 3E 01\InsetSpace ~
12838 \InsetSpace ~
12839 \InsetSpace ~
12840 \InsetSpace ~
12841 \InsetSpace ~
12842 \InsetSpace ~
12843 ld a,#0x01
12844 \newline
12845 D3 78\InsetSpace ~
12846 \InsetSpace ~
12847 \InsetSpace ~
12848 \InsetSpace ~
12849 \InsetSpace ~
12850 \InsetSpace ~
12851 out (_IoPort),a 
12852 \end_layout
12853
12854 \begin_layout Subsubsection
12855 banked sfr
12856 \begin_inset LatexCommand \index{sfr}
12857
12858 \end_inset
12859
12860
12861 \begin_inset LatexCommand \index{\_\_sfr}
12862
12863 \end_inset
12864
12865  (in/out to 16-bit addresses)
12866 \end_layout
12867
12868 \begin_layout Standard
12869 The keyword 
12870 \emph on
12871 banked
12872 \emph default
12873  is used to support 16 bit addresses in I/O memory e.g.:
12874 \end_layout
12875
12876 \begin_layout Verse
12877
12878 \family typewriter
12879 sfr banked at
12880 \begin_inset LatexCommand \index{at}
12881
12882 \end_inset
12883
12884
12885 \begin_inset LatexCommand \index{\_\_at}
12886
12887 \end_inset
12888
12889  0x123 IoPort; 
12890 \end_layout
12891
12892 \begin_layout Standard
12893 Writing 0x01 to this variable generates the assembly code:
12894 \end_layout
12895
12896 \begin_layout Verse
12897
12898 \family typewriter
12899 01 23 01\InsetSpace ~
12900 \InsetSpace ~
12901 \InsetSpace ~
12902 ld bc,#_IoPort
12903 \newline
12904 3E 01\InsetSpace ~
12905 \InsetSpace ~
12906 \InsetSpace ~
12907 \InsetSpace ~
12908 \InsetSpace ~
12909 \InsetSpace ~
12910 ld a,#0x01 
12911 \newline
12912 ED 79\InsetSpace ~
12913 \InsetSpace ~
12914 \InsetSpace ~
12915 \InsetSpace ~
12916 \InsetSpace ~
12917 \InsetSpace ~
12918 out (c),a 
12919 \end_layout
12920
12921 \begin_layout Subsubsection
12922 sfr
12923 \begin_inset LatexCommand \index{sfr}
12924
12925 \end_inset
12926
12927
12928 \begin_inset LatexCommand \index{\_\_sfr}
12929
12930 \end_inset
12931
12932  (in0/out0 to 8 bit addresses on Z180
12933 \begin_inset LatexCommand \index{Z180}
12934
12935 \end_inset
12936
12937 /HD64180
12938 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12939
12940 \end_inset
12941
12942 )
12943 \end_layout
12944
12945 \begin_layout Standard
12946 The compiler option -
12947 \begin_inset ERT
12948 status collapsed
12949
12950 \begin_layout Standard
12951
12952
12953 \backslash
12954 /
12955 \end_layout
12956
12957 \end_inset
12958
12959 -portmode
12960 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12961
12962 \end_inset
12963
12964 =180 (80) and a compiler #pragma\InsetSpace ~
12965 portmode
12966 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12967
12968 \end_inset
12969
12970  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12971 ns 
12972 \family typewriter
12973 in0/out0
12974 \family default
12975  instead of 
12976 \family typewriter
12977 in/out
12978 \family default
12979 .
12980  If you include the file z180.h this will be set automatically.
12981 \begin_inset VSpace bigskip
12982 \end_inset
12983
12984
12985 \end_layout
12986
12987 \begin_layout Subsection
12988 HC08 Storage Class
12989 \begin_inset LatexCommand \index{HC08!Storage class}
12990
12991 \end_inset
12992
12993  Language Extensions
12994 \end_layout
12995
12996 \begin_layout Subsubsection
12997 data
12998 \begin_inset LatexCommand \index{data (hc08 storage class)}
12999
13000 \end_inset
13001
13002
13003 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
13004
13005 \end_inset
13006
13007  
13008 \end_layout
13009
13010 \begin_layout Standard
13011 The data storage class declares a variable that resides in the first 256
13012  bytes of memory (the direct page).
13013  The HC08
13014 \begin_inset LatexCommand \index{HC08}
13015
13016 \end_inset
13017
13018  is most efficient at accessing variables (especially pointers) stored here.
13019 \end_layout
13020
13021 \begin_layout Subsubsection
13022 xdata
13023 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
13024
13025 \end_inset
13026
13027
13028 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
13029
13030 \end_inset
13031
13032  
13033 \end_layout
13034
13035 \begin_layout Standard
13036 The xdata storage class declares a variable that can reside anywhere in
13037  memory.
13038  This is the default if no storage class is specified.
13039  
13040 \begin_inset VSpace bigskip
13041 \end_inset
13042
13043
13044 \end_layout
13045
13046 \begin_layout Section
13047 Absolute Addressing
13048 \begin_inset LatexCommand \index{Absolute addressing}
13049
13050 \end_inset
13051
13052
13053 \end_layout
13054
13055 \begin_layout Standard
13056 Data items can be assigned an absolute address with the 
13057 \emph on
13058 at
13059 \begin_inset LatexCommand \index{at}
13060
13061 \end_inset
13062
13063
13064 \begin_inset LatexCommand \index{\_\_at}
13065
13066 \end_inset
13067
13068  <address>
13069 \emph default
13070  keyword, in addition to a storage class, e.g.:
13071 \end_layout
13072
13073 \begin_layout Verse
13074
13075 \family typewriter
13076 xdata
13077 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13078
13079 \end_inset
13080
13081
13082 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
13083
13084 \end_inset
13085
13086  at
13087 \begin_inset LatexCommand \index{at}
13088
13089 \end_inset
13090
13091
13092 \begin_inset LatexCommand \index{\_\_at}
13093
13094 \end_inset
13095
13096  0x7ffe unsigned int chksum;
13097 \end_layout
13098
13099 \begin_layout Standard
13100 or, better conforming to ISO/IEC 9899 C:
13101 \end_layout
13102
13103 \begin_layout Verse
13104
13105 \family typewriter
13106 __xdata __at (0x7ffe) unsigned int chksum;
13107 \end_layout
13108
13109 \begin_layout Standard
13110 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13111  of the external ram.
13112  The compiler does 
13113 \emph on
13114 not
13115 \emph default
13116  reserve any space for variables declared in this way
13117 \begin_inset Marginal
13118 status collapsed
13119
13120 \begin_layout Standard
13121
13122 \series bold
13123 \InsetSpace ~
13124 !
13125 \end_layout
13126
13127 \end_inset
13128
13129  (they are implemented with an equate in the assembler).
13130  Thus it is left to the programmer to make sure there are no overlaps with
13131  other variables that are declared without the absolute address.
13132  The assembler listing file (.lst
13133 \begin_inset LatexCommand \index{<file>.lst}
13134
13135 \end_inset
13136
13137 ) and the linker output files (.rst
13138 \begin_inset LatexCommand \index{<file>.rst}
13139
13140 \end_inset
13141
13142 ) and (.map
13143 \begin_inset LatexCommand \index{<file>.map}
13144
13145 \end_inset
13146
13147 ) are good places to look for such overlaps.
13148 \end_layout
13149
13150 \begin_layout Standard
13151 If however you provide an initializer
13152 \begin_inset LatexCommand \index{Variable initialization}
13153
13154 \end_inset
13155
13156  actual memory allocation will take place and overlaps will be detected
13157  by the linker.
13158  E.g.:
13159 \end_layout
13160
13161 \begin_layout Verse
13162
13163 \family typewriter
13164 __code __at (0x7ff0) char Id[5] = 
13165 \begin_inset Quotes sld
13166 \end_inset
13167
13168 SDCC
13169 \begin_inset Quotes srd
13170 \end_inset
13171
13172 ;
13173 \end_layout
13174
13175 \begin_layout Standard
13176 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13177  in code memory.
13178 \end_layout
13179
13180 \begin_layout Standard
13181 In case of memory mapped I/O devices the keyword 
13182 \emph on
13183 volatile
13184 \emph default
13185  has to be used to tell the compiler that accesses might not be removed:
13186 \end_layout
13187
13188 \begin_layout Verse
13189
13190 \family typewriter
13191 volatile
13192 \begin_inset LatexCommand \index{volatile}
13193
13194 \end_inset
13195
13196  __xdata
13197 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13198
13199 \end_inset
13200
13201  __at
13202 \begin_inset LatexCommand \index{at}
13203
13204 \end_inset
13205
13206  (0x8000) unsigned char PORTA_8255;
13207 \end_layout
13208
13209 \begin_layout Standard
13210 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13211 r) array
13212 \family typewriter
13213 \size footnotesize
13214
13215 \begin_inset LatexCommand \index{Aligned array}
13216
13217 \end_inset
13218
13219
13220 \family default
13221 \size default
13222  starts at a block (256 byte) boundary
13223 \begin_inset LatexCommand \index{block boundary}
13224
13225 \end_inset
13226
13227  (section 
13228 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13229
13230 \end_inset
13231
13232  has an example).
13233 \newline
13234 Absolute addresses can be specified for variables in all
13235  storage classes, e.g.:
13236 \end_layout
13237
13238 \begin_layout Verse
13239
13240 \family typewriter
13241 __bit
13242 \begin_inset LatexCommand \index{bit}
13243
13244 \end_inset
13245
13246  __at
13247 \begin_inset LatexCommand \index{at}
13248
13249 \end_inset
13250
13251  (0x02) bvar;
13252 \end_layout
13253
13254 \begin_layout Standard
13255 The above example will allocate the variable at offset 0x02 in the bit-addressab
13256 le space.
13257  There is no real advantage to assigning absolute addresses to variables
13258  in this manner, unless you want strict control over all the variables allocated.
13259  One possible use would be to write hardware portable code.
13260  For example, if you have a routine that uses one or more of the microcontroller
13261  I/O pins, and such pins are different for two different hardwares, you
13262  can declare the I/O pins in your routine using:
13263 \end_layout
13264
13265 \begin_layout Verse
13266
13267 \family typewriter
13268 extern volatile
13269 \begin_inset LatexCommand \index{volatile}
13270
13271 \end_inset
13272
13273  __bit MOSI;\InsetSpace ~
13274 \InsetSpace ~
13275 \InsetSpace ~
13276 \InsetSpace ~
13277 /* master out, slave in */
13278 \newline
13279 extern volatile __bit MISO;\InsetSpace ~
13280 \InsetSpace ~
13281 \InsetSpace ~
13282 \InsetSpace ~
13283 /* master
13284  in, slave out */
13285 \newline
13286 extern volatile __bit MCLK;\InsetSpace ~
13287 \InsetSpace ~
13288 \InsetSpace ~
13289 \InsetSpace ~
13290 /* master clock */
13291 \newline
13292
13293 \newline
13294 /* Input and
13295  Output of a byte on a 3-wire serial bus.
13296 \newline
13297 \InsetSpace ~
13298 \InsetSpace ~
13299 \InsetSpace ~
13300 If needed adapt polarity of clock,
13301  polarity of data and bit order
13302 \newline
13303 \InsetSpace ~
13304 */
13305 \newline
13306 unsigned char spi_io(unsigned char out_byte)
13307  
13308 \newline
13309
13310 \newline
13311 \InsetSpace ~
13312 \InsetSpace ~
13313 \InsetSpace ~
13314 \InsetSpace ~
13315 unsigned char i=8;
13316 \newline
13317 \InsetSpace ~
13318 \InsetSpace ~
13319 \InsetSpace ~
13320 \InsetSpace ~
13321 do { 
13322 \newline
13323 \InsetSpace ~
13324 \InsetSpace ~
13325 \InsetSpace ~
13326 \InsetSpace ~
13327 \InsetSpace ~
13328 \InsetSpace ~
13329 \InsetSpace ~
13330 \InsetSpace ~
13331 MOSI = out_byte & 0x80; 
13332 \newline
13333 \InsetSpace ~
13334 \InsetSpace ~
13335 \InsetSpace ~
13336 \InsetSpace ~
13337 \InsetSpace ~
13338 \InsetSpace ~
13339 \InsetSpace ~
13340 \InsetSpace ~
13341 out_byte <<= 1;
13342 \newline
13343 \InsetSpace ~
13344 \InsetSpace ~
13345 \InsetSpace ~
13346 \InsetSpace ~
13347 \InsetSpace ~
13348 \InsetSpace ~
13349 \InsetSpace ~
13350 \InsetSpace ~
13351 MCLK =
13352  1; 
13353 \newline
13354 \InsetSpace ~
13355 \InsetSpace ~
13356 \InsetSpace ~
13357 \InsetSpace ~
13358 \InsetSpace ~
13359 \InsetSpace ~
13360 \InsetSpace ~
13361 \InsetSpace ~
13362 /* _asm nop _endasm; */\InsetSpace ~
13363 \InsetSpace ~
13364 \InsetSpace ~
13365 \InsetSpace ~
13366 \InsetSpace ~
13367 \InsetSpace ~
13368 \InsetSpace ~
13369 \InsetSpace ~
13370 /* for slow peripherals */
13371 \newline
13372 \InsetSpace ~
13373 \InsetSpace ~
13374 \InsetSpace ~
13375 \InsetSpace ~
13376 \InsetSpace ~
13377 \InsetSpace ~
13378 \InsetSpace ~
13379 \InsetSpace ~
13380 if(MISO) 
13381 \newline
13382 \InsetSpace ~
13383 \InsetSpace ~
13384 \InsetSpace ~
13385 \InsetSpace ~
13386 \InsetSpace ~
13387 \InsetSpace ~
13388 \InsetSpace ~
13389 \InsetSpace ~
13390 \InsetSpace ~
13391 \InsetSpace ~
13392 \InsetSpace ~
13393 \InsetSpace ~
13394 out_byte +=
13395  1; 
13396 \newline
13397 \InsetSpace ~
13398 \InsetSpace ~
13399 \InsetSpace ~
13400 \InsetSpace ~
13401 \InsetSpace ~
13402 \InsetSpace ~
13403 \InsetSpace ~
13404 \InsetSpace ~
13405 MCLK = 0; 
13406 \newline
13407 \InsetSpace ~
13408 \InsetSpace ~
13409 \InsetSpace ~
13410 \InsetSpace ~
13411 } while(--i);
13412 \newline
13413 \InsetSpace ~
13414 \InsetSpace ~
13415 \InsetSpace ~
13416 \InsetSpace ~
13417 return out_byte; 
13418 \newline
13419 }
13420 \end_layout
13421
13422 \begin_layout Standard
13423 Then, someplace in the code for the first hardware you would use
13424 \end_layout
13425
13426 \begin_layout Verse
13427
13428 \family typewriter
13429 __bit __at
13430 \begin_inset LatexCommand \index{at}
13431
13432 \end_inset
13433
13434
13435 \begin_inset LatexCommand \index{\_\_at}
13436
13437 \end_inset
13438
13439  (0x80) MOSI;\InsetSpace ~
13440 \InsetSpace ~
13441 \InsetSpace ~
13442 \InsetSpace ~
13443 /* I/O port 0, bit 0 */
13444 \newline
13445 __bit __at (0x81) MISO;\InsetSpace ~
13446 \InsetSpace ~
13447 \InsetSpace ~
13448 \InsetSpace ~
13449 /* I/O port 0,
13450  bit 1 */
13451 \newline
13452 __bit __at (0x82) MCLK;\InsetSpace ~
13453 \InsetSpace ~
13454 \InsetSpace ~
13455 \InsetSpace ~
13456 /* I/O port 0, bit 2 */
13457 \end_layout
13458
13459 \begin_layout Standard
13460 Similarly, for the second hardware you would use
13461 \end_layout
13462
13463 \begin_layout Verse
13464
13465 \family typewriter
13466 __bit __at (0x83) MOSI;\InsetSpace ~
13467 \InsetSpace ~
13468 \InsetSpace ~
13469 \InsetSpace ~
13470 /* I/O port 0, bit 3 */
13471 \newline
13472 __bit __at (0x91) MISO;\InsetSpace ~
13473 \InsetSpace ~
13474 \InsetSpace ~
13475 \InsetSpace ~
13476 /*
13477  I/O port 1, bit 1 */
13478 \newline
13479 __bit
13480 \begin_inset LatexCommand \index{bit}
13481
13482 \end_inset
13483
13484  __at (0x92) MCLK;\InsetSpace ~
13485 \InsetSpace ~
13486 \InsetSpace ~
13487 \InsetSpace ~
13488 /* I/O port 1, bit 2 */
13489 \end_layout
13490
13491 \begin_layout Standard
13492 and you can use the same hardware dependent routine without changes, as
13493  for example in a library.
13494  This is somehow similar to sbit, but only one absolute address has to be
13495  specified in the whole project.
13496 \begin_inset VSpace bigskip
13497 \end_inset
13498
13499
13500 \end_layout
13501
13502 \begin_layout Section
13503 Parameters
13504 \begin_inset LatexCommand \index{Parameters}
13505
13506 \end_inset
13507
13508
13509 \begin_inset LatexCommand \index{function parameter}
13510
13511 \end_inset
13512
13513  & Local Variables
13514 \begin_inset LatexCommand \index{local variables}
13515
13516 \end_inset
13517
13518
13519 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13520
13521 \end_inset
13522
13523
13524 \end_layout
13525
13526 \begin_layout Standard
13527 Automatic (local) variables and parameters to functions can either be placed
13528  on the stack or in data-space.
13529  The default action of the compiler is to place these variables in the internal
13530  RAM (for small model) or external RAM (for medium or large model).
13531  This in fact makes them similar to 
13532 \emph on
13533 static
13534 \begin_inset LatexCommand \index{static}
13535
13536 \end_inset
13537
13538
13539 \emph default
13540  so by default functions are non-reentrant
13541 \begin_inset LatexCommand \index{reentrant}
13542
13543 \end_inset
13544
13545 .
13546  
13547 \newline
13548
13549 \newline
13550 They can be placed on the stack
13551 \begin_inset LatexCommand \index{stack}
13552
13553 \end_inset
13554
13555  by using the
13556 \emph on
13557  -
13558 \begin_inset ERT
13559 status collapsed
13560
13561 \begin_layout Standard
13562
13563
13564 \backslash
13565 /
13566 \end_layout
13567
13568 \end_inset
13569
13570 -stack-auto
13571 \begin_inset LatexCommand \index{-\/-stack-auto}
13572
13573 \end_inset
13574
13575
13576 \emph default
13577  option, by using 
13578 \emph on
13579 #pragma\InsetSpace ~
13580 stackauto
13581 \emph default
13582
13583 \begin_inset LatexCommand \index{\#pragma stackauto}
13584
13585 \end_inset
13586
13587  or by using the 
13588 \emph on
13589 reentrant
13590 \begin_inset LatexCommand \index{reentrant}
13591
13592 \end_inset
13593
13594
13595 \emph default
13596  keyword in the function declaration, e.g.:
13597 \end_layout
13598
13599 \begin_layout Verse
13600
13601 \family typewriter
13602 unsigned char foo(char i) __reentrant 
13603 \newline
13604
13605 \newline
13606 \InsetSpace ~
13607 \InsetSpace ~
13608 \InsetSpace ~
13609 \InsetSpace ~
13610 ...
13611  
13612 \newline
13613 }
13614 \end_layout
13615
13616 \begin_layout Standard
13617 Since stack space on 8051 is limited, the 
13618 \emph on
13619 reentrant 
13620 \emph default
13621 keyword or the
13622 \emph on
13623  -
13624 \begin_inset ERT
13625 status collapsed
13626
13627 \begin_layout Standard
13628
13629
13630 \backslash
13631 /
13632 \end_layout
13633
13634 \end_inset
13635
13636 -stack-auto
13637 \emph default
13638  option should be used sparingly.
13639  Note that the reentrant keyword just means that the parameters & local
13640  variables will be allocated to the stack, it 
13641 \emph on
13642 does not
13643 \emph default
13644  mean that the function is register bank
13645 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13646
13647 \end_inset
13648
13649  independent.
13650 \newline
13651
13652 \newline
13653 Local variables
13654 \begin_inset LatexCommand \index{local variables}
13655
13656 \end_inset
13657
13658  can be assigned storage classes and absolute
13659 \begin_inset LatexCommand \index{Absolute addressing}
13660
13661 \end_inset
13662
13663  addresses, e.g.: 
13664 \end_layout
13665
13666 \begin_layout Verse
13667
13668 \family typewriter
13669 unsigned char foo() 
13670 \newline
13671 {
13672 \newline
13673 \InsetSpace ~
13674 \InsetSpace ~
13675 \InsetSpace ~
13676 \InsetSpace ~
13677 __xdata unsigned char i;
13678 \newline
13679 \InsetSpace ~
13680 \InsetSpace ~
13681 \InsetSpace ~
13682 \InsetSpace ~
13683 __bit bvar;
13684 \newline
13685 \InsetSpace ~
13686 \InsetSpace ~
13687 \InsetSpace ~
13688 \InsetSpace ~
13689 __data __at
13690 \begin_inset LatexCommand \index{at}
13691
13692 \end_inset
13693
13694  (0x31) unsigned char j;
13695 \newline
13696 \InsetSpace ~
13697 \InsetSpace ~
13698 \InsetSpace ~
13699 \InsetSpace ~
13700 ...
13701  
13702 \newline
13703 }
13704 \end_layout
13705
13706 \begin_layout Standard
13707 In the above example the variable 
13708 \emph on
13709 i
13710 \emph default
13711  will be allocated in the external ram, 
13712 \emph on
13713 bvar
13714 \emph default
13715  in bit addressable space and
13716 \emph on
13717  j
13718 \emph default
13719  in internal ram.
13720  When compiled with 
13721 \emph on
13722 -
13723 \begin_inset ERT
13724 status collapsed
13725
13726 \begin_layout Standard
13727
13728
13729 \backslash
13730 /
13731 \end_layout
13732
13733 \end_inset
13734
13735 -stack-auto
13736 \emph default
13737  or when a function is declared as 
13738 \emph on
13739 reentrant
13740 \emph default
13741  this should only be done for static variables.
13742 \end_layout
13743
13744 \begin_layout Standard
13745 Parameters
13746 \begin_inset LatexCommand \index{function parameter}
13747
13748 \end_inset
13749
13750  however are not allowed any storage class
13751 \begin_inset LatexCommand \index{Storage class}
13752
13753 \end_inset
13754
13755 , (storage classes for parameters will be ignored), their allocation is
13756  governed by the memory model in use, and the reentrancy options.
13757 \end_layout
13758
13759 \begin_layout Standard
13760 It is however allowed to use bit parameters in reentrant functions and also
13761  non-static local bit variables are supported.
13762  Efficient use is limited to 8 semi-bitregisters in bit space.
13763  They are pushed and popped to stack
13764 \begin_inset LatexCommand \index{stack}
13765
13766 \end_inset
13767
13768  as a single byte just like the normal registers.
13769 \end_layout
13770
13771 \begin_layout Section
13772 Overlaying
13773 \begin_inset LatexCommand \label{sub:Overlaying}
13774
13775 \end_inset
13776
13777
13778 \begin_inset LatexCommand \index{Overlaying}
13779
13780 \end_inset
13781
13782
13783 \end_layout
13784
13785 \begin_layout Standard
13786 For non-reentrant
13787 \begin_inset LatexCommand \index{reentrant}
13788
13789 \end_inset
13790
13791  functions SDCC will try to reduce internal ram space usage by overlaying
13792  parameters and local variables of a function (if possible).
13793  Parameters and local variables
13794 \begin_inset LatexCommand \index{local variables}
13795
13796 \end_inset
13797
13798  of a function will be allocated to an overlayable segment if the function
13799  has 
13800 \emph on
13801 no other function calls and the function is non-reentrant and the memory
13802  model
13803 \begin_inset LatexCommand \index{Memory model}
13804
13805 \end_inset
13806
13807  is small.
13808
13809 \emph default
13810  If an explicit storage class
13811 \begin_inset LatexCommand \index{Storage class}
13812
13813 \end_inset
13814
13815  is specified for a local variable, it will NOT be overlayed.
13816 \end_layout
13817
13818 \begin_layout Standard
13819 Note that the compiler (not the linkage editor) makes the decision for overlayin
13820 g the data items.
13821  Functions that are called from an interrupt service routine
13822 \begin_inset Marginal
13823 status collapsed
13824
13825 \begin_layout Standard
13826
13827 \series bold
13828 !
13829 \end_layout
13830
13831 \end_inset
13832
13833  should be preceded by a #pragma\InsetSpace ~
13834 nooverlay
13835 \begin_inset LatexCommand \index{\#pragma nooverlay}
13836
13837 \end_inset
13838
13839  if they are not reentrant.
13840 \end_layout
13841
13842 \begin_layout Standard
13843 Also note that the compiler does not do any processing of inline assembler
13844  code, so the compiler might incorrectly assign local variables and parameters
13845  of a function into the overlay segment if the inline assembler code calls
13846  other c-functions that might use the overlay.
13847  In that case the #pragma\InsetSpace ~
13848 nooverlay should be used.
13849 \end_layout
13850
13851 \begin_layout Standard
13852 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13853 tion
13854 \begin_inset LatexCommand \index{Multiplication}
13855
13856 \end_inset
13857
13858  or division
13859 \begin_inset LatexCommand \index{Division}
13860
13861 \end_inset
13862
13863  will NOT be overlayed since these are implemented using external functions,
13864  e.g.:
13865 \end_layout
13866
13867 \begin_layout Verse
13868
13869 \family typewriter
13870 #pragma save 
13871 \newline
13872 #pragma nooverlay
13873 \begin_inset LatexCommand \index{\#pragma nooverlay}
13874
13875 \end_inset
13876
13877  
13878 \newline
13879 void set_error(unsigned char errcd) 
13880 \newline
13881 {
13882 \newline
13883 \InsetSpace ~
13884 \InsetSpace ~
13885 \InsetSpace ~
13886 \InsetSpace ~
13887 P3 = errcd;
13888 \newline
13889
13890 \newline
13891 #pragma restore 
13892 \newline
13893
13894 \newline
13895 void
13896  some_isr () __interrupt
13897 \begin_inset LatexCommand \index{interrupt}
13898
13899 \end_inset
13900
13901  (2)
13902 \newline
13903 {
13904 \newline
13905 \InsetSpace ~
13906 \InsetSpace ~
13907 \InsetSpace ~
13908 \InsetSpace ~
13909 ...
13910 \newline
13911 \InsetSpace ~
13912 \InsetSpace ~
13913 \InsetSpace ~
13914 \InsetSpace ~
13915 set_error(10);
13916 \newline
13917 \InsetSpace ~
13918 \InsetSpace ~
13919 \InsetSpace ~
13920 \InsetSpace ~
13921 ...
13922  
13923 \newline
13924 }
13925 \end_layout
13926
13927 \begin_layout Standard
13928 In the above example the parameter 
13929 \emph on
13930 errcd
13931 \emph default
13932  for the function 
13933 \emph on
13934 set_error
13935 \emph default
13936  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13937 nooverlay was
13938  not present, this could cause unpredictable runtime behavior when called
13939  from an interrupt service routine.
13940  The #pragma\InsetSpace ~
13941 nooverlay ensures that the parameters and local variables for
13942  the function are NOT overlayed.
13943 \begin_inset VSpace bigskip
13944 \end_inset
13945
13946
13947 \end_layout
13948
13949 \begin_layout Section
13950 Interrupt Service Routines
13951 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13952
13953 \end_inset
13954
13955
13956 \end_layout
13957
13958 \begin_layout Subsection
13959 General Information
13960 \end_layout
13961
13962 \begin_layout Standard
13963 SDCC allows 
13964 \emph on
13965 i
13966 \emph default
13967 nterrupt 
13968 \emph on
13969 s
13970 \emph default
13971 ervice 
13972 \emph on
13973 r
13974 \emph default
13975 outines to be coded in C, with some extended keywords.
13976 \end_layout
13977
13978 \begin_layout Verse
13979
13980 \family typewriter
13981 void timer_isr (void) __interrupt (1) __using (1) 
13982 \newline
13983
13984 \newline
13985 \InsetSpace ~
13986 \InsetSpace ~
13987 \InsetSpace ~
13988 \InsetSpace ~
13989 ...
13990  
13991 \newline
13992 }
13993 \end_layout
13994
13995 \begin_layout Standard
13996 The optional number following the 
13997 \emph on
13998 interrupt
13999 \begin_inset LatexCommand \index{interrupt}
14000
14001 \end_inset
14002
14003
14004 \begin_inset LatexCommand \index{\_\_interrupt}
14005
14006 \end_inset
14007
14008
14009 \emph default
14010  keyword is the interrupt number this routine will service.
14011  When present, the compiler will insert a call to this routine in the interrupt
14012  vector table
14013 \begin_inset LatexCommand \index{interrupt vector table}
14014
14015 \end_inset
14016
14017  for the interrupt number specified.
14018  If you have multiple source files in your project, interrupt service routines
14019  can be present in any of them, but a prototype of the isr MUST be present
14020  or included in the file that contains the function 
14021 \emph on
14022 main
14023 \emph default
14024 .
14025  The optional (8051 specific) keyword 
14026 \emph on
14027 using
14028 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14029
14030 \end_inset
14031
14032
14033 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14034
14035 \end_inset
14036
14037
14038 \emph default
14039  can be used to tell the compiler to use the specified register bank when
14040  generating code for this function.
14041  
14042 \newline
14043 Interrupt service routines open the door for some very interesting bugs:
14044 \end_layout
14045
14046 \begin_layout Subsubsection
14047 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
14048
14049 \end_inset
14050
14051 Common interrupt pitfall: variable not declared 
14052 \emph on
14053 volatile
14054 \end_layout
14055
14056 \begin_layout Standard
14057 If an interrupt service routine changes variables which are accessed by
14058  other functions these variables have to be declared 
14059 \emph on
14060 volatile
14061 \emph default
14062
14063 \begin_inset LatexCommand \index{volatile}
14064
14065 \end_inset
14066
14067 .
14068  See 
14069 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
14070
14071 \end_inset
14072
14073  .
14074 \end_layout
14075
14076 \begin_layout Subsubsection
14077 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
14078
14079 \end_inset
14080
14081 Common interrupt pitfall: 
14082 \emph on
14083 non-atomic access
14084 \end_layout
14085
14086 \begin_layout Standard
14087 If the access to these variables is not 
14088 \emph on
14089 atomic
14090 \begin_inset LatexCommand \index{atomic}
14091
14092 \end_inset
14093
14094
14095 \emph default
14096  (i.e.
14097  the processor needs more than one instruction for the access and could
14098  be interrupted while accessing the variable) the interrupt must be disabled
14099  during the access to avoid inconsistent data.
14100  
14101 \newline
14102 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
14103  and should be protected by disabling interrupts.
14104  You're not automatically on the safe side if you use 8 bit variables though.
14105  We need an example here: f.e.
14106  on the 8051 the harmless looking 
14107 \begin_inset Quotes srd
14108 \end_inset
14109
14110
14111 \family typewriter
14112 flags\InsetSpace ~
14113 |=\InsetSpace ~
14114 0x80;
14115 \family default
14116
14117 \begin_inset Quotes sld
14118 \end_inset
14119
14120  is not atomic if 
14121 \family typewriter
14122 flags
14123 \family default
14124  resides in xdata.
14125  Setting 
14126 \begin_inset Quotes srd
14127 \end_inset
14128
14129
14130 \family typewriter
14131 flags\InsetSpace ~
14132 |=\InsetSpace ~
14133 0x40;
14134 \family default
14135
14136 \begin_inset Quotes sld
14137 \end_inset
14138
14139  from within an interrupt routine might get lost if the interrupt occurs
14140  at the wrong time.
14141  
14142 \begin_inset Quotes sld
14143 \end_inset
14144
14145
14146 \family typewriter
14147 counter\InsetSpace ~
14148 +=\InsetSpace ~
14149 8;
14150 \family default
14151
14152 \begin_inset Quotes srd
14153 \end_inset
14154
14155  is not atomic on the 8051 even if 
14156 \family typewriter
14157 counter
14158 \family default
14159  is located in data memory.
14160 \newline
14161 Bugs like these are hard to reproduce and can
14162  cause a lot of trouble.
14163  
14164 \end_layout
14165
14166 \begin_layout Subsubsection
14167 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14168
14169 \end_inset
14170
14171 Common interrupt pitfall: 
14172 \emph on
14173 stack overflow
14174 \end_layout
14175
14176 \begin_layout Standard
14177 The return address and the registers used in the interrupt service routine
14178  are saved on the stack
14179 \begin_inset LatexCommand \index{stack}
14180
14181 \end_inset
14182
14183  so there must be sufficient stack space.
14184  If there isn't variables or registers (or even the return address itself)
14185  will be corrupted.
14186  This 
14187 \emph on
14188 stack overflow
14189 \emph default
14190
14191 \begin_inset LatexCommand \index{stack overflow}
14192
14193 \end_inset
14194
14195  is most likely to happen if the interrupt occurs during the 
14196 \begin_inset Quotes sld
14197 \end_inset
14198
14199 deepest
14200 \begin_inset Quotes srd
14201 \end_inset
14202
14203  subroutine when the stack is already in use for f.e.
14204  many return addresses.
14205 \end_layout
14206
14207 \begin_layout Subsubsection
14208 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14209
14210 \end_inset
14211
14212 Common interrupt pitfall: 
14213 \emph on
14214 use of non-reentrant functions
14215 \end_layout
14216
14217 \begin_layout Standard
14218 A special note here, int (16 bit) and long (32 bit) integer division
14219 \begin_inset LatexCommand \index{Division}
14220
14221 \end_inset
14222
14223 , multiplication
14224 \begin_inset LatexCommand \index{Multiplication}
14225
14226 \end_inset
14227
14228  & modulus
14229 \begin_inset LatexCommand \index{Modulus}
14230
14231 \end_inset
14232
14233  and floating-point
14234 \begin_inset LatexCommand \index{Floating point support}
14235
14236 \end_inset
14237
14238  operations are implemented using external support routines.
14239  If an interrupt service routine needs to do any of these operations then
14240  the support routines (as mentioned in a following section) will have to
14241  be recompiled using the
14242 \emph on
14243  -
14244 \begin_inset ERT
14245 status collapsed
14246
14247 \begin_layout Standard
14248
14249
14250 \backslash
14251 /
14252 \end_layout
14253
14254 \end_inset
14255
14256 -stack-auto
14257 \begin_inset LatexCommand \index{-\/-stack-auto}
14258
14259 \end_inset
14260
14261
14262 \emph default
14263  option and the source file will need to be compiled using the 
14264 \emph on
14265 -
14266 \begin_inset ERT
14267 status collapsed
14268
14269 \begin_layout Standard
14270
14271
14272 \backslash
14273 /
14274 \end_layout
14275
14276 \end_inset
14277
14278 -int-long-reent
14279 \emph default
14280
14281 \begin_inset LatexCommand \index{-\/-int-long-reent}
14282
14283 \end_inset
14284
14285  compiler option.
14286  
14287 \newline
14288 Note, the type promotion
14289 \begin_inset LatexCommand \index{type promotion}
14290
14291 \end_inset
14292
14293  required by ANSI C can cause 16 bit routines to be used
14294 \begin_inset Marginal
14295 status collapsed
14296
14297 \begin_layout Standard
14298
14299 \series bold
14300 \InsetSpace ~
14301 !
14302 \end_layout
14303
14304 \end_inset
14305
14306  without the programmer being aware of it.
14307  See f.e.
14308  the cast 
14309 \family typewriter
14310 (unsigned char)(tail-1)
14311 \family default
14312  within the if clause in section 
14313 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14314
14315 \end_inset
14316
14317 .
14318 \end_layout
14319
14320 \begin_layout Standard
14321 Calling other functions from an interrupt service routine is not recommended,
14322  avoid it if possible.
14323  Note that when some function is called from an interrupt service routine
14324  it should be preceded by a #pragma\InsetSpace ~
14325 nooverlay
14326 \begin_inset LatexCommand \index{\#pragma nooverlay}
14327
14328 \end_inset
14329
14330  if it is not reentrant.
14331  Furthermore nonreentrant functions should not be called from the main program
14332  while the interrupt service routine might be active.
14333  They also must not be called from low priority interrupt service routines
14334  while a high priority interrupt service routine might be active.
14335  You could use semaphores or make the function
14336 \emph on
14337  critical
14338 \emph default
14339  if all parameters are passed in registers.
14340 \newline
14341  Also see section 
14342 \begin_inset LatexCommand \ref{sub:Overlaying}
14343
14344 \end_inset
14345
14346 \InsetSpace ~
14347 about Overlaying and section 
14348 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14349
14350 \end_inset
14351
14352 \InsetSpace ~
14353 about Functions using private register banks.
14354 \begin_inset VSpace bigskip
14355 \end_inset
14356
14357
14358 \end_layout
14359
14360 \begin_layout Subsection
14361 MCS51/DS390 Interrupt Service Routines
14362 \end_layout
14363
14364 \begin_layout Standard
14365 Interrupt
14366 \begin_inset LatexCommand \index{interrupt}
14367
14368 \end_inset
14369
14370  numbers and the corresponding address & descriptions for the Standard 8051/8052
14371  are listed below.
14372  SDCC will automatically adjust the 
14373 \begin_inset LatexCommand \index{interrupt vector table}
14374
14375 \end_inset
14376
14377  to the maximum interrupt number specified.
14378 \newline
14379
14380 \end_layout
14381
14382 \begin_layout Standard
14383 \align center
14384 \begin_inset Tabular
14385 <lyxtabular version="3" rows="9" columns="3">
14386 <features>
14387 <column alignment="center" valignment="top" leftline="true" width="0in">
14388 <column alignment="left" valignment="top" leftline="true" width="0in">
14389 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14390 <row topline="true" bottomline="true">
14391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14392 \begin_inset Text
14393
14394 \begin_layout Standard
14395 Interrupt #
14396 \end_layout
14397
14398 \end_inset
14399 </cell>
14400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14401 \begin_inset Text
14402
14403 \begin_layout Standard
14404 Description
14405 \end_layout
14406
14407 \end_inset
14408 </cell>
14409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14410 \begin_inset Text
14411
14412 \begin_layout Standard
14413 Vector Address
14414 \end_layout
14415
14416 \end_inset
14417 </cell>
14418 </row>
14419 <row topline="true">
14420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14421 \begin_inset Text
14422
14423 \begin_layout Standard
14424 0
14425 \end_layout
14426
14427 \end_inset
14428 </cell>
14429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14430 \begin_inset Text
14431
14432 \begin_layout Standard
14433 External 0
14434 \end_layout
14435
14436 \end_inset
14437 </cell>
14438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14439 \begin_inset Text
14440
14441 \begin_layout Standard
14442 0x0003
14443 \end_layout
14444
14445 \end_inset
14446 </cell>
14447 </row>
14448 <row topline="true">
14449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14450 \begin_inset Text
14451
14452 \begin_layout Standard
14453 1
14454 \end_layout
14455
14456 \end_inset
14457 </cell>
14458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14459 \begin_inset Text
14460
14461 \begin_layout Standard
14462 Timer 0
14463 \end_layout
14464
14465 \end_inset
14466 </cell>
14467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14468 \begin_inset Text
14469
14470 \begin_layout Standard
14471 0x000b
14472 \end_layout
14473
14474 \end_inset
14475 </cell>
14476 </row>
14477 <row topline="true">
14478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14479 \begin_inset Text
14480
14481 \begin_layout Standard
14482 2
14483 \end_layout
14484
14485 \end_inset
14486 </cell>
14487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14488 \begin_inset Text
14489
14490 \begin_layout Standard
14491 External 1
14492 \end_layout
14493
14494 \end_inset
14495 </cell>
14496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14497 \begin_inset Text
14498
14499 \begin_layout Standard
14500 0x0013
14501 \end_layout
14502
14503 \end_inset
14504 </cell>
14505 </row>
14506 <row topline="true">
14507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14508 \begin_inset Text
14509
14510 \begin_layout Standard
14511 3
14512 \end_layout
14513
14514 \end_inset
14515 </cell>
14516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14517 \begin_inset Text
14518
14519 \begin_layout Standard
14520 Timer 1
14521 \end_layout
14522
14523 \end_inset
14524 </cell>
14525 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14526 \begin_inset Text
14527
14528 \begin_layout Standard
14529 0x001b
14530 \end_layout
14531
14532 \end_inset
14533 </cell>
14534 </row>
14535 <row topline="true">
14536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14537 \begin_inset Text
14538
14539 \begin_layout Standard
14540 4
14541 \end_layout
14542
14543 \end_inset
14544 </cell>
14545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14546 \begin_inset Text
14547
14548 \begin_layout Standard
14549 Serial
14550 \end_layout
14551
14552 \end_inset
14553 </cell>
14554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14555 \begin_inset Text
14556
14557 \begin_layout Standard
14558 0x0023
14559 \end_layout
14560
14561 \end_inset
14562 </cell>
14563 </row>
14564 <row topline="true">
14565 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14566 \begin_inset Text
14567
14568 \begin_layout Standard
14569 5
14570 \end_layout
14571
14572 \end_inset
14573 </cell>
14574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14575 \begin_inset Text
14576
14577 \begin_layout Standard
14578 Timer 2 (8052)
14579 \end_layout
14580
14581 \end_inset
14582 </cell>
14583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14584 \begin_inset Text
14585
14586 \begin_layout Standard
14587 0x002b
14588 \end_layout
14589
14590 \end_inset
14591 </cell>
14592 </row>
14593 <row topline="true">
14594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14595 \begin_inset Text
14596
14597 \begin_layout Standard
14598 ...
14599 \end_layout
14600
14601 \end_inset
14602 </cell>
14603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14604 \begin_inset Text
14605
14606 \begin_layout Standard
14607
14608 \end_layout
14609
14610 \end_inset
14611 </cell>
14612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14613 \begin_inset Text
14614
14615 \begin_layout Standard
14616 ...
14617 \end_layout
14618
14619 \end_inset
14620 </cell>
14621 </row>
14622 <row topline="true" bottomline="true">
14623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14624 \begin_inset Text
14625
14626 \begin_layout Standard
14627 n
14628 \end_layout
14629
14630 \end_inset
14631 </cell>
14632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14633 \begin_inset Text
14634
14635 \begin_layout Standard
14636
14637 \end_layout
14638
14639 \end_inset
14640 </cell>
14641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14642 \begin_inset Text
14643
14644 \begin_layout Standard
14645 0x0003 + 8*n
14646 \end_layout
14647
14648 \end_inset
14649 </cell>
14650 </row>
14651 </lyxtabular>
14652
14653 \end_inset
14654
14655
14656 \newline
14657
14658 \end_layout
14659
14660 \begin_layout Standard
14661 If the interrupt service routine is defined without 
14662 \emph on
14663 using
14664 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14665
14666 \end_inset
14667
14668
14669 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14670
14671 \end_inset
14672
14673
14674 \emph default
14675  a register bank or with register bank 0 (
14676 \emph on
14677 using
14678 \emph default
14679  0), the compiler will save the registers used by itself on the stack upon
14680  entry and restore them at exit, however if such an interrupt service routine
14681  calls another function then the entire register bank will be saved on the
14682  stack.
14683  This scheme may be advantageous for small interrupt service routines which
14684  have low register usage.
14685 \end_layout
14686
14687 \begin_layout Standard
14688 If the interrupt service routine is defined to be using a specific register
14689  bank then only 
14690 \emph on
14691 a, b, dptr
14692 \emph default
14693  & psw are saved and restored, if such an interrupt service routine calls
14694  another function (using another register bank) then the entire register
14695  bank of the called function will be saved on the stack
14696 \begin_inset LatexCommand \index{stack}
14697
14698 \end_inset
14699
14700 .
14701  This scheme is recommended for larger interrupt service routines.
14702 \begin_inset VSpace bigskip
14703 \end_inset
14704
14705
14706 \end_layout
14707
14708 \begin_layout Subsection
14709 HC08
14710 \begin_inset LatexCommand \index{HC08}
14711
14712 \end_inset
14713
14714  Interrupt Service Routines
14715 \end_layout
14716
14717 \begin_layout Standard
14718 Since the number of interrupts
14719 \begin_inset LatexCommand \index{HC08!interrupt}
14720
14721 \end_inset
14722
14723  available is chip specific and the interrupt vector table always ends at
14724  the last byte of memory, the interrupt numbers corresponds to the interrupt
14725  vectors in reverse order of address.
14726  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14727  2 will use the interrupt vector at 0xfffa, and so on.
14728  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14729  this way; instead see section 
14730 \begin_inset LatexCommand \ref{sub:Startup-Code}
14731
14732 \end_inset
14733
14734  for details on customizing startup.
14735 \begin_inset VSpace bigskip
14736 \end_inset
14737
14738
14739 \end_layout
14740
14741 \begin_layout Subsection
14742 Z80 Interrupt Service Routines
14743 \end_layout
14744
14745 \begin_layout Standard
14746 The Z80
14747 \begin_inset LatexCommand \index{Z80}
14748
14749 \end_inset
14750
14751  uses several different methods for determining the correct interrupt
14752 \begin_inset LatexCommand \index{Z80!interrupt}
14753
14754 \end_inset
14755
14756  vector depending on the hardware implementation.
14757  Therefore, SDCC ignores the optional interrupt number and does not attempt
14758  to generate an interrupt vector table.
14759 \end_layout
14760
14761 \begin_layout Standard
14762 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14763  instruction to return from the interrupt.
14764  To write an interrupt handler for the non-maskable interrupt, which needs
14765  a RETN instruction instead, add the 
14766 \emph on
14767 critical
14768 \emph default
14769  keyword:
14770 \end_layout
14771
14772 \begin_layout Verse
14773
14774 \family typewriter
14775 void nmi_isr (void) critical interrupt
14776 \newline
14777
14778 \newline
14779 \InsetSpace ~
14780 \InsetSpace ~
14781 \InsetSpace ~
14782 \InsetSpace ~
14783 ...
14784  
14785 \newline
14786 }
14787 \end_layout
14788
14789 \begin_layout Standard
14790 However if you need to create a non-interruptable interrupt service routine
14791  you would also require the 
14792 \emph on
14793 critical
14794 \emph default
14795  keyword.
14796  To distinguish between this and an nmi_isr you must provide an interrupt
14797  number.
14798 \begin_inset VSpace bigskip
14799 \end_inset
14800
14801
14802 \end_layout
14803
14804 \begin_layout Section
14805 Enabling and Disabling Interrupts
14806 \end_layout
14807
14808 \begin_layout Subsection
14809 Critical Functions and Critical Statements
14810 \end_layout
14811
14812 \begin_layout Standard
14813 A special keyword may be associated with a block or a function declaring
14814  it as 
14815 \emph on
14816 critical
14817 \emph default
14818 .
14819  SDCC will generate code to disable all interrupts
14820 \begin_inset LatexCommand \index{interrupt}
14821
14822 \end_inset
14823
14824  upon entry to a critical function and restore the interrupt enable to the
14825  previous state before returning.
14826  Nesting critical functions will need one additional byte on the stack
14827 \begin_inset LatexCommand \index{stack}
14828
14829 \end_inset
14830
14831  for each call.
14832 \end_layout
14833
14834 \begin_layout Verse
14835
14836 \family typewriter
14837 int foo () __critical
14838 \begin_inset LatexCommand \index{critical}
14839
14840 \end_inset
14841
14842
14843 \begin_inset LatexCommand \index{\_\_critical}
14844
14845 \end_inset
14846
14847  
14848 \newline
14849
14850 \newline
14851 \InsetSpace ~
14852 \InsetSpace ~
14853 \InsetSpace ~
14854 \InsetSpace ~
14855 ...
14856  
14857 \newline
14858 \InsetSpace ~
14859 \InsetSpace ~
14860 \InsetSpace ~
14861 \InsetSpace ~
14862 ...
14863  
14864 \newline
14865 }
14866 \end_layout
14867
14868 \begin_layout Standard
14869 The critical attribute maybe used with other attributes like 
14870 \emph on
14871 reentrant.
14872 \emph default
14873
14874 \newline
14875 The keyword 
14876 \emph on
14877 critical
14878 \emph default
14879  may also be used to disable interrupts more locally:
14880 \end_layout
14881
14882 \begin_layout Verse
14883
14884 \family typewriter
14885 __critical{ i++; }
14886 \end_layout
14887
14888 \begin_layout Standard
14889 More than one statement could have been included in the block.
14890 \end_layout
14891
14892 \begin_layout Subsection
14893 Enabling and Disabling Interrupts directly
14894 \end_layout
14895
14896 \begin_layout Standard
14897 Interrupts
14898 \begin_inset LatexCommand \index{interrupt}
14899
14900 \end_inset
14901
14902  can also be disabled and enabled directly (8051):
14903 \end_layout
14904
14905 \begin_layout Verse
14906
14907 \family typewriter
14908 EA = 0;\InsetSpace ~
14909 \InsetSpace ~
14910 \InsetSpace ~
14911 \InsetSpace ~
14912 \InsetSpace ~
14913 \InsetSpace ~
14914 \InsetSpace ~
14915 \InsetSpace ~
14916 \InsetSpace ~
14917 \InsetSpace ~
14918 \InsetSpace ~
14919 \InsetSpace ~
14920 or:\InsetSpace ~
14921 \InsetSpace ~
14922 \InsetSpace ~
14923 \InsetSpace ~
14924 \InsetSpace ~
14925 \InsetSpace ~
14926 \InsetSpace ~
14927 \InsetSpace ~
14928 \InsetSpace ~
14929 \InsetSpace ~
14930 \InsetSpace ~
14931 EA_SAVE = EA;
14932 \end_layout
14933
14934 \begin_layout Verse
14935
14936 \family typewriter
14937 ...\InsetSpace ~
14938 \InsetSpace ~
14939 \InsetSpace ~
14940 \InsetSpace ~
14941 \InsetSpace ~
14942 \InsetSpace ~
14943 \InsetSpace ~
14944 \InsetSpace ~
14945 \InsetSpace ~
14946 \InsetSpace ~
14947 \InsetSpace ~
14948 \InsetSpace ~
14949 \InsetSpace ~
14950 \InsetSpace ~
14951 \InsetSpace ~
14952 \InsetSpace ~
14953 \InsetSpace ~
14954 \InsetSpace ~
14955 \InsetSpace ~
14956 \InsetSpace ~
14957 \InsetSpace ~
14958 \InsetSpace ~
14959 \InsetSpace ~
14960 \InsetSpace ~
14961 \InsetSpace ~
14962 \InsetSpace ~
14963 \InsetSpace ~
14964 \InsetSpace ~
14965 \InsetSpace ~
14966 \InsetSpace ~
14967 EA = 0;
14968 \end_layout
14969
14970 \begin_layout Verse
14971
14972 \family typewriter
14973 EA = 1;\InsetSpace ~
14974 \InsetSpace ~
14975 \InsetSpace ~
14976 \InsetSpace ~
14977 \InsetSpace ~
14978 \InsetSpace ~
14979 \InsetSpace ~
14980 \InsetSpace ~
14981 \InsetSpace ~
14982 \InsetSpace ~
14983 \InsetSpace ~
14984 \InsetSpace ~
14985 \InsetSpace ~
14986 \InsetSpace ~
14987 \InsetSpace ~
14988 \InsetSpace ~
14989 \InsetSpace ~
14990 \InsetSpace ~
14991 \InsetSpace ~
14992 \InsetSpace ~
14993 \InsetSpace ~
14994 \InsetSpace ~
14995 \InsetSpace ~
14996 \InsetSpace ~
14997 \InsetSpace ~
14998 \InsetSpace ~
14999 ...
15000 \end_layout
15001
15002 \begin_layout Verse
15003
15004 \family typewriter
15005 \InsetSpace ~
15006 \InsetSpace ~
15007 \InsetSpace ~
15008 \InsetSpace ~
15009 \InsetSpace ~
15010 \InsetSpace ~
15011 \InsetSpace ~
15012 \InsetSpace ~
15013 \InsetSpace ~
15014 \InsetSpace ~
15015 \InsetSpace ~
15016 \InsetSpace ~
15017 \InsetSpace ~
15018 \InsetSpace ~
15019 \InsetSpace ~
15020 \InsetSpace ~
15021 \InsetSpace ~
15022 \InsetSpace ~
15023 \InsetSpace ~
15024 \InsetSpace ~
15025 \InsetSpace ~
15026 \InsetSpace ~
15027 \InsetSpace ~
15028 \InsetSpace ~
15029 \InsetSpace ~
15030 \InsetSpace ~
15031 \InsetSpace ~
15032 \InsetSpace ~
15033 \InsetSpace ~
15034 \InsetSpace ~
15035 \InsetSpace ~
15036 \InsetSpace ~
15037 \InsetSpace ~
15038 EA = EA_SAVE;
15039 \end_layout
15040
15041 \begin_layout Standard
15042 On other architectures which have seperate opcodes for enabling and disabling
15043  interrupts you might want to make use of defines with inline assembly
15044 \begin_inset LatexCommand \index{Assembler routines}
15045
15046 \end_inset
15047
15048  (HC08
15049 \begin_inset LatexCommand \index{HC08!interrupt}
15050
15051 \end_inset
15052
15053 ):
15054 \end_layout
15055
15056 \begin_layout Verse
15057
15058 \family typewriter
15059 #define CLI _asm
15060 \begin_inset LatexCommand \index{\_asm}
15061
15062 \end_inset
15063
15064 \InsetSpace ~
15065 \InsetSpace ~
15066 cli\InsetSpace ~
15067 \InsetSpace ~
15068 _endasm
15069 \begin_inset LatexCommand \index{\_endasm}
15070
15071 \end_inset
15072
15073
15074 \end_layout
15075
15076 \begin_layout Verse
15077
15078 \family typewriter
15079 #define SEI _asm\InsetSpace ~
15080 \InsetSpace ~
15081 sei\InsetSpace ~
15082 \InsetSpace ~
15083 _endasm; 
15084 \end_layout
15085
15086 \begin_layout Verse
15087
15088 \family typewriter
15089 ...
15090 \end_layout
15091
15092 \begin_layout Standard
15093 Note: it is sometimes sufficient to disable only a specific interrupt source
15094  like f.e.
15095  a timer or serial interrupt by manipulating an 
15096 \emph on
15097 interrupt mask
15098 \begin_inset LatexCommand \index{interrupt mask}
15099
15100 \end_inset
15101
15102
15103 \emph default
15104  register.
15105  
15106 \end_layout
15107
15108 \begin_layout Standard
15109 Usually the time during which interrupts are disabled should be kept as
15110  short as possible.
15111  This minimizes both 
15112 \emph on
15113 interrupt latency
15114 \emph default
15115
15116 \begin_inset LatexCommand \index{interrupt latency}
15117
15118 \end_inset
15119
15120  (the time between the occurrence of the interrupt and the execution of
15121  the first code in the interrupt routine) and 
15122 \emph on
15123 interrupt jitter
15124 \emph default
15125
15126 \begin_inset LatexCommand \index{interrupt jitter}
15127
15128 \end_inset
15129
15130  (the difference between the shortest and the longest interrupt latency).
15131  These really are something different, f.e.
15132  a serial interrupt has to be served before its buffer overruns so it cares
15133  for the maximum interrupt latency, whereas it does not care about jitter.
15134  On a loudspeaker driven via a digital to analog converter which is fed
15135  by an interrupt a latency of a few milliseconds might be tolerable, whereas
15136  a much smaller jitter will be very audible.
15137 \end_layout
15138
15139 \begin_layout Standard
15140 You can reenable interrupts within an interrupt routine and on some architecture
15141 s you can make use of two (or more) levels of 
15142 \emph on
15143 interrupt priorities
15144 \emph default
15145
15146 \begin_inset LatexCommand \index{interrupt priority}
15147
15148 \end_inset
15149
15150 .
15151  On some architectures which don't support interrupt priorities these can
15152  be implemented by manipulating the interrupt mask and reenabling interrupts
15153  within the interrupt routine.
15154  Check there is sufficient space on the stack
15155 \begin_inset LatexCommand \index{stack}
15156
15157 \end_inset
15158
15159  and don't add complexity unless you have to.
15160  
15161 \end_layout
15162
15163 \begin_layout Subsection
15164 Semaphore
15165 \begin_inset LatexCommand \index{semaphore}
15166
15167 \end_inset
15168
15169  locking (mcs51/ds390)
15170 \end_layout
15171
15172 \begin_layout Standard
15173 Some architectures (mcs51/ds390) have an atomic
15174 \begin_inset LatexCommand \index{atomic}
15175
15176 \end_inset
15177
15178  bit test and
15179 \emph on
15180  
15181 \emph default
15182 clear
15183 \emph on
15184  
15185 \emph default
15186 instruction.
15187  These type of instructions are typically used in preemptive multitasking
15188  systems, where a routine f.e.
15189  claims the use of a data structure ('acquires a lock
15190 \begin_inset LatexCommand \index{lock}
15191
15192 \end_inset
15193
15194  on it'), makes some modifications and then releases the lock when the data
15195  structure is consistent again.
15196  The instruction may also be used if interrupt and non-interrupt code have
15197  to compete for a resource.
15198  With the atomic bit test and clear instruction interrupts
15199 \begin_inset LatexCommand \index{interrupt}
15200
15201 \end_inset
15202
15203  don't have to be disabled for the locking operation.
15204  
15205 \end_layout
15206
15207 \begin_layout Standard
15208 SDCC generates this instruction if the source follows this pattern:
15209 \end_layout
15210
15211 \begin_layout Verse
15212
15213 \family typewriter
15214 volatile
15215 \begin_inset LatexCommand \index{volatile}
15216
15217 \end_inset
15218
15219  bit resource_is_free; 
15220 \newline
15221
15222 \newline
15223 if (resource_is_free) 
15224 \newline
15225 \InsetSpace ~
15226 \InsetSpace ~
15227
15228 \newline
15229 \InsetSpace ~
15230 \InsetSpace ~
15231 \InsetSpace ~
15232 \InsetSpace ~
15233 resource_is_free=0; 
15234 \newline
15235 \InsetSpace ~
15236 \InsetSpace ~
15237 \InsetSpace ~
15238 \InsetSpace ~
15239 ...
15240  
15241 \newline
15242 \InsetSpace ~
15243 \InsetSpace ~
15244 \InsetSpace ~
15245 \InsetSpace ~
15246 resource_is_free=1;
15247 \newline
15248 \InsetSpace ~
15249 \InsetSpace ~
15250
15251 \end_layout
15252
15253 \begin_layout Standard
15254 Note, mcs51 and ds390 support only an atomic
15255 \begin_inset LatexCommand \index{atomic}
15256
15257 \end_inset
15258
15259  bit test and 
15260 \emph on
15261 clear
15262 \emph default
15263  instruction (as opposed to atomic bit test and 
15264 \emph on
15265 set).
15266 \end_layout
15267
15268 \begin_layout Section
15269 Functions using private register banks
15270 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15271
15272 \end_inset
15273
15274  (mcs51/ds390)
15275 \end_layout
15276
15277 \begin_layout Standard
15278 Some architectures have support for quickly changing register sets.
15279  SDCC supports this feature with the 
15280 \emph on
15281 using
15282 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15283
15284 \end_inset
15285
15286
15287 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15288
15289 \end_inset
15290
15291
15292 \emph default
15293  attribute (which tells the compiler to use a register bank
15294 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15295
15296 \end_inset
15297
15298  other than the default bank zero).
15299  It should only be applied to 
15300 \emph on
15301 interrupt
15302 \begin_inset LatexCommand \index{interrupt}
15303
15304 \end_inset
15305
15306
15307 \emph default
15308  functions (see footnote below).
15309  This will in most circumstances make the generated ISR code more efficient
15310  since it will not have to save registers on the stack.
15311 \end_layout
15312
15313 \begin_layout Standard
15314 The 
15315 \emph on
15316 using
15317 \emph default
15318  attribute will have no effect on the generated code for a 
15319 \emph on
15320 non-interrupt
15321 \emph default
15322  function (but may occasionally be useful anyway
15323 \begin_inset Foot
15324 status open
15325
15326 \begin_layout Standard
15327 possible exception: if a function is called ONLY from 'interrupt' functions
15328  using a particular bank, it can be declared with the same 'using' attribute
15329  as the calling 'interrupt' functions.
15330  For instance, if you have several ISRs using bank one, and all of them
15331  call memcpy(), it might make sense to create a specialized version of memcpy()
15332  'using 1', since this would prevent the ISR from having to save bank zero
15333  to the stack on entry and switch to bank zero before calling the function
15334 \end_layout
15335
15336 \end_inset
15337
15338 ).
15339 \newline
15340
15341 \emph on
15342 (pending: Note, nowadays the 
15343 \emph default
15344 using
15345 \emph on
15346  attribute has an effect on
15347 \emph default
15348  
15349 \emph on
15350 the generated code for a 
15351 \emph default
15352 non-interrupt
15353 \emph on
15354  function
15355 \emph default
15356 .
15357 \emph on
15358 )
15359 \end_layout
15360
15361 \begin_layout Standard
15362 An 
15363 \emph on
15364 interrupt
15365 \emph default
15366  function using a non-zero bank will assume that it can trash that register
15367  bank, and will not save it.
15368  Since high-priority interrupts
15369 \begin_inset LatexCommand \index{interrupts}
15370
15371 \end_inset
15372
15373
15374 \begin_inset LatexCommand \index{interrupt priority}
15375
15376 \end_inset
15377
15378  can interrupt low-priority ones on the 8051 and friends, this means that
15379  if a high-priority ISR 
15380 \emph on
15381 using
15382 \emph default
15383  a particular bank occurs while processing a low-priority ISR 
15384 \emph on
15385 using
15386 \emph default
15387  the same bank, terrible and bad things can happen.
15388  To prevent this, no single register bank should be 
15389 \emph on
15390 used
15391 \emph default
15392  by both a high priority and a low priority ISR.
15393  This is probably most easily done by having all high priority ISRs use
15394  one bank and all low priority ISRs use another.
15395  If you have an ISR which can change priority at runtime, you're on your
15396  own: I suggest using the default bank zero and taking the small performance
15397  hit.
15398 \end_layout
15399
15400 \begin_layout Standard
15401 It is most efficient if your ISR calls no other functions.
15402  If your ISR must call other functions, it is most efficient if those functions
15403  use the same bank as the ISR (see note 1 below); the next best is if the
15404  called functions use bank zero.
15405  It is very inefficient to call a function using a different, non-zero bank
15406  from an ISR.
15407  
15408 \begin_inset VSpace bigskip
15409 \end_inset
15410
15411
15412 \end_layout
15413
15414 \begin_layout Section
15415 Startup Code
15416 \begin_inset LatexCommand \label{sub:Startup-Code}
15417
15418 \end_inset
15419
15420
15421 \begin_inset LatexCommand \index{Startup code}
15422
15423 \end_inset
15424
15425
15426 \end_layout
15427
15428 \begin_layout Subsection
15429 MCS51/DS390 Startup Code
15430 \end_layout
15431
15432 \begin_layout Standard
15433 The compiler triggers the linker to link certain initialization modules
15434  from the runtime library
15435 \begin_inset LatexCommand \index{Runtime library}
15436
15437 \end_inset
15438
15439  called crt<something>.
15440  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15441  GSINIT5) is not linked unless the -
15442 \series bold
15443
15444 \begin_inset ERT
15445 status open
15446
15447 \begin_layout Standard
15448
15449
15450 \backslash
15451 /
15452 \end_layout
15453
15454 \end_inset
15455
15456
15457 \series default
15458 -xstack option is used.
15459  These modules are highly entangled by the use of special segments/areas,
15460  but a common layout is shown below:
15461 \end_layout
15462
15463 \begin_layout Verse
15464
15465 \family typewriter
15466 \series bold
15467 \size footnotesize
15468 (main.asm)
15469 \end_layout
15470
15471 \begin_layout Verse
15472
15473 \family typewriter
15474 \size footnotesize
15475 \InsetSpace ~
15476 \InsetSpace ~
15477 \InsetSpace ~
15478 \InsetSpace ~
15479 \InsetSpace ~
15480 \InsetSpace ~
15481 \InsetSpace ~
15482 \InsetSpace ~
15483 .area HOME (CODE)
15484 \newline
15485 __interrupt_vect:
15486 \newline
15487 \InsetSpace ~
15488 \InsetSpace ~
15489 \InsetSpace ~
15490 \InsetSpace ~
15491 \InsetSpace ~
15492 \InsetSpace ~
15493 \InsetSpace ~
15494 \InsetSpace ~
15495 ljmp __sdcc_gsinit_startup
15496 \end_layout
15497
15498 \begin_layout Verse
15499
15500 \family typewriter
15501 \series bold
15502 \size footnotesize
15503 (crtstart.asm)
15504 \end_layout
15505
15506 \begin_layout Verse
15507
15508 \family typewriter
15509 \size footnotesize
15510 \InsetSpace ~
15511 \InsetSpace ~
15512 \InsetSpace ~
15513 \InsetSpace ~
15514 \InsetSpace ~
15515 \InsetSpace ~
15516 \InsetSpace ~
15517 \InsetSpace ~
15518 .area GSINIT0 (CODE)
15519 \newline
15520 __sdcc_gsinit_startup::
15521 \newline
15522 \InsetSpace ~
15523 \InsetSpace ~
15524 \InsetSpace ~
15525 \InsetSpace ~
15526 \InsetSpace ~
15527 \InsetSpace ~
15528 \InsetSpace ~
15529 \InsetSpace ~
15530 mov sp,#__start__stack - 1
15531 \end_layout
15532
15533 \begin_layout Verse
15534
15535 \family typewriter
15536 \series bold
15537 \size footnotesize
15538 (crtxstack.asm)
15539 \end_layout
15540
15541 \begin_layout Verse
15542
15543 \family typewriter
15544 \size footnotesize
15545 \InsetSpace ~
15546 \InsetSpace ~
15547 \InsetSpace ~
15548 \InsetSpace ~
15549 \InsetSpace ~
15550 \InsetSpace ~
15551 \InsetSpace ~
15552 \InsetSpace ~
15553 .area GSINIT1 (CODE)
15554 \newline
15555 __sdcc_init_xstack::
15556 \newline
15557 ; Need to initialize in GSINIT1 in
15558  case the user's __sdcc_external_startup uses the xstack.
15559 \newline
15560 \InsetSpace ~
15561 \InsetSpace ~
15562 \InsetSpace ~
15563 \InsetSpace ~
15564 \InsetSpace ~
15565 \InsetSpace ~
15566 \InsetSpace ~
15567 \InsetSpace ~
15568 mov __XPAGE,#(__start__x
15569 stack >> 8)
15570 \newline
15571 \InsetSpace ~
15572 \InsetSpace ~
15573 \InsetSpace ~
15574 \InsetSpace ~
15575 \InsetSpace ~
15576 \InsetSpace ~
15577 \InsetSpace ~
15578 \InsetSpace ~
15579 mov _spx,#__start__xstack
15580 \end_layout
15581
15582 \begin_layout Verse
15583
15584 \family typewriter
15585 \series bold
15586 \size footnotesize
15587 (crtstart.asm)
15588 \end_layout
15589
15590 \begin_layout Verse
15591
15592 \family typewriter
15593 \size footnotesize
15594 \InsetSpace ~
15595 \InsetSpace ~
15596 \InsetSpace ~
15597 \InsetSpace ~
15598 \InsetSpace ~
15599 \InsetSpace ~
15600 \InsetSpace ~
15601 \InsetSpace ~
15602 .area GSINIT2 (CODE)
15603 \newline
15604 \InsetSpace ~
15605 \InsetSpace ~
15606 \InsetSpace ~
15607 \InsetSpace ~
15608 \InsetSpace ~
15609 \InsetSpace ~
15610 \InsetSpace ~
15611 \InsetSpace ~
15612 lcall __sdcc_external_startup
15613 \newline
15614 \InsetSpace ~
15615 \InsetSpace ~
15616 \InsetSpace ~
15617 \InsetSpace ~
15618 \InsetSpace ~
15619 \InsetSpace ~
15620 \InsetSpace ~
15621 \InsetSpace ~
15622 mov a,dpl
15623 \newline
15624 \InsetSpace ~
15625 \InsetSpace ~
15626 \InsetSpace ~
15627 \InsetSpace ~
15628 \InsetSpace ~
15629 \InsetSpace ~
15630 \InsetSpace ~
15631 \InsetSpace ~
15632 jz __sdcc_init_data
15633 \newline
15634 \InsetSpace ~
15635 \InsetSpace ~
15636 \InsetSpace ~
15637 \InsetSpace ~
15638 \InsetSpace ~
15639 \InsetSpace ~
15640 \InsetSpace ~
15641 \InsetSpace ~
15642 ljmp
15643  __sdcc_program_startup
15644 \newline
15645 __sdcc_init_data:
15646 \end_layout
15647
15648 \begin_layout Verse
15649
15650 \family typewriter
15651 \series bold
15652 \size footnotesize
15653 (crtxinit.asm)
15654 \end_layout
15655
15656 \begin_layout Verse
15657
15658 \family typewriter
15659 \size footnotesize
15660 \InsetSpace ~
15661 \InsetSpace ~
15662 \InsetSpace ~
15663 \InsetSpace ~
15664 \InsetSpace ~
15665 \InsetSpace ~
15666 \InsetSpace ~
15667 \InsetSpace ~
15668 .area GSINIT3 (CODE)
15669 \newline
15670 __mcs51_genXINIT::
15671 \newline
15672 \InsetSpace ~
15673 \InsetSpace ~
15674 \InsetSpace ~
15675 \InsetSpace ~
15676 \InsetSpace ~
15677 \InsetSpace ~
15678 \InsetSpace ~
15679 \InsetSpace ~
15680 mov r1,#l_XINIT
15681 \newline
15682 \InsetSpace ~
15683 \InsetSpace ~
15684 \InsetSpace ~
15685 \InsetSpace ~
15686 \InsetSpace ~
15687 \InsetSpace ~
15688 \InsetSpace ~
15689 \InsetSpace ~
15690 mov a,r1
15691 \newline
15692 \InsetSpace ~
15693 \InsetSpace ~
15694 \InsetSpace ~
15695 \InsetSpace ~
15696 \InsetSpace ~
15697 \InsetSpace ~
15698 \InsetSpace ~
15699 \InsetSpace ~
15700 orl a,#(l_XINIT
15701  >> 8)
15702 \newline
15703 \InsetSpace ~
15704 \InsetSpace ~
15705 \InsetSpace ~
15706 \InsetSpace ~
15707 \InsetSpace ~
15708 \InsetSpace ~
15709 \InsetSpace ~
15710 \InsetSpace ~
15711 jz 00003$
15712 \newline
15713 \InsetSpace ~
15714 \InsetSpace ~
15715 \InsetSpace ~
15716 \InsetSpace ~
15717 \InsetSpace ~
15718 \InsetSpace ~
15719 \InsetSpace ~
15720 \InsetSpace ~
15721 mov r2,#((l_XINIT+255) >> 8)
15722 \newline
15723 \InsetSpace ~
15724 \InsetSpace ~
15725 \InsetSpace ~
15726 \InsetSpace ~
15727 \InsetSpace ~
15728 \InsetSpace ~
15729 \InsetSpace ~
15730 \InsetSpace ~
15731 mov dptr,#s_XINIT
15732 \newline
15733 \InsetSpace ~
15734 \InsetSpace ~
15735 \InsetSpace ~
15736 \InsetSpace ~
15737 \InsetSpace ~
15738 \InsetSpace ~
15739 \InsetSpace ~
15740 \InsetSpace ~
15741 mov r0,#s_XISEG
15742 \newline
15743 \InsetSpace ~
15744 \InsetSpace ~
15745 \InsetSpace ~
15746 \InsetSpace ~
15747 \InsetSpace ~
15748 \InsetSpace ~
15749 \InsetSpace ~
15750 \InsetSpace ~
15751 mov
15752  __XPAGE,#(s_XISEG >> 8)
15753 \newline
15754 00001$:\InsetSpace ~
15755 clr a
15756 \newline
15757 \InsetSpace ~
15758 \InsetSpace ~
15759 \InsetSpace ~
15760 \InsetSpace ~
15761 \InsetSpace ~
15762 \InsetSpace ~
15763 \InsetSpace ~
15764 \InsetSpace ~
15765 movc a,@a+dptr
15766 \newline
15767 \InsetSpace ~
15768 \InsetSpace ~
15769 \InsetSpace ~
15770 \InsetSpace ~
15771 \InsetSpace ~
15772 \InsetSpace ~
15773 \InsetSpace ~
15774 \InsetSpace ~
15775 movx @r0,a
15776 \newline
15777 \InsetSpace ~
15778 \InsetSpace ~
15779 \InsetSpace ~
15780 \InsetSpace ~
15781 \InsetSpace ~
15782 \InsetSpace ~
15783 \InsetSpace ~
15784 \InsetSpace ~
15785 inc dptr
15786 \newline
15787 \InsetSpace ~
15788 \InsetSpace ~
15789 \InsetSpace ~
15790 \InsetSpace ~
15791 \InsetSpace ~
15792 \InsetSpace ~
15793 \InsetSpace ~
15794 \InsetSpace ~
15795 inc
15796  r0
15797 \newline
15798 \InsetSpace ~
15799 \InsetSpace ~
15800 \InsetSpace ~
15801 \InsetSpace ~
15802 \InsetSpace ~
15803 \InsetSpace ~
15804 \InsetSpace ~
15805 \InsetSpace ~
15806 cjne r0,#0,00002$
15807 \newline
15808 \InsetSpace ~
15809 \InsetSpace ~
15810 \InsetSpace ~
15811 \InsetSpace ~
15812 \InsetSpace ~
15813 \InsetSpace ~
15814 \InsetSpace ~
15815 \InsetSpace ~
15816 inc __XPAGE
15817 \newline
15818 00002$:\InsetSpace ~
15819 djnz r1,00001$
15820 \newline
15821 \InsetSpace ~
15822 \InsetSpace ~
15823 \InsetSpace ~
15824 \InsetSpace ~
15825 \InsetSpace ~
15826 \InsetSpace ~
15827 \InsetSpace ~
15828 \InsetSpace ~
15829 djnz r2,00001$
15830 \newline
15831 \InsetSpace ~
15832 \InsetSpace ~
15833 \InsetSpace ~
15834 \InsetSpace ~
15835 \InsetSpace ~
15836 \InsetSpace ~
15837 \InsetSpace ~
15838 \InsetSpace ~
15839 mov __XPAGE,#0
15840 xFF
15841 \newline
15842 00003$:
15843 \end_layout
15844
15845 \begin_layout Verse
15846
15847 \family typewriter
15848 \series bold
15849 \size footnotesize
15850 (crtclear.asm)
15851 \end_layout
15852
15853 \begin_layout Verse
15854
15855 \family typewriter
15856 \size footnotesize
15857 \InsetSpace ~
15858 \InsetSpace ~
15859 \InsetSpace ~
15860 \InsetSpace ~
15861 \InsetSpace ~
15862 \InsetSpace ~
15863 \InsetSpace ~
15864 \InsetSpace ~
15865 .area GSINIT4 (CODE)
15866 \newline
15867 __mcs51_genRAMCLEAR::
15868 \newline
15869 \InsetSpace ~
15870 \InsetSpace ~
15871 \InsetSpace ~
15872 \InsetSpace ~
15873 \InsetSpace ~
15874 \InsetSpace ~
15875 \InsetSpace ~
15876 \InsetSpace ~
15877 clr a
15878 \newline
15879 \InsetSpace ~
15880 \InsetSpace ~
15881 \InsetSpace ~
15882 \InsetSpace ~
15883 \InsetSpace ~
15884 \InsetSpace ~
15885 \InsetSpace ~
15886 \InsetSpace ~
15887 mov r0,#(l_IRAM-1)
15888 \newline
15889 00004$:\InsetSpace ~
15890 mov
15891  @r0,a
15892 \newline
15893 \InsetSpace ~
15894 \InsetSpace ~
15895 \InsetSpace ~
15896 \InsetSpace ~
15897 \InsetSpace ~
15898 \InsetSpace ~
15899 \InsetSpace ~
15900 \InsetSpace ~
15901 djnz r0,00004$
15902 \newline
15903 ; _mcs51_genRAMCLEAR() end
15904 \end_layout
15905
15906 \begin_layout Verse
15907
15908 \family typewriter
15909 \series bold
15910 \size footnotesize
15911 (crtxclear.asm)
15912 \end_layout
15913
15914 \begin_layout Verse
15915
15916 \family typewriter
15917 \size footnotesize
15918 \InsetSpace ~
15919 \InsetSpace ~
15920 \InsetSpace ~
15921 \InsetSpace ~
15922 \InsetSpace ~
15923 \InsetSpace ~
15924 \InsetSpace ~
15925 \InsetSpace ~
15926 .area GSINIT4 (CODE)
15927 \newline
15928 __mcs51_genXRAMCLEAR::
15929 \newline
15930 \InsetSpace ~
15931 \InsetSpace ~
15932 \InsetSpace ~
15933 \InsetSpace ~
15934 \InsetSpace ~
15935 \InsetSpace ~
15936 \InsetSpace ~
15937 \InsetSpace ~
15938 mov r0,#l_PSEG
15939 \newline
15940 \InsetSpace ~
15941 \InsetSpace ~
15942 \InsetSpace ~
15943 \InsetSpace ~
15944 \InsetSpace ~
15945 \InsetSpace ~
15946 \InsetSpace ~
15947 \InsetSpace ~
15948 mov a,r0
15949 \newline
15950 \InsetSpace ~
15951 \InsetSpace ~
15952 \InsetSpace ~
15953 \InsetSpace ~
15954 \InsetSpace ~
15955 \InsetSpace ~
15956 \InsetSpace ~
15957 \InsetSpace ~
15958 orl a,#(l_PSEG
15959  >> 8)
15960 \newline
15961 \InsetSpace ~
15962 \InsetSpace ~
15963 \InsetSpace ~
15964 \InsetSpace ~
15965 \InsetSpace ~
15966 \InsetSpace ~
15967 \InsetSpace ~
15968 \InsetSpace ~
15969 jz 00006$
15970 \newline
15971 \InsetSpace ~
15972 \InsetSpace ~
15973 \InsetSpace ~
15974 \InsetSpace ~
15975 \InsetSpace ~
15976 \InsetSpace ~
15977 \InsetSpace ~
15978 \InsetSpace ~
15979 mov r1,#s_PSEG
15980 \newline
15981 \InsetSpace ~
15982 \InsetSpace ~
15983 \InsetSpace ~
15984 \InsetSpace ~
15985 \InsetSpace ~
15986 \InsetSpace ~
15987 \InsetSpace ~
15988 \InsetSpace ~
15989 mov __XPAGE,#(s_PSEG >> 8)
15990 \newline
15991 \InsetSpace ~
15992 \InsetSpace ~
15993 \InsetSpace ~
15994 \InsetSpace ~
15995 \InsetSpace ~
15996 \InsetSpace ~
15997 \InsetSpace ~
15998 \InsetSpace ~
15999 clr a
16000 \newline
16001 00005$:\InsetSpace ~
16002 movx
16003  @r1,a
16004 \newline
16005 \InsetSpace ~
16006 \InsetSpace ~
16007 \InsetSpace ~
16008 \InsetSpace ~
16009 \InsetSpace ~
16010 \InsetSpace ~
16011 \InsetSpace ~
16012 \InsetSpace ~
16013 inc r1
16014 \newline
16015 \InsetSpace ~
16016 \InsetSpace ~
16017 \InsetSpace ~
16018 \InsetSpace ~
16019 \InsetSpace ~
16020 \InsetSpace ~
16021 \InsetSpace ~
16022 \InsetSpace ~
16023 djnz r0,00005$
16024 \newline
16025 00006$:
16026 \newline
16027 \InsetSpace ~
16028 \InsetSpace ~
16029 \InsetSpace ~
16030 \InsetSpace ~
16031 \InsetSpace ~
16032 \InsetSpace ~
16033 \InsetSpace ~
16034 \InsetSpace ~
16035 mov r0,#l_XSEG
16036 \newline
16037 \InsetSpace ~
16038 \InsetSpace ~
16039 \InsetSpace ~
16040 \InsetSpace ~
16041 \InsetSpace ~
16042 \InsetSpace ~
16043 \InsetSpace ~
16044 \InsetSpace ~
16045 mov a,r0
16046 \newline
16047 \InsetSpace ~
16048 \InsetSpace ~
16049 \InsetSpace ~
16050 \InsetSpace ~
16051 \InsetSpace ~
16052 \InsetSpace ~
16053 \InsetSpace ~
16054 \InsetSpace ~
16055 orl a,#(l_XSEG >>
16056  8)
16057 \newline
16058 \InsetSpace ~
16059 \InsetSpace ~
16060 \InsetSpace ~
16061 \InsetSpace ~
16062 \InsetSpace ~
16063 \InsetSpace ~
16064 \InsetSpace ~
16065 \InsetSpace ~
16066 jz 00008$
16067 \newline
16068 \InsetSpace ~
16069 \InsetSpace ~
16070 \InsetSpace ~
16071 \InsetSpace ~
16072 \InsetSpace ~
16073 \InsetSpace ~
16074 \InsetSpace ~
16075 \InsetSpace ~
16076 mov r1,#((l_XSEG + 255) >> 8)
16077 \newline
16078 \InsetSpace ~
16079 \InsetSpace ~
16080 \InsetSpace ~
16081 \InsetSpace ~
16082 \InsetSpace ~
16083 \InsetSpace ~
16084 \InsetSpace ~
16085 \InsetSpace ~
16086 mov dptr,#s_XSEG
16087 \newline
16088 \InsetSpace ~
16089 \InsetSpace ~
16090 \InsetSpace ~
16091 \InsetSpace ~
16092 \InsetSpace ~
16093 \InsetSpace ~
16094 \InsetSpace ~
16095 \InsetSpace ~
16096 clr a
16097 \newline
16098 00007$:\InsetSpace ~
16099 movx
16100  @dptr,a
16101 \newline
16102 \InsetSpace ~
16103 \InsetSpace ~
16104 \InsetSpace ~
16105 \InsetSpace ~
16106 \InsetSpace ~
16107 \InsetSpace ~
16108 \InsetSpace ~
16109 \InsetSpace ~
16110 inc dptr
16111 \newline
16112 \InsetSpace ~
16113 \InsetSpace ~
16114 \InsetSpace ~
16115 \InsetSpace ~
16116 \InsetSpace ~
16117 \InsetSpace ~
16118 \InsetSpace ~
16119 \InsetSpace ~
16120 djnz r0,00007$
16121 \newline
16122 \InsetSpace ~
16123 \InsetSpace ~
16124 \InsetSpace ~
16125 \InsetSpace ~
16126 \InsetSpace ~
16127 \InsetSpace ~
16128 \InsetSpace ~
16129 \InsetSpace ~
16130 djnz r1,00007$
16131 \newline
16132 00008$:
16133 \end_layout
16134
16135 \begin_layout Verse
16136
16137 \family typewriter
16138 \series bold
16139 \size footnotesize
16140 (crtxstack.asm)
16141 \end_layout
16142
16143 \begin_layout Verse
16144
16145 \family typewriter
16146 \size footnotesize
16147 \InsetSpace ~
16148 \InsetSpace ~
16149 \InsetSpace ~
16150 \InsetSpace ~
16151 \InsetSpace ~
16152 \InsetSpace ~
16153 \InsetSpace ~
16154 \InsetSpace ~
16155 .area GSINIT5 (CODE)
16156 \newline
16157 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
16158  modifies __XPAGE
16159 \newline
16160 ; and __mcs51_genRAMCLEAR modifies _spx.
16161 \newline
16162 \InsetSpace ~
16163 \InsetSpace ~
16164 \InsetSpace ~
16165 \InsetSpace ~
16166 \InsetSpace ~
16167 \InsetSpace ~
16168 \InsetSpace ~
16169 \InsetSpace ~
16170 mov __XPAGE,#(__start__x
16171 stack >> 8)
16172 \newline
16173 \InsetSpace ~
16174 \InsetSpace ~
16175 \InsetSpace ~
16176 \InsetSpace ~
16177 \InsetSpace ~
16178 \InsetSpace ~
16179 \InsetSpace ~
16180 \InsetSpace ~
16181 mov _spx,#__start__xstack
16182 \end_layout
16183
16184 \begin_layout Verse
16185
16186 \family typewriter
16187 \series bold
16188 \size footnotesize
16189 (application modules)
16190 \end_layout
16191
16192 \begin_layout Verse
16193
16194 \family typewriter
16195 \size footnotesize
16196 \InsetSpace ~
16197 \InsetSpace ~
16198 \InsetSpace ~
16199 \InsetSpace ~
16200 \InsetSpace ~
16201 \InsetSpace ~
16202 \InsetSpace ~
16203 \InsetSpace ~
16204 .area GSINIT (CODE)
16205 \end_layout
16206
16207 \begin_layout Verse
16208
16209 \family typewriter
16210 \series bold
16211 \size footnotesize
16212 (main.asm)
16213 \end_layout
16214
16215 \begin_layout Verse
16216
16217 \family typewriter
16218 \size footnotesize
16219 \InsetSpace ~
16220 \InsetSpace ~
16221 \InsetSpace ~
16222 \InsetSpace ~
16223 \InsetSpace ~
16224 \InsetSpace ~
16225 \InsetSpace ~
16226 \InsetSpace ~
16227 .area GSFINAL (CODE)
16228 \newline
16229 \InsetSpace ~
16230 \InsetSpace ~
16231 \InsetSpace ~
16232 \InsetSpace ~
16233 \InsetSpace ~
16234 \InsetSpace ~
16235 \InsetSpace ~
16236 \InsetSpace ~
16237 ljmp __sdcc_program_startup
16238 \newline
16239 ;---------------------------------
16240 -----------------------
16241 \newline
16242 ; Home
16243 \newline
16244 ;--------------------------------------------------
16245 ------
16246 \newline
16247 \InsetSpace ~
16248 \InsetSpace ~
16249 \InsetSpace ~
16250 \InsetSpace ~
16251 \InsetSpace ~
16252 \InsetSpace ~
16253 \InsetSpace ~
16254 \InsetSpace ~
16255 .area HOME (CODE)
16256 \newline
16257 \InsetSpace ~
16258 \InsetSpace ~
16259 \InsetSpace ~
16260 \InsetSpace ~
16261 \InsetSpace ~
16262 \InsetSpace ~
16263 \InsetSpace ~
16264 \InsetSpace ~
16265 .area CSEG (CODE)
16266 \newline
16267 __sdcc_program_startup:
16268 \newline
16269 \InsetSpace ~
16270 \InsetSpace ~
16271 \InsetSpace ~
16272 \InsetSpace ~
16273 \InsetSpace ~
16274 \InsetSpace ~
16275 \InsetSpace ~
16276 \InsetSpace ~
16277 lcall _main
16278 \newline
16279 ;
16280  return from main will lock up
16281 \newline
16282 \InsetSpace ~
16283 \InsetSpace ~
16284 \InsetSpace ~
16285 \InsetSpace ~
16286 \InsetSpace ~
16287 \InsetSpace ~
16288 \InsetSpace ~
16289 \InsetSpace ~
16290 sjmp .
16291 \end_layout
16292
16293 \begin_layout Standard
16294 One of these modules (crtstart.asm) contains a call to the C routine 
16295 \emph on
16296 _sdcc_external_startup()
16297 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16298
16299 \end_inset
16300
16301
16302 \series bold
16303 \emph default
16304  
16305 \series default
16306 at the start of the CODE area.
16307  This routine is also in the runtime library
16308 \begin_inset LatexCommand \index{Runtime library}
16309
16310 \end_inset
16311
16312  and returns 0 by default.
16313  If this routine returns a non-zero value, the static & global variable
16314  initialization will be skipped and the function main will be invoked.
16315  Otherwise static & global variables will be initialized before the function
16316  main is invoked.
16317  You could add an 
16318 \emph on
16319 _sdcc_external_startup()
16320 \emph default
16321  routine to your program to override the default if you need to setup hardware
16322  or perform some other critical operation prior to static & global variable
16323  initialization
16324 \begin_inset LatexCommand \index{Variable initialization}
16325
16326 \end_inset
16327
16328 .
16329  On some mcs51 variants xdata
16330 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16331
16332 \end_inset
16333
16334  memory has to be explicitly enabled before it can be accessed or if the
16335  watchdog
16336 \begin_inset LatexCommand \index{watchdog}
16337
16338 \end_inset
16339
16340  needs to be disabled, this is the place to do it.
16341  The startup code clears all internal data memory, 256 bytes by default,
16342  but from 0 to n-1 if 
16343 \emph on
16344 -
16345 \begin_inset ERT
16346 status collapsed
16347
16348 \begin_layout Standard
16349
16350
16351 \backslash
16352 /
16353 \end_layout
16354
16355 \end_inset
16356
16357 -iram-size
16358 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16359
16360 \end_inset
16361
16362 n
16363 \emph default
16364  is used.
16365  (recommended for Chipcon CC1010).
16366 \end_layout
16367
16368 \begin_layout Standard
16369 See also the compiler options 
16370 \emph on
16371 -
16372 \begin_inset ERT
16373 status collapsed
16374
16375 \begin_layout Standard
16376
16377
16378 \backslash
16379 /
16380 \end_layout
16381
16382 \end_inset
16383
16384 -no-xinit
16385 \emph default
16386 -
16387 \emph on
16388 opt
16389 \emph default
16390
16391 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16392
16393 \end_inset
16394
16395
16396 \emph on
16397 -
16398 \begin_inset ERT
16399 status collapsed
16400
16401 \begin_layout Standard
16402
16403
16404 \backslash
16405 /
16406 \end_layout
16407
16408 \end_inset
16409
16410 -main-return
16411 \emph default
16412
16413 \begin_inset LatexCommand \index{-\/-main-return}
16414
16415 \end_inset
16416
16417  and section 
16418 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16419
16420 \end_inset
16421
16422  about MCS51-variants.
16423 \newline
16424
16425 \end_layout
16426
16427 \begin_layout Standard
16428 While these initialization modules are meant as generic startup code there
16429  might be the need for customization.
16430  Let's assume the return value of 
16431 \emph on
16432 _sdcc_external_startup()
16433 \emph default
16434  in 
16435 \emph on
16436 crtstart.asm
16437 \emph default
16438  should not be checked (or 
16439 \emph on
16440 _sdcc_external_startup()
16441 \emph default
16442  should not be called at all).
16443  The recommended way would be to copy 
16444 \emph on
16445 crtstart.asm
16446 \emph default
16447  (f.e.
16448  from 
16449 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm}
16450
16451 \end_inset
16452
16453 ) into the source directory, adapt it there, then assemble it with 
16454 \emph on
16455 asx8051 -plosgff
16456 \begin_inset Foot
16457 status open
16458
16459 \begin_layout Standard
16460 \begin_inset Quotes sld
16461 \end_inset
16462
16463 -plosgff
16464 \begin_inset Quotes srd
16465 \end_inset
16466
16467  are the assembler options used in 
16468 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup }
16469
16470 \end_inset
16471
16472
16473 \end_layout
16474
16475 \end_inset
16476
16477  crtstart.asm
16478 \emph default
16479  and when linking your project explicitely specify 
16480 \emph on
16481 crtstart.rel
16482 \emph default
16483 .
16484  As a bonus a listing of the relocated object file 
16485 \emph on
16486 crtstart.rst
16487 \emph default
16488  is generated.
16489 \end_layout
16490
16491 \begin_layout Standard
16492 \begin_inset VSpace bigskip
16493 \end_inset
16494
16495
16496 \end_layout
16497
16498 \begin_layout Subsection
16499 HC08 Startup Code
16500 \end_layout
16501
16502 \begin_layout Standard
16503 The HC08
16504 \begin_inset LatexCommand \index{HC08}
16505
16506 \end_inset
16507
16508  startup code follows the same scheme as the MCS51 startup code.
16509 \begin_inset VSpace bigskip
16510 \end_inset
16511
16512
16513 \end_layout
16514
16515 \begin_layout Subsection
16516 Z80 Startup Code
16517 \end_layout
16518
16519 \begin_layout Standard
16520 On the Z80
16521 \begin_inset LatexCommand \index{Z80}
16522
16523 \end_inset
16524
16525  the startup code is inserted by linking with crt0.o which is generated from
16526  sdcc/device/lib/z80/crt0.s.
16527  If you need a different startup code you can use the compiler option 
16528 \emph on
16529 -
16530 \series bold
16531 \emph default
16532
16533 \begin_inset ERT
16534 status collapsed
16535
16536 \begin_layout Standard
16537
16538
16539 \backslash
16540 /
16541 \end_layout
16542
16543 \end_inset
16544
16545
16546 \series default
16547 \emph on
16548 -no-std-crt0
16549 \emph default
16550
16551 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16552
16553 \end_inset
16554
16555  and provide your own crt0.o.
16556  
16557 \begin_inset VSpace bigskip
16558 \end_inset
16559
16560
16561 \end_layout
16562
16563 \begin_layout Section
16564 Inline Assembler Code
16565 \begin_inset LatexCommand \index{Assembler routines}
16566
16567 \end_inset
16568
16569
16570 \end_layout
16571
16572 \begin_layout Subsection
16573 A Step by Step Introduction
16574 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16575
16576 \end_inset
16577
16578
16579 \end_layout
16580
16581 \begin_layout Standard
16582 Starting from a small snippet of c-code this example shows for the MCS51
16583  how to use inline assembly, access variables, a function parameter and
16584  an array in xdata memory.
16585  The example uses an MCS51 here but is easily adapted for other architectures.
16586  This is a buffer routine which should be optimized:
16587 \end_layout
16588
16589 \begin_layout Verse
16590
16591 \family typewriter
16592 \size footnotesize
16593 unsigned char __far
16594 \begin_inset LatexCommand \index{far (storage class)}
16595
16596 \end_inset
16597
16598
16599 \begin_inset LatexCommand \index{\_\_far (storage class)}
16600
16601 \end_inset
16602
16603  __at
16604 \begin_inset LatexCommand \index{at}
16605
16606 \end_inset
16607
16608
16609 \begin_inset LatexCommand \index{\_\_at}
16610
16611 \end_inset
16612
16613 (0x7f00) buf[0x100];
16614 \begin_inset LatexCommand \index{Aligned array}
16615
16616 \end_inset
16617
16618
16619 \newline
16620 unsigned char head, tail;\InsetSpace ~
16621 \InsetSpace ~
16622 \InsetSpace ~
16623 \InsetSpace ~
16624 \InsetSpace ~
16625 \InsetSpace ~
16626 \InsetSpace ~
16627 \InsetSpace ~
16628 \InsetSpace ~
16629 \InsetSpace ~
16630 \InsetSpace ~
16631 \InsetSpace ~
16632 \InsetSpace ~
16633 \InsetSpace ~
16634 \InsetSpace ~
16635 \InsetSpace ~
16636 \InsetSpace ~
16637 /* if interrupts
16638 \begin_inset LatexCommand \index{interrupt}
16639
16640 \end_inset
16641
16642  are involved see
16643 \newline
16644 \InsetSpace ~
16645 \InsetSpace ~
16646 \InsetSpace ~
16647 \InsetSpace ~
16648 \InsetSpace ~
16649 \InsetSpace ~
16650 \InsetSpace ~
16651 \InsetSpace ~
16652 \InsetSpace ~
16653 \InsetSpace ~
16654 \InsetSpace ~
16655 \InsetSpace ~
16656 \InsetSpace ~
16657 \InsetSpace ~
16658 \InsetSpace ~
16659 \InsetSpace ~
16660 \InsetSpace ~
16661 \InsetSpace ~
16662 \InsetSpace ~
16663 \InsetSpace ~
16664 \InsetSpace ~
16665 \InsetSpace ~
16666 \InsetSpace ~
16667 \InsetSpace ~
16668 \InsetSpace ~
16669 \InsetSpace ~
16670 \InsetSpace ~
16671 \InsetSpace ~
16672 \InsetSpace ~
16673 \InsetSpace ~
16674 \InsetSpace ~
16675 \InsetSpace ~
16676 \InsetSpace ~
16677 \InsetSpace ~
16678 \InsetSpace ~
16679 \InsetSpace ~
16680 \InsetSpace ~
16681 \InsetSpace ~
16682 \InsetSpace ~
16683 \InsetSpace ~
16684 \InsetSpace ~
16685 \InsetSpace ~
16686 \InsetSpace ~
16687 \InsetSpace ~
16688 \InsetSpace ~
16689 section 
16690 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16691
16692 \end_inset
16693
16694  about
16695 \series bold
16696  volatile
16697 \series default
16698  */
16699 \newline
16700
16701 \newline
16702 void to_buffer( unsigned char c ) 
16703 \newline
16704 {
16705 \newline
16706 \InsetSpace ~
16707 \InsetSpace ~
16708 \InsetSpace ~
16709 \InsetSpace ~
16710 if( head != (unsigned char)(tail-1)
16711  )\InsetSpace ~
16712 /* cast 
16713 \series bold
16714 needed
16715 \series default
16716  to avoid promotion
16717 \begin_inset LatexCommand \index{promotion to signed int}
16718
16719 \end_inset
16720
16721
16722 \begin_inset LatexCommand \index{type promotion}
16723
16724 \end_inset
16725
16726  to integer */
16727 \begin_inset Marginal
16728 status collapsed
16729
16730 \begin_layout Standard
16731
16732 \series bold
16733 \InsetSpace ~
16734 !
16735 \end_layout
16736
16737 \end_inset
16738
16739
16740 \newline
16741 \InsetSpace ~
16742 \InsetSpace ~
16743 \InsetSpace ~
16744 \InsetSpace ~
16745 \InsetSpace ~
16746 \InsetSpace ~
16747 \InsetSpace ~
16748 \InsetSpace ~
16749 buf[ head++ ] = c;\InsetSpace ~
16750 \InsetSpace ~
16751 \InsetSpace ~
16752 \InsetSpace ~
16753 \InsetSpace ~
16754 \InsetSpace ~
16755 \InsetSpace ~
16756 \InsetSpace ~
16757 \InsetSpace ~
16758 \InsetSpace ~
16759 \InsetSpace ~
16760 \InsetSpace ~
16761 \InsetSpace ~
16762 \InsetSpace ~
16763 \InsetSpace ~
16764 \InsetSpace ~
16765 /* access to a 256 byte aligned array */
16766 \newline
16767
16768 \end_layout
16769
16770 \begin_layout Standard
16771 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16772  then a corresponding buffer.asm file is generated.
16773  We define a new function 
16774 \family typewriter
16775 to_buffer_asm()
16776 \family default
16777  in file buffer.c in which we cut and paste the generated code, removing
16778  unwanted comments and some ':'.
16779  Then add 
16780 \begin_inset Quotes sld
16781 \end_inset
16782
16783
16784 \series bold
16785 _asm
16786 \series default
16787
16788 \begin_inset Quotes srd
16789 \end_inset
16790
16791  and 
16792 \begin_inset Quotes sld
16793 \end_inset
16794
16795
16796 \series bold
16797 _endasm;
16798 \series default
16799
16800 \begin_inset Quotes srd
16801 \end_inset
16802
16803
16804 \begin_inset Foot
16805 status open
16806
16807 \begin_layout Standard
16808 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16809  and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16810  has to be used.
16811  The latter is also used in the library functions.
16812 \end_layout
16813
16814 \end_inset
16815
16816  to the beginning and the end of the function body:
16817 \end_layout
16818
16819 \begin_layout Verse
16820
16821 \family typewriter
16822 \size footnotesize
16823 /* With a cut and paste from the .asm file, we have something to start with.
16824 \newline
16825 \InsetSpace ~
16826 \InsetSpace ~
16827 \InsetSpace ~
16828 The
16829  function is not yet OK! (registers aren't saved) */ 
16830 \newline
16831 void to_buffer_asm(
16832  unsigned char c ) 
16833 \newline
16834
16835 \newline
16836 \InsetSpace ~
16837 \InsetSpace ~
16838 \InsetSpace ~
16839 \InsetSpace ~
16840 _asm
16841 \begin_inset LatexCommand \index{\_asm}
16842
16843 \end_inset
16844
16845
16846 \begin_inset LatexCommand \index{\_\_asm}
16847
16848 \end_inset
16849
16850
16851 \newline
16852 \InsetSpace ~
16853 \InsetSpace ~
16854 \InsetSpace ~
16855 \InsetSpace ~
16856 mov\InsetSpace ~
16857 \InsetSpace ~
16858 r2,dpl 
16859 \newline
16860 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16861 /* cast 
16862 \series bold
16863 needed
16864 \series default
16865  to avoid promotion
16866 \begin_inset LatexCommand \index{promotion to signed int}
16867
16868 \end_inset
16869
16870
16871 \begin_inset LatexCommand \index{type promotion}
16872
16873 \end_inset
16874
16875  to integer */
16876 \newline
16877 \InsetSpace ~
16878 \InsetSpace ~
16879 \InsetSpace ~
16880 \InsetSpace ~
16881 mov\InsetSpace ~
16882 \InsetSpace ~
16883 a,_tail 
16884 \newline
16885 \InsetSpace ~
16886 \InsetSpace ~
16887 \InsetSpace ~
16888 \InsetSpace ~
16889 dec\InsetSpace ~
16890 \InsetSpace ~
16891
16892 \newline
16893 \InsetSpace ~
16894 \InsetSpace ~
16895 \InsetSpace ~
16896 \InsetSpace ~
16897 mov\InsetSpace ~
16898 \InsetSpace ~
16899 r3,a 
16900 \newline
16901 \InsetSpace ~
16902 \InsetSpace ~
16903 \InsetSpace ~
16904 \InsetSpace ~
16905 mov\InsetSpace ~
16906 \InsetSpace ~
16907 a,_head 
16908 \newline
16909 \InsetSpace ~
16910 \InsetSpace ~
16911 \InsetSpace ~
16912 \InsetSpace ~
16913 cjne a,ar3,00106$ 
16914 \newline
16915 \InsetSpace ~
16916 \InsetSpace ~
16917 \InsetSpace ~
16918 \InsetSpace ~
16919 ret
16920 \newline
16921 00106$:
16922  
16923 \newline
16924 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16925 \begin_inset LatexCommand \index{Aligned array}
16926
16927 \end_inset
16928
16929
16930 \newline
16931 \InsetSpace ~
16932 \InsetSpace ~
16933 \InsetSpace ~
16934 \InsetSpace ~
16935 mov\InsetSpace ~
16936 \InsetSpace ~
16937 r3,_head 
16938 \newline
16939 \InsetSpace ~
16940 \InsetSpace ~
16941 \InsetSpace ~
16942 \InsetSpace ~
16943 inc\InsetSpace ~
16944 \InsetSpace ~
16945 _head 
16946 \newline
16947 \InsetSpace ~
16948 \InsetSpace ~
16949 \InsetSpace ~
16950 \InsetSpace ~
16951 mov\InsetSpace ~
16952 \InsetSpace ~
16953 dpl,r3 
16954 \newline
16955 \InsetSpace ~
16956 \InsetSpace ~
16957 \InsetSpace ~
16958 \InsetSpace ~
16959 mov\InsetSpace ~
16960 \InsetSpace ~
16961 dph,#(_buf >> 8) 
16962 \newline
16963 \InsetSpace ~
16964 \InsetSpace ~
16965 \InsetSpace ~
16966 \InsetSpace ~
16967 mov\InsetSpace ~
16968 \InsetSpace ~
16969 a,r2 
16970 \newline
16971 \InsetSpace ~
16972 \InsetSpace ~
16973 \InsetSpace ~
16974 \InsetSpace ~
16975 movx @dptr,a
16976  
16977 \newline
16978 00103$: 
16979 \newline
16980 \InsetSpace ~
16981 \InsetSpace ~
16982 \InsetSpace ~
16983 \InsetSpace ~
16984 ret
16985 \newline
16986 \InsetSpace ~
16987 \InsetSpace ~
16988 \InsetSpace ~
16989 \InsetSpace ~
16990 _endasm
16991 \begin_inset LatexCommand \index{\_endasm}
16992
16993 \end_inset
16994
16995
16996 \begin_inset LatexCommand \index{\_\_endasm}
16997
16998 \end_inset
16999
17000 ;
17001 \newline
17002
17003 \end_layout
17004
17005 \begin_layout Standard
17006 The new file buffer.c should compile with only one warning about the unreferenced
17007  function argument 'c'.
17008  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
17009  (1) and finally have:
17010 \end_layout
17011
17012 \begin_layout Verse
17013
17014 \family typewriter
17015 \size footnotesize
17016 unsigned char __far __at(0x7f00) buf[0x100];
17017 \newline
17018 unsigned char head, tail;
17019 \newline
17020 #define
17021  USE_ASSEMBLY (1)
17022 \newline
17023
17024 \newline
17025 #if !USE_ASSEMBLY
17026 \newline
17027
17028 \newline
17029 void to_buffer( unsigned char c )
17030 \newline
17031 {
17032 \newline
17033 \InsetSpace ~
17034 \InsetSpace ~
17035 \InsetSpace ~
17036 \InsetSpace ~
17037 if(
17038  head != (unsigned char)(tail-1) )
17039 \newline
17040 \InsetSpace ~
17041 \InsetSpace ~
17042 \InsetSpace ~
17043 \InsetSpace ~
17044 \InsetSpace ~
17045 \InsetSpace ~
17046 \InsetSpace ~
17047 \InsetSpace ~
17048 buf[ head++ ] = c;
17049 \newline
17050 }
17051 \newline
17052
17053 \newline
17054 #else
17055 \newline
17056
17057 \newline
17058 void to_buffer(
17059  unsigned char c )
17060 \newline
17061 {
17062 \newline
17063 \InsetSpace ~
17064 \InsetSpace ~
17065 \InsetSpace ~
17066 \InsetSpace ~
17067 c; // to avoid warning: unreferenced function argument
17068 \newline
17069 \InsetSpace ~
17070 \InsetSpace ~
17071 \InsetSpace ~
17072 \InsetSpace ~
17073 _asm
17074 \begin_inset LatexCommand \index{\_asm}
17075
17076 \end_inset
17077
17078
17079 \begin_inset LatexCommand \index{\_\_asm}
17080
17081 \end_inset
17082
17083
17084 \newline
17085 \InsetSpace ~
17086 \InsetSpace ~
17087 \InsetSpace ~
17088 \InsetSpace ~
17089 \InsetSpace ~
17090 \InsetSpace ~
17091 \InsetSpace ~
17092 \InsetSpace ~
17093 ; save used registers here.
17094  
17095 \newline
17096 \InsetSpace ~
17097 \InsetSpace ~
17098 \InsetSpace ~
17099 \InsetSpace ~
17100 \InsetSpace ~
17101 \InsetSpace ~
17102 \InsetSpace ~
17103 \InsetSpace ~
17104 ; If we were still using r2,r3 we would have to push them here.
17105  
17106 \newline
17107 ; if( head != (unsigned char)(tail-1) )
17108 \newline
17109 \InsetSpace ~
17110 \InsetSpace ~
17111 \InsetSpace ~
17112 \InsetSpace ~
17113 \InsetSpace ~
17114 \InsetSpace ~
17115 \InsetSpace ~
17116 \InsetSpace ~
17117 mov\InsetSpace ~
17118  a,_tail
17119 \newline
17120 \InsetSpace ~
17121 \InsetSpace ~
17122 \InsetSpace ~
17123 \InsetSpace ~
17124 \InsetSpace ~
17125 \InsetSpace ~
17126 \InsetSpace ~
17127 \InsetSpace ~
17128 dec\InsetSpace ~
17129  a
17130 \newline
17131 \InsetSpace ~
17132 \InsetSpace ~
17133 \InsetSpace ~
17134 \InsetSpace ~
17135 \InsetSpace ~
17136 \InsetSpace ~
17137 \InsetSpace ~
17138 \InsetSpace ~
17139 xrl\InsetSpace ~
17140  a,_head
17141 \newline
17142 \InsetSpace ~
17143 \InsetSpace ~
17144 \InsetSpace ~
17145 \InsetSpace ~
17146 \InsetSpace ~
17147 \InsetSpace ~
17148 \InsetSpace ~
17149 \InsetSpace ~
17150 ; we
17151  could do an ANL a,#0x0f here to use a smaller buffer (see below)
17152 \newline
17153 \InsetSpace ~
17154 \InsetSpace ~
17155 \InsetSpace ~
17156 \InsetSpace ~
17157 \InsetSpace ~
17158 \InsetSpace ~
17159 \InsetSpace ~
17160 \InsetSpace ~
17161 jz\InsetSpace ~
17162 \InsetSpace ~
17163  t_b_end$
17164 \newline
17165 \InsetSpace ~
17166 \InsetSpace ~
17167 \InsetSpace ~
17168 \InsetSpace ~
17169 \InsetSpace ~
17170 \InsetSpace ~
17171 \InsetSpace ~
17172 \InsetSpace ~
17173 ;
17174 \newline
17175 ;
17176  buf[ head++ ] = c;
17177 \newline
17178 \InsetSpace ~
17179 \InsetSpace ~
17180 \InsetSpace ~
17181 \InsetSpace ~
17182 \InsetSpace ~
17183 \InsetSpace ~
17184 \InsetSpace ~
17185 \InsetSpace ~
17186 mov\InsetSpace ~
17187  a,dpl \InsetSpace ~
17188 \InsetSpace ~
17189 \InsetSpace ~
17190 \InsetSpace ~
17191 \InsetSpace ~
17192 \InsetSpace ~
17193 \InsetSpace ~
17194 ; dpl holds lower byte of function argument
17195 \newline
17196 \InsetSpace ~
17197 \InsetSpace ~
17198 \InsetSpace ~
17199 \InsetSpace ~
17200 \InsetSpace ~
17201 \InsetSpace ~
17202 \InsetSpace ~
17203 \InsetSpace ~
17204 mov\InsetSpace ~
17205
17206  dpl,_head \InsetSpace ~
17207 \InsetSpace ~
17208 \InsetSpace ~
17209 ; buf is 0x100 byte aligned so head can be used directly
17210 \newline
17211 \InsetSpace ~
17212 \InsetSpace ~
17213 \InsetSpace ~
17214 \InsetSpace ~
17215 \InsetSpace ~
17216 \InsetSpace ~
17217 \InsetSpace ~
17218 \InsetSpace ~
17219 mov\InsetSpace ~
17220  dph,#(_bu
17221 f>>8)
17222 \newline
17223 \InsetSpace ~
17224 \InsetSpace ~
17225 \InsetSpace ~
17226 \InsetSpace ~
17227 \InsetSpace ~
17228 \InsetSpace ~
17229 \InsetSpace ~
17230 \InsetSpace ~
17231 movx @dptr,a
17232 \newline
17233 \InsetSpace ~
17234 \InsetSpace ~
17235 \InsetSpace ~
17236 \InsetSpace ~
17237 \InsetSpace ~
17238 \InsetSpace ~
17239 \InsetSpace ~
17240 \InsetSpace ~
17241 inc \InsetSpace ~
17242 _head
17243 \newline
17244 \InsetSpace ~
17245 \InsetSpace ~
17246 \InsetSpace ~
17247 \InsetSpace ~
17248 \InsetSpace ~
17249 \InsetSpace ~
17250 \InsetSpace ~
17251 \InsetSpace ~
17252 ; we could do an ANL _head,#0x0f here to use a
17253  smaller buffer (see above)
17254 \newline
17255 t_b_end$:
17256 \newline
17257 \InsetSpace ~
17258 \InsetSpace ~
17259 \InsetSpace ~
17260 \InsetSpace ~
17261 \InsetSpace ~
17262 \InsetSpace ~
17263 \InsetSpace ~
17264 \InsetSpace ~
17265 ; restore used registers here 
17266 \newline
17267 \InsetSpace ~
17268 \InsetSpace ~
17269 \InsetSpace ~
17270 \InsetSpace ~
17271 _endasm
17272 \begin_inset LatexCommand \index{\_endasm}
17273
17274 \end_inset
17275
17276
17277 \begin_inset LatexCommand \index{\_\_endasm}
17278
17279 \end_inset
17280
17281 ;
17282 \newline
17283 }
17284 \newline
17285 #endif
17286 \end_layout
17287
17288 \begin_layout Standard
17289 The inline assembler code can contain any valid code understood by the assembler
17290 , this includes any assembler directives and comment lines.
17291  The assembler does not like some characters like ':' or ''' in comments.
17292  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17293 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17294
17295 \end_inset
17296
17297
17298 \begin_inset LatexCommand \index{Assembler documentation}
17299
17300 \end_inset
17301
17302  or online at 
17303 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17304
17305 \end_inset
17306
17307 \InsetSpace ~
17308 .
17309 \end_layout
17310
17311 \begin_layout Standard
17312 The compiler does not do any validation of the code within the 
17313 \family typewriter
17314 _asm
17315 \begin_inset LatexCommand \index{\_asm}
17316
17317 \end_inset
17318
17319
17320 \begin_inset LatexCommand \index{\_\_asm}
17321
17322 \end_inset
17323
17324  ...
17325  _endasm
17326 \size footnotesize
17327
17328 \begin_inset LatexCommand \index{\_endasm}
17329
17330 \end_inset
17331
17332
17333 \begin_inset LatexCommand \index{\_\_endasm}
17334
17335 \end_inset
17336
17337
17338 \size default
17339 ;
17340 \family default
17341  keyword pair.
17342  Specifically it will not know which registers are used and thus register
17343  pushing/popping
17344 \begin_inset LatexCommand \index{push/pop}
17345
17346 \end_inset
17347
17348  has to be done manually.
17349  
17350 \end_layout
17351
17352 \begin_layout Standard
17353 It is recommended that each assembly instruction (including labels) be placed
17354  in a separate line (as the example shows).
17355  When the -
17356 \begin_inset ERT
17357 status collapsed
17358
17359 \begin_layout Standard
17360
17361
17362 \backslash
17363 /
17364 \end_layout
17365
17366 \end_inset
17367
17368 -
17369 \emph on
17370 peep-asm
17371 \begin_inset LatexCommand \index{-\/-peep-asm}
17372
17373 \end_inset
17374
17375
17376 \emph default
17377  command line option is used, the inline assembler code will be passed through
17378  the peephole optimizer
17379 \begin_inset LatexCommand \index{Peephole optimizer}
17380
17381 \end_inset
17382
17383 .
17384  There are only a few (if any) cases where this option makes sense, it might
17385  cause some unexpected changes in the inline assembler code.
17386  Please go through the peephole optimizer rules defined in file 
17387 \emph on
17388 SDCCpeeph.def
17389 \emph default
17390  before using this option.
17391 \end_layout
17392
17393 \begin_layout Subsection
17394 Naked Functions
17395 \begin_inset LatexCommand \label{sub:Naked-Functions}
17396
17397 \end_inset
17398
17399
17400 \begin_inset LatexCommand \index{Naked functions}
17401
17402 \end_inset
17403
17404
17405 \end_layout
17406
17407 \begin_layout Standard
17408 A special keyword may be associated with a function declaring it as 
17409 \emph on
17410 _naked
17411 \begin_inset LatexCommand \index{\_naked}
17412
17413 \end_inset
17414
17415
17416 \begin_inset LatexCommand \index{\_\_naked}
17417
17418 \end_inset
17419
17420 .
17421  
17422 \emph default
17423 The 
17424 \emph on
17425 _naked
17426 \emph default
17427  function modifier attribute prevents the compiler from generating prologue
17428 \begin_inset LatexCommand \index{function prologue}
17429
17430 \end_inset
17431
17432  and epilogue
17433 \begin_inset LatexCommand \index{function epilogue}
17434
17435 \end_inset
17436
17437  code for that function.
17438  This means that the user is entirely responsible for such things as saving
17439  any registers that may need to be preserved, selecting the proper register
17440  bank, generating the 
17441 \emph on
17442 return
17443 \emph default
17444  instruction at the end, etc.
17445  Practically, this means that the contents of the function must be written
17446  in inline assembler.
17447  This is particularly useful for interrupt functions, which can have a large
17448  (and often unnecessary) prologue/epilogue.
17449  For example, compare the code generated by these two functions:
17450 \end_layout
17451
17452 \begin_layout Verse
17453
17454 \family typewriter
17455 volatile
17456 \begin_inset LatexCommand \index{volatile}
17457
17458 \end_inset
17459
17460  data unsigned char counter;
17461 \newline
17462
17463 \newline
17464 void simpleInterrupt(void) __interrupt
17465 \begin_inset LatexCommand \index{interrupt}
17466
17467 \end_inset
17468
17469
17470 \begin_inset LatexCommand \index{\_\_interrupt}
17471
17472 \end_inset
17473
17474  (1)
17475 \newline
17476 {
17477 \newline
17478 \InsetSpace ~
17479 \InsetSpace ~
17480 \InsetSpace ~
17481 \InsetSpace ~
17482 counter++;
17483 \newline
17484 }
17485 \newline
17486
17487 \newline
17488 void nakedInterrupt(void) __interrupt (2) __naked
17489 \newline
17490 {
17491 \newline
17492 \InsetSpace ~
17493 \InsetSpace ~
17494 \InsetSpace ~
17495 \InsetSpace ~
17496 _asm
17497 \begin_inset LatexCommand \index{\_asm}
17498
17499 \end_inset
17500
17501
17502 \begin_inset LatexCommand \index{\_\_asm}
17503
17504 \end_inset
17505
17506
17507 \newline
17508 \InsetSpace ~
17509 \InsetSpace ~
17510 \InsetSpace ~
17511 \InsetSpace ~
17512 \InsetSpace ~
17513 \InsetSpace ~
17514 inc\InsetSpace ~
17515 \InsetSpace ~
17516 \InsetSpace ~
17517 \InsetSpace ~
17518 \InsetSpace ~
17519 _counter ; does not change flags, no need to save psw
17520 \newline
17521 \InsetSpace ~
17522 \InsetSpace ~
17523 \InsetSpace ~
17524 \InsetSpace ~
17525 \InsetSpace ~
17526 \InsetSpace ~
17527 reti\InsetSpace ~
17528 \InsetSpace ~
17529 \InsetSpace ~
17530 \InsetSpace ~
17531 ; MUST explicitly
17532  include ret or reti in _naked function.
17533 \newline
17534 \InsetSpace ~
17535 \InsetSpace ~
17536 \InsetSpace ~
17537 \InsetSpace ~
17538 _endasm
17539 \begin_inset LatexCommand \index{\_endasm}
17540
17541 \end_inset
17542
17543
17544 \begin_inset LatexCommand \index{\_\_endasm}
17545
17546 \end_inset
17547
17548 ;
17549 \newline
17550 }
17551 \end_layout
17552
17553 \begin_layout Standard
17554 For an 8051 target, the generated simpleInterrupt looks like:
17555 \end_layout
17556
17557 \begin_layout Verse
17558
17559 \family typewriter
17560 Note, this is an 
17561 \emph on
17562 outdated
17563 \emph default
17564  example, recent versions of SDCC generate
17565 \newline
17566 the 
17567 \emph on
17568 same
17569 \emph default
17570  code for simpleInterrupt() and nakedInterrupt()!
17571 \newline
17572
17573 \newline
17574 _simpleInterrupt:
17575 \newline
17576 \InsetSpace ~
17577 \InsetSpace ~
17578 \InsetSpace ~
17579 \InsetSpace ~
17580 push\InsetSpace ~
17581 \InsetSpace ~
17582 \InsetSpace ~
17583 \InsetSpace ~
17584 acc
17585 \newline
17586 \InsetSpace ~
17587 \InsetSpace ~
17588 \InsetSpace ~
17589 \InsetSpace ~
17590 push\InsetSpace ~
17591 \InsetSpace ~
17592 \InsetSpace ~
17593 \InsetSpace ~
17594 b
17595 \newline
17596 \InsetSpace ~
17597 \InsetSpace ~
17598 \InsetSpace ~
17599 \InsetSpace ~
17600 pu
17601 sh\InsetSpace ~
17602 \InsetSpace ~
17603 \InsetSpace ~
17604 \InsetSpace ~
17605 dpl
17606 \newline
17607 \InsetSpace ~
17608 \InsetSpace ~
17609 \InsetSpace ~
17610 \InsetSpace ~
17611 push\InsetSpace ~
17612 \InsetSpace ~
17613 \InsetSpace ~
17614 \InsetSpace ~
17615 dph
17616 \newline
17617 \InsetSpace ~
17618 \InsetSpace ~
17619 \InsetSpace ~
17620 \InsetSpace ~
17621 push\InsetSpace ~
17622 \InsetSpace ~
17623 \InsetSpace ~
17624 \InsetSpace ~
17625 psw
17626 \newline
17627 \InsetSpace ~
17628 \InsetSpace ~
17629 \InsetSpace ~
17630 \InsetSpace ~
17631 mov\InsetSpace ~
17632 \InsetSpace ~
17633 \InsetSpace ~
17634 \InsetSpace ~
17635 \InsetSpace ~
17636 psw,#0x00
17637 \newline
17638 \InsetSpace ~
17639 \InsetSpace ~
17640 \InsetSpace ~
17641 \InsetSpace ~
17642 inc\InsetSpace ~
17643 \InsetSpace ~
17644 \InsetSpace ~
17645 \InsetSpace ~
17646 \InsetSpace ~
17647 _counter
17648 \newline
17649 \InsetSpace ~
17650 \InsetSpace ~
17651 \InsetSpace ~
17652 \InsetSpace ~
17653 pop\InsetSpace ~
17654 \InsetSpace ~
17655 \InsetSpace ~
17656 \InsetSpace ~
17657 \InsetSpace ~
17658 psw
17659 \newline
17660 \InsetSpace ~
17661 \InsetSpace ~
17662 \InsetSpace ~
17663 \InsetSpace ~
17664 pop\InsetSpace ~
17665 \InsetSpace ~
17666 \InsetSpace ~
17667 \InsetSpace ~
17668 \InsetSpace ~
17669 dph
17670 \newline
17671 \InsetSpace ~
17672 \InsetSpace ~
17673 \InsetSpace ~
17674 \InsetSpace ~
17675 pop\InsetSpace ~
17676 \InsetSpace ~
17677 \InsetSpace ~
17678 \InsetSpace ~
17679 \InsetSpace ~
17680 dpl
17681 \newline
17682 \InsetSpace ~
17683 \InsetSpace ~
17684 \InsetSpace ~
17685 \InsetSpace ~
17686 pop\InsetSpace ~
17687 \InsetSpace ~
17688 \InsetSpace ~
17689 \InsetSpace ~
17690 \InsetSpace ~
17691 b
17692 \newline
17693 \InsetSpace ~
17694 \InsetSpace ~
17695 \InsetSpace ~
17696 \InsetSpace ~
17697 pop\InsetSpace ~
17698 \InsetSpace ~
17699 \InsetSpace ~
17700 \InsetSpace ~
17701 \InsetSpace ~
17702 acc
17703 \newline
17704 \InsetSpace ~
17705 \InsetSpace ~
17706 \InsetSpace ~
17707 \InsetSpace ~
17708 reti
17709 \end_layout
17710
17711 \begin_layout Standard
17712 whereas nakedInterrupt looks like:
17713 \end_layout
17714
17715 \begin_layout Verse
17716
17717 \family typewriter
17718 _nakedInterrupt:
17719 \newline
17720 \InsetSpace ~
17721 \InsetSpace ~
17722 \InsetSpace ~
17723 \InsetSpace ~
17724 inc\InsetSpace ~
17725 \InsetSpace ~
17726 \InsetSpace ~
17727 \InsetSpace ~
17728 _counter ; does not change flags, no need to save psw
17729 \newline
17730 \InsetSpace ~
17731 \InsetSpace ~
17732 \InsetSpace ~
17733 \InsetSpace ~
17734 reti\InsetSpace ~
17735 \InsetSpace ~
17736 \InsetSpace ~
17737 \InsetSpace ~
17738 \InsetSpace ~
17739 \InsetSpace ~
17740 \InsetSpace ~
17741 \InsetSpace ~
17742 \InsetSpace ~
17743 \InsetSpace ~
17744 \InsetSpace ~
17745 \InsetSpace ~
17746 ;
17747  MUST explicitly include ret or reti in _naked function
17748 \end_layout
17749
17750 \begin_layout Standard
17751 The related directive #pragma exclude
17752 \begin_inset LatexCommand \index{\#pragma exclude}
17753
17754 \end_inset
17755
17756  allows a more fine grained control over pushing & popping
17757 \begin_inset LatexCommand \index{push/pop}
17758
17759 \end_inset
17760
17761  the registers.
17762 \end_layout
17763
17764 \begin_layout Standard
17765 While there is nothing preventing you from writing C code inside a 
17766 \family typewriter
17767 _naked
17768 \family default
17769  function, there are many ways to shoot yourself in the foot doing this,
17770  and it is recommended that you stick to inline assembler.
17771 \end_layout
17772
17773 \begin_layout Subsection
17774 Use of Labels within Inline Assembler
17775 \end_layout
17776
17777 \begin_layout Standard
17778 SDCC allows the use of in-line assembler with a few restrictions regarding
17779  labels.
17780  All labels defined within inline assembler code have to be of the form
17781  
17782 \emph on
17783 nnnnn$
17784 \emph default
17785  where nnnnn is a number less than 100 (which implies a limit of utmost
17786  100 inline assembler labels 
17787 \emph on
17788 per function
17789 \emph default
17790 \noun on
17791 )
17792 \noun default
17793 .
17794 \begin_inset Foot
17795 status open
17796
17797 \begin_layout Standard
17798 This is a slightly more stringent rule than absolutely necessary, but stays
17799  always on the safe side.
17800  Labels in the form of nnnnn$ are local labels in the assembler, locality
17801  of which is confined within two labels of the standard form.
17802  The compiler uses the same form for labels within a function (but starting
17803  from nnnnn=00100); and places always a standard label at the beginning
17804  of a function, thus limiting the locality of labels within the scope of
17805  the function.
17806  So, if the inline assembler part would be embedded into C-code, an improperly
17807  placed non-local label in the assembler would break up the reference space
17808  for labels created by the compiler for the C-code, leading to an assembling
17809  error.
17810 \end_layout
17811
17812 \begin_layout Standard
17813 The numeric part of local labels does not need to have 5 digits (although
17814  this is the form of labels output by the compiler), any valid integer will
17815  do.
17816  Please refer to the assemblers documentation for further details.
17817 \end_layout
17818
17819 \end_inset
17820
17821  
17822 \end_layout
17823
17824 \begin_layout Verse
17825
17826 \family typewriter
17827 _asm
17828 \begin_inset LatexCommand \index{\_asm}
17829
17830 \end_inset
17831
17832
17833 \begin_inset LatexCommand \index{\_\_asm}
17834
17835 \end_inset
17836
17837  
17838 \newline
17839 \InsetSpace ~
17840 \InsetSpace ~
17841 \InsetSpace ~
17842 \InsetSpace ~
17843 mov\InsetSpace ~
17844 \InsetSpace ~
17845 \InsetSpace ~
17846 \InsetSpace ~
17847 \InsetSpace ~
17848 b,#10 
17849 \newline
17850 00001$: 
17851 \newline
17852 \InsetSpace ~
17853 \InsetSpace ~
17854 \InsetSpace ~
17855 \InsetSpace ~
17856 djnz\InsetSpace ~
17857 \InsetSpace ~
17858 \InsetSpace ~
17859 \InsetSpace ~
17860 b,00001$ 
17861 \newline
17862 _endasm
17863 \begin_inset LatexCommand \index{\_endasm}
17864
17865 \end_inset
17866
17867
17868 \begin_inset LatexCommand \index{\_\_endasm}
17869
17870 \end_inset
17871
17872  ;
17873 \end_layout
17874
17875 \begin_layout Standard
17876 Inline assembler code cannot reference any C-labels, however it can reference
17877  labels
17878 \begin_inset LatexCommand \index{Labels}
17879
17880 \end_inset
17881
17882  defined by the inline assembler, e.g.:
17883 \end_layout
17884
17885 \begin_layout Verse
17886
17887 \family typewriter
17888 foo() { 
17889 \newline
17890 \InsetSpace ~
17891 \InsetSpace ~
17892 \InsetSpace ~
17893 \InsetSpace ~
17894 /* some c code */ 
17895 \newline
17896 \InsetSpace ~
17897 \InsetSpace ~
17898 \InsetSpace ~
17899 \InsetSpace ~
17900 _asm 
17901 \newline
17902 \InsetSpace ~
17903 \InsetSpace ~
17904 \InsetSpace ~
17905 \InsetSpace ~
17906 \InsetSpace ~
17907 \InsetSpace ~
17908 ; some assembler code 
17909 \newline
17910 \InsetSpace ~
17911 \InsetSpace ~
17912 \InsetSpace ~
17913 \InsetSpace ~
17914 \InsetSpace ~
17915 \InsetSpace ~
17916 ljmp 0003$ 
17917 \newline
17918 \InsetSpace ~
17919 \InsetSpace ~
17920 \InsetSpace ~
17921 \InsetSpace ~
17922 _endasm;
17923  
17924 \newline
17925 \InsetSpace ~
17926 \InsetSpace ~
17927 \InsetSpace ~
17928 \InsetSpace ~
17929 /* some more c code */ 
17930 \newline
17931 clabel:\InsetSpace ~
17932 \InsetSpace ~
17933 /* inline assembler cannot reference this
17934  label */ 
17935 \begin_inset Foot
17936 status open
17937
17938 \begin_layout Standard
17939 Here, the C-label 
17940 \family typewriter
17941 clabel
17942 \family default
17943  is translated by the compiler into a local label, so the locality of labels
17944  within the function is not broken.
17945 \end_layout
17946
17947 \end_inset
17948
17949
17950 \newline
17951 \InsetSpace ~
17952 \InsetSpace ~
17953 \InsetSpace ~
17954 \InsetSpace ~
17955 _asm
17956 \newline
17957 \InsetSpace ~
17958 \InsetSpace ~
17959 \InsetSpace ~
17960 \InsetSpace ~
17961 0003$: ;label (can be referenced by inline assembler only) 
17962 \newline
17963 \InsetSpace ~
17964 \InsetSpace ~
17965 \InsetSpace ~
17966 \InsetSpace ~
17967 _endasm
17968 \begin_inset LatexCommand \index{\_endasm}
17969
17970 \end_inset
17971
17972
17973 \begin_inset LatexCommand \index{\_\_endasm}
17974
17975 \end_inset
17976
17977  ; 
17978 \newline
17979 \InsetSpace ~
17980 \InsetSpace ~
17981 \InsetSpace ~
17982 \InsetSpace ~
17983 /* some more c code */
17984 \newline
17985 }
17986 \end_layout
17987
17988 \begin_layout Standard
17989 In other words inline assembly code can access labels defined in inline
17990  assembly within the scope of the function.
17991  The same goes the other way, i.e.
17992  labels defines in inline assembly can not be accessed by C statements.
17993 \end_layout
17994
17995 \begin_layout Section
17996 Interfacing with Assembler Code
17997 \begin_inset LatexCommand \index{Assembler routines}
17998
17999 \end_inset
18000
18001
18002 \end_layout
18003
18004 \begin_layout Subsection
18005 Global Registers used for Parameter Passing
18006 \begin_inset LatexCommand \index{Parameter passing}
18007
18008 \end_inset
18009
18010
18011 \end_layout
18012
18013 \begin_layout Standard
18014 The compiler always uses the global registers 
18015 \emph on
18016 DPL, DPH
18017 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18018
18019 \end_inset
18020
18021
18022 \begin_inset LatexCommand \index{DPTR}
18023
18024 \end_inset
18025
18026 , B
18027 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
18028
18029 \end_inset
18030
18031  
18032 \emph default
18033 and
18034 \emph on
18035  ACC
18036 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
18037
18038 \end_inset
18039
18040
18041 \emph default
18042  to pass the first (non-bit) parameter to a function, and also to pass the
18043  return value 
18044 \begin_inset LatexCommand \index{return value}
18045
18046 \end_inset
18047
18048 of function; according to the following scheme: one byte return value in
18049  
18050 \emph on
18051 DPL
18052 \emph default
18053 , two byte value in 
18054 \emph on
18055 DPL
18056 \emph default
18057  (LSB) and 
18058 \emph on
18059 DPH
18060 \emph default
18061  (MSB).
18062  three byte values (generic pointers) in 
18063 \emph on
18064 DPH
18065 \emph default
18066
18067 \emph on
18068 DPL
18069 \emph default
18070  and 
18071 \emph on
18072 B
18073 \emph default
18074 , and four byte values in 
18075 \emph on
18076 DPH
18077 \emph default
18078
18079 \emph on
18080 DPL
18081 \emph default
18082 ,
18083 \emph on
18084  B
18085 \emph default
18086  and 
18087 \emph on
18088 ACC
18089 \emph default
18090 .
18091  Generic pointers
18092 \begin_inset LatexCommand \index{generic pointer}
18093
18094 \end_inset
18095
18096  contain type of accessed memory in 
18097 \emph on
18098 B
18099 \emph default
18100
18101 \series bold
18102 0x00
18103 \series default
18104  -- xdata/far, 
18105 \series bold
18106 0x40
18107 \series default
18108  -- idata/near -- , 
18109 \series bold
18110 0x60
18111 \series default
18112  -- pdata, 
18113 \series bold
18114 0x80
18115 \series default
18116  -- code
18117 \begin_inset Note Note
18118 status collapsed
18119
18120 \begin_layout Standard
18121 This might not be the case of certain memory models (medium???)
18122 \end_layout
18123
18124 \end_inset
18125
18126 .
18127 \end_layout
18128
18129 \begin_layout Standard
18130 The second parameter onwards is either allocated on the stack (for reentrant
18131  routines or if -
18132 \begin_inset ERT
18133 status collapsed
18134
18135 \begin_layout Standard
18136
18137
18138 \backslash
18139 /
18140 \end_layout
18141
18142 \end_inset
18143
18144 -stack-auto is used) or in data/xdata memory (depending on the memory model).
18145 \end_layout
18146
18147 \begin_layout Standard
18148 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
18149  space for reentrant functions or allocated directly in bit memory otherwise.
18150 \end_layout
18151
18152 \begin_layout Standard
18153 Functions (with two or more parameters or bit parameters) that are called
18154  through function pointers
18155 \begin_inset LatexCommand \index{function pointers}
18156
18157 \end_inset
18158
18159  must therefor be reentrant so the compiler knows how to pass the parameters.
18160 \end_layout
18161
18162 \begin_layout Subsection
18163 Registers usage
18164 \end_layout
18165
18166 \begin_layout Standard
18167 Unless the called function is declared as 
18168 \family typewriter
18169 _naked
18170 \family default
18171
18172 \begin_inset LatexCommand \index{naked}
18173
18174 \end_inset
18175
18176 , or the -
18177 \begin_inset ERT
18178 status collapsed
18179
18180 \begin_layout Standard
18181
18182
18183 \backslash
18184 /
18185 \end_layout
18186
18187 \end_inset
18188
18189 -callee-saves
18190 \begin_inset LatexCommand \index{-\/-callee-saves}
18191
18192 \end_inset
18193
18194 /-
18195 \begin_inset ERT
18196 status collapsed
18197
18198 \begin_layout Standard
18199
18200
18201 \backslash
18202 /
18203 \end_layout
18204
18205 \end_inset
18206
18207 -all-callee-saves command line option or the corresponding callee_saves
18208  pragma are used, the caller will save the registers (
18209 \emph on
18210 R0-R7
18211 \emph default
18212 ) around the call, so the called function can destroy they content freely.
18213 \end_layout
18214
18215 \begin_layout Standard
18216 If the called function is not declared as 
18217 \family typewriter
18218 _naked
18219 \family default
18220 , the caller will swap register banks around the call, if caller and callee
18221  use different register banks (having them defined by the 
18222 \family typewriter
18223 _using
18224 \family default
18225  modifier).
18226  
18227 \end_layout
18228
18229 \begin_layout Standard
18230 The called function can also use 
18231 \emph on
18232 DPL
18233 \emph default
18234
18235 \emph on
18236 DPH
18237 \emph default
18238
18239 \emph on
18240 B
18241 \emph default
18242  and 
18243 \emph on
18244 ACC
18245 \emph default
18246  observing that they are used for parameter/return value passing.
18247 \end_layout
18248
18249 \begin_layout Subsection
18250 Assembler Routine (non-reentrant)
18251 \end_layout
18252
18253 \begin_layout Standard
18254 In the following example
18255 \begin_inset LatexCommand \index{reentrant}
18256
18257 \end_inset
18258
18259
18260 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18261
18262 \end_inset
18263
18264  the function c_func calls an assembler routine asm_func, which takes two
18265  parameters
18266 \begin_inset LatexCommand \index{function parameter}
18267
18268 \end_inset
18269
18270 .
18271 \end_layout
18272
18273 \begin_layout Verse
18274
18275 \family typewriter
18276 extern int asm_func(unsigned char, unsigned char);
18277 \newline
18278
18279 \newline
18280 int c_func (unsigned char
18281  i, unsigned char j)
18282 \newline
18283 {
18284 \newline
18285 \InsetSpace ~
18286 \InsetSpace ~
18287 \InsetSpace ~
18288 \InsetSpace ~
18289 return asm_func(i,j);
18290 \newline
18291 }
18292 \newline
18293
18294 \newline
18295 int main()
18296 \newline
18297 {
18298 \newline
18299 \InsetSpace ~
18300 \InsetSpace ~
18301 \InsetSpace ~
18302 \InsetSpace ~
18303 return c_func(10,9);
18304 \newline
18305 }
18306 \end_layout
18307
18308 \begin_layout Standard
18309 The corresponding assembler function is:
18310 \end_layout
18311
18312 \begin_layout Verse
18313
18314 \family typewriter
18315 .globl _asm_func_PARM_2 
18316 \newline
18317 \InsetSpace ~
18318 \InsetSpace ~
18319 \InsetSpace ~
18320 \InsetSpace ~
18321 \InsetSpace ~
18322 \InsetSpace ~
18323 \InsetSpace ~
18324 \InsetSpace ~
18325 .globl _asm_func 
18326 \newline
18327 \InsetSpace ~
18328 \InsetSpace ~
18329 \InsetSpace ~
18330 \InsetSpace ~
18331 \InsetSpace ~
18332 \InsetSpace ~
18333 \InsetSpace ~
18334 \InsetSpace ~
18335 .area OSEG 
18336 \newline
18337 _asm_func_PARM_2:
18338 \newline
18339 \InsetSpace ~
18340 \InsetSpace ~
18341 \InsetSpace ~
18342 \InsetSpace ~
18343 \InsetSpace ~
18344 \InsetSpace ~
18345 \InsetSpace ~
18346 \InsetSpace ~
18347 .ds   
18348  1 
18349 \newline
18350 \InsetSpace ~
18351 \InsetSpace ~
18352 \InsetSpace ~
18353 \InsetSpace ~
18354 \InsetSpace ~
18355 \InsetSpace ~
18356 \InsetSpace ~
18357 \InsetSpace ~
18358 .area CSEG 
18359 \newline
18360 _asm_func: 
18361 \newline
18362 \InsetSpace ~
18363 \InsetSpace ~
18364 \InsetSpace ~
18365 \InsetSpace ~
18366 \InsetSpace ~
18367 \InsetSpace ~
18368 \InsetSpace ~
18369 \InsetSpace ~
18370 mov\InsetSpace ~
18371 \InsetSpace ~
18372 \InsetSpace ~
18373 \InsetSpace ~
18374 a,dpl 
18375 \newline
18376 \InsetSpace ~
18377 \InsetSpace ~
18378 \InsetSpace ~
18379 \InsetSpace ~
18380 \InsetSpace ~
18381 \InsetSpace ~
18382 \InsetSpace ~
18383 \InsetSpace ~
18384 add\InsetSpace ~
18385 \InsetSpace ~
18386 \InsetSpace ~
18387 \InsetSpace ~
18388 a,_asm_func_PARM_2 
18389 \newline
18390 \InsetSpace ~
18391 \InsetSpace ~
18392 \InsetSpace ~
18393 \InsetSpace ~
18394 \InsetSpace ~
18395 \InsetSpace ~
18396 \InsetSpace ~
18397 \InsetSpace ~
18398 mov\InsetSpace ~
18399 \InsetSpace ~
18400 \InsetSpace ~
18401 \InsetSpace ~
18402 dpl,a 
18403 \newline
18404 \InsetSpace ~
18405 \InsetSpace ~
18406 \InsetSpace ~
18407 \InsetSpace ~
18408 \InsetSpace ~
18409 \InsetSpace ~
18410 \InsetSpace ~
18411 \InsetSpace ~
18412 mov\InsetSpace ~
18413 \InsetSpace ~
18414 \InsetSpace ~
18415 \InsetSpace ~
18416 dph
18417 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18418
18419 \end_inset
18420
18421 ,#0x00 
18422 \newline
18423 \InsetSpace ~
18424 \InsetSpace ~
18425 \InsetSpace ~
18426 \InsetSpace ~
18427 \InsetSpace ~
18428 \InsetSpace ~
18429 \InsetSpace ~
18430 \InsetSpace ~
18431 ret
18432 \end_layout
18433
18434 \begin_layout Standard
18435 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18436  the parameter number starting from 1, and counting from the left.
18437  The first parameter is passed in 
18438 \emph on
18439 DPH
18440 \emph default
18441
18442 \emph on
18443 DPL
18444 \emph default
18445
18446 \emph on
18447 B
18448 \emph default
18449  and 
18450 \emph on
18451 ACC
18452 \emph default
18453  according to the description above.
18454  The variable name for the second parameter will be _<function_name>_PARM_2.
18455 \newline
18456
18457 \newline
18458 Assem
18459 ble the assembler routine with the following command:
18460 \newline
18461
18462 \newline
18463
18464 \family sans
18465 \series bold
18466 asx8051 -losg asmfunc.asm
18467 \newline
18468
18469 \newline
18470
18471 \family default
18472 \series default
18473 Then compile and link the assembler routine to the C source file with the
18474  following command:
18475 \newline
18476
18477 \newline
18478
18479 \family sans
18480 \series bold
18481 sdcc cfunc.c asmfunc.rel
18482 \end_layout
18483
18484 \begin_layout Subsection
18485 Assembler Routine (reentrant)
18486 \end_layout
18487
18488 \begin_layout Standard
18489 In this case
18490 \begin_inset LatexCommand \index{reentrant}
18491
18492 \end_inset
18493
18494
18495 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18496
18497 \end_inset
18498
18499  the second parameter
18500 \begin_inset LatexCommand \index{function parameter}
18501
18502 \end_inset
18503
18504  onwards will be passed on the stack, the parameters are pushed from right
18505  to left i.e.
18506  before the call the second leftmost parameter will be on the top of the
18507  stack (the leftmost parameter is passed in registers).
18508  Here is an example:
18509 \end_layout
18510
18511 \begin_layout Verse
18512
18513 \family typewriter
18514 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18515 \newline
18516
18517 \newline
18518 int
18519  c_func (unsigned char i, unsigned char j, unsigned char k) reentrant 
18520 \newline
18521 {
18522  
18523 \newline
18524 \InsetSpace ~
18525 \InsetSpace ~
18526 \InsetSpace ~
18527 \InsetSpace ~
18528 return asm_func(i,j,k); 
18529 \newline
18530
18531 \newline
18532
18533 \newline
18534 int main() 
18535 \newline
18536
18537 \newline
18538 \InsetSpace ~
18539 \InsetSpace ~
18540 \InsetSpace ~
18541 \InsetSpace ~
18542 return c_func(10,9,8); 
18543 \newline
18544 }
18545 \end_layout
18546
18547 \begin_layout Standard
18548 The corresponding (unoptimized) assembler routine is:
18549 \end_layout
18550
18551 \begin_layout Verse
18552
18553 \family typewriter
18554 .globl _asm_func 
18555 \newline
18556 _asm_func: 
18557 \newline
18558 \InsetSpace ~
18559 \InsetSpace ~
18560 \InsetSpace ~
18561 \InsetSpace ~
18562 push\InsetSpace ~
18563 _bp 
18564 \newline
18565 \InsetSpace ~
18566 \InsetSpace ~
18567 \InsetSpace ~
18568 \InsetSpace ~
18569 mov\InsetSpace ~
18570 \InsetSpace ~
18571 _bp,sp\InsetSpace ~
18572 \InsetSpace ~
18573 \InsetSpace ~
18574 \InsetSpace ~
18575 \InsetSpace ~
18576 \InsetSpace ~
18577 ;stack contains: _bp, return
18578  address, second parameter, third parameter
18579 \newline
18580 \InsetSpace ~
18581 \InsetSpace ~
18582 \InsetSpace ~
18583 \InsetSpace ~
18584 mov\InsetSpace ~
18585 \InsetSpace ~
18586 r2,dpl
18587 \newline
18588 \InsetSpace ~
18589 \InsetSpace ~
18590 \InsetSpace ~
18591 \InsetSpace ~
18592 mov\InsetSpace ~
18593 \InsetSpace ~
18594 a,_bp
18595 \newline
18596 \InsetSpace ~
18597 \InsetSpace ~
18598 \InsetSpace ~
18599 \InsetSpace ~
18600 add\InsetSpace ~
18601 \InsetSpace ~
18602 a,#0xfd\InsetSpace ~
18603 \InsetSpace ~
18604 \InsetSpace ~
18605 \InsetSpace ~
18606 \InsetSpace ~
18607 ;calculate
18608  pointer to the second parameter
18609 \newline
18610 \InsetSpace ~
18611 \InsetSpace ~
18612 \InsetSpace ~
18613 \InsetSpace ~
18614 mov\InsetSpace ~
18615 \InsetSpace ~
18616 r0,a 
18617 \newline
18618 \InsetSpace ~
18619 \InsetSpace ~
18620 \InsetSpace ~
18621 \InsetSpace ~
18622 mov\InsetSpace ~
18623 \InsetSpace ~
18624 a,_bp 
18625 \newline
18626 \InsetSpace ~
18627 \InsetSpace ~
18628 \InsetSpace ~
18629 \InsetSpace ~
18630 add\InsetSpace ~
18631 \InsetSpace ~
18632 a,#0xfc\InsetSpace ~
18633 \InsetSpace ~
18634 \InsetSpace ~
18635 \InsetSpace ~
18636 \InsetSpace ~
18637 ;calculate pointer
18638  to the rightmost parameter
18639 \newline
18640 \InsetSpace ~
18641 \InsetSpace ~
18642 \InsetSpace ~
18643 \InsetSpace ~
18644 mov\InsetSpace ~
18645 \InsetSpace ~
18646 r1,a 
18647 \newline
18648 \InsetSpace ~
18649 \InsetSpace ~
18650 \InsetSpace ~
18651 \InsetSpace ~
18652 mov\InsetSpace ~
18653 \InsetSpace ~
18654 a,@r0
18655 \newline
18656 \InsetSpace ~
18657 \InsetSpace ~
18658 \InsetSpace ~
18659 \InsetSpace ~
18660 add\InsetSpace ~
18661 \InsetSpace ~
18662 a,@r1
18663 \newline
18664 \InsetSpace ~
18665 \InsetSpace ~
18666 \InsetSpace ~
18667 \InsetSpace ~
18668 add\InsetSpace ~
18669 \InsetSpace ~
18670 a,r2\InsetSpace ~
18671 \InsetSpace ~
18672 \InsetSpace ~
18673 \InsetSpace ~
18674 \InsetSpace ~
18675 \InsetSpace ~
18676 \InsetSpace ~
18677 \InsetSpace ~
18678 ;calculate the
18679  result (= sum of all three parameters)
18680 \newline
18681 \InsetSpace ~
18682 \InsetSpace ~
18683 \InsetSpace ~
18684 \InsetSpace ~
18685 mov\InsetSpace ~
18686 \InsetSpace ~
18687 dpl,a\InsetSpace ~
18688 \InsetSpace ~
18689 \InsetSpace ~
18690 \InsetSpace ~
18691 \InsetSpace ~
18692 \InsetSpace ~
18693 \InsetSpace ~
18694 ;return value goes into dptr
18695  (cast into int)
18696 \newline
18697 \InsetSpace ~
18698 \InsetSpace ~
18699 \InsetSpace ~
18700 \InsetSpace ~
18701 mov\InsetSpace ~
18702 \InsetSpace ~
18703 dph,#0x00 
18704 \newline
18705 \InsetSpace ~
18706 \InsetSpace ~
18707 \InsetSpace ~
18708 \InsetSpace ~
18709 mov\InsetSpace ~
18710 \InsetSpace ~
18711 sp,_bp 
18712 \newline
18713 \InsetSpace ~
18714 \InsetSpace ~
18715 \InsetSpace ~
18716 \InsetSpace ~
18717 pop\InsetSpace ~
18718 \InsetSpace ~
18719 _bp 
18720 \newline
18721 \InsetSpace ~
18722 \InsetSpace ~
18723 \InsetSpace ~
18724 \InsetSpace ~
18725 ret
18726 \end_layout
18727
18728 \begin_layout Standard
18729 The compiling and linking procedure remains the same, however note the extra
18730  entry & exit linkage required for the assembler code, _bp is the stack
18731  frame pointer and is used to compute the offset into the stack for parameters
18732  and local variables.
18733 \begin_inset VSpace bigskip
18734 \end_inset
18735
18736
18737 \end_layout
18738
18739 \begin_layout Section
18740 int (16 bit)
18741 \begin_inset LatexCommand \index{int (16 bit)}
18742
18743 \end_inset
18744
18745  and long (32 bit)
18746 \begin_inset LatexCommand \index{long (32 bit)}
18747
18748 \end_inset
18749
18750  Support
18751 \end_layout
18752
18753 \begin_layout Standard
18754 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18755  multiplication and modulus operations are implemented by support routines.
18756  These support routines are all developed in ANSI-C to facilitate porting
18757  to other MCUs, although some model specific assembler optimizations are
18758  used.
18759  The following files contain the described routines, all of them can be
18760  found in <installdir>/share/sdcc/lib.
18761 \newline
18762
18763 \end_layout
18764
18765 \begin_layout Standard
18766 \align center
18767 \begin_inset Tabular
18768 <lyxtabular version="3" rows="11" columns="2">
18769 <features>
18770 <column alignment="left" valignment="top" leftline="true" width="0">
18771 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18772 <row topline="true" bottomline="true">
18773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18774 \begin_inset Text
18775
18776 \begin_layout Standard
18777
18778 \series bold
18779 Function
18780 \end_layout
18781
18782 \end_inset
18783 </cell>
18784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18785 \begin_inset Text
18786
18787 \begin_layout Standard
18788
18789 \series bold
18790 Description
18791 \end_layout
18792
18793 \end_inset
18794 </cell>
18795 </row>
18796 <row topline="true">
18797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18798 \begin_inset Text
18799
18800 \begin_layout Standard
18801 _mulint.c 
18802 \end_layout
18803
18804 \end_inset
18805 </cell>
18806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18807 \begin_inset Text
18808
18809 \begin_layout Standard
18810 16 bit multiplication
18811 \end_layout
18812
18813 \end_inset
18814 </cell>
18815 </row>
18816 <row topline="true">
18817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18818 \begin_inset Text
18819
18820 \begin_layout Standard
18821 _divsint.c 
18822 \end_layout
18823
18824 \end_inset
18825 </cell>
18826 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18827 \begin_inset Text
18828
18829 \begin_layout Standard
18830  signed 16 bit division (calls _divuint)
18831 \end_layout
18832
18833 \end_inset
18834 </cell>
18835 </row>
18836 <row topline="true">
18837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18838 \begin_inset Text
18839
18840 \begin_layout Standard
18841 _divuint.c 
18842 \end_layout
18843
18844 \end_inset
18845 </cell>
18846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18847 \begin_inset Text
18848
18849 \begin_layout Standard
18850  unsigned 16 bit division
18851 \end_layout
18852
18853 \end_inset
18854 </cell>
18855 </row>
18856 <row topline="true">
18857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18858 \begin_inset Text
18859
18860 \begin_layout Standard
18861 _modsint.c
18862 \end_layout
18863
18864 \end_inset
18865 </cell>
18866 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18867 \begin_inset Text
18868
18869 \begin_layout Standard
18870 signed 16 bit modulus (calls _moduint)
18871 \end_layout
18872
18873 \end_inset
18874 </cell>
18875 </row>
18876 <row topline="true">
18877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18878 \begin_inset Text
18879
18880 \begin_layout Standard
18881 _moduint.c
18882 \end_layout
18883
18884 \end_inset
18885 </cell>
18886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18887 \begin_inset Text
18888
18889 \begin_layout Standard
18890 unsigned 16 bit modulus
18891 \end_layout
18892
18893 \end_inset
18894 </cell>
18895 </row>
18896 <row topline="true">
18897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18898 \begin_inset Text
18899
18900 \begin_layout Standard
18901 _mullong.c
18902 \end_layout
18903
18904 \end_inset
18905 </cell>
18906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18907 \begin_inset Text
18908
18909 \begin_layout Standard
18910 32 bit multiplication
18911 \end_layout
18912
18913 \end_inset
18914 </cell>
18915 </row>
18916 <row topline="true">
18917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18918 \begin_inset Text
18919
18920 \begin_layout Standard
18921 _divslong.c 
18922 \end_layout
18923
18924 \end_inset
18925 </cell>
18926 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18927 \begin_inset Text
18928
18929 \begin_layout Standard
18930  signed 32 division (calls _divulong)
18931 \end_layout
18932
18933 \end_inset
18934 </cell>
18935 </row>
18936 <row topline="true">
18937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18938 \begin_inset Text
18939
18940 \begin_layout Standard
18941 _divulong.c 
18942 \end_layout
18943
18944 \end_inset
18945 </cell>
18946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18947 \begin_inset Text
18948
18949 \begin_layout Standard
18950 unsigned 32 division
18951 \end_layout
18952
18953 \end_inset
18954 </cell>
18955 </row>
18956 <row topline="true">
18957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18958 \begin_inset Text
18959
18960 \begin_layout Standard
18961 _modslong.c
18962 \end_layout
18963
18964 \end_inset
18965 </cell>
18966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18967 \begin_inset Text
18968
18969 \begin_layout Standard
18970  signed 32 bit modulus (calls _modulong)
18971 \end_layout
18972
18973 \end_inset
18974 </cell>
18975 </row>
18976 <row topline="true" bottomline="true">
18977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18978 \begin_inset Text
18979
18980 \begin_layout Standard
18981 _modulong.c
18982 \end_layout
18983
18984 \end_inset
18985 </cell>
18986 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18987 \begin_inset Text
18988
18989 \begin_layout Standard
18990 unsigned 32 bit modulus
18991 \end_layout
18992
18993 \end_inset
18994 </cell>
18995 </row>
18996 </lyxtabular>
18997
18998 \end_inset
18999
19000
19001 \newline
19002
19003 \end_layout
19004
19005 \begin_layout Standard
19006 Since they are compiled as 
19007 \emph on
19008 non-reentrant
19009 \emph default
19010
19011 \begin_inset LatexCommand \index{reentrant}
19012
19013 \end_inset
19014
19015 , interrupt
19016 \begin_inset LatexCommand \index{interrupt}
19017
19018 \end_inset
19019
19020  service routines should not do any of the above operations.
19021  If this is unavoidable then the above routines will need to be compiled
19022  with the 
19023 \emph on
19024 -
19025 \begin_inset ERT
19026 status collapsed
19027
19028 \begin_layout Standard
19029
19030
19031 \backslash
19032 /
19033 \end_layout
19034
19035 \end_inset
19036
19037 -stack-auto
19038 \begin_inset LatexCommand \index{-\/-stack-auto}
19039
19040 \end_inset
19041
19042
19043 \emph default
19044  option, after which the source program will have to be compiled with 
19045 \emph on
19046 -
19047 \begin_inset ERT
19048 status collapsed
19049
19050 \begin_layout Standard
19051
19052
19053 \backslash
19054 /
19055 \end_layout
19056
19057 \end_inset
19058
19059 -int-long-reent
19060 \begin_inset LatexCommand \index{-\/-int-long-reent}
19061
19062 \end_inset
19063
19064
19065 \emph default
19066  option.
19067  Notice that you don't have to call these routines directly.
19068  The compiler will use them automatically every time an integer operation
19069  is required.
19070 \end_layout
19071
19072 \begin_layout Section
19073 Floating Point Support
19074 \begin_inset LatexCommand \index{Floating point support}
19075
19076 \end_inset
19077
19078
19079 \end_layout
19080
19081 \begin_layout Standard
19082 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
19083  The floating point support routines are derived from gcc's floatlib.c and
19084  consist of the following routines:
19085 \newline
19086
19087 \end_layout
19088
19089 \begin_layout Standard
19090 \align center
19091
19092 \size footnotesize
19093 \begin_inset Tabular
19094 <lyxtabular version="3" rows="17" columns="2">
19095 <features>
19096 <column alignment="left" valignment="top" leftline="true" width="0">
19097 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19098 <row topline="true" bottomline="true">
19099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19100 \begin_inset Text
19101
19102 \begin_layout Standard
19103
19104 \family roman
19105 \series medium
19106 \shape up
19107 \size normal
19108 \emph off
19109 \bar no
19110 \noun off
19111 \color none
19112 Function 
19113 \end_layout
19114
19115 \end_inset
19116 </cell>
19117 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19118 \begin_inset Text
19119
19120 \begin_layout Standard
19121 Description
19122 \end_layout
19123
19124 \end_inset
19125 </cell>
19126 </row>
19127 <row topline="true">
19128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19129 \begin_inset Text
19130
19131 \begin_layout Standard
19132
19133 \family roman
19134 \series medium
19135 \shape up
19136 \size normal
19137 \emph off
19138 \bar no
19139 \noun off
19140 \color none
19141 _fsadd.c
19142 \end_layout
19143
19144 \end_inset
19145 </cell>
19146 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19147 \begin_inset Text
19148
19149 \begin_layout Standard
19150
19151 \family roman
19152 \series medium
19153 \shape up
19154 \size normal
19155 \emph off
19156 \bar no
19157 \noun off
19158 \color none
19159 add floating point numbers
19160 \end_layout
19161
19162 \end_inset
19163 </cell>
19164 </row>
19165 <row topline="true">
19166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19167 \begin_inset Text
19168
19169 \begin_layout Standard
19170
19171 \family roman
19172 \series medium
19173 \shape up
19174 \size normal
19175 \emph off
19176 \bar no
19177 \noun off
19178 \color none
19179 _fssub.c 
19180 \end_layout
19181
19182 \end_inset
19183 </cell>
19184 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19185 \begin_inset Text
19186
19187 \begin_layout Standard
19188
19189 \family roman
19190 \series medium
19191 \shape up
19192 \size normal
19193 \emph off
19194 \bar no
19195 \noun off
19196 \color none
19197 subtract floating point numbers 
19198 \end_layout
19199
19200 \end_inset
19201 </cell>
19202 </row>
19203 <row topline="true">
19204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19205 \begin_inset Text
19206
19207 \begin_layout Standard
19208
19209 \family roman
19210 \series medium
19211 \shape up
19212 \size normal
19213 \emph off
19214 \bar no
19215 \noun off
19216 \color none
19217 _fsdiv.c 
19218 \end_layout
19219
19220 \end_inset
19221 </cell>
19222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19223 \begin_inset Text
19224
19225 \begin_layout Standard
19226
19227 \family roman
19228 \series medium
19229 \shape up
19230 \size normal
19231 \emph off
19232 \bar no
19233 \noun off
19234 \color none
19235 divide floating point numbers 
19236 \end_layout
19237
19238 \end_inset
19239 </cell>
19240 </row>
19241 <row topline="true">
19242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19243 \begin_inset Text
19244
19245 \begin_layout Standard
19246
19247 \family roman
19248 \series medium
19249 \shape up
19250 \size normal
19251 \emph off
19252 \bar no
19253 \noun off
19254 \color none
19255 _fsmul.c 
19256 \end_layout
19257
19258 \end_inset
19259 </cell>
19260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19261 \begin_inset Text
19262
19263 \begin_layout Standard
19264
19265 \family roman
19266 \series medium
19267 \shape up
19268 \size normal
19269 \emph off
19270 \bar no
19271 \noun off
19272 \color none
19273 multiply floating point numbers 
19274 \end_layout
19275
19276 \end_inset
19277 </cell>
19278 </row>
19279 <row topline="true">
19280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19281 \begin_inset Text
19282
19283 \begin_layout Standard
19284
19285 \family roman
19286 \series medium
19287 \shape up
19288 \size normal
19289 \emph off
19290 \bar no
19291 \noun off
19292 \color none
19293 _fs2uchar.c
19294 \end_layout
19295
19296 \end_inset
19297 </cell>
19298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19299 \begin_inset Text
19300
19301 \begin_layout Standard
19302
19303 \family roman
19304 \series medium
19305 \shape up
19306 \size normal
19307 \emph off
19308 \bar no
19309 \noun off
19310 \color none
19311 convert floating point to unsigned char
19312 \end_layout
19313
19314 \end_inset
19315 </cell>
19316 </row>
19317 <row topline="true">
19318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19319 \begin_inset Text
19320
19321 \begin_layout Standard
19322
19323 \family roman
19324 \series medium
19325 \shape up
19326 \size normal
19327 \emph off
19328 \bar no
19329 \noun off
19330 \color none
19331 _fs2char.c
19332 \end_layout
19333
19334 \end_inset
19335 </cell>
19336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19337 \begin_inset Text
19338
19339 \begin_layout Standard
19340
19341 \family roman
19342 \series medium
19343 \shape up
19344 \size normal
19345 \emph off
19346 \bar no
19347 \noun off
19348 \color none
19349 convert floating point to signed char
19350 \end_layout
19351
19352 \end_inset
19353 </cell>
19354 </row>
19355 <row topline="true">
19356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19357 \begin_inset Text
19358
19359 \begin_layout Standard
19360
19361 \family roman
19362 \series medium
19363 \shape up
19364 \size normal
19365 \emph off
19366 \bar no
19367 \noun off
19368 \color none
19369 _fs2uint.c
19370 \end_layout
19371
19372 \end_inset
19373 </cell>
19374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19375 \begin_inset Text
19376
19377 \begin_layout Standard
19378
19379 \family roman
19380 \series medium
19381 \shape up
19382 \size normal
19383 \emph off
19384 \bar no
19385 \noun off
19386 \color none
19387 convert floating point to unsigned int
19388 \end_layout
19389
19390 \end_inset
19391 </cell>
19392 </row>
19393 <row topline="true">
19394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19395 \begin_inset Text
19396
19397 \begin_layout Standard
19398
19399 \family roman
19400 \series medium
19401 \shape up
19402 \size normal
19403 \emph off
19404 \bar no
19405 \noun off
19406 \color none
19407 _fs2int.c
19408 \end_layout
19409
19410 \end_inset
19411 </cell>
19412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19413 \begin_inset Text
19414
19415 \begin_layout Standard
19416
19417 \family roman
19418 \series medium
19419 \shape up
19420 \size normal
19421 \emph off
19422 \bar no
19423 \noun off
19424 \color none
19425 convert floating point to signed int
19426 \end_layout
19427
19428 \end_inset
19429 </cell>
19430 </row>
19431 <row topline="true">
19432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19433 \begin_inset Text
19434
19435 \begin_layout Standard
19436
19437 \family roman
19438 \series medium
19439 \shape up
19440 \size normal
19441 \emph off
19442 \bar no
19443 \noun off
19444 \color none
19445 _fs2ulong.
19446 \family default
19447 \series default
19448 \shape default
19449 \size default
19450 \emph default
19451 \bar default
19452 \noun default
19453 c
19454 \end_layout
19455
19456 \end_inset
19457 </cell>
19458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19459 \begin_inset Text
19460
19461 \begin_layout Standard
19462
19463 \family roman
19464 \series medium
19465 \shape up
19466 \size normal
19467 \emph off
19468 \bar no
19469 \noun off
19470 \color none
19471 convert floating point to unsigned long
19472 \end_layout
19473
19474 \end_inset
19475 </cell>
19476 </row>
19477 <row topline="true">
19478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19479 \begin_inset Text
19480
19481 \begin_layout Standard
19482
19483 \family roman
19484 \series medium
19485 \shape up
19486 \size normal
19487 \emph off
19488 \bar no
19489 \noun off
19490 \color none
19491 _fs2long.c
19492 \end_layout
19493
19494 \end_inset
19495 </cell>
19496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19497 \begin_inset Text
19498
19499 \begin_layout Standard
19500
19501 \family roman
19502 \series medium
19503 \shape up
19504 \size normal
19505 \emph off
19506 \bar no
19507 \noun off
19508 \color none
19509 convert floating point to signed long
19510 \end_layout
19511
19512 \end_inset
19513 </cell>
19514 </row>
19515 <row topline="true">
19516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19517 \begin_inset Text
19518
19519 \begin_layout Standard
19520
19521 \family roman
19522 \series medium
19523 \shape up
19524 \size normal
19525 \emph off
19526 \bar no
19527 \noun off
19528 \color none
19529 _uchar2fs.c
19530 \end_layout
19531
19532 \end_inset
19533 </cell>
19534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19535 \begin_inset Text
19536
19537 \begin_layout Standard
19538
19539 \family roman
19540 \series medium
19541 \shape up
19542 \size normal
19543 \emph off
19544 \bar no
19545 \noun off
19546 \color none
19547 convert unsigned char to floating point
19548 \end_layout
19549
19550 \end_inset
19551 </cell>
19552 </row>
19553 <row topline="true">
19554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19555 \begin_inset Text
19556
19557 \begin_layout Standard
19558
19559 \family roman
19560 \series medium
19561 \shape up
19562 \size normal
19563 \emph off
19564 \bar no
19565 \noun off
19566 \color none
19567 _char2fs.c
19568 \end_layout
19569
19570 \end_inset
19571 </cell>
19572 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19573 \begin_inset Text
19574
19575 \begin_layout Standard
19576
19577 \family roman
19578 \series medium
19579 \shape up
19580 \size normal
19581 \emph off
19582 \bar no
19583 \noun off
19584 \color none
19585 convert char to floating point number
19586 \end_layout
19587
19588 \end_inset
19589 </cell>
19590 </row>
19591 <row topline="true">
19592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19593 \begin_inset Text
19594
19595 \begin_layout Standard
19596
19597 \family roman
19598 \series medium
19599 \shape up
19600 \size normal
19601 \emph off
19602 \bar no
19603 \noun off
19604 \color none
19605 _uint2fs.c
19606 \end_layout
19607
19608 \end_inset
19609 </cell>
19610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19611 \begin_inset Text
19612
19613 \begin_layout Standard
19614
19615 \family roman
19616 \series medium
19617 \shape up
19618 \size normal
19619 \emph off
19620 \bar no
19621 \noun off
19622 \color none
19623 convert unsigned int to floating point
19624 \end_layout
19625
19626 \end_inset
19627 </cell>
19628 </row>
19629 <row topline="true">
19630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19631 \begin_inset Text
19632
19633 \begin_layout Standard
19634
19635 \family roman
19636 \series medium
19637 \shape up
19638 \size normal
19639 \emph off
19640 \bar no
19641 \noun off
19642 \color none
19643 _int2fs.c
19644 \end_layout
19645
19646 \end_inset
19647 </cell>
19648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19649 \begin_inset Text
19650
19651 \begin_layout Standard
19652
19653 \family roman
19654 \series medium
19655 \shape up
19656 \size normal
19657 \emph off
19658 \bar no
19659 \noun off
19660 \color none
19661 convert int to floating point numbers
19662 \end_layout
19663
19664 \end_inset
19665 </cell>
19666 </row>
19667 <row topline="true">
19668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19669 \begin_inset Text
19670
19671 \begin_layout Standard
19672
19673 \family roman
19674 \series medium
19675 \shape up
19676 \size normal
19677 \emph off
19678 \bar no
19679 \noun off
19680 \color none
19681 _ulong2fs.c
19682 \end_layout
19683
19684 \end_inset
19685 </cell>
19686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19687 \begin_inset Text
19688
19689 \begin_layout Standard
19690
19691 \family roman
19692 \series medium
19693 \shape up
19694 \size normal
19695 \emph off
19696 \bar no
19697 \noun off
19698 \color none
19699 convert unsigned long to floating point number
19700 \end_layout
19701
19702 \end_inset
19703 </cell>
19704 </row>
19705 <row topline="true" bottomline="true">
19706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19707 \begin_inset Text
19708
19709 \begin_layout Standard
19710
19711 \family roman
19712 \series medium
19713 \shape up
19714 \size normal
19715 \emph off
19716 \bar no
19717 \noun off
19718 \color none
19719 _long2fs.c
19720 \end_layout
19721
19722 \end_inset
19723 </cell>
19724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19725 \begin_inset Text
19726
19727 \begin_layout Standard
19728
19729 \family roman
19730 \series medium
19731 \shape up
19732 \size normal
19733 \emph off
19734 \bar no
19735 \noun off
19736 \color none
19737 convert long to floating point number
19738 \end_layout
19739
19740 \end_inset
19741 </cell>
19742 </row>
19743 </lyxtabular>
19744
19745 \end_inset
19746
19747
19748 \newline
19749
19750 \end_layout
19751
19752 \begin_layout Standard
19753 These support routines are developed in ANSI-C so there is room for space
19754  and speed improvement
19755 \begin_inset Foot
19756 status open
19757
19758 \begin_layout Standard
19759 These floating point routines (
19760 \emph on
19761 not
19762 \emph default
19763  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19764  
19765 \end_layout
19766
19767 \end_inset
19768
19769 .
19770  Note if all these routines are used simultaneously the data space might
19771  overflow.
19772  For serious floating point usage the large model might be needed.
19773  Also notice that you don't have to call this routines directly.
19774  The compiler will use them automatically every time a floating point operation
19775  is required.
19776 \begin_inset VSpace bigskip
19777 \end_inset
19778
19779
19780 \end_layout
19781
19782 \begin_layout Section
19783 Library Routines
19784 \begin_inset LatexCommand \index{Libraries}
19785
19786 \end_inset
19787
19788
19789 \end_layout
19790
19791 \begin_layout Standard
19792
19793 \emph on
19794 <pending: this is messy and incomplete - a little more information is in
19795  sdcc/doc/libdoc.txt
19796 \emph default
19797  >
19798 \end_layout
19799
19800 \begin_layout Subsection
19801 Compiler support routines (_gptrget, _mulint etc.)
19802 \end_layout
19803
19804 \begin_layout Subsection
19805 Stdclib functions (puts, printf, strcat etc.)
19806 \end_layout
19807
19808 \begin_layout Subsubsection
19809 <stdio.h>
19810 \end_layout
19811
19812 \begin_layout Paragraph
19813 getchar(), putchar()
19814 \end_layout
19815
19816 \begin_layout Standard
19817 \begin_inset LatexCommand \index{<stdio.h>}
19818
19819 \end_inset
19820
19821 As usual on embedded systems you have to provide your own 
19822 \family typewriter
19823 getchar()
19824 \begin_inset LatexCommand \index{getchar()}
19825
19826 \end_inset
19827
19828  
19829 \family default
19830 and 
19831 \family typewriter
19832 putchar()
19833 \begin_inset LatexCommand \index{putchar()}
19834
19835 \end_inset
19836
19837
19838 \family default
19839  routines.
19840  SDCC does not know whether the system connects to a serial line with or
19841  without handshake, LCD, keyboard or other device.
19842  And whether a 
19843 \family typewriter
19844 lf
19845 \family default
19846  to 
19847 \family typewriter
19848 crlf
19849 \family default
19850  conversion within 
19851 \family typewriter
19852 putchar()
19853 \family default
19854  is intended.
19855  You'll find examples for serial routines f.e.
19856  in sdcc/device/lib.
19857  For the mcs51 this minimalistic polling 
19858 \family typewriter
19859 putchar()
19860 \family default
19861  routine might be a start:
19862 \end_layout
19863
19864 \begin_layout Verse
19865
19866 \family typewriter
19867 void putchar (char c) { 
19868 \newline
19869 \InsetSpace ~
19870 \InsetSpace ~
19871 \InsetSpace ~
19872 \InsetSpace ~
19873 while (!TI)\InsetSpace ~
19874 \InsetSpace ~
19875 \InsetSpace ~
19876  /* assumes UART is initialized */
19877 \newline
19878 \InsetSpace ~
19879 \InsetSpace ~
19880 \InsetSpace ~
19881 \InsetSpace ~
19882 \InsetSpace ~
19883 \InsetSpace ~
19884 \InsetSpace ~
19885 \InsetSpace ~
19886 ;
19887 \newline
19888 \InsetSpace ~
19889 \InsetSpace ~
19890 \InsetSpace ~
19891 \InsetSpace ~
19892 TI
19893  = 0;
19894 \newline
19895 \InsetSpace ~
19896 \InsetSpace ~
19897 \InsetSpace ~
19898 \InsetSpace ~
19899 SBUF = c;
19900 \newline
19901 }
19902 \end_layout
19903
19904 \begin_layout Paragraph
19905 printf()
19906 \end_layout
19907
19908 \begin_layout Standard
19909 The default
19910 \family typewriter
19911  printf()
19912 \begin_inset LatexCommand \index{printf()}
19913
19914 \end_inset
19915
19916
19917 \family default
19918  implementation in
19919 \family typewriter
19920  printf_large.c
19921 \family default
19922  does not support float (except on ds390).
19923  To enable this recompile it with the option 
19924 \emph on
19925 -
19926 \begin_inset ERT
19927 status collapsed
19928
19929 \begin_layout Standard
19930
19931
19932 \backslash
19933 /
19934 \end_layout
19935
19936 \end_inset
19937
19938 DUSE_FLOATS=1
19939 \begin_inset LatexCommand \index{USE\_FLOATS}
19940
19941 \end_inset
19942
19943
19944 \emph default
19945  on the command line.
19946  Use
19947 \emph on
19948  -
19949 \begin_inset ERT
19950 status collapsed
19951
19952 \begin_layout Standard
19953
19954
19955 \backslash
19956 /
19957 \end_layout
19958
19959 \end_inset
19960
19961 -model-large
19962 \begin_inset LatexCommand \index{-\/-model-large}
19963
19964 \end_inset
19965
19966
19967 \emph default
19968  for the mcs51 port, since this uses a lot of memory.
19969 \end_layout
19970
19971 \begin_layout Standard
19972 If you're short on code memory you might want to use 
19973 \family typewriter
19974 printf_small()
19975 \begin_inset LatexCommand \index{printf\_small()}
19976
19977 \end_inset
19978
19979
19980 \family default
19981  
19982 \emph on
19983 instead
19984 \emph default
19985  of
19986 \family typewriter
19987  printf().
19988
19989 \family default
19990  For the mcs51 there additionally are assembly versions 
19991 \family typewriter
19992 printf_tiny()
19993 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19994
19995 \end_inset
19996
19997
19998 \family default
19999  (subset of printf using less than 270 bytes) and 
20000 \family typewriter
20001 printf_fast()
20002 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
20003
20004 \end_inset
20005
20006  
20007 \family default
20008 and
20009 \family typewriter
20010  printf_fast_f()
20011 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
20012
20013 \end_inset
20014
20015
20016 \family default
20017  (floating-point aware version of printf_fast) which should fit the requirements
20018  of many embedded systems (printf_fast() can be customized by unsetting
20019  #defines to 
20020 \emph on
20021 not
20022 \emph default
20023  support long variables and field widths).
20024  Be sure to use only one of these printf options within a project.
20025 \newline
20026
20027 \end_layout
20028
20029 \begin_layout Standard
20030 Feature matrix of different 
20031 \emph on
20032 printf
20033 \emph default
20034  options on mcs51.
20035 \end_layout
20036
20037 \begin_layout Standard
20038 \begin_inset Tabular
20039 <lyxtabular version="3" rows="14" columns="7">
20040 <features islongtable="true">
20041 <column alignment="left" valignment="middle" leftline="true" width="14col%">
20042 <column alignment="center" valignment="top" leftline="true" width="0">
20043 <column alignment="center" valignment="top" leftline="true" width="12col%">
20044 <column alignment="center" valignment="top" leftline="true" width="10col%">
20045 <column alignment="center" valignment="top" leftline="true" width="0">
20046 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
20047 <column alignment="center" valignment="top" rightline="true" width="0">
20048 <row topline="true" bottomline="true" endhead="true">
20049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20050 \begin_inset Text
20051
20052 \begin_layout Standard
20053
20054 \series bold
20055 \size large
20056 mcs51
20057 \end_layout
20058
20059 \end_inset
20060 </cell>
20061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20062 \begin_inset Text
20063
20064 \begin_layout Standard
20065 printf
20066 \begin_inset LatexCommand \index{printf}
20067
20068 \end_inset
20069
20070
20071 \end_layout
20072
20073 \end_inset
20074 </cell>
20075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20076 \begin_inset Text
20077
20078 \begin_layout Standard
20079 printf 
20080 \size scriptsize
20081 USE_FLOATS=1
20082 \end_layout
20083
20084 \end_inset
20085 </cell>
20086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20087 \begin_inset Text
20088
20089 \begin_layout Standard
20090 printf_small
20091 \end_layout
20092
20093 \end_inset
20094 </cell>
20095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20096 \begin_inset Text
20097
20098 \begin_layout Standard
20099 printf_fast
20100 \end_layout
20101
20102 \end_inset
20103 </cell>
20104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20105 \begin_inset Text
20106
20107 \begin_layout Standard
20108 printf_fast_f
20109 \end_layout
20110
20111 \end_inset
20112 </cell>
20113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20114 \begin_inset Text
20115
20116 \begin_layout Standard
20117 printf_tiny
20118 \end_layout
20119
20120 \end_inset
20121 </cell>
20122 </row>
20123 <row topline="true" endhead="true">
20124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20125 \begin_inset Text
20126
20127 \begin_layout Standard
20128 filename
20129 \end_layout
20130
20131 \end_inset
20132 </cell>
20133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20134 \begin_inset Text
20135
20136 \begin_layout Standard
20137
20138 \size scriptsize
20139 printf_large.c
20140 \end_layout
20141
20142 \end_inset
20143 </cell>
20144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20145 \begin_inset Text
20146
20147 \begin_layout Standard
20148
20149 \size scriptsize
20150 printf_large.c
20151 \end_layout
20152
20153 \end_inset
20154 </cell>
20155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20156 \begin_inset Text
20157
20158 \begin_layout Standard
20159
20160 \size scriptsize
20161 printfl.c
20162 \end_layout
20163
20164 \end_inset
20165 </cell>
20166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20167 \begin_inset Text
20168
20169 \begin_layout Standard
20170
20171 \size scriptsize
20172 printf_fast.c
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 \size scriptsize
20183 printf_fast_f.c
20184 \end_layout
20185
20186 \end_inset
20187 </cell>
20188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20189 \begin_inset Text
20190
20191 \begin_layout Standard
20192
20193 \size scriptsize
20194 printf_tiny.c
20195 \end_layout
20196
20197 \end_inset
20198 </cell>
20199 </row>
20200 <row topline="true" endhead="true">
20201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20202 \begin_inset Text
20203
20204 \begin_layout Standard
20205 \begin_inset Quotes sld
20206 \end_inset
20207
20208 Hello World
20209 \begin_inset Quotes srd
20210 \end_inset
20211
20212  size
20213 \end_layout
20214
20215 \begin_layout Standard
20216 small / large
20217 \end_layout
20218
20219 \end_inset
20220 </cell>
20221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20222 \begin_inset Text
20223
20224 \begin_layout Standard
20225 1.7k / 2.4k
20226 \end_layout
20227
20228 \end_inset
20229 </cell>
20230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20231 \begin_inset Text
20232
20233 \begin_layout Standard
20234 4.3k / 5.6k
20235 \end_layout
20236
20237 \end_inset
20238 </cell>
20239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20240 \begin_inset Text
20241
20242 \begin_layout Standard
20243 1.2k / 1.8k
20244 \end_layout
20245
20246 \end_inset
20247 </cell>
20248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20249 \begin_inset Text
20250
20251 \begin_layout Standard
20252 1.3k / 1.3k
20253 \end_layout
20254
20255 \end_inset
20256 </cell>
20257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20258 \begin_inset Text
20259
20260 \begin_layout Standard
20261 1.9k / 1.9k
20262 \end_layout
20263
20264 \end_inset
20265 </cell>
20266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20267 \begin_inset Text
20268
20269 \begin_layout Standard
20270 0.44k / 0.44k
20271 \end_layout
20272
20273 \end_inset
20274 </cell>
20275 </row>
20276 <row topline="true" endhead="true">
20277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20278 \begin_inset Text
20279
20280 \begin_layout Standard
20281 code size
20282 \end_layout
20283
20284 \begin_layout Standard
20285 small / large
20286 \end_layout
20287
20288 \end_inset
20289 </cell>
20290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20291 \begin_inset Text
20292
20293 \begin_layout Standard
20294 1.4k / 2.0k
20295 \end_layout
20296
20297 \end_inset
20298 </cell>
20299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20300 \begin_inset Text
20301
20302 \begin_layout Standard
20303 2.8k / 3.7k
20304 \end_layout
20305
20306 \end_inset
20307 </cell>
20308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20309 \begin_inset Text
20310
20311 \begin_layout Standard
20312 0.45k / 0.47k (+ _ltoa)
20313 \end_layout
20314
20315 \end_inset
20316 </cell>
20317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20318 \begin_inset Text
20319
20320 \begin_layout Standard
20321 1.2k / 1.2k
20322 \end_layout
20323
20324 \end_inset
20325 </cell>
20326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20327 \begin_inset Text
20328
20329 \begin_layout Standard
20330 1.6k / 1.6k
20331 \end_layout
20332
20333 \end_inset
20334 </cell>
20335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20336 \begin_inset Text
20337
20338 \begin_layout Standard
20339 0.26k / 0.26k
20340 \end_layout
20341
20342 \end_inset
20343 </cell>
20344 </row>
20345 <row topline="true">
20346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20347 \begin_inset Text
20348
20349 \begin_layout Standard
20350 formats
20351 \end_layout
20352
20353 \end_inset
20354 </cell>
20355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20356 \begin_inset Text
20357
20358 \begin_layout Standard
20359 cdi
20360 \emph on
20361 o
20362 \emph default
20363 psux
20364 \end_layout
20365
20366 \end_inset
20367 </cell>
20368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20369 \begin_inset Text
20370
20371 \begin_layout Standard
20372
20373 \family roman
20374 \series medium
20375 \shape up
20376 \size normal
20377 \emph off
20378 \bar no
20379 \noun off
20380 \color none
20381 cd
20382 \family default
20383 \series default
20384 \shape default
20385 \size default
20386 \emph default
20387 \bar default
20388 \noun default
20389 f
20390 \family roman
20391 \series medium
20392 \shape up
20393 \size normal
20394 \emph off
20395 \bar no
20396 \noun off
20397 i
20398 \family default
20399 \series default
20400 \shape default
20401 \size default
20402 \emph on
20403 \bar default
20404 \noun default
20405 o
20406 \family roman
20407 \series medium
20408 \shape up
20409 \size normal
20410 \emph off
20411 \bar no
20412 \noun off
20413 psux
20414 \end_layout
20415
20416 \end_inset
20417 </cell>
20418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20419 \begin_inset Text
20420
20421 \begin_layout Standard
20422 c
20423 \family roman
20424 \series medium
20425 \shape up
20426 \size normal
20427 \emph off
20428 \bar no
20429 \noun off
20430 \color none
20431 d
20432 \family default
20433 \series default
20434 \shape default
20435 \size default
20436 \emph on
20437 \bar default
20438 \noun default
20439 o
20440 \family roman
20441 \series medium
20442 \shape up
20443 \size normal
20444 \emph off
20445 \bar no
20446 \noun off
20447 s
20448 \family default
20449 \series default
20450 \shape default
20451 \size default
20452 \emph default
20453 \bar default
20454 \noun default
20455 x
20456 \end_layout
20457
20458 \end_inset
20459 </cell>
20460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20461 \begin_inset Text
20462
20463 \begin_layout Standard
20464 cdsux
20465 \end_layout
20466
20467 \end_inset
20468 </cell>
20469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20470 \begin_inset Text
20471
20472 \begin_layout Standard
20473 cdfsux
20474 \end_layout
20475
20476 \end_inset
20477 </cell>
20478 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20479 \begin_inset Text
20480
20481 \begin_layout Standard
20482 cdsux
20483 \end_layout
20484
20485 \end_inset
20486 </cell>
20487 </row>
20488 <row topline="true">
20489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20490 \begin_inset Text
20491
20492 \begin_layout Standard
20493 long (32 bit) support
20494 \end_layout
20495
20496 \end_inset
20497 </cell>
20498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20499 \begin_inset Text
20500
20501 \begin_layout Standard
20502 x
20503 \end_layout
20504
20505 \end_inset
20506 </cell>
20507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20508 \begin_inset Text
20509
20510 \begin_layout Standard
20511 x
20512 \end_layout
20513
20514 \end_inset
20515 </cell>
20516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20517 \begin_inset Text
20518
20519 \begin_layout Standard
20520 x
20521 \end_layout
20522
20523 \end_inset
20524 </cell>
20525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20526 \begin_inset Text
20527
20528 \begin_layout Standard
20529 x
20530 \end_layout
20531
20532 \end_inset
20533 </cell>
20534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20535 \begin_inset Text
20536
20537 \begin_layout Standard
20538
20539 \family roman
20540 \series medium
20541 \shape up
20542 \size normal
20543 \emph off
20544 \bar no
20545 \noun off
20546 \color none
20547 x
20548 \end_layout
20549
20550 \end_inset
20551 </cell>
20552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20553 \begin_inset Text
20554
20555 \begin_layout Standard
20556 -
20557 \end_layout
20558
20559 \end_inset
20560 </cell>
20561 </row>
20562 <row topline="true">
20563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20564 \begin_inset Text
20565
20566 \begin_layout Standard
20567 byte arguments on stack
20568 \end_layout
20569
20570 \end_inset
20571 </cell>
20572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20573 \begin_inset Text
20574
20575 \begin_layout Standard
20576 b
20577 \end_layout
20578
20579 \end_inset
20580 </cell>
20581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20582 \begin_inset Text
20583
20584 \begin_layout Standard
20585 b
20586 \end_layout
20587
20588 \end_inset
20589 </cell>
20590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20591 \begin_inset Text
20592
20593 \begin_layout Standard
20594 -
20595 \end_layout
20596
20597 \end_inset
20598 </cell>
20599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20600 \begin_inset Text
20601
20602 \begin_layout Standard
20603 -
20604 \end_layout
20605
20606 \end_inset
20607 </cell>
20608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20609 \begin_inset Text
20610
20611 \begin_layout Standard
20612 -
20613 \end_layout
20614
20615 \end_inset
20616 </cell>
20617 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20618 \begin_inset Text
20619
20620 \begin_layout Standard
20621 -
20622 \end_layout
20623
20624 \end_inset
20625 </cell>
20626 </row>
20627 <row topline="true">
20628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20629 \begin_inset Text
20630
20631 \begin_layout Standard
20632 float format
20633 \begin_inset LatexCommand \index{Floating point support}
20634
20635 \end_inset
20636
20637
20638 \end_layout
20639
20640 \end_inset
20641 </cell>
20642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20643 \begin_inset Text
20644
20645 \begin_layout Standard
20646 -
20647 \end_layout
20648
20649 \end_inset
20650 </cell>
20651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20652 \begin_inset Text
20653
20654 \begin_layout Standard
20655 %f
20656 \end_layout
20657
20658 \end_inset
20659 </cell>
20660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20661 \begin_inset Text
20662
20663 \begin_layout Standard
20664 -
20665 \end_layout
20666
20667 \end_inset
20668 </cell>
20669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20670 \begin_inset Text
20671
20672 \begin_layout Standard
20673 -
20674 \end_layout
20675
20676 \end_inset
20677 </cell>
20678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20679 \begin_inset Text
20680
20681 \begin_layout Standard
20682 %f
20683 \begin_inset Foot
20684 status collapsed
20685
20686 \begin_layout Standard
20687 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20688 \end_layout
20689
20690 \end_inset
20691
20692
20693 \end_layout
20694
20695 \end_inset
20696 </cell>
20697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20698 \begin_inset Text
20699
20700 \begin_layout Standard
20701 -
20702 \end_layout
20703
20704 \end_inset
20705 </cell>
20706 </row>
20707 <row topline="true">
20708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20709 \begin_inset Text
20710
20711 \begin_layout Standard
20712 float formats %e %g
20713 \end_layout
20714
20715 \end_inset
20716 </cell>
20717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20718 \begin_inset Text
20719
20720 \begin_layout Standard
20721 -
20722 \end_layout
20723
20724 \end_inset
20725 </cell>
20726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20727 \begin_inset Text
20728
20729 \begin_layout Standard
20730 -
20731 \end_layout
20732
20733 \end_inset
20734 </cell>
20735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20736 \begin_inset Text
20737
20738 \begin_layout Standard
20739 -
20740 \end_layout
20741
20742 \end_inset
20743 </cell>
20744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20745 \begin_inset Text
20746
20747 \begin_layout Standard
20748 -
20749 \end_layout
20750
20751 \end_inset
20752 </cell>
20753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20754 \begin_inset Text
20755
20756 \begin_layout Standard
20757 -
20758 \end_layout
20759
20760 \end_inset
20761 </cell>
20762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20763 \begin_inset Text
20764
20765 \begin_layout Standard
20766 -
20767 \end_layout
20768
20769 \end_inset
20770 </cell>
20771 </row>
20772 <row topline="true" bottomline="true">
20773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20774 \begin_inset Text
20775
20776 \begin_layout Standard
20777 field width
20778 \end_layout
20779
20780 \end_inset
20781 </cell>
20782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20783 \begin_inset Text
20784
20785 \begin_layout Standard
20786 x
20787 \end_layout
20788
20789 \end_inset
20790 </cell>
20791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20792 \begin_inset Text
20793
20794 \begin_layout Standard
20795 x
20796 \end_layout
20797
20798 \end_inset
20799 </cell>
20800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20801 \begin_inset Text
20802
20803 \begin_layout Standard
20804 -
20805 \end_layout
20806
20807 \end_inset
20808 </cell>
20809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20810 \begin_inset Text
20811
20812 \begin_layout Standard
20813 x
20814 \end_layout
20815
20816 \end_inset
20817 </cell>
20818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20819 \begin_inset Text
20820
20821 \begin_layout Standard
20822 x
20823 \end_layout
20824
20825 \end_inset
20826 </cell>
20827 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20828 \begin_inset Text
20829
20830 \begin_layout Standard
20831 -
20832 \end_layout
20833
20834 \end_inset
20835 </cell>
20836 </row>
20837 <row bottomline="true">
20838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20839 \begin_inset Text
20840
20841 \begin_layout Standard
20842 string speed
20843 \begin_inset Foot
20844 status collapsed
20845
20846 \begin_layout Standard
20847 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20848 \backslash
20849 r', '
20850 \backslash
20851 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20852 \end_layout
20853
20854 \end_inset
20855
20856 ,
20857 \end_layout
20858
20859 \begin_layout Standard
20860 small / large
20861 \end_layout
20862
20863 \end_inset
20864 </cell>
20865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20866 \begin_inset Text
20867
20868 \begin_layout Standard
20869 1.52 / 2.59 ms
20870 \end_layout
20871
20872 \end_inset
20873 </cell>
20874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20875 \begin_inset Text
20876
20877 \begin_layout Standard
20878 1.53 / 2.62 ms
20879 \end_layout
20880
20881 \end_inset
20882 </cell>
20883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20884 \begin_inset Text
20885
20886 \begin_layout Standard
20887 0.92 / 0.93 ms
20888 \end_layout
20889
20890 \end_inset
20891 </cell>
20892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20893 \begin_inset Text
20894
20895 \begin_layout Standard
20896 0.45 / 0.45 ms
20897 \end_layout
20898
20899 \end_inset
20900 </cell>
20901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20902 \begin_inset Text
20903
20904 \begin_layout Standard
20905 0.46 / 0.46 ms
20906 \end_layout
20907
20908 \end_inset
20909 </cell>
20910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20911 \begin_inset Text
20912
20913 \begin_layout Standard
20914 0.45 / 0.45 ms
20915 \end_layout
20916
20917 \end_inset
20918 </cell>
20919 </row>
20920 <row bottomline="true">
20921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20922 \begin_inset Text
20923
20924 \begin_layout Standard
20925 int speed
20926 \begin_inset Foot
20927 status collapsed
20928
20929 \begin_layout Standard
20930 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20931  putchar()
20932 \end_layout
20933
20934 \end_inset
20935
20936 ,
20937 \end_layout
20938
20939 \begin_layout Standard
20940 small / large
20941 \end_layout
20942
20943 \end_inset
20944 </cell>
20945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20946 \begin_inset Text
20947
20948 \begin_layout Standard
20949 3.01 / 3.61 ms
20950 \end_layout
20951
20952 \end_inset
20953 </cell>
20954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20955 \begin_inset Text
20956
20957 \begin_layout Standard
20958 3.01 / 3.61 ms
20959 \end_layout
20960
20961 \end_inset
20962 </cell>
20963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20964 \begin_inset Text
20965
20966 \begin_layout Standard
20967 3.51 / 18.13 ms
20968 \end_layout
20969
20970 \end_inset
20971 </cell>
20972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20973 \begin_inset Text
20974
20975 \begin_layout Standard
20976 0.22 / 0.22 ms
20977 \end_layout
20978
20979 \end_inset
20980 </cell>
20981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20982 \begin_inset Text
20983
20984 \begin_layout Standard
20985 0.23 / 0.23 ms
20986 \end_layout
20987
20988 \end_inset
20989 </cell>
20990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20991 \begin_inset Text
20992
20993 \begin_layout Standard
20994 0.25 / 0.25 ms
20995 \begin_inset Foot
20996 status collapsed
20997
20998 \begin_layout Standard
20999 printf_tiny integer speed is data dependent, worst case is 0.33 ms
21000 \end_layout
21001
21002 \end_inset
21003
21004
21005 \end_layout
21006
21007 \end_inset
21008 </cell>
21009 </row>
21010 <row bottomline="true">
21011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21012 \begin_inset Text
21013
21014 \begin_layout Standard
21015 long speed
21016 \begin_inset Foot
21017 status collapsed
21018
21019 \begin_layout Standard
21020 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
21021  empty putchar()
21022 \end_layout
21023
21024 \end_inset
21025
21026 ,
21027 \end_layout
21028
21029 \begin_layout Standard
21030 small / large
21031 \end_layout
21032
21033 \end_inset
21034 </cell>
21035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21036 \begin_inset Text
21037
21038 \begin_layout Standard
21039 5.37 / 6.31 ms
21040 \end_layout
21041
21042 \end_inset
21043 </cell>
21044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21045 \begin_inset Text
21046
21047 \begin_layout Standard
21048 5.37 / 6.31 ms
21049 \end_layout
21050
21051 \end_inset
21052 </cell>
21053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21054 \begin_inset Text
21055
21056 \begin_layout Standard
21057 8.71 / 40.65 ms
21058 \end_layout
21059
21060 \end_inset
21061 </cell>
21062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21063 \begin_inset Text
21064
21065 \begin_layout Standard
21066 0.40 / 0.40 ms
21067 \end_layout
21068
21069 \end_inset
21070 </cell>
21071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21072 \begin_inset Text
21073
21074 \begin_layout Standard
21075 0.40 / 0.40 ms
21076 \end_layout
21077
21078 \end_inset
21079 </cell>
21080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21081 \begin_inset Text
21082
21083 \begin_layout Standard
21084 -
21085 \end_layout
21086
21087 \end_inset
21088 </cell>
21089 </row>
21090 <row bottomline="true">
21091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21092 \begin_inset Text
21093
21094 \begin_layout Standard
21095 float speed
21096 \begin_inset Foot
21097 status collapsed
21098
21099 \begin_layout Standard
21100 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
21101  empty putchar()
21102 \end_layout
21103
21104 \end_inset
21105
21106 ,
21107 \end_layout
21108
21109 \begin_layout Standard
21110 small / large
21111 \end_layout
21112
21113 \end_inset
21114 </cell>
21115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21116 \begin_inset Text
21117
21118 \begin_layout Standard
21119 -
21120 \end_layout
21121
21122 \end_inset
21123 </cell>
21124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21125 \begin_inset Text
21126
21127 \begin_layout Standard
21128 7.49 / 22.47 ms
21129 \end_layout
21130
21131 \end_inset
21132 </cell>
21133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21134 \begin_inset Text
21135
21136 \begin_layout Standard
21137 -
21138 \end_layout
21139
21140 \end_inset
21141 </cell>
21142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21143 \begin_inset Text
21144
21145 \begin_layout Standard
21146 -
21147 \end_layout
21148
21149 \end_inset
21150 </cell>
21151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21152 \begin_inset Text
21153
21154 \begin_layout Standard
21155 1.04 / 1.04 ms
21156 \end_layout
21157
21158 \end_inset
21159 </cell>
21160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21161 \begin_inset Text
21162
21163 \begin_layout Standard
21164 -
21165 \end_layout
21166
21167 \end_inset
21168 </cell>
21169 </row>
21170 </lyxtabular>
21171
21172 \end_inset
21173
21174
21175 \end_layout
21176
21177 \begin_layout Subsubsection
21178 <malloc.h>
21179 \begin_inset LatexCommand \index{malloc.h}
21180
21181 \end_inset
21182
21183
21184 \end_layout
21185
21186 \begin_layout Standard
21187 As of SDCC 2.6.2 you no longer need to call an initialization routine before
21188  using dynamic memory allocation
21189 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21190
21191 \end_inset
21192
21193  and a default heap
21194 \begin_inset LatexCommand \index{heap (malloc)}
21195
21196 \end_inset
21197
21198  space of 1024 bytes is provided for malloc to allocate memory from.
21199  If you need a different heap size you need to recompile _heap.c with the
21200  required size defined in HEAP_SIZE.
21201  It is recommended to make a copy of this file into your project directory
21202  and compile it there with:
21203 \end_layout
21204
21205 \begin_layout Verse
21206
21207 \family typewriter
21208 sdcc -c _heap.c -D HEAD_SIZE=2048
21209 \end_layout
21210
21211 \begin_layout Standard
21212 And then link it with:
21213 \end_layout
21214
21215 \begin_layout Verse
21216
21217 \family typewriter
21218 sdcc main.rel _heap.rel
21219 \end_layout
21220
21221 \begin_layout Subsection
21222 Math functions (sinf, powf, sqrtf etc.)
21223 \end_layout
21224
21225 \begin_layout Subsubsection
21226 <math.h>
21227 \end_layout
21228
21229 \begin_layout Standard
21230 See definitions in file <math.h>.
21231 \end_layout
21232
21233 \begin_layout Subsection
21234 Other libraries
21235 \end_layout
21236
21237 \begin_layout Standard
21238 Libraries
21239 \begin_inset LatexCommand \index{Libraries}
21240
21241 \end_inset
21242
21243  included in SDCC should have a license at least as liberal as the GNU Lesser
21244  General Public License
21245 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21246
21247 \end_inset
21248
21249  
21250 \emph on
21251 LGPL
21252 \emph default
21253 .
21254 \end_layout
21255
21256 \begin_layout Standard
21257 \begin_inset Note Note
21258 status collapsed
21259
21260 \begin_layout Standard
21261 license statements for the libraries are missing.
21262  sdcc/device/lib/ser_ir.c
21263 \end_layout
21264
21265 \begin_layout Standard
21266 or _decdptr f.e.
21267  come with a GPL (as opposed to LGPL) License - this will not be liberal
21268  enough for many embedded programmers.
21269 \end_layout
21270
21271 \end_inset
21272
21273
21274 \end_layout
21275
21276 \begin_layout Standard
21277 If you have ported some library or want to share experience about some code
21278  which f.e.
21279  falls into any of these categories Busses (I
21280 \begin_inset Formula $^{\textrm{2}}$
21281 \end_inset
21282
21283 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21284  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21285  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
21286 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21287
21288 \end_inset
21289
21290 \InsetSpace ~
21291 would certainly like to hear about it.
21292 \end_layout
21293
21294 \begin_layout Standard
21295 Programmers coding for embedded systems are not especially famous for being
21296  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21297 e these references are very valuable.
21298  Let's help to create a climate where information is shared.
21299 \begin_inset VSpace bigskip
21300 \end_inset
21301
21302
21303 \end_layout
21304
21305 \begin_layout Section
21306 Memory Models
21307 \end_layout
21308
21309 \begin_layout Subsection
21310 MCS51 Memory Models
21311 \begin_inset LatexCommand \index{Memory model}
21312
21313 \end_inset
21314
21315
21316 \begin_inset LatexCommand \index{MCS51 memory model}
21317
21318 \end_inset
21319
21320
21321 \end_layout
21322
21323 \begin_layout Subsubsection
21324 Small, Medium and Large
21325 \end_layout
21326
21327 \begin_layout Standard
21328 SDCC allows three memory models for MCS51 code, 
21329 \shape slanted
21330 small, medium
21331 \shape default
21332  and 
21333 \shape slanted
21334 large
21335 \shape default
21336 .
21337  Modules compiled with different memory models should 
21338 \emph on
21339 never
21340 \emph default
21341  be combined together or the results would be unpredictable.
21342  The library routines supplied with the compiler are compiled as small,
21343  medium and large.
21344  The compiled library modules are contained in separate directories as small,
21345  medium and large so that you can link to the appropriate set.
21346 \end_layout
21347
21348 \begin_layout Standard
21349 When the medium or large model is used all variables declared without a
21350  storage class will be allocated into the external ram, this includes all
21351  parameters and local variables (for non-reentrant
21352 \begin_inset LatexCommand \index{reentrant}
21353
21354 \end_inset
21355
21356  functions).
21357  When the small model is used variables without storage class are allocated
21358  in the internal ram.
21359 \end_layout
21360
21361 \begin_layout Standard
21362 Judicious usage of the processor specific storage classes
21363 \begin_inset LatexCommand \index{Storage class}
21364
21365 \end_inset
21366
21367  and the 'reentrant' function type will yield much more efficient code,
21368  than using the large model.
21369  Several optimizations are disabled when the program is compiled using the
21370  large model, it is therefore recommended that the small model be used unless
21371  absolutely required.
21372 \end_layout
21373
21374 \begin_layout Subsubsection
21375 External Stack
21376 \begin_inset LatexCommand \label{sub:External-Stack}
21377
21378 \end_inset
21379
21380
21381 \begin_inset LatexCommand \index{stack}
21382
21383 \end_inset
21384
21385
21386 \begin_inset LatexCommand \index{External stack (mcs51)}
21387
21388 \end_inset
21389
21390
21391 \end_layout
21392
21393 \begin_layout Standard
21394 The external stack (-
21395 \begin_inset ERT
21396 status collapsed
21397
21398 \begin_layout Standard
21399
21400
21401 \backslash
21402 /
21403 \end_layout
21404
21405 \end_inset
21406
21407 -xstack option
21408 \begin_inset LatexCommand \index{-\/-xstack}
21409
21410 \end_inset
21411
21412 ) is located in pdata
21413 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21414
21415 \end_inset
21416
21417  memory (usually at the start of the external ram segment) and uses all
21418  unused space in pdata (max.
21419  256 bytes).
21420  When -
21421 \begin_inset ERT
21422 status collapsed
21423
21424 \begin_layout Standard
21425
21426
21427 \backslash
21428 /
21429 \end_layout
21430
21431 \end_inset
21432
21433 -xstack option is used to compile the program, the parameters and local
21434  variables
21435 \begin_inset LatexCommand \index{local variables}
21436
21437 \end_inset
21438
21439  of all reentrant functions are allocated in this area.
21440  This option is provided for programs with large stack space requirements.
21441  When used with the -
21442 \begin_inset ERT
21443 status collapsed
21444
21445 \begin_layout Standard
21446
21447
21448 \backslash
21449 /
21450 \end_layout
21451
21452 \end_inset
21453
21454 -stack-auto
21455 \begin_inset LatexCommand \index{-\/-stack-auto}
21456
21457 \end_inset
21458
21459  option, all parameters and local variables are allocated on the external
21460  stack (note: support libraries will need to be recompiled with the same
21461  options.
21462  There is a predefined target in the library makefile).
21463 \end_layout
21464
21465 \begin_layout Standard
21466 The compiler outputs the higher order address byte of the external ram segment
21467  into port P2
21468 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21469
21470 \end_inset
21471
21472  (see also section 
21473 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21474
21475 \end_inset
21476
21477 ), therefore when using the External Stack option, this port 
21478 \emph on
21479 may not
21480 \emph default
21481  be used by the application program.
21482 \end_layout
21483
21484 \begin_layout Subsection
21485 DS390 Memory Model
21486 \begin_inset LatexCommand \index{Memory model}
21487
21488 \end_inset
21489
21490
21491 \begin_inset LatexCommand \index{DS390 memory model}
21492
21493 \end_inset
21494
21495
21496 \end_layout
21497
21498 \begin_layout Standard
21499 The only model supported is Flat 24
21500 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21501
21502 \end_inset
21503
21504 .
21505  This generates code for the 24 bit contiguous addressing mode of the Dallas
21506  DS80C390 part.
21507  In this mode, up to four meg of external RAM or code space can be directly
21508  addressed.
21509  See the data sheets at www.dalsemi.com for further information on this part.
21510 \newline
21511
21512 \newline
21513 Note
21514  that the compiler does not generate any code to place the processor into
21515  24 bitmode (although 
21516 \emph on
21517 tinibios
21518 \emph default
21519  in the ds390 libraries will do that for you).
21520  If you don't use 
21521 \emph on
21522 tinibios
21523 \emph default
21524
21525 \begin_inset LatexCommand \index{Tinibios (DS390)}
21526
21527 \end_inset
21528
21529 , the boot loader or similar code must ensure that the processor is in 24
21530  bit contiguous addressing mode before calling the SDCC startup code.
21531 \newline
21532
21533 \newline
21534 Like
21535  the 
21536 \emph on
21537 -
21538 \begin_inset ERT
21539 status collapsed
21540
21541 \begin_layout Standard
21542
21543
21544 \backslash
21545 /
21546 \end_layout
21547
21548 \end_inset
21549
21550 -model-large
21551 \emph default
21552  option, variables will by default be placed into the XDATA segment.
21553  
21554 \newline
21555
21556 \newline
21557 Segments may be placed anywhere in the 4 meg address space using the usual
21558  -
21559 \begin_inset ERT
21560 status collapsed
21561
21562 \begin_layout Standard
21563
21564
21565 \backslash
21566 /
21567 \end_layout
21568
21569 \end_inset
21570
21571 -*-loc options.
21572  Note that if any segments are located above 64K, the -r flag must be passed
21573  to the linker to generate the proper segment relocations, and the Intel
21574  HEX output format must be used.
21575  The -r flag can be passed to the linker by using the option 
21576 \emph on
21577 -Wl-r
21578 \emph default
21579  on the SDCC command line.
21580  However, currently the linker can not handle code segments > 64k.
21581 \end_layout
21582
21583 \begin_layout Section
21584 Pragmas
21585 \begin_inset LatexCommand \label{sec:Pragmas}
21586
21587 \end_inset
21588
21589
21590 \begin_inset LatexCommand \index{Pragmas}
21591
21592 \end_inset
21593
21594
21595 \end_layout
21596
21597 \begin_layout Standard
21598 Pragmas are used to turn on and/or off certain compiler options.
21599  Some of them are closely related to corresponding command-line options
21600  (see section 
21601 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21602
21603 \end_inset
21604
21605 ).
21606 \newline
21607 Pragmas should be placed before and/or after a function, placing pragmas
21608  inside a function body could have unpredictable results.
21609 \newline
21610
21611 \newline
21612 SDCC supports the
21613  following #pragma directives:
21614 \end_layout
21615
21616 \begin_layout Itemize
21617
21618 \series bold
21619 save
21620 \series default
21621
21622 \begin_inset LatexCommand \index{\#pragma save}
21623
21624 \end_inset
21625
21626  - this will save most current options to the save/restore stack.
21627  See #pragma\InsetSpace ~
21628 restore.
21629 \end_layout
21630
21631 \begin_layout Itemize
21632
21633 \series bold
21634 restore
21635 \series default
21636
21637 \begin_inset LatexCommand \index{\#pragma restore}
21638
21639 \end_inset
21640
21641  - will restore saved options from the last save.
21642  saves & restores can be nested.
21643  SDCC uses a save/restore stack: save pushes current options to the stack,
21644  restore pulls current options from the stack.
21645  See #pragma\InsetSpace ~
21646 save.
21647 \newline
21648
21649 \end_layout
21650
21651 \begin_layout Itemize
21652
21653 \series bold
21654 callee_saves
21655 \series default
21656
21657 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21658
21659 \end_inset
21660
21661
21662 \begin_inset LatexCommand \index{function prologue}
21663
21664 \end_inset
21665
21666  function1[,function2[,function3...]] 
21667 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21668
21669 \end_inset
21670
21671 - The compiler by default uses a caller saves convention for register saving
21672  across function calls, however this can cause unnecessary register pushing
21673  and popping
21674 \begin_inset LatexCommand \index{push/pop}
21675
21676 \end_inset
21677
21678  when calling small functions from larger functions.
21679  This option can be used to switch off the register saving convention for
21680  the function names specified.
21681  The compiler will not save registers when calling these functions, extra
21682  code need to be manually inserted at the entry and exit for these functions
21683  to save and restore the registers used by these functions, this can SUBSTANTIAL
21684 LY reduce code and improve run time performance of the generated code.
21685  In the future the compiler (with inter procedural analysis) may be able
21686  to determine the appropriate scheme to use for each function call.
21687  If -
21688 \begin_inset ERT
21689 status collapsed
21690
21691 \begin_layout Standard
21692
21693
21694 \backslash
21695 /
21696 \end_layout
21697
21698 \end_inset
21699
21700 -callee-saves command line option is used (see page 
21701 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21702
21703 \end_inset
21704
21705 ), the function names specified in #pragma\InsetSpace ~
21706 callee_saves
21707 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21708
21709 \end_inset
21710
21711  is appended to the list of functions specified in the command line.
21712 \end_layout
21713
21714 \begin_layout Itemize
21715
21716 \series bold
21717 exclude
21718 \series default
21719
21720 \begin_inset LatexCommand \index{\#pragma exclude}
21721
21722 \end_inset
21723
21724  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21725  of pairs of push/pop
21726 \begin_inset LatexCommand \index{push/pop}
21727
21728 \end_inset
21729
21730  instructions in 
21731 \emph on
21732 I
21733 \emph default
21734 nterrupt
21735 \begin_inset LatexCommand \index{interrupt}
21736
21737 \end_inset
21738
21739  
21740 \emph on
21741 S
21742 \emph default
21743 ervice 
21744 \emph on
21745 R
21746 \emph default
21747 outines.
21748  The directive should be placed immediately before the ISR function definition
21749  and it affects ALL ISR functions following it.
21750  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21751 exclude\InsetSpace ~
21752 none
21753 \begin_inset LatexCommand \index{\#pragma exclude}
21754
21755 \end_inset
21756
21757 .
21758  See also the related keyword _naked
21759 \begin_inset LatexCommand \index{\_naked}
21760
21761 \end_inset
21762
21763
21764 \begin_inset LatexCommand \index{\_\_naked}
21765
21766 \end_inset
21767
21768 .
21769 \end_layout
21770
21771 \begin_layout Itemize
21772
21773 \series bold
21774 less_pedantic
21775 \series default
21776
21777 \begin_inset LatexCommand \index{pedantic}
21778
21779 \end_inset
21780
21781
21782 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21783
21784 \end_inset
21785
21786  
21787 \begin_inset LatexCommand \label{ite:less_pedantic}
21788
21789 \end_inset
21790
21791 - the compiler will not warn you anymore for obvious mistakes, you're on
21792  your own now ;-( .
21793  See also the command line option -
21794 \begin_inset ERT
21795 status collapsed
21796
21797 \begin_layout Standard
21798
21799
21800 \backslash
21801 /
21802 \end_layout
21803
21804 \end_inset
21805
21806 -less-pedantic 
21807 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21808
21809 \end_inset
21810
21811 .
21812  
21813 \newline
21814 More specifically, the following warnings will be disabled: 
21815 \shape italic
21816 comparison is always [true/false] due to limited range of data type
21817 \shape default
21818  (94); 
21819 \shape italic
21820 overflow in implicit constant conversion
21821 \shape default
21822  (158); [the (in)famous] 
21823 \shape italic
21824 conditional flow changed by optimizer: so said EVELYN the modified DOG
21825 \shape default
21826  (110); 
21827 \shape italic
21828 function '[function name]' must return value
21829 \shape default
21830  (59).
21831  
21832 \newline
21833 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21834  level) are disabled, too, namely: 
21835 \shape italic
21836 constant value '[
21837 \begin_inset Note Note
21838 status collapsed
21839
21840 \begin_layout Standard
21841 dunno what comes here - this warning appears to be unused altogether
21842 \end_layout
21843
21844 \end_inset
21845
21846 ]', out of range
21847 \shape default
21848  (81); 
21849 \shape italic
21850 [left/right] shifting more than size of object changed to zero
21851 \shape default
21852  (116); 
21853 \shape italic
21854 unreachable code
21855 \shape default
21856  (126); 
21857 \shape italic
21858 integer overflow in expression
21859 \shape default
21860  (165); 
21861 \shape italic
21862 unmatched #pragma save and #pragma restore
21863 \shape default
21864  (170); 
21865 \shape italic
21866 comparison of 'signed char' with 'unsigned char' requires promotion to int
21867 \shape default
21868  (185); 
21869 \shape italic
21870 ISO C90 does not support flexible array members
21871 \shape default
21872  (187); 
21873 \shape italic
21874 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21875 nam
21876 e]':\InsetSpace ~
21877 [
21878 \begin_inset Note Note
21879 status collapsed
21880
21881 \begin_layout Standard
21882 appears to be always blank - what was supposed to be here?
21883 \end_layout
21884
21885 \end_inset
21886
21887 ]
21888 \shape default
21889  (114); 
21890 \shape italic
21891 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21892  complexity [number]
21893 \shape default
21894  (121).
21895 \end_layout
21896
21897 \begin_layout Itemize
21898
21899 \series bold
21900 disable_warning
21901 \series default
21902  <nnnn>
21903 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21904
21905 \end_inset
21906
21907  - the compiler will not warn you anymore about warning number <nnnn>.
21908 \end_layout
21909
21910 \begin_layout Itemize
21911
21912 \series bold
21913 nogcse
21914 \series default
21915
21916 \begin_inset LatexCommand \index{\#pragma nogcse}
21917
21918 \end_inset
21919
21920  - will stop global common subexpression elimination.
21921 \end_layout
21922
21923 \begin_layout Itemize
21924
21925 \series bold
21926 noinduction
21927 \series default
21928
21929 \begin_inset LatexCommand \index{\#pragma noinduction}
21930
21931 \end_inset
21932
21933  - will stop loop induction optimizations.
21934 \end_layout
21935
21936 \begin_layout Itemize
21937
21938 \series bold
21939 noinvariant
21940 \series default
21941
21942 \begin_inset LatexCommand \index{\#pragma noinvariant}
21943
21944 \end_inset
21945
21946  - will not do loop invariant optimizations.
21947  For more details see Loop Invariants in section
21948 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21949
21950 \end_inset
21951
21952 .
21953 \end_layout
21954
21955 \begin_layout Itemize
21956
21957 \series bold
21958 noiv
21959 \series default
21960
21961 \begin_inset LatexCommand \index{\#pragma noiv}
21962
21963 \end_inset
21964
21965  - Do not generate interrupt
21966 \begin_inset LatexCommand \index{interrupt}
21967
21968 \end_inset
21969
21970  vector table
21971 \begin_inset LatexCommand \index{interrupt vector table}
21972
21973 \end_inset
21974
21975  entries for all ISR functions defined after the pragma.
21976  This is useful in cases where the interrupt vector table must be defined
21977  manually, or when there is a secondary, manually defined interrupt vector
21978  table (e.g.
21979  for the autovector feature of the Cypress EZ-USB FX2).
21980  More elegantly this can be achieved by obmitting the optional interrupt
21981  number after the interrupt keyword, see section 
21982 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21983
21984 \end_inset
21985
21986 \InsetSpace ~
21987 about interrupts.
21988 \end_layout
21989
21990 \begin_layout Itemize
21991
21992 \series bold
21993 nojtbound
21994 \series default
21995
21996 \begin_inset LatexCommand \index{\#pragma nojtbound}
21997
21998 \end_inset
21999
22000  - will not generate code for boundary value checking, when switch statements
22001  are turned into jump-tables (dangerous).
22002  For more details see section 
22003 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
22004
22005 \end_inset
22006
22007 .
22008 \end_layout
22009
22010 \begin_layout Itemize
22011
22012 \series bold
22013 noloopreverse
22014 \series default
22015
22016 \begin_inset LatexCommand \index{\#pragma noloopreverse}
22017
22018 \end_inset
22019
22020  - Will not do loop reversal optimization
22021 \end_layout
22022
22023 \begin_layout Itemize
22024
22025 \series bold
22026 nooverlay
22027 \series default
22028
22029 \begin_inset LatexCommand \index{\#pragma nooverlay}
22030
22031 \end_inset
22032
22033  - the compiler will not overlay the parameters and local variables of a
22034  function.
22035 \end_layout
22036
22037 \begin_layout Itemize
22038
22039 \series bold
22040 stackauto
22041 \series default
22042
22043 \begin_inset LatexCommand \index{\#pragma stackauto}
22044
22045 \end_inset
22046
22047 - See option -
22048 \begin_inset ERT
22049 status collapsed
22050
22051 \begin_layout Standard
22052
22053
22054 \backslash
22055 /
22056 \end_layout
22057
22058 \end_inset
22059
22060 -stack-auto
22061 \begin_inset LatexCommand \index{-\/-stack-auto}
22062
22063 \end_inset
22064
22065  and section 
22066 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
22067
22068 \end_inset
22069
22070  Parameters and Local Variables.
22071 \end_layout
22072
22073 \begin_layout Itemize
22074
22075 \series bold
22076 opt_code_speed
22077 \series default
22078  
22079 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
22080
22081 \end_inset
22082
22083 - The compiler will optimize code generation towards fast code, possibly
22084  at the expense of code size.
22085  Currently this has little effect.
22086 \end_layout
22087
22088 \begin_layout Itemize
22089
22090 \series bold
22091 opt_code_size
22092 \series default
22093  
22094 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
22095
22096 \end_inset
22097
22098 - The compiler will optimize code generation towards compact code, possibly
22099  at the expense of code speed.
22100  Currently this has little effect.
22101 \end_layout
22102
22103 \begin_layout Itemize
22104
22105 \series bold
22106 opt_code_balanced
22107 \series default
22108  
22109 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
22110
22111 \end_inset
22112
22113 - The compiler will attempt to generate code that is both compact and fast,
22114  as long as meeting one goal is not a detriment to the other (this is the
22115  default).
22116  
22117 \end_layout
22118
22119 \begin_layout Itemize
22120
22121 \series bold
22122 std_sdcc89
22123 \series default
22124  
22125 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
22126
22127 \end_inset
22128
22129 - Generally follow the C89 standard, but allow SDCC features that conflict
22130  with the standard (default).
22131 \end_layout
22132
22133 \begin_layout Itemize
22134
22135 \series bold
22136 std_c89
22137 \series default
22138  
22139 \begin_inset LatexCommand \index{\#pragma std\_c89}
22140
22141 \end_inset
22142
22143 - Follow the C89 standard and disable SDCC features that conflict with the
22144  standard.
22145 \end_layout
22146
22147 \begin_layout Itemize
22148
22149 \series bold
22150 std_sdcc99
22151 \series default
22152  
22153 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
22154
22155 \end_inset
22156
22157 - Generally follow the C99 standard, but allow SDCC features that conflict
22158  with the standard (incomplete support).
22159 \end_layout
22160
22161 \begin_layout Itemize
22162
22163 \series bold
22164 std_c99
22165 \series default
22166  
22167 \begin_inset LatexCommand \index{\#pragma std\_c99}
22168
22169 \end_inset
22170
22171 - Follow the C99 standard and disable SDCC features that conflict with the
22172  standard (incomplete support).
22173 \end_layout
22174
22175 \begin_layout Itemize
22176
22177 \series bold
22178 codeseg
22179 \series default
22180  <name>
22181 \begin_inset LatexCommand \index{\#pragma codeseg}
22182
22183 \end_inset
22184
22185 - Use this name (max.
22186  8 characters) for the code segment.
22187  See option -
22188 \begin_inset ERT
22189 status collapsed
22190
22191 \begin_layout Standard
22192
22193
22194 \backslash
22195 /
22196 \end_layout
22197
22198 \end_inset
22199
22200 -codeseg.
22201 \end_layout
22202
22203 \begin_layout Itemize
22204
22205 \series bold
22206 constseg
22207 \series default
22208  <name>
22209 \begin_inset LatexCommand \index{\#pragma constseg}
22210
22211 \end_inset
22212
22213 - Use this name (max.
22214  8 characters) for the const segment.
22215  See option -
22216 \begin_inset ERT
22217 status collapsed
22218
22219 \begin_layout Standard
22220
22221
22222 \backslash
22223 /
22224 \end_layout
22225
22226 \end_inset
22227
22228 -constseg.
22229 \end_layout
22230
22231 \begin_layout Standard
22232 The preprocessor SDCPP
22233 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22234
22235 \end_inset
22236
22237  supports the following #pragma directives:
22238 \end_layout
22239
22240 \begin_layout Itemize
22241
22242 \series bold
22243 pedantic_parse_number
22244 \series default
22245
22246 \begin_inset LatexCommand \index{pedantic}
22247
22248 \end_inset
22249
22250
22251 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22252
22253 \end_inset
22254
22255  (+ | -) 
22256 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22257
22258 \end_inset
22259
22260 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22261  properly and the macro LO_B(3) gets expanded.
22262  Default is off.
22263  See also the -
22264 \begin_inset ERT
22265 status collapsed
22266
22267 \begin_layout Standard
22268
22269
22270 \backslash
22271 /
22272 \end_layout
22273
22274 \end_inset
22275
22276 -pedantic-parse-number command line option 
22277 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22278
22279 \end_inset
22280
22281 .
22282  
22283 \newline
22284 Below is an example on how to use this pragma.
22285
22286 \emph on
22287  Note: this functionality is not in conformance with standard!
22288 \end_layout
22289
22290 \begin_layout Verse
22291
22292 \family typewriter
22293 #pragma pedantic_parse_number +
22294 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22295
22296 \end_inset
22297
22298
22299 \newline
22300
22301 \newline
22302 #define LO_B(x) ((x) & 0xff)
22303 \newline
22304
22305 \newline
22306 unsigned char foo(void)
22307 \newline
22308 {
22309 \newline
22310 \InsetSpace ~
22311 \InsetSpace ~
22312 \InsetSpace ~
22313 unsigned char c=0xfe-LO_B(3)
22314 ;
22315 \newline
22316
22317 \newline
22318 \InsetSpace ~
22319 \InsetSpace ~
22320 \InsetSpace ~
22321 return c;
22322 \newline
22323 }
22324 \newline
22325
22326 \end_layout
22327
22328 \begin_layout Itemize
22329
22330 \series bold
22331 preproc_asm
22332 \series default
22333
22334 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22335
22336 \end_inset
22337
22338  (+ | -) - switch _asm _endasm block preprocessing on / off.
22339  Default is on.
22340  You use this prama to define multilines of assembly code.
22341  This will prevent the preprocessor from changing the formating required
22342  by assembly code.
22343  Below is an example on how to use this pragma.
22344 \end_layout
22345
22346 \begin_layout Verse
22347
22348 \family typewriter
22349 #pragma preproc_asm -
22350 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22351
22352 \end_inset
22353
22354
22355 \newline
22356 #define MYDELAY _asm
22357 \newline
22358 \InsetSpace ~
22359 \InsetSpace ~
22360 \InsetSpace ~
22361 nop ;my assembly comment...
22362 \newline
22363 \InsetSpace ~
22364 \InsetSpace ~
22365 \InsetSpace ~
22366 nop
22367 \newline
22368 \InsetSpace ~
22369 \InsetSpace ~
22370 \InsetSpace ~
22371 nop
22372 \newline
22373 _endasm
22374 \newline
22375 #pragma preproc_asm
22376  +
22377 \newline
22378
22379 \newline
22380 void foo (void) 
22381 \newline
22382
22383 \newline
22384 \InsetSpace ~
22385 \InsetSpace ~
22386 \InsetSpace ~
22387  ...
22388  
22389 \newline
22390 \InsetSpace ~
22391 \InsetSpace ~
22392 \InsetSpace ~
22393  MYDELAY;
22394 \newline
22395 \InsetSpace ~
22396 \InsetSpace ~
22397 \InsetSpace ~
22398  ...
22399  
22400 \newline
22401
22402 \newline
22403
22404 \end_layout
22405
22406 \begin_layout Itemize
22407
22408 \series bold
22409 sdcc_hash
22410 \series default
22411
22412 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22413
22414 \end_inset
22415
22416  (+ | -) - Allow "naked" hash in macro definition, for example:
22417 \newline
22418
22419 \family typewriter
22420 #define DIR_LO(x) #(x & 0xff)
22421 \family default
22422
22423 \newline
22424 Default is off.
22425  Below is an example on how to use this pragma.
22426 \end_layout
22427
22428 \begin_layout Verse
22429
22430 \family typewriter
22431 #pragma preproc_asm +
22432 \newline
22433 #pragma sdcc_hash +
22434 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22435
22436 \end_inset
22437
22438
22439 \newline
22440
22441 \newline
22442 #define ROMCALL(x) 
22443 \backslash
22444
22445 \newline
22446 \InsetSpace ~
22447 \InsetSpace ~
22448 \InsetSpace ~
22449 mov R6_B3, #(x & 0xff) 
22450 \backslash
22451
22452 \newline
22453 \InsetSpace ~
22454 \InsetSpace ~
22455 \InsetSpace ~
22456 mov R7_B3, #((x >> 8) & 0xff) 
22457 \backslash
22458
22459 \newline
22460 \InsetSpace ~
22461 \InsetSpace ~
22462 \InsetSpace ~
22463 lcall __romcall
22464 \newline
22465
22466 \newline
22467 ...
22468 \newline
22469 _asm
22470 \newline
22471 ROMCALL(72)
22472 \newline
22473 _endasm;
22474 \newline
22475 ...
22476 \newline
22477
22478 \end_layout
22479
22480 \begin_layout Standard
22481 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22482 ons which might cause the compiler to generate extra stack and/or data space
22483  to store compiler generated temporary variables.
22484  This usually happens in large functions.
22485  Pragma directives should be used as shown in the following example, they
22486  are used to control options and optimizations for a given function.
22487  
22488 \end_layout
22489
22490 \begin_layout Verse
22491
22492 \family typewriter
22493 #pragma save
22494 \begin_inset LatexCommand \index{\#pragma save}
22495
22496 \end_inset
22497
22498  \InsetSpace ~
22499 \InsetSpace ~
22500 \InsetSpace ~
22501 \InsetSpace ~
22502 \InsetSpace ~
22503 \InsetSpace ~
22504 \InsetSpace ~
22505 /* save the current settings */ 
22506 \newline
22507 #pragma nogcse
22508 \begin_inset LatexCommand \index{\#pragma nogcse}
22509
22510 \end_inset
22511
22512  \InsetSpace ~
22513 \InsetSpace ~
22514 \InsetSpace ~
22515 \InsetSpace ~
22516 \InsetSpace ~
22517 /* turnoff global subexpression elimination */ 
22518 \newline
22519 #pragma noinduction
22520 \begin_inset LatexCommand \index{\#pragma noinduction}
22521
22522 \end_inset
22523
22524  /* turn off induction optimizations */ 
22525 \newline
22526 int foo () 
22527 \newline
22528
22529 \newline
22530 \InsetSpace ~
22531  \InsetSpace ~
22532  ...
22533  
22534 \newline
22535 \InsetSpace ~
22536  \InsetSpace ~
22537  /* large code */ 
22538 \newline
22539 \InsetSpace ~
22540  \InsetSpace ~
22541  ...
22542  
22543 \newline
22544
22545 \newline
22546 #pragma restore
22547 \begin_inset LatexCommand \index{\#pragma restore}
22548
22549 \end_inset
22550
22551  /* turn the optimizations back on */
22552 \end_layout
22553
22554 \begin_layout Standard
22555 The compiler will generate a warning message when extra space is allocated.
22556  It is strongly recommended that the save and restore pragmas be used when
22557  changing options for a function.
22558 \newline
22559
22560 \newline
22561
22562 \newline
22563
22564 \end_layout
22565
22566 \begin_layout Section
22567 Defines Created by the Compiler
22568 \end_layout
22569
22570 \begin_layout Standard
22571 The compiler creates the following #defines
22572 \begin_inset LatexCommand \index{\#defines}
22573
22574 \end_inset
22575
22576
22577 \begin_inset LatexCommand \index{Defines created by the compiler}
22578
22579 \end_inset
22580
22581 :
22582 \newline
22583
22584 \end_layout
22585
22586 \begin_layout Standard
22587 \begin_inset Tabular
22588 <lyxtabular version="3" rows="11" columns="2">
22589 <features>
22590 <column alignment="left" valignment="top" leftline="true" width="3in">
22591 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22592 <row topline="true" bottomline="true">
22593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22594 \begin_inset Text
22595
22596 \begin_layout Standard
22597
22598 \series bold
22599 #define
22600 \end_layout
22601
22602 \end_inset
22603 </cell>
22604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22605 \begin_inset Text
22606
22607 \begin_layout Standard
22608
22609 \series bold
22610 Description
22611 \end_layout
22612
22613 \end_inset
22614 </cell>
22615 </row>
22616 <row topline="true">
22617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22618 \begin_inset Text
22619
22620 \begin_layout Standard
22621 SDCC
22622 \begin_inset LatexCommand \index{SDCC}
22623
22624 \end_inset
22625
22626  
22627 \end_layout
22628
22629 \end_inset
22630 </cell>
22631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22632 \begin_inset Text
22633
22634 \begin_layout Standard
22635 Always defined.
22636  Since version 2.5.6 the version number as an int (ex.
22637  256)
22638 \end_layout
22639
22640 \end_inset
22641 </cell>
22642 </row>
22643 <row topline="true">
22644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22645 \begin_inset Text
22646
22647 \begin_layout Standard
22648 SDCC_mcs51
22649 \begin_inset LatexCommand \index{SDCC\_mcs51}
22650
22651 \end_inset
22652
22653  or SDCC_ds390
22654 \begin_inset LatexCommand \index{SDCC\_ds390}
22655
22656 \end_inset
22657
22658  or SDCC_z80
22659 \begin_inset LatexCommand \index{SDCC\_z80}
22660
22661 \end_inset
22662
22663 , etc.
22664 \end_layout
22665
22666 \end_inset
22667 </cell>
22668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22669 \begin_inset Text
22670
22671 \begin_layout Standard
22672 depending on the model used (e.g.: -mds390)
22673 \end_layout
22674
22675 \end_inset
22676 </cell>
22677 </row>
22678 <row topline="true">
22679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22680 \begin_inset Text
22681
22682 \begin_layout Standard
22683 __mcs51
22684 \begin_inset LatexCommand \index{\_\_mcs51}
22685
22686 \end_inset
22687
22688 , __ds390
22689 \begin_inset LatexCommand \index{\_\_ds390}
22690
22691 \end_inset
22692
22693 , __hc08
22694 \begin_inset LatexCommand \index{\_\_hc08}
22695
22696 \end_inset
22697
22698 , __z80
22699 \begin_inset LatexCommand \index{\_\_z80}
22700
22701 \end_inset
22702
22703 , etc
22704 \end_layout
22705
22706 \end_inset
22707 </cell>
22708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22709 \begin_inset Text
22710
22711 \begin_layout Standard
22712 depending on the model used (e.g.
22713  -mz80)
22714 \end_layout
22715
22716 \end_inset
22717 </cell>
22718 </row>
22719 <row topline="true">
22720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22721 \begin_inset Text
22722
22723 \begin_layout Standard
22724 SDCC_STACK_AUTO
22725 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22726
22727 \end_inset
22728
22729
22730 \end_layout
22731
22732 \end_inset
22733 </cell>
22734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22735 \begin_inset Text
22736
22737 \begin_layout Standard
22738 when 
22739 \emph on
22740 -
22741 \begin_inset ERT
22742 status collapsed
22743
22744 \begin_layout Standard
22745
22746
22747 \backslash
22748 /
22749 \end_layout
22750
22751 \end_inset
22752
22753 -stack-auto
22754 \emph default
22755  option is used
22756 \end_layout
22757
22758 \end_inset
22759 </cell>
22760 </row>
22761 <row topline="true">
22762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22763 \begin_inset Text
22764
22765 \begin_layout Standard
22766 SDCC_MODEL_SMALL
22767 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22768
22769 \end_inset
22770
22771
22772 \end_layout
22773
22774 \end_inset
22775 </cell>
22776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22777 \begin_inset Text
22778
22779 \begin_layout Standard
22780 when 
22781 \emph on
22782 -
22783 \begin_inset ERT
22784 status collapsed
22785
22786 \begin_layout Standard
22787
22788
22789 \backslash
22790 /
22791 \end_layout
22792
22793 \end_inset
22794
22795 -model-small
22796 \emph default
22797  is used
22798 \end_layout
22799
22800 \end_inset
22801 </cell>
22802 </row>
22803 <row topline="true">
22804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22805 \begin_inset Text
22806
22807 \begin_layout Standard
22808 SDCC_MODEL_MEDIUM
22809 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22810
22811 \end_inset
22812
22813
22814 \end_layout
22815
22816 \end_inset
22817 </cell>
22818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22819 \begin_inset Text
22820
22821 \begin_layout Standard
22822 when 
22823 \emph on
22824 -
22825 \begin_inset ERT
22826 status collapsed
22827
22828 \begin_layout Standard
22829
22830
22831 \backslash
22832 /
22833 \end_layout
22834
22835 \end_inset
22836
22837 -model-medium
22838 \emph default
22839  is used
22840 \end_layout
22841
22842 \end_inset
22843 </cell>
22844 </row>
22845 <row topline="true">
22846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22847 \begin_inset Text
22848
22849 \begin_layout Standard
22850 SDCC_MODEL_LARGE
22851 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22852
22853 \end_inset
22854
22855
22856 \end_layout
22857
22858 \end_inset
22859 </cell>
22860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22861 \begin_inset Text
22862
22863 \begin_layout Standard
22864 when 
22865 \emph on
22866 -
22867 \begin_inset ERT
22868 status collapsed
22869
22870 \begin_layout Standard
22871
22872
22873 \backslash
22874 /
22875 \end_layout
22876
22877 \end_inset
22878
22879 -model-large
22880 \emph default
22881  is used
22882 \end_layout
22883
22884 \end_inset
22885 </cell>
22886 </row>
22887 <row topline="true">
22888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22889 \begin_inset Text
22890
22891 \begin_layout Standard
22892 SDCC_USE_XSTACK
22893 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22894
22895 \end_inset
22896
22897
22898 \end_layout
22899
22900 \end_inset
22901 </cell>
22902 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22903 \begin_inset Text
22904
22905 \begin_layout Standard
22906 when 
22907 \emph on
22908 -
22909 \begin_inset ERT
22910 status collapsed
22911
22912 \begin_layout Standard
22913
22914
22915 \backslash
22916 /
22917 \end_layout
22918
22919 \end_inset
22920
22921 -xstack
22922 \emph default
22923  option is used
22924 \end_layout
22925
22926 \end_inset
22927 </cell>
22928 </row>
22929 <row topline="true">
22930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22931 \begin_inset Text
22932
22933 \begin_layout Standard
22934 SDCC_STACK_TENBIT
22935 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22936
22937 \end_inset
22938
22939  
22940 \end_layout
22941
22942 \end_inset
22943 </cell>
22944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22945 \begin_inset Text
22946
22947 \begin_layout Standard
22948 when 
22949 \emph on
22950 -mds390
22951 \emph default
22952  is used
22953 \end_layout
22954
22955 \end_inset
22956 </cell>
22957 </row>
22958 <row topline="true" bottomline="true">
22959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22960 \begin_inset Text
22961
22962 \begin_layout Standard
22963 SDCC_MODEL_FLAT24
22964 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22965
22966 \end_inset
22967
22968
22969 \end_layout
22970
22971 \end_inset
22972 </cell>
22973 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22974 \begin_inset Text
22975
22976 \begin_layout Standard
22977 when 
22978 \emph on
22979 -mds390
22980 \emph default
22981  is used
22982 \end_layout
22983
22984 \end_inset
22985 </cell>
22986 </row>
22987 </lyxtabular>
22988
22989 \end_inset
22990
22991
22992 \end_layout
22993
22994 \begin_layout Chapter
22995 Notes on supported Processors
22996 \end_layout
22997
22998 \begin_layout Section
22999 MCS51 variants
23000 \begin_inset LatexCommand \label{sub:MCS51-variants}
23001
23002 \end_inset
23003
23004
23005 \begin_inset LatexCommand \index{MCS51 variants}
23006
23007 \end_inset
23008
23009
23010 \end_layout
23011
23012 \begin_layout Standard
23013 MCS51 processors are available from many vendors and come in many different
23014  flavours.
23015  While they might differ considerably in respect to Special Function Registers
23016  the core MCS51 is usually not modified or is kept compatible.
23017  
23018 \end_layout
23019
23020 \begin_layout Subsection
23021 pdata access by SFR 
23022 \end_layout
23023
23024 \begin_layout Standard
23025 With the upcome of devices with internal xdata and flash memory devices
23026  using port P2
23027 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
23028
23029 \end_inset
23030
23031  as dedicated I/O port is becoming more popular.
23032  Switching the high byte for pdata
23033 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
23034
23035 \end_inset
23036
23037  access which was formerly done by port P2 is then achieved by a Special
23038  Function Register
23039 \begin_inset LatexCommand \index{sfr}
23040
23041 \end_inset
23042
23043 .
23044  In well-established MCS51 tradition the address of this 
23045 \emph on
23046 sfr
23047 \emph default
23048  is where the chip designers decided to put it.
23049  Needless to say that they didn't agree on a common name either.
23050  So that the startup code can correctly initialize xdata variables, you
23051  should define an sfr with the name _XPAGE
23052 \family typewriter
23053
23054 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
23055
23056 \end_inset
23057
23058
23059 \family default
23060  at the appropriate location if the default, port P2, is not used for this.
23061  Some examples are:
23062 \end_layout
23063
23064 \begin_layout Verse
23065
23066 \family typewriter
23067 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
23068  MPAGE */
23069 \end_layout
23070
23071 \begin_layout Verse
23072
23073 \family typewriter
23074 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
23075  a.k.a.
23076  MPAGE */
23077 \end_layout
23078
23079 \begin_layout Verse
23080
23081 \family typewriter
23082 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
23083  XPAGE */
23084 \end_layout
23085
23086 \begin_layout Verse
23087
23088 \family typewriter
23089 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23090  EMI0CN */
23091 \end_layout
23092
23093 \begin_layout Verse
23094
23095 \family typewriter
23096 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23097  EMI0CN */
23098 \end_layout
23099
23100 \begin_layout Standard
23101 For more exotic implementations further customizations may be needed.
23102  See section 
23103 \begin_inset LatexCommand \ref{sub:Startup-Code}
23104
23105 \end_inset
23106
23107  for other possibilities.
23108 \end_layout
23109
23110 \begin_layout Subsection
23111 Other Features available by SFR
23112 \end_layout
23113
23114 \begin_layout Standard
23115 Some MCS51 variants offer features like Double DPTR
23116 \begin_inset LatexCommand \index{DPTR}
23117
23118 \end_inset
23119
23120 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
23121  These are currently not used for the MCS51 port.
23122  If you absolutely need them you can fall back to inline assembly or submit
23123  a patch to SDCC.
23124 \begin_inset VSpace bigskip
23125 \end_inset
23126
23127
23128 \end_layout
23129
23130 \begin_layout Section
23131 DS400 port
23132 \end_layout
23133
23134 \begin_layout Standard
23135 The DS80C400
23136 \begin_inset LatexCommand \index{DS80C400}
23137
23138 \end_inset
23139
23140
23141 \begin_inset LatexCommand \index{DS400}
23142
23143 \end_inset
23144
23145  microcontroller has a rich set of peripherals.
23146  In its built-in ROM library it includes functions to access some of the
23147  features, among them is a TCP stack with IP4 and IP6 support.
23148  Library headers (currently in beta status) and other files are provided
23149  at 
23150 \size footnotesize
23151
23152 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23153
23154 \end_inset
23155
23156 .
23157  
23158 \begin_inset VSpace bigskip
23159 \end_inset
23160
23161
23162 \end_layout
23163
23164 \begin_layout Section
23165 The Z80 and gbz80 port
23166 \end_layout
23167
23168 \begin_layout Standard
23169 SDCC can target both the Zilog Z80
23170 \begin_inset LatexCommand \index{Z80}
23171
23172 \end_inset
23173
23174  and the Nintendo Gameboy's Z80-like gbz80
23175 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23176
23177 \end_inset
23178
23179 .
23180  The Z80 port is passed through the same 
23181 \emph on
23182 regressions tests
23183 \begin_inset LatexCommand \index{Regression test}
23184
23185 \end_inset
23186
23187
23188 \emph default
23189  (see section 
23190 \begin_inset LatexCommand \ref{sec:Quality-control}
23191
23192 \end_inset
23193
23194 ) as the MCS51 and DS390 ports, so floating point support, support for long
23195  variables and bitfield support is fine.
23196  See mailing lists and forums about interrupt routines.
23197 \end_layout
23198
23199 \begin_layout Standard
23200 As always, the code is the authoritative reference - see z80/ralloc.c and
23201  z80/gen.c.
23202  The stack
23203 \begin_inset LatexCommand \index{Z80!stack}
23204
23205 \end_inset
23206
23207  frame is similar to that generated by the IAR Z80 compiler.
23208  IX is used as the base pointer, HL and IY are used as a temporary registers,
23209  and BC and DE are available for holding variables.
23210  Return values
23211 \begin_inset LatexCommand \index{Z80!return value}
23212
23213 \end_inset
23214
23215  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23216  bytes).
23217  The gbz80 port use the same set of registers for the return values, but
23218  in a different order of significance: E (one byte), DE (two bytes), or
23219  HLDE (four bytes).
23220 \begin_inset VSpace bigskip
23221 \end_inset
23222
23223
23224 \end_layout
23225
23226 \begin_layout Section
23227 The HC08 port
23228 \end_layout
23229
23230 \begin_layout Standard
23231 The port to the Freescale/Motorola HC08
23232 \begin_inset LatexCommand \index{HC08}
23233
23234 \end_inset
23235
23236  family has been added in October 2003, and is still undergoing some basic
23237  development.
23238  The code generator is complete, but the register allocation is still quite
23239  unoptimized.
23240  Some of the SDCC's standard C library functions have embedded non-HC08
23241  inline assembly and so are not yet usable.
23242 \end_layout
23243
23244 \begin_layout Standard
23245 The HC08 port passes the regression test suite (see section 
23246 \begin_inset LatexCommand \ref{sec:Quality-control}
23247
23248 \end_inset
23249
23250 ).
23251 \begin_inset VSpace bigskip
23252 \end_inset
23253
23254
23255 \newpage
23256
23257 \end_layout
23258
23259 \begin_layout Section
23260 The PIC14
23261 \begin_inset LatexCommand \index{PIC14}
23262
23263 \end_inset
23264
23265  port
23266 \end_layout
23267
23268 \begin_layout Standard
23269 The PIC14 port adds support for Microchip
23270 \begin_inset LatexCommand \index{Microchip}
23271
23272 \end_inset
23273
23274
23275 \begin_inset Formula $^{\text{TM}}$
23276 \end_inset
23277
23278  PIC
23279 \begin_inset LatexCommand \index{PIC14}
23280
23281 \end_inset
23282
23283
23284 \begin_inset Formula $^{\text{TM}}$
23285 \end_inset
23286
23287  MCUs with 14 bit wide instructions.
23288  This port is not yet mature and still lacks many features.
23289  However, it can work for simple code.
23290 \end_layout
23291
23292 \begin_layout Standard
23293 Currently supported devices include:
23294 \end_layout
23295
23296 \begin_layout Standard
23297 12F: 629, 635, 675, 683
23298 \end_layout
23299
23300 \begin_layout Standard
23301 16C: 432, 433
23302 \end_layout
23303
23304 \begin_layout Standard
23305 16C: 554, 557, 558
23306 \end_layout
23307
23308 \begin_layout Standard
23309 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23310 \end_layout
23311
23312 \begin_layout Standard
23313 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23314  781, 782
23315 \end_layout
23316
23317 \begin_layout Standard
23318 16C: 925, 926
23319 \end_layout
23320
23321 \begin_layout Standard
23322 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
23323  689, 690
23324 \end_layout
23325
23326 \begin_layout Standard
23327 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
23328 \end_layout
23329
23330 \begin_layout Standard
23331 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23332  877, 877a, 88
23333 \end_layout
23334
23335 \begin_layout Standard
23336 16F: 913, 914, 916, 917
23337 \end_layout
23338
23339 \begin_layout Standard
23340 An up-to-date list of currently supported devices can be obtained via 
23341 \family typewriter
23342 sdcc -mpic14 -phelp foo.c
23343 \family default
23344  (foo.c must exist...).
23345 \end_layout
23346
23347 \begin_layout Subsection
23348 PIC Code Pages
23349 \begin_inset LatexCommand \index{code page (pic14)}
23350
23351 \end_inset
23352
23353  and Memory Banks
23354 \begin_inset LatexCommand \index{Memory bank (pic14)}
23355
23356 \end_inset
23357
23358
23359 \end_layout
23360
23361 \begin_layout Standard
23362 The linker organizes allocation for the code page and RAM banks.
23363  It does not have intimate knowledge of the code flow.
23364  It will put all the code section of a single .asm file into a single code
23365  page.
23366  In order to make use of multiple code pages, separate asm files must be
23367  used.
23368  The compiler assigns all 
23369 \emph on
23370 static
23371 \emph default
23372  functions of a single .c file into the same code page.
23373 \newline
23374
23375 \newline
23376 To get the best results,
23377  follow these guidelines:
23378 \end_layout
23379
23380 \begin_layout Enumerate
23381 Make local functions static, as non static functions require code page selection
23382  overhead.
23383 \newline
23384 Due to the way sdcc handles functions, place called functions prior
23385  to calling functions in the file wherever possible: Otherwise sdcc will
23386  insert unneccessary pagesel directives around the call, believing that
23387  the called function is externally defined.
23388 \end_layout
23389
23390 \begin_layout Enumerate
23391 For devices that have multiple code pages it is more efficient to use the
23392  same number of files as pages: Use up to 4 separate .c files for the 16F877,
23393  but only 2 files for the 16F874.
23394  This way the linker can put the code for each file into different code
23395  pages and there will be less page selection overhead.
23396 \end_layout
23397
23398 \begin_layout Enumerate
23399 And as for any 8 bit micro (especially for PIC14 as they have a very simple
23400  instruction set), use `unsigned char' wherever possible instead of `int'.
23401 \end_layout
23402
23403 \begin_layout Subsection
23404 Adding New Devices to the Port 
23405 \end_layout
23406
23407 \begin_layout Standard
23408 Adding support for a new 14
23409 \begin_inset ERT
23410 status open
23411
23412 \begin_layout Standard
23413
23414
23415 \backslash
23416 ,
23417 \end_layout
23418
23419 \end_inset
23420
23421 bit PIC MCU requires the following steps:
23422 \end_layout
23423
23424 \begin_layout Enumerate
23425 Create a new device description.
23426 \newline
23427 Each device is described in two files: pic16f*.h
23428  and pic16f*.c.
23429  These files primarily define SFRs, structs to access their bits, and symbolic
23430  configuration options.
23431  Both files can be generated from gputils' .inc files using the perl script
23432  
23433 \family typewriter
23434 support/scripts/inc2h.pl
23435 \family default
23436 .
23437  This file also contains further instructions on how to proceed.
23438 \end_layout
23439
23440 \begin_layout Enumerate
23441 Copy the .h file into SDCC's include path and either add the .c file to your
23442  project or copy it to 
23443 \family typewriter
23444 device/lib/pic/libdev
23445 \family default
23446 .
23447  Afterwards, rebuild and install the libraries.
23448 \end_layout
23449
23450 \begin_layout Enumerate
23451 Edit pic14devices.txt in SDCC's include path (
23452 \family typewriter
23453 device/include/pic/
23454 \family default
23455  in the source tree or 
23456 \family typewriter
23457 /usr/local/share/sdcc/include/pic
23458 \family default
23459  after installation).
23460 \newline
23461 You need to add a device specification here to make
23462  the memory layout (code banks, RAM, aliased memory regions, ...) known to
23463  the compiler.
23464  Probably you can copy and modify an existing entry.
23465  The file format is documented at the top of the file.
23466 \end_layout
23467
23468 \begin_layout Subsection
23469 Interrupt Code
23470 \end_layout
23471
23472 \begin_layout Standard
23473 For the interrupt function, use the keyword `__interrupt'
23474 \begin_inset LatexCommand \index{PIC14!interrupt}
23475
23476 \end_inset
23477
23478  with level number of 0 (PIC14 only has 1 interrupt so this number is only
23479  there to avoid a syntax error - it ought to be fixed).
23480  E.g.:
23481 \end_layout
23482
23483 \begin_layout Verse
23484
23485 \family typewriter
23486 void Intr(void) __interrupt 0
23487 \newline
23488 {
23489 \newline
23490 \InsetSpace ~
23491 \InsetSpace ~
23492 T0IF = 0; /* Clear timer interrupt */
23493 \newline
23494 }
23495 \end_layout
23496
23497 \begin_layout Subsection
23498 Linking and Assembling
23499 \end_layout
23500
23501 \begin_layout Standard
23502 For assembling you can use either GPUTILS'
23503 \begin_inset LatexCommand \index{gputils (pic tools)}
23504
23505 \end_inset
23506
23507  gpasm.exe or MPLAB's mpasmwin.exe.
23508  GPUTILS are available from 
23509 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23510
23511 \end_inset
23512
23513 .
23514  For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
23515  If you use MPLAB and an interrupt function then the linker script file
23516  vectors section will need to be enlarged to link with mplink.
23517 \newline
23518
23519 \newline
23520 Here is a 
23521 \family typewriter
23522 Makefile
23523 \family default
23524  using GPUTILS:
23525 \end_layout
23526
23527 \begin_layout Verse
23528
23529 \family typewriter
23530 .c.o:
23531 \newline
23532 \InsetSpace ~
23533 \InsetSpace ~
23534 \InsetSpace ~
23535 \InsetSpace ~
23536 \InsetSpace ~
23537 \InsetSpace ~
23538 \InsetSpace ~
23539 \InsetSpace ~
23540 sdcc -V -mpic14 -p16f877 -c $< 
23541 \newline
23542
23543 \newline
23544 $(PRJ).hex: $(OBJS) 
23545 \newline
23546 \InsetSpace ~
23547 \InsetSpace ~
23548 \InsetSpace ~
23549 \InsetSpace ~
23550 \InsetSpace ~
23551 \InsetSpace ~
23552 \InsetSpace ~
23553 \InsetSpace ~
23554 gplink -m -s $(PRJ).lkr
23555  -o $(PRJ).hex $(OBJS) libsdcc.lib
23556 \end_layout
23557
23558 \begin_layout Standard
23559 Here is a 
23560 \family typewriter
23561 Makefile
23562 \family default
23563  using MPLAB:
23564 \end_layout
23565
23566 \begin_layout Verse
23567
23568 \family typewriter
23569 .c.o: 
23570 \newline
23571 \InsetSpace ~
23572 \InsetSpace ~
23573 \InsetSpace ~
23574 \InsetSpace ~
23575 \InsetSpace ~
23576 \InsetSpace ~
23577 \InsetSpace ~
23578 \InsetSpace ~
23579 sdcc -S -V -mpic14 -p16f877 $< 
23580 \newline
23581 \InsetSpace ~
23582 \InsetSpace ~
23583 \InsetSpace ~
23584 \InsetSpace ~
23585 \InsetSpace ~
23586 \InsetSpace ~
23587 \InsetSpace ~
23588 \InsetSpace ~
23589 mpasmwin /q /o $*.asm
23590 \newline
23591
23592 \newline
23593 $(PRJ).hex: $(OBJS)
23594  
23595 \newline
23596 \InsetSpace ~
23597 \InsetSpace ~
23598 \InsetSpace ~
23599 \InsetSpace ~
23600 \InsetSpace ~
23601 \InsetSpace ~
23602 \InsetSpace ~
23603 \InsetSpace ~
23604 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
23605 \end_layout
23606
23607 \begin_layout Standard
23608 Please note that indentations within a
23609 \family typewriter
23610  Makefile
23611 \family default
23612  have to be done with a tabulator character.
23613 \end_layout
23614
23615 \begin_layout Subsection
23616 Command-Line Options
23617 \end_layout
23618
23619 \begin_layout Standard
23620 Besides the switches common to all SDCC backends, the PIC14 port accepts
23621  the following options (for an updated list see sdcc -
23622 \begin_inset ERT
23623 status collapsed
23624
23625 \begin_layout Standard
23626
23627
23628 \backslash
23629 /
23630 \end_layout
23631
23632 \end_inset
23633
23634 -help):
23635 \end_layout
23636
23637 \begin_layout Description
23638 -
23639 \begin_inset ERT
23640 status collapsed
23641
23642 \begin_layout Standard
23643
23644
23645 \backslash
23646 /
23647 \end_layout
23648
23649 \end_inset
23650
23651 -debug-xtra
23652 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
23653
23654 \end_inset
23655
23656  emit debug info in assembly output
23657 \end_layout
23658
23659 \begin_layout Description
23660 -
23661 \begin_inset ERT
23662 status collapsed
23663
23664 \begin_layout Standard
23665
23666
23667 \backslash
23668 /
23669 \end_layout
23670
23671 \end_inset
23672
23673 -no-pcode-opt
23674 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
23675
23676 \end_inset
23677
23678  disable (slightly faulty) optimization on pCode
23679 \end_layout
23680
23681 \begin_layout Description
23682 -
23683 \begin_inset ERT
23684 status collapsed
23685
23686 \begin_layout Standard
23687
23688
23689 \backslash
23690 /
23691 \end_layout
23692
23693 \end_inset
23694
23695 -stack-loc
23696 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
23697
23698 \end_inset
23699
23700  sets the lowest address of the argument passing stack (defaults to a suitably
23701  large shared databank to reduce BANKSEL overhead)
23702 \end_layout
23703
23704 \begin_layout Description
23705 -
23706 \begin_inset ERT
23707 status collapsed
23708
23709 \begin_layout Standard
23710
23711
23712 \backslash
23713 /
23714 \end_layout
23715
23716 \end_inset
23717
23718 -stack-size
23719 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
23720
23721 \end_inset
23722
23723  sets the size if the argument passing stack (default: 16, minimum: 4)
23724 \end_layout
23725
23726 \begin_layout Subsection
23727 Environment Variables
23728 \end_layout
23729
23730 \begin_layout Standard
23731 The PIC14 port recognizes the following environment variables:
23732 \end_layout
23733
23734 \begin_layout Description
23735 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
23736  register (the ones called r0xNNNN) in a section of its own.
23737  By default (if this variable is unset), sdcc tries to cluster registers
23738  in sections in order to reduce the BANKSEL overhead when accessing them.
23739 \end_layout
23740
23741 \begin_layout Subsection
23742 The Library
23743 \end_layout
23744
23745 \begin_layout Standard
23746 The PIC14 library currently only contains support routines required by the
23747  compiler to implement multiplication, division, and floating point support.
23748  No libc-like replacement is available at the moment, though many of the
23749  common sdcc library sources (in 
23750 \family typewriter
23751 device/lib
23752 \family default
23753 ) should also compile with the PIC14 port.
23754 \end_layout
23755
23756 \begin_layout Subsubsection
23757 error: missing definition for symbol ``__gptrget1''
23758 \end_layout
23759
23760 \begin_layout Standard
23761 The PIC14 port uses library routines to provide more complex operations
23762  like multiplication, division/modulus and (generic) pointer dereferencing.
23763  In order to add these routines to your project, you must link with PIC14's
23764  
23765 \family typewriter
23766 libsdcc.lib
23767 \family default
23768 .
23769  For single source file projects this is done automatically, more complex
23770  projects must add 
23771 \family typewriter
23772 libsdcc.lib
23773 \family default
23774  to the linker's arguments.
23775  Make sure you also add an include path for the library (using the -I switch
23776  to the linker)!
23777 \end_layout
23778
23779 \begin_layout Subsubsection
23780 Processor mismatch in file ``XXX''.
23781 \end_layout
23782
23783 \begin_layout Standard
23784 This warning can usually be ignored due to the very good compatibility amongst
23785  14
23786 \begin_inset ERT
23787 status open
23788
23789 \begin_layout Standard
23790
23791
23792 \backslash
23793 ,
23794 \end_layout
23795
23796 \end_inset
23797
23798 bit PIC
23799 \begin_inset LatexCommand \index{PIC14}
23800
23801 \end_inset
23802
23803  devices.
23804 \end_layout
23805
23806 \begin_layout Standard
23807 You might also consider recompiling the library for your specific device
23808  by changing the ARCH=p16f877 (default target) entry in 
23809 \family typewriter
23810 device/lib/pic/Makefile.in
23811 \family default
23812  and 
23813 \family typewriter
23814 device/lib/pic/Makefile
23815 \family default
23816  to reflect your device.
23817  This might even improve performance for smaller devices as unneccesary
23818  BANKSELs might be removed.
23819 \end_layout
23820
23821 \begin_layout Subsection
23822 Known Bugs
23823 \end_layout
23824
23825 \begin_layout Subsubsection
23826 Function arguments
23827 \end_layout
23828
23829 \begin_layout Standard
23830 Functions with variable argument lists (like printf) are not yet supported.
23831  Similarly, taking the argument of the first argument passed into a function
23832  does not work: It is currently passed in WREG and has no address...
23833 \end_layout
23834
23835 \begin_layout Subsubsection
23836 Regression tests fail
23837 \end_layout
23838
23839 \begin_layout Standard
23840 Though the small subset of regression tests in src/regression passes, SDCC
23841  regression test suite does not, indicating that there are still major bugs
23842  in the port.
23843  However, many smaller projects have successfully used SDCC in the past...
23844 \end_layout
23845
23846 \begin_layout Standard
23847
23848 \size footnotesize
23849
23850 \newpage
23851
23852 \end_layout
23853
23854 \begin_layout Section
23855 The PIC16
23856 \begin_inset LatexCommand \index{PIC16}
23857
23858 \end_inset
23859
23860  port
23861 \end_layout
23862
23863 \begin_layout Standard
23864 The PIC16 port adds support for Microchip
23865 \begin_inset LatexCommand \index{Microchip}
23866
23867 \end_inset
23868
23869
23870 \begin_inset Formula $^{\text{TM}}$
23871 \end_inset
23872
23873  PIC
23874 \begin_inset LatexCommand \index{PIC}
23875
23876 \end_inset
23877
23878
23879 \begin_inset Formula $^{\text{TM}}$
23880 \end_inset
23881
23882  MCUs with 16 bit wide instructions.
23883  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
23884 ; devices supported by the port include:
23885 \end_layout
23886
23887 \begin_layout Standard
23888 18F: 242, 248, 252, 258, 442, 448, 452, 458
23889 \end_layout
23890
23891 \begin_layout Standard
23892 18F: 1220, 1320
23893 \end_layout
23894
23895 \begin_layout Standard
23896 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 24j10, 2525, 2550, 25j10,
23897  2620
23898 \end_layout
23899
23900 \begin_layout Standard
23901 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 44j10, 4520, 4525, 4550,
23902  45j10, 4620
23903 \end_layout
23904
23905 \begin_layout Standard
23906 18F: 6520, 6620, 6680, 6720
23907 \end_layout
23908
23909 \begin_layout Standard
23910 18F: 8520, 8620, 8680, 8720
23911 \end_layout
23912
23913 \begin_layout Subsection
23914 Global Options
23915 \end_layout
23916
23917 \begin_layout Standard
23918 PIC16 port supports the standard command line arguments as supposed, with
23919  the exception of certain cases that will be mentioned in the following
23920  list:
23921 \end_layout
23922
23923 \begin_layout Description
23924 -
23925 \begin_inset ERT
23926 status collapsed
23927
23928 \begin_layout Standard
23929
23930
23931 \backslash
23932 /
23933 \end_layout
23934
23935 \end_inset
23936
23937 -callee-saves
23938 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23939
23940 \end_inset
23941
23942  See -
23943 \begin_inset ERT
23944 status collapsed
23945
23946 \begin_layout Standard
23947
23948
23949 \backslash
23950 /
23951 \end_layout
23952
23953 \end_inset
23954
23955 -all-callee-saves
23956 \end_layout
23957
23958 \begin_layout Description
23959 -
23960 \begin_inset ERT
23961 status collapsed
23962
23963 \begin_layout Standard
23964
23965
23966 \backslash
23967 /
23968 \end_layout
23969
23970 \end_inset
23971
23972 -fommit-frame-pointer
23973 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23974
23975 \end_inset
23976
23977  Frame pointer will be omitted when the function uses no local variables.
23978 \end_layout
23979
23980 \begin_layout Subsection
23981 Port Specific Options
23982 \begin_inset LatexCommand \index{Options PIC16}
23983
23984 \end_inset
23985
23986
23987 \end_layout
23988
23989 \begin_layout Standard
23990 The port specific options appear after the global options in the sdcc -
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 -help output.
24004 \end_layout
24005
24006 \begin_layout Subsubsection
24007 Code Generation Options
24008 \end_layout
24009
24010 \begin_layout Standard
24011 These options influence the generated assembler code.
24012 \end_layout
24013
24014 \begin_layout Description
24015 -
24016 \begin_inset ERT
24017 status collapsed
24018
24019 \begin_layout Standard
24020
24021
24022 \backslash
24023 /
24024 \end_layout
24025
24026 \end_inset
24027
24028 -pstack-model=[model] Used in conjuction with the command above.
24029  Defines the stack model to be used, valid stack models are:
24030 \end_layout
24031
24032 \begin_deeper
24033 \begin_layout List
24034 \labelwidthstring 00.00.0000
24035
24036 \emph on
24037 small
24038 \emph default
24039  Selects small stack model.
24040  8 bit stack and frame pointers.
24041  Supports 256 bytes stack size.
24042 \end_layout
24043
24044 \begin_layout List
24045 \labelwidthstring 00.00.0000
24046
24047 \emph on
24048 large
24049 \emph default
24050  Selects large stack model.
24051  16 bit stack and frame pointers.
24052  Supports 65536 bytes stack size.
24053 \end_layout
24054
24055 \end_deeper
24056 \begin_layout Description
24057 -
24058 \begin_inset ERT
24059 status collapsed
24060
24061 \begin_layout Standard
24062
24063
24064 \backslash
24065 /
24066 \end_layout
24067
24068 \end_inset
24069
24070 -pno-banksel Do not generate BANKSEL assembler directives.
24071 \end_layout
24072
24073 \begin_layout Description
24074 -
24075 \begin_inset ERT
24076 status collapsed
24077
24078 \begin_layout Standard
24079
24080
24081 \backslash
24082 /
24083 \end_layout
24084
24085 \end_inset
24086
24087 -extended Enable extended instruction set/literal offset addressing mode.
24088  Use with care!
24089 \end_layout
24090
24091 \begin_layout Subsubsection
24092 Optimization Options
24093 \end_layout
24094
24095 \begin_layout Description
24096 -
24097 \begin_inset ERT
24098 status collapsed
24099
24100 \begin_layout Standard
24101
24102
24103 \backslash
24104 /
24105 \end_layout
24106
24107 \end_inset
24108
24109 -obanksel=n Set optimization level for inserting BANKSELs.
24110 \newline
24111
24112 \end_layout
24113
24114 \begin_deeper
24115 \begin_layout List
24116 \labelwidthstring 00.00.0000
24117 0 no optimization
24118 \end_layout
24119
24120 \begin_layout List
24121 \labelwidthstring 00.00.0000
24122 1 checks previous used register and if it is the same then does not emit
24123  BANKSEL, accounts only for labels.
24124 \end_layout
24125
24126 \begin_layout List
24127 \labelwidthstring 00.00.0000
24128 2 tries to check the location of (even different) symbols and removes BANKSELs
24129  if they are in the same bank.
24130  
24131 \newline
24132
24133 \emph on
24134 Important: There might be problems if the linker script has data sections
24135  across bank borders!
24136 \end_layout
24137
24138 \end_deeper
24139 \begin_layout Description
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 -denable-peeps Force the usage of peepholes.
24154  Use with care.
24155 \end_layout
24156
24157 \begin_layout Description
24158 -
24159 \begin_inset ERT
24160 status collapsed
24161
24162 \begin_layout Standard
24163
24164
24165 \backslash
24166 /
24167 \end_layout
24168
24169 \end_inset
24170
24171 -optimize-goto Try to use (conditional) BRA instead of GOTO.
24172 \end_layout
24173
24174 \begin_layout Description
24175 -
24176 \begin_inset ERT
24177 status collapsed
24178
24179 \begin_layout Standard
24180
24181
24182 \backslash
24183 /
24184 \end_layout
24185
24186 \end_inset
24187
24188 -optimize-cmp Try to optimize some compares.
24189 \end_layout
24190
24191 \begin_layout Description
24192 -
24193 \begin_inset ERT
24194 status collapsed
24195
24196 \begin_layout Standard
24197
24198
24199 \backslash
24200 /
24201 \end_layout
24202
24203 \end_inset
24204
24205 -optimize-df Analyze the dataflow of the generated code and improve it.
24206 \end_layout
24207
24208 \begin_layout Subsubsection
24209 Assembling Options
24210 \end_layout
24211
24212 \begin_layout Description
24213 -
24214 \begin_inset ERT
24215 status collapsed
24216
24217 \begin_layout Standard
24218
24219
24220 \backslash
24221 /
24222 \end_layout
24223
24224 \end_inset
24225
24226 -asm= Sets the full path and name of an external assembler to call.
24227 \end_layout
24228
24229 \begin_layout Description
24230 -
24231 \begin_inset ERT
24232 status collapsed
24233
24234 \begin_layout Standard
24235
24236
24237 \backslash
24238 /
24239 \end_layout
24240
24241 \end_inset
24242
24243 -mplab-comp MPLAB
24244 \begin_inset LatexCommand \index{PIC16!MPLAB}
24245
24246 \end_inset
24247
24248  compatibility option.
24249  Currently only suppresses special gpasm directives.
24250 \end_layout
24251
24252 \begin_layout Subsubsection
24253 Linking Options
24254 \end_layout
24255
24256 \begin_layout Description
24257 -
24258 \begin_inset ERT
24259 status collapsed
24260
24261 \begin_layout Standard
24262
24263
24264 \backslash
24265 /
24266 \end_layout
24267
24268 \end_inset
24269
24270 -link= Sets the full path and name of an external linker to call.
24271 \end_layout
24272
24273 \begin_layout Description
24274 -
24275 \begin_inset ERT
24276 status collapsed
24277
24278 \begin_layout Standard
24279
24280
24281 \backslash
24282 /
24283 \end_layout
24284
24285 \end_inset
24286
24287 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24288  unitialized data variables with [kword].
24289  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24290 \end_layout
24291
24292 \begin_layout Description
24293 -
24294 \begin_inset ERT
24295 status collapsed
24296
24297 \begin_layout Standard
24298
24299
24300 \backslash
24301 /
24302 \end_layout
24303
24304 \end_inset
24305
24306 -ivt-loc=n Place the interrupt vector table at address 
24307 \emph on
24308 n
24309 \emph default
24310 .
24311  Useful for bootloaders.
24312 \end_layout
24313
24314 \begin_layout Description
24315 -
24316 \begin_inset ERT
24317 status collapsed
24318
24319 \begin_layout Standard
24320
24321
24322 \backslash
24323 /
24324 \end_layout
24325
24326 \end_inset
24327
24328 -nodefaultlibs Do not link default libraries when linking.
24329 \end_layout
24330
24331 \begin_layout Description
24332 -
24333 \begin_inset ERT
24334 status collapsed
24335
24336 \begin_layout Standard
24337
24338
24339 \backslash
24340 /
24341 \end_layout
24342
24343 \end_inset
24344
24345 -use-crt= Use a custom run-time module instead of the defaults.
24346 \end_layout
24347
24348 \begin_layout Description
24349 -
24350 \begin_inset ERT
24351 status collapsed
24352
24353 \begin_layout Standard
24354
24355
24356 \backslash
24357 /
24358 \end_layout
24359
24360 \end_inset
24361
24362 -no-crt Don't link the default run-time modules
24363 \end_layout
24364
24365 \begin_layout Subsubsection
24366 Debugging Options
24367 \end_layout
24368
24369 \begin_layout Standard
24370 Debugging options enable extra debugging information in the output files.
24371 \end_layout
24372
24373 \begin_layout Description
24374 -
24375 \begin_inset ERT
24376 status collapsed
24377
24378 \begin_layout Standard
24379
24380
24381 \backslash
24382 /
24383 \end_layout
24384
24385 \end_inset
24386
24387 -debug-xtra Similar to -
24388 \begin_inset ERT
24389 status collapsed
24390
24391 \begin_layout Standard
24392
24393
24394 \backslash
24395 /
24396 \end_layout
24397
24398 \end_inset
24399
24400 -debug
24401 \begin_inset LatexCommand \index{-\/-debug}
24402
24403 \end_inset
24404
24405 , but dumps more information.
24406 \end_layout
24407
24408 \begin_layout Description
24409 -
24410 \begin_inset ERT
24411 status collapsed
24412
24413 \begin_layout Standard
24414
24415
24416 \backslash
24417 /
24418 \end_layout
24419
24420 \end_inset
24421
24422 -debug-ralloc Force register allocator to dump <source>.d file with debugging
24423  information.
24424  <source> is the name of the file being compiled.
24425 \end_layout
24426
24427 \begin_layout Description
24428 -
24429 \begin_inset ERT
24430 status collapsed
24431
24432 \begin_layout Standard
24433
24434
24435 \backslash
24436 /
24437 \end_layout
24438
24439 \end_inset
24440
24441 -pcode-verbose Enable pcode debugging information in translation.
24442 \end_layout
24443
24444 \begin_layout Description
24445 -
24446 \begin_inset ERT
24447 status collapsed
24448
24449 \begin_layout Standard
24450
24451
24452 \backslash
24453 /
24454 \end_layout
24455
24456 \end_inset
24457
24458 -calltree Dump call tree in .calltree file.
24459 \end_layout
24460
24461 \begin_layout Description
24462 -
24463 \begin_inset ERT
24464 status collapsed
24465
24466 \begin_layout Standard
24467
24468
24469 \backslash
24470 /
24471 \end_layout
24472
24473 \end_inset
24474
24475 -gstack Trace push/pops for stack pointer overflow.
24476 \end_layout
24477
24478 \begin_layout Subsection
24479 Enviroment Variables
24480 \end_layout
24481
24482 \begin_layout Standard
24483 There is a number of enviromental variables that can be used when running
24484  SDCC to enable certain optimizations or force a specific program behaviour.
24485  these variables are primarily for debugging purposes so they can be enabled/dis
24486 abled at will.
24487 \end_layout
24488
24489 \begin_layout Standard
24490 Currently there is only two such variables available:
24491 \end_layout
24492
24493 \begin_layout Description
24494 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
24495  bitfields is optimized by directly loading FSR0 with the address of the
24496  bitfield structure.
24497  Normally SDCC will cast the bitfield structure to a bitfield pointer and
24498  then load FSR0.
24499  This step saves data ram and code space for functions that make heavy use
24500  of bitfields.
24501  (i.e., 80 bytes of code space are saved when compiling malloc.c with this
24502  option).
24503  
24504 \end_layout
24505
24506 \begin_layout Description
24507 NO_REG_OPT Do not perform pCode registers optimization.
24508  This should be used for debugging purposes.
24509  If bugs in the pcode optimizer are found, users can benefit from temporarily
24510  disabling the optimizer until the bug is fixed.
24511 \end_layout
24512
24513 \begin_layout Subsection
24514 Preprocessor Macros
24515 \end_layout
24516
24517 \begin_layout Standard
24518 PIC16
24519 \begin_inset LatexCommand \index{PIC16}
24520
24521 \end_inset
24522
24523  port defines the following preprocessor macros while translating a source.
24524 \end_layout
24525
24526 \begin_layout Standard
24527 \align center
24528 \begin_inset Tabular
24529 <lyxtabular version="3" rows="6" columns="2">
24530 <features>
24531 <column alignment="center" valignment="top" leftline="true" width="0">
24532 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24533 <row topline="true" bottomline="true">
24534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24535 \begin_inset Text
24536
24537 \begin_layout Standard
24538 Macro
24539 \end_layout
24540
24541 \end_inset
24542 </cell>
24543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24544 \begin_inset Text
24545
24546 \begin_layout Standard
24547 Description
24548 \end_layout
24549
24550 \end_inset
24551 </cell>
24552 </row>
24553 <row topline="true">
24554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24555 \begin_inset Text
24556
24557 \begin_layout Standard
24558 SDCC_pic16
24559 \end_layout
24560
24561 \end_inset
24562 </cell>
24563 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24564 \begin_inset Text
24565
24566 \begin_layout Standard
24567 Port identification
24568 \end_layout
24569
24570 \end_inset
24571 </cell>
24572 </row>
24573 <row topline="true">
24574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24575 \begin_inset Text
24576
24577 \begin_layout Standard
24578 _
24579 \begin_inset ERT
24580 status collapsed
24581
24582 \begin_layout Standard
24583
24584
24585 \backslash
24586 /
24587 \end_layout
24588
24589 \end_inset
24590
24591 _pic16
24592 \end_layout
24593
24594 \end_inset
24595 </cell>
24596 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24597 \begin_inset Text
24598
24599 \begin_layout Standard
24600 Port identification (same as above)
24601 \end_layout
24602
24603 \end_inset
24604 </cell>
24605 </row>
24606 <row topline="true">
24607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24608 \begin_inset Text
24609
24610 \begin_layout Standard
24611 pic18fxxxx
24612 \end_layout
24613
24614 \end_inset
24615 </cell>
24616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24617 \begin_inset Text
24618
24619 \begin_layout Standard
24620 MCU Identification.
24621  
24622 \emph on
24623 xxxx
24624 \emph default
24625  is the microcontrol identification number, i.e.
24626  452, 6620, etc
24627 \end_layout
24628
24629 \end_inset
24630 </cell>
24631 </row>
24632 <row topline="true">
24633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24634 \begin_inset Text
24635
24636 \begin_layout Standard
24637 _
24638 \begin_inset ERT
24639 status collapsed
24640
24641 \begin_layout Standard
24642
24643
24644 \backslash
24645 /
24646 \end_layout
24647
24648 \end_inset
24649
24650 _18Fxxxx
24651 \end_layout
24652
24653 \end_inset
24654 </cell>
24655 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24656 \begin_inset Text
24657
24658 \begin_layout Standard
24659 MCU Identification (same as above)
24660 \end_layout
24661
24662 \end_inset
24663 </cell>
24664 </row>
24665 <row topline="true" bottomline="true">
24666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24667 \begin_inset Text
24668
24669 \begin_layout Standard
24670 STACK_MODEL_nnn
24671 \end_layout
24672
24673 \end_inset
24674 </cell>
24675 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24676 \begin_inset Text
24677
24678 \begin_layout Standard
24679 nnn = SMALL or LARGE respectively according to the stack model used
24680 \end_layout
24681
24682 \end_inset
24683 </cell>
24684 </row>
24685 </lyxtabular>
24686
24687 \end_inset
24688
24689
24690 \end_layout
24691
24692 \begin_layout Standard
24693 In addition the following macros are defined when calling assembler:
24694 \end_layout
24695
24696 \begin_layout Standard
24697 \align center
24698 \begin_inset Tabular
24699 <lyxtabular version="3" rows="4" columns="2">
24700 <features>
24701 <column alignment="center" valignment="top" leftline="true" width="0">
24702 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24703 <row topline="true" bottomline="true">
24704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24705 \begin_inset Text
24706
24707 \begin_layout Standard
24708 Macro
24709 \end_layout
24710
24711 \end_inset
24712 </cell>
24713 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24714 \begin_inset Text
24715
24716 \begin_layout Standard
24717 Description
24718 \end_layout
24719
24720 \end_inset
24721 </cell>
24722 </row>
24723 <row topline="true">
24724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24725 \begin_inset Text
24726
24727 \begin_layout Standard
24728 __18Fxxxx
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 MCU Identification.
24738  
24739 \emph on
24740 xxxx
24741 \emph default
24742  is the microcontrol identification number, i.e.
24743  452, 6620, etc
24744 \end_layout
24745
24746 \end_inset
24747 </cell>
24748 </row>
24749 <row topline="true">
24750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24751 \begin_inset Text
24752
24753 \begin_layout Standard
24754 SDCC_MODEL_nnn
24755 \end_layout
24756
24757 \end_inset
24758 </cell>
24759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24760 \begin_inset Text
24761
24762 \begin_layout Standard
24763 nnn = SMALL or LARGE respectively according to the memory model used for
24764  SDCC
24765 \end_layout
24766
24767 \end_inset
24768 </cell>
24769 </row>
24770 <row topline="true" bottomline="true">
24771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24772 \begin_inset Text
24773
24774 \begin_layout Standard
24775 STACK_MODEL_nnn
24776 \end_layout
24777
24778 \end_inset
24779 </cell>
24780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24781 \begin_inset Text
24782
24783 \begin_layout Standard
24784 nnn = SMALL or LARGE respectively according to the stack model used
24785 \end_layout
24786
24787 \end_inset
24788 </cell>
24789 </row>
24790 </lyxtabular>
24791
24792 \end_inset
24793
24794
24795 \end_layout
24796
24797 \begin_layout Subsection
24798 Directories
24799 \end_layout
24800
24801 \begin_layout Standard
24802 PIC16
24803 \begin_inset LatexCommand \index{PIC16}
24804
24805 \end_inset
24806
24807  port uses the following directories for searching header files and libraries.
24808 \end_layout
24809
24810 \begin_layout Standard
24811 \align center
24812 \begin_inset Tabular
24813 <lyxtabular version="3" rows="3" columns="4">
24814 <features>
24815 <column alignment="center" valignment="top" leftline="true" width="0">
24816 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24817 <column alignment="center" valignment="top" width="0">
24818 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24819 <row topline="true" bottomline="true">
24820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24821 \begin_inset Text
24822
24823 \begin_layout Standard
24824 Directory
24825 \end_layout
24826
24827 \end_inset
24828 </cell>
24829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24830 \begin_inset Text
24831
24832 \begin_layout Standard
24833 Description
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 Target
24843 \end_layout
24844
24845 \end_inset
24846 </cell>
24847 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24848 \begin_inset Text
24849
24850 \begin_layout Standard
24851 Command prefix
24852 \end_layout
24853
24854 \end_inset
24855 </cell>
24856 </row>
24857 <row topline="true">
24858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24859 \begin_inset Text
24860
24861 \begin_layout Standard
24862 PREFIX/sdcc/include/pic16
24863 \end_layout
24864
24865 \end_inset
24866 </cell>
24867 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24868 \begin_inset Text
24869
24870 \begin_layout Standard
24871 PIC16 specific headers
24872 \end_layout
24873
24874 \end_inset
24875 </cell>
24876 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24877 \begin_inset Text
24878
24879 \begin_layout Standard
24880 Compiler
24881 \end_layout
24882
24883 \end_inset
24884 </cell>
24885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24886 \begin_inset Text
24887
24888 \begin_layout Standard
24889 -I
24890 \end_layout
24891
24892 \end_inset
24893 </cell>
24894 </row>
24895 <row topline="true" bottomline="true">
24896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24897 \begin_inset Text
24898
24899 \begin_layout Standard
24900 PREFIX/sdcc/lib/pic16
24901 \end_layout
24902
24903 \end_inset
24904 </cell>
24905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24906 \begin_inset Text
24907
24908 \begin_layout Standard
24909 PIC16 specific libraries
24910 \end_layout
24911
24912 \end_inset
24913 </cell>
24914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24915 \begin_inset Text
24916
24917 \begin_layout Standard
24918 Linker
24919 \end_layout
24920
24921 \end_inset
24922 </cell>
24923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24924 \begin_inset Text
24925
24926 \begin_layout Standard
24927 -L
24928 \end_layout
24929
24930 \end_inset
24931 </cell>
24932 </row>
24933 </lyxtabular>
24934
24935 \end_inset
24936
24937
24938 \end_layout
24939
24940 \begin_layout Subsection
24941 Pragmas
24942 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24943
24944 \end_inset
24945
24946
24947 \end_layout
24948
24949 \begin_layout Standard
24950 The PIC16
24951 \begin_inset LatexCommand \index{PIC16}
24952
24953 \end_inset
24954
24955  port currently supports the following pragmas:
24956 \end_layout
24957
24958 \begin_layout Description
24959 stack
24960 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24961
24962 \end_inset
24963
24964  This forces the code generator to initialize the stack & frame pointers
24965  at a specific address.
24966  This is an ad hoc solution for cases where no STACK directive is available
24967  in the linker script or gplink is not instructed to create a stack section.
24968 \newline
24969 The
24970  stack pragma should be used only once in a project.
24971  Multiple pragmas may result in indeterminate behaviour of the program.
24972 \begin_inset Foot
24973 status open
24974
24975 \begin_layout Standard
24976 The old format (ie.
24977  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24978  cross page boundaries (or even exceed the available data RAM) and crash
24979  the program.
24980  Make sure that stack does not cross page boundaries when using the SMALL
24981  stack model.
24982 \end_layout
24983
24984 \end_inset
24985
24986
24987 \newline
24988 The format is as follows:
24989 \newline
24990
24991 \end_layout
24992
24993 \begin_layout LyX-Code
24994 #pragma stack bottom_address [stack_size]
24995 \newline
24996
24997 \end_layout
24998
24999 \begin_layout Standard
25000
25001 \emph on
25002 bottom_address
25003 \emph default
25004  is the lower bound of the stack section.
25005  The stack pointer initially will point at address (bottom_address+stack_size-1).
25006 \end_layout
25007
25008 \begin_layout LyX-Code
25009 Example:
25010 \end_layout
25011
25012 \begin_layout LyX-Code
25013
25014 \end_layout
25015
25016 \begin_layout LyX-Code
25017 /* initializes stack of 100 bytes at RAM address 0x200 */
25018 \end_layout
25019
25020 \begin_layout LyX-Code
25021 #pragma stack 0x200 100
25022 \end_layout
25023
25024 \begin_layout Standard
25025 If the stack_size field is omitted then a stack is created with the default
25026  size of 64.
25027  This size might be enough for most programs, but its not enough for operations
25028  with deep function nesting or excessive stack usage.
25029 \end_layout
25030
25031 \begin_layout Description
25032 code
25033 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
25034
25035 \end_inset
25036
25037  Force a function to a static FLASH address.
25038 \end_layout
25039
25040 \begin_layout LyX-Code
25041 Example:
25042 \end_layout
25043
25044 \begin_layout LyX-Code
25045
25046 \end_layout
25047
25048 \begin_layout LyX-Code
25049 /* place function test_func at 0x4000 */
25050 \end_layout
25051
25052 \begin_layout LyX-Code
25053 #pragma code test_func 0x4000
25054 \end_layout
25055
25056 \begin_layout LyX-Code
25057
25058 \end_layout
25059
25060 \begin_layout Description
25061 library instructs the linker to use a library module.
25062 \newline
25063 Usage:
25064 \end_layout
25065
25066 \begin_layout LyX-Code
25067 #pragma library module_name
25068 \end_layout
25069
25070 \begin_layout Standard
25071
25072 \emph on
25073 module_name
25074 \emph default
25075  can be any library or object file (including its path).
25076  Note that there are four reserved keywords which have special meaning.
25077  These are:
25078 \end_layout
25079
25080 \begin_layout Standard
25081 \align center
25082 \begin_inset Tabular
25083 <lyxtabular version="3" rows="6" columns="3">
25084 <features>
25085 <column alignment="center" valignment="top" leftline="true" width="0">
25086 <column alignment="block" valignment="top" leftline="true" width="20page%">
25087 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
25088 <row topline="true" bottomline="true">
25089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25090 \begin_inset Text
25091
25092 \begin_layout Standard
25093 Keyword
25094 \end_layout
25095
25096 \end_inset
25097 </cell>
25098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25099 \begin_inset Text
25100
25101 \begin_layout Standard
25102 Description
25103 \end_layout
25104
25105 \end_inset
25106 </cell>
25107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25108 \begin_inset Text
25109
25110 \begin_layout Standard
25111 Module to link
25112 \end_layout
25113
25114 \end_inset
25115 </cell>
25116 </row>
25117 <row topline="true">
25118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25119 \begin_inset Text
25120
25121 \begin_layout Standard
25122
25123 \series bold
25124 ignore
25125 \end_layout
25126
25127 \end_inset
25128 </cell>
25129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25130 \begin_inset Text
25131
25132 \begin_layout Standard
25133 ignore all library pragmas
25134 \end_layout
25135
25136 \end_inset
25137 </cell>
25138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25139 \begin_inset Text
25140
25141 \begin_layout Standard
25142
25143 \emph on
25144 (none)
25145 \end_layout
25146
25147 \end_inset
25148 </cell>
25149 </row>
25150 <row topline="true">
25151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25152 \begin_inset Text
25153
25154 \begin_layout Standard
25155
25156 \series bold
25157 c
25158 \end_layout
25159
25160 \end_inset
25161 </cell>
25162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25163 \begin_inset Text
25164
25165 \begin_layout Standard
25166 link the C library
25167 \end_layout
25168
25169 \end_inset
25170 </cell>
25171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25172 \begin_inset Text
25173
25174 \begin_layout Standard
25175
25176 \emph on
25177 libc18f
25178 \emph default
25179 .lib
25180 \end_layout
25181
25182 \end_inset
25183 </cell>
25184 </row>
25185 <row topline="true">
25186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25187 \begin_inset Text
25188
25189 \begin_layout Standard
25190
25191 \series bold
25192 math
25193 \end_layout
25194
25195 \end_inset
25196 </cell>
25197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25198 \begin_inset Text
25199
25200 \begin_layout Standard
25201 link the Math libarary
25202 \end_layout
25203
25204 \end_inset
25205 </cell>
25206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25207 \begin_inset Text
25208
25209 \begin_layout Standard
25210
25211 \emph on
25212 libm18f
25213 \emph default
25214 .lib
25215 \end_layout
25216
25217 \end_inset
25218 </cell>
25219 </row>
25220 <row topline="true">
25221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25222 \begin_inset Text
25223
25224 \begin_layout Standard
25225
25226 \series bold
25227 io
25228 \end_layout
25229
25230 \end_inset
25231 </cell>
25232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25233 \begin_inset Text
25234
25235 \begin_layout Standard
25236 link the I/O library
25237 \end_layout
25238
25239 \end_inset
25240 </cell>
25241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25242 \begin_inset Text
25243
25244 \begin_layout Standard
25245
25246 \emph on
25247 libio18f*
25248 \emph default
25249 .lib
25250 \end_layout
25251
25252 \end_inset
25253 </cell>
25254 </row>
25255 <row topline="true" bottomline="true">
25256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25257 \begin_inset Text
25258
25259 \begin_layout Standard
25260
25261 \series bold
25262 debug
25263 \end_layout
25264
25265 \end_inset
25266 </cell>
25267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25268 \begin_inset Text
25269
25270 \begin_layout Standard
25271 link the debug library
25272 \end_layout
25273
25274 \end_inset
25275 </cell>
25276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25277 \begin_inset Text
25278
25279 \begin_layout Standard
25280
25281 \emph on
25282 libdebug
25283 \emph default
25284 .lib
25285 \end_layout
25286
25287 \end_inset
25288 </cell>
25289 </row>
25290 </lyxtabular>
25291
25292 \end_inset
25293
25294
25295 \newline
25296 * is the device number, i.e.
25297  452 for PIC18F452 MCU.
25298 \end_layout
25299
25300 \begin_layout Standard
25301 This feature allows for linking with specific libraries withoug having to
25302  explicit name them in the command line.
25303  Note that the 
25304 \noun on
25305 ignore
25306 \noun default
25307  keyword will reject all modules specified by the library pragma.
25308 \end_layout
25309
25310 \begin_layout Description
25311 udata The pragma udata instructs the compiler to emit code so that linker
25312  will place a variable at a specific memory bank.
25313 \end_layout
25314
25315 \begin_layout LyX-Code
25316 Example:
25317 \end_layout
25318
25319 \begin_layout LyX-Code
25320
25321 \end_layout
25322
25323 \begin_layout LyX-Code
25324 /* places variable foo at bank2 */
25325 \end_layout
25326
25327 \begin_layout LyX-Code
25328 #pragma udata bank2 foo
25329 \end_layout
25330
25331 \begin_layout LyX-Code
25332 char foo;
25333 \end_layout
25334
25335 \begin_layout Standard
25336 In order for this pragma to work extra SECTION directives should be added
25337  in the .lkr script.
25338  In the following example a sample .lkr file is shown:
25339 \end_layout
25340
25341 \begin_layout LyX-Code
25342
25343 \end_layout
25344
25345 \begin_layout LyX-Code
25346 // Sample linker script for the PIC18F452 processor
25347 \end_layout
25348
25349 \begin_layout LyX-Code
25350 LIBPATH .
25351 \end_layout
25352
25353 \begin_layout LyX-Code
25354 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
25355 \end_layout
25356
25357 \begin_layout LyX-Code
25358 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
25359 \end_layout
25360
25361 \begin_layout LyX-Code
25362 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
25363 \end_layout
25364
25365 \begin_layout LyX-Code
25366 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
25367 \end_layout
25368
25369 \begin_layout LyX-Code
25370 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
25371 \end_layout
25372
25373 \begin_layout LyX-Code
25374 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
25375 \end_layout
25376
25377 \begin_layout LyX-Code
25378 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
25379 \end_layout
25380
25381 \begin_layout LyX-Code
25382
25383 \end_layout
25384
25385 \begin_layout LyX-Code
25386 DATABANK   NAME=gpr0       START=0x80           END=0xFF
25387 \end_layout
25388
25389 \begin_layout LyX-Code
25390 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
25391 \end_layout
25392
25393 \begin_layout LyX-Code
25394 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
25395 \end_layout
25396
25397 \begin_layout LyX-Code
25398 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
25399 \end_layout
25400
25401 \begin_layout LyX-Code
25402 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
25403 \end_layout
25404
25405 \begin_layout LyX-Code
25406 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
25407 \end_layout
25408
25409 \begin_layout LyX-Code
25410 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
25411 \end_layout
25412
25413 \begin_layout LyX-Code
25414
25415 \end_layout
25416
25417 \begin_layout LyX-Code
25418 SECTION    NAME=CONFIG     ROM=config
25419 \end_layout
25420
25421 \begin_layout LyX-Code
25422
25423 \end_layout
25424
25425 \begin_layout LyX-Code
25426 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
25427 \end_layout
25428
25429 \begin_layout LyX-Code
25430 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
25431 \end_layout
25432
25433 \begin_layout LyX-Code
25434 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
25435 \end_layout
25436
25437 \begin_layout LyX-Code
25438 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
25439 \end_layout
25440
25441 \begin_layout LyX-Code
25442 SECTION    NAME=bank4      RAM=gpr4
25443 \end_layout
25444
25445 \begin_layout LyX-Code
25446 SECTION    NAME=bank5      RAM=gpr5
25447 \end_layout
25448
25449 \begin_layout Standard
25450 The linker will recognise the section name set in the pragma statement and
25451  will position the variable at the memory bank set with the RAM field at
25452  the SECTION line in the linker script file.
25453 \end_layout
25454
25455 \begin_layout Subsection
25456 Header Files
25457 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
25458
25459 \end_inset
25460
25461
25462 \end_layout
25463
25464 \begin_layout Standard
25465 There is one main header file
25466 \begin_inset LatexCommand \index{PIC16!Header files}
25467
25468 \end_inset
25469
25470  that can be included to the source files using the pic16
25471 \begin_inset LatexCommand \index{PIC16}
25472
25473 \end_inset
25474
25475  port.
25476  That file is the 
25477 \series bold
25478 pic18fregs.h
25479 \series default
25480 .
25481  This header file contains the definitions for the processor special registers,
25482  so it is necessary if the source accesses them.
25483  It can be included by adding the following line in the beginning of the
25484  file:
25485 \end_layout
25486
25487 \begin_layout LyX-Code
25488 #include <pic18fregs.h>
25489 \end_layout
25490
25491 \begin_layout Standard
25492 The specific microcontroller is selected within the pic18fregs.h automatically,
25493  so the same source can be used with a variety of devices.
25494 \end_layout
25495
25496 \begin_layout Subsection
25497 Libraries
25498 \end_layout
25499
25500 \begin_layout Standard
25501 The libraries
25502 \begin_inset LatexCommand \index{PIC16!Libraries}
25503
25504 \end_inset
25505
25506  that PIC16
25507 \begin_inset LatexCommand \index{PIC16}
25508
25509 \end_inset
25510
25511  port depends on are the microcontroller device libraries which contain
25512  the symbol definitions for the microcontroller special function registers.
25513  These libraries have the format pic18fxxxx.lib, where 
25514 \emph on
25515 xxxx
25516 \emph default
25517  is the microcontroller identification number.
25518  The specific library is selected automatically by the compiler at link
25519  stage according to the selected device.
25520 \end_layout
25521
25522 \begin_layout Standard
25523 Libraries are created with gplib which is part of the gputils package 
25524 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
25525
25526 \end_inset
25527
25528 .
25529 \end_layout
25530
25531 \begin_layout Subsubsection*
25532 Building the libraries
25533 \end_layout
25534
25535 \begin_layout Standard
25536 Before using SDCC/pic16 there are some libraries that need to be compiled.
25537  This process is not done automatically by SDCC since not all users use
25538  SDCC for pic16 projects.
25539  So each user should compile the libraries separately.
25540 \end_layout
25541
25542 \begin_layout Standard
25543 The steps to compile the pic16 libraries under Linux and Mac OS X are:
25544 \end_layout
25545
25546 \begin_layout LyX-Code
25547 cd device/lib/pic16
25548 \end_layout
25549
25550 \begin_layout LyX-Code
25551 ./configure
25552 \end_layout
25553
25554 \begin_layout LyX-Code
25555 make
25556 \end_layout
25557
25558 \begin_layout LyX-Code
25559 cd ..
25560 \end_layout
25561
25562 \begin_layout LyX-Code
25563 make model-pic16
25564 \end_layout
25565
25566 \begin_layout LyX-Code
25567 su -c 'make install'     # install the libraries, you need the root password
25568 \end_layout
25569
25570 \begin_layout Standard
25571 If you need to install the headers too, do:
25572 \end_layout
25573
25574 \begin_layout LyX-Code
25575 cd device/include
25576 \end_layout
25577
25578 \begin_layout LyX-Code
25579 su -c 'make install'     # install the headers, you need the root password
25580 \end_layout
25581
25582 \begin_layout Standard
25583 There exist a special target to build the I/O libraries.
25584  This target is not automatically build because it will build the I/O library
25585  for 
25586 \emph on
25587 every
25588 \emph default
25589  supported device.
25590  This way building will take quite a lot of time.
25591  Users are advised to edit the 
25592 \series bold
25593 device/lib/pic16/pics.build
25594 \series default
25595  file and then execute:
25596 \end_layout
25597
25598 \begin_layout LyX-Code
25599 make lib-io
25600 \end_layout
25601
25602 \begin_layout Subsection
25603 Adding New Devices to the Port
25604 \end_layout
25605
25606 \begin_layout Standard
25607 Adding support for a new 16
25608 \begin_inset ERT
25609 status open
25610
25611 \begin_layout Standard
25612
25613
25614 \backslash
25615 ,
25616 \end_layout
25617
25618 \end_inset
25619
25620 bit PIC MCU requires the following steps:
25621 \end_layout
25622
25623 \begin_layout Enumerate
25624 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
25625 \newline
25626
25627 \family typewriter
25628 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
25629 inc
25630 \end_layout
25631
25632 \begin_layout Enumerate
25633
25634 \family typewriter
25635 mv picDEVICE.h /path/to/sdcc/device/include/pic16
25636 \end_layout
25637
25638 \begin_layout Enumerate
25639
25640 \family typewriter
25641 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
25642 \end_layout
25643
25644 \begin_layout Enumerate
25645 Add DEVICE to 
25646 \family typewriter
25647 /path/to/sdcc/device/lib/pic16/pics.all
25648 \family default
25649  (and 
25650 \family typewriter
25651 .build
25652 \family default
25653 ).
25654 \newline
25655 Note: No 18f prefix here!
25656 \end_layout
25657
25658 \begin_layout Enumerate
25659 Adjust 
25660 \family typewriter
25661 /path/to/sdcc/device/lib/pic16/libio/*.ignore
25662 \family default
25663
25664 \newline
25665 Add your DEVICE if it does not compile in 
25666 \family typewriter
25667 adc
25668 \family default
25669
25670 \family typewriter
25671 i2c
25672 \family default
25673 , or 
25674 \family typewriter
25675 usart
25676 \family default
25677 .
25678 \end_layout
25679
25680 \begin_layout Enumerate
25681 Edit 
25682 \family typewriter
25683 /path/to/sdcc/device/include/pic16/pic18fregs.h
25684 \family default
25685 .
25686  The file format is self-explanatory, just add
25687 \newline
25688
25689 \family typewriter
25690 #elif defined(picDEVICE)
25691 \newline
25692 # include <picDEVICE.h>
25693 \family default
25694
25695 \newline
25696 at the right place (keep it sorted).
25697 \end_layout
25698
25699 \begin_layout Enumerate
25700 Edit 
25701 \family typewriter
25702 /path/to/sdcc/src/pic16/devices.inc
25703 \family default
25704 .
25705  Copy and modify an existing entry and insert it at the correct place (keep
25706  the file sorted).
25707  The file is hardly documented, look at the entries for the 18f2221...
25708 \end_layout
25709
25710 \begin_layout Enumerate
25711 Recompile SDCC, including the pic16 libraries.
25712 \end_layout
25713
25714 \begin_layout Subsection
25715 Memory Models
25716 \end_layout
25717
25718 \begin_layout Standard
25719 The following memory models are supported by the PIC16 port:
25720 \end_layout
25721
25722 \begin_layout Itemize
25723 small model
25724 \end_layout
25725
25726 \begin_layout Itemize
25727 large model
25728 \end_layout
25729
25730 \begin_layout Standard
25731 Memory model affects the default size of pointers within the source.
25732  The sizes are shown in the next table:
25733 \end_layout
25734
25735 \begin_layout Standard
25736 \align center
25737 \begin_inset Tabular
25738 <lyxtabular version="3" rows="3" columns="3">
25739 <features>
25740 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25741 <column alignment="center" valignment="top" leftline="true" width="0">
25742 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25743 <row topline="true" bottomline="true">
25744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25745 \begin_inset Text
25746
25747 \begin_layout Standard
25748 Pointer sizes according to memory model
25749 \end_layout
25750
25751 \end_inset
25752 </cell>
25753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25754 \begin_inset Text
25755
25756 \begin_layout Standard
25757 small model
25758 \end_layout
25759
25760 \end_inset
25761 </cell>
25762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25763 \begin_inset Text
25764
25765 \begin_layout Standard
25766 large model
25767 \end_layout
25768
25769 \end_inset
25770 </cell>
25771 </row>
25772 <row topline="true" bottomline="true">
25773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25774 \begin_inset Text
25775
25776 \begin_layout Standard
25777 code pointers
25778 \end_layout
25779
25780 \end_inset
25781 </cell>
25782 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25783 \begin_inset Text
25784
25785 \begin_layout Standard
25786 16-bits
25787 \end_layout
25788
25789 \end_inset
25790 </cell>
25791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25792 \begin_inset Text
25793
25794 \begin_layout Standard
25795 24-bits
25796 \end_layout
25797
25798 \end_inset
25799 </cell>
25800 </row>
25801 <row topline="true" bottomline="true">
25802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25803 \begin_inset Text
25804
25805 \begin_layout Standard
25806 data pointers
25807 \end_layout
25808
25809 \end_inset
25810 </cell>
25811 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25812 \begin_inset Text
25813
25814 \begin_layout Standard
25815 16-bits
25816 \end_layout
25817
25818 \end_inset
25819 </cell>
25820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25821 \begin_inset Text
25822
25823 \begin_layout Standard
25824 16-bits
25825 \end_layout
25826
25827 \end_inset
25828 </cell>
25829 </row>
25830 </lyxtabular>
25831
25832 \end_inset
25833
25834
25835 \end_layout
25836
25837 \begin_layout Standard
25838 It is advisable that all sources within a project are compiled with the
25839  same memory model.
25840  If one wants to override the default memory model, this can be done by
25841  declaring a pointer as 
25842 \series bold
25843 far
25844 \series default
25845  or 
25846 \series bold
25847 near
25848 \series default
25849 .
25850  Far selects large memory model's pointers, while near selects small memory
25851  model's pointers.
25852 \end_layout
25853
25854 \begin_layout Standard
25855 The standard device libraries (see 
25856 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25857
25858 \end_inset
25859
25860 ) contain no reference to pointers, so they can be used with both memory
25861  models.
25862 \end_layout
25863
25864 \begin_layout Subsection
25865 Stack
25866 \end_layout
25867
25868 \begin_layout Standard
25869 The stack
25870 \begin_inset LatexCommand \index{PIC16!stack}
25871
25872 \end_inset
25873
25874  implementation for the PIC16 port uses two indirect registers, FSR1 and
25875  FSR2.
25876 \end_layout
25877
25878 \begin_layout Description
25879 FSR1 is assigned as stack pointer
25880 \end_layout
25881
25882 \begin_layout Description
25883 FSR2 is assigned as frame pointer
25884 \end_layout
25885
25886 \begin_layout Standard
25887 The following stack models are supported by the PIC16 port
25888 \end_layout
25889
25890 \begin_layout Itemize
25891
25892 \noun on
25893 small
25894 \noun default
25895  model
25896 \end_layout
25897
25898 \begin_layout Itemize
25899
25900 \noun on
25901 large
25902 \noun default
25903  model
25904 \end_layout
25905
25906 \begin_layout Standard
25907
25908 \noun on
25909 Small
25910 \noun default
25911  model means that only the FSRxL byte is used to access stack and frame,
25912  while 
25913 \emph on
25914 \noun on
25915 large
25916 \emph default
25917 \noun default
25918  uses both FSRxL and FSRxH registers.
25919  The following table shows the stack/frame pointers sizes according to stack
25920  model and the maximum space they can address:
25921 \end_layout
25922
25923 \begin_layout Standard
25924 \align center
25925 \begin_inset Tabular
25926 <lyxtabular version="3" rows="3" columns="3">
25927 <features>
25928 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25929 <column alignment="center" valignment="top" leftline="true" width="0">
25930 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25931 <row topline="true" bottomline="true">
25932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25933 \begin_inset Text
25934
25935 \begin_layout Standard
25936 Stack & Frame pointer sizes according to stack model
25937 \end_layout
25938
25939 \end_inset
25940 </cell>
25941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25942 \begin_inset Text
25943
25944 \begin_layout Standard
25945 small
25946 \end_layout
25947
25948 \end_inset
25949 </cell>
25950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25951 \begin_inset Text
25952
25953 \begin_layout Standard
25954 large
25955 \end_layout
25956
25957 \end_inset
25958 </cell>
25959 </row>
25960 <row topline="true">
25961 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25962 \begin_inset Text
25963
25964 \begin_layout Standard
25965 Stack pointer FSR1
25966 \end_layout
25967
25968 \end_inset
25969 </cell>
25970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25971 \begin_inset Text
25972
25973 \begin_layout Standard
25974 8-bits
25975 \end_layout
25976
25977 \end_inset
25978 </cell>
25979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25980 \begin_inset Text
25981
25982 \begin_layout Standard
25983 16-bits
25984 \end_layout
25985
25986 \end_inset
25987 </cell>
25988 </row>
25989 <row topline="true" bottomline="true">
25990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25991 \begin_inset Text
25992
25993 \begin_layout Standard
25994 Frame pointer FSR2
25995 \end_layout
25996
25997 \end_inset
25998 </cell>
25999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26000 \begin_inset Text
26001
26002 \begin_layout Standard
26003 8-bits
26004 \end_layout
26005
26006 \end_inset
26007 </cell>
26008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26009 \begin_inset Text
26010
26011 \begin_layout Standard
26012 16-bits
26013 \end_layout
26014
26015 \end_inset
26016 </cell>
26017 </row>
26018 </lyxtabular>
26019
26020 \end_inset
26021
26022
26023 \end_layout
26024
26025 \begin_layout Standard
26026
26027 \noun on
26028 Large 
26029 \noun default
26030 stack model is currently not working properly throughout the code generator.
26031  So its use is not advised.
26032  Also there are some other points that need special care:
26033 \newline
26034
26035 \end_layout
26036
26037 \begin_layout Enumerate
26038 Do not create stack sections with size more than one physical bank (that
26039  is 256 bytes)
26040 \end_layout
26041
26042 \begin_layout Enumerate
26043 Stack sections should no cross physical bank limits (i.e.
26044  #pragma stack 0x50 0x100)
26045 \end_layout
26046
26047 \begin_layout Standard
26048 These limitations are caused by the fact that only FSRxL is modified when
26049  using SMALL stack model, so no more than 256 bytes of stack can be used.
26050  This problem will disappear after LARGE model is fully implemented.
26051 \end_layout
26052
26053 \begin_layout Subsection
26054 Functions
26055 \end_layout
26056
26057 \begin_layout Standard
26058 In addition to the standard SDCC function keywords, PIC16
26059 \begin_inset LatexCommand \index{PIC16}
26060
26061 \end_inset
26062
26063  port makes available two more:
26064 \end_layout
26065
26066 \begin_layout Description
26067 wparam
26068 \begin_inset LatexCommand \index{PIC16!wparam}
26069
26070 \end_inset
26071
26072  Use the WREG to pass one byte of the first function argument.
26073  This improves speed but you may not use this for functions with arguments
26074  that are called via function pointers, otherwise the first byte of the
26075  first parameter will get lost.
26076  Usage:
26077 \end_layout
26078
26079 \begin_layout LyX-Code
26080 void func_wparam(int a) wparam
26081 \end_layout
26082
26083 \begin_layout LyX-Code
26084 {
26085 \end_layout
26086
26087 \begin_layout LyX-Code
26088     /* WREG hold the lower part of a */
26089 \end_layout
26090
26091 \begin_layout LyX-Code
26092     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
26093  */
26094 \end_layout
26095
26096 \begin_layout LyX-Code
26097 ...
26098 \end_layout
26099
26100 \begin_layout LyX-Code
26101 }
26102 \end_layout
26103
26104 \begin_layout Description
26105 shadowregs
26106 \begin_inset LatexCommand \index{PIC16!shadowregs}
26107
26108 \end_inset
26109
26110  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
26111  hardware shadow registers which hold the values of WREG, STATUS and BSR
26112  registers.
26113  This can be done by adding the keyword 
26114 \emph on
26115 shadowregs
26116 \emph default
26117  before the 
26118 \emph on
26119 interrupt
26120 \emph default
26121  keyword in the function's header.
26122 \end_layout
26123
26124 \begin_layout LyX-Code
26125 void isr_shadow(void) shadowregs interrupt 1
26126 \end_layout
26127
26128 \begin_layout LyX-Code
26129 {
26130 \end_layout
26131
26132 \begin_layout LyX-Code
26133 ...
26134 \end_layout
26135
26136 \begin_layout LyX-Code
26137 }
26138 \end_layout
26139
26140 \begin_layout Standard
26141
26142 \emph on
26143 shadowregs
26144 \emph default
26145  instructs the code generator not to store/restore WREG, STATUS, BSR when
26146  entering/exiting the ISR.
26147 \end_layout
26148
26149 \begin_layout Subsection
26150 Function return values
26151 \end_layout
26152
26153 \begin_layout Standard
26154 Return values from functions are placed to the appropriate registers following
26155  a modified Microchip policy optimized for SDCC.
26156  The following table shows these registers:
26157 \end_layout
26158
26159 \begin_layout Standard
26160 \align center
26161 \begin_inset Tabular
26162 <lyxtabular version="3" rows="6" columns="2">
26163 <features>
26164 <column alignment="center" valignment="top" leftline="true" width="0">
26165 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26166 <row topline="true" bottomline="true">
26167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26168 \begin_inset Text
26169
26170 \begin_layout Standard
26171 size
26172 \end_layout
26173
26174 \end_inset
26175 </cell>
26176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26177 \begin_inset Text
26178
26179 \begin_layout Standard
26180 destination register
26181 \end_layout
26182
26183 \end_inset
26184 </cell>
26185 </row>
26186 <row topline="true">
26187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26188 \begin_inset Text
26189
26190 \begin_layout Standard
26191 8 bits
26192 \end_layout
26193
26194 \end_inset
26195 </cell>
26196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26197 \begin_inset Text
26198
26199 \begin_layout Standard
26200 WREG
26201 \end_layout
26202
26203 \end_inset
26204 </cell>
26205 </row>
26206 <row topline="true">
26207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26208 \begin_inset Text
26209
26210 \begin_layout Standard
26211 16 bits
26212 \end_layout
26213
26214 \end_inset
26215 </cell>
26216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26217 \begin_inset Text
26218
26219 \begin_layout Standard
26220 PRODL:WREG
26221 \end_layout
26222
26223 \end_inset
26224 </cell>
26225 </row>
26226 <row topline="true">
26227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26228 \begin_inset Text
26229
26230 \begin_layout Standard
26231 24 bits
26232 \end_layout
26233
26234 \end_inset
26235 </cell>
26236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26237 \begin_inset Text
26238
26239 \begin_layout Standard
26240 PRODH:PRODL:WREG
26241 \end_layout
26242
26243 \end_inset
26244 </cell>
26245 </row>
26246 <row topline="true">
26247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26248 \begin_inset Text
26249
26250 \begin_layout Standard
26251 32 bits
26252 \end_layout
26253
26254 \end_inset
26255 </cell>
26256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26257 \begin_inset Text
26258
26259 \begin_layout Standard
26260 FSR0L:PRODH:PRODL:WREG
26261 \end_layout
26262
26263 \end_inset
26264 </cell>
26265 </row>
26266 <row topline="true" bottomline="true">
26267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26268 \begin_inset Text
26269
26270 \begin_layout Standard
26271 >32 bits
26272 \end_layout
26273
26274 \end_inset
26275 </cell>
26276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26277 \begin_inset Text
26278
26279 \begin_layout Standard
26280 on stack, FSR0 points to the beginning
26281 \end_layout
26282
26283 \end_inset
26284 </cell>
26285 </row>
26286 </lyxtabular>
26287
26288 \end_inset
26289
26290
26291 \end_layout
26292
26293 \begin_layout Subsection
26294 Interrupts
26295 \end_layout
26296
26297 \begin_layout Standard
26298 An interrupt
26299 \begin_inset LatexCommand \index{PIC16!interrupt}
26300
26301 \end_inset
26302
26303  service routine (ISR) is declared using the 
26304 \emph on
26305 interrupt
26306 \emph default
26307  keyword.
26308 \end_layout
26309
26310 \begin_layout LyX-Code
26311 void isr(void) interrupt 
26312 \emph on
26313 n
26314 \end_layout
26315
26316 \begin_layout LyX-Code
26317 {
26318 \end_layout
26319
26320 \begin_layout LyX-Code
26321 ...
26322 \end_layout
26323
26324 \begin_layout LyX-Code
26325 }
26326 \end_layout
26327
26328 \begin_layout Standard
26329
26330 \emph on
26331 n
26332 \emph default
26333  is the interrupt number, which for PIC18F devices can be:
26334 \end_layout
26335
26336 \begin_layout Standard
26337 \align center
26338 \begin_inset Tabular
26339 <lyxtabular version="3" rows="4" columns="3">
26340 <features>
26341 <column alignment="center" valignment="top" leftline="true" width="0">
26342 <column alignment="center" valignment="top" leftline="true" width="0">
26343 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26344 <row topline="true" bottomline="true">
26345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26346 \begin_inset Text
26347
26348 \begin_layout Standard
26349
26350 \emph on
26351 n
26352 \end_layout
26353
26354 \end_inset
26355 </cell>
26356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26357 \begin_inset Text
26358
26359 \begin_layout Standard
26360 Interrupt Vector
26361 \end_layout
26362
26363 \end_inset
26364 </cell>
26365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26366 \begin_inset Text
26367
26368 \begin_layout Standard
26369 Interrupt Vector Address
26370 \end_layout
26371
26372 \end_inset
26373 </cell>
26374 </row>
26375 <row topline="true">
26376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26377 \begin_inset Text
26378
26379 \begin_layout Standard
26380 0
26381 \end_layout
26382
26383 \end_inset
26384 </cell>
26385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26386 \begin_inset Text
26387
26388 \begin_layout Standard
26389 RESET vector
26390 \end_layout
26391
26392 \end_inset
26393 </cell>
26394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26395 \begin_inset Text
26396
26397 \begin_layout Standard
26398 0x000000
26399 \end_layout
26400
26401 \end_inset
26402 </cell>
26403 </row>
26404 <row topline="true">
26405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26406 \begin_inset Text
26407
26408 \begin_layout Standard
26409
26410 \family roman
26411 \series medium
26412 \shape up
26413 \size normal
26414 \emph off
26415 \bar no
26416 \noun off
26417 \color none
26418 1
26419 \end_layout
26420
26421 \end_inset
26422 </cell>
26423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26424 \begin_inset Text
26425
26426 \begin_layout Standard
26427
26428 \family roman
26429 \series medium
26430 \shape up
26431 \size normal
26432 \emph off
26433 \bar no
26434 \noun off
26435 \color none
26436 HIGH priority interrupts
26437 \end_layout
26438
26439 \end_inset
26440 </cell>
26441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26442 \begin_inset Text
26443
26444 \begin_layout Standard
26445 0x000008
26446 \end_layout
26447
26448 \end_inset
26449 </cell>
26450 </row>
26451 <row topline="true" bottomline="true">
26452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26453 \begin_inset Text
26454
26455 \begin_layout Standard
26456 2
26457 \end_layout
26458
26459 \end_inset
26460 </cell>
26461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26462 \begin_inset Text
26463
26464 \begin_layout Standard
26465 LOW priority interrupts
26466 \end_layout
26467
26468 \end_inset
26469 </cell>
26470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26471 \begin_inset Text
26472
26473 \begin_layout Standard
26474 0x000018
26475 \end_layout
26476
26477 \end_inset
26478 </cell>
26479 </row>
26480 </lyxtabular>
26481
26482 \end_inset
26483
26484
26485 \end_layout
26486
26487 \begin_layout Standard
26488 When generating assembly code for ISR the code generator places a 
26489 \noun on
26490 goto 
26491 \noun default
26492 instruction at the 
26493 \emph on
26494 Interrupt Vector Address
26495 \emph default
26496  which points at the genetated ISR.
26497  This single GOTO instruction is part of an automatically generated 
26498 \emph on
26499 interrupt entry point
26500 \emph default
26501  function.
26502  The actuall ISR code is placed as normally would in the code space.
26503  Upon interrupt request, the GOTO instruction is executed which jumps to
26504  the ISR code.
26505  When declaring interrupt functions as _naked this GOTO instruction is 
26506 \series bold
26507 not
26508 \series default
26509  generated.
26510  The whole interrupt functions is therefore placed at the Interrupt Vector
26511  Address of the specific interrupt.
26512  This is not a problem for the LOW priority interrupts, but it is a problem
26513  for the RESET and the HIGH priority interrupts because code may be written
26514  at the next interrupt's vector address and cause undeterminate program
26515  behaviour if that interrupt is raised.
26516 \begin_inset Foot
26517 status open
26518
26519 \begin_layout Standard
26520 This is not a problem when
26521 \end_layout
26522
26523 \begin_layout Enumerate
26524 this is a HIGH interrupt ISR and LOW interrupts are 
26525 \emph on
26526 disabled
26527 \emph default
26528  or not used.
26529 \end_layout
26530
26531 \begin_layout Enumerate
26532 when the ISR is small enough not to reach the next interrupt's vector address.
26533 \end_layout
26534
26535 \end_inset
26536
26537
26538 \end_layout
26539
26540 \begin_layout Standard
26541
26542 \emph on
26543 n
26544 \emph default
26545  may be omitted.
26546  This way a function is generated similar to an ISR, but it is not assigned
26547  to any interrupt.
26548 \end_layout
26549
26550 \begin_layout Standard
26551 When entering an interrupt, currently the PIC16
26552 \begin_inset LatexCommand \index{PIC16}
26553
26554 \end_inset
26555
26556  port automatically saves the following registers:
26557 \end_layout
26558
26559 \begin_layout Itemize
26560 WREG
26561 \end_layout
26562
26563 \begin_layout Itemize
26564 STATUS
26565 \end_layout
26566
26567 \begin_layout Itemize
26568 BSR
26569 \end_layout
26570
26571 \begin_layout Itemize
26572 PROD (PRODL and PRODH)
26573 \end_layout
26574
26575 \begin_layout Itemize
26576 FSR0 (FSR0L and FSR0H)
26577 \end_layout
26578
26579 \begin_layout Standard
26580 These registers are restored upon return from the interrupt routine.
26581 \begin_inset Foot
26582 status open
26583
26584 \begin_layout Standard
26585 NOTE that when the _naked attribute is specified for an interrupt routine,
26586  then NO registers are stored or restored.
26587 \end_layout
26588
26589 \end_inset
26590
26591
26592 \end_layout
26593
26594 \begin_layout Subsection
26595 Generic Pointers
26596 \end_layout
26597
26598 \begin_layout Standard
26599 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
26600  There are 3 types of generic pointers currently implemented data, code
26601  and eeprom pointers.
26602  They are differentiated by the value of the 7th and 6th bits of the upper
26603  byte:
26604 \end_layout
26605
26606 \begin_layout Standard
26607 \align center
26608 \begin_inset Tabular
26609 <lyxtabular version="3" rows="5" columns="5">
26610 <features>
26611 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26612 <column alignment="center" valignment="top" width="0">
26613 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26614 <column alignment="center" valignment="top" width="0">
26615 <column alignment="left" valignment="top" rightline="true" width="0">
26616 <row topline="true" bottomline="true">
26617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26618 \begin_inset Text
26619
26620 \begin_layout Standard
26621 pointer type
26622 \end_layout
26623
26624 \end_inset
26625 </cell>
26626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26627 \begin_inset Text
26628
26629 \begin_layout Standard
26630 7th bit
26631 \end_layout
26632
26633 \end_inset
26634 </cell>
26635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26636 \begin_inset Text
26637
26638 \begin_layout Standard
26639 6th bit
26640 \end_layout
26641
26642 \end_inset
26643 </cell>
26644 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26645 \begin_inset Text
26646
26647 \begin_layout Standard
26648 rest of the pointer
26649 \end_layout
26650
26651 \end_inset
26652 </cell>
26653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26654 \begin_inset Text
26655
26656 \begin_layout Standard
26657 description
26658 \end_layout
26659
26660 \end_inset
26661 </cell>
26662 </row>
26663 <row topline="true" bottomline="true">
26664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26665 \begin_inset Text
26666
26667 \begin_layout Standard
26668 data 
26669 \end_layout
26670
26671 \end_inset
26672 </cell>
26673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26674 \begin_inset Text
26675
26676 \begin_layout Standard
26677 1
26678 \end_layout
26679
26680 \end_inset
26681 </cell>
26682 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26683 \begin_inset Text
26684
26685 \begin_layout Standard
26686 0
26687 \end_layout
26688
26689 \end_inset
26690 </cell>
26691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26692 \begin_inset Text
26693
26694 \begin_layout Standard
26695
26696 \family typewriter
26697 \shape slanted
26698 \emph on
26699 uuuuuu uuuuxxxx xxxxxxxx
26700 \end_layout
26701
26702 \end_inset
26703 </cell>
26704 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26705 \begin_inset Text
26706
26707 \begin_layout Standard
26708 a 12-bit data pointer in data RAM memory
26709 \end_layout
26710
26711 \end_inset
26712 </cell>
26713 </row>
26714 <row bottomline="true">
26715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26716 \begin_inset Text
26717
26718 \begin_layout Standard
26719 code
26720 \end_layout
26721
26722 \end_inset
26723 </cell>
26724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26725 \begin_inset Text
26726
26727 \begin_layout Standard
26728 0
26729 \end_layout
26730
26731 \end_inset
26732 </cell>
26733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26734 \begin_inset Text
26735
26736 \begin_layout Standard
26737 0
26738 \end_layout
26739
26740 \end_inset
26741 </cell>
26742 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26743 \begin_inset Text
26744
26745 \begin_layout Standard
26746
26747 \family typewriter
26748 \shape slanted
26749 \emph on
26750 uxxxxx xxxxxxxx xxxxxxxx
26751 \end_layout
26752
26753 \end_inset
26754 </cell>
26755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26756 \begin_inset Text
26757
26758 \begin_layout Standard
26759 a 21-bit code pointer in FLASH memory
26760 \end_layout
26761
26762 \end_inset
26763 </cell>
26764 </row>
26765 <row bottomline="true">
26766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26767 \begin_inset Text
26768
26769 \begin_layout Standard
26770 eeprom
26771 \end_layout
26772
26773 \end_inset
26774 </cell>
26775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26776 \begin_inset Text
26777
26778 \begin_layout Standard
26779 0
26780 \end_layout
26781
26782 \end_inset
26783 </cell>
26784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26785 \begin_inset Text
26786
26787 \begin_layout Standard
26788 1
26789 \end_layout
26790
26791 \end_inset
26792 </cell>
26793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26794 \begin_inset Text
26795
26796 \begin_layout Standard
26797
26798 \family typewriter
26799 \shape slanted
26800 \emph on
26801 uuuuuu uuuuuuxx xxxxxxxx
26802 \end_layout
26803
26804 \end_inset
26805 </cell>
26806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26807 \begin_inset Text
26808
26809 \begin_layout Standard
26810 a 10-bit eeprom pointer in EEPROM memory
26811 \end_layout
26812
26813 \end_inset
26814 </cell>
26815 </row>
26816 <row bottomline="true">
26817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26818 \begin_inset Text
26819
26820 \begin_layout Standard
26821 (unimplemented)
26822 \end_layout
26823
26824 \end_inset
26825 </cell>
26826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26827 \begin_inset Text
26828
26829 \begin_layout Standard
26830 1
26831 \end_layout
26832
26833 \end_inset
26834 </cell>
26835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26836 \begin_inset Text
26837
26838 \begin_layout Standard
26839 1
26840 \end_layout
26841
26842 \end_inset
26843 </cell>
26844 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26845 \begin_inset Text
26846
26847 \begin_layout Standard
26848
26849 \family typewriter
26850 \shape slanted
26851 \emph on
26852 xxxxxx xxxxxxxx xxxxxxxx
26853 \end_layout
26854
26855 \end_inset
26856 </cell>
26857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26858 \begin_inset Text
26859
26860 \begin_layout Standard
26861 unimplemented pointer type
26862 \end_layout
26863
26864 \end_inset
26865 </cell>
26866 </row>
26867 </lyxtabular>
26868
26869 \end_inset
26870
26871
26872 \end_layout
26873
26874 \begin_layout Standard
26875 Generic pointer are read and written with a set of library functions which
26876  read/write 1, 2, 3, 4 bytes.
26877 \end_layout
26878
26879 \begin_layout Subsection
26880 PIC16 C Libraries
26881 \end_layout
26882
26883 \begin_layout Subsubsection
26884 Standard I/O Streams
26885 \end_layout
26886
26887 \begin_layout Standard
26888 In the 
26889 \emph on
26890 stdio.h
26891 \emph default
26892  the type FILE is defined as:
26893 \end_layout
26894
26895 \begin_layout LyX-Code
26896 typedef char * FILE;
26897 \end_layout
26898
26899 \begin_layout Standard
26900 This type is the stream type implemented I/O in the PIC18F devices.
26901  Also the standard input and output streams are declared in stdio.h:
26902 \end_layout
26903
26904 \begin_layout LyX-Code
26905 extern FILE * stdin;
26906 \end_layout
26907
26908 \begin_layout LyX-Code
26909 extern FILE * stdout;
26910 \end_layout
26911
26912 \begin_layout Standard
26913 The FILE type is actually a generic pointer which defines one more type
26914  of generic pointers, the 
26915 \emph on
26916 stream 
26917 \emph default
26918 pointer.
26919  This new type has the format:
26920 \end_layout
26921
26922 \begin_layout Standard
26923 \align center
26924 \begin_inset Tabular
26925 <lyxtabular version="3" rows="2" columns="7">
26926 <features>
26927 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26928 <column alignment="center" valignment="top" width="0">
26929 <column alignment="center" valignment="top" leftline="true" width="0">
26930 <column alignment="center" valignment="top" leftline="true" width="0">
26931 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26932 <column alignment="center" valignment="top" width="0">
26933 <column alignment="left" valignment="top" rightline="true" width="0">
26934 <row topline="true" bottomline="true">
26935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26936 \begin_inset Text
26937
26938 \begin_layout Standard
26939 pointer type
26940 \end_layout
26941
26942 \end_inset
26943 </cell>
26944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26945 \begin_inset Text
26946
26947 \begin_layout Standard
26948 <7:6>
26949 \end_layout
26950
26951 \end_inset
26952 </cell>
26953 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26954 \begin_inset Text
26955
26956 \begin_layout Standard
26957 <5>
26958 \end_layout
26959
26960 \end_inset
26961 </cell>
26962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26963 \begin_inset Text
26964
26965 \begin_layout Standard
26966 <4>
26967 \end_layout
26968
26969 \end_inset
26970 </cell>
26971 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26972 \begin_inset Text
26973
26974 \begin_layout Standard
26975 <3:0>
26976 \end_layout
26977
26978 \end_inset
26979 </cell>
26980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26981 \begin_inset Text
26982
26983 \begin_layout Standard
26984 rest of the pointer
26985 \end_layout
26986
26987 \end_inset
26988 </cell>
26989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26990 \begin_inset Text
26991
26992 \begin_layout Standard
26993 descrption
26994 \end_layout
26995
26996 \end_inset
26997 </cell>
26998 </row>
26999 <row topline="true" bottomline="true">
27000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27001 \begin_inset Text
27002
27003 \begin_layout Standard
27004 stream
27005 \end_layout
27006
27007 \end_inset
27008 </cell>
27009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27010 \begin_inset Text
27011
27012 \begin_layout Standard
27013 00
27014 \end_layout
27015
27016 \end_inset
27017 </cell>
27018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27019 \begin_inset Text
27020
27021 \begin_layout Standard
27022 1
27023 \end_layout
27024
27025 \end_inset
27026 </cell>
27027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27028 \begin_inset Text
27029
27030 \begin_layout Standard
27031 0
27032 \end_layout
27033
27034 \end_inset
27035 </cell>
27036 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27037 \begin_inset Text
27038
27039 \begin_layout Standard
27040 nnnn
27041 \end_layout
27042
27043 \end_inset
27044 </cell>
27045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27046 \begin_inset Text
27047
27048 \begin_layout Standard
27049
27050 \family typewriter
27051 \shape slanted
27052 \emph on
27053 uuuuuuuu uuuuuuuu
27054 \end_layout
27055
27056 \end_inset
27057 </cell>
27058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27059 \begin_inset Text
27060
27061 \begin_layout Standard
27062 upper byte high nubble is 0x2n, the rest are zeroes
27063 \end_layout
27064
27065 \end_inset
27066 </cell>
27067 </row>
27068 </lyxtabular>
27069
27070 \end_inset
27071
27072
27073 \end_layout
27074
27075 \begin_layout Standard
27076 Currently implemented there are 3 types of streams defined:
27077 \end_layout
27078
27079 \begin_layout Standard
27080 \align center
27081 \begin_inset Tabular
27082 <lyxtabular version="3" rows="4" columns="4">
27083 <features>
27084 <column alignment="center" valignment="top" leftline="true" width="0">
27085 <column alignment="center" valignment="top" leftline="true" width="0">
27086 <column alignment="center" valignment="top" leftline="true" width="0">
27087 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27088 <row topline="true" bottomline="true">
27089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27090 \begin_inset Text
27091
27092 \begin_layout Standard
27093 stream type
27094 \end_layout
27095
27096 \end_inset
27097 </cell>
27098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27099 \begin_inset Text
27100
27101 \begin_layout Standard
27102 value
27103 \end_layout
27104
27105 \end_inset
27106 </cell>
27107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27108 \begin_inset Text
27109
27110 \begin_layout Standard
27111 module
27112 \end_layout
27113
27114 \end_inset
27115 </cell>
27116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27117 \begin_inset Text
27118
27119 \begin_layout Standard
27120 description
27121 \end_layout
27122
27123 \end_inset
27124 </cell>
27125 </row>
27126 <row topline="true">
27127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27128 \begin_inset Text
27129
27130 \begin_layout Standard
27131 STREAM_USART
27132 \end_layout
27133
27134 \end_inset
27135 </cell>
27136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27137 \begin_inset Text
27138
27139 \begin_layout Standard
27140
27141 \family typewriter
27142 0x200000UL
27143 \end_layout
27144
27145 \end_inset
27146 </cell>
27147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27148 \begin_inset Text
27149
27150 \begin_layout Standard
27151 USART
27152 \end_layout
27153
27154 \end_inset
27155 </cell>
27156 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27157 \begin_inset Text
27158
27159 \begin_layout Standard
27160 Writes/Reads characters via the USART peripheral
27161 \end_layout
27162
27163 \end_inset
27164 </cell>
27165 </row>
27166 <row topline="true">
27167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27168 \begin_inset Text
27169
27170 \begin_layout Standard
27171 STREAM_MSSP
27172 \end_layout
27173
27174 \end_inset
27175 </cell>
27176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27177 \begin_inset Text
27178
27179 \begin_layout Standard
27180
27181 \family typewriter
27182 0x210000UL
27183 \end_layout
27184
27185 \end_inset
27186 </cell>
27187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27188 \begin_inset Text
27189
27190 \begin_layout Standard
27191 MSSP
27192 \end_layout
27193
27194 \end_inset
27195 </cell>
27196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27197 \begin_inset Text
27198
27199 \begin_layout Standard
27200 Writes/Reads characters via the MSSP peripheral
27201 \end_layout
27202
27203 \end_inset
27204 </cell>
27205 </row>
27206 <row topline="true" bottomline="true">
27207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27208 \begin_inset Text
27209
27210 \begin_layout Standard
27211 STREAM_USER
27212 \end_layout
27213
27214 \end_inset
27215 </cell>
27216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27217 \begin_inset Text
27218
27219 \begin_layout Standard
27220
27221 \family typewriter
27222 0x2f0000UL
27223 \end_layout
27224
27225 \end_inset
27226 </cell>
27227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27228 \begin_inset Text
27229
27230 \begin_layout Standard
27231 (none)
27232 \end_layout
27233
27234 \end_inset
27235 </cell>
27236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27237 \begin_inset Text
27238
27239 \begin_layout Standard
27240 Writes/Reads characters via used defined functions
27241 \end_layout
27242
27243 \end_inset
27244 </cell>
27245 </row>
27246 </lyxtabular>
27247
27248 \end_inset
27249
27250
27251 \end_layout
27252
27253 \begin_layout Standard
27254 The stream identifiers are declared as macros in the stdio.h header.
27255 \end_layout
27256
27257 \begin_layout Standard
27258 In the libc library there exist the functions that are used to write to
27259  each of the above streams.
27260  These are
27261 \end_layout
27262
27263 \begin_layout Description
27264 _
27265 \begin_inset ERT
27266 status collapsed
27267
27268 \begin_layout Standard
27269
27270
27271 \backslash
27272 /
27273 \end_layout
27274
27275 \end_inset
27276
27277 _stream_usart_putchar writes a character at the USART stream
27278 \end_layout
27279
27280 \begin_layout Description
27281 _
27282 \begin_inset ERT
27283 status collapsed
27284
27285 \begin_layout Standard
27286
27287
27288 \backslash
27289 /
27290 \end_layout
27291
27292 \end_inset
27293
27294 _stream_mssp_putchar writes a character at the MSSP stream
27295 \end_layout
27296
27297 \begin_layout Description
27298 putchar dummy function.
27299  This writes a character to a user specified manner.
27300 \end_layout
27301
27302 \begin_layout Standard
27303 In order to increase performance 
27304 \emph on
27305 putchar 
27306 \emph default
27307 is declared in stdio.h as having its parameter in WREG (it has the wparam
27308  keyword).
27309  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27310  in a user-friendly way.
27311  
27312 \emph on
27313 arg
27314 \emph default
27315  is the name of the variable that holds the character to print.
27316  An example follows:
27317 \end_layout
27318
27319 \begin_layout LyX-Code
27320 #include <pic18fregs.h>
27321 \newline
27322 #include <stdio.h>
27323 \newline
27324
27325 \newline
27326 PUTCHAR( c )
27327 \end_layout
27328
27329 \begin_layout LyX-Code
27330 {
27331 \end_layout
27332
27333 \begin_layout LyX-Code
27334     PORTA = c;    /* dump character c to PORTA */
27335 \end_layout
27336
27337 \begin_layout LyX-Code
27338
27339 \newline
27340
27341 \newline
27342 void main(void)
27343 \end_layout
27344
27345 \begin_layout LyX-Code
27346 {
27347 \end_layout
27348
27349 \begin_layout LyX-Code
27350     stdout = STREAM_USER;    /* this is not necessary, since stdout points
27351 \end_layout
27352
27353 \begin_layout LyX-Code
27354                               * by default to STREAM_USER */
27355 \end_layout
27356
27357 \begin_layout LyX-Code
27358     printf (
27359 \begin_inset Quotes sld
27360 \end_inset
27361
27362 This is a printf test
27363 \backslash
27364 n
27365 \begin_inset Quotes srd
27366 \end_inset
27367
27368 );
27369 \end_layout
27370
27371 \begin_layout LyX-Code
27372 }
27373 \end_layout
27374
27375 \begin_layout LyX-Code
27376
27377 \end_layout
27378
27379 \begin_layout Subsubsection
27380 Printing functions
27381 \end_layout
27382
27383 \begin_layout Standard
27384 PIC16 contains an implementation of the printf-family of functions.
27385  There exist the following functions:
27386 \end_layout
27387
27388 \begin_layout LyX-Code
27389 extern unsigned int sprintf(char *buf, char *fmt, ...);
27390 \end_layout
27391
27392 \begin_layout LyX-Code
27393 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
27394 \end_layout
27395
27396 \begin_layout LyX-Code
27397
27398 \end_layout
27399
27400 \begin_layout LyX-Code
27401 extern unsigned int printf(char *fmt, ...);
27402 \end_layout
27403
27404 \begin_layout LyX-Code
27405 extern unsigned int vprintf(char *fmt, va_lista ap);
27406 \end_layout
27407
27408 \begin_layout LyX-Code
27409
27410 \end_layout
27411
27412 \begin_layout LyX-Code
27413 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
27414 \end_layout
27415
27416 \begin_layout LyX-Code
27417 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
27418 \end_layout
27419
27420 \begin_layout Standard
27421 For sprintf and vsprintf 
27422 \emph on
27423 buf 
27424 \emph default
27425 should normally be a data pointer where the resulting string will be placed.
27426  No range checking is done so the user should allocate the necessery buffer.
27427  For fprintf and vfprintf 
27428 \emph on
27429 fp
27430 \emph default
27431  should be a stream pointer (i.e.
27432  stdout, STREAM_MSSP, etc...).
27433 \end_layout
27434
27435 \begin_layout Subsubsection
27436 Signals
27437 \end_layout
27438
27439 \begin_layout Standard
27440 The PIC18F family of microcontrollers supports a number of interrupt sources.
27441  A list of these interrupts is shown in the following table:
27442 \end_layout
27443
27444 \begin_layout Standard
27445 \align center
27446 \begin_inset Tabular
27447 <lyxtabular version="3" rows="11" columns="4">
27448 <features>
27449 <column alignment="left" valignment="top" leftline="true" width="0">
27450 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27451 <column alignment="left" valignment="top" leftline="true" width="0">
27452 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27453 <row topline="true" bottomline="true">
27454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27455 \begin_inset Text
27456
27457 \begin_layout Standard
27458 signal name
27459 \end_layout
27460
27461 \end_inset
27462 </cell>
27463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27464 \begin_inset Text
27465
27466 \begin_layout Standard
27467 description
27468 \end_layout
27469
27470 \end_inset
27471 </cell>
27472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27473 \begin_inset Text
27474
27475 \begin_layout Standard
27476 signal name
27477 \end_layout
27478
27479 \end_inset
27480 </cell>
27481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27482 \begin_inset Text
27483
27484 \begin_layout Standard
27485 descritpion
27486 \end_layout
27487
27488 \end_inset
27489 </cell>
27490 </row>
27491 <row topline="true">
27492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27493 \begin_inset Text
27494
27495 \begin_layout Standard
27496 SIG_RB
27497 \end_layout
27498
27499 \end_inset
27500 </cell>
27501 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27502 \begin_inset Text
27503
27504 \begin_layout Standard
27505 PORTB change interrupt
27506 \end_layout
27507
27508 \end_inset
27509 </cell>
27510 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27511 \begin_inset Text
27512
27513 \begin_layout Standard
27514 SIG_EE
27515 \end_layout
27516
27517 \end_inset
27518 </cell>
27519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27520 \begin_inset Text
27521
27522 \begin_layout Standard
27523 EEPROM/FLASH write complete interrupt
27524 \end_layout
27525
27526 \end_inset
27527 </cell>
27528 </row>
27529 <row topline="true">
27530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27531 \begin_inset Text
27532
27533 \begin_layout Standard
27534 SIG_INT0
27535 \end_layout
27536
27537 \end_inset
27538 </cell>
27539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27540 \begin_inset Text
27541
27542 \begin_layout Standard
27543 INT0 external interrupt
27544 \end_layout
27545
27546 \end_inset
27547 </cell>
27548 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27549 \begin_inset Text
27550
27551 \begin_layout Standard
27552 SIG_BCOL
27553 \end_layout
27554
27555 \end_inset
27556 </cell>
27557 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27558 \begin_inset Text
27559
27560 \begin_layout Standard
27561 Bus collision interrupt
27562 \end_layout
27563
27564 \end_inset
27565 </cell>
27566 </row>
27567 <row topline="true">
27568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27569 \begin_inset Text
27570
27571 \begin_layout Standard
27572 SIG_INT1
27573 \end_layout
27574
27575 \end_inset
27576 </cell>
27577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27578 \begin_inset Text
27579
27580 \begin_layout Standard
27581 INT1 external interrupt
27582 \end_layout
27583
27584 \end_inset
27585 </cell>
27586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27587 \begin_inset Text
27588
27589 \begin_layout Standard
27590 SIG_LVD
27591 \end_layout
27592
27593 \end_inset
27594 </cell>
27595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27596 \begin_inset Text
27597
27598 \begin_layout Standard
27599 Low voltage detect interrupt
27600 \end_layout
27601
27602 \end_inset
27603 </cell>
27604 </row>
27605 <row topline="true">
27606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27607 \begin_inset Text
27608
27609 \begin_layout Standard
27610 SIG_INT2
27611 \end_layout
27612
27613 \end_inset
27614 </cell>
27615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27616 \begin_inset Text
27617
27618 \begin_layout Standard
27619 INT2 external interrupt
27620 \end_layout
27621
27622 \end_inset
27623 </cell>
27624 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27625 \begin_inset Text
27626
27627 \begin_layout Standard
27628 SIG_PSP
27629 \end_layout
27630
27631 \end_inset
27632 </cell>
27633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27634 \begin_inset Text
27635
27636 \begin_layout Standard
27637 Parallel slave port interrupt
27638 \end_layout
27639
27640 \end_inset
27641 </cell>
27642 </row>
27643 <row topline="true">
27644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27645 \begin_inset Text
27646
27647 \begin_layout Standard
27648 SIG_CCP1
27649 \end_layout
27650
27651 \end_inset
27652 </cell>
27653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27654 \begin_inset Text
27655
27656 \begin_layout Standard
27657 CCP1 module interrupt
27658 \end_layout
27659
27660 \end_inset
27661 </cell>
27662 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27663 \begin_inset Text
27664
27665 \begin_layout Standard
27666 SIG_AD
27667 \end_layout
27668
27669 \end_inset
27670 </cell>
27671 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27672 \begin_inset Text
27673
27674 \begin_layout Standard
27675 AD convertion complete interrupt
27676 \end_layout
27677
27678 \end_inset
27679 </cell>
27680 </row>
27681 <row topline="true">
27682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27683 \begin_inset Text
27684
27685 \begin_layout Standard
27686 SIG_CCP2
27687 \end_layout
27688
27689 \end_inset
27690 </cell>
27691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27692 \begin_inset Text
27693
27694 \begin_layout Standard
27695 CCP2 module interrupt
27696 \end_layout
27697
27698 \end_inset
27699 </cell>
27700 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27701 \begin_inset Text
27702
27703 \begin_layout Standard
27704 SIG_RC
27705 \end_layout
27706
27707 \end_inset
27708 </cell>
27709 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27710 \begin_inset Text
27711
27712 \begin_layout Standard
27713 USART receive interrupt
27714 \end_layout
27715
27716 \end_inset
27717 </cell>
27718 </row>
27719 <row topline="true">
27720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27721 \begin_inset Text
27722
27723 \begin_layout Standard
27724 SIG_TMR0
27725 \end_layout
27726
27727 \end_inset
27728 </cell>
27729 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27730 \begin_inset Text
27731
27732 \begin_layout Standard
27733 TMR0 overflow interrupt
27734 \end_layout
27735
27736 \end_inset
27737 </cell>
27738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27739 \begin_inset Text
27740
27741 \begin_layout Standard
27742 SIG_TX
27743 \end_layout
27744
27745 \end_inset
27746 </cell>
27747 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27748 \begin_inset Text
27749
27750 \begin_layout Standard
27751 USART transmit interrupt
27752 \end_layout
27753
27754 \end_inset
27755 </cell>
27756 </row>
27757 <row topline="true">
27758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27759 \begin_inset Text
27760
27761 \begin_layout Standard
27762 SIG_TMR1
27763 \end_layout
27764
27765 \end_inset
27766 </cell>
27767 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27768 \begin_inset Text
27769
27770 \begin_layout Standard
27771 TMR1 overflow interrupt
27772 \end_layout
27773
27774 \end_inset
27775 </cell>
27776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27777 \begin_inset Text
27778
27779 \begin_layout Standard
27780 SIG_MSSP
27781 \end_layout
27782
27783 \end_inset
27784 </cell>
27785 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27786 \begin_inset Text
27787
27788 \begin_layout Standard
27789 SSP receive/transmit interrupt
27790 \end_layout
27791
27792 \end_inset
27793 </cell>
27794 </row>
27795 <row topline="true">
27796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27797 \begin_inset Text
27798
27799 \begin_layout Standard
27800 SIG_TMR2
27801 \end_layout
27802
27803 \end_inset
27804 </cell>
27805 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27806 \begin_inset Text
27807
27808 \begin_layout Standard
27809 TMR2 matches PR2 interrupt
27810 \end_layout
27811
27812 \end_inset
27813 </cell>
27814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27815 \begin_inset Text
27816
27817 \begin_layout Standard
27818
27819 \end_layout
27820
27821 \end_inset
27822 </cell>
27823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27824 \begin_inset Text
27825
27826 \begin_layout Standard
27827
27828 \end_layout
27829
27830 \end_inset
27831 </cell>
27832 </row>
27833 <row topline="true" bottomline="true">
27834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27835 \begin_inset Text
27836
27837 \begin_layout Standard
27838 SIG_TMR3
27839 \end_layout
27840
27841 \end_inset
27842 </cell>
27843 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27844 \begin_inset Text
27845
27846 \begin_layout Standard
27847 TMR3 overflow interrupt
27848 \end_layout
27849
27850 \end_inset
27851 </cell>
27852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27853 \begin_inset Text
27854
27855 \begin_layout Standard
27856
27857 \end_layout
27858
27859 \end_inset
27860 </cell>
27861 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27862 \begin_inset Text
27863
27864 \begin_layout Standard
27865
27866 \end_layout
27867
27868 \end_inset
27869 </cell>
27870 </row>
27871 </lyxtabular>
27872
27873 \end_inset
27874
27875
27876 \end_layout
27877
27878 \begin_layout Standard
27879 The prototypes for these names are defined in the header file 
27880 \emph on
27881 signal.h
27882 \emph default
27883  .
27884 \end_layout
27885
27886 \begin_layout Standard
27887 In order to simplify signal handling, a number of macros is provided:
27888 \end_layout
27889
27890 \begin_layout List
27891 \labelwidthstring 00.00.0000
27892 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27893  high priority interrupts.
27894  
27895 \emph on
27896 name
27897 \emph default
27898  is the function name to use.
27899 \end_layout
27900
27901 \begin_layout List
27902 \labelwidthstring 00.00.0000
27903 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27904  low priority interrupt.
27905  
27906 \emph on
27907 name
27908 \emph default
27909  is the function name to use.
27910 \end_layout
27911
27912 \begin_layout List
27913 \labelwidthstring 00.00.0000
27914 DEF_HANDLER(sig,handler) define a handler for signal 
27915 \emph on
27916 sig.
27917 \end_layout
27918
27919 \begin_layout List
27920 \labelwidthstring 00.00.0000
27921 END_DEF end the declaration of the dispatch table.
27922 \end_layout
27923
27924 \begin_layout Standard
27925 Additionally there are two more macros to simplify the declaration of the
27926  signal handler:
27927 \end_layout
27928
27929 \begin_layout List
27930 \labelwidthstring 00.00.0000
27931
27932 \series medium
27933 SIGHANDLER(handler) 
27934 \series default
27935 this declares the function prototype for the 
27936 \emph on
27937 handler
27938 \emph default
27939  function.
27940 \end_layout
27941
27942 \begin_layout List
27943 \labelwidthstring 00.00.0000
27944 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27945 \end_layout
27946
27947 \begin_layout Standard
27948 An example of using the macros above is shown below:
27949 \end_layout
27950
27951 \begin_layout LyX-Code
27952 #include <pic18fregs.h>
27953 \end_layout
27954
27955 \begin_layout LyX-Code
27956 #include <signal.h>
27957 \newline
27958
27959 \newline
27960 DEF_INTHIGH(high_int)
27961 \end_layout
27962
27963 \begin_layout LyX-Code
27964 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27965 \end_layout
27966
27967 \begin_layout LyX-Code
27968 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27969 \end_layout
27970
27971 \begin_layout LyX-Code
27972 END_DEF
27973 \newline
27974
27975 \newline
27976 SIGHANDLER(_tmr0_handler)
27977 \end_layout
27978
27979 \begin_layout LyX-Code
27980 {
27981 \end_layout
27982
27983 \begin_layout LyX-Code
27984   /* action to be taken when timer 0 overflows */
27985 \end_layout
27986
27987 \begin_layout LyX-Code
27988 }
27989 \newline
27990
27991 \newline
27992 SIGHANDLERNAKED(_bcol_handler)
27993 \end_layout
27994
27995 \begin_layout LyX-Code
27996 {
27997 \end_layout
27998
27999 \begin_layout LyX-Code
28000   _asm
28001 \end_layout
28002
28003 \begin_layout LyX-Code
28004     /* action to be taken when bus collision occurs */
28005 \end_layout
28006
28007 \begin_layout LyX-Code
28008     retfie
28009 \end_layout
28010
28011 \begin_layout LyX-Code
28012  _endasm;
28013 \end_layout
28014
28015 \begin_layout LyX-Code
28016 }
28017 \end_layout
28018
28019 \begin_layout Standard
28020
28021 \series bold
28022 NOTES:
28023 \series default
28024  Special care should be taken when using the above scheme:
28025 \end_layout
28026
28027 \begin_layout Itemize
28028 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
28029 \end_layout
28030
28031 \begin_layout Itemize
28032 when declaring SIGHANDLERNAKED handler never forget to use 
28033 \emph on
28034 retfie
28035 \emph default
28036  for proper returning.
28037 \end_layout
28038
28039 \begin_layout Subsection
28040 PIC16 Port -- Tips
28041 \end_layout
28042
28043 \begin_layout Standard
28044 Here you can find some general tips for compiling programs with SDCC/pic16.
28045 \end_layout
28046
28047 \begin_layout Subsubsection
28048 Stack size
28049 \end_layout
28050
28051 \begin_layout Standard
28052 The default stack
28053 \begin_inset LatexCommand \index{PIC16!stack}
28054
28055 \end_inset
28056
28057  size (that is 64 bytes) probably is enough for many programs.
28058  One must take care that when there are many levels of function nesting,
28059  or there is excessive usage of stack, its size should be extended.
28060  An example of such a case is the printf/sprintf family of functions.
28061  If you encounter problems like not being able to print integers, then you
28062  need to set the stack size around the maximum (256 for small stack model).
28063  The following diagram shows what happens when calling printf to print an
28064  integer:
28065 \end_layout
28066
28067 \begin_layout LyX-Code
28068 printf () --> ltoa () --> ultoa () --> divschar ()
28069 \end_layout
28070
28071 \begin_layout Standard
28072 It is should be understood that stack is easily consumed when calling complicate
28073 d functions.
28074  Using command line arguments like -
28075 \begin_inset ERT
28076 status collapsed
28077
28078 \begin_layout Standard
28079
28080
28081 \backslash
28082 /
28083 \end_layout
28084
28085 \end_inset
28086
28087 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
28088  stack frames.
28089  Other ways to reduce stack usage may exist.
28090 \end_layout
28091
28092 \begin_layout Subsection
28093 Known Bugs
28094 \end_layout
28095
28096 \begin_layout Standard
28097 The PIC16 Port currently does not pass SDCC's regression test
28098 \begin_inset LatexCommand \index{Regression test (PIC16)}
28099
28100 \end_inset
28101
28102  suite (see section 
28103 \begin_inset LatexCommand \ref{sec:Quality-control}
28104
28105 \end_inset
28106
28107 ) and thus the snapshot build regression tests for the PIC16 target are
28108  currently disabled for all hosts
28109 \emph on
28110 .
28111 \end_layout
28112
28113 \begin_layout Chapter
28114 Debugging
28115 \end_layout
28116
28117 \begin_layout Standard
28118 There are several approaches to debugging your code.
28119  This chapter is meant to show your options and to give detail on some of
28120  them:
28121 \newline
28122
28123 \newline
28124 When writing your code:
28125 \end_layout
28126
28127 \begin_layout Itemize
28128 write your code with debugging in mind (avoid duplicating code, put conceptually
28129  similar variables into structs, use structured code, have strategic points
28130  within your code where all variables are consistent, ...)
28131 \end_layout
28132
28133 \begin_layout Itemize
28134 run a syntax-checking tool like splint
28135 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28136
28137 \end_inset
28138
28139
28140 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28141
28142 \end_inset
28143
28144  (see -
28145 \begin_inset ERT
28146 status collapsed
28147
28148 \begin_layout Standard
28149
28150
28151 \backslash
28152 /
28153 \end_layout
28154
28155 \end_inset
28156
28157 -more-pedantic 
28158 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28159
28160 \end_inset
28161
28162 ) over the code.
28163 \end_layout
28164
28165 \begin_layout Itemize
28166 for the high level code use a C-compiler (like f.e.
28167  GCC) to compile run and debug the code on your host.
28168  See (see -
28169 \begin_inset ERT
28170 status collapsed
28171
28172 \begin_layout Standard
28173
28174
28175 \backslash
28176 /
28177 \end_layout
28178
28179 \end_inset
28180
28181 -more-pedantic 
28182 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28183
28184 \end_inset
28185
28186 ) on how to handle syntax extensions like __xdata, __at(), ...
28187  
28188 \end_layout
28189
28190 \begin_layout Itemize
28191 use another C-compiler to compile code for your target.
28192  Always an option but not recommended:) And not very likely to help you.
28193  If you seriously consider walking this path you should at least occasionally
28194  check portability of your code.
28195  Most commercial compiler vendors will offer an evaluation version so you
28196  can test compile your code or snippets of your code.
28197 \end_layout
28198
28199 \begin_layout Standard
28200 Debugging on a simulator:
28201 \end_layout
28202
28203 \begin_layout Itemize
28204 there is a separate section about SDCDB (section 
28205 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28206
28207 \end_inset
28208
28209 ) below.
28210 \end_layout
28211
28212 \begin_layout Itemize
28213 or (8051 specific) use a freeware/commercial simulator which interfaces
28214  to the AOMF
28215 \begin_inset LatexCommand \index{AOMF, AOMF51}
28216
28217 \end_inset
28218
28219  file (see 
28220 \begin_inset LatexCommand \ref{OMF file}
28221
28222 \end_inset
28223
28224 ) optionally generated by SDCC.
28225 \end_layout
28226
28227 \begin_layout Standard
28228 Debugging On-target: 
28229 \end_layout
28230
28231 \begin_layout Itemize
28232 use a MCU port pin to serially output debug data to the RS232 port of your
28233  host.
28234  You'll probably want some level shifting device typically involving a MAX232
28235  or similar IC.
28236  If the hardware serial port of the MCU is not available search for 'Software
28237  UART' in your favourite search machine.
28238 \end_layout
28239
28240 \begin_layout Itemize
28241 use an on-target monitor.
28242  In this context a monitor is a small program which usually accepts commands
28243  via a serial line and allows to set program counter, to single step through
28244  a program and read/write memory locations.
28245  For the 8051 good examples of monitors are paulmon and cmon51 (see section
28246  
28247 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28248
28249 \end_inset
28250
28251 ).
28252 \end_layout
28253
28254 \begin_layout Itemize
28255 toggle MCU port pins at strategic points within your code and use an oscilloscop
28256 e.
28257  A 
28258 \emph on
28259 digital oscilloscope
28260 \emph default
28261
28262 \begin_inset LatexCommand \index{Oscilloscope}
28263
28264 \end_inset
28265
28266  with deep trace memory is really helpful especially if you have to debug
28267  a realtime application.
28268  If you need to monitor more pins than your oscilloscope provides you can
28269  sometimes get away with a small R-2R network.
28270  On a single channel oscilloscope you could f.e.
28271  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28272 k
28273 \begin_inset Formula $\Omega$
28274 \end_inset
28275
28276  resistor and the other one by a 5\InsetSpace ~
28277 k
28278 \begin_inset Formula $\Omega$
28279 \end_inset
28280
28281  resistor to the oscilloscope probe (check output drive capability of the
28282  pins you want to monitor).
28283  If you need to monitor many more pins a 
28284 \emph on
28285 logic analyzer
28286 \emph default
28287  will be handy.
28288 \end_layout
28289
28290 \begin_layout Itemize
28291 use an ICE (
28292 \emph on
28293 i
28294 \emph default
28295
28296 \emph on
28297 c
28298 \emph default
28299 ircuit 
28300 \emph on
28301 e
28302 \emph default
28303 mulator
28304 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28305
28306 \end_inset
28307
28308 ).
28309  Usually very expensive.
28310  And very nice to have too.
28311  And usually locks you (for years...) to the devices the ICE can emulate.
28312  
28313 \end_layout
28314
28315 \begin_layout Itemize
28316 use a remote debugger.
28317  In most 8-bit systems the symbol information is not available on the target,
28318  and a complete debugger is too bulky for the target system.
28319  Therefore usually a debugger on the host system connects to an on-target
28320  debugging stub which accepts only primitive commands.
28321  
28322 \newline
28323 Terms to enter into your favourite search engine could be 'remote debugging',
28324  'gdb stub' or 'inferior debugger'.
28325  (is there one?)
28326 \end_layout
28327
28328 \begin_layout Itemize
28329 use an on target hardware debugger.
28330  Some of the more modern MCUs include hardware support for setting break
28331  points and monitoring/changing variables by using dedicated hardware pins.
28332  This facility doesn't require additional code to run on the target and
28333  
28334 \emph on
28335 usually
28336 \emph default
28337  doesn't affect runtime behaviour until a breakpoint is hit.
28338  For the mcs51 most hardware debuggers use the AOMF
28339 \begin_inset LatexCommand \index{AOMF, AOMF51}
28340
28341 \end_inset
28342
28343  file (see 
28344 \begin_inset LatexCommand \ref{OMF file}
28345
28346 \end_inset
28347
28348 ) as input file.
28349  
28350 \end_layout
28351
28352 \begin_layout Standard
28353 Last not least:
28354 \end_layout
28355
28356 \begin_layout Itemize
28357 if you are not familiar with any of the following terms you're likely to
28358  run into problems rather sooner than later: 
28359 \emph on
28360 volatile
28361 \emph default
28362
28363 \emph on
28364 atomic
28365 \emph default
28366
28367 \emph on
28368 memory map
28369 \emph default
28370
28371 \emph on
28372 overlay
28373 \emph default
28374 .
28375  As an embedded programmer you 
28376 \emph on
28377 have
28378 \emph default
28379  to know them so why not look them up 
28380 \emph on
28381 before
28382 \emph default
28383  you have problems?)
28384 \end_layout
28385
28386 \begin_layout Itemize
28387 tell someone else about your problem (actually this is a surprisingly effective
28388  means to hunt down the bug even if the listener is not familiar with your
28389  environment).
28390  As 'failure to communicate' is probably one of the job-induced deformations
28391  of an embedded programmer this is highly encouraged.
28392 \end_layout
28393
28394 \begin_layout Section
28395 Debugging with SDCDB
28396 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
28397
28398 \end_inset
28399
28400
28401 \begin_inset LatexCommand \index{SDCDB (debugger)}
28402
28403 \end_inset
28404
28405  
28406 \end_layout
28407
28408 \begin_layout Standard
28409 SDCC is distributed with a source level debugger
28410 \begin_inset LatexCommand \index{Debugger}
28411
28412 \end_inset
28413
28414 .
28415  The debugger uses a command line interface, the command repertoire of the
28416  debugger has been kept as close to gdb
28417 \begin_inset LatexCommand \index{gdb}
28418
28419 \end_inset
28420
28421  (the GNU debugger) as possible.
28422  The configuration and build process is part of the standard compiler installati
28423 on, which also builds and installs the debugger in the target directory
28424  specified during configuration.
28425  The debugger allows you debug BOTH at the C source and at the ASM source
28426  level.
28427 \end_layout
28428
28429 \begin_layout Subsection
28430 Compiling for Debugging
28431 \end_layout
28432
28433 \begin_layout Standard
28434 The -
28435 \begin_inset ERT
28436 status collapsed
28437
28438 \begin_layout Standard
28439
28440
28441 \backslash
28442 /
28443 \end_layout
28444
28445 \end_inset
28446
28447 -debug
28448 \begin_inset LatexCommand \index{-\/-debug}
28449
28450 \end_inset
28451
28452  option must be specified for all files for which debug information is to
28453  be generated.
28454  The compiler generates a .adb file for each of these files.
28455  The linker creates the .cdb
28456 \begin_inset LatexCommand \index{<file>.cdb}
28457
28458 \end_inset
28459
28460  file from the .adb
28461 \begin_inset LatexCommand \index{<file>.adb}
28462
28463 \end_inset
28464
28465  files and the address information.
28466  This .cdb is used by the debugger.
28467 \end_layout
28468
28469 \begin_layout Subsection
28470 How the Debugger Works
28471 \end_layout
28472
28473 \begin_layout Standard
28474 When the -
28475 \begin_inset ERT
28476 status collapsed
28477
28478 \begin_layout Standard
28479
28480
28481 \backslash
28482 /
28483 \end_layout
28484
28485 \end_inset
28486
28487 -debug option is specified the compiler generates extra symbol information
28488  some of which are put into the assembler source and some are put into the
28489  .adb file.
28490  Then the linker creates the .cdb file from the individual .adb files with
28491  the address information for the symbols.
28492  The debugger reads the symbolic information generated by the compiler &
28493  the address information generated by the linker.
28494  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
28495  execution is controlled by the debugger.
28496  When a command is issued for the debugger, it translates it into appropriate
28497  commands for the simulator.
28498  (Currently SDCDM only connects to the simulator but 
28499 \emph on
28500 newcdb
28501 \emph default
28502  at 
28503 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
28504
28505 \end_inset
28506
28507  is an effort to connect directly to the hardware.) 
28508 \end_layout
28509
28510 \begin_layout Subsection
28511 Starting the Debugger SDCDB
28512 \end_layout
28513
28514 \begin_layout Standard
28515 The debugger can be started using the following command line.
28516  (Assume the file you are debugging has the file name foo).
28517 \newline
28518
28519 \newline
28520
28521 \family sans
28522 \series bold
28523 sdcdb foo
28524 \newline
28525
28526 \family default
28527 \series default
28528
28529 \newline
28530 The debugger will look for the following files.
28531 \end_layout
28532
28533 \begin_layout Itemize
28534 foo.c - the source file.
28535 \end_layout
28536
28537 \begin_layout Itemize
28538 foo.cdb - the debugger symbol information file.
28539 \end_layout
28540
28541 \begin_layout Itemize
28542 foo.ihx - the Intel hex format
28543 \begin_inset LatexCommand \index{Intel hex format}
28544
28545 \end_inset
28546
28547  object file.
28548 \end_layout
28549
28550 \begin_layout Subsection
28551 SDCDB Command Line Options
28552 \end_layout
28553
28554 \begin_layout Itemize
28555 -
28556 \begin_inset ERT
28557 status collapsed
28558
28559 \begin_layout Standard
28560
28561
28562 \backslash
28563 /
28564 \end_layout
28565
28566 \end_inset
28567
28568 -directory=<source file directory> this option can used to specify the directory
28569  search list.
28570  The debugger will look into the directory list specified for source, cdb
28571  & ihx files.
28572  The items in the directory list must be separated by ':', e.g.
28573  if the source files can be in the directories /home/src1 and /home/src2,
28574  the -
28575 \begin_inset ERT
28576 status collapsed
28577
28578 \begin_layout Standard
28579
28580
28581 \backslash
28582 /
28583 \end_layout
28584
28585 \end_inset
28586
28587 -directory option should be -
28588 \begin_inset ERT
28589 status collapsed
28590
28591 \begin_layout Standard
28592
28593
28594 \backslash
28595 /
28596 \end_layout
28597
28598 \end_inset
28599
28600 -directory=/home/src1:/home/src2.
28601  Note there can be no spaces in the option.
28602  
28603 \end_layout
28604
28605 \begin_layout Itemize
28606 -cd <directory> - change to the <directory>.
28607 \end_layout
28608
28609 \begin_layout Itemize
28610 -fullname - used by GUI front ends.
28611 \end_layout
28612
28613 \begin_layout Itemize
28614 -cpu <cpu-type> - this argument is passed to the simulator please see the
28615  simulator docs for details.
28616 \end_layout
28617
28618 \begin_layout Itemize
28619 -X <Clock frequency > this options is passed to the simulator please see
28620  the simulator docs for details.
28621 \end_layout
28622
28623 \begin_layout Itemize
28624 -s <serial port file> passed to simulator see the simulator docs for details.
28625 \end_layout
28626
28627 \begin_layout Itemize
28628 -S <serial in,out> passed to simulator see the simulator docs for details.
28629 \end_layout
28630
28631 \begin_layout Itemize
28632 -k <port number> passed to simulator see the simulator docs for details.
28633 \end_layout
28634
28635 \begin_layout Subsection
28636 SDCDB Debugger Commands
28637 \end_layout
28638
28639 \begin_layout Standard
28640 As mentioned earlier the command interface for the debugger has been deliberatel
28641 y kept as close the GNU debugger gdb, as possible.
28642  This will help the integration with existing graphical user interfaces
28643  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
28644  If you use a graphical user interface for the debugger you can skip this
28645  section.
28646 \end_layout
28647
28648 \begin_layout Subsubsection*
28649 break [line | file:line | function | file:function]
28650 \end_layout
28651
28652 \begin_layout Standard
28653 Set breakpoint at specified line or function:
28654 \newline
28655
28656 \newline
28657
28658 \family sans
28659 \series bold
28660 sdcdb>break 100 
28661 \newline
28662 sdcdb>break foo.c:100
28663 \newline
28664 sdcdb>break funcfoo
28665 \newline
28666 sdcdb>break foo.c:funcfoo
28667 \end_layout
28668
28669 \begin_layout Subsubsection*
28670 clear [line | file:line | function | file:function ]
28671 \end_layout
28672
28673 \begin_layout Standard
28674 Clear breakpoint at specified line or function:
28675 \newline
28676
28677 \newline
28678
28679 \family sans
28680 \series bold
28681 sdcdb>clear 100
28682 \newline
28683 sdcdb>clear foo.c:100
28684 \newline
28685 sdcdb>clear funcfoo
28686 \newline
28687 sdcdb>clear foo.c:funcfoo
28688 \end_layout
28689
28690 \begin_layout Subsubsection*
28691 continue
28692 \end_layout
28693
28694 \begin_layout Standard
28695 Continue program being debugged, after breakpoint.
28696 \end_layout
28697
28698 \begin_layout Subsubsection*
28699 finish
28700 \end_layout
28701
28702 \begin_layout Standard
28703 Execute till the end of the current function.
28704 \end_layout
28705
28706 \begin_layout Subsubsection*
28707 delete [n]
28708 \end_layout
28709
28710 \begin_layout Standard
28711 Delete breakpoint number 'n'.
28712  If used without any option clear ALL user defined break points.
28713 \end_layout
28714
28715 \begin_layout Subsubsection*
28716 info [break | stack | frame | registers ]
28717 \end_layout
28718
28719 \begin_layout Itemize
28720 info break - list all breakpoints
28721 \end_layout
28722
28723 \begin_layout Itemize
28724 info stack - show the function call stack.
28725 \end_layout
28726
28727 \begin_layout Itemize
28728 info frame - show information about the current execution frame.
28729 \end_layout
28730
28731 \begin_layout Itemize
28732 info registers - show content of all registers.
28733 \end_layout
28734
28735 \begin_layout Subsubsection*
28736 step
28737 \end_layout
28738
28739 \begin_layout Standard
28740 Step program until it reaches a different source line.
28741  Note: pressing <return> repeats the last command.
28742 \end_layout
28743
28744 \begin_layout Subsubsection*
28745 next
28746 \end_layout
28747
28748 \begin_layout Standard
28749 Step program, proceeding through subroutine calls.
28750 \end_layout
28751
28752 \begin_layout Subsubsection*
28753 run
28754 \end_layout
28755
28756 \begin_layout Standard
28757 Start debugged program.
28758 \end_layout
28759
28760 \begin_layout Subsubsection*
28761 ptype variable 
28762 \end_layout
28763
28764 \begin_layout Standard
28765 Print type information of the variable.
28766 \end_layout
28767
28768 \begin_layout Subsubsection*
28769 print variable
28770 \end_layout
28771
28772 \begin_layout Standard
28773 print value of variable.
28774 \end_layout
28775
28776 \begin_layout Subsubsection*
28777 file filename
28778 \end_layout
28779
28780 \begin_layout Standard
28781 load the given file name.
28782  Note this is an alternate method of loading file for debugging.
28783 \end_layout
28784
28785 \begin_layout Subsubsection*
28786 frame
28787 \end_layout
28788
28789 \begin_layout Standard
28790 print information about current frame.
28791 \end_layout
28792
28793 \begin_layout Subsubsection*
28794 set srcmode
28795 \end_layout
28796
28797 \begin_layout Standard
28798 Toggle between C source & assembly source.
28799 \end_layout
28800
28801 \begin_layout Subsubsection*
28802 ! simulator command
28803 \end_layout
28804
28805 \begin_layout Standard
28806 Send the string following '!' to the simulator, the simulator response is
28807  displayed.
28808  Note the debugger does not interpret the command being sent to the simulator,
28809  so if a command like 'go' is sent the debugger can loose its execution
28810  context and may display incorrect values.
28811 \end_layout
28812
28813 \begin_layout Subsubsection*
28814 quit
28815 \end_layout
28816
28817 \begin_layout Standard
28818 "Watch me now.
28819  Iam going Down.
28820  My name is Bobby Brown"
28821 \end_layout
28822
28823 \begin_layout Subsection
28824 Interfacing SDCDB with DDD
28825 \end_layout
28826
28827 \begin_layout Standard
28828 \begin_inset Note Note
28829 status collapsed
28830
28831 \begin_layout Standard
28832 The screenshot was converted from png to eps with: 
28833 \begin_inset Quotes sld
28834 \end_inset
28835
28836 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28837 \begin_inset Quotes srd
28838 \end_inset
28839
28840  which produces a pretty compact eps file which is free from compression
28841  artifacts.
28842 \end_layout
28843
28844 \begin_layout Standard
28845 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28846  as this broke the build system on Sourceforge (pdf-file was broken.
28847  pdflatex does not accept eps files).
28848 \end_layout
28849
28850 \end_inset
28851
28852
28853 \end_layout
28854
28855 \begin_layout Standard
28856 The 
28857 \emph on
28858 p
28859 \emph default
28860 ortable 
28861 \emph on
28862 n
28863 \emph default
28864 etwork 
28865 \emph on
28866 g
28867 \emph default
28868 raphics File 
28869 \size footnotesize
28870
28871 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28872
28873 \end_inset
28874
28875
28876 \size default
28877  shows a screenshot of a debugging session with DDD
28878 \begin_inset LatexCommand \index{DDD (debugger)}
28879
28880 \end_inset
28881
28882  (Unix only) on a simulated 8032.
28883  The debugging session might not run as smoothly as the screenshot suggests.
28884  The debugger allows setting of breakpoints, displaying and changing variables,
28885  single stepping through C and assembler code.
28886  
28887 \newline
28888 The source was compiled with 
28889 \family sans
28890 \series bold
28891
28892 \newline
28893
28894 \newline
28895 sdcc -
28896 \family default
28897 \series default
28898
28899 \begin_inset ERT
28900 status collapsed
28901
28902 \begin_layout Standard
28903
28904
28905 \backslash
28906 /
28907 \end_layout
28908
28909 \end_inset
28910
28911
28912 \family sans
28913 \series bold
28914 -debug ddd_example.c
28915 \family default
28916 \series default
28917  
28918 \family sans
28919 \series bold
28920
28921 \newline
28922
28923 \family default
28924 \series default
28925
28926 \newline
28927 and DDD was invoked with 
28928 \family sans
28929 \series bold
28930
28931 \newline
28932
28933 \newline
28934 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28935 \end_layout
28936
28937 \begin_layout Standard
28938 \begin_inset Note Note
28939 status open
28940
28941 \begin_layout Standard
28942 Check that the double quotes or an apostroph within the command line survive
28943  the LyX tool chain.
28944  Previously the apostrophs got slanted in the PDF output so a cut and paste
28945  did not work.
28946 \end_layout
28947
28948 \end_inset
28949
28950
28951 \end_layout
28952
28953 \begin_layout Subsection
28954 Interfacing SDCDB with XEmacs
28955 \begin_inset LatexCommand \index{XEmacs}
28956
28957 \end_inset
28958
28959
28960 \begin_inset LatexCommand \index{Emacs}
28961
28962 \end_inset
28963
28964
28965 \end_layout
28966
28967 \begin_layout Standard
28968 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28969  sdcdb.el and sdcdbsrc.el.
28970  These two files can be found in the $(prefix)/bin directory after the installat
28971 ion is complete.
28972  These files need to be loaded into XEmacs for the interface to work.
28973  This can be done at XEmacs startup time by inserting the following into
28974  your '.xemacs' file (which can be found in your HOME directory): 
28975 \newline
28976
28977 \newline
28978
28979 \family typewriter
28980 (load-file sdcdbsrc.el) 
28981 \family default
28982
28983 \newline
28984
28985 \newline
28986 .xemacs is a lisp file so the () around the command is REQUIRED.
28987  The files can also be loaded dynamically while XEmacs is running, set the
28988  environment variable 'EMACSLOADPATH' to the installation bin directory
28989  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28990  To start the interface enter the following command: 
28991 \newline
28992
28993 \newline
28994
28995 \family sans
28996 \series bold
28997 ESC-x sdcdbsrc
28998 \family default
28999 \series default
29000
29001 \newline
29002
29003 \newline
29004 You will prompted to enter the file name to be debugged.
29005  
29006 \newline
29007
29008 \newline
29009 The command line options that are passed to the simulator directly are
29010  bound to default values in the file sdcdbsrc.el.
29011  The variables are listed below, these values maybe changed as required.
29012 \end_layout
29013
29014 \begin_layout Itemize
29015 sdcdbsrc-cpu-type '51
29016 \end_layout
29017
29018 \begin_layout Itemize
29019 sdcdbsrc-frequency '11059200
29020 \end_layout
29021
29022 \begin_layout Itemize
29023 sdcdbsrc-serial nil
29024 \end_layout
29025
29026 \begin_layout Standard
29027 The following is a list of key mapping for the debugger interface.
29028 \end_layout
29029
29030 \begin_layout Standard
29031 \InsetSpace ~
29032
29033 \family typewriter
29034
29035 \newline
29036 ;;\InsetSpace ~
29037 Current Listing :: 
29038 \newline
29039 ;;key\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 binding\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 Comment 
29076 \newline
29077 ;;---\InsetSpace ~
29078 \InsetSpace ~
29079 \InsetSpace ~
29080 \InsetSpace ~
29081 \InsetSpace ~
29082 \InsetSpace ~
29083 \InsetSpace ~
29084 \InsetSpace ~
29085 \InsetSpace ~
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 \InsetSpace ~
29103 \InsetSpace ~
29104 \InsetSpace ~
29105 \InsetSpace ~
29106 \InsetSpace ~
29107 \InsetSpace ~
29108 \InsetSpace ~
29109 \InsetSpace ~
29110 \InsetSpace ~
29111 \InsetSpace ~
29112 \InsetSpace ~
29113 -------
29114 \newline
29115 ;; 
29116 \newline
29117 ;;\InsetSpace ~
29118 n\InsetSpace ~
29119 \InsetSpace ~
29120 \InsetSpace ~
29121 \InsetSpace ~
29122 \InsetSpace ~
29123 \InsetSpace ~
29124 \InsetSpace ~
29125 \InsetSpace ~
29126 \InsetSpace ~
29127 \InsetSpace ~
29128 \InsetSpace ~
29129 \InsetSpace ~
29130 \InsetSpace ~
29131 \InsetSpace ~
29132 \InsetSpace ~
29133 sdcdb-next-fro
29134 m-src\InsetSpace ~
29135 \InsetSpace ~
29136 \InsetSpace ~
29137 \InsetSpace ~
29138 \InsetSpace ~
29139 \InsetSpace ~
29140 \InsetSpace ~
29141 \InsetSpace ~
29142 \InsetSpace ~
29143 \InsetSpace ~
29144 SDCDB next command 
29145 \newline
29146 ;;\InsetSpace ~
29147 b\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 sdcdb-back-from-src\InsetSpace ~
29163 \InsetSpace ~
29164 \InsetSpace ~
29165 \InsetSpace ~
29166 \InsetSpace ~
29167 \InsetSpace ~
29168 \InsetSpace ~
29169 \InsetSpace ~
29170 \InsetSpace ~
29171 \InsetSpace ~
29172 SDCDB back command 
29173 \newline
29174 ;;\InsetSpace ~
29175 c\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 sdcdb-cont-f
29191 rom-src\InsetSpace ~
29192 \InsetSpace ~
29193 \InsetSpace ~
29194 \InsetSpace ~
29195 \InsetSpace ~
29196 \InsetSpace ~
29197 \InsetSpace ~
29198 \InsetSpace ~
29199 \InsetSpace ~
29200 \InsetSpace ~
29201 SDCDB continue command
29202 \newline
29203 ;;\InsetSpace ~
29204 s\InsetSpace ~
29205 \InsetSpace ~
29206 \InsetSpace ~
29207 \InsetSpace ~
29208 \InsetSpace ~
29209 \InsetSpace ~
29210 \InsetSpace ~
29211 \InsetSpace ~
29212 \InsetSpace ~
29213 \InsetSpace ~
29214 \InsetSpace ~
29215 \InsetSpace ~
29216 \InsetSpace ~
29217 \InsetSpace ~
29218 \InsetSpace ~
29219 sdcdb-step-from-src\InsetSpace ~
29220 \InsetSpace ~
29221 \InsetSpace ~
29222 \InsetSpace ~
29223 \InsetSpace ~
29224 \InsetSpace ~
29225 \InsetSpace ~
29226 \InsetSpace ~
29227 \InsetSpace ~
29228 \InsetSpace ~
29229 SDCDB step command 
29230 \newline
29231 ;;\InsetSpace ~
29232 ?\InsetSpace ~
29233 \InsetSpace ~
29234 \InsetSpace ~
29235 \InsetSpace ~
29236 \InsetSpace ~
29237 \InsetSpace ~
29238 \InsetSpace ~
29239 \InsetSpace ~
29240 \InsetSpace ~
29241 \InsetSpace ~
29242 \InsetSpace ~
29243 \InsetSpace ~
29244 \InsetSpace ~
29245 \InsetSpace ~
29246 \InsetSpace ~
29247 sdcdb-w
29248 hatis-c-sexp\InsetSpace ~
29249 \InsetSpace ~
29250 \InsetSpace ~
29251 \InsetSpace ~
29252 \InsetSpace ~
29253 \InsetSpace ~
29254 \InsetSpace ~
29255 \InsetSpace ~
29256 \InsetSpace ~
29257 \InsetSpace ~
29258 SDCDB ptypecommand for data at 
29259 \newline
29260 ;;\InsetSpace ~
29261 \InsetSpace ~
29262 \InsetSpace ~
29263 \InsetSpace ~
29264 \InsetSpace ~
29265 \InsetSpace ~
29266 \InsetSpace ~
29267 \InsetSpace ~
29268 \InsetSpace ~
29269 \InsetSpace ~
29270 \InsetSpace ~
29271 \InsetSpace ~
29272 \InsetSpace ~
29273 \InsetSpace ~
29274 \InsetSpace ~
29275 \InsetSpace ~
29276 \InsetSpace ~
29277 \InsetSpace ~
29278 \InsetSpace ~
29279 \InsetSpace ~
29280 \InsetSpace ~
29281 \InsetSpace ~
29282 \InsetSpace ~
29283 \InsetSpace ~
29284 \InsetSpace ~
29285 \InsetSpace ~
29286 \InsetSpace ~
29287 \InsetSpace ~
29288 \InsetSpace ~
29289 \InsetSpace ~
29290 \InsetSpace ~
29291 \InsetSpace ~
29292 \InsetSpace ~
29293 \InsetSpace ~
29294 \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 buffer point 
29308 \newline
29309 ;;\InsetSpace ~
29310 x\InsetSpace ~
29311 \InsetSpace ~
29312 \InsetSpace ~
29313 \InsetSpace ~
29314 \InsetSpace ~
29315 \InsetSpace ~
29316 \InsetSpace ~
29317 \InsetSpace ~
29318 \InsetSpace ~
29319 \InsetSpace ~
29320 \InsetSpace ~
29321 \InsetSpace ~
29322 \InsetSpace ~
29323 \InsetSpace ~
29324 \InsetSpace ~
29325 sdcdbsrc-delete\InsetSpace ~
29326 \InsetSpace ~
29327 \InsetSpace ~
29328 \InsetSpace ~
29329 \InsetSpace ~
29330 \InsetSpace ~
29331 \InsetSpace ~
29332 \InsetSpace ~
29333 \InsetSpace ~
29334 \InsetSpace ~
29335 \InsetSpace ~
29336 \InsetSpace ~
29337 \InsetSpace ~
29338 \InsetSpace ~
29339 SDCD
29340 B Delete all breakpoints if no arg 
29341 \newline
29342 ;;\InsetSpace ~
29343 \InsetSpace ~
29344 \InsetSpace ~
29345 \InsetSpace ~
29346 \InsetSpace ~
29347 \InsetSpace ~
29348 \InsetSpace ~
29349 \InsetSpace ~
29350 \InsetSpace ~
29351 \InsetSpace ~
29352 \InsetSpace ~
29353 \InsetSpace ~
29354 \InsetSpace ~
29355 \InsetSpace ~
29356 \InsetSpace ~
29357 \InsetSpace ~
29358 \InsetSpace ~
29359 \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 \InsetSpace ~
29373 \InsetSpace ~
29374 \InsetSpace ~
29375 \InsetSpace ~
29376 \InsetSpace ~
29377 \InsetSpace ~
29378 \InsetSpace ~
29379 \InsetSpace ~
29380 \InsetSpace ~
29381 \InsetSpace ~
29382 \InsetSpace ~
29383 \InsetSpace ~
29384 \InsetSpace ~
29385 \InsetSpace ~
29386 \InsetSpace ~
29387 \InsetSpace ~
29388 \InsetSpace ~
29389 given or delete arg (C-u arg x) 
29390 \newline
29391 ;;\InsetSpace ~
29392 m\InsetSpace ~
29393 \InsetSpace ~
29394 \InsetSpace ~
29395 \InsetSpace ~
29396 \InsetSpace ~
29397 \InsetSpace ~
29398 \InsetSpace ~
29399 \InsetSpace ~
29400 \InsetSpace ~
29401 \InsetSpace ~
29402 \InsetSpace ~
29403 \InsetSpace ~
29404 \InsetSpace ~
29405 \InsetSpace ~
29406 \InsetSpace ~
29407 sdcdbsrc
29408 -frame\InsetSpace ~
29409 \InsetSpace ~
29410 \InsetSpace ~
29411 \InsetSpace ~
29412 \InsetSpace ~
29413 \InsetSpace ~
29414 \InsetSpace ~
29415 \InsetSpace ~
29416 \InsetSpace ~
29417 \InsetSpace ~
29418 \InsetSpace ~
29419 \InsetSpace ~
29420 \InsetSpace ~
29421 \InsetSpace ~
29422 \InsetSpace ~
29423 SDCDB Display current frame if no arg, 
29424 \newline
29425 ;;\InsetSpace ~
29426 \InsetSpace ~
29427 \InsetSpace ~
29428 \InsetSpace ~
29429 \InsetSpace ~
29430 \InsetSpace ~
29431 \InsetSpace ~
29432 \InsetSpace ~
29433 \InsetSpace ~
29434 \InsetSpace ~
29435 \InsetSpace ~
29436 \InsetSpace ~
29437 \InsetSpace ~
29438 \InsetSpace ~
29439 \InsetSpace ~
29440 \InsetSpace ~
29441 \InsetSpace ~
29442 \InsetSpace ~
29443 \InsetSpace ~
29444 \InsetSpace ~
29445 \InsetSpace ~
29446 \InsetSpace ~
29447 \InsetSpace ~
29448 \InsetSpace ~
29449 \InsetSpace ~
29450 \InsetSpace ~
29451 \InsetSpace ~
29452 \InsetSpace ~
29453 \InsetSpace ~
29454 \InsetSpace ~
29455 \InsetSpace ~
29456 \InsetSpace ~
29457 \InsetSpace ~
29458 \InsetSpace ~
29459 \InsetSpace ~
29460 \InsetSpace ~
29461 \InsetSpace ~
29462 \InsetSpace ~
29463 \InsetSpace ~
29464 \InsetSpace ~
29465 \InsetSpace ~
29466 \InsetSpace ~
29467 \InsetSpace ~
29468 \InsetSpace ~
29469 \InsetSpace ~
29470 \InsetSpace ~
29471 \InsetSpace ~
29472 given or display frame arg
29473  
29474 \newline
29475 ;;\InsetSpace ~
29476 \InsetSpace ~
29477 \InsetSpace ~
29478 \InsetSpace ~
29479 \InsetSpace ~
29480 \InsetSpace ~
29481 \InsetSpace ~
29482 \InsetSpace ~
29483 \InsetSpace ~
29484 \InsetSpace ~
29485 \InsetSpace ~
29486 \InsetSpace ~
29487 \InsetSpace ~
29488 \InsetSpace ~
29489 \InsetSpace ~
29490 \InsetSpace ~
29491 \InsetSpace ~
29492 \InsetSpace ~
29493 \InsetSpace ~
29494 \InsetSpace ~
29495 \InsetSpace ~
29496 \InsetSpace ~
29497 \InsetSpace ~
29498 \InsetSpace ~
29499 \InsetSpace ~
29500 \InsetSpace ~
29501 \InsetSpace ~
29502 \InsetSpace ~
29503 \InsetSpace ~
29504 \InsetSpace ~
29505 \InsetSpace ~
29506 \InsetSpace ~
29507 \InsetSpace ~
29508 \InsetSpace ~
29509 \InsetSpace ~
29510 \InsetSpace ~
29511 \InsetSpace ~
29512 \InsetSpace ~
29513 \InsetSpace ~
29514 \InsetSpace ~
29515 \InsetSpace ~
29516 \InsetSpace ~
29517 \InsetSpace ~
29518 \InsetSpace ~
29519 \InsetSpace ~
29520 \InsetSpace ~
29521 \InsetSpace ~
29522 buffer point 
29523 \newline
29524 ;;\InsetSpace ~
29525 !\InsetSpace ~
29526 \InsetSpace ~
29527 \InsetSpace ~
29528 \InsetSpace ~
29529 \InsetSpace ~
29530 \InsetSpace ~
29531 \InsetSpace ~
29532 \InsetSpace ~
29533 \InsetSpace ~
29534 \InsetSpace ~
29535 \InsetSpace ~
29536 \InsetSpace ~
29537 \InsetSpace ~
29538 \InsetSpace ~
29539 \InsetSpace ~
29540 sdcdbsrc-goto-sdcdb\InsetSpace ~
29541 \InsetSpace ~
29542 \InsetSpace ~
29543 \InsetSpace ~
29544 \InsetSpace ~
29545 \InsetSpace ~
29546 \InsetSpace ~
29547 \InsetSpace ~
29548 \InsetSpace ~
29549 \InsetSpace ~
29550 Goto the SDCDB output buffer 
29551 \newline
29552 ;;\InsetSpace ~
29553 p\InsetSpace ~
29554 \InsetSpace ~
29555 \InsetSpace ~
29556 \InsetSpace ~
29557 \InsetSpace ~
29558 \InsetSpace ~
29559 \InsetSpace ~
29560 \InsetSpace ~
29561 \InsetSpace ~
29562 \InsetSpace ~
29563 \InsetSpace ~
29564 \InsetSpace ~
29565 \InsetSpace ~
29566 \InsetSpace ~
29567 \InsetSpace ~
29568 sdcdb-prin
29569 t-c-sexp\InsetSpace ~
29570 \InsetSpace ~
29571 \InsetSpace ~
29572 \InsetSpace ~
29573 \InsetSpace ~
29574 \InsetSpace ~
29575 \InsetSpace ~
29576 \InsetSpace ~
29577 \InsetSpace ~
29578 \InsetSpace ~
29579 \InsetSpace ~
29580 SDCDB print command for data at 
29581 \newline
29582 ;;\InsetSpace ~
29583 \InsetSpace ~
29584 \InsetSpace ~
29585 \InsetSpace ~
29586 \InsetSpace ~
29587 \InsetSpace ~
29588 \InsetSpace ~
29589 \InsetSpace ~
29590 \InsetSpace ~
29591 \InsetSpace ~
29592 \InsetSpace ~
29593 \InsetSpace ~
29594 \InsetSpace ~
29595 \InsetSpace ~
29596 \InsetSpace ~
29597 \InsetSpace ~
29598 \InsetSpace ~
29599 \InsetSpace ~
29600 \InsetSpace ~
29601 \InsetSpace ~
29602 \InsetSpace ~
29603 \InsetSpace ~
29604 \InsetSpace ~
29605 \InsetSpace ~
29606 \InsetSpace ~
29607 \InsetSpace ~
29608 \InsetSpace ~
29609 \InsetSpace ~
29610 \InsetSpace ~
29611 \InsetSpace ~
29612 \InsetSpace ~
29613 \InsetSpace ~
29614 \InsetSpace ~
29615 \InsetSpace ~
29616 \InsetSpace ~
29617 \InsetSpace ~
29618 \InsetSpace ~
29619 \InsetSpace ~
29620 \InsetSpace ~
29621 \InsetSpace ~
29622 \InsetSpace ~
29623 \InsetSpace ~
29624 \InsetSpace ~
29625 \InsetSpace ~
29626 \InsetSpace ~
29627 \InsetSpace ~
29628 \InsetSpace ~
29629 buffer point 
29630 \newline
29631 ;;\InsetSpace ~
29632 g\InsetSpace ~
29633 \InsetSpace ~
29634 \InsetSpace ~
29635 \InsetSpace ~
29636 \InsetSpace ~
29637 \InsetSpace ~
29638 \InsetSpace ~
29639 \InsetSpace ~
29640 \InsetSpace ~
29641 \InsetSpace ~
29642 \InsetSpace ~
29643 \InsetSpace ~
29644 \InsetSpace ~
29645 \InsetSpace ~
29646 \InsetSpace ~
29647 sdcdbsrc-goto-sdcdb\InsetSpace ~
29648 \InsetSpace ~
29649 \InsetSpace ~
29650 \InsetSpace ~
29651 \InsetSpace ~
29652 \InsetSpace ~
29653 \InsetSpace ~
29654 \InsetSpace ~
29655 \InsetSpace ~
29656 \InsetSpace ~
29657 Got
29658 o the SDCDB output buffer 
29659 \newline
29660 ;;\InsetSpace ~
29661 t\InsetSpace ~
29662 \InsetSpace ~
29663 \InsetSpace ~
29664 \InsetSpace ~
29665 \InsetSpace ~
29666 \InsetSpace ~
29667 \InsetSpace ~
29668 \InsetSpace ~
29669 \InsetSpace ~
29670 \InsetSpace ~
29671 \InsetSpace ~
29672 \InsetSpace ~
29673 \InsetSpace ~
29674 \InsetSpace ~
29675 \InsetSpace ~
29676 sdcdbsrc-mode\InsetSpace ~
29677 \InsetSpace ~
29678 \InsetSpace ~
29679 \InsetSpace ~
29680 \InsetSpace ~
29681 \InsetSpace ~
29682 \InsetSpace ~
29683 \InsetSpace ~
29684 \InsetSpace ~
29685 \InsetSpace ~
29686 \InsetSpace ~
29687 \InsetSpace ~
29688 \InsetSpace ~
29689 \InsetSpace ~
29690 \InsetSpace ~
29691 \InsetSpace ~
29692 Toggles Sdcdbsrc mode (turns it
29693  off) 
29694 \newline
29695 ;; 
29696 \newline
29697 ;;\InsetSpace ~
29698 C-c\InsetSpace ~
29699 C-f\InsetSpace ~
29700 \InsetSpace ~
29701 \InsetSpace ~
29702 \InsetSpace ~
29703 \InsetSpace ~
29704 \InsetSpace ~
29705 \InsetSpace ~
29706 \InsetSpace ~
29707 \InsetSpace ~
29708 sdcdb-finish-from-src\InsetSpace ~
29709 \InsetSpace ~
29710 \InsetSpace ~
29711 \InsetSpace ~
29712 \InsetSpace ~
29713 \InsetSpace ~
29714 \InsetSpace ~
29715 \InsetSpace ~
29716 SDCDB finish command 
29717 \newline
29718 ;; 
29719 \newline
29720 ;;\InsetSpace ~
29721 C-x\InsetSpace ~
29722 SPC\InsetSpace ~
29723 \InsetSpace ~
29724 \InsetSpace ~
29725 \InsetSpace ~
29726 \InsetSpace ~
29727 \InsetSpace ~
29728 \InsetSpace ~
29729 \InsetSpace ~
29730 \InsetSpace ~
29731 sdcdb-brea
29732 k\InsetSpace ~
29733 \InsetSpace ~
29734 \InsetSpace ~
29735 \InsetSpace ~
29736 \InsetSpace ~
29737 \InsetSpace ~
29738 \InsetSpace ~
29739 \InsetSpace ~
29740 \InsetSpace ~
29741 \InsetSpace ~
29742 \InsetSpace ~
29743 \InsetSpace ~
29744 \InsetSpace ~
29745 \InsetSpace ~
29746 \InsetSpace ~
29747 \InsetSpace ~
29748 \InsetSpace ~
29749 \InsetSpace ~
29750 Set break for line with point 
29751 \newline
29752 ;;\InsetSpace ~
29753 ESC\InsetSpace ~
29754 t\InsetSpace ~
29755 \InsetSpace ~
29756 \InsetSpace ~
29757 \InsetSpace ~
29758 \InsetSpace ~
29759 \InsetSpace ~
29760 \InsetSpace ~
29761 \InsetSpace ~
29762 \InsetSpace ~
29763 \InsetSpace ~
29764 \InsetSpace ~
29765 sdcdbsrc-mode\InsetSpace ~
29766 \InsetSpace ~
29767 \InsetSpace ~
29768 \InsetSpace ~
29769 \InsetSpace ~
29770 \InsetSpace ~
29771 \InsetSpace ~
29772 \InsetSpace ~
29773 \InsetSpace ~
29774 \InsetSpace ~
29775 \InsetSpace ~
29776 \InsetSpace ~
29777 \InsetSpace ~
29778 \InsetSpace ~
29779 \InsetSpace ~
29780 \InsetSpace ~
29781 Toggle Sdcdbsrc mode 
29782 \newline
29783 ;;\InsetSpace ~
29784 ESC\InsetSpace ~
29785 m\InsetSpace ~
29786 \InsetSpace ~
29787 \InsetSpace ~
29788 \InsetSpace ~
29789 \InsetSpace ~
29790 \InsetSpace ~
29791 \InsetSpace ~
29792 \InsetSpace ~
29793 \InsetSpace ~
29794 \InsetSpace ~
29795 \InsetSpace ~
29796 sdc
29797 dbsrc-srcmode\InsetSpace ~
29798 \InsetSpace ~
29799 \InsetSpace ~
29800 \InsetSpace ~
29801 \InsetSpace ~
29802 \InsetSpace ~
29803 \InsetSpace ~
29804 \InsetSpace ~
29805 \InsetSpace ~
29806 \InsetSpace ~
29807 \InsetSpace ~
29808 \InsetSpace ~
29809 \InsetSpace ~
29810 Toggle list mode 
29811 \newline
29812 ;; 
29813 \newline
29814
29815 \family default
29816
29817 \newpage
29818
29819 \end_layout
29820
29821 \begin_layout Chapter
29822 TIPS
29823 \end_layout
29824
29825 \begin_layout Standard
29826 Here are a few guidelines that will help the compiler generate more efficient
29827  code, some of the tips are specific to this compiler others are generally
29828  good programming practice.
29829 \end_layout
29830
29831 \begin_layout Itemize
29832 Use the smallest data type to represent your data-value.
29833  If it is known in advance that the value is going to be less than 256 then
29834  use an 'unsigned char' instead of a 'short' or 'int'.
29835  Please note, that ANSI C requires both signed and unsigned chars to be
29836  promoted to 'signed int'
29837 \begin_inset LatexCommand \index{promotion to signed int}
29838
29839 \end_inset
29840
29841
29842 \begin_inset Marginal
29843 status collapsed
29844
29845 \begin_layout Standard
29846
29847 \series bold
29848 \InsetSpace ~
29849 !
29850 \end_layout
29851
29852 \end_inset
29853
29854  before doing any operation.
29855  This promotion
29856 \begin_inset LatexCommand \index{type promotion}
29857
29858 \end_inset
29859
29860
29861 \begin_inset LatexCommand \label{type promotion}
29862
29863 \end_inset
29864
29865  can be omitted, if the result is the same.
29866  The effect of the promotion rules together with the sign-extension is often
29867  surprising:
29868 \end_layout
29869
29870 \begin_deeper
29871 \begin_layout Verse
29872
29873 \family typewriter
29874 unsigned char uc = 0xfe;
29875 \newline
29876 if (uc * uc < 0) /* this is true! */
29877 \newline
29878 {
29879 \newline
29880 \InsetSpace ~
29881 \InsetSpace ~
29882 \InsetSpace ~
29883 \InsetSpace ~
29884 ....
29885 \newline
29886 }
29887 \end_layout
29888
29889 \begin_layout Standard
29890
29891 \family typewriter
29892 uc * uc
29893 \family default
29894  is evaluated as 
29895 \family typewriter
29896 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29897 \family default
29898 .
29899  
29900 \newline
29901 Another one:
29902 \end_layout
29903
29904 \begin_layout Verse
29905
29906 \family typewriter
29907 (unsigned char) -12 / (signed char) -3 = ...
29908 \end_layout
29909
29910 \begin_layout Standard
29911 No, the result is not 4:
29912 \end_layout
29913
29914 \begin_layout Verse
29915
29916 \family typewriter
29917 (int) (unsigned char) -12 / (int) (signed char) -3 =
29918 \newline
29919 (int) (unsigned char)
29920  0xf4 / (int) (signed char) 0xfd =
29921 \newline
29922 (int) 0x00f4 / (int) 0xfffd =
29923 \newline
29924 (int) 0x00f4
29925  / (int) 0xfffd =
29926 \newline
29927 (int) 244 / (int) -3 =
29928 \newline
29929 (int) -81 = (int) 0xffaf;
29930 \end_layout
29931
29932 \begin_layout Standard
29933 Don't complain, that gcc gives you a different result.
29934  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29935  Therefore the results are different.
29936 \newline
29937 From 
29938 \begin_inset Quotes sld
29939 \end_inset
29940
29941 comp.lang.c FAQ
29942 \begin_inset Quotes srd
29943 \end_inset
29944
29945 :
29946 \end_layout
29947
29948 \begin_layout Quote
29949
29950 \emph on
29951 If well-defined overflow characteristics are important and negative values
29952  are not, or if you want to steer clear of sign-extension problems when
29953  manipulating bits or bytes, use one of the corresponding unsigned types.
29954  (Beware when mixing signed and unsigned values in expressions, though.)
29955 \newline
29956 Although
29957  character types (especially unsigned char) can be used as "tiny" integers,
29958  doing so is sometimes more trouble than it's worth, due to unpredictable
29959  sign extension and increased code size.
29960 \end_layout
29961
29962 \end_deeper
29963 \begin_layout Itemize
29964 Use unsigned when it is known in advance that the value is not going to
29965  be negative.
29966  This helps especially if you are doing division or multiplication, bit-shifting
29967  or are using an array index.
29968 \end_layout
29969
29970 \begin_layout Itemize
29971 NEVER jump into a LOOP.
29972 \end_layout
29973
29974 \begin_layout Itemize
29975 Declare the variables to be local
29976 \begin_inset LatexCommand \index{local variables}
29977
29978 \end_inset
29979
29980  whenever possible, especially loop control variables (induction).
29981 \end_layout
29982
29983 \begin_layout Itemize
29984 Have a look at the assembly listing to get a 
29985 \begin_inset Quotes sld
29986 \end_inset
29987
29988 feeling
29989 \begin_inset Quotes srd
29990 \end_inset
29991
29992  for the code generation.
29993 \end_layout
29994
29995 \begin_layout Section
29996 Porting code from or to other compilers
29997 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29998
29999 \end_inset
30000
30001
30002 \end_layout
30003
30004 \begin_layout Itemize
30005 check whether endianness of the compilers differs and adapt where needed.
30006 \end_layout
30007
30008 \begin_layout Itemize
30009 check the device specific header files
30010 \begin_inset LatexCommand \index{Header files}
30011
30012 \end_inset
30013
30014
30015 \begin_inset LatexCommand \index{Include files}
30016
30017 \end_inset
30018
30019  for compiler specific syntax.
30020  Eventually include the file <compiler.h
30021 \begin_inset LatexCommand \index{compiler.h (include file)}
30022
30023 \end_inset
30024
30025
30026 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
30027
30028 \end_inset
30029
30030  to allow using common header files.
30031  (see f.e.
30032  cc2510fx.h 
30033 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
30034
30035 \end_inset
30036
30037 ).
30038 \end_layout
30039
30040 \begin_layout Itemize
30041 check whether the startup code contains the correct initialization (watchdog,
30042  peripherals).
30043 \end_layout
30044
30045 \begin_layout Itemize
30046 check whether the sizes of short, int, long match.
30047 \end_layout
30048
30049 \begin_layout Itemize
30050 check if some 16 or 32 bit hardware registers require a specific addressing
30051  order (least significant or most significant byte first) and adapt if needed
30052  (
30053 \emph on
30054 first
30055 \emph default
30056  and 
30057 \emph on
30058 last
30059 \emph default
30060  relate to time and not to lower/upper memory location here, so this is
30061  
30062 \emph on
30063 not
30064 \emph default
30065  the same as endianness).
30066 \end_layout
30067
30068 \begin_layout Itemize
30069 check whether the keyword 
30070 \emph on
30071 volatile
30072 \emph default
30073  is used where needed.
30074  The compilers might differ in their optimization characteristics (as different
30075  versions of the same compiler might also use more clever optimizations
30076  this is good idea anyway).
30077  See section 
30078 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
30079
30080 \end_inset
30081
30082 .
30083 \end_layout
30084
30085 \begin_layout Itemize
30086 check that the compilers are not told to supress warnings.
30087 \end_layout
30088
30089 \begin_layout Itemize
30090 check and convert compiler specific extensions (interrupts, memory areas,
30091  pragmas etc.).
30092 \end_layout
30093
30094 \begin_layout Itemize
30095 check for differences in type promotion.
30096  Especially check for math operations on 
30097 \family typewriter
30098 char
30099 \family default
30100  or 
30101 \family typewriter
30102 unsigned char
30103 \family default
30104  variables.
30105  For the sake of C99 compatibility SDCC will probably promote these to 
30106 \family typewriter
30107 int
30108 \family default
30109  more often than other compilers.
30110  Eventually insert explicit casts to 
30111 \family typewriter
30112 (char) 
30113 \family default
30114 or
30115 \family typewriter
30116  (unsigned char)
30117 \family default
30118 .
30119  Also check that the ~\InsetSpace ~
30120 operator
30121 \begin_inset LatexCommand \index{\~\/ Operator}
30122
30123 \end_inset
30124
30125  is not used on 
30126 \family typewriter
30127 bit
30128 \begin_inset LatexCommand \index{bit}
30129
30130 \end_inset
30131
30132
30133 \family default
30134  variables, use the !\InsetSpace ~
30135 operator instead.
30136  See sections 
30137 \begin_inset LatexCommand \ref{type promotion}
30138
30139 \end_inset
30140
30141  and 
30142 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30143
30144 \end_inset
30145
30146 .
30147 \end_layout
30148
30149 \begin_layout Itemize
30150 check the assembly code generated for interrupt routines (f.e.
30151  for calls to possibly non-reentrant library functions).
30152 \end_layout
30153
30154 \begin_layout Itemize
30155 check whether timing loops result in proper timing (or preferably consider
30156  a rewrite of the code with timer based delays instead).
30157 \end_layout
30158
30159 \begin_layout Itemize
30160 check for differences in printf parameters (some compilers push (va_arg
30161 \begin_inset LatexCommand \index{vararg, va\_arg}
30162
30163 \end_inset
30164
30165 ) char variables as 
30166 \family typewriter
30167 int
30168 \family default
30169  others push them as 
30170 \family typewriter
30171 char
30172 \family default
30173 .
30174  See section 
30175 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30176
30177 \end_inset
30178
30179 ).
30180 \end_layout
30181
30182 \begin_layout Itemize
30183 check the resulting memory map
30184 \begin_inset LatexCommand \index{Memory map}
30185
30186 \end_inset
30187
30188 .
30189  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30190 ly idata, pdata, xdata).
30191  Eventually check if unexpected library functions are included.
30192 \end_layout
30193
30194 \begin_layout Section
30195 Tools
30196 \begin_inset LatexCommand \index{Tools}
30197
30198 \end_inset
30199
30200  included in the distribution
30201 \end_layout
30202
30203 \begin_layout Standard
30204 \align left
30205 \begin_inset Tabular
30206 <lyxtabular version="3" rows="12" columns="3">
30207 <features>
30208 <column alignment="left" valignment="top" leftline="true" width="0pt">
30209 <column alignment="left" valignment="top" leftline="true" width="0pt">
30210 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30211 <row topline="true" bottomline="true">
30212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30213 \begin_inset Text
30214
30215 \begin_layout Standard
30216
30217 \series bold
30218 Name
30219 \end_layout
30220
30221 \end_inset
30222 </cell>
30223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30224 \begin_inset Text
30225
30226 \begin_layout Standard
30227
30228 \series bold
30229 Purpose
30230 \end_layout
30231
30232 \end_inset
30233 </cell>
30234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30235 \begin_inset Text
30236
30237 \begin_layout Standard
30238
30239 \series bold
30240 Directory
30241 \end_layout
30242
30243 \end_inset
30244 </cell>
30245 </row>
30246 <row topline="true">
30247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30248 \begin_inset Text
30249
30250 \begin_layout Standard
30251 uCsim
30252 \begin_inset LatexCommand \index{uCsim}
30253
30254 \end_inset
30255
30256
30257 \end_layout
30258
30259 \end_inset
30260 </cell>
30261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30262 \begin_inset Text
30263
30264 \begin_layout Standard
30265 Simulator for various architectures
30266 \end_layout
30267
30268 \end_inset
30269 </cell>
30270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30271 \begin_inset Text
30272
30273 \begin_layout Standard
30274 sdcc/sim/ucsim
30275 \end_layout
30276
30277 \end_inset
30278 </cell>
30279 </row>
30280 <row topline="true">
30281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30282 \begin_inset Text
30283
30284 \begin_layout Standard
30285 keil2sdcc.pl
30286 \end_layout
30287
30288 \end_inset
30289 </cell>
30290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30291 \begin_inset Text
30292
30293 \begin_layout Standard
30294 header file
30295 \begin_inset LatexCommand \index{Header files}
30296
30297 \end_inset
30298
30299
30300 \begin_inset LatexCommand \index{Include files}
30301
30302 \end_inset
30303
30304  conversion
30305 \end_layout
30306
30307 \end_inset
30308 </cell>
30309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30310 \begin_inset Text
30311
30312 \begin_layout Standard
30313 sdcc/support/scripts
30314 \end_layout
30315
30316 \end_inset
30317 </cell>
30318 </row>
30319 <row topline="true">
30320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30321 \begin_inset Text
30322
30323 \begin_layout Standard
30324 mh2h.c
30325 \end_layout
30326
30327 \end_inset
30328 </cell>
30329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30330 \begin_inset Text
30331
30332 \begin_layout Standard
30333 header file conversion
30334 \end_layout
30335
30336 \end_inset
30337 </cell>
30338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30339 \begin_inset Text
30340
30341 \begin_layout Standard
30342 sdcc/support/scripts
30343 \end_layout
30344
30345 \end_inset
30346 </cell>
30347 </row>
30348 <row topline="true">
30349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30350 \begin_inset Text
30351
30352 \begin_layout Standard
30353 as-gbz80
30354 \end_layout
30355
30356 \end_inset
30357 </cell>
30358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30359 \begin_inset Text
30360
30361 \begin_layout Standard
30362 Assembler
30363 \end_layout
30364
30365 \end_inset
30366 </cell>
30367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30368 \begin_inset Text
30369
30370 \begin_layout Standard
30371
30372 \family roman
30373 \series medium
30374 \shape up
30375 \size normal
30376 \emph off
30377 \bar no
30378 \noun off
30379 \color none
30380 sdcc/bin
30381 \end_layout
30382
30383 \end_inset
30384 </cell>
30385 </row>
30386 <row topline="true">
30387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30388 \begin_inset Text
30389
30390 \begin_layout Standard
30391 as-z80
30392 \end_layout
30393
30394 \end_inset
30395 </cell>
30396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30397 \begin_inset Text
30398
30399 \begin_layout Standard
30400 Assembler
30401 \end_layout
30402
30403 \end_inset
30404 </cell>
30405 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30406 \begin_inset Text
30407
30408 \begin_layout Standard
30409
30410 \family roman
30411 \series medium
30412 \shape up
30413 \size normal
30414 \emph off
30415 \bar no
30416 \noun off
30417 \color none
30418 sdcc/bin
30419 \end_layout
30420
30421 \end_inset
30422 </cell>
30423 </row>
30424 <row topline="true">
30425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30426 \begin_inset Text
30427
30428 \begin_layout Standard
30429 asx8051
30430 \end_layout
30431
30432 \end_inset
30433 </cell>
30434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30435 \begin_inset Text
30436
30437 \begin_layout Standard
30438 Assembler
30439 \end_layout
30440
30441 \end_inset
30442 </cell>
30443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30444 \begin_inset Text
30445
30446 \begin_layout Standard
30447
30448 \family roman
30449 \series medium
30450 \shape up
30451 \size normal
30452 \emph off
30453 \bar no
30454 \noun off
30455 \color none
30456 sdcc/bin
30457 \end_layout
30458
30459 \end_inset
30460 </cell>
30461 </row>
30462 <row topline="true">
30463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30464 \begin_inset Text
30465
30466 \begin_layout Standard
30467 SDCDB
30468 \end_layout
30469
30470 \end_inset
30471 </cell>
30472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30473 \begin_inset Text
30474
30475 \begin_layout Standard
30476 Simulator
30477 \end_layout
30478
30479 \end_inset
30480 </cell>
30481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30482 \begin_inset Text
30483
30484 \begin_layout Standard
30485
30486 \family roman
30487 \series medium
30488 \shape up
30489 \size normal
30490 \emph off
30491 \bar no
30492 \noun off
30493 \color none
30494 sdcc/bin
30495 \end_layout
30496
30497 \end_inset
30498 </cell>
30499 </row>
30500 <row topline="true">
30501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30502 \begin_inset Text
30503
30504 \begin_layout Standard
30505 aslink
30506 \end_layout
30507
30508 \end_inset
30509 </cell>
30510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30511 \begin_inset Text
30512
30513 \begin_layout Standard
30514 Linker
30515 \end_layout
30516
30517 \end_inset
30518 </cell>
30519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30520 \begin_inset Text
30521
30522 \begin_layout Standard
30523
30524 \family roman
30525 \series medium
30526 \shape up
30527 \size normal
30528 \emph off
30529 \bar no
30530 \noun off
30531 \color none
30532 sdcc/bin
30533 \end_layout
30534
30535 \end_inset
30536 </cell>
30537 </row>
30538 <row topline="true">
30539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30540 \begin_inset Text
30541
30542 \begin_layout Standard
30543 link-z80
30544 \end_layout
30545
30546 \end_inset
30547 </cell>
30548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30549 \begin_inset Text
30550
30551 \begin_layout Standard
30552 Linker
30553 \end_layout
30554
30555 \end_inset
30556 </cell>
30557 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30558 \begin_inset Text
30559
30560 \begin_layout Standard
30561
30562 \family roman
30563 \series medium
30564 \shape up
30565 \size normal
30566 \emph off
30567 \bar no
30568 \noun off
30569 \color none
30570 sdcc/bin
30571 \end_layout
30572
30573 \end_inset
30574 </cell>
30575 </row>
30576 <row topline="true">
30577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30578 \begin_inset Text
30579
30580 \begin_layout Standard
30581 link-gbz80
30582 \end_layout
30583
30584 \end_inset
30585 </cell>
30586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30587 \begin_inset Text
30588
30589 \begin_layout Standard
30590 Linker
30591 \end_layout
30592
30593 \end_inset
30594 </cell>
30595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30596 \begin_inset Text
30597
30598 \begin_layout Standard
30599
30600 \family roman
30601 \series medium
30602 \shape up
30603 \size normal
30604 \emph off
30605 \bar no
30606 \noun off
30607 \color none
30608 sdcc/bin
30609 \end_layout
30610
30611 \end_inset
30612 </cell>
30613 </row>
30614 <row topline="true" bottomline="true">
30615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30616 \begin_inset Text
30617
30618 \begin_layout Standard
30619 packihx
30620 \end_layout
30621
30622 \end_inset
30623 </cell>
30624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30625 \begin_inset Text
30626
30627 \begin_layout Standard
30628 Intel Hex packer 
30629 \begin_inset LatexCommand \index{packihx (tool)}
30630
30631 \end_inset
30632
30633
30634 \end_layout
30635
30636 \end_inset
30637 </cell>
30638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30639 \begin_inset Text
30640
30641 \begin_layout Standard
30642
30643 \family roman
30644 \series medium
30645 \shape up
30646 \size normal
30647 \emph off
30648 \bar no
30649 \noun off
30650 \color none
30651 sdcc/bin
30652 \end_layout
30653
30654 \end_inset
30655 </cell>
30656 </row>
30657 </lyxtabular>
30658
30659 \end_inset
30660
30661
30662 \newline
30663
30664 \end_layout
30665
30666 \begin_layout Section
30667 Documentation
30668 \begin_inset LatexCommand \index{Documentation}
30669
30670 \end_inset
30671
30672  included in the distribution
30673 \end_layout
30674
30675 \begin_layout Standard
30676 \align left
30677 \begin_inset Tabular
30678 <lyxtabular version="3" rows="10" columns="2">
30679 <features>
30680 <column alignment="block" valignment="top" leftline="true" width="40col%">
30681 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
30682 <row topline="true" bottomline="true" endhead="true">
30683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30684 \begin_inset Text
30685
30686 \begin_layout Standard
30687
30688 \series bold
30689 Subject / Title
30690 \end_layout
30691
30692 \end_inset
30693 </cell>
30694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30695 \begin_inset Text
30696
30697 \begin_layout Standard
30698
30699 \series bold
30700 Filename / Where to get
30701 \end_layout
30702
30703 \end_inset
30704 </cell>
30705 </row>
30706 <row topline="true">
30707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30708 \begin_inset Text
30709
30710 \begin_layout Standard
30711 SDCC Compiler User Guide
30712 \end_layout
30713
30714 \end_inset
30715 </cell>
30716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30717 \begin_inset Text
30718
30719 \begin_layout Standard
30720 You're reading it right now
30721 \emph on
30722  \InsetSpace ~
30723 \InsetSpace ~
30724 \InsetSpace ~
30725
30726 \hfill
30727 online at:
30728 \emph default
30729
30730 \newline
30731
30732 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
30733
30734 \end_inset
30735
30736
30737 \end_layout
30738
30739 \end_inset
30740 </cell>
30741 </row>
30742 <row topline="true">
30743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30744 \begin_inset Text
30745
30746 \begin_layout Standard
30747 Changelog of SDCC
30748 \end_layout
30749
30750 \end_inset
30751 </cell>
30752 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30753 \begin_inset Text
30754
30755 \begin_layout Standard
30756 sdcc/Changelog
30757 \emph on
30758  \InsetSpace ~
30759 \InsetSpace ~
30760 \InsetSpace ~
30761
30762 \hfill
30763 online at:
30764 \emph default
30765
30766 \newline
30767
30768 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
30769
30770 \end_inset
30771
30772
30773 \end_layout
30774
30775 \end_inset
30776 </cell>
30777 </row>
30778 <row topline="true">
30779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30780 \begin_inset Text
30781
30782 \begin_layout Standard
30783 ASXXXX
30784 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
30785
30786 \end_inset
30787
30788
30789 \begin_inset LatexCommand \index{Assembler documentation}
30790
30791 \end_inset
30792
30793  Assemblers and
30794 \newline
30795 ASLINK
30796 \begin_inset LatexCommand \index{aslink}
30797
30798 \end_inset
30799
30800
30801 \begin_inset LatexCommand \index{Linker documentation}
30802
30803 \end_inset
30804
30805  Relocating Linker
30806 \end_layout
30807
30808 \end_inset
30809 </cell>
30810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30811 \begin_inset Text
30812
30813 \begin_layout Standard
30814 sdcc/as/doc/asxhtm.html 
30815 \emph on
30816 \InsetSpace ~
30817 \InsetSpace ~
30818 \InsetSpace ~
30819
30820 \hfill
30821 online at:
30822 \emph default
30823
30824 \newline
30825
30826 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
30827
30828 \end_inset
30829
30830
30831 \end_layout
30832
30833 \end_inset
30834 </cell>
30835 </row>
30836 <row topline="true">
30837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30838 \begin_inset Text
30839
30840 \begin_layout Standard
30841 SDCC regression test
30842 \begin_inset LatexCommand \index{Regression test}
30843
30844 \end_inset
30845
30846
30847 \end_layout
30848
30849 \end_inset
30850 </cell>
30851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30852 \begin_inset Text
30853
30854 \begin_layout Standard
30855 sdcc/doc/test_suite_spec.pdf 
30856 \emph on
30857 \InsetSpace ~
30858 \InsetSpace ~
30859 \InsetSpace ~
30860
30861 \hfill
30862 online at:
30863 \emph default
30864
30865 \newline
30866
30867 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
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 Various notes
30883 \end_layout
30884
30885 \end_inset
30886 </cell>
30887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30888 \begin_inset Text
30889
30890 \begin_layout Standard
30891 sdcc/doc/* 
30892 \emph on
30893 \InsetSpace ~
30894 \InsetSpace ~
30895 \InsetSpace ~
30896
30897 \hfill
30898 online at:
30899 \emph default
30900
30901 \newline
30902
30903 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30904
30905 \end_inset
30906
30907
30908 \end_layout
30909
30910 \end_inset
30911 </cell>
30912 </row>
30913 <row topline="true">
30914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30915 \begin_inset Text
30916
30917 \begin_layout Standard
30918 Notes on debugging with SDCDB
30919 \begin_inset LatexCommand \index{SDCDB (debugger)}
30920
30921 \end_inset
30922
30923
30924 \end_layout
30925
30926 \end_inset
30927 </cell>
30928 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30929 \begin_inset Text
30930
30931 \begin_layout Standard
30932 sdcc/debugger/README 
30933 \emph on
30934 \InsetSpace ~
30935 \InsetSpace ~
30936 \InsetSpace ~
30937
30938 \hfill
30939 online at
30940 \emph default
30941 :
30942 \newline
30943
30944 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30945
30946 \end_inset
30947
30948
30949 \end_layout
30950
30951 \end_inset
30952 </cell>
30953 </row>
30954 <row topline="true">
30955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30956 \begin_inset Text
30957
30958 \begin_layout Standard
30959 uCsim
30960 \begin_inset LatexCommand \index{uCsim}
30961
30962 \end_inset
30963
30964  Software simulator for microcontrollers
30965 \end_layout
30966
30967 \end_inset
30968 </cell>
30969 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30970 \begin_inset Text
30971
30972 \begin_layout Standard
30973
30974 \family roman
30975 \series medium
30976 \shape up
30977 \size normal
30978 \emph off
30979 \bar no
30980 \noun off
30981 \color none
30982 sdcc/sim/ucsim/doc
30983 \family default
30984 \series default
30985 \shape default
30986 \size default
30987 \emph default
30988 \bar default
30989 \noun default
30990 /index.html 
30991 \emph on
30992 \InsetSpace ~
30993 \InsetSpace ~
30994 \InsetSpace ~
30995
30996 \hfill
30997 online at:
30998 \emph default
30999
31000 \newline
31001
31002 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
31003
31004 \end_inset
31005
31006
31007 \end_layout
31008
31009 \end_inset
31010 </cell>
31011 </row>
31012 <row topline="true">
31013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31014 \begin_inset Text
31015
31016 \begin_layout Standard
31017 Temporary notes on the pic16
31018 \begin_inset LatexCommand \index{PIC16}
31019
31020 \end_inset
31021
31022  port
31023 \end_layout
31024
31025 \end_inset
31026 </cell>
31027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31028 \begin_inset Text
31029
31030 \begin_layout Standard
31031 sdcc/src/pic16/NOTES 
31032 \emph on
31033 \InsetSpace ~
31034 \InsetSpace ~
31035 \InsetSpace ~
31036
31037 \hfill
31038 online at:
31039 \newline
31040
31041 \emph default
31042
31043 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
31044
31045 \end_inset
31046
31047
31048 \end_layout
31049
31050 \end_inset
31051 </cell>
31052 </row>
31053 <row topline="true" bottomline="true">
31054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31055 \begin_inset Text
31056
31057 \begin_layout Standard
31058 SDCC internal documentation (debugging file format)
31059 \end_layout
31060
31061 \end_inset
31062 </cell>
31063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31064 \begin_inset Text
31065
31066 \begin_layout Standard
31067 sdcc/doc/
31068 \family roman
31069 \series medium
31070 \shape up
31071 \size normal
31072 \emph off
31073 \bar no
31074 \noun off
31075 \color none
31076 cdbfileformat.pd
31077 \family default
31078 \series default
31079 \shape default
31080 \size default
31081 \emph default
31082 \bar default
31083 \noun default
31084 f
31085 \emph on
31086  \InsetSpace ~
31087 \InsetSpace ~
31088 \InsetSpace ~
31089
31090 \hfill
31091 online at:
31092 \emph default
31093
31094 \newline
31095
31096 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
31097
31098 \end_inset
31099
31100
31101 \end_layout
31102
31103 \end_inset
31104 </cell>
31105 </row>
31106 </lyxtabular>
31107
31108 \end_inset
31109
31110
31111 \newline
31112
31113 \end_layout
31114
31115 \begin_layout Section
31116 Related open source tools
31117 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
31118
31119 \end_inset
31120
31121
31122 \begin_inset LatexCommand \index{Related tools}
31123
31124 \end_inset
31125
31126
31127 \end_layout
31128
31129 \begin_layout Standard
31130 \align left
31131 \begin_inset Tabular
31132 <lyxtabular version="3" rows="16" columns="3">
31133 <features>
31134 <column alignment="left" valignment="top" leftline="true" width="0pt">
31135 <column alignment="block" valignment="top" leftline="true" width="30line%">
31136 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
31137 <row topline="true" bottomline="true">
31138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31139 \begin_inset Text
31140
31141 \begin_layout Standard
31142
31143 \series bold
31144 Name
31145 \end_layout
31146
31147 \end_inset
31148 </cell>
31149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31150 \begin_inset Text
31151
31152 \begin_layout Standard
31153
31154 \series bold
31155 Purpose
31156 \end_layout
31157
31158 \end_inset
31159 </cell>
31160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31161 \begin_inset Text
31162
31163 \begin_layout Standard
31164
31165 \series bold
31166 Where to get
31167 \end_layout
31168
31169 \end_inset
31170 </cell>
31171 </row>
31172 <row topline="true">
31173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31174 \begin_inset Text
31175
31176 \begin_layout Standard
31177 gpsim
31178 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31179
31180 \end_inset
31181
31182
31183 \end_layout
31184
31185 \end_inset
31186 </cell>
31187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31188 \begin_inset Text
31189
31190 \begin_layout Standard
31191 PIC simulator
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.dattalo.com/gnupic/gpsim.html}
31201
31202 \end_inset
31203
31204
31205 \end_layout
31206
31207 \end_inset
31208 </cell>
31209 </row>
31210 <row topline="true">
31211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31212 \begin_inset Text
31213
31214 \begin_layout Standard
31215 gputils
31216 \begin_inset LatexCommand \index{gputils (pic tools)}
31217
31218 \end_inset
31219
31220
31221 \end_layout
31222
31223 \end_inset
31224 </cell>
31225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31226 \begin_inset Text
31227
31228 \begin_layout Standard
31229 GNU PIC utilities
31230 \end_layout
31231
31232 \end_inset
31233 </cell>
31234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31235 \begin_inset Text
31236
31237 \begin_layout Standard
31238 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31239
31240 \end_inset
31241
31242
31243 \end_layout
31244
31245 \end_inset
31246 </cell>
31247 </row>
31248 <row topline="true">
31249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31250 \begin_inset Text
31251
31252 \begin_layout Standard
31253 flP5
31254 \end_layout
31255
31256 \end_inset
31257 </cell>
31258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31259 \begin_inset Text
31260
31261 \begin_layout Standard
31262 PIC programmer
31263 \end_layout
31264
31265 \end_inset
31266 </cell>
31267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31268 \begin_inset Text
31269
31270 \begin_layout Standard
31271 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31272
31273 \end_inset
31274
31275
31276 \end_layout
31277
31278 \end_inset
31279 </cell>
31280 </row>
31281 <row topline="true">
31282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31283 \begin_inset Text
31284
31285 \begin_layout Standard
31286 ec2drv/newcdb
31287 \end_layout
31288
31289 \end_inset
31290 </cell>
31291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31292 \begin_inset Text
31293
31294 \begin_layout Standard
31295 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31296  (Unix only)
31297 \end_layout
31298
31299 \end_inset
31300 </cell>
31301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31302 \begin_inset Text
31303
31304 \begin_layout Standard
31305 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31306
31307 \end_inset
31308
31309
31310 \end_layout
31311
31312 \end_inset
31313 </cell>
31314 </row>
31315 <row topline="true">
31316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31317 \begin_inset Text
31318
31319 \begin_layout Standard
31320 indent
31321 \begin_inset LatexCommand \index{indent (source formatting tool)}
31322
31323 \end_inset
31324
31325
31326 \end_layout
31327
31328 \end_inset
31329 </cell>
31330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31331 \begin_inset Text
31332
31333 \begin_layout Standard
31334 Formats C source - Master of the white spaces
31335 \end_layout
31336
31337 \end_inset
31338 </cell>
31339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31340 \begin_inset Text
31341
31342 \begin_layout Standard
31343 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31344
31345 \end_inset
31346
31347
31348 \end_layout
31349
31350 \end_inset
31351 </cell>
31352 </row>
31353 <row topline="true">
31354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31355 \begin_inset Text
31356
31357 \begin_layout Standard
31358 srecord
31359 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
31360
31361 \end_inset
31362
31363
31364 \end_layout
31365
31366 \end_inset
31367 </cell>
31368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31369 \begin_inset Text
31370
31371 \begin_layout Standard
31372 Object file conversion, checksumming, ...
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 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
31382
31383 \end_inset
31384
31385
31386 \end_layout
31387
31388 \end_inset
31389 </cell>
31390 </row>
31391 <row topline="true">
31392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31393 \begin_inset Text
31394
31395 \begin_layout Standard
31396 objdump
31397 \begin_inset LatexCommand \index{objdump (tool)}
31398
31399 \end_inset
31400
31401
31402 \end_layout
31403
31404 \end_inset
31405 </cell>
31406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31407 \begin_inset Text
31408
31409 \begin_layout Standard
31410 Object file conversion, ...
31411 \end_layout
31412
31413 \end_inset
31414 </cell>
31415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31416 \begin_inset Text
31417
31418 \begin_layout Standard
31419 Part of binutils (should be there anyway)
31420 \end_layout
31421
31422 \end_inset
31423 </cell>
31424 </row>
31425 <row topline="true">
31426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31427 \begin_inset Text
31428
31429 \begin_layout Standard
31430 cmon51
31431 \end_layout
31432
31433 \end_inset
31434 </cell>
31435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31436 \begin_inset Text
31437
31438 \begin_layout Standard
31439 8051 monitor (hex up-/download, single step, disassemble)
31440 \end_layout
31441
31442 \end_inset
31443 </cell>
31444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31445 \begin_inset Text
31446
31447 \begin_layout Standard
31448 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
31449
31450 \end_inset
31451
31452
31453 \end_layout
31454
31455 \end_inset
31456 </cell>
31457 </row>
31458 <row topline="true">
31459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31460 \begin_inset Text
31461
31462 \begin_layout Standard
31463 doxygen
31464 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
31465
31466 \end_inset
31467
31468
31469 \end_layout
31470
31471 \end_inset
31472 </cell>
31473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31474 \begin_inset Text
31475
31476 \begin_layout Standard
31477 Source code documentation system
31478 \end_layout
31479
31480 \end_inset
31481 </cell>
31482 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31483 \begin_inset Text
31484
31485 \begin_layout Standard
31486 \begin_inset LatexCommand \url{http://www.doxygen.org}
31487
31488 \end_inset
31489
31490
31491 \end_layout
31492
31493 \end_inset
31494 </cell>
31495 </row>
31496 <row topline="true">
31497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31498 \begin_inset Text
31499
31500 \begin_layout Standard
31501 kdevelop
31502 \end_layout
31503
31504 \end_inset
31505 </cell>
31506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31507 \begin_inset Text
31508
31509 \begin_layout Standard
31510 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
31511 \end_layout
31512
31513 \end_inset
31514 </cell>
31515 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31516 \begin_inset Text
31517
31518 \begin_layout Standard
31519 \begin_inset LatexCommand \url{http://www.kdevelop.org}
31520
31521 \end_inset
31522
31523
31524 \end_layout
31525
31526 \end_inset
31527 </cell>
31528 </row>
31529 <row topline="true">
31530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31531 \begin_inset Text
31532
31533 \begin_layout Standard
31534 paulmon
31535 \end_layout
31536
31537 \end_inset
31538 </cell>
31539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31540 \begin_inset Text
31541
31542 \begin_layout Standard
31543 8051 monitor (hex up-/download, single step, disassemble)
31544 \end_layout
31545
31546 \end_inset
31547 </cell>
31548 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31549 \begin_inset Text
31550
31551 \begin_layout Standard
31552 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
31553
31554 \end_inset
31555
31556
31557 \end_layout
31558
31559 \end_inset
31560 </cell>
31561 </row>
31562 <row topline="true">
31563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31564 \begin_inset Text
31565
31566 \begin_layout Standard
31567 splint
31568 \begin_inset LatexCommand \index{splint (syntax checking tool)}
31569
31570 \end_inset
31571
31572
31573 \end_layout
31574
31575 \end_inset
31576 </cell>
31577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31578 \begin_inset Text
31579
31580 \begin_layout Standard
31581 Statically checks c sources (see 
31582 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
31583
31584 \end_inset
31585
31586 )
31587 \end_layout
31588
31589 \end_inset
31590 </cell>
31591 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31592 \begin_inset Text
31593
31594 \begin_layout Standard
31595 \begin_inset LatexCommand \url{http://www.splint.org}
31596
31597 \end_inset
31598
31599
31600 \end_layout
31601
31602 \end_inset
31603 </cell>
31604 </row>
31605 <row topline="true" bottomline="true">
31606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31607 \begin_inset Text
31608
31609 \begin_layout Standard
31610 ddd
31611 \begin_inset LatexCommand \index{DDD (debugger)}
31612
31613 \end_inset
31614
31615
31616 \end_layout
31617
31618 \end_inset
31619 </cell>
31620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31621 \begin_inset Text
31622
31623 \begin_layout Standard
31624 Debugger, serves nicely as GUI to SDCDB
31625 \begin_inset LatexCommand \index{SDCDB (debugger)}
31626
31627 \end_inset
31628
31629  (Unix only)
31630 \end_layout
31631
31632 \end_inset
31633 </cell>
31634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31635 \begin_inset Text
31636
31637 \begin_layout Standard
31638 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
31639
31640 \end_inset
31641
31642
31643 \end_layout
31644
31645 \end_inset
31646 </cell>
31647 </row>
31648 <row bottomline="true">
31649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31650 \begin_inset Text
31651
31652 \begin_layout Standard
31653 d52
31654 \begin_inset LatexCommand \index{d52}
31655
31656 \end_inset
31657
31658
31659 \begin_inset LatexCommand \index{d52 (disassembler)}
31660
31661 \end_inset
31662
31663
31664 \end_layout
31665
31666 \end_inset
31667 </cell>
31668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31669 \begin_inset Text
31670
31671 \begin_layout Standard
31672 Disassembler, can count instruction cycles
31673 \begin_inset LatexCommand \index{instruction cycles (count)}
31674
31675 \end_inset
31676
31677 , use with options -pnd
31678 \end_layout
31679
31680 \end_inset
31681 </cell>
31682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31683 \begin_inset Text
31684
31685 \begin_layout Standard
31686 \begin_inset LatexCommand \url{http://www.8052.com/users/disasm/}
31687
31688 \end_inset
31689
31690
31691 \end_layout
31692
31693 \end_inset
31694 </cell>
31695 </row>
31696 <row bottomline="true">
31697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31698 \begin_inset Text
31699
31700 \begin_layout Standard
31701 cmake
31702 \begin_inset LatexCommand \index{cmake}
31703
31704 \end_inset
31705
31706
31707 \end_layout
31708
31709 \end_inset
31710 </cell>
31711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31712 \begin_inset Text
31713
31714 \begin_layout Standard
31715 Cross platform build system, generates Makefiles
31716 \begin_inset LatexCommand \index{Makefile}
31717
31718 \end_inset
31719
31720  and project workspaces
31721 \begin_inset LatexCommand \index{project workspace}
31722
31723 \end_inset
31724
31725
31726 \end_layout
31727
31728 \end_inset
31729 </cell>
31730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31731 \begin_inset Text
31732
31733 \begin_layout Standard
31734 \begin_inset LatexCommand \url{http://www.cmake.org}
31735
31736 \end_inset
31737
31738  \InsetSpace ~
31739 \InsetSpace ~
31740 \InsetSpace ~
31741 \InsetSpace ~
31742 and a dedicated wiki entry: 
31743 \begin_inset LatexCommand \url{http://www.cmake.org/Wiki/CmakeSdcc}
31744
31745 \end_inset
31746
31747
31748 \end_layout
31749
31750 \end_inset
31751 </cell>
31752 </row>
31753 </lyxtabular>
31754
31755 \end_inset
31756
31757
31758 \newline
31759
31760 \end_layout
31761
31762 \begin_layout Section
31763 Related documentation / recommended reading
31764 \end_layout
31765
31766 \begin_layout Standard
31767 \align left
31768 \begin_inset Tabular
31769 <lyxtabular version="3" rows="7" columns="3">
31770 <features>
31771 <column alignment="left" valignment="top" leftline="true" width="0pt">
31772 <column alignment="left" valignment="top" leftline="true" width="0">
31773 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
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 \series bold
31781 Name
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 \series bold
31792 Subject / Title
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 \series bold
31803 Where to get
31804 \end_layout
31805
31806 \end_inset
31807 </cell>
31808 </row>
31809 <row topline="true">
31810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31811 \begin_inset Text
31812
31813 \begin_layout Standard
31814
31815 \family roman
31816 \series medium
31817 \shape up
31818 \size normal
31819 \emph off
31820 \bar no
31821 \noun off
31822 \color none
31823 c-refcard.pdf
31824 \end_layout
31825
31826 \end_inset
31827 </cell>
31828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31829 \begin_inset Text
31830
31831 \begin_layout Standard
31832 C Reference Card
31833 \begin_inset LatexCommand \index{C Reference card}
31834
31835 \end_inset
31836
31837 , 2 pages
31838 \end_layout
31839
31840 \end_inset
31841 </cell>
31842 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31843 \begin_inset Text
31844
31845 \begin_layout Standard
31846 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
31847
31848 \end_inset
31849
31850
31851 \end_layout
31852
31853 \end_inset
31854 </cell>
31855 </row>
31856 <row topline="true">
31857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31858 \begin_inset Text
31859
31860 \begin_layout Standard
31861 c-faq
31862 \end_layout
31863
31864 \end_inset
31865 </cell>
31866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31867 \begin_inset Text
31868
31869 \begin_layout Standard
31870 C-FAQ
31871 \begin_inset LatexCommand \index{C FAQ}
31872
31873 \end_inset
31874
31875
31876 \end_layout
31877
31878 \end_inset
31879 </cell>
31880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31881 \begin_inset Text
31882
31883 \begin_layout Standard
31884 \begin_inset LatexCommand \url{http://www.c-faq.com}
31885
31886 \end_inset
31887
31888
31889 \end_layout
31890
31891 \end_inset
31892 </cell>
31893 </row>
31894 <row topline="true">
31895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31896 \begin_inset Text
31897
31898 \begin_layout Standard
31899 ISO/IEC 9899:TC2
31900 \end_layout
31901
31902 \end_inset
31903 </cell>
31904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31905 \begin_inset Text
31906
31907 \begin_layout Standard
31908 \begin_inset Quotes sld
31909 \end_inset
31910
31911 C-Standard
31912 \begin_inset Quotes srd
31913 \end_inset
31914
31915
31916 \end_layout
31917
31918 \end_inset
31919 </cell>
31920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31921 \begin_inset Text
31922
31923 \begin_layout Standard
31924
31925 \size footnotesize
31926 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31927
31928 \end_inset
31929
31930
31931 \end_layout
31932
31933 \end_inset
31934 </cell>
31935 </row>
31936 <row topline="true">
31937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31938 \begin_inset Text
31939
31940 \begin_layout Standard
31941 ISO/IEC DTR 18037
31942 \end_layout
31943
31944 \end_inset
31945 </cell>
31946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31947 \begin_inset Text
31948
31949 \begin_layout Standard
31950 \begin_inset Quotes sld
31951 \end_inset
31952
31953 Extensions for Embedded C
31954 \begin_inset Quotes srd
31955 \end_inset
31956
31957
31958 \end_layout
31959
31960 \end_inset
31961 </cell>
31962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31963 \begin_inset Text
31964
31965 \begin_layout Standard
31966
31967 \size footnotesize
31968 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31969
31970 \end_inset
31971
31972
31973 \end_layout
31974
31975 \end_inset
31976 </cell>
31977 </row>
31978 <row topline="true">
31979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31980 \begin_inset Text
31981
31982 \begin_layout Standard
31983
31984 \end_layout
31985
31986 \end_inset
31987 </cell>
31988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31989 \begin_inset Text
31990
31991 \begin_layout Standard
31992 Latest datasheet of target CPU
31993 \end_layout
31994
31995 \end_inset
31996 </cell>
31997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31998 \begin_inset Text
31999
32000 \begin_layout Standard
32001 vendor
32002 \end_layout
32003
32004 \end_inset
32005 </cell>
32006 </row>
32007 <row topline="true" bottomline="true">
32008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32009 \begin_inset Text
32010
32011 \begin_layout Standard
32012
32013 \end_layout
32014
32015 \end_inset
32016 </cell>
32017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32018 \begin_inset Text
32019
32020 \begin_layout Standard
32021 Revision history of datasheet
32022 \end_layout
32023
32024 \end_inset
32025 </cell>
32026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32027 \begin_inset Text
32028
32029 \begin_layout Standard
32030 vendor
32031 \end_layout
32032
32033 \end_inset
32034 </cell>
32035 </row>
32036 </lyxtabular>
32037
32038 \end_inset
32039
32040
32041 \newline
32042
32043 \end_layout
32044
32045 \begin_layout Section
32046 Application notes specifically for SDCC
32047 \end_layout
32048
32049 \begin_layout Standard
32050 SDCC makes no claims about the completeness of this list and about up-to-datenes
32051 s or correctness of the application notes
32052 \begin_inset LatexCommand \index{Application notes}
32053
32054 \end_inset
32055
32056 .
32057 \end_layout
32058
32059 \begin_layout Standard
32060 \align left
32061
32062 \size footnotesize
32063 \begin_inset Tabular
32064 <lyxtabular version="3" rows="7" columns="3">
32065 <features>
32066 <column alignment="block" valignment="top" leftline="true" width="17col%">
32067 <column alignment="block" valignment="top" leftline="true" width="27col%">
32068 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
32069 <row topline="true" bottomline="true">
32070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32071 \begin_inset Text
32072
32073 \begin_layout Standard
32074
32075 \series bold
32076 \size footnotesize
32077 Vendor
32078 \end_layout
32079
32080 \end_inset
32081 </cell>
32082 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
32083 \begin_inset Text
32084
32085 \begin_layout Standard
32086
32087 \series bold
32088 \size footnotesize
32089 Subject / Title
32090 \end_layout
32091
32092 \end_inset
32093 </cell>
32094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32095 \begin_inset Text
32096
32097 \begin_layout Standard
32098
32099 \series bold
32100 \size footnotesize
32101 Where to get
32102 \end_layout
32103
32104 \end_inset
32105 </cell>
32106 </row>
32107 <row topline="true">
32108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32109 \begin_inset Text
32110
32111 \begin_layout Standard
32112
32113 \size footnotesize
32114 Maxim / Dallas
32115 \end_layout
32116
32117 \end_inset
32118 </cell>
32119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32120 \begin_inset Text
32121
32122 \begin_layout Standard
32123
32124 \size footnotesize
32125 Using the SDCC Compiler for the DS80C400
32126 \begin_inset LatexCommand \index{DS80C400}
32127
32128 \end_inset
32129
32130
32131 \end_layout
32132
32133 \end_inset
32134 </cell>
32135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32136 \begin_inset Text
32137
32138 \begin_layout Standard
32139
32140 \size footnotesize
32141 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
32142
32143 \end_inset
32144
32145
32146 \end_layout
32147
32148 \end_inset
32149 </cell>
32150 </row>
32151 <row topline="true">
32152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32153 \begin_inset Text
32154
32155 \begin_layout Standard
32156
32157 \size footnotesize
32158 Maxim / Dallas
32159 \end_layout
32160
32161 \end_inset
32162 </cell>
32163 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
32164 \begin_inset Text
32165
32166 \begin_layout Standard
32167
32168 \size footnotesize
32169 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
32170 \begin_inset LatexCommand \index{DS89C4x0}
32171
32172 \end_inset
32173
32174  Family of Microcontrollers
32175 \end_layout
32176
32177 \end_inset
32178 </cell>
32179 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32180 \begin_inset Text
32181
32182 \begin_layout Standard
32183
32184 \size footnotesize
32185 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
32186
32187 \end_inset
32188
32189
32190 \end_layout
32191
32192 \end_inset
32193 </cell>
32194 </row>
32195 <row topline="true">
32196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32197 \begin_inset Text
32198
32199 \begin_layout Standard
32200
32201 \size footnotesize
32202 Silicon Laboratories / Cygnal
32203 \end_layout
32204
32205 \end_inset
32206 </cell>
32207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32208 \begin_inset Text
32209
32210 \begin_layout Standard
32211
32212 \size footnotesize
32213 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
32214 \begin_inset LatexCommand \index{IDE}
32215
32216 \end_inset
32217
32218
32219 \end_layout
32220
32221 \end_inset
32222 </cell>
32223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32224 \begin_inset Text
32225
32226 \begin_layout Standard
32227
32228 \size footnotesize
32229 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
32230
32231 \end_inset
32232
32233
32234 \end_layout
32235
32236 \end_inset
32237 </cell>
32238 </row>
32239 <row topline="true">
32240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32241 \begin_inset Text
32242
32243 \begin_layout Standard
32244
32245 \size footnotesize
32246 Ramtron / Goal Semiconductor
32247 \end_layout
32248
32249 \end_inset
32250 </cell>
32251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32252 \begin_inset Text
32253
32254 \begin_layout Standard
32255
32256 \size footnotesize
32257 Interfacing SDCC to Syn and Textpad
32258 \end_layout
32259
32260 \end_inset
32261 </cell>
32262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32263 \begin_inset Text
32264
32265 \begin_layout Standard
32266
32267 \size footnotesize
32268 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32269
32270 \end_inset
32271
32272
32273 \end_layout
32274
32275 \end_inset
32276 </cell>
32277 </row>
32278 <row topline="true">
32279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32280 \begin_inset Text
32281
32282 \begin_layout Standard
32283
32284 \size footnotesize
32285 Ramtron / Goal Semiconductor
32286 \end_layout
32287
32288 \end_inset
32289 </cell>
32290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32291 \begin_inset Text
32292
32293 \begin_layout Standard
32294
32295 \size footnotesize
32296 Installing and Configuring SDCC and Crimson Editor 
32297 \end_layout
32298
32299 \end_inset
32300 </cell>
32301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32302 \begin_inset Text
32303
32304 \begin_layout Standard
32305
32306 \size footnotesize
32307 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32308
32309 \end_inset
32310
32311
32312 \end_layout
32313
32314 \end_inset
32315 </cell>
32316 </row>
32317 <row topline="true" bottomline="true">
32318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32319 \begin_inset Text
32320
32321 \begin_layout Standard
32322
32323 \size footnotesize
32324 Texas Instruments
32325 \end_layout
32326
32327 \end_inset
32328 </cell>
32329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32330 \begin_inset Text
32331
32332 \begin_layout Standard
32333
32334 \size footnotesize
32335 MSC12xx Programming with SDCC
32336 \end_layout
32337
32338 \end_inset
32339 </cell>
32340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32341 \begin_inset Text
32342
32343 \begin_layout Standard
32344
32345 \size footnotesize
32346 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
32347
32348 \end_inset
32349
32350
32351 \end_layout
32352
32353 \end_inset
32354 </cell>
32355 </row>
32356 </lyxtabular>
32357
32358 \end_inset
32359
32360
32361 \end_layout
32362
32363 \begin_layout Section
32364 Some Questions
32365 \end_layout
32366
32367 \begin_layout Standard
32368 Some questions answered, some pointers given - it might be time to in turn
32369  ask 
32370 \emph on
32371 you
32372 \emph default
32373  some questions: 
32374 \end_layout
32375
32376 \begin_layout Itemize
32377 can you solve your project with the selected microcontroller? Would you
32378  find out early or rather late that your target is too small/slow/whatever?
32379  Can you switch to a slightly better device if it doesn't fit?
32380 \end_layout
32381
32382 \begin_layout Itemize
32383 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
32384  and/or another programming language be more adequate? Would an operating
32385  system on the target device help?
32386 \end_layout
32387
32388 \begin_layout Itemize
32389 if you solved the problem, will the marketing department be happy?
32390 \end_layout
32391
32392 \begin_layout Itemize
32393 if the marketing department is happy, will customers be happy?
32394 \end_layout
32395
32396 \begin_layout Itemize
32397 if you're the project manager, marketing department and maybe even the customer
32398  in one person, have you tried to see the project from the outside?
32399 \end_layout
32400
32401 \begin_layout Itemize
32402 is the project done if you think it is done? Or is just that other interface/pro
32403 tocol/feature/configuration/option missing? How about website, manual(s),
32404  internationali(z|s)ation, packaging, labels, 2nd source for components,
32405  electromagnetic compatability/interference, documentation for production,
32406  production test software, update mechanism, patent issues?
32407 \end_layout
32408
32409 \begin_layout Itemize
32410 is your project adequately positioned in that magic triangle: fame, fortune,
32411  fun?
32412 \end_layout
32413
32414 \begin_layout Standard
32415 Maybe not all answers to these questions are known and some answers may
32416  even be 
32417 \emph on
32418 no
32419 \emph default
32420 , nevertheless knowing these questions may help you to avoid burnout
32421 \begin_inset Foot
32422 status open
32423
32424 \begin_layout Standard
32425 burnout is bad for electronic devices, programmers and motorcycle tyres
32426 \end_layout
32427
32428 \end_inset
32429
32430 .
32431  Chances are you didn't want to hear some of them...
32432 \end_layout
32433
32434 \begin_layout Chapter
32435 Support
32436 \begin_inset LatexCommand \index{Support}
32437
32438 \end_inset
32439
32440
32441 \end_layout
32442
32443 \begin_layout Standard
32444 SDCC has grown to be a large project.
32445  The compiler alone (without the preprocessor, assembler and linker) is
32446  well over 150,000 lines of code (blank stripped).
32447  The open source nature of this project is a key to its continued growth
32448  and support.
32449  You gain the benefit and support of many active software developers and
32450  end users.
32451  Is SDCC perfect? No, that's why we need your help.
32452  The developers take pride in fixing reported bugs.
32453  You can help by reporting the bugs and helping other SDCC users.
32454  There are lots of ways to contribute, and we encourage you to take part
32455  in making SDCC a great software package.
32456  
32457 \end_layout
32458
32459 \begin_layout Standard
32460 The SDCC project is hosted on the SDCC sourceforge site at 
32461 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
32462
32463 \end_inset
32464
32465 .
32466  You'll find the complete set of mailing lists
32467 \begin_inset LatexCommand \index{Mailing list(s)}
32468
32469 \end_inset
32470
32471 , forums, bug reporting system, patch submission
32472 \begin_inset LatexCommand \index{Patch submission}
32473
32474 \end_inset
32475
32476  system, download
32477 \begin_inset LatexCommand \index{download}
32478
32479 \end_inset
32480
32481  area and Subversion code repository
32482 \begin_inset LatexCommand \index{Subversion code repository}
32483
32484 \end_inset
32485
32486  there.
32487 \end_layout
32488
32489 \begin_layout Section
32490 Reporting Bugs
32491 \begin_inset LatexCommand \index{Bug reporting}
32492
32493 \end_inset
32494
32495
32496 \begin_inset LatexCommand \index{Reporting bugs}
32497
32498 \end_inset
32499
32500
32501 \end_layout
32502
32503 \begin_layout Standard
32504 The recommended way of reporting bugs is using the infrastructure of the
32505  sourceforge site.
32506  You can follow the status of bug reports there and have an overview about
32507  the known bugs.
32508 \end_layout
32509
32510 \begin_layout Standard
32511 Bug reports are automatically forwarded to the developer mailing list and
32512  will be fixed ASAP.
32513  When reporting a bug, it is very useful to include a small test program
32514  (the smaller the better) which reproduces the problem.
32515  If you can isolate the problem by looking at the generated assembly code,
32516  this can be very helpful.
32517  Compiling your program with the -
32518 \begin_inset ERT
32519 status collapsed
32520
32521 \begin_layout Standard
32522
32523
32524 \backslash
32525 /
32526 \end_layout
32527
32528 \end_inset
32529
32530 -dumpall
32531 \begin_inset LatexCommand \index{-\/-dumpall}
32532
32533 \end_inset
32534
32535  option can sometimes be useful in locating optimization problems.
32536  When reporting a bug please make sure you:
32537 \end_layout
32538
32539 \begin_layout Enumerate
32540 Attach the code you are compiling with SDCC.
32541  
32542 \end_layout
32543
32544 \begin_layout Enumerate
32545 Specify the exact command you use to run SDCC, or attach your Makefile.
32546  
32547 \end_layout
32548
32549 \begin_layout Enumerate
32550 Specify the SDCC version (type "
32551 \family sans
32552 \series bold
32553 sdcc -v
32554 \family default
32555 \series default
32556 "), your platform, and operating system.
32557  
32558 \end_layout
32559
32560 \begin_layout Enumerate
32561 Provide an exact copy of any error message or incorrect output.
32562  
32563 \end_layout
32564
32565 \begin_layout Enumerate
32566 Put something meaningful in the subject of your message.
32567 \end_layout
32568
32569 \begin_layout Standard
32570 Please attempt to include these 5 important parts, as applicable, in all
32571  requests for support or when reporting any problems or bugs with SDCC.
32572  Though this will make your message lengthy, it will greatly improve your
32573  chance that SDCC users and developers will be able to help you.
32574  Some SDCC developers are frustrated by bug reports without code provided
32575  that they can use to reproduce and ultimately fix the problem, so please
32576  be sure to provide sample code if you are reporting a bug! 
32577 \end_layout
32578
32579 \begin_layout Standard
32580 Please have a short check that you are using a recent version of SDCC and
32581  the bug is not yet known.
32582  This is the link for reporting bugs: 
32583 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
32584
32585 \end_inset
32586
32587 .
32588  With SDCC on average having more than 200 downloads
32589 \begin_inset LatexCommand \index{download}
32590
32591 \end_inset
32592
32593  on sourceforge per day
32594 \begin_inset Foot
32595 status open
32596
32597 \begin_layout Standard
32598 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
32599  between 2002 and 2005.
32600  This does not include other methods of distribution.
32601 \end_layout
32602
32603 \end_inset
32604
32605  there must be some users.
32606  So it's not exactly easy to find a new bug.
32607  If you find one we need it: 
32608 \emph on
32609 reporting bugs is good
32610 \emph default
32611 .
32612 \end_layout
32613
32614 \begin_layout Section
32615 Requesting Features
32616 \begin_inset LatexCommand \label{sub:Requesting-Features}
32617
32618 \end_inset
32619
32620
32621 \begin_inset LatexCommand \index{Feature request}
32622
32623 \end_inset
32624
32625
32626 \begin_inset LatexCommand \index{Requesting features}
32627
32628 \end_inset
32629
32630
32631 \end_layout
32632
32633 \begin_layout Standard
32634 Like bug reports feature requests are forwarded to the developer mailing
32635  list.
32636  This is the link for requesting features: 
32637 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32638
32639 \end_inset
32640
32641 .
32642 \end_layout
32643
32644 \begin_layout Section
32645 Submitting patches
32646 \end_layout
32647
32648 \begin_layout Standard
32649 Like bug reports contributed patches are forwarded to the developer mailing
32650  list.
32651  This is the link for submitting patches
32652 \begin_inset LatexCommand \index{Patch submission}
32653
32654 \end_inset
32655
32656
32657 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
32658
32659 \end_inset
32660
32661 .
32662 \end_layout
32663
32664 \begin_layout Standard
32665 You need to specify some parameters to the 
32666 \family typewriter
32667 diff
32668 \family default
32669  command for the patches to be useful.
32670  If you modified more than one file a patch created f.e.
32671  with 
32672 \family sans
32673 \series bold
32674
32675 \begin_inset Quotes sld
32676 \end_inset
32677
32678 diff -Naur unmodified_directory modified_directory >my_changes.patch
32679 \begin_inset Quotes srd
32680 \end_inset
32681
32682
32683 \family default
32684 \series default
32685  will be fine, otherwise 
32686 \family sans
32687 \series bold
32688
32689 \begin_inset Quotes sld
32690 \end_inset
32691
32692 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
32693 \begin_inset Quotes srd
32694 \end_inset
32695
32696
32697 \series default
32698  
32699 \family default
32700 will do.
32701 \end_layout
32702
32703 \begin_layout Section
32704 Getting Help
32705 \end_layout
32706
32707 \begin_layout Standard
32708 These links should take you directly to the 
32709 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
32710
32711 \end_inset
32712
32713
32714 \begin_inset Foot
32715 status open
32716
32717 \begin_layout Standard
32718 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
32719  automated messages (mid 2003)
32720 \end_layout
32721
32722 \end_inset
32723
32724  and the 
32725 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
32726
32727 \end_inset
32728
32729 , lists
32730 \begin_inset LatexCommand \index{Mailing list(s)}
32731
32732 \end_inset
32733
32734  and forums are archived and searchable so if you are lucky someone already
32735  had a similar problem.
32736  While mails to the lists themselves are delivered promptly their web front
32737  end on sourceforge sometimes shows a severe time lag (up to several weeks),
32738  if you're seriously using SDCC please consider subscribing to the lists.
32739 \end_layout
32740
32741 \begin_layout Section
32742 ChangeLog
32743 \end_layout
32744
32745 \begin_layout Standard
32746 You can follow the status of the Subversion version
32747 \begin_inset LatexCommand \index{version}
32748
32749 \end_inset
32750
32751  of SDCC by watching the Changelog
32752 \begin_inset LatexCommand \index{Changelog}
32753
32754 \end_inset
32755
32756  in the Subversion repository
32757 \size footnotesize
32758  
32759 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
32760
32761 \end_inset
32762
32763 .
32764 \end_layout
32765
32766 \begin_layout Section
32767 Subversion Source Code Repository
32768 \end_layout
32769
32770 \begin_layout Standard
32771 The output of 
32772 \family sans
32773 \series bold
32774 sdcc -
32775 \family default
32776
32777 \begin_inset ERT
32778 status open
32779
32780 \begin_layout Standard
32781
32782
32783 \backslash
32784 /
32785 \end_layout
32786
32787 \end_inset
32788
32789
32790 \family sans
32791 -version
32792 \family default
32793 \series default
32794  or the filenames of the snapshot versions of SDCC include date and its
32795  Subversion
32796 \begin_inset LatexCommand \index{Subversion code repository}
32797
32798 \end_inset
32799
32800  number.
32801  Subversion allows to download the source of recent or previous versions
32802  
32803 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
32804
32805 \end_inset
32806
32807  (by number or by date).
32808  An on-line source code browser and detailled instructions are also available
32809  there.
32810  SDCC versions starting from 1999 up to now are available (currently the
32811  versions prior to the conversion from cvs
32812 \begin_inset LatexCommand \index{cvs|see{Subversion}}
32813
32814 \end_inset
32815
32816  to Subversion (April 2006) are either by accessible by Subversion or by
32817  cvs).
32818 \end_layout
32819
32820 \begin_layout Section
32821 Release policy
32822 \begin_inset LatexCommand \index{Release policy}
32823
32824 \end_inset
32825
32826
32827 \end_layout
32828
32829 \begin_layout Standard
32830 Historically there often were long delays between official releases and
32831  the sourceforge download area tends to get not updated at all.
32832  Excuses in the past might have referred to problems with live range analysis,
32833  but as this was fixed a while ago, the current problem is that another
32834  excuse has to be found.
32835  Kidding aside, we have to get better there! On the other hand there are
32836  daily snapshots available at 
32837 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
32838
32839 \end_inset
32840
32841 , and you can always build the very last version (hopefully with many bugs
32842  fixed, and features added) from the source code available at 
32843 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
32844
32845 \end_inset
32846
32847 .
32848  The SDCC Wiki
32849 \begin_inset LatexCommand \index{wiki}
32850
32851 \end_inset
32852
32853
32854 \begin_inset LatexCommand \index{SDCC Wiki}
32855
32856 \end_inset
32857
32858  at 
32859 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
32860
32861 \end_inset
32862
32863  also holds some information about past and future releases.
32864 \end_layout
32865
32866 \begin_layout Section
32867 Examples
32868 \begin_inset LatexCommand \index{Examples}
32869
32870 \end_inset
32871
32872
32873 \end_layout
32874
32875 \begin_layout Standard
32876 You'll find some small examples in the directory 
32877 \emph on
32878 sdcc/device/examples/.
32879  
32880 \emph default
32881 More examples and libraries are available at
32882 \emph on
32883  The SDCC Open Knowledge Resource 
32884 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
32885
32886 \end_inset
32887
32888  
32889 \emph default
32890 web site or at 
32891 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
32892
32893 \end_inset
32894
32895 .
32896 \end_layout
32897
32898 \begin_layout Standard
32899 \begin_inset Note Note
32900 status collapsed
32901
32902 \begin_layout Standard
32903 I did insert a reference to Paul's web site here although it seems rather
32904  dedicated to a specific 8032 board (I think it's okay because it f.e.
32905  shows LCD/Harddisc interface and has a free 8051 monitor.
32906  Independent 8032 board vendors face hard competition of heavily subsidized
32907  development boards anyway).
32908 \end_layout
32909
32910 \begin_layout Standard
32911 Maybe we should include some links to real world applications.
32912  Preferably pointer to pointers (one for each architecture) so this stays
32913  manageable here?
32914 \end_layout
32915
32916 \end_inset
32917
32918
32919 \end_layout
32920
32921 \begin_layout Section
32922 Quality control
32923 \begin_inset LatexCommand \label{sec:Quality-control}
32924
32925 \end_inset
32926
32927
32928 \begin_inset LatexCommand \index{Quality control}
32929
32930 \end_inset
32931
32932
32933 \end_layout
32934
32935 \begin_layout Standard
32936 The compiler is passed through snaphot build compile and build checks.
32937  The so called 
32938 \shape italic
32939 regression tests
32940 \shape default
32941
32942 \begin_inset LatexCommand \index{Regression test}
32943
32944 \end_inset
32945
32946  check that SDCC itself compiles flawlessly on several host platforms (i386,
32947  Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
32948  and checks the quality of the code generated by SDCC by running the code
32949  for several target platforms through simulators.
32950  The regression test suite comprises more than 100 files which expand to
32951  more than 500 test cases which include more than 4500 tests.
32952  The results of these tests are published daily on SDCC's snapshot page
32953  (click on the red or green symbols on the right side of 
32954 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32955
32956 \end_inset
32957
32958 ).
32959 \end_layout
32960
32961 \begin_layout Standard
32962 There is a separate document 
32963 \shape italic
32964 test_suite.pdf 
32965 \begin_inset LatexCommand \index{Test suite}
32966
32967 \end_inset
32968
32969
32970 \shape default
32971  
32972 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32973
32974 \end_inset
32975
32976  about the regression test suite.
32977 \end_layout
32978
32979 \begin_layout Standard
32980 You'll find the test code in the directory 
32981 \shape italic
32982 sdcc/support/regression
32983 \shape default
32984 .
32985  You can run these tests manually by running 
32986 \family sans
32987 make
32988 \family default
32989  in this directory (or f.e.
32990  
32991 \family sans
32992 \series bold
32993
32994 \begin_inset Quotes sld
32995 \end_inset
32996
32997 make test-mcs51
32998 \begin_inset Quotes srd
32999 \end_inset
33000
33001
33002 \family default
33003 \series default
33004  if you don't want to run the complete tests).
33005  The test code might also be interesting if you want to look for examples
33006 \begin_inset LatexCommand \index{Examples}
33007
33008 \end_inset
33009
33010  checking corner cases of SDCC or if you plan to submit patches
33011 \begin_inset LatexCommand \index{Patch submission}
33012
33013 \end_inset
33014
33015 .
33016 \end_layout
33017
33018 \begin_layout Standard
33019 The PIC14 port uses a different set of regression tests 
33020 \begin_inset LatexCommand \index{Regression test (PIC14)}
33021
33022 \end_inset
33023
33024 , you'll find them in the directory 
33025 \shape italic
33026 sdcc/src/regression
33027 \shape default
33028 .
33029 \end_layout
33030
33031 \begin_layout Section
33032 Use of SDCC in Education
33033 \end_layout
33034
33035 \begin_layout Standard
33036 In short: 
33037 \emph on
33038 highly
33039 \emph default
33040  encouraged
33041 \begin_inset Foot
33042 status open
33043
33044 \begin_layout Standard
33045 the phrase "use in education" might evoke the association "
33046 \emph on
33047 only
33048 \emph default
33049  fit for use in education".
33050  This connotation is not intended but nevertheless risked as the licensing
33051  of SDCC makes it difficult to offer educational discounts
33052 \end_layout
33053
33054 \end_inset
33055
33056 .
33057  If your rationales are to:
33058 \end_layout
33059
33060 \begin_layout Enumerate
33061 give students a chance to understand the 
33062 \emph on
33063 complete
33064 \emph default
33065  steps of code generation
33066 \end_layout
33067
33068 \begin_layout Enumerate
33069 have a curriculum that can be extended for years.
33070  Then you could use an fpga board as target and your curriculum will seamlessly
33071  extend from logic synthesis (
33072 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
33073
33074 \end_inset
33075
33076
33077 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
33078
33079 \end_inset
33080
33081 ), over assembly programming, to C to FPGA compilers (
33082 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
33083
33084 \end_inset
33085
33086 ) and to C.
33087 \end_layout
33088
33089 \begin_layout Enumerate
33090 be able to insert excursions about skills like using a revision control
33091  system, submitting/applying patches, using a type-setting (as opposed to
33092  word-processing) engine LyX/LaTeX, using 
33093 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
33094
33095 \end_inset
33096
33097 , following some 
33098 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
33099
33100 \end_inset
33101
33102 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
33103  Source Software, CPU simulation, compiler regression tests
33104 \begin_inset LatexCommand \index{Regression test}
33105
33106 \end_inset
33107
33108 .
33109  
33110 \newline
33111 And if there should be a shortage of ideas then you can always point students
33112  to the ever-growing feature request list 
33113 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33114
33115 \end_inset
33116
33117 .
33118 \end_layout
33119
33120 \begin_layout Enumerate
33121 not tie students to a specific host platform and instead allow them to use
33122  a host platform of 
33123 \emph on
33124 their
33125 \emph default
33126  choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
33127  and eventually 
33128 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
33129
33130 \end_inset
33131
33132 )
33133 \end_layout
33134
33135 \begin_layout Enumerate
33136 not encourage students to use illegal copies of educational software
33137 \end_layout
33138
33139 \begin_layout Enumerate
33140 be immune to licensing/availability/price changes of the chosen tool chain
33141 \end_layout
33142
33143 \begin_layout Enumerate
33144 be able to change to a new target platform without having to adopt a new
33145  tool chain
33146 \end_layout
33147
33148 \begin_layout Enumerate
33149 have complete control over and insight into the tool chain
33150 \end_layout
33151
33152 \begin_layout Enumerate
33153 make your students aware about the pros and cons of open source software
33154  development
33155 \end_layout
33156
33157 \begin_layout Enumerate
33158 give back to the public as you are probably at least partially publically
33159  funded
33160 \end_layout
33161
33162 \begin_layout Enumerate
33163 give students a chance to publically prove their skills and to possibly
33164  see a world wide impact
33165 \end_layout
33166
33167 \begin_layout Standard
33168 then SDCC is probably among the first choices.
33169  Well, probably SDCC might be the only choice.
33170 \newpage
33171
33172 \end_layout
33173
33174 \begin_layout Chapter
33175 SDCC Technical Data
33176 \end_layout
33177
33178 \begin_layout Section
33179 Optimizations
33180 \begin_inset LatexCommand \index{Optimizations}
33181
33182 \end_inset
33183
33184
33185 \end_layout
33186
33187 \begin_layout Standard
33188 SDCC performs a host of standard optimizations in addition to some MCU specific
33189  optimizations.
33190  
33191 \end_layout
33192
33193 \begin_layout Subsection
33194 Sub-expression Elimination
33195 \begin_inset LatexCommand \index{Subexpression elimination}
33196
33197 \end_inset
33198
33199
33200 \end_layout
33201
33202 \begin_layout Standard
33203 The compiler does local and 
33204 \emph on
33205 g
33206 \emph default
33207 lobal 
33208 \emph on
33209 c
33210 \emph default
33211 ommon 
33212 \emph on
33213 s
33214 \emph default
33215 ubexpression 
33216 \emph on
33217 e
33218 \emph default
33219 limination, e.g.: 
33220 \end_layout
33221
33222 \begin_layout Verse
33223
33224 \family typewriter
33225 i = x + y + 1; 
33226 \newline
33227 j = x + y;
33228 \end_layout
33229
33230 \begin_layout Standard
33231 will be translated to
33232 \end_layout
33233
33234 \begin_layout Verse
33235
33236 \family typewriter
33237 iTemp = x + y; 
33238 \newline
33239 i = iTemp + 1; 
33240 \newline
33241 j = iTemp;
33242 \end_layout
33243
33244 \begin_layout Standard
33245 Some subexpressions are not as obvious as the above example, e.g.:
33246 \end_layout
33247
33248 \begin_layout Verse
33249
33250 \family typewriter
33251 a->b[i].c = 10; 
33252 \newline
33253 a->b[i].d = 11;
33254 \end_layout
33255
33256 \begin_layout Standard
33257 In this case the address arithmetic a->b[i] will be computed only once;
33258  the equivalent code in C would be.
33259 \end_layout
33260
33261 \begin_layout Verse
33262
33263 \family typewriter
33264 iTemp = a->b[i]; 
33265 \newline
33266 iTemp.c = 10; 
33267 \newline
33268 iTemp.d = 11;
33269 \end_layout
33270
33271 \begin_layout Standard
33272 The compiler will try to keep these temporary variables in registers.
33273 \end_layout
33274
33275 \begin_layout Subsection
33276 Dead-Code Elimination
33277 \begin_inset LatexCommand \index{Dead-code elimination}
33278
33279 \end_inset
33280
33281
33282 \end_layout
33283
33284 \begin_layout Verse
33285
33286 \family typewriter
33287 int global;
33288 \newline
33289
33290 \newline
33291 void f () { 
33292 \newline
33293 \InsetSpace ~
33294 \InsetSpace ~
33295 int i; 
33296 \newline
33297 \InsetSpace ~
33298 \InsetSpace ~
33299 i = 1; \InsetSpace ~
33300 \InsetSpace ~
33301 \InsetSpace ~
33302 \InsetSpace ~
33303 \InsetSpace ~
33304 /* dead store */ 
33305 \newline
33306 \InsetSpace ~
33307 \InsetSpace ~
33308 global = 1;\InsetSpace ~
33309 /* dead
33310  store */ 
33311 \newline
33312 \InsetSpace ~
33313 \InsetSpace ~
33314 global = 2; 
33315 \newline
33316 \InsetSpace ~
33317 \InsetSpace ~
33318 return; 
33319 \newline
33320 \InsetSpace ~
33321 \InsetSpace ~
33322 global = 3;\InsetSpace ~
33323 /* unreachable */ 
33324 \newline
33325 }
33326 \end_layout
33327
33328 \begin_layout Standard
33329 will be changed to
33330 \end_layout
33331
33332 \begin_layout Verse
33333
33334 \family typewriter
33335 int global;
33336 \newline
33337
33338 \newline
33339 void f () {
33340 \newline
33341 \InsetSpace ~
33342 \InsetSpace ~
33343 global = 2; 
33344 \newline
33345 }
33346 \end_layout
33347
33348 \begin_layout Subsection
33349 Copy-Propagation
33350 \begin_inset LatexCommand \index{Copy propagation}
33351
33352 \end_inset
33353
33354
33355 \end_layout
33356
33357 \begin_layout Verse
33358
33359 \family typewriter
33360 int f() { 
33361 \newline
33362 \InsetSpace ~
33363 \InsetSpace ~
33364 int i, j; 
33365 \newline
33366 \InsetSpace ~
33367 \InsetSpace ~
33368 i = 10; 
33369 \newline
33370 \InsetSpace ~
33371 \InsetSpace ~
33372 j = i; 
33373 \newline
33374 \InsetSpace ~
33375 \InsetSpace ~
33376 return j; 
33377 \newline
33378 }
33379 \end_layout
33380
33381 \begin_layout Standard
33382 will be changed to 
33383 \end_layout
33384
33385 \begin_layout Verse
33386
33387 \family typewriter
33388 int f() { 
33389 \newline
33390 \InsetSpace ~
33391 \InsetSpace ~
33392 int i, j; 
33393 \newline
33394 \InsetSpace ~
33395 \InsetSpace ~
33396 i = 10; 
33397 \newline
33398 \InsetSpace ~
33399 \InsetSpace ~
33400 j = 10; 
33401 \newline
33402 \InsetSpace ~
33403 \InsetSpace ~
33404 return 10; 
33405 \newline
33406 }
33407 \end_layout
33408
33409 \begin_layout Standard
33410 Note: the dead stores created by this copy propagation will be eliminated
33411  by dead-code elimination.
33412 \end_layout
33413
33414 \begin_layout Subsection
33415 Loop Optimizations
33416 \begin_inset LatexCommand \index{Loop optimization}
33417
33418 \end_inset
33419
33420
33421 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
33422
33423 \end_inset
33424
33425
33426 \end_layout
33427
33428 \begin_layout Standard
33429 Two types of loop optimizations are done by SDCC 
33430 \emph on
33431 loop invariant
33432 \emph default
33433  lifting and
33434 \emph on
33435  strength reduction
33436 \emph default
33437  of loop induction variables.
33438  In addition to the strength reduction the optimizer marks the induction
33439  variables and the register allocator tries to keep the induction variables
33440  in registers for the duration of the loop.
33441  Because of this preference of the register allocator
33442 \begin_inset LatexCommand \index{Register allocation}
33443
33444 \end_inset
33445
33446 , loop induction optimization causes an increase in register pressure, which
33447  may cause unwanted spilling of other temporary variables into the stack
33448 \begin_inset LatexCommand \index{stack}
33449
33450 \end_inset
33451
33452  / data space.
33453  The compiler will generate a warning message when it is forced to allocate
33454  extra space either on the stack or data space.
33455  If this extra space allocation is undesirable then induction optimization
33456  can be eliminated either for the entire source file (with -
33457 \begin_inset ERT
33458 status collapsed
33459
33460 \begin_layout Standard
33461
33462
33463 \backslash
33464 /
33465 \end_layout
33466
33467 \end_inset
33468
33469 -noinduction option) or for a given function only using #pragma\InsetSpace ~
33470 noinduction
33471 \begin_inset LatexCommand \index{\#pragma noinduction}
33472
33473 \end_inset
33474
33475 .
33476 \newline
33477
33478 \newline
33479 Loop Invariant:
33480 \end_layout
33481
33482 \begin_layout Verse
33483
33484 \family typewriter
33485 for (i = 0 ; i < 100 ; i ++) 
33486 \newline
33487 \InsetSpace ~
33488 \InsetSpace ~
33489 \InsetSpace ~
33490 \InsetSpace ~
33491 f += k + l;
33492 \end_layout
33493
33494 \begin_layout Standard
33495 changed to
33496 \end_layout
33497
33498 \begin_layout Verse
33499
33500 \family typewriter
33501 itemp = k + l; 
33502 \newline
33503 for (i = 0; i < 100; i++) 
33504 \newline
33505 \InsetSpace ~
33506 \InsetSpace ~
33507 \InsetSpace ~
33508 \InsetSpace ~
33509 f += itemp;
33510 \end_layout
33511
33512 \begin_layout Standard
33513 As mentioned previously some loop invariants are not as apparent, all static
33514  address computations are also moved out of the loop.
33515 \newline
33516
33517 \newline
33518 Strength Reduction
33519 \begin_inset LatexCommand \index{Strength reduction}
33520
33521 \end_inset
33522
33523 , this optimization substitutes an expression by a cheaper expression:
33524 \end_layout
33525
33526 \begin_layout Verse
33527
33528 \family typewriter
33529 for (i=0;i < 100; i++)
33530 \newline
33531 \InsetSpace ~
33532 \InsetSpace ~
33533 \InsetSpace ~
33534 \InsetSpace ~
33535 ar[i*5] = i*3;
33536 \end_layout
33537
33538 \begin_layout Standard
33539 changed to
33540 \end_layout
33541
33542 \begin_layout Verse
33543
33544 \family typewriter
33545 itemp1 = 0; 
33546 \newline
33547 itemp2 = 0; 
33548 \newline
33549 for (i=0;i< 100;i++) { 
33550 \newline
33551 \InsetSpace ~
33552 \InsetSpace ~
33553 \InsetSpace ~
33554 \InsetSpace ~
33555 ar[itemp1] = itemp2; 
33556 \newline
33557 \InsetSpace ~
33558 \InsetSpace ~
33559 \InsetSpace ~
33560 \InsetSpace ~
33561 itemp1
33562  += 5; 
33563 \newline
33564 \InsetSpace ~
33565 \InsetSpace ~
33566 \InsetSpace ~
33567 \InsetSpace ~
33568 itemp2 += 3; 
33569 \newline
33570 }
33571 \end_layout
33572
33573 \begin_layout Standard
33574 The more expensive multiplication
33575 \begin_inset LatexCommand \index{Multiplication}
33576
33577 \end_inset
33578
33579  is changed to a less expensive addition.
33580 \end_layout
33581
33582 \begin_layout Subsection
33583 Loop Reversing
33584 \begin_inset LatexCommand \index{Loop reversing}
33585
33586 \end_inset
33587
33588
33589 \end_layout
33590
33591 \begin_layout Standard
33592 This optimization is done to reduce the overhead of checking loop boundaries
33593  for every iteration.
33594  Some simple loops can be reversed and implemented using a 
33595 \begin_inset Quotes eld
33596 \end_inset
33597
33598 decrement and jump if not zero
33599 \begin_inset Quotes erd
33600 \end_inset
33601
33602  instruction.
33603  SDCC checks for the following criterion to determine if a loop is reversible
33604  (note: more sophisticated compilers use data-dependency analysis to make
33605  this determination, SDCC uses a more simple minded analysis).
33606 \end_layout
33607
33608 \begin_layout Itemize
33609 The 'for' loop is of the form 
33610 \newline
33611
33612 \newline
33613
33614 \family typewriter
33615 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
33616  += 1])
33617 \newline
33618 \InsetSpace ~
33619 \InsetSpace ~
33620 \InsetSpace ~
33621 \InsetSpace ~
33622 <for body>
33623 \end_layout
33624
33625 \begin_layout Itemize
33626 The <for body> does not contain 
33627 \begin_inset Quotes eld
33628 \end_inset
33629
33630 continue
33631 \begin_inset Quotes erd
33632 \end_inset
33633
33634  or 'break
33635 \begin_inset Quotes erd
33636 \end_inset
33637
33638 .
33639 \end_layout
33640
33641 \begin_layout Itemize
33642 All goto's are contained within the loop.
33643 \end_layout
33644
33645 \begin_layout Itemize
33646 No function calls within the loop.
33647 \end_layout
33648
33649 \begin_layout Itemize
33650 The loop control variable <sym> is not assigned any value within the loop
33651 \end_layout
33652
33653 \begin_layout Itemize
33654 The loop control variable does NOT participate in any arithmetic operation
33655  within the loop.
33656 \end_layout
33657
33658 \begin_layout Itemize
33659 There are NO switch statements in the loop.
33660 \end_layout
33661
33662 \begin_layout Subsection
33663 Algebraic Simplifications
33664 \end_layout
33665
33666 \begin_layout Standard
33667 SDCC does numerous algebraic simplifications, the following is a small sub-set
33668  of these optimizations.
33669 \end_layout
33670
33671 \begin_layout Verse
33672
33673 \family typewriter
33674 i = j + 0;\InsetSpace ~
33675 \InsetSpace ~
33676 \InsetSpace ~
33677 \InsetSpace ~
33678  /* changed to: */\InsetSpace ~
33679 \InsetSpace ~
33680 \InsetSpace ~
33681 \InsetSpace ~
33682  i = j; 
33683 \newline
33684 i /= 2;\InsetSpace ~
33685 \InsetSpace ~
33686 \InsetSpace ~
33687 \InsetSpace ~
33688 \InsetSpace ~
33689 \InsetSpace ~
33690 \InsetSpace ~
33691  /* changed to: */\InsetSpace ~
33692 \InsetSpace ~
33693 \InsetSpace ~
33694 \InsetSpace ~
33695  i >>= 1; 
33696 \newline
33697 i
33698  = j - j;\InsetSpace ~
33699 \InsetSpace ~
33700 \InsetSpace ~
33701 \InsetSpace ~
33702  /* changed to: */\InsetSpace ~
33703 \InsetSpace ~
33704 \InsetSpace ~
33705 \InsetSpace ~
33706  i = 0; 
33707 \newline
33708 i = j / 1;\InsetSpace ~
33709 \InsetSpace ~
33710 \InsetSpace ~
33711 \InsetSpace ~
33712  /* changed to: */\InsetSpace ~
33713 \InsetSpace ~
33714 \InsetSpace ~
33715 \InsetSpace ~
33716  i = j;
33717 \end_layout
33718
33719 \begin_layout Standard
33720 Note the subexpressions
33721 \begin_inset LatexCommand \index{Subexpression}
33722
33723 \end_inset
33724
33725  given above are generally introduced by macro expansions or as a result
33726  of copy/constant propagation.
33727 \end_layout
33728
33729 \begin_layout Subsection
33730 'switch' Statements
33731 \begin_inset LatexCommand \label{sub:'switch'-Statements}
33732
33733 \end_inset
33734
33735
33736 \begin_inset LatexCommand \index{switch statement}
33737
33738 \end_inset
33739
33740
33741 \end_layout
33742
33743 \begin_layout Standard
33744 SDCC can optimize switch statements to jump tables
33745 \begin_inset LatexCommand \index{jump tables}
33746
33747 \end_inset
33748
33749 .
33750  It makes the decision based on an estimate of the generated code size.
33751  SDCC is quite liberal in the requirements for jump table generation: 
33752 \end_layout
33753
33754 \begin_layout Itemize
33755 The labels need not be in order, and the starting number need not be one
33756  or zero, the case labels are in numerical sequence or not too many case
33757  labels are missing.
33758 \end_layout
33759
33760 \begin_deeper
33761 \begin_layout Verse
33762
33763 \family typewriter
33764 switch(i) {\InsetSpace ~
33765 \InsetSpace ~
33766 \InsetSpace ~
33767 \InsetSpace ~
33768 \InsetSpace ~
33769 \InsetSpace ~
33770 \InsetSpace ~
33771 \InsetSpace ~
33772 \InsetSpace ~
33773 \InsetSpace ~
33774 \InsetSpace ~
33775 \InsetSpace ~
33776 \InsetSpace ~
33777 \InsetSpace ~
33778 \InsetSpace ~
33779 \InsetSpace ~
33780 \InsetSpace ~
33781 \InsetSpace ~
33782 \InsetSpace ~
33783 \InsetSpace ~
33784 \InsetSpace ~
33785 \InsetSpace ~
33786 \InsetSpace ~
33787 \InsetSpace ~
33788 \InsetSpace ~
33789 \InsetSpace ~
33790 switch (i) { 
33791 \newline
33792 \InsetSpace ~
33793 \InsetSpace ~
33794 \InsetSpace ~
33795 case 4: ...\InsetSpace ~
33796 \InsetSpace ~
33797 \InsetSpace ~
33798 \InsetSpace ~
33799 \InsetSpace ~
33800 \InsetSpace ~
33801 \InsetSpace ~
33802 \InsetSpace ~
33803 \InsetSpace ~
33804 \InsetSpace ~
33805 \InsetSpace ~
33806 \InsetSpace ~
33807 \InsetSpace ~
33808 \InsetSpace ~
33809 \InsetSpace ~
33810 \InsetSpace ~
33811 \InsetSpace ~
33812 \InsetSpace ~
33813 \InsetSpace ~
33814 \InsetSpace ~
33815 \InsetSpace ~
33816 \InsetSpace ~
33817 \InsetSpace ~
33818 \InsetSpace ~
33819 \InsetSpace ~
33820 \InsetSpace ~
33821 case 0: ...
33822  
33823 \newline
33824 \InsetSpace ~
33825 \InsetSpace ~
33826 \InsetSpace ~
33827 case 5: ...\InsetSpace ~
33828 \InsetSpace ~
33829 \InsetSpace ~
33830 \InsetSpace ~
33831 \InsetSpace ~
33832 \InsetSpace ~
33833 \InsetSpace ~
33834 \InsetSpace ~
33835 \InsetSpace ~
33836 \InsetSpace ~
33837 \InsetSpace ~
33838 \InsetSpace ~
33839 \InsetSpace ~
33840 \InsetSpace ~
33841 \InsetSpace ~
33842 \InsetSpace ~
33843 \InsetSpace ~
33844 \InsetSpace ~
33845 \InsetSpace ~
33846 \InsetSpace ~
33847 \InsetSpace ~
33848 \InsetSpace ~
33849 \InsetSpace ~
33850 \InsetSpace ~
33851 \InsetSpace ~
33852 \InsetSpace ~
33853 case 1: ...
33854  
33855 \newline
33856 \InsetSpace ~
33857 \InsetSpace ~
33858 \InsetSpace ~
33859 case 3: ...\InsetSpace ~
33860 \InsetSpace ~
33861 \InsetSpace ~
33862 \InsetSpace ~
33863 \InsetSpace ~
33864 \InsetSpace ~
33865 \InsetSpace ~
33866 \InsetSpace ~
33867 \InsetSpace ~
33868 \InsetSpace ~
33869 \InsetSpace ~
33870 \InsetSpace ~
33871 \InsetSpace ~
33872 \InsetSpace ~
33873 \InsetSpace ~
33874 \InsetSpace ~
33875 \InsetSpace ~
33876 \InsetSpace ~
33877 \InsetSpace ~
33878 \InsetSpace ~
33879 \InsetSpace ~
33880 \InsetSpace ~
33881 \InsetSpace ~
33882 \InsetSpace ~
33883 \InsetSpace ~
33884 \InsetSpace ~
33885
33886 \newline
33887 \InsetSpace ~
33888 \InsetSpace ~
33889 \InsetSpace ~
33890 case 6: ...\InsetSpace ~
33891 \InsetSpace ~
33892 \InsetSpace ~
33893 \InsetSpace ~
33894 \InsetSpace ~
33895 \InsetSpace ~
33896 \InsetSpace ~
33897 \InsetSpace ~
33898 \InsetSpace ~
33899 \InsetSpace ~
33900 \InsetSpace ~
33901 \InsetSpace ~
33902 \InsetSpace ~
33903 \InsetSpace ~
33904 \InsetSpace ~
33905 \InsetSpace ~
33906 \InsetSpace ~
33907 \InsetSpace ~
33908 \InsetSpace ~
33909 \InsetSpace ~
33910 \InsetSpace ~
33911 \InsetSpace ~
33912 \InsetSpace ~
33913 \InsetSpace ~
33914 \InsetSpace ~
33915 \InsetSpace ~
33916 case 3: ...
33917  
33918 \newline
33919 \InsetSpace ~
33920 \InsetSpace ~
33921 \InsetSpace ~
33922 case 7: ...\InsetSpace ~
33923 \InsetSpace ~
33924 \InsetSpace ~
33925 \InsetSpace ~
33926 \InsetSpace ~
33927 \InsetSpace ~
33928 \InsetSpace ~
33929 \InsetSpace ~
33930 \InsetSpace ~
33931 \InsetSpace ~
33932 \InsetSpace ~
33933 \InsetSpace ~
33934 \InsetSpace ~
33935 \InsetSpace ~
33936 \InsetSpace ~
33937 \InsetSpace ~
33938 \InsetSpace ~
33939 \InsetSpace ~
33940 \InsetSpace ~
33941 \InsetSpace ~
33942 \InsetSpace ~
33943 \InsetSpace ~
33944 \InsetSpace ~
33945 \InsetSpace ~
33946 \InsetSpace ~
33947 \InsetSpace ~
33948 case 4: ...
33949  
33950 \newline
33951 \InsetSpace ~
33952 \InsetSpace ~
33953 \InsetSpace ~
33954 case 8: ...\InsetSpace ~
33955 \InsetSpace ~
33956 \InsetSpace ~
33957 \InsetSpace ~
33958 \InsetSpace ~
33959 \InsetSpace ~
33960 \InsetSpace ~
33961 \InsetSpace ~
33962 \InsetSpace ~
33963 \InsetSpace ~
33964 \InsetSpace ~
33965 \InsetSpace ~
33966 \InsetSpace ~
33967 \InsetSpace ~
33968 \InsetSpace ~
33969 \InsetSpace ~
33970 \InsetSpace ~
33971 \InsetSpace ~
33972 \InsetSpace ~
33973 \InsetSpace ~
33974 \InsetSpace ~
33975 \InsetSpace ~
33976 \InsetSpace ~
33977 \InsetSpace ~
33978 \InsetSpace ~
33979 \InsetSpace ~
33980 case 5: ...
33981  
33982 \newline
33983 \InsetSpace ~
33984 \InsetSpace ~
33985 \InsetSpace ~
33986 case 9: ...\InsetSpace ~
33987 \InsetSpace ~
33988 \InsetSpace ~
33989 \InsetSpace ~
33990 \InsetSpace ~
33991 \InsetSpace ~
33992 \InsetSpace ~
33993 \InsetSpace ~
33994 \InsetSpace ~
33995 \InsetSpace ~
33996 \InsetSpace ~
33997 \InsetSpace ~
33998 \InsetSpace ~
33999 \InsetSpace ~
34000 \InsetSpace ~
34001 \InsetSpace ~
34002 \InsetSpace ~
34003 \InsetSpace ~
34004 \InsetSpace ~
34005 \InsetSpace ~
34006 \InsetSpace ~
34007 \InsetSpace ~
34008 \InsetSpace ~
34009 \InsetSpace ~
34010 \InsetSpace ~
34011 \InsetSpace ~
34012 case 6: ...
34013  
34014 \newline
34015 \InsetSpace ~
34016 \InsetSpace ~
34017 \InsetSpace ~
34018 case 10: ...\InsetSpace ~
34019 \InsetSpace ~
34020 \InsetSpace ~
34021 \InsetSpace ~
34022 \InsetSpace ~
34023 \InsetSpace ~
34024 \InsetSpace ~
34025 \InsetSpace ~
34026 \InsetSpace ~
34027 \InsetSpace ~
34028 \InsetSpace ~
34029 \InsetSpace ~
34030 \InsetSpace ~
34031 \InsetSpace ~
34032 \InsetSpace ~
34033 \InsetSpace ~
34034 \InsetSpace ~
34035 \InsetSpace ~
34036 \InsetSpace ~
34037 \InsetSpace ~
34038 \InsetSpace ~
34039 \InsetSpace ~
34040 \InsetSpace ~
34041 \InsetSpace ~
34042 \InsetSpace ~
34043 case 7: ...
34044  
34045 \newline
34046 \InsetSpace ~
34047 \InsetSpace ~
34048 \InsetSpace ~
34049 case 11: ...\InsetSpace ~
34050 \InsetSpace ~
34051 \InsetSpace ~
34052 \InsetSpace ~
34053 \InsetSpace ~
34054 \InsetSpace ~
34055 \InsetSpace ~
34056 \InsetSpace ~
34057 \InsetSpace ~
34058 \InsetSpace ~
34059 \InsetSpace ~
34060 \InsetSpace ~
34061 \InsetSpace ~
34062 \InsetSpace ~
34063 \InsetSpace ~
34064 \InsetSpace ~
34065 \InsetSpace ~
34066 \InsetSpace ~
34067 \InsetSpace ~
34068 \InsetSpace ~
34069 \InsetSpace ~
34070 \InsetSpace ~
34071 \InsetSpace ~
34072 \InsetSpace ~
34073 \InsetSpace ~
34074 case 8: ...
34075  
34076 \newline
34077 }\InsetSpace ~
34078 \InsetSpace ~
34079 \InsetSpace ~
34080 \InsetSpace ~
34081 \InsetSpace ~
34082 \InsetSpace ~
34083 \InsetSpace ~
34084 \InsetSpace ~
34085 \InsetSpace ~
34086 \InsetSpace ~
34087 \InsetSpace ~
34088 \InsetSpace ~
34089 \InsetSpace ~
34090 \InsetSpace ~
34091 \InsetSpace ~
34092 \InsetSpace ~
34093 \InsetSpace ~
34094 \InsetSpace ~
34095 \InsetSpace ~
34096 \InsetSpace ~
34097 \InsetSpace ~
34098 \InsetSpace ~
34099 \InsetSpace ~
34100 \InsetSpace ~
34101 \InsetSpace ~
34102 \InsetSpace ~
34103 \InsetSpace ~
34104 \InsetSpace ~
34105 \InsetSpace ~
34106 \InsetSpace ~
34107 \InsetSpace ~
34108 \InsetSpace ~
34109 \InsetSpace ~
34110 \InsetSpace ~
34111 \InsetSpace ~
34112 \InsetSpace ~
34113 }
34114 \end_layout
34115
34116 \begin_layout Standard
34117 Both the above switch statements will be implemented using a jump-table.
34118  The example to the right side is slightly more efficient as the check for
34119  the lower boundary of the jump-table is not needed.
34120 \end_layout
34121
34122 \end_deeper
34123 \begin_layout Itemize
34124 The number of case labels is not larger than supported by the target architectur
34125 e.
34126 \end_layout
34127
34128 \begin_layout Itemize
34129 If the case labels are not in numerical sequence ('gaps' between cases)
34130  SDCC checks whether a jump table with additionally inserted dummy cases
34131  is still attractive.
34132  
34133 \end_layout
34134
34135 \begin_layout Itemize
34136 If the starting number is not zero and a check for the lower boundary of
34137  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
34138  ...
34139  .
34140 \end_layout
34141
34142 \begin_layout Standard
34143 Switch statements which have large gaps in the numeric sequence or those
34144  that have too many case labels can be split into more than one switch statement
34145  for efficient code generation, e.g.:
34146 \end_layout
34147
34148 \begin_layout Verse
34149
34150 \family typewriter
34151 switch (i) { 
34152 \newline
34153 \InsetSpace ~
34154 \InsetSpace ~
34155 case 1: ...
34156  
34157 \newline
34158 \InsetSpace ~
34159 \InsetSpace ~
34160 case 2: ...
34161  
34162 \newline
34163 \InsetSpace ~
34164 \InsetSpace ~
34165 case 3: ...
34166  
34167 \newline
34168 \InsetSpace ~
34169 \InsetSpace ~
34170 case 4: ...
34171  
34172 \newline
34173 \InsetSpace ~
34174 \InsetSpace ~
34175 case 5: ...
34176  
34177 \newline
34178 \InsetSpace ~
34179 \InsetSpace ~
34180 case 6: ...
34181  
34182 \newline
34183 \InsetSpace ~
34184 \InsetSpace ~
34185 case 7: ...
34186  
34187 \newline
34188 \InsetSpace ~
34189 \InsetSpace ~
34190 case 101: ...
34191  
34192 \newline
34193 \InsetSpace ~
34194 \InsetSpace ~
34195 case 102: ...
34196  
34197 \newline
34198 \InsetSpace ~
34199 \InsetSpace ~
34200 case 103: ...
34201  
34202 \newline
34203 \InsetSpace ~
34204 \InsetSpace ~
34205 case 104: ...
34206  
34207 \newline
34208 \InsetSpace ~
34209 \InsetSpace ~
34210 case 105: ...
34211  
34212 \newline
34213 \InsetSpace ~
34214 \InsetSpace ~
34215 case 106: ...
34216  
34217 \newline
34218 \InsetSpace ~
34219 \InsetSpace ~
34220 case 107: ...
34221  
34222 \newline
34223 }
34224 \end_layout
34225
34226 \begin_layout Standard
34227 If the above switch statement is broken down into two switch statements
34228 \end_layout
34229
34230 \begin_layout Verse
34231
34232 \family typewriter
34233 switch (i) { 
34234 \newline
34235 \InsetSpace ~
34236 \InsetSpace ~
34237 case 1: ...
34238  
34239 \newline
34240 \InsetSpace ~
34241 \InsetSpace ~
34242 case 2: ...
34243  
34244 \newline
34245 \InsetSpace ~
34246 \InsetSpace ~
34247 case 3: ...
34248  
34249 \newline
34250 \InsetSpace ~
34251 \InsetSpace ~
34252 case 4: ...
34253  
34254 \newline
34255 \InsetSpace ~
34256 \InsetSpace ~
34257 case 5: ...
34258  
34259 \newline
34260 \InsetSpace ~
34261 \InsetSpace ~
34262 case 6: ...
34263  
34264 \newline
34265 \InsetSpace ~
34266 \InsetSpace ~
34267 case 7: ...
34268  
34269 \newline
34270 }
34271 \end_layout
34272
34273 \begin_layout Standard
34274 and
34275 \end_layout
34276
34277 \begin_layout Verse
34278
34279 \family typewriter
34280 switch (i) { 
34281 \newline
34282 \InsetSpace ~
34283 \InsetSpace ~
34284 case 101: ...
34285  
34286 \newline
34287 \InsetSpace ~
34288 \InsetSpace ~
34289 case 102: ...
34290  
34291 \newline
34292 \InsetSpace ~
34293 \InsetSpace ~
34294 case 103: ...
34295  
34296 \newline
34297 \InsetSpace ~
34298 \InsetSpace ~
34299 case 104: ...
34300  
34301 \newline
34302 \InsetSpace ~
34303 \InsetSpace ~
34304 case 105: ...
34305  
34306 \newline
34307 \InsetSpace ~
34308 \InsetSpace ~
34309 case 106: ...
34310  
34311 \newline
34312 \InsetSpace ~
34313 \InsetSpace ~
34314 case 107: ...
34315  
34316 \newline
34317 }
34318 \end_layout
34319
34320 \begin_layout Standard
34321 then both the switch statements will be implemented using jump-tables whereas
34322  the unmodified switch statement will not be.
34323 \end_layout
34324
34325 \begin_layout Standard
34326 \begin_inset Note Note
34327 status collapsed
34328
34329 \begin_layout Standard
34330 There might be reasons which SDCC cannot know about to either favour or
34331  not favour jump tables.
34332  If the target system has to be as quick for the last switch case as for
34333  the first (pro jump table), or if the switch argument is known to be zero
34334  in the majority of the cases (contra jump table).
34335 \end_layout
34336
34337 \end_inset
34338
34339
34340 \end_layout
34341
34342 \begin_layout Standard
34343 The pragma nojtbound
34344 \begin_inset LatexCommand \index{\#pragma nojtbound}
34345
34346 \end_inset
34347
34348  can be used to turn off checking the 
34349 \emph on
34350 j
34351 \emph default
34352 ump 
34353 \emph on
34354 t
34355 \emph default
34356 able 
34357 \emph on
34358 bound
34359 \emph default
34360 aries.
34361  It has no effect if a default label is supplied.
34362  Use of this pragma is dangerous: if the switch
34363 \begin_inset LatexCommand \index{switch statement}
34364
34365 \end_inset
34366
34367  argument is not matched by a case statement the processor will happily
34368  jump into Nirvana.
34369 \end_layout
34370
34371 \begin_layout Subsection
34372 Bit-shifting Operations
34373 \begin_inset LatexCommand \index{Bit shifting}
34374
34375 \end_inset
34376
34377 .
34378 \end_layout
34379
34380 \begin_layout Standard
34381 Bit shifting is one of the most frequently used operation in embedded programmin
34382 g.
34383  SDCC tries to implement bit-shift operations in the most efficient way
34384  possible, e.g.:
34385 \end_layout
34386
34387 \begin_layout Verse
34388
34389 \family typewriter
34390 unsigned char i;
34391 \newline
34392 ...
34393  
34394 \newline
34395 i >>= 4; 
34396 \newline
34397 ...
34398 \end_layout
34399
34400 \begin_layout Standard
34401 generates the following code:
34402 \end_layout
34403
34404 \begin_layout Verse
34405
34406 \family typewriter
34407 mov\InsetSpace ~
34408  a,_i 
34409 \newline
34410 swap a 
34411 \newline
34412 anl\InsetSpace ~
34413  a,#0x0f 
34414 \newline
34415 mov\InsetSpace ~
34416  _i,a
34417 \end_layout
34418
34419 \begin_layout Standard
34420 In general SDCC will never setup a loop if the shift count is known.
34421  Another example:
34422 \end_layout
34423
34424 \begin_layout Verse
34425
34426 \family typewriter
34427 unsigned int i; 
34428 \newline
34429 ...
34430  
34431 \newline
34432 i >>= 9; 
34433 \newline
34434 ...
34435 \end_layout
34436
34437 \begin_layout Standard
34438 will generate:
34439 \end_layout
34440
34441 \begin_layout Verse
34442
34443 \family typewriter
34444 mov\InsetSpace ~
34445 \InsetSpace ~
34446 a,(_i + 1) 
34447 \newline
34448 mov\InsetSpace ~
34449 \InsetSpace ~
34450 (_i + 1),#0x00 
34451 \newline
34452 clr\InsetSpace ~
34453 \InsetSpace ~
34454
34455 \newline
34456 rrc\InsetSpace ~
34457 \InsetSpace ~
34458
34459 \newline
34460 mov\InsetSpace ~
34461 \InsetSpace ~
34462 _i,a
34463 \end_layout
34464
34465 \begin_layout Subsection
34466 Bit-rotation
34467 \begin_inset LatexCommand \index{Bit rotation}
34468
34469 \end_inset
34470
34471
34472 \end_layout
34473
34474 \begin_layout Standard
34475 A special case of the bit-shift operation is bit rotation
34476 \begin_inset LatexCommand \index{rotating bits}
34477
34478 \end_inset
34479
34480 , SDCC recognizes the following expression to be a left bit-rotation:
34481 \end_layout
34482
34483 \begin_layout Verse
34484
34485 \family typewriter
34486 \series bold
34487 unsigned
34488 \series default
34489 \InsetSpace ~
34490 \InsetSpace ~
34491 char i;\InsetSpace ~
34492 \InsetSpace ~
34493 \InsetSpace ~
34494 \InsetSpace ~
34495 \InsetSpace ~
34496 \InsetSpace ~
34497 \InsetSpace ~
34498 \InsetSpace ~
34499 \InsetSpace ~
34500 \InsetSpace ~
34501 \InsetSpace ~
34502 /* unsigned is needed for rotation */ 
34503 \newline
34504 ...
34505  
34506 \newline
34507 i = ((i << 1) | (i >> 7)); 
34508 \family default
34509
34510 \newline
34511
34512 \family typewriter
34513 ...
34514 \end_layout
34515
34516 \begin_layout Standard
34517 will generate the following code:
34518 \end_layout
34519
34520 \begin_layout Verse
34521
34522 \family typewriter
34523 mov\InsetSpace ~
34524 \InsetSpace ~
34525 a,_i 
34526 \newline
34527 rl\InsetSpace ~
34528 \InsetSpace ~
34529 \InsetSpace ~
34530
34531 \newline
34532 mov\InsetSpace ~
34533 \InsetSpace ~
34534 _i,a
34535 \end_layout
34536
34537 \begin_layout Standard
34538 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
34539 ns of this case will also be recognized as bit-rotation, i.e.: 
34540 \end_layout
34541
34542 \begin_layout Verse
34543
34544 \family typewriter
34545 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
34546 \end_layout
34547
34548 \begin_layout Subsection
34549 Nibble and Byte Swapping
34550 \end_layout
34551
34552 \begin_layout Standard
34553 Other special cases of the bit-shift operations are nibble or byte swapping
34554 \begin_inset LatexCommand \index{swapping nibbles/bytes}
34555
34556 \end_inset
34557
34558 , SDCC recognizes the following expressions:
34559 \end_layout
34560
34561 \begin_layout Verse
34562
34563 \family typewriter
34564 \series bold
34565 unsigned
34566 \series default
34567 \InsetSpace ~
34568 \InsetSpace ~
34569 char i; 
34570 \newline
34571
34572 \series bold
34573 unsigned
34574 \series default
34575 \InsetSpace ~
34576 \InsetSpace ~
34577 int j; 
34578 \newline
34579 ...
34580  
34581 \newline
34582 i = ((i << 4) | (i >> 4)); 
34583 \family default
34584
34585 \newline
34586
34587 \family typewriter
34588 j = ((j << 8) | (j >> 8)); 
34589 \end_layout
34590
34591 \begin_layout Standard
34592 and generates a swap instruction for the nibble swapping
34593 \begin_inset LatexCommand \index{Nibble swapping}
34594
34595 \end_inset
34596
34597  or move instructions for the byte swapping
34598 \begin_inset LatexCommand \index{Byte swapping}
34599
34600 \end_inset
34601
34602 .
34603  The 
34604 \begin_inset Quotes sld
34605 \end_inset
34606
34607 j
34608 \begin_inset Quotes srd
34609 \end_inset
34610
34611  example can be used to convert from little to big-endian or vice versa.
34612  If you want to change the endianness of a 
34613 \emph on
34614 signed
34615 \emph default
34616  integer you have to cast to 
34617 \family typewriter
34618 (unsigned int)
34619 \family default
34620  first.
34621 \end_layout
34622
34623 \begin_layout Standard
34624 Note that SDCC stores numbers in little-endian
34625 \begin_inset Foot
34626 status open
34627
34628 \begin_layout Standard
34629 Usually 8-bit processors don't care much about endianness.
34630  This is not the case for the standard 8051 which only has an instruction
34631  to increment its 
34632 \emph on
34633 dptr
34634 \emph default
34635
34636 \begin_inset LatexCommand \index{DPTR}
34637
34638 \end_inset
34639
34640 -datapointer
34641 \emph on
34642  
34643 \emph default
34644 so little-endian is the more efficient byte order.
34645 \end_layout
34646
34647 \end_inset
34648
34649
34650 \begin_inset LatexCommand \index{little-endian}
34651
34652 \end_inset
34653
34654
34655 \begin_inset LatexCommand \index{Endianness}
34656
34657 \end_inset
34658
34659  format (i.e.
34660  lowest order first).
34661 \end_layout
34662
34663 \begin_layout Subsection
34664 Highest Order Bit
34665 \begin_inset LatexCommand \index{Highest Order Bit}
34666
34667 \end_inset
34668
34669  / Any Order Bit
34670 \begin_inset LatexCommand \index{Any Order Bit}
34671
34672 \end_inset
34673
34674
34675 \end_layout
34676
34677 \begin_layout Standard
34678 It is frequently required to obtain the highest order bit of an integral
34679  type (long, int, short or char types).
34680  Also obtaining any other order bit is not uncommon.
34681  SDCC recognizes the following expressions to yield the highest order bit
34682  and generates optimized code for it, e.g.:
34683 \end_layout
34684
34685 \begin_layout Verse
34686
34687 \family typewriter
34688 unsigned int gint; 
34689 \newline
34690
34691 \newline
34692 foo () { 
34693 \newline
34694 \InsetSpace ~
34695 \InsetSpace ~
34696 unsigned char hob1, aob1; 
34697 \newline
34698 \InsetSpace ~
34699 \InsetSpace ~
34700 bit hob2, hob3, aob2,
34701  aob3; 
34702 \newline
34703 \InsetSpace ~
34704 \InsetSpace ~
34705 ...
34706  
34707 \newline
34708 \InsetSpace ~
34709 \InsetSpace ~
34710 hob1 = (gint >> 15) & 1; 
34711 \newline
34712 \InsetSpace ~
34713 \InsetSpace ~
34714 hob2 = (gint >> 15) & 1; 
34715 \newline
34716 \InsetSpace ~
34717 \InsetSpace ~
34718 hob3 = gint & 0x8000;
34719  
34720 \newline
34721 \InsetSpace ~
34722 \InsetSpace ~
34723 aob1 = (gint >> 9) & 1; 
34724 \newline
34725 \InsetSpace ~
34726 \InsetSpace ~
34727 aob2 = (gint >> 8) & 1; 
34728 \newline
34729 \InsetSpace ~
34730 \InsetSpace ~
34731 aob3 = gint & 0x0800; 
34732 \newline
34733 \InsetSpace ~
34734 \InsetSpace ~
34735 ..
34736  
34737 \newline
34738 }
34739 \end_layout
34740
34741 \begin_layout Standard
34742 will generate the following code:
34743 \end_layout
34744
34745 \begin_layout Verse
34746
34747 \family typewriter
34748 \InsetSpace ~
34749 \InsetSpace ~
34750 \InsetSpace ~
34751 \InsetSpace ~
34752 \InsetSpace ~
34753 \InsetSpace ~
34754 \InsetSpace ~
34755 \InsetSpace ~
34756 \InsetSpace ~
34757 \InsetSpace ~
34758 \InsetSpace ~
34759 \InsetSpace ~
34760 \InsetSpace ~
34761 \InsetSpace ~
34762 \InsetSpace ~
34763 \InsetSpace ~
34764 \InsetSpace ~
34765 \InsetSpace ~
34766 \InsetSpace ~
34767 \InsetSpace ~
34768 \InsetSpace ~
34769 \InsetSpace ~
34770 \InsetSpace ~
34771 \InsetSpace ~
34772 \InsetSpace ~
34773  61 ;\InsetSpace ~
34774  hob.c 7 
34775 \newline
34776 000A E5*01\InsetSpace ~
34777 \InsetSpace ~
34778 \InsetSpace ~
34779 \InsetSpace ~
34780 \InsetSpace ~
34781 \InsetSpace ~
34782 \InsetSpace ~
34783 \InsetSpace ~
34784 \InsetSpace ~
34785 \InsetSpace ~
34786 \InsetSpace ~
34787 \InsetSpace ~
34788 \InsetSpace ~
34789 \InsetSpace ~
34790 \InsetSpace ~
34791  62\InsetSpace ~
34792 \InsetSpace ~
34793 \InsetSpace ~
34794 \InsetSpace ~
34795 \InsetSpace ~
34796 \InsetSpace ~
34797 \InsetSpace ~
34798 \InsetSpace ~
34799  mov\InsetSpace ~
34800 \InsetSpace ~
34801  a,(_gint + 1) 
34802 \newline
34803 000C 23\InsetSpace ~
34804 \InsetSpace ~
34805 \InsetSpace ~
34806 \InsetSpace ~
34807 \InsetSpace ~
34808 \InsetSpace ~
34809 \InsetSpace ~
34810 \InsetSpace ~
34811 \InsetSpace ~
34812 \InsetSpace ~
34813 \InsetSpace ~
34814 \InsetSpace ~
34815 \InsetSpace ~
34816 \InsetSpace ~
34817 \InsetSpace ~
34818 \InsetSpace ~
34819 \InsetSpace ~
34820 \InsetSpace ~
34821  63\InsetSpace ~
34822 \InsetSpace ~
34823 \InsetSpace ~
34824 \InsetSpace ~
34825 \InsetSpace ~
34826 \InsetSpace ~
34827 \InsetSpace ~
34828 \InsetSpace ~
34829  rl\InsetSpace ~
34830 \InsetSpace ~
34831 \InsetSpace ~
34832  a 
34833 \newline
34834 000D 54 01\InsetSpace ~
34835 \InsetSpace ~
34836 \InsetSpace ~
34837 \InsetSpace ~
34838 \InsetSpace ~
34839 \InsetSpace ~
34840 \InsetSpace ~
34841 \InsetSpace ~
34842 \InsetSpace ~
34843 \InsetSpace ~
34844 \InsetSpace ~
34845 \InsetSpace ~
34846 \InsetSpace ~
34847 \InsetSpace ~
34848 \InsetSpace ~
34849
34850  64\InsetSpace ~
34851 \InsetSpace ~
34852 \InsetSpace ~
34853 \InsetSpace ~
34854 \InsetSpace ~
34855 \InsetSpace ~
34856 \InsetSpace ~
34857 \InsetSpace ~
34858  anl\InsetSpace ~
34859 \InsetSpace ~
34860  a,#0x01 
34861 \newline
34862 000F F5*02\InsetSpace ~
34863 \InsetSpace ~
34864 \InsetSpace ~
34865 \InsetSpace ~
34866 \InsetSpace ~
34867 \InsetSpace ~
34868 \InsetSpace ~
34869 \InsetSpace ~
34870 \InsetSpace ~
34871 \InsetSpace ~
34872 \InsetSpace ~
34873 \InsetSpace ~
34874 \InsetSpace ~
34875 \InsetSpace ~
34876 \InsetSpace ~
34877  65\InsetSpace ~
34878 \InsetSpace ~
34879 \InsetSpace ~
34880 \InsetSpace ~
34881 \InsetSpace ~
34882 \InsetSpace ~
34883 \InsetSpace ~
34884 \InsetSpace ~
34885  mov\InsetSpace ~
34886 \InsetSpace ~
34887  _foo_hob1_1_1,a 
34888 \newline
34889 \InsetSpace ~
34890 \InsetSpace ~
34891 \InsetSpace ~
34892 \InsetSpace ~
34893 \InsetSpace ~
34894 \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 \InsetSpace ~
34910 \InsetSpace ~
34911 \InsetSpace ~
34912 \InsetSpace ~
34913 \InsetSpace ~
34914  66 ;\InsetSpace ~
34915  hob.c 8 
34916 \newline
34917 0011 E5*01\InsetSpace ~
34918 \InsetSpace ~
34919 \InsetSpace ~
34920 \InsetSpace ~
34921 \InsetSpace ~
34922 \InsetSpace ~
34923 \InsetSpace ~
34924 \InsetSpace ~
34925 \InsetSpace ~
34926 \InsetSpace ~
34927 \InsetSpace ~
34928 \InsetSpace ~
34929 \InsetSpace ~
34930 \InsetSpace ~
34931 \InsetSpace ~
34932
34933  67\InsetSpace ~
34934 \InsetSpace ~
34935 \InsetSpace ~
34936 \InsetSpace ~
34937 \InsetSpace ~
34938 \InsetSpace ~
34939 \InsetSpace ~
34940 \InsetSpace ~
34941  mov\InsetSpace ~
34942 \InsetSpace ~
34943  a,(_gint + 1) 
34944 \newline
34945 0013 33\InsetSpace ~
34946 \InsetSpace ~
34947 \InsetSpace ~
34948 \InsetSpace ~
34949 \InsetSpace ~
34950 \InsetSpace ~
34951 \InsetSpace ~
34952 \InsetSpace ~
34953 \InsetSpace ~
34954 \InsetSpace ~
34955 \InsetSpace ~
34956 \InsetSpace ~
34957 \InsetSpace ~
34958 \InsetSpace ~
34959 \InsetSpace ~
34960 \InsetSpace ~
34961 \InsetSpace ~
34962 \InsetSpace ~
34963  68\InsetSpace ~
34964 \InsetSpace ~
34965 \InsetSpace ~
34966 \InsetSpace ~
34967 \InsetSpace ~
34968 \InsetSpace ~
34969 \InsetSpace ~
34970 \InsetSpace ~
34971  rlc\InsetSpace ~
34972 \InsetSpace ~
34973  a 
34974 \newline
34975 0014 92*00\InsetSpace ~
34976 \InsetSpace ~
34977 \InsetSpace ~
34978 \InsetSpace ~
34979 \InsetSpace ~
34980 \InsetSpace ~
34981 \InsetSpace ~
34982 \InsetSpace ~
34983 \InsetSpace ~
34984 \InsetSpace ~
34985 \InsetSpace ~
34986 \InsetSpace ~
34987 \InsetSpace ~
34988 \InsetSpace ~
34989 \InsetSpace ~
34990  69\InsetSpace ~
34991 \InsetSpace ~
34992 \InsetSpace ~
34993 \InsetSpace ~
34994 \InsetSpace ~
34995 \InsetSpace ~
34996 \InsetSpace ~
34997 \InsetSpace ~
34998  mov\InsetSpace ~
34999 \InsetSpace ~
35000  _foo_hob2_1_1,c
35001  
35002 \newline
35003 \InsetSpace ~
35004 \InsetSpace ~
35005 \InsetSpace ~
35006 \InsetSpace ~
35007 \InsetSpace ~
35008 \InsetSpace ~
35009 \InsetSpace ~
35010 \InsetSpace ~
35011 \InsetSpace ~
35012 \InsetSpace ~
35013 \InsetSpace ~
35014 \InsetSpace ~
35015 \InsetSpace ~
35016 \InsetSpace ~
35017 \InsetSpace ~
35018 \InsetSpace ~
35019 \InsetSpace ~
35020 \InsetSpace ~
35021 \InsetSpace ~
35022 \InsetSpace ~
35023 \InsetSpace ~
35024 \InsetSpace ~
35025 \InsetSpace ~
35026 \InsetSpace ~
35027 \InsetSpace ~
35028  66 ;\InsetSpace ~
35029  hob.c 9 
35030 \newline
35031 0016 E5*01\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  67\InsetSpace ~
35047 \InsetSpace ~
35048 \InsetSpace ~
35049 \InsetSpace ~
35050 \InsetSpace ~
35051 \InsetSpace ~
35052 \InsetSpace ~
35053 \InsetSpace ~
35054  mov\InsetSpace ~
35055 \InsetSpace ~
35056  a,(_gint + 1) 
35057 \newline
35058 0018 33\InsetSpace ~
35059 \InsetSpace ~
35060 \InsetSpace ~
35061 \InsetSpace ~
35062 \InsetSpace ~
35063 \InsetSpace ~
35064 \InsetSpace ~
35065 \InsetSpace ~
35066 \InsetSpace ~
35067 \InsetSpace ~
35068 \InsetSpace ~
35069 \InsetSpace ~
35070 \InsetSpace ~
35071 \InsetSpace ~
35072 \InsetSpace ~
35073 \InsetSpace ~
35074 \InsetSpace ~
35075 \InsetSpace ~
35076  68\InsetSpace ~
35077 \InsetSpace ~
35078 \InsetSpace ~
35079 \InsetSpace ~
35080 \InsetSpace ~
35081 \InsetSpace ~
35082 \InsetSpace ~
35083 \InsetSpace ~
35084  rlc\InsetSpace ~
35085 \InsetSpace ~
35086  a 
35087 \newline
35088 0019 92*01\InsetSpace ~
35089 \InsetSpace ~
35090 \InsetSpace ~
35091 \InsetSpace ~
35092 \InsetSpace ~
35093 \InsetSpace ~
35094 \InsetSpace ~
35095 \InsetSpace ~
35096 \InsetSpace ~
35097 \InsetSpace ~
35098 \InsetSpace ~
35099 \InsetSpace ~
35100 \InsetSpace ~
35101 \InsetSpace ~
35102 \InsetSpace ~
35103
35104  69\InsetSpace ~
35105 \InsetSpace ~
35106 \InsetSpace ~
35107 \InsetSpace ~
35108 \InsetSpace ~
35109 \InsetSpace ~
35110 \InsetSpace ~
35111 \InsetSpace ~
35112  mov\InsetSpace ~
35113 \InsetSpace ~
35114  _foo_hob3_1_1,c 
35115 \newline
35116 \InsetSpace ~
35117 \InsetSpace ~
35118 \InsetSpace ~
35119 \InsetSpace ~
35120 \InsetSpace ~
35121 \InsetSpace ~
35122 \InsetSpace ~
35123 \InsetSpace ~
35124 \InsetSpace ~
35125 \InsetSpace ~
35126 \InsetSpace ~
35127 \InsetSpace ~
35128 \InsetSpace ~
35129 \InsetSpace ~
35130 \InsetSpace ~
35131 \InsetSpace ~
35132 \InsetSpace ~
35133 \InsetSpace ~
35134 \InsetSpace ~
35135 \InsetSpace ~
35136 \InsetSpace ~
35137 \InsetSpace ~
35138 \InsetSpace ~
35139 \InsetSpace ~
35140 \InsetSpace ~
35141  70 ;\InsetSpace ~
35142  hob.c 10 
35143 \newline
35144 001B E5*01\InsetSpace ~
35145 \InsetSpace ~
35146 \InsetSpace ~
35147 \InsetSpace ~
35148 \InsetSpace ~
35149 \InsetSpace ~
35150 \InsetSpace ~
35151 \InsetSpace ~
35152 \InsetSpace ~
35153 \InsetSpace ~
35154 \InsetSpace ~
35155 \InsetSpace ~
35156 \InsetSpace ~
35157 \InsetSpace ~
35158 \InsetSpace ~
35159  71\InsetSpace ~
35160 \InsetSpace ~
35161 \InsetSpace ~
35162 \InsetSpace ~
35163 \InsetSpace ~
35164 \InsetSpace ~
35165 \InsetSpace ~
35166 \InsetSpace ~
35167  mov\InsetSpace ~
35168 \InsetSpace ~
35169  a,(_gint + 1) 
35170 \newline
35171 001D
35172  03\InsetSpace ~
35173 \InsetSpace ~
35174 \InsetSpace ~
35175 \InsetSpace ~
35176 \InsetSpace ~
35177 \InsetSpace ~
35178 \InsetSpace ~
35179 \InsetSpace ~
35180 \InsetSpace ~
35181 \InsetSpace ~
35182 \InsetSpace ~
35183 \InsetSpace ~
35184 \InsetSpace ~
35185 \InsetSpace ~
35186 \InsetSpace ~
35187 \InsetSpace ~
35188 \InsetSpace ~
35189 \InsetSpace ~
35190  72\InsetSpace ~
35191 \InsetSpace ~
35192 \InsetSpace ~
35193 \InsetSpace ~
35194 \InsetSpace ~
35195 \InsetSpace ~
35196 \InsetSpace ~
35197 \InsetSpace ~
35198  rr\InsetSpace ~
35199 \InsetSpace ~
35200 \InsetSpace ~
35201  a 
35202 \newline
35203 001E 54 01\InsetSpace ~
35204 \InsetSpace ~
35205 \InsetSpace ~
35206 \InsetSpace ~
35207 \InsetSpace ~
35208 \InsetSpace ~
35209 \InsetSpace ~
35210 \InsetSpace ~
35211 \InsetSpace ~
35212 \InsetSpace ~
35213 \InsetSpace ~
35214 \InsetSpace ~
35215 \InsetSpace ~
35216 \InsetSpace ~
35217 \InsetSpace ~
35218  73\InsetSpace ~
35219 \InsetSpace ~
35220 \InsetSpace ~
35221 \InsetSpace ~
35222 \InsetSpace ~
35223 \InsetSpace ~
35224 \InsetSpace ~
35225 \InsetSpace ~
35226  anl\InsetSpace ~
35227 \InsetSpace ~
35228  a,#0x01 
35229 \newline
35230 0020 F5*03\InsetSpace ~
35231 \InsetSpace ~
35232 \InsetSpace ~
35233 \InsetSpace ~
35234 \InsetSpace ~
35235 \InsetSpace ~
35236 \InsetSpace ~
35237 \InsetSpace ~
35238 \InsetSpace ~
35239 \InsetSpace ~
35240 \InsetSpace ~
35241 \InsetSpace ~
35242 \InsetSpace ~
35243 \InsetSpace ~
35244 \InsetSpace ~
35245  74\InsetSpace ~
35246 \InsetSpace ~
35247 \InsetSpace ~
35248 \InsetSpace ~
35249 \InsetSpace ~
35250 \InsetSpace ~
35251 \InsetSpace ~
35252 \InsetSpace ~
35253  mov\InsetSpace ~
35254 \InsetSpace ~
35255  _foo_aob1_1_1,a
35256  
35257 \newline
35258 \InsetSpace ~
35259 \InsetSpace ~
35260 \InsetSpace ~
35261 \InsetSpace ~
35262 \InsetSpace ~
35263 \InsetSpace ~
35264 \InsetSpace ~
35265 \InsetSpace ~
35266 \InsetSpace ~
35267 \InsetSpace ~
35268 \InsetSpace ~
35269 \InsetSpace ~
35270 \InsetSpace ~
35271 \InsetSpace ~
35272 \InsetSpace ~
35273 \InsetSpace ~
35274 \InsetSpace ~
35275 \InsetSpace ~
35276 \InsetSpace ~
35277 \InsetSpace ~
35278 \InsetSpace ~
35279 \InsetSpace ~
35280 \InsetSpace ~
35281 \InsetSpace ~
35282 \InsetSpace ~
35283  75 ;\InsetSpace ~
35284  hob.c 11 
35285 \newline
35286 0022 E5*01\InsetSpace ~
35287 \InsetSpace ~
35288 \InsetSpace ~
35289 \InsetSpace ~
35290 \InsetSpace ~
35291 \InsetSpace ~
35292 \InsetSpace ~
35293 \InsetSpace ~
35294 \InsetSpace ~
35295 \InsetSpace ~
35296 \InsetSpace ~
35297 \InsetSpace ~
35298 \InsetSpace ~
35299 \InsetSpace ~
35300 \InsetSpace ~
35301  76\InsetSpace ~
35302 \InsetSpace ~
35303 \InsetSpace ~
35304 \InsetSpace ~
35305 \InsetSpace ~
35306 \InsetSpace ~
35307 \InsetSpace ~
35308 \InsetSpace ~
35309  mov\InsetSpace ~
35310 \InsetSpace ~
35311  a,(_gint + 1) 
35312 \newline
35313 0024 13\InsetSpace ~
35314 \InsetSpace ~
35315 \InsetSpace ~
35316 \InsetSpace ~
35317 \InsetSpace ~
35318 \InsetSpace ~
35319 \InsetSpace ~
35320 \InsetSpace ~
35321 \InsetSpace ~
35322 \InsetSpace ~
35323 \InsetSpace ~
35324 \InsetSpace ~
35325 \InsetSpace ~
35326 \InsetSpace ~
35327 \InsetSpace ~
35328 \InsetSpace ~
35329 \InsetSpace ~
35330 \InsetSpace ~
35331  77\InsetSpace ~
35332 \InsetSpace ~
35333 \InsetSpace ~
35334 \InsetSpace ~
35335 \InsetSpace ~
35336 \InsetSpace ~
35337 \InsetSpace ~
35338 \InsetSpace ~
35339  rrc\InsetSpace ~
35340 \InsetSpace ~
35341  a 
35342 \newline
35343 0025 92*02\InsetSpace ~
35344 \InsetSpace ~
35345 \InsetSpace ~
35346 \InsetSpace ~
35347 \InsetSpace ~
35348 \InsetSpace ~
35349 \InsetSpace ~
35350 \InsetSpace ~
35351 \InsetSpace ~
35352 \InsetSpace ~
35353 \InsetSpace ~
35354 \InsetSpace ~
35355 \InsetSpace ~
35356 \InsetSpace ~
35357 \InsetSpace ~
35358
35359  78\InsetSpace ~
35360 \InsetSpace ~
35361 \InsetSpace ~
35362 \InsetSpace ~
35363 \InsetSpace ~
35364 \InsetSpace ~
35365 \InsetSpace ~
35366 \InsetSpace ~
35367  mov\InsetSpace ~
35368 \InsetSpace ~
35369  _foo_aob2_1_1,c 
35370 \newline
35371 \InsetSpace ~
35372 \InsetSpace ~
35373 \InsetSpace ~
35374 \InsetSpace ~
35375 \InsetSpace ~
35376 \InsetSpace ~
35377 \InsetSpace ~
35378 \InsetSpace ~
35379 \InsetSpace ~
35380 \InsetSpace ~
35381 \InsetSpace ~
35382 \InsetSpace ~
35383 \InsetSpace ~
35384 \InsetSpace ~
35385 \InsetSpace ~
35386 \InsetSpace ~
35387 \InsetSpace ~
35388 \InsetSpace ~
35389 \InsetSpace ~
35390 \InsetSpace ~
35391 \InsetSpace ~
35392 \InsetSpace ~
35393 \InsetSpace ~
35394 \InsetSpace ~
35395 \InsetSpace ~
35396  79 ;\InsetSpace ~
35397  hob.c 12 
35398 \newline
35399 0027 E5*01\InsetSpace ~
35400 \InsetSpace ~
35401 \InsetSpace ~
35402 \InsetSpace ~
35403 \InsetSpace ~
35404 \InsetSpace ~
35405 \InsetSpace ~
35406 \InsetSpace ~
35407 \InsetSpace ~
35408 \InsetSpace ~
35409 \InsetSpace ~
35410 \InsetSpace ~
35411 \InsetSpace ~
35412 \InsetSpace ~
35413 \InsetSpace ~
35414  80\InsetSpace ~
35415 \InsetSpace ~
35416 \InsetSpace ~
35417 \InsetSpace ~
35418 \InsetSpace ~
35419 \InsetSpace ~
35420 \InsetSpace ~
35421 \InsetSpace ~
35422  mov\InsetSpace ~
35423 \InsetSpace ~
35424  a,(_gint + 1) 
35425 \newline
35426 0029
35427  A2 E3\InsetSpace ~
35428 \InsetSpace ~
35429 \InsetSpace ~
35430 \InsetSpace ~
35431 \InsetSpace ~
35432 \InsetSpace ~
35433 \InsetSpace ~
35434 \InsetSpace ~
35435 \InsetSpace ~
35436 \InsetSpace ~
35437 \InsetSpace ~
35438 \InsetSpace ~
35439 \InsetSpace ~
35440 \InsetSpace ~
35441 \InsetSpace ~
35442  81\InsetSpace ~
35443 \InsetSpace ~
35444 \InsetSpace ~
35445 \InsetSpace ~
35446 \InsetSpace ~
35447 \InsetSpace ~
35448 \InsetSpace ~
35449 \InsetSpace ~
35450  mov\InsetSpace ~
35451 \InsetSpace ~
35452  c,acc[3] 
35453 \newline
35454 002B 92*03\InsetSpace ~
35455 \InsetSpace ~
35456 \InsetSpace ~
35457 \InsetSpace ~
35458 \InsetSpace ~
35459 \InsetSpace ~
35460 \InsetSpace ~
35461 \InsetSpace ~
35462 \InsetSpace ~
35463 \InsetSpace ~
35464 \InsetSpace ~
35465 \InsetSpace ~
35466 \InsetSpace ~
35467 \InsetSpace ~
35468 \InsetSpace ~
35469  82\InsetSpace ~
35470 \InsetSpace ~
35471 \InsetSpace ~
35472 \InsetSpace ~
35473 \InsetSpace ~
35474 \InsetSpace ~
35475 \InsetSpace ~
35476 \InsetSpace ~
35477  mov\InsetSpace ~
35478 \InsetSpace ~
35479  _foo_aob3_1_1,c 
35480 \end_layout
35481
35482 \begin_layout Standard
35483 Other variations of these cases however will 
35484 \emph on
35485 not
35486 \emph default
35487  be recognized.
35488  They are standard C expressions, so I heartily recommend these be the only
35489  way to get the highest order bit, (it is portable).
35490  Of course it will be recognized even if it is embedded in other expressions,
35491  e.g.:
35492 \end_layout
35493
35494 \begin_layout Verse
35495
35496 \family typewriter
35497 xyz = gint + ((gint >> 15) & 1);
35498 \end_layout
35499
35500 \begin_layout Standard
35501 will still be recognized.
35502 \end_layout
35503
35504 \begin_layout Subsection
35505 Higher Order Byte
35506 \begin_inset LatexCommand \index{Higher Order Byte}
35507
35508 \end_inset
35509
35510  / Higher Order Word
35511 \begin_inset LatexCommand \index{Higher Order Word}
35512
35513 \end_inset
35514
35515
35516 \end_layout
35517
35518 \begin_layout Standard
35519 It is also frequently required to obtain a higher order byte or word of
35520  a larger integral type (long, int or short types).
35521  SDCC recognizes the following expressions to yield the higher order byte
35522  or word and generates optimized code for it, e.g.:
35523 \end_layout
35524
35525 \begin_layout Verse
35526
35527 \family typewriter
35528 unsigned int gint; 
35529 \newline
35530 unsigned long int glong; 
35531 \newline
35532
35533 \newline
35534 foo () { 
35535 \newline
35536 \InsetSpace ~
35537 \InsetSpace ~
35538 unsigned char hob1,
35539  hob2; 
35540 \newline
35541 \InsetSpace ~
35542 \InsetSpace ~
35543 unsigned int how1, how2; 
35544 \newline
35545 \InsetSpace ~
35546 \InsetSpace ~
35547 ...
35548  
35549 \newline
35550 \InsetSpace ~
35551 \InsetSpace ~
35552 hob1 = (gint >> 8) & 0xFF; 
35553 \newline
35554 \InsetSpace ~
35555 \InsetSpace ~
35556 hob2 = glong >> 24; 
35557 \newline
35558 \InsetSpace ~
35559 \InsetSpace ~
35560 how1 = (glong >> 16) & 0xFFFF;
35561  
35562 \newline
35563 \InsetSpace ~
35564 \InsetSpace ~
35565 how2 = glong >> 8; 
35566 \newline
35567 \InsetSpace ~
35568 \InsetSpace ~
35569 ..
35570  
35571 \newline
35572 }
35573 \end_layout
35574
35575 \begin_layout Standard
35576 will generate the following code:
35577 \end_layout
35578
35579 \begin_layout Verse
35580
35581 \family typewriter
35582 \InsetSpace ~
35583 \InsetSpace ~
35584 \InsetSpace ~
35585 \InsetSpace ~
35586 \InsetSpace ~
35587 \InsetSpace ~
35588 \InsetSpace ~
35589 \InsetSpace ~
35590 \InsetSpace ~
35591 \InsetSpace ~
35592 \InsetSpace ~
35593 \InsetSpace ~
35594 \InsetSpace ~
35595 \InsetSpace ~
35596 \InsetSpace ~
35597 \InsetSpace ~
35598 \InsetSpace ~
35599 \InsetSpace ~
35600 \InsetSpace ~
35601 \InsetSpace ~
35602 \InsetSpace ~
35603 \InsetSpace ~
35604 \InsetSpace ~
35605 \InsetSpace ~
35606 \InsetSpace ~
35607  91 ;\InsetSpace ~
35608  hob.c 15 
35609 \newline
35610 0037 85*01*06\InsetSpace ~
35611 \InsetSpace ~
35612 \InsetSpace ~
35613 \InsetSpace ~
35614 \InsetSpace ~
35615 \InsetSpace ~
35616 \InsetSpace ~
35617 \InsetSpace ~
35618 \InsetSpace ~
35619 \InsetSpace ~
35620 \InsetSpace ~
35621 \InsetSpace ~
35622  92\InsetSpace ~
35623 \InsetSpace ~
35624 \InsetSpace ~
35625 \InsetSpace ~
35626 \InsetSpace ~
35627 \InsetSpace ~
35628 \InsetSpace ~
35629 \InsetSpace ~
35630  mov\InsetSpace ~
35631 \InsetSpace ~
35632  _foo_hob1_1_1,(_gint + 1) 
35633 \newline
35634 \InsetSpace ~
35635 \InsetSpace ~
35636 \InsetSpace ~
35637 \InsetSpace ~
35638 \InsetSpace ~
35639 \InsetSpace ~
35640 \InsetSpace ~
35641 \InsetSpace ~
35642 \InsetSpace ~
35643 \InsetSpace ~
35644 \InsetSpace ~
35645 \InsetSpace ~
35646 \InsetSpace ~
35647 \InsetSpace ~
35648 \InsetSpace ~
35649 \InsetSpace ~
35650 \InsetSpace ~
35651 \InsetSpace ~
35652 \InsetSpace ~
35653 \InsetSpace ~
35654 \InsetSpace ~
35655 \InsetSpace ~
35656 \InsetSpace ~
35657 \InsetSpace ~
35658 \InsetSpace ~
35659  93 ;\InsetSpace ~
35660  hob.c
35661  16 
35662 \newline
35663 003A 85*05*07\InsetSpace ~
35664 \InsetSpace ~
35665 \InsetSpace ~
35666 \InsetSpace ~
35667 \InsetSpace ~
35668 \InsetSpace ~
35669 \InsetSpace ~
35670 \InsetSpace ~
35671 \InsetSpace ~
35672 \InsetSpace ~
35673 \InsetSpace ~
35674 \InsetSpace ~
35675  94\InsetSpace ~
35676 \InsetSpace ~
35677 \InsetSpace ~
35678 \InsetSpace ~
35679 \InsetSpace ~
35680 \InsetSpace ~
35681 \InsetSpace ~
35682 \InsetSpace ~
35683  mov\InsetSpace ~
35684 \InsetSpace ~
35685  _foo_hob2_1_1,(_glong + 3) 
35686 \newline
35687 \InsetSpace ~
35688 \InsetSpace ~
35689 \InsetSpace ~
35690 \InsetSpace ~
35691 \InsetSpace ~
35692 \InsetSpace ~
35693 \InsetSpace ~
35694 \InsetSpace ~
35695 \InsetSpace ~
35696 \InsetSpace ~
35697 \InsetSpace ~
35698 \InsetSpace ~
35699 \InsetSpace ~
35700 \InsetSpace ~
35701 \InsetSpace ~
35702 \InsetSpace ~
35703 \InsetSpace ~
35704 \InsetSpace ~
35705 \InsetSpace ~
35706 \InsetSpace ~
35707 \InsetSpace ~
35708 \InsetSpace ~
35709 \InsetSpace ~
35710 \InsetSpace ~
35711 \InsetSpace ~
35712  95 ;\InsetSpace ~
35713  hob.c 17 
35714 \newline
35715 003D 85*04*08\InsetSpace ~
35716 \InsetSpace ~
35717 \InsetSpace ~
35718 \InsetSpace ~
35719 \InsetSpace ~
35720 \InsetSpace ~
35721 \InsetSpace ~
35722 \InsetSpace ~
35723 \InsetSpace ~
35724 \InsetSpace ~
35725 \InsetSpace ~
35726 \InsetSpace ~
35727
35728  96\InsetSpace ~
35729 \InsetSpace ~
35730 \InsetSpace ~
35731 \InsetSpace ~
35732 \InsetSpace ~
35733 \InsetSpace ~
35734 \InsetSpace ~
35735 \InsetSpace ~
35736  mov\InsetSpace ~
35737 \InsetSpace ~
35738  _foo_how1_1_1,(_glong + 2) 
35739 \newline
35740 0040 85*05*09\InsetSpace ~
35741 \InsetSpace ~
35742 \InsetSpace ~
35743 \InsetSpace ~
35744 \InsetSpace ~
35745 \InsetSpace ~
35746 \InsetSpace ~
35747 \InsetSpace ~
35748 \InsetSpace ~
35749 \InsetSpace ~
35750 \InsetSpace ~
35751 \InsetSpace ~
35752  97\InsetSpace ~
35753 \InsetSpace ~
35754 \InsetSpace ~
35755 \InsetSpace ~
35756 \InsetSpace ~
35757 \InsetSpace ~
35758 \InsetSpace ~
35759 \InsetSpace ~
35760  mov\InsetSpace ~
35761 \InsetSpace ~
35762  (_foo_how1_1_1 +
35763  1),(_glong + 3) 
35764 \newline
35765 0043 85*03*0A\InsetSpace ~
35766 \InsetSpace ~
35767 \InsetSpace ~
35768 \InsetSpace ~
35769 \InsetSpace ~
35770 \InsetSpace ~
35771 \InsetSpace ~
35772 \InsetSpace ~
35773 \InsetSpace ~
35774 \InsetSpace ~
35775 \InsetSpace ~
35776 \InsetSpace ~
35777  98\InsetSpace ~
35778 \InsetSpace ~
35779 \InsetSpace ~
35780 \InsetSpace ~
35781 \InsetSpace ~
35782 \InsetSpace ~
35783 \InsetSpace ~
35784 \InsetSpace ~
35785  mov\InsetSpace ~
35786 \InsetSpace ~
35787  _foo_how2_1_1,(_glong + 1) 
35788 \newline
35789 0046 85*04*0B\InsetSpace ~
35790 \InsetSpace ~
35791 \InsetSpace ~
35792 \InsetSpace ~
35793 \InsetSpace ~
35794 \InsetSpace ~
35795 \InsetSpace ~
35796 \InsetSpace ~
35797 \InsetSpace ~
35798 \InsetSpace ~
35799 \InsetSpace ~
35800 \InsetSpace ~
35801
35802  99\InsetSpace ~
35803 \InsetSpace ~
35804 \InsetSpace ~
35805 \InsetSpace ~
35806 \InsetSpace ~
35807 \InsetSpace ~
35808 \InsetSpace ~
35809 \InsetSpace ~
35810  mov\InsetSpace ~
35811 \InsetSpace ~
35812  (_foo_how2_1_1 + 1),(_glong + 2) 
35813 \end_layout
35814
35815 \begin_layout Standard
35816 Again, variations of these cases may 
35817 \emph on
35818 not
35819 \emph default
35820  be recognized.
35821  They are standard C expressions, so I heartily recommend these be the only
35822  way to get the higher order byte/word, (it is portable).
35823  Of course it will be recognized even if it is embedded in other expressions,
35824  e.g.:
35825 \end_layout
35826
35827 \begin_layout Verse
35828
35829 \family typewriter
35830 xyz = gint + ((gint >> 8) & 0xFF);
35831 \end_layout
35832
35833 \begin_layout Standard
35834 will still be recognized.
35835 \end_layout
35836
35837 \begin_layout Subsection
35838 Peephole Optimizer
35839 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
35840
35841 \end_inset
35842
35843
35844 \begin_inset LatexCommand \index{Peephole optimizer}
35845
35846 \end_inset
35847
35848
35849 \end_layout
35850
35851 \begin_layout Standard
35852 The compiler uses a rule based, pattern matching and re-writing mechanism
35853  for peep-hole optimization.
35854  It is inspired by 
35855 \emph on
35856 copt
35857 \emph default
35858  a peep-hole optimizer by Christopher W.
35859  Fraser (cwfraser\InsetSpace ~
35860 @\InsetSpace ~
35861 microsoft.com).
35862  A default set of rules are compiled into the compiler, additional rules
35863  may be added with the 
35864 \emph on
35865 -
35866 \begin_inset ERT
35867 status collapsed
35868
35869 \begin_layout Standard
35870
35871
35872 \backslash
35873 /
35874 \end_layout
35875
35876 \end_inset
35877
35878 -peep-file
35879 \begin_inset LatexCommand \index{-\/-peep-file}
35880
35881 \end_inset
35882
35883  <filename>
35884 \emph default
35885  option.
35886  The rule language is best illustrated with examples.
35887 \end_layout
35888
35889 \begin_layout Verse
35890
35891 \family typewriter
35892 replace { 
35893 \newline
35894 \InsetSpace ~
35895 \InsetSpace ~
35896 mov %1,a 
35897 \newline
35898 \InsetSpace ~
35899 \InsetSpace ~
35900 mov a,%1
35901 \newline
35902 } by {
35903 \newline
35904 \InsetSpace ~
35905 \InsetSpace ~
35906 mov %1,a
35907 \newline
35908 }
35909 \end_layout
35910
35911 \begin_layout Standard
35912 The above rule will change the following assembly
35913 \begin_inset LatexCommand \index{Assembler routines}
35914
35915 \end_inset
35916
35917  sequence:
35918 \end_layout
35919
35920 \begin_layout Verse
35921
35922 \family typewriter
35923 mov r1,a 
35924 \newline
35925 mov a,r1
35926 \end_layout
35927
35928 \begin_layout Standard
35929 to
35930 \end_layout
35931
35932 \begin_layout Verse
35933
35934 \family typewriter
35935 mov r1,a
35936 \end_layout
35937
35938 \begin_layout Standard
35939 Note: All occurrences of a 
35940 \emph on
35941 %n
35942 \emph default
35943  (pattern variable) must denote the same string.
35944  With the above rule, the assembly sequence:
35945 \end_layout
35946
35947 \begin_layout Verse
35948
35949 \family typewriter
35950 mov r1,a 
35951 \newline
35952 mov a,r2
35953 \end_layout
35954
35955 \begin_layout Standard
35956 will remain unmodified.
35957 \newline
35958
35959 \newline
35960 Other special case optimizations may be added by the
35961  user (via 
35962 \emph on
35963 -
35964 \begin_inset ERT
35965 status collapsed
35966
35967 \begin_layout Standard
35968
35969
35970 \backslash
35971 /
35972 \end_layout
35973
35974 \end_inset
35975
35976 -peep-file option
35977 \emph default
35978 ).
35979  E.g.
35980  some variants of the 8051 MCU
35981 \begin_inset LatexCommand \index{MCS51 variants}
35982
35983 \end_inset
35984
35985  allow only 
35986 \family typewriter
35987 ajmp
35988 \family default
35989  and 
35990 \family typewriter
35991 acall
35992 \family default
35993 .
35994  The following two rules will change all 
35995 \family typewriter
35996 ljmp
35997 \family default
35998  and 
35999 \family typewriter
36000 lcall
36001 \family default
36002  to 
36003 \family typewriter
36004 ajmp
36005 \family default
36006  and 
36007 \family typewriter
36008 acall
36009 \end_layout
36010
36011 \begin_layout Verse
36012
36013 \family typewriter
36014 replace { lcall %1 } by { acall %1 } 
36015 \newline
36016 replace { ljmp %1 } by { ajmp %1 }
36017 \end_layout
36018
36019 \begin_layout Standard
36020 (NOTE: from version 2.7.3 on, you can use option -
36021 \emph on
36022
36023 \begin_inset ERT
36024 status collapsed
36025
36026 \begin_layout Standard
36027
36028
36029 \backslash
36030 /
36031 \end_layout
36032
36033 \end_inset
36034
36035
36036 \emph default
36037 -acall-ajmp
36038 \begin_inset LatexCommand \index{-\/-acall-ajmp}
36039
36040 \end_inset
36041
36042 , which also takes care of aligning the interrupt vectors properly.)
36043 \newline
36044
36045 \end_layout
36046
36047 \begin_layout Standard
36048 The 
36049 \emph on
36050 inline-assembler code
36051 \emph default
36052  is also passed through the peep hole optimizer, thus the peephole optimizer
36053  can also be used as an assembly level macro expander.
36054  The rules themselves are MCU dependent whereas the rule language infra-structur
36055 e is MCU independent.
36056  Peephole optimization rules for other MCU can be easily programmed using
36057  the rule language.
36058 \newline
36059
36060 \newline
36061 The syntax for a rule is as follows:
36062 \end_layout
36063
36064 \begin_layout Verse
36065
36066 \family typewriter
36067 rule := replace [ restart ] '{' <assembly sequence> '
36068 \backslash
36069 n' 
36070 \newline
36071 \InsetSpace ~
36072  \InsetSpace ~
36073  \InsetSpace ~
36074  \InsetSpace ~
36075  \InsetSpace ~
36076  \InsetSpace ~
36077  \InsetSpace ~
36078  \InsetSpace ~
36079  \InsetSpace ~
36080  \InsetSpace ~
36081  \InsetSpace ~
36082  \InsetSpace ~
36083  \InsetSpace ~
36084  \InsetSpace ~
36085  '}' by '{' '
36086 \backslash
36087 n' 
36088 \newline
36089 \InsetSpace ~
36090  \InsetSpace ~
36091  \InsetSpace ~
36092  \InsetSpace ~
36093  \InsetSpace ~
36094  \InsetSpace ~
36095  \InsetSpace ~
36096  \InsetSpace ~
36097  \InsetSpace ~
36098  \InsetSpace ~
36099  \InsetSpace ~
36100  \InsetSpace ~
36101  \InsetSpace ~
36102  \InsetSpace ~
36103  \InsetSpace ~
36104  \InsetSpace ~
36105  <assembly sequence> '
36106 \backslash
36107 n' 
36108 \newline
36109 \InsetSpace ~
36110  \InsetSpace ~
36111  \InsetSpace ~
36112  \InsetSpace ~
36113  \InsetSpace ~
36114  \InsetSpace ~
36115  \InsetSpace ~
36116  \InsetSpace ~
36117  \InsetSpace ~
36118  \InsetSpace ~
36119  \InsetSpace ~
36120  \InsetSpace ~
36121  \InsetSpace ~
36122  \InsetSpace ~
36123  '}' [if <functionName> ] '
36124 \backslash
36125 n' 
36126 \end_layout
36127
36128 \begin_layout Standard
36129 <assembly sequence> := assembly instruction (each instruction including
36130  labels must be on a separate line).
36131 \newline
36132
36133 \newline
36134 The optimizer will apply to the rules
36135  one by one from the top in the sequence of their appearance, it will terminate
36136  when all rules are exhausted.
36137  If the 'restart' option is specified, then the optimizer will start matching
36138  the rules again from the top, this option for a rule is expensive (performance)
36139 , it is intended to be used in situations where a transformation will trigger
36140  the same rule again.
36141  An example of this (not a good one, it has side effects) is the following
36142  rule:
36143 \end_layout
36144
36145 \begin_layout Verse
36146
36147 \family typewriter
36148 replace restart { 
36149 \newline
36150 \InsetSpace ~
36151 \InsetSpace ~
36152 pop %1 
36153 \newline
36154 \InsetSpace ~
36155 \InsetSpace ~
36156 push %1 } by { 
36157 \newline
36158 \InsetSpace ~
36159 \InsetSpace ~
36160 ; nop 
36161 \newline
36162 }
36163 \end_layout
36164
36165 \begin_layout Standard
36166 Note that the replace pattern cannot be a blank, but can be a comment line.
36167  Without the 'restart' option only the innermost 'pop' 'push' pair would
36168  be eliminated, i.e.:
36169 \end_layout
36170
36171 \begin_layout Verse
36172
36173 \family typewriter
36174 pop ar1 
36175 \newline
36176 pop ar2 
36177 \newline
36178 push ar2 
36179 \newline
36180 push ar1
36181 \end_layout
36182
36183 \begin_layout Standard
36184 would result in:
36185 \end_layout
36186
36187 \begin_layout Verse
36188
36189 \family typewriter
36190 pop ar1 
36191 \newline
36192 ; nop 
36193 \newline
36194 push ar1
36195 \end_layout
36196
36197 \begin_layout Standard
36198
36199 \emph on
36200 with
36201 \emph default
36202  the restart option the rule will be applied again to the resulting code
36203  and then all the pop-push pairs will be eliminated to yield:
36204 \end_layout
36205
36206 \begin_layout Verse
36207
36208 \family typewriter
36209 ; nop 
36210 \newline
36211 ; nop
36212 \end_layout
36213
36214 \begin_layout Standard
36215 A conditional function can be attached to a rule.
36216  Attaching rules are somewhat more involved, let me illustrate this with
36217  an example.
36218 \end_layout
36219
36220 \begin_layout Verse
36221
36222 \family typewriter
36223 replace { 
36224 \newline
36225 \InsetSpace ~
36226  \InsetSpace ~
36227  \InsetSpace ~
36228 ljmp %5 
36229 \newline
36230 %2:
36231 \newline
36232 } by { 
36233 \newline
36234 \InsetSpace ~
36235  \InsetSpace ~
36236  \InsetSpace ~
36237 sjmp %5 
36238 \newline
36239 %2:
36240 \newline
36241 } if labelInRange
36242 \end_layout
36243
36244 \begin_layout Standard
36245 The optimizer does a look-up of a function name table defined in function
36246  
36247 \emph on
36248 callFuncByName
36249 \emph default
36250  in the source file SDCCpeeph.c, with the name 
36251 \emph on
36252 labelInRange
36253 \emph default
36254 .
36255  If it finds a corresponding entry the function is called.
36256  Note there can be no parameters specified for these functions, in this
36257  case the use of 
36258 \emph on
36259 %5
36260 \emph default
36261  is crucial, since the function 
36262 \emph on
36263 labelInRange
36264 \emph default
36265  expects to find the label in that particular variable (the hash table containin
36266 g the variable bindings is passed as a parameter).
36267  If you want to code more such functions, take a close look at the function
36268  labelInRange and the calling mechanism in source file SDCCpeeph.c.
36269  Currently implemented are 
36270 \emph on
36271 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
36272  24bitMode, portIsDS390, 24bitModeAndPortDS390 
36273 \emph default
36274 and
36275 \emph on
36276  notVolatile
36277 \emph default
36278 .
36279 \end_layout
36280
36281 \begin_layout Standard
36282 I know this whole thing is a little kludgey, but maybe some day we will
36283  have some better means.
36284  If you are looking at this file, you will see the default rules that are
36285  compiled into the compiler, you can add your own rules in the default set
36286  there if you get tired of specifying the -
36287 \begin_inset ERT
36288 status collapsed
36289
36290 \begin_layout Standard
36291
36292
36293 \backslash
36294 /
36295 \end_layout
36296
36297 \end_inset
36298
36299 -peep-file option.
36300 \end_layout
36301
36302 \begin_layout Section
36303 ANSI-Compliance
36304 \begin_inset LatexCommand \index{ANSI-compliance}
36305
36306 \end_inset
36307
36308
36309 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
36310
36311 \end_inset
36312
36313
36314 \end_layout
36315
36316 \begin_layout Standard
36317 The latest publically available version of the standard 
36318 \emph on
36319 ISO/IEC 9899 - Programming languages - C
36320 \emph default
36321  should be available at: 
36322 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
36323
36324 \end_inset
36325
36326 .
36327 \newline
36328
36329 \end_layout
36330
36331 \begin_layout Standard
36332 Deviations from the compliance:
36333 \end_layout
36334
36335 \begin_layout Itemize
36336 functions are not reentrant
36337 \begin_inset LatexCommand \index{reentrant}
36338
36339 \end_inset
36340
36341  unless explicitly declared as such or the 
36342 \series bold
36343 -
36344 \begin_inset ERT
36345 status collapsed
36346
36347 \begin_layout Standard
36348
36349
36350 \backslash
36351 /
36352 \end_layout
36353
36354 \end_inset
36355
36356 -stack-auto
36357 \begin_inset LatexCommand \index{-\/-stack-auto}
36358
36359 \end_inset
36360
36361
36362 \series default
36363  command line option is specified.
36364 \end_layout
36365
36366 \begin_layout Itemize
36367 structures
36368 \begin_inset LatexCommand \index{struct}
36369
36370 \end_inset
36371
36372  and unions
36373 \begin_inset LatexCommand \index{union}
36374
36375 \end_inset
36376
36377  cannot be assigned values directly, cannot be passed as function parameters
36378  or assigned to each other and cannot be a return value
36379 \begin_inset LatexCommand \index{return value}
36380
36381 \end_inset
36382
36383  from a function, e.g.:
36384 \end_layout
36385
36386 \begin_deeper
36387 \begin_layout Verse
36388
36389 \family typewriter
36390 struct s { ...
36391  }; 
36392 \newline
36393 struct s s1, s2; 
36394 \newline
36395 foo() 
36396 \newline
36397
36398 \newline
36399 \InsetSpace ~
36400 \InsetSpace ~
36401 \InsetSpace ~
36402 \InsetSpace ~
36403 ...
36404  
36405 \newline
36406 \InsetSpace ~
36407 \InsetSpace ~
36408 \InsetSpace ~
36409 \InsetSpace ~
36410 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
36411 \newline
36412 \InsetSpace ~
36413 \InsetSpace ~
36414 \InsetSpace ~
36415 \InsetSpace ~
36416 ...
36417  
36418 \newline
36419 }
36420 \newline
36421
36422 \series bold
36423 struct
36424 \series default
36425  s foo1 (
36426 \series bold
36427 struct
36428 \series default
36429  s parms) /* invalid in SDCC although allowed in ANSI */
36430 \newline
36431
36432 \newline
36433 \InsetSpace ~
36434 \InsetSpace ~
36435 \InsetSpace ~
36436 \InsetSpace ~
36437 struct s rets;
36438  
36439 \newline
36440 \InsetSpace ~
36441 \InsetSpace ~
36442 \InsetSpace ~
36443 \InsetSpace ~
36444 ...
36445  
36446 \newline
36447 \InsetSpace ~
36448 \InsetSpace ~
36449 \InsetSpace ~
36450 \InsetSpace ~
36451 return rets; /* is invalid in SDCC although allowed in ANSI */ 
36452 \newline
36453 }
36454 \end_layout
36455
36456 \end_deeper
36457 \begin_layout Itemize
36458 initialization of structure arrays must be fully braced.
36459 \end_layout
36460
36461 \begin_deeper
36462 \begin_layout Verse
36463
36464 \family typewriter
36465 struct s { char x } a[] = {1, 2};\InsetSpace ~
36466 \InsetSpace ~
36467 \InsetSpace ~
36468 \InsetSpace ~
36469 \InsetSpace ~
36470 /* invalid in SDCC */
36471 \newline
36472 struct s { char x
36473  } a[] = {{1}, {2}}; /* OK */
36474 \end_layout
36475
36476 \end_deeper
36477 \begin_layout Itemize
36478 'long long
36479 \begin_inset LatexCommand \index{long long (not supported)}
36480
36481 \end_inset
36482
36483 ' (64 bit integers
36484 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
36485
36486 \end_inset
36487
36488 ) not supported.
36489 \end_layout
36490
36491 \begin_layout Itemize
36492 'double
36493 \begin_inset LatexCommand \index{double (not supported)}
36494
36495 \end_inset
36496
36497 ' precision floating point 
36498 \begin_inset LatexCommand \index{Floating point support}
36499
36500 \end_inset
36501
36502 not supported.
36503 \end_layout
36504
36505 \begin_layout Itemize
36506 Old K&R style
36507 \begin_inset LatexCommand \index{K\&R style}
36508
36509 \end_inset
36510
36511  function declarations are NOT allowed.
36512 \end_layout
36513
36514 \begin_deeper
36515 \begin_layout Verse
36516
36517 \family typewriter
36518 foo(i,j) /* this old style of function declarations */ 
36519 \newline
36520 int i,j; /* is valid
36521  in ANSI but not valid in SDCC */ 
36522 \newline
36523
36524 \newline
36525 \InsetSpace ~
36526 \InsetSpace ~
36527 \InsetSpace ~
36528 \InsetSpace ~
36529 ...
36530  
36531 \newline
36532 }
36533 \end_layout
36534
36535 \end_deeper
36536 \begin_layout Itemize
36537 Most enhancements in C99 are not supported, e.g.:
36538 \end_layout
36539
36540 \begin_deeper
36541 \begin_layout Verse
36542
36543 \family typewriter
36544 for (
36545 \series bold
36546 int
36547 \series default
36548  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
36549 \end_layout
36550
36551 \end_deeper
36552 \begin_layout Itemize
36553 But some have been added recently in SDCC 2.7.0.
36554  They must be considered alpha quality however.
36555 \end_layout
36556
36557 \begin_deeper
36558 \begin_layout Verse
36559
36560 \family typewriter
36561 \series bold
36562 inline
36563 \begin_inset LatexCommand \index{inline (not supported)}
36564
36565 \end_inset
36566
36567
36568 \series default
36569  int increment (int a) { return a+1; } /* inlines the increment without
36570  function call overhead */
36571 \newline
36572 int * 
36573 \series bold
36574 restrict
36575 \begin_inset LatexCommand \index{inline (not supported)}
36576
36577 \end_inset
36578
36579
36580 \series default
36581  p; /* accepted but ignored */
36582 \end_layout
36583
36584 \end_deeper
36585 \begin_layout Itemize
36586 Certain words that are valid identifiers in the standard may be reserved
36587  words in SDCC unless the 
36588 \series bold
36589 -
36590 \begin_inset ERT
36591 status collapsed
36592
36593 \begin_layout Standard
36594
36595
36596 \backslash
36597 /
36598 \end_layout
36599
36600 \end_inset
36601
36602 -std-c89
36603 \begin_inset LatexCommand \index{-\/-std-c89}
36604
36605 \end_inset
36606
36607  or -
36608 \begin_inset ERT
36609 status collapsed
36610
36611 \begin_layout Standard
36612
36613
36614 \backslash
36615 /
36616 \end_layout
36617
36618 \end_inset
36619
36620 -std-c99
36621 \begin_inset LatexCommand \index{-\/-std-c99}
36622
36623 \end_inset
36624
36625
36626 \series default
36627  command line options are used.
36628  These may include (depending on the selected processor): 'at', 'banked',
36629  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
36630 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
36631  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
36632  '_naked'.
36633  Compliant equivalents of these keywords are always available in a form
36634  that begin with two underscores
36635 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
36636
36637 \end_inset
36638
36639 , f.e.
36640  '__data' instead of 'data'.
36641 \end_layout
36642
36643 \begin_layout Itemize
36644 integer promotion of variable arguments is not performed if the argument
36645  is explicitly taypecasted unless the
36646 \series bold
36647  -
36648 \begin_inset ERT
36649 status collapsed
36650
36651 \begin_layout Standard
36652
36653
36654 \backslash
36655 /
36656 \end_layout
36657
36658 \end_inset
36659
36660 -std-c89
36661 \begin_inset LatexCommand \index{-\/-std-c89}
36662
36663 \end_inset
36664
36665  or -
36666 \begin_inset ERT
36667 status collapsed
36668
36669 \begin_layout Standard
36670
36671
36672 \backslash
36673 /
36674 \end_layout
36675
36676 \end_inset
36677
36678 -std-c99
36679 \begin_inset LatexCommand \index{-\/-std-c99}
36680
36681 \end_inset
36682
36683
36684 \series default
36685  command line options are used.
36686 \end_layout
36687
36688 \begin_deeper
36689 \begin_layout Verse
36690
36691 \family typewriter
36692 void vararg_func (char *str, ...) { atr; }
36693 \newline
36694
36695 \newline
36696 void main (void)
36697 \newline
36698 {
36699 \newline
36700 \InsetSpace ~
36701 \InsetSpace ~
36702 char c = 10;
36703 \newline
36704
36705 \newline
36706 \InsetSpace ~
36707 \InsetSpace ~
36708 /* argument
36709  u is promoted to int before
36710 \newline
36711 \InsetSpace ~
36712 \InsetSpace ~
36713 \InsetSpace ~
36714 * passing to function */
36715 \newline
36716 \InsetSpace ~
36717 \InsetSpace ~
36718 vararg_func (
36719 \begin_inset Quotes sld
36720 \end_inset
36721
36722 %c
36723 \begin_inset Quotes srd
36724 \end_inset
36725
36726 , c);
36727 \newline
36728
36729 \newline
36730 \InsetSpace ~
36731 \InsetSpace ~
36732 /* argument u is not promoted to int,
36733 \newline
36734 \InsetSpace ~
36735 \InsetSpace ~
36736 \InsetSpace ~
36737 * it is passed as char to function
36738 \newline
36739 \InsetSpace ~
36740 \InsetSpace ~
36741 \InsetSpace ~
36742 *
36743  if --std-cXX is not defined;
36744 \newline
36745 \InsetSpace ~
36746 \InsetSpace ~
36747 \InsetSpace ~
36748 * is promoted to int before passing
36749 \newline
36750 \InsetSpace ~
36751 \InsetSpace ~
36752 \InsetSpace ~
36753 * to function
36754  if --std-cXX is defined */
36755 \newline
36756 \InsetSpace ~
36757 \InsetSpace ~
36758 vararg_func (
36759 \begin_inset Quotes sld
36760 \end_inset
36761
36762 %bc
36763 \begin_inset Quotes srd
36764 \end_inset
36765
36766 , (char)u);
36767 \newline
36768 }
36769 \end_layout
36770
36771 \end_deeper
36772 \begin_layout Section
36773 Cyclomatic Complexity
36774 \begin_inset LatexCommand \index{Cyclomatic complexity}
36775
36776 \end_inset
36777
36778
36779 \end_layout
36780
36781 \begin_layout Standard
36782 Cyclomatic complexity of a function is defined as the number of independent
36783  paths the program can take during execution of the function.
36784  This is an important number since it defines the number test cases you
36785  have to generate to validate the function.
36786  The accepted industry standard for complexity number is 10, if the cyclomatic
36787  complexity reported by SDCC exceeds 10 you should think about simplification
36788  of the function logic.
36789  Note that the complexity level is not related to the number of lines of
36790  code in a function.
36791  Large functions can have low complexity, and small functions can have large
36792  complexity levels.
36793  
36794 \newline
36795
36796 \newline
36797 SDCC uses the following formula to compute the complexity:
36798 \newline
36799
36800 \end_layout
36801
36802 \begin_layout Standard
36803 complexity = (number of edges in control flow graph) - (number of nodes
36804  in control flow graph) + 2;
36805 \newline
36806
36807 \newline
36808 Having said that the industry standard is 10,
36809  you should be aware that in some cases it be may unavoidable to have a
36810  complexity level of less than 10.
36811  For example if you have switch statement with more than 10 case labels,
36812  each case label adds one to the complexity level.
36813  The complexity level is by no means an absolute measure of the algorithmic
36814  complexity of the function, it does however provide a good starting point
36815  for which functions you might look at for further optimization.
36816 \end_layout
36817
36818 \begin_layout Section
36819 Retargetting for other Processors
36820 \end_layout
36821
36822 \begin_layout Standard
36823 The issues for retargetting the compiler are far too numerous to be covered
36824  by this document.
36825  What follows is a brief description of each of the seven phases of the
36826  compiler and its MCU dependency.
36827 \end_layout
36828
36829 \begin_layout Itemize
36830 Parsing the source and building the annotated parse tree.
36831  This phase is largely MCU independent (except for the language extensions).
36832  Syntax & semantic checks are also done in this phase, along with some initial
36833  optimizations like back patching labels and the pattern matching optimizations
36834  like bit-rotation etc.
36835 \end_layout
36836
36837 \begin_layout Itemize
36838 The second phase involves generating an intermediate code which can be easy
36839  manipulated during the later phases.
36840  This phase is entirely MCU independent.
36841  The intermediate code generation assumes the target machine has unlimited
36842  number of registers, and designates them with the name iTemp.
36843  The compiler can be made to dump a human readable form of the code generated
36844  by using the -
36845 \begin_inset ERT
36846 status collapsed
36847
36848 \begin_layout Standard
36849
36850
36851 \backslash
36852 /
36853 \end_layout
36854
36855 \end_inset
36856
36857 -dumpraw option.
36858 \end_layout
36859
36860 \begin_layout Itemize
36861 This phase does the bulk of the standard optimizations and is also MCU independe
36862 nt.
36863  This phase can be broken down into several sub-phases:
36864 \newline
36865
36866 \newline
36867 Break down intermediate
36868  code (iCode) into basic blocks.
36869 \newline
36870 Do control flow & data flow analysis on the
36871  basic blocks.
36872 \newline
36873 Do local common subexpression elimination, then global subexpressio
36874 n elimination
36875 \newline
36876 Dead code elimination
36877 \newline
36878 Loop optimizations
36879 \newline
36880 If loop optimizations
36881  caused any changes then do 'global subexpression elimination' and 'dead
36882  code elimination' again.
36883 \end_layout
36884
36885 \begin_layout Itemize
36886 This phase determines the live-ranges; by live range I mean those iTemp
36887  variables defined by the compiler that still survive after all the optimization
36888 s.
36889  Live range analysis
36890 \begin_inset LatexCommand \index{Live range analysis}
36891
36892 \end_inset
36893
36894  is essential for register allocation, since these computation determines
36895  which of these iTemps will be assigned to registers, and for how long.
36896 \end_layout
36897
36898 \begin_layout Itemize
36899 Phase five is register allocation.
36900  There are two parts to this process.
36901 \newline
36902
36903 \newline
36904 The first part I call 'register packing'
36905  (for lack of a better term).
36906  In this case several MCU specific expression folding is done to reduce
36907  register pressure.
36908 \newline
36909
36910 \newline
36911 The second part is more MCU independent and deals with
36912  allocating registers to the remaining live ranges.
36913  A lot of MCU specific code does creep into this phase because of the limited
36914  number of index registers available in the 8051.
36915 \end_layout
36916
36917 \begin_layout Itemize
36918 The Code generation phase is (unhappily), entirely MCU dependent and very
36919  little (if any at all) of this code can be reused for other MCU.
36920  However the scheme for allocating a homogenized assembler operand for each
36921  iCode operand may be reused.
36922 \end_layout
36923
36924 \begin_layout Itemize
36925 As mentioned in the optimization section the peep-hole optimizer is rule
36926  based system, which can reprogrammed for other MCUs.
36927 \end_layout
36928
36929 \begin_layout Standard
36930 More information is available on SDCC Wiki
36931 \begin_inset LatexCommand \index{wiki}
36932
36933 \end_inset
36934
36935  (preliminary link 
36936 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
36937
36938 \end_inset
36939
36940 ) and in the thread 
36941 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
36942
36943 \end_inset
36944
36945  .
36946 \end_layout
36947
36948 \begin_layout Chapter
36949 Compiler internals
36950 \begin_inset LatexCommand \index{Compiler internals}
36951
36952 \end_inset
36953
36954
36955 \end_layout
36956
36957 \begin_layout Section
36958 The anatomy of the compiler
36959 \begin_inset LatexCommand \label{sub:The-anatomy-of}
36960
36961 \end_inset
36962
36963
36964 \end_layout
36965
36966 \begin_layout Standard
36967
36968 \shape italic
36969 This is an excerpt from an article published in Circuit Cellar Magazine
36970  in 
36971 \series bold
36972 August 2000
36973 \series default
36974 .
36975  It's a little outdated (the compiler is much more efficient now and user/develo
36976 per friendly), but pretty well exposes the guts of it all.
36977 \shape default
36978
36979 \newline
36980
36981 \newline
36982 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
36983  It is fairly easy to retarget for other 8-bit MCU.
36984  Here we take a look at some of the internals of the compiler.
36985  
36986 \end_layout
36987
36988 \begin_layout Paragraph*
36989 Parsing
36990 \begin_inset LatexCommand \index{Parsing}
36991
36992 \end_inset
36993
36994  
36995 \end_layout
36996
36997 \begin_layout Standard
36998 Parsing the input source file and creating an AST (Annotated Syntax Tree
36999 \begin_inset LatexCommand \index{Annotated syntax tree}
37000
37001 \end_inset
37002
37003 ).
37004  This phase also involves propagating types (annotating each node of the
37005  parse tree with type information) and semantic analysis.
37006  There are some MCU specific parsing rules.
37007  For example the storage classes, the extended storage classes are MCU specific
37008  while there may be a xdata storage class for 8051 there is no such storage
37009  class for z80 or Atmel AVR.
37010  SDCC allows MCU specific storage class extensions, i.e.
37011  xdata will be treated as a storage class specifier when parsing 8051 C
37012  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
37013  C code.
37014 \end_layout
37015
37016 \begin_layout Paragraph*
37017 Generating iCode
37018 \begin_inset LatexCommand \index{iCode}
37019
37020 \end_inset
37021
37022
37023 \end_layout
37024
37025 \begin_layout Standard
37026 Intermediate code generation.
37027  In this phase the AST is broken down into three-operand form (iCode).
37028  These three operand forms are represented as doubly linked lists.
37029  ICode is the term given to the intermediate form generated by the compiler.
37030  ICode example section shows some examples of iCode generated for some simple
37031  C source functions.
37032 \end_layout
37033
37034 \begin_layout Paragraph*
37035 Optimizations
37036 \begin_inset LatexCommand \index{Optimizations}
37037
37038 \end_inset
37039
37040 .
37041 \end_layout
37042
37043 \begin_layout Standard
37044 Bulk of the target independent optimizations is performed in this phase.
37045  The optimizations include constant propagation, common sub-expression eliminati
37046 on, loop invariant code movement, strength reduction of loop induction variables
37047  and dead-code elimination.
37048 \end_layout
37049
37050 \begin_layout Paragraph*
37051 Live range analysis
37052 \begin_inset LatexCommand \index{Live range analysis}
37053
37054 \end_inset
37055
37056
37057 \end_layout
37058
37059 \begin_layout Standard
37060 During intermediate code generation phase, the compiler assumes the target
37061  machine has infinite number of registers and generates a lot of temporary
37062  variables.
37063  The live range computation determines the lifetime of each of these compiler-ge
37064 nerated temporaries.
37065  A picture speaks a thousand words.
37066  ICode example sections show the live range annotations for each of the
37067  operand.
37068  It is important to note here, each iCode is assigned a number in the order
37069  of its execution in the function.
37070  The live ranges are computed in terms of these numbers.
37071  The from number is the number of the iCode which first defines the operand
37072  and the to number signifies the iCode which uses this operand last.
37073 \end_layout
37074
37075 \begin_layout Paragraph*
37076 Register Allocation
37077 \begin_inset LatexCommand \index{Register allocation}
37078
37079 \end_inset
37080
37081
37082 \end_layout
37083
37084 \begin_layout Standard
37085 The register allocation determines the type and number of registers needed
37086  by each operand.
37087  In most MCUs only a few registers can be used for indirect addressing.
37088  In case of 8051 for example the registers R0 & R1 can be used to indirectly
37089  address the internal ram and DPTR to indirectly address the external ram.
37090  The compiler will try to allocate the appropriate register to pointer variables
37091  if it can.
37092  ICode example section shows the operands annotated with the registers assigned
37093  to them.
37094  The compiler will try to keep operands in registers as much as possible;
37095  there are several schemes the compiler uses to do achieve this.
37096  When the compiler runs out of registers the compiler will check to see
37097  if there are any live operands which is not used or defined in the current
37098  basic block being processed, if there are any found then it will push that
37099  operand and use the registers in this block, the operand will then be popped
37100  at the end of the basic block.
37101  
37102 \end_layout
37103
37104 \begin_layout Standard
37105 There are other MCU specific considerations in this phase.
37106  Some MCUs have an accumulator; very short-lived operands could be assigned
37107  to the accumulator instead of a general-purpose register.
37108 \end_layout
37109
37110 \begin_layout Paragraph*
37111 Code generation
37112 \end_layout
37113
37114 \begin_layout Standard
37115 Figure II gives a table of iCode
37116 \begin_inset LatexCommand \index{iCode}
37117
37118 \end_inset
37119
37120  operations supported by the compiler.
37121  The code generation involves translating these operations into corresponding
37122  assembly code for the processor.
37123  This sounds overly simple but that is the essence of code generation.
37124  Some of the iCode operations are generated on a MCU specific manner for
37125  example, the z80 port does not use registers to pass parameters so the
37126  SEND and RECV iCode operations will not be generated, and it also does
37127  not support JUMPTABLES.
37128  
37129 \newline
37130
37131 \end_layout
37132
37133 \begin_layout Standard
37134
37135 \size footnotesize
37136 Figure II 
37137 \begin_inset Tabular
37138 <lyxtabular version="3" rows="39" columns="4">
37139 <features islongtable="true" headBottomDL="true">
37140 <column alignment="block" valignment="top" leftline="true" width="13col%">
37141 <column alignment="left" valignment="top" leftline="true" width="13col%">
37142 <column alignment="block" valignment="top" leftline="true" width="22col%">
37143 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
37144 <row topline="true" bottomline="true" endhead="true">
37145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37146 \begin_inset Text
37147
37148 \begin_layout Standard
37149
37150 \series bold
37151 iCode
37152 \series default
37153
37154 \begin_inset LatexCommand \index{iCode}
37155
37156 \end_inset
37157
37158
37159 \end_layout
37160
37161 \end_inset
37162 </cell>
37163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37164 \begin_inset Text
37165
37166 \begin_layout Standard
37167
37168 \series bold
37169 Operands
37170 \end_layout
37171
37172 \end_inset
37173 </cell>
37174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37175 \begin_inset Text
37176
37177 \begin_layout Standard
37178
37179 \series bold
37180 Description
37181 \end_layout
37182
37183 \end_inset
37184 </cell>
37185 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37186 \begin_inset Text
37187
37188 \begin_layout Standard
37189
37190 \series bold
37191 C Equivalent
37192 \end_layout
37193
37194 \end_inset
37195 </cell>
37196 </row>
37197 <row topline="true">
37198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37199 \begin_inset Text
37200
37201 \begin_layout Standard
37202
37203 \size footnotesize
37204 '!'
37205 \end_layout
37206
37207 \end_inset
37208 </cell>
37209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37210 \begin_inset Text
37211
37212 \begin_layout Standard
37213
37214 \size footnotesize
37215 IC_LEFT() IC_RESULT()
37216 \end_layout
37217
37218 \end_inset
37219 </cell>
37220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37221 \begin_inset Text
37222
37223 \begin_layout Standard
37224
37225 \size footnotesize
37226 NOT operation 
37227 \end_layout
37228
37229 \end_inset
37230 </cell>
37231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37232 \begin_inset Text
37233
37234 \begin_layout Standard
37235
37236 \size footnotesize
37237 IC_RESULT = ! IC_LEFT;
37238 \end_layout
37239
37240 \end_inset
37241 </cell>
37242 </row>
37243 <row topline="true">
37244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37245 \begin_inset Text
37246
37247 \begin_layout Standard
37248
37249 \size footnotesize
37250 '~'
37251 \end_layout
37252
37253 \end_inset
37254 </cell>
37255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37256 \begin_inset Text
37257
37258 \begin_layout Standard
37259
37260 \size footnotesize
37261 IC_LEFT() IC_RESULT()
37262 \end_layout
37263
37264 \end_inset
37265 </cell>
37266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37267 \begin_inset Text
37268
37269 \begin_layout Standard
37270
37271 \size footnotesize
37272 Bitwise complement of 
37273 \end_layout
37274
37275 \end_inset
37276 </cell>
37277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37278 \begin_inset Text
37279
37280 \begin_layout Standard
37281
37282 \size footnotesize
37283 IC_RESULT = ~IC_LEFT;
37284 \end_layout
37285
37286 \end_inset
37287 </cell>
37288 </row>
37289 <row topline="true">
37290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37291 \begin_inset Text
37292
37293 \begin_layout Standard
37294
37295 \size footnotesize
37296 RRC
37297 \end_layout
37298
37299 \end_inset
37300 </cell>
37301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37302 \begin_inset Text
37303
37304 \begin_layout Standard
37305
37306 \size footnotesize
37307 IC_LEFT() IC_RESULT()
37308 \end_layout
37309
37310 \end_inset
37311 </cell>
37312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37313 \begin_inset Text
37314
37315 \begin_layout Standard
37316
37317 \size footnotesize
37318 Rotate right with carry
37319 \end_layout
37320
37321 \end_inset
37322 </cell>
37323 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37324 \begin_inset Text
37325
37326 \begin_layout Standard
37327
37328 \size footnotesize
37329 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
37330 \end_layout
37331
37332 \end_inset
37333 </cell>
37334 </row>
37335 <row topline="true">
37336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37337 \begin_inset Text
37338
37339 \begin_layout Standard
37340
37341 \size footnotesize
37342 RLC
37343 \end_layout
37344
37345 \end_inset
37346 </cell>
37347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37348 \begin_inset Text
37349
37350 \begin_layout Standard
37351
37352 \size footnotesize
37353 IC_LEFT() IC_RESULT()
37354 \end_layout
37355
37356 \end_inset
37357 </cell>
37358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37359 \begin_inset Text
37360
37361 \begin_layout Standard
37362
37363 \size footnotesize
37364 Rotate left with carry
37365 \end_layout
37366
37367 \end_inset
37368 </cell>
37369 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37370 \begin_inset Text
37371
37372 \begin_layout Standard
37373
37374 \size footnotesize
37375 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
37376 \end_layout
37377
37378 \end_inset
37379 </cell>
37380 </row>
37381 <row topline="true">
37382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37383 \begin_inset Text
37384
37385 \begin_layout Standard
37386
37387 \size footnotesize
37388 GETHBIT
37389 \end_layout
37390
37391 \end_inset
37392 </cell>
37393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37394 \begin_inset Text
37395
37396 \begin_layout Standard
37397
37398 \size footnotesize
37399 IC_LEFT() IC_RESULT()
37400 \end_layout
37401
37402 \end_inset
37403 </cell>
37404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37405 \begin_inset Text
37406
37407 \begin_layout Standard
37408
37409 \size footnotesize
37410 Get the highest order bit of IC_LEFT
37411 \end_layout
37412
37413 \end_inset
37414 </cell>
37415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37416 \begin_inset Text
37417
37418 \begin_layout Standard
37419
37420 \size footnotesize
37421 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
37422 \end_layout
37423
37424 \end_inset
37425 </cell>
37426 </row>
37427 <row topline="true">
37428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37429 \begin_inset Text
37430
37431 \begin_layout Standard
37432
37433 \size footnotesize
37434 UNARYMINUS
37435 \end_layout
37436
37437 \end_inset
37438 </cell>
37439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37440 \begin_inset Text
37441
37442 \begin_layout Standard
37443
37444 \size footnotesize
37445 IC_LEFT() IC_RESULT()
37446 \end_layout
37447
37448 \end_inset
37449 </cell>
37450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37451 \begin_inset Text
37452
37453 \begin_layout Standard
37454
37455 \size footnotesize
37456 Unary minus
37457 \end_layout
37458
37459 \end_inset
37460 </cell>
37461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37462 \begin_inset Text
37463
37464 \begin_layout Standard
37465
37466 \size footnotesize
37467 IC_RESULT = - IC_LEFT;
37468 \end_layout
37469
37470 \end_inset
37471 </cell>
37472 </row>
37473 <row topline="true">
37474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37475 \begin_inset Text
37476
37477 \begin_layout Standard
37478
37479 \size footnotesize
37480 IPUSH
37481 \end_layout
37482
37483 \end_inset
37484 </cell>
37485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37486 \begin_inset Text
37487
37488 \begin_layout Standard
37489
37490 \size footnotesize
37491 IC_LEFT()
37492 \end_layout
37493
37494 \end_inset
37495 </cell>
37496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37497 \begin_inset Text
37498
37499 \begin_layout Standard
37500
37501 \size footnotesize
37502 Push the operand into stack
37503 \end_layout
37504
37505 \end_inset
37506 </cell>
37507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37508 \begin_inset Text
37509
37510 \begin_layout Standard
37511
37512 \size footnotesize
37513 NONE
37514 \end_layout
37515
37516 \end_inset
37517 </cell>
37518 </row>
37519 <row topline="true">
37520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37521 \begin_inset Text
37522
37523 \begin_layout Standard
37524
37525 \size footnotesize
37526 IPOP
37527 \end_layout
37528
37529 \end_inset
37530 </cell>
37531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37532 \begin_inset Text
37533
37534 \begin_layout Standard
37535
37536 \size footnotesize
37537 IC_LEFT()
37538 \end_layout
37539
37540 \end_inset
37541 </cell>
37542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37543 \begin_inset Text
37544
37545 \begin_layout Standard
37546
37547 \size footnotesize
37548 Pop the operand from the stack 
37549 \end_layout
37550
37551 \end_inset
37552 </cell>
37553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37554 \begin_inset Text
37555
37556 \begin_layout Standard
37557
37558 \size footnotesize
37559 NONE
37560 \end_layout
37561
37562 \end_inset
37563 </cell>
37564 </row>
37565 <row topline="true">
37566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37567 \begin_inset Text
37568
37569 \begin_layout Standard
37570
37571 \size footnotesize
37572 CALL
37573 \end_layout
37574
37575 \end_inset
37576 </cell>
37577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37578 \begin_inset Text
37579
37580 \begin_layout Standard
37581
37582 \size footnotesize
37583 IC_LEFT() IC_RESULT()
37584 \end_layout
37585
37586 \end_inset
37587 </cell>
37588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37589 \begin_inset Text
37590
37591 \begin_layout Standard
37592
37593 \size footnotesize
37594 Call the function represented by IC_LEFT 
37595 \end_layout
37596
37597 \end_inset
37598 </cell>
37599 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37600 \begin_inset Text
37601
37602 \begin_layout Standard
37603
37604 \size footnotesize
37605 IC_RESULT = IC_LEFT();
37606 \end_layout
37607
37608 \end_inset
37609 </cell>
37610 </row>
37611 <row topline="true">
37612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37613 \begin_inset Text
37614
37615 \begin_layout Standard
37616
37617 \size footnotesize
37618 PCALL
37619 \end_layout
37620
37621 \end_inset
37622 </cell>
37623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37624 \begin_inset Text
37625
37626 \begin_layout Standard
37627
37628 \size footnotesize
37629 IC_LEFT() IC_RESULT()
37630 \end_layout
37631
37632 \end_inset
37633 </cell>
37634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37635 \begin_inset Text
37636
37637 \begin_layout Standard
37638
37639 \size footnotesize
37640 Call via function pointer
37641 \end_layout
37642
37643 \end_inset
37644 </cell>
37645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37646 \begin_inset Text
37647
37648 \begin_layout Standard
37649
37650 \size footnotesize
37651 IC_RESULT = (*IC_LEFT)();
37652 \end_layout
37653
37654 \end_inset
37655 </cell>
37656 </row>
37657 <row topline="true">
37658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37659 \begin_inset Text
37660
37661 \begin_layout Standard
37662
37663 \size footnotesize
37664 RETURN
37665 \end_layout
37666
37667 \end_inset
37668 </cell>
37669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37670 \begin_inset Text
37671
37672 \begin_layout Standard
37673
37674 \size footnotesize
37675 IC_LEFT()
37676 \end_layout
37677
37678 \end_inset
37679 </cell>
37680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37681 \begin_inset Text
37682
37683 \begin_layout Standard
37684
37685 \size footnotesize
37686 Return the value in operand IC_LEFT 
37687 \end_layout
37688
37689 \end_inset
37690 </cell>
37691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37692 \begin_inset Text
37693
37694 \begin_layout Standard
37695
37696 \size footnotesize
37697 return IC_LEFT;
37698 \end_layout
37699
37700 \end_inset
37701 </cell>
37702 </row>
37703 <row topline="true">
37704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37705 \begin_inset Text
37706
37707 \begin_layout Standard
37708
37709 \size footnotesize
37710 LABEL
37711 \end_layout
37712
37713 \end_inset
37714 </cell>
37715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37716 \begin_inset Text
37717
37718 \begin_layout Standard
37719
37720 \size footnotesize
37721 IC_LABEL() 
37722 \end_layout
37723
37724 \end_inset
37725 </cell>
37726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37727 \begin_inset Text
37728
37729 \begin_layout Standard
37730
37731 \size footnotesize
37732 Label
37733 \end_layout
37734
37735 \end_inset
37736 </cell>
37737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37738 \begin_inset Text
37739
37740 \begin_layout Standard
37741
37742 \size footnotesize
37743 IC_LABEL:
37744 \end_layout
37745
37746 \end_inset
37747 </cell>
37748 </row>
37749 <row topline="true">
37750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37751 \begin_inset Text
37752
37753 \begin_layout Standard
37754
37755 \size footnotesize
37756 GOTO
37757 \end_layout
37758
37759 \end_inset
37760 </cell>
37761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37762 \begin_inset Text
37763
37764 \begin_layout Standard
37765
37766 \size footnotesize
37767 IC_LABEL() 
37768 \end_layout
37769
37770 \end_inset
37771 </cell>
37772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37773 \begin_inset Text
37774
37775 \begin_layout Standard
37776
37777 \size footnotesize
37778 Goto label
37779 \end_layout
37780
37781 \end_inset
37782 </cell>
37783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37784 \begin_inset Text
37785
37786 \begin_layout Standard
37787
37788 \size footnotesize
37789 goto IC_LABEL();
37790 \end_layout
37791
37792 \end_inset
37793 </cell>
37794 </row>
37795 <row topline="true">
37796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37797 \begin_inset Text
37798
37799 \begin_layout Standard
37800
37801 \size footnotesize
37802 '+'
37803 \end_layout
37804
37805 \end_inset
37806 </cell>
37807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37808 \begin_inset Text
37809
37810 \begin_layout Standard
37811
37812 \size footnotesize
37813 IC_LEFT() IC_RIGHT() IC_RESULT()
37814 \end_layout
37815
37816 \end_inset
37817 </cell>
37818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37819 \begin_inset Text
37820
37821 \begin_layout Standard
37822
37823 \size footnotesize
37824 Addition
37825 \end_layout
37826
37827 \end_inset
37828 </cell>
37829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37830 \begin_inset Text
37831
37832 \begin_layout Standard
37833
37834 \size footnotesize
37835 IC_RESULT = IC_LEFT + IC_RIGHT
37836 \end_layout
37837
37838 \end_inset
37839 </cell>
37840 </row>
37841 <row topline="true">
37842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37843 \begin_inset Text
37844
37845 \begin_layout Standard
37846
37847 \size footnotesize
37848 '-'
37849 \end_layout
37850
37851 \end_inset
37852 </cell>
37853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37854 \begin_inset Text
37855
37856 \begin_layout Standard
37857
37858 \size footnotesize
37859 IC_LEFT() IC_RIGHT() IC_RESULT()
37860 \end_layout
37861
37862 \end_inset
37863 </cell>
37864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37865 \begin_inset Text
37866
37867 \begin_layout Standard
37868
37869 \size footnotesize
37870 Subtraction
37871 \end_layout
37872
37873 \end_inset
37874 </cell>
37875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37876 \begin_inset Text
37877
37878 \begin_layout Standard
37879
37880 \size footnotesize
37881 IC_RESULT = IC_LEFT - IC_RIGHT 
37882 \end_layout
37883
37884 \end_inset
37885 </cell>
37886 </row>
37887 <row topline="true">
37888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37889 \begin_inset Text
37890
37891 \begin_layout Standard
37892
37893 \size footnotesize
37894 '*'
37895 \end_layout
37896
37897 \end_inset
37898 </cell>
37899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37900 \begin_inset Text
37901
37902 \begin_layout Standard
37903
37904 \size footnotesize
37905 IC_LEFT() IC_RIGHT() IC_RESULT()
37906 \end_layout
37907
37908 \end_inset
37909 </cell>
37910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37911 \begin_inset Text
37912
37913 \begin_layout Standard
37914
37915 \size footnotesize
37916 Multiplication 
37917 \end_layout
37918
37919 \end_inset
37920 </cell>
37921 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37922 \begin_inset Text
37923
37924 \begin_layout Standard
37925
37926 \size footnotesize
37927 IC_RESULT = IC_LEFT * IC_RIGHT;
37928 \end_layout
37929
37930 \end_inset
37931 </cell>
37932 </row>
37933 <row topline="true">
37934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37935 \begin_inset Text
37936
37937 \begin_layout Standard
37938
37939 \size footnotesize
37940 '/'
37941 \end_layout
37942
37943 \end_inset
37944 </cell>
37945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37946 \begin_inset Text
37947
37948 \begin_layout Standard
37949
37950 \size footnotesize
37951 IC_LEFT() IC_RIGHT() IC_RESULT()
37952 \end_layout
37953
37954 \end_inset
37955 </cell>
37956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37957 \begin_inset Text
37958
37959 \begin_layout Standard
37960
37961 \size footnotesize
37962 Division
37963 \end_layout
37964
37965 \end_inset
37966 </cell>
37967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37968 \begin_inset Text
37969
37970 \begin_layout Standard
37971
37972 \size footnotesize
37973 IC_RESULT = IC_LEFT / IC_RIGHT;
37974 \end_layout
37975
37976 \end_inset
37977 </cell>
37978 </row>
37979 <row topline="true">
37980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37981 \begin_inset Text
37982
37983 \begin_layout Standard
37984
37985 \size footnotesize
37986 '%'
37987 \end_layout
37988
37989 \end_inset
37990 </cell>
37991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37992 \begin_inset Text
37993
37994 \begin_layout Standard
37995
37996 \size footnotesize
37997 IC_LEFT() IC_RIGHT() IC_RESULT()
37998 \end_layout
37999
38000 \end_inset
38001 </cell>
38002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38003 \begin_inset Text
38004
38005 \begin_layout Standard
38006
38007 \size footnotesize
38008 Modulus
38009 \end_layout
38010
38011 \end_inset
38012 </cell>
38013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38014 \begin_inset Text
38015
38016 \begin_layout Standard
38017
38018 \size footnotesize
38019 IC_RESULT = IC_LEFT % IC_RIGHT;
38020 \end_layout
38021
38022 \end_inset
38023 </cell>
38024 </row>
38025 <row topline="true">
38026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38027 \begin_inset Text
38028
38029 \begin_layout Standard
38030
38031 \size footnotesize
38032 '<'
38033 \end_layout
38034
38035 \end_inset
38036 </cell>
38037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38038 \begin_inset Text
38039
38040 \begin_layout Standard
38041
38042 \size footnotesize
38043 IC_LEFT() IC_RIGHT() IC_RESULT()
38044 \end_layout
38045
38046 \end_inset
38047 </cell>
38048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38049 \begin_inset Text
38050
38051 \begin_layout Standard
38052
38053 \size footnotesize
38054 Less than
38055 \end_layout
38056
38057 \end_inset
38058 </cell>
38059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38060 \begin_inset Text
38061
38062 \begin_layout Standard
38063
38064 \size footnotesize
38065 IC_RESULT = IC_LEFT < IC_RIGHT;
38066 \end_layout
38067
38068 \end_inset
38069 </cell>
38070 </row>
38071 <row topline="true">
38072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38073 \begin_inset Text
38074
38075 \begin_layout Standard
38076
38077 \size footnotesize
38078 '>'
38079 \end_layout
38080
38081 \end_inset
38082 </cell>
38083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38084 \begin_inset Text
38085
38086 \begin_layout Standard
38087
38088 \size footnotesize
38089 IC_LEFT() IC_RIGHT() IC_RESULT()
38090 \end_layout
38091
38092 \end_inset
38093 </cell>
38094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38095 \begin_inset Text
38096
38097 \begin_layout Standard
38098
38099 \size footnotesize
38100 Greater than 
38101 \end_layout
38102
38103 \end_inset
38104 </cell>
38105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38106 \begin_inset Text
38107
38108 \begin_layout Standard
38109
38110 \size footnotesize
38111 IC_RESULT = IC_LEFT > IC_RIGHT;
38112 \end_layout
38113
38114 \end_inset
38115 </cell>
38116 </row>
38117 <row topline="true">
38118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38119 \begin_inset Text
38120
38121 \begin_layout Standard
38122
38123 \size footnotesize
38124 EQ_OP
38125 \end_layout
38126
38127 \end_inset
38128 </cell>
38129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38130 \begin_inset Text
38131
38132 \begin_layout Standard
38133
38134 \size footnotesize
38135 IC_LEFT() IC_RIGHT() IC_RESULT()
38136 \end_layout
38137
38138 \end_inset
38139 </cell>
38140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38141 \begin_inset Text
38142
38143 \begin_layout Standard
38144
38145 \size footnotesize
38146 Equal to 
38147 \end_layout
38148
38149 \end_inset
38150 </cell>
38151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38152 \begin_inset Text
38153
38154 \begin_layout Standard
38155
38156 \size footnotesize
38157 IC_RESULT = IC_LEFT == IC_RIGHT;
38158 \end_layout
38159
38160 \end_inset
38161 </cell>
38162 </row>
38163 <row topline="true">
38164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38165 \begin_inset Text
38166
38167 \begin_layout Standard
38168
38169 \size footnotesize
38170 AND_OP
38171 \end_layout
38172
38173 \end_inset
38174 </cell>
38175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38176 \begin_inset Text
38177
38178 \begin_layout Standard
38179
38180 \size footnotesize
38181 IC_LEFT() IC_RIGHT() IC_RESULT() 
38182 \end_layout
38183
38184 \end_inset
38185 </cell>
38186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38187 \begin_inset Text
38188
38189 \begin_layout Standard
38190
38191 \size footnotesize
38192 Logical and operation
38193 \end_layout
38194
38195 \end_inset
38196 </cell>
38197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38198 \begin_inset Text
38199
38200 \begin_layout Standard
38201
38202 \size footnotesize
38203 IC_RESULT = IC_LEFT && IC_RIGHT; 
38204 \end_layout
38205
38206 \end_inset
38207 </cell>
38208 </row>
38209 <row topline="true">
38210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38211 \begin_inset Text
38212
38213 \begin_layout Standard
38214
38215 \size footnotesize
38216 OR_OP
38217 \end_layout
38218
38219 \end_inset
38220 </cell>
38221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38222 \begin_inset Text
38223
38224 \begin_layout Standard
38225
38226 \size footnotesize
38227 IC_LEFT() IC_RIGHT() IC_RESULT() 
38228 \end_layout
38229
38230 \end_inset
38231 </cell>
38232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38233 \begin_inset Text
38234
38235 \begin_layout Standard
38236
38237 \size footnotesize
38238 Logical or operation 
38239 \end_layout
38240
38241 \end_inset
38242 </cell>
38243 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38244 \begin_inset Text
38245
38246 \begin_layout Standard
38247
38248 \size footnotesize
38249 IC_RESULT = IC_LEFT || IC_RIGHT; 
38250 \end_layout
38251
38252 \end_inset
38253 </cell>
38254 </row>
38255 <row topline="true">
38256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38257 \begin_inset Text
38258
38259 \begin_layout Standard
38260
38261 \size footnotesize
38262 '^'
38263 \end_layout
38264
38265 \end_inset
38266 </cell>
38267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38268 \begin_inset Text
38269
38270 \begin_layout Standard
38271
38272 \size footnotesize
38273 IC_LEFT() IC_RIGHT() IC_RESULT() 
38274 \end_layout
38275
38276 \end_inset
38277 </cell>
38278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38279 \begin_inset Text
38280
38281 \begin_layout Standard
38282
38283 \size footnotesize
38284 Exclusive OR
38285 \end_layout
38286
38287 \end_inset
38288 </cell>
38289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38290 \begin_inset Text
38291
38292 \begin_layout Standard
38293
38294 \size footnotesize
38295 IC_RESULT = IC_LEFT ^ IC_RIGHT;
38296 \end_layout
38297
38298 \end_inset
38299 </cell>
38300 </row>
38301 <row topline="true">
38302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38303 \begin_inset Text
38304
38305 \begin_layout Standard
38306
38307 \size footnotesize
38308 '|'
38309 \end_layout
38310
38311 \end_inset
38312 </cell>
38313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38314 \begin_inset Text
38315
38316 \begin_layout Standard
38317
38318 \size footnotesize
38319 IC_LEFT() IC_RIGHT() IC_RESULT() 
38320 \end_layout
38321
38322 \end_inset
38323 </cell>
38324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38325 \begin_inset Text
38326
38327 \begin_layout Standard
38328
38329 \size footnotesize
38330 Bitwise OR 
38331 \end_layout
38332
38333 \end_inset
38334 </cell>
38335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38336 \begin_inset Text
38337
38338 \begin_layout Standard
38339
38340 \size footnotesize
38341 IC_RESULT = IC_LEFT | IC_RIGHT;
38342 \end_layout
38343
38344 \end_inset
38345 </cell>
38346 </row>
38347 <row topline="true">
38348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38349 \begin_inset Text
38350
38351 \begin_layout Standard
38352
38353 \size footnotesize
38354 BITWISEAND
38355 \end_layout
38356
38357 \end_inset
38358 </cell>
38359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38360 \begin_inset Text
38361
38362 \begin_layout Standard
38363
38364 \size footnotesize
38365 IC_LEFT() IC_RIGHT() IC_RESULT()
38366 \end_layout
38367
38368 \end_inset
38369 </cell>
38370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38371 \begin_inset Text
38372
38373 \begin_layout Standard
38374
38375 \size footnotesize
38376 Bitwise AND 
38377 \end_layout
38378
38379 \end_inset
38380 </cell>
38381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38382 \begin_inset Text
38383
38384 \begin_layout Standard
38385
38386 \size footnotesize
38387 IC_RESULT = IC_LEFT & IC_RIGHT;
38388 \end_layout
38389
38390 \end_inset
38391 </cell>
38392 </row>
38393 <row topline="true">
38394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38395 \begin_inset Text
38396
38397 \begin_layout Standard
38398
38399 \size footnotesize
38400 LEFT_OP
38401 \end_layout
38402
38403 \end_inset
38404 </cell>
38405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38406 \begin_inset Text
38407
38408 \begin_layout Standard
38409
38410 \size footnotesize
38411 IC_LEFT() IC_RIGHT() IC_RESULT()
38412 \end_layout
38413
38414 \end_inset
38415 </cell>
38416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38417 \begin_inset Text
38418
38419 \begin_layout Standard
38420
38421 \size footnotesize
38422 Left shift 
38423 \end_layout
38424
38425 \end_inset
38426 </cell>
38427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38428 \begin_inset Text
38429
38430 \begin_layout Standard
38431
38432 \size footnotesize
38433 IC_RESULT = IC_LEFT << IC_RIGHT 
38434 \end_layout
38435
38436 \end_inset
38437 </cell>
38438 </row>
38439 <row topline="true">
38440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38441 \begin_inset Text
38442
38443 \begin_layout Standard
38444
38445 \size footnotesize
38446 RIGHT_OP
38447 \end_layout
38448
38449 \end_inset
38450 </cell>
38451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38452 \begin_inset Text
38453
38454 \begin_layout Standard
38455
38456 \size footnotesize
38457 IC_LEFT() IC_RIGHT() IC_RESULT()
38458 \end_layout
38459
38460 \end_inset
38461 </cell>
38462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38463 \begin_inset Text
38464
38465 \begin_layout Standard
38466
38467 \size footnotesize
38468 Right shift
38469 \end_layout
38470
38471 \end_inset
38472 </cell>
38473 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38474 \begin_inset Text
38475
38476 \begin_layout Standard
38477
38478 \size footnotesize
38479 IC_RESULT = IC_LEFT >> IC_RIGHT 
38480 \end_layout
38481
38482 \end_inset
38483 </cell>
38484 </row>
38485 <row topline="true">
38486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38487 \begin_inset Text
38488
38489 \begin_layout Standard
38490
38491 \size footnotesize
38492 GET_VALUE_
38493 \newline
38494 AT_ ADDRESS
38495 \end_layout
38496
38497 \end_inset
38498 </cell>
38499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38500 \begin_inset Text
38501
38502 \begin_layout Standard
38503
38504 \size footnotesize
38505 IC_LEFT() IC_RESULT()
38506 \end_layout
38507
38508 \end_inset
38509 </cell>
38510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38511 \begin_inset Text
38512
38513 \begin_layout Standard
38514
38515 \size footnotesize
38516 Indirect fetch 
38517 \end_layout
38518
38519 \end_inset
38520 </cell>
38521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38522 \begin_inset Text
38523
38524 \begin_layout Standard
38525
38526 \size footnotesize
38527 IC_RESULT = (*IC_LEFT);
38528 \end_layout
38529
38530 \end_inset
38531 </cell>
38532 </row>
38533 <row topline="true">
38534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38535 \begin_inset Text
38536
38537 \begin_layout Standard
38538
38539 \size footnotesize
38540 POINTER_SET
38541 \end_layout
38542
38543 \end_inset
38544 </cell>
38545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38546 \begin_inset Text
38547
38548 \begin_layout Standard
38549
38550 \size footnotesize
38551 IC_RIGHT() IC_RESULT() 
38552 \end_layout
38553
38554 \end_inset
38555 </cell>
38556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38557 \begin_inset Text
38558
38559 \begin_layout Standard
38560
38561 \size footnotesize
38562 Indirect set
38563 \end_layout
38564
38565 \end_inset
38566 </cell>
38567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38568 \begin_inset Text
38569
38570 \begin_layout Standard
38571
38572 \size footnotesize
38573 (*IC_RESULT) = IC_RIGHT;
38574 \end_layout
38575
38576 \end_inset
38577 </cell>
38578 </row>
38579 <row topline="true">
38580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38581 \begin_inset Text
38582
38583 \begin_layout Standard
38584
38585 \size footnotesize
38586 '='
38587 \end_layout
38588
38589 \end_inset
38590 </cell>
38591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38592 \begin_inset Text
38593
38594 \begin_layout Standard
38595
38596 \size footnotesize
38597 IC_RIGHT() IC_RESULT()
38598 \end_layout
38599
38600 \end_inset
38601 </cell>
38602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38603 \begin_inset Text
38604
38605 \begin_layout Standard
38606
38607 \size footnotesize
38608 Assignment
38609 \end_layout
38610
38611 \end_inset
38612 </cell>
38613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38614 \begin_inset Text
38615
38616 \begin_layout Standard
38617
38618 \size footnotesize
38619 IC_RESULT = IC_RIGHT;
38620 \end_layout
38621
38622 \end_inset
38623 </cell>
38624 </row>
38625 <row topline="true">
38626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38627 \begin_inset Text
38628
38629 \begin_layout Standard
38630
38631 \size footnotesize
38632 IFX
38633 \end_layout
38634
38635 \end_inset
38636 </cell>
38637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38638 \begin_inset Text
38639
38640 \begin_layout Standard
38641
38642 \size footnotesize
38643 IC_COND IC_TRUE IC_LABEL
38644 \end_layout
38645
38646 \end_inset
38647 </cell>
38648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38649 \begin_inset Text
38650
38651 \begin_layout Standard
38652
38653 \size footnotesize
38654 Conditional jump.
38655  If true label is present then jump to true label if condition is true else
38656  jump to false label if condition is false 
38657 \end_layout
38658
38659 \end_inset
38660 </cell>
38661 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38662 \begin_inset Text
38663
38664 \begin_layout Standard
38665
38666 \size footnotesize
38667 if (IC_COND) goto IC_TRUE; 
38668 \newline
38669 \InsetSpace ~
38670 \InsetSpace ~
38671 Or 
38672 \newline
38673 If (!IC_COND) goto IC_FALSE;
38674 \end_layout
38675
38676 \end_inset
38677 </cell>
38678 </row>
38679 <row topline="true">
38680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38681 \begin_inset Text
38682
38683 \begin_layout Standard
38684
38685 \size footnotesize
38686 ADDRESS_OF
38687 \end_layout
38688
38689 \end_inset
38690 </cell>
38691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38692 \begin_inset Text
38693
38694 \begin_layout Standard
38695
38696 \size footnotesize
38697 IC_LEFT() IC_RESULT()
38698 \end_layout
38699
38700 \end_inset
38701 </cell>
38702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38703 \begin_inset Text
38704
38705 \begin_layout Standard
38706
38707 \size footnotesize
38708 Address of 
38709 \end_layout
38710
38711 \end_inset
38712 </cell>
38713 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38714 \begin_inset Text
38715
38716 \begin_layout Standard
38717
38718 \size footnotesize
38719 IC_RESULT = &IC_LEFT();
38720 \end_layout
38721
38722 \end_inset
38723 </cell>
38724 </row>
38725 <row topline="true">
38726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38727 \begin_inset Text
38728
38729 \begin_layout Standard
38730
38731 \size footnotesize
38732 JUMPTABLE
38733 \end_layout
38734
38735 \end_inset
38736 </cell>
38737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38738 \begin_inset Text
38739
38740 \begin_layout Standard
38741
38742 \size footnotesize
38743 IC_JTCOND IC_JTLABELS
38744 \end_layout
38745
38746 \end_inset
38747 </cell>
38748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38749 \begin_inset Text
38750
38751 \begin_layout Standard
38752
38753 \size footnotesize
38754 Jump to list of labels depending on the value of JTCOND
38755 \end_layout
38756
38757 \end_inset
38758 </cell>
38759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38760 \begin_inset Text
38761
38762 \begin_layout Standard
38763
38764 \size footnotesize
38765 Switch statement
38766 \end_layout
38767
38768 \end_inset
38769 </cell>
38770 </row>
38771 <row topline="true">
38772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38773 \begin_inset Text
38774
38775 \begin_layout Standard
38776
38777 \size footnotesize
38778 CAST
38779 \end_layout
38780
38781 \end_inset
38782 </cell>
38783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38784 \begin_inset Text
38785
38786 \begin_layout Standard
38787
38788 \size footnotesize
38789 IC_RIGHT() IC_LEFT() IC_RESULT()
38790 \end_layout
38791
38792 \end_inset
38793 </cell>
38794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38795 \begin_inset Text
38796
38797 \begin_layout Standard
38798
38799 \size footnotesize
38800 Cast types 
38801 \end_layout
38802
38803 \end_inset
38804 </cell>
38805 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38806 \begin_inset Text
38807
38808 \begin_layout Standard
38809
38810 \size footnotesize
38811 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
38812 \end_layout
38813
38814 \end_inset
38815 </cell>
38816 </row>
38817 <row topline="true">
38818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38819 \begin_inset Text
38820
38821 \begin_layout Standard
38822
38823 \size footnotesize
38824 SEND
38825 \end_layout
38826
38827 \end_inset
38828 </cell>
38829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38830 \begin_inset Text
38831
38832 \begin_layout Standard
38833
38834 \size footnotesize
38835 IC_LEFT()
38836 \end_layout
38837
38838 \end_inset
38839 </cell>
38840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38841 \begin_inset Text
38842
38843 \begin_layout Standard
38844
38845 \size footnotesize
38846 This is used for passing parameters in registers; 
38847 \newline
38848 move IC_LEFT to the next
38849  available parameter register.
38850 \end_layout
38851
38852 \end_inset
38853 </cell>
38854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38855 \begin_inset Text
38856
38857 \begin_layout Standard
38858
38859 \size footnotesize
38860 None
38861 \end_layout
38862
38863 \end_inset
38864 </cell>
38865 </row>
38866 <row topline="true">
38867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38868 \begin_inset Text
38869
38870 \begin_layout Standard
38871
38872 \size footnotesize
38873 RECV
38874 \end_layout
38875
38876 \end_inset
38877 </cell>
38878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38879 \begin_inset Text
38880
38881 \begin_layout Standard
38882
38883 \size footnotesize
38884 IC_RESULT()
38885 \end_layout
38886
38887 \end_inset
38888 </cell>
38889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38890 \begin_inset Text
38891
38892 \begin_layout Standard
38893
38894 \size footnotesize
38895 This is used for receiving parameters passed in registers;
38896 \newline
38897 Move the values
38898  in the next parameter register to IC_RESULT 
38899 \end_layout
38900
38901 \end_inset
38902 </cell>
38903 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38904 \begin_inset Text
38905
38906 \begin_layout Standard
38907
38908 \size footnotesize
38909 None
38910 \end_layout
38911
38912 \end_inset
38913 </cell>
38914 </row>
38915 <row topline="true" bottomline="true">
38916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38917 \begin_inset Text
38918
38919 \begin_layout Standard
38920
38921 \shape slanted
38922 \size footnotesize
38923 (some more have been added)
38924 \end_layout
38925
38926 \end_inset
38927 </cell>
38928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38929 \begin_inset Text
38930
38931 \begin_layout Standard
38932
38933 \end_layout
38934
38935 \end_inset
38936 </cell>
38937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38938 \begin_inset Text
38939
38940 \begin_layout Standard
38941
38942 \end_layout
38943
38944 \end_inset
38945 </cell>
38946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38947 \begin_inset Text
38948
38949 \begin_layout Standard
38950
38951 \shape slanted
38952 \size footnotesize
38953 see f.e.
38954  
38955 \family typewriter
38956 gen51Code()
38957 \family default
38958  in 
38959 \family typewriter
38960 src/mcs51/gen.c
38961 \end_layout
38962
38963 \end_inset
38964 </cell>
38965 </row>
38966 </lyxtabular>
38967
38968 \end_inset
38969
38970
38971 \end_layout
38972
38973 \begin_layout Standard
38974 \begin_inset Note Note
38975 status collapsed
38976
38977 \begin_layout Standard
38978 In the original article Figure II was announced to be downloadable on 
38979 \shape italic
38980 Circuit Cellar
38981 \shape default
38982 's web site.
38983  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
38984 \end_layout
38985
38986 \end_inset
38987
38988
38989 \end_layout
38990
38991 \begin_layout Paragraph*
38992 ICode Example
38993 \begin_inset LatexCommand \index{iCode}
38994
38995 \end_inset
38996
38997
38998 \end_layout
38999
39000 \begin_layout Standard
39001 This section shows some details of iCode.
39002  The example C code does not do anything useful; it is used as an example
39003  to illustrate the intermediate code generated by the compiler.
39004 \end_layout
39005
39006 \begin_layout Verse
39007
39008 \family typewriter
39009 1.\InsetSpace ~
39010 xdata int * p;
39011 \newline
39012 2.\InsetSpace ~
39013 int gint;
39014 \newline
39015 3.\InsetSpace ~
39016 /* This function does nothing useful.
39017  It is used
39018 \newline
39019 4.\InsetSpace ~
39020 \InsetSpace ~
39021 \InsetSpace ~
39022 \InsetSpace ~
39023 for the purpose of explaining iCode */
39024 \newline
39025 5.\InsetSpace ~
39026 short function (data
39027  int *x)
39028 \newline
39029 6.\InsetSpace ~
39030 {
39031 \newline
39032 7.\InsetSpace ~
39033 \InsetSpace ~
39034 \InsetSpace ~
39035 short i=10; \InsetSpace ~
39036 \InsetSpace ~
39037 /* dead initialization eliminated */
39038 \newline
39039 8.\InsetSpace ~
39040 \InsetSpace ~
39041 \InsetSpace ~
39042 short sum=10;
39043  /* dead initialization eliminated */
39044 \newline
39045 9.\InsetSpace ~
39046 \InsetSpace ~
39047 \InsetSpace ~
39048 short mul;
39049 \newline
39050 10.\InsetSpace ~
39051 \InsetSpace ~
39052 int j ;
39053 \newline
39054 11.\InsetSpace ~
39055 \InsetSpace ~
39056 while (*x) *x++
39057  = *p++; 
39058 \newline
39059 12.\InsetSpace ~
39060 \InsetSpace ~
39061 \InsetSpace ~
39062 \InsetSpace ~
39063 sum = 0 ; 
39064 \newline
39065 13.\InsetSpace ~
39066 \InsetSpace ~
39067 mul = 0;
39068 \newline
39069 14.\InsetSpace ~
39070 \InsetSpace ~
39071 /* compiler detects i,j to be induction
39072  variables */
39073 \newline
39074 15.\InsetSpace ~
39075 \InsetSpace ~
39076 for (i = 0, j = 10 ; i < 10 ; i++, j
39077 \family default
39078 -
39079 \begin_inset ERT
39080 status collapsed
39081
39082 \begin_layout Standard
39083
39084
39085 \backslash
39086 /
39087 \end_layout
39088
39089 \end_inset
39090
39091 -
39092 \family typewriter
39093 ) {
39094 \newline
39095 16.\InsetSpace ~
39096 \InsetSpace ~
39097 \InsetSpace ~
39098 \InsetSpace ~
39099 sum += i;
39100 \newline
39101 17.\InsetSpace ~
39102 \InsetSpace ~
39103 \InsetSpace ~
39104 \InsetSpace ~
39105 mul += i * 3; \InsetSpace ~
39106 \InsetSpace ~
39107 /* this multiplication remains */
39108 \newline
39109 18.\InsetSpace ~
39110 \InsetSpace ~
39111 \InsetSpace ~
39112 \InsetSpace ~
39113 gint +=
39114  j * 3;\InsetSpace ~
39115 \InsetSpace ~
39116 /* this multiplication changed to addition */
39117 \newline
39118 19.\InsetSpace ~
39119 \InsetSpace ~
39120 }
39121 \newline
39122 20.\InsetSpace ~
39123 \InsetSpace ~
39124 return sum+mul;
39125 \newline
39126 21.\InsetSpace ~
39127 }
39128 \end_layout
39129
39130 \begin_layout Standard
39131 In addition to the operands each iCode contains information about the filename
39132  and line it corresponds to in the source file.
39133  The first field in the listing should be interpreted as follows:
39134 \newline
39135
39136 \shape italic
39137 \size footnotesize
39138 Filename(linenumber: iCode Execution sequence number : ICode hash table
39139  key : loop depth of the iCode).
39140 \shape default
39141 \size default
39142
39143 \newline
39144 Then follows the human readable form of the ICode operation.
39145  Each operand of this triplet form can be of three basic types a) compiler
39146  generated temporary b) user defined variable c) a constant value.
39147  Note that local variables and parameters are replaced by compiler generated
39148  temporaries.
39149  Live ranges
39150 \begin_inset LatexCommand \index{Live range analysis}
39151
39152 \end_inset
39153
39154  are computed only for temporaries (i.e.
39155  live ranges are not computed for global variables).
39156  Registers
39157 \begin_inset LatexCommand \index{Register allocation}
39158
39159 \end_inset
39160
39161  are allocated for temporaries only.
39162  Operands are formatted in the following manner:
39163 \newline
39164
39165 \shape italic
39166 \size footnotesize
39167 Operand Name [lr live-from : live-to ] { type information } [ registers
39168  allocated ].
39169 \shape default
39170 \size default
39171
39172 \newline
39173 As mentioned earlier the live ranges are computed in terms of the execution
39174  sequence number of the iCodes, for example 
39175 \newline
39176 the iTemp0 is live from (i.e.
39177  first defined in iCode with execution sequence number 3, and is last used
39178  in the iCode with sequence number 5).
39179  For induction variables such as iTemp21 the live range computation extends
39180  the lifetime from the start to the end of the loop.
39181 \newline
39182 The register allocator
39183  used the live range information to allocate registers, the same registers
39184  may be used for different temporaries if their live ranges do not overlap,
39185  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
39186  ranges do not overlap.
39187  In addition the allocator also takes into consideration the type and usage
39188  of a temporary, for example itemp6 is a pointer to near space and is used
39189  as to fetch data from (i.e.
39190  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
39191  Some short lived temporaries are allocated to special registers which have
39192  meaning to the code generator e.g.
39193  iTemp13 is allocated to a pseudo register CC which tells the back end that
39194  the temporary is used only for a conditional jump the code generation makes
39195  use of this information to optimize a compare and jump ICode.
39196 \newline
39197 There are several
39198  loop optimizations
39199 \begin_inset LatexCommand \index{Loop optimization}
39200
39201 \end_inset
39202
39203  performed by the compiler.
39204  It can detect induction variables iTemp21(i) and iTemp23(j).
39205  Also note the compiler does selective strength reduction
39206 \begin_inset LatexCommand \index{Strength reduction}
39207
39208 \end_inset
39209
39210 , i.e.
39211  the multiplication of an induction variable in line 18 (gint = j * 3) is
39212  changed to addition, a new temporary iTemp17 is allocated and assigned
39213  a initial value, a constant 3 is then added for each iteration of the loop.
39214  The compiler does not change the multiplication
39215 \begin_inset LatexCommand \index{Multiplication}
39216
39217 \end_inset
39218
39219  in line 17 however since the processor does support an 8 * 8 bit multiplication.
39220 \newline
39221
39222 Note the dead code elimination
39223 \begin_inset LatexCommand \index{Dead-code elimination}
39224
39225 \end_inset
39226
39227  optimization eliminated the dead assignments in line 7 & 8 to I and sum
39228  respectively.
39229 \newline
39230
39231 \end_layout
39232
39233 \begin_layout Standard
39234
39235 \size footnotesize
39236 Sample.c (5:1:0:0) _entry($9) :
39237 \end_layout
39238
39239 \begin_layout Standard
39240
39241 \size footnotesize
39242 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
39243 \end_layout
39244
39245 \begin_layout Standard
39246
39247 \size footnotesize
39248 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
39249 \end_layout
39250
39251 \begin_layout Standard
39252
39253 \size footnotesize
39254 Sample.c(11:4:53:0) preHeaderLbl0($11) :
39255 \end_layout
39256
39257 \begin_layout Standard
39258
39259 \size footnotesize
39260 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
39261  * int}[r2]
39262 \end_layout
39263
39264 \begin_layout Standard
39265
39266 \size footnotesize
39267 Sample.c(11:6:5:1) _whilecontinue_0($1) :
39268 \end_layout
39269
39270 \begin_layout Standard
39271
39272 \size footnotesize
39273 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
39274  int}[r0]]
39275 \end_layout
39276
39277 \begin_layout Standard
39278
39279 \size footnotesize
39280 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39281 \end_layout
39282
39283 \begin_layout Standard
39284
39285 \size footnotesize
39286 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
39287  * int}
39288 \end_layout
39289
39290 \begin_layout Standard
39291
39292 \size footnotesize
39293 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
39294  {short}
39295 \end_layout
39296
39297 \begin_layout Standard
39298
39299 \size footnotesize
39300 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
39301  * int}[DPTR]]
39302 \end_layout
39303
39304 \begin_layout Standard
39305
39306 \size footnotesize
39307 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
39308 }[r2 r3]
39309 \end_layout
39310
39311 \begin_layout Standard
39312
39313 \size footnotesize
39314 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
39315  * int}[r0] + 0x2 {short}
39316 \end_layout
39317
39318 \begin_layout Standard
39319
39320 \size footnotesize
39321 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
39322 \end_layout
39323
39324 \begin_layout Standard
39325
39326 \size footnotesize
39327 Sample.c(11:17:21:0)_whilebreak_0($3) :
39328 \end_layout
39329
39330 \begin_layout Standard
39331
39332 \size footnotesize
39333 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39334 \end_layout
39335
39336 \begin_layout Standard
39337
39338 \size footnotesize
39339 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39340 \end_layout
39341
39342 \begin_layout Standard
39343
39344 \size footnotesize
39345 Sample.c(15:20:54:0)preHeaderLbl1($13) :
39346 \end_layout
39347
39348 \begin_layout Standard
39349
39350 \size footnotesize
39351 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39352 \end_layout
39353
39354 \begin_layout Standard
39355
39356 \size footnotesize
39357 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39358 \end_layout
39359
39360 \begin_layout Standard
39361
39362 \size footnotesize
39363 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39364 \end_layout
39365
39366 \begin_layout Standard
39367
39368 \size footnotesize
39369 Sample.c(15:24:26:1)_forcond_0($4) :
39370 \end_layout
39371
39372 \begin_layout Standard
39373
39374 \size footnotesize
39375 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
39376  < 0xa {short}
39377 \end_layout
39378
39379 \begin_layout Standard
39380
39381 \size footnotesize
39382 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39383 \end_layout
39384
39385 \begin_layout Standard
39386
39387 \size footnotesize
39388 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
39389  + ITemp21 [lr21:38]{short}[r4]
39390 \end_layout
39391
39392 \begin_layout Standard
39393
39394 \size footnotesize
39395 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
39396  * 0x3 {short}
39397 \end_layout
39398
39399 \begin_layout Standard
39400
39401 \size footnotesize
39402 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
39403  + iTemp15 [lr29:30]{short}[r1]
39404 \end_layout
39405
39406 \begin_layout Standard
39407
39408 \size footnotesize
39409 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
39410  r0]- 0x3 {short}
39411 \end_layout
39412
39413 \begin_layout Standard
39414
39415 \size footnotesize
39416 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
39417 int}[r7 r0]
39418 \end_layout
39419
39420 \begin_layout Standard
39421
39422 \size footnotesize
39423 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
39424  + 0x1 {short}
39425 \end_layout
39426
39427 \begin_layout Standard
39428
39429 \size footnotesize
39430 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
39431  r6]- 0x1 {short}
39432 \end_layout
39433
39434 \begin_layout Standard
39435
39436 \size footnotesize
39437 Sample.c(19:38:47:1) goto _forcond_0($4)
39438 \end_layout
39439
39440 \begin_layout Standard
39441
39442 \size footnotesize
39443 Sample.c(19:39:48:0)_forbreak_0($7) :
39444 \end_layout
39445
39446 \begin_layout Standard
39447
39448 \size footnotesize
39449 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
39450  + ITemp11 [lr19:40]{short}[r3]
39451 \end_layout
39452
39453 \begin_layout Standard
39454
39455 \size footnotesize
39456 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
39457 \end_layout
39458
39459 \begin_layout Standard
39460
39461 \size footnotesize
39462 Sample.c(20:42:51:0)_return($8) :
39463 \end_layout
39464
39465 \begin_layout Standard
39466
39467 \size footnotesize
39468 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
39469 \size default
39470
39471 \newline
39472
39473 \newline
39474 Finally the code generated for this function:
39475 \newline
39476
39477 \end_layout
39478
39479 \begin_layout Standard
39480
39481 \size footnotesize
39482 .area DSEG (DATA)
39483 \end_layout
39484
39485 \begin_layout Standard
39486
39487 \size footnotesize
39488 _p::
39489 \end_layout
39490
39491 \begin_layout Standard
39492
39493 \size footnotesize
39494 \InsetSpace ~
39495 \InsetSpace ~
39496 .ds 2
39497 \end_layout
39498
39499 \begin_layout Standard
39500
39501 \size footnotesize
39502 _gint::
39503 \end_layout
39504
39505 \begin_layout Standard
39506
39507 \size footnotesize
39508 \InsetSpace ~
39509 \InsetSpace ~
39510 .ds 2
39511 \end_layout
39512
39513 \begin_layout Standard
39514
39515 \size footnotesize
39516 ; sample.c 5
39517 \end_layout
39518
39519 \begin_layout Standard
39520
39521 \size footnotesize
39522 ; ----------------------------------------------
39523 \end_layout
39524
39525 \begin_layout Standard
39526
39527 \size footnotesize
39528 ; function function
39529 \end_layout
39530
39531 \begin_layout Standard
39532
39533 \size footnotesize
39534 ; ----------------------------------------------
39535 \end_layout
39536
39537 \begin_layout Standard
39538
39539 \size footnotesize
39540 _function:
39541 \end_layout
39542
39543 \begin_layout Standard
39544
39545 \size footnotesize
39546 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
39547 \end_layout
39548
39549 \begin_layout Standard
39550
39551 \size footnotesize
39552 \InsetSpace ~
39553 \InsetSpace ~
39554 mov r2,dpl
39555 \end_layout
39556
39557 \begin_layout Standard
39558
39559 \size footnotesize
39560 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
39561 \end_layout
39562
39563 \begin_layout Standard
39564
39565 \size footnotesize
39566 \InsetSpace ~
39567 \InsetSpace ~
39568 mov ar0,r2
39569 \end_layout
39570
39571 \begin_layout Standard
39572
39573 \size footnotesize
39574 ;_whilecontinue_0($1) :
39575 \end_layout
39576
39577 \begin_layout Standard
39578
39579 \size footnotesize
39580 00101$:
39581 \end_layout
39582
39583 \begin_layout Standard
39584
39585 \size footnotesize
39586 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
39587 \end_layout
39588
39589 \begin_layout Standard
39590
39591 \size footnotesize
39592 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39593 \end_layout
39594
39595 \begin_layout Standard
39596
39597 \size footnotesize
39598 \InsetSpace ~
39599 \InsetSpace ~
39600 mov ar2,@r0
39601 \end_layout
39602
39603 \begin_layout Standard
39604
39605 \size footnotesize
39606 \InsetSpace ~
39607 \InsetSpace ~
39608 inc r0
39609 \end_layout
39610
39611 \begin_layout Standard
39612
39613 \size footnotesize
39614 \InsetSpace ~
39615 \InsetSpace ~
39616 mov ar3,@r0
39617 \end_layout
39618
39619 \begin_layout Standard
39620
39621 \size footnotesize
39622 \InsetSpace ~
39623 \InsetSpace ~
39624 dec r0
39625 \end_layout
39626
39627 \begin_layout Standard
39628
39629 \size footnotesize
39630 \InsetSpace ~
39631 \InsetSpace ~
39632 mov a,r2
39633 \end_layout
39634
39635 \begin_layout Standard
39636
39637 \size footnotesize
39638 \InsetSpace ~
39639 \InsetSpace ~
39640 orl a,r3
39641 \end_layout
39642
39643 \begin_layout Standard
39644
39645 \size footnotesize
39646 \InsetSpace ~
39647 \InsetSpace ~
39648 jz 00103$
39649 \end_layout
39650
39651 \begin_layout Standard
39652
39653 \size footnotesize
39654 00114$:
39655 \end_layout
39656
39657 \begin_layout Standard
39658
39659 \size footnotesize
39660 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
39661 \end_layout
39662
39663 \begin_layout Standard
39664
39665 \size footnotesize
39666 \InsetSpace ~
39667 \InsetSpace ~
39668 mov dpl,_p
39669 \end_layout
39670
39671 \begin_layout Standard
39672
39673 \size footnotesize
39674 \InsetSpace ~
39675 \InsetSpace ~
39676 mov dph,(_p + 1)
39677 \end_layout
39678
39679 \begin_layout Standard
39680
39681 \size footnotesize
39682 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
39683 \end_layout
39684
39685 \begin_layout Standard
39686
39687 \size footnotesize
39688 \InsetSpace ~
39689 \InsetSpace ~
39690 mov a,#0x02
39691 \end_layout
39692
39693 \begin_layout Standard
39694
39695 \size footnotesize
39696 \InsetSpace ~
39697 \InsetSpace ~
39698 add a,_p
39699 \end_layout
39700
39701 \begin_layout Standard
39702
39703 \size footnotesize
39704 \InsetSpace ~
39705 \InsetSpace ~
39706 mov _p,a
39707 \end_layout
39708
39709 \begin_layout Standard
39710
39711 \size footnotesize
39712 \InsetSpace ~
39713 \InsetSpace ~
39714 clr a
39715 \end_layout
39716
39717 \begin_layout Standard
39718
39719 \size footnotesize
39720 \InsetSpace ~
39721 \InsetSpace ~
39722 addc a,(_p + 1)
39723 \end_layout
39724
39725 \begin_layout Standard
39726
39727 \size footnotesize
39728 \InsetSpace ~
39729 \InsetSpace ~
39730 mov (_p + 1),a
39731 \end_layout
39732
39733 \begin_layout Standard
39734
39735 \size footnotesize
39736 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
39737 \end_layout
39738
39739 \begin_layout Standard
39740
39741 \size footnotesize
39742 \InsetSpace ~
39743 \InsetSpace ~
39744 movx a,@dptr
39745 \end_layout
39746
39747 \begin_layout Standard
39748
39749 \size footnotesize
39750 \InsetSpace ~
39751 \InsetSpace ~
39752 mov r2,a
39753 \end_layout
39754
39755 \begin_layout Standard
39756
39757 \size footnotesize
39758 \InsetSpace ~
39759 \InsetSpace ~
39760 inc dptr
39761 \end_layout
39762
39763 \begin_layout Standard
39764
39765 \size footnotesize
39766 \InsetSpace ~
39767 \InsetSpace ~
39768 movx a,@dptr
39769 \end_layout
39770
39771 \begin_layout Standard
39772
39773 \size footnotesize
39774 \InsetSpace ~
39775 \InsetSpace ~
39776 mov r3,a
39777 \end_layout
39778
39779 \begin_layout Standard
39780
39781 \size footnotesize
39782 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
39783 \end_layout
39784
39785 \begin_layout Standard
39786
39787 \size footnotesize
39788 \InsetSpace ~
39789 \InsetSpace ~
39790 mov @r0,ar2
39791 \end_layout
39792
39793 \begin_layout Standard
39794
39795 \size footnotesize
39796 \InsetSpace ~
39797 \InsetSpace ~
39798 inc r0
39799 \end_layout
39800
39801 \begin_layout Standard
39802
39803 \size footnotesize
39804 \InsetSpace ~
39805 \InsetSpace ~
39806 mov @r0,ar3
39807 \end_layout
39808
39809 \begin_layout Standard
39810
39811 \size footnotesize
39812 ; iTemp6 [lr5:16]{_near * int}[r0] = 
39813 \end_layout
39814
39815 \begin_layout Standard
39816
39817 \size footnotesize
39818 ; iTemp6 [lr5:16]{_near * int}[r0] + 
39819 \end_layout
39820
39821 \begin_layout Standard
39822
39823 \size footnotesize
39824 ; 0x2 {short}
39825 \end_layout
39826
39827 \begin_layout Standard
39828
39829 \size footnotesize
39830 \InsetSpace ~
39831 \InsetSpace ~
39832 inc r0
39833 \end_layout
39834
39835 \begin_layout Standard
39836
39837 \size footnotesize
39838 ; goto _whilecontinue_0($1)
39839 \end_layout
39840
39841 \begin_layout Standard
39842
39843 \size footnotesize
39844 \InsetSpace ~
39845 \InsetSpace ~
39846 sjmp 00101$
39847 \end_layout
39848
39849 \begin_layout Standard
39850
39851 \size footnotesize
39852 ; _whilebreak_0($3) :
39853 \end_layout
39854
39855 \begin_layout Standard
39856
39857 \size footnotesize
39858 00103$:
39859 \end_layout
39860
39861 \begin_layout Standard
39862
39863 \size footnotesize
39864 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39865 \end_layout
39866
39867 \begin_layout Standard
39868
39869 \size footnotesize
39870 \InsetSpace ~
39871 \InsetSpace ~
39872 mov r2,#0x00
39873 \end_layout
39874
39875 \begin_layout Standard
39876
39877 \size footnotesize
39878 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39879 \end_layout
39880
39881 \begin_layout Standard
39882
39883 \size footnotesize
39884 \InsetSpace ~
39885 \InsetSpace ~
39886 mov r3,#0x00
39887 \end_layout
39888
39889 \begin_layout Standard
39890
39891 \size footnotesize
39892 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39893 \end_layout
39894
39895 \begin_layout Standard
39896
39897 \size footnotesize
39898 \InsetSpace ~
39899 \InsetSpace ~
39900 mov r4,#0x00
39901 \end_layout
39902
39903 \begin_layout Standard
39904
39905 \size footnotesize
39906 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39907 \end_layout
39908
39909 \begin_layout Standard
39910
39911 \size footnotesize
39912 \InsetSpace ~
39913 \InsetSpace ~
39914 mov r5,#0x0A
39915 \end_layout
39916
39917 \begin_layout Standard
39918
39919 \size footnotesize
39920 \InsetSpace ~
39921 \InsetSpace ~
39922 mov r6,#0x00
39923 \end_layout
39924
39925 \begin_layout Standard
39926
39927 \size footnotesize
39928 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39929 \end_layout
39930
39931 \begin_layout Standard
39932
39933 \size footnotesize
39934 \InsetSpace ~
39935 \InsetSpace ~
39936 mov r7,#0x1E
39937 \end_layout
39938
39939 \begin_layout Standard
39940
39941 \size footnotesize
39942 \InsetSpace ~
39943 \InsetSpace ~
39944 mov r0,#0x00
39945 \end_layout
39946
39947 \begin_layout Standard
39948
39949 \size footnotesize
39950 ; _forcond_0($4) :
39951 \end_layout
39952
39953 \begin_layout Standard
39954
39955 \size footnotesize
39956 00104$:
39957 \end_layout
39958
39959 \begin_layout Standard
39960
39961 \size footnotesize
39962 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
39963 \end_layout
39964
39965 \begin_layout Standard
39966
39967 \size footnotesize
39968 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39969 \end_layout
39970
39971 \begin_layout Standard
39972
39973 \size footnotesize
39974 \InsetSpace ~
39975 \InsetSpace ~
39976 clr c
39977 \end_layout
39978
39979 \begin_layout Standard
39980
39981 \size footnotesize
39982 \InsetSpace ~
39983 \InsetSpace ~
39984 mov a,r4
39985 \end_layout
39986
39987 \begin_layout Standard
39988
39989 \size footnotesize
39990 \InsetSpace ~
39991 \InsetSpace ~
39992 xrl a,#0x80
39993 \end_layout
39994
39995 \begin_layout Standard
39996
39997 \size footnotesize
39998 \InsetSpace ~
39999 \InsetSpace ~
40000 subb a,#0x8a
40001 \end_layout
40002
40003 \begin_layout Standard
40004
40005 \size footnotesize
40006 \InsetSpace ~
40007 \InsetSpace ~
40008 jnc 00107$
40009 \end_layout
40010
40011 \begin_layout Standard
40012
40013 \size footnotesize
40014 00115$:
40015 \end_layout
40016
40017 \begin_layout Standard
40018
40019 \size footnotesize
40020 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
40021 \end_layout
40022
40023 \begin_layout Standard
40024
40025 \size footnotesize
40026 ; iTemp21 [lr21:38]{short}[r4]
40027 \end_layout
40028
40029 \begin_layout Standard
40030
40031 \size footnotesize
40032 \InsetSpace ~
40033 \InsetSpace ~
40034 mov a,r4
40035 \end_layout
40036
40037 \begin_layout Standard
40038
40039 \size footnotesize
40040 \InsetSpace ~
40041 \InsetSpace ~
40042 add a,r2
40043 \end_layout
40044
40045 \begin_layout Standard
40046
40047 \size footnotesize
40048 \InsetSpace ~
40049 \InsetSpace ~
40050 mov r2,a
40051 \end_layout
40052
40053 \begin_layout Standard
40054
40055 \size footnotesize
40056 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
40057 \end_layout
40058
40059 \begin_layout Standard
40060
40061 \size footnotesize
40062 \InsetSpace ~
40063 \InsetSpace ~
40064 mov b,#0x03
40065 \end_layout
40066
40067 \begin_layout Standard
40068
40069 \size footnotesize
40070 \InsetSpace ~
40071 \InsetSpace ~
40072 mov a,r4
40073 \end_layout
40074
40075 \begin_layout Standard
40076
40077 \size footnotesize
40078 \InsetSpace ~
40079 \InsetSpace ~
40080 mul ab
40081 \end_layout
40082
40083 \begin_layout Standard
40084
40085 \size footnotesize
40086 \InsetSpace ~
40087 \InsetSpace ~
40088 mov r1,a
40089 \end_layout
40090
40091 \begin_layout Standard
40092
40093 \size footnotesize
40094 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
40095 \end_layout
40096
40097 \begin_layout Standard
40098
40099 \size footnotesize
40100 ; iTemp15 [lr29:30]{short}[r1]
40101 \end_layout
40102
40103 \begin_layout Standard
40104
40105 \size footnotesize
40106 \InsetSpace ~
40107 \InsetSpace ~
40108 add a,r3
40109 \end_layout
40110
40111 \begin_layout Standard
40112
40113 \size footnotesize
40114 \InsetSpace ~
40115 \InsetSpace ~
40116 mov r3,a
40117 \end_layout
40118
40119 \begin_layout Standard
40120
40121 \size footnotesize
40122 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
40123 \end_layout
40124
40125 \begin_layout Standard
40126
40127 \size footnotesize
40128 \InsetSpace ~
40129 \InsetSpace ~
40130 mov a,r7
40131 \end_layout
40132
40133 \begin_layout Standard
40134
40135 \size footnotesize
40136 \InsetSpace ~
40137 \InsetSpace ~
40138 add a,#0xfd
40139 \end_layout
40140
40141 \begin_layout Standard
40142
40143 \size footnotesize
40144 \InsetSpace ~
40145 \InsetSpace ~
40146 mov r7,a
40147 \end_layout
40148
40149 \begin_layout Standard
40150
40151 \size footnotesize
40152 \InsetSpace ~
40153 \InsetSpace ~
40154 mov a,r0
40155 \end_layout
40156
40157 \begin_layout Standard
40158
40159 \size footnotesize
40160 \InsetSpace ~
40161 \InsetSpace ~
40162 addc a,#0xff
40163 \end_layout
40164
40165 \begin_layout Standard
40166
40167 \size footnotesize
40168 \InsetSpace ~
40169 \InsetSpace ~
40170 mov r0,a
40171 \end_layout
40172
40173 \begin_layout Standard
40174
40175 \size footnotesize
40176 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
40177 \end_layout
40178
40179 \begin_layout Standard
40180
40181 \size footnotesize
40182 \InsetSpace ~
40183 \InsetSpace ~
40184 mov a,r7
40185 \end_layout
40186
40187 \begin_layout Standard
40188
40189 \size footnotesize
40190 \InsetSpace ~
40191 \InsetSpace ~
40192 add a,_gint
40193 \end_layout
40194
40195 \begin_layout Standard
40196
40197 \size footnotesize
40198 \InsetSpace ~
40199 \InsetSpace ~
40200 mov _gint,a
40201 \end_layout
40202
40203 \begin_layout Standard
40204
40205 \size footnotesize
40206 \InsetSpace ~
40207 \InsetSpace ~
40208 mov a,r0
40209 \end_layout
40210
40211 \begin_layout Standard
40212
40213 \size footnotesize
40214 \InsetSpace ~
40215 \InsetSpace ~
40216 addc a,(_gint + 1)
40217 \end_layout
40218
40219 \begin_layout Standard
40220
40221 \size footnotesize
40222 \InsetSpace ~
40223 \InsetSpace ~
40224 mov (_gint + 1),a
40225 \end_layout
40226
40227 \begin_layout Standard
40228
40229 \size footnotesize
40230 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
40231 \end_layout
40232
40233 \begin_layout Standard
40234
40235 \size footnotesize
40236 \InsetSpace ~
40237 \InsetSpace ~
40238 inc r4
40239 \end_layout
40240
40241 \begin_layout Standard
40242
40243 \size footnotesize
40244 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
40245 \end_layout
40246
40247 \begin_layout Standard
40248
40249 \size footnotesize
40250 \InsetSpace ~
40251 \InsetSpace ~
40252 dec r5
40253 \end_layout
40254
40255 \begin_layout Standard
40256
40257 \size footnotesize
40258 \InsetSpace ~
40259 \InsetSpace ~
40260 cjne r5,#0xff,00104$
40261 \end_layout
40262
40263 \begin_layout Standard
40264
40265 \size footnotesize
40266 \InsetSpace ~
40267 \InsetSpace ~
40268 dec r6
40269 \end_layout
40270
40271 \begin_layout Standard
40272
40273 \size footnotesize
40274 ; goto _forcond_0($4)
40275 \end_layout
40276
40277 \begin_layout Standard
40278
40279 \size footnotesize
40280 \InsetSpace ~
40281 \InsetSpace ~
40282 sjmp 00104$
40283 \end_layout
40284
40285 \begin_layout Standard
40286
40287 \size footnotesize
40288 ; _forbreak_0($7) :
40289 \end_layout
40290
40291 \begin_layout Standard
40292
40293 \size footnotesize
40294 00107$:
40295 \end_layout
40296
40297 \begin_layout Standard
40298
40299 \size footnotesize
40300 ; ret iTemp24 [lr40:41]{short}
40301 \end_layout
40302
40303 \begin_layout Standard
40304
40305 \size footnotesize
40306 \InsetSpace ~
40307 \InsetSpace ~
40308 mov a,r3
40309 \end_layout
40310
40311 \begin_layout Standard
40312
40313 \size footnotesize
40314 \InsetSpace ~
40315 \InsetSpace ~
40316 add a,r2
40317 \end_layout
40318
40319 \begin_layout Standard
40320
40321 \size footnotesize
40322 \InsetSpace ~
40323 \InsetSpace ~
40324 mov dpl,a
40325 \end_layout
40326
40327 \begin_layout Standard
40328
40329 \size footnotesize
40330 ; _return($8) :
40331 \end_layout
40332
40333 \begin_layout Standard
40334
40335 \size footnotesize
40336 00108$:
40337 \end_layout
40338
40339 \begin_layout Standard
40340
40341 \size footnotesize
40342 \InsetSpace ~
40343 \InsetSpace ~
40344 ret
40345 \newline
40346
40347 \end_layout
40348
40349 \begin_layout Section
40350 A few words about basic block successors, predecessors and dominators
40351 \end_layout
40352
40353 \begin_layout Standard
40354 Successors are basic blocks
40355 \begin_inset LatexCommand \index{Basic blocks}
40356
40357 \end_inset
40358
40359  that might execute after this basic block.
40360 \newline
40361 Predecessors are basic blocks
40362  that might execute before reaching this basic block.
40363 \newline
40364 Dominators are basic
40365  blocks that WILL execute before reaching this basic block.
40366 \newline
40367
40368 \end_layout
40369
40370 \begin_layout Standard
40371 [basic block 1]
40372 \end_layout
40373
40374 \begin_layout Standard
40375 if (something)
40376 \end_layout
40377
40378 \begin_layout Standard
40379 \InsetSpace ~
40380 \InsetSpace ~
40381 \InsetSpace ~
40382 \InsetSpace ~
40383 [basic block 2]
40384 \end_layout
40385
40386 \begin_layout Standard
40387 else
40388 \end_layout
40389
40390 \begin_layout Standard
40391 \InsetSpace ~
40392 \InsetSpace ~
40393 \InsetSpace ~
40394 \InsetSpace ~
40395 [basic block 3]
40396 \end_layout
40397
40398 \begin_layout Standard
40399 [basic block 4]
40400 \newline
40401
40402 \end_layout
40403
40404 \begin_layout Standard
40405 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
40406 \end_layout
40407
40408 \begin_layout Standard
40409 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
40410 \end_layout
40411
40412 \begin_layout Standard
40413 c) domVect of [BB4] = BB1 ...
40414  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
40415  was executed.
40416 \end_layout
40417
40418 \begin_layout Chapter
40419 Acknowledgments
40420 \end_layout
40421
40422 \begin_layout Standard
40423 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
40424
40425 \end_inset
40426
40427
40428 \newline
40429
40430 \newline
40431
40432 \emph on
40433 Thanks to all the other volunteer developers who have helped with coding,
40434  testing, web-page creation, distribution sets, etc.
40435  You know who you are :-)
40436 \emph default
40437
40438 \newline
40439
40440 \newline
40441
40442 \emph on
40443 Thanks to Sourceforge 
40444 \begin_inset LatexCommand \url{http://www.sf.net}
40445
40446 \end_inset
40447
40448  which has hosted the project since 1999 and donates significant download
40449  bandwidth.
40450 \emph default
40451
40452 \newline
40453
40454 \newline
40455
40456 \emph on
40457 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
40458  cycles and bandwidth for snapshot builds.
40459 \newline
40460
40461 \end_layout
40462
40463 \begin_layout Standard
40464 This document was initially written by Sandeep Dutta
40465 \end_layout
40466
40467 \begin_layout Standard
40468 All product names mentioned herein may be trademarks
40469 \begin_inset LatexCommand \index{Trademarks}
40470
40471 \end_inset
40472
40473  of their respective companies.
40474  
40475 \end_layout
40476
40477 \begin_layout Section*
40478 Alphabetical index
40479 \end_layout
40480
40481 \begin_layout Standard
40482 To avoid confusion, the installation and building options for SDCC itself
40483  (chapter 2) are not part of the index.
40484 \end_layout
40485
40486 \begin_layout Standard
40487 \begin_inset LatexCommand \printindex{}
40488
40489 \end_inset
40490
40491
40492 \end_layout
40493
40494 \end_body
40495 \end_document