* sdc/SDCC.y, src/SDCCmain.c, src/SDCCglobl.h, doc/sdccman.lyx:
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.4.1 created this file. For more info see http://www.lyx.org/
2 \lyxformat 221
3 \textclass book
4 \begin_preamble
5 \pdfoptionpdfminorversion=3
6 \usepackage[
7   pdftitle={SDCC Compiler User Guide},
8   pdfauthor={SDCC development team},
9   pdfsubject={installation, user manual},
10   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},
11   pdfpagemode=UseOutlines,
12   colorlinks=true,
13   linkcolor=blue] {hyperref}
14 %
15 \sloppy
16 \tolerance=500          
17 \emergencystretch=30pt 
18 %
19 \date{}
20 \end_preamble
21 \language english
22 \inputencoding default
23 \fontscheme pslatex
24 \graphics default
25 \paperfontsize default
26 \spacing single
27 \papersize letterpaper
28 \use_geometry 1
29 \use_amsmath 0
30 \use_natbib 0
31 \use_numerical_citations 0
32 \paperorientation portrait
33 \leftmargin 30mm
34 \topmargin 20mm
35 \rightmargin 25mm
36 \bottommargin 20mm
37 \secnumdepth 3
38 \tocdepth 3
39 \paragraph_separation indent
40 \defskip medskip
41 \quotes_language swedish
42 \papercolumns 1
43 \papersides 1
44 \paperpagestyle fancy
45
46 \layout Standard
47 \begin_inset Note
48 collapsed true
49
50 \layout Standard
51 Please note: double dashed longoptions (e.g.
52  --version) are written this way: -
53 \begin_inset ERT
54 status Collapsed
55
56 \layout Standard
57
58
59 \backslash
60 /
61
62 \end_inset
63
64 -
65
66 \layout Standard
67 Two resp.
68  three consecutive dashes simply result in a long resp.
69  extra long dash.
70
71 \layout Standard
72 Architecture specific stuff (like memory models, code examples) should maybe
73  later go
74
75 \layout Standard
76 into seperate sections/chapters/appendices (it is hard to document PIC or
77  Z80 in 
78
79 \layout Standard
80 a 8051 centered document) - for now simply add.
81
82 \end_inset
83
84
85
86 \layout Title
87 SDCC Compiler User Guide
88
89 \layout Date
90
91 \size normal
92 SDCC 2.6.4
93 \size footnotesize
94
95 \newline
96 $Date$ 
97 \newline
98 $Revision$
99
100 \layout Standard
101 \begin_inset Note
102 collapsed true
103
104 \layout Standard
105 The above strings enclosed in $ are automatically updated by Subversion
106
107 \end_inset
108
109
110
111 \layout Standard
112 \begin_inset LatexCommand \tableofcontents{}
113
114 \end_inset
115
116
117
118 \layout Chapter
119 Introduction
120
121 \layout Section
122 About SDCC
123
124 \layout Standard
125
126 \series bold
127 SDCC
128 \series default
129  (
130 \emph on
131 S
132 \emph default
133 mall 
134 \emph on
135 D
136 \emph default
137 evice 
138 \emph on
139 C
140 \emph default
141  
142 \emph on
143 C
144 \emph default
145 ompiler) is an open source, retargettable, optimizing ANSI-C compiler by
146  
147 \series bold
148 Sandeep Dutta
149 \series default
150  designed for 8 bit Microprocessors.
151  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
152  8051, 8052
153 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
154
155 \end_inset
156
157 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
158  Zilog Z80 based MCUs.
159  It can be retargeted for other microprocessors, support for Microchip PIC,
160  Atmel AVR is under development.
161  The entire source code for the compiler is distributed under GPL.
162  SDCC uses ASXXXX
163 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
164
165 \end_inset
166
167  & ASLINK
168 \begin_inset LatexCommand \index{aslink}
169
170 \end_inset
171
172 , an open source retargetable assembler & linker.
173  SDCC has extensive language extensions suitable for utilizing various microcont
174 rollers and underlying hardware effectively.
175  
176 \newline
177
178 \newline
179 In addition to the MCU specific optimizations SDCC also does a host of
180  standard optimizations like:
181
182 \layout Itemize
183 global sub expression elimination, 
184
185 \layout Itemize
186 loop optimizations (loop invariant, strength reduction of induction variables
187  and loop reversing), 
188
189 \layout Itemize
190 constant folding & propagation, 
191
192 \layout Itemize
193 copy propagation, 
194
195 \layout Itemize
196 dead code elimination 
197
198 \layout Itemize
199 jump tables for 
200 \emph on
201 switch
202 \emph default
203  statements.
204
205 \layout Standard
206 For the back-end SDCC uses a global register allocation scheme which should
207  be well suited for other 8 bit MCUs.
208  
209 \newline
210
211 \newline
212 The peep hole optimizer uses a rule based substitution mechanism which
213  is MCU independent.
214  
215 \newline
216
217 \newline
218 Supported data-types are:
219
220 \layout Standard
221 \begin_inset Tabular
222 <lyxtabular version="3" rows="8" columns="5">
223 <features>
224 <column alignment="center" valignment="top" leftline="true" width="0">
225 <column alignment="center" valignment="top" leftline="true" width="0">
226 <column alignment="center" valignment="top" leftline="true" width="0">
227 <column alignment="center" valignment="top" leftline="true" width="0">
228 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
229 <row topline="true" bottomline="true">
230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
231 \begin_inset Text
232
233 \layout Standard
234 type
235
236 \end_inset
237 </cell>
238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
239 \begin_inset Text
240
241 \layout Standard
242 width
243
244 \end_inset
245 </cell>
246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
247 \begin_inset Text
248
249 \layout Standard
250 default
251
252 \end_inset
253 </cell>
254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
255 \begin_inset Text
256
257 \layout Standard
258 signed range
259
260 \end_inset
261 </cell>
262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
263 \begin_inset Text
264
265 \layout Standard
266 unsigned range
267
268 \end_inset
269 </cell>
270 </row>
271 <row topline="true">
272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
273 \begin_inset Text
274
275 \layout Standard
276 bool
277
278 \end_inset
279 </cell>
280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
281 \begin_inset Text
282
283 \layout Standard
284 1 bit
285
286 \end_inset
287 </cell>
288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
289 \begin_inset Text
290
291 \layout Standard
292 unsigned
293
294 \end_inset
295 </cell>
296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
297 \begin_inset Text
298
299 \layout Standard
300 -
301
302 \end_inset
303 </cell>
304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
305 \begin_inset Text
306
307 \layout Standard
308 0, 1
309
310 \end_inset
311 </cell>
312 </row>
313 <row topline="true">
314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
315 \begin_inset Text
316
317 \layout Standard
318 char
319
320 \end_inset
321 </cell>
322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
323 \begin_inset Text
324
325 \layout Standard
326 8 bits, 1 byte
327
328 \end_inset
329 </cell>
330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
331 \begin_inset Text
332
333 \layout Standard
334 signed
335
336 \end_inset
337 </cell>
338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
339 \begin_inset Text
340
341 \layout Standard
342 -128, +127
343
344 \end_inset
345 </cell>
346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
347 \begin_inset Text
348
349 \layout Standard
350 0, +255
351
352 \end_inset
353 </cell>
354 </row>
355 <row topline="true">
356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
357 \begin_inset Text
358
359 \layout Standard
360 short
361
362 \end_inset
363 </cell>
364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
365 \begin_inset Text
366
367 \layout Standard
368 16 bits, 2 bytes
369
370 \end_inset
371 </cell>
372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
373 \begin_inset Text
374
375 \layout Standard
376 signed
377
378 \end_inset
379 </cell>
380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
381 \begin_inset Text
382
383 \layout Standard
384 -32.768, +32.767
385
386 \end_inset
387 </cell>
388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
389 \begin_inset Text
390
391 \layout Standard
392 0, +65.535
393
394 \end_inset
395 </cell>
396 </row>
397 <row topline="true">
398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
399 \begin_inset Text
400
401 \layout Standard
402 int
403
404 \end_inset
405 </cell>
406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
407 \begin_inset Text
408
409 \layout Standard
410 16 bits, 2 bytes
411
412 \end_inset
413 </cell>
414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
415 \begin_inset Text
416
417 \layout Standard
418 signed
419
420 \end_inset
421 </cell>
422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
423 \begin_inset Text
424
425 \layout Standard
426 -32.768, +32.767
427
428 \end_inset
429 </cell>
430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
431 \begin_inset Text
432
433 \layout Standard
434 0, +65.535
435
436 \end_inset
437 </cell>
438 </row>
439 <row topline="true" bottomline="true">
440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
441 \begin_inset Text
442
443 \layout Standard
444 long
445
446 \end_inset
447 </cell>
448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
449 \begin_inset Text
450
451 \layout Standard
452 32 bits, 4 bytes
453
454 \end_inset
455 </cell>
456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
457 \begin_inset Text
458
459 \layout Standard
460 signed
461
462 \end_inset
463 </cell>
464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
465 \begin_inset Text
466
467 \layout Standard
468 -2.147.483.648, +2.147.483.647
469
470 \end_inset
471 </cell>
472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
473 \begin_inset Text
474
475 \layout Standard
476 0, +4.294.967.295
477
478 \end_inset
479 </cell>
480 </row>
481 <row topline="true" bottomline="true">
482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
483 \begin_inset Text
484
485 \layout Standard
486 float
487
488 \end_inset
489 </cell>
490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
491 \begin_inset Text
492
493 \layout Standard
494 4 bytes IEEE 754
495
496 \end_inset
497 </cell>
498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
499 \begin_inset Text
500
501 \layout Standard
502 signed
503
504 \end_inset
505 </cell>
506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
507 \begin_inset Text
508
509 \layout Standard
510
511
512 \end_inset
513 </cell>
514 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
515 \begin_inset Text
516
517 \layout Standard
518 1.175494351E-38, 
519 \family roman
520 \series medium
521 \shape up
522 \size normal
523 \emph off
524 \bar no
525 \noun off
526 \color none
527 3.402823466E+38
528
529 \end_inset
530 </cell>
531 </row>
532 <row topline="true" bottomline="true">
533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
534 \begin_inset Text
535
536 \layout Standard
537 pointer
538
539 \end_inset
540 </cell>
541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
542 \begin_inset Text
543
544 \layout Standard
545 1, 2, 3 or 4 bytes
546
547 \end_inset
548 </cell>
549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
550 \begin_inset Text
551
552 \layout Standard
553 generic
554
555 \end_inset
556 </cell>
557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
558 \begin_inset Text
559
560 \layout Standard
561
562
563 \end_inset
564 </cell>
565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
566 \begin_inset Text
567
568 \layout Standard
569
570
571 \end_inset
572 </cell>
573 </row>
574 </lyxtabular>
575
576 \end_inset
577
578
579 \newline
580 The compiler also allows 
581 \emph on
582 inline assembler code
583 \emph default
584  to be embedded anywhere in a function.
585  In addition, routines developed in assembly can also be called.
586 \newline
587
588 \newline
589 SDCC also
590  provides an option (-
591 \begin_inset ERT
592 status Collapsed
593
594 \layout Standard
595
596
597 \backslash
598 /
599
600 \end_inset
601
602 -cyclomatic) to report the relative complexity of a function.
603  These functions can then be further optimized, or hand coded in assembly
604  if needed.
605  
606 \newline
607
608 \newline
609 SDCC also comes with a companion source level debugger SDCDB, the debugger
610  currently uses ucSim a freeware simulator for 8051 and other micro-controllers.<
611 \newline
612
613 \newline
614
615 The latest version can be downloaded from 
616 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
617
618 \end_inset
619
620 .
621
622 \series bold
623  
624 \series default
625 \emph on
626 Please note: the compiler will probably always be some steps ahead of this
627  documentation
628 \series bold
629 \emph default
630
631 \begin_inset LatexCommand \index{Status of documentation}
632
633 \end_inset
634
635
636 \begin_inset Foot
637 collapsed false
638
639 \layout Standard
640 Obviously this has pros and cons
641
642 \end_inset
643
644 .
645
646 \layout Section
647 Open Source
648
649 \layout Standard
650 All packages used in this compiler system are 
651 \emph on
652 open source
653 \emph default
654  and 
655 \emph on
656 freeware
657 \emph default
658 ; source code for all the sub-packages (pre-processor, assemblers, linkers
659  etc) is distributed with the package.
660  This documentation is maintained using a freeware word processor (LyX).
661 \newline
662 This
663  program is free software; you can redistribute it and/or modify it under
664  the terms of the GNU General Public License
665 \begin_inset LatexCommand \index{GNU General Public License, GPL}
666
667 \end_inset
668
669  as published by the Free Software Foundation; either version 2, or (at
670  your option) any later version.
671  This program is distributed in the hope that it will be useful, but WITHOUT
672  ANY WARRANTY; without even the implied warranty
673 \begin_inset LatexCommand \index{warranty}
674
675 \end_inset
676
677  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
678  See the GNU General Public License for more details.
679  You should have received a copy of the GNU General Public License along
680  with this program; if not, write to the Free Software Foundation, 59 Temple
681  Place - Suite 330, Boston, MA 02111-1307, USA.
682  In other words, you are welcome to use, share and improve this program.
683  You are forbidden to forbid anyone else to use, share and improve what
684  you give them.
685  Help stamp out software-hoarding! 
686
687 \layout Section
688 Typographic conventions
689 \begin_inset LatexCommand \index{Typographic conventions}
690
691 \end_inset
692
693
694
695 \layout Standard
696 Throughout this manual, we will use the following convention.
697  Commands you have to type in are printed in 
698 \family sans
699 \series bold
700 "sans serif"
701 \series default
702 .
703
704 \family default
705  Code samples are printed in 
706 \family typewriter
707 typewriter font.
708
709 \family default
710  Interesting items and new terms are printed in 
711 \emph on
712 italic.
713
714 \layout Section
715 Compatibility
716 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
717
718 \end_inset
719
720  with previous versions
721 \begin_inset LatexCommand \index{Compatibility with previous versions}
722
723 \end_inset
724
725
726
727 \layout Standard
728 This version has numerous bug fixes compared with the previous version.
729  But we also introduced some incompatibilities with older versions.
730  Not just for the fun of it, but to make the compiler more stable, efficient
731  and ANSI compliant
732 \begin_inset LatexCommand \index{ANSI-compliance}
733
734 \end_inset
735
736  (see section 
737 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
738
739 \end_inset
740
741  for ANSI-Compliance).
742  
743 \newline
744
745
746 \layout Itemize
747 short is now equivalent to int (16 bits), it used to be equivalent to char
748  (8 bits) which is not ANSI compliant.
749
750 \layout Itemize
751 the default directory for gcc-builds where include, library and documentation
752  files are stored is now in /usr/local/share.
753
754 \layout Itemize
755 char type parameters to vararg
756 \begin_inset LatexCommand \index{vararg, va\_arg}
757
758 \end_inset
759
760  functions are casted to int unless explicitly casted
761 \begin_inset Marginal
762 collapsed true
763
764 \layout Standard
765
766 \series bold
767 \SpecialChar ~
768 !
769
770 \end_inset
771
772 , e.g.: 
773 \newline
774
775 \family typewriter
776 \SpecialChar ~
777 \SpecialChar ~
778 char a=3;
779 \newline
780 \SpecialChar ~
781 \SpecialChar ~
782 printf ("%d %c
783 \backslash
784 n", a, (char)a);
785 \family default
786
787 \newline
788  will push a as an int and as a char resp.
789
790 \layout Itemize
791 option -
792 \begin_inset ERT
793 status Collapsed
794
795 \layout Standard
796
797
798 \backslash
799 /
800
801 \end_inset
802
803 -regextend has been removed.
804
805 \layout Itemize
806 option -
807 \begin_inset ERT
808 status Collapsed
809
810 \layout Standard
811
812
813 \backslash
814 /
815
816 \end_inset
817
818 -noregparms has been removed.
819
820 \layout Itemize
821 option -
822 \begin_inset ERT
823 status Collapsed
824
825 \layout Standard
826
827
828 \backslash
829 /
830
831 \end_inset
832
833 -stack-after-data has been removed.
834
835 \layout Itemize
836 bit
837 \begin_inset LatexCommand \index{bit}
838
839 \end_inset
840
841  and sbit
842 \begin_inset LatexCommand \index{sbit}
843
844 \end_inset
845
846
847 \begin_inset LatexCommand \index{\_\_sbit}
848
849 \end_inset
850
851  types now consistently behave like the C99 _Bool type with respect to type
852  conversion
853 \begin_inset LatexCommand \index{type conversion}
854
855 \end_inset
856
857
858 \begin_inset LatexCommand \index{type promotion}
859
860 \end_inset
861
862 .
863  The most common incompatibility resulting from this change is related to
864  bit toggling
865 \begin_inset LatexCommand \index{Bit toggling}
866
867 \end_inset
868
869  idioms, e.g.:
870 \newline
871
872 \family typewriter
873 \SpecialChar ~
874 \SpecialChar ~
875 bit b;
876 \newline
877 \SpecialChar ~
878 \SpecialChar ~
879 b = ~
880 \begin_inset LatexCommand \index{\~\/ Operator}
881
882 \end_inset
883
884 b; /* equivalent to b=1 instead of toggling b */
885 \begin_inset Marginal
886 collapsed true
887
888 \layout Standard
889
890 \series bold
891 \SpecialChar ~
892 !
893
894 \end_inset
895
896
897 \newline
898 \SpecialChar ~
899 \SpecialChar ~
900 b = !b; /* toggles b */
901 \newline
902
903 \family default
904 In previous versions, both forms would have toggled the bit.
905
906 \layout Standard
907
908 \emph on
909 <pending: more incompatibilities?>
910
911 \layout Section
912 System Requirements
913
914 \layout Standard
915 What do you need before you start installation of SDCC? A computer, and
916  a desire to compute.
917  The preferred method of installation is to compile SDCC from source using
918  GNU gcc and make.
919  For Windows some pre-compiled binary distributions are available for your
920  convenience.
921  You should have some experience with command line tools and compiler use.
922
923 \layout Section
924 Other Resources
925
926 \layout Standard
927 The SDCC home page at 
928 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
929
930 \end_inset
931
932  is a great place to find distribution sets.
933  You can also find links to the user mailing lists that offer help or discuss
934  SDCC with other SDCC users.
935  Web links to other SDCC related sites can also be found here.
936  This document can be found in the DOC directory of the source package as
937  a text or HTML file.
938  A pdf version of this document is available at 
939 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
940
941 \end_inset
942
943 .
944  Some of the other tools (simulator and assembler) included with SDCC contain
945  their own documentation and can be found in the source distribution.
946  If you want the latest unreleased software, the complete source package
947  is available directly from Subversion on https://svn.sourceforge.net/svnroot/sdcc
948 /trunk/sdcc.
949
950 \layout Section
951 Wishes for the future
952
953 \layout Standard
954 There are (and always will be) some things that could be done.
955  Here are some I can think of:
956 \newline
957
958
959 \layout Standard
960
961 \family typewriter
962 char KernelFunction3(char p) at 0x340;
963 \newline
964
965
966 \layout Standard
967
968 \family typewriter
969 better code banking
970 \begin_inset LatexCommand \index{code banking (limited support)}
971
972 \end_inset
973
974  support for mcs51
975 \newline
976
977 \newline
978
979 \family default
980 If you can think of some more, please see the section 
981 \begin_inset LatexCommand \ref{sub:Requesting-Features}
982
983 \end_inset
984
985  about filing feature requests
986 \begin_inset LatexCommand \index{Requesting features}
987
988 \end_inset
989
990
991 \begin_inset LatexCommand \index{Feature request}
992
993 \end_inset
994
995 .
996 \newline
997
998
999 \layout Chapter
1000 Installing SDCC
1001 \begin_inset LatexCommand \index{Installation}
1002
1003 \end_inset
1004
1005
1006
1007 \layout Standard
1008 For most users it is sufficient to skip to either section 
1009 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1010
1011 \end_inset
1012
1013  (Unix) or section 
1014 \begin_inset LatexCommand \ref{sub:Windows-Install}
1015
1016 \end_inset
1017
1018  (Windows).
1019  More detailed instructions follow below.
1020
1021 \layout Section
1022 Configure Options
1023 \begin_inset LatexCommand \index{Options SDCC configuration}
1024
1025 \end_inset
1026
1027
1028
1029 \layout Standard
1030 The install paths, search paths and other options are defined when running
1031  'configure'.
1032  The defaults can be overridden by:
1033
1034 \layout List
1035 \labelwidthstring 00.00.0000
1036 -
1037 \begin_inset ERT
1038 status Collapsed
1039
1040 \layout Standard
1041
1042
1043 \backslash
1044 /
1045
1046 \end_inset
1047
1048 -prefix see table below
1049
1050 \layout List
1051 \labelwidthstring 00.00.0000
1052 -
1053 \begin_inset ERT
1054 status Collapsed
1055
1056 \layout Standard
1057
1058
1059 \backslash
1060 /
1061
1062 \end_inset
1063
1064 -exec_prefix see table below
1065
1066 \layout List
1067 \labelwidthstring 00.00.0000
1068 -
1069 \begin_inset ERT
1070 status Collapsed
1071
1072 \layout Standard
1073
1074
1075 \backslash
1076 /
1077
1078 \end_inset
1079
1080 -bindir see table below
1081
1082 \layout List
1083 \labelwidthstring 00.00.0000
1084 -
1085 \begin_inset ERT
1086 status Collapsed
1087
1088 \layout Standard
1089
1090
1091 \backslash
1092 /
1093
1094 \end_inset
1095
1096 -datadir see table below
1097
1098 \layout List
1099 \labelwidthstring 00.00.0000
1100 -
1101 \begin_inset ERT
1102 status Collapsed
1103
1104 \layout Standard
1105
1106
1107 \backslash
1108 /
1109
1110 \end_inset
1111
1112 -datarootdir see table below
1113 \newline
1114
1115
1116 \layout List
1117 \labelwidthstring 00.00.0000
1118 \SpecialChar ~
1119 \SpecialChar ~
1120 docdir environment variable, see table below
1121
1122 \layout List
1123 \labelwidthstring 00.00.0000
1124 \SpecialChar ~
1125 \SpecialChar ~
1126 include_dir_suffix environment variable, see table below
1127
1128 \layout List
1129 \labelwidthstring 00.00.0000
1130 \SpecialChar ~
1131 \SpecialChar ~
1132 lib_dir_suffix environment variable, see table below
1133
1134 \layout List
1135 \labelwidthstring 00.00.0000
1136 \SpecialChar ~
1137 \SpecialChar ~
1138 sdccconf_h_dir_separator environment variable, either / or 
1139 \backslash
1140
1141 \backslash
1142  makes sense here.
1143  This character will only be used in sdccconf.h; don't forget it's a C-header,
1144  therefore a double-backslash is needed there.
1145 \newline
1146
1147
1148 \layout List
1149 \labelwidthstring 00.00.0000
1150 -
1151 \begin_inset ERT
1152 status Collapsed
1153
1154 \layout Standard
1155
1156
1157 \backslash
1158 /
1159
1160 \end_inset
1161
1162 -disable-mcs51-port Excludes the Intel mcs51 port
1163
1164 \layout List
1165 \labelwidthstring 00.00.0000
1166 -
1167 \begin_inset ERT
1168 status Collapsed
1169
1170 \layout Standard
1171
1172
1173 \backslash
1174 /
1175
1176 \end_inset
1177
1178 -disable-gbz80-port Excludes the Gameboy gbz80 port
1179
1180 \layout List
1181 \labelwidthstring 00.00.0000
1182 -
1183 \begin_inset ERT
1184 status Collapsed
1185
1186 \layout Standard
1187
1188
1189 \backslash
1190 /
1191
1192 \end_inset
1193
1194 -disable-z80-port Excludes the z80 port
1195
1196 \layout List
1197 \labelwidthstring 00.00.0000
1198 -
1199 \begin_inset ERT
1200 status Collapsed
1201
1202 \layout Standard
1203
1204
1205 \backslash
1206 /
1207
1208 \end_inset
1209
1210 -disable-avr-port Excludes the AVR port
1211
1212 \layout List
1213 \labelwidthstring 00.00.0000
1214 -
1215 \begin_inset ERT
1216 status Collapsed
1217
1218 \layout Standard
1219
1220
1221 \backslash
1222 /
1223
1224 \end_inset
1225
1226 -disable-ds390-port Excludes the DS390 port
1227
1228 \layout List
1229 \labelwidthstring 00.00.0000
1230 -
1231 \begin_inset ERT
1232 status Collapsed
1233
1234 \layout Standard
1235
1236
1237 \backslash
1238 /
1239
1240 \end_inset
1241
1242 -disable-hc08-port Excludes the HC08 port
1243
1244 \layout List
1245 \labelwidthstring 00.00.0000
1246 -
1247 \begin_inset ERT
1248 status Collapsed
1249
1250 \layout Standard
1251
1252
1253 \backslash
1254 /
1255
1256 \end_inset
1257
1258 -disable-pic-port Excludes the PIC port
1259
1260 \layout List
1261 \labelwidthstring 00.00.0000
1262 -
1263 \begin_inset ERT
1264 status Collapsed
1265
1266 \layout Standard
1267
1268
1269 \backslash
1270 /
1271
1272 \end_inset
1273
1274 -disable-xa51-port Excludes the XA51 port
1275
1276 \layout List
1277 \labelwidthstring 00.00.0000
1278 -
1279 \begin_inset ERT
1280 status Collapsed
1281
1282 \layout Standard
1283
1284
1285 \backslash
1286 /
1287
1288 \end_inset
1289
1290 -disable-ucsim Disables configuring and building of ucsim
1291
1292 \layout List
1293 \labelwidthstring 00.00.0000
1294 -
1295 \begin_inset ERT
1296 status Collapsed
1297
1298 \layout Standard
1299
1300
1301 \backslash
1302 /
1303
1304 \end_inset
1305
1306 -disable-device-lib Disables automatically building device libraries
1307
1308 \layout List
1309 \labelwidthstring 00.00.0000
1310 -
1311 \begin_inset ERT
1312 status Collapsed
1313
1314 \layout Standard
1315
1316
1317 \backslash
1318 /
1319
1320 \end_inset
1321
1322 -disable-packihx Disables building packihx
1323 \newline
1324
1325
1326 \layout List
1327 \labelwidthstring 00.00.0000
1328 -
1329 \begin_inset ERT
1330 status Collapsed
1331
1332 \layout Standard
1333
1334
1335 \backslash
1336 /
1337
1338 \end_inset
1339
1340 -enable-doc Build pdf, html and txt files from the lyx sources
1341
1342 \layout List
1343 \labelwidthstring 00.00.0000
1344 -
1345 \begin_inset ERT
1346 status Collapsed
1347
1348 \layout Standard
1349
1350
1351 \backslash
1352 /
1353
1354 \end_inset
1355
1356 -enable-libgc Use the Bohem memory allocator.
1357  Lower runtime footprint.
1358
1359 \layout Standard
1360 Furthermore the environment variables CC, CFLAGS, ...
1361  the tools and their arguments can be influenced.
1362  Please see `configure -
1363 \begin_inset ERT
1364 status Collapsed
1365
1366 \layout Standard
1367
1368
1369 \backslash
1370 /
1371
1372 \end_inset
1373
1374 -help` and the man/info pages of `configure` for details.
1375 \newline
1376
1377 \newline
1378 The names of the
1379  standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1380 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1381  SDCC_LIB_NAME are defined by `configure` too.
1382  At the moment it's not possible to change the default settings (it was
1383  simply never required).
1384 \newline
1385
1386 \newline
1387 These configure options are compiled into the binaries,
1388  and can only be changed by rerunning 'configure' and recompiling SDCC.
1389  The configure options are written in 
1390 \emph on
1391 italics
1392 \emph default
1393  to distinguish them from run time environment variables (see section search
1394  paths).
1395 \newline
1396
1397 \newline
1398 The settings for 
1399 \begin_inset Quotes sld
1400 \end_inset
1401
1402 Win32 builds
1403 \begin_inset Quotes srd
1404 \end_inset
1405
1406  are used by the SDCC team to build the official Win32 binaries.
1407  The SDCC team uses Mingw32 to build the official Windows binaries, because
1408  it's
1409
1410 \layout Enumerate
1411 open source, 
1412
1413 \layout Enumerate
1414 a gcc compiler and last but not least
1415
1416 \layout Enumerate
1417 the binaries can be built by cross compiling on Sourceforge's compile farm.
1418
1419 \layout Standard
1420 See the examples, how to pass the Win32 settings to 'configure'.
1421  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1422  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1423  for Win32.
1424 \newline
1425
1426 \newline
1427 These defaults are:
1428 \newline
1429
1430
1431 \layout Standard
1432 \align center
1433 \begin_inset Tabular
1434 <lyxtabular version="3" rows="9" columns="3">
1435 <features>
1436 <column alignment="block" valignment="top" leftline="true" width="0in">
1437 <column alignment="block" valignment="top" leftline="true" width="0in">
1438 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1439 <row topline="true" bottomline="true">
1440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1441 \begin_inset Text
1442
1443 \layout Standard
1444 Variable
1445
1446 \end_inset
1447 </cell>
1448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1449 \begin_inset Text
1450
1451 \layout Standard
1452 default
1453
1454 \end_inset
1455 </cell>
1456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1457 \begin_inset Text
1458
1459 \layout Standard
1460 Win32 builds
1461
1462 \end_inset
1463 </cell>
1464 </row>
1465 <row topline="true">
1466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1467 \begin_inset Text
1468
1469 \layout Standard
1470
1471 \emph on
1472 PREFIX
1473
1474 \end_inset
1475 </cell>
1476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1477 \begin_inset Text
1478
1479 \layout Standard
1480 /usr/local
1481
1482 \end_inset
1483 </cell>
1484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1485 \begin_inset Text
1486
1487 \layout Standard
1488
1489 \backslash
1490 sdcc
1491
1492 \end_inset
1493 </cell>
1494 </row>
1495 <row topline="true">
1496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1497 \begin_inset Text
1498
1499 \layout Standard
1500
1501 \emph on
1502 EXEC_PREFIX
1503
1504 \end_inset
1505 </cell>
1506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1507 \begin_inset Text
1508
1509 \layout Standard
1510
1511 \emph on
1512 $PREFIX
1513
1514 \end_inset
1515 </cell>
1516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1517 \begin_inset Text
1518
1519 \layout Standard
1520
1521 \emph on
1522 $PREFIX
1523
1524 \end_inset
1525 </cell>
1526 </row>
1527 <row topline="true">
1528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1529 \begin_inset Text
1530
1531 \layout Standard
1532
1533 \emph on
1534 BINDIR
1535
1536 \end_inset
1537 </cell>
1538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1539 \begin_inset Text
1540
1541 \layout Standard
1542
1543 \emph on
1544 $EXEC_PREFIX
1545 \emph default
1546 /bin
1547
1548 \end_inset
1549 </cell>
1550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1551 \begin_inset Text
1552
1553 \layout Standard
1554
1555 \emph on
1556 $EXEC_PREFIX
1557 \emph default
1558
1559 \backslash
1560 bin
1561
1562 \end_inset
1563 </cell>
1564 </row>
1565 <row topline="true">
1566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1567 \begin_inset Text
1568
1569 \layout Standard
1570
1571 \emph on
1572 DATADIR
1573
1574 \end_inset
1575 </cell>
1576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1577 \begin_inset Text
1578
1579 \layout Standard
1580
1581 \emph on
1582 $DATAROOTDIR
1583
1584 \end_inset
1585 </cell>
1586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1587 \begin_inset Text
1588
1589 \layout Standard
1590
1591 \emph on
1592 $DATAROOTDIR
1593
1594 \end_inset
1595 </cell>
1596 </row>
1597 <row topline="true">
1598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1599 \begin_inset Text
1600
1601 \layout Standard
1602
1603 \emph on
1604 DATAROOTDIR
1605
1606 \end_inset
1607 </cell>
1608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1609 \begin_inset Text
1610
1611 \layout Standard
1612
1613 \emph on
1614 $PREFIX
1615 \emph default
1616 /share
1617
1618 \end_inset
1619 </cell>
1620 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1621 \begin_inset Text
1622
1623 \layout Standard
1624
1625 \emph on
1626 $PREFIX
1627
1628 \end_inset
1629 </cell>
1630 </row>
1631 <row topline="true">
1632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1633 \begin_inset Text
1634
1635 \layout Standard
1636
1637 \emph on
1638 DOCDIR
1639
1640 \end_inset
1641 </cell>
1642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1643 \begin_inset Text
1644
1645 \layout Standard
1646
1647 \emph on
1648 $DATAROOTDIR
1649 \emph default
1650 /sdcc/doc
1651
1652 \end_inset
1653 </cell>
1654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1655 \begin_inset Text
1656
1657 \layout Standard
1658
1659 \emph on
1660 $DATAROOTDIR
1661 \emph default
1662
1663 \backslash
1664 doc
1665
1666 \end_inset
1667 </cell>
1668 </row>
1669 <row topline="true">
1670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1671 \begin_inset Text
1672
1673 \layout Standard
1674
1675 \emph on
1676 INCLUDE_DIR_SUFFIX
1677
1678 \end_inset
1679 </cell>
1680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1681 \begin_inset Text
1682
1683 \layout Standard
1684 sdcc/include
1685
1686 \end_inset
1687 </cell>
1688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1689 \begin_inset Text
1690
1691 \layout Standard
1692 include
1693
1694 \end_inset
1695 </cell>
1696 </row>
1697 <row topline="true" bottomline="true">
1698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1699 \begin_inset Text
1700
1701 \layout Standard
1702
1703 \emph on
1704 LIB_DIR_SUFFIX
1705
1706 \end_inset
1707 </cell>
1708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1709 \begin_inset Text
1710
1711 \layout Standard
1712 sdcc/lib
1713
1714 \end_inset
1715 </cell>
1716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1717 \begin_inset Text
1718
1719 \layout Standard
1720 lib
1721
1722 \end_inset
1723 </cell>
1724 </row>
1725 </lyxtabular>
1726
1727 \end_inset
1728
1729
1730 \newline
1731
1732
1733 \layout Standard
1734 \noindent
1735 'configure' also computes relative paths.
1736  This is needed for full relocatability of a binary package and to complete
1737  search paths (see section search paths below):
1738 \newline
1739  
1740
1741 \layout Standard
1742 \align center
1743 \begin_inset Tabular
1744 <lyxtabular version="3" rows="4" columns="3">
1745 <features>
1746 <column alignment="block" valignment="top" leftline="true" width="0in">
1747 <column alignment="block" valignment="top" leftline="true" width="0in">
1748 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1749 <row topline="true" bottomline="true">
1750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1751 \begin_inset Text
1752
1753 \layout Standard
1754 Variable (computed)
1755
1756 \end_inset
1757 </cell>
1758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1759 \begin_inset Text
1760
1761 \layout Standard
1762 default
1763
1764 \end_inset
1765 </cell>
1766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1767 \begin_inset Text
1768
1769 \layout Standard
1770 Win32 builds
1771
1772 \end_inset
1773 </cell>
1774 </row>
1775 <row topline="true" bottomline="true">
1776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1777 \begin_inset Text
1778
1779 \layout Standard
1780
1781 \emph on
1782 BIN2DATA_DIR
1783
1784 \end_inset
1785 </cell>
1786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1787 \begin_inset Text
1788
1789 \layout Standard
1790 ../share
1791
1792 \end_inset
1793 </cell>
1794 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1795 \begin_inset Text
1796
1797 \layout Standard
1798 ..
1799
1800 \end_inset
1801 </cell>
1802 </row>
1803 <row bottomline="true">
1804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1805 \begin_inset Text
1806
1807 \layout Standard
1808
1809 \emph on
1810 PREFIX2BIN_DIR
1811
1812 \end_inset
1813 </cell>
1814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1815 \begin_inset Text
1816
1817 \layout Standard
1818 bin
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 \layout Standard
1826 bin
1827
1828 \end_inset
1829 </cell>
1830 </row>
1831 <row bottomline="true">
1832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1833 \begin_inset Text
1834
1835 \layout Standard
1836
1837 \emph on
1838 PREFIX2DATA_DIR
1839
1840 \end_inset
1841 </cell>
1842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1843 \begin_inset Text
1844
1845 \layout Standard
1846 share/sdcc
1847
1848 \end_inset
1849 </cell>
1850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1851 \begin_inset Text
1852
1853 \layout Standard
1854
1855
1856 \end_inset
1857 </cell>
1858 </row>
1859 </lyxtabular>
1860
1861 \end_inset
1862
1863
1864 \newline
1865
1866
1867 \layout Standard
1868 \noindent
1869 Examples:
1870
1871 \layout LyX-Code
1872 ./configure
1873 \newline
1874 ./configure -
1875 \begin_inset ERT
1876 status Collapsed
1877
1878 \layout Standard
1879
1880
1881 \backslash
1882 /
1883
1884 \end_inset
1885
1886 -prefix=
1887 \begin_inset Quotes srd
1888 \end_inset
1889
1890 /usr/bin
1891 \begin_inset Quotes srd
1892 \end_inset
1893
1894  -
1895 \begin_inset ERT
1896 status Collapsed
1897
1898 \layout Standard
1899
1900
1901 \backslash
1902 /
1903
1904 \end_inset
1905
1906 -datarootdir=
1907 \begin_inset Quotes srd
1908 \end_inset
1909
1910 /usr/share
1911 \begin_inset Quotes srd
1912 \end_inset
1913
1914
1915 \newline
1916 ./configure -
1917 \begin_inset ERT
1918 status Collapsed
1919
1920 \layout Standard
1921
1922
1923 \backslash
1924 /
1925
1926 \end_inset
1927
1928 -disable-avr-port -
1929 \begin_inset ERT
1930 status Collapsed
1931
1932 \layout Standard
1933
1934
1935 \backslash
1936 /
1937
1938 \end_inset
1939
1940 -disable-xa51-port
1941
1942 \layout Standard
1943 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1944 32'):
1945
1946 \layout LyX-Code
1947 ./configure 
1948 \backslash
1949
1950 \newline
1951 CC=
1952 \begin_inset Quotes srd
1953 \end_inset
1954
1955 i586-mingw32msvc-gcc
1956 \begin_inset Quotes srd
1957 \end_inset
1958
1959  CXX=
1960 \begin_inset Quotes srd
1961 \end_inset
1962
1963 i586-mingw32msvc-g++
1964 \begin_inset Quotes srd
1965 \end_inset
1966
1967  
1968 \backslash
1969  
1970 \newline
1971 RANLIB=
1972 \begin_inset Quotes srd
1973 \end_inset
1974
1975 i586-mingw32msvc-ranlib
1976 \begin_inset Quotes srd
1977 \end_inset
1978
1979  
1980 \backslash
1981
1982 \newline
1983 STRIP=
1984 \begin_inset Quotes srd
1985 \end_inset
1986
1987 i586-mingw32msvc-strip
1988 \begin_inset Quotes srd
1989 \end_inset
1990
1991  
1992 \backslash
1993
1994 \newline
1995 -
1996 \begin_inset ERT
1997 status Collapsed
1998
1999 \layout Standard
2000
2001
2002 \backslash
2003 /
2004
2005 \end_inset
2006
2007 -prefix=
2008 \begin_inset Quotes srd
2009 \end_inset
2010
2011 /sdcc
2012 \begin_inset Quotes srd
2013 \end_inset
2014
2015  
2016 \backslash
2017
2018 \newline
2019 -
2020 \begin_inset ERT
2021 status Collapsed
2022
2023 \layout Standard
2024
2025
2026 \backslash
2027 /
2028
2029 \end_inset
2030
2031 -datarootdir=
2032 \begin_inset Quotes srd
2033 \end_inset
2034
2035 /sdcc
2036 \begin_inset Quotes srd
2037 \end_inset
2038
2039  
2040 \backslash
2041
2042 \newline
2043 docdir=
2044 \begin_inset Quotes srd
2045 \end_inset
2046
2047
2048 \backslash
2049 ${datarootdir}/doc
2050 \begin_inset Quotes srd
2051 \end_inset
2052
2053  
2054 \backslash
2055
2056 \newline
2057 include_dir_suffix=
2058 \begin_inset Quotes srd
2059 \end_inset
2060
2061 include
2062 \begin_inset Quotes srd
2063 \end_inset
2064
2065  
2066 \backslash
2067
2068 \newline
2069 lib_dir_suffix=
2070 \begin_inset Quotes srd
2071 \end_inset
2072
2073 lib
2074 \begin_inset Quotes srd
2075 \end_inset
2076
2077  
2078 \backslash
2079
2080 \newline
2081 sdccconf_h_dir_separator=
2082 \begin_inset Quotes srd
2083 \end_inset
2084
2085
2086 \backslash
2087
2088 \backslash
2089
2090 \backslash
2091
2092 \backslash
2093
2094 \begin_inset Quotes srd
2095 \end_inset
2096
2097  
2098 \backslash
2099
2100 \newline
2101 -
2102 \begin_inset ERT
2103 status Collapsed
2104
2105 \layout Standard
2106
2107
2108 \backslash
2109 /
2110
2111 \end_inset
2112
2113 -disable-device-lib
2114 \backslash
2115
2116 \newline
2117 -
2118 \begin_inset ERT
2119 status Collapsed
2120
2121 \layout Standard
2122
2123
2124 \backslash
2125 /
2126
2127 \end_inset
2128
2129 -host=i586-mingw32msvc
2130 \backslash
2131
2132 \newline
2133 -
2134 \begin_inset ERT
2135 status Collapsed
2136
2137 \layout Standard
2138
2139
2140 \backslash
2141 /
2142
2143 \end_inset
2144
2145 -build=unknown-unknown-linux-gnu
2146
2147 \layout Standard
2148 To 
2149 \begin_inset Quotes sld
2150 \end_inset
2151
2152 cross
2153 \begin_inset Quotes srd
2154 \end_inset
2155
2156 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2157 ):
2158
2159 \layout LyX-Code
2160 ./configure -C 
2161 \backslash
2162
2163 \newline
2164 -
2165 \begin_inset ERT
2166 status Collapsed
2167
2168 \layout Standard
2169
2170
2171 \backslash
2172 /
2173
2174 \end_inset
2175
2176 -prefix=
2177 \begin_inset Quotes srd
2178 \end_inset
2179
2180 /sdcc
2181 \begin_inset Quotes srd
2182 \end_inset
2183
2184  
2185 \backslash
2186
2187 \newline
2188 -
2189 \begin_inset ERT
2190 status Collapsed
2191
2192 \layout Standard
2193
2194
2195 \backslash
2196 /
2197
2198 \end_inset
2199
2200 -datarootdir=
2201 \begin_inset Quotes srd
2202 \end_inset
2203
2204 /sdcc
2205 \begin_inset Quotes srd
2206 \end_inset
2207
2208  
2209 \backslash
2210
2211 \newline
2212 docdir=
2213 \begin_inset Quotes srd
2214 \end_inset
2215
2216
2217 \backslash
2218 ${datarootdir}/doc
2219 \begin_inset Quotes srd
2220 \end_inset
2221
2222  
2223 \backslash
2224  
2225 \newline
2226 include_dir_suffix=
2227 \begin_inset Quotes srd
2228 \end_inset
2229
2230 include
2231 \begin_inset Quotes srd
2232 \end_inset
2233
2234  
2235 \backslash
2236
2237 \newline
2238 lib_dir_suffix=
2239 \begin_inset Quotes srd
2240 \end_inset
2241
2242 lib
2243 \begin_inset Quotes srd
2244 \end_inset
2245
2246  
2247 \backslash
2248
2249 \newline
2250 sdccconf_h_dir_separator=
2251 \begin_inset Quotes srd
2252 \end_inset
2253
2254
2255 \backslash
2256
2257 \backslash
2258
2259 \backslash
2260
2261 \backslash
2262
2263 \begin_inset Quotes srd
2264 \end_inset
2265
2266  
2267 \backslash
2268
2269 \newline
2270 CC=
2271 \begin_inset Quotes srd
2272 \end_inset
2273
2274 gcc -mno-cygwin
2275 \begin_inset Quotes srd
2276 \end_inset
2277
2278  
2279 \backslash
2280
2281 \newline
2282 CXX=
2283 \begin_inset Quotes srd
2284 \end_inset
2285
2286 g++ -mno-cygwin
2287 \begin_inset Quotes srd
2288 \end_inset
2289
2290  
2291
2292 \layout Standard
2293 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2294  The option '-
2295 \begin_inset ERT
2296 status Collapsed
2297
2298 \layout Standard
2299
2300
2301 \backslash
2302 /
2303
2304 \end_inset
2305
2306 -C' turns on caching, which gives a little bit extra speed.
2307  However if options are changed, it can be necessary to delete the config.cache
2308  file.
2309
2310 \layout Section
2311 Install paths
2312 \added_space_bottom medskip 
2313 \begin_inset LatexCommand \label{sub:Install-paths}
2314
2315 \end_inset
2316
2317
2318 \begin_inset LatexCommand \index{Install paths}
2319
2320 \end_inset
2321
2322
2323
2324
2325 \layout Standard
2326 \align center
2327 \begin_inset Tabular
2328 <lyxtabular version="3" rows="5" columns="4">
2329 <features>
2330 <column alignment="left" valignment="top" leftline="true" width="0">
2331 <column alignment="left" valignment="top" leftline="true" width="0">
2332 <column alignment="left" valignment="top" leftline="true" width="0">
2333 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2334 <row topline="true" bottomline="true">
2335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2336 \begin_inset Text
2337
2338 \layout Standard
2339
2340 \series bold
2341 Description
2342
2343 \end_inset
2344 </cell>
2345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2346 \begin_inset Text
2347
2348 \layout Standard
2349
2350 \series bold
2351 Path
2352
2353 \end_inset
2354 </cell>
2355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2356 \begin_inset Text
2357
2358 \layout Standard
2359
2360 \series bold
2361 Default
2362
2363 \end_inset
2364 </cell>
2365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2366 \begin_inset Text
2367
2368 \layout Standard
2369
2370 \series bold
2371 Win32 builds
2372
2373 \end_inset
2374 </cell>
2375 </row>
2376 <row topline="true">
2377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2378 \begin_inset Text
2379
2380 \layout Standard
2381 Binary files*
2382
2383 \end_inset
2384 </cell>
2385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2386 \begin_inset Text
2387
2388 \layout Standard
2389
2390 \emph on
2391 $EXEC_PREFIX
2392
2393 \end_inset
2394 </cell>
2395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2396 \begin_inset Text
2397
2398 \layout Standard
2399 /usr/local/bin
2400
2401 \end_inset
2402 </cell>
2403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2404 \begin_inset Text
2405
2406 \layout Standard
2407
2408 \backslash
2409 sdcc
2410 \backslash
2411 bin
2412
2413 \end_inset
2414 </cell>
2415 </row>
2416 <row topline="true">
2417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2418 \begin_inset Text
2419
2420 \layout Standard
2421 Include files
2422
2423 \end_inset
2424 </cell>
2425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2426 \begin_inset Text
2427
2428 \layout Standard
2429
2430 \emph on
2431 $DATADIR/ $INCLUDE_DIR_SUFFIX
2432
2433 \end_inset
2434 </cell>
2435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2436 \begin_inset Text
2437
2438 \layout Standard
2439 /usr/local/share/sdcc/include
2440
2441 \end_inset
2442 </cell>
2443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2444 \begin_inset Text
2445
2446 \layout Standard
2447
2448 \backslash
2449 sdcc
2450 \backslash
2451 include
2452
2453 \end_inset
2454 </cell>
2455 </row>
2456 <row topline="true">
2457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2458 \begin_inset Text
2459
2460 \layout Standard
2461 Library file**
2462
2463 \end_inset
2464 </cell>
2465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2466 \begin_inset Text
2467
2468 \layout Standard
2469
2470 \emph on
2471 $DATADIR/$LIB_DIR_SUFFIX
2472
2473 \end_inset
2474 </cell>
2475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2476 \begin_inset Text
2477
2478 \layout Standard
2479 /usr/local/share/sdcc/lib
2480
2481 \end_inset
2482 </cell>
2483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2484 \begin_inset Text
2485
2486 \layout Standard
2487
2488 \backslash
2489 sdcc
2490 \backslash
2491 lib
2492
2493 \end_inset
2494 </cell>
2495 </row>
2496 <row topline="true" bottomline="true">
2497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2498 \begin_inset Text
2499
2500 \layout Standard
2501 Documentation
2502
2503 \end_inset
2504 </cell>
2505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2506 \begin_inset Text
2507
2508 \layout Standard
2509
2510 \emph on
2511 $DOCDIR
2512
2513 \end_inset
2514 </cell>
2515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2516 \begin_inset Text
2517
2518 \layout Standard
2519 /usr/local/share/sdcc/doc
2520
2521 \end_inset
2522 </cell>
2523 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2524 \begin_inset Text
2525
2526 \layout Standard
2527
2528 \backslash
2529 sdcc
2530 \backslash
2531 doc
2532
2533 \end_inset
2534 </cell>
2535 </row>
2536 </lyxtabular>
2537
2538 \end_inset
2539
2540
2541
2542 \layout Verse
2543
2544 \size footnotesize
2545 *compiler, preprocessor, assembler, and linker
2546 \newline
2547 **the 
2548 \shape italic
2549 model
2550 \shape default
2551  is auto-appended by the compiler, e.g.
2552  small, large, z80, ds390 etc
2553
2554 \layout Standard
2555 \noindent
2556 The install paths can still be changed during `make install` with e.g.:
2557
2558 \layout LyX-Code
2559 make install prefix=$(HOME)/local/sdcc
2560
2561 \layout Standard
2562 Of course this doesn't change the search paths compiled into the binaries.
2563 \newline
2564
2565 \newline
2566 Moreove
2567 r the install path can be changed by defining DESTDIR
2568 \begin_inset LatexCommand \index{DESTDIR}
2569
2570 \end_inset
2571
2572 :
2573
2574 \layout LyX-Code
2575 make install DESTDIR=$(HOME)/sdcc.rpm/
2576
2577 \layout Standard
2578 Please note that DESTDIR must have a trailing slash!
2579
2580 \layout Section
2581 Search Paths
2582 \begin_inset LatexCommand \label{sub:Search-Paths}
2583
2584 \end_inset
2585
2586
2587 \begin_inset LatexCommand \index{Search path}
2588
2589 \end_inset
2590
2591
2592
2593 \layout Standard
2594 Some search paths or parts of them are determined by configure variables
2595  (in 
2596 \emph on
2597 italics
2598 \emph default
2599 , see section above).
2600  Further search paths are determined by environment variables during runtime.
2601  
2602 \newline
2603 The paths searched when running the compiler are as follows (the first
2604  catch wins):
2605 \newline
2606
2607 \newline
2608 1.
2609  Binary files (preprocessor, assembler and linker)
2610 \newline
2611
2612
2613 \layout Standard
2614 \align center
2615 \begin_inset Tabular
2616 <lyxtabular version="3" rows="4" columns="3">
2617 <features>
2618 <column alignment="block" valignment="top" leftline="true" width="0in">
2619 <column alignment="block" valignment="top" leftline="true" width="0in">
2620 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2621 <row topline="true" bottomline="true">
2622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2623 \begin_inset Text
2624
2625 \layout Standard
2626 Search path
2627
2628 \end_inset
2629 </cell>
2630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2631 \begin_inset Text
2632
2633 \layout Standard
2634 default
2635
2636 \end_inset
2637 </cell>
2638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2639 \begin_inset Text
2640
2641 \layout Standard
2642 Win32 builds
2643
2644 \end_inset
2645 </cell>
2646 </row>
2647 <row topline="true">
2648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2649 \begin_inset Text
2650
2651 \layout Standard
2652 $SDCC_HOME/
2653 \emph on
2654 $PPREFIX2BIN_DIR
2655
2656 \end_inset
2657 </cell>
2658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2659 \begin_inset Text
2660
2661 \layout Standard
2662 $SDCC_HOME/bin
2663
2664 \end_inset
2665 </cell>
2666 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2667 \begin_inset Text
2668
2669 \layout Standard
2670 $SDCC_HOME
2671 \backslash
2672 bin
2673
2674 \end_inset
2675 </cell>
2676 </row>
2677 <row topline="true">
2678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2679 \begin_inset Text
2680
2681 \layout Standard
2682 Path of argv[0] (if available)
2683
2684 \end_inset
2685 </cell>
2686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2687 \begin_inset Text
2688
2689 \layout Standard
2690 Path of argv[0]
2691
2692 \end_inset
2693 </cell>
2694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2695 \begin_inset Text
2696
2697 \layout Standard
2698 Path of argv[0]
2699
2700 \end_inset
2701 </cell>
2702 </row>
2703 <row topline="true" bottomline="true">
2704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2705 \begin_inset Text
2706
2707 \layout Standard
2708 $PATH
2709
2710 \end_inset
2711 </cell>
2712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2713 \begin_inset Text
2714
2715 \layout Standard
2716 $PATH
2717
2718 \end_inset
2719 </cell>
2720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2721 \begin_inset Text
2722
2723 \layout Standard
2724 $PATH
2725
2726 \end_inset
2727 </cell>
2728 </row>
2729 </lyxtabular>
2730
2731 \end_inset
2732
2733  
2734 \newline
2735
2736
2737 \layout Standard
2738 \noindent
2739 2.
2740  Include files
2741 \newline
2742
2743
2744 \layout Standard
2745 \align center
2746 \begin_inset Tabular
2747 <lyxtabular version="3" rows="6" columns="3">
2748 <features>
2749 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2750 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2751 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2752 <row topline="true" bottomline="true">
2753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2754 \begin_inset Text
2755
2756 \layout Standard
2757 Search path
2758
2759 \end_inset
2760 </cell>
2761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2762 \begin_inset Text
2763
2764 \layout Standard
2765 default
2766
2767 \end_inset
2768 </cell>
2769 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2770 \begin_inset Text
2771
2772 \layout Standard
2773 Win32 builds
2774
2775 \end_inset
2776 </cell>
2777 </row>
2778 <row topline="true">
2779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2780 \begin_inset Text
2781
2782 \layout Standard
2783 -
2784 \begin_inset ERT
2785 status Collapsed
2786
2787 \layout Standard
2788
2789
2790 \backslash
2791 /
2792
2793 \end_inset
2794
2795 -I dir
2796
2797 \end_inset
2798 </cell>
2799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2800 \begin_inset Text
2801
2802 \layout Standard
2803 -
2804 \begin_inset ERT
2805 status Collapsed
2806
2807 \layout Standard
2808
2809
2810 \backslash
2811 /
2812
2813 \end_inset
2814
2815 -I dir
2816
2817 \end_inset
2818 </cell>
2819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2820 \begin_inset Text
2821
2822 \layout Standard
2823 -
2824 \begin_inset ERT
2825 status Collapsed
2826
2827 \layout Standard
2828
2829
2830 \backslash
2831 /
2832
2833 \end_inset
2834
2835 -I dir
2836
2837 \end_inset
2838 </cell>
2839 </row>
2840 <row topline="true">
2841 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2842 \begin_inset Text
2843
2844 \layout Standard
2845 $SDCC_INCLUDE
2846
2847 \end_inset
2848 </cell>
2849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2850 \begin_inset Text
2851
2852 \layout Standard
2853 $SDCC_INCLUDE
2854
2855 \end_inset
2856 </cell>
2857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2858 \begin_inset Text
2859
2860 \layout Standard
2861 $SDCC_INCLUDE
2862
2863 \end_inset
2864 </cell>
2865 </row>
2866 <row topline="true">
2867 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2868 \begin_inset Text
2869
2870 \layout Standard
2871 $SDCC_HOME/
2872 \newline
2873
2874 \emph on
2875 $PREFIX2DATA_DIR/
2876 \newline
2877 $INCLUDE_DIR_SUFFIX
2878
2879 \end_inset
2880 </cell>
2881 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2882 \begin_inset Text
2883
2884 \layout Standard
2885 $SDCC_ HOME/
2886 \newline
2887 share/sdcc/
2888 \newline
2889 include
2890
2891 \end_inset
2892 </cell>
2893 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2894 \begin_inset Text
2895
2896 \layout Standard
2897 $SDCC_HOME
2898 \backslash
2899 include
2900
2901 \end_inset
2902 </cell>
2903 </row>
2904 <row topline="true">
2905 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2906 \begin_inset Text
2907
2908 \layout Standard
2909 path(argv[0])/
2910 \newline
2911
2912 \emph on
2913 $BIN2DATADIR/
2914 \emph default
2915
2916 \newline
2917
2918 \emph on
2919 $INCLUDE_DIR_SUFFIX
2920
2921 \end_inset
2922 </cell>
2923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2924 \begin_inset Text
2925
2926 \layout Standard
2927 path(argv[0])/
2928 \newline
2929 ../sdcc/include
2930 \newline
2931 \SpecialChar ~
2932 \SpecialChar ~
2933 \SpecialChar ~
2934 \SpecialChar ~
2935 \SpecialChar ~
2936 \SpecialChar ~
2937 \SpecialChar ~
2938 \SpecialChar ~
2939 \SpecialChar ~
2940 \SpecialChar ~
2941 \SpecialChar ~
2942 \SpecialChar ~
2943 \SpecialChar ~
2944 \SpecialChar ~
2945 \SpecialChar ~
2946 \SpecialChar ~
2947 \SpecialChar ~
2948 \SpecialChar ~
2949 \SpecialChar ~
2950 \SpecialChar ~
2951 \SpecialChar ~
2952 \SpecialChar ~
2953 \SpecialChar ~
2954 \SpecialChar ~
2955 \SpecialChar ~
2956 \SpecialChar ~
2957 \SpecialChar ~
2958 \SpecialChar ~
2959 \SpecialChar ~
2960 \SpecialChar ~
2961 \SpecialChar ~
2962 \SpecialChar ~
2963 \SpecialChar ~
2964 \SpecialChar ~
2965 \SpecialChar ~
2966 \SpecialChar ~
2967 \SpecialChar ~
2968 \SpecialChar ~
2969
2970
2971 \end_inset
2972 </cell>
2973 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2974 \begin_inset Text
2975
2976 \layout Standard
2977 path(argv[0])
2978 \backslash
2979 ..
2980 \backslash
2981 include
2982
2983 \end_inset
2984 </cell>
2985 </row>
2986 <row topline="true" bottomline="true">
2987 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2988 \begin_inset Text
2989
2990 \layout Standard
2991
2992 \emph on
2993 $DATADIR/
2994 \emph default
2995
2996 \newline
2997
2998 \emph on
2999 $INCLUDE_DIR_SUFFIX
3000
3001 \end_inset
3002 </cell>
3003 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3004 \begin_inset Text
3005
3006 \layout Standard
3007 /usr/local/share/sdcc/
3008 \newline
3009 include
3010
3011 \end_inset
3012 </cell>
3013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3014 \begin_inset Text
3015
3016 \layout Standard
3017 (not on Win32)
3018
3019 \end_inset
3020 </cell>
3021 </row>
3022 </lyxtabular>
3023
3024 \end_inset
3025
3026  
3027 \newline
3028
3029
3030 \layout Standard
3031 \noindent
3032 The option -
3033 \begin_inset ERT
3034 status Collapsed
3035
3036 \layout Standard
3037
3038
3039 \backslash
3040 /
3041
3042 \end_inset
3043
3044 -nostdinc disables the last two search paths.
3045 \newline
3046
3047 \newline
3048 3.
3049  Library files 
3050 \newline
3051
3052
3053 \layout Standard
3054 With the exception of 
3055 \begin_inset Quotes sld
3056 \end_inset
3057
3058 -
3059 \begin_inset ERT
3060 status Collapsed
3061
3062 \layout Standard
3063
3064
3065 \backslash
3066 /
3067
3068 \end_inset
3069
3070 -L dir
3071 \begin_inset Quotes srd
3072 \end_inset
3073
3074  the 
3075 \shape italic
3076 model
3077 \shape default
3078  is auto-appended by the compiler (e.g.
3079  small, large, z80, ds390 etc.).
3080  
3081 \newline
3082
3083
3084 \layout Standard
3085 \align center
3086 \begin_inset Tabular
3087 <lyxtabular version="3" rows="6" columns="3">
3088 <features>
3089 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3090 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3091 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3092 <row topline="true" bottomline="true">
3093 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3094 \begin_inset Text
3095
3096 \layout Standard
3097 Search path
3098
3099 \end_inset
3100 </cell>
3101 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3102 \begin_inset Text
3103
3104 \layout Standard
3105 default
3106
3107 \end_inset
3108 </cell>
3109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3110 \begin_inset Text
3111
3112 \layout Standard
3113 Win32 builds
3114
3115 \end_inset
3116 </cell>
3117 </row>
3118 <row topline="true">
3119 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3120 \begin_inset Text
3121
3122 \layout Standard
3123 -
3124 \begin_inset ERT
3125 status Collapsed
3126
3127 \layout Standard
3128
3129
3130 \backslash
3131 /
3132
3133 \end_inset
3134
3135 -L dir
3136
3137 \end_inset
3138 </cell>
3139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3140 \begin_inset Text
3141
3142 \layout Standard
3143 -
3144 \begin_inset ERT
3145 status Collapsed
3146
3147 \layout Standard
3148
3149
3150 \backslash
3151 /
3152
3153 \end_inset
3154
3155 -L dir
3156
3157 \end_inset
3158 </cell>
3159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3160 \begin_inset Text
3161
3162 \layout Standard
3163 -
3164 \begin_inset ERT
3165 status Collapsed
3166
3167 \layout Standard
3168
3169
3170 \backslash
3171 /
3172
3173 \end_inset
3174
3175 -L dir
3176
3177 \end_inset
3178 </cell>
3179 </row>
3180 <row topline="true">
3181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3182 \begin_inset Text
3183
3184 \layout Standard
3185 $SDCC_LIB/
3186 \newline
3187
3188 \emph on
3189 <model>
3190
3191 \end_inset
3192 </cell>
3193 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3194 \begin_inset Text
3195
3196 \layout Standard
3197 $SDCC_LIB/
3198 \newline
3199
3200 \emph on
3201 <model>
3202
3203 \end_inset
3204 </cell>
3205 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3206 \begin_inset Text
3207
3208 \layout Standard
3209 $SDCC_LIB
3210 \backslash
3211
3212 \newline
3213
3214 \emph on
3215 <model>
3216
3217 \end_inset
3218 </cell>
3219 </row>
3220 <row topline="true">
3221 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3222 \begin_inset Text
3223
3224 \layout Standard
3225 $SDCC_HOME/
3226 \newline
3227
3228 \emph on
3229 $PREFIX2DATA_DIR/
3230 \newline
3231 $LIB_DIR_SUFFIX/<model>
3232
3233 \end_inset
3234 </cell>
3235 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3236 \begin_inset Text
3237
3238 \layout Standard
3239 $SDCC_HOME/
3240 \newline
3241 share/sdcc/
3242 \newline
3243 lib/
3244 \emph on
3245 <model>
3246
3247 \end_inset
3248 </cell>
3249 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3250 \begin_inset Text
3251
3252 \layout Standard
3253 $SDCC_HOME
3254 \backslash
3255 lib
3256 \backslash
3257
3258 \emph on
3259
3260 \newline
3261 <model>
3262
3263 \end_inset
3264 </cell>
3265 </row>
3266 <row topline="true">
3267 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3268 \begin_inset Text
3269
3270 \layout Standard
3271 path(argv[0])/
3272 \newline
3273
3274 \emph on
3275 $BIN2DATADIR/
3276 \emph default
3277
3278 \newline
3279
3280 \emph on
3281 $LIB_DIR_SUFFIX/<model>
3282
3283 \end_inset
3284 </cell>
3285 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3286 \begin_inset Text
3287
3288 \layout Standard
3289 path(argv[0])/
3290 \newline
3291 ../sdcc/lib/
3292 \emph on
3293 <model>
3294 \newline
3295 \SpecialChar ~
3296 \SpecialChar ~
3297 \SpecialChar ~
3298 \SpecialChar ~
3299 \SpecialChar ~
3300 \SpecialChar ~
3301 \SpecialChar ~
3302 \SpecialChar ~
3303 \SpecialChar ~
3304 \SpecialChar ~
3305 \SpecialChar ~
3306 \SpecialChar ~
3307 \SpecialChar ~
3308 \SpecialChar ~
3309 \SpecialChar ~
3310 \SpecialChar ~
3311 \SpecialChar ~
3312 \SpecialChar ~
3313 \SpecialChar ~
3314 \SpecialChar ~
3315 \SpecialChar ~
3316 \SpecialChar ~
3317 \SpecialChar ~
3318 \SpecialChar ~
3319 \SpecialChar ~
3320 \SpecialChar ~
3321 \SpecialChar ~
3322 \SpecialChar ~
3323 \SpecialChar ~
3324 \SpecialChar ~
3325 \SpecialChar ~
3326 \SpecialChar ~
3327 \SpecialChar ~
3328 \SpecialChar ~
3329 \SpecialChar ~
3330 \SpecialChar ~
3331 \SpecialChar ~
3332 \SpecialChar ~
3333 \SpecialChar ~
3334
3335
3336 \end_inset
3337 </cell>
3338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3339 \begin_inset Text
3340
3341 \layout Standard
3342 path(argv[0])
3343 \backslash
3344
3345 \newline
3346 ..
3347 \backslash
3348 lib
3349 \backslash
3350
3351 \emph on
3352 <model>
3353 \newline
3354 \SpecialChar ~
3355 \SpecialChar ~
3356 \SpecialChar ~
3357 \SpecialChar ~
3358 \SpecialChar ~
3359 \SpecialChar ~
3360 \SpecialChar ~
3361 \SpecialChar ~
3362 \SpecialChar ~
3363 \SpecialChar ~
3364 \SpecialChar ~
3365 \SpecialChar ~
3366 \SpecialChar ~
3367 \SpecialChar ~
3368 \SpecialChar ~
3369 \SpecialChar ~
3370 \SpecialChar ~
3371 \SpecialChar ~
3372 \SpecialChar ~
3373 \SpecialChar ~
3374 \SpecialChar ~
3375 \SpecialChar ~
3376 \SpecialChar ~
3377 \SpecialChar ~
3378 \SpecialChar ~
3379 \SpecialChar ~
3380 \SpecialChar ~
3381 \SpecialChar ~
3382 \SpecialChar ~
3383 \SpecialChar ~
3384 \SpecialChar ~
3385 \SpecialChar ~
3386 \SpecialChar ~
3387 \SpecialChar ~
3388 \SpecialChar ~
3389
3390
3391 \end_inset
3392 </cell>
3393 </row>
3394 <row topline="true" bottomline="true">
3395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3396 \begin_inset Text
3397
3398 \layout Standard
3399
3400 \emph on
3401 $DATADIR/
3402 \newline
3403 $LIB_DIR_SUFFIX/<model>
3404
3405 \end_inset
3406 </cell>
3407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3408 \begin_inset Text
3409
3410 \layout Standard
3411 /usr/local/share/sdcc/
3412 \newline
3413 lib/
3414 \emph on
3415 <model>
3416
3417 \end_inset
3418 </cell>
3419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3420 \begin_inset Text
3421
3422 \layout Standard
3423 (not on Win32)
3424
3425 \end_inset
3426 </cell>
3427 </row>
3428 </lyxtabular>
3429
3430 \end_inset
3431
3432
3433 \newline
3434
3435
3436 \layout Standard
3437 \begin_inset Note
3438 collapsed true
3439
3440 \layout Standard
3441 Don't delete any of the stray spaces in the table above without checking
3442  the HTML output (last line)!
3443
3444 \end_inset
3445
3446
3447
3448 \layout Standard
3449 \SpecialChar ~
3450
3451 \newline
3452 The option -
3453 \begin_inset ERT
3454 status Collapsed
3455
3456 \layout Standard
3457
3458
3459 \backslash
3460 /
3461
3462 \end_inset
3463
3464 -nostdlib disables the last two search paths.
3465
3466 \layout Section
3467 Building SDCC
3468 \begin_inset LatexCommand \index{Building SDCC}
3469
3470 \end_inset
3471
3472
3473
3474 \layout Subsection
3475 Building SDCC on Linux
3476 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3477
3478 \end_inset
3479
3480
3481
3482 \layout Enumerate
3483
3484 \series medium
3485 Download the source package
3486 \series default
3487  either from the SDCC Subversion repository or from the nightly snapshots
3488 \series medium
3489 , it will be named something like sdcc
3490 \series default
3491 .src
3492 \series medium
3493 .t
3494 \series default
3495 ar.
3496 \series medium
3497 gz
3498 \series default
3499  
3500 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3501
3502 \end_inset
3503
3504 .
3505
3506 \layout Enumerate
3507
3508 \series medium
3509 Bring up a command line terminal, such as xterm.
3510
3511 \layout Enumerate
3512
3513 \series medium
3514 Unpack the file using a command like: 
3515 \family sans
3516 \series bold
3517 "tar -xvzf sdcc.src.tar.gz
3518 \family default
3519 \series default
3520 "
3521 \series medium
3522 , this will create a sub-directory called sdcc with all of the sources.
3523
3524 \layout Enumerate
3525 Change directory into the main SDCC directory, for example type: 
3526 \family sans
3527 \series bold
3528 "cd sdcc
3529 \series default
3530 ".
3531
3532 \layout Enumerate
3533
3534 \series medium
3535 Type 
3536 \family sans
3537 \series bold
3538 "./configure
3539 \family default
3540 \series default
3541 ".
3542  This configures the package for compilation on your system.
3543
3544 \layout Enumerate
3545
3546 \series medium
3547 Type 
3548 \family sans
3549 \series bold
3550 "make
3551 \family default
3552 \series default
3553 "
3554 \series medium
3555 .
3556
3557 \series default
3558  All of the source packages will compile, this can take a while.
3559
3560 \layout Enumerate
3561
3562 \series medium
3563 Type 
3564 \family sans
3565 \series bold
3566 "make install"
3567 \family default
3568 \series default
3569  as root
3570 \series medium
3571 .
3572
3573 \series default
3574  This copies the binary executables, the include files, the libraries and
3575  the documentation to the install directories.
3576  Proceed with section 
3577 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3578
3579 \end_inset
3580
3581 .
3582
3583 \layout Subsection
3584 Building SDCC on OSX 2.x
3585
3586 \layout Standard
3587 Follow the instruction for Linux.
3588 \newline
3589
3590 \newline
3591 On OSX 2.x it was reported, that the default
3592  gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3593  Fortunately there's also gcc 2.9.x installed, which works fine.
3594  This compiler can be selected by running 'configure' with:
3595
3596 \layout LyX-Code
3597 ./configure CC=gcc2 CXX=g++2
3598
3599 \layout Subsection
3600 Cross compiling SDCC on Linux for Windows
3601
3602 \layout Standard
3603 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3604  See section 'Configure Options'.
3605
3606 \layout Subsection
3607 Building SDCC using Cygwin and Mingw32
3608
3609 \layout Standard
3610 For building and installing a Cygwin executable follow the instructions
3611  for Linux.
3612 \newline
3613
3614 \newline
3615 On Cygwin a 
3616 \begin_inset Quotes sld
3617 \end_inset
3618
3619 native
3620 \begin_inset Quotes srd
3621 \end_inset
3622
3623  Win32-binary can be built, which will not need the Cygwin-DLL.
3624  For the necessary 'configure' options see section 'configure options' or
3625  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3626 \newline
3627
3628 \newline
3629 In order to install
3630  Cygwin on Windows download setup.exe from 
3631 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3632
3633 \end_inset
3634
3635 .
3636  Run it, set the 
3637 \begin_inset Quotes sld
3638 \end_inset
3639
3640 default text file type
3641 \begin_inset Quotes srd
3642 \end_inset
3643
3644  to 
3645 \begin_inset Quotes sld
3646 \end_inset
3647
3648 unix
3649 \begin_inset Quotes srd
3650 \end_inset
3651
3652  and download/install at least the following packages.
3653  Some packages are selected by default, others will be automatically selected
3654  because of dependencies with the manually selected packages.
3655  Never deselect these packages!
3656
3657 \layout Itemize
3658 flex
3659
3660 \layout Itemize
3661 bison
3662
3663 \layout Itemize
3664 gcc ; version 3.x is fine, no need to use the old 2.9x
3665
3666 \layout Itemize
3667 binutils ; selected with gcc
3668
3669 \layout Itemize
3670 make
3671
3672 \layout Itemize
3673 rxvt ; a nice console, which makes life much easier under windoze (see below)
3674
3675 \layout Itemize
3676 man ; not really needed for building SDCC, but you'll miss it sooner or
3677  later
3678
3679 \layout Itemize
3680 less ; not really needed for building SDCC, but you'll miss it sooner or
3681  later
3682
3683 \layout Itemize
3684 svn ; only if you use Subversion access
3685
3686 \layout Standard
3687 If you want to develop something you'll need:
3688
3689 \layout Itemize
3690 python ; for the regression tests
3691
3692 \layout Itemize
3693 gdb ; the gnu debugger, together with the nice GUI 
3694 \begin_inset Quotes sld
3695 \end_inset
3696
3697 insight
3698 \begin_inset Quotes srd
3699 \end_inset
3700
3701
3702
3703 \layout Itemize
3704 openssh ; to access the CF or commit changes
3705
3706 \layout Itemize
3707 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3708  use autoconf-stable!
3709
3710 \layout Standard
3711 rxvt is a nice console with history.
3712  Replace in your cygwin.bat the line
3713
3714 \layout LyX-Code
3715 bash -
3716 \begin_inset ERT
3717 status Collapsed
3718
3719 \layout Standard
3720
3721
3722 \backslash
3723 /
3724
3725 \end_inset
3726
3727 -login -i 
3728
3729 \layout Standard
3730 with (one line):
3731
3732 \layout LyX-Code
3733 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3734
3735 \layout LyX-Code
3736      -bg black -fg white -geometry 100x65 -e bash -
3737 \begin_inset ERT
3738 status Collapsed
3739
3740 \layout Standard
3741
3742
3743 \backslash
3744 /
3745
3746 \end_inset
3747
3748 -login
3749
3750 \layout Standard
3751 Text selected with the mouse is automatically copied to the clipboard, pasting
3752  works with shift-insert.
3753 \newline
3754
3755 \newline
3756 The other good tip is to make sure you have no //c/-styl
3757 e paths anywhere, use /cygdrive/c/ instead.
3758  Using // invokes a network lookup which is very slow.
3759  If you think 
3760 \begin_inset Quotes sld
3761 \end_inset
3762
3763 cygdrive
3764 \begin_inset Quotes srd
3765 \end_inset
3766
3767  is too long, you can change it with e.g.
3768
3769 \layout LyX-Code
3770 mount -s -u -c /mnt
3771
3772 \layout Standard
3773 SDCC sources use the unix line ending LF.
3774  Life is much easier, if you store the source tree on a drive which is mounted
3775  in binary mode.
3776  And use an editor which can handle LF-only line endings.
3777  Make sure not to commit files with windows line endings.
3778  The tabulator spacing
3779 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3780
3781 \end_inset
3782
3783  used in the project is 8.
3784  Although a tabulator spacing of 8 is a sensible choice for programmers
3785  (it's a power of 2 and allows to display 8/16 bit signed variables without
3786  loosing columns) the plan is to move towards using only spaces in the source.
3787
3788 \layout Subsection
3789 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3790
3791 \layout Standard
3792
3793 \series medium
3794 Download the source package
3795 \series default
3796  either from the SDCC Subversion repository or from the 
3797 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3798
3799 \end_inset
3800
3801
3802 \series medium
3803 , it will be named something like sdcc
3804 \series default
3805 .src
3806 \series medium
3807 .tgz.
3808
3809 \series default
3810  SDCC is distributed with all the projects, workspaces, and files you need
3811  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
3812  The workspace name is 'sdcc.dsw'.
3813  Please note that as it is now, all the executables are created in a folder
3814  called sdcc
3815 \backslash
3816 bin_vc.
3817  Once built you need to copy the executables from sdcc
3818 \backslash
3819 bin_vc to sdcc
3820 \backslash
3821 bin before running SDCC.
3822  
3823 \newline
3824
3825 \newline
3826 WARNING: Visual studio is very picky with line terminations; it expects
3827  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3828  When using the Subversion repository it's easiest to configure the svn
3829  client to convert automatically for you.
3830  If however you are getting a message such as "This makefile was not generated
3831  by Developer Studio etc.
3832  etc.
3833 \begin_inset Quotes srd
3834 \end_inset
3835
3836  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3837  need to convert the Unix style line endings to DOS style line endings.
3838  To do so you can use the 
3839 \begin_inset Quotes sld
3840 \end_inset
3841
3842 unix2dos
3843 \begin_inset Quotes srd
3844 \end_inset
3845
3846  utility freely available on the internet.
3847  Doug Hawkins reported in the sdcc-user list that this works:
3848 \newline
3849
3850 \newline
3851 C:
3852 \backslash
3853 Programming
3854 \backslash
3855 SDCC> unix2dos sdcc.dsw
3856 \newline
3857 C:
3858 \backslash
3859 Programming
3860 \backslash
3861 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3862 \newline
3863
3864 \newline
3865 In order to build SDCC with MSVC
3866  you need win32 executables of bison.exe, flex.exe, and gawk.exe.
3867  One good place to get them is 
3868 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3869
3870 \end_inset
3871
3872
3873 \newline
3874
3875 \newline
3876 Download the file UnxUtils
3877 \begin_inset LatexCommand \index{UnxUtils}
3878
3879 \end_inset
3880
3881 .zip.
3882  Now you have to install the utilities and setup MSVC so it can locate the
3883  required programs.
3884  Here there are two alternatives (choose one!):
3885
3886 \layout Enumerate
3887 The easy way:
3888 \newline
3889
3890 \newline
3891 a) Extract UnxUtils.zip to your C:
3892 \backslash
3893  hard disk PRESERVING the original paths, otherwise bison won't work.
3894  (If you are using WinZip make certain that 'Use folder names' is selected)
3895 \newline
3896
3897 \newline
3898 b)
3899  In the Visual C++ IDE click Tools, Options, select the Directory tab, in
3900  'Show directories for:' select 'Executable files', and in the directories
3901  window add a new path: 'C:
3902 \backslash
3903 user
3904 \backslash
3905 local
3906 \backslash
3907 wbin', click ok.
3908 \newline
3909
3910 \newline
3911 (As a side effect, you get a bunch of Unix utilities that
3912  could be useful, such as diff and patch.)
3913
3914 \layout Enumerate
3915 A more compact way:
3916 \newline
3917
3918 \newline
3919 This one avoids extracting a bunch of files you may not
3920  use, but requires some extra work:
3921 \newline
3922
3923 \newline
3924 a) Create a directory were to put the
3925  tools needed, or use a directory already present.
3926  Say for example 'C:
3927 \backslash
3928 util'.
3929 \newline
3930
3931 \newline
3932 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
3933  gawk.exe to such directory WITHOUT preserving the original paths.
3934  (If you are using WinZip make certain that 'Use folder names' is not selected)
3935 \newline
3936
3937 \newline
3938 c
3939 ) Rename bison.exe to '_bison.exe'.
3940 \newline
3941
3942 \newline
3943 d) Create a batch file 'bison.bat' in 'C:
3944 \backslash
3945 util
3946 \backslash
3947 ' and add these lines: 
3948 \newline
3949 \SpecialChar ~
3950 \SpecialChar ~
3951 set BISON_SIMPLE=C:
3952 \backslash
3953 util
3954 \backslash
3955 bison.simple 
3956 \newline
3957 \SpecialChar ~
3958 \SpecialChar ~
3959 set BISON_HAIRY=C:
3960 \backslash
3961 util
3962 \backslash
3963 bison.hairy
3964 \newline
3965 \SpecialChar ~
3966 \SpecialChar ~
3967 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3968 \newline
3969
3970 \newline
3971 Steps 'c' and 'd' are needed
3972  because bison requires by default that the files 'bison.simple' and 'bison.hairy'
3973  reside in some weird Unix directory, '/usr/local/share/' I think.
3974  So it is necessary to tell bison where those files are located if they
3975  are not in such directory.
3976  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3977 \newline
3978
3979 \newline
3980 e
3981 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3982  in 'Show directories for:' select 'Executable files', and in the directories
3983  window add a new path: 'c:
3984 \backslash
3985 util', click ok.
3986  Note that you can use any other path instead of 'c:
3987 \backslash
3988 util', even the path where the Visual C++ tools are, probably: 'C:
3989 \backslash
3990 Program Files
3991 \backslash
3992 Microsoft Visual Studio
3993 \backslash
3994 Common
3995 \backslash
3996 Tools'.
3997  So you don't have to execute step 'e' :)
3998
3999 \layout Standard
4000 That is it.
4001  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4002  the executables from sdcc
4003 \backslash
4004 bin_vc to sdcc
4005 \backslash
4006 bin, and you can compile using SDCC.
4007
4008 \layout Subsection
4009 Building SDCC Using Borland
4010
4011 \layout Enumerate
4012 From the sdcc directory, run the command "make -f Makefile.bcc".
4013  This should regenerate all the .exe files in the bin directory except for
4014  SDCDB and ucSim.
4015
4016 \layout Enumerate
4017 If you modify any source files and need to rebuild, be aware that the dependenci
4018 es may not be correctly calculated.
4019  The safest option is to delete all .obj files and run the build again.
4020  From a Cygwin BASH prompt, this can easily be done with the command (be
4021  sure you are in the sdcc directory):
4022 \newline
4023
4024 \newline
4025
4026 \family sans
4027 \series bold
4028 find .
4029  
4030 \backslash
4031 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
4032 \backslash
4033 ) -print -exec rm {} 
4034 \backslash
4035 ;
4036 \family default
4037 \series default
4038
4039 \newline
4040
4041 \newline
4042 or on Windows NT/2000/XP from the command prompt with the command:
4043 \newline
4044
4045 \family sans
4046 \series bold
4047
4048 \newline
4049 del /s *.obj *.lib *.rul
4050 \family default
4051 \series default
4052  from the sdcc directory.
4053
4054 \layout Subsection
4055 Windows Install Using a ZIP Package
4056
4057 \layout Enumerate
4058 Download the binary zip package from 
4059 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4060
4061 \end_inset
4062
4063  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4064  This should unpack to a group of sub-directories.
4065  An example directory structure after unpacking the mingw32 package is:
4066  c:
4067 \backslash
4068 sdcc
4069 \backslash
4070 bin for the executables, c:
4071 \backslash
4072 sdcc
4073 \backslash
4074 include and c:
4075 \backslash
4076 sdcc
4077 \backslash
4078 lib for the include and libraries.
4079
4080 \layout Enumerate
4081 Adjust your environment variable PATH to include the location of the bin
4082  directory or start sdcc using the full path.
4083
4084 \layout Subsection
4085 Windows Install Using the Setup Program
4086 \begin_inset LatexCommand \label{sub:Windows-Install}
4087
4088 \end_inset
4089
4090
4091
4092 \layout Standard
4093 Download the setup program 
4094 \emph on
4095 sdcc-x.y.z-setup.exe
4096 \emph default
4097  for an official release from 
4098 \newline
4099
4100 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4101
4102 \end_inset
4103
4104  or a setup program for one of the snapshots 
4105 \emph on
4106 sdcc-yyyymmdd-xxxx-setup.exe
4107 \emph default
4108  from 
4109 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4110
4111 \end_inset
4112
4113  and execute it.
4114  A windows typical installer will guide you through the installation process.
4115
4116 \layout Subsection
4117 VPATH
4118 \begin_inset LatexCommand \index{VPATH}
4119
4120 \end_inset
4121
4122  feature
4123
4124 \layout Standard
4125 SDCC supports the VPATH feature provided by configure and make.
4126  It allows to separate the source and build trees.
4127  Here's an example:
4128
4129 \layout Standard
4130
4131 \family typewriter
4132 cd ~\SpecialChar ~
4133 \SpecialChar ~
4134 \SpecialChar ~
4135 \SpecialChar ~
4136 \SpecialChar ~
4137 \SpecialChar ~
4138 \SpecialChar ~
4139 \SpecialChar ~
4140 \SpecialChar ~
4141 \SpecialChar ~
4142 \SpecialChar ~
4143 \SpecialChar ~
4144 \SpecialChar ~
4145 \SpecialChar ~
4146 \SpecialChar ~
4147 \SpecialChar ~
4148 \SpecialChar ~
4149 \SpecialChar ~
4150 \SpecialChar ~
4151 \SpecialChar ~
4152 \SpecialChar ~
4153 # cd $HOME
4154
4155 \layout Standard
4156
4157 \family typewriter
4158 tar -xzf sdcc.src.tar.gz\SpecialChar ~
4159 # extract source to directory sdcc
4160
4161 \layout Standard
4162
4163 \family typewriter
4164 mkdir sdcc.build\SpecialChar ~
4165 \SpecialChar ~
4166 \SpecialChar ~
4167 \SpecialChar ~
4168 \SpecialChar ~
4169 \SpecialChar ~
4170 \SpecialChar ~
4171 \SpecialChar ~
4172 \SpecialChar ~
4173 # put output in sdcc.build
4174
4175 \layout Standard
4176
4177 \family typewriter
4178 cd sdcc.build
4179
4180 \layout Standard
4181
4182 \family typewriter
4183 ../sdcc/configure\SpecialChar ~
4184 \SpecialChar ~
4185 \SpecialChar ~
4186 \SpecialChar ~
4187 \SpecialChar ~
4188 \SpecialChar ~
4189 \SpecialChar ~
4190 \SpecialChar ~
4191 # configure is doing all the magic!
4192
4193 \layout Standard
4194
4195 \family typewriter
4196 make
4197
4198 \layout Standard
4199 \noindent
4200 That's it! 
4201 \series bold
4202 configure
4203 \series default
4204  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4205  It automagically computes the variables srcdir, top_srcdir and top_buildir
4206  for each directory.
4207  After running 
4208 \series bold
4209 make
4210 \series default
4211  the generated files will be in ~/sdcc.build, while the source files stay
4212  in ~/sdcc.
4213 \newline
4214 This is not only usefull for building different binaries, e.g.
4215  when cross compiling.
4216  It also gives you a much better overview in the source tree when all the
4217  generated files are not scattered between the source files.
4218  And the best thing is: if you want to change a file you can leave the original
4219  file untouched in the source directory.
4220  Simply copy it to the build directory, edit it, enter `make clean`, `rm
4221  Makefile.dep` and `make`.
4222  
4223 \series bold
4224 make
4225 \series default
4226  will do the rest for you!
4227
4228 \layout Section
4229 Building the Documentation
4230
4231 \layout Standard
4232 Add -
4233 \begin_inset ERT
4234 status Collapsed
4235
4236 \layout Standard
4237
4238
4239 \backslash
4240 /
4241
4242 \end_inset
4243
4244 -enable-doc to the configure arguments to build the documentation together
4245  with all the other stuff.
4246  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4247  dvips and makeindex) to get the job done.
4248  Another possibility is to change to the doc directory and to type 
4249 \family sans
4250 \series bold
4251
4252 \begin_inset Quotes srd
4253 \end_inset
4254
4255 make
4256 \begin_inset Quotes srd
4257 \end_inset
4258
4259
4260 \family default
4261 \series default
4262  there.
4263  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4264 x).
4265  Using LyX 
4266 \begin_inset LatexCommand \url{http://www.lyx.org}
4267
4268 \end_inset
4269
4270  as editor is straightforward.
4271  Prebuilt documentation in html and pdf format is available from 
4272 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4273
4274 \end_inset
4275
4276 .
4277
4278 \layout Section
4279 Reading the Documentation
4280 \begin_inset LatexCommand \index{Documentation}
4281
4282 \end_inset
4283
4284
4285
4286 \layout Standard
4287 Currently reading the document in pdf format is recommended, as for unknown
4288  reason the hyperlinks are working there whereas in the html version they
4289  are not
4290 \begin_inset Foot
4291 collapsed false
4292
4293 \layout Standard
4294 If you should know why please drop us a note
4295
4296 \end_inset
4297
4298 .
4299  
4300 \newline
4301 You'll find the pdf version
4302 \begin_inset LatexCommand \index{PDF version of this document}
4303
4304 \end_inset
4305
4306  at 
4307 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4308
4309 \end_inset
4310
4311 .
4312  
4313 \newline
4314 A html version
4315 \begin_inset LatexCommand \index{HTML version of this document}
4316
4317 \end_inset
4318
4319  should be online at 
4320 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4321
4322 \end_inset
4323
4324 .
4325 \newline
4326 This documentation is in some aspects different from a commercial documentation:
4327  
4328
4329 \layout Itemize
4330 It tries to document SDCC for several processor architectures in one document
4331  (commercially these probably would be separate documents/products).
4332  This document
4333 \begin_inset LatexCommand \index{Status of documentation}
4334
4335 \end_inset
4336
4337  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4338 on about f.e.
4339  Z80, PIC14, PIC16 and HC08.
4340
4341 \layout Itemize
4342 There are many references pointing away from this documentation.
4343  Don't let this distract you.
4344  If there f.e.
4345  was a reference like 
4346 \begin_inset LatexCommand \url{http://www.opencores.org}
4347
4348 \end_inset
4349
4350  together with a statement 
4351 \begin_inset Quotes sld
4352 \end_inset
4353
4354 some processors which are targetted by SDCC can be implemented in a 
4355 \emph on
4356 f
4357 \emph default
4358 ield 
4359 \emph on
4360 p
4361 \emph default
4362 rogrammable 
4363 \emph on
4364 g
4365 \emph default
4366 ate 
4367 \emph on
4368 a
4369 \emph default
4370 rray
4371 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4372
4373 \end_inset
4374
4375
4376 \begin_inset Quotes srd
4377 \end_inset
4378
4379  or 
4380 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4381
4382 \end_inset
4383
4384
4385 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4386
4387 \end_inset
4388
4389  
4390 \begin_inset Quotes sld
4391 \end_inset
4392
4393 have you ever heard of an open source compiler that compiles a subset of
4394  C for an FPGA?
4395 \begin_inset Quotes srd
4396 \end_inset
4397
4398  we expect you to have a quick look there and come back.
4399  If you read this you are on the right track.
4400
4401 \layout Itemize
4402 Some sections attribute more space to problems, restrictions and warnings
4403  than to the solution.
4404
4405 \layout Itemize
4406 The installation section and the section about the debugger is intimidating.
4407
4408 \layout Itemize
4409 There are still lots of typos and there are more different writing styles
4410  than pictures.
4411
4412 \layout Section
4413 Testing the SDCC Compiler
4414 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4415
4416 \end_inset
4417
4418
4419
4420 \layout Standard
4421 The first thing you should do after installing your SDCC compiler is to
4422  see if it runs.
4423  Type 
4424 \family sans
4425 \series bold
4426 "sdcc -
4427 \begin_inset ERT
4428 status Collapsed
4429
4430 \layout Standard
4431
4432
4433 \backslash
4434 /
4435
4436 \end_inset
4437
4438 -version"
4439 \begin_inset LatexCommand \index{version}
4440
4441 \end_inset
4442
4443
4444 \family default
4445 \series default
4446  at the prompt, and the program should run and output its version like:
4447  
4448 \newline
4449
4450 \family typewriter
4451 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4452  (UNIX)
4453
4454 \layout Standard
4455 If it doesn't run, or gives a message about not finding sdcc program, then
4456  you need to check over your installation.
4457  Make sure that the sdcc bin directory is in your executable search path
4458  defined by the PATH environment setting (
4459 \series medium
4460 see 
4461 \series default
4462 section 
4463 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4464
4465 \end_inset
4466
4467 \SpecialChar ~
4468
4469 \series medium
4470 Install trouble-shooting for suggestions
4471 \series default
4472 ).
4473  Make sure that the sdcc program is in the bin folder, if not perhaps something
4474  did not install correctly.
4475 \newline
4476
4477 \newline
4478
4479 \series medium
4480 SDCC 
4481 \series default
4482 is commonly installed as described in section 
4483 \begin_inset Quotes sld
4484 \end_inset
4485
4486 Install and search paths
4487 \begin_inset Quotes srd
4488 \end_inset
4489
4490 .
4491 \newline
4492
4493 \newline
4494
4495 \series medium
4496 Make sure the compiler works on a very simple example.
4497  Type in the following test.c program using your favorite 
4498 \series default
4499 ASCII 
4500 \series medium
4501 editor:
4502
4503 \layout Verse
4504
4505 \family typewriter
4506 char test;
4507 \newline
4508
4509 \newline
4510 void main(void) {
4511 \newline
4512 \SpecialChar ~
4513 \SpecialChar ~
4514 \SpecialChar ~
4515 \SpecialChar ~
4516 test=0;
4517 \newline
4518 }
4519
4520 \layout Standard
4521
4522 \series medium
4523 Compile this using the following command: 
4524 \family sans
4525 \series bold
4526 "sdcc -c test.c".
4527
4528 \family default
4529 \series default
4530  
4531 \series medium
4532 If all goes well, the compiler will generate a test.asm and test.rel file.
4533  Congratulations, you've just compiled your first program with SDCC.
4534  We used the -c option to tell SDCC not to link the generated code, just
4535  to keep things simple for this step.
4536 \series default
4537
4538 \newline
4539
4540 \newline
4541
4542 \series medium
4543 The next step is to try it with the linker.
4544  Type in 
4545 \family sans
4546 \series bold
4547 "sdcc test.c
4548 \family default
4549 \series default
4550 "
4551 \series medium
4552 .
4553  If all goes well the compiler will link with the libraries and produce
4554  a test.ihx output file.
4555  If this step fails
4556 \series default
4557  
4558 \series medium
4559 (no test.ihx, and the linker generates warnings), then the problem is most
4560  likely that 
4561 \series default
4562 SDCC
4563 \series medium
4564  cannot find the 
4565 \series default
4566 /
4567 \series medium
4568 usr/local/share/sdcc/lib directory
4569 \series default
4570  
4571 \series medium
4572 (see 
4573 \series default
4574 section 
4575 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4576
4577 \end_inset
4578
4579 \SpecialChar ~
4580
4581 \series medium
4582 Install trouble-shooting for suggestions).
4583 \series default
4584
4585 \newline
4586
4587 \newline
4588
4589 \series medium
4590 The final test is to ensure 
4591 \series default
4592 SDCC
4593 \series medium
4594  can use the 
4595 \series default
4596 standard
4597 \series medium
4598  header files and libraries.
4599  Edit test.c and change it to the following:
4600
4601 \layout Verse
4602
4603 \family typewriter
4604 #include <string.h>
4605 \newline
4606
4607 \newline
4608 char str1[10];
4609 \newline
4610
4611 \newline
4612 void main(void) {
4613 \newline
4614 \SpecialChar ~
4615 \SpecialChar ~
4616 strcpy(str1, "testing");
4617 \newline
4618 }
4619
4620 \layout Standard
4621
4622 \series medium
4623 Compile this by typing 
4624 \family sans
4625 \series bold
4626 "sdcc test.c"
4627 \family default
4628 \series medium
4629 .
4630  This should generate a test.ihx output file, and it should give no warnings
4631  such as not finding the string.h file.
4632  If it cannot find the string.h file, then the problem is that 
4633 \series default
4634 SDCC
4635 \series medium
4636  cannot find the /usr/local/share/sdcc/include directory
4637 \series default
4638  
4639 \series medium
4640 (see the 
4641 \series default
4642 section 
4643 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4644
4645 \end_inset
4646
4647 \SpecialChar ~
4648
4649 \series medium
4650 Install trouble-shooting section for suggestions).
4651
4652 \series default
4653  Use option 
4654 \series bold
4655 -
4656 \begin_inset ERT
4657 status Collapsed
4658
4659 \layout Standard
4660
4661
4662 \backslash
4663 /
4664
4665 \end_inset
4666
4667 -print-search-dirs
4668 \series default
4669
4670 \begin_inset LatexCommand \index{-\/-print-search-dirs}
4671
4672 \end_inset
4673
4674  to find exactly where SDCC is looking for the include and lib files.
4675
4676 \layout Section
4677 Install Trouble-shooting
4678 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
4679
4680 \end_inset
4681
4682
4683 \begin_inset LatexCommand \index{Install trouble-shooting}
4684
4685 \end_inset
4686
4687
4688
4689 \layout Subsection
4690 If SDCC does not build correctly
4691
4692 \layout Standard
4693 A thing to try is starting from scratch by unpacking the .tgz source package
4694  again in an empty directory.
4695  Configure it like:
4696 \newline
4697
4698 \newline
4699
4700 \family sans
4701 \series bold
4702 ./configure 2>&1 | tee configure.log
4703 \family default
4704 \series default
4705
4706 \newline
4707
4708 \newline
4709 and build it like:
4710 \newline
4711
4712 \newline
4713
4714 \family sans
4715 \series bold
4716 make 2>&1 | tee make.log
4717 \family default
4718 \series default
4719
4720 \newline
4721
4722 \newline
4723 If anything goes wrong, you can review the log files to locate the problem.
4724  Or a relevant part of this can be attached to an email that could be helpful
4725  when requesting help from the mailing list.
4726
4727 \layout Subsection
4728 What the 
4729 \begin_inset Quotes sld
4730 \end_inset
4731
4732 ./configure
4733 \begin_inset Quotes srd
4734 \end_inset
4735
4736  does
4737
4738 \layout Standard
4739 The 
4740 \begin_inset Quotes sld
4741 \end_inset
4742
4743 ./configure
4744 \begin_inset Quotes srd
4745 \end_inset
4746
4747  command is a script that analyzes your system and performs some configuration
4748  to ensure the source package compiles on your system.
4749  It will take a few minutes to run, and will compile a few tests to determine
4750  what compiler features are installed.
4751
4752 \layout Subsection
4753 What the 
4754 \begin_inset Quotes sld
4755 \end_inset
4756
4757 make
4758 \begin_inset Quotes srd
4759 \end_inset
4760
4761  does
4762
4763 \layout Standard
4764 This runs the GNU make tool, which automatically compiles all the source
4765  packages into the final installed binary executables.
4766
4767 \layout Subsection
4768 What the 
4769 \begin_inset Quotes sld
4770 \end_inset
4771
4772 make install
4773 \begin_inset Quotes erd
4774 \end_inset
4775
4776  command does.
4777
4778 \layout Standard
4779 This will install the compiler, other executables libraries and include
4780  files into the appropriate directories.
4781  See sections 
4782 \begin_inset LatexCommand \ref{sub:Install-paths}
4783
4784 \end_inset
4785
4786 ,\SpecialChar ~
4787
4788 \begin_inset LatexCommand \ref{sub:Search-Paths}
4789
4790 \end_inset
4791
4792 \SpecialChar ~
4793 about install and search paths.
4794 \newline
4795 On most systems you will need super-user privilege
4796 s to do this.
4797
4798 \layout Section
4799 Components of SDCC
4800
4801 \layout Standard
4802 SDCC is not just a compiler, but a collection of tools by various developers.
4803  These include linkers, assemblers, simulators and other components.
4804  Here is a summary of some of the components.
4805  Note that the included simulator and assembler have separate documentation
4806  which you can find in the source package in their respective directories.
4807  As SDCC grows to include support for other processors, other packages from
4808  various developers are included and may have their own sets of documentation.
4809 \newline
4810
4811 \newline
4812 You
4813  might want to look at the files which are installed in <installdir>.
4814  At the time of this writing, we find the following programs for gcc-builds:
4815 \newline
4816
4817  
4818 \newline
4819 In <installdir>/bin:
4820
4821 \layout Itemize
4822 sdcc - The compiler.
4823
4824 \layout Itemize
4825 sdcpp - The C preprocessor.
4826
4827 \layout Itemize
4828 asx8051 - The assembler for 8051 type processors.
4829
4830 \layout Itemize
4831 as-z80
4832 \series bold
4833
4834 \series default
4835 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4836
4837 \layout Itemize
4838 aslink -The linker for 8051 type processors.
4839
4840 \layout Itemize
4841 link-z80
4842 \series bold
4843
4844 \series default
4845 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4846
4847 \layout Itemize
4848 s51 - The ucSim 8051 simulator.
4849
4850 \layout Itemize
4851 sdcdb - The source debugger.
4852
4853 \layout Itemize
4854 packihx - A tool to pack (compress) Intel hex files.
4855
4856 \layout Standard
4857 In <installdir>/share/sdcc/include
4858
4859 \layout Itemize
4860 the include files
4861
4862 \layout Standard
4863 In <installdir>/share/sdcc/lib
4864
4865 \layout Itemize
4866 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4867  relocatables.
4868
4869 \layout Standard
4870 In <installdir>/share/sdcc/doc
4871
4872 \layout Itemize
4873 the documentation
4874
4875 \layout Standard
4876 As development for other processors proceeds, this list will expand to include
4877  executables to support processors like AVR, PIC, etc.
4878
4879 \layout Subsection
4880 sdcc - The Compiler
4881
4882 \layout Standard
4883 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4884  the assembler and linkage editor.
4885
4886 \layout Subsection
4887 sdcpp - The C-Preprocessor
4888
4889 \layout Standard
4890 The preprocessor
4891 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4892
4893 \end_inset
4894
4895  is a modified version of the GNU cpp
4896 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
4897
4898 \end_inset
4899
4900  preprocessor 
4901 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
4902
4903 \end_inset
4904
4905 .
4906  The C preprocessor is used to pull in #include sources, process #ifdef
4907  statements, #defines and so on.
4908
4909 \layout Subsection
4910 as
4911 \emph on
4912 xxxx
4913 \emph default
4914 , aslink, link-
4915 \emph on
4916 xxx
4917 \emph default
4918  - The Assemblers and Linkage Editors
4919
4920 \layout Standard
4921 This is retargettable assembler & linkage editor, it was developed by Alan
4922  Baldwin.
4923  John Hartman created the version for 8051, and I (Sandeep) have made some
4924  enhancements and bug fixes for it to work properly with SDCC.
4925
4926 \layout Subsection
4927 s51 - The Simulator
4928
4929 \layout Standard
4930 S51
4931 \begin_inset LatexCommand \index{s51}
4932
4933 \end_inset
4934
4935  is a freeware, opensource simulator developed by Daniel Drotos.
4936  The simulator is built as part of the build process.
4937  For more information visit Daniel's web site at: 
4938 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4939
4940 \end_inset
4941
4942 .
4943  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4944  XA51 family.
4945
4946 \layout Subsection
4947 sdcdb - Source Level Debugger
4948
4949 \layout Standard
4950 SDCDB
4951 \begin_inset LatexCommand \index{SDCDB (debugger)}
4952
4953 \end_inset
4954
4955  is the companion source level debugger.
4956  More about SDCDB in section 
4957 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4958
4959 \end_inset
4960
4961 .
4962  The current version of the debugger uses Daniel's Simulator S51
4963 \begin_inset LatexCommand \index{s51}
4964
4965 \end_inset
4966
4967 , but can be easily changed to use other simulators.
4968
4969 \layout Chapter
4970 Using SDCC
4971
4972 \layout Section
4973 Compiling
4974
4975 \layout Subsection
4976 Single Source File Projects
4977
4978 \layout Standard
4979 For single source file 8051 projects the process is very simple.
4980  Compile your programs with the following command 
4981 \family sans
4982 \series bold
4983 "sdcc sourcefile.c".
4984
4985 \family default
4986 \series default
4987  This will compile, assemble and link your source file.
4988  Output files are as follows:
4989
4990 \layout Itemize
4991 sourcefile.asm
4992 \begin_inset LatexCommand \index{<file>.asm}
4993
4994 \end_inset
4995
4996  - Assembler source
4997 \begin_inset LatexCommand \index{Assembler source}
4998
4999 \end_inset
5000
5001  file created by the compiler
5002
5003 \layout Itemize
5004 sourcefile.lst
5005 \begin_inset LatexCommand \index{<file>.lst}
5006
5007 \end_inset
5008
5009  - Assembler listing
5010 \begin_inset LatexCommand \index{Assembler listing}
5011
5012 \end_inset
5013
5014  file created by the Assembler
5015
5016 \layout Itemize
5017 sourcefile.rst
5018 \begin_inset LatexCommand \index{<file>.rst}
5019
5020 \end_inset
5021
5022  - Assembler listing
5023 \begin_inset LatexCommand \index{Assembler listing}
5024
5025 \end_inset
5026
5027  file updated with linkedit information, created by linkage editor
5028
5029 \layout Itemize
5030 sourcefile.sym
5031 \begin_inset LatexCommand \index{<file>.sym}
5032
5033 \end_inset
5034
5035  - symbol listing
5036 \begin_inset LatexCommand \index{Symbol listing}
5037
5038 \end_inset
5039
5040  for the sourcefile, created by the assembler
5041
5042 \layout Itemize
5043 sourcefile.rel
5044 \begin_inset LatexCommand \index{<file>.rel}
5045
5046 \end_inset
5047
5048  or sourcefile.o
5049 \begin_inset LatexCommand \index{<file>.o}
5050
5051 \end_inset
5052
5053  - Object file
5054 \begin_inset LatexCommand \index{Object file}
5055
5056 \end_inset
5057
5058  created by the assembler, input to Linkage editor
5059
5060 \layout Itemize
5061 sourcefile.map
5062 \begin_inset LatexCommand \index{<file>.map}
5063
5064 \end_inset
5065
5066  - The memory map
5067 \begin_inset LatexCommand \index{Memory map}
5068
5069 \end_inset
5070
5071  for the load module, created by the Linker
5072
5073 \layout Itemize
5074 sourcefile.mem
5075 \begin_inset LatexCommand \index{<file>.mem}
5076
5077 \end_inset
5078
5079  - A file with a summary of the memory usage
5080
5081 \layout Itemize
5082 sourcefile.ihx
5083 \begin_inset LatexCommand \index{<file>.ihx}
5084
5085 \end_inset
5086
5087  - The load module in Intel hex format
5088 \begin_inset LatexCommand \index{Intel hex format}
5089
5090 \end_inset
5091
5092  (you can select the Motorola S19 format
5093 \begin_inset LatexCommand \index{Motorola S19 format}
5094
5095 \end_inset
5096
5097  with -
5098 \begin_inset ERT
5099 status Collapsed
5100
5101 \layout Standard
5102
5103
5104 \backslash
5105 /
5106
5107 \end_inset
5108
5109 -out-fmt-s19
5110 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5111
5112 \end_inset
5113
5114 .
5115  If you need another format you might want to use 
5116 \family sans
5117 \shape italic
5118 objdump
5119 \family default
5120 \shape default
5121
5122 \begin_inset LatexCommand \index{objdump (tool)}
5123
5124 \end_inset
5125
5126  or
5127 \family sans
5128 \shape italic
5129  srecord
5130 \family default
5131 \shape default
5132
5133 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5134
5135 \end_inset
5136
5137 ).
5138  Both formats are documented in the documentation of srecord
5139 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5140
5141 \end_inset
5142
5143
5144
5145 \layout Itemize
5146 sourcefile.adb
5147 \begin_inset LatexCommand \index{<file>.adb}
5148
5149 \end_inset
5150
5151  - An intermediate file containing debug information needed to create the
5152  .cdb file (with -
5153 \begin_inset ERT
5154 status Collapsed
5155
5156 \layout Standard
5157
5158
5159 \backslash
5160 /
5161
5162 \end_inset
5163
5164 -debug
5165 \begin_inset LatexCommand \index{-\/-debug}
5166
5167 \end_inset
5168
5169
5170
5171 \layout Itemize
5172 sourcefile.cdb
5173 \begin_inset LatexCommand \index{<file>.cdb}
5174
5175 \end_inset
5176
5177  - An optional file (with -
5178 \begin_inset ERT
5179 status Collapsed
5180
5181 \layout Standard
5182
5183
5184 \backslash
5185 /
5186
5187 \end_inset
5188
5189 -debug) containing debug information.
5190  The format is documented in cdbfileformat.pdf
5191
5192 \layout Itemize
5193 sourcefile.
5194  - (no extension)
5195 \begin_inset LatexCommand \index{<file> (no extension)}
5196
5197 \end_inset
5198
5199  An optional AOMF or AOMF51
5200 \begin_inset LatexCommand \index{AOMF, AOMF51}
5201
5202 \end_inset
5203
5204  
5205 \begin_inset LatexCommand \label{OMF file}
5206
5207 \end_inset
5208
5209 file containing debug information (generated with option -
5210 \begin_inset ERT
5211 status Collapsed
5212
5213 \layout Standard
5214
5215
5216 \backslash
5217 /
5218
5219 \end_inset
5220
5221 -debug).
5222  The (Intel)
5223 \emph on
5224  a
5225 \emph default
5226 bsolute 
5227 \emph on
5228 o
5229 \emph default
5230 bject 
5231 \emph on
5232 m
5233 \emph default
5234 odule 
5235 \emph on
5236 f
5237 \emph default
5238 ormat is commonly used by third party tools (debuggers
5239 \begin_inset LatexCommand \index{Debugger}
5240
5241 \end_inset
5242
5243 , simulators, emulators)
5244
5245 \layout Itemize
5246 sourcefile.dump*
5247 \begin_inset LatexCommand \index{<file>.dump*}
5248
5249 \end_inset
5250
5251  - Dump file to debug the compiler it self (generated with option -
5252 \begin_inset ERT
5253 status Collapsed
5254
5255 \layout Standard
5256
5257
5258 \backslash
5259 /
5260
5261 \end_inset
5262
5263 -dumpall) (see section 
5264 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5265
5266 \end_inset
5267
5268 \SpecialChar ~
5269  and section 
5270 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5271
5272 \end_inset
5273
5274 \SpecialChar ~
5275
5276 \begin_inset Quotes sld
5277 \end_inset
5278
5279 Anatomy of the compiler
5280 \begin_inset Quotes srd
5281 \end_inset
5282
5283 ).
5284
5285 \layout Subsection
5286 Postprocessing the Intel Hex
5287 \begin_inset LatexCommand \index{Intel hex format}
5288
5289 \end_inset
5290
5291  file
5292
5293 \layout Standard
5294 In most cases this won't be needed but the Intel Hex file
5295 \begin_inset LatexCommand \index{<file>.ihx}
5296
5297 \end_inset
5298
5299  which is generated by SDCC might include lines of varying length and the
5300  addresses within the file are not guaranteed to be strictly ascending.
5301  If your toolchain or a bootloader does not like this you can use the tool
5302  
5303 \family typewriter
5304 packihx
5305 \family default
5306
5307 \begin_inset LatexCommand \index{packihx (tool)}
5308
5309 \end_inset
5310
5311  which is part of the SDCC distribution: 
5312 \newline
5313
5314 \newline
5315
5316 \family sans
5317 \series bold
5318  packihx sourcefile.ihx >sourcefile.hex
5319 \family default
5320 \series default
5321
5322 \newline
5323
5324 \newline
5325 The separately available
5326 \emph on
5327  srecord
5328 \emph default
5329
5330 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5331
5332 \end_inset
5333
5334  package additionally allows to set undefined locations to a predefined
5335  value, to insert checksums
5336 \begin_inset LatexCommand \index{checksum}
5337
5338 \end_inset
5339
5340  of various flavours (crc, add, xor) and to perform other manipulations
5341  (convert, split, crop, offset, ...).
5342  
5343 \newline
5344
5345 \newline
5346
5347 \family sans
5348 \series bold
5349 srec_cat\SpecialChar ~
5350 \SpecialChar ~
5351 sourcefile.ihx -intel\SpecialChar ~
5352 \SpecialChar ~
5353 -o sourcefile.hex -intel
5354 \newline
5355
5356 \newline
5357
5358 \family default
5359 \series default
5360 An example for a more complex command line
5361 \begin_inset Foot
5362 collapsed false
5363
5364 \layout Standard
5365 the command backfills
5366 \begin_inset LatexCommand \index{backfill unused memory}
5367
5368 \end_inset
5369
5370  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5371  block is zero.
5372  If the program counter on an mcs51 runs wild the backfill pattern 0x12
5373  will be interpreted as an 
5374 \family typewriter
5375 lcall
5376 \family default
5377  to address 
5378 \family typewriter
5379 0x1212
5380 \family default
5381  (where an emergency routine could sit).
5382
5383 \end_inset
5384
5385  could look like:
5386 \newline
5387
5388 \newline
5389
5390 \family sans
5391 \series bold
5392 \size footnotesize
5393 srec_cat\SpecialChar ~
5394 sourcefile.ihx -intel\SpecialChar ~
5395 \SpecialChar ~
5396 -fill 0x12 0x0000 0xfffe\SpecialChar ~
5397 -little-endian-checksum-nega
5398 tive 0xfffe 0x02 0x02\SpecialChar ~
5399 \SpecialChar ~
5400 -o sourcefile.hex -intel
5401 \size default
5402
5403 \newline
5404
5405 \newline
5406
5407 \family default
5408 \series default
5409 The srecord package is available at 
5410 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5411
5412 \end_inset
5413
5414  .
5415
5416 \layout Subsection
5417 Projects with Multiple Source Files
5418
5419 \layout Standard
5420 SDCC can compile only ONE file at a time.
5421  Let us for example assume that you have a project containing the following
5422  files:
5423 \newline
5424
5425 \newline
5426 foo1.c (contains some functions)
5427 \newline
5428 foo2.c (contains some more functions)
5429 \newline
5430 foomai
5431 n.c (contains more functions and the function main)
5432 \newline
5433
5434 \size footnotesize
5435
5436 \newline
5437
5438 \size default
5439 The first two files will need to be compiled separately with the commands:
5440 \size footnotesize
5441  
5442 \size default
5443
5444 \newline
5445
5446 \newline
5447
5448 \family sans
5449 \series bold
5450 sdcc\SpecialChar ~
5451 -c\SpecialChar ~
5452 foo1.c
5453 \family default
5454 \series default
5455 \size footnotesize
5456
5457 \newline
5458
5459 \family sans
5460 \series bold
5461 \size default
5462 sdcc\SpecialChar ~
5463 -c\SpecialChar ~
5464 foo2.c
5465 \family default
5466 \series default
5467
5468 \newline
5469
5470 \newline
5471 Then compile the source file containing the 
5472 \emph on
5473 main()
5474 \emph default
5475  function and link
5476 \begin_inset LatexCommand \index{Linker}
5477
5478 \end_inset
5479
5480  the files together with the following command: 
5481 \newline
5482
5483 \newline
5484
5485 \family sans
5486 \series bold
5487 sdcc\SpecialChar ~
5488 foomain.c\SpecialChar ~
5489 foo1.rel\SpecialChar ~
5490 foo2.rel
5491 \family default
5492 \series default
5493
5494 \begin_inset LatexCommand \index{<file>.rel}
5495
5496 \end_inset
5497
5498
5499 \newline
5500
5501 \newline
5502 Alternatively, 
5503 \emph on
5504 foomain.c 
5505 \emph default
5506 can be separately compiled as well: 
5507 \family sans
5508 \series bold
5509
5510 \newline
5511
5512 \newline
5513 sdcc\SpecialChar ~
5514 -c\SpecialChar ~
5515 foomain.c
5516 \newline
5517 sdcc foomain.rel foo1.rel foo2.rel
5518 \newline
5519
5520 \newline
5521
5522 \family default
5523 \series default
5524 The file containing the 
5525 \emph on
5526 main()
5527 \emph default
5528  function
5529 \emph on
5530  
5531 \emph default
5532 \noun on
5533 must
5534 \noun default
5535  be the 
5536 \noun on
5537 first
5538 \noun default
5539  file specified in the command line, since the linkage editor processes
5540  file in the order they are presented to it.
5541  The linker is invoked from SDCC using a script file with extension .lnk
5542 \begin_inset LatexCommand \index{<file>.lnk}
5543
5544 \end_inset
5545
5546 .
5547  You can view this file to troubleshoot linking problems such as those arising
5548  from missing libraries.
5549
5550 \layout Subsection
5551 Projects with Additional Libraries
5552 \begin_inset LatexCommand \index{Libraries}
5553
5554 \end_inset
5555
5556
5557
5558 \layout Standard
5559 Some reusable routines may be compiled into a library, see the documentation
5560  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
5561  for how to create a 
5562 \emph on
5563 .lib
5564 \begin_inset LatexCommand \index{<file>.lib}
5565
5566 \end_inset
5567
5568
5569 \emph default
5570  library file.
5571  Libraries created in this manner can be included in the command line.
5572  Make sure you include the -L <library-path> option to tell the linker where
5573  to look for these files if they are not in the current directory.
5574  Here is an example, assuming you have the source file 
5575 \emph on
5576 foomain.c
5577 \emph default
5578  and a library
5579 \emph on
5580  foolib.lib
5581 \emph default
5582  in the directory 
5583 \emph on
5584 mylib
5585 \emph default
5586  (if that is not the same as your current project):
5587 \newline
5588
5589 \newline
5590
5591 \family sans
5592 \series bold
5593 sdcc foomain.c foolib.lib -L mylib
5594 \newline
5595
5596 \newline
5597
5598 \family default
5599 \series default
5600 Note here that
5601 \emph on
5602  mylib
5603 \emph default
5604  must be an absolute path name.
5605 \newline
5606
5607 \newline
5608 The most efficient way to use libraries is
5609  to keep separate modules in separate source files.
5610  The lib file now should name all the modules.rel
5611 \begin_inset LatexCommand \index{<file>.rel}
5612
5613 \end_inset
5614
5615  files.
5616  For an example see the standard library file 
5617 \emph on
5618 libsdcc.lib
5619 \emph default
5620  in the directory <installdir>/share/lib/small.
5621
5622 \layout Subsection
5623 Using sdcclib to Create and Manage Libraries
5624 \begin_inset LatexCommand \index{sdcclib}
5625
5626 \end_inset
5627
5628
5629
5630 \layout Standard
5631 Alternatively, instead of having a .rel file for each entry on the library
5632  file as described in the preceding section, sdcclib can be used to embed
5633  all the modules belonging to such library in the library file itself.
5634  This results in a larger library file, but it greatly reduces the number
5635  of disk files accessed by the linker.
5636   Additionally, the packed library file contains an index of all include
5637  modules and symbols that significantly speeds up the linking process.
5638  To display a list of options supported by sdcclib type:
5639 \newline
5640
5641
5642 \layout Standard
5643
5644 \family sans
5645 \series bold
5646 sdcclib -?
5647 \begin_inset LatexCommand \index{sdcclib}
5648
5649 \end_inset
5650
5651
5652 \newline
5653
5654 \newline
5655
5656 \family default
5657 \series default
5658 To create a new library file, start by compiling all the required modules.
5659  For example:
5660 \newline
5661
5662
5663 \layout Standard
5664
5665 \family sans
5666 \series bold
5667 sdcc -c _divsint.c
5668
5669 \layout Standard
5670
5671 \family sans
5672 \series bold
5673 sdcc -c _divuint.c
5674
5675 \layout Standard
5676
5677 \family sans
5678 \series bold
5679 sdcc -c _modsint.c
5680
5681 \layout Standard
5682
5683 \family sans
5684 \series bold
5685 sdcc -c _moduint.c
5686
5687 \layout Standard
5688
5689 \family sans
5690 \series bold
5691 sdcc -c _mulint.c
5692 \newline
5693
5694
5695 \layout Standard
5696 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
5697  and _mulint.rel.
5698  The next step is to add the .rel files to the library file:
5699 \newline
5700
5701
5702 \layout Standard
5703
5704 \family sans
5705 \series bold
5706 sdcclib libint.lib _divsint.rel
5707 \family default
5708
5709 \begin_inset LatexCommand \index{sdcclib}
5710
5711 \end_inset
5712
5713
5714
5715 \layout Standard
5716
5717 \family sans
5718 \series bold
5719 sdcclib libint.lib _divuint.rel
5720
5721 \layout Standard
5722
5723 \family sans
5724 \series bold
5725 sdcclib libint.lib _modsint.rel
5726
5727 \layout Standard
5728
5729 \family sans
5730 \series bold
5731 sdcclib libint.lib _moduint.rel
5732
5733 \layout Standard
5734
5735 \family sans
5736 \series bold
5737 sdcclib libint.lib _mulint.rel
5738 \series default
5739
5740 \newline
5741
5742
5743 \layout Standard
5744 If the file already exists in the library, it will be replaced.
5745  To see what modules and symbols are included in the library, options -s
5746  and -m are available.
5747  For example:
5748 \newline
5749
5750 \newline
5751
5752 \family sans
5753 \series bold
5754 sdcclib -s libint.lib
5755 \family default
5756
5757 \begin_inset LatexCommand \index{sdcclib}
5758
5759 \end_inset
5760
5761
5762 \newline
5763
5764 \family typewriter
5765 \series default
5766 _divsint.rel:
5767
5768 \layout Standard
5769
5770 \family typewriter
5771 __divsint_a_1_1
5772
5773 \layout Standard
5774
5775 \family typewriter
5776 __divsint_PARM_2
5777
5778 \layout Standard
5779
5780 \family typewriter
5781 __divsint
5782 \newline
5783 _divuint.rel:
5784
5785 \layout Standard
5786
5787 \family typewriter
5788 __divuint_a_1_1
5789
5790 \layout Standard
5791
5792 \family typewriter
5793 __divuint_PARM_2
5794
5795 \layout Standard
5796
5797 \family typewriter
5798 __divuint_reste_1_1
5799
5800 \layout Standard
5801
5802 \family typewriter
5803 __divuint_count_1_1
5804
5805 \layout Standard
5806
5807 \family typewriter
5808 __divuint
5809 \newline
5810 _modsint.rel:
5811
5812 \layout Standard
5813
5814 \family typewriter
5815 __modsint_a_1_1
5816
5817 \layout Standard
5818
5819 \family typewriter
5820 __modsint_PARM_2
5821
5822 \layout Standard
5823
5824 \family typewriter
5825 __modsint
5826 \newline
5827 _moduint.rel:
5828
5829 \layout Standard
5830
5831 \family typewriter
5832 __moduint_a_1_1
5833
5834 \layout Standard
5835
5836 \family typewriter
5837 __moduint_PARM_2
5838
5839 \layout Standard
5840
5841 \family typewriter
5842 __moduint_count_1_1
5843
5844 \layout Standard
5845
5846 \family typewriter
5847 __moduint
5848 \newline
5849 _mulint.rel:
5850
5851 \layout Standard
5852
5853 \family typewriter
5854 __mulint_PARM_2
5855
5856 \layout Standard
5857
5858 \family typewriter
5859 __mulint
5860 \family default
5861 \series bold
5862
5863 \newline
5864
5865
5866 \layout Standard
5867 \added_space_bottom bigskip 
5868 If the source files are compiled using -
5869 \begin_inset ERT
5870 status Collapsed
5871
5872 \layout Standard
5873
5874
5875 \backslash
5876 /
5877
5878 \end_inset
5879
5880 -debug
5881 \begin_inset LatexCommand \index{-\/-debug}
5882
5883 \end_inset
5884
5885 , the corresponding debug information file .adb will be include in the library
5886  file as well.
5887  The library files created with sdcclib are plain text files, so they can
5888  be viewed with a text editor.
5889  It is not recomended to modify a library file created with sdcclib using
5890  a text editor, as there are file indexes numbers located accross the file
5891  used by the linker to quickly locate the required module to link.
5892  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
5893  it can be safely deleted, since all the information required for linking
5894  is embedded in the library file itself.
5895  Library files created using sdcclib are used as described in the preceding
5896  sections.
5897
5898
5899
5900 \layout Section
5901 Command Line Options
5902 \begin_inset LatexCommand \index{Command Line Options}
5903
5904 \end_inset
5905
5906
5907
5908 \layout Subsection
5909 Processor Selection Options
5910 \begin_inset LatexCommand \index{Options processor selection}
5911
5912 \end_inset
5913
5914
5915 \begin_inset LatexCommand \index{Processor selection options}
5916
5917 \end_inset
5918
5919
5920
5921 \layout List
5922 \labelwidthstring 00.00.0000
5923
5924 \series bold
5925 -mmcs51
5926 \begin_inset LatexCommand \index{-mmcs51}
5927
5928 \end_inset
5929
5930
5931 \series default
5932  Generate code for the Intel MCS51
5933 \begin_inset LatexCommand \index{MCS51}
5934
5935 \end_inset
5936
5937  family of processors.
5938  This is the default processor target.
5939
5940 \layout List
5941 \labelwidthstring 00.00.0000
5942
5943 \series bold
5944 -mds390
5945 \begin_inset LatexCommand \index{-mds390}
5946
5947 \end_inset
5948
5949
5950 \series default
5951  Generate code for the Dallas DS80C390
5952 \begin_inset LatexCommand \index{DS80C390}
5953
5954 \end_inset
5955
5956  processor.
5957
5958 \layout List
5959 \labelwidthstring 00.00.0000
5960
5961 \series bold
5962 -mds400
5963 \begin_inset LatexCommand \index{-mds400}
5964
5965 \end_inset
5966
5967
5968 \series default
5969  Generate code for the Dallas DS80C400
5970 \begin_inset LatexCommand \index{DS80C400}
5971
5972 \end_inset
5973
5974  processor.
5975
5976 \layout List
5977 \labelwidthstring 00.00.0000
5978
5979 \series bold
5980 -mhc08
5981 \begin_inset LatexCommand \index{-mhc08}
5982
5983 \end_inset
5984
5985
5986 \series default
5987  Generate code for the Freescale/Motorola HC08
5988 \begin_inset LatexCommand \index{HC08}
5989
5990 \end_inset
5991
5992  family of processors.
5993
5994 \layout List
5995 \labelwidthstring 00.00.0000
5996
5997 \series bold
5998 -mz80
5999 \begin_inset LatexCommand \index{-mz80}
6000
6001 \end_inset
6002
6003
6004 \series default
6005  Generate code for the Zilog Z80
6006 \begin_inset LatexCommand \index{Z80}
6007
6008 \end_inset
6009
6010  family of processors.
6011
6012 \layout List
6013 \labelwidthstring 00.00.0000
6014
6015 \series bold
6016 -mgbz80
6017 \begin_inset LatexCommand \index{-mgbz80}
6018
6019 \end_inset
6020
6021
6022 \series default
6023  Generate code for the GameBoy Z80
6024 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6025
6026 \end_inset
6027
6028  processor (Not actively maintained).
6029
6030 \layout List
6031 \labelwidthstring 00.00.0000
6032
6033 \series bold
6034 -mavr
6035 \begin_inset LatexCommand \index{-mavr}
6036
6037 \end_inset
6038
6039
6040 \series default
6041  Generate code for the Atmel AVR
6042 \begin_inset LatexCommand \index{AVR}
6043
6044 \end_inset
6045
6046  processor (Not maintained, not complete).
6047  AVR users should probably have a look at winavr 
6048 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6049
6050 \end_inset
6051
6052  or 
6053 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6054
6055 \end_inset
6056
6057 .
6058
6059 \layout Standard
6060 \begin_inset Note
6061 collapsed true
6062
6063 \layout Standard
6064 I think it is fair to direct users there for now.
6065  Open source is also about avoiding unnecessary work .
6066  But I didn't find the 'official' link.
6067
6068 \end_inset
6069
6070
6071
6072 \layout List
6073 \labelwidthstring 00.00.0000
6074
6075 \series bold
6076 -mpic14
6077 \begin_inset LatexCommand \index{-mpic14}
6078
6079 \end_inset
6080
6081
6082 \series default
6083  Generate code for the Microchip PIC 14
6084 \begin_inset LatexCommand \index{PIC14}
6085
6086 \end_inset
6087
6088 -bit processors (p16f84 and variants.
6089  In development, not complete).
6090
6091 \layout Standard
6092 \begin_inset Note
6093 collapsed true
6094
6095 \layout Standard
6096 p16f627 p16f628 p16f84 p16f873 p16f877?
6097
6098 \end_inset
6099
6100
6101
6102 \layout List
6103 \labelwidthstring 00.00.0000
6104
6105 \series bold
6106 -mpic16
6107 \begin_inset LatexCommand \index{-mpic16}
6108
6109 \end_inset
6110
6111
6112 \series default
6113  Generate code for the Microchip PIC 16
6114 \begin_inset LatexCommand \index{PIC16}
6115
6116 \end_inset
6117
6118 -bit processors (p18f452 and variants.
6119  In development, not complete).
6120
6121 \layout List
6122 \labelwidthstring 00.00.0000
6123
6124 \series bold
6125 -mtlcs900h
6126 \series default
6127  Generate code for the Toshiba TLCS-900H
6128 \begin_inset LatexCommand \index{TLCS-900H}
6129
6130 \end_inset
6131
6132  processor (Not maintained, not complete).
6133
6134 \layout List
6135 \labelwidthstring 00.00.0000
6136 \added_space_bottom bigskip 
6137
6138 \series bold
6139 -mxa51
6140 \begin_inset LatexCommand \index{-mxa51}
6141
6142 \end_inset
6143
6144
6145 \series default
6146  Generate code for the Phillips XA51
6147 \begin_inset LatexCommand \index{XA51}
6148
6149 \end_inset
6150
6151  processor (Not maintained, not complete).
6152
6153
6154 \layout Subsection
6155 Preprocessor Options
6156 \begin_inset LatexCommand \index{Options preprocessor}
6157
6158 \end_inset
6159
6160
6161 \begin_inset LatexCommand \index{Preprocessor options}
6162
6163 \end_inset
6164
6165
6166 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6167
6168 \end_inset
6169
6170
6171
6172 \layout List
6173 \labelwidthstring 00.00.0000
6174
6175 \series bold
6176 -I<path>
6177 \begin_inset LatexCommand \index{-I<path>}
6178
6179 \end_inset
6180
6181
6182 \series default
6183  The additional location where the pre processor will look for <..h> or 
6184 \begin_inset Quotes eld
6185 \end_inset
6186
6187 ..h
6188 \begin_inset Quotes erd
6189 \end_inset
6190
6191  files.
6192
6193 \layout List
6194 \labelwidthstring 00.00.0000
6195
6196 \series bold
6197 -D<macro[=value]>
6198 \begin_inset LatexCommand \index{-D<macro[=value]>}
6199
6200 \end_inset
6201
6202
6203 \series default
6204  Command line definition of macros.
6205  Passed to the preprocessor.
6206
6207 \layout List
6208 \labelwidthstring 00.00.0000
6209
6210 \series bold
6211 -M
6212 \begin_inset LatexCommand \index{-M}
6213
6214 \end_inset
6215
6216
6217 \series default
6218  Tell the preprocessor to output a rule suitable for make describing the
6219  dependencies of each object file.
6220  For each source file, the preprocessor outputs one make-rule whose target
6221  is the object file name for that source file and whose dependencies are
6222  all the files `#include'd in it.
6223  This rule may be a single line or may be continued with `
6224 \backslash
6225 '-newline if it is long.
6226  The list of rules is printed on standard output instead of the preprocessed
6227  C program.
6228  `-M' implies `-E
6229 \begin_inset LatexCommand \index{-E}
6230
6231 \end_inset
6232
6233 '.
6234
6235 \layout List
6236 \labelwidthstring 00.00.0000
6237
6238 \series bold
6239 -C
6240 \begin_inset LatexCommand \index{-C}
6241
6242 \end_inset
6243
6244
6245 \series default
6246  Tell the preprocessor not to discard comments.
6247  Used with the `-E' option.
6248
6249 \layout List
6250 \labelwidthstring 00.00.0000
6251
6252 \series bold
6253 -MM
6254 \begin_inset LatexCommand \index{-MM}
6255
6256 \end_inset
6257
6258
6259 \size large
6260 \bar under
6261  
6262 \series default
6263 \size default
6264 \bar default
6265 Like `-M' but the output mentions only the user header files included with
6266  `#include 
6267 \begin_inset Quotes eld
6268 \end_inset
6269
6270 file"'.
6271  System header files included with `#include <file>' are omitted.
6272
6273 \layout List
6274 \labelwidthstring 00.00.0000
6275
6276 \series bold
6277 -Aquestion(answer)
6278 \begin_inset LatexCommand \index{-Aquestion(answer)}
6279
6280 \end_inset
6281
6282
6283 \series default
6284  Assert the answer answer for question, in case it is tested with a preprocessor
6285  conditional such as `#if #question(answer)'.
6286  `-A-' disables the standard assertions that normally describe the target
6287  machine.
6288
6289 \layout List
6290 \labelwidthstring 00.00.0000
6291
6292 \series bold
6293 -Umacro
6294 \begin_inset LatexCommand \index{-Umacro}
6295
6296 \end_inset
6297
6298
6299 \series default
6300  Undefine macro macro.
6301  `-U' options are evaluated after all `-D' options, but before any `-include'
6302  and `-imacros' options.
6303
6304 \layout List
6305 \labelwidthstring 00.00.0000
6306
6307 \series bold
6308 -dM
6309 \begin_inset LatexCommand \index{-dM}
6310
6311 \end_inset
6312
6313
6314 \series default
6315  Tell the preprocessor to output only a list of the macro definitions that
6316  are in effect at the end of preprocessing.
6317  Used with the `-E' option.
6318
6319 \layout List
6320 \labelwidthstring 00.00.0000
6321
6322 \series bold
6323 -dD
6324 \begin_inset LatexCommand \index{-dD}
6325
6326 \end_inset
6327
6328
6329 \series default
6330  Tell the preprocessor to pass all macro definitions into the output, in
6331  their proper sequence in the rest of the output.
6332
6333 \layout List
6334 \labelwidthstring 00.00.0000
6335
6336 \series bold
6337 -dN
6338 \begin_inset LatexCommand \index{-dN}
6339
6340 \end_inset
6341
6342
6343 \size large
6344 \bar under
6345  
6346 \series default
6347 \size default
6348 \bar default
6349 Like `-dD' except that the macro arguments and contents are omitted.
6350  Only `#define name' is included in the output.
6351
6352 \layout List
6353 \labelwidthstring 00.00.0000
6354
6355 \series bold
6356 -pedantic-parse-number
6357 \begin_inset LatexCommand \index{-pedantic-parse-number}
6358
6359 \end_inset
6360
6361
6362 \size large
6363 \bar under
6364  
6365 \series default
6366 \size default
6367 \bar default
6368 Pedentic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6369  and the macro LO_B(3) gets expanded.
6370  See also #pragma pedantic_parse_number in section
6371 \begin_inset LatexCommand \ref{sec:Pragmas}
6372
6373 \end_inset
6374
6375  
6376 \emph on
6377 Note: this functionality is not in conformance with standard!
6378
6379 \layout List
6380 \labelwidthstring 00.00.0000
6381 \added_space_bottom bigskip 
6382
6383 \series bold
6384 -Wp\SpecialChar ~
6385 preprocessorOption[,preprocessorOption]
6386 \series default
6387
6388 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6389
6390 \end_inset
6391
6392 ...
6393  Pass the preprocessorOption to the preprocessor 
6394 \family typewriter
6395 sdcpp
6396 \family default
6397
6398 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6399
6400 \end_inset
6401
6402 .
6403  SDCC uses an adapted version of the preprocessor 
6404 \emph on
6405 cpp
6406 \emph default
6407  of the GNU Compiler Collection
6408 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
6409
6410 \end_inset
6411
6412  (
6413 \emph on
6414 gcc
6415 \emph default
6416  
6417 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
6418
6419 \end_inset
6420
6421 ), if you need more dedicated options please refer to the GCC\SpecialChar ~
6422 4.1.1\SpecialChar ~
6423 CPP\SpecialChar ~
6424 Manual
6425  at 
6426 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
6427
6428 \end_inset
6429
6430 .
6431
6432
6433 \layout Subsection
6434 Linker Options
6435 \begin_inset LatexCommand \index{Options linker}
6436
6437 \end_inset
6438
6439
6440 \begin_inset LatexCommand \index{Linker options}
6441
6442 \end_inset
6443
6444
6445
6446 \layout List
6447 \labelwidthstring 00.00.0000
6448
6449 \series bold
6450 -L\SpecialChar ~
6451 -
6452 \series default
6453
6454 \begin_inset ERT
6455 status Collapsed
6456
6457 \layout Standard
6458
6459
6460 \backslash
6461 /
6462
6463 \end_inset
6464
6465
6466 \series bold
6467 -lib-path
6468 \begin_inset LatexCommand \index{-\/-lib-path <path>}
6469
6470 \end_inset
6471
6472
6473 \begin_inset LatexCommand \index{-L -\/-lib-path}
6474
6475 \end_inset
6476
6477
6478 \series default
6479 \SpecialChar ~
6480 <absolute path to additional libraries> This option is passed to the linkage
6481  editor's additional libraries
6482 \begin_inset LatexCommand \index{Libraries}
6483
6484 \end_inset
6485
6486  search path.
6487  The path name must be absolute.
6488  Additional library files may be specified in the command line.
6489  See section Compiling programs for more details.
6490
6491 \layout List
6492 \labelwidthstring 00.00.0000
6493
6494 \series bold
6495 -
6496 \begin_inset ERT
6497 status Collapsed
6498
6499 \layout Standard
6500
6501
6502 \backslash
6503 /
6504
6505 \end_inset
6506
6507 -xram-loc
6508 \series default
6509
6510 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
6511
6512 \end_inset
6513
6514 \SpecialChar ~
6515 <Value> The start location of the external ram
6516 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
6517
6518 \end_inset
6519
6520 , default value is 0.
6521  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6522 \begin_inset ERT
6523 status Collapsed
6524
6525 \layout Standard
6526
6527
6528 \backslash
6529 /
6530
6531 \end_inset
6532
6533 -xram-loc 0x8000 or -
6534 \begin_inset ERT
6535 status Collapsed
6536
6537 \layout Standard
6538
6539
6540 \backslash
6541 /
6542
6543 \end_inset
6544
6545 -xram-loc 32768.
6546
6547 \layout List
6548 \labelwidthstring 00.00.0000
6549
6550 \series bold
6551 -
6552 \begin_inset ERT
6553 status Collapsed
6554
6555 \layout Standard
6556
6557
6558 \backslash
6559 /
6560
6561 \end_inset
6562
6563 -code-loc
6564 \series default
6565
6566 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
6567
6568 \end_inset
6569
6570 \SpecialChar ~
6571 <Value> The start location of the code
6572 \begin_inset LatexCommand \index{code}
6573
6574 \end_inset
6575
6576  segment, default value 0.
6577  Note when this option is used the interrupt vector table
6578 \begin_inset LatexCommand \index{interrupt vector table}
6579
6580 \end_inset
6581
6582  is also relocated to the given address.
6583  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6584 \begin_inset ERT
6585 status Collapsed
6586
6587 \layout Standard
6588
6589
6590 \backslash
6591 /
6592
6593 \end_inset
6594
6595 -code-loc 0x8000 or -
6596 \begin_inset ERT
6597 status Collapsed
6598
6599 \layout Standard
6600
6601
6602 \backslash
6603 /
6604
6605 \end_inset
6606
6607 -code-loc 32768.
6608
6609 \layout List
6610 \labelwidthstring 00.00.0000
6611
6612 \series bold
6613 -
6614 \begin_inset ERT
6615 status Collapsed
6616
6617 \layout Standard
6618
6619
6620 \backslash
6621 /
6622
6623 \end_inset
6624
6625 -stack-loc
6626 \series default
6627
6628 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
6629
6630 \end_inset
6631
6632 \SpecialChar ~
6633 <Value> By default the stack
6634 \begin_inset LatexCommand \index{stack}
6635
6636 \end_inset
6637
6638  is placed after the data segment.
6639  Using this option the stack can be placed anywhere in the internal memory
6640  space of the 8051.
6641  The value entered can be in Hexadecimal or Decimal format, e.g.
6642  -
6643 \begin_inset ERT
6644 status Collapsed
6645
6646 \layout Standard
6647
6648
6649 \backslash
6650 /
6651
6652 \end_inset
6653
6654 -stack-loc 0x20 or -
6655 \begin_inset ERT
6656 status Collapsed
6657
6658 \layout Standard
6659
6660
6661 \backslash
6662 /
6663
6664 \end_inset
6665
6666 -stack-loc 32.
6667  Since the sp register is incremented before a push or call, the initial
6668  sp will be set to one byte prior the provided value.
6669  The provided value should not overlap any other memory areas such as used
6670  register banks or the data segment and with enough space for the current
6671  application.
6672  The 
6673 \series bold
6674 -
6675 \begin_inset ERT
6676 status Collapsed
6677
6678 \layout Standard
6679
6680
6681 \backslash
6682 /
6683
6684 \end_inset
6685
6686 -pack-iram
6687 \series default
6688 \SpecialChar ~
6689
6690 \begin_inset LatexCommand \index{-\/-pack-iram}
6691
6692 \end_inset
6693
6694  option (which is now a default setting) will override this setting, so
6695  you should also specify the 
6696 \series bold
6697 -
6698 \begin_inset ERT
6699 status Collapsed
6700
6701 \layout Standard
6702
6703
6704 \backslash
6705 /
6706
6707 \end_inset
6708
6709 -no-pack-iram
6710 \series default
6711 \SpecialChar ~
6712
6713 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6714
6715 \end_inset
6716
6717  option if you need to manually place the stack.
6718
6719 \layout List
6720 \labelwidthstring 00.00.0000
6721
6722 \series bold
6723 -
6724 \begin_inset ERT
6725 status Collapsed
6726
6727 \layout Standard
6728
6729
6730 \backslash
6731 /
6732
6733 \end_inset
6734
6735 -xstack-loc
6736 \series default
6737
6738 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
6739
6740 \end_inset
6741
6742 \SpecialChar ~
6743 <Value> By default the external stack
6744 \begin_inset LatexCommand \index{xstack}
6745
6746 \end_inset
6747
6748  is placed after the pdata
6749 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6750
6751 \end_inset
6752
6753  segment.
6754  Using this option the xstack can be placed anywhere in the external memory
6755  space of the 8051.
6756  The value entered can be in Hexadecimal or Decimal format, e.g.
6757  -
6758 \begin_inset ERT
6759 status Collapsed
6760
6761 \layout Standard
6762
6763
6764 \backslash
6765 /
6766
6767 \end_inset
6768
6769 -xstack-loc 0x8000 or -
6770 \begin_inset ERT
6771 status Collapsed
6772
6773 \layout Standard
6774
6775
6776 \backslash
6777 /
6778
6779 \end_inset
6780
6781 -stack-loc 32768.
6782  The provided value should not overlap any other memory areas such as the
6783  pdata or xdata segment and with enough space for the current application.
6784
6785 \layout List
6786 \labelwidthstring 00.00.0000
6787
6788 \series bold
6789 -
6790 \begin_inset ERT
6791 status Collapsed
6792
6793 \layout Standard
6794
6795
6796 \backslash
6797 /
6798
6799 \end_inset
6800
6801 -data-loc
6802 \series default
6803
6804 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
6805
6806 \end_inset
6807
6808 \SpecialChar ~
6809 <Value> The start location of the internal ram data
6810 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
6811
6812 \end_inset
6813
6814  segment.
6815  The value entered can be in Hexadecimal or Decimal format, eg.
6816  -
6817 \begin_inset ERT
6818 status Collapsed
6819
6820 \layout Standard
6821
6822
6823 \backslash
6824 /
6825
6826 \end_inset
6827
6828 -data-loc 0x20 or -
6829 \begin_inset ERT
6830 status Collapsed
6831
6832 \layout Standard
6833
6834
6835 \backslash
6836 /
6837
6838 \end_inset
6839
6840 -data-loc 32.
6841  (By default, the start location of the internal ram data segment  is set
6842  as low as possible in memory, taking into account the used register banks
6843  and the bit segment at address 0x20.
6844  For example if register banks 0 and 1 are used without bit variables, the
6845  data segment will be set, if -
6846 \begin_inset ERT
6847 status Collapsed
6848
6849 \layout Standard
6850
6851
6852 \backslash
6853 /
6854
6855 \end_inset
6856
6857 -data-loc is not used, to location 0x10.)
6858
6859 \layout List
6860 \labelwidthstring 00.00.0000
6861
6862 \series bold
6863 -
6864 \begin_inset ERT
6865 status Collapsed
6866
6867 \layout Standard
6868
6869
6870 \backslash
6871 /
6872
6873 \end_inset
6874
6875 -idata-loc
6876 \series default
6877
6878 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
6879
6880 \end_inset
6881
6882 \SpecialChar ~
6883 <Value> The start location of the indirectly addressable internal ram
6884 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
6885
6886 \end_inset
6887
6888  of the 8051, default value is 0x80.
6889  The value entered can be in Hexadecimal or Decimal format, eg.
6890  -
6891 \begin_inset ERT
6892 status Collapsed
6893
6894 \layout Standard
6895
6896
6897 \backslash
6898 /
6899
6900 \end_inset
6901
6902 -idata-loc 0x88 or -
6903 \begin_inset ERT
6904 status Collapsed
6905
6906 \layout Standard
6907
6908
6909 \backslash
6910 /
6911
6912 \end_inset
6913
6914 -idata-loc 136.
6915
6916 \layout List
6917 \labelwidthstring 00.00.0000
6918
6919 \series bold
6920 -
6921 \begin_inset ERT
6922 status Collapsed
6923
6924 \layout Standard
6925
6926
6927 \backslash
6928 /
6929
6930 \end_inset
6931
6932 -bit-loc
6933 \series default
6934 \SpecialChar ~
6935 <Value> The start location of the bit
6936 \begin_inset LatexCommand \index{bit}
6937
6938 \end_inset
6939
6940  addressable internal ram of the 8051.
6941  This is 
6942 \emph on
6943 not
6944 \emph default
6945  implemented yet.
6946  Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
6947 -bBSEG=<Value>.
6948
6949 \layout List
6950 \labelwidthstring 00.00.0000
6951
6952 \series bold
6953 -
6954 \begin_inset ERT
6955 status Collapsed
6956
6957 \layout Standard
6958
6959
6960 \backslash
6961 /
6962
6963 \end_inset
6964
6965 -out-fmt-ihx
6966 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
6967
6968 \end_inset
6969
6970
6971 \bar under
6972  
6973 \series default
6974 \bar default
6975 The linker output (final object code) is in Intel Hex format.
6976 \begin_inset LatexCommand \index{Intel hex format}
6977
6978 \end_inset
6979
6980  This is the default option.
6981  The format itself is documented in the documentation of srecord
6982 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6983
6984 \end_inset
6985
6986 .
6987
6988 \layout List
6989 \labelwidthstring 00.00.0000
6990
6991 \series bold
6992 -
6993 \begin_inset ERT
6994 status Collapsed
6995
6996 \layout Standard
6997
6998
6999 \backslash
7000 /
7001
7002 \end_inset
7003
7004 -out-fmt-s19
7005 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7006
7007 \end_inset
7008
7009
7010 \bar under
7011  
7012 \series default
7013 \bar default
7014 The linker output (final object code) is in Motorola S19 format
7015 \begin_inset LatexCommand \index{Motorola S19 format}
7016
7017 \end_inset
7018
7019 .
7020  The format itself is documented in the documentation of srecord.
7021
7022 \layout List
7023 \labelwidthstring 00.00.0000
7024
7025 \series bold
7026 -
7027 \begin_inset ERT
7028 status Collapsed
7029
7030 \layout Standard
7031
7032
7033 \backslash
7034 /
7035
7036 \end_inset
7037
7038 -out-fmt-elf
7039 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7040
7041 \end_inset
7042
7043
7044 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7045
7046 \end_inset
7047
7048
7049 \bar under
7050  
7051 \series default
7052 \bar default
7053 The linker output (final object code) is in ELF format
7054 \begin_inset LatexCommand \index{ELF format}
7055
7056 \end_inset
7057
7058 .
7059  (Currently only supported for the HC08
7060 \begin_inset LatexCommand \index{HC08}
7061
7062 \end_inset
7063
7064  processors)
7065
7066 \layout List
7067 \labelwidthstring 00.00.0000
7068 \added_space_bottom bigskip 
7069
7070 \series bold
7071 -Wl\SpecialChar ~
7072 linkOption[,linkOption]
7073 \series default
7074
7075 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7076
7077 \end_inset
7078
7079 ...
7080  Pass the linkOption to the linker.
7081  If a bootloader is used an option like 
7082 \begin_inset Quotes sld
7083 \end_inset
7084
7085 -Wl\SpecialChar ~
7086 -bCSEG=0x1000
7087 \begin_inset Quotes srd
7088 \end_inset
7089
7090  would be typical to set the start of the code segment.
7091  See also #pragma constseg and #pragma codeseg in section 
7092 \begin_inset LatexCommand \ref{sec:Pragmas}
7093
7094 \end_inset
7095
7096  .
7097  File sdcc/as/doc/asxhtm.html has more on linker options.
7098
7099
7100 \layout Subsection
7101 MCS51 Options
7102 \begin_inset LatexCommand \index{Options MCS51}
7103
7104 \end_inset
7105
7106
7107 \begin_inset LatexCommand \index{MCS51 options}
7108
7109 \end_inset
7110
7111
7112
7113 \layout List
7114 \labelwidthstring 00.00.0000
7115
7116 \series bold
7117 -
7118 \begin_inset ERT
7119 status Collapsed
7120
7121 \layout Standard
7122
7123
7124 \backslash
7125 /
7126
7127 \end_inset
7128
7129 -model-small
7130 \begin_inset LatexCommand \index{-\/-model-small}
7131
7132 \end_inset
7133
7134
7135 \series default
7136 \size large
7137 \emph on
7138  
7139 \size default
7140 \emph default
7141 Generate code for Small Model programs, see section Memory Models for more
7142  details.
7143  This is the default model.
7144
7145 \layout List
7146 \labelwidthstring 00.00.0000
7147
7148 \series bold
7149 -
7150 \begin_inset ERT
7151 status Collapsed
7152
7153 \layout Standard
7154
7155
7156 \backslash
7157 /
7158
7159 \end_inset
7160
7161 -model-medium
7162 \begin_inset LatexCommand \index{-\/-model-medium}
7163
7164 \end_inset
7165
7166
7167 \series default
7168  Generate code for Medium model programs, see section Memory Models for
7169  more details.
7170  If this option is used all source files in the project have to be compiled
7171  with this option.
7172  It must also be used when invoking the linker.
7173
7174 \layout List
7175 \labelwidthstring 00.00.0000
7176
7177 \series bold
7178 -
7179 \begin_inset ERT
7180 status Collapsed
7181
7182 \layout Standard
7183
7184
7185 \backslash
7186 /
7187
7188 \end_inset
7189
7190 -model-large
7191 \begin_inset LatexCommand \index{-\/-model-large}
7192
7193 \end_inset
7194
7195
7196 \series default
7197  Generate code for Large model programs, see section Memory Models for more
7198  details.
7199  If this option is used all source files in the project have to be compiled
7200  with this option.
7201  It must also be used when invoking the linker.
7202
7203 \layout List
7204 \labelwidthstring 00.00.0000
7205
7206 \series bold
7207 -
7208 \begin_inset ERT
7209 status Collapsed
7210
7211 \layout Standard
7212
7213
7214 \backslash
7215 /
7216
7217 \end_inset
7218
7219 -xstack
7220 \begin_inset LatexCommand \index{-\/-xstack}
7221
7222 \end_inset
7223
7224
7225 \series default
7226  Uses a pseudo stack in the pdata
7227 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7228
7229 \end_inset
7230
7231  area (usually the first 256 bytes in the external ram) for allocating variables
7232  and passing parameters.
7233  See section 
7234 \begin_inset LatexCommand \ref{sub:External-Stack}
7235
7236 \end_inset
7237
7238 \SpecialChar ~
7239  External Stack for more details.
7240
7241 \layout List
7242 \labelwidthstring 00.00.0000
7243
7244 \series bold
7245 -
7246 \begin_inset ERT
7247 status Collapsed
7248
7249 \layout Standard
7250
7251
7252 \backslash
7253 /
7254
7255 \end_inset
7256
7257 -iram-size
7258 \series default
7259 \SpecialChar ~
7260 <Value>
7261 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7262
7263 \end_inset
7264
7265  Causes the linker to check if the internal ram usage is within limits of
7266  the given value.
7267
7268 \layout List
7269 \labelwidthstring 00.00.0000
7270
7271 \series bold
7272 -
7273 \begin_inset ERT
7274 status Collapsed
7275
7276 \layout Standard
7277
7278
7279 \backslash
7280 /
7281
7282 \end_inset
7283
7284 -xram-size
7285 \series default
7286 \SpecialChar ~
7287 <Value>
7288 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7289
7290 \end_inset
7291
7292  Causes the linker to check if the external ram usage is within limits of
7293  the given value.
7294
7295 \layout List
7296 \labelwidthstring 00.00.0000
7297
7298 \series bold
7299 -
7300 \begin_inset ERT
7301 status Collapsed
7302
7303 \layout Standard
7304
7305
7306 \backslash
7307 /
7308
7309 \end_inset
7310
7311 -code-size
7312 \series default
7313 \SpecialChar ~
7314 <Value>
7315 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7316
7317 \end_inset
7318
7319  Causes the linker to check if the code memory usage is within limits of
7320  the given value.
7321
7322 \layout List
7323 \labelwidthstring 00.00.0000
7324
7325 \series bold
7326 -
7327 \begin_inset ERT
7328 status Collapsed
7329
7330 \layout Standard
7331
7332
7333 \backslash
7334 /
7335
7336 \end_inset
7337
7338 -stack-size
7339 \series default
7340 \SpecialChar ~
7341 <Value>
7342 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
7343
7344 \end_inset
7345
7346  Causes the linker to check if there is at minimum <Value> bytes for stack.
7347
7348 \layout List
7349 \labelwidthstring 00.00.0000
7350
7351 \series bold
7352 -
7353 \begin_inset ERT
7354 status Collapsed
7355
7356 \layout Standard
7357
7358
7359 \backslash
7360 /
7361
7362 \end_inset
7363
7364 -pack-iram
7365 \series default
7366 \SpecialChar ~
7367
7368 \begin_inset LatexCommand \index{-\/-pack-iram}
7369
7370 \end_inset
7371
7372  Causes the linker to use unused register banks for data variables and pack
7373  data, idata and stack together.
7374  This is the default now.
7375
7376 \layout List
7377 \labelwidthstring 00.00.0000
7378 \added_space_bottom bigskip 
7379
7380 \series bold
7381 -
7382 \begin_inset ERT
7383 status Collapsed
7384
7385 \layout Standard
7386
7387
7388 \backslash
7389 /
7390
7391 \end_inset
7392
7393 -no-pack-iram
7394 \series default
7395 \SpecialChar ~
7396
7397 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7398
7399 \end_inset
7400
7401  Causes the linker to use old style for allocating memory areas.
7402
7403
7404 \layout Subsection
7405 DS390 / DS400 Options
7406 \begin_inset LatexCommand \index{Options DS390}
7407
7408 \end_inset
7409
7410
7411 \begin_inset LatexCommand \index{DS390}
7412
7413 \end_inset
7414
7415
7416
7417 \layout List
7418 \labelwidthstring 00.00.0000
7419
7420 \series bold
7421 -
7422 \begin_inset ERT
7423 status Collapsed
7424
7425 \layout Standard
7426
7427
7428 \backslash
7429 /
7430
7431 \end_inset
7432
7433 -model-flat24
7434 \series default
7435
7436 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
7437
7438 \end_inset
7439
7440
7441 \size large
7442 \emph on
7443  
7444 \size default
7445 \emph default
7446 Generate 24-bit flat mode code.
7447  This is the one and only that the ds390 code generator supports right now
7448  and is default when using 
7449 \emph on
7450 -mds390
7451 \emph default
7452 .
7453  See section Memory Models for more details.
7454
7455 \layout List
7456 \labelwidthstring 00.00.0000
7457
7458 \series bold
7459 -
7460 \begin_inset ERT
7461 status Collapsed
7462
7463 \layout Standard
7464
7465
7466 \backslash
7467 /
7468
7469 \end_inset
7470
7471 -protect-sp-update
7472 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
7473
7474 \end_inset
7475
7476
7477 \series default
7478  disable interrupts during ESP:SP updates.
7479
7480 \layout List
7481 \labelwidthstring 00.00.0000
7482
7483 \series bold
7484 -
7485 \begin_inset ERT
7486 status Collapsed
7487
7488 \layout Standard
7489
7490
7491 \backslash
7492 /
7493
7494 \end_inset
7495
7496 -stack-10bit
7497 \series default
7498
7499 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
7500
7501 \end_inset
7502
7503  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
7504  This is the one and only that the ds390 code generator supports right now
7505  and is default when using 
7506 \emph on
7507 -mds390
7508 \emph default
7509 .
7510  In this mode, the stack is located in the lower 1K of the internal RAM,
7511  which is mapped to 0x400000.
7512  Note that the support is incomplete, since it still uses a single byte
7513  as the stack pointer.
7514  This means that only the lower 256 bytes of the potential 1K stack space
7515  will actually be used.
7516  However, this does allow you to reclaim the precious 256 bytes of low RAM
7517  for use for the DATA and IDATA segments.
7518  The compiler will not generate any code to put the processor into 10 bit
7519  stack mode.
7520  It is important to ensure that the processor is in this mode before calling
7521  any re-entrant functions compiled with this option.
7522  In principle, this should work with the 
7523 \emph on
7524 -
7525 \begin_inset ERT
7526 status Collapsed
7527
7528 \layout Standard
7529
7530
7531 \backslash
7532 /
7533
7534 \end_inset
7535
7536 -stack-auto
7537 \begin_inset LatexCommand \index{-\/-stack-auto}
7538
7539 \end_inset
7540
7541
7542 \emph default
7543  option, but that has not been tested.
7544  It is incompatible with the 
7545 \emph on
7546 -
7547 \begin_inset ERT
7548 status Collapsed
7549
7550 \layout Standard
7551
7552
7553 \backslash
7554 /
7555
7556 \end_inset
7557
7558 -xstack
7559 \begin_inset LatexCommand \index{-\/-xstack}
7560
7561 \end_inset
7562
7563
7564 \emph default
7565  option.
7566  It also only makes sense if the processor is in 24 bit contiguous addressing
7567  mode (see the 
7568 \emph on
7569 -
7570 \begin_inset ERT
7571 status Collapsed
7572
7573 \layout Standard
7574
7575
7576 \backslash
7577 /
7578
7579 \end_inset
7580
7581 -model-flat24 option
7582 \emph default
7583 ).
7584
7585 \layout List
7586 \labelwidthstring 00.00.0000
7587
7588 \series bold
7589 -
7590 \begin_inset ERT
7591 status Collapsed
7592
7593 \layout Standard
7594
7595
7596 \backslash
7597 /
7598
7599 \end_inset
7600
7601 -stack-probe
7602 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
7603
7604 \end_inset
7605
7606
7607 \series default
7608  insert call to function __stack_probe at each function prologue.
7609
7610 \layout List
7611 \labelwidthstring 00.00.0000
7612
7613 \series bold
7614 -
7615 \begin_inset ERT
7616 status Collapsed
7617
7618 \layout Standard
7619
7620
7621 \backslash
7622 /
7623
7624 \end_inset
7625
7626 -tini-libid
7627 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
7628
7629 \end_inset
7630
7631
7632 \series default
7633  <nnnn> LibraryID used in -mTININative.
7634  
7635
7636 \layout List
7637 \labelwidthstring 00.00.0000
7638 \added_space_bottom bigskip 
7639
7640 \series bold
7641 -
7642 \begin_inset ERT
7643 status Collapsed
7644
7645 \layout Standard
7646
7647
7648 \backslash
7649 /
7650
7651 \end_inset
7652
7653 -use-accelerator
7654 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
7655
7656 \end_inset
7657
7658
7659 \series default
7660  generate code for DS390 Arithmetic Accelerator.
7661  
7662
7663
7664 \layout Subsection
7665 Z80 Options
7666 \begin_inset LatexCommand \index{Options Z80}
7667
7668 \end_inset
7669
7670
7671 \begin_inset LatexCommand \index{Z80}
7672
7673 \end_inset
7674
7675
7676
7677 \layout List
7678 \labelwidthstring 00.00.0000
7679
7680 \series bold
7681 -
7682 \begin_inset ERT
7683 status Collapsed
7684
7685 \layout Standard
7686
7687
7688 \backslash
7689 /
7690
7691 \end_inset
7692
7693 -callee-saves-bc
7694 \series default
7695
7696 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
7697
7698 \end_inset
7699
7700
7701 \size large
7702 \emph on
7703  
7704 \size default
7705 \emph default
7706 Force a called function to always save BC.
7707
7708 \layout List
7709 \labelwidthstring 00.00.0000
7710 \added_space_bottom bigskip 
7711
7712 \series bold
7713 -
7714 \begin_inset ERT
7715 status Collapsed
7716
7717 \layout Standard
7718
7719
7720 \backslash
7721 /
7722
7723 \end_inset
7724
7725 -no-std-crt0
7726 \series default
7727
7728 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
7729
7730 \end_inset
7731
7732  When linking, skip the standard crt0.o object file.
7733  You must provide your own crt0.o for your system when linking.
7734  
7735
7736
7737 \layout Subsection
7738 Optimization Options
7739 \begin_inset LatexCommand \index{Options optimization}
7740
7741 \end_inset
7742
7743
7744 \begin_inset LatexCommand \index{Optimization options}
7745
7746 \end_inset
7747
7748
7749
7750 \layout List
7751 \labelwidthstring 00.00.0000
7752
7753 \series bold
7754 -
7755 \begin_inset ERT
7756 status Collapsed
7757
7758 \layout Standard
7759
7760
7761 \backslash
7762 /
7763
7764 \end_inset
7765
7766 -nogcse
7767 \begin_inset LatexCommand \index{-\/-nogcse}
7768
7769 \end_inset
7770
7771
7772 \series default
7773  Will not do global subexpression elimination, this option may be used when
7774  the compiler creates undesirably large stack/data spaces to store compiler
7775  temporaries (
7776 \emph on
7777 s
7778 \emph default
7779 pill 
7780 \emph on
7781 loc
7782 \emph default
7783 ations, sloc
7784 \begin_inset LatexCommand \index{sloc (spill location)}
7785
7786 \end_inset
7787
7788 ).
7789  A warning message will be generated when this happens and the compiler
7790  will indicate the number of extra bytes it allocated.
7791  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7792 nogcse
7793 \begin_inset LatexCommand \index{\#pragma nogcse}
7794
7795 \end_inset
7796
7797  can be used to turn off global subexpression elimination
7798 \begin_inset LatexCommand \index{Subexpression elimination}
7799
7800 \end_inset
7801
7802  for a given function only.
7803
7804 \layout List
7805 \labelwidthstring 00.00.0000
7806
7807 \series bold
7808 -
7809 \begin_inset ERT
7810 status Collapsed
7811
7812 \layout Standard
7813
7814
7815 \backslash
7816 /
7817
7818 \end_inset
7819
7820 -noinvariant
7821 \begin_inset LatexCommand \index{-\/-noinvariant}
7822
7823 \end_inset
7824
7825
7826 \series default
7827  Will not do loop invariant optimizations, this may be turned off for reasons
7828  explained for the previous option.
7829  For more details of loop optimizations performed see Loop Invariants in
7830  section 
7831 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
7832
7833 \end_inset
7834
7835 .
7836  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7837 noinvariant
7838 \begin_inset LatexCommand \index{\#pragma noinvariant}
7839
7840 \end_inset
7841
7842  can be used to turn off invariant optimizations for a given function only.
7843
7844 \layout List
7845 \labelwidthstring 00.00.0000
7846
7847 \series bold
7848 -
7849 \begin_inset ERT
7850 status Collapsed
7851
7852 \layout Standard
7853
7854
7855 \backslash
7856 /
7857
7858 \end_inset
7859
7860 -noinduction
7861 \begin_inset LatexCommand \index{-\/-noinduction}
7862
7863 \end_inset
7864
7865
7866 \series default
7867  Will not do loop induction optimizations, see section strength reduction
7868  for more details.
7869  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7870 noinduction
7871 \begin_inset LatexCommand \index{\#pragma noinduction}
7872
7873 \end_inset
7874
7875  can be used to turn off induction optimizations for a given function only.
7876
7877 \layout List
7878 \labelwidthstring 00.00.0000
7879
7880 \series bold
7881 -
7882 \begin_inset ERT
7883 status Collapsed
7884
7885 \layout Standard
7886
7887
7888 \backslash
7889 /
7890
7891 \end_inset
7892
7893 -nojtbound
7894 \begin_inset LatexCommand \index{-\/-nojtbound}
7895
7896 \end_inset
7897
7898
7899 \size large
7900 \bar under
7901  
7902 \series default
7903 \size default
7904 \bar default
7905  Will not generate boundary condition check when switch statements
7906 \begin_inset LatexCommand \index{switch statement}
7907
7908 \end_inset
7909
7910  are implemented using jump-tables.
7911  See section 
7912 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
7913
7914 \end_inset
7915
7916 \SpecialChar ~
7917 Switch Statements for more details.
7918  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7919 nojtbound
7920 \begin_inset LatexCommand \index{\#pragma nojtbound}
7921
7922 \end_inset
7923
7924  can be used to turn off boundary checking for jump tables for a given function
7925  only.
7926
7927 \layout List
7928 \labelwidthstring 00.00.0000
7929
7930 \series bold
7931 -
7932 \begin_inset ERT
7933 status Collapsed
7934
7935 \layout Standard
7936
7937
7938 \backslash
7939 /
7940
7941 \end_inset
7942
7943 -noloopreverse
7944 \begin_inset LatexCommand \index{-\/-noloopreverse}
7945
7946 \end_inset
7947
7948
7949 \series default
7950 \size large
7951  
7952 \size default
7953 Will not do loop reversal 
7954 \begin_inset LatexCommand \index{Loop reversing}
7955
7956 \end_inset
7957
7958 optimization.
7959
7960 \layout List
7961 \labelwidthstring 00.00.0000
7962 -
7963 \begin_inset ERT
7964 status Collapsed
7965
7966 \layout Standard
7967
7968
7969 \backslash
7970 /
7971
7972 \end_inset
7973
7974 -
7975 \series bold
7976 nolabelopt
7977 \series default
7978  
7979 \begin_inset LatexCommand \index{-\/-nolabelopt }
7980
7981 \end_inset
7982
7983 Will not optimize labels (makes the dumpfiles more readable).
7984
7985 \layout List
7986 \labelwidthstring 00.00.0000
7987
7988 \series bold
7989 -
7990 \begin_inset ERT
7991 status Collapsed
7992
7993 \layout Standard
7994
7995
7996 \backslash
7997 /
7998
7999 \end_inset
8000
8001 -no-xinit-opt
8002 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8003
8004 \end_inset
8005
8006
8007 \series default
8008  Will not memcpy initialized data from code space into xdata space.
8009  This saves a few bytes in code space if you don't have initialized data
8010 \begin_inset LatexCommand \index{Variable initialization}
8011
8012 \end_inset
8013
8014 .
8015
8016 \layout List
8017 \labelwidthstring 00.00.0000
8018
8019 \series bold
8020 -
8021 \begin_inset ERT
8022 status Collapsed
8023
8024 \layout Standard
8025
8026
8027 \backslash
8028 /
8029
8030 \end_inset
8031
8032 -nooverlay
8033 \begin_inset LatexCommand \index{-\/-nooverlay}
8034
8035 \end_inset
8036
8037
8038 \series default
8039   The compiler will not overlay parameters and local variables of any function,
8040  see section Parameters and local variables for more details.
8041
8042 \layout List
8043 \labelwidthstring 00.00.0000
8044
8045 \series bold
8046 -
8047 \begin_inset ERT
8048 status Collapsed
8049
8050 \layout Standard
8051
8052
8053 \backslash
8054 /
8055
8056 \end_inset
8057
8058 -no-peep
8059 \begin_inset LatexCommand \index{-\/-no-peep}
8060
8061 \end_inset
8062
8063
8064 \series default
8065  Disable peep-hole optimization with built-in rules.
8066
8067 \layout List
8068 \labelwidthstring 00.00.0000
8069
8070 \series bold
8071 -
8072 \begin_inset ERT
8073 status Collapsed
8074
8075 \layout Standard
8076
8077
8078 \backslash
8079 /
8080
8081 \end_inset
8082
8083 -peep-file
8084 \series default
8085
8086 \begin_inset LatexCommand \index{-\/-peep-file}
8087
8088 \end_inset
8089
8090 \SpecialChar ~
8091 <filename> This option can be used to use additional rules to be used by
8092  the peep hole optimizer.
8093  See section 
8094 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
8095
8096 \end_inset
8097
8098 \SpecialChar ~
8099 Peep Hole optimizations for details on how to write these rules.
8100
8101 \layout List
8102 \labelwidthstring 00.00.0000
8103
8104 \series bold
8105 -
8106 \begin_inset ERT
8107 status Collapsed
8108
8109 \layout Standard
8110
8111
8112 \backslash
8113 /
8114
8115 \end_inset
8116
8117 -peep-asm
8118 \begin_inset LatexCommand \index{-\/-peep-asm}
8119
8120 \end_inset
8121
8122
8123 \series default
8124  Pass the inline assembler code through the peep hole optimizer.
8125  This can cause unexpected changes to inline assembler code, please go through
8126  the peephole optimizer
8127 \begin_inset LatexCommand \index{Peephole optimizer}
8128
8129 \end_inset
8130
8131  rules defined in the source file tree '<target>/peeph.def' before using
8132  this option.
8133
8134 \layout List
8135 \labelwidthstring 00.00.0000
8136
8137 \series bold
8138 -
8139 \begin_inset ERT
8140 status Collapsed
8141
8142 \layout Standard
8143
8144
8145 \backslash
8146 /
8147
8148 \end_inset
8149
8150 -opt-code-speed
8151 \begin_inset LatexCommand \index{-\/-opt-code-speed}
8152
8153 \end_inset
8154
8155
8156 \series default
8157  The compiler will optimize code generation towards fast code, possibly
8158  at the expense of code size.
8159
8160 \layout List
8161 \labelwidthstring 00.00.0000
8162 \added_space_bottom bigskip 
8163
8164 \series bold
8165 -
8166 \begin_inset ERT
8167 status Collapsed
8168
8169 \layout Standard
8170
8171
8172 \backslash
8173 /
8174
8175 \end_inset
8176
8177 -opt-code-size
8178 \begin_inset LatexCommand \index{-\/-opt-code-size}
8179
8180 \end_inset
8181
8182
8183 \series default
8184  The compiler will optimize code generation towards compact code, possibly
8185  at the expense of code speed.
8186
8187
8188 \layout Subsection
8189 Other Options
8190 \begin_inset LatexCommand \index{Options other}
8191
8192 \end_inset
8193
8194
8195
8196 \layout List
8197 \labelwidthstring 00.00.0000
8198
8199 \series bold
8200 -c\SpecialChar ~
8201 -
8202 \begin_inset ERT
8203 status Collapsed
8204
8205 \layout Standard
8206
8207
8208 \backslash
8209 /
8210
8211 \end_inset
8212
8213 -compile-only
8214 \begin_inset LatexCommand \index{-\/-compile-only}
8215
8216 \end_inset
8217
8218
8219 \begin_inset LatexCommand \index{-c -\/-compile-only}
8220
8221 \end_inset
8222
8223
8224 \series default
8225  will compile and assemble the source, but will not call the linkage editor.
8226
8227 \layout List
8228 \labelwidthstring 00.00.0000
8229
8230 \series bold
8231 -
8232 \series default
8233
8234 \begin_inset ERT
8235 status Collapsed
8236
8237 \layout Standard
8238
8239
8240 \backslash
8241 /
8242
8243 \end_inset
8244
8245
8246 \series bold
8247 -c1mode
8248 \begin_inset LatexCommand \index{-\/-c1mode}
8249
8250 \end_inset
8251
8252
8253 \series default
8254  reads the preprocessed source from standard input and compiles it.
8255  The file name for the assembler output must be specified using the -o option.
8256
8257 \layout List
8258 \labelwidthstring 00.00.0000
8259
8260 \series bold
8261 -E
8262 \begin_inset LatexCommand \index{-E}
8263
8264 \end_inset
8265
8266
8267 \series default
8268  Run only the C preprocessor.
8269  Preprocess all the C source files specified and output the results to standard
8270  output.
8271
8272 \layout List
8273 \labelwidthstring 00.00.0000
8274
8275 \series bold
8276 -o\SpecialChar ~
8277 <path/file>
8278 \begin_inset LatexCommand \index{-o <path/file>}
8279
8280 \end_inset
8281
8282  
8283 \series default
8284 The output path resp.
8285  file where everything will be placed.
8286  If the parameter is a path, it must have a trailing slash (or backslash
8287  for the Windows binaries) to be recognized as a path.
8288  
8289
8290 \layout List
8291 \labelwidthstring 00.00.0000
8292
8293 \series bold
8294 -
8295 \begin_inset ERT
8296 status Collapsed
8297
8298 \layout Standard
8299
8300
8301 \backslash
8302 /
8303
8304 \end_inset
8305
8306 -stack-auto
8307 \begin_inset LatexCommand \index{-\/-stack-auto}
8308
8309 \end_inset
8310
8311
8312 \series default
8313 \size large
8314 \emph on
8315  
8316 \size default
8317 \emph default
8318 All functions in the source file will be compiled as 
8319 \emph on
8320 reentrant
8321 \emph default
8322
8323 \begin_inset LatexCommand \index{reentrant}
8324
8325 \end_inset
8326
8327 , i.e.
8328  the parameters and local variables will be allocated on the stack
8329 \begin_inset LatexCommand \index{stack}
8330
8331 \end_inset
8332
8333 .
8334  See section 
8335 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
8336
8337 \end_inset
8338
8339  Parameters and Local Variables for more details.
8340  If this option is used all source files in the project should be compiled
8341  with this option.
8342  It automatically implies --int-long-reent and --float-reent.
8343  
8344
8345 \layout List
8346 \labelwidthstring 00.00.0000
8347
8348 \series bold
8349 -
8350 \begin_inset ERT
8351 status Collapsed
8352
8353 \layout Standard
8354
8355
8356 \backslash
8357 /
8358
8359 \end_inset
8360
8361 -callee-saves
8362 \begin_inset LatexCommand \index{-\/-callee-saves}
8363
8364 \end_inset
8365
8366  function1[,function2][,function3]....
8367
8368 \series default
8369  The compiler by default uses a caller saves convention for register saving
8370  across function calls, however this can cause unnecessary register pushing
8371  & popping when calling small functions from larger functions.
8372  This option can be used to switch the register saving convention for the
8373  function names specified.
8374  The compiler will not save registers when calling these functions, no extra
8375  code will be generated at the entry & exit (function prologue
8376 \series bold
8377
8378 \begin_inset LatexCommand \index{function prologue}
8379
8380 \end_inset
8381
8382
8383 \series default
8384  & epilogue
8385 \series bold
8386
8387 \begin_inset LatexCommand \index{function epilogue}
8388
8389 \end_inset
8390
8391
8392 \series default
8393 ) for these functions to save & restore the registers used by these functions,
8394  this can SUBSTANTIALLY reduce code & improve run time performance of the
8395  generated code.
8396  In the future the compiler (with inter procedural analysis) will be able
8397  to determine the appropriate scheme to use for each function call.
8398  DO NOT use this option for built-in functions such as _mulint..., if this
8399  option is used for a library function the appropriate library function
8400  needs to be recompiled with the same option.
8401  If the project consists of multiple source files then all the source file
8402  should be compiled with the same -
8403 \begin_inset ERT
8404 status Collapsed
8405
8406 \layout Standard
8407
8408
8409 \backslash
8410 /
8411
8412 \end_inset
8413
8414 -callee-saves option string.
8415  Also see #pragma\SpecialChar ~
8416 callee_saves
8417 \begin_inset LatexCommand \index{\#pragma callee\_saves}
8418
8419 \end_inset
8420
8421 .
8422
8423 \layout List
8424 \labelwidthstring 00.00.0000
8425
8426 \series bold
8427 -
8428 \begin_inset ERT
8429 status Collapsed
8430
8431 \layout Standard
8432
8433
8434 \backslash
8435 /
8436
8437 \end_inset
8438
8439 -debug
8440 \begin_inset LatexCommand \index{-\/-debug}
8441
8442 \end_inset
8443
8444
8445 \bar under
8446  
8447 \series default
8448 \bar default
8449 When this option is used the compiler will generate debug information.
8450  The debug information collected in a file with .cdb extension can be used
8451  with the SDCDB.
8452  For more information see documentation for SDCDB.
8453  Another file with no extension contains debug information in AOMF or AOMF51
8454 \begin_inset LatexCommand \index{AOMF, AOMF51}
8455
8456 \end_inset
8457
8458  format which is commonly used by third party tools.
8459
8460 \layout List
8461 \labelwidthstring 00.00.0000
8462
8463 \series bold
8464 -S
8465 \begin_inset LatexCommand \index{-S}
8466
8467 \end_inset
8468
8469
8470 \size large
8471 \bar under
8472  
8473 \series default
8474 \size default
8475 \bar default
8476 Stop after the stage of compilation proper; do not assemble.
8477  The output is an assembler code file for the input file specified.
8478
8479 \layout List
8480 \labelwidthstring 00.00.0000
8481
8482 \series bold
8483 -
8484 \begin_inset ERT
8485 status Collapsed
8486
8487 \layout Standard
8488
8489
8490 \backslash
8491 /
8492
8493 \end_inset
8494
8495 -int-long-reent
8496 \begin_inset LatexCommand \index{-\/-int-long-reent}
8497
8498 \end_inset
8499
8500
8501 \series default
8502  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
8503  Note by default these libraries are compiled as non-reentrant.
8504  See section Installation for more details.
8505
8506 \layout List
8507 \labelwidthstring 00.00.0000
8508
8509 \series bold
8510 -
8511 \begin_inset ERT
8512 status Collapsed
8513
8514 \layout Standard
8515
8516
8517 \backslash
8518 /
8519
8520 \end_inset
8521
8522 -cyclomatic
8523 \begin_inset LatexCommand \index{-\/-cyclomatic}
8524
8525 \end_inset
8526
8527
8528 \bar under
8529  
8530 \series default
8531 \bar default
8532 This option will cause the compiler to generate an information message for
8533  each function in the source file.
8534  The message contains some 
8535 \emph on
8536 important
8537 \emph default
8538  information about the function.
8539  The number of edges and nodes the compiler detected in the control flow
8540  graph of the function, and most importantly the 
8541 \emph on
8542 cyclomatic complexity
8543 \begin_inset LatexCommand \index{Cyclomatic complexity}
8544
8545 \end_inset
8546
8547
8548 \emph default
8549  see section on Cyclomatic Complexity for more details.
8550
8551 \layout List
8552 \labelwidthstring 00.00.0000
8553
8554 \series bold
8555 -
8556 \begin_inset ERT
8557 status Collapsed
8558
8559 \layout Standard
8560
8561
8562 \backslash
8563 /
8564
8565 \end_inset
8566
8567 -float-reent
8568 \begin_inset LatexCommand \index{-\/-float-reent}
8569
8570 \end_inset
8571
8572
8573 \series default
8574  Floating point library is compiled as reentrant
8575 \begin_inset LatexCommand \index{reentrant}
8576
8577 \end_inset
8578
8579 .
8580  See section Installation for more details.
8581
8582 \layout List
8583 \labelwidthstring 00.00.0000
8584
8585 \series bold
8586 -
8587 \begin_inset ERT
8588 status Collapsed
8589
8590 \layout Standard
8591
8592
8593 \backslash
8594 /
8595
8596 \end_inset
8597
8598 -funsigned-char
8599 \begin_inset LatexCommand \index{-\/-funsigned-char}
8600
8601 \end_inset
8602
8603
8604 \series default
8605  The default signedness for every type is
8606 \family typewriter
8607  signed
8608 \family default
8609 . In some embedded enviornments the default signedness of
8610 \family typewriter
8611  char
8612 \family default
8613  is
8614 \family typewriter
8615  unsigned
8616 \family default
8617 . To set the signess for characters to unsigned, use the option --funsigned-char.
8618  If this option is set and no signedness keyword (unsigned/signed) is given, a char will be signed.
8619  All other types are unaffected.
8620
8621 \layout List
8622 \labelwidthstring 00.00.0000
8623
8624 \series bold
8625 -
8626 \begin_inset ERT
8627 status Collapsed
8628
8629 \layout Standard
8630
8631
8632 \backslash
8633 /
8634
8635 \end_inset
8636
8637 -main-return
8638 \begin_inset LatexCommand \index{-\/-main-return}
8639
8640 \end_inset
8641
8642
8643 \series default
8644  This option can be used if the code generated is called by a monitor program
8645  or if the main routine includes an endless loop.
8646  This option results in slightly smaller code and saves two bytes of stack
8647  space.
8648  The return from the 'main'
8649 \begin_inset LatexCommand \index{main return}
8650
8651 \end_inset
8652
8653  function will return to the function calling main.
8654  The default setting is to lock up i.e.
8655  generate a '
8656 \family typewriter
8657 sjmp .
8658 \family default
8659 '.
8660
8661 \layout List
8662 \labelwidthstring 00.00.0000
8663
8664 \series bold
8665 -
8666 \begin_inset ERT
8667 status Collapsed
8668
8669 \layout Standard
8670
8671
8672 \backslash
8673 /
8674
8675 \end_inset
8676
8677 -nostdinc
8678 \begin_inset LatexCommand \index{-\/-nostdinc}
8679
8680 \end_inset
8681
8682
8683 \series default
8684  This will prevent the compiler from passing on the default include path
8685  to the preprocessor.
8686
8687 \layout List
8688 \labelwidthstring 00.00.0000
8689
8690 \series bold
8691 -
8692 \begin_inset ERT
8693 status Collapsed
8694
8695 \layout Standard
8696
8697
8698 \backslash
8699 /
8700
8701 \end_inset
8702
8703 -nostdlib
8704 \begin_inset LatexCommand \index{-\/-nostdlib}
8705
8706 \end_inset
8707
8708
8709 \series default
8710  This will prevent the compiler from passing on the default library
8711 \begin_inset LatexCommand \index{Libraries}
8712
8713 \end_inset
8714
8715  path to the linker.
8716
8717 \layout List
8718 \labelwidthstring 00.00.0000
8719
8720 \series bold
8721 -
8722 \begin_inset ERT
8723 status Collapsed
8724
8725 \layout Standard
8726
8727
8728 \backslash
8729 /
8730
8731 \end_inset
8732
8733 -verbose
8734 \begin_inset LatexCommand \index{-\/-verbose}
8735
8736 \end_inset
8737
8738
8739 \series default
8740  Shows the various actions the compiler is performing.
8741
8742 \layout List
8743 \labelwidthstring 00.00.0000
8744
8745 \series bold
8746 -V
8747 \begin_inset LatexCommand \index{-V}
8748
8749 \end_inset
8750
8751
8752 \series default
8753  Shows the actual commands the compiler is executing.
8754
8755 \layout List
8756 \labelwidthstring 00.00.0000
8757
8758 \series bold
8759 -
8760 \begin_inset ERT
8761 status Collapsed
8762
8763 \layout Standard
8764
8765
8766 \backslash
8767 /
8768
8769 \end_inset
8770
8771 -no-c-code-in-asm
8772 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
8773
8774 \end_inset
8775
8776
8777 \series default
8778  Hides your ugly and inefficient c-code from the asm file, so you can always
8779  blame the compiler :)
8780
8781 \layout List
8782 \labelwidthstring 00.00.0000
8783
8784 \series bold
8785 -
8786 \begin_inset ERT
8787 status Collapsed
8788
8789 \layout Standard
8790
8791
8792 \backslash
8793 /
8794
8795 \end_inset
8796
8797 -no-peep-comments
8798 \begin_inset LatexCommand \index{-\/-no-peep-comments}
8799
8800 \end_inset
8801
8802
8803 \series default
8804  Will not include peep-hole comments in the generated files.
8805
8806 \layout List
8807 \labelwidthstring 00.00.0000
8808
8809 \series bold
8810 -
8811 \begin_inset ERT
8812 status Collapsed
8813
8814 \layout Standard
8815
8816
8817 \backslash
8818 /
8819
8820 \end_inset
8821
8822 -i-code-in-asm
8823 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
8824
8825 \end_inset
8826
8827
8828 \series default
8829  Include i-codes in the asm file.
8830  Sounds like noise but is most helpful for debugging the compiler itself.
8831
8832 \layout List
8833 \labelwidthstring 00.00.0000
8834
8835 \series bold
8836 -
8837 \begin_inset ERT
8838 status Collapsed
8839
8840 \layout Standard
8841
8842
8843 \backslash
8844 /
8845
8846 \end_inset
8847
8848 -less-pedantic
8849 \begin_inset LatexCommand \index{-\/-less-pedantic}
8850
8851 \end_inset
8852
8853
8854 \series default
8855  Disable some of the more pedantic warnings
8856 \begin_inset LatexCommand \index{Warnings}
8857
8858 \end_inset
8859
8860  (jwk burps: please be more specific here, please!).
8861
8862 \layout List
8863 \labelwidthstring 00.00.0000
8864
8865 \series bold
8866 -
8867 \begin_inset ERT
8868 status Collapsed
8869
8870 \layout Standard
8871
8872
8873 \backslash
8874 /
8875
8876 \end_inset
8877
8878 -disable-warning\SpecialChar ~
8879 <nnnn>
8880 \begin_inset LatexCommand \index{-\/-disable-warning}
8881
8882 \end_inset
8883
8884
8885 \series default
8886  Disable specific warning with number <nnnn>.
8887
8888 \layout List
8889 \labelwidthstring 00.00.0000
8890
8891 \series bold
8892 -
8893 \begin_inset ERT
8894 status Collapsed
8895
8896 \layout Standard
8897
8898
8899 \backslash
8900 /
8901
8902 \end_inset
8903
8904 -print-search-dirs
8905 \begin_inset LatexCommand \index{-\/-print-search-dirs}
8906
8907 \end_inset
8908
8909
8910 \series default
8911  Display the directories in the compiler's search path
8912
8913 \layout List
8914 \labelwidthstring 00.00.0000
8915
8916 \series bold
8917 -
8918 \begin_inset ERT
8919 status Collapsed
8920
8921 \layout Standard
8922
8923
8924 \backslash
8925 /
8926
8927 \end_inset
8928
8929 -vc
8930 \begin_inset LatexCommand \index{-\/-vc}
8931
8932 \end_inset
8933
8934
8935 \series default
8936  Display errors and warnings using MSVC style, so you can use SDCC with
8937  the visual studio IDE
8938 \begin_inset LatexCommand \index{IDE}
8939
8940 \end_inset
8941
8942 .
8943  With SDCC both offering a GCC-like (the default) and a MSVC-like
8944 \begin_inset LatexCommand \index{MSVC output style}
8945
8946 \end_inset
8947
8948  output style, integration into most programming editors should be straightforwa
8949 rd.
8950
8951 \layout List
8952 \labelwidthstring 00.00.0000
8953
8954 \series bold
8955 -
8956 \begin_inset ERT
8957 status Collapsed
8958
8959 \layout Standard
8960
8961
8962 \backslash
8963 /
8964
8965 \end_inset
8966
8967 -use-stdout
8968 \begin_inset LatexCommand \index{-\/-use-stdout}
8969
8970 \end_inset
8971
8972
8973 \series default
8974  Send errors and warnings to stdout instead of stderr.
8975
8976 \layout List
8977 \labelwidthstring 00.00.0000
8978
8979 \series bold
8980 -Wa\SpecialChar ~
8981 asmOption[,asmOption]
8982 \series default
8983
8984 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
8985
8986 \end_inset
8987
8988 ...
8989  Pass the asmOption to the assembler
8990 \begin_inset LatexCommand \index{Options assembler}
8991
8992 \end_inset
8993
8994
8995 \begin_inset LatexCommand \index{Assembler options}
8996
8997 \end_inset
8998
8999 .
9000  See file sdcc/as/doc/asxhtm.html for assembler options.cd
9001
9002 \layout List
9003 \labelwidthstring 00.00.0000
9004
9005 \series bold
9006 -
9007 \begin_inset ERT
9008 status Collapsed
9009
9010 \layout Standard
9011
9012
9013 \backslash
9014 /
9015
9016 \end_inset
9017
9018 -std-sdcc89
9019 \begin_inset LatexCommand \index{-\/-std-sdcc89}
9020
9021 \end_inset
9022
9023
9024 \series default
9025  Generally follow the C89 standard, but allow SDCC features that conflict
9026  with the standard (default).
9027
9028 \layout List
9029 \labelwidthstring 00.00.0000
9030
9031 \series bold
9032 -
9033 \begin_inset ERT
9034 status Collapsed
9035
9036 \layout Standard
9037
9038
9039 \backslash
9040 /
9041
9042 \end_inset
9043
9044 -std-c89
9045 \begin_inset LatexCommand \index{-\/-std-c89}
9046
9047 \end_inset
9048
9049
9050 \series default
9051  Follow the C89 standard and disable SDCC features that conflict with the
9052  standard.
9053
9054 \layout List
9055 \labelwidthstring 00.00.0000
9056
9057 \series bold
9058 -
9059 \begin_inset ERT
9060 status Collapsed
9061
9062 \layout Standard
9063
9064
9065 \backslash
9066 /
9067
9068 \end_inset
9069
9070 -std-sdcc99
9071 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9072
9073 \end_inset
9074
9075
9076 \series default
9077  Generally follow the C99 standard, but allow SDCC features that conflict
9078  with the standard (incomplete support).
9079
9080 \layout List
9081 \labelwidthstring 00.00.0000
9082
9083 \series bold
9084 -
9085 \begin_inset ERT
9086 status Collapsed
9087
9088 \layout Standard
9089
9090
9091 \backslash
9092 /
9093
9094 \end_inset
9095
9096 -std-c99
9097 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9098
9099 \end_inset
9100
9101
9102 \series default
9103  Follow the C99 standard and disable SDCC features that conflict with the
9104  standard (incomplete support).
9105
9106 \layout List
9107 \labelwidthstring 00.00.0000
9108
9109 \series bold
9110 -
9111 \begin_inset ERT
9112 status Collapsed
9113
9114 \layout Standard
9115
9116
9117 \backslash
9118 /
9119
9120 \end_inset
9121
9122 -codeseg
9123 \series default
9124
9125 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
9126
9127 \end_inset
9128
9129 \SpecialChar ~
9130 <Name> The name to be used for the code
9131 \begin_inset LatexCommand \index{code}
9132
9133 \end_inset
9134
9135  segment, default CSEG.
9136  This is useful if you need to tell the compiler to put the code in a special
9137  segment so you can later on tell the linker to put this segment in a special
9138  place in memory.
9139  Can be used for instance when using bank switching to put the code in a
9140  bank.
9141
9142 \layout List
9143 \labelwidthstring 00.00.0000
9144
9145 \series bold
9146 -
9147 \begin_inset ERT
9148 status Collapsed
9149
9150 \layout Standard
9151
9152
9153 \backslash
9154 /
9155
9156 \end_inset
9157
9158 -constseg
9159 \series default
9160
9161 \begin_inset LatexCommand \index{-\/-constseg <Value>}
9162
9163 \end_inset
9164
9165 \SpecialChar ~
9166 <Name> The name to be used for the const
9167 \begin_inset LatexCommand \index{code}
9168
9169 \end_inset
9170
9171  segment, default CONST.
9172  This is useful if you need to tell the compiler to put the const data in
9173  a special segment so you can later on tell the linker to put this segment
9174  in a special place in memory.
9175  Can be used for instance when using bank switching to put the const data
9176  in a bank.
9177
9178 \layout List
9179 \labelwidthstring 00.00.0000
9180
9181 \series bold
9182 -
9183 \begin_inset ERT
9184 status Collapsed
9185
9186 \layout Standard
9187
9188
9189 \backslash
9190 /
9191
9192 \end_inset
9193
9194 -fdollars-in-identifiers
9195 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
9196
9197 \end_inset
9198
9199
9200 \series default
9201  Permit '$' as an identifier character
9202
9203 \layout List
9204 \labelwidthstring 00.00.0000
9205 \added_space_bottom bigskip 
9206
9207 \series bold
9208 more-pedantic
9209 \series default
9210  Actually this is 
9211 \series bold
9212 \emph on
9213 not
9214 \series default
9215 \emph default
9216  a SDCC compiler option but if you want 
9217 \emph on
9218 more
9219 \emph default
9220  warnings you can use a separate tool dedicated to syntax checking like
9221  splint
9222 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
9223
9224 \end_inset
9225
9226
9227 \begin_inset LatexCommand \index{lint (syntax checking tool)}
9228
9229 \end_inset
9230
9231  
9232 \begin_inset LatexCommand \url{http://www.splint.org}
9233
9234 \end_inset
9235
9236 .
9237  To make your source files parseable by splint you will have to include
9238  
9239 \family sans
9240 lint.h
9241 \family default
9242
9243 \begin_inset LatexCommand \index{splint (syntax checking tool)}
9244
9245 \end_inset
9246
9247  in your source file and add brackets around extended keywords (like 
9248 \family sans
9249
9250 \begin_inset Quotes sld
9251 \end_inset
9252
9253 __at\SpecialChar ~
9254
9255 \series bold
9256 (
9257 \series default
9258 0xab
9259 \series bold
9260 )
9261 \series default
9262
9263 \begin_inset Quotes srd
9264 \end_inset
9265
9266
9267 \family default
9268  and 
9269 \family sans
9270
9271 \begin_inset Quotes sld
9272 \end_inset
9273
9274 __interrupt\SpecialChar ~
9275 (2)
9276 \begin_inset Quotes srd
9277 \end_inset
9278
9279
9280 \family default
9281 ).
9282  
9283 \newline
9284 Splint has an excellent on line manual at 
9285 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
9286
9287 \end_inset
9288
9289  and it's capabilities go beyond pure syntax checking.
9290  You'll need to tell splint the location of SDCC's include files so a typical
9291  command line could look like this: 
9292 \newline
9293
9294 \family sans
9295 splint\SpecialChar ~
9296 -I\SpecialChar ~
9297 /usr/local/share/sdcc/include/mcs51/\SpecialChar ~
9298 \SpecialChar ~
9299 myprogram.c
9300
9301
9302 \layout Subsection
9303 Intermediate Dump Options
9304 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
9305
9306 \end_inset
9307
9308
9309 \begin_inset LatexCommand \index{Options intermediate dump}
9310
9311 \end_inset
9312
9313
9314 \begin_inset LatexCommand \index{Intermediate dump options}
9315
9316 \end_inset
9317
9318
9319
9320 \layout Standard
9321 The following options are provided for the purpose of retargetting and debugging
9322  the compiler.
9323  They provide a means to dump the intermediate code (iCode
9324 \begin_inset LatexCommand \index{iCode}
9325
9326 \end_inset
9327
9328 ) generated by the compiler in human readable form at various stages of
9329  the compilation process.
9330  More on iCodes see chapter 
9331 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
9332
9333 \end_inset
9334
9335  
9336 \begin_inset Quotes srd
9337 \end_inset
9338
9339 The anatomy of the compiler
9340 \begin_inset Quotes srd
9341 \end_inset
9342
9343 .
9344
9345 \layout List
9346 \labelwidthstring 00.00.0000
9347
9348 \series bold
9349 -
9350 \begin_inset ERT
9351 status Collapsed
9352
9353 \layout Standard
9354
9355
9356 \backslash
9357 /
9358
9359 \end_inset
9360
9361 -dumpraw
9362 \begin_inset LatexCommand \index{-\/-dumpraw}
9363
9364 \end_inset
9365
9366
9367 \series default
9368  This option will cause the compiler to dump the intermediate code into
9369  a file of named 
9370 \emph on
9371 <source filename>.dumpraw
9372 \emph default
9373  just after the intermediate code has been generated for a function, i.e.
9374  before any optimizations are done.
9375  The basic blocks
9376 \begin_inset LatexCommand \index{Basic blocks}
9377
9378 \end_inset
9379
9380  at this stage ordered in the depth first number, so they may not be in
9381  sequence of execution.
9382
9383 \layout List
9384 \labelwidthstring 00.00.0000
9385
9386 \series bold
9387 -
9388 \begin_inset ERT
9389 status Collapsed
9390
9391 \layout Standard
9392
9393
9394 \backslash
9395 /
9396
9397 \end_inset
9398
9399 -dumpgcse
9400 \begin_inset LatexCommand \index{-\/-dumpgcse}
9401
9402 \end_inset
9403
9404
9405 \series default
9406  Will create a dump of iCode's, after global subexpression elimination
9407 \begin_inset LatexCommand \index{Global subexpression elimination}
9408
9409 \end_inset
9410
9411 , into a file named 
9412 \emph on
9413 <source filename>.dumpgcse.
9414
9415 \layout List
9416 \labelwidthstring 00.00.0000
9417
9418 \series bold
9419 -
9420 \begin_inset ERT
9421 status Collapsed
9422
9423 \layout Standard
9424
9425
9426 \backslash
9427 /
9428
9429 \end_inset
9430
9431 -dumpdeadcode
9432 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
9433
9434 \end_inset
9435
9436
9437 \series default
9438  Will create a dump of iCode's, after deadcode elimination
9439 \begin_inset LatexCommand \index{Dead-code elimination}
9440
9441 \end_inset
9442
9443 , into a file named 
9444 \emph on
9445 <source filename>.dumpdeadcode.
9446
9447 \layout List
9448 \labelwidthstring 00.00.0000
9449
9450 \series bold
9451 -
9452 \begin_inset ERT
9453 status Collapsed
9454
9455 \layout Standard
9456
9457
9458 \backslash
9459 /
9460
9461 \end_inset
9462
9463 -dumploop
9464 \begin_inset LatexCommand \index{-\/-dumploop}
9465
9466 \end_inset
9467
9468
9469 \series default
9470 \size large
9471  
9472 \size default
9473 Will create a dump of iCode's, after loop optimizations
9474 \begin_inset LatexCommand \index{Loop optimization}
9475
9476 \end_inset
9477
9478 , into a file named 
9479 \emph on
9480 <source filename>.dumploop.
9481
9482 \layout List
9483 \labelwidthstring 00.00.0000
9484
9485 \series bold
9486 -
9487 \begin_inset ERT
9488 status Collapsed
9489
9490 \layout Standard
9491
9492
9493 \backslash
9494 /
9495
9496 \end_inset
9497
9498 -dumprange
9499 \begin_inset LatexCommand \index{-\/-dumprange}
9500
9501 \end_inset
9502
9503
9504 \series default
9505 \size large
9506  
9507 \size default
9508 Will create a dump of iCode's, after live range analysis
9509 \begin_inset LatexCommand \index{Live range analysis}
9510
9511 \end_inset
9512
9513 , into a file named 
9514 \emph on
9515 <source filename>.dumprange.
9516
9517 \layout List
9518 \labelwidthstring 00.00.0000
9519
9520 \series bold
9521 -
9522 \begin_inset ERT
9523 status Collapsed
9524
9525 \layout Standard
9526
9527
9528 \backslash
9529 /
9530
9531 \end_inset
9532
9533 -dumlrange
9534 \begin_inset LatexCommand \index{-\/-dumlrange}
9535
9536 \end_inset
9537
9538
9539 \series default
9540  Will dump the life ranges
9541 \begin_inset LatexCommand \index{Live range analysis}
9542
9543 \end_inset
9544
9545  for all symbols.
9546
9547 \layout List
9548 \labelwidthstring 00.00.0000
9549
9550 \series bold
9551 -
9552 \begin_inset ERT
9553 status Collapsed
9554
9555 \layout Standard
9556
9557
9558 \backslash
9559 /
9560
9561 \end_inset
9562
9563 -dumpregassign
9564 \begin_inset LatexCommand \index{-\/-dumpregassign}
9565
9566 \end_inset
9567
9568
9569 \bar under
9570  
9571 \series default
9572 \bar default
9573 Will create a dump of iCode's, after register assignment
9574 \begin_inset LatexCommand \index{Register assignment}
9575
9576 \end_inset
9577
9578 , into a file named 
9579 \emph on
9580 <source filename>.dumprassgn.
9581
9582 \layout List
9583 \labelwidthstring 00.00.0000
9584
9585 \series bold
9586 -
9587 \begin_inset ERT
9588 status Collapsed
9589
9590 \layout Standard
9591
9592
9593 \backslash
9594 /
9595
9596 \end_inset
9597
9598 -dumplrange
9599 \begin_inset LatexCommand \index{-\/-dumplrange}
9600
9601 \end_inset
9602
9603
9604 \series default
9605  Will create a dump of the live ranges of iTemp's
9606
9607 \layout List
9608 \labelwidthstring 00.00.0000
9609 \added_space_bottom bigskip 
9610
9611 \series bold
9612 -
9613 \begin_inset ERT
9614 status Collapsed
9615
9616 \layout Standard
9617
9618
9619 \backslash
9620 /
9621
9622 \end_inset
9623
9624 -dumpall
9625 \begin_inset LatexCommand \index{-\/-dumpall}
9626
9627 \end_inset
9628
9629
9630 \size large
9631 \bar under
9632  
9633 \series default
9634 \size default
9635 \bar default
9636 Will cause all the above mentioned dumps to be created.
9637
9638
9639 \layout Subsection
9640 Redirecting output on Windows Shells
9641
9642 \layout Standard
9643 \added_space_bottom bigskip 
9644 By default SDCC writes it's error messages to 
9645 \begin_inset Quotes sld
9646 \end_inset
9647
9648 standard error
9649 \begin_inset Quotes srd
9650 \end_inset
9651
9652 .
9653  To force all messages to 
9654 \begin_inset Quotes sld
9655 \end_inset
9656
9657 standard output
9658 \begin_inset Quotes srd
9659 \end_inset
9660
9661  use 
9662 \series bold
9663 -
9664 \series default
9665 \emph on
9666
9667 \begin_inset ERT
9668 status Collapsed
9669
9670 \layout Standard
9671
9672
9673 \backslash
9674 /
9675
9676 \end_inset
9677
9678
9679 \series bold
9680 \emph default
9681 -
9682 \series default
9683 use-stdout
9684 \begin_inset LatexCommand \index{-\/-use-stdout}
9685
9686 \end_inset
9687
9688 .
9689  Additionally, if you happen to have visual studio installed in your windows
9690  machine, you can use it to compile your sources using a custom build and
9691  the SDCC -
9692 \emph on
9693
9694 \begin_inset ERT
9695 status Collapsed
9696
9697 \layout Standard
9698
9699
9700 \backslash
9701 /
9702
9703 \end_inset
9704
9705
9706 \emph default
9707 -vc
9708 \begin_inset LatexCommand \index{-\/-vc}
9709
9710 \end_inset
9711
9712  option.
9713  Something like this should work:
9714 \newline
9715
9716 \newline
9717
9718 \series bold
9719 c:
9720 \backslash
9721 sdcc
9722 \backslash
9723 bin
9724 \backslash
9725 sdcc.exe -
9726 \series default
9727 \emph on
9728
9729 \begin_inset ERT
9730 status Collapsed
9731
9732 \layout Standard
9733
9734
9735 \backslash
9736 /
9737
9738 \end_inset
9739
9740
9741 \series bold
9742 \emph default
9743 -vc -
9744 \series default
9745 \emph on
9746
9747 \begin_inset ERT
9748 status Collapsed
9749
9750 \layout Standard
9751
9752
9753 \backslash
9754 /
9755
9756 \end_inset
9757
9758
9759 \series bold
9760 \emph default
9761 -model-large -c $(InputPath)
9762 \series default
9763
9764
9765
9766
9767 \layout Section
9768 Environment variables
9769 \begin_inset LatexCommand \index{Environment variables}
9770
9771 \end_inset
9772
9773
9774
9775 \layout Standard
9776 SDCC recognizes the following environment variables:
9777
9778 \layout List
9779 \labelwidthstring 00.00.0000
9780
9781 \series bold
9782 SDCC_LEAVE_SIGNALS
9783 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
9784
9785 \end_inset
9786
9787
9788 \series default
9789  SDCC installs a signal handler
9790 \begin_inset LatexCommand \index{signal handler}
9791
9792 \end_inset
9793
9794  to be able to delete temporary files after an user break (^C) or an exception.
9795  If this environment variable is set, SDCC won't install the signal handler
9796  in order to be able to debug SDCC.
9797
9798 \layout List
9799 \labelwidthstring 00.00.0000
9800
9801 \series bold
9802 TMP,\SpecialChar ~
9803 TEMP,\SpecialChar ~
9804 TMPDIR
9805 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
9806
9807 \end_inset
9808
9809
9810 \series default
9811  Path, where temporary files will be created.
9812  The order of the variables is the search order.
9813  In a standard *nix environment these variables are not set, and there's
9814  no need to set them.
9815  On Windows it's recommended to set one of them.
9816
9817 \layout List
9818 \labelwidthstring 00.00.0000
9819
9820 \series bold
9821 SDCC_HOME
9822 \begin_inset LatexCommand \index{SDCC\_HOME}
9823
9824 \end_inset
9825
9826
9827 \series default
9828  Path, see section 
9829 \begin_inset LatexCommand \ref{sub:Install-paths}
9830
9831 \end_inset
9832
9833 \SpecialChar ~
9834
9835 \begin_inset Quotes sld
9836 \end_inset
9837
9838  Install Paths
9839 \begin_inset Quotes srd
9840 \end_inset
9841
9842 .
9843
9844 \layout List
9845 \labelwidthstring 00.00.0000
9846
9847 \series bold
9848 SDCC_INCLUDE
9849 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
9850
9851 \end_inset
9852
9853
9854 \series default
9855  Path, see section 
9856 \begin_inset LatexCommand \ref{sub:Search-Paths}
9857
9858 \end_inset
9859
9860 \SpecialChar ~
9861
9862 \begin_inset Quotes sld
9863 \end_inset
9864
9865 Search Paths
9866 \begin_inset Quotes srd
9867 \end_inset
9868
9869 .
9870
9871 \layout List
9872 \labelwidthstring 00.00.0000
9873
9874 \series bold
9875 SDCC_LIB
9876 \begin_inset LatexCommand \index{SDCC\_LIB}
9877
9878 \end_inset
9879
9880
9881 \series default
9882  Path, see section 
9883 \begin_inset LatexCommand \ref{sub:Search-Paths}
9884
9885 \end_inset
9886
9887 \SpecialChar ~
9888
9889 \begin_inset Quotes sld
9890 \end_inset
9891
9892 Search Paths
9893 \begin_inset Quotes srd
9894 \end_inset
9895
9896 ..
9897
9898 \layout Standard
9899 \added_space_bottom bigskip 
9900 There are some more environment variables recognized by SDCC, but these
9901  are solely used for debugging purposes.
9902  They can change or disappear very quickly, and will never be documented.
9903
9904
9905
9906 \layout Section
9907 Storage Class Language Extensions
9908
9909 \layout Subsection
9910 MCS51/DS390 Storage Class
9911 \begin_inset LatexCommand \index{Storage class}
9912
9913 \end_inset
9914
9915  Language Extensions
9916
9917 \layout Standard
9918 In addition to the ANSI storage classes SDCC allows the following MCS51
9919  specific storage classes:
9920
9921 \layout Subsubsection
9922 data
9923 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9924
9925 \end_inset
9926
9927
9928 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9929
9930 \end_inset
9931
9932  / near
9933 \begin_inset LatexCommand \index{near (storage class)}
9934
9935 \end_inset
9936
9937
9938 \begin_inset LatexCommand \index{\_\_near (storage class)}
9939
9940 \end_inset
9941
9942
9943
9944 \layout Standard
9945 This is the 
9946 \series bold
9947 default
9948 \series default
9949  storage class for the Small Memory model (
9950 \emph on
9951 data
9952 \emph default
9953  and 
9954 \emph on
9955 near
9956 \emph default
9957  or the more ANSI-C compliant forms 
9958 \emph on
9959 __data
9960 \emph default
9961  and 
9962 \emph on
9963 __near
9964 \emph default
9965  can be used synonymously).
9966  Variables declared with this storage class will be allocated in the directly
9967  addressable portion of the internal RAM of a 8051, e.g.:
9968
9969 \layout Verse
9970
9971 \family typewriter
9972 __data unsigned char test_data;
9973
9974 \layout Standard
9975 Writing 0x01 to this variable generates the assembly code:
9976
9977 \layout Verse
9978
9979 \family typewriter
9980 75*00 01\SpecialChar ~
9981 \SpecialChar ~
9982 \SpecialChar ~
9983 mov\SpecialChar ~
9984 \SpecialChar ~
9985 _test_data,#0x01
9986
9987 \layout Subsubsection
9988 xdata
9989 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9990
9991 \end_inset
9992
9993
9994 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9995
9996 \end_inset
9997
9998  / far
9999 \begin_inset LatexCommand \index{far (storage class)}
10000
10001 \end_inset
10002
10003
10004 \begin_inset LatexCommand \index{\_\_far (storage class)}
10005
10006 \end_inset
10007
10008
10009
10010 \layout Standard
10011 Variables declared with this storage class will be placed in the external
10012  RAM.
10013  This is the 
10014 \series bold
10015 default
10016 \series default
10017  storage class for the Large Memory model, e.g.:
10018
10019 \layout Verse
10020
10021 \family typewriter
10022 __xdata unsigned char test_xdata;
10023
10024 \layout Standard
10025 Writing 0x01 to this variable generates the assembly code:
10026
10027 \layout Verse
10028
10029 \family typewriter
10030 90s00r00\SpecialChar ~
10031 \SpecialChar ~
10032 \SpecialChar ~
10033 mov\SpecialChar ~
10034 \SpecialChar ~
10035 dptr,#_test_xdata 
10036 \newline
10037 74\SpecialChar ~
10038 01\SpecialChar ~
10039 \SpecialChar ~
10040 \SpecialChar ~
10041 \SpecialChar ~
10042 \SpecialChar ~
10043 \SpecialChar ~
10044 mov\SpecialChar ~
10045 \SpecialChar ~
10046 a,#0x01 
10047 \newline
10048 F0\SpecialChar ~
10049 \SpecialChar ~
10050 \SpecialChar ~
10051 \SpecialChar ~
10052 \SpecialChar ~
10053 \SpecialChar ~
10054 \SpecialChar ~
10055 \SpecialChar ~
10056 \SpecialChar ~
10057 movx\SpecialChar ~
10058 @dptr,a 
10059
10060 \layout Subsubsection
10061 idata
10062 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10063
10064 \end_inset
10065
10066
10067 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10068
10069 \end_inset
10070
10071
10072
10073 \layout Standard
10074 Variables declared with this storage class will be allocated into the indirectly
10075  addressable portion of the internal ram of a 8051, e.g.:
10076
10077 \layout Verse
10078
10079 \family typewriter
10080 __idata unsigned char test_idata;
10081
10082 \layout Standard
10083 Writing 0x01 to this variable generates the assembly code:
10084
10085 \layout Verse
10086
10087 \family typewriter
10088 78r00\SpecialChar ~
10089 \SpecialChar ~
10090 \SpecialChar ~
10091 \SpecialChar ~
10092 \SpecialChar ~
10093 \SpecialChar ~
10094 \SpecialChar ~
10095 mov\SpecialChar ~
10096 \SpecialChar ~
10097 r0,#_test_idata
10098 \newline
10099 76\SpecialChar ~
10100 01\SpecialChar ~
10101 \SpecialChar ~
10102 \SpecialChar ~
10103 \SpecialChar ~
10104 \SpecialChar ~
10105 \SpecialChar ~
10106 \SpecialChar ~
10107 mov\SpecialChar ~
10108 \SpecialChar ~
10109 @r0,#0x01
10110
10111 \layout Standard
10112 Please note, the first 128 byte of idata physically access the same RAM
10113  as the data memory.
10114  The original 8051 had 128 byte idata memory, nowadays most devices have
10115  256 byte idata memory.
10116  The stack
10117 \begin_inset LatexCommand \index{stack}
10118
10119 \end_inset
10120
10121  is located in idata memory.
10122
10123 \layout Subsubsection
10124 pdata
10125 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
10126
10127 \end_inset
10128
10129
10130 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
10131
10132 \end_inset
10133
10134
10135
10136 \layout Standard
10137 Paged xdata access is just as straightforward as using the other addressing
10138  modes of a 8051.
10139  It is typically located at the start of xdata and has a maximum size of
10140  256 bytes.
10141  The following example writes 0x01 to the pdata variable.
10142  Please note, pdata access physically accesses xdata memory.
10143  The high byte of the address is determined by port P2 
10144 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
10145
10146 \end_inset
10147
10148 (or in case of some 8051 variants by a separate Special Function Register,
10149  see section 
10150 \begin_inset LatexCommand \ref{sub:MCS51-variants}
10151
10152 \end_inset
10153
10154 ).
10155  This is the 
10156 \series bold
10157 default
10158 \series default
10159  storage class for the Medium Memory model, e.g.:
10160
10161 \layout Verse
10162
10163 \family typewriter
10164 __pdata unsigned char test_pdata;
10165
10166 \layout Standard
10167 Writing 0x01 to this variable generates the assembly code:
10168
10169 \layout Verse
10170
10171 \family typewriter
10172 78r00\SpecialChar ~
10173 \SpecialChar ~
10174 \SpecialChar ~
10175 \SpecialChar ~
10176 \SpecialChar ~
10177 \SpecialChar ~
10178 mov r0,#_test_pdata
10179 \newline
10180 74 01\SpecialChar ~
10181 \SpecialChar ~
10182 \SpecialChar ~
10183 \SpecialChar ~
10184 \SpecialChar ~
10185 \SpecialChar ~
10186 mov a,#0x01 
10187 \newline
10188 F2\SpecialChar ~
10189 \SpecialChar ~
10190 \SpecialChar ~
10191 \SpecialChar ~
10192 \SpecialChar ~
10193 \SpecialChar ~
10194 \SpecialChar ~
10195 \SpecialChar ~
10196 \SpecialChar ~
10197 movx @r0,a
10198
10199 \layout Standard
10200 If the -
10201 \begin_inset ERT
10202 status Collapsed
10203
10204 \layout Standard
10205
10206
10207 \backslash
10208 /
10209
10210 \end_inset
10211
10212 -xstack
10213 \begin_inset LatexCommand \index{-\/-xstack}
10214
10215 \end_inset
10216
10217  option is used the pdata memory area is followed by the xstack memory area
10218  and the sum of their sizes is limited to 256 bytes.
10219
10220 \layout Subsubsection
10221 code
10222 \begin_inset LatexCommand \index{code}
10223
10224 \end_inset
10225
10226
10227 \begin_inset LatexCommand \index{\_\_code}
10228
10229 \end_inset
10230
10231
10232
10233 \layout Standard
10234 'Variables' declared with this storage class will be placed in the code
10235  memory:
10236
10237 \layout Verse
10238
10239 \family typewriter
10240 __code unsigned char test_code;
10241
10242 \layout Standard
10243 Read access to this variable generates the assembly code:
10244
10245 \layout Verse
10246
10247 \family typewriter
10248 90s00r6F\SpecialChar ~
10249 \SpecialChar ~
10250 \SpecialChar ~
10251 mov dptr,#_test_code
10252 \newline
10253 E4\SpecialChar ~
10254 \SpecialChar ~
10255 \SpecialChar ~
10256 \SpecialChar ~
10257 \SpecialChar ~
10258 \SpecialChar ~
10259 \SpecialChar ~
10260 \SpecialChar ~
10261 \SpecialChar ~
10262 clr a
10263 \newline
10264 93\SpecialChar ~
10265 \SpecialChar ~
10266 \SpecialChar ~
10267 \SpecialChar ~
10268 \SpecialChar ~
10269 \SpecialChar ~
10270 \SpecialChar ~
10271 \SpecialChar ~
10272 \SpecialChar ~
10273 movc a,@a+dptr 
10274
10275 \layout Standard
10276
10277 \family typewriter
10278 char
10279 \family default
10280  indexed arrays of characters in code memory can be accessed efficiently:
10281
10282 \layout Verse
10283
10284 \family typewriter
10285 __code char test_array[] = {'c','h','e','a','p'}; 
10286
10287 \layout Standard
10288 Read access to this array using an 8-bit unsigned index generates the assembly
10289  code:
10290
10291 \layout Verse
10292
10293 \family typewriter
10294 E5*00\SpecialChar ~
10295 \SpecialChar ~
10296 \SpecialChar ~
10297 \SpecialChar ~
10298 \SpecialChar ~
10299 \SpecialChar ~
10300 mov a,_index 
10301
10302 \layout Verse
10303
10304 \family typewriter
10305 90s00r41\SpecialChar ~
10306 \SpecialChar ~
10307 \SpecialChar ~
10308 mov dptr,#_test_array
10309
10310 \layout Verse
10311
10312 \family typewriter
10313 93\SpecialChar ~
10314 \SpecialChar ~
10315 \SpecialChar ~
10316 \SpecialChar ~
10317 \SpecialChar ~
10318 \SpecialChar ~
10319 \SpecialChar ~
10320 \SpecialChar ~
10321 \SpecialChar ~
10322 movc a,@a+dptr 
10323
10324 \layout Subsubsection
10325 bit
10326 \begin_inset LatexCommand \index{bit}
10327
10328 \end_inset
10329
10330
10331 \begin_inset LatexCommand \index{\_\_bit}
10332
10333 \end_inset
10334
10335
10336
10337 \layout Standard
10338 This is a data-type and a storage class specifier.
10339  When a variable is declared as a bit, it is allocated into the bit addressable
10340  memory of 8051, e.g.:
10341
10342 \layout Verse
10343
10344 \family typewriter
10345 __bit test_bit;
10346
10347 \layout Standard
10348 Writing 1 to this variable generates the assembly code:
10349
10350 \layout Verse
10351
10352 \family typewriter
10353 D2*00\SpecialChar ~
10354 \SpecialChar ~
10355 \SpecialChar ~
10356 \SpecialChar ~
10357 \SpecialChar ~
10358 \SpecialChar ~
10359 \SpecialChar ~
10360 setb\SpecialChar ~
10361 _test_bit
10362
10363 \layout Standard
10364 The bit addressable memory consists of 128 bits which are located from 0x20
10365  to 0x2f in data memory.
10366  
10367 \newline
10368 Apart from this 8051 specific storage class most architectures support
10369  ANSI-C bitfields
10370 \begin_inset LatexCommand \index{bitfields}
10371
10372 \end_inset
10373
10374
10375 \begin_inset Foot
10376 collapsed false
10377
10378 \layout Standard
10379 Not really meant as examples, but nevertheless showing what bitfields are
10380  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
10381
10382 \end_inset
10383
10384 .
10385  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
10386  signed modifier are implemented as unsigned.
10387
10388 \layout Subsubsection
10389 sfr
10390 \begin_inset LatexCommand \index{sfr}
10391
10392 \end_inset
10393
10394
10395 \begin_inset LatexCommand \index{\_\_sfr}
10396
10397 \end_inset
10398
10399  / sfr16
10400 \begin_inset LatexCommand \index{sfr16}
10401
10402 \end_inset
10403
10404
10405 \begin_inset LatexCommand \index{\_\_sfr16}
10406
10407 \end_inset
10408
10409  / sfr32
10410 \begin_inset LatexCommand \index{sfr32}
10411
10412 \end_inset
10413
10414
10415 \begin_inset LatexCommand \index{\_\_sfr32}
10416
10417 \end_inset
10418
10419  / sbit
10420 \begin_inset LatexCommand \index{\_\_sbit}
10421
10422 \end_inset
10423
10424
10425 \begin_inset LatexCommand \index{sbit}
10426
10427 \end_inset
10428
10429
10430
10431 \layout Standard
10432 Like the bit keyword, 
10433 \emph on
10434 sfr / sfr16 / sfr32 / sbit 
10435 \emph default
10436 signify both a data-type and storage class, they are used to describe the
10437  
10438 \emph on
10439 s
10440 \emph default
10441 pecial 
10442 \emph on
10443 f
10444 \emph default
10445 unction 
10446 \emph on
10447 r
10448 \emph default
10449 egisters and 
10450 \emph on
10451 s
10452 \emph default
10453 pecial 
10454 \emph on
10455 bit
10456 \emph default
10457  variables of a 8051, eg:
10458
10459 \layout Verse
10460
10461 \family typewriter
10462 __sfr __at
10463 \begin_inset LatexCommand \index{at}
10464
10465 \end_inset
10466
10467
10468 \begin_inset LatexCommand \index{\_\_at}
10469
10470 \end_inset
10471
10472  (0x80) P0;\SpecialChar ~
10473  /* special function register P0 at location 0x80 */
10474 \newline
10475
10476 \newline
10477 /* 16 bit
10478  special function register combination for timer 0
10479 \newline
10480 \SpecialChar ~
10481 \SpecialChar ~
10482  with the high byte at
10483  location 0x8C and the low byte at location 0x8A */
10484 \newline
10485 __sfr16 __at (0x8C8A)
10486  TMR0;
10487 \newline
10488
10489 \newline
10490 __sbit __at
10491 \begin_inset LatexCommand \index{at}
10492
10493 \end_inset
10494
10495
10496 \begin_inset LatexCommand \index{\_\_at}
10497
10498 \end_inset
10499
10500  (0xd7) CY;\SpecialChar ~
10501  /* CY (Carry Flag
10502 \begin_inset LatexCommand \index{Flags}
10503
10504 \end_inset
10505
10506
10507 \begin_inset LatexCommand \index{Carry flag}
10508
10509 \end_inset
10510
10511 ) */
10512
10513 \layout Standard
10514 Special function registers which are located on an address dividable by
10515  8 are bit-addressable, an
10516 \emph on
10517  sbit
10518 \emph default
10519  addresses a specific bit within these sfr.
10520 \newline
10521 16 Bit and 32 bit special function
10522  register combinations which require a certain access order are better not
10523  declared using 
10524 \emph on
10525 sfr16
10526 \emph default
10527  or 
10528 \emph on
10529 sfr32.
10530
10531 \emph default
10532  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
10533  this is not guaranteed.
10534 \newline
10535
10536
10537 \layout Standard
10538 Please note, if you use a header file which was written for another compiler
10539  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
10540  likely be 
10541 \emph on
10542 not 
10543 \emph default
10544 compatible.
10545  Specifically the syntax 
10546 \family typewriter
10547 \SpecialChar ~
10548 sfr P0 = 0x80;\SpecialChar ~
10549
10550 \family default
10551  is compiled 
10552 \emph on
10553 without warning
10554 \emph default
10555  by SDCC to an assignment of 0x80 to a variable called P0 
10556 \family typewriter
10557
10558 \begin_inset Marginal
10559 collapsed true
10560
10561 \layout Standard
10562
10563 \series bold
10564 \SpecialChar ~
10565 !
10566
10567 \end_inset
10568
10569 .
10570  
10571 \family default
10572 Nevertheless it is possible to write header files
10573 \begin_inset LatexCommand \index{Header files}
10574
10575 \end_inset
10576
10577
10578 \begin_inset LatexCommand \index{Include files}
10579
10580 \end_inset
10581
10582  which can be shared among different compilers (see section 
10583 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
10584
10585 \end_inset
10586
10587 ).
10588  
10589
10590 \layout Subsubsection
10591 Pointers
10592 \begin_inset LatexCommand \index{Pointer}
10593
10594 \end_inset
10595
10596  to MCS51/DS390 specific memory spaces
10597
10598 \layout Standard
10599 SDCC allows (via language extensions) pointers to explicitly point to any
10600  of the memory spaces
10601 \begin_inset LatexCommand \index{Memory model}
10602
10603 \end_inset
10604
10605  of the 8051.
10606  In addition to the explicit pointers, the compiler uses (by default) generic
10607  pointers which can be used to point to any of the memory spaces.
10608 \newline
10609
10610 \newline
10611 Pointer
10612  declaration examples:
10613
10614 \layout Verse
10615
10616 \family typewriter
10617 /* pointer physically in internal ram pointing to object in external ram
10618  */ 
10619 \newline
10620 __xdata unsigned char * __data p;
10621 \newline
10622
10623 \newline
10624 /* pointer physically in external ram
10625  pointing to object in internal ram */ 
10626 \newline
10627 __data unsigned char * __xdata p;
10628 \newline
10629
10630 \newline
10631 /*
10632  pointer physically in code rom pointing to data in xdata space */ 
10633 \newline
10634 __xdata
10635  unsigned char * __code p;
10636 \newline
10637
10638 \newline
10639 /* pointer physically in code space pointing to
10640  data in code space */ 
10641 \newline
10642 __code unsigned char * __code p;
10643 \newline
10644
10645 \newline
10646 /* generic pointer
10647  physically located in xdata space */
10648 \newline
10649 unsigned char * __xdata p;
10650 \newline
10651
10652 \newline
10653 /* generic
10654  pointer physically located in default memory space */
10655 \newline
10656 unsigned char * p;
10657 \newline
10658
10659 \newline
10660 /*
10661  the following is a function pointer
10662 \begin_inset LatexCommand \index{function pointer}
10663
10664 \end_inset
10665
10666  physically located in data space */
10667 \newline
10668 char (* __data fp)(void);
10669
10670 \layout Standard
10671 Well you get the idea.
10672  
10673 \newline
10674
10675 \newline
10676 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
10677 \emph on
10678 generic
10679 \emph default
10680  pointers.
10681  
10682 \size small
10683
10684 \newline
10685
10686 \newline
10687
10688 \size default
10689 The highest order byte of the 
10690 \emph on
10691 generic
10692 \emph default
10693  pointers contains the data space information.
10694  Assembler support routines are called whenever data is stored or retrieved
10695  using 
10696 \emph on
10697 generic
10698 \emph default
10699  pointers.
10700  These are useful for developing reusable library
10701 \begin_inset LatexCommand \index{Libraries}
10702
10703 \end_inset
10704
10705  routines.
10706  Explicitly specifying the pointer
10707 \begin_inset LatexCommand \index{pointer}
10708
10709 \end_inset
10710
10711  type will generate the most efficient code.
10712
10713 \layout Subsubsection
10714 Notes on MCS51 memory
10715 \begin_inset LatexCommand \index{MCS51 memory}
10716
10717 \end_inset
10718
10719  layout
10720
10721 \layout Standard
10722 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
10723  RAM memory which is structured as follows:
10724 \newline
10725
10726 \newline
10727 - Bytes 00-1F - 32 bytes to hold
10728  up to 4 banks of the registers R0 to R7, 
10729 \newline
10730 - Bytes 20-2F - 16 bytes to hold
10731  128 bit
10732 \begin_inset LatexCommand \index{bit}
10733
10734 \end_inset
10735
10736  variables and, 
10737 \newline
10738 - Bytes 30-7F - 80 bytes for general purpose use.
10739 \newline
10740
10741
10742 \layout Standard
10743 Additionally some members of the MCS51 family may have up to 128 bytes of
10744  additional, indirectly addressable, internal RAM memory (
10745 \emph on
10746 idata
10747 \emph default
10748
10749 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10750
10751 \end_inset
10752
10753
10754 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10755
10756 \end_inset
10757
10758 ).
10759  Furthermore, some chips may have some built in external memory (
10760 \emph on
10761 xdata
10762 \emph default
10763
10764 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10765
10766 \end_inset
10767
10768
10769 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10770
10771 \end_inset
10772
10773 ) which should not be confused with the internal, directly addressable RAM
10774  memory (
10775 \emph on
10776 data
10777 \emph default
10778
10779 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10780
10781 \end_inset
10782
10783
10784 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10785
10786 \end_inset
10787
10788 ).
10789  Sometimes this built in 
10790 \emph on
10791 xdata
10792 \emph default
10793  memory has to be activated before using it (you can probably find this
10794  information on the datasheet of the microcontroller your are using, see
10795  also section 
10796 \begin_inset LatexCommand \ref{sub:Startup-Code}
10797
10798 \end_inset
10799
10800 \SpecialChar ~
10801 Startup-Code).
10802
10803 \layout Standard
10804 Normally SDCC will only use the first bank
10805 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10806
10807 \end_inset
10808
10809  of registers (register bank 0), but it is possible to specify that other
10810  banks of registers (keyword 
10811 \emph on
10812 using
10813 \emph default
10814  
10815 \emph on
10816
10817 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10818
10819 \end_inset
10820
10821
10822 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
10823
10824 \end_inset
10825
10826
10827 \emph default
10828 ) should be used in interrupt
10829 \begin_inset LatexCommand \index{interrupt}
10830
10831 \end_inset
10832
10833
10834 \begin_inset LatexCommand \index{\_\_interrupt}
10835
10836 \end_inset
10837
10838  routines.
10839  By default, the compiler will place the stack after the last byte of allocated
10840  memory for variables.
10841  For example, if the first 2 banks of registers are used, and only four
10842  bytes are used for 
10843 \emph on
10844 data
10845 \emph default
10846  variables, it will position the base of the internal stack at address 20
10847  (0x14).
10848  This implies that as the stack
10849 \begin_inset LatexCommand \index{stack}
10850
10851 \end_inset
10852
10853  grows, it will use up the remaining register banks, and the 16 bytes used
10854  by the 128 bit variables, and 80 bytes for general purpose use.
10855  If any bit variables are used, the data variables will be placed in unused
10856  register banks and after the byte holding the last bit variable.
10857  For example, if register banks 0 and 1 are used, and there are 9 bit variables
10858  (two bytes used), 
10859 \emph on
10860 data
10861 \emph default
10862  variables will be placed starting from address 0x10 to 0x20 and continue
10863  at address 0x22.
10864  You can also use -
10865 \begin_inset ERT
10866 status Collapsed
10867
10868 \layout Standard
10869
10870
10871 \backslash
10872 /
10873
10874 \end_inset
10875
10876 -data-loc
10877 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
10878
10879 \end_inset
10880
10881  to specify the start address of the 
10882 \emph on
10883 data
10884 \emph default
10885  and -
10886 \begin_inset ERT
10887 status Collapsed
10888
10889 \layout Standard
10890
10891
10892 \backslash
10893 /
10894
10895 \end_inset
10896
10897 -iram-size
10898 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
10899
10900 \end_inset
10901
10902  to specify the size of the total internal RAM (
10903 \emph on
10904 data
10905 \emph default
10906 +
10907 \emph on
10908 idata
10909 \emph default
10910 ).
10911  
10912 \newline
10913
10914
10915 \layout Standard
10916 By default the 8051 linker will place the stack after the last byte of (i)data
10917  variables.
10918  Option -
10919 \begin_inset ERT
10920 status Collapsed
10921
10922 \layout Standard
10923
10924
10925 \backslash
10926 /
10927
10928 \end_inset
10929
10930 -stack-loc
10931 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
10932
10933 \end_inset
10934
10935  allows you to specify the start of the stack, i.e.
10936  you could start it after any data in the general purpose area.
10937  If your microcontroller has additional indirectly addressable internal
10938  RAM (
10939 \emph on
10940 idata
10941 \emph default
10942 ) you can place the stack on it.
10943  You may also need to use -
10944 \begin_inset ERT
10945 status Collapsed
10946
10947 \layout Standard
10948
10949
10950 \backslash
10951 /
10952
10953 \end_inset
10954
10955 -xdata-loc
10956 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
10957
10958 \end_inset
10959
10960  to set the start address of the external RAM (
10961 \emph on
10962 xdata
10963 \emph default
10964 ) and -
10965 \begin_inset ERT
10966 status Collapsed
10967
10968 \layout Standard
10969
10970
10971 \backslash
10972 /
10973
10974 \end_inset
10975
10976 -xram-size
10977 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
10978
10979 \end_inset
10980
10981  to specify its size.
10982  Same goes for the code memory, using -
10983 \begin_inset ERT
10984 status Collapsed
10985
10986 \layout Standard
10987
10988
10989 \backslash
10990 /
10991
10992 \end_inset
10993
10994 -code-loc
10995 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
10996
10997 \end_inset
10998
10999  and -
11000 \begin_inset ERT
11001 status Collapsed
11002
11003 \layout Standard
11004
11005
11006 \backslash
11007 /
11008
11009 \end_inset
11010
11011 -code-size
11012 \begin_inset LatexCommand \index{-\/-code-size <Value>}
11013
11014 \end_inset
11015
11016 .
11017  If in doubt, don't specify any options and see if the resulting memory
11018  layout is appropriate, then you can adjust it.
11019
11020 \layout Standard
11021 \added_space_bottom bigskip 
11022 The linker generates two files with memory allocation information.
11023  The first, with extension .map
11024 \begin_inset LatexCommand \index{<file>.map}
11025
11026 \end_inset
11027
11028  shows all the variables and segments.
11029  The second with extension .mem
11030 \begin_inset LatexCommand \index{<file>.mem}
11031
11032 \end_inset
11033
11034  shows the final memory layout.
11035  The linker will complain either if memory segments overlap, there is not
11036  enough memory, or there is not enough space for stack.
11037  If you get any linking warnings and/or errors related to stack or segments
11038  allocation, take a look at either the .map or .mem files to find out what
11039  the problem is.
11040  The .mem file may even suggest a solution to the problem.
11041
11042
11043
11044 \layout Subsection
11045 Z80/Z180 Storage Class
11046 \begin_inset LatexCommand \index{Z80!Storage class}
11047
11048 \end_inset
11049
11050  Language Extensions
11051
11052 \layout Subsubsection
11053 sfr
11054 \begin_inset LatexCommand \index{sfr}
11055
11056 \end_inset
11057
11058
11059 \begin_inset LatexCommand \index{\_\_sfr}
11060
11061 \end_inset
11062
11063  (in/out to 8-bit addresses)
11064
11065 \layout Standard
11066 The Z80
11067 \begin_inset LatexCommand \index{Z80}
11068
11069 \end_inset
11070
11071  family has separate address spaces for memory and 
11072 \emph on
11073 i
11074 \emph default
11075 nput/
11076 \emph on
11077 o
11078 \emph default
11079 utput memory.
11080  I/O memory
11081 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
11082
11083 \end_inset
11084
11085
11086 \begin_inset LatexCommand \index{Z80!I/O memory}
11087
11088 \end_inset
11089
11090
11091 \begin_inset LatexCommand \index{Z180!I/O memory}
11092
11093 \end_inset
11094
11095  is accessed with special instructions, e.g.:
11096
11097 \layout Verse
11098
11099 \family typewriter
11100 sfr at 0x78 IoPort;\SpecialChar ~
11101 \SpecialChar ~
11102 /* define a var in I/O space at 78h called IoPort */
11103  
11104
11105 \layout Standard
11106 Writing 0x01 to this variable generates the assembly code:
11107
11108 \layout Verse
11109
11110 \family typewriter
11111 3E 01\SpecialChar ~
11112 \SpecialChar ~
11113 \SpecialChar ~
11114 \SpecialChar ~
11115 \SpecialChar ~
11116 \SpecialChar ~
11117 ld a,#0x01
11118 \newline
11119 D3 78\SpecialChar ~
11120 \SpecialChar ~
11121 \SpecialChar ~
11122 \SpecialChar ~
11123 \SpecialChar ~
11124 \SpecialChar ~
11125 out (_IoPort),a 
11126
11127 \layout Subsubsection
11128 banked sfr
11129 \begin_inset LatexCommand \index{sfr}
11130
11131 \end_inset
11132
11133
11134 \begin_inset LatexCommand \index{\_\_sfr}
11135
11136 \end_inset
11137
11138  (in/out to 16-bit addresses)
11139
11140 \layout Standard
11141 The keyword 
11142 \emph on
11143 banked
11144 \emph default
11145  is used to support 16 bit addresses in I/O memory e.g.:
11146
11147 \layout Verse
11148
11149 \family typewriter
11150 sfr banked at
11151 \begin_inset LatexCommand \index{at}
11152
11153 \end_inset
11154
11155
11156 \begin_inset LatexCommand \index{\_\_at}
11157
11158 \end_inset
11159
11160  0x123 IoPort; 
11161
11162 \layout Standard
11163 Writing 0x01 to this variable generates the assembly code:
11164
11165 \layout Verse
11166
11167 \family typewriter
11168 01 23 01\SpecialChar ~
11169 \SpecialChar ~
11170 \SpecialChar ~
11171 ld bc,#_IoPort
11172 \newline
11173 3E 01\SpecialChar ~
11174 \SpecialChar ~
11175 \SpecialChar ~
11176 \SpecialChar ~
11177 \SpecialChar ~
11178 \SpecialChar ~
11179 ld a,#0x01 
11180 \newline
11181 ED 79\SpecialChar ~
11182 \SpecialChar ~
11183 \SpecialChar ~
11184 \SpecialChar ~
11185 \SpecialChar ~
11186 \SpecialChar ~
11187 out (c),a 
11188
11189 \layout Subsubsection
11190 sfr
11191 \begin_inset LatexCommand \index{sfr}
11192
11193 \end_inset
11194
11195
11196 \begin_inset LatexCommand \index{\_\_sfr}
11197
11198 \end_inset
11199
11200  (in0/out0 to 8 bit addresses on Z180
11201 \begin_inset LatexCommand \index{Z180}
11202
11203 \end_inset
11204
11205 /HD64180
11206 \begin_inset LatexCommand \index{HD64180 (see Z180)}
11207
11208 \end_inset
11209
11210 )
11211
11212 \layout Standard
11213 \added_space_bottom bigskip 
11214 The compiler option -
11215 \begin_inset ERT
11216 status Collapsed
11217
11218 \layout Standard
11219
11220
11221 \backslash
11222 /
11223
11224 \end_inset
11225
11226 -portmode
11227 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
11228
11229 \end_inset
11230
11231 =180 (80) and a compiler #pragma\SpecialChar ~
11232 portmode
11233 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
11234
11235 \end_inset
11236
11237  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
11238 ns 
11239 \family typewriter
11240 in0/out0
11241 \family default
11242  instead of 
11243 \family typewriter
11244 in/out
11245 \family default
11246 .
11247  If you include the file z180.h this will be set automatically.
11248
11249
11250
11251 \layout Subsection
11252 HC08 Storage Class
11253 \begin_inset LatexCommand \index{HC08!Storage class}
11254
11255 \end_inset
11256
11257  Language Extensions
11258
11259 \layout Subsubsection
11260 data
11261 \begin_inset LatexCommand \index{data (hc08 storage class)}
11262
11263 \end_inset
11264
11265
11266 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
11267
11268 \end_inset
11269
11270  
11271
11272 \layout Standard
11273 The data storage class declares a variable that resides in the first 256
11274  bytes of memory (the direct page).
11275  The HC08
11276 \begin_inset LatexCommand \index{HC08}
11277
11278 \end_inset
11279
11280  is most efficient at accessing variables (especially pointers) stored here.
11281
11282 \layout Subsubsection
11283 xdata
11284 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
11285
11286 \end_inset
11287
11288
11289 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
11290
11291 \end_inset
11292
11293  
11294
11295 \layout Standard
11296 \added_space_bottom bigskip 
11297 The xdata storage class declares a variable that can reside anywhere in
11298  memory.
11299  This is the default if no storage class is specified.
11300  
11301
11302
11303
11304 \layout Section
11305 Absolute Addressing
11306 \begin_inset LatexCommand \index{Absolute addressing}
11307
11308 \end_inset
11309
11310
11311
11312 \layout Standard
11313 Data items can be assigned an absolute address with the 
11314 \emph on
11315 at
11316 \begin_inset LatexCommand \index{at}
11317
11318 \end_inset
11319
11320
11321 \begin_inset LatexCommand \index{\_\_at}
11322
11323 \end_inset
11324
11325  <address>
11326 \emph default
11327  keyword, in addition to a storage class, e.g.:
11328
11329 \layout Verse
11330
11331 \family typewriter
11332 xdata
11333 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11334
11335 \end_inset
11336
11337
11338 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11339
11340 \end_inset
11341
11342  at
11343 \begin_inset LatexCommand \index{at}
11344
11345 \end_inset
11346
11347
11348 \begin_inset LatexCommand \index{\_\_at}
11349
11350 \end_inset
11351
11352  0x7ffe unsigned int chksum;
11353
11354 \layout Standard
11355 or, better conforming to ISO/IEC 9899 C:
11356
11357 \layout Verse
11358
11359 \family typewriter
11360 __xdata __at (0x7ffe) unsigned int chksum;
11361
11362 \layout Standard
11363 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
11364  of the external ram.
11365  The compiler does 
11366 \emph on
11367 not
11368 \emph default
11369  reserve any space for variables declared in this way
11370 \begin_inset Marginal
11371 collapsed true
11372
11373 \layout Standard
11374
11375 \series bold
11376 \SpecialChar ~
11377 !
11378
11379 \end_inset
11380
11381  (they are implemented with an equate in the assembler).
11382  Thus it is left to the programmer to make sure there are no overlaps with
11383  other variables that are declared without the absolute address.
11384  The assembler listing file (.lst
11385 \begin_inset LatexCommand \index{<file>.lst}
11386
11387 \end_inset
11388
11389 ) and the linker output files (.rst
11390 \begin_inset LatexCommand \index{<file>.rst}
11391
11392 \end_inset
11393
11394 ) and (.map
11395 \begin_inset LatexCommand \index{<file>.map}
11396
11397 \end_inset
11398
11399 ) are good places to look for such overlaps.
11400  Variables with an absolute address are 
11401 \emph on
11402 not
11403 \begin_inset Marginal
11404 collapsed true
11405
11406 \layout Standard
11407
11408 \series bold
11409 \SpecialChar ~
11410 !
11411
11412 \end_inset
11413
11414
11415 \emph default
11416  initialized
11417 \begin_inset LatexCommand \index{Variable initialization}
11418
11419 \end_inset
11420
11421 .
11422
11423 \layout Standard
11424 In case of memory mapped I/O devices the keyword 
11425 \emph on
11426 volatile
11427 \emph default
11428  has to be used to tell the compiler that accesses might not be removed:
11429
11430 \layout Verse
11431
11432 \family typewriter
11433 volatile
11434 \begin_inset LatexCommand \index{volatile}
11435
11436 \end_inset
11437
11438  __xdata
11439 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11440
11441 \end_inset
11442
11443  __at
11444 \begin_inset LatexCommand \index{at}
11445
11446 \end_inset
11447
11448  (0x8000) unsigned char PORTA_8255;
11449
11450 \layout Standard
11451 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
11452 r) array
11453 \family typewriter
11454 \size footnotesize
11455
11456 \begin_inset LatexCommand \index{Aligned array}
11457
11458 \end_inset
11459
11460
11461 \family default
11462 \size default
11463  starts at a block (256 byte) boundary
11464 \begin_inset LatexCommand \index{block boundary}
11465
11466 \end_inset
11467
11468  (section 
11469 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
11470
11471 \end_inset
11472
11473  has an example).
11474 \newline
11475 Absolute addresses can be specified for variables in all
11476  storage classes, e.g.:
11477
11478 \layout Verse
11479
11480 \family typewriter
11481 __bit
11482 \begin_inset LatexCommand \index{bit}
11483
11484 \end_inset
11485
11486  __at
11487 \begin_inset LatexCommand \index{at}
11488
11489 \end_inset
11490
11491  (0x02) bvar;
11492
11493 \layout Standard
11494 The above example will allocate the variable at offset 0x02 in the bit-addressab
11495 le space.
11496  There is no real advantage to assigning absolute addresses to variables
11497  in this manner, unless you want strict control over all the variables allocated.
11498  One possible use would be to write hardware portable code.
11499  For example, if you have a routine that uses one or more of the microcontroller
11500  I/O pins, and such pins are different for two different hardwares, you
11501  can declare the I/O pins in your routine using:
11502
11503 \layout Verse
11504
11505 \family typewriter
11506 extern volatile
11507 \begin_inset LatexCommand \index{volatile}
11508
11509 \end_inset
11510
11511  __bit MOSI;\SpecialChar ~
11512 \SpecialChar ~
11513 \SpecialChar ~
11514 \SpecialChar ~
11515 /* master out, slave in */
11516 \newline
11517 extern volatile __bit MISO;\SpecialChar ~
11518 \SpecialChar ~
11519 \SpecialChar ~
11520 \SpecialChar ~
11521 /* master
11522  in, slave out */
11523 \newline
11524 extern volatile __bit MCLK;\SpecialChar ~
11525 \SpecialChar ~
11526 \SpecialChar ~
11527 \SpecialChar ~
11528 /* master clock */
11529 \newline
11530
11531 \newline
11532 /* Input and
11533  Output of a byte on a 3-wire serial bus.
11534 \newline
11535 \SpecialChar ~
11536 \SpecialChar ~
11537 \SpecialChar ~
11538 If needed adapt polarity of clock,
11539  polarity of data and bit order
11540 \newline
11541 \SpecialChar ~
11542 */
11543 \newline
11544 unsigned char spi_io(unsigned char out_byte)
11545  
11546 \newline
11547
11548 \newline
11549 \SpecialChar ~
11550 \SpecialChar ~
11551 \SpecialChar ~
11552 \SpecialChar ~
11553 unsigned char i=8;
11554 \newline
11555 \SpecialChar ~
11556 \SpecialChar ~
11557 \SpecialChar ~
11558 \SpecialChar ~
11559 do { 
11560 \newline
11561 \SpecialChar ~
11562 \SpecialChar ~
11563 \SpecialChar ~
11564 \SpecialChar ~
11565 \SpecialChar ~
11566 \SpecialChar ~
11567 \SpecialChar ~
11568 \SpecialChar ~
11569 MOSI = out_byte & 0x80; 
11570 \newline
11571 \SpecialChar ~
11572 \SpecialChar ~
11573 \SpecialChar ~
11574 \SpecialChar ~
11575 \SpecialChar ~
11576 \SpecialChar ~
11577 \SpecialChar ~
11578 \SpecialChar ~
11579 out_byte <<= 1;
11580 \newline
11581 \SpecialChar ~
11582 \SpecialChar ~
11583 \SpecialChar ~
11584 \SpecialChar ~
11585 \SpecialChar ~
11586 \SpecialChar ~
11587 \SpecialChar ~
11588 \SpecialChar ~
11589 MCLK =
11590  1; 
11591 \newline
11592 \SpecialChar ~
11593 \SpecialChar ~
11594 \SpecialChar ~
11595 \SpecialChar ~
11596 \SpecialChar ~
11597 \SpecialChar ~
11598 \SpecialChar ~
11599 \SpecialChar ~
11600 /* _asm nop _endasm; */\SpecialChar ~
11601 \SpecialChar ~
11602 \SpecialChar ~
11603 \SpecialChar ~
11604 \SpecialChar ~
11605 \SpecialChar ~
11606 \SpecialChar ~
11607 \SpecialChar ~
11608 /* for slow peripherals */
11609 \newline
11610 \SpecialChar ~
11611 \SpecialChar ~
11612 \SpecialChar ~
11613 \SpecialChar ~
11614 \SpecialChar ~
11615 \SpecialChar ~
11616 \SpecialChar ~
11617 \SpecialChar ~
11618 if(MISO) 
11619 \newline
11620 \SpecialChar ~
11621 \SpecialChar ~
11622 \SpecialChar ~
11623 \SpecialChar ~
11624 \SpecialChar ~
11625 \SpecialChar ~
11626 \SpecialChar ~
11627 \SpecialChar ~
11628 \SpecialChar ~
11629 \SpecialChar ~
11630 \SpecialChar ~
11631 \SpecialChar ~
11632 out_byte +=
11633  1; 
11634 \newline
11635 \SpecialChar ~
11636 \SpecialChar ~
11637 \SpecialChar ~
11638 \SpecialChar ~
11639 \SpecialChar ~
11640 \SpecialChar ~
11641 \SpecialChar ~
11642 \SpecialChar ~
11643 MCLK = 0; 
11644 \newline
11645 \SpecialChar ~
11646 \SpecialChar ~
11647 \SpecialChar ~
11648 \SpecialChar ~
11649 } while(--i);
11650 \newline
11651 \SpecialChar ~
11652 \SpecialChar ~
11653 \SpecialChar ~
11654 \SpecialChar ~
11655 return out_byte; 
11656 \newline
11657 }
11658
11659 \layout Standard
11660 Then, someplace in the code for the first hardware you would use
11661
11662 \layout Verse
11663
11664 \family typewriter
11665 __bit __at
11666 \begin_inset LatexCommand \index{at}
11667
11668 \end_inset
11669
11670
11671 \begin_inset LatexCommand \index{\_\_at}
11672
11673 \end_inset
11674
11675  (0x80) MOSI;\SpecialChar ~
11676 \SpecialChar ~
11677 \SpecialChar ~
11678 \SpecialChar ~
11679 /* I/O port 0, bit 0 */
11680 \newline
11681 __bit __at (0x81) MISO;\SpecialChar ~
11682 \SpecialChar ~
11683 \SpecialChar ~
11684 \SpecialChar ~
11685 /* I/O port 0,
11686  bit 1 */
11687 \newline
11688 __bit __at (0x82) MCLK;\SpecialChar ~
11689 \SpecialChar ~
11690 \SpecialChar ~
11691 \SpecialChar ~
11692 /* I/O port 0, bit 2 */
11693
11694 \layout Standard
11695 Similarly, for the second hardware you would use
11696
11697 \layout Verse
11698
11699 \family typewriter
11700 __bit __at (0x83) MOSI;\SpecialChar ~
11701 \SpecialChar ~
11702 \SpecialChar ~
11703 \SpecialChar ~
11704 /* I/O port 0, bit 3 */
11705 \newline
11706 __bit __at (0x91) MISO;\SpecialChar ~
11707 \SpecialChar ~
11708 \SpecialChar ~
11709 \SpecialChar ~
11710 /*
11711  I/O port 1, bit 1 */
11712 \newline
11713 __bit
11714 \begin_inset LatexCommand \index{bit}
11715
11716 \end_inset
11717
11718  __at (0x92) MCLK;\SpecialChar ~
11719 \SpecialChar ~
11720 \SpecialChar ~
11721 \SpecialChar ~
11722 /* I/O port 1, bit 2 */
11723
11724 \layout Standard
11725 \added_space_bottom bigskip 
11726 and you can use the same hardware dependent routine without changes, as
11727  for example in a library.
11728  This is somehow similar to sbit, but only one absolute address has to be
11729  specified in the whole project.
11730
11731
11732
11733 \layout Section
11734 Parameters
11735 \begin_inset LatexCommand \index{Parameters}
11736
11737 \end_inset
11738
11739
11740 \begin_inset LatexCommand \index{function parameter}
11741
11742 \end_inset
11743
11744  & Local Variables
11745 \begin_inset LatexCommand \index{local variables}
11746
11747 \end_inset
11748
11749
11750 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
11751
11752 \end_inset
11753
11754
11755
11756 \layout Standard
11757 Automatic (local) variables and parameters to functions can either be placed
11758  on the stack or in data-space.
11759  The default action of the compiler is to place these variables in the internal
11760  RAM (for small model) or external RAM (for large model).
11761  This in fact makes them similar to 
11762 \emph on
11763 static
11764 \begin_inset LatexCommand \index{static}
11765
11766 \end_inset
11767
11768
11769 \emph default
11770  so by default functions are non-reentrant
11771 \begin_inset LatexCommand \index{reentrant}
11772
11773 \end_inset
11774
11775 .
11776  
11777 \newline
11778
11779 \newline
11780 They can be placed on the stack
11781 \begin_inset LatexCommand \index{stack}
11782
11783 \end_inset
11784
11785  by using the
11786 \emph on
11787  -
11788 \begin_inset ERT
11789 status Collapsed
11790
11791 \layout Standard
11792
11793
11794 \backslash
11795 /
11796
11797 \end_inset
11798
11799 -stack-auto
11800 \begin_inset LatexCommand \index{-\/-stack-auto}
11801
11802 \end_inset
11803
11804
11805 \emph default
11806  option, by using 
11807 \emph on
11808 #pragma\SpecialChar ~
11809 stackauto
11810 \emph default
11811
11812 \begin_inset LatexCommand \index{\#pragma stackauto}
11813
11814 \end_inset
11815
11816  or by using the 
11817 \emph on
11818 reentrant
11819 \begin_inset LatexCommand \index{reentrant}
11820
11821 \end_inset
11822
11823
11824 \emph default
11825  keyword in the function declaration, e.g.:
11826
11827 \layout Verse
11828
11829 \family typewriter
11830 unsigned char foo(char i) __reentrant 
11831 \newline
11832
11833 \newline
11834 \SpecialChar ~
11835 \SpecialChar ~
11836 \SpecialChar ~
11837 \SpecialChar ~
11838 ...
11839  
11840 \newline
11841 }
11842
11843 \layout Standard
11844 Since stack space on 8051 is limited, the 
11845 \emph on
11846 reentrant 
11847 \emph default
11848 keyword or the
11849 \emph on
11850  -
11851 \begin_inset ERT
11852 status Collapsed
11853
11854 \layout Standard
11855
11856
11857 \backslash
11858 /
11859
11860 \end_inset
11861
11862 -stack-auto
11863 \emph default
11864  option should be used sparingly.
11865  Note that the reentrant keyword just means that the parameters & local
11866  variables will be allocated to the stack, it 
11867 \emph on
11868 does not
11869 \emph default
11870  mean that the function is register bank
11871 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11872
11873 \end_inset
11874
11875  independent.
11876 \newline
11877
11878 \newline
11879 Local variables
11880 \begin_inset LatexCommand \index{local variables}
11881
11882 \end_inset
11883
11884  can be assigned storage classes and absolute
11885 \begin_inset LatexCommand \index{Absolute addressing}
11886
11887 \end_inset
11888
11889  addresses, e.g.: 
11890
11891 \layout Verse
11892
11893 \family typewriter
11894 unsigned char foo() 
11895 \newline
11896 {
11897 \newline
11898 \SpecialChar ~
11899 \SpecialChar ~
11900 \SpecialChar ~
11901 \SpecialChar ~
11902 __xdata unsigned char i;
11903 \newline
11904 \SpecialChar ~
11905 \SpecialChar ~
11906 \SpecialChar ~
11907 \SpecialChar ~
11908 __bit bvar;
11909 \newline
11910 \SpecialChar ~
11911 \SpecialChar ~
11912 \SpecialChar ~
11913 \SpecialChar ~
11914 __data __at
11915 \begin_inset LatexCommand \index{at}
11916
11917 \end_inset
11918
11919  (0x31) unsigned char j;
11920 \newline
11921 \SpecialChar ~
11922 \SpecialChar ~
11923 \SpecialChar ~
11924 \SpecialChar ~
11925 ...
11926  
11927 \newline
11928 }
11929
11930 \layout Standard
11931 In the above example the variable 
11932 \emph on
11933 i
11934 \emph default
11935  will be allocated in the external ram, 
11936 \emph on
11937 bvar
11938 \emph default
11939  in bit addressable space and
11940 \emph on
11941  j
11942 \emph default
11943  in internal ram.
11944  When compiled with 
11945 \emph on
11946 -
11947 \begin_inset ERT
11948 status Collapsed
11949
11950 \layout Standard
11951
11952
11953 \backslash
11954 /
11955
11956 \end_inset
11957
11958 -stack-auto
11959 \emph default
11960  or when a function is declared as 
11961 \emph on
11962 reentrant
11963 \emph default
11964  this should only be done for static variables.
11965
11966 \layout Standard
11967 Parameters
11968 \begin_inset LatexCommand \index{function parameter}
11969
11970 \end_inset
11971
11972  however are not allowed any storage class
11973 \begin_inset LatexCommand \index{Storage class}
11974
11975 \end_inset
11976
11977 , (storage classes for parameters will be ignored), their allocation is
11978  governed by the memory model in use, and the reentrancy options.
11979
11980 \layout Standard
11981 It is however allowed to use bit parameters in reentrant functions and also
11982  non-static local bit variables are supported.
11983  Efficient use is limited to 8 semi-bitregisters in bit space.
11984  They are pushed and popped to stack
11985 \begin_inset LatexCommand \index{stack}
11986
11987 \end_inset
11988
11989  as a single byte just like the normal registers.
11990
11991 \layout Section
11992 Overlaying
11993 \begin_inset LatexCommand \label{sub:Overlaying}
11994
11995 \end_inset
11996
11997
11998 \begin_inset LatexCommand \index{Overlaying}
11999
12000 \end_inset
12001
12002
12003
12004 \layout Standard
12005 For non-reentrant
12006 \begin_inset LatexCommand \index{reentrant}
12007
12008 \end_inset
12009
12010  functions SDCC will try to reduce internal ram space usage by overlaying
12011  parameters and local variables of a function (if possible).
12012  Parameters and local variables
12013 \begin_inset LatexCommand \index{local variables}
12014
12015 \end_inset
12016
12017  of a function will be allocated to an overlayable segment if the function
12018  has 
12019 \emph on
12020 no other function calls and the function is non-reentrant and the memory
12021  model
12022 \begin_inset LatexCommand \index{Memory model}
12023
12024 \end_inset
12025
12026  is small.
12027
12028 \emph default
12029  If an explicit storage class
12030 \begin_inset LatexCommand \index{Storage class}
12031
12032 \end_inset
12033
12034  is specified for a local variable, it will NOT be overlayed.
12035
12036 \layout Standard
12037 Note that the compiler (not the linkage editor) makes the decision for overlayin
12038 g the data items.
12039  Functions that are called from an interrupt service routine
12040 \begin_inset Marginal
12041 collapsed true
12042
12043 \layout Standard
12044
12045 \series bold
12046 !
12047
12048 \end_inset
12049
12050  should be preceded by a #pragma\SpecialChar ~
12051 nooverlay
12052 \begin_inset LatexCommand \index{\#pragma nooverlay}
12053
12054 \end_inset
12055
12056  if they are not reentrant.
12057
12058 \layout Standard
12059 Also note that the compiler does not do any processing of inline assembler
12060  code, so the compiler might incorrectly assign local variables and parameters
12061  of a function into the overlay segment if the inline assembler code calls
12062  other c-functions that might use the overlay.
12063  In that case the #pragma\SpecialChar ~
12064 nooverlay should be used.
12065
12066 \layout Standard
12067 Parameters and local variables of functions that contain 16 or 32 bit multiplica
12068 tion
12069 \begin_inset LatexCommand \index{Multiplication}
12070
12071 \end_inset
12072
12073  or division
12074 \begin_inset LatexCommand \index{Division}
12075
12076 \end_inset
12077
12078  will NOT be overlayed since these are implemented using external functions,
12079  e.g.:
12080
12081 \layout Verse
12082
12083 \family typewriter
12084 #pragma save 
12085 \newline
12086 #pragma nooverlay
12087 \begin_inset LatexCommand \index{\#pragma nooverlay}
12088
12089 \end_inset
12090
12091  
12092 \newline
12093 void set_error(unsigned char errcd) 
12094 \newline
12095 {
12096 \newline
12097 \SpecialChar ~
12098 \SpecialChar ~
12099 \SpecialChar ~
12100 \SpecialChar ~
12101 P3 = errcd;
12102 \newline
12103
12104 \newline
12105 #pragma restore 
12106 \newline
12107
12108 \newline
12109 void
12110  some_isr () __interrupt
12111 \begin_inset LatexCommand \index{interrupt}
12112
12113 \end_inset
12114
12115  (2)
12116 \newline
12117 {
12118 \newline
12119 \SpecialChar ~
12120 \SpecialChar ~
12121 \SpecialChar ~
12122 \SpecialChar ~
12123 ...
12124 \newline
12125 \SpecialChar ~
12126 \SpecialChar ~
12127 \SpecialChar ~
12128 \SpecialChar ~
12129 set_error(10);
12130 \newline
12131 \SpecialChar ~
12132 \SpecialChar ~
12133 \SpecialChar ~
12134 \SpecialChar ~
12135 ...
12136  
12137 \newline
12138 }
12139
12140 \layout Standard
12141 \added_space_bottom bigskip 
12142 In the above example the parameter 
12143 \emph on
12144 errcd
12145 \emph default
12146  for the function 
12147 \emph on
12148 set_error
12149 \emph default
12150  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
12151 nooverlay was
12152  not present, this could cause unpredictable runtime behavior when called
12153  from an interrupt service routine.
12154  The #pragma\SpecialChar ~
12155 nooverlay ensures that the parameters and local variables for
12156  the function are NOT overlayed.
12157
12158
12159
12160 \layout Section
12161 Interrupt Service Routines
12162 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
12163
12164 \end_inset
12165
12166
12167
12168 \layout Subsection
12169 General Information
12170
12171 \layout Standard
12172 SDCC allows 
12173 \emph on
12174 i
12175 \emph default
12176 nterrupt 
12177 \emph on
12178 s
12179 \emph default
12180 ervice 
12181 \emph on
12182 r
12183 \emph default
12184 outines to be coded in C, with some extended keywords.
12185
12186 \layout Verse
12187
12188 \family typewriter
12189 void timer_isr (void) __interrupt (1) __using (1) 
12190 \newline
12191
12192 \newline
12193 \SpecialChar ~
12194 \SpecialChar ~
12195 \SpecialChar ~
12196 \SpecialChar ~
12197 ...
12198  
12199 \newline
12200 }
12201
12202 \layout Standard
12203 The optional number following the 
12204 \emph on
12205 interrupt
12206 \begin_inset LatexCommand \index{interrupt}
12207
12208 \end_inset
12209
12210
12211 \begin_inset LatexCommand \index{\_\_interrupt}
12212
12213 \end_inset
12214
12215
12216 \emph default
12217  keyword is the interrupt number this routine will service.
12218  When present, the compiler will insert a call to this routine in the interrupt
12219  vector table
12220 \begin_inset LatexCommand \index{interrupt vector table}
12221
12222 \end_inset
12223
12224  for the interrupt number specified.
12225  If you have multiple source files in your project, interrupt service routines
12226  can be present in any of them, but a prototype of the isr MUST be present
12227  or included in the file that contains the function 
12228 \emph on
12229 main
12230 \emph default
12231 .
12232  The optional (8051 specific) keyword 
12233 \emph on
12234 using
12235 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12236
12237 \end_inset
12238
12239
12240 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12241
12242 \end_inset
12243
12244
12245 \emph default
12246  can be used to tell the compiler to use the specified register bank when
12247  generating code for this function.
12248  
12249 \newline
12250 Interrupt service routines open the door for some very interesting bugs:
12251
12252 \layout Subsubsection
12253 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
12254
12255 \end_inset
12256
12257 Common interrupt pitfall: variable not declared 
12258 \emph on
12259 volatile
12260
12261 \layout Standard
12262 If an interrupt service routine changes variables which are accessed by
12263  other functions these variables have to be declared 
12264 \emph on
12265 volatile
12266 \emph default
12267
12268 \begin_inset LatexCommand \index{volatile}
12269
12270 \end_inset
12271
12272 .
12273  See 
12274 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
12275
12276 \end_inset
12277
12278  .
12279
12280 \layout Subsubsection
12281 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
12282
12283 \end_inset
12284
12285 Common interrupt pitfall: 
12286 \emph on
12287 non-atomic access
12288
12289 \layout Standard
12290 If the access to these variables is not 
12291 \emph on
12292 atomic
12293 \begin_inset LatexCommand \index{atomic}
12294
12295 \end_inset
12296
12297
12298 \emph default
12299  (i.e.
12300  the processor needs more than one instruction for the access and could
12301  be interrupted while accessing the variable) the interrupt must be disabled
12302  during the access to avoid inconsistent data.
12303  
12304 \newline
12305 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
12306  and should be protected by disabling interrupts.
12307  You're not automatically on the safe side if you use 8 bit variables though.
12308  We need an example here: f.e.
12309  on the 8051 the harmless looking 
12310 \begin_inset Quotes srd
12311 \end_inset
12312
12313
12314 \family typewriter
12315 flags\SpecialChar ~
12316 |=\SpecialChar ~
12317 0x80;
12318 \family default
12319
12320 \begin_inset Quotes sld
12321 \end_inset
12322
12323  is not atomic if 
12324 \family typewriter
12325 flags
12326 \family default
12327  resides in xdata.
12328  Setting 
12329 \begin_inset Quotes srd
12330 \end_inset
12331
12332
12333 \family typewriter
12334 flags\SpecialChar ~
12335 |=\SpecialChar ~
12336 0x40;
12337 \family default
12338
12339 \begin_inset Quotes sld
12340 \end_inset
12341
12342  from within an interrupt routine might get lost if the interrupt occurs
12343  at the wrong time.
12344  
12345 \begin_inset Quotes sld
12346 \end_inset
12347
12348
12349 \family typewriter
12350 counter\SpecialChar ~
12351 +=\SpecialChar ~
12352 8;
12353 \family default
12354
12355 \begin_inset Quotes srd
12356 \end_inset
12357
12358  is not atomic on the 8051 even if 
12359 \family typewriter
12360 counter
12361 \family default
12362  is located in data memory.
12363 \newline
12364 Bugs like these are hard to reproduce and can
12365  cause a lot of trouble.
12366  
12367
12368 \layout Subsubsection
12369 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
12370
12371 \end_inset
12372
12373 Common interrupt pitfall: 
12374 \emph on
12375 stack overflow
12376
12377 \layout Standard
12378 The return address and the registers used in the interrupt service routine
12379  are saved on the stack
12380 \begin_inset LatexCommand \index{stack}
12381
12382 \end_inset
12383
12384  so there must be sufficient stack space.
12385  If there isn't variables or registers (or even the return address itself)
12386  will be corrupted.
12387  This 
12388 \emph on
12389 stack overflow
12390 \emph default
12391
12392 \begin_inset LatexCommand \index{stack overflow}
12393
12394 \end_inset
12395
12396  is most likely to happen if the interrupt occurs during the 
12397 \begin_inset Quotes sld
12398 \end_inset
12399
12400 deepest
12401 \begin_inset Quotes srd
12402 \end_inset
12403
12404  subroutine when the stack is already in use for f.e.
12405  many return addresses.
12406
12407 \layout Subsubsection
12408 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
12409
12410 \end_inset
12411
12412 Common interrupt pitfall: 
12413 \emph on
12414 use of non-reentrant functions
12415
12416 \layout Standard
12417 A special note here, int (16 bit) and long (32 bit) integer division
12418 \begin_inset LatexCommand \index{Division}
12419
12420 \end_inset
12421
12422 , multiplication
12423 \begin_inset LatexCommand \index{Multiplication}
12424
12425 \end_inset
12426
12427  & modulus
12428 \begin_inset LatexCommand \index{Modulus}
12429
12430 \end_inset
12431
12432  and floating-point
12433 \begin_inset LatexCommand \index{Floating point support}
12434
12435 \end_inset
12436
12437  operations are implemented using external support routines.
12438  If an interrupt service routine needs to do any of these operations then
12439  the support routines (as mentioned in a following section) will have to
12440  be recompiled using the
12441 \emph on
12442  -
12443 \begin_inset ERT
12444 status Collapsed
12445
12446 \layout Standard
12447
12448
12449 \backslash
12450 /
12451
12452 \end_inset
12453
12454 -stack-auto
12455 \begin_inset LatexCommand \index{-\/-stack-auto}
12456
12457 \end_inset
12458
12459
12460 \emph default
12461  option and the source file will need to be compiled using the 
12462 \emph on
12463 -
12464 \begin_inset ERT
12465 status Collapsed
12466
12467 \layout Standard
12468
12469
12470 \backslash
12471 /
12472
12473 \end_inset
12474
12475 -int-long-reent
12476 \emph default
12477
12478 \begin_inset LatexCommand \index{-\/-int-long-reent}
12479
12480 \end_inset
12481
12482  compiler option.
12483  
12484 \newline
12485 Note, the type promotion
12486 \begin_inset LatexCommand \index{type promotion}
12487
12488 \end_inset
12489
12490  required by ANSI C can cause 16 bit routines to be used
12491 \begin_inset Marginal
12492 collapsed true
12493
12494 \layout Standard
12495
12496 \series bold
12497 \SpecialChar ~
12498 !
12499
12500 \end_inset
12501
12502  without the programmer being aware of it.
12503  See f.e.
12504  the cast 
12505 \family typewriter
12506 (unsigned char)(tail-1)
12507 \family default
12508  within the if clause in section 
12509 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12510
12511 \end_inset
12512
12513 .
12514
12515 \layout Standard
12516 \added_space_bottom bigskip 
12517 Calling other functions from an interrupt service routine is not recommended,
12518  avoid it if possible.
12519  Note that when some function is called from an interrupt service routine
12520  it should be preceded by a #pragma\SpecialChar ~
12521 nooverlay
12522 \begin_inset LatexCommand \index{\#pragma nooverlay}
12523
12524 \end_inset
12525
12526  if it is not reentrant.
12527  Furthermore nonreentrant functions should not be called from the main program
12528  while the interrupt service routine might be active.
12529  They also must not be called from low priority interrupt service routines
12530  while a high priority interrupt service routine might be active.
12531  You could use semaphores or make the function
12532 \emph on
12533  critical
12534 \emph default
12535  if all parameters are passed in registers.
12536 \newline
12537  Also see section 
12538 \begin_inset LatexCommand \ref{sub:Overlaying}
12539
12540 \end_inset
12541
12542 \SpecialChar ~
12543 about Overlaying and section 
12544 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
12545
12546 \end_inset
12547
12548 \SpecialChar ~
12549 about Functions using private register banks.
12550
12551
12552
12553 \layout Subsection
12554 MCS51/DS390 Interrupt Service Routines
12555
12556 \layout Standard
12557 Interrupt
12558 \begin_inset LatexCommand \index{interrupt}
12559
12560 \end_inset
12561
12562  numbers and the corresponding address & descriptions for the Standard 8051/8052
12563  are listed below.
12564  SDCC will automatically adjust the 
12565 \begin_inset LatexCommand \index{interrupt vector table}
12566
12567 \end_inset
12568
12569  to the maximum interrupt number specified.
12570 \newline
12571
12572
12573 \layout Standard
12574 \align center
12575 \begin_inset Tabular
12576 <lyxtabular version="3" rows="9" columns="3">
12577 <features>
12578 <column alignment="center" valignment="top" leftline="true" width="0in">
12579 <column alignment="left" valignment="top" leftline="true" width="0in">
12580 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
12581 <row topline="true" bottomline="true">
12582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12583 \begin_inset Text
12584
12585 \layout Standard
12586 Interrupt #
12587
12588 \end_inset
12589 </cell>
12590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12591 \begin_inset Text
12592
12593 \layout Standard
12594 Description
12595
12596 \end_inset
12597 </cell>
12598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12599 \begin_inset Text
12600
12601 \layout Standard
12602 Vector Address
12603
12604 \end_inset
12605 </cell>
12606 </row>
12607 <row topline="true">
12608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12609 \begin_inset Text
12610
12611 \layout Standard
12612 0
12613
12614 \end_inset
12615 </cell>
12616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12617 \begin_inset Text
12618
12619 \layout Standard
12620 External 0
12621
12622 \end_inset
12623 </cell>
12624 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12625 \begin_inset Text
12626
12627 \layout Standard
12628 0x0003
12629
12630 \end_inset
12631 </cell>
12632 </row>
12633 <row topline="true">
12634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12635 \begin_inset Text
12636
12637 \layout Standard
12638 1
12639
12640 \end_inset
12641 </cell>
12642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12643 \begin_inset Text
12644
12645 \layout Standard
12646 Timer 0
12647
12648 \end_inset
12649 </cell>
12650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12651 \begin_inset Text
12652
12653 \layout Standard
12654 0x000b
12655
12656 \end_inset
12657 </cell>
12658 </row>
12659 <row topline="true">
12660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12661 \begin_inset Text
12662
12663 \layout Standard
12664 2
12665
12666 \end_inset
12667 </cell>
12668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12669 \begin_inset Text
12670
12671 \layout Standard
12672 External 1
12673
12674 \end_inset
12675 </cell>
12676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12677 \begin_inset Text
12678
12679 \layout Standard
12680 0x0013
12681
12682 \end_inset
12683 </cell>
12684 </row>
12685 <row topline="true">
12686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12687 \begin_inset Text
12688
12689 \layout Standard
12690 3
12691
12692 \end_inset
12693 </cell>
12694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12695 \begin_inset Text
12696
12697 \layout Standard
12698 Timer 1
12699
12700 \end_inset
12701 </cell>
12702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12703 \begin_inset Text
12704
12705 \layout Standard
12706 0x001b
12707
12708 \end_inset
12709 </cell>
12710 </row>
12711 <row topline="true">
12712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12713 \begin_inset Text
12714
12715 \layout Standard
12716 4
12717
12718 \end_inset
12719 </cell>
12720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12721 \begin_inset Text
12722
12723 \layout Standard
12724 Serial
12725
12726 \end_inset
12727 </cell>
12728 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12729 \begin_inset Text
12730
12731 \layout Standard
12732 0x0023
12733
12734 \end_inset
12735 </cell>
12736 </row>
12737 <row topline="true">
12738 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12739 \begin_inset Text
12740
12741 \layout Standard
12742 5
12743
12744 \end_inset
12745 </cell>
12746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12747 \begin_inset Text
12748
12749 \layout Standard
12750 Timer 2 (8052)
12751
12752 \end_inset
12753 </cell>
12754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12755 \begin_inset Text
12756
12757 \layout Standard
12758 0x002b
12759
12760 \end_inset
12761 </cell>
12762 </row>
12763 <row topline="true">
12764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12765 \begin_inset Text
12766
12767 \layout Standard
12768 ...
12769
12770 \end_inset
12771 </cell>
12772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12773 \begin_inset Text
12774
12775 \layout Standard
12776
12777
12778 \end_inset
12779 </cell>
12780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12781 \begin_inset Text
12782
12783 \layout Standard
12784 ...
12785
12786 \end_inset
12787 </cell>
12788 </row>
12789 <row topline="true" bottomline="true">
12790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12791 \begin_inset Text
12792
12793 \layout Standard
12794 n
12795
12796 \end_inset
12797 </cell>
12798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12799 \begin_inset Text
12800
12801 \layout Standard
12802
12803
12804 \end_inset
12805 </cell>
12806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12807 \begin_inset Text
12808
12809 \layout Standard
12810 0x0003 + 8*n
12811
12812 \end_inset
12813 </cell>
12814 </row>
12815 </lyxtabular>
12816
12817 \end_inset
12818
12819
12820 \newline
12821
12822
12823 \layout Standard
12824 If the interrupt service routine is defined without 
12825 \emph on
12826 using
12827 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12828
12829 \end_inset
12830
12831
12832 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12833
12834 \end_inset
12835
12836
12837 \emph default
12838  a register bank or with register bank 0 (
12839 \emph on
12840 using
12841 \emph default
12842  0), the compiler will save the registers used by itself on the stack upon
12843  entry and restore them at exit, however if such an interrupt service routine
12844  calls another function then the entire register bank will be saved on the
12845  stack.
12846  This scheme may be advantageous for small interrupt service routines which
12847  have low register usage.
12848
12849 \layout Standard
12850 \added_space_bottom bigskip 
12851 If the interrupt service routine is defined to be using a specific register
12852  bank then only 
12853 \emph on
12854 a, b, dptr
12855 \emph default
12856  & psw are saved and restored, if such an interrupt service routine calls
12857  another function (using another register bank) then the entire register
12858  bank of the called function will be saved on the stack
12859 \begin_inset LatexCommand \index{stack}
12860
12861 \end_inset
12862
12863 .
12864  This scheme is recommended for larger interrupt service routines.
12865
12866
12867
12868 \layout Subsection
12869 HC08
12870 \begin_inset LatexCommand \index{HC08}
12871
12872 \end_inset
12873
12874  Interrupt Service Routines
12875
12876 \layout Standard
12877 \added_space_bottom bigskip 
12878 Since the number of interrupts
12879 \begin_inset LatexCommand \index{HC08!interrupt}
12880
12881 \end_inset
12882
12883  available is chip specific and the interrupt vector table always ends at
12884  the last byte of memory, the interrupt numbers corresponds to the interrupt
12885  vectors in reverse order of address.
12886  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
12887  2 will use the interrupt vector at 0xfffa, and so on.
12888  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
12889  this way; instead see section 
12890 \begin_inset LatexCommand \ref{sub:Startup-Code}
12891
12892 \end_inset
12893
12894  for details on customizing startup.
12895
12896
12897
12898 \layout Subsection
12899 Z80 Interrupt Service Routines
12900
12901 \layout Standard
12902 The Z80
12903 \begin_inset LatexCommand \index{Z80}
12904
12905 \end_inset
12906
12907  uses several different methods for determining the correct interrupt
12908 \begin_inset LatexCommand \index{Z80!interrupt}
12909
12910 \end_inset
12911
12912  vector depending on the hardware implementation.
12913  Therefore, SDCC ignores the optional interrupt number and does not attempt
12914  to generate an interrupt vector table.
12915
12916 \layout Standard
12917 By default, SDCC generates code for a maskable interrupt, which uses a RETI
12918  instruction to return from the interrupt.
12919  To write an interrupt handler for the non-maskable interrupt, which needs
12920  a RETN instruction instead, add the 
12921 \emph on
12922 critical
12923 \emph default
12924  keyword:
12925
12926 \layout Verse
12927
12928 \family typewriter
12929 void nmi_isr (void) critical interrupt
12930 \newline
12931
12932 \newline
12933 \SpecialChar ~
12934 \SpecialChar ~
12935 \SpecialChar ~
12936 \SpecialChar ~
12937 ...
12938  
12939 \newline
12940 }
12941
12942 \layout Standard
12943 \added_space_bottom bigskip 
12944 However if you need to create a non-interruptable interrupt service routine
12945  you would also require the 
12946 \emph on
12947 critical
12948 \emph default
12949  keyword.
12950  To distinguish between this and an nmi_isr you must provide an interrupt
12951  number.
12952
12953
12954
12955 \layout Section
12956 Enabling and Disabling Interrupts
12957
12958 \layout Subsection
12959 Critical Functions and Critical Statements
12960
12961 \layout Standard
12962 A special keyword may be associated with a block or a function declaring
12963  it as 
12964 \emph on
12965 critical
12966 \emph default
12967 .
12968  SDCC will generate code to disable all interrupts
12969 \begin_inset LatexCommand \index{interrupt}
12970
12971 \end_inset
12972
12973  upon entry to a critical function and restore the interrupt enable to the
12974  previous state before returning.
12975  Nesting critical functions will need one additional byte on the stack
12976 \begin_inset LatexCommand \index{stack}
12977
12978 \end_inset
12979
12980  for each call.
12981
12982 \layout Verse
12983
12984 \family typewriter
12985 int foo () __critical
12986 \begin_inset LatexCommand \index{critical}
12987
12988 \end_inset
12989
12990
12991 \begin_inset LatexCommand \index{\_\_critical}
12992
12993 \end_inset
12994
12995  
12996 \newline
12997
12998 \newline
12999 \SpecialChar ~
13000 \SpecialChar ~
13001 \SpecialChar ~
13002 \SpecialChar ~
13003 ...
13004  
13005 \newline
13006 \SpecialChar ~
13007 \SpecialChar ~
13008 \SpecialChar ~
13009 \SpecialChar ~
13010 ...
13011  
13012 \newline
13013 }
13014
13015 \layout Standard
13016 The critical attribute maybe used with other attributes like 
13017 \emph on
13018 reentrant.
13019 \emph default
13020
13021 \newline
13022 The keyword 
13023 \emph on
13024 critical
13025 \emph default
13026  may also be used to disable interrupts more locally:
13027
13028 \layout Verse
13029
13030 \family typewriter
13031 __critical{ i++; }
13032
13033 \layout Standard
13034 More than one statement could have been included in the block.
13035
13036 \layout Subsection
13037 Enabling and Disabling Interrupts directly
13038
13039 \layout Standard
13040 Interrupts
13041 \begin_inset LatexCommand \index{interrupt}
13042
13043 \end_inset
13044
13045  can also be disabled and enabled directly (8051):
13046
13047 \layout Verse
13048
13049 \family typewriter
13050 EA = 0;\SpecialChar ~
13051 \SpecialChar ~
13052 \SpecialChar ~
13053 \SpecialChar ~
13054 \SpecialChar ~
13055 \SpecialChar ~
13056 \SpecialChar ~
13057 \SpecialChar ~
13058 \SpecialChar ~
13059 \SpecialChar ~
13060 \SpecialChar ~
13061 \SpecialChar ~
13062 or:\SpecialChar ~
13063 \SpecialChar ~
13064 \SpecialChar ~
13065 \SpecialChar ~
13066 \SpecialChar ~
13067 \SpecialChar ~
13068 \SpecialChar ~
13069 \SpecialChar ~
13070 \SpecialChar ~
13071 \SpecialChar ~
13072 \SpecialChar ~
13073 EA_SAVE = EA;
13074
13075 \layout Verse
13076
13077 \family typewriter
13078 ...\SpecialChar ~
13079 \SpecialChar ~
13080 \SpecialChar ~
13081 \SpecialChar ~
13082 \SpecialChar ~
13083 \SpecialChar ~
13084 \SpecialChar ~
13085 \SpecialChar ~
13086 \SpecialChar ~
13087 \SpecialChar ~
13088 \SpecialChar ~
13089 \SpecialChar ~
13090 \SpecialChar ~
13091 \SpecialChar ~
13092 \SpecialChar ~
13093 \SpecialChar ~
13094 \SpecialChar ~
13095 \SpecialChar ~
13096 \SpecialChar ~
13097 \SpecialChar ~
13098 \SpecialChar ~
13099 \SpecialChar ~
13100 \SpecialChar ~
13101 \SpecialChar ~
13102 \SpecialChar ~
13103 \SpecialChar ~
13104 \SpecialChar ~
13105 \SpecialChar ~
13106 \SpecialChar ~
13107 \SpecialChar ~
13108 EA = 0;
13109
13110 \layout Verse
13111
13112 \family typewriter
13113 EA = 1;\SpecialChar ~
13114 \SpecialChar ~
13115 \SpecialChar ~
13116 \SpecialChar ~
13117 \SpecialChar ~
13118 \SpecialChar ~
13119 \SpecialChar ~
13120 \SpecialChar ~
13121 \SpecialChar ~
13122 \SpecialChar ~
13123 \SpecialChar ~
13124 \SpecialChar ~
13125 \SpecialChar ~
13126 \SpecialChar ~
13127 \SpecialChar ~
13128 \SpecialChar ~
13129 \SpecialChar ~
13130 \SpecialChar ~
13131 \SpecialChar ~
13132 \SpecialChar ~
13133 \SpecialChar ~
13134 \SpecialChar ~
13135 \SpecialChar ~
13136 \SpecialChar ~
13137 \SpecialChar ~
13138 \SpecialChar ~
13139 ...
13140
13141 \layout Verse
13142
13143 \family typewriter
13144 \SpecialChar ~
13145 \SpecialChar ~
13146 \SpecialChar ~
13147 \SpecialChar ~
13148 \SpecialChar ~
13149 \SpecialChar ~
13150 \SpecialChar ~
13151 \SpecialChar ~
13152 \SpecialChar ~
13153 \SpecialChar ~
13154 \SpecialChar ~
13155 \SpecialChar ~
13156 \SpecialChar ~
13157 \SpecialChar ~
13158 \SpecialChar ~
13159 \SpecialChar ~
13160 \SpecialChar ~
13161 \SpecialChar ~
13162 \SpecialChar ~
13163 \SpecialChar ~
13164 \SpecialChar ~
13165 \SpecialChar ~
13166 \SpecialChar ~
13167 \SpecialChar ~
13168 \SpecialChar ~
13169 \SpecialChar ~
13170 \SpecialChar ~
13171 \SpecialChar ~
13172 \SpecialChar ~
13173 \SpecialChar ~
13174 \SpecialChar ~
13175 \SpecialChar ~
13176 \SpecialChar ~
13177 EA = EA_SAVE;
13178
13179 \layout Standard
13180 On other architectures which have seperate opcodes for enabling and disabling
13181  interrupts you might want to make use of defines with inline assembly
13182 \begin_inset LatexCommand \index{Assembler routines}
13183
13184 \end_inset
13185
13186  (HC08
13187 \begin_inset LatexCommand \index{HC08!interrupt}
13188
13189 \end_inset
13190
13191 ):
13192
13193 \layout Verse
13194
13195 \family typewriter
13196 #define CLI _asm
13197 \begin_inset LatexCommand \index{\_asm}
13198
13199 \end_inset
13200
13201 \SpecialChar ~
13202 \SpecialChar ~
13203 cli\SpecialChar ~
13204 \SpecialChar ~
13205 _endasm
13206 \begin_inset LatexCommand \index{\_endasm}
13207
13208 \end_inset
13209
13210
13211
13212 \layout Verse
13213
13214 \family typewriter
13215 #define SEI _asm\SpecialChar ~
13216 \SpecialChar ~
13217 sei\SpecialChar ~
13218 \SpecialChar ~
13219 _endasm; 
13220
13221 \layout Verse
13222
13223 \family typewriter
13224 ...
13225
13226 \layout Standard
13227 Note: it is sometimes sufficient to disable only a specific interrupt source
13228  like f.e.
13229  a timer or serial interrupt by manipulating an 
13230 \emph on
13231 interrupt mask
13232 \begin_inset LatexCommand \index{interrupt mask}
13233
13234 \end_inset
13235
13236
13237 \emph default
13238  register.
13239  
13240
13241 \layout Standard
13242 Usually the time during which interrupts are disabled should be kept as
13243  short as possible.
13244  This minimizes both 
13245 \emph on
13246 interrupt latency
13247 \emph default
13248
13249 \begin_inset LatexCommand \index{interrupt latency}
13250
13251 \end_inset
13252
13253  (the time between the occurrence of the interrupt and the execution of
13254  the first code in the interrupt routine) and 
13255 \emph on
13256 interrupt jitter
13257 \emph default
13258
13259 \begin_inset LatexCommand \index{interrupt jitter}
13260
13261 \end_inset
13262
13263  (the difference between the shortest and the longest interrupt latency).
13264  These really are something different, f.e.
13265  a serial interrupt has to be served before its buffer overruns so it cares
13266  for the maximum interrupt latency, whereas it does not care about jitter.
13267  On a loudspeaker driven via a digital to analog converter which is fed
13268  by an interrupt a latency of a few milliseconds might be tolerable, whereas
13269  a much smaller jitter will be very audible.
13270
13271 \layout Standard
13272 You can reenable interrupts within an interrupt routine and on some architecture
13273 s you can make use of two (or more) levels of 
13274 \emph on
13275 interrupt priorities
13276 \emph default
13277
13278 \begin_inset LatexCommand \index{interrupt priority}
13279
13280 \end_inset
13281
13282 .
13283  On some architectures which don't support interrupt priorities these can
13284  be implemented by manipulating the interrupt mask and reenabling interrupts
13285  within the interrupt routine.
13286  Check there is sufficient space on the stack
13287 \begin_inset LatexCommand \index{stack}
13288
13289 \end_inset
13290
13291  and don't add complexity unless you have to.
13292  
13293
13294 \layout Subsection
13295 Semaphore
13296 \begin_inset LatexCommand \index{semaphore}
13297
13298 \end_inset
13299
13300  locking (mcs51/ds390)
13301
13302 \layout Standard
13303 Some architectures (mcs51/ds390) have an atomic
13304 \begin_inset LatexCommand \index{atomic}
13305
13306 \end_inset
13307
13308  bit test and
13309 \emph on
13310  
13311 \emph default
13312 clear
13313 \emph on
13314  
13315 \emph default
13316 instruction.
13317  These type of instructions are typically used in preemptive multitasking
13318  systems, where a routine f.e.
13319  claims the use of a data structure ('acquires a lock
13320 \begin_inset LatexCommand \index{lock}
13321
13322 \end_inset
13323
13324  on it'), makes some modifications and then releases the lock when the data
13325  structure is consistent again.
13326  The instruction may also be used if interrupt and non-interrupt code have
13327  to compete for a resource.
13328  With the atomic bit test and clear instruction interrupts
13329 \begin_inset LatexCommand \index{interrupt}
13330
13331 \end_inset
13332
13333  don't have to be disabled for the locking operation.
13334  
13335
13336 \layout Standard
13337 SDCC generates this instruction if the source follows this pattern:
13338
13339 \layout Verse
13340
13341 \family typewriter
13342 volatile
13343 \begin_inset LatexCommand \index{volatile}
13344
13345 \end_inset
13346
13347  bit resource_is_free; 
13348 \newline
13349
13350 \newline
13351 if (resource_is_free) 
13352 \newline
13353 \SpecialChar ~
13354 \SpecialChar ~
13355
13356 \newline
13357 \SpecialChar ~
13358 \SpecialChar ~
13359 \SpecialChar ~
13360 \SpecialChar ~
13361 resource_is_free=0; 
13362 \newline
13363 \SpecialChar ~
13364 \SpecialChar ~
13365 \SpecialChar ~
13366 \SpecialChar ~
13367 ...
13368  
13369 \newline
13370 \SpecialChar ~
13371 \SpecialChar ~
13372 \SpecialChar ~
13373 \SpecialChar ~
13374 resource_is_free=1;
13375 \newline
13376 \SpecialChar ~
13377 \SpecialChar ~
13378
13379
13380 \layout Standard
13381 Note, mcs51 and ds390 support only an atomic
13382 \begin_inset LatexCommand \index{atomic}
13383
13384 \end_inset
13385
13386  bit test and 
13387 \emph on
13388 clear
13389 \emph default
13390  instruction (as opposed to atomic bit test and 
13391 \emph on
13392 set).
13393
13394 \layout Section
13395 Functions using private register banks
13396 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
13397
13398 \end_inset
13399
13400  (mcs51/ds390)
13401
13402 \layout Standard
13403 Some architectures have support for quickly changing register sets.
13404  SDCC supports this feature with the 
13405 \emph on
13406 using
13407 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13408
13409 \end_inset
13410
13411
13412 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13413
13414 \end_inset
13415
13416
13417 \emph default
13418  attribute (which tells the compiler to use a register bank
13419 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13420
13421 \end_inset
13422
13423  other than the default bank zero).
13424  It should only be applied to 
13425 \emph on
13426 interrupt
13427 \begin_inset LatexCommand \index{interrupt}
13428
13429 \end_inset
13430
13431
13432 \emph default
13433  functions (see footnote below).
13434  This will in most circumstances make the generated ISR code more efficient
13435  since it will not have to save registers on the stack.
13436
13437 \layout Standard
13438 The 
13439 \emph on
13440 using
13441 \emph default
13442  attribute will have no effect on the generated code for a 
13443 \emph on
13444 non-interrupt
13445 \emph default
13446  function (but may occasionally be useful anyway
13447 \begin_inset Foot
13448 collapsed false
13449
13450 \layout Standard
13451 possible exception: if a function is called ONLY from 'interrupt' functions
13452  using a particular bank, it can be declared with the same 'using' attribute
13453  as the calling 'interrupt' functions.
13454  For instance, if you have several ISRs using bank one, and all of them
13455  call memcpy(), it might make sense to create a specialized version of memcpy()
13456  'using 1', since this would prevent the ISR from having to save bank zero
13457  to the stack on entry and switch to bank zero before calling the function
13458
13459 \end_inset
13460
13461 ).
13462 \newline
13463
13464 \emph on
13465 (pending: Note, nowadays the 
13466 \emph default
13467 using
13468 \emph on
13469  attribute has an effect on
13470 \emph default
13471  
13472 \emph on
13473 the generated code for a 
13474 \emph default
13475 non-interrupt
13476 \emph on
13477  function
13478 \emph default
13479 .
13480 \emph on
13481 )
13482
13483 \layout Standard
13484 An 
13485 \emph on
13486 interrupt
13487 \emph default
13488  function using a non-zero bank will assume that it can trash that register
13489  bank, and will not save it.
13490  Since high-priority interrupts
13491 \begin_inset LatexCommand \index{interrupts}
13492
13493 \end_inset
13494
13495
13496 \begin_inset LatexCommand \index{interrupt priority}
13497
13498 \end_inset
13499
13500  can interrupt low-priority ones on the 8051 and friends, this means that
13501  if a high-priority ISR 
13502 \emph on
13503 using
13504 \emph default
13505  a particular bank occurs while processing a low-priority ISR 
13506 \emph on
13507 using
13508 \emph default
13509  the same bank, terrible and bad things can happen.
13510  To prevent this, no single register bank should be 
13511 \emph on
13512 used
13513 \emph default
13514  by both a high priority and a low priority ISR.
13515  This is probably most easily done by having all high priority ISRs use
13516  one bank and all low priority ISRs use another.
13517  If you have an ISR which can change priority at runtime, you're on your
13518  own: I suggest using the default bank zero and taking the small performance
13519  hit.
13520
13521 \layout Standard
13522 \added_space_bottom bigskip 
13523 It is most efficient if your ISR calls no other functions.
13524  If your ISR must call other functions, it is most efficient if those functions
13525  use the same bank as the ISR (see note 1 below); the next best is if the
13526  called functions use bank zero.
13527  It is very inefficient to call a function using a different, non-zero bank
13528  from an ISR.
13529  
13530
13531
13532
13533 \layout Section
13534 Startup Code
13535 \begin_inset LatexCommand \label{sub:Startup-Code}
13536
13537 \end_inset
13538
13539
13540 \begin_inset LatexCommand \index{Startup code}
13541
13542 \end_inset
13543
13544
13545
13546 \layout Subsection
13547 MCS51/DS390 Startup Code
13548
13549 \layout Standard
13550 The compiler inserts a call to the C routine 
13551 \emph on
13552 _sdcc_external_startup()
13553 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
13554
13555 \end_inset
13556
13557
13558 \series bold
13559 \emph default
13560  
13561 \series default
13562 at the start of the CODE area.
13563  This routine is in the runtime library
13564 \begin_inset LatexCommand \index{Runtime library}
13565
13566 \end_inset
13567
13568 .
13569  By default this routine returns 0, if this routine returns a non-zero value,
13570  the static & global variable initialization will be skipped and the function
13571  main will be invoked.
13572  Otherwise static & global variables will be initialized before the function
13573  main is invoked.
13574  You could add a 
13575 \emph on
13576 _sdcc_external_startup()
13577 \emph default
13578  routine to your program to override the default if you need to setup hardware
13579  or perform some other critical operation prior to static & global variable
13580  initialization
13581 \begin_inset LatexCommand \index{Variable initialization}
13582
13583 \end_inset
13584
13585 .
13586  On some mcs51 variants xdata
13587 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13588
13589 \end_inset
13590
13591  memory has to be explicitly enabled before it can be accessed or if the
13592  watchdog
13593 \begin_inset LatexCommand \index{watchdog}
13594
13595 \end_inset
13596
13597  needs to be disabled, this is the place to do it.
13598  The startup code clears all internal data memory, 256 bytes by default,
13599  but from 0 to n-1 if 
13600 \emph on
13601 -
13602 \begin_inset ERT
13603 status Collapsed
13604
13605 \layout Standard
13606
13607
13608 \backslash
13609 /
13610
13611 \end_inset
13612
13613 -iram-size
13614 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
13615
13616 \end_inset
13617
13618 n
13619 \emph default
13620  is used.
13621  (recommended for Chipcon CC1010).
13622
13623 \layout Standard
13624 \added_space_bottom bigskip 
13625 See also the compiler options 
13626 \emph on
13627 -
13628 \begin_inset ERT
13629 status Collapsed
13630
13631 \layout Standard
13632
13633
13634 \backslash
13635 /
13636
13637 \end_inset
13638
13639 -no-xinit
13640 \emph default
13641 -
13642 \emph on
13643 opt
13644 \emph default
13645
13646 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
13647
13648 \end_inset
13649
13650
13651 \emph on
13652 -
13653 \begin_inset ERT
13654 status Collapsed
13655
13656 \layout Standard
13657
13658
13659 \backslash
13660 /
13661
13662 \end_inset
13663
13664 -main-return
13665 \emph default
13666
13667 \begin_inset LatexCommand \index{-\/-main-return}
13668
13669 \end_inset
13670
13671  and section 
13672 \begin_inset LatexCommand \ref{sub:MCS51-variants}
13673
13674 \end_inset
13675
13676  about MCS51-variants.
13677
13678
13679
13680 \layout Subsection
13681 HC08 Startup Code
13682
13683 \layout Standard
13684 \added_space_bottom bigskip 
13685 The HC08
13686 \begin_inset LatexCommand \index{HC08}
13687
13688 \end_inset
13689
13690  startup code follows the same scheme as the MCS51 startup code.
13691
13692
13693
13694 \layout Subsection
13695 Z80 Startup Code
13696
13697 \layout Standard
13698 \added_space_bottom bigskip 
13699 On the Z80
13700 \begin_inset LatexCommand \index{Z80}
13701
13702 \end_inset
13703
13704  the startup code is inserted by linking with crt0.o which is generated from
13705  sdcc/device/lib/z80/crt0.s.
13706  If you need a different startup code you can use the compiler option 
13707 \emph on
13708 -
13709 \series bold
13710 \emph default
13711
13712 \begin_inset ERT
13713 status Collapsed
13714
13715 \layout Standard
13716
13717
13718 \backslash
13719 /
13720
13721 \end_inset
13722
13723
13724 \series default
13725 \emph on
13726 -no-std-crt0
13727 \emph default
13728
13729 \begin_inset LatexCommand \index{-\/-no-std-crt0}
13730
13731 \end_inset
13732
13733  and provide your own crt0.o.
13734  
13735
13736
13737
13738 \layout Section
13739 Inline Assembler Code
13740 \begin_inset LatexCommand \index{Assembler routines}
13741
13742 \end_inset
13743
13744
13745
13746 \layout Subsection
13747 A Step by Step Introduction
13748 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
13749
13750 \end_inset
13751
13752
13753
13754 \layout Standard
13755 Starting from a small snippet of c-code this example shows for the MCS51
13756  how to use inline assembly, access variables, a function parameter and
13757  an array in xdata memory.
13758  The example uses an MCS51 here but is easily adapted for other architectures.
13759  This is a buffer routine which should be optimized:
13760
13761 \layout Verse
13762
13763 \family typewriter
13764 \size footnotesize
13765 unsigned char __far
13766 \begin_inset LatexCommand \index{far (storage class)}
13767
13768 \end_inset
13769
13770
13771 \begin_inset LatexCommand \index{\_\_far (storage class)}
13772
13773 \end_inset
13774
13775  __at
13776 \begin_inset LatexCommand \index{at}
13777
13778 \end_inset
13779
13780
13781 \begin_inset LatexCommand \index{\_\_at}
13782
13783 \end_inset
13784
13785 (0x7f00) buf[0x100];
13786 \begin_inset LatexCommand \index{Aligned array}
13787
13788 \end_inset
13789
13790
13791 \newline
13792 unsigned char head, tail;\SpecialChar ~
13793 \SpecialChar ~
13794 \SpecialChar ~
13795 \SpecialChar ~
13796 \SpecialChar ~
13797 \SpecialChar ~
13798 \SpecialChar ~
13799 \SpecialChar ~
13800 \SpecialChar ~
13801 \SpecialChar ~
13802 \SpecialChar ~
13803 \SpecialChar ~
13804 \SpecialChar ~
13805 \SpecialChar ~
13806 \SpecialChar ~
13807 \SpecialChar ~
13808 \SpecialChar ~
13809 /* if interrupts
13810 \begin_inset LatexCommand \index{interrupt}
13811
13812 \end_inset
13813
13814  are involved see
13815 \newline
13816 \SpecialChar ~
13817 \SpecialChar ~
13818 \SpecialChar ~
13819 \SpecialChar ~
13820 \SpecialChar ~
13821 \SpecialChar ~
13822 \SpecialChar ~
13823 \SpecialChar ~
13824 \SpecialChar ~
13825 \SpecialChar ~
13826 \SpecialChar ~
13827 \SpecialChar ~
13828 \SpecialChar ~
13829 \SpecialChar ~
13830 \SpecialChar ~
13831 \SpecialChar ~
13832 \SpecialChar ~
13833 \SpecialChar ~
13834 \SpecialChar ~
13835 \SpecialChar ~
13836 \SpecialChar ~
13837 \SpecialChar ~
13838 \SpecialChar ~
13839 \SpecialChar ~
13840 \SpecialChar ~
13841 \SpecialChar ~
13842 \SpecialChar ~
13843 \SpecialChar ~
13844 \SpecialChar ~
13845 \SpecialChar ~
13846 \SpecialChar ~
13847 \SpecialChar ~
13848 \SpecialChar ~
13849 \SpecialChar ~
13850 \SpecialChar ~
13851 \SpecialChar ~
13852 \SpecialChar ~
13853 \SpecialChar ~
13854 \SpecialChar ~
13855 \SpecialChar ~
13856 \SpecialChar ~
13857 \SpecialChar ~
13858 \SpecialChar ~
13859 \SpecialChar ~
13860 \SpecialChar ~
13861 section 
13862 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
13863
13864 \end_inset
13865
13866  about
13867 \series bold
13868  volatile
13869 \series default
13870  */
13871 \newline
13872
13873 \newline
13874 void to_buffer( unsigned char c ) 
13875 \newline
13876 {
13877 \newline
13878 \SpecialChar ~
13879 \SpecialChar ~
13880 \SpecialChar ~
13881 \SpecialChar ~
13882 if( head != (unsigned char)(tail-1)
13883  )\SpecialChar ~
13884 /* cast 
13885 \series bold
13886 needed
13887 \series default
13888  to avoid promotion
13889 \begin_inset LatexCommand \index{promotion to signed int}
13890
13891 \end_inset
13892
13893
13894 \begin_inset LatexCommand \index{type promotion}
13895
13896 \end_inset
13897
13898  to integer */
13899 \begin_inset Marginal
13900 collapsed true
13901
13902 \layout Standard
13903
13904 \series bold
13905 \SpecialChar ~
13906 !
13907
13908 \end_inset
13909
13910
13911 \newline
13912 \SpecialChar ~
13913 \SpecialChar ~
13914 \SpecialChar ~
13915 \SpecialChar ~
13916 \SpecialChar ~
13917 \SpecialChar ~
13918 \SpecialChar ~
13919 \SpecialChar ~
13920 buf[ head++ ] = c;\SpecialChar ~
13921 \SpecialChar ~
13922 \SpecialChar ~
13923 \SpecialChar ~
13924 \SpecialChar ~
13925 \SpecialChar ~
13926 \SpecialChar ~
13927 \SpecialChar ~
13928 \SpecialChar ~
13929 \SpecialChar ~
13930 \SpecialChar ~
13931 \SpecialChar ~
13932 \SpecialChar ~
13933 \SpecialChar ~
13934 \SpecialChar ~
13935 \SpecialChar ~
13936 /* access to a 256 byte aligned array */
13937 \newline
13938
13939
13940 \layout Standard
13941 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
13942  then a corresponding buffer.asm file is generated.
13943  We define a new function 
13944 \family typewriter
13945 to_buffer_asm()
13946 \family default
13947  in file buffer.c in which we cut and paste the generated code, removing
13948  unwanted comments and some ':'.
13949  Then add 
13950 \begin_inset Quotes sld
13951 \end_inset
13952
13953 _asm
13954 \begin_inset Quotes srd
13955 \end_inset
13956
13957  and 
13958 \begin_inset Quotes sld
13959 \end_inset
13960
13961 _endasm;
13962 \begin_inset Quotes srd
13963 \end_inset
13964
13965  to the beginning and the end of the function body:
13966
13967 \layout Verse
13968
13969 \family typewriter
13970 \size footnotesize
13971 /* With a cut and paste from the .asm file, we have something to start with.
13972 \newline
13973 \SpecialChar ~
13974 \SpecialChar ~
13975 \SpecialChar ~
13976 The
13977  function is not yet OK! (registers aren't saved) */ 
13978 \newline
13979 void to_buffer_asm(
13980  unsigned char c ) 
13981 \newline
13982
13983 \newline
13984 \SpecialChar ~
13985 \SpecialChar ~
13986 \SpecialChar ~
13987 \SpecialChar ~
13988 _asm
13989 \begin_inset LatexCommand \index{\_asm}
13990
13991 \end_inset
13992
13993
13994 \begin_inset LatexCommand \index{\_\_asm}
13995
13996 \end_inset
13997
13998
13999 \newline
14000 \SpecialChar ~
14001 \SpecialChar ~
14002 \SpecialChar ~
14003 \SpecialChar ~
14004 mov\SpecialChar ~
14005 \SpecialChar ~
14006 r2,dpl 
14007 \newline
14008 ;buffer.c if( head != (unsigned char)(tail-1) ) \SpecialChar ~
14009 /* cast 
14010 \series bold
14011 needed
14012 \series default
14013  to avoid promotion
14014 \begin_inset LatexCommand \index{promotion to signed int}
14015
14016 \end_inset
14017
14018
14019 \begin_inset LatexCommand \index{type promotion}
14020
14021 \end_inset
14022
14023  to integer */
14024 \newline
14025 \SpecialChar ~
14026 \SpecialChar ~
14027 \SpecialChar ~
14028 \SpecialChar ~
14029 mov\SpecialChar ~
14030 \SpecialChar ~
14031 a,_tail 
14032 \newline
14033 \SpecialChar ~
14034 \SpecialChar ~
14035 \SpecialChar ~
14036 \SpecialChar ~
14037 dec\SpecialChar ~
14038 \SpecialChar ~
14039
14040 \newline
14041 \SpecialChar ~
14042 \SpecialChar ~
14043 \SpecialChar ~
14044 \SpecialChar ~
14045 mov\SpecialChar ~
14046 \SpecialChar ~
14047 r3,a 
14048 \newline
14049 \SpecialChar ~
14050 \SpecialChar ~
14051 \SpecialChar ~
14052 \SpecialChar ~
14053 mov\SpecialChar ~
14054 \SpecialChar ~
14055 a,_head 
14056 \newline
14057 \SpecialChar ~
14058 \SpecialChar ~
14059 \SpecialChar ~
14060 \SpecialChar ~
14061 cjne a,ar3,00106$ 
14062 \newline
14063 \SpecialChar ~
14064 \SpecialChar ~
14065 \SpecialChar ~
14066 \SpecialChar ~
14067 ret
14068 \newline
14069 00106$:
14070  
14071 \newline
14072 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
14073 \begin_inset LatexCommand \index{Aligned array}
14074
14075 \end_inset
14076
14077
14078 \newline
14079 \SpecialChar ~
14080 \SpecialChar ~
14081 \SpecialChar ~
14082 \SpecialChar ~
14083 mov\SpecialChar ~
14084 \SpecialChar ~
14085 r3,_head 
14086 \newline
14087 \SpecialChar ~
14088 \SpecialChar ~
14089 \SpecialChar ~
14090 \SpecialChar ~
14091 inc\SpecialChar ~
14092 \SpecialChar ~
14093 _head 
14094 \newline
14095 \SpecialChar ~
14096 \SpecialChar ~
14097 \SpecialChar ~
14098 \SpecialChar ~
14099 mov\SpecialChar ~
14100 \SpecialChar ~
14101 dpl,r3 
14102 \newline
14103 \SpecialChar ~
14104 \SpecialChar ~
14105 \SpecialChar ~
14106 \SpecialChar ~
14107 mov\SpecialChar ~
14108 \SpecialChar ~
14109 dph,#(_buf >> 8) 
14110 \newline
14111 \SpecialChar ~
14112 \SpecialChar ~
14113 \SpecialChar ~
14114 \SpecialChar ~
14115 mov\SpecialChar ~
14116 \SpecialChar ~
14117 a,r2 
14118 \newline
14119 \SpecialChar ~
14120 \SpecialChar ~
14121 \SpecialChar ~
14122 \SpecialChar ~
14123 movx @dptr,a
14124  
14125 \newline
14126 00103$: 
14127 \newline
14128 \SpecialChar ~
14129 \SpecialChar ~
14130 \SpecialChar ~
14131 \SpecialChar ~
14132 ret
14133 \newline
14134 \SpecialChar ~
14135 \SpecialChar ~
14136 \SpecialChar ~
14137 \SpecialChar ~
14138 _endasm
14139 \begin_inset LatexCommand \index{\_endasm}
14140
14141 \end_inset
14142
14143
14144 \begin_inset LatexCommand \index{\_\_endasm}
14145
14146 \end_inset
14147
14148 ;
14149 \newline
14150
14151
14152 \layout Standard
14153 The new file buffer.c should compile with only one warning about the unreferenced
14154  function argument 'c'.
14155  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
14156  (1) and finally have:
14157
14158 \layout Verse
14159
14160 \family typewriter
14161 \size footnotesize
14162 unsigned char __far __at(0x7f00) buf[0x100];
14163 \newline
14164 unsigned char head, tail;
14165 \newline
14166 #define
14167  USE_ASSEMBLY (1)
14168 \newline
14169
14170 \newline
14171 #if !USE_ASSEMBLY
14172 \newline
14173
14174 \newline
14175 void to_buffer( unsigned char c )
14176 \newline
14177 {
14178 \newline
14179 \SpecialChar ~
14180 \SpecialChar ~
14181 \SpecialChar ~
14182 \SpecialChar ~
14183 if(
14184  head != (unsigned char)(tail-1) )
14185 \newline
14186 \SpecialChar ~
14187 \SpecialChar ~
14188 \SpecialChar ~
14189 \SpecialChar ~
14190 \SpecialChar ~
14191 \SpecialChar ~
14192 \SpecialChar ~
14193 \SpecialChar ~
14194 buf[ head++ ] = c;
14195 \newline
14196 }
14197 \newline
14198
14199 \newline
14200 #else
14201 \newline
14202
14203 \newline
14204 void to_buffer(
14205  unsigned char c )
14206 \newline
14207 {
14208 \newline
14209 \SpecialChar ~
14210 \SpecialChar ~
14211 \SpecialChar ~
14212 \SpecialChar ~
14213 c; // to avoid warning: unreferenced function argument
14214 \newline
14215 \SpecialChar ~
14216 \SpecialChar ~
14217 \SpecialChar ~
14218 \SpecialChar ~
14219 _asm
14220 \begin_inset LatexCommand \index{\_asm}
14221
14222 \end_inset
14223
14224
14225 \begin_inset LatexCommand \index{\_\_asm}
14226
14227 \end_inset
14228
14229
14230 \newline
14231 \SpecialChar ~
14232 \SpecialChar ~
14233 \SpecialChar ~
14234 \SpecialChar ~
14235 \SpecialChar ~
14236 \SpecialChar ~
14237 \SpecialChar ~
14238 \SpecialChar ~
14239 ; save used registers here.
14240  
14241 \newline
14242 \SpecialChar ~
14243 \SpecialChar ~
14244 \SpecialChar ~
14245 \SpecialChar ~
14246 \SpecialChar ~
14247 \SpecialChar ~
14248 \SpecialChar ~
14249 \SpecialChar ~
14250 ; If we were still using r2,r3 we would have to push them here.
14251  
14252 \newline
14253 ; if( head != (unsigned char)(tail-1) )
14254 \newline
14255 \SpecialChar ~
14256 \SpecialChar ~
14257 \SpecialChar ~
14258 \SpecialChar ~
14259 \SpecialChar ~
14260 \SpecialChar ~
14261 \SpecialChar ~
14262 \SpecialChar ~
14263 mov\SpecialChar ~
14264  a,_tail
14265 \newline
14266 \SpecialChar ~
14267 \SpecialChar ~
14268 \SpecialChar ~
14269 \SpecialChar ~
14270 \SpecialChar ~
14271 \SpecialChar ~
14272 \SpecialChar ~
14273 \SpecialChar ~
14274 dec\SpecialChar ~
14275  a
14276 \newline
14277 \SpecialChar ~
14278 \SpecialChar ~
14279 \SpecialChar ~
14280 \SpecialChar ~
14281 \SpecialChar ~
14282 \SpecialChar ~
14283 \SpecialChar ~
14284 \SpecialChar ~
14285 xrl\SpecialChar ~
14286  a,_head
14287 \newline
14288 \SpecialChar ~
14289 \SpecialChar ~
14290 \SpecialChar ~
14291 \SpecialChar ~
14292 \SpecialChar ~
14293 \SpecialChar ~
14294 \SpecialChar ~
14295 \SpecialChar ~
14296 ; we
14297  could do an ANL a,#0x0f here to use a smaller buffer (see below)
14298 \newline
14299 \SpecialChar ~
14300 \SpecialChar ~
14301 \SpecialChar ~
14302 \SpecialChar ~
14303 \SpecialChar ~
14304 \SpecialChar ~
14305 \SpecialChar ~
14306 \SpecialChar ~
14307 jz\SpecialChar ~
14308 \SpecialChar ~
14309  t_b_end$
14310 \newline
14311 \SpecialChar ~
14312 \SpecialChar ~
14313 \SpecialChar ~
14314 \SpecialChar ~
14315 \SpecialChar ~
14316 \SpecialChar ~
14317 \SpecialChar ~
14318 \SpecialChar ~
14319 ;
14320 \newline
14321 ;
14322  buf[ head++ ] = c;
14323 \newline
14324 \SpecialChar ~
14325 \SpecialChar ~
14326 \SpecialChar ~
14327 \SpecialChar ~
14328 \SpecialChar ~
14329 \SpecialChar ~
14330 \SpecialChar ~
14331 \SpecialChar ~
14332 mov\SpecialChar ~
14333  a,dpl \SpecialChar ~
14334 \SpecialChar ~
14335 \SpecialChar ~
14336 \SpecialChar ~
14337 \SpecialChar ~
14338 \SpecialChar ~
14339 \SpecialChar ~
14340 ; dpl holds lower byte of function argument
14341 \newline
14342 \SpecialChar ~
14343 \SpecialChar ~
14344 \SpecialChar ~
14345 \SpecialChar ~
14346 \SpecialChar ~
14347 \SpecialChar ~
14348 \SpecialChar ~
14349 \SpecialChar ~
14350 mov\SpecialChar ~
14351
14352  dpl,_head \SpecialChar ~
14353 \SpecialChar ~
14354 \SpecialChar ~
14355 ; buf is 0x100 byte aligned so head can be used directly
14356 \newline
14357 \SpecialChar ~
14358 \SpecialChar ~
14359 \SpecialChar ~
14360 \SpecialChar ~
14361 \SpecialChar ~
14362 \SpecialChar ~
14363 \SpecialChar ~
14364 \SpecialChar ~
14365 mov\SpecialChar ~
14366  dph,#(_bu
14367 f>>8)
14368 \newline
14369 \SpecialChar ~
14370 \SpecialChar ~
14371 \SpecialChar ~
14372 \SpecialChar ~
14373 \SpecialChar ~
14374 \SpecialChar ~
14375 \SpecialChar ~
14376 \SpecialChar ~
14377 movx @dptr,a
14378 \newline
14379 \SpecialChar ~
14380 \SpecialChar ~
14381 \SpecialChar ~
14382 \SpecialChar ~
14383 \SpecialChar ~
14384 \SpecialChar ~
14385 \SpecialChar ~
14386 \SpecialChar ~
14387 inc \SpecialChar ~
14388 _head
14389 \newline
14390 \SpecialChar ~
14391 \SpecialChar ~
14392 \SpecialChar ~
14393 \SpecialChar ~
14394 \SpecialChar ~
14395 \SpecialChar ~
14396 \SpecialChar ~
14397 \SpecialChar ~
14398 ; we could do an ANL _head,#0x0f here to use a
14399  smaller buffer (see above)
14400 \newline
14401 t_b_end$:
14402 \newline
14403 \SpecialChar ~
14404 \SpecialChar ~
14405 \SpecialChar ~
14406 \SpecialChar ~
14407 \SpecialChar ~
14408 \SpecialChar ~
14409 \SpecialChar ~
14410 \SpecialChar ~
14411 ; restore used registers here 
14412 \newline
14413 \SpecialChar ~
14414 \SpecialChar ~
14415 \SpecialChar ~
14416 \SpecialChar ~
14417 _endasm
14418 \begin_inset LatexCommand \index{\_endasm}
14419
14420 \end_inset
14421
14422
14423 \begin_inset LatexCommand \index{\_\_endasm}
14424
14425 \end_inset
14426
14427 ;
14428 \newline
14429 }
14430 \newline
14431 #endif
14432
14433 \layout Standard
14434 The inline assembler code can contain any valid code understood by the assembler
14435 , this includes any assembler directives and comment lines.
14436  The assembler does not like some characters like ':' or ''' in comments.
14437  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
14438 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
14439
14440 \end_inset
14441
14442
14443 \begin_inset LatexCommand \index{Assembler documentation}
14444
14445 \end_inset
14446
14447  or online at 
14448 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
14449
14450 \end_inset
14451
14452 \SpecialChar ~
14453 .
14454
14455 \layout Standard
14456 The compiler does not do any validation of the code within the 
14457 \family typewriter
14458 _asm
14459 \begin_inset LatexCommand \index{\_asm}
14460
14461 \end_inset
14462
14463
14464 \begin_inset LatexCommand \index{\_\_asm}
14465
14466 \end_inset
14467
14468  ...
14469  _endasm
14470 \size footnotesize
14471
14472 \begin_inset LatexCommand \index{\_endasm}
14473
14474 \end_inset
14475
14476
14477 \begin_inset LatexCommand \index{\_\_endasm}
14478
14479 \end_inset
14480
14481
14482 \size default
14483 ;
14484 \family default
14485  keyword pair.
14486  Specifically it will not know which registers are used and thus register
14487  pushing/popping
14488 \begin_inset LatexCommand \index{push/pop}
14489
14490 \end_inset
14491
14492  has to be done manually.
14493  
14494
14495 \layout Standard
14496 It is recommended that each assembly instruction (including labels) be placed
14497  in a separate line (as the example shows).
14498  When the -
14499 \begin_inset ERT
14500 status Collapsed
14501
14502 \layout Standard
14503
14504
14505 \backslash
14506 /
14507
14508 \end_inset
14509
14510 -
14511 \emph on
14512 peep-asm
14513 \begin_inset LatexCommand \index{-\/-peep-asm}
14514
14515 \end_inset
14516
14517
14518 \emph default
14519  command line option is used, the inline assembler code will be passed through
14520  the peephole optimizer
14521 \begin_inset LatexCommand \index{Peephole optimizer}
14522
14523 \end_inset
14524
14525 .
14526  There are only a few (if any) cases where this option makes sense, it might
14527  cause some unexpected changes in the inline assembler code.
14528  Please go through the peephole optimizer rules defined in file 
14529 \emph on
14530 SDCCpeeph.def
14531 \emph default
14532  before using this option.
14533
14534 \layout Subsection
14535 Naked Functions
14536 \begin_inset LatexCommand \label{sub:Naked-Functions}
14537
14538 \end_inset
14539
14540
14541 \begin_inset LatexCommand \index{Naked functions}
14542
14543 \end_inset
14544
14545
14546
14547 \layout Standard
14548 A special keyword may be associated with a function declaring it as 
14549 \emph on
14550 _naked
14551 \begin_inset LatexCommand \index{\_naked}
14552
14553 \end_inset
14554
14555
14556 \begin_inset LatexCommand \index{\_\_naked}
14557
14558 \end_inset
14559
14560 .
14561  
14562 \emph default
14563 The 
14564 \emph on
14565 _naked
14566 \emph default
14567  function modifier attribute prevents the compiler from generating prologue
14568 \begin_inset LatexCommand \index{function prologue}
14569
14570 \end_inset
14571
14572  and epilogue
14573 \begin_inset LatexCommand \index{function epilogue}
14574
14575 \end_inset
14576
14577  code for that function.
14578  This means that the user is entirely responsible for such things as saving
14579  any registers that may need to be preserved, selecting the proper register
14580  bank, generating the 
14581 \emph on
14582 return
14583 \emph default
14584  instruction at the end, etc.
14585  Practically, this means that the contents of the function must be written
14586  in inline assembler.
14587  This is particularly useful for interrupt functions, which can have a large
14588  (and often unnecessary) prologue/epilogue.
14589  For example, compare the code generated by these two functions:
14590
14591 \layout Verse
14592
14593 \family typewriter
14594 volatile
14595 \begin_inset LatexCommand \index{volatile}
14596
14597 \end_inset
14598
14599  data unsigned char counter;
14600 \newline
14601
14602 \newline
14603 void simpleInterrupt(void) __interrupt
14604 \begin_inset LatexCommand \index{interrupt}
14605
14606 \end_inset
14607
14608
14609 \begin_inset LatexCommand \index{\_\_interrupt}
14610
14611 \end_inset
14612
14613  (1)
14614 \newline
14615 {
14616 \newline
14617 \SpecialChar ~
14618 \SpecialChar ~
14619 \SpecialChar ~
14620 \SpecialChar ~
14621 counter++;
14622 \newline
14623 }
14624 \newline
14625
14626 \newline
14627 void nakedInterrupt(void) __interrupt (2) __naked
14628 \newline
14629 {
14630 \newline
14631 \SpecialChar ~
14632 \SpecialChar ~
14633 \SpecialChar ~
14634 \SpecialChar ~
14635 _asm
14636 \begin_inset LatexCommand \index{\_asm}
14637
14638 \end_inset
14639
14640
14641 \begin_inset LatexCommand \index{\_\_asm}
14642
14643 \end_inset
14644
14645
14646 \newline
14647 \SpecialChar ~
14648 \SpecialChar ~
14649 \SpecialChar ~
14650 \SpecialChar ~
14651 \SpecialChar ~
14652 \SpecialChar ~
14653 inc\SpecialChar ~
14654 \SpecialChar ~
14655 \SpecialChar ~
14656 \SpecialChar ~
14657 \SpecialChar ~
14658 _counter ; does not change flags, no need to save psw
14659 \newline
14660 \SpecialChar ~
14661 \SpecialChar ~
14662 \SpecialChar ~
14663 \SpecialChar ~
14664 \SpecialChar ~
14665 \SpecialChar ~
14666 reti\SpecialChar ~
14667 \SpecialChar ~
14668 \SpecialChar ~
14669 \SpecialChar ~
14670 ; MUST explicitly
14671  include ret or reti in _naked function.
14672 \newline
14673 \SpecialChar ~
14674 \SpecialChar ~
14675 \SpecialChar ~
14676 \SpecialChar ~
14677 _endasm
14678 \begin_inset LatexCommand \index{\_endasm}
14679
14680 \end_inset
14681
14682
14683 \begin_inset LatexCommand \index{\_\_endasm}
14684
14685 \end_inset
14686
14687 ;
14688 \newline
14689 }
14690
14691 \layout Standard
14692 For an 8051 target, the generated simpleInterrupt looks like:
14693
14694 \layout Verse
14695
14696 \family typewriter
14697 Note, this is an 
14698 \emph on
14699 outdated
14700 \emph default
14701  example, recent versions of SDCC generate
14702 \newline
14703 the 
14704 \emph on
14705 same
14706 \emph default
14707  code for simpleInterrupt() and nakedInterrupt()!
14708 \newline
14709
14710 \newline
14711 _simpleInterrupt:
14712 \newline
14713 \SpecialChar ~
14714 \SpecialChar ~
14715 \SpecialChar ~
14716 \SpecialChar ~
14717 push\SpecialChar ~
14718 \SpecialChar ~
14719 \SpecialChar ~
14720 \SpecialChar ~
14721 acc
14722 \newline
14723 \SpecialChar ~
14724 \SpecialChar ~
14725 \SpecialChar ~
14726 \SpecialChar ~
14727 push\SpecialChar ~
14728 \SpecialChar ~
14729 \SpecialChar ~
14730 \SpecialChar ~
14731 b
14732 \newline
14733 \SpecialChar ~
14734 \SpecialChar ~
14735 \SpecialChar ~
14736 \SpecialChar ~
14737 pu
14738 sh\SpecialChar ~
14739 \SpecialChar ~
14740 \SpecialChar ~
14741 \SpecialChar ~
14742 dpl
14743 \newline
14744 \SpecialChar ~
14745 \SpecialChar ~
14746 \SpecialChar ~
14747 \SpecialChar ~
14748 push\SpecialChar ~
14749 \SpecialChar ~
14750 \SpecialChar ~
14751 \SpecialChar ~
14752 dph
14753 \newline
14754 \SpecialChar ~
14755 \SpecialChar ~
14756 \SpecialChar ~
14757 \SpecialChar ~
14758 push\SpecialChar ~
14759 \SpecialChar ~
14760 \SpecialChar ~
14761 \SpecialChar ~
14762 psw
14763 \newline
14764 \SpecialChar ~
14765 \SpecialChar ~
14766 \SpecialChar ~
14767 \SpecialChar ~
14768 mov\SpecialChar ~
14769 \SpecialChar ~
14770 \SpecialChar ~
14771 \SpecialChar ~
14772 \SpecialChar ~
14773 psw,#0x00
14774 \newline
14775 \SpecialChar ~
14776 \SpecialChar ~
14777 \SpecialChar ~
14778 \SpecialChar ~
14779 inc\SpecialChar ~
14780 \SpecialChar ~
14781 \SpecialChar ~
14782 \SpecialChar ~
14783 \SpecialChar ~
14784 _counter
14785 \newline
14786 \SpecialChar ~
14787 \SpecialChar ~
14788 \SpecialChar ~
14789 \SpecialChar ~
14790 pop\SpecialChar ~
14791 \SpecialChar ~
14792 \SpecialChar ~
14793 \SpecialChar ~
14794 \SpecialChar ~
14795 psw
14796 \newline
14797 \SpecialChar ~
14798 \SpecialChar ~
14799 \SpecialChar ~
14800 \SpecialChar ~
14801 pop\SpecialChar ~
14802 \SpecialChar ~
14803 \SpecialChar ~
14804 \SpecialChar ~
14805 \SpecialChar ~
14806 dph
14807 \newline
14808 \SpecialChar ~
14809 \SpecialChar ~
14810 \SpecialChar ~
14811 \SpecialChar ~
14812 pop\SpecialChar ~
14813 \SpecialChar ~
14814 \SpecialChar ~
14815 \SpecialChar ~
14816 \SpecialChar ~
14817 dpl
14818 \newline
14819 \SpecialChar ~
14820 \SpecialChar ~
14821 \SpecialChar ~
14822 \SpecialChar ~
14823 pop\SpecialChar ~
14824 \SpecialChar ~
14825 \SpecialChar ~
14826 \SpecialChar ~
14827 \SpecialChar ~
14828 b
14829 \newline
14830 \SpecialChar ~
14831 \SpecialChar ~
14832 \SpecialChar ~
14833 \SpecialChar ~
14834 pop\SpecialChar ~
14835 \SpecialChar ~
14836 \SpecialChar ~
14837 \SpecialChar ~
14838 \SpecialChar ~
14839 acc
14840 \newline
14841 \SpecialChar ~
14842 \SpecialChar ~
14843 \SpecialChar ~
14844 \SpecialChar ~
14845 reti
14846
14847 \layout Standard
14848 whereas nakedInterrupt looks like:
14849
14850 \layout Verse
14851
14852 \family typewriter
14853 _nakedInterrupt:
14854 \newline
14855 \SpecialChar ~
14856 \SpecialChar ~
14857 \SpecialChar ~
14858 \SpecialChar ~
14859 inc\SpecialChar ~
14860 \SpecialChar ~
14861 \SpecialChar ~
14862 \SpecialChar ~
14863 _counter ; does not change flags, no need to save psw
14864 \newline
14865 \SpecialChar ~
14866 \SpecialChar ~
14867 \SpecialChar ~
14868 \SpecialChar ~
14869 reti\SpecialChar ~
14870 \SpecialChar ~
14871 \SpecialChar ~
14872 \SpecialChar ~
14873 \SpecialChar ~
14874 \SpecialChar ~
14875 \SpecialChar ~
14876 \SpecialChar ~
14877 \SpecialChar ~
14878 \SpecialChar ~
14879 \SpecialChar ~
14880 \SpecialChar ~
14881 ;
14882  MUST explicitly include ret or reti in _naked function
14883
14884 \layout Standard
14885 The related directive #pragma exclude
14886 \begin_inset LatexCommand \index{\#pragma exclude}
14887
14888 \end_inset
14889
14890  allows a more fine grained control over pushing & popping
14891 \begin_inset LatexCommand \index{push/pop}
14892
14893 \end_inset
14894
14895  the registers.
14896
14897 \layout Standard
14898 While there is nothing preventing you from writing C code inside a 
14899 \family typewriter
14900 _naked
14901 \family default
14902  function, there are many ways to shoot yourself in the foot doing this,
14903  and it is recommended that you stick to inline assembler.
14904
14905 \layout Subsection
14906 Use of Labels within Inline Assembler
14907
14908 \layout Standard
14909 SDCC allows the use of in-line assembler with a few restrictions regarding
14910  labels.
14911  In older versions of the compiler all labels defined within inline assembler
14912  code 
14913 \emph on
14914 had to be
14915 \emph default
14916  of the form 
14917 \emph on
14918 nnnnn$
14919 \emph default
14920  where nnnn is a number less than 100 (which implies a limit of utmost 100
14921  inline assembler labels 
14922 \emph on
14923 per function
14924 \emph default
14925 \noun on
14926 )
14927 \noun default
14928 .
14929  
14930
14931 \layout Verse
14932
14933 \family typewriter
14934 _asm
14935 \begin_inset LatexCommand \index{\_asm}
14936
14937 \end_inset
14938
14939
14940 \begin_inset LatexCommand \index{\_\_asm}
14941
14942 \end_inset
14943
14944  
14945 \newline
14946 \SpecialChar ~
14947 \SpecialChar ~
14948 \SpecialChar ~
14949 \SpecialChar ~
14950 mov\SpecialChar ~
14951 \SpecialChar ~
14952 \SpecialChar ~
14953 \SpecialChar ~
14954 \SpecialChar ~
14955 b,#10 
14956 \newline
14957 00001$: 
14958 \newline
14959 \SpecialChar ~
14960 \SpecialChar ~
14961 \SpecialChar ~
14962 \SpecialChar ~
14963 djnz\SpecialChar ~
14964 \SpecialChar ~
14965 \SpecialChar ~
14966 \SpecialChar ~
14967 b,00001$ 
14968 \newline
14969 _endasm
14970 \begin_inset LatexCommand \index{\_endasm}
14971
14972 \end_inset
14973
14974
14975 \begin_inset LatexCommand \index{\_\_endasm}
14976
14977 \end_inset
14978
14979  ;
14980
14981 \layout Standard
14982 Inline assembler code cannot reference any C-Labels, however it can reference
14983  labels
14984 \begin_inset LatexCommand \index{Labels}
14985
14986 \end_inset
14987
14988  defined by the inline assembler, e.g.:
14989
14990 \layout Verse
14991
14992 \family typewriter
14993 foo() { 
14994 \newline
14995 \SpecialChar ~
14996 \SpecialChar ~
14997 \SpecialChar ~
14998 \SpecialChar ~
14999 /* some c code */ 
15000 \newline
15001 \SpecialChar ~
15002 \SpecialChar ~
15003 \SpecialChar ~
15004 \SpecialChar ~
15005 _asm 
15006 \newline
15007 \SpecialChar ~
15008 \SpecialChar ~
15009 \SpecialChar ~
15010 \SpecialChar ~
15011 \SpecialChar ~
15012 \SpecialChar ~
15013 ; some assembler code 
15014 \newline
15015 \SpecialChar ~
15016 \SpecialChar ~
15017 \SpecialChar ~
15018 \SpecialChar ~
15019 \SpecialChar ~
15020 \SpecialChar ~
15021 ljmp $0003 
15022 \newline
15023 \SpecialChar ~
15024 \SpecialChar ~
15025 \SpecialChar ~
15026 \SpecialChar ~
15027 _endasm;
15028  
15029 \newline
15030 \SpecialChar ~
15031 \SpecialChar ~
15032 \SpecialChar ~
15033 \SpecialChar ~
15034 /* some more c code */ 
15035 \newline
15036 clabel:\SpecialChar ~
15037 \SpecialChar ~
15038 /* inline assembler cannot reference this
15039  label */ 
15040 \newline
15041 \SpecialChar ~
15042 \SpecialChar ~
15043 \SpecialChar ~
15044 \SpecialChar ~
15045 _asm
15046 \newline
15047 \SpecialChar ~
15048 \SpecialChar ~
15049 \SpecialChar ~
15050 \SpecialChar ~
15051 $0003: ;label (can be referenced by inline assembler only)
15052  
15053 \newline
15054 \SpecialChar ~
15055 \SpecialChar ~
15056 \SpecialChar ~
15057 \SpecialChar ~
15058 _endasm
15059 \begin_inset LatexCommand \index{\_endasm}
15060
15061 \end_inset
15062
15063
15064 \begin_inset LatexCommand \index{\_\_endasm}
15065
15066 \end_inset
15067
15068  ; 
15069 \newline
15070 \SpecialChar ~
15071 \SpecialChar ~
15072 \SpecialChar ~
15073 \SpecialChar ~
15074 /* some more c code */
15075 \newline
15076 }
15077
15078 \layout Standard
15079 In other words inline assembly code can access labels defined in inline
15080  assembly within the scope of the function.
15081  The same goes the other way, i.e.
15082  labels defines in inline assembly can not be accessed by C statements.
15083
15084 \layout Section
15085 Interfacing with Assembler Code
15086 \begin_inset LatexCommand \index{Assembler routines}
15087
15088 \end_inset
15089
15090
15091
15092 \layout Subsection
15093 Global Registers used for Parameter Passing
15094 \begin_inset LatexCommand \index{Parameter passing}
15095
15096 \end_inset
15097
15098
15099
15100 \layout Standard
15101 The compiler always uses the global registers 
15102 \emph on
15103 DPL, DPH
15104 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
15105
15106 \end_inset
15107
15108
15109 \begin_inset LatexCommand \index{DPTR}
15110
15111 \end_inset
15112
15113 , B
15114 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
15115
15116 \end_inset
15117
15118  
15119 \emph default
15120 and
15121 \emph on
15122  ACC
15123 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
15124
15125 \end_inset
15126
15127
15128 \emph default
15129  to pass the first parameter to a routine.
15130  The second parameter onwards is either allocated on the stack (for reentrant
15131  routines or if -
15132 \begin_inset ERT
15133 status Collapsed
15134
15135 \layout Standard
15136
15137
15138 \backslash
15139 /
15140
15141 \end_inset
15142
15143 -stack-auto is used) or in data / xdata memory (depending on the memory
15144  model).
15145  
15146
15147 \layout Subsection
15148 Assembler Routine (non-reentrant)
15149
15150 \layout Standard
15151 In the following example
15152 \begin_inset LatexCommand \index{reentrant}
15153
15154 \end_inset
15155
15156
15157 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
15158
15159 \end_inset
15160
15161  the function c_func calls an assembler routine asm_func, which takes two
15162  parameters
15163 \begin_inset LatexCommand \index{function parameter}
15164
15165 \end_inset
15166
15167 .
15168
15169 \layout Verse
15170
15171 \family typewriter
15172 extern int asm_func(unsigned char, unsigned char);
15173 \newline
15174
15175 \newline
15176 int c_func (unsigned char
15177  i, unsigned char j)
15178 \newline
15179 {
15180 \newline
15181 \SpecialChar ~
15182 \SpecialChar ~
15183 \SpecialChar ~
15184 \SpecialChar ~
15185 return asm_func(i,j);
15186 \newline
15187 }
15188 \newline
15189
15190 \newline
15191 int main()
15192 \newline
15193 {
15194 \newline
15195 \SpecialChar ~
15196 \SpecialChar ~
15197 \SpecialChar ~
15198 \SpecialChar ~
15199 return c_func(10,9);
15200 \newline
15201 }
15202
15203 \layout Standard
15204 The corresponding assembler function is:
15205
15206 \layout Verse
15207
15208 \family typewriter
15209 .globl _asm_func_PARM_2 
15210 \newline
15211 \SpecialChar ~
15212 \SpecialChar ~
15213 \SpecialChar ~
15214 \SpecialChar ~
15215 \SpecialChar ~
15216 \SpecialChar ~
15217 \SpecialChar ~
15218 \SpecialChar ~
15219 .globl _asm_func 
15220 \newline
15221 \SpecialChar ~
15222 \SpecialChar ~
15223 \SpecialChar ~
15224 \SpecialChar ~
15225 \SpecialChar ~
15226 \SpecialChar ~
15227 \SpecialChar ~
15228 \SpecialChar ~
15229 .area OSEG 
15230 \newline
15231 _asm_func_PARM_2:
15232 \newline
15233 \SpecialChar ~
15234 \SpecialChar ~
15235 \SpecialChar ~
15236 \SpecialChar ~
15237 \SpecialChar ~
15238 \SpecialChar ~
15239 \SpecialChar ~
15240 \SpecialChar ~
15241 .ds   
15242  1 
15243 \newline
15244 \SpecialChar ~
15245 \SpecialChar ~
15246 \SpecialChar ~
15247 \SpecialChar ~
15248 \SpecialChar ~
15249 \SpecialChar ~
15250 \SpecialChar ~
15251 \SpecialChar ~
15252 .area CSEG 
15253 \newline
15254 _asm_func: 
15255 \newline
15256 \SpecialChar ~
15257 \SpecialChar ~
15258 \SpecialChar ~
15259 \SpecialChar ~
15260 \SpecialChar ~
15261 \SpecialChar ~
15262 \SpecialChar ~
15263 \SpecialChar ~
15264 mov\SpecialChar ~
15265 \SpecialChar ~
15266 \SpecialChar ~
15267 \SpecialChar ~
15268 a,dpl 
15269 \newline
15270 \SpecialChar ~
15271 \SpecialChar ~
15272 \SpecialChar ~
15273 \SpecialChar ~
15274 \SpecialChar ~
15275 \SpecialChar ~
15276 \SpecialChar ~
15277 \SpecialChar ~
15278 add\SpecialChar ~
15279 \SpecialChar ~
15280 \SpecialChar ~
15281 \SpecialChar ~
15282 a,_asm_func_PARM_2 
15283 \newline
15284 \SpecialChar ~
15285 \SpecialChar ~
15286 \SpecialChar ~
15287 \SpecialChar ~
15288 \SpecialChar ~
15289 \SpecialChar ~
15290 \SpecialChar ~
15291 \SpecialChar ~
15292 mov\SpecialChar ~
15293 \SpecialChar ~
15294 \SpecialChar ~
15295 \SpecialChar ~
15296 dpl,a 
15297 \newline
15298 \SpecialChar ~
15299 \SpecialChar ~
15300 \SpecialChar ~
15301 \SpecialChar ~
15302 \SpecialChar ~
15303 \SpecialChar ~
15304 \SpecialChar ~
15305 \SpecialChar ~
15306 mov\SpecialChar ~
15307 \SpecialChar ~
15308 \SpecialChar ~
15309 \SpecialChar ~
15310 dph
15311 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
15312
15313 \end_inset
15314
15315 ,#0x00 
15316 \newline
15317 \SpecialChar ~
15318 \SpecialChar ~
15319 \SpecialChar ~
15320 \SpecialChar ~
15321 \SpecialChar ~
15322 \SpecialChar ~
15323 \SpecialChar ~
15324 \SpecialChar ~
15325 ret
15326
15327 \layout Standard
15328 Note here that the return values
15329 \begin_inset LatexCommand \index{return value}
15330
15331 \end_inset
15332
15333  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
15334  two byte values.
15335  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
15336 b' & 'acc' for four byte values.
15337
15338 \layout Standard
15339 The parameter naming convention is _<function_name>_PARM_<n>, where n is
15340  the parameter number starting from 1, and counting from the left.
15341  The first parameter is passed in 
15342 \begin_inset Quotes eld
15343 \end_inset
15344
15345 dpl
15346 \begin_inset Quotes erd
15347 \end_inset
15348
15349  for a one byte parameter, 
15350 \begin_inset Quotes eld
15351 \end_inset
15352
15353 dptr
15354 \begin_inset Quotes erd
15355 \end_inset
15356
15357  for two bytes, 
15358 \begin_inset Quotes eld
15359 \end_inset
15360
15361 b,dptr
15362 \begin_inset Quotes erd
15363 \end_inset
15364
15365  for three bytes and 
15366 \begin_inset Quotes eld
15367 \end_inset
15368
15369 acc,b,dptr
15370 \begin_inset Quotes erd
15371 \end_inset
15372
15373  for a four bytes parameter.
15374  The variable name for the second parameter will be _<function_name>_PARM_2.
15375 \newline
15376
15377 \newline
15378 Assem
15379 ble the assembler routine with the following command:
15380 \newline
15381
15382 \newline
15383
15384 \family sans
15385 \series bold
15386 asx8051 -losg asmfunc.asm
15387 \newline
15388
15389 \newline
15390
15391 \family default
15392 \series default
15393 Then compile and link the assembler routine to the C source file with the
15394  following command:
15395 \newline
15396
15397 \newline
15398
15399 \family sans
15400 \series bold
15401 sdcc cfunc.c asmfunc.rel
15402
15403 \layout Subsection
15404 Assembler Routine (reentrant)
15405
15406 \layout Standard
15407 In this case
15408 \begin_inset LatexCommand \index{reentrant}
15409
15410 \end_inset
15411
15412
15413 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
15414
15415 \end_inset
15416
15417  the second parameter
15418 \begin_inset LatexCommand \index{function parameter}
15419
15420 \end_inset
15421
15422  onwards will be passed on the stack, the parameters are pushed from right
15423  to left i.e.
15424  after the call the leftmost parameter will be on the top of the stack.
15425  Here is an example:
15426
15427 \layout Verse
15428
15429 \family typewriter
15430 extern int asm_func(unsigned char, unsigned char);
15431 \newline
15432
15433 \newline
15434 int c_func (unsigned char
15435  i, unsigned char j) reentrant 
15436 \newline
15437
15438 \newline
15439 \SpecialChar ~
15440 \SpecialChar ~
15441 \SpecialChar ~
15442 \SpecialChar ~
15443 return asm_func(i,j); 
15444 \newline
15445
15446 \newline
15447
15448 \newline
15449 int main() 
15450 \newline
15451
15452 \newline
15453 \SpecialChar ~
15454 \SpecialChar ~
15455 \SpecialChar ~
15456 \SpecialChar ~
15457 return
15458  c_func(10,9); 
15459 \newline
15460 }
15461
15462 \layout Standard
15463 The corresponding assembler routine is:
15464
15465 \layout Verse
15466
15467 \family typewriter
15468 .globl _asm_func 
15469 \newline
15470 _asm_func: 
15471 \newline
15472 \SpecialChar ~
15473 \SpecialChar ~
15474 \SpecialChar ~
15475 \SpecialChar ~
15476 push  _bp 
15477 \newline
15478 \SpecialChar ~
15479 \SpecialChar ~
15480 \SpecialChar ~
15481 \SpecialChar ~
15482 mov _bp,sp 
15483 \newline
15484 \SpecialChar ~
15485 \SpecialChar ~
15486 \SpecialChar ~
15487 \SpecialChar ~
15488 mov r2,dpl
15489 \newline
15490 \SpecialChar ~
15491 \SpecialChar ~
15492 \SpecialChar ~
15493 \SpecialChar ~
15494 mov a,_bp 
15495 \newline
15496 \SpecialChar ~
15497 \SpecialChar ~
15498 \SpecialChar ~
15499 \SpecialChar ~
15500 add
15501  a,#0xfd 
15502 \newline
15503 \SpecialChar ~
15504 \SpecialChar ~
15505 \SpecialChar ~
15506 \SpecialChar ~
15507 mov r0,a 
15508 \newline
15509 \SpecialChar ~
15510 \SpecialChar ~
15511 \SpecialChar ~
15512 \SpecialChar ~
15513 add  a,#0xfc ;?
15514 \newline
15515 \SpecialChar ~
15516 \SpecialChar ~
15517 \SpecialChar ~
15518 \SpecialChar ~
15519 mov  r1,a 
15520 \newline
15521 \SpecialChar ~
15522 \SpecialChar ~
15523 \SpecialChar ~
15524 \SpecialChar ~
15525 mov  a,@r0 
15526 \newline
15527 \SpecialChar ~
15528 \SpecialChar ~
15529 \SpecialChar ~
15530 \SpecialChar ~
15531 add  a,r2 ;?
15532 \newline
15533 \SpecialChar ~
15534 \SpecialChar ~
15535 \SpecialChar ~
15536 \SpecialChar ~
15537 mov  dpl,a
15538  
15539 \newline
15540 \SpecialChar ~
15541 \SpecialChar ~
15542 \SpecialChar ~
15543 \SpecialChar ~
15544 mov  dph,#0x00 
15545 \newline
15546 \SpecialChar ~
15547 \SpecialChar ~
15548 \SpecialChar ~
15549 \SpecialChar ~
15550 mov  sp,_bp 
15551 \newline
15552 \SpecialChar ~
15553 \SpecialChar ~
15554 \SpecialChar ~
15555 \SpecialChar ~
15556 pop  _bp 
15557 \newline
15558 \SpecialChar ~
15559 \SpecialChar ~
15560 \SpecialChar ~
15561 \SpecialChar ~
15562 ret
15563
15564 \layout Standard
15565 \added_space_bottom bigskip 
15566 The compiling and linking procedure remains the same, however note the extra
15567  entry & exit linkage required for the assembler code, _bp is the stack
15568  frame pointer and is used to compute the offset into the stack for parameters
15569  and local variables.
15570
15571
15572
15573 \layout Section
15574 int (16 bit)
15575 \begin_inset LatexCommand \index{int (16 bit)}
15576
15577 \end_inset
15578
15579  and long (32 bit)
15580 \begin_inset LatexCommand \index{long (32 bit)}
15581
15582 \end_inset
15583
15584  Support
15585
15586 \layout Standard
15587 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
15588  multiplication and modulus operations are implemented by support routines.
15589  These support routines are all developed in ANSI-C to facilitate porting
15590  to other MCUs, although some model specific assembler optimizations are
15591  used.
15592  The following files contain the described routines, all of them can be
15593  found in <installdir>/share/sdcc/lib.
15594 \newline
15595
15596
15597 \layout Standard
15598 \align center
15599 \begin_inset Tabular
15600 <lyxtabular version="3" rows="11" columns="2">
15601 <features>
15602 <column alignment="left" valignment="top" leftline="true" width="0">
15603 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
15604 <row topline="true" bottomline="true">
15605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15606 \begin_inset Text
15607
15608 \layout Standard
15609
15610 \series bold
15611 Function
15612
15613 \end_inset
15614 </cell>
15615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15616 \begin_inset Text
15617
15618 \layout Standard
15619
15620 \series bold
15621 Description
15622
15623 \end_inset
15624 </cell>
15625 </row>
15626 <row topline="true">
15627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15628 \begin_inset Text
15629
15630 \layout Standard
15631 _mulint.c 
15632
15633 \end_inset
15634 </cell>
15635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15636 \begin_inset Text
15637
15638 \layout Standard
15639 16 bit multiplication
15640
15641 \end_inset
15642 </cell>
15643 </row>
15644 <row topline="true">
15645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15646 \begin_inset Text
15647
15648 \layout Standard
15649 _divsint.c 
15650
15651 \end_inset
15652 </cell>
15653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15654 \begin_inset Text
15655
15656 \layout Standard
15657  signed 16 bit division (calls _divuint)
15658
15659 \end_inset
15660 </cell>
15661 </row>
15662 <row topline="true">
15663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15664 \begin_inset Text
15665
15666 \layout Standard
15667 _divuint.c 
15668
15669 \end_inset
15670 </cell>
15671 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15672 \begin_inset Text
15673
15674 \layout Standard
15675  unsigned 16 bit division
15676
15677 \end_inset
15678 </cell>
15679 </row>
15680 <row topline="true">
15681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15682 \begin_inset Text
15683
15684 \layout Standard
15685 _modsint.c
15686
15687 \end_inset
15688 </cell>
15689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15690 \begin_inset Text
15691
15692 \layout Standard
15693 signed 16 bit modulus (calls _moduint)
15694
15695 \end_inset
15696 </cell>
15697 </row>
15698 <row topline="true">
15699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15700 \begin_inset Text
15701
15702 \layout Standard
15703 _moduint.c
15704
15705 \end_inset
15706 </cell>
15707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15708 \begin_inset Text
15709
15710 \layout Standard
15711 unsigned 16 bit modulus
15712
15713 \end_inset
15714 </cell>
15715 </row>
15716 <row topline="true">
15717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15718 \begin_inset Text
15719
15720 \layout Standard
15721 _mullong.c
15722
15723 \end_inset
15724 </cell>
15725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15726 \begin_inset Text
15727
15728 \layout Standard
15729 32 bit multiplication
15730
15731 \end_inset
15732 </cell>
15733 </row>
15734 <row topline="true">
15735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15736 \begin_inset Text
15737
15738 \layout Standard
15739 _divslong.c 
15740
15741 \end_inset
15742 </cell>
15743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15744 \begin_inset Text
15745
15746 \layout Standard
15747  signed 32 division (calls _divulong)
15748
15749 \end_inset
15750 </cell>
15751 </row>
15752 <row topline="true">
15753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15754 \begin_inset Text
15755
15756 \layout Standard
15757 _divulong.c 
15758
15759 \end_inset
15760 </cell>
15761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15762 \begin_inset Text
15763
15764 \layout Standard
15765 unsigned 32 division
15766
15767 \end_inset
15768 </cell>
15769 </row>
15770 <row topline="true">
15771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15772 \begin_inset Text
15773
15774 \layout Standard
15775 _modslong.c
15776
15777 \end_inset
15778 </cell>
15779 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15780 \begin_inset Text
15781
15782 \layout Standard
15783  signed 32 bit modulus (calls _modulong)
15784
15785 \end_inset
15786 </cell>
15787 </row>
15788 <row topline="true" bottomline="true">
15789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15790 \begin_inset Text
15791
15792 \layout Standard
15793 _modulong.c
15794
15795 \end_inset
15796 </cell>
15797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15798 \begin_inset Text
15799
15800 \layout Standard
15801 unsigned 32 bit modulus
15802
15803 \end_inset
15804 </cell>
15805 </row>
15806 </lyxtabular>
15807
15808 \end_inset
15809
15810
15811 \newline
15812
15813
15814 \layout Standard
15815 Since they are compiled as 
15816 \emph on
15817 non-reentrant
15818 \emph default
15819
15820 \begin_inset LatexCommand \index{reentrant}
15821
15822 \end_inset
15823
15824 , interrupt
15825 \begin_inset LatexCommand \index{interrupt}
15826
15827 \end_inset
15828
15829  service routines should not do any of the above operations.
15830  If this is unavoidable then the above routines will need to be compiled
15831  with the 
15832 \emph on
15833 -
15834 \begin_inset ERT
15835 status Collapsed
15836
15837 \layout Standard
15838
15839
15840 \backslash
15841 /
15842
15843 \end_inset
15844
15845 -stack-auto
15846 \begin_inset LatexCommand \index{-\/-stack-auto}
15847
15848 \end_inset
15849
15850
15851 \emph default
15852  option, after which the source program will have to be compiled with 
15853 \emph on
15854 -
15855 \begin_inset ERT
15856 status Collapsed
15857
15858 \layout Standard
15859
15860
15861 \backslash
15862 /
15863
15864 \end_inset
15865
15866 -int-long-reent
15867 \begin_inset LatexCommand \index{-\/-int-long-reent}
15868
15869 \end_inset
15870
15871
15872 \emph default
15873  option.
15874  Notice that you don't have to call these routines directly.
15875  The compiler will use them automatically every time an integer operation
15876  is required.
15877
15878 \layout Section
15879 Floating Point Support
15880 \begin_inset LatexCommand \index{Floating point support}
15881
15882 \end_inset
15883
15884
15885
15886 \layout Standard
15887 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
15888  The floating point support routines are derived from gcc's floatlib.c and
15889  consist of the following routines:
15890 \newline
15891
15892
15893 \layout Standard
15894 \align center
15895
15896 \size footnotesize
15897 \begin_inset Tabular
15898 <lyxtabular version="3" rows="17" columns="2">
15899 <features>
15900 <column alignment="left" valignment="top" leftline="true" width="0">
15901 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
15902 <row topline="true" bottomline="true">
15903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15904 \begin_inset Text
15905
15906 \layout Standard
15907
15908 \family roman
15909 \series medium
15910 \shape up
15911 \size normal
15912 \emph off
15913 \bar no
15914 \noun off
15915 \color none
15916 Function 
15917
15918 \end_inset
15919 </cell>
15920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15921 \begin_inset Text
15922
15923 \layout Standard
15924 Description
15925
15926 \end_inset
15927 </cell>
15928 </row>
15929 <row topline="true">
15930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15931 \begin_inset Text
15932
15933 \layout Standard
15934
15935 \family roman
15936 \series medium
15937 \shape up
15938 \size normal
15939 \emph off
15940 \bar no
15941 \noun off
15942 \color none
15943 _fsadd.c
15944
15945 \end_inset
15946 </cell>
15947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15948 \begin_inset Text
15949
15950 \layout Standard
15951
15952 \family roman
15953 \series medium
15954 \shape up
15955 \size normal
15956 \emph off
15957 \bar no
15958 \noun off
15959 \color none
15960 add floating point numbers
15961
15962 \end_inset
15963 </cell>
15964 </row>
15965 <row topline="true">
15966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15967 \begin_inset Text
15968
15969 \layout Standard
15970
15971 \family roman
15972 \series medium
15973 \shape up
15974 \size normal
15975 \emph off
15976 \bar no
15977 \noun off
15978 \color none
15979 _fssub.c 
15980
15981 \end_inset
15982 </cell>
15983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15984 \begin_inset Text
15985
15986 \layout Standard
15987
15988 \family roman
15989 \series medium
15990 \shape up
15991 \size normal
15992 \emph off
15993 \bar no
15994 \noun off
15995 \color none
15996 subtract floating point numbers 
15997
15998 \end_inset
15999 </cell>
16000 </row>
16001 <row topline="true">
16002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16003 \begin_inset Text
16004
16005 \layout Standard
16006
16007 \family roman
16008 \series medium
16009 \shape up
16010 \size normal
16011 \emph off
16012 \bar no
16013 \noun off
16014 \color none
16015 _fsdiv.c 
16016
16017 \end_inset
16018 </cell>
16019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16020 \begin_inset Text
16021
16022 \layout Standard
16023
16024 \family roman
16025 \series medium
16026 \shape up
16027 \size normal
16028 \emph off
16029 \bar no
16030 \noun off
16031 \color none
16032 divide floating point numbers 
16033
16034 \end_inset
16035 </cell>
16036 </row>
16037 <row topline="true">
16038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16039 \begin_inset Text
16040
16041 \layout Standard
16042
16043 \family roman
16044 \series medium
16045 \shape up
16046 \size normal
16047 \emph off
16048 \bar no
16049 \noun off
16050 \color none
16051 _fsmul.c 
16052
16053 \end_inset
16054 </cell>
16055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16056 \begin_inset Text
16057
16058 \layout Standard
16059
16060 \family roman
16061 \series medium
16062 \shape up
16063 \size normal
16064 \emph off
16065 \bar no
16066 \noun off
16067 \color none
16068 multiply floating point numbers 
16069
16070 \end_inset
16071 </cell>
16072 </row>
16073 <row topline="true">
16074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16075 \begin_inset Text
16076
16077 \layout Standard
16078
16079 \family roman
16080 \series medium
16081 \shape up
16082 \size normal
16083 \emph off
16084 \bar no
16085 \noun off
16086 \color none
16087 _fs2uchar.c
16088
16089 \end_inset
16090 </cell>
16091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16092 \begin_inset Text
16093
16094 \layout Standard
16095
16096 \family roman
16097 \series medium
16098 \shape up
16099 \size normal
16100 \emph off
16101 \bar no
16102 \noun off
16103 \color none
16104 convert floating point to unsigned char
16105
16106 \end_inset
16107 </cell>
16108 </row>
16109 <row topline="true">
16110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16111 \begin_inset Text
16112
16113 \layout Standard
16114
16115 \family roman
16116 \series medium
16117 \shape up
16118 \size normal
16119 \emph off
16120 \bar no
16121 \noun off
16122 \color none
16123 _fs2char.c
16124
16125 \end_inset
16126 </cell>
16127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16128 \begin_inset Text
16129
16130 \layout Standard
16131
16132 \family roman
16133 \series medium
16134 \shape up
16135 \size normal
16136 \emph off
16137 \bar no
16138 \noun off
16139 \color none
16140 convert floating point to signed char
16141
16142 \end_inset
16143 </cell>
16144 </row>
16145 <row topline="true">
16146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16147 \begin_inset Text
16148
16149 \layout Standard
16150
16151 \family roman
16152 \series medium
16153 \shape up
16154 \size normal
16155 \emph off
16156 \bar no
16157 \noun off
16158 \color none
16159 _fs2uint.c
16160
16161 \end_inset
16162 </cell>
16163 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16164 \begin_inset Text
16165
16166 \layout Standard
16167
16168 \family roman
16169 \series medium
16170 \shape up
16171 \size normal
16172 \emph off
16173 \bar no
16174 \noun off
16175 \color none
16176 convert floating point to unsigned int
16177
16178 \end_inset
16179 </cell>
16180 </row>
16181 <row topline="true">
16182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16183 \begin_inset Text
16184
16185 \layout Standard
16186
16187 \family roman
16188 \series medium
16189 \shape up
16190 \size normal
16191 \emph off
16192 \bar no
16193 \noun off
16194 \color none
16195 _fs2int.c
16196
16197 \end_inset
16198 </cell>
16199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16200 \begin_inset Text
16201
16202 \layout Standard
16203
16204 \family roman
16205 \series medium
16206 \shape up
16207 \size normal
16208 \emph off
16209 \bar no
16210 \noun off
16211 \color none
16212 convert floating point to signed int
16213
16214 \end_inset
16215 </cell>
16216 </row>
16217 <row topline="true">
16218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16219 \begin_inset Text
16220
16221 \layout Standard
16222
16223 \family roman
16224 \series medium
16225 \shape up
16226 \size normal
16227 \emph off
16228 \bar no
16229 \noun off
16230 \color none
16231 _fs2ulong.
16232 \family default
16233 \series default
16234 \shape default
16235 \size default
16236 \emph default
16237 \bar default
16238 \noun default
16239 c
16240
16241 \end_inset
16242 </cell>
16243 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16244 \begin_inset Text
16245
16246 \layout Standard
16247
16248 \family roman
16249 \series medium
16250 \shape up
16251 \size normal
16252 \emph off
16253 \bar no
16254 \noun off
16255 \color none
16256 convert floating point to unsigned long
16257
16258 \end_inset
16259 </cell>
16260 </row>
16261 <row topline="true">
16262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16263 \begin_inset Text
16264
16265 \layout Standard
16266
16267 \family roman
16268 \series medium
16269 \shape up
16270 \size normal
16271 \emph off
16272 \bar no
16273 \noun off
16274 \color none
16275 _fs2long.c
16276
16277 \end_inset
16278 </cell>
16279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16280 \begin_inset Text
16281
16282 \layout Standard
16283
16284 \family roman
16285 \series medium
16286 \shape up
16287 \size normal
16288 \emph off
16289 \bar no
16290 \noun off
16291 \color none
16292 convert floating point to signed long
16293
16294 \end_inset
16295 </cell>
16296 </row>
16297 <row topline="true">
16298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16299 \begin_inset Text
16300
16301 \layout Standard
16302
16303 \family roman
16304 \series medium
16305 \shape up
16306 \size normal
16307 \emph off
16308 \bar no
16309 \noun off
16310 \color none
16311 _uchar2fs.c
16312
16313 \end_inset
16314 </cell>
16315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16316 \begin_inset Text
16317
16318 \layout Standard
16319
16320 \family roman
16321 \series medium
16322 \shape up
16323 \size normal
16324 \emph off
16325 \bar no
16326 \noun off
16327 \color none
16328 convert unsigned char to floating point
16329
16330 \end_inset
16331 </cell>
16332 </row>
16333 <row topline="true">
16334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16335 \begin_inset Text
16336
16337 \layout Standard
16338
16339 \family roman
16340 \series medium
16341 \shape up
16342 \size normal
16343 \emph off
16344 \bar no
16345 \noun off
16346 \color none
16347 _char2fs.c
16348
16349 \end_inset
16350 </cell>
16351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16352 \begin_inset Text
16353
16354 \layout Standard
16355
16356 \family roman
16357 \series medium
16358 \shape up
16359 \size normal
16360 \emph off
16361 \bar no
16362 \noun off
16363 \color none
16364 convert char to floating point number
16365
16366 \end_inset
16367 </cell>
16368 </row>
16369 <row topline="true">
16370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16371 \begin_inset Text
16372
16373 \layout Standard
16374
16375 \family roman
16376 \series medium
16377 \shape up
16378 \size normal
16379 \emph off
16380 \bar no
16381 \noun off
16382 \color none
16383 _uint2fs.c
16384
16385 \end_inset
16386 </cell>
16387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16388 \begin_inset Text
16389
16390 \layout Standard
16391
16392 \family roman
16393 \series medium
16394 \shape up
16395 \size normal
16396 \emph off
16397 \bar no
16398 \noun off
16399 \color none
16400 convert unsigned int to floating point
16401
16402 \end_inset
16403 </cell>
16404 </row>
16405 <row topline="true">
16406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16407 \begin_inset Text
16408
16409 \layout Standard
16410
16411 \family roman
16412 \series medium
16413 \shape up
16414 \size normal
16415 \emph off
16416 \bar no
16417 \noun off
16418 \color none
16419 _int2fs.c
16420
16421 \end_inset
16422 </cell>
16423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16424 \begin_inset Text
16425
16426 \layout Standard
16427
16428 \family roman
16429 \series medium
16430 \shape up
16431 \size normal
16432 \emph off
16433 \bar no
16434 \noun off
16435 \color none
16436 convert int to floating point numbers
16437
16438 \end_inset
16439 </cell>
16440 </row>
16441 <row topline="true">
16442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16443 \begin_inset Text
16444
16445 \layout Standard
16446
16447 \family roman
16448 \series medium
16449 \shape up
16450 \size normal
16451 \emph off
16452 \bar no
16453 \noun off
16454 \color none
16455 _ulong2fs.c
16456
16457 \end_inset
16458 </cell>
16459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16460 \begin_inset Text
16461
16462 \layout Standard
16463
16464 \family roman
16465 \series medium
16466 \shape up
16467 \size normal
16468 \emph off
16469 \bar no
16470 \noun off
16471 \color none
16472 convert unsigned long to floating point number
16473
16474 \end_inset
16475 </cell>
16476 </row>
16477 <row topline="true" bottomline="true">
16478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16479 \begin_inset Text
16480
16481 \layout Standard
16482
16483 \family roman
16484 \series medium
16485 \shape up
16486 \size normal
16487 \emph off
16488 \bar no
16489 \noun off
16490 \color none
16491 _long2fs.c
16492
16493 \end_inset
16494 </cell>
16495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16496 \begin_inset Text
16497
16498 \layout Standard
16499
16500 \family roman
16501 \series medium
16502 \shape up
16503 \size normal
16504 \emph off
16505 \bar no
16506 \noun off
16507 \color none
16508 convert long to floating point number
16509
16510 \end_inset
16511 </cell>
16512 </row>
16513 </lyxtabular>
16514
16515 \end_inset
16516
16517
16518 \newline
16519
16520
16521 \layout Standard
16522 \added_space_bottom bigskip 
16523 These support routines are developed in ANSI-C so there is room for space
16524  and speed improvement
16525 \begin_inset Foot
16526 collapsed false
16527
16528 \layout Standard
16529 These floating point routines (
16530 \emph on
16531 not
16532 \emph default
16533  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
16534  
16535
16536 \end_inset
16537
16538 .
16539  Note if all these routines are used simultaneously the data space might
16540  overflow.
16541  For serious floating point usage the large model might be needed.
16542  Also notice that you don't have to call this routines directly.
16543  The compiler will use them automatically every time a floating point operation
16544  is required.
16545
16546
16547
16548 \layout Section
16549 Library Routines
16550 \begin_inset LatexCommand \index{Libraries}
16551
16552 \end_inset
16553
16554
16555
16556 \layout Standard
16557
16558 \emph on
16559 <pending: this is messy and incomplete - a little more information is in
16560  sdcc/doc/libdoc.txt
16561 \emph default
16562  >
16563
16564 \layout Subsection
16565 Compiler support routines (_gptrget, _mulint etc.)
16566
16567 \layout Subsection
16568 Stdclib functions (puts, printf, strcat etc.)
16569
16570 \layout Subsubsection
16571 <stdio.h>
16572
16573 \layout Paragraph
16574 getchar(), putchar()
16575
16576 \layout Standard
16577 \begin_inset LatexCommand \index{<stdio.h>}
16578
16579 \end_inset
16580
16581 As usual on embedded systems you have to provide your own 
16582 \family typewriter
16583 getchar()
16584 \begin_inset LatexCommand \index{getchar()}
16585
16586 \end_inset
16587
16588  
16589 \family default
16590 and 
16591 \family typewriter
16592 putchar()
16593 \begin_inset LatexCommand \index{putchar()}
16594
16595 \end_inset
16596
16597
16598 \family default
16599  routines.
16600  SDCC does not know whether the system connects to a serial line with or
16601  without handshake, LCD, keyboard or other device.
16602  And whether a 
16603 \family typewriter
16604 lf
16605 \family default
16606  to 
16607 \family typewriter
16608 crlf
16609 \family default
16610  conversion within 
16611 \family typewriter
16612 putchar()
16613 \family default
16614  is intended.
16615  You'll find examples for serial routines f.e.
16616  in sdcc/device/lib.
16617  For the mcs51 this minimalistic polling 
16618 \family typewriter
16619 putchar()
16620 \family default
16621  routine might be a start:
16622
16623 \layout Verse
16624
16625 \family typewriter
16626 void putchar (char c) { 
16627 \newline
16628 \SpecialChar ~
16629 \SpecialChar ~
16630 \SpecialChar ~
16631 \SpecialChar ~
16632 while (!TI)\SpecialChar ~
16633 \SpecialChar ~
16634 \SpecialChar ~
16635  /* assumes UART is initialized */
16636 \newline
16637 \SpecialChar ~
16638 \SpecialChar ~
16639 \SpecialChar ~
16640 \SpecialChar ~
16641 \SpecialChar ~
16642 \SpecialChar ~
16643 \SpecialChar ~
16644 \SpecialChar ~
16645 ;
16646 \newline
16647 \SpecialChar ~
16648 \SpecialChar ~
16649 \SpecialChar ~
16650 \SpecialChar ~
16651 TI
16652  = 0;
16653 \newline
16654 \SpecialChar ~
16655 \SpecialChar ~
16656 \SpecialChar ~
16657 \SpecialChar ~
16658 SBUF = c;
16659 \newline
16660 }
16661
16662 \layout Paragraph
16663 printf()
16664
16665 \layout Standard
16666 The default
16667 \family typewriter
16668  printf()
16669 \begin_inset LatexCommand \index{printf()}
16670
16671 \end_inset
16672
16673
16674 \family default
16675  implementation in
16676 \family typewriter
16677  printf_large.c
16678 \family default
16679  does not support float (except on ds390).
16680  To enable this recompile it with the option 
16681 \emph on
16682 -
16683 \begin_inset ERT
16684 status Collapsed
16685
16686 \layout Standard
16687
16688
16689 \backslash
16690 /
16691
16692 \end_inset
16693
16694 DUSE_FLOATS=1
16695 \begin_inset LatexCommand \index{USE\_FLOATS}
16696
16697 \end_inset
16698
16699
16700 \emph default
16701  on the command line.
16702  Use
16703 \emph on
16704  -
16705 \begin_inset ERT
16706 status Collapsed
16707
16708 \layout Standard
16709
16710
16711 \backslash
16712 /
16713
16714 \end_inset
16715
16716 -model-large
16717 \begin_inset LatexCommand \index{-\/-model-large}
16718
16719 \end_inset
16720
16721
16722 \emph default
16723  for the mcs51 port, since this uses a lot of memory.
16724
16725 \layout Standard
16726 If you're short on code memory you might want to use 
16727 \family typewriter
16728 printf_small()
16729 \begin_inset LatexCommand \index{printf\_small()}
16730
16731 \end_inset
16732
16733
16734 \family default
16735  
16736 \emph on
16737 instead
16738 \emph default
16739  of
16740 \family typewriter
16741  printf().
16742
16743 \family default
16744  For the mcs51 there additionally are assembly versions 
16745 \family typewriter
16746 printf_tiny()
16747 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
16748
16749 \end_inset
16750
16751
16752 \family default
16753  (subset of printf using less than 270 bytes) and 
16754 \family typewriter
16755 printf_fast()
16756 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
16757
16758 \end_inset
16759
16760  
16761 \family default
16762 and
16763 \family typewriter
16764  printf_fast_f()
16765 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
16766
16767 \end_inset
16768
16769
16770 \family default
16771  (floating-point aware version of printf_fast) which should fit the requirements
16772  of many embedded systems (printf_fast() can be customized by unsetting
16773  #defines to 
16774 \emph on
16775 not
16776 \emph default
16777  support long variables and field widths).
16778  Be sure to only use only one of these printf options within a project.
16779 \newline
16780
16781
16782 \layout Standard
16783 Feature matrix of different 
16784 \emph on
16785 printf
16786 \emph default
16787  options on mcs51.
16788
16789 \layout Standard
16790 \begin_inset Tabular
16791 <lyxtabular version="3" rows="14" columns="7">
16792 <features islongtable="true">
16793 <column alignment="left" valignment="center" leftline="true" width="14col%">
16794 <column alignment="center" valignment="top" leftline="true" width="0">
16795 <column alignment="center" valignment="top" leftline="true" width="12col%">
16796 <column alignment="center" valignment="top" leftline="true" width="10col%">
16797 <column alignment="center" valignment="top" leftline="true" width="0">
16798 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
16799 <column alignment="center" valignment="top" rightline="true" width="0">
16800 <row topline="true" bottomline="true" endhead="true">
16801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16802 \begin_inset Text
16803
16804 \layout Standard
16805
16806 \series bold
16807 \size large
16808 mcs51
16809
16810 \end_inset
16811 </cell>
16812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16813 \begin_inset Text
16814
16815 \layout Standard
16816 printf
16817 \begin_inset LatexCommand \index{printf}
16818
16819 \end_inset
16820
16821
16822
16823 \end_inset
16824 </cell>
16825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16826 \begin_inset Text
16827
16828 \layout Standard
16829 printf 
16830 \size scriptsize
16831 USE_FLOATS=1
16832
16833 \end_inset
16834 </cell>
16835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16836 \begin_inset Text
16837
16838 \layout Standard
16839 printf_small
16840
16841 \end_inset
16842 </cell>
16843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16844 \begin_inset Text
16845
16846 \layout Standard
16847 printf_fast
16848
16849 \end_inset
16850 </cell>
16851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16852 \begin_inset Text
16853
16854 \layout Standard
16855 printf_fast_f
16856
16857 \end_inset
16858 </cell>
16859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16860 \begin_inset Text
16861
16862 \layout Standard
16863 printf_tiny
16864
16865 \end_inset
16866 </cell>
16867 </row>
16868 <row topline="true" endhead="true">
16869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16870 \begin_inset Text
16871
16872 \layout Standard
16873 filename
16874
16875 \end_inset
16876 </cell>
16877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16878 \begin_inset Text
16879
16880 \layout Standard
16881
16882 \size scriptsize
16883 printf_large.c
16884
16885 \end_inset
16886 </cell>
16887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16888 \begin_inset Text
16889
16890 \layout Standard
16891
16892 \size scriptsize
16893 printf_large.c
16894
16895 \end_inset
16896 </cell>
16897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16898 \begin_inset Text
16899
16900 \layout Standard
16901
16902 \size scriptsize
16903 printfl.c
16904
16905 \end_inset
16906 </cell>
16907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16908 \begin_inset Text
16909
16910 \layout Standard
16911
16912 \size scriptsize
16913 printf_fast.c
16914
16915 \end_inset
16916 </cell>
16917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16918 \begin_inset Text
16919
16920 \layout Standard
16921
16922 \size scriptsize
16923 printf_fast_f.c
16924
16925 \end_inset
16926 </cell>
16927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16928 \begin_inset Text
16929
16930 \layout Standard
16931
16932 \size scriptsize
16933 printf_tiny.c
16934
16935 \end_inset
16936 </cell>
16937 </row>
16938 <row topline="true" endhead="true">
16939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16940 \begin_inset Text
16941
16942 \layout Standard
16943 \begin_inset Quotes sld
16944 \end_inset
16945
16946 Hello World
16947 \begin_inset Quotes srd
16948 \end_inset
16949
16950  size
16951
16952 \layout Standard
16953 small / large
16954
16955 \end_inset
16956 </cell>
16957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16958 \begin_inset Text
16959
16960 \layout Standard
16961 1.7k / 2.4k
16962
16963 \end_inset
16964 </cell>
16965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16966 \begin_inset Text
16967
16968 \layout Standard
16969 4.3k / 5.6k
16970
16971 \end_inset
16972 </cell>
16973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16974 \begin_inset Text
16975
16976 \layout Standard
16977 1.2k / 1.8k
16978
16979 \end_inset
16980 </cell>
16981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16982 \begin_inset Text
16983
16984 \layout Standard
16985 1.3k / 1.3k
16986
16987 \end_inset
16988 </cell>
16989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16990 \begin_inset Text
16991
16992 \layout Standard
16993 1.9k / 1.9k
16994
16995 \end_inset
16996 </cell>
16997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16998 \begin_inset Text
16999
17000 \layout Standard
17001 0.44k / 0.44k
17002
17003 \end_inset
17004 </cell>
17005 </row>
17006 <row topline="true" endhead="true">
17007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17008 \begin_inset Text
17009
17010 \layout Standard
17011 code size
17012
17013 \layout Standard
17014 small / large
17015
17016 \end_inset
17017 </cell>
17018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17019 \begin_inset Text
17020
17021 \layout Standard
17022 1.4k / 2.0k
17023
17024 \end_inset
17025 </cell>
17026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17027 \begin_inset Text
17028
17029 \layout Standard
17030 2.8k / 3.7k
17031
17032 \end_inset
17033 </cell>
17034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17035 \begin_inset Text
17036
17037 \layout Standard
17038 0.45k / 0.47k (+ _ltoa)
17039
17040 \end_inset
17041 </cell>
17042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17043 \begin_inset Text
17044
17045 \layout Standard
17046 1.2k / 1.2k
17047
17048 \end_inset
17049 </cell>
17050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17051 \begin_inset Text
17052
17053 \layout Standard
17054 1.6k / 1.6k
17055
17056 \end_inset
17057 </cell>
17058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17059 \begin_inset Text
17060
17061 \layout Standard
17062 0.26k / 0.26k
17063
17064 \end_inset
17065 </cell>
17066 </row>
17067 <row topline="true">
17068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17069 \begin_inset Text
17070
17071 \layout Standard
17072 formats
17073
17074 \end_inset
17075 </cell>
17076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17077 \begin_inset Text
17078
17079 \layout Standard
17080 cdi
17081 \emph on
17082 o
17083 \emph default
17084 psux
17085
17086 \end_inset
17087 </cell>
17088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17089 \begin_inset Text
17090
17091 \layout Standard
17092
17093 \family roman
17094 \series medium
17095 \shape up
17096 \size normal
17097 \emph off
17098 \bar no
17099 \noun off
17100 \color none
17101 cd
17102 \family default
17103 \series default
17104 \shape default
17105 \size default
17106 \emph default
17107 \bar default
17108 \noun default
17109 f
17110 \family roman
17111 \series medium
17112 \shape up
17113 \size normal
17114 \emph off
17115 \bar no
17116 \noun off
17117 i
17118 \family default
17119 \series default
17120 \shape default
17121 \size default
17122 \emph on
17123 \bar default
17124 \noun default
17125 o
17126 \family roman
17127 \series medium
17128 \shape up
17129 \size normal
17130 \emph off
17131 \bar no
17132 \noun off
17133 psux
17134
17135 \end_inset
17136 </cell>
17137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17138 \begin_inset Text
17139
17140 \layout Standard
17141 c
17142 \family roman
17143 \series medium
17144 \shape up
17145 \size normal
17146 \emph off
17147 \bar no
17148 \noun off
17149 \color none
17150 d
17151 \family default
17152 \series default
17153 \shape default
17154 \size default
17155 \emph on
17156 \bar default
17157 \noun default
17158 o
17159 \family roman
17160 \series medium
17161 \shape up
17162 \size normal
17163 \emph off
17164 \bar no
17165 \noun off
17166 s
17167 \family default
17168 \series default
17169 \shape default
17170 \size default
17171 \emph default
17172 \bar default
17173 \noun default
17174 x
17175
17176 \end_inset
17177 </cell>
17178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17179 \begin_inset Text
17180
17181 \layout Standard
17182 cdsux
17183
17184 \end_inset
17185 </cell>
17186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17187 \begin_inset Text
17188
17189 \layout Standard
17190 cdfsux
17191
17192 \end_inset
17193 </cell>
17194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17195 \begin_inset Text
17196
17197 \layout Standard
17198 cdsux
17199
17200 \end_inset
17201 </cell>
17202 </row>
17203 <row topline="true">
17204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17205 \begin_inset Text
17206
17207 \layout Standard
17208 long (32 bit) support
17209
17210 \end_inset
17211 </cell>
17212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17213 \begin_inset Text
17214
17215 \layout Standard
17216 x
17217
17218 \end_inset
17219 </cell>
17220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17221 \begin_inset Text
17222
17223 \layout Standard
17224 x
17225
17226 \end_inset
17227 </cell>
17228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17229 \begin_inset Text
17230
17231 \layout Standard
17232 x
17233
17234 \end_inset
17235 </cell>
17236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17237 \begin_inset Text
17238
17239 \layout Standard
17240 x
17241
17242 \end_inset
17243 </cell>
17244 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17245 \begin_inset Text
17246
17247 \layout Standard
17248
17249 \family roman
17250 \series medium
17251 \shape up
17252 \size normal
17253 \emph off
17254 \bar no
17255 \noun off
17256 \color none
17257 x
17258
17259 \end_inset
17260 </cell>
17261 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17262 \begin_inset Text
17263
17264 \layout Standard
17265 -
17266
17267 \end_inset
17268 </cell>
17269 </row>
17270 <row topline="true">
17271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17272 \begin_inset Text
17273
17274 \layout Standard
17275 byte arguments on stack
17276
17277 \end_inset
17278 </cell>
17279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17280 \begin_inset Text
17281
17282 \layout Standard
17283 b
17284
17285 \end_inset
17286 </cell>
17287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17288 \begin_inset Text
17289
17290 \layout Standard
17291 b
17292
17293 \end_inset
17294 </cell>
17295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17296 \begin_inset Text
17297
17298 \layout Standard
17299 -
17300
17301 \end_inset
17302 </cell>
17303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17304 \begin_inset Text
17305
17306 \layout Standard
17307 -
17308
17309 \end_inset
17310 </cell>
17311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17312 \begin_inset Text
17313
17314 \layout Standard
17315 -
17316
17317 \end_inset
17318 </cell>
17319 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17320 \begin_inset Text
17321
17322 \layout Standard
17323 -
17324
17325 \end_inset
17326 </cell>
17327 </row>
17328 <row topline="true">
17329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17330 \begin_inset Text
17331
17332 \layout Standard
17333 float format
17334 \begin_inset LatexCommand \index{Floating point support}
17335
17336 \end_inset
17337
17338
17339
17340 \end_inset
17341 </cell>
17342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17343 \begin_inset Text
17344
17345 \layout Standard
17346 -
17347
17348 \end_inset
17349 </cell>
17350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17351 \begin_inset Text
17352
17353 \layout Standard
17354 %f
17355
17356 \end_inset
17357 </cell>
17358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17359 \begin_inset Text
17360
17361 \layout Standard
17362 -
17363
17364 \end_inset
17365 </cell>
17366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17367 \begin_inset Text
17368
17369 \layout Standard
17370 -
17371
17372 \end_inset
17373 </cell>
17374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17375 \begin_inset Text
17376
17377 \layout Standard
17378 %f
17379 \begin_inset Foot
17380 collapsed true
17381
17382 \layout Standard
17383 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
17384
17385 \end_inset
17386
17387
17388
17389 \end_inset
17390 </cell>
17391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17392 \begin_inset Text
17393
17394 \layout Standard
17395 -
17396
17397 \end_inset
17398 </cell>
17399 </row>
17400 <row topline="true">
17401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17402 \begin_inset Text
17403
17404 \layout Standard
17405 float formats %e %g
17406
17407 \end_inset
17408 </cell>
17409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17410 \begin_inset Text
17411
17412 \layout Standard
17413 -
17414
17415 \end_inset
17416 </cell>
17417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17418 \begin_inset Text
17419
17420 \layout Standard
17421 -
17422
17423 \end_inset
17424 </cell>
17425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17426 \begin_inset Text
17427
17428 \layout Standard
17429 -
17430
17431 \end_inset
17432 </cell>
17433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17434 \begin_inset Text
17435
17436 \layout Standard
17437 -
17438
17439 \end_inset
17440 </cell>
17441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17442 \begin_inset Text
17443
17444 \layout Standard
17445 -
17446
17447 \end_inset
17448 </cell>
17449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17450 \begin_inset Text
17451
17452 \layout Standard
17453 -
17454
17455 \end_inset
17456 </cell>
17457 </row>
17458 <row topline="true" bottomline="true">
17459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17460 \begin_inset Text
17461
17462 \layout Standard
17463 field width
17464
17465 \end_inset
17466 </cell>
17467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17468 \begin_inset Text
17469
17470 \layout Standard
17471 x
17472
17473 \end_inset
17474 </cell>
17475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17476 \begin_inset Text
17477
17478 \layout Standard
17479 x
17480
17481 \end_inset
17482 </cell>
17483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17484 \begin_inset Text
17485
17486 \layout Standard
17487 -
17488
17489 \end_inset
17490 </cell>
17491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17492 \begin_inset Text
17493
17494 \layout Standard
17495 x
17496
17497 \end_inset
17498 </cell>
17499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17500 \begin_inset Text
17501
17502 \layout Standard
17503 x
17504
17505 \end_inset
17506 </cell>
17507 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17508 \begin_inset Text
17509
17510 \layout Standard
17511 -
17512
17513 \end_inset
17514 </cell>
17515 </row>
17516 <row bottomline="true">
17517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17518 \begin_inset Text
17519
17520 \layout Standard
17521 string speed
17522 \begin_inset Foot
17523 collapsed true
17524
17525 \layout Standard
17526 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
17527 \backslash
17528 r', '
17529 \backslash
17530 n'); standard 8051 @ 22.1184 MHz, empty putchar()
17531
17532 \end_inset
17533
17534 ,
17535
17536 \layout Standard
17537 small / large
17538
17539 \end_inset
17540 </cell>
17541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17542 \begin_inset Text
17543
17544 \layout Standard
17545 1.52 / 2.59 ms
17546
17547 \end_inset
17548 </cell>
17549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17550 \begin_inset Text
17551
17552 \layout Standard
17553 1.53 / 2.62 ms
17554
17555 \end_inset
17556 </cell>
17557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17558 \begin_inset Text
17559
17560 \layout Standard
17561 0.92 / 0.93 ms
17562
17563 \end_inset
17564 </cell>
17565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17566 \begin_inset Text
17567
17568 \layout Standard
17569 0.45 / 0.45 ms
17570
17571 \end_inset
17572 </cell>
17573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17574 \begin_inset Text
17575
17576 \layout Standard
17577 0.46 / 0.46 ms
17578
17579 \end_inset
17580 </cell>
17581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17582 \begin_inset Text
17583
17584 \layout Standard
17585 0.45 / 0.45 ms
17586
17587 \end_inset
17588 </cell>
17589 </row>
17590 <row bottomline="true">
17591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17592 \begin_inset Text
17593
17594 \layout Standard
17595 int speed
17596 \begin_inset Foot
17597 collapsed true
17598
17599 \layout Standard
17600 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
17601  putchar()
17602
17603 \end_inset
17604
17605 ,
17606
17607 \layout Standard
17608 small / large
17609
17610 \end_inset
17611 </cell>
17612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17613 \begin_inset Text
17614
17615 \layout Standard
17616 3.01 / 3.61 ms
17617
17618 \end_inset
17619 </cell>
17620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17621 \begin_inset Text
17622
17623 \layout Standard
17624 3.01 / 3.61 ms
17625
17626 \end_inset
17627 </cell>
17628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17629 \begin_inset Text
17630
17631 \layout Standard
17632 3.51 / 18.13 ms
17633
17634 \end_inset
17635 </cell>
17636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17637 \begin_inset Text
17638
17639 \layout Standard
17640 0.22 / 0.22 ms
17641
17642 \end_inset
17643 </cell>
17644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17645 \begin_inset Text
17646
17647 \layout Standard
17648 0.23 / 0.23 ms
17649
17650 \end_inset
17651 </cell>
17652 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17653 \begin_inset Text
17654
17655 \layout Standard
17656 0.25 / 0.25 ms
17657 \begin_inset Foot
17658 collapsed true
17659
17660 \layout Standard
17661 printf_tiny integer speed is data dependent, worst case is 0.33 ms
17662
17663 \end_inset
17664
17665
17666
17667 \end_inset
17668 </cell>
17669 </row>
17670 <row bottomline="true">
17671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17672 \begin_inset Text
17673
17674 \layout Standard
17675 long speed
17676 \begin_inset Foot
17677 collapsed true
17678
17679 \layout Standard
17680 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
17681  empty putchar()
17682
17683 \end_inset
17684
17685 ,
17686
17687 \layout Standard
17688 small / large
17689
17690 \end_inset
17691 </cell>
17692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17693 \begin_inset Text
17694
17695 \layout Standard
17696 5.37 / 6.31 ms
17697
17698 \end_inset
17699 </cell>
17700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17701 \begin_inset Text
17702
17703 \layout Standard
17704 5.37 / 6.31 ms
17705
17706 \end_inset
17707 </cell>
17708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17709 \begin_inset Text
17710
17711 \layout Standard
17712 8.71 / 40.65 ms
17713
17714 \end_inset
17715 </cell>
17716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17717 \begin_inset Text
17718
17719 \layout Standard
17720 0.40 / 0.40 ms
17721
17722 \end_inset
17723 </cell>
17724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17725 \begin_inset Text
17726
17727 \layout Standard
17728 0.40 / 0.40 ms
17729
17730 \end_inset
17731 </cell>
17732 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17733 \begin_inset Text
17734
17735 \layout Standard
17736 -
17737
17738 \end_inset
17739 </cell>
17740 </row>
17741 <row bottomline="true">
17742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17743 \begin_inset Text
17744
17745 \layout Standard
17746 float speed
17747 \begin_inset Foot
17748 collapsed true
17749
17750 \layout Standard
17751 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
17752  empty putchar()
17753
17754 \end_inset
17755
17756 ,
17757
17758 \layout Standard
17759 small / large
17760
17761 \end_inset
17762 </cell>
17763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17764 \begin_inset Text
17765
17766 \layout Standard
17767 -
17768
17769 \end_inset
17770 </cell>
17771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17772 \begin_inset Text
17773
17774 \layout Standard
17775 7.49 / 22.47 ms
17776
17777 \end_inset
17778 </cell>
17779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17780 \begin_inset Text
17781
17782 \layout Standard
17783 -
17784
17785 \end_inset
17786 </cell>
17787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17788 \begin_inset Text
17789
17790 \layout Standard
17791 -
17792
17793 \end_inset
17794 </cell>
17795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17796 \begin_inset Text
17797
17798 \layout Standard
17799 1.04 / 1.04 ms
17800
17801 \end_inset
17802 </cell>
17803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17804 \begin_inset Text
17805
17806 \layout Standard
17807 -
17808
17809 \end_inset
17810 </cell>
17811 </row>
17812 </lyxtabular>
17813
17814 \end_inset
17815
17816
17817
17818 \layout Subsubsection
17819 <malloc.h>
17820 \begin_inset LatexCommand \index{malloc.h}
17821
17822 \end_inset
17823
17824
17825
17826 \layout Standard
17827 As of SDCC 2.6.2 you no longer need to call an initialization routine before
17828  using dynamic memory allocation
17829 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
17830
17831 \end_inset
17832
17833  and a default heap
17834 \begin_inset LatexCommand \index{heap (malloc)}
17835
17836 \end_inset
17837
17838  space of 1024 bytes is provided for malloc to allocate memory from.
17839  If you need a different heap size you need to recompile _heap.c with the
17840  required size defined in HEAP_SIZE.
17841  It is recommended to make a copy of this file into your project directory
17842  and compile it there with:
17843
17844 \layout Verse
17845
17846 \family typewriter
17847 sdcc -c _heap.c -D HEAD_SIZE=2048
17848
17849 \layout Standard
17850 And then link it with:
17851
17852 \layout Verse
17853
17854 \family typewriter
17855 sdcc main.rel _heap.rel
17856
17857 \layout Subsection
17858 Math functions (sinf, powf, sqrtf etc.)
17859
17860 \layout Subsubsection
17861 <math.h>
17862
17863 \layout Standard
17864 See definitions in file <math.h>.
17865
17866 \layout Subsection
17867 Other libraries
17868
17869 \layout Standard
17870 Libraries
17871 \begin_inset LatexCommand \index{Libraries}
17872
17873 \end_inset
17874
17875  included in SDCC should have a license at least as liberal as the GNU Lesser
17876  General Public License
17877 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
17878
17879 \end_inset
17880
17881  
17882 \emph on
17883 LGPL
17884 \emph default
17885 .
17886
17887 \layout Standard
17888 \begin_inset Note
17889 collapsed true
17890
17891 \layout Standard
17892 license statements for the libraries are missing.
17893  sdcc/device/lib/ser_ir.c
17894
17895 \layout Standard
17896 or _decdptr f.e.
17897  come with a GPL (as opposed to LGPL) License - this will not be liberal
17898  enough for many embedded programmers.
17899
17900 \end_inset
17901
17902
17903
17904 \layout Standard
17905 If you have ported some library or want to share experience about some code
17906  which f.e.
17907  falls into any of these categories Busses (I
17908 \begin_inset Formula $^{\textrm{2}}$
17909 \end_inset
17910
17911 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
17912  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
17913  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
17914 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
17915
17916 \end_inset
17917
17918 \SpecialChar ~
17919 would certainly like to hear about it.
17920
17921 \layout Standard
17922 \added_space_bottom bigskip 
17923 Programmers coding for embedded systems are not especially famous for being
17924  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
17925 e these references are very valuable.
17926  Let's help to create a climate where information is shared.
17927
17928
17929
17930 \layout Section
17931 Memory Models
17932
17933 \layout Subsection
17934 MCS51 Memory Models
17935 \begin_inset LatexCommand \index{Memory model}
17936
17937 \end_inset
17938
17939
17940 \begin_inset LatexCommand \index{MCS51 memory model}
17941
17942 \end_inset
17943
17944
17945
17946 \layout Subsubsection
17947 Small, Medium and Large
17948
17949 \layout Standard
17950 SDCC allows three memory models for MCS51 code, 
17951 \shape slanted
17952 small, medium
17953 \shape default
17954  and 
17955 \shape slanted
17956 large
17957 \shape default
17958 .
17959  Modules compiled with different memory models should 
17960 \emph on
17961 never
17962 \emph default
17963  be combined together or the results would be unpredictable.
17964  The library routines supplied with the compiler are compiled as small,
17965  medium and large.
17966  The compiled library modules are contained in separate directories as small,
17967  medium and large so that you can link to the appropriate set.
17968
17969 \layout Standard
17970 When the medium or large model is used all variables declared without a
17971  storage class will be allocated into the external ram, this includes all
17972  parameters and local variables (for non-reentrant
17973 \begin_inset LatexCommand \index{reentrant}
17974
17975 \end_inset
17976
17977  functions).
17978  When the small model is used variables without storage class are allocated
17979  in the internal ram.
17980
17981 \layout Standard
17982 Judicious usage of the processor specific storage classes
17983 \begin_inset LatexCommand \index{Storage class}
17984
17985 \end_inset
17986
17987  and the 'reentrant' function type will yield much more efficient code,
17988  than using the large model.
17989  Several optimizations are disabled when the program is compiled using the
17990  large model, it is therefore recommended that the small model be used unless
17991  absolutely required.
17992
17993 \layout Subsubsection
17994 External Stack
17995 \begin_inset LatexCommand \label{sub:External-Stack}
17996
17997 \end_inset
17998
17999
18000 \begin_inset LatexCommand \index{stack}
18001
18002 \end_inset
18003
18004
18005 \begin_inset LatexCommand \index{External stack (mcs51)}
18006
18007 \end_inset
18008
18009
18010
18011 \layout Standard
18012 The external stack (-
18013 \begin_inset ERT
18014 status Collapsed
18015
18016 \layout Standard
18017
18018
18019 \backslash
18020 /
18021
18022 \end_inset
18023
18024 -xstack option
18025 \begin_inset LatexCommand \index{-\/-xstack}
18026
18027 \end_inset
18028
18029 ) is located in pdata
18030 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
18031
18032 \end_inset
18033
18034  memory (usually at the start of the external ram segment) and uses all
18035  unused space in pdata (max.
18036  256 bytes).
18037  When -
18038 \begin_inset ERT
18039 status Collapsed
18040
18041 \layout Standard
18042
18043
18044 \backslash
18045 /
18046
18047 \end_inset
18048
18049 -xstack option is used to compile the program, the parameters and local
18050  variables
18051 \begin_inset LatexCommand \index{local variables}
18052
18053 \end_inset
18054
18055  of all reentrant functions are allocated in this area.
18056  This option is provided for programs with large stack space requirements.
18057  When used with the -
18058 \begin_inset ERT
18059 status Collapsed
18060
18061 \layout Standard
18062
18063
18064 \backslash
18065 /
18066
18067 \end_inset
18068
18069 -stack-auto
18070 \begin_inset LatexCommand \index{-\/-stack-auto}
18071
18072 \end_inset
18073
18074  option, all parameters and local variables are allocated on the external
18075  stack (note: support libraries will need to be recompiled with the same
18076  options.
18077  There is a predefined target in the library makefile).
18078
18079 \layout Standard
18080 The compiler outputs the higher order address byte of the external ram segment
18081  into port P2
18082 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
18083
18084 \end_inset
18085
18086  (see also section 
18087 \begin_inset LatexCommand \ref{sub:MCS51-variants}
18088
18089 \end_inset
18090
18091 ), therefore when using the External Stack option, this port 
18092 \emph on
18093 may not
18094 \emph default
18095  be used by the application program.
18096
18097 \layout Subsection
18098 DS390 Memory Model
18099 \begin_inset LatexCommand \index{Memory model}
18100
18101 \end_inset
18102
18103
18104 \begin_inset LatexCommand \index{DS390 memory model}
18105
18106 \end_inset
18107
18108
18109
18110 \layout Standard
18111 The only model supported is Flat 24
18112 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
18113
18114 \end_inset
18115
18116 .
18117  This generates code for the 24 bit contiguous addressing mode of the Dallas
18118  DS80C390 part.
18119  In this mode, up to four meg of external RAM or code space can be directly
18120  addressed.
18121  See the data sheets at www.dalsemi.com for further information on this part.
18122 \newline
18123
18124 \newline
18125 Note
18126  that the compiler does not generate any code to place the processor into
18127  24 bitmode (although 
18128 \emph on
18129 tinibios
18130 \emph default
18131  in the ds390 libraries will do that for you).
18132  If you don't use 
18133 \emph on
18134 tinibios
18135 \emph default
18136
18137 \begin_inset LatexCommand \index{Tinibios (DS390)}
18138
18139 \end_inset
18140
18141 , the boot loader or similar code must ensure that the processor is in 24
18142  bit contiguous addressing mode before calling the SDCC startup code.
18143 \newline
18144
18145 \newline
18146 Like
18147  the 
18148 \emph on
18149 -
18150 \begin_inset ERT
18151 status Collapsed
18152
18153 \layout Standard
18154
18155
18156 \backslash
18157 /
18158
18159 \end_inset
18160
18161 -model-large
18162 \emph default
18163  option, variables will by default be placed into the XDATA segment.
18164  
18165 \newline
18166
18167 \newline
18168 Segments may be placed anywhere in the 4 meg address space using the usual
18169  -
18170 \begin_inset ERT
18171 status Collapsed
18172
18173 \layout Standard
18174
18175
18176 \backslash
18177 /
18178
18179 \end_inset
18180
18181 -*-loc options.
18182  Note that if any segments are located above 64K, the -r flag must be passed
18183  to the linker to generate the proper segment relocations, and the Intel
18184  HEX output format must be used.
18185  The -r flag can be passed to the linker by using the option 
18186 \emph on
18187 -Wl-r
18188 \emph default
18189  on the SDCC command line.
18190  However, currently the linker can not handle code segments > 64k.
18191
18192 \layout Section
18193 Pragmas
18194 \begin_inset LatexCommand \label{sec:Pragmas}
18195
18196 \end_inset
18197
18198
18199 \begin_inset LatexCommand \index{Pragmas}
18200
18201 \end_inset
18202
18203
18204
18205 \layout Standard
18206 SDCC supports the following #pragma directives:
18207
18208 \layout Itemize
18209
18210 \series bold
18211 save
18212 \series default
18213
18214 \begin_inset LatexCommand \index{\#pragma save}
18215
18216 \end_inset
18217
18218  - this will save most current options to the save/restore stack.
18219  See #pragma\SpecialChar ~
18220 restore.
18221
18222 \layout Itemize
18223
18224 \series bold
18225 restore
18226 \series default
18227
18228 \begin_inset LatexCommand \index{\#pragma restore}
18229
18230 \end_inset
18231
18232  - will restore saved options from the last save.
18233  saves & restores can be nested.
18234  SDCC uses a save/restore stack: save pushes current options to the stack,
18235  restore pulls current options from the stack.
18236  See #pragma\SpecialChar ~
18237 save.
18238 \newline
18239
18240
18241 \layout Itemize
18242
18243 \series bold
18244 callee_saves
18245 \series default
18246
18247 \begin_inset LatexCommand \index{\#pragma callee\_saves}
18248
18249 \end_inset
18250
18251
18252 \begin_inset LatexCommand \index{function prologue}
18253
18254 \end_inset
18255
18256  function1[,function2[,function3...]] - The compiler by default uses a caller
18257  saves convention for register saving across function calls, however this
18258  can cause unnecessary register pushing & popping
18259 \begin_inset LatexCommand \index{push/pop}
18260
18261 \end_inset
18262
18263  when calling small functions from larger functions.
18264  This option can be used to switch off the register saving convention for
18265  the function names specified.
18266  The compiler will not save registers when calling these functions, extra
18267  code need to be manually inserted at the entry & exit for these functions
18268  to save & restore the registers used by these functions, this can SUBSTANTIALLY
18269  reduce code & improve run time performance of the generated code.
18270  In the future the compiler (with inter procedural analysis) may be able
18271  to determine the appropriate scheme to use for each function call.
18272  If -
18273 \begin_inset ERT
18274 status Collapsed
18275
18276 \layout Standard
18277
18278
18279 \backslash
18280 /
18281
18282 \end_inset
18283
18284 -callee-saves command line option is used, the function names specified
18285  in #pragma\SpecialChar ~
18286 callee_saves
18287 \begin_inset LatexCommand \index{\#pragma callee\_saves}
18288
18289 \end_inset
18290
18291  is appended to the list of functions specified in the command line.
18292
18293 \layout Itemize
18294
18295 \series bold
18296 exclude
18297 \series default
18298
18299 \begin_inset LatexCommand \index{\#pragma exclude}
18300
18301 \end_inset
18302
18303  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
18304  of pairs of push/pop
18305 \begin_inset LatexCommand \index{push/pop}
18306
18307 \end_inset
18308
18309  instructions in 
18310 \emph on
18311 I
18312 \emph default
18313 nterrupt
18314 \begin_inset LatexCommand \index{interrupt}
18315
18316 \end_inset
18317
18318  
18319 \emph on
18320 S
18321 \emph default
18322 ervice 
18323 \emph on
18324 R
18325 \emph default
18326 outines.
18327  The directive should be placed immediately before the ISR function definition
18328  and it affects ALL ISR functions following it.
18329  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
18330 exclude\SpecialChar ~
18331 none
18332 \begin_inset LatexCommand \index{\#pragma exclude}
18333
18334 \end_inset
18335
18336 .
18337  See also the related keyword _naked
18338 \begin_inset LatexCommand \index{\_naked}
18339
18340 \end_inset
18341
18342
18343 \begin_inset LatexCommand \index{\_\_naked}
18344
18345 \end_inset
18346
18347 .
18348
18349 \layout Itemize
18350
18351 \series bold
18352 less_pedantic
18353 \series default
18354
18355 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
18356
18357 \end_inset
18358
18359  - the compiler will not warn you anymore for obvious mistakes, you'r on
18360  your own now ;-(
18361
18362 \layout Itemize
18363
18364 \series bold
18365 disable_warning
18366 \series default
18367  <nnnn>
18368 \begin_inset LatexCommand \index{\#pragma disable\_warning}
18369
18370 \end_inset
18371
18372  - the compiler will not warn you anymore about warning number <nnnn>.
18373
18374 \layout Itemize
18375
18376 \series bold
18377 nogcse
18378 \series default
18379
18380 \begin_inset LatexCommand \index{\#pragma nogcse}
18381
18382 \end_inset
18383
18384  - will stop global common subexpression elimination.
18385
18386 \layout Itemize
18387
18388 \series bold
18389 noinduction
18390 \series default
18391
18392 \begin_inset LatexCommand \index{\#pragma noinduction}
18393
18394 \end_inset
18395
18396  - will stop loop induction optimizations.
18397
18398 \layout Itemize
18399
18400 \series bold
18401 noinvariant
18402 \series default
18403
18404 \begin_inset LatexCommand \index{\#pragma noinvariant}
18405
18406 \end_inset
18407
18408  - will not do loop invariant optimizations.
18409  For more details see Loop Invariants in section
18410 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
18411
18412 \end_inset
18413
18414 .
18415
18416 \layout Itemize
18417
18418 \series bold
18419 noiv
18420 \series default
18421
18422 \begin_inset LatexCommand \index{\#pragma noiv}
18423
18424 \end_inset
18425
18426  - Do not generate interrupt
18427 \begin_inset LatexCommand \index{interrupt}
18428
18429 \end_inset
18430
18431  vector table
18432 \begin_inset LatexCommand \index{interrupt vector table}
18433
18434 \end_inset
18435
18436  entries for all ISR functions defined after the pragma.
18437  This is useful in cases where the interrupt vector table must be defined
18438  manually, or when there is a secondary, manually defined interrupt vector
18439  table (e.g.
18440  for the autovector feature of the Cypress EZ-USB FX2).
18441  More elegantly this can be achieved by obmitting the optional interrupt
18442  number after the interrupt keyword, see section 
18443 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
18444
18445 \end_inset
18446
18447 \SpecialChar ~
18448 about interrupts.
18449
18450 \layout Itemize
18451
18452 \series bold
18453 nojtbound
18454 \series default
18455
18456 \begin_inset LatexCommand \index{\#pragma nojtbound}
18457
18458 \end_inset
18459
18460  - will not generate code for boundary value checking, when switch statements
18461  are turned into jump-tables (dangerous).
18462  For more details see section 
18463 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
18464
18465 \end_inset
18466
18467 .
18468
18469 \layout Itemize
18470
18471 \series bold
18472 noloopreverse
18473 \series default
18474
18475 \begin_inset LatexCommand \index{\#pragma noloopreverse}
18476
18477 \end_inset
18478
18479  - Will not do loop reversal optimization
18480
18481 \layout Itemize
18482
18483 \series bold
18484 nooverlay
18485 \series default
18486
18487 \begin_inset LatexCommand \index{\#pragma nooverlay}
18488
18489 \end_inset
18490
18491  - the compiler will not overlay the parameters and local variables of a
18492  function.
18493
18494 \layout Itemize
18495
18496 \series bold
18497 stackauto
18498 \series default
18499
18500 \begin_inset LatexCommand \index{\#pragma stackauto}
18501
18502 \end_inset
18503
18504 - See option -
18505 \begin_inset ERT
18506 status Collapsed
18507
18508 \layout Standard
18509
18510
18511 \backslash
18512 /
18513
18514 \end_inset
18515
18516 -stack-auto
18517 \begin_inset LatexCommand \index{-\/-stack-auto}
18518
18519 \end_inset
18520
18521  and section 
18522 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
18523
18524 \end_inset
18525
18526  Parameters and Local Variables.
18527
18528 \layout Itemize
18529
18530 \series bold
18531 opt_code_speed
18532 \series default
18533  
18534 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
18535
18536 \end_inset
18537
18538 - The compiler will optimize code generation towards fast code, possibly
18539  at the expense of code size.
18540  Currently this has little effect.
18541
18542 \layout Itemize
18543
18544 \series bold
18545 opt_code_size
18546 \series default
18547  
18548 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
18549
18550 \end_inset
18551
18552 - The compiler will optimize code generation towards compact code, possibly
18553  at the expense of code speed.
18554  Currently this has little effect.
18555
18556 \layout Itemize
18557
18558 \series bold
18559 opt_code_balanced
18560 \series default
18561  
18562 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
18563
18564 \end_inset
18565
18566 - The compiler will attempt to generate code that is both compact and fast,
18567  as long as meeting one goal is not a detriment to the other (this is the
18568  default).
18569  
18570
18571 \layout Itemize
18572
18573 \series bold
18574 std_sdcc89
18575 \series default
18576  
18577 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
18578
18579 \end_inset
18580
18581 - Generally follow the C89 standard, but allow SDCC features that conflict
18582  with the standard (default).
18583
18584 \layout Itemize
18585
18586 \series bold
18587 std_c89
18588 \series default
18589  
18590 \begin_inset LatexCommand \index{\#pragma std\_c89}
18591
18592 \end_inset
18593
18594 - Follow the C89 standard and disable SDCC features that conflict with the
18595  standard.
18596
18597 \layout Itemize
18598
18599 \series bold
18600 std_sdcc99
18601 \series default
18602  
18603 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
18604
18605 \end_inset
18606
18607 - Generally follow the C99 standard, but allow SDCC features that conflict
18608  with the standard (incomplete support).
18609
18610 \layout Itemize
18611
18612 \series bold
18613 std_c99
18614 \series default
18615  
18616 \begin_inset LatexCommand \index{\#pragma std\_c99}
18617
18618 \end_inset
18619
18620 - Follow the C99 standard and disable SDCC features that conflict with the
18621  standard (incomplete support).
18622
18623 \layout Itemize
18624
18625 \series bold
18626 codeseg
18627 \series default
18628  <name>
18629 \begin_inset LatexCommand \index{\#pragma codeseg}
18630
18631 \end_inset
18632
18633 - Use this name (max.
18634  8 characters) for the code segment.
18635  See option -
18636 \begin_inset ERT
18637 status Collapsed
18638
18639 \layout Standard
18640
18641
18642 \backslash
18643 /
18644
18645 \end_inset
18646
18647 -codeseg.
18648
18649 \layout Itemize
18650
18651 \series bold
18652 constseg
18653 \series default
18654  <name>
18655 \begin_inset LatexCommand \index{\#pragma constseg}
18656
18657 \end_inset
18658
18659 - Use this name (max.
18660  8 characters) for the const segment.
18661  See option -
18662 \begin_inset ERT
18663 status Collapsed
18664
18665 \layout Standard
18666
18667
18668 \backslash
18669 /
18670
18671 \end_inset
18672
18673 -constseg.
18674
18675 \layout Standard
18676 The preprocessor SDCPP
18677 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
18678
18679 \end_inset
18680
18681  supports the following #pragma directives:
18682
18683 \layout Itemize
18684
18685 \series bold
18686 pedantic_parse_number
18687 \series default
18688
18689 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
18690
18691 \end_inset
18692
18693  (+ | -) - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are
18694  parsed properly and the macro LO_B(3) gets expanded.
18695  Default is off.
18696  Below is an example on how to use this pragma.
18697
18698 \emph on
18699  Note: this functionality is not in conformance with standard!
18700
18701 \layout Verse
18702
18703 \family typewriter
18704 #pragma pedantic_parse_number +
18705 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
18706
18707 \end_inset
18708
18709
18710 \newline
18711
18712 \newline
18713 #define LO_B(x) ((x) & 0xff)
18714 \newline
18715
18716 \newline
18717 unsigned char foo(void)
18718 \newline
18719 {
18720 \newline
18721 \SpecialChar ~
18722 \SpecialChar ~
18723 \SpecialChar ~
18724 unsigned char c=0xfe-LO_B(3)
18725 ;
18726 \newline
18727
18728 \newline
18729 \SpecialChar ~
18730 \SpecialChar ~
18731 \SpecialChar ~
18732 return c;
18733 \newline
18734 }
18735 \newline
18736
18737
18738 \layout Itemize
18739
18740 \series bold
18741 preproc_asm
18742 \series default
18743
18744 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
18745
18746 \end_inset
18747
18748  (+ | -) - switch _asm _endasm block preprocessing on / off.
18749  Default is on.
18750  You use this prama to define multilines of assembly code.
18751  This will prevent the preprocessor from changing the formating required
18752  by assembly code.
18753  Below is an example on how to use this pragma.
18754
18755 \layout Verse
18756
18757 \family typewriter
18758 #pragma preproc_asm -
18759 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
18760
18761 \end_inset
18762
18763
18764 \newline
18765 #define MYDELAY _asm
18766 \newline
18767 \SpecialChar ~
18768 \SpecialChar ~
18769 \SpecialChar ~
18770 nop ;my assembly comment...
18771 \newline
18772 \SpecialChar ~
18773 \SpecialChar ~
18774 \SpecialChar ~
18775 nop
18776 \newline
18777 \SpecialChar ~
18778 \SpecialChar ~
18779 \SpecialChar ~
18780 nop
18781 \newline
18782 _endasm
18783 \newline
18784 #pragma preproc_asm
18785  +
18786 \newline
18787
18788 \newline
18789 void foo (void) 
18790 \newline
18791
18792 \newline
18793 \SpecialChar ~
18794 \SpecialChar ~
18795 \SpecialChar ~
18796  ...
18797  
18798 \newline
18799 \SpecialChar ~
18800 \SpecialChar ~
18801 \SpecialChar ~
18802  MYDELAY;
18803 \newline
18804 \SpecialChar ~
18805 \SpecialChar ~
18806 \SpecialChar ~
18807  ...
18808  
18809 \newline
18810
18811 \newline
18812
18813
18814 \layout Itemize
18815
18816 \series bold
18817 sdcc_hash
18818 \series default
18819
18820 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
18821
18822 \end_inset
18823
18824  (+ | -) - Allow "naked" hash in macro definition, for example:
18825 \newline
18826
18827 \family typewriter
18828 #define DIR_LO(x) #(x & 0xff)
18829 \family default
18830
18831 \newline
18832 Default is off.
18833  Below is an example on how to use this pragma.
18834
18835 \layout Verse
18836
18837 \family typewriter
18838 #pragma preproc_asm +
18839 \newline
18840 #pragma sdcc_hash +
18841 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
18842
18843 \end_inset
18844
18845
18846 \newline
18847
18848 \newline
18849 #define ROMCALL(x) 
18850 \backslash
18851
18852 \newline
18853 \SpecialChar ~
18854 \SpecialChar ~
18855 \SpecialChar ~
18856 mov R6_B3, #(x & 0xff) 
18857 \backslash
18858
18859 \newline
18860 \SpecialChar ~
18861 \SpecialChar ~
18862 \SpecialChar ~
18863 mov R7_B3, #((x >> 8) & 0xff) 
18864 \backslash
18865
18866 \newline
18867 \SpecialChar ~
18868 \SpecialChar ~
18869 \SpecialChar ~
18870 lcall __romcall
18871 \newline
18872
18873 \newline
18874 ...
18875 \newline
18876 _asm
18877 \newline
18878 ROMCALL(72)
18879 \newline
18880 _endasm;
18881 \newline
18882 ...
18883 \newline
18884
18885
18886 \layout Standard
18887 The pragma's are intended to be used to turn-on or off certain optimizations
18888  which might cause the compiler to generate extra stack / data space to
18889  store compiler generated temporary variables.
18890  This usually happens in large functions.
18891  Pragma directives should be used as shown in the following example, they
18892  are used to control options & optimizations for a given function; pragmas
18893  should be placed before and/or after a function, placing pragma's inside
18894  a function body could have unpredictable results.
18895
18896 \layout Verse
18897
18898 \family typewriter
18899 #pragma save
18900 \begin_inset LatexCommand \index{\#pragma save}
18901
18902 \end_inset
18903
18904  \SpecialChar ~
18905 \SpecialChar ~
18906 \SpecialChar ~
18907 \SpecialChar ~
18908 \SpecialChar ~
18909 \SpecialChar ~
18910 \SpecialChar ~
18911 /* save the current settings */ 
18912 \newline
18913 #pragma nogcse
18914 \begin_inset LatexCommand \index{\#pragma nogcse}
18915
18916 \end_inset
18917
18918  \SpecialChar ~
18919 \SpecialChar ~
18920 \SpecialChar ~
18921 \SpecialChar ~
18922 \SpecialChar ~
18923 /* turnoff global subexpression elimination */ 
18924 \newline
18925 #pragma noinduction
18926 \begin_inset LatexCommand \index{\#pragma noinduction}
18927
18928 \end_inset
18929
18930  /* turn off induction optimizations */ 
18931 \newline
18932 int foo () 
18933 \newline
18934
18935 \newline
18936 \SpecialChar ~
18937  \SpecialChar ~
18938  ...
18939  
18940 \newline
18941 \SpecialChar ~
18942  \SpecialChar ~
18943  /* large code */ 
18944 \newline
18945 \SpecialChar ~
18946  \SpecialChar ~
18947  ...
18948  
18949 \newline
18950
18951 \newline
18952 #pragma restore
18953 \begin_inset LatexCommand \index{\#pragma restore}
18954
18955 \end_inset
18956
18957  /* turn the optimizations back on */
18958
18959 \layout Standard
18960 The compiler will generate a warning message when extra space is allocated.
18961  It is strongly recommended that the save and restore pragma's be used when
18962  changing options for a function.
18963 \newline
18964
18965 \newline
18966
18967 \newline
18968
18969
18970 \layout Section
18971 Defines Created by the Compiler
18972
18973 \layout Standard
18974 The compiler creates the following #defines
18975 \begin_inset LatexCommand \index{\#defines}
18976
18977 \end_inset
18978
18979
18980 \begin_inset LatexCommand \index{Defines created by the compiler}
18981
18982 \end_inset
18983
18984 :
18985 \newline
18986
18987
18988 \layout Standard
18989 \begin_inset Tabular
18990 <lyxtabular version="3" rows="11" columns="2">
18991 <features>
18992 <column alignment="left" valignment="top" leftline="true" width="3in">
18993 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
18994 <row topline="true" bottomline="true">
18995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18996 \begin_inset Text
18997
18998 \layout Standard
18999
19000 \series bold
19001 #define
19002
19003 \end_inset
19004 </cell>
19005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19006 \begin_inset Text
19007
19008 \layout Standard
19009
19010 \series bold
19011 Description
19012
19013 \end_inset
19014 </cell>
19015 </row>
19016 <row topline="true">
19017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19018 \begin_inset Text
19019
19020 \layout Standard
19021 SDCC
19022 \begin_inset LatexCommand \index{SDCC}
19023
19024 \end_inset
19025
19026  
19027
19028 \end_inset
19029 </cell>
19030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19031 \begin_inset Text
19032
19033 \layout Standard
19034 Always defined.
19035  Since version 2.5.6 the version number as an int (ex.
19036  256)
19037
19038 \end_inset
19039 </cell>
19040 </row>
19041 <row topline="true">
19042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19043 \begin_inset Text
19044
19045 \layout Standard
19046 SDCC_mcs51
19047 \begin_inset LatexCommand \index{SDCC\_mcs51}
19048
19049 \end_inset
19050
19051  or SDCC_ds390
19052 \begin_inset LatexCommand \index{SDCC\_ds390}
19053
19054 \end_inset
19055
19056  or SDCC_z80
19057 \begin_inset LatexCommand \index{SDCC\_z80}
19058
19059 \end_inset
19060
19061 , etc.
19062
19063 \end_inset
19064 </cell>
19065 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19066 \begin_inset Text
19067
19068 \layout Standard
19069 depending on the model used (e.g.: -mds390)
19070
19071 \end_inset
19072 </cell>
19073 </row>
19074 <row topline="true">
19075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19076 \begin_inset Text
19077
19078 \layout Standard
19079 __mcs51
19080 \begin_inset LatexCommand \index{\_\_mcs51}
19081
19082 \end_inset
19083
19084 , __ds390
19085 \begin_inset LatexCommand \index{\_\_ds390}
19086
19087 \end_inset
19088
19089 , __hc08
19090 \begin_inset LatexCommand \index{\_\_hc08}
19091
19092 \end_inset
19093
19094 , __z80
19095 \begin_inset LatexCommand \index{\_\_z80}
19096
19097 \end_inset
19098
19099 , etc
19100
19101 \end_inset
19102 </cell>
19103 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19104 \begin_inset Text
19105
19106 \layout Standard
19107 depending on the model used (e.g.
19108  -mz80)
19109
19110 \end_inset
19111 </cell>
19112 </row>
19113 <row topline="true">
19114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19115 \begin_inset Text
19116
19117 \layout Standard
19118 SDCC_STACK_AUTO
19119 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
19120
19121 \end_inset
19122
19123
19124
19125 \end_inset
19126 </cell>
19127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19128 \begin_inset Text
19129
19130 \layout Standard
19131 when 
19132 \emph on
19133 -
19134 \begin_inset ERT
19135 status Collapsed
19136
19137 \layout Standard
19138
19139
19140 \backslash
19141 /
19142
19143 \end_inset
19144
19145 -stack-auto
19146 \emph default
19147  option is used
19148
19149 \end_inset
19150 </cell>
19151 </row>
19152 <row topline="true">
19153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19154 \begin_inset Text
19155
19156 \layout Standard
19157 SDCC_MODEL_SMALL
19158 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
19159
19160 \end_inset
19161
19162
19163
19164 \end_inset
19165 </cell>
19166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19167 \begin_inset Text
19168
19169 \layout Standard
19170 when 
19171 \emph on
19172 -
19173 \begin_inset ERT
19174 status Collapsed
19175
19176 \layout Standard
19177
19178
19179 \backslash
19180 /
19181
19182 \end_inset
19183
19184 -model-small
19185 \emph default
19186  is used
19187
19188 \end_inset
19189 </cell>
19190 </row>
19191 <row topline="true">
19192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19193 \begin_inset Text
19194
19195 \layout Standard
19196 SDCC_MODEL_MEDIUM
19197 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
19198
19199 \end_inset
19200
19201
19202
19203 \end_inset
19204 </cell>
19205 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19206 \begin_inset Text
19207
19208 \layout Standard
19209 when 
19210 \emph on
19211 -
19212 \begin_inset ERT
19213 status Collapsed
19214
19215 \layout Standard
19216
19217
19218 \backslash
19219 /
19220
19221 \end_inset
19222
19223 -model-medium
19224 \emph default
19225  is used
19226
19227 \end_inset
19228 </cell>
19229 </row>
19230 <row topline="true">
19231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19232 \begin_inset Text
19233
19234 \layout Standard
19235 SDCC_MODEL_LARGE
19236 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
19237
19238 \end_inset
19239
19240
19241
19242 \end_inset
19243 </cell>
19244 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19245 \begin_inset Text
19246
19247 \layout Standard
19248 when 
19249 \emph on
19250 -
19251 \begin_inset ERT
19252 status Collapsed
19253
19254 \layout Standard
19255
19256
19257 \backslash
19258 /
19259
19260 \end_inset
19261
19262 -model-large
19263 \emph default
19264  is used
19265
19266 \end_inset
19267 </cell>
19268 </row>
19269 <row topline="true">
19270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19271 \begin_inset Text
19272
19273 \layout Standard
19274 SDCC_USE_XSTACK
19275 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
19276
19277 \end_inset
19278
19279
19280
19281 \end_inset
19282 </cell>
19283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19284 \begin_inset Text
19285
19286 \layout Standard
19287 when 
19288 \emph on
19289 -
19290 \begin_inset ERT
19291 status Collapsed
19292
19293 \layout Standard
19294
19295
19296 \backslash
19297 /
19298
19299 \end_inset
19300
19301 -xstack
19302 \emph default
19303  option is used
19304
19305 \end_inset
19306 </cell>
19307 </row>
19308 <row topline="true">
19309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19310 \begin_inset Text
19311
19312 \layout Standard
19313 SDCC_STACK_TENBIT
19314 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
19315
19316 \end_inset
19317
19318  
19319
19320 \end_inset
19321 </cell>
19322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19323 \begin_inset Text
19324
19325 \layout Standard
19326 when 
19327 \emph on
19328 -mds390
19329 \emph default
19330  is used
19331
19332 \end_inset
19333 </cell>
19334 </row>
19335 <row topline="true" bottomline="true">
19336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19337 \begin_inset Text
19338
19339 \layout Standard
19340 SDCC_MODEL_FLAT24
19341 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
19342
19343 \end_inset
19344
19345
19346
19347 \end_inset
19348 </cell>
19349 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19350 \begin_inset Text
19351
19352 \layout Standard
19353 when 
19354 \emph on
19355 -mds390
19356 \emph default
19357  is used
19358
19359 \end_inset
19360 </cell>
19361 </row>
19362 </lyxtabular>
19363
19364 \end_inset
19365
19366
19367
19368 \layout Chapter
19369 Notes on supported Processors
19370
19371 \layout Section
19372 MCS51 variants
19373 \begin_inset LatexCommand \label{sub:MCS51-variants}
19374
19375 \end_inset
19376
19377
19378 \begin_inset LatexCommand \index{MCS51 variants}
19379
19380 \end_inset
19381
19382
19383
19384 \layout Standard
19385 MCS51 processors are available from many vendors and come in many different
19386  flavours.
19387  While they might differ considerably in respect to Special Function Registers
19388  the core MCS51 is usually not modified or is kept compatible.
19389  
19390
19391 \layout Subsection
19392 pdata access by SFR 
19393
19394 \layout Standard
19395 With the upcome of devices with internal xdata and flash memory devices
19396  using port P2
19397 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
19398
19399 \end_inset
19400
19401  as dedicated I/O port is becoming more popular.
19402  Switching the high byte for pdata
19403 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
19404
19405 \end_inset
19406
19407  access which was formerly done by port P2 is then achieved by a Special
19408  Function Register
19409 \begin_inset LatexCommand \index{sfr}
19410
19411 \end_inset
19412
19413 .
19414  In well-established MCS51 tradition the address of this 
19415 \emph on
19416 sfr
19417 \emph default
19418  is where the chip designers decided to put it.
19419  Needless to say that they didn't agree on a common name either.
19420  So that the startup code can correctly initialize xdata variables, you
19421  should define an sfr with the name _XPAGE
19422 \family typewriter
19423
19424 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
19425
19426 \end_inset
19427
19428
19429 \family default
19430  at the appropriate location if the default, port P2, is not used for this.
19431  Some examples are:
19432
19433 \layout Verse
19434
19435 \family typewriter
19436 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family */
19437
19438 \layout Verse
19439
19440 \family typewriter
19441 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips */
19442
19443 \layout Verse
19444
19445 \family typewriter
19446 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips */
19447
19448 \layout Standard
19449 For more exotic implementations further customizations may be needed.
19450  See section 
19451 \begin_inset LatexCommand \ref{sub:Startup-Code}
19452
19453 \end_inset
19454
19455  for other possibilities.
19456
19457 \layout Subsection
19458 Other Features available by SFR
19459
19460 \layout Standard
19461 \added_space_bottom bigskip 
19462 Some MCS51 variants offer features like Double DPTR
19463 \begin_inset LatexCommand \index{DPTR}
19464
19465 \end_inset
19466
19467 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
19468  These are currently not used for the MCS51 port.
19469  If you absolutely need them you can fall back to inline assembly or submit
19470  a patch to SDCC.
19471
19472
19473
19474 \layout Section
19475 DS400 port
19476
19477 \layout Standard
19478 \added_space_bottom bigskip 
19479 The DS80C400
19480 \begin_inset LatexCommand \index{DS80C400}
19481
19482 \end_inset
19483
19484
19485 \begin_inset LatexCommand \index{DS400}
19486
19487 \end_inset
19488
19489  microcontroller has a rich set of peripherals.
19490  In its built-in ROM library it includes functions to access some of the
19491  features, among them is a TCP stack with IP4 and IP6 support.
19492  Library headers (currently in beta status) and other files are provided
19493  at 
19494 \size footnotesize
19495
19496 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
19497
19498 \end_inset
19499
19500 .
19501  
19502
19503
19504
19505 \layout Section
19506 The Z80 and gbz80 port
19507
19508 \layout Standard
19509 SDCC can target both the Zilog Z80
19510 \begin_inset LatexCommand \index{Z80}
19511
19512 \end_inset
19513
19514  and the Nintendo Gameboy's Z80-like gbz80
19515 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
19516
19517 \end_inset
19518
19519 .
19520  The Z80 port is passed through the same 
19521 \emph on
19522 regressions tests
19523 \begin_inset LatexCommand \index{Regression test}
19524
19525 \end_inset
19526
19527
19528 \emph default
19529  (see section 
19530 \begin_inset LatexCommand \ref{sec:Quality-control}
19531
19532 \end_inset
19533
19534 ) as the MCS51 and DS390 ports, so floating point support, support for long
19535  variables and bitfield support is fine.
19536  See mailing lists and forums about interrupt routines.
19537
19538 \layout Standard
19539 \added_space_bottom bigskip 
19540 As always, the code is the authoritative reference - see z80/ralloc.c and
19541  z80/gen.c.
19542  The stack
19543 \begin_inset LatexCommand \index{Z80!stack}
19544
19545 \end_inset
19546
19547  frame is similar to that generated by the IAR Z80 compiler.
19548  IX is used as the base pointer, HL and IY are used as a temporary registers,
19549  and BC and DE are available for holding variables.
19550  Return values
19551 \begin_inset LatexCommand \index{Z80!return value}
19552
19553 \end_inset
19554
19555  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
19556  bytes).
19557  The gbz80 port use the same set of registers for the return values, but
19558  in a different order of significance: E (one byte), DE (two bytes), or
19559  HLDE (four bytes).
19560
19561
19562
19563 \layout Section
19564 The HC08 port
19565
19566 \layout Standard
19567 The port to the Freescale/Motorola HC08
19568 \begin_inset LatexCommand \index{HC08}
19569
19570 \end_inset
19571
19572  family has been added in October 2003, and is still undergoing some basic
19573  development.
19574  The code generator is complete, but the register allocation is still quite
19575  unoptimized.
19576  Some of the SDCC's standard C library functions have embedded non-HC08
19577  inline assembly and so are not yet usable.
19578
19579 \layout Standard
19580 \added_space_bottom bigskip 
19581 \pagebreak_bottom 
19582 The HC08 port passes the regression test suite (see section 
19583 \begin_inset LatexCommand \ref{sec:Quality-control}
19584
19585 \end_inset
19586
19587 ).
19588
19589
19590
19591
19592 \layout Section
19593 The PIC14 port
19594
19595 \layout Standard
19596 The 14bit PIC
19597 \begin_inset LatexCommand \index{PIC14}
19598
19599 \end_inset
19600
19601  port still requires a major effort from the development community.
19602  However it can work for simple code.
19603  It passes its (smaller set of) regression tests
19604 \begin_inset LatexCommand \index{Regression test (PIC14)}
19605
19606 \end_inset
19607
19608  in the directory 
19609 \shape italic
19610 sdcc/src/regression
19611 \shape default
19612 .
19613
19614 \layout Subsection
19615 C code and 14bit PIC code page
19616 \begin_inset LatexCommand \index{code page (pic14)}
19617
19618 \end_inset
19619
19620  and RAM banks
19621 \begin_inset LatexCommand \index{RAM bank (pic14)}
19622
19623 \end_inset
19624
19625
19626
19627 \layout Standard
19628 The linker organizes allocation for the code page and RAM banks.
19629  It does not have intimate knowledge of the code flow.
19630  It will put all the code section of a single asm file into a single code
19631  page.
19632  In order to make use of multiple code pages, separate asm files must be
19633  used.
19634  The compiler treats all functions of a single C file as being in the same
19635  code page unless it is non static.
19636 \newline
19637
19638 \newline
19639 To get the best follow these guide lines:
19640
19641 \layout Enumerate
19642 Make local functions static, as non static functions require code page selection
19643  overhead.
19644
19645 \layout Enumerate
19646 For devices that have multiple code pages it is more efficient to use the
19647  same number of files as pages, i.e.
19648  for the 16F877 use 4 separate files and i.e.
19649  for the 16F874 use 2 separate files.
19650  This way the linker can put the code for each file into different code
19651  pages and there's less page selection overhead.
19652
19653 \layout Enumerate
19654  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
19655  instruction set), use 'unsigned char' whereever possible instead of 'int'.
19656
19657 \layout Subsection
19658 Creating a device include file 
19659
19660 \layout Standard
19661 For generating a device include file
19662 \begin_inset LatexCommand \index{PIC14!Header files}
19663
19664 \end_inset
19665
19666  use the support perl script inc2h.pl kept in directory support/script.
19667
19668 \layout Subsection
19669 Interrupt code
19670
19671 \layout Standard
19672 For the interrupt function, use the keyword '__interrupt'
19673 \begin_inset LatexCommand \index{PIC14!interrupt}
19674
19675 \end_inset
19676
19677  with level number of 0 (PIC14 only has 1 interrupt so this number is only
19678  there to avoid a syntax error - it ought to be fixed).
19679  E.g.:
19680
19681 \layout Verse
19682
19683 \family typewriter
19684 void Intr(void) __interrupt 0
19685 \newline
19686 {
19687 \newline
19688 \SpecialChar ~
19689 \SpecialChar ~
19690 T0IF = 0; /* Clear timer interrupt */
19691 \newline
19692 }
19693
19694 \layout Subsection
19695 Linking and assembling
19696
19697 \layout Standard
19698 For assembling you can use either GPUTILS'
19699 \begin_inset LatexCommand \index{gputils (pic tools)}
19700
19701 \end_inset
19702
19703  gpasm.exe or MPLAB's mpasmwin.exe.
19704  GPUTILS is available from 
19705 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
19706
19707 \end_inset
19708
19709 .
19710  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
19711  If you use MPLAB and an interrupt function then the linker script file
19712  vectors section will need to be enlarged to link with mplink.
19713 \newline
19714
19715 \newline
19716 Here is a 
19717 \family typewriter
19718 Makefile
19719 \family default
19720  using GPUTILS:
19721
19722 \layout Verse
19723
19724 \family typewriter
19725 .c.o:
19726 \newline
19727 \SpecialChar ~
19728 \SpecialChar ~
19729 \SpecialChar ~
19730 \SpecialChar ~
19731 \SpecialChar ~
19732 \SpecialChar ~
19733 \SpecialChar ~
19734 \SpecialChar ~
19735 sdcc -S -V -mpic14 -p16F877 $< 
19736 \newline
19737 \SpecialChar ~
19738 \SpecialChar ~
19739 \SpecialChar ~
19740 \SpecialChar ~
19741 \SpecialChar ~
19742 \SpecialChar ~
19743 \SpecialChar ~
19744 \SpecialChar ~
19745 gpasm -c $*.asm
19746 \newline
19747
19748 \newline
19749 $(PRJ).hex: $(OBJS) 
19750 \newline
19751 \SpecialChar ~
19752 \SpecialChar ~
19753 \SpecialChar ~
19754 \SpecialChar ~
19755 \SpecialChar ~
19756 \SpecialChar ~
19757 \SpecialChar ~
19758 \SpecialChar ~
19759 gplink
19760  -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
19761
19762 \layout Standard
19763 Here is a 
19764 \family typewriter
19765 Makefile
19766 \family default
19767  using MPLAB:
19768
19769 \layout Verse
19770
19771 \family typewriter
19772 .c.o: 
19773 \newline
19774 \SpecialChar ~
19775 \SpecialChar ~
19776 \SpecialChar ~
19777 \SpecialChar ~
19778 \SpecialChar ~
19779 \SpecialChar ~
19780 \SpecialChar ~
19781 \SpecialChar ~
19782 sdcc -S -V -mpic14 -p16F877 $< 
19783 \newline
19784 \SpecialChar ~
19785 \SpecialChar ~
19786 \SpecialChar ~
19787 \SpecialChar ~
19788 \SpecialChar ~
19789 \SpecialChar ~
19790 \SpecialChar ~
19791 \SpecialChar ~
19792 mpasmwin /q /o $*.asm
19793 \newline
19794
19795 \newline
19796 $(PRJ).hex: $(OBJS)
19797  
19798 \newline
19799 \SpecialChar ~
19800 \SpecialChar ~
19801 \SpecialChar ~
19802 \SpecialChar ~
19803 \SpecialChar ~
19804 \SpecialChar ~
19805 \SpecialChar ~
19806 \SpecialChar ~
19807 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
19808
19809 \layout Standard
19810 Please note that indentations within a
19811 \family typewriter
19812  Makefile
19813 \family default
19814  have to be done with a tabulator character.
19815
19816 \layout Subsection
19817 Command-line options
19818
19819 \layout Standard
19820 Besides the switches common to all SDCC backends, the PIC14 port accepts
19821  the following options (for an updated list see sdcc -
19822 \begin_inset ERT
19823 status Collapsed
19824
19825 \layout Standard
19826
19827
19828 \backslash
19829 /
19830
19831 \end_inset
19832
19833 -help):
19834
19835 \layout List
19836 \labelwidthstring 00.00.0000
19837 -
19838 \begin_inset ERT
19839 status Collapsed
19840
19841 \layout Standard
19842
19843
19844 \backslash
19845 /
19846
19847 \end_inset
19848
19849 -debug-extra
19850 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
19851
19852 \end_inset
19853
19854  emit debug info in assembly output
19855
19856 \layout List
19857 \labelwidthstring 00.00.0000
19858 -
19859 \begin_inset ERT
19860 status Collapsed
19861
19862 \layout Standard
19863
19864
19865 \backslash
19866 /
19867
19868 \end_inset
19869
19870 -no-pcode-opt
19871 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
19872
19873 \end_inset
19874
19875  disable (slightly faulty) optimization on pCode
19876
19877 \layout List
19878 \labelwidthstring 00.00.0000
19879 -
19880 \begin_inset ERT
19881 status Collapsed
19882
19883 \layout Standard
19884
19885
19886 \backslash
19887 /
19888
19889 \end_inset
19890
19891 -stack-loc
19892 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
19893
19894 \end_inset
19895
19896  sets the lowest address of the argument passing stack (defaults to a suitably
19897  large shared databank to reduce BANKSEL overhead)
19898
19899 \layout List
19900 \labelwidthstring 00.00.0000
19901 -
19902 \begin_inset ERT
19903 status Collapsed
19904
19905 \layout Standard
19906
19907
19908 \backslash
19909 /
19910
19911 \end_inset
19912
19913 -stack-size
19914 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
19915
19916 \end_inset
19917
19918  sets the size if the argument passing stack (default: 16, minimum: 4)
19919
19920 \layout Subsection
19921 The library
19922
19923 \layout Subsubsection
19924 error: missing definition for symbol 
19925 \begin_inset Quotes sld
19926 \end_inset
19927
19928 __gptrget1
19929 \begin_inset Quotes srd
19930 \end_inset
19931
19932
19933
19934 \layout Standard
19935 The PIC14 port uses library routines to provide more complex operations
19936  like multiplication, division/modulus and (generic) pointer dereferencing.
19937  In order to add these routines to your project, you must link with PIC14's
19938  
19939 \family typewriter
19940 libsdcc.lib
19941 \family default
19942 .
19943  For single source file projects this is done automatically, more complex
19944  projects must add 
19945 \family typewriter
19946 libsdcc.lib
19947 \family default
19948  to the linker's arguments.
19949  Make sure you also add an include path for the library (using the -I switch
19950  to the linker)!
19951
19952 \layout Subsubsection
19953 Processor mismatch in file 
19954 \begin_inset Quotes sld
19955 \end_inset
19956
19957 XXX
19958 \begin_inset Quotes srd
19959 \end_inset
19960
19961 .
19962
19963 \layout Standard
19964 This warning can usually be ignored due to the very good compatibility amongst
19965  14 bit PIC
19966 \begin_inset LatexCommand \index{PIC14}
19967
19968 \end_inset
19969
19970  devices.
19971
19972 \layout Standard
19973 You might also consider recompiling the library for your specific device
19974  by changing the ARCH=p16f877 (default target) entry in 
19975 \family typewriter
19976 device/lib/pic/Makefile.in
19977 \family default
19978  and 
19979 \family typewriter
19980 device/lib/pic/Makefile
19981 \family default
19982  to reflect your device.
19983  This might even improve performance for smaller devices as unneccesary
19984  BANKSELs migth be removed.
19985
19986 \layout Subsection
19987 Known bugs
19988
19989 \layout Subsubsection
19990 initialized data
19991
19992 \layout Standard
19993 Currently, data can only be initialized if it resides in the source file
19994 \pagebreak_bottom 
19995  together with 
19996 \emph on
19997 main()
19998 \emph default
19999 .
20000  Data in other source files will silently 
20001 \series bold
20002 not
20003 \series default
20004  be initialized.
20005 \family typewriter
20006 \size footnotesize
20007
20008 \begin_inset Marginal
20009 collapsed true
20010
20011 \layout Standard
20012
20013 \series bold
20014 \SpecialChar ~
20015 !
20016
20017 \end_inset
20018
20019
20020
20021
20022 \layout Section
20023 The PIC16
20024 \begin_inset LatexCommand \index{PIC16}
20025
20026 \end_inset
20027
20028  port
20029
20030 \layout Standard
20031 The PIC16
20032 \begin_inset LatexCommand \index{PIC16}
20033
20034 \end_inset
20035
20036  port is the portion of SDCC that is responsible to produce code for the
20037  Microchip
20038 \begin_inset LatexCommand \index{Microchip}
20039
20040 \end_inset
20041
20042 (TM) microcontrollers with 16 bit core.
20043  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
20044  Currently supported devices are:
20045
20046 \layout Standard
20047 \align center
20048 \begin_inset Tabular
20049 <lyxtabular version="3" rows="4" columns="6">
20050 <features>
20051 <column alignment="center" valignment="top" leftline="true" width="0">
20052 <column alignment="center" valignment="top" leftline="true" width="0">
20053 <column alignment="center" valignment="top" leftline="true" width="0">
20054 <column alignment="center" valignment="top" leftline="true" width="0">
20055 <column alignment="center" valignment="top" leftline="true" width="0">
20056 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20057 <row topline="true">
20058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20059 \begin_inset Text
20060
20061 \layout Standard
20062 18F242
20063
20064 \end_inset
20065 </cell>
20066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20067 \begin_inset Text
20068
20069 \layout Standard
20070 18F248
20071
20072 \end_inset
20073 </cell>
20074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20075 \begin_inset Text
20076
20077 \layout Standard
20078 18F252
20079
20080 \end_inset
20081 </cell>
20082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20083 \begin_inset Text
20084
20085 \layout Standard
20086 18F258
20087
20088 \end_inset
20089 </cell>
20090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20091 \begin_inset Text
20092
20093 \layout Standard
20094 18F442
20095
20096 \end_inset
20097 </cell>
20098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20099 \begin_inset Text
20100
20101 \layout Standard
20102 18F448
20103
20104 \end_inset
20105 </cell>
20106 </row>
20107 <row topline="true">
20108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20109 \begin_inset Text
20110
20111 \layout Standard
20112 18F452
20113
20114 \end_inset
20115 </cell>
20116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20117 \begin_inset Text
20118
20119 \layout Standard
20120 18F458
20121
20122 \end_inset
20123 </cell>
20124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20125 \begin_inset Text
20126
20127 \layout Standard
20128 18F1220
20129
20130 \end_inset
20131 </cell>
20132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20133 \begin_inset Text
20134
20135 \layout Standard
20136 18F2220
20137
20138 \end_inset
20139 </cell>
20140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20141 \begin_inset Text
20142
20143 \layout Standard
20144 18F2550
20145
20146 \end_inset
20147 </cell>
20148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20149 \begin_inset Text
20150
20151 \layout Standard
20152 18F4331
20153
20154 \end_inset
20155 </cell>
20156 </row>
20157 <row topline="true">
20158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20159 \begin_inset Text
20160
20161 \layout Standard
20162 18F4455
20163
20164 \end_inset
20165 </cell>
20166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20167 \begin_inset Text
20168
20169 \layout Standard
20170 18F6520
20171
20172 \end_inset
20173 </cell>
20174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20175 \begin_inset Text
20176
20177 \layout Standard
20178 18F6620
20179
20180 \end_inset
20181 </cell>
20182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20183 \begin_inset Text
20184
20185 \layout Standard
20186 18F6680
20187
20188 \end_inset
20189 </cell>
20190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20191 \begin_inset Text
20192
20193 \layout Standard
20194 18F6720
20195
20196 \end_inset
20197 </cell>
20198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20199 \begin_inset Text
20200
20201 \layout Standard
20202 18F8520
20203
20204 \end_inset
20205 </cell>
20206 </row>
20207 <row topline="true" bottomline="true">
20208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20209 \begin_inset Text
20210
20211 \layout Standard
20212 18F8620
20213
20214 \end_inset
20215 </cell>
20216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20217 \begin_inset Text
20218
20219 \layout Standard
20220 18F8680
20221
20222 \end_inset
20223 </cell>
20224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20225 \begin_inset Text
20226
20227 \layout Standard
20228 18F8720
20229
20230 \end_inset
20231 </cell>
20232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20233 \begin_inset Text
20234
20235 \layout Standard
20236
20237
20238 \end_inset
20239 </cell>
20240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20241 \begin_inset Text
20242
20243 \layout Standard
20244
20245
20246 \end_inset
20247 </cell>
20248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20249 \begin_inset Text
20250
20251 \layout Standard
20252
20253
20254 \end_inset
20255 </cell>
20256 </row>
20257 </lyxtabular>
20258
20259 \end_inset
20260
20261
20262
20263 \layout Subsection
20264 Global Options
20265
20266 \layout Standard
20267 PIC16 port supports the standard command line arguments as supposed, with
20268  the exception of certain cases that will be mentioned in the following
20269  list:
20270
20271 \layout List
20272 \labelwidthstring 00.00.0000
20273 -
20274 \begin_inset ERT
20275 status Collapsed
20276
20277 \layout Standard
20278
20279
20280 \backslash
20281 /
20282
20283 \end_inset
20284
20285 -callee-saves
20286 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
20287
20288 \end_inset
20289
20290  See -
20291 \begin_inset ERT
20292 status Collapsed
20293
20294 \layout Standard
20295
20296
20297 \backslash
20298 /
20299
20300 \end_inset
20301
20302 -all-callee-saves
20303
20304 \layout List
20305 \labelwidthstring 00.00.0000
20306 -
20307 \begin_inset ERT
20308 status Collapsed
20309
20310 \layout Standard
20311
20312
20313 \backslash
20314 /
20315
20316 \end_inset
20317
20318 -all-callee-saves
20319 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
20320
20321 \end_inset
20322
20323  All function arguments are passed on stack by default.
20324  
20325 \emph on
20326 There is no need to specify this in the command line.
20327
20328 \layout List
20329 \labelwidthstring 00.00.0000
20330 -
20331 \begin_inset ERT
20332 status Collapsed
20333
20334 \layout Standard
20335
20336
20337 \backslash
20338 /
20339
20340 \end_inset
20341
20342 -fommit-frame-pointer
20343 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
20344
20345 \end_inset
20346
20347  Frame pointer will be omitted when the function uses no local variables.
20348
20349 \layout Subsection
20350 Port Specific Options
20351 \begin_inset LatexCommand \index{Options PIC16}
20352
20353 \end_inset
20354
20355
20356
20357 \layout Standard
20358 The port specific options appear after the global options in the sdcc --help
20359  output.
20360
20361 \layout Subsubsection
20362 General Options
20363
20364 \layout Standard
20365 General options enable certain port features and optimizations.
20366
20367 \layout List
20368 \labelwidthstring 00.00.0000
20369 -
20370 \begin_inset ERT
20371 status Collapsed
20372
20373 \layout Standard
20374
20375
20376 \backslash
20377 /
20378
20379 \end_inset
20380
20381 -pstack-model=[model] Used in conjuction with the command above.
20382  Defines the stack model to be used, valid stack models are : 
20383
20384 \begin_deeper
20385 \layout List
20386 \labelwidthstring 00.00.0000
20387
20388 \emph on
20389 small
20390 \emph default
20391  Selects small stack model.
20392  8 bit stack and frame pointers.
20393  Supports 256 bytes stack size.
20394
20395 \layout List
20396 \labelwidthstring 00.00.0000
20397
20398 \emph on
20399 large
20400 \emph default
20401  Selects large stack model.
20402  16 bit stack and frame pointers.
20403  Supports 65536 bytes stack size.
20404
20405 \end_deeper
20406 \layout List
20407 \labelwidthstring 00.00.0000
20408 -
20409 \begin_inset ERT
20410 status Collapsed
20411
20412 \layout Standard
20413
20414
20415 \backslash
20416 /
20417
20418 \end_inset
20419
20420 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
20421  unitialized data variables with [kword].
20422  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
20423
20424 \layout List
20425 \labelwidthstring 00.00.0000
20426 -
20427 \begin_inset ERT
20428 status Collapsed
20429
20430 \layout Standard
20431
20432
20433 \backslash
20434 /
20435
20436 \end_inset
20437
20438 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
20439  Useful for bootloaders.
20440
20441 \layout List
20442 \labelwidthstring 00.00.0000
20443 -
20444 \begin_inset ERT
20445 status Collapsed
20446
20447 \layout Standard
20448
20449
20450 \backslash
20451 /
20452
20453 \end_inset
20454
20455 -asm= sets the full path and name of an external assembler to call.
20456
20457 \layout List
20458 \labelwidthstring 00.00.0000
20459 -
20460 \begin_inset ERT
20461 status Collapsed
20462
20463 \layout Standard
20464
20465
20466 \backslash
20467 /
20468
20469 \end_inset
20470
20471 -link= sets the full path and name of an external linker to call.
20472
20473 \layout List
20474 \labelwidthstring 00.00.0000
20475 -
20476 \begin_inset ERT
20477 status Collapsed
20478
20479 \layout Standard
20480
20481
20482 \backslash
20483 /
20484
20485 \end_inset
20486
20487 -mplab-comp MPLAB
20488 \begin_inset LatexCommand \index{PIC16!MPLAB}
20489
20490 \end_inset
20491
20492  compatibility option.
20493  Currently only suppresses special gpasm directives.
20494
20495 \layout Subsubsection
20496 Optimization Options
20497
20498 \layout List
20499 \labelwidthstring 00.00.0000
20500 -
20501 \begin_inset ERT
20502 status Collapsed
20503
20504 \layout Standard
20505
20506
20507 \backslash
20508 /
20509
20510 \end_inset
20511
20512 -optimize-goto Try to use (conditional) BRA instead of GOTO
20513
20514 \layout List
20515 \labelwidthstring 00.00.0000
20516 -
20517 \begin_inset ERT
20518 status Collapsed
20519
20520 \layout Standard
20521
20522
20523 \backslash
20524 /
20525
20526 \end_inset
20527
20528 -optimize-cmp Try to optimize some compares.
20529
20530 \layout List
20531 \labelwidthstring 00.00.0000
20532 -
20533 \begin_inset ERT
20534 status Collapsed
20535
20536 \layout Standard
20537
20538
20539 \backslash
20540 /
20541
20542 \end_inset
20543
20544 -optimize-df Analyze the dataflow of the generated code and improve it.
20545
20546 \layout List
20547 \labelwidthstring 00.00.0000
20548 -
20549 \begin_inset ERT
20550 status Collapsed
20551
20552 \layout Standard
20553
20554
20555 \backslash
20556 /
20557
20558 \end_inset
20559
20560 -obanksel=nn Set optimization level for inserting BANKSELs.
20561 \newline
20562
20563
20564 \begin_deeper
20565 \layout List
20566 \labelwidthstring 00.00.0000
20567 0 no optimization
20568
20569 \layout List
20570 \labelwidthstring 00.00.0000
20571 1 checks previous used register and if it is the same then does not emit
20572  BANKSEL, accounts only for labels.
20573
20574 \layout List
20575 \labelwidthstring 00.00.0000
20576 2 tries to check the location of (even different) symbols and removes BANKSELs
20577  if they are in the same bank.
20578  
20579 \newline
20580
20581 \emph on
20582 Important: There might be problems if the linker script has data sections
20583  across bank borders!
20584
20585 \end_deeper
20586 \layout Subsubsection
20587 Linking Options
20588
20589 \layout List
20590 \labelwidthstring 00.00.0000
20591 -
20592 \begin_inset ERT
20593 status Collapsed
20594
20595 \layout Standard
20596
20597
20598 \backslash
20599 /
20600
20601 \end_inset
20602
20603 -nodefaultlibs do not link default libraries when linking
20604
20605 \layout List
20606 \labelwidthstring 00.00.0000
20607 -
20608 \begin_inset ERT
20609 status Collapsed
20610
20611 \layout Standard
20612
20613
20614 \backslash
20615 /
20616
20617 \end_inset
20618
20619 -no-crt Don't link the default run-time modules
20620
20621 \layout List
20622 \labelwidthstring 00.00.0000
20623 -
20624 \begin_inset ERT
20625 status Collapsed
20626
20627 \layout Standard
20628
20629
20630 \backslash
20631 /
20632
20633 \end_inset
20634
20635 -use-crt= Use a custom run-time module instead of the defaults.
20636
20637 \layout Subsubsection
20638 Debugging Options
20639
20640 \layout Standard
20641 Debugging options enable extra debugging information in the output files.
20642
20643 \layout List
20644 \labelwidthstring 00.00.0000
20645 -
20646 \begin_inset ERT
20647 status Collapsed
20648
20649 \layout Standard
20650
20651
20652 \backslash
20653 /
20654
20655 \end_inset
20656
20657 -debug-xtra Similar to -
20658 \begin_inset ERT
20659 status Collapsed
20660
20661 \layout Standard
20662
20663
20664 \backslash
20665 /
20666
20667 \end_inset
20668
20669 -debug
20670 \begin_inset LatexCommand \index{-\/-debug}
20671
20672 \end_inset
20673
20674 , but dumps more information.
20675
20676 \layout List
20677 \labelwidthstring 00.00.0000
20678 -
20679 \begin_inset ERT
20680 status Collapsed
20681
20682 \layout Standard
20683
20684
20685 \backslash
20686 /
20687
20688 \end_inset
20689
20690 -debug-ralloc Force register allocator to dump <source>.d file with debugging
20691  information.
20692  <source> is the name of the file compiled.
20693
20694 \layout List
20695 \labelwidthstring 00.00.0000
20696 -
20697 \begin_inset ERT
20698 status Collapsed
20699
20700 \layout Standard
20701
20702
20703 \backslash
20704 /
20705
20706 \end_inset
20707
20708 -pcode-verbose Enable pcode debugging information in translation.
20709
20710 \layout List
20711 \labelwidthstring 00.00.0000
20712 -
20713 \begin_inset ERT
20714 status Collapsed
20715
20716 \layout Standard
20717
20718
20719 \backslash
20720 /
20721
20722 \end_inset
20723
20724 -denable-peeps Force the usage of peepholes.
20725  Use with care.
20726
20727 \layout List
20728 \labelwidthstring 00.00.0000
20729 -
20730 \begin_inset ERT
20731 status Collapsed
20732
20733 \layout Standard
20734
20735
20736 \backslash
20737 /
20738
20739 \end_inset
20740
20741 -gstack Trace push/pops for stack pointer overflow
20742
20743 \layout List
20744 \labelwidthstring 00.00.0000
20745 -
20746 \begin_inset ERT
20747 status Collapsed
20748
20749 \layout Standard
20750
20751
20752 \backslash
20753 /
20754
20755 \end_inset
20756
20757 -call-tree dump call tree in .calltree file
20758
20759 \layout Subsection
20760 Enviromental Variables
20761
20762 \layout Standard
20763 There is a number of enviromental variables that can be used when running
20764  SDCC to enable certain optimizations or force a specific program behaviour.
20765  these variables are primarily for debugging purposes so they can be enabled/dis
20766 abled at will.
20767
20768 \layout Standard
20769 Currently there is only two such variables available:
20770
20771 \layout List
20772 \labelwidthstring 00.00.0000
20773 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
20774  bitfields is optimized by directly loading FSR0 with the address of the
20775  bitfield structure.
20776  Normally SDCC will cast the bitfield structure to a bitfield pointer and
20777  then load FSR0.
20778  This step saves data ram and code space for functions that perform heavy
20779  use of bitfields.
20780  (ie.
20781  80 bytes of code space are saved when compiling malloc.c with this option).
20782  
20783
20784 \layout List
20785 \labelwidthstring 00.00.0000
20786 NO_REG_OPT do not perform pCode registers optimization.
20787  This should be used for debugging purposes.
20788  In some where bugs in the pcode optimizer are found, users can benefit
20789  from temporarily disabling the optimizer until the bug is fixed.
20790
20791 \layout Subsection
20792 Preprocessor Macros
20793
20794 \layout Standard
20795 PIC16
20796 \begin_inset LatexCommand \index{PIC16}
20797
20798 \end_inset
20799
20800  port defines the following preprocessor macros while translating a source.
20801
20802 \layout Standard
20803 \align center
20804 \begin_inset Tabular
20805 <lyxtabular version="3" rows="6" columns="2">
20806 <features>
20807 <column alignment="center" valignment="top" leftline="true" width="0">
20808 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20809 <row topline="true" bottomline="true">
20810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20811 \begin_inset Text
20812
20813 \layout Standard
20814 Macro
20815
20816 \end_inset
20817 </cell>
20818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20819 \begin_inset Text
20820
20821 \layout Standard
20822 Description
20823
20824 \end_inset
20825 </cell>
20826 </row>
20827 <row topline="true">
20828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20829 \begin_inset Text
20830
20831 \layout Standard
20832 SDCC_pic16
20833
20834 \end_inset
20835 </cell>
20836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20837 \begin_inset Text
20838
20839 \layout Standard
20840 Port identification
20841
20842 \end_inset
20843 </cell>
20844 </row>
20845 <row topline="true">
20846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20847 \begin_inset Text
20848
20849 \layout Standard
20850 _
20851 \begin_inset ERT
20852 status Collapsed
20853
20854 \layout Standard
20855
20856
20857 \backslash
20858 /
20859
20860 \end_inset
20861
20862 _pic16
20863
20864 \end_inset
20865 </cell>
20866 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20867 \begin_inset Text
20868
20869 \layout Standard
20870 Port identification (same as above)
20871
20872 \end_inset
20873 </cell>
20874 </row>
20875 <row topline="true">
20876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20877 \begin_inset Text
20878
20879 \layout Standard
20880 pic18fxxxx
20881
20882 \end_inset
20883 </cell>
20884 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20885 \begin_inset Text
20886
20887 \layout Standard
20888 MCU Identification.
20889  
20890 \emph on
20891 xxxx
20892 \emph default
20893  is the microcontrol identification number, i.e.
20894  452, 6620, etc
20895
20896 \end_inset
20897 </cell>
20898 </row>
20899 <row topline="true">
20900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20901 \begin_inset Text
20902
20903 \layout Standard
20904 _
20905 \begin_inset ERT
20906 status Collapsed
20907
20908 \layout Standard
20909
20910
20911 \backslash
20912 /
20913
20914 \end_inset
20915
20916 _18Fxxxx
20917
20918 \end_inset
20919 </cell>
20920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20921 \begin_inset Text
20922
20923 \layout Standard
20924 MCU Identification (same as above)
20925
20926 \end_inset
20927 </cell>
20928 </row>
20929 <row topline="true" bottomline="true">
20930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20931 \begin_inset Text
20932
20933 \layout Standard
20934 STACK_MODEL_nnn
20935
20936 \end_inset
20937 </cell>
20938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20939 \begin_inset Text
20940
20941 \layout Standard
20942 nnn = SMALL or LARGE respectively according to the stack model used
20943
20944 \end_inset
20945 </cell>
20946 </row>
20947 </lyxtabular>
20948
20949 \end_inset
20950
20951
20952
20953 \layout Standard
20954 In addition the following macros are defined when calling assembler:
20955
20956 \layout Standard
20957 \align center
20958 \begin_inset Tabular
20959 <lyxtabular version="3" rows="4" columns="2">
20960 <features>
20961 <column alignment="center" valignment="top" leftline="true" width="0">
20962 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20963 <row topline="true" bottomline="true">
20964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20965 \begin_inset Text
20966
20967 \layout Standard
20968 Macro
20969
20970 \end_inset
20971 </cell>
20972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20973 \begin_inset Text
20974
20975 \layout Standard
20976 Description
20977
20978 \end_inset
20979 </cell>
20980 </row>
20981 <row topline="true">
20982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20983 \begin_inset Text
20984
20985 \layout Standard
20986 __18Fxxxx
20987
20988 \end_inset
20989 </cell>
20990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20991 \begin_inset Text
20992
20993 \layout Standard
20994 MCU Identification.
20995  
20996 \emph on
20997 xxxx
20998 \emph default
20999  is the microcontrol identification number, i.e.
21000  452, 6620, etc
21001
21002 \end_inset
21003 </cell>
21004 </row>
21005 <row topline="true">
21006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21007 \begin_inset Text
21008
21009 \layout Standard
21010 SDCC_MODEL_nnn
21011
21012 \end_inset
21013 </cell>
21014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21015 \begin_inset Text
21016
21017 \layout Standard
21018 nnn = SMALL or LARGE respectively according to the memory model used for
21019  SDCC
21020
21021 \end_inset
21022 </cell>
21023 </row>
21024 <row topline="true" bottomline="true">
21025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21026 \begin_inset Text
21027
21028 \layout Standard
21029 STACK_MODEL_nnn
21030
21031 \end_inset
21032 </cell>
21033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21034 \begin_inset Text
21035
21036 \layout Standard
21037 nnn = SMALL or LARGE respectively according to the stack model used
21038
21039 \end_inset
21040 </cell>
21041 </row>
21042 </lyxtabular>
21043
21044 \end_inset
21045
21046
21047
21048 \layout Subsection
21049 Directories
21050
21051 \layout Standard
21052 PIC16
21053 \begin_inset LatexCommand \index{PIC16}
21054
21055 \end_inset
21056
21057  port uses the following directories for searching header files and libraries.
21058
21059 \layout Standard
21060 \align center
21061 \begin_inset Tabular
21062 <lyxtabular version="3" rows="3" columns="4">
21063 <features>
21064 <column alignment="center" valignment="top" leftline="true" width="0">
21065 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21066 <column alignment="center" valignment="top" width="0">
21067 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21068 <row topline="true" bottomline="true">
21069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21070 \begin_inset Text
21071
21072 \layout Standard
21073 Directory
21074
21075 \end_inset
21076 </cell>
21077 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21078 \begin_inset Text
21079
21080 \layout Standard
21081 Description
21082
21083 \end_inset
21084 </cell>
21085 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21086 \begin_inset Text
21087
21088 \layout Standard
21089 Target
21090
21091 \end_inset
21092 </cell>
21093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21094 \begin_inset Text
21095
21096 \layout Standard
21097 Command prefix
21098
21099 \end_inset
21100 </cell>
21101 </row>
21102 <row topline="true">
21103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21104 \begin_inset Text
21105
21106 \layout Standard
21107 PREFIX/sdcc/include/pic16
21108
21109 \end_inset
21110 </cell>
21111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21112 \begin_inset Text
21113
21114 \layout Standard
21115 PIC16 specific headers
21116
21117 \end_inset
21118 </cell>
21119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21120 \begin_inset Text
21121
21122 \layout Standard
21123 Compiler
21124
21125 \end_inset
21126 </cell>
21127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21128 \begin_inset Text
21129
21130 \layout Standard
21131 -I
21132
21133 \end_inset
21134 </cell>
21135 </row>
21136 <row topline="true" bottomline="true">
21137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21138 \begin_inset Text
21139
21140 \layout Standard
21141 PREFIX/sdcc/lib/pic16
21142
21143 \end_inset
21144 </cell>
21145 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21146 \begin_inset Text
21147
21148 \layout Standard
21149 PIC16 specific libraries
21150
21151 \end_inset
21152 </cell>
21153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21154 \begin_inset Text
21155
21156 \layout Standard
21157 Linker
21158
21159 \end_inset
21160 </cell>
21161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21162 \begin_inset Text
21163
21164 \layout Standard
21165 -L
21166
21167 \end_inset
21168 </cell>
21169 </row>
21170 </lyxtabular>
21171
21172 \end_inset
21173
21174
21175
21176 \layout Subsection
21177 Pragmas
21178 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
21179
21180 \end_inset
21181
21182
21183
21184 \layout Standard
21185 PIC16
21186 \begin_inset LatexCommand \index{PIC16}
21187
21188 \end_inset
21189
21190  port currently supports the following pragmas:
21191
21192 \layout List
21193 \labelwidthstring 00.00.0000
21194 stack
21195 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
21196
21197 \end_inset
21198
21199  pragma stack
21200 \begin_inset LatexCommand \index{PIC16!stack}
21201
21202 \end_inset
21203
21204  forces the code generator to initialize the stack & frame pointers at a
21205  specific address.
21206  This is an adhoc solution for cases where no STACK directive is available
21207  in the linker script or gplink is not instructed to create a stack section.
21208 \newline
21209 The
21210  stack pragma should be used only once in a project.
21211  Multiple pragmas may result in indeterminate behaviour of the program.
21212 \begin_inset Foot
21213 collapsed false
21214
21215 \layout Standard
21216 The old format (ie.
21217  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
21218  cross page boundaries (or even exceed the available data RAM) and crash
21219  the program.
21220  Make sure that stack does not cross page boundaries when using the SMALL
21221  stack model.
21222
21223 \end_inset
21224
21225
21226 \newline
21227 The format is as follows:
21228
21229 \layout LyX-Code
21230 #pragma stack bottom_address [stack_size]
21231
21232 \layout Standard
21233
21234 \emph on
21235 bottom_address
21236 \emph default
21237  is the lower bound of the stack section.
21238  The stack pointer initially will point at address (bottom_address+stack_size-1).
21239
21240 \layout LyX-Code
21241 Example:
21242
21243 \layout LyX-Code
21244
21245
21246 \layout LyX-Code
21247 /* initializes stack of 100 bytes at RAM address 0x200 */
21248
21249 \layout LyX-Code
21250 #pragma stack 0x200 100
21251
21252 \layout Standard
21253 If the stack_size field is omitted then a stack is created with the default
21254  size of 64.
21255  This size might be enough for most programs, but its not enough for operations
21256  with deep function nesting or excessive stack usage.
21257
21258 \layout List
21259 \labelwidthstring 00.00.0000
21260 code
21261 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
21262
21263 \end_inset
21264
21265  place a function symbol at static FLASH address
21266
21267 \layout LyX-Code
21268 Example:
21269
21270 \layout LyX-Code
21271
21272
21273 \layout LyX-Code
21274 /* place function test_func at 0x4000 */
21275
21276 \layout LyX-Code
21277 #pragma code test_func 0x4000
21278
21279 \layout LyX-Code
21280
21281
21282 \layout List
21283 \labelwidthstring 00.00.0000
21284 library instructs the linker to use a library module.
21285 \newline
21286 Usage:
21287
21288 \layout LyX-Code
21289 #pragma library module_name
21290
21291 \layout Standard
21292
21293 \emph on
21294 module_name
21295 \emph default
21296  can be any library or object file (including its path).
21297  Note that there are four reserved keywords which have special meaning.
21298  These are:
21299
21300 \layout Standard
21301 \align center
21302 \begin_inset Tabular
21303 <lyxtabular version="3" rows="6" columns="3">
21304 <features>
21305 <column alignment="center" valignment="top" leftline="true" width="0">
21306 <column alignment="block" valignment="top" leftline="true" width="20page%">
21307 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
21308 <row topline="true" bottomline="true">
21309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21310 \begin_inset Text
21311
21312 \layout Standard
21313 Keyword
21314
21315 \end_inset
21316 </cell>
21317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21318 \begin_inset Text
21319
21320 \layout Standard
21321 Description
21322
21323 \end_inset
21324 </cell>
21325 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21326 \begin_inset Text
21327
21328 \layout Standard
21329 Module to link
21330
21331 \end_inset
21332 </cell>
21333 </row>
21334 <row topline="true">
21335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21336 \begin_inset Text
21337
21338 \layout Standard
21339
21340 \series bold
21341 ignore
21342
21343 \end_inset
21344 </cell>
21345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21346 \begin_inset Text
21347
21348 \layout Standard
21349 ignore all library pragmas
21350
21351 \end_inset
21352 </cell>
21353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21354 \begin_inset Text
21355
21356 \layout Standard
21357
21358 \emph on
21359 (none)
21360
21361 \end_inset
21362 </cell>
21363 </row>
21364 <row topline="true">
21365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21366 \begin_inset Text
21367
21368 \layout Standard
21369
21370 \series bold
21371 c
21372
21373 \end_inset
21374 </cell>
21375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21376 \begin_inset Text
21377
21378 \layout Standard
21379 link the C library
21380
21381 \end_inset
21382 </cell>
21383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21384 \begin_inset Text
21385
21386 \layout Standard
21387
21388 \emph on
21389 libc18f
21390 \emph default
21391 .lib
21392
21393 \end_inset
21394 </cell>
21395 </row>
21396 <row topline="true">
21397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21398 \begin_inset Text
21399
21400 \layout Standard
21401
21402 \series bold
21403 math
21404
21405 \end_inset
21406 </cell>
21407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21408 \begin_inset Text
21409
21410 \layout Standard
21411 link the Math libarary
21412
21413 \end_inset
21414 </cell>
21415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21416 \begin_inset Text
21417
21418 \layout Standard
21419
21420 \emph on
21421 libm18f
21422 \emph default
21423 .lib
21424
21425 \end_inset
21426 </cell>
21427 </row>
21428 <row topline="true">
21429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21430 \begin_inset Text
21431
21432 \layout Standard
21433
21434 \series bold
21435 io
21436
21437 \end_inset
21438 </cell>
21439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21440 \begin_inset Text
21441
21442 \layout Standard
21443 link the I/O library
21444
21445 \end_inset
21446 </cell>
21447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21448 \begin_inset Text
21449
21450 \layout Standard
21451
21452 \emph on
21453 libio18f*
21454 \emph default
21455 .lib
21456
21457 \end_inset
21458 </cell>
21459 </row>
21460 <row topline="true" bottomline="true">
21461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21462 \begin_inset Text
21463
21464 \layout Standard
21465
21466 \series bold
21467 debug
21468
21469 \end_inset
21470 </cell>
21471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21472 \begin_inset Text
21473
21474 \layout Standard
21475 link the debug library
21476
21477 \end_inset
21478 </cell>
21479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21480 \begin_inset Text
21481
21482 \layout Standard
21483
21484 \emph on
21485 libdebug
21486 \emph default
21487 .lib
21488
21489 \end_inset
21490 </cell>
21491 </row>
21492 </lyxtabular>
21493
21494 \end_inset
21495
21496
21497 \newline
21498 * is the device number, i.e.
21499  452 for PIC18F452 MCU.
21500
21501 \layout Standard
21502 This feature allows for linking with specific libraries withoug having to
21503  explicit name them in the command line.
21504  Note that the 
21505 \noun on
21506 ignore
21507 \noun default
21508  keyword will reject all modules specified by the library pragma.
21509
21510 \layout List
21511 \labelwidthstring 00.00.0000
21512 udata pragma udata instructs the compiler to emit code so that linker will
21513  place a variable at a specific memory bank
21514
21515 \layout LyX-Code
21516 Example:
21517
21518 \layout LyX-Code
21519
21520
21521 \layout LyX-Code
21522 /* places variable foo at bank2 */
21523
21524 \layout LyX-Code
21525 #pragma udata bank2 foo
21526
21527 \layout LyX-Code
21528 char foo;
21529
21530 \layout Standard
21531 In order for this pragma to work extra SECTION directives should be added
21532  in the .lkr script.
21533  In the following example a sample .lkr file is shown:
21534
21535 \layout LyX-Code
21536
21537
21538 \layout LyX-Code
21539 // Sample linker script for the PIC18F452 processor
21540
21541 \layout LyX-Code
21542 LIBPATH .
21543
21544 \layout LyX-Code
21545 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
21546
21547 \layout LyX-Code
21548 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
21549
21550 \layout LyX-Code
21551 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
21552
21553 \layout LyX-Code
21554 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
21555
21556 \layout LyX-Code
21557 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
21558
21559 \layout LyX-Code
21560 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
21561
21562 \layout LyX-Code
21563 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
21564
21565 \layout LyX-Code
21566
21567
21568 \layout LyX-Code
21569 DATABANK   NAME=gpr0       START=0x80           END=0xFF
21570
21571 \layout LyX-Code
21572 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
21573
21574 \layout LyX-Code
21575 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
21576
21577 \layout LyX-Code
21578 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
21579
21580 \layout LyX-Code
21581 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
21582
21583 \layout LyX-Code
21584 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
21585
21586 \layout LyX-Code
21587 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
21588
21589 \layout LyX-Code
21590
21591
21592 \layout LyX-Code
21593 SECTION    NAME=CONFIG     ROM=config
21594
21595 \layout LyX-Code
21596
21597
21598 \layout LyX-Code
21599 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
21600
21601 \layout LyX-Code
21602 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
21603
21604 \layout LyX-Code
21605 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
21606
21607 \layout LyX-Code
21608 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
21609
21610 \layout LyX-Code
21611 SECTION    NAME=bank4      RAM=gpr4
21612
21613 \layout LyX-Code
21614 SECTION    NAME=bank5      RAM=gpr5
21615
21616 \layout Standard
21617 The linker will recognise the section name set in the pragma statement and
21618  will position the variable at the memory bank set with the RAM field at
21619  the SECTION line in the linker script file.
21620
21621 \layout Subsection
21622 Header Files
21623 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
21624
21625 \end_inset
21626
21627
21628
21629 \layout Standard
21630 There is one main header file
21631 \begin_inset LatexCommand \index{PIC16!Header files}
21632
21633 \end_inset
21634
21635  that can be included to the source files using the pic16
21636 \begin_inset LatexCommand \index{PIC16}
21637
21638 \end_inset
21639
21640  port.
21641  That file is the 
21642 \series bold
21643 pic18fregs.h
21644 \series default
21645 .
21646  This header file contains the definitions for the processor special registers,
21647  so it is necessary if the source accesses them.
21648  It can be included by adding the following line in the beginning of the
21649  file:
21650
21651 \layout LyX-Code
21652 #include <pic18fregs.h>
21653
21654 \layout Standard
21655 The specific microcontroller is selected within the pic18fregs.h automatically,
21656  so the same source can be used with a variety of devices.
21657
21658 \layout Subsection
21659 Libraries
21660
21661 \layout Standard
21662 The libraries
21663 \begin_inset LatexCommand \index{PIC16!Libraries}
21664
21665 \end_inset
21666
21667  that PIC16
21668 \begin_inset LatexCommand \index{PIC16}
21669
21670 \end_inset
21671
21672  port depends on are the microcontroller device libraries which contain
21673  the symbol definitions for the microcontroller special function registers.
21674  These libraries have the format pic18fxxxx.lib, where 
21675 \emph on
21676 xxxx
21677 \emph default
21678  is the microcontroller identification number.
21679  The specific library is selected automatically by the compiler at link
21680  stage according to the selected device.
21681
21682 \layout Standard
21683 Libraries are created with gplib which is part of the gputils package 
21684 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
21685
21686 \end_inset
21687
21688 .
21689
21690 \layout Subsubsection*
21691 Building the libraries
21692
21693 \layout Standard
21694 Before using SDCC/pic16 there are some libraries that need to be compiled.
21695  This process is not done automatically by SDCC since not all users use
21696  SDCC for pic16 projects.
21697  So each user should compile the libraries separately.
21698
21699 \layout Standard
21700 The steps to compile the pic16 libraries under Linux are:
21701
21702 \layout LyX-Code
21703 cd device/lib/pic16
21704
21705 \layout LyX-Code
21706 ./configure
21707
21708 \layout LyX-Code
21709 make
21710
21711 \layout LyX-Code
21712 cd ..
21713
21714 \layout LyX-Code
21715 make model-pic16
21716
21717 \layout LyX-Code
21718 su -c 'make install'     # install the libraries, you need the root password
21719
21720 \layout Standard
21721 If you need to install the headers too, do:
21722
21723 \layout LyX-Code
21724 cd device/include
21725
21726 \layout LyX-Code
21727 su -c 'make install'     # install the headers, you need the root password
21728
21729 \layout Standard
21730 There exist a special target to build the I/O libraries.
21731  This target is not automatically build because it will build the I/O library
21732  for 
21733 \emph on
21734 every
21735 \emph default
21736  supported device.
21737  This way building will take quite a lot of time.
21738  Users are advised to edit the 
21739 \series bold
21740 device/lib/pic16/pics.build
21741 \series default
21742  file and then execute:
21743
21744 \layout LyX-Code
21745 make lib-io
21746
21747 \layout Subsection
21748 Memory Models
21749
21750 \layout Standard
21751 The following memory models are supported by the PIC16 port:
21752
21753 \layout Itemize
21754 small model
21755
21756 \layout Itemize
21757 large model
21758
21759 \layout Standard
21760 Memory model affects the default size of pointers within the source.
21761  The sizes are shown in the next table:
21762
21763 \layout Standard
21764 \align center
21765 \begin_inset Tabular
21766 <lyxtabular version="3" rows="3" columns="3">
21767 <features>
21768 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21769 <column alignment="center" valignment="top" leftline="true" width="0">
21770 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21771 <row topline="true" bottomline="true">
21772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21773 \begin_inset Text
21774
21775 \layout Standard
21776 Pointer sizes according to memory model
21777
21778 \end_inset
21779 </cell>
21780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21781 \begin_inset Text
21782
21783 \layout Standard
21784 small model
21785
21786 \end_inset
21787 </cell>
21788 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21789 \begin_inset Text
21790
21791 \layout Standard
21792 large model
21793
21794 \end_inset
21795 </cell>
21796 </row>
21797 <row topline="true" bottomline="true">
21798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21799 \begin_inset Text
21800
21801 \layout Standard
21802 code pointers
21803
21804 \end_inset
21805 </cell>
21806 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21807 \begin_inset Text
21808
21809 \layout Standard
21810 16-bits
21811
21812 \end_inset
21813 </cell>
21814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21815 \begin_inset Text
21816
21817 \layout Standard
21818 24-bits
21819
21820 \end_inset
21821 </cell>
21822 </row>
21823 <row topline="true" bottomline="true">
21824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21825 \begin_inset Text
21826
21827 \layout Standard
21828 data pointers
21829
21830 \end_inset
21831 </cell>
21832 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
21833 \begin_inset Text
21834
21835 \layout Standard
21836 16-bits
21837
21838 \end_inset
21839 </cell>
21840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21841 \begin_inset Text
21842
21843 \layout Standard
21844 16-bits
21845
21846 \end_inset
21847 </cell>
21848 </row>
21849 </lyxtabular>
21850
21851 \end_inset
21852
21853
21854
21855 \layout Standard
21856 It is advisable that all sources within a project are compiled with the
21857  same memory model.
21858  If one wants to override the default memory model, this can be done by
21859  declaring a pointer as 
21860 \series bold
21861 far
21862 \series default
21863  or 
21864 \series bold
21865 near
21866 \series default
21867 .
21868  Far selects large memory model's pointers, while near selects small memory
21869  model's pointers.
21870
21871 \layout Standard
21872 The standard device libraries (see 
21873 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
21874
21875 \end_inset
21876
21877 ) contain no reference to pointers, so they can be used with both memory
21878  models.
21879
21880 \layout Subsection
21881 Stack
21882
21883 \layout Standard
21884 The stack
21885 \begin_inset LatexCommand \index{PIC16!stack}
21886
21887 \end_inset
21888
21889  implementation for the PIC16 port uses two indirect registers, FSR1 and
21890  FSR2.
21891
21892 \layout List
21893 \labelwidthstring 00.00.0000
21894 FSR1 is assigned as stack pointer
21895
21896 \layout List
21897 \labelwidthstring 00.00.0000
21898 FSR2 is assigned as frame pointer
21899
21900 \layout Standard
21901 The following stack models are supported by the PIC16 port
21902
21903 \layout Itemize
21904
21905 \noun on
21906 small
21907 \noun default
21908  model
21909
21910 \layout Itemize
21911
21912 \noun on
21913 large
21914 \noun default
21915  model
21916
21917 \layout Standard
21918
21919 \noun on
21920 Small
21921 \noun default
21922  model means that only the FSRxL byte is used to access stack and frame,
21923  while 
21924 \emph on
21925 \noun on
21926 large
21927 \emph default
21928 \noun default
21929  uses both FSRxL and FSRxH registers.
21930  The following table shows the stack/frame pointers sizes according to stack
21931  model and the maximum space they can address:
21932
21933 \layout Standard
21934 \align center
21935 \begin_inset Tabular
21936 <lyxtabular version="3" rows="3" columns="3">
21937 <features>
21938 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21939 <column alignment="center" valignment="top" leftline="true" width="0">
21940 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21941 <row topline="true" bottomline="true">
21942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21943 \begin_inset Text
21944
21945 \layout Standard
21946 Stack & Frame pointer sizes according to stack model
21947
21948 \end_inset
21949 </cell>
21950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21951 \begin_inset Text
21952
21953 \layout Standard
21954 small
21955
21956 \end_inset
21957 </cell>
21958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21959 \begin_inset Text
21960
21961 \layout Standard
21962 large
21963
21964 \end_inset
21965 </cell>
21966 </row>
21967 <row topline="true">
21968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21969 \begin_inset Text
21970
21971 \layout Standard
21972 Stack pointer FSR1
21973
21974 \end_inset
21975 </cell>
21976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21977 \begin_inset Text
21978
21979 \layout Standard
21980 8-bits
21981
21982 \end_inset
21983 </cell>
21984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21985 \begin_inset Text
21986
21987 \layout Standard
21988 16-bits
21989
21990 \end_inset
21991 </cell>
21992 </row>
21993 <row topline="true" bottomline="true">
21994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21995 \begin_inset Text
21996
21997 \layout Standard
21998 Frame pointer FSR2
21999
22000 \end_inset
22001 </cell>
22002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22003 \begin_inset Text
22004
22005 \layout Standard
22006 8-bits
22007
22008 \end_inset
22009 </cell>
22010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22011 \begin_inset Text
22012
22013 \layout Standard
22014 16-bits
22015
22016 \end_inset
22017 </cell>
22018 </row>
22019 </lyxtabular>
22020
22021 \end_inset
22022
22023
22024
22025 \layout Standard
22026
22027 \noun on
22028 Large 
22029 \noun default
22030 stack model is currently not working properly throughout the code generator.
22031  So its use is not advised.
22032  Also there are some other points that need special care:
22033 \newline
22034
22035
22036 \layout Enumerate
22037 Do not create stack sections with size more than one physical bank (that
22038  is 256 bytes)
22039
22040 \layout Enumerate
22041 Stack sections should no cross physical bank limits (i.e.
22042  #pragma stack 0x50 0x100)
22043
22044 \layout Standard
22045 These limitations are caused by the fact that only FSRxL is modified when
22046  using SMALL stack model, so no more than 256 bytes of stack can be used.
22047  This problem will disappear after LARGE model is fully implemented.
22048
22049 \layout Subsection
22050 Functions
22051
22052 \layout Standard
22053 In addition to the standard SDCC function keywords, PIC16
22054 \begin_inset LatexCommand \index{PIC16}
22055
22056 \end_inset
22057
22058  port makes available two more:
22059
22060 \layout List
22061 \labelwidthstring 00.00.0000
22062 wparam
22063 \begin_inset LatexCommand \index{PIC16!wparam}
22064
22065 \end_inset
22066
22067  Use the WREG to pass one byte of the first function argument.
22068  This improves speed but you may not use this for functions with arguments
22069  that are called via function pointers, otherwise the first byte of the
22070  first parameter will get lost.
22071  Usage:
22072
22073 \layout LyX-Code
22074 void func_wparam(int a) wparam
22075
22076 \layout LyX-Code
22077 {
22078
22079 \layout LyX-Code
22080     /* WREG hold the lower part of a */
22081
22082 \layout LyX-Code
22083     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
22084  */
22085
22086 \layout LyX-Code
22087 ...
22088
22089 \layout LyX-Code
22090 }
22091
22092 \layout List
22093 \labelwidthstring 00.00.0000
22094 shadowregs
22095 \begin_inset LatexCommand \index{PIC16!shadowregs}
22096
22097 \end_inset
22098
22099  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
22100  hardware shadow registers which hold the values of WREG, STATUS and BSR
22101  registers.
22102  This can be done by adding the keyword 
22103 \emph on
22104 shadowregs
22105 \emph default
22106  before the 
22107 \emph on
22108 interrupt
22109 \emph default
22110  keyword in the function's header.
22111
22112 \layout LyX-Code
22113 void isr_shadow(void) shadowregs interrupt 1
22114
22115 \layout LyX-Code
22116 {
22117
22118 \layout LyX-Code
22119 ...
22120
22121 \layout LyX-Code
22122 }
22123
22124 \layout Standard
22125
22126 \emph on
22127 shadowregs
22128 \emph default
22129  instructs the code generator not to store/restore WREG, STATUS, BSR when
22130  entering/exiting the ISR.
22131
22132 \layout Subsection
22133 Function return values
22134
22135 \layout Standard
22136 Return values from functions are placed to the appropriate registers following
22137  a modified Microchip policy optimized for SDCC.
22138  The following table shows these registers:
22139
22140 \layout Standard
22141 \align center
22142 \begin_inset Tabular
22143 <lyxtabular version="3" rows="6" columns="2">
22144 <features>
22145 <column alignment="center" valignment="top" leftline="true" width="0">
22146 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22147 <row topline="true" bottomline="true">
22148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22149 \begin_inset Text
22150
22151 \layout Standard
22152 size
22153
22154 \end_inset
22155 </cell>
22156 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22157 \begin_inset Text
22158
22159 \layout Standard
22160 destination register
22161
22162 \end_inset
22163 </cell>
22164 </row>
22165 <row topline="true">
22166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22167 \begin_inset Text
22168
22169 \layout Standard
22170 8 bits
22171
22172 \end_inset
22173 </cell>
22174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22175 \begin_inset Text
22176
22177 \layout Standard
22178 WREG
22179
22180 \end_inset
22181 </cell>
22182 </row>
22183 <row topline="true">
22184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22185 \begin_inset Text
22186
22187 \layout Standard
22188 16 bits
22189
22190 \end_inset
22191 </cell>
22192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22193 \begin_inset Text
22194
22195 \layout Standard
22196 PRODL:WREG
22197
22198 \end_inset
22199 </cell>
22200 </row>
22201 <row topline="true">
22202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22203 \begin_inset Text
22204
22205 \layout Standard
22206 24 bits
22207
22208 \end_inset
22209 </cell>
22210 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22211 \begin_inset Text
22212
22213 \layout Standard
22214 PRODH:PRODL:WREG
22215
22216 \end_inset
22217 </cell>
22218 </row>
22219 <row topline="true">
22220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22221 \begin_inset Text
22222
22223 \layout Standard
22224 32 bits
22225
22226 \end_inset
22227 </cell>
22228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22229 \begin_inset Text
22230
22231 \layout Standard
22232 FSR0L:PRODH:PRODL:WREG
22233
22234 \end_inset
22235 </cell>
22236 </row>
22237 <row topline="true" bottomline="true">
22238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22239 \begin_inset Text
22240
22241 \layout Standard
22242 >32 bits
22243
22244 \end_inset
22245 </cell>
22246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22247 \begin_inset Text
22248
22249 \layout Standard
22250 on stack, FSR0 points to the beginning
22251
22252 \end_inset
22253 </cell>
22254 </row>
22255 </lyxtabular>
22256
22257 \end_inset
22258
22259
22260
22261 \layout Subsection
22262 Interrupts
22263
22264 \layout Standard
22265 An interrupt
22266 \begin_inset LatexCommand \index{PIC16!interrupt}
22267
22268 \end_inset
22269
22270  service routine (ISR) is declared using the 
22271 \emph on
22272 interrupt
22273 \emph default
22274  keyword.
22275
22276 \layout LyX-Code
22277 void isr(void) interrupt 
22278 \emph on
22279 n
22280
22281 \layout LyX-Code
22282 {
22283
22284 \layout LyX-Code
22285 ...
22286
22287 \layout LyX-Code
22288 }
22289
22290 \layout Standard
22291
22292 \emph on
22293 n
22294 \emph default
22295  is the interrupt number, which for PIC18F devices can be:
22296
22297 \layout Standard
22298 \align center
22299 \begin_inset Tabular
22300 <lyxtabular version="3" rows="4" columns="3">
22301 <features>
22302 <column alignment="center" valignment="top" leftline="true" width="0">
22303 <column alignment="center" valignment="top" leftline="true" width="0">
22304 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22305 <row topline="true" bottomline="true">
22306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22307 \begin_inset Text
22308
22309 \layout Standard
22310
22311 \emph on
22312 n
22313
22314 \end_inset
22315 </cell>
22316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22317 \begin_inset Text
22318
22319 \layout Standard
22320 Interrupt Vector
22321
22322 \end_inset
22323 </cell>
22324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22325 \begin_inset Text
22326
22327 \layout Standard
22328 Interrupt Vector Address
22329
22330 \end_inset
22331 </cell>
22332 </row>
22333 <row topline="true">
22334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22335 \begin_inset Text
22336
22337 \layout Standard
22338 0
22339
22340 \end_inset
22341 </cell>
22342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22343 \begin_inset Text
22344
22345 \layout Standard
22346 RESET vector
22347
22348 \end_inset
22349 </cell>
22350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22351 \begin_inset Text
22352
22353 \layout Standard
22354 0x000000
22355
22356 \end_inset
22357 </cell>
22358 </row>
22359 <row topline="true">
22360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22361 \begin_inset Text
22362
22363 \layout Standard
22364
22365 \family roman
22366 \series medium
22367 \shape up
22368 \size normal
22369 \emph off
22370 \bar no
22371 \noun off
22372 \color none
22373 1
22374
22375 \end_inset
22376 </cell>
22377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22378 \begin_inset Text
22379
22380 \layout Standard
22381
22382 \family roman
22383 \series medium
22384 \shape up
22385 \size normal
22386 \emph off
22387 \bar no
22388 \noun off
22389 \color none
22390 HIGH priority interrupts
22391
22392 \end_inset
22393 </cell>
22394 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22395 \begin_inset Text
22396
22397 \layout Standard
22398 0x000008
22399
22400 \end_inset
22401 </cell>
22402 </row>
22403 <row topline="true" bottomline="true">
22404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22405 \begin_inset Text
22406
22407 \layout Standard
22408 2
22409
22410 \end_inset
22411 </cell>
22412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22413 \begin_inset Text
22414
22415 \layout Standard
22416 LOW priority interrupts
22417
22418 \end_inset
22419 </cell>
22420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22421 \begin_inset Text
22422
22423 \layout Standard
22424 0x000018
22425
22426 \end_inset
22427 </cell>
22428 </row>
22429 </lyxtabular>
22430
22431 \end_inset
22432
22433
22434
22435 \layout Standard
22436 When generating assembly code for ISR the code generator places a 
22437 \noun on
22438 goto 
22439 \noun default
22440 instruction at the 
22441 \emph on
22442 Interrupt Vector Address
22443 \emph default
22444  which points at the genetated ISR.
22445  This single GOTO instruction is part of an automatically generated 
22446 \emph on
22447 interrupt entry point
22448 \emph default
22449  function.
22450  The actuall ISR code is placed as normally would in the code space.
22451  Upon interrupt request, the GOTO instruction is executed which jumps to
22452  the ISR code.
22453  When declaring interrupt functions as _naked this GOTO instruction is 
22454 \series bold
22455 not
22456 \series default
22457  generated.
22458  The whole interrupt functions is therefore placed at the Interrupt Vector
22459  Address of the specific interrupt.
22460  This is not a problem for the LOW priority interrupts, but it is a problem
22461  for the RESET and the HIGH priority interrupts because code may be written
22462  at the next interrupt´s vector address and cause undeterminate program
22463  behaviour if that interrupt is raised.
22464 \begin_inset Foot
22465 collapsed false
22466
22467 \layout Standard
22468 This is not a problem when
22469
22470 \layout Enumerate
22471 this is a HIGH interrupt ISR and LOW interrupts are 
22472 \emph on
22473 disabled
22474 \emph default
22475  or not used.
22476
22477 \layout Enumerate
22478 when the ISR is small enough not to reach the next interrupt´s vector address.
22479
22480 \end_inset
22481
22482
22483
22484 \layout Standard
22485
22486 \emph on
22487 n
22488 \emph default
22489  is possible to be omitted.
22490  This way a function is generated similar to an ISR, but it is not assigned
22491  to any interrupt.
22492
22493 \layout Standard
22494 When entering an interrupt, currently the PIC16
22495 \begin_inset LatexCommand \index{PIC16}
22496
22497 \end_inset
22498
22499  port automatically saves the following registers:
22500
22501 \layout Itemize
22502 WREG
22503
22504 \layout Itemize
22505 STATUS
22506
22507 \layout Itemize
22508 BSR
22509
22510 \layout Itemize
22511 PROD (PRODL and PRODH)
22512
22513 \layout Itemize
22514 FSR0 (FSR0L and FSR0H)
22515
22516 \layout Standard
22517 These registers are restored upon return from the interrupt routine.
22518 \begin_inset Foot
22519 collapsed false
22520
22521 \layout Standard
22522 NOTE that when the _naked attribute is specified for an interrupt routine,
22523  then NO registers are stored or restored.
22524
22525 \end_inset
22526
22527
22528
22529 \layout Subsection
22530 Generic Pointers
22531
22532 \layout Standard
22533 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
22534  There are 3 types of generic pointers currently implemented data, code
22535  and eeprom pointers.
22536  They are differentiated by the value of the 7th and 6th bits of the upper
22537  byte:
22538
22539 \layout Standard
22540 \align center
22541 \begin_inset Tabular
22542 <lyxtabular version="3" rows="5" columns="5">
22543 <features>
22544 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22545 <column alignment="center" valignment="top" width="0">
22546 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22547 <column alignment="center" valignment="top" width="0">
22548 <column alignment="left" valignment="top" rightline="true" width="0">
22549 <row topline="true" bottomline="true">
22550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22551 \begin_inset Text
22552
22553 \layout Standard
22554 pointer type
22555
22556 \end_inset
22557 </cell>
22558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22559 \begin_inset Text
22560
22561 \layout Standard
22562 7th bit
22563
22564 \end_inset
22565 </cell>
22566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22567 \begin_inset Text
22568
22569 \layout Standard
22570 6th bit
22571
22572 \end_inset
22573 </cell>
22574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22575 \begin_inset Text
22576
22577 \layout Standard
22578 rest of the pointer
22579
22580 \end_inset
22581 </cell>
22582 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22583 \begin_inset Text
22584
22585 \layout Standard
22586 description
22587
22588 \end_inset
22589 </cell>
22590 </row>
22591 <row topline="true" bottomline="true">
22592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22593 \begin_inset Text
22594
22595 \layout Standard
22596 data 
22597
22598 \end_inset
22599 </cell>
22600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22601 \begin_inset Text
22602
22603 \layout Standard
22604 1
22605
22606 \end_inset
22607 </cell>
22608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22609 \begin_inset Text
22610
22611 \layout Standard
22612 0
22613
22614 \end_inset
22615 </cell>
22616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22617 \begin_inset Text
22618
22619 \layout Standard
22620
22621 \family typewriter
22622 \shape slanted
22623 \emph on
22624 uuuuuu uuuuxxxx xxxxxxxx
22625
22626 \end_inset
22627 </cell>
22628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22629 \begin_inset Text
22630
22631 \layout Standard
22632 a 12-bit data pointer in data RAM memory
22633
22634 \end_inset
22635 </cell>
22636 </row>
22637 <row bottomline="true">
22638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22639 \begin_inset Text
22640
22641 \layout Standard
22642 code
22643
22644 \end_inset
22645 </cell>
22646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22647 \begin_inset Text
22648
22649 \layout Standard
22650 0
22651
22652 \end_inset
22653 </cell>
22654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22655 \begin_inset Text
22656
22657 \layout Standard
22658 0
22659
22660 \end_inset
22661 </cell>
22662 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22663 \begin_inset Text
22664
22665 \layout Standard
22666
22667 \family typewriter
22668 \shape slanted
22669 \emph on
22670 uxxxxx xxxxxxxx xxxxxxxx
22671
22672 \end_inset
22673 </cell>
22674 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22675 \begin_inset Text
22676
22677 \layout Standard
22678 a 21-bit code pointer in FLASH memory
22679
22680 \end_inset
22681 </cell>
22682 </row>
22683 <row bottomline="true">
22684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22685 \begin_inset Text
22686
22687 \layout Standard
22688 eeprom
22689
22690 \end_inset
22691 </cell>
22692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22693 \begin_inset Text
22694
22695 \layout Standard
22696 0
22697
22698 \end_inset
22699 </cell>
22700 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22701 \begin_inset Text
22702
22703 \layout Standard
22704 1
22705
22706 \end_inset
22707 </cell>
22708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22709 \begin_inset Text
22710
22711 \layout Standard
22712
22713 \family typewriter
22714 \shape slanted
22715 \emph on
22716 uuuuuu uuuuuuxx xxxxxxxx
22717
22718 \end_inset
22719 </cell>
22720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22721 \begin_inset Text
22722
22723 \layout Standard
22724 a 10-bit eeprom pointer in EEPROM memory
22725
22726 \end_inset
22727 </cell>
22728 </row>
22729 <row bottomline="true">
22730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22731 \begin_inset Text
22732
22733 \layout Standard
22734 (unimplemented)
22735
22736 \end_inset
22737 </cell>
22738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22739 \begin_inset Text
22740
22741 \layout Standard
22742 1
22743
22744 \end_inset
22745 </cell>
22746 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22747 \begin_inset Text
22748
22749 \layout Standard
22750 1
22751
22752 \end_inset
22753 </cell>
22754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22755 \begin_inset Text
22756
22757 \layout Standard
22758
22759 \family typewriter
22760 \shape slanted
22761 \emph on
22762 xxxxxx xxxxxxxx xxxxxxxx
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 \layout Standard
22770 unimplemented pointer type
22771
22772 \end_inset
22773 </cell>
22774 </row>
22775 </lyxtabular>
22776
22777 \end_inset
22778
22779
22780
22781 \layout Standard
22782 Generic pointer are read and written with a set of library functions which
22783  read/write 1, 2, 3, 4 bytes.
22784
22785 \layout Subsection
22786 PIC16 C Libraries
22787
22788 \layout Subsubsection
22789 Standard I/O Streams
22790
22791 \layout Standard
22792 In the 
22793 \emph on
22794 stdio.h
22795 \emph default
22796  the type FILE is defined as:
22797
22798 \layout LyX-Code
22799 typedef char * FILE;
22800
22801 \layout Standard
22802 This type is the stream type implemented I/O in the PIC18F devices.
22803  Also the standard input and output streams are declared in stdio.h:
22804
22805 \layout LyX-Code
22806 extern FILE * stdin;
22807
22808 \layout LyX-Code
22809 extern FILE * stdout;
22810
22811 \layout Standard
22812 The FILE type is actually a generic pointer which defines one more type
22813  of generic pointers, the 
22814 \emph on
22815 stream 
22816 \emph default
22817 pointer.
22818  This new type has the format:
22819
22820 \layout Standard
22821 \align center
22822 \begin_inset Tabular
22823 <lyxtabular version="3" rows="2" columns="7">
22824 <features>
22825 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22826 <column alignment="center" valignment="top" width="0">
22827 <column alignment="center" valignment="top" leftline="true" width="0">
22828 <column alignment="center" valignment="top" leftline="true" width="0">
22829 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22830 <column alignment="center" valignment="top" width="0">
22831 <column alignment="left" valignment="top" rightline="true" width="0">
22832 <row topline="true" bottomline="true">
22833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22834 \begin_inset Text
22835
22836 \layout Standard
22837 pointer type
22838
22839 \end_inset
22840 </cell>
22841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22842 \begin_inset Text
22843
22844 \layout Standard
22845 <7:6>
22846
22847 \end_inset
22848 </cell>
22849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22850 \begin_inset Text
22851
22852 \layout Standard
22853 <5>
22854
22855 \end_inset
22856 </cell>
22857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22858 \begin_inset Text
22859
22860 \layout Standard
22861 <4>
22862
22863 \end_inset
22864 </cell>
22865 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22866 \begin_inset Text
22867
22868 \layout Standard
22869 <3:0>
22870
22871 \end_inset
22872 </cell>
22873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22874 \begin_inset Text
22875
22876 \layout Standard
22877 rest of the pointer
22878
22879 \end_inset
22880 </cell>
22881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22882 \begin_inset Text
22883
22884 \layout Standard
22885 descrption
22886
22887 \end_inset
22888 </cell>
22889 </row>
22890 <row topline="true" bottomline="true">
22891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22892 \begin_inset Text
22893
22894 \layout Standard
22895 stream
22896
22897 \end_inset
22898 </cell>
22899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22900 \begin_inset Text
22901
22902 \layout Standard
22903 00
22904
22905 \end_inset
22906 </cell>
22907 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22908 \begin_inset Text
22909
22910 \layout Standard
22911 1
22912
22913 \end_inset
22914 </cell>
22915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22916 \begin_inset Text
22917
22918 \layout Standard
22919 0
22920
22921 \end_inset
22922 </cell>
22923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22924 \begin_inset Text
22925
22926 \layout Standard
22927 nnnn
22928
22929 \end_inset
22930 </cell>
22931 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22932 \begin_inset Text
22933
22934 \layout Standard
22935
22936 \family typewriter
22937 \shape slanted
22938 \emph on
22939 uuuuuuuu uuuuuuuu
22940
22941 \end_inset
22942 </cell>
22943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22944 \begin_inset Text
22945
22946 \layout Standard
22947 upper byte high nubble is 0x2n, the rest are zeroes
22948
22949 \end_inset
22950 </cell>
22951 </row>
22952 </lyxtabular>
22953
22954 \end_inset
22955
22956
22957
22958 \layout Standard
22959 Currently implemented there are 3 types of streams defined:
22960
22961 \layout Standard
22962 \align center
22963 \begin_inset Tabular
22964 <lyxtabular version="3" rows="4" columns="4">
22965 <features>
22966 <column alignment="center" valignment="top" leftline="true" width="0">
22967 <column alignment="center" valignment="top" leftline="true" width="0">
22968 <column alignment="center" valignment="top" leftline="true" width="0">
22969 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22970 <row topline="true" bottomline="true">
22971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22972 \begin_inset Text
22973
22974 \layout Standard
22975 stream type
22976
22977 \end_inset
22978 </cell>
22979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22980 \begin_inset Text
22981
22982 \layout Standard
22983 value
22984
22985 \end_inset
22986 </cell>
22987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22988 \begin_inset Text
22989
22990 \layout Standard
22991 module
22992
22993 \end_inset
22994 </cell>
22995 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22996 \begin_inset Text
22997
22998 \layout Standard
22999 description
23000
23001 \end_inset
23002 </cell>
23003 </row>
23004 <row topline="true">
23005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23006 \begin_inset Text
23007
23008 \layout Standard
23009 STREAM_USART
23010
23011 \end_inset
23012 </cell>
23013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23014 \begin_inset Text
23015
23016 \layout Standard
23017
23018 \family typewriter
23019 0x200000UL
23020
23021 \end_inset
23022 </cell>
23023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23024 \begin_inset Text
23025
23026 \layout Standard
23027 USART
23028
23029 \end_inset
23030 </cell>
23031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23032 \begin_inset Text
23033
23034 \layout Standard
23035 Writes/Reads characters via the USART peripheral
23036
23037 \end_inset
23038 </cell>
23039 </row>
23040 <row topline="true">
23041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23042 \begin_inset Text
23043
23044 \layout Standard
23045 STREAM_MSSP
23046
23047 \end_inset
23048 </cell>
23049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23050 \begin_inset Text
23051
23052 \layout Standard
23053
23054 \family typewriter
23055 0x210000UL
23056
23057 \end_inset
23058 </cell>
23059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23060 \begin_inset Text
23061
23062 \layout Standard
23063 MSSP
23064
23065 \end_inset
23066 </cell>
23067 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23068 \begin_inset Text
23069
23070 \layout Standard
23071 Writes/Reads characters via the MSSP peripheral
23072
23073 \end_inset
23074 </cell>
23075 </row>
23076 <row topline="true" bottomline="true">
23077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23078 \begin_inset Text
23079
23080 \layout Standard
23081 STREAM_USER
23082
23083 \end_inset
23084 </cell>
23085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23086 \begin_inset Text
23087
23088 \layout Standard
23089
23090 \family typewriter
23091 0x2f0000UL
23092
23093 \end_inset
23094 </cell>
23095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23096 \begin_inset Text
23097
23098 \layout Standard
23099 (none)
23100
23101 \end_inset
23102 </cell>
23103 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23104 \begin_inset Text
23105
23106 \layout Standard
23107 Writes/Reads characters via used defined functions
23108
23109 \end_inset
23110 </cell>
23111 </row>
23112 </lyxtabular>
23113
23114 \end_inset
23115
23116
23117
23118 \layout Standard
23119 The stream identifiers are declared as macros in the stdio.h header.
23120
23121 \layout Standard
23122 In the libc library there exist the functions that are used to write to
23123  each of the above streams.
23124  These are
23125
23126 \layout List
23127 \labelwidthstring 00.00.0000
23128 _
23129 \begin_inset ERT
23130 status Collapsed
23131
23132 \layout Standard
23133
23134
23135 \backslash
23136 /
23137
23138 \end_inset
23139
23140 _stream_usart_putchar writes a character at the USART stream
23141
23142 \layout List
23143 \labelwidthstring 00.00.0000
23144 _
23145 \begin_inset ERT
23146 status Collapsed
23147
23148 \layout Standard
23149
23150
23151 \backslash
23152 /
23153
23154 \end_inset
23155
23156 _stream_mssp_putchar writes a character at the MSSP stream
23157
23158 \layout List
23159 \labelwidthstring 00.00.0000
23160 putchar dummy function.
23161  This writes a character to a user specified manner.
23162
23163 \layout Standard
23164 In order to increase performance 
23165 \emph on
23166 putchar 
23167 \emph default
23168 is declared in stdio.h as having its parameter in WREG (it has the wparam
23169  keyword).
23170  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
23171  in a user-friendly way.
23172  
23173 \emph on
23174 arg
23175 \emph default
23176  is the name of the variable that holds the character to print.
23177  An example follows:
23178
23179 \layout LyX-Code
23180 #include <pic18fregs.h>
23181 \newline
23182 #include <stdio.h>
23183 \newline
23184
23185 \newline
23186 PUTCHAR( c )
23187
23188 \layout LyX-Code
23189 {
23190
23191 \layout LyX-Code
23192     PORTA = c;    /* dump character c to PORTA */
23193
23194 \layout LyX-Code
23195
23196 \newline
23197
23198 \newline
23199 void main(void)
23200
23201 \layout LyX-Code
23202 {
23203
23204 \layout LyX-Code
23205     stdout = STREAM_USER;    /* this is not necessary, since stdout points
23206
23207 \layout LyX-Code
23208                               * by default to STREAM_USER */
23209
23210 \layout LyX-Code
23211     printf (¨This is a printf test
23212 \backslash
23213 n¨);
23214
23215 \layout LyX-Code
23216 }
23217
23218 \layout LyX-Code
23219
23220
23221 \layout Subsubsection
23222 Printing functions
23223
23224 \layout Standard
23225 PIC16 contains an implementation of the printf-family of functions.
23226  There exist the following functions:
23227
23228 \layout LyX-Code
23229 extern unsigned int sprintf(char *buf, char *fmt, ...);
23230
23231 \layout LyX-Code
23232 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
23233
23234 \layout LyX-Code
23235
23236
23237 \layout LyX-Code
23238 extern unsigned int printf(char *fmt, ...);
23239
23240 \layout LyX-Code
23241 extern unsigned int vprintf(char *fmt, va_lista ap);
23242
23243 \layout LyX-Code
23244
23245
23246 \layout LyX-Code
23247 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
23248
23249 \layout LyX-Code
23250 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
23251
23252 \layout Standard
23253 For sprintf and vsprintf 
23254 \emph on
23255 buf 
23256 \emph default
23257 should normally be a data pointer where the resulting string will be placed.
23258  No range checking is done so the user should allocate the necessery buffer.
23259  For fprintf and vfprintf 
23260 \emph on
23261 fp
23262 \emph default
23263  should be a stream pointer (i.e.
23264  stdout, STREAM_MSSP, etc...).
23265
23266 \layout Subsubsection
23267 Signals
23268
23269 \layout Standard
23270 The PIC18F family of microcontrollers supports a number of interrupt sources.
23271  A list of these interrupts is shown in the following table:
23272
23273 \layout Standard
23274 \align center
23275 \begin_inset Tabular
23276 <lyxtabular version="3" rows="11" columns="4">
23277 <features>
23278 <column alignment="left" valignment="top" leftline="true" width="0">
23279 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23280 <column alignment="left" valignment="top" leftline="true" width="0">
23281 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23282 <row topline="true" bottomline="true">
23283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23284 \begin_inset Text
23285
23286 \layout Standard
23287 signal name
23288
23289 \end_inset
23290 </cell>
23291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23292 \begin_inset Text
23293
23294 \layout Standard
23295 description
23296
23297 \end_inset
23298 </cell>
23299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23300 \begin_inset Text
23301
23302 \layout Standard
23303 signal name
23304
23305 \end_inset
23306 </cell>
23307 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23308 \begin_inset Text
23309
23310 \layout Standard
23311 descritpion
23312
23313 \end_inset
23314 </cell>
23315 </row>
23316 <row topline="true">
23317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23318 \begin_inset Text
23319
23320 \layout Standard
23321 SIG_RB
23322
23323 \end_inset
23324 </cell>
23325 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23326 \begin_inset Text
23327
23328 \layout Standard
23329 PORTB change interrupt
23330
23331 \end_inset
23332 </cell>
23333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23334 \begin_inset Text
23335
23336 \layout Standard
23337 SIG_EE
23338
23339 \end_inset
23340 </cell>
23341 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23342 \begin_inset Text
23343
23344 \layout Standard
23345 EEPROM/FLASH write complete interrupt
23346
23347 \end_inset
23348 </cell>
23349 </row>
23350 <row topline="true">
23351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23352 \begin_inset Text
23353
23354 \layout Standard
23355 SIG_INT0
23356
23357 \end_inset
23358 </cell>
23359 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23360 \begin_inset Text
23361
23362 \layout Standard
23363 INT0 external interrupt
23364
23365 \end_inset
23366 </cell>
23367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23368 \begin_inset Text
23369
23370 \layout Standard
23371 SIG_BCOL
23372
23373 \end_inset
23374 </cell>
23375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23376 \begin_inset Text
23377
23378 \layout Standard
23379 Bus collision interrupt
23380
23381 \end_inset
23382 </cell>
23383 </row>
23384 <row topline="true">
23385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23386 \begin_inset Text
23387
23388 \layout Standard
23389 SIG_INT1
23390
23391 \end_inset
23392 </cell>
23393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23394 \begin_inset Text
23395
23396 \layout Standard
23397 INT1 external interrupt
23398
23399 \end_inset
23400 </cell>
23401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23402 \begin_inset Text
23403
23404 \layout Standard
23405 SIG_LVD
23406
23407 \end_inset
23408 </cell>
23409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23410 \begin_inset Text
23411
23412 \layout Standard
23413 Low voltage detect interrupt
23414
23415 \end_inset
23416 </cell>
23417 </row>
23418 <row topline="true">
23419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23420 \begin_inset Text
23421
23422 \layout Standard
23423 SIG_INT2
23424
23425 \end_inset
23426 </cell>
23427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23428 \begin_inset Text
23429
23430 \layout Standard
23431 INT2 external interrupt
23432
23433 \end_inset
23434 </cell>
23435 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23436 \begin_inset Text
23437
23438 \layout Standard
23439 SIG_PSP
23440
23441 \end_inset
23442 </cell>
23443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23444 \begin_inset Text
23445
23446 \layout Standard
23447 Parallel slave port interrupt
23448
23449 \end_inset
23450 </cell>
23451 </row>
23452 <row topline="true">
23453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23454 \begin_inset Text
23455
23456 \layout Standard
23457 SIG_CCP1
23458
23459 \end_inset
23460 </cell>
23461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23462 \begin_inset Text
23463
23464 \layout Standard
23465 CCP1 module interrupt
23466
23467 \end_inset
23468 </cell>
23469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23470 \begin_inset Text
23471
23472 \layout Standard
23473 SIG_AD
23474
23475 \end_inset
23476 </cell>
23477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23478 \begin_inset Text
23479
23480 \layout Standard
23481 AD convertion complete interrupt
23482
23483 \end_inset
23484 </cell>
23485 </row>
23486 <row topline="true">
23487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23488 \begin_inset Text
23489
23490 \layout Standard
23491 SIG_CCP2
23492
23493 \end_inset
23494 </cell>
23495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23496 \begin_inset Text
23497
23498 \layout Standard
23499 CCP2 module interrupt
23500
23501 \end_inset
23502 </cell>
23503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23504 \begin_inset Text
23505
23506 \layout Standard
23507 SIG_RC
23508
23509 \end_inset
23510 </cell>
23511 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23512 \begin_inset Text
23513
23514 \layout Standard
23515 USART receive interrupt
23516
23517 \end_inset
23518 </cell>
23519 </row>
23520 <row topline="true">
23521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23522 \begin_inset Text
23523
23524 \layout Standard
23525 SIG_TMR0
23526
23527 \end_inset
23528 </cell>
23529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23530 \begin_inset Text
23531
23532 \layout Standard
23533 TMR0 overflow interrupt
23534
23535 \end_inset
23536 </cell>
23537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23538 \begin_inset Text
23539
23540 \layout Standard
23541 SIG_TX
23542
23543 \end_inset
23544 </cell>
23545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23546 \begin_inset Text
23547
23548 \layout Standard
23549 USART transmit interrupt
23550
23551 \end_inset
23552 </cell>
23553 </row>
23554 <row topline="true">
23555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23556 \begin_inset Text
23557
23558 \layout Standard
23559 SIG_TMR1
23560
23561 \end_inset
23562 </cell>
23563 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23564 \begin_inset Text
23565
23566 \layout Standard
23567 TMR1 overflow interrupt
23568
23569 \end_inset
23570 </cell>
23571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23572 \begin_inset Text
23573
23574 \layout Standard
23575 SIG_MSSP
23576
23577 \end_inset
23578 </cell>
23579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23580 \begin_inset Text
23581
23582 \layout Standard
23583 SSP receive/transmit interrupt
23584
23585 \end_inset
23586 </cell>
23587 </row>
23588 <row topline="true">
23589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23590 \begin_inset Text
23591
23592 \layout Standard
23593 SIG_TMR2
23594
23595 \end_inset
23596 </cell>
23597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23598 \begin_inset Text
23599
23600 \layout Standard
23601 TMR2 matches PR2 interrupt
23602
23603 \end_inset
23604 </cell>
23605 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23606 \begin_inset Text
23607
23608 \layout Standard
23609
23610
23611 \end_inset
23612 </cell>
23613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23614 \begin_inset Text
23615
23616 \layout Standard
23617
23618
23619 \end_inset
23620 </cell>
23621 </row>
23622 <row topline="true" bottomline="true">
23623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23624 \begin_inset Text
23625
23626 \layout Standard
23627 SIG_TMR3
23628
23629 \end_inset
23630 </cell>
23631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23632 \begin_inset Text
23633
23634 \layout Standard
23635 TMR3 overflow interrupt
23636
23637 \end_inset
23638 </cell>
23639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23640 \begin_inset Text
23641
23642 \layout Standard
23643
23644
23645 \end_inset
23646 </cell>
23647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23648 \begin_inset Text
23649
23650 \layout Standard
23651
23652
23653 \end_inset
23654 </cell>
23655 </row>
23656 </lyxtabular>
23657
23658 \end_inset
23659
23660
23661
23662 \layout Standard
23663 The prototypes for these names are defined in the header file 
23664 \emph on
23665 signal.h
23666 \emph default
23667  .
23668
23669 \layout Standard
23670 In order to simplify signal handling, a number of macros is provided:
23671
23672 \layout List
23673 \labelwidthstring 00.00.0000
23674 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
23675  high priority interrupts.
23676  
23677 \emph on
23678 name
23679 \emph default
23680  is the function name to use.
23681
23682 \layout List
23683 \labelwidthstring 00.00.0000
23684 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
23685  low priority interrupt.
23686  
23687 \emph on
23688 name
23689 \emph default
23690  is the function name to use.
23691
23692 \layout List
23693 \labelwidthstring 00.00.0000
23694 DEF_HANDLER(sig,handler) define a handler for signal 
23695 \emph on
23696 sig.
23697
23698 \layout List
23699 \labelwidthstring 00.00.0000
23700 END_DEF end the declaration of the dispatch table.
23701
23702 \layout Standard
23703 Additionally there are two more macros to simplify the declaration of the
23704  signal handler:
23705
23706 \layout List
23707 \labelwidthstring 00.00.0000
23708
23709 \series medium
23710 SIGHANDLER(handler) 
23711 \series default
23712 this declares the function prototype for the 
23713 \emph on
23714 handler
23715 \emph default
23716  function.
23717
23718 \layout List
23719 \labelwidthstring 00.00.0000
23720 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
23721
23722 \layout Standard
23723 An example of using the macros above is shown below:
23724
23725 \layout LyX-Code
23726 #include <pic18fregs.h>
23727
23728 \layout LyX-Code
23729 #include <signal.h>
23730 \newline
23731
23732 \newline
23733 DEF_INTHIGH(high_int)
23734
23735 \layout LyX-Code
23736 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
23737
23738 \layout LyX-Code
23739 DEF_HANDLER(SIG_BCOL, _bcol_handler)
23740
23741 \layout LyX-Code
23742 END_DEF
23743 \newline
23744
23745 \newline
23746 SIGHANDLER(_tmr0_handler)
23747
23748 \layout LyX-Code
23749 {
23750
23751 \layout LyX-Code
23752   /* action to be taken when timer 0 overflows */
23753
23754 \layout LyX-Code
23755 }
23756 \newline
23757
23758 \newline
23759 SIGHANDLERNAKED(_bcol_handler)
23760
23761 \layout LyX-Code
23762 {
23763
23764 \layout LyX-Code
23765   _asm
23766
23767 \layout LyX-Code
23768     /* action to be taken when bus collision occurs */
23769
23770 \layout LyX-Code
23771     retfie
23772
23773 \layout LyX-Code
23774  _endasm;
23775
23776 \layout LyX-Code
23777 }
23778
23779 \layout Standard
23780
23781 \series bold
23782 NOTES:
23783 \series default
23784  Special care should be taken when using the above scheme:
23785
23786 \layout Itemize
23787 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
23788
23789 \layout Itemize
23790 when declaring SIGHANDLERNAKED handler never forget to use 
23791 \emph on
23792 retfie
23793 \emph default
23794  for proper returning.
23795
23796 \layout Subsection
23797 PIC16 Port -- Tips
23798
23799 \layout Standard
23800 Here you can find some general tips for compiling programs with SDCC/pic16.
23801
23802 \layout Subsubsection
23803 Stack size
23804
23805 \layout Standard
23806 The default stack
23807 \begin_inset LatexCommand \index{PIC16!stack}
23808
23809 \end_inset
23810
23811  size (that is 64 bytes) probably is enough for many programs.
23812  One must take care that when there are many levels of function nesting,
23813  or there is excessive usage of stack, its size should be extended.
23814  An example of such a case is the printf/sprintf family of functions.
23815  If you encounter problems like not being able to print integers, then you
23816  need to set the stack size around the maximum (256 for small stack model).
23817  The following diagram shows what happens when calling printf to print an
23818  integer:
23819
23820 \layout LyX-Code
23821 printf () --> ltoa () --> ultoa () --> divschar ()
23822
23823 \layout Standard
23824 It is should be understood that stack is easily consumed when calling complicate
23825 d functions.
23826  Using command line arguments like -
23827 \begin_inset ERT
23828 status Collapsed
23829
23830 \layout Standard
23831
23832
23833 \backslash
23834 /
23835
23836 \end_inset
23837
23838 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
23839  stack frames.
23840  Other ways to reduce stack usage may exist.
23841
23842 \layout Subsection
23843 Known bugs
23844
23845 \layout Standard
23846 The PIC16 Port currently does not pass SDCC's regression test
23847 \begin_inset LatexCommand \index{Regression test (PIC16)}
23848
23849 \end_inset
23850
23851  suite (see section 
23852 \begin_inset LatexCommand \ref{sec:Quality-control}
23853
23854 \end_inset
23855
23856 ) and thus the nightly regression tests for the PIC16 target are currently
23857  disabled for all hosts except for 
23858 \emph on
23859 Linux on Opteron.
23860
23861 \emph default
23862  This means you can see the result of the PIC16 regression tests f.e.
23863  by checking the log files in 
23864 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/regression_test_results/amd64-unknown-linux2.3/}
23865
23866 \end_inset
23867
23868  (pick the most up to date file there, scroll down, lend a hand).
23869
23870 \layout Chapter
23871 Debugging
23872
23873 \layout Standard
23874 There are several approaches to debugging your code.
23875  This chapter is meant to show your options and to give detail on some of
23876  them:
23877 \newline
23878
23879 \newline
23880 When writing your code:
23881
23882 \layout Itemize
23883 write your code with debugging in mind (avoid duplicating code, put conceptually
23884  similar variables into structs, use structured code, have strategic points
23885  within your code where all variables are consistent, ...)
23886
23887 \layout Itemize
23888 run a syntax-checking tool like splint
23889 \begin_inset LatexCommand \index{splint (syntax checking tool)}
23890
23891 \end_inset
23892
23893
23894 \begin_inset LatexCommand \index{lint (syntax checking tool)}
23895
23896 \end_inset
23897
23898  (see -
23899 \begin_inset ERT
23900 status Collapsed
23901
23902 \layout Standard
23903
23904
23905 \backslash
23906 /
23907
23908 \end_inset
23909
23910 -more-pedantic 
23911 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
23912
23913 \end_inset
23914
23915 ) over the code.
23916
23917 \layout Itemize
23918 for the high level code use a C-compiler (like f.e.
23919  GCC) to compile run and debug the code on your host.
23920  See (see -
23921 \begin_inset ERT
23922 status Collapsed
23923
23924 \layout Standard
23925
23926
23927 \backslash
23928 /
23929
23930 \end_inset
23931
23932 -more-pedantic 
23933 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
23934
23935 \end_inset
23936
23937  ) on howto handle syntax extensions like __xdata, __at(), ...
23938  
23939
23940 \layout Itemize
23941 use another C-compiler to compile code for your target.
23942  Always an option but not recommended:) And not very likely to help you.
23943  If you seriously consider walking this path you should at least occasionally
23944  check portability of your code.
23945  Most commercial compiler vendors will offer an evaluation version so you
23946  can test compile your code or snippets of your code.
23947
23948 \layout Standard
23949 Debugging on a simulator:
23950
23951 \layout Itemize
23952 there is a separate section about SDCDB (section 
23953 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
23954
23955 \end_inset
23956
23957 ) below.
23958
23959 \layout Itemize
23960 or (8051 specific) use a freeware/commercial simulator which interfaces
23961  to the AOMF
23962 \begin_inset LatexCommand \index{AOMF, AOMF51}
23963
23964 \end_inset
23965
23966  file (see 
23967 \begin_inset LatexCommand \ref{OMF file}
23968
23969 \end_inset
23970
23971 ) optionally generated by SDCC.
23972
23973 \layout Standard
23974 Debugging On-target: 
23975
23976 \layout Itemize
23977 use a MCU port pin to serially output debug data to the RS232 port of your
23978  host.
23979  You'll probably want some level shifting device typically involving a MAX232
23980  or similar IC.
23981  If the hardware serial port of the MCU is not available search for 'Software
23982  UART' in your favourite search machine.
23983
23984 \layout Itemize
23985 use an on-target monitor.
23986  In this context a monitor is a small program which usually accepts commands
23987  via a serial line and allows to set program counter, to single step through
23988  a program and read/write memory locations.
23989  For the 8051 good examples of monitors are paulmon and cmon51 (see section
23990  
23991 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
23992
23993 \end_inset
23994
23995 ).
23996
23997 \layout Itemize
23998 toggle MCU port pins at strategic points within your code and use an oscilloscop
23999 e.
24000  A 
24001 \emph on
24002 digital oscilloscope
24003 \emph default
24004
24005 \begin_inset LatexCommand \index{Oscilloscope}
24006
24007 \end_inset
24008
24009  with deep trace memory is really helpful especially if you have to debug
24010  a realtime application.
24011  If you need to monitor more pins than your oscilloscope provides you can
24012  sometimes get away with a small R-2R network.
24013  On a single channel oscilloscope you could f.e.
24014  monitor 2 push-pull driven pins by connecting one via a 10\SpecialChar ~
24015 k
24016 \begin_inset Formula $\Omega$
24017 \end_inset
24018
24019  resistor and the other one by a 5\SpecialChar ~
24020 k
24021 \begin_inset Formula $\Omega$
24022 \end_inset
24023
24024  resistor to the oscilloscope probe (check output drive capability of the
24025  pins you want to monitor).
24026  If you need to monitor many more pins a 
24027 \emph on
24028 logic analyzer
24029 \emph default
24030  will be handy.
24031
24032 \layout Itemize
24033 use an ICE (
24034 \emph on
24035 i
24036 \emph default
24037
24038 \emph on
24039 c
24040 \emph default
24041 ircuit 
24042 \emph on
24043 e
24044 \emph default
24045 mulator
24046 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
24047
24048 \end_inset
24049
24050 ).
24051  Usually very expensive.
24052  And very nice to have too.
24053  And usually locks you (for years...) to the devices the ICE can emulate.
24054  
24055
24056 \layout Itemize
24057 use a remote debugger.
24058  In most 8-bit systems the symbol information is not available on the target,
24059  and a complete debugger is too bulky for the target system.
24060  Therefore usually a debugger on the host system connects to an on-target
24061  debugging stub which accepts only primitive commands.
24062  
24063 \newline
24064 Terms to enter into your favourite search engine could be 'remote debugging',
24065  'gdb stub' or 'inferior debugger'.
24066  (is there one?)
24067
24068 \layout Itemize
24069 use an on target hardware debugger.
24070  Some of the more modern MCUs include hardware support for setting break
24071  points and monitoring/changing variables by using dedicated hardware pins.
24072  This facility doesn't require additional code to run on the target and
24073  
24074 \emph on
24075 usually
24076 \emph default
24077  doesn't affect runtime behaviour until a breakpoint is hit.
24078  For the mcs51 most hardware debuggers use the AOMF
24079 \begin_inset LatexCommand \index{AOMF, AOMF51}
24080
24081 \end_inset
24082
24083  file (see 
24084 \begin_inset LatexCommand \ref{OMF file}
24085
24086 \end_inset
24087
24088 ) as input file.
24089  
24090
24091 \layout Standard
24092 Last not least:
24093
24094 \layout Itemize
24095 if you are not familiar with any of the following terms you're likely to
24096  run into problems rather sooner than later: 
24097 \emph on
24098 volatile
24099 \emph default
24100
24101 \emph on
24102 atomic
24103 \emph default
24104
24105 \emph on
24106 memory map
24107 \emph default
24108
24109 \emph on
24110 overlay
24111 \emph default
24112 .
24113  As an embedded programmer you 
24114 \emph on
24115 have
24116 \emph default
24117  to know them so why not look them up 
24118 \emph on
24119 before
24120 \emph default
24121  you have problems?)
24122
24123 \layout Itemize
24124 tell someone else about your problem (actually this is a surprisingly effective
24125  means to hunt down the bug even if the listener is not familiar with your
24126  environment).
24127  As 'failure to communicate' is probably one of the job-induced deformations
24128  of an embedded programmer this is highly encouraged.
24129
24130 \layout Section
24131 Debugging with SDCDB
24132 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
24133
24134 \end_inset
24135
24136
24137 \begin_inset LatexCommand \index{SDCDB (debugger)}
24138
24139 \end_inset
24140
24141  
24142
24143 \layout Standard
24144 SDCC is distributed with a source level debugger
24145 \begin_inset LatexCommand \index{Debugger}
24146
24147 \end_inset
24148
24149 .
24150  The debugger uses a command line interface, the command repertoire of the
24151  debugger has been kept as close to gdb
24152 \begin_inset LatexCommand \index{gdb}
24153
24154 \end_inset
24155
24156  (the GNU debugger) as possible.
24157  The configuration and build process is part of the standard compiler installati
24158 on, which also builds and installs the debugger in the target directory
24159  specified during configuration.
24160  The debugger allows you debug BOTH at the C source and at the ASM source
24161  level.
24162
24163 \layout Subsection
24164 Compiling for Debugging
24165
24166 \layout Standard
24167 The -
24168 \begin_inset ERT
24169 status Collapsed
24170
24171 \layout Standard
24172
24173
24174 \backslash
24175 /
24176
24177 \end_inset
24178
24179 -debug
24180 \begin_inset LatexCommand \index{-\/-debug}
24181
24182 \end_inset
24183
24184  option must be specified for all files for which debug information is to
24185  be generated.
24186  The compiler generates a .adb file for each of these files.
24187  The linker creates the .cdb
24188 \begin_inset LatexCommand \index{<file>.cdb}
24189
24190 \end_inset
24191
24192  file from the .adb
24193 \begin_inset LatexCommand \index{<file>.adb}
24194
24195 \end_inset
24196
24197  files and the address information.
24198  This .cdb is used by the debugger.
24199
24200 \layout Subsection
24201 How the Debugger Works
24202
24203 \layout Standard
24204 When the -
24205 \begin_inset ERT
24206 status Collapsed
24207
24208 \layout Standard
24209
24210
24211 \backslash
24212 /
24213
24214 \end_inset
24215
24216 -debug option is specified the compiler generates extra symbol information
24217  some of which are put into the assembler source and some are put into the
24218  .adb file.
24219  Then the linker creates the .cdb file from the individual .adb files with
24220  the address information for the symbols.
24221  The debugger reads the symbolic information generated by the compiler &
24222  the address information generated by the linker.
24223  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
24224  execution is controlled by the debugger.
24225  When a command is issued for the debugger, it translates it into appropriate
24226  commands for the simulator.
24227  (Currently SDCDM only connects to the simulator but 
24228 \emph on
24229 newcdb
24230 \emph default
24231  at 
24232 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
24233
24234 \end_inset
24235
24236  is an effort to connect directly to the hardware.) 
24237
24238 \layout Subsection
24239 Starting the Debugger SDCDB
24240
24241 \layout Standard
24242 The debugger can be started using the following command line.
24243  (Assume the file you are debugging has the file name foo).
24244 \newline
24245
24246 \newline
24247
24248 \family sans
24249 \series bold
24250 sdcdb foo
24251 \newline
24252
24253 \family default
24254 \series default
24255
24256 \newline
24257 The debugger will look for the following files.
24258
24259 \layout Itemize
24260 foo.c - the source file.
24261
24262 \layout Itemize
24263 foo.cdb - the debugger symbol information file.
24264
24265 \layout Itemize
24266 foo.ihx - the Intel hex format
24267 \begin_inset LatexCommand \index{Intel hex format}
24268
24269 \end_inset
24270
24271  object file.
24272
24273 \layout Subsection
24274 SDCDB Command Line Options
24275
24276 \layout Itemize
24277 -
24278 \begin_inset ERT
24279 status Collapsed
24280
24281 \layout Standard
24282
24283
24284 \backslash
24285 /
24286
24287 \end_inset
24288
24289 -directory=<source file directory> this option can used to specify the directory
24290  search list.
24291  The debugger will look into the directory list specified for source, cdb
24292  & ihx files.
24293  The items in the directory list must be separated by ':', e.g.
24294  if the source files can be in the directories /home/src1 and /home/src2,
24295  the -
24296 \begin_inset ERT
24297 status Collapsed
24298
24299 \layout Standard
24300
24301
24302 \backslash
24303 /
24304
24305 \end_inset
24306
24307 -directory option should be -
24308 \begin_inset ERT
24309 status Collapsed
24310
24311 \layout Standard
24312
24313
24314 \backslash
24315 /
24316
24317 \end_inset
24318
24319 -directory=/home/src1:/home/src2.
24320  Note there can be no spaces in the option.
24321  
24322
24323 \layout Itemize
24324 -cd <directory> - change to the <directory>.
24325
24326 \layout Itemize
24327 -fullname - used by GUI front ends.
24328
24329 \layout Itemize
24330 -cpu <cpu-type> - this argument is passed to the simulator please see the
24331  simulator docs for details.
24332
24333 \layout Itemize
24334 -X <Clock frequency > this options is passed to the simulator please see
24335  the simulator docs for details.
24336
24337 \layout Itemize
24338 -s <serial port file> passed to simulator see the simulator docs for details.
24339
24340 \layout Itemize
24341 -S <serial in,out> passed to simulator see the simulator docs for details.
24342
24343 \layout Itemize
24344 -k <port number> passed to simulator see the simulator docs for details.
24345
24346 \layout Subsection
24347 SDCDB Debugger Commands
24348
24349 \layout Standard
24350 As mentioned earlier the command interface for the debugger has been deliberatel
24351 y kept as close the GNU debugger gdb, as possible.
24352  This will help the integration with existing graphical user interfaces
24353  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
24354  If you use a graphical user interface for the debugger you can skip this
24355  section.
24356
24357 \layout Subsubsection*
24358 break [line | file:line | function | file:function]
24359
24360 \layout Standard
24361 Set breakpoint at specified line or function:
24362 \newline
24363
24364 \newline
24365
24366 \family sans
24367 \series bold
24368 sdcdb>break 100 
24369 \newline
24370 sdcdb>break foo.c:100
24371 \newline
24372 sdcdb>break funcfoo
24373 \newline
24374 sdcdb>break foo.c:funcfoo
24375
24376 \layout Subsubsection*
24377 clear [line | file:line | function | file:function ]
24378
24379 \layout Standard
24380 Clear breakpoint at specified line or function:
24381 \newline
24382
24383 \newline
24384
24385 \family sans
24386 \series bold
24387 sdcdb>clear 100
24388 \newline
24389 sdcdb>clear foo.c:100
24390 \newline
24391 sdcdb>clear funcfoo
24392 \newline
24393 sdcdb>clear foo.c:funcfoo
24394
24395 \layout Subsubsection*
24396 continue
24397
24398 \layout Standard
24399 Continue program being debugged, after breakpoint.
24400
24401 \layout Subsubsection*
24402 finish
24403
24404 \layout Standard
24405 Execute till the end of the current function.
24406
24407 \layout Subsubsection*
24408 delete [n]
24409
24410 \layout Standard
24411 Delete breakpoint number 'n'.
24412  If used without any option clear ALL user defined break points.
24413
24414 \layout Subsubsection*
24415 info [break | stack | frame | registers ]
24416
24417 \layout Itemize
24418 info break - list all breakpoints
24419
24420 \layout Itemize
24421 info stack - show the function call stack.
24422
24423 \layout Itemize
24424 info frame - show information about the current execution frame.
24425
24426 \layout Itemize
24427 info registers - show content of all registers.
24428
24429 \layout Subsubsection*
24430 step
24431
24432 \layout Standard
24433 Step program until it reaches a different source line.
24434  Note: pressing <return> repeats the last command.
24435
24436 \layout Subsubsection*
24437 next
24438
24439 \layout Standard
24440 Step program, proceeding through subroutine calls.
24441
24442 \layout Subsubsection*
24443 run
24444
24445 \layout Standard
24446 Start debugged program.
24447
24448 \layout Subsubsection*
24449 ptype variable 
24450
24451 \layout Standard
24452 Print type information of the variable.
24453
24454 \layout Subsubsection*
24455 print variable
24456
24457 \layout Standard
24458 print value of variable.
24459
24460 \layout Subsubsection*
24461 file filename
24462
24463 \layout Standard
24464 load the given file name.
24465  Note this is an alternate method of loading file for debugging.
24466
24467 \layout Subsubsection*
24468 frame
24469
24470 \layout Standard
24471 print information about current frame.
24472
24473 \layout Subsubsection*
24474 set srcmode
24475
24476 \layout Standard
24477 Toggle between C source & assembly source.
24478
24479 \layout Subsubsection*
24480 ! simulator command
24481
24482 \layout Standard
24483 Send the string following '!' to the simulator, the simulator response is
24484  displayed.
24485  Note the debugger does not interpret the command being sent to the simulator,
24486  so if a command like 'go' is sent the debugger can loose its execution
24487  context and may display incorrect values.
24488
24489 \layout Subsubsection*
24490 quit
24491
24492 \layout Standard
24493 "Watch me now.
24494  Iam going Down.
24495  My name is Bobby Brown"
24496
24497 \layout Subsection
24498 Interfacing SDCDB with DDD
24499
24500 \layout Standard
24501 \begin_inset Note
24502 collapsed true
24503
24504 \layout Standard
24505 The screenshot was converted from png to eps with: 
24506 \begin_inset Quotes sld
24507 \end_inset
24508
24509 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
24510 \begin_inset Quotes srd
24511 \end_inset
24512
24513  which produces a pretty compact eps file which is free from compression
24514  artifacts.
24515
24516 \layout Standard
24517 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
24518  as this broke the build system on Sourceforge (pdf-file was broken.
24519  pdflatex does not accept eps files).
24520
24521 \end_inset
24522
24523
24524
24525 \layout Standard
24526 The 
24527 \emph on
24528 p
24529 \emph default
24530 ortable 
24531 \emph on
24532 n
24533 \emph default
24534 etwork 
24535 \emph on
24536 g
24537 \emph default
24538 raphics File 
24539 \size footnotesize
24540
24541 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
24542
24543 \end_inset
24544
24545
24546 \size default
24547  shows a screenshot of a debugging session with DDD
24548 \begin_inset LatexCommand \index{DDD (debugger)}
24549
24550 \end_inset
24551
24552  (Unix only) on a simulated 8032.
24553  The debugging session might not run as smoothly as the screenshot suggests.
24554  The debugger allows setting of breakpoints, displaying and changing variables,
24555  single stepping through C and assembler code.
24556  
24557 \newline
24558 The source was compiled with 
24559 \family sans
24560 \series bold
24561
24562 \newline
24563
24564 \newline
24565 sdcc -
24566 \family default
24567 \series default
24568
24569 \begin_inset ERT
24570 status Collapsed
24571
24572 \layout Standard
24573
24574
24575 \backslash
24576 /
24577
24578 \end_inset
24579
24580
24581 \family sans
24582 \series bold
24583 -debug ddd_example.c
24584 \family default
24585 \series default
24586  
24587 \family sans
24588 \series bold
24589
24590 \newline
24591
24592 \family default
24593 \series default
24594
24595 \newline
24596 and DDD was invoked with 
24597 \family sans
24598 \series bold
24599
24600 \newline
24601
24602 \newline
24603 ddd -debugger "sdcdb -cpu 8032 ddd_example"
24604
24605 \layout Standard
24606 \begin_inset Note
24607 collapsed false
24608
24609 \layout Standard
24610 Check that the double quotes or an apostroph within the command line survive
24611  the LyX tool chain.
24612  Previously the apostrophs got slanted in the PDF output so a cut and paste
24613  did not work.
24614
24615 \end_inset
24616
24617
24618
24619 \layout Subsection
24620 Interfacing SDCDB with XEmacs
24621 \begin_inset LatexCommand \index{XEmacs}
24622
24623 \end_inset
24624
24625
24626 \begin_inset LatexCommand \index{Emacs}
24627
24628 \end_inset
24629
24630
24631
24632 \layout Standard
24633 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
24634  sdcdb.el and sdcdbsrc.el.
24635  These two files can be found in the $(prefix)/bin directory after the installat
24636 ion is complete.
24637  These files need to be loaded into XEmacs for the interface to work.
24638  This can be done at XEmacs startup time by inserting the following into
24639  your '.xemacs' file (which can be found in your HOME directory): 
24640 \newline
24641
24642 \newline
24643
24644 \family typewriter
24645 (load-file sdcdbsrc.el) 
24646 \family default
24647
24648 \newline
24649
24650 \newline
24651 .xemacs is a lisp file so the () around the command is REQUIRED.
24652  The files can also be loaded dynamically while XEmacs is running, set the
24653  environment variable 'EMACSLOADPATH' to the installation bin directory
24654  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
24655  To start the interface enter the following command: 
24656 \newline
24657
24658 \newline
24659
24660 \family sans
24661 \series bold
24662 ESC-x sdcdbsrc
24663 \family default
24664 \series default
24665
24666 \newline
24667
24668 \newline
24669 You will prompted to enter the file name to be debugged.
24670  
24671 \newline
24672
24673 \newline
24674 The command line options that are passed to the simulator directly are
24675  bound to default values in the file sdcdbsrc.el.
24676  The variables are listed below, these values maybe changed as required.
24677
24678 \layout Itemize
24679 sdcdbsrc-cpu-type '51
24680
24681 \layout Itemize
24682 sdcdbsrc-frequency '11059200
24683
24684 \layout Itemize
24685 sdcdbsrc-serial nil
24686
24687 \layout Standard
24688 The following is a list of key mapping for the debugger interface.
24689
24690 \layout Standard
24691 \SpecialChar ~
24692 \pagebreak_bottom 
24693
24694 \family typewriter
24695
24696 \newline
24697 ;;\SpecialChar ~
24698 Current Listing :: 
24699 \newline
24700 ;;key\SpecialChar ~
24701 \SpecialChar ~
24702 \SpecialChar ~
24703 \SpecialChar ~
24704 \SpecialChar ~
24705 \SpecialChar ~
24706 \SpecialChar ~
24707 \SpecialChar ~
24708 \SpecialChar ~
24709 \SpecialChar ~
24710 \SpecialChar ~
24711 \SpecialChar ~
24712 \SpecialChar ~
24713 \SpecialChar ~
24714 binding\SpecialChar ~
24715 \SpecialChar ~
24716 \SpecialChar ~
24717 \SpecialChar ~
24718 \SpecialChar ~
24719 \SpecialChar ~
24720 \SpecialChar ~
24721 \SpecialChar ~
24722 \SpecialChar ~
24723 \SpecialChar ~
24724 \SpecialChar ~
24725 \SpecialChar ~
24726 \SpecialChar ~
24727 \SpecialChar ~
24728 \SpecialChar ~
24729 \SpecialChar ~
24730 \SpecialChar ~
24731 \SpecialChar ~
24732 \SpecialChar ~
24733 \SpecialChar ~
24734 \SpecialChar ~
24735 \SpecialChar ~
24736 Comment 
24737 \newline
24738 ;;---\SpecialChar ~
24739 \SpecialChar ~
24740 \SpecialChar ~
24741 \SpecialChar ~
24742 \SpecialChar ~
24743 \SpecialChar ~
24744 \SpecialChar ~
24745 \SpecialChar ~
24746 \SpecialChar ~
24747 \SpecialChar ~
24748 \SpecialChar ~
24749 \SpecialChar ~
24750 \SpecialChar ~
24751 \SpecialChar ~
24752 -------\SpecialChar ~
24753 \SpecialChar ~
24754 \SpecialChar ~
24755 \SpecialChar ~
24756 \SpecialChar ~
24757 \SpecialChar ~
24758 \SpecialChar ~
24759 \SpecialChar ~
24760 \SpecialChar ~
24761 \SpecialChar ~
24762 \SpecialChar ~
24763 \SpecialChar ~
24764 \SpecialChar ~
24765 \SpecialChar ~
24766 \SpecialChar ~
24767 \SpecialChar ~
24768 \SpecialChar ~
24769 \SpecialChar ~
24770 \SpecialChar ~
24771 \SpecialChar ~
24772 \SpecialChar ~
24773 \SpecialChar ~
24774 -------
24775 \newline
24776 ;; 
24777 \newline
24778 ;;\SpecialChar ~
24779 n\SpecialChar ~
24780 \SpecialChar ~
24781 \SpecialChar ~
24782 \SpecialChar ~
24783 \SpecialChar ~
24784 \SpecialChar ~
24785 \SpecialChar ~
24786 \SpecialChar ~
24787 \SpecialChar ~
24788 \SpecialChar ~
24789 \SpecialChar ~
24790 \SpecialChar ~
24791 \SpecialChar ~
24792 \SpecialChar ~
24793 \SpecialChar ~
24794 sdcdb-next-fro
24795 m-src\SpecialChar ~
24796 \SpecialChar ~
24797 \SpecialChar ~
24798 \SpecialChar ~
24799 \SpecialChar ~
24800 \SpecialChar ~
24801 \SpecialChar ~
24802 \SpecialChar ~
24803 \SpecialChar ~
24804 \SpecialChar ~
24805 SDCDB next command 
24806 \newline
24807 ;;\SpecialChar ~
24808 b\SpecialChar ~
24809 \SpecialChar ~
24810 \SpecialChar ~
24811 \SpecialChar ~
24812 \SpecialChar ~
24813 \SpecialChar ~
24814 \SpecialChar ~
24815 \SpecialChar ~
24816 \SpecialChar ~
24817 \SpecialChar ~
24818 \SpecialChar ~
24819 \SpecialChar ~
24820 \SpecialChar ~
24821 \SpecialChar ~
24822 \SpecialChar ~
24823 sdcdb-back-from-src\SpecialChar ~
24824 \SpecialChar ~
24825 \SpecialChar ~
24826 \SpecialChar ~
24827 \SpecialChar ~
24828 \SpecialChar ~
24829 \SpecialChar ~
24830 \SpecialChar ~
24831 \SpecialChar ~
24832 \SpecialChar ~
24833 SDCDB back command 
24834 \newline
24835 ;;\SpecialChar ~
24836 c\SpecialChar ~
24837 \SpecialChar ~
24838 \SpecialChar ~
24839 \SpecialChar ~
24840 \SpecialChar ~
24841 \SpecialChar ~
24842 \SpecialChar ~
24843 \SpecialChar ~
24844 \SpecialChar ~
24845 \SpecialChar ~
24846 \SpecialChar ~
24847 \SpecialChar ~
24848 \SpecialChar ~
24849 \SpecialChar ~
24850 \SpecialChar ~
24851 sdcdb-cont-f
24852 rom-src\SpecialChar ~
24853 \SpecialChar ~
24854 \SpecialChar ~
24855 \SpecialChar ~
24856 \SpecialChar ~
24857 \SpecialChar ~
24858 \SpecialChar ~
24859 \SpecialChar ~
24860 \SpecialChar ~
24861 \SpecialChar ~
24862 SDCDB continue command
24863 \newline
24864 ;;\SpecialChar ~
24865 s\SpecialChar ~
24866 \SpecialChar ~
24867 \SpecialChar ~
24868 \SpecialChar ~
24869 \SpecialChar ~
24870 \SpecialChar ~
24871 \SpecialChar ~
24872 \SpecialChar ~
24873 \SpecialChar ~
24874 \SpecialChar ~
24875 \SpecialChar ~
24876 \SpecialChar ~
24877 \SpecialChar ~
24878 \SpecialChar ~
24879 \SpecialChar ~
24880 sdcdb-step-from-src\SpecialChar ~
24881 \SpecialChar ~
24882 \SpecialChar ~
24883 \SpecialChar ~
24884 \SpecialChar ~
24885 \SpecialChar ~
24886 \SpecialChar ~
24887 \SpecialChar ~
24888 \SpecialChar ~
24889 \SpecialChar ~
24890 SDCDB step command 
24891 \newline
24892 ;;\SpecialChar ~
24893 ?\SpecialChar ~
24894 \SpecialChar ~
24895 \SpecialChar ~
24896 \SpecialChar ~
24897 \SpecialChar ~
24898 \SpecialChar ~
24899 \SpecialChar ~
24900 \SpecialChar ~
24901 \SpecialChar ~
24902 \SpecialChar ~
24903 \SpecialChar ~
24904 \SpecialChar ~
24905 \SpecialChar ~
24906 \SpecialChar ~
24907 \SpecialChar ~
24908 sdcdb-w
24909 hatis-c-sexp\SpecialChar ~
24910 \SpecialChar ~
24911 \SpecialChar ~
24912 \SpecialChar ~
24913 \SpecialChar ~
24914 \SpecialChar ~
24915 \SpecialChar ~
24916 \SpecialChar ~
24917 \SpecialChar ~
24918 \SpecialChar ~
24919 SDCDB ptypecommand for data at 
24920 \newline
24921 ;;\SpecialChar ~
24922 \SpecialChar ~
24923 \SpecialChar ~
24924 \SpecialChar ~
24925 \SpecialChar ~
24926 \SpecialChar ~
24927 \SpecialChar ~
24928 \SpecialChar ~
24929 \SpecialChar ~
24930 \SpecialChar ~
24931 \SpecialChar ~
24932 \SpecialChar ~
24933 \SpecialChar ~
24934 \SpecialChar ~
24935 \SpecialChar ~
24936 \SpecialChar ~
24937 \SpecialChar ~
24938 \SpecialChar ~
24939 \SpecialChar ~
24940 \SpecialChar ~
24941 \SpecialChar ~
24942 \SpecialChar ~
24943 \SpecialChar ~
24944 \SpecialChar ~
24945 \SpecialChar ~
24946 \SpecialChar ~
24947 \SpecialChar ~
24948 \SpecialChar ~
24949 \SpecialChar ~
24950 \SpecialChar ~
24951 \SpecialChar ~
24952 \SpecialChar ~
24953 \SpecialChar ~
24954 \SpecialChar ~
24955 \SpecialChar ~
24956 \SpecialChar ~
24957 \SpecialChar ~
24958 \SpecialChar ~
24959 \SpecialChar ~
24960 \SpecialChar ~
24961 \SpecialChar ~
24962 \SpecialChar ~
24963 \SpecialChar ~
24964 \SpecialChar ~
24965 \SpecialChar ~
24966 \SpecialChar ~
24967 \SpecialChar ~
24968 buffer point 
24969 \newline
24970 ;;\SpecialChar ~
24971 x\SpecialChar ~
24972 \SpecialChar ~
24973 \SpecialChar ~
24974 \SpecialChar ~
24975 \SpecialChar ~
24976 \SpecialChar ~
24977 \SpecialChar ~
24978 \SpecialChar ~
24979 \SpecialChar ~
24980 \SpecialChar ~
24981 \SpecialChar ~
24982 \SpecialChar ~
24983 \SpecialChar ~
24984 \SpecialChar ~
24985 \SpecialChar ~
24986 sdcdbsrc-delete\SpecialChar ~
24987 \SpecialChar ~
24988 \SpecialChar ~
24989 \SpecialChar ~
24990 \SpecialChar ~
24991 \SpecialChar ~
24992 \SpecialChar ~
24993 \SpecialChar ~
24994 \SpecialChar ~
24995 \SpecialChar ~
24996 \SpecialChar ~
24997 \SpecialChar ~
24998 \SpecialChar ~
24999 \SpecialChar ~
25000 SDCD
25001 B Delete all breakpoints if no arg 
25002 \newline
25003 ;;\SpecialChar ~
25004 \SpecialChar ~
25005 \SpecialChar ~
25006 \SpecialChar ~
25007 \SpecialChar ~
25008 \SpecialChar ~
25009 \SpecialChar ~
25010 \SpecialChar ~
25011 \SpecialChar ~
25012 \SpecialChar ~
25013 \SpecialChar ~
25014 \SpecialChar ~
25015 \SpecialChar ~
25016 \SpecialChar ~
25017 \SpecialChar ~
25018 \SpecialChar ~
25019 \SpecialChar ~
25020 \SpecialChar ~
25021 \SpecialChar ~
25022 \SpecialChar ~
25023 \SpecialChar ~
25024 \SpecialChar ~
25025 \SpecialChar ~
25026 \SpecialChar ~
25027 \SpecialChar ~
25028 \SpecialChar ~
25029 \SpecialChar ~
25030 \SpecialChar ~
25031 \SpecialChar ~
25032 \SpecialChar ~
25033 \SpecialChar ~
25034 \SpecialChar ~
25035 \SpecialChar ~
25036 \SpecialChar ~
25037 \SpecialChar ~
25038 \SpecialChar ~
25039 \SpecialChar ~
25040 \SpecialChar ~
25041 \SpecialChar ~
25042 \SpecialChar ~
25043 \SpecialChar ~
25044 \SpecialChar ~
25045 \SpecialChar ~
25046 \SpecialChar ~
25047 \SpecialChar ~
25048 \SpecialChar ~
25049 \SpecialChar ~
25050 given or delete arg (C-u arg x) 
25051 \newline
25052 ;;\SpecialChar ~
25053 m\SpecialChar ~
25054 \SpecialChar ~
25055 \SpecialChar ~
25056 \SpecialChar ~
25057 \SpecialChar ~
25058 \SpecialChar ~
25059 \SpecialChar ~
25060 \SpecialChar ~
25061 \SpecialChar ~
25062 \SpecialChar ~
25063 \SpecialChar ~
25064 \SpecialChar ~
25065 \SpecialChar ~
25066 \SpecialChar ~
25067 \SpecialChar ~
25068 sdcdbsrc
25069 -frame\SpecialChar ~
25070 \SpecialChar ~
25071 \SpecialChar ~
25072 \SpecialChar ~
25073 \SpecialChar ~
25074 \SpecialChar ~
25075 \SpecialChar ~
25076 \SpecialChar ~
25077 \SpecialChar ~
25078 \SpecialChar ~
25079 \SpecialChar ~
25080 \SpecialChar ~
25081 \SpecialChar ~
25082 \SpecialChar ~
25083 \SpecialChar ~
25084 SDCDB Display current frame if no arg, 
25085 \newline
25086 ;;\SpecialChar ~
25087 \SpecialChar ~
25088 \SpecialChar ~
25089 \SpecialChar ~
25090 \SpecialChar ~
25091 \SpecialChar ~
25092 \SpecialChar ~
25093 \SpecialChar ~
25094 \SpecialChar ~
25095 \SpecialChar ~
25096 \SpecialChar ~
25097 \SpecialChar ~
25098 \SpecialChar ~
25099 \SpecialChar ~
25100 \SpecialChar ~
25101 \SpecialChar ~
25102 \SpecialChar ~
25103 \SpecialChar ~
25104 \SpecialChar ~
25105 \SpecialChar ~
25106 \SpecialChar ~
25107 \SpecialChar ~
25108 \SpecialChar ~
25109 \SpecialChar ~
25110 \SpecialChar ~
25111 \SpecialChar ~
25112 \SpecialChar ~
25113 \SpecialChar ~
25114 \SpecialChar ~
25115 \SpecialChar ~
25116 \SpecialChar ~
25117 \SpecialChar ~
25118 \SpecialChar ~
25119 \SpecialChar ~
25120 \SpecialChar ~
25121 \SpecialChar ~
25122 \SpecialChar ~
25123 \SpecialChar ~
25124 \SpecialChar ~
25125 \SpecialChar ~
25126 \SpecialChar ~
25127 \SpecialChar ~
25128 \SpecialChar ~
25129 \SpecialChar ~
25130 \SpecialChar ~
25131 \SpecialChar ~
25132 \SpecialChar ~
25133 given or display frame arg
25134  
25135 \newline
25136 ;;\SpecialChar ~
25137 \SpecialChar ~
25138 \SpecialChar ~
25139 \SpecialChar ~
25140 \SpecialChar ~
25141 \SpecialChar ~
25142 \SpecialChar ~
25143 \SpecialChar ~
25144 \SpecialChar ~
25145 \SpecialChar ~
25146 \SpecialChar ~
25147 \SpecialChar ~
25148 \SpecialChar ~
25149 \SpecialChar ~
25150 \SpecialChar ~
25151 \SpecialChar ~
25152 \SpecialChar ~
25153 \SpecialChar ~
25154 \SpecialChar ~
25155 \SpecialChar ~
25156 \SpecialChar ~
25157 \SpecialChar ~
25158 \SpecialChar ~
25159 \SpecialChar ~
25160 \SpecialChar ~
25161 \SpecialChar ~
25162 \SpecialChar ~
25163 \SpecialChar ~
25164 \SpecialChar ~
25165 \SpecialChar ~
25166 \SpecialChar ~
25167 \SpecialChar ~
25168 \SpecialChar ~
25169 \SpecialChar ~
25170 \SpecialChar ~
25171 \SpecialChar ~
25172 \SpecialChar ~
25173 \SpecialChar ~
25174 \SpecialChar ~
25175 \SpecialChar ~
25176 \SpecialChar ~
25177 \SpecialChar ~
25178 \SpecialChar ~
25179 \SpecialChar ~
25180 \SpecialChar ~
25181 \SpecialChar ~
25182 \SpecialChar ~
25183 buffer point 
25184 \newline
25185 ;;\SpecialChar ~
25186 !\SpecialChar ~
25187 \SpecialChar ~
25188 \SpecialChar ~
25189 \SpecialChar ~
25190 \SpecialChar ~
25191 \SpecialChar ~
25192 \SpecialChar ~
25193 \SpecialChar ~
25194 \SpecialChar ~
25195 \SpecialChar ~
25196 \SpecialChar ~
25197 \SpecialChar ~
25198 \SpecialChar ~
25199 \SpecialChar ~
25200 \SpecialChar ~
25201 sdcdbsrc-goto-sdcdb\SpecialChar ~
25202 \SpecialChar ~
25203 \SpecialChar ~
25204 \SpecialChar ~
25205 \SpecialChar ~
25206 \SpecialChar ~
25207 \SpecialChar ~
25208 \SpecialChar ~
25209 \SpecialChar ~
25210 \SpecialChar ~
25211 Goto the SDCDB output buffer 
25212 \newline
25213 ;;\SpecialChar ~
25214 p\SpecialChar ~
25215 \SpecialChar ~
25216 \SpecialChar ~
25217 \SpecialChar ~
25218 \SpecialChar ~
25219 \SpecialChar ~
25220 \SpecialChar ~
25221 \SpecialChar ~
25222 \SpecialChar ~
25223 \SpecialChar ~
25224 \SpecialChar ~
25225 \SpecialChar ~
25226 \SpecialChar ~
25227 \SpecialChar ~
25228 \SpecialChar ~
25229 sdcdb-prin
25230 t-c-sexp\SpecialChar ~
25231 \SpecialChar ~
25232 \SpecialChar ~
25233 \SpecialChar ~
25234 \SpecialChar ~
25235 \SpecialChar ~
25236 \SpecialChar ~
25237 \SpecialChar ~
25238 \SpecialChar ~
25239 \SpecialChar ~
25240 \SpecialChar ~
25241 SDCDB print command for data at 
25242 \newline
25243 ;;\SpecialChar ~
25244 \SpecialChar ~
25245 \SpecialChar ~
25246 \SpecialChar ~
25247 \SpecialChar ~
25248 \SpecialChar ~
25249 \SpecialChar ~
25250 \SpecialChar ~
25251 \SpecialChar ~
25252 \SpecialChar ~
25253 \SpecialChar ~
25254 \SpecialChar ~
25255 \SpecialChar ~
25256 \SpecialChar ~
25257 \SpecialChar ~
25258 \SpecialChar ~
25259 \SpecialChar ~
25260 \SpecialChar ~
25261 \SpecialChar ~
25262 \SpecialChar ~
25263 \SpecialChar ~
25264 \SpecialChar ~
25265 \SpecialChar ~
25266 \SpecialChar ~
25267 \SpecialChar ~
25268 \SpecialChar ~
25269 \SpecialChar ~
25270 \SpecialChar ~
25271 \SpecialChar ~
25272 \SpecialChar ~
25273 \SpecialChar ~
25274 \SpecialChar ~
25275 \SpecialChar ~
25276 \SpecialChar ~
25277 \SpecialChar ~
25278 \SpecialChar ~
25279 \SpecialChar ~
25280 \SpecialChar ~
25281 \SpecialChar ~
25282 \SpecialChar ~
25283 \SpecialChar ~
25284 \SpecialChar ~
25285 \SpecialChar ~
25286 \SpecialChar ~
25287 \SpecialChar ~
25288 \SpecialChar ~
25289 \SpecialChar ~
25290 buffer point 
25291 \newline
25292 ;;\SpecialChar ~
25293 g\SpecialChar ~
25294 \SpecialChar ~
25295 \SpecialChar ~
25296 \SpecialChar ~
25297 \SpecialChar ~
25298 \SpecialChar ~
25299 \SpecialChar ~
25300 \SpecialChar ~
25301 \SpecialChar ~
25302 \SpecialChar ~
25303 \SpecialChar ~
25304 \SpecialChar ~
25305 \SpecialChar ~
25306 \SpecialChar ~
25307 \SpecialChar ~
25308 sdcdbsrc-goto-sdcdb\SpecialChar ~
25309 \SpecialChar ~
25310 \SpecialChar ~
25311 \SpecialChar ~
25312 \SpecialChar ~
25313 \SpecialChar ~
25314 \SpecialChar ~
25315 \SpecialChar ~
25316 \SpecialChar ~
25317 \SpecialChar ~
25318 Got
25319 o the SDCDB output buffer 
25320 \newline
25321 ;;\SpecialChar ~
25322 t\SpecialChar ~
25323 \SpecialChar ~
25324 \SpecialChar ~
25325 \SpecialChar ~
25326 \SpecialChar ~
25327 \SpecialChar ~
25328 \SpecialChar ~
25329 \SpecialChar ~
25330 \SpecialChar ~
25331 \SpecialChar ~
25332 \SpecialChar ~
25333 \SpecialChar ~
25334 \SpecialChar ~
25335 \SpecialChar ~
25336 \SpecialChar ~
25337 sdcdbsrc-mode\SpecialChar ~
25338 \SpecialChar ~
25339 \SpecialChar ~
25340 \SpecialChar ~
25341 \SpecialChar ~
25342 \SpecialChar ~
25343 \SpecialChar ~
25344 \SpecialChar ~
25345 \SpecialChar ~
25346 \SpecialChar ~
25347 \SpecialChar ~
25348 \SpecialChar ~
25349 \SpecialChar ~
25350 \SpecialChar ~
25351 \SpecialChar ~
25352 \SpecialChar ~
25353 Toggles Sdcdbsrc mode (turns it
25354  off) 
25355 \newline
25356 ;; 
25357 \newline
25358 ;;\SpecialChar ~
25359 C-c\SpecialChar ~
25360 C-f\SpecialChar ~
25361 \SpecialChar ~
25362 \SpecialChar ~
25363 \SpecialChar ~
25364 \SpecialChar ~
25365 \SpecialChar ~
25366 \SpecialChar ~
25367 \SpecialChar ~
25368 \SpecialChar ~
25369 sdcdb-finish-from-src\SpecialChar ~
25370 \SpecialChar ~
25371 \SpecialChar ~
25372 \SpecialChar ~
25373 \SpecialChar ~
25374 \SpecialChar ~
25375 \SpecialChar ~
25376 \SpecialChar ~
25377 SDCDB finish command 
25378 \newline
25379 ;; 
25380 \newline
25381 ;;\SpecialChar ~
25382 C-x\SpecialChar ~
25383 SPC\SpecialChar ~
25384 \SpecialChar ~
25385 \SpecialChar ~
25386 \SpecialChar ~
25387 \SpecialChar ~
25388 \SpecialChar ~
25389 \SpecialChar ~
25390 \SpecialChar ~
25391 \SpecialChar ~
25392 sdcdb-brea
25393 k\SpecialChar ~
25394 \SpecialChar ~
25395 \SpecialChar ~
25396 \SpecialChar ~
25397 \SpecialChar ~
25398 \SpecialChar ~
25399 \SpecialChar ~
25400 \SpecialChar ~
25401 \SpecialChar ~
25402 \SpecialChar ~
25403 \SpecialChar ~
25404 \SpecialChar ~
25405 \SpecialChar ~
25406 \SpecialChar ~
25407 \SpecialChar ~
25408 \SpecialChar ~
25409 \SpecialChar ~
25410 \SpecialChar ~
25411 Set break for line with point 
25412 \newline
25413 ;;\SpecialChar ~
25414 ESC\SpecialChar ~
25415 t\SpecialChar ~
25416 \SpecialChar ~
25417 \SpecialChar ~
25418 \SpecialChar ~
25419 \SpecialChar ~
25420 \SpecialChar ~
25421 \SpecialChar ~
25422 \SpecialChar ~
25423 \SpecialChar ~
25424 \SpecialChar ~
25425 \SpecialChar ~
25426 sdcdbsrc-mode\SpecialChar ~
25427 \SpecialChar ~
25428 \SpecialChar ~
25429 \SpecialChar ~
25430 \SpecialChar ~
25431 \SpecialChar ~
25432 \SpecialChar ~
25433 \SpecialChar ~
25434 \SpecialChar ~
25435 \SpecialChar ~
25436 \SpecialChar ~
25437 \SpecialChar ~
25438 \SpecialChar ~
25439 \SpecialChar ~
25440 \SpecialChar ~
25441 \SpecialChar ~
25442 Toggle Sdcdbsrc mode 
25443 \newline
25444 ;;\SpecialChar ~
25445 ESC\SpecialChar ~
25446 m\SpecialChar ~
25447 \SpecialChar ~
25448 \SpecialChar ~
25449 \SpecialChar ~
25450 \SpecialChar ~
25451 \SpecialChar ~
25452 \SpecialChar ~
25453 \SpecialChar ~
25454 \SpecialChar ~
25455 \SpecialChar ~
25456 \SpecialChar ~
25457 sdc
25458 dbsrc-srcmode\SpecialChar ~
25459 \SpecialChar ~
25460 \SpecialChar ~
25461 \SpecialChar ~
25462 \SpecialChar ~
25463 \SpecialChar ~
25464 \SpecialChar ~
25465 \SpecialChar ~
25466 \SpecialChar ~
25467 \SpecialChar ~
25468 \SpecialChar ~
25469 \SpecialChar ~
25470 \SpecialChar ~
25471 Toggle list mode 
25472 \newline
25473 ;; 
25474 \newline
25475
25476
25477
25478 \layout Chapter
25479 TIPS
25480
25481 \layout Standard
25482 Here are a few guidelines that will help the compiler generate more efficient
25483  code, some of the tips are specific to this compiler others are generally
25484  good programming practice.
25485
25486 \layout Itemize
25487 Use the smallest data type to represent your data-value.
25488  If it is known in advance that the value is going to be less than 256 then
25489  use an 'unsigned char' instead of a 'short' or 'int'.
25490  Please note, that ANSI C requires both signed and unsigned chars to be
25491  promoted to 'signed int'
25492 \begin_inset LatexCommand \index{promotion to signed int}
25493
25494 \end_inset
25495
25496
25497 \begin_inset Marginal
25498 collapsed true
25499
25500 \layout Standard
25501
25502 \series bold
25503 \SpecialChar ~
25504 !
25505
25506 \end_inset
25507
25508  before doing any operation.
25509  This promotion
25510 \begin_inset LatexCommand \index{type promotion}
25511
25512 \end_inset
25513
25514
25515 \begin_inset LatexCommand \label{type promotion}
25516
25517 \end_inset
25518
25519  can be omitted, if the result is the same.
25520  The effect of the promotion rules together with the sign-extension is often
25521  surprising:
25522
25523 \begin_deeper
25524 \layout Verse
25525
25526 \family typewriter
25527 unsigned char uc = 0xfe;
25528 \newline
25529 if (uc * uc < 0) /* this is true! */
25530 \newline
25531 {
25532 \newline
25533 \SpecialChar ~
25534 \SpecialChar ~
25535 \SpecialChar ~
25536 \SpecialChar ~
25537 ....
25538 \newline
25539 }
25540
25541 \layout Standard
25542
25543 \family typewriter
25544 uc * uc
25545 \family default
25546  is evaluated as 
25547 \family typewriter
25548 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
25549 \family default
25550 .
25551  
25552 \newline
25553 Another one:
25554
25555 \layout Verse
25556
25557 \family typewriter
25558 (unsigned char) -12 / (signed char) -3 = ...
25559
25560 \layout Standard
25561 No, the result is not 4:
25562
25563 \layout Verse
25564
25565 \family typewriter
25566 (int) (unsigned char) -12 / (int) (signed char) -3 =
25567 \newline
25568 (int) (unsigned char)
25569  0xf4 / (int) (signed char) 0xfd =
25570 \newline
25571 (int) 0x00f4 / (int) 0xfffd =
25572 \newline
25573 (int) 0x00f4
25574  / (int) 0xfffd =
25575 \newline
25576 (int) 244 / (int) -3 =
25577 \newline
25578 (int) -81 = (int) 0xffaf;
25579
25580 \layout Standard
25581 Don't complain, that gcc gives you a different result.
25582  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
25583  Therefore the results are different.
25584 \newline
25585 From 
25586 \begin_inset Quotes sld
25587 \end_inset
25588
25589 comp.lang.c FAQ
25590 \begin_inset Quotes srd
25591 \end_inset
25592
25593 :
25594
25595 \layout Quote
25596
25597 \emph on
25598 If well-defined overflow characteristics are important and negative values
25599  are not, or if you want to steer clear of sign-extension problems when
25600  manipulating bits or bytes, use one of the corresponding unsigned types.
25601  (Beware when mixing signed and unsigned values in expressions, though.)
25602 \newline
25603 Although
25604  character types (especially unsigned char) can be used as "tiny" integers,
25605  doing so is sometimes more trouble than it's worth, due to unpredictable
25606  sign extension and increased code size.
25607
25608 \end_deeper
25609 \layout Itemize
25610 Use unsigned when it is known in advance that the value is not going to
25611  be negative.
25612  This helps especially if you are doing division or multiplication, bit-shifting
25613  or are using an array index.
25614
25615 \layout Itemize
25616 NEVER jump into a LOOP.
25617
25618 \layout Itemize
25619 Declare the variables to be local
25620 \begin_inset LatexCommand \index{local variables}
25621
25622 \end_inset
25623
25624  whenever possible, especially loop control variables (induction).
25625
25626 \layout Itemize
25627 Have a look at the assembly listing to get a 
25628 \begin_inset Quotes sld
25629 \end_inset
25630
25631 feeling
25632 \begin_inset Quotes srd
25633 \end_inset
25634
25635  for the code generation.
25636
25637 \layout Section
25638 Porting code from or to other compilers
25639 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
25640
25641 \end_inset
25642
25643
25644
25645 \layout Itemize
25646 check whether endianness of the compilers differs and adapt where needed.
25647
25648 \layout Itemize
25649 check the device specific header files
25650 \begin_inset LatexCommand \index{Header files}
25651
25652 \end_inset
25653
25654
25655 \begin_inset LatexCommand \index{Include files}
25656
25657 \end_inset
25658
25659  for compiler specific syntax.
25660  Eventually include the file <compiler.h
25661 \begin_inset LatexCommand \index{compiler.h (include file)}
25662
25663 \end_inset
25664
25665
25666 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
25667
25668 \end_inset
25669
25670  to allow using common header files.
25671  (see f.e.
25672  cc2510fx.h 
25673 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
25674
25675 \end_inset
25676
25677 ).
25678
25679 \layout Itemize
25680 check whether the startup code contains the correct initialization (watchdog,
25681  peripherals).
25682
25683 \layout Itemize
25684 check whether the sizes of short, int, long match.
25685
25686 \layout Itemize
25687 check if some 16 or 32 bit hardware registers require a specific addressing
25688  order (least significant or most significant byte first) and adapt if needed
25689  (
25690 \emph on
25691 first
25692 \emph default
25693  and 
25694 \emph on
25695 last
25696 \emph default
25697  relate to time and not to lower/upper memory location here, so this is
25698  
25699 \emph on
25700 not
25701 \emph default
25702  the same as endianness).
25703
25704 \layout Itemize
25705 check whether the keyword 
25706 \emph on
25707 volatile
25708 \emph default
25709  is used where needed.
25710  The compilers might differ in their optimization characteristics (as different
25711  versions of the same compiler might also use more clever optimizations
25712  this is good idea anyway).
25713  See section 
25714 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
25715
25716 \end_inset
25717
25718 .
25719
25720 \layout Itemize
25721 check that the compilers are not told to supress warnings.
25722
25723 \layout Itemize
25724 check and convert compiler specific extensions (interrupts, memory areas,
25725  pragmas etc.).
25726
25727 \layout Itemize
25728 check for differences in type promotion.
25729  Especially check for math operations on 
25730 \family typewriter
25731 char
25732 \family default
25733  or 
25734 \family typewriter
25735 unsigned char
25736 \family default
25737  variables.
25738  For the sake of C99 compatibility SDCC will probably promote these to 
25739 \family typewriter
25740 int
25741 \family default
25742  more often than other compilers.
25743  Eventually insert explicit casts to 
25744 \family typewriter
25745 (char) 
25746 \family default
25747 or
25748 \family typewriter
25749  (unsigned char)
25750 \family default
25751 .
25752  Also check that the ~\SpecialChar ~
25753 operator
25754 \begin_inset LatexCommand \index{\~\/ Operator}
25755
25756 \end_inset
25757
25758  is not used on 
25759 \family typewriter
25760 bit
25761 \begin_inset LatexCommand \index{bit}
25762
25763 \end_inset
25764
25765
25766 \family default
25767  variables, use the !\SpecialChar ~
25768 operator instead.
25769  See sections 
25770 \begin_inset LatexCommand \ref{type promotion}
25771
25772 \end_inset
25773
25774  and 
25775 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
25776
25777 \end_inset
25778
25779 .
25780
25781 \layout Itemize
25782 check the assembly code generated for interrupt routines (f.e.
25783  for calls to possibly non-reentrant library functions).
25784
25785 \layout Itemize
25786 check whether timing loops result in proper timing (or preferably consider
25787  a rewrite of the code with timer based delays instead).
25788
25789 \layout Itemize
25790 check for differences in printf parameters (some compilers push (va_arg
25791 \begin_inset LatexCommand \index{vararg, va\_arg}
25792
25793 \end_inset
25794
25795 ) char variables as 
25796 \family typewriter
25797 int
25798 \family default
25799  others push them as 
25800 \family typewriter
25801 char
25802 \family default
25803 .
25804  See section 
25805 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
25806
25807 \end_inset
25808
25809 ).
25810
25811 \layout Itemize
25812 check the resulting memory map
25813 \begin_inset LatexCommand \index{Memory map}
25814
25815 \end_inset
25816
25817 .
25818  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
25819 ly idata, pdata, xdata).
25820  Eventually check if unexpected library functions are included.
25821
25822 \layout Section
25823 Tools
25824 \begin_inset LatexCommand \index{Tools}
25825
25826 \end_inset
25827
25828  included in the distribution
25829
25830 \layout Standard
25831 \align left
25832 \begin_inset Tabular
25833 <lyxtabular version="3" rows="12" columns="3">
25834 <features>
25835 <column alignment="left" valignment="top" leftline="true" width="0pt">
25836 <column alignment="left" valignment="top" leftline="true" width="0pt">
25837 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
25838 <row topline="true" bottomline="true">
25839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25840 \begin_inset Text
25841
25842 \layout Standard
25843
25844 \series bold
25845 Name
25846
25847 \end_inset
25848 </cell>
25849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25850 \begin_inset Text
25851
25852 \layout Standard
25853
25854 \series bold
25855 Purpose
25856
25857 \end_inset
25858 </cell>
25859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25860 \begin_inset Text
25861
25862 \layout Standard
25863
25864 \series bold
25865 Directory
25866
25867 \end_inset
25868 </cell>
25869 </row>
25870 <row topline="true">
25871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25872 \begin_inset Text
25873
25874 \layout Standard
25875 uCsim
25876 \begin_inset LatexCommand \index{uCsim}
25877
25878 \end_inset
25879
25880
25881
25882 \end_inset
25883 </cell>
25884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25885 \begin_inset Text
25886
25887 \layout Standard
25888 Simulator for various architectures
25889
25890 \end_inset
25891 </cell>
25892 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25893 \begin_inset Text
25894
25895 \layout Standard
25896 sdcc/sim/ucsim
25897
25898 \end_inset
25899 </cell>
25900 </row>
25901 <row topline="true">
25902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25903 \begin_inset Text
25904
25905 \layout Standard
25906 keil2sdcc.pl
25907
25908 \end_inset
25909 </cell>
25910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25911 \begin_inset Text
25912
25913 \layout Standard
25914 header file
25915 \begin_inset LatexCommand \index{Header files}
25916
25917 \end_inset
25918
25919
25920 \begin_inset LatexCommand \index{Include files}
25921
25922 \end_inset
25923
25924  conversion
25925
25926 \end_inset
25927 </cell>
25928 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25929 \begin_inset Text
25930
25931 \layout Standard
25932 sdcc/support/scripts
25933
25934 \end_inset
25935 </cell>
25936 </row>
25937 <row topline="true">
25938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25939 \begin_inset Text
25940
25941 \layout Standard
25942 mh2h.c
25943
25944 \end_inset
25945 </cell>
25946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25947 \begin_inset Text
25948
25949 \layout Standard
25950 header file conversion
25951
25952 \end_inset
25953 </cell>
25954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25955 \begin_inset Text
25956
25957 \layout Standard
25958 sdcc/support/scripts
25959
25960 \end_inset
25961 </cell>
25962 </row>
25963 <row topline="true">
25964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25965 \begin_inset Text
25966
25967 \layout Standard
25968 as-gbz80
25969
25970 \end_inset
25971 </cell>
25972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25973 \begin_inset Text
25974
25975 \layout Standard
25976 Assembler
25977
25978 \end_inset
25979 </cell>
25980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25981 \begin_inset Text
25982
25983 \layout Standard
25984
25985 \family roman
25986 \series medium
25987 \shape up
25988 \size normal
25989 \emph off
25990 \bar no
25991 \noun off
25992 \color none
25993 sdcc/bin
25994
25995 \end_inset
25996 </cell>
25997 </row>
25998 <row topline="true">
25999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26000 \begin_inset Text
26001
26002 \layout Standard
26003 as-z80
26004
26005 \end_inset
26006 </cell>
26007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26008 \begin_inset Text
26009
26010 \layout Standard
26011 Assembler
26012
26013 \end_inset
26014 </cell>
26015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26016 \begin_inset Text
26017
26018 \layout Standard
26019
26020 \family roman
26021 \series medium
26022 \shape up
26023 \size normal
26024 \emph off
26025 \bar no
26026 \noun off
26027 \color none
26028 sdcc/bin
26029
26030 \end_inset
26031 </cell>
26032 </row>
26033 <row topline="true">
26034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26035 \begin_inset Text
26036
26037 \layout Standard
26038 asx8051
26039
26040 \end_inset
26041 </cell>
26042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26043 \begin_inset Text
26044
26045 \layout Standard
26046 Assembler
26047
26048 \end_inset
26049 </cell>
26050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26051 \begin_inset Text
26052
26053 \layout Standard
26054
26055 \family roman
26056 \series medium
26057 \shape up
26058 \size normal
26059 \emph off
26060 \bar no
26061 \noun off
26062 \color none
26063 sdcc/bin
26064
26065 \end_inset
26066 </cell>
26067 </row>
26068 <row topline="true">
26069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26070 \begin_inset Text
26071
26072 \layout Standard
26073 SDCDB
26074
26075 \end_inset
26076 </cell>
26077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26078 \begin_inset Text
26079
26080 \layout Standard
26081 Simulator
26082
26083 \end_inset
26084 </cell>
26085 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26086 \begin_inset Text
26087
26088 \layout Standard
26089
26090 \family roman
26091 \series medium
26092 \shape up
26093 \size normal
26094 \emph off
26095 \bar no
26096 \noun off
26097 \color none
26098 sdcc/bin
26099
26100 \end_inset
26101 </cell>
26102 </row>
26103 <row topline="true">
26104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26105 \begin_inset Text
26106
26107 \layout Standard
26108 aslink
26109
26110 \end_inset
26111 </cell>
26112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26113 \begin_inset Text
26114
26115 \layout Standard
26116 Linker
26117
26118 \end_inset
26119 </cell>
26120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26121 \begin_inset Text
26122
26123 \layout Standard
26124
26125 \family roman
26126 \series medium
26127 \shape up
26128 \size normal
26129 \emph off
26130 \bar no
26131 \noun off
26132 \color none
26133 sdcc/bin
26134
26135 \end_inset
26136 </cell>
26137 </row>
26138 <row topline="true">
26139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26140 \begin_inset Text
26141
26142 \layout Standard
26143 link-z80
26144
26145 \end_inset
26146 </cell>
26147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26148 \begin_inset Text
26149
26150 \layout Standard
26151 Linker
26152
26153 \end_inset
26154 </cell>
26155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26156 \begin_inset Text
26157
26158 \layout Standard
26159
26160 \family roman
26161 \series medium
26162 \shape up
26163 \size normal
26164 \emph off
26165 \bar no
26166 \noun off
26167 \color none
26168 sdcc/bin
26169
26170 \end_inset
26171 </cell>
26172 </row>
26173 <row topline="true">
26174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26175 \begin_inset Text
26176
26177 \layout Standard
26178 link-gbz80
26179
26180 \end_inset
26181 </cell>
26182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26183 \begin_inset Text
26184
26185 \layout Standard
26186 Linker
26187
26188 \end_inset
26189 </cell>
26190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26191 \begin_inset Text
26192
26193 \layout Standard
26194
26195 \family roman
26196 \series medium
26197 \shape up
26198 \size normal
26199 \emph off
26200 \bar no
26201 \noun off
26202 \color none
26203 sdcc/bin
26204
26205 \end_inset
26206 </cell>
26207 </row>
26208 <row topline="true" bottomline="true">
26209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26210 \begin_inset Text
26211
26212 \layout Standard
26213 packihx
26214
26215 \end_inset
26216 </cell>
26217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26218 \begin_inset Text
26219
26220 \layout Standard
26221 Intel Hex packer 
26222 \begin_inset LatexCommand \index{packihx (tool)}
26223
26224 \end_inset
26225
26226
26227
26228 \end_inset
26229 </cell>
26230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26231 \begin_inset Text
26232
26233 \layout Standard
26234
26235 \family roman
26236 \series medium
26237 \shape up
26238 \size normal
26239 \emph off
26240 \bar no
26241 \noun off
26242 \color none
26243 sdcc/bin
26244
26245 \end_inset
26246 </cell>
26247 </row>
26248 </lyxtabular>
26249
26250 \end_inset
26251
26252
26253 \newline
26254
26255
26256 \layout Section
26257 Documentation
26258 \begin_inset LatexCommand \index{Documentation}
26259
26260 \end_inset
26261
26262  included in the distribution
26263
26264 \layout Standard
26265 \align left
26266 \begin_inset Tabular
26267 <lyxtabular version="3" rows="10" columns="2">
26268 <features>
26269 <column alignment="block" valignment="top" leftline="true" width="40col%">
26270 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
26271 <row topline="true" bottomline="true" endhead="true">
26272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26273 \begin_inset Text
26274
26275 \layout Standard
26276
26277 \series bold
26278 Subject / Title
26279
26280 \end_inset
26281 </cell>
26282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26283 \begin_inset Text
26284
26285 \layout Standard
26286
26287 \series bold
26288 Filename / Where to get
26289
26290 \end_inset
26291 </cell>
26292 </row>
26293 <row topline="true">
26294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26295 \begin_inset Text
26296
26297 \layout Standard
26298 SDCC Compiler User Guide
26299
26300 \end_inset
26301 </cell>
26302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26303 \begin_inset Text
26304
26305 \layout Standard
26306 You're reading it right now
26307 \emph on
26308  \SpecialChar ~
26309 \SpecialChar ~
26310 \SpecialChar ~
26311
26312 \hfill
26313 online at:
26314 \emph default
26315
26316 \newline
26317
26318 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
26319
26320 \end_inset
26321
26322
26323
26324 \end_inset
26325 </cell>
26326 </row>
26327 <row topline="true">
26328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26329 \begin_inset Text
26330
26331 \layout Standard
26332 Changelog of SDCC
26333
26334 \end_inset
26335 </cell>
26336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26337 \begin_inset Text
26338
26339 \layout Standard
26340 sdcc/Changelog
26341 \emph on
26342  \SpecialChar ~
26343 \SpecialChar ~
26344 \SpecialChar ~
26345
26346 \hfill
26347 online at:
26348 \emph default
26349
26350 \newline
26351
26352 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
26353
26354 \end_inset
26355
26356
26357
26358 \end_inset
26359 </cell>
26360 </row>
26361 <row topline="true">
26362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26363 \begin_inset Text
26364
26365 \layout Standard
26366 ASXXXX
26367 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
26368
26369 \end_inset
26370
26371
26372 \begin_inset LatexCommand \index{Assembler documentation}
26373
26374 \end_inset
26375
26376  Assemblers and
26377 \newline
26378 ASLINK
26379 \begin_inset LatexCommand \index{aslink}
26380
26381 \end_inset
26382
26383
26384 \begin_inset LatexCommand \index{Linker documentation}
26385
26386 \end_inset
26387
26388  Relocating Linker
26389
26390 \end_inset
26391 </cell>
26392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26393 \begin_inset Text
26394
26395 \layout Standard
26396 sdcc/as/doc/asxhtm.html 
26397 \emph on
26398 \SpecialChar ~
26399 \SpecialChar ~
26400 \SpecialChar ~
26401
26402 \hfill
26403 online at:
26404 \emph default
26405
26406 \newline
26407
26408 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
26409
26410 \end_inset
26411
26412
26413
26414 \end_inset
26415 </cell>
26416 </row>
26417 <row topline="true">
26418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26419 \begin_inset Text
26420
26421 \layout Standard
26422 SDCC regression test
26423 \begin_inset LatexCommand \index{Regression test}
26424
26425 \end_inset
26426
26427
26428
26429 \end_inset
26430 </cell>
26431 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26432 \begin_inset Text
26433
26434 \layout Standard
26435 sdcc/doc/test_suite_spec.pdf 
26436 \emph on
26437 \SpecialChar ~
26438 \SpecialChar ~
26439 \SpecialChar ~
26440
26441 \hfill
26442 online at:
26443 \emph default
26444
26445 \newline
26446
26447 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
26448
26449 \end_inset
26450
26451
26452
26453 \end_inset
26454 </cell>
26455 </row>
26456 <row topline="true">
26457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26458 \begin_inset Text
26459
26460 \layout Standard
26461 Various notes
26462
26463 \end_inset
26464 </cell>
26465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26466 \begin_inset Text
26467
26468 \layout Standard
26469 sdcc/doc/* 
26470 \emph on
26471 \SpecialChar ~
26472 \SpecialChar ~
26473 \SpecialChar ~
26474
26475 \hfill
26476 online at:
26477 \emph default
26478
26479 \newline
26480
26481 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
26482
26483 \end_inset
26484
26485
26486
26487 \end_inset
26488 </cell>
26489 </row>
26490 <row topline="true">
26491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26492 \begin_inset Text
26493
26494 \layout Standard
26495 Notes on debugging with SDCDB
26496 \begin_inset LatexCommand \index{SDCDB (debugger)}
26497
26498 \end_inset
26499
26500
26501
26502 \end_inset
26503 </cell>
26504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26505 \begin_inset Text
26506
26507 \layout Standard
26508 sdcc/debugger/README 
26509 \emph on
26510 \SpecialChar ~
26511 \SpecialChar ~
26512 \SpecialChar ~
26513
26514 \hfill
26515 online at
26516 \emph default
26517 :
26518 \newline
26519
26520 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
26521
26522 \end_inset
26523
26524
26525
26526 \end_inset
26527 </cell>
26528 </row>
26529 <row topline="true">
26530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26531 \begin_inset Text
26532
26533 \layout Standard
26534 uCsim
26535 \begin_inset LatexCommand \index{uCsim}
26536
26537 \end_inset
26538
26539  Software simulator for microcontrollers
26540
26541 \end_inset
26542 </cell>
26543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26544 \begin_inset Text
26545
26546 \layout Standard
26547
26548 \family roman
26549 \series medium
26550 \shape up
26551 \size normal
26552 \emph off
26553 \bar no
26554 \noun off
26555 \color none
26556 sdcc/sim/ucsim/doc
26557 \family default
26558 \series default
26559 \shape default
26560 \size default
26561 \emph default
26562 \bar default
26563 \noun default
26564 /index.html 
26565 \emph on
26566 \SpecialChar ~
26567 \SpecialChar ~
26568 \SpecialChar ~
26569
26570 \hfill
26571 online at:
26572 \emph default
26573
26574 \newline
26575
26576 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
26577
26578 \end_inset
26579
26580
26581
26582 \end_inset
26583 </cell>
26584 </row>
26585 <row topline="true">
26586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26587 \begin_inset Text
26588
26589 \layout Standard
26590 Temporary notes on the pic16
26591 \begin_inset LatexCommand \index{PIC16}
26592
26593 \end_inset
26594
26595  port
26596
26597 \end_inset
26598 </cell>
26599 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26600 \begin_inset Text
26601
26602 \layout Standard
26603 sdcc/src/pic16/NOTES 
26604 \emph on
26605 \SpecialChar ~
26606 \SpecialChar ~
26607 \SpecialChar ~
26608
26609 \hfill
26610 online at:
26611 \newline
26612
26613 \emph default
26614
26615 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
26616
26617 \end_inset
26618
26619
26620
26621 \end_inset
26622 </cell>
26623 </row>
26624 <row topline="true" bottomline="true">
26625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26626 \begin_inset Text
26627
26628 \layout Standard
26629 SDCC internal documentation (debugging file format)
26630
26631 \end_inset
26632 </cell>
26633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26634 \begin_inset Text
26635
26636 \layout Standard
26637 sdcc/doc/
26638 \family roman
26639 \series medium
26640 \shape up
26641 \size normal
26642 \emph off
26643 \bar no
26644 \noun off
26645 \color none
26646 cdbfileformat.pd
26647 \family default
26648 \series default
26649 \shape default
26650 \size default
26651 \emph default
26652 \bar default
26653 \noun default
26654 f
26655 \emph on
26656  \SpecialChar ~
26657 \SpecialChar ~
26658 \SpecialChar ~
26659
26660 \hfill
26661 online at:
26662 \emph default
26663
26664 \newline
26665
26666 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
26667
26668 \end_inset
26669
26670
26671
26672 \end_inset
26673 </cell>
26674 </row>
26675 </lyxtabular>
26676
26677 \end_inset
26678
26679
26680 \newline
26681
26682
26683 \layout Section
26684 Related open source tools
26685 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
26686
26687 \end_inset
26688
26689
26690 \begin_inset LatexCommand \index{Related tools}
26691
26692 \end_inset
26693
26694
26695
26696 \layout Standard
26697 \align left
26698 \begin_inset Tabular
26699 <lyxtabular version="3" rows="14" columns="3">
26700 <features>
26701 <column alignment="left" valignment="top" leftline="true" width="0pt">
26702 <column alignment="block" valignment="top" leftline="true" width="30line%">
26703 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
26704 <row topline="true" bottomline="true">
26705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26706 \begin_inset Text
26707
26708 \layout Standard
26709
26710 \series bold
26711 Name
26712
26713 \end_inset
26714 </cell>
26715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26716 \begin_inset Text
26717
26718 \layout Standard
26719
26720 \series bold
26721 Purpose
26722
26723 \end_inset
26724 </cell>
26725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26726 \begin_inset Text
26727
26728 \layout Standard
26729
26730 \series bold
26731 Where to get
26732
26733 \end_inset
26734 </cell>
26735 </row>
26736 <row topline="true">
26737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26738 \begin_inset Text
26739
26740 \layout Standard
26741 gpsim
26742 \begin_inset LatexCommand \index{gpsim (pic simulator)}
26743
26744 \end_inset
26745
26746
26747
26748 \end_inset
26749 </cell>
26750 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26751 \begin_inset Text
26752
26753 \layout Standard
26754 PIC simulator
26755
26756 \end_inset
26757 </cell>
26758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26759 \begin_inset Text
26760
26761 \layout Standard
26762 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
26763
26764 \end_inset
26765
26766
26767
26768 \end_inset
26769 </cell>
26770 </row>
26771 <row topline="true">
26772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26773 \begin_inset Text
26774
26775 \layout Standard
26776 gputils
26777 \begin_inset LatexCommand \index{gputils (pic tools)}
26778
26779 \end_inset
26780
26781
26782
26783 \end_inset
26784 </cell>
26785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26786 \begin_inset Text
26787
26788 \layout Standard
26789 GNU PIC utilities
26790
26791 \end_inset
26792 </cell>
26793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26794 \begin_inset Text
26795
26796 \layout Standard
26797 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
26798
26799 \end_inset
26800
26801
26802
26803 \end_inset
26804 </cell>
26805 </row>
26806 <row topline="true">
26807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26808 \begin_inset Text
26809
26810 \layout Standard
26811 flP5
26812
26813 \end_inset
26814 </cell>
26815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26816 \begin_inset Text
26817
26818 \layout Standard
26819 PIC programmer
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 \layout Standard
26827 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
26828
26829 \end_inset
26830
26831
26832
26833 \end_inset
26834 </cell>
26835 </row>
26836 <row topline="true">
26837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26838 \begin_inset Text
26839
26840 \layout Standard
26841 ec2drv/newcdb
26842
26843 \end_inset
26844 </cell>
26845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26846 \begin_inset Text
26847
26848 \layout Standard
26849 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
26850  (Unix only)
26851
26852 \end_inset
26853 </cell>
26854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26855 \begin_inset Text
26856
26857 \layout Standard
26858 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
26859
26860 \end_inset
26861
26862
26863
26864 \end_inset
26865 </cell>
26866 </row>
26867 <row topline="true">
26868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26869 \begin_inset Text
26870
26871 \layout Standard
26872 indent
26873 \begin_inset LatexCommand \index{indent (source formatting tool)}
26874
26875 \end_inset
26876
26877
26878
26879 \end_inset
26880 </cell>
26881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26882 \begin_inset Text
26883
26884 \layout Standard
26885 Formats C source - Master of the white spaces
26886
26887 \end_inset
26888 </cell>
26889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26890 \begin_inset Text
26891
26892 \layout Standard
26893 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
26894
26895 \end_inset
26896
26897
26898
26899 \end_inset
26900 </cell>
26901 </row>
26902 <row topline="true">
26903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26904 \begin_inset Text
26905
26906 \layout Standard
26907 srecord
26908 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
26909
26910 \end_inset
26911
26912
26913
26914 \end_inset
26915 </cell>
26916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26917 \begin_inset Text
26918
26919 \layout Standard
26920 Object file conversion, checksumming, ...
26921
26922 \end_inset
26923 </cell>
26924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26925 \begin_inset Text
26926
26927 \layout Standard
26928 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
26929
26930 \end_inset
26931
26932
26933
26934 \end_inset
26935 </cell>
26936 </row>
26937 <row topline="true">
26938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26939 \begin_inset Text
26940
26941 \layout Standard
26942 objdump
26943 \begin_inset LatexCommand \index{objdump (tool)}
26944
26945 \end_inset
26946
26947
26948
26949 \end_inset
26950 </cell>
26951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26952 \begin_inset Text
26953
26954 \layout Standard
26955 Object file conversion, ...
26956
26957 \end_inset
26958 </cell>
26959 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26960 \begin_inset Text
26961
26962 \layout Standard
26963 Part of binutils (should be there anyway)
26964
26965 \end_inset
26966 </cell>
26967 </row>
26968 <row topline="true">
26969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26970 \begin_inset Text
26971
26972 \layout Standard
26973 cmon51
26974
26975 \end_inset
26976 </cell>
26977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26978 \begin_inset Text
26979
26980 \layout Standard
26981 8051 monitor (hex up-/download, single step, disassemble)
26982
26983 \end_inset
26984 </cell>
26985 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26986 \begin_inset Text
26987
26988 \layout Standard
26989 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
26990
26991 \end_inset
26992
26993
26994
26995 \end_inset
26996 </cell>
26997 </row>
26998 <row topline="true">
26999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27000 \begin_inset Text
27001
27002 \layout Standard
27003 doxygen
27004 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
27005
27006 \end_inset
27007
27008
27009
27010 \end_inset
27011 </cell>
27012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27013 \begin_inset Text
27014
27015 \layout Standard
27016 Source code documentation system
27017
27018 \end_inset
27019 </cell>
27020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27021 \begin_inset Text
27022
27023 \layout Standard
27024 \begin_inset LatexCommand \url{http://www.doxygen.org}
27025
27026 \end_inset
27027
27028
27029
27030 \end_inset
27031 </cell>
27032 </row>
27033 <row topline="true">
27034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27035 \begin_inset Text
27036
27037 \layout Standard
27038 kdevelop
27039
27040 \end_inset
27041 </cell>
27042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27043 \begin_inset Text
27044
27045 \layout Standard
27046 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
27047
27048 \end_inset
27049 </cell>
27050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27051 \begin_inset Text
27052
27053 \layout Standard
27054 \begin_inset LatexCommand \url{http://www.kdevelop.org}
27055
27056 \end_inset
27057
27058
27059
27060 \end_inset
27061 </cell>
27062 </row>
27063 <row topline="true">
27064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27065 \begin_inset Text
27066
27067 \layout Standard
27068 paulmon
27069
27070 \end_inset
27071 </cell>
27072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27073 \begin_inset Text
27074
27075 \layout Standard
27076 8051 monitor (hex up-/download, single step, disassemble)
27077
27078 \end_inset
27079 </cell>
27080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27081 \begin_inset Text
27082
27083 \layout Standard
27084 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
27085
27086 \end_inset
27087
27088
27089
27090 \end_inset
27091 </cell>
27092 </row>
27093 <row topline="true">
27094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27095 \begin_inset Text
27096
27097 \layout Standard
27098 splint
27099 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27100
27101 \end_inset
27102
27103
27104
27105 \end_inset
27106 </cell>
27107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27108 \begin_inset Text
27109
27110 \layout Standard
27111 Statically checks c sources (see 
27112 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27113
27114 \end_inset
27115
27116 )
27117
27118 \end_inset
27119 </cell>
27120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27121 \begin_inset Text
27122
27123 \layout Standard
27124 \begin_inset LatexCommand \url{http://www.splint.org}
27125
27126 \end_inset
27127
27128
27129
27130 \end_inset
27131 </cell>
27132 </row>
27133 <row topline="true" bottomline="true">
27134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27135 \begin_inset Text
27136
27137 \layout Standard
27138 ddd
27139 \begin_inset LatexCommand \index{DDD (debugger)}
27140
27141 \end_inset
27142
27143
27144
27145 \end_inset
27146 </cell>
27147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27148 \begin_inset Text
27149
27150 \layout Standard
27151 Debugger, serves nicely as GUI to SDCDB
27152 \begin_inset LatexCommand \index{SDCDB (debugger)}
27153
27154 \end_inset
27155
27156  (Unix only)
27157
27158 \end_inset
27159 </cell>
27160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27161 \begin_inset Text
27162
27163 \layout Standard
27164 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
27165
27166 \end_inset
27167
27168
27169
27170 \end_inset
27171 </cell>
27172 </row>
27173 </lyxtabular>
27174
27175 \end_inset
27176
27177
27178 \newline
27179
27180
27181 \layout Section
27182 Related documentation / recommended reading
27183
27184 \layout Standard
27185 \align left
27186 \begin_inset Tabular
27187 <lyxtabular version="3" rows="7" columns="3">
27188 <features>
27189 <column alignment="left" valignment="top" leftline="true" width="0pt">
27190 <column alignment="left" valignment="top" leftline="true" width="0">
27191 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
27192 <row topline="true" bottomline="true">
27193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27194 \begin_inset Text
27195
27196 \layout Standard
27197
27198 \series bold
27199 Name
27200
27201 \end_inset
27202 </cell>
27203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27204 \begin_inset Text
27205
27206 \layout Standard
27207
27208 \series bold
27209 Subject / Title
27210
27211 \end_inset
27212 </cell>
27213 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27214 \begin_inset Text
27215
27216 \layout Standard
27217
27218 \series bold
27219 Where to get
27220
27221 \end_inset
27222 </cell>
27223 </row>
27224 <row topline="true">
27225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27226 \begin_inset Text
27227
27228 \layout Standard
27229
27230 \family roman
27231 \series medium
27232 \shape up
27233 \size normal
27234 \emph off
27235 \bar no
27236 \noun off
27237 \color none
27238 c-refcard.pdf
27239
27240 \end_inset
27241 </cell>
27242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27243 \begin_inset Text
27244
27245 \layout Standard
27246 C Reference Card
27247 \begin_inset LatexCommand \index{C Reference card}
27248
27249 \end_inset
27250
27251 , 2 pages
27252
27253 \end_inset
27254 </cell>
27255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27256 \begin_inset Text
27257
27258 \layout Standard
27259 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
27260
27261 \end_inset
27262
27263
27264
27265 \end_inset
27266 </cell>
27267 </row>
27268 <row topline="true">
27269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27270 \begin_inset Text
27271
27272 \layout Standard
27273 c-faq
27274
27275 \end_inset
27276 </cell>
27277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27278 \begin_inset Text
27279
27280 \layout Standard
27281 C-FAQ
27282 \begin_inset LatexCommand \index{C FAQ}
27283
27284 \end_inset
27285
27286
27287
27288 \end_inset
27289 </cell>
27290 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27291 \begin_inset Text
27292
27293 \layout Standard
27294 \begin_inset LatexCommand \url{http://www.c-faq.com}
27295
27296 \end_inset
27297
27298
27299
27300 \end_inset
27301 </cell>
27302 </row>
27303 <row topline="true">
27304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27305 \begin_inset Text
27306
27307 \layout Standard
27308 ISO/IEC 9899:TC2
27309
27310 \end_inset
27311 </cell>
27312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27313 \begin_inset Text
27314
27315 \layout Standard
27316 \begin_inset Quotes sld
27317 \end_inset
27318
27319 C-Standard
27320 \begin_inset Quotes srd
27321 \end_inset
27322
27323
27324
27325 \end_inset
27326 </cell>
27327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27328 \begin_inset Text
27329
27330 \layout Standard
27331
27332 \size footnotesize
27333 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
27334
27335 \end_inset
27336
27337
27338
27339 \end_inset
27340 </cell>
27341 </row>
27342 <row topline="true">
27343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27344 \begin_inset Text
27345
27346 \layout Standard
27347 ISO/IEC DTR 18037
27348
27349 \end_inset
27350 </cell>
27351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27352 \begin_inset Text
27353
27354 \layout Standard
27355 \begin_inset Quotes sld
27356 \end_inset
27357
27358 Extensions for Embedded C
27359 \begin_inset Quotes srd
27360 \end_inset
27361
27362
27363
27364 \end_inset
27365 </cell>
27366 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27367 \begin_inset Text
27368
27369 \layout Standard
27370
27371 \size footnotesize
27372 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
27373
27374 \end_inset
27375
27376
27377
27378 \end_inset
27379 </cell>
27380 </row>
27381 <row topline="true">
27382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27383 \begin_inset Text
27384
27385 \layout Standard
27386
27387
27388 \end_inset
27389 </cell>
27390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27391 \begin_inset Text
27392
27393 \layout Standard
27394 Latest datasheet of target CPU
27395
27396 \end_inset
27397 </cell>
27398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27399 \begin_inset Text
27400
27401 \layout Standard
27402 vendor
27403
27404 \end_inset
27405 </cell>
27406 </row>
27407 <row topline="true" bottomline="true">
27408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27409 \begin_inset Text
27410
27411 \layout Standard
27412
27413
27414 \end_inset
27415 </cell>
27416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27417 \begin_inset Text
27418
27419 \layout Standard
27420 Revision history of datasheet
27421
27422 \end_inset
27423 </cell>
27424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27425 \begin_inset Text
27426
27427 \layout Standard
27428 vendor
27429
27430 \end_inset
27431 </cell>
27432 </row>
27433 </lyxtabular>
27434
27435 \end_inset
27436
27437
27438 \newline
27439
27440
27441 \layout Section
27442 Application notes specifically for SDCC
27443
27444 \layout Standard
27445 SDCC makes no claims about the completeness of this list and about up-to-datenes
27446 s or correctness of the application notes
27447 \begin_inset LatexCommand \index{Application notes}
27448
27449 \end_inset
27450
27451 .
27452
27453 \layout Standard
27454 \align left
27455
27456 \size footnotesize
27457 \begin_inset Tabular
27458 <lyxtabular version="3" rows="7" columns="3">
27459 <features>
27460 <column alignment="block" valignment="top" leftline="true" width="17col%">
27461 <column alignment="block" valignment="top" leftline="true" width="27col%">
27462 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
27463 <row topline="true" bottomline="true">
27464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27465 \begin_inset Text
27466
27467 \layout Standard
27468
27469 \series bold
27470 \size footnotesize
27471 Vendor
27472
27473 \end_inset
27474 </cell>
27475 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
27476 \begin_inset Text
27477
27478 \layout Standard
27479
27480 \series bold
27481 \size footnotesize
27482 Subject / Title
27483
27484 \end_inset
27485 </cell>
27486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27487 \begin_inset Text
27488
27489 \layout Standard
27490
27491 \series bold
27492 \size footnotesize
27493 Where to get
27494
27495 \end_inset
27496 </cell>
27497 </row>
27498 <row topline="true">
27499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27500 \begin_inset Text
27501
27502 \layout Standard
27503
27504 \size footnotesize
27505 Maxim / Dallas
27506
27507 \end_inset
27508 </cell>
27509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27510 \begin_inset Text
27511
27512 \layout Standard
27513
27514 \size footnotesize
27515 Using the SDCC Compiler for the DS80C400
27516 \begin_inset LatexCommand \index{DS80C400}
27517
27518 \end_inset
27519
27520
27521
27522 \end_inset
27523 </cell>
27524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27525 \begin_inset Text
27526
27527 \layout Standard
27528
27529 \size footnotesize
27530 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
27531
27532 \end_inset
27533
27534
27535
27536 \end_inset
27537 </cell>
27538 </row>
27539 <row topline="true">
27540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27541 \begin_inset Text
27542
27543 \layout Standard
27544
27545 \size footnotesize
27546 Maxim / Dallas
27547
27548 \end_inset
27549 </cell>
27550 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
27551 \begin_inset Text
27552
27553 \layout Standard
27554
27555 \size footnotesize
27556 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
27557 \begin_inset LatexCommand \index{DS89C4x0}
27558
27559 \end_inset
27560
27561  Family of Microcontrollers
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 \layout Standard
27569
27570 \size footnotesize
27571 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
27572
27573 \end_inset
27574
27575
27576
27577 \end_inset
27578 </cell>
27579 </row>
27580 <row topline="true">
27581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27582 \begin_inset Text
27583
27584 \layout Standard
27585
27586 \size footnotesize
27587 Silicon Laboratories / Cygnal
27588
27589 \end_inset
27590 </cell>
27591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27592 \begin_inset Text
27593
27594 \layout Standard
27595
27596 \size footnotesize
27597 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
27598 \begin_inset LatexCommand \index{IDE}
27599
27600 \end_inset
27601
27602
27603
27604 \end_inset
27605 </cell>
27606 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27607 \begin_inset Text
27608
27609 \layout Standard
27610
27611 \size footnotesize
27612 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
27613
27614 \end_inset
27615
27616
27617
27618 \end_inset
27619 </cell>
27620 </row>
27621 <row topline="true">
27622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27623 \begin_inset Text
27624
27625 \layout Standard
27626
27627 \size footnotesize
27628 Ramtron / Goal Semiconductor
27629
27630 \end_inset
27631 </cell>
27632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27633 \begin_inset Text
27634
27635 \layout Standard
27636
27637 \size footnotesize
27638 Interfacing SDCC to Syn and Textpad
27639
27640 \end_inset
27641 </cell>
27642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27643 \begin_inset Text
27644
27645 \layout Standard
27646
27647 \size footnotesize
27648 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
27649
27650 \end_inset
27651
27652
27653
27654 \end_inset
27655 </cell>
27656 </row>
27657 <row topline="true">
27658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27659 \begin_inset Text
27660
27661 \layout Standard
27662
27663 \size footnotesize
27664 Ramtron / Goal Semiconductor
27665
27666 \end_inset
27667 </cell>
27668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27669 \begin_inset Text
27670
27671 \layout Standard
27672
27673 \size footnotesize
27674 Installing and Configuring SDCC and Crimson Editor 
27675
27676 \end_inset
27677 </cell>
27678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27679 \begin_inset Text
27680
27681 \layout Standard
27682
27683 \size footnotesize
27684 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
27685
27686 \end_inset
27687
27688
27689
27690 \end_inset
27691 </cell>
27692 </row>
27693 <row topline="true" bottomline="true">
27694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27695 \begin_inset Text
27696
27697 \layout Standard
27698
27699 \size footnotesize
27700 Texas Instruments
27701
27702 \end_inset
27703 </cell>
27704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27705 \begin_inset Text
27706
27707 \layout Standard
27708
27709 \size footnotesize
27710 MSC12xx Programming with SDCC
27711
27712 \end_inset
27713 </cell>
27714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27715 \begin_inset Text
27716
27717 \layout Standard
27718
27719 \size footnotesize
27720 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
27721
27722 \end_inset
27723
27724
27725
27726 \end_inset
27727 </cell>
27728 </row>
27729 </lyxtabular>
27730
27731 \end_inset
27732
27733
27734
27735 \layout Section
27736 Some Questions
27737
27738 \layout Standard
27739 Some questions answered, some pointers given - it might be time to in turn
27740  ask 
27741 \emph on
27742 you
27743 \emph default
27744  some questions: 
27745
27746 \layout Itemize
27747 can you solve your project with the selected microcontroller? Would you
27748  find out early or rather late that your target is too small/slow/whatever?
27749  Can you switch to a slightly better device if it doesn't fit?
27750
27751 \layout Itemize
27752 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
27753  and/or another programming language be more adequate? Would an operating
27754  system on the target device help?
27755
27756 \layout Itemize
27757 if you solved the problem, will the marketing department be happy?
27758
27759 \layout Itemize
27760 if the marketing department is happy, will customers be happy?
27761
27762 \layout Itemize
27763 if you're the project manager, marketing department and maybe even the customer
27764  in one person, have you tried to see the project from the outside?
27765
27766 \layout Itemize
27767 is the project done if you think it is done? Or is just that other interface/pro
27768 tocol/feature/configuration/option missing? How about website, manual(s),
27769  internationali(z|s)ation, packaging, labels, 2nd source for components,
27770  electromagnetic compatability/interference, documentation for production,
27771  production test software, update mechanism, patent issues?
27772
27773 \layout Itemize
27774 is your project adequately positioned in that magic triangle: fame, fortune,
27775  fun?
27776
27777 \layout Standard
27778 Maybe not all answers to these questions are known and some answers may
27779  even be 
27780 \emph on
27781 no
27782 \emph default
27783 , nevertheless knowing these questions may help you to avoid burnout
27784 \begin_inset Foot
27785 collapsed false
27786
27787 \layout Standard
27788 burnout is bad for electronic devices, programmers and motorcycle tyres
27789
27790 \end_inset
27791
27792 .
27793  Chances are you didn't want to hear some of them...
27794
27795 \layout Chapter
27796 Support
27797 \begin_inset LatexCommand \index{Support}
27798
27799 \end_inset
27800
27801
27802
27803 \layout Standard
27804 SDCC has grown to be a large project.
27805  The compiler alone (without the preprocessor, assembler and linker) is
27806  well over 150,000 lines of code (blank stripped).
27807  The open source nature of this project is a key to its continued growth
27808  and support.
27809  You gain the benefit and support of many active software developers and
27810  end users.
27811  Is SDCC perfect? No, that's why we need your help.
27812  The developers take pride in fixing reported bugs.
27813  You can help by reporting the bugs and helping other SDCC users.
27814  There are lots of ways to contribute, and we encourage you to take part
27815  in making SDCC a great software package.
27816  
27817
27818 \layout Standard
27819 The SDCC project is hosted on the SDCC sourceforge site at 
27820 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
27821
27822 \end_inset
27823
27824 .
27825  You'll find the complete set of mailing lists
27826 \begin_inset LatexCommand \index{Mailing list(s)}
27827
27828 \end_inset
27829
27830 , forums, bug reporting system, patch submission
27831 \begin_inset LatexCommand \index{Patch submission}
27832
27833 \end_inset
27834
27835  system, download
27836 \begin_inset LatexCommand \index{download}
27837
27838 \end_inset
27839
27840  area and Subversion code repository
27841 \begin_inset LatexCommand \index{Subversion code repository}
27842
27843 \end_inset
27844
27845  there.
27846
27847 \layout Section
27848 Reporting Bugs
27849 \begin_inset LatexCommand \index{Bug reporting}
27850
27851 \end_inset
27852
27853
27854 \begin_inset LatexCommand \index{Reporting bugs}
27855
27856 \end_inset
27857
27858
27859
27860 \layout Standard
27861 The recommended way of reporting bugs is using the infrastructure of the
27862  sourceforge site.
27863  You can follow the status of bug reports there and have an overview about
27864  the known bugs.
27865
27866 \layout Standard
27867 Bug reports are automatically forwarded to the developer mailing list and
27868  will be fixed ASAP.
27869  When reporting a bug, it is very useful to include a small test program
27870  (the smaller the better) which reproduces the problem.
27871  If you can isolate the problem by looking at the generated assembly code,
27872  this can be very helpful.
27873  Compiling your program with the -
27874 \begin_inset ERT
27875 status Collapsed
27876
27877 \layout Standard
27878
27879
27880 \backslash
27881 /
27882
27883 \end_inset
27884
27885 -dumpall
27886 \begin_inset LatexCommand \index{-\/-dumpall}
27887
27888 \end_inset
27889
27890  option can sometimes be useful in locating optimization problems.
27891  When reporting a bug please make sure you:
27892
27893 \layout Enumerate
27894 Attach the code you are compiling with SDCC.
27895  
27896
27897 \layout Enumerate
27898 Specify the exact command you use to run SDCC, or attach your Makefile.
27899  
27900
27901 \layout Enumerate
27902 Specify the SDCC version (type "
27903 \family sans
27904 \series bold
27905 sdcc -v
27906 \family default
27907 \series default
27908 "), your platform, and operating system.
27909  
27910
27911 \layout Enumerate
27912 Provide an exact copy of any error message or incorrect output.
27913  
27914
27915 \layout Enumerate
27916 Put something meaningful in the subject of your message.
27917
27918 \layout Standard
27919 Please attempt to include these 5 important parts, as applicable, in all
27920  requests for support or when reporting any problems or bugs with SDCC.
27921  Though this will make your message lengthy, it will greatly improve your
27922  chance that SDCC users and developers will be able to help you.
27923  Some SDCC developers are frustrated by bug reports without code provided
27924  that they can use to reproduce and ultimately fix the problem, so please
27925  be sure to provide sample code if you are reporting a bug! 
27926
27927 \layout Standard
27928 Please have a short check that you are using a recent version of SDCC and
27929  the bug is not yet known.
27930  This is the link for reporting bugs: 
27931 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
27932
27933 \end_inset
27934
27935 .
27936  With SDCC on average having more than 200 downloads
27937 \begin_inset LatexCommand \index{download}
27938
27939 \end_inset
27940
27941  on sourceforge per day
27942 \begin_inset Foot
27943 collapsed false
27944
27945 \layout Standard
27946 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
27947  between 2002 and 2005.
27948  This does not include other methods of distribution.
27949
27950 \end_inset
27951
27952  there must be some users.
27953  So it's not exactly easy to find a new bug.
27954  If you find one we need it: 
27955 \emph on
27956 reporting bugs is good
27957 \emph default
27958 .
27959
27960 \layout Section
27961 Requesting Features
27962 \begin_inset LatexCommand \label{sub:Requesting-Features}
27963
27964 \end_inset
27965
27966
27967 \begin_inset LatexCommand \index{Feature request}
27968
27969 \end_inset
27970
27971
27972 \begin_inset LatexCommand \index{Requesting features}
27973
27974 \end_inset
27975
27976
27977
27978 \layout Standard
27979 Like bug reports feature requests are forwarded to the developer mailing
27980  list.
27981  This is the link for requesting features: 
27982 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
27983
27984 \end_inset
27985
27986 .
27987
27988 \layout Section
27989 Submitting patches
27990
27991 \layout Standard
27992 Like bug reports contributed patches are forwarded to the developer mailing
27993  list.
27994  This is the link for submitting patches
27995 \begin_inset LatexCommand \index{Patch submission}
27996
27997 \end_inset
27998
27999
28000 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
28001
28002 \end_inset
28003
28004 .
28005
28006 \layout Standard
28007 You need to specify some parameters to the 
28008 \family typewriter
28009 diff
28010 \family default
28011  command for the patches to be useful.
28012  If you modified more than one file a patch created f.e.
28013  with 
28014 \family sans
28015 \series bold
28016
28017 \begin_inset Quotes sld
28018 \end_inset
28019
28020 diff -Naur unmodified_directory modified_directory >my_changes.patch
28021 \begin_inset Quotes srd
28022 \end_inset
28023
28024
28025 \family default
28026 \series default
28027  will be fine, otherwise 
28028 \family sans
28029 \series bold
28030
28031 \begin_inset Quotes sld
28032 \end_inset
28033
28034 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
28035 \begin_inset Quotes srd
28036 \end_inset
28037
28038
28039 \series default
28040  
28041 \family default
28042 will do.
28043
28044 \layout Section
28045 Getting Help
28046
28047 \layout Standard
28048 These links should take you directly to the 
28049 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
28050
28051 \end_inset
28052
28053
28054 \begin_inset Foot
28055 collapsed false
28056
28057 \layout Standard
28058 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
28059  automated messages (mid 2003)
28060
28061 \end_inset
28062
28063  and the 
28064 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
28065
28066 \end_inset
28067
28068 , lists
28069 \begin_inset LatexCommand \index{Mailing list(s)}
28070
28071 \end_inset
28072
28073  and forums are archived and searchable so if you are lucky someone already
28074  had a similar problem.
28075  While mails to the lists themselves are delivered promptly their web front
28076  end on sourceforge sometimes shows a severe time lag (up to several weeks),
28077  if you're seriously using SDCC please consider subscribing to the lists.
28078
28079 \layout Section
28080 ChangeLog
28081
28082 \layout Standard
28083 You can follow the status of the Subversion version
28084 \begin_inset LatexCommand \index{version}
28085
28086 \end_inset
28087
28088  of SDCC by watching the Changelog
28089 \begin_inset LatexCommand \index{Changelog}
28090
28091 \end_inset
28092
28093  in the Subversion repository
28094 \size footnotesize
28095  
28096 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
28097
28098 \end_inset
28099
28100 .
28101
28102 \layout Section
28103 Subversion Source Code Repository
28104
28105 \layout Standard
28106 The output of 
28107 \family sans
28108 \series bold
28109 sdcc --version
28110 \family default
28111 \series default
28112  or the filenames of the snapshot versions of SDCC include date and its
28113  Subversion
28114 \begin_inset LatexCommand \index{Subversion code repository}
28115
28116 \end_inset
28117
28118  number.
28119  Subversion allows to download the source of recent or previous versions
28120  
28121 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
28122
28123 \end_inset
28124
28125  (by number or by date).
28126  An on-line source code browser and detailled instructions are also available
28127  there.
28128  SDCC versions starting from 1999 up to now are available (currently the
28129  versions prior to the conversion from cvs
28130 \begin_inset LatexCommand \index{cvs|see{Subversion}}
28131
28132 \end_inset
28133
28134  to Subversion (April 2006) are either by accessible by Subversion or by
28135  cvs).
28136
28137 \layout Section
28138 Release policy
28139 \begin_inset LatexCommand \index{Release policy}
28140
28141 \end_inset
28142
28143
28144
28145 \layout Standard
28146 Historically there often were long delays between official releases and
28147  the sourceforge download area tends to get not updated at all.
28148  Excuses in the past might have referred to problems with live range analysis,
28149  but as this was fixed a while ago, the current problem is that another
28150  excuse has to be found.
28151  Kidding aside, we have to get better there! On the other hand there are
28152  daily snapshots available at 
28153 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
28154
28155 \end_inset
28156
28157 , and you can always build the very last version (hopefully with many bugs
28158  fixed, and features added) from the source code available at 
28159 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
28160
28161 \end_inset
28162
28163 .
28164  A release wiki
28165 \begin_inset LatexCommand \index{wiki}
28166
28167 \end_inset
28168
28169
28170 \begin_inset LatexCommand \index{Release wiki}
28171
28172 \end_inset
28173
28174  at 
28175 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
28176
28177 \end_inset
28178
28179  also holds some information about past and future releases.
28180
28181 \layout Section
28182 Examples
28183 \begin_inset LatexCommand \index{Examples}
28184
28185 \end_inset
28186
28187
28188
28189 \layout Standard
28190 You'll find some small examples in the directory 
28191 \emph on
28192 sdcc/device/examples/.
28193  
28194 \emph default
28195 More examples and libraries are available at
28196 \emph on
28197  The SDCC Open Knowledge Resource 
28198 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
28199
28200 \end_inset
28201
28202  
28203 \emph default
28204 web site or at 
28205 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
28206
28207 \end_inset
28208
28209 .
28210
28211 \layout Standard
28212 \begin_inset Note
28213 collapsed true
28214
28215 \layout Standard
28216 I did insert a reference to Paul's web site here although it seems rather
28217  dedicated to a specific 8032 board (I think it's okay because it f.e.
28218  shows LCD/Harddisc interface and has a free 8051 monitor.
28219  Independent 8032 board vendors face hard competition of heavily subsidized
28220  development boards anyway).
28221
28222 \layout Standard
28223 Maybe we should include some links to real world applications.
28224  Preferably pointer to pointers (one for each architecture) so this stays
28225  manageable here?
28226
28227 \end_inset
28228
28229
28230
28231 \layout Section
28232 Quality control
28233 \begin_inset LatexCommand \label{sec:Quality-control}
28234
28235 \end_inset
28236
28237
28238 \begin_inset LatexCommand \index{Quality control}
28239
28240 \end_inset
28241
28242
28243
28244 \layout Standard
28245 The compiler is passed through nightly compile and build checks.
28246  The so called 
28247 \shape italic
28248 regression tests
28249 \shape default
28250
28251 \begin_inset LatexCommand \index{Regression test}
28252
28253 \end_inset
28254
28255  check that SDCC itself compiles flawlessly on several host platforms (i386,
28256  Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
28257  the quality of the code generated by SDCC by running the code for several
28258  target platforms through simulators.
28259  The regression test suite comprises more than 100 files which expand to
28260  more than 500 test cases which include more than 4500 tests.
28261  The results of these tests are published daily on SDCC's snapshot page
28262  (click on the red or green symbols on the right side of 
28263 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
28264
28265 \end_inset
28266
28267 ).
28268
28269 \layout Standard
28270 There is a separate document 
28271 \shape italic
28272 test_suite.pdf 
28273 \begin_inset LatexCommand \index{Test suite}
28274
28275 \end_inset
28276
28277
28278 \shape default
28279  
28280 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
28281
28282 \end_inset
28283
28284  about the regression test suite.
28285
28286 \layout Standard
28287 You'll find the test code in the directory 
28288 \shape italic
28289 sdcc/support/regression
28290 \shape default
28291 .
28292  You can run these tests manually by running 
28293 \family sans
28294 make
28295 \family default
28296  in this directory (or f.e.
28297  
28298 \family sans
28299 \series bold
28300
28301 \begin_inset Quotes sld
28302 \end_inset
28303
28304 make test-mcs51
28305 \begin_inset Quotes srd
28306 \end_inset
28307
28308
28309 \family default
28310 \series default
28311  if you don't want to run the complete tests).
28312  The test code might also be interesting if you want to look for examples
28313 \begin_inset LatexCommand \index{Examples}
28314
28315 \end_inset
28316
28317  checking corner cases of SDCC or if you plan to submit patches
28318 \begin_inset LatexCommand \index{Patch submission}
28319
28320 \end_inset
28321
28322 .
28323
28324 \layout Standard
28325 The 14bit pic port uses a different set of regression tests 
28326 \begin_inset LatexCommand \index{Regression test (PIC14)}
28327
28328 \end_inset
28329
28330 , you'll find them in the directory 
28331 \shape italic
28332 sdcc/src/regression
28333 \shape default
28334 .
28335
28336 \layout Section
28337 Use of SDCC in Education
28338
28339 \layout Standard
28340 In short: 
28341 \emph on
28342 highly
28343 \emph default
28344  encouraged
28345 \begin_inset Foot
28346 collapsed false
28347
28348 \layout Standard
28349 the phrase "use in education" might evoke the association "
28350 \emph on
28351 only
28352 \emph default
28353  fit for use in education".
28354  This connotation is not intended but nevertheless risked as the licensing
28355  of SDCC makes it difficult to offer educational discounts
28356
28357 \end_inset
28358
28359 .
28360  If your rationales are to:
28361
28362 \layout Enumerate
28363 give students a chance to understand the 
28364 \emph on
28365 complete
28366 \emph default
28367  steps of code generation
28368
28369 \layout Enumerate
28370 have a curriculum that can be extended for years.
28371  Then you could use an fpga board as target and your curriculum will seamlessly
28372  extend from logic synthesis (
28373 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
28374
28375 \end_inset
28376
28377
28378 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
28379
28380 \end_inset
28381
28382 ), over assembly programming, to C to FPGA compilers (
28383 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
28384
28385 \end_inset
28386
28387 ) and to C.
28388
28389 \layout Enumerate
28390 be able to insert excursions about skills like using a revision control
28391  system, submitting/applying patches, using a type-setting (as opposed to
28392  word-processing) engine LyX/LaTeX, using 
28393 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
28394
28395 \end_inset
28396
28397 , following some 
28398 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
28399
28400 \end_inset
28401
28402 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
28403  Source Software, CPU simulation, compiler regression tests
28404 \begin_inset LatexCommand \index{Regression test}
28405
28406 \end_inset
28407
28408 .
28409  
28410 \newline
28411 And if there should be a shortage of ideas then you can always point students
28412  to the ever-growing feature request list 
28413 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
28414
28415 \end_inset
28416
28417 .
28418
28419 \layout Enumerate
28420 not tie students to a specific host platform and instead allow them to use
28421  a host platform of 
28422 \emph on
28423 their
28424 \emph default
28425  choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
28426  eventually 
28427 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
28428
28429 \end_inset
28430
28431 )
28432
28433 \layout Enumerate
28434 not encourage students to use illegal copies of educational software
28435
28436 \layout Enumerate
28437 be immune to licensing/availability/price changes of the chosen tool chain
28438
28439 \layout Enumerate
28440 be able to change to a new target platform without having to adopt a new
28441  tool chain
28442
28443 \layout Enumerate
28444 have complete control over and insight into the tool chain
28445
28446 \layout Enumerate
28447 make your students aware about the pros and cons of open source software
28448  development
28449
28450 \layout Enumerate
28451 give back to the public as you are probably at least partially publically
28452  funded
28453
28454 \layout Enumerate
28455 give students a chance to publically prove their skills and to possibly
28456  see a world wide impact
28457
28458 \layout Standard
28459 then SDCC is probably among the first choices.
28460 \pagebreak_bottom 
28461  Well, probably SDCC might be the only choice.
28462
28463
28464 \layout Chapter
28465 SDCC Technical Data
28466
28467 \layout Section
28468 Optimizations
28469 \begin_inset LatexCommand \index{Optimizations}
28470
28471 \end_inset
28472
28473
28474
28475 \layout Standard
28476 SDCC performs a host of standard optimizations in addition to some MCU specific
28477  optimizations.
28478  
28479
28480 \layout Subsection
28481 Sub-expression Elimination
28482 \begin_inset LatexCommand \index{Subexpression elimination}
28483
28484 \end_inset
28485
28486
28487
28488 \layout Standard
28489 The compiler does local and 
28490 \emph on
28491 g
28492 \emph default
28493 lobal 
28494 \emph on
28495 c
28496 \emph default
28497 ommon 
28498 \emph on
28499 s
28500 \emph default
28501 ubexpression 
28502 \emph on
28503 e
28504 \emph default
28505 limination, e.g.: 
28506
28507 \layout Verse
28508
28509 \family typewriter
28510 i = x + y + 1; 
28511 \newline
28512 j = x + y;
28513
28514 \layout Standard
28515 will be translated to
28516
28517 \layout Verse
28518
28519 \family typewriter
28520 iTemp = x + y; 
28521 \newline
28522 i = iTemp + 1; 
28523 \newline
28524 j = iTemp;
28525
28526 \layout Standard
28527 Some subexpressions are not as obvious as the above example, e.g.:
28528
28529 \layout Verse
28530
28531 \family typewriter
28532 a->b[i].c = 10; 
28533 \newline
28534 a->b[i].d = 11;
28535
28536 \layout Standard
28537 In this case the address arithmetic a->b[i] will be computed only once;
28538  the equivalent code in C would be.
28539
28540 \layout Verse
28541
28542 \family typewriter
28543 iTemp = a->b[i]; 
28544 \newline
28545 iTemp.c = 10; 
28546 \newline
28547 iTemp.d = 11;
28548
28549 \layout Standard
28550 The compiler will try to keep these temporary variables in registers.
28551
28552 \layout Subsection
28553 Dead-Code Elimination
28554 \begin_inset LatexCommand \index{Dead-code elimination}
28555
28556 \end_inset
28557
28558
28559
28560 \layout Verse
28561
28562 \family typewriter
28563 int global;
28564 \newline
28565
28566 \newline
28567 void f () { 
28568 \newline
28569 \SpecialChar ~
28570 \SpecialChar ~
28571 int i; 
28572 \newline
28573 \SpecialChar ~
28574 \SpecialChar ~
28575 i = 1; \SpecialChar ~
28576 \SpecialChar ~
28577 \SpecialChar ~
28578 \SpecialChar ~
28579 \SpecialChar ~
28580 /* dead store */ 
28581 \newline
28582 \SpecialChar ~
28583 \SpecialChar ~
28584 global = 1;\SpecialChar ~
28585 /* dead
28586  store */ 
28587 \newline
28588 \SpecialChar ~
28589 \SpecialChar ~
28590 global = 2; 
28591 \newline
28592 \SpecialChar ~
28593 \SpecialChar ~
28594 return; 
28595 \newline
28596 \SpecialChar ~
28597 \SpecialChar ~
28598 global = 3;\SpecialChar ~
28599 /* unreachable */ 
28600 \newline
28601 }
28602
28603 \layout Standard
28604 will be changed to
28605
28606 \layout Verse
28607
28608 \family typewriter
28609 int global;
28610 \newline
28611
28612 \newline
28613 void f () {
28614 \newline
28615 \SpecialChar ~
28616 \SpecialChar ~
28617 global = 2; 
28618 \newline
28619 }
28620
28621 \layout Subsection
28622 Copy-Propagation
28623 \begin_inset LatexCommand \index{Copy propagation}
28624
28625 \end_inset
28626
28627
28628
28629 \layout Verse
28630
28631 \family typewriter
28632 int f() { 
28633 \newline
28634 \SpecialChar ~
28635 \SpecialChar ~
28636 int i, j; 
28637 \newline
28638 \SpecialChar ~
28639 \SpecialChar ~
28640 i = 10; 
28641 \newline
28642 \SpecialChar ~
28643 \SpecialChar ~
28644 j = i; 
28645 \newline
28646 \SpecialChar ~
28647 \SpecialChar ~
28648 return j; 
28649 \newline
28650 }
28651
28652 \layout Standard
28653 will be changed to 
28654
28655 \layout Verse
28656
28657 \family typewriter
28658 int f() { 
28659 \newline
28660 \SpecialChar ~
28661 \SpecialChar ~
28662 int i, j; 
28663 \newline
28664 \SpecialChar ~
28665 \SpecialChar ~
28666 i = 10; 
28667 \newline
28668 \SpecialChar ~
28669 \SpecialChar ~
28670 j = 10; 
28671 \newline
28672 \SpecialChar ~
28673 \SpecialChar ~
28674 return 10; 
28675 \newline
28676 }
28677
28678 \layout Standard
28679 Note: the dead stores created by this copy propagation will be eliminated
28680  by dead-code elimination.
28681
28682 \layout Subsection
28683 Loop Optimizations
28684 \begin_inset LatexCommand \index{Loop optimization}
28685
28686 \end_inset
28687
28688
28689 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
28690
28691 \end_inset
28692
28693
28694
28695 \layout Standard
28696 Two types of loop optimizations are done by SDCC 
28697 \emph on
28698 loop invariant
28699 \emph default
28700  lifting and
28701 \emph on
28702  strength reduction
28703 \emph default
28704  of loop induction variables.
28705  In addition to the strength reduction the optimizer marks the induction
28706  variables and the register allocator tries to keep the induction variables
28707  in registers for the duration of the loop.
28708  Because of this preference of the register allocator
28709 \begin_inset LatexCommand \index{Register allocation}
28710
28711 \end_inset
28712
28713 , loop induction optimization causes an increase in register pressure, which
28714  may cause unwanted spilling of other temporary variables into the stack
28715 \begin_inset LatexCommand \index{stack}
28716
28717 \end_inset
28718
28719  / data space.
28720  The compiler will generate a warning message when it is forced to allocate
28721  extra space either on the stack or data space.
28722  If this extra space allocation is undesirable then induction optimization
28723  can be eliminated either for the entire source file (with -
28724 \begin_inset ERT
28725 status Collapsed
28726
28727 \layout Standard
28728
28729
28730 \backslash
28731 /
28732
28733 \end_inset
28734
28735 -noinduction option) or for a given function only using #pragma\SpecialChar ~
28736 noinduction
28737 \begin_inset LatexCommand \index{\#pragma noinduction}
28738
28739 \end_inset
28740
28741 .
28742 \newline
28743
28744 \newline
28745 Loop Invariant:
28746
28747 \layout Verse
28748
28749 \family typewriter
28750 for (i = 0 ; i < 100 ; i ++) 
28751 \newline
28752 \SpecialChar ~
28753 \SpecialChar ~
28754 \SpecialChar ~
28755 \SpecialChar ~
28756 f += k + l;
28757
28758 \layout Standard
28759 changed to
28760
28761 \layout Verse
28762
28763 \family typewriter
28764 itemp = k + l; 
28765 \newline
28766 for (i = 0; i < 100; i++) 
28767 \newline
28768 \SpecialChar ~
28769 \SpecialChar ~
28770 \SpecialChar ~
28771 \SpecialChar ~
28772 f += itemp;
28773
28774 \layout Standard
28775 As mentioned previously some loop invariants are not as apparent, all static
28776  address computations are also moved out of the loop.
28777 \newline
28778
28779 \newline
28780 Strength Reduction
28781 \begin_inset LatexCommand \index{Strength reduction}
28782
28783 \end_inset
28784
28785 , this optimization substitutes an expression by a cheaper expression:
28786
28787 \layout Verse
28788
28789 \family typewriter
28790 for (i=0;i < 100; i++)
28791 \newline
28792 \SpecialChar ~
28793 \SpecialChar ~
28794 \SpecialChar ~
28795 \SpecialChar ~
28796 ar[i*5] = i*3;
28797
28798 \layout Standard
28799 changed to
28800
28801 \layout Verse
28802
28803 \family typewriter
28804 itemp1 = 0; 
28805 \newline
28806 itemp2 = 0; 
28807 \newline
28808 for (i=0;i< 100;i++) { 
28809 \newline
28810 \SpecialChar ~
28811 \SpecialChar ~
28812 \SpecialChar ~
28813 \SpecialChar ~
28814 ar[itemp1] = itemp2; 
28815 \newline
28816 \SpecialChar ~
28817 \SpecialChar ~
28818 \SpecialChar ~
28819 \SpecialChar ~
28820 itemp1
28821  += 5; 
28822 \newline
28823 \SpecialChar ~
28824 \SpecialChar ~
28825 \SpecialChar ~
28826 \SpecialChar ~
28827 itemp2 += 3; 
28828 \newline
28829 }
28830
28831 \layout Standard
28832 The more expensive multiplication
28833 \begin_inset LatexCommand \index{Multiplication}
28834
28835 \end_inset
28836
28837  is changed to a less expensive addition.
28838
28839 \layout Subsection
28840 Loop Reversing
28841 \begin_inset LatexCommand \index{Loop reversing}
28842
28843 \end_inset
28844
28845
28846
28847 \layout Standard
28848 This optimization is done to reduce the overhead of checking loop boundaries
28849  for every iteration.
28850  Some simple loops can be reversed and implemented using a 
28851 \begin_inset Quotes eld
28852 \end_inset
28853
28854 decrement and jump if not zero
28855 \begin_inset Quotes erd
28856 \end_inset
28857
28858  instruction.
28859  SDCC checks for the following criterion to determine if a loop is reversible
28860  (note: more sophisticated compilers use data-dependency analysis to make
28861  this determination, SDCC uses a more simple minded analysis).
28862
28863 \layout Itemize
28864 The 'for' loop is of the form 
28865 \newline
28866
28867 \newline
28868
28869 \family typewriter
28870 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
28871  += 1])
28872 \newline
28873 \SpecialChar ~
28874 \SpecialChar ~
28875 \SpecialChar ~
28876 \SpecialChar ~
28877 <for body>
28878
28879 \layout Itemize
28880 The <for body> does not contain 
28881 \begin_inset Quotes eld
28882 \end_inset
28883
28884 continue
28885 \begin_inset Quotes erd
28886 \end_inset
28887
28888  or 'break
28889 \begin_inset Quotes erd
28890 \end_inset
28891
28892 .
28893
28894 \layout Itemize
28895 All goto's are contained within the loop.
28896
28897 \layout Itemize
28898 No function calls within the loop.
28899
28900 \layout Itemize
28901 The loop control variable <sym> is not assigned any value within the loop
28902
28903 \layout Itemize
28904 The loop control variable does NOT participate in any arithmetic operation
28905  within the loop.
28906
28907 \layout Itemize
28908 There are NO switch statements in the loop.
28909
28910 \layout Subsection
28911 Algebraic Simplifications
28912
28913 \layout Standard
28914 SDCC does numerous algebraic simplifications, the following is a small sub-set
28915  of these optimizations.
28916
28917 \layout Verse
28918
28919 \family typewriter
28920 i = j + 0;\SpecialChar ~
28921 \SpecialChar ~
28922 \SpecialChar ~
28923 \SpecialChar ~
28924  /* changed to: */\SpecialChar ~
28925 \SpecialChar ~
28926 \SpecialChar ~
28927 \SpecialChar ~
28928  i = j; 
28929 \newline
28930 i /= 2;\SpecialChar ~
28931 \SpecialChar ~
28932 \SpecialChar ~
28933 \SpecialChar ~
28934 \SpecialChar ~
28935 \SpecialChar ~
28936 \SpecialChar ~
28937  /* changed to: */\SpecialChar ~
28938 \SpecialChar ~
28939 \SpecialChar ~
28940 \SpecialChar ~
28941  i >>= 1; 
28942 \newline
28943 i
28944  = j - j;\SpecialChar ~
28945 \SpecialChar ~
28946 \SpecialChar ~
28947 \SpecialChar ~
28948  /* changed to: */\SpecialChar ~
28949 \SpecialChar ~
28950 \SpecialChar ~
28951 \SpecialChar ~
28952  i = 0; 
28953 \newline
28954 i = j / 1;\SpecialChar ~
28955 \SpecialChar ~
28956 \SpecialChar ~
28957 \SpecialChar ~
28958  /* changed to: */\SpecialChar ~
28959 \SpecialChar ~
28960 \SpecialChar ~
28961 \SpecialChar ~
28962  i = j;
28963
28964 \layout Standard
28965 Note the subexpressions
28966 \begin_inset LatexCommand \index{Subexpression}
28967
28968 \end_inset
28969
28970  given above are generally introduced by macro expansions or as a result
28971  of copy/constant propagation.
28972
28973 \layout Subsection
28974 'switch' Statements
28975 \begin_inset LatexCommand \label{sub:'switch'-Statements}
28976
28977 \end_inset
28978
28979
28980 \begin_inset LatexCommand \index{switch statement}
28981
28982 \end_inset
28983
28984
28985
28986 \layout Standard
28987 SDCC can optimize switch statements to jump tables
28988 \begin_inset LatexCommand \index{jump tables}
28989
28990 \end_inset
28991
28992 .
28993  It makes the decision based on an estimate of the generated code size.
28994  SDCC is quite liberal in the requirements for jump table generation: 
28995
28996 \layout Itemize
28997 The labels need not be in order, and the starting number need not be one
28998  or zero, the case labels are in numerical sequence or not too many case
28999  labels are missing.
29000
29001 \begin_deeper
29002 \layout Verse
29003
29004 \family typewriter
29005 switch(i) {\SpecialChar ~
29006 \SpecialChar ~
29007 \SpecialChar ~
29008 \SpecialChar ~
29009 \SpecialChar ~
29010 \SpecialChar ~
29011 \SpecialChar ~
29012 \SpecialChar ~
29013 \SpecialChar ~
29014 \SpecialChar ~
29015 \SpecialChar ~
29016 \SpecialChar ~
29017 \SpecialChar ~
29018 \SpecialChar ~
29019 \SpecialChar ~
29020 \SpecialChar ~
29021 \SpecialChar ~
29022 \SpecialChar ~
29023 \SpecialChar ~
29024 \SpecialChar ~
29025 \SpecialChar ~
29026 \SpecialChar ~
29027 \SpecialChar ~
29028 \SpecialChar ~
29029 \SpecialChar ~
29030 \SpecialChar ~
29031 switch (i) { 
29032 \newline
29033 \SpecialChar ~
29034 \SpecialChar ~
29035 \SpecialChar ~
29036 case 4: ...\SpecialChar ~
29037 \SpecialChar ~
29038 \SpecialChar ~
29039 \SpecialChar ~
29040 \SpecialChar ~
29041 \SpecialChar ~
29042 \SpecialChar ~
29043 \SpecialChar ~
29044 \SpecialChar ~
29045 \SpecialChar ~
29046 \SpecialChar ~
29047 \SpecialChar ~
29048 \SpecialChar ~
29049 \SpecialChar ~
29050 \SpecialChar ~
29051 \SpecialChar ~
29052 \SpecialChar ~
29053 \SpecialChar ~
29054 \SpecialChar ~
29055 \SpecialChar ~
29056 \SpecialChar ~
29057 \SpecialChar ~
29058 \SpecialChar ~
29059 \SpecialChar ~
29060 \SpecialChar ~
29061 \SpecialChar ~
29062 case 0: ...
29063  
29064 \newline
29065 \SpecialChar ~
29066 \SpecialChar ~
29067 \SpecialChar ~
29068 case 5: ...\SpecialChar ~
29069 \SpecialChar ~
29070 \SpecialChar ~
29071 \SpecialChar ~
29072 \SpecialChar ~
29073 \SpecialChar ~
29074 \SpecialChar ~
29075 \SpecialChar ~
29076 \SpecialChar ~
29077 \SpecialChar ~
29078 \SpecialChar ~
29079 \SpecialChar ~
29080 \SpecialChar ~
29081 \SpecialChar ~
29082 \SpecialChar ~
29083 \SpecialChar ~
29084 \SpecialChar ~
29085 \SpecialChar ~
29086 \SpecialChar ~
29087 \SpecialChar ~
29088 \SpecialChar ~
29089 \SpecialChar ~
29090 \SpecialChar ~
29091 \SpecialChar ~
29092 \SpecialChar ~
29093 \SpecialChar ~
29094 case 1: ...
29095  
29096 \newline
29097 \SpecialChar ~
29098 \SpecialChar ~
29099 \SpecialChar ~
29100 case 3: ...\SpecialChar ~
29101 \SpecialChar ~
29102 \SpecialChar ~
29103 \SpecialChar ~
29104 \SpecialChar ~
29105 \SpecialChar ~
29106 \SpecialChar ~
29107 \SpecialChar ~
29108 \SpecialChar ~
29109 \SpecialChar ~
29110 \SpecialChar ~
29111 \SpecialChar ~
29112 \SpecialChar ~
29113 \SpecialChar ~
29114 \SpecialChar ~
29115 \SpecialChar ~
29116 \SpecialChar ~
29117 \SpecialChar ~
29118 \SpecialChar ~
29119 \SpecialChar ~
29120 \SpecialChar ~
29121 \SpecialChar ~
29122 \SpecialChar ~
29123 \SpecialChar ~
29124 \SpecialChar ~
29125 \SpecialChar ~
29126
29127 \newline
29128 \SpecialChar ~
29129 \SpecialChar ~
29130 \SpecialChar ~
29131 case 6: ...\SpecialChar ~
29132 \SpecialChar ~
29133 \SpecialChar ~
29134 \SpecialChar ~
29135 \SpecialChar ~
29136 \SpecialChar ~
29137 \SpecialChar ~
29138 \SpecialChar ~
29139 \SpecialChar ~
29140 \SpecialChar ~
29141 \SpecialChar ~
29142 \SpecialChar ~
29143 \SpecialChar ~
29144 \SpecialChar ~
29145 \SpecialChar ~
29146 \SpecialChar ~
29147 \SpecialChar ~
29148 \SpecialChar ~
29149 \SpecialChar ~
29150 \SpecialChar ~
29151 \SpecialChar ~
29152 \SpecialChar ~
29153 \SpecialChar ~
29154 \SpecialChar ~
29155 \SpecialChar ~
29156 \SpecialChar ~
29157 case 3: ...
29158  
29159 \newline
29160 \SpecialChar ~
29161 \SpecialChar ~
29162 \SpecialChar ~
29163 case 7: ...\SpecialChar ~
29164 \SpecialChar ~
29165 \SpecialChar ~
29166 \SpecialChar ~
29167 \SpecialChar ~
29168 \SpecialChar ~
29169 \SpecialChar ~
29170 \SpecialChar ~
29171 \SpecialChar ~
29172 \SpecialChar ~
29173 \SpecialChar ~
29174 \SpecialChar ~
29175 \SpecialChar ~
29176 \SpecialChar ~
29177 \SpecialChar ~
29178 \SpecialChar ~
29179 \SpecialChar ~
29180 \SpecialChar ~
29181 \SpecialChar ~
29182 \SpecialChar ~
29183 \SpecialChar ~
29184 \SpecialChar ~
29185 \SpecialChar ~
29186 \SpecialChar ~
29187 \SpecialChar ~
29188 \SpecialChar ~
29189 case 4: ...
29190  
29191 \newline
29192 \SpecialChar ~
29193 \SpecialChar ~
29194 \SpecialChar ~
29195 case 8: ...\SpecialChar ~
29196 \SpecialChar ~
29197 \SpecialChar ~
29198 \SpecialChar ~
29199 \SpecialChar ~
29200 \SpecialChar ~
29201 \SpecialChar ~
29202 \SpecialChar ~
29203 \SpecialChar ~
29204 \SpecialChar ~
29205 \SpecialChar ~
29206 \SpecialChar ~
29207 \SpecialChar ~
29208 \SpecialChar ~
29209 \SpecialChar ~
29210 \SpecialChar ~
29211 \SpecialChar ~
29212 \SpecialChar ~
29213 \SpecialChar ~
29214 \SpecialChar ~
29215 \SpecialChar ~
29216 \SpecialChar ~
29217 \SpecialChar ~
29218 \SpecialChar ~
29219 \SpecialChar ~
29220 \SpecialChar ~
29221 case 5: ...
29222  
29223 \newline
29224 \SpecialChar ~
29225 \SpecialChar ~
29226 \SpecialChar ~
29227 case 9: ...\SpecialChar ~
29228 \SpecialChar ~
29229 \SpecialChar ~
29230 \SpecialChar ~
29231 \SpecialChar ~
29232 \SpecialChar ~
29233 \SpecialChar ~
29234 \SpecialChar ~
29235 \SpecialChar ~
29236 \SpecialChar ~
29237 \SpecialChar ~
29238 \SpecialChar ~
29239 \SpecialChar ~
29240 \SpecialChar ~
29241 \SpecialChar ~
29242 \SpecialChar ~
29243 \SpecialChar ~
29244 \SpecialChar ~
29245 \SpecialChar ~
29246 \SpecialChar ~
29247 \SpecialChar ~
29248 \SpecialChar ~
29249 \SpecialChar ~
29250 \SpecialChar ~
29251 \SpecialChar ~
29252 \SpecialChar ~
29253 case 6: ...
29254  
29255 \newline
29256 \SpecialChar ~
29257 \SpecialChar ~
29258 \SpecialChar ~
29259 case 10: ...\SpecialChar ~
29260 \SpecialChar ~
29261 \SpecialChar ~
29262 \SpecialChar ~
29263 \SpecialChar ~
29264 \SpecialChar ~
29265 \SpecialChar ~
29266 \SpecialChar ~
29267 \SpecialChar ~
29268 \SpecialChar ~
29269 \SpecialChar ~
29270 \SpecialChar ~
29271 \SpecialChar ~
29272 \SpecialChar ~
29273 \SpecialChar ~
29274 \SpecialChar ~
29275 \SpecialChar ~
29276 \SpecialChar ~
29277 \SpecialChar ~
29278 \SpecialChar ~
29279 \SpecialChar ~
29280 \SpecialChar ~
29281 \SpecialChar ~
29282 \SpecialChar ~
29283 \SpecialChar ~
29284 case 7: ...
29285  
29286 \newline
29287 \SpecialChar ~
29288 \SpecialChar ~
29289 \SpecialChar ~
29290 case 11: ...\SpecialChar ~
29291 \SpecialChar ~
29292 \SpecialChar ~
29293 \SpecialChar ~
29294 \SpecialChar ~
29295 \SpecialChar ~
29296 \SpecialChar ~
29297 \SpecialChar ~
29298 \SpecialChar ~
29299 \SpecialChar ~
29300 \SpecialChar ~
29301 \SpecialChar ~
29302 \SpecialChar ~
29303 \SpecialChar ~
29304 \SpecialChar ~
29305 \SpecialChar ~
29306 \SpecialChar ~
29307 \SpecialChar ~
29308 \SpecialChar ~
29309 \SpecialChar ~
29310 \SpecialChar ~
29311 \SpecialChar ~
29312 \SpecialChar ~
29313 \SpecialChar ~
29314 \SpecialChar ~
29315 case 8: ...
29316  
29317 \newline
29318 }\SpecialChar ~
29319 \SpecialChar ~
29320 \SpecialChar ~
29321 \SpecialChar ~
29322 \SpecialChar ~
29323 \SpecialChar ~
29324 \SpecialChar ~
29325 \SpecialChar ~
29326 \SpecialChar ~
29327 \SpecialChar ~
29328 \SpecialChar ~
29329 \SpecialChar ~
29330 \SpecialChar ~
29331 \SpecialChar ~
29332 \SpecialChar ~
29333 \SpecialChar ~
29334 \SpecialChar ~
29335 \SpecialChar ~
29336 \SpecialChar ~
29337 \SpecialChar ~
29338 \SpecialChar ~
29339 \SpecialChar ~
29340 \SpecialChar ~
29341 \SpecialChar ~
29342 \SpecialChar ~
29343 \SpecialChar ~
29344 \SpecialChar ~
29345 \SpecialChar ~
29346 \SpecialChar ~
29347 \SpecialChar ~
29348 \SpecialChar ~
29349 \SpecialChar ~
29350 \SpecialChar ~
29351 \SpecialChar ~
29352 \SpecialChar ~
29353 \SpecialChar ~
29354 }
29355
29356 \layout Standard
29357 Both the above switch statements will be implemented using a jump-table.
29358  The example to the right side is slightly more efficient as the check for
29359  the lower boundary of the jump-table is not needed.
29360
29361 \end_deeper
29362 \layout Itemize
29363 The number of case labels is not larger than supported by the target architectur
29364 e.
29365
29366 \layout Itemize
29367 If the case labels are not in numerical sequence ('gaps' between cases)
29368  SDCC checks whether a jump table with additionally inserted dummy cases
29369  is still attractive.
29370  
29371
29372 \layout Itemize
29373 If the starting number is not zero and a check for the lower boundary of
29374  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
29375  ...
29376  .
29377
29378 \layout Standard
29379 Switch statements which have large gaps in the numeric sequence or those
29380  that have too many case labels can be split into more than one switch statement
29381  for efficient code generation, e.g.:
29382
29383 \layout Verse
29384
29385 \family typewriter
29386 switch (i) { 
29387 \newline
29388 \SpecialChar ~
29389 \SpecialChar ~
29390 case 1: ...
29391  
29392 \newline
29393 \SpecialChar ~
29394 \SpecialChar ~
29395 case 2: ...
29396  
29397 \newline
29398 \SpecialChar ~
29399 \SpecialChar ~
29400 case 3: ...
29401  
29402 \newline
29403 \SpecialChar ~
29404 \SpecialChar ~
29405 case 4: ...
29406  
29407 \newline
29408 \SpecialChar ~
29409 \SpecialChar ~
29410 case 5: ...
29411  
29412 \newline
29413 \SpecialChar ~
29414 \SpecialChar ~
29415 case 6: ...
29416  
29417 \newline
29418 \SpecialChar ~
29419 \SpecialChar ~
29420 case 7: ...
29421  
29422 \newline
29423 \SpecialChar ~
29424 \SpecialChar ~
29425 case 101: ...
29426  
29427 \newline
29428 \SpecialChar ~
29429 \SpecialChar ~
29430 case 102: ...
29431  
29432 \newline
29433 \SpecialChar ~
29434 \SpecialChar ~
29435 case 103: ...
29436  
29437 \newline
29438 \SpecialChar ~
29439 \SpecialChar ~
29440 case 104: ...
29441  
29442 \newline
29443 \SpecialChar ~
29444 \SpecialChar ~
29445 case 105: ...
29446  
29447 \newline
29448 \SpecialChar ~
29449 \SpecialChar ~
29450 case 106: ...
29451  
29452 \newline
29453 \SpecialChar ~
29454 \SpecialChar ~
29455 case 107: ...
29456  
29457 \newline
29458 }
29459
29460 \layout Standard
29461 If the above switch statement is broken down into two switch statements
29462
29463 \layout Verse
29464
29465 \family typewriter
29466 switch (i) { 
29467 \newline
29468 \SpecialChar ~
29469 \SpecialChar ~
29470 case 1: ...
29471  
29472 \newline
29473 \SpecialChar ~
29474 \SpecialChar ~
29475 case 2: ...
29476  
29477 \newline
29478 \SpecialChar ~
29479 \SpecialChar ~
29480 case 3: ...
29481  
29482 \newline
29483 \SpecialChar ~
29484 \SpecialChar ~
29485 case 4: ...
29486  
29487 \newline
29488 \SpecialChar ~
29489 \SpecialChar ~
29490 case 5: ...
29491  
29492 \newline
29493 \SpecialChar ~
29494 \SpecialChar ~
29495 case 6: ...
29496  
29497 \newline
29498 \SpecialChar ~
29499 \SpecialChar ~
29500 case 7: ...
29501  
29502 \newline
29503 }
29504
29505 \layout Standard
29506 and
29507
29508 \layout Verse
29509
29510 \family typewriter
29511 switch (i) { 
29512 \newline
29513 \SpecialChar ~
29514 \SpecialChar ~
29515 case 101: ...
29516  
29517 \newline
29518 \SpecialChar ~
29519 \SpecialChar ~
29520 case 102: ...
29521  
29522 \newline
29523 \SpecialChar ~
29524 \SpecialChar ~
29525 case 103: ...
29526  
29527 \newline
29528 \SpecialChar ~
29529 \SpecialChar ~
29530 case 104: ...
29531  
29532 \newline
29533 \SpecialChar ~
29534 \SpecialChar ~
29535 case 105: ...
29536  
29537 \newline
29538 \SpecialChar ~
29539 \SpecialChar ~
29540 case 106: ...
29541  
29542 \newline
29543 \SpecialChar ~
29544 \SpecialChar ~
29545 case 107: ...
29546  
29547 \newline
29548 }
29549
29550 \layout Standard
29551 then both the switch statements will be implemented using jump-tables whereas
29552  the unmodified switch statement will not be.
29553
29554 \layout Standard
29555 \begin_inset Note
29556 collapsed true
29557
29558 \layout Standard
29559 There might be reasons which SDCC cannot know about to either favour or
29560  not favour jump tables.
29561  If the target system has to be as quick for the last switch case as for
29562  the first (pro jump table), or if the switch argument is known to be zero
29563  in the majority of the cases (contra jump table).
29564
29565 \end_inset
29566
29567
29568
29569 \layout Standard
29570 The pragma nojtbound
29571 \begin_inset LatexCommand \index{\#pragma nojtbound}
29572
29573 \end_inset
29574
29575  can be used to turn off checking the 
29576 \emph on
29577 j
29578 \emph default
29579 ump 
29580 \emph on
29581 t
29582 \emph default
29583 able 
29584 \emph on
29585 bound
29586 \emph default
29587 aries.
29588  It has no effect if a default label is supplied.
29589  Use of this pragma is dangerous: if the switch
29590 \begin_inset LatexCommand \index{switch statement}
29591
29592 \end_inset
29593
29594  argument is not matched by a case statement the processor will happily
29595  jump into Nirvana.
29596
29597 \layout Subsection
29598 Bit-shifting Operations
29599 \begin_inset LatexCommand \index{Bit shifting}
29600
29601 \end_inset
29602
29603 .
29604
29605 \layout Standard
29606 Bit shifting is one of the most frequently used operation in embedded programmin
29607 g.
29608  SDCC tries to implement bit-shift operations in the most efficient way
29609  possible, e.g.:
29610
29611 \layout Verse
29612
29613 \family typewriter
29614 unsigned char i;
29615 \newline
29616 ...
29617  
29618 \newline
29619 i >>= 4; 
29620 \newline
29621 ...
29622
29623 \layout Standard
29624 generates the following code:
29625
29626 \layout Verse
29627
29628 \family typewriter
29629 mov\SpecialChar ~
29630  a,_i 
29631 \newline
29632 swap a 
29633 \newline
29634 anl\SpecialChar ~
29635  a,#0x0f 
29636 \newline
29637 mov\SpecialChar ~
29638  _i,a
29639
29640 \layout Standard
29641 In general SDCC will never setup a loop if the shift count is known.
29642  Another example:
29643
29644 \layout Verse
29645
29646 \family typewriter
29647 unsigned int i; 
29648 \newline
29649 ...
29650  
29651 \newline
29652 i >>= 9; 
29653 \newline
29654 ...
29655
29656 \layout Standard
29657 will generate:
29658
29659 \layout Verse
29660
29661 \family typewriter
29662 mov\SpecialChar ~
29663 \SpecialChar ~
29664 a,(_i + 1) 
29665 \newline
29666 mov\SpecialChar ~
29667 \SpecialChar ~
29668 (_i + 1),#0x00 
29669 \newline
29670 clr\SpecialChar ~
29671 \SpecialChar ~
29672
29673 \newline
29674 rrc\SpecialChar ~
29675 \SpecialChar ~
29676
29677 \newline
29678 mov\SpecialChar ~
29679 \SpecialChar ~
29680 _i,a
29681
29682 \layout Subsection
29683 Bit-rotation
29684 \begin_inset LatexCommand \index{Bit rotation}
29685
29686 \end_inset
29687
29688
29689
29690 \layout Standard
29691 A special case of the bit-shift operation is bit rotation
29692 \begin_inset LatexCommand \index{rotating bits}
29693
29694 \end_inset
29695
29696 , SDCC recognizes the following expression to be a left bit-rotation:
29697
29698 \layout Verse
29699
29700 \family typewriter
29701 \series bold
29702 unsigned
29703 \series default
29704 \SpecialChar ~
29705 \SpecialChar ~
29706 char i;\SpecialChar ~
29707 \SpecialChar ~
29708 \SpecialChar ~
29709 \SpecialChar ~
29710 \SpecialChar ~
29711 \SpecialChar ~
29712 \SpecialChar ~
29713 \SpecialChar ~
29714 \SpecialChar ~
29715 \SpecialChar ~
29716 \SpecialChar ~
29717 /* unsigned is needed for rotation */ 
29718 \newline
29719 ...
29720  
29721 \newline
29722 i = ((i << 1) | (i >> 7)); 
29723 \family default
29724
29725 \newline
29726
29727 \family typewriter
29728 ...
29729
29730 \layout Standard
29731 will generate the following code:
29732
29733 \layout Verse
29734
29735 \family typewriter
29736 mov\SpecialChar ~
29737 \SpecialChar ~
29738 a,_i 
29739 \newline
29740 rl\SpecialChar ~
29741 \SpecialChar ~
29742 \SpecialChar ~
29743
29744 \newline
29745 mov\SpecialChar ~
29746 \SpecialChar ~
29747 _i,a
29748
29749 \layout Standard
29750 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
29751 ns of this case will also be recognized as bit-rotation, i.e.: 
29752
29753 \layout Verse
29754
29755 \family typewriter
29756 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
29757
29758 \layout Subsection
29759 Nibble and Byte Swapping
29760
29761 \layout Standard
29762 Other special cases of the bit-shift operations are nibble or byte swapping
29763 \begin_inset LatexCommand \index{swapping nibbles/bytes}
29764
29765 \end_inset
29766
29767 , SDCC recognizes the following expressions:
29768
29769 \layout Verse
29770
29771 \family typewriter
29772 \series bold
29773 unsigned
29774 \series default
29775 \SpecialChar ~
29776 \SpecialChar ~
29777 char i; 
29778 \newline
29779
29780 \series bold
29781 unsigned
29782 \series default
29783 \SpecialChar ~
29784 \SpecialChar ~
29785 int j; 
29786 \newline
29787 ...
29788  
29789 \newline
29790 i = ((i << 4) | (i >> 4)); 
29791 \family default
29792
29793 \newline
29794
29795 \family typewriter
29796 j = ((j << 8) | (j >> 8)); 
29797
29798 \layout Standard
29799 and generates a swap instruction for the nibble swapping
29800 \begin_inset LatexCommand \index{Nibble swapping}
29801
29802 \end_inset
29803
29804  or move instructions for the byte swapping
29805 \begin_inset LatexCommand \index{Byte swapping}
29806
29807 \end_inset
29808
29809 .
29810  The 
29811 \begin_inset Quotes sld
29812 \end_inset
29813
29814 j
29815 \begin_inset Quotes srd
29816 \end_inset
29817
29818  example can be used to convert from little to big-endian or vice versa.
29819  If you want to change the endianness of a 
29820 \emph on
29821 signed
29822 \emph default
29823  integer you have to cast to 
29824 \family typewriter
29825 (unsigned int)
29826 \family default
29827  first.
29828
29829 \layout Standard
29830 Note that SDCC stores numbers in little-endian
29831 \begin_inset Foot
29832 collapsed false
29833
29834 \layout Standard
29835 Usually 8-bit processors don't care much about endianness.
29836  This is not the case for the standard 8051 which only has an instruction
29837  to increment its 
29838 \emph on
29839 dptr
29840 \emph default
29841
29842 \begin_inset LatexCommand \index{DPTR}
29843
29844 \end_inset
29845
29846 -datapointer
29847 \emph on
29848  
29849 \emph default
29850 so little-endian is the more efficient byte order.
29851
29852 \end_inset
29853
29854
29855 \begin_inset LatexCommand \index{little-endian}
29856
29857 \end_inset
29858
29859
29860 \begin_inset LatexCommand \index{Endianness}
29861
29862 \end_inset
29863
29864  format (i.e.
29865  lowest order first).
29866
29867 \layout Subsection
29868 Highest Order Bit
29869 \begin_inset LatexCommand \index{Highest Order Bit}
29870
29871 \end_inset
29872
29873  / Any Order Bit
29874 \begin_inset LatexCommand \index{Any Order Bit}
29875
29876 \end_inset
29877
29878
29879
29880 \layout Standard
29881 It is frequently required to obtain the highest order bit of an integral
29882  type (long, int, short or char types).
29883  Also obtaining any other order bit is not uncommon.
29884  SDCC recognizes the following expressions to yield the highest order bit
29885  and generates optimized code for it, e.g.:
29886
29887 \layout Verse
29888
29889 \family typewriter
29890 unsigned int gint; 
29891 \newline
29892
29893 \newline
29894 foo () { 
29895 \newline
29896 \SpecialChar ~
29897 \SpecialChar ~
29898 unsigned char hob1, aob1; 
29899 \newline
29900 \SpecialChar ~
29901 \SpecialChar ~
29902 bit hob2, hob3, aob2,
29903  aob3; 
29904 \newline
29905 \SpecialChar ~
29906 \SpecialChar ~
29907 ...
29908  
29909 \newline
29910 \SpecialChar ~
29911 \SpecialChar ~
29912 hob1 = (gint >> 15) & 1; 
29913 \newline
29914 \SpecialChar ~
29915 \SpecialChar ~
29916 hob2 = (gint >> 15) & 1; 
29917 \newline
29918 \SpecialChar ~
29919 \SpecialChar ~
29920 hob3 = gint & 0x8000;
29921  
29922 \newline
29923 \SpecialChar ~
29924 \SpecialChar ~
29925 aob1 = (gint >> 9) & 1; 
29926 \newline
29927 \SpecialChar ~
29928 \SpecialChar ~
29929 aob2 = (gint >> 8) & 1; 
29930 \newline
29931 \SpecialChar ~
29932 \SpecialChar ~
29933 aob3 = gint & 0x0800; 
29934 \newline
29935 \SpecialChar ~
29936 \SpecialChar ~
29937 ..
29938  
29939 \newline
29940 }
29941
29942 \layout Standard
29943 will generate the following code:
29944
29945 \layout Verse
29946
29947 \family typewriter
29948 \SpecialChar ~
29949 \SpecialChar ~
29950 \SpecialChar ~
29951 \SpecialChar ~
29952 \SpecialChar ~
29953 \SpecialChar ~
29954 \SpecialChar ~
29955 \SpecialChar ~
29956 \SpecialChar ~
29957 \SpecialChar ~
29958 \SpecialChar ~
29959 \SpecialChar ~
29960 \SpecialChar ~
29961 \SpecialChar ~
29962 \SpecialChar ~
29963 \SpecialChar ~
29964 \SpecialChar ~
29965 \SpecialChar ~
29966 \SpecialChar ~
29967 \SpecialChar ~
29968 \SpecialChar ~
29969 \SpecialChar ~
29970 \SpecialChar ~
29971 \SpecialChar ~
29972 \SpecialChar ~
29973  61 ;\SpecialChar ~
29974  hob.c 7 
29975 \newline
29976 000A E5*01\SpecialChar ~
29977 \SpecialChar ~
29978 \SpecialChar ~
29979 \SpecialChar ~
29980 \SpecialChar ~
29981 \SpecialChar ~
29982 \SpecialChar ~
29983 \SpecialChar ~
29984 \SpecialChar ~
29985 \SpecialChar ~
29986 \SpecialChar ~
29987 \SpecialChar ~
29988 \SpecialChar ~
29989 \SpecialChar ~
29990 \SpecialChar ~
29991  62\SpecialChar ~
29992 \SpecialChar ~
29993 \SpecialChar ~
29994 \SpecialChar ~
29995 \SpecialChar ~
29996 \SpecialChar ~
29997 \SpecialChar ~
29998 \SpecialChar ~
29999  mov\SpecialChar ~
30000 \SpecialChar ~
30001  a,(_gint + 1) 
30002 \newline
30003 000C 23\SpecialChar ~
30004 \SpecialChar ~
30005 \SpecialChar ~
30006 \SpecialChar ~
30007 \SpecialChar ~
30008 \SpecialChar ~
30009 \SpecialChar ~
30010 \SpecialChar ~
30011 \SpecialChar ~
30012 \SpecialChar ~
30013 \SpecialChar ~
30014 \SpecialChar ~
30015 \SpecialChar ~
30016 \SpecialChar ~
30017 \SpecialChar ~
30018 \SpecialChar ~
30019 \SpecialChar ~
30020 \SpecialChar ~
30021  63\SpecialChar ~
30022 \SpecialChar ~
30023 \SpecialChar ~
30024 \SpecialChar ~
30025 \SpecialChar ~
30026 \SpecialChar ~
30027 \SpecialChar ~
30028 \SpecialChar ~
30029  rl\SpecialChar ~
30030 \SpecialChar ~
30031 \SpecialChar ~
30032  a 
30033 \newline
30034 000D 54 01\SpecialChar ~
30035 \SpecialChar ~
30036 \SpecialChar ~
30037 \SpecialChar ~
30038 \SpecialChar ~
30039 \SpecialChar ~
30040 \SpecialChar ~
30041 \SpecialChar ~
30042 \SpecialChar ~
30043 \SpecialChar ~
30044 \SpecialChar ~
30045 \SpecialChar ~
30046 \SpecialChar ~
30047 \SpecialChar ~
30048 \SpecialChar ~
30049
30050  64\SpecialChar ~
30051 \SpecialChar ~
30052 \SpecialChar ~
30053 \SpecialChar ~
30054 \SpecialChar ~
30055 \SpecialChar ~
30056 \SpecialChar ~
30057 \SpecialChar ~
30058  anl\SpecialChar ~
30059 \SpecialChar ~
30060  a,#0x01 
30061 \newline
30062 000F F5*02\SpecialChar ~
30063 \SpecialChar ~
30064 \SpecialChar ~
30065 \SpecialChar ~
30066 \SpecialChar ~
30067 \SpecialChar ~
30068 \SpecialChar ~
30069 \SpecialChar ~
30070 \SpecialChar ~
30071 \SpecialChar ~
30072 \SpecialChar ~
30073 \SpecialChar ~
30074 \SpecialChar ~
30075 \SpecialChar ~
30076 \SpecialChar ~
30077  65\SpecialChar ~
30078 \SpecialChar ~
30079 \SpecialChar ~
30080 \SpecialChar ~
30081 \SpecialChar ~
30082 \SpecialChar ~
30083 \SpecialChar ~
30084 \SpecialChar ~
30085  mov\SpecialChar ~
30086 \SpecialChar ~
30087  _foo_hob1_1_1,a 
30088 \newline
30089 \SpecialChar ~
30090 \SpecialChar ~
30091 \SpecialChar ~
30092 \SpecialChar ~
30093 \SpecialChar ~
30094 \SpecialChar ~
30095 \SpecialChar ~
30096 \SpecialChar ~
30097 \SpecialChar ~
30098 \SpecialChar ~
30099 \SpecialChar ~
30100 \SpecialChar ~
30101 \SpecialChar ~
30102 \SpecialChar ~
30103 \SpecialChar ~
30104 \SpecialChar ~
30105 \SpecialChar ~
30106 \SpecialChar ~
30107 \SpecialChar ~
30108 \SpecialChar ~
30109 \SpecialChar ~
30110 \SpecialChar ~
30111 \SpecialChar ~
30112 \SpecialChar ~
30113 \SpecialChar ~
30114  66 ;\SpecialChar ~
30115  hob.c 8 
30116 \newline
30117 0011 E5*01\SpecialChar ~
30118 \SpecialChar ~
30119 \SpecialChar ~
30120 \SpecialChar ~
30121 \SpecialChar ~
30122 \SpecialChar ~
30123 \SpecialChar ~
30124 \SpecialChar ~
30125 \SpecialChar ~
30126 \SpecialChar ~
30127 \SpecialChar ~
30128 \SpecialChar ~
30129 \SpecialChar ~
30130 \SpecialChar ~
30131 \SpecialChar ~
30132
30133  67\SpecialChar ~
30134 \SpecialChar ~
30135 \SpecialChar ~
30136 \SpecialChar ~
30137 \SpecialChar ~
30138 \SpecialChar ~
30139 \SpecialChar ~
30140 \SpecialChar ~
30141  mov\SpecialChar ~
30142 \SpecialChar ~
30143  a,(_gint + 1) 
30144 \newline
30145 0013 33\SpecialChar ~
30146 \SpecialChar ~
30147 \SpecialChar ~
30148 \SpecialChar ~
30149 \SpecialChar ~
30150 \SpecialChar ~
30151 \SpecialChar ~
30152 \SpecialChar ~
30153 \SpecialChar ~
30154 \SpecialChar ~
30155 \SpecialChar ~
30156 \SpecialChar ~
30157 \SpecialChar ~
30158 \SpecialChar ~
30159 \SpecialChar ~
30160 \SpecialChar ~
30161 \SpecialChar ~
30162 \SpecialChar ~
30163  68\SpecialChar ~
30164 \SpecialChar ~
30165 \SpecialChar ~
30166 \SpecialChar ~
30167 \SpecialChar ~
30168 \SpecialChar ~
30169 \SpecialChar ~
30170 \SpecialChar ~
30171  rlc\SpecialChar ~
30172 \SpecialChar ~
30173  a 
30174 \newline
30175 0014 92*00\SpecialChar ~
30176 \SpecialChar ~
30177 \SpecialChar ~
30178 \SpecialChar ~
30179 \SpecialChar ~
30180 \SpecialChar ~
30181 \SpecialChar ~
30182 \SpecialChar ~
30183 \SpecialChar ~
30184 \SpecialChar ~
30185 \SpecialChar ~
30186 \SpecialChar ~
30187 \SpecialChar ~
30188 \SpecialChar ~
30189 \SpecialChar ~
30190  69\SpecialChar ~
30191 \SpecialChar ~
30192 \SpecialChar ~
30193 \SpecialChar ~
30194 \SpecialChar ~
30195 \SpecialChar ~
30196 \SpecialChar ~
30197 \SpecialChar ~
30198  mov\SpecialChar ~
30199 \SpecialChar ~
30200  _foo_hob2_1_1,c
30201  
30202 \newline
30203 \SpecialChar ~
30204 \SpecialChar ~
30205 \SpecialChar ~
30206 \SpecialChar ~
30207 \SpecialChar ~
30208 \SpecialChar ~
30209 \SpecialChar ~
30210 \SpecialChar ~
30211 \SpecialChar ~
30212 \SpecialChar ~
30213 \SpecialChar ~
30214 \SpecialChar ~
30215 \SpecialChar ~
30216 \SpecialChar ~
30217 \SpecialChar ~
30218 \SpecialChar ~
30219 \SpecialChar ~
30220 \SpecialChar ~
30221 \SpecialChar ~
30222 \SpecialChar ~
30223 \SpecialChar ~
30224 \SpecialChar ~
30225 \SpecialChar ~
30226 \SpecialChar ~
30227 \SpecialChar ~
30228  66 ;\SpecialChar ~
30229  hob.c 9 
30230 \newline
30231 0016 E5*01\SpecialChar ~
30232 \SpecialChar ~
30233 \SpecialChar ~
30234 \SpecialChar ~
30235 \SpecialChar ~
30236 \SpecialChar ~
30237 \SpecialChar ~
30238 \SpecialChar ~
30239 \SpecialChar ~
30240 \SpecialChar ~
30241 \SpecialChar ~
30242 \SpecialChar ~
30243 \SpecialChar ~
30244 \SpecialChar ~
30245 \SpecialChar ~
30246  67\SpecialChar ~
30247 \SpecialChar ~
30248 \SpecialChar ~
30249 \SpecialChar ~
30250 \SpecialChar ~
30251 \SpecialChar ~
30252 \SpecialChar ~
30253 \SpecialChar ~
30254  mov\SpecialChar ~
30255 \SpecialChar ~
30256  a,(_gint + 1) 
30257 \newline
30258 0018 33\SpecialChar ~
30259 \SpecialChar ~
30260 \SpecialChar ~
30261 \SpecialChar ~
30262 \SpecialChar ~
30263 \SpecialChar ~
30264 \SpecialChar ~
30265 \SpecialChar ~
30266 \SpecialChar ~
30267 \SpecialChar ~
30268 \SpecialChar ~
30269 \SpecialChar ~
30270 \SpecialChar ~
30271 \SpecialChar ~
30272 \SpecialChar ~
30273 \SpecialChar ~
30274 \SpecialChar ~
30275 \SpecialChar ~
30276  68\SpecialChar ~
30277 \SpecialChar ~
30278 \SpecialChar ~
30279 \SpecialChar ~
30280 \SpecialChar ~
30281 \SpecialChar ~
30282 \SpecialChar ~
30283 \SpecialChar ~
30284  rlc\SpecialChar ~
30285 \SpecialChar ~
30286  a 
30287 \newline
30288 0019 92*01\SpecialChar ~
30289 \SpecialChar ~
30290 \SpecialChar ~
30291 \SpecialChar ~
30292 \SpecialChar ~
30293 \SpecialChar ~
30294 \SpecialChar ~
30295 \SpecialChar ~
30296 \SpecialChar ~
30297 \SpecialChar ~
30298 \SpecialChar ~
30299 \SpecialChar ~
30300 \SpecialChar ~
30301 \SpecialChar ~
30302 \SpecialChar ~
30303
30304  69\SpecialChar ~
30305 \SpecialChar ~
30306 \SpecialChar ~
30307 \SpecialChar ~
30308 \SpecialChar ~
30309 \SpecialChar ~
30310 \SpecialChar ~
30311 \SpecialChar ~
30312  mov\SpecialChar ~
30313 \SpecialChar ~
30314  _foo_hob3_1_1,c 
30315 \newline
30316 \SpecialChar ~
30317 \SpecialChar ~
30318 \SpecialChar ~
30319 \SpecialChar ~
30320 \SpecialChar ~
30321 \SpecialChar ~
30322 \SpecialChar ~
30323 \SpecialChar ~
30324 \SpecialChar ~
30325 \SpecialChar ~
30326 \SpecialChar ~
30327 \SpecialChar ~
30328 \SpecialChar ~
30329 \SpecialChar ~
30330 \SpecialChar ~
30331 \SpecialChar ~
30332 \SpecialChar ~
30333 \SpecialChar ~
30334 \SpecialChar ~
30335 \SpecialChar ~
30336 \SpecialChar ~
30337 \SpecialChar ~
30338 \SpecialChar ~
30339 \SpecialChar ~
30340 \SpecialChar ~
30341  70 ;\SpecialChar ~
30342  hob.c 10 
30343 \newline
30344 001B E5*01\SpecialChar ~
30345 \SpecialChar ~
30346 \SpecialChar ~
30347 \SpecialChar ~
30348 \SpecialChar ~
30349 \SpecialChar ~
30350 \SpecialChar ~
30351 \SpecialChar ~
30352 \SpecialChar ~
30353 \SpecialChar ~
30354 \SpecialChar ~
30355 \SpecialChar ~
30356 \SpecialChar ~
30357 \SpecialChar ~
30358 \SpecialChar ~
30359  71\SpecialChar ~
30360 \SpecialChar ~
30361 \SpecialChar ~
30362 \SpecialChar ~
30363 \SpecialChar ~
30364 \SpecialChar ~
30365 \SpecialChar ~
30366 \SpecialChar ~
30367  mov\SpecialChar ~
30368 \SpecialChar ~
30369  a,(_gint + 1) 
30370 \newline
30371 001D
30372  03\SpecialChar ~
30373 \SpecialChar ~
30374 \SpecialChar ~
30375 \SpecialChar ~
30376 \SpecialChar ~
30377 \SpecialChar ~
30378 \SpecialChar ~
30379 \SpecialChar ~
30380 \SpecialChar ~
30381 \SpecialChar ~
30382 \SpecialChar ~
30383 \SpecialChar ~
30384 \SpecialChar ~
30385 \SpecialChar ~
30386 \SpecialChar ~
30387 \SpecialChar ~
30388 \SpecialChar ~
30389 \SpecialChar ~
30390  72\SpecialChar ~
30391 \SpecialChar ~
30392 \SpecialChar ~
30393 \SpecialChar ~
30394 \SpecialChar ~
30395 \SpecialChar ~
30396 \SpecialChar ~
30397 \SpecialChar ~
30398  rr\SpecialChar ~
30399 \SpecialChar ~
30400 \SpecialChar ~
30401  a 
30402 \newline
30403 001E 54 01\SpecialChar ~
30404 \SpecialChar ~
30405 \SpecialChar ~
30406 \SpecialChar ~
30407 \SpecialChar ~
30408 \SpecialChar ~
30409 \SpecialChar ~
30410 \SpecialChar ~
30411 \SpecialChar ~
30412 \SpecialChar ~
30413 \SpecialChar ~
30414 \SpecialChar ~
30415 \SpecialChar ~
30416 \SpecialChar ~
30417 \SpecialChar ~
30418  73\SpecialChar ~
30419 \SpecialChar ~
30420 \SpecialChar ~
30421 \SpecialChar ~
30422 \SpecialChar ~
30423 \SpecialChar ~
30424 \SpecialChar ~
30425 \SpecialChar ~
30426  anl\SpecialChar ~
30427 \SpecialChar ~
30428  a,#0x01 
30429 \newline
30430 0020 F5*03\SpecialChar ~
30431 \SpecialChar ~
30432 \SpecialChar ~
30433 \SpecialChar ~
30434 \SpecialChar ~
30435 \SpecialChar ~
30436 \SpecialChar ~
30437 \SpecialChar ~
30438 \SpecialChar ~
30439 \SpecialChar ~
30440 \SpecialChar ~
30441 \SpecialChar ~
30442 \SpecialChar ~
30443 \SpecialChar ~
30444 \SpecialChar ~
30445  74\SpecialChar ~
30446 \SpecialChar ~
30447 \SpecialChar ~
30448 \SpecialChar ~
30449 \SpecialChar ~
30450 \SpecialChar ~
30451 \SpecialChar ~
30452 \SpecialChar ~
30453  mov\SpecialChar ~
30454 \SpecialChar ~
30455  _foo_aob1_1_1,a
30456  
30457 \newline
30458 \SpecialChar ~
30459 \SpecialChar ~
30460 \SpecialChar ~
30461 \SpecialChar ~
30462 \SpecialChar ~
30463 \SpecialChar ~
30464 \SpecialChar ~
30465 \SpecialChar ~
30466 \SpecialChar ~
30467 \SpecialChar ~
30468 \SpecialChar ~
30469 \SpecialChar ~
30470 \SpecialChar ~
30471 \SpecialChar ~
30472 \SpecialChar ~
30473 \SpecialChar ~
30474 \SpecialChar ~
30475 \SpecialChar ~
30476 \SpecialChar ~
30477 \SpecialChar ~
30478 \SpecialChar ~
30479 \SpecialChar ~
30480 \SpecialChar ~
30481 \SpecialChar ~
30482 \SpecialChar ~
30483  75 ;\SpecialChar ~
30484  hob.c 11 
30485 \newline
30486 0022 E5*01\SpecialChar ~
30487 \SpecialChar ~
30488 \SpecialChar ~
30489 \SpecialChar ~
30490 \SpecialChar ~
30491 \SpecialChar ~
30492 \SpecialChar ~
30493 \SpecialChar ~
30494 \SpecialChar ~
30495 \SpecialChar ~
30496 \SpecialChar ~
30497 \SpecialChar ~
30498 \SpecialChar ~
30499 \SpecialChar ~
30500 \SpecialChar ~
30501  76\SpecialChar ~
30502 \SpecialChar ~
30503 \SpecialChar ~
30504 \SpecialChar ~
30505 \SpecialChar ~
30506 \SpecialChar ~
30507 \SpecialChar ~
30508 \SpecialChar ~
30509  mov\SpecialChar ~
30510 \SpecialChar ~
30511  a,(_gint + 1) 
30512 \newline
30513 0024 13\SpecialChar ~
30514 \SpecialChar ~
30515 \SpecialChar ~
30516 \SpecialChar ~
30517 \SpecialChar ~
30518 \SpecialChar ~
30519 \SpecialChar ~
30520 \SpecialChar ~
30521 \SpecialChar ~
30522 \SpecialChar ~
30523 \SpecialChar ~
30524 \SpecialChar ~
30525 \SpecialChar ~
30526 \SpecialChar ~
30527 \SpecialChar ~
30528 \SpecialChar ~
30529 \SpecialChar ~
30530 \SpecialChar ~
30531  77\SpecialChar ~
30532 \SpecialChar ~
30533 \SpecialChar ~
30534 \SpecialChar ~
30535 \SpecialChar ~
30536 \SpecialChar ~
30537 \SpecialChar ~
30538 \SpecialChar ~
30539  rrc\SpecialChar ~
30540 \SpecialChar ~
30541  a 
30542 \newline
30543 0025 92*02\SpecialChar ~
30544 \SpecialChar ~
30545 \SpecialChar ~
30546 \SpecialChar ~
30547 \SpecialChar ~
30548 \SpecialChar ~
30549 \SpecialChar ~
30550 \SpecialChar ~
30551 \SpecialChar ~
30552 \SpecialChar ~
30553 \SpecialChar ~
30554 \SpecialChar ~
30555 \SpecialChar ~
30556 \SpecialChar ~
30557 \SpecialChar ~
30558
30559  78\SpecialChar ~
30560 \SpecialChar ~
30561 \SpecialChar ~
30562 \SpecialChar ~
30563 \SpecialChar ~
30564 \SpecialChar ~
30565 \SpecialChar ~
30566 \SpecialChar ~
30567  mov\SpecialChar ~
30568 \SpecialChar ~
30569  _foo_aob2_1_1,c 
30570 \newline
30571 \SpecialChar ~
30572 \SpecialChar ~
30573 \SpecialChar ~
30574 \SpecialChar ~
30575 \SpecialChar ~
30576 \SpecialChar ~
30577 \SpecialChar ~
30578 \SpecialChar ~
30579 \SpecialChar ~
30580 \SpecialChar ~
30581 \SpecialChar ~
30582 \SpecialChar ~
30583 \SpecialChar ~
30584 \SpecialChar ~
30585 \SpecialChar ~
30586 \SpecialChar ~
30587 \SpecialChar ~
30588 \SpecialChar ~
30589 \SpecialChar ~
30590 \SpecialChar ~
30591 \SpecialChar ~
30592 \SpecialChar ~
30593 \SpecialChar ~
30594 \SpecialChar ~
30595 \SpecialChar ~
30596  79 ;\SpecialChar ~
30597  hob.c 12 
30598 \newline
30599 0027 E5*01\SpecialChar ~
30600 \SpecialChar ~
30601 \SpecialChar ~
30602 \SpecialChar ~
30603 \SpecialChar ~
30604 \SpecialChar ~
30605 \SpecialChar ~
30606 \SpecialChar ~
30607 \SpecialChar ~
30608 \SpecialChar ~
30609 \SpecialChar ~
30610 \SpecialChar ~
30611 \SpecialChar ~
30612 \SpecialChar ~
30613 \SpecialChar ~
30614  80\SpecialChar ~
30615 \SpecialChar ~
30616 \SpecialChar ~
30617 \SpecialChar ~
30618 \SpecialChar ~
30619 \SpecialChar ~
30620 \SpecialChar ~
30621 \SpecialChar ~
30622  mov\SpecialChar ~
30623 \SpecialChar ~
30624  a,(_gint + 1) 
30625 \newline
30626 0029
30627  A2 E3\SpecialChar ~
30628 \SpecialChar ~
30629 \SpecialChar ~
30630 \SpecialChar ~
30631 \SpecialChar ~
30632 \SpecialChar ~
30633 \SpecialChar ~
30634 \SpecialChar ~
30635 \SpecialChar ~
30636 \SpecialChar ~
30637 \SpecialChar ~
30638 \SpecialChar ~
30639 \SpecialChar ~
30640 \SpecialChar ~
30641 \SpecialChar ~
30642  81\SpecialChar ~
30643 \SpecialChar ~
30644 \SpecialChar ~
30645 \SpecialChar ~
30646 \SpecialChar ~
30647 \SpecialChar ~
30648 \SpecialChar ~
30649 \SpecialChar ~
30650  mov\SpecialChar ~
30651 \SpecialChar ~
30652  c,acc[3] 
30653 \newline
30654 002B 92*03\SpecialChar ~
30655 \SpecialChar ~
30656 \SpecialChar ~
30657 \SpecialChar ~
30658 \SpecialChar ~
30659 \SpecialChar ~
30660 \SpecialChar ~
30661 \SpecialChar ~
30662 \SpecialChar ~
30663 \SpecialChar ~
30664 \SpecialChar ~
30665 \SpecialChar ~
30666 \SpecialChar ~
30667 \SpecialChar ~
30668 \SpecialChar ~
30669  82\SpecialChar ~
30670 \SpecialChar ~
30671 \SpecialChar ~
30672 \SpecialChar ~
30673 \SpecialChar ~
30674 \SpecialChar ~
30675 \SpecialChar ~
30676 \SpecialChar ~
30677  mov\SpecialChar ~
30678 \SpecialChar ~
30679  _foo_aob3_1_1,c 
30680
30681 \layout Standard
30682 Other variations of these cases however will 
30683 \emph on
30684 not
30685 \emph default
30686  be recognized.
30687  They are standard C expressions, so I heartily recommend these be the only
30688  way to get the highest order bit, (it is portable).
30689  Of course it will be recognized even if it is embedded in other expressions,
30690  e.g.:
30691
30692 \layout Verse
30693
30694 \family typewriter
30695 xyz = gint + ((gint >> 15) & 1);
30696
30697 \layout Standard
30698 will still be recognized.
30699
30700 \layout Subsection
30701 Higher Order Byte
30702 \begin_inset LatexCommand \index{Higher Order Byte}
30703
30704 \end_inset
30705
30706  / Higher Order Word
30707 \begin_inset LatexCommand \index{Higher Order Word}
30708
30709 \end_inset
30710
30711
30712
30713 \layout Standard
30714 It is also frequently required to obtain a higher order byte or word of
30715  a larger integral type (long, int or short types).
30716  SDCC recognizes the following expressions to yield the higher order byte
30717  or word and generates optimized code for it, e.g.:
30718
30719 \layout Verse
30720
30721 \family typewriter
30722 unsigned int gint; 
30723 \newline
30724 unsigned long int glong; 
30725 \newline
30726
30727 \newline
30728 foo () { 
30729 \newline
30730 \SpecialChar ~
30731 \SpecialChar ~
30732 unsigned char hob1,
30733  hob2; 
30734 \newline
30735 \SpecialChar ~
30736 \SpecialChar ~
30737 unsigned int how1, how2; 
30738 \newline
30739 \SpecialChar ~
30740 \SpecialChar ~
30741 ...
30742  
30743 \newline
30744 \SpecialChar ~
30745 \SpecialChar ~
30746 hob1 = (gint >> 8) & 0xFF; 
30747 \newline
30748 \SpecialChar ~
30749 \SpecialChar ~
30750 hob2 = glong >> 24; 
30751 \newline
30752 \SpecialChar ~
30753 \SpecialChar ~
30754 how1 = (glong >> 16) & 0xFFFF;
30755  
30756 \newline
30757 \SpecialChar ~
30758 \SpecialChar ~
30759 how2 = glong >> 8; 
30760 \newline
30761 \SpecialChar ~
30762 \SpecialChar ~
30763 ..
30764  
30765 \newline
30766 }
30767
30768 \layout Standard
30769 will generate the following code:
30770
30771 \layout Verse
30772
30773 \family typewriter
30774 \SpecialChar ~
30775 \SpecialChar ~
30776 \SpecialChar ~
30777 \SpecialChar ~
30778 \SpecialChar ~
30779 \SpecialChar ~
30780 \SpecialChar ~
30781 \SpecialChar ~
30782 \SpecialChar ~
30783 \SpecialChar ~
30784 \SpecialChar ~
30785 \SpecialChar ~
30786 \SpecialChar ~
30787 \SpecialChar ~
30788 \SpecialChar ~
30789 \SpecialChar ~
30790 \SpecialChar ~
30791 \SpecialChar ~
30792 \SpecialChar ~
30793 \SpecialChar ~
30794 \SpecialChar ~
30795 \SpecialChar ~
30796 \SpecialChar ~
30797 \SpecialChar ~
30798 \SpecialChar ~
30799  91 ;\SpecialChar ~
30800  hob.c 15 
30801 \newline
30802 0037 85*01*06\SpecialChar ~
30803 \SpecialChar ~
30804 \SpecialChar ~
30805 \SpecialChar ~
30806 \SpecialChar ~
30807 \SpecialChar ~
30808 \SpecialChar ~
30809 \SpecialChar ~
30810 \SpecialChar ~
30811 \SpecialChar ~
30812 \SpecialChar ~
30813 \SpecialChar ~
30814  92\SpecialChar ~
30815 \SpecialChar ~
30816 \SpecialChar ~
30817 \SpecialChar ~
30818 \SpecialChar ~
30819 \SpecialChar ~
30820 \SpecialChar ~
30821 \SpecialChar ~
30822  mov\SpecialChar ~
30823 \SpecialChar ~
30824  _foo_hob1_1_1,(_gint + 1) 
30825 \newline
30826 \SpecialChar ~
30827 \SpecialChar ~
30828 \SpecialChar ~
30829 \SpecialChar ~
30830 \SpecialChar ~
30831 \SpecialChar ~
30832 \SpecialChar ~
30833 \SpecialChar ~
30834 \SpecialChar ~
30835 \SpecialChar ~
30836 \SpecialChar ~
30837 \SpecialChar ~
30838 \SpecialChar ~
30839 \SpecialChar ~
30840 \SpecialChar ~
30841 \SpecialChar ~
30842 \SpecialChar ~
30843 \SpecialChar ~
30844 \SpecialChar ~
30845 \SpecialChar ~
30846 \SpecialChar ~
30847 \SpecialChar ~
30848 \SpecialChar ~
30849 \SpecialChar ~
30850 \SpecialChar ~
30851  93 ;\SpecialChar ~
30852  hob.c
30853  16 
30854 \newline
30855 003A 85*05*07\SpecialChar ~
30856 \SpecialChar ~
30857 \SpecialChar ~
30858 \SpecialChar ~
30859 \SpecialChar ~
30860 \SpecialChar ~
30861 \SpecialChar ~
30862 \SpecialChar ~
30863 \SpecialChar ~
30864 \SpecialChar ~
30865 \SpecialChar ~
30866 \SpecialChar ~
30867  94\SpecialChar ~
30868 \SpecialChar ~
30869 \SpecialChar ~
30870 \SpecialChar ~
30871 \SpecialChar ~
30872 \SpecialChar ~
30873 \SpecialChar ~
30874 \SpecialChar ~
30875  mov\SpecialChar ~
30876 \SpecialChar ~
30877  _foo_hob2_1_1,(_glong + 3) 
30878 \newline
30879 \SpecialChar ~
30880 \SpecialChar ~
30881 \SpecialChar ~
30882 \SpecialChar ~
30883 \SpecialChar ~
30884 \SpecialChar ~
30885 \SpecialChar ~
30886 \SpecialChar ~
30887 \SpecialChar ~
30888 \SpecialChar ~
30889 \SpecialChar ~
30890 \SpecialChar ~
30891 \SpecialChar ~
30892 \SpecialChar ~
30893 \SpecialChar ~
30894 \SpecialChar ~
30895 \SpecialChar ~
30896 \SpecialChar ~
30897 \SpecialChar ~
30898 \SpecialChar ~
30899 \SpecialChar ~
30900 \SpecialChar ~
30901 \SpecialChar ~
30902 \SpecialChar ~
30903 \SpecialChar ~
30904  95 ;\SpecialChar ~
30905  hob.c 17 
30906 \newline
30907 003D 85*04*08\SpecialChar ~
30908 \SpecialChar ~
30909 \SpecialChar ~
30910 \SpecialChar ~
30911 \SpecialChar ~
30912 \SpecialChar ~
30913 \SpecialChar ~
30914 \SpecialChar ~
30915 \SpecialChar ~
30916 \SpecialChar ~
30917 \SpecialChar ~
30918 \SpecialChar ~
30919
30920  96\SpecialChar ~
30921 \SpecialChar ~
30922 \SpecialChar ~
30923 \SpecialChar ~
30924 \SpecialChar ~
30925 \SpecialChar ~
30926 \SpecialChar ~
30927 \SpecialChar ~
30928  mov\SpecialChar ~
30929 \SpecialChar ~
30930  _foo_how1_1_1,(_glong + 2) 
30931 \newline
30932 0040 85*05*09\SpecialChar ~
30933 \SpecialChar ~
30934 \SpecialChar ~
30935 \SpecialChar ~
30936 \SpecialChar ~
30937 \SpecialChar ~
30938 \SpecialChar ~
30939 \SpecialChar ~
30940 \SpecialChar ~
30941 \SpecialChar ~
30942 \SpecialChar ~
30943 \SpecialChar ~
30944  97\SpecialChar ~
30945 \SpecialChar ~
30946 \SpecialChar ~
30947 \SpecialChar ~
30948 \SpecialChar ~
30949 \SpecialChar ~
30950 \SpecialChar ~
30951 \SpecialChar ~
30952  mov\SpecialChar ~
30953 \SpecialChar ~
30954  (_foo_how1_1_1 +
30955  1),(_glong + 3) 
30956 \newline
30957 0043 85*03*0A\SpecialChar ~
30958 \SpecialChar ~
30959 \SpecialChar ~
30960 \SpecialChar ~
30961 \SpecialChar ~
30962 \SpecialChar ~
30963 \SpecialChar ~
30964 \SpecialChar ~
30965 \SpecialChar ~
30966 \SpecialChar ~
30967 \SpecialChar ~
30968 \SpecialChar ~
30969  98\SpecialChar ~
30970 \SpecialChar ~
30971 \SpecialChar ~
30972 \SpecialChar ~
30973 \SpecialChar ~
30974 \SpecialChar ~
30975 \SpecialChar ~
30976 \SpecialChar ~
30977  mov\SpecialChar ~
30978 \SpecialChar ~
30979  _foo_how2_1_1,(_glong + 1) 
30980 \newline
30981 0046 85*04*0B\SpecialChar ~
30982 \SpecialChar ~
30983 \SpecialChar ~
30984 \SpecialChar ~
30985 \SpecialChar ~
30986 \SpecialChar ~
30987 \SpecialChar ~
30988 \SpecialChar ~
30989 \SpecialChar ~
30990 \SpecialChar ~
30991 \SpecialChar ~
30992 \SpecialChar ~
30993
30994  99\SpecialChar ~
30995 \SpecialChar ~
30996 \SpecialChar ~
30997 \SpecialChar ~
30998 \SpecialChar ~
30999 \SpecialChar ~
31000 \SpecialChar ~
31001 \SpecialChar ~
31002  mov\SpecialChar ~
31003 \SpecialChar ~
31004  (_foo_how2_1_1 + 1),(_glong + 2) 
31005
31006 \layout Standard
31007 Again, variations of these cases may 
31008 \emph on
31009 not
31010 \emph default
31011  be recognized.
31012  They are standard C expressions, so I heartily recommend these be the only
31013  way to get the higher order byte/word, (it is portable).
31014  Of course it will be recognized even if it is embedded in other expressions,
31015  e.g.:
31016
31017 \layout Verse
31018
31019 \family typewriter
31020 xyz = gint + ((gint >> 8) & 0xFF);
31021
31022 \layout Standard
31023 will still be recognized.
31024
31025 \layout Subsection
31026 Peephole Optimizer
31027 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
31028
31029 \end_inset
31030
31031
31032 \begin_inset LatexCommand \index{Peephole optimizer}
31033
31034 \end_inset
31035
31036
31037
31038 \layout Standard
31039 The compiler uses a rule based, pattern matching and re-writing mechanism
31040  for peep-hole optimization.
31041  It is inspired by 
31042 \emph on
31043 copt
31044 \emph default
31045  a peep-hole optimizer by Christopher W.
31046  Fraser (cwfraser\SpecialChar ~
31047 @\SpecialChar ~
31048 microsoft.com).
31049  A default set of rules are compiled into the compiler, additional rules
31050  may be added with the 
31051 \emph on
31052 -
31053 \begin_inset ERT
31054 status Collapsed
31055
31056 \layout Standard
31057
31058
31059 \backslash
31060 /
31061
31062 \end_inset
31063
31064 -peep-file
31065 \begin_inset LatexCommand \index{-\/-peep-file}
31066
31067 \end_inset
31068
31069  <filename>
31070 \emph default
31071  option.
31072  The rule language is best illustrated with examples.
31073
31074 \layout Verse
31075
31076 \family typewriter
31077 replace { 
31078 \newline
31079 \SpecialChar ~
31080 \SpecialChar ~
31081 mov %1,a 
31082 \newline
31083 \SpecialChar ~
31084 \SpecialChar ~
31085 mov a,%1
31086 \newline
31087 } by {
31088 \newline
31089 \SpecialChar ~
31090 \SpecialChar ~
31091 mov %1,a
31092 \newline
31093 }
31094
31095 \layout Standard
31096 The above rule will change the following assembly
31097 \begin_inset LatexCommand \index{Assembler routines}
31098
31099 \end_inset
31100
31101  sequence:
31102
31103 \layout Verse
31104
31105 \family typewriter
31106 mov r1,a 
31107 \newline
31108 mov a,r1
31109
31110 \layout Standard
31111 to
31112
31113 \layout Verse
31114
31115 \family typewriter
31116 mov r1,a
31117
31118 \layout Standard
31119 Note: All occurrences of a 
31120 \emph on
31121 %n
31122 \emph default
31123  (pattern variable) must denote the same string.
31124  With the above rule, the assembly sequence:
31125
31126 \layout Verse
31127
31128 \family typewriter
31129 mov r1,a 
31130 \newline
31131 mov a,r2
31132
31133 \layout Standard
31134 will remain unmodified.
31135 \newline
31136
31137 \newline
31138 Other special case optimizations may be added by the
31139  user (via 
31140 \emph on
31141 -
31142 \begin_inset ERT
31143 status Collapsed
31144
31145 \layout Standard
31146
31147
31148 \backslash
31149 /
31150
31151 \end_inset
31152
31153 -peep-file option
31154 \emph default
31155 ).
31156  E.g.
31157  some variants of the 8051 MCU
31158 \begin_inset LatexCommand \index{MCS51 variants}
31159
31160 \end_inset
31161
31162  allow only 
31163 \family typewriter
31164 ajmp
31165 \family default
31166  and 
31167 \family typewriter
31168 acall
31169 \family default
31170 .
31171  The following two rules will change all 
31172 \family typewriter
31173 ljmp
31174 \family default
31175  and 
31176 \family typewriter
31177 lcall
31178 \family default
31179  to 
31180 \family typewriter
31181 ajmp
31182 \family default
31183  and 
31184 \family typewriter
31185 acall
31186
31187 \layout Verse
31188
31189 \family typewriter
31190 replace { lcall %1 } by { acall %1 } 
31191 \newline
31192 replace { ljmp %1 } by { ajmp %1 }
31193
31194 \layout Standard
31195 The 
31196 \emph on
31197 inline-assembler code
31198 \emph default
31199  is also passed through the peep hole optimizer, thus the peephole optimizer
31200  can also be used as an assembly level macro expander.
31201  The rules themselves are MCU dependent whereas the rule language infra-structur
31202 e is MCU independent.
31203  Peephole optimization rules for other MCU can be easily programmed using
31204  the rule language.
31205 \newline
31206
31207 \newline
31208 The syntax for a rule is as follows:
31209
31210 \layout Verse
31211
31212 \family typewriter
31213 rule := replace [ restart ] '{' <assembly sequence> '
31214 \backslash
31215 n' 
31216 \newline
31217 \SpecialChar ~
31218  \SpecialChar ~
31219  \SpecialChar ~
31220  \SpecialChar ~
31221  \SpecialChar ~
31222  \SpecialChar ~
31223  \SpecialChar ~
31224  \SpecialChar ~
31225  \SpecialChar ~
31226  \SpecialChar ~
31227  \SpecialChar ~
31228  \SpecialChar ~
31229  \SpecialChar ~
31230  \SpecialChar ~
31231  '}' by '{' '
31232 \backslash
31233 n' 
31234 \newline
31235 \SpecialChar ~
31236  \SpecialChar ~
31237  \SpecialChar ~
31238  \SpecialChar ~
31239  \SpecialChar ~
31240  \SpecialChar ~
31241  \SpecialChar ~
31242  \SpecialChar ~
31243  \SpecialChar ~
31244  \SpecialChar ~
31245  \SpecialChar ~
31246  \SpecialChar ~
31247  \SpecialChar ~
31248  \SpecialChar ~
31249  \SpecialChar ~
31250  \SpecialChar ~
31251  <assembly sequence> '
31252 \backslash
31253 n' 
31254 \newline
31255 \SpecialChar ~
31256  \SpecialChar ~
31257  \SpecialChar ~
31258  \SpecialChar ~
31259  \SpecialChar ~
31260  \SpecialChar ~
31261  \SpecialChar ~
31262  \SpecialChar ~
31263  \SpecialChar ~
31264  \SpecialChar ~
31265  \SpecialChar ~
31266  \SpecialChar ~
31267  \SpecialChar ~
31268  \SpecialChar ~
31269  '}' [if <functionName> ] '
31270 \backslash
31271 n' 
31272
31273 \layout Standard
31274 <assembly sequence> := assembly instruction (each instruction including
31275  labels must be on a separate line).
31276 \newline
31277
31278 \newline
31279 The optimizer will apply to the rules
31280  one by one from the top in the sequence of their appearance, it will terminate
31281  when all rules are exhausted.
31282  If the 'restart' option is specified, then the optimizer will start matching
31283  the rules again from the top, this option for a rule is expensive (performance)
31284 , it is intended to be used in situations where a transformation will trigger
31285  the same rule again.
31286  An example of this (not a good one, it has side effects) is the following
31287  rule:
31288
31289 \layout Verse
31290
31291 \family typewriter
31292 replace restart { 
31293 \newline
31294 \SpecialChar ~
31295 \SpecialChar ~
31296 pop %1 
31297 \newline
31298 \SpecialChar ~
31299 \SpecialChar ~
31300 push %1 } by { 
31301 \newline
31302 \SpecialChar ~
31303 \SpecialChar ~
31304 ; nop 
31305 \newline
31306 }
31307
31308 \layout Standard
31309 Note that the replace pattern cannot be a blank, but can be a comment line.
31310  Without the 'restart' option only the innermost 'pop' 'push' pair would
31311  be eliminated, i.e.:
31312
31313 \layout Verse
31314
31315 \family typewriter
31316 pop ar1 
31317 \newline
31318 pop ar2 
31319 \newline
31320 push ar2 
31321 \newline
31322 push ar1
31323
31324 \layout Standard
31325 would result in:
31326
31327 \layout Verse
31328
31329 \family typewriter
31330 pop ar1 
31331 \newline
31332 ; nop 
31333 \newline
31334 push ar1
31335
31336 \layout Standard
31337
31338 \emph on
31339 with
31340 \emph default
31341  the restart option the rule will be applied again to the resulting code
31342  and then all the pop-push pairs will be eliminated to yield:
31343
31344 \layout Verse
31345
31346 \family typewriter
31347 ; nop 
31348 \newline
31349 ; nop
31350
31351 \layout Standard
31352 A conditional function can be attached to a rule.
31353  Attaching rules are somewhat more involved, let me illustrate this with
31354  an example.
31355
31356 \layout Verse
31357
31358 \family typewriter
31359 replace { 
31360 \newline
31361 \SpecialChar ~
31362  \SpecialChar ~
31363  \SpecialChar ~
31364 ljmp %5 
31365 \newline
31366 %2:
31367 \newline
31368 } by { 
31369 \newline
31370 \SpecialChar ~
31371  \SpecialChar ~
31372  \SpecialChar ~
31373 sjmp %5 
31374 \newline
31375 %2:
31376 \newline
31377 } if labelInRange
31378
31379 \layout Standard
31380 The optimizer does a look-up of a function name table defined in function
31381  
31382 \emph on
31383 callFuncByName
31384 \emph default
31385  in the source file SDCCpeeph.c, with the name 
31386 \emph on
31387 labelInRange
31388 \emph default
31389 .
31390  If it finds a corresponding entry the function is called.
31391  Note there can be no parameters specified for these functions, in this
31392  case the use of 
31393 \emph on
31394 %5
31395 \emph default
31396  is crucial, since the function 
31397 \emph on
31398 labelInRange
31399 \emph default
31400  expects to find the label in that particular variable (the hash table containin
31401 g the variable bindings is passed as a parameter).
31402  If you want to code more such functions, take a close look at the function
31403  labelInRange and the calling mechanism in source file SDCCpeeph.c.
31404  Currently implemented are 
31405 \emph on
31406 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
31407  24bitMode, portIsDS390, 24bitModeAndPortDS390 
31408 \emph default
31409 and
31410 \emph on
31411  notVolatile
31412 \emph default
31413 .
31414
31415 \layout Standard
31416 I know this whole thing is a little kludgey, but maybe some day we will
31417  have some better means.
31418  If you are looking at this file, you will see the default rules that are
31419  compiled into the compiler, you can add your own rules in the default set
31420  there if you get tired of specifying the -
31421 \begin_inset ERT
31422 status Collapsed
31423
31424 \layout Standard
31425
31426
31427 \backslash
31428 /
31429
31430 \end_inset
31431
31432 -peep-file option.
31433
31434 \layout Section
31435 ANSI-Compliance
31436 \begin_inset LatexCommand \index{ANSI-compliance}
31437
31438 \end_inset
31439
31440
31441 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
31442
31443 \end_inset
31444
31445
31446
31447 \layout Standard
31448 The latest publically available version of the standard 
31449 \emph on
31450 ISO/IEC 9899 - Programming languages - C
31451 \emph default
31452  should be available at: 
31453 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31454
31455 \end_inset
31456
31457 .
31458 \newline
31459
31460
31461 \layout Standard
31462 Deviations from the compliance:
31463
31464 \layout Itemize
31465 functions are not reentrant
31466 \begin_inset LatexCommand \index{reentrant}
31467
31468 \end_inset
31469
31470  unless explicitly declared as such or the 
31471 \series bold
31472 -
31473 \begin_inset ERT
31474 status Collapsed
31475
31476 \layout Standard
31477
31478
31479 \backslash
31480 /
31481
31482 \end_inset
31483
31484 -stack-auto
31485 \begin_inset LatexCommand \index{-\/-stack-auto}
31486
31487 \end_inset
31488
31489
31490 \series default
31491  command line option is specified.
31492
31493 \layout Itemize
31494 structures
31495 \begin_inset LatexCommand \index{struct}
31496
31497 \end_inset
31498
31499  and unions
31500 \begin_inset LatexCommand \index{union}
31501
31502 \end_inset
31503
31504  cannot be assigned values directly, cannot be passed as function parameters
31505  or assigned to each other and cannot be a return value
31506 \begin_inset LatexCommand \index{return value}
31507
31508 \end_inset
31509
31510  from a function, e.g.:
31511
31512 \begin_deeper
31513 \layout Verse
31514
31515 \family typewriter
31516 struct s { ...
31517  }; 
31518 \newline
31519 struct s s1, s2; 
31520 \newline
31521 foo() 
31522 \newline
31523
31524 \newline
31525 \SpecialChar ~
31526 \SpecialChar ~
31527 \SpecialChar ~
31528 \SpecialChar ~
31529 ...
31530  
31531 \newline
31532 \SpecialChar ~
31533 \SpecialChar ~
31534 \SpecialChar ~
31535 \SpecialChar ~
31536 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
31537 \newline
31538 \SpecialChar ~
31539 \SpecialChar ~
31540 \SpecialChar ~
31541 \SpecialChar ~
31542 ...
31543  
31544 \newline
31545 }
31546 \newline
31547
31548 \series bold
31549 struct
31550 \series default
31551  s foo1 (
31552 \series bold
31553 struct
31554 \series default
31555  s parms) /* invalid in SDCC although allowed in ANSI */
31556 \newline
31557
31558 \newline
31559 \SpecialChar ~
31560 \SpecialChar ~
31561 \SpecialChar ~
31562 \SpecialChar ~
31563 struct s rets;
31564  
31565 \newline
31566 \SpecialChar ~
31567 \SpecialChar ~
31568 \SpecialChar ~
31569 \SpecialChar ~
31570 ...
31571  
31572 \newline
31573 \SpecialChar ~
31574 \SpecialChar ~
31575 \SpecialChar ~
31576 \SpecialChar ~
31577 return rets; /* is invalid in SDCC although allowed in ANSI */ 
31578 \newline
31579 }
31580
31581 \end_deeper
31582 \layout Itemize
31583 initialization of structure arrays must be fully braced.
31584
31585 \begin_deeper
31586 \layout Verse
31587
31588 \family typewriter
31589 struct s { char x } a[] = {1, 2};\SpecialChar ~
31590 \SpecialChar ~
31591 \SpecialChar ~
31592 \SpecialChar ~
31593 \SpecialChar ~
31594 /* invalid in SDCC */
31595 \newline
31596 struct s { char x
31597  } a[] = {{1}, {2}}; /* OK */
31598
31599 \end_deeper
31600 \layout Itemize
31601 'long long
31602 \begin_inset LatexCommand \index{long long (not supported)}
31603
31604 \end_inset
31605
31606 ' (64 bit integers
31607 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
31608
31609 \end_inset
31610
31611 ) not supported.
31612
31613 \layout Itemize
31614 'double
31615 \begin_inset LatexCommand \index{double (not supported)}
31616
31617 \end_inset
31618
31619 ' precision floating point 
31620 \begin_inset LatexCommand \index{Floating point support}
31621
31622 \end_inset
31623
31624 not supported.
31625
31626 \layout Itemize
31627 Old K&R style
31628 \begin_inset LatexCommand \index{K\&R style}
31629
31630 \end_inset
31631
31632  function declarations are NOT allowed.
31633
31634 \begin_deeper
31635 \layout Verse
31636
31637 \family typewriter
31638 foo(i,j) /* this old style of function declarations */ 
31639 \newline
31640 int i,j; /* are valid
31641  in ANSI but not valid in SDCC */ 
31642 \newline
31643
31644 \newline
31645 \SpecialChar ~
31646 \SpecialChar ~
31647 \SpecialChar ~
31648 \SpecialChar ~
31649 ...
31650  
31651 \newline
31652 }
31653
31654 \end_deeper
31655 \layout Itemize
31656 Most enhancements in C99 are not supported, f.e.:
31657
31658 \begin_deeper
31659 \layout Verse
31660
31661 \family typewriter
31662 \series bold
31663 inline
31664 \begin_inset LatexCommand \index{inline (not supported)}
31665
31666 \end_inset
31667
31668
31669 \series default
31670  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
31671  in C99.
31672  An empty define 
31673 \emph on
31674 #define inline
31675 \emph default
31676  can be used as a work around */
31677 \newline
31678
31679 \newline
31680 for (
31681 \series bold
31682 int
31683 \series default
31684  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
31685
31686 \end_deeper
31687 \layout Itemize
31688 Certain words that are valid identifiers in the standard may be reserved
31689  words in SDCC unless the 
31690 \series bold
31691 -
31692 \begin_inset ERT
31693 status Collapsed
31694
31695 \layout Standard
31696
31697
31698 \backslash
31699 /
31700
31701 \end_inset
31702
31703 -std-c89
31704 \begin_inset LatexCommand \index{-\/-std-c89}
31705
31706 \end_inset
31707
31708  or -
31709 \begin_inset ERT
31710 status Collapsed
31711
31712 \layout Standard
31713
31714
31715 \backslash
31716 /
31717
31718 \end_inset
31719
31720 -std-c99
31721 \begin_inset LatexCommand \index{-\/-std-c99}
31722
31723 \end_inset
31724
31725
31726 \series default
31727  command line options are used.
31728  These may include (depending on the selected processor): 'at', 'banked',
31729  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
31730 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
31731  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
31732  '_naked'.
31733  Compliant equivalents of these keywords are always available in a form
31734  that begin with two underscores
31735 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
31736
31737 \end_inset
31738
31739 , f.e.
31740  '__data' instead of 'data'.
31741
31742 \layout Section
31743 Cyclomatic Complexity
31744 \begin_inset LatexCommand \index{Cyclomatic complexity}
31745
31746 \end_inset
31747
31748
31749
31750 \layout Standard
31751 Cyclomatic complexity of a function is defined as the number of independent
31752  paths the program can take during execution of the function.
31753  This is an important number since it defines the number test cases you
31754  have to generate to validate the function.
31755  The accepted industry standard for complexity number is 10, if the cyclomatic
31756  complexity reported by SDCC exceeds 10 you should think about simplification
31757  of the function logic.
31758  Note that the complexity level is not related to the number of lines of
31759  code in a function.
31760  Large functions can have low complexity, and small functions can have large
31761  complexity levels.
31762  
31763 \newline
31764
31765 \newline
31766 SDCC uses the following formula to compute the complexity:
31767 \newline
31768
31769
31770 \layout Standard
31771 complexity = (number of edges in control flow graph) - (number of nodes
31772  in control flow graph) + 2;
31773 \newline
31774
31775 \newline
31776 Having said that the industry standard is 10,
31777  you should be aware that in some cases it be may unavoidable to have a
31778  complexity level of less than 10.
31779  For example if you have switch statement with more than 10 case labels,
31780  each case label adds one to the complexity level.
31781  The complexity level is by no means an absolute measure of the algorithmic
31782  complexity of the function, it does however provide a good starting point
31783  for which functions you might look at for further optimization.
31784
31785 \layout Section
31786 Retargetting for other Processors
31787
31788 \layout Standard
31789 The issues for retargetting the compiler are far too numerous to be covered
31790  by this document.
31791  What follows is a brief description of each of the seven phases of the
31792  compiler and its MCU dependency.
31793
31794 \layout Itemize
31795 Parsing the source and building the annotated parse tree.
31796  This phase is largely MCU independent (except for the language extensions).
31797  Syntax & semantic checks are also done in this phase, along with some initial
31798  optimizations like back patching labels and the pattern matching optimizations
31799  like bit-rotation etc.
31800
31801 \layout Itemize
31802 The second phase involves generating an intermediate code which can be easy
31803  manipulated during the later phases.
31804  This phase is entirely MCU independent.
31805  The intermediate code generation assumes the target machine has unlimited
31806  number of registers, and designates them with the name iTemp.
31807  The compiler can be made to dump a human readable form of the code generated
31808  by using the -
31809 \begin_inset ERT
31810 status Collapsed
31811
31812 \layout Standard
31813
31814
31815 \backslash
31816 /
31817
31818 \end_inset
31819
31820 -dumpraw option.
31821
31822 \layout Itemize
31823 This phase does the bulk of the standard optimizations and is also MCU independe
31824 nt.
31825  This phase can be broken down into several sub-phases:
31826 \newline
31827
31828 \newline
31829 Break down intermediate
31830  code (iCode) into basic blocks.
31831 \newline
31832 Do control flow & data flow analysis on the
31833  basic blocks.
31834 \newline
31835 Do local common subexpression elimination, then global subexpressio
31836 n elimination
31837 \newline
31838 Dead code elimination
31839 \newline
31840 Loop optimizations
31841 \newline
31842 If loop optimizations
31843  caused any changes then do 'global subexpression elimination' and 'dead
31844  code elimination' again.
31845
31846 \layout Itemize
31847 This phase determines the live-ranges; by live range I mean those iTemp
31848  variables defined by the compiler that still survive after all the optimization
31849 s.
31850  Live range analysis
31851 \begin_inset LatexCommand \index{Live range analysis}
31852
31853 \end_inset
31854
31855  is essential for register allocation, since these computation determines
31856  which of these iTemps will be assigned to registers, and for how long.
31857
31858 \layout Itemize
31859 Phase five is register allocation.
31860  There are two parts to this process.
31861 \newline
31862
31863 \newline
31864 The first part I call 'register packing'
31865  (for lack of a better term).
31866  In this case several MCU specific expression folding is done to reduce
31867  register pressure.
31868 \newline
31869
31870 \newline
31871 The second part is more MCU independent and deals with
31872  allocating registers to the remaining live ranges.
31873  A lot of MCU specific code does creep into this phase because of the limited
31874  number of index registers available in the 8051.
31875
31876 \layout Itemize
31877 The Code generation phase is (unhappily), entirely MCU dependent and very
31878  little (if any at all) of this code can be reused for other MCU.
31879  However the scheme for allocating a homogenized assembler operand for each
31880  iCode operand may be reused.
31881
31882 \layout Itemize
31883 As mentioned in the optimization section the peep-hole optimizer is rule
31884  based system, which can reprogrammed for other MCUs.
31885
31886 \layout Standard
31887 More information is available in a wiki
31888 \begin_inset LatexCommand \index{wiki}
31889
31890 \end_inset
31891
31892  (preliminary link 
31893 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
31894
31895 \end_inset
31896
31897 ) and in the thread 
31898 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
31899
31900 \end_inset
31901
31902  .
31903
31904 \layout Chapter
31905 Compiler internals
31906 \begin_inset LatexCommand \index{Compiler internals}
31907
31908 \end_inset
31909
31910
31911
31912 \layout Section
31913 The anatomy of the compiler
31914 \begin_inset LatexCommand \label{sub:The-anatomy-of}
31915
31916 \end_inset
31917
31918
31919
31920 \layout Standard
31921
31922 \shape italic
31923 This is an excerpt from an article published in Circuit Cellar Magazine
31924  in 
31925 \series bold
31926 August 2000
31927 \series default
31928 .
31929  It's a little outdated (the compiler is much more efficient now and user/develo
31930 per friendly), but pretty well exposes the guts of it all.
31931 \shape default
31932
31933 \newline
31934
31935 \newline
31936 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
31937  It is fairly easy to retarget for other 8-bit MCU.
31938  Here we take a look at some of the internals of the compiler.
31939  
31940
31941 \layout Paragraph*
31942 Parsing
31943 \begin_inset LatexCommand \index{Parsing}
31944
31945 \end_inset
31946
31947  
31948
31949 \layout Standard
31950 Parsing the input source file and creating an AST (Annotated Syntax Tree
31951 \begin_inset LatexCommand \index{Annotated syntax tree}
31952
31953 \end_inset
31954
31955 ).
31956  This phase also involves propagating types (annotating each node of the
31957  parse tree with type information) and semantic analysis.
31958  There are some MCU specific parsing rules.
31959  For example the storage classes, the extended storage classes are MCU specific
31960  while there may be a xdata storage class for 8051 there is no such storage
31961  class for z80 or Atmel AVR.
31962  SDCC allows MCU specific storage class extensions, i.e.
31963  xdata will be treated as a storage class specifier when parsing 8051 C
31964  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
31965  C code.
31966
31967 \layout Paragraph*
31968 Generating iCode
31969 \begin_inset LatexCommand \index{iCode}
31970
31971 \end_inset
31972
31973
31974
31975 \layout Standard
31976 Intermediate code generation.
31977  In this phase the AST is broken down into three-operand form (iCode).
31978  These three operand forms are represented as doubly linked lists.
31979  ICode is the term given to the intermediate form generated by the compiler.
31980  ICode example section shows some examples of iCode generated for some simple
31981  C source functions.
31982
31983 \layout Paragraph*
31984 Optimizations
31985 \begin_inset LatexCommand \index{Optimizations}
31986
31987 \end_inset
31988
31989 .
31990
31991 \layout Standard
31992 Bulk of the target independent optimizations is performed in this phase.
31993  The optimizations include constant propagation, common sub-expression eliminati
31994 on, loop invariant code movement, strength reduction of loop induction variables
31995  and dead-code elimination.
31996
31997 \layout Paragraph*
31998 Live range analysis
31999 \begin_inset LatexCommand \index{Live range analysis}
32000
32001 \end_inset
32002
32003
32004
32005 \layout Standard
32006 During intermediate code generation phase, the compiler assumes the target
32007  machine has infinite number of registers and generates a lot of temporary
32008  variables.
32009  The live range computation determines the lifetime of each of these compiler-ge
32010 nerated temporaries.
32011  A picture speaks a thousand words.
32012  ICode example sections show the live range annotations for each of the
32013  operand.
32014  It is important to note here, each iCode is assigned a number in the order
32015  of its execution in the function.
32016  The live ranges are computed in terms of these numbers.
32017  The from number is the number of the iCode which first defines the operand
32018  and the to number signifies the iCode which uses this operand last.
32019
32020 \layout Paragraph*
32021 Register Allocation
32022 \begin_inset LatexCommand \index{Register allocation}
32023
32024 \end_inset
32025
32026
32027
32028 \layout Standard
32029 The register allocation determines the type and number of registers needed
32030  by each operand.
32031  In most MCUs only a few registers can be used for indirect addressing.
32032  In case of 8051 for example the registers R0 & R1 can be used to indirectly
32033  address the internal ram and DPTR to indirectly address the external ram.
32034  The compiler will try to allocate the appropriate register to pointer variables
32035  if it can.
32036  ICode example section shows the operands annotated with the registers assigned
32037  to them.
32038  The compiler will try to keep operands in registers as much as possible;
32039  there are several schemes the compiler uses to do achieve this.
32040  When the compiler runs out of registers the compiler will check to see
32041  if there are any live operands which is not used or defined in the current
32042  basic block being processed, if there are any found then it will push that
32043  operand and use the registers in this block, the operand will then be popped
32044  at the end of the basic block.
32045  
32046
32047 \layout Standard
32048 There are other MCU specific considerations in this phase.
32049  Some MCUs have an accumulator; very short-lived operands could be assigned
32050  to the accumulator instead of a general-purpose register.
32051
32052 \layout Paragraph*
32053 Code generation
32054
32055 \layout Standard
32056 Figure II gives a table of iCode
32057 \begin_inset LatexCommand \index{iCode}
32058
32059 \end_inset
32060
32061  operations supported by the compiler.
32062  The code generation involves translating these operations into corresponding
32063  assembly code for the processor.
32064  This sounds overly simple but that is the essence of code generation.
32065  Some of the iCode operations are generated on a MCU specific manner for
32066  example, the z80 port does not use registers to pass parameters so the
32067  SEND and RECV iCode operations will not be generated, and it also does
32068  not support JUMPTABLES.
32069  
32070 \newline
32071
32072
32073 \layout Standard
32074
32075 \size footnotesize
32076 Figure II 
32077 \begin_inset Tabular
32078 <lyxtabular version="3" rows="39" columns="4">
32079 <features islongtable="true" headBottomDL="true">
32080 <column alignment="block" valignment="top" leftline="true" width="13col%">
32081 <column alignment="left" valignment="top" leftline="true" width="13col%">
32082 <column alignment="block" valignment="top" leftline="true" width="22col%">
32083 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
32084 <row topline="true" bottomline="true" endhead="true">
32085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32086 \begin_inset Text
32087
32088 \layout Standard
32089
32090 \series bold
32091 iCode
32092 \series default
32093
32094 \begin_inset LatexCommand \index{iCode}
32095
32096 \end_inset
32097
32098
32099
32100 \end_inset
32101 </cell>
32102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32103 \begin_inset Text
32104
32105 \layout Standard
32106
32107 \series bold
32108 Operands
32109
32110 \end_inset
32111 </cell>
32112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32113 \begin_inset Text
32114
32115 \layout Standard
32116
32117 \series bold
32118 Description
32119
32120 \end_inset
32121 </cell>
32122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32123 \begin_inset Text
32124
32125 \layout Standard
32126
32127 \series bold
32128 C Equivalent
32129
32130 \end_inset
32131 </cell>
32132 </row>
32133 <row topline="true">
32134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32135 \begin_inset Text
32136
32137 \layout Standard
32138
32139 \size footnotesize
32140 '!'
32141
32142 \end_inset
32143 </cell>
32144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32145 \begin_inset Text
32146
32147 \layout Standard
32148
32149 \size footnotesize
32150 IC_LEFT() IC_RESULT()
32151
32152 \end_inset
32153 </cell>
32154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32155 \begin_inset Text
32156
32157 \layout Standard
32158
32159 \size footnotesize
32160 NOT operation 
32161
32162 \end_inset
32163 </cell>
32164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32165 \begin_inset Text
32166
32167 \layout Standard
32168
32169 \size footnotesize
32170 IC_RESULT = ! IC_LEFT;
32171
32172 \end_inset
32173 </cell>
32174 </row>
32175 <row topline="true">
32176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32177 \begin_inset Text
32178
32179 \layout Standard
32180
32181 \size footnotesize
32182 '~'
32183
32184 \end_inset
32185 </cell>
32186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32187 \begin_inset Text
32188
32189 \layout Standard
32190
32191 \size footnotesize
32192 IC_LEFT() IC_RESULT()
32193
32194 \end_inset
32195 </cell>
32196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32197 \begin_inset Text
32198
32199 \layout Standard
32200
32201 \size footnotesize
32202 Bitwise complement of 
32203
32204 \end_inset
32205 </cell>
32206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32207 \begin_inset Text
32208
32209 \layout Standard
32210
32211 \size footnotesize
32212 IC_RESULT = ~IC_LEFT;
32213
32214 \end_inset
32215 </cell>
32216 </row>
32217 <row topline="true">
32218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32219 \begin_inset Text
32220
32221 \layout Standard
32222
32223 \size footnotesize
32224 RRC
32225
32226 \end_inset
32227 </cell>
32228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32229 \begin_inset Text
32230
32231 \layout Standard
32232
32233 \size footnotesize
32234 IC_LEFT() IC_RESULT()
32235
32236 \end_inset
32237 </cell>
32238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32239 \begin_inset Text
32240
32241 \layout Standard
32242
32243 \size footnotesize
32244 Rotate right with carry
32245
32246 \end_inset
32247 </cell>
32248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32249 \begin_inset Text
32250
32251 \layout Standard
32252
32253 \size footnotesize
32254 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
32255
32256 \end_inset
32257 </cell>
32258 </row>
32259 <row topline="true">
32260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32261 \begin_inset Text
32262
32263 \layout Standard
32264
32265 \size footnotesize
32266 RLC
32267
32268 \end_inset
32269 </cell>
32270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32271 \begin_inset Text
32272
32273 \layout Standard
32274
32275 \size footnotesize
32276 IC_LEFT() IC_RESULT()
32277
32278 \end_inset
32279 </cell>
32280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32281 \begin_inset Text
32282
32283 \layout Standard
32284
32285 \size footnotesize
32286 Rotate left with carry
32287
32288 \end_inset
32289 </cell>
32290 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32291 \begin_inset Text
32292
32293 \layout Standard
32294
32295 \size footnotesize
32296 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
32297
32298 \end_inset
32299 </cell>
32300 </row>
32301 <row topline="true">
32302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32303 \begin_inset Text
32304
32305 \layout Standard
32306
32307 \size footnotesize
32308 GETHBIT
32309
32310 \end_inset
32311 </cell>
32312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32313 \begin_inset Text
32314
32315 \layout Standard
32316
32317 \size footnotesize
32318 IC_LEFT() IC_RESULT()
32319
32320 \end_inset
32321 </cell>
32322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32323 \begin_inset Text
32324
32325 \layout Standard
32326
32327 \size footnotesize
32328 Get the highest order bit of IC_LEFT
32329
32330 \end_inset
32331 </cell>
32332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32333 \begin_inset Text
32334
32335 \layout Standard
32336
32337 \size footnotesize
32338 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
32339
32340 \end_inset
32341 </cell>
32342 </row>
32343 <row topline="true">
32344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32345 \begin_inset Text
32346
32347 \layout Standard
32348
32349 \size footnotesize
32350 UNARYMINUS
32351
32352 \end_inset
32353 </cell>
32354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32355 \begin_inset Text
32356
32357 \layout Standard
32358
32359 \size footnotesize
32360 IC_LEFT() IC_RESULT()
32361
32362 \end_inset
32363 </cell>
32364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32365 \begin_inset Text
32366
32367 \layout Standard
32368
32369 \size footnotesize
32370 Unary minus
32371
32372 \end_inset
32373 </cell>
32374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32375 \begin_inset Text
32376
32377 \layout Standard
32378
32379 \size footnotesize
32380 IC_RESULT = - IC_LEFT;
32381
32382 \end_inset
32383 </cell>
32384 </row>
32385 <row topline="true">
32386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32387 \begin_inset Text
32388
32389 \layout Standard
32390
32391 \size footnotesize
32392 IPUSH
32393
32394 \end_inset
32395 </cell>
32396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32397 \begin_inset Text
32398
32399 \layout Standard
32400
32401 \size footnotesize
32402 IC_LEFT()
32403
32404 \end_inset
32405 </cell>
32406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32407 \begin_inset Text
32408
32409 \layout Standard
32410
32411 \size footnotesize
32412 Push the operand into stack
32413
32414 \end_inset
32415 </cell>
32416 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32417 \begin_inset Text
32418
32419 \layout Standard
32420
32421 \size footnotesize
32422 NONE
32423
32424 \end_inset
32425 </cell>
32426 </row>
32427 <row topline="true">
32428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32429 \begin_inset Text
32430
32431 \layout Standard
32432
32433 \size footnotesize
32434 IPOP
32435
32436 \end_inset
32437 </cell>
32438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32439 \begin_inset Text
32440
32441 \layout Standard
32442
32443 \size footnotesize
32444 IC_LEFT()
32445
32446 \end_inset
32447 </cell>
32448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32449 \begin_inset Text
32450
32451 \layout Standard
32452
32453 \size footnotesize
32454 Pop the operand from the stack 
32455
32456 \end_inset
32457 </cell>
32458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32459 \begin_inset Text
32460
32461 \layout Standard
32462
32463 \size footnotesize
32464 NONE
32465
32466 \end_inset
32467 </cell>
32468 </row>
32469 <row topline="true">
32470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32471 \begin_inset Text
32472
32473 \layout Standard
32474
32475 \size footnotesize
32476 CALL
32477
32478 \end_inset
32479 </cell>
32480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32481 \begin_inset Text
32482
32483 \layout Standard
32484
32485 \size footnotesize
32486 IC_LEFT() IC_RESULT()
32487
32488 \end_inset
32489 </cell>
32490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32491 \begin_inset Text
32492
32493 \layout Standard
32494
32495 \size footnotesize
32496 Call the function represented by IC_LEFT 
32497
32498 \end_inset
32499 </cell>
32500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32501 \begin_inset Text
32502
32503 \layout Standard
32504
32505 \size footnotesize
32506 IC_RESULT = IC_LEFT();
32507
32508 \end_inset
32509 </cell>
32510 </row>
32511 <row topline="true">
32512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32513 \begin_inset Text
32514
32515 \layout Standard
32516
32517 \size footnotesize
32518 PCALL
32519
32520 \end_inset
32521 </cell>
32522 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32523 \begin_inset Text
32524
32525 \layout Standard
32526
32527 \size footnotesize
32528 IC_LEFT() IC_RESULT()
32529
32530 \end_inset
32531 </cell>
32532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32533 \begin_inset Text
32534
32535 \layout Standard
32536
32537 \size footnotesize
32538 Call via function pointer
32539
32540 \end_inset
32541 </cell>
32542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32543 \begin_inset Text
32544
32545 \layout Standard
32546
32547 \size footnotesize
32548 IC_RESULT = (*IC_LEFT)();
32549
32550 \end_inset
32551 </cell>
32552 </row>
32553 <row topline="true">
32554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32555 \begin_inset Text
32556
32557 \layout Standard
32558
32559 \size footnotesize
32560 RETURN
32561
32562 \end_inset
32563 </cell>
32564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32565 \begin_inset Text
32566
32567 \layout Standard
32568
32569 \size footnotesize
32570 IC_LEFT()
32571
32572 \end_inset
32573 </cell>
32574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32575 \begin_inset Text
32576
32577 \layout Standard
32578
32579 \size footnotesize
32580 Return the value in operand IC_LEFT 
32581
32582 \end_inset
32583 </cell>
32584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32585 \begin_inset Text
32586
32587 \layout Standard
32588
32589 \size footnotesize
32590 return IC_LEFT;
32591
32592 \end_inset
32593 </cell>
32594 </row>
32595 <row topline="true">
32596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32597 \begin_inset Text
32598
32599 \layout Standard
32600
32601 \size footnotesize
32602 LABEL
32603
32604 \end_inset
32605 </cell>
32606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32607 \begin_inset Text
32608
32609 \layout Standard
32610
32611 \size footnotesize
32612 IC_LABEL() 
32613
32614 \end_inset
32615 </cell>
32616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32617 \begin_inset Text
32618
32619 \layout Standard
32620
32621 \size footnotesize
32622 Label
32623
32624 \end_inset
32625 </cell>
32626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32627 \begin_inset Text
32628
32629 \layout Standard
32630
32631 \size footnotesize
32632 IC_LABEL:
32633
32634 \end_inset
32635 </cell>
32636 </row>
32637 <row topline="true">
32638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32639 \begin_inset Text
32640
32641 \layout Standard
32642
32643 \size footnotesize
32644 GOTO
32645
32646 \end_inset
32647 </cell>
32648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32649 \begin_inset Text
32650
32651 \layout Standard
32652
32653 \size footnotesize
32654 IC_LABEL() 
32655
32656 \end_inset
32657 </cell>
32658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32659 \begin_inset Text
32660
32661 \layout Standard
32662
32663 \size footnotesize
32664 Goto label
32665
32666 \end_inset
32667 </cell>
32668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32669 \begin_inset Text
32670
32671 \layout Standard
32672
32673 \size footnotesize
32674 goto IC_LABEL();
32675
32676 \end_inset
32677 </cell>
32678 </row>
32679 <row topline="true">
32680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32681 \begin_inset Text
32682
32683 \layout Standard
32684
32685 \size footnotesize
32686 '+'
32687
32688 \end_inset
32689 </cell>
32690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32691 \begin_inset Text
32692
32693 \layout Standard
32694
32695 \size footnotesize
32696 IC_LEFT() IC_RIGHT() IC_RESULT()
32697
32698 \end_inset
32699 </cell>
32700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32701 \begin_inset Text
32702
32703 \layout Standard
32704
32705 \size footnotesize
32706 Addition
32707
32708 \end_inset
32709 </cell>
32710 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32711 \begin_inset Text
32712
32713 \layout Standard
32714
32715 \size footnotesize
32716 IC_RESULT = IC_LEFT + IC_RIGHT
32717
32718 \end_inset
32719 </cell>
32720 </row>
32721 <row topline="true">
32722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32723 \begin_inset Text
32724
32725 \layout Standard
32726
32727 \size footnotesize
32728 '-'
32729
32730 \end_inset
32731 </cell>
32732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32733 \begin_inset Text
32734
32735 \layout Standard
32736
32737 \size footnotesize
32738 IC_LEFT() IC_RIGHT() IC_RESULT()
32739
32740 \end_inset
32741 </cell>
32742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32743 \begin_inset Text
32744
32745 \layout Standard
32746
32747 \size footnotesize
32748 Subtraction
32749
32750 \end_inset
32751 </cell>
32752 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32753 \begin_inset Text
32754
32755 \layout Standard
32756
32757 \size footnotesize
32758 IC_RESULT = IC_LEFT - IC_RIGHT 
32759
32760 \end_inset
32761 </cell>
32762 </row>
32763 <row topline="true">
32764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32765 \begin_inset Text
32766
32767 \layout Standard
32768
32769 \size footnotesize
32770 '*'
32771
32772 \end_inset
32773 </cell>
32774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32775 \begin_inset Text
32776
32777 \layout Standard
32778
32779 \size footnotesize
32780 IC_LEFT() IC_RIGHT() IC_RESULT()
32781
32782 \end_inset
32783 </cell>
32784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32785 \begin_inset Text
32786
32787 \layout Standard
32788
32789 \size footnotesize
32790 Multiplication 
32791
32792 \end_inset
32793 </cell>
32794 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32795 \begin_inset Text
32796
32797 \layout Standard
32798
32799 \size footnotesize
32800 IC_RESULT = IC_LEFT * IC_RIGHT;
32801
32802 \end_inset
32803 </cell>
32804 </row>
32805 <row topline="true">
32806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32807 \begin_inset Text
32808
32809 \layout Standard
32810
32811 \size footnotesize
32812 '/'
32813
32814 \end_inset
32815 </cell>
32816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32817 \begin_inset Text
32818
32819 \layout Standard
32820
32821 \size footnotesize
32822 IC_LEFT() IC_RIGHT() IC_RESULT()
32823
32824 \end_inset
32825 </cell>
32826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32827 \begin_inset Text
32828
32829 \layout Standard
32830
32831 \size footnotesize
32832 Division
32833
32834 \end_inset
32835 </cell>
32836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32837 \begin_inset Text
32838
32839 \layout Standard
32840
32841 \size footnotesize
32842 IC_RESULT = IC_LEFT / IC_RIGHT;
32843
32844 \end_inset
32845 </cell>
32846 </row>
32847 <row topline="true">
32848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32849 \begin_inset Text
32850
32851 \layout Standard
32852
32853 \size footnotesize
32854 '%'
32855
32856 \end_inset
32857 </cell>
32858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32859 \begin_inset Text
32860
32861 \layout Standard
32862
32863 \size footnotesize
32864 IC_LEFT() IC_RIGHT() IC_RESULT()
32865
32866 \end_inset
32867 </cell>
32868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32869 \begin_inset Text
32870
32871 \layout Standard
32872
32873 \size footnotesize
32874 Modulus
32875
32876 \end_inset
32877 </cell>
32878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32879 \begin_inset Text
32880
32881 \layout Standard
32882
32883 \size footnotesize
32884 IC_RESULT = IC_LEFT % IC_RIGHT;
32885
32886 \end_inset
32887 </cell>
32888 </row>
32889 <row topline="true">
32890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32891 \begin_inset Text
32892
32893 \layout Standard
32894
32895 \size footnotesize
32896 '<'
32897
32898 \end_inset
32899 </cell>
32900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32901 \begin_inset Text
32902
32903 \layout Standard
32904
32905 \size footnotesize
32906 IC_LEFT() IC_RIGHT() IC_RESULT()
32907
32908 \end_inset
32909 </cell>
32910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32911 \begin_inset Text
32912
32913 \layout Standard
32914
32915 \size footnotesize
32916 Less than
32917
32918 \end_inset
32919 </cell>
32920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32921 \begin_inset Text
32922
32923 \layout Standard
32924
32925 \size footnotesize
32926 IC_RESULT = IC_LEFT < IC_RIGHT;
32927
32928 \end_inset
32929 </cell>
32930 </row>
32931 <row topline="true">
32932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32933 \begin_inset Text
32934
32935 \layout Standard
32936
32937 \size footnotesize
32938 '>'
32939
32940 \end_inset
32941 </cell>
32942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32943 \begin_inset Text
32944
32945 \layout Standard
32946
32947 \size footnotesize
32948 IC_LEFT() IC_RIGHT() IC_RESULT()
32949
32950 \end_inset
32951 </cell>
32952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32953 \begin_inset Text
32954
32955 \layout Standard
32956
32957 \size footnotesize
32958 Greater than 
32959
32960 \end_inset
32961 </cell>
32962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32963 \begin_inset Text
32964
32965 \layout Standard
32966
32967 \size footnotesize
32968 IC_RESULT = IC_LEFT > IC_RIGHT;
32969
32970 \end_inset
32971 </cell>
32972 </row>
32973 <row topline="true">
32974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32975 \begin_inset Text
32976
32977 \layout Standard
32978
32979 \size footnotesize
32980 EQ_OP
32981
32982 \end_inset
32983 </cell>
32984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32985 \begin_inset Text
32986
32987 \layout Standard
32988
32989 \size footnotesize
32990 IC_LEFT() IC_RIGHT() IC_RESULT()
32991
32992 \end_inset
32993 </cell>
32994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32995 \begin_inset Text
32996
32997 \layout Standard
32998
32999 \size footnotesize
33000 Equal to 
33001
33002 \end_inset
33003 </cell>
33004 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33005 \begin_inset Text
33006
33007 \layout Standard
33008
33009 \size footnotesize
33010 IC_RESULT = IC_LEFT == IC_RIGHT;
33011
33012 \end_inset
33013 </cell>
33014 </row>
33015 <row topline="true">
33016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33017 \begin_inset Text
33018
33019 \layout Standard
33020
33021 \size footnotesize
33022 AND_OP
33023
33024 \end_inset
33025 </cell>
33026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33027 \begin_inset Text
33028
33029 \layout Standard
33030
33031 \size footnotesize
33032 IC_LEFT() IC_RIGHT() IC_RESULT() 
33033
33034 \end_inset
33035 </cell>
33036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33037 \begin_inset Text
33038
33039 \layout Standard
33040
33041 \size footnotesize
33042 Logical and operation
33043
33044 \end_inset
33045 </cell>
33046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33047 \begin_inset Text
33048
33049 \layout Standard
33050
33051 \size footnotesize
33052 IC_RESULT = IC_LEFT && IC_RIGHT; 
33053
33054 \end_inset
33055 </cell>
33056 </row>
33057 <row topline="true">
33058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33059 \begin_inset Text
33060
33061 \layout Standard
33062
33063 \size footnotesize
33064 OR_OP
33065
33066 \end_inset
33067 </cell>
33068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33069 \begin_inset Text
33070
33071 \layout Standard
33072
33073 \size footnotesize
33074 IC_LEFT() IC_RIGHT() IC_RESULT() 
33075
33076 \end_inset
33077 </cell>
33078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33079 \begin_inset Text
33080
33081 \layout Standard
33082
33083 \size footnotesize
33084 Logical or operation 
33085
33086 \end_inset
33087 </cell>
33088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33089 \begin_inset Text
33090
33091 \layout Standard
33092
33093 \size footnotesize
33094 IC_RESULT = IC_LEFT || IC_RIGHT; 
33095
33096 \end_inset
33097 </cell>
33098 </row>
33099 <row topline="true">
33100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33101 \begin_inset Text
33102
33103 \layout Standard
33104
33105 \size footnotesize
33106 '^'
33107
33108 \end_inset
33109 </cell>
33110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33111 \begin_inset Text
33112
33113 \layout Standard
33114
33115 \size footnotesize
33116 IC_LEFT() IC_RIGHT() IC_RESULT() 
33117
33118 \end_inset
33119 </cell>
33120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33121 \begin_inset Text
33122
33123 \layout Standard
33124
33125 \size footnotesize
33126 Exclusive OR
33127
33128 \end_inset
33129 </cell>
33130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33131 \begin_inset Text
33132
33133 \layout Standard
33134
33135 \size footnotesize
33136 IC_RESULT = IC_LEFT ^ IC_RIGHT;
33137
33138 \end_inset
33139 </cell>
33140 </row>
33141 <row topline="true">
33142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33143 \begin_inset Text
33144
33145 \layout Standard
33146
33147 \size footnotesize
33148 '|'
33149
33150 \end_inset
33151 </cell>
33152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33153 \begin_inset Text
33154
33155 \layout Standard
33156
33157 \size footnotesize
33158 IC_LEFT() IC_RIGHT() IC_RESULT() 
33159
33160 \end_inset
33161 </cell>
33162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33163 \begin_inset Text
33164
33165 \layout Standard
33166
33167 \size footnotesize
33168 Bitwise OR 
33169
33170 \end_inset
33171 </cell>
33172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33173 \begin_inset Text
33174
33175 \layout Standard
33176
33177 \size footnotesize
33178 IC_RESULT = IC_LEFT | IC_RIGHT;
33179
33180 \end_inset
33181 </cell>
33182 </row>
33183 <row topline="true">
33184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33185 \begin_inset Text
33186
33187 \layout Standard
33188
33189 \size footnotesize
33190 BITWISEAND
33191
33192 \end_inset
33193 </cell>
33194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33195 \begin_inset Text
33196
33197 \layout Standard
33198
33199 \size footnotesize
33200 IC_LEFT() IC_RIGHT() IC_RESULT()
33201
33202 \end_inset
33203 </cell>
33204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33205 \begin_inset Text
33206
33207 \layout Standard
33208
33209 \size footnotesize
33210 Bitwise AND 
33211
33212 \end_inset
33213 </cell>
33214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33215 \begin_inset Text
33216
33217 \layout Standard
33218
33219 \size footnotesize
33220 IC_RESULT = IC_LEFT & IC_RIGHT;
33221
33222 \end_inset
33223 </cell>
33224 </row>
33225 <row topline="true">
33226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33227 \begin_inset Text
33228
33229 \layout Standard
33230
33231 \size footnotesize
33232 LEFT_OP
33233
33234 \end_inset
33235 </cell>
33236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33237 \begin_inset Text
33238
33239 \layout Standard
33240
33241 \size footnotesize
33242 IC_LEFT() IC_RIGHT() IC_RESULT()
33243
33244 \end_inset
33245 </cell>
33246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33247 \begin_inset Text
33248
33249 \layout Standard
33250
33251 \size footnotesize
33252 Left shift 
33253
33254 \end_inset
33255 </cell>
33256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33257 \begin_inset Text
33258
33259 \layout Standard
33260
33261 \size footnotesize
33262 IC_RESULT = IC_LEFT << IC_RIGHT 
33263
33264 \end_inset
33265 </cell>
33266 </row>
33267 <row topline="true">
33268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33269 \begin_inset Text
33270
33271 \layout Standard
33272
33273 \size footnotesize
33274 RIGHT_OP
33275
33276 \end_inset
33277 </cell>
33278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33279 \begin_inset Text
33280
33281 \layout Standard
33282
33283 \size footnotesize
33284 IC_LEFT() IC_RIGHT() IC_RESULT()
33285
33286 \end_inset
33287 </cell>
33288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33289 \begin_inset Text
33290
33291 \layout Standard
33292
33293 \size footnotesize
33294 Right shift
33295
33296 \end_inset
33297 </cell>
33298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33299 \begin_inset Text
33300
33301 \layout Standard
33302
33303 \size footnotesize
33304 IC_RESULT = IC_LEFT >> IC_RIGHT 
33305
33306 \end_inset
33307 </cell>
33308 </row>
33309 <row topline="true">
33310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33311 \begin_inset Text
33312
33313 \layout Standard
33314
33315 \size footnotesize
33316 GET_VALUE_
33317 \newline
33318 AT_ ADDRESS
33319
33320 \end_inset
33321 </cell>
33322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33323 \begin_inset Text
33324
33325 \layout Standard
33326
33327 \size footnotesize
33328 IC_LEFT() IC_RESULT()
33329
33330 \end_inset
33331 </cell>
33332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33333 \begin_inset Text
33334
33335 \layout Standard
33336
33337 \size footnotesize
33338 Indirect fetch 
33339
33340 \end_inset
33341 </cell>
33342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33343 \begin_inset Text
33344
33345 \layout Standard
33346
33347 \size footnotesize
33348 IC_RESULT = (*IC_LEFT);
33349
33350 \end_inset
33351 </cell>
33352 </row>
33353 <row topline="true">
33354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33355 \begin_inset Text
33356
33357 \layout Standard
33358
33359 \size footnotesize
33360 POINTER_SET
33361
33362 \end_inset
33363 </cell>
33364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33365 \begin_inset Text
33366
33367 \layout Standard
33368
33369 \size footnotesize
33370 IC_RIGHT() IC_RESULT() 
33371
33372 \end_inset
33373 </cell>
33374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33375 \begin_inset Text
33376
33377 \layout Standard
33378
33379 \size footnotesize
33380 Indirect set
33381
33382 \end_inset
33383 </cell>
33384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33385 \begin_inset Text
33386
33387 \layout Standard
33388
33389 \size footnotesize
33390 (*IC_RESULT) = IC_RIGHT;
33391
33392 \end_inset
33393 </cell>
33394 </row>
33395 <row topline="true">
33396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33397 \begin_inset Text
33398
33399 \layout Standard
33400
33401 \size footnotesize
33402 '='
33403
33404 \end_inset
33405 </cell>
33406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33407 \begin_inset Text
33408
33409 \layout Standard
33410
33411 \size footnotesize
33412 IC_RIGHT() IC_RESULT()
33413
33414 \end_inset
33415 </cell>
33416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33417 \begin_inset Text
33418
33419 \layout Standard
33420
33421 \size footnotesize
33422 Assignment
33423
33424 \end_inset
33425 </cell>
33426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33427 \begin_inset Text
33428
33429 \layout Standard
33430
33431 \size footnotesize
33432 IC_RESULT = IC_RIGHT;
33433
33434 \end_inset
33435 </cell>
33436 </row>
33437 <row topline="true">
33438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33439 \begin_inset Text
33440
33441 \layout Standard
33442
33443 \size footnotesize
33444 IFX
33445
33446 \end_inset
33447 </cell>
33448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33449 \begin_inset Text
33450
33451 \layout Standard
33452
33453 \size footnotesize
33454 IC_COND IC_TRUE IC_LABEL
33455
33456 \end_inset
33457 </cell>
33458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33459 \begin_inset Text
33460
33461 \layout Standard
33462
33463 \size footnotesize
33464 Conditional jump.
33465  If true label is present then jump to true label if condition is true else
33466  jump to false label if condition is false 
33467
33468 \end_inset
33469 </cell>
33470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33471 \begin_inset Text
33472
33473 \layout Standard
33474
33475 \size footnotesize
33476 if (IC_COND) goto IC_TRUE; 
33477 \newline
33478 \SpecialChar ~
33479 \SpecialChar ~
33480 Or 
33481 \newline
33482 If (!IC_COND) goto IC_FALSE;
33483
33484 \end_inset
33485 </cell>
33486 </row>
33487 <row topline="true">
33488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33489 \begin_inset Text
33490
33491 \layout Standard
33492
33493 \size footnotesize
33494 ADDRESS_OF
33495
33496 \end_inset
33497 </cell>
33498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33499 \begin_inset Text
33500
33501 \layout Standard
33502
33503 \size footnotesize
33504 IC_LEFT() IC_RESULT()
33505
33506 \end_inset
33507 </cell>
33508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33509 \begin_inset Text
33510
33511 \layout Standard
33512
33513 \size footnotesize
33514 Address of 
33515
33516 \end_inset
33517 </cell>
33518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33519 \begin_inset Text
33520
33521 \layout Standard
33522
33523 \size footnotesize
33524 IC_RESULT = &IC_LEFT();
33525
33526 \end_inset
33527 </cell>
33528 </row>
33529 <row topline="true">
33530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33531 \begin_inset Text
33532
33533 \layout Standard
33534
33535 \size footnotesize
33536 JUMPTABLE
33537
33538 \end_inset
33539 </cell>
33540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33541 \begin_inset Text
33542
33543 \layout Standard
33544
33545 \size footnotesize
33546 IC_JTCOND IC_JTLABELS
33547
33548 \end_inset
33549 </cell>
33550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33551 \begin_inset Text
33552
33553 \layout Standard
33554
33555 \size footnotesize
33556 Jump to list of labels depending on the value of JTCOND
33557
33558 \end_inset
33559 </cell>
33560 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33561 \begin_inset Text
33562
33563 \layout Standard
33564
33565 \size footnotesize
33566 Switch statement
33567
33568 \end_inset
33569 </cell>
33570 </row>
33571 <row topline="true">
33572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33573 \begin_inset Text
33574
33575 \layout Standard
33576
33577 \size footnotesize
33578 CAST
33579
33580 \end_inset
33581 </cell>
33582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33583 \begin_inset Text
33584
33585 \layout Standard
33586
33587 \size footnotesize
33588 IC_RIGHT() IC_LEFT() IC_RESULT()
33589
33590 \end_inset
33591 </cell>
33592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33593 \begin_inset Text
33594
33595 \layout Standard
33596
33597 \size footnotesize
33598 Cast types 
33599
33600 \end_inset
33601 </cell>
33602 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33603 \begin_inset Text
33604
33605 \layout Standard
33606
33607 \size footnotesize
33608 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
33609
33610 \end_inset
33611 </cell>
33612 </row>
33613 <row topline="true">
33614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33615 \begin_inset Text
33616
33617 \layout Standard
33618
33619 \size footnotesize
33620 SEND
33621
33622 \end_inset
33623 </cell>
33624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33625 \begin_inset Text
33626
33627 \layout Standard
33628
33629 \size footnotesize
33630 IC_LEFT()
33631
33632 \end_inset
33633 </cell>
33634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33635 \begin_inset Text
33636
33637 \layout Standard
33638
33639 \size footnotesize
33640 This is used for passing parameters in registers; 
33641 \newline
33642 move IC_LEFT to the next
33643  available parameter register.
33644
33645 \end_inset
33646 </cell>
33647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33648 \begin_inset Text
33649
33650 \layout Standard
33651
33652 \size footnotesize
33653 None
33654
33655 \end_inset
33656 </cell>
33657 </row>
33658 <row topline="true">
33659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33660 \begin_inset Text
33661
33662 \layout Standard
33663
33664 \size footnotesize
33665 RECV
33666
33667 \end_inset
33668 </cell>
33669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33670 \begin_inset Text
33671
33672 \layout Standard
33673
33674 \size footnotesize
33675 IC_RESULT()
33676
33677 \end_inset
33678 </cell>
33679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33680 \begin_inset Text
33681
33682 \layout Standard
33683
33684 \size footnotesize
33685 This is used for receiving parameters passed in registers;
33686 \newline
33687 Move the values
33688  in the next parameter register to IC_RESULT 
33689
33690 \end_inset
33691 </cell>
33692 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33693 \begin_inset Text
33694
33695 \layout Standard
33696
33697 \size footnotesize
33698 None
33699
33700 \end_inset
33701 </cell>
33702 </row>
33703 <row topline="true" bottomline="true">
33704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33705 \begin_inset Text
33706
33707 \layout Standard
33708
33709 \shape slanted
33710 \size footnotesize
33711 (some more have been added)
33712
33713 \end_inset
33714 </cell>
33715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33716 \begin_inset Text
33717
33718 \layout Standard
33719
33720
33721 \end_inset
33722 </cell>
33723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33724 \begin_inset Text
33725
33726 \layout Standard
33727
33728
33729 \end_inset
33730 </cell>
33731 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33732 \begin_inset Text
33733
33734 \layout Standard
33735
33736 \shape slanted
33737 \size footnotesize
33738 see f.e.
33739  
33740 \family typewriter
33741 gen51Code()
33742 \family default
33743  in 
33744 \family typewriter
33745 src/mcs51/gen.c
33746
33747 \end_inset
33748 </cell>
33749 </row>
33750 </lyxtabular>
33751
33752 \end_inset
33753
33754
33755
33756 \layout Standard
33757 \begin_inset Note
33758 collapsed true
33759
33760 \layout Standard
33761 In the original article Figure II was announced to be downloadable on 
33762 \shape italic
33763 Circuit Cellar
33764 \shape default
33765 's web site.
33766  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
33767
33768 \end_inset
33769
33770
33771
33772 \layout Paragraph*
33773 ICode Example
33774 \begin_inset LatexCommand \index{iCode}
33775
33776 \end_inset
33777
33778
33779
33780 \layout Standard
33781 This section shows some details of iCode.
33782  The example C code does not do anything useful; it is used as an example
33783  to illustrate the intermediate code generated by the compiler.
33784
33785 \layout Verse
33786
33787 \family typewriter
33788 1.\SpecialChar ~
33789 xdata int * p;
33790 \newline
33791 2.\SpecialChar ~
33792 int gint;
33793 \newline
33794 3.\SpecialChar ~
33795 /* This function does nothing useful.
33796  It is used
33797 \newline
33798 4.\SpecialChar ~
33799 \SpecialChar ~
33800 \SpecialChar ~
33801 \SpecialChar ~
33802 for the purpose of explaining iCode */
33803 \newline
33804 5.\SpecialChar ~
33805 short function (data
33806  int *x)
33807 \newline
33808 6.\SpecialChar ~
33809 {
33810 \newline
33811 7.\SpecialChar ~
33812 \SpecialChar ~
33813 \SpecialChar ~
33814 short i=10; \SpecialChar ~
33815 \SpecialChar ~
33816 /* dead initialization eliminated */
33817 \newline
33818 8.\SpecialChar ~
33819 \SpecialChar ~
33820 \SpecialChar ~
33821 short sum=10;
33822  /* dead initialization eliminated */
33823 \newline
33824 9.\SpecialChar ~
33825 \SpecialChar ~
33826 \SpecialChar ~
33827 short mul;
33828 \newline
33829 10.\SpecialChar ~
33830 \SpecialChar ~
33831 int j ;
33832 \newline
33833 11.\SpecialChar ~
33834 \SpecialChar ~
33835 while (*x) *x++
33836  = *p++; 
33837 \newline
33838 12.\SpecialChar ~
33839 \SpecialChar ~
33840 \SpecialChar ~
33841 \SpecialChar ~
33842 sum = 0 ; 
33843 \newline
33844 13.\SpecialChar ~
33845 \SpecialChar ~
33846 mul = 0;
33847 \newline
33848 14.\SpecialChar ~
33849 \SpecialChar ~
33850 /* compiler detects i,j to be induction
33851  variables */
33852 \newline
33853 15.\SpecialChar ~
33854 \SpecialChar ~
33855 for (i = 0, j = 10 ; i < 10 ; i++, j
33856 \family default
33857 -
33858 \begin_inset ERT
33859 status Collapsed
33860
33861 \layout Standard
33862
33863
33864 \backslash
33865 /
33866
33867 \end_inset
33868
33869 -
33870 \family typewriter
33871 ) {
33872 \newline
33873 16.\SpecialChar ~
33874 \SpecialChar ~
33875 \SpecialChar ~
33876 \SpecialChar ~
33877 sum += i;
33878 \newline
33879 17.\SpecialChar ~
33880 \SpecialChar ~
33881 \SpecialChar ~
33882 \SpecialChar ~
33883 mul += i * 3; \SpecialChar ~
33884 \SpecialChar ~
33885 /* this multiplication remains */
33886 \newline
33887 18.\SpecialChar ~
33888 \SpecialChar ~
33889 \SpecialChar ~
33890 \SpecialChar ~
33891 gint +=
33892  j * 3;\SpecialChar ~
33893 \SpecialChar ~
33894 /* this multiplication changed to addition */
33895 \newline
33896 19.\SpecialChar ~
33897 \SpecialChar ~
33898 }
33899 \newline
33900 20.\SpecialChar ~
33901 \SpecialChar ~
33902 return sum+mul;
33903 \newline
33904 21.\SpecialChar ~
33905 }
33906
33907 \layout Standard
33908 In addition to the operands each iCode contains information about the filename
33909  and line it corresponds to in the source file.
33910  The first field in the listing should be interpreted as follows:
33911 \newline
33912
33913 \shape italic
33914 \size footnotesize
33915 Filename(linenumber: iCode Execution sequence number : ICode hash table
33916  key : loop depth of the iCode).
33917 \shape default
33918 \size default
33919
33920 \newline
33921 Then follows the human readable form of the ICode operation.
33922  Each operand of this triplet form can be of three basic types a) compiler
33923  generated temporary b) user defined variable c) a constant value.
33924  Note that local variables and parameters are replaced by compiler generated
33925  temporaries.
33926  Live ranges
33927 \begin_inset LatexCommand \index{Live range analysis}
33928
33929 \end_inset
33930
33931  are computed only for temporaries (i.e.
33932  live ranges are not computed for global variables).
33933  Registers
33934 \begin_inset LatexCommand \index{Register allocation}
33935
33936 \end_inset
33937
33938  are allocated for temporaries only.
33939  Operands are formatted in the following manner:
33940 \newline
33941
33942 \shape italic
33943 \size footnotesize
33944 Operand Name [lr live-from : live-to ] { type information } [ registers
33945  allocated ].
33946 \shape default
33947 \size default
33948
33949 \newline
33950 As mentioned earlier the live ranges are computed in terms of the execution
33951  sequence number of the iCodes, for example 
33952 \newline
33953 the iTemp0 is live from (i.e.
33954  first defined in iCode with execution sequence number 3, and is last used
33955  in the iCode with sequence number 5).
33956  For induction variables such as iTemp21 the live range computation extends
33957  the lifetime from the start to the end of the loop.
33958 \newline
33959 The register allocator
33960  used the live range information to allocate registers, the same registers
33961  may be used for different temporaries if their live ranges do not overlap,
33962  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
33963  ranges do not overlap.
33964  In addition the allocator also takes into consideration the type and usage
33965  of a temporary, for example itemp6 is a pointer to near space and is used
33966  as to fetch data from (i.e.
33967  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
33968  Some short lived temporaries are allocated to special registers which have
33969  meaning to the code generator e.g.
33970  iTemp13 is allocated to a pseudo register CC which tells the back end that
33971  the temporary is used only for a conditional jump the code generation makes
33972  use of this information to optimize a compare and jump ICode.
33973 \newline
33974 There are several
33975  loop optimizations
33976 \begin_inset LatexCommand \index{Loop optimization}
33977
33978 \end_inset
33979
33980  performed by the compiler.
33981  It can detect induction variables iTemp21(i) and iTemp23(j).
33982  Also note the compiler does selective strength reduction
33983 \begin_inset LatexCommand \index{Strength reduction}
33984
33985 \end_inset
33986
33987 , i.e.
33988  the multiplication of an induction variable in line 18 (gint = j * 3) is
33989  changed to addition, a new temporary iTemp17 is allocated and assigned
33990  a initial value, a constant 3 is then added for each iteration of the loop.
33991  The compiler does not change the multiplication
33992 \begin_inset LatexCommand \index{Multiplication}
33993
33994 \end_inset
33995
33996  in line 17 however since the processor does support an 8 * 8 bit multiplication.
33997 \newline
33998
33999 Note the dead code elimination
34000 \begin_inset LatexCommand \index{Dead-code elimination}
34001
34002 \end_inset
34003
34004  optimization eliminated the dead assignments in line 7 & 8 to I and sum
34005  respectively.
34006 \newline
34007
34008
34009 \layout Standard
34010
34011 \size footnotesize
34012 Sample.c (5:1:0:0) _entry($9) :
34013
34014 \layout Standard
34015
34016 \size footnotesize
34017 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
34018
34019 \layout Standard
34020
34021 \size footnotesize
34022 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
34023
34024 \layout Standard
34025
34026 \size footnotesize
34027 Sample.c(11:4:53:0) preHeaderLbl0($11) :
34028
34029 \layout Standard
34030
34031 \size footnotesize
34032 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
34033  * int}[r2]
34034
34035 \layout Standard
34036
34037 \size footnotesize
34038 Sample.c(11:6:5:1) _whilecontinue_0($1) :
34039
34040 \layout Standard
34041
34042 \size footnotesize
34043 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
34044  int}[r0]]
34045
34046 \layout Standard
34047
34048 \size footnotesize
34049 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
34050
34051 \layout Standard
34052
34053 \size footnotesize
34054 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
34055  * int}
34056
34057 \layout Standard
34058
34059 \size footnotesize
34060 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
34061  {short}
34062
34063 \layout Standard
34064
34065 \size footnotesize
34066 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
34067  * int}[DPTR]]
34068
34069 \layout Standard
34070
34071 \size footnotesize
34072 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
34073 }[r2 r3]
34074
34075 \layout Standard
34076
34077 \size footnotesize
34078 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
34079  * int}[r0] + 0x2 {short}
34080
34081 \layout Standard
34082
34083 \size footnotesize
34084 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
34085
34086 \layout Standard
34087
34088 \size footnotesize
34089 Sample.c(11:17:21:0)_whilebreak_0($3) :
34090
34091 \layout Standard
34092
34093 \size footnotesize
34094 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
34095
34096 \layout Standard
34097
34098 \size footnotesize
34099 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
34100
34101 \layout Standard
34102
34103 \size footnotesize
34104 Sample.c(15:20:54:0)preHeaderLbl1($13) :
34105
34106 \layout Standard
34107
34108 \size footnotesize
34109 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
34110
34111 \layout Standard
34112
34113 \size footnotesize
34114 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
34115
34116 \layout Standard
34117
34118 \size footnotesize
34119 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
34120
34121 \layout Standard
34122
34123 \size footnotesize
34124 Sample.c(15:24:26:1)_forcond_0($4) :
34125
34126 \layout Standard
34127
34128 \size footnotesize
34129 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
34130  < 0xa {short}
34131
34132 \layout Standard
34133
34134 \size footnotesize
34135 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
34136
34137 \layout Standard
34138
34139 \size footnotesize
34140 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
34141  + ITemp21 [lr21:38]{short}[r4]
34142
34143 \layout Standard
34144
34145 \size footnotesize
34146 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
34147  * 0x3 {short}
34148
34149 \layout Standard
34150
34151 \size footnotesize
34152 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
34153  + iTemp15 [lr29:30]{short}[r1]
34154
34155 \layout Standard
34156
34157 \size footnotesize
34158 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
34159  r0]- 0x3 {short}
34160
34161 \layout Standard
34162
34163 \size footnotesize
34164 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
34165 int}[r7 r0]
34166
34167 \layout Standard
34168
34169 \size footnotesize
34170 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
34171  + 0x1 {short}
34172
34173 \layout Standard
34174
34175 \size footnotesize
34176 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
34177  r6]- 0x1 {short}
34178
34179 \layout Standard
34180
34181 \size footnotesize
34182 Sample.c(19:38:47:1) goto _forcond_0($4)
34183
34184 \layout Standard
34185
34186 \size footnotesize
34187 Sample.c(19:39:48:0)_forbreak_0($7) :
34188
34189 \layout Standard
34190
34191 \size footnotesize
34192 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
34193  + ITemp11 [lr19:40]{short}[r3]
34194
34195 \layout Standard
34196
34197 \size footnotesize
34198 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
34199
34200 \layout Standard
34201
34202 \size footnotesize
34203 Sample.c(20:42:51:0)_return($8) :
34204
34205 \layout Standard
34206
34207 \size footnotesize
34208 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
34209 \size default
34210
34211 \newline
34212
34213 \newline
34214 Finally the code generated for this function:
34215 \newline
34216
34217
34218 \layout Standard
34219
34220 \size footnotesize
34221 .area DSEG (DATA)
34222
34223 \layout Standard
34224
34225 \size footnotesize
34226 _p::
34227
34228 \layout Standard
34229
34230 \size footnotesize
34231 \SpecialChar ~
34232 \SpecialChar ~
34233 .ds 2
34234
34235 \layout Standard
34236
34237 \size footnotesize
34238 _gint::
34239
34240 \layout Standard
34241
34242 \size footnotesize
34243 \SpecialChar ~
34244 \SpecialChar ~
34245 .ds 2
34246
34247 \layout Standard
34248
34249 \size footnotesize
34250 ; sample.c 5
34251
34252 \layout Standard
34253
34254 \size footnotesize
34255 ; ----------------------------------------------
34256
34257 \layout Standard
34258
34259 \size footnotesize
34260 ; function function
34261
34262 \layout Standard
34263
34264 \size footnotesize
34265 ; ----------------------------------------------
34266
34267 \layout Standard
34268
34269 \size footnotesize
34270 _function:
34271
34272 \layout Standard
34273
34274 \size footnotesize
34275 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
34276
34277 \layout Standard
34278
34279 \size footnotesize
34280 \SpecialChar ~
34281 \SpecialChar ~
34282 mov r2,dpl
34283
34284 \layout Standard
34285
34286 \size footnotesize
34287 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
34288
34289 \layout Standard
34290
34291 \size footnotesize
34292 \SpecialChar ~
34293 \SpecialChar ~
34294 mov ar0,r2
34295
34296 \layout Standard
34297
34298 \size footnotesize
34299 ;_whilecontinue_0($1) :
34300
34301 \layout Standard
34302
34303 \size footnotesize
34304 00101$:
34305
34306 \layout Standard
34307
34308 \size footnotesize
34309 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
34310
34311 \layout Standard
34312
34313 \size footnotesize
34314 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
34315
34316 \layout Standard
34317
34318 \size footnotesize
34319 \SpecialChar ~
34320 \SpecialChar ~
34321 mov ar2,@r0
34322
34323 \layout Standard
34324
34325 \size footnotesize
34326 \SpecialChar ~
34327 \SpecialChar ~
34328 inc r0
34329
34330 \layout Standard
34331
34332 \size footnotesize
34333 \SpecialChar ~
34334 \SpecialChar ~
34335 mov ar3,@r0
34336
34337 \layout Standard
34338
34339 \size footnotesize
34340 \SpecialChar ~
34341 \SpecialChar ~
34342 dec r0
34343
34344 \layout Standard
34345
34346 \size footnotesize
34347 \SpecialChar ~
34348 \SpecialChar ~
34349 mov a,r2
34350
34351 \layout Standard
34352
34353 \size footnotesize
34354 \SpecialChar ~
34355 \SpecialChar ~
34356 orl a,r3
34357
34358 \layout Standard
34359
34360 \size footnotesize
34361 \SpecialChar ~
34362 \SpecialChar ~
34363 jz 00103$
34364
34365 \layout Standard
34366
34367 \size footnotesize
34368 00114$:
34369
34370 \layout Standard
34371
34372 \size footnotesize
34373 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
34374
34375 \layout Standard
34376
34377 \size footnotesize
34378 \SpecialChar ~
34379 \SpecialChar ~
34380 mov dpl,_p
34381
34382 \layout Standard
34383
34384 \size footnotesize
34385 \SpecialChar ~
34386 \SpecialChar ~
34387 mov dph,(_p + 1)
34388
34389 \layout Standard
34390
34391 \size footnotesize
34392 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
34393
34394 \layout Standard
34395
34396 \size footnotesize
34397 \SpecialChar ~
34398 \SpecialChar ~
34399 mov a,#0x02
34400
34401 \layout Standard
34402
34403 \size footnotesize
34404 \SpecialChar ~
34405 \SpecialChar ~
34406 add a,_p
34407
34408 \layout Standard
34409
34410 \size footnotesize
34411 \SpecialChar ~
34412 \SpecialChar ~
34413 mov _p,a
34414
34415 \layout Standard
34416
34417 \size footnotesize
34418 \SpecialChar ~
34419 \SpecialChar ~
34420 clr a
34421
34422 \layout Standard
34423
34424 \size footnotesize
34425 \SpecialChar ~
34426 \SpecialChar ~
34427 addc a,(_p + 1)
34428
34429 \layout Standard
34430
34431 \size footnotesize
34432 \SpecialChar ~
34433 \SpecialChar ~
34434 mov (_p + 1),a
34435
34436 \layout Standard
34437
34438 \size footnotesize
34439 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
34440
34441 \layout Standard
34442
34443 \size footnotesize
34444 \SpecialChar ~
34445 \SpecialChar ~
34446 movx a,@dptr
34447
34448 \layout Standard
34449
34450 \size footnotesize
34451 \SpecialChar ~
34452 \SpecialChar ~
34453 mov r2,a
34454
34455 \layout Standard
34456
34457 \size footnotesize
34458 \SpecialChar ~
34459 \SpecialChar ~
34460 inc dptr
34461
34462 \layout Standard
34463
34464 \size footnotesize
34465 \SpecialChar ~
34466 \SpecialChar ~
34467 movx a,@dptr
34468
34469 \layout Standard
34470
34471 \size footnotesize
34472 \SpecialChar ~
34473 \SpecialChar ~
34474 mov r3,a
34475
34476 \layout Standard
34477
34478 \size footnotesize
34479 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
34480
34481 \layout Standard
34482
34483 \size footnotesize
34484 \SpecialChar ~
34485 \SpecialChar ~
34486 mov @r0,ar2
34487
34488 \layout Standard
34489
34490 \size footnotesize
34491 \SpecialChar ~
34492 \SpecialChar ~
34493 inc r0
34494
34495 \layout Standard
34496
34497 \size footnotesize
34498 \SpecialChar ~
34499 \SpecialChar ~
34500 mov @r0,ar3
34501
34502 \layout Standard
34503
34504 \size footnotesize
34505 ; iTemp6 [lr5:16]{_near * int}[r0] = 
34506
34507 \layout Standard
34508
34509 \size footnotesize
34510 ; iTemp6 [lr5:16]{_near * int}[r0] + 
34511
34512 \layout Standard
34513
34514 \size footnotesize
34515 ; 0x2 {short}
34516
34517 \layout Standard
34518
34519 \size footnotesize
34520 \SpecialChar ~
34521 \SpecialChar ~
34522 inc r0
34523
34524 \layout Standard
34525
34526 \size footnotesize
34527 ; goto _whilecontinue_0($1)
34528
34529 \layout Standard
34530
34531 \size footnotesize
34532 \SpecialChar ~
34533 \SpecialChar ~
34534 sjmp 00101$
34535
34536 \layout Standard
34537
34538 \size footnotesize
34539 ; _whilebreak_0($3) :
34540
34541 \layout Standard
34542
34543 \size footnotesize
34544 00103$:
34545
34546 \layout Standard
34547
34548 \size footnotesize
34549 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
34550
34551 \layout Standard
34552
34553 \size footnotesize
34554 \SpecialChar ~
34555 \SpecialChar ~
34556 mov r2,#0x00
34557
34558 \layout Standard
34559
34560 \size footnotesize
34561 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
34562
34563 \layout Standard
34564
34565 \size footnotesize
34566 \SpecialChar ~
34567 \SpecialChar ~
34568 mov r3,#0x00
34569
34570 \layout Standard
34571
34572 \size footnotesize
34573 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
34574
34575 \layout Standard
34576
34577 \size footnotesize
34578 \SpecialChar ~
34579 \SpecialChar ~
34580 mov r4,#0x00
34581
34582 \layout Standard
34583
34584 \size footnotesize
34585 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
34586
34587 \layout Standard
34588
34589 \size footnotesize
34590 \SpecialChar ~
34591 \SpecialChar ~
34592 mov r5,#0x0A
34593
34594 \layout Standard
34595
34596 \size footnotesize
34597 \SpecialChar ~
34598 \SpecialChar ~
34599 mov r6,#0x00
34600
34601 \layout Standard
34602
34603 \size footnotesize
34604 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
34605
34606 \layout Standard
34607
34608 \size footnotesize
34609 \SpecialChar ~
34610 \SpecialChar ~
34611 mov r7,#0x1E
34612
34613 \layout Standard
34614
34615 \size footnotesize
34616 \SpecialChar ~
34617 \SpecialChar ~
34618 mov r0,#0x00
34619
34620 \layout Standard
34621
34622 \size footnotesize
34623 ; _forcond_0($4) :
34624
34625 \layout Standard
34626
34627 \size footnotesize
34628 00104$:
34629
34630 \layout Standard
34631
34632 \size footnotesize
34633 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
34634
34635 \layout Standard
34636
34637 \size footnotesize
34638 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
34639
34640 \layout Standard
34641
34642 \size footnotesize
34643 \SpecialChar ~
34644 \SpecialChar ~
34645 clr c
34646
34647 \layout Standard
34648
34649 \size footnotesize
34650 \SpecialChar ~
34651 \SpecialChar ~
34652 mov a,r4
34653
34654 \layout Standard
34655
34656 \size footnotesize
34657 \SpecialChar ~
34658 \SpecialChar ~
34659 xrl a,#0x80
34660
34661 \layout Standard
34662
34663 \size footnotesize
34664 \SpecialChar ~
34665 \SpecialChar ~
34666 subb a,#0x8a
34667
34668 \layout Standard
34669
34670 \size footnotesize
34671 \SpecialChar ~
34672 \SpecialChar ~
34673 jnc 00107$
34674
34675 \layout Standard
34676
34677 \size footnotesize
34678 00115$:
34679
34680 \layout Standard
34681
34682 \size footnotesize
34683 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
34684
34685 \layout Standard
34686
34687 \size footnotesize
34688 ; iTemp21 [lr21:38]{short}[r4]
34689
34690 \layout Standard
34691
34692 \size footnotesize
34693 \SpecialChar ~
34694 \SpecialChar ~
34695 mov a,r4
34696
34697 \layout Standard
34698
34699 \size footnotesize
34700 \SpecialChar ~
34701 \SpecialChar ~
34702 add a,r2
34703
34704 \layout Standard
34705
34706 \size footnotesize
34707 \SpecialChar ~
34708 \SpecialChar ~
34709 mov r2,a
34710
34711 \layout Standard
34712
34713 \size footnotesize
34714 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
34715
34716 \layout Standard
34717
34718 \size footnotesize
34719 \SpecialChar ~
34720 \SpecialChar ~
34721 mov b,#0x03
34722
34723 \layout Standard
34724
34725 \size footnotesize
34726 \SpecialChar ~
34727 \SpecialChar ~
34728 mov a,r4
34729
34730 \layout Standard
34731
34732 \size footnotesize
34733 \SpecialChar ~
34734 \SpecialChar ~
34735 mul ab
34736
34737 \layout Standard
34738
34739 \size footnotesize
34740 \SpecialChar ~
34741 \SpecialChar ~
34742 mov r1,a
34743
34744 \layout Standard
34745
34746 \size footnotesize
34747 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
34748
34749 \layout Standard
34750
34751 \size footnotesize
34752 ; iTemp15 [lr29:30]{short}[r1]
34753
34754 \layout Standard
34755
34756 \size footnotesize
34757 \SpecialChar ~
34758 \SpecialChar ~
34759 add a,r3
34760
34761 \layout Standard
34762
34763 \size footnotesize
34764 \SpecialChar ~
34765 \SpecialChar ~
34766 mov r3,a
34767
34768 \layout Standard
34769
34770 \size footnotesize
34771 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
34772
34773 \layout Standard
34774
34775 \size footnotesize
34776 \SpecialChar ~
34777 \SpecialChar ~
34778 mov a,r7
34779
34780 \layout Standard
34781
34782 \size footnotesize
34783 \SpecialChar ~
34784 \SpecialChar ~
34785 add a,#0xfd
34786
34787 \layout Standard
34788
34789 \size footnotesize
34790 \SpecialChar ~
34791 \SpecialChar ~
34792 mov r7,a
34793
34794 \layout Standard
34795
34796 \size footnotesize
34797 \SpecialChar ~
34798 \SpecialChar ~
34799 mov a,r0
34800
34801 \layout Standard
34802
34803 \size footnotesize
34804 \SpecialChar ~
34805 \SpecialChar ~
34806 addc a,#0xff
34807
34808 \layout Standard
34809
34810 \size footnotesize
34811 \SpecialChar ~
34812 \SpecialChar ~
34813 mov r0,a
34814
34815 \layout Standard
34816
34817 \size footnotesize
34818 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
34819
34820 \layout Standard
34821
34822 \size footnotesize
34823 \SpecialChar ~
34824 \SpecialChar ~
34825 mov a,r7
34826
34827 \layout Standard
34828
34829 \size footnotesize
34830 \SpecialChar ~
34831 \SpecialChar ~
34832 add a,_gint
34833
34834 \layout Standard
34835
34836 \size footnotesize
34837 \SpecialChar ~
34838 \SpecialChar ~
34839 mov _gint,a
34840
34841 \layout Standard
34842
34843 \size footnotesize
34844 \SpecialChar ~
34845 \SpecialChar ~
34846 mov a,r0
34847
34848 \layout Standard
34849
34850 \size footnotesize
34851 \SpecialChar ~
34852 \SpecialChar ~
34853 addc a,(_gint + 1)
34854
34855 \layout Standard
34856
34857 \size footnotesize
34858 \SpecialChar ~
34859 \SpecialChar ~
34860 mov (_gint + 1),a
34861
34862 \layout Standard
34863
34864 \size footnotesize
34865 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
34866
34867 \layout Standard
34868
34869 \size footnotesize
34870 \SpecialChar ~
34871 \SpecialChar ~
34872 inc r4
34873
34874 \layout Standard
34875
34876 \size footnotesize
34877 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
34878
34879 \layout Standard
34880
34881 \size footnotesize
34882 \SpecialChar ~
34883 \SpecialChar ~
34884 dec r5
34885
34886 \layout Standard
34887
34888 \size footnotesize
34889 \SpecialChar ~
34890 \SpecialChar ~
34891 cjne r5,#0xff,00104$
34892
34893 \layout Standard
34894
34895 \size footnotesize
34896 \SpecialChar ~
34897 \SpecialChar ~
34898 dec r6
34899
34900 \layout Standard
34901
34902 \size footnotesize
34903 ; goto _forcond_0($4)
34904
34905 \layout Standard
34906
34907 \size footnotesize
34908 \SpecialChar ~
34909 \SpecialChar ~
34910 sjmp 00104$
34911
34912 \layout Standard
34913
34914 \size footnotesize
34915 ; _forbreak_0($7) :
34916
34917 \layout Standard
34918
34919 \size footnotesize
34920 00107$:
34921
34922 \layout Standard
34923
34924 \size footnotesize
34925 ; ret iTemp24 [lr40:41]{short}
34926
34927 \layout Standard
34928
34929 \size footnotesize
34930 \SpecialChar ~
34931 \SpecialChar ~
34932 mov a,r3
34933
34934 \layout Standard
34935
34936 \size footnotesize
34937 \SpecialChar ~
34938 \SpecialChar ~
34939 add a,r2
34940
34941 \layout Standard
34942
34943 \size footnotesize
34944 \SpecialChar ~
34945 \SpecialChar ~
34946 mov dpl,a
34947
34948 \layout Standard
34949
34950 \size footnotesize
34951 ; _return($8) :
34952
34953 \layout Standard
34954
34955 \size footnotesize
34956 00108$:
34957
34958 \layout Standard
34959
34960 \size footnotesize
34961 \SpecialChar ~
34962 \SpecialChar ~
34963 ret
34964 \newline
34965
34966
34967 \layout Section
34968 A few words about basic block successors, predecessors and dominators
34969
34970 \layout Standard
34971 Successors are basic blocks
34972 \begin_inset LatexCommand \index{Basic blocks}
34973
34974 \end_inset
34975
34976  that might execute after this basic block.
34977 \newline
34978 Predecessors are basic blocks
34979  that might execute before reaching this basic block.
34980 \newline
34981 Dominators are basic
34982  blocks that WILL execute before reaching this basic block.
34983 \newline
34984
34985
34986 \layout Standard
34987 [basic block 1]
34988
34989 \layout Standard
34990 if (something)
34991
34992 \layout Standard
34993 \SpecialChar ~
34994 \SpecialChar ~
34995 \SpecialChar ~
34996 \SpecialChar ~
34997 [basic block 2]
34998
34999 \layout Standard
35000 else
35001
35002 \layout Standard
35003 \SpecialChar ~
35004 \SpecialChar ~
35005 \SpecialChar ~
35006 \SpecialChar ~
35007 [basic block 3]
35008
35009 \layout Standard
35010 [basic block 4]
35011 \newline
35012
35013
35014 \layout Standard
35015 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
35016
35017 \layout Standard
35018 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
35019
35020 \layout Standard
35021 c) domVect of [BB4] = BB1 ...
35022  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
35023  was executed.
35024
35025 \layout Chapter
35026 Acknowledgments
35027
35028 \layout Standard
35029 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
35030
35031 \end_inset
35032
35033
35034 \newline
35035
35036 \newline
35037
35038 \emph on
35039 Thanks to all the other volunteer developers who have helped with coding,
35040  testing, web-page creation, distribution sets, etc.
35041  You know who you are :-)
35042 \emph default
35043
35044 \newline
35045
35046 \newline
35047
35048 \emph on
35049 Also thanks to Sourceforge 
35050 \begin_inset LatexCommand \url{http://www.sf.net}
35051
35052 \end_inset
35053
35054  which has hosted the project since 1999 and donates significant download
35055  bandwidth and probably more than 
35056 \begin_inset ERT
35057 status Collapsed
35058
35059 \layout Standard
35060
35061 $10^{13}$
35062
35063 \end_inset
35064
35065 CPU cycles per day.
35066 \newline
35067  
35068 \begin_inset Note
35069 collapsed false
35070
35071 \layout Standard
35072 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
35073  minutes for (configure+make+regression test), and there is (i386, amd64,
35074  alpha, ppc64, (mingw32), sparc, macosx).
35075  
35076
35077 \end_inset
35078
35079
35080
35081 \layout Standard
35082 This document was initially written by Sandeep Dutta
35083
35084 \layout Standard
35085 All product names mentioned herein may be trademarks
35086 \begin_inset LatexCommand \index{Trademarks}
35087
35088 \end_inset
35089
35090  of their respective companies.
35091  
35092
35093 \layout Section*
35094 Alphabetical index
35095
35096 \layout Standard
35097 To avoid confusion, the installation and building options for SDCC itself
35098  (chapter 2) are not part of the index.
35099
35100 \layout Standard
35101 \begin_inset LatexCommand \printindex{}
35102
35103 \end_inset
35104
35105
35106
35107 \the_end