* updated the list pf supported pic14 devices
[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.8.0
108 \size footnotesize
109
110 \newline
111 $Date::             $ 
112 \newline
113 $Revision$
114 \end_layout
115
116 \begin_layout Standard
117 \begin_inset Note Note
118 status collapsed
119
120 \begin_layout Standard
121 The above strings enclosed in $ are automatically updated by Subversion
122 \end_layout
123
124 \end_inset
125
126
127 \end_layout
128
129 \begin_layout Standard
130 \begin_inset LatexCommand \tableofcontents{}
131
132 \end_inset
133
134
135 \end_layout
136
137 \begin_layout Chapter
138 Introduction
139 \end_layout
140
141 \begin_layout Section
142 About SDCC
143 \end_layout
144
145 \begin_layout Standard
146
147 \series bold
148 SDCC
149 \series default
150  (
151 \emph on
152 S
153 \emph default
154 mall 
155 \emph on
156 D
157 \emph default
158 evice 
159 \emph on
160 C
161 \emph default
162  
163 \emph on
164 C
165 \emph default
166 ompiler) is free open source, retargettable, optimizing ANSI-C compiler
167  by 
168 \series bold
169 Sandeep Dutta
170 \series default
171  designed for 8 bit Microprocessors.
172  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
173  8051, 8052
174 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
175
176 \end_inset
177
178 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
179  Zilog Z80 based MCUs.
180  It can be retargeted for other microprocessors, support for Microchip PIC,
181  Atmel AVR is under development.
182  The entire source code for the compiler is distributed under GPL.
183  SDCC uses ASXXXX
184 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
185
186 \end_inset
187
188  & ASLINK
189 \begin_inset LatexCommand \index{aslink}
190
191 \end_inset
192
193 , an open source retargetable assembler & linker.
194  SDCC has extensive language extensions suitable for utilizing various microcont
195 rollers and underlying hardware effectively.
196  
197 \newline
198
199 \newline
200 In addition to the MCU specific optimizations SDCC also does a host of
201  standard optimizations like:
202 \end_layout
203
204 \begin_layout Itemize
205 global sub expression elimination, 
206 \end_layout
207
208 \begin_layout Itemize
209 loop optimizations (loop invariant, strength reduction of induction variables
210  and loop reversing), 
211 \end_layout
212
213 \begin_layout Itemize
214 constant folding & propagation, 
215 \end_layout
216
217 \begin_layout Itemize
218 copy propagation, 
219 \end_layout
220
221 \begin_layout Itemize
222 dead code elimination 
223 \end_layout
224
225 \begin_layout Itemize
226 jump tables for 
227 \emph on
228 switch
229 \emph default
230  statements.
231 \end_layout
232
233 \begin_layout Standard
234 For the back-end SDCC uses a global register allocation scheme which should
235  be well suited for other 8 bit MCUs.
236  
237 \newline
238
239 \newline
240 The peep hole optimizer uses a rule based substitution mechanism which
241  is MCU independent.
242  
243 \newline
244
245 \newline
246 Supported data-types are:
247 \end_layout
248
249 \begin_layout Standard
250 \begin_inset Tabular
251 <lyxtabular version="3" rows="8" columns="5">
252 <features>
253 <column alignment="center" valignment="top" leftline="true" width="0">
254 <column alignment="center" valignment="top" leftline="true" width="0">
255 <column alignment="center" valignment="top" leftline="true" width="0">
256 <column alignment="center" valignment="top" leftline="true" width="0">
257 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
258 <row topline="true" bottomline="true">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
260 \begin_inset Text
261
262 \begin_layout Standard
263 type
264 \end_layout
265
266 \end_inset
267 </cell>
268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
269 \begin_inset Text
270
271 \begin_layout Standard
272 width
273 \end_layout
274
275 \end_inset
276 </cell>
277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
278 \begin_inset Text
279
280 \begin_layout Standard
281 default
282 \end_layout
283
284 \end_inset
285 </cell>
286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
287 \begin_inset Text
288
289 \begin_layout Standard
290 signed range
291 \end_layout
292
293 \end_inset
294 </cell>
295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
296 \begin_inset Text
297
298 \begin_layout Standard
299 unsigned range
300 \end_layout
301
302 \end_inset
303 </cell>
304 </row>
305 <row topline="true">
306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
307 \begin_inset Text
308
309 \begin_layout Standard
310 bool
311 \end_layout
312
313 \end_inset
314 </cell>
315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
316 \begin_inset Text
317
318 \begin_layout Standard
319 1 bit
320 \end_layout
321
322 \end_inset
323 </cell>
324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
325 \begin_inset Text
326
327 \begin_layout Standard
328 unsigned
329 \end_layout
330
331 \end_inset
332 </cell>
333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
334 \begin_inset Text
335
336 \begin_layout Standard
337 -
338 \end_layout
339
340 \end_inset
341 </cell>
342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
343 \begin_inset Text
344
345 \begin_layout Standard
346 0, 1
347 \end_layout
348
349 \end_inset
350 </cell>
351 </row>
352 <row topline="true">
353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
354 \begin_inset Text
355
356 \begin_layout Standard
357 char
358 \end_layout
359
360 \end_inset
361 </cell>
362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
363 \begin_inset Text
364
365 \begin_layout Standard
366 8 bits, 1 byte
367 \end_layout
368
369 \end_inset
370 </cell>
371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
372 \begin_inset Text
373
374 \begin_layout Standard
375 signed
376 \end_layout
377
378 \end_inset
379 </cell>
380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
381 \begin_inset Text
382
383 \begin_layout Standard
384 -128, +127
385 \end_layout
386
387 \end_inset
388 </cell>
389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
390 \begin_inset Text
391
392 \begin_layout Standard
393 0, +255
394 \end_layout
395
396 \end_inset
397 </cell>
398 </row>
399 <row topline="true">
400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
401 \begin_inset Text
402
403 \begin_layout Standard
404 short
405 \end_layout
406
407 \end_inset
408 </cell>
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
410 \begin_inset Text
411
412 \begin_layout Standard
413 16 bits, 2 bytes
414 \end_layout
415
416 \end_inset
417 </cell>
418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
419 \begin_inset Text
420
421 \begin_layout Standard
422 signed
423 \end_layout
424
425 \end_inset
426 </cell>
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
428 \begin_inset Text
429
430 \begin_layout Standard
431 -32.768, +32.767
432 \end_layout
433
434 \end_inset
435 </cell>
436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
437 \begin_inset Text
438
439 \begin_layout Standard
440 0, +65.535
441 \end_layout
442
443 \end_inset
444 </cell>
445 </row>
446 <row topline="true">
447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
448 \begin_inset Text
449
450 \begin_layout Standard
451 int
452 \end_layout
453
454 \end_inset
455 </cell>
456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
457 \begin_inset Text
458
459 \begin_layout Standard
460 16 bits, 2 bytes
461 \end_layout
462
463 \end_inset
464 </cell>
465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
466 \begin_inset Text
467
468 \begin_layout Standard
469 signed
470 \end_layout
471
472 \end_inset
473 </cell>
474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
475 \begin_inset Text
476
477 \begin_layout Standard
478 -32.768, +32.767
479 \end_layout
480
481 \end_inset
482 </cell>
483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
484 \begin_inset Text
485
486 \begin_layout Standard
487 0, +65.535
488 \end_layout
489
490 \end_inset
491 </cell>
492 </row>
493 <row topline="true" bottomline="true">
494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
495 \begin_inset Text
496
497 \begin_layout Standard
498 long
499 \end_layout
500
501 \end_inset
502 </cell>
503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
504 \begin_inset Text
505
506 \begin_layout Standard
507 32 bits, 4 bytes
508 \end_layout
509
510 \end_inset
511 </cell>
512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
513 \begin_inset Text
514
515 \begin_layout Standard
516 signed
517 \end_layout
518
519 \end_inset
520 </cell>
521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
522 \begin_inset Text
523
524 \begin_layout Standard
525 -2.147.483.648, +2.147.483.647
526 \end_layout
527
528 \end_inset
529 </cell>
530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
531 \begin_inset Text
532
533 \begin_layout Standard
534 0, +4.294.967.295
535 \end_layout
536
537 \end_inset
538 </cell>
539 </row>
540 <row topline="true" bottomline="true">
541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
542 \begin_inset Text
543
544 \begin_layout Standard
545 float
546 \end_layout
547
548 \end_inset
549 </cell>
550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
551 \begin_inset Text
552
553 \begin_layout Standard
554 4 bytes IEEE 754
555 \end_layout
556
557 \end_inset
558 </cell>
559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
560 \begin_inset Text
561
562 \begin_layout Standard
563 signed
564 \end_layout
565
566 \end_inset
567 </cell>
568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
569 \begin_inset Text
570
571 \begin_layout Standard
572
573 \end_layout
574
575 \end_inset
576 </cell>
577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
578 \begin_inset Text
579
580 \begin_layout Standard
581 1.175494351E-38, 
582 \family roman
583 \series medium
584 \shape up
585 \size normal
586 \emph off
587 \bar no
588 \noun off
589 \color none
590 3.402823466E+38
591 \end_layout
592
593 \end_inset
594 </cell>
595 </row>
596 <row topline="true" bottomline="true">
597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
598 \begin_inset Text
599
600 \begin_layout Standard
601 pointer
602 \end_layout
603
604 \end_inset
605 </cell>
606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
607 \begin_inset Text
608
609 \begin_layout Standard
610 1, 2, 3 or 4 bytes
611 \end_layout
612
613 \end_inset
614 </cell>
615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
616 \begin_inset Text
617
618 \begin_layout Standard
619 generic
620 \end_layout
621
622 \end_inset
623 </cell>
624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
625 \begin_inset Text
626
627 \begin_layout Standard
628
629 \end_layout
630
631 \end_inset
632 </cell>
633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
634 \begin_inset Text
635
636 \begin_layout Standard
637
638 \end_layout
639
640 \end_inset
641 </cell>
642 </row>
643 </lyxtabular>
644
645 \end_inset
646
647
648 \newline
649 The compiler also allows 
650 \emph on
651 inline assembler code
652 \emph default
653  to be embedded anywhere in a function.
654  In addition, routines developed in assembly can also be called.
655 \newline
656
657 \newline
658 SDCC also
659  provides an option (-
660 \begin_inset ERT
661 status collapsed
662
663 \begin_layout Standard
664
665
666 \backslash
667 /
668 \end_layout
669
670 \end_inset
671
672 -cyclomatic) to report the relative complexity of a function.
673  These functions can then be further optimized, or hand coded in assembly
674  if needed.
675  
676 \newline
677
678 \newline
679 SDCC also comes with a companion source level debugger SDCDB.
680  The debugger currently uses ucSim, a free open source simulator for 8051
681  and other micro-controllers.
682 \newline
683
684 \newline
685 The latest SDCC version can be downloaded from
686  
687 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
688
689 \end_inset
690
691 .
692
693 \series bold
694  
695 \series default
696 \emph on
697 Please note: the compiler will probably always be some steps ahead of this
698  documentation
699 \series bold
700 \emph default
701
702 \begin_inset LatexCommand \index{Status of documentation}
703
704 \end_inset
705
706
707 \begin_inset Foot
708 status open
709
710 \begin_layout Standard
711 Obviously this has pros and cons
712 \end_layout
713
714 \end_inset
715
716 .
717 \end_layout
718
719 \begin_layout Section
720 Open Source
721 \end_layout
722
723 \begin_layout Standard
724 All packages used in this compiler system are 
725 \emph on
726 open source
727 \emph default
728  and 
729 \emph on
730 freeware
731 \emph default
732 ; source code for all the sub-packages (pre-processor, assemblers, linkers
733  etc.) is distributed with the package.
734  This documentation is maintained using a free open source word processor
735  (LyX).
736 \newline
737 This program is free software; you can redistribute it and/or modify
738  it under the terms of the GNU General Public License
739 \begin_inset LatexCommand \index{GNU General Public License, GPL}
740
741 \end_inset
742
743  as published by the Free Software Foundation; either version 2, or (at
744  your option) any later version.
745  This program is distributed in the hope that it will be useful, but WITHOUT
746  ANY WARRANTY; without even the implied warranty
747 \begin_inset LatexCommand \index{warranty}
748
749 \end_inset
750
751  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
752  See the GNU General Public License for more details.
753  You should have received a copy of the GNU General Public License along
754  with this program; if not, write to the Free Software Foundation, 59 Temple
755  Place - Suite 330, Boston, MA 02111-1307, USA.
756  In other words, you are welcome to use, share and improve this program.
757  You are forbidden to forbid anyone else to use, share and improve what
758  you give them.
759  Help stamp out software-hoarding! 
760 \end_layout
761
762 \begin_layout Section
763 Typographic conventions
764 \begin_inset LatexCommand \index{Typographic conventions}
765
766 \end_inset
767
768
769 \end_layout
770
771 \begin_layout Standard
772 Throughout this manual, we will use the following convention.
773  Commands you have to type in are printed in 
774 \family sans
775 \series bold
776 "sans serif"
777 \series default
778 .
779
780 \family default
781  Code samples are printed in 
782 \family typewriter
783 typewriter font.
784
785 \family default
786  Interesting items and new terms are printed in 
787 \emph on
788 italic.
789 \end_layout
790
791 \begin_layout Section
792 Compatibility
793 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
794
795 \end_inset
796
797  with previous versions
798 \begin_inset LatexCommand \index{Compatibility with previous versions}
799
800 \end_inset
801
802
803 \end_layout
804
805 \begin_layout Standard
806 Newer versions have usually numerous bug fixes compared with the previous
807  version.
808  But we also sometimes introduce some incompatibilities with older versions.
809  Not just for the fun of it, but to make the compiler more stable, efficient
810  and ANSI compliant
811 \begin_inset LatexCommand \index{ANSI-compliance}
812
813 \end_inset
814
815  (see section 
816 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
817
818 \end_inset
819
820  for ANSI-Compliance).
821  
822 \begin_inset Note Note
823 status collapsed
824
825 \begin_layout Standard
826 It would be fine to add to each item, in which version was it changed.
827 \end_layout
828
829 \end_inset
830
831
832 \newline
833
834 \end_layout
835
836 \begin_layout Itemize
837 short is now equivalent to int (16 bits), it used to be equivalent to char
838  (8 bits) which is not ANSI compliant.
839  To maintain compatibility, old programs may be compiled using the -
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 and 
872 \series bold
873 -
874 \begin_inset ERT
875 status collapsed
876
877 \begin_layout Standard
878
879
880 \backslash
881 /
882 \end_layout
883
884 \end_inset
885
886 -std-c89
887 \begin_inset LatexCommand \index{-\/-std-c89}
888
889 \end_inset
890
891  
892 \series default
893 and
894 \series bold
895  -
896 \begin_inset ERT
897 status collapsed
898
899 \begin_layout Standard
900
901
902 \backslash
903 /
904 \end_layout
905
906 \end_inset
907
908 -std-c99
909 \begin_inset LatexCommand \index{-\/-std-c99}
910
911 \end_inset
912
913
914 \series default
915  command line option are not defined 
916 \begin_inset Marginal
917 status collapsed
918
919 \begin_layout Standard
920
921 \series bold
922 \InsetSpace ~
923 !
924 \end_layout
925
926 \end_inset
927
928 , e.g.: 
929 \newline
930
931 \family typewriter
932 \InsetSpace ~
933 \InsetSpace ~
934 char a=3;
935 \newline
936 \InsetSpace ~
937 \InsetSpace ~
938 printf ("%d %c
939 \backslash
940 n", a, (char)a);
941 \family default
942
943 \newline
944  will push a as an int and as a char resp if
945 \series bold
946  -
947 \begin_inset ERT
948 status collapsed
949
950 \begin_layout Standard
951
952
953 \backslash
954 /
955 \end_layout
956
957 \end_inset
958
959 -std-c89
960 \begin_inset LatexCommand \index{-\/-std-c89}
961
962 \end_inset
963
964  
965 \series default
966 and
967 \series bold
968  -
969 \begin_inset ERT
970 status collapsed
971
972 \begin_layout Standard
973
974
975 \backslash
976 /
977 \end_layout
978
979 \end_inset
980
981 -std-c99
982 \begin_inset LatexCommand \index{-\/-std-c99}
983
984 \end_inset
985
986
987 \series default
988  command line options are not defined,
989 \newline
990  will push a as two ints if
991 \series bold
992  -
993 \begin_inset ERT
994 status collapsed
995
996 \begin_layout Standard
997
998
999 \backslash
1000 /
1001 \end_layout
1002
1003 \end_inset
1004
1005 -std-c89
1006 \begin_inset LatexCommand \index{-\/-std-c89}
1007
1008 \end_inset
1009
1010  
1011 \series default
1012 or
1013 \series bold
1014  -
1015 \begin_inset ERT
1016 status collapsed
1017
1018 \begin_layout Standard
1019
1020
1021 \backslash
1022 /
1023 \end_layout
1024
1025 \end_inset
1026
1027 -std-c99
1028 \begin_inset LatexCommand \index{-\/-std-c99}
1029
1030 \end_inset
1031
1032
1033 \series default
1034  command line option is defined.
1035 \end_layout
1036
1037 \begin_layout Itemize
1038 option -
1039 \begin_inset ERT
1040 status collapsed
1041
1042 \begin_layout Standard
1043
1044
1045 \backslash
1046 /
1047 \end_layout
1048
1049 \end_inset
1050
1051 -regextend has been removed.
1052 \end_layout
1053
1054 \begin_layout Itemize
1055 option -
1056 \begin_inset ERT
1057 status collapsed
1058
1059 \begin_layout Standard
1060
1061
1062 \backslash
1063 /
1064 \end_layout
1065
1066 \end_inset
1067
1068 -noregparms has been removed.
1069 \end_layout
1070
1071 \begin_layout Itemize
1072 option -
1073 \begin_inset ERT
1074 status collapsed
1075
1076 \begin_layout Standard
1077
1078
1079 \backslash
1080 /
1081 \end_layout
1082
1083 \end_inset
1084
1085 -stack-after-data has been removed.
1086 \end_layout
1087
1088 \begin_layout Itemize
1089 bit
1090 \begin_inset LatexCommand \index{bit}
1091
1092 \end_inset
1093
1094  and sbit
1095 \begin_inset LatexCommand \index{sbit}
1096
1097 \end_inset
1098
1099
1100 \begin_inset LatexCommand \index{\_\_sbit}
1101
1102 \end_inset
1103
1104  types now consistently behave like the C99 _Bool type with respect to type
1105  conversion
1106 \begin_inset LatexCommand \index{type conversion}
1107
1108 \end_inset
1109
1110
1111 \begin_inset LatexCommand \index{type promotion}
1112
1113 \end_inset
1114
1115 .
1116  The most common incompatibility resulting from this change is related to
1117  bit toggling
1118 \begin_inset LatexCommand \index{Bit toggling}
1119
1120 \end_inset
1121
1122  idioms, e.g.:
1123 \newline
1124
1125 \family typewriter
1126 \InsetSpace ~
1127 \InsetSpace ~
1128 bit b;
1129 \newline
1130 \InsetSpace ~
1131 \InsetSpace ~
1132 b = ~
1133 \begin_inset LatexCommand \index{\~\/ Operator}
1134
1135 \end_inset
1136
1137 b; /* equivalent to b=1 instead of toggling b */
1138 \begin_inset Marginal
1139 status collapsed
1140
1141 \begin_layout Standard
1142
1143 \series bold
1144 \InsetSpace ~
1145 !
1146 \end_layout
1147
1148 \end_inset
1149
1150
1151 \newline
1152 \InsetSpace ~
1153 \InsetSpace ~
1154 b = !b; /* toggles b */
1155 \newline
1156
1157 \family default
1158 In previous versions, both forms would have toggled the bit.
1159 \end_layout
1160
1161 \begin_layout Standard
1162
1163 \emph on
1164 <pending: more incompatibilities?>
1165 \end_layout
1166
1167 \begin_layout Section
1168 System Requirements
1169 \end_layout
1170
1171 \begin_layout Standard
1172 What do you need before you start installation of SDCC? A computer, and
1173  a desire to compute.
1174  The preferred method of installation is to compile SDCC from source using
1175  GNU gcc and make.
1176  For Windows some pre-compiled binary distributions are available for your
1177  convenience.
1178  You should have some experience with command line tools and compiler use.
1179 \end_layout
1180
1181 \begin_layout Section
1182 Other Resources
1183 \end_layout
1184
1185 \begin_layout Standard
1186 The SDCC home page at 
1187 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1188
1189 \end_inset
1190
1191  is a great place to find distribution sets.
1192  You can also find links to the user mailing lists that offer help or discuss
1193  SDCC with other SDCC users.
1194  Web links to other SDCC related sites can also be found here.
1195  This document can be found in the DOC directory of the source package as
1196  a text or HTML file.
1197  A pdf version of this document is available at 
1198 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1199
1200 \end_inset
1201
1202 .
1203  Some of the other tools (simulator and assembler) included with SDCC contain
1204  their own documentation and can be found in the source distribution.
1205  If you want the latest unreleased software, the complete source package
1206  is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1207 sdcc/trunk/sdcc.
1208 \end_layout
1209
1210 \begin_layout Section
1211 Wishes for the future
1212 \end_layout
1213
1214 \begin_layout Standard
1215 There are (and always will be) some things that could be done.
1216  Here are some I can think of:
1217 \newline
1218
1219 \end_layout
1220
1221 \begin_layout Standard
1222
1223 \family typewriter
1224 char KernelFunction3(char p) at 0x340;
1225 \newline
1226
1227 \end_layout
1228
1229 \begin_layout Standard
1230
1231 \family typewriter
1232 better code banking
1233 \begin_inset LatexCommand \index{code banking (limited support)}
1234
1235 \end_inset
1236
1237  support for mcs51
1238 \newline
1239
1240 \newline
1241
1242 \family default
1243 If you can think of some more, please see the section 
1244 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1245
1246 \end_inset
1247
1248  about filing feature requests
1249 \begin_inset LatexCommand \index{Requesting features}
1250
1251 \end_inset
1252
1253
1254 \begin_inset LatexCommand \index{Feature request}
1255
1256 \end_inset
1257
1258 .
1259 \newline
1260
1261 \end_layout
1262
1263 \begin_layout Chapter
1264 Installing SDCC
1265 \begin_inset LatexCommand \index{Installation}
1266
1267 \end_inset
1268
1269
1270 \end_layout
1271
1272 \begin_layout Standard
1273 For most users it is sufficient to skip to either section 
1274 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1275
1276 \end_inset
1277
1278  (Unix) or section 
1279 \begin_inset LatexCommand \ref{sub:Windows-Install}
1280
1281 \end_inset
1282
1283  (Windows).
1284  More detailed instructions follow below.
1285 \end_layout
1286
1287 \begin_layout Section
1288 Configure Options
1289 \begin_inset LatexCommand \index{Options SDCC configuration}
1290
1291 \end_inset
1292
1293
1294 \end_layout
1295
1296 \begin_layout Standard
1297 The install paths, search paths and other options are defined when running
1298  'configure'.
1299  The defaults can be overridden by:
1300 \end_layout
1301
1302 \begin_layout List
1303 \labelwidthstring 00.00.0000
1304 -
1305 \begin_inset ERT
1306 status collapsed
1307
1308 \begin_layout Standard
1309
1310
1311 \backslash
1312 /
1313 \end_layout
1314
1315 \end_inset
1316
1317 -prefix see table below
1318 \end_layout
1319
1320 \begin_layout List
1321 \labelwidthstring 00.00.0000
1322 -
1323 \begin_inset ERT
1324 status collapsed
1325
1326 \begin_layout Standard
1327
1328
1329 \backslash
1330 /
1331 \end_layout
1332
1333 \end_inset
1334
1335 -exec_prefix see table below
1336 \end_layout
1337
1338 \begin_layout List
1339 \labelwidthstring 00.00.0000
1340 -
1341 \begin_inset ERT
1342 status collapsed
1343
1344 \begin_layout Standard
1345
1346
1347 \backslash
1348 /
1349 \end_layout
1350
1351 \end_inset
1352
1353 -bindir see table below
1354 \end_layout
1355
1356 \begin_layout List
1357 \labelwidthstring 00.00.0000
1358 -
1359 \begin_inset ERT
1360 status collapsed
1361
1362 \begin_layout Standard
1363
1364
1365 \backslash
1366 /
1367 \end_layout
1368
1369 \end_inset
1370
1371 -datadir see table below
1372 \end_layout
1373
1374 \begin_layout List
1375 \labelwidthstring 00.00.0000
1376 -
1377 \begin_inset ERT
1378 status collapsed
1379
1380 \begin_layout Standard
1381
1382
1383 \backslash
1384 /
1385 \end_layout
1386
1387 \end_inset
1388
1389 -datarootdir see table below
1390 \newline
1391
1392 \end_layout
1393
1394 \begin_layout List
1395 \labelwidthstring 00.00.0000
1396 \InsetSpace ~
1397 \InsetSpace ~
1398 docdir environment variable, see table below
1399 \end_layout
1400
1401 \begin_layout List
1402 \labelwidthstring 00.00.0000
1403 \InsetSpace ~
1404 \InsetSpace ~
1405 include_dir_suffix environment variable, see table below
1406 \end_layout
1407
1408 \begin_layout List
1409 \labelwidthstring 00.00.0000
1410 \InsetSpace ~
1411 \InsetSpace ~
1412 lib_dir_suffix environment variable, see table below
1413 \end_layout
1414
1415 \begin_layout List
1416 \labelwidthstring 00.00.0000
1417 \InsetSpace ~
1418 \InsetSpace ~
1419 sdccconf_h_dir_separator environment variable, either / or 
1420 \backslash
1421
1422 \backslash
1423  makes sense here.
1424  This character will only be used in sdccconf.h; don't forget it's a C-header,
1425  therefore a double-backslash is needed there.
1426 \newline
1427
1428 \end_layout
1429
1430 \begin_layout List
1431 \labelwidthstring 00.00.0000
1432 -
1433 \begin_inset ERT
1434 status collapsed
1435
1436 \begin_layout Standard
1437
1438
1439 \backslash
1440 /
1441 \end_layout
1442
1443 \end_inset
1444
1445 -disable-mcs51-port Excludes the Intel mcs51 port
1446 \end_layout
1447
1448 \begin_layout List
1449 \labelwidthstring 00.00.0000
1450 -
1451 \begin_inset ERT
1452 status collapsed
1453
1454 \begin_layout Standard
1455
1456
1457 \backslash
1458 /
1459 \end_layout
1460
1461 \end_inset
1462
1463 -disable-gbz80-port Excludes the Gameboy gbz80 port
1464 \end_layout
1465
1466 \begin_layout List
1467 \labelwidthstring 00.00.0000
1468 -
1469 \begin_inset ERT
1470 status collapsed
1471
1472 \begin_layout Standard
1473
1474
1475 \backslash
1476 /
1477 \end_layout
1478
1479 \end_inset
1480
1481 -disable-z80-port Excludes the z80 port
1482 \end_layout
1483
1484 \begin_layout List
1485 \labelwidthstring 00.00.0000
1486 -
1487 \begin_inset ERT
1488 status collapsed
1489
1490 \begin_layout Standard
1491
1492
1493 \backslash
1494 /
1495 \end_layout
1496
1497 \end_inset
1498
1499 -disable-avr-port Excludes the AVR port
1500 \end_layout
1501
1502 \begin_layout List
1503 \labelwidthstring 00.00.0000
1504 -
1505 \begin_inset ERT
1506 status collapsed
1507
1508 \begin_layout Standard
1509
1510
1511 \backslash
1512 /
1513 \end_layout
1514
1515 \end_inset
1516
1517 -disable-ds390-port Excludes the DS390 port
1518 \end_layout
1519
1520 \begin_layout List
1521 \labelwidthstring 00.00.0000
1522 -
1523 \begin_inset ERT
1524 status collapsed
1525
1526 \begin_layout Standard
1527
1528
1529 \backslash
1530 /
1531 \end_layout
1532
1533 \end_inset
1534
1535 -disable-hc08-port Excludes the HC08 port
1536 \end_layout
1537
1538 \begin_layout List
1539 \labelwidthstring 00.00.0000
1540 -
1541 \begin_inset ERT
1542 status collapsed
1543
1544 \begin_layout Standard
1545
1546
1547 \backslash
1548 /
1549 \end_layout
1550
1551 \end_inset
1552
1553 -disable-pic-port Excludes the PIC14 port
1554 \end_layout
1555
1556 \begin_layout List
1557 \labelwidthstring 00.00.0000
1558 -
1559 \begin_inset ERT
1560 status collapsed
1561
1562 \begin_layout Standard
1563
1564
1565 \backslash
1566 /
1567 \end_layout
1568
1569 \end_inset
1570
1571 -disable-pic16-port Excludes the PIC16 port
1572 \end_layout
1573
1574 \begin_layout List
1575 \labelwidthstring 00.00.0000
1576 -
1577 \begin_inset ERT
1578 status collapsed
1579
1580 \begin_layout Standard
1581
1582
1583 \backslash
1584 /
1585 \end_layout
1586
1587 \end_inset
1588
1589 -disable-xa51-port Excludes the XA51 port
1590 \end_layout
1591
1592 \begin_layout List
1593 \labelwidthstring 00.00.0000
1594 -
1595 \begin_inset ERT
1596 status collapsed
1597
1598 \begin_layout Standard
1599
1600
1601 \backslash
1602 /
1603 \end_layout
1604
1605 \end_inset
1606
1607 -disable-ucsim Disables configuring and building of ucsim
1608 \end_layout
1609
1610 \begin_layout List
1611 \labelwidthstring 00.00.0000
1612 -
1613 \begin_inset ERT
1614 status collapsed
1615
1616 \begin_layout Standard
1617
1618
1619 \backslash
1620 /
1621 \end_layout
1622
1623 \end_inset
1624
1625 -disable-device-lib Disables automatically building device libraries
1626 \end_layout
1627
1628 \begin_layout List
1629 \labelwidthstring 00.00.0000
1630 -
1631 \begin_inset ERT
1632 status collapsed
1633
1634 \begin_layout Standard
1635
1636
1637 \backslash
1638 /
1639 \end_layout
1640
1641 \end_inset
1642
1643 -disable-packihx Disables building packihx
1644 \newline
1645
1646 \end_layout
1647
1648 \begin_layout List
1649 \labelwidthstring 00.00.0000
1650 -
1651 \begin_inset ERT
1652 status collapsed
1653
1654 \begin_layout Standard
1655
1656
1657 \backslash
1658 /
1659 \end_layout
1660
1661 \end_inset
1662
1663 -enable-doc Build pdf, html and txt files from the lyx sources
1664 \end_layout
1665
1666 \begin_layout List
1667 \labelwidthstring 00.00.0000
1668 -
1669 \begin_inset ERT
1670 status collapsed
1671
1672 \begin_layout Standard
1673
1674
1675 \backslash
1676 /
1677 \end_layout
1678
1679 \end_inset
1680
1681 -enable-libgc Use the Bohem memory allocator.
1682  Lower runtime footprint.
1683 \end_layout
1684
1685 \begin_layout Standard
1686 Furthermore the environment variables CC, CFLAGS, ...
1687  the tools and their arguments can be influenced.
1688  Please see `configure -
1689 \begin_inset ERT
1690 status collapsed
1691
1692 \begin_layout Standard
1693
1694
1695 \backslash
1696 /
1697 \end_layout
1698
1699 \end_inset
1700
1701 -help' and the man/info pages of `configure' for details.
1702 \newline
1703
1704 \newline
1705 The names of the
1706  standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1707 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1708  SDCC_LIB_NAME are defined by `configure' too.
1709  At the moment it's not possible to change the default settings (it was
1710  simply never required).
1711 \newline
1712
1713 \newline
1714 These configure options are compiled into the binaries,
1715  and can only be changed by rerunning 'configure' and recompiling SDCC.
1716  The configure options are written in 
1717 \emph on
1718 italics
1719 \emph default
1720  to distinguish them from run time environment variables (see section search
1721  paths).
1722 \newline
1723
1724 \newline
1725 The settings for 
1726 \begin_inset Quotes sld
1727 \end_inset
1728
1729 Win32 builds
1730 \begin_inset Quotes srd
1731 \end_inset
1732
1733  are used by the SDCC team to build the official Win32 binaries.
1734  The SDCC team uses Mingw32 to build the official Windows binaries, because
1735  it's
1736 \end_layout
1737
1738 \begin_layout Enumerate
1739 open source, 
1740 \end_layout
1741
1742 \begin_layout Enumerate
1743 a gcc compiler and last but not least
1744 \end_layout
1745
1746 \begin_layout Enumerate
1747 the binaries can be built by cross compiling on SDCC Distributed Compile
1748  Farm.
1749 \end_layout
1750
1751 \begin_layout Standard
1752 See the examples, how to pass the Win32 settings to 'configure'.
1753  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1754  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1755  for Win32.
1756 \newline
1757
1758 \newline
1759 These defaults are:
1760 \newline
1761
1762 \end_layout
1763
1764 \begin_layout Standard
1765 \align center
1766 \begin_inset Tabular
1767 <lyxtabular version="3" rows="9" columns="3">
1768 <features>
1769 <column alignment="block" valignment="top" leftline="true" width="0in">
1770 <column alignment="block" valignment="top" leftline="true" width="0in">
1771 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1772 <row topline="true" bottomline="true">
1773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1774 \begin_inset Text
1775
1776 \begin_layout Standard
1777 Variable
1778 \end_layout
1779
1780 \end_inset
1781 </cell>
1782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1783 \begin_inset Text
1784
1785 \begin_layout Standard
1786 default
1787 \end_layout
1788
1789 \end_inset
1790 </cell>
1791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1792 \begin_inset Text
1793
1794 \begin_layout Standard
1795 Win32 builds
1796 \end_layout
1797
1798 \end_inset
1799 </cell>
1800 </row>
1801 <row topline="true">
1802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1803 \begin_inset Text
1804
1805 \begin_layout Standard
1806
1807 \emph on
1808 PREFIX
1809 \end_layout
1810
1811 \end_inset
1812 </cell>
1813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1814 \begin_inset Text
1815
1816 \begin_layout Standard
1817 /usr/local
1818 \end_layout
1819
1820 \end_inset
1821 </cell>
1822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1823 \begin_inset Text
1824
1825 \begin_layout Standard
1826
1827 \backslash
1828 sdcc
1829 \end_layout
1830
1831 \end_inset
1832 </cell>
1833 </row>
1834 <row topline="true">
1835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1836 \begin_inset Text
1837
1838 \begin_layout Standard
1839
1840 \emph on
1841 EXEC_PREFIX
1842 \end_layout
1843
1844 \end_inset
1845 </cell>
1846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1847 \begin_inset Text
1848
1849 \begin_layout Standard
1850
1851 \emph on
1852 $PREFIX
1853 \end_layout
1854
1855 \end_inset
1856 </cell>
1857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1858 \begin_inset Text
1859
1860 \begin_layout Standard
1861
1862 \emph on
1863 $PREFIX
1864 \end_layout
1865
1866 \end_inset
1867 </cell>
1868 </row>
1869 <row topline="true">
1870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1871 \begin_inset Text
1872
1873 \begin_layout Standard
1874
1875 \emph on
1876 BINDIR
1877 \end_layout
1878
1879 \end_inset
1880 </cell>
1881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1882 \begin_inset Text
1883
1884 \begin_layout Standard
1885
1886 \emph on
1887 $EXEC_PREFIX
1888 \emph default
1889 /bin
1890 \end_layout
1891
1892 \end_inset
1893 </cell>
1894 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1895 \begin_inset Text
1896
1897 \begin_layout Standard
1898
1899 \emph on
1900 $EXEC_PREFIX
1901 \emph default
1902
1903 \backslash
1904 bin
1905 \end_layout
1906
1907 \end_inset
1908 </cell>
1909 </row>
1910 <row topline="true">
1911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1912 \begin_inset Text
1913
1914 \begin_layout Standard
1915
1916 \emph on
1917 DATADIR
1918 \end_layout
1919
1920 \end_inset
1921 </cell>
1922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1923 \begin_inset Text
1924
1925 \begin_layout Standard
1926
1927 \emph on
1928 $DATAROOTDIR
1929 \end_layout
1930
1931 \end_inset
1932 </cell>
1933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1934 \begin_inset Text
1935
1936 \begin_layout Standard
1937
1938 \emph on
1939 $DATAROOTDIR
1940 \end_layout
1941
1942 \end_inset
1943 </cell>
1944 </row>
1945 <row topline="true">
1946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1947 \begin_inset Text
1948
1949 \begin_layout Standard
1950
1951 \emph on
1952 DATAROOTDIR
1953 \end_layout
1954
1955 \end_inset
1956 </cell>
1957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1958 \begin_inset Text
1959
1960 \begin_layout Standard
1961
1962 \emph on
1963 $PREFIX
1964 \emph default
1965 /share
1966 \end_layout
1967
1968 \end_inset
1969 </cell>
1970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1971 \begin_inset Text
1972
1973 \begin_layout Standard
1974
1975 \emph on
1976 $PREFIX
1977 \end_layout
1978
1979 \end_inset
1980 </cell>
1981 </row>
1982 <row topline="true">
1983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1984 \begin_inset Text
1985
1986 \begin_layout Standard
1987
1988 \emph on
1989 DOCDIR
1990 \end_layout
1991
1992 \end_inset
1993 </cell>
1994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1995 \begin_inset Text
1996
1997 \begin_layout Standard
1998
1999 \emph on
2000 $DATAROOTDIR
2001 \emph default
2002 /sdcc/doc
2003 \end_layout
2004
2005 \end_inset
2006 </cell>
2007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2008 \begin_inset Text
2009
2010 \begin_layout Standard
2011
2012 \emph on
2013 $DATAROOTDIR
2014 \emph default
2015
2016 \backslash
2017 doc
2018 \end_layout
2019
2020 \end_inset
2021 </cell>
2022 </row>
2023 <row topline="true">
2024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2025 \begin_inset Text
2026
2027 \begin_layout Standard
2028
2029 \emph on
2030 INCLUDE_DIR_SUFFIX
2031 \end_layout
2032
2033 \end_inset
2034 </cell>
2035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2036 \begin_inset Text
2037
2038 \begin_layout Standard
2039 sdcc/include
2040 \end_layout
2041
2042 \end_inset
2043 </cell>
2044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2045 \begin_inset Text
2046
2047 \begin_layout Standard
2048 include
2049 \end_layout
2050
2051 \end_inset
2052 </cell>
2053 </row>
2054 <row topline="true" bottomline="true">
2055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2056 \begin_inset Text
2057
2058 \begin_layout Standard
2059
2060 \emph on
2061 LIB_DIR_SUFFIX
2062 \end_layout
2063
2064 \end_inset
2065 </cell>
2066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2067 \begin_inset Text
2068
2069 \begin_layout Standard
2070 sdcc/lib
2071 \end_layout
2072
2073 \end_inset
2074 </cell>
2075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2076 \begin_inset Text
2077
2078 \begin_layout Standard
2079 lib
2080 \end_layout
2081
2082 \end_inset
2083 </cell>
2084 </row>
2085 </lyxtabular>
2086
2087 \end_inset
2088
2089
2090 \newline
2091
2092 \end_layout
2093
2094 \begin_layout Standard
2095 \noindent
2096 'configure' also computes relative paths.
2097  This is needed for full relocatability of a binary package and to complete
2098  search paths (see section search paths below):
2099 \newline
2100  
2101 \end_layout
2102
2103 \begin_layout Standard
2104 \align center
2105 \begin_inset Tabular
2106 <lyxtabular version="3" rows="4" columns="3">
2107 <features>
2108 <column alignment="block" valignment="top" leftline="true" width="0in">
2109 <column alignment="block" valignment="top" leftline="true" width="0in">
2110 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2111 <row topline="true" bottomline="true">
2112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2113 \begin_inset Text
2114
2115 \begin_layout Standard
2116 Variable (computed)
2117 \end_layout
2118
2119 \end_inset
2120 </cell>
2121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2122 \begin_inset Text
2123
2124 \begin_layout Standard
2125 default
2126 \end_layout
2127
2128 \end_inset
2129 </cell>
2130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2131 \begin_inset Text
2132
2133 \begin_layout Standard
2134 Win32 builds
2135 \end_layout
2136
2137 \end_inset
2138 </cell>
2139 </row>
2140 <row topline="true" bottomline="true">
2141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2142 \begin_inset Text
2143
2144 \begin_layout Standard
2145
2146 \emph on
2147 BIN2DATA_DIR
2148 \end_layout
2149
2150 \end_inset
2151 </cell>
2152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2153 \begin_inset Text
2154
2155 \begin_layout Standard
2156 ../share
2157 \end_layout
2158
2159 \end_inset
2160 </cell>
2161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2162 \begin_inset Text
2163
2164 \begin_layout Standard
2165 ..
2166 \end_layout
2167
2168 \end_inset
2169 </cell>
2170 </row>
2171 <row bottomline="true">
2172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2173 \begin_inset Text
2174
2175 \begin_layout Standard
2176
2177 \emph on
2178 PREFIX2BIN_DIR
2179 \end_layout
2180
2181 \end_inset
2182 </cell>
2183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2184 \begin_inset Text
2185
2186 \begin_layout Standard
2187 bin
2188 \end_layout
2189
2190 \end_inset
2191 </cell>
2192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2193 \begin_inset Text
2194
2195 \begin_layout Standard
2196 bin
2197 \end_layout
2198
2199 \end_inset
2200 </cell>
2201 </row>
2202 <row bottomline="true">
2203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2204 \begin_inset Text
2205
2206 \begin_layout Standard
2207
2208 \emph on
2209 PREFIX2DATA_DIR
2210 \end_layout
2211
2212 \end_inset
2213 </cell>
2214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2215 \begin_inset Text
2216
2217 \begin_layout Standard
2218 share/sdcc
2219 \end_layout
2220
2221 \end_inset
2222 </cell>
2223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2224 \begin_inset Text
2225
2226 \begin_layout Standard
2227
2228 \end_layout
2229
2230 \end_inset
2231 </cell>
2232 </row>
2233 </lyxtabular>
2234
2235 \end_inset
2236
2237
2238 \newline
2239
2240 \end_layout
2241
2242 \begin_layout Standard
2243 \noindent
2244 Examples:
2245 \end_layout
2246
2247 \begin_layout LyX-Code
2248 ./configure
2249 \newline
2250 ./configure -
2251 \begin_inset ERT
2252 status collapsed
2253
2254 \begin_layout Standard
2255
2256
2257 \backslash
2258 /
2259 \end_layout
2260
2261 \end_inset
2262
2263 -prefix=
2264 \begin_inset Quotes srd
2265 \end_inset
2266
2267 /usr/bin
2268 \begin_inset Quotes srd
2269 \end_inset
2270
2271  -
2272 \begin_inset ERT
2273 status collapsed
2274
2275 \begin_layout Standard
2276
2277
2278 \backslash
2279 /
2280 \end_layout
2281
2282 \end_inset
2283
2284 -datarootdir=
2285 \begin_inset Quotes srd
2286 \end_inset
2287
2288 /usr/share
2289 \begin_inset Quotes srd
2290 \end_inset
2291
2292
2293 \newline
2294 ./configure -
2295 \begin_inset ERT
2296 status collapsed
2297
2298 \begin_layout Standard
2299
2300
2301 \backslash
2302 /
2303 \end_layout
2304
2305 \end_inset
2306
2307 -disable-avr-port -
2308 \begin_inset ERT
2309 status collapsed
2310
2311 \begin_layout Standard
2312
2313
2314 \backslash
2315 /
2316 \end_layout
2317
2318 \end_inset
2319
2320 -disable-xa51-port
2321 \end_layout
2322
2323 \begin_layout Standard
2324 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2325 32'):
2326 \end_layout
2327
2328 \begin_layout LyX-Code
2329 ./configure 
2330 \backslash
2331
2332 \newline
2333 CC=
2334 \begin_inset Quotes srd
2335 \end_inset
2336
2337 i586-mingw32msvc-gcc
2338 \begin_inset Quotes srd
2339 \end_inset
2340
2341  CXX=
2342 \begin_inset Quotes srd
2343 \end_inset
2344
2345 i586-mingw32msvc-g++
2346 \begin_inset Quotes srd
2347 \end_inset
2348
2349  
2350 \backslash
2351  
2352 \newline
2353 RANLIB=
2354 \begin_inset Quotes srd
2355 \end_inset
2356
2357 i586-mingw32msvc-ranlib
2358 \begin_inset Quotes srd
2359 \end_inset
2360
2361  
2362 \backslash
2363
2364 \newline
2365 STRIP=
2366 \begin_inset Quotes srd
2367 \end_inset
2368
2369 i586-mingw32msvc-strip
2370 \begin_inset Quotes srd
2371 \end_inset
2372
2373  
2374 \backslash
2375
2376 \newline
2377 -
2378 \begin_inset ERT
2379 status collapsed
2380
2381 \begin_layout Standard
2382
2383
2384 \backslash
2385 /
2386 \end_layout
2387
2388 \end_inset
2389
2390 -prefix=
2391 \begin_inset Quotes srd
2392 \end_inset
2393
2394 /sdcc
2395 \begin_inset Quotes srd
2396 \end_inset
2397
2398  
2399 \backslash
2400
2401 \newline
2402 -
2403 \begin_inset ERT
2404 status collapsed
2405
2406 \begin_layout Standard
2407
2408
2409 \backslash
2410 /
2411 \end_layout
2412
2413 \end_inset
2414
2415 -datarootdir=
2416 \begin_inset Quotes srd
2417 \end_inset
2418
2419 /sdcc
2420 \begin_inset Quotes srd
2421 \end_inset
2422
2423  
2424 \backslash
2425
2426 \newline
2427 docdir=
2428 \begin_inset Quotes srd
2429 \end_inset
2430
2431
2432 \backslash
2433 ${datarootdir}/doc
2434 \begin_inset Quotes srd
2435 \end_inset
2436
2437  
2438 \backslash
2439
2440 \newline
2441 include_dir_suffix=
2442 \begin_inset Quotes srd
2443 \end_inset
2444
2445 include
2446 \begin_inset Quotes srd
2447 \end_inset
2448
2449  
2450 \backslash
2451
2452 \newline
2453 lib_dir_suffix=
2454 \begin_inset Quotes srd
2455 \end_inset
2456
2457 lib
2458 \begin_inset Quotes srd
2459 \end_inset
2460
2461  
2462 \backslash
2463
2464 \newline
2465 sdccconf_h_dir_separator=
2466 \begin_inset Quotes srd
2467 \end_inset
2468
2469
2470 \backslash
2471
2472 \backslash
2473
2474 \backslash
2475
2476 \backslash
2477
2478 \begin_inset Quotes srd
2479 \end_inset
2480
2481  
2482 \backslash
2483
2484 \newline
2485 -
2486 \begin_inset ERT
2487 status collapsed
2488
2489 \begin_layout Standard
2490
2491
2492 \backslash
2493 /
2494 \end_layout
2495
2496 \end_inset
2497
2498 -disable-device-lib
2499 \backslash
2500
2501 \newline
2502 -
2503 \begin_inset ERT
2504 status collapsed
2505
2506 \begin_layout Standard
2507
2508
2509 \backslash
2510 /
2511 \end_layout
2512
2513 \end_inset
2514
2515 -host=i586-mingw32msvc
2516 \backslash
2517
2518 \newline
2519 -
2520 \begin_inset ERT
2521 status collapsed
2522
2523 \begin_layout Standard
2524
2525
2526 \backslash
2527 /
2528 \end_layout
2529
2530 \end_inset
2531
2532 -build=unknown-unknown-linux-gnu
2533 \end_layout
2534
2535 \begin_layout Standard
2536 To 
2537 \begin_inset Quotes sld
2538 \end_inset
2539
2540 cross
2541 \begin_inset Quotes srd
2542 \end_inset
2543
2544 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2545 ):
2546 \end_layout
2547
2548 \begin_layout LyX-Code
2549 ./configure -C 
2550 \backslash
2551
2552 \newline
2553 -
2554 \begin_inset ERT
2555 status collapsed
2556
2557 \begin_layout Standard
2558
2559
2560 \backslash
2561 /
2562 \end_layout
2563
2564 \end_inset
2565
2566 -prefix=
2567 \begin_inset Quotes srd
2568 \end_inset
2569
2570 /sdcc
2571 \begin_inset Quotes srd
2572 \end_inset
2573
2574  
2575 \backslash
2576
2577 \newline
2578 -
2579 \begin_inset ERT
2580 status collapsed
2581
2582 \begin_layout Standard
2583
2584
2585 \backslash
2586 /
2587 \end_layout
2588
2589 \end_inset
2590
2591 -datarootdir=
2592 \begin_inset Quotes srd
2593 \end_inset
2594
2595 /sdcc
2596 \begin_inset Quotes srd
2597 \end_inset
2598
2599  
2600 \backslash
2601
2602 \newline
2603 docdir=
2604 \begin_inset Quotes srd
2605 \end_inset
2606
2607
2608 \backslash
2609 ${datarootdir}/doc
2610 \begin_inset Quotes srd
2611 \end_inset
2612
2613  
2614 \backslash
2615  
2616 \newline
2617 include_dir_suffix=
2618 \begin_inset Quotes srd
2619 \end_inset
2620
2621 include
2622 \begin_inset Quotes srd
2623 \end_inset
2624
2625  
2626 \backslash
2627
2628 \newline
2629 lib_dir_suffix=
2630 \begin_inset Quotes srd
2631 \end_inset
2632
2633 lib
2634 \begin_inset Quotes srd
2635 \end_inset
2636
2637  
2638 \backslash
2639
2640 \newline
2641 sdccconf_h_dir_separator=
2642 \begin_inset Quotes srd
2643 \end_inset
2644
2645
2646 \backslash
2647
2648 \backslash
2649
2650 \backslash
2651
2652 \backslash
2653
2654 \begin_inset Quotes srd
2655 \end_inset
2656
2657  
2658 \backslash
2659
2660 \newline
2661 CC=
2662 \begin_inset Quotes srd
2663 \end_inset
2664
2665 gcc -mno-cygwin
2666 \begin_inset Quotes srd
2667 \end_inset
2668
2669  
2670 \backslash
2671
2672 \newline
2673 CXX=
2674 \begin_inset Quotes srd
2675 \end_inset
2676
2677 g++ -mno-cygwin
2678 \begin_inset Quotes srd
2679 \end_inset
2680
2681  
2682 \end_layout
2683
2684 \begin_layout Standard
2685 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2686  The option '-
2687 \begin_inset ERT
2688 status collapsed
2689
2690 \begin_layout Standard
2691
2692
2693 \backslash
2694 /
2695 \end_layout
2696
2697 \end_inset
2698
2699 -C' turns on caching, which gives a little bit extra speed.
2700  However if options are changed, it can be necessary to delete the config.cache
2701  file.
2702 \end_layout
2703
2704 \begin_layout Section
2705 Install paths
2706 \begin_inset LatexCommand \label{sub:Install-paths}
2707
2708 \end_inset
2709
2710
2711 \begin_inset LatexCommand \index{Install paths}
2712
2713 \end_inset
2714
2715
2716 \end_layout
2717
2718 \begin_layout Standard
2719 \begin_inset VSpace medskip
2720 \end_inset
2721
2722
2723 \end_layout
2724
2725 \begin_layout Standard
2726 \align center
2727 \begin_inset Tabular
2728 <lyxtabular version="3" rows="5" columns="4">
2729 <features>
2730 <column alignment="left" valignment="top" leftline="true" width="0">
2731 <column alignment="left" valignment="top" leftline="true" width="0">
2732 <column alignment="left" valignment="top" leftline="true" width="0">
2733 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2734 <row topline="true" bottomline="true">
2735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2736 \begin_inset Text
2737
2738 \begin_layout Standard
2739
2740 \series bold
2741 Description
2742 \end_layout
2743
2744 \end_inset
2745 </cell>
2746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2747 \begin_inset Text
2748
2749 \begin_layout Standard
2750
2751 \series bold
2752 Path
2753 \end_layout
2754
2755 \end_inset
2756 </cell>
2757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2758 \begin_inset Text
2759
2760 \begin_layout Standard
2761
2762 \series bold
2763 Default
2764 \end_layout
2765
2766 \end_inset
2767 </cell>
2768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2769 \begin_inset Text
2770
2771 \begin_layout Standard
2772
2773 \series bold
2774 Win32 builds
2775 \end_layout
2776
2777 \end_inset
2778 </cell>
2779 </row>
2780 <row topline="true">
2781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2782 \begin_inset Text
2783
2784 \begin_layout Standard
2785 Binary files*
2786 \end_layout
2787
2788 \end_inset
2789 </cell>
2790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2791 \begin_inset Text
2792
2793 \begin_layout Standard
2794
2795 \emph on
2796 $EXEC_PREFIX
2797 \end_layout
2798
2799 \end_inset
2800 </cell>
2801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2802 \begin_inset Text
2803
2804 \begin_layout Standard
2805 /usr/local/bin
2806 \end_layout
2807
2808 \end_inset
2809 </cell>
2810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2811 \begin_inset Text
2812
2813 \begin_layout Standard
2814
2815 \backslash
2816 sdcc
2817 \backslash
2818 bin
2819 \end_layout
2820
2821 \end_inset
2822 </cell>
2823 </row>
2824 <row topline="true">
2825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2826 \begin_inset Text
2827
2828 \begin_layout Standard
2829 Include files
2830 \end_layout
2831
2832 \end_inset
2833 </cell>
2834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2835 \begin_inset Text
2836
2837 \begin_layout Standard
2838
2839 \emph on
2840 $DATADIR/ $INCLUDE_DIR_SUFFIX
2841 \end_layout
2842
2843 \end_inset
2844 </cell>
2845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2846 \begin_inset Text
2847
2848 \begin_layout Standard
2849 /usr/local/share/sdcc/include
2850 \end_layout
2851
2852 \end_inset
2853 </cell>
2854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2855 \begin_inset Text
2856
2857 \begin_layout Standard
2858
2859 \backslash
2860 sdcc
2861 \backslash
2862 include
2863 \end_layout
2864
2865 \end_inset
2866 </cell>
2867 </row>
2868 <row topline="true">
2869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2870 \begin_inset Text
2871
2872 \begin_layout Standard
2873 Library file**
2874 \end_layout
2875
2876 \end_inset
2877 </cell>
2878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2879 \begin_inset Text
2880
2881 \begin_layout Standard
2882
2883 \emph on
2884 $DATADIR/$LIB_DIR_SUFFIX
2885 \end_layout
2886
2887 \end_inset
2888 </cell>
2889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2890 \begin_inset Text
2891
2892 \begin_layout Standard
2893 /usr/local/share/sdcc/lib
2894 \end_layout
2895
2896 \end_inset
2897 </cell>
2898 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2899 \begin_inset Text
2900
2901 \begin_layout Standard
2902
2903 \backslash
2904 sdcc
2905 \backslash
2906 lib
2907 \end_layout
2908
2909 \end_inset
2910 </cell>
2911 </row>
2912 <row topline="true" bottomline="true">
2913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2914 \begin_inset Text
2915
2916 \begin_layout Standard
2917 Documentation
2918 \end_layout
2919
2920 \end_inset
2921 </cell>
2922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2923 \begin_inset Text
2924
2925 \begin_layout Standard
2926
2927 \emph on
2928 $DOCDIR
2929 \end_layout
2930
2931 \end_inset
2932 </cell>
2933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2934 \begin_inset Text
2935
2936 \begin_layout Standard
2937 /usr/local/share/sdcc/doc
2938 \end_layout
2939
2940 \end_inset
2941 </cell>
2942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2943 \begin_inset Text
2944
2945 \begin_layout Standard
2946
2947 \backslash
2948 sdcc
2949 \backslash
2950 doc
2951 \end_layout
2952
2953 \end_inset
2954 </cell>
2955 </row>
2956 </lyxtabular>
2957
2958 \end_inset
2959
2960
2961 \end_layout
2962
2963 \begin_layout Verse
2964
2965 \size footnotesize
2966 *compiler, preprocessor, assembler, and linker
2967 \newline
2968 **the 
2969 \shape italic
2970 model
2971 \shape default
2972  is auto-appended by the compiler, e.g.
2973  small, large, z80, ds390 etc
2974 \end_layout
2975
2976 \begin_layout Standard
2977 \noindent
2978 The install paths can still be changed during `make install' with e.g.:
2979 \end_layout
2980
2981 \begin_layout LyX-Code
2982 make install prefix=$(HOME)/local/sdcc
2983 \end_layout
2984
2985 \begin_layout Standard
2986 Of course this doesn't change the search paths compiled into the binaries.
2987 \newline
2988
2989 \newline
2990 Moreove
2991 r the install path can be changed by defining DESTDIR
2992 \begin_inset LatexCommand \index{DESTDIR}
2993
2994 \end_inset
2995
2996 :
2997 \end_layout
2998
2999 \begin_layout LyX-Code
3000 make install DESTDIR=$(HOME)/sdcc.rpm/
3001 \end_layout
3002
3003 \begin_layout Standard
3004 Please note that DESTDIR must have a trailing slash!
3005 \end_layout
3006
3007 \begin_layout Section
3008 Search Paths
3009 \begin_inset LatexCommand \label{sub:Search-Paths}
3010
3011 \end_inset
3012
3013
3014 \begin_inset LatexCommand \index{Search path}
3015
3016 \end_inset
3017
3018
3019 \end_layout
3020
3021 \begin_layout Standard
3022 Some search paths or parts of them are determined by configure variables
3023  (in 
3024 \emph on
3025 italics
3026 \emph default
3027 , see section above).
3028  Further search paths are determined by environment variables during runtime.
3029  
3030 \newline
3031 The paths searched when running the compiler are as follows (the first
3032  catch wins):
3033 \newline
3034
3035 \newline
3036 1.
3037  Binary files (preprocessor, assembler and linker)
3038 \newline
3039
3040 \end_layout
3041
3042 \begin_layout Standard
3043 \align center
3044 \begin_inset Tabular
3045 <lyxtabular version="3" rows="4" columns="3">
3046 <features>
3047 <column alignment="block" valignment="top" leftline="true" width="0in">
3048 <column alignment="block" valignment="top" leftline="true" width="0in">
3049 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3050 <row topline="true" bottomline="true">
3051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3052 \begin_inset Text
3053
3054 \begin_layout Standard
3055 Search path
3056 \end_layout
3057
3058 \end_inset
3059 </cell>
3060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3061 \begin_inset Text
3062
3063 \begin_layout Standard
3064 default
3065 \end_layout
3066
3067 \end_inset
3068 </cell>
3069 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3070 \begin_inset Text
3071
3072 \begin_layout Standard
3073 Win32 builds
3074 \end_layout
3075
3076 \end_inset
3077 </cell>
3078 </row>
3079 <row topline="true">
3080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3081 \begin_inset Text
3082
3083 \begin_layout Standard
3084 $SDCC_HOME/
3085 \emph on
3086 $PPREFIX2BIN_DIR
3087 \end_layout
3088
3089 \end_inset
3090 </cell>
3091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3092 \begin_inset Text
3093
3094 \begin_layout Standard
3095 $SDCC_HOME/bin
3096 \end_layout
3097
3098 \end_inset
3099 </cell>
3100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3101 \begin_inset Text
3102
3103 \begin_layout Standard
3104 $SDCC_HOME
3105 \backslash
3106 bin
3107 \end_layout
3108
3109 \end_inset
3110 </cell>
3111 </row>
3112 <row topline="true">
3113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3114 \begin_inset Text
3115
3116 \begin_layout Standard
3117 Path of argv[0] (if available)
3118 \end_layout
3119
3120 \end_inset
3121 </cell>
3122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3123 \begin_inset Text
3124
3125 \begin_layout Standard
3126 Path of argv[0]
3127 \end_layout
3128
3129 \end_inset
3130 </cell>
3131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3132 \begin_inset Text
3133
3134 \begin_layout Standard
3135 Path of argv[0]
3136 \end_layout
3137
3138 \end_inset
3139 </cell>
3140 </row>
3141 <row topline="true" bottomline="true">
3142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3143 \begin_inset Text
3144
3145 \begin_layout Standard
3146 $PATH
3147 \end_layout
3148
3149 \end_inset
3150 </cell>
3151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3152 \begin_inset Text
3153
3154 \begin_layout Standard
3155 $PATH
3156 \end_layout
3157
3158 \end_inset
3159 </cell>
3160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3161 \begin_inset Text
3162
3163 \begin_layout Standard
3164 $PATH
3165 \end_layout
3166
3167 \end_inset
3168 </cell>
3169 </row>
3170 </lyxtabular>
3171
3172 \end_inset
3173
3174  
3175 \newline
3176
3177 \end_layout
3178
3179 \begin_layout Standard
3180 \noindent
3181 2.
3182  Include files
3183 \newline
3184
3185 \end_layout
3186
3187 \begin_layout Standard
3188 \align center
3189 \begin_inset Tabular
3190 <lyxtabular version="3" rows="6" columns="3">
3191 <features>
3192 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3193 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3194 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3195 <row topline="true" bottomline="true">
3196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3197 \begin_inset Text
3198
3199 \begin_layout Standard
3200 Search path
3201 \end_layout
3202
3203 \end_inset
3204 </cell>
3205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3206 \begin_inset Text
3207
3208 \begin_layout Standard
3209 default
3210 \end_layout
3211
3212 \end_inset
3213 </cell>
3214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3215 \begin_inset Text
3216
3217 \begin_layout Standard
3218 Win32 builds
3219 \end_layout
3220
3221 \end_inset
3222 </cell>
3223 </row>
3224 <row topline="true">
3225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3226 \begin_inset Text
3227
3228 \begin_layout Standard
3229 -
3230 \begin_inset ERT
3231 status collapsed
3232
3233 \begin_layout Standard
3234
3235
3236 \backslash
3237 /
3238 \end_layout
3239
3240 \end_inset
3241
3242 -I dir
3243 \end_layout
3244
3245 \end_inset
3246 </cell>
3247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3248 \begin_inset Text
3249
3250 \begin_layout Standard
3251 -
3252 \begin_inset ERT
3253 status collapsed
3254
3255 \begin_layout Standard
3256
3257
3258 \backslash
3259 /
3260 \end_layout
3261
3262 \end_inset
3263
3264 -I dir
3265 \end_layout
3266
3267 \end_inset
3268 </cell>
3269 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3270 \begin_inset Text
3271
3272 \begin_layout Standard
3273 -
3274 \begin_inset ERT
3275 status collapsed
3276
3277 \begin_layout Standard
3278
3279
3280 \backslash
3281 /
3282 \end_layout
3283
3284 \end_inset
3285
3286 -I dir
3287 \end_layout
3288
3289 \end_inset
3290 </cell>
3291 </row>
3292 <row topline="true">
3293 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3294 \begin_inset Text
3295
3296 \begin_layout Standard
3297 $SDCC_INCLUDE
3298 \end_layout
3299
3300 \end_inset
3301 </cell>
3302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3303 \begin_inset Text
3304
3305 \begin_layout Standard
3306 $SDCC_INCLUDE
3307 \end_layout
3308
3309 \end_inset
3310 </cell>
3311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3312 \begin_inset Text
3313
3314 \begin_layout Standard
3315 $SDCC_INCLUDE
3316 \end_layout
3317
3318 \end_inset
3319 </cell>
3320 </row>
3321 <row topline="true">
3322 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3323 \begin_inset Text
3324
3325 \begin_layout Standard
3326 $SDCC_HOME/
3327 \newline
3328
3329 \emph on
3330 $PREFIX2DATA_DIR/
3331 \newline
3332 $INCLUDE_DIR_SUFFIX
3333 \end_layout
3334
3335 \end_inset
3336 </cell>
3337 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3338 \begin_inset Text
3339
3340 \begin_layout Standard
3341 $SDCC_ HOME/
3342 \newline
3343 share/sdcc/
3344 \newline
3345 include
3346 \end_layout
3347
3348 \end_inset
3349 </cell>
3350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3351 \begin_inset Text
3352
3353 \begin_layout Standard
3354 $SDCC_HOME
3355 \backslash
3356 include
3357 \end_layout
3358
3359 \end_inset
3360 </cell>
3361 </row>
3362 <row topline="true">
3363 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3364 \begin_inset Text
3365
3366 \begin_layout Standard
3367 path(argv[0])/
3368 \newline
3369
3370 \emph on
3371 $BIN2DATADIR/
3372 \emph default
3373
3374 \newline
3375
3376 \emph on
3377 $INCLUDE_DIR_SUFFIX
3378 \end_layout
3379
3380 \end_inset
3381 </cell>
3382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3383 \begin_inset Text
3384
3385 \begin_layout Standard
3386 path(argv[0])/
3387 \newline
3388 ../sdcc/include
3389 \newline
3390 \InsetSpace ~
3391 \InsetSpace ~
3392 \InsetSpace ~
3393 \InsetSpace ~
3394 \InsetSpace ~
3395 \InsetSpace ~
3396 \InsetSpace ~
3397 \InsetSpace ~
3398 \InsetSpace ~
3399 \InsetSpace ~
3400 \InsetSpace ~
3401 \InsetSpace ~
3402 \InsetSpace ~
3403 \InsetSpace ~
3404 \InsetSpace ~
3405 \InsetSpace ~
3406 \InsetSpace ~
3407 \InsetSpace ~
3408 \InsetSpace ~
3409 \InsetSpace ~
3410 \InsetSpace ~
3411 \InsetSpace ~
3412 \InsetSpace ~
3413 \InsetSpace ~
3414 \InsetSpace ~
3415 \InsetSpace ~
3416 \InsetSpace ~
3417 \InsetSpace ~
3418 \InsetSpace ~
3419 \InsetSpace ~
3420 \InsetSpace ~
3421 \InsetSpace ~
3422 \InsetSpace ~
3423 \InsetSpace ~
3424 \InsetSpace ~
3425 \InsetSpace ~
3426 \InsetSpace ~
3427 \InsetSpace ~
3428
3429 \end_layout
3430
3431 \end_inset
3432 </cell>
3433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3434 \begin_inset Text
3435
3436 \begin_layout Standard
3437 path(argv[0])
3438 \backslash
3439 ..
3440 \backslash
3441 include
3442 \end_layout
3443
3444 \end_inset
3445 </cell>
3446 </row>
3447 <row topline="true" bottomline="true">
3448 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3449 \begin_inset Text
3450
3451 \begin_layout Standard
3452
3453 \emph on
3454 $DATADIR/
3455 \emph default
3456
3457 \newline
3458
3459 \emph on
3460 $INCLUDE_DIR_SUFFIX
3461 \end_layout
3462
3463 \end_inset
3464 </cell>
3465 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3466 \begin_inset Text
3467
3468 \begin_layout Standard
3469 /usr/local/share/sdcc/
3470 \newline
3471 include
3472 \end_layout
3473
3474 \end_inset
3475 </cell>
3476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3477 \begin_inset Text
3478
3479 \begin_layout Standard
3480 (not on Win32)
3481 \end_layout
3482
3483 \end_inset
3484 </cell>
3485 </row>
3486 </lyxtabular>
3487
3488 \end_inset
3489
3490  
3491 \newline
3492
3493 \end_layout
3494
3495 \begin_layout Standard
3496 \noindent
3497 The option -
3498 \begin_inset ERT
3499 status collapsed
3500
3501 \begin_layout Standard
3502
3503
3504 \backslash
3505 /
3506 \end_layout
3507
3508 \end_inset
3509
3510 -nostdinc disables the last two search paths.
3511 \newline
3512
3513 \newline
3514 3.
3515  Library files 
3516 \newline
3517
3518 \end_layout
3519
3520 \begin_layout Standard
3521 With the exception of 
3522 \begin_inset Quotes sld
3523 \end_inset
3524
3525 -
3526 \begin_inset ERT
3527 status collapsed
3528
3529 \begin_layout Standard
3530
3531
3532 \backslash
3533 /
3534 \end_layout
3535
3536 \end_inset
3537
3538 -L dir
3539 \begin_inset Quotes srd
3540 \end_inset
3541
3542  the 
3543 \shape italic
3544 model
3545 \shape default
3546  is auto-appended by the compiler (e.g.
3547  small, large, z80, ds390 etc.).
3548  
3549 \newline
3550
3551 \end_layout
3552
3553 \begin_layout Standard
3554 \align center
3555 \begin_inset Tabular
3556 <lyxtabular version="3" rows="6" columns="3">
3557 <features>
3558 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3559 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3560 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3561 <row topline="true" bottomline="true">
3562 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3563 \begin_inset Text
3564
3565 \begin_layout Standard
3566 Search path
3567 \end_layout
3568
3569 \end_inset
3570 </cell>
3571 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3572 \begin_inset Text
3573
3574 \begin_layout Standard
3575 default
3576 \end_layout
3577
3578 \end_inset
3579 </cell>
3580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3581 \begin_inset Text
3582
3583 \begin_layout Standard
3584 Win32 builds
3585 \end_layout
3586
3587 \end_inset
3588 </cell>
3589 </row>
3590 <row topline="true">
3591 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3592 \begin_inset Text
3593
3594 \begin_layout Standard
3595 -
3596 \begin_inset ERT
3597 status collapsed
3598
3599 \begin_layout Standard
3600
3601
3602 \backslash
3603 /
3604 \end_layout
3605
3606 \end_inset
3607
3608 -L dir
3609 \end_layout
3610
3611 \end_inset
3612 </cell>
3613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3614 \begin_inset Text
3615
3616 \begin_layout Standard
3617 -
3618 \begin_inset ERT
3619 status collapsed
3620
3621 \begin_layout Standard
3622
3623
3624 \backslash
3625 /
3626 \end_layout
3627
3628 \end_inset
3629
3630 -L dir
3631 \end_layout
3632
3633 \end_inset
3634 </cell>
3635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3636 \begin_inset Text
3637
3638 \begin_layout Standard
3639 -
3640 \begin_inset ERT
3641 status collapsed
3642
3643 \begin_layout Standard
3644
3645
3646 \backslash
3647 /
3648 \end_layout
3649
3650 \end_inset
3651
3652 -L dir
3653 \end_layout
3654
3655 \end_inset
3656 </cell>
3657 </row>
3658 <row topline="true">
3659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3660 \begin_inset Text
3661
3662 \begin_layout Standard
3663 $SDCC_LIB/
3664 \newline
3665
3666 \emph on
3667 <model>
3668 \end_layout
3669
3670 \end_inset
3671 </cell>
3672 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3673 \begin_inset Text
3674
3675 \begin_layout Standard
3676 $SDCC_LIB/
3677 \newline
3678
3679 \emph on
3680 <model>
3681 \end_layout
3682
3683 \end_inset
3684 </cell>
3685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3686 \begin_inset Text
3687
3688 \begin_layout Standard
3689 $SDCC_LIB
3690 \backslash
3691
3692 \newline
3693
3694 \emph on
3695 <model>
3696 \end_layout
3697
3698 \end_inset
3699 </cell>
3700 </row>
3701 <row topline="true">
3702 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3703 \begin_inset Text
3704
3705 \begin_layout Standard
3706 $SDCC_HOME/
3707 \newline
3708
3709 \emph on
3710 $PREFIX2DATA_DIR/
3711 \newline
3712 $LIB_DIR_SUFFIX/<model>
3713 \end_layout
3714
3715 \end_inset
3716 </cell>
3717 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3718 \begin_inset Text
3719
3720 \begin_layout Standard
3721 $SDCC_HOME/
3722 \newline
3723 share/sdcc/
3724 \newline
3725 lib/
3726 \emph on
3727 <model>
3728 \end_layout
3729
3730 \end_inset
3731 </cell>
3732 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3733 \begin_inset Text
3734
3735 \begin_layout Standard
3736 $SDCC_HOME
3737 \backslash
3738 lib
3739 \backslash
3740
3741 \emph on
3742
3743 \newline
3744 <model>
3745 \end_layout
3746
3747 \end_inset
3748 </cell>
3749 </row>
3750 <row topline="true">
3751 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3752 \begin_inset Text
3753
3754 \begin_layout Standard
3755 path(argv[0])/
3756 \newline
3757
3758 \emph on
3759 $BIN2DATADIR/
3760 \emph default
3761
3762 \newline
3763
3764 \emph on
3765 $LIB_DIR_SUFFIX/<model>
3766 \end_layout
3767
3768 \end_inset
3769 </cell>
3770 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3771 \begin_inset Text
3772
3773 \begin_layout Standard
3774 path(argv[0])/
3775 \newline
3776 ../sdcc/lib/
3777 \emph on
3778 <model>
3779 \newline
3780 \InsetSpace ~
3781 \InsetSpace ~
3782 \InsetSpace ~
3783 \InsetSpace ~
3784 \InsetSpace ~
3785 \InsetSpace ~
3786 \InsetSpace ~
3787 \InsetSpace ~
3788 \InsetSpace ~
3789 \InsetSpace ~
3790 \InsetSpace ~
3791 \InsetSpace ~
3792 \InsetSpace ~
3793 \InsetSpace ~
3794 \InsetSpace ~
3795 \InsetSpace ~
3796 \InsetSpace ~
3797 \InsetSpace ~
3798 \InsetSpace ~
3799 \InsetSpace ~
3800 \InsetSpace ~
3801 \InsetSpace ~
3802 \InsetSpace ~
3803 \InsetSpace ~
3804 \InsetSpace ~
3805 \InsetSpace ~
3806 \InsetSpace ~
3807 \InsetSpace ~
3808 \InsetSpace ~
3809 \InsetSpace ~
3810 \InsetSpace ~
3811 \InsetSpace ~
3812 \InsetSpace ~
3813 \InsetSpace ~
3814 \InsetSpace ~
3815 \InsetSpace ~
3816 \InsetSpace ~
3817 \InsetSpace ~
3818 \InsetSpace ~
3819
3820 \end_layout
3821
3822 \end_inset
3823 </cell>
3824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3825 \begin_inset Text
3826
3827 \begin_layout Standard
3828 path(argv[0])
3829 \backslash
3830
3831 \newline
3832 ..
3833 \backslash
3834 lib
3835 \backslash
3836
3837 \emph on
3838 <model>
3839 \newline
3840 \InsetSpace ~
3841 \InsetSpace ~
3842 \InsetSpace ~
3843 \InsetSpace ~
3844 \InsetSpace ~
3845 \InsetSpace ~
3846 \InsetSpace ~
3847 \InsetSpace ~
3848 \InsetSpace ~
3849 \InsetSpace ~
3850 \InsetSpace ~
3851 \InsetSpace ~
3852 \InsetSpace ~
3853 \InsetSpace ~
3854 \InsetSpace ~
3855 \InsetSpace ~
3856 \InsetSpace ~
3857 \InsetSpace ~
3858 \InsetSpace ~
3859 \InsetSpace ~
3860 \InsetSpace ~
3861 \InsetSpace ~
3862 \InsetSpace ~
3863 \InsetSpace ~
3864 \InsetSpace ~
3865 \InsetSpace ~
3866 \InsetSpace ~
3867 \InsetSpace ~
3868 \InsetSpace ~
3869 \InsetSpace ~
3870 \InsetSpace ~
3871 \InsetSpace ~
3872 \InsetSpace ~
3873 \InsetSpace ~
3874 \InsetSpace ~
3875
3876 \end_layout
3877
3878 \end_inset
3879 </cell>
3880 </row>
3881 <row topline="true" bottomline="true">
3882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3883 \begin_inset Text
3884
3885 \begin_layout Standard
3886
3887 \emph on
3888 $DATADIR/
3889 \newline
3890 $LIB_DIR_SUFFIX/<model>
3891 \end_layout
3892
3893 \end_inset
3894 </cell>
3895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3896 \begin_inset Text
3897
3898 \begin_layout Standard
3899 /usr/local/share/sdcc/
3900 \newline
3901 lib/
3902 \emph on
3903 <model>
3904 \end_layout
3905
3906 \end_inset
3907 </cell>
3908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3909 \begin_inset Text
3910
3911 \begin_layout Standard
3912 (not on Win32)
3913 \end_layout
3914
3915 \end_inset
3916 </cell>
3917 </row>
3918 </lyxtabular>
3919
3920 \end_inset
3921
3922
3923 \newline
3924
3925 \end_layout
3926
3927 \begin_layout Standard
3928 \begin_inset Note Note
3929 status collapsed
3930
3931 \begin_layout Standard
3932 Don't delete any of the stray spaces in the table above without checking
3933  the HTML output (last line)!
3934 \end_layout
3935
3936 \end_inset
3937
3938
3939 \end_layout
3940
3941 \begin_layout Standard
3942 \InsetSpace ~
3943
3944 \newline
3945 The option -
3946 \begin_inset ERT
3947 status collapsed
3948
3949 \begin_layout Standard
3950
3951
3952 \backslash
3953 /
3954 \end_layout
3955
3956 \end_inset
3957
3958 -nostdlib disables the last two search paths.
3959 \end_layout
3960
3961 \begin_layout Section
3962 Building SDCC
3963 \begin_inset LatexCommand \index{Building SDCC}
3964
3965 \end_inset
3966
3967
3968 \end_layout
3969
3970 \begin_layout Subsection
3971 Building SDCC on Linux
3972 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3973
3974 \end_inset
3975
3976
3977 \end_layout
3978
3979 \begin_layout Enumerate
3980
3981 \series medium
3982 Download the source package
3983 \series default
3984  either from the SDCC Subversion repository or from snapshot builds
3985 \series medium
3986 , it will be named something like sdcc
3987 \series default
3988 -src
3989 \series medium
3990 -yyyymmdd-rrrr.t
3991 \series default
3992 ar.
3993 \series medium
3994 bz2
3995 \series default
3996  
3997 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3998
3999 \end_inset
4000
4001 .
4002 \end_layout
4003
4004 \begin_layout Enumerate
4005
4006 \series medium
4007 Bring up a command line terminal, such as xterm.
4008 \end_layout
4009
4010 \begin_layout Enumerate
4011
4012 \series medium
4013 Unpack the file using a command like: 
4014 \family sans
4015 \series bold
4016 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
4017 \begin_inset Quotes srd
4018 \end_inset
4019
4020
4021 \family default
4022 \series medium
4023 , this will create a sub-directory called sdcc with all of the sources.
4024 \end_layout
4025
4026 \begin_layout Enumerate
4027 Change directory into the main SDCC directory, for example type: 
4028 \family sans
4029 \series bold
4030 "cd sdcc
4031 \series default
4032 ".
4033 \end_layout
4034
4035 \begin_layout Enumerate
4036
4037 \series medium
4038 Type 
4039 \family sans
4040 \series bold
4041 "./configure
4042 \family default
4043 \series default
4044 ".
4045  This configures the package for compilation on your system.
4046 \end_layout
4047
4048 \begin_layout Enumerate
4049
4050 \series medium
4051 Type 
4052 \family sans
4053 \series bold
4054 "make
4055 \family default
4056 \series default
4057 "
4058 \series medium
4059 .
4060
4061 \series default
4062  All of the source packages will compile, this can take a while.
4063 \end_layout
4064
4065 \begin_layout Enumerate
4066
4067 \series medium
4068 Type 
4069 \family sans
4070 \series bold
4071 "make install"
4072 \family default
4073 \series default
4074  as root
4075 \series medium
4076 .
4077
4078 \series default
4079  This copies the binary executables, the include files, the libraries and
4080  the documentation to the install directories.
4081  Proceed with section 
4082 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
4083
4084 \end_inset
4085
4086 .
4087 \end_layout
4088
4089 \begin_layout Subsection
4090 Building SDCC on Mac OS X
4091 \end_layout
4092
4093 \begin_layout Standard
4094 Follow the instruction for Linux.
4095 \newline
4096
4097 \newline
4098 On Mac OS X 10.2.x it was reported, that the
4099  default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
4100  Fortunately there's also gcc 2.9.x installed, which works fine.
4101  This compiler can be selected by running 'configure' with:
4102 \end_layout
4103
4104 \begin_layout LyX-Code
4105 ./configure CC=gcc2 CXX=g++2
4106 \end_layout
4107
4108 \begin_layout Standard
4109 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
4110  Xcode.
4111  Run 'configure' with:
4112 \end_layout
4113
4114 \begin_layout LyX-Code
4115 ./configure 
4116 \backslash
4117
4118 \end_layout
4119
4120 \begin_layout LyX-Code
4121 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4122  ppc" 
4123 \backslash
4124
4125 \end_layout
4126
4127 \begin_layout LyX-Code
4128 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4129  ppc" 
4130 \backslash
4131
4132 \end_layout
4133
4134 \begin_layout LyX-Code
4135 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
4136 \end_layout
4137
4138 \begin_layout Subsection
4139 Cross compiling SDCC on Linux for Windows
4140 \end_layout
4141
4142 \begin_layout Standard
4143 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
4144  See section 'Configure Options'.
4145 \end_layout
4146
4147 \begin_layout Subsection
4148 Building SDCC using Cygwin and Mingw32
4149 \end_layout
4150
4151 \begin_layout Standard
4152 For building and installing a Cygwin executable follow the instructions
4153  for Linux.
4154 \newline
4155
4156 \newline
4157 On Cygwin a 
4158 \begin_inset Quotes sld
4159 \end_inset
4160
4161 native
4162 \begin_inset Quotes srd
4163 \end_inset
4164
4165  Win32-binary can be built, which will not need the Cygwin-DLL.
4166  For the necessary 'configure' options see section 'configure options' or
4167  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4168 \newline
4169
4170 \newline
4171 In order to install
4172  Cygwin on Windows download setup.exe from 
4173 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
4174
4175 \end_inset
4176
4177 .
4178  Run it, set the 
4179 \begin_inset Quotes sld
4180 \end_inset
4181
4182 default text file type
4183 \begin_inset Quotes srd
4184 \end_inset
4185
4186  to 
4187 \begin_inset Quotes sld
4188 \end_inset
4189
4190 unix
4191 \begin_inset Quotes srd
4192 \end_inset
4193
4194  and download/install at least the following packages.
4195  Some packages are selected by default, others will be automatically selected
4196  because of dependencies with the manually selected packages.
4197  Never deselect these packages!
4198 \end_layout
4199
4200 \begin_layout Itemize
4201 flex
4202 \end_layout
4203
4204 \begin_layout Itemize
4205 bison
4206 \end_layout
4207
4208 \begin_layout Itemize
4209 gcc ; version 3.x is fine, no need to use the old 2.9x
4210 \end_layout
4211
4212 \begin_layout Itemize
4213 binutils ; selected with gcc
4214 \end_layout
4215
4216 \begin_layout Itemize
4217 make
4218 \end_layout
4219
4220 \begin_layout Itemize
4221 rxvt ; a nice console, which makes life much easier under windoze (see below)
4222 \end_layout
4223
4224 \begin_layout Itemize
4225 man ; not really needed for building SDCC, but you'll miss it sooner or
4226  later
4227 \end_layout
4228
4229 \begin_layout Itemize
4230 less ; not really needed for building SDCC, but you'll miss it sooner or
4231  later
4232 \end_layout
4233
4234 \begin_layout Itemize
4235 svn ; only if you use Subversion access
4236 \end_layout
4237
4238 \begin_layout Standard
4239 If you want to develop something you'll need:
4240 \end_layout
4241
4242 \begin_layout Itemize
4243 python ; for the regression tests
4244 \end_layout
4245
4246 \begin_layout Itemize
4247 gdb ; the gnu debugger, together with the nice GUI 
4248 \begin_inset Quotes sld
4249 \end_inset
4250
4251 insight
4252 \begin_inset Quotes srd
4253 \end_inset
4254
4255
4256 \end_layout
4257
4258 \begin_layout Itemize
4259 openssh ; to access the CF or commit changes
4260 \end_layout
4261
4262 \begin_layout Itemize
4263 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4264  use autoconf-stable!
4265 \end_layout
4266
4267 \begin_layout Standard
4268 rxvt is a nice console with history.
4269  Replace in your cygwin.bat the line
4270 \end_layout
4271
4272 \begin_layout LyX-Code
4273 bash -
4274 \begin_inset ERT
4275 status collapsed
4276
4277 \begin_layout Standard
4278
4279
4280 \backslash
4281 /
4282 \end_layout
4283
4284 \end_inset
4285
4286 -login -i 
4287 \end_layout
4288
4289 \begin_layout Standard
4290 with (one line):
4291 \end_layout
4292
4293 \begin_layout LyX-Code
4294 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4295 \end_layout
4296
4297 \begin_layout LyX-Code
4298      -bg black -fg white -geometry 100x65 -e bash -
4299 \begin_inset ERT
4300 status collapsed
4301
4302 \begin_layout Standard
4303
4304
4305 \backslash
4306 /
4307 \end_layout
4308
4309 \end_inset
4310
4311 -login
4312 \end_layout
4313
4314 \begin_layout Standard
4315 Text selected with the mouse is automatically copied to the clipboard, pasting
4316  works with shift-insert.
4317 \newline
4318
4319 \newline
4320 The other good tip is to make sure you have no //c/-styl
4321 e paths anywhere, use /cygdrive/c/ instead.
4322  Using // invokes a network lookup which is very slow.
4323  If you think 
4324 \begin_inset Quotes sld
4325 \end_inset
4326
4327 cygdrive
4328 \begin_inset Quotes srd
4329 \end_inset
4330
4331  is too long, you can change it with e.g.
4332 \end_layout
4333
4334 \begin_layout LyX-Code
4335 mount -s -u -c /mnt
4336 \end_layout
4337
4338 \begin_layout Standard
4339 SDCC sources use the unix line ending LF.
4340  Life is much easier, if you store the source tree on a drive which is mounted
4341  in binary mode.
4342  And use an editor which can handle LF-only line endings.
4343  Make sure not to commit files with windows line endings.
4344  The tabulator spacing
4345 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4346
4347 \end_inset
4348
4349  used in the project is 8.
4350  Although a tabulator spacing of 8 is a sensible choice for programmers
4351  (it's a power of 2 and allows to display 8/16 bit signed variables without
4352  loosing columns) the plan is to move towards using only spaces in the source.
4353 \end_layout
4354
4355 \begin_layout Subsection
4356 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4357 \end_layout
4358
4359 \begin_layout Standard
4360
4361 \series medium
4362 Download the source package
4363 \series default
4364  either from the SDCC Subversion repository or from the 
4365 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4366
4367 \end_inset
4368
4369
4370 \series medium
4371 , it will be named something like sdcc
4372 \series default
4373 -src
4374 \series medium
4375 -yyyymmdd-rrrr.tar.bz2.
4376
4377 \series default
4378  SDCC is distributed with all the projects, workspaces, and files you need
4379  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4380  The workspace name is 'sdcc.dsw'.
4381  Please note that as it is now, all the executables are created in a folder
4382  called sdcc
4383 \backslash
4384 bin_vc.
4385  Once built you need to copy the executables from sdcc
4386 \backslash
4387 bin_vc to sdcc
4388 \backslash
4389 bin before running SDCC.
4390  
4391 \newline
4392
4393 \newline
4394 WARNING: Visual studio is very picky with line terminations; it expects
4395  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4396  When using the Subversion repository it's easiest to configure the svn
4397  client to convert automatically for you.
4398  If however you are getting a message such as "This makefile was not generated
4399  by Developer Studio etc.
4400  etc.
4401 \begin_inset Quotes srd
4402 \end_inset
4403
4404  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4405  need to convert the Unix style line endings to DOS style line endings.
4406  To do so you can use the 
4407 \begin_inset Quotes sld
4408 \end_inset
4409
4410 unix2dos
4411 \begin_inset Quotes srd
4412 \end_inset
4413
4414  utility freely available on the internet.
4415  Doug Hawkins reported in the sdcc-user list that this works:
4416 \newline
4417
4418 \newline
4419 C:
4420 \backslash
4421 Programming
4422 \backslash
4423 SDCC> unix2dos sdcc.dsw
4424 \newline
4425 C:
4426 \backslash
4427 Programming
4428 \backslash
4429 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4430 \newline
4431
4432 \newline
4433 In order to build SDCC with MSVC
4434  you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4435  One good place to get them is 
4436 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4437
4438 \end_inset
4439
4440
4441 \newline
4442
4443 \newline
4444 Download the file UnxUtils
4445 \begin_inset LatexCommand \index{UnxUtils}
4446
4447 \end_inset
4448
4449 .zip.
4450  Now you have to install the utilities and setup MSVC so it can locate the
4451  required programs.
4452  Here there are two alternatives (choose one!):
4453 \end_layout
4454
4455 \begin_layout Enumerate
4456 The easy way:
4457 \newline
4458
4459 \newline
4460 a) Extract UnxUtils.zip to your C:
4461 \backslash
4462  hard disk PRESERVING the original paths, otherwise bison won't work.
4463  (If you are using WinZip make certain that 'Use folder names' is selected)
4464 \newline
4465
4466 \newline
4467 b)
4468  In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4469  'Show directories for:' select 'Executable files', and in the directories
4470  window add a new path: 'C:
4471 \backslash
4472 user
4473 \backslash
4474 local
4475 \backslash
4476 wbin', click ok.
4477 \newline
4478
4479 \newline
4480 (As a side effect, you get a bunch of Unix utilities that
4481  could be useful, such as diff and patch.)
4482 \end_layout
4483
4484 \begin_layout Enumerate
4485 A more compact way:
4486 \newline
4487
4488 \newline
4489 This one avoids extracting a bunch of files you may not
4490  use, but requires some extra work:
4491 \newline
4492
4493 \newline
4494 a) Create a directory were to put the
4495  tools needed, or use a directory already present.
4496  Say for example 'C:
4497 \backslash
4498 util'.
4499 \newline
4500
4501 \newline
4502 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4503  gawk.exe to such directory WITHOUT preserving the original paths.
4504  (If you are using WinZip make certain that 'Use folder names' is not selected)
4505 \newline
4506
4507 \newline
4508 c
4509 ) Rename bison.exe to '_bison.exe'.
4510 \newline
4511
4512 \newline
4513 d) Create a batch file 'bison.bat' in 'C:
4514 \backslash
4515 util
4516 \backslash
4517 ' and add these lines: 
4518 \newline
4519 \InsetSpace ~
4520 \InsetSpace ~
4521 set BISON_SIMPLE=C:
4522 \backslash
4523 util
4524 \backslash
4525 bison.simple 
4526 \newline
4527 \InsetSpace ~
4528 \InsetSpace ~
4529 set BISON_HAIRY=C:
4530 \backslash
4531 util
4532 \backslash
4533 bison.hairy
4534 \newline
4535 \InsetSpace ~
4536 \InsetSpace ~
4537 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4538 \newline
4539
4540 \newline
4541 Steps 'c' and 'd' are needed
4542  because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4543  reside in some weird Unix directory, '/usr/local/share/' I think.
4544  So it is necessary to tell bison where those files are located if they
4545  are not in such directory.
4546  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4547 \newline
4548
4549 \newline
4550 e
4551 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4552  in 'Show directories for:' select 'Executable files', and in the directories
4553  window add a new path: 'c:
4554 \backslash
4555 util', click ok.
4556  Note that you can use any other path instead of 'c:
4557 \backslash
4558 util', even the path where the Visual C++ tools are, probably: 'C:
4559 \backslash
4560 Program Files
4561 \backslash
4562 Microsoft Visual Studio
4563 \backslash
4564 Common
4565 \backslash
4566 Tools'.
4567  So you don't have to execute step 'e' :)
4568 \end_layout
4569
4570 \begin_layout Standard
4571 That is it.
4572  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4573  the executables from sdcc
4574 \backslash
4575 bin_vc to sdcc
4576 \backslash
4577 bin, and you can compile using SDCC.
4578 \end_layout
4579
4580 \begin_layout Subsection
4581 Building SDCC Using Borland
4582 \end_layout
4583
4584 \begin_layout Enumerate
4585 From the sdcc directory, run the command "make -f Makefile.bcc".
4586  This should regenerate all the .exe files in the bin directory except for
4587  SDCDB and ucSim.
4588 \end_layout
4589
4590 \begin_layout Enumerate
4591 If you modify any source files and need to rebuild, be aware that the dependenci
4592 es may not be correctly calculated.
4593  The safest option is to delete all .obj files and run the build again.
4594  From a Cygwin BASH prompt, this can easily be done with the command (be
4595  sure you are in the sdcc directory):
4596 \newline
4597
4598 \newline
4599
4600 \family sans
4601 \series bold
4602 find .
4603  
4604 \backslash
4605 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
4606 \backslash
4607 ) -print -exec rm {} 
4608 \backslash
4609 ;
4610 \family default
4611 \series default
4612
4613 \newline
4614
4615 \newline
4616 or on Windows NT/2000/XP from the command prompt with the command:
4617 \newline
4618
4619 \family sans
4620 \series bold
4621
4622 \newline
4623 del /s *.obj *.lib *.rul
4624 \family default
4625 \series default
4626  from the sdcc directory.
4627 \end_layout
4628
4629 \begin_layout Subsection
4630 Windows Install Using a ZIP Package
4631 \end_layout
4632
4633 \begin_layout Enumerate
4634 Download the binary zip package from 
4635 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4636
4637 \end_inset
4638
4639  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4640  This should unpack to a group of sub-directories.
4641  An example directory structure after unpacking the mingw32 package is:
4642  c:
4643 \backslash
4644 sdcc
4645 \backslash
4646 bin for the executables, c:
4647 \backslash
4648 sdcc
4649 \backslash
4650 include and c:
4651 \backslash
4652 sdcc
4653 \backslash
4654 lib for the include and libraries.
4655 \end_layout
4656
4657 \begin_layout Enumerate
4658 Adjust your environment variable PATH to include the location of the bin
4659  directory or start sdcc using the full path.
4660 \end_layout
4661
4662 \begin_layout Subsection
4663 Windows Install Using the Setup Program
4664 \begin_inset LatexCommand \label{sub:Windows-Install}
4665
4666 \end_inset
4667
4668
4669 \end_layout
4670
4671 \begin_layout Standard
4672 Download the setup program 
4673 \emph on
4674 sdcc-x.y.z-setup.exe
4675 \emph default
4676  for an official release from 
4677 \newline
4678
4679 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4680
4681 \end_inset
4682
4683  or a setup program for one of the snapshots 
4684 \emph on
4685 sdcc-yyyymmdd-xxxx-setup.exe
4686 \emph default
4687  from 
4688 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4689
4690 \end_inset
4691
4692  and execute it.
4693  A windows typical installer will guide you through the installation process.
4694 \end_layout
4695
4696 \begin_layout Subsection
4697 VPATH
4698 \begin_inset LatexCommand \index{VPATH}
4699
4700 \end_inset
4701
4702  feature
4703 \end_layout
4704
4705 \begin_layout Standard
4706 SDCC supports the VPATH feature provided by configure and make.
4707  It allows to separate the source and build trees.
4708  Here's an example:
4709 \end_layout
4710
4711 \begin_layout Standard
4712
4713 \family typewriter
4714 cd ~\InsetSpace ~
4715 \InsetSpace ~
4716 \InsetSpace ~
4717 \InsetSpace ~
4718 \InsetSpace ~
4719 \InsetSpace ~
4720 \InsetSpace ~
4721 \InsetSpace ~
4722 \InsetSpace ~
4723 \InsetSpace ~
4724 \InsetSpace ~
4725 \InsetSpace ~
4726 \InsetSpace ~
4727 \InsetSpace ~
4728 \InsetSpace ~
4729 \InsetSpace ~
4730 \InsetSpace ~
4731 \InsetSpace ~
4732 \InsetSpace ~
4733 \InsetSpace ~
4734 \InsetSpace ~
4735 # cd $HOME
4736 \end_layout
4737
4738 \begin_layout Standard
4739
4740 \family typewriter
4741 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4742 # extract source to directory sdcc
4743 \end_layout
4744
4745 \begin_layout Standard
4746
4747 \family typewriter
4748 mkdir sdcc.build\InsetSpace ~
4749 \InsetSpace ~
4750 \InsetSpace ~
4751 \InsetSpace ~
4752 \InsetSpace ~
4753 \InsetSpace ~
4754 \InsetSpace ~
4755 \InsetSpace ~
4756 \InsetSpace ~
4757 # put output in sdcc.build
4758 \end_layout
4759
4760 \begin_layout Standard
4761
4762 \family typewriter
4763 cd sdcc.build
4764 \end_layout
4765
4766 \begin_layout Standard
4767
4768 \family typewriter
4769 ../sdcc/configure\InsetSpace ~
4770 \InsetSpace ~
4771 \InsetSpace ~
4772 \InsetSpace ~
4773 \InsetSpace ~
4774 \InsetSpace ~
4775 \InsetSpace ~
4776 \InsetSpace ~
4777 # configure is doing all the magic!
4778 \end_layout
4779
4780 \begin_layout Standard
4781
4782 \family typewriter
4783 make
4784 \end_layout
4785
4786 \begin_layout Standard
4787 \noindent
4788 That's it! 
4789 \series bold
4790 configure
4791 \series default
4792  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4793  It automagically computes the variables srcdir, top_srcdir and top_buildir
4794  for each directory.
4795  After running 
4796 \series bold
4797 make
4798 \series default
4799  the generated files will be in ~/sdcc.build, while the source files stay
4800  in ~/sdcc.
4801 \newline
4802 This is not only usefull for building different binaries, e.g.
4803  when cross compiling.
4804  It also gives you a much better overview in the source tree when all the
4805  generated files are not scattered between the source files.
4806  And the best thing is: if you want to change a file you can leave the original
4807  file untouched in the source directory.
4808  Simply copy it to the build directory, edit it, enter `make clean', `rm
4809  Makefile.dep' and `make'.
4810  
4811 \series bold
4812 make
4813 \series default
4814  will do the rest for you!
4815 \end_layout
4816
4817 \begin_layout Section
4818 Building the Documentation
4819 \end_layout
4820
4821 \begin_layout Standard
4822 Add -
4823 \begin_inset ERT
4824 status collapsed
4825
4826 \begin_layout Standard
4827
4828
4829 \backslash
4830 /
4831 \end_layout
4832
4833 \end_inset
4834
4835 -enable-doc to the configure arguments to build the documentation together
4836  with all the other stuff.
4837  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4838  dvips and makeindex) to get the job done.
4839  Another possibility is to change to the doc directory and to type 
4840 \family sans
4841 \series bold
4842
4843 \begin_inset Quotes srd
4844 \end_inset
4845
4846 make
4847 \begin_inset Quotes srd
4848 \end_inset
4849
4850
4851 \family default
4852 \series default
4853  there.
4854  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4855 x).
4856  Using LyX 
4857 \begin_inset LatexCommand \url{http://www.lyx.org}
4858
4859 \end_inset
4860
4861  as editor is straightforward.
4862  Prebuilt documentation in html and pdf format is available from 
4863 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4864
4865 \end_inset
4866
4867 .
4868 \end_layout
4869
4870 \begin_layout Section
4871 Reading the Documentation
4872 \begin_inset LatexCommand \index{Documentation}
4873
4874 \end_inset
4875
4876
4877 \end_layout
4878
4879 \begin_layout Standard
4880 Currently reading the document in pdf format is recommended, as for unknown
4881  reason the hyperlinks are working there whereas in the html version they
4882  are not
4883 \begin_inset Foot
4884 status open
4885
4886 \begin_layout Standard
4887 If you should know why please drop us a note
4888 \end_layout
4889
4890 \end_inset
4891
4892 .
4893  
4894 \newline
4895 You'll find the pdf version
4896 \begin_inset LatexCommand \index{PDF version of this document}
4897
4898 \end_inset
4899
4900  at 
4901 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4902
4903 \end_inset
4904
4905 .
4906  
4907 \newline
4908 A html version
4909 \begin_inset LatexCommand \index{HTML version of this document}
4910
4911 \end_inset
4912
4913  should be online at 
4914 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4915
4916 \end_inset
4917
4918 .
4919 \newline
4920 This documentation is in some aspects different from a commercial documentation:
4921  
4922 \end_layout
4923
4924 \begin_layout Itemize
4925 It tries to document SDCC for several processor architectures in one document
4926  (commercially these probably would be separate documents/products).
4927  This document
4928 \begin_inset LatexCommand \index{Status of documentation}
4929
4930 \end_inset
4931
4932  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4933 on about f.e.
4934  Z80, PIC14, PIC16 and HC08.
4935 \end_layout
4936
4937 \begin_layout Itemize
4938 There are many references pointing away from this documentation.
4939  Don't let this distract you.
4940  If there f.e.
4941  was a reference like 
4942 \begin_inset LatexCommand \url{http://www.opencores.org}
4943
4944 \end_inset
4945
4946  together with a statement 
4947 \begin_inset Quotes sld
4948 \end_inset
4949
4950 some processors which are targetted by SDCC can be implemented in a 
4951 \emph on
4952 f
4953 \emph default
4954 ield 
4955 \emph on
4956 p
4957 \emph default
4958 rogrammable 
4959 \emph on
4960 g
4961 \emph default
4962 ate 
4963 \emph on
4964 a
4965 \emph default
4966 rray
4967 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4968
4969 \end_inset
4970
4971
4972 \begin_inset Quotes srd
4973 \end_inset
4974
4975  or 
4976 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4977
4978 \end_inset
4979
4980
4981 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4982
4983 \end_inset
4984
4985  
4986 \begin_inset Quotes sld
4987 \end_inset
4988
4989 have you ever heard of an open source compiler that compiles a subset of
4990  C for an FPGA?
4991 \begin_inset Quotes srd
4992 \end_inset
4993
4994  we expect you to have a quick look there and come back.
4995  If you read this you are on the right track.
4996 \end_layout
4997
4998 \begin_layout Itemize
4999 Some sections attribute more space to problems, restrictions and warnings
5000  than to the solution.
5001 \end_layout
5002
5003 \begin_layout Itemize
5004 The installation section and the section about the debugger is intimidating.
5005 \end_layout
5006
5007 \begin_layout Itemize
5008 There are still lots of typos and there are more different writing styles
5009  than pictures.
5010 \end_layout
5011
5012 \begin_layout Section
5013 Testing the SDCC Compiler
5014 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
5015
5016 \end_inset
5017
5018
5019 \end_layout
5020
5021 \begin_layout Standard
5022 The first thing you should do after installing your SDCC compiler is to
5023  see if it runs.
5024  Type 
5025 \family sans
5026 \series bold
5027 "sdcc -
5028 \begin_inset ERT
5029 status collapsed
5030
5031 \begin_layout Standard
5032
5033
5034 \backslash
5035 /
5036 \end_layout
5037
5038 \end_inset
5039
5040 -version"
5041 \begin_inset LatexCommand \index{version}
5042
5043 \end_inset
5044
5045
5046 \family default
5047 \series default
5048  at the prompt, and the program should run and output its version like:
5049  
5050 \newline
5051
5052 \family typewriter
5053 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
5054  (UNIX)
5055 \end_layout
5056
5057 \begin_layout Standard
5058 If it doesn't run, or gives a message about not finding sdcc program, then
5059  you need to check over your installation.
5060  Make sure that the sdcc bin directory is in your executable search path
5061  defined by the PATH environment setting (
5062 \series medium
5063 see 
5064 \series default
5065 section 
5066 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5067
5068 \end_inset
5069
5070 \InsetSpace ~
5071
5072 \series medium
5073 Install trouble-shooting for suggestions
5074 \series default
5075 ).
5076  Make sure that the sdcc program is in the bin folder, if not perhaps something
5077  did not install correctly.
5078 \newline
5079
5080 \newline
5081
5082 \series medium
5083 SDCC 
5084 \series default
5085 is commonly installed as described in section 
5086 \begin_inset Quotes sld
5087 \end_inset
5088
5089 Install and search paths
5090 \begin_inset Quotes srd
5091 \end_inset
5092
5093 .
5094 \newline
5095
5096 \newline
5097
5098 \series medium
5099 Make sure the compiler works on a very simple example.
5100  Type in the following test.c program using your favorite 
5101 \series default
5102 ASCII 
5103 \series medium
5104 editor:
5105 \end_layout
5106
5107 \begin_layout Verse
5108
5109 \family typewriter
5110 char test;
5111 \newline
5112
5113 \newline
5114 void main(void) {
5115 \newline
5116 \InsetSpace ~
5117 \InsetSpace ~
5118 \InsetSpace ~
5119 \InsetSpace ~
5120 test=0;
5121 \newline
5122 }
5123 \end_layout
5124
5125 \begin_layout Standard
5126
5127 \series medium
5128 Compile this using the following command: 
5129 \family sans
5130 \series bold
5131 "sdcc -c test.c".
5132
5133 \family default
5134 \series default
5135  
5136 \series medium
5137 If all goes well, the compiler will generate a test.asm and test.rel file.
5138  Congratulations, you've just compiled your first program with SDCC.
5139  We used the -c option to tell SDCC not to link the generated code, just
5140  to keep things simple for this step.
5141 \series default
5142
5143 \newline
5144
5145 \newline
5146
5147 \series medium
5148 The next step is to try it with the linker.
5149  Type in 
5150 \family sans
5151 \series bold
5152 "sdcc test.c
5153 \family default
5154 \series default
5155 "
5156 \series medium
5157 .
5158  If all goes well the compiler will link with the libraries and produce
5159  a test.ihx output file.
5160  If this step fails
5161 \series default
5162  
5163 \series medium
5164 (no test.ihx, and the linker generates warnings), then the problem is most
5165  likely that 
5166 \series default
5167 SDCC
5168 \series medium
5169  cannot find the 
5170 \series default
5171 /
5172 \series medium
5173 usr/local/share/sdcc/lib directory
5174 \series default
5175  
5176 \series medium
5177 (see 
5178 \series default
5179 section 
5180 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5181
5182 \end_inset
5183
5184 \InsetSpace ~
5185
5186 \series medium
5187 Install trouble-shooting for suggestions).
5188 \series default
5189
5190 \newline
5191
5192 \newline
5193
5194 \series medium
5195 The final test is to ensure 
5196 \series default
5197 SDCC
5198 \series medium
5199  can use the 
5200 \series default
5201 standard
5202 \series medium
5203  header files and libraries.
5204  Edit test.c and change it to the following:
5205 \end_layout
5206
5207 \begin_layout Verse
5208
5209 \family typewriter
5210 #include <string.h>
5211 \newline
5212
5213 \newline
5214 char str1[10];
5215 \newline
5216
5217 \newline
5218 void main(void) {
5219 \newline
5220 \InsetSpace ~
5221 \InsetSpace ~
5222 strcpy(str1, "testing");
5223 \newline
5224 }
5225 \end_layout
5226
5227 \begin_layout Standard
5228
5229 \series medium
5230 Compile this by typing 
5231 \family sans
5232 \series bold
5233 "sdcc test.c"
5234 \family default
5235 \series medium
5236 .
5237  This should generate a test.ihx output file, and it should give no warnings
5238  such as not finding the string.h file.
5239  If it cannot find the string.h file, then the problem is that 
5240 \series default
5241 SDCC
5242 \series medium
5243  cannot find the /usr/local/share/sdcc/include directory
5244 \series default
5245  
5246 \series medium
5247 (see the 
5248 \series default
5249 section 
5250 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5251
5252 \end_inset
5253
5254 \InsetSpace ~
5255
5256 \series medium
5257 Install trouble-shooting section for suggestions).
5258
5259 \series default
5260  Use option 
5261 \series bold
5262 -
5263 \begin_inset ERT
5264 status collapsed
5265
5266 \begin_layout Standard
5267
5268
5269 \backslash
5270 /
5271 \end_layout
5272
5273 \end_inset
5274
5275 -print-search-dirs
5276 \series default
5277
5278 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5279
5280 \end_inset
5281
5282  to find exactly where SDCC is looking for the include and lib files.
5283 \end_layout
5284
5285 \begin_layout Section
5286 Install Trouble-shooting
5287 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5288
5289 \end_inset
5290
5291
5292 \begin_inset LatexCommand \index{Install trouble-shooting}
5293
5294 \end_inset
5295
5296
5297 \end_layout
5298
5299 \begin_layout Subsection
5300 If SDCC does not build correctly
5301 \end_layout
5302
5303 \begin_layout Standard
5304 A thing to try is starting from scratch by unpacking the .tgz source package
5305  again in an empty directory.
5306  Configure it like:
5307 \newline
5308
5309 \newline
5310
5311 \family sans
5312 \series bold
5313 ./configure 2>&1 | tee configure.log
5314 \family default
5315 \series default
5316
5317 \newline
5318
5319 \newline
5320 and build it like:
5321 \newline
5322
5323 \newline
5324
5325 \family sans
5326 \series bold
5327 make 2>&1 | tee make.log
5328 \family default
5329 \series default
5330
5331 \newline
5332
5333 \newline
5334 If anything goes wrong, you can review the log files to locate the problem.
5335  Or a relevant part of this can be attached to an email that could be helpful
5336  when requesting help from the mailing list.
5337 \end_layout
5338
5339 \begin_layout Subsection
5340 What the 
5341 \begin_inset Quotes sld
5342 \end_inset
5343
5344 ./configure
5345 \begin_inset Quotes srd
5346 \end_inset
5347
5348  does
5349 \end_layout
5350
5351 \begin_layout Standard
5352 The 
5353 \begin_inset Quotes sld
5354 \end_inset
5355
5356 ./configure
5357 \begin_inset Quotes srd
5358 \end_inset
5359
5360  command is a script that analyzes your system and performs some configuration
5361  to ensure the source package compiles on your system.
5362  It will take a few minutes to run, and will compile a few tests to determine
5363  what compiler features are installed.
5364 \end_layout
5365
5366 \begin_layout Subsection
5367 What the 
5368 \begin_inset Quotes sld
5369 \end_inset
5370
5371 make
5372 \begin_inset Quotes srd
5373 \end_inset
5374
5375  does
5376 \end_layout
5377
5378 \begin_layout Standard
5379 This runs the GNU make tool, which automatically compiles all the source
5380  packages into the final installed binary executables.
5381 \end_layout
5382
5383 \begin_layout Subsection
5384 What the 
5385 \begin_inset Quotes sld
5386 \end_inset
5387
5388 make install
5389 \begin_inset Quotes erd
5390 \end_inset
5391
5392  command does.
5393 \end_layout
5394
5395 \begin_layout Standard
5396 This will install the compiler, other executables libraries and include
5397  files into the appropriate directories.
5398  See sections 
5399 \begin_inset LatexCommand \ref{sub:Install-paths}
5400
5401 \end_inset
5402
5403 ,\InsetSpace ~
5404
5405 \begin_inset LatexCommand \ref{sub:Search-Paths}
5406
5407 \end_inset
5408
5409 \InsetSpace ~
5410 about install and search paths.
5411 \newline
5412 On most systems you will need super-user privilege
5413 s to do this.
5414 \end_layout
5415
5416 \begin_layout Section
5417 Components of SDCC
5418 \end_layout
5419
5420 \begin_layout Standard
5421 SDCC is not just a compiler, but a collection of tools by various developers.
5422  These include linkers, assemblers, simulators and other components.
5423  Here is a summary of some of the components.
5424  Note that the included simulator and assembler have separate documentation
5425  which you can find in the source package in their respective directories.
5426  As SDCC grows to include support for other processors, other packages from
5427  various developers are included and may have their own sets of documentation.
5428 \newline
5429
5430 \newline
5431 You
5432  might want to look at the files which are installed in <installdir>.
5433  At the time of this writing, we find the following programs for gcc-builds:
5434 \newline
5435
5436  
5437 \newline
5438 In <installdir>/bin:
5439 \end_layout
5440
5441 \begin_layout Itemize
5442 sdcc - The compiler.
5443 \end_layout
5444
5445 \begin_layout Itemize
5446 sdcpp - The C preprocessor.
5447 \end_layout
5448
5449 \begin_layout Itemize
5450 asx8051 - The assembler for 8051 type processors.
5451 \end_layout
5452
5453 \begin_layout Itemize
5454 as-z80
5455 \series bold
5456
5457 \series default
5458 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5459 \end_layout
5460
5461 \begin_layout Itemize
5462 aslink -The linker for 8051 type processors.
5463 \end_layout
5464
5465 \begin_layout Itemize
5466 link-z80
5467 \series bold
5468
5469 \series default
5470 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5471 \end_layout
5472
5473 \begin_layout Itemize
5474 s51 - The ucSim 8051 simulator.
5475 \end_layout
5476
5477 \begin_layout Itemize
5478 sdcdb - The source debugger.
5479 \end_layout
5480
5481 \begin_layout Itemize
5482 packihx - A tool to pack (compress) Intel hex files.
5483 \end_layout
5484
5485 \begin_layout Standard
5486 In <installdir>/share/sdcc/include
5487 \end_layout
5488
5489 \begin_layout Itemize
5490 the include files
5491 \end_layout
5492
5493 \begin_layout Standard
5494 In <installdir>/share/sdcc/lib
5495 \end_layout
5496
5497 \begin_layout Itemize
5498 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5499  relocatables.
5500 \end_layout
5501
5502 \begin_layout Standard
5503 In <installdir>/share/sdcc/doc
5504 \end_layout
5505
5506 \begin_layout Itemize
5507 the documentation
5508 \end_layout
5509
5510 \begin_layout Standard
5511 As development for other processors proceeds, this list will expand to include
5512  executables to support processors like AVR, PIC, etc.
5513 \end_layout
5514
5515 \begin_layout Subsection
5516 sdcc - The Compiler
5517 \end_layout
5518
5519 \begin_layout Standard
5520 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5521  the assembler and linkage editor.
5522 \end_layout
5523
5524 \begin_layout Subsection
5525 sdcpp - The C-Preprocessor
5526 \end_layout
5527
5528 \begin_layout Standard
5529 The preprocessor
5530 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5531
5532 \end_inset
5533
5534  is a modified version of the GNU cpp
5535 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5536
5537 \end_inset
5538
5539  preprocessor 
5540 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5541
5542 \end_inset
5543
5544 .
5545  The C preprocessor is used to pull in #include sources, process #ifdef
5546  statements, #defines and so on.
5547 \end_layout
5548
5549 \begin_layout Subsection
5550 as
5551 \emph on
5552 xxxx
5553 \emph default
5554 , aslink, link-
5555 \emph on
5556 xxx
5557 \emph default
5558  - The Assemblers and Linkage Editors
5559 \end_layout
5560
5561 \begin_layout Standard
5562 This is retargettable assembler & linkage editor, it was developed by Alan
5563  Baldwin.
5564  John Hartman created the version for 8051, and I (Sandeep) have made some
5565  enhancements and bug fixes for it to work properly with SDCC.
5566 \end_layout
5567
5568 \begin_layout Subsection
5569 s51 - The Simulator
5570 \end_layout
5571
5572 \begin_layout Standard
5573 S51
5574 \begin_inset LatexCommand \index{s51}
5575
5576 \end_inset
5577
5578  is a free open source simulator developed by Daniel Drotos.
5579  The simulator is built as part of the build process.
5580  For more information visit Daniel's web site at: 
5581 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5582
5583 \end_inset
5584
5585 .
5586  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5587  XA51 family.
5588 \end_layout
5589
5590 \begin_layout Subsection
5591 sdcdb - Source Level Debugger
5592 \end_layout
5593
5594 \begin_layout Standard
5595 SDCDB
5596 \begin_inset LatexCommand \index{SDCDB (debugger)}
5597
5598 \end_inset
5599
5600  is the companion source level debugger.
5601  More about SDCDB in section 
5602 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5603
5604 \end_inset
5605
5606 .
5607  The current version of the debugger uses Daniel's Simulator S51
5608 \begin_inset LatexCommand \index{s51}
5609
5610 \end_inset
5611
5612 , but can be easily changed to use other simulators.
5613 \end_layout
5614
5615 \begin_layout Chapter
5616 Using SDCC
5617 \end_layout
5618
5619 \begin_layout Section
5620 Compiling
5621 \end_layout
5622
5623 \begin_layout Subsection
5624 Single Source File Projects
5625 \end_layout
5626
5627 \begin_layout Standard
5628 For single source file 8051 projects the process is very simple.
5629  Compile your programs with the following command 
5630 \family sans
5631 \series bold
5632 "sdcc sourcefile.c".
5633
5634 \family default
5635 \series default
5636  This will compile, assemble and link your source file.
5637  Output files are as follows:
5638 \end_layout
5639
5640 \begin_layout Itemize
5641 sourcefile.asm
5642 \begin_inset LatexCommand \index{<file>.asm}
5643
5644 \end_inset
5645
5646  - Assembler source
5647 \begin_inset LatexCommand \index{Assembler source}
5648
5649 \end_inset
5650
5651  file created by the compiler
5652 \end_layout
5653
5654 \begin_layout Itemize
5655 sourcefile.lst
5656 \begin_inset LatexCommand \index{<file>.lst}
5657
5658 \end_inset
5659
5660  - Assembler listing
5661 \begin_inset LatexCommand \index{Assembler listing}
5662
5663 \end_inset
5664
5665  file created by the Assembler
5666 \end_layout
5667
5668 \begin_layout Itemize
5669 sourcefile.rst
5670 \begin_inset LatexCommand \index{<file>.rst}
5671
5672 \end_inset
5673
5674  - Assembler listing
5675 \begin_inset LatexCommand \index{Assembler listing}
5676
5677 \end_inset
5678
5679  file updated with linkedit information, created by linkage editor
5680 \end_layout
5681
5682 \begin_layout Itemize
5683 sourcefile.sym
5684 \begin_inset LatexCommand \index{<file>.sym}
5685
5686 \end_inset
5687
5688  - symbol listing
5689 \begin_inset LatexCommand \index{Symbol listing}
5690
5691 \end_inset
5692
5693  for the sourcefile, created by the assembler
5694 \end_layout
5695
5696 \begin_layout Itemize
5697 sourcefile.rel
5698 \begin_inset LatexCommand \index{<file>.rel}
5699
5700 \end_inset
5701
5702  or sourcefile.o
5703 \begin_inset LatexCommand \index{<file>.o}
5704
5705 \end_inset
5706
5707  - Object file
5708 \begin_inset LatexCommand \index{Object file}
5709
5710 \end_inset
5711
5712  created by the assembler, input to Linkage editor
5713 \end_layout
5714
5715 \begin_layout Itemize
5716 sourcefile.map
5717 \begin_inset LatexCommand \index{<file>.map}
5718
5719 \end_inset
5720
5721  - The memory map
5722 \begin_inset LatexCommand \index{Memory map}
5723
5724 \end_inset
5725
5726  for the load module, created by the Linker
5727 \end_layout
5728
5729 \begin_layout Itemize
5730 sourcefile.mem
5731 \begin_inset LatexCommand \index{<file>.mem}
5732
5733 \end_inset
5734
5735  - A file with a summary of the memory usage
5736 \end_layout
5737
5738 \begin_layout Itemize
5739 sourcefile.ihx
5740 \begin_inset LatexCommand \index{<file>.ihx}
5741
5742 \end_inset
5743
5744  - The load module in Intel hex format
5745 \begin_inset LatexCommand \index{Intel hex format}
5746
5747 \end_inset
5748
5749  (you can select the Motorola S19 format
5750 \begin_inset LatexCommand \index{Motorola S19 format}
5751
5752 \end_inset
5753
5754  with -
5755 \begin_inset ERT
5756 status collapsed
5757
5758 \begin_layout Standard
5759
5760
5761 \backslash
5762 /
5763 \end_layout
5764
5765 \end_inset
5766
5767 -out-fmt-s19
5768 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5769
5770 \end_inset
5771
5772 .
5773  If you need another format you might want to use 
5774 \family sans
5775 \shape italic
5776 objdump
5777 \family default
5778 \shape default
5779
5780 \begin_inset LatexCommand \index{objdump (tool)}
5781
5782 \end_inset
5783
5784  or
5785 \family sans
5786 \shape italic
5787  srecord
5788 \family default
5789 \shape default
5790
5791 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5792
5793 \end_inset
5794
5795
5796 \begin_inset Note Note
5797 status collapsed
5798
5799 \begin_layout Standard
5800 hyperlinks needed
5801 \end_layout
5802
5803 \end_inset
5804
5805  - see also section 
5806 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5807
5808 \end_inset
5809
5810 ).
5811  Both formats are documented in the documentation of srecord
5812 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5813
5814 \end_inset
5815
5816
5817 \end_layout
5818
5819 \begin_layout Itemize
5820 sourcefile.adb
5821 \begin_inset LatexCommand \index{<file>.adb}
5822
5823 \end_inset
5824
5825  - An intermediate file containing debug information needed to create the
5826  .cdb file (with -
5827 \begin_inset ERT
5828 status collapsed
5829
5830 \begin_layout Standard
5831
5832
5833 \backslash
5834 /
5835 \end_layout
5836
5837 \end_inset
5838
5839 -debug
5840 \begin_inset LatexCommand \index{-\/-debug}
5841
5842 \end_inset
5843
5844
5845 \end_layout
5846
5847 \begin_layout Itemize
5848 sourcefile.cdb
5849 \begin_inset LatexCommand \index{<file>.cdb}
5850
5851 \end_inset
5852
5853  - An optional file (with -
5854 \begin_inset ERT
5855 status collapsed
5856
5857 \begin_layout Standard
5858
5859
5860 \backslash
5861 /
5862 \end_layout
5863
5864 \end_inset
5865
5866 -debug) containing debug information.
5867  The format is documented in cdbfileformat.pdf
5868 \end_layout
5869
5870 \begin_layout Itemize
5871 sourcefile.
5872  - (no extension)
5873 \begin_inset LatexCommand \index{<file> (no extension)}
5874
5875 \end_inset
5876
5877  An optional AOMF or AOMF51
5878 \begin_inset LatexCommand \index{AOMF, AOMF51}
5879
5880 \end_inset
5881
5882  
5883 \begin_inset LatexCommand \label{OMF file}
5884
5885 \end_inset
5886
5887 file containing debug information (generated with option -
5888 \begin_inset ERT
5889 status collapsed
5890
5891 \begin_layout Standard
5892
5893
5894 \backslash
5895 /
5896 \end_layout
5897
5898 \end_inset
5899
5900 -debug).
5901  The (Intel)
5902 \emph on
5903  a
5904 \emph default
5905 bsolute 
5906 \emph on
5907 o
5908 \emph default
5909 bject 
5910 \emph on
5911 m
5912 \emph default
5913 odule 
5914 \emph on
5915 f
5916 \emph default
5917 ormat is a subformat of the OMF51 format and is commonly used by third party
5918  tools (debuggers
5919 \begin_inset LatexCommand \index{Debugger}
5920
5921 \end_inset
5922
5923 , simulators, emulators).
5924 \end_layout
5925
5926 \begin_layout Itemize
5927 sourcefile.dump*
5928 \begin_inset LatexCommand \index{<file>.dump*}
5929
5930 \end_inset
5931
5932  - Dump file to debug the compiler it self (generated with option -
5933 \begin_inset ERT
5934 status collapsed
5935
5936 \begin_layout Standard
5937
5938
5939 \backslash
5940 /
5941 \end_layout
5942
5943 \end_inset
5944
5945 -dumpall) (see section 
5946 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5947
5948 \end_inset
5949
5950 \InsetSpace ~
5951  and section 
5952 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5953
5954 \end_inset
5955
5956 \InsetSpace ~
5957
5958 \begin_inset Quotes sld
5959 \end_inset
5960
5961 Anatomy of the compiler
5962 \begin_inset Quotes srd
5963 \end_inset
5964
5965 ).
5966 \end_layout
5967
5968 \begin_layout Subsection
5969 Postprocessing the Intel Hex
5970 \begin_inset LatexCommand \index{Intel hex format}
5971
5972 \end_inset
5973
5974  file
5975 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5976
5977 \end_inset
5978
5979
5980 \end_layout
5981
5982 \begin_layout Standard
5983 In most cases this won't be needed but the Intel Hex file
5984 \begin_inset LatexCommand \index{<file>.ihx}
5985
5986 \end_inset
5987
5988  which is generated by SDCC might include lines of varying length and the
5989  addresses within the file are not guaranteed to be strictly ascending.
5990  If your toolchain or a bootloader does not like this you can use the tool
5991  
5992 \family typewriter
5993 packihx
5994 \family default
5995
5996 \begin_inset LatexCommand \index{packihx (tool)}
5997
5998 \end_inset
5999
6000  which is part of the SDCC distribution: 
6001 \newline
6002
6003 \newline
6004
6005 \family sans
6006 \series bold
6007  packihx sourcefile.ihx >sourcefile.hex
6008 \family default
6009 \series default
6010
6011 \newline
6012
6013 \newline
6014 The separately available
6015 \emph on
6016  srecord
6017 \emph default
6018
6019 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6020
6021 \end_inset
6022
6023  package additionally allows to set undefined locations to a predefined
6024  value, to insert checksums
6025 \begin_inset LatexCommand \index{checksum}
6026
6027 \end_inset
6028
6029  of various flavours (crc, add, xor) and to perform other manipulations
6030  (convert, split, crop, offset, ...).
6031  
6032 \newline
6033
6034 \newline
6035
6036 \family sans
6037 \series bold
6038 srec_cat\InsetSpace ~
6039 \InsetSpace ~
6040 sourcefile.ihx -intel\InsetSpace ~
6041 \InsetSpace ~
6042 -o sourcefile.hex -intel
6043 \newline
6044
6045 \newline
6046
6047 \family default
6048 \series default
6049 An example for a more complex command line
6050 \begin_inset Foot
6051 status open
6052
6053 \begin_layout Standard
6054 the command backfills
6055 \begin_inset LatexCommand \index{backfill unused memory}
6056
6057 \end_inset
6058
6059  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
6060  block is zero.
6061  If the program counter on an mcs51 runs wild the backfill pattern 0x12
6062  will be interpreted as an 
6063 \family typewriter
6064 lcall
6065 \family default
6066  to address 
6067 \family typewriter
6068 0x1212
6069 \family default
6070  (where an emergency routine could sit).
6071 \end_layout
6072
6073 \end_inset
6074
6075  could look like:
6076 \newline
6077
6078 \newline
6079
6080 \family sans
6081 \series bold
6082 \size footnotesize
6083 srec_cat\InsetSpace ~
6084 sourcefile.ihx -intel\InsetSpace ~
6085 \InsetSpace ~
6086 -fill 0x12 0x0000 0xfffe\InsetSpace ~
6087 -little-endian-checksum-nega
6088 tive 0xfffe 0x02 0x02\InsetSpace ~
6089 \InsetSpace ~
6090 -o sourcefile.hex -intel
6091 \size default
6092
6093 \newline
6094
6095 \newline
6096
6097 \family default
6098 \series default
6099 The srecord package is available at 
6100 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
6101
6102 \end_inset
6103
6104  .
6105 \end_layout
6106
6107 \begin_layout Subsection
6108 Projects with Multiple Source Files
6109 \end_layout
6110
6111 \begin_layout Standard
6112 SDCC can compile only ONE file at a time.
6113  Let us for example assume that you have a project containing the following
6114  files:
6115 \newline
6116
6117 \newline
6118 foo1.c (contains some functions)
6119 \newline
6120 foo2.c (contains some more functions)
6121 \newline
6122 foomai
6123 n.c (contains more functions and the function main)
6124 \newline
6125
6126 \size footnotesize
6127
6128 \newline
6129
6130 \size default
6131 The first two files will need to be compiled separately with the commands:
6132 \size footnotesize
6133  
6134 \size default
6135
6136 \newline
6137
6138 \newline
6139
6140 \family sans
6141 \series bold
6142 sdcc\InsetSpace ~
6143 -c\InsetSpace ~
6144 foo1.c
6145 \family default
6146 \series default
6147 \size footnotesize
6148
6149 \newline
6150
6151 \family sans
6152 \series bold
6153 \size default
6154 sdcc\InsetSpace ~
6155 -c\InsetSpace ~
6156 foo2.c
6157 \family default
6158 \series default
6159
6160 \newline
6161
6162 \newline
6163 Then compile the source file containing the 
6164 \emph on
6165 main()
6166 \emph default
6167  function and link
6168 \begin_inset LatexCommand \index{Linker}
6169
6170 \end_inset
6171
6172  the files together with the following command: 
6173 \newline
6174
6175 \newline
6176
6177 \family sans
6178 \series bold
6179 sdcc\InsetSpace ~
6180 foomain.c\InsetSpace ~
6181 foo1.rel\InsetSpace ~
6182 foo2.rel
6183 \family default
6184 \series default
6185
6186 \begin_inset LatexCommand \index{<file>.rel}
6187
6188 \end_inset
6189
6190
6191 \newline
6192
6193 \newline
6194 Alternatively, 
6195 \emph on
6196 foomain.c 
6197 \emph default
6198 can be separately compiled as well: 
6199 \family sans
6200 \series bold
6201
6202 \newline
6203
6204 \newline
6205 sdcc\InsetSpace ~
6206 -c\InsetSpace ~
6207 foomain.c
6208 \newline
6209 sdcc foomain.rel foo1.rel foo2.rel
6210 \newline
6211
6212 \newline
6213
6214 \family default
6215 \series default
6216 The file containing the 
6217 \emph on
6218 main()
6219 \emph default
6220  function
6221 \emph on
6222  
6223 \emph default
6224 \noun on
6225 must
6226 \noun default
6227  be the 
6228 \noun on
6229 first
6230 \noun default
6231  file specified in the command line, since the linkage editor processes
6232  file in the order they are presented to it.
6233  The linker is invoked from SDCC using a script file with extension .lnk
6234 \begin_inset LatexCommand \index{<file>.lnk}
6235
6236 \end_inset
6237
6238 .
6239  You can view this file to troubleshoot linking problems such as those arising
6240  from missing libraries.
6241 \end_layout
6242
6243 \begin_layout Subsection
6244 Projects with Additional Libraries
6245 \begin_inset LatexCommand \index{Libraries}
6246
6247 \end_inset
6248
6249
6250 \end_layout
6251
6252 \begin_layout Standard
6253 Some reusable routines may be compiled into a library, see the documentation
6254  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6255  for how to create a 
6256 \emph on
6257 .lib
6258 \begin_inset LatexCommand \index{<file>.lib}
6259
6260 \end_inset
6261
6262
6263 \emph default
6264  library file.
6265  Libraries created in this manner can be included in the command line.
6266  Make sure you include the -L <library-path> option to tell the linker where
6267  to look for these files if they are not in the current directory.
6268  Here is an example, assuming you have the source file 
6269 \emph on
6270 foomain.c
6271 \emph default
6272  and a library
6273 \emph on
6274  foolib.lib
6275 \emph default
6276  in the directory 
6277 \emph on
6278 mylib
6279 \emph default
6280  (if that is not the same as your current project):
6281 \newline
6282
6283 \newline
6284
6285 \family sans
6286 \series bold
6287 sdcc foomain.c foolib.lib -L mylib
6288 \newline
6289
6290 \newline
6291
6292 \family default
6293 \series default
6294 Note here that
6295 \emph on
6296  mylib
6297 \emph default
6298  must be an absolute path name.
6299 \newline
6300
6301 \newline
6302 The most efficient way to use libraries is
6303  to keep separate modules in separate source files.
6304  The lib file now should name all the modules.rel
6305 \begin_inset LatexCommand \index{<file>.rel}
6306
6307 \end_inset
6308
6309  files.
6310  For an example see the standard library file 
6311 \emph on
6312 libsdcc.lib
6313 \emph default
6314  in the directory <installdir>/share/lib/small.
6315 \end_layout
6316
6317 \begin_layout Subsection
6318 Using sdcclib to Create and Manage Libraries
6319 \begin_inset LatexCommand \index{sdcclib}
6320
6321 \end_inset
6322
6323
6324 \end_layout
6325
6326 \begin_layout Standard
6327 Alternatively, instead of having a .rel file for each entry on the library
6328  file as described in the preceding section, sdcclib can be used to embed
6329  all the modules belonging to such library in the library file itself.
6330  This results in a larger library file, but it greatly reduces the number
6331  of disk files accessed by the linker.
6332   Additionally, the packed library file contains an index of all include
6333  modules and symbols that significantly speeds up the linking process.
6334  To display a list of options supported by sdcclib type:
6335 \newline
6336
6337 \end_layout
6338
6339 \begin_layout Standard
6340
6341 \family sans
6342 \series bold
6343 sdcclib -?
6344 \begin_inset LatexCommand \index{sdcclib}
6345
6346 \end_inset
6347
6348
6349 \newline
6350
6351 \newline
6352
6353 \family default
6354 \series default
6355 To create a new library file, start by compiling all the required modules.
6356  For example:
6357 \newline
6358
6359 \end_layout
6360
6361 \begin_layout Standard
6362
6363 \family sans
6364 \series bold
6365 sdcc -c _divsint.c
6366 \end_layout
6367
6368 \begin_layout Standard
6369
6370 \family sans
6371 \series bold
6372 sdcc -c _divuint.c
6373 \end_layout
6374
6375 \begin_layout Standard
6376
6377 \family sans
6378 \series bold
6379 sdcc -c _modsint.c
6380 \end_layout
6381
6382 \begin_layout Standard
6383
6384 \family sans
6385 \series bold
6386 sdcc -c _moduint.c
6387 \end_layout
6388
6389 \begin_layout Standard
6390
6391 \family sans
6392 \series bold
6393 sdcc -c _mulint.c
6394 \newline
6395
6396 \end_layout
6397
6398 \begin_layout Standard
6399 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6400  and _mulint.rel.
6401  The next step is to add the .rel files to the library file:
6402 \newline
6403
6404 \end_layout
6405
6406 \begin_layout Standard
6407
6408 \family sans
6409 \series bold
6410 sdcclib libint.lib _divsint.rel
6411 \family default
6412
6413 \begin_inset LatexCommand \index{sdcclib}
6414
6415 \end_inset
6416
6417
6418 \end_layout
6419
6420 \begin_layout Standard
6421
6422 \family sans
6423 \series bold
6424 sdcclib libint.lib _divuint.rel
6425 \end_layout
6426
6427 \begin_layout Standard
6428
6429 \family sans
6430 \series bold
6431 sdcclib libint.lib _modsint.rel
6432 \end_layout
6433
6434 \begin_layout Standard
6435
6436 \family sans
6437 \series bold
6438 sdcclib libint.lib _moduint.rel
6439 \end_layout
6440
6441 \begin_layout Standard
6442
6443 \family sans
6444 \series bold
6445 sdcclib libint.lib _mulint.rel
6446 \family default
6447 \series default
6448
6449 \newline
6450
6451 \end_layout
6452
6453 \begin_layout Standard
6454 Or, if you preffer:
6455 \family sans
6456 \series bold
6457
6458 \newline
6459
6460 \end_layout
6461
6462 \begin_layout Standard
6463
6464 \family sans
6465 \series bold
6466 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6467 \family default
6468 \series default
6469
6470 \newline
6471
6472 \end_layout
6473
6474 \begin_layout Standard
6475 If the file already exists in the library, it will be replaced.
6476  If a list of .rel files is available, you can tell sdcclib to add those
6477  files to a library.
6478  For example, if the file 'myliblist.txt' contains
6479 \family sans
6480 \series bold
6481
6482 \newline
6483
6484 \end_layout
6485
6486 \begin_layout Standard
6487
6488 \family sans
6489 \series bold
6490 _divsint.rel
6491 \end_layout
6492
6493 \begin_layout Standard
6494
6495 \family sans
6496 \series bold
6497 _divuint.rel
6498 \end_layout
6499
6500 \begin_layout Standard
6501
6502 \family sans
6503 \series bold
6504 _modsint.rel
6505 \end_layout
6506
6507 \begin_layout Standard
6508
6509 \family sans
6510 \series bold
6511 _moduint.rel
6512 \end_layout
6513
6514 \begin_layout Standard
6515
6516 \family sans
6517 \series bold
6518 _mulint.rel
6519 \family default
6520 \series default
6521
6522 \newline
6523
6524 \end_layout
6525
6526 \begin_layout Standard
6527 Use
6528 \family sans
6529 \series bold
6530
6531 \newline
6532
6533 \end_layout
6534
6535 \begin_layout Standard
6536
6537 \family sans
6538 \series bold
6539 sdcclib -l libint.lib myliblist.txt
6540 \family default
6541 \series default
6542
6543 \newline
6544
6545 \end_layout
6546
6547 \begin_layout Standard
6548 Additionally, you can instruct sdcclib to compiles the files before adding
6549  them to the library.
6550  This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6551  For example:
6552 \family sans
6553 \series bold
6554
6555 \newline
6556
6557 \end_layout
6558
6559 \begin_layout Standard
6560
6561 \family sans
6562 \series bold
6563 set SDCCLIB_CC=sdcc -c
6564 \end_layout
6565
6566 \begin_layout Standard
6567
6568 \family sans
6569 \series bold
6570 sdcclib -l libint.lib myliblist.txt
6571 \family default
6572 \series default
6573
6574 \newline
6575
6576 \end_layout
6577
6578 \begin_layout Standard
6579 To see what modules and symbols are included in the library, options -s
6580  and -m are available.
6581  For example:
6582 \newline
6583
6584 \newline
6585
6586 \family sans
6587 \series bold
6588 sdcclib -s libint.lib
6589 \family default
6590
6591 \begin_inset LatexCommand \index{sdcclib}
6592
6593 \end_inset
6594
6595
6596 \newline
6597
6598 \family typewriter
6599 \series default
6600 _divsint.rel:
6601 \end_layout
6602
6603 \begin_layout Standard
6604
6605 \family typewriter
6606 __divsint_a_1_1
6607 \end_layout
6608
6609 \begin_layout Standard
6610
6611 \family typewriter
6612 __divsint_PARM_2
6613 \end_layout
6614
6615 \begin_layout Standard
6616
6617 \family typewriter
6618 __divsint
6619 \newline
6620 _divuint.rel:
6621 \end_layout
6622
6623 \begin_layout Standard
6624
6625 \family typewriter
6626 __divuint_a_1_1
6627 \end_layout
6628
6629 \begin_layout Standard
6630
6631 \family typewriter
6632 __divuint_PARM_2
6633 \end_layout
6634
6635 \begin_layout Standard
6636
6637 \family typewriter
6638 __divuint_reste_1_1
6639 \end_layout
6640
6641 \begin_layout Standard
6642
6643 \family typewriter
6644 __divuint_count_1_1
6645 \end_layout
6646
6647 \begin_layout Standard
6648
6649 \family typewriter
6650 __divuint
6651 \newline
6652 _modsint.rel:
6653 \end_layout
6654
6655 \begin_layout Standard
6656
6657 \family typewriter
6658 __modsint_a_1_1
6659 \end_layout
6660
6661 \begin_layout Standard
6662
6663 \family typewriter
6664 __modsint_PARM_2
6665 \end_layout
6666
6667 \begin_layout Standard
6668
6669 \family typewriter
6670 __modsint
6671 \newline
6672 _moduint.rel:
6673 \end_layout
6674
6675 \begin_layout Standard
6676
6677 \family typewriter
6678 __moduint_a_1_1
6679 \end_layout
6680
6681 \begin_layout Standard
6682
6683 \family typewriter
6684 __moduint_PARM_2
6685 \end_layout
6686
6687 \begin_layout Standard
6688
6689 \family typewriter
6690 __moduint_count_1_1
6691 \end_layout
6692
6693 \begin_layout Standard
6694
6695 \family typewriter
6696 __moduint
6697 \newline
6698 _mulint.rel:
6699 \end_layout
6700
6701 \begin_layout Standard
6702
6703 \family typewriter
6704 __mulint_PARM_2
6705 \end_layout
6706
6707 \begin_layout Standard
6708
6709 \family typewriter
6710 __mulint
6711 \family default
6712 \series bold
6713
6714 \newline
6715
6716 \end_layout
6717
6718 \begin_layout Standard
6719 If the source files are compiled using -
6720 \begin_inset ERT
6721 status collapsed
6722
6723 \begin_layout Standard
6724
6725
6726 \backslash
6727 /
6728 \end_layout
6729
6730 \end_inset
6731
6732 -debug
6733 \begin_inset LatexCommand \index{-\/-debug}
6734
6735 \end_inset
6736
6737 , the corresponding debug information file .adb will be include in the library
6738  file as well.
6739  The library files created with sdcclib are plain text files, so they can
6740  be viewed with a text editor.
6741  It is not recomended to modify a library file created with sdcclib using
6742  a text editor, as there are file indexes numbers located accross the file
6743  used by the linker to quickly locate the required module to link.
6744  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6745  it can be safely deleted, since all the information required for linking
6746  is embedded in the library file itself.
6747  Library files created using sdcclib are used as described in the preceding
6748  sections.
6749 \begin_inset VSpace bigskip
6750 \end_inset
6751
6752
6753 \end_layout
6754
6755 \begin_layout Section
6756 Command Line Options
6757 \begin_inset LatexCommand \index{Command Line Options}
6758
6759 \end_inset
6760
6761
6762 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6763
6764 \end_inset
6765
6766
6767 \end_layout
6768
6769 \begin_layout Subsection
6770 Processor Selection Options
6771 \begin_inset LatexCommand \index{Options processor selection}
6772
6773 \end_inset
6774
6775
6776 \begin_inset LatexCommand \index{Processor selection options}
6777
6778 \end_inset
6779
6780
6781 \end_layout
6782
6783 \begin_layout List
6784 \labelwidthstring 00.00.0000
6785
6786 \series bold
6787 -mmcs51
6788 \begin_inset LatexCommand \index{-mmcs51}
6789
6790 \end_inset
6791
6792
6793 \series default
6794  Generate code for the Intel MCS51
6795 \begin_inset LatexCommand \index{MCS51}
6796
6797 \end_inset
6798
6799  family of processors.
6800  This is the default processor target.
6801 \end_layout
6802
6803 \begin_layout List
6804 \labelwidthstring 00.00.0000
6805
6806 \series bold
6807 -mds390
6808 \begin_inset LatexCommand \index{-mds390}
6809
6810 \end_inset
6811
6812
6813 \series default
6814  Generate code for the Dallas DS80C390
6815 \begin_inset LatexCommand \index{DS80C390}
6816
6817 \end_inset
6818
6819  processor.
6820 \end_layout
6821
6822 \begin_layout List
6823 \labelwidthstring 00.00.0000
6824
6825 \series bold
6826 -mds400
6827 \begin_inset LatexCommand \index{-mds400}
6828
6829 \end_inset
6830
6831
6832 \series default
6833  Generate code for the Dallas DS80C400
6834 \begin_inset LatexCommand \index{DS80C400}
6835
6836 \end_inset
6837
6838  processor.
6839 \end_layout
6840
6841 \begin_layout List
6842 \labelwidthstring 00.00.0000
6843
6844 \series bold
6845 -mhc08
6846 \begin_inset LatexCommand \index{-mhc08}
6847
6848 \end_inset
6849
6850
6851 \series default
6852  Generate code for the Freescale/Motorola HC08
6853 \begin_inset LatexCommand \index{HC08}
6854
6855 \end_inset
6856
6857  family of processors.
6858 \end_layout
6859
6860 \begin_layout List
6861 \labelwidthstring 00.00.0000
6862
6863 \series bold
6864 -mz80
6865 \begin_inset LatexCommand \index{-mz80}
6866
6867 \end_inset
6868
6869
6870 \series default
6871  Generate code for the Zilog Z80
6872 \begin_inset LatexCommand \index{Z80}
6873
6874 \end_inset
6875
6876  family of processors.
6877 \end_layout
6878
6879 \begin_layout List
6880 \labelwidthstring 00.00.0000
6881
6882 \series bold
6883 -mgbz80
6884 \begin_inset LatexCommand \index{-mgbz80}
6885
6886 \end_inset
6887
6888
6889 \series default
6890  Generate code for the GameBoy Z80
6891 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6892
6893 \end_inset
6894
6895  processor (Not actively maintained).
6896 \end_layout
6897
6898 \begin_layout List
6899 \labelwidthstring 00.00.0000
6900
6901 \series bold
6902 -mavr
6903 \begin_inset LatexCommand \index{-mavr}
6904
6905 \end_inset
6906
6907
6908 \series default
6909  Generate code for the Atmel AVR
6910 \begin_inset LatexCommand \index{AVR}
6911
6912 \end_inset
6913
6914  processor (Not maintained, not complete).
6915  AVR users should probably have a look at winavr 
6916 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6917
6918 \end_inset
6919
6920  or 
6921 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6922
6923 \end_inset
6924
6925 , which is based on AVR-port of the gcc compiler.
6926 \end_layout
6927
6928 \begin_layout Standard
6929 \begin_inset Note Note
6930 status collapsed
6931
6932 \begin_layout Standard
6933 I think it is fair to direct users there for now.
6934  Open source is also about avoiding unnecessary work .
6935  But I didn't find the 'official' link.
6936 \end_layout
6937
6938 \end_inset
6939
6940
6941 \end_layout
6942
6943 \begin_layout List
6944 \labelwidthstring 00.00.0000
6945
6946 \series bold
6947 -mpic14
6948 \begin_inset LatexCommand \index{-mpic14}
6949
6950 \end_inset
6951
6952
6953 \series default
6954  Generate code for the Microchip PIC 14
6955 \begin_inset LatexCommand \index{PIC14}
6956
6957 \end_inset
6958
6959 -bit processors (p16f84 and variants.
6960  In development, not complete).
6961 \end_layout
6962
6963 \begin_layout Standard
6964 \begin_inset Note Note
6965 status collapsed
6966
6967 \begin_layout Standard
6968 p16f627 p16f628 p16f84 p16f873 p16f877?
6969 \end_layout
6970
6971 \end_inset
6972
6973
6974 \end_layout
6975
6976 \begin_layout List
6977 \labelwidthstring 00.00.0000
6978
6979 \series bold
6980 -mpic16
6981 \begin_inset LatexCommand \index{-mpic16}
6982
6983 \end_inset
6984
6985
6986 \series default
6987  Generate code for the Microchip PIC 16
6988 \begin_inset LatexCommand \index{PIC16}
6989
6990 \end_inset
6991
6992 -bit processors (p18f452 and variants.
6993  In development, not complete).
6994 \end_layout
6995
6996 \begin_layout List
6997 \labelwidthstring 00.00.0000
6998
6999 \series bold
7000 -mtlcs900h
7001 \series default
7002  Generate code for the Toshiba TLCS-900H
7003 \begin_inset LatexCommand \index{TLCS-900H}
7004
7005 \end_inset
7006
7007  processor (Not maintained, not complete).
7008 \end_layout
7009
7010 \begin_layout List
7011 \labelwidthstring 00.00.0000
7012
7013 \series bold
7014 -mxa51
7015 \begin_inset LatexCommand \index{-mxa51}
7016
7017 \end_inset
7018
7019
7020 \series default
7021  Generate code for the Phillips XA51
7022 \begin_inset LatexCommand \index{XA51}
7023
7024 \end_inset
7025
7026  processor (Not maintained, not complete).
7027 \end_layout
7028
7029 \begin_layout Standard
7030 \begin_inset VSpace bigskip
7031 \end_inset
7032
7033
7034 \end_layout
7035
7036 \begin_layout Subsection
7037 Preprocessor Options
7038 \begin_inset LatexCommand \index{Options preprocessor}
7039
7040 \end_inset
7041
7042
7043 \begin_inset LatexCommand \index{Preprocessor options}
7044
7045 \end_inset
7046
7047
7048 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7049
7050 \end_inset
7051
7052
7053 \end_layout
7054
7055 \begin_layout List
7056 \labelwidthstring 00.00.0000
7057
7058 \series bold
7059 -I<path>
7060 \begin_inset LatexCommand \index{-I<path>}
7061
7062 \end_inset
7063
7064
7065 \series default
7066  The additional location where the preprocessor will look for <..h> or 
7067 \begin_inset Quotes eld
7068 \end_inset
7069
7070 ..h
7071 \begin_inset Quotes erd
7072 \end_inset
7073
7074  files.
7075 \end_layout
7076
7077 \begin_layout List
7078 \labelwidthstring 00.00.0000
7079
7080 \series bold
7081 -D<macro[=value]>
7082 \begin_inset LatexCommand \index{-D<macro[=value]>}
7083
7084 \end_inset
7085
7086
7087 \series default
7088  Command line definition of macros.
7089  Passed to the preprocessor.
7090 \end_layout
7091
7092 \begin_layout List
7093 \labelwidthstring 00.00.0000
7094
7095 \series bold
7096 -M
7097 \begin_inset LatexCommand \index{-M}
7098
7099 \end_inset
7100
7101
7102 \series default
7103  Tell the preprocessor to output a rule suitable for make describing the
7104  dependencies of each object file.
7105  For each source file, the preprocessor outputs one make-rule whose target
7106  is the object file name for that source file and whose dependencies are
7107  all the files `#include'd in it.
7108  This rule may be a single line or may be continued with `
7109 \backslash
7110 '-newline if it is long.
7111  The list of rules is printed on standard output instead of the preprocessed
7112  C program.
7113  `-M' implies `-E
7114 \begin_inset LatexCommand \index{-E}
7115
7116 \end_inset
7117
7118 '.
7119 \end_layout
7120
7121 \begin_layout List
7122 \labelwidthstring 00.00.0000
7123
7124 \series bold
7125 -C
7126 \begin_inset LatexCommand \index{-C}
7127
7128 \end_inset
7129
7130
7131 \series default
7132  Tell the preprocessor not to discard comments.
7133  Used with the `-E' option.
7134 \end_layout
7135
7136 \begin_layout List
7137 \labelwidthstring 00.00.0000
7138
7139 \series bold
7140 -MM
7141 \begin_inset LatexCommand \index{-MM}
7142
7143 \end_inset
7144
7145
7146 \size large
7147 \bar under
7148  
7149 \series default
7150 \size default
7151 \bar default
7152 Like `-M' but the output mentions only the user header files included with
7153  `#include 
7154 \begin_inset Quotes eld
7155 \end_inset
7156
7157 file"'.
7158  System header files included with `#include <file>' are omitted.
7159 \end_layout
7160
7161 \begin_layout List
7162 \labelwidthstring 00.00.0000
7163
7164 \series bold
7165 -Aquestion(answer)
7166 \begin_inset LatexCommand \index{-Aquestion(answer)}
7167
7168 \end_inset
7169
7170
7171 \series default
7172  Assert the answer answer for question, in case it is tested with a preprocessor
7173  conditional such as `#if #question(answer)'.
7174  `-A-' disables the standard assertions that normally describe the target
7175  machine.
7176 \end_layout
7177
7178 \begin_layout List
7179 \labelwidthstring 00.00.0000
7180
7181 \series bold
7182 -Umacro
7183 \begin_inset LatexCommand \index{-Umacro}
7184
7185 \end_inset
7186
7187
7188 \series default
7189  Undefine macro macro.
7190  `-U' options are evaluated after all `-D' options, but before any `-include'
7191  and `-imacros' options.
7192 \end_layout
7193
7194 \begin_layout List
7195 \labelwidthstring 00.00.0000
7196
7197 \series bold
7198 -dM
7199 \begin_inset LatexCommand \index{-dM}
7200
7201 \end_inset
7202
7203
7204 \series default
7205  Tell the preprocessor to output only a list of the macro definitions that
7206  are in effect at the end of preprocessing.
7207  Used with the `-E' option.
7208 \end_layout
7209
7210 \begin_layout List
7211 \labelwidthstring 00.00.0000
7212
7213 \series bold
7214 -dD
7215 \begin_inset LatexCommand \index{-dD}
7216
7217 \end_inset
7218
7219
7220 \series default
7221  Tell the preprocessor to pass all macro definitions into the output, in
7222  their proper sequence in the rest of the output.
7223 \end_layout
7224
7225 \begin_layout List
7226 \labelwidthstring 00.00.0000
7227
7228 \series bold
7229 -dN
7230 \begin_inset LatexCommand \index{-dN}
7231
7232 \end_inset
7233
7234
7235 \size large
7236 \bar under
7237  
7238 \series default
7239 \size default
7240 \bar default
7241 Like `-dD' except that the macro arguments and contents are omitted.
7242  Only `#define name' is included in the output.
7243 \end_layout
7244
7245 \begin_layout List
7246 \labelwidthstring 00.00.0000
7247
7248 \series bold
7249 -pedantic-parse-number
7250 \begin_inset LatexCommand \index{pedantic}
7251
7252 \end_inset
7253
7254
7255 \begin_inset LatexCommand \index{-pedantic-parse-number}
7256
7257 \end_inset
7258
7259
7260 \size large
7261 \bar under
7262
7263 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
7264
7265 \end_inset
7266
7267  
7268 \series default
7269 \size default
7270 \bar default
7271 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7272  and the macro LO_B(3) gets expanded.
7273  See also #pragma pedantic_parse_number 
7274 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
7275
7276 \end_inset
7277
7278  in section
7279 \begin_inset LatexCommand \ref{sec:Pragmas}
7280
7281 \end_inset
7282
7283  
7284 \emph on
7285 Note: this functionality is not in conformance with C99 standard!
7286 \end_layout
7287
7288 \begin_layout List
7289 \labelwidthstring 00.00.0000
7290
7291 \series bold
7292 -Wp\InsetSpace ~
7293 preprocessorOption[,preprocessorOption]
7294 \series default
7295
7296 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
7297
7298 \end_inset
7299
7300 ...
7301  Pass the preprocessorOption to the preprocessor 
7302 \family typewriter
7303 sdcpp
7304 \family default
7305
7306 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
7307
7308 \end_inset
7309
7310 .
7311  SDCC uses an adapted version of the preprocessor 
7312 \emph on
7313 cpp
7314 \emph default
7315  of the GNU Compiler Collection
7316 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
7317
7318 \end_inset
7319
7320  (
7321 \emph on
7322 gcc
7323 \emph default
7324  
7325 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7326
7327 \end_inset
7328
7329 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7330 4.1.1\InsetSpace ~
7331 CPP\InsetSpace ~
7332 Manual
7333  at 
7334 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7335
7336 \end_inset
7337
7338 .
7339 \end_layout
7340
7341 \begin_layout Standard
7342 \begin_inset VSpace bigskip
7343 \end_inset
7344
7345
7346 \end_layout
7347
7348 \begin_layout Subsection
7349 Linker Options
7350 \begin_inset LatexCommand \index{Options linker}
7351
7352 \end_inset
7353
7354
7355 \begin_inset LatexCommand \index{Linker options}
7356
7357 \end_inset
7358
7359
7360 \end_layout
7361
7362 \begin_layout List
7363 \labelwidthstring 00.00.0000
7364
7365 \series bold
7366 -L\InsetSpace ~
7367 -
7368 \series default
7369
7370 \begin_inset ERT
7371 status collapsed
7372
7373 \begin_layout Standard
7374
7375
7376 \backslash
7377 /
7378 \end_layout
7379
7380 \end_inset
7381
7382
7383 \series bold
7384 -lib-path
7385 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7386
7387 \end_inset
7388
7389
7390 \begin_inset LatexCommand \index{-L -\/-lib-path}
7391
7392 \end_inset
7393
7394
7395 \series default
7396 \InsetSpace ~
7397 <absolute path to additional libraries> This option is passed to the linkage
7398  editor's additional libraries
7399 \begin_inset LatexCommand \index{Libraries}
7400
7401 \end_inset
7402
7403  search path.
7404  The path name must be absolute.
7405  Additional library files may be specified in the command line.
7406  See section Compiling programs for more details.
7407 \end_layout
7408
7409 \begin_layout List
7410 \labelwidthstring 00.00.0000
7411
7412 \series bold
7413 -
7414 \begin_inset ERT
7415 status collapsed
7416
7417 \begin_layout Standard
7418
7419
7420 \backslash
7421 /
7422 \end_layout
7423
7424 \end_inset
7425
7426 -xram-loc
7427 \series default
7428
7429 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7430
7431 \end_inset
7432
7433 \InsetSpace ~
7434 <Value> The start location of the external ram
7435 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7436
7437 \end_inset
7438
7439 , default value is 0.
7440  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7441 \begin_inset ERT
7442 status collapsed
7443
7444 \begin_layout Standard
7445
7446
7447 \backslash
7448 /
7449 \end_layout
7450
7451 \end_inset
7452
7453 -xram-loc 0x8000 or -
7454 \begin_inset ERT
7455 status collapsed
7456
7457 \begin_layout Standard
7458
7459
7460 \backslash
7461 /
7462 \end_layout
7463
7464 \end_inset
7465
7466 -xram-loc 32768.
7467 \end_layout
7468
7469 \begin_layout List
7470 \labelwidthstring 00.00.0000
7471
7472 \series bold
7473 -
7474 \begin_inset ERT
7475 status collapsed
7476
7477 \begin_layout Standard
7478
7479
7480 \backslash
7481 /
7482 \end_layout
7483
7484 \end_inset
7485
7486 -code-loc
7487 \series default
7488
7489 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7490
7491 \end_inset
7492
7493 \InsetSpace ~
7494 <Value> The start location of the code
7495 \begin_inset LatexCommand \index{code}
7496
7497 \end_inset
7498
7499  segment, default value 0.
7500  Note when this option is used the interrupt vector table
7501 \begin_inset LatexCommand \index{interrupt vector table}
7502
7503 \end_inset
7504
7505  is also relocated to the given address.
7506  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7507 \begin_inset ERT
7508 status collapsed
7509
7510 \begin_layout Standard
7511
7512
7513 \backslash
7514 /
7515 \end_layout
7516
7517 \end_inset
7518
7519 -code-loc 0x8000 or -
7520 \begin_inset ERT
7521 status collapsed
7522
7523 \begin_layout Standard
7524
7525
7526 \backslash
7527 /
7528 \end_layout
7529
7530 \end_inset
7531
7532 -code-loc 32768.
7533 \end_layout
7534
7535 \begin_layout List
7536 \labelwidthstring 00.00.0000
7537
7538 \series bold
7539 -
7540 \begin_inset ERT
7541 status collapsed
7542
7543 \begin_layout Standard
7544
7545
7546 \backslash
7547 /
7548 \end_layout
7549
7550 \end_inset
7551
7552 -stack-loc
7553 \series default
7554
7555 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7556
7557 \end_inset
7558
7559 \InsetSpace ~
7560 <Value> By default the stack
7561 \begin_inset LatexCommand \index{stack}
7562
7563 \end_inset
7564
7565  is placed after the data segment.
7566  Using this option the stack can be placed anywhere in the internal memory
7567  space of the 8051.
7568  The value entered can be in Hexadecimal or Decimal format, e.g.
7569  -
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 0x20 or -
7583 \begin_inset ERT
7584 status collapsed
7585
7586 \begin_layout Standard
7587
7588
7589 \backslash
7590 /
7591 \end_layout
7592
7593 \end_inset
7594
7595 -stack-loc 32.
7596  Since the sp register is incremented before a push or call, the initial
7597  sp will be set to one byte prior the provided value.
7598  The provided value should not overlap any other memory areas such as used
7599  register banks or the data segment and with enough space for the current
7600  application.
7601  The 
7602 \series bold
7603 -
7604 \begin_inset ERT
7605 status collapsed
7606
7607 \begin_layout Standard
7608
7609
7610 \backslash
7611 /
7612 \end_layout
7613
7614 \end_inset
7615
7616 -pack-iram
7617 \series default
7618 \InsetSpace ~
7619
7620 \begin_inset LatexCommand \index{-\/-pack-iram}
7621
7622 \end_inset
7623
7624  option (which is now a default setting) will override this setting, so
7625  you should also specify the 
7626 \series bold
7627 -
7628 \begin_inset ERT
7629 status collapsed
7630
7631 \begin_layout Standard
7632
7633
7634 \backslash
7635 /
7636 \end_layout
7637
7638 \end_inset
7639
7640 -no-pack-iram
7641 \series default
7642 \InsetSpace ~
7643
7644 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7645
7646 \end_inset
7647
7648  option if you need to manually place the stack.
7649 \end_layout
7650
7651 \begin_layout List
7652 \labelwidthstring 00.00.0000
7653
7654 \series bold
7655 -
7656 \begin_inset ERT
7657 status collapsed
7658
7659 \begin_layout Standard
7660
7661
7662 \backslash
7663 /
7664 \end_layout
7665
7666 \end_inset
7667
7668 -xstack-loc
7669 \series default
7670
7671 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7672
7673 \end_inset
7674
7675 \InsetSpace ~
7676 <Value> By default the external stack
7677 \begin_inset LatexCommand \index{xstack}
7678
7679 \end_inset
7680
7681  is placed after the pdata
7682 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7683
7684 \end_inset
7685
7686  segment.
7687  Using this option the xstack can be placed anywhere in the external memory
7688  space of the 8051.
7689  The value entered can be in Hexadecimal or Decimal format, e.g.
7690  -
7691 \begin_inset ERT
7692 status collapsed
7693
7694 \begin_layout Standard
7695
7696
7697 \backslash
7698 /
7699 \end_layout
7700
7701 \end_inset
7702
7703 -xstack-loc 0x8000 or -
7704 \begin_inset ERT
7705 status collapsed
7706
7707 \begin_layout Standard
7708
7709
7710 \backslash
7711 /
7712 \end_layout
7713
7714 \end_inset
7715
7716 -stack-loc 32768.
7717  The provided value should not overlap any other memory areas such as the
7718  pdata or xdata segment and with enough space for the current application.
7719 \end_layout
7720
7721 \begin_layout List
7722 \labelwidthstring 00.00.0000
7723
7724 \series bold
7725 -
7726 \begin_inset ERT
7727 status collapsed
7728
7729 \begin_layout Standard
7730
7731
7732 \backslash
7733 /
7734 \end_layout
7735
7736 \end_inset
7737
7738 -data-loc
7739 \series default
7740
7741 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7742
7743 \end_inset
7744
7745 \InsetSpace ~
7746 <Value> The start location of the internal ram data
7747 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7748
7749 \end_inset
7750
7751  segment.
7752  The value entered can be in Hexadecimal or Decimal format, eg.
7753  -
7754 \begin_inset ERT
7755 status collapsed
7756
7757 \begin_layout Standard
7758
7759
7760 \backslash
7761 /
7762 \end_layout
7763
7764 \end_inset
7765
7766 -data-loc 0x20 or -
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 -data-loc 32.
7780  (By default, the start location of the internal ram data segment  is set
7781  as low as possible in memory, taking into account the used register banks
7782  and the bit segment at address 0x20.
7783  For example if register banks 0 and 1 are used without bit variables, the
7784  data segment will be set, if -
7785 \begin_inset ERT
7786 status collapsed
7787
7788 \begin_layout Standard
7789
7790
7791 \backslash
7792 /
7793 \end_layout
7794
7795 \end_inset
7796
7797 -data-loc is not used, to location 0x10.)
7798 \end_layout
7799
7800 \begin_layout List
7801 \labelwidthstring 00.00.0000
7802
7803 \series bold
7804 -
7805 \begin_inset ERT
7806 status collapsed
7807
7808 \begin_layout Standard
7809
7810
7811 \backslash
7812 /
7813 \end_layout
7814
7815 \end_inset
7816
7817 -idata-loc
7818 \series default
7819
7820 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7821
7822 \end_inset
7823
7824 \InsetSpace ~
7825 <Value> The start location of the indirectly addressable internal ram
7826 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7827
7828 \end_inset
7829
7830  of the 8051, default value is 0x80.
7831  The value entered can be in Hexadecimal or Decimal format, eg.
7832  -
7833 \begin_inset ERT
7834 status collapsed
7835
7836 \begin_layout Standard
7837
7838
7839 \backslash
7840 /
7841 \end_layout
7842
7843 \end_inset
7844
7845 -idata-loc 0x88 or -
7846 \begin_inset ERT
7847 status collapsed
7848
7849 \begin_layout Standard
7850
7851
7852 \backslash
7853 /
7854 \end_layout
7855
7856 \end_inset
7857
7858 -idata-loc 136.
7859 \end_layout
7860
7861 \begin_layout List
7862 \labelwidthstring 00.00.0000
7863
7864 \series bold
7865 -
7866 \begin_inset ERT
7867 status collapsed
7868
7869 \begin_layout Standard
7870
7871
7872 \backslash
7873 /
7874 \end_layout
7875
7876 \end_inset
7877
7878 -bit-loc
7879 \series default
7880 \InsetSpace ~
7881 <Value> The start location of the bit
7882 \begin_inset LatexCommand \index{bit}
7883
7884 \end_inset
7885
7886  addressable internal ram of the 8051.
7887  This is 
7888 \emph on
7889 not
7890 \emph default
7891  implemented yet.
7892  Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7893 -bBSEG=<Value>.
7894 \end_layout
7895
7896 \begin_layout List
7897 \labelwidthstring 00.00.0000
7898
7899 \series bold
7900 -
7901 \begin_inset ERT
7902 status collapsed
7903
7904 \begin_layout Standard
7905
7906
7907 \backslash
7908 /
7909 \end_layout
7910
7911 \end_inset
7912
7913 -out-fmt-ihx
7914 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7915
7916 \end_inset
7917
7918
7919 \bar under
7920  
7921 \series default
7922 \bar default
7923 The linker output (final object code) is in Intel Hex format.
7924 \begin_inset LatexCommand \index{Intel hex format}
7925
7926 \end_inset
7927
7928  This is the default option.
7929  The format itself is documented in the documentation of srecord
7930 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7931
7932 \end_inset
7933
7934 .
7935 \end_layout
7936
7937 \begin_layout List
7938 \labelwidthstring 00.00.0000
7939
7940 \series bold
7941 -
7942 \begin_inset ERT
7943 status collapsed
7944
7945 \begin_layout Standard
7946
7947
7948 \backslash
7949 /
7950 \end_layout
7951
7952 \end_inset
7953
7954 -out-fmt-s19
7955 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7956
7957 \end_inset
7958
7959
7960 \bar under
7961  
7962 \series default
7963 \bar default
7964 The linker output (final object code) is in Motorola S19 format
7965 \begin_inset LatexCommand \index{Motorola S19 format}
7966
7967 \end_inset
7968
7969 .
7970  The format itself is documented in the documentation of srecord.
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 -out-fmt-elf
7991 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7992
7993 \end_inset
7994
7995
7996 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7997
7998 \end_inset
7999
8000
8001 \bar under
8002  
8003 \series default
8004 \bar default
8005 The linker output (final object code) is in ELF format
8006 \begin_inset LatexCommand \index{ELF format}
8007
8008 \end_inset
8009
8010 .
8011  (Currently only supported for the HC08
8012 \begin_inset LatexCommand \index{HC08}
8013
8014 \end_inset
8015
8016  processors)
8017 \end_layout
8018
8019 \begin_layout List
8020 \labelwidthstring 00.00.0000
8021
8022 \series bold
8023 -Wl\InsetSpace ~
8024 linkOption[,linkOption]
8025 \series default
8026
8027 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
8028
8029 \end_inset
8030
8031 ...
8032  Pass the linkOption to the linker.
8033  If a bootloader is used an option like 
8034 \begin_inset Quotes sld
8035 \end_inset
8036
8037 -Wl\InsetSpace ~
8038 -bCSEG=0x1000
8039 \begin_inset Quotes srd
8040 \end_inset
8041
8042  would be typical to set the start of the code segment.
8043  See also #pragma constseg and #pragma codeseg in section 
8044 \begin_inset LatexCommand \ref{sec:Pragmas}
8045
8046 \end_inset
8047
8048  .
8049  File sdcc/as/doc/asxhtm.html has more on linker options.
8050 \end_layout
8051
8052 \begin_layout Standard
8053 \begin_inset VSpace bigskip
8054 \end_inset
8055
8056
8057 \end_layout
8058
8059 \begin_layout Subsection
8060 MCS51 Options
8061 \begin_inset LatexCommand \index{Options MCS51}
8062
8063 \end_inset
8064
8065
8066 \begin_inset LatexCommand \index{MCS51 options}
8067
8068 \end_inset
8069
8070
8071 \end_layout
8072
8073 \begin_layout List
8074 \labelwidthstring 00.00.0000
8075
8076 \series bold
8077 -
8078 \begin_inset ERT
8079 status collapsed
8080
8081 \begin_layout Standard
8082
8083
8084 \backslash
8085 /
8086 \end_layout
8087
8088 \end_inset
8089
8090 -model-small
8091 \begin_inset LatexCommand \index{-\/-model-small}
8092
8093 \end_inset
8094
8095
8096 \series default
8097 \size large
8098 \emph on
8099  
8100 \size default
8101 \emph default
8102 Generate code for Small Model programs, see section Memory Models for more
8103  details.
8104  This is the default model.
8105 \end_layout
8106
8107 \begin_layout List
8108 \labelwidthstring 00.00.0000
8109
8110 \series bold
8111 -
8112 \begin_inset ERT
8113 status collapsed
8114
8115 \begin_layout Standard
8116
8117
8118 \backslash
8119 /
8120 \end_layout
8121
8122 \end_inset
8123
8124 -model-medium
8125 \begin_inset LatexCommand \index{-\/-model-medium}
8126
8127 \end_inset
8128
8129
8130 \series default
8131  Generate code for Medium model programs, see section Memory Models for
8132  more details.
8133  If this option is used all source files in the project have to be compiled
8134  with this option.
8135  It must also be used when invoking the linker.
8136 \end_layout
8137
8138 \begin_layout List
8139 \labelwidthstring 00.00.0000
8140
8141 \series bold
8142 -
8143 \begin_inset ERT
8144 status collapsed
8145
8146 \begin_layout Standard
8147
8148
8149 \backslash
8150 /
8151 \end_layout
8152
8153 \end_inset
8154
8155 -model-large
8156 \begin_inset LatexCommand \index{-\/-model-large}
8157
8158 \end_inset
8159
8160
8161 \series default
8162  Generate code for Large model programs, see section Memory Models for more
8163  details.
8164  If this option is used all source files in the project have to be compiled
8165  with this option.
8166  It must also be used when invoking the linker.
8167 \end_layout
8168
8169 \begin_layout List
8170 \labelwidthstring 00.00.0000
8171
8172 \series bold
8173 -
8174 \begin_inset ERT
8175 status collapsed
8176
8177 \begin_layout Standard
8178
8179
8180 \backslash
8181 /
8182 \end_layout
8183
8184 \end_inset
8185
8186 -xstack
8187 \begin_inset LatexCommand \index{-\/-xstack}
8188
8189 \end_inset
8190
8191
8192 \series default
8193  Uses a pseudo stack in the pdata
8194 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8195
8196 \end_inset
8197
8198  area (usually the first 256 bytes in the external ram) for allocating variables
8199  and passing parameters.
8200  See section 
8201 \begin_inset LatexCommand \ref{sub:External-Stack}
8202
8203 \end_inset
8204
8205 \InsetSpace ~
8206  External Stack for more details.
8207 \end_layout
8208
8209 \begin_layout List
8210 \labelwidthstring 00.00.0000
8211
8212 \series bold
8213 -
8214 \begin_inset ERT
8215 status collapsed
8216
8217 \begin_layout Standard
8218
8219
8220 \backslash
8221 /
8222 \end_layout
8223
8224 \end_inset
8225
8226 -iram-size
8227 \series default
8228 \InsetSpace ~
8229 <Value>
8230 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
8231
8232 \end_inset
8233
8234  Causes the linker to check if the internal ram usage is within limits of
8235  the given value.
8236 \end_layout
8237
8238 \begin_layout List
8239 \labelwidthstring 00.00.0000
8240
8241 \series bold
8242 -
8243 \begin_inset ERT
8244 status collapsed
8245
8246 \begin_layout Standard
8247
8248
8249 \backslash
8250 /
8251 \end_layout
8252
8253 \end_inset
8254
8255 -xram-size
8256 \series default
8257 \InsetSpace ~
8258 <Value>
8259 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
8260
8261 \end_inset
8262
8263  Causes the linker to check if the external ram usage is within limits of
8264  the given value.
8265 \end_layout
8266
8267 \begin_layout List
8268 \labelwidthstring 00.00.0000
8269
8270 \series bold
8271 -
8272 \begin_inset ERT
8273 status collapsed
8274
8275 \begin_layout Standard
8276
8277
8278 \backslash
8279 /
8280 \end_layout
8281
8282 \end_inset
8283
8284 -code-size
8285 \series default
8286 \InsetSpace ~
8287 <Value>
8288 \begin_inset LatexCommand \index{-\/-code-size <Value>}
8289
8290 \end_inset
8291
8292  Causes the linker to check if the code memory usage is within limits of
8293  the given value.
8294 \end_layout
8295
8296 \begin_layout List
8297 \labelwidthstring 00.00.0000
8298
8299 \series bold
8300 -
8301 \begin_inset ERT
8302 status collapsed
8303
8304 \begin_layout Standard
8305
8306
8307 \backslash
8308 /
8309 \end_layout
8310
8311 \end_inset
8312
8313 -stack-size
8314 \series default
8315 \InsetSpace ~
8316 <Value>
8317 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
8318
8319 \end_inset
8320
8321  Causes the linker to check if there is at minimum <Value> bytes for stack.
8322 \end_layout
8323
8324 \begin_layout List
8325 \labelwidthstring 00.00.0000
8326
8327 \series bold
8328 -
8329 \begin_inset ERT
8330 status collapsed
8331
8332 \begin_layout Standard
8333
8334
8335 \backslash
8336 /
8337 \end_layout
8338
8339 \end_inset
8340
8341 -pack-iram
8342 \series default
8343 \InsetSpace ~
8344
8345 \begin_inset LatexCommand \index{-\/-pack-iram}
8346
8347 \end_inset
8348
8349  Causes the linker to use unused register banks for data variables and pack
8350  data, idata and stack together.
8351  This is the default now.
8352 \end_layout
8353
8354 \begin_layout List
8355 \labelwidthstring 00.00.0000
8356
8357 \series bold
8358 -
8359 \begin_inset ERT
8360 status collapsed
8361
8362 \begin_layout Standard
8363
8364
8365 \backslash
8366 /
8367 \end_layout
8368
8369 \end_inset
8370
8371 -no-pack-iram
8372 \series default
8373 \InsetSpace ~
8374
8375 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8376
8377 \end_inset
8378
8379  Causes the linker to use old style for allocating memory areas.
8380 \end_layout
8381
8382 \begin_layout List
8383 \labelwidthstring 00.00.0000
8384
8385 \series bold
8386 -
8387 \begin_inset ERT
8388 status collapsed
8389
8390 \begin_layout Standard
8391
8392
8393 \backslash
8394 /
8395 \end_layout
8396
8397 \end_inset
8398
8399 -acall-ajmp
8400 \series default
8401 \InsetSpace ~
8402
8403 \begin_inset LatexCommand \index{-\/-acall-ajmp}
8404
8405 \end_inset
8406
8407  Replaces the three byte instructions lcall/ljmp with the two byte instructions
8408  acall/ajmp.
8409  Only use this option if your code is in the same 2k block of memory.
8410  You may need to use this option for some 8051 derivatives which lack the
8411  lcall/ljmp instructions..
8412 \end_layout
8413
8414 \begin_layout Standard
8415 \begin_inset VSpace bigskip
8416 \end_inset
8417
8418
8419 \end_layout
8420
8421 \begin_layout Subsection
8422 DS390 / DS400 Options
8423 \begin_inset LatexCommand \index{Options DS390}
8424
8425 \end_inset
8426
8427
8428 \begin_inset LatexCommand \index{DS390}
8429
8430 \end_inset
8431
8432
8433 \end_layout
8434
8435 \begin_layout List
8436 \labelwidthstring 00.00.0000
8437
8438 \series bold
8439 -
8440 \begin_inset ERT
8441 status collapsed
8442
8443 \begin_layout Standard
8444
8445
8446 \backslash
8447 /
8448 \end_layout
8449
8450 \end_inset
8451
8452 -model-flat24
8453 \series default
8454
8455 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8456
8457 \end_inset
8458
8459
8460 \size large
8461 \emph on
8462  
8463 \size default
8464 \emph default
8465 Generate 24-bit flat mode code.
8466  This is the one and only that the ds390 code generator supports right now
8467  and is default when using 
8468 \emph on
8469 -mds390
8470 \emph default
8471 .
8472  See section Memory Models for more details.
8473 \end_layout
8474
8475 \begin_layout List
8476 \labelwidthstring 00.00.0000
8477
8478 \series bold
8479 -
8480 \begin_inset ERT
8481 status collapsed
8482
8483 \begin_layout Standard
8484
8485
8486 \backslash
8487 /
8488 \end_layout
8489
8490 \end_inset
8491
8492 -protect-sp-update
8493 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8494
8495 \end_inset
8496
8497
8498 \series default
8499  disable interrupts during ESP:SP updates.
8500 \end_layout
8501
8502 \begin_layout List
8503 \labelwidthstring 00.00.0000
8504
8505 \series bold
8506 -
8507 \begin_inset ERT
8508 status collapsed
8509
8510 \begin_layout Standard
8511
8512
8513 \backslash
8514 /
8515 \end_layout
8516
8517 \end_inset
8518
8519 -stack-10bit
8520 \series default
8521
8522 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8523
8524 \end_inset
8525
8526  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8527  This is the one and only that the ds390 code generator supports right now
8528  and is default when using 
8529 \emph on
8530 -mds390
8531 \emph default
8532 .
8533  In this mode, the stack is located in the lower 1K of the internal RAM,
8534  which is mapped to 0x400000.
8535  Note that the support is incomplete, since it still uses a single byte
8536  as the stack pointer.
8537  This means that only the lower 256 bytes of the potential 1K stack space
8538  will actually be used.
8539  However, this does allow you to reclaim the precious 256 bytes of low RAM
8540  for use for the DATA and IDATA segments.
8541  The compiler will not generate any code to put the processor into 10 bit
8542  stack mode.
8543  It is important to ensure that the processor is in this mode before calling
8544  any re-entrant functions compiled with this option.
8545  In principle, this should work with the 
8546 \emph on
8547 -
8548 \begin_inset ERT
8549 status collapsed
8550
8551 \begin_layout Standard
8552
8553
8554 \backslash
8555 /
8556 \end_layout
8557
8558 \end_inset
8559
8560 -stack-auto
8561 \begin_inset LatexCommand \index{-\/-stack-auto}
8562
8563 \end_inset
8564
8565
8566 \emph default
8567  option, but that has not been tested.
8568  It is incompatible with the 
8569 \emph on
8570 -
8571 \begin_inset ERT
8572 status collapsed
8573
8574 \begin_layout Standard
8575
8576
8577 \backslash
8578 /
8579 \end_layout
8580
8581 \end_inset
8582
8583 -xstack
8584 \begin_inset LatexCommand \index{-\/-xstack}
8585
8586 \end_inset
8587
8588
8589 \emph default
8590  option.
8591  It also only makes sense if the processor is in 24 bit contiguous addressing
8592  mode (see the 
8593 \emph on
8594 -
8595 \begin_inset ERT
8596 status collapsed
8597
8598 \begin_layout Standard
8599
8600
8601 \backslash
8602 /
8603 \end_layout
8604
8605 \end_inset
8606
8607 -model-flat24 option
8608 \emph default
8609 ).
8610 \series bold
8611
8612 \begin_inset Note Note
8613 status collapsed
8614
8615 \begin_layout List
8616 \labelwidthstring 00.00.0000
8617
8618 \series bold
8619 -
8620 \begin_inset ERT
8621 status open
8622
8623 \begin_layout Standard
8624
8625
8626 \backslash
8627 /
8628 \end_layout
8629
8630 \end_inset
8631
8632 -stack-8-bit - switches off the 10-bit mode
8633 \end_layout
8634
8635 \end_inset
8636
8637
8638 \end_layout
8639
8640 \begin_layout List
8641 \labelwidthstring 00.00.0000
8642
8643 \series bold
8644 -
8645 \begin_inset ERT
8646 status collapsed
8647
8648 \begin_layout Standard
8649
8650
8651 \backslash
8652 /
8653 \end_layout
8654
8655 \end_inset
8656
8657 -stack-probe
8658 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8659
8660 \end_inset
8661
8662
8663 \series default
8664  insert call to function __stack_probe at each function prologue.
8665 \end_layout
8666
8667 \begin_layout List
8668 \labelwidthstring 00.00.0000
8669
8670 \series bold
8671 -
8672 \begin_inset ERT
8673 status open
8674
8675 \begin_layout Standard
8676
8677
8678 \backslash
8679 /
8680 \end_layout
8681
8682 \end_inset
8683
8684 -tini-libid
8685 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8686
8687 \end_inset
8688
8689
8690 \series default
8691  <nnnn> LibraryID used in -mTININative.
8692  
8693 \end_layout
8694
8695 \begin_layout List
8696 \labelwidthstring 00.00.0000
8697
8698 \series bold
8699 -
8700 \begin_inset ERT
8701 status collapsed
8702
8703 \begin_layout Standard
8704
8705
8706 \backslash
8707 /
8708 \end_layout
8709
8710 \end_inset
8711
8712 -use-accelerator
8713 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8714
8715 \end_inset
8716
8717
8718 \series default
8719  generate code for DS390 Arithmetic Accelerator.
8720  
8721 \end_layout
8722
8723 \begin_layout Standard
8724 \begin_inset VSpace bigskip
8725 \end_inset
8726
8727
8728 \end_layout
8729
8730 \begin_layout Subsection
8731 Z80 Options
8732 \begin_inset LatexCommand \index{Options Z80}
8733
8734 \end_inset
8735
8736
8737 \begin_inset LatexCommand \index{Z80}
8738
8739 \end_inset
8740
8741
8742 \end_layout
8743
8744 \begin_layout List
8745 \labelwidthstring 00.00.0000
8746
8747 \series bold
8748 -
8749 \begin_inset ERT
8750 status collapsed
8751
8752 \begin_layout Standard
8753
8754
8755 \backslash
8756 /
8757 \end_layout
8758
8759 \end_inset
8760
8761 -callee-saves-bc
8762 \series default
8763
8764 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8765
8766 \end_inset
8767
8768
8769 \size large
8770 \emph on
8771  
8772 \size default
8773 \emph default
8774 Force a called function to always save BC.
8775 \end_layout
8776
8777 \begin_layout List
8778 \labelwidthstring 00.00.0000
8779
8780 \series bold
8781 -
8782 \begin_inset ERT
8783 status collapsed
8784
8785 \begin_layout Standard
8786
8787
8788 \backslash
8789 /
8790 \end_layout
8791
8792 \end_inset
8793
8794 -no-std-crt0
8795 \series default
8796
8797 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8798
8799 \end_inset
8800
8801  When linking, skip the standard crt0.o object file.
8802  You must provide your own crt0.o for your system when linking.
8803 \end_layout
8804
8805 \begin_layout List
8806 \labelwidthstring 00.00.0000
8807
8808 \series bold
8809 -
8810 \begin_inset ERT
8811 status collapsed
8812
8813 \begin_layout Standard
8814
8815
8816 \backslash
8817 /
8818 \end_layout
8819
8820 \end_inset
8821
8822 -portmode=
8823 \series default
8824 <Value>
8825 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8826
8827 \end_inset
8828
8829  Determinate PORT I/O mode (<Value> is z80 or z180).
8830 \end_layout
8831
8832 \begin_layout List
8833 \labelwidthstring 00.00.0000
8834
8835 \series bold
8836 -
8837 \begin_inset ERT
8838 status collapsed
8839
8840 \begin_layout Standard
8841
8842
8843 \backslash
8844 /
8845 \end_layout
8846
8847 \end_inset
8848
8849 -asm=
8850 \series default
8851 <Value>
8852 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8853
8854 \end_inset
8855
8856  Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8857 \end_layout
8858
8859 \begin_layout List
8860 \labelwidthstring 00.00.0000
8861
8862 \series bold
8863 -
8864 \begin_inset ERT
8865 status collapsed
8866
8867 \begin_layout Standard
8868
8869
8870 \backslash
8871 /
8872 \end_layout
8873
8874 \end_inset
8875
8876 -codeseg
8877 \series default
8878 \InsetSpace ~
8879 <Value>
8880 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8881
8882 \end_inset
8883
8884  Use <Value> for the code segment name.
8885 \end_layout
8886
8887 \begin_layout List
8888 \labelwidthstring 00.00.0000
8889
8890 \series bold
8891 -
8892 \begin_inset ERT
8893 status collapsed
8894
8895 \begin_layout Standard
8896
8897
8898 \backslash
8899 /
8900 \end_layout
8901
8902 \end_inset
8903
8904 -constseg
8905 \series default
8906 \InsetSpace ~
8907 <Value>
8908 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8909
8910 \end_inset
8911
8912  Use <Value> for the const segment name.
8913 \end_layout
8914
8915 \begin_layout List
8916 \labelwidthstring 00.00.0000
8917 \begin_inset VSpace bigskip
8918 \end_inset
8919
8920
8921 \end_layout
8922
8923 \begin_layout Subsection
8924 GBZ80 Options
8925 \begin_inset LatexCommand \index{Options GBZ80}
8926
8927 \end_inset
8928
8929
8930 \begin_inset LatexCommand \index{GBZ80}
8931
8932 \end_inset
8933
8934
8935 \end_layout
8936
8937 \begin_layout List
8938 \labelwidthstring 00.00.0000
8939
8940 \series bold
8941 -
8942 \begin_inset ERT
8943 status collapsed
8944
8945 \begin_layout Standard
8946
8947
8948 \backslash
8949 /
8950 \end_layout
8951
8952 \end_inset
8953
8954 -callee-saves-bc
8955 \series default
8956
8957 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8958
8959 \end_inset
8960
8961
8962 \size large
8963 \emph on
8964  
8965 \size default
8966 \emph default
8967 Force a called function to always save BC.
8968 \end_layout
8969
8970 \begin_layout List
8971 \labelwidthstring 00.00.0000
8972
8973 \series bold
8974 -
8975 \begin_inset ERT
8976 status collapsed
8977
8978 \begin_layout Standard
8979
8980
8981 \backslash
8982 /
8983 \end_layout
8984
8985 \end_inset
8986
8987 -no-std-crt0
8988 \series default
8989
8990 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8991
8992 \end_inset
8993
8994  When linking, skip the standard crt0.o object file.
8995  You must provide your own crt0.o for your system when linking.
8996 \end_layout
8997
8998 \begin_layout List
8999 \labelwidthstring 00.00.0000
9000
9001 \series bold
9002 -bo
9003 \series default
9004 \InsetSpace ~
9005 <Num>
9006 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
9007
9008 \end_inset
9009
9010  Use code bank <Num>.
9011 \end_layout
9012
9013 \begin_layout List
9014 \labelwidthstring 00.00.0000
9015
9016 \series bold
9017 -ba
9018 \series default
9019 \InsetSpace ~
9020 <Num>
9021 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
9022
9023 \end_inset
9024
9025  Use data bank <Num>.
9026 \end_layout
9027
9028 \begin_layout List
9029 \labelwidthstring 00.00.0000
9030
9031 \series bold
9032 -
9033 \begin_inset ERT
9034 status collapsed
9035
9036 \begin_layout Standard
9037
9038
9039 \backslash
9040 /
9041 \end_layout
9042
9043 \end_inset
9044
9045 -codeseg
9046 \series default
9047 \InsetSpace ~
9048 <Value>
9049 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
9050
9051 \end_inset
9052
9053  Use <Value> for the code segment name.
9054 \end_layout
9055
9056 \begin_layout List
9057 \labelwidthstring 00.00.0000
9058
9059 \series bold
9060 -
9061 \begin_inset ERT
9062 status collapsed
9063
9064 \begin_layout Standard
9065
9066
9067 \backslash
9068 /
9069 \end_layout
9070
9071 \end_inset
9072
9073 -constseg
9074 \series default
9075 \InsetSpace ~
9076 <Value>
9077 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
9078
9079 \end_inset
9080
9081  Use <Value> for the const segment name.
9082 \end_layout
9083
9084 \begin_layout Standard
9085 \begin_inset VSpace bigskip
9086 \end_inset
9087
9088
9089 \end_layout
9090
9091 \begin_layout Subsection
9092 Optimization Options
9093 \begin_inset LatexCommand \index{Options optimization}
9094
9095 \end_inset
9096
9097
9098 \begin_inset LatexCommand \index{Optimization options}
9099
9100 \end_inset
9101
9102
9103 \end_layout
9104
9105 \begin_layout List
9106 \labelwidthstring 00.00.0000
9107
9108 \series bold
9109 -
9110 \begin_inset ERT
9111 status collapsed
9112
9113 \begin_layout Standard
9114
9115
9116 \backslash
9117 /
9118 \end_layout
9119
9120 \end_inset
9121
9122 -nogcse
9123 \begin_inset LatexCommand \index{-\/-nogcse}
9124
9125 \end_inset
9126
9127
9128 \series default
9129  Will not do global subexpression elimination, this option may be used when
9130  the compiler creates undesirably large stack/data spaces to store compiler
9131  temporaries (
9132 \emph on
9133 s
9134 \emph default
9135 pill 
9136 \emph on
9137 loc
9138 \emph default
9139 ations, sloc
9140 \begin_inset LatexCommand \index{sloc (spill location)}
9141
9142 \end_inset
9143
9144 ).
9145  A warning message will be generated when this happens and the compiler
9146  will indicate the number of extra bytes it allocated.
9147  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9148 nogcse
9149 \begin_inset LatexCommand \index{\#pragma nogcse}
9150
9151 \end_inset
9152
9153  can be used to turn off global subexpression elimination
9154 \begin_inset LatexCommand \index{Subexpression elimination}
9155
9156 \end_inset
9157
9158  for a given function only.
9159 \end_layout
9160
9161 \begin_layout List
9162 \labelwidthstring 00.00.0000
9163
9164 \series bold
9165 -
9166 \begin_inset ERT
9167 status collapsed
9168
9169 \begin_layout Standard
9170
9171
9172 \backslash
9173 /
9174 \end_layout
9175
9176 \end_inset
9177
9178 -noinvariant
9179 \begin_inset LatexCommand \index{-\/-noinvariant}
9180
9181 \end_inset
9182
9183
9184 \series default
9185  Will not do loop invariant optimizations, this may be turned off for reasons
9186  explained for the previous option.
9187  For more details of loop optimizations performed see Loop Invariants in
9188  section 
9189 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
9190
9191 \end_inset
9192
9193 .
9194  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9195 noinvariant
9196 \begin_inset LatexCommand \index{\#pragma noinvariant}
9197
9198 \end_inset
9199
9200  can be used to turn off invariant optimizations for a given function only.
9201 \end_layout
9202
9203 \begin_layout List
9204 \labelwidthstring 00.00.0000
9205
9206 \series bold
9207 -
9208 \begin_inset ERT
9209 status collapsed
9210
9211 \begin_layout Standard
9212
9213
9214 \backslash
9215 /
9216 \end_layout
9217
9218 \end_inset
9219
9220 -noinduction
9221 \begin_inset LatexCommand \index{-\/-noinduction}
9222
9223 \end_inset
9224
9225
9226 \series default
9227  Will not do loop induction optimizations, see section strength reduction
9228  for more details.
9229  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9230 noinduction
9231 \begin_inset LatexCommand \index{\#pragma noinduction}
9232
9233 \end_inset
9234
9235  can be used to turn off induction optimizations for a given function only.
9236 \end_layout
9237
9238 \begin_layout List
9239 \labelwidthstring 00.00.0000
9240
9241 \series bold
9242 -
9243 \begin_inset ERT
9244 status collapsed
9245
9246 \begin_layout Standard
9247
9248
9249 \backslash
9250 /
9251 \end_layout
9252
9253 \end_inset
9254
9255 -nojtbound
9256 \begin_inset LatexCommand \index{-\/-nojtbound}
9257
9258 \end_inset
9259
9260
9261 \size large
9262 \bar under
9263  
9264 \series default
9265 \size default
9266 \bar default
9267  Will not generate boundary condition check when switch statements
9268 \begin_inset LatexCommand \index{switch statement}
9269
9270 \end_inset
9271
9272  are implemented using jump-tables.
9273  See section 
9274 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
9275
9276 \end_inset
9277
9278 \InsetSpace ~
9279 Switch Statements for more details.
9280  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9281 nojtbound
9282 \begin_inset LatexCommand \index{\#pragma nojtbound}
9283
9284 \end_inset
9285
9286  can be used to turn off boundary checking for jump tables for a given function
9287  only.
9288 \end_layout
9289
9290 \begin_layout List
9291 \labelwidthstring 00.00.0000
9292
9293 \series bold
9294 -
9295 \begin_inset ERT
9296 status collapsed
9297
9298 \begin_layout Standard
9299
9300
9301 \backslash
9302 /
9303 \end_layout
9304
9305 \end_inset
9306
9307 -noloopreverse
9308 \begin_inset LatexCommand \index{-\/-noloopreverse}
9309
9310 \end_inset
9311
9312
9313 \series default
9314 \size large
9315  
9316 \size default
9317 Will not do loop reversal 
9318 \begin_inset LatexCommand \index{Loop reversing}
9319
9320 \end_inset
9321
9322 optimization.
9323 \end_layout
9324
9325 \begin_layout List
9326 \labelwidthstring 00.00.0000
9327 -
9328 \begin_inset ERT
9329 status collapsed
9330
9331 \begin_layout Standard
9332
9333
9334 \backslash
9335 /
9336 \end_layout
9337
9338 \end_inset
9339
9340 -
9341 \series bold
9342 nolabelopt
9343 \series default
9344  
9345 \begin_inset LatexCommand \index{-\/-nolabelopt }
9346
9347 \end_inset
9348
9349 Will not optimize labels (makes the dumpfiles more readable).
9350 \end_layout
9351
9352 \begin_layout List
9353 \labelwidthstring 00.00.0000
9354
9355 \series bold
9356 -
9357 \begin_inset ERT
9358 status collapsed
9359
9360 \begin_layout Standard
9361
9362
9363 \backslash
9364 /
9365 \end_layout
9366
9367 \end_inset
9368
9369 -no-xinit-opt
9370 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9371
9372 \end_inset
9373
9374
9375 \series default
9376  Will not memcpy initialized data from code space into xdata space.
9377  This saves a few bytes in code space if you don't have initialized data
9378 \begin_inset LatexCommand \index{Variable initialization}
9379
9380 \end_inset
9381
9382 .
9383 \end_layout
9384
9385 \begin_layout List
9386 \labelwidthstring 00.00.0000
9387
9388 \series bold
9389 -
9390 \begin_inset ERT
9391 status collapsed
9392
9393 \begin_layout Standard
9394
9395
9396 \backslash
9397 /
9398 \end_layout
9399
9400 \end_inset
9401
9402 -nooverlay
9403 \begin_inset LatexCommand \index{-\/-nooverlay}
9404
9405 \end_inset
9406
9407
9408 \series default
9409   The compiler will not overlay parameters and local variables of any function,
9410  see section Parameters and local variables for more details.
9411 \end_layout
9412
9413 \begin_layout List
9414 \labelwidthstring 00.00.0000
9415
9416 \series bold
9417 -
9418 \begin_inset ERT
9419 status collapsed
9420
9421 \begin_layout Standard
9422
9423
9424 \backslash
9425 /
9426 \end_layout
9427
9428 \end_inset
9429
9430 -no-peep
9431 \begin_inset LatexCommand \index{-\/-no-peep}
9432
9433 \end_inset
9434
9435
9436 \series default
9437  Disable peep-hole optimization with built-in rules.
9438 \end_layout
9439
9440 \begin_layout List
9441 \labelwidthstring 00.00.0000
9442
9443 \series bold
9444 -
9445 \begin_inset ERT
9446 status collapsed
9447
9448 \begin_layout Standard
9449
9450
9451 \backslash
9452 /
9453 \end_layout
9454
9455 \end_inset
9456
9457 -peep-file
9458 \series default
9459
9460 \begin_inset LatexCommand \index{-\/-peep-file}
9461
9462 \end_inset
9463
9464 \InsetSpace ~
9465 <filename> This option can be used to use additional rules to be used by
9466  the peep hole optimizer.
9467  See section 
9468 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9469
9470 \end_inset
9471
9472 \InsetSpace ~
9473 Peep Hole optimizations for details on how to write these rules.
9474 \end_layout
9475
9476 \begin_layout List
9477 \labelwidthstring 00.00.0000
9478
9479 \series bold
9480 -
9481 \begin_inset ERT
9482 status collapsed
9483
9484 \begin_layout Standard
9485
9486
9487 \backslash
9488 /
9489 \end_layout
9490
9491 \end_inset
9492
9493 -peep-asm
9494 \begin_inset LatexCommand \index{-\/-peep-asm}
9495
9496 \end_inset
9497
9498
9499 \series default
9500  Pass the inline assembler code through the peep hole optimizer.
9501  This can cause unexpected changes to inline assembler code, please go through
9502  the peephole optimizer
9503 \begin_inset LatexCommand \index{Peephole optimizer}
9504
9505 \end_inset
9506
9507  rules defined in the source file tree '<target>/peeph.def' before using
9508  this option.
9509 \end_layout
9510
9511 \begin_layout List
9512 \labelwidthstring 00.00.0000
9513
9514 \series bold
9515 -
9516 \begin_inset ERT
9517 status collapsed
9518
9519 \begin_layout Standard
9520
9521
9522 \backslash
9523 /
9524 \end_layout
9525
9526 \end_inset
9527
9528 -opt-code-speed
9529 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9530
9531 \end_inset
9532
9533
9534 \series default
9535  The compiler will optimize code generation towards fast code, possibly
9536  at the expense of code size.
9537 \end_layout
9538
9539 \begin_layout List
9540 \labelwidthstring 00.00.0000
9541
9542 \series bold
9543 -
9544 \begin_inset ERT
9545 status collapsed
9546
9547 \begin_layout Standard
9548
9549
9550 \backslash
9551 /
9552 \end_layout
9553
9554 \end_inset
9555
9556 -opt-code-size
9557 \begin_inset LatexCommand \index{-\/-opt-code-size}
9558
9559 \end_inset
9560
9561
9562 \series default
9563  The compiler will optimize code generation towards compact code, possibly
9564  at the expense of code speed.
9565 \end_layout
9566
9567 \begin_layout Standard
9568 \begin_inset VSpace bigskip
9569 \end_inset
9570
9571
9572 \end_layout
9573
9574 \begin_layout Subsection
9575 Other Options
9576 \begin_inset LatexCommand \index{Options other}
9577
9578 \end_inset
9579
9580
9581 \end_layout
9582
9583 \begin_layout List
9584 \labelwidthstring 00.00.0000
9585
9586 \series bold
9587 -c\InsetSpace ~
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 -compile-only
9602 \begin_inset LatexCommand \index{-\/-compile-only}
9603
9604 \end_inset
9605
9606
9607 \begin_inset LatexCommand \index{-c -\/-compile-only}
9608
9609 \end_inset
9610
9611
9612 \series default
9613  will compile and assemble the source, but will not call the linkage editor.
9614 \end_layout
9615
9616 \begin_layout List
9617 \labelwidthstring 00.00.0000
9618
9619 \series bold
9620 -
9621 \series default
9622
9623 \begin_inset ERT
9624 status collapsed
9625
9626 \begin_layout Standard
9627
9628
9629 \backslash
9630 /
9631 \end_layout
9632
9633 \end_inset
9634
9635
9636 \series bold
9637 -c1mode
9638 \begin_inset LatexCommand \index{-\/-c1mode}
9639
9640 \end_inset
9641
9642
9643 \series default
9644  reads the preprocessed source from standard input and compiles it.
9645  The file name for the assembler output must be specified using the -o option.
9646 \end_layout
9647
9648 \begin_layout List
9649 \labelwidthstring 00.00.0000
9650
9651 \series bold
9652 -E
9653 \begin_inset LatexCommand \index{-E}
9654
9655 \end_inset
9656
9657
9658 \series default
9659  Run only the C preprocessor.
9660  Preprocess all the C source files specified and output the results to standard
9661  output.
9662 \end_layout
9663
9664 \begin_layout List
9665 \labelwidthstring 00.00.0000
9666
9667 \series bold
9668 -o\InsetSpace ~
9669 <path/file>
9670 \begin_inset LatexCommand \index{-o <path/file>}
9671
9672 \end_inset
9673
9674  
9675 \series default
9676 The output path where everything will be placed or the file name used for
9677  all generated output files.
9678  If the parameter is a path, it must have a trailing slash (or backslash
9679  for the Windows binaries) to be recognized as a path.
9680
9681 \emph on
9682  
9683 \emph default
9684 Note for Windows users: if the path contains spaces, it should be surrounded
9685  by quotes.
9686  The trailing backslash should be doubled in order to prevent escaping the
9687  final quote, for example: 
9688 \emph on
9689 -o 
9690 \begin_inset Quotes sld
9691 \end_inset
9692
9693 F:
9694 \backslash
9695 Projects
9696 \backslash
9697 test3
9698 \backslash
9699 output 1
9700 \backslash
9701
9702 \backslash
9703
9704 \begin_inset Quotes srd
9705 \end_inset
9706
9707
9708 \emph default
9709  or put after the final quote, for example: 
9710 \emph on
9711 -o 
9712 \begin_inset Quotes sld
9713 \end_inset
9714
9715 F:
9716 \backslash
9717 Projects
9718 \backslash
9719 test3
9720 \backslash
9721 output 1
9722 \begin_inset Quotes srd
9723 \end_inset
9724
9725
9726 \backslash
9727
9728 \emph default
9729 .
9730  The path using slashes for directory delimiters can be used too, for example:
9731  
9732 \emph on
9733 -o 
9734 \begin_inset Quotes sld
9735 \end_inset
9736
9737 F:/Projects/test3/output 1/
9738 \begin_inset Quotes srd
9739 \end_inset
9740
9741
9742 \emph default
9743 .
9744 \end_layout
9745
9746 \begin_layout List
9747 \labelwidthstring 00.00.0000
9748
9749 \series bold
9750 -
9751 \begin_inset ERT
9752 status collapsed
9753
9754 \begin_layout Standard
9755
9756
9757 \backslash
9758 /
9759 \end_layout
9760
9761 \end_inset
9762
9763 -stack-auto
9764 \begin_inset LatexCommand \index{-\/-stack-auto}
9765
9766 \end_inset
9767
9768
9769 \series default
9770 \size large
9771 \emph on
9772  
9773 \size default
9774 \emph default
9775 All functions in the source file will be compiled as 
9776 \emph on
9777 reentrant
9778 \emph default
9779
9780 \begin_inset LatexCommand \index{reentrant}
9781
9782 \end_inset
9783
9784 , i.e.
9785  the parameters and local variables will be allocated on the stack
9786 \begin_inset LatexCommand \index{stack}
9787
9788 \end_inset
9789
9790 .
9791  See section 
9792 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9793
9794 \end_inset
9795
9796  Parameters and Local Variables for more details.
9797  If this option is used all source files in the project should be compiled
9798  with this option.
9799  It automatically implies -
9800 \series bold
9801
9802 \begin_inset ERT
9803 status open
9804
9805 \begin_layout Standard
9806
9807
9808 \backslash
9809 /
9810 \end_layout
9811
9812 \end_inset
9813
9814
9815 \series default
9816 -int-long-reent and -
9817 \series bold
9818
9819 \begin_inset ERT
9820 status open
9821
9822 \begin_layout Standard
9823
9824
9825 \backslash
9826 /
9827 \end_layout
9828
9829 \end_inset
9830
9831
9832 \series default
9833 -float-reent.
9834  
9835 \end_layout
9836
9837 \begin_layout List
9838 \labelwidthstring 00.00.0000
9839
9840 \series bold
9841 -
9842 \begin_inset ERT
9843 status collapsed
9844
9845 \begin_layout Standard
9846
9847
9848 \backslash
9849 /
9850 \end_layout
9851
9852 \end_inset
9853
9854 -callee-saves
9855 \begin_inset LatexCommand \index{-\/-callee-saves}
9856
9857 \end_inset
9858
9859  
9860 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9861
9862 \end_inset
9863
9864 function1[,function2][,function3]....
9865
9866 \series default
9867  The compiler by default uses a caller saves convention for register saving
9868  across function calls, however this can cause unnecessary register pushing
9869  and popping when calling small functions from larger functions.
9870  This option can be used to switch the register saving convention for the
9871  function names specified.
9872  The compiler will not save registers when calling these functions, no extra
9873  code will be generated at the entry and exit (function prologue
9874 \series bold
9875
9876 \begin_inset LatexCommand \index{function prologue}
9877
9878 \end_inset
9879
9880
9881 \series default
9882  and epilogue
9883 \series bold
9884
9885 \begin_inset LatexCommand \index{function epilogue}
9886
9887 \end_inset
9888
9889
9890 \series default
9891 ) for these functions to save and restore the registers used by these functions,
9892  this can SUBSTANTIALLY reduce code and improve run time performance of
9893  the generated code.
9894  In the future the compiler (with inter procedural analysis) will be able
9895  to determine the appropriate scheme to use for each function call.
9896  DO NOT use this option for built-in functions such as _mulint..., if this
9897  option is used for a library function the appropriate library function
9898  needs to be recompiled with the same option.
9899  If the project consists of multiple source files then all the source file
9900  should be compiled with the same -
9901 \begin_inset ERT
9902 status collapsed
9903
9904 \begin_layout Standard
9905
9906
9907 \backslash
9908 /
9909 \end_layout
9910
9911 \end_inset
9912
9913 -callee-saves option string.
9914  Also see #pragma\InsetSpace ~
9915 callee_saves 
9916 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9917
9918 \end_inset
9919
9920  
9921 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9922
9923 \end_inset
9924
9925 .
9926 \end_layout
9927
9928 \begin_layout List
9929 \labelwidthstring 00.00.0000
9930
9931 \series bold
9932 -
9933 \begin_inset ERT
9934 status collapsed
9935
9936 \begin_layout Standard
9937
9938
9939 \backslash
9940 /
9941 \end_layout
9942
9943 \end_inset
9944
9945 -all-callee-saves
9946 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9947
9948 \end_inset
9949
9950  
9951 \series default
9952 Function of
9953 \series bold
9954  
9955 \series default
9956 -
9957 \begin_inset ERT
9958 status collapsed
9959
9960 \begin_layout Standard
9961
9962
9963 \backslash
9964 /
9965 \end_layout
9966
9967 \end_inset
9968
9969 -callee-saves will be applied to all functions by default.
9970 \end_layout
9971
9972 \begin_layout List
9973 \labelwidthstring 00.00.0000
9974
9975 \series bold
9976 -
9977 \begin_inset ERT
9978 status collapsed
9979
9980 \begin_layout Standard
9981
9982
9983 \backslash
9984 /
9985 \end_layout
9986
9987 \end_inset
9988
9989 -debug
9990 \begin_inset LatexCommand \index{-\/-debug}
9991
9992 \end_inset
9993
9994
9995 \bar under
9996  
9997 \series default
9998 \bar default
9999 When this option is used the compiler will generate debug information.
10000  The debug information collected in a file with .cdb extension can be used
10001  with the SDCDB.
10002  For more information see documentation for SDCDB.
10003  Another file with no extension contains debug information in AOMF or AOMF51
10004 \begin_inset LatexCommand \index{AOMF, AOMF51}
10005
10006 \end_inset
10007
10008  format which is commonly used by third party tools.
10009 \end_layout
10010
10011 \begin_layout List
10012 \labelwidthstring 00.00.0000
10013
10014 \series bold
10015 -S
10016 \begin_inset LatexCommand \index{-S}
10017
10018 \end_inset
10019
10020
10021 \size large
10022 \bar under
10023  
10024 \series default
10025 \size default
10026 \bar default
10027 Stop after the stage of compilation proper; do not assemble.
10028  The output is an assembler code file for the input file specified.
10029 \end_layout
10030
10031 \begin_layout List
10032 \labelwidthstring 00.00.0000
10033
10034 \series bold
10035 -
10036 \begin_inset ERT
10037 status collapsed
10038
10039 \begin_layout Standard
10040
10041
10042 \backslash
10043 /
10044 \end_layout
10045
10046 \end_inset
10047
10048 -int-long-reent
10049 \begin_inset LatexCommand \index{-\/-int-long-reent}
10050
10051 \end_inset
10052
10053
10054 \series default
10055  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10056  Note by default these libraries are compiled as non-reentrant.
10057  See section Installation for more details.
10058 \end_layout
10059
10060 \begin_layout List
10061 \labelwidthstring 00.00.0000
10062
10063 \series bold
10064 -
10065 \begin_inset ERT
10066 status collapsed
10067
10068 \begin_layout Standard
10069
10070
10071 \backslash
10072 /
10073 \end_layout
10074
10075 \end_inset
10076
10077 -cyclomatic
10078 \begin_inset LatexCommand \index{-\/-cyclomatic}
10079
10080 \end_inset
10081
10082
10083 \bar under
10084  
10085 \series default
10086 \bar default
10087 This option will cause the compiler to generate an information message for
10088  each function in the source file.
10089  The message contains some 
10090 \emph on
10091 important
10092 \emph default
10093  information about the function.
10094  The number of edges and nodes the compiler detected in the control flow
10095  graph of the function, and most importantly the 
10096 \emph on
10097 cyclomatic complexity
10098 \begin_inset LatexCommand \index{Cyclomatic complexity}
10099
10100 \end_inset
10101
10102
10103 \emph default
10104  see section on Cyclomatic Complexity for more details.
10105 \end_layout
10106
10107 \begin_layout List
10108 \labelwidthstring 00.00.0000
10109
10110 \series bold
10111 -
10112 \begin_inset ERT
10113 status collapsed
10114
10115 \begin_layout Standard
10116
10117
10118 \backslash
10119 /
10120 \end_layout
10121
10122 \end_inset
10123
10124 -float-reent
10125 \begin_inset LatexCommand \index{-\/-float-reent}
10126
10127 \end_inset
10128
10129
10130 \series default
10131  Floating point library is compiled as reentrant
10132 \begin_inset LatexCommand \index{reentrant}
10133
10134 \end_inset
10135
10136 .
10137  See section Installation for more details.
10138 \end_layout
10139
10140 \begin_layout List
10141 \labelwidthstring 00.00.0000
10142
10143 \series bold
10144 -
10145 \begin_inset ERT
10146 status collapsed
10147
10148 \begin_layout Standard
10149
10150
10151 \backslash
10152 /
10153 \end_layout
10154
10155 \end_inset
10156
10157 -funsigned-char
10158 \begin_inset LatexCommand \index{-\/-funsigned-char}
10159
10160 \end_inset
10161
10162
10163 \series default
10164  The default signedness for every type is
10165 \family typewriter
10166  signed
10167 \family default
10168 .
10169  In some embedded environments the default signedness of
10170 \family typewriter
10171  char
10172 \family default
10173  is
10174 \family typewriter
10175  unsigned
10176 \family default
10177 .
10178  To set the signess for characters to unsigned, use the option -
10179 \series bold
10180
10181 \begin_inset ERT
10182 status open
10183
10184 \begin_layout Standard
10185
10186
10187 \backslash
10188 /
10189 \end_layout
10190
10191 \end_inset
10192
10193
10194 \series default
10195 -funsigned-char.
10196  If this option is set and no signedness keyword (unsigned/signed) is given,
10197  a char will be signed.
10198  All other types are unaffected.
10199 \end_layout
10200
10201 \begin_layout List
10202 \labelwidthstring 00.00.0000
10203
10204 \series bold
10205 -
10206 \begin_inset ERT
10207 status collapsed
10208
10209 \begin_layout Standard
10210
10211
10212 \backslash
10213 /
10214 \end_layout
10215
10216 \end_inset
10217
10218 -main-return
10219 \begin_inset LatexCommand \index{-\/-main-return}
10220
10221 \end_inset
10222
10223
10224 \series default
10225  This option can be used if the code generated is called by a monitor program
10226  or if the main routine includes an endless loop.
10227  This option results in slightly smaller code and saves two bytes of stack
10228  space.
10229  The return from the 'main'
10230 \begin_inset LatexCommand \index{main return}
10231
10232 \end_inset
10233
10234  function will return to the function calling main.
10235  The default setting is to lock up i.e.
10236  generate a '
10237 \family typewriter
10238 sjmp .
10239 \family default
10240 '.
10241 \end_layout
10242
10243 \begin_layout List
10244 \labelwidthstring 00.00.0000
10245
10246 \series bold
10247 -
10248 \begin_inset ERT
10249 status collapsed
10250
10251 \begin_layout Standard
10252
10253
10254 \backslash
10255 /
10256 \end_layout
10257
10258 \end_inset
10259
10260 -nostdinc
10261 \begin_inset LatexCommand \index{-\/-nostdinc}
10262
10263 \end_inset
10264
10265
10266 \series default
10267  This will prevent the compiler from passing on the default include path
10268  to the preprocessor.
10269 \end_layout
10270
10271 \begin_layout List
10272 \labelwidthstring 00.00.0000
10273
10274 \series bold
10275 -
10276 \begin_inset ERT
10277 status collapsed
10278
10279 \begin_layout Standard
10280
10281
10282 \backslash
10283 /
10284 \end_layout
10285
10286 \end_inset
10287
10288 -nostdlib
10289 \begin_inset LatexCommand \index{-\/-nostdlib}
10290
10291 \end_inset
10292
10293
10294 \series default
10295  This will prevent the compiler from passing on the default library
10296 \begin_inset LatexCommand \index{Libraries}
10297
10298 \end_inset
10299
10300  path to the linker.
10301 \end_layout
10302
10303 \begin_layout List
10304 \labelwidthstring 00.00.0000
10305
10306 \series bold
10307 -
10308 \begin_inset ERT
10309 status collapsed
10310
10311 \begin_layout Standard
10312
10313
10314 \backslash
10315 /
10316 \end_layout
10317
10318 \end_inset
10319
10320 -verbose
10321 \begin_inset LatexCommand \index{-\/-verbose}
10322
10323 \end_inset
10324
10325
10326 \series default
10327  Shows the various actions the compiler is performing.
10328 \end_layout
10329
10330 \begin_layout List
10331 \labelwidthstring 00.00.0000
10332
10333 \series bold
10334 -V
10335 \begin_inset LatexCommand \index{-V}
10336
10337 \end_inset
10338
10339
10340 \series default
10341  Shows the actual commands the compiler is executing.
10342 \end_layout
10343
10344 \begin_layout List
10345 \labelwidthstring 00.00.0000
10346
10347 \series bold
10348 -
10349 \begin_inset ERT
10350 status collapsed
10351
10352 \begin_layout Standard
10353
10354
10355 \backslash
10356 /
10357 \end_layout
10358
10359 \end_inset
10360
10361 -no-c-code-in-asm
10362 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
10363
10364 \end_inset
10365
10366
10367 \series default
10368  Hides your ugly and inefficient c-code from the asm file, so you can always
10369  blame the compiler :)
10370 \end_layout
10371
10372 \begin_layout List
10373 \labelwidthstring 00.00.0000
10374
10375 \series bold
10376 -
10377 \begin_inset ERT
10378 status collapsed
10379
10380 \begin_layout Standard
10381
10382
10383 \backslash
10384 /
10385 \end_layout
10386
10387 \end_inset
10388
10389 -fverbose-asm
10390 \begin_inset LatexCommand \index{-\/-no-gen-comments}
10391
10392 \end_inset
10393
10394
10395 \series default
10396  Include code generator and peep-hole comments in the generated asm files.
10397 \end_layout
10398
10399 \begin_layout List
10400 \labelwidthstring 00.00.0000
10401
10402 \series bold
10403 -
10404 \begin_inset ERT
10405 status collapsed
10406
10407 \begin_layout Standard
10408
10409
10410 \backslash
10411 /
10412 \end_layout
10413
10414 \end_inset
10415
10416 -no-peep-comments
10417 \begin_inset LatexCommand \index{-\/-no-peep-comments}
10418
10419 \end_inset
10420
10421
10422 \series default
10423  Don't include peep-hole comments in the generated asm files even if -
10424 \series bold
10425
10426 \begin_inset ERT
10427 status open
10428
10429 \begin_layout Standard
10430
10431
10432 \backslash
10433 /
10434 \end_layout
10435
10436 \end_inset
10437
10438
10439 \series default
10440 -fverbose-asm option is specified.
10441 \end_layout
10442
10443 \begin_layout List
10444 \labelwidthstring 00.00.0000
10445
10446 \series bold
10447 -
10448 \begin_inset ERT
10449 status collapsed
10450
10451 \begin_layout Standard
10452
10453
10454 \backslash
10455 /
10456 \end_layout
10457
10458 \end_inset
10459
10460 -i-code-in-asm
10461 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10462
10463 \end_inset
10464
10465
10466 \series default
10467  Include i-codes in the asm file.
10468  Sounds like noise but is most helpful for debugging the compiler itself.
10469 \end_layout
10470
10471 \begin_layout List
10472 \labelwidthstring 00.00.0000
10473
10474 \series bold
10475 -
10476 \begin_inset ERT
10477 status collapsed
10478
10479 \begin_layout Standard
10480
10481
10482 \backslash
10483 /
10484 \end_layout
10485
10486 \end_inset
10487
10488 -less-pedantic
10489 \begin_inset LatexCommand \index{pedantic}
10490
10491 \end_inset
10492
10493
10494 \begin_inset LatexCommand \index{-\/-less-pedantic}
10495
10496 \end_inset
10497
10498
10499 \series default
10500
10501 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10502
10503 \end_inset
10504
10505  Disable some of the more pedantic warnings
10506 \begin_inset LatexCommand \index{Warnings}
10507
10508 \end_inset
10509
10510 .
10511  For more details, see the less_pedantic pragma 
10512 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10513
10514 \end_inset
10515
10516 .
10517 \end_layout
10518
10519 \begin_layout List
10520 \labelwidthstring 00.00.0000
10521
10522 \series bold
10523 -
10524 \begin_inset ERT
10525 status collapsed
10526
10527 \begin_layout Standard
10528
10529
10530 \backslash
10531 /
10532 \end_layout
10533
10534 \end_inset
10535
10536 -disable-warning\InsetSpace ~
10537 <nnnn>
10538 \begin_inset LatexCommand \index{-\/-disable-warning}
10539
10540 \end_inset
10541
10542
10543 \series default
10544  Disable specific warning with number <nnnn>.
10545 \end_layout
10546
10547 \begin_layout List
10548 \labelwidthstring 00.00.0000
10549
10550 \series bold
10551 -
10552 \begin_inset ERT
10553 status collapsed
10554
10555 \begin_layout Standard
10556
10557
10558 \backslash
10559 /
10560 \end_layout
10561
10562 \end_inset
10563
10564 -Werror
10565 \begin_inset LatexCommand \index{-\/-Werror}
10566
10567 \end_inset
10568
10569
10570 \series default
10571  Treat all warnings as errors.
10572 \end_layout
10573
10574 \begin_layout List
10575 \labelwidthstring 00.00.0000
10576
10577 \series bold
10578 -
10579 \begin_inset ERT
10580 status collapsed
10581
10582 \begin_layout Standard
10583
10584
10585 \backslash
10586 /
10587 \end_layout
10588
10589 \end_inset
10590
10591 -print-search-dirs
10592 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10593
10594 \end_inset
10595
10596
10597 \series default
10598  Display the directories in the compiler's search path
10599 \end_layout
10600
10601 \begin_layout List
10602 \labelwidthstring 00.00.0000
10603
10604 \series bold
10605 -
10606 \begin_inset ERT
10607 status collapsed
10608
10609 \begin_layout Standard
10610
10611
10612 \backslash
10613 /
10614 \end_layout
10615
10616 \end_inset
10617
10618 -vc
10619 \begin_inset LatexCommand \index{-\/-vc}
10620
10621 \end_inset
10622
10623
10624 \series default
10625  Display errors and warnings using MSVC style, so you can use SDCC with
10626  the visual studio IDE
10627 \begin_inset LatexCommand \index{IDE}
10628
10629 \end_inset
10630
10631 .
10632  With SDCC both offering a GCC-like (the default) and a MSVC-like
10633 \begin_inset LatexCommand \index{MSVC output style}
10634
10635 \end_inset
10636
10637  output style, integration into most programming editors should be straightforwa
10638 rd.
10639 \end_layout
10640
10641 \begin_layout List
10642 \labelwidthstring 00.00.0000
10643
10644 \series bold
10645 -
10646 \begin_inset ERT
10647 status collapsed
10648
10649 \begin_layout Standard
10650
10651
10652 \backslash
10653 /
10654 \end_layout
10655
10656 \end_inset
10657
10658 -use-stdout
10659 \begin_inset LatexCommand \index{-\/-use-stdout}
10660
10661 \end_inset
10662
10663
10664 \series default
10665  Send errors and warnings to stdout instead of stderr.
10666 \end_layout
10667
10668 \begin_layout List
10669 \labelwidthstring 00.00.0000
10670
10671 \series bold
10672 -Wa\InsetSpace ~
10673 asmOption[,asmOption]
10674 \series default
10675
10676 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10677
10678 \end_inset
10679
10680 ...
10681  Pass the asmOption to the assembler
10682 \begin_inset LatexCommand \index{Options assembler}
10683
10684 \end_inset
10685
10686
10687 \begin_inset LatexCommand \index{Assembler options}
10688
10689 \end_inset
10690
10691 .
10692  See file sdcc/as/doc/asxhtm.html for assembler options.cd
10693 \end_layout
10694
10695 \begin_layout List
10696 \labelwidthstring 00.00.0000
10697
10698 \series bold
10699 -
10700 \begin_inset ERT
10701 status collapsed
10702
10703 \begin_layout Standard
10704
10705
10706 \backslash
10707 /
10708 \end_layout
10709
10710 \end_inset
10711
10712 -std-sdcc89
10713 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10714
10715 \end_inset
10716
10717
10718 \series default
10719  Generally follow the C89 standard, but allow SDCC features that conflict
10720  with the standard (default).
10721 \end_layout
10722
10723 \begin_layout List
10724 \labelwidthstring 00.00.0000
10725
10726 \series bold
10727 -
10728 \begin_inset ERT
10729 status collapsed
10730
10731 \begin_layout Standard
10732
10733
10734 \backslash
10735 /
10736 \end_layout
10737
10738 \end_inset
10739
10740 -std-c89
10741 \begin_inset LatexCommand \index{-\/-std-c89}
10742
10743 \end_inset
10744
10745
10746 \series default
10747  Follow the C89 standard and disable SDCC features that conflict with the
10748  standard.
10749 \end_layout
10750
10751 \begin_layout List
10752 \labelwidthstring 00.00.0000
10753
10754 \series bold
10755 -
10756 \begin_inset ERT
10757 status collapsed
10758
10759 \begin_layout Standard
10760
10761
10762 \backslash
10763 /
10764 \end_layout
10765
10766 \end_inset
10767
10768 -std-sdcc99
10769 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10770
10771 \end_inset
10772
10773
10774 \series default
10775  Generally follow the C99 standard, but allow SDCC features that conflict
10776  with the standard (incomplete support).
10777 \end_layout
10778
10779 \begin_layout List
10780 \labelwidthstring 00.00.0000
10781
10782 \series bold
10783 -
10784 \begin_inset ERT
10785 status collapsed
10786
10787 \begin_layout Standard
10788
10789
10790 \backslash
10791 /
10792 \end_layout
10793
10794 \end_inset
10795
10796 -std-c99
10797 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10798
10799 \end_inset
10800
10801
10802 \series default
10803  Follow the C99 standard and disable SDCC features that conflict with the
10804  standard (incomplete support).
10805 \end_layout
10806
10807 \begin_layout List
10808 \labelwidthstring 00.00.0000
10809
10810 \series bold
10811 -
10812 \begin_inset ERT
10813 status collapsed
10814
10815 \begin_layout Standard
10816
10817
10818 \backslash
10819 /
10820 \end_layout
10821
10822 \end_inset
10823
10824 -codeseg
10825 \series default
10826
10827 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10828
10829 \end_inset
10830
10831 \InsetSpace ~
10832 <Name> The name to be used for the code
10833 \begin_inset LatexCommand \index{code}
10834
10835 \end_inset
10836
10837  segment, default CSEG.
10838  This is useful if you need to tell the compiler to put the code in a special
10839  segment so you can later on tell the linker to put this segment in a special
10840  place in memory.
10841  Can be used for instance when using bank switching to put the code in a
10842  bank.
10843 \end_layout
10844
10845 \begin_layout List
10846 \labelwidthstring 00.00.0000
10847
10848 \series bold
10849 -
10850 \begin_inset ERT
10851 status collapsed
10852
10853 \begin_layout Standard
10854
10855
10856 \backslash
10857 /
10858 \end_layout
10859
10860 \end_inset
10861
10862 -constseg
10863 \series default
10864
10865 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10866
10867 \end_inset
10868
10869 \InsetSpace ~
10870 <Name> The name to be used for the const
10871 \begin_inset LatexCommand \index{const}
10872
10873 \end_inset
10874
10875  segment, default CONST.
10876  This is useful if you need to tell the compiler to put the const data in
10877  a special segment so you can later on tell the linker to put this segment
10878  in a special place in memory.
10879  Can be used for instance when using bank switching to put the const data
10880  in a bank.
10881 \end_layout
10882
10883 \begin_layout List
10884 \labelwidthstring 00.00.0000
10885
10886 \series bold
10887 -
10888 \begin_inset ERT
10889 status collapsed
10890
10891 \begin_layout Standard
10892
10893
10894 \backslash
10895 /
10896 \end_layout
10897
10898 \end_inset
10899
10900 -fdollars-in-identifiers
10901 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10902
10903 \end_inset
10904
10905
10906 \series default
10907  Permit '$' as an identifier character.
10908 \end_layout
10909
10910 \begin_layout List
10911 \labelwidthstring 00.00.0000
10912
10913 \series bold
10914 -
10915 \begin_inset ERT
10916 status collapsed
10917
10918 \begin_layout Standard
10919
10920
10921 \backslash
10922 /
10923 \end_layout
10924
10925 \end_inset
10926
10927 -more-pedantic
10928 \series default
10929
10930 \begin_inset LatexCommand \index{-\/-more-pedantic}
10931
10932 \end_inset
10933
10934
10935 \begin_inset LatexCommand \index{pedantic}
10936
10937 \end_inset
10938
10939  Actually this is 
10940 \series bold
10941 \emph on
10942 not
10943 \series default
10944 \emph default
10945  a SDCC compiler option but if you want 
10946 \emph on
10947 more
10948 \emph default
10949  warnings you can use a separate tool dedicated to syntax checking like
10950  splint
10951 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10952
10953 \end_inset
10954
10955
10956 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10957
10958 \end_inset
10959
10960  
10961 \begin_inset LatexCommand \url{http://www.splint.org}
10962
10963 \end_inset
10964
10965 .
10966  To make your source files parseable by splint you will have to include
10967  
10968 \family sans
10969 lint.h
10970 \family default
10971
10972 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10973
10974 \end_inset
10975
10976  in your source file and add brackets around extended keywords (like 
10977 \family sans
10978
10979 \begin_inset Quotes sld
10980 \end_inset
10981
10982 __at\InsetSpace ~
10983
10984 \series bold
10985 (
10986 \series default
10987 0xab
10988 \series bold
10989 )
10990 \series default
10991
10992 \begin_inset Quotes srd
10993 \end_inset
10994
10995
10996 \family default
10997  and 
10998 \family sans
10999
11000 \begin_inset Quotes sld
11001 \end_inset
11002
11003 __interrupt\InsetSpace ~
11004 (2)
11005 \begin_inset Quotes srd
11006 \end_inset
11007
11008
11009 \family default
11010 ).
11011  
11012 \newline
11013 Splint has an excellent on line manual at 
11014 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
11015
11016 \end_inset
11017
11018  and it's capabilities go beyond pure syntax checking.
11019  You'll need to tell splint the location of SDCC's include files so a typical
11020  command line could look like this: 
11021 \newline
11022
11023 \family sans
11024 splint\InsetSpace ~
11025 -I\InsetSpace ~
11026 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
11027 \InsetSpace ~
11028 myprogram.c
11029 \end_layout
11030
11031 \begin_layout List
11032 \labelwidthstring 00.00.0000
11033
11034 \series bold
11035 -
11036 \begin_inset ERT
11037 status collapsed
11038
11039 \begin_layout Standard
11040
11041
11042 \backslash
11043 /
11044 \end_layout
11045
11046 \end_inset
11047
11048 -short-is-8bits
11049 \series default
11050
11051 \begin_inset LatexCommand \index{-\/-short-is-8bits}
11052
11053 \end_inset
11054
11055
11056 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
11057
11058 \end_inset
11059
11060  Treat short as 8-bit (for backward compatibility with older versions of
11061  compiler - see section 
11062 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
11063
11064 \end_inset
11065
11066 )
11067 \end_layout
11068
11069 \begin_layout Standard
11070 \begin_inset VSpace bigskip
11071 \end_inset
11072
11073
11074 \end_layout
11075
11076 \begin_layout Subsection
11077 Intermediate Dump Options
11078 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
11079
11080 \end_inset
11081
11082
11083 \begin_inset LatexCommand \index{Options intermediate dump}
11084
11085 \end_inset
11086
11087
11088 \begin_inset LatexCommand \index{Intermediate dump options}
11089
11090 \end_inset
11091
11092
11093 \end_layout
11094
11095 \begin_layout Standard
11096 The following options are provided for the purpose of retargetting and debugging
11097  the compiler.
11098  They provide a means to dump the intermediate code (iCode
11099 \begin_inset LatexCommand \index{iCode}
11100
11101 \end_inset
11102
11103 ) generated by the compiler in human readable form at various stages of
11104  the compilation process.
11105  More on iCodes see chapter 
11106 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
11107
11108 \end_inset
11109
11110  
11111 \begin_inset Quotes srd
11112 \end_inset
11113
11114 The anatomy of the compiler
11115 \begin_inset Quotes srd
11116 \end_inset
11117
11118 .
11119 \end_layout
11120
11121 \begin_layout List
11122 \labelwidthstring 00.00.0000
11123
11124 \series bold
11125 -
11126 \begin_inset ERT
11127 status collapsed
11128
11129 \begin_layout Standard
11130
11131
11132 \backslash
11133 /
11134 \end_layout
11135
11136 \end_inset
11137
11138 -dumpraw
11139 \begin_inset LatexCommand \index{-\/-dumpraw}
11140
11141 \end_inset
11142
11143
11144 \series default
11145  This option will cause the compiler to dump the intermediate code into
11146  a file of named 
11147 \emph on
11148 <source filename>.dumpraw
11149 \emph default
11150  just after the intermediate code has been generated for a function, i.e.
11151  before any optimizations are done.
11152  The basic blocks
11153 \begin_inset LatexCommand \index{Basic blocks}
11154
11155 \end_inset
11156
11157  at this stage ordered in the depth first number, so they may not be in
11158  sequence of execution.
11159 \end_layout
11160
11161 \begin_layout List
11162 \labelwidthstring 00.00.0000
11163
11164 \series bold
11165 -
11166 \begin_inset ERT
11167 status collapsed
11168
11169 \begin_layout Standard
11170
11171
11172 \backslash
11173 /
11174 \end_layout
11175
11176 \end_inset
11177
11178 -dumpgcse
11179 \begin_inset LatexCommand \index{-\/-dumpgcse}
11180
11181 \end_inset
11182
11183
11184 \series default
11185  Will create a dump of iCodes, after global subexpression elimination
11186 \begin_inset LatexCommand \index{Global subexpression elimination}
11187
11188 \end_inset
11189
11190 , into a file named 
11191 \emph on
11192 <source filename>.dumpgcse.
11193 \end_layout
11194
11195 \begin_layout List
11196 \labelwidthstring 00.00.0000
11197
11198 \series bold
11199 -
11200 \begin_inset ERT
11201 status collapsed
11202
11203 \begin_layout Standard
11204
11205
11206 \backslash
11207 /
11208 \end_layout
11209
11210 \end_inset
11211
11212 -dumpdeadcode
11213 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
11214
11215 \end_inset
11216
11217
11218 \series default
11219  Will create a dump of iCodes, after deadcode elimination
11220 \begin_inset LatexCommand \index{Dead-code elimination}
11221
11222 \end_inset
11223
11224 , into a file named 
11225 \emph on
11226 <source filename>.dumpdeadcode.
11227 \end_layout
11228
11229 \begin_layout List
11230 \labelwidthstring 00.00.0000
11231
11232 \series bold
11233 -
11234 \begin_inset ERT
11235 status collapsed
11236
11237 \begin_layout Standard
11238
11239
11240 \backslash
11241 /
11242 \end_layout
11243
11244 \end_inset
11245
11246 -dumploop
11247 \begin_inset LatexCommand \index{-\/-dumploop}
11248
11249 \end_inset
11250
11251
11252 \series default
11253 \size large
11254  
11255 \size default
11256 Will create a dump of iCodes, after loop optimizations
11257 \begin_inset LatexCommand \index{Loop optimization}
11258
11259 \end_inset
11260
11261 , into a file named 
11262 \emph on
11263 <source filename>.dumploop.
11264 \end_layout
11265
11266 \begin_layout List
11267 \labelwidthstring 00.00.0000
11268
11269 \series bold
11270 -
11271 \begin_inset ERT
11272 status collapsed
11273
11274 \begin_layout Standard
11275
11276
11277 \backslash
11278 /
11279 \end_layout
11280
11281 \end_inset
11282
11283 -dumprange
11284 \begin_inset LatexCommand \index{-\/-dumprange}
11285
11286 \end_inset
11287
11288
11289 \series default
11290 \size large
11291  
11292 \size default
11293 Will create a dump of iCodes, after live range analysis
11294 \begin_inset LatexCommand \index{Live range analysis}
11295
11296 \end_inset
11297
11298 , into a file named 
11299 \emph on
11300 <source filename>.dumprange.
11301 \end_layout
11302
11303 \begin_layout List
11304 \labelwidthstring 00.00.0000
11305
11306 \series bold
11307 -
11308 \begin_inset ERT
11309 status collapsed
11310
11311 \begin_layout Standard
11312
11313
11314 \backslash
11315 /
11316 \end_layout
11317
11318 \end_inset
11319
11320 -dumlrange
11321 \begin_inset LatexCommand \index{-\/-dumlrange}
11322
11323 \end_inset
11324
11325
11326 \series default
11327  Will dump the life ranges
11328 \begin_inset LatexCommand \index{Live range analysis}
11329
11330 \end_inset
11331
11332  for all symbols.
11333 \end_layout
11334
11335 \begin_layout List
11336 \labelwidthstring 00.00.0000
11337
11338 \series bold
11339 -
11340 \begin_inset ERT
11341 status collapsed
11342
11343 \begin_layout Standard
11344
11345
11346 \backslash
11347 /
11348 \end_layout
11349
11350 \end_inset
11351
11352 -dumpregassign
11353 \begin_inset LatexCommand \index{-\/-dumpregassign}
11354
11355 \end_inset
11356
11357
11358 \bar under
11359  
11360 \series default
11361 \bar default
11362 Will create a dump of iCodes, after register assignment
11363 \begin_inset LatexCommand \index{Register assignment}
11364
11365 \end_inset
11366
11367 , into a file named 
11368 \emph on
11369 <source filename>.dumprassgn.
11370 \end_layout
11371
11372 \begin_layout List
11373 \labelwidthstring 00.00.0000
11374
11375 \series bold
11376 -
11377 \begin_inset ERT
11378 status collapsed
11379
11380 \begin_layout Standard
11381
11382
11383 \backslash
11384 /
11385 \end_layout
11386
11387 \end_inset
11388
11389 -dumplrange
11390 \begin_inset LatexCommand \index{-\/-dumplrange}
11391
11392 \end_inset
11393
11394
11395 \series default
11396  Will create a dump of the live ranges of iTemp's
11397 \end_layout
11398
11399 \begin_layout List
11400 \labelwidthstring 00.00.0000
11401
11402 \series bold
11403 -
11404 \begin_inset ERT
11405 status collapsed
11406
11407 \begin_layout Standard
11408
11409
11410 \backslash
11411 /
11412 \end_layout
11413
11414 \end_inset
11415
11416 -dumpall
11417 \begin_inset LatexCommand \index{-\/-dumpall}
11418
11419 \end_inset
11420
11421
11422 \size large
11423 \bar under
11424  
11425 \series default
11426 \size default
11427 \bar default
11428 Will cause all the above mentioned dumps to be created.
11429 \end_layout
11430
11431 \begin_layout Standard
11432 \begin_inset VSpace bigskip
11433 \end_inset
11434
11435
11436 \end_layout
11437
11438 \begin_layout Subsection
11439 Redirecting output on Windows Shells
11440 \end_layout
11441
11442 \begin_layout Standard
11443 By default SDCC writes its error messages to 
11444 \begin_inset Quotes sld
11445 \end_inset
11446
11447 standard error
11448 \begin_inset Quotes srd
11449 \end_inset
11450
11451 .
11452  To force all messages to 
11453 \begin_inset Quotes sld
11454 \end_inset
11455
11456 standard output
11457 \begin_inset Quotes srd
11458 \end_inset
11459
11460  use 
11461 \series bold
11462 -
11463 \series default
11464 \emph on
11465
11466 \begin_inset ERT
11467 status collapsed
11468
11469 \begin_layout Standard
11470
11471
11472 \backslash
11473 /
11474 \end_layout
11475
11476 \end_inset
11477
11478
11479 \series bold
11480 \emph default
11481 -
11482 \series default
11483 use-stdout
11484 \begin_inset LatexCommand \index{-\/-use-stdout}
11485
11486 \end_inset
11487
11488 .
11489  Additionally, if you happen to have visual studio installed in your windows
11490  machine, you can use it to compile your sources using a custom build and
11491  the SDCC -
11492 \emph on
11493
11494 \begin_inset ERT
11495 status collapsed
11496
11497 \begin_layout Standard
11498
11499
11500 \backslash
11501 /
11502 \end_layout
11503
11504 \end_inset
11505
11506
11507 \emph default
11508 -vc
11509 \begin_inset LatexCommand \index{-\/-vc}
11510
11511 \end_inset
11512
11513  option.
11514  Something like this should work:
11515 \newline
11516
11517 \newline
11518
11519 \series bold
11520 c:
11521 \backslash
11522 sdcc
11523 \backslash
11524 bin
11525 \backslash
11526 sdcc.exe -
11527 \series default
11528 \emph on
11529
11530 \begin_inset ERT
11531 status collapsed
11532
11533 \begin_layout Standard
11534
11535
11536 \backslash
11537 /
11538 \end_layout
11539
11540 \end_inset
11541
11542
11543 \series bold
11544 \emph default
11545 -vc -
11546 \series default
11547 \emph on
11548
11549 \begin_inset ERT
11550 status collapsed
11551
11552 \begin_layout Standard
11553
11554
11555 \backslash
11556 /
11557 \end_layout
11558
11559 \end_inset
11560
11561
11562 \series bold
11563 \emph default
11564 -model-large -c $(InputPath)
11565 \series default
11566
11567 \begin_inset VSpace bigskip
11568 \end_inset
11569
11570
11571 \end_layout
11572
11573 \begin_layout Section
11574 Environment variables
11575 \begin_inset LatexCommand \index{Environment variables}
11576
11577 \end_inset
11578
11579
11580 \end_layout
11581
11582 \begin_layout Standard
11583 SDCC recognizes the following environment variables:
11584 \end_layout
11585
11586 \begin_layout List
11587 \labelwidthstring 00.00.0000
11588
11589 \series bold
11590 SDCC_LEAVE_SIGNALS
11591 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11592
11593 \end_inset
11594
11595
11596 \series default
11597  SDCC installs a signal handler
11598 \begin_inset LatexCommand \index{signal handler}
11599
11600 \end_inset
11601
11602  to be able to delete temporary files after an user break (^C) or an exception.
11603  If this environment variable is set, SDCC won't install the signal handler
11604  in order to be able to debug SDCC.
11605 \end_layout
11606
11607 \begin_layout List
11608 \labelwidthstring 00.00.0000
11609
11610 \series bold
11611 TMP,\InsetSpace ~
11612 TEMP,\InsetSpace ~
11613 TMPDIR
11614 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11615
11616 \end_inset
11617
11618
11619 \series default
11620  Path, where temporary files will be created.
11621  The order of the variables is the search order.
11622  In a standard *nix environment these variables are not set, and there's
11623  no need to set them.
11624  On Windows it's recommended to set one of them.
11625 \end_layout
11626
11627 \begin_layout List
11628 \labelwidthstring 00.00.0000
11629
11630 \series bold
11631 SDCC_HOME
11632 \begin_inset LatexCommand \index{SDCC\_HOME}
11633
11634 \end_inset
11635
11636
11637 \series default
11638  Path, see section 
11639 \begin_inset LatexCommand \ref{sub:Install-paths}
11640
11641 \end_inset
11642
11643 \InsetSpace ~
11644
11645 \begin_inset Quotes sld
11646 \end_inset
11647
11648  Install Paths
11649 \begin_inset Quotes srd
11650 \end_inset
11651
11652 .
11653 \end_layout
11654
11655 \begin_layout List
11656 \labelwidthstring 00.00.0000
11657
11658 \series bold
11659 SDCC_INCLUDE
11660 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11661
11662 \end_inset
11663
11664
11665 \series default
11666  Path, see section 
11667 \begin_inset LatexCommand \ref{sub:Search-Paths}
11668
11669 \end_inset
11670
11671 \InsetSpace ~
11672
11673 \begin_inset Quotes sld
11674 \end_inset
11675
11676 Search Paths
11677 \begin_inset Quotes srd
11678 \end_inset
11679
11680 .
11681 \end_layout
11682
11683 \begin_layout List
11684 \labelwidthstring 00.00.0000
11685
11686 \series bold
11687 SDCC_LIB
11688 \begin_inset LatexCommand \index{SDCC\_LIB}
11689
11690 \end_inset
11691
11692
11693 \series default
11694  Path, see section 
11695 \begin_inset LatexCommand \ref{sub:Search-Paths}
11696
11697 \end_inset
11698
11699 \InsetSpace ~
11700
11701 \begin_inset Quotes sld
11702 \end_inset
11703
11704 Search Paths
11705 \begin_inset Quotes srd
11706 \end_inset
11707
11708 ..
11709 \end_layout
11710
11711 \begin_layout Standard
11712 There are some more environment variables recognized by SDCC, but these
11713  are solely used for debugging purposes.
11714  They can change or disappear very quickly, and will never be documented.
11715 \begin_inset VSpace bigskip
11716 \end_inset
11717
11718
11719 \end_layout
11720
11721 \begin_layout Section
11722 Storage Class Language Extensions
11723 \end_layout
11724
11725 \begin_layout Subsection
11726 MCS51/DS390 Storage Class
11727 \begin_inset LatexCommand \index{Storage class}
11728
11729 \end_inset
11730
11731  Language Extensions
11732 \end_layout
11733
11734 \begin_layout Standard
11735 In addition to the ANSI storage classes SDCC allows the following MCS51
11736  specific storage classes:
11737 \end_layout
11738
11739 \begin_layout Subsubsection
11740 data
11741 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11742
11743 \end_inset
11744
11745
11746 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11747
11748 \end_inset
11749
11750  / near
11751 \begin_inset LatexCommand \index{near (storage class)}
11752
11753 \end_inset
11754
11755
11756 \begin_inset LatexCommand \index{\_\_near (storage class)}
11757
11758 \end_inset
11759
11760
11761 \end_layout
11762
11763 \begin_layout Standard
11764 This is the 
11765 \series bold
11766 default
11767 \series default
11768  storage class for the Small Memory model (
11769 \emph on
11770 data
11771 \emph default
11772  and 
11773 \emph on
11774 near
11775 \emph default
11776  or the more ANSI-C compliant forms 
11777 \emph on
11778 __data
11779 \emph default
11780  and 
11781 \emph on
11782 __near
11783 \emph default
11784  can be used synonymously).
11785  Variables declared with this storage class will be allocated in the directly
11786  addressable portion of the internal RAM of a 8051, e.g.:
11787 \end_layout
11788
11789 \begin_layout Verse
11790
11791 \family typewriter
11792 __data unsigned char test_data;
11793 \end_layout
11794
11795 \begin_layout Standard
11796 Writing 0x01 to this variable generates the assembly code:
11797 \end_layout
11798
11799 \begin_layout Verse
11800
11801 \family typewriter
11802 75*00 01\InsetSpace ~
11803 \InsetSpace ~
11804 \InsetSpace ~
11805 mov\InsetSpace ~
11806 \InsetSpace ~
11807 _test_data,#0x01
11808 \end_layout
11809
11810 \begin_layout Subsubsection
11811 xdata
11812 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11813
11814 \end_inset
11815
11816
11817 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11818
11819 \end_inset
11820
11821  / far
11822 \begin_inset LatexCommand \index{far (storage class)}
11823
11824 \end_inset
11825
11826
11827 \begin_inset LatexCommand \index{\_\_far (storage class)}
11828
11829 \end_inset
11830
11831
11832 \end_layout
11833
11834 \begin_layout Standard
11835 Variables declared with this storage class will be placed in the external
11836  RAM.
11837  This is the 
11838 \series bold
11839 default
11840 \series default
11841  storage class for the Large Memory model, e.g.:
11842 \end_layout
11843
11844 \begin_layout Verse
11845
11846 \family typewriter
11847 __xdata unsigned char test_xdata;
11848 \end_layout
11849
11850 \begin_layout Standard
11851 Writing 0x01 to this variable generates the assembly code:
11852 \end_layout
11853
11854 \begin_layout Verse
11855
11856 \family typewriter
11857 90s00r00\InsetSpace ~
11858 \InsetSpace ~
11859 \InsetSpace ~
11860 mov\InsetSpace ~
11861 \InsetSpace ~
11862 dptr,#_test_xdata 
11863 \newline
11864 74\InsetSpace ~
11865 01\InsetSpace ~
11866 \InsetSpace ~
11867 \InsetSpace ~
11868 \InsetSpace ~
11869 \InsetSpace ~
11870 \InsetSpace ~
11871 mov\InsetSpace ~
11872 \InsetSpace ~
11873 a,#0x01 
11874 \newline
11875 F0\InsetSpace ~
11876 \InsetSpace ~
11877 \InsetSpace ~
11878 \InsetSpace ~
11879 \InsetSpace ~
11880 \InsetSpace ~
11881 \InsetSpace ~
11882 \InsetSpace ~
11883 \InsetSpace ~
11884 movx\InsetSpace ~
11885 @dptr,a 
11886 \end_layout
11887
11888 \begin_layout Subsubsection
11889 idata
11890 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11891
11892 \end_inset
11893
11894
11895 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11896
11897 \end_inset
11898
11899
11900 \end_layout
11901
11902 \begin_layout Standard
11903 Variables declared with this storage class will be allocated into the indirectly
11904  addressable portion of the internal ram of a 8051, e.g.:
11905 \end_layout
11906
11907 \begin_layout Verse
11908
11909 \family typewriter
11910 __idata unsigned char test_idata;
11911 \end_layout
11912
11913 \begin_layout Standard
11914 Writing 0x01 to this variable generates the assembly code:
11915 \end_layout
11916
11917 \begin_layout Verse
11918
11919 \family typewriter
11920 78r00\InsetSpace ~
11921 \InsetSpace ~
11922 \InsetSpace ~
11923 \InsetSpace ~
11924 \InsetSpace ~
11925 \InsetSpace ~
11926 \InsetSpace ~
11927 mov\InsetSpace ~
11928 \InsetSpace ~
11929 r0,#_test_idata
11930 \newline
11931 76\InsetSpace ~
11932 01\InsetSpace ~
11933 \InsetSpace ~
11934 \InsetSpace ~
11935 \InsetSpace ~
11936 \InsetSpace ~
11937 \InsetSpace ~
11938 \InsetSpace ~
11939 mov\InsetSpace ~
11940 \InsetSpace ~
11941 @r0,#0x01
11942 \end_layout
11943
11944 \begin_layout Standard
11945 Please note, the first 128 byte of idata physically access the same RAM
11946  as the data memory.
11947  The original 8051 had 128 byte idata memory, nowadays most devices have
11948  256 byte idata memory.
11949  The stack
11950 \begin_inset LatexCommand \index{stack}
11951
11952 \end_inset
11953
11954  is located in idata memory.
11955 \end_layout
11956
11957 \begin_layout Subsubsection
11958 pdata
11959 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11960
11961 \end_inset
11962
11963
11964 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11965
11966 \end_inset
11967
11968
11969 \end_layout
11970
11971 \begin_layout Standard
11972 Paged xdata access is just as straightforward as using the other addressing
11973  modes of a 8051.
11974  It is typically located at the start of xdata and has a maximum size of
11975  256 bytes.
11976  The following example writes 0x01 to the pdata variable.
11977  Please note, pdata access physically accesses xdata memory.
11978  The high byte of the address is determined by port P2 
11979 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11980
11981 \end_inset
11982
11983 (or in case of some 8051 variants by a separate Special Function Register,
11984  see section 
11985 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11986
11987 \end_inset
11988
11989 ).
11990  This is the 
11991 \series bold
11992 default
11993 \series default
11994  storage class for the Medium Memory model, e.g.:
11995 \end_layout
11996
11997 \begin_layout Verse
11998
11999 \family typewriter
12000 __pdata unsigned char test_pdata;
12001 \end_layout
12002
12003 \begin_layout Standard
12004 Writing 0x01 to this variable generates the assembly code:
12005 \end_layout
12006
12007 \begin_layout Verse
12008
12009 \family typewriter
12010 78r00\InsetSpace ~
12011 \InsetSpace ~
12012 \InsetSpace ~
12013 \InsetSpace ~
12014 \InsetSpace ~
12015 \InsetSpace ~
12016 mov r0,#_test_pdata
12017 \newline
12018 74 01\InsetSpace ~
12019 \InsetSpace ~
12020 \InsetSpace ~
12021 \InsetSpace ~
12022 \InsetSpace ~
12023 \InsetSpace ~
12024 mov a,#0x01 
12025 \newline
12026 F2\InsetSpace ~
12027 \InsetSpace ~
12028 \InsetSpace ~
12029 \InsetSpace ~
12030 \InsetSpace ~
12031 \InsetSpace ~
12032 \InsetSpace ~
12033 \InsetSpace ~
12034 \InsetSpace ~
12035 movx @r0,a
12036 \end_layout
12037
12038 \begin_layout Standard
12039 If the -
12040 \begin_inset ERT
12041 status collapsed
12042
12043 \begin_layout Standard
12044
12045
12046 \backslash
12047 /
12048 \end_layout
12049
12050 \end_inset
12051
12052 -xstack
12053 \begin_inset LatexCommand \index{-\/-xstack}
12054
12055 \end_inset
12056
12057  option is used the pdata memory area is followed by the xstack memory area
12058  and the sum of their sizes is limited to 256 bytes.
12059 \end_layout
12060
12061 \begin_layout Subsubsection
12062 code
12063 \begin_inset LatexCommand \index{code}
12064
12065 \end_inset
12066
12067
12068 \begin_inset LatexCommand \index{\_\_code}
12069
12070 \end_inset
12071
12072
12073 \end_layout
12074
12075 \begin_layout Standard
12076 'Variables' declared with this storage class will be placed in the code
12077  memory:
12078 \end_layout
12079
12080 \begin_layout Verse
12081
12082 \family typewriter
12083 __code unsigned char test_code;
12084 \end_layout
12085
12086 \begin_layout Standard
12087 Read access to this variable generates the assembly code:
12088 \end_layout
12089
12090 \begin_layout Verse
12091
12092 \family typewriter
12093 90s00r6F\InsetSpace ~
12094 \InsetSpace ~
12095 \InsetSpace ~
12096 mov dptr,#_test_code
12097 \newline
12098 E4\InsetSpace ~
12099 \InsetSpace ~
12100 \InsetSpace ~
12101 \InsetSpace ~
12102 \InsetSpace ~
12103 \InsetSpace ~
12104 \InsetSpace ~
12105 \InsetSpace ~
12106 \InsetSpace ~
12107 clr a
12108 \newline
12109 93\InsetSpace ~
12110 \InsetSpace ~
12111 \InsetSpace ~
12112 \InsetSpace ~
12113 \InsetSpace ~
12114 \InsetSpace ~
12115 \InsetSpace ~
12116 \InsetSpace ~
12117 \InsetSpace ~
12118 movc a,@a+dptr 
12119 \end_layout
12120
12121 \begin_layout Standard
12122
12123 \family typewriter
12124 char
12125 \family default
12126  indexed arrays of characters in code memory can be accessed efficiently:
12127 \end_layout
12128
12129 \begin_layout Verse
12130
12131 \family typewriter
12132 __code char test_array[] = {'c','h','e','a','p'}; 
12133 \end_layout
12134
12135 \begin_layout Standard
12136 Read access to this array using an 8-bit unsigned index generates the assembly
12137  code:
12138 \end_layout
12139
12140 \begin_layout Verse
12141
12142 \family typewriter
12143 E5*00\InsetSpace ~
12144 \InsetSpace ~
12145 \InsetSpace ~
12146 \InsetSpace ~
12147 \InsetSpace ~
12148 \InsetSpace ~
12149 mov a,_index 
12150 \end_layout
12151
12152 \begin_layout Verse
12153
12154 \family typewriter
12155 90s00r41\InsetSpace ~
12156 \InsetSpace ~
12157 \InsetSpace ~
12158 mov dptr,#_test_array
12159 \end_layout
12160
12161 \begin_layout Verse
12162
12163 \family typewriter
12164 93\InsetSpace ~
12165 \InsetSpace ~
12166 \InsetSpace ~
12167 \InsetSpace ~
12168 \InsetSpace ~
12169 \InsetSpace ~
12170 \InsetSpace ~
12171 \InsetSpace ~
12172 \InsetSpace ~
12173 movc a,@a+dptr 
12174 \end_layout
12175
12176 \begin_layout Subsubsection
12177 bit
12178 \begin_inset LatexCommand \index{bit}
12179
12180 \end_inset
12181
12182
12183 \begin_inset LatexCommand \index{\_\_bit}
12184
12185 \end_inset
12186
12187
12188 \end_layout
12189
12190 \begin_layout Standard
12191 This is a data-type and a storage class specifier.
12192  When a variable is declared as a bit, it is allocated into the bit addressable
12193  memory of 8051, e.g.:
12194 \end_layout
12195
12196 \begin_layout Verse
12197
12198 \family typewriter
12199 __bit test_bit;
12200 \end_layout
12201
12202 \begin_layout Standard
12203 Writing 1 to this variable generates the assembly code:
12204 \end_layout
12205
12206 \begin_layout Verse
12207
12208 \family typewriter
12209 D2*00\InsetSpace ~
12210 \InsetSpace ~
12211 \InsetSpace ~
12212 \InsetSpace ~
12213 \InsetSpace ~
12214 \InsetSpace ~
12215 \InsetSpace ~
12216 setb\InsetSpace ~
12217 _test_bit
12218 \end_layout
12219
12220 \begin_layout Standard
12221 The bit addressable memory consists of 128 bits which are located from 0x20
12222  to 0x2f in data memory.
12223  
12224 \newline
12225 Apart from this 8051 specific storage class most architectures support
12226  ANSI-C bitfields
12227 \begin_inset LatexCommand \index{bitfields}
12228
12229 \end_inset
12230
12231
12232 \begin_inset Foot
12233 status open
12234
12235 \begin_layout Standard
12236 Not really meant as examples, but nevertheless showing what bitfields are
12237  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12238 \end_layout
12239
12240 \end_inset
12241
12242 .
12243  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12244  signed modifier are implemented as unsigned.
12245 \end_layout
12246
12247 \begin_layout Subsubsection
12248 sfr
12249 \begin_inset LatexCommand \index{sfr}
12250
12251 \end_inset
12252
12253
12254 \begin_inset LatexCommand \index{\_\_sfr}
12255
12256 \end_inset
12257
12258  / sfr16
12259 \begin_inset LatexCommand \index{sfr16}
12260
12261 \end_inset
12262
12263
12264 \begin_inset LatexCommand \index{\_\_sfr16}
12265
12266 \end_inset
12267
12268  / sfr32
12269 \begin_inset LatexCommand \index{sfr32}
12270
12271 \end_inset
12272
12273
12274 \begin_inset LatexCommand \index{\_\_sfr32}
12275
12276 \end_inset
12277
12278  / sbit
12279 \begin_inset LatexCommand \index{\_\_sbit}
12280
12281 \end_inset
12282
12283
12284 \begin_inset LatexCommand \index{sbit}
12285
12286 \end_inset
12287
12288
12289 \end_layout
12290
12291 \begin_layout Standard
12292 Like the bit keyword, 
12293 \emph on
12294 sfr / sfr16 / sfr32 / sbit 
12295 \emph default
12296 signify both a data-type and storage class, they are used to describe the
12297  
12298 \emph on
12299 s
12300 \emph default
12301 pecial 
12302 \emph on
12303 f
12304 \emph default
12305 unction 
12306 \emph on
12307 r
12308 \emph default
12309 egisters and 
12310 \emph on
12311 s
12312 \emph default
12313 pecial 
12314 \emph on
12315 bit
12316 \emph default
12317  variables of a 8051, eg:
12318 \end_layout
12319
12320 \begin_layout Verse
12321
12322 \family typewriter
12323 __sfr __at
12324 \begin_inset LatexCommand \index{at}
12325
12326 \end_inset
12327
12328
12329 \begin_inset LatexCommand \index{\_\_at}
12330
12331 \end_inset
12332
12333  (0x80) P0;\InsetSpace ~
12334  /* special function register P0 at location 0x80 */
12335 \newline
12336
12337 \newline
12338 /* 16 bit
12339  special function register combination for timer 0
12340 \newline
12341 \InsetSpace ~
12342 \InsetSpace ~
12343  with the high byte at
12344  location 0x8C and the low byte at location 0x8A */
12345 \newline
12346 __sfr16 __at (0x8C8A)
12347  TMR0;
12348 \newline
12349
12350 \newline
12351 __sbit __at
12352 \begin_inset LatexCommand \index{at}
12353
12354 \end_inset
12355
12356
12357 \begin_inset LatexCommand \index{\_\_at}
12358
12359 \end_inset
12360
12361  (0xd7) CY;\InsetSpace ~
12362  /* CY (Carry Flag
12363 \begin_inset LatexCommand \index{Flags}
12364
12365 \end_inset
12366
12367
12368 \begin_inset LatexCommand \index{Carry flag}
12369
12370 \end_inset
12371
12372 ) */
12373 \end_layout
12374
12375 \begin_layout Standard
12376 Special function registers which are located on an address dividable by
12377  8 are bit-addressable, an
12378 \emph on
12379  sbit
12380 \emph default
12381  addresses a specific bit within these sfr.
12382 \newline
12383 16 Bit and 32 bit special function
12384  register combinations which require a certain access order are better not
12385  declared using 
12386 \emph on
12387 sfr16
12388 \emph default
12389  or 
12390 \emph on
12391 sfr32.
12392
12393 \emph default
12394  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12395  this is not guaranteed.
12396 \newline
12397
12398 \end_layout
12399
12400 \begin_layout Standard
12401 Please note, if you use a header file which was written for another compiler
12402  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
12403  likely be 
12404 \emph on
12405 not 
12406 \emph default
12407 compatible.
12408  Specifically the syntax 
12409 \family typewriter
12410 \InsetSpace ~
12411 sfr P0 = 0x80;\InsetSpace ~
12412
12413 \family default
12414  is compiled 
12415 \emph on
12416 without warning
12417 \emph default
12418  by SDCC to an assignment of 0x80 to a variable called P0 
12419 \family typewriter
12420
12421 \begin_inset Marginal
12422 status collapsed
12423
12424 \begin_layout Standard
12425
12426 \series bold
12427 \InsetSpace ~
12428 !
12429 \end_layout
12430
12431 \end_inset
12432
12433 .
12434  
12435 \family default
12436 Nevertheless it is possible to write header files
12437 \begin_inset LatexCommand \index{Header files}
12438
12439 \end_inset
12440
12441
12442 \begin_inset LatexCommand \index{Include files}
12443
12444 \end_inset
12445
12446  which can be shared among different compilers (see section 
12447 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
12448
12449 \end_inset
12450
12451 ).
12452  
12453 \end_layout
12454
12455 \begin_layout Subsubsection
12456 Pointers
12457 \begin_inset LatexCommand \index{Pointer}
12458
12459 \end_inset
12460
12461  to MCS51/DS390 specific memory spaces
12462 \end_layout
12463
12464 \begin_layout Standard
12465 SDCC allows (via language extensions) pointers to explicitly point to any
12466  of the memory spaces
12467 \begin_inset LatexCommand \index{Memory model}
12468
12469 \end_inset
12470
12471  of the 8051.
12472  In addition to the explicit pointers, the compiler uses (by default) generic
12473  pointers which can be used to point to any of the memory spaces.
12474 \newline
12475
12476 \newline
12477 Pointer
12478  declaration examples:
12479 \end_layout
12480
12481 \begin_layout Verse
12482
12483 \family typewriter
12484 /* pointer physically in internal ram pointing to object in external ram
12485  */ 
12486 \newline
12487 __xdata unsigned char * __data p;
12488 \newline
12489
12490 \newline
12491 /* pointer physically in external ram
12492  pointing to object in internal ram */ 
12493 \newline
12494 __data unsigned char * __xdata p;
12495 \newline
12496
12497 \newline
12498 /*
12499  pointer physically in code rom pointing to data in xdata space */ 
12500 \newline
12501 __xdata
12502  unsigned char * __code p;
12503 \newline
12504
12505 \newline
12506 /* pointer physically in code space pointing to
12507  data in code space */ 
12508 \newline
12509 __code unsigned char * __code p;
12510 \newline
12511
12512 \newline
12513 /* generic pointer
12514  physically located in xdata space */
12515 \newline
12516 unsigned char * __xdata p;
12517 \newline
12518
12519 \newline
12520 /* generic
12521  pointer physically located in default memory space */
12522 \newline
12523 unsigned char * p;
12524 \newline
12525
12526 \newline
12527 /*
12528  the following is a function pointer
12529 \begin_inset LatexCommand \index{function pointer}
12530
12531 \end_inset
12532
12533  physically located in data space */
12534 \newline
12535 char (* __data fp)(void);
12536 \end_layout
12537
12538 \begin_layout Standard
12539 Well you get the idea.
12540  
12541 \newline
12542
12543 \newline
12544 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
12545 \emph on
12546 generic
12547 \emph default
12548  pointers.
12549  
12550 \size small
12551
12552 \newline
12553
12554 \newline
12555
12556 \size default
12557 The highest order byte of the 
12558 \emph on
12559 generic
12560 \emph default
12561  pointers contains the data space information.
12562  Assembler support routines are called whenever data is stored or retrieved
12563  using 
12564 \emph on
12565 generic
12566 \emph default
12567  pointers.
12568  These are useful for developing reusable library
12569 \begin_inset LatexCommand \index{Libraries}
12570
12571 \end_inset
12572
12573  routines.
12574  Explicitly specifying the pointer
12575 \begin_inset LatexCommand \index{pointer}
12576
12577 \end_inset
12578
12579  type will generate the most efficient code.
12580 \end_layout
12581
12582 \begin_layout Subsubsection
12583 Notes on MCS51 memory
12584 \begin_inset LatexCommand \index{MCS51 memory}
12585
12586 \end_inset
12587
12588  layout
12589 \end_layout
12590
12591 \begin_layout Standard
12592 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12593  RAM memory which is structured as follows:
12594 \newline
12595
12596 \newline
12597 - Bytes 00-1F - 32 bytes to hold
12598  up to 4 banks of the registers R0 to R7, 
12599 \newline
12600 - Bytes 20-2F - 16 bytes to hold
12601  128 bit
12602 \begin_inset LatexCommand \index{bit}
12603
12604 \end_inset
12605
12606  variables and, 
12607 \newline
12608 - Bytes 30-7F - 80 bytes for general purpose use.
12609 \newline
12610
12611 \end_layout
12612
12613 \begin_layout Standard
12614 Additionally some members of the MCS51 family may have up to 128 bytes of
12615  additional, indirectly addressable, internal RAM memory (
12616 \emph on
12617 idata
12618 \emph default
12619
12620 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12621
12622 \end_inset
12623
12624
12625 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12626
12627 \end_inset
12628
12629 ).
12630  Furthermore, some chips may have some built in external memory (
12631 \emph on
12632 xdata
12633 \emph default
12634
12635 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12636
12637 \end_inset
12638
12639
12640 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12641
12642 \end_inset
12643
12644 ) which should not be confused with the internal, directly addressable RAM
12645  memory (
12646 \emph on
12647 data
12648 \emph default
12649
12650 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12651
12652 \end_inset
12653
12654
12655 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12656
12657 \end_inset
12658
12659 ).
12660  Sometimes this built in 
12661 \emph on
12662 xdata
12663 \emph default
12664  memory has to be activated before using it (you can probably find this
12665  information on the datasheet of the microcontroller your are using, see
12666  also section 
12667 \begin_inset LatexCommand \ref{sub:Startup-Code}
12668
12669 \end_inset
12670
12671 \InsetSpace ~
12672 Startup-Code).
12673 \end_layout
12674
12675 \begin_layout Standard
12676 Normally SDCC will only use the first bank
12677 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12678
12679 \end_inset
12680
12681  of registers (register bank 0), but it is possible to specify that other
12682  banks of registers (keyword 
12683 \emph on
12684 using
12685 \emph default
12686  
12687 \emph on
12688
12689 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12690
12691 \end_inset
12692
12693
12694 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12695
12696 \end_inset
12697
12698
12699 \emph default
12700 ) should be used for example in interrupt
12701 \begin_inset LatexCommand \index{interrupt}
12702
12703 \end_inset
12704
12705
12706 \begin_inset LatexCommand \index{\_\_interrupt}
12707
12708 \end_inset
12709
12710  routines.
12711  By default, the compiler will place the stack after the last byte of allocated
12712  memory for variables.
12713  For example, if the first 2 banks of registers are used, and only four
12714  bytes are used for 
12715 \emph on
12716 data
12717 \emph default
12718  variables, it will position the base of the internal stack at address 20
12719  (0x14).
12720  This implies that as the stack
12721 \begin_inset LatexCommand \index{stack}
12722
12723 \end_inset
12724
12725  grows, it will use up the remaining register banks, and the 16 bytes used
12726  by the 128 bit variables, and 80 bytes for general purpose use.
12727  If any bit variables are used, the data variables will be placed in unused
12728  register banks and after the byte holding the last bit variable.
12729  For example, if register banks 0 and 1 are used, and there are 9 bit variables
12730  (two bytes used), 
12731 \emph on
12732 data
12733 \emph default
12734  variables will be placed starting from address 0x10 to 0x20 and continue
12735  at address 0x22.
12736  You can also use -
12737 \begin_inset ERT
12738 status collapsed
12739
12740 \begin_layout Standard
12741
12742
12743 \backslash
12744 /
12745 \end_layout
12746
12747 \end_inset
12748
12749 -data-loc
12750 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12751
12752 \end_inset
12753
12754  to specify the start address of the 
12755 \emph on
12756 data
12757 \emph default
12758  and -
12759 \begin_inset ERT
12760 status collapsed
12761
12762 \begin_layout Standard
12763
12764
12765 \backslash
12766 /
12767 \end_layout
12768
12769 \end_inset
12770
12771 -iram-size
12772 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12773
12774 \end_inset
12775
12776  to specify the size of the total internal RAM (
12777 \emph on
12778 data
12779 \emph default
12780 +
12781 \emph on
12782 idata
12783 \emph default
12784 ).
12785  
12786 \newline
12787
12788 \end_layout
12789
12790 \begin_layout Standard
12791 By default the 8051 linker will place the stack after the last byte of (i)data
12792  variables.
12793  Option -
12794 \begin_inset ERT
12795 status collapsed
12796
12797 \begin_layout Standard
12798
12799
12800 \backslash
12801 /
12802 \end_layout
12803
12804 \end_inset
12805
12806 -stack-loc
12807 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12808
12809 \end_inset
12810
12811  allows you to specify the start of the stack, i.e.
12812  you could start it after any data in the general purpose area.
12813  If your microcontroller has additional indirectly addressable internal
12814  RAM (
12815 \emph on
12816 idata
12817 \emph default
12818 ) you can place the stack on it.
12819  You may also need to use -
12820 \begin_inset ERT
12821 status collapsed
12822
12823 \begin_layout Standard
12824
12825
12826 \backslash
12827 /
12828 \end_layout
12829
12830 \end_inset
12831
12832 -xdata-loc
12833 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12834
12835 \end_inset
12836
12837  to set the start address of the external RAM (
12838 \emph on
12839 xdata
12840 \emph default
12841 ) and -
12842 \begin_inset ERT
12843 status collapsed
12844
12845 \begin_layout Standard
12846
12847
12848 \backslash
12849 /
12850 \end_layout
12851
12852 \end_inset
12853
12854 -xram-size
12855 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12856
12857 \end_inset
12858
12859  to specify its size.
12860  Same goes for the code memory, using -
12861 \begin_inset ERT
12862 status collapsed
12863
12864 \begin_layout Standard
12865
12866
12867 \backslash
12868 /
12869 \end_layout
12870
12871 \end_inset
12872
12873 -code-loc
12874 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12875
12876 \end_inset
12877
12878  and -
12879 \begin_inset ERT
12880 status collapsed
12881
12882 \begin_layout Standard
12883
12884
12885 \backslash
12886 /
12887 \end_layout
12888
12889 \end_inset
12890
12891 -code-size
12892 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12893
12894 \end_inset
12895
12896 .
12897  If in doubt, don't specify any options and see if the resulting memory
12898  layout is appropriate, then you can adjust it.
12899 \end_layout
12900
12901 \begin_layout Standard
12902 The linker generates two files with memory allocation information.
12903  The first, with extension .map
12904 \begin_inset LatexCommand \index{<file>.map}
12905
12906 \end_inset
12907
12908  shows all the variables and segments.
12909  The second with extension .mem
12910 \begin_inset LatexCommand \index{<file>.mem}
12911
12912 \end_inset
12913
12914  shows the final memory layout.
12915  The linker will complain either if memory segments overlap, there is not
12916  enough memory, or there is not enough space for stack.
12917  If you get any linking warnings and/or errors related to stack or segments
12918  allocation, take a look at either the .map or .mem files to find out what
12919  the problem is.
12920  The .mem file may even suggest a solution to the problem.
12921 \begin_inset VSpace bigskip
12922 \end_inset
12923
12924
12925 \end_layout
12926
12927 \begin_layout Subsection
12928 Z80/Z180 Storage Class
12929 \begin_inset LatexCommand \index{Z80!Storage class}
12930
12931 \end_inset
12932
12933  Language Extensions
12934 \end_layout
12935
12936 \begin_layout Subsubsection
12937 sfr
12938 \begin_inset LatexCommand \index{sfr}
12939
12940 \end_inset
12941
12942
12943 \begin_inset LatexCommand \index{\_\_sfr}
12944
12945 \end_inset
12946
12947  (in/out to 8-bit addresses)
12948 \end_layout
12949
12950 \begin_layout Standard
12951 The Z80
12952 \begin_inset LatexCommand \index{Z80}
12953
12954 \end_inset
12955
12956  family has separate address spaces for memory and 
12957 \emph on
12958 i
12959 \emph default
12960 nput/
12961 \emph on
12962 o
12963 \emph default
12964 utput memory.
12965  I/O memory
12966 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12967
12968 \end_inset
12969
12970
12971 \begin_inset LatexCommand \index{Z80!I/O memory}
12972
12973 \end_inset
12974
12975
12976 \begin_inset LatexCommand \index{Z180!I/O memory}
12977
12978 \end_inset
12979
12980  is accessed with special instructions, e.g.:
12981 \end_layout
12982
12983 \begin_layout Verse
12984
12985 \family typewriter
12986 sfr at 0x78 IoPort;\InsetSpace ~
12987 \InsetSpace ~
12988 /* define a var in I/O space at 78h called IoPort */
12989  
12990 \end_layout
12991
12992 \begin_layout Standard
12993 Writing 0x01 to this variable generates the assembly code:
12994 \end_layout
12995
12996 \begin_layout Verse
12997
12998 \family typewriter
12999 3E 01\InsetSpace ~
13000 \InsetSpace ~
13001 \InsetSpace ~
13002 \InsetSpace ~
13003 \InsetSpace ~
13004 \InsetSpace ~
13005 ld a,#0x01
13006 \newline
13007 D3 78\InsetSpace ~
13008 \InsetSpace ~
13009 \InsetSpace ~
13010 \InsetSpace ~
13011 \InsetSpace ~
13012 \InsetSpace ~
13013 out (_IoPort),a 
13014 \end_layout
13015
13016 \begin_layout Subsubsection
13017 banked sfr
13018 \begin_inset LatexCommand \index{sfr}
13019
13020 \end_inset
13021
13022
13023 \begin_inset LatexCommand \index{\_\_sfr}
13024
13025 \end_inset
13026
13027  (in/out to 16-bit addresses)
13028 \end_layout
13029
13030 \begin_layout Standard
13031 The keyword 
13032 \emph on
13033 banked
13034 \emph default
13035  is used to support 16 bit addresses in I/O memory e.g.:
13036 \end_layout
13037
13038 \begin_layout Verse
13039
13040 \family typewriter
13041 sfr banked at
13042 \begin_inset LatexCommand \index{at}
13043
13044 \end_inset
13045
13046
13047 \begin_inset LatexCommand \index{\_\_at}
13048
13049 \end_inset
13050
13051  0x123 IoPort; 
13052 \end_layout
13053
13054 \begin_layout Standard
13055 Writing 0x01 to this variable generates the assembly code:
13056 \end_layout
13057
13058 \begin_layout Verse
13059
13060 \family typewriter
13061 01 23 01\InsetSpace ~
13062 \InsetSpace ~
13063 \InsetSpace ~
13064 ld bc,#_IoPort
13065 \newline
13066 3E 01\InsetSpace ~
13067 \InsetSpace ~
13068 \InsetSpace ~
13069 \InsetSpace ~
13070 \InsetSpace ~
13071 \InsetSpace ~
13072 ld a,#0x01 
13073 \newline
13074 ED 79\InsetSpace ~
13075 \InsetSpace ~
13076 \InsetSpace ~
13077 \InsetSpace ~
13078 \InsetSpace ~
13079 \InsetSpace ~
13080 out (c),a 
13081 \end_layout
13082
13083 \begin_layout Subsubsection
13084 sfr
13085 \begin_inset LatexCommand \index{sfr}
13086
13087 \end_inset
13088
13089
13090 \begin_inset LatexCommand \index{\_\_sfr}
13091
13092 \end_inset
13093
13094  (in0/out0 to 8 bit addresses on Z180
13095 \begin_inset LatexCommand \index{Z180}
13096
13097 \end_inset
13098
13099 /HD64180
13100 \begin_inset LatexCommand \index{HD64180 (see Z180)}
13101
13102 \end_inset
13103
13104 )
13105 \end_layout
13106
13107 \begin_layout Standard
13108 The compiler option -
13109 \begin_inset ERT
13110 status collapsed
13111
13112 \begin_layout Standard
13113
13114
13115 \backslash
13116 /
13117 \end_layout
13118
13119 \end_inset
13120
13121 -portmode
13122 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
13123
13124 \end_inset
13125
13126 =180 (80) and a compiler #pragma\InsetSpace ~
13127 portmode
13128 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
13129
13130 \end_inset
13131
13132  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13133 ns 
13134 \family typewriter
13135 in0/out0
13136 \family default
13137  instead of 
13138 \family typewriter
13139 in/out
13140 \family default
13141 .
13142  If you include the file z180.h this will be set automatically.
13143 \begin_inset VSpace bigskip
13144 \end_inset
13145
13146
13147 \end_layout
13148
13149 \begin_layout Subsection
13150 HC08 Storage Class
13151 \begin_inset LatexCommand \index{HC08!Storage class}
13152
13153 \end_inset
13154
13155  Language Extensions
13156 \end_layout
13157
13158 \begin_layout Subsubsection
13159 data
13160 \begin_inset LatexCommand \index{data (hc08 storage class)}
13161
13162 \end_inset
13163
13164
13165 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
13166
13167 \end_inset
13168
13169  
13170 \end_layout
13171
13172 \begin_layout Standard
13173 The data storage class declares a variable that resides in the first 256
13174  bytes of memory (the direct page).
13175  The HC08
13176 \begin_inset LatexCommand \index{HC08}
13177
13178 \end_inset
13179
13180  is most efficient at accessing variables (especially pointers) stored here.
13181 \end_layout
13182
13183 \begin_layout Subsubsection
13184 xdata
13185 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
13186
13187 \end_inset
13188
13189
13190 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
13191
13192 \end_inset
13193
13194  
13195 \end_layout
13196
13197 \begin_layout Standard
13198 The xdata storage class declares a variable that can reside anywhere in
13199  memory.
13200  This is the default if no storage class is specified.
13201  
13202 \begin_inset VSpace bigskip
13203 \end_inset
13204
13205
13206 \end_layout
13207
13208 \begin_layout Section
13209 Absolute Addressing
13210 \begin_inset LatexCommand \index{Absolute addressing}
13211
13212 \end_inset
13213
13214
13215 \end_layout
13216
13217 \begin_layout Standard
13218 Data items can be assigned an absolute address with the 
13219 \emph on
13220 at
13221 \begin_inset LatexCommand \index{at}
13222
13223 \end_inset
13224
13225
13226 \begin_inset LatexCommand \index{\_\_at}
13227
13228 \end_inset
13229
13230  <address>
13231 \emph default
13232  keyword, in addition to a storage class, e.g.:
13233 \end_layout
13234
13235 \begin_layout Verse
13236
13237 \family typewriter
13238 xdata
13239 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13240
13241 \end_inset
13242
13243
13244 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
13245
13246 \end_inset
13247
13248  at
13249 \begin_inset LatexCommand \index{at}
13250
13251 \end_inset
13252
13253
13254 \begin_inset LatexCommand \index{\_\_at}
13255
13256 \end_inset
13257
13258  0x7ffe unsigned int chksum;
13259 \end_layout
13260
13261 \begin_layout Standard
13262 or, better conforming to ISO/IEC 9899 C:
13263 \end_layout
13264
13265 \begin_layout Verse
13266
13267 \family typewriter
13268 __xdata __at (0x7ffe) unsigned int chksum;
13269 \end_layout
13270
13271 \begin_layout Standard
13272 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13273  of the external ram.
13274  The compiler does 
13275 \emph on
13276 not
13277 \emph default
13278  reserve any space for variables declared in this way
13279 \begin_inset Marginal
13280 status collapsed
13281
13282 \begin_layout Standard
13283
13284 \series bold
13285 \InsetSpace ~
13286 !
13287 \end_layout
13288
13289 \end_inset
13290
13291  (they are implemented with an equate in the assembler).
13292  Thus it is left to the programmer to make sure there are no overlaps with
13293  other variables that are declared without the absolute address.
13294  The assembler listing file (.lst
13295 \begin_inset LatexCommand \index{<file>.lst}
13296
13297 \end_inset
13298
13299 ) and the linker output files (.rst
13300 \begin_inset LatexCommand \index{<file>.rst}
13301
13302 \end_inset
13303
13304 ) and (.map
13305 \begin_inset LatexCommand \index{<file>.map}
13306
13307 \end_inset
13308
13309 ) are good places to look for such overlaps.
13310 \end_layout
13311
13312 \begin_layout Standard
13313 If however you provide an initializer
13314 \begin_inset LatexCommand \index{Variable initialization}
13315
13316 \end_inset
13317
13318  actual memory allocation will take place and overlaps will be detected
13319  by the linker.
13320  E.g.:
13321 \end_layout
13322
13323 \begin_layout Verse
13324
13325 \family typewriter
13326 __code __at (0x7ff0) char Id[5] = 
13327 \begin_inset Quotes sld
13328 \end_inset
13329
13330 SDCC
13331 \begin_inset Quotes srd
13332 \end_inset
13333
13334 ;
13335 \end_layout
13336
13337 \begin_layout Standard
13338 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
13339  in code memory.
13340 \end_layout
13341
13342 \begin_layout Standard
13343 In case of memory mapped I/O devices the keyword 
13344 \emph on
13345 volatile
13346 \emph default
13347  has to be used to tell the compiler that accesses might not be removed:
13348 \end_layout
13349
13350 \begin_layout Verse
13351
13352 \family typewriter
13353 volatile
13354 \begin_inset LatexCommand \index{volatile}
13355
13356 \end_inset
13357
13358  __xdata
13359 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13360
13361 \end_inset
13362
13363  __at
13364 \begin_inset LatexCommand \index{at}
13365
13366 \end_inset
13367
13368  (0x8000) unsigned char PORTA_8255;
13369 \end_layout
13370
13371 \begin_layout Standard
13372 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
13373 r) array
13374 \family typewriter
13375 \size footnotesize
13376
13377 \begin_inset LatexCommand \index{Aligned array}
13378
13379 \end_inset
13380
13381
13382 \family default
13383 \size default
13384  starts at a block (256 byte) boundary
13385 \begin_inset LatexCommand \index{block boundary}
13386
13387 \end_inset
13388
13389  (section 
13390 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13391
13392 \end_inset
13393
13394  has an example).
13395 \newline
13396 Absolute addresses can be specified for variables in all
13397  storage classes, e.g.:
13398 \end_layout
13399
13400 \begin_layout Verse
13401
13402 \family typewriter
13403 __bit
13404 \begin_inset LatexCommand \index{bit}
13405
13406 \end_inset
13407
13408  __at
13409 \begin_inset LatexCommand \index{at}
13410
13411 \end_inset
13412
13413  (0x02) bvar;
13414 \end_layout
13415
13416 \begin_layout Standard
13417 The above example will allocate the variable at offset 0x02 in the bit-addressab
13418 le space.
13419  There is no real advantage to assigning absolute addresses to variables
13420  in this manner, unless you want strict control over all the variables allocated.
13421  One possible use would be to write hardware portable code.
13422  For example, if you have a routine that uses one or more of the microcontroller
13423  I/O pins, and such pins are different for two different hardwares, you
13424  can declare the I/O pins in your routine using:
13425 \end_layout
13426
13427 \begin_layout Verse
13428
13429 \family typewriter
13430 extern volatile
13431 \begin_inset LatexCommand \index{volatile}
13432
13433 \end_inset
13434
13435  __bit MOSI;\InsetSpace ~
13436 \InsetSpace ~
13437 \InsetSpace ~
13438 \InsetSpace ~
13439 /* master out, slave in */
13440 \newline
13441 extern volatile __bit MISO;\InsetSpace ~
13442 \InsetSpace ~
13443 \InsetSpace ~
13444 \InsetSpace ~
13445 /* master
13446  in, slave out */
13447 \newline
13448 extern volatile __bit MCLK;\InsetSpace ~
13449 \InsetSpace ~
13450 \InsetSpace ~
13451 \InsetSpace ~
13452 /* master clock */
13453 \newline
13454
13455 \newline
13456 /* Input and
13457  Output of a byte on a 3-wire serial bus.
13458 \newline
13459 \InsetSpace ~
13460 \InsetSpace ~
13461 \InsetSpace ~
13462 If needed adapt polarity of clock,
13463  polarity of data and bit order
13464 \newline
13465 \InsetSpace ~
13466 */
13467 \newline
13468 unsigned char spi_io(unsigned char out_byte)
13469  
13470 \newline
13471
13472 \newline
13473 \InsetSpace ~
13474 \InsetSpace ~
13475 \InsetSpace ~
13476 \InsetSpace ~
13477 unsigned char i=8;
13478 \newline
13479 \InsetSpace ~
13480 \InsetSpace ~
13481 \InsetSpace ~
13482 \InsetSpace ~
13483 do { 
13484 \newline
13485 \InsetSpace ~
13486 \InsetSpace ~
13487 \InsetSpace ~
13488 \InsetSpace ~
13489 \InsetSpace ~
13490 \InsetSpace ~
13491 \InsetSpace ~
13492 \InsetSpace ~
13493 MOSI = out_byte & 0x80; 
13494 \newline
13495 \InsetSpace ~
13496 \InsetSpace ~
13497 \InsetSpace ~
13498 \InsetSpace ~
13499 \InsetSpace ~
13500 \InsetSpace ~
13501 \InsetSpace ~
13502 \InsetSpace ~
13503 out_byte <<= 1;
13504 \newline
13505 \InsetSpace ~
13506 \InsetSpace ~
13507 \InsetSpace ~
13508 \InsetSpace ~
13509 \InsetSpace ~
13510 \InsetSpace ~
13511 \InsetSpace ~
13512 \InsetSpace ~
13513 MCLK =
13514  1; 
13515 \newline
13516 \InsetSpace ~
13517 \InsetSpace ~
13518 \InsetSpace ~
13519 \InsetSpace ~
13520 \InsetSpace ~
13521 \InsetSpace ~
13522 \InsetSpace ~
13523 \InsetSpace ~
13524 /* _asm nop _endasm; */\InsetSpace ~
13525 \InsetSpace ~
13526 \InsetSpace ~
13527 \InsetSpace ~
13528 \InsetSpace ~
13529 \InsetSpace ~
13530 \InsetSpace ~
13531 \InsetSpace ~
13532 /* for slow peripherals */
13533 \newline
13534 \InsetSpace ~
13535 \InsetSpace ~
13536 \InsetSpace ~
13537 \InsetSpace ~
13538 \InsetSpace ~
13539 \InsetSpace ~
13540 \InsetSpace ~
13541 \InsetSpace ~
13542 if(MISO) 
13543 \newline
13544 \InsetSpace ~
13545 \InsetSpace ~
13546 \InsetSpace ~
13547 \InsetSpace ~
13548 \InsetSpace ~
13549 \InsetSpace ~
13550 \InsetSpace ~
13551 \InsetSpace ~
13552 \InsetSpace ~
13553 \InsetSpace ~
13554 \InsetSpace ~
13555 \InsetSpace ~
13556 out_byte +=
13557  1; 
13558 \newline
13559 \InsetSpace ~
13560 \InsetSpace ~
13561 \InsetSpace ~
13562 \InsetSpace ~
13563 \InsetSpace ~
13564 \InsetSpace ~
13565 \InsetSpace ~
13566 \InsetSpace ~
13567 MCLK = 0; 
13568 \newline
13569 \InsetSpace ~
13570 \InsetSpace ~
13571 \InsetSpace ~
13572 \InsetSpace ~
13573 } while(--i);
13574 \newline
13575 \InsetSpace ~
13576 \InsetSpace ~
13577 \InsetSpace ~
13578 \InsetSpace ~
13579 return out_byte; 
13580 \newline
13581 }
13582 \end_layout
13583
13584 \begin_layout Standard
13585 Then, someplace in the code for the first hardware you would use
13586 \end_layout
13587
13588 \begin_layout Verse
13589
13590 \family typewriter
13591 __bit __at
13592 \begin_inset LatexCommand \index{at}
13593
13594 \end_inset
13595
13596
13597 \begin_inset LatexCommand \index{\_\_at}
13598
13599 \end_inset
13600
13601  (0x80) MOSI;\InsetSpace ~
13602 \InsetSpace ~
13603 \InsetSpace ~
13604 \InsetSpace ~
13605 /* I/O port 0, bit 0 */
13606 \newline
13607 __bit __at (0x81) MISO;\InsetSpace ~
13608 \InsetSpace ~
13609 \InsetSpace ~
13610 \InsetSpace ~
13611 /* I/O port 0,
13612  bit 1 */
13613 \newline
13614 __bit __at (0x82) MCLK;\InsetSpace ~
13615 \InsetSpace ~
13616 \InsetSpace ~
13617 \InsetSpace ~
13618 /* I/O port 0, bit 2 */
13619 \end_layout
13620
13621 \begin_layout Standard
13622 Similarly, for the second hardware you would use
13623 \end_layout
13624
13625 \begin_layout Verse
13626
13627 \family typewriter
13628 __bit __at (0x83) MOSI;\InsetSpace ~
13629 \InsetSpace ~
13630 \InsetSpace ~
13631 \InsetSpace ~
13632 /* I/O port 0, bit 3 */
13633 \newline
13634 __bit __at (0x91) MISO;\InsetSpace ~
13635 \InsetSpace ~
13636 \InsetSpace ~
13637 \InsetSpace ~
13638 /*
13639  I/O port 1, bit 1 */
13640 \newline
13641 __bit
13642 \begin_inset LatexCommand \index{bit}
13643
13644 \end_inset
13645
13646  __at (0x92) MCLK;\InsetSpace ~
13647 \InsetSpace ~
13648 \InsetSpace ~
13649 \InsetSpace ~
13650 /* I/O port 1, bit 2 */
13651 \end_layout
13652
13653 \begin_layout Standard
13654 and you can use the same hardware dependent routine without changes, as
13655  for example in a library.
13656  This is somehow similar to sbit, but only one absolute address has to be
13657  specified in the whole project.
13658 \begin_inset VSpace bigskip
13659 \end_inset
13660
13661
13662 \end_layout
13663
13664 \begin_layout Section
13665 Parameters
13666 \begin_inset LatexCommand \index{Parameters}
13667
13668 \end_inset
13669
13670
13671 \begin_inset LatexCommand \index{function parameter}
13672
13673 \end_inset
13674
13675  & Local Variables
13676 \begin_inset LatexCommand \index{local variables}
13677
13678 \end_inset
13679
13680
13681 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13682
13683 \end_inset
13684
13685
13686 \end_layout
13687
13688 \begin_layout Standard
13689 Automatic (local) variables and parameters to functions can either be placed
13690  on the stack or in data-space.
13691  The default action of the compiler is to place these variables in the internal
13692  RAM (for small model) or external RAM (for medium or large model).
13693  This in fact makes them similar to 
13694 \emph on
13695 static
13696 \begin_inset LatexCommand \index{static}
13697
13698 \end_inset
13699
13700
13701 \emph default
13702  so by default functions are non-reentrant
13703 \begin_inset LatexCommand \index{reentrant}
13704
13705 \end_inset
13706
13707 .
13708  
13709 \newline
13710
13711 \newline
13712 They can be placed on the stack
13713 \begin_inset LatexCommand \index{stack}
13714
13715 \end_inset
13716
13717  by using the
13718 \emph on
13719  -
13720 \begin_inset ERT
13721 status collapsed
13722
13723 \begin_layout Standard
13724
13725
13726 \backslash
13727 /
13728 \end_layout
13729
13730 \end_inset
13731
13732 -stack-auto
13733 \begin_inset LatexCommand \index{-\/-stack-auto}
13734
13735 \end_inset
13736
13737
13738 \emph default
13739  option, by using 
13740 \emph on
13741 #pragma\InsetSpace ~
13742 stackauto
13743 \emph default
13744
13745 \begin_inset LatexCommand \index{\#pragma stackauto}
13746
13747 \end_inset
13748
13749  or by using the 
13750 \emph on
13751 reentrant
13752 \begin_inset LatexCommand \index{reentrant}
13753
13754 \end_inset
13755
13756
13757 \emph default
13758  keyword in the function declaration, e.g.:
13759 \end_layout
13760
13761 \begin_layout Verse
13762
13763 \family typewriter
13764 unsigned char foo(char i) __reentrant 
13765 \newline
13766
13767 \newline
13768 \InsetSpace ~
13769 \InsetSpace ~
13770 \InsetSpace ~
13771 \InsetSpace ~
13772 ...
13773  
13774 \newline
13775 }
13776 \end_layout
13777
13778 \begin_layout Standard
13779 Since stack space on 8051 is limited, the 
13780 \emph on
13781 reentrant 
13782 \emph default
13783 keyword or the
13784 \emph on
13785  -
13786 \begin_inset ERT
13787 status collapsed
13788
13789 \begin_layout Standard
13790
13791
13792 \backslash
13793 /
13794 \end_layout
13795
13796 \end_inset
13797
13798 -stack-auto
13799 \emph default
13800  option should be used sparingly.
13801  Note that the reentrant keyword just means that the parameters & local
13802  variables will be allocated to the stack, it 
13803 \emph on
13804 does not
13805 \emph default
13806  mean that the function is register bank
13807 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13808
13809 \end_inset
13810
13811  independent.
13812 \newline
13813
13814 \newline
13815 Local variables
13816 \begin_inset LatexCommand \index{local variables}
13817
13818 \end_inset
13819
13820  can be assigned storage classes and absolute
13821 \begin_inset LatexCommand \index{Absolute addressing}
13822
13823 \end_inset
13824
13825  addresses, e.g.: 
13826 \end_layout
13827
13828 \begin_layout Verse
13829
13830 \family typewriter
13831 unsigned char foo() 
13832 \newline
13833 {
13834 \newline
13835 \InsetSpace ~
13836 \InsetSpace ~
13837 \InsetSpace ~
13838 \InsetSpace ~
13839 __xdata unsigned char i;
13840 \newline
13841 \InsetSpace ~
13842 \InsetSpace ~
13843 \InsetSpace ~
13844 \InsetSpace ~
13845 __bit bvar;
13846 \newline
13847 \InsetSpace ~
13848 \InsetSpace ~
13849 \InsetSpace ~
13850 \InsetSpace ~
13851 __data __at
13852 \begin_inset LatexCommand \index{at}
13853
13854 \end_inset
13855
13856  (0x31) unsigned char j;
13857 \newline
13858 \InsetSpace ~
13859 \InsetSpace ~
13860 \InsetSpace ~
13861 \InsetSpace ~
13862 ...
13863  
13864 \newline
13865 }
13866 \end_layout
13867
13868 \begin_layout Standard
13869 In the above example the variable 
13870 \emph on
13871 i
13872 \emph default
13873  will be allocated in the external ram, 
13874 \emph on
13875 bvar
13876 \emph default
13877  in bit addressable space and
13878 \emph on
13879  j
13880 \emph default
13881  in internal ram.
13882  When compiled with 
13883 \emph on
13884 -
13885 \begin_inset ERT
13886 status collapsed
13887
13888 \begin_layout Standard
13889
13890
13891 \backslash
13892 /
13893 \end_layout
13894
13895 \end_inset
13896
13897 -stack-auto
13898 \emph default
13899  or when a function is declared as 
13900 \emph on
13901 reentrant
13902 \emph default
13903  this should only be done for static variables.
13904 \end_layout
13905
13906 \begin_layout Standard
13907 Parameters
13908 \begin_inset LatexCommand \index{function parameter}
13909
13910 \end_inset
13911
13912  however are not allowed any storage class
13913 \begin_inset LatexCommand \index{Storage class}
13914
13915 \end_inset
13916
13917 , (storage classes for parameters will be ignored), their allocation is
13918  governed by the memory model in use, and the reentrancy options.
13919 \end_layout
13920
13921 \begin_layout Standard
13922 It is however allowed to use bit parameters in reentrant functions and also
13923  non-static local bit variables are supported.
13924  Efficient use is limited to 8 semi-bitregisters in bit space.
13925  They are pushed and popped to stack
13926 \begin_inset LatexCommand \index{stack}
13927
13928 \end_inset
13929
13930  as a single byte just like the normal registers.
13931 \end_layout
13932
13933 \begin_layout Section
13934 Overlaying
13935 \begin_inset LatexCommand \label{sub:Overlaying}
13936
13937 \end_inset
13938
13939
13940 \begin_inset LatexCommand \index{Overlaying}
13941
13942 \end_inset
13943
13944
13945 \end_layout
13946
13947 \begin_layout Standard
13948 For non-reentrant
13949 \begin_inset LatexCommand \index{reentrant}
13950
13951 \end_inset
13952
13953  functions SDCC will try to reduce internal ram space usage by overlaying
13954  parameters and local variables of a function (if possible).
13955  Parameters and local variables
13956 \begin_inset LatexCommand \index{local variables}
13957
13958 \end_inset
13959
13960  of a function will be allocated to an overlayable segment if the function
13961  has 
13962 \emph on
13963 no other function calls and the function is non-reentrant and the memory
13964  model
13965 \begin_inset LatexCommand \index{Memory model}
13966
13967 \end_inset
13968
13969  is small.
13970
13971 \emph default
13972  If an explicit storage class
13973 \begin_inset LatexCommand \index{Storage class}
13974
13975 \end_inset
13976
13977  is specified for a local variable, it will NOT be overlayed.
13978 \end_layout
13979
13980 \begin_layout Standard
13981 Note that the compiler (not the linkage editor) makes the decision for overlayin
13982 g the data items.
13983  Functions that are called from an interrupt service routine
13984 \begin_inset Marginal
13985 status collapsed
13986
13987 \begin_layout Standard
13988
13989 \series bold
13990 !
13991 \end_layout
13992
13993 \end_inset
13994
13995  should be preceded by a #pragma\InsetSpace ~
13996 nooverlay
13997 \begin_inset LatexCommand \index{\#pragma nooverlay}
13998
13999 \end_inset
14000
14001  if they are not reentrant.
14002 \end_layout
14003
14004 \begin_layout Standard
14005 Also note that the compiler does not do any processing of inline assembler
14006  code, so the compiler might incorrectly assign local variables and parameters
14007  of a function into the overlay segment if the inline assembler code calls
14008  other c-functions that might use the overlay.
14009  In that case the #pragma\InsetSpace ~
14010 nooverlay should be used.
14011 \end_layout
14012
14013 \begin_layout Standard
14014 Parameters and local variables of functions that contain 16 or 32 bit multiplica
14015 tion
14016 \begin_inset LatexCommand \index{Multiplication}
14017
14018 \end_inset
14019
14020  or division
14021 \begin_inset LatexCommand \index{Division}
14022
14023 \end_inset
14024
14025  will NOT be overlayed since these are implemented using external functions,
14026  e.g.:
14027 \end_layout
14028
14029 \begin_layout Verse
14030
14031 \family typewriter
14032 #pragma save 
14033 \newline
14034 #pragma nooverlay
14035 \begin_inset LatexCommand \index{\#pragma nooverlay}
14036
14037 \end_inset
14038
14039  
14040 \newline
14041 void set_error(unsigned char errcd) 
14042 \newline
14043 {
14044 \newline
14045 \InsetSpace ~
14046 \InsetSpace ~
14047 \InsetSpace ~
14048 \InsetSpace ~
14049 P3 = errcd;
14050 \newline
14051
14052 \newline
14053 #pragma restore 
14054 \newline
14055
14056 \newline
14057 void
14058  some_isr () __interrupt
14059 \begin_inset LatexCommand \index{interrupt}
14060
14061 \end_inset
14062
14063  (2)
14064 \newline
14065 {
14066 \newline
14067 \InsetSpace ~
14068 \InsetSpace ~
14069 \InsetSpace ~
14070 \InsetSpace ~
14071 ...
14072 \newline
14073 \InsetSpace ~
14074 \InsetSpace ~
14075 \InsetSpace ~
14076 \InsetSpace ~
14077 set_error(10);
14078 \newline
14079 \InsetSpace ~
14080 \InsetSpace ~
14081 \InsetSpace ~
14082 \InsetSpace ~
14083 ...
14084  
14085 \newline
14086 }
14087 \end_layout
14088
14089 \begin_layout Standard
14090 In the above example the parameter 
14091 \emph on
14092 errcd
14093 \emph default
14094  for the function 
14095 \emph on
14096 set_error
14097 \emph default
14098  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14099 nooverlay was
14100  not present, this could cause unpredictable runtime behavior when called
14101  from an interrupt service routine.
14102  The #pragma\InsetSpace ~
14103 nooverlay ensures that the parameters and local variables for
14104  the function are NOT overlayed.
14105 \begin_inset VSpace bigskip
14106 \end_inset
14107
14108
14109 \end_layout
14110
14111 \begin_layout Section
14112 Interrupt Service Routines
14113 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
14114
14115 \end_inset
14116
14117
14118 \end_layout
14119
14120 \begin_layout Subsection
14121 General Information
14122 \end_layout
14123
14124 \begin_layout Standard
14125 SDCC allows 
14126 \emph on
14127 i
14128 \emph default
14129 nterrupt 
14130 \emph on
14131 s
14132 \emph default
14133 ervice 
14134 \emph on
14135 r
14136 \emph default
14137 outines to be coded in C, with some extended keywords.
14138 \end_layout
14139
14140 \begin_layout Verse
14141
14142 \family typewriter
14143 void timer_isr (void) __interrupt (1) __using (1) 
14144 \newline
14145
14146 \newline
14147 \InsetSpace ~
14148 \InsetSpace ~
14149 \InsetSpace ~
14150 \InsetSpace ~
14151 ...
14152  
14153 \newline
14154 }
14155 \end_layout
14156
14157 \begin_layout Standard
14158 The optional number following the 
14159 \emph on
14160 interrupt
14161 \begin_inset LatexCommand \index{interrupt}
14162
14163 \end_inset
14164
14165
14166 \begin_inset LatexCommand \index{\_\_interrupt}
14167
14168 \end_inset
14169
14170
14171 \emph default
14172  keyword is the interrupt number this routine will service.
14173  When present, the compiler will insert a call to this routine in the interrupt
14174  vector table
14175 \begin_inset LatexCommand \index{interrupt vector table}
14176
14177 \end_inset
14178
14179  for the interrupt number specified.
14180  If you have multiple source files in your project, interrupt service routines
14181  can be present in any of them, but a prototype of the isr MUST be present
14182  or included in the file that contains the function 
14183 \emph on
14184 main
14185 \emph default
14186 .
14187  The optional (8051 specific) keyword 
14188 \emph on
14189 using
14190 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14191
14192 \end_inset
14193
14194
14195 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14196
14197 \end_inset
14198
14199
14200 \emph default
14201  can be used to tell the compiler to use the specified register bank when
14202  generating code for this function.
14203  
14204 \newline
14205 Interrupt service routines open the door for some very interesting bugs:
14206 \end_layout
14207
14208 \begin_layout Subsubsection
14209 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
14210
14211 \end_inset
14212
14213 Common interrupt pitfall: variable not declared 
14214 \emph on
14215 volatile
14216 \end_layout
14217
14218 \begin_layout Standard
14219 If an interrupt service routine changes variables which are accessed by
14220  other functions these variables have to be declared 
14221 \emph on
14222 volatile
14223 \emph default
14224
14225 \begin_inset LatexCommand \index{volatile}
14226
14227 \end_inset
14228
14229 .
14230  See 
14231 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
14232
14233 \end_inset
14234
14235  .
14236 \end_layout
14237
14238 \begin_layout Subsubsection
14239 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
14240
14241 \end_inset
14242
14243 Common interrupt pitfall: 
14244 \emph on
14245 non-atomic access
14246 \end_layout
14247
14248 \begin_layout Standard
14249 If the access to these variables is not 
14250 \emph on
14251 atomic
14252 \begin_inset LatexCommand \index{atomic}
14253
14254 \end_inset
14255
14256
14257 \emph default
14258  (i.e.
14259  the processor needs more than one instruction for the access and could
14260  be interrupted while accessing the variable) the interrupt must be disabled
14261  during the access to avoid inconsistent data.
14262  
14263 \newline
14264 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
14265  and should be protected by disabling interrupts.
14266  You're not automatically on the safe side if you use 8 bit variables though.
14267  We need an example here: f.e.
14268  on the 8051 the harmless looking 
14269 \begin_inset Quotes srd
14270 \end_inset
14271
14272
14273 \family typewriter
14274 flags\InsetSpace ~
14275 |=\InsetSpace ~
14276 0x80;
14277 \family default
14278
14279 \begin_inset Quotes sld
14280 \end_inset
14281
14282  is not atomic if 
14283 \family typewriter
14284 flags
14285 \family default
14286  resides in xdata.
14287  Setting 
14288 \begin_inset Quotes srd
14289 \end_inset
14290
14291
14292 \family typewriter
14293 flags\InsetSpace ~
14294 |=\InsetSpace ~
14295 0x40;
14296 \family default
14297
14298 \begin_inset Quotes sld
14299 \end_inset
14300
14301  from within an interrupt routine might get lost if the interrupt occurs
14302  at the wrong time.
14303  
14304 \begin_inset Quotes sld
14305 \end_inset
14306
14307
14308 \family typewriter
14309 counter\InsetSpace ~
14310 +=\InsetSpace ~
14311 8;
14312 \family default
14313
14314 \begin_inset Quotes srd
14315 \end_inset
14316
14317  is not atomic on the 8051 even if 
14318 \family typewriter
14319 counter
14320 \family default
14321  is located in data memory.
14322 \newline
14323 Bugs like these are hard to reproduce and can
14324  cause a lot of trouble.
14325  
14326 \end_layout
14327
14328 \begin_layout Subsubsection
14329 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
14330
14331 \end_inset
14332
14333 Common interrupt pitfall: 
14334 \emph on
14335 stack overflow
14336 \end_layout
14337
14338 \begin_layout Standard
14339 The return address and the registers used in the interrupt service routine
14340  are saved on the stack
14341 \begin_inset LatexCommand \index{stack}
14342
14343 \end_inset
14344
14345  so there must be sufficient stack space.
14346  If there isn't variables or registers (or even the return address itself)
14347  will be corrupted.
14348  This 
14349 \emph on
14350 stack overflow
14351 \emph default
14352
14353 \begin_inset LatexCommand \index{stack overflow}
14354
14355 \end_inset
14356
14357  is most likely to happen if the interrupt occurs during the 
14358 \begin_inset Quotes sld
14359 \end_inset
14360
14361 deepest
14362 \begin_inset Quotes srd
14363 \end_inset
14364
14365  subroutine when the stack is already in use for f.e.
14366  many return addresses.
14367 \end_layout
14368
14369 \begin_layout Subsubsection
14370 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
14371
14372 \end_inset
14373
14374 Common interrupt pitfall: 
14375 \emph on
14376 use of non-reentrant functions
14377 \end_layout
14378
14379 \begin_layout Standard
14380 A special note here, int (16 bit) and long (32 bit) integer division
14381 \begin_inset LatexCommand \index{Division}
14382
14383 \end_inset
14384
14385 , multiplication
14386 \begin_inset LatexCommand \index{Multiplication}
14387
14388 \end_inset
14389
14390  & modulus
14391 \begin_inset LatexCommand \index{Modulus}
14392
14393 \end_inset
14394
14395  and floating-point
14396 \begin_inset LatexCommand \index{Floating point support}
14397
14398 \end_inset
14399
14400  operations are implemented using external support routines.
14401  If an interrupt service routine needs to do any of these operations then
14402  the support routines (as mentioned in a following section) will have to
14403  be recompiled using the
14404 \emph on
14405  -
14406 \begin_inset ERT
14407 status collapsed
14408
14409 \begin_layout Standard
14410
14411
14412 \backslash
14413 /
14414 \end_layout
14415
14416 \end_inset
14417
14418 -stack-auto
14419 \begin_inset LatexCommand \index{-\/-stack-auto}
14420
14421 \end_inset
14422
14423
14424 \emph default
14425  option and the source file will need to be compiled using the 
14426 \emph on
14427 -
14428 \begin_inset ERT
14429 status collapsed
14430
14431 \begin_layout Standard
14432
14433
14434 \backslash
14435 /
14436 \end_layout
14437
14438 \end_inset
14439
14440 -int-long-reent
14441 \emph default
14442
14443 \begin_inset LatexCommand \index{-\/-int-long-reent}
14444
14445 \end_inset
14446
14447  compiler option.
14448  
14449 \newline
14450 Note, the type promotion
14451 \begin_inset LatexCommand \index{type promotion}
14452
14453 \end_inset
14454
14455  required by ANSI C can cause 16 bit routines to be used
14456 \begin_inset Marginal
14457 status collapsed
14458
14459 \begin_layout Standard
14460
14461 \series bold
14462 \InsetSpace ~
14463 !
14464 \end_layout
14465
14466 \end_inset
14467
14468  without the programmer being aware of it.
14469  See f.e.
14470  the cast 
14471 \family typewriter
14472 (unsigned char)(tail-1)
14473 \family default
14474  within the if clause in section 
14475 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
14476
14477 \end_inset
14478
14479 .
14480 \end_layout
14481
14482 \begin_layout Standard
14483 Calling other functions from an interrupt service routine is not recommended,
14484  avoid it if possible.
14485  Note that when some function is called from an interrupt service routine
14486  it should be preceded by a #pragma\InsetSpace ~
14487 nooverlay
14488 \begin_inset LatexCommand \index{\#pragma nooverlay}
14489
14490 \end_inset
14491
14492  if it is not reentrant.
14493  Furthermore nonreentrant functions should not be called from the main program
14494  while the interrupt service routine might be active.
14495  They also must not be called from low priority interrupt service routines
14496  while a high priority interrupt service routine might be active.
14497  You could use semaphores or make the function
14498 \emph on
14499  critical
14500 \emph default
14501  if all parameters are passed in registers.
14502 \newline
14503  Also see section 
14504 \begin_inset LatexCommand \ref{sub:Overlaying}
14505
14506 \end_inset
14507
14508 \InsetSpace ~
14509 about Overlaying and section 
14510 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14511
14512 \end_inset
14513
14514 \InsetSpace ~
14515 about Functions using private register banks.
14516 \begin_inset VSpace bigskip
14517 \end_inset
14518
14519
14520 \end_layout
14521
14522 \begin_layout Subsection
14523 MCS51/DS390 Interrupt Service Routines
14524 \end_layout
14525
14526 \begin_layout Standard
14527 Interrupt
14528 \begin_inset LatexCommand \index{interrupt}
14529
14530 \end_inset
14531
14532  numbers and the corresponding address & descriptions for the Standard 8051/8052
14533  are listed below.
14534  SDCC will automatically adjust the 
14535 \begin_inset LatexCommand \index{interrupt vector table}
14536
14537 \end_inset
14538
14539  to the maximum interrupt number specified.
14540 \newline
14541
14542 \end_layout
14543
14544 \begin_layout Standard
14545 \align center
14546 \begin_inset Tabular
14547 <lyxtabular version="3" rows="9" columns="3">
14548 <features>
14549 <column alignment="center" valignment="top" leftline="true" width="0in">
14550 <column alignment="left" valignment="top" leftline="true" width="0in">
14551 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14552 <row topline="true" bottomline="true">
14553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14554 \begin_inset Text
14555
14556 \begin_layout Standard
14557 Interrupt #
14558 \end_layout
14559
14560 \end_inset
14561 </cell>
14562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14563 \begin_inset Text
14564
14565 \begin_layout Standard
14566 Description
14567 \end_layout
14568
14569 \end_inset
14570 </cell>
14571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14572 \begin_inset Text
14573
14574 \begin_layout Standard
14575 Vector Address
14576 \end_layout
14577
14578 \end_inset
14579 </cell>
14580 </row>
14581 <row topline="true">
14582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14583 \begin_inset Text
14584
14585 \begin_layout Standard
14586 0
14587 \end_layout
14588
14589 \end_inset
14590 </cell>
14591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14592 \begin_inset Text
14593
14594 \begin_layout Standard
14595 External 0
14596 \end_layout
14597
14598 \end_inset
14599 </cell>
14600 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14601 \begin_inset Text
14602
14603 \begin_layout Standard
14604 0x0003
14605 \end_layout
14606
14607 \end_inset
14608 </cell>
14609 </row>
14610 <row topline="true">
14611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14612 \begin_inset Text
14613
14614 \begin_layout Standard
14615 1
14616 \end_layout
14617
14618 \end_inset
14619 </cell>
14620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14621 \begin_inset Text
14622
14623 \begin_layout Standard
14624 Timer 0
14625 \end_layout
14626
14627 \end_inset
14628 </cell>
14629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14630 \begin_inset Text
14631
14632 \begin_layout Standard
14633 0x000b
14634 \end_layout
14635
14636 \end_inset
14637 </cell>
14638 </row>
14639 <row topline="true">
14640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14641 \begin_inset Text
14642
14643 \begin_layout Standard
14644 2
14645 \end_layout
14646
14647 \end_inset
14648 </cell>
14649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14650 \begin_inset Text
14651
14652 \begin_layout Standard
14653 External 1
14654 \end_layout
14655
14656 \end_inset
14657 </cell>
14658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14659 \begin_inset Text
14660
14661 \begin_layout Standard
14662 0x0013
14663 \end_layout
14664
14665 \end_inset
14666 </cell>
14667 </row>
14668 <row topline="true">
14669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14670 \begin_inset Text
14671
14672 \begin_layout Standard
14673 3
14674 \end_layout
14675
14676 \end_inset
14677 </cell>
14678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14679 \begin_inset Text
14680
14681 \begin_layout Standard
14682 Timer 1
14683 \end_layout
14684
14685 \end_inset
14686 </cell>
14687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14688 \begin_inset Text
14689
14690 \begin_layout Standard
14691 0x001b
14692 \end_layout
14693
14694 \end_inset
14695 </cell>
14696 </row>
14697 <row topline="true">
14698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14699 \begin_inset Text
14700
14701 \begin_layout Standard
14702 4
14703 \end_layout
14704
14705 \end_inset
14706 </cell>
14707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14708 \begin_inset Text
14709
14710 \begin_layout Standard
14711 Serial
14712 \end_layout
14713
14714 \end_inset
14715 </cell>
14716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14717 \begin_inset Text
14718
14719 \begin_layout Standard
14720 0x0023
14721 \end_layout
14722
14723 \end_inset
14724 </cell>
14725 </row>
14726 <row topline="true">
14727 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14728 \begin_inset Text
14729
14730 \begin_layout Standard
14731 5
14732 \end_layout
14733
14734 \end_inset
14735 </cell>
14736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14737 \begin_inset Text
14738
14739 \begin_layout Standard
14740 Timer 2 (8052)
14741 \end_layout
14742
14743 \end_inset
14744 </cell>
14745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14746 \begin_inset Text
14747
14748 \begin_layout Standard
14749 0x002b
14750 \end_layout
14751
14752 \end_inset
14753 </cell>
14754 </row>
14755 <row topline="true">
14756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14757 \begin_inset Text
14758
14759 \begin_layout Standard
14760 ...
14761 \end_layout
14762
14763 \end_inset
14764 </cell>
14765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14766 \begin_inset Text
14767
14768 \begin_layout Standard
14769
14770 \end_layout
14771
14772 \end_inset
14773 </cell>
14774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14775 \begin_inset Text
14776
14777 \begin_layout Standard
14778 ...
14779 \end_layout
14780
14781 \end_inset
14782 </cell>
14783 </row>
14784 <row topline="true" bottomline="true">
14785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14786 \begin_inset Text
14787
14788 \begin_layout Standard
14789 n
14790 \end_layout
14791
14792 \end_inset
14793 </cell>
14794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14795 \begin_inset Text
14796
14797 \begin_layout Standard
14798
14799 \end_layout
14800
14801 \end_inset
14802 </cell>
14803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14804 \begin_inset Text
14805
14806 \begin_layout Standard
14807 0x0003 + 8*n
14808 \end_layout
14809
14810 \end_inset
14811 </cell>
14812 </row>
14813 </lyxtabular>
14814
14815 \end_inset
14816
14817
14818 \newline
14819
14820 \end_layout
14821
14822 \begin_layout Standard
14823 If the interrupt service routine is defined without 
14824 \emph on
14825 using
14826 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14827
14828 \end_inset
14829
14830
14831 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14832
14833 \end_inset
14834
14835
14836 \emph default
14837  a register bank or with register bank 0 (
14838 \emph on
14839 using
14840 \emph default
14841  0), the compiler will save the registers used by itself on the stack upon
14842  entry and restore them at exit, however if such an interrupt service routine
14843  calls another function then the entire register bank will be saved on the
14844  stack.
14845  This scheme may be advantageous for small interrupt service routines which
14846  have low register usage.
14847 \end_layout
14848
14849 \begin_layout Standard
14850 If the interrupt service routine is defined to be using a specific register
14851  bank then only 
14852 \emph on
14853 a, b, dptr
14854 \emph default
14855  & psw are saved and restored, if such an interrupt service routine calls
14856  another function (using another register bank) then the entire register
14857  bank of the called function will be saved on the stack
14858 \begin_inset LatexCommand \index{stack}
14859
14860 \end_inset
14861
14862 .
14863  This scheme is recommended for larger interrupt service routines.
14864 \begin_inset VSpace bigskip
14865 \end_inset
14866
14867
14868 \end_layout
14869
14870 \begin_layout Subsection
14871 HC08
14872 \begin_inset LatexCommand \index{HC08}
14873
14874 \end_inset
14875
14876  Interrupt Service Routines
14877 \end_layout
14878
14879 \begin_layout Standard
14880 Since the number of interrupts
14881 \begin_inset LatexCommand \index{HC08!interrupt}
14882
14883 \end_inset
14884
14885  available is chip specific and the interrupt vector table always ends at
14886  the last byte of memory, the interrupt numbers corresponds to the interrupt
14887  vectors in reverse order of address.
14888  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14889  2 will use the interrupt vector at 0xfffa, and so on.
14890  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14891  this way; instead see section 
14892 \begin_inset LatexCommand \ref{sub:Startup-Code}
14893
14894 \end_inset
14895
14896  for details on customizing startup.
14897 \begin_inset VSpace bigskip
14898 \end_inset
14899
14900
14901 \end_layout
14902
14903 \begin_layout Subsection
14904 Z80 Interrupt Service Routines
14905 \end_layout
14906
14907 \begin_layout Standard
14908 The Z80
14909 \begin_inset LatexCommand \index{Z80}
14910
14911 \end_inset
14912
14913  uses several different methods for determining the correct interrupt
14914 \begin_inset LatexCommand \index{Z80!interrupt}
14915
14916 \end_inset
14917
14918  vector depending on the hardware implementation.
14919  Therefore, SDCC ignores the optional interrupt number and does not attempt
14920  to generate an interrupt vector table.
14921 \end_layout
14922
14923 \begin_layout Standard
14924 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14925  instruction to return from the interrupt.
14926  To write an interrupt handler for the non-maskable interrupt, which needs
14927  a RETN instruction instead, add the 
14928 \emph on
14929 critical
14930 \emph default
14931  keyword:
14932 \end_layout
14933
14934 \begin_layout Verse
14935
14936 \family typewriter
14937 void nmi_isr (void) critical interrupt
14938 \newline
14939
14940 \newline
14941 \InsetSpace ~
14942 \InsetSpace ~
14943 \InsetSpace ~
14944 \InsetSpace ~
14945 ...
14946  
14947 \newline
14948 }
14949 \end_layout
14950
14951 \begin_layout Standard
14952 However if you need to create a non-interruptable interrupt service routine
14953  you would also require the 
14954 \emph on
14955 critical
14956 \emph default
14957  keyword.
14958  To distinguish between this and an nmi_isr you must provide an interrupt
14959  number.
14960 \begin_inset VSpace bigskip
14961 \end_inset
14962
14963
14964 \end_layout
14965
14966 \begin_layout Section
14967 Enabling and Disabling Interrupts
14968 \end_layout
14969
14970 \begin_layout Subsection
14971 Critical Functions and Critical Statements
14972 \end_layout
14973
14974 \begin_layout Standard
14975 A special keyword may be associated with a block or a function declaring
14976  it as 
14977 \emph on
14978 critical
14979 \emph default
14980 .
14981  SDCC will generate code to disable all interrupts
14982 \begin_inset LatexCommand \index{interrupt}
14983
14984 \end_inset
14985
14986  upon entry to a critical function and restore the interrupt enable to the
14987  previous state before returning.
14988  Nesting critical functions will need one additional byte on the stack
14989 \begin_inset LatexCommand \index{stack}
14990
14991 \end_inset
14992
14993  for each call.
14994 \end_layout
14995
14996 \begin_layout Verse
14997
14998 \family typewriter
14999 int foo () __critical
15000 \begin_inset LatexCommand \index{critical}
15001
15002 \end_inset
15003
15004
15005 \begin_inset LatexCommand \index{\_\_critical}
15006
15007 \end_inset
15008
15009  
15010 \newline
15011
15012 \newline
15013 \InsetSpace ~
15014 \InsetSpace ~
15015 \InsetSpace ~
15016 \InsetSpace ~
15017 ...
15018  
15019 \newline
15020 \InsetSpace ~
15021 \InsetSpace ~
15022 \InsetSpace ~
15023 \InsetSpace ~
15024 ...
15025  
15026 \newline
15027 }
15028 \end_layout
15029
15030 \begin_layout Standard
15031 The critical attribute maybe used with other attributes like 
15032 \emph on
15033 reentrant.
15034 \emph default
15035
15036 \newline
15037 The keyword 
15038 \emph on
15039 critical
15040 \emph default
15041  may also be used to disable interrupts more locally:
15042 \end_layout
15043
15044 \begin_layout Verse
15045
15046 \family typewriter
15047 __critical{ i++; }
15048 \end_layout
15049
15050 \begin_layout Standard
15051 More than one statement could have been included in the block.
15052 \end_layout
15053
15054 \begin_layout Subsection
15055 Enabling and Disabling Interrupts directly
15056 \end_layout
15057
15058 \begin_layout Standard
15059 Interrupts
15060 \begin_inset LatexCommand \index{interrupt}
15061
15062 \end_inset
15063
15064  can also be disabled and enabled directly (8051):
15065 \end_layout
15066
15067 \begin_layout Verse
15068
15069 \family typewriter
15070 EA = 0;\InsetSpace ~
15071 \InsetSpace ~
15072 \InsetSpace ~
15073 \InsetSpace ~
15074 \InsetSpace ~
15075 \InsetSpace ~
15076 \InsetSpace ~
15077 \InsetSpace ~
15078 \InsetSpace ~
15079 \InsetSpace ~
15080 \InsetSpace ~
15081 \InsetSpace ~
15082 or:\InsetSpace ~
15083 \InsetSpace ~
15084 \InsetSpace ~
15085 \InsetSpace ~
15086 \InsetSpace ~
15087 \InsetSpace ~
15088 \InsetSpace ~
15089 \InsetSpace ~
15090 \InsetSpace ~
15091 \InsetSpace ~
15092 \InsetSpace ~
15093 EA_SAVE = EA;
15094 \end_layout
15095
15096 \begin_layout Verse
15097
15098 \family typewriter
15099 ...\InsetSpace ~
15100 \InsetSpace ~
15101 \InsetSpace ~
15102 \InsetSpace ~
15103 \InsetSpace ~
15104 \InsetSpace ~
15105 \InsetSpace ~
15106 \InsetSpace ~
15107 \InsetSpace ~
15108 \InsetSpace ~
15109 \InsetSpace ~
15110 \InsetSpace ~
15111 \InsetSpace ~
15112 \InsetSpace ~
15113 \InsetSpace ~
15114 \InsetSpace ~
15115 \InsetSpace ~
15116 \InsetSpace ~
15117 \InsetSpace ~
15118 \InsetSpace ~
15119 \InsetSpace ~
15120 \InsetSpace ~
15121 \InsetSpace ~
15122 \InsetSpace ~
15123 \InsetSpace ~
15124 \InsetSpace ~
15125 \InsetSpace ~
15126 \InsetSpace ~
15127 \InsetSpace ~
15128 \InsetSpace ~
15129 EA = 0;
15130 \end_layout
15131
15132 \begin_layout Verse
15133
15134 \family typewriter
15135 EA = 1;\InsetSpace ~
15136 \InsetSpace ~
15137 \InsetSpace ~
15138 \InsetSpace ~
15139 \InsetSpace ~
15140 \InsetSpace ~
15141 \InsetSpace ~
15142 \InsetSpace ~
15143 \InsetSpace ~
15144 \InsetSpace ~
15145 \InsetSpace ~
15146 \InsetSpace ~
15147 \InsetSpace ~
15148 \InsetSpace ~
15149 \InsetSpace ~
15150 \InsetSpace ~
15151 \InsetSpace ~
15152 \InsetSpace ~
15153 \InsetSpace ~
15154 \InsetSpace ~
15155 \InsetSpace ~
15156 \InsetSpace ~
15157 \InsetSpace ~
15158 \InsetSpace ~
15159 \InsetSpace ~
15160 \InsetSpace ~
15161 ...
15162 \end_layout
15163
15164 \begin_layout Verse
15165
15166 \family typewriter
15167 \InsetSpace ~
15168 \InsetSpace ~
15169 \InsetSpace ~
15170 \InsetSpace ~
15171 \InsetSpace ~
15172 \InsetSpace ~
15173 \InsetSpace ~
15174 \InsetSpace ~
15175 \InsetSpace ~
15176 \InsetSpace ~
15177 \InsetSpace ~
15178 \InsetSpace ~
15179 \InsetSpace ~
15180 \InsetSpace ~
15181 \InsetSpace ~
15182 \InsetSpace ~
15183 \InsetSpace ~
15184 \InsetSpace ~
15185 \InsetSpace ~
15186 \InsetSpace ~
15187 \InsetSpace ~
15188 \InsetSpace ~
15189 \InsetSpace ~
15190 \InsetSpace ~
15191 \InsetSpace ~
15192 \InsetSpace ~
15193 \InsetSpace ~
15194 \InsetSpace ~
15195 \InsetSpace ~
15196 \InsetSpace ~
15197 \InsetSpace ~
15198 \InsetSpace ~
15199 \InsetSpace ~
15200 EA = EA_SAVE;
15201 \end_layout
15202
15203 \begin_layout Standard
15204 On other architectures which have seperate opcodes for enabling and disabling
15205  interrupts you might want to make use of defines with inline assembly
15206 \begin_inset LatexCommand \index{Assembler routines}
15207
15208 \end_inset
15209
15210  (HC08
15211 \begin_inset LatexCommand \index{HC08!interrupt}
15212
15213 \end_inset
15214
15215 ):
15216 \end_layout
15217
15218 \begin_layout Verse
15219
15220 \family typewriter
15221 #define CLI _asm
15222 \begin_inset LatexCommand \index{\_asm}
15223
15224 \end_inset
15225
15226 \InsetSpace ~
15227 \InsetSpace ~
15228 cli\InsetSpace ~
15229 \InsetSpace ~
15230 _endasm
15231 \begin_inset LatexCommand \index{\_endasm}
15232
15233 \end_inset
15234
15235
15236 \end_layout
15237
15238 \begin_layout Verse
15239
15240 \family typewriter
15241 #define SEI _asm\InsetSpace ~
15242 \InsetSpace ~
15243 sei\InsetSpace ~
15244 \InsetSpace ~
15245 _endasm; 
15246 \end_layout
15247
15248 \begin_layout Verse
15249
15250 \family typewriter
15251 ...
15252 \end_layout
15253
15254 \begin_layout Standard
15255 Note: it is sometimes sufficient to disable only a specific interrupt source
15256  like f.e.
15257  a timer or serial interrupt by manipulating an 
15258 \emph on
15259 interrupt mask
15260 \begin_inset LatexCommand \index{interrupt mask}
15261
15262 \end_inset
15263
15264
15265 \emph default
15266  register.
15267  
15268 \end_layout
15269
15270 \begin_layout Standard
15271 Usually the time during which interrupts are disabled should be kept as
15272  short as possible.
15273  This minimizes both 
15274 \emph on
15275 interrupt latency
15276 \emph default
15277
15278 \begin_inset LatexCommand \index{interrupt latency}
15279
15280 \end_inset
15281
15282  (the time between the occurrence of the interrupt and the execution of
15283  the first code in the interrupt routine) and 
15284 \emph on
15285 interrupt jitter
15286 \emph default
15287
15288 \begin_inset LatexCommand \index{interrupt jitter}
15289
15290 \end_inset
15291
15292  (the difference between the shortest and the longest interrupt latency).
15293  These really are something different, f.e.
15294  a serial interrupt has to be served before its buffer overruns so it cares
15295  for the maximum interrupt latency, whereas it does not care about jitter.
15296  On a loudspeaker driven via a digital to analog converter which is fed
15297  by an interrupt a latency of a few milliseconds might be tolerable, whereas
15298  a much smaller jitter will be very audible.
15299 \end_layout
15300
15301 \begin_layout Standard
15302 You can reenable interrupts within an interrupt routine and on some architecture
15303 s you can make use of two (or more) levels of 
15304 \emph on
15305 interrupt priorities
15306 \emph default
15307
15308 \begin_inset LatexCommand \index{interrupt priority}
15309
15310 \end_inset
15311
15312 .
15313  On some architectures which don't support interrupt priorities these can
15314  be implemented by manipulating the interrupt mask and reenabling interrupts
15315  within the interrupt routine.
15316  Check there is sufficient space on the stack
15317 \begin_inset LatexCommand \index{stack}
15318
15319 \end_inset
15320
15321  and don't add complexity unless you have to.
15322  
15323 \end_layout
15324
15325 \begin_layout Subsection
15326 Semaphore
15327 \begin_inset LatexCommand \index{semaphore}
15328
15329 \end_inset
15330
15331  locking (mcs51/ds390)
15332 \end_layout
15333
15334 \begin_layout Standard
15335 Some architectures (mcs51/ds390) have an atomic
15336 \begin_inset LatexCommand \index{atomic}
15337
15338 \end_inset
15339
15340  bit test and
15341 \emph on
15342  
15343 \emph default
15344 clear
15345 \emph on
15346  
15347 \emph default
15348 instruction.
15349  These type of instructions are typically used in preemptive multitasking
15350  systems, where a routine f.e.
15351  claims the use of a data structure ('acquires a lock
15352 \begin_inset LatexCommand \index{lock}
15353
15354 \end_inset
15355
15356  on it'), makes some modifications and then releases the lock when the data
15357  structure is consistent again.
15358  The instruction may also be used if interrupt and non-interrupt code have
15359  to compete for a resource.
15360  With the atomic bit test and clear instruction interrupts
15361 \begin_inset LatexCommand \index{interrupt}
15362
15363 \end_inset
15364
15365  don't have to be disabled for the locking operation.
15366  
15367 \end_layout
15368
15369 \begin_layout Standard
15370 SDCC generates this instruction if the source follows this pattern:
15371 \end_layout
15372
15373 \begin_layout Verse
15374
15375 \family typewriter
15376 volatile
15377 \begin_inset LatexCommand \index{volatile}
15378
15379 \end_inset
15380
15381  bit resource_is_free; 
15382 \newline
15383
15384 \newline
15385 if (resource_is_free) 
15386 \newline
15387 \InsetSpace ~
15388 \InsetSpace ~
15389
15390 \newline
15391 \InsetSpace ~
15392 \InsetSpace ~
15393 \InsetSpace ~
15394 \InsetSpace ~
15395 resource_is_free=0; 
15396 \newline
15397 \InsetSpace ~
15398 \InsetSpace ~
15399 \InsetSpace ~
15400 \InsetSpace ~
15401 ...
15402  
15403 \newline
15404 \InsetSpace ~
15405 \InsetSpace ~
15406 \InsetSpace ~
15407 \InsetSpace ~
15408 resource_is_free=1;
15409 \newline
15410 \InsetSpace ~
15411 \InsetSpace ~
15412
15413 \end_layout
15414
15415 \begin_layout Standard
15416 Note, mcs51 and ds390 support only an atomic
15417 \begin_inset LatexCommand \index{atomic}
15418
15419 \end_inset
15420
15421  bit test and 
15422 \emph on
15423 clear
15424 \emph default
15425  instruction (as opposed to atomic bit test and 
15426 \emph on
15427 set).
15428 \end_layout
15429
15430 \begin_layout Section
15431 Functions using private register banks
15432 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
15433
15434 \end_inset
15435
15436  (mcs51/ds390)
15437 \end_layout
15438
15439 \begin_layout Standard
15440 Some architectures have support for quickly changing register sets.
15441  SDCC supports this feature with the 
15442 \emph on
15443 using
15444 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
15445
15446 \end_inset
15447
15448
15449 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
15450
15451 \end_inset
15452
15453
15454 \emph default
15455  attribute (which tells the compiler to use a register bank
15456 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
15457
15458 \end_inset
15459
15460  other than the default bank zero).
15461  It should only be applied to 
15462 \emph on
15463 interrupt
15464 \begin_inset LatexCommand \index{interrupt}
15465
15466 \end_inset
15467
15468
15469 \emph default
15470  functions (see footnote below).
15471  This will in most circumstances make the generated ISR code more efficient
15472  since it will not have to save registers on the stack.
15473 \end_layout
15474
15475 \begin_layout Standard
15476 The 
15477 \emph on
15478 using
15479 \emph default
15480  attribute will have no effect on the generated code for a 
15481 \emph on
15482 non-interrupt
15483 \emph default
15484  function (but may occasionally be useful anyway
15485 \begin_inset Foot
15486 status open
15487
15488 \begin_layout Standard
15489 possible exception: if a function is called ONLY from 'interrupt' functions
15490  using a particular bank, it can be declared with the same 'using' attribute
15491  as the calling 'interrupt' functions.
15492  For instance, if you have several ISRs using bank one, and all of them
15493  call memcpy(), it might make sense to create a specialized version of memcpy()
15494  'using 1', since this would prevent the ISR from having to save bank zero
15495  to the stack on entry and switch to bank zero before calling the function
15496 \end_layout
15497
15498 \end_inset
15499
15500 ).
15501 \newline
15502
15503 \emph on
15504 (pending: Note, nowadays the 
15505 \emph default
15506 using
15507 \emph on
15508  attribute has an effect on
15509 \emph default
15510  
15511 \emph on
15512 the generated code for a 
15513 \emph default
15514 non-interrupt
15515 \emph on
15516  function
15517 \emph default
15518 .
15519 \emph on
15520 )
15521 \end_layout
15522
15523 \begin_layout Standard
15524 An 
15525 \emph on
15526 interrupt
15527 \emph default
15528  function using a non-zero bank will assume that it can trash that register
15529  bank, and will not save it.
15530  Since high-priority interrupts
15531 \begin_inset LatexCommand \index{interrupts}
15532
15533 \end_inset
15534
15535
15536 \begin_inset LatexCommand \index{interrupt priority}
15537
15538 \end_inset
15539
15540  can interrupt low-priority ones on the 8051 and friends, this means that
15541  if a high-priority ISR 
15542 \emph on
15543 using
15544 \emph default
15545  a particular bank occurs while processing a low-priority ISR 
15546 \emph on
15547 using
15548 \emph default
15549  the same bank, terrible and bad things can happen.
15550  To prevent this, no single register bank should be 
15551 \emph on
15552 used
15553 \emph default
15554  by both a high priority and a low priority ISR.
15555  This is probably most easily done by having all high priority ISRs use
15556  one bank and all low priority ISRs use another.
15557  If you have an ISR which can change priority at runtime, you're on your
15558  own: I suggest using the default bank zero and taking the small performance
15559  hit.
15560 \end_layout
15561
15562 \begin_layout Standard
15563 It is most efficient if your ISR calls no other functions.
15564  If your ISR must call other functions, it is most efficient if those functions
15565  use the same bank as the ISR (see note 1 below); the next best is if the
15566  called functions use bank zero.
15567  It is very inefficient to call a function using a different, non-zero bank
15568  from an ISR.
15569  
15570 \begin_inset VSpace bigskip
15571 \end_inset
15572
15573
15574 \end_layout
15575
15576 \begin_layout Section
15577 Startup Code
15578 \begin_inset LatexCommand \label{sub:Startup-Code}
15579
15580 \end_inset
15581
15582
15583 \begin_inset LatexCommand \index{Startup code}
15584
15585 \end_inset
15586
15587
15588 \end_layout
15589
15590 \begin_layout Subsection
15591 MCS51/DS390 Startup Code
15592 \end_layout
15593
15594 \begin_layout Standard
15595 The compiler triggers the linker to link certain initialization modules
15596  from the runtime library
15597 \begin_inset LatexCommand \index{Runtime library}
15598
15599 \end_inset
15600
15601  called crt<something>.
15602  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15603  GSINIT5) is not linked unless the -
15604 \series bold
15605
15606 \begin_inset ERT
15607 status open
15608
15609 \begin_layout Standard
15610
15611
15612 \backslash
15613 /
15614 \end_layout
15615
15616 \end_inset
15617
15618
15619 \series default
15620 -xstack option is used.
15621  These modules are highly entangled by the use of special segments/areas,
15622  but a common layout is shown below:
15623 \end_layout
15624
15625 \begin_layout Verse
15626
15627 \family typewriter
15628 \series bold
15629 \size footnotesize
15630 (main.asm)
15631 \end_layout
15632
15633 \begin_layout Verse
15634
15635 \family typewriter
15636 \size footnotesize
15637 \InsetSpace ~
15638 \InsetSpace ~
15639 \InsetSpace ~
15640 \InsetSpace ~
15641 \InsetSpace ~
15642 \InsetSpace ~
15643 \InsetSpace ~
15644 \InsetSpace ~
15645 .area HOME (CODE)
15646 \newline
15647 __interrupt_vect:
15648 \newline
15649 \InsetSpace ~
15650 \InsetSpace ~
15651 \InsetSpace ~
15652 \InsetSpace ~
15653 \InsetSpace ~
15654 \InsetSpace ~
15655 \InsetSpace ~
15656 \InsetSpace ~
15657 ljmp __sdcc_gsinit_startup
15658 \end_layout
15659
15660 \begin_layout Verse
15661
15662 \family typewriter
15663 \series bold
15664 \size footnotesize
15665 (crtstart.asm)
15666 \end_layout
15667
15668 \begin_layout Verse
15669
15670 \family typewriter
15671 \size footnotesize
15672 \InsetSpace ~
15673 \InsetSpace ~
15674 \InsetSpace ~
15675 \InsetSpace ~
15676 \InsetSpace ~
15677 \InsetSpace ~
15678 \InsetSpace ~
15679 \InsetSpace ~
15680 .area GSINIT0 (CODE)
15681 \newline
15682 __sdcc_gsinit_startup::
15683 \newline
15684 \InsetSpace ~
15685 \InsetSpace ~
15686 \InsetSpace ~
15687 \InsetSpace ~
15688 \InsetSpace ~
15689 \InsetSpace ~
15690 \InsetSpace ~
15691 \InsetSpace ~
15692 mov sp,#__start__stack - 1
15693 \end_layout
15694
15695 \begin_layout Verse
15696
15697 \family typewriter
15698 \series bold
15699 \size footnotesize
15700 (crtxstack.asm)
15701 \end_layout
15702
15703 \begin_layout Verse
15704
15705 \family typewriter
15706 \size footnotesize
15707 \InsetSpace ~
15708 \InsetSpace ~
15709 \InsetSpace ~
15710 \InsetSpace ~
15711 \InsetSpace ~
15712 \InsetSpace ~
15713 \InsetSpace ~
15714 \InsetSpace ~
15715 .area GSINIT1 (CODE)
15716 \newline
15717 __sdcc_init_xstack::
15718 \newline
15719 ; Need to initialize in GSINIT1 in
15720  case the user's __sdcc_external_startup uses the xstack.
15721 \newline
15722 \InsetSpace ~
15723 \InsetSpace ~
15724 \InsetSpace ~
15725 \InsetSpace ~
15726 \InsetSpace ~
15727 \InsetSpace ~
15728 \InsetSpace ~
15729 \InsetSpace ~
15730 mov __XPAGE,#(__start__x
15731 stack >> 8)
15732 \newline
15733 \InsetSpace ~
15734 \InsetSpace ~
15735 \InsetSpace ~
15736 \InsetSpace ~
15737 \InsetSpace ~
15738 \InsetSpace ~
15739 \InsetSpace ~
15740 \InsetSpace ~
15741 mov _spx,#__start__xstack
15742 \end_layout
15743
15744 \begin_layout Verse
15745
15746 \family typewriter
15747 \series bold
15748 \size footnotesize
15749 (crtstart.asm)
15750 \end_layout
15751
15752 \begin_layout Verse
15753
15754 \family typewriter
15755 \size footnotesize
15756 \InsetSpace ~
15757 \InsetSpace ~
15758 \InsetSpace ~
15759 \InsetSpace ~
15760 \InsetSpace ~
15761 \InsetSpace ~
15762 \InsetSpace ~
15763 \InsetSpace ~
15764 .area GSINIT2 (CODE)
15765 \newline
15766 \InsetSpace ~
15767 \InsetSpace ~
15768 \InsetSpace ~
15769 \InsetSpace ~
15770 \InsetSpace ~
15771 \InsetSpace ~
15772 \InsetSpace ~
15773 \InsetSpace ~
15774 lcall __sdcc_external_startup
15775 \newline
15776 \InsetSpace ~
15777 \InsetSpace ~
15778 \InsetSpace ~
15779 \InsetSpace ~
15780 \InsetSpace ~
15781 \InsetSpace ~
15782 \InsetSpace ~
15783 \InsetSpace ~
15784 mov a,dpl
15785 \newline
15786 \InsetSpace ~
15787 \InsetSpace ~
15788 \InsetSpace ~
15789 \InsetSpace ~
15790 \InsetSpace ~
15791 \InsetSpace ~
15792 \InsetSpace ~
15793 \InsetSpace ~
15794 jz __sdcc_init_data
15795 \newline
15796 \InsetSpace ~
15797 \InsetSpace ~
15798 \InsetSpace ~
15799 \InsetSpace ~
15800 \InsetSpace ~
15801 \InsetSpace ~
15802 \InsetSpace ~
15803 \InsetSpace ~
15804 ljmp
15805  __sdcc_program_startup
15806 \newline
15807 __sdcc_init_data:
15808 \end_layout
15809
15810 \begin_layout Verse
15811
15812 \family typewriter
15813 \series bold
15814 \size footnotesize
15815 (crtxinit.asm)
15816 \end_layout
15817
15818 \begin_layout Verse
15819
15820 \family typewriter
15821 \size footnotesize
15822 \InsetSpace ~
15823 \InsetSpace ~
15824 \InsetSpace ~
15825 \InsetSpace ~
15826 \InsetSpace ~
15827 \InsetSpace ~
15828 \InsetSpace ~
15829 \InsetSpace ~
15830 .area GSINIT3 (CODE)
15831 \newline
15832 __mcs51_genXINIT::
15833 \newline
15834 \InsetSpace ~
15835 \InsetSpace ~
15836 \InsetSpace ~
15837 \InsetSpace ~
15838 \InsetSpace ~
15839 \InsetSpace ~
15840 \InsetSpace ~
15841 \InsetSpace ~
15842 mov r1,#l_XINIT
15843 \newline
15844 \InsetSpace ~
15845 \InsetSpace ~
15846 \InsetSpace ~
15847 \InsetSpace ~
15848 \InsetSpace ~
15849 \InsetSpace ~
15850 \InsetSpace ~
15851 \InsetSpace ~
15852 mov a,r1
15853 \newline
15854 \InsetSpace ~
15855 \InsetSpace ~
15856 \InsetSpace ~
15857 \InsetSpace ~
15858 \InsetSpace ~
15859 \InsetSpace ~
15860 \InsetSpace ~
15861 \InsetSpace ~
15862 orl a,#(l_XINIT
15863  >> 8)
15864 \newline
15865 \InsetSpace ~
15866 \InsetSpace ~
15867 \InsetSpace ~
15868 \InsetSpace ~
15869 \InsetSpace ~
15870 \InsetSpace ~
15871 \InsetSpace ~
15872 \InsetSpace ~
15873 jz 00003$
15874 \newline
15875 \InsetSpace ~
15876 \InsetSpace ~
15877 \InsetSpace ~
15878 \InsetSpace ~
15879 \InsetSpace ~
15880 \InsetSpace ~
15881 \InsetSpace ~
15882 \InsetSpace ~
15883 mov r2,#((l_XINIT+255) >> 8)
15884 \newline
15885 \InsetSpace ~
15886 \InsetSpace ~
15887 \InsetSpace ~
15888 \InsetSpace ~
15889 \InsetSpace ~
15890 \InsetSpace ~
15891 \InsetSpace ~
15892 \InsetSpace ~
15893 mov dptr,#s_XINIT
15894 \newline
15895 \InsetSpace ~
15896 \InsetSpace ~
15897 \InsetSpace ~
15898 \InsetSpace ~
15899 \InsetSpace ~
15900 \InsetSpace ~
15901 \InsetSpace ~
15902 \InsetSpace ~
15903 mov r0,#s_XISEG
15904 \newline
15905 \InsetSpace ~
15906 \InsetSpace ~
15907 \InsetSpace ~
15908 \InsetSpace ~
15909 \InsetSpace ~
15910 \InsetSpace ~
15911 \InsetSpace ~
15912 \InsetSpace ~
15913 mov
15914  __XPAGE,#(s_XISEG >> 8)
15915 \newline
15916 00001$:\InsetSpace ~
15917 clr a
15918 \newline
15919 \InsetSpace ~
15920 \InsetSpace ~
15921 \InsetSpace ~
15922 \InsetSpace ~
15923 \InsetSpace ~
15924 \InsetSpace ~
15925 \InsetSpace ~
15926 \InsetSpace ~
15927 movc a,@a+dptr
15928 \newline
15929 \InsetSpace ~
15930 \InsetSpace ~
15931 \InsetSpace ~
15932 \InsetSpace ~
15933 \InsetSpace ~
15934 \InsetSpace ~
15935 \InsetSpace ~
15936 \InsetSpace ~
15937 movx @r0,a
15938 \newline
15939 \InsetSpace ~
15940 \InsetSpace ~
15941 \InsetSpace ~
15942 \InsetSpace ~
15943 \InsetSpace ~
15944 \InsetSpace ~
15945 \InsetSpace ~
15946 \InsetSpace ~
15947 inc dptr
15948 \newline
15949 \InsetSpace ~
15950 \InsetSpace ~
15951 \InsetSpace ~
15952 \InsetSpace ~
15953 \InsetSpace ~
15954 \InsetSpace ~
15955 \InsetSpace ~
15956 \InsetSpace ~
15957 inc
15958  r0
15959 \newline
15960 \InsetSpace ~
15961 \InsetSpace ~
15962 \InsetSpace ~
15963 \InsetSpace ~
15964 \InsetSpace ~
15965 \InsetSpace ~
15966 \InsetSpace ~
15967 \InsetSpace ~
15968 cjne r0,#0,00002$
15969 \newline
15970 \InsetSpace ~
15971 \InsetSpace ~
15972 \InsetSpace ~
15973 \InsetSpace ~
15974 \InsetSpace ~
15975 \InsetSpace ~
15976 \InsetSpace ~
15977 \InsetSpace ~
15978 inc __XPAGE
15979 \newline
15980 00002$:\InsetSpace ~
15981 djnz r1,00001$
15982 \newline
15983 \InsetSpace ~
15984 \InsetSpace ~
15985 \InsetSpace ~
15986 \InsetSpace ~
15987 \InsetSpace ~
15988 \InsetSpace ~
15989 \InsetSpace ~
15990 \InsetSpace ~
15991 djnz r2,00001$
15992 \newline
15993 \InsetSpace ~
15994 \InsetSpace ~
15995 \InsetSpace ~
15996 \InsetSpace ~
15997 \InsetSpace ~
15998 \InsetSpace ~
15999 \InsetSpace ~
16000 \InsetSpace ~
16001 mov __XPAGE,#0
16002 xFF
16003 \newline
16004 00003$:
16005 \end_layout
16006
16007 \begin_layout Verse
16008
16009 \family typewriter
16010 \series bold
16011 \size footnotesize
16012 (crtclear.asm)
16013 \end_layout
16014
16015 \begin_layout Verse
16016
16017 \family typewriter
16018 \size footnotesize
16019 \InsetSpace ~
16020 \InsetSpace ~
16021 \InsetSpace ~
16022 \InsetSpace ~
16023 \InsetSpace ~
16024 \InsetSpace ~
16025 \InsetSpace ~
16026 \InsetSpace ~
16027 .area GSINIT4 (CODE)
16028 \newline
16029 __mcs51_genRAMCLEAR::
16030 \newline
16031 \InsetSpace ~
16032 \InsetSpace ~
16033 \InsetSpace ~
16034 \InsetSpace ~
16035 \InsetSpace ~
16036 \InsetSpace ~
16037 \InsetSpace ~
16038 \InsetSpace ~
16039 clr a
16040 \newline
16041 \InsetSpace ~
16042 \InsetSpace ~
16043 \InsetSpace ~
16044 \InsetSpace ~
16045 \InsetSpace ~
16046 \InsetSpace ~
16047 \InsetSpace ~
16048 \InsetSpace ~
16049 mov r0,#(l_IRAM-1)
16050 \newline
16051 00004$:\InsetSpace ~
16052 mov
16053  @r0,a
16054 \newline
16055 \InsetSpace ~
16056 \InsetSpace ~
16057 \InsetSpace ~
16058 \InsetSpace ~
16059 \InsetSpace ~
16060 \InsetSpace ~
16061 \InsetSpace ~
16062 \InsetSpace ~
16063 djnz r0,00004$
16064 \newline
16065 ; _mcs51_genRAMCLEAR() end
16066 \end_layout
16067
16068 \begin_layout Verse
16069
16070 \family typewriter
16071 \series bold
16072 \size footnotesize
16073 (crtxclear.asm)
16074 \end_layout
16075
16076 \begin_layout Verse
16077
16078 \family typewriter
16079 \size footnotesize
16080 \InsetSpace ~
16081 \InsetSpace ~
16082 \InsetSpace ~
16083 \InsetSpace ~
16084 \InsetSpace ~
16085 \InsetSpace ~
16086 \InsetSpace ~
16087 \InsetSpace ~
16088 .area GSINIT4 (CODE)
16089 \newline
16090 __mcs51_genXRAMCLEAR::
16091 \newline
16092 \InsetSpace ~
16093 \InsetSpace ~
16094 \InsetSpace ~
16095 \InsetSpace ~
16096 \InsetSpace ~
16097 \InsetSpace ~
16098 \InsetSpace ~
16099 \InsetSpace ~
16100 mov r0,#l_PSEG
16101 \newline
16102 \InsetSpace ~
16103 \InsetSpace ~
16104 \InsetSpace ~
16105 \InsetSpace ~
16106 \InsetSpace ~
16107 \InsetSpace ~
16108 \InsetSpace ~
16109 \InsetSpace ~
16110 mov a,r0
16111 \newline
16112 \InsetSpace ~
16113 \InsetSpace ~
16114 \InsetSpace ~
16115 \InsetSpace ~
16116 \InsetSpace ~
16117 \InsetSpace ~
16118 \InsetSpace ~
16119 \InsetSpace ~
16120 orl a,#(l_PSEG
16121  >> 8)
16122 \newline
16123 \InsetSpace ~
16124 \InsetSpace ~
16125 \InsetSpace ~
16126 \InsetSpace ~
16127 \InsetSpace ~
16128 \InsetSpace ~
16129 \InsetSpace ~
16130 \InsetSpace ~
16131 jz 00006$
16132 \newline
16133 \InsetSpace ~
16134 \InsetSpace ~
16135 \InsetSpace ~
16136 \InsetSpace ~
16137 \InsetSpace ~
16138 \InsetSpace ~
16139 \InsetSpace ~
16140 \InsetSpace ~
16141 mov r1,#s_PSEG
16142 \newline
16143 \InsetSpace ~
16144 \InsetSpace ~
16145 \InsetSpace ~
16146 \InsetSpace ~
16147 \InsetSpace ~
16148 \InsetSpace ~
16149 \InsetSpace ~
16150 \InsetSpace ~
16151 mov __XPAGE,#(s_PSEG >> 8)
16152 \newline
16153 \InsetSpace ~
16154 \InsetSpace ~
16155 \InsetSpace ~
16156 \InsetSpace ~
16157 \InsetSpace ~
16158 \InsetSpace ~
16159 \InsetSpace ~
16160 \InsetSpace ~
16161 clr a
16162 \newline
16163 00005$:\InsetSpace ~
16164 movx
16165  @r1,a
16166 \newline
16167 \InsetSpace ~
16168 \InsetSpace ~
16169 \InsetSpace ~
16170 \InsetSpace ~
16171 \InsetSpace ~
16172 \InsetSpace ~
16173 \InsetSpace ~
16174 \InsetSpace ~
16175 inc r1
16176 \newline
16177 \InsetSpace ~
16178 \InsetSpace ~
16179 \InsetSpace ~
16180 \InsetSpace ~
16181 \InsetSpace ~
16182 \InsetSpace ~
16183 \InsetSpace ~
16184 \InsetSpace ~
16185 djnz r0,00005$
16186 \newline
16187 00006$:
16188 \newline
16189 \InsetSpace ~
16190 \InsetSpace ~
16191 \InsetSpace ~
16192 \InsetSpace ~
16193 \InsetSpace ~
16194 \InsetSpace ~
16195 \InsetSpace ~
16196 \InsetSpace ~
16197 mov r0,#l_XSEG
16198 \newline
16199 \InsetSpace ~
16200 \InsetSpace ~
16201 \InsetSpace ~
16202 \InsetSpace ~
16203 \InsetSpace ~
16204 \InsetSpace ~
16205 \InsetSpace ~
16206 \InsetSpace ~
16207 mov a,r0
16208 \newline
16209 \InsetSpace ~
16210 \InsetSpace ~
16211 \InsetSpace ~
16212 \InsetSpace ~
16213 \InsetSpace ~
16214 \InsetSpace ~
16215 \InsetSpace ~
16216 \InsetSpace ~
16217 orl a,#(l_XSEG >>
16218  8)
16219 \newline
16220 \InsetSpace ~
16221 \InsetSpace ~
16222 \InsetSpace ~
16223 \InsetSpace ~
16224 \InsetSpace ~
16225 \InsetSpace ~
16226 \InsetSpace ~
16227 \InsetSpace ~
16228 jz 00008$
16229 \newline
16230 \InsetSpace ~
16231 \InsetSpace ~
16232 \InsetSpace ~
16233 \InsetSpace ~
16234 \InsetSpace ~
16235 \InsetSpace ~
16236 \InsetSpace ~
16237 \InsetSpace ~
16238 mov r1,#((l_XSEG + 255) >> 8)
16239 \newline
16240 \InsetSpace ~
16241 \InsetSpace ~
16242 \InsetSpace ~
16243 \InsetSpace ~
16244 \InsetSpace ~
16245 \InsetSpace ~
16246 \InsetSpace ~
16247 \InsetSpace ~
16248 mov dptr,#s_XSEG
16249 \newline
16250 \InsetSpace ~
16251 \InsetSpace ~
16252 \InsetSpace ~
16253 \InsetSpace ~
16254 \InsetSpace ~
16255 \InsetSpace ~
16256 \InsetSpace ~
16257 \InsetSpace ~
16258 clr a
16259 \newline
16260 00007$:\InsetSpace ~
16261 movx
16262  @dptr,a
16263 \newline
16264 \InsetSpace ~
16265 \InsetSpace ~
16266 \InsetSpace ~
16267 \InsetSpace ~
16268 \InsetSpace ~
16269 \InsetSpace ~
16270 \InsetSpace ~
16271 \InsetSpace ~
16272 inc dptr
16273 \newline
16274 \InsetSpace ~
16275 \InsetSpace ~
16276 \InsetSpace ~
16277 \InsetSpace ~
16278 \InsetSpace ~
16279 \InsetSpace ~
16280 \InsetSpace ~
16281 \InsetSpace ~
16282 djnz r0,00007$
16283 \newline
16284 \InsetSpace ~
16285 \InsetSpace ~
16286 \InsetSpace ~
16287 \InsetSpace ~
16288 \InsetSpace ~
16289 \InsetSpace ~
16290 \InsetSpace ~
16291 \InsetSpace ~
16292 djnz r1,00007$
16293 \newline
16294 00008$:
16295 \end_layout
16296
16297 \begin_layout Verse
16298
16299 \family typewriter
16300 \series bold
16301 \size footnotesize
16302 (crtxstack.asm)
16303 \end_layout
16304
16305 \begin_layout Verse
16306
16307 \family typewriter
16308 \size footnotesize
16309 \InsetSpace ~
16310 \InsetSpace ~
16311 \InsetSpace ~
16312 \InsetSpace ~
16313 \InsetSpace ~
16314 \InsetSpace ~
16315 \InsetSpace ~
16316 \InsetSpace ~
16317 .area GSINIT5 (CODE)
16318 \newline
16319 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
16320  modifies __XPAGE
16321 \newline
16322 ; and __mcs51_genRAMCLEAR modifies _spx.
16323 \newline
16324 \InsetSpace ~
16325 \InsetSpace ~
16326 \InsetSpace ~
16327 \InsetSpace ~
16328 \InsetSpace ~
16329 \InsetSpace ~
16330 \InsetSpace ~
16331 \InsetSpace ~
16332 mov __XPAGE,#(__start__x
16333 stack >> 8)
16334 \newline
16335 \InsetSpace ~
16336 \InsetSpace ~
16337 \InsetSpace ~
16338 \InsetSpace ~
16339 \InsetSpace ~
16340 \InsetSpace ~
16341 \InsetSpace ~
16342 \InsetSpace ~
16343 mov _spx,#__start__xstack
16344 \end_layout
16345
16346 \begin_layout Verse
16347
16348 \family typewriter
16349 \series bold
16350 \size footnotesize
16351 (application modules)
16352 \end_layout
16353
16354 \begin_layout Verse
16355
16356 \family typewriter
16357 \size footnotesize
16358 \InsetSpace ~
16359 \InsetSpace ~
16360 \InsetSpace ~
16361 \InsetSpace ~
16362 \InsetSpace ~
16363 \InsetSpace ~
16364 \InsetSpace ~
16365 \InsetSpace ~
16366 .area GSINIT (CODE)
16367 \end_layout
16368
16369 \begin_layout Verse
16370
16371 \family typewriter
16372 \series bold
16373 \size footnotesize
16374 (main.asm)
16375 \end_layout
16376
16377 \begin_layout Verse
16378
16379 \family typewriter
16380 \size footnotesize
16381 \InsetSpace ~
16382 \InsetSpace ~
16383 \InsetSpace ~
16384 \InsetSpace ~
16385 \InsetSpace ~
16386 \InsetSpace ~
16387 \InsetSpace ~
16388 \InsetSpace ~
16389 .area GSFINAL (CODE)
16390 \newline
16391 \InsetSpace ~
16392 \InsetSpace ~
16393 \InsetSpace ~
16394 \InsetSpace ~
16395 \InsetSpace ~
16396 \InsetSpace ~
16397 \InsetSpace ~
16398 \InsetSpace ~
16399 ljmp __sdcc_program_startup
16400 \newline
16401 ;---------------------------------
16402 -----------------------
16403 \newline
16404 ; Home
16405 \newline
16406 ;--------------------------------------------------
16407 ------
16408 \newline
16409 \InsetSpace ~
16410 \InsetSpace ~
16411 \InsetSpace ~
16412 \InsetSpace ~
16413 \InsetSpace ~
16414 \InsetSpace ~
16415 \InsetSpace ~
16416 \InsetSpace ~
16417 .area HOME (CODE)
16418 \newline
16419 \InsetSpace ~
16420 \InsetSpace ~
16421 \InsetSpace ~
16422 \InsetSpace ~
16423 \InsetSpace ~
16424 \InsetSpace ~
16425 \InsetSpace ~
16426 \InsetSpace ~
16427 .area CSEG (CODE)
16428 \newline
16429 __sdcc_program_startup:
16430 \newline
16431 \InsetSpace ~
16432 \InsetSpace ~
16433 \InsetSpace ~
16434 \InsetSpace ~
16435 \InsetSpace ~
16436 \InsetSpace ~
16437 \InsetSpace ~
16438 \InsetSpace ~
16439 lcall _main
16440 \newline
16441 ;
16442  return from main will lock up
16443 \newline
16444 \InsetSpace ~
16445 \InsetSpace ~
16446 \InsetSpace ~
16447 \InsetSpace ~
16448 \InsetSpace ~
16449 \InsetSpace ~
16450 \InsetSpace ~
16451 \InsetSpace ~
16452 sjmp .
16453 \end_layout
16454
16455 \begin_layout Standard
16456 One of these modules (crtstart.asm) contains a call to the C routine 
16457 \emph on
16458 _sdcc_external_startup()
16459 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
16460
16461 \end_inset
16462
16463
16464 \series bold
16465 \emph default
16466  
16467 \series default
16468 at the start of the CODE area.
16469  This routine is also in the runtime library
16470 \begin_inset LatexCommand \index{Runtime library}
16471
16472 \end_inset
16473
16474  and returns 0 by default.
16475  If this routine returns a non-zero value, the static & global variable
16476  initialization will be skipped and the function main will be invoked.
16477  Otherwise static & global variables will be initialized before the function
16478  main is invoked.
16479  You could add an 
16480 \emph on
16481 _sdcc_external_startup()
16482 \emph default
16483  routine to your program to override the default if you need to setup hardware
16484  or perform some other critical operation prior to static & global variable
16485  initialization
16486 \begin_inset LatexCommand \index{Variable initialization}
16487
16488 \end_inset
16489
16490 .
16491  On some mcs51 variants xdata
16492 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
16493
16494 \end_inset
16495
16496  memory has to be explicitly enabled before it can be accessed or if the
16497  watchdog
16498 \begin_inset LatexCommand \index{watchdog}
16499
16500 \end_inset
16501
16502  needs to be disabled, this is the place to do it.
16503  The startup code clears all internal data memory, 256 bytes by default,
16504  but from 0 to n-1 if 
16505 \emph on
16506 -
16507 \begin_inset ERT
16508 status collapsed
16509
16510 \begin_layout Standard
16511
16512
16513 \backslash
16514 /
16515 \end_layout
16516
16517 \end_inset
16518
16519 -iram-size
16520 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16521
16522 \end_inset
16523
16524 n
16525 \emph default
16526  is used.
16527  (recommended for Chipcon CC1010).
16528 \end_layout
16529
16530 \begin_layout Standard
16531 See also the compiler options 
16532 \emph on
16533 -
16534 \begin_inset ERT
16535 status collapsed
16536
16537 \begin_layout Standard
16538
16539
16540 \backslash
16541 /
16542 \end_layout
16543
16544 \end_inset
16545
16546 -no-xinit
16547 \emph default
16548 -
16549 \emph on
16550 opt
16551 \emph default
16552
16553 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16554
16555 \end_inset
16556
16557
16558 \emph on
16559 -
16560 \begin_inset ERT
16561 status collapsed
16562
16563 \begin_layout Standard
16564
16565
16566 \backslash
16567 /
16568 \end_layout
16569
16570 \end_inset
16571
16572 -main-return
16573 \emph default
16574
16575 \begin_inset LatexCommand \index{-\/-main-return}
16576
16577 \end_inset
16578
16579  and section 
16580 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16581
16582 \end_inset
16583
16584  about MCS51-variants.
16585 \newline
16586
16587 \end_layout
16588
16589 \begin_layout Standard
16590 While these initialization modules are meant as generic startup code there
16591  might be the need for customization.
16592  Let's assume the return value of 
16593 \emph on
16594 _sdcc_external_startup()
16595 \emph default
16596  in 
16597 \emph on
16598 crtstart.asm
16599 \emph default
16600  should not be checked (or 
16601 \emph on
16602 _sdcc_external_startup()
16603 \emph default
16604  should not be called at all).
16605  The recommended way would be to copy 
16606 \emph on
16607 crtstart.asm
16608 \emph default
16609  (f.e.
16610  from 
16611 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm}
16612
16613 \end_inset
16614
16615 ) into the source directory, adapt it there, then assemble it with 
16616 \emph on
16617 asx8051 -plosgff
16618 \begin_inset Foot
16619 status open
16620
16621 \begin_layout Standard
16622 \begin_inset Quotes sld
16623 \end_inset
16624
16625 -plosgff
16626 \begin_inset Quotes srd
16627 \end_inset
16628
16629  are the assembler options used in 
16630 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup }
16631
16632 \end_inset
16633
16634
16635 \end_layout
16636
16637 \end_inset
16638
16639  crtstart.asm
16640 \emph default
16641  and when linking your project explicitely specify 
16642 \emph on
16643 crtstart.rel
16644 \emph default
16645 .
16646  As a bonus a listing of the relocated object file 
16647 \emph on
16648 crtstart.rst
16649 \emph default
16650  is generated.
16651 \end_layout
16652
16653 \begin_layout Standard
16654 \begin_inset VSpace bigskip
16655 \end_inset
16656
16657
16658 \end_layout
16659
16660 \begin_layout Subsection
16661 HC08 Startup Code
16662 \end_layout
16663
16664 \begin_layout Standard
16665 The HC08
16666 \begin_inset LatexCommand \index{HC08}
16667
16668 \end_inset
16669
16670  startup code follows the same scheme as the MCS51 startup code.
16671 \begin_inset VSpace bigskip
16672 \end_inset
16673
16674
16675 \end_layout
16676
16677 \begin_layout Subsection
16678 Z80 Startup Code
16679 \end_layout
16680
16681 \begin_layout Standard
16682 On the Z80
16683 \begin_inset LatexCommand \index{Z80}
16684
16685 \end_inset
16686
16687  the startup code is inserted by linking with crt0.o which is generated from
16688  sdcc/device/lib/z80/crt0.s.
16689  If you need a different startup code you can use the compiler option 
16690 \emph on
16691 -
16692 \series bold
16693 \emph default
16694
16695 \begin_inset ERT
16696 status collapsed
16697
16698 \begin_layout Standard
16699
16700
16701 \backslash
16702 /
16703 \end_layout
16704
16705 \end_inset
16706
16707
16708 \series default
16709 \emph on
16710 -no-std-crt0
16711 \emph default
16712
16713 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16714
16715 \end_inset
16716
16717  and provide your own crt0.o.
16718  
16719 \begin_inset VSpace bigskip
16720 \end_inset
16721
16722
16723 \end_layout
16724
16725 \begin_layout Section
16726 Inline Assembler Code
16727 \begin_inset LatexCommand \index{Assembler routines}
16728
16729 \end_inset
16730
16731
16732 \end_layout
16733
16734 \begin_layout Subsection
16735 A Step by Step Introduction
16736 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16737
16738 \end_inset
16739
16740
16741 \end_layout
16742
16743 \begin_layout Standard
16744 Starting from a small snippet of c-code this example shows for the MCS51
16745  how to use inline assembly, access variables, a function parameter and
16746  an array in xdata memory.
16747  The example uses an MCS51 here but is easily adapted for other architectures.
16748  This is a buffer routine which should be optimized:
16749 \end_layout
16750
16751 \begin_layout Verse
16752
16753 \family typewriter
16754 \size footnotesize
16755 unsigned char __far
16756 \begin_inset LatexCommand \index{far (storage class)}
16757
16758 \end_inset
16759
16760
16761 \begin_inset LatexCommand \index{\_\_far (storage class)}
16762
16763 \end_inset
16764
16765  __at
16766 \begin_inset LatexCommand \index{at}
16767
16768 \end_inset
16769
16770
16771 \begin_inset LatexCommand \index{\_\_at}
16772
16773 \end_inset
16774
16775 (0x7f00) buf[0x100];
16776 \begin_inset LatexCommand \index{Aligned array}
16777
16778 \end_inset
16779
16780
16781 \newline
16782 unsigned char head, tail;\InsetSpace ~
16783 \InsetSpace ~
16784 \InsetSpace ~
16785 \InsetSpace ~
16786 \InsetSpace ~
16787 \InsetSpace ~
16788 \InsetSpace ~
16789 \InsetSpace ~
16790 \InsetSpace ~
16791 \InsetSpace ~
16792 \InsetSpace ~
16793 \InsetSpace ~
16794 \InsetSpace ~
16795 \InsetSpace ~
16796 \InsetSpace ~
16797 \InsetSpace ~
16798 \InsetSpace ~
16799 /* if interrupts
16800 \begin_inset LatexCommand \index{interrupt}
16801
16802 \end_inset
16803
16804  are involved see
16805 \newline
16806 \InsetSpace ~
16807 \InsetSpace ~
16808 \InsetSpace ~
16809 \InsetSpace ~
16810 \InsetSpace ~
16811 \InsetSpace ~
16812 \InsetSpace ~
16813 \InsetSpace ~
16814 \InsetSpace ~
16815 \InsetSpace ~
16816 \InsetSpace ~
16817 \InsetSpace ~
16818 \InsetSpace ~
16819 \InsetSpace ~
16820 \InsetSpace ~
16821 \InsetSpace ~
16822 \InsetSpace ~
16823 \InsetSpace ~
16824 \InsetSpace ~
16825 \InsetSpace ~
16826 \InsetSpace ~
16827 \InsetSpace ~
16828 \InsetSpace ~
16829 \InsetSpace ~
16830 \InsetSpace ~
16831 \InsetSpace ~
16832 \InsetSpace ~
16833 \InsetSpace ~
16834 \InsetSpace ~
16835 \InsetSpace ~
16836 \InsetSpace ~
16837 \InsetSpace ~
16838 \InsetSpace ~
16839 \InsetSpace ~
16840 \InsetSpace ~
16841 \InsetSpace ~
16842 \InsetSpace ~
16843 \InsetSpace ~
16844 \InsetSpace ~
16845 \InsetSpace ~
16846 \InsetSpace ~
16847 \InsetSpace ~
16848 \InsetSpace ~
16849 \InsetSpace ~
16850 \InsetSpace ~
16851 section 
16852 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16853
16854 \end_inset
16855
16856  about
16857 \series bold
16858  volatile
16859 \series default
16860  */
16861 \newline
16862
16863 \newline
16864 void to_buffer( unsigned char c ) 
16865 \newline
16866 {
16867 \newline
16868 \InsetSpace ~
16869 \InsetSpace ~
16870 \InsetSpace ~
16871 \InsetSpace ~
16872 if( head != (unsigned char)(tail-1)
16873  )\InsetSpace ~
16874 /* cast 
16875 \series bold
16876 needed
16877 \series default
16878  to avoid promotion
16879 \begin_inset LatexCommand \index{promotion to signed int}
16880
16881 \end_inset
16882
16883
16884 \begin_inset LatexCommand \index{type promotion}
16885
16886 \end_inset
16887
16888  to integer */
16889 \begin_inset Marginal
16890 status collapsed
16891
16892 \begin_layout Standard
16893
16894 \series bold
16895 \InsetSpace ~
16896 !
16897 \end_layout
16898
16899 \end_inset
16900
16901
16902 \newline
16903 \InsetSpace ~
16904 \InsetSpace ~
16905 \InsetSpace ~
16906 \InsetSpace ~
16907 \InsetSpace ~
16908 \InsetSpace ~
16909 \InsetSpace ~
16910 \InsetSpace ~
16911 buf[ head++ ] = c;\InsetSpace ~
16912 \InsetSpace ~
16913 \InsetSpace ~
16914 \InsetSpace ~
16915 \InsetSpace ~
16916 \InsetSpace ~
16917 \InsetSpace ~
16918 \InsetSpace ~
16919 \InsetSpace ~
16920 \InsetSpace ~
16921 \InsetSpace ~
16922 \InsetSpace ~
16923 \InsetSpace ~
16924 \InsetSpace ~
16925 \InsetSpace ~
16926 \InsetSpace ~
16927 /* access to a 256 byte aligned array */
16928 \newline
16929
16930 \end_layout
16931
16932 \begin_layout Standard
16933 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16934  then a corresponding buffer.asm file is generated.
16935  We define a new function 
16936 \family typewriter
16937 to_buffer_asm()
16938 \family default
16939  in file buffer.c in which we cut and paste the generated code, removing
16940  unwanted comments and some ':'.
16941  Then add 
16942 \begin_inset Quotes sld
16943 \end_inset
16944
16945
16946 \series bold
16947 _asm
16948 \series default
16949
16950 \begin_inset Quotes srd
16951 \end_inset
16952
16953  and 
16954 \begin_inset Quotes sld
16955 \end_inset
16956
16957
16958 \series bold
16959 _endasm;
16960 \series default
16961
16962 \begin_inset Quotes srd
16963 \end_inset
16964
16965
16966 \begin_inset Foot
16967 status open
16968
16969 \begin_layout Standard
16970 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16971  and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16972  has to be used.
16973  The latter is also used in the library functions.
16974 \end_layout
16975
16976 \end_inset
16977
16978  to the beginning and the end of the function body:
16979 \end_layout
16980
16981 \begin_layout Verse
16982
16983 \family typewriter
16984 \size footnotesize
16985 /* With a cut and paste from the .asm file, we have something to start with.
16986 \newline
16987 \InsetSpace ~
16988 \InsetSpace ~
16989 \InsetSpace ~
16990 The
16991  function is not yet OK! (registers aren't saved) */ 
16992 \newline
16993 void to_buffer_asm(
16994  unsigned char c ) 
16995 \newline
16996
16997 \newline
16998 \InsetSpace ~
16999 \InsetSpace ~
17000 \InsetSpace ~
17001 \InsetSpace ~
17002 _asm
17003 \begin_inset LatexCommand \index{\_asm}
17004
17005 \end_inset
17006
17007
17008 \begin_inset LatexCommand \index{\_\_asm}
17009
17010 \end_inset
17011
17012
17013 \newline
17014 \InsetSpace ~
17015 \InsetSpace ~
17016 \InsetSpace ~
17017 \InsetSpace ~
17018 mov\InsetSpace ~
17019 \InsetSpace ~
17020 r2,dpl 
17021 \newline
17022 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
17023 /* cast 
17024 \series bold
17025 needed
17026 \series default
17027  to avoid promotion
17028 \begin_inset LatexCommand \index{promotion to signed int}
17029
17030 \end_inset
17031
17032
17033 \begin_inset LatexCommand \index{type promotion}
17034
17035 \end_inset
17036
17037  to integer */
17038 \newline
17039 \InsetSpace ~
17040 \InsetSpace ~
17041 \InsetSpace ~
17042 \InsetSpace ~
17043 mov\InsetSpace ~
17044 \InsetSpace ~
17045 a,_tail 
17046 \newline
17047 \InsetSpace ~
17048 \InsetSpace ~
17049 \InsetSpace ~
17050 \InsetSpace ~
17051 dec\InsetSpace ~
17052 \InsetSpace ~
17053
17054 \newline
17055 \InsetSpace ~
17056 \InsetSpace ~
17057 \InsetSpace ~
17058 \InsetSpace ~
17059 mov\InsetSpace ~
17060 \InsetSpace ~
17061 r3,a 
17062 \newline
17063 \InsetSpace ~
17064 \InsetSpace ~
17065 \InsetSpace ~
17066 \InsetSpace ~
17067 mov\InsetSpace ~
17068 \InsetSpace ~
17069 a,_head 
17070 \newline
17071 \InsetSpace ~
17072 \InsetSpace ~
17073 \InsetSpace ~
17074 \InsetSpace ~
17075 cjne a,ar3,00106$ 
17076 \newline
17077 \InsetSpace ~
17078 \InsetSpace ~
17079 \InsetSpace ~
17080 \InsetSpace ~
17081 ret
17082 \newline
17083 00106$:
17084  
17085 \newline
17086 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
17087 \begin_inset LatexCommand \index{Aligned array}
17088
17089 \end_inset
17090
17091
17092 \newline
17093 \InsetSpace ~
17094 \InsetSpace ~
17095 \InsetSpace ~
17096 \InsetSpace ~
17097 mov\InsetSpace ~
17098 \InsetSpace ~
17099 r3,_head 
17100 \newline
17101 \InsetSpace ~
17102 \InsetSpace ~
17103 \InsetSpace ~
17104 \InsetSpace ~
17105 inc\InsetSpace ~
17106 \InsetSpace ~
17107 _head 
17108 \newline
17109 \InsetSpace ~
17110 \InsetSpace ~
17111 \InsetSpace ~
17112 \InsetSpace ~
17113 mov\InsetSpace ~
17114 \InsetSpace ~
17115 dpl,r3 
17116 \newline
17117 \InsetSpace ~
17118 \InsetSpace ~
17119 \InsetSpace ~
17120 \InsetSpace ~
17121 mov\InsetSpace ~
17122 \InsetSpace ~
17123 dph,#(_buf >> 8) 
17124 \newline
17125 \InsetSpace ~
17126 \InsetSpace ~
17127 \InsetSpace ~
17128 \InsetSpace ~
17129 mov\InsetSpace ~
17130 \InsetSpace ~
17131 a,r2 
17132 \newline
17133 \InsetSpace ~
17134 \InsetSpace ~
17135 \InsetSpace ~
17136 \InsetSpace ~
17137 movx @dptr,a
17138  
17139 \newline
17140 00103$: 
17141 \newline
17142 \InsetSpace ~
17143 \InsetSpace ~
17144 \InsetSpace ~
17145 \InsetSpace ~
17146 ret
17147 \newline
17148 \InsetSpace ~
17149 \InsetSpace ~
17150 \InsetSpace ~
17151 \InsetSpace ~
17152 _endasm
17153 \begin_inset LatexCommand \index{\_endasm}
17154
17155 \end_inset
17156
17157
17158 \begin_inset LatexCommand \index{\_\_endasm}
17159
17160 \end_inset
17161
17162 ;
17163 \newline
17164
17165 \end_layout
17166
17167 \begin_layout Standard
17168 The new file buffer.c should compile with only one warning about the unreferenced
17169  function argument 'c'.
17170  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
17171  (1) and finally have:
17172 \end_layout
17173
17174 \begin_layout Verse
17175
17176 \family typewriter
17177 \size footnotesize
17178 unsigned char __far __at(0x7f00) buf[0x100];
17179 \newline
17180 unsigned char head, tail;
17181 \newline
17182 #define
17183  USE_ASSEMBLY (1)
17184 \newline
17185
17186 \newline
17187 #if !USE_ASSEMBLY
17188 \newline
17189
17190 \newline
17191 void to_buffer( unsigned char c )
17192 \newline
17193 {
17194 \newline
17195 \InsetSpace ~
17196 \InsetSpace ~
17197 \InsetSpace ~
17198 \InsetSpace ~
17199 if(
17200  head != (unsigned char)(tail-1) )
17201 \newline
17202 \InsetSpace ~
17203 \InsetSpace ~
17204 \InsetSpace ~
17205 \InsetSpace ~
17206 \InsetSpace ~
17207 \InsetSpace ~
17208 \InsetSpace ~
17209 \InsetSpace ~
17210 buf[ head++ ] = c;
17211 \newline
17212 }
17213 \newline
17214
17215 \newline
17216 #else
17217 \newline
17218
17219 \newline
17220 void to_buffer(
17221  unsigned char c )
17222 \newline
17223 {
17224 \newline
17225 \InsetSpace ~
17226 \InsetSpace ~
17227 \InsetSpace ~
17228 \InsetSpace ~
17229 c; // to avoid warning: unreferenced function argument
17230 \newline
17231 \InsetSpace ~
17232 \InsetSpace ~
17233 \InsetSpace ~
17234 \InsetSpace ~
17235 _asm
17236 \begin_inset LatexCommand \index{\_asm}
17237
17238 \end_inset
17239
17240
17241 \begin_inset LatexCommand \index{\_\_asm}
17242
17243 \end_inset
17244
17245
17246 \newline
17247 \InsetSpace ~
17248 \InsetSpace ~
17249 \InsetSpace ~
17250 \InsetSpace ~
17251 \InsetSpace ~
17252 \InsetSpace ~
17253 \InsetSpace ~
17254 \InsetSpace ~
17255 ; save used registers here.
17256  
17257 \newline
17258 \InsetSpace ~
17259 \InsetSpace ~
17260 \InsetSpace ~
17261 \InsetSpace ~
17262 \InsetSpace ~
17263 \InsetSpace ~
17264 \InsetSpace ~
17265 \InsetSpace ~
17266 ; If we were still using r2,r3 we would have to push them here.
17267  
17268 \newline
17269 ; if( head != (unsigned char)(tail-1) )
17270 \newline
17271 \InsetSpace ~
17272 \InsetSpace ~
17273 \InsetSpace ~
17274 \InsetSpace ~
17275 \InsetSpace ~
17276 \InsetSpace ~
17277 \InsetSpace ~
17278 \InsetSpace ~
17279 mov\InsetSpace ~
17280  a,_tail
17281 \newline
17282 \InsetSpace ~
17283 \InsetSpace ~
17284 \InsetSpace ~
17285 \InsetSpace ~
17286 \InsetSpace ~
17287 \InsetSpace ~
17288 \InsetSpace ~
17289 \InsetSpace ~
17290 dec\InsetSpace ~
17291  a
17292 \newline
17293 \InsetSpace ~
17294 \InsetSpace ~
17295 \InsetSpace ~
17296 \InsetSpace ~
17297 \InsetSpace ~
17298 \InsetSpace ~
17299 \InsetSpace ~
17300 \InsetSpace ~
17301 xrl\InsetSpace ~
17302  a,_head
17303 \newline
17304 \InsetSpace ~
17305 \InsetSpace ~
17306 \InsetSpace ~
17307 \InsetSpace ~
17308 \InsetSpace ~
17309 \InsetSpace ~
17310 \InsetSpace ~
17311 \InsetSpace ~
17312 ; we
17313  could do an ANL a,#0x0f here to use a smaller buffer (see below)
17314 \newline
17315 \InsetSpace ~
17316 \InsetSpace ~
17317 \InsetSpace ~
17318 \InsetSpace ~
17319 \InsetSpace ~
17320 \InsetSpace ~
17321 \InsetSpace ~
17322 \InsetSpace ~
17323 jz\InsetSpace ~
17324 \InsetSpace ~
17325  t_b_end$
17326 \newline
17327 \InsetSpace ~
17328 \InsetSpace ~
17329 \InsetSpace ~
17330 \InsetSpace ~
17331 \InsetSpace ~
17332 \InsetSpace ~
17333 \InsetSpace ~
17334 \InsetSpace ~
17335 ;
17336 \newline
17337 ;
17338  buf[ head++ ] = c;
17339 \newline
17340 \InsetSpace ~
17341 \InsetSpace ~
17342 \InsetSpace ~
17343 \InsetSpace ~
17344 \InsetSpace ~
17345 \InsetSpace ~
17346 \InsetSpace ~
17347 \InsetSpace ~
17348 mov\InsetSpace ~
17349  a,dpl \InsetSpace ~
17350 \InsetSpace ~
17351 \InsetSpace ~
17352 \InsetSpace ~
17353 \InsetSpace ~
17354 \InsetSpace ~
17355 \InsetSpace ~
17356 ; dpl holds lower byte of function argument
17357 \newline
17358 \InsetSpace ~
17359 \InsetSpace ~
17360 \InsetSpace ~
17361 \InsetSpace ~
17362 \InsetSpace ~
17363 \InsetSpace ~
17364 \InsetSpace ~
17365 \InsetSpace ~
17366 mov\InsetSpace ~
17367
17368  dpl,_head \InsetSpace ~
17369 \InsetSpace ~
17370 \InsetSpace ~
17371 ; buf is 0x100 byte aligned so head can be used directly
17372 \newline
17373 \InsetSpace ~
17374 \InsetSpace ~
17375 \InsetSpace ~
17376 \InsetSpace ~
17377 \InsetSpace ~
17378 \InsetSpace ~
17379 \InsetSpace ~
17380 \InsetSpace ~
17381 mov\InsetSpace ~
17382  dph,#(_bu
17383 f>>8)
17384 \newline
17385 \InsetSpace ~
17386 \InsetSpace ~
17387 \InsetSpace ~
17388 \InsetSpace ~
17389 \InsetSpace ~
17390 \InsetSpace ~
17391 \InsetSpace ~
17392 \InsetSpace ~
17393 movx @dptr,a
17394 \newline
17395 \InsetSpace ~
17396 \InsetSpace ~
17397 \InsetSpace ~
17398 \InsetSpace ~
17399 \InsetSpace ~
17400 \InsetSpace ~
17401 \InsetSpace ~
17402 \InsetSpace ~
17403 inc \InsetSpace ~
17404 _head
17405 \newline
17406 \InsetSpace ~
17407 \InsetSpace ~
17408 \InsetSpace ~
17409 \InsetSpace ~
17410 \InsetSpace ~
17411 \InsetSpace ~
17412 \InsetSpace ~
17413 \InsetSpace ~
17414 ; we could do an ANL _head,#0x0f here to use a
17415  smaller buffer (see above)
17416 \newline
17417 t_b_end$:
17418 \newline
17419 \InsetSpace ~
17420 \InsetSpace ~
17421 \InsetSpace ~
17422 \InsetSpace ~
17423 \InsetSpace ~
17424 \InsetSpace ~
17425 \InsetSpace ~
17426 \InsetSpace ~
17427 ; restore used registers here 
17428 \newline
17429 \InsetSpace ~
17430 \InsetSpace ~
17431 \InsetSpace ~
17432 \InsetSpace ~
17433 _endasm
17434 \begin_inset LatexCommand \index{\_endasm}
17435
17436 \end_inset
17437
17438
17439 \begin_inset LatexCommand \index{\_\_endasm}
17440
17441 \end_inset
17442
17443 ;
17444 \newline
17445 }
17446 \newline
17447 #endif
17448 \end_layout
17449
17450 \begin_layout Standard
17451 The inline assembler code can contain any valid code understood by the assembler
17452 , this includes any assembler directives and comment lines.
17453  The assembler does not like some characters like ':' or ''' in comments.
17454  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
17455 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
17456
17457 \end_inset
17458
17459
17460 \begin_inset LatexCommand \index{Assembler documentation}
17461
17462 \end_inset
17463
17464  or online at 
17465 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
17466
17467 \end_inset
17468
17469 \InsetSpace ~
17470 .
17471 \end_layout
17472
17473 \begin_layout Standard
17474 The compiler does not do any validation of the code within the 
17475 \family typewriter
17476 _asm
17477 \begin_inset LatexCommand \index{\_asm}
17478
17479 \end_inset
17480
17481
17482 \begin_inset LatexCommand \index{\_\_asm}
17483
17484 \end_inset
17485
17486  ...
17487  _endasm
17488 \size footnotesize
17489
17490 \begin_inset LatexCommand \index{\_endasm}
17491
17492 \end_inset
17493
17494
17495 \begin_inset LatexCommand \index{\_\_endasm}
17496
17497 \end_inset
17498
17499
17500 \size default
17501 ;
17502 \family default
17503  keyword pair.
17504  Specifically it will not know which registers are used and thus register
17505  pushing/popping
17506 \begin_inset LatexCommand \index{push/pop}
17507
17508 \end_inset
17509
17510  has to be done manually.
17511  
17512 \end_layout
17513
17514 \begin_layout Standard
17515 It is recommended that each assembly instruction (including labels) be placed
17516  in a separate line (as the example shows).
17517  When the -
17518 \begin_inset ERT
17519 status collapsed
17520
17521 \begin_layout Standard
17522
17523
17524 \backslash
17525 /
17526 \end_layout
17527
17528 \end_inset
17529
17530 -
17531 \emph on
17532 peep-asm
17533 \begin_inset LatexCommand \index{-\/-peep-asm}
17534
17535 \end_inset
17536
17537
17538 \emph default
17539  command line option is used, the inline assembler code will be passed through
17540  the peephole optimizer
17541 \begin_inset LatexCommand \index{Peephole optimizer}
17542
17543 \end_inset
17544
17545 .
17546  There are only a few (if any) cases where this option makes sense, it might
17547  cause some unexpected changes in the inline assembler code.
17548  Please go through the peephole optimizer rules defined in file 
17549 \emph on
17550 SDCCpeeph.def
17551 \emph default
17552  before using this option.
17553 \end_layout
17554
17555 \begin_layout Subsection
17556 Naked Functions
17557 \begin_inset LatexCommand \label{sub:Naked-Functions}
17558
17559 \end_inset
17560
17561
17562 \begin_inset LatexCommand \index{Naked functions}
17563
17564 \end_inset
17565
17566
17567 \end_layout
17568
17569 \begin_layout Standard
17570 A special keyword may be associated with a function declaring it as 
17571 \emph on
17572 _naked
17573 \begin_inset LatexCommand \index{\_naked}
17574
17575 \end_inset
17576
17577
17578 \begin_inset LatexCommand \index{\_\_naked}
17579
17580 \end_inset
17581
17582 .
17583  
17584 \emph default
17585 The 
17586 \emph on
17587 _naked
17588 \emph default
17589  function modifier attribute prevents the compiler from generating prologue
17590 \begin_inset LatexCommand \index{function prologue}
17591
17592 \end_inset
17593
17594  and epilogue
17595 \begin_inset LatexCommand \index{function epilogue}
17596
17597 \end_inset
17598
17599  code for that function.
17600  This means that the user is entirely responsible for such things as saving
17601  any registers that may need to be preserved, selecting the proper register
17602  bank, generating the 
17603 \emph on
17604 return
17605 \emph default
17606  instruction at the end, etc.
17607  Practically, this means that the contents of the function must be written
17608  in inline assembler.
17609  This is particularly useful for interrupt functions, which can have a large
17610  (and often unnecessary) prologue/epilogue.
17611  For example, compare the code generated by these two functions:
17612 \end_layout
17613
17614 \begin_layout Verse
17615
17616 \family typewriter
17617 volatile
17618 \begin_inset LatexCommand \index{volatile}
17619
17620 \end_inset
17621
17622  data unsigned char counter;
17623 \newline
17624
17625 \newline
17626 void simpleInterrupt(void) __interrupt
17627 \begin_inset LatexCommand \index{interrupt}
17628
17629 \end_inset
17630
17631
17632 \begin_inset LatexCommand \index{\_\_interrupt}
17633
17634 \end_inset
17635
17636  (1)
17637 \newline
17638 {
17639 \newline
17640 \InsetSpace ~
17641 \InsetSpace ~
17642 \InsetSpace ~
17643 \InsetSpace ~
17644 counter++;
17645 \newline
17646 }
17647 \newline
17648
17649 \newline
17650 void nakedInterrupt(void) __interrupt (2) __naked
17651 \newline
17652 {
17653 \newline
17654 \InsetSpace ~
17655 \InsetSpace ~
17656 \InsetSpace ~
17657 \InsetSpace ~
17658 _asm
17659 \begin_inset LatexCommand \index{\_asm}
17660
17661 \end_inset
17662
17663
17664 \begin_inset LatexCommand \index{\_\_asm}
17665
17666 \end_inset
17667
17668
17669 \newline
17670 \InsetSpace ~
17671 \InsetSpace ~
17672 \InsetSpace ~
17673 \InsetSpace ~
17674 \InsetSpace ~
17675 \InsetSpace ~
17676 inc\InsetSpace ~
17677 \InsetSpace ~
17678 \InsetSpace ~
17679 \InsetSpace ~
17680 \InsetSpace ~
17681 _counter ; does not change flags, no need to save psw
17682 \newline
17683 \InsetSpace ~
17684 \InsetSpace ~
17685 \InsetSpace ~
17686 \InsetSpace ~
17687 \InsetSpace ~
17688 \InsetSpace ~
17689 reti\InsetSpace ~
17690 \InsetSpace ~
17691 \InsetSpace ~
17692 \InsetSpace ~
17693 ; MUST explicitly
17694  include ret or reti in _naked function.
17695 \newline
17696 \InsetSpace ~
17697 \InsetSpace ~
17698 \InsetSpace ~
17699 \InsetSpace ~
17700 _endasm
17701 \begin_inset LatexCommand \index{\_endasm}
17702
17703 \end_inset
17704
17705
17706 \begin_inset LatexCommand \index{\_\_endasm}
17707
17708 \end_inset
17709
17710 ;
17711 \newline
17712 }
17713 \end_layout
17714
17715 \begin_layout Standard
17716 For an 8051 target, the generated simpleInterrupt looks like:
17717 \end_layout
17718
17719 \begin_layout Verse
17720
17721 \family typewriter
17722 Note, this is an 
17723 \emph on
17724 outdated
17725 \emph default
17726  example, recent versions of SDCC generate
17727 \newline
17728 the 
17729 \emph on
17730 same
17731 \emph default
17732  code for simpleInterrupt() and nakedInterrupt()!
17733 \newline
17734
17735 \newline
17736 _simpleInterrupt:
17737 \newline
17738 \InsetSpace ~
17739 \InsetSpace ~
17740 \InsetSpace ~
17741 \InsetSpace ~
17742 push\InsetSpace ~
17743 \InsetSpace ~
17744 \InsetSpace ~
17745 \InsetSpace ~
17746 acc
17747 \newline
17748 \InsetSpace ~
17749 \InsetSpace ~
17750 \InsetSpace ~
17751 \InsetSpace ~
17752 push\InsetSpace ~
17753 \InsetSpace ~
17754 \InsetSpace ~
17755 \InsetSpace ~
17756 b
17757 \newline
17758 \InsetSpace ~
17759 \InsetSpace ~
17760 \InsetSpace ~
17761 \InsetSpace ~
17762 pu
17763 sh\InsetSpace ~
17764 \InsetSpace ~
17765 \InsetSpace ~
17766 \InsetSpace ~
17767 dpl
17768 \newline
17769 \InsetSpace ~
17770 \InsetSpace ~
17771 \InsetSpace ~
17772 \InsetSpace ~
17773 push\InsetSpace ~
17774 \InsetSpace ~
17775 \InsetSpace ~
17776 \InsetSpace ~
17777 dph
17778 \newline
17779 \InsetSpace ~
17780 \InsetSpace ~
17781 \InsetSpace ~
17782 \InsetSpace ~
17783 push\InsetSpace ~
17784 \InsetSpace ~
17785 \InsetSpace ~
17786 \InsetSpace ~
17787 psw
17788 \newline
17789 \InsetSpace ~
17790 \InsetSpace ~
17791 \InsetSpace ~
17792 \InsetSpace ~
17793 mov\InsetSpace ~
17794 \InsetSpace ~
17795 \InsetSpace ~
17796 \InsetSpace ~
17797 \InsetSpace ~
17798 psw,#0x00
17799 \newline
17800 \InsetSpace ~
17801 \InsetSpace ~
17802 \InsetSpace ~
17803 \InsetSpace ~
17804 inc\InsetSpace ~
17805 \InsetSpace ~
17806 \InsetSpace ~
17807 \InsetSpace ~
17808 \InsetSpace ~
17809 _counter
17810 \newline
17811 \InsetSpace ~
17812 \InsetSpace ~
17813 \InsetSpace ~
17814 \InsetSpace ~
17815 pop\InsetSpace ~
17816 \InsetSpace ~
17817 \InsetSpace ~
17818 \InsetSpace ~
17819 \InsetSpace ~
17820 psw
17821 \newline
17822 \InsetSpace ~
17823 \InsetSpace ~
17824 \InsetSpace ~
17825 \InsetSpace ~
17826 pop\InsetSpace ~
17827 \InsetSpace ~
17828 \InsetSpace ~
17829 \InsetSpace ~
17830 \InsetSpace ~
17831 dph
17832 \newline
17833 \InsetSpace ~
17834 \InsetSpace ~
17835 \InsetSpace ~
17836 \InsetSpace ~
17837 pop\InsetSpace ~
17838 \InsetSpace ~
17839 \InsetSpace ~
17840 \InsetSpace ~
17841 \InsetSpace ~
17842 dpl
17843 \newline
17844 \InsetSpace ~
17845 \InsetSpace ~
17846 \InsetSpace ~
17847 \InsetSpace ~
17848 pop\InsetSpace ~
17849 \InsetSpace ~
17850 \InsetSpace ~
17851 \InsetSpace ~
17852 \InsetSpace ~
17853 b
17854 \newline
17855 \InsetSpace ~
17856 \InsetSpace ~
17857 \InsetSpace ~
17858 \InsetSpace ~
17859 pop\InsetSpace ~
17860 \InsetSpace ~
17861 \InsetSpace ~
17862 \InsetSpace ~
17863 \InsetSpace ~
17864 acc
17865 \newline
17866 \InsetSpace ~
17867 \InsetSpace ~
17868 \InsetSpace ~
17869 \InsetSpace ~
17870 reti
17871 \end_layout
17872
17873 \begin_layout Standard
17874 whereas nakedInterrupt looks like:
17875 \end_layout
17876
17877 \begin_layout Verse
17878
17879 \family typewriter
17880 _nakedInterrupt:
17881 \newline
17882 \InsetSpace ~
17883 \InsetSpace ~
17884 \InsetSpace ~
17885 \InsetSpace ~
17886 inc\InsetSpace ~
17887 \InsetSpace ~
17888 \InsetSpace ~
17889 \InsetSpace ~
17890 _counter ; does not change flags, no need to save psw
17891 \newline
17892 \InsetSpace ~
17893 \InsetSpace ~
17894 \InsetSpace ~
17895 \InsetSpace ~
17896 reti\InsetSpace ~
17897 \InsetSpace ~
17898 \InsetSpace ~
17899 \InsetSpace ~
17900 \InsetSpace ~
17901 \InsetSpace ~
17902 \InsetSpace ~
17903 \InsetSpace ~
17904 \InsetSpace ~
17905 \InsetSpace ~
17906 \InsetSpace ~
17907 \InsetSpace ~
17908 ;
17909  MUST explicitly include ret or reti in _naked function
17910 \end_layout
17911
17912 \begin_layout Standard
17913 The related directive #pragma exclude
17914 \begin_inset LatexCommand \index{\#pragma exclude}
17915
17916 \end_inset
17917
17918  allows a more fine grained control over pushing & popping
17919 \begin_inset LatexCommand \index{push/pop}
17920
17921 \end_inset
17922
17923  the registers.
17924 \end_layout
17925
17926 \begin_layout Standard
17927 While there is nothing preventing you from writing C code inside a 
17928 \family typewriter
17929 _naked
17930 \family default
17931  function, there are many ways to shoot yourself in the foot doing this,
17932  and it is recommended that you stick to inline assembler.
17933 \end_layout
17934
17935 \begin_layout Subsection
17936 Use of Labels within Inline Assembler
17937 \end_layout
17938
17939 \begin_layout Standard
17940 SDCC allows the use of in-line assembler with a few restrictions regarding
17941  labels.
17942  All labels defined within inline assembler code have to be of the form
17943  
17944 \emph on
17945 nnnnn$
17946 \emph default
17947  where nnnnn is a number less than 100 (which implies a limit of utmost
17948  100 inline assembler labels 
17949 \emph on
17950 per function
17951 \emph default
17952 \noun on
17953 )
17954 \noun default
17955 .
17956 \begin_inset Foot
17957 status open
17958
17959 \begin_layout Standard
17960 This is a slightly more stringent rule than absolutely necessary, but stays
17961  always on the safe side.
17962  Labels in the form of nnnnn$ are local labels in the assembler, locality
17963  of which is confined within two labels of the standard form.
17964  The compiler uses the same form for labels within a function (but starting
17965  from nnnnn=00100); and places always a standard label at the beginning
17966  of a function, thus limiting the locality of labels within the scope of
17967  the function.
17968  So, if the inline assembler part would be embedded into C-code, an improperly
17969  placed non-local label in the assembler would break up the reference space
17970  for labels created by the compiler for the C-code, leading to an assembling
17971  error.
17972 \end_layout
17973
17974 \begin_layout Standard
17975 The numeric part of local labels does not need to have 5 digits (although
17976  this is the form of labels output by the compiler), any valid integer will
17977  do.
17978  Please refer to the assemblers documentation for further details.
17979 \end_layout
17980
17981 \end_inset
17982
17983  
17984 \end_layout
17985
17986 \begin_layout Verse
17987
17988 \family typewriter
17989 _asm
17990 \begin_inset LatexCommand \index{\_asm}
17991
17992 \end_inset
17993
17994
17995 \begin_inset LatexCommand \index{\_\_asm}
17996
17997 \end_inset
17998
17999  
18000 \newline
18001 \InsetSpace ~
18002 \InsetSpace ~
18003 \InsetSpace ~
18004 \InsetSpace ~
18005 mov\InsetSpace ~
18006 \InsetSpace ~
18007 \InsetSpace ~
18008 \InsetSpace ~
18009 \InsetSpace ~
18010 b,#10 
18011 \newline
18012 00001$: 
18013 \newline
18014 \InsetSpace ~
18015 \InsetSpace ~
18016 \InsetSpace ~
18017 \InsetSpace ~
18018 djnz\InsetSpace ~
18019 \InsetSpace ~
18020 \InsetSpace ~
18021 \InsetSpace ~
18022 b,00001$ 
18023 \newline
18024 _endasm
18025 \begin_inset LatexCommand \index{\_endasm}
18026
18027 \end_inset
18028
18029
18030 \begin_inset LatexCommand \index{\_\_endasm}
18031
18032 \end_inset
18033
18034  ;
18035 \end_layout
18036
18037 \begin_layout Standard
18038 Inline assembler code cannot reference any C-labels, however it can reference
18039  labels
18040 \begin_inset LatexCommand \index{Labels}
18041
18042 \end_inset
18043
18044  defined by the inline assembler, e.g.:
18045 \end_layout
18046
18047 \begin_layout Verse
18048
18049 \family typewriter
18050 foo() { 
18051 \newline
18052 \InsetSpace ~
18053 \InsetSpace ~
18054 \InsetSpace ~
18055 \InsetSpace ~
18056 /* some c code */ 
18057 \newline
18058 \InsetSpace ~
18059 \InsetSpace ~
18060 \InsetSpace ~
18061 \InsetSpace ~
18062 _asm 
18063 \newline
18064 \InsetSpace ~
18065 \InsetSpace ~
18066 \InsetSpace ~
18067 \InsetSpace ~
18068 \InsetSpace ~
18069 \InsetSpace ~
18070 ; some assembler code 
18071 \newline
18072 \InsetSpace ~
18073 \InsetSpace ~
18074 \InsetSpace ~
18075 \InsetSpace ~
18076 \InsetSpace ~
18077 \InsetSpace ~
18078 ljmp 0003$ 
18079 \newline
18080 \InsetSpace ~
18081 \InsetSpace ~
18082 \InsetSpace ~
18083 \InsetSpace ~
18084 _endasm;
18085  
18086 \newline
18087 \InsetSpace ~
18088 \InsetSpace ~
18089 \InsetSpace ~
18090 \InsetSpace ~
18091 /* some more c code */ 
18092 \newline
18093 clabel:\InsetSpace ~
18094 \InsetSpace ~
18095 /* inline assembler cannot reference this
18096  label */ 
18097 \begin_inset Foot
18098 status open
18099
18100 \begin_layout Standard
18101 Here, the C-label 
18102 \family typewriter
18103 clabel
18104 \family default
18105  is translated by the compiler into a local label, so the locality of labels
18106  within the function is not broken.
18107 \end_layout
18108
18109 \end_inset
18110
18111
18112 \newline
18113 \InsetSpace ~
18114 \InsetSpace ~
18115 \InsetSpace ~
18116 \InsetSpace ~
18117 _asm
18118 \newline
18119 \InsetSpace ~
18120 \InsetSpace ~
18121 \InsetSpace ~
18122 \InsetSpace ~
18123 0003$: ;label (can be referenced by inline assembler only) 
18124 \newline
18125 \InsetSpace ~
18126 \InsetSpace ~
18127 \InsetSpace ~
18128 \InsetSpace ~
18129 _endasm
18130 \begin_inset LatexCommand \index{\_endasm}
18131
18132 \end_inset
18133
18134
18135 \begin_inset LatexCommand \index{\_\_endasm}
18136
18137 \end_inset
18138
18139  ; 
18140 \newline
18141 \InsetSpace ~
18142 \InsetSpace ~
18143 \InsetSpace ~
18144 \InsetSpace ~
18145 /* some more c code */
18146 \newline
18147 }
18148 \end_layout
18149
18150 \begin_layout Standard
18151 In other words inline assembly code can access labels defined in inline
18152  assembly within the scope of the function.
18153  The same goes the other way, i.e.
18154  labels defines in inline assembly can not be accessed by C statements.
18155 \end_layout
18156
18157 \begin_layout Section
18158 Interfacing with Assembler Code
18159 \begin_inset LatexCommand \index{Assembler routines}
18160
18161 \end_inset
18162
18163
18164 \end_layout
18165
18166 \begin_layout Subsection
18167 Global Registers used for Parameter Passing
18168 \begin_inset LatexCommand \index{Parameter passing}
18169
18170 \end_inset
18171
18172
18173 \end_layout
18174
18175 \begin_layout Standard
18176 The compiler always uses the global registers 
18177 \emph on
18178 DPL, DPH
18179 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18180
18181 \end_inset
18182
18183
18184 \begin_inset LatexCommand \index{DPTR}
18185
18186 \end_inset
18187
18188 , B
18189 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
18190
18191 \end_inset
18192
18193  
18194 \emph default
18195 and
18196 \emph on
18197  ACC
18198 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
18199
18200 \end_inset
18201
18202
18203 \emph default
18204  to pass the first (non-bit) parameter to a function, and also to pass the
18205  return value 
18206 \begin_inset LatexCommand \index{return value}
18207
18208 \end_inset
18209
18210 of function; according to the following scheme: one byte return value in
18211  
18212 \emph on
18213 DPL
18214 \emph default
18215 , two byte value in 
18216 \emph on
18217 DPL
18218 \emph default
18219  (LSB) and 
18220 \emph on
18221 DPH
18222 \emph default
18223  (MSB).
18224  three byte values (generic pointers) in 
18225 \emph on
18226 DPH
18227 \emph default
18228
18229 \emph on
18230 DPL
18231 \emph default
18232  and 
18233 \emph on
18234 B
18235 \emph default
18236 , and four byte values in 
18237 \emph on
18238 DPH
18239 \emph default
18240
18241 \emph on
18242 DPL
18243 \emph default
18244 ,
18245 \emph on
18246  B
18247 \emph default
18248  and 
18249 \emph on
18250 ACC
18251 \emph default
18252 .
18253  Generic pointers
18254 \begin_inset LatexCommand \index{generic pointer}
18255
18256 \end_inset
18257
18258  contain type of accessed memory in 
18259 \emph on
18260 B
18261 \emph default
18262
18263 \series bold
18264 0x00
18265 \series default
18266  -- xdata/far, 
18267 \series bold
18268 0x40
18269 \series default
18270  -- idata/near -- , 
18271 \series bold
18272 0x60
18273 \series default
18274  -- pdata, 
18275 \series bold
18276 0x80
18277 \series default
18278  -- code
18279 \begin_inset Note Note
18280 status collapsed
18281
18282 \begin_layout Standard
18283 This might not be the case of certain memory models (medium???)
18284 \end_layout
18285
18286 \end_inset
18287
18288 .
18289 \end_layout
18290
18291 \begin_layout Standard
18292 The second parameter onwards is either allocated on the stack (for reentrant
18293  routines or if -
18294 \begin_inset ERT
18295 status collapsed
18296
18297 \begin_layout Standard
18298
18299
18300 \backslash
18301 /
18302 \end_layout
18303
18304 \end_inset
18305
18306 -stack-auto is used) or in data/xdata memory (depending on the memory model).
18307 \end_layout
18308
18309 \begin_layout Standard
18310 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
18311  space for reentrant functions or allocated directly in bit memory otherwise.
18312 \end_layout
18313
18314 \begin_layout Standard
18315 Functions (with two or more parameters or bit parameters) that are called
18316  through function pointers
18317 \begin_inset LatexCommand \index{function pointers}
18318
18319 \end_inset
18320
18321  must therefor be reentrant so the compiler knows how to pass the parameters.
18322 \end_layout
18323
18324 \begin_layout Subsection
18325 Registers usage
18326 \end_layout
18327
18328 \begin_layout Standard
18329 Unless the called function is declared as 
18330 \family typewriter
18331 _naked
18332 \family default
18333
18334 \begin_inset LatexCommand \index{naked}
18335
18336 \end_inset
18337
18338 , or the -
18339 \begin_inset ERT
18340 status collapsed
18341
18342 \begin_layout Standard
18343
18344
18345 \backslash
18346 /
18347 \end_layout
18348
18349 \end_inset
18350
18351 -callee-saves
18352 \begin_inset LatexCommand \index{-\/-callee-saves}
18353
18354 \end_inset
18355
18356 /-
18357 \begin_inset ERT
18358 status collapsed
18359
18360 \begin_layout Standard
18361
18362
18363 \backslash
18364 /
18365 \end_layout
18366
18367 \end_inset
18368
18369 -all-callee-saves command line option or the corresponding callee_saves
18370  pragma are used, the caller will save the registers (
18371 \emph on
18372 R0-R7
18373 \emph default
18374 ) around the call, so the called function can destroy they content freely.
18375 \end_layout
18376
18377 \begin_layout Standard
18378 If the called function is not declared as 
18379 \family typewriter
18380 _naked
18381 \family default
18382 , the caller will swap register banks around the call, if caller and callee
18383  use different register banks (having them defined by the 
18384 \family typewriter
18385 _using
18386 \family default
18387  modifier).
18388  
18389 \end_layout
18390
18391 \begin_layout Standard
18392 The called function can also use 
18393 \emph on
18394 DPL
18395 \emph default
18396
18397 \emph on
18398 DPH
18399 \emph default
18400
18401 \emph on
18402 B
18403 \emph default
18404  and 
18405 \emph on
18406 ACC
18407 \emph default
18408  observing that they are used for parameter/return value passing.
18409 \end_layout
18410
18411 \begin_layout Subsection
18412 Assembler Routine (non-reentrant)
18413 \end_layout
18414
18415 \begin_layout Standard
18416 In the following example
18417 \begin_inset LatexCommand \index{reentrant}
18418
18419 \end_inset
18420
18421
18422 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
18423
18424 \end_inset
18425
18426  the function c_func calls an assembler routine asm_func, which takes two
18427  parameters
18428 \begin_inset LatexCommand \index{function parameter}
18429
18430 \end_inset
18431
18432 .
18433 \end_layout
18434
18435 \begin_layout Verse
18436
18437 \family typewriter
18438 extern int asm_func(unsigned char, unsigned char);
18439 \newline
18440
18441 \newline
18442 int c_func (unsigned char
18443  i, unsigned char j)
18444 \newline
18445 {
18446 \newline
18447 \InsetSpace ~
18448 \InsetSpace ~
18449 \InsetSpace ~
18450 \InsetSpace ~
18451 return asm_func(i,j);
18452 \newline
18453 }
18454 \newline
18455
18456 \newline
18457 int main()
18458 \newline
18459 {
18460 \newline
18461 \InsetSpace ~
18462 \InsetSpace ~
18463 \InsetSpace ~
18464 \InsetSpace ~
18465 return c_func(10,9);
18466 \newline
18467 }
18468 \end_layout
18469
18470 \begin_layout Standard
18471 The corresponding assembler function is:
18472 \end_layout
18473
18474 \begin_layout Verse
18475
18476 \family typewriter
18477 .globl _asm_func_PARM_2 
18478 \newline
18479 \InsetSpace ~
18480 \InsetSpace ~
18481 \InsetSpace ~
18482 \InsetSpace ~
18483 \InsetSpace ~
18484 \InsetSpace ~
18485 \InsetSpace ~
18486 \InsetSpace ~
18487 .globl _asm_func 
18488 \newline
18489 \InsetSpace ~
18490 \InsetSpace ~
18491 \InsetSpace ~
18492 \InsetSpace ~
18493 \InsetSpace ~
18494 \InsetSpace ~
18495 \InsetSpace ~
18496 \InsetSpace ~
18497 .area OSEG 
18498 \newline
18499 _asm_func_PARM_2:
18500 \newline
18501 \InsetSpace ~
18502 \InsetSpace ~
18503 \InsetSpace ~
18504 \InsetSpace ~
18505 \InsetSpace ~
18506 \InsetSpace ~
18507 \InsetSpace ~
18508 \InsetSpace ~
18509 .ds   
18510  1 
18511 \newline
18512 \InsetSpace ~
18513 \InsetSpace ~
18514 \InsetSpace ~
18515 \InsetSpace ~
18516 \InsetSpace ~
18517 \InsetSpace ~
18518 \InsetSpace ~
18519 \InsetSpace ~
18520 .area CSEG 
18521 \newline
18522 _asm_func: 
18523 \newline
18524 \InsetSpace ~
18525 \InsetSpace ~
18526 \InsetSpace ~
18527 \InsetSpace ~
18528 \InsetSpace ~
18529 \InsetSpace ~
18530 \InsetSpace ~
18531 \InsetSpace ~
18532 mov\InsetSpace ~
18533 \InsetSpace ~
18534 \InsetSpace ~
18535 \InsetSpace ~
18536 a,dpl 
18537 \newline
18538 \InsetSpace ~
18539 \InsetSpace ~
18540 \InsetSpace ~
18541 \InsetSpace ~
18542 \InsetSpace ~
18543 \InsetSpace ~
18544 \InsetSpace ~
18545 \InsetSpace ~
18546 add\InsetSpace ~
18547 \InsetSpace ~
18548 \InsetSpace ~
18549 \InsetSpace ~
18550 a,_asm_func_PARM_2 
18551 \newline
18552 \InsetSpace ~
18553 \InsetSpace ~
18554 \InsetSpace ~
18555 \InsetSpace ~
18556 \InsetSpace ~
18557 \InsetSpace ~
18558 \InsetSpace ~
18559 \InsetSpace ~
18560 mov\InsetSpace ~
18561 \InsetSpace ~
18562 \InsetSpace ~
18563 \InsetSpace ~
18564 dpl,a 
18565 \newline
18566 \InsetSpace ~
18567 \InsetSpace ~
18568 \InsetSpace ~
18569 \InsetSpace ~
18570 \InsetSpace ~
18571 \InsetSpace ~
18572 \InsetSpace ~
18573 \InsetSpace ~
18574 mov\InsetSpace ~
18575 \InsetSpace ~
18576 \InsetSpace ~
18577 \InsetSpace ~
18578 dph
18579 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
18580
18581 \end_inset
18582
18583 ,#0x00 
18584 \newline
18585 \InsetSpace ~
18586 \InsetSpace ~
18587 \InsetSpace ~
18588 \InsetSpace ~
18589 \InsetSpace ~
18590 \InsetSpace ~
18591 \InsetSpace ~
18592 \InsetSpace ~
18593 ret
18594 \end_layout
18595
18596 \begin_layout Standard
18597 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18598  the parameter number starting from 1, and counting from the left.
18599  The first parameter is passed in 
18600 \emph on
18601 DPH
18602 \emph default
18603
18604 \emph on
18605 DPL
18606 \emph default
18607
18608 \emph on
18609 B
18610 \emph default
18611  and 
18612 \emph on
18613 ACC
18614 \emph default
18615  according to the description above.
18616  The variable name for the second parameter will be _<function_name>_PARM_2.
18617 \newline
18618
18619 \newline
18620 Assem
18621 ble the assembler routine with the following command:
18622 \newline
18623
18624 \newline
18625
18626 \family sans
18627 \series bold
18628 asx8051 -losg asmfunc.asm
18629 \newline
18630
18631 \newline
18632
18633 \family default
18634 \series default
18635 Then compile and link the assembler routine to the C source file with the
18636  following command:
18637 \newline
18638
18639 \newline
18640
18641 \family sans
18642 \series bold
18643 sdcc cfunc.c asmfunc.rel
18644 \end_layout
18645
18646 \begin_layout Subsection
18647 Assembler Routine (reentrant)
18648 \end_layout
18649
18650 \begin_layout Standard
18651 In this case
18652 \begin_inset LatexCommand \index{reentrant}
18653
18654 \end_inset
18655
18656
18657 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18658
18659 \end_inset
18660
18661  the second parameter
18662 \begin_inset LatexCommand \index{function parameter}
18663
18664 \end_inset
18665
18666  onwards will be passed on the stack, the parameters are pushed from right
18667  to left i.e.
18668  before the call the second leftmost parameter will be on the top of the
18669  stack (the leftmost parameter is passed in registers).
18670  Here is an example:
18671 \end_layout
18672
18673 \begin_layout Verse
18674
18675 \family typewriter
18676 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18677 \newline
18678
18679 \newline
18680 int
18681  c_func (unsigned char i, unsigned char j, unsigned char k) reentrant 
18682 \newline
18683 {
18684  
18685 \newline
18686 \InsetSpace ~
18687 \InsetSpace ~
18688 \InsetSpace ~
18689 \InsetSpace ~
18690 return asm_func(i,j,k); 
18691 \newline
18692
18693 \newline
18694
18695 \newline
18696 int main() 
18697 \newline
18698
18699 \newline
18700 \InsetSpace ~
18701 \InsetSpace ~
18702 \InsetSpace ~
18703 \InsetSpace ~
18704 return c_func(10,9,8); 
18705 \newline
18706 }
18707 \end_layout
18708
18709 \begin_layout Standard
18710 The corresponding (unoptimized) assembler routine is:
18711 \end_layout
18712
18713 \begin_layout Verse
18714
18715 \family typewriter
18716 .globl _asm_func 
18717 \newline
18718 _asm_func: 
18719 \newline
18720 \InsetSpace ~
18721 \InsetSpace ~
18722 \InsetSpace ~
18723 \InsetSpace ~
18724 push\InsetSpace ~
18725 _bp 
18726 \newline
18727 \InsetSpace ~
18728 \InsetSpace ~
18729 \InsetSpace ~
18730 \InsetSpace ~
18731 mov\InsetSpace ~
18732 \InsetSpace ~
18733 _bp,sp\InsetSpace ~
18734 \InsetSpace ~
18735 \InsetSpace ~
18736 \InsetSpace ~
18737 \InsetSpace ~
18738 \InsetSpace ~
18739 ;stack contains: _bp, return
18740  address, second parameter, third parameter
18741 \newline
18742 \InsetSpace ~
18743 \InsetSpace ~
18744 \InsetSpace ~
18745 \InsetSpace ~
18746 mov\InsetSpace ~
18747 \InsetSpace ~
18748 r2,dpl
18749 \newline
18750 \InsetSpace ~
18751 \InsetSpace ~
18752 \InsetSpace ~
18753 \InsetSpace ~
18754 mov\InsetSpace ~
18755 \InsetSpace ~
18756 a,_bp
18757 \newline
18758 \InsetSpace ~
18759 \InsetSpace ~
18760 \InsetSpace ~
18761 \InsetSpace ~
18762 add\InsetSpace ~
18763 \InsetSpace ~
18764 a,#0xfd\InsetSpace ~
18765 \InsetSpace ~
18766 \InsetSpace ~
18767 \InsetSpace ~
18768 \InsetSpace ~
18769 ;calculate
18770  pointer to the second parameter
18771 \newline
18772 \InsetSpace ~
18773 \InsetSpace ~
18774 \InsetSpace ~
18775 \InsetSpace ~
18776 mov\InsetSpace ~
18777 \InsetSpace ~
18778 r0,a 
18779 \newline
18780 \InsetSpace ~
18781 \InsetSpace ~
18782 \InsetSpace ~
18783 \InsetSpace ~
18784 mov\InsetSpace ~
18785 \InsetSpace ~
18786 a,_bp 
18787 \newline
18788 \InsetSpace ~
18789 \InsetSpace ~
18790 \InsetSpace ~
18791 \InsetSpace ~
18792 add\InsetSpace ~
18793 \InsetSpace ~
18794 a,#0xfc\InsetSpace ~
18795 \InsetSpace ~
18796 \InsetSpace ~
18797 \InsetSpace ~
18798 \InsetSpace ~
18799 ;calculate pointer
18800  to the rightmost parameter
18801 \newline
18802 \InsetSpace ~
18803 \InsetSpace ~
18804 \InsetSpace ~
18805 \InsetSpace ~
18806 mov\InsetSpace ~
18807 \InsetSpace ~
18808 r1,a 
18809 \newline
18810 \InsetSpace ~
18811 \InsetSpace ~
18812 \InsetSpace ~
18813 \InsetSpace ~
18814 mov\InsetSpace ~
18815 \InsetSpace ~
18816 a,@r0
18817 \newline
18818 \InsetSpace ~
18819 \InsetSpace ~
18820 \InsetSpace ~
18821 \InsetSpace ~
18822 add\InsetSpace ~
18823 \InsetSpace ~
18824 a,@r1
18825 \newline
18826 \InsetSpace ~
18827 \InsetSpace ~
18828 \InsetSpace ~
18829 \InsetSpace ~
18830 add\InsetSpace ~
18831 \InsetSpace ~
18832 a,r2\InsetSpace ~
18833 \InsetSpace ~
18834 \InsetSpace ~
18835 \InsetSpace ~
18836 \InsetSpace ~
18837 \InsetSpace ~
18838 \InsetSpace ~
18839 \InsetSpace ~
18840 ;calculate the
18841  result (= sum of all three parameters)
18842 \newline
18843 \InsetSpace ~
18844 \InsetSpace ~
18845 \InsetSpace ~
18846 \InsetSpace ~
18847 mov\InsetSpace ~
18848 \InsetSpace ~
18849 dpl,a\InsetSpace ~
18850 \InsetSpace ~
18851 \InsetSpace ~
18852 \InsetSpace ~
18853 \InsetSpace ~
18854 \InsetSpace ~
18855 \InsetSpace ~
18856 ;return value goes into dptr
18857  (cast into int)
18858 \newline
18859 \InsetSpace ~
18860 \InsetSpace ~
18861 \InsetSpace ~
18862 \InsetSpace ~
18863 mov\InsetSpace ~
18864 \InsetSpace ~
18865 dph,#0x00 
18866 \newline
18867 \InsetSpace ~
18868 \InsetSpace ~
18869 \InsetSpace ~
18870 \InsetSpace ~
18871 mov\InsetSpace ~
18872 \InsetSpace ~
18873 sp,_bp 
18874 \newline
18875 \InsetSpace ~
18876 \InsetSpace ~
18877 \InsetSpace ~
18878 \InsetSpace ~
18879 pop\InsetSpace ~
18880 \InsetSpace ~
18881 _bp 
18882 \newline
18883 \InsetSpace ~
18884 \InsetSpace ~
18885 \InsetSpace ~
18886 \InsetSpace ~
18887 ret
18888 \end_layout
18889
18890 \begin_layout Standard
18891 The compiling and linking procedure remains the same, however note the extra
18892  entry & exit linkage required for the assembler code, _bp is the stack
18893  frame pointer and is used to compute the offset into the stack for parameters
18894  and local variables.
18895 \begin_inset VSpace bigskip
18896 \end_inset
18897
18898
18899 \end_layout
18900
18901 \begin_layout Section
18902 int (16 bit)
18903 \begin_inset LatexCommand \index{int (16 bit)}
18904
18905 \end_inset
18906
18907  and long (32 bit)
18908 \begin_inset LatexCommand \index{long (32 bit)}
18909
18910 \end_inset
18911
18912  Support
18913 \end_layout
18914
18915 \begin_layout Standard
18916 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18917  multiplication and modulus operations are implemented by support routines.
18918  These support routines are all developed in ANSI-C to facilitate porting
18919  to other MCUs, although some model specific assembler optimizations are
18920  used.
18921  The following files contain the described routines, all of them can be
18922  found in <installdir>/share/sdcc/lib.
18923 \newline
18924
18925 \end_layout
18926
18927 \begin_layout Standard
18928 \align center
18929 \begin_inset Tabular
18930 <lyxtabular version="3" rows="11" columns="2">
18931 <features>
18932 <column alignment="left" valignment="top" leftline="true" width="0">
18933 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18934 <row topline="true" bottomline="true">
18935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18936 \begin_inset Text
18937
18938 \begin_layout Standard
18939
18940 \series bold
18941 Function
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
18951 \series bold
18952 Description
18953 \end_layout
18954
18955 \end_inset
18956 </cell>
18957 </row>
18958 <row topline="true">
18959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18960 \begin_inset Text
18961
18962 \begin_layout Standard
18963 _mulint.c 
18964 \end_layout
18965
18966 \end_inset
18967 </cell>
18968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18969 \begin_inset Text
18970
18971 \begin_layout Standard
18972 16 bit multiplication
18973 \end_layout
18974
18975 \end_inset
18976 </cell>
18977 </row>
18978 <row topline="true">
18979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18980 \begin_inset Text
18981
18982 \begin_layout Standard
18983 _divsint.c 
18984 \end_layout
18985
18986 \end_inset
18987 </cell>
18988 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18989 \begin_inset Text
18990
18991 \begin_layout Standard
18992  signed 16 bit division (calls _divuint)
18993 \end_layout
18994
18995 \end_inset
18996 </cell>
18997 </row>
18998 <row topline="true">
18999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19000 \begin_inset Text
19001
19002 \begin_layout Standard
19003 _divuint.c 
19004 \end_layout
19005
19006 \end_inset
19007 </cell>
19008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19009 \begin_inset Text
19010
19011 \begin_layout Standard
19012  unsigned 16 bit division
19013 \end_layout
19014
19015 \end_inset
19016 </cell>
19017 </row>
19018 <row topline="true">
19019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19020 \begin_inset Text
19021
19022 \begin_layout Standard
19023 _modsint.c
19024 \end_layout
19025
19026 \end_inset
19027 </cell>
19028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19029 \begin_inset Text
19030
19031 \begin_layout Standard
19032 signed 16 bit modulus (calls _moduint)
19033 \end_layout
19034
19035 \end_inset
19036 </cell>
19037 </row>
19038 <row topline="true">
19039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19040 \begin_inset Text
19041
19042 \begin_layout Standard
19043 _moduint.c
19044 \end_layout
19045
19046 \end_inset
19047 </cell>
19048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19049 \begin_inset Text
19050
19051 \begin_layout Standard
19052 unsigned 16 bit modulus
19053 \end_layout
19054
19055 \end_inset
19056 </cell>
19057 </row>
19058 <row topline="true">
19059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19060 \begin_inset Text
19061
19062 \begin_layout Standard
19063 _mullong.c
19064 \end_layout
19065
19066 \end_inset
19067 </cell>
19068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19069 \begin_inset Text
19070
19071 \begin_layout Standard
19072 32 bit multiplication
19073 \end_layout
19074
19075 \end_inset
19076 </cell>
19077 </row>
19078 <row topline="true">
19079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19080 \begin_inset Text
19081
19082 \begin_layout Standard
19083 _divslong.c 
19084 \end_layout
19085
19086 \end_inset
19087 </cell>
19088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19089 \begin_inset Text
19090
19091 \begin_layout Standard
19092  signed 32 division (calls _divulong)
19093 \end_layout
19094
19095 \end_inset
19096 </cell>
19097 </row>
19098 <row topline="true">
19099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19100 \begin_inset Text
19101
19102 \begin_layout Standard
19103 _divulong.c 
19104 \end_layout
19105
19106 \end_inset
19107 </cell>
19108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19109 \begin_inset Text
19110
19111 \begin_layout Standard
19112 unsigned 32 division
19113 \end_layout
19114
19115 \end_inset
19116 </cell>
19117 </row>
19118 <row topline="true">
19119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19120 \begin_inset Text
19121
19122 \begin_layout Standard
19123 _modslong.c
19124 \end_layout
19125
19126 \end_inset
19127 </cell>
19128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19129 \begin_inset Text
19130
19131 \begin_layout Standard
19132  signed 32 bit modulus (calls _modulong)
19133 \end_layout
19134
19135 \end_inset
19136 </cell>
19137 </row>
19138 <row topline="true" bottomline="true">
19139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19140 \begin_inset Text
19141
19142 \begin_layout Standard
19143 _modulong.c
19144 \end_layout
19145
19146 \end_inset
19147 </cell>
19148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19149 \begin_inset Text
19150
19151 \begin_layout Standard
19152 unsigned 32 bit modulus
19153 \end_layout
19154
19155 \end_inset
19156 </cell>
19157 </row>
19158 </lyxtabular>
19159
19160 \end_inset
19161
19162
19163 \newline
19164
19165 \end_layout
19166
19167 \begin_layout Standard
19168 Since they are compiled as 
19169 \emph on
19170 non-reentrant
19171 \emph default
19172
19173 \begin_inset LatexCommand \index{reentrant}
19174
19175 \end_inset
19176
19177 , interrupt
19178 \begin_inset LatexCommand \index{interrupt}
19179
19180 \end_inset
19181
19182  service routines should not do any of the above operations.
19183  If this is unavoidable then the above routines will need to be compiled
19184  with the 
19185 \emph on
19186 -
19187 \begin_inset ERT
19188 status collapsed
19189
19190 \begin_layout Standard
19191
19192
19193 \backslash
19194 /
19195 \end_layout
19196
19197 \end_inset
19198
19199 -stack-auto
19200 \begin_inset LatexCommand \index{-\/-stack-auto}
19201
19202 \end_inset
19203
19204
19205 \emph default
19206  option, after which the source program will have to be compiled with 
19207 \emph on
19208 -
19209 \begin_inset ERT
19210 status collapsed
19211
19212 \begin_layout Standard
19213
19214
19215 \backslash
19216 /
19217 \end_layout
19218
19219 \end_inset
19220
19221 -int-long-reent
19222 \begin_inset LatexCommand \index{-\/-int-long-reent}
19223
19224 \end_inset
19225
19226
19227 \emph default
19228  option.
19229  Notice that you don't have to call these routines directly.
19230  The compiler will use them automatically every time an integer operation
19231  is required.
19232 \end_layout
19233
19234 \begin_layout Section
19235 Floating Point Support
19236 \begin_inset LatexCommand \index{Floating point support}
19237
19238 \end_inset
19239
19240
19241 \end_layout
19242
19243 \begin_layout Standard
19244 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
19245  The floating point support routines are derived from gcc's floatlib.c and
19246  consist of the following routines:
19247 \newline
19248
19249 \end_layout
19250
19251 \begin_layout Standard
19252 \align center
19253
19254 \size footnotesize
19255 \begin_inset Tabular
19256 <lyxtabular version="3" rows="17" columns="2">
19257 <features>
19258 <column alignment="left" valignment="top" leftline="true" width="0">
19259 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19260 <row topline="true" bottomline="true">
19261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19262 \begin_inset Text
19263
19264 \begin_layout Standard
19265
19266 \family roman
19267 \series medium
19268 \shape up
19269 \size normal
19270 \emph off
19271 \bar no
19272 \noun off
19273 \color none
19274 Function 
19275 \end_layout
19276
19277 \end_inset
19278 </cell>
19279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19280 \begin_inset Text
19281
19282 \begin_layout Standard
19283 Description
19284 \end_layout
19285
19286 \end_inset
19287 </cell>
19288 </row>
19289 <row topline="true">
19290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19291 \begin_inset Text
19292
19293 \begin_layout Standard
19294
19295 \family roman
19296 \series medium
19297 \shape up
19298 \size normal
19299 \emph off
19300 \bar no
19301 \noun off
19302 \color none
19303 _fsadd.c
19304 \end_layout
19305
19306 \end_inset
19307 </cell>
19308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19309 \begin_inset Text
19310
19311 \begin_layout Standard
19312
19313 \family roman
19314 \series medium
19315 \shape up
19316 \size normal
19317 \emph off
19318 \bar no
19319 \noun off
19320 \color none
19321 add floating point numbers
19322 \end_layout
19323
19324 \end_inset
19325 </cell>
19326 </row>
19327 <row topline="true">
19328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19329 \begin_inset Text
19330
19331 \begin_layout Standard
19332
19333 \family roman
19334 \series medium
19335 \shape up
19336 \size normal
19337 \emph off
19338 \bar no
19339 \noun off
19340 \color none
19341 _fssub.c 
19342 \end_layout
19343
19344 \end_inset
19345 </cell>
19346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19347 \begin_inset Text
19348
19349 \begin_layout Standard
19350
19351 \family roman
19352 \series medium
19353 \shape up
19354 \size normal
19355 \emph off
19356 \bar no
19357 \noun off
19358 \color none
19359 subtract floating point numbers 
19360 \end_layout
19361
19362 \end_inset
19363 </cell>
19364 </row>
19365 <row topline="true">
19366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19367 \begin_inset Text
19368
19369 \begin_layout Standard
19370
19371 \family roman
19372 \series medium
19373 \shape up
19374 \size normal
19375 \emph off
19376 \bar no
19377 \noun off
19378 \color none
19379 _fsdiv.c 
19380 \end_layout
19381
19382 \end_inset
19383 </cell>
19384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19385 \begin_inset Text
19386
19387 \begin_layout Standard
19388
19389 \family roman
19390 \series medium
19391 \shape up
19392 \size normal
19393 \emph off
19394 \bar no
19395 \noun off
19396 \color none
19397 divide floating point numbers 
19398 \end_layout
19399
19400 \end_inset
19401 </cell>
19402 </row>
19403 <row topline="true">
19404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19405 \begin_inset Text
19406
19407 \begin_layout Standard
19408
19409 \family roman
19410 \series medium
19411 \shape up
19412 \size normal
19413 \emph off
19414 \bar no
19415 \noun off
19416 \color none
19417 _fsmul.c 
19418 \end_layout
19419
19420 \end_inset
19421 </cell>
19422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19423 \begin_inset Text
19424
19425 \begin_layout Standard
19426
19427 \family roman
19428 \series medium
19429 \shape up
19430 \size normal
19431 \emph off
19432 \bar no
19433 \noun off
19434 \color none
19435 multiply floating point numbers 
19436 \end_layout
19437
19438 \end_inset
19439 </cell>
19440 </row>
19441 <row topline="true">
19442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19443 \begin_inset Text
19444
19445 \begin_layout Standard
19446
19447 \family roman
19448 \series medium
19449 \shape up
19450 \size normal
19451 \emph off
19452 \bar no
19453 \noun off
19454 \color none
19455 _fs2uchar.c
19456 \end_layout
19457
19458 \end_inset
19459 </cell>
19460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19461 \begin_inset Text
19462
19463 \begin_layout Standard
19464
19465 \family roman
19466 \series medium
19467 \shape up
19468 \size normal
19469 \emph off
19470 \bar no
19471 \noun off
19472 \color none
19473 convert floating point to unsigned char
19474 \end_layout
19475
19476 \end_inset
19477 </cell>
19478 </row>
19479 <row topline="true">
19480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19481 \begin_inset Text
19482
19483 \begin_layout Standard
19484
19485 \family roman
19486 \series medium
19487 \shape up
19488 \size normal
19489 \emph off
19490 \bar no
19491 \noun off
19492 \color none
19493 _fs2char.c
19494 \end_layout
19495
19496 \end_inset
19497 </cell>
19498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19499 \begin_inset Text
19500
19501 \begin_layout Standard
19502
19503 \family roman
19504 \series medium
19505 \shape up
19506 \size normal
19507 \emph off
19508 \bar no
19509 \noun off
19510 \color none
19511 convert floating point to signed char
19512 \end_layout
19513
19514 \end_inset
19515 </cell>
19516 </row>
19517 <row topline="true">
19518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19519 \begin_inset Text
19520
19521 \begin_layout Standard
19522
19523 \family roman
19524 \series medium
19525 \shape up
19526 \size normal
19527 \emph off
19528 \bar no
19529 \noun off
19530 \color none
19531 _fs2uint.c
19532 \end_layout
19533
19534 \end_inset
19535 </cell>
19536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19537 \begin_inset Text
19538
19539 \begin_layout Standard
19540
19541 \family roman
19542 \series medium
19543 \shape up
19544 \size normal
19545 \emph off
19546 \bar no
19547 \noun off
19548 \color none
19549 convert floating point to unsigned int
19550 \end_layout
19551
19552 \end_inset
19553 </cell>
19554 </row>
19555 <row topline="true">
19556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19557 \begin_inset Text
19558
19559 \begin_layout Standard
19560
19561 \family roman
19562 \series medium
19563 \shape up
19564 \size normal
19565 \emph off
19566 \bar no
19567 \noun off
19568 \color none
19569 _fs2int.c
19570 \end_layout
19571
19572 \end_inset
19573 </cell>
19574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19575 \begin_inset Text
19576
19577 \begin_layout Standard
19578
19579 \family roman
19580 \series medium
19581 \shape up
19582 \size normal
19583 \emph off
19584 \bar no
19585 \noun off
19586 \color none
19587 convert floating point to signed int
19588 \end_layout
19589
19590 \end_inset
19591 </cell>
19592 </row>
19593 <row topline="true">
19594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19595 \begin_inset Text
19596
19597 \begin_layout Standard
19598
19599 \family roman
19600 \series medium
19601 \shape up
19602 \size normal
19603 \emph off
19604 \bar no
19605 \noun off
19606 \color none
19607 _fs2ulong.
19608 \family default
19609 \series default
19610 \shape default
19611 \size default
19612 \emph default
19613 \bar default
19614 \noun default
19615 c
19616 \end_layout
19617
19618 \end_inset
19619 </cell>
19620 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19621 \begin_inset Text
19622
19623 \begin_layout Standard
19624
19625 \family roman
19626 \series medium
19627 \shape up
19628 \size normal
19629 \emph off
19630 \bar no
19631 \noun off
19632 \color none
19633 convert floating point to unsigned long
19634 \end_layout
19635
19636 \end_inset
19637 </cell>
19638 </row>
19639 <row topline="true">
19640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19641 \begin_inset Text
19642
19643 \begin_layout Standard
19644
19645 \family roman
19646 \series medium
19647 \shape up
19648 \size normal
19649 \emph off
19650 \bar no
19651 \noun off
19652 \color none
19653 _fs2long.c
19654 \end_layout
19655
19656 \end_inset
19657 </cell>
19658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19659 \begin_inset Text
19660
19661 \begin_layout Standard
19662
19663 \family roman
19664 \series medium
19665 \shape up
19666 \size normal
19667 \emph off
19668 \bar no
19669 \noun off
19670 \color none
19671 convert floating point to signed long
19672 \end_layout
19673
19674 \end_inset
19675 </cell>
19676 </row>
19677 <row topline="true">
19678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19679 \begin_inset Text
19680
19681 \begin_layout Standard
19682
19683 \family roman
19684 \series medium
19685 \shape up
19686 \size normal
19687 \emph off
19688 \bar no
19689 \noun off
19690 \color none
19691 _uchar2fs.c
19692 \end_layout
19693
19694 \end_inset
19695 </cell>
19696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19697 \begin_inset Text
19698
19699 \begin_layout Standard
19700
19701 \family roman
19702 \series medium
19703 \shape up
19704 \size normal
19705 \emph off
19706 \bar no
19707 \noun off
19708 \color none
19709 convert unsigned char to floating point
19710 \end_layout
19711
19712 \end_inset
19713 </cell>
19714 </row>
19715 <row topline="true">
19716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19717 \begin_inset Text
19718
19719 \begin_layout Standard
19720
19721 \family roman
19722 \series medium
19723 \shape up
19724 \size normal
19725 \emph off
19726 \bar no
19727 \noun off
19728 \color none
19729 _char2fs.c
19730 \end_layout
19731
19732 \end_inset
19733 </cell>
19734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19735 \begin_inset Text
19736
19737 \begin_layout Standard
19738
19739 \family roman
19740 \series medium
19741 \shape up
19742 \size normal
19743 \emph off
19744 \bar no
19745 \noun off
19746 \color none
19747 convert char to floating point number
19748 \end_layout
19749
19750 \end_inset
19751 </cell>
19752 </row>
19753 <row topline="true">
19754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19755 \begin_inset Text
19756
19757 \begin_layout Standard
19758
19759 \family roman
19760 \series medium
19761 \shape up
19762 \size normal
19763 \emph off
19764 \bar no
19765 \noun off
19766 \color none
19767 _uint2fs.c
19768 \end_layout
19769
19770 \end_inset
19771 </cell>
19772 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19773 \begin_inset Text
19774
19775 \begin_layout Standard
19776
19777 \family roman
19778 \series medium
19779 \shape up
19780 \size normal
19781 \emph off
19782 \bar no
19783 \noun off
19784 \color none
19785 convert unsigned int to floating point
19786 \end_layout
19787
19788 \end_inset
19789 </cell>
19790 </row>
19791 <row topline="true">
19792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19793 \begin_inset Text
19794
19795 \begin_layout Standard
19796
19797 \family roman
19798 \series medium
19799 \shape up
19800 \size normal
19801 \emph off
19802 \bar no
19803 \noun off
19804 \color none
19805 _int2fs.c
19806 \end_layout
19807
19808 \end_inset
19809 </cell>
19810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19811 \begin_inset Text
19812
19813 \begin_layout Standard
19814
19815 \family roman
19816 \series medium
19817 \shape up
19818 \size normal
19819 \emph off
19820 \bar no
19821 \noun off
19822 \color none
19823 convert int to floating point numbers
19824 \end_layout
19825
19826 \end_inset
19827 </cell>
19828 </row>
19829 <row topline="true">
19830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19831 \begin_inset Text
19832
19833 \begin_layout Standard
19834
19835 \family roman
19836 \series medium
19837 \shape up
19838 \size normal
19839 \emph off
19840 \bar no
19841 \noun off
19842 \color none
19843 _ulong2fs.c
19844 \end_layout
19845
19846 \end_inset
19847 </cell>
19848 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19849 \begin_inset Text
19850
19851 \begin_layout Standard
19852
19853 \family roman
19854 \series medium
19855 \shape up
19856 \size normal
19857 \emph off
19858 \bar no
19859 \noun off
19860 \color none
19861 convert unsigned long to floating point number
19862 \end_layout
19863
19864 \end_inset
19865 </cell>
19866 </row>
19867 <row topline="true" bottomline="true">
19868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19869 \begin_inset Text
19870
19871 \begin_layout Standard
19872
19873 \family roman
19874 \series medium
19875 \shape up
19876 \size normal
19877 \emph off
19878 \bar no
19879 \noun off
19880 \color none
19881 _long2fs.c
19882 \end_layout
19883
19884 \end_inset
19885 </cell>
19886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19887 \begin_inset Text
19888
19889 \begin_layout Standard
19890
19891 \family roman
19892 \series medium
19893 \shape up
19894 \size normal
19895 \emph off
19896 \bar no
19897 \noun off
19898 \color none
19899 convert long to floating point number
19900 \end_layout
19901
19902 \end_inset
19903 </cell>
19904 </row>
19905 </lyxtabular>
19906
19907 \end_inset
19908
19909
19910 \newline
19911
19912 \end_layout
19913
19914 \begin_layout Standard
19915 These support routines are developed in ANSI-C so there is room for space
19916  and speed improvement
19917 \begin_inset Foot
19918 status open
19919
19920 \begin_layout Standard
19921 These floating point routines (
19922 \emph on
19923 not
19924 \emph default
19925  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19926  
19927 \end_layout
19928
19929 \end_inset
19930
19931 .
19932  Note if all these routines are used simultaneously the data space might
19933  overflow.
19934  For serious floating point usage the large model might be needed.
19935  Also notice that you don't have to call this routines directly.
19936  The compiler will use them automatically every time a floating point operation
19937  is required.
19938 \begin_inset VSpace bigskip
19939 \end_inset
19940
19941
19942 \end_layout
19943
19944 \begin_layout Section
19945 Library Routines
19946 \begin_inset LatexCommand \index{Libraries}
19947
19948 \end_inset
19949
19950
19951 \end_layout
19952
19953 \begin_layout Standard
19954
19955 \emph on
19956 <pending: this is messy and incomplete - a little more information is in
19957  sdcc/doc/libdoc.txt
19958 \emph default
19959  >
19960 \end_layout
19961
19962 \begin_layout Subsection
19963 Compiler support routines (_gptrget, _mulint etc.)
19964 \end_layout
19965
19966 \begin_layout Subsection
19967 Stdclib functions (puts, printf, strcat etc.)
19968 \end_layout
19969
19970 \begin_layout Subsubsection
19971 <stdio.h>
19972 \end_layout
19973
19974 \begin_layout Paragraph
19975 getchar(), putchar()
19976 \end_layout
19977
19978 \begin_layout Standard
19979 \begin_inset LatexCommand \index{<stdio.h>}
19980
19981 \end_inset
19982
19983 As usual on embedded systems you have to provide your own 
19984 \family typewriter
19985 getchar()
19986 \begin_inset LatexCommand \index{getchar()}
19987
19988 \end_inset
19989
19990  
19991 \family default
19992 and 
19993 \family typewriter
19994 putchar()
19995 \begin_inset LatexCommand \index{putchar()}
19996
19997 \end_inset
19998
19999
20000 \family default
20001  routines.
20002  SDCC does not know whether the system connects to a serial line with or
20003  without handshake, LCD, keyboard or other device.
20004  And whether a 
20005 \family typewriter
20006 lf
20007 \family default
20008  to 
20009 \family typewriter
20010 crlf
20011 \family default
20012  conversion within 
20013 \family typewriter
20014 putchar()
20015 \family default
20016  is intended.
20017  You'll find examples for serial routines f.e.
20018  in sdcc/device/lib.
20019  For the mcs51 this minimalistic polling 
20020 \family typewriter
20021 putchar()
20022 \family default
20023  routine might be a start:
20024 \end_layout
20025
20026 \begin_layout Verse
20027
20028 \family typewriter
20029 void putchar (char c) { 
20030 \newline
20031 \InsetSpace ~
20032 \InsetSpace ~
20033 \InsetSpace ~
20034 \InsetSpace ~
20035 while (!TI)\InsetSpace ~
20036 \InsetSpace ~
20037 \InsetSpace ~
20038  /* assumes UART is initialized */
20039 \newline
20040 \InsetSpace ~
20041 \InsetSpace ~
20042 \InsetSpace ~
20043 \InsetSpace ~
20044 \InsetSpace ~
20045 \InsetSpace ~
20046 \InsetSpace ~
20047 \InsetSpace ~
20048 ;
20049 \newline
20050 \InsetSpace ~
20051 \InsetSpace ~
20052 \InsetSpace ~
20053 \InsetSpace ~
20054 TI
20055  = 0;
20056 \newline
20057 \InsetSpace ~
20058 \InsetSpace ~
20059 \InsetSpace ~
20060 \InsetSpace ~
20061 SBUF = c;
20062 \newline
20063 }
20064 \end_layout
20065
20066 \begin_layout Paragraph
20067 printf()
20068 \end_layout
20069
20070 \begin_layout Standard
20071 The default
20072 \family typewriter
20073  printf()
20074 \begin_inset LatexCommand \index{printf()}
20075
20076 \end_inset
20077
20078
20079 \family default
20080  implementation in
20081 \family typewriter
20082  printf_large.c
20083 \family default
20084  does not support float (except on ds390).
20085  To enable this recompile it with the option 
20086 \emph on
20087 -
20088 \begin_inset ERT
20089 status collapsed
20090
20091 \begin_layout Standard
20092
20093
20094 \backslash
20095 /
20096 \end_layout
20097
20098 \end_inset
20099
20100 DUSE_FLOATS=1
20101 \begin_inset LatexCommand \index{USE\_FLOATS}
20102
20103 \end_inset
20104
20105
20106 \emph default
20107  on the command line.
20108  Use
20109 \emph on
20110  -
20111 \begin_inset ERT
20112 status collapsed
20113
20114 \begin_layout Standard
20115
20116
20117 \backslash
20118 /
20119 \end_layout
20120
20121 \end_inset
20122
20123 -model-large
20124 \begin_inset LatexCommand \index{-\/-model-large}
20125
20126 \end_inset
20127
20128
20129 \emph default
20130  for the mcs51 port, since this uses a lot of memory.
20131 \end_layout
20132
20133 \begin_layout Standard
20134 If you're short on code memory you might want to use 
20135 \family typewriter
20136 printf_small()
20137 \begin_inset LatexCommand \index{printf\_small()}
20138
20139 \end_inset
20140
20141
20142 \family default
20143  
20144 \emph on
20145 instead
20146 \emph default
20147  of
20148 \family typewriter
20149  printf().
20150
20151 \family default
20152  For the mcs51 there additionally are assembly versions 
20153 \family typewriter
20154 printf_tiny()
20155 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
20156
20157 \end_inset
20158
20159
20160 \family default
20161  (subset of printf using less than 270 bytes) and 
20162 \family typewriter
20163 printf_fast()
20164 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
20165
20166 \end_inset
20167
20168  
20169 \family default
20170 and
20171 \family typewriter
20172  printf_fast_f()
20173 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
20174
20175 \end_inset
20176
20177
20178 \family default
20179  (floating-point aware version of printf_fast) which should fit the requirements
20180  of many embedded systems (printf_fast() can be customized by unsetting
20181  #defines to 
20182 \emph on
20183 not
20184 \emph default
20185  support long variables and field widths).
20186  Be sure to use only one of these printf options within a project.
20187 \newline
20188
20189 \end_layout
20190
20191 \begin_layout Standard
20192 Feature matrix of different 
20193 \emph on
20194 printf
20195 \emph default
20196  options on mcs51.
20197 \end_layout
20198
20199 \begin_layout Standard
20200 \begin_inset Tabular
20201 <lyxtabular version="3" rows="14" columns="7">
20202 <features islongtable="true">
20203 <column alignment="left" valignment="middle" leftline="true" width="14col%">
20204 <column alignment="center" valignment="top" leftline="true" width="0">
20205 <column alignment="center" valignment="top" leftline="true" width="12col%">
20206 <column alignment="center" valignment="top" leftline="true" width="10col%">
20207 <column alignment="center" valignment="top" leftline="true" width="0">
20208 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
20209 <column alignment="center" valignment="top" rightline="true" width="0">
20210 <row topline="true" bottomline="true" endhead="true">
20211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20212 \begin_inset Text
20213
20214 \begin_layout Standard
20215
20216 \series bold
20217 \size large
20218 mcs51
20219 \end_layout
20220
20221 \end_inset
20222 </cell>
20223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20224 \begin_inset Text
20225
20226 \begin_layout Standard
20227 printf
20228 \begin_inset LatexCommand \index{printf}
20229
20230 \end_inset
20231
20232
20233 \end_layout
20234
20235 \end_inset
20236 </cell>
20237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20238 \begin_inset Text
20239
20240 \begin_layout Standard
20241 printf 
20242 \size scriptsize
20243 USE_FLOATS=1
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 printf_small
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 printf_fast
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 printf_fast_f
20271 \end_layout
20272
20273 \end_inset
20274 </cell>
20275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20276 \begin_inset Text
20277
20278 \begin_layout Standard
20279 printf_tiny
20280 \end_layout
20281
20282 \end_inset
20283 </cell>
20284 </row>
20285 <row topline="true" endhead="true">
20286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20287 \begin_inset Text
20288
20289 \begin_layout Standard
20290 filename
20291 \end_layout
20292
20293 \end_inset
20294 </cell>
20295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20296 \begin_inset Text
20297
20298 \begin_layout Standard
20299
20300 \size scriptsize
20301 printf_large.c
20302 \end_layout
20303
20304 \end_inset
20305 </cell>
20306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20307 \begin_inset Text
20308
20309 \begin_layout Standard
20310
20311 \size scriptsize
20312 printf_large.c
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
20322 \size scriptsize
20323 printfl.c
20324 \end_layout
20325
20326 \end_inset
20327 </cell>
20328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20329 \begin_inset Text
20330
20331 \begin_layout Standard
20332
20333 \size scriptsize
20334 printf_fast.c
20335 \end_layout
20336
20337 \end_inset
20338 </cell>
20339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20340 \begin_inset Text
20341
20342 \begin_layout Standard
20343
20344 \size scriptsize
20345 printf_fast_f.c
20346 \end_layout
20347
20348 \end_inset
20349 </cell>
20350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20351 \begin_inset Text
20352
20353 \begin_layout Standard
20354
20355 \size scriptsize
20356 printf_tiny.c
20357 \end_layout
20358
20359 \end_inset
20360 </cell>
20361 </row>
20362 <row topline="true" endhead="true">
20363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20364 \begin_inset Text
20365
20366 \begin_layout Standard
20367 \begin_inset Quotes sld
20368 \end_inset
20369
20370 Hello World
20371 \begin_inset Quotes srd
20372 \end_inset
20373
20374  size
20375 \end_layout
20376
20377 \begin_layout Standard
20378 small / large
20379 \end_layout
20380
20381 \end_inset
20382 </cell>
20383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20384 \begin_inset Text
20385
20386 \begin_layout Standard
20387 1.7k / 2.4k
20388 \end_layout
20389
20390 \end_inset
20391 </cell>
20392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20393 \begin_inset Text
20394
20395 \begin_layout Standard
20396 4.3k / 5.6k
20397 \end_layout
20398
20399 \end_inset
20400 </cell>
20401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20402 \begin_inset Text
20403
20404 \begin_layout Standard
20405 1.2k / 1.8k
20406 \end_layout
20407
20408 \end_inset
20409 </cell>
20410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20411 \begin_inset Text
20412
20413 \begin_layout Standard
20414 1.3k / 1.3k
20415 \end_layout
20416
20417 \end_inset
20418 </cell>
20419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20420 \begin_inset Text
20421
20422 \begin_layout Standard
20423 1.9k / 1.9k
20424 \end_layout
20425
20426 \end_inset
20427 </cell>
20428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20429 \begin_inset Text
20430
20431 \begin_layout Standard
20432 0.44k / 0.44k
20433 \end_layout
20434
20435 \end_inset
20436 </cell>
20437 </row>
20438 <row topline="true" endhead="true">
20439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20440 \begin_inset Text
20441
20442 \begin_layout Standard
20443 code size
20444 \end_layout
20445
20446 \begin_layout Standard
20447 small / large
20448 \end_layout
20449
20450 \end_inset
20451 </cell>
20452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20453 \begin_inset Text
20454
20455 \begin_layout Standard
20456 1.4k / 2.0k
20457 \end_layout
20458
20459 \end_inset
20460 </cell>
20461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20462 \begin_inset Text
20463
20464 \begin_layout Standard
20465 2.8k / 3.7k
20466 \end_layout
20467
20468 \end_inset
20469 </cell>
20470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20471 \begin_inset Text
20472
20473 \begin_layout Standard
20474 0.45k / 0.47k (+ _ltoa)
20475 \end_layout
20476
20477 \end_inset
20478 </cell>
20479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20480 \begin_inset Text
20481
20482 \begin_layout Standard
20483 1.2k / 1.2k
20484 \end_layout
20485
20486 \end_inset
20487 </cell>
20488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20489 \begin_inset Text
20490
20491 \begin_layout Standard
20492 1.6k / 1.6k
20493 \end_layout
20494
20495 \end_inset
20496 </cell>
20497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20498 \begin_inset Text
20499
20500 \begin_layout Standard
20501 0.26k / 0.26k
20502 \end_layout
20503
20504 \end_inset
20505 </cell>
20506 </row>
20507 <row topline="true">
20508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20509 \begin_inset Text
20510
20511 \begin_layout Standard
20512 formats
20513 \end_layout
20514
20515 \end_inset
20516 </cell>
20517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20518 \begin_inset Text
20519
20520 \begin_layout Standard
20521 cdi
20522 \emph on
20523 o
20524 \emph default
20525 psux
20526 \end_layout
20527
20528 \end_inset
20529 </cell>
20530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20531 \begin_inset Text
20532
20533 \begin_layout Standard
20534
20535 \family roman
20536 \series medium
20537 \shape up
20538 \size normal
20539 \emph off
20540 \bar no
20541 \noun off
20542 \color none
20543 cd
20544 \family default
20545 \series default
20546 \shape default
20547 \size default
20548 \emph default
20549 \bar default
20550 \noun default
20551 f
20552 \family roman
20553 \series medium
20554 \shape up
20555 \size normal
20556 \emph off
20557 \bar no
20558 \noun off
20559 i
20560 \family default
20561 \series default
20562 \shape default
20563 \size default
20564 \emph on
20565 \bar default
20566 \noun default
20567 o
20568 \family roman
20569 \series medium
20570 \shape up
20571 \size normal
20572 \emph off
20573 \bar no
20574 \noun off
20575 psux
20576 \end_layout
20577
20578 \end_inset
20579 </cell>
20580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20581 \begin_inset Text
20582
20583 \begin_layout Standard
20584 c
20585 \family roman
20586 \series medium
20587 \shape up
20588 \size normal
20589 \emph off
20590 \bar no
20591 \noun off
20592 \color none
20593 d
20594 \family default
20595 \series default
20596 \shape default
20597 \size default
20598 \emph on
20599 \bar default
20600 \noun default
20601 o
20602 \family roman
20603 \series medium
20604 \shape up
20605 \size normal
20606 \emph off
20607 \bar no
20608 \noun off
20609 s
20610 \family default
20611 \series default
20612 \shape default
20613 \size default
20614 \emph default
20615 \bar default
20616 \noun default
20617 x
20618 \end_layout
20619
20620 \end_inset
20621 </cell>
20622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20623 \begin_inset Text
20624
20625 \begin_layout Standard
20626 cdsux
20627 \end_layout
20628
20629 \end_inset
20630 </cell>
20631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20632 \begin_inset Text
20633
20634 \begin_layout Standard
20635 cdfsux
20636 \end_layout
20637
20638 \end_inset
20639 </cell>
20640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20641 \begin_inset Text
20642
20643 \begin_layout Standard
20644 cdsux
20645 \end_layout
20646
20647 \end_inset
20648 </cell>
20649 </row>
20650 <row topline="true">
20651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20652 \begin_inset Text
20653
20654 \begin_layout Standard
20655 long (32 bit) support
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 x
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 x
20674 \end_layout
20675
20676 \end_inset
20677 </cell>
20678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20679 \begin_inset Text
20680
20681 \begin_layout Standard
20682 x
20683 \end_layout
20684
20685 \end_inset
20686 </cell>
20687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20688 \begin_inset Text
20689
20690 \begin_layout Standard
20691 x
20692 \end_layout
20693
20694 \end_inset
20695 </cell>
20696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20697 \begin_inset Text
20698
20699 \begin_layout Standard
20700
20701 \family roman
20702 \series medium
20703 \shape up
20704 \size normal
20705 \emph off
20706 \bar no
20707 \noun off
20708 \color none
20709 x
20710 \end_layout
20711
20712 \end_inset
20713 </cell>
20714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20715 \begin_inset Text
20716
20717 \begin_layout Standard
20718 -
20719 \end_layout
20720
20721 \end_inset
20722 </cell>
20723 </row>
20724 <row topline="true">
20725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20726 \begin_inset Text
20727
20728 \begin_layout Standard
20729 byte arguments on stack
20730 \end_layout
20731
20732 \end_inset
20733 </cell>
20734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20735 \begin_inset Text
20736
20737 \begin_layout Standard
20738 b
20739 \end_layout
20740
20741 \end_inset
20742 </cell>
20743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20744 \begin_inset Text
20745
20746 \begin_layout Standard
20747 b
20748 \end_layout
20749
20750 \end_inset
20751 </cell>
20752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20753 \begin_inset Text
20754
20755 \begin_layout Standard
20756 -
20757 \end_layout
20758
20759 \end_inset
20760 </cell>
20761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20762 \begin_inset Text
20763
20764 \begin_layout Standard
20765 -
20766 \end_layout
20767
20768 \end_inset
20769 </cell>
20770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20771 \begin_inset Text
20772
20773 \begin_layout Standard
20774 -
20775 \end_layout
20776
20777 \end_inset
20778 </cell>
20779 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20780 \begin_inset Text
20781
20782 \begin_layout Standard
20783 -
20784 \end_layout
20785
20786 \end_inset
20787 </cell>
20788 </row>
20789 <row topline="true">
20790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20791 \begin_inset Text
20792
20793 \begin_layout Standard
20794 float format
20795 \begin_inset LatexCommand \index{Floating point support}
20796
20797 \end_inset
20798
20799
20800 \end_layout
20801
20802 \end_inset
20803 </cell>
20804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20805 \begin_inset Text
20806
20807 \begin_layout Standard
20808 -
20809 \end_layout
20810
20811 \end_inset
20812 </cell>
20813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20814 \begin_inset Text
20815
20816 \begin_layout Standard
20817 %f
20818 \end_layout
20819
20820 \end_inset
20821 </cell>
20822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20823 \begin_inset Text
20824
20825 \begin_layout Standard
20826 -
20827 \end_layout
20828
20829 \end_inset
20830 </cell>
20831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20832 \begin_inset Text
20833
20834 \begin_layout Standard
20835 -
20836 \end_layout
20837
20838 \end_inset
20839 </cell>
20840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20841 \begin_inset Text
20842
20843 \begin_layout Standard
20844 %f
20845 \begin_inset Foot
20846 status collapsed
20847
20848 \begin_layout Standard
20849 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20850 \end_layout
20851
20852 \end_inset
20853
20854
20855 \end_layout
20856
20857 \end_inset
20858 </cell>
20859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20860 \begin_inset Text
20861
20862 \begin_layout Standard
20863 -
20864 \end_layout
20865
20866 \end_inset
20867 </cell>
20868 </row>
20869 <row topline="true">
20870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20871 \begin_inset Text
20872
20873 \begin_layout Standard
20874 float formats %e %g
20875 \end_layout
20876
20877 \end_inset
20878 </cell>
20879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20880 \begin_inset Text
20881
20882 \begin_layout Standard
20883 -
20884 \end_layout
20885
20886 \end_inset
20887 </cell>
20888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20889 \begin_inset Text
20890
20891 \begin_layout Standard
20892 -
20893 \end_layout
20894
20895 \end_inset
20896 </cell>
20897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20898 \begin_inset Text
20899
20900 \begin_layout Standard
20901 -
20902 \end_layout
20903
20904 \end_inset
20905 </cell>
20906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20907 \begin_inset Text
20908
20909 \begin_layout Standard
20910 -
20911 \end_layout
20912
20913 \end_inset
20914 </cell>
20915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20916 \begin_inset Text
20917
20918 \begin_layout Standard
20919 -
20920 \end_layout
20921
20922 \end_inset
20923 </cell>
20924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20925 \begin_inset Text
20926
20927 \begin_layout Standard
20928 -
20929 \end_layout
20930
20931 \end_inset
20932 </cell>
20933 </row>
20934 <row topline="true" bottomline="true">
20935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20936 \begin_inset Text
20937
20938 \begin_layout Standard
20939 field width
20940 \end_layout
20941
20942 \end_inset
20943 </cell>
20944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20945 \begin_inset Text
20946
20947 \begin_layout Standard
20948 x
20949 \end_layout
20950
20951 \end_inset
20952 </cell>
20953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20954 \begin_inset Text
20955
20956 \begin_layout Standard
20957 x
20958 \end_layout
20959
20960 \end_inset
20961 </cell>
20962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20963 \begin_inset Text
20964
20965 \begin_layout Standard
20966 -
20967 \end_layout
20968
20969 \end_inset
20970 </cell>
20971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20972 \begin_inset Text
20973
20974 \begin_layout Standard
20975 x
20976 \end_layout
20977
20978 \end_inset
20979 </cell>
20980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20981 \begin_inset Text
20982
20983 \begin_layout Standard
20984 x
20985 \end_layout
20986
20987 \end_inset
20988 </cell>
20989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20990 \begin_inset Text
20991
20992 \begin_layout Standard
20993 -
20994 \end_layout
20995
20996 \end_inset
20997 </cell>
20998 </row>
20999 <row bottomline="true">
21000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21001 \begin_inset Text
21002
21003 \begin_layout Standard
21004 string speed
21005 \begin_inset Foot
21006 status collapsed
21007
21008 \begin_layout Standard
21009 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
21010 \backslash
21011 r', '
21012 \backslash
21013 n'); standard 8051 @ 22.1184 MHz, empty putchar()
21014 \end_layout
21015
21016 \end_inset
21017
21018 ,
21019 \end_layout
21020
21021 \begin_layout Standard
21022 small / large
21023 \end_layout
21024
21025 \end_inset
21026 </cell>
21027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21028 \begin_inset Text
21029
21030 \begin_layout Standard
21031 1.52 / 2.59 ms
21032 \end_layout
21033
21034 \end_inset
21035 </cell>
21036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21037 \begin_inset Text
21038
21039 \begin_layout Standard
21040 1.53 / 2.62 ms
21041 \end_layout
21042
21043 \end_inset
21044 </cell>
21045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21046 \begin_inset Text
21047
21048 \begin_layout Standard
21049 0.92 / 0.93 ms
21050 \end_layout
21051
21052 \end_inset
21053 </cell>
21054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21055 \begin_inset Text
21056
21057 \begin_layout Standard
21058 0.45 / 0.45 ms
21059 \end_layout
21060
21061 \end_inset
21062 </cell>
21063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21064 \begin_inset Text
21065
21066 \begin_layout Standard
21067 0.46 / 0.46 ms
21068 \end_layout
21069
21070 \end_inset
21071 </cell>
21072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21073 \begin_inset Text
21074
21075 \begin_layout Standard
21076 0.45 / 0.45 ms
21077 \end_layout
21078
21079 \end_inset
21080 </cell>
21081 </row>
21082 <row bottomline="true">
21083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21084 \begin_inset Text
21085
21086 \begin_layout Standard
21087 int speed
21088 \begin_inset Foot
21089 status collapsed
21090
21091 \begin_layout Standard
21092 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
21093  putchar()
21094 \end_layout
21095
21096 \end_inset
21097
21098 ,
21099 \end_layout
21100
21101 \begin_layout Standard
21102 small / large
21103 \end_layout
21104
21105 \end_inset
21106 </cell>
21107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21108 \begin_inset Text
21109
21110 \begin_layout Standard
21111 3.01 / 3.61 ms
21112 \end_layout
21113
21114 \end_inset
21115 </cell>
21116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21117 \begin_inset Text
21118
21119 \begin_layout Standard
21120 3.01 / 3.61 ms
21121 \end_layout
21122
21123 \end_inset
21124 </cell>
21125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21126 \begin_inset Text
21127
21128 \begin_layout Standard
21129 3.51 / 18.13 ms
21130 \end_layout
21131
21132 \end_inset
21133 </cell>
21134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21135 \begin_inset Text
21136
21137 \begin_layout Standard
21138 0.22 / 0.22 ms
21139 \end_layout
21140
21141 \end_inset
21142 </cell>
21143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21144 \begin_inset Text
21145
21146 \begin_layout Standard
21147 0.23 / 0.23 ms
21148 \end_layout
21149
21150 \end_inset
21151 </cell>
21152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21153 \begin_inset Text
21154
21155 \begin_layout Standard
21156 0.25 / 0.25 ms
21157 \begin_inset Foot
21158 status collapsed
21159
21160 \begin_layout Standard
21161 printf_tiny integer speed is data dependent, worst case is 0.33 ms
21162 \end_layout
21163
21164 \end_inset
21165
21166
21167 \end_layout
21168
21169 \end_inset
21170 </cell>
21171 </row>
21172 <row bottomline="true">
21173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21174 \begin_inset Text
21175
21176 \begin_layout Standard
21177 long speed
21178 \begin_inset Foot
21179 status collapsed
21180
21181 \begin_layout Standard
21182 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
21183  empty putchar()
21184 \end_layout
21185
21186 \end_inset
21187
21188 ,
21189 \end_layout
21190
21191 \begin_layout Standard
21192 small / large
21193 \end_layout
21194
21195 \end_inset
21196 </cell>
21197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21198 \begin_inset Text
21199
21200 \begin_layout Standard
21201 5.37 / 6.31 ms
21202 \end_layout
21203
21204 \end_inset
21205 </cell>
21206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21207 \begin_inset Text
21208
21209 \begin_layout Standard
21210 5.37 / 6.31 ms
21211 \end_layout
21212
21213 \end_inset
21214 </cell>
21215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21216 \begin_inset Text
21217
21218 \begin_layout Standard
21219 8.71 / 40.65 ms
21220 \end_layout
21221
21222 \end_inset
21223 </cell>
21224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21225 \begin_inset Text
21226
21227 \begin_layout Standard
21228 0.40 / 0.40 ms
21229 \end_layout
21230
21231 \end_inset
21232 </cell>
21233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21234 \begin_inset Text
21235
21236 \begin_layout Standard
21237 0.40 / 0.40 ms
21238 \end_layout
21239
21240 \end_inset
21241 </cell>
21242 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21243 \begin_inset Text
21244
21245 \begin_layout Standard
21246 -
21247 \end_layout
21248
21249 \end_inset
21250 </cell>
21251 </row>
21252 <row bottomline="true">
21253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21254 \begin_inset Text
21255
21256 \begin_layout Standard
21257 float speed
21258 \begin_inset Foot
21259 status collapsed
21260
21261 \begin_layout Standard
21262 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
21263  empty putchar()
21264 \end_layout
21265
21266 \end_inset
21267
21268 ,
21269 \end_layout
21270
21271 \begin_layout Standard
21272 small / large
21273 \end_layout
21274
21275 \end_inset
21276 </cell>
21277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21278 \begin_inset Text
21279
21280 \begin_layout Standard
21281 -
21282 \end_layout
21283
21284 \end_inset
21285 </cell>
21286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21287 \begin_inset Text
21288
21289 \begin_layout Standard
21290 7.49 / 22.47 ms
21291 \end_layout
21292
21293 \end_inset
21294 </cell>
21295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21296 \begin_inset Text
21297
21298 \begin_layout Standard
21299 -
21300 \end_layout
21301
21302 \end_inset
21303 </cell>
21304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21305 \begin_inset Text
21306
21307 \begin_layout Standard
21308 -
21309 \end_layout
21310
21311 \end_inset
21312 </cell>
21313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21314 \begin_inset Text
21315
21316 \begin_layout Standard
21317 1.04 / 1.04 ms
21318 \end_layout
21319
21320 \end_inset
21321 </cell>
21322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21323 \begin_inset Text
21324
21325 \begin_layout Standard
21326 -
21327 \end_layout
21328
21329 \end_inset
21330 </cell>
21331 </row>
21332 </lyxtabular>
21333
21334 \end_inset
21335
21336
21337 \end_layout
21338
21339 \begin_layout Subsubsection
21340 <malloc.h>
21341 \begin_inset LatexCommand \index{malloc.h}
21342
21343 \end_inset
21344
21345
21346 \end_layout
21347
21348 \begin_layout Standard
21349 As of SDCC 2.6.2 you no longer need to call an initialization routine before
21350  using dynamic memory allocation
21351 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
21352
21353 \end_inset
21354
21355  and a default heap
21356 \begin_inset LatexCommand \index{heap (malloc)}
21357
21358 \end_inset
21359
21360  space of 1024 bytes is provided for malloc to allocate memory from.
21361  If you need a different heap size you need to recompile _heap.c with the
21362  required size defined in HEAP_SIZE.
21363  It is recommended to make a copy of this file into your project directory
21364  and compile it there with:
21365 \end_layout
21366
21367 \begin_layout Verse
21368
21369 \family typewriter
21370 sdcc -c _heap.c -D HEAD_SIZE=2048
21371 \end_layout
21372
21373 \begin_layout Standard
21374 And then link it with:
21375 \end_layout
21376
21377 \begin_layout Verse
21378
21379 \family typewriter
21380 sdcc main.rel _heap.rel
21381 \end_layout
21382
21383 \begin_layout Subsection
21384 Math functions (sinf, powf, sqrtf etc.)
21385 \end_layout
21386
21387 \begin_layout Subsubsection
21388 <math.h>
21389 \end_layout
21390
21391 \begin_layout Standard
21392 See definitions in file <math.h>.
21393 \end_layout
21394
21395 \begin_layout Subsection
21396 Other libraries
21397 \end_layout
21398
21399 \begin_layout Standard
21400 Libraries
21401 \begin_inset LatexCommand \index{Libraries}
21402
21403 \end_inset
21404
21405  included in SDCC should have a license at least as liberal as the GNU Lesser
21406  General Public License
21407 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
21408
21409 \end_inset
21410
21411  
21412 \emph on
21413 LGPL
21414 \emph default
21415 .
21416 \end_layout
21417
21418 \begin_layout Standard
21419 \begin_inset Note Note
21420 status collapsed
21421
21422 \begin_layout Standard
21423 license statements for the libraries are missing.
21424  sdcc/device/lib/ser_ir.c
21425 \end_layout
21426
21427 \begin_layout Standard
21428 or _decdptr f.e.
21429  come with a GPL (as opposed to LGPL) License - this will not be liberal
21430  enough for many embedded programmers.
21431 \end_layout
21432
21433 \end_inset
21434
21435
21436 \end_layout
21437
21438 \begin_layout Standard
21439 If you have ported some library or want to share experience about some code
21440  which f.e.
21441  falls into any of these categories Busses (I
21442 \begin_inset Formula $^{\textrm{2}}$
21443 \end_inset
21444
21445 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
21446  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
21447  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
21448 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
21449
21450 \end_inset
21451
21452 \InsetSpace ~
21453 would certainly like to hear about it.
21454 \end_layout
21455
21456 \begin_layout Standard
21457 Programmers coding for embedded systems are not especially famous for being
21458  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
21459 e these references are very valuable.
21460  Let's help to create a climate where information is shared.
21461 \begin_inset VSpace bigskip
21462 \end_inset
21463
21464
21465 \end_layout
21466
21467 \begin_layout Section
21468 Memory Models
21469 \end_layout
21470
21471 \begin_layout Subsection
21472 MCS51 Memory Models
21473 \begin_inset LatexCommand \index{Memory model}
21474
21475 \end_inset
21476
21477
21478 \begin_inset LatexCommand \index{MCS51 memory model}
21479
21480 \end_inset
21481
21482
21483 \end_layout
21484
21485 \begin_layout Subsubsection
21486 Small, Medium and Large
21487 \end_layout
21488
21489 \begin_layout Standard
21490 SDCC allows three memory models for MCS51 code, 
21491 \shape slanted
21492 small, medium
21493 \shape default
21494  and 
21495 \shape slanted
21496 large
21497 \shape default
21498 .
21499  Modules compiled with different memory models should 
21500 \emph on
21501 never
21502 \emph default
21503  be combined together or the results would be unpredictable.
21504  The library routines supplied with the compiler are compiled as small,
21505  medium and large.
21506  The compiled library modules are contained in separate directories as small,
21507  medium and large so that you can link to the appropriate set.
21508 \end_layout
21509
21510 \begin_layout Standard
21511 When the medium or large model is used all variables declared without a
21512  storage class will be allocated into the external ram, this includes all
21513  parameters and local variables (for non-reentrant
21514 \begin_inset LatexCommand \index{reentrant}
21515
21516 \end_inset
21517
21518  functions).
21519  When the small model is used variables without storage class are allocated
21520  in the internal ram.
21521 \end_layout
21522
21523 \begin_layout Standard
21524 Judicious usage of the processor specific storage classes
21525 \begin_inset LatexCommand \index{Storage class}
21526
21527 \end_inset
21528
21529  and the 'reentrant' function type will yield much more efficient code,
21530  than using the large model.
21531  Several optimizations are disabled when the program is compiled using the
21532  large model, it is therefore recommended that the small model be used unless
21533  absolutely required.
21534 \end_layout
21535
21536 \begin_layout Subsubsection
21537 External Stack
21538 \begin_inset LatexCommand \label{sub:External-Stack}
21539
21540 \end_inset
21541
21542
21543 \begin_inset LatexCommand \index{stack}
21544
21545 \end_inset
21546
21547
21548 \begin_inset LatexCommand \index{External stack (mcs51)}
21549
21550 \end_inset
21551
21552
21553 \end_layout
21554
21555 \begin_layout Standard
21556 The external stack (-
21557 \begin_inset ERT
21558 status collapsed
21559
21560 \begin_layout Standard
21561
21562
21563 \backslash
21564 /
21565 \end_layout
21566
21567 \end_inset
21568
21569 -xstack option
21570 \begin_inset LatexCommand \index{-\/-xstack}
21571
21572 \end_inset
21573
21574 ) is located in pdata
21575 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
21576
21577 \end_inset
21578
21579  memory (usually at the start of the external ram segment) and uses all
21580  unused space in pdata (max.
21581  256 bytes).
21582  When -
21583 \begin_inset ERT
21584 status collapsed
21585
21586 \begin_layout Standard
21587
21588
21589 \backslash
21590 /
21591 \end_layout
21592
21593 \end_inset
21594
21595 -xstack option is used to compile the program, the parameters and local
21596  variables
21597 \begin_inset LatexCommand \index{local variables}
21598
21599 \end_inset
21600
21601  of all reentrant functions are allocated in this area.
21602  This option is provided for programs with large stack space requirements.
21603  When used with the -
21604 \begin_inset ERT
21605 status collapsed
21606
21607 \begin_layout Standard
21608
21609
21610 \backslash
21611 /
21612 \end_layout
21613
21614 \end_inset
21615
21616 -stack-auto
21617 \begin_inset LatexCommand \index{-\/-stack-auto}
21618
21619 \end_inset
21620
21621  option, all parameters and local variables are allocated on the external
21622  stack (note: support libraries will need to be recompiled with the same
21623  options.
21624  There is a predefined target in the library makefile).
21625 \end_layout
21626
21627 \begin_layout Standard
21628 The compiler outputs the higher order address byte of the external ram segment
21629  into port P2
21630 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21631
21632 \end_inset
21633
21634  (see also section 
21635 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21636
21637 \end_inset
21638
21639 ), therefore when using the External Stack option, this port 
21640 \emph on
21641 may not
21642 \emph default
21643  be used by the application program.
21644 \end_layout
21645
21646 \begin_layout Subsection
21647 DS390 Memory Model
21648 \begin_inset LatexCommand \index{Memory model}
21649
21650 \end_inset
21651
21652
21653 \begin_inset LatexCommand \index{DS390 memory model}
21654
21655 \end_inset
21656
21657
21658 \end_layout
21659
21660 \begin_layout Standard
21661 The only model supported is Flat 24
21662 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21663
21664 \end_inset
21665
21666 .
21667  This generates code for the 24 bit contiguous addressing mode of the Dallas
21668  DS80C390 part.
21669  In this mode, up to four meg of external RAM or code space can be directly
21670  addressed.
21671  See the data sheets at www.dalsemi.com for further information on this part.
21672 \newline
21673
21674 \newline
21675 Note
21676  that the compiler does not generate any code to place the processor into
21677  24 bitmode (although 
21678 \emph on
21679 tinibios
21680 \emph default
21681  in the ds390 libraries will do that for you).
21682  If you don't use 
21683 \emph on
21684 tinibios
21685 \emph default
21686
21687 \begin_inset LatexCommand \index{Tinibios (DS390)}
21688
21689 \end_inset
21690
21691 , the boot loader or similar code must ensure that the processor is in 24
21692  bit contiguous addressing mode before calling the SDCC startup code.
21693 \newline
21694
21695 \newline
21696 Like
21697  the 
21698 \emph on
21699 -
21700 \begin_inset ERT
21701 status collapsed
21702
21703 \begin_layout Standard
21704
21705
21706 \backslash
21707 /
21708 \end_layout
21709
21710 \end_inset
21711
21712 -model-large
21713 \emph default
21714  option, variables will by default be placed into the XDATA segment.
21715  
21716 \newline
21717
21718 \newline
21719 Segments may be placed anywhere in the 4 meg address space using the usual
21720  -
21721 \begin_inset ERT
21722 status collapsed
21723
21724 \begin_layout Standard
21725
21726
21727 \backslash
21728 /
21729 \end_layout
21730
21731 \end_inset
21732
21733 -*-loc options.
21734  Note that if any segments are located above 64K, the -r flag must be passed
21735  to the linker to generate the proper segment relocations, and the Intel
21736  HEX output format must be used.
21737  The -r flag can be passed to the linker by using the option 
21738 \emph on
21739 -Wl-r
21740 \emph default
21741  on the SDCC command line.
21742  However, currently the linker can not handle code segments > 64k.
21743 \end_layout
21744
21745 \begin_layout Section
21746 Pragmas
21747 \begin_inset LatexCommand \label{sec:Pragmas}
21748
21749 \end_inset
21750
21751
21752 \begin_inset LatexCommand \index{Pragmas}
21753
21754 \end_inset
21755
21756
21757 \end_layout
21758
21759 \begin_layout Standard
21760 Pragmas are used to turn on and/or off certain compiler options.
21761  Some of them are closely related to corresponding command-line options
21762  (see section 
21763 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21764
21765 \end_inset
21766
21767 ).
21768 \newline
21769 Pragmas should be placed before and/or after a function, placing pragmas
21770  inside a function body could have unpredictable results.
21771 \newline
21772
21773 \newline
21774 SDCC supports the
21775  following #pragma directives:
21776 \end_layout
21777
21778 \begin_layout Itemize
21779
21780 \series bold
21781 save
21782 \series default
21783
21784 \begin_inset LatexCommand \index{\#pragma save}
21785
21786 \end_inset
21787
21788  - this will save most current options to the save/restore stack.
21789  See #pragma\InsetSpace ~
21790 restore.
21791 \end_layout
21792
21793 \begin_layout Itemize
21794
21795 \series bold
21796 restore
21797 \series default
21798
21799 \begin_inset LatexCommand \index{\#pragma restore}
21800
21801 \end_inset
21802
21803  - will restore saved options from the last save.
21804  saves & restores can be nested.
21805  SDCC uses a save/restore stack: save pushes current options to the stack,
21806  restore pulls current options from the stack.
21807  See #pragma\InsetSpace ~
21808 save.
21809 \newline
21810
21811 \end_layout
21812
21813 \begin_layout Itemize
21814
21815 \series bold
21816 callee_saves
21817 \series default
21818
21819 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21820
21821 \end_inset
21822
21823
21824 \begin_inset LatexCommand \index{function prologue}
21825
21826 \end_inset
21827
21828  function1[,function2[,function3...]] 
21829 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21830
21831 \end_inset
21832
21833 - The compiler by default uses a caller saves convention for register saving
21834  across function calls, however this can cause unnecessary register pushing
21835  and popping
21836 \begin_inset LatexCommand \index{push/pop}
21837
21838 \end_inset
21839
21840  when calling small functions from larger functions.
21841  This option can be used to switch off the register saving convention for
21842  the function names specified.
21843  The compiler will not save registers when calling these functions, extra
21844  code need to be manually inserted at the entry and exit for these functions
21845  to save and restore the registers used by these functions, this can SUBSTANTIAL
21846 LY reduce code and improve run time performance of the generated code.
21847  In the future the compiler (with inter procedural analysis) may be able
21848  to determine the appropriate scheme to use for each function call.
21849  If -
21850 \begin_inset ERT
21851 status collapsed
21852
21853 \begin_layout Standard
21854
21855
21856 \backslash
21857 /
21858 \end_layout
21859
21860 \end_inset
21861
21862 -callee-saves command line option is used (see page 
21863 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21864
21865 \end_inset
21866
21867 ), the function names specified in #pragma\InsetSpace ~
21868 callee_saves
21869 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21870
21871 \end_inset
21872
21873  is appended to the list of functions specified in the command line.
21874 \end_layout
21875
21876 \begin_layout Itemize
21877
21878 \series bold
21879 exclude
21880 \series default
21881
21882 \begin_inset LatexCommand \index{\#pragma exclude}
21883
21884 \end_inset
21885
21886  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21887  of pairs of push/pop
21888 \begin_inset LatexCommand \index{push/pop}
21889
21890 \end_inset
21891
21892  instructions in 
21893 \emph on
21894 I
21895 \emph default
21896 nterrupt
21897 \begin_inset LatexCommand \index{interrupt}
21898
21899 \end_inset
21900
21901  
21902 \emph on
21903 S
21904 \emph default
21905 ervice 
21906 \emph on
21907 R
21908 \emph default
21909 outines.
21910  The directive should be placed immediately before the ISR function definition
21911  and it affects ALL ISR functions following it.
21912  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21913 exclude\InsetSpace ~
21914 none
21915 \begin_inset LatexCommand \index{\#pragma exclude}
21916
21917 \end_inset
21918
21919 .
21920  See also the related keyword _naked
21921 \begin_inset LatexCommand \index{\_naked}
21922
21923 \end_inset
21924
21925
21926 \begin_inset LatexCommand \index{\_\_naked}
21927
21928 \end_inset
21929
21930 .
21931 \end_layout
21932
21933 \begin_layout Itemize
21934
21935 \series bold
21936 less_pedantic
21937 \series default
21938
21939 \begin_inset LatexCommand \index{pedantic}
21940
21941 \end_inset
21942
21943
21944 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21945
21946 \end_inset
21947
21948  
21949 \begin_inset LatexCommand \label{ite:less_pedantic}
21950
21951 \end_inset
21952
21953 - the compiler will not warn you anymore for obvious mistakes, you're on
21954  your own now ;-( .
21955  See also the command line option -
21956 \begin_inset ERT
21957 status collapsed
21958
21959 \begin_layout Standard
21960
21961
21962 \backslash
21963 /
21964 \end_layout
21965
21966 \end_inset
21967
21968 -less-pedantic 
21969 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21970
21971 \end_inset
21972
21973 .
21974  
21975 \newline
21976 More specifically, the following warnings will be disabled: 
21977 \shape italic
21978 comparison is always [true/false] due to limited range of data type
21979 \shape default
21980  (94); 
21981 \shape italic
21982 overflow in implicit constant conversion
21983 \shape default
21984  (158); [the (in)famous] 
21985 \shape italic
21986 conditional flow changed by optimizer: so said EVELYN the modified DOG
21987 \shape default
21988  (110); 
21989 \shape italic
21990 function '[function name]' must return value
21991 \shape default
21992  (59).
21993  
21994 \newline
21995 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21996  level) are disabled, too, namely: 
21997 \shape italic
21998 constant value '[
21999 \begin_inset Note Note
22000 status collapsed
22001
22002 \begin_layout Standard
22003 dunno what comes here - this warning appears to be unused altogether
22004 \end_layout
22005
22006 \end_inset
22007
22008 ]', out of range
22009 \shape default
22010  (81); 
22011 \shape italic
22012 [left/right] shifting more than size of object changed to zero
22013 \shape default
22014  (116); 
22015 \shape italic
22016 unreachable code
22017 \shape default
22018  (126); 
22019 \shape italic
22020 integer overflow in expression
22021 \shape default
22022  (165); 
22023 \shape italic
22024 unmatched #pragma save and #pragma restore
22025 \shape default
22026  (170); 
22027 \shape italic
22028 comparison of 'signed char' with 'unsigned char' requires promotion to int
22029 \shape default
22030  (185); 
22031 \shape italic
22032 ISO C90 does not support flexible array members
22033 \shape default
22034  (187); 
22035 \shape italic
22036 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
22037 nam
22038 e]':\InsetSpace ~
22039 [
22040 \begin_inset Note Note
22041 status collapsed
22042
22043 \begin_layout Standard
22044 appears to be always blank - what was supposed to be here?
22045 \end_layout
22046
22047 \end_inset
22048
22049 ]
22050 \shape default
22051  (114); 
22052 \shape italic
22053 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
22054  complexity [number]
22055 \shape default
22056  (121).
22057 \end_layout
22058
22059 \begin_layout Itemize
22060
22061 \series bold
22062 disable_warning
22063 \series default
22064  <nnnn>
22065 \begin_inset LatexCommand \index{\#pragma disable\_warning}
22066
22067 \end_inset
22068
22069  - the compiler will not warn you anymore about warning number <nnnn>.
22070 \end_layout
22071
22072 \begin_layout Itemize
22073
22074 \series bold
22075 nogcse
22076 \series default
22077
22078 \begin_inset LatexCommand \index{\#pragma nogcse}
22079
22080 \end_inset
22081
22082  - will stop global common subexpression elimination.
22083 \end_layout
22084
22085 \begin_layout Itemize
22086
22087 \series bold
22088 noinduction
22089 \series default
22090
22091 \begin_inset LatexCommand \index{\#pragma noinduction}
22092
22093 \end_inset
22094
22095  - will stop loop induction optimizations.
22096 \end_layout
22097
22098 \begin_layout Itemize
22099
22100 \series bold
22101 noinvariant
22102 \series default
22103
22104 \begin_inset LatexCommand \index{\#pragma noinvariant}
22105
22106 \end_inset
22107
22108  - will not do loop invariant optimizations.
22109  For more details see Loop Invariants in section
22110 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
22111
22112 \end_inset
22113
22114 .
22115 \end_layout
22116
22117 \begin_layout Itemize
22118
22119 \series bold
22120 noiv
22121 \series default
22122
22123 \begin_inset LatexCommand \index{\#pragma noiv}
22124
22125 \end_inset
22126
22127  - Do not generate interrupt
22128 \begin_inset LatexCommand \index{interrupt}
22129
22130 \end_inset
22131
22132  vector table
22133 \begin_inset LatexCommand \index{interrupt vector table}
22134
22135 \end_inset
22136
22137  entries for all ISR functions defined after the pragma.
22138  This is useful in cases where the interrupt vector table must be defined
22139  manually, or when there is a secondary, manually defined interrupt vector
22140  table (e.g.
22141  for the autovector feature of the Cypress EZ-USB FX2).
22142  More elegantly this can be achieved by obmitting the optional interrupt
22143  number after the interrupt keyword, see section 
22144 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
22145
22146 \end_inset
22147
22148 \InsetSpace ~
22149 about interrupts.
22150 \end_layout
22151
22152 \begin_layout Itemize
22153
22154 \series bold
22155 nojtbound
22156 \series default
22157
22158 \begin_inset LatexCommand \index{\#pragma nojtbound}
22159
22160 \end_inset
22161
22162  - will not generate code for boundary value checking, when switch statements
22163  are turned into jump-tables (dangerous).
22164  For more details see section 
22165 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
22166
22167 \end_inset
22168
22169 .
22170 \end_layout
22171
22172 \begin_layout Itemize
22173
22174 \series bold
22175 noloopreverse
22176 \series default
22177
22178 \begin_inset LatexCommand \index{\#pragma noloopreverse}
22179
22180 \end_inset
22181
22182  - Will not do loop reversal optimization
22183 \end_layout
22184
22185 \begin_layout Itemize
22186
22187 \series bold
22188 nooverlay
22189 \series default
22190
22191 \begin_inset LatexCommand \index{\#pragma nooverlay}
22192
22193 \end_inset
22194
22195  - the compiler will not overlay the parameters and local variables of a
22196  function.
22197 \end_layout
22198
22199 \begin_layout Itemize
22200
22201 \series bold
22202 stackauto
22203 \series default
22204
22205 \begin_inset LatexCommand \index{\#pragma stackauto}
22206
22207 \end_inset
22208
22209 - See option -
22210 \begin_inset ERT
22211 status collapsed
22212
22213 \begin_layout Standard
22214
22215
22216 \backslash
22217 /
22218 \end_layout
22219
22220 \end_inset
22221
22222 -stack-auto
22223 \begin_inset LatexCommand \index{-\/-stack-auto}
22224
22225 \end_inset
22226
22227  and section 
22228 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
22229
22230 \end_inset
22231
22232  Parameters and Local Variables.
22233 \end_layout
22234
22235 \begin_layout Itemize
22236
22237 \series bold
22238 opt_code_speed
22239 \series default
22240  
22241 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
22242
22243 \end_inset
22244
22245 - The compiler will optimize code generation towards fast code, possibly
22246  at the expense of code size.
22247  Currently this has little effect.
22248 \end_layout
22249
22250 \begin_layout Itemize
22251
22252 \series bold
22253 opt_code_size
22254 \series default
22255  
22256 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
22257
22258 \end_inset
22259
22260 - The compiler will optimize code generation towards compact code, possibly
22261  at the expense of code speed.
22262  Currently this has little effect.
22263 \end_layout
22264
22265 \begin_layout Itemize
22266
22267 \series bold
22268 opt_code_balanced
22269 \series default
22270  
22271 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
22272
22273 \end_inset
22274
22275 - The compiler will attempt to generate code that is both compact and fast,
22276  as long as meeting one goal is not a detriment to the other (this is the
22277  default).
22278  
22279 \end_layout
22280
22281 \begin_layout Itemize
22282
22283 \series bold
22284 std_sdcc89
22285 \series default
22286  
22287 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
22288
22289 \end_inset
22290
22291 - Generally follow the C89 standard, but allow SDCC features that conflict
22292  with the standard (default).
22293 \end_layout
22294
22295 \begin_layout Itemize
22296
22297 \series bold
22298 std_c89
22299 \series default
22300  
22301 \begin_inset LatexCommand \index{\#pragma std\_c89}
22302
22303 \end_inset
22304
22305 - Follow the C89 standard and disable SDCC features that conflict with the
22306  standard.
22307 \end_layout
22308
22309 \begin_layout Itemize
22310
22311 \series bold
22312 std_sdcc99
22313 \series default
22314  
22315 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
22316
22317 \end_inset
22318
22319 - Generally follow the C99 standard, but allow SDCC features that conflict
22320  with the standard (incomplete support).
22321 \end_layout
22322
22323 \begin_layout Itemize
22324
22325 \series bold
22326 std_c99
22327 \series default
22328  
22329 \begin_inset LatexCommand \index{\#pragma std\_c99}
22330
22331 \end_inset
22332
22333 - Follow the C99 standard and disable SDCC features that conflict with the
22334  standard (incomplete support).
22335 \end_layout
22336
22337 \begin_layout Itemize
22338
22339 \series bold
22340 codeseg
22341 \series default
22342  <name>
22343 \begin_inset LatexCommand \index{\#pragma codeseg}
22344
22345 \end_inset
22346
22347 - Use this name (max.
22348  8 characters) for the code segment.
22349  See option -
22350 \begin_inset ERT
22351 status collapsed
22352
22353 \begin_layout Standard
22354
22355
22356 \backslash
22357 /
22358 \end_layout
22359
22360 \end_inset
22361
22362 -codeseg.
22363 \end_layout
22364
22365 \begin_layout Itemize
22366
22367 \series bold
22368 constseg
22369 \series default
22370  <name>
22371 \begin_inset LatexCommand \index{\#pragma constseg}
22372
22373 \end_inset
22374
22375 - Use this name (max.
22376  8 characters) for the const segment.
22377  See option -
22378 \begin_inset ERT
22379 status collapsed
22380
22381 \begin_layout Standard
22382
22383
22384 \backslash
22385 /
22386 \end_layout
22387
22388 \end_inset
22389
22390 -constseg.
22391 \end_layout
22392
22393 \begin_layout Standard
22394 The preprocessor SDCPP
22395 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
22396
22397 \end_inset
22398
22399  supports the following #pragma directives:
22400 \end_layout
22401
22402 \begin_layout Itemize
22403
22404 \series bold
22405 pedantic_parse_number
22406 \series default
22407
22408 \begin_inset LatexCommand \index{pedantic}
22409
22410 \end_inset
22411
22412
22413 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22414
22415 \end_inset
22416
22417  (+ | -) 
22418 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
22419
22420 \end_inset
22421
22422 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
22423  properly and the macro LO_B(3) gets expanded.
22424  Default is off.
22425  See also the -
22426 \begin_inset ERT
22427 status collapsed
22428
22429 \begin_layout Standard
22430
22431
22432 \backslash
22433 /
22434 \end_layout
22435
22436 \end_inset
22437
22438 -pedantic-parse-number command line option 
22439 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
22440
22441 \end_inset
22442
22443 .
22444  
22445 \newline
22446 Below is an example on how to use this pragma.
22447
22448 \emph on
22449  Note: this functionality is not in conformance with standard!
22450 \end_layout
22451
22452 \begin_layout Verse
22453
22454 \family typewriter
22455 #pragma pedantic_parse_number +
22456 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
22457
22458 \end_inset
22459
22460
22461 \newline
22462
22463 \newline
22464 #define LO_B(x) ((x) & 0xff)
22465 \newline
22466
22467 \newline
22468 unsigned char foo(void)
22469 \newline
22470 {
22471 \newline
22472 \InsetSpace ~
22473 \InsetSpace ~
22474 \InsetSpace ~
22475 unsigned char c=0xfe-LO_B(3)
22476 ;
22477 \newline
22478
22479 \newline
22480 \InsetSpace ~
22481 \InsetSpace ~
22482 \InsetSpace ~
22483 return c;
22484 \newline
22485 }
22486 \newline
22487
22488 \end_layout
22489
22490 \begin_layout Itemize
22491
22492 \series bold
22493 preproc_asm
22494 \series default
22495
22496 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22497
22498 \end_inset
22499
22500  (+ | -) - switch _asm _endasm block preprocessing on / off.
22501  Default is on.
22502  You use this prama to define multilines of assembly code.
22503  This will prevent the preprocessor from changing the formating required
22504  by assembly code.
22505  Below is an example on how to use this pragma.
22506 \end_layout
22507
22508 \begin_layout Verse
22509
22510 \family typewriter
22511 #pragma preproc_asm -
22512 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
22513
22514 \end_inset
22515
22516
22517 \newline
22518 #define MYDELAY _asm
22519 \newline
22520 \InsetSpace ~
22521 \InsetSpace ~
22522 \InsetSpace ~
22523 nop ;my assembly comment...
22524 \newline
22525 \InsetSpace ~
22526 \InsetSpace ~
22527 \InsetSpace ~
22528 nop
22529 \newline
22530 \InsetSpace ~
22531 \InsetSpace ~
22532 \InsetSpace ~
22533 nop
22534 \newline
22535 _endasm
22536 \newline
22537 #pragma preproc_asm
22538  +
22539 \newline
22540
22541 \newline
22542 void foo (void) 
22543 \newline
22544
22545 \newline
22546 \InsetSpace ~
22547 \InsetSpace ~
22548 \InsetSpace ~
22549  ...
22550  
22551 \newline
22552 \InsetSpace ~
22553 \InsetSpace ~
22554 \InsetSpace ~
22555  MYDELAY;
22556 \newline
22557 \InsetSpace ~
22558 \InsetSpace ~
22559 \InsetSpace ~
22560  ...
22561  
22562 \newline
22563
22564 \newline
22565
22566 \end_layout
22567
22568 \begin_layout Itemize
22569
22570 \series bold
22571 sdcc_hash
22572 \series default
22573
22574 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22575
22576 \end_inset
22577
22578  (+ | -) - Allow "naked" hash in macro definition, for example:
22579 \newline
22580
22581 \family typewriter
22582 #define DIR_LO(x) #(x & 0xff)
22583 \family default
22584
22585 \newline
22586 Default is off.
22587  Below is an example on how to use this pragma.
22588 \end_layout
22589
22590 \begin_layout Verse
22591
22592 \family typewriter
22593 #pragma preproc_asm +
22594 \newline
22595 #pragma sdcc_hash +
22596 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22597
22598 \end_inset
22599
22600
22601 \newline
22602
22603 \newline
22604 #define ROMCALL(x) 
22605 \backslash
22606
22607 \newline
22608 \InsetSpace ~
22609 \InsetSpace ~
22610 \InsetSpace ~
22611 mov R6_B3, #(x & 0xff) 
22612 \backslash
22613
22614 \newline
22615 \InsetSpace ~
22616 \InsetSpace ~
22617 \InsetSpace ~
22618 mov R7_B3, #((x >> 8) & 0xff) 
22619 \backslash
22620
22621 \newline
22622 \InsetSpace ~
22623 \InsetSpace ~
22624 \InsetSpace ~
22625 lcall __romcall
22626 \newline
22627
22628 \newline
22629 ...
22630 \newline
22631 _asm
22632 \newline
22633 ROMCALL(72)
22634 \newline
22635 _endasm;
22636 \newline
22637 ...
22638 \newline
22639
22640 \end_layout
22641
22642 \begin_layout Standard
22643 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22644 ons which might cause the compiler to generate extra stack and/or data space
22645  to store compiler generated temporary variables.
22646  This usually happens in large functions.
22647  Pragma directives should be used as shown in the following example, they
22648  are used to control options and optimizations for a given function.
22649  
22650 \end_layout
22651
22652 \begin_layout Verse
22653
22654 \family typewriter
22655 #pragma save
22656 \begin_inset LatexCommand \index{\#pragma save}
22657
22658 \end_inset
22659
22660  \InsetSpace ~
22661 \InsetSpace ~
22662 \InsetSpace ~
22663 \InsetSpace ~
22664 \InsetSpace ~
22665 \InsetSpace ~
22666 \InsetSpace ~
22667 /* save the current settings */ 
22668 \newline
22669 #pragma nogcse
22670 \begin_inset LatexCommand \index{\#pragma nogcse}
22671
22672 \end_inset
22673
22674  \InsetSpace ~
22675 \InsetSpace ~
22676 \InsetSpace ~
22677 \InsetSpace ~
22678 \InsetSpace ~
22679 /* turnoff global subexpression elimination */ 
22680 \newline
22681 #pragma noinduction
22682 \begin_inset LatexCommand \index{\#pragma noinduction}
22683
22684 \end_inset
22685
22686  /* turn off induction optimizations */ 
22687 \newline
22688 int foo () 
22689 \newline
22690
22691 \newline
22692 \InsetSpace ~
22693  \InsetSpace ~
22694  ...
22695  
22696 \newline
22697 \InsetSpace ~
22698  \InsetSpace ~
22699  /* large code */ 
22700 \newline
22701 \InsetSpace ~
22702  \InsetSpace ~
22703  ...
22704  
22705 \newline
22706
22707 \newline
22708 #pragma restore
22709 \begin_inset LatexCommand \index{\#pragma restore}
22710
22711 \end_inset
22712
22713  /* turn the optimizations back on */
22714 \end_layout
22715
22716 \begin_layout Standard
22717 The compiler will generate a warning message when extra space is allocated.
22718  It is strongly recommended that the save and restore pragmas be used when
22719  changing options for a function.
22720 \newline
22721
22722 \newline
22723
22724 \newline
22725
22726 \end_layout
22727
22728 \begin_layout Section
22729 Defines Created by the Compiler
22730 \end_layout
22731
22732 \begin_layout Standard
22733 The compiler creates the following #defines
22734 \begin_inset LatexCommand \index{\#defines}
22735
22736 \end_inset
22737
22738
22739 \begin_inset LatexCommand \index{Defines created by the compiler}
22740
22741 \end_inset
22742
22743 :
22744 \newline
22745
22746 \end_layout
22747
22748 \begin_layout Standard
22749 \begin_inset Tabular
22750 <lyxtabular version="3" rows="15" columns="2">
22751 <features>
22752 <column alignment="left" valignment="top" leftline="true" width="3in">
22753 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22754 <row topline="true" bottomline="true">
22755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22756 \begin_inset Text
22757
22758 \begin_layout Standard
22759
22760 \series bold
22761 #define
22762 \end_layout
22763
22764 \end_inset
22765 </cell>
22766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22767 \begin_inset Text
22768
22769 \begin_layout Standard
22770
22771 \series bold
22772 Description
22773 \end_layout
22774
22775 \end_inset
22776 </cell>
22777 </row>
22778 <row topline="true">
22779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22780 \begin_inset Text
22781
22782 \begin_layout Standard
22783 SDCC
22784 \begin_inset LatexCommand \index{SDCC}
22785
22786 \end_inset
22787
22788  
22789 \end_layout
22790
22791 \end_inset
22792 </cell>
22793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22794 \begin_inset Text
22795
22796 \begin_layout Standard
22797 Always defined.
22798  Since version 2.5.6 the version number as an int (ex.
22799  256)
22800 \end_layout
22801
22802 \end_inset
22803 </cell>
22804 </row>
22805 <row topline="true">
22806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22807 \begin_inset Text
22808
22809 \begin_layout Standard
22810 SDCC_mcs51
22811 \begin_inset LatexCommand \index{SDCC\_mcs51}
22812
22813 \end_inset
22814
22815  or SDCC_ds390
22816 \begin_inset LatexCommand \index{SDCC\_ds390}
22817
22818 \end_inset
22819
22820  or SDCC_z80
22821 \begin_inset LatexCommand \index{SDCC\_z80}
22822
22823 \end_inset
22824
22825 , etc.
22826 \end_layout
22827
22828 \end_inset
22829 </cell>
22830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22831 \begin_inset Text
22832
22833 \begin_layout Standard
22834 depending on the model used (e.g.: -mds390)
22835 \end_layout
22836
22837 \end_inset
22838 </cell>
22839 </row>
22840 <row topline="true">
22841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22842 \begin_inset Text
22843
22844 \begin_layout Standard
22845 __mcs51
22846 \begin_inset LatexCommand \index{\_\_mcs51}
22847
22848 \end_inset
22849
22850 , __ds390
22851 \begin_inset LatexCommand \index{\_\_ds390}
22852
22853 \end_inset
22854
22855 , __hc08
22856 \begin_inset LatexCommand \index{\_\_hc08}
22857
22858 \end_inset
22859
22860 , __z80
22861 \begin_inset LatexCommand \index{\_\_z80}
22862
22863 \end_inset
22864
22865 , etc
22866 \end_layout
22867
22868 \end_inset
22869 </cell>
22870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22871 \begin_inset Text
22872
22873 \begin_layout Standard
22874 depending on the model used (e.g.
22875  -mz80)
22876 \end_layout
22877
22878 \end_inset
22879 </cell>
22880 </row>
22881 <row topline="true">
22882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22883 \begin_inset Text
22884
22885 \begin_layout Standard
22886 SDCC_STACK_AUTO
22887 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22888
22889 \end_inset
22890
22891
22892 \end_layout
22893
22894 \end_inset
22895 </cell>
22896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22897 \begin_inset Text
22898
22899 \begin_layout Standard
22900 when 
22901 \emph on
22902 -
22903 \begin_inset ERT
22904 status collapsed
22905
22906 \begin_layout Standard
22907
22908
22909 \backslash
22910 /
22911 \end_layout
22912
22913 \end_inset
22914
22915 -stack-auto
22916 \emph default
22917  option is used
22918 \end_layout
22919
22920 \end_inset
22921 </cell>
22922 </row>
22923 <row topline="true">
22924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22925 \begin_inset Text
22926
22927 \begin_layout Standard
22928 SDCC_MODEL_SMALL
22929 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22930
22931 \end_inset
22932
22933
22934 \end_layout
22935
22936 \end_inset
22937 </cell>
22938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22939 \begin_inset Text
22940
22941 \begin_layout Standard
22942 when 
22943 \emph on
22944 -
22945 \begin_inset ERT
22946 status collapsed
22947
22948 \begin_layout Standard
22949
22950
22951 \backslash
22952 /
22953 \end_layout
22954
22955 \end_inset
22956
22957 -model-small
22958 \emph default
22959  is used
22960 \end_layout
22961
22962 \end_inset
22963 </cell>
22964 </row>
22965 <row topline="true">
22966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22967 \begin_inset Text
22968
22969 \begin_layout Standard
22970 SDCC_MODEL_MEDIUM
22971 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22972
22973 \end_inset
22974
22975
22976 \end_layout
22977
22978 \end_inset
22979 </cell>
22980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22981 \begin_inset Text
22982
22983 \begin_layout Standard
22984 when 
22985 \emph on
22986 -
22987 \begin_inset ERT
22988 status collapsed
22989
22990 \begin_layout Standard
22991
22992
22993 \backslash
22994 /
22995 \end_layout
22996
22997 \end_inset
22998
22999 -model-medium
23000 \emph default
23001  is used
23002 \end_layout
23003
23004 \end_inset
23005 </cell>
23006 </row>
23007 <row topline="true">
23008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23009 \begin_inset Text
23010
23011 \begin_layout Standard
23012 SDCC_MODEL_LARGE
23013 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
23014
23015 \end_inset
23016
23017
23018 \end_layout
23019
23020 \end_inset
23021 </cell>
23022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23023 \begin_inset Text
23024
23025 \begin_layout Standard
23026 when 
23027 \emph on
23028 -
23029 \begin_inset ERT
23030 status collapsed
23031
23032 \begin_layout Standard
23033
23034
23035 \backslash
23036 /
23037 \end_layout
23038
23039 \end_inset
23040
23041 -model-large
23042 \emph default
23043  is used
23044 \end_layout
23045
23046 \end_inset
23047 </cell>
23048 </row>
23049 <row topline="true">
23050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23051 \begin_inset Text
23052
23053 \begin_layout Standard
23054 SDCC_USE_XSTACK
23055 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
23056
23057 \end_inset
23058
23059
23060 \end_layout
23061
23062 \end_inset
23063 </cell>
23064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23065 \begin_inset Text
23066
23067 \begin_layout Standard
23068 when 
23069 \emph on
23070 -
23071 \begin_inset ERT
23072 status collapsed
23073
23074 \begin_layout Standard
23075
23076
23077 \backslash
23078 /
23079 \end_layout
23080
23081 \end_inset
23082
23083 -xstack
23084 \emph default
23085  option is used
23086 \end_layout
23087
23088 \end_inset
23089 </cell>
23090 </row>
23091 <row topline="true">
23092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23093 \begin_inset Text
23094
23095 \begin_layout Standard
23096 SDCC_STACK_TENBIT
23097 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
23098
23099 \end_inset
23100
23101  
23102 \end_layout
23103
23104 \end_inset
23105 </cell>
23106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23107 \begin_inset Text
23108
23109 \begin_layout Standard
23110 when 
23111 \emph on
23112 -mds390
23113 \emph default
23114  is used
23115 \end_layout
23116
23117 \end_inset
23118 </cell>
23119 </row>
23120 <row topline="true">
23121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23122 \begin_inset Text
23123
23124 \begin_layout Standard
23125 SDCC_MODEL_FLAT24
23126 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23127
23128 \end_inset
23129
23130
23131 \end_layout
23132
23133 \end_inset
23134 </cell>
23135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23136 \begin_inset Text
23137
23138 \begin_layout Standard
23139 when 
23140 \emph on
23141 -mds390
23142 \emph default
23143  is used
23144 \end_layout
23145
23146 \end_inset
23147 </cell>
23148 </row>
23149 <row topline="true">
23150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23151 \begin_inset Text
23152
23153 \begin_layout Standard
23154 SDCC_REVISION
23155 \begin_inset LatexCommand \index{SDCC\_REVISION}
23156
23157 \end_inset
23158
23159
23160 \end_layout
23161
23162 \end_inset
23163 </cell>
23164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23165 \begin_inset Text
23166
23167 \begin_layout Standard
23168 Always defined.
23169  SDCC svn revision number
23170 \end_layout
23171
23172 \end_inset
23173 </cell>
23174 </row>
23175 <row topline="true">
23176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23177 \begin_inset Text
23178
23179 \begin_layout Standard
23180 SDCC_PARMS_IN_BANK1
23181 \begin_inset LatexCommand \index{SDCC\_PARMS\_IN\_BANK1}
23182
23183 \end_inset
23184
23185
23186 \end_layout
23187
23188 \end_inset
23189 </cell>
23190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23191 \begin_inset Text
23192
23193 \begin_layout Standard
23194 when 
23195 \emph on
23196 -
23197 \begin_inset ERT
23198 status collapsed
23199
23200 \begin_layout Standard
23201
23202
23203 \backslash
23204 /
23205 \end_layout
23206
23207 \end_inset
23208
23209 -parms-in-bank1
23210 \emph default
23211  is used
23212 \end_layout
23213
23214 \end_inset
23215 </cell>
23216 </row>
23217 <row topline="true">
23218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23219 \begin_inset Text
23220
23221 \begin_layout Standard
23222 SDCC_FLOAT_REENT
23223 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
23224
23225 \end_inset
23226
23227
23228 \end_layout
23229
23230 \end_inset
23231 </cell>
23232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23233 \begin_inset Text
23234
23235 \begin_layout Standard
23236 when 
23237 \emph on
23238 -
23239 \begin_inset ERT
23240 status collapsed
23241
23242 \begin_layout Standard
23243
23244
23245 \backslash
23246 /
23247 \end_layout
23248
23249 \end_inset
23250
23251 -float-reent
23252 \emph default
23253  is used
23254 \end_layout
23255
23256 \end_inset
23257 </cell>
23258 </row>
23259 <row topline="true" bottomline="true">
23260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23261 \begin_inset Text
23262
23263 \begin_layout Standard
23264 SDCC_INT_LONG_REENT
23265 \begin_inset LatexCommand \index{SDCC\_INT\_LONG\_REENT}
23266
23267 \end_inset
23268
23269
23270 \end_layout
23271
23272 \end_inset
23273 </cell>
23274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23275 \begin_inset Text
23276
23277 \begin_layout Standard
23278 when 
23279 \emph on
23280 -
23281 \begin_inset ERT
23282 status collapsed
23283
23284 \begin_layout Standard
23285
23286
23287 \backslash
23288 /
23289 \end_layout
23290
23291 \end_inset
23292
23293 -int-long-reent
23294 \emph default
23295  is used
23296 \end_layout
23297
23298 \end_inset
23299 </cell>
23300 </row>
23301 </lyxtabular>
23302
23303 \end_inset
23304
23305
23306 \end_layout
23307
23308 \begin_layout Chapter
23309 Notes on supported Processors
23310 \end_layout
23311
23312 \begin_layout Section
23313 MCS51 variants
23314 \begin_inset LatexCommand \label{sub:MCS51-variants}
23315
23316 \end_inset
23317
23318
23319 \begin_inset LatexCommand \index{MCS51 variants}
23320
23321 \end_inset
23322
23323
23324 \end_layout
23325
23326 \begin_layout Standard
23327 MCS51 processors are available from many vendors and come in many different
23328  flavours.
23329  While they might differ considerably in respect to Special Function Registers
23330  the core MCS51 is usually not modified or is kept compatible.
23331  
23332 \end_layout
23333
23334 \begin_layout Subsection
23335 pdata access by SFR 
23336 \end_layout
23337
23338 \begin_layout Standard
23339 With the upcome of devices with internal xdata and flash memory devices
23340  using port P2
23341 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
23342
23343 \end_inset
23344
23345  as dedicated I/O port is becoming more popular.
23346  Switching the high byte for pdata
23347 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
23348
23349 \end_inset
23350
23351  access which was formerly done by port P2 is then achieved by a Special
23352  Function Register
23353 \begin_inset LatexCommand \index{sfr}
23354
23355 \end_inset
23356
23357 .
23358  In well-established MCS51 tradition the address of this 
23359 \emph on
23360 sfr
23361 \emph default
23362  is where the chip designers decided to put it.
23363  Needless to say that they didn't agree on a common name either.
23364  So that the startup code can correctly initialize xdata variables, you
23365  should define an sfr with the name _XPAGE
23366 \family typewriter
23367
23368 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
23369
23370 \end_inset
23371
23372
23373 \family default
23374  at the appropriate location if the default, port P2, is not used for this.
23375  Some examples are:
23376 \end_layout
23377
23378 \begin_layout Verse
23379
23380 \family typewriter
23381 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
23382  MPAGE */
23383 \end_layout
23384
23385 \begin_layout Verse
23386
23387 \family typewriter
23388 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
23389  a.k.a.
23390  MPAGE */
23391 \end_layout
23392
23393 \begin_layout Verse
23394
23395 \family typewriter
23396 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
23397  XPAGE */
23398 \end_layout
23399
23400 \begin_layout Verse
23401
23402 \family typewriter
23403 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23404  EMI0CN */
23405 \end_layout
23406
23407 \begin_layout Verse
23408
23409 \family typewriter
23410 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
23411  EMI0CN */
23412 \end_layout
23413
23414 \begin_layout Standard
23415 For more exotic implementations further customizations may be needed.
23416  See section 
23417 \begin_inset LatexCommand \ref{sub:Startup-Code}
23418
23419 \end_inset
23420
23421  for other possibilities.
23422 \end_layout
23423
23424 \begin_layout Subsection
23425 Other Features available by SFR
23426 \end_layout
23427
23428 \begin_layout Standard
23429 Some MCS51 variants offer features like Double DPTR
23430 \begin_inset LatexCommand \index{DPTR}
23431
23432 \end_inset
23433
23434 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
23435  These are currently not used for the MCS51 port.
23436  If you absolutely need them you can fall back to inline assembly or submit
23437  a patch to SDCC.
23438 \end_layout
23439
23440 \begin_layout Subsection
23441 Bankswitching
23442 \end_layout
23443
23444 \begin_layout Standard
23445 Bankswitching
23446 \begin_inset LatexCommand \index{Bankswitching}
23447
23448 \end_inset
23449
23450  (a.k.a.
23451  code banking
23452 \begin_inset LatexCommand \index{code banking}
23453
23454 \end_inset
23455
23456 ) is a technique to increase the code space above the 64k limit of the 8051.
23457 \end_layout
23458
23459 \begin_layout Subsubsection
23460 Hardware
23461 \end_layout
23462
23463 \begin_layout Standard
23464 \begin_inset Tabular
23465 <lyxtabular version="3" rows="3" columns="4">
23466 <features>
23467 <column alignment="center" valignment="top" width="0">
23468 <column alignment="center" valignment="top" leftline="true" width="0">
23469 <column alignment="center" valignment="top" leftline="true" width="0">
23470 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23471 <row topline="true" bottomline="true">
23472 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23473 \begin_inset Text
23474
23475 \begin_layout Standard
23476 8000-FFFF
23477 \end_layout
23478
23479 \end_inset
23480 </cell>
23481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23482 \begin_inset Text
23483
23484 \begin_layout Standard
23485 bank1
23486 \end_layout
23487
23488 \end_inset
23489 </cell>
23490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23491 \begin_inset Text
23492
23493 \begin_layout Standard
23494 bank2
23495 \end_layout
23496
23497 \end_inset
23498 </cell>
23499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23500 \begin_inset Text
23501
23502 \begin_layout Standard
23503 bank3
23504 \end_layout
23505
23506 \end_inset
23507 </cell>
23508 </row>
23509 <row topline="true" bottomline="true">
23510 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23511 \begin_inset Text
23512
23513 \begin_layout Standard
23514 0000-7FFF
23515 \end_layout
23516
23517 \end_inset
23518 </cell>
23519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23520 \begin_inset Text
23521
23522 \begin_layout Standard
23523 common
23524 \end_layout
23525
23526 \end_inset
23527 </cell>
23528 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23529 \begin_inset Text
23530
23531 \begin_layout Standard
23532
23533 \end_layout
23534
23535 \end_inset
23536 </cell>
23537 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23538 \begin_inset Text
23539
23540 \begin_layout Standard
23541
23542 \end_layout
23543
23544 \end_inset
23545 </cell>
23546 </row>
23547 <row>
23548 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
23549 \begin_inset Text
23550
23551 \begin_layout Standard
23552 SiLabs C8051F120 example
23553 \end_layout
23554
23555 \end_inset
23556 </cell>
23557 <cell multicolumn="2" alignment="center" valignment="top" usebox="none">
23558 \begin_inset Text
23559
23560 \begin_layout Standard
23561
23562 \end_layout
23563
23564 \end_inset
23565 </cell>
23566 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23567 \begin_inset Text
23568
23569 \begin_layout Standard
23570
23571 \end_layout
23572
23573 \end_inset
23574 </cell>
23575 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23576 \begin_inset Text
23577
23578 \begin_layout Standard
23579
23580 \end_layout
23581
23582 \end_inset
23583 </cell>
23584 </row>
23585 </lyxtabular>
23586
23587 \end_inset
23588
23589
23590 \newline
23591
23592 \newline
23593 Usually the hardware uses some sfr (an output port or an internal sfr) to
23594  select a bank and put it in the banked area of the memory map.
23595  Because the selected bank usually becomes active immediately you cannot
23596  jump call directly from one bank to another and need to use a so-called
23597  trampoline in the common area.
23598  For SDCC an example trampoline is in crtbank.asm and you may need to change
23599  it to your 8051 derivative or schematic.
23600  The presented code is written for the C8051F120.
23601 \newline
23602
23603 \newline
23604 When calling a banked function
23605  SDCC will put the LSB of the functions address in register R0, the MSB
23606  in R1 and the bank in R2 and then call this trampoline __sdcc_banked_call.
23607  The current selected bank is saved on the stack, the new bank is selected
23608  and an indirect jump is made.
23609  When the banked function returns it jumps to __sdcc_banked_ret which restores
23610  the previous bank and returns to the caller.
23611 \end_layout
23612
23613 \begin_layout Subsubsection
23614 Software
23615 \end_layout
23616
23617 \begin_layout Standard
23618 When writing banked software using SDCC you need to use some special keywords
23619  and options.
23620  You also need to take over a bit of work from the linker.
23621 \newline
23622
23623 \newline
23624 To create a function
23625  that can be called from another bank it requires the keyword banked.
23626  The caller must see this in the prototype of the callee and the callee
23627  needs it for a proper return.
23628  Called functions within the same bank as the caller do not need the banked
23629  keyword nor do functions in the common area.
23630  Beware: SDCC does not know or check if functions are in the same bank.
23631  This is your responsibility!
23632 \newline
23633
23634 \newline
23635 Normally all functions you write end up in
23636  the segment CSEG.
23637  If you want a function explicitly to reside in the common area put it in
23638  segment HOME.
23639  This applies for instance to interrupt service routines as they should
23640  not be banked.
23641 \end_layout
23642
23643 \begin_layout Standard
23644 Functions that need to be in a switched bank must be put in a named segment.
23645  The name can be mostly anything upto eight characters (e.g.
23646  BANK1).
23647  To do this you either use --codeseg BANK1 on the command line when compiling
23648  or #pragma codeseg BANK1 at the top of the C source file.
23649  The segment name always applies to the whole source file and generated
23650  object so functions for different banks need to be defined in different
23651  source files.
23652 \newline
23653
23654 \newline
23655 When linking your objects you need to tell the linker where
23656  to put your segments.
23657  To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180
23658 00.
23659  This sets the virtual start address of this segment.
23660  It sets the banknumber to 0x01 and maps the bank to 0x8000 and up.
23661  The linker will not check for overflows, again this is your responsibility.
23662 \end_layout
23663
23664 \begin_layout Standard
23665 \begin_inset VSpace bigskip
23666 \end_inset
23667
23668
23669 \end_layout
23670
23671 \begin_layout Section
23672 DS400 port
23673 \end_layout
23674
23675 \begin_layout Standard
23676 The DS80C400
23677 \begin_inset LatexCommand \index{DS80C400}
23678
23679 \end_inset
23680
23681
23682 \begin_inset LatexCommand \index{DS400}
23683
23684 \end_inset
23685
23686  microcontroller has a rich set of peripherals.
23687  In its built-in ROM library it includes functions to access some of the
23688  features, among them is a TCP stack with IP4 and IP6 support.
23689  Library headers (currently in beta status) and other files are provided
23690  at 
23691 \size footnotesize
23692
23693 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
23694
23695 \end_inset
23696
23697 .
23698  
23699 \begin_inset VSpace bigskip
23700 \end_inset
23701
23702
23703 \end_layout
23704
23705 \begin_layout Section
23706 The Z80 and gbz80 port
23707 \end_layout
23708
23709 \begin_layout Standard
23710 SDCC can target both the Zilog Z80
23711 \begin_inset LatexCommand \index{Z80}
23712
23713 \end_inset
23714
23715  and the Nintendo Gameboy's Z80-like gbz80
23716 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
23717
23718 \end_inset
23719
23720 .
23721  The Z80 port is passed through the same 
23722 \emph on
23723 regressions tests
23724 \begin_inset LatexCommand \index{Regression test}
23725
23726 \end_inset
23727
23728
23729 \emph default
23730  (see section 
23731 \begin_inset LatexCommand \ref{sec:Quality-control}
23732
23733 \end_inset
23734
23735 ) as the MCS51 and DS390 ports, so floating point support, support for long
23736  variables and bitfield support is fine.
23737  See mailing lists and forums about interrupt routines.
23738 \end_layout
23739
23740 \begin_layout Standard
23741 As always, the code is the authoritative reference - see z80/ralloc.c and
23742  z80/gen.c.
23743  The stack
23744 \begin_inset LatexCommand \index{Z80!stack}
23745
23746 \end_inset
23747
23748  frame is similar to that generated by the IAR Z80 compiler.
23749  IX is used as the base pointer, HL and IY are used as a temporary registers,
23750  and BC and DE are available for holding variables.
23751  Return values
23752 \begin_inset LatexCommand \index{Z80!return value}
23753
23754 \end_inset
23755
23756  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
23757  bytes).
23758  The gbz80 port use the same set of registers for the return values, but
23759  in a different order of significance: E (one byte), DE (two bytes), or
23760  HLDE (four bytes).
23761 \begin_inset VSpace bigskip
23762 \end_inset
23763
23764
23765 \end_layout
23766
23767 \begin_layout Section
23768 The HC08 port
23769 \end_layout
23770
23771 \begin_layout Standard
23772 The port to the Freescale/Motorola HC08
23773 \begin_inset LatexCommand \index{HC08}
23774
23775 \end_inset
23776
23777  family has been added in October 2003, and is still undergoing some basic
23778  development.
23779  The code generator is complete, but the register allocation is still quite
23780  unoptimized.
23781  Some of the SDCC's standard C library functions have embedded non-HC08
23782  inline assembly and so are not yet usable.
23783 \end_layout
23784
23785 \begin_layout Standard
23786 The HC08 port passes the regression test suite (see section 
23787 \begin_inset LatexCommand \ref{sec:Quality-control}
23788
23789 \end_inset
23790
23791 ).
23792 \begin_inset VSpace bigskip
23793 \end_inset
23794
23795
23796 \end_layout
23797
23798 \begin_layout Section
23799 The PIC14
23800 \begin_inset LatexCommand \index{PIC14}
23801
23802 \end_inset
23803
23804  port
23805 \end_layout
23806
23807 \begin_layout Standard
23808 The PIC14 port adds support for Microchip
23809 \begin_inset LatexCommand \index{Microchip}
23810
23811 \end_inset
23812
23813
23814 \begin_inset Formula $^{\text{TM}}$
23815 \end_inset
23816
23817  PIC
23818 \begin_inset LatexCommand \index{PIC14}
23819
23820 \end_inset
23821
23822
23823 \begin_inset Formula $^{\text{TM}}$
23824 \end_inset
23825
23826  MCUs with 14 bit wide instructions.
23827  This port is not yet mature and still lacks many features.
23828  However, it can work for simple code.
23829 \end_layout
23830
23831 \begin_layout Standard
23832 Currently supported devices include:
23833 \end_layout
23834
23835 \begin_layout Standard
23836 12F: 629, 635, 675, 683
23837 \end_layout
23838
23839 \begin_layout Standard
23840 16C: 432, 433
23841 \end_layout
23842
23843 \begin_layout Standard
23844 16C: 554, 557, 558
23845 \end_layout
23846
23847 \begin_layout Standard
23848 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
23849 \end_layout
23850
23851 \begin_layout Standard
23852 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
23853  781, 782
23854 \end_layout
23855
23856 \begin_layout Standard
23857 16C: 925, 926
23858 \end_layout
23859
23860 \begin_layout Standard
23861 16CR: 620a, 73, 74, 76, 77
23862 \end_layout
23863
23864 \begin_layout Standard
23865 16F: 616, 627, 627a, 628, 628a, 630, 636, 639, 648, 648a, 676, 684, 685,
23866  687, 688, 689, 690
23867 \end_layout
23868
23869 \begin_layout Standard
23870 16F: 716, 72, 73, 737, 74, 747, 76, 767, 77, 777, 785
23871 \end_layout
23872
23873 \begin_layout Standard
23874 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
23875  877, 877a, 88, 886, 887
23876 \end_layout
23877
23878 \begin_layout Standard
23879 16F: 913, 914, 916, 917, 946
23880 \end_layout
23881
23882 \begin_layout Standard
23883 26HV: 626, 785
23884 \end_layout
23885
23886 \begin_layout Standard
23887 An up-to-date list of currently supported devices can be obtained via 
23888 \family typewriter
23889 sdcc -mpic14 -phelp foo.c
23890 \family default
23891  (foo.c must exist...).
23892 \end_layout
23893
23894 \begin_layout Subsection
23895 PIC Code Pages
23896 \begin_inset LatexCommand \index{code page (pic14)}
23897
23898 \end_inset
23899
23900  and Memory Banks
23901 \begin_inset LatexCommand \index{Memory bank (pic14)}
23902
23903 \end_inset
23904
23905
23906 \end_layout
23907
23908 \begin_layout Standard
23909 The linker organizes allocation for the code page and RAM banks.
23910  It does not have intimate knowledge of the code flow.
23911  It will put all the code section of a single .asm file into a single code
23912  page.
23913  In order to make use of multiple code pages, separate asm files must be
23914  used.
23915  The compiler assigns all 
23916 \emph on
23917 static
23918 \emph default
23919  functions of a single .c file into the same code page.
23920 \newline
23921
23922 \newline
23923 To get the best results,
23924  follow these guidelines:
23925 \end_layout
23926
23927 \begin_layout Enumerate
23928 Make local functions static, as non static functions require code page selection
23929  overhead.
23930 \newline
23931 Due to the way sdcc handles functions, place called functions prior
23932  to calling functions in the file wherever possible: Otherwise sdcc will
23933  insert unneccessary pagesel directives around the call, believing that
23934  the called function is externally defined.
23935 \end_layout
23936
23937 \begin_layout Enumerate
23938 For devices that have multiple code pages it is more efficient to use the
23939  same number of files as pages: Use up to 4 separate .c files for the 16F877,
23940  but only 2 files for the 16F874.
23941  This way the linker can put the code for each file into different code
23942  pages and there will be less page selection overhead.
23943 \end_layout
23944
23945 \begin_layout Enumerate
23946 And as for any 8 bit micro (especially for PIC14 as they have a very simple
23947  instruction set), use `unsigned char' wherever possible instead of `int'.
23948 \end_layout
23949
23950 \begin_layout Subsection
23951 Adding New Devices to the Port 
23952 \end_layout
23953
23954 \begin_layout Standard
23955 Adding support for a new 14
23956 \begin_inset ERT
23957 status open
23958
23959 \begin_layout Standard
23960
23961
23962 \backslash
23963 ,
23964 \end_layout
23965
23966 \end_inset
23967
23968 bit PIC MCU requires the following steps:
23969 \end_layout
23970
23971 \begin_layout Enumerate
23972 Create a new device description.
23973 \newline
23974 Each device is described in two files: pic16f*.h
23975  and pic16f*.c.
23976  These files primarily define SFRs, structs to access their bits, and symbolic
23977  configuration options.
23978  Both files can be generated from gputils' .inc files using the perl script
23979  
23980 \family typewriter
23981 support/scripts/inc2h.pl
23982 \family default
23983 .
23984  This file also contains further instructions on how to proceed.
23985 \end_layout
23986
23987 \begin_layout Enumerate
23988 Copy the .h file into SDCC's include path and either add the .c file to your
23989  project or copy it to 
23990 \family typewriter
23991 device/lib/pic/libdev
23992 \family default
23993 .
23994  Afterwards, rebuild and install the libraries.
23995 \end_layout
23996
23997 \begin_layout Enumerate
23998 Edit pic14devices.txt in SDCC's include path (
23999 \family typewriter
24000 device/include/pic/
24001 \family default
24002  in the source tree or 
24003 \family typewriter
24004 /usr/local/share/sdcc/include/pic
24005 \family default
24006  after installation).
24007 \newline
24008 You need to add a device specification here to make
24009  the memory layout (code banks, RAM, aliased memory regions, ...) known to
24010  the compiler.
24011  Probably you can copy and modify an existing entry.
24012  The file format is documented at the top of the file.
24013 \end_layout
24014
24015 \begin_layout Subsection
24016 Interrupt Code
24017 \end_layout
24018
24019 \begin_layout Standard
24020 For the interrupt function, use the keyword `__interrupt'
24021 \begin_inset LatexCommand \index{PIC14!interrupt}
24022
24023 \end_inset
24024
24025  with level number of 0 (PIC14 only has 1 interrupt so this number is only
24026  there to avoid a syntax error - it ought to be fixed).
24027  E.g.:
24028 \end_layout
24029
24030 \begin_layout Verse
24031
24032 \family typewriter
24033 void Intr(void) __interrupt 0
24034 \newline
24035 {
24036 \newline
24037 \InsetSpace ~
24038 \InsetSpace ~
24039 T0IF = 0; /* Clear timer interrupt */
24040 \newline
24041 }
24042 \end_layout
24043
24044 \begin_layout Subsection
24045 Linking and Assembling
24046 \end_layout
24047
24048 \begin_layout Standard
24049 For assembling you can use either GPUTILS'
24050 \begin_inset LatexCommand \index{gputils (pic tools)}
24051
24052 \end_inset
24053
24054  gpasm.exe or MPLAB's mpasmwin.exe.
24055  GPUTILS are available from 
24056 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24057
24058 \end_inset
24059
24060 .
24061  For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
24062  If you use MPLAB and an interrupt function then the linker script file
24063  vectors section will need to be enlarged to link with mplink.
24064 \newline
24065
24066 \newline
24067 Here is a 
24068 \family typewriter
24069 Makefile
24070 \family default
24071  using GPUTILS:
24072 \end_layout
24073
24074 \begin_layout Verse
24075
24076 \family typewriter
24077 .c.o:
24078 \newline
24079 \InsetSpace ~
24080 \InsetSpace ~
24081 \InsetSpace ~
24082 \InsetSpace ~
24083 \InsetSpace ~
24084 \InsetSpace ~
24085 \InsetSpace ~
24086 \InsetSpace ~
24087 sdcc -V -mpic14 -p16f877 -c $< 
24088 \newline
24089
24090 \newline
24091 $(PRJ).hex: $(OBJS) 
24092 \newline
24093 \InsetSpace ~
24094 \InsetSpace ~
24095 \InsetSpace ~
24096 \InsetSpace ~
24097 \InsetSpace ~
24098 \InsetSpace ~
24099 \InsetSpace ~
24100 \InsetSpace ~
24101 gplink -m -s $(PRJ).lkr
24102  -o $(PRJ).hex $(OBJS) libsdcc.lib
24103 \end_layout
24104
24105 \begin_layout Standard
24106 Here is a 
24107 \family typewriter
24108 Makefile
24109 \family default
24110  using MPLAB:
24111 \end_layout
24112
24113 \begin_layout Verse
24114
24115 \family typewriter
24116 .c.o: 
24117 \newline
24118 \InsetSpace ~
24119 \InsetSpace ~
24120 \InsetSpace ~
24121 \InsetSpace ~
24122 \InsetSpace ~
24123 \InsetSpace ~
24124 \InsetSpace ~
24125 \InsetSpace ~
24126 sdcc -S -V -mpic14 -p16f877 $< 
24127 \newline
24128 \InsetSpace ~
24129 \InsetSpace ~
24130 \InsetSpace ~
24131 \InsetSpace ~
24132 \InsetSpace ~
24133 \InsetSpace ~
24134 \InsetSpace ~
24135 \InsetSpace ~
24136 mpasmwin /q /o $*.asm
24137 \newline
24138
24139 \newline
24140 $(PRJ).hex: $(OBJS)
24141  
24142 \newline
24143 \InsetSpace ~
24144 \InsetSpace ~
24145 \InsetSpace ~
24146 \InsetSpace ~
24147 \InsetSpace ~
24148 \InsetSpace ~
24149 \InsetSpace ~
24150 \InsetSpace ~
24151 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
24152 \end_layout
24153
24154 \begin_layout Standard
24155 Please note that indentations within a
24156 \family typewriter
24157  Makefile
24158 \family default
24159  have to be done with a tabulator character.
24160 \end_layout
24161
24162 \begin_layout Subsection
24163 Command-Line Options
24164 \end_layout
24165
24166 \begin_layout Standard
24167 Besides the switches common to all SDCC backends, the PIC14 port accepts
24168  the following options (for an updated list see sdcc -
24169 \begin_inset ERT
24170 status collapsed
24171
24172 \begin_layout Standard
24173
24174
24175 \backslash
24176 /
24177 \end_layout
24178
24179 \end_inset
24180
24181 -help):
24182 \end_layout
24183
24184 \begin_layout Description
24185 -
24186 \begin_inset ERT
24187 status collapsed
24188
24189 \begin_layout Standard
24190
24191
24192 \backslash
24193 /
24194 \end_layout
24195
24196 \end_inset
24197
24198 -debug-xtra
24199 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
24200
24201 \end_inset
24202
24203  emit debug info in assembly output
24204 \end_layout
24205
24206 \begin_layout Description
24207 -
24208 \begin_inset ERT
24209 status collapsed
24210
24211 \begin_layout Standard
24212
24213
24214 \backslash
24215 /
24216 \end_layout
24217
24218 \end_inset
24219
24220 -no-pcode-opt
24221 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
24222
24223 \end_inset
24224
24225  disable (slightly faulty) optimization on pCode
24226 \end_layout
24227
24228 \begin_layout Description
24229 -
24230 \begin_inset ERT
24231 status collapsed
24232
24233 \begin_layout Standard
24234
24235
24236 \backslash
24237 /
24238 \end_layout
24239
24240 \end_inset
24241
24242 -stack-loc
24243 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
24244
24245 \end_inset
24246
24247  sets the lowest address of the argument passing stack (defaults to a suitably
24248  large shared databank to reduce BANKSEL overhead)
24249 \end_layout
24250
24251 \begin_layout Description
24252 -
24253 \begin_inset ERT
24254 status collapsed
24255
24256 \begin_layout Standard
24257
24258
24259 \backslash
24260 /
24261 \end_layout
24262
24263 \end_inset
24264
24265 -stack-size
24266 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
24267
24268 \end_inset
24269
24270  sets the size if the argument passing stack (default: 16, minimum: 4)
24271 \end_layout
24272
24273 \begin_layout Subsection
24274 Environment Variables
24275 \end_layout
24276
24277 \begin_layout Standard
24278 The PIC14 port recognizes the following environment variables:
24279 \end_layout
24280
24281 \begin_layout Description
24282 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
24283  register (the ones called r0xNNNN) in a section of its own.
24284  By default (if this variable is unset), sdcc tries to cluster registers
24285  in sections in order to reduce the BANKSEL overhead when accessing them.
24286 \end_layout
24287
24288 \begin_layout Subsection
24289 The Library
24290 \end_layout
24291
24292 \begin_layout Standard
24293 The PIC14 library currently only contains support routines required by the
24294  compiler to implement multiplication, division, and floating point support.
24295  No libc-like replacement is available at the moment, though many of the
24296  common sdcc library sources (in 
24297 \family typewriter
24298 device/lib
24299 \family default
24300 ) should also compile with the PIC14 port.
24301 \end_layout
24302
24303 \begin_layout Subsubsection
24304 error: missing definition for symbol ``__gptrget1''
24305 \end_layout
24306
24307 \begin_layout Standard
24308 The PIC14 port uses library routines to provide more complex operations
24309  like multiplication, division/modulus and (generic) pointer dereferencing.
24310  In order to add these routines to your project, you must link with PIC14's
24311  
24312 \family typewriter
24313 libsdcc.lib
24314 \family default
24315 .
24316  For single source file projects this is done automatically, more complex
24317  projects must add 
24318 \family typewriter
24319 libsdcc.lib
24320 \family default
24321  to the linker's arguments.
24322  Make sure you also add an include path for the library (using the -I switch
24323  to the linker)!
24324 \end_layout
24325
24326 \begin_layout Subsubsection
24327 Processor mismatch in file ``XXX''.
24328 \end_layout
24329
24330 \begin_layout Standard
24331 This warning can usually be ignored due to the very good compatibility amongst
24332  14
24333 \begin_inset ERT
24334 status open
24335
24336 \begin_layout Standard
24337
24338
24339 \backslash
24340 ,
24341 \end_layout
24342
24343 \end_inset
24344
24345 bit PIC
24346 \begin_inset LatexCommand \index{PIC14}
24347
24348 \end_inset
24349
24350  devices.
24351 \end_layout
24352
24353 \begin_layout Standard
24354 You might also consider recompiling the library for your specific device
24355  by changing the ARCH=p16f877 (default target) entry in 
24356 \family typewriter
24357 device/lib/pic/Makefile.in
24358 \family default
24359  and 
24360 \family typewriter
24361 device/lib/pic/Makefile
24362 \family default
24363  to reflect your device.
24364  This might even improve performance for smaller devices as unneccesary
24365  BANKSELs might be removed.
24366 \end_layout
24367
24368 \begin_layout Subsection
24369 Known Bugs
24370 \end_layout
24371
24372 \begin_layout Subsubsection
24373 Function arguments
24374 \end_layout
24375
24376 \begin_layout Standard
24377 Functions with variable argument lists (like printf) are not yet supported.
24378  Similarly, taking the address of the first argument passed into a function
24379  does not work: It is currently passed in WREG and has no address...
24380 \end_layout
24381
24382 \begin_layout Subsubsection
24383 Regression tests fail
24384 \end_layout
24385
24386 \begin_layout Standard
24387 Though the small subset of regression tests in src/regression passes, SDCC
24388  regression test suite does not, indicating that there are still major bugs
24389  in the port.
24390  However, many smaller projects have successfully used SDCC in the past...
24391 \end_layout
24392
24393 \begin_layout Standard
24394
24395 \size footnotesize
24396
24397 \newpage
24398
24399 \end_layout
24400
24401 \begin_layout Section
24402 The PIC16
24403 \begin_inset LatexCommand \index{PIC16}
24404
24405 \end_inset
24406
24407  port
24408 \end_layout
24409
24410 \begin_layout Standard
24411 The PIC16 port adds support for Microchip
24412 \begin_inset LatexCommand \index{Microchip}
24413
24414 \end_inset
24415
24416
24417 \begin_inset Formula $^{\text{TM}}$
24418 \end_inset
24419
24420  PIC
24421 \begin_inset LatexCommand \index{PIC}
24422
24423 \end_inset
24424
24425
24426 \begin_inset Formula $^{\text{TM}}$
24427 \end_inset
24428
24429  MCUs with 16 bit wide instructions.
24430  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
24431 ; devices supported by the port include:
24432 \end_layout
24433
24434 \begin_layout Standard
24435 18F: 242, 248, 252, 258, 442, 448, 452, 458
24436 \end_layout
24437
24438 \begin_layout Standard
24439 18F: 1220, 1320
24440 \end_layout
24441
24442 \begin_layout Standard
24443 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 24j10, 2525, 2550, 25j10,
24444  2620
24445 \end_layout
24446
24447 \begin_layout Standard
24448 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 44j10, 4520, 4525, 4550,
24449  45j10, 4620
24450 \end_layout
24451
24452 \begin_layout Standard
24453 18F: 6520, 6620, 6680, 6720
24454 \end_layout
24455
24456 \begin_layout Standard
24457 18F: 8520, 8620, 8680, 8720
24458 \end_layout
24459
24460 \begin_layout Subsection
24461 Global Options
24462 \end_layout
24463
24464 \begin_layout Standard
24465 PIC16 port supports the standard command line arguments as supposed, with
24466  the exception of certain cases that will be mentioned in the following
24467  list:
24468 \end_layout
24469
24470 \begin_layout Description
24471 -
24472 \begin_inset ERT
24473 status collapsed
24474
24475 \begin_layout Standard
24476
24477
24478 \backslash
24479 /
24480 \end_layout
24481
24482 \end_inset
24483
24484 -callee-saves
24485 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
24486
24487 \end_inset
24488
24489  See -
24490 \begin_inset ERT
24491 status collapsed
24492
24493 \begin_layout Standard
24494
24495
24496 \backslash
24497 /
24498 \end_layout
24499
24500 \end_inset
24501
24502 -all-callee-saves
24503 \end_layout
24504
24505 \begin_layout Description
24506 -
24507 \begin_inset ERT
24508 status collapsed
24509
24510 \begin_layout Standard
24511
24512
24513 \backslash
24514 /
24515 \end_layout
24516
24517 \end_inset
24518
24519 -fommit-frame-pointer
24520 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
24521
24522 \end_inset
24523
24524  Frame pointer will be omitted when the function uses no local variables.
24525 \end_layout
24526
24527 \begin_layout Subsection
24528 Port Specific Options
24529 \begin_inset LatexCommand \index{Options PIC16}
24530
24531 \end_inset
24532
24533
24534 \end_layout
24535
24536 \begin_layout Standard
24537 The port specific options appear after the global options in the sdcc -
24538 \begin_inset ERT
24539 status collapsed
24540
24541 \begin_layout Standard
24542
24543
24544 \backslash
24545 /
24546 \end_layout
24547
24548 \end_inset
24549
24550 -help output.
24551 \end_layout
24552
24553 \begin_layout Subsubsection
24554 Code Generation Options
24555 \end_layout
24556
24557 \begin_layout Standard
24558 These options influence the generated assembler code.
24559 \end_layout
24560
24561 \begin_layout Description
24562 -
24563 \begin_inset ERT
24564 status collapsed
24565
24566 \begin_layout Standard
24567
24568
24569 \backslash
24570 /
24571 \end_layout
24572
24573 \end_inset
24574
24575 -pstack-model=[model] Used in conjuction with the command above.
24576  Defines the stack model to be used, valid stack models are:
24577 \end_layout
24578
24579 \begin_deeper
24580 \begin_layout List
24581 \labelwidthstring 00.00.0000
24582
24583 \emph on
24584 small
24585 \emph default
24586  Selects small stack model.
24587  8 bit stack and frame pointers.
24588  Supports 256 bytes stack size.
24589 \end_layout
24590
24591 \begin_layout List
24592 \labelwidthstring 00.00.0000
24593
24594 \emph on
24595 large
24596 \emph default
24597  Selects large stack model.
24598  16 bit stack and frame pointers.
24599  Supports 65536 bytes stack size.
24600 \end_layout
24601
24602 \end_deeper
24603 \begin_layout Description
24604 -
24605 \begin_inset ERT
24606 status collapsed
24607
24608 \begin_layout Standard
24609
24610
24611 \backslash
24612 /
24613 \end_layout
24614
24615 \end_inset
24616
24617 -pno-banksel Do not generate BANKSEL assembler directives.
24618 \end_layout
24619
24620 \begin_layout Description
24621 -
24622 \begin_inset ERT
24623 status collapsed
24624
24625 \begin_layout Standard
24626
24627
24628 \backslash
24629 /
24630 \end_layout
24631
24632 \end_inset
24633
24634 -extended Enable extended instruction set/literal offset addressing mode.
24635  Use with care!
24636 \end_layout
24637
24638 \begin_layout Subsubsection
24639 Optimization Options
24640 \end_layout
24641
24642 \begin_layout Description
24643 -
24644 \begin_inset ERT
24645 status collapsed
24646
24647 \begin_layout Standard
24648
24649
24650 \backslash
24651 /
24652 \end_layout
24653
24654 \end_inset
24655
24656 -obanksel=n Set optimization level for inserting BANKSELs.
24657 \newline
24658
24659 \end_layout
24660
24661 \begin_deeper
24662 \begin_layout List
24663 \labelwidthstring 00.00.0000
24664 0 no optimization
24665 \end_layout
24666
24667 \begin_layout List
24668 \labelwidthstring 00.00.0000
24669 1 checks previous used register and if it is the same then does not emit
24670  BANKSEL, accounts only for labels.
24671 \end_layout
24672
24673 \begin_layout List
24674 \labelwidthstring 00.00.0000
24675 2 tries to check the location of (even different) symbols and removes BANKSELs
24676  if they are in the same bank.
24677  
24678 \newline
24679
24680 \emph on
24681 Important: There might be problems if the linker script has data sections
24682  across bank borders!
24683 \end_layout
24684
24685 \end_deeper
24686 \begin_layout Description
24687 -
24688 \begin_inset ERT
24689 status collapsed
24690
24691 \begin_layout Standard
24692
24693
24694 \backslash
24695 /
24696 \end_layout
24697
24698 \end_inset
24699
24700 -denable-peeps Force the usage of peepholes.
24701  Use with care.
24702 \end_layout
24703
24704 \begin_layout Description
24705 -
24706 \begin_inset ERT
24707 status collapsed
24708
24709 \begin_layout Standard
24710
24711
24712 \backslash
24713 /
24714 \end_layout
24715
24716 \end_inset
24717
24718 -optimize-goto Try to use (conditional) BRA instead of GOTO.
24719 \end_layout
24720
24721 \begin_layout Description
24722 -
24723 \begin_inset ERT
24724 status collapsed
24725
24726 \begin_layout Standard
24727
24728
24729 \backslash
24730 /
24731 \end_layout
24732
24733 \end_inset
24734
24735 -optimize-cmp Try to optimize some compares.
24736 \end_layout
24737
24738 \begin_layout Description
24739 -
24740 \begin_inset ERT
24741 status collapsed
24742
24743 \begin_layout Standard
24744
24745
24746 \backslash
24747 /
24748 \end_layout
24749
24750 \end_inset
24751
24752 -optimize-df Analyze the dataflow of the generated code and improve it.
24753 \end_layout
24754
24755 \begin_layout Subsubsection
24756 Assembling Options
24757 \end_layout
24758
24759 \begin_layout Description
24760 -
24761 \begin_inset ERT
24762 status collapsed
24763
24764 \begin_layout Standard
24765
24766
24767 \backslash
24768 /
24769 \end_layout
24770
24771 \end_inset
24772
24773 -asm= Sets the full path and name of an external assembler to call.
24774 \end_layout
24775
24776 \begin_layout Description
24777 -
24778 \begin_inset ERT
24779 status collapsed
24780
24781 \begin_layout Standard
24782
24783
24784 \backslash
24785 /
24786 \end_layout
24787
24788 \end_inset
24789
24790 -mplab-comp MPLAB
24791 \begin_inset LatexCommand \index{PIC16!MPLAB}
24792
24793 \end_inset
24794
24795  compatibility option.
24796  Currently only suppresses special gpasm directives.
24797 \end_layout
24798
24799 \begin_layout Subsubsection
24800 Linking Options
24801 \end_layout
24802
24803 \begin_layout Description
24804 -
24805 \begin_inset ERT
24806 status collapsed
24807
24808 \begin_layout Standard
24809
24810
24811 \backslash
24812 /
24813 \end_layout
24814
24815 \end_inset
24816
24817 -link= Sets the full path and name of an external linker to call.
24818 \end_layout
24819
24820 \begin_layout Description
24821 -
24822 \begin_inset ERT
24823 status collapsed
24824
24825 \begin_layout Standard
24826
24827
24828 \backslash
24829 /
24830 \end_layout
24831
24832 \end_inset
24833
24834 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
24835  unitialized data variables with [kword].
24836  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
24837 \end_layout
24838
24839 \begin_layout Description
24840 -
24841 \begin_inset ERT
24842 status collapsed
24843
24844 \begin_layout Standard
24845
24846
24847 \backslash
24848 /
24849 \end_layout
24850
24851 \end_inset
24852
24853 -ivt-loc=n Place the interrupt vector table at address 
24854 \emph on
24855 n
24856 \emph default
24857 .
24858  Useful for bootloaders.
24859 \end_layout
24860
24861 \begin_layout Description
24862 -
24863 \begin_inset ERT
24864 status collapsed
24865
24866 \begin_layout Standard
24867
24868
24869 \backslash
24870 /
24871 \end_layout
24872
24873 \end_inset
24874
24875 -nodefaultlibs Do not link default libraries when linking.
24876 \end_layout
24877
24878 \begin_layout Description
24879 -
24880 \begin_inset ERT
24881 status collapsed
24882
24883 \begin_layout Standard
24884
24885
24886 \backslash
24887 /
24888 \end_layout
24889
24890 \end_inset
24891
24892 -use-crt= Use a custom run-time module instead of the defaults.
24893 \end_layout
24894
24895 \begin_layout Description
24896 -
24897 \begin_inset ERT
24898 status collapsed
24899
24900 \begin_layout Standard
24901
24902
24903 \backslash
24904 /
24905 \end_layout
24906
24907 \end_inset
24908
24909 -no-crt Don't link the default run-time modules
24910 \end_layout
24911
24912 \begin_layout Subsubsection
24913 Debugging Options
24914 \end_layout
24915
24916 \begin_layout Standard
24917 Debugging options enable extra debugging information in the output files.
24918 \end_layout
24919
24920 \begin_layout Description
24921 -
24922 \begin_inset ERT
24923 status collapsed
24924
24925 \begin_layout Standard
24926
24927
24928 \backslash
24929 /
24930 \end_layout
24931
24932 \end_inset
24933
24934 -debug-xtra Similar to -
24935 \begin_inset ERT
24936 status collapsed
24937
24938 \begin_layout Standard
24939
24940
24941 \backslash
24942 /
24943 \end_layout
24944
24945 \end_inset
24946
24947 -debug
24948 \begin_inset LatexCommand \index{-\/-debug}
24949
24950 \end_inset
24951
24952 , but dumps more information.
24953 \end_layout
24954
24955 \begin_layout Description
24956 -
24957 \begin_inset ERT
24958 status collapsed
24959
24960 \begin_layout Standard
24961
24962
24963 \backslash
24964 /
24965 \end_layout
24966
24967 \end_inset
24968
24969 -debug-ralloc Force register allocator to dump <source>.d file with debugging
24970  information.
24971  <source> is the name of the file being compiled.
24972 \end_layout
24973
24974 \begin_layout Description
24975 -
24976 \begin_inset ERT
24977 status collapsed
24978
24979 \begin_layout Standard
24980
24981
24982 \backslash
24983 /
24984 \end_layout
24985
24986 \end_inset
24987
24988 -pcode-verbose Enable pcode debugging information in translation.
24989 \end_layout
24990
24991 \begin_layout Description
24992 -
24993 \begin_inset ERT
24994 status collapsed
24995
24996 \begin_layout Standard
24997
24998
24999 \backslash
25000 /
25001 \end_layout
25002
25003 \end_inset
25004
25005 -calltree Dump call tree in .calltree file.
25006 \end_layout
25007
25008 \begin_layout Description
25009 -
25010 \begin_inset ERT
25011 status collapsed
25012
25013 \begin_layout Standard
25014
25015
25016 \backslash
25017 /
25018 \end_layout
25019
25020 \end_inset
25021
25022 -gstack Trace push/pops for stack pointer overflow.
25023 \end_layout
25024
25025 \begin_layout Subsection
25026 Enviroment Variables
25027 \end_layout
25028
25029 \begin_layout Standard
25030 There is a number of enviromental variables that can be used when running
25031  SDCC to enable certain optimizations or force a specific program behaviour.
25032  these variables are primarily for debugging purposes so they can be enabled/dis
25033 abled at will.
25034 \end_layout
25035
25036 \begin_layout Standard
25037 Currently there is only two such variables available:
25038 \end_layout
25039
25040 \begin_layout Description
25041 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
25042  bitfields is optimized by directly loading FSR0 with the address of the
25043  bitfield structure.
25044  Normally SDCC will cast the bitfield structure to a bitfield pointer and
25045  then load FSR0.
25046  This step saves data ram and code space for functions that make heavy use
25047  of bitfields.
25048  (i.e., 80 bytes of code space are saved when compiling malloc.c with this
25049  option).
25050  
25051 \end_layout
25052
25053 \begin_layout Description
25054 NO_REG_OPT Do not perform pCode registers optimization.
25055  This should be used for debugging purposes.
25056  If bugs in the pcode optimizer are found, users can benefit from temporarily
25057  disabling the optimizer until the bug is fixed.
25058 \end_layout
25059
25060 \begin_layout Subsection
25061 Preprocessor Macros
25062 \end_layout
25063
25064 \begin_layout Standard
25065 PIC16
25066 \begin_inset LatexCommand \index{PIC16}
25067
25068 \end_inset
25069
25070  port defines the following preprocessor macros while translating a source.
25071 \end_layout
25072
25073 \begin_layout Standard
25074 \align center
25075 \begin_inset Tabular
25076 <lyxtabular version="3" rows="6" columns="2">
25077 <features>
25078 <column alignment="center" valignment="top" leftline="true" width="0">
25079 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25080 <row topline="true" bottomline="true">
25081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25082 \begin_inset Text
25083
25084 \begin_layout Standard
25085 Macro
25086 \end_layout
25087
25088 \end_inset
25089 </cell>
25090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25091 \begin_inset Text
25092
25093 \begin_layout Standard
25094 Description
25095 \end_layout
25096
25097 \end_inset
25098 </cell>
25099 </row>
25100 <row topline="true">
25101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25102 \begin_inset Text
25103
25104 \begin_layout Standard
25105 SDCC_pic16
25106 \end_layout
25107
25108 \end_inset
25109 </cell>
25110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25111 \begin_inset Text
25112
25113 \begin_layout Standard
25114 Port identification
25115 \end_layout
25116
25117 \end_inset
25118 </cell>
25119 </row>
25120 <row topline="true">
25121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25122 \begin_inset Text
25123
25124 \begin_layout Standard
25125 _
25126 \begin_inset ERT
25127 status collapsed
25128
25129 \begin_layout Standard
25130
25131
25132 \backslash
25133 /
25134 \end_layout
25135
25136 \end_inset
25137
25138 _pic16
25139 \end_layout
25140
25141 \end_inset
25142 </cell>
25143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25144 \begin_inset Text
25145
25146 \begin_layout Standard
25147 Port identification (same as above)
25148 \end_layout
25149
25150 \end_inset
25151 </cell>
25152 </row>
25153 <row topline="true">
25154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25155 \begin_inset Text
25156
25157 \begin_layout Standard
25158 pic18fxxxx
25159 \end_layout
25160
25161 \end_inset
25162 </cell>
25163 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25164 \begin_inset Text
25165
25166 \begin_layout Standard
25167 MCU Identification.
25168  
25169 \emph on
25170 xxxx
25171 \emph default
25172  is the microcontrol identification number, i.e.
25173  452, 6620, etc
25174 \end_layout
25175
25176 \end_inset
25177 </cell>
25178 </row>
25179 <row topline="true">
25180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25181 \begin_inset Text
25182
25183 \begin_layout Standard
25184 _
25185 \begin_inset ERT
25186 status collapsed
25187
25188 \begin_layout Standard
25189
25190
25191 \backslash
25192 /
25193 \end_layout
25194
25195 \end_inset
25196
25197 _18Fxxxx
25198 \end_layout
25199
25200 \end_inset
25201 </cell>
25202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25203 \begin_inset Text
25204
25205 \begin_layout Standard
25206 MCU Identification (same as above)
25207 \end_layout
25208
25209 \end_inset
25210 </cell>
25211 </row>
25212 <row topline="true" bottomline="true">
25213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25214 \begin_inset Text
25215
25216 \begin_layout Standard
25217 STACK_MODEL_nnn
25218 \end_layout
25219
25220 \end_inset
25221 </cell>
25222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25223 \begin_inset Text
25224
25225 \begin_layout Standard
25226 nnn = SMALL or LARGE respectively according to the stack model used
25227 \end_layout
25228
25229 \end_inset
25230 </cell>
25231 </row>
25232 </lyxtabular>
25233
25234 \end_inset
25235
25236
25237 \end_layout
25238
25239 \begin_layout Standard
25240 In addition the following macros are defined when calling assembler:
25241 \end_layout
25242
25243 \begin_layout Standard
25244 \align center
25245 \begin_inset Tabular
25246 <lyxtabular version="3" rows="4" columns="2">
25247 <features>
25248 <column alignment="center" valignment="top" leftline="true" width="0">
25249 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25250 <row topline="true" bottomline="true">
25251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25252 \begin_inset Text
25253
25254 \begin_layout Standard
25255 Macro
25256 \end_layout
25257
25258 \end_inset
25259 </cell>
25260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25261 \begin_inset Text
25262
25263 \begin_layout Standard
25264 Description
25265 \end_layout
25266
25267 \end_inset
25268 </cell>
25269 </row>
25270 <row topline="true">
25271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25272 \begin_inset Text
25273
25274 \begin_layout Standard
25275 __18Fxxxx
25276 \end_layout
25277
25278 \end_inset
25279 </cell>
25280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25281 \begin_inset Text
25282
25283 \begin_layout Standard
25284 MCU Identification.
25285  
25286 \emph on
25287 xxxx
25288 \emph default
25289  is the microcontrol identification number, i.e.
25290  452, 6620, etc
25291 \end_layout
25292
25293 \end_inset
25294 </cell>
25295 </row>
25296 <row topline="true">
25297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25298 \begin_inset Text
25299
25300 \begin_layout Standard
25301 SDCC_MODEL_nnn
25302 \end_layout
25303
25304 \end_inset
25305 </cell>
25306 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25307 \begin_inset Text
25308
25309 \begin_layout Standard
25310 nnn = SMALL or LARGE respectively according to the memory model used for
25311  SDCC
25312 \end_layout
25313
25314 \end_inset
25315 </cell>
25316 </row>
25317 <row topline="true" bottomline="true">
25318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25319 \begin_inset Text
25320
25321 \begin_layout Standard
25322 STACK_MODEL_nnn
25323 \end_layout
25324
25325 \end_inset
25326 </cell>
25327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25328 \begin_inset Text
25329
25330 \begin_layout Standard
25331 nnn = SMALL or LARGE respectively according to the stack model used
25332 \end_layout
25333
25334 \end_inset
25335 </cell>
25336 </row>
25337 </lyxtabular>
25338
25339 \end_inset
25340
25341
25342 \end_layout
25343
25344 \begin_layout Subsection
25345 Directories
25346 \end_layout
25347
25348 \begin_layout Standard
25349 PIC16
25350 \begin_inset LatexCommand \index{PIC16}
25351
25352 \end_inset
25353
25354  port uses the following directories for searching header files and libraries.
25355 \end_layout
25356
25357 \begin_layout Standard
25358 \align center
25359 \begin_inset Tabular
25360 <lyxtabular version="3" rows="3" columns="4">
25361 <features>
25362 <column alignment="center" valignment="top" leftline="true" width="0">
25363 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25364 <column alignment="center" valignment="top" width="0">
25365 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25366 <row topline="true" bottomline="true">
25367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25368 \begin_inset Text
25369
25370 \begin_layout Standard
25371 Directory
25372 \end_layout
25373
25374 \end_inset
25375 </cell>
25376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25377 \begin_inset Text
25378
25379 \begin_layout Standard
25380 Description
25381 \end_layout
25382
25383 \end_inset
25384 </cell>
25385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25386 \begin_inset Text
25387
25388 \begin_layout Standard
25389 Target
25390 \end_layout
25391
25392 \end_inset
25393 </cell>
25394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25395 \begin_inset Text
25396
25397 \begin_layout Standard
25398 Command prefix
25399 \end_layout
25400
25401 \end_inset
25402 </cell>
25403 </row>
25404 <row topline="true">
25405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25406 \begin_inset Text
25407
25408 \begin_layout Standard
25409 PREFIX/sdcc/include/pic16
25410 \end_layout
25411
25412 \end_inset
25413 </cell>
25414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25415 \begin_inset Text
25416
25417 \begin_layout Standard
25418 PIC16 specific headers
25419 \end_layout
25420
25421 \end_inset
25422 </cell>
25423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25424 \begin_inset Text
25425
25426 \begin_layout Standard
25427 Compiler
25428 \end_layout
25429
25430 \end_inset
25431 </cell>
25432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25433 \begin_inset Text
25434
25435 \begin_layout Standard
25436 -I
25437 \end_layout
25438
25439 \end_inset
25440 </cell>
25441 </row>
25442 <row topline="true" bottomline="true">
25443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25444 \begin_inset Text
25445
25446 \begin_layout Standard
25447 PREFIX/sdcc/lib/pic16
25448 \end_layout
25449
25450 \end_inset
25451 </cell>
25452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25453 \begin_inset Text
25454
25455 \begin_layout Standard
25456 PIC16 specific libraries
25457 \end_layout
25458
25459 \end_inset
25460 </cell>
25461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25462 \begin_inset Text
25463
25464 \begin_layout Standard
25465 Linker
25466 \end_layout
25467
25468 \end_inset
25469 </cell>
25470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25471 \begin_inset Text
25472
25473 \begin_layout Standard
25474 -L
25475 \end_layout
25476
25477 \end_inset
25478 </cell>
25479 </row>
25480 </lyxtabular>
25481
25482 \end_inset
25483
25484
25485 \end_layout
25486
25487 \begin_layout Subsection
25488 Pragmas
25489 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
25490
25491 \end_inset
25492
25493
25494 \end_layout
25495
25496 \begin_layout Standard
25497 The PIC16
25498 \begin_inset LatexCommand \index{PIC16}
25499
25500 \end_inset
25501
25502  port currently supports the following pragmas:
25503 \end_layout
25504
25505 \begin_layout Description
25506 stack
25507 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
25508
25509 \end_inset
25510
25511  This forces the code generator to initialize the stack & frame pointers
25512  at a specific address.
25513  This is an ad hoc solution for cases where no STACK directive is available
25514  in the linker script or gplink is not instructed to create a stack section.
25515 \newline
25516 The
25517  stack pragma should be used only once in a project.
25518  Multiple pragmas may result in indeterminate behaviour of the program.
25519 \begin_inset Foot
25520 status open
25521
25522 \begin_layout Standard
25523 The old format (ie.
25524  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
25525  cross page boundaries (or even exceed the available data RAM) and crash
25526  the program.
25527  Make sure that stack does not cross page boundaries when using the SMALL
25528  stack model.
25529 \end_layout
25530
25531 \end_inset
25532
25533
25534 \newline
25535 The format is as follows:
25536 \newline
25537
25538 \end_layout
25539
25540 \begin_layout LyX-Code
25541 #pragma stack bottom_address [stack_size]
25542 \newline
25543
25544 \end_layout
25545
25546 \begin_layout Standard
25547
25548 \emph on
25549 bottom_address
25550 \emph default
25551  is the lower bound of the stack section.
25552  The stack pointer initially will point at address (bottom_address+stack_size-1).
25553 \end_layout
25554
25555 \begin_layout LyX-Code
25556 Example:
25557 \end_layout
25558
25559 \begin_layout LyX-Code
25560
25561 \end_layout
25562
25563 \begin_layout LyX-Code
25564 /* initializes stack of 100 bytes at RAM address 0x200 */
25565 \end_layout
25566
25567 \begin_layout LyX-Code
25568 #pragma stack 0x200 100
25569 \end_layout
25570
25571 \begin_layout Standard
25572 If the stack_size field is omitted then a stack is created with the default
25573  size of 64.
25574  This size might be enough for most programs, but its not enough for operations
25575  with deep function nesting or excessive stack usage.
25576 \end_layout
25577
25578 \begin_layout Description
25579 code
25580 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
25581
25582 \end_inset
25583
25584  Force a function to a static FLASH address.
25585 \end_layout
25586
25587 \begin_layout LyX-Code
25588 Example:
25589 \end_layout
25590
25591 \begin_layout LyX-Code
25592
25593 \end_layout
25594
25595 \begin_layout LyX-Code
25596 /* place function test_func at 0x4000 */
25597 \end_layout
25598
25599 \begin_layout LyX-Code
25600 #pragma code test_func 0x4000
25601 \end_layout
25602
25603 \begin_layout LyX-Code
25604
25605 \end_layout
25606
25607 \begin_layout Description
25608 library instructs the linker to use a library module.
25609 \newline
25610 Usage:
25611 \end_layout
25612
25613 \begin_layout LyX-Code
25614 #pragma library module_name
25615 \end_layout
25616
25617 \begin_layout Standard
25618
25619 \emph on
25620 module_name
25621 \emph default
25622  can be any library or object file (including its path).
25623  Note that there are four reserved keywords which have special meaning.
25624  These are:
25625 \end_layout
25626
25627 \begin_layout Standard
25628 \align center
25629 \begin_inset Tabular
25630 <lyxtabular version="3" rows="6" columns="3">
25631 <features>
25632 <column alignment="center" valignment="top" leftline="true" width="0">
25633 <column alignment="block" valignment="top" leftline="true" width="20page%">
25634 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
25635 <row topline="true" bottomline="true">
25636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25637 \begin_inset Text
25638
25639 \begin_layout Standard
25640 Keyword
25641 \end_layout
25642
25643 \end_inset
25644 </cell>
25645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25646 \begin_inset Text
25647
25648 \begin_layout Standard
25649 Description
25650 \end_layout
25651
25652 \end_inset
25653 </cell>
25654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25655 \begin_inset Text
25656
25657 \begin_layout Standard
25658 Module to link
25659 \end_layout
25660
25661 \end_inset
25662 </cell>
25663 </row>
25664 <row topline="true">
25665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25666 \begin_inset Text
25667
25668 \begin_layout Standard
25669
25670 \series bold
25671 ignore
25672 \end_layout
25673
25674 \end_inset
25675 </cell>
25676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25677 \begin_inset Text
25678
25679 \begin_layout Standard
25680 ignore all library pragmas
25681 \end_layout
25682
25683 \end_inset
25684 </cell>
25685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25686 \begin_inset Text
25687
25688 \begin_layout Standard
25689
25690 \emph on
25691 (none)
25692 \end_layout
25693
25694 \end_inset
25695 </cell>
25696 </row>
25697 <row topline="true">
25698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25699 \begin_inset Text
25700
25701 \begin_layout Standard
25702
25703 \series bold
25704 c
25705 \end_layout
25706
25707 \end_inset
25708 </cell>
25709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25710 \begin_inset Text
25711
25712 \begin_layout Standard
25713 link the C library
25714 \end_layout
25715
25716 \end_inset
25717 </cell>
25718 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25719 \begin_inset Text
25720
25721 \begin_layout Standard
25722
25723 \emph on
25724 libc18f
25725 \emph default
25726 .lib
25727 \end_layout
25728
25729 \end_inset
25730 </cell>
25731 </row>
25732 <row topline="true">
25733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25734 \begin_inset Text
25735
25736 \begin_layout Standard
25737
25738 \series bold
25739 math
25740 \end_layout
25741
25742 \end_inset
25743 </cell>
25744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25745 \begin_inset Text
25746
25747 \begin_layout Standard
25748 link the Math libarary
25749 \end_layout
25750
25751 \end_inset
25752 </cell>
25753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25754 \begin_inset Text
25755
25756 \begin_layout Standard
25757
25758 \emph on
25759 libm18f
25760 \emph default
25761 .lib
25762 \end_layout
25763
25764 \end_inset
25765 </cell>
25766 </row>
25767 <row topline="true">
25768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25769 \begin_inset Text
25770
25771 \begin_layout Standard
25772
25773 \series bold
25774 io
25775 \end_layout
25776
25777 \end_inset
25778 </cell>
25779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25780 \begin_inset Text
25781
25782 \begin_layout Standard
25783 link the I/O library
25784 \end_layout
25785
25786 \end_inset
25787 </cell>
25788 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25789 \begin_inset Text
25790
25791 \begin_layout Standard
25792
25793 \emph on
25794 libio18f*
25795 \emph default
25796 .lib
25797 \end_layout
25798
25799 \end_inset
25800 </cell>
25801 </row>
25802 <row topline="true" bottomline="true">
25803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25804 \begin_inset Text
25805
25806 \begin_layout Standard
25807
25808 \series bold
25809 debug
25810 \end_layout
25811
25812 \end_inset
25813 </cell>
25814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25815 \begin_inset Text
25816
25817 \begin_layout Standard
25818 link the debug library
25819 \end_layout
25820
25821 \end_inset
25822 </cell>
25823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25824 \begin_inset Text
25825
25826 \begin_layout Standard
25827
25828 \emph on
25829 libdebug
25830 \emph default
25831 .lib
25832 \end_layout
25833
25834 \end_inset
25835 </cell>
25836 </row>
25837 </lyxtabular>
25838
25839 \end_inset
25840
25841
25842 \newline
25843 * is the device number, i.e.
25844  452 for PIC18F452 MCU.
25845 \end_layout
25846
25847 \begin_layout Standard
25848 This feature allows for linking with specific libraries withoug having to
25849  explicit name them in the command line.
25850  Note that the 
25851 \noun on
25852 ignore
25853 \noun default
25854  keyword will reject all modules specified by the library pragma.
25855 \end_layout
25856
25857 \begin_layout Description
25858 udata The pragma udata instructs the compiler to emit code so that linker
25859  will place a variable at a specific memory bank.
25860 \end_layout
25861
25862 \begin_layout LyX-Code
25863 Example:
25864 \end_layout
25865
25866 \begin_layout LyX-Code
25867
25868 \end_layout
25869
25870 \begin_layout LyX-Code
25871 /* places variable foo at bank2 */
25872 \end_layout
25873
25874 \begin_layout LyX-Code
25875 #pragma udata bank2 foo
25876 \end_layout
25877
25878 \begin_layout LyX-Code
25879 char foo;
25880 \end_layout
25881
25882 \begin_layout Standard
25883 In order for this pragma to work extra SECTION directives should be added
25884  in the .lkr script.
25885  In the following example a sample .lkr file is shown:
25886 \end_layout
25887
25888 \begin_layout LyX-Code
25889
25890 \end_layout
25891
25892 \begin_layout LyX-Code
25893 // Sample linker script for the PIC18F452 processor
25894 \end_layout
25895
25896 \begin_layout LyX-Code
25897 LIBPATH .
25898 \end_layout
25899
25900 \begin_layout LyX-Code
25901 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
25902 \end_layout
25903
25904 \begin_layout LyX-Code
25905 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
25906 \end_layout
25907
25908 \begin_layout LyX-Code
25909 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
25910 \end_layout
25911
25912 \begin_layout LyX-Code
25913 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
25914 \end_layout
25915
25916 \begin_layout LyX-Code
25917 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
25918 \end_layout
25919
25920 \begin_layout LyX-Code
25921 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
25922 \end_layout
25923
25924 \begin_layout LyX-Code
25925 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
25926 \end_layout
25927
25928 \begin_layout LyX-Code
25929
25930 \end_layout
25931
25932 \begin_layout LyX-Code
25933 DATABANK   NAME=gpr0       START=0x80           END=0xFF
25934 \end_layout
25935
25936 \begin_layout LyX-Code
25937 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
25938 \end_layout
25939
25940 \begin_layout LyX-Code
25941 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
25942 \end_layout
25943
25944 \begin_layout LyX-Code
25945 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
25946 \end_layout
25947
25948 \begin_layout LyX-Code
25949 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
25950 \end_layout
25951
25952 \begin_layout LyX-Code
25953 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
25954 \end_layout
25955
25956 \begin_layout LyX-Code
25957 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
25958 \end_layout
25959
25960 \begin_layout LyX-Code
25961
25962 \end_layout
25963
25964 \begin_layout LyX-Code
25965 SECTION    NAME=CONFIG     ROM=config
25966 \end_layout
25967
25968 \begin_layout LyX-Code
25969
25970 \end_layout
25971
25972 \begin_layout LyX-Code
25973 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
25974 \end_layout
25975
25976 \begin_layout LyX-Code
25977 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
25978 \end_layout
25979
25980 \begin_layout LyX-Code
25981 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
25982 \end_layout
25983
25984 \begin_layout LyX-Code
25985 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
25986 \end_layout
25987
25988 \begin_layout LyX-Code
25989 SECTION    NAME=bank4      RAM=gpr4
25990 \end_layout
25991
25992 \begin_layout LyX-Code
25993 SECTION    NAME=bank5      RAM=gpr5
25994 \end_layout
25995
25996 \begin_layout Standard
25997 The linker will recognise the section name set in the pragma statement and
25998  will position the variable at the memory bank set with the RAM field at
25999  the SECTION line in the linker script file.
26000 \end_layout
26001
26002 \begin_layout Subsection
26003 Header Files
26004 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
26005
26006 \end_inset
26007
26008
26009 \end_layout
26010
26011 \begin_layout Standard
26012 There is one main header file
26013 \begin_inset LatexCommand \index{PIC16!Header files}
26014
26015 \end_inset
26016
26017  that can be included to the source files using the pic16
26018 \begin_inset LatexCommand \index{PIC16}
26019
26020 \end_inset
26021
26022  port.
26023  That file is the 
26024 \series bold
26025 pic18fregs.h
26026 \series default
26027 .
26028  This header file contains the definitions for the processor special registers,
26029  so it is necessary if the source accesses them.
26030  It can be included by adding the following line in the beginning of the
26031  file:
26032 \end_layout
26033
26034 \begin_layout LyX-Code
26035 #include <pic18fregs.h>
26036 \end_layout
26037
26038 \begin_layout Standard
26039 The specific microcontroller is selected within the pic18fregs.h automatically,
26040  so the same source can be used with a variety of devices.
26041 \end_layout
26042
26043 \begin_layout Subsection
26044 Libraries
26045 \end_layout
26046
26047 \begin_layout Standard
26048 The libraries
26049 \begin_inset LatexCommand \index{PIC16!Libraries}
26050
26051 \end_inset
26052
26053  that PIC16
26054 \begin_inset LatexCommand \index{PIC16}
26055
26056 \end_inset
26057
26058  port depends on are the microcontroller device libraries which contain
26059  the symbol definitions for the microcontroller special function registers.
26060  These libraries have the format pic18fxxxx.lib, where 
26061 \emph on
26062 xxxx
26063 \emph default
26064  is the microcontroller identification number.
26065  The specific library is selected automatically by the compiler at link
26066  stage according to the selected device.
26067 \end_layout
26068
26069 \begin_layout Standard
26070 Libraries are created with gplib which is part of the gputils package 
26071 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
26072
26073 \end_inset
26074
26075 .
26076 \end_layout
26077
26078 \begin_layout Subsubsection*
26079 Building the libraries
26080 \end_layout
26081
26082 \begin_layout Standard
26083 Before using SDCC/pic16 there are some libraries that need to be compiled.
26084  This process is not done automatically by SDCC since not all users use
26085  SDCC for pic16 projects.
26086  So each user should compile the libraries separately.
26087 \end_layout
26088
26089 \begin_layout Standard
26090 The steps to compile the pic16 libraries under Linux and Mac OS X are:
26091 \end_layout
26092
26093 \begin_layout LyX-Code
26094 cd device/lib/pic16
26095 \end_layout
26096
26097 \begin_layout LyX-Code
26098 ./configure
26099 \end_layout
26100
26101 \begin_layout LyX-Code
26102 make
26103 \end_layout
26104
26105 \begin_layout LyX-Code
26106 cd ..
26107 \end_layout
26108
26109 \begin_layout LyX-Code
26110 make model-pic16
26111 \end_layout
26112
26113 \begin_layout LyX-Code
26114 su -c 'make install'     # install the libraries, you need the root password
26115 \end_layout
26116
26117 \begin_layout Standard
26118 If you need to install the headers too, do:
26119 \end_layout
26120
26121 \begin_layout LyX-Code
26122 cd device/include
26123 \end_layout
26124
26125 \begin_layout LyX-Code
26126 su -c 'make install'     # install the headers, you need the root password
26127 \end_layout
26128
26129 \begin_layout Standard
26130 There exist a special target to build the I/O libraries.
26131  This target is not automatically build because it will build the I/O library
26132  for 
26133 \emph on
26134 every
26135 \emph default
26136  supported device.
26137  This way building will take quite a lot of time.
26138  Users are advised to edit the 
26139 \series bold
26140 device/lib/pic16/pics.build
26141 \series default
26142  file and then execute:
26143 \end_layout
26144
26145 \begin_layout LyX-Code
26146 make lib-io
26147 \end_layout
26148
26149 \begin_layout Subsection
26150 Adding New Devices to the Port
26151 \end_layout
26152
26153 \begin_layout Standard
26154 Adding support for a new 16
26155 \begin_inset ERT
26156 status open
26157
26158 \begin_layout Standard
26159
26160
26161 \backslash
26162 ,
26163 \end_layout
26164
26165 \end_inset
26166
26167 bit PIC MCU requires the following steps:
26168 \end_layout
26169
26170 \begin_layout Enumerate
26171 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
26172 \newline
26173
26174 \family typewriter
26175 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
26176 inc
26177 \end_layout
26178
26179 \begin_layout Enumerate
26180
26181 \family typewriter
26182 mv picDEVICE.h /path/to/sdcc/device/include/pic16
26183 \end_layout
26184
26185 \begin_layout Enumerate
26186
26187 \family typewriter
26188 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
26189 \end_layout
26190
26191 \begin_layout Enumerate
26192 Add DEVICE to 
26193 \family typewriter
26194 /path/to/sdcc/device/lib/pic16/pics.all
26195 \family default
26196  (and 
26197 \family typewriter
26198 .build
26199 \family default
26200 ).
26201 \newline
26202 Note: No 18f prefix here!
26203 \end_layout
26204
26205 \begin_layout Enumerate
26206 Adjust 
26207 \family typewriter
26208 /path/to/sdcc/device/lib/pic16/libio/*.ignore
26209 \family default
26210
26211 \newline
26212 Add your DEVICE if it does not compile in 
26213 \family typewriter
26214 adc
26215 \family default
26216
26217 \family typewriter
26218 i2c
26219 \family default
26220 , or 
26221 \family typewriter
26222 usart
26223 \family default
26224 .
26225 \end_layout
26226
26227 \begin_layout Enumerate
26228 Edit 
26229 \family typewriter
26230 /path/to/sdcc/device/include/pic16/pic18fregs.h
26231 \family default
26232 .
26233  The file format is self-explanatory, just add
26234 \newline
26235
26236 \family typewriter
26237 #elif defined(picDEVICE)
26238 \newline
26239 # include <picDEVICE.h>
26240 \family default
26241
26242 \newline
26243 at the right place (keep it sorted).
26244 \end_layout
26245
26246 \begin_layout Enumerate
26247 Edit 
26248 \family typewriter
26249 /path/to/sdcc/src/pic16/devices.inc
26250 \family default
26251 .
26252  Copy and modify an existing entry and insert it at the correct place (keep
26253  the file sorted).
26254  The file is hardly documented, look at the entries for the 18f2221...
26255 \end_layout
26256
26257 \begin_layout Enumerate
26258 Recompile SDCC, including the pic16 libraries.
26259 \end_layout
26260
26261 \begin_layout Subsection
26262 Memory Models
26263 \end_layout
26264
26265 \begin_layout Standard
26266 The following memory models are supported by the PIC16 port:
26267 \end_layout
26268
26269 \begin_layout Itemize
26270 small model
26271 \end_layout
26272
26273 \begin_layout Itemize
26274 large model
26275 \end_layout
26276
26277 \begin_layout Standard
26278 Memory model affects the default size of pointers within the source.
26279  The sizes are shown in the next table:
26280 \end_layout
26281
26282 \begin_layout Standard
26283 \align center
26284 \begin_inset Tabular
26285 <lyxtabular version="3" rows="3" columns="3">
26286 <features>
26287 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26288 <column alignment="center" valignment="top" leftline="true" width="0">
26289 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26290 <row topline="true" bottomline="true">
26291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26292 \begin_inset Text
26293
26294 \begin_layout Standard
26295 Pointer sizes according to memory model
26296 \end_layout
26297
26298 \end_inset
26299 </cell>
26300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26301 \begin_inset Text
26302
26303 \begin_layout Standard
26304 small model
26305 \end_layout
26306
26307 \end_inset
26308 </cell>
26309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26310 \begin_inset Text
26311
26312 \begin_layout Standard
26313 large model
26314 \end_layout
26315
26316 \end_inset
26317 </cell>
26318 </row>
26319 <row topline="true" bottomline="true">
26320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26321 \begin_inset Text
26322
26323 \begin_layout Standard
26324 code pointers
26325 \end_layout
26326
26327 \end_inset
26328 </cell>
26329 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26330 \begin_inset Text
26331
26332 \begin_layout Standard
26333 16-bits
26334 \end_layout
26335
26336 \end_inset
26337 </cell>
26338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26339 \begin_inset Text
26340
26341 \begin_layout Standard
26342 24-bits
26343 \end_layout
26344
26345 \end_inset
26346 </cell>
26347 </row>
26348 <row topline="true" bottomline="true">
26349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26350 \begin_inset Text
26351
26352 \begin_layout Standard
26353 data pointers
26354 \end_layout
26355
26356 \end_inset
26357 </cell>
26358 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
26359 \begin_inset Text
26360
26361 \begin_layout Standard
26362 16-bits
26363 \end_layout
26364
26365 \end_inset
26366 </cell>
26367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26368 \begin_inset Text
26369
26370 \begin_layout Standard
26371 16-bits
26372 \end_layout
26373
26374 \end_inset
26375 </cell>
26376 </row>
26377 </lyxtabular>
26378
26379 \end_inset
26380
26381
26382 \end_layout
26383
26384 \begin_layout Standard
26385 It is advisable that all sources within a project are compiled with the
26386  same memory model.
26387  If one wants to override the default memory model, this can be done by
26388  declaring a pointer as 
26389 \series bold
26390 far
26391 \series default
26392  or 
26393 \series bold
26394 near
26395 \series default
26396 .
26397  Far selects large memory model's pointers, while near selects small memory
26398  model's pointers.
26399 \end_layout
26400
26401 \begin_layout Standard
26402 The standard device libraries (see 
26403 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
26404
26405 \end_inset
26406
26407 ) contain no reference to pointers, so they can be used with both memory
26408  models.
26409 \end_layout
26410
26411 \begin_layout Subsection
26412 Stack
26413 \end_layout
26414
26415 \begin_layout Standard
26416 The stack
26417 \begin_inset LatexCommand \index{PIC16!stack}
26418
26419 \end_inset
26420
26421  implementation for the PIC16 port uses two indirect registers, FSR1 and
26422  FSR2.
26423 \end_layout
26424
26425 \begin_layout Description
26426 FSR1 is assigned as stack pointer
26427 \end_layout
26428
26429 \begin_layout Description
26430 FSR2 is assigned as frame pointer
26431 \end_layout
26432
26433 \begin_layout Standard
26434 The following stack models are supported by the PIC16 port
26435 \end_layout
26436
26437 \begin_layout Itemize
26438
26439 \noun on
26440 small
26441 \noun default
26442  model
26443 \end_layout
26444
26445 \begin_layout Itemize
26446
26447 \noun on
26448 large
26449 \noun default
26450  model
26451 \end_layout
26452
26453 \begin_layout Standard
26454
26455 \noun on
26456 Small
26457 \noun default
26458  model means that only the FSRxL byte is used to access stack and frame,
26459  while 
26460 \emph on
26461 \noun on
26462 large
26463 \emph default
26464 \noun default
26465  uses both FSRxL and FSRxH registers.
26466  The following table shows the stack/frame pointers sizes according to stack
26467  model and the maximum space they can address:
26468 \end_layout
26469
26470 \begin_layout Standard
26471 \align center
26472 \begin_inset Tabular
26473 <lyxtabular version="3" rows="3" columns="3">
26474 <features>
26475 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26476 <column alignment="center" valignment="top" leftline="true" width="0">
26477 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26478 <row topline="true" bottomline="true">
26479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26480 \begin_inset Text
26481
26482 \begin_layout Standard
26483 Stack & Frame pointer sizes according to stack model
26484 \end_layout
26485
26486 \end_inset
26487 </cell>
26488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26489 \begin_inset Text
26490
26491 \begin_layout Standard
26492 small
26493 \end_layout
26494
26495 \end_inset
26496 </cell>
26497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26498 \begin_inset Text
26499
26500 \begin_layout Standard
26501 large
26502 \end_layout
26503
26504 \end_inset
26505 </cell>
26506 </row>
26507 <row topline="true">
26508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26509 \begin_inset Text
26510
26511 \begin_layout Standard
26512 Stack pointer FSR1
26513 \end_layout
26514
26515 \end_inset
26516 </cell>
26517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26518 \begin_inset Text
26519
26520 \begin_layout Standard
26521 8-bits
26522 \end_layout
26523
26524 \end_inset
26525 </cell>
26526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26527 \begin_inset Text
26528
26529 \begin_layout Standard
26530 16-bits
26531 \end_layout
26532
26533 \end_inset
26534 </cell>
26535 </row>
26536 <row topline="true" bottomline="true">
26537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26538 \begin_inset Text
26539
26540 \begin_layout Standard
26541 Frame pointer FSR2
26542 \end_layout
26543
26544 \end_inset
26545 </cell>
26546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26547 \begin_inset Text
26548
26549 \begin_layout Standard
26550 8-bits
26551 \end_layout
26552
26553 \end_inset
26554 </cell>
26555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26556 \begin_inset Text
26557
26558 \begin_layout Standard
26559 16-bits
26560 \end_layout
26561
26562 \end_inset
26563 </cell>
26564 </row>
26565 </lyxtabular>
26566
26567 \end_inset
26568
26569
26570 \end_layout
26571
26572 \begin_layout Standard
26573
26574 \noun on
26575 Large 
26576 \noun default
26577 stack model is currently not working properly throughout the code generator.
26578  So its use is not advised.
26579  Also there are some other points that need special care:
26580 \newline
26581
26582 \end_layout
26583
26584 \begin_layout Enumerate
26585 Do not create stack sections with size more than one physical bank (that
26586  is 256 bytes)
26587 \end_layout
26588
26589 \begin_layout Enumerate
26590 Stack sections should no cross physical bank limits (i.e.
26591  #pragma stack 0x50 0x100)
26592 \end_layout
26593
26594 \begin_layout Standard
26595 These limitations are caused by the fact that only FSRxL is modified when
26596  using SMALL stack model, so no more than 256 bytes of stack can be used.
26597  This problem will disappear after LARGE model is fully implemented.
26598 \end_layout
26599
26600 \begin_layout Subsection
26601 Functions
26602 \end_layout
26603
26604 \begin_layout Standard
26605 In addition to the standard SDCC function keywords, PIC16
26606 \begin_inset LatexCommand \index{PIC16}
26607
26608 \end_inset
26609
26610  port makes available two more:
26611 \end_layout
26612
26613 \begin_layout Description
26614 wparam
26615 \begin_inset LatexCommand \index{PIC16!wparam}
26616
26617 \end_inset
26618
26619  Use the WREG to pass one byte of the first function argument.
26620  This improves speed but you may not use this for functions with arguments
26621  that are called via function pointers, otherwise the first byte of the
26622  first parameter will get lost.
26623  Usage:
26624 \end_layout
26625
26626 \begin_layout LyX-Code
26627 void func_wparam(int a) wparam
26628 \end_layout
26629
26630 \begin_layout LyX-Code
26631 {
26632 \end_layout
26633
26634 \begin_layout LyX-Code
26635     /* WREG hold the lower part of a */
26636 \end_layout
26637
26638 \begin_layout LyX-Code
26639     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
26640  */
26641 \end_layout
26642
26643 \begin_layout LyX-Code
26644 ...
26645 \end_layout
26646
26647 \begin_layout LyX-Code
26648 }
26649 \end_layout
26650
26651 \begin_layout Description
26652 shadowregs
26653 \begin_inset LatexCommand \index{PIC16!shadowregs}
26654
26655 \end_inset
26656
26657  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
26658  hardware shadow registers which hold the values of WREG, STATUS and BSR
26659  registers.
26660  This can be done by adding the keyword 
26661 \emph on
26662 shadowregs
26663 \emph default
26664  before the 
26665 \emph on
26666 interrupt
26667 \emph default
26668  keyword in the function's header.
26669 \end_layout
26670
26671 \begin_layout LyX-Code
26672 void isr_shadow(void) shadowregs interrupt 1
26673 \end_layout
26674
26675 \begin_layout LyX-Code
26676 {
26677 \end_layout
26678
26679 \begin_layout LyX-Code
26680 ...
26681 \end_layout
26682
26683 \begin_layout LyX-Code
26684 }
26685 \end_layout
26686
26687 \begin_layout Standard
26688
26689 \emph on
26690 shadowregs
26691 \emph default
26692  instructs the code generator not to store/restore WREG, STATUS, BSR when
26693  entering/exiting the ISR.
26694 \end_layout
26695
26696 \begin_layout Subsection
26697 Function return values
26698 \end_layout
26699
26700 \begin_layout Standard
26701 Return values from functions are placed to the appropriate registers following
26702  a modified Microchip policy optimized for SDCC.
26703  The following table shows these registers:
26704 \end_layout
26705
26706 \begin_layout Standard
26707 \align center
26708 \begin_inset Tabular
26709 <lyxtabular version="3" rows="6" columns="2">
26710 <features>
26711 <column alignment="center" valignment="top" leftline="true" width="0">
26712 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26713 <row topline="true" bottomline="true">
26714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26715 \begin_inset Text
26716
26717 \begin_layout Standard
26718 size
26719 \end_layout
26720
26721 \end_inset
26722 </cell>
26723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26724 \begin_inset Text
26725
26726 \begin_layout Standard
26727 destination register
26728 \end_layout
26729
26730 \end_inset
26731 </cell>
26732 </row>
26733 <row topline="true">
26734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26735 \begin_inset Text
26736
26737 \begin_layout Standard
26738 8 bits
26739 \end_layout
26740
26741 \end_inset
26742 </cell>
26743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26744 \begin_inset Text
26745
26746 \begin_layout Standard
26747 WREG
26748 \end_layout
26749
26750 \end_inset
26751 </cell>
26752 </row>
26753 <row topline="true">
26754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26755 \begin_inset Text
26756
26757 \begin_layout Standard
26758 16 bits
26759 \end_layout
26760
26761 \end_inset
26762 </cell>
26763 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26764 \begin_inset Text
26765
26766 \begin_layout Standard
26767 PRODL:WREG
26768 \end_layout
26769
26770 \end_inset
26771 </cell>
26772 </row>
26773 <row topline="true">
26774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26775 \begin_inset Text
26776
26777 \begin_layout Standard
26778 24 bits
26779 \end_layout
26780
26781 \end_inset
26782 </cell>
26783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26784 \begin_inset Text
26785
26786 \begin_layout Standard
26787 PRODH:PRODL:WREG
26788 \end_layout
26789
26790 \end_inset
26791 </cell>
26792 </row>
26793 <row topline="true">
26794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26795 \begin_inset Text
26796
26797 \begin_layout Standard
26798 32 bits
26799 \end_layout
26800
26801 \end_inset
26802 </cell>
26803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26804 \begin_inset Text
26805
26806 \begin_layout Standard
26807 FSR0L:PRODH:PRODL:WREG
26808 \end_layout
26809
26810 \end_inset
26811 </cell>
26812 </row>
26813 <row topline="true" bottomline="true">
26814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26815 \begin_inset Text
26816
26817 \begin_layout Standard
26818 >32 bits
26819 \end_layout
26820
26821 \end_inset
26822 </cell>
26823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26824 \begin_inset Text
26825
26826 \begin_layout Standard
26827 on stack, FSR0 points to the beginning
26828 \end_layout
26829
26830 \end_inset
26831 </cell>
26832 </row>
26833 </lyxtabular>
26834
26835 \end_inset
26836
26837
26838 \end_layout
26839
26840 \begin_layout Subsection
26841 Interrupts
26842 \end_layout
26843
26844 \begin_layout Standard
26845 An interrupt
26846 \begin_inset LatexCommand \index{PIC16!interrupt}
26847
26848 \end_inset
26849
26850  service routine (ISR) is declared using the 
26851 \emph on
26852 interrupt
26853 \emph default
26854  keyword.
26855 \end_layout
26856
26857 \begin_layout LyX-Code
26858 void isr(void) interrupt 
26859 \emph on
26860 n
26861 \end_layout
26862
26863 \begin_layout LyX-Code
26864 {
26865 \end_layout
26866
26867 \begin_layout LyX-Code
26868 ...
26869 \end_layout
26870
26871 \begin_layout LyX-Code
26872 }
26873 \end_layout
26874
26875 \begin_layout Standard
26876
26877 \emph on
26878 n
26879 \emph default
26880  is the interrupt number, which for PIC18F devices can be:
26881 \end_layout
26882
26883 \begin_layout Standard
26884 \align center
26885 \begin_inset Tabular
26886 <lyxtabular version="3" rows="4" columns="3">
26887 <features>
26888 <column alignment="center" valignment="top" leftline="true" width="0">
26889 <column alignment="center" valignment="top" leftline="true" width="0">
26890 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26891 <row topline="true" bottomline="true">
26892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26893 \begin_inset Text
26894
26895 \begin_layout Standard
26896
26897 \emph on
26898 n
26899 \end_layout
26900
26901 \end_inset
26902 </cell>
26903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26904 \begin_inset Text
26905
26906 \begin_layout Standard
26907 Interrupt Vector
26908 \end_layout
26909
26910 \end_inset
26911 </cell>
26912 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26913 \begin_inset Text
26914
26915 \begin_layout Standard
26916 Interrupt Vector Address
26917 \end_layout
26918
26919 \end_inset
26920 </cell>
26921 </row>
26922 <row topline="true">
26923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26924 \begin_inset Text
26925
26926 \begin_layout Standard
26927 0
26928 \end_layout
26929
26930 \end_inset
26931 </cell>
26932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26933 \begin_inset Text
26934
26935 \begin_layout Standard
26936 RESET vector
26937 \end_layout
26938
26939 \end_inset
26940 </cell>
26941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26942 \begin_inset Text
26943
26944 \begin_layout Standard
26945 0x000000
26946 \end_layout
26947
26948 \end_inset
26949 </cell>
26950 </row>
26951 <row topline="true">
26952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26953 \begin_inset Text
26954
26955 \begin_layout Standard
26956
26957 \family roman
26958 \series medium
26959 \shape up
26960 \size normal
26961 \emph off
26962 \bar no
26963 \noun off
26964 \color none
26965 1
26966 \end_layout
26967
26968 \end_inset
26969 </cell>
26970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26971 \begin_inset Text
26972
26973 \begin_layout Standard
26974
26975 \family roman
26976 \series medium
26977 \shape up
26978 \size normal
26979 \emph off
26980 \bar no
26981 \noun off
26982 \color none
26983 HIGH priority interrupts
26984 \end_layout
26985
26986 \end_inset
26987 </cell>
26988 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26989 \begin_inset Text
26990
26991 \begin_layout Standard
26992 0x000008
26993 \end_layout
26994
26995 \end_inset
26996 </cell>
26997 </row>
26998 <row topline="true" bottomline="true">
26999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27000 \begin_inset Text
27001
27002 \begin_layout Standard
27003 2
27004 \end_layout
27005
27006 \end_inset
27007 </cell>
27008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27009 \begin_inset Text
27010
27011 \begin_layout Standard
27012 LOW priority interrupts
27013 \end_layout
27014
27015 \end_inset
27016 </cell>
27017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27018 \begin_inset Text
27019
27020 \begin_layout Standard
27021 0x000018
27022 \end_layout
27023
27024 \end_inset
27025 </cell>
27026 </row>
27027 </lyxtabular>
27028
27029 \end_inset
27030
27031
27032 \end_layout
27033
27034 \begin_layout Standard
27035 When generating assembly code for ISR the code generator places a 
27036 \noun on
27037 goto 
27038 \noun default
27039 instruction at the 
27040 \emph on
27041 Interrupt Vector Address
27042 \emph default
27043  which points at the genetated ISR.
27044  This single GOTO instruction is part of an automatically generated 
27045 \emph on
27046 interrupt entry point
27047 \emph default
27048  function.
27049  The actuall ISR code is placed as normally would in the code space.
27050  Upon interrupt request, the GOTO instruction is executed which jumps to
27051  the ISR code.
27052  When declaring interrupt functions as _naked this GOTO instruction is 
27053 \series bold
27054 not
27055 \series default
27056  generated.
27057  The whole interrupt functions is therefore placed at the Interrupt Vector
27058  Address of the specific interrupt.
27059  This is not a problem for the LOW priority interrupts, but it is a problem
27060  for the RESET and the HIGH priority interrupts because code may be written
27061  at the next interrupt's vector address and cause undeterminate program
27062  behaviour if that interrupt is raised.
27063 \begin_inset Foot
27064 status open
27065
27066 \begin_layout Standard
27067 This is not a problem when
27068 \end_layout
27069
27070 \begin_layout Enumerate
27071 this is a HIGH interrupt ISR and LOW interrupts are 
27072 \emph on
27073 disabled
27074 \emph default
27075  or not used.
27076 \end_layout
27077
27078 \begin_layout Enumerate
27079 when the ISR is small enough not to reach the next interrupt's vector address.
27080 \end_layout
27081
27082 \end_inset
27083
27084
27085 \end_layout
27086
27087 \begin_layout Standard
27088
27089 \emph on
27090 n
27091 \emph default
27092  may be omitted.
27093  This way a function is generated similar to an ISR, but it is not assigned
27094  to any interrupt.
27095 \end_layout
27096
27097 \begin_layout Standard
27098 When entering an interrupt, currently the PIC16
27099 \begin_inset LatexCommand \index{PIC16}
27100
27101 \end_inset
27102
27103  port automatically saves the following registers:
27104 \end_layout
27105
27106 \begin_layout Itemize
27107 WREG
27108 \end_layout
27109
27110 \begin_layout Itemize
27111 STATUS
27112 \end_layout
27113
27114 \begin_layout Itemize
27115 BSR
27116 \end_layout
27117
27118 \begin_layout Itemize
27119 PROD (PRODL and PRODH)
27120 \end_layout
27121
27122 \begin_layout Itemize
27123 FSR0 (FSR0L and FSR0H)
27124 \end_layout
27125
27126 \begin_layout Standard
27127 These registers are restored upon return from the interrupt routine.
27128 \begin_inset Foot
27129 status open
27130
27131 \begin_layout Standard
27132 NOTE that when the _naked attribute is specified for an interrupt routine,
27133  then NO registers are stored or restored.
27134 \end_layout
27135
27136 \end_inset
27137
27138
27139 \end_layout
27140
27141 \begin_layout Subsection
27142 Generic Pointers
27143 \end_layout
27144
27145 \begin_layout Standard
27146 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
27147  There are 3 types of generic pointers currently implemented data, code
27148  and eeprom pointers.
27149  They are differentiated by the value of the 7th and 6th bits of the upper
27150  byte:
27151 \end_layout
27152
27153 \begin_layout Standard
27154 \align center
27155 \begin_inset Tabular
27156 <lyxtabular version="3" rows="5" columns="5">
27157 <features>
27158 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27159 <column alignment="center" valignment="top" width="0">
27160 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27161 <column alignment="center" valignment="top" width="0">
27162 <column alignment="left" valignment="top" rightline="true" width="0">
27163 <row topline="true" bottomline="true">
27164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27165 \begin_inset Text
27166
27167 \begin_layout Standard
27168 pointer type
27169 \end_layout
27170
27171 \end_inset
27172 </cell>
27173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27174 \begin_inset Text
27175
27176 \begin_layout Standard
27177 7th bit
27178 \end_layout
27179
27180 \end_inset
27181 </cell>
27182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27183 \begin_inset Text
27184
27185 \begin_layout Standard
27186 6th bit
27187 \end_layout
27188
27189 \end_inset
27190 </cell>
27191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27192 \begin_inset Text
27193
27194 \begin_layout Standard
27195 rest of the pointer
27196 \end_layout
27197
27198 \end_inset
27199 </cell>
27200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27201 \begin_inset Text
27202
27203 \begin_layout Standard
27204 description
27205 \end_layout
27206
27207 \end_inset
27208 </cell>
27209 </row>
27210 <row topline="true" bottomline="true">
27211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27212 \begin_inset Text
27213
27214 \begin_layout Standard
27215 data 
27216 \end_layout
27217
27218 \end_inset
27219 </cell>
27220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27221 \begin_inset Text
27222
27223 \begin_layout Standard
27224 1
27225 \end_layout
27226
27227 \end_inset
27228 </cell>
27229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27230 \begin_inset Text
27231
27232 \begin_layout Standard
27233 0
27234 \end_layout
27235
27236 \end_inset
27237 </cell>
27238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27239 \begin_inset Text
27240
27241 \begin_layout Standard
27242
27243 \family typewriter
27244 \shape slanted
27245 \emph on
27246 uuuuuu uuuuxxxx xxxxxxxx
27247 \end_layout
27248
27249 \end_inset
27250 </cell>
27251 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27252 \begin_inset Text
27253
27254 \begin_layout Standard
27255 a 12-bit data pointer in data RAM memory
27256 \end_layout
27257
27258 \end_inset
27259 </cell>
27260 </row>
27261 <row bottomline="true">
27262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27263 \begin_inset Text
27264
27265 \begin_layout Standard
27266 code
27267 \end_layout
27268
27269 \end_inset
27270 </cell>
27271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27272 \begin_inset Text
27273
27274 \begin_layout Standard
27275 0
27276 \end_layout
27277
27278 \end_inset
27279 </cell>
27280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27281 \begin_inset Text
27282
27283 \begin_layout Standard
27284 0
27285 \end_layout
27286
27287 \end_inset
27288 </cell>
27289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27290 \begin_inset Text
27291
27292 \begin_layout Standard
27293
27294 \family typewriter
27295 \shape slanted
27296 \emph on
27297 uxxxxx xxxxxxxx xxxxxxxx
27298 \end_layout
27299
27300 \end_inset
27301 </cell>
27302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27303 \begin_inset Text
27304
27305 \begin_layout Standard
27306 a 21-bit code pointer in FLASH memory
27307 \end_layout
27308
27309 \end_inset
27310 </cell>
27311 </row>
27312 <row bottomline="true">
27313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27314 \begin_inset Text
27315
27316 \begin_layout Standard
27317 eeprom
27318 \end_layout
27319
27320 \end_inset
27321 </cell>
27322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27323 \begin_inset Text
27324
27325 \begin_layout Standard
27326 0
27327 \end_layout
27328
27329 \end_inset
27330 </cell>
27331 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27332 \begin_inset Text
27333
27334 \begin_layout Standard
27335 1
27336 \end_layout
27337
27338 \end_inset
27339 </cell>
27340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27341 \begin_inset Text
27342
27343 \begin_layout Standard
27344
27345 \family typewriter
27346 \shape slanted
27347 \emph on
27348 uuuuuu uuuuuuxx xxxxxxxx
27349 \end_layout
27350
27351 \end_inset
27352 </cell>
27353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27354 \begin_inset Text
27355
27356 \begin_layout Standard
27357 a 10-bit eeprom pointer in EEPROM memory
27358 \end_layout
27359
27360 \end_inset
27361 </cell>
27362 </row>
27363 <row bottomline="true">
27364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27365 \begin_inset Text
27366
27367 \begin_layout Standard
27368 (unimplemented)
27369 \end_layout
27370
27371 \end_inset
27372 </cell>
27373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27374 \begin_inset Text
27375
27376 \begin_layout Standard
27377 1
27378 \end_layout
27379
27380 \end_inset
27381 </cell>
27382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27383 \begin_inset Text
27384
27385 \begin_layout Standard
27386 1
27387 \end_layout
27388
27389 \end_inset
27390 </cell>
27391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27392 \begin_inset Text
27393
27394 \begin_layout Standard
27395
27396 \family typewriter
27397 \shape slanted
27398 \emph on
27399 xxxxxx xxxxxxxx xxxxxxxx
27400 \end_layout
27401
27402 \end_inset
27403 </cell>
27404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27405 \begin_inset Text
27406
27407 \begin_layout Standard
27408 unimplemented pointer type
27409 \end_layout
27410
27411 \end_inset
27412 </cell>
27413 </row>
27414 </lyxtabular>
27415
27416 \end_inset
27417
27418
27419 \end_layout
27420
27421 \begin_layout Standard
27422 Generic pointer are read and written with a set of library functions which
27423  read/write 1, 2, 3, 4 bytes.
27424 \end_layout
27425
27426 \begin_layout Subsection
27427 PIC16 C Libraries
27428 \end_layout
27429
27430 \begin_layout Subsubsection
27431 Standard I/O Streams
27432 \end_layout
27433
27434 \begin_layout Standard
27435 In the 
27436 \emph on
27437 stdio.h
27438 \emph default
27439  the type FILE is defined as:
27440 \end_layout
27441
27442 \begin_layout LyX-Code
27443 typedef char * FILE;
27444 \end_layout
27445
27446 \begin_layout Standard
27447 This type is the stream type implemented I/O in the PIC18F devices.
27448  Also the standard input and output streams are declared in stdio.h:
27449 \end_layout
27450
27451 \begin_layout LyX-Code
27452 extern FILE * stdin;
27453 \end_layout
27454
27455 \begin_layout LyX-Code
27456 extern FILE * stdout;
27457 \end_layout
27458
27459 \begin_layout Standard
27460 The FILE type is actually a generic pointer which defines one more type
27461  of generic pointers, the 
27462 \emph on
27463 stream 
27464 \emph default
27465 pointer.
27466  This new type has the format:
27467 \end_layout
27468
27469 \begin_layout Standard
27470 \align center
27471 \begin_inset Tabular
27472 <lyxtabular version="3" rows="2" columns="7">
27473 <features>
27474 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27475 <column alignment="center" valignment="top" width="0">
27476 <column alignment="center" valignment="top" leftline="true" width="0">
27477 <column alignment="center" valignment="top" leftline="true" width="0">
27478 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27479 <column alignment="center" valignment="top" width="0">
27480 <column alignment="left" valignment="top" rightline="true" width="0">
27481 <row topline="true" bottomline="true">
27482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27483 \begin_inset Text
27484
27485 \begin_layout Standard
27486 pointer type
27487 \end_layout
27488
27489 \end_inset
27490 </cell>
27491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27492 \begin_inset Text
27493
27494 \begin_layout Standard
27495 <7:6>
27496 \end_layout
27497
27498 \end_inset
27499 </cell>
27500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27501 \begin_inset Text
27502
27503 \begin_layout Standard
27504 <5>
27505 \end_layout
27506
27507 \end_inset
27508 </cell>
27509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27510 \begin_inset Text
27511
27512 \begin_layout Standard
27513 <4>
27514 \end_layout
27515
27516 \end_inset
27517 </cell>
27518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27519 \begin_inset Text
27520
27521 \begin_layout Standard
27522 <3:0>
27523 \end_layout
27524
27525 \end_inset
27526 </cell>
27527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27528 \begin_inset Text
27529
27530 \begin_layout Standard
27531 rest of the pointer
27532 \end_layout
27533
27534 \end_inset
27535 </cell>
27536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27537 \begin_inset Text
27538
27539 \begin_layout Standard
27540 descrption
27541 \end_layout
27542
27543 \end_inset
27544 </cell>
27545 </row>
27546 <row topline="true" bottomline="true">
27547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27548 \begin_inset Text
27549
27550 \begin_layout Standard
27551 stream
27552 \end_layout
27553
27554 \end_inset
27555 </cell>
27556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27557 \begin_inset Text
27558
27559 \begin_layout Standard
27560 00
27561 \end_layout
27562
27563 \end_inset
27564 </cell>
27565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27566 \begin_inset Text
27567
27568 \begin_layout Standard
27569 1
27570 \end_layout
27571
27572 \end_inset
27573 </cell>
27574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27575 \begin_inset Text
27576
27577 \begin_layout Standard
27578 0
27579 \end_layout
27580
27581 \end_inset
27582 </cell>
27583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27584 \begin_inset Text
27585
27586 \begin_layout Standard
27587 nnnn
27588 \end_layout
27589
27590 \end_inset
27591 </cell>
27592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27593 \begin_inset Text
27594
27595 \begin_layout Standard
27596
27597 \family typewriter
27598 \shape slanted
27599 \emph on
27600 uuuuuuuu uuuuuuuu
27601 \end_layout
27602
27603 \end_inset
27604 </cell>
27605 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27606 \begin_inset Text
27607
27608 \begin_layout Standard
27609 upper byte high nubble is 0x2n, the rest are zeroes
27610 \end_layout
27611
27612 \end_inset
27613 </cell>
27614 </row>
27615 </lyxtabular>
27616
27617 \end_inset
27618
27619
27620 \end_layout
27621
27622 \begin_layout Standard
27623 Currently implemented there are 3 types of streams defined:
27624 \end_layout
27625
27626 \begin_layout Standard
27627 \align center
27628 \begin_inset Tabular
27629 <lyxtabular version="3" rows="4" columns="4">
27630 <features>
27631 <column alignment="center" valignment="top" leftline="true" width="0">
27632 <column alignment="center" valignment="top" leftline="true" width="0">
27633 <column alignment="center" valignment="top" leftline="true" width="0">
27634 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27635 <row topline="true" bottomline="true">
27636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27637 \begin_inset Text
27638
27639 \begin_layout Standard
27640 stream type
27641 \end_layout
27642
27643 \end_inset
27644 </cell>
27645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27646 \begin_inset Text
27647
27648 \begin_layout Standard
27649 value
27650 \end_layout
27651
27652 \end_inset
27653 </cell>
27654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27655 \begin_inset Text
27656
27657 \begin_layout Standard
27658 module
27659 \end_layout
27660
27661 \end_inset
27662 </cell>
27663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27664 \begin_inset Text
27665
27666 \begin_layout Standard
27667 description
27668 \end_layout
27669
27670 \end_inset
27671 </cell>
27672 </row>
27673 <row topline="true">
27674 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27675 \begin_inset Text
27676
27677 \begin_layout Standard
27678 STREAM_USART
27679 \end_layout
27680
27681 \end_inset
27682 </cell>
27683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27684 \begin_inset Text
27685
27686 \begin_layout Standard
27687
27688 \family typewriter
27689 0x200000UL
27690 \end_layout
27691
27692 \end_inset
27693 </cell>
27694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27695 \begin_inset Text
27696
27697 \begin_layout Standard
27698 USART
27699 \end_layout
27700
27701 \end_inset
27702 </cell>
27703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27704 \begin_inset Text
27705
27706 \begin_layout Standard
27707 Writes/Reads characters via the USART peripheral
27708 \end_layout
27709
27710 \end_inset
27711 </cell>
27712 </row>
27713 <row topline="true">
27714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27715 \begin_inset Text
27716
27717 \begin_layout Standard
27718 STREAM_MSSP
27719 \end_layout
27720
27721 \end_inset
27722 </cell>
27723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27724 \begin_inset Text
27725
27726 \begin_layout Standard
27727
27728 \family typewriter
27729 0x210000UL
27730 \end_layout
27731
27732 \end_inset
27733 </cell>
27734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27735 \begin_inset Text
27736
27737 \begin_layout Standard
27738 MSSP
27739 \end_layout
27740
27741 \end_inset
27742 </cell>
27743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27744 \begin_inset Text
27745
27746 \begin_layout Standard
27747 Writes/Reads characters via the MSSP peripheral
27748 \end_layout
27749
27750 \end_inset
27751 </cell>
27752 </row>
27753 <row topline="true" bottomline="true">
27754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27755 \begin_inset Text
27756
27757 \begin_layout Standard
27758 STREAM_USER
27759 \end_layout
27760
27761 \end_inset
27762 </cell>
27763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27764 \begin_inset Text
27765
27766 \begin_layout Standard
27767
27768 \family typewriter
27769 0x2f0000UL
27770 \end_layout
27771
27772 \end_inset
27773 </cell>
27774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27775 \begin_inset Text
27776
27777 \begin_layout Standard
27778 (none)
27779 \end_layout
27780
27781 \end_inset
27782 </cell>
27783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27784 \begin_inset Text
27785
27786 \begin_layout Standard
27787 Writes/Reads characters via used defined functions
27788 \end_layout
27789
27790 \end_inset
27791 </cell>
27792 </row>
27793 </lyxtabular>
27794
27795 \end_inset
27796
27797
27798 \end_layout
27799
27800 \begin_layout Standard
27801 The stream identifiers are declared as macros in the stdio.h header.
27802 \end_layout
27803
27804 \begin_layout Standard
27805 In the libc library there exist the functions that are used to write to
27806  each of the above streams.
27807  These are
27808 \end_layout
27809
27810 \begin_layout Description
27811 _
27812 \begin_inset ERT
27813 status collapsed
27814
27815 \begin_layout Standard
27816
27817
27818 \backslash
27819 /
27820 \end_layout
27821
27822 \end_inset
27823
27824 _stream_usart_putchar writes a character at the USART stream
27825 \end_layout
27826
27827 \begin_layout Description
27828 _
27829 \begin_inset ERT
27830 status collapsed
27831
27832 \begin_layout Standard
27833
27834
27835 \backslash
27836 /
27837 \end_layout
27838
27839 \end_inset
27840
27841 _stream_mssp_putchar writes a character at the MSSP stream
27842 \end_layout
27843
27844 \begin_layout Description
27845 putchar dummy function.
27846  This writes a character to a user specified manner.
27847 \end_layout
27848
27849 \begin_layout Standard
27850 In order to increase performance 
27851 \emph on
27852 putchar 
27853 \emph default
27854 is declared in stdio.h as having its parameter in WREG (it has the wparam
27855  keyword).
27856  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
27857  in a user-friendly way.
27858  
27859 \emph on
27860 arg
27861 \emph default
27862  is the name of the variable that holds the character to print.
27863  An example follows:
27864 \end_layout
27865
27866 \begin_layout LyX-Code
27867 #include <pic18fregs.h>
27868 \newline
27869 #include <stdio.h>
27870 \newline
27871
27872 \newline
27873 PUTCHAR( c )
27874 \end_layout
27875
27876 \begin_layout LyX-Code
27877 {
27878 \end_layout
27879
27880 \begin_layout LyX-Code
27881     PORTA = c;    /* dump character c to PORTA */
27882 \end_layout
27883
27884 \begin_layout LyX-Code
27885
27886 \newline
27887
27888 \newline
27889 void main(void)
27890 \end_layout
27891
27892 \begin_layout LyX-Code
27893 {
27894 \end_layout
27895
27896 \begin_layout LyX-Code
27897     stdout = STREAM_USER;    /* this is not necessary, since stdout points
27898 \end_layout
27899
27900 \begin_layout LyX-Code
27901                               * by default to STREAM_USER */
27902 \end_layout
27903
27904 \begin_layout LyX-Code
27905     printf (
27906 \begin_inset Quotes sld
27907 \end_inset
27908
27909 This is a printf test
27910 \backslash
27911 n
27912 \begin_inset Quotes srd
27913 \end_inset
27914
27915 );
27916 \end_layout
27917
27918 \begin_layout LyX-Code
27919 }
27920 \end_layout
27921
27922 \begin_layout LyX-Code
27923
27924 \end_layout
27925
27926 \begin_layout Subsubsection
27927 Printing functions
27928 \end_layout
27929
27930 \begin_layout Standard
27931 PIC16 contains an implementation of the printf-family of functions.
27932  There exist the following functions:
27933 \end_layout
27934
27935 \begin_layout LyX-Code
27936 extern unsigned int sprintf(char *buf, char *fmt, ...);
27937 \end_layout
27938
27939 \begin_layout LyX-Code
27940 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
27941 \end_layout
27942
27943 \begin_layout LyX-Code
27944
27945 \end_layout
27946
27947 \begin_layout LyX-Code
27948 extern unsigned int printf(char *fmt, ...);
27949 \end_layout
27950
27951 \begin_layout LyX-Code
27952 extern unsigned int vprintf(char *fmt, va_lista ap);
27953 \end_layout
27954
27955 \begin_layout LyX-Code
27956
27957 \end_layout
27958
27959 \begin_layout LyX-Code
27960 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
27961 \end_layout
27962
27963 \begin_layout LyX-Code
27964 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
27965 \end_layout
27966
27967 \begin_layout Standard
27968 For sprintf and vsprintf 
27969 \emph on
27970 buf 
27971 \emph default
27972 should normally be a data pointer where the resulting string will be placed.
27973  No range checking is done so the user should allocate the necessery buffer.
27974  For fprintf and vfprintf 
27975 \emph on
27976 fp
27977 \emph default
27978  should be a stream pointer (i.e.
27979  stdout, STREAM_MSSP, etc...).
27980 \end_layout
27981
27982 \begin_layout Subsubsection
27983 Signals
27984 \end_layout
27985
27986 \begin_layout Standard
27987 The PIC18F family of microcontrollers supports a number of interrupt sources.
27988  A list of these interrupts is shown in the following table:
27989 \end_layout
27990
27991 \begin_layout Standard
27992 \align center
27993 \begin_inset Tabular
27994 <lyxtabular version="3" rows="11" columns="4">
27995 <features>
27996 <column alignment="left" valignment="top" leftline="true" width="0">
27997 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27998 <column alignment="left" valignment="top" leftline="true" width="0">
27999 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28000 <row topline="true" bottomline="true">
28001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28002 \begin_inset Text
28003
28004 \begin_layout Standard
28005 signal name
28006 \end_layout
28007
28008 \end_inset
28009 </cell>
28010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28011 \begin_inset Text
28012
28013 \begin_layout Standard
28014 description
28015 \end_layout
28016
28017 \end_inset
28018 </cell>
28019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28020 \begin_inset Text
28021
28022 \begin_layout Standard
28023 signal name
28024 \end_layout
28025
28026 \end_inset
28027 </cell>
28028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28029 \begin_inset Text
28030
28031 \begin_layout Standard
28032 descritpion
28033 \end_layout
28034
28035 \end_inset
28036 </cell>
28037 </row>
28038 <row topline="true">
28039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28040 \begin_inset Text
28041
28042 \begin_layout Standard
28043 SIG_RB
28044 \end_layout
28045
28046 \end_inset
28047 </cell>
28048 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28049 \begin_inset Text
28050
28051 \begin_layout Standard
28052 PORTB change interrupt
28053 \end_layout
28054
28055 \end_inset
28056 </cell>
28057 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28058 \begin_inset Text
28059
28060 \begin_layout Standard
28061 SIG_EE
28062 \end_layout
28063
28064 \end_inset
28065 </cell>
28066 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28067 \begin_inset Text
28068
28069 \begin_layout Standard
28070 EEPROM/FLASH write complete interrupt
28071 \end_layout
28072
28073 \end_inset
28074 </cell>
28075 </row>
28076 <row topline="true">
28077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28078 \begin_inset Text
28079
28080 \begin_layout Standard
28081 SIG_INT0
28082 \end_layout
28083
28084 \end_inset
28085 </cell>
28086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28087 \begin_inset Text
28088
28089 \begin_layout Standard
28090 INT0 external interrupt
28091 \end_layout
28092
28093 \end_inset
28094 </cell>
28095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28096 \begin_inset Text
28097
28098 \begin_layout Standard
28099 SIG_BCOL
28100 \end_layout
28101
28102 \end_inset
28103 </cell>
28104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28105 \begin_inset Text
28106
28107 \begin_layout Standard
28108 Bus collision interrupt
28109 \end_layout
28110
28111 \end_inset
28112 </cell>
28113 </row>
28114 <row topline="true">
28115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28116 \begin_inset Text
28117
28118 \begin_layout Standard
28119 SIG_INT1
28120 \end_layout
28121
28122 \end_inset
28123 </cell>
28124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28125 \begin_inset Text
28126
28127 \begin_layout Standard
28128 INT1 external interrupt
28129 \end_layout
28130
28131 \end_inset
28132 </cell>
28133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28134 \begin_inset Text
28135
28136 \begin_layout Standard
28137 SIG_LVD
28138 \end_layout
28139
28140 \end_inset
28141 </cell>
28142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28143 \begin_inset Text
28144
28145 \begin_layout Standard
28146 Low voltage detect interrupt
28147 \end_layout
28148
28149 \end_inset
28150 </cell>
28151 </row>
28152 <row topline="true">
28153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28154 \begin_inset Text
28155
28156 \begin_layout Standard
28157 SIG_INT2
28158 \end_layout
28159
28160 \end_inset
28161 </cell>
28162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28163 \begin_inset Text
28164
28165 \begin_layout Standard
28166 INT2 external interrupt
28167 \end_layout
28168
28169 \end_inset
28170 </cell>
28171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28172 \begin_inset Text
28173
28174 \begin_layout Standard
28175 SIG_PSP
28176 \end_layout
28177
28178 \end_inset
28179 </cell>
28180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28181 \begin_inset Text
28182
28183 \begin_layout Standard
28184 Parallel slave port interrupt
28185 \end_layout
28186
28187 \end_inset
28188 </cell>
28189 </row>
28190 <row topline="true">
28191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28192 \begin_inset Text
28193
28194 \begin_layout Standard
28195 SIG_CCP1
28196 \end_layout
28197
28198 \end_inset
28199 </cell>
28200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28201 \begin_inset Text
28202
28203 \begin_layout Standard
28204 CCP1 module interrupt
28205 \end_layout
28206
28207 \end_inset
28208 </cell>
28209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28210 \begin_inset Text
28211
28212 \begin_layout Standard
28213 SIG_AD
28214 \end_layout
28215
28216 \end_inset
28217 </cell>
28218 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28219 \begin_inset Text
28220
28221 \begin_layout Standard
28222 AD convertion complete interrupt
28223 \end_layout
28224
28225 \end_inset
28226 </cell>
28227 </row>
28228 <row topline="true">
28229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28230 \begin_inset Text
28231
28232 \begin_layout Standard
28233 SIG_CCP2
28234 \end_layout
28235
28236 \end_inset
28237 </cell>
28238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28239 \begin_inset Text
28240
28241 \begin_layout Standard
28242 CCP2 module interrupt
28243 \end_layout
28244
28245 \end_inset
28246 </cell>
28247 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28248 \begin_inset Text
28249
28250 \begin_layout Standard
28251 SIG_RC
28252 \end_layout
28253
28254 \end_inset
28255 </cell>
28256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28257 \begin_inset Text
28258
28259 \begin_layout Standard
28260 USART receive interrupt
28261 \end_layout
28262
28263 \end_inset
28264 </cell>
28265 </row>
28266 <row topline="true">
28267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28268 \begin_inset Text
28269
28270 \begin_layout Standard
28271 SIG_TMR0
28272 \end_layout
28273
28274 \end_inset
28275 </cell>
28276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28277 \begin_inset Text
28278
28279 \begin_layout Standard
28280 TMR0 overflow interrupt
28281 \end_layout
28282
28283 \end_inset
28284 </cell>
28285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28286 \begin_inset Text
28287
28288 \begin_layout Standard
28289 SIG_TX
28290 \end_layout
28291
28292 \end_inset
28293 </cell>
28294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28295 \begin_inset Text
28296
28297 \begin_layout Standard
28298 USART transmit interrupt
28299 \end_layout
28300
28301 \end_inset
28302 </cell>
28303 </row>
28304 <row topline="true">
28305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28306 \begin_inset Text
28307
28308 \begin_layout Standard
28309 SIG_TMR1
28310 \end_layout
28311
28312 \end_inset
28313 </cell>
28314 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28315 \begin_inset Text
28316
28317 \begin_layout Standard
28318 TMR1 overflow interrupt
28319 \end_layout
28320
28321 \end_inset
28322 </cell>
28323 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28324 \begin_inset Text
28325
28326 \begin_layout Standard
28327 SIG_MSSP
28328 \end_layout
28329
28330 \end_inset
28331 </cell>
28332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28333 \begin_inset Text
28334
28335 \begin_layout Standard
28336 SSP receive/transmit interrupt
28337 \end_layout
28338
28339 \end_inset
28340 </cell>
28341 </row>
28342 <row topline="true">
28343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28344 \begin_inset Text
28345
28346 \begin_layout Standard
28347 SIG_TMR2
28348 \end_layout
28349
28350 \end_inset
28351 </cell>
28352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28353 \begin_inset Text
28354
28355 \begin_layout Standard
28356 TMR2 matches PR2 interrupt
28357 \end_layout
28358
28359 \end_inset
28360 </cell>
28361 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28362 \begin_inset Text
28363
28364 \begin_layout Standard
28365
28366 \end_layout
28367
28368 \end_inset
28369 </cell>
28370 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28371 \begin_inset Text
28372
28373 \begin_layout Standard
28374
28375 \end_layout
28376
28377 \end_inset
28378 </cell>
28379 </row>
28380 <row topline="true" bottomline="true">
28381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28382 \begin_inset Text
28383
28384 \begin_layout Standard
28385 SIG_TMR3
28386 \end_layout
28387
28388 \end_inset
28389 </cell>
28390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28391 \begin_inset Text
28392
28393 \begin_layout Standard
28394 TMR3 overflow interrupt
28395 \end_layout
28396
28397 \end_inset
28398 </cell>
28399 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28400 \begin_inset Text
28401
28402 \begin_layout Standard
28403
28404 \end_layout
28405
28406 \end_inset
28407 </cell>
28408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28409 \begin_inset Text
28410
28411 \begin_layout Standard
28412
28413 \end_layout
28414
28415 \end_inset
28416 </cell>
28417 </row>
28418 </lyxtabular>
28419
28420 \end_inset
28421
28422
28423 \end_layout
28424
28425 \begin_layout Standard
28426 The prototypes for these names are defined in the header file 
28427 \emph on
28428 signal.h
28429 \emph default
28430  .
28431 \end_layout
28432
28433 \begin_layout Standard
28434 In order to simplify signal handling, a number of macros is provided:
28435 \end_layout
28436
28437 \begin_layout List
28438 \labelwidthstring 00.00.0000
28439 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
28440  high priority interrupts.
28441  
28442 \emph on
28443 name
28444 \emph default
28445  is the function name to use.
28446 \end_layout
28447
28448 \begin_layout List
28449 \labelwidthstring 00.00.0000
28450 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
28451  low priority interrupt.
28452  
28453 \emph on
28454 name
28455 \emph default
28456  is the function name to use.
28457 \end_layout
28458
28459 \begin_layout List
28460 \labelwidthstring 00.00.0000
28461 DEF_HANDLER(sig,handler) define a handler for signal 
28462 \emph on
28463 sig.
28464 \end_layout
28465
28466 \begin_layout List
28467 \labelwidthstring 00.00.0000
28468 END_DEF end the declaration of the dispatch table.
28469 \end_layout
28470
28471 \begin_layout Standard
28472 Additionally there are two more macros to simplify the declaration of the
28473  signal handler:
28474 \end_layout
28475
28476 \begin_layout List
28477 \labelwidthstring 00.00.0000
28478
28479 \series medium
28480 SIGHANDLER(handler) 
28481 \series default
28482 this declares the function prototype for the 
28483 \emph on
28484 handler
28485 \emph default
28486  function.
28487 \end_layout
28488
28489 \begin_layout List
28490 \labelwidthstring 00.00.0000
28491 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
28492 \end_layout
28493
28494 \begin_layout Standard
28495 An example of using the macros above is shown below:
28496 \end_layout
28497
28498 \begin_layout LyX-Code
28499 #include <pic18fregs.h>
28500 \end_layout
28501
28502 \begin_layout LyX-Code
28503 #include <signal.h>
28504 \newline
28505
28506 \newline
28507 DEF_INTHIGH(high_int)
28508 \end_layout
28509
28510 \begin_layout LyX-Code
28511 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
28512 \end_layout
28513
28514 \begin_layout LyX-Code
28515 DEF_HANDLER(SIG_BCOL, _bcol_handler)
28516 \end_layout
28517
28518 \begin_layout LyX-Code
28519 END_DEF
28520 \newline
28521
28522 \newline
28523 SIGHANDLER(_tmr0_handler)
28524 \end_layout
28525
28526 \begin_layout LyX-Code
28527 {
28528 \end_layout
28529
28530 \begin_layout LyX-Code
28531   /* action to be taken when timer 0 overflows */
28532 \end_layout
28533
28534 \begin_layout LyX-Code
28535 }
28536 \newline
28537
28538 \newline
28539 SIGHANDLERNAKED(_bcol_handler)
28540 \end_layout
28541
28542 \begin_layout LyX-Code
28543 {
28544 \end_layout
28545
28546 \begin_layout LyX-Code
28547   _asm
28548 \end_layout
28549
28550 \begin_layout LyX-Code
28551     /* action to be taken when bus collision occurs */
28552 \end_layout
28553
28554 \begin_layout LyX-Code
28555     retfie
28556 \end_layout
28557
28558 \begin_layout LyX-Code
28559  _endasm;
28560 \end_layout
28561
28562 \begin_layout LyX-Code
28563 }
28564 \end_layout
28565
28566 \begin_layout Standard
28567
28568 \series bold
28569 NOTES:
28570 \series default
28571  Special care should be taken when using the above scheme:
28572 \end_layout
28573
28574 \begin_layout Itemize
28575 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
28576 \end_layout
28577
28578 \begin_layout Itemize
28579 when declaring SIGHANDLERNAKED handler never forget to use 
28580 \emph on
28581 retfie
28582 \emph default
28583  for proper returning.
28584 \end_layout
28585
28586 \begin_layout Subsection
28587 PIC16 Port -- Tips
28588 \end_layout
28589
28590 \begin_layout Standard
28591 Here you can find some general tips for compiling programs with SDCC/pic16.
28592 \end_layout
28593
28594 \begin_layout Subsubsection
28595 Stack size
28596 \end_layout
28597
28598 \begin_layout Standard
28599 The default stack
28600 \begin_inset LatexCommand \index{PIC16!stack}
28601
28602 \end_inset
28603
28604  size (that is 64 bytes) probably is enough for many programs.
28605  One must take care that when there are many levels of function nesting,
28606  or there is excessive usage of stack, its size should be extended.
28607  An example of such a case is the printf/sprintf family of functions.
28608  If you encounter problems like not being able to print integers, then you
28609  need to set the stack size around the maximum (256 for small stack model).
28610  The following diagram shows what happens when calling printf to print an
28611  integer:
28612 \end_layout
28613
28614 \begin_layout LyX-Code
28615 printf () --> ltoa () --> ultoa () --> divschar ()
28616 \end_layout
28617
28618 \begin_layout Standard
28619 It is should be understood that stack is easily consumed when calling complicate
28620 d functions.
28621  Using command line arguments like -
28622 \begin_inset ERT
28623 status collapsed
28624
28625 \begin_layout Standard
28626
28627
28628 \backslash
28629 /
28630 \end_layout
28631
28632 \end_inset
28633
28634 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
28635  stack frames.
28636  Other ways to reduce stack usage may exist.
28637 \end_layout
28638
28639 \begin_layout Subsection
28640 Known Bugs
28641 \end_layout
28642
28643 \begin_layout Standard
28644 The PIC16 Port currently does not pass SDCC's regression test
28645 \begin_inset LatexCommand \index{Regression test (PIC16)}
28646
28647 \end_inset
28648
28649  suite (see section 
28650 \begin_inset LatexCommand \ref{sec:Quality-control}
28651
28652 \end_inset
28653
28654 ) and thus the snapshot build regression tests for the PIC16 target are
28655  currently disabled for all hosts
28656 \emph on
28657 .
28658 \end_layout
28659
28660 \begin_layout Chapter
28661 Debugging
28662 \end_layout
28663
28664 \begin_layout Standard
28665 There are several approaches to debugging your code.
28666  This chapter is meant to show your options and to give detail on some of
28667  them:
28668 \newline
28669
28670 \newline
28671 When writing your code:
28672 \end_layout
28673
28674 \begin_layout Itemize
28675 write your code with debugging in mind (avoid duplicating code, put conceptually
28676  similar variables into structs, use structured code, have strategic points
28677  within your code where all variables are consistent, ...)
28678 \end_layout
28679
28680 \begin_layout Itemize
28681 run a syntax-checking tool like splint
28682 \begin_inset LatexCommand \index{splint (syntax checking tool)}
28683
28684 \end_inset
28685
28686
28687 \begin_inset LatexCommand \index{lint (syntax checking tool)}
28688
28689 \end_inset
28690
28691  (see -
28692 \begin_inset ERT
28693 status collapsed
28694
28695 \begin_layout Standard
28696
28697
28698 \backslash
28699 /
28700 \end_layout
28701
28702 \end_inset
28703
28704 -more-pedantic 
28705 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28706
28707 \end_inset
28708
28709 ) over the code.
28710 \end_layout
28711
28712 \begin_layout Itemize
28713 for the high level code use a C-compiler (like f.e.
28714  GCC) to compile run and debug the code on your host.
28715  See (see -
28716 \begin_inset ERT
28717 status collapsed
28718
28719 \begin_layout Standard
28720
28721
28722 \backslash
28723 /
28724 \end_layout
28725
28726 \end_inset
28727
28728 -more-pedantic 
28729 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
28730
28731 \end_inset
28732
28733 ) on how to handle syntax extensions like __xdata, __at(), ...
28734  
28735 \end_layout
28736
28737 \begin_layout Itemize
28738 use another C-compiler to compile code for your target.
28739  Always an option but not recommended:) And not very likely to help you.
28740  If you seriously consider walking this path you should at least occasionally
28741  check portability of your code.
28742  Most commercial compiler vendors will offer an evaluation version so you
28743  can test compile your code or snippets of your code.
28744 \end_layout
28745
28746 \begin_layout Standard
28747 Debugging on a simulator:
28748 \end_layout
28749
28750 \begin_layout Itemize
28751 there is a separate section about SDCDB (section 
28752 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
28753
28754 \end_inset
28755
28756 ) below.
28757 \end_layout
28758
28759 \begin_layout Itemize
28760 or (8051 specific) use a freeware/commercial simulator which interfaces
28761  to the AOMF
28762 \begin_inset LatexCommand \index{AOMF, AOMF51}
28763
28764 \end_inset
28765
28766  file (see 
28767 \begin_inset LatexCommand \ref{OMF file}
28768
28769 \end_inset
28770
28771 ) optionally generated by SDCC.
28772 \end_layout
28773
28774 \begin_layout Standard
28775 Debugging On-target: 
28776 \end_layout
28777
28778 \begin_layout Itemize
28779 use a MCU port pin to serially output debug data to the RS232 port of your
28780  host.
28781  You'll probably want some level shifting device typically involving a MAX232
28782  or similar IC.
28783  If the hardware serial port of the MCU is not available search for 'Software
28784  UART' in your favourite search machine.
28785 \end_layout
28786
28787 \begin_layout Itemize
28788 use an on-target monitor.
28789  In this context a monitor is a small program which usually accepts commands
28790  via a serial line and allows to set program counter, to single step through
28791  a program and read/write memory locations.
28792  For the 8051 good examples of monitors are paulmon and cmon51 (see section
28793  
28794 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
28795
28796 \end_inset
28797
28798 ).
28799 \end_layout
28800
28801 \begin_layout Itemize
28802 toggle MCU port pins at strategic points within your code and use an oscilloscop
28803 e.
28804  A 
28805 \emph on
28806 digital oscilloscope
28807 \emph default
28808
28809 \begin_inset LatexCommand \index{Oscilloscope}
28810
28811 \end_inset
28812
28813  with deep trace memory is really helpful especially if you have to debug
28814  a realtime application.
28815  If you need to monitor more pins than your oscilloscope provides you can
28816  sometimes get away with a small R-2R network.
28817  On a single channel oscilloscope you could f.e.
28818  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
28819 k
28820 \begin_inset Formula $\Omega$
28821 \end_inset
28822
28823  resistor and the other one by a 5\InsetSpace ~
28824 k
28825 \begin_inset Formula $\Omega$
28826 \end_inset
28827
28828  resistor to the oscilloscope probe (check output drive capability of the
28829  pins you want to monitor).
28830  If you need to monitor many more pins a 
28831 \emph on
28832 logic analyzer
28833 \emph default
28834  will be handy.
28835 \end_layout
28836
28837 \begin_layout Itemize
28838 use an ICE (
28839 \emph on
28840 i
28841 \emph default
28842
28843 \emph on
28844 c
28845 \emph default
28846 ircuit 
28847 \emph on
28848 e
28849 \emph default
28850 mulator
28851 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
28852
28853 \end_inset
28854
28855 ).
28856  Usually very expensive.
28857  And very nice to have too.
28858  And usually locks you (for years...) to the devices the ICE can emulate.
28859  
28860 \end_layout
28861
28862 \begin_layout Itemize
28863 use a remote debugger.
28864  In most 8-bit systems the symbol information is not available on the target,
28865  and a complete debugger is too bulky for the target system.
28866  Therefore usually a debugger on the host system connects to an on-target
28867  debugging stub which accepts only primitive commands.
28868  
28869 \newline
28870 Terms to enter into your favourite search engine could be 'remote debugging',
28871  'gdb stub' or 'inferior debugger'.
28872  (is there one?)
28873 \end_layout
28874
28875 \begin_layout Itemize
28876 use an on target hardware debugger.
28877  Some of the more modern MCUs include hardware support for setting break
28878  points and monitoring/changing variables by using dedicated hardware pins.
28879  This facility doesn't require additional code to run on the target and
28880  
28881 \emph on
28882 usually
28883 \emph default
28884  doesn't affect runtime behaviour until a breakpoint is hit.
28885  For the mcs51 most hardware debuggers use the AOMF
28886 \begin_inset LatexCommand \index{AOMF, AOMF51}
28887
28888 \end_inset
28889
28890  file (see 
28891 \begin_inset LatexCommand \ref{OMF file}
28892
28893 \end_inset
28894
28895 ) as input file.
28896  
28897 \end_layout
28898
28899 \begin_layout Standard
28900 Last not least:
28901 \end_layout
28902
28903 \begin_layout Itemize
28904 if you are not familiar with any of the following terms you're likely to
28905  run into problems rather sooner than later: 
28906 \emph on
28907 volatile
28908 \emph default
28909
28910 \emph on
28911 atomic
28912 \emph default
28913
28914 \emph on
28915 memory map
28916 \emph default
28917
28918 \emph on
28919 overlay
28920 \emph default
28921 .
28922  As an embedded programmer you 
28923 \emph on
28924 have
28925 \emph default
28926  to know them so why not look them up 
28927 \emph on
28928 before
28929 \emph default
28930  you have problems?)
28931 \end_layout
28932
28933 \begin_layout Itemize
28934 tell someone else about your problem (actually this is a surprisingly effective
28935  means to hunt down the bug even if the listener is not familiar with your
28936  environment).
28937  As 'failure to communicate' is probably one of the job-induced deformations
28938  of an embedded programmer this is highly encouraged.
28939 \end_layout
28940
28941 \begin_layout Section
28942 Debugging with SDCDB
28943 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
28944
28945 \end_inset
28946
28947
28948 \begin_inset LatexCommand \index{SDCDB (debugger)}
28949
28950 \end_inset
28951
28952  
28953 \end_layout
28954
28955 \begin_layout Standard
28956 SDCC is distributed with a source level debugger
28957 \begin_inset LatexCommand \index{Debugger}
28958
28959 \end_inset
28960
28961 .
28962  The debugger uses a command line interface, the command repertoire of the
28963  debugger has been kept as close to gdb
28964 \begin_inset LatexCommand \index{gdb}
28965
28966 \end_inset
28967
28968  (the GNU debugger) as possible.
28969  The configuration and build process is part of the standard compiler installati
28970 on, which also builds and installs the debugger in the target directory
28971  specified during configuration.
28972  The debugger allows you debug BOTH at the C source and at the ASM source
28973  level.
28974 \end_layout
28975
28976 \begin_layout Subsection
28977 Compiling for Debugging
28978 \end_layout
28979
28980 \begin_layout Standard
28981 The -
28982 \begin_inset ERT
28983 status collapsed
28984
28985 \begin_layout Standard
28986
28987
28988 \backslash
28989 /
28990 \end_layout
28991
28992 \end_inset
28993
28994 -debug
28995 \begin_inset LatexCommand \index{-\/-debug}
28996
28997 \end_inset
28998
28999  option must be specified for all files for which debug information is to
29000  be generated.
29001  The compiler generates a .adb file for each of these files.
29002  The linker creates the .cdb
29003 \begin_inset LatexCommand \index{<file>.cdb}
29004
29005 \end_inset
29006
29007  file from the .adb
29008 \begin_inset LatexCommand \index{<file>.adb}
29009
29010 \end_inset
29011
29012  files and the address information.
29013  This .cdb is used by the debugger.
29014 \end_layout
29015
29016 \begin_layout Subsection
29017 How the Debugger Works
29018 \end_layout
29019
29020 \begin_layout Standard
29021 When the -
29022 \begin_inset ERT
29023 status collapsed
29024
29025 \begin_layout Standard
29026
29027
29028 \backslash
29029 /
29030 \end_layout
29031
29032 \end_inset
29033
29034 -debug option is specified the compiler generates extra symbol information
29035  some of which are put into the assembler source and some are put into the
29036  .adb file.
29037  Then the linker creates the .cdb file from the individual .adb files with
29038  the address information for the symbols.
29039  The debugger reads the symbolic information generated by the compiler &
29040  the address information generated by the linker.
29041  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
29042  execution is controlled by the debugger.
29043  When a command is issued for the debugger, it translates it into appropriate
29044  commands for the simulator.
29045  (Currently SDCDM only connects to the simulator but 
29046 \emph on
29047 newcdb
29048 \emph default
29049  at 
29050 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
29051
29052 \end_inset
29053
29054  is an effort to connect directly to the hardware.) 
29055 \end_layout
29056
29057 \begin_layout Subsection
29058 Starting the Debugger SDCDB
29059 \end_layout
29060
29061 \begin_layout Standard
29062 The debugger can be started using the following command line.
29063  (Assume the file you are debugging has the file name foo).
29064 \newline
29065
29066 \newline
29067
29068 \family sans
29069 \series bold
29070 sdcdb foo
29071 \newline
29072
29073 \family default
29074 \series default
29075
29076 \newline
29077 The debugger will look for the following files.
29078 \end_layout
29079
29080 \begin_layout Itemize
29081 foo.c - the source file.
29082 \end_layout
29083
29084 \begin_layout Itemize
29085 foo.cdb - the debugger symbol information file.
29086 \end_layout
29087
29088 \begin_layout Itemize
29089 foo.ihx - the Intel hex format
29090 \begin_inset LatexCommand \index{Intel hex format}
29091
29092 \end_inset
29093
29094  object file.
29095 \end_layout
29096
29097 \begin_layout Subsection
29098 SDCDB Command Line Options
29099 \end_layout
29100
29101 \begin_layout Itemize
29102 -
29103 \begin_inset ERT
29104 status collapsed
29105
29106 \begin_layout Standard
29107
29108
29109 \backslash
29110 /
29111 \end_layout
29112
29113 \end_inset
29114
29115 -directory=<source file directory> this option can used to specify the directory
29116  search list.
29117  The debugger will look into the directory list specified for source, cdb
29118  & ihx files.
29119  The items in the directory list must be separated by ':', e.g.
29120  if the source files can be in the directories /home/src1 and /home/src2,
29121  the -
29122 \begin_inset ERT
29123 status collapsed
29124
29125 \begin_layout Standard
29126
29127
29128 \backslash
29129 /
29130 \end_layout
29131
29132 \end_inset
29133
29134 -directory option should be -
29135 \begin_inset ERT
29136 status collapsed
29137
29138 \begin_layout Standard
29139
29140
29141 \backslash
29142 /
29143 \end_layout
29144
29145 \end_inset
29146
29147 -directory=/home/src1:/home/src2.
29148  Note there can be no spaces in the option.
29149  
29150 \end_layout
29151
29152 \begin_layout Itemize
29153 -cd <directory> - change to the <directory>.
29154 \end_layout
29155
29156 \begin_layout Itemize
29157 -fullname - used by GUI front ends.
29158 \end_layout
29159
29160 \begin_layout Itemize
29161 -cpu <cpu-type> - this argument is passed to the simulator please see the
29162  simulator docs for details.
29163 \end_layout
29164
29165 \begin_layout Itemize
29166 -X <Clock frequency > this options is passed to the simulator please see
29167  the simulator docs for details.
29168 \end_layout
29169
29170 \begin_layout Itemize
29171 -s <serial port file> passed to simulator see the simulator docs for details.
29172 \end_layout
29173
29174 \begin_layout Itemize
29175 -S <serial in,out> passed to simulator see the simulator docs for details.
29176 \end_layout
29177
29178 \begin_layout Itemize
29179 -k <port number> passed to simulator see the simulator docs for details.
29180 \end_layout
29181
29182 \begin_layout Subsection
29183 SDCDB Debugger Commands
29184 \end_layout
29185
29186 \begin_layout Standard
29187 As mentioned earlier the command interface for the debugger has been deliberatel
29188 y kept as close the GNU debugger gdb, as possible.
29189  This will help the integration with existing graphical user interfaces
29190  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
29191  If you use a graphical user interface for the debugger you can skip this
29192  section.
29193 \end_layout
29194
29195 \begin_layout Subsubsection*
29196 break [line | file:line | function | file:function]
29197 \end_layout
29198
29199 \begin_layout Standard
29200 Set breakpoint at specified line or function:
29201 \newline
29202
29203 \newline
29204
29205 \family sans
29206 \series bold
29207 sdcdb>break 100 
29208 \newline
29209 sdcdb>break foo.c:100
29210 \newline
29211 sdcdb>break funcfoo
29212 \newline
29213 sdcdb>break foo.c:funcfoo
29214 \end_layout
29215
29216 \begin_layout Subsubsection*
29217 clear [line | file:line | function | file:function ]
29218 \end_layout
29219
29220 \begin_layout Standard
29221 Clear breakpoint at specified line or function:
29222 \newline
29223
29224 \newline
29225
29226 \family sans
29227 \series bold
29228 sdcdb>clear 100
29229 \newline
29230 sdcdb>clear foo.c:100
29231 \newline
29232 sdcdb>clear funcfoo
29233 \newline
29234 sdcdb>clear foo.c:funcfoo
29235 \end_layout
29236
29237 \begin_layout Subsubsection*
29238 continue
29239 \end_layout
29240
29241 \begin_layout Standard
29242 Continue program being debugged, after breakpoint.
29243 \end_layout
29244
29245 \begin_layout Subsubsection*
29246 finish
29247 \end_layout
29248
29249 \begin_layout Standard
29250 Execute till the end of the current function.
29251 \end_layout
29252
29253 \begin_layout Subsubsection*
29254 delete [n]
29255 \end_layout
29256
29257 \begin_layout Standard
29258 Delete breakpoint number 'n'.
29259  If used without any option clear ALL user defined break points.
29260 \end_layout
29261
29262 \begin_layout Subsubsection*
29263 info [break | stack | frame | registers ]
29264 \end_layout
29265
29266 \begin_layout Itemize
29267 info break - list all breakpoints
29268 \end_layout
29269
29270 \begin_layout Itemize
29271 info stack - show the function call stack.
29272 \end_layout
29273
29274 \begin_layout Itemize
29275 info frame - show information about the current execution frame.
29276 \end_layout
29277
29278 \begin_layout Itemize
29279 info registers - show content of all registers.
29280 \end_layout
29281
29282 \begin_layout Subsubsection*
29283 step
29284 \end_layout
29285
29286 \begin_layout Standard
29287 Step program until it reaches a different source line.
29288  Note: pressing <return> repeats the last command.
29289 \end_layout
29290
29291 \begin_layout Subsubsection*
29292 next
29293 \end_layout
29294
29295 \begin_layout Standard
29296 Step program, proceeding through subroutine calls.
29297 \end_layout
29298
29299 \begin_layout Subsubsection*
29300 run
29301 \end_layout
29302
29303 \begin_layout Standard
29304 Start debugged program.
29305 \end_layout
29306
29307 \begin_layout Subsubsection*
29308 ptype variable 
29309 \end_layout
29310
29311 \begin_layout Standard
29312 Print type information of the variable.
29313 \end_layout
29314
29315 \begin_layout Subsubsection*
29316 print variable
29317 \end_layout
29318
29319 \begin_layout Standard
29320 print value of variable.
29321 \end_layout
29322
29323 \begin_layout Subsubsection*
29324 file filename
29325 \end_layout
29326
29327 \begin_layout Standard
29328 load the given file name.
29329  Note this is an alternate method of loading file for debugging.
29330 \end_layout
29331
29332 \begin_layout Subsubsection*
29333 frame
29334 \end_layout
29335
29336 \begin_layout Standard
29337 print information about current frame.
29338 \end_layout
29339
29340 \begin_layout Subsubsection*
29341 set srcmode
29342 \end_layout
29343
29344 \begin_layout Standard
29345 Toggle between C source & assembly source.
29346 \end_layout
29347
29348 \begin_layout Subsubsection*
29349 ! simulator command
29350 \end_layout
29351
29352 \begin_layout Standard
29353 Send the string following '!' to the simulator, the simulator response is
29354  displayed.
29355  Note the debugger does not interpret the command being sent to the simulator,
29356  so if a command like 'go' is sent the debugger can loose its execution
29357  context and may display incorrect values.
29358 \end_layout
29359
29360 \begin_layout Subsubsection*
29361 quit
29362 \end_layout
29363
29364 \begin_layout Standard
29365 "Watch me now.
29366  Iam going Down.
29367  My name is Bobby Brown"
29368 \end_layout
29369
29370 \begin_layout Subsection
29371 Interfacing SDCDB with DDD
29372 \end_layout
29373
29374 \begin_layout Standard
29375 \begin_inset Note Note
29376 status collapsed
29377
29378 \begin_layout Standard
29379 The screenshot was converted from png to eps with: 
29380 \begin_inset Quotes sld
29381 \end_inset
29382
29383 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
29384 \begin_inset Quotes srd
29385 \end_inset
29386
29387  which produces a pretty compact eps file which is free from compression
29388  artifacts.
29389 \end_layout
29390
29391 \begin_layout Standard
29392 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
29393  as this broke the build system on Sourceforge (pdf-file was broken.
29394  pdflatex does not accept eps files).
29395 \end_layout
29396
29397 \end_inset
29398
29399
29400 \end_layout
29401
29402 \begin_layout Standard
29403 The 
29404 \emph on
29405 p
29406 \emph default
29407 ortable 
29408 \emph on
29409 n
29410 \emph default
29411 etwork 
29412 \emph on
29413 g
29414 \emph default
29415 raphics File 
29416 \size footnotesize
29417
29418 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
29419
29420 \end_inset
29421
29422
29423 \size default
29424  shows a screenshot of a debugging session with DDD
29425 \begin_inset LatexCommand \index{DDD (debugger)}
29426
29427 \end_inset
29428
29429  (Unix only) on a simulated 8032.
29430  The debugging session might not run as smoothly as the screenshot suggests.
29431  The debugger allows setting of breakpoints, displaying and changing variables,
29432  single stepping through C and assembler code.
29433  
29434 \newline
29435 The source was compiled with 
29436 \family sans
29437 \series bold
29438
29439 \newline
29440
29441 \newline
29442 sdcc -
29443 \family default
29444 \series default
29445
29446 \begin_inset ERT
29447 status collapsed
29448
29449 \begin_layout Standard
29450
29451
29452 \backslash
29453 /
29454 \end_layout
29455
29456 \end_inset
29457
29458
29459 \family sans
29460 \series bold
29461 -debug ddd_example.c
29462 \family default
29463 \series default
29464  
29465 \family sans
29466 \series bold
29467
29468 \newline
29469
29470 \family default
29471 \series default
29472
29473 \newline
29474 and DDD was invoked with 
29475 \family sans
29476 \series bold
29477
29478 \newline
29479
29480 \newline
29481 ddd -debugger "sdcdb -cpu 8032 ddd_example"
29482 \end_layout
29483
29484 \begin_layout Standard
29485 \begin_inset Note Note
29486 status open
29487
29488 \begin_layout Standard
29489 Check that the double quotes or an apostroph within the command line survive
29490  the LyX tool chain.
29491  Previously the apostrophs got slanted in the PDF output so a cut and paste
29492  did not work.
29493 \end_layout
29494
29495 \end_inset
29496
29497
29498 \end_layout
29499
29500 \begin_layout Subsection
29501 Interfacing SDCDB with XEmacs
29502 \begin_inset LatexCommand \index{XEmacs}
29503
29504 \end_inset
29505
29506
29507 \begin_inset LatexCommand \index{Emacs}
29508
29509 \end_inset
29510
29511
29512 \end_layout
29513
29514 \begin_layout Standard
29515 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
29516  sdcdb.el and sdcdbsrc.el.
29517  These two files can be found in the $(prefix)/bin directory after the installat
29518 ion is complete.
29519  These files need to be loaded into XEmacs for the interface to work.
29520  This can be done at XEmacs startup time by inserting the following into
29521  your '.xemacs' file (which can be found in your HOME directory): 
29522 \newline
29523
29524 \newline
29525
29526 \family typewriter
29527 (load-file sdcdbsrc.el) 
29528 \family default
29529
29530 \newline
29531
29532 \newline
29533 .xemacs is a lisp file so the () around the command is REQUIRED.
29534  The files can also be loaded dynamically while XEmacs is running, set the
29535  environment variable 'EMACSLOADPATH' to the installation bin directory
29536  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
29537  To start the interface enter the following command: 
29538 \newline
29539
29540 \newline
29541
29542 \family sans
29543 \series bold
29544 ESC-x sdcdbsrc
29545 \family default
29546 \series default
29547
29548 \newline
29549
29550 \newline
29551 You will prompted to enter the file name to be debugged.
29552  
29553 \newline
29554
29555 \newline
29556 The command line options that are passed to the simulator directly are
29557  bound to default values in the file sdcdbsrc.el.
29558  The variables are listed below, these values maybe changed as required.
29559 \end_layout
29560
29561 \begin_layout Itemize
29562 sdcdbsrc-cpu-type '51
29563 \end_layout
29564
29565 \begin_layout Itemize
29566 sdcdbsrc-frequency '11059200
29567 \end_layout
29568
29569 \begin_layout Itemize
29570 sdcdbsrc-serial nil
29571 \end_layout
29572
29573 \begin_layout Standard
29574 The following is a list of key mapping for the debugger interface.
29575 \end_layout
29576
29577 \begin_layout Standard
29578 \InsetSpace ~
29579
29580 \family typewriter
29581
29582 \newline
29583 ;;\InsetSpace ~
29584 Current Listing :: 
29585 \newline
29586 ;;key\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 binding\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 Comment 
29623 \newline
29624 ;;---\InsetSpace ~
29625 \InsetSpace ~
29626 \InsetSpace ~
29627 \InsetSpace ~
29628 \InsetSpace ~
29629 \InsetSpace ~
29630 \InsetSpace ~
29631 \InsetSpace ~
29632 \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 \InsetSpace ~
29648 \InsetSpace ~
29649 \InsetSpace ~
29650 \InsetSpace ~
29651 \InsetSpace ~
29652 \InsetSpace ~
29653 \InsetSpace ~
29654 \InsetSpace ~
29655 \InsetSpace ~
29656 \InsetSpace ~
29657 \InsetSpace ~
29658 \InsetSpace ~
29659 \InsetSpace ~
29660 -------
29661 \newline
29662 ;; 
29663 \newline
29664 ;;\InsetSpace ~
29665 n\InsetSpace ~
29666 \InsetSpace ~
29667 \InsetSpace ~
29668 \InsetSpace ~
29669 \InsetSpace ~
29670 \InsetSpace ~
29671 \InsetSpace ~
29672 \InsetSpace ~
29673 \InsetSpace ~
29674 \InsetSpace ~
29675 \InsetSpace ~
29676 \InsetSpace ~
29677 \InsetSpace ~
29678 \InsetSpace ~
29679 \InsetSpace ~
29680 sdcdb-next-fro
29681 m-src\InsetSpace ~
29682 \InsetSpace ~
29683 \InsetSpace ~
29684 \InsetSpace ~
29685 \InsetSpace ~
29686 \InsetSpace ~
29687 \InsetSpace ~
29688 \InsetSpace ~
29689 \InsetSpace ~
29690 \InsetSpace ~
29691 SDCDB next command 
29692 \newline
29693 ;;\InsetSpace ~
29694 b\InsetSpace ~
29695 \InsetSpace ~
29696 \InsetSpace ~
29697 \InsetSpace ~
29698 \InsetSpace ~
29699 \InsetSpace ~
29700 \InsetSpace ~
29701 \InsetSpace ~
29702 \InsetSpace ~
29703 \InsetSpace ~
29704 \InsetSpace ~
29705 \InsetSpace ~
29706 \InsetSpace ~
29707 \InsetSpace ~
29708 \InsetSpace ~
29709 sdcdb-back-from-src\InsetSpace ~
29710 \InsetSpace ~
29711 \InsetSpace ~
29712 \InsetSpace ~
29713 \InsetSpace ~
29714 \InsetSpace ~
29715 \InsetSpace ~
29716 \InsetSpace ~
29717 \InsetSpace ~
29718 \InsetSpace ~
29719 SDCDB back command 
29720 \newline
29721 ;;\InsetSpace ~
29722 c\InsetSpace ~
29723 \InsetSpace ~
29724 \InsetSpace ~
29725 \InsetSpace ~
29726 \InsetSpace ~
29727 \InsetSpace ~
29728 \InsetSpace ~
29729 \InsetSpace ~
29730 \InsetSpace ~
29731 \InsetSpace ~
29732 \InsetSpace ~
29733 \InsetSpace ~
29734 \InsetSpace ~
29735 \InsetSpace ~
29736 \InsetSpace ~
29737 sdcdb-cont-f
29738 rom-src\InsetSpace ~
29739 \InsetSpace ~
29740 \InsetSpace ~
29741 \InsetSpace ~
29742 \InsetSpace ~
29743 \InsetSpace ~
29744 \InsetSpace ~
29745 \InsetSpace ~
29746 \InsetSpace ~
29747 \InsetSpace ~
29748 SDCDB continue command
29749 \newline
29750 ;;\InsetSpace ~
29751 s\InsetSpace ~
29752 \InsetSpace ~
29753 \InsetSpace ~
29754 \InsetSpace ~
29755 \InsetSpace ~
29756 \InsetSpace ~
29757 \InsetSpace ~
29758 \InsetSpace ~
29759 \InsetSpace ~
29760 \InsetSpace ~
29761 \InsetSpace ~
29762 \InsetSpace ~
29763 \InsetSpace ~
29764 \InsetSpace ~
29765 \InsetSpace ~
29766 sdcdb-step-from-src\InsetSpace ~
29767 \InsetSpace ~
29768 \InsetSpace ~
29769 \InsetSpace ~
29770 \InsetSpace ~
29771 \InsetSpace ~
29772 \InsetSpace ~
29773 \InsetSpace ~
29774 \InsetSpace ~
29775 \InsetSpace ~
29776 SDCDB step command 
29777 \newline
29778 ;;\InsetSpace ~
29779 ?\InsetSpace ~
29780 \InsetSpace ~
29781 \InsetSpace ~
29782 \InsetSpace ~
29783 \InsetSpace ~
29784 \InsetSpace ~
29785 \InsetSpace ~
29786 \InsetSpace ~
29787 \InsetSpace ~
29788 \InsetSpace ~
29789 \InsetSpace ~
29790 \InsetSpace ~
29791 \InsetSpace ~
29792 \InsetSpace ~
29793 \InsetSpace ~
29794 sdcdb-w
29795 hatis-c-sexp\InsetSpace ~
29796 \InsetSpace ~
29797 \InsetSpace ~
29798 \InsetSpace ~
29799 \InsetSpace ~
29800 \InsetSpace ~
29801 \InsetSpace ~
29802 \InsetSpace ~
29803 \InsetSpace ~
29804 \InsetSpace ~
29805 SDCDB ptypecommand for data at 
29806 \newline
29807 ;;\InsetSpace ~
29808 \InsetSpace ~
29809 \InsetSpace ~
29810 \InsetSpace ~
29811 \InsetSpace ~
29812 \InsetSpace ~
29813 \InsetSpace ~
29814 \InsetSpace ~
29815 \InsetSpace ~
29816 \InsetSpace ~
29817 \InsetSpace ~
29818 \InsetSpace ~
29819 \InsetSpace ~
29820 \InsetSpace ~
29821 \InsetSpace ~
29822 \InsetSpace ~
29823 \InsetSpace ~
29824 \InsetSpace ~
29825 \InsetSpace ~
29826 \InsetSpace ~
29827 \InsetSpace ~
29828 \InsetSpace ~
29829 \InsetSpace ~
29830 \InsetSpace ~
29831 \InsetSpace ~
29832 \InsetSpace ~
29833 \InsetSpace ~
29834 \InsetSpace ~
29835 \InsetSpace ~
29836 \InsetSpace ~
29837 \InsetSpace ~
29838 \InsetSpace ~
29839 \InsetSpace ~
29840 \InsetSpace ~
29841 \InsetSpace ~
29842 \InsetSpace ~
29843 \InsetSpace ~
29844 \InsetSpace ~
29845 \InsetSpace ~
29846 \InsetSpace ~
29847 \InsetSpace ~
29848 \InsetSpace ~
29849 \InsetSpace ~
29850 \InsetSpace ~
29851 \InsetSpace ~
29852 \InsetSpace ~
29853 \InsetSpace ~
29854 buffer point 
29855 \newline
29856 ;;\InsetSpace ~
29857 x\InsetSpace ~
29858 \InsetSpace ~
29859 \InsetSpace ~
29860 \InsetSpace ~
29861 \InsetSpace ~
29862 \InsetSpace ~
29863 \InsetSpace ~
29864 \InsetSpace ~
29865 \InsetSpace ~
29866 \InsetSpace ~
29867 \InsetSpace ~
29868 \InsetSpace ~
29869 \InsetSpace ~
29870 \InsetSpace ~
29871 \InsetSpace ~
29872 sdcdbsrc-delete\InsetSpace ~
29873 \InsetSpace ~
29874 \InsetSpace ~
29875 \InsetSpace ~
29876 \InsetSpace ~
29877 \InsetSpace ~
29878 \InsetSpace ~
29879 \InsetSpace ~
29880 \InsetSpace ~
29881 \InsetSpace ~
29882 \InsetSpace ~
29883 \InsetSpace ~
29884 \InsetSpace ~
29885 \InsetSpace ~
29886 SDCD
29887 B Delete all breakpoints if no arg 
29888 \newline
29889 ;;\InsetSpace ~
29890 \InsetSpace ~
29891 \InsetSpace ~
29892 \InsetSpace ~
29893 \InsetSpace ~
29894 \InsetSpace ~
29895 \InsetSpace ~
29896 \InsetSpace ~
29897 \InsetSpace ~
29898 \InsetSpace ~
29899 \InsetSpace ~
29900 \InsetSpace ~
29901 \InsetSpace ~
29902 \InsetSpace ~
29903 \InsetSpace ~
29904 \InsetSpace ~
29905 \InsetSpace ~
29906 \InsetSpace ~
29907 \InsetSpace ~
29908 \InsetSpace ~
29909 \InsetSpace ~
29910 \InsetSpace ~
29911 \InsetSpace ~
29912 \InsetSpace ~
29913 \InsetSpace ~
29914 \InsetSpace ~
29915 \InsetSpace ~
29916 \InsetSpace ~
29917 \InsetSpace ~
29918 \InsetSpace ~
29919 \InsetSpace ~
29920 \InsetSpace ~
29921 \InsetSpace ~
29922 \InsetSpace ~
29923 \InsetSpace ~
29924 \InsetSpace ~
29925 \InsetSpace ~
29926 \InsetSpace ~
29927 \InsetSpace ~
29928 \InsetSpace ~
29929 \InsetSpace ~
29930 \InsetSpace ~
29931 \InsetSpace ~
29932 \InsetSpace ~
29933 \InsetSpace ~
29934 \InsetSpace ~
29935 \InsetSpace ~
29936 given or delete arg (C-u arg x) 
29937 \newline
29938 ;;\InsetSpace ~
29939 m\InsetSpace ~
29940 \InsetSpace ~
29941 \InsetSpace ~
29942 \InsetSpace ~
29943 \InsetSpace ~
29944 \InsetSpace ~
29945 \InsetSpace ~
29946 \InsetSpace ~
29947 \InsetSpace ~
29948 \InsetSpace ~
29949 \InsetSpace ~
29950 \InsetSpace ~
29951 \InsetSpace ~
29952 \InsetSpace ~
29953 \InsetSpace ~
29954 sdcdbsrc
29955 -frame\InsetSpace ~
29956 \InsetSpace ~
29957 \InsetSpace ~
29958 \InsetSpace ~
29959 \InsetSpace ~
29960 \InsetSpace ~
29961 \InsetSpace ~
29962 \InsetSpace ~
29963 \InsetSpace ~
29964 \InsetSpace ~
29965 \InsetSpace ~
29966 \InsetSpace ~
29967 \InsetSpace ~
29968 \InsetSpace ~
29969 \InsetSpace ~
29970 SDCDB Display current frame if no arg, 
29971 \newline
29972 ;;\InsetSpace ~
29973 \InsetSpace ~
29974 \InsetSpace ~
29975 \InsetSpace ~
29976 \InsetSpace ~
29977 \InsetSpace ~
29978 \InsetSpace ~
29979 \InsetSpace ~
29980 \InsetSpace ~
29981 \InsetSpace ~
29982 \InsetSpace ~
29983 \InsetSpace ~
29984 \InsetSpace ~
29985 \InsetSpace ~
29986 \InsetSpace ~
29987 \InsetSpace ~
29988 \InsetSpace ~
29989 \InsetSpace ~
29990 \InsetSpace ~
29991 \InsetSpace ~
29992 \InsetSpace ~
29993 \InsetSpace ~
29994 \InsetSpace ~
29995 \InsetSpace ~
29996 \InsetSpace ~
29997 \InsetSpace ~
29998 \InsetSpace ~
29999 \InsetSpace ~
30000 \InsetSpace ~
30001 \InsetSpace ~
30002 \InsetSpace ~
30003 \InsetSpace ~
30004 \InsetSpace ~
30005 \InsetSpace ~
30006 \InsetSpace ~
30007 \InsetSpace ~
30008 \InsetSpace ~
30009 \InsetSpace ~
30010 \InsetSpace ~
30011 \InsetSpace ~
30012 \InsetSpace ~
30013 \InsetSpace ~
30014 \InsetSpace ~
30015 \InsetSpace ~
30016 \InsetSpace ~
30017 \InsetSpace ~
30018 \InsetSpace ~
30019 given or display frame arg
30020  
30021 \newline
30022 ;;\InsetSpace ~
30023 \InsetSpace ~
30024 \InsetSpace ~
30025 \InsetSpace ~
30026 \InsetSpace ~
30027 \InsetSpace ~
30028 \InsetSpace ~
30029 \InsetSpace ~
30030 \InsetSpace ~
30031 \InsetSpace ~
30032 \InsetSpace ~
30033 \InsetSpace ~
30034 \InsetSpace ~
30035 \InsetSpace ~
30036 \InsetSpace ~
30037 \InsetSpace ~
30038 \InsetSpace ~
30039 \InsetSpace ~
30040 \InsetSpace ~
30041 \InsetSpace ~
30042 \InsetSpace ~
30043 \InsetSpace ~
30044 \InsetSpace ~
30045 \InsetSpace ~
30046 \InsetSpace ~
30047 \InsetSpace ~
30048 \InsetSpace ~
30049 \InsetSpace ~
30050 \InsetSpace ~
30051 \InsetSpace ~
30052 \InsetSpace ~
30053 \InsetSpace ~
30054 \InsetSpace ~
30055 \InsetSpace ~
30056 \InsetSpace ~
30057 \InsetSpace ~
30058 \InsetSpace ~
30059 \InsetSpace ~
30060 \InsetSpace ~
30061 \InsetSpace ~
30062 \InsetSpace ~
30063 \InsetSpace ~
30064 \InsetSpace ~
30065 \InsetSpace ~
30066 \InsetSpace ~
30067 \InsetSpace ~
30068 \InsetSpace ~
30069 buffer point 
30070 \newline
30071 ;;\InsetSpace ~
30072 !\InsetSpace ~
30073 \InsetSpace ~
30074 \InsetSpace ~
30075 \InsetSpace ~
30076 \InsetSpace ~
30077 \InsetSpace ~
30078 \InsetSpace ~
30079 \InsetSpace ~
30080 \InsetSpace ~
30081 \InsetSpace ~
30082 \InsetSpace ~
30083 \InsetSpace ~
30084 \InsetSpace ~
30085 \InsetSpace ~
30086 \InsetSpace ~
30087 sdcdbsrc-goto-sdcdb\InsetSpace ~
30088 \InsetSpace ~
30089 \InsetSpace ~
30090 \InsetSpace ~
30091 \InsetSpace ~
30092 \InsetSpace ~
30093 \InsetSpace ~
30094 \InsetSpace ~
30095 \InsetSpace ~
30096 \InsetSpace ~
30097 Goto the SDCDB output buffer 
30098 \newline
30099 ;;\InsetSpace ~
30100 p\InsetSpace ~
30101 \InsetSpace ~
30102 \InsetSpace ~
30103 \InsetSpace ~
30104 \InsetSpace ~
30105 \InsetSpace ~
30106 \InsetSpace ~
30107 \InsetSpace ~
30108 \InsetSpace ~
30109 \InsetSpace ~
30110 \InsetSpace ~
30111 \InsetSpace ~
30112 \InsetSpace ~
30113 \InsetSpace ~
30114 \InsetSpace ~
30115 sdcdb-prin
30116 t-c-sexp\InsetSpace ~
30117 \InsetSpace ~
30118 \InsetSpace ~
30119 \InsetSpace ~
30120 \InsetSpace ~
30121 \InsetSpace ~
30122 \InsetSpace ~
30123 \InsetSpace ~
30124 \InsetSpace ~
30125 \InsetSpace ~
30126 \InsetSpace ~
30127 SDCDB print command for data at 
30128 \newline
30129 ;;\InsetSpace ~
30130 \InsetSpace ~
30131 \InsetSpace ~
30132 \InsetSpace ~
30133 \InsetSpace ~
30134 \InsetSpace ~
30135 \InsetSpace ~
30136 \InsetSpace ~
30137 \InsetSpace ~
30138 \InsetSpace ~
30139 \InsetSpace ~
30140 \InsetSpace ~
30141 \InsetSpace ~
30142 \InsetSpace ~
30143 \InsetSpace ~
30144 \InsetSpace ~
30145 \InsetSpace ~
30146 \InsetSpace ~
30147 \InsetSpace ~
30148 \InsetSpace ~
30149 \InsetSpace ~
30150 \InsetSpace ~
30151 \InsetSpace ~
30152 \InsetSpace ~
30153 \InsetSpace ~
30154 \InsetSpace ~
30155 \InsetSpace ~
30156 \InsetSpace ~
30157 \InsetSpace ~
30158 \InsetSpace ~
30159 \InsetSpace ~
30160 \InsetSpace ~
30161 \InsetSpace ~
30162 \InsetSpace ~
30163 \InsetSpace ~
30164 \InsetSpace ~
30165 \InsetSpace ~
30166 \InsetSpace ~
30167 \InsetSpace ~
30168 \InsetSpace ~
30169 \InsetSpace ~
30170 \InsetSpace ~
30171 \InsetSpace ~
30172 \InsetSpace ~
30173 \InsetSpace ~
30174 \InsetSpace ~
30175 \InsetSpace ~
30176 buffer point 
30177 \newline
30178 ;;\InsetSpace ~
30179 g\InsetSpace ~
30180 \InsetSpace ~
30181 \InsetSpace ~
30182 \InsetSpace ~
30183 \InsetSpace ~
30184 \InsetSpace ~
30185 \InsetSpace ~
30186 \InsetSpace ~
30187 \InsetSpace ~
30188 \InsetSpace ~
30189 \InsetSpace ~
30190 \InsetSpace ~
30191 \InsetSpace ~
30192 \InsetSpace ~
30193 \InsetSpace ~
30194 sdcdbsrc-goto-sdcdb\InsetSpace ~
30195 \InsetSpace ~
30196 \InsetSpace ~
30197 \InsetSpace ~
30198 \InsetSpace ~
30199 \InsetSpace ~
30200 \InsetSpace ~
30201 \InsetSpace ~
30202 \InsetSpace ~
30203 \InsetSpace ~
30204 Got
30205 o the SDCDB output buffer 
30206 \newline
30207 ;;\InsetSpace ~
30208 t\InsetSpace ~
30209 \InsetSpace ~
30210 \InsetSpace ~
30211 \InsetSpace ~
30212 \InsetSpace ~
30213 \InsetSpace ~
30214 \InsetSpace ~
30215 \InsetSpace ~
30216 \InsetSpace ~
30217 \InsetSpace ~
30218 \InsetSpace ~
30219 \InsetSpace ~
30220 \InsetSpace ~
30221 \InsetSpace ~
30222 \InsetSpace ~
30223 sdcdbsrc-mode\InsetSpace ~
30224 \InsetSpace ~
30225 \InsetSpace ~
30226 \InsetSpace ~
30227 \InsetSpace ~
30228 \InsetSpace ~
30229 \InsetSpace ~
30230 \InsetSpace ~
30231 \InsetSpace ~
30232 \InsetSpace ~
30233 \InsetSpace ~
30234 \InsetSpace ~
30235 \InsetSpace ~
30236 \InsetSpace ~
30237 \InsetSpace ~
30238 \InsetSpace ~
30239 Toggles Sdcdbsrc mode (turns it
30240  off) 
30241 \newline
30242 ;; 
30243 \newline
30244 ;;\InsetSpace ~
30245 C-c\InsetSpace ~
30246 C-f\InsetSpace ~
30247 \InsetSpace ~
30248 \InsetSpace ~
30249 \InsetSpace ~
30250 \InsetSpace ~
30251 \InsetSpace ~
30252 \InsetSpace ~
30253 \InsetSpace ~
30254 \InsetSpace ~
30255 sdcdb-finish-from-src\InsetSpace ~
30256 \InsetSpace ~
30257 \InsetSpace ~
30258 \InsetSpace ~
30259 \InsetSpace ~
30260 \InsetSpace ~
30261 \InsetSpace ~
30262 \InsetSpace ~
30263 SDCDB finish command 
30264 \newline
30265 ;; 
30266 \newline
30267 ;;\InsetSpace ~
30268 C-x\InsetSpace ~
30269 SPC\InsetSpace ~
30270 \InsetSpace ~
30271 \InsetSpace ~
30272 \InsetSpace ~
30273 \InsetSpace ~
30274 \InsetSpace ~
30275 \InsetSpace ~
30276 \InsetSpace ~
30277 \InsetSpace ~
30278 sdcdb-brea
30279 k\InsetSpace ~
30280 \InsetSpace ~
30281 \InsetSpace ~
30282 \InsetSpace ~
30283 \InsetSpace ~
30284 \InsetSpace ~
30285 \InsetSpace ~
30286 \InsetSpace ~
30287 \InsetSpace ~
30288 \InsetSpace ~
30289 \InsetSpace ~
30290 \InsetSpace ~
30291 \InsetSpace ~
30292 \InsetSpace ~
30293 \InsetSpace ~
30294 \InsetSpace ~
30295 \InsetSpace ~
30296 \InsetSpace ~
30297 Set break for line with point 
30298 \newline
30299 ;;\InsetSpace ~
30300 ESC\InsetSpace ~
30301 t\InsetSpace ~
30302 \InsetSpace ~
30303 \InsetSpace ~
30304 \InsetSpace ~
30305 \InsetSpace ~
30306 \InsetSpace ~
30307 \InsetSpace ~
30308 \InsetSpace ~
30309 \InsetSpace ~
30310 \InsetSpace ~
30311 \InsetSpace ~
30312 sdcdbsrc-mode\InsetSpace ~
30313 \InsetSpace ~
30314 \InsetSpace ~
30315 \InsetSpace ~
30316 \InsetSpace ~
30317 \InsetSpace ~
30318 \InsetSpace ~
30319 \InsetSpace ~
30320 \InsetSpace ~
30321 \InsetSpace ~
30322 \InsetSpace ~
30323 \InsetSpace ~
30324 \InsetSpace ~
30325 \InsetSpace ~
30326 \InsetSpace ~
30327 \InsetSpace ~
30328 Toggle Sdcdbsrc mode 
30329 \newline
30330 ;;\InsetSpace ~
30331 ESC\InsetSpace ~
30332 m\InsetSpace ~
30333 \InsetSpace ~
30334 \InsetSpace ~
30335 \InsetSpace ~
30336 \InsetSpace ~
30337 \InsetSpace ~
30338 \InsetSpace ~
30339 \InsetSpace ~
30340 \InsetSpace ~
30341 \InsetSpace ~
30342 \InsetSpace ~
30343 sdc
30344 dbsrc-srcmode\InsetSpace ~
30345 \InsetSpace ~
30346 \InsetSpace ~
30347 \InsetSpace ~
30348 \InsetSpace ~
30349 \InsetSpace ~
30350 \InsetSpace ~
30351 \InsetSpace ~
30352 \InsetSpace ~
30353 \InsetSpace ~
30354 \InsetSpace ~
30355 \InsetSpace ~
30356 \InsetSpace ~
30357 Toggle list mode 
30358 \newline
30359 ;; 
30360 \newline
30361
30362 \family default
30363
30364 \newpage
30365
30366 \end_layout
30367
30368 \begin_layout Chapter
30369 TIPS
30370 \end_layout
30371
30372 \begin_layout Standard
30373 Here are a few guidelines that will help the compiler generate more efficient
30374  code, some of the tips are specific to this compiler others are generally
30375  good programming practice.
30376 \end_layout
30377
30378 \begin_layout Itemize
30379 Use the smallest data type to represent your data-value.
30380  If it is known in advance that the value is going to be less than 256 then
30381  use an 'unsigned char' instead of a 'short' or 'int'.
30382  Please note, that ANSI C requires both signed and unsigned chars to be
30383  promoted to 'signed int'
30384 \begin_inset LatexCommand \index{promotion to signed int}
30385
30386 \end_inset
30387
30388
30389 \begin_inset Marginal
30390 status collapsed
30391
30392 \begin_layout Standard
30393
30394 \series bold
30395 \InsetSpace ~
30396 !
30397 \end_layout
30398
30399 \end_inset
30400
30401  before doing any operation.
30402  This promotion
30403 \begin_inset LatexCommand \index{type promotion}
30404
30405 \end_inset
30406
30407
30408 \begin_inset LatexCommand \label{type promotion}
30409
30410 \end_inset
30411
30412  can be omitted, if the result is the same.
30413  The effect of the promotion rules together with the sign-extension is often
30414  surprising:
30415 \end_layout
30416
30417 \begin_deeper
30418 \begin_layout Verse
30419
30420 \family typewriter
30421 unsigned char uc = 0xfe;
30422 \newline
30423 if (uc * uc < 0) /* this is true! */
30424 \newline
30425 {
30426 \newline
30427 \InsetSpace ~
30428 \InsetSpace ~
30429 \InsetSpace ~
30430 \InsetSpace ~
30431 ....
30432 \newline
30433 }
30434 \end_layout
30435
30436 \begin_layout Standard
30437
30438 \family typewriter
30439 uc * uc
30440 \family default
30441  is evaluated as 
30442 \family typewriter
30443 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
30444 \family default
30445 .
30446  
30447 \newline
30448 Another one:
30449 \end_layout
30450
30451 \begin_layout Verse
30452
30453 \family typewriter
30454 (unsigned char) -12 / (signed char) -3 = ...
30455 \end_layout
30456
30457 \begin_layout Standard
30458 No, the result is not 4:
30459 \end_layout
30460
30461 \begin_layout Verse
30462
30463 \family typewriter
30464 (int) (unsigned char) -12 / (int) (signed char) -3 =
30465 \newline
30466 (int) (unsigned char)
30467  0xf4 / (int) (signed char) 0xfd =
30468 \newline
30469 (int) 0x00f4 / (int) 0xfffd =
30470 \newline
30471 (int) 0x00f4
30472  / (int) 0xfffd =
30473 \newline
30474 (int) 244 / (int) -3 =
30475 \newline
30476 (int) -81 = (int) 0xffaf;
30477 \end_layout
30478
30479 \begin_layout Standard
30480 Don't complain, that gcc gives you a different result.
30481  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
30482  Therefore the results are different.
30483 \newline
30484 From 
30485 \begin_inset Quotes sld
30486 \end_inset
30487
30488 comp.lang.c FAQ
30489 \begin_inset Quotes srd
30490 \end_inset
30491
30492 :
30493 \end_layout
30494
30495 \begin_layout Quote
30496
30497 \emph on
30498 If well-defined overflow characteristics are important and negative values
30499  are not, or if you want to steer clear of sign-extension problems when
30500  manipulating bits or bytes, use one of the corresponding unsigned types.
30501  (Beware when mixing signed and unsigned values in expressions, though.)
30502 \newline
30503 Although
30504  character types (especially unsigned char) can be used as "tiny" integers,
30505  doing so is sometimes more trouble than it's worth, due to unpredictable
30506  sign extension and increased code size.
30507 \end_layout
30508
30509 \end_deeper
30510 \begin_layout Itemize
30511 Use unsigned when it is known in advance that the value is not going to
30512  be negative.
30513  This helps especially if you are doing division or multiplication, bit-shifting
30514  or are using an array index.
30515 \end_layout
30516
30517 \begin_layout Itemize
30518 NEVER jump into a LOOP.
30519 \end_layout
30520
30521 \begin_layout Itemize
30522 Declare the variables to be local
30523 \begin_inset LatexCommand \index{local variables}
30524
30525 \end_inset
30526
30527  whenever possible, especially loop control variables (induction).
30528 \end_layout
30529
30530 \begin_layout Itemize
30531 Have a look at the assembly listing to get a 
30532 \begin_inset Quotes sld
30533 \end_inset
30534
30535 feeling
30536 \begin_inset Quotes srd
30537 \end_inset
30538
30539  for the code generation.
30540 \end_layout
30541
30542 \begin_layout Section
30543 Porting code from or to other compilers
30544 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
30545
30546 \end_inset
30547
30548
30549 \end_layout
30550
30551 \begin_layout Itemize
30552 check whether endianness of the compilers differs and adapt where needed.
30553 \end_layout
30554
30555 \begin_layout Itemize
30556 check the device specific header files
30557 \begin_inset LatexCommand \index{Header files}
30558
30559 \end_inset
30560
30561
30562 \begin_inset LatexCommand \index{Include files}
30563
30564 \end_inset
30565
30566  for compiler specific syntax.
30567  Eventually include the file <compiler.h
30568 \begin_inset LatexCommand \index{compiler.h (include file)}
30569
30570 \end_inset
30571
30572
30573 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
30574
30575 \end_inset
30576
30577  to allow using common header files.
30578  (see f.e.
30579  cc2510fx.h 
30580 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
30581
30582 \end_inset
30583
30584 ).
30585 \end_layout
30586
30587 \begin_layout Itemize
30588 check whether the startup code contains the correct initialization (watchdog,
30589  peripherals).
30590 \end_layout
30591
30592 \begin_layout Itemize
30593 check whether the sizes of short, int, long match.
30594 \end_layout
30595
30596 \begin_layout Itemize
30597 check if some 16 or 32 bit hardware registers require a specific addressing
30598  order (least significant or most significant byte first) and adapt if needed
30599  (
30600 \emph on
30601 first
30602 \emph default
30603  and 
30604 \emph on
30605 last
30606 \emph default
30607  relate to time and not to lower/upper memory location here, so this is
30608  
30609 \emph on
30610 not
30611 \emph default
30612  the same as endianness).
30613 \end_layout
30614
30615 \begin_layout Itemize
30616 check whether the keyword 
30617 \emph on
30618 volatile
30619 \emph default
30620  is used where needed.
30621  The compilers might differ in their optimization characteristics (as different
30622  versions of the same compiler might also use more clever optimizations
30623  this is good idea anyway).
30624  See section 
30625 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
30626
30627 \end_inset
30628
30629 .
30630 \end_layout
30631
30632 \begin_layout Itemize
30633 check that the compilers are not told to supress warnings.
30634 \end_layout
30635
30636 \begin_layout Itemize
30637 check and convert compiler specific extensions (interrupts, memory areas,
30638  pragmas etc.).
30639 \end_layout
30640
30641 \begin_layout Itemize
30642 check for differences in type promotion.
30643  Especially check for math operations on 
30644 \family typewriter
30645 char
30646 \family default
30647  or 
30648 \family typewriter
30649 unsigned char
30650 \family default
30651  variables.
30652  For the sake of C99 compatibility SDCC will probably promote these to 
30653 \family typewriter
30654 int
30655 \family default
30656  more often than other compilers.
30657  Eventually insert explicit casts to 
30658 \family typewriter
30659 (char) 
30660 \family default
30661 or
30662 \family typewriter
30663  (unsigned char)
30664 \family default
30665 .
30666  Also check that the ~\InsetSpace ~
30667 operator
30668 \begin_inset LatexCommand \index{\~\/ Operator}
30669
30670 \end_inset
30671
30672  is not used on 
30673 \family typewriter
30674 bit
30675 \begin_inset LatexCommand \index{bit}
30676
30677 \end_inset
30678
30679
30680 \family default
30681  variables, use the !\InsetSpace ~
30682 operator instead.
30683  See sections 
30684 \begin_inset LatexCommand \ref{type promotion}
30685
30686 \end_inset
30687
30688  and 
30689 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30690
30691 \end_inset
30692
30693 .
30694 \end_layout
30695
30696 \begin_layout Itemize
30697 check the assembly code generated for interrupt routines (f.e.
30698  for calls to possibly non-reentrant library functions).
30699 \end_layout
30700
30701 \begin_layout Itemize
30702 check whether timing loops result in proper timing (or preferably consider
30703  a rewrite of the code with timer based delays instead).
30704 \end_layout
30705
30706 \begin_layout Itemize
30707 check for differences in printf parameters (some compilers push (va_arg
30708 \begin_inset LatexCommand \index{vararg, va\_arg}
30709
30710 \end_inset
30711
30712 ) char variables as 
30713 \family typewriter
30714 int
30715 \family default
30716  others push them as 
30717 \family typewriter
30718 char
30719 \family default
30720 .
30721  See section 
30722 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
30723
30724 \end_inset
30725
30726 ).
30727 \end_layout
30728
30729 \begin_layout Itemize
30730 check the resulting memory map
30731 \begin_inset LatexCommand \index{Memory map}
30732
30733 \end_inset
30734
30735 .
30736  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
30737 ly idata, pdata, xdata).
30738  Eventually check if unexpected library functions are included.
30739 \end_layout
30740
30741 \begin_layout Section
30742 Tools
30743 \begin_inset LatexCommand \index{Tools}
30744
30745 \end_inset
30746
30747  included in the distribution
30748 \end_layout
30749
30750 \begin_layout Standard
30751 \align left
30752 \begin_inset Tabular
30753 <lyxtabular version="3" rows="12" columns="3">
30754 <features>
30755 <column alignment="left" valignment="top" leftline="true" width="0pt">
30756 <column alignment="left" valignment="top" leftline="true" width="0pt">
30757 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30758 <row topline="true" bottomline="true">
30759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30760 \begin_inset Text
30761
30762 \begin_layout Standard
30763
30764 \series bold
30765 Name
30766 \end_layout
30767
30768 \end_inset
30769 </cell>
30770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30771 \begin_inset Text
30772
30773 \begin_layout Standard
30774
30775 \series bold
30776 Purpose
30777 \end_layout
30778
30779 \end_inset
30780 </cell>
30781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30782 \begin_inset Text
30783
30784 \begin_layout Standard
30785
30786 \series bold
30787 Directory
30788 \end_layout
30789
30790 \end_inset
30791 </cell>
30792 </row>
30793 <row topline="true">
30794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30795 \begin_inset Text
30796
30797 \begin_layout Standard
30798 uCsim
30799 \begin_inset LatexCommand \index{uCsim}
30800
30801 \end_inset
30802
30803
30804 \end_layout
30805
30806 \end_inset
30807 </cell>
30808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30809 \begin_inset Text
30810
30811 \begin_layout Standard
30812 Simulator for various architectures
30813 \end_layout
30814
30815 \end_inset
30816 </cell>
30817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30818 \begin_inset Text
30819
30820 \begin_layout Standard
30821 sdcc/sim/ucsim
30822 \end_layout
30823
30824 \end_inset
30825 </cell>
30826 </row>
30827 <row topline="true">
30828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30829 \begin_inset Text
30830
30831 \begin_layout Standard
30832 keil2sdcc.pl
30833 \end_layout
30834
30835 \end_inset
30836 </cell>
30837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30838 \begin_inset Text
30839
30840 \begin_layout Standard
30841 header file
30842 \begin_inset LatexCommand \index{Header files}
30843
30844 \end_inset
30845
30846
30847 \begin_inset LatexCommand \index{Include files}
30848
30849 \end_inset
30850
30851  conversion
30852 \end_layout
30853
30854 \end_inset
30855 </cell>
30856 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30857 \begin_inset Text
30858
30859 \begin_layout Standard
30860 sdcc/support/scripts
30861 \end_layout
30862
30863 \end_inset
30864 </cell>
30865 </row>
30866 <row topline="true">
30867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30868 \begin_inset Text
30869
30870 \begin_layout Standard
30871 mh2h.c
30872 \end_layout
30873
30874 \end_inset
30875 </cell>
30876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30877 \begin_inset Text
30878
30879 \begin_layout Standard
30880 header file conversion
30881 \end_layout
30882
30883 \end_inset
30884 </cell>
30885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30886 \begin_inset Text
30887
30888 \begin_layout Standard
30889 sdcc/support/scripts
30890 \end_layout
30891
30892 \end_inset
30893 </cell>
30894 </row>
30895 <row topline="true">
30896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30897 \begin_inset Text
30898
30899 \begin_layout Standard
30900 as-gbz80
30901 \end_layout
30902
30903 \end_inset
30904 </cell>
30905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30906 \begin_inset Text
30907
30908 \begin_layout Standard
30909 Assembler
30910 \end_layout
30911
30912 \end_inset
30913 </cell>
30914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30915 \begin_inset Text
30916
30917 \begin_layout Standard
30918
30919 \family roman
30920 \series medium
30921 \shape up
30922 \size normal
30923 \emph off
30924 \bar no
30925 \noun off
30926 \color none
30927 sdcc/bin
30928 \end_layout
30929
30930 \end_inset
30931 </cell>
30932 </row>
30933 <row topline="true">
30934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30935 \begin_inset Text
30936
30937 \begin_layout Standard
30938 as-z80
30939 \end_layout
30940
30941 \end_inset
30942 </cell>
30943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30944 \begin_inset Text
30945
30946 \begin_layout Standard
30947 Assembler
30948 \end_layout
30949
30950 \end_inset
30951 </cell>
30952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30953 \begin_inset Text
30954
30955 \begin_layout Standard
30956
30957 \family roman
30958 \series medium
30959 \shape up
30960 \size normal
30961 \emph off
30962 \bar no
30963 \noun off
30964 \color none
30965 sdcc/bin
30966 \end_layout
30967
30968 \end_inset
30969 </cell>
30970 </row>
30971 <row topline="true">
30972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30973 \begin_inset Text
30974
30975 \begin_layout Standard
30976 asx8051
30977 \end_layout
30978
30979 \end_inset
30980 </cell>
30981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30982 \begin_inset Text
30983
30984 \begin_layout Standard
30985 Assembler
30986 \end_layout
30987
30988 \end_inset
30989 </cell>
30990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30991 \begin_inset Text
30992
30993 \begin_layout Standard
30994
30995 \family roman
30996 \series medium
30997 \shape up
30998 \size normal
30999 \emph off
31000 \bar no
31001 \noun off
31002 \color none
31003 sdcc/bin
31004 \end_layout
31005
31006 \end_inset
31007 </cell>
31008 </row>
31009 <row topline="true">
31010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31011 \begin_inset Text
31012
31013 \begin_layout Standard
31014 SDCDB
31015 \end_layout
31016
31017 \end_inset
31018 </cell>
31019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31020 \begin_inset Text
31021
31022 \begin_layout Standard
31023 Simulator
31024 \end_layout
31025
31026 \end_inset
31027 </cell>
31028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31029 \begin_inset Text
31030
31031 \begin_layout Standard
31032
31033 \family roman
31034 \series medium
31035 \shape up
31036 \size normal
31037 \emph off
31038 \bar no
31039 \noun off
31040 \color none
31041 sdcc/bin
31042 \end_layout
31043
31044 \end_inset
31045 </cell>
31046 </row>
31047 <row topline="true">
31048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31049 \begin_inset Text
31050
31051 \begin_layout Standard
31052 aslink
31053 \end_layout
31054
31055 \end_inset
31056 </cell>
31057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31058 \begin_inset Text
31059
31060 \begin_layout Standard
31061 Linker
31062 \end_layout
31063
31064 \end_inset
31065 </cell>
31066 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31067 \begin_inset Text
31068
31069 \begin_layout Standard
31070
31071 \family roman
31072 \series medium
31073 \shape up
31074 \size normal
31075 \emph off
31076 \bar no
31077 \noun off
31078 \color none
31079 sdcc/bin
31080 \end_layout
31081
31082 \end_inset
31083 </cell>
31084 </row>
31085 <row topline="true">
31086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31087 \begin_inset Text
31088
31089 \begin_layout Standard
31090 link-z80
31091 \end_layout
31092
31093 \end_inset
31094 </cell>
31095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31096 \begin_inset Text
31097
31098 \begin_layout Standard
31099 Linker
31100 \end_layout
31101
31102 \end_inset
31103 </cell>
31104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31105 \begin_inset Text
31106
31107 \begin_layout Standard
31108
31109 \family roman
31110 \series medium
31111 \shape up
31112 \size normal
31113 \emph off
31114 \bar no
31115 \noun off
31116 \color none
31117 sdcc/bin
31118 \end_layout
31119
31120 \end_inset
31121 </cell>
31122 </row>
31123 <row topline="true">
31124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31125 \begin_inset Text
31126
31127 \begin_layout Standard
31128 link-gbz80
31129 \end_layout
31130
31131 \end_inset
31132 </cell>
31133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31134 \begin_inset Text
31135
31136 \begin_layout Standard
31137 Linker
31138 \end_layout
31139
31140 \end_inset
31141 </cell>
31142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31143 \begin_inset Text
31144
31145 \begin_layout Standard
31146
31147 \family roman
31148 \series medium
31149 \shape up
31150 \size normal
31151 \emph off
31152 \bar no
31153 \noun off
31154 \color none
31155 sdcc/bin
31156 \end_layout
31157
31158 \end_inset
31159 </cell>
31160 </row>
31161 <row topline="true" bottomline="true">
31162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31163 \begin_inset Text
31164
31165 \begin_layout Standard
31166 packihx
31167 \end_layout
31168
31169 \end_inset
31170 </cell>
31171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31172 \begin_inset Text
31173
31174 \begin_layout Standard
31175 Intel Hex packer 
31176 \begin_inset LatexCommand \index{packihx (tool)}
31177
31178 \end_inset
31179
31180
31181 \end_layout
31182
31183 \end_inset
31184 </cell>
31185 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31186 \begin_inset Text
31187
31188 \begin_layout Standard
31189
31190 \family roman
31191 \series medium
31192 \shape up
31193 \size normal
31194 \emph off
31195 \bar no
31196 \noun off
31197 \color none
31198 sdcc/bin
31199 \end_layout
31200
31201 \end_inset
31202 </cell>
31203 </row>
31204 </lyxtabular>
31205
31206 \end_inset
31207
31208
31209 \newline
31210
31211 \end_layout
31212
31213 \begin_layout Section
31214 Documentation
31215 \begin_inset LatexCommand \index{Documentation}
31216
31217 \end_inset
31218
31219  included in the distribution
31220 \end_layout
31221
31222 \begin_layout Standard
31223 \align left
31224 \begin_inset Tabular
31225 <lyxtabular version="3" rows="10" columns="2">
31226 <features>
31227 <column alignment="block" valignment="top" leftline="true" width="40col%">
31228 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
31229 <row topline="true" bottomline="true" endhead="true">
31230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31231 \begin_inset Text
31232
31233 \begin_layout Standard
31234
31235 \series bold
31236 Subject / Title
31237 \end_layout
31238
31239 \end_inset
31240 </cell>
31241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31242 \begin_inset Text
31243
31244 \begin_layout Standard
31245
31246 \series bold
31247 Filename / Where to get
31248 \end_layout
31249
31250 \end_inset
31251 </cell>
31252 </row>
31253 <row topline="true">
31254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31255 \begin_inset Text
31256
31257 \begin_layout Standard
31258 SDCC Compiler User Guide
31259 \end_layout
31260
31261 \end_inset
31262 </cell>
31263 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31264 \begin_inset Text
31265
31266 \begin_layout Standard
31267 You're reading it right now
31268 \emph on
31269  \InsetSpace ~
31270 \InsetSpace ~
31271 \InsetSpace ~
31272
31273 \hfill
31274 online at:
31275 \emph default
31276
31277 \newline
31278
31279 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
31280
31281 \end_inset
31282
31283
31284 \end_layout
31285
31286 \end_inset
31287 </cell>
31288 </row>
31289 <row topline="true">
31290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31291 \begin_inset Text
31292
31293 \begin_layout Standard
31294 Changelog of SDCC
31295 \end_layout
31296
31297 \end_inset
31298 </cell>
31299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31300 \begin_inset Text
31301
31302 \begin_layout Standard
31303 sdcc/Changelog
31304 \emph on
31305  \InsetSpace ~
31306 \InsetSpace ~
31307 \InsetSpace ~
31308
31309 \hfill
31310 online at:
31311 \emph default
31312
31313 \newline
31314
31315 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31316
31317 \end_inset
31318
31319
31320 \end_layout
31321
31322 \end_inset
31323 </cell>
31324 </row>
31325 <row topline="true">
31326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31327 \begin_inset Text
31328
31329 \begin_layout Standard
31330 ASXXXX
31331 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
31332
31333 \end_inset
31334
31335
31336 \begin_inset LatexCommand \index{Assembler documentation}
31337
31338 \end_inset
31339
31340  Assemblers and
31341 \newline
31342 ASLINK
31343 \begin_inset LatexCommand \index{aslink}
31344
31345 \end_inset
31346
31347
31348 \begin_inset LatexCommand \index{Linker documentation}
31349
31350 \end_inset
31351
31352  Relocating Linker
31353 \end_layout
31354
31355 \end_inset
31356 </cell>
31357 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31358 \begin_inset Text
31359
31360 \begin_layout Standard
31361 sdcc/as/doc/asxhtm.html 
31362 \emph on
31363 \InsetSpace ~
31364 \InsetSpace ~
31365 \InsetSpace ~
31366
31367 \hfill
31368 online at:
31369 \emph default
31370
31371 \newline
31372
31373 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
31374
31375 \end_inset
31376
31377
31378 \end_layout
31379
31380 \end_inset
31381 </cell>
31382 </row>
31383 <row topline="true">
31384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31385 \begin_inset Text
31386
31387 \begin_layout Standard
31388 SDCC regression test
31389 \begin_inset LatexCommand \index{Regression test}
31390
31391 \end_inset
31392
31393
31394 \end_layout
31395
31396 \end_inset
31397 </cell>
31398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31399 \begin_inset Text
31400
31401 \begin_layout Standard
31402 sdcc/doc/test_suite_spec.pdf 
31403 \emph on
31404 \InsetSpace ~
31405 \InsetSpace ~
31406 \InsetSpace ~
31407
31408 \hfill
31409 online at:
31410 \emph default
31411
31412 \newline
31413
31414 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
31415
31416 \end_inset
31417
31418
31419 \end_layout
31420
31421 \end_inset
31422 </cell>
31423 </row>
31424 <row topline="true">
31425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31426 \begin_inset Text
31427
31428 \begin_layout Standard
31429 Various notes
31430 \end_layout
31431
31432 \end_inset
31433 </cell>
31434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31435 \begin_inset Text
31436
31437 \begin_layout Standard
31438 sdcc/doc/* 
31439 \emph on
31440 \InsetSpace ~
31441 \InsetSpace ~
31442 \InsetSpace ~
31443
31444 \hfill
31445 online at:
31446 \emph default
31447
31448 \newline
31449
31450 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
31451
31452 \end_inset
31453
31454
31455 \end_layout
31456
31457 \end_inset
31458 </cell>
31459 </row>
31460 <row topline="true">
31461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31462 \begin_inset Text
31463
31464 \begin_layout Standard
31465 Notes on debugging with SDCDB
31466 \begin_inset LatexCommand \index{SDCDB (debugger)}
31467
31468 \end_inset
31469
31470
31471 \end_layout
31472
31473 \end_inset
31474 </cell>
31475 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31476 \begin_inset Text
31477
31478 \begin_layout Standard
31479 sdcc/debugger/README 
31480 \emph on
31481 \InsetSpace ~
31482 \InsetSpace ~
31483 \InsetSpace ~
31484
31485 \hfill
31486 online at
31487 \emph default
31488 :
31489 \newline
31490
31491 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
31492
31493 \end_inset
31494
31495
31496 \end_layout
31497
31498 \end_inset
31499 </cell>
31500 </row>
31501 <row topline="true">
31502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31503 \begin_inset Text
31504
31505 \begin_layout Standard
31506 uCsim
31507 \begin_inset LatexCommand \index{uCsim}
31508
31509 \end_inset
31510
31511  Software simulator for microcontrollers
31512 \end_layout
31513
31514 \end_inset
31515 </cell>
31516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31517 \begin_inset Text
31518
31519 \begin_layout Standard
31520
31521 \family roman
31522 \series medium
31523 \shape up
31524 \size normal
31525 \emph off
31526 \bar no
31527 \noun off
31528 \color none
31529 sdcc/sim/ucsim/doc
31530 \family default
31531 \series default
31532 \shape default
31533 \size default
31534 \emph default
31535 \bar default
31536 \noun default
31537 /index.html 
31538 \emph on
31539 \InsetSpace ~
31540 \InsetSpace ~
31541 \InsetSpace ~
31542
31543 \hfill
31544 online at:
31545 \emph default
31546
31547 \newline
31548
31549 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
31550
31551 \end_inset
31552
31553
31554 \end_layout
31555
31556 \end_inset
31557 </cell>
31558 </row>
31559 <row topline="true">
31560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31561 \begin_inset Text
31562
31563 \begin_layout Standard
31564 Temporary notes on the pic16
31565 \begin_inset LatexCommand \index{PIC16}
31566
31567 \end_inset
31568
31569  port
31570 \end_layout
31571
31572 \end_inset
31573 </cell>
31574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31575 \begin_inset Text
31576
31577 \begin_layout Standard
31578 sdcc/src/pic16/NOTES 
31579 \emph on
31580 \InsetSpace ~
31581 \InsetSpace ~
31582 \InsetSpace ~
31583
31584 \hfill
31585 online at:
31586 \newline
31587
31588 \emph default
31589
31590 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
31591
31592 \end_inset
31593
31594
31595 \end_layout
31596
31597 \end_inset
31598 </cell>
31599 </row>
31600 <row topline="true" bottomline="true">
31601 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31602 \begin_inset Text
31603
31604 \begin_layout Standard
31605 SDCC internal documentation (debugging file format)
31606 \end_layout
31607
31608 \end_inset
31609 </cell>
31610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31611 \begin_inset Text
31612
31613 \begin_layout Standard
31614 sdcc/doc/
31615 \family roman
31616 \series medium
31617 \shape up
31618 \size normal
31619 \emph off
31620 \bar no
31621 \noun off
31622 \color none
31623 cdbfileformat.pd
31624 \family default
31625 \series default
31626 \shape default
31627 \size default
31628 \emph default
31629 \bar default
31630 \noun default
31631 f
31632 \emph on
31633  \InsetSpace ~
31634 \InsetSpace ~
31635 \InsetSpace ~
31636
31637 \hfill
31638 online at:
31639 \emph default
31640
31641 \newline
31642
31643 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
31644
31645 \end_inset
31646
31647
31648 \end_layout
31649
31650 \end_inset
31651 </cell>
31652 </row>
31653 </lyxtabular>
31654
31655 \end_inset
31656
31657
31658 \newline
31659
31660 \end_layout
31661
31662 \begin_layout Section
31663 Related open source tools
31664 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
31665
31666 \end_inset
31667
31668
31669 \begin_inset LatexCommand \index{Related tools}
31670
31671 \end_inset
31672
31673
31674 \end_layout
31675
31676 \begin_layout Standard
31677 \align left
31678 \begin_inset Tabular
31679 <lyxtabular version="3" rows="16" columns="3">
31680 <features>
31681 <column alignment="left" valignment="top" leftline="true" width="0pt">
31682 <column alignment="block" valignment="top" leftline="true" width="30line%">
31683 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
31684 <row topline="true" bottomline="true">
31685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31686 \begin_inset Text
31687
31688 \begin_layout Standard
31689
31690 \series bold
31691 Name
31692 \end_layout
31693
31694 \end_inset
31695 </cell>
31696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31697 \begin_inset Text
31698
31699 \begin_layout Standard
31700
31701 \series bold
31702 Purpose
31703 \end_layout
31704
31705 \end_inset
31706 </cell>
31707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31708 \begin_inset Text
31709
31710 \begin_layout Standard
31711
31712 \series bold
31713 Where to get
31714 \end_layout
31715
31716 \end_inset
31717 </cell>
31718 </row>
31719 <row topline="true">
31720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31721 \begin_inset Text
31722
31723 \begin_layout Standard
31724 gpsim
31725 \begin_inset LatexCommand \index{gpsim (pic simulator)}
31726
31727 \end_inset
31728
31729
31730 \end_layout
31731
31732 \end_inset
31733 </cell>
31734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31735 \begin_inset Text
31736
31737 \begin_layout Standard
31738 PIC simulator
31739 \end_layout
31740
31741 \end_inset
31742 </cell>
31743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31744 \begin_inset Text
31745
31746 \begin_layout Standard
31747 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
31748
31749 \end_inset
31750
31751
31752 \end_layout
31753
31754 \end_inset
31755 </cell>
31756 </row>
31757 <row topline="true">
31758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31759 \begin_inset Text
31760
31761 \begin_layout Standard
31762 gputils
31763 \begin_inset LatexCommand \index{gputils (pic tools)}
31764
31765 \end_inset
31766
31767
31768 \end_layout
31769
31770 \end_inset
31771 </cell>
31772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31773 \begin_inset Text
31774
31775 \begin_layout Standard
31776 GNU PIC utilities
31777 \end_layout
31778
31779 \end_inset
31780 </cell>
31781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31782 \begin_inset Text
31783
31784 \begin_layout Standard
31785 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
31786
31787 \end_inset
31788
31789
31790 \end_layout
31791
31792 \end_inset
31793 </cell>
31794 </row>
31795 <row topline="true">
31796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31797 \begin_inset Text
31798
31799 \begin_layout Standard
31800 flP5
31801 \end_layout
31802
31803 \end_inset
31804 </cell>
31805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31806 \begin_inset Text
31807
31808 \begin_layout Standard
31809 PIC programmer
31810 \end_layout
31811
31812 \end_inset
31813 </cell>
31814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31815 \begin_inset Text
31816
31817 \begin_layout Standard
31818 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
31819
31820 \end_inset
31821
31822
31823 \end_layout
31824
31825 \end_inset
31826 </cell>
31827 </row>
31828 <row topline="true">
31829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31830 \begin_inset Text
31831
31832 \begin_layout Standard
31833 ec2drv/newcdb
31834 \end_layout
31835
31836 \end_inset
31837 </cell>
31838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31839 \begin_inset Text
31840
31841 \begin_layout Standard
31842 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
31843  (Unix only)
31844 \end_layout
31845
31846 \end_inset
31847 </cell>
31848 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31849 \begin_inset Text
31850
31851 \begin_layout Standard
31852 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
31853
31854 \end_inset
31855
31856
31857 \end_layout
31858
31859 \end_inset
31860 </cell>
31861 </row>
31862 <row topline="true">
31863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31864 \begin_inset Text
31865
31866 \begin_layout Standard
31867 indent
31868 \begin_inset LatexCommand \index{indent (source formatting tool)}
31869
31870 \end_inset
31871
31872
31873 \end_layout
31874
31875 \end_inset
31876 </cell>
31877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31878 \begin_inset Text
31879
31880 \begin_layout Standard
31881 Formats C source - Master of the white spaces
31882 \end_layout
31883
31884 \end_inset
31885 </cell>
31886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31887 \begin_inset Text
31888
31889 \begin_layout Standard
31890 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
31891
31892 \end_inset
31893
31894
31895 \end_layout
31896
31897 \end_inset
31898 </cell>
31899 </row>
31900 <row topline="true">
31901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31902 \begin_inset Text
31903
31904 \begin_layout Standard
31905 srecord
31906 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
31907
31908 \end_inset
31909
31910
31911 \end_layout
31912
31913 \end_inset
31914 </cell>
31915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31916 \begin_inset Text
31917
31918 \begin_layout Standard
31919 Object file conversion, checksumming, ...
31920 \end_layout
31921
31922 \end_inset
31923 </cell>
31924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31925 \begin_inset Text
31926
31927 \begin_layout Standard
31928 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
31929
31930 \end_inset
31931
31932
31933 \end_layout
31934
31935 \end_inset
31936 </cell>
31937 </row>
31938 <row topline="true">
31939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31940 \begin_inset Text
31941
31942 \begin_layout Standard
31943 objdump
31944 \begin_inset LatexCommand \index{objdump (tool)}
31945
31946 \end_inset
31947
31948
31949 \end_layout
31950
31951 \end_inset
31952 </cell>
31953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31954 \begin_inset Text
31955
31956 \begin_layout Standard
31957 Object file conversion, ...
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 Part of binutils (should be there anyway)
31967 \end_layout
31968
31969 \end_inset
31970 </cell>
31971 </row>
31972 <row topline="true">
31973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31974 \begin_inset Text
31975
31976 \begin_layout Standard
31977 cmon51
31978 \end_layout
31979
31980 \end_inset
31981 </cell>
31982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31983 \begin_inset Text
31984
31985 \begin_layout Standard
31986 8051 monitor (hex up-/download, single step, disassemble)
31987 \end_layout
31988
31989 \end_inset
31990 </cell>
31991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31992 \begin_inset Text
31993
31994 \begin_layout Standard
31995 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
31996
31997 \end_inset
31998
31999
32000 \end_layout
32001
32002 \end_inset
32003 </cell>
32004 </row>
32005 <row topline="true">
32006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32007 \begin_inset Text
32008
32009 \begin_layout Standard
32010 doxygen
32011 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
32012
32013 \end_inset
32014
32015
32016 \end_layout
32017
32018 \end_inset
32019 </cell>
32020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32021 \begin_inset Text
32022
32023 \begin_layout Standard
32024 Source code documentation system
32025 \end_layout
32026
32027 \end_inset
32028 </cell>
32029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32030 \begin_inset Text
32031
32032 \begin_layout Standard
32033 \begin_inset LatexCommand \url{http://www.doxygen.org}
32034
32035 \end_inset
32036
32037
32038 \end_layout
32039
32040 \end_inset
32041 </cell>
32042 </row>
32043 <row topline="true">
32044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32045 \begin_inset Text
32046
32047 \begin_layout Standard
32048 kdevelop
32049 \end_layout
32050
32051 \end_inset
32052 </cell>
32053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32054 \begin_inset Text
32055
32056 \begin_layout Standard
32057 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
32058 \end_layout
32059
32060 \end_inset
32061 </cell>
32062 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32063 \begin_inset Text
32064
32065 \begin_layout Standard
32066 \begin_inset LatexCommand \url{http://www.kdevelop.org}
32067
32068 \end_inset
32069
32070
32071 \end_layout
32072
32073 \end_inset
32074 </cell>
32075 </row>
32076 <row topline="true">
32077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32078 \begin_inset Text
32079
32080 \begin_layout Standard
32081 paulmon
32082 \end_layout
32083
32084 \end_inset
32085 </cell>
32086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32087 \begin_inset Text
32088
32089 \begin_layout Standard
32090 8051 monitor (hex up-/download, single step, disassemble)
32091 \end_layout
32092
32093 \end_inset
32094 </cell>
32095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32096 \begin_inset Text
32097
32098 \begin_layout Standard
32099 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
32100
32101 \end_inset
32102
32103
32104 \end_layout
32105
32106 \end_inset
32107 </cell>
32108 </row>
32109 <row topline="true">
32110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32111 \begin_inset Text
32112
32113 \begin_layout Standard
32114 splint
32115 \begin_inset LatexCommand \index{splint (syntax checking tool)}
32116
32117 \end_inset
32118
32119
32120 \end_layout
32121
32122 \end_inset
32123 </cell>
32124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32125 \begin_inset Text
32126
32127 \begin_layout Standard
32128 Statically checks c sources (see 
32129 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
32130
32131 \end_inset
32132
32133 )
32134 \end_layout
32135
32136 \end_inset
32137 </cell>
32138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32139 \begin_inset Text
32140
32141 \begin_layout Standard
32142 \begin_inset LatexCommand \url{http://www.splint.org}
32143
32144 \end_inset
32145
32146
32147 \end_layout
32148
32149 \end_inset
32150 </cell>
32151 </row>
32152 <row topline="true" bottomline="true">
32153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32154 \begin_inset Text
32155
32156 \begin_layout Standard
32157 ddd
32158 \begin_inset LatexCommand \index{DDD (debugger)}
32159
32160 \end_inset
32161
32162
32163 \end_layout
32164
32165 \end_inset
32166 </cell>
32167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32168 \begin_inset Text
32169
32170 \begin_layout Standard
32171 Debugger, serves nicely as GUI to SDCDB
32172 \begin_inset LatexCommand \index{SDCDB (debugger)}
32173
32174 \end_inset
32175
32176  (Unix only)
32177 \end_layout
32178
32179 \end_inset
32180 </cell>
32181 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32182 \begin_inset Text
32183
32184 \begin_layout Standard
32185 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
32186
32187 \end_inset
32188
32189
32190 \end_layout
32191
32192 \end_inset
32193 </cell>
32194 </row>
32195 <row bottomline="true">
32196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32197 \begin_inset Text
32198
32199 \begin_layout Standard
32200 d52
32201 \begin_inset LatexCommand \index{d52}
32202
32203 \end_inset
32204
32205
32206 \begin_inset LatexCommand \index{d52 (disassembler)}
32207
32208 \end_inset
32209
32210
32211 \end_layout
32212
32213 \end_inset
32214 </cell>
32215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32216 \begin_inset Text
32217
32218 \begin_layout Standard
32219 Disassembler, can count instruction cycles
32220 \begin_inset LatexCommand \index{instruction cycles (count)}
32221
32222 \end_inset
32223
32224 , use with options -pnd
32225 \end_layout
32226
32227 \end_inset
32228 </cell>
32229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32230 \begin_inset Text
32231
32232 \begin_layout Standard
32233 \begin_inset LatexCommand \url{http://www.8052.com/users/disasm/}
32234
32235 \end_inset
32236
32237
32238 \end_layout
32239
32240 \end_inset
32241 </cell>
32242 </row>
32243 <row bottomline="true">
32244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32245 \begin_inset Text
32246
32247 \begin_layout Standard
32248 cmake
32249 \begin_inset LatexCommand \index{cmake}
32250
32251 \end_inset
32252
32253
32254 \end_layout
32255
32256 \end_inset
32257 </cell>
32258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32259 \begin_inset Text
32260
32261 \begin_layout Standard
32262 Cross platform build system, generates Makefiles
32263 \begin_inset LatexCommand \index{Makefile}
32264
32265 \end_inset
32266
32267  and project workspaces
32268 \begin_inset LatexCommand \index{project workspace}
32269
32270 \end_inset
32271
32272
32273 \end_layout
32274
32275 \end_inset
32276 </cell>
32277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32278 \begin_inset Text
32279
32280 \begin_layout Standard
32281 \begin_inset LatexCommand \url{http://www.cmake.org}
32282
32283 \end_inset
32284
32285  \InsetSpace ~
32286 \InsetSpace ~
32287 \InsetSpace ~
32288 \InsetSpace ~
32289 and a dedicated wiki entry: 
32290 \begin_inset LatexCommand \url{http://www.cmake.org/Wiki/CmakeSdcc}
32291
32292 \end_inset
32293
32294
32295 \end_layout
32296
32297 \end_inset
32298 </cell>
32299 </row>
32300 </lyxtabular>
32301
32302 \end_inset
32303
32304
32305 \newline
32306
32307 \end_layout
32308
32309 \begin_layout Section
32310 Related documentation / recommended reading
32311 \end_layout
32312
32313 \begin_layout Standard
32314 \align left
32315 \begin_inset Tabular
32316 <lyxtabular version="3" rows="7" columns="3">
32317 <features>
32318 <column alignment="left" valignment="top" leftline="true" width="0pt">
32319 <column alignment="left" valignment="top" leftline="true" width="0">
32320 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32321 <row topline="true" bottomline="true">
32322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32323 \begin_inset Text
32324
32325 \begin_layout Standard
32326
32327 \series bold
32328 Name
32329 \end_layout
32330
32331 \end_inset
32332 </cell>
32333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32334 \begin_inset Text
32335
32336 \begin_layout Standard
32337
32338 \series bold
32339 Subject / Title
32340 \end_layout
32341
32342 \end_inset
32343 </cell>
32344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32345 \begin_inset Text
32346
32347 \begin_layout Standard
32348
32349 \series bold
32350 Where to get
32351 \end_layout
32352
32353 \end_inset
32354 </cell>
32355 </row>
32356 <row topline="true">
32357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32358 \begin_inset Text
32359
32360 \begin_layout Standard
32361
32362 \family roman
32363 \series medium
32364 \shape up
32365 \size normal
32366 \emph off
32367 \bar no
32368 \noun off
32369 \color none
32370 c-refcard.pdf
32371 \end_layout
32372
32373 \end_inset
32374 </cell>
32375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32376 \begin_inset Text
32377
32378 \begin_layout Standard
32379 C Reference Card
32380 \begin_inset LatexCommand \index{C Reference card}
32381
32382 \end_inset
32383
32384 , 2 pages
32385 \end_layout
32386
32387 \end_inset
32388 </cell>
32389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32390 \begin_inset Text
32391
32392 \begin_layout Standard
32393 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
32394
32395 \end_inset
32396
32397
32398 \end_layout
32399
32400 \end_inset
32401 </cell>
32402 </row>
32403 <row topline="true">
32404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32405 \begin_inset Text
32406
32407 \begin_layout Standard
32408 c-faq
32409 \end_layout
32410
32411 \end_inset
32412 </cell>
32413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32414 \begin_inset Text
32415
32416 \begin_layout Standard
32417 C-FAQ
32418 \begin_inset LatexCommand \index{C FAQ}
32419
32420 \end_inset
32421
32422
32423 \end_layout
32424
32425 \end_inset
32426 </cell>
32427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32428 \begin_inset Text
32429
32430 \begin_layout Standard
32431 \begin_inset LatexCommand \url{http://www.c-faq.com}
32432
32433 \end_inset
32434
32435
32436 \end_layout
32437
32438 \end_inset
32439 </cell>
32440 </row>
32441 <row topline="true">
32442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32443 \begin_inset Text
32444
32445 \begin_layout Standard
32446 ISO/IEC 9899:TC2
32447 \end_layout
32448
32449 \end_inset
32450 </cell>
32451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32452 \begin_inset Text
32453
32454 \begin_layout Standard
32455 \begin_inset Quotes sld
32456 \end_inset
32457
32458 C-Standard
32459 \begin_inset Quotes srd
32460 \end_inset
32461
32462
32463 \end_layout
32464
32465 \end_inset
32466 </cell>
32467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32468 \begin_inset Text
32469
32470 \begin_layout Standard
32471
32472 \size footnotesize
32473 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
32474
32475 \end_inset
32476
32477
32478 \end_layout
32479
32480 \end_inset
32481 </cell>
32482 </row>
32483 <row topline="true">
32484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32485 \begin_inset Text
32486
32487 \begin_layout Standard
32488 ISO/IEC DTR 18037
32489 \end_layout
32490
32491 \end_inset
32492 </cell>
32493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32494 \begin_inset Text
32495
32496 \begin_layout Standard
32497 \begin_inset Quotes sld
32498 \end_inset
32499
32500 Extensions for Embedded C
32501 \begin_inset Quotes srd
32502 \end_inset
32503
32504
32505 \end_layout
32506
32507 \end_inset
32508 </cell>
32509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32510 \begin_inset Text
32511
32512 \begin_layout Standard
32513
32514 \size footnotesize
32515 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
32516
32517 \end_inset
32518
32519
32520 \end_layout
32521
32522 \end_inset
32523 </cell>
32524 </row>
32525 <row topline="true">
32526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32527 \begin_inset Text
32528
32529 \begin_layout Standard
32530
32531 \end_layout
32532
32533 \end_inset
32534 </cell>
32535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32536 \begin_inset Text
32537
32538 \begin_layout Standard
32539 Latest datasheet of target CPU
32540 \end_layout
32541
32542 \end_inset
32543 </cell>
32544 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32545 \begin_inset Text
32546
32547 \begin_layout Standard
32548 vendor
32549 \end_layout
32550
32551 \end_inset
32552 </cell>
32553 </row>
32554 <row topline="true" bottomline="true">
32555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32556 \begin_inset Text
32557
32558 \begin_layout Standard
32559
32560 \end_layout
32561
32562 \end_inset
32563 </cell>
32564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32565 \begin_inset Text
32566
32567 \begin_layout Standard
32568 Revision history of datasheet
32569 \end_layout
32570
32571 \end_inset
32572 </cell>
32573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32574 \begin_inset Text
32575
32576 \begin_layout Standard
32577 vendor
32578 \end_layout
32579
32580 \end_inset
32581 </cell>
32582 </row>
32583 </lyxtabular>
32584
32585 \end_inset
32586
32587
32588 \newline
32589
32590 \end_layout
32591
32592 \begin_layout Section
32593 Application notes specifically for SDCC
32594 \end_layout
32595
32596 \begin_layout Standard
32597 SDCC makes no claims about the completeness of this list and about up-to-datenes
32598 s or correctness of the application notes
32599 \begin_inset LatexCommand \index{Application notes}
32600
32601 \end_inset
32602
32603 .
32604 \end_layout
32605
32606 \begin_layout Standard
32607 \align left
32608
32609 \size footnotesize
32610 \begin_inset Tabular
32611 <lyxtabular version="3" rows="7" columns="3">
32612 <features>
32613 <column alignment="block" valignment="top" leftline="true" width="17col%">
32614 <column alignment="block" valignment="top" leftline="true" width="27col%">
32615 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
32616 <row topline="true" bottomline="true">
32617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32618 \begin_inset Text
32619
32620 \begin_layout Standard
32621
32622 \series bold
32623 \size footnotesize
32624 Vendor
32625 \end_layout
32626
32627 \end_inset
32628 </cell>
32629 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
32630 \begin_inset Text
32631
32632 \begin_layout Standard
32633
32634 \series bold
32635 \size footnotesize
32636 Subject / Title
32637 \end_layout
32638
32639 \end_inset
32640 </cell>
32641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32642 \begin_inset Text
32643
32644 \begin_layout Standard
32645
32646 \series bold
32647 \size footnotesize
32648 Where to get
32649 \end_layout
32650
32651 \end_inset
32652 </cell>
32653 </row>
32654 <row topline="true">
32655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32656 \begin_inset Text
32657
32658 \begin_layout Standard
32659
32660 \size footnotesize
32661 Maxim / Dallas
32662 \end_layout
32663
32664 \end_inset
32665 </cell>
32666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32667 \begin_inset Text
32668
32669 \begin_layout Standard
32670
32671 \size footnotesize
32672 Using the SDCC Compiler for the DS80C400
32673 \begin_inset LatexCommand \index{DS80C400}
32674
32675 \end_inset
32676
32677
32678 \end_layout
32679
32680 \end_inset
32681 </cell>
32682 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32683 \begin_inset Text
32684
32685 \begin_layout Standard
32686
32687 \size footnotesize
32688 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
32689
32690 \end_inset
32691
32692
32693 \end_layout
32694
32695 \end_inset
32696 </cell>
32697 </row>
32698 <row topline="true">
32699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32700 \begin_inset Text
32701
32702 \begin_layout Standard
32703
32704 \size footnotesize
32705 Maxim / Dallas
32706 \end_layout
32707
32708 \end_inset
32709 </cell>
32710 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
32711 \begin_inset Text
32712
32713 \begin_layout Standard
32714
32715 \size footnotesize
32716 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
32717 \begin_inset LatexCommand \index{DS89C4x0}
32718
32719 \end_inset
32720
32721  Family of Microcontrollers
32722 \end_layout
32723
32724 \end_inset
32725 </cell>
32726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32727 \begin_inset Text
32728
32729 \begin_layout Standard
32730
32731 \size footnotesize
32732 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
32733
32734 \end_inset
32735
32736
32737 \end_layout
32738
32739 \end_inset
32740 </cell>
32741 </row>
32742 <row topline="true">
32743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32744 \begin_inset Text
32745
32746 \begin_layout Standard
32747
32748 \size footnotesize
32749 Silicon Laboratories / Cygnal
32750 \end_layout
32751
32752 \end_inset
32753 </cell>
32754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32755 \begin_inset Text
32756
32757 \begin_layout Standard
32758
32759 \size footnotesize
32760 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
32761 \begin_inset LatexCommand \index{IDE}
32762
32763 \end_inset
32764
32765
32766 \end_layout
32767
32768 \end_inset
32769 </cell>
32770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32771 \begin_inset Text
32772
32773 \begin_layout Standard
32774
32775 \size footnotesize
32776 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
32777
32778 \end_inset
32779
32780
32781 \end_layout
32782
32783 \end_inset
32784 </cell>
32785 </row>
32786 <row topline="true">
32787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32788 \begin_inset Text
32789
32790 \begin_layout Standard
32791
32792 \size footnotesize
32793 Ramtron / Goal Semiconductor
32794 \end_layout
32795
32796 \end_inset
32797 </cell>
32798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32799 \begin_inset Text
32800
32801 \begin_layout Standard
32802
32803 \size footnotesize
32804 Interfacing SDCC to Syn and Textpad
32805 \end_layout
32806
32807 \end_inset
32808 </cell>
32809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32810 \begin_inset Text
32811
32812 \begin_layout Standard
32813
32814 \size footnotesize
32815 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32816
32817 \end_inset
32818
32819
32820 \end_layout
32821
32822 \end_inset
32823 </cell>
32824 </row>
32825 <row topline="true">
32826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32827 \begin_inset Text
32828
32829 \begin_layout Standard
32830
32831 \size footnotesize
32832 Ramtron / Goal Semiconductor
32833 \end_layout
32834
32835 \end_inset
32836 </cell>
32837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32838 \begin_inset Text
32839
32840 \begin_layout Standard
32841
32842 \size footnotesize
32843 Installing and Configuring SDCC and Crimson Editor 
32844 \end_layout
32845
32846 \end_inset
32847 </cell>
32848 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32849 \begin_inset Text
32850
32851 \begin_layout Standard
32852
32853 \size footnotesize
32854 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
32855
32856 \end_inset
32857
32858
32859 \end_layout
32860
32861 \end_inset
32862 </cell>
32863 </row>
32864 <row topline="true" bottomline="true">
32865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32866 \begin_inset Text
32867
32868 \begin_layout Standard
32869
32870 \size footnotesize
32871 Texas Instruments
32872 \end_layout
32873
32874 \end_inset
32875 </cell>
32876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32877 \begin_inset Text
32878
32879 \begin_layout Standard
32880
32881 \size footnotesize
32882 MSC12xx Programming with SDCC
32883 \end_layout
32884
32885 \end_inset
32886 </cell>
32887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32888 \begin_inset Text
32889
32890 \begin_layout Standard
32891
32892 \size footnotesize
32893 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
32894
32895 \end_inset
32896
32897
32898 \end_layout
32899
32900 \end_inset
32901 </cell>
32902 </row>
32903 </lyxtabular>
32904
32905 \end_inset
32906
32907
32908 \end_layout
32909
32910 \begin_layout Section
32911 Some Questions
32912 \end_layout
32913
32914 \begin_layout Standard
32915 Some questions answered, some pointers given - it might be time to in turn
32916  ask 
32917 \emph on
32918 you
32919 \emph default
32920  some questions: 
32921 \end_layout
32922
32923 \begin_layout Itemize
32924 can you solve your project with the selected microcontroller? Would you
32925  find out early or rather late that your target is too small/slow/whatever?
32926  Can you switch to a slightly better device if it doesn't fit?
32927 \end_layout
32928
32929 \begin_layout Itemize
32930 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
32931  and/or another programming language be more adequate? Would an operating
32932  system on the target device help?
32933 \end_layout
32934
32935 \begin_layout Itemize
32936 if you solved the problem, will the marketing department be happy?
32937 \end_layout
32938
32939 \begin_layout Itemize
32940 if the marketing department is happy, will customers be happy?
32941 \end_layout
32942
32943 \begin_layout Itemize
32944 if you're the project manager, marketing department and maybe even the customer
32945  in one person, have you tried to see the project from the outside?
32946 \end_layout
32947
32948 \begin_layout Itemize
32949 is the project done if you think it is done? Or is just that other interface/pro
32950 tocol/feature/configuration/option missing? How about website, manual(s),
32951  internationali(z|s)ation, packaging, labels, 2nd source for components,
32952  electromagnetic compatability/interference, documentation for production,
32953  production test software, update mechanism, patent issues?
32954 \end_layout
32955
32956 \begin_layout Itemize
32957 is your project adequately positioned in that magic triangle: fame, fortune,
32958  fun?
32959 \end_layout
32960
32961 \begin_layout Standard
32962 Maybe not all answers to these questions are known and some answers may
32963  even be 
32964 \emph on
32965 no
32966 \emph default
32967 , nevertheless knowing these questions may help you to avoid burnout
32968 \begin_inset Foot
32969 status open
32970
32971 \begin_layout Standard
32972 burnout is bad for electronic devices, programmers and motorcycle tyres
32973 \end_layout
32974
32975 \end_inset
32976
32977 .
32978  Chances are you didn't want to hear some of them...
32979 \end_layout
32980
32981 \begin_layout Chapter
32982 Support
32983 \begin_inset LatexCommand \index{Support}
32984
32985 \end_inset
32986
32987
32988 \end_layout
32989
32990 \begin_layout Standard
32991 SDCC has grown to be a large project.
32992  The compiler alone (without the preprocessor, assembler and linker) is
32993  well over 150,000 lines of code (blank stripped).
32994  The open source nature of this project is a key to its continued growth
32995  and support.
32996  You gain the benefit and support of many active software developers and
32997  end users.
32998  Is SDCC perfect? No, that's why we need your help.
32999  The developers take pride in fixing reported bugs.
33000  You can help by reporting the bugs and helping other SDCC users.
33001  There are lots of ways to contribute, and we encourage you to take part
33002  in making SDCC a great software package.
33003  
33004 \end_layout
33005
33006 \begin_layout Standard
33007 The SDCC project is hosted on the SDCC sourceforge site at 
33008 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
33009
33010 \end_inset
33011
33012 .
33013  You'll find the complete set of mailing lists
33014 \begin_inset LatexCommand \index{Mailing list(s)}
33015
33016 \end_inset
33017
33018 , forums, bug reporting system, patch submission
33019 \begin_inset LatexCommand \index{Patch submission}
33020
33021 \end_inset
33022
33023  system, download
33024 \begin_inset LatexCommand \index{download}
33025
33026 \end_inset
33027
33028  area and Subversion code repository
33029 \begin_inset LatexCommand \index{Subversion code repository}
33030
33031 \end_inset
33032
33033  there.
33034 \end_layout
33035
33036 \begin_layout Section
33037 Reporting Bugs
33038 \begin_inset LatexCommand \index{Bug reporting}
33039
33040 \end_inset
33041
33042
33043 \begin_inset LatexCommand \index{Reporting bugs}
33044
33045 \end_inset
33046
33047
33048 \end_layout
33049
33050 \begin_layout Standard
33051 The recommended way of reporting bugs is using the infrastructure of the
33052  sourceforge site.
33053  You can follow the status of bug reports there and have an overview about
33054  the known bugs.
33055 \end_layout
33056
33057 \begin_layout Standard
33058 Bug reports are automatically forwarded to the developer mailing list and
33059  will be fixed ASAP.
33060  When reporting a bug, it is very useful to include a small test program
33061  (the smaller the better) which reproduces the problem.
33062  If you can isolate the problem by looking at the generated assembly code,
33063  this can be very helpful.
33064  Compiling your program with the -
33065 \begin_inset ERT
33066 status collapsed
33067
33068 \begin_layout Standard
33069
33070
33071 \backslash
33072 /
33073 \end_layout
33074
33075 \end_inset
33076
33077 -dumpall
33078 \begin_inset LatexCommand \index{-\/-dumpall}
33079
33080 \end_inset
33081
33082  option can sometimes be useful in locating optimization problems.
33083  When reporting a bug please make sure you:
33084 \end_layout
33085
33086 \begin_layout Enumerate
33087 Attach the code you are compiling with SDCC.
33088  
33089 \end_layout
33090
33091 \begin_layout Enumerate
33092 Specify the exact command you use to run SDCC, or attach your Makefile.
33093  
33094 \end_layout
33095
33096 \begin_layout Enumerate
33097 Specify the SDCC version (type "
33098 \family sans
33099 \series bold
33100 sdcc -v
33101 \family default
33102 \series default
33103 "), your platform, and operating system.
33104  
33105 \end_layout
33106
33107 \begin_layout Enumerate
33108 Provide an exact copy of any error message or incorrect output.
33109  
33110 \end_layout
33111
33112 \begin_layout Enumerate
33113 Put something meaningful in the subject of your message.
33114 \end_layout
33115
33116 \begin_layout Standard
33117 Please attempt to include these 5 important parts, as applicable, in all
33118  requests for support or when reporting any problems or bugs with SDCC.
33119  Though this will make your message lengthy, it will greatly improve your
33120  chance that SDCC users and developers will be able to help you.
33121  Some SDCC developers are frustrated by bug reports without code provided
33122  that they can use to reproduce and ultimately fix the problem, so please
33123  be sure to provide sample code if you are reporting a bug! 
33124 \end_layout
33125
33126 \begin_layout Standard
33127 Please have a short check that you are using a recent version of SDCC and
33128  the bug is not yet known.
33129  This is the link for reporting bugs: 
33130 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
33131
33132 \end_inset
33133
33134 .
33135  With SDCC on average having more than 200 downloads
33136 \begin_inset LatexCommand \index{download}
33137
33138 \end_inset
33139
33140  on sourceforge per day
33141 \begin_inset Foot
33142 status open
33143
33144 \begin_layout Standard
33145 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
33146  between 2002 and 2005.
33147  This does not include other methods of distribution.
33148 \end_layout
33149
33150 \end_inset
33151
33152  there must be some users.
33153  So it's not exactly easy to find a new bug.
33154  If you find one we need it: 
33155 \emph on
33156 reporting bugs is good
33157 \emph default
33158 .
33159 \end_layout
33160
33161 \begin_layout Section
33162 Requesting Features
33163 \begin_inset LatexCommand \label{sub:Requesting-Features}
33164
33165 \end_inset
33166
33167
33168 \begin_inset LatexCommand \index{Feature request}
33169
33170 \end_inset
33171
33172
33173 \begin_inset LatexCommand \index{Requesting features}
33174
33175 \end_inset
33176
33177
33178 \end_layout
33179
33180 \begin_layout Standard
33181 Like bug reports feature requests are forwarded to the developer mailing
33182  list.
33183  This is the link for requesting features: 
33184 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33185
33186 \end_inset
33187
33188 .
33189 \end_layout
33190
33191 \begin_layout Section
33192 Submitting patches
33193 \end_layout
33194
33195 \begin_layout Standard
33196 Like bug reports contributed patches are forwarded to the developer mailing
33197  list.
33198  This is the link for submitting patches
33199 \begin_inset LatexCommand \index{Patch submission}
33200
33201 \end_inset
33202
33203
33204 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
33205
33206 \end_inset
33207
33208 .
33209 \end_layout
33210
33211 \begin_layout Standard
33212 You need to specify some parameters to the 
33213 \family typewriter
33214 diff
33215 \family default
33216  command for the patches to be useful.
33217  If you modified more than one file a patch created f.e.
33218  with 
33219 \family sans
33220 \series bold
33221
33222 \begin_inset Quotes sld
33223 \end_inset
33224
33225 diff -Naur unmodified_directory modified_directory >my_changes.patch
33226 \begin_inset Quotes srd
33227 \end_inset
33228
33229
33230 \family default
33231 \series default
33232  will be fine, otherwise 
33233 \family sans
33234 \series bold
33235
33236 \begin_inset Quotes sld
33237 \end_inset
33238
33239 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
33240 \begin_inset Quotes srd
33241 \end_inset
33242
33243
33244 \series default
33245  
33246 \family default
33247 will do.
33248 \end_layout
33249
33250 \begin_layout Section
33251 Getting Help
33252 \end_layout
33253
33254 \begin_layout Standard
33255 These links should take you directly to the 
33256 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
33257
33258 \end_inset
33259
33260
33261 \begin_inset Foot
33262 status open
33263
33264 \begin_layout Standard
33265 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
33266  automated messages (mid 2003)
33267 \end_layout
33268
33269 \end_inset
33270
33271  and the 
33272 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
33273
33274 \end_inset
33275
33276 , lists
33277 \begin_inset LatexCommand \index{Mailing list(s)}
33278
33279 \end_inset
33280
33281  and forums are archived and searchable so if you are lucky someone already
33282  had a similar problem.
33283  While mails to the lists themselves are delivered promptly their web front
33284  end on sourceforge sometimes shows a severe time lag (up to several weeks),
33285  if you're seriously using SDCC please consider subscribing to the lists.
33286 \end_layout
33287
33288 \begin_layout Section
33289 ChangeLog
33290 \end_layout
33291
33292 \begin_layout Standard
33293 You can follow the status of the Subversion version
33294 \begin_inset LatexCommand \index{version}
33295
33296 \end_inset
33297
33298  of SDCC by watching the Changelog
33299 \begin_inset LatexCommand \index{Changelog}
33300
33301 \end_inset
33302
33303  in the Subversion repository
33304 \size footnotesize
33305  
33306 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
33307
33308 \end_inset
33309
33310 .
33311 \end_layout
33312
33313 \begin_layout Section
33314 Subversion Source Code Repository
33315 \end_layout
33316
33317 \begin_layout Standard
33318 The output of 
33319 \family sans
33320 \series bold
33321 sdcc -
33322 \family default
33323
33324 \begin_inset ERT
33325 status open
33326
33327 \begin_layout Standard
33328
33329
33330 \backslash
33331 /
33332 \end_layout
33333
33334 \end_inset
33335
33336
33337 \family sans
33338 -version
33339 \family default
33340 \series default
33341  or the filenames of the snapshot versions of SDCC include date and its
33342  Subversion
33343 \begin_inset LatexCommand \index{Subversion code repository}
33344
33345 \end_inset
33346
33347  number.
33348  Subversion allows to download the source of recent or previous versions
33349  
33350 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
33351
33352 \end_inset
33353
33354  (by number or by date).
33355  An on-line source code browser and detailled instructions are also available
33356  there.
33357  SDCC versions starting from 1999 up to now are available (currently the
33358  versions prior to the conversion from cvs
33359 \begin_inset LatexCommand \index{cvs|see{Subversion}}
33360
33361 \end_inset
33362
33363  to Subversion (April 2006) are either by accessible by Subversion or by
33364  cvs).
33365 \end_layout
33366
33367 \begin_layout Section
33368 Release policy
33369 \begin_inset LatexCommand \index{Release policy}
33370
33371 \end_inset
33372
33373
33374 \end_layout
33375
33376 \begin_layout Standard
33377 Historically there often were long delays between official releases and
33378  the sourceforge download area tends to get not updated at all.
33379  Excuses in the past might have referred to problems with live range analysis,
33380  but as this was fixed a while ago, the current problem is that another
33381  excuse has to be found.
33382  Kidding aside, we have to get better there! On the other hand there are
33383  daily snapshots available at 
33384 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
33385
33386 \end_inset
33387
33388 , and you can always build the very last version (hopefully with many bugs
33389  fixed, and features added) from the source code available at 
33390 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
33391
33392 \end_inset
33393
33394 .
33395  The SDCC Wiki
33396 \begin_inset LatexCommand \index{wiki}
33397
33398 \end_inset
33399
33400
33401 \begin_inset LatexCommand \index{SDCC Wiki}
33402
33403 \end_inset
33404
33405  at 
33406 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/}
33407
33408 \end_inset
33409
33410  also holds some information about past and future releases.
33411 \end_layout
33412
33413 \begin_layout Section
33414 Examples
33415 \begin_inset LatexCommand \index{Examples}
33416
33417 \end_inset
33418
33419
33420 \end_layout
33421
33422 \begin_layout Standard
33423 You'll find some small examples in the directory 
33424 \emph on
33425 sdcc/device/examples/.
33426  
33427 \emph default
33428 More examples and libraries are available at
33429 \emph on
33430  The SDCC Open Knowledge Resource 
33431 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
33432
33433 \end_inset
33434
33435  
33436 \emph default
33437 web site or at 
33438 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
33439
33440 \end_inset
33441
33442 .
33443 \end_layout
33444
33445 \begin_layout Standard
33446 \begin_inset Note Note
33447 status collapsed
33448
33449 \begin_layout Standard
33450 I did insert a reference to Paul's web site here although it seems rather
33451  dedicated to a specific 8032 board (I think it's okay because it f.e.
33452  shows LCD/Harddisc interface and has a free 8051 monitor.
33453  Independent 8032 board vendors face hard competition of heavily subsidized
33454  development boards anyway).
33455 \end_layout
33456
33457 \begin_layout Standard
33458 Maybe we should include some links to real world applications.
33459  Preferably pointer to pointers (one for each architecture) so this stays
33460  manageable here?
33461 \end_layout
33462
33463 \end_inset
33464
33465
33466 \end_layout
33467
33468 \begin_layout Section
33469 Quality control
33470 \begin_inset LatexCommand \label{sec:Quality-control}
33471
33472 \end_inset
33473
33474
33475 \begin_inset LatexCommand \index{Quality control}
33476
33477 \end_inset
33478
33479
33480 \end_layout
33481
33482 \begin_layout Standard
33483 The compiler is passed through snaphot build compile and build checks.
33484  The so called 
33485 \shape italic
33486 regression tests
33487 \shape default
33488
33489 \begin_inset LatexCommand \index{Regression test}
33490
33491 \end_inset
33492
33493  check that SDCC itself compiles flawlessly on several host platforms (i386,
33494  Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
33495  and checks the quality of the code generated by SDCC by running the code
33496  for several target platforms through simulators.
33497  The regression test suite comprises more than 100 files which expand to
33498  more than 500 test cases which include more than 4500 tests.
33499  The results of these tests are published daily on SDCC's snapshot page
33500  (click on the red or green symbols on the right side of 
33501 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
33502
33503 \end_inset
33504
33505 ).
33506 \end_layout
33507
33508 \begin_layout Standard
33509 There is a separate document 
33510 \shape italic
33511 test_suite.pdf 
33512 \begin_inset LatexCommand \index{Test suite}
33513
33514 \end_inset
33515
33516
33517 \shape default
33518  
33519 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
33520
33521 \end_inset
33522
33523  about the regression test suite.
33524 \end_layout
33525
33526 \begin_layout Standard
33527 You'll find the test code in the directory 
33528 \shape italic
33529 sdcc/support/regression
33530 \shape default
33531 .
33532  You can run these tests manually by running 
33533 \family sans
33534 make
33535 \family default
33536  in this directory (or f.e.
33537  
33538 \family sans
33539 \series bold
33540
33541 \begin_inset Quotes sld
33542 \end_inset
33543
33544 make test-mcs51
33545 \begin_inset Quotes srd
33546 \end_inset
33547
33548
33549 \family default
33550 \series default
33551  if you don't want to run the complete tests).
33552  The test code might also be interesting if you want to look for examples
33553 \begin_inset LatexCommand \index{Examples}
33554
33555 \end_inset
33556
33557  checking corner cases of SDCC or if you plan to submit patches
33558 \begin_inset LatexCommand \index{Patch submission}
33559
33560 \end_inset
33561
33562 .
33563 \end_layout
33564
33565 \begin_layout Standard
33566 The PIC14 port uses a different set of regression tests 
33567 \begin_inset LatexCommand \index{Regression test (PIC14)}
33568
33569 \end_inset
33570
33571 , you'll find them in the directory 
33572 \shape italic
33573 sdcc/src/regression
33574 \shape default
33575 .
33576 \end_layout
33577
33578 \begin_layout Section
33579 Use of SDCC in Education
33580 \end_layout
33581
33582 \begin_layout Standard
33583 In short: 
33584 \emph on
33585 highly
33586 \emph default
33587  encouraged
33588 \begin_inset Foot
33589 status open
33590
33591 \begin_layout Standard
33592 the phrase "use in education" might evoke the association "
33593 \emph on
33594 only
33595 \emph default
33596  fit for use in education".
33597  This connotation is not intended but nevertheless risked as the licensing
33598  of SDCC makes it difficult to offer educational discounts
33599 \end_layout
33600
33601 \end_inset
33602
33603 .
33604  If your rationales are to:
33605 \end_layout
33606
33607 \begin_layout Enumerate
33608 give students a chance to understand the 
33609 \emph on
33610 complete
33611 \emph default
33612  steps of code generation
33613 \end_layout
33614
33615 \begin_layout Enumerate
33616 have a curriculum that can be extended for years.
33617  Then you could use an fpga board as target and your curriculum will seamlessly
33618  extend from logic synthesis (
33619 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
33620
33621 \end_inset
33622
33623
33624 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
33625
33626 \end_inset
33627
33628 ), over assembly programming, to C to FPGA compilers (
33629 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
33630
33631 \end_inset
33632
33633 ) and to C.
33634 \end_layout
33635
33636 \begin_layout Enumerate
33637 be able to insert excursions about skills like using a revision control
33638  system, submitting/applying patches, using a type-setting (as opposed to
33639  word-processing) engine LyX/LaTeX, using 
33640 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
33641
33642 \end_inset
33643
33644 , following some 
33645 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
33646
33647 \end_inset
33648
33649 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
33650  Source Software, CPU simulation, compiler regression tests
33651 \begin_inset LatexCommand \index{Regression test}
33652
33653 \end_inset
33654
33655 .
33656  
33657 \newline
33658 And if there should be a shortage of ideas then you can always point students
33659  to the ever-growing feature request list 
33660 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
33661
33662 \end_inset
33663
33664 .
33665 \end_layout
33666
33667 \begin_layout Enumerate
33668 not tie students to a specific host platform and instead allow them to use
33669  a host platform of 
33670 \emph on
33671 their
33672 \emph default
33673  choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
33674  and eventually 
33675 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
33676
33677 \end_inset
33678
33679 )
33680 \end_layout
33681
33682 \begin_layout Enumerate
33683 not encourage students to use illegal copies of educational software
33684 \end_layout
33685
33686 \begin_layout Enumerate
33687 be immune to licensing/availability/price changes of the chosen tool chain
33688 \end_layout
33689
33690 \begin_layout Enumerate
33691 be able to change to a new target platform without having to adopt a new
33692  tool chain
33693 \end_layout
33694
33695 \begin_layout Enumerate
33696 have complete control over and insight into the tool chain
33697 \end_layout
33698
33699 \begin_layout Enumerate
33700 make your students aware about the pros and cons of open source software
33701  development
33702 \end_layout
33703
33704 \begin_layout Enumerate
33705 give back to the public as you are probably at least partially publically
33706  funded
33707 \end_layout
33708
33709 \begin_layout Enumerate
33710 give students a chance to publically prove their skills and to possibly
33711  see a world wide impact
33712 \end_layout
33713
33714 \begin_layout Standard
33715 then SDCC is probably among the first choices.
33716  Well, probably SDCC might be the only choice.
33717 \newpage
33718
33719 \end_layout
33720
33721 \begin_layout Chapter
33722 SDCC Technical Data
33723 \end_layout
33724
33725 \begin_layout Section
33726 Optimizations
33727 \begin_inset LatexCommand \index{Optimizations}
33728
33729 \end_inset
33730
33731
33732 \end_layout
33733
33734 \begin_layout Standard
33735 SDCC performs a host of standard optimizations in addition to some MCU specific
33736  optimizations.
33737  
33738 \end_layout
33739
33740 \begin_layout Subsection
33741 Sub-expression Elimination
33742 \begin_inset LatexCommand \index{Subexpression elimination}
33743
33744 \end_inset
33745
33746
33747 \end_layout
33748
33749 \begin_layout Standard
33750 The compiler does local and 
33751 \emph on
33752 g
33753 \emph default
33754 lobal 
33755 \emph on
33756 c
33757 \emph default
33758 ommon 
33759 \emph on
33760 s
33761 \emph default
33762 ubexpression 
33763 \emph on
33764 e
33765 \emph default
33766 limination, e.g.: 
33767 \end_layout
33768
33769 \begin_layout Verse
33770
33771 \family typewriter
33772 i = x + y + 1; 
33773 \newline
33774 j = x + y;
33775 \end_layout
33776
33777 \begin_layout Standard
33778 will be translated to
33779 \end_layout
33780
33781 \begin_layout Verse
33782
33783 \family typewriter
33784 iTemp = x + y; 
33785 \newline
33786 i = iTemp + 1; 
33787 \newline
33788 j = iTemp;
33789 \end_layout
33790
33791 \begin_layout Standard
33792 Some subexpressions are not as obvious as the above example, e.g.:
33793 \end_layout
33794
33795 \begin_layout Verse
33796
33797 \family typewriter
33798 a->b[i].c = 10; 
33799 \newline
33800 a->b[i].d = 11;
33801 \end_layout
33802
33803 \begin_layout Standard
33804 In this case the address arithmetic a->b[i] will be computed only once;
33805  the equivalent code in C would be.
33806 \end_layout
33807
33808 \begin_layout Verse
33809
33810 \family typewriter
33811 iTemp = a->b[i]; 
33812 \newline
33813 iTemp.c = 10; 
33814 \newline
33815 iTemp.d = 11;
33816 \end_layout
33817
33818 \begin_layout Standard
33819 The compiler will try to keep these temporary variables in registers.
33820 \end_layout
33821
33822 \begin_layout Subsection
33823 Dead-Code Elimination
33824 \begin_inset LatexCommand \index{Dead-code elimination}
33825
33826 \end_inset
33827
33828
33829 \end_layout
33830
33831 \begin_layout Verse
33832
33833 \family typewriter
33834 int global;
33835 \newline
33836
33837 \newline
33838 void f () { 
33839 \newline
33840 \InsetSpace ~
33841 \InsetSpace ~
33842 int i; 
33843 \newline
33844 \InsetSpace ~
33845 \InsetSpace ~
33846 i = 1; \InsetSpace ~
33847 \InsetSpace ~
33848 \InsetSpace ~
33849 \InsetSpace ~
33850 \InsetSpace ~
33851 /* dead store */ 
33852 \newline
33853 \InsetSpace ~
33854 \InsetSpace ~
33855 global = 1;\InsetSpace ~
33856 /* dead
33857  store */ 
33858 \newline
33859 \InsetSpace ~
33860 \InsetSpace ~
33861 global = 2; 
33862 \newline
33863 \InsetSpace ~
33864 \InsetSpace ~
33865 return; 
33866 \newline
33867 \InsetSpace ~
33868 \InsetSpace ~
33869 global = 3;\InsetSpace ~
33870 /* unreachable */ 
33871 \newline
33872 }
33873 \end_layout
33874
33875 \begin_layout Standard
33876 will be changed to
33877 \end_layout
33878
33879 \begin_layout Verse
33880
33881 \family typewriter
33882 int global;
33883 \newline
33884
33885 \newline
33886 void f () {
33887 \newline
33888 \InsetSpace ~
33889 \InsetSpace ~
33890 global = 2; 
33891 \newline
33892 }
33893 \end_layout
33894
33895 \begin_layout Subsection
33896 Copy-Propagation
33897 \begin_inset LatexCommand \index{Copy propagation}
33898
33899 \end_inset
33900
33901
33902 \end_layout
33903
33904 \begin_layout Verse
33905
33906 \family typewriter
33907 int f() { 
33908 \newline
33909 \InsetSpace ~
33910 \InsetSpace ~
33911 int i, j; 
33912 \newline
33913 \InsetSpace ~
33914 \InsetSpace ~
33915 i = 10; 
33916 \newline
33917 \InsetSpace ~
33918 \InsetSpace ~
33919 j = i; 
33920 \newline
33921 \InsetSpace ~
33922 \InsetSpace ~
33923 return j; 
33924 \newline
33925 }
33926 \end_layout
33927
33928 \begin_layout Standard
33929 will be changed to 
33930 \end_layout
33931
33932 \begin_layout Verse
33933
33934 \family typewriter
33935 int f() { 
33936 \newline
33937 \InsetSpace ~
33938 \InsetSpace ~
33939 int i, j; 
33940 \newline
33941 \InsetSpace ~
33942 \InsetSpace ~
33943 i = 10; 
33944 \newline
33945 \InsetSpace ~
33946 \InsetSpace ~
33947 j = 10; 
33948 \newline
33949 \InsetSpace ~
33950 \InsetSpace ~
33951 return 10; 
33952 \newline
33953 }
33954 \end_layout
33955
33956 \begin_layout Standard
33957 Note: the dead stores created by this copy propagation will be eliminated
33958  by dead-code elimination.
33959 \end_layout
33960
33961 \begin_layout Subsection
33962 Loop Optimizations
33963 \begin_inset LatexCommand \index{Loop optimization}
33964
33965 \end_inset
33966
33967
33968 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
33969
33970 \end_inset
33971
33972
33973 \end_layout
33974
33975 \begin_layout Standard
33976 Two types of loop optimizations are done by SDCC 
33977 \emph on
33978 loop invariant
33979 \emph default
33980  lifting and
33981 \emph on
33982  strength reduction
33983 \emph default
33984  of loop induction variables.
33985  In addition to the strength reduction the optimizer marks the induction
33986  variables and the register allocator tries to keep the induction variables
33987  in registers for the duration of the loop.
33988  Because of this preference of the register allocator
33989 \begin_inset LatexCommand \index{Register allocation}
33990
33991 \end_inset
33992
33993 , loop induction optimization causes an increase in register pressure, which
33994  may cause unwanted spilling of other temporary variables into the stack
33995 \begin_inset LatexCommand \index{stack}
33996
33997 \end_inset
33998
33999  / data space.
34000  The compiler will generate a warning message when it is forced to allocate
34001  extra space either on the stack or data space.
34002  If this extra space allocation is undesirable then induction optimization
34003  can be eliminated either for the entire source file (with -
34004 \begin_inset ERT
34005 status collapsed
34006
34007 \begin_layout Standard
34008
34009
34010 \backslash
34011 /
34012 \end_layout
34013
34014 \end_inset
34015
34016 -noinduction option) or for a given function only using #pragma\InsetSpace ~
34017 noinduction
34018 \begin_inset LatexCommand \index{\#pragma noinduction}
34019
34020 \end_inset
34021
34022 .
34023 \newline
34024
34025 \newline
34026 Loop Invariant:
34027 \end_layout
34028
34029 \begin_layout Verse
34030
34031 \family typewriter
34032 for (i = 0 ; i < 100 ; i ++) 
34033 \newline
34034 \InsetSpace ~
34035 \InsetSpace ~
34036 \InsetSpace ~
34037 \InsetSpace ~
34038 f += k + l;
34039 \end_layout
34040
34041 \begin_layout Standard
34042 changed to
34043 \end_layout
34044
34045 \begin_layout Verse
34046
34047 \family typewriter
34048 itemp = k + l; 
34049 \newline
34050 for (i = 0; i < 100; i++) 
34051 \newline
34052 \InsetSpace ~
34053 \InsetSpace ~
34054 \InsetSpace ~
34055 \InsetSpace ~
34056 f += itemp;
34057 \end_layout
34058
34059 \begin_layout Standard
34060 As mentioned previously some loop invariants are not as apparent, all static
34061  address computations are also moved out of the loop.
34062 \newline
34063
34064 \newline
34065 Strength Reduction
34066 \begin_inset LatexCommand \index{Strength reduction}
34067
34068 \end_inset
34069
34070 , this optimization substitutes an expression by a cheaper expression:
34071 \end_layout
34072
34073 \begin_layout Verse
34074
34075 \family typewriter
34076 for (i=0;i < 100; i++)
34077 \newline
34078 \InsetSpace ~
34079 \InsetSpace ~
34080 \InsetSpace ~
34081 \InsetSpace ~
34082 ar[i*5] = i*3;
34083 \end_layout
34084
34085 \begin_layout Standard
34086 changed to
34087 \end_layout
34088
34089 \begin_layout Verse
34090
34091 \family typewriter
34092 itemp1 = 0; 
34093 \newline
34094 itemp2 = 0; 
34095 \newline
34096 for (i=0;i< 100;i++) { 
34097 \newline
34098 \InsetSpace ~
34099 \InsetSpace ~
34100 \InsetSpace ~
34101 \InsetSpace ~
34102 ar[itemp1] = itemp2; 
34103 \newline
34104 \InsetSpace ~
34105 \InsetSpace ~
34106 \InsetSpace ~
34107 \InsetSpace ~
34108 itemp1
34109  += 5; 
34110 \newline
34111 \InsetSpace ~
34112 \InsetSpace ~
34113 \InsetSpace ~
34114 \InsetSpace ~
34115 itemp2 += 3; 
34116 \newline
34117 }
34118 \end_layout
34119
34120 \begin_layout Standard
34121 The more expensive multiplication
34122 \begin_inset LatexCommand \index{Multiplication}
34123
34124 \end_inset
34125
34126  is changed to a less expensive addition.
34127 \end_layout
34128
34129 \begin_layout Subsection
34130 Loop Reversing
34131 \begin_inset LatexCommand \index{Loop reversing}
34132
34133 \end_inset
34134
34135
34136 \end_layout
34137
34138 \begin_layout Standard
34139 This optimization is done to reduce the overhead of checking loop boundaries
34140  for every iteration.
34141  Some simple loops can be reversed and implemented using a 
34142 \begin_inset Quotes eld
34143 \end_inset
34144
34145 decrement and jump if not zero
34146 \begin_inset Quotes erd
34147 \end_inset
34148
34149  instruction.
34150  SDCC checks for the following criterion to determine if a loop is reversible
34151  (note: more sophisticated compilers use data-dependency analysis to make
34152  this determination, SDCC uses a more simple minded analysis).
34153 \end_layout
34154
34155 \begin_layout Itemize
34156 The 'for' loop is of the form 
34157 \newline
34158
34159 \newline
34160
34161 \family typewriter
34162 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
34163  += 1])
34164 \newline
34165 \InsetSpace ~
34166 \InsetSpace ~
34167 \InsetSpace ~
34168 \InsetSpace ~
34169 <for body>
34170 \end_layout
34171
34172 \begin_layout Itemize
34173 The <for body> does not contain 
34174 \begin_inset Quotes eld
34175 \end_inset
34176
34177 continue
34178 \begin_inset Quotes erd
34179 \end_inset
34180
34181  or 'break
34182 \begin_inset Quotes erd
34183 \end_inset
34184
34185 .
34186 \end_layout
34187
34188 \begin_layout Itemize
34189 All goto's are contained within the loop.
34190 \end_layout
34191
34192 \begin_layout Itemize
34193 No function calls within the loop.
34194 \end_layout
34195
34196 \begin_layout Itemize
34197 The loop control variable <sym> is not assigned any value within the loop
34198 \end_layout
34199
34200 \begin_layout Itemize
34201 The loop control variable does NOT participate in any arithmetic operation
34202  within the loop.
34203 \end_layout
34204
34205 \begin_layout Itemize
34206 There are NO switch statements in the loop.
34207 \end_layout
34208
34209 \begin_layout Subsection
34210 Algebraic Simplifications
34211 \end_layout
34212
34213 \begin_layout Standard
34214 SDCC does numerous algebraic simplifications, the following is a small sub-set
34215  of these optimizations.
34216 \end_layout
34217
34218 \begin_layout Verse
34219
34220 \family typewriter
34221 i = j + 0;\InsetSpace ~
34222 \InsetSpace ~
34223 \InsetSpace ~
34224 \InsetSpace ~
34225  /* changed to: */\InsetSpace ~
34226 \InsetSpace ~
34227 \InsetSpace ~
34228 \InsetSpace ~
34229  i = j; 
34230 \newline
34231 i /= 2;\InsetSpace ~
34232 \InsetSpace ~
34233 \InsetSpace ~
34234 \InsetSpace ~
34235 \InsetSpace ~
34236 \InsetSpace ~
34237 \InsetSpace ~
34238  /* changed to: */\InsetSpace ~
34239 \InsetSpace ~
34240 \InsetSpace ~
34241 \InsetSpace ~
34242  i >>= 1; 
34243 \newline
34244 i
34245  = j - j;\InsetSpace ~
34246 \InsetSpace ~
34247 \InsetSpace ~
34248 \InsetSpace ~
34249  /* changed to: */\InsetSpace ~
34250 \InsetSpace ~
34251 \InsetSpace ~
34252 \InsetSpace ~
34253  i = 0; 
34254 \newline
34255 i = j / 1;\InsetSpace ~
34256 \InsetSpace ~
34257 \InsetSpace ~
34258 \InsetSpace ~
34259  /* changed to: */\InsetSpace ~
34260 \InsetSpace ~
34261 \InsetSpace ~
34262 \InsetSpace ~
34263  i = j;
34264 \end_layout
34265
34266 \begin_layout Standard
34267 Note the subexpressions
34268 \begin_inset LatexCommand \index{Subexpression}
34269
34270 \end_inset
34271
34272  given above are generally introduced by macro expansions or as a result
34273  of copy/constant propagation.
34274 \end_layout
34275
34276 \begin_layout Subsection
34277 'switch' Statements
34278 \begin_inset LatexCommand \label{sub:'switch'-Statements}
34279
34280 \end_inset
34281
34282
34283 \begin_inset LatexCommand \index{switch statement}
34284
34285 \end_inset
34286
34287
34288 \end_layout
34289
34290 \begin_layout Standard
34291 SDCC can optimize switch statements to jump tables
34292 \begin_inset LatexCommand \index{jump tables}
34293
34294 \end_inset
34295
34296 .
34297  It makes the decision based on an estimate of the generated code size.
34298  SDCC is quite liberal in the requirements for jump table generation: 
34299 \end_layout
34300
34301 \begin_layout Itemize
34302 The labels need not be in order, and the starting number need not be one
34303  or zero, the case labels are in numerical sequence or not too many case
34304  labels are missing.
34305 \end_layout
34306
34307 \begin_deeper
34308 \begin_layout Verse
34309
34310 \family typewriter
34311 switch(i) {\InsetSpace ~
34312 \InsetSpace ~
34313 \InsetSpace ~
34314 \InsetSpace ~
34315 \InsetSpace ~
34316 \InsetSpace ~
34317 \InsetSpace ~
34318 \InsetSpace ~
34319 \InsetSpace ~
34320 \InsetSpace ~
34321 \InsetSpace ~
34322 \InsetSpace ~
34323 \InsetSpace ~
34324 \InsetSpace ~
34325 \InsetSpace ~
34326 \InsetSpace ~
34327 \InsetSpace ~
34328 \InsetSpace ~
34329 \InsetSpace ~
34330 \InsetSpace ~
34331 \InsetSpace ~
34332 \InsetSpace ~
34333 \InsetSpace ~
34334 \InsetSpace ~
34335 \InsetSpace ~
34336 \InsetSpace ~
34337 switch (i) { 
34338 \newline
34339 \InsetSpace ~
34340 \InsetSpace ~
34341 \InsetSpace ~
34342 case 4: ...\InsetSpace ~
34343 \InsetSpace ~
34344 \InsetSpace ~
34345 \InsetSpace ~
34346 \InsetSpace ~
34347 \InsetSpace ~
34348 \InsetSpace ~
34349 \InsetSpace ~
34350 \InsetSpace ~
34351 \InsetSpace ~
34352 \InsetSpace ~
34353 \InsetSpace ~
34354 \InsetSpace ~
34355 \InsetSpace ~
34356 \InsetSpace ~
34357 \InsetSpace ~
34358 \InsetSpace ~
34359 \InsetSpace ~
34360 \InsetSpace ~
34361 \InsetSpace ~
34362 \InsetSpace ~
34363 \InsetSpace ~
34364 \InsetSpace ~
34365 \InsetSpace ~
34366 \InsetSpace ~
34367 \InsetSpace ~
34368 case 0: ...
34369  
34370 \newline
34371 \InsetSpace ~
34372 \InsetSpace ~
34373 \InsetSpace ~
34374 case 5: ...\InsetSpace ~
34375 \InsetSpace ~
34376 \InsetSpace ~
34377 \InsetSpace ~
34378 \InsetSpace ~
34379 \InsetSpace ~
34380 \InsetSpace ~
34381 \InsetSpace ~
34382 \InsetSpace ~
34383 \InsetSpace ~
34384 \InsetSpace ~
34385 \InsetSpace ~
34386 \InsetSpace ~
34387 \InsetSpace ~
34388 \InsetSpace ~
34389 \InsetSpace ~
34390 \InsetSpace ~
34391 \InsetSpace ~
34392 \InsetSpace ~
34393 \InsetSpace ~
34394 \InsetSpace ~
34395 \InsetSpace ~
34396 \InsetSpace ~
34397 \InsetSpace ~
34398 \InsetSpace ~
34399 \InsetSpace ~
34400 case 1: ...
34401  
34402 \newline
34403 \InsetSpace ~
34404 \InsetSpace ~
34405 \InsetSpace ~
34406 case 3: ...\InsetSpace ~
34407 \InsetSpace ~
34408 \InsetSpace ~
34409 \InsetSpace ~
34410 \InsetSpace ~
34411 \InsetSpace ~
34412 \InsetSpace ~
34413 \InsetSpace ~
34414 \InsetSpace ~
34415 \InsetSpace ~
34416 \InsetSpace ~
34417 \InsetSpace ~
34418 \InsetSpace ~
34419 \InsetSpace ~
34420 \InsetSpace ~
34421 \InsetSpace ~
34422 \InsetSpace ~
34423 \InsetSpace ~
34424 \InsetSpace ~
34425 \InsetSpace ~
34426 \InsetSpace ~
34427 \InsetSpace ~
34428 \InsetSpace ~
34429 \InsetSpace ~
34430 \InsetSpace ~
34431 \InsetSpace ~
34432
34433 \newline
34434 \InsetSpace ~
34435 \InsetSpace ~
34436 \InsetSpace ~
34437 case 6: ...\InsetSpace ~
34438 \InsetSpace ~
34439 \InsetSpace ~
34440 \InsetSpace ~
34441 \InsetSpace ~
34442 \InsetSpace ~
34443 \InsetSpace ~
34444 \InsetSpace ~
34445 \InsetSpace ~
34446 \InsetSpace ~
34447 \InsetSpace ~
34448 \InsetSpace ~
34449 \InsetSpace ~
34450 \InsetSpace ~
34451 \InsetSpace ~
34452 \InsetSpace ~
34453 \InsetSpace ~
34454 \InsetSpace ~
34455 \InsetSpace ~
34456 \InsetSpace ~
34457 \InsetSpace ~
34458 \InsetSpace ~
34459 \InsetSpace ~
34460 \InsetSpace ~
34461 \InsetSpace ~
34462 \InsetSpace ~
34463 case 3: ...
34464  
34465 \newline
34466 \InsetSpace ~
34467 \InsetSpace ~
34468 \InsetSpace ~
34469 case 7: ...\InsetSpace ~
34470 \InsetSpace ~
34471 \InsetSpace ~
34472 \InsetSpace ~
34473 \InsetSpace ~
34474 \InsetSpace ~
34475 \InsetSpace ~
34476 \InsetSpace ~
34477 \InsetSpace ~
34478 \InsetSpace ~
34479 \InsetSpace ~
34480 \InsetSpace ~
34481 \InsetSpace ~
34482 \InsetSpace ~
34483 \InsetSpace ~
34484 \InsetSpace ~
34485 \InsetSpace ~
34486 \InsetSpace ~
34487 \InsetSpace ~
34488 \InsetSpace ~
34489 \InsetSpace ~
34490 \InsetSpace ~
34491 \InsetSpace ~
34492 \InsetSpace ~
34493 \InsetSpace ~
34494 \InsetSpace ~
34495 case 4: ...
34496  
34497 \newline
34498 \InsetSpace ~
34499 \InsetSpace ~
34500 \InsetSpace ~
34501 case 8: ...\InsetSpace ~
34502 \InsetSpace ~
34503 \InsetSpace ~
34504 \InsetSpace ~
34505 \InsetSpace ~
34506 \InsetSpace ~
34507 \InsetSpace ~
34508 \InsetSpace ~
34509 \InsetSpace ~
34510 \InsetSpace ~
34511 \InsetSpace ~
34512 \InsetSpace ~
34513 \InsetSpace ~
34514 \InsetSpace ~
34515 \InsetSpace ~
34516 \InsetSpace ~
34517 \InsetSpace ~
34518 \InsetSpace ~
34519 \InsetSpace ~
34520 \InsetSpace ~
34521 \InsetSpace ~
34522 \InsetSpace ~
34523 \InsetSpace ~
34524 \InsetSpace ~
34525 \InsetSpace ~
34526 \InsetSpace ~
34527 case 5: ...
34528  
34529 \newline
34530 \InsetSpace ~
34531 \InsetSpace ~
34532 \InsetSpace ~
34533 case 9: ...\InsetSpace ~
34534 \InsetSpace ~
34535 \InsetSpace ~
34536 \InsetSpace ~
34537 \InsetSpace ~
34538 \InsetSpace ~
34539 \InsetSpace ~
34540 \InsetSpace ~
34541 \InsetSpace ~
34542 \InsetSpace ~
34543 \InsetSpace ~
34544 \InsetSpace ~
34545 \InsetSpace ~
34546 \InsetSpace ~
34547 \InsetSpace ~
34548 \InsetSpace ~
34549 \InsetSpace ~
34550 \InsetSpace ~
34551 \InsetSpace ~
34552 \InsetSpace ~
34553 \InsetSpace ~
34554 \InsetSpace ~
34555 \InsetSpace ~
34556 \InsetSpace ~
34557 \InsetSpace ~
34558 \InsetSpace ~
34559 case 6: ...
34560  
34561 \newline
34562 \InsetSpace ~
34563 \InsetSpace ~
34564 \InsetSpace ~
34565 case 10: ...\InsetSpace ~
34566 \InsetSpace ~
34567 \InsetSpace ~
34568 \InsetSpace ~
34569 \InsetSpace ~
34570 \InsetSpace ~
34571 \InsetSpace ~
34572 \InsetSpace ~
34573 \InsetSpace ~
34574 \InsetSpace ~
34575 \InsetSpace ~
34576 \InsetSpace ~
34577 \InsetSpace ~
34578 \InsetSpace ~
34579 \InsetSpace ~
34580 \InsetSpace ~
34581 \InsetSpace ~
34582 \InsetSpace ~
34583 \InsetSpace ~
34584 \InsetSpace ~
34585 \InsetSpace ~
34586 \InsetSpace ~
34587 \InsetSpace ~
34588 \InsetSpace ~
34589 \InsetSpace ~
34590 case 7: ...
34591  
34592 \newline
34593 \InsetSpace ~
34594 \InsetSpace ~
34595 \InsetSpace ~
34596 case 11: ...\InsetSpace ~
34597 \InsetSpace ~
34598 \InsetSpace ~
34599 \InsetSpace ~
34600 \InsetSpace ~
34601 \InsetSpace ~
34602 \InsetSpace ~
34603 \InsetSpace ~
34604 \InsetSpace ~
34605 \InsetSpace ~
34606 \InsetSpace ~
34607 \InsetSpace ~
34608 \InsetSpace ~
34609 \InsetSpace ~
34610 \InsetSpace ~
34611 \InsetSpace ~
34612 \InsetSpace ~
34613 \InsetSpace ~
34614 \InsetSpace ~
34615 \InsetSpace ~
34616 \InsetSpace ~
34617 \InsetSpace ~
34618 \InsetSpace ~
34619 \InsetSpace ~
34620 \InsetSpace ~
34621 case 8: ...
34622  
34623 \newline
34624 }\InsetSpace ~
34625 \InsetSpace ~
34626 \InsetSpace ~
34627 \InsetSpace ~
34628 \InsetSpace ~
34629 \InsetSpace ~
34630 \InsetSpace ~
34631 \InsetSpace ~
34632 \InsetSpace ~
34633 \InsetSpace ~
34634 \InsetSpace ~
34635 \InsetSpace ~
34636 \InsetSpace ~
34637 \InsetSpace ~
34638 \InsetSpace ~
34639 \InsetSpace ~
34640 \InsetSpace ~
34641 \InsetSpace ~
34642 \InsetSpace ~
34643 \InsetSpace ~
34644 \InsetSpace ~
34645 \InsetSpace ~
34646 \InsetSpace ~
34647 \InsetSpace ~
34648 \InsetSpace ~
34649 \InsetSpace ~
34650 \InsetSpace ~
34651 \InsetSpace ~
34652 \InsetSpace ~
34653 \InsetSpace ~
34654 \InsetSpace ~
34655 \InsetSpace ~
34656 \InsetSpace ~
34657 \InsetSpace ~
34658 \InsetSpace ~
34659 \InsetSpace ~
34660 }
34661 \end_layout
34662
34663 \begin_layout Standard
34664 Both the above switch statements will be implemented using a jump-table.
34665  The example to the right side is slightly more efficient as the check for
34666  the lower boundary of the jump-table is not needed.
34667 \end_layout
34668
34669 \end_deeper
34670 \begin_layout Itemize
34671 The number of case labels is not larger than supported by the target architectur
34672 e.
34673 \end_layout
34674
34675 \begin_layout Itemize
34676 If the case labels are not in numerical sequence ('gaps' between cases)
34677  SDCC checks whether a jump table with additionally inserted dummy cases
34678  is still attractive.
34679  
34680 \end_layout
34681
34682 \begin_layout Itemize
34683 If the starting number is not zero and a check for the lower boundary of
34684  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
34685  ...
34686  .
34687 \end_layout
34688
34689 \begin_layout Standard
34690 Switch statements which have large gaps in the numeric sequence or those
34691  that have too many case labels can be split into more than one switch statement
34692  for efficient code generation, e.g.:
34693 \end_layout
34694
34695 \begin_layout Verse
34696
34697 \family typewriter
34698 switch (i) { 
34699 \newline
34700 \InsetSpace ~
34701 \InsetSpace ~
34702 case 1: ...
34703  
34704 \newline
34705 \InsetSpace ~
34706 \InsetSpace ~
34707 case 2: ...
34708  
34709 \newline
34710 \InsetSpace ~
34711 \InsetSpace ~
34712 case 3: ...
34713  
34714 \newline
34715 \InsetSpace ~
34716 \InsetSpace ~
34717 case 4: ...
34718  
34719 \newline
34720 \InsetSpace ~
34721 \InsetSpace ~
34722 case 5: ...
34723  
34724 \newline
34725 \InsetSpace ~
34726 \InsetSpace ~
34727 case 6: ...
34728  
34729 \newline
34730 \InsetSpace ~
34731 \InsetSpace ~
34732 case 7: ...
34733  
34734 \newline
34735 \InsetSpace ~
34736 \InsetSpace ~
34737 case 101: ...
34738  
34739 \newline
34740 \InsetSpace ~
34741 \InsetSpace ~
34742 case 102: ...
34743  
34744 \newline
34745 \InsetSpace ~
34746 \InsetSpace ~
34747 case 103: ...
34748  
34749 \newline
34750 \InsetSpace ~
34751 \InsetSpace ~
34752 case 104: ...
34753  
34754 \newline
34755 \InsetSpace ~
34756 \InsetSpace ~
34757 case 105: ...
34758  
34759 \newline
34760 \InsetSpace ~
34761 \InsetSpace ~
34762 case 106: ...
34763  
34764 \newline
34765 \InsetSpace ~
34766 \InsetSpace ~
34767 case 107: ...
34768  
34769 \newline
34770 }
34771 \end_layout
34772
34773 \begin_layout Standard
34774 If the above switch statement is broken down into two switch statements
34775 \end_layout
34776
34777 \begin_layout Verse
34778
34779 \family typewriter
34780 switch (i) { 
34781 \newline
34782 \InsetSpace ~
34783 \InsetSpace ~
34784 case 1: ...
34785  
34786 \newline
34787 \InsetSpace ~
34788 \InsetSpace ~
34789 case 2: ...
34790  
34791 \newline
34792 \InsetSpace ~
34793 \InsetSpace ~
34794 case 3: ...
34795  
34796 \newline
34797 \InsetSpace ~
34798 \InsetSpace ~
34799 case 4: ...
34800  
34801 \newline
34802 \InsetSpace ~
34803 \InsetSpace ~
34804 case 5: ...
34805  
34806 \newline
34807 \InsetSpace ~
34808 \InsetSpace ~
34809 case 6: ...
34810  
34811 \newline
34812 \InsetSpace ~
34813 \InsetSpace ~
34814 case 7: ...
34815  
34816 \newline
34817 }
34818 \end_layout
34819
34820 \begin_layout Standard
34821 and
34822 \end_layout
34823
34824 \begin_layout Verse
34825
34826 \family typewriter
34827 switch (i) { 
34828 \newline
34829 \InsetSpace ~
34830 \InsetSpace ~
34831 case 101: ...
34832  
34833 \newline
34834 \InsetSpace ~
34835 \InsetSpace ~
34836 case 102: ...
34837  
34838 \newline
34839 \InsetSpace ~
34840 \InsetSpace ~
34841 case 103: ...
34842  
34843 \newline
34844 \InsetSpace ~
34845 \InsetSpace ~
34846 case 104: ...
34847  
34848 \newline
34849 \InsetSpace ~
34850 \InsetSpace ~
34851 case 105: ...
34852  
34853 \newline
34854 \InsetSpace ~
34855 \InsetSpace ~
34856 case 106: ...
34857  
34858 \newline
34859 \InsetSpace ~
34860 \InsetSpace ~
34861 case 107: ...
34862  
34863 \newline
34864 }
34865 \end_layout
34866
34867 \begin_layout Standard
34868 then both the switch statements will be implemented using jump-tables whereas
34869  the unmodified switch statement will not be.
34870 \end_layout
34871
34872 \begin_layout Standard
34873 \begin_inset Note Note
34874 status collapsed
34875
34876 \begin_layout Standard
34877 There might be reasons which SDCC cannot know about to either favour or
34878  not favour jump tables.
34879  If the target system has to be as quick for the last switch case as for
34880  the first (pro jump table), or if the switch argument is known to be zero
34881  in the majority of the cases (contra jump table).
34882 \end_layout
34883
34884 \end_inset
34885
34886
34887 \end_layout
34888
34889 \begin_layout Standard
34890 The pragma nojtbound
34891 \begin_inset LatexCommand \index{\#pragma nojtbound}
34892
34893 \end_inset
34894
34895  can be used to turn off checking the 
34896 \emph on
34897 j
34898 \emph default
34899 ump 
34900 \emph on
34901 t
34902 \emph default
34903 able 
34904 \emph on
34905 bound
34906 \emph default
34907 aries.
34908  It has no effect if a default label is supplied.
34909  Use of this pragma is dangerous: if the switch
34910 \begin_inset LatexCommand \index{switch statement}
34911
34912 \end_inset
34913
34914  argument is not matched by a case statement the processor will happily
34915  jump into Nirvana.
34916 \end_layout
34917
34918 \begin_layout Subsection
34919 Bit-shifting Operations
34920 \begin_inset LatexCommand \index{Bit shifting}
34921
34922 \end_inset
34923
34924 .
34925 \end_layout
34926
34927 \begin_layout Standard
34928 Bit shifting is one of the most frequently used operation in embedded programmin
34929 g.
34930  SDCC tries to implement bit-shift operations in the most efficient way
34931  possible, e.g.:
34932 \end_layout
34933
34934 \begin_layout Verse
34935
34936 \family typewriter
34937 unsigned char i;
34938 \newline
34939 ...
34940  
34941 \newline
34942 i >>= 4; 
34943 \newline
34944 ...
34945 \end_layout
34946
34947 \begin_layout Standard
34948 generates the following code:
34949 \end_layout
34950
34951 \begin_layout Verse
34952
34953 \family typewriter
34954 mov\InsetSpace ~
34955  a,_i 
34956 \newline
34957 swap a 
34958 \newline
34959 anl\InsetSpace ~
34960  a,#0x0f 
34961 \newline
34962 mov\InsetSpace ~
34963  _i,a
34964 \end_layout
34965
34966 \begin_layout Standard
34967 In general SDCC will never setup a loop if the shift count is known.
34968  Another example:
34969 \end_layout
34970
34971 \begin_layout Verse
34972
34973 \family typewriter
34974 unsigned int i; 
34975 \newline
34976 ...
34977  
34978 \newline
34979 i >>= 9; 
34980 \newline
34981 ...
34982 \end_layout
34983
34984 \begin_layout Standard
34985 will generate:
34986 \end_layout
34987
34988 \begin_layout Verse
34989
34990 \family typewriter
34991 mov\InsetSpace ~
34992 \InsetSpace ~
34993 a,(_i + 1) 
34994 \newline
34995 mov\InsetSpace ~
34996 \InsetSpace ~
34997 (_i + 1),#0x00 
34998 \newline
34999 clr\InsetSpace ~
35000 \InsetSpace ~
35001
35002 \newline
35003 rrc\InsetSpace ~
35004 \InsetSpace ~
35005
35006 \newline
35007 mov\InsetSpace ~
35008 \InsetSpace ~
35009 _i,a
35010 \end_layout
35011
35012 \begin_layout Subsection
35013 Bit-rotation
35014 \begin_inset LatexCommand \index{Bit rotation}
35015
35016 \end_inset
35017
35018
35019 \end_layout
35020
35021 \begin_layout Standard
35022 A special case of the bit-shift operation is bit rotation
35023 \begin_inset LatexCommand \index{rotating bits}
35024
35025 \end_inset
35026
35027 , SDCC recognizes the following expression to be a left bit-rotation:
35028 \end_layout
35029
35030 \begin_layout Verse
35031
35032 \family typewriter
35033 \series bold
35034 unsigned
35035 \series default
35036 \InsetSpace ~
35037 \InsetSpace ~
35038 char i;\InsetSpace ~
35039 \InsetSpace ~
35040 \InsetSpace ~
35041 \InsetSpace ~
35042 \InsetSpace ~
35043 \InsetSpace ~
35044 \InsetSpace ~
35045 \InsetSpace ~
35046 \InsetSpace ~
35047 \InsetSpace ~
35048 \InsetSpace ~
35049 /* unsigned is needed for rotation */ 
35050 \newline
35051 ...
35052  
35053 \newline
35054 i = ((i << 1) | (i >> 7)); 
35055 \family default
35056
35057 \newline
35058
35059 \family typewriter
35060 ...
35061 \end_layout
35062
35063 \begin_layout Standard
35064 will generate the following code:
35065 \end_layout
35066
35067 \begin_layout Verse
35068
35069 \family typewriter
35070 mov\InsetSpace ~
35071 \InsetSpace ~
35072 a,_i 
35073 \newline
35074 rl\InsetSpace ~
35075 \InsetSpace ~
35076 \InsetSpace ~
35077
35078 \newline
35079 mov\InsetSpace ~
35080 \InsetSpace ~
35081 _i,a
35082 \end_layout
35083
35084 \begin_layout Standard
35085 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
35086 ns of this case will also be recognized as bit-rotation, i.e.: 
35087 \end_layout
35088
35089 \begin_layout Verse
35090
35091 \family typewriter
35092 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
35093 \end_layout
35094
35095 \begin_layout Subsection
35096 Nibble and Byte Swapping
35097 \end_layout
35098
35099 \begin_layout Standard
35100 Other special cases of the bit-shift operations are nibble or byte swapping
35101 \begin_inset LatexCommand \index{swapping nibbles/bytes}
35102
35103 \end_inset
35104
35105 , SDCC recognizes the following expressions:
35106 \end_layout
35107
35108 \begin_layout Verse
35109
35110 \family typewriter
35111 \series bold
35112 unsigned
35113 \series default
35114 \InsetSpace ~
35115 \InsetSpace ~
35116 char i; 
35117 \newline
35118
35119 \series bold
35120 unsigned
35121 \series default
35122 \InsetSpace ~
35123 \InsetSpace ~
35124 int j; 
35125 \newline
35126 ...
35127  
35128 \newline
35129 i = ((i << 4) | (i >> 4)); 
35130 \family default
35131
35132 \newline
35133
35134 \family typewriter
35135 j = ((j << 8) | (j >> 8)); 
35136 \end_layout
35137
35138 \begin_layout Standard
35139 and generates a swap instruction for the nibble swapping
35140 \begin_inset LatexCommand \index{Nibble swapping}
35141
35142 \end_inset
35143
35144  or move instructions for the byte swapping
35145 \begin_inset LatexCommand \index{Byte swapping}
35146
35147 \end_inset
35148
35149 .
35150  The 
35151 \begin_inset Quotes sld
35152 \end_inset
35153
35154 j
35155 \begin_inset Quotes srd
35156 \end_inset
35157
35158  example can be used to convert from little to big-endian or vice versa.
35159  If you want to change the endianness of a 
35160 \emph on
35161 signed
35162 \emph default
35163  integer you have to cast to 
35164 \family typewriter
35165 (unsigned int)
35166 \family default
35167  first.
35168 \end_layout
35169
35170 \begin_layout Standard
35171 Note that SDCC stores numbers in little-endian
35172 \begin_inset Foot
35173 status open
35174
35175 \begin_layout Standard
35176 Usually 8-bit processors don't care much about endianness.
35177  This is not the case for the standard 8051 which only has an instruction
35178  to increment its 
35179 \emph on
35180 dptr
35181 \emph default
35182
35183 \begin_inset LatexCommand \index{DPTR}
35184
35185 \end_inset
35186
35187 -datapointer
35188 \emph on
35189  
35190 \emph default
35191 so little-endian is the more efficient byte order.
35192 \end_layout
35193
35194 \end_inset
35195
35196
35197 \begin_inset LatexCommand \index{little-endian}
35198
35199 \end_inset
35200
35201
35202 \begin_inset LatexCommand \index{Endianness}
35203
35204 \end_inset
35205
35206  format (i.e.
35207  lowest order first).
35208 \end_layout
35209
35210 \begin_layout Subsection
35211 Highest Order Bit
35212 \begin_inset LatexCommand \index{Highest Order Bit}
35213
35214 \end_inset
35215
35216  / Any Order Bit
35217 \begin_inset LatexCommand \index{Any Order Bit}
35218
35219 \end_inset
35220
35221
35222 \end_layout
35223
35224 \begin_layout Standard
35225 It is frequently required to obtain the highest order bit of an integral
35226  type (long, int, short or char types).
35227  Also obtaining any other order bit is not uncommon.
35228  SDCC recognizes the following expressions to yield the highest order bit
35229  and generates optimized code for it, e.g.:
35230 \end_layout
35231
35232 \begin_layout Verse
35233
35234 \family typewriter
35235 unsigned int gint; 
35236 \newline
35237
35238 \newline
35239 foo () { 
35240 \newline
35241 \InsetSpace ~
35242 \InsetSpace ~
35243 unsigned char hob1, aob1; 
35244 \newline
35245 \InsetSpace ~
35246 \InsetSpace ~
35247 bit hob2, hob3, aob2,
35248  aob3; 
35249 \newline
35250 \InsetSpace ~
35251 \InsetSpace ~
35252 ...
35253  
35254 \newline
35255 \InsetSpace ~
35256 \InsetSpace ~
35257 hob1 = (gint >> 15) & 1; 
35258 \newline
35259 \InsetSpace ~
35260 \InsetSpace ~
35261 hob2 = (gint >> 15) & 1; 
35262 \newline
35263 \InsetSpace ~
35264 \InsetSpace ~
35265 hob3 = gint & 0x8000;
35266  
35267 \newline
35268 \InsetSpace ~
35269 \InsetSpace ~
35270 aob1 = (gint >> 9) & 1; 
35271 \newline
35272 \InsetSpace ~
35273 \InsetSpace ~
35274 aob2 = (gint >> 8) & 1; 
35275 \newline
35276 \InsetSpace ~
35277 \InsetSpace ~
35278 aob3 = gint & 0x0800; 
35279 \newline
35280 \InsetSpace ~
35281 \InsetSpace ~
35282 ..
35283  
35284 \newline
35285 }
35286 \end_layout
35287
35288 \begin_layout Standard
35289 will generate the following code:
35290 \end_layout
35291
35292 \begin_layout Verse
35293
35294 \family typewriter
35295 \InsetSpace ~
35296 \InsetSpace ~
35297 \InsetSpace ~
35298 \InsetSpace ~
35299 \InsetSpace ~
35300 \InsetSpace ~
35301 \InsetSpace ~
35302 \InsetSpace ~
35303 \InsetSpace ~
35304 \InsetSpace ~
35305 \InsetSpace ~
35306 \InsetSpace ~
35307 \InsetSpace ~
35308 \InsetSpace ~
35309 \InsetSpace ~
35310 \InsetSpace ~
35311 \InsetSpace ~
35312 \InsetSpace ~
35313 \InsetSpace ~
35314 \InsetSpace ~
35315 \InsetSpace ~
35316 \InsetSpace ~
35317 \InsetSpace ~
35318 \InsetSpace ~
35319 \InsetSpace ~
35320  61 ;\InsetSpace ~
35321  hob.c 7 
35322 \newline
35323 000A E5*01\InsetSpace ~
35324 \InsetSpace ~
35325 \InsetSpace ~
35326 \InsetSpace ~
35327 \InsetSpace ~
35328 \InsetSpace ~
35329 \InsetSpace ~
35330 \InsetSpace ~
35331 \InsetSpace ~
35332 \InsetSpace ~
35333 \InsetSpace ~
35334 \InsetSpace ~
35335 \InsetSpace ~
35336 \InsetSpace ~
35337 \InsetSpace ~
35338  62\InsetSpace ~
35339 \InsetSpace ~
35340 \InsetSpace ~
35341 \InsetSpace ~
35342 \InsetSpace ~
35343 \InsetSpace ~
35344 \InsetSpace ~
35345 \InsetSpace ~
35346  mov\InsetSpace ~
35347 \InsetSpace ~
35348  a,(_gint + 1) 
35349 \newline
35350 000C 23\InsetSpace ~
35351 \InsetSpace ~
35352 \InsetSpace ~
35353 \InsetSpace ~
35354 \InsetSpace ~
35355 \InsetSpace ~
35356 \InsetSpace ~
35357 \InsetSpace ~
35358 \InsetSpace ~
35359 \InsetSpace ~
35360 \InsetSpace ~
35361 \InsetSpace ~
35362 \InsetSpace ~
35363 \InsetSpace ~
35364 \InsetSpace ~
35365 \InsetSpace ~
35366 \InsetSpace ~
35367 \InsetSpace ~
35368  63\InsetSpace ~
35369 \InsetSpace ~
35370 \InsetSpace ~
35371 \InsetSpace ~
35372 \InsetSpace ~
35373 \InsetSpace ~
35374 \InsetSpace ~
35375 \InsetSpace ~
35376  rl\InsetSpace ~
35377 \InsetSpace ~
35378 \InsetSpace ~
35379  a 
35380 \newline
35381 000D 54 01\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
35397  64\InsetSpace ~
35398 \InsetSpace ~
35399 \InsetSpace ~
35400 \InsetSpace ~
35401 \InsetSpace ~
35402 \InsetSpace ~
35403 \InsetSpace ~
35404 \InsetSpace ~
35405  anl\InsetSpace ~
35406 \InsetSpace ~
35407  a,#0x01 
35408 \newline
35409 000F F5*02\InsetSpace ~
35410 \InsetSpace ~
35411 \InsetSpace ~
35412 \InsetSpace ~
35413 \InsetSpace ~
35414 \InsetSpace ~
35415 \InsetSpace ~
35416 \InsetSpace ~
35417 \InsetSpace ~
35418 \InsetSpace ~
35419 \InsetSpace ~
35420 \InsetSpace ~
35421 \InsetSpace ~
35422 \InsetSpace ~
35423 \InsetSpace ~
35424  65\InsetSpace ~
35425 \InsetSpace ~
35426 \InsetSpace ~
35427 \InsetSpace ~
35428 \InsetSpace ~
35429 \InsetSpace ~
35430 \InsetSpace ~
35431 \InsetSpace ~
35432  mov\InsetSpace ~
35433 \InsetSpace ~
35434  _foo_hob1_1_1,a 
35435 \newline
35436 \InsetSpace ~
35437 \InsetSpace ~
35438 \InsetSpace ~
35439 \InsetSpace ~
35440 \InsetSpace ~
35441 \InsetSpace ~
35442 \InsetSpace ~
35443 \InsetSpace ~
35444 \InsetSpace ~
35445 \InsetSpace ~
35446 \InsetSpace ~
35447 \InsetSpace ~
35448 \InsetSpace ~
35449 \InsetSpace ~
35450 \InsetSpace ~
35451 \InsetSpace ~
35452 \InsetSpace ~
35453 \InsetSpace ~
35454 \InsetSpace ~
35455 \InsetSpace ~
35456 \InsetSpace ~
35457 \InsetSpace ~
35458 \InsetSpace ~
35459 \InsetSpace ~
35460 \InsetSpace ~
35461  66 ;\InsetSpace ~
35462  hob.c 8 
35463 \newline
35464 0011 E5*01\InsetSpace ~
35465 \InsetSpace ~
35466 \InsetSpace ~
35467 \InsetSpace ~
35468 \InsetSpace ~
35469 \InsetSpace ~
35470 \InsetSpace ~
35471 \InsetSpace ~
35472 \InsetSpace ~
35473 \InsetSpace ~
35474 \InsetSpace ~
35475 \InsetSpace ~
35476 \InsetSpace ~
35477 \InsetSpace ~
35478 \InsetSpace ~
35479
35480  67\InsetSpace ~
35481 \InsetSpace ~
35482 \InsetSpace ~
35483 \InsetSpace ~
35484 \InsetSpace ~
35485 \InsetSpace ~
35486 \InsetSpace ~
35487 \InsetSpace ~
35488  mov\InsetSpace ~
35489 \InsetSpace ~
35490  a,(_gint + 1) 
35491 \newline
35492 0013 33\InsetSpace ~
35493 \InsetSpace ~
35494 \InsetSpace ~
35495 \InsetSpace ~
35496 \InsetSpace ~
35497 \InsetSpace ~
35498 \InsetSpace ~
35499 \InsetSpace ~
35500 \InsetSpace ~
35501 \InsetSpace ~
35502 \InsetSpace ~
35503 \InsetSpace ~
35504 \InsetSpace ~
35505 \InsetSpace ~
35506 \InsetSpace ~
35507 \InsetSpace ~
35508 \InsetSpace ~
35509 \InsetSpace ~
35510  68\InsetSpace ~
35511 \InsetSpace ~
35512 \InsetSpace ~
35513 \InsetSpace ~
35514 \InsetSpace ~
35515 \InsetSpace ~
35516 \InsetSpace ~
35517 \InsetSpace ~
35518  rlc\InsetSpace ~
35519 \InsetSpace ~
35520  a 
35521 \newline
35522 0014 92*00\InsetSpace ~
35523 \InsetSpace ~
35524 \InsetSpace ~
35525 \InsetSpace ~
35526 \InsetSpace ~
35527 \InsetSpace ~
35528 \InsetSpace ~
35529 \InsetSpace ~
35530 \InsetSpace ~
35531 \InsetSpace ~
35532 \InsetSpace ~
35533 \InsetSpace ~
35534 \InsetSpace ~
35535 \InsetSpace ~
35536 \InsetSpace ~
35537  69\InsetSpace ~
35538 \InsetSpace ~
35539 \InsetSpace ~
35540 \InsetSpace ~
35541 \InsetSpace ~
35542 \InsetSpace ~
35543 \InsetSpace ~
35544 \InsetSpace ~
35545  mov\InsetSpace ~
35546 \InsetSpace ~
35547  _foo_hob2_1_1,c
35548  
35549 \newline
35550 \InsetSpace ~
35551 \InsetSpace ~
35552 \InsetSpace ~
35553 \InsetSpace ~
35554 \InsetSpace ~
35555 \InsetSpace ~
35556 \InsetSpace ~
35557 \InsetSpace ~
35558 \InsetSpace ~
35559 \InsetSpace ~
35560 \InsetSpace ~
35561 \InsetSpace ~
35562 \InsetSpace ~
35563 \InsetSpace ~
35564 \InsetSpace ~
35565 \InsetSpace ~
35566 \InsetSpace ~
35567 \InsetSpace ~
35568 \InsetSpace ~
35569 \InsetSpace ~
35570 \InsetSpace ~
35571 \InsetSpace ~
35572 \InsetSpace ~
35573 \InsetSpace ~
35574 \InsetSpace ~
35575  66 ;\InsetSpace ~
35576  hob.c 9 
35577 \newline
35578 0016 E5*01\InsetSpace ~
35579 \InsetSpace ~
35580 \InsetSpace ~
35581 \InsetSpace ~
35582 \InsetSpace ~
35583 \InsetSpace ~
35584 \InsetSpace ~
35585 \InsetSpace ~
35586 \InsetSpace ~
35587 \InsetSpace ~
35588 \InsetSpace ~
35589 \InsetSpace ~
35590 \InsetSpace ~
35591 \InsetSpace ~
35592 \InsetSpace ~
35593  67\InsetSpace ~
35594 \InsetSpace ~
35595 \InsetSpace ~
35596 \InsetSpace ~
35597 \InsetSpace ~
35598 \InsetSpace ~
35599 \InsetSpace ~
35600 \InsetSpace ~
35601  mov\InsetSpace ~
35602 \InsetSpace ~
35603  a,(_gint + 1) 
35604 \newline
35605 0018 33\InsetSpace ~
35606 \InsetSpace ~
35607 \InsetSpace ~
35608 \InsetSpace ~
35609 \InsetSpace ~
35610 \InsetSpace ~
35611 \InsetSpace ~
35612 \InsetSpace ~
35613 \InsetSpace ~
35614 \InsetSpace ~
35615 \InsetSpace ~
35616 \InsetSpace ~
35617 \InsetSpace ~
35618 \InsetSpace ~
35619 \InsetSpace ~
35620 \InsetSpace ~
35621 \InsetSpace ~
35622 \InsetSpace ~
35623  68\InsetSpace ~
35624 \InsetSpace ~
35625 \InsetSpace ~
35626 \InsetSpace ~
35627 \InsetSpace ~
35628 \InsetSpace ~
35629 \InsetSpace ~
35630 \InsetSpace ~
35631  rlc\InsetSpace ~
35632 \InsetSpace ~
35633  a 
35634 \newline
35635 0019 92*01\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
35651  69\InsetSpace ~
35652 \InsetSpace ~
35653 \InsetSpace ~
35654 \InsetSpace ~
35655 \InsetSpace ~
35656 \InsetSpace ~
35657 \InsetSpace ~
35658 \InsetSpace ~
35659  mov\InsetSpace ~
35660 \InsetSpace ~
35661  _foo_hob3_1_1,c 
35662 \newline
35663 \InsetSpace ~
35664 \InsetSpace ~
35665 \InsetSpace ~
35666 \InsetSpace ~
35667 \InsetSpace ~
35668 \InsetSpace ~
35669 \InsetSpace ~
35670 \InsetSpace ~
35671 \InsetSpace ~
35672 \InsetSpace ~
35673 \InsetSpace ~
35674 \InsetSpace ~
35675 \InsetSpace ~
35676 \InsetSpace ~
35677 \InsetSpace ~
35678 \InsetSpace ~
35679 \InsetSpace ~
35680 \InsetSpace ~
35681 \InsetSpace ~
35682 \InsetSpace ~
35683 \InsetSpace ~
35684 \InsetSpace ~
35685 \InsetSpace ~
35686 \InsetSpace ~
35687 \InsetSpace ~
35688  70 ;\InsetSpace ~
35689  hob.c 10 
35690 \newline
35691 001B E5*01\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  71\InsetSpace ~
35707 \InsetSpace ~
35708 \InsetSpace ~
35709 \InsetSpace ~
35710 \InsetSpace ~
35711 \InsetSpace ~
35712 \InsetSpace ~
35713 \InsetSpace ~
35714  mov\InsetSpace ~
35715 \InsetSpace ~
35716  a,(_gint + 1) 
35717 \newline
35718 001D
35719  03\InsetSpace ~
35720 \InsetSpace ~
35721 \InsetSpace ~
35722 \InsetSpace ~
35723 \InsetSpace ~
35724 \InsetSpace ~
35725 \InsetSpace ~
35726 \InsetSpace ~
35727 \InsetSpace ~
35728 \InsetSpace ~
35729 \InsetSpace ~
35730 \InsetSpace ~
35731 \InsetSpace ~
35732 \InsetSpace ~
35733 \InsetSpace ~
35734 \InsetSpace ~
35735 \InsetSpace ~
35736 \InsetSpace ~
35737  72\InsetSpace ~
35738 \InsetSpace ~
35739 \InsetSpace ~
35740 \InsetSpace ~
35741 \InsetSpace ~
35742 \InsetSpace ~
35743 \InsetSpace ~
35744 \InsetSpace ~
35745  rr\InsetSpace ~
35746 \InsetSpace ~
35747 \InsetSpace ~
35748  a 
35749 \newline
35750 001E 54 01\InsetSpace ~
35751 \InsetSpace ~
35752 \InsetSpace ~
35753 \InsetSpace ~
35754 \InsetSpace ~
35755 \InsetSpace ~
35756 \InsetSpace ~
35757 \InsetSpace ~
35758 \InsetSpace ~
35759 \InsetSpace ~
35760 \InsetSpace ~
35761 \InsetSpace ~
35762 \InsetSpace ~
35763 \InsetSpace ~
35764 \InsetSpace ~
35765  73\InsetSpace ~
35766 \InsetSpace ~
35767 \InsetSpace ~
35768 \InsetSpace ~
35769 \InsetSpace ~
35770 \InsetSpace ~
35771 \InsetSpace ~
35772 \InsetSpace ~
35773  anl\InsetSpace ~
35774 \InsetSpace ~
35775  a,#0x01 
35776 \newline
35777 0020 F5*03\InsetSpace ~
35778 \InsetSpace ~
35779 \InsetSpace ~
35780 \InsetSpace ~
35781 \InsetSpace ~
35782 \InsetSpace ~
35783 \InsetSpace ~
35784 \InsetSpace ~
35785 \InsetSpace ~
35786 \InsetSpace ~
35787 \InsetSpace ~
35788 \InsetSpace ~
35789 \InsetSpace ~
35790 \InsetSpace ~
35791 \InsetSpace ~
35792  74\InsetSpace ~
35793 \InsetSpace ~
35794 \InsetSpace ~
35795 \InsetSpace ~
35796 \InsetSpace ~
35797 \InsetSpace ~
35798 \InsetSpace ~
35799 \InsetSpace ~
35800  mov\InsetSpace ~
35801 \InsetSpace ~
35802  _foo_aob1_1_1,a
35803  
35804 \newline
35805 \InsetSpace ~
35806 \InsetSpace ~
35807 \InsetSpace ~
35808 \InsetSpace ~
35809 \InsetSpace ~
35810 \InsetSpace ~
35811 \InsetSpace ~
35812 \InsetSpace ~
35813 \InsetSpace ~
35814 \InsetSpace ~
35815 \InsetSpace ~
35816 \InsetSpace ~
35817 \InsetSpace ~
35818 \InsetSpace ~
35819 \InsetSpace ~
35820 \InsetSpace ~
35821 \InsetSpace ~
35822 \InsetSpace ~
35823 \InsetSpace ~
35824 \InsetSpace ~
35825 \InsetSpace ~
35826 \InsetSpace ~
35827 \InsetSpace ~
35828 \InsetSpace ~
35829 \InsetSpace ~
35830  75 ;\InsetSpace ~
35831  hob.c 11 
35832 \newline
35833 0022 E5*01\InsetSpace ~
35834 \InsetSpace ~
35835 \InsetSpace ~
35836 \InsetSpace ~
35837 \InsetSpace ~
35838 \InsetSpace ~
35839 \InsetSpace ~
35840 \InsetSpace ~
35841 \InsetSpace ~
35842 \InsetSpace ~
35843 \InsetSpace ~
35844 \InsetSpace ~
35845 \InsetSpace ~
35846 \InsetSpace ~
35847 \InsetSpace ~
35848  76\InsetSpace ~
35849 \InsetSpace ~
35850 \InsetSpace ~
35851 \InsetSpace ~
35852 \InsetSpace ~
35853 \InsetSpace ~
35854 \InsetSpace ~
35855 \InsetSpace ~
35856  mov\InsetSpace ~
35857 \InsetSpace ~
35858  a,(_gint + 1) 
35859 \newline
35860 0024 13\InsetSpace ~
35861 \InsetSpace ~
35862 \InsetSpace ~
35863 \InsetSpace ~
35864 \InsetSpace ~
35865 \InsetSpace ~
35866 \InsetSpace ~
35867 \InsetSpace ~
35868 \InsetSpace ~
35869 \InsetSpace ~
35870 \InsetSpace ~
35871 \InsetSpace ~
35872 \InsetSpace ~
35873 \InsetSpace ~
35874 \InsetSpace ~
35875 \InsetSpace ~
35876 \InsetSpace ~
35877 \InsetSpace ~
35878  77\InsetSpace ~
35879 \InsetSpace ~
35880 \InsetSpace ~
35881 \InsetSpace ~
35882 \InsetSpace ~
35883 \InsetSpace ~
35884 \InsetSpace ~
35885 \InsetSpace ~
35886  rrc\InsetSpace ~
35887 \InsetSpace ~
35888  a 
35889 \newline
35890 0025 92*02\InsetSpace ~
35891 \InsetSpace ~
35892 \InsetSpace ~
35893 \InsetSpace ~
35894 \InsetSpace ~
35895 \InsetSpace ~
35896 \InsetSpace ~
35897 \InsetSpace ~
35898 \InsetSpace ~
35899 \InsetSpace ~
35900 \InsetSpace ~
35901 \InsetSpace ~
35902 \InsetSpace ~
35903 \InsetSpace ~
35904 \InsetSpace ~
35905
35906  78\InsetSpace ~
35907 \InsetSpace ~
35908 \InsetSpace ~
35909 \InsetSpace ~
35910 \InsetSpace ~
35911 \InsetSpace ~
35912 \InsetSpace ~
35913 \InsetSpace ~
35914  mov\InsetSpace ~
35915 \InsetSpace ~
35916  _foo_aob2_1_1,c 
35917 \newline
35918 \InsetSpace ~
35919 \InsetSpace ~
35920 \InsetSpace ~
35921 \InsetSpace ~
35922 \InsetSpace ~
35923 \InsetSpace ~
35924 \InsetSpace ~
35925 \InsetSpace ~
35926 \InsetSpace ~
35927 \InsetSpace ~
35928 \InsetSpace ~
35929 \InsetSpace ~
35930 \InsetSpace ~
35931 \InsetSpace ~
35932 \InsetSpace ~
35933 \InsetSpace ~
35934 \InsetSpace ~
35935 \InsetSpace ~
35936 \InsetSpace ~
35937 \InsetSpace ~
35938 \InsetSpace ~
35939 \InsetSpace ~
35940 \InsetSpace ~
35941 \InsetSpace ~
35942 \InsetSpace ~
35943  79 ;\InsetSpace ~
35944  hob.c 12 
35945 \newline
35946 0027 E5*01\InsetSpace ~
35947 \InsetSpace ~
35948 \InsetSpace ~
35949 \InsetSpace ~
35950 \InsetSpace ~
35951 \InsetSpace ~
35952 \InsetSpace ~
35953 \InsetSpace ~
35954 \InsetSpace ~
35955 \InsetSpace ~
35956 \InsetSpace ~
35957 \InsetSpace ~
35958 \InsetSpace ~
35959 \InsetSpace ~
35960 \InsetSpace ~
35961  80\InsetSpace ~
35962 \InsetSpace ~
35963 \InsetSpace ~
35964 \InsetSpace ~
35965 \InsetSpace ~
35966 \InsetSpace ~
35967 \InsetSpace ~
35968 \InsetSpace ~
35969  mov\InsetSpace ~
35970 \InsetSpace ~
35971  a,(_gint + 1) 
35972 \newline
35973 0029
35974  A2 E3\InsetSpace ~
35975 \InsetSpace ~
35976 \InsetSpace ~
35977 \InsetSpace ~
35978 \InsetSpace ~
35979 \InsetSpace ~
35980 \InsetSpace ~
35981 \InsetSpace ~
35982 \InsetSpace ~
35983 \InsetSpace ~
35984 \InsetSpace ~
35985 \InsetSpace ~
35986 \InsetSpace ~
35987 \InsetSpace ~
35988 \InsetSpace ~
35989  81\InsetSpace ~
35990 \InsetSpace ~
35991 \InsetSpace ~
35992 \InsetSpace ~
35993 \InsetSpace ~
35994 \InsetSpace ~
35995 \InsetSpace ~
35996 \InsetSpace ~
35997  mov\InsetSpace ~
35998 \InsetSpace ~
35999  c,acc[3] 
36000 \newline
36001 002B 92*03\InsetSpace ~
36002 \InsetSpace ~
36003 \InsetSpace ~
36004 \InsetSpace ~
36005 \InsetSpace ~
36006 \InsetSpace ~
36007 \InsetSpace ~
36008 \InsetSpace ~
36009 \InsetSpace ~
36010 \InsetSpace ~
36011 \InsetSpace ~
36012 \InsetSpace ~
36013 \InsetSpace ~
36014 \InsetSpace ~
36015 \InsetSpace ~
36016  82\InsetSpace ~
36017 \InsetSpace ~
36018 \InsetSpace ~
36019 \InsetSpace ~
36020 \InsetSpace ~
36021 \InsetSpace ~
36022 \InsetSpace ~
36023 \InsetSpace ~
36024  mov\InsetSpace ~
36025 \InsetSpace ~
36026  _foo_aob3_1_1,c 
36027 \end_layout
36028
36029 \begin_layout Standard
36030 Other variations of these cases however will 
36031 \emph on
36032 not
36033 \emph default
36034  be recognized.
36035  They are standard C expressions, so I heartily recommend these be the only
36036  way to get the highest order bit, (it is portable).
36037  Of course it will be recognized even if it is embedded in other expressions,
36038  e.g.:
36039 \end_layout
36040
36041 \begin_layout Verse
36042
36043 \family typewriter
36044 xyz = gint + ((gint >> 15) & 1);
36045 \end_layout
36046
36047 \begin_layout Standard
36048 will still be recognized.
36049 \end_layout
36050
36051 \begin_layout Subsection
36052 Higher Order Byte
36053 \begin_inset LatexCommand \index{Higher Order Byte}
36054
36055 \end_inset
36056
36057  / Higher Order Word
36058 \begin_inset LatexCommand \index{Higher Order Word}
36059
36060 \end_inset
36061
36062
36063 \end_layout
36064
36065 \begin_layout Standard
36066 It is also frequently required to obtain a higher order byte or word of
36067  a larger integral type (long, int or short types).
36068  SDCC recognizes the following expressions to yield the higher order byte
36069  or word and generates optimized code for it, e.g.:
36070 \end_layout
36071
36072 \begin_layout Verse
36073
36074 \family typewriter
36075 unsigned int gint; 
36076 \newline
36077 unsigned long int glong; 
36078 \newline
36079
36080 \newline
36081 foo () { 
36082 \newline
36083 \InsetSpace ~
36084 \InsetSpace ~
36085 unsigned char hob1,
36086  hob2; 
36087 \newline
36088 \InsetSpace ~
36089 \InsetSpace ~
36090 unsigned int how1, how2; 
36091 \newline
36092 \InsetSpace ~
36093 \InsetSpace ~
36094 ...
36095  
36096 \newline
36097 \InsetSpace ~
36098 \InsetSpace ~
36099 hob1 = (gint >> 8) & 0xFF; 
36100 \newline
36101 \InsetSpace ~
36102 \InsetSpace ~
36103 hob2 = glong >> 24; 
36104 \newline
36105 \InsetSpace ~
36106 \InsetSpace ~
36107 how1 = (glong >> 16) & 0xFFFF;
36108  
36109 \newline
36110 \InsetSpace ~
36111 \InsetSpace ~
36112 how2 = glong >> 8; 
36113 \newline
36114 \InsetSpace ~
36115 \InsetSpace ~
36116 ..
36117  
36118 \newline
36119 }
36120 \end_layout
36121
36122 \begin_layout Standard
36123 will generate the following code:
36124 \end_layout
36125
36126 \begin_layout Verse
36127
36128 \family typewriter
36129 \InsetSpace ~
36130 \InsetSpace ~
36131 \InsetSpace ~
36132 \InsetSpace ~
36133 \InsetSpace ~
36134 \InsetSpace ~
36135 \InsetSpace ~
36136 \InsetSpace ~
36137 \InsetSpace ~
36138 \InsetSpace ~
36139 \InsetSpace ~
36140 \InsetSpace ~
36141 \InsetSpace ~
36142 \InsetSpace ~
36143 \InsetSpace ~
36144 \InsetSpace ~
36145 \InsetSpace ~
36146 \InsetSpace ~
36147 \InsetSpace ~
36148 \InsetSpace ~
36149 \InsetSpace ~
36150 \InsetSpace ~
36151 \InsetSpace ~
36152 \InsetSpace ~
36153 \InsetSpace ~
36154  91 ;\InsetSpace ~
36155  hob.c 15 
36156 \newline
36157 0037 85*01*06\InsetSpace ~
36158 \InsetSpace ~
36159 \InsetSpace ~
36160 \InsetSpace ~
36161 \InsetSpace ~
36162 \InsetSpace ~
36163 \InsetSpace ~
36164 \InsetSpace ~
36165 \InsetSpace ~
36166 \InsetSpace ~
36167 \InsetSpace ~
36168 \InsetSpace ~
36169  92\InsetSpace ~
36170 \InsetSpace ~
36171 \InsetSpace ~
36172 \InsetSpace ~
36173 \InsetSpace ~
36174 \InsetSpace ~
36175 \InsetSpace ~
36176 \InsetSpace ~
36177  mov\InsetSpace ~
36178 \InsetSpace ~
36179  _foo_hob1_1_1,(_gint + 1) 
36180 \newline
36181 \InsetSpace ~
36182 \InsetSpace ~
36183 \InsetSpace ~
36184 \InsetSpace ~
36185 \InsetSpace ~
36186 \InsetSpace ~
36187 \InsetSpace ~
36188 \InsetSpace ~
36189 \InsetSpace ~
36190 \InsetSpace ~
36191 \InsetSpace ~
36192 \InsetSpace ~
36193 \InsetSpace ~
36194 \InsetSpace ~
36195 \InsetSpace ~
36196 \InsetSpace ~
36197 \InsetSpace ~
36198 \InsetSpace ~
36199 \InsetSpace ~
36200 \InsetSpace ~
36201 \InsetSpace ~
36202 \InsetSpace ~
36203 \InsetSpace ~
36204 \InsetSpace ~
36205 \InsetSpace ~
36206  93 ;\InsetSpace ~
36207  hob.c
36208  16 
36209 \newline
36210 003A 85*05*07\InsetSpace ~
36211 \InsetSpace ~
36212 \InsetSpace ~
36213 \InsetSpace ~
36214 \InsetSpace ~
36215 \InsetSpace ~
36216 \InsetSpace ~
36217 \InsetSpace ~
36218 \InsetSpace ~
36219 \InsetSpace ~
36220 \InsetSpace ~
36221 \InsetSpace ~
36222  94\InsetSpace ~
36223 \InsetSpace ~
36224 \InsetSpace ~
36225 \InsetSpace ~
36226 \InsetSpace ~
36227 \InsetSpace ~
36228 \InsetSpace ~
36229 \InsetSpace ~
36230  mov\InsetSpace ~
36231 \InsetSpace ~
36232  _foo_hob2_1_1,(_glong + 3) 
36233 \newline
36234 \InsetSpace ~
36235 \InsetSpace ~
36236 \InsetSpace ~
36237 \InsetSpace ~
36238 \InsetSpace ~
36239 \InsetSpace ~
36240 \InsetSpace ~
36241 \InsetSpace ~
36242 \InsetSpace ~
36243 \InsetSpace ~
36244 \InsetSpace ~
36245 \InsetSpace ~
36246 \InsetSpace ~
36247 \InsetSpace ~
36248 \InsetSpace ~
36249 \InsetSpace ~
36250 \InsetSpace ~
36251 \InsetSpace ~
36252 \InsetSpace ~
36253 \InsetSpace ~
36254 \InsetSpace ~
36255 \InsetSpace ~
36256 \InsetSpace ~
36257 \InsetSpace ~
36258 \InsetSpace ~
36259  95 ;\InsetSpace ~
36260  hob.c 17 
36261 \newline
36262 003D 85*04*08\InsetSpace ~
36263 \InsetSpace ~
36264 \InsetSpace ~
36265 \InsetSpace ~
36266 \InsetSpace ~
36267 \InsetSpace ~
36268 \InsetSpace ~
36269 \InsetSpace ~
36270 \InsetSpace ~
36271 \InsetSpace ~
36272 \InsetSpace ~
36273 \InsetSpace ~
36274
36275  96\InsetSpace ~
36276 \InsetSpace ~
36277 \InsetSpace ~
36278 \InsetSpace ~
36279 \InsetSpace ~
36280 \InsetSpace ~
36281 \InsetSpace ~
36282 \InsetSpace ~
36283  mov\InsetSpace ~
36284 \InsetSpace ~
36285  _foo_how1_1_1,(_glong + 2) 
36286 \newline
36287 0040 85*05*09\InsetSpace ~
36288 \InsetSpace ~
36289 \InsetSpace ~
36290 \InsetSpace ~
36291 \InsetSpace ~
36292 \InsetSpace ~
36293 \InsetSpace ~
36294 \InsetSpace ~
36295 \InsetSpace ~
36296 \InsetSpace ~
36297 \InsetSpace ~
36298 \InsetSpace ~
36299  97\InsetSpace ~
36300 \InsetSpace ~
36301 \InsetSpace ~
36302 \InsetSpace ~
36303 \InsetSpace ~
36304 \InsetSpace ~
36305 \InsetSpace ~
36306 \InsetSpace ~
36307  mov\InsetSpace ~
36308 \InsetSpace ~
36309  (_foo_how1_1_1 +
36310  1),(_glong + 3) 
36311 \newline
36312 0043 85*03*0A\InsetSpace ~
36313 \InsetSpace ~
36314 \InsetSpace ~
36315 \InsetSpace ~
36316 \InsetSpace ~
36317 \InsetSpace ~
36318 \InsetSpace ~
36319 \InsetSpace ~
36320 \InsetSpace ~
36321 \InsetSpace ~
36322 \InsetSpace ~
36323 \InsetSpace ~
36324  98\InsetSpace ~
36325 \InsetSpace ~
36326 \InsetSpace ~
36327 \InsetSpace ~
36328 \InsetSpace ~
36329 \InsetSpace ~
36330 \InsetSpace ~
36331 \InsetSpace ~
36332  mov\InsetSpace ~
36333 \InsetSpace ~
36334  _foo_how2_1_1,(_glong + 1) 
36335 \newline
36336 0046 85*04*0B\InsetSpace ~
36337 \InsetSpace ~
36338 \InsetSpace ~
36339 \InsetSpace ~
36340 \InsetSpace ~
36341 \InsetSpace ~
36342 \InsetSpace ~
36343 \InsetSpace ~
36344 \InsetSpace ~
36345 \InsetSpace ~
36346 \InsetSpace ~
36347 \InsetSpace ~
36348
36349  99\InsetSpace ~
36350 \InsetSpace ~
36351 \InsetSpace ~
36352 \InsetSpace ~
36353 \InsetSpace ~
36354 \InsetSpace ~
36355 \InsetSpace ~
36356 \InsetSpace ~
36357  mov\InsetSpace ~
36358 \InsetSpace ~
36359  (_foo_how2_1_1 + 1),(_glong + 2) 
36360 \end_layout
36361
36362 \begin_layout Standard
36363 Again, variations of these cases may 
36364 \emph on
36365 not
36366 \emph default
36367  be recognized.
36368  They are standard C expressions, so I heartily recommend these be the only
36369  way to get the higher order byte/word, (it is portable).
36370  Of course it will be recognized even if it is embedded in other expressions,
36371  e.g.:
36372 \end_layout
36373
36374 \begin_layout Verse
36375
36376 \family typewriter
36377 xyz = gint + ((gint >> 8) & 0xFF);
36378 \end_layout
36379
36380 \begin_layout Standard
36381 will still be recognized.
36382 \end_layout
36383
36384 \begin_layout Subsection
36385 Peephole Optimizer
36386 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
36387
36388 \end_inset
36389
36390
36391 \begin_inset LatexCommand \index{Peephole optimizer}
36392
36393 \end_inset
36394
36395
36396 \end_layout
36397
36398 \begin_layout Standard
36399 The compiler uses a rule based, pattern matching and re-writing mechanism
36400  for peep-hole optimization.
36401  It is inspired by 
36402 \emph on
36403 copt
36404 \emph default
36405  a peep-hole optimizer by Christopher W.
36406  Fraser (cwfraser\InsetSpace ~
36407 @\InsetSpace ~
36408 microsoft.com).
36409  A default set of rules are compiled into the compiler, additional rules
36410  may be added with the 
36411 \emph on
36412 -
36413 \begin_inset ERT
36414 status collapsed
36415
36416 \begin_layout Standard
36417
36418
36419 \backslash
36420 /
36421 \end_layout
36422
36423 \end_inset
36424
36425 -peep-file
36426 \begin_inset LatexCommand \index{-\/-peep-file}
36427
36428 \end_inset
36429
36430  <filename>
36431 \emph default
36432  option.
36433  The rule language is best illustrated with examples.
36434 \end_layout
36435
36436 \begin_layout Verse
36437
36438 \family typewriter
36439 replace { 
36440 \newline
36441 \InsetSpace ~
36442 \InsetSpace ~
36443 mov %1,a 
36444 \newline
36445 \InsetSpace ~
36446 \InsetSpace ~
36447 mov a,%1
36448 \newline
36449 } by {
36450 \newline
36451 \InsetSpace ~
36452 \InsetSpace ~
36453 mov %1,a
36454 \newline
36455 }
36456 \end_layout
36457
36458 \begin_layout Standard
36459 The above rule will change the following assembly
36460 \begin_inset LatexCommand \index{Assembler routines}
36461
36462 \end_inset
36463
36464  sequence:
36465 \end_layout
36466
36467 \begin_layout Verse
36468
36469 \family typewriter
36470 mov r1,a 
36471 \newline
36472 mov a,r1
36473 \end_layout
36474
36475 \begin_layout Standard
36476 to
36477 \end_layout
36478
36479 \begin_layout Verse
36480
36481 \family typewriter
36482 mov r1,a
36483 \end_layout
36484
36485 \begin_layout Standard
36486 Note: All occurrences of a 
36487 \emph on
36488 %n
36489 \emph default
36490  (pattern variable) must denote the same string.
36491  With the above rule, the assembly sequence:
36492 \end_layout
36493
36494 \begin_layout Verse
36495
36496 \family typewriter
36497 mov r1,a 
36498 \newline
36499 mov a,r2
36500 \end_layout
36501
36502 \begin_layout Standard
36503 will remain unmodified.
36504 \newline
36505
36506 \newline
36507 Other special case optimizations may be added by the
36508  user (via 
36509 \emph on
36510 -
36511 \begin_inset ERT
36512 status collapsed
36513
36514 \begin_layout Standard
36515
36516
36517 \backslash
36518 /
36519 \end_layout
36520
36521 \end_inset
36522
36523 -peep-file option
36524 \emph default
36525 ).
36526  E.g.
36527  some variants of the 8051 MCU
36528 \begin_inset LatexCommand \index{MCS51 variants}
36529
36530 \end_inset
36531
36532  allow only 
36533 \family typewriter
36534 ajmp
36535 \family default
36536  and 
36537 \family typewriter
36538 acall
36539 \family default
36540 .
36541  The following two rules will change all 
36542 \family typewriter
36543 ljmp
36544 \family default
36545  and 
36546 \family typewriter
36547 lcall
36548 \family default
36549  to 
36550 \family typewriter
36551 ajmp
36552 \family default
36553  and 
36554 \family typewriter
36555 acall
36556 \end_layout
36557
36558 \begin_layout Verse
36559
36560 \family typewriter
36561 replace { lcall %1 } by { acall %1 } 
36562 \newline
36563 replace { ljmp %1 } by { ajmp %1 }
36564 \end_layout
36565
36566 \begin_layout Standard
36567 (NOTE: from version 2.7.3 on, you can use option -
36568 \emph on
36569
36570 \begin_inset ERT
36571 status collapsed
36572
36573 \begin_layout Standard
36574
36575
36576 \backslash
36577 /
36578 \end_layout
36579
36580 \end_inset
36581
36582
36583 \emph default
36584 -acall-ajmp
36585 \begin_inset LatexCommand \index{-\/-acall-ajmp}
36586
36587 \end_inset
36588
36589 , which also takes care of aligning the interrupt vectors properly.)
36590 \newline
36591
36592 \end_layout
36593
36594 \begin_layout Standard
36595 The 
36596 \emph on
36597 inline-assembler code
36598 \emph default
36599  is also passed through the peep hole optimizer, thus the peephole optimizer
36600  can also be used as an assembly level macro expander.
36601  The rules themselves are MCU dependent whereas the rule language infra-structur
36602 e is MCU independent.
36603  Peephole optimization rules for other MCU can be easily programmed using
36604  the rule language.
36605 \newline
36606
36607 \newline
36608 The syntax for a rule is as follows:
36609 \end_layout
36610
36611 \begin_layout Verse
36612
36613 \family typewriter
36614 rule := replace [ restart ] '{' <assembly sequence> '
36615 \backslash
36616 n' 
36617 \newline
36618 \InsetSpace ~
36619  \InsetSpace ~
36620  \InsetSpace ~
36621  \InsetSpace ~
36622  \InsetSpace ~
36623  \InsetSpace ~
36624  \InsetSpace ~
36625  \InsetSpace ~
36626  \InsetSpace ~
36627  \InsetSpace ~
36628  \InsetSpace ~
36629  \InsetSpace ~
36630  \InsetSpace ~
36631  \InsetSpace ~
36632  '}' by '{' '
36633 \backslash
36634 n' 
36635 \newline
36636 \InsetSpace ~
36637  \InsetSpace ~
36638  \InsetSpace ~
36639  \InsetSpace ~
36640  \InsetSpace ~
36641  \InsetSpace ~
36642  \InsetSpace ~
36643  \InsetSpace ~
36644  \InsetSpace ~
36645  \InsetSpace ~
36646  \InsetSpace ~
36647  \InsetSpace ~
36648  \InsetSpace ~
36649  \InsetSpace ~
36650  \InsetSpace ~
36651  \InsetSpace ~
36652  <assembly sequence> '
36653 \backslash
36654 n' 
36655 \newline
36656 \InsetSpace ~
36657  \InsetSpace ~
36658  \InsetSpace ~
36659  \InsetSpace ~
36660  \InsetSpace ~
36661  \InsetSpace ~
36662  \InsetSpace ~
36663  \InsetSpace ~
36664  \InsetSpace ~
36665  \InsetSpace ~
36666  \InsetSpace ~
36667  \InsetSpace ~
36668  \InsetSpace ~
36669  \InsetSpace ~
36670  '}' [if <functionName> ] '
36671 \backslash
36672 n' 
36673 \end_layout
36674
36675 \begin_layout Standard
36676 <assembly sequence> := assembly instruction (each instruction including
36677  labels must be on a separate line).
36678 \newline
36679
36680 \newline
36681 The optimizer will apply to the rules
36682  one by one from the top in the sequence of their appearance, it will terminate
36683  when all rules are exhausted.
36684  If the 'restart' option is specified, then the optimizer will start matching
36685  the rules again from the top, this option for a rule is expensive (performance)
36686 , it is intended to be used in situations where a transformation will trigger
36687  the same rule again.
36688  An example of this (not a good one, it has side effects) is the following
36689  rule:
36690 \end_layout
36691
36692 \begin_layout Verse
36693
36694 \family typewriter
36695 replace restart { 
36696 \newline
36697 \InsetSpace ~
36698 \InsetSpace ~
36699 pop %1 
36700 \newline
36701 \InsetSpace ~
36702 \InsetSpace ~
36703 push %1 } by { 
36704 \newline
36705 \InsetSpace ~
36706 \InsetSpace ~
36707 ; nop 
36708 \newline
36709 }
36710 \end_layout
36711
36712 \begin_layout Standard
36713 Note that the replace pattern cannot be a blank, but can be a comment line.
36714  Without the 'restart' option only the innermost 'pop' 'push' pair would
36715  be eliminated, i.e.:
36716 \end_layout
36717
36718 \begin_layout Verse
36719
36720 \family typewriter
36721 pop ar1 
36722 \newline
36723 pop ar2 
36724 \newline
36725 push ar2 
36726 \newline
36727 push ar1
36728 \end_layout
36729
36730 \begin_layout Standard
36731 would result in:
36732 \end_layout
36733
36734 \begin_layout Verse
36735
36736 \family typewriter
36737 pop ar1 
36738 \newline
36739 ; nop 
36740 \newline
36741 push ar1
36742 \end_layout
36743
36744 \begin_layout Standard
36745
36746 \emph on
36747 with
36748 \emph default
36749  the restart option the rule will be applied again to the resulting code
36750  and then all the pop-push pairs will be eliminated to yield:
36751 \end_layout
36752
36753 \begin_layout Verse
36754
36755 \family typewriter
36756 ; nop 
36757 \newline
36758 ; nop
36759 \end_layout
36760
36761 \begin_layout Standard
36762 A conditional function can be attached to a rule.
36763  Attaching rules are somewhat more involved, let me illustrate this with
36764  an example.
36765 \end_layout
36766
36767 \begin_layout Verse
36768
36769 \family typewriter
36770 replace { 
36771 \newline
36772 \InsetSpace ~
36773  \InsetSpace ~
36774  \InsetSpace ~
36775 ljmp %5 
36776 \newline
36777 %2:
36778 \newline
36779 } by { 
36780 \newline
36781 \InsetSpace ~
36782  \InsetSpace ~
36783  \InsetSpace ~
36784 sjmp %5 
36785 \newline
36786 %2:
36787 \newline
36788 } if labelInRange
36789 \end_layout
36790
36791 \begin_layout Standard
36792 The optimizer does a look-up of a function name table defined in function
36793  
36794 \emph on
36795 callFuncByName
36796 \emph default
36797  in the source file SDCCpeeph.c, with the name 
36798 \emph on
36799 labelInRange
36800 \emph default
36801 .
36802  If it finds a corresponding entry the function is called.
36803  Note there can be no parameters specified for these functions, in this
36804  case the use of 
36805 \emph on
36806 %5
36807 \emph default
36808  is crucial, since the function 
36809 \emph on
36810 labelInRange
36811 \emph default
36812  expects to find the label in that particular variable (the hash table containin
36813 g the variable bindings is passed as a parameter).
36814  If you want to code more such functions, take a close look at the function
36815  labelInRange and the calling mechanism in source file SDCCpeeph.c.
36816  Currently implemented are 
36817 \emph on
36818 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
36819  24bitMode, portIsDS390, 24bitModeAndPortDS390 
36820 \emph default
36821 and
36822 \emph on
36823  notVolatile
36824 \emph default
36825 .
36826 \end_layout
36827
36828 \begin_layout Standard
36829 I know this whole thing is a little kludgey, but maybe some day we will
36830  have some better means.
36831  If you are looking at this file, you will see the default rules that are
36832  compiled into the compiler, you can add your own rules in the default set
36833  there if you get tired of specifying the -
36834 \begin_inset ERT
36835 status collapsed
36836
36837 \begin_layout Standard
36838
36839
36840 \backslash
36841 /
36842 \end_layout
36843
36844 \end_inset
36845
36846 -peep-file option.
36847 \end_layout
36848
36849 \begin_layout Section
36850 ANSI-Compliance
36851 \begin_inset LatexCommand \index{ANSI-compliance}
36852
36853 \end_inset
36854
36855
36856 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
36857
36858 \end_inset
36859
36860
36861 \end_layout
36862
36863 \begin_layout Standard
36864 The latest publically available version of the standard 
36865 \emph on
36866 ISO/IEC 9899 - Programming languages - C
36867 \emph default
36868  should be available at: 
36869 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
36870
36871 \end_inset
36872
36873 .
36874 \newline
36875
36876 \end_layout
36877
36878 \begin_layout Standard
36879 Deviations from the compliance:
36880 \end_layout
36881
36882 \begin_layout Itemize
36883 functions are not reentrant
36884 \begin_inset LatexCommand \index{reentrant}
36885
36886 \end_inset
36887
36888  unless explicitly declared as such or the 
36889 \series bold
36890 -
36891 \begin_inset ERT
36892 status collapsed
36893
36894 \begin_layout Standard
36895
36896
36897 \backslash
36898 /
36899 \end_layout
36900
36901 \end_inset
36902
36903 -stack-auto
36904 \begin_inset LatexCommand \index{-\/-stack-auto}
36905
36906 \end_inset
36907
36908
36909 \series default
36910  command line option is specified.
36911 \end_layout
36912
36913 \begin_layout Itemize
36914 structures
36915 \begin_inset LatexCommand \index{struct}
36916
36917 \end_inset
36918
36919  and unions
36920 \begin_inset LatexCommand \index{union}
36921
36922 \end_inset
36923
36924  cannot be assigned values directly, cannot be passed as function parameters
36925  or assigned to each other and cannot be a return value
36926 \begin_inset LatexCommand \index{return value}
36927
36928 \end_inset
36929
36930  from a function, e.g.:
36931 \end_layout
36932
36933 \begin_deeper
36934 \begin_layout Verse
36935
36936 \family typewriter
36937 struct s { ...
36938  }; 
36939 \newline
36940 struct s s1, s2; 
36941 \newline
36942 foo() 
36943 \newline
36944
36945 \newline
36946 \InsetSpace ~
36947 \InsetSpace ~
36948 \InsetSpace ~
36949 \InsetSpace ~
36950 ...
36951  
36952 \newline
36953 \InsetSpace ~
36954 \InsetSpace ~
36955 \InsetSpace ~
36956 \InsetSpace ~
36957 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
36958 \newline
36959 \InsetSpace ~
36960 \InsetSpace ~
36961 \InsetSpace ~
36962 \InsetSpace ~
36963 ...
36964  
36965 \newline
36966 }
36967 \newline
36968
36969 \series bold
36970 struct
36971 \series default
36972  s foo1 (
36973 \series bold
36974 struct
36975 \series default
36976  s parms) /* invalid in SDCC although allowed in ANSI */
36977 \newline
36978
36979 \newline
36980 \InsetSpace ~
36981 \InsetSpace ~
36982 \InsetSpace ~
36983 \InsetSpace ~
36984 struct s rets;
36985  
36986 \newline
36987 \InsetSpace ~
36988 \InsetSpace ~
36989 \InsetSpace ~
36990 \InsetSpace ~
36991 ...
36992  
36993 \newline
36994 \InsetSpace ~
36995 \InsetSpace ~
36996 \InsetSpace ~
36997 \InsetSpace ~
36998 return rets; /* is invalid in SDCC although allowed in ANSI */ 
36999 \newline
37000 }
37001 \end_layout
37002
37003 \end_deeper
37004 \begin_layout Itemize
37005 initialization of structure arrays must be fully braced.
37006 \end_layout
37007
37008 \begin_deeper
37009 \begin_layout Verse
37010
37011 \family typewriter
37012 struct s { char x } a[] = {1, 2};\InsetSpace ~
37013 \InsetSpace ~
37014 \InsetSpace ~
37015 \InsetSpace ~
37016 \InsetSpace ~
37017 /* invalid in SDCC */
37018 \newline
37019 struct s { char x
37020  } a[] = {{1}, {2}}; /* OK */
37021 \end_layout
37022
37023 \end_deeper
37024 \begin_layout Itemize
37025 'long long
37026 \begin_inset LatexCommand \index{long long (not supported)}
37027
37028 \end_inset
37029
37030 ' (64 bit integers
37031 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
37032
37033 \end_inset
37034
37035 ) not supported.
37036 \end_layout
37037
37038 \begin_layout Itemize
37039 'double
37040 \begin_inset LatexCommand \index{double (not supported)}
37041
37042 \end_inset
37043
37044 ' precision floating point 
37045 \begin_inset LatexCommand \index{Floating point support}
37046
37047 \end_inset
37048
37049 not supported.
37050 \end_layout
37051
37052 \begin_layout Itemize
37053 Old K&R style
37054 \begin_inset LatexCommand \index{K\&R style}
37055
37056 \end_inset
37057
37058  function declarations are NOT allowed.
37059 \end_layout
37060
37061 \begin_deeper
37062 \begin_layout Verse
37063
37064 \family typewriter
37065 foo(i,j) /* this old style of function declarations */ 
37066 \newline
37067 int i,j; /* is valid
37068  in ANSI but not valid in SDCC */ 
37069 \newline
37070
37071 \newline
37072 \InsetSpace ~
37073 \InsetSpace ~
37074 \InsetSpace ~
37075 \InsetSpace ~
37076 ...
37077  
37078 \newline
37079 }
37080 \end_layout
37081
37082 \end_deeper
37083 \begin_layout Itemize
37084 Most enhancements in C99 are not supported, e.g.:
37085 \end_layout
37086
37087 \begin_deeper
37088 \begin_layout Verse
37089
37090 \family typewriter
37091 for (
37092 \series bold
37093 int
37094 \series default
37095  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
37096 \end_layout
37097
37098 \end_deeper
37099 \begin_layout Itemize
37100 But some have been added recently in SDCC 2.7.0.
37101  They must be considered alpha quality however.
37102 \end_layout
37103
37104 \begin_deeper
37105 \begin_layout Verse
37106
37107 \family typewriter
37108 \series bold
37109 inline
37110 \begin_inset LatexCommand \index{inline (not supported)}
37111
37112 \end_inset
37113
37114
37115 \series default
37116  int increment (int a) { return a+1; } /* inlines the increment without
37117  function call overhead */
37118 \newline
37119 int * 
37120 \series bold
37121 restrict
37122 \begin_inset LatexCommand \index{inline (not supported)}
37123
37124 \end_inset
37125
37126
37127 \series default
37128  p; /* accepted but ignored */
37129 \end_layout
37130
37131 \end_deeper
37132 \begin_layout Itemize
37133 Certain words that are valid identifiers in the standard may be reserved
37134  words in SDCC unless the 
37135 \series bold
37136 -
37137 \begin_inset ERT
37138 status collapsed
37139
37140 \begin_layout Standard
37141
37142
37143 \backslash
37144 /
37145 \end_layout
37146
37147 \end_inset
37148
37149 -std-c89
37150 \begin_inset LatexCommand \index{-\/-std-c89}
37151
37152 \end_inset
37153
37154  
37155 \series default
37156 or
37157 \series bold
37158  -
37159 \begin_inset ERT
37160 status collapsed
37161
37162 \begin_layout Standard
37163
37164
37165 \backslash
37166 /
37167 \end_layout
37168
37169 \end_inset
37170
37171 -std-c99
37172 \begin_inset LatexCommand \index{-\/-std-c99}
37173
37174 \end_inset
37175
37176
37177 \series default
37178  command line options are used.
37179  These may include (depending on the selected processor): 'at', 'banked',
37180  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
37181 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
37182  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
37183  '_naked'.
37184  Compliant equivalents of these keywords are always available in a form
37185  that begin with two underscores
37186 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
37187
37188 \end_inset
37189
37190 , f.e.
37191  '__data' instead of 'data'.
37192 \end_layout
37193
37194 \begin_layout Itemize
37195 Integer promotion of variable arguments is not performed if the argument
37196  is explicitly taypecasted unless the
37197 \series bold
37198  -
37199 \begin_inset ERT
37200 status collapsed
37201
37202 \begin_layout Standard
37203
37204
37205 \backslash
37206 /
37207 \end_layout
37208
37209 \end_inset
37210
37211 -std-c89
37212 \begin_inset LatexCommand \index{-\/-std-c89}
37213
37214 \end_inset
37215
37216  
37217 \series default
37218 or
37219 \series bold
37220  -
37221 \begin_inset ERT
37222 status collapsed
37223
37224 \begin_layout Standard
37225
37226
37227 \backslash
37228 /
37229 \end_layout
37230
37231 \end_inset
37232
37233 -std-c99
37234 \begin_inset LatexCommand \index{-\/-std-c99}
37235
37236 \end_inset
37237
37238
37239 \series default
37240  command line options are used.
37241 \end_layout
37242
37243 \begin_deeper
37244 \begin_layout Verse
37245
37246 \family typewriter
37247 void vararg_func (char *str, ...) { str; }
37248 \newline
37249
37250 \newline
37251 void main (void)
37252 \newline
37253 {
37254 \newline
37255 \InsetSpace ~
37256 \InsetSpace ~
37257 char c = 10;
37258 \newline
37259
37260 \newline
37261 \InsetSpace ~
37262 \InsetSpace ~
37263 /* argument
37264  u is promoted to int before
37265 \newline
37266 \InsetSpace ~
37267 \InsetSpace ~
37268 \InsetSpace ~
37269 * passing to function */
37270 \newline
37271 \InsetSpace ~
37272 \InsetSpace ~
37273 vararg_func ("%c", c);
37274 \newline
37275
37276 \newline
37277 \InsetSpace ~
37278 \InsetSpace ~
37279 /*
37280  argument u is not promoted to int,
37281 \newline
37282 \InsetSpace ~
37283 \InsetSpace ~
37284 \InsetSpace ~
37285 * it is passed as char to function
37286 \newline
37287 \InsetSpace ~
37288 \InsetSpace ~
37289 \InsetSpace ~
37290 * if
37291  --std-cXX is not defined;
37292 \newline
37293 \InsetSpace ~
37294 \InsetSpace ~
37295 \InsetSpace ~
37296 * is promoted to int before passing
37297 \newline
37298 \InsetSpace ~
37299 \InsetSpace ~
37300 \InsetSpace ~
37301 * to function
37302  if --std-cXX is defined */
37303 \newline
37304 \InsetSpace ~
37305 \InsetSpace ~
37306 vararg_func ("%bc", (char)u);
37307 \newline
37308 }
37309 \end_layout
37310
37311 \end_deeper
37312 \begin_layout Section
37313 Cyclomatic Complexity
37314 \begin_inset LatexCommand \index{Cyclomatic complexity}
37315
37316 \end_inset
37317
37318
37319 \end_layout
37320
37321 \begin_layout Standard
37322 Cyclomatic complexity of a function is defined as the number of independent
37323  paths the program can take during execution of the function.
37324  This is an important number since it defines the number test cases you
37325  have to generate to validate the function.
37326  The accepted industry standard for complexity number is 10, if the cyclomatic
37327  complexity reported by SDCC exceeds 10 you should think about simplification
37328  of the function logic.
37329  Note that the complexity level is not related to the number of lines of
37330  code in a function.
37331  Large functions can have low complexity, and small functions can have large
37332  complexity levels.
37333  
37334 \newline
37335
37336 \newline
37337 SDCC uses the following formula to compute the complexity:
37338 \newline
37339
37340 \end_layout
37341
37342 \begin_layout Standard
37343 complexity = (number of edges in control flow graph) - (number of nodes
37344  in control flow graph) + 2;
37345 \newline
37346
37347 \newline
37348 Having said that the industry standard is 10,
37349  you should be aware that in some cases it be may unavoidable to have a
37350  complexity level of less than 10.
37351  For example if you have switch statement with more than 10 case labels,
37352  each case label adds one to the complexity level.
37353  The complexity level is by no means an absolute measure of the algorithmic
37354  complexity of the function, it does however provide a good starting point
37355  for which functions you might look at for further optimization.
37356 \end_layout
37357
37358 \begin_layout Section
37359 Retargetting for other Processors
37360 \end_layout
37361
37362 \begin_layout Standard
37363 The issues for retargetting the compiler are far too numerous to be covered
37364  by this document.
37365  What follows is a brief description of each of the seven phases of the
37366  compiler and its MCU dependency.
37367 \end_layout
37368
37369 \begin_layout Itemize
37370 Parsing the source and building the annotated parse tree.
37371  This phase is largely MCU independent (except for the language extensions).
37372  Syntax & semantic checks are also done in this phase, along with some initial
37373  optimizations like back patching labels and the pattern matching optimizations
37374  like bit-rotation etc.
37375 \end_layout
37376
37377 \begin_layout Itemize
37378 The second phase involves generating an intermediate code which can be easy
37379  manipulated during the later phases.
37380  This phase is entirely MCU independent.
37381  The intermediate code generation assumes the target machine has unlimited
37382  number of registers, and designates them with the name iTemp.
37383  The compiler can be made to dump a human readable form of the code generated
37384  by using the -
37385 \begin_inset ERT
37386 status collapsed
37387
37388 \begin_layout Standard
37389
37390
37391 \backslash
37392 /
37393 \end_layout
37394
37395 \end_inset
37396
37397 -dumpraw option.
37398 \end_layout
37399
37400 \begin_layout Itemize
37401 This phase does the bulk of the standard optimizations and is also MCU independe
37402 nt.
37403  This phase can be broken down into several sub-phases:
37404 \newline
37405
37406 \newline
37407 Break down intermediate
37408  code (iCode) into basic blocks.
37409 \newline
37410 Do control flow & data flow analysis on the
37411  basic blocks.
37412 \newline
37413 Do local common subexpression elimination, then global subexpressio
37414 n elimination
37415 \newline
37416 Dead code elimination
37417 \newline
37418 Loop optimizations
37419 \newline
37420 If loop optimizations
37421  caused any changes then do 'global subexpression elimination' and 'dead
37422  code elimination' again.
37423 \end_layout
37424
37425 \begin_layout Itemize
37426 This phase determines the live-ranges; by live range I mean those iTemp
37427  variables defined by the compiler that still survive after all the optimization
37428 s.
37429  Live range analysis
37430 \begin_inset LatexCommand \index{Live range analysis}
37431
37432 \end_inset
37433
37434  is essential for register allocation, since these computation determines
37435  which of these iTemps will be assigned to registers, and for how long.
37436 \end_layout
37437
37438 \begin_layout Itemize
37439 Phase five is register allocation.
37440  There are two parts to this process.
37441 \newline
37442
37443 \newline
37444 The first part I call 'register packing'
37445  (for lack of a better term).
37446  In this case several MCU specific expression folding is done to reduce
37447  register pressure.
37448 \newline
37449
37450 \newline
37451 The second part is more MCU independent and deals with
37452  allocating registers to the remaining live ranges.
37453  A lot of MCU specific code does creep into this phase because of the limited
37454  number of index registers available in the 8051.
37455 \end_layout
37456
37457 \begin_layout Itemize
37458 The Code generation phase is (unhappily), entirely MCU dependent and very
37459  little (if any at all) of this code can be reused for other MCU.
37460  However the scheme for allocating a homogenized assembler operand for each
37461  iCode operand may be reused.
37462 \end_layout
37463
37464 \begin_layout Itemize
37465 As mentioned in the optimization section the peep-hole optimizer is rule
37466  based system, which can reprogrammed for other MCUs.
37467 \end_layout
37468
37469 \begin_layout Standard
37470 More information is available on SDCC Wiki
37471 \begin_inset LatexCommand \index{wiki}
37472
37473 \end_inset
37474
37475  (preliminary link 
37476 \begin_inset LatexCommand \url{http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting}
37477
37478 \end_inset
37479
37480 ) and in the thread 
37481 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
37482
37483 \end_inset
37484
37485  .
37486 \end_layout
37487
37488 \begin_layout Chapter
37489 Compiler internals
37490 \begin_inset LatexCommand \index{Compiler internals}
37491
37492 \end_inset
37493
37494
37495 \end_layout
37496
37497 \begin_layout Section
37498 The anatomy of the compiler
37499 \begin_inset LatexCommand \label{sub:The-anatomy-of}
37500
37501 \end_inset
37502
37503
37504 \end_layout
37505
37506 \begin_layout Standard
37507
37508 \shape italic
37509 This is an excerpt from an article published in Circuit Cellar Magazine
37510  in 
37511 \series bold
37512 August 2000
37513 \series default
37514 .
37515  It's a little outdated (the compiler is much more efficient now and user/develo
37516 per friendly), but pretty well exposes the guts of it all.
37517 \shape default
37518
37519 \newline
37520
37521 \newline
37522 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
37523  It is fairly easy to retarget for other 8-bit MCU.
37524  Here we take a look at some of the internals of the compiler.
37525  
37526 \end_layout
37527
37528 \begin_layout Paragraph*
37529 Parsing
37530 \begin_inset LatexCommand \index{Parsing}
37531
37532 \end_inset
37533
37534  
37535 \end_layout
37536
37537 \begin_layout Standard
37538 Parsing the input source file and creating an AST (Annotated Syntax Tree
37539 \begin_inset LatexCommand \index{Annotated syntax tree}
37540
37541 \end_inset
37542
37543 ).
37544  This phase also involves propagating types (annotating each node of the
37545  parse tree with type information) and semantic analysis.
37546  There are some MCU specific parsing rules.
37547  For example the storage classes, the extended storage classes are MCU specific
37548  while there may be a xdata storage class for 8051 there is no such storage
37549  class for z80 or Atmel AVR.
37550  SDCC allows MCU specific storage class extensions, i.e.
37551  xdata will be treated as a storage class specifier when parsing 8051 C
37552  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
37553  C code.
37554 \end_layout
37555
37556 \begin_layout Paragraph*
37557 Generating iCode
37558 \begin_inset LatexCommand \index{iCode}
37559
37560 \end_inset
37561
37562
37563 \end_layout
37564
37565 \begin_layout Standard
37566 Intermediate code generation.
37567  In this phase the AST is broken down into three-operand form (iCode).
37568  These three operand forms are represented as doubly linked lists.
37569  ICode is the term given to the intermediate form generated by the compiler.
37570  ICode example section shows some examples of iCode generated for some simple
37571  C source functions.
37572 \end_layout
37573
37574 \begin_layout Paragraph*
37575 Optimizations
37576 \begin_inset LatexCommand \index{Optimizations}
37577
37578 \end_inset
37579
37580 .
37581 \end_layout
37582
37583 \begin_layout Standard
37584 Bulk of the target independent optimizations is performed in this phase.
37585  The optimizations include constant propagation, common sub-expression eliminati
37586 on, loop invariant code movement, strength reduction of loop induction variables
37587  and dead-code elimination.
37588 \end_layout
37589
37590 \begin_layout Paragraph*
37591 Live range analysis
37592 \begin_inset LatexCommand \index{Live range analysis}
37593
37594 \end_inset
37595
37596
37597 \end_layout
37598
37599 \begin_layout Standard
37600 During intermediate code generation phase, the compiler assumes the target
37601  machine has infinite number of registers and generates a lot of temporary
37602  variables.
37603  The live range computation determines the lifetime of each of these compiler-ge
37604 nerated temporaries.
37605  A picture speaks a thousand words.
37606  ICode example sections show the live range annotations for each of the
37607  operand.
37608  It is important to note here, each iCode is assigned a number in the order
37609  of its execution in the function.
37610  The live ranges are computed in terms of these numbers.
37611  The from number is the number of the iCode which first defines the operand
37612  and the to number signifies the iCode which uses this operand last.
37613 \end_layout
37614
37615 \begin_layout Paragraph*
37616 Register Allocation
37617 \begin_inset LatexCommand \index{Register allocation}
37618
37619 \end_inset
37620
37621
37622 \end_layout
37623
37624 \begin_layout Standard
37625 The register allocation determines the type and number of registers needed
37626  by each operand.
37627  In most MCUs only a few registers can be used for indirect addressing.
37628  In case of 8051 for example the registers R0 & R1 can be used to indirectly
37629  address the internal ram and DPTR to indirectly address the external ram.
37630  The compiler will try to allocate the appropriate register to pointer variables
37631  if it can.
37632  ICode example section shows the operands annotated with the registers assigned
37633  to them.
37634  The compiler will try to keep operands in registers as much as possible;
37635  there are several schemes the compiler uses to do achieve this.
37636  When the compiler runs out of registers the compiler will check to see
37637  if there are any live operands which is not used or defined in the current
37638  basic block being processed, if there are any found then it will push that
37639  operand and use the registers in this block, the operand will then be popped
37640  at the end of the basic block.
37641  
37642 \end_layout
37643
37644 \begin_layout Standard
37645 There are other MCU specific considerations in this phase.
37646  Some MCUs have an accumulator; very short-lived operands could be assigned
37647  to the accumulator instead of a general-purpose register.
37648 \end_layout
37649
37650 \begin_layout Paragraph*
37651 Code generation
37652 \end_layout
37653
37654 \begin_layout Standard
37655 Figure II gives a table of iCode
37656 \begin_inset LatexCommand \index{iCode}
37657
37658 \end_inset
37659
37660  operations supported by the compiler.
37661  The code generation involves translating these operations into corresponding
37662  assembly code for the processor.
37663  This sounds overly simple but that is the essence of code generation.
37664  Some of the iCode operations are generated on a MCU specific manner for
37665  example, the z80 port does not use registers to pass parameters so the
37666  SEND and RECV iCode operations will not be generated, and it also does
37667  not support JUMPTABLES.
37668  
37669 \newline
37670
37671 \end_layout
37672
37673 \begin_layout Standard
37674
37675 \size footnotesize
37676 Figure II 
37677 \begin_inset Tabular
37678 <lyxtabular version="3" rows="39" columns="4">
37679 <features islongtable="true" headBottomDL="true">
37680 <column alignment="block" valignment="top" leftline="true" width="13col%">
37681 <column alignment="left" valignment="top" leftline="true" width="13col%">
37682 <column alignment="block" valignment="top" leftline="true" width="22col%">
37683 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
37684 <row topline="true" bottomline="true" endhead="true">
37685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37686 \begin_inset Text
37687
37688 \begin_layout Standard
37689
37690 \series bold
37691 iCode
37692 \series default
37693
37694 \begin_inset LatexCommand \index{iCode}
37695
37696 \end_inset
37697
37698
37699 \end_layout
37700
37701 \end_inset
37702 </cell>
37703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37704 \begin_inset Text
37705
37706 \begin_layout Standard
37707
37708 \series bold
37709 Operands
37710 \end_layout
37711
37712 \end_inset
37713 </cell>
37714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37715 \begin_inset Text
37716
37717 \begin_layout Standard
37718
37719 \series bold
37720 Description
37721 \end_layout
37722
37723 \end_inset
37724 </cell>
37725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37726 \begin_inset Text
37727
37728 \begin_layout Standard
37729
37730 \series bold
37731 C Equivalent
37732 \end_layout
37733
37734 \end_inset
37735 </cell>
37736 </row>
37737 <row topline="true">
37738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37739 \begin_inset Text
37740
37741 \begin_layout Standard
37742
37743 \size footnotesize
37744 '!'
37745 \end_layout
37746
37747 \end_inset
37748 </cell>
37749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37750 \begin_inset Text
37751
37752 \begin_layout Standard
37753
37754 \size footnotesize
37755 IC_LEFT() IC_RESULT()
37756 \end_layout
37757
37758 \end_inset
37759 </cell>
37760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37761 \begin_inset Text
37762
37763 \begin_layout Standard
37764
37765 \size footnotesize
37766 NOT operation 
37767 \end_layout
37768
37769 \end_inset
37770 </cell>
37771 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37772 \begin_inset Text
37773
37774 \begin_layout Standard
37775
37776 \size footnotesize
37777 IC_RESULT = ! IC_LEFT;
37778 \end_layout
37779
37780 \end_inset
37781 </cell>
37782 </row>
37783 <row topline="true">
37784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37785 \begin_inset Text
37786
37787 \begin_layout Standard
37788
37789 \size footnotesize
37790 '~'
37791 \end_layout
37792
37793 \end_inset
37794 </cell>
37795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37796 \begin_inset Text
37797
37798 \begin_layout Standard
37799
37800 \size footnotesize
37801 IC_LEFT() IC_RESULT()
37802 \end_layout
37803
37804 \end_inset
37805 </cell>
37806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37807 \begin_inset Text
37808
37809 \begin_layout Standard
37810
37811 \size footnotesize
37812 Bitwise complement of 
37813 \end_layout
37814
37815 \end_inset
37816 </cell>
37817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37818 \begin_inset Text
37819
37820 \begin_layout Standard
37821
37822 \size footnotesize
37823 IC_RESULT = ~IC_LEFT;
37824 \end_layout
37825
37826 \end_inset
37827 </cell>
37828 </row>
37829 <row topline="true">
37830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37831 \begin_inset Text
37832
37833 \begin_layout Standard
37834
37835 \size footnotesize
37836 RRC
37837 \end_layout
37838
37839 \end_inset
37840 </cell>
37841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37842 \begin_inset Text
37843
37844 \begin_layout Standard
37845
37846 \size footnotesize
37847 IC_LEFT() IC_RESULT()
37848 \end_layout
37849
37850 \end_inset
37851 </cell>
37852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37853 \begin_inset Text
37854
37855 \begin_layout Standard
37856
37857 \size footnotesize
37858 Rotate right with carry
37859 \end_layout
37860
37861 \end_inset
37862 </cell>
37863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37864 \begin_inset Text
37865
37866 \begin_layout Standard
37867
37868 \size footnotesize
37869 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
37870 \end_layout
37871
37872 \end_inset
37873 </cell>
37874 </row>
37875 <row topline="true">
37876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37877 \begin_inset Text
37878
37879 \begin_layout Standard
37880
37881 \size footnotesize
37882 RLC
37883 \end_layout
37884
37885 \end_inset
37886 </cell>
37887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37888 \begin_inset Text
37889
37890 \begin_layout Standard
37891
37892 \size footnotesize
37893 IC_LEFT() IC_RESULT()
37894 \end_layout
37895
37896 \end_inset
37897 </cell>
37898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37899 \begin_inset Text
37900
37901 \begin_layout Standard
37902
37903 \size footnotesize
37904 Rotate left with carry
37905 \end_layout
37906
37907 \end_inset
37908 </cell>
37909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37910 \begin_inset Text
37911
37912 \begin_layout Standard
37913
37914 \size footnotesize
37915 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
37916 \end_layout
37917
37918 \end_inset
37919 </cell>
37920 </row>
37921 <row topline="true">
37922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37923 \begin_inset Text
37924
37925 \begin_layout Standard
37926
37927 \size footnotesize
37928 GETHBIT
37929 \end_layout
37930
37931 \end_inset
37932 </cell>
37933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37934 \begin_inset Text
37935
37936 \begin_layout Standard
37937
37938 \size footnotesize
37939 IC_LEFT() IC_RESULT()
37940 \end_layout
37941
37942 \end_inset
37943 </cell>
37944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37945 \begin_inset Text
37946
37947 \begin_layout Standard
37948
37949 \size footnotesize
37950 Get the highest order bit of IC_LEFT
37951 \end_layout
37952
37953 \end_inset
37954 </cell>
37955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37956 \begin_inset Text
37957
37958 \begin_layout Standard
37959
37960 \size footnotesize
37961 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
37962 \end_layout
37963
37964 \end_inset
37965 </cell>
37966 </row>
37967 <row topline="true">
37968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37969 \begin_inset Text
37970
37971 \begin_layout Standard
37972
37973 \size footnotesize
37974 UNARYMINUS
37975 \end_layout
37976
37977 \end_inset
37978 </cell>
37979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37980 \begin_inset Text
37981
37982 \begin_layout Standard
37983
37984 \size footnotesize
37985 IC_LEFT() IC_RESULT()
37986 \end_layout
37987
37988 \end_inset
37989 </cell>
37990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37991 \begin_inset Text
37992
37993 \begin_layout Standard
37994
37995 \size footnotesize
37996 Unary minus
37997 \end_layout
37998
37999 \end_inset
38000 </cell>
38001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38002 \begin_inset Text
38003
38004 \begin_layout Standard
38005
38006 \size footnotesize
38007 IC_RESULT = - IC_LEFT;
38008 \end_layout
38009
38010 \end_inset
38011 </cell>
38012 </row>
38013 <row topline="true">
38014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38015 \begin_inset Text
38016
38017 \begin_layout Standard
38018
38019 \size footnotesize
38020 IPUSH
38021 \end_layout
38022
38023 \end_inset
38024 </cell>
38025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38026 \begin_inset Text
38027
38028 \begin_layout Standard
38029
38030 \size footnotesize
38031 IC_LEFT()
38032 \end_layout
38033
38034 \end_inset
38035 </cell>
38036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38037 \begin_inset Text
38038
38039 \begin_layout Standard
38040
38041 \size footnotesize
38042 Push the operand into stack
38043 \end_layout
38044
38045 \end_inset
38046 </cell>
38047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38048 \begin_inset Text
38049
38050 \begin_layout Standard
38051
38052 \size footnotesize
38053 NONE
38054 \end_layout
38055
38056 \end_inset
38057 </cell>
38058 </row>
38059 <row topline="true">
38060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38061 \begin_inset Text
38062
38063 \begin_layout Standard
38064
38065 \size footnotesize
38066 IPOP
38067 \end_layout
38068
38069 \end_inset
38070 </cell>
38071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38072 \begin_inset Text
38073
38074 \begin_layout Standard
38075
38076 \size footnotesize
38077 IC_LEFT()
38078 \end_layout
38079
38080 \end_inset
38081 </cell>
38082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38083 \begin_inset Text
38084
38085 \begin_layout Standard
38086
38087 \size footnotesize
38088 Pop the operand from the stack 
38089 \end_layout
38090
38091 \end_inset
38092 </cell>
38093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38094 \begin_inset Text
38095
38096 \begin_layout Standard
38097
38098 \size footnotesize
38099 NONE
38100 \end_layout
38101
38102 \end_inset
38103 </cell>
38104 </row>
38105 <row topline="true">
38106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38107 \begin_inset Text
38108
38109 \begin_layout Standard
38110
38111 \size footnotesize
38112 CALL
38113 \end_layout
38114
38115 \end_inset
38116 </cell>
38117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38118 \begin_inset Text
38119
38120 \begin_layout Standard
38121
38122 \size footnotesize
38123 IC_LEFT() IC_RESULT()
38124 \end_layout
38125
38126 \end_inset
38127 </cell>
38128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38129 \begin_inset Text
38130
38131 \begin_layout Standard
38132
38133 \size footnotesize
38134 Call the function represented by IC_LEFT 
38135 \end_layout
38136
38137 \end_inset
38138 </cell>
38139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38140 \begin_inset Text
38141
38142 \begin_layout Standard
38143
38144 \size footnotesize
38145 IC_RESULT = IC_LEFT();
38146 \end_layout
38147
38148 \end_inset
38149 </cell>
38150 </row>
38151 <row topline="true">
38152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38153 \begin_inset Text
38154
38155 \begin_layout Standard
38156
38157 \size footnotesize
38158 PCALL
38159 \end_layout
38160
38161 \end_inset
38162 </cell>
38163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38164 \begin_inset Text
38165
38166 \begin_layout Standard
38167
38168 \size footnotesize
38169 IC_LEFT() IC_RESULT()
38170 \end_layout
38171
38172 \end_inset
38173 </cell>
38174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38175 \begin_inset Text
38176
38177 \begin_layout Standard
38178
38179 \size footnotesize
38180 Call via function pointer
38181 \end_layout
38182
38183 \end_inset
38184 </cell>
38185 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38186 \begin_inset Text
38187
38188 \begin_layout Standard
38189
38190 \size footnotesize
38191 IC_RESULT = (*IC_LEFT)();
38192 \end_layout
38193
38194 \end_inset
38195 </cell>
38196 </row>
38197 <row topline="true">
38198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38199 \begin_inset Text
38200
38201 \begin_layout Standard
38202
38203 \size footnotesize
38204 RETURN
38205 \end_layout
38206
38207 \end_inset
38208 </cell>
38209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38210 \begin_inset Text
38211
38212 \begin_layout Standard
38213
38214 \size footnotesize
38215 IC_LEFT()
38216 \end_layout
38217
38218 \end_inset
38219 </cell>
38220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38221 \begin_inset Text
38222
38223 \begin_layout Standard
38224
38225 \size footnotesize
38226 Return the value in operand IC_LEFT 
38227 \end_layout
38228
38229 \end_inset
38230 </cell>
38231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38232 \begin_inset Text
38233
38234 \begin_layout Standard
38235
38236 \size footnotesize
38237 return IC_LEFT;
38238 \end_layout
38239
38240 \end_inset
38241 </cell>
38242 </row>
38243 <row topline="true">
38244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38245 \begin_inset Text
38246
38247 \begin_layout Standard
38248
38249 \size footnotesize
38250 LABEL
38251 \end_layout
38252
38253 \end_inset
38254 </cell>
38255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38256 \begin_inset Text
38257
38258 \begin_layout Standard
38259
38260 \size footnotesize
38261 IC_LABEL() 
38262 \end_layout
38263
38264 \end_inset
38265 </cell>
38266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38267 \begin_inset Text
38268
38269 \begin_layout Standard
38270
38271 \size footnotesize
38272 Label
38273 \end_layout
38274
38275 \end_inset
38276 </cell>
38277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38278 \begin_inset Text
38279
38280 \begin_layout Standard
38281
38282 \size footnotesize
38283 IC_LABEL:
38284 \end_layout
38285
38286 \end_inset
38287 </cell>
38288 </row>
38289 <row topline="true">
38290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38291 \begin_inset Text
38292
38293 \begin_layout Standard
38294
38295 \size footnotesize
38296 GOTO
38297 \end_layout
38298
38299 \end_inset
38300 </cell>
38301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38302 \begin_inset Text
38303
38304 \begin_layout Standard
38305
38306 \size footnotesize
38307 IC_LABEL() 
38308 \end_layout
38309
38310 \end_inset
38311 </cell>
38312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38313 \begin_inset Text
38314
38315 \begin_layout Standard
38316
38317 \size footnotesize
38318 Goto label
38319 \end_layout
38320
38321 \end_inset
38322 </cell>
38323 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38324 \begin_inset Text
38325
38326 \begin_layout Standard
38327
38328 \size footnotesize
38329 goto IC_LABEL();
38330 \end_layout
38331
38332 \end_inset
38333 </cell>
38334 </row>
38335 <row topline="true">
38336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38337 \begin_inset Text
38338
38339 \begin_layout Standard
38340
38341 \size footnotesize
38342 '+'
38343 \end_layout
38344
38345 \end_inset
38346 </cell>
38347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38348 \begin_inset Text
38349
38350 \begin_layout Standard
38351
38352 \size footnotesize
38353 IC_LEFT() IC_RIGHT() IC_RESULT()
38354 \end_layout
38355
38356 \end_inset
38357 </cell>
38358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38359 \begin_inset Text
38360
38361 \begin_layout Standard
38362
38363 \size footnotesize
38364 Addition
38365 \end_layout
38366
38367 \end_inset
38368 </cell>
38369 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38370 \begin_inset Text
38371
38372 \begin_layout Standard
38373
38374 \size footnotesize
38375 IC_RESULT = IC_LEFT + IC_RIGHT
38376 \end_layout
38377
38378 \end_inset
38379 </cell>
38380 </row>
38381 <row topline="true">
38382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38383 \begin_inset Text
38384
38385 \begin_layout Standard
38386
38387 \size footnotesize
38388 '-'
38389 \end_layout
38390
38391 \end_inset
38392 </cell>
38393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38394 \begin_inset Text
38395
38396 \begin_layout Standard
38397
38398 \size footnotesize
38399 IC_LEFT() IC_RIGHT() IC_RESULT()
38400 \end_layout
38401
38402 \end_inset
38403 </cell>
38404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38405 \begin_inset Text
38406
38407 \begin_layout Standard
38408
38409 \size footnotesize
38410 Subtraction
38411 \end_layout
38412
38413 \end_inset
38414 </cell>
38415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38416 \begin_inset Text
38417
38418 \begin_layout Standard
38419
38420 \size footnotesize
38421 IC_RESULT = IC_LEFT - IC_RIGHT 
38422 \end_layout
38423
38424 \end_inset
38425 </cell>
38426 </row>
38427 <row topline="true">
38428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38429 \begin_inset Text
38430
38431 \begin_layout Standard
38432
38433 \size footnotesize
38434 '*'
38435 \end_layout
38436
38437 \end_inset
38438 </cell>
38439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38440 \begin_inset Text
38441
38442 \begin_layout Standard
38443
38444 \size footnotesize
38445 IC_LEFT() IC_RIGHT() IC_RESULT()
38446 \end_layout
38447
38448 \end_inset
38449 </cell>
38450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38451 \begin_inset Text
38452
38453 \begin_layout Standard
38454
38455 \size footnotesize
38456 Multiplication 
38457 \end_layout
38458
38459 \end_inset
38460 </cell>
38461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38462 \begin_inset Text
38463
38464 \begin_layout Standard
38465
38466 \size footnotesize
38467 IC_RESULT = IC_LEFT * IC_RIGHT;
38468 \end_layout
38469
38470 \end_inset
38471 </cell>
38472 </row>
38473 <row topline="true">
38474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38475 \begin_inset Text
38476
38477 \begin_layout Standard
38478
38479 \size footnotesize
38480 '/'
38481 \end_layout
38482
38483 \end_inset
38484 </cell>
38485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38486 \begin_inset Text
38487
38488 \begin_layout Standard
38489
38490 \size footnotesize
38491 IC_LEFT() IC_RIGHT() IC_RESULT()
38492 \end_layout
38493
38494 \end_inset
38495 </cell>
38496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38497 \begin_inset Text
38498
38499 \begin_layout Standard
38500
38501 \size footnotesize
38502 Division
38503 \end_layout
38504
38505 \end_inset
38506 </cell>
38507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38508 \begin_inset Text
38509
38510 \begin_layout Standard
38511
38512 \size footnotesize
38513 IC_RESULT = IC_LEFT / IC_RIGHT;
38514 \end_layout
38515
38516 \end_inset
38517 </cell>
38518 </row>
38519 <row topline="true">
38520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38521 \begin_inset Text
38522
38523 \begin_layout Standard
38524
38525 \size footnotesize
38526 '%'
38527 \end_layout
38528
38529 \end_inset
38530 </cell>
38531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38532 \begin_inset Text
38533
38534 \begin_layout Standard
38535
38536 \size footnotesize
38537 IC_LEFT() IC_RIGHT() IC_RESULT()
38538 \end_layout
38539
38540 \end_inset
38541 </cell>
38542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38543 \begin_inset Text
38544
38545 \begin_layout Standard
38546
38547 \size footnotesize
38548 Modulus
38549 \end_layout
38550
38551 \end_inset
38552 </cell>
38553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38554 \begin_inset Text
38555
38556 \begin_layout Standard
38557
38558 \size footnotesize
38559 IC_RESULT = IC_LEFT % IC_RIGHT;
38560 \end_layout
38561
38562 \end_inset
38563 </cell>
38564 </row>
38565 <row topline="true">
38566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38567 \begin_inset Text
38568
38569 \begin_layout Standard
38570
38571 \size footnotesize
38572 '<'
38573 \end_layout
38574
38575 \end_inset
38576 </cell>
38577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38578 \begin_inset Text
38579
38580 \begin_layout Standard
38581
38582 \size footnotesize
38583 IC_LEFT() IC_RIGHT() IC_RESULT()
38584 \end_layout
38585
38586 \end_inset
38587 </cell>
38588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38589 \begin_inset Text
38590
38591 \begin_layout Standard
38592
38593 \size footnotesize
38594 Less than
38595 \end_layout
38596
38597 \end_inset
38598 </cell>
38599 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38600 \begin_inset Text
38601
38602 \begin_layout Standard
38603
38604 \size footnotesize
38605 IC_RESULT = IC_LEFT < IC_RIGHT;
38606 \end_layout
38607
38608 \end_inset
38609 </cell>
38610 </row>
38611 <row topline="true">
38612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38613 \begin_inset Text
38614
38615 \begin_layout Standard
38616
38617 \size footnotesize
38618 '>'
38619 \end_layout
38620
38621 \end_inset
38622 </cell>
38623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38624 \begin_inset Text
38625
38626 \begin_layout Standard
38627
38628 \size footnotesize
38629 IC_LEFT() IC_RIGHT() IC_RESULT()
38630 \end_layout
38631
38632 \end_inset
38633 </cell>
38634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38635 \begin_inset Text
38636
38637 \begin_layout Standard
38638
38639 \size footnotesize
38640 Greater than 
38641 \end_layout
38642
38643 \end_inset
38644 </cell>
38645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38646 \begin_inset Text
38647
38648 \begin_layout Standard
38649
38650 \size footnotesize
38651 IC_RESULT = IC_LEFT > IC_RIGHT;
38652 \end_layout
38653
38654 \end_inset
38655 </cell>
38656 </row>
38657 <row topline="true">
38658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38659 \begin_inset Text
38660
38661 \begin_layout Standard
38662
38663 \size footnotesize
38664 EQ_OP
38665 \end_layout
38666
38667 \end_inset
38668 </cell>
38669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38670 \begin_inset Text
38671
38672 \begin_layout Standard
38673
38674 \size footnotesize
38675 IC_LEFT() IC_RIGHT() IC_RESULT()
38676 \end_layout
38677
38678 \end_inset
38679 </cell>
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 Equal to 
38687 \end_layout
38688
38689 \end_inset
38690 </cell>
38691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38692 \begin_inset Text
38693
38694 \begin_layout Standard
38695
38696 \size footnotesize
38697 IC_RESULT = IC_LEFT == IC_RIGHT;
38698 \end_layout
38699
38700 \end_inset
38701 </cell>
38702 </row>
38703 <row topline="true">
38704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38705 \begin_inset Text
38706
38707 \begin_layout Standard
38708
38709 \size footnotesize
38710 AND_OP
38711 \end_layout
38712
38713 \end_inset
38714 </cell>
38715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38716 \begin_inset Text
38717
38718 \begin_layout Standard
38719
38720 \size footnotesize
38721 IC_LEFT() IC_RIGHT() IC_RESULT() 
38722 \end_layout
38723
38724 \end_inset
38725 </cell>
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 Logical and operation
38733 \end_layout
38734
38735 \end_inset
38736 </cell>
38737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38738 \begin_inset Text
38739
38740 \begin_layout Standard
38741
38742 \size footnotesize
38743 IC_RESULT = IC_LEFT && IC_RIGHT; 
38744 \end_layout
38745
38746 \end_inset
38747 </cell>
38748 </row>
38749 <row topline="true">
38750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38751 \begin_inset Text
38752
38753 \begin_layout Standard
38754
38755 \size footnotesize
38756 OR_OP
38757 \end_layout
38758
38759 \end_inset
38760 </cell>
38761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38762 \begin_inset Text
38763
38764 \begin_layout Standard
38765
38766 \size footnotesize
38767 IC_LEFT() IC_RIGHT() IC_RESULT() 
38768 \end_layout
38769
38770 \end_inset
38771 </cell>
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 Logical or operation 
38779 \end_layout
38780
38781 \end_inset
38782 </cell>
38783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38784 \begin_inset Text
38785
38786 \begin_layout Standard
38787
38788 \size footnotesize
38789 IC_RESULT = IC_LEFT || IC_RIGHT; 
38790 \end_layout
38791
38792 \end_inset
38793 </cell>
38794 </row>
38795 <row topline="true">
38796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38797 \begin_inset Text
38798
38799 \begin_layout Standard
38800
38801 \size footnotesize
38802 '^'
38803 \end_layout
38804
38805 \end_inset
38806 </cell>
38807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38808 \begin_inset Text
38809
38810 \begin_layout Standard
38811
38812 \size footnotesize
38813 IC_LEFT() IC_RIGHT() IC_RESULT() 
38814 \end_layout
38815
38816 \end_inset
38817 </cell>
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 Exclusive OR
38825 \end_layout
38826
38827 \end_inset
38828 </cell>
38829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38830 \begin_inset Text
38831
38832 \begin_layout Standard
38833
38834 \size footnotesize
38835 IC_RESULT = IC_LEFT ^ IC_RIGHT;
38836 \end_layout
38837
38838 \end_inset
38839 </cell>
38840 </row>
38841 <row topline="true">
38842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38843 \begin_inset Text
38844
38845 \begin_layout Standard
38846
38847 \size footnotesize
38848 '|'
38849 \end_layout
38850
38851 \end_inset
38852 </cell>
38853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38854 \begin_inset Text
38855
38856 \begin_layout Standard
38857
38858 \size footnotesize
38859 IC_LEFT() IC_RIGHT() IC_RESULT() 
38860 \end_layout
38861
38862 \end_inset
38863 </cell>
38864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38865 \begin_inset Text
38866
38867 \begin_layout Standard
38868
38869 \size footnotesize
38870 Bitwise OR 
38871 \end_layout
38872
38873 \end_inset
38874 </cell>
38875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38876 \begin_inset Text
38877
38878 \begin_layout Standard
38879
38880 \size footnotesize
38881 IC_RESULT = IC_LEFT | IC_RIGHT;
38882 \end_layout
38883
38884 \end_inset
38885 </cell>
38886 </row>
38887 <row topline="true">
38888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38889 \begin_inset Text
38890
38891 \begin_layout Standard
38892
38893 \size footnotesize
38894 BITWISEAND
38895 \end_layout
38896
38897 \end_inset
38898 </cell>
38899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38900 \begin_inset Text
38901
38902 \begin_layout Standard
38903
38904 \size footnotesize
38905 IC_LEFT() IC_RIGHT() IC_RESULT()
38906 \end_layout
38907
38908 \end_inset
38909 </cell>
38910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38911 \begin_inset Text
38912
38913 \begin_layout Standard
38914
38915 \size footnotesize
38916 Bitwise AND 
38917 \end_layout
38918
38919 \end_inset
38920 </cell>
38921 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38922 \begin_inset Text
38923
38924 \begin_layout Standard
38925
38926 \size footnotesize
38927 IC_RESULT = IC_LEFT & IC_RIGHT;
38928 \end_layout
38929
38930 \end_inset
38931 </cell>
38932 </row>
38933 <row topline="true">
38934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38935 \begin_inset Text
38936
38937 \begin_layout Standard
38938
38939 \size footnotesize
38940 LEFT_OP
38941 \end_layout
38942
38943 \end_inset
38944 </cell>
38945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38946 \begin_inset Text
38947
38948 \begin_layout Standard
38949
38950 \size footnotesize
38951 IC_LEFT() IC_RIGHT() IC_RESULT()
38952 \end_layout
38953
38954 \end_inset
38955 </cell>
38956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38957 \begin_inset Text
38958
38959 \begin_layout Standard
38960
38961 \size footnotesize
38962 Left shift 
38963 \end_layout
38964
38965 \end_inset
38966 </cell>
38967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38968 \begin_inset Text
38969
38970 \begin_layout Standard
38971
38972 \size footnotesize
38973 IC_RESULT = IC_LEFT << IC_RIGHT 
38974 \end_layout
38975
38976 \end_inset
38977 </cell>
38978 </row>
38979 <row topline="true">
38980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38981 \begin_inset Text
38982
38983 \begin_layout Standard
38984
38985 \size footnotesize
38986 RIGHT_OP
38987 \end_layout
38988
38989 \end_inset
38990 </cell>
38991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38992 \begin_inset Text
38993
38994 \begin_layout Standard
38995
38996 \size footnotesize
38997 IC_LEFT() IC_RIGHT() IC_RESULT()
38998 \end_layout
38999
39000 \end_inset
39001 </cell>
39002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39003 \begin_inset Text
39004
39005 \begin_layout Standard
39006
39007 \size footnotesize
39008 Right shift
39009 \end_layout
39010
39011 \end_inset
39012 </cell>
39013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39014 \begin_inset Text
39015
39016 \begin_layout Standard
39017
39018 \size footnotesize
39019 IC_RESULT = IC_LEFT >> IC_RIGHT 
39020 \end_layout
39021
39022 \end_inset
39023 </cell>
39024 </row>
39025 <row topline="true">
39026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39027 \begin_inset Text
39028
39029 \begin_layout Standard
39030
39031 \size footnotesize
39032 GET_VALUE_
39033 \newline
39034 AT_ ADDRESS
39035 \end_layout
39036
39037 \end_inset
39038 </cell>
39039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39040 \begin_inset Text
39041
39042 \begin_layout Standard
39043
39044 \size footnotesize
39045 IC_LEFT() IC_RESULT()
39046 \end_layout
39047
39048 \end_inset
39049 </cell>
39050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39051 \begin_inset Text
39052
39053 \begin_layout Standard
39054
39055 \size footnotesize
39056 Indirect fetch 
39057 \end_layout
39058
39059 \end_inset
39060 </cell>
39061 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39062 \begin_inset Text
39063
39064 \begin_layout Standard
39065
39066 \size footnotesize
39067 IC_RESULT = (*IC_LEFT);
39068 \end_layout
39069
39070 \end_inset
39071 </cell>
39072 </row>
39073 <row topline="true">
39074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39075 \begin_inset Text
39076
39077 \begin_layout Standard
39078
39079 \size footnotesize
39080 POINTER_SET
39081 \end_layout
39082
39083 \end_inset
39084 </cell>
39085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39086 \begin_inset Text
39087
39088 \begin_layout Standard
39089
39090 \size footnotesize
39091 IC_RIGHT() IC_RESULT() 
39092 \end_layout
39093
39094 \end_inset
39095 </cell>
39096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39097 \begin_inset Text
39098
39099 \begin_layout Standard
39100
39101 \size footnotesize
39102 Indirect set
39103 \end_layout
39104
39105 \end_inset
39106 </cell>
39107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39108 \begin_inset Text
39109
39110 \begin_layout Standard
39111
39112 \size footnotesize
39113 (*IC_RESULT) = IC_RIGHT;
39114 \end_layout
39115
39116 \end_inset
39117 </cell>
39118 </row>
39119 <row topline="true">
39120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39121 \begin_inset Text
39122
39123 \begin_layout Standard
39124
39125 \size footnotesize
39126 '='
39127 \end_layout
39128
39129 \end_inset
39130 </cell>
39131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39132 \begin_inset Text
39133
39134 \begin_layout Standard
39135
39136 \size footnotesize
39137 IC_RIGHT() IC_RESULT()
39138 \end_layout
39139
39140 \end_inset
39141 </cell>
39142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39143 \begin_inset Text
39144
39145 \begin_layout Standard
39146
39147 \size footnotesize
39148 Assignment
39149 \end_layout
39150
39151 \end_inset
39152 </cell>
39153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39154 \begin_inset Text
39155
39156 \begin_layout Standard
39157
39158 \size footnotesize
39159 IC_RESULT = IC_RIGHT;
39160 \end_layout
39161
39162 \end_inset
39163 </cell>
39164 </row>
39165 <row topline="true">
39166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39167 \begin_inset Text
39168
39169 \begin_layout Standard
39170
39171 \size footnotesize
39172 IFX
39173 \end_layout
39174
39175 \end_inset
39176 </cell>
39177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39178 \begin_inset Text
39179
39180 \begin_layout Standard
39181
39182 \size footnotesize
39183 IC_COND IC_TRUE IC_LABEL
39184 \end_layout
39185
39186 \end_inset
39187 </cell>
39188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39189 \begin_inset Text
39190
39191 \begin_layout Standard
39192
39193 \size footnotesize
39194 Conditional jump.
39195  If true label is present then jump to true label if condition is true else
39196  jump to false label if condition is false 
39197 \end_layout
39198
39199 \end_inset
39200 </cell>
39201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39202 \begin_inset Text
39203
39204 \begin_layout Standard
39205
39206 \size footnotesize
39207 if (IC_COND) goto IC_TRUE; 
39208 \newline
39209 \InsetSpace ~
39210 \InsetSpace ~
39211 Or 
39212 \newline
39213 If (!IC_COND) goto IC_FALSE;
39214 \end_layout
39215
39216 \end_inset
39217 </cell>
39218 </row>
39219 <row topline="true">
39220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39221 \begin_inset Text
39222
39223 \begin_layout Standard
39224
39225 \size footnotesize
39226 ADDRESS_OF
39227 \end_layout
39228
39229 \end_inset
39230 </cell>
39231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39232 \begin_inset Text
39233
39234 \begin_layout Standard
39235
39236 \size footnotesize
39237 IC_LEFT() IC_RESULT()
39238 \end_layout
39239
39240 \end_inset
39241 </cell>
39242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39243 \begin_inset Text
39244
39245 \begin_layout Standard
39246
39247 \size footnotesize
39248 Address of 
39249 \end_layout
39250
39251 \end_inset
39252 </cell>
39253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39254 \begin_inset Text
39255
39256 \begin_layout Standard
39257
39258 \size footnotesize
39259 IC_RESULT = &IC_LEFT();
39260 \end_layout
39261
39262 \end_inset
39263 </cell>
39264 </row>
39265 <row topline="true">
39266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39267 \begin_inset Text
39268
39269 \begin_layout Standard
39270
39271 \size footnotesize
39272 JUMPTABLE
39273 \end_layout
39274
39275 \end_inset
39276 </cell>
39277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39278 \begin_inset Text
39279
39280 \begin_layout Standard
39281
39282 \size footnotesize
39283 IC_JTCOND IC_JTLABELS
39284 \end_layout
39285
39286 \end_inset
39287 </cell>
39288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39289 \begin_inset Text
39290
39291 \begin_layout Standard
39292
39293 \size footnotesize
39294 Jump to list of labels depending on the value of JTCOND
39295 \end_layout
39296
39297 \end_inset
39298 </cell>
39299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39300 \begin_inset Text
39301
39302 \begin_layout Standard
39303
39304 \size footnotesize
39305 Switch statement
39306 \end_layout
39307
39308 \end_inset
39309 </cell>
39310 </row>
39311 <row topline="true">
39312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39313 \begin_inset Text
39314
39315 \begin_layout Standard
39316
39317 \size footnotesize
39318 CAST
39319 \end_layout
39320
39321 \end_inset
39322 </cell>
39323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39324 \begin_inset Text
39325
39326 \begin_layout Standard
39327
39328 \size footnotesize
39329 IC_RIGHT() IC_LEFT() IC_RESULT()
39330 \end_layout
39331
39332 \end_inset
39333 </cell>
39334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39335 \begin_inset Text
39336
39337 \begin_layout Standard
39338
39339 \size footnotesize
39340 Cast types 
39341 \end_layout
39342
39343 \end_inset
39344 </cell>
39345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39346 \begin_inset Text
39347
39348 \begin_layout Standard
39349
39350 \size footnotesize
39351 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
39352 \end_layout
39353
39354 \end_inset
39355 </cell>
39356 </row>
39357 <row topline="true">
39358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39359 \begin_inset Text
39360
39361 \begin_layout Standard
39362
39363 \size footnotesize
39364 SEND
39365 \end_layout
39366
39367 \end_inset
39368 </cell>
39369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39370 \begin_inset Text
39371
39372 \begin_layout Standard
39373
39374 \size footnotesize
39375 IC_LEFT()
39376 \end_layout
39377
39378 \end_inset
39379 </cell>
39380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39381 \begin_inset Text
39382
39383 \begin_layout Standard
39384
39385 \size footnotesize
39386 This is used for passing parameters in registers; 
39387 \newline
39388 move IC_LEFT to the next
39389  available parameter register.
39390 \end_layout
39391
39392 \end_inset
39393 </cell>
39394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39395 \begin_inset Text
39396
39397 \begin_layout Standard
39398
39399 \size footnotesize
39400 None
39401 \end_layout
39402
39403 \end_inset
39404 </cell>
39405 </row>
39406 <row topline="true">
39407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39408 \begin_inset Text
39409
39410 \begin_layout Standard
39411
39412 \size footnotesize
39413 RECV
39414 \end_layout
39415
39416 \end_inset
39417 </cell>
39418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39419 \begin_inset Text
39420
39421 \begin_layout Standard
39422
39423 \size footnotesize
39424 IC_RESULT()
39425 \end_layout
39426
39427 \end_inset
39428 </cell>
39429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39430 \begin_inset Text
39431
39432 \begin_layout Standard
39433
39434 \size footnotesize
39435 This is used for receiving parameters passed in registers;
39436 \newline
39437 Move the values
39438  in the next parameter register to IC_RESULT 
39439 \end_layout
39440
39441 \end_inset
39442 </cell>
39443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39444 \begin_inset Text
39445
39446 \begin_layout Standard
39447
39448 \size footnotesize
39449 None
39450 \end_layout
39451
39452 \end_inset
39453 </cell>
39454 </row>
39455 <row topline="true" bottomline="true">
39456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39457 \begin_inset Text
39458
39459 \begin_layout Standard
39460
39461 \shape slanted
39462 \size footnotesize
39463 (some more have been added)
39464 \end_layout
39465
39466 \end_inset
39467 </cell>
39468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39469 \begin_inset Text
39470
39471 \begin_layout Standard
39472
39473 \end_layout
39474
39475 \end_inset
39476 </cell>
39477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39478 \begin_inset Text
39479
39480 \begin_layout Standard
39481
39482 \end_layout
39483
39484 \end_inset
39485 </cell>
39486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39487 \begin_inset Text
39488
39489 \begin_layout Standard
39490
39491 \shape slanted
39492 \size footnotesize
39493 see f.e.
39494  
39495 \family typewriter
39496 gen51Code()
39497 \family default
39498  in 
39499 \family typewriter
39500 src/mcs51/gen.c
39501 \end_layout
39502
39503 \end_inset
39504 </cell>
39505 </row>
39506 </lyxtabular>
39507
39508 \end_inset
39509
39510
39511 \end_layout
39512
39513 \begin_layout Standard
39514 \begin_inset Note Note
39515 status collapsed
39516
39517 \begin_layout Standard
39518 In the original article Figure II was announced to be downloadable on 
39519 \shape italic
39520 Circuit Cellar
39521 \shape default
39522 's web site.
39523  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
39524 \end_layout
39525
39526 \end_inset
39527
39528
39529 \end_layout
39530
39531 \begin_layout Paragraph*
39532 ICode Example
39533 \begin_inset LatexCommand \index{iCode}
39534
39535 \end_inset
39536
39537
39538 \end_layout
39539
39540 \begin_layout Standard
39541 This section shows some details of iCode.
39542  The example C code does not do anything useful; it is used as an example
39543  to illustrate the intermediate code generated by the compiler.
39544 \end_layout
39545
39546 \begin_layout Verse
39547
39548 \family typewriter
39549 1.\InsetSpace ~
39550 xdata int * p;
39551 \newline
39552 2.\InsetSpace ~
39553 int gint;
39554 \newline
39555 3.\InsetSpace ~
39556 /* This function does nothing useful.
39557  It is used
39558 \newline
39559 4.\InsetSpace ~
39560 \InsetSpace ~
39561 \InsetSpace ~
39562 \InsetSpace ~
39563 for the purpose of explaining iCode */
39564 \newline
39565 5.\InsetSpace ~
39566 short function (data
39567  int *x)
39568 \newline
39569 6.\InsetSpace ~
39570 {
39571 \newline
39572 7.\InsetSpace ~
39573 \InsetSpace ~
39574 \InsetSpace ~
39575 short i=10; \InsetSpace ~
39576 \InsetSpace ~
39577 /* dead initialization eliminated */
39578 \newline
39579 8.\InsetSpace ~
39580 \InsetSpace ~
39581 \InsetSpace ~
39582 short sum=10;
39583  /* dead initialization eliminated */
39584 \newline
39585 9.\InsetSpace ~
39586 \InsetSpace ~
39587 \InsetSpace ~
39588 short mul;
39589 \newline
39590 10.\InsetSpace ~
39591 \InsetSpace ~
39592 int j ;
39593 \newline
39594 11.\InsetSpace ~
39595 \InsetSpace ~
39596 while (*x) *x++
39597  = *p++; 
39598 \newline
39599 12.\InsetSpace ~
39600 \InsetSpace ~
39601 \InsetSpace ~
39602 \InsetSpace ~
39603 sum = 0 ; 
39604 \newline
39605 13.\InsetSpace ~
39606 \InsetSpace ~
39607 mul = 0;
39608 \newline
39609 14.\InsetSpace ~
39610 \InsetSpace ~
39611 /* compiler detects i,j to be induction
39612  variables */
39613 \newline
39614 15.\InsetSpace ~
39615 \InsetSpace ~
39616 for (i = 0, j = 10 ; i < 10 ; i++, j
39617 \family default
39618 -
39619 \begin_inset ERT
39620 status collapsed
39621
39622 \begin_layout Standard
39623
39624
39625 \backslash
39626 /
39627 \end_layout
39628
39629 \end_inset
39630
39631 -
39632 \family typewriter
39633 ) {
39634 \newline
39635 16.\InsetSpace ~
39636 \InsetSpace ~
39637 \InsetSpace ~
39638 \InsetSpace ~
39639 sum += i;
39640 \newline
39641 17.\InsetSpace ~
39642 \InsetSpace ~
39643 \InsetSpace ~
39644 \InsetSpace ~
39645 mul += i * 3; \InsetSpace ~
39646 \InsetSpace ~
39647 /* this multiplication remains */
39648 \newline
39649 18.\InsetSpace ~
39650 \InsetSpace ~
39651 \InsetSpace ~
39652 \InsetSpace ~
39653 gint +=
39654  j * 3;\InsetSpace ~
39655 \InsetSpace ~
39656 /* this multiplication changed to addition */
39657 \newline
39658 19.\InsetSpace ~
39659 \InsetSpace ~
39660 }
39661 \newline
39662 20.\InsetSpace ~
39663 \InsetSpace ~
39664 return sum+mul;
39665 \newline
39666 21.\InsetSpace ~
39667 }
39668 \end_layout
39669
39670 \begin_layout Standard
39671 In addition to the operands each iCode contains information about the filename
39672  and line it corresponds to in the source file.
39673  The first field in the listing should be interpreted as follows:
39674 \newline
39675
39676 \shape italic
39677 \size footnotesize
39678 Filename(linenumber: iCode Execution sequence number : ICode hash table
39679  key : loop depth of the iCode).
39680 \shape default
39681 \size default
39682
39683 \newline
39684 Then follows the human readable form of the ICode operation.
39685  Each operand of this triplet form can be of three basic types a) compiler
39686  generated temporary b) user defined variable c) a constant value.
39687  Note that local variables and parameters are replaced by compiler generated
39688  temporaries.
39689  Live ranges
39690 \begin_inset LatexCommand \index{Live range analysis}
39691
39692 \end_inset
39693
39694  are computed only for temporaries (i.e.
39695  live ranges are not computed for global variables).
39696  Registers
39697 \begin_inset LatexCommand \index{Register allocation}
39698
39699 \end_inset
39700
39701  are allocated for temporaries only.
39702  Operands are formatted in the following manner:
39703 \newline
39704
39705 \shape italic
39706 \size footnotesize
39707 Operand Name [lr live-from : live-to ] { type information } [ registers
39708  allocated ].
39709 \shape default
39710 \size default
39711
39712 \newline
39713 As mentioned earlier the live ranges are computed in terms of the execution
39714  sequence number of the iCodes, for example 
39715 \newline
39716 the iTemp0 is live from (i.e.
39717  first defined in iCode with execution sequence number 3, and is last used
39718  in the iCode with sequence number 5).
39719  For induction variables such as iTemp21 the live range computation extends
39720  the lifetime from the start to the end of the loop.
39721 \newline
39722 The register allocator
39723  used the live range information to allocate registers, the same registers
39724  may be used for different temporaries if their live ranges do not overlap,
39725  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
39726  ranges do not overlap.
39727  In addition the allocator also takes into consideration the type and usage
39728  of a temporary, for example itemp6 is a pointer to near space and is used
39729  as to fetch data from (i.e.
39730  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
39731  Some short lived temporaries are allocated to special registers which have
39732  meaning to the code generator e.g.
39733  iTemp13 is allocated to a pseudo register CC which tells the back end that
39734  the temporary is used only for a conditional jump the code generation makes
39735  use of this information to optimize a compare and jump ICode.
39736 \newline
39737 There are several
39738  loop optimizations
39739 \begin_inset LatexCommand \index{Loop optimization}
39740
39741 \end_inset
39742
39743  performed by the compiler.
39744  It can detect induction variables iTemp21(i) and iTemp23(j).
39745  Also note the compiler does selective strength reduction
39746 \begin_inset LatexCommand \index{Strength reduction}
39747
39748 \end_inset
39749
39750 , i.e.
39751  the multiplication of an induction variable in line 18 (gint = j * 3) is
39752  changed to addition, a new temporary iTemp17 is allocated and assigned
39753  a initial value, a constant 3 is then added for each iteration of the loop.
39754  The compiler does not change the multiplication
39755 \begin_inset LatexCommand \index{Multiplication}
39756
39757 \end_inset
39758
39759  in line 17 however since the processor does support an 8 * 8 bit multiplication.
39760 \newline
39761
39762 Note the dead code elimination
39763 \begin_inset LatexCommand \index{Dead-code elimination}
39764
39765 \end_inset
39766
39767  optimization eliminated the dead assignments in line 7 & 8 to I and sum
39768  respectively.
39769 \newline
39770
39771 \end_layout
39772
39773 \begin_layout Standard
39774
39775 \size footnotesize
39776 Sample.c (5:1:0:0) _entry($9) :
39777 \end_layout
39778
39779 \begin_layout Standard
39780
39781 \size footnotesize
39782 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
39783 \end_layout
39784
39785 \begin_layout Standard
39786
39787 \size footnotesize
39788 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
39789 \end_layout
39790
39791 \begin_layout Standard
39792
39793 \size footnotesize
39794 Sample.c(11:4:53:0) preHeaderLbl0($11) :
39795 \end_layout
39796
39797 \begin_layout Standard
39798
39799 \size footnotesize
39800 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
39801  * int}[r2]
39802 \end_layout
39803
39804 \begin_layout Standard
39805
39806 \size footnotesize
39807 Sample.c(11:6:5:1) _whilecontinue_0($1) :
39808 \end_layout
39809
39810 \begin_layout Standard
39811
39812 \size footnotesize
39813 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
39814  int}[r0]]
39815 \end_layout
39816
39817 \begin_layout Standard
39818
39819 \size footnotesize
39820 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
39821 \end_layout
39822
39823 \begin_layout Standard
39824
39825 \size footnotesize
39826 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
39827  * int}
39828 \end_layout
39829
39830 \begin_layout Standard
39831
39832 \size footnotesize
39833 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
39834  {short}
39835 \end_layout
39836
39837 \begin_layout Standard
39838
39839 \size footnotesize
39840 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
39841  * int}[DPTR]]
39842 \end_layout
39843
39844 \begin_layout Standard
39845
39846 \size footnotesize
39847 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
39848 }[r2 r3]
39849 \end_layout
39850
39851 \begin_layout Standard
39852
39853 \size footnotesize
39854 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
39855  * int}[r0] + 0x2 {short}
39856 \end_layout
39857
39858 \begin_layout Standard
39859
39860 \size footnotesize
39861 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
39862 \end_layout
39863
39864 \begin_layout Standard
39865
39866 \size footnotesize
39867 Sample.c(11:17:21:0)_whilebreak_0($3) :
39868 \end_layout
39869
39870 \begin_layout Standard
39871
39872 \size footnotesize
39873 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39874 \end_layout
39875
39876 \begin_layout Standard
39877
39878 \size footnotesize
39879 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39880 \end_layout
39881
39882 \begin_layout Standard
39883
39884 \size footnotesize
39885 Sample.c(15:20:54:0)preHeaderLbl1($13) :
39886 \end_layout
39887
39888 \begin_layout Standard
39889
39890 \size footnotesize
39891 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39892 \end_layout
39893
39894 \begin_layout Standard
39895
39896 \size footnotesize
39897 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39898 \end_layout
39899
39900 \begin_layout Standard
39901
39902 \size footnotesize
39903 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39904 \end_layout
39905
39906 \begin_layout Standard
39907
39908 \size footnotesize
39909 Sample.c(15:24:26:1)_forcond_0($4) :
39910 \end_layout
39911
39912 \begin_layout Standard
39913
39914 \size footnotesize
39915 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
39916  < 0xa {short}
39917 \end_layout
39918
39919 \begin_layout Standard
39920
39921 \size footnotesize
39922 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39923 \end_layout
39924
39925 \begin_layout Standard
39926
39927 \size footnotesize
39928 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
39929  + ITemp21 [lr21:38]{short}[r4]
39930 \end_layout
39931
39932 \begin_layout Standard
39933
39934 \size footnotesize
39935 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
39936  * 0x3 {short}
39937 \end_layout
39938
39939 \begin_layout Standard
39940
39941 \size footnotesize
39942 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
39943  + iTemp15 [lr29:30]{short}[r1]
39944 \end_layout
39945
39946 \begin_layout Standard
39947
39948 \size footnotesize
39949 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
39950  r0]- 0x3 {short}
39951 \end_layout
39952
39953 \begin_layout Standard
39954
39955 \size footnotesize
39956 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
39957 int}[r7 r0]
39958 \end_layout
39959
39960 \begin_layout Standard
39961
39962 \size footnotesize
39963 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
39964  + 0x1 {short}
39965 \end_layout
39966
39967 \begin_layout Standard
39968
39969 \size footnotesize
39970 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
39971  r6]- 0x1 {short}
39972 \end_layout
39973
39974 \begin_layout Standard
39975
39976 \size footnotesize
39977 Sample.c(19:38:47:1) goto _forcond_0($4)
39978 \end_layout
39979
39980 \begin_layout Standard
39981
39982 \size footnotesize
39983 Sample.c(19:39:48:0)_forbreak_0($7) :
39984 \end_layout
39985
39986 \begin_layout Standard
39987
39988 \size footnotesize
39989 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
39990  + ITemp11 [lr19:40]{short}[r3]
39991 \end_layout
39992
39993 \begin_layout Standard
39994
39995 \size footnotesize
39996 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
39997 \end_layout
39998
39999 \begin_layout Standard
40000
40001 \size footnotesize
40002 Sample.c(20:42:51:0)_return($8) :
40003 \end_layout
40004
40005 \begin_layout Standard
40006
40007 \size footnotesize
40008 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
40009 \size default
40010
40011 \newline
40012
40013 \newline
40014 Finally the code generated for this function:
40015 \newline
40016
40017 \end_layout
40018
40019 \begin_layout Standard
40020
40021 \size footnotesize
40022 .area DSEG (DATA)
40023 \end_layout
40024
40025 \begin_layout Standard
40026
40027 \size footnotesize
40028 _p::
40029 \end_layout
40030
40031 \begin_layout Standard
40032
40033 \size footnotesize
40034 \InsetSpace ~
40035 \InsetSpace ~
40036 .ds 2
40037 \end_layout
40038
40039 \begin_layout Standard
40040
40041 \size footnotesize
40042 _gint::
40043 \end_layout
40044
40045 \begin_layout Standard
40046
40047 \size footnotesize
40048 \InsetSpace ~
40049 \InsetSpace ~
40050 .ds 2
40051 \end_layout
40052
40053 \begin_layout Standard
40054
40055 \size footnotesize
40056 ; sample.c 5
40057 \end_layout
40058
40059 \begin_layout Standard
40060
40061 \size footnotesize
40062 ; ----------------------------------------------
40063 \end_layout
40064
40065 \begin_layout Standard
40066
40067 \size footnotesize
40068 ; function function
40069 \end_layout
40070
40071 \begin_layout Standard
40072
40073 \size footnotesize
40074 ; ----------------------------------------------
40075 \end_layout
40076
40077 \begin_layout Standard
40078
40079 \size footnotesize
40080 _function:
40081 \end_layout
40082
40083 \begin_layout Standard
40084
40085 \size footnotesize
40086 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
40087 \end_layout
40088
40089 \begin_layout Standard
40090
40091 \size footnotesize
40092 \InsetSpace ~
40093 \InsetSpace ~
40094 mov r2,dpl
40095 \end_layout
40096
40097 \begin_layout Standard
40098
40099 \size footnotesize
40100 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
40101 \end_layout
40102
40103 \begin_layout Standard
40104
40105 \size footnotesize
40106 \InsetSpace ~
40107 \InsetSpace ~
40108 mov ar0,r2
40109 \end_layout
40110
40111 \begin_layout Standard
40112
40113 \size footnotesize
40114 ;_whilecontinue_0($1) :
40115 \end_layout
40116
40117 \begin_layout Standard
40118
40119 \size footnotesize
40120 00101$:
40121 \end_layout
40122
40123 \begin_layout Standard
40124
40125 \size footnotesize
40126 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
40127 \end_layout
40128
40129 \begin_layout Standard
40130
40131 \size footnotesize
40132 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
40133 \end_layout
40134
40135 \begin_layout Standard
40136
40137 \size footnotesize
40138 \InsetSpace ~
40139 \InsetSpace ~
40140 mov ar2,@r0
40141 \end_layout
40142
40143 \begin_layout Standard
40144
40145 \size footnotesize
40146 \InsetSpace ~
40147 \InsetSpace ~
40148 inc r0
40149 \end_layout
40150
40151 \begin_layout Standard
40152
40153 \size footnotesize
40154 \InsetSpace ~
40155 \InsetSpace ~
40156 mov ar3,@r0
40157 \end_layout
40158
40159 \begin_layout Standard
40160
40161 \size footnotesize
40162 \InsetSpace ~
40163 \InsetSpace ~
40164 dec r0
40165 \end_layout
40166
40167 \begin_layout Standard
40168
40169 \size footnotesize
40170 \InsetSpace ~
40171 \InsetSpace ~
40172 mov a,r2
40173 \end_layout
40174
40175 \begin_layout Standard
40176
40177 \size footnotesize
40178 \InsetSpace ~
40179 \InsetSpace ~
40180 orl a,r3
40181 \end_layout
40182
40183 \begin_layout Standard
40184
40185 \size footnotesize
40186 \InsetSpace ~
40187 \InsetSpace ~
40188 jz 00103$
40189 \end_layout
40190
40191 \begin_layout Standard
40192
40193 \size footnotesize
40194 00114$:
40195 \end_layout
40196
40197 \begin_layout Standard
40198
40199 \size footnotesize
40200 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
40201 \end_layout
40202
40203 \begin_layout Standard
40204
40205 \size footnotesize
40206 \InsetSpace ~
40207 \InsetSpace ~
40208 mov dpl,_p
40209 \end_layout
40210
40211 \begin_layout Standard
40212
40213 \size footnotesize
40214 \InsetSpace ~
40215 \InsetSpace ~
40216 mov dph,(_p + 1)
40217 \end_layout
40218
40219 \begin_layout Standard
40220
40221 \size footnotesize
40222 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
40223 \end_layout
40224
40225 \begin_layout Standard
40226
40227 \size footnotesize
40228 \InsetSpace ~
40229 \InsetSpace ~
40230 mov a,#0x02
40231 \end_layout
40232
40233 \begin_layout Standard
40234
40235 \size footnotesize
40236 \InsetSpace ~
40237 \InsetSpace ~
40238 add a,_p
40239 \end_layout
40240
40241 \begin_layout Standard
40242
40243 \size footnotesize
40244 \InsetSpace ~
40245 \InsetSpace ~
40246 mov _p,a
40247 \end_layout
40248
40249 \begin_layout Standard
40250
40251 \size footnotesize
40252 \InsetSpace ~
40253 \InsetSpace ~
40254 clr a
40255 \end_layout
40256
40257 \begin_layout Standard
40258
40259 \size footnotesize
40260 \InsetSpace ~
40261 \InsetSpace ~
40262 addc a,(_p + 1)
40263 \end_layout
40264
40265 \begin_layout Standard
40266
40267 \size footnotesize
40268 \InsetSpace ~
40269 \InsetSpace ~
40270 mov (_p + 1),a
40271 \end_layout
40272
40273 \begin_layout Standard
40274
40275 \size footnotesize
40276 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
40277 \end_layout
40278
40279 \begin_layout Standard
40280
40281 \size footnotesize
40282 \InsetSpace ~
40283 \InsetSpace ~
40284 movx a,@dptr
40285 \end_layout
40286
40287 \begin_layout Standard
40288
40289 \size footnotesize
40290 \InsetSpace ~
40291 \InsetSpace ~
40292 mov r2,a
40293 \end_layout
40294
40295 \begin_layout Standard
40296
40297 \size footnotesize
40298 \InsetSpace ~
40299 \InsetSpace ~
40300 inc dptr
40301 \end_layout
40302
40303 \begin_layout Standard
40304
40305 \size footnotesize
40306 \InsetSpace ~
40307 \InsetSpace ~
40308 movx a,@dptr
40309 \end_layout
40310
40311 \begin_layout Standard
40312
40313 \size footnotesize
40314 \InsetSpace ~
40315 \InsetSpace ~
40316 mov r3,a
40317 \end_layout
40318
40319 \begin_layout Standard
40320
40321 \size footnotesize
40322 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
40323 \end_layout
40324
40325 \begin_layout Standard
40326
40327 \size footnotesize
40328 \InsetSpace ~
40329 \InsetSpace ~
40330 mov @r0,ar2
40331 \end_layout
40332
40333 \begin_layout Standard
40334
40335 \size footnotesize
40336 \InsetSpace ~
40337 \InsetSpace ~
40338 inc r0
40339 \end_layout
40340
40341 \begin_layout Standard
40342
40343 \size footnotesize
40344 \InsetSpace ~
40345 \InsetSpace ~
40346 mov @r0,ar3
40347 \end_layout
40348
40349 \begin_layout Standard
40350
40351 \size footnotesize
40352 ; iTemp6 [lr5:16]{_near * int}[r0] = 
40353 \end_layout
40354
40355 \begin_layout Standard
40356
40357 \size footnotesize
40358 ; iTemp6 [lr5:16]{_near * int}[r0] + 
40359 \end_layout
40360
40361 \begin_layout Standard
40362
40363 \size footnotesize
40364 ; 0x2 {short}
40365 \end_layout
40366
40367 \begin_layout Standard
40368
40369 \size footnotesize
40370 \InsetSpace ~
40371 \InsetSpace ~
40372 inc r0
40373 \end_layout
40374
40375 \begin_layout Standard
40376
40377 \size footnotesize
40378 ; goto _whilecontinue_0($1)
40379 \end_layout
40380
40381 \begin_layout Standard
40382
40383 \size footnotesize
40384 \InsetSpace ~
40385 \InsetSpace ~
40386 sjmp 00101$
40387 \end_layout
40388
40389 \begin_layout Standard
40390
40391 \size footnotesize
40392 ; _whilebreak_0($3) :
40393 \end_layout
40394
40395 \begin_layout Standard
40396
40397 \size footnotesize
40398 00103$:
40399 \end_layout
40400
40401 \begin_layout Standard
40402
40403 \size footnotesize
40404 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
40405 \end_layout
40406
40407 \begin_layout Standard
40408
40409 \size footnotesize
40410 \InsetSpace ~
40411 \InsetSpace ~
40412 mov r2,#0x00
40413 \end_layout
40414
40415 \begin_layout Standard
40416
40417 \size footnotesize
40418 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
40419 \end_layout
40420
40421 \begin_layout Standard
40422
40423 \size footnotesize
40424 \InsetSpace ~
40425 \InsetSpace ~
40426 mov r3,#0x00
40427 \end_layout
40428
40429 \begin_layout Standard
40430
40431 \size footnotesize
40432 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
40433 \end_layout
40434
40435 \begin_layout Standard
40436
40437 \size footnotesize
40438 \InsetSpace ~
40439 \InsetSpace ~
40440 mov r4,#0x00
40441 \end_layout
40442
40443 \begin_layout Standard
40444
40445 \size footnotesize
40446 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
40447 \end_layout
40448
40449 \begin_layout Standard
40450
40451 \size footnotesize
40452 \InsetSpace ~
40453 \InsetSpace ~
40454 mov r5,#0x0A
40455 \end_layout
40456
40457 \begin_layout Standard
40458
40459 \size footnotesize
40460 \InsetSpace ~
40461 \InsetSpace ~
40462 mov r6,#0x00
40463 \end_layout
40464
40465 \begin_layout Standard
40466
40467 \size footnotesize
40468 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
40469 \end_layout
40470
40471 \begin_layout Standard
40472
40473 \size footnotesize
40474 \InsetSpace ~
40475 \InsetSpace ~
40476 mov r7,#0x1E
40477 \end_layout
40478
40479 \begin_layout Standard
40480
40481 \size footnotesize
40482 \InsetSpace ~
40483 \InsetSpace ~
40484 mov r0,#0x00
40485 \end_layout
40486
40487 \begin_layout Standard
40488
40489 \size footnotesize
40490 ; _forcond_0($4) :
40491 \end_layout
40492
40493 \begin_layout Standard
40494
40495 \size footnotesize
40496 00104$:
40497 \end_layout
40498
40499 \begin_layout Standard
40500
40501 \size footnotesize
40502 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
40503 \end_layout
40504
40505 \begin_layout Standard
40506
40507 \size footnotesize
40508 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
40509 \end_layout
40510
40511 \begin_layout Standard
40512
40513 \size footnotesize
40514 \InsetSpace ~
40515 \InsetSpace ~
40516 clr c
40517 \end_layout
40518
40519 \begin_layout Standard
40520
40521 \size footnotesize
40522 \InsetSpace ~
40523 \InsetSpace ~
40524 mov a,r4
40525 \end_layout
40526
40527 \begin_layout Standard
40528
40529 \size footnotesize
40530 \InsetSpace ~
40531 \InsetSpace ~
40532 xrl a,#0x80
40533 \end_layout
40534
40535 \begin_layout Standard
40536
40537 \size footnotesize
40538 \InsetSpace ~
40539 \InsetSpace ~
40540 subb a,#0x8a
40541 \end_layout
40542
40543 \begin_layout Standard
40544
40545 \size footnotesize
40546 \InsetSpace ~
40547 \InsetSpace ~
40548 jnc 00107$
40549 \end_layout
40550
40551 \begin_layout Standard
40552
40553 \size footnotesize
40554 00115$:
40555 \end_layout
40556
40557 \begin_layout Standard
40558
40559 \size footnotesize
40560 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
40561 \end_layout
40562
40563 \begin_layout Standard
40564
40565 \size footnotesize
40566 ; iTemp21 [lr21:38]{short}[r4]
40567 \end_layout
40568
40569 \begin_layout Standard
40570
40571 \size footnotesize
40572 \InsetSpace ~
40573 \InsetSpace ~
40574 mov a,r4
40575 \end_layout
40576
40577 \begin_layout Standard
40578
40579 \size footnotesize
40580 \InsetSpace ~
40581 \InsetSpace ~
40582 add a,r2
40583 \end_layout
40584
40585 \begin_layout Standard
40586
40587 \size footnotesize
40588 \InsetSpace ~
40589 \InsetSpace ~
40590 mov r2,a
40591 \end_layout
40592
40593 \begin_layout Standard
40594
40595 \size footnotesize
40596 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
40597 \end_layout
40598
40599 \begin_layout Standard
40600
40601 \size footnotesize
40602 \InsetSpace ~
40603 \InsetSpace ~
40604 mov b,#0x03
40605 \end_layout
40606
40607 \begin_layout Standard
40608
40609 \size footnotesize
40610 \InsetSpace ~
40611 \InsetSpace ~
40612 mov a,r4
40613 \end_layout
40614
40615 \begin_layout Standard
40616
40617 \size footnotesize
40618 \InsetSpace ~
40619 \InsetSpace ~
40620 mul ab
40621 \end_layout
40622
40623 \begin_layout Standard
40624
40625 \size footnotesize
40626 \InsetSpace ~
40627 \InsetSpace ~
40628 mov r1,a
40629 \end_layout
40630
40631 \begin_layout Standard
40632
40633 \size footnotesize
40634 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
40635 \end_layout
40636
40637 \begin_layout Standard
40638
40639 \size footnotesize
40640 ; iTemp15 [lr29:30]{short}[r1]
40641 \end_layout
40642
40643 \begin_layout Standard
40644
40645 \size footnotesize
40646 \InsetSpace ~
40647 \InsetSpace ~
40648 add a,r3
40649 \end_layout
40650
40651 \begin_layout Standard
40652
40653 \size footnotesize
40654 \InsetSpace ~
40655 \InsetSpace ~
40656 mov r3,a
40657 \end_layout
40658
40659 \begin_layout Standard
40660
40661 \size footnotesize
40662 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
40663 \end_layout
40664
40665 \begin_layout Standard
40666
40667 \size footnotesize
40668 \InsetSpace ~
40669 \InsetSpace ~
40670 mov a,r7
40671 \end_layout
40672
40673 \begin_layout Standard
40674
40675 \size footnotesize
40676 \InsetSpace ~
40677 \InsetSpace ~
40678 add a,#0xfd
40679 \end_layout
40680
40681 \begin_layout Standard
40682
40683 \size footnotesize
40684 \InsetSpace ~
40685 \InsetSpace ~
40686 mov r7,a
40687 \end_layout
40688
40689 \begin_layout Standard
40690
40691 \size footnotesize
40692 \InsetSpace ~
40693 \InsetSpace ~
40694 mov a,r0
40695 \end_layout
40696
40697 \begin_layout Standard
40698
40699 \size footnotesize
40700 \InsetSpace ~
40701 \InsetSpace ~
40702 addc a,#0xff
40703 \end_layout
40704
40705 \begin_layout Standard
40706
40707 \size footnotesize
40708 \InsetSpace ~
40709 \InsetSpace ~
40710 mov r0,a
40711 \end_layout
40712
40713 \begin_layout Standard
40714
40715 \size footnotesize
40716 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
40717 \end_layout
40718
40719 \begin_layout Standard
40720
40721 \size footnotesize
40722 \InsetSpace ~
40723 \InsetSpace ~
40724 mov a,r7
40725 \end_layout
40726
40727 \begin_layout Standard
40728
40729 \size footnotesize
40730 \InsetSpace ~
40731 \InsetSpace ~
40732 add a,_gint
40733 \end_layout
40734
40735 \begin_layout Standard
40736
40737 \size footnotesize
40738 \InsetSpace ~
40739 \InsetSpace ~
40740 mov _gint,a
40741 \end_layout
40742
40743 \begin_layout Standard
40744
40745 \size footnotesize
40746 \InsetSpace ~
40747 \InsetSpace ~
40748 mov a,r0
40749 \end_layout
40750
40751 \begin_layout Standard
40752
40753 \size footnotesize
40754 \InsetSpace ~
40755 \InsetSpace ~
40756 addc a,(_gint + 1)
40757 \end_layout
40758
40759 \begin_layout Standard
40760
40761 \size footnotesize
40762 \InsetSpace ~
40763 \InsetSpace ~
40764 mov (_gint + 1),a
40765 \end_layout
40766
40767 \begin_layout Standard
40768
40769 \size footnotesize
40770 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
40771 \end_layout
40772
40773 \begin_layout Standard
40774
40775 \size footnotesize
40776 \InsetSpace ~
40777 \InsetSpace ~
40778 inc r4
40779 \end_layout
40780
40781 \begin_layout Standard
40782
40783 \size footnotesize
40784 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
40785 \end_layout
40786
40787 \begin_layout Standard
40788
40789 \size footnotesize
40790 \InsetSpace ~
40791 \InsetSpace ~
40792 dec r5
40793 \end_layout
40794
40795 \begin_layout Standard
40796
40797 \size footnotesize
40798 \InsetSpace ~
40799 \InsetSpace ~
40800 cjne r5,#0xff,00104$
40801 \end_layout
40802
40803 \begin_layout Standard
40804
40805 \size footnotesize
40806 \InsetSpace ~
40807 \InsetSpace ~
40808 dec r6
40809 \end_layout
40810
40811 \begin_layout Standard
40812
40813 \size footnotesize
40814 ; goto _forcond_0($4)
40815 \end_layout
40816
40817 \begin_layout Standard
40818
40819 \size footnotesize
40820 \InsetSpace ~
40821 \InsetSpace ~
40822 sjmp 00104$
40823 \end_layout
40824
40825 \begin_layout Standard
40826
40827 \size footnotesize
40828 ; _forbreak_0($7) :
40829 \end_layout
40830
40831 \begin_layout Standard
40832
40833 \size footnotesize
40834 00107$:
40835 \end_layout
40836
40837 \begin_layout Standard
40838
40839 \size footnotesize
40840 ; ret iTemp24 [lr40:41]{short}
40841 \end_layout
40842
40843 \begin_layout Standard
40844
40845 \size footnotesize
40846 \InsetSpace ~
40847 \InsetSpace ~
40848 mov a,r3
40849 \end_layout
40850
40851 \begin_layout Standard
40852
40853 \size footnotesize
40854 \InsetSpace ~
40855 \InsetSpace ~
40856 add a,r2
40857 \end_layout
40858
40859 \begin_layout Standard
40860
40861 \size footnotesize
40862 \InsetSpace ~
40863 \InsetSpace ~
40864 mov dpl,a
40865 \end_layout
40866
40867 \begin_layout Standard
40868
40869 \size footnotesize
40870 ; _return($8) :
40871 \end_layout
40872
40873 \begin_layout Standard
40874
40875 \size footnotesize
40876 00108$:
40877 \end_layout
40878
40879 \begin_layout Standard
40880
40881 \size footnotesize
40882 \InsetSpace ~
40883 \InsetSpace ~
40884 ret
40885 \newline
40886
40887 \end_layout
40888
40889 \begin_layout Section
40890 A few words about basic block successors, predecessors and dominators
40891 \end_layout
40892
40893 \begin_layout Standard
40894 Successors are basic blocks
40895 \begin_inset LatexCommand \index{Basic blocks}
40896
40897 \end_inset
40898
40899  that might execute after this basic block.
40900 \newline
40901 Predecessors are basic blocks
40902  that might execute before reaching this basic block.
40903 \newline
40904 Dominators are basic
40905  blocks that WILL execute before reaching this basic block.
40906 \newline
40907
40908 \end_layout
40909
40910 \begin_layout Standard
40911 [basic block 1]
40912 \end_layout
40913
40914 \begin_layout Standard
40915 if (something)
40916 \end_layout
40917
40918 \begin_layout Standard
40919 \InsetSpace ~
40920 \InsetSpace ~
40921 \InsetSpace ~
40922 \InsetSpace ~
40923 [basic block 2]
40924 \end_layout
40925
40926 \begin_layout Standard
40927 else
40928 \end_layout
40929
40930 \begin_layout Standard
40931 \InsetSpace ~
40932 \InsetSpace ~
40933 \InsetSpace ~
40934 \InsetSpace ~
40935 [basic block 3]
40936 \end_layout
40937
40938 \begin_layout Standard
40939 [basic block 4]
40940 \newline
40941
40942 \end_layout
40943
40944 \begin_layout Standard
40945 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
40946 \end_layout
40947
40948 \begin_layout Standard
40949 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
40950 \end_layout
40951
40952 \begin_layout Standard
40953 c) domVect of [BB4] = BB1 ...
40954  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
40955  was executed.
40956 \end_layout
40957
40958 \begin_layout Chapter
40959 Acknowledgments
40960 \end_layout
40961
40962 \begin_layout Standard
40963 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/#Who}
40964
40965 \end_inset
40966
40967
40968 \newline
40969
40970 \newline
40971
40972 \emph on
40973 Thanks to all the other volunteer developers who have helped with coding,
40974  testing, web-page creation, distribution sets, etc.
40975  You know who you are :-)
40976 \emph default
40977
40978 \newline
40979
40980 \newline
40981
40982 \emph on
40983 Thanks to Sourceforge 
40984 \begin_inset LatexCommand \url{http://www.sf.net}
40985
40986 \end_inset
40987
40988  which has hosted the project since 1999 and donates significant download
40989  bandwidth.
40990 \emph default
40991
40992 \newline
40993
40994 \newline
40995
40996 \emph on
40997 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
40998  cycles and bandwidth for snapshot builds.
40999 \newline
41000
41001 \end_layout
41002
41003 \begin_layout Standard
41004 This document was initially written by Sandeep Dutta
41005 \end_layout
41006
41007 \begin_layout Standard
41008 All product names mentioned herein may be trademarks
41009 \begin_inset LatexCommand \index{Trademarks}
41010
41011 \end_inset
41012
41013  of their respective companies.
41014  
41015 \end_layout
41016
41017 \begin_layout Section*
41018 Alphabetical index
41019 \end_layout
41020
41021 \begin_layout Standard
41022 To avoid confusion, the installation and building options for SDCC itself
41023  (chapter 2) are not part of the index.
41024 \end_layout
41025
41026 \begin_layout Standard
41027 \begin_inset LatexCommand \printindex{}
41028
41029 \end_inset
41030
41031
41032 \end_layout
41033
41034 \end_body
41035 \end_document