* device/lib/mcs51/crtcall.asm: new, added for indirect calls
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.3 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 \paperpackage a4
29 \use_geometry 1
30 \use_amsmath 0
31 \use_natbib 0
32 \use_numerical_citations 0
33 \paperorientation portrait
34 \leftmargin 30mm
35 \topmargin 20mm
36 \rightmargin 25mm
37 \bottommargin 20mm
38 \secnumdepth 3
39 \tocdepth 3
40 \paragraph_separation indent
41 \defskip medskip
42 \quotes_language swedish
43 \quotes_times 2
44 \papercolumns 1
45 \papersides 1
46 \paperpagestyle fancy
47
48 \layout Standard
49
50
51 \begin_inset Note
52 collapsed true
53
54 \layout Standard
55
56 Please note: double dashed longoptions (e.g.
57  --version) are written this way: -
58 \begin_inset ERT
59 status Collapsed
60
61 \layout Standard
62
63 \backslash 
64 /
65 \end_inset 
66
67 -
68 \layout Standard
69
70 Two resp.
71  three consecutive dashes simply result in a long resp.
72  extra long dash.
73 \layout Standard
74
75 Architecture specific stuff (like memory models, code examples) should maybe
76  later go
77 \layout Standard
78
79 into seperate sections/chapters/appendices (it is hard to document PIC or
80  Z80 in 
81 \layout Standard
82
83 a 8051 centered document) - for now simply add.
84 \end_inset 
85
86
87 \layout Title
88
89 SDCC Compiler User Guide
90 \layout Date
91
92
93 \size normal 
94 SDCC 2.6.4
95 \size footnotesize 
96
97 \newline 
98 $Date$ 
99 \newline 
100 $Revision$
101 \layout Standard
102
103
104 \begin_inset Note
105 collapsed true
106
107 \layout Standard
108
109 The above strings enclosed in $ are automatically updated by Subversion
110 \end_inset 
111
112
113 \layout Standard
114
115
116 \begin_inset LatexCommand \tableofcontents{}
117
118 \end_inset 
119
120
121 \layout Chapter
122
123 Introduction
124 \layout Section
125
126 About SDCC
127 \layout Standard
128
129
130 \series bold 
131 SDCC
132 \series default 
133  (
134 \emph on 
135 S
136 \emph default 
137 mall 
138 \emph on 
139 D
140 \emph default 
141 evice 
142 \emph on 
143 C
144 \emph default 
145  
146 \emph on 
147 C
148 \emph default 
149 ompiler) is an open source, retargettable, optimizing ANSI-C compiler by
150  
151 \series bold 
152 Sandeep Dutta
153 \series default 
154  designed for 8 bit Microprocessors.
155  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
156  8051, 8052
157 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
158
159 \end_inset 
160
161 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
162  Zilog Z80 based MCUs.
163  It can be retargeted for other microprocessors, support for Microchip PIC,
164  Atmel AVR is under development.
165  The entire source code for the compiler is distributed under GPL.
166  SDCC uses ASXXXX
167 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
168
169 \end_inset 
170
171  & ASLINK
172 \begin_inset LatexCommand \index{aslink}
173
174 \end_inset 
175
176 , an open source retargetable assembler & linker.
177  SDCC has extensive language extensions suitable for utilizing various microcont
178 rollers and underlying hardware effectively.
179  
180 \newline 
181
182 \newline 
183 In addition to the MCU specific optimizations SDCC also does a host of standard
184  optimizations like:
185 \layout Itemize
186
187 global sub expression elimination, 
188 \layout Itemize
189
190 loop optimizations (loop invariant, strength reduction of induction variables
191  and loop reversing), 
192 \layout Itemize
193
194 constant folding & propagation, 
195 \layout Itemize
196
197 copy propagation, 
198 \layout Itemize
199
200 dead code elimination 
201 \layout Itemize
202
203 jump tables for 
204 \emph on 
205 switch
206 \emph default 
207  statements.
208 \layout Standard
209
210 For the back-end SDCC uses a global register allocation scheme which should
211  be well suited for other 8 bit MCUs.
212  
213 \newline 
214
215 \newline 
216 The peep hole optimizer uses a rule based substitution mechanism which is
217  MCU independent.
218  
219 \newline 
220
221 \newline 
222 Supported data-types are:
223 \layout Standard
224
225
226 \begin_inset  Tabular
227 <lyxtabular version="3" rows="8" columns="5">
228 <features>
229 <column alignment="center" valignment="top" leftline="true" width="0">
230 <column alignment="center" valignment="top" leftline="true" width="0">
231 <column alignment="center" valignment="top" leftline="true" width="0">
232 <column alignment="center" valignment="top" leftline="true" width="0">
233 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
234 <row topline="true" bottomline="true">
235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
236 \begin_inset Text
237
238 \layout Standard
239
240 type
241 \end_inset 
242 </cell>
243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
244 \begin_inset Text
245
246 \layout Standard
247
248 width
249 \end_inset 
250 </cell>
251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
252 \begin_inset Text
253
254 \layout Standard
255
256 default
257 \end_inset 
258 </cell>
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
260 \begin_inset Text
261
262 \layout Standard
263
264 signed range
265 \end_inset 
266 </cell>
267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
268 \begin_inset Text
269
270 \layout Standard
271
272 unsigned range
273 \end_inset 
274 </cell>
275 </row>
276 <row topline="true">
277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
278 \begin_inset Text
279
280 \layout Standard
281
282 bool
283 \end_inset 
284 </cell>
285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
286 \begin_inset Text
287
288 \layout Standard
289
290 1 bit
291 \end_inset 
292 </cell>
293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
294 \begin_inset Text
295
296 \layout Standard
297
298 unsigned
299 \end_inset 
300 </cell>
301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
302 \begin_inset Text
303
304 \layout Standard
305
306 -
307 \end_inset 
308 </cell>
309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
310 \begin_inset Text
311
312 \layout Standard
313
314 0, 1
315 \end_inset 
316 </cell>
317 </row>
318 <row topline="true">
319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
320 \begin_inset Text
321
322 \layout Standard
323
324 char
325 \end_inset 
326 </cell>
327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
328 \begin_inset Text
329
330 \layout Standard
331
332 8 bits, 1 byte
333 \end_inset 
334 </cell>
335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
336 \begin_inset Text
337
338 \layout Standard
339
340 signed
341 \end_inset 
342 </cell>
343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
344 \begin_inset Text
345
346 \layout Standard
347
348 -128, +127
349 \end_inset 
350 </cell>
351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
352 \begin_inset Text
353
354 \layout Standard
355
356 0, +255
357 \end_inset 
358 </cell>
359 </row>
360 <row topline="true">
361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
362 \begin_inset Text
363
364 \layout Standard
365
366 short
367 \end_inset 
368 </cell>
369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
370 \begin_inset Text
371
372 \layout Standard
373
374 16 bits, 2 bytes
375 \end_inset 
376 </cell>
377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
378 \begin_inset Text
379
380 \layout Standard
381
382 signed
383 \end_inset 
384 </cell>
385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
386 \begin_inset Text
387
388 \layout Standard
389
390 -32.768, +32.767
391 \end_inset 
392 </cell>
393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
394 \begin_inset Text
395
396 \layout Standard
397
398 0, +65.535
399 \end_inset 
400 </cell>
401 </row>
402 <row topline="true">
403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
404 \begin_inset Text
405
406 \layout Standard
407
408 int
409 \end_inset 
410 </cell>
411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
412 \begin_inset Text
413
414 \layout Standard
415
416 16 bits, 2 bytes
417 \end_inset 
418 </cell>
419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
420 \begin_inset Text
421
422 \layout Standard
423
424 signed
425 \end_inset 
426 </cell>
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
428 \begin_inset Text
429
430 \layout Standard
431
432 -32.768, +32.767
433 \end_inset 
434 </cell>
435 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
436 \begin_inset Text
437
438 \layout Standard
439
440 0, +65.535
441 \end_inset 
442 </cell>
443 </row>
444 <row topline="true" bottomline="true">
445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
446 \begin_inset Text
447
448 \layout Standard
449
450 long
451 \end_inset 
452 </cell>
453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
454 \begin_inset Text
455
456 \layout Standard
457
458 32 bits, 4 bytes
459 \end_inset 
460 </cell>
461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
462 \begin_inset Text
463
464 \layout Standard
465
466 signed
467 \end_inset 
468 </cell>
469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
470 \begin_inset Text
471
472 \layout Standard
473
474 -2.147.483.648, +2.147.483.647
475 \end_inset 
476 </cell>
477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
478 \begin_inset Text
479
480 \layout Standard
481
482 0, +4.294.967.295
483 \end_inset 
484 </cell>
485 </row>
486 <row topline="true" bottomline="true">
487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
488 \begin_inset Text
489
490 \layout Standard
491
492 float
493 \end_inset 
494 </cell>
495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
496 \begin_inset Text
497
498 \layout Standard
499
500 4 bytes IEEE 754
501 \end_inset 
502 </cell>
503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
504 \begin_inset Text
505
506 \layout Standard
507
508 signed
509 \end_inset 
510 </cell>
511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
512 \begin_inset Text
513
514 \layout Standard
515
516 \end_inset 
517 </cell>
518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
519 \begin_inset Text
520
521 \layout Standard
522
523 1.175494351E-38, 
524 \family roman 
525 \series medium 
526 \shape up 
527 \size normal 
528 \emph off 
529 \bar no 
530 \noun off 
531 \color none
532 3.402823466E+38
533 \end_inset 
534 </cell>
535 </row>
536 <row topline="true" bottomline="true">
537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
538 \begin_inset Text
539
540 \layout Standard
541
542 pointer
543 \end_inset 
544 </cell>
545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
546 \begin_inset Text
547
548 \layout Standard
549
550 1, 2, 3 or 4 bytes
551 \end_inset 
552 </cell>
553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
554 \begin_inset Text
555
556 \layout Standard
557
558 generic
559 \end_inset 
560 </cell>
561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
562 \begin_inset Text
563
564 \layout Standard
565
566 \end_inset 
567 </cell>
568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
569 \begin_inset Text
570
571 \layout Standard
572
573 \end_inset 
574 </cell>
575 </row>
576 </lyxtabular>
577
578 \end_inset 
579
580
581 \newline 
582 The compiler also allows 
583 \emph on 
584 inline assembler code
585 \emph default 
586  to be embedded anywhere in a function.
587  In addition, routines developed in assembly can also be called.
588 \newline 
589
590 \newline 
591 SDCC also provides an option (-
592 \begin_inset ERT
593 status Collapsed
594
595 \layout Standard
596
597 \backslash 
598 /
599 \end_inset 
600
601 -cyclomatic) to report the relative complexity of a function.
602  These functions can then be further optimized, or hand coded in assembly
603  if needed.
604  
605 \newline 
606
607 \newline 
608 SDCC also comes with a companion source level debugger SDCDB, the debugger
609  currently uses ucSim a freeware simulator for 8051 and other micro-controllers.<
610 \newline 
611
612 \newline 
613 The latest version can be downloaded from 
614 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
615
616 \end_inset 
617
618 .
619
620 \series bold 
621  
622 \series default 
623 \emph on 
624 Please note: the compiler will probably always be some steps ahead of this
625  documentation
626 \series bold 
627 \emph default 
628
629 \begin_inset LatexCommand \index{Status of documentation}
630
631 \end_inset 
632
633
634 \begin_inset Foot
635 collapsed false
636
637 \layout Standard
638
639 Obviously this has pros and cons
640 \end_inset 
641
642 .
643 \layout Section
644
645 Open Source
646 \layout Standard
647
648 All packages used in this compiler system are 
649 \emph on 
650 open source
651 \emph default 
652  and 
653 \emph on 
654 freeware
655 \emph default 
656 ; source code for all the sub-packages (pre-processor, assemblers, linkers
657  etc) is distributed with the package.
658  This documentation is maintained using a freeware word processor (LyX).
659 \newline 
660 This program is free software; you can redistribute it and/or modify it
661  under the terms of the GNU General Public License
662 \begin_inset LatexCommand \index{GNU General Public License, GPL}
663
664 \end_inset 
665
666  as published by the Free Software Foundation; either version 2, or (at
667  your option) any later version.
668  This program is distributed in the hope that it will be useful, but WITHOUT
669  ANY WARRANTY; without even the implied warranty
670 \begin_inset LatexCommand \index{warranty}
671
672 \end_inset 
673
674  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
675  See the GNU General Public License for more details.
676  You should have received a copy of the GNU General Public License along
677  with this program; if not, write to the Free Software Foundation, 59 Temple
678  Place - Suite 330, Boston, MA 02111-1307, USA.
679  In other words, you are welcome to use, share and improve this program.
680  You are forbidden to forbid anyone else to use, share and improve what
681  you give them.
682  Help stamp out software-hoarding! 
683 \layout Section
684
685 Typographic conventions
686 \begin_inset LatexCommand \index{Typographic conventions}
687
688 \end_inset 
689
690
691 \layout Standard
692
693 Throughout this manual, we will use the following convention.
694  Commands you have to type in are printed in 
695 \family sans 
696 \series bold 
697 "sans serif"
698 \series default 
699 .
700
701 \family default 
702  Code samples are printed in 
703 \family typewriter 
704 typewriter font.
705
706 \family default 
707  Interesting items and new terms are printed in 
708 \emph on 
709 italic.
710 \layout Section
711
712 Compatibility
713 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
714
715 \end_inset 
716
717  with previous versions
718 \begin_inset LatexCommand \index{Compatibility with previous versions}
719
720 \end_inset 
721
722
723 \layout Standard
724
725 This version has numerous bug fixes compared with the previous version.
726  But we also introduced some incompatibilities with older versions.
727  Not just for the fun of it, but to make the compiler more stable, efficient
728  and ANSI compliant
729 \begin_inset LatexCommand \index{ANSI-compliance}
730
731 \end_inset 
732
733  (see section 
734 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
735
736 \end_inset 
737
738  for ANSI-Compliance).
739  
740 \newline 
741
742 \layout Itemize
743
744 short is now equivalent to int (16 bits), it used to be equivalent to char
745  (8 bits) which is not ANSI compliant.
746 \layout Itemize
747
748 the default directory for gcc-builds where include, library and documentation
749  files are stored is now in /usr/local/share.
750 \layout Itemize
751
752 char type parameters to vararg
753 \begin_inset LatexCommand \index{vararg, va\_arg}
754
755 \end_inset 
756
757  functions are casted to int unless explicitly casted
758 \begin_inset Marginal
759 collapsed true
760
761 \layout Standard
762
763
764 \series bold 
765 \SpecialChar ~
766 !
767 \end_inset 
768
769 , e.g.: 
770 \newline 
771
772 \family typewriter 
773 \SpecialChar ~
774 \SpecialChar ~
775 char a=3;
776 \newline 
777 \SpecialChar ~
778 \SpecialChar ~
779 printf ("%d %c
780 \backslash 
781 n", a, (char)a);
782 \family default 
783
784 \newline 
785  will push a as an int and as a char resp.
786 \layout Itemize
787
788 option -
789 \begin_inset ERT
790 status Collapsed
791
792 \layout Standard
793
794 \backslash 
795 /
796 \end_inset 
797
798 -regextend has been removed.
799 \layout Itemize
800
801 option -
802 \begin_inset ERT
803 status Collapsed
804
805 \layout Standard
806
807 \backslash 
808 /
809 \end_inset 
810
811 -noregparms has been removed.
812 \layout Itemize
813
814 option -
815 \begin_inset ERT
816 status Collapsed
817
818 \layout Standard
819
820 \backslash 
821 /
822 \end_inset 
823
824 -stack-after-data has been removed.
825 \layout Itemize
826
827 bit
828 \begin_inset LatexCommand \index{bit}
829
830 \end_inset 
831
832  and sbit
833 \begin_inset LatexCommand \index{sbit}
834
835 \end_inset 
836
837
838 \begin_inset LatexCommand \index{\_\_sbit}
839
840 \end_inset 
841
842  types now consistently behave like the C99 _Bool type with respect to type
843  conversion
844 \begin_inset LatexCommand \index{type conversion}
845
846 \end_inset 
847
848
849 \begin_inset LatexCommand \index{type promotion}
850
851 \end_inset 
852
853 .
854  The most common incompatibility resulting from this change is related to
855  bit toggling
856 \begin_inset LatexCommand \index{Bit toggling}
857
858 \end_inset 
859
860  idioms, e.g.:
861 \newline 
862
863 \family typewriter 
864 \SpecialChar ~
865 \SpecialChar ~
866 bit b;
867 \newline 
868 \SpecialChar ~
869 \SpecialChar ~
870 b = ~
871 \begin_inset LatexCommand \index{\~\/ Operator}
872
873 \end_inset 
874
875 b; /* equivalent to b=1 instead of toggling b */
876 \begin_inset Marginal
877 collapsed true
878
879 \layout Standard
880
881
882 \series bold 
883 \SpecialChar ~
884 !
885 \end_inset 
886
887
888 \newline 
889 \SpecialChar ~
890 \SpecialChar ~
891 b = !b; /* toggles b */
892 \newline 
893
894 \family default 
895 In previous versions, both forms would have toggled the bit.
896 \layout Standard
897
898
899 \emph on 
900 <pending: more incompatibilities?>
901 \layout Section
902
903 System Requirements
904 \layout Standard
905
906 What do you need before you start installation of SDCC? A computer, and
907  a desire to compute.
908  The preferred method of installation is to compile SDCC from source using
909  GNU gcc and make.
910  For Windows some pre-compiled binary distributions are available for your
911  convenience.
912  You should have some experience with command line tools and compiler use.
913 \layout Section
914
915 Other Resources
916 \layout Standard
917
918 The SDCC home page at 
919 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
920
921 \end_inset 
922
923  is a great place to find distribution sets.
924  You can also find links to the user mailing lists that offer help or discuss
925  SDCC with other SDCC users.
926  Web links to other SDCC related sites can also be found here.
927  This document can be found in the DOC directory of the source package as
928  a text or HTML file.
929  A pdf version of this document is available at 
930 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
931
932 \end_inset 
933
934 .
935  Some of the other tools (simulator and assembler) included with SDCC contain
936  their own documentation and can be found in the source distribution.
937  If you want the latest unreleased software, the complete source package
938  is available directly from Subversion on https://svn.sourceforge.net/svnroot/sdcc
939 /trunk/sdcc.
940 \layout Section
941
942 Wishes for the future
943 \layout Standard
944
945 There are (and always will be) some things that could be done.
946  Here are some I can think of:
947 \newline 
948
949 \layout Standard
950
951
952 \family typewriter 
953 char KernelFunction3(char p) at 0x340;
954 \newline 
955
956 \layout Standard
957
958
959 \family typewriter 
960 better code banking
961 \begin_inset LatexCommand \index{code banking (limited support)}
962
963 \end_inset 
964
965  support for mcs51
966 \newline 
967
968 \newline 
969
970 \family default 
971 If you can think of some more, please see the section 
972 \begin_inset LatexCommand \ref{sub:Requesting-Features}
973
974 \end_inset 
975
976  about filing feature requests
977 \begin_inset LatexCommand \index{Requesting features}
978
979 \end_inset 
980
981
982 \begin_inset LatexCommand \index{Feature request}
983
984 \end_inset 
985
986 .
987 \newline 
988
989 \layout Chapter
990
991 Installing SDCC
992 \begin_inset LatexCommand \index{Installation}
993
994 \end_inset 
995
996
997 \layout Standard
998
999 For most users it is sufficient to skip to either section 
1000 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1001
1002 \end_inset 
1003
1004  (Unix) or section 
1005 \begin_inset LatexCommand \ref{sub:Windows-Install}
1006
1007 \end_inset 
1008
1009  (Windows).
1010  More detailed instructions follow below.
1011 \layout Section
1012
1013 Configure Options
1014 \begin_inset LatexCommand \index{Options SDCC configuration}
1015
1016 \end_inset 
1017
1018
1019 \layout Standard
1020
1021 The install paths, search paths and other options are defined when running
1022  'configure'.
1023  The defaults can be overridden by:
1024 \layout List
1025 \labelwidthstring 00.00.0000
1026
1027 -
1028 \begin_inset ERT
1029 status Collapsed
1030
1031 \layout Standard
1032
1033 \backslash 
1034 /
1035 \end_inset 
1036
1037 -prefix see table below
1038 \layout List
1039 \labelwidthstring 00.00.0000
1040
1041 -
1042 \begin_inset ERT
1043 status Collapsed
1044
1045 \layout Standard
1046
1047 \backslash 
1048 /
1049 \end_inset 
1050
1051 -exec_prefix see table below
1052 \layout List
1053 \labelwidthstring 00.00.0000
1054
1055 -
1056 \begin_inset ERT
1057 status Collapsed
1058
1059 \layout Standard
1060
1061 \backslash 
1062 /
1063 \end_inset 
1064
1065 -bindir see table below
1066 \layout List
1067 \labelwidthstring 00.00.0000
1068
1069 -
1070 \begin_inset ERT
1071 status Collapsed
1072
1073 \layout Standard
1074
1075 \backslash 
1076 /
1077 \end_inset 
1078
1079 -datadir see table below
1080 \layout List
1081 \labelwidthstring 00.00.0000
1082
1083 -
1084 \begin_inset ERT
1085 status Collapsed
1086
1087 \layout Standard
1088
1089 \backslash 
1090 /
1091 \end_inset 
1092
1093 -datarootdir see table below
1094 \newline 
1095
1096 \layout List
1097 \labelwidthstring 00.00.0000
1098
1099 \SpecialChar ~
1100 \SpecialChar ~
1101 docdir environment variable, see table below
1102 \layout List
1103 \labelwidthstring 00.00.0000
1104
1105 \SpecialChar ~
1106 \SpecialChar ~
1107 include_dir_suffix environment variable, see table below
1108 \layout List
1109 \labelwidthstring 00.00.0000
1110
1111 \SpecialChar ~
1112 \SpecialChar ~
1113 lib_dir_suffix environment variable, see table below
1114 \layout List
1115 \labelwidthstring 00.00.0000
1116
1117 \SpecialChar ~
1118 \SpecialChar ~
1119 sdccconf_h_dir_separator environment variable, either / or 
1120 \backslash 
1121
1122 \backslash 
1123  makes sense here.
1124  This character will only be used in sdccconf.h; don't forget it's a C-header,
1125  therefore a double-backslash is needed there.
1126 \newline 
1127
1128 \layout List
1129 \labelwidthstring 00.00.0000
1130
1131 -
1132 \begin_inset ERT
1133 status Collapsed
1134
1135 \layout Standard
1136
1137 \backslash 
1138 /
1139 \end_inset 
1140
1141 -disable-mcs51-port Excludes the Intel mcs51 port
1142 \layout List
1143 \labelwidthstring 00.00.0000
1144
1145 -
1146 \begin_inset ERT
1147 status Collapsed
1148
1149 \layout Standard
1150
1151 \backslash 
1152 /
1153 \end_inset 
1154
1155 -disable-gbz80-port Excludes the Gameboy gbz80 port
1156 \layout List
1157 \labelwidthstring 00.00.0000
1158
1159 -
1160 \begin_inset ERT
1161 status Collapsed
1162
1163 \layout Standard
1164
1165 \backslash 
1166 /
1167 \end_inset 
1168
1169 -disable-z80-port Excludes the z80 port
1170 \layout List
1171 \labelwidthstring 00.00.0000
1172
1173 -
1174 \begin_inset ERT
1175 status Collapsed
1176
1177 \layout Standard
1178
1179 \backslash 
1180 /
1181 \end_inset 
1182
1183 -disable-avr-port Excludes the AVR port
1184 \layout List
1185 \labelwidthstring 00.00.0000
1186
1187 -
1188 \begin_inset ERT
1189 status Collapsed
1190
1191 \layout Standard
1192
1193 \backslash 
1194 /
1195 \end_inset 
1196
1197 -disable-ds390-port Excludes the DS390 port
1198 \layout List
1199 \labelwidthstring 00.00.0000
1200
1201 -
1202 \begin_inset ERT
1203 status Collapsed
1204
1205 \layout Standard
1206
1207 \backslash 
1208 /
1209 \end_inset 
1210
1211 -disable-hc08-port Excludes the HC08 port
1212 \layout List
1213 \labelwidthstring 00.00.0000
1214
1215 -
1216 \begin_inset ERT
1217 status Collapsed
1218
1219 \layout Standard
1220
1221 \backslash 
1222 /
1223 \end_inset 
1224
1225 -disable-pic-port Excludes the PIC port
1226 \layout List
1227 \labelwidthstring 00.00.0000
1228
1229 -
1230 \begin_inset ERT
1231 status Collapsed
1232
1233 \layout Standard
1234
1235 \backslash 
1236 /
1237 \end_inset 
1238
1239 -disable-xa51-port Excludes the XA51 port
1240 \layout List
1241 \labelwidthstring 00.00.0000
1242
1243 -
1244 \begin_inset ERT
1245 status Collapsed
1246
1247 \layout Standard
1248
1249 \backslash 
1250 /
1251 \end_inset 
1252
1253 -disable-ucsim Disables configuring and building of ucsim
1254 \layout List
1255 \labelwidthstring 00.00.0000
1256
1257 -
1258 \begin_inset ERT
1259 status Collapsed
1260
1261 \layout Standard
1262
1263 \backslash 
1264 /
1265 \end_inset 
1266
1267 -disable-device-lib Disables automatically building device libraries
1268 \layout List
1269 \labelwidthstring 00.00.0000
1270
1271 -
1272 \begin_inset ERT
1273 status Collapsed
1274
1275 \layout Standard
1276
1277 \backslash 
1278 /
1279 \end_inset 
1280
1281 -disable-packihx Disables building packihx
1282 \newline 
1283
1284 \layout List
1285 \labelwidthstring 00.00.0000
1286
1287 -
1288 \begin_inset ERT
1289 status Collapsed
1290
1291 \layout Standard
1292
1293 \backslash 
1294 /
1295 \end_inset 
1296
1297 -enable-doc Build pdf, html and txt files from the lyx sources
1298 \layout List
1299 \labelwidthstring 00.00.0000
1300
1301 -
1302 \begin_inset ERT
1303 status Collapsed
1304
1305 \layout Standard
1306
1307 \backslash 
1308 /
1309 \end_inset 
1310
1311 -enable-libgc Use the Bohem memory allocator.
1312  Lower runtime footprint.
1313 \layout Standard
1314
1315 Furthermore the environment variables CC, CFLAGS, ...
1316  the tools and their arguments can be influenced.
1317  Please see `configure -
1318 \begin_inset ERT
1319 status Collapsed
1320
1321 \layout Standard
1322
1323 \backslash 
1324 /
1325 \end_inset 
1326
1327 -help` and the man/info pages of `configure` for details.
1328 \newline 
1329
1330 \newline 
1331 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
1332  STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
1333 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
1334  At the moment it's not possible to change the default settings (it was
1335  simply never required).
1336 \newline 
1337
1338 \newline 
1339 These configure options are compiled into the binaries, and can only be
1340  changed by rerunning 'configure' and recompiling SDCC.
1341  The configure options are written in 
1342 \emph on 
1343 italics
1344 \emph default 
1345  to distinguish them from run time environment variables (see section search
1346  paths).
1347 \newline 
1348
1349 \newline 
1350 The settings for 
1351 \begin_inset Quotes sld
1352 \end_inset 
1353
1354 Win32 builds
1355 \begin_inset Quotes srd
1356 \end_inset 
1357
1358  are used by the SDCC team to build the official Win32 binaries.
1359  The SDCC team uses Mingw32 to build the official Windows binaries, because
1360  it's
1361 \layout Enumerate
1362
1363 open source, 
1364 \layout Enumerate
1365
1366 a gcc compiler and last but not least
1367 \layout Enumerate
1368
1369 the binaries can be built by cross compiling on Sourceforge's compile farm.
1370 \layout Standard
1371
1372 See the examples, how to pass the Win32 settings to 'configure'.
1373  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1374  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1375  for Win32.
1376 \newline 
1377
1378 \newline 
1379 These defaults are:
1380 \newline 
1381
1382 \layout Standard
1383 \align center 
1384
1385 \begin_inset  Tabular
1386 <lyxtabular version="3" rows="9" columns="3">
1387 <features>
1388 <column alignment="block" valignment="top" leftline="true" width="0in">
1389 <column alignment="block" valignment="top" leftline="true" width="0in">
1390 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1391 <row topline="true" bottomline="true">
1392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1393 \begin_inset Text
1394
1395 \layout Standard
1396
1397 Variable
1398 \end_inset 
1399 </cell>
1400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1401 \begin_inset Text
1402
1403 \layout Standard
1404
1405 default
1406 \end_inset 
1407 </cell>
1408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1409 \begin_inset Text
1410
1411 \layout Standard
1412
1413 Win32 builds
1414 \end_inset 
1415 </cell>
1416 </row>
1417 <row topline="true">
1418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1419 \begin_inset Text
1420
1421 \layout Standard
1422
1423
1424 \emph on 
1425 PREFIX
1426 \end_inset 
1427 </cell>
1428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1429 \begin_inset Text
1430
1431 \layout Standard
1432
1433 /usr/local
1434 \end_inset 
1435 </cell>
1436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1437 \begin_inset Text
1438
1439 \layout Standard
1440
1441
1442 \backslash 
1443 sdcc
1444 \end_inset 
1445 </cell>
1446 </row>
1447 <row topline="true">
1448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1449 \begin_inset Text
1450
1451 \layout Standard
1452
1453
1454 \emph on 
1455 EXEC_PREFIX
1456 \end_inset 
1457 </cell>
1458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1459 \begin_inset Text
1460
1461 \layout Standard
1462
1463
1464 \emph on 
1465 $PREFIX
1466 \end_inset 
1467 </cell>
1468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1469 \begin_inset Text
1470
1471 \layout Standard
1472
1473
1474 \emph on 
1475 $PREFIX
1476 \end_inset 
1477 </cell>
1478 </row>
1479 <row topline="true">
1480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1481 \begin_inset Text
1482
1483 \layout Standard
1484
1485
1486 \emph on 
1487 BINDIR
1488 \end_inset 
1489 </cell>
1490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1491 \begin_inset Text
1492
1493 \layout Standard
1494
1495
1496 \emph on 
1497 $EXEC_PREFIX
1498 \emph default 
1499 /bin
1500 \end_inset 
1501 </cell>
1502 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1503 \begin_inset Text
1504
1505 \layout Standard
1506
1507
1508 \emph on 
1509 $EXEC_PREFIX
1510 \emph default 
1511
1512 \backslash 
1513 bin
1514 \end_inset 
1515 </cell>
1516 </row>
1517 <row topline="true">
1518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1519 \begin_inset Text
1520
1521 \layout Standard
1522
1523
1524 \emph on 
1525 DATADIR
1526 \end_inset 
1527 </cell>
1528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1529 \begin_inset Text
1530
1531 \layout Standard
1532
1533
1534 \emph on 
1535 $DATAROOTDIR
1536 \end_inset 
1537 </cell>
1538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1539 \begin_inset Text
1540
1541 \layout Standard
1542
1543
1544 \emph on 
1545 $DATAROOTDIR
1546 \end_inset 
1547 </cell>
1548 </row>
1549 <row topline="true">
1550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1551 \begin_inset Text
1552
1553 \layout Standard
1554
1555
1556 \emph on 
1557 DATAROOTDIR
1558 \end_inset 
1559 </cell>
1560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1561 \begin_inset Text
1562
1563 \layout Standard
1564
1565
1566 \emph on 
1567 $PREFIX
1568 \emph default 
1569 /share
1570 \end_inset 
1571 </cell>
1572 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1573 \begin_inset Text
1574
1575 \layout Standard
1576
1577
1578 \emph on 
1579 $PREFIX
1580 \end_inset 
1581 </cell>
1582 </row>
1583 <row topline="true">
1584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1585 \begin_inset Text
1586
1587 \layout Standard
1588
1589
1590 \emph on 
1591 DOCDIR
1592 \end_inset 
1593 </cell>
1594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1595 \begin_inset Text
1596
1597 \layout Standard
1598
1599
1600 \emph on 
1601 $DATAROOTDIR
1602 \emph default 
1603 /sdcc/doc
1604 \end_inset 
1605 </cell>
1606 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1607 \begin_inset Text
1608
1609 \layout Standard
1610
1611
1612 \emph on 
1613 $DATAROOTDIR
1614 \emph default 
1615
1616 \backslash 
1617 doc
1618 \end_inset 
1619 </cell>
1620 </row>
1621 <row topline="true">
1622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1623 \begin_inset Text
1624
1625 \layout Standard
1626
1627
1628 \emph on 
1629 INCLUDE_DIR_SUFFIX
1630 \end_inset 
1631 </cell>
1632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1633 \begin_inset Text
1634
1635 \layout Standard
1636
1637 sdcc/include
1638 \end_inset 
1639 </cell>
1640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1641 \begin_inset Text
1642
1643 \layout Standard
1644
1645 include
1646 \end_inset 
1647 </cell>
1648 </row>
1649 <row topline="true" bottomline="true">
1650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1651 \begin_inset Text
1652
1653 \layout Standard
1654
1655
1656 \emph on 
1657 LIB_DIR_SUFFIX
1658 \end_inset 
1659 </cell>
1660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1661 \begin_inset Text
1662
1663 \layout Standard
1664
1665 sdcc/lib
1666 \end_inset 
1667 </cell>
1668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1669 \begin_inset Text
1670
1671 \layout Standard
1672
1673 lib
1674 \end_inset 
1675 </cell>
1676 </row>
1677 </lyxtabular>
1678
1679 \end_inset 
1680
1681
1682 \newline 
1683
1684 \layout Standard
1685 \noindent 
1686 'configure' also computes relative paths.
1687  This is needed for full relocatability of a binary package and to complete
1688  search paths (see section search paths below):
1689 \newline 
1690  
1691 \layout Standard
1692 \align center 
1693
1694 \begin_inset  Tabular
1695 <lyxtabular version="3" rows="4" columns="3">
1696 <features>
1697 <column alignment="block" valignment="top" leftline="true" width="0in">
1698 <column alignment="block" valignment="top" leftline="true" width="0in">
1699 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1700 <row topline="true" bottomline="true">
1701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1702 \begin_inset Text
1703
1704 \layout Standard
1705
1706 Variable (computed)
1707 \end_inset 
1708 </cell>
1709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1710 \begin_inset Text
1711
1712 \layout Standard
1713
1714 default
1715 \end_inset 
1716 </cell>
1717 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1718 \begin_inset Text
1719
1720 \layout Standard
1721
1722 Win32 builds
1723 \end_inset 
1724 </cell>
1725 </row>
1726 <row topline="true" bottomline="true">
1727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1728 \begin_inset Text
1729
1730 \layout Standard
1731
1732
1733 \emph on 
1734 BIN2DATA_DIR
1735 \end_inset 
1736 </cell>
1737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1738 \begin_inset Text
1739
1740 \layout Standard
1741
1742 ../share
1743 \end_inset 
1744 </cell>
1745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1746 \begin_inset Text
1747
1748 \layout Standard
1749
1750 ..
1751 \end_inset 
1752 </cell>
1753 </row>
1754 <row bottomline="true">
1755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1756 \begin_inset Text
1757
1758 \layout Standard
1759
1760
1761 \emph on 
1762 PREFIX2BIN_DIR
1763 \end_inset 
1764 </cell>
1765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1766 \begin_inset Text
1767
1768 \layout Standard
1769
1770 bin
1771 \end_inset 
1772 </cell>
1773 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1774 \begin_inset Text
1775
1776 \layout Standard
1777
1778 bin
1779 \end_inset 
1780 </cell>
1781 </row>
1782 <row bottomline="true">
1783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1784 \begin_inset Text
1785
1786 \layout Standard
1787
1788
1789 \emph on 
1790 PREFIX2DATA_DIR
1791 \end_inset 
1792 </cell>
1793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1794 \begin_inset Text
1795
1796 \layout Standard
1797
1798 share/sdcc
1799 \end_inset 
1800 </cell>
1801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1802 \begin_inset Text
1803
1804 \layout Standard
1805
1806 \end_inset 
1807 </cell>
1808 </row>
1809 </lyxtabular>
1810
1811 \end_inset 
1812
1813
1814 \newline 
1815
1816 \layout Standard
1817 \noindent 
1818 Examples:
1819 \layout LyX-Code
1820
1821 ./configure
1822 \newline 
1823 ./configure -
1824 \begin_inset ERT
1825 status Collapsed
1826
1827 \layout Standard
1828
1829 \backslash 
1830 /
1831 \end_inset 
1832
1833 -prefix=
1834 \begin_inset Quotes srd
1835 \end_inset 
1836
1837 /usr/bin
1838 \begin_inset Quotes srd
1839 \end_inset 
1840
1841  -
1842 \begin_inset ERT
1843 status Collapsed
1844
1845 \layout Standard
1846
1847 \backslash 
1848 /
1849 \end_inset 
1850
1851 -datarootdir=
1852 \begin_inset Quotes srd
1853 \end_inset 
1854
1855 /usr/share
1856 \begin_inset Quotes srd
1857 \end_inset 
1858
1859
1860 \newline 
1861 ./configure -
1862 \begin_inset ERT
1863 status Collapsed
1864
1865 \layout Standard
1866
1867 \backslash 
1868 /
1869 \end_inset 
1870
1871 -disable-avr-port -
1872 \begin_inset ERT
1873 status Collapsed
1874
1875 \layout Standard
1876
1877 \backslash 
1878 /
1879 \end_inset 
1880
1881 -disable-xa51-port
1882 \layout Standard
1883
1884 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1885 32'):
1886 \layout LyX-Code
1887
1888 ./configure 
1889 \backslash 
1890
1891 \newline 
1892 CC=
1893 \begin_inset Quotes srd
1894 \end_inset 
1895
1896 i586-mingw32msvc-gcc
1897 \begin_inset Quotes srd
1898 \end_inset 
1899
1900  CXX=
1901 \begin_inset Quotes srd
1902 \end_inset 
1903
1904 i586-mingw32msvc-g++
1905 \begin_inset Quotes srd
1906 \end_inset 
1907
1908  
1909 \backslash 
1910  
1911 \newline 
1912 RANLIB=
1913 \begin_inset Quotes srd
1914 \end_inset 
1915
1916 i586-mingw32msvc-ranlib
1917 \begin_inset Quotes srd
1918 \end_inset 
1919
1920  
1921 \backslash 
1922
1923 \newline 
1924 STRIP=
1925 \begin_inset Quotes srd
1926 \end_inset 
1927
1928 i586-mingw32msvc-strip
1929 \begin_inset Quotes srd
1930 \end_inset 
1931
1932  
1933 \backslash 
1934
1935 \newline 
1936 -
1937 \begin_inset ERT
1938 status Collapsed
1939
1940 \layout Standard
1941
1942 \backslash 
1943 /
1944 \end_inset 
1945
1946 -prefix=
1947 \begin_inset Quotes srd
1948 \end_inset 
1949
1950 /sdcc
1951 \begin_inset Quotes srd
1952 \end_inset 
1953
1954  
1955 \backslash 
1956
1957 \newline 
1958 -
1959 \begin_inset ERT
1960 status Collapsed
1961
1962 \layout Standard
1963
1964 \backslash 
1965 /
1966 \end_inset 
1967
1968 -datarootdir=
1969 \begin_inset Quotes srd
1970 \end_inset 
1971
1972 /sdcc
1973 \begin_inset Quotes srd
1974 \end_inset 
1975
1976  
1977 \backslash 
1978
1979 \newline 
1980 docdir=
1981 \begin_inset Quotes srd
1982 \end_inset 
1983
1984
1985 \backslash 
1986 ${datarootdir}/doc
1987 \begin_inset Quotes srd
1988 \end_inset 
1989
1990  
1991 \backslash 
1992
1993 \newline 
1994 include_dir_suffix=
1995 \begin_inset Quotes srd
1996 \end_inset 
1997
1998 include
1999 \begin_inset Quotes srd
2000 \end_inset 
2001
2002  
2003 \backslash 
2004
2005 \newline 
2006 lib_dir_suffix=
2007 \begin_inset Quotes srd
2008 \end_inset 
2009
2010 lib
2011 \begin_inset Quotes srd
2012 \end_inset 
2013
2014  
2015 \backslash 
2016
2017 \newline 
2018 sdccconf_h_dir_separator=
2019 \begin_inset Quotes srd
2020 \end_inset 
2021
2022
2023 \backslash 
2024
2025 \backslash 
2026
2027 \backslash 
2028
2029 \backslash 
2030
2031 \begin_inset Quotes srd
2032 \end_inset 
2033
2034  
2035 \backslash 
2036
2037 \newline 
2038 -
2039 \begin_inset ERT
2040 status Collapsed
2041
2042 \layout Standard
2043
2044 \backslash 
2045 /
2046 \end_inset 
2047
2048 -disable-device-lib
2049 \backslash 
2050
2051 \newline 
2052 -
2053 \begin_inset ERT
2054 status Collapsed
2055
2056 \layout Standard
2057
2058 \backslash 
2059 /
2060 \end_inset 
2061
2062 -host=i586-mingw32msvc
2063 \backslash 
2064
2065 \newline 
2066 -
2067 \begin_inset ERT
2068 status Collapsed
2069
2070 \layout Standard
2071
2072 \backslash 
2073 /
2074 \end_inset 
2075
2076 -build=unknown-unknown-linux-gnu
2077 \layout Standard
2078
2079 To 
2080 \begin_inset Quotes sld
2081 \end_inset 
2082
2083 cross
2084 \begin_inset Quotes srd
2085 \end_inset 
2086
2087 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2088 ):
2089 \layout LyX-Code
2090
2091 ./configure -C 
2092 \backslash 
2093
2094 \newline 
2095 -
2096 \begin_inset ERT
2097 status Collapsed
2098
2099 \layout Standard
2100
2101 \backslash 
2102 /
2103 \end_inset 
2104
2105 -prefix=
2106 \begin_inset Quotes srd
2107 \end_inset 
2108
2109 /sdcc
2110 \begin_inset Quotes srd
2111 \end_inset 
2112
2113  
2114 \backslash 
2115
2116 \newline 
2117 -
2118 \begin_inset ERT
2119 status Collapsed
2120
2121 \layout Standard
2122
2123 \backslash 
2124 /
2125 \end_inset 
2126
2127 -datarootdir=
2128 \begin_inset Quotes srd
2129 \end_inset 
2130
2131 /sdcc
2132 \begin_inset Quotes srd
2133 \end_inset 
2134
2135  
2136 \backslash 
2137
2138 \newline 
2139 docdir=
2140 \begin_inset Quotes srd
2141 \end_inset 
2142
2143
2144 \backslash 
2145 ${datarootdir}/doc
2146 \begin_inset Quotes srd
2147 \end_inset 
2148
2149  
2150 \backslash 
2151  
2152 \newline 
2153 include_dir_suffix=
2154 \begin_inset Quotes srd
2155 \end_inset 
2156
2157 include
2158 \begin_inset Quotes srd
2159 \end_inset 
2160
2161  
2162 \backslash 
2163
2164 \newline 
2165 lib_dir_suffix=
2166 \begin_inset Quotes srd
2167 \end_inset 
2168
2169 lib
2170 \begin_inset Quotes srd
2171 \end_inset 
2172
2173  
2174 \backslash 
2175
2176 \newline 
2177 sdccconf_h_dir_separator=
2178 \begin_inset Quotes srd
2179 \end_inset 
2180
2181
2182 \backslash 
2183
2184 \backslash 
2185
2186 \backslash 
2187
2188 \backslash 
2189
2190 \begin_inset Quotes srd
2191 \end_inset 
2192
2193  
2194 \backslash 
2195
2196 \newline 
2197 CC=
2198 \begin_inset Quotes srd
2199 \end_inset 
2200
2201 gcc -mno-cygwin
2202 \begin_inset Quotes srd
2203 \end_inset 
2204
2205  
2206 \backslash 
2207
2208 \newline 
2209 CXX=
2210 \begin_inset Quotes srd
2211 \end_inset 
2212
2213 g++ -mno-cygwin
2214 \begin_inset Quotes srd
2215 \end_inset 
2216
2217  
2218 \layout Standard
2219
2220 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2221  The option '-
2222 \begin_inset ERT
2223 status Collapsed
2224
2225 \layout Standard
2226
2227 \backslash 
2228 /
2229 \end_inset 
2230
2231 -C' turns on caching, which gives a little bit extra speed.
2232  However if options are changed, it can be necessary to delete the config.cache
2233  file.
2234 \layout Section
2235 \added_space_bottom medskip 
2236 Install paths
2237 \begin_inset LatexCommand \label{sub:Install-paths}
2238
2239 \end_inset 
2240
2241
2242 \begin_inset LatexCommand \index{Install paths}
2243
2244 \end_inset 
2245
2246
2247 \layout Standard
2248 \align center 
2249
2250 \begin_inset  Tabular
2251 <lyxtabular version="3" rows="5" columns="4">
2252 <features>
2253 <column alignment="left" valignment="top" leftline="true" width="0">
2254 <column alignment="left" valignment="top" leftline="true" width="0">
2255 <column alignment="left" valignment="top" leftline="true" width="0">
2256 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2257 <row topline="true" bottomline="true">
2258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2259 \begin_inset Text
2260
2261 \layout Standard
2262
2263
2264 \series bold 
2265 Description
2266 \end_inset 
2267 </cell>
2268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2269 \begin_inset Text
2270
2271 \layout Standard
2272
2273
2274 \series bold 
2275 Path
2276 \end_inset 
2277 </cell>
2278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2279 \begin_inset Text
2280
2281 \layout Standard
2282
2283
2284 \series bold 
2285 Default
2286 \end_inset 
2287 </cell>
2288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2289 \begin_inset Text
2290
2291 \layout Standard
2292
2293
2294 \series bold 
2295 Win32 builds
2296 \end_inset 
2297 </cell>
2298 </row>
2299 <row topline="true">
2300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2301 \begin_inset Text
2302
2303 \layout Standard
2304
2305 Binary files*
2306 \end_inset 
2307 </cell>
2308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2309 \begin_inset Text
2310
2311 \layout Standard
2312
2313
2314 \emph on 
2315 $EXEC_PREFIX
2316 \end_inset 
2317 </cell>
2318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2319 \begin_inset Text
2320
2321 \layout Standard
2322
2323 /usr/local/bin
2324 \end_inset 
2325 </cell>
2326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2327 \begin_inset Text
2328
2329 \layout Standard
2330
2331
2332 \backslash 
2333 sdcc
2334 \backslash 
2335 bin
2336 \end_inset 
2337 </cell>
2338 </row>
2339 <row topline="true">
2340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2341 \begin_inset Text
2342
2343 \layout Standard
2344
2345 Include files
2346 \end_inset 
2347 </cell>
2348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2349 \begin_inset Text
2350
2351 \layout Standard
2352
2353
2354 \emph on 
2355 $DATADIR/ $INCLUDE_DIR_SUFFIX
2356 \end_inset 
2357 </cell>
2358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2359 \begin_inset Text
2360
2361 \layout Standard
2362
2363 /usr/local/share/sdcc/include
2364 \end_inset 
2365 </cell>
2366 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2367 \begin_inset Text
2368
2369 \layout Standard
2370
2371
2372 \backslash 
2373 sdcc
2374 \backslash 
2375 include
2376 \end_inset 
2377 </cell>
2378 </row>
2379 <row topline="true">
2380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2381 \begin_inset Text
2382
2383 \layout Standard
2384
2385 Library file**
2386 \end_inset 
2387 </cell>
2388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2389 \begin_inset Text
2390
2391 \layout Standard
2392
2393
2394 \emph on 
2395 $DATADIR/$LIB_DIR_SUFFIX
2396 \end_inset 
2397 </cell>
2398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2399 \begin_inset Text
2400
2401 \layout Standard
2402
2403 /usr/local/share/sdcc/lib
2404 \end_inset 
2405 </cell>
2406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2407 \begin_inset Text
2408
2409 \layout Standard
2410
2411
2412 \backslash 
2413 sdcc
2414 \backslash 
2415 lib
2416 \end_inset 
2417 </cell>
2418 </row>
2419 <row topline="true" bottomline="true">
2420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2421 \begin_inset Text
2422
2423 \layout Standard
2424
2425 Documentation
2426 \end_inset 
2427 </cell>
2428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2429 \begin_inset Text
2430
2431 \layout Standard
2432
2433
2434 \emph on 
2435 $DOCDIR
2436 \end_inset 
2437 </cell>
2438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2439 \begin_inset Text
2440
2441 \layout Standard
2442
2443 /usr/local/share/sdcc/doc
2444 \end_inset 
2445 </cell>
2446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2447 \begin_inset Text
2448
2449 \layout Standard
2450
2451
2452 \backslash 
2453 sdcc
2454 \backslash 
2455 doc
2456 \end_inset 
2457 </cell>
2458 </row>
2459 </lyxtabular>
2460
2461 \end_inset 
2462
2463
2464 \layout Verse
2465
2466
2467 \size footnotesize 
2468 *compiler, preprocessor, assembler, and linker
2469 \newline 
2470 **the 
2471 \shape italic 
2472 model
2473 \shape default 
2474  is auto-appended by the compiler, e.g.
2475  small, large, z80, ds390 etc
2476 \layout Standard
2477 \noindent 
2478 The install paths can still be changed during `make install` with e.g.:
2479 \layout LyX-Code
2480
2481 make install prefix=$(HOME)/local/sdcc
2482 \layout Standard
2483
2484 Of course this doesn't change the search paths compiled into the binaries.
2485 \newline 
2486
2487 \newline 
2488 Moreover the install path can be changed by defining DESTDIR
2489 \begin_inset LatexCommand \index{DESTDIR}
2490
2491 \end_inset 
2492
2493 :
2494 \layout LyX-Code
2495
2496 make install DESTDIR=$(HOME)/sdcc.rpm/
2497 \layout Standard
2498
2499 Please note that DESTDIR must have a trailing slash!
2500 \layout Section
2501
2502 Search Paths
2503 \begin_inset LatexCommand \label{sub:Search-Paths}
2504
2505 \end_inset 
2506
2507
2508 \begin_inset LatexCommand \index{Search path}
2509
2510 \end_inset 
2511
2512
2513 \layout Standard
2514
2515 Some search paths or parts of them are determined by configure variables
2516  (in 
2517 \emph on 
2518 italics
2519 \emph default 
2520 , see section above).
2521  Further search paths are determined by environment variables during runtime.
2522  
2523 \newline 
2524 The paths searched when running the compiler are as follows (the first catch
2525  wins):
2526 \newline 
2527
2528 \newline 
2529 1.
2530  Binary files (preprocessor, assembler and linker)
2531 \newline 
2532
2533 \layout Standard
2534 \align center 
2535
2536 \begin_inset  Tabular
2537 <lyxtabular version="3" rows="4" columns="3">
2538 <features>
2539 <column alignment="block" valignment="top" leftline="true" width="0in">
2540 <column alignment="block" valignment="top" leftline="true" width="0in">
2541 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2542 <row topline="true" bottomline="true">
2543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2544 \begin_inset Text
2545
2546 \layout Standard
2547
2548 Search path
2549 \end_inset 
2550 </cell>
2551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2552 \begin_inset Text
2553
2554 \layout Standard
2555
2556 default
2557 \end_inset 
2558 </cell>
2559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2560 \begin_inset Text
2561
2562 \layout Standard
2563
2564 Win32 builds
2565 \end_inset 
2566 </cell>
2567 </row>
2568 <row topline="true">
2569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2570 \begin_inset Text
2571
2572 \layout Standard
2573
2574 $SDCC_HOME/
2575 \emph on 
2576 $PPREFIX2BIN_DIR
2577 \end_inset 
2578 </cell>
2579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2580 \begin_inset Text
2581
2582 \layout Standard
2583
2584 $SDCC_HOME/bin
2585 \end_inset 
2586 </cell>
2587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2588 \begin_inset Text
2589
2590 \layout Standard
2591
2592 $SDCC_HOME
2593 \backslash 
2594 bin
2595 \end_inset 
2596 </cell>
2597 </row>
2598 <row topline="true">
2599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2600 \begin_inset Text
2601
2602 \layout Standard
2603
2604 Path of argv[0] (if available)
2605 \end_inset 
2606 </cell>
2607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2608 \begin_inset Text
2609
2610 \layout Standard
2611
2612 Path of argv[0]
2613 \end_inset 
2614 </cell>
2615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2616 \begin_inset Text
2617
2618 \layout Standard
2619
2620 Path of argv[0]
2621 \end_inset 
2622 </cell>
2623 </row>
2624 <row topline="true" bottomline="true">
2625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2626 \begin_inset Text
2627
2628 \layout Standard
2629
2630 $PATH
2631 \end_inset 
2632 </cell>
2633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2634 \begin_inset Text
2635
2636 \layout Standard
2637
2638 $PATH
2639 \end_inset 
2640 </cell>
2641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2642 \begin_inset Text
2643
2644 \layout Standard
2645
2646 $PATH
2647 \end_inset 
2648 </cell>
2649 </row>
2650 </lyxtabular>
2651
2652 \end_inset 
2653
2654  
2655 \newline 
2656
2657 \layout Standard
2658 \noindent 
2659 2.
2660  Include files
2661 \newline 
2662
2663 \layout Standard
2664 \align center 
2665
2666 \begin_inset  Tabular
2667 <lyxtabular version="3" rows="6" columns="3">
2668 <features>
2669 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2670 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2671 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2672 <row topline="true" bottomline="true">
2673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2674 \begin_inset Text
2675
2676 \layout Standard
2677
2678 Search path
2679 \end_inset 
2680 </cell>
2681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2682 \begin_inset Text
2683
2684 \layout Standard
2685
2686 default
2687 \end_inset 
2688 </cell>
2689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2690 \begin_inset Text
2691
2692 \layout Standard
2693
2694 Win32 builds
2695 \end_inset 
2696 </cell>
2697 </row>
2698 <row topline="true">
2699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2700 \begin_inset Text
2701
2702 \layout Standard
2703
2704 -
2705 \begin_inset ERT
2706 status Collapsed
2707
2708 \layout Standard
2709
2710 \backslash 
2711 /
2712 \end_inset 
2713
2714 -I dir
2715 \end_inset 
2716 </cell>
2717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2718 \begin_inset Text
2719
2720 \layout Standard
2721
2722 -
2723 \begin_inset ERT
2724 status Collapsed
2725
2726 \layout Standard
2727
2728 \backslash 
2729 /
2730 \end_inset 
2731
2732 -I dir
2733 \end_inset 
2734 </cell>
2735 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2736 \begin_inset Text
2737
2738 \layout Standard
2739
2740 -
2741 \begin_inset ERT
2742 status Collapsed
2743
2744 \layout Standard
2745
2746 \backslash 
2747 /
2748 \end_inset 
2749
2750 -I dir
2751 \end_inset 
2752 </cell>
2753 </row>
2754 <row topline="true">
2755 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2756 \begin_inset Text
2757
2758 \layout Standard
2759
2760 $SDCC_INCLUDE
2761 \end_inset 
2762 </cell>
2763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2764 \begin_inset Text
2765
2766 \layout Standard
2767
2768 $SDCC_INCLUDE
2769 \end_inset 
2770 </cell>
2771 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2772 \begin_inset Text
2773
2774 \layout Standard
2775
2776 $SDCC_INCLUDE
2777 \end_inset 
2778 </cell>
2779 </row>
2780 <row topline="true">
2781 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2782 \begin_inset Text
2783
2784 \layout Standard
2785
2786 $SDCC_HOME/
2787 \newline 
2788
2789 \emph on 
2790 $PREFIX2DATA_DIR/
2791 \newline 
2792 $INCLUDE_DIR_SUFFIX
2793 \end_inset 
2794 </cell>
2795 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2796 \begin_inset Text
2797
2798 \layout Standard
2799
2800 $SDCC_ HOME/
2801 \newline 
2802 share/sdcc/
2803 \newline 
2804 include
2805 \end_inset 
2806 </cell>
2807 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2808 \begin_inset Text
2809
2810 \layout Standard
2811
2812 $SDCC_HOME
2813 \backslash 
2814 include
2815 \end_inset 
2816 </cell>
2817 </row>
2818 <row topline="true">
2819 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2820 \begin_inset Text
2821
2822 \layout Standard
2823
2824 path(argv[0])/
2825 \newline 
2826
2827 \emph on 
2828 $BIN2DATADIR/
2829 \emph default 
2830
2831 \newline 
2832
2833 \emph on 
2834 $INCLUDE_DIR_SUFFIX
2835 \end_inset 
2836 </cell>
2837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2838 \begin_inset Text
2839
2840 \layout Standard
2841
2842 path(argv[0])/
2843 \newline 
2844 ../sdcc/include
2845 \newline 
2846 \SpecialChar ~
2847 \SpecialChar ~
2848 \SpecialChar ~
2849 \SpecialChar ~
2850 \SpecialChar ~
2851 \SpecialChar ~
2852 \SpecialChar ~
2853 \SpecialChar ~
2854 \SpecialChar ~
2855 \SpecialChar ~
2856 \SpecialChar ~
2857 \SpecialChar ~
2858 \SpecialChar ~
2859 \SpecialChar ~
2860 \SpecialChar ~
2861 \SpecialChar ~
2862 \SpecialChar ~
2863 \SpecialChar ~
2864 \SpecialChar ~
2865 \SpecialChar ~
2866 \SpecialChar ~
2867 \SpecialChar ~
2868 \SpecialChar ~
2869 \SpecialChar ~
2870 \SpecialChar ~
2871 \SpecialChar ~
2872 \SpecialChar ~
2873 \SpecialChar ~
2874 \SpecialChar ~
2875 \SpecialChar ~
2876 \SpecialChar ~
2877 \SpecialChar ~
2878 \SpecialChar ~
2879 \SpecialChar ~
2880 \SpecialChar ~
2881 \SpecialChar ~
2882 \SpecialChar ~
2883 \SpecialChar ~
2884
2885 \end_inset 
2886 </cell>
2887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2888 \begin_inset Text
2889
2890 \layout Standard
2891
2892 path(argv[0])
2893 \backslash 
2894 ..
2895 \backslash 
2896 include
2897 \end_inset 
2898 </cell>
2899 </row>
2900 <row topline="true" bottomline="true">
2901 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2902 \begin_inset Text
2903
2904 \layout Standard
2905
2906
2907 \emph on 
2908 $DATADIR/
2909 \emph default 
2910
2911 \newline 
2912
2913 \emph on 
2914 $INCLUDE_DIR_SUFFIX
2915 \end_inset 
2916 </cell>
2917 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2918 \begin_inset Text
2919
2920 \layout Standard
2921
2922 /usr/local/share/sdcc/
2923 \newline 
2924 include
2925 \end_inset 
2926 </cell>
2927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2928 \begin_inset Text
2929
2930 \layout Standard
2931
2932 (not on Win32)
2933 \end_inset 
2934 </cell>
2935 </row>
2936 </lyxtabular>
2937
2938 \end_inset 
2939
2940  
2941 \newline 
2942
2943 \layout Standard
2944 \noindent 
2945 The option -
2946 \begin_inset ERT
2947 status Collapsed
2948
2949 \layout Standard
2950
2951 \backslash 
2952 /
2953 \end_inset 
2954
2955 -nostdinc disables the last two search paths.
2956 \newline 
2957
2958 \newline 
2959 3.
2960  Library files 
2961 \newline 
2962
2963 \layout Standard
2964
2965 With the exception of 
2966 \begin_inset Quotes sld
2967 \end_inset 
2968
2969 -
2970 \begin_inset ERT
2971 status Collapsed
2972
2973 \layout Standard
2974
2975 \backslash 
2976 /
2977 \end_inset 
2978
2979 -L dir
2980 \begin_inset Quotes srd
2981 \end_inset 
2982
2983  the 
2984 \shape italic 
2985 model
2986 \shape default 
2987  is auto-appended by the compiler (e.g.
2988  small, large, z80, ds390 etc.).
2989  
2990 \newline 
2991
2992 \layout Standard
2993 \align center 
2994
2995 \begin_inset  Tabular
2996 <lyxtabular version="3" rows="6" columns="3">
2997 <features>
2998 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2999 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3000 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3001 <row topline="true" bottomline="true">
3002 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3003 \begin_inset Text
3004
3005 \layout Standard
3006
3007 Search path
3008 \end_inset 
3009 </cell>
3010 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3011 \begin_inset Text
3012
3013 \layout Standard
3014
3015 default
3016 \end_inset 
3017 </cell>
3018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3019 \begin_inset Text
3020
3021 \layout Standard
3022
3023 Win32 builds
3024 \end_inset 
3025 </cell>
3026 </row>
3027 <row topline="true">
3028 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3029 \begin_inset Text
3030
3031 \layout Standard
3032
3033 -
3034 \begin_inset ERT
3035 status Collapsed
3036
3037 \layout Standard
3038
3039 \backslash 
3040 /
3041 \end_inset 
3042
3043 -L dir
3044 \end_inset 
3045 </cell>
3046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3047 \begin_inset Text
3048
3049 \layout Standard
3050
3051 -
3052 \begin_inset ERT
3053 status Collapsed
3054
3055 \layout Standard
3056
3057 \backslash 
3058 /
3059 \end_inset 
3060
3061 -L dir
3062 \end_inset 
3063 </cell>
3064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3065 \begin_inset Text
3066
3067 \layout Standard
3068
3069 -
3070 \begin_inset ERT
3071 status Collapsed
3072
3073 \layout Standard
3074
3075 \backslash 
3076 /
3077 \end_inset 
3078
3079 -L dir
3080 \end_inset 
3081 </cell>
3082 </row>
3083 <row topline="true">
3084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3085 \begin_inset Text
3086
3087 \layout Standard
3088
3089 $SDCC_LIB/
3090 \newline 
3091
3092 \emph on 
3093 <model>
3094 \end_inset 
3095 </cell>
3096 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3097 \begin_inset Text
3098
3099 \layout Standard
3100
3101 $SDCC_LIB/
3102 \newline 
3103
3104 \emph on 
3105 <model>
3106 \end_inset 
3107 </cell>
3108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3109 \begin_inset Text
3110
3111 \layout Standard
3112
3113 $SDCC_LIB
3114 \backslash 
3115
3116 \newline 
3117
3118 \emph on 
3119 <model>
3120 \end_inset 
3121 </cell>
3122 </row>
3123 <row topline="true">
3124 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3125 \begin_inset Text
3126
3127 \layout Standard
3128
3129 $SDCC_HOME/
3130 \newline 
3131
3132 \emph on 
3133 $PREFIX2DATA_DIR/
3134 \newline 
3135 $LIB_DIR_SUFFIX/<model>
3136 \end_inset 
3137 </cell>
3138 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3139 \begin_inset Text
3140
3141 \layout Standard
3142
3143 $SDCC_HOME/
3144 \newline 
3145 share/sdcc/
3146 \newline 
3147 lib/
3148 \emph on 
3149 <model>
3150 \end_inset 
3151 </cell>
3152 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3153 \begin_inset Text
3154
3155 \layout Standard
3156
3157 $SDCC_HOME
3158 \backslash 
3159 lib
3160 \backslash 
3161
3162 \emph on 
3163
3164 \newline 
3165 <model>
3166 \end_inset 
3167 </cell>
3168 </row>
3169 <row topline="true">
3170 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3171 \begin_inset Text
3172
3173 \layout Standard
3174
3175 path(argv[0])/
3176 \newline 
3177
3178 \emph on 
3179 $BIN2DATADIR/
3180 \emph default 
3181
3182 \newline 
3183
3184 \emph on 
3185 $LIB_DIR_SUFFIX/<model>
3186 \end_inset 
3187 </cell>
3188 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3189 \begin_inset Text
3190
3191 \layout Standard
3192
3193 path(argv[0])/
3194 \newline 
3195 ../sdcc/lib/
3196 \emph on 
3197 <model>
3198 \newline 
3199 \SpecialChar ~
3200 \SpecialChar ~
3201 \SpecialChar ~
3202 \SpecialChar ~
3203 \SpecialChar ~
3204 \SpecialChar ~
3205 \SpecialChar ~
3206 \SpecialChar ~
3207 \SpecialChar ~
3208 \SpecialChar ~
3209 \SpecialChar ~
3210 \SpecialChar ~
3211 \SpecialChar ~
3212 \SpecialChar ~
3213 \SpecialChar ~
3214 \SpecialChar ~
3215 \SpecialChar ~
3216 \SpecialChar ~
3217 \SpecialChar ~
3218 \SpecialChar ~
3219 \SpecialChar ~
3220 \SpecialChar ~
3221 \SpecialChar ~
3222 \SpecialChar ~
3223 \SpecialChar ~
3224 \SpecialChar ~
3225 \SpecialChar ~
3226 \SpecialChar ~
3227 \SpecialChar ~
3228 \SpecialChar ~
3229 \SpecialChar ~
3230 \SpecialChar ~
3231 \SpecialChar ~
3232 \SpecialChar ~
3233 \SpecialChar ~
3234 \SpecialChar ~
3235 \SpecialChar ~
3236 \SpecialChar ~
3237 \SpecialChar ~
3238
3239 \end_inset 
3240 </cell>
3241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3242 \begin_inset Text
3243
3244 \layout Standard
3245
3246 path(argv[0])
3247 \backslash 
3248
3249 \newline 
3250 ..
3251 \backslash 
3252 lib
3253 \backslash 
3254
3255 \emph on 
3256 <model>
3257 \newline 
3258 \SpecialChar ~
3259 \SpecialChar ~
3260 \SpecialChar ~
3261 \SpecialChar ~
3262 \SpecialChar ~
3263 \SpecialChar ~
3264 \SpecialChar ~
3265 \SpecialChar ~
3266 \SpecialChar ~
3267 \SpecialChar ~
3268 \SpecialChar ~
3269 \SpecialChar ~
3270 \SpecialChar ~
3271 \SpecialChar ~
3272 \SpecialChar ~
3273 \SpecialChar ~
3274 \SpecialChar ~
3275 \SpecialChar ~
3276 \SpecialChar ~
3277 \SpecialChar ~
3278 \SpecialChar ~
3279 \SpecialChar ~
3280 \SpecialChar ~
3281 \SpecialChar ~
3282 \SpecialChar ~
3283 \SpecialChar ~
3284 \SpecialChar ~
3285 \SpecialChar ~
3286 \SpecialChar ~
3287 \SpecialChar ~
3288 \SpecialChar ~
3289 \SpecialChar ~
3290 \SpecialChar ~
3291 \SpecialChar ~
3292 \SpecialChar ~
3293
3294 \end_inset 
3295 </cell>
3296 </row>
3297 <row topline="true" bottomline="true">
3298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3299 \begin_inset Text
3300
3301 \layout Standard
3302
3303
3304 \emph on 
3305 $DATADIR/
3306 \newline 
3307 $LIB_DIR_SUFFIX/<model>
3308 \end_inset 
3309 </cell>
3310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3311 \begin_inset Text
3312
3313 \layout Standard
3314
3315 /usr/local/share/sdcc/
3316 \newline 
3317 lib/
3318 \emph on 
3319 <model>
3320 \end_inset 
3321 </cell>
3322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3323 \begin_inset Text
3324
3325 \layout Standard
3326
3327 (not on Win32)
3328 \end_inset 
3329 </cell>
3330 </row>
3331 </lyxtabular>
3332
3333 \end_inset 
3334
3335
3336 \newline 
3337
3338 \layout Standard
3339
3340
3341 \begin_inset Note
3342 collapsed true
3343
3344 \layout Standard
3345
3346 Don't delete any of the stray spaces in the table above without checking
3347  the HTML output (last line)!
3348 \end_inset 
3349
3350
3351 \layout Standard
3352
3353 \SpecialChar ~
3354
3355 \newline 
3356 The option -
3357 \begin_inset ERT
3358 status Collapsed
3359
3360 \layout Standard
3361
3362 \backslash 
3363 /
3364 \end_inset 
3365
3366 -nostdlib disables the last two search paths.
3367 \layout Section
3368
3369 Building SDCC
3370 \begin_inset LatexCommand \index{Building SDCC}
3371
3372 \end_inset 
3373
3374
3375 \layout Subsection
3376
3377 Building SDCC on Linux
3378 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3379
3380 \end_inset 
3381
3382
3383 \layout Enumerate
3384
3385
3386 \series medium 
3387 Download the source package
3388 \series default 
3389  either from the SDCC Subversion repository or from the nightly snapshots
3390 \series medium 
3391 , it will be named something like sdcc
3392 \series default 
3393 .src
3394 \series medium 
3395 .t
3396 \series default 
3397 ar.
3398 \series medium 
3399 gz
3400 \series default 
3401  
3402 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3403
3404 \end_inset 
3405
3406 .
3407 \layout Enumerate
3408
3409
3410 \series medium 
3411 Bring up a command line terminal, such as xterm.
3412 \layout Enumerate
3413
3414
3415 \series medium 
3416 Unpack the file using a command like: 
3417 \family sans 
3418 \series bold 
3419 "tar -xvzf sdcc.src.tar.gz
3420 \family default 
3421 \series default 
3422 "
3423 \series medium 
3424 , this will create a sub-directory called sdcc with all of the sources.
3425 \layout Enumerate
3426
3427 Change directory into the main SDCC directory, for example type: 
3428 \family sans 
3429 \series bold 
3430 "cd sdcc
3431 \series default 
3432 ".
3433 \layout Enumerate
3434
3435
3436 \series medium 
3437 Type 
3438 \family sans 
3439 \series bold 
3440 "./configure
3441 \family default 
3442 \series default 
3443 ".
3444  This configures the package for compilation on your system.
3445 \layout Enumerate
3446
3447
3448 \series medium 
3449 Type 
3450 \family sans 
3451 \series bold 
3452 "make
3453 \family default 
3454 \series default 
3455 "
3456 \series medium 
3457 .
3458
3459 \series default 
3460  All of the source packages will compile, this can take a while.
3461 \layout Enumerate
3462
3463
3464 \series medium 
3465 Type 
3466 \family sans 
3467 \series bold 
3468 "make install"
3469 \family default 
3470 \series default 
3471  as root
3472 \series medium 
3473 .
3474
3475 \series default 
3476  This copies the binary executables, the include files, the libraries and
3477  the documentation to the install directories.
3478  Proceed with section 
3479 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3480
3481 \end_inset 
3482
3483 .
3484 \layout Subsection
3485
3486 Building SDCC on OSX 2.x
3487 \layout Standard
3488
3489 Follow the instruction for Linux.
3490 \newline 
3491
3492 \newline 
3493 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
3494 )) fails to compile SDCC.
3495  Fortunately there's also gcc 2.9.x installed, which works fine.
3496  This compiler can be selected by running 'configure' with:
3497 \layout LyX-Code
3498
3499 ./configure CC=gcc2 CXX=g++2
3500 \layout Subsection
3501
3502 Cross compiling SDCC on Linux for Windows
3503 \layout Standard
3504
3505 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3506  See section 'Configure Options'.
3507 \layout Subsection
3508
3509 Building SDCC using Cygwin and Mingw32
3510 \layout Standard
3511
3512 For building and installing a Cygwin executable follow the instructions
3513  for Linux.
3514 \newline 
3515
3516 \newline 
3517 On Cygwin a 
3518 \begin_inset Quotes sld
3519 \end_inset 
3520
3521 native
3522 \begin_inset Quotes srd
3523 \end_inset 
3524
3525  Win32-binary can be built, which will not need the Cygwin-DLL.
3526  For the necessary 'configure' options see section 'configure options' or
3527  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3528 \newline 
3529
3530 \newline 
3531 In order to install Cygwin on Windows download setup.exe from 
3532 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3533
3534 \end_inset 
3535
3536 .
3537  Run it, set the 
3538 \begin_inset Quotes sld
3539 \end_inset 
3540
3541 default text file type
3542 \begin_inset Quotes srd
3543 \end_inset 
3544
3545  to 
3546 \begin_inset Quotes sld
3547 \end_inset 
3548
3549 unix
3550 \begin_inset Quotes srd
3551 \end_inset 
3552
3553  and download/install at least the following packages.
3554  Some packages are selected by default, others will be automatically selected
3555  because of dependencies with the manually selected packages.
3556  Never deselect these packages!
3557 \layout Itemize
3558
3559 flex
3560 \layout Itemize
3561
3562 bison
3563 \layout Itemize
3564
3565 gcc ; version 3.x is fine, no need to use the old 2.9x
3566 \layout Itemize
3567
3568 binutils ; selected with gcc
3569 \layout Itemize
3570
3571 make
3572 \layout Itemize
3573
3574 rxvt ; a nice console, which makes life much easier under windoze (see below)
3575 \layout Itemize
3576
3577 man ; not really needed for building SDCC, but you'll miss it sooner or
3578  later
3579 \layout Itemize
3580
3581 less ; not really needed for building SDCC, but you'll miss it sooner or
3582  later
3583 \layout Itemize
3584
3585 svn ; only if you use Subversion access
3586 \layout Standard
3587
3588 If you want to develop something you'll need:
3589 \layout Itemize
3590
3591 python ; for the regression tests
3592 \layout Itemize
3593
3594 gdb ; the gnu debugger, together with the nice GUI 
3595 \begin_inset Quotes sld
3596 \end_inset 
3597
3598 insight
3599 \begin_inset Quotes srd
3600 \end_inset 
3601
3602
3603 \layout Itemize
3604
3605 openssh ; to access the CF or commit changes
3606 \layout Itemize
3607
3608 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3609  use autoconf-stable!
3610 \layout Standard
3611
3612 rxvt is a nice console with history.
3613  Replace in your cygwin.bat the line
3614 \layout LyX-Code
3615
3616 bash -
3617 \begin_inset ERT
3618 status Collapsed
3619
3620 \layout Standard
3621
3622 \backslash 
3623 /
3624 \end_inset 
3625
3626 -login -i 
3627 \layout Standard
3628
3629 with (one line):
3630 \layout LyX-Code
3631
3632 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3633 \layout LyX-Code
3634
3635      -bg black -fg white -geometry 100x65 -e bash -
3636 \begin_inset ERT
3637 status Collapsed
3638
3639 \layout Standard
3640
3641 \backslash 
3642 /
3643 \end_inset 
3644
3645 -login
3646 \layout Standard
3647
3648 Text selected with the mouse is automatically copied to the clipboard, pasting
3649  works with shift-insert.
3650 \newline 
3651
3652 \newline 
3653 The other good tip is to make sure you have no //c/-style paths anywhere,
3654  use /cygdrive/c/ instead.
3655  Using // invokes a network lookup which is very slow.
3656  If you think 
3657 \begin_inset Quotes sld
3658 \end_inset 
3659
3660 cygdrive
3661 \begin_inset Quotes srd
3662 \end_inset 
3663
3664  is too long, you can change it with e.g.
3665 \layout LyX-Code
3666
3667 mount -s -u -c /mnt
3668 \layout Standard
3669
3670 SDCC sources use the unix line ending LF.
3671  Life is much easier, if you store the source tree on a drive which is mounted
3672  in binary mode.
3673  And use an editor which can handle LF-only line endings.
3674  Make sure not to commit files with windows line endings.
3675  The tabulator spacing
3676 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3677
3678 \end_inset 
3679
3680  used in the project is 8.
3681  Although a tabulator spacing of 8 is a sensible choice for programmers
3682  (it's a power of 2 and allows to display 8/16 bit signed variables without
3683  loosing columns) the plan is to move towards using only spaces in the source.
3684 \layout Subsection
3685
3686 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3687 \layout Standard
3688
3689
3690 \series medium 
3691 Download the source package
3692 \series default 
3693  either from the SDCC Subversion repository or from the 
3694 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3695
3696 \end_inset 
3697
3698
3699 \series medium 
3700 , it will be named something like sdcc
3701 \series default 
3702 .src
3703 \series medium 
3704 .tgz.
3705
3706 \series default 
3707  SDCC is distributed with all the projects, workspaces, and files you need
3708  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
3709  The workspace name is 'sdcc.dsw'.
3710  Please note that as it is now, all the executables are created in a folder
3711  called sdcc
3712 \backslash 
3713 bin_vc.
3714  Once built you need to copy the executables from sdcc
3715 \backslash 
3716 bin_vc to sdcc
3717 \backslash 
3718 bin before running SDCC.
3719  
3720 \newline 
3721
3722 \newline 
3723 WARNING: Visual studio is very picky with line terminations; it expects
3724  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3725  When using the Subversion repository it's easiest to configure the svn
3726  client to convert automatically for you.
3727  If however you are getting a message such as "This makefile was not generated
3728  by Developer Studio etc.
3729  etc.
3730 \begin_inset Quotes srd
3731 \end_inset 
3732
3733  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3734  need to convert the Unix style line endings to DOS style line endings.
3735  To do so you can use the 
3736 \begin_inset Quotes sld
3737 \end_inset 
3738
3739 unix2dos
3740 \begin_inset Quotes srd
3741 \end_inset 
3742
3743  utility freely available on the internet.
3744  Doug Hawkins reported in the sdcc-user list that this works:
3745 \newline 
3746
3747 \newline 
3748 C:
3749 \backslash 
3750 Programming
3751 \backslash 
3752 SDCC> unix2dos sdcc.dsw
3753 \newline 
3754 C:
3755 \backslash 
3756 Programming
3757 \backslash 
3758 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3759 \newline 
3760
3761 \newline 
3762 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3763  flex.exe, and gawk.exe.
3764  One good place to get them is 
3765 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3766
3767 \end_inset 
3768
3769
3770 \newline 
3771
3772 \newline 
3773 Download the file UnxUtils
3774 \begin_inset LatexCommand \index{UnxUtils}
3775
3776 \end_inset 
3777
3778 .zip.
3779  Now you have to install the utilities and setup MSVC so it can locate the
3780  required programs.
3781  Here there are two alternatives (choose one!):
3782 \layout Enumerate
3783
3784 The easy way:
3785 \newline 
3786
3787 \newline 
3788 a) Extract UnxUtils.zip to your C:
3789 \backslash 
3790  hard disk PRESERVING the original paths, otherwise bison won't work.
3791  (If you are using WinZip make certain that 'Use folder names' is selected)
3792 \newline 
3793
3794 \newline 
3795 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3796  in 'Show directories for:' select 'Executable files', and in the directories
3797  window add a new path: 'C:
3798 \backslash 
3799 user
3800 \backslash 
3801 local
3802 \backslash 
3803 wbin', click ok.
3804 \newline 
3805
3806 \newline 
3807 (As a side effect, you get a bunch of Unix utilities that could be useful,
3808  such as diff and patch.)
3809 \layout Enumerate
3810
3811 A more compact way:
3812 \newline 
3813
3814 \newline 
3815 This one avoids extracting a bunch of files you may not use, but requires
3816  some extra work:
3817 \newline 
3818
3819 \newline 
3820 a) Create a directory were to put the tools needed, or use a directory already
3821  present.
3822  Say for example 'C:
3823 \backslash 
3824 util'.
3825 \newline 
3826
3827 \newline 
3828 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3829  to such directory WITHOUT preserving the original paths.
3830  (If you are using WinZip make certain that 'Use folder names' is not selected)
3831 \newline 
3832
3833 \newline 
3834 c) Rename bison.exe to '_bison.exe'.
3835 \newline 
3836
3837 \newline 
3838 d) Create a batch file 'bison.bat' in 'C:
3839 \backslash 
3840 util
3841 \backslash 
3842 ' and add these lines: 
3843 \newline 
3844 \SpecialChar ~
3845 \SpecialChar ~
3846 set BISON_SIMPLE=C:
3847 \backslash 
3848 util
3849 \backslash 
3850 bison.simple 
3851 \newline 
3852 \SpecialChar ~
3853 \SpecialChar ~
3854 set BISON_HAIRY=C:
3855 \backslash 
3856 util
3857 \backslash 
3858 bison.hairy
3859 \newline 
3860 \SpecialChar ~
3861 \SpecialChar ~
3862 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3863 \newline 
3864
3865 \newline 
3866 Steps 'c' and 'd' are needed because bison requires by default that the
3867  files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3868  '/usr/local/share/' I think.
3869  So it is necessary to tell bison where those files are located if they
3870  are not in such directory.
3871  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3872 \newline 
3873
3874 \newline 
3875 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3876  in 'Show directories for:' select 'Executable files', and in the directories
3877  window add a new path: 'c:
3878 \backslash 
3879 util', click ok.
3880  Note that you can use any other path instead of 'c:
3881 \backslash 
3882 util', even the path where the Visual C++ tools are, probably: 'C:
3883 \backslash 
3884 Program Files
3885 \backslash 
3886 Microsoft Visual Studio
3887 \backslash 
3888 Common
3889 \backslash 
3890 Tools'.
3891  So you don't have to execute step 'e' :)
3892 \layout Standard
3893
3894 That is it.
3895  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3896  the executables from sdcc
3897 \backslash 
3898 bin_vc to sdcc
3899 \backslash 
3900 bin, and you can compile using SDCC.
3901 \layout Subsection
3902
3903 Building SDCC Using Borland
3904 \layout Enumerate
3905
3906 From the sdcc directory, run the command "make -f Makefile.bcc".
3907  This should regenerate all the .exe files in the bin directory except for
3908  SDCDB and ucSim.
3909 \layout Enumerate
3910
3911 If you modify any source files and need to rebuild, be aware that the dependenci
3912 es may not be correctly calculated.
3913  The safest option is to delete all .obj files and run the build again.
3914  From a Cygwin BASH prompt, this can easily be done with the command (be
3915  sure you are in the sdcc directory):
3916 \newline 
3917
3918 \newline 
3919
3920 \family sans 
3921 \series bold 
3922 find .
3923  
3924 \backslash 
3925 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
3926 \backslash 
3927 ) -print -exec rm {} 
3928 \backslash 
3929 ;
3930 \family default 
3931 \series default 
3932
3933 \newline 
3934
3935 \newline 
3936 or on Windows NT/2000/XP from the command prompt with the command:
3937 \newline 
3938
3939 \family sans 
3940 \series bold 
3941
3942 \newline 
3943 del /s *.obj *.lib *.rul
3944 \family default 
3945 \series default 
3946  from the sdcc directory.
3947 \layout Subsection
3948
3949 Windows Install Using a ZIP Package
3950 \layout Enumerate
3951
3952 Download the binary zip package from 
3953 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
3954
3955 \end_inset 
3956
3957  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3958  This should unpack to a group of sub-directories.
3959  An example directory structure after unpacking the mingw32 package is:
3960  c:
3961 \backslash 
3962 sdcc
3963 \backslash 
3964 bin for the executables, c:
3965 \backslash 
3966 sdcc
3967 \backslash 
3968 include and c:
3969 \backslash 
3970 sdcc
3971 \backslash 
3972 lib for the include and libraries.
3973 \layout Enumerate
3974
3975 Adjust your environment variable PATH to include the location of the bin
3976  directory or start sdcc using the full path.
3977 \layout Subsection
3978
3979 Windows Install Using the Setup Program
3980 \begin_inset LatexCommand \label{sub:Windows-Install}
3981
3982 \end_inset 
3983
3984
3985 \layout Standard
3986
3987 Download the setup program 
3988 \emph on 
3989 sdcc-x.y.z-setup.exe
3990 \emph default 
3991  for an official release from 
3992 \newline 
3993
3994 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
3995
3996 \end_inset 
3997
3998  or a setup program for one of the snapshots 
3999 \emph on 
4000 sdcc-yyyymmdd-xxxx-setup.exe
4001 \emph default 
4002  from 
4003 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4004
4005 \end_inset 
4006
4007  and execute it.
4008  A windows typical installer will guide you through the installation process.
4009 \layout Subsection
4010
4011 VPATH
4012 \begin_inset LatexCommand \index{VPATH}
4013
4014 \end_inset 
4015
4016  feature
4017 \layout Standard
4018
4019 SDCC supports the VPATH feature provided by configure and make.
4020  It allows to separate the source and build trees.
4021  Here's an example:
4022 \layout Standard
4023
4024
4025 \family typewriter 
4026 cd ~\SpecialChar ~
4027 \SpecialChar ~
4028 \SpecialChar ~
4029 \SpecialChar ~
4030 \SpecialChar ~
4031 \SpecialChar ~
4032 \SpecialChar ~
4033 \SpecialChar ~
4034 \SpecialChar ~
4035 \SpecialChar ~
4036 \SpecialChar ~
4037 \SpecialChar ~
4038 \SpecialChar ~
4039 \SpecialChar ~
4040 \SpecialChar ~
4041 \SpecialChar ~
4042 \SpecialChar ~
4043 \SpecialChar ~
4044 \SpecialChar ~
4045 \SpecialChar ~
4046 \SpecialChar ~
4047 # cd $HOME
4048 \layout Standard
4049
4050
4051 \family typewriter 
4052 tar -xzf sdcc.src.tar.gz\SpecialChar ~
4053 # extract source to directory sdcc
4054 \layout Standard
4055
4056
4057 \family typewriter 
4058 mkdir sdcc.build\SpecialChar ~
4059 \SpecialChar ~
4060 \SpecialChar ~
4061 \SpecialChar ~
4062 \SpecialChar ~
4063 \SpecialChar ~
4064 \SpecialChar ~
4065 \SpecialChar ~
4066 \SpecialChar ~
4067 # put output in sdcc.build
4068 \layout Standard
4069
4070
4071 \family typewriter 
4072 cd sdcc.build
4073 \layout Standard
4074
4075
4076 \family typewriter 
4077 ../sdcc/configure\SpecialChar ~
4078 \SpecialChar ~
4079 \SpecialChar ~
4080 \SpecialChar ~
4081 \SpecialChar ~
4082 \SpecialChar ~
4083 \SpecialChar ~
4084 \SpecialChar ~
4085 # configure is doing all the magic!
4086 \layout Standard
4087
4088
4089 \family typewriter 
4090 make
4091 \layout Standard
4092 \noindent 
4093 That's it! 
4094 \series bold 
4095 configure
4096 \series default 
4097  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4098  It automagically computes the variables srcdir, top_srcdir and top_buildir
4099  for each directory.
4100  After running 
4101 \series bold 
4102 make
4103 \series default 
4104  the generated files will be in ~/sdcc.build, while the source files stay
4105  in ~/sdcc.
4106 \newline 
4107 This is not only usefull for building different binaries, e.g.
4108  when cross compiling.
4109  It also gives you a much better overview in the source tree when all the
4110  generated files are not scattered between the source files.
4111  And the best thing is: if you want to change a file you can leave the original
4112  file untouched in the source directory.
4113  Simply copy it to the build directory, edit it, enter `make clean`, `rm
4114  Makefile.dep` and `make`.
4115  
4116 \series bold 
4117 make
4118 \series default 
4119  will do the rest for you!
4120 \layout Section
4121
4122 Building the Documentation
4123 \layout Standard
4124
4125 Add -
4126 \begin_inset ERT
4127 status Collapsed
4128
4129 \layout Standard
4130
4131 \backslash 
4132 /
4133 \end_inset 
4134
4135 -enable-doc to the configure arguments to build the documentation together
4136  with all the other stuff.
4137  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4138  dvips and makeindex) to get the job done.
4139  Another possibility is to change to the doc directory and to type 
4140 \family sans 
4141 \series bold 
4142
4143 \begin_inset Quotes srd
4144 \end_inset 
4145
4146 make
4147 \begin_inset Quotes srd
4148 \end_inset 
4149
4150
4151 \family default 
4152 \series default 
4153  there.
4154  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4155 x).
4156  Using LyX 
4157 \begin_inset LatexCommand \url{http://www.lyx.org}
4158
4159 \end_inset 
4160
4161  as editor is straightforward.
4162  Prebuilt documentation in html and pdf format is available from 
4163 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4164
4165 \end_inset 
4166
4167 .
4168 \layout Section
4169
4170 Reading the Documentation
4171 \begin_inset LatexCommand \index{Documentation}
4172
4173 \end_inset 
4174
4175
4176 \layout Standard
4177
4178 Currently reading the document in pdf format is recommended, as for unknown
4179  reason the hyperlinks are working there whereas in the html version they
4180  are not
4181 \begin_inset Foot
4182 collapsed false
4183
4184 \layout Standard
4185
4186 If you should know why please drop us a note
4187 \end_inset 
4188
4189 .
4190  
4191 \newline 
4192 You'll find the pdf version
4193 \begin_inset LatexCommand \index{PDF version of this document}
4194
4195 \end_inset 
4196
4197  at 
4198 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4199
4200 \end_inset 
4201
4202 .
4203  
4204 \newline 
4205 A html version
4206 \begin_inset LatexCommand \index{HTML version of this document}
4207
4208 \end_inset 
4209
4210  should be online at 
4211 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4212
4213 \end_inset 
4214
4215 .
4216 \newline 
4217 This documentation is in some aspects different from a commercial documentation:
4218  
4219 \layout Itemize
4220
4221 It tries to document SDCC for several processor architectures in one document
4222  (commercially these probably would be separate documents/products).
4223  This document
4224 \begin_inset LatexCommand \index{Status of documentation}
4225
4226 \end_inset 
4227
4228  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4229 on about f.e.
4230  Z80, PIC14, PIC16 and HC08.
4231 \layout Itemize
4232
4233 There are many references pointing away from this documentation.
4234  Don't let this distract you.
4235  If there f.e.
4236  was a reference like 
4237 \begin_inset LatexCommand \url{http://www.opencores.org}
4238
4239 \end_inset 
4240
4241  together with a statement 
4242 \begin_inset Quotes sld
4243 \end_inset 
4244
4245 some processors which are targetted by SDCC can be implemented in a 
4246 \emph on 
4247 f
4248 \emph default 
4249 ield 
4250 \emph on 
4251 p
4252 \emph default 
4253 rogrammable 
4254 \emph on 
4255 g
4256 \emph default 
4257 ate 
4258 \emph on 
4259 a
4260 \emph default 
4261 rray
4262 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4263
4264 \end_inset 
4265
4266
4267 \begin_inset Quotes srd
4268 \end_inset 
4269
4270  or 
4271 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4272
4273 \end_inset 
4274
4275
4276 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4277
4278 \end_inset 
4279
4280  
4281 \begin_inset Quotes sld
4282 \end_inset 
4283
4284 have you ever heard of an open source compiler that compiles a subset of
4285  C for an FPGA?
4286 \begin_inset Quotes srd
4287 \end_inset 
4288
4289  we expect you to have a quick look there and come back.
4290  If you read this you are on the right track.
4291 \layout Itemize
4292
4293 Some sections attribute more space to problems, restrictions and warnings
4294  than to the solution.
4295 \layout Itemize
4296
4297 The installation section and the section about the debugger is intimidating.
4298 \layout Itemize
4299
4300 There are still lots of typos and there are more different writing styles
4301  than pictures.
4302 \layout Section
4303
4304 Testing the SDCC Compiler
4305 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4306
4307 \end_inset 
4308
4309
4310 \layout Standard
4311
4312 The first thing you should do after installing your SDCC compiler is to
4313  see if it runs.
4314  Type 
4315 \family sans 
4316 \series bold 
4317 "sdcc -
4318 \begin_inset ERT
4319 status Collapsed
4320
4321 \layout Standard
4322
4323 \backslash 
4324 /
4325 \end_inset 
4326
4327 -version"
4328 \begin_inset LatexCommand \index{version}
4329
4330 \end_inset 
4331
4332
4333 \family default 
4334 \series default 
4335  at the prompt, and the program should run and output its version like:
4336  
4337 \newline 
4338
4339 \family typewriter 
4340 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4341  (UNIX)
4342 \layout Standard
4343
4344 If it doesn't run, or gives a message about not finding sdcc program, then
4345  you need to check over your installation.
4346  Make sure that the sdcc bin directory is in your executable search path
4347  defined by the PATH environment setting (
4348 \series medium 
4349 see 
4350 \series default 
4351 section 
4352 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4353
4354 \end_inset 
4355
4356 \SpecialChar ~
4357
4358 \series medium 
4359 Install trouble-shooting for suggestions
4360 \series default 
4361 ).
4362  Make sure that the sdcc program is in the bin folder, if not perhaps something
4363  did not install correctly.
4364 \newline 
4365
4366 \newline 
4367
4368 \series medium 
4369 SDCC 
4370 \series default 
4371 is commonly installed as described in section 
4372 \begin_inset Quotes sld
4373 \end_inset 
4374
4375 Install and search paths
4376 \begin_inset Quotes srd
4377 \end_inset 
4378
4379 .
4380 \newline 
4381
4382 \newline 
4383
4384 \series medium 
4385 Make sure the compiler works on a very simple example.
4386  Type in the following test.c program using your favorite 
4387 \series default 
4388 ASCII 
4389 \series medium 
4390 editor:
4391 \layout Verse
4392
4393
4394 \family typewriter 
4395 char test;
4396 \newline 
4397
4398 \newline 
4399 void main(void) {
4400 \newline 
4401 \SpecialChar ~
4402 \SpecialChar ~
4403 \SpecialChar ~
4404 \SpecialChar ~
4405 test=0;
4406 \newline 
4407 }
4408 \layout Standard
4409
4410
4411 \series medium 
4412 Compile this using the following command: 
4413 \family sans 
4414 \series bold 
4415 "sdcc -c test.c".
4416
4417 \family default 
4418 \series default 
4419  
4420 \series medium 
4421 If all goes well, the compiler will generate a test.asm and test.rel file.
4422  Congratulations, you've just compiled your first program with SDCC.
4423  We used the -c option to tell SDCC not to link the generated code, just
4424  to keep things simple for this step.
4425 \series default 
4426
4427 \newline 
4428
4429 \newline 
4430
4431 \series medium 
4432 The next step is to try it with the linker.
4433  Type in 
4434 \family sans 
4435 \series bold 
4436 "sdcc test.c
4437 \family default 
4438 \series default 
4439 "
4440 \series medium 
4441 .
4442  If all goes well the compiler will link with the libraries and produce
4443  a test.ihx output file.
4444  If this step fails
4445 \series default 
4446  
4447 \series medium 
4448 (no test.ihx, and the linker generates warnings), then the problem is most
4449  likely that 
4450 \series default 
4451 SDCC
4452 \series medium 
4453  cannot find the 
4454 \series default 
4455 /
4456 \series medium 
4457 usr/local/share/sdcc/lib directory
4458 \series default 
4459  
4460 \series medium 
4461 (see 
4462 \series default 
4463 section 
4464 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4465
4466 \end_inset 
4467
4468 \SpecialChar ~
4469
4470 \series medium 
4471 Install trouble-shooting for suggestions).
4472 \series default 
4473
4474 \newline 
4475
4476 \newline 
4477
4478 \series medium 
4479 The final test is to ensure 
4480 \series default 
4481 SDCC
4482 \series medium 
4483  can use the 
4484 \series default 
4485 standard
4486 \series medium 
4487  header files and libraries.
4488  Edit test.c and change it to the following:
4489 \layout Verse
4490
4491
4492 \family typewriter 
4493 #include <string.h>
4494 \newline 
4495
4496 \newline 
4497 char str1[10];
4498 \newline 
4499
4500 \newline 
4501 void main(void) {
4502 \newline 
4503 \SpecialChar ~
4504 \SpecialChar ~
4505 strcpy(str1, "testing");
4506 \newline 
4507 }
4508 \layout Standard
4509
4510
4511 \series medium 
4512 Compile this by typing 
4513 \family sans 
4514 \series bold 
4515 "sdcc test.c"
4516 \family default 
4517 \series medium 
4518 .
4519  This should generate a test.ihx output file, and it should give no warnings
4520  such as not finding the string.h file.
4521  If it cannot find the string.h file, then the problem is that 
4522 \series default 
4523 SDCC
4524 \series medium 
4525  cannot find the /usr/local/share/sdcc/include directory
4526 \series default 
4527  
4528 \series medium 
4529 (see the 
4530 \series default 
4531 section 
4532 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4533
4534 \end_inset 
4535
4536 \SpecialChar ~
4537
4538 \series medium 
4539 Install trouble-shooting section for suggestions).
4540
4541 \series default 
4542  Use option 
4543 \series bold 
4544 -
4545 \begin_inset ERT
4546 status Collapsed
4547
4548 \layout Standard
4549
4550 \backslash 
4551 /
4552 \end_inset 
4553
4554 -print-search-dirs
4555 \series default 
4556
4557 \begin_inset LatexCommand \index{-\/-print-search-dirs}
4558
4559 \end_inset 
4560
4561  to find exactly where SDCC is looking for the include and lib files.
4562 \layout Section
4563
4564 Install Trouble-shooting
4565 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
4566
4567 \end_inset 
4568
4569
4570 \begin_inset LatexCommand \index{Install trouble-shooting}
4571
4572 \end_inset 
4573
4574
4575 \layout Subsection
4576
4577 If SDCC does not build correctly
4578 \layout Standard
4579
4580 A thing to try is starting from scratch by unpacking the .tgz source package
4581  again in an empty directory.
4582  Configure it like:
4583 \newline 
4584
4585 \newline 
4586
4587 \family sans 
4588 \series bold 
4589 ./configure 2>&1 | tee configure.log
4590 \family default 
4591 \series default 
4592
4593 \newline 
4594
4595 \newline 
4596 and build it like:
4597 \newline 
4598
4599 \newline 
4600
4601 \family sans 
4602 \series bold 
4603 make 2>&1 | tee make.log
4604 \family default 
4605 \series default 
4606
4607 \newline 
4608
4609 \newline 
4610 If anything goes wrong, you can review the log files to locate the problem.
4611  Or a relevant part of this can be attached to an email that could be helpful
4612  when requesting help from the mailing list.
4613 \layout Subsection
4614
4615 What the 
4616 \begin_inset Quotes sld
4617 \end_inset 
4618
4619 ./configure
4620 \begin_inset Quotes srd
4621 \end_inset 
4622
4623  does
4624 \layout Standard
4625
4626 The 
4627 \begin_inset Quotes sld
4628 \end_inset 
4629
4630 ./configure
4631 \begin_inset Quotes srd
4632 \end_inset 
4633
4634  command is a script that analyzes your system and performs some configuration
4635  to ensure the source package compiles on your system.
4636  It will take a few minutes to run, and will compile a few tests to determine
4637  what compiler features are installed.
4638 \layout Subsection
4639
4640 What the 
4641 \begin_inset Quotes sld
4642 \end_inset 
4643
4644 make
4645 \begin_inset Quotes srd
4646 \end_inset 
4647
4648  does
4649 \layout Standard
4650
4651 This runs the GNU make tool, which automatically compiles all the source
4652  packages into the final installed binary executables.
4653 \layout Subsection
4654
4655 What the 
4656 \begin_inset Quotes sld
4657 \end_inset 
4658
4659 make install
4660 \begin_inset Quotes erd
4661 \end_inset 
4662
4663  command does.
4664 \layout Standard
4665
4666 This will install the compiler, other executables libraries and include
4667  files into the appropriate directories.
4668  See sections 
4669 \begin_inset LatexCommand \ref{sub:Install-paths}
4670
4671 \end_inset 
4672
4673 ,\SpecialChar ~
4674
4675 \begin_inset LatexCommand \ref{sub:Search-Paths}
4676
4677 \end_inset 
4678
4679 \SpecialChar ~
4680 about install and search paths.
4681 \newline 
4682 On most systems you will need super-user privileges to do this.
4683 \layout Section
4684
4685 Components of SDCC
4686 \layout Standard
4687
4688 SDCC is not just a compiler, but a collection of tools by various developers.
4689  These include linkers, assemblers, simulators and other components.
4690  Here is a summary of some of the components.
4691  Note that the included simulator and assembler have separate documentation
4692  which you can find in the source package in their respective directories.
4693  As SDCC grows to include support for other processors, other packages from
4694  various developers are included and may have their own sets of documentation.
4695 \newline 
4696
4697 \newline 
4698 You might want to look at the files which are installed in <installdir>.
4699  At the time of this writing, we find the following programs for gcc-builds:
4700 \newline 
4701  
4702 \newline 
4703 In <installdir>/bin:
4704 \layout Itemize
4705
4706 sdcc - The compiler.
4707 \layout Itemize
4708
4709 sdcpp - The C preprocessor.
4710 \layout Itemize
4711
4712 asx8051 - The assembler for 8051 type processors.
4713 \layout Itemize
4714
4715 as-z80
4716 \series bold 
4717
4718 \series default 
4719 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4720 \layout Itemize
4721
4722 aslink -The linker for 8051 type processors.
4723 \layout Itemize
4724
4725 link-z80
4726 \series bold 
4727
4728 \series default 
4729 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4730 \layout Itemize
4731
4732 s51 - The ucSim 8051 simulator.
4733 \layout Itemize
4734
4735 sdcdb - The source debugger.
4736 \layout Itemize
4737
4738 packihx - A tool to pack (compress) Intel hex files.
4739 \layout Standard
4740
4741 In <installdir>/share/sdcc/include
4742 \layout Itemize
4743
4744 the include files
4745 \layout Standard
4746
4747 In <installdir>/share/sdcc/lib
4748 \layout Itemize
4749
4750 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4751  relocatables.
4752 \layout Standard
4753
4754 In <installdir>/share/sdcc/doc
4755 \layout Itemize
4756
4757 the documentation
4758 \layout Standard
4759
4760 As development for other processors proceeds, this list will expand to include
4761  executables to support processors like AVR, PIC, etc.
4762 \layout Subsection
4763
4764 sdcc - The Compiler
4765 \layout Standard
4766
4767 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4768  the assembler and linkage editor.
4769 \layout Subsection
4770
4771 sdcpp - The C-Preprocessor
4772 \layout Standard
4773
4774 The preprocessor
4775 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4776
4777 \end_inset 
4778
4779  is a modified version of the GNU cpp
4780 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
4781
4782 \end_inset 
4783
4784  preprocessor 
4785 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
4786
4787 \end_inset 
4788
4789 .
4790  The C preprocessor is used to pull in #include sources, process #ifdef
4791  statements, #defines and so on.
4792 \layout Subsection
4793
4794 as
4795 \emph on 
4796 xxxx
4797 \emph default 
4798 , aslink, link-
4799 \emph on 
4800 xxx
4801 \emph default 
4802  - The Assemblers and Linkage Editors
4803 \layout Standard
4804
4805 This is retargettable assembler & linkage editor, it was developed by Alan
4806  Baldwin.
4807  John Hartman created the version for 8051, and I (Sandeep) have made some
4808  enhancements and bug fixes for it to work properly with SDCC.
4809 \layout Subsection
4810
4811 s51 - The Simulator
4812 \layout Standard
4813
4814 S51
4815 \begin_inset LatexCommand \index{s51}
4816
4817 \end_inset 
4818
4819  is a freeware, opensource simulator developed by Daniel Drotos.
4820  The simulator is built as part of the build process.
4821  For more information visit Daniel's web site at: 
4822 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4823
4824 \end_inset 
4825
4826 .
4827  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4828  XA51 family.
4829 \layout Subsection
4830
4831 sdcdb - Source Level Debugger
4832 \layout Standard
4833
4834 SDCDB
4835 \begin_inset LatexCommand \index{SDCDB (debugger)}
4836
4837 \end_inset 
4838
4839  is the companion source level debugger.
4840  More about SDCDB in section 
4841 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4842
4843 \end_inset 
4844
4845 .
4846  The current version of the debugger uses Daniel's Simulator S51
4847 \begin_inset LatexCommand \index{s51}
4848
4849 \end_inset 
4850
4851 , but can be easily changed to use other simulators.
4852 \layout Chapter
4853
4854 Using SDCC
4855 \layout Section
4856
4857 Compiling
4858 \layout Subsection
4859
4860 Single Source File Projects
4861 \layout Standard
4862
4863 For single source file 8051 projects the process is very simple.
4864  Compile your programs with the following command 
4865 \family sans 
4866 \series bold 
4867 "sdcc sourcefile.c".
4868
4869 \family default 
4870 \series default 
4871  This will compile, assemble and link your source file.
4872  Output files are as follows:
4873 \layout Itemize
4874
4875 sourcefile.asm
4876 \begin_inset LatexCommand \index{<file>.asm}
4877
4878 \end_inset 
4879
4880  - Assembler source
4881 \begin_inset LatexCommand \index{Assembler source}
4882
4883 \end_inset 
4884
4885  file created by the compiler
4886 \layout Itemize
4887
4888 sourcefile.lst
4889 \begin_inset LatexCommand \index{<file>.lst}
4890
4891 \end_inset 
4892
4893  - Assembler listing
4894 \begin_inset LatexCommand \index{Assembler listing}
4895
4896 \end_inset 
4897
4898  file created by the Assembler
4899 \layout Itemize
4900
4901 sourcefile.rst
4902 \begin_inset LatexCommand \index{<file>.rst}
4903
4904 \end_inset 
4905
4906  - Assembler listing
4907 \begin_inset LatexCommand \index{Assembler listing}
4908
4909 \end_inset 
4910
4911  file updated with linkedit information, created by linkage editor
4912 \layout Itemize
4913
4914 sourcefile.sym
4915 \begin_inset LatexCommand \index{<file>.sym}
4916
4917 \end_inset 
4918
4919  - symbol listing
4920 \begin_inset LatexCommand \index{Symbol listing}
4921
4922 \end_inset 
4923
4924  for the sourcefile, created by the assembler
4925 \layout Itemize
4926
4927 sourcefile.rel
4928 \begin_inset LatexCommand \index{<file>.rel}
4929
4930 \end_inset 
4931
4932  or sourcefile.o
4933 \begin_inset LatexCommand \index{<file>.o}
4934
4935 \end_inset 
4936
4937  - Object file
4938 \begin_inset LatexCommand \index{Object file}
4939
4940 \end_inset 
4941
4942  created by the assembler, input to Linkage editor
4943 \layout Itemize
4944
4945 sourcefile.map
4946 \begin_inset LatexCommand \index{<file>.map}
4947
4948 \end_inset 
4949
4950  - The memory map
4951 \begin_inset LatexCommand \index{Memory map}
4952
4953 \end_inset 
4954
4955  for the load module, created by the Linker
4956 \layout Itemize
4957
4958 sourcefile.mem
4959 \begin_inset LatexCommand \index{<file>.mem}
4960
4961 \end_inset 
4962
4963  - A file with a summary of the memory usage
4964 \layout Itemize
4965
4966 sourcefile.ihx
4967 \begin_inset LatexCommand \index{<file>.ihx}
4968
4969 \end_inset 
4970
4971  - The load module in Intel hex format
4972 \begin_inset LatexCommand \index{Intel hex format}
4973
4974 \end_inset 
4975
4976  (you can select the Motorola S19 format
4977 \begin_inset LatexCommand \index{Motorola S19 format}
4978
4979 \end_inset 
4980
4981  with -
4982 \begin_inset ERT
4983 status Collapsed
4984
4985 \layout Standard
4986
4987 \backslash 
4988 /
4989 \end_inset 
4990
4991 -out-fmt-s19
4992 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4993
4994 \end_inset 
4995
4996 .
4997  If you need another format you might want to use 
4998 \family sans 
4999 \shape italic 
5000 objdump
5001 \family default 
5002 \shape default 
5003
5004 \begin_inset LatexCommand \index{objdump (tool)}
5005
5006 \end_inset 
5007
5008  or
5009 \family sans 
5010 \shape italic 
5011  srecord
5012 \family default 
5013 \shape default 
5014
5015 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5016
5017 \end_inset 
5018
5019 ).
5020  Both formats are documented in the documentation of srecord
5021 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5022
5023 \end_inset 
5024
5025
5026 \layout Itemize
5027
5028 sourcefile.adb
5029 \begin_inset LatexCommand \index{<file>.adb}
5030
5031 \end_inset 
5032
5033  - An intermediate file containing debug information needed to create the
5034  .cdb file (with -
5035 \begin_inset ERT
5036 status Collapsed
5037
5038 \layout Standard
5039
5040 \backslash 
5041 /
5042 \end_inset 
5043
5044 -debug
5045 \begin_inset LatexCommand \index{-\/-debug}
5046
5047 \end_inset 
5048
5049
5050 \layout Itemize
5051
5052 sourcefile.cdb
5053 \begin_inset LatexCommand \index{<file>.cdb}
5054
5055 \end_inset 
5056
5057  - An optional file (with -
5058 \begin_inset ERT
5059 status Collapsed
5060
5061 \layout Standard
5062
5063 \backslash 
5064 /
5065 \end_inset 
5066
5067 -debug) containing debug information.
5068  The format is documented in cdbfileformat.pdf
5069 \layout Itemize
5070
5071 sourcefile.
5072  - (no extension)
5073 \begin_inset LatexCommand \index{<file> (no extension)}
5074
5075 \end_inset 
5076
5077  An optional AOMF or AOMF51
5078 \begin_inset LatexCommand \index{AOMF, AOMF51}
5079
5080 \end_inset 
5081
5082  
5083 \begin_inset LatexCommand \label{OMF file}
5084
5085 \end_inset 
5086
5087 file containing debug information (generated with option -
5088 \begin_inset ERT
5089 status Collapsed
5090
5091 \layout Standard
5092
5093 \backslash 
5094 /
5095 \end_inset 
5096
5097 -debug).
5098  The (Intel)
5099 \emph on 
5100  a
5101 \emph default 
5102 bsolute 
5103 \emph on 
5104 o
5105 \emph default 
5106 bject 
5107 \emph on 
5108 m
5109 \emph default 
5110 odule 
5111 \emph on 
5112 f
5113 \emph default 
5114 ormat is commonly used by third party tools (debuggers
5115 \begin_inset LatexCommand \index{Debugger}
5116
5117 \end_inset 
5118
5119 , simulators, emulators)
5120 \layout Itemize
5121
5122 sourcefile.dump*
5123 \begin_inset LatexCommand \index{<file>.dump*}
5124
5125 \end_inset 
5126
5127  - Dump file to debug the compiler it self (generated with option -
5128 \begin_inset ERT
5129 status Collapsed
5130
5131 \layout Standard
5132
5133 \backslash 
5134 /
5135 \end_inset 
5136
5137 -dumpall) (see section 
5138 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5139
5140 \end_inset 
5141
5142 \SpecialChar ~
5143  and section 
5144 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5145
5146 \end_inset 
5147
5148 \SpecialChar ~
5149
5150 \begin_inset Quotes sld
5151 \end_inset 
5152
5153 Anatomy of the compiler
5154 \begin_inset Quotes srd
5155 \end_inset 
5156
5157 ).
5158 \layout Subsection
5159
5160 Postprocessing the Intel Hex
5161 \begin_inset LatexCommand \index{Intel hex format}
5162
5163 \end_inset 
5164
5165  file
5166 \layout Standard
5167
5168 In most cases this won't be needed but the Intel Hex file
5169 \begin_inset LatexCommand \index{<file>.ihx}
5170
5171 \end_inset 
5172
5173  which is generated by SDCC might include lines of varying length and the
5174  addresses within the file are not guaranteed to be strictly ascending.
5175  If your toolchain or a bootloader does not like this you can use the tool
5176  
5177 \family typewriter 
5178 packihx
5179 \family default 
5180
5181 \begin_inset LatexCommand \index{packihx (tool)}
5182
5183 \end_inset 
5184
5185  which is part of the SDCC distribution: 
5186 \newline 
5187
5188 \newline 
5189
5190 \family sans 
5191 \series bold 
5192  packihx sourcefile.ihx >sourcefile.hex
5193 \family default 
5194 \series default 
5195
5196 \newline 
5197
5198 \newline 
5199 The separately available
5200 \emph on 
5201  srecord
5202 \emph default 
5203
5204 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5205
5206 \end_inset 
5207
5208  package additionally allows to set undefined locations to a predefined
5209  value, to insert checksums
5210 \begin_inset LatexCommand \index{checksum}
5211
5212 \end_inset 
5213
5214  of various flavours (crc, add, xor) and to perform other manipulations
5215  (convert, split, crop, offset, ...).
5216  
5217 \newline 
5218
5219 \newline 
5220
5221 \family sans 
5222 \series bold 
5223 srec_cat\SpecialChar ~
5224 \SpecialChar ~
5225 sourcefile.ihx -intel\SpecialChar ~
5226 \SpecialChar ~
5227 -o sourcefile.hex -intel
5228 \newline 
5229
5230 \newline 
5231
5232 \family default 
5233 \series default 
5234 An example for a more complex command line
5235 \begin_inset Foot
5236 collapsed false
5237
5238 \layout Standard
5239
5240 the command backfills
5241 \begin_inset LatexCommand \index{backfill unused memory}
5242
5243 \end_inset 
5244
5245  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5246  block is zero.
5247  If the program counter on an mcs51 runs wild the backfill pattern 0x12
5248  will be interpreted as an 
5249 \family typewriter 
5250 lcall
5251 \family default 
5252  to address 
5253 \family typewriter 
5254 0x1212
5255 \family default 
5256  (where an emergency routine could sit).
5257 \end_inset 
5258
5259  could look like:
5260 \newline 
5261
5262 \newline 
5263
5264 \family sans 
5265 \series bold 
5266 \size footnotesize 
5267 srec_cat\SpecialChar ~
5268 sourcefile.ihx -intel\SpecialChar ~
5269 \SpecialChar ~
5270 -fill 0x12 0x0000 0xfffe\SpecialChar ~
5271 -little-endian-checksum-nega
5272 tive 0xfffe 0x02 0x02\SpecialChar ~
5273 \SpecialChar ~
5274 -o sourcefile.hex -intel
5275 \size default 
5276
5277 \newline 
5278
5279 \newline 
5280
5281 \family default 
5282 \series default 
5283 The srecord package is available at 
5284 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5285
5286 \end_inset 
5287
5288  .
5289 \layout Subsection
5290
5291 Projects with Multiple Source Files
5292 \layout Standard
5293
5294 SDCC can compile only ONE file at a time.
5295  Let us for example assume that you have a project containing the following
5296  files:
5297 \newline 
5298
5299 \newline 
5300 foo1.c (contains some functions)
5301 \newline 
5302 foo2.c (contains some more functions)
5303 \newline 
5304 foomain.c (contains more functions and the function main)
5305 \newline 
5306
5307 \size footnotesize 
5308
5309 \newline 
5310
5311 \size default 
5312 The first two files will need to be compiled separately with the commands:
5313 \size footnotesize 
5314  
5315 \size default 
5316
5317 \newline 
5318
5319 \newline 
5320
5321 \family sans 
5322 \series bold 
5323 sdcc\SpecialChar ~
5324 -c\SpecialChar ~
5325 foo1.c
5326 \family default 
5327 \series default 
5328 \size footnotesize 
5329
5330 \newline 
5331
5332 \family sans 
5333 \series bold 
5334 \size default 
5335 sdcc\SpecialChar ~
5336 -c\SpecialChar ~
5337 foo2.c
5338 \family default 
5339 \series default 
5340
5341 \newline 
5342
5343 \newline 
5344 Then compile the source file containing the 
5345 \emph on 
5346 main()
5347 \emph default 
5348  function and link
5349 \begin_inset LatexCommand \index{Linker}
5350
5351 \end_inset 
5352
5353  the files together with the following command: 
5354 \newline 
5355
5356 \newline 
5357
5358 \family sans 
5359 \series bold 
5360 sdcc\SpecialChar ~
5361 foomain.c\SpecialChar ~
5362 foo1.rel\SpecialChar ~
5363 foo2.rel
5364 \family default 
5365 \series default 
5366
5367 \begin_inset LatexCommand \index{<file>.rel}
5368
5369 \end_inset 
5370
5371
5372 \newline 
5373
5374 \newline 
5375 Alternatively, 
5376 \emph on 
5377 foomain.c 
5378 \emph default 
5379 can be separately compiled as well: 
5380 \family sans 
5381 \series bold 
5382
5383 \newline 
5384
5385 \newline 
5386 sdcc\SpecialChar ~
5387 -c\SpecialChar ~
5388 foomain.c
5389 \newline 
5390 sdcc foomain.rel foo1.rel foo2.rel
5391 \newline 
5392
5393 \newline 
5394
5395 \family default 
5396 \series default 
5397 The file containing the 
5398 \emph on 
5399 main()
5400 \emph default 
5401  function
5402 \emph on 
5403  
5404 \emph default 
5405 \noun on 
5406 must
5407 \noun default 
5408  be the 
5409 \noun on 
5410 first
5411 \noun default 
5412  file specified in the command line, since the linkage editor processes
5413  file in the order they are presented to it.
5414  The linker is invoked from SDCC using a script file with extension .lnk
5415 \begin_inset LatexCommand \index{<file>.lnk}
5416
5417 \end_inset 
5418
5419 .
5420  You can view this file to troubleshoot linking problems such as those arising
5421  from missing libraries.
5422 \layout Subsection
5423
5424 Projects with Additional Libraries
5425 \begin_inset LatexCommand \index{Libraries}
5426
5427 \end_inset 
5428
5429
5430 \layout Standard
5431
5432 Some reusable routines may be compiled into a library, see the documentation
5433  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
5434  for how to create a 
5435 \emph on 
5436 .lib
5437 \begin_inset LatexCommand \index{<file>.lib}
5438
5439 \end_inset 
5440
5441
5442 \emph default 
5443  library file.
5444  Libraries created in this manner can be included in the command line.
5445  Make sure you include the -L <library-path> option to tell the linker where
5446  to look for these files if they are not in the current directory.
5447  Here is an example, assuming you have the source file 
5448 \emph on 
5449 foomain.c
5450 \emph default 
5451  and a library
5452 \emph on 
5453  foolib.lib
5454 \emph default 
5455  in the directory 
5456 \emph on 
5457 mylib
5458 \emph default 
5459  (if that is not the same as your current project):
5460 \newline 
5461
5462 \newline 
5463
5464 \family sans 
5465 \series bold 
5466 sdcc foomain.c foolib.lib -L mylib
5467 \newline 
5468
5469 \newline 
5470
5471 \family default 
5472 \series default 
5473 Note here that
5474 \emph on 
5475  mylib
5476 \emph default 
5477  must be an absolute path name.
5478 \newline 
5479
5480 \newline 
5481 The most efficient way to use libraries is to keep separate modules in separate
5482  source files.
5483  The lib file now should name all the modules.rel
5484 \begin_inset LatexCommand \index{<file>.rel}
5485
5486 \end_inset 
5487
5488  files.
5489  For an example see the standard library file 
5490 \emph on 
5491 libsdcc.lib
5492 \emph default 
5493  in the directory <installdir>/share/lib/small.
5494 \layout Subsection
5495
5496 Using sdcclib to Create and Manage Libraries
5497 \begin_inset LatexCommand \index{sdcclib}
5498
5499 \end_inset 
5500
5501
5502 \layout Standard
5503
5504 Alternatively, instead of having a .rel file for each entry on the library
5505  file as described in the preceding section, sdcclib can be used to embed
5506  all the modules belonging to such library in the library file itself.
5507  This results in a larger library file, but it greatly reduces the number
5508  of disk files accessed by the linker.
5509   Additionally, the packed library file contains an index of all include
5510  modules and symbols that significantly speeds up the linking process.
5511  To display a list of options supported by sdcclib type:
5512 \newline 
5513
5514 \layout Standard
5515
5516
5517 \family sans 
5518 \series bold 
5519 sdcclib -?
5520 \begin_inset LatexCommand \index{sdcclib}
5521
5522 \end_inset 
5523
5524
5525 \newline 
5526
5527 \newline 
5528
5529 \family default 
5530 \series default 
5531 To create a new library file, start by compiling all the required modules.
5532  For example:
5533 \newline 
5534
5535 \layout Standard
5536
5537
5538 \family sans 
5539 \series bold 
5540 sdcc -c _divsint.c
5541 \layout Standard
5542
5543
5544 \family sans 
5545 \series bold 
5546 sdcc -c _divuint.c
5547 \layout Standard
5548
5549
5550 \family sans 
5551 \series bold 
5552 sdcc -c _modsint.c
5553 \layout Standard
5554
5555
5556 \family sans 
5557 \series bold 
5558 sdcc -c _moduint.c
5559 \layout Standard
5560
5561
5562 \family sans 
5563 \series bold 
5564 sdcc -c _mulint.c
5565 \newline 
5566
5567 \layout Standard
5568
5569 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
5570  and _mulint.rel.
5571  The next step is to add the .rel files to the library file:
5572 \newline 
5573
5574 \layout Standard
5575
5576
5577 \family sans 
5578 \series bold 
5579 sdcclib libint.lib _divsint.rel
5580 \family default 
5581
5582 \begin_inset LatexCommand \index{sdcclib}
5583
5584 \end_inset 
5585
5586
5587 \layout Standard
5588
5589
5590 \family sans 
5591 \series bold 
5592 sdcclib libint.lib _divuint.rel
5593 \layout Standard
5594
5595
5596 \family sans 
5597 \series bold 
5598 sdcclib libint.lib _modsint.rel
5599 \layout Standard
5600
5601
5602 \family sans 
5603 \series bold 
5604 sdcclib libint.lib _moduint.rel
5605 \layout Standard
5606
5607
5608 \family sans 
5609 \series bold 
5610 sdcclib libint.lib _mulint.rel
5611 \series default 
5612
5613 \newline 
5614
5615 \layout Standard
5616
5617 If the file already exists in the library, it will be replaced.
5618  To see what modules and symbols are included in the library, options -s
5619  and -m are available.
5620  For example:
5621 \newline 
5622
5623 \newline 
5624
5625 \family sans 
5626 \series bold 
5627 sdcclib -s libint.lib
5628 \family default 
5629
5630 \begin_inset LatexCommand \index{sdcclib}
5631
5632 \end_inset 
5633
5634
5635 \newline 
5636
5637 \family typewriter 
5638 \series default 
5639 _divsint.rel:
5640 \layout Standard
5641
5642
5643 \family typewriter 
5644 __divsint_a_1_1
5645 \layout Standard
5646
5647
5648 \family typewriter 
5649 __divsint_PARM_2
5650 \layout Standard
5651
5652
5653 \family typewriter 
5654 __divsint
5655 \newline 
5656 _divuint.rel:
5657 \layout Standard
5658
5659
5660 \family typewriter 
5661 __divuint_a_1_1
5662 \layout Standard
5663
5664
5665 \family typewriter 
5666 __divuint_PARM_2
5667 \layout Standard
5668
5669
5670 \family typewriter 
5671 __divuint_reste_1_1
5672 \layout Standard
5673
5674
5675 \family typewriter 
5676 __divuint_count_1_1
5677 \layout Standard
5678
5679
5680 \family typewriter 
5681 __divuint
5682 \newline 
5683 _modsint.rel:
5684 \layout Standard
5685
5686
5687 \family typewriter 
5688 __modsint_a_1_1
5689 \layout Standard
5690
5691
5692 \family typewriter 
5693 __modsint_PARM_2
5694 \layout Standard
5695
5696
5697 \family typewriter 
5698 __modsint
5699 \newline 
5700 _moduint.rel:
5701 \layout Standard
5702
5703
5704 \family typewriter 
5705 __moduint_a_1_1
5706 \layout Standard
5707
5708
5709 \family typewriter 
5710 __moduint_PARM_2
5711 \layout Standard
5712
5713
5714 \family typewriter 
5715 __moduint_count_1_1
5716 \layout Standard
5717
5718
5719 \family typewriter 
5720 __moduint
5721 \newline 
5722 _mulint.rel:
5723 \layout Standard
5724
5725
5726 \family typewriter 
5727 __mulint_PARM_2
5728 \layout Standard
5729
5730
5731 \family typewriter 
5732 __mulint
5733 \family default 
5734 \series bold 
5735
5736 \newline 
5737
5738 \layout Standard
5739 \added_space_bottom bigskip 
5740 If the source files are compiled using -
5741 \begin_inset ERT
5742 status Collapsed
5743
5744 \layout Standard
5745
5746 \backslash 
5747 /
5748 \end_inset 
5749
5750 -debug
5751 \begin_inset LatexCommand \index{-\/-debug}
5752
5753 \end_inset 
5754
5755 , the corresponding debug information file .adb will be include in the library
5756  file as well.
5757  The library files created with sdcclib are plain text files, so they can
5758  be viewed with a text editor.
5759  It is not recomended to modify a library file created with sdcclib using
5760  a text editor, as there are file indexes numbers located accross the file
5761  used by the linker to quickly locate the required module to link.
5762  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
5763  it can be safely deleted, since all the information required for linking
5764  is embedded in the library file itself.
5765  Library files created using sdcclib are used as described in the preceding
5766  sections.
5767 \layout Section
5768
5769 Command Line Options
5770 \begin_inset LatexCommand \index{Command Line Options}
5771
5772 \end_inset 
5773
5774
5775 \layout Subsection
5776
5777 Processor Selection Options
5778 \begin_inset LatexCommand \index{Options processor selection}
5779
5780 \end_inset 
5781
5782
5783 \begin_inset LatexCommand \index{Processor selection options}
5784
5785 \end_inset 
5786
5787
5788 \layout List
5789 \labelwidthstring 00.00.0000
5790
5791
5792 \series bold 
5793 -mmcs51
5794 \begin_inset LatexCommand \index{-mmcs51}
5795
5796 \end_inset 
5797
5798
5799 \series default 
5800  Generate code for the Intel MCS51
5801 \begin_inset LatexCommand \index{MCS51}
5802
5803 \end_inset 
5804
5805  family of processors.
5806  This is the default processor target.
5807 \layout List
5808 \labelwidthstring 00.00.0000
5809
5810
5811 \series bold 
5812 -mds390
5813 \begin_inset LatexCommand \index{-mds390}
5814
5815 \end_inset 
5816
5817
5818 \series default 
5819  Generate code for the Dallas DS80C390
5820 \begin_inset LatexCommand \index{DS80C390}
5821
5822 \end_inset 
5823
5824  processor.
5825 \layout List
5826 \labelwidthstring 00.00.0000
5827
5828
5829 \series bold 
5830 -mds400
5831 \begin_inset LatexCommand \index{-mds400}
5832
5833 \end_inset 
5834
5835
5836 \series default 
5837  Generate code for the Dallas DS80C400
5838 \begin_inset LatexCommand \index{DS80C400}
5839
5840 \end_inset 
5841
5842  processor.
5843 \layout List
5844 \labelwidthstring 00.00.0000
5845
5846
5847 \series bold 
5848 -mhc08
5849 \begin_inset LatexCommand \index{-mhc08}
5850
5851 \end_inset 
5852
5853
5854 \series default 
5855  Generate code for the Freescale/Motorola HC08
5856 \begin_inset LatexCommand \index{HC08}
5857
5858 \end_inset 
5859
5860  family of processors.
5861 \layout List
5862 \labelwidthstring 00.00.0000
5863
5864
5865 \series bold 
5866 -mz80
5867 \begin_inset LatexCommand \index{-mz80}
5868
5869 \end_inset 
5870
5871
5872 \series default 
5873  Generate code for the Zilog Z80
5874 \begin_inset LatexCommand \index{Z80}
5875
5876 \end_inset 
5877
5878  family of processors.
5879 \layout List
5880 \labelwidthstring 00.00.0000
5881
5882
5883 \series bold 
5884 -mgbz80
5885 \begin_inset LatexCommand \index{-mgbz80}
5886
5887 \end_inset 
5888
5889
5890 \series default 
5891  Generate code for the GameBoy Z80
5892 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
5893
5894 \end_inset 
5895
5896  processor (Not actively maintained).
5897 \layout List
5898 \labelwidthstring 00.00.0000
5899
5900
5901 \series bold 
5902 -mavr
5903 \begin_inset LatexCommand \index{-mavr}
5904
5905 \end_inset 
5906
5907
5908 \series default 
5909  Generate code for the Atmel AVR
5910 \begin_inset LatexCommand \index{AVR}
5911
5912 \end_inset 
5913
5914  processor (Not maintained, not complete).
5915  AVR users should probably have a look at winavr 
5916 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
5917
5918 \end_inset 
5919
5920  or 
5921 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
5922
5923 \end_inset 
5924
5925 .
5926 \layout Standard
5927
5928
5929 \begin_inset Note
5930 collapsed true
5931
5932 \layout Standard
5933
5934 I think it is fair to direct users there for now.
5935  Open source is also about avoiding unnecessary work .
5936  But I didn't find the 'official' link.
5937 \end_inset 
5938
5939
5940 \layout List
5941 \labelwidthstring 00.00.0000
5942
5943
5944 \series bold 
5945 -mpic14
5946 \begin_inset LatexCommand \index{-mpic14}
5947
5948 \end_inset 
5949
5950
5951 \series default 
5952  Generate code for the Microchip PIC 14
5953 \begin_inset LatexCommand \index{PIC14}
5954
5955 \end_inset 
5956
5957 -bit processors (p16f84 and variants.
5958  In development, not complete).
5959 \layout Standard
5960
5961
5962 \begin_inset Note
5963 collapsed true
5964
5965 \layout Standard
5966
5967 p16f627 p16f628 p16f84 p16f873 p16f877?
5968 \end_inset 
5969
5970
5971 \layout List
5972 \labelwidthstring 00.00.0000
5973
5974
5975 \series bold 
5976 -mpic16
5977 \begin_inset LatexCommand \index{-mpic16}
5978
5979 \end_inset 
5980
5981
5982 \series default 
5983  Generate code for the Microchip PIC 16
5984 \begin_inset LatexCommand \index{PIC16}
5985
5986 \end_inset 
5987
5988 -bit processors (p18f452 and variants.
5989  In development, not complete).
5990 \layout List
5991 \labelwidthstring 00.00.0000
5992
5993
5994 \series bold 
5995 -mtlcs900h
5996 \series default 
5997  Generate code for the Toshiba TLCS-900H
5998 \begin_inset LatexCommand \index{TLCS-900H}
5999
6000 \end_inset 
6001
6002  processor (Not maintained, not complete).
6003 \layout List
6004 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6005
6006
6007 \series bold 
6008 -mxa51
6009 \begin_inset LatexCommand \index{-mxa51}
6010
6011 \end_inset 
6012
6013
6014 \series default 
6015  Generate code for the Phillips XA51
6016 \begin_inset LatexCommand \index{XA51}
6017
6018 \end_inset 
6019
6020  processor (Not maintained, not complete).
6021 \layout Subsection
6022
6023 Preprocessor Options
6024 \begin_inset LatexCommand \index{Options preprocessor}
6025
6026 \end_inset 
6027
6028
6029 \begin_inset LatexCommand \index{Preprocessor options}
6030
6031 \end_inset 
6032
6033
6034 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6035
6036 \end_inset 
6037
6038
6039 \layout List
6040 \labelwidthstring 00.00.0000
6041
6042
6043 \series bold 
6044 -I<path>
6045 \begin_inset LatexCommand \index{-I<path>}
6046
6047 \end_inset 
6048
6049
6050 \series default 
6051  The additional location where the pre processor will look for <..h> or 
6052 \begin_inset Quotes eld
6053 \end_inset 
6054
6055 ..h
6056 \begin_inset Quotes erd
6057 \end_inset 
6058
6059  files.
6060 \layout List
6061 \labelwidthstring 00.00.0000
6062
6063
6064 \series bold 
6065 -D<macro[=value]>
6066 \begin_inset LatexCommand \index{-D<macro[=value]>}
6067
6068 \end_inset 
6069
6070
6071 \series default 
6072  Command line definition of macros.
6073  Passed to the preprocessor.
6074 \layout List
6075 \labelwidthstring 00.00.0000
6076
6077
6078 \series bold 
6079 -M
6080 \begin_inset LatexCommand \index{-M}
6081
6082 \end_inset 
6083
6084
6085 \series default 
6086  Tell the preprocessor to output a rule suitable for make describing the
6087  dependencies of each object file.
6088  For each source file, the preprocessor outputs one make-rule whose target
6089  is the object file name for that source file and whose dependencies are
6090  all the files `#include'd in it.
6091  This rule may be a single line or may be continued with `
6092 \backslash 
6093 '-newline if it is long.
6094  The list of rules is printed on standard output instead of the preprocessed
6095  C program.
6096  `-M' implies `-E
6097 \begin_inset LatexCommand \index{-E}
6098
6099 \end_inset 
6100
6101 '.
6102 \layout List
6103 \labelwidthstring 00.00.0000
6104
6105
6106 \series bold 
6107 -C
6108 \begin_inset LatexCommand \index{-C}
6109
6110 \end_inset 
6111
6112
6113 \series default 
6114  Tell the preprocessor not to discard comments.
6115  Used with the `-E' option.
6116 \layout List
6117 \labelwidthstring 00.00.0000
6118
6119
6120 \series bold 
6121 -MM
6122 \begin_inset LatexCommand \index{-MM}
6123
6124 \end_inset 
6125
6126
6127 \size large 
6128 \bar under 
6129  
6130 \series default 
6131 \size default 
6132 \bar default 
6133 Like `-M' but the output mentions only the user header files included with
6134  `#include 
6135 \begin_inset Quotes eld
6136 \end_inset 
6137
6138 file"'.
6139  System header files included with `#include <file>' are omitted.
6140 \layout List
6141 \labelwidthstring 00.00.0000
6142
6143
6144 \series bold 
6145 -Aquestion(answer)
6146 \begin_inset LatexCommand \index{-Aquestion(answer)}
6147
6148 \end_inset 
6149
6150
6151 \series default 
6152  Assert the answer answer for question, in case it is tested with a preprocessor
6153  conditional such as `#if #question(answer)'.
6154  `-A-' disables the standard assertions that normally describe the target
6155  machine.
6156 \layout List
6157 \labelwidthstring 00.00.0000
6158
6159
6160 \series bold 
6161 -Umacro
6162 \begin_inset LatexCommand \index{-Umacro}
6163
6164 \end_inset 
6165
6166
6167 \series default 
6168  Undefine macro macro.
6169  `-U' options are evaluated after all `-D' options, but before any `-include'
6170  and `-imacros' options.
6171 \layout List
6172 \labelwidthstring 00.00.0000
6173
6174
6175 \series bold 
6176 -dM
6177 \begin_inset LatexCommand \index{-dM}
6178
6179 \end_inset 
6180
6181
6182 \series default 
6183  Tell the preprocessor to output only a list of the macro definitions that
6184  are in effect at the end of preprocessing.
6185  Used with the `-E' option.
6186 \layout List
6187 \labelwidthstring 00.00.0000
6188
6189
6190 \series bold 
6191 -dD
6192 \begin_inset LatexCommand \index{-dD}
6193
6194 \end_inset 
6195
6196
6197 \series default 
6198  Tell the preprocessor to pass all macro definitions into the output, in
6199  their proper sequence in the rest of the output.
6200 \layout List
6201 \labelwidthstring 00.00.0000
6202
6203
6204 \series bold 
6205 -dN
6206 \begin_inset LatexCommand \index{-dN}
6207
6208 \end_inset 
6209
6210
6211 \size large 
6212 \bar under 
6213  
6214 \series default 
6215 \size default 
6216 \bar default 
6217 Like `-dD' except that the macro arguments and contents are omitted.
6218  Only `#define name' is included in the output.
6219 \layout List
6220 \labelwidthstring 00.00.0000
6221
6222
6223 \series bold 
6224 -pedantic-parse-number
6225 \begin_inset LatexCommand \index{-pedantic-parse-number}
6226
6227 \end_inset 
6228
6229
6230 \size large 
6231 \bar under 
6232  
6233 \series default 
6234 \size default 
6235 \bar default 
6236 Pedentic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6237  and the macro LO_B(3) gets expanded.
6238  See also #pragma pedantic_parse_number in section
6239 \begin_inset LatexCommand \ref{sec:Pragmas}
6240
6241 \end_inset 
6242
6243  
6244 \emph on 
6245 Note: this functionality is not in conformance with standard!
6246 \layout List
6247 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6248
6249
6250 \series bold 
6251 -Wp\SpecialChar ~
6252 preprocessorOption[,preprocessorOption]
6253 \series default 
6254
6255 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6256
6257 \end_inset 
6258
6259 ...
6260  Pass the preprocessorOption to the preprocessor 
6261 \family typewriter 
6262 sdcpp
6263 \family default 
6264
6265 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6266
6267 \end_inset 
6268
6269 .
6270  SDCC uses an adapted version of the preprocessor 
6271 \emph on 
6272 cpp
6273 \emph default 
6274  of the GNU Compiler Collection
6275 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
6276
6277 \end_inset 
6278
6279  (
6280 \emph on 
6281 gcc
6282 \emph default 
6283  
6284 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
6285
6286 \end_inset 
6287
6288 ), if you need more dedicated options please refer to the GCC\SpecialChar ~
6289 4.1.1\SpecialChar ~
6290 CPP\SpecialChar ~
6291 Manual
6292  at 
6293 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
6294
6295 \end_inset 
6296
6297 .
6298 \layout Subsection
6299
6300 Linker Options
6301 \begin_inset LatexCommand \index{Options linker}
6302
6303 \end_inset 
6304
6305
6306 \begin_inset LatexCommand \index{Linker options}
6307
6308 \end_inset 
6309
6310
6311 \layout List
6312 \labelwidthstring 00.00.0000
6313
6314
6315 \series bold 
6316 -L\SpecialChar ~
6317 -
6318 \series default 
6319
6320 \begin_inset ERT
6321 status Collapsed
6322
6323 \layout Standard
6324
6325 \backslash 
6326 /
6327 \end_inset 
6328
6329
6330 \series bold 
6331 -lib-path
6332 \begin_inset LatexCommand \index{-\/-lib-path <path>}
6333
6334 \end_inset 
6335
6336
6337 \begin_inset LatexCommand \index{-L -\/-lib-path}
6338
6339 \end_inset 
6340
6341
6342 \series default 
6343 \SpecialChar ~
6344 <absolute path to additional libraries> This option is passed to the linkage
6345  editor's additional libraries
6346 \begin_inset LatexCommand \index{Libraries}
6347
6348 \end_inset 
6349
6350  search path.
6351  The path name must be absolute.
6352  Additional library files may be specified in the command line.
6353  See section Compiling programs for more details.
6354 \layout List
6355 \labelwidthstring 00.00.0000
6356
6357
6358 \series bold 
6359 -
6360 \begin_inset ERT
6361 status Collapsed
6362
6363 \layout Standard
6364
6365 \backslash 
6366 /
6367 \end_inset 
6368
6369 -xram-loc
6370 \series default 
6371
6372 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
6373
6374 \end_inset 
6375
6376 \SpecialChar ~
6377 <Value> The start location of the external ram
6378 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
6379
6380 \end_inset 
6381
6382 , default value is 0.
6383  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6384 \begin_inset ERT
6385 status Collapsed
6386
6387 \layout Standard
6388
6389 \backslash 
6390 /
6391 \end_inset 
6392
6393 -xram-loc 0x8000 or -
6394 \begin_inset ERT
6395 status Collapsed
6396
6397 \layout Standard
6398
6399 \backslash 
6400 /
6401 \end_inset 
6402
6403 -xram-loc 32768.
6404 \layout List
6405 \labelwidthstring 00.00.0000
6406
6407
6408 \series bold 
6409 -
6410 \begin_inset ERT
6411 status Collapsed
6412
6413 \layout Standard
6414
6415 \backslash 
6416 /
6417 \end_inset 
6418
6419 -code-loc
6420 \series default 
6421
6422 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
6423
6424 \end_inset 
6425
6426 \SpecialChar ~
6427 <Value> The start location of the code
6428 \begin_inset LatexCommand \index{code}
6429
6430 \end_inset 
6431
6432  segment, default value 0.
6433  Note when this option is used the interrupt vector table
6434 \begin_inset LatexCommand \index{interrupt vector table}
6435
6436 \end_inset 
6437
6438  is also relocated to the given address.
6439  The value entered can be in Hexadecimal or Decimal format, e.g.: -
6440 \begin_inset ERT
6441 status Collapsed
6442
6443 \layout Standard
6444
6445 \backslash 
6446 /
6447 \end_inset 
6448
6449 -code-loc 0x8000 or -
6450 \begin_inset ERT
6451 status Collapsed
6452
6453 \layout Standard
6454
6455 \backslash 
6456 /
6457 \end_inset 
6458
6459 -code-loc 32768.
6460 \layout List
6461 \labelwidthstring 00.00.0000
6462
6463
6464 \series bold 
6465 -
6466 \begin_inset ERT
6467 status Collapsed
6468
6469 \layout Standard
6470
6471 \backslash 
6472 /
6473 \end_inset 
6474
6475 -stack-loc
6476 \series default 
6477
6478 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
6479
6480 \end_inset 
6481
6482 \SpecialChar ~
6483 <Value> By default the stack
6484 \begin_inset LatexCommand \index{stack}
6485
6486 \end_inset 
6487
6488  is placed after the data segment.
6489  Using this option the stack can be placed anywhere in the internal memory
6490  space of the 8051.
6491  The value entered can be in Hexadecimal or Decimal format, e.g.
6492  -
6493 \begin_inset ERT
6494 status Collapsed
6495
6496 \layout Standard
6497
6498 \backslash 
6499 /
6500 \end_inset 
6501
6502 -stack-loc 0x20 or -
6503 \begin_inset ERT
6504 status Collapsed
6505
6506 \layout Standard
6507
6508 \backslash 
6509 /
6510 \end_inset 
6511
6512 -stack-loc 32.
6513  Since the sp register is incremented before a push or call, the initial
6514  sp will be set to one byte prior the provided value.
6515  The provided value should not overlap any other memory areas such as used
6516  register banks or the data segment and with enough space for the current
6517  application.
6518  The 
6519 \series bold 
6520 -
6521 \begin_inset ERT
6522 status Collapsed
6523
6524 \layout Standard
6525
6526 \backslash 
6527 /
6528 \end_inset 
6529
6530 -pack-iram
6531 \series default 
6532 \SpecialChar ~
6533
6534 \begin_inset LatexCommand \index{-\/-pack-iram}
6535
6536 \end_inset 
6537
6538  option (which is now a default setting) will override this setting, so
6539  you should also specify the 
6540 \series bold 
6541 -
6542 \begin_inset ERT
6543 status Collapsed
6544
6545 \layout Standard
6546
6547 \backslash 
6548 /
6549 \end_inset 
6550
6551 -no-pack-iram
6552 \series default 
6553 \SpecialChar ~
6554
6555 \begin_inset LatexCommand \index{-\/-no-pack-iram}
6556
6557 \end_inset 
6558
6559  option if you need to manually place the stack.
6560 \layout List
6561 \labelwidthstring 00.00.0000
6562
6563
6564 \series bold 
6565 -
6566 \begin_inset ERT
6567 status Collapsed
6568
6569 \layout Standard
6570
6571 \backslash 
6572 /
6573 \end_inset 
6574
6575 -xstack-loc
6576 \series default 
6577
6578 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
6579
6580 \end_inset 
6581
6582 \SpecialChar ~
6583 <Value> By default the external stack
6584 \begin_inset LatexCommand \index{xstack}
6585
6586 \end_inset 
6587
6588  is placed after the pdata
6589 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
6590
6591 \end_inset 
6592
6593  segment.
6594  Using this option the xstack can be placed anywhere in the external memory
6595  space of the 8051.
6596  The value entered can be in Hexadecimal or Decimal format, e.g.
6597  -
6598 \begin_inset ERT
6599 status Collapsed
6600
6601 \layout Standard
6602
6603 \backslash 
6604 /
6605 \end_inset 
6606
6607 -xstack-loc 0x8000 or -
6608 \begin_inset ERT
6609 status Collapsed
6610
6611 \layout Standard
6612
6613 \backslash 
6614 /
6615 \end_inset 
6616
6617 -stack-loc 32768.
6618  The provided value should not overlap any other memory areas such as the
6619  pdata or xdata segment and with enough space for the current application.
6620 \layout List
6621 \labelwidthstring 00.00.0000
6622
6623
6624 \series bold 
6625 -
6626 \begin_inset ERT
6627 status Collapsed
6628
6629 \layout Standard
6630
6631 \backslash 
6632 /
6633 \end_inset 
6634
6635 -data-loc
6636 \series default 
6637
6638 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
6639
6640 \end_inset 
6641
6642 \SpecialChar ~
6643 <Value> The start location of the internal ram data
6644 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
6645
6646 \end_inset 
6647
6648  segment.
6649  The value entered can be in Hexadecimal or Decimal format, eg.
6650  -
6651 \begin_inset ERT
6652 status Collapsed
6653
6654 \layout Standard
6655
6656 \backslash 
6657 /
6658 \end_inset 
6659
6660 -data-loc 0x20 or -
6661 \begin_inset ERT
6662 status Collapsed
6663
6664 \layout Standard
6665
6666 \backslash 
6667 /
6668 \end_inset 
6669
6670 -data-loc 32.
6671  (By default, the start location of the internal ram data segment  is set
6672  as low as possible in memory, taking into account the used register banks
6673  and the bit segment at address 0x20.
6674  For example if register banks 0 and 1 are used without bit variables, the
6675  data segment will be set, if -
6676 \begin_inset ERT
6677 status Collapsed
6678
6679 \layout Standard
6680
6681 \backslash 
6682 /
6683 \end_inset 
6684
6685 -data-loc is not used, to location 0x10.)
6686 \layout List
6687 \labelwidthstring 00.00.0000
6688
6689
6690 \series bold 
6691 -
6692 \begin_inset ERT
6693 status Collapsed
6694
6695 \layout Standard
6696
6697 \backslash 
6698 /
6699 \end_inset 
6700
6701 -idata-loc
6702 \series default 
6703
6704 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
6705
6706 \end_inset 
6707
6708 \SpecialChar ~
6709 <Value> The start location of the indirectly addressable internal ram
6710 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
6711
6712 \end_inset 
6713
6714  of the 8051, default value is 0x80.
6715  The value entered can be in Hexadecimal or Decimal format, eg.
6716  -
6717 \begin_inset ERT
6718 status Collapsed
6719
6720 \layout Standard
6721
6722 \backslash 
6723 /
6724 \end_inset 
6725
6726 -idata-loc 0x88 or -
6727 \begin_inset ERT
6728 status Collapsed
6729
6730 \layout Standard
6731
6732 \backslash 
6733 /
6734 \end_inset 
6735
6736 -idata-loc 136.
6737 \layout List
6738 \labelwidthstring 00.00.0000
6739
6740
6741 \series bold 
6742 -
6743 \begin_inset ERT
6744 status Collapsed
6745
6746 \layout Standard
6747
6748 \backslash 
6749 /
6750 \end_inset 
6751
6752 -bit-loc
6753 \series default 
6754 \SpecialChar ~
6755 <Value> The start location of the bit
6756 \begin_inset LatexCommand \index{bit}
6757
6758 \end_inset 
6759
6760  addressable internal ram of the 8051.
6761  This is 
6762 \emph on 
6763 not
6764 \emph default 
6765  implemented yet.
6766  Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
6767 -bBSEG=<Value>.
6768 \layout List
6769 \labelwidthstring 00.00.0000
6770
6771
6772 \series bold 
6773 -
6774 \begin_inset ERT
6775 status Collapsed
6776
6777 \layout Standard
6778
6779 \backslash 
6780 /
6781 \end_inset 
6782
6783 -out-fmt-ihx
6784 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
6785
6786 \end_inset 
6787
6788
6789 \bar under 
6790  
6791 \series default 
6792 \bar default 
6793 The linker output (final object code) is in Intel Hex format.
6794 \begin_inset LatexCommand \index{Intel hex format}
6795
6796 \end_inset 
6797
6798  This is the default option.
6799  The format itself is documented in the documentation of srecord
6800 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
6801
6802 \end_inset 
6803
6804 .
6805 \layout List
6806 \labelwidthstring 00.00.0000
6807
6808
6809 \series bold 
6810 -
6811 \begin_inset ERT
6812 status Collapsed
6813
6814 \layout Standard
6815
6816 \backslash 
6817 /
6818 \end_inset 
6819
6820 -out-fmt-s19
6821 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6822
6823 \end_inset 
6824
6825
6826 \bar under 
6827  
6828 \series default 
6829 \bar default 
6830 The linker output (final object code) is in Motorola S19 format
6831 \begin_inset LatexCommand \index{Motorola S19 format}
6832
6833 \end_inset 
6834
6835 .
6836  The format itself is documented in the documentation of srecord.
6837 \layout List
6838 \labelwidthstring 00.00.0000
6839
6840
6841 \series bold 
6842 -
6843 \begin_inset ERT
6844 status Collapsed
6845
6846 \layout Standard
6847
6848 \backslash 
6849 /
6850 \end_inset 
6851
6852 -out-fmt-elf
6853 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
6854
6855 \end_inset 
6856
6857
6858 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
6859
6860 \end_inset 
6861
6862
6863 \bar under 
6864  
6865 \series default 
6866 \bar default 
6867 The linker output (final object code) is in ELF format
6868 \begin_inset LatexCommand \index{ELF format}
6869
6870 \end_inset 
6871
6872 .
6873  (Currently only supported for the HC08
6874 \begin_inset LatexCommand \index{HC08}
6875
6876 \end_inset 
6877
6878  processors)
6879 \layout List
6880 \added_space_bottom bigskip \labelwidthstring 00.00.0000
6881
6882
6883 \series bold 
6884 -Wl\SpecialChar ~
6885 linkOption[,linkOption]
6886 \series default 
6887
6888 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
6889
6890 \end_inset 
6891
6892 ...
6893  Pass the linkOption to the linker.
6894  If a bootloader is used an option like 
6895 \begin_inset Quotes sld
6896 \end_inset 
6897
6898 -Wl\SpecialChar ~
6899 -bCSEG=0x1000
6900 \begin_inset Quotes srd
6901 \end_inset 
6902
6903  would be typical to set the start of the code segment.
6904  See also #pragma constseg and #pragma codeseg in section 
6905 \begin_inset LatexCommand \ref{sec:Pragmas}
6906
6907 \end_inset 
6908
6909  .
6910  File sdcc/as/doc/asxhtm.html has more on linker options.
6911 \layout Subsection
6912
6913 MCS51 Options
6914 \begin_inset LatexCommand \index{Options MCS51}
6915
6916 \end_inset 
6917
6918
6919 \begin_inset LatexCommand \index{MCS51 options}
6920
6921 \end_inset 
6922
6923
6924 \layout List
6925 \labelwidthstring 00.00.0000
6926
6927
6928 \series bold 
6929 -
6930 \begin_inset ERT
6931 status Collapsed
6932
6933 \layout Standard
6934
6935 \backslash 
6936 /
6937 \end_inset 
6938
6939 -model-small
6940 \begin_inset LatexCommand \index{-\/-model-small}
6941
6942 \end_inset 
6943
6944
6945 \series default 
6946 \size large 
6947 \emph on 
6948  
6949 \size default 
6950 \emph default 
6951 Generate code for Small Model programs, see section Memory Models for more
6952  details.
6953  This is the default model.
6954 \layout List
6955 \labelwidthstring 00.00.0000
6956
6957
6958 \series bold 
6959 -
6960 \begin_inset ERT
6961 status Collapsed
6962
6963 \layout Standard
6964
6965 \backslash 
6966 /
6967 \end_inset 
6968
6969 -model-medium
6970 \begin_inset LatexCommand \index{-\/-model-medium}
6971
6972 \end_inset 
6973
6974
6975 \series default 
6976  Generate code for Medium model programs, see section Memory Models for
6977  more details.
6978  If this option is used all source files in the project have to be compiled
6979  with this option.
6980  It must also be used when invoking the linker.
6981 \layout List
6982 \labelwidthstring 00.00.0000
6983
6984
6985 \series bold 
6986 -
6987 \begin_inset ERT
6988 status Collapsed
6989
6990 \layout Standard
6991
6992 \backslash 
6993 /
6994 \end_inset 
6995
6996 -model-large
6997 \begin_inset LatexCommand \index{-\/-model-large}
6998
6999 \end_inset 
7000
7001
7002 \series default 
7003  Generate code for Large model programs, see section Memory Models for more
7004  details.
7005  If this option is used all source files in the project have to be compiled
7006  with this option.
7007  It must also be used when invoking the linker.
7008 \layout List
7009 \labelwidthstring 00.00.0000
7010
7011
7012 \series bold 
7013 -
7014 \begin_inset ERT
7015 status Collapsed
7016
7017 \layout Standard
7018
7019 \backslash 
7020 /
7021 \end_inset 
7022
7023 -xstack
7024 \begin_inset LatexCommand \index{-\/-xstack}
7025
7026 \end_inset 
7027
7028
7029 \series default 
7030  Uses a pseudo stack in the pdata
7031 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7032
7033 \end_inset 
7034
7035  area (usually the first 256 bytes in the external ram) for allocating variables
7036  and passing parameters.
7037  See section 
7038 \begin_inset LatexCommand \ref{sub:External-Stack}
7039
7040 \end_inset 
7041
7042 \SpecialChar ~
7043  External Stack for more details.
7044 \layout List
7045 \labelwidthstring 00.00.0000
7046
7047
7048 \series bold 
7049 -
7050 \begin_inset ERT
7051 status Collapsed
7052
7053 \layout Standard
7054
7055 \backslash 
7056 /
7057 \end_inset 
7058
7059 -iram-size
7060 \series default 
7061 \SpecialChar ~
7062 <Value>
7063 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7064
7065 \end_inset 
7066
7067  Causes the linker to check if the internal ram usage is within limits of
7068  the given value.
7069 \layout List
7070 \labelwidthstring 00.00.0000
7071
7072
7073 \series bold 
7074 -
7075 \begin_inset ERT
7076 status Collapsed
7077
7078 \layout Standard
7079
7080 \backslash 
7081 /
7082 \end_inset 
7083
7084 -xram-size
7085 \series default 
7086 \SpecialChar ~
7087 <Value>
7088 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7089
7090 \end_inset 
7091
7092  Causes the linker to check if the external ram usage is within limits of
7093  the given value.
7094 \layout List
7095 \labelwidthstring 00.00.0000
7096
7097
7098 \series bold 
7099 -
7100 \begin_inset ERT
7101 status Collapsed
7102
7103 \layout Standard
7104
7105 \backslash 
7106 /
7107 \end_inset 
7108
7109 -code-size
7110 \series default 
7111 \SpecialChar ~
7112 <Value>
7113 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7114
7115 \end_inset 
7116
7117  Causes the linker to check if the code memory usage is within limits of
7118  the given value.
7119 \layout List
7120 \labelwidthstring 00.00.0000
7121
7122
7123 \series bold 
7124 -
7125 \begin_inset ERT
7126 status Collapsed
7127
7128 \layout Standard
7129
7130 \backslash 
7131 /
7132 \end_inset 
7133
7134 -stack-size
7135 \series default 
7136 \SpecialChar ~
7137 <Value>
7138 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
7139
7140 \end_inset 
7141
7142  Causes the linker to check if there is at minimum <Value> bytes for stack.
7143 \layout List
7144 \labelwidthstring 00.00.0000
7145
7146
7147 \series bold 
7148 -
7149 \begin_inset ERT
7150 status Collapsed
7151
7152 \layout Standard
7153
7154 \backslash 
7155 /
7156 \end_inset 
7157
7158 -pack-iram
7159 \series default 
7160 \SpecialChar ~
7161
7162 \begin_inset LatexCommand \index{-\/-pack-iram}
7163
7164 \end_inset 
7165
7166  Causes the linker to use unused register banks for data variables and pack
7167  data, idata and stack together.
7168  This is the default now.
7169 \layout List
7170 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7171
7172
7173 \series bold 
7174 -
7175 \begin_inset ERT
7176 status Collapsed
7177
7178 \layout Standard
7179
7180 \backslash 
7181 /
7182 \end_inset 
7183
7184 -no-pack-iram
7185 \series default 
7186 \SpecialChar ~
7187
7188 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7189
7190 \end_inset 
7191
7192  Causes the linker to use old style for allocating memory areas.
7193 \layout Subsection
7194
7195 DS390 / DS400 Options
7196 \begin_inset LatexCommand \index{Options DS390}
7197
7198 \end_inset 
7199
7200
7201 \begin_inset LatexCommand \index{DS390}
7202
7203 \end_inset 
7204
7205
7206 \layout List
7207 \labelwidthstring 00.00.0000
7208
7209
7210 \series bold 
7211 -
7212 \begin_inset ERT
7213 status Collapsed
7214
7215 \layout Standard
7216
7217 \backslash 
7218 /
7219 \end_inset 
7220
7221 -model-flat24
7222 \series default 
7223
7224 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
7225
7226 \end_inset 
7227
7228
7229 \size large 
7230 \emph on 
7231  
7232 \size default 
7233 \emph default 
7234 Generate 24-bit flat mode code.
7235  This is the one and only that the ds390 code generator supports right now
7236  and is default when using 
7237 \emph on 
7238 -mds390
7239 \emph default 
7240 .
7241  See section Memory Models for more details.
7242 \layout List
7243 \labelwidthstring 00.00.0000
7244
7245
7246 \series bold 
7247 -
7248 \begin_inset ERT
7249 status Collapsed
7250
7251 \layout Standard
7252
7253 \backslash 
7254 /
7255 \end_inset 
7256
7257 -protect-sp-update
7258 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
7259
7260 \end_inset 
7261
7262
7263 \series default 
7264  disable interrupts during ESP:SP updates.
7265 \layout List
7266 \labelwidthstring 00.00.0000
7267
7268
7269 \series bold 
7270 -
7271 \begin_inset ERT
7272 status Collapsed
7273
7274 \layout Standard
7275
7276 \backslash 
7277 /
7278 \end_inset 
7279
7280 -stack-10bit
7281 \series default 
7282
7283 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
7284
7285 \end_inset 
7286
7287  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
7288  This is the one and only that the ds390 code generator supports right now
7289  and is default when using 
7290 \emph on 
7291 -mds390
7292 \emph default 
7293 .
7294  In this mode, the stack is located in the lower 1K of the internal RAM,
7295  which is mapped to 0x400000.
7296  Note that the support is incomplete, since it still uses a single byte
7297  as the stack pointer.
7298  This means that only the lower 256 bytes of the potential 1K stack space
7299  will actually be used.
7300  However, this does allow you to reclaim the precious 256 bytes of low RAM
7301  for use for the DATA and IDATA segments.
7302  The compiler will not generate any code to put the processor into 10 bit
7303  stack mode.
7304  It is important to ensure that the processor is in this mode before calling
7305  any re-entrant functions compiled with this option.
7306  In principle, this should work with the 
7307 \emph on 
7308 -
7309 \begin_inset ERT
7310 status Collapsed
7311
7312 \layout Standard
7313
7314 \backslash 
7315 /
7316 \end_inset 
7317
7318 -stack-auto
7319 \begin_inset LatexCommand \index{-\/-stack-auto}
7320
7321 \end_inset 
7322
7323
7324 \emph default 
7325  option, but that has not been tested.
7326  It is incompatible with the 
7327 \emph on 
7328 -
7329 \begin_inset ERT
7330 status Collapsed
7331
7332 \layout Standard
7333
7334 \backslash 
7335 /
7336 \end_inset 
7337
7338 -xstack
7339 \begin_inset LatexCommand \index{-\/-xstack}
7340
7341 \end_inset 
7342
7343
7344 \emph default 
7345  option.
7346  It also only makes sense if the processor is in 24 bit contiguous addressing
7347  mode (see the 
7348 \emph on 
7349 -
7350 \begin_inset ERT
7351 status Collapsed
7352
7353 \layout Standard
7354
7355 \backslash 
7356 /
7357 \end_inset 
7358
7359 -model-flat24 option
7360 \emph default 
7361 ).
7362 \layout List
7363 \labelwidthstring 00.00.0000
7364
7365
7366 \series bold 
7367 -
7368 \begin_inset ERT
7369 status Collapsed
7370
7371 \layout Standard
7372
7373 \backslash 
7374 /
7375 \end_inset 
7376
7377 -stack-probe
7378 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
7379
7380 \end_inset 
7381
7382
7383 \series default 
7384  insert call to function __stack_probe at each function prologue.
7385 \layout List
7386 \labelwidthstring 00.00.0000
7387
7388
7389 \series bold 
7390 -
7391 \begin_inset ERT
7392 status Collapsed
7393
7394 \layout Standard
7395
7396 \backslash 
7397 /
7398 \end_inset 
7399
7400 -tini-libid
7401 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
7402
7403 \end_inset 
7404
7405
7406 \series default 
7407  <nnnn> LibraryID used in -mTININative.
7408  
7409 \layout List
7410 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7411
7412
7413 \series bold 
7414 -
7415 \begin_inset ERT
7416 status Collapsed
7417
7418 \layout Standard
7419
7420 \backslash 
7421 /
7422 \end_inset 
7423
7424 -use-accelerator
7425 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
7426
7427 \end_inset 
7428
7429
7430 \series default 
7431  generate code for DS390 Arithmetic Accelerator.
7432  
7433 \layout Subsection
7434
7435 Z80 Options
7436 \begin_inset LatexCommand \index{Options Z80}
7437
7438 \end_inset 
7439
7440
7441 \begin_inset LatexCommand \index{Z80}
7442
7443 \end_inset 
7444
7445
7446 \layout List
7447 \labelwidthstring 00.00.0000
7448
7449
7450 \series bold 
7451 -
7452 \begin_inset ERT
7453 status Collapsed
7454
7455 \layout Standard
7456
7457 \backslash 
7458 /
7459 \end_inset 
7460
7461 -callee-saves-bc
7462 \series default 
7463
7464 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
7465
7466 \end_inset 
7467
7468
7469 \size large 
7470 \emph on 
7471  
7472 \size default 
7473 \emph default 
7474 Force a called function to always save BC.
7475 \layout List
7476 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7477
7478
7479 \series bold 
7480 -
7481 \begin_inset ERT
7482 status Collapsed
7483
7484 \layout Standard
7485
7486 \backslash 
7487 /
7488 \end_inset 
7489
7490 -no-std-crt0
7491 \series default 
7492
7493 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
7494
7495 \end_inset 
7496
7497  When linking, skip the standard crt0.o object file.
7498  You must provide your own crt0.o for your system when linking.
7499  
7500 \layout Subsection
7501
7502 Optimization Options
7503 \begin_inset LatexCommand \index{Options optimization}
7504
7505 \end_inset 
7506
7507
7508 \begin_inset LatexCommand \index{Optimization options}
7509
7510 \end_inset 
7511
7512
7513 \layout List
7514 \labelwidthstring 00.00.0000
7515
7516
7517 \series bold 
7518 -
7519 \begin_inset ERT
7520 status Collapsed
7521
7522 \layout Standard
7523
7524 \backslash 
7525 /
7526 \end_inset 
7527
7528 -nogcse
7529 \begin_inset LatexCommand \index{-\/-nogcse}
7530
7531 \end_inset 
7532
7533
7534 \series default 
7535  Will not do global subexpression elimination, this option may be used when
7536  the compiler creates undesirably large stack/data spaces to store compiler
7537  temporaries (
7538 \emph on 
7539 s
7540 \emph default 
7541 pill 
7542 \emph on 
7543 loc
7544 \emph default 
7545 ations, sloc
7546 \begin_inset LatexCommand \index{sloc (spill location)}
7547
7548 \end_inset 
7549
7550 ).
7551  A warning message will be generated when this happens and the compiler
7552  will indicate the number of extra bytes it allocated.
7553  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7554 nogcse
7555 \begin_inset LatexCommand \index{\#pragma nogcse}
7556
7557 \end_inset 
7558
7559  can be used to turn off global subexpression elimination
7560 \begin_inset LatexCommand \index{Subexpression elimination}
7561
7562 \end_inset 
7563
7564  for a given function only.
7565 \layout List
7566 \labelwidthstring 00.00.0000
7567
7568
7569 \series bold 
7570 -
7571 \begin_inset ERT
7572 status Collapsed
7573
7574 \layout Standard
7575
7576 \backslash 
7577 /
7578 \end_inset 
7579
7580 -noinvariant
7581 \begin_inset LatexCommand \index{-\/-noinvariant}
7582
7583 \end_inset 
7584
7585
7586 \series default 
7587  Will not do loop invariant optimizations, this may be turned off for reasons
7588  explained for the previous option.
7589  For more details of loop optimizations performed see Loop Invariants in
7590  section 
7591 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
7592
7593 \end_inset 
7594
7595 .
7596  It is recommended that this option NOT be used, #pragma\SpecialChar ~
7597 noinvariant
7598 \begin_inset LatexCommand \index{\#pragma noinvariant}
7599
7600 \end_inset 
7601
7602  can be used to turn off invariant optimizations for a given function only.
7603 \layout List
7604 \labelwidthstring 00.00.0000
7605
7606
7607 \series bold 
7608 -
7609 \begin_inset ERT
7610 status Collapsed
7611
7612 \layout Standard
7613
7614 \backslash 
7615 /
7616 \end_inset 
7617
7618 -noinduction
7619 \begin_inset LatexCommand \index{-\/-noinduction}
7620
7621 \end_inset 
7622
7623
7624 \series default 
7625  Will not do loop induction optimizations, see section strength reduction
7626  for more details.
7627  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7628 noinduction
7629 \begin_inset LatexCommand \index{\#pragma noinduction}
7630
7631 \end_inset 
7632
7633  can be used to turn off induction optimizations for a given function only.
7634 \layout List
7635 \labelwidthstring 00.00.0000
7636
7637
7638 \series bold 
7639 -
7640 \begin_inset ERT
7641 status Collapsed
7642
7643 \layout Standard
7644
7645 \backslash 
7646 /
7647 \end_inset 
7648
7649 -nojtbound
7650 \begin_inset LatexCommand \index{-\/-nojtbound}
7651
7652 \end_inset 
7653
7654
7655 \size large 
7656 \bar under 
7657  
7658 \series default 
7659 \size default 
7660 \bar default 
7661  Will not generate boundary condition check when switch statements
7662 \begin_inset LatexCommand \index{switch statement}
7663
7664 \end_inset 
7665
7666  are implemented using jump-tables.
7667  See section 
7668 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
7669
7670 \end_inset 
7671
7672 \SpecialChar ~
7673 Switch Statements for more details.
7674  It is recommended that this option is NOT used, #pragma\SpecialChar ~
7675 nojtbound
7676 \begin_inset LatexCommand \index{\#pragma nojtbound}
7677
7678 \end_inset 
7679
7680  can be used to turn off boundary checking for jump tables for a given function
7681  only.
7682 \layout List
7683 \labelwidthstring 00.00.0000
7684
7685
7686 \series bold 
7687 -
7688 \begin_inset ERT
7689 status Collapsed
7690
7691 \layout Standard
7692
7693 \backslash 
7694 /
7695 \end_inset 
7696
7697 -noloopreverse
7698 \begin_inset LatexCommand \index{-\/-noloopreverse}
7699
7700 \end_inset 
7701
7702
7703 \series default 
7704 \size large 
7705  
7706 \size default 
7707 Will not do loop reversal 
7708 \begin_inset LatexCommand \index{Loop reversing}
7709
7710 \end_inset 
7711
7712 optimization.
7713 \layout List
7714 \labelwidthstring 00.00.0000
7715
7716 -
7717 \begin_inset ERT
7718 status Collapsed
7719
7720 \layout Standard
7721
7722 \backslash 
7723 /
7724 \end_inset 
7725
7726 -
7727 \series bold 
7728 nolabelopt
7729 \series default 
7730  
7731 \begin_inset LatexCommand \index{-\/-nolabelopt }
7732
7733 \end_inset 
7734
7735 Will not optimize labels (makes the dumpfiles more readable).
7736 \layout List
7737 \labelwidthstring 00.00.0000
7738
7739
7740 \series bold 
7741 -
7742 \begin_inset ERT
7743 status Collapsed
7744
7745 \layout Standard
7746
7747 \backslash 
7748 /
7749 \end_inset 
7750
7751 -no-xinit-opt
7752 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
7753
7754 \end_inset 
7755
7756
7757 \series default 
7758  Will not memcpy initialized data from code space into xdata space.
7759  This saves a few bytes in code space if you don't have initialized data
7760 \begin_inset LatexCommand \index{Variable initialization}
7761
7762 \end_inset 
7763
7764 .
7765 \layout List
7766 \labelwidthstring 00.00.0000
7767
7768
7769 \series bold 
7770 -
7771 \begin_inset ERT
7772 status Collapsed
7773
7774 \layout Standard
7775
7776 \backslash 
7777 /
7778 \end_inset 
7779
7780 -nooverlay
7781 \begin_inset LatexCommand \index{-\/-nooverlay}
7782
7783 \end_inset 
7784
7785
7786 \series default 
7787   The compiler will not overlay parameters and local variables of any function,
7788  see section Parameters and local variables for more details.
7789 \layout List
7790 \labelwidthstring 00.00.0000
7791
7792
7793 \series bold 
7794 -
7795 \begin_inset ERT
7796 status Collapsed
7797
7798 \layout Standard
7799
7800 \backslash 
7801 /
7802 \end_inset 
7803
7804 -no-peep
7805 \begin_inset LatexCommand \index{-\/-no-peep}
7806
7807 \end_inset 
7808
7809
7810 \series default 
7811  Disable peep-hole optimization with built-in rules.
7812 \layout List
7813 \labelwidthstring 00.00.0000
7814
7815
7816 \series bold 
7817 -
7818 \begin_inset ERT
7819 status Collapsed
7820
7821 \layout Standard
7822
7823 \backslash 
7824 /
7825 \end_inset 
7826
7827 -peep-file
7828 \series default 
7829
7830 \begin_inset LatexCommand \index{-\/-peep-file}
7831
7832 \end_inset 
7833
7834 \SpecialChar ~
7835 <filename> This option can be used to use additional rules to be used by
7836  the peep hole optimizer.
7837  See section 
7838 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
7839
7840 \end_inset 
7841
7842 \SpecialChar ~
7843 Peep Hole optimizations for details on how to write these rules.
7844 \layout List
7845 \labelwidthstring 00.00.0000
7846
7847
7848 \series bold 
7849 -
7850 \begin_inset ERT
7851 status Collapsed
7852
7853 \layout Standard
7854
7855 \backslash 
7856 /
7857 \end_inset 
7858
7859 -peep-asm
7860 \begin_inset LatexCommand \index{-\/-peep-asm}
7861
7862 \end_inset 
7863
7864
7865 \series default 
7866  Pass the inline assembler code through the peep hole optimizer.
7867  This can cause unexpected changes to inline assembler code, please go through
7868  the peephole optimizer
7869 \begin_inset LatexCommand \index{Peephole optimizer}
7870
7871 \end_inset 
7872
7873  rules defined in the source file tree '<target>/peeph.def' before using
7874  this option.
7875 \layout List
7876 \labelwidthstring 00.00.0000
7877
7878
7879 \series bold 
7880 -
7881 \begin_inset ERT
7882 status Collapsed
7883
7884 \layout Standard
7885
7886 \backslash 
7887 /
7888 \end_inset 
7889
7890 -opt-code-speed
7891 \begin_inset LatexCommand \index{-\/-opt-code-speed}
7892
7893 \end_inset 
7894
7895
7896 \series default 
7897  The compiler will optimize code generation towards fast code, possibly
7898  at the expense of code size.
7899 \layout List
7900 \added_space_bottom bigskip \labelwidthstring 00.00.0000
7901
7902
7903 \series bold 
7904 -
7905 \begin_inset ERT
7906 status Collapsed
7907
7908 \layout Standard
7909
7910 \backslash 
7911 /
7912 \end_inset 
7913
7914 -opt-code-size
7915 \begin_inset LatexCommand \index{-\/-opt-code-size}
7916
7917 \end_inset 
7918
7919
7920 \series default 
7921  The compiler will optimize code generation towards compact code, possibly
7922  at the expense of code speed.
7923 \layout Subsection
7924
7925 Other Options
7926 \begin_inset LatexCommand \index{Options other}
7927
7928 \end_inset 
7929
7930
7931 \layout List
7932 \labelwidthstring 00.00.0000
7933
7934
7935 \series bold 
7936 -c\SpecialChar ~
7937 -
7938 \begin_inset ERT
7939 status Collapsed
7940
7941 \layout Standard
7942
7943 \backslash 
7944 /
7945 \end_inset 
7946
7947 -compile-only
7948 \begin_inset LatexCommand \index{-\/-compile-only}
7949
7950 \end_inset 
7951
7952
7953 \begin_inset LatexCommand \index{-c -\/-compile-only}
7954
7955 \end_inset 
7956
7957
7958 \series default 
7959  will compile and assemble the source, but will not call the linkage editor.
7960 \layout List
7961 \labelwidthstring 00.00.0000
7962
7963
7964 \series bold 
7965 -
7966 \series default 
7967
7968 \begin_inset ERT
7969 status Collapsed
7970
7971 \layout Standard
7972
7973 \backslash 
7974 /
7975 \end_inset 
7976
7977
7978 \series bold 
7979 -c1mode
7980 \begin_inset LatexCommand \index{-\/-c1mode}
7981
7982 \end_inset 
7983
7984
7985 \series default 
7986  reads the preprocessed source from standard input and compiles it.
7987  The file name for the assembler output must be specified using the -o option.
7988 \layout List
7989 \labelwidthstring 00.00.0000
7990
7991
7992 \series bold 
7993 -E
7994 \begin_inset LatexCommand \index{-E}
7995
7996 \end_inset 
7997
7998
7999 \series default 
8000  Run only the C preprocessor.
8001  Preprocess all the C source files specified and output the results to standard
8002  output.
8003 \layout List
8004 \labelwidthstring 00.00.0000
8005
8006
8007 \series bold 
8008 -o\SpecialChar ~
8009 <path/file>
8010 \begin_inset LatexCommand \index{-o <path/file>}
8011
8012 \end_inset 
8013
8014  
8015 \series default 
8016 The output path resp.
8017  file where everything will be placed.
8018  If the parameter is a path, it must have a trailing slash (or backslash
8019  for the Windows binaries) to be recognized as a path.
8020  
8021 \layout List
8022 \labelwidthstring 00.00.0000
8023
8024
8025 \series bold 
8026 -
8027 \begin_inset ERT
8028 status Collapsed
8029
8030 \layout Standard
8031
8032 \backslash 
8033 /
8034 \end_inset 
8035
8036 -stack-auto
8037 \begin_inset LatexCommand \index{-\/-stack-auto}
8038
8039 \end_inset 
8040
8041
8042 \series default 
8043 \size large 
8044 \emph on 
8045  
8046 \size default 
8047 \emph default 
8048 All functions in the source file will be compiled as 
8049 \emph on 
8050 reentrant
8051 \emph default 
8052
8053 \begin_inset LatexCommand \index{reentrant}
8054
8055 \end_inset 
8056
8057 , i.e.
8058  the parameters and local variables will be allocated on the stack
8059 \begin_inset LatexCommand \index{stack}
8060
8061 \end_inset 
8062
8063 .
8064  See section 
8065 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
8066
8067 \end_inset 
8068
8069  Parameters and Local Variables for more details.
8070  If this option is used all source files in the project should be compiled
8071  with this option.
8072  It automatically implies --int-long-reent and --float-reent.
8073  
8074 \layout List
8075 \labelwidthstring 00.00.0000
8076
8077
8078 \series bold 
8079 -
8080 \begin_inset ERT
8081 status Collapsed
8082
8083 \layout Standard
8084
8085 \backslash 
8086 /
8087 \end_inset 
8088
8089 -callee-saves
8090 \begin_inset LatexCommand \index{-\/-callee-saves}
8091
8092 \end_inset 
8093
8094  function1[,function2][,function3]....
8095
8096 \series default 
8097  The compiler by default uses a caller saves convention for register saving
8098  across function calls, however this can cause unnecessary register pushing
8099  & popping when calling small functions from larger functions.
8100  This option can be used to switch the register saving convention for the
8101  function names specified.
8102  The compiler will not save registers when calling these functions, no extra
8103  code will be generated at the entry & exit (function prologue
8104 \series bold 
8105
8106 \begin_inset LatexCommand \index{function prologue}
8107
8108 \end_inset 
8109
8110
8111 \series default 
8112  & epilogue
8113 \series bold 
8114
8115 \begin_inset LatexCommand \index{function epilogue}
8116
8117 \end_inset 
8118
8119
8120 \series default 
8121 ) for these functions to save & restore the registers used by these functions,
8122  this can SUBSTANTIALLY reduce code & improve run time performance of the
8123  generated code.
8124  In the future the compiler (with inter procedural analysis) will be able
8125  to determine the appropriate scheme to use for each function call.
8126  DO NOT use this option for built-in functions such as _mulint..., if this
8127  option is used for a library function the appropriate library function
8128  needs to be recompiled with the same option.
8129  If the project consists of multiple source files then all the source file
8130  should be compiled with the same -
8131 \begin_inset ERT
8132 status Collapsed
8133
8134 \layout Standard
8135
8136 \backslash 
8137 /
8138 \end_inset 
8139
8140 -callee-saves option string.
8141  Also see #pragma\SpecialChar ~
8142 callee_saves
8143 \begin_inset LatexCommand \index{\#pragma callee\_saves}
8144
8145 \end_inset 
8146
8147 .
8148 \layout List
8149 \labelwidthstring 00.00.0000
8150
8151
8152 \series bold 
8153 -
8154 \begin_inset ERT
8155 status Collapsed
8156
8157 \layout Standard
8158
8159 \backslash 
8160 /
8161 \end_inset 
8162
8163 -debug
8164 \begin_inset LatexCommand \index{-\/-debug}
8165
8166 \end_inset 
8167
8168
8169 \bar under 
8170  
8171 \series default 
8172 \bar default 
8173 When this option is used the compiler will generate debug information.
8174  The debug information collected in a file with .cdb extension can be used
8175  with the SDCDB.
8176  For more information see documentation for SDCDB.
8177  Another file with no extension contains debug information in AOMF or AOMF51
8178 \begin_inset LatexCommand \index{AOMF, AOMF51}
8179
8180 \end_inset 
8181
8182  format which is commonly used by third party tools.
8183 \layout List
8184 \labelwidthstring 00.00.0000
8185
8186
8187 \series bold 
8188 -S
8189 \begin_inset LatexCommand \index{-S}
8190
8191 \end_inset 
8192
8193
8194 \size large 
8195 \bar under 
8196  
8197 \series default 
8198 \size default 
8199 \bar default 
8200 Stop after the stage of compilation proper; do not assemble.
8201  The output is an assembler code file for the input file specified.
8202 \layout List
8203 \labelwidthstring 00.00.0000
8204
8205
8206 \series bold 
8207 -
8208 \begin_inset ERT
8209 status Collapsed
8210
8211 \layout Standard
8212
8213 \backslash 
8214 /
8215 \end_inset 
8216
8217 -int-long-reent
8218 \begin_inset LatexCommand \index{-\/-int-long-reent}
8219
8220 \end_inset 
8221
8222
8223 \series default 
8224  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
8225  Note by default these libraries are compiled as non-reentrant.
8226  See section Installation for more details.
8227 \layout List
8228 \labelwidthstring 00.00.0000
8229
8230
8231 \series bold 
8232 -
8233 \begin_inset ERT
8234 status Collapsed
8235
8236 \layout Standard
8237
8238 \backslash 
8239 /
8240 \end_inset 
8241
8242 -cyclomatic
8243 \begin_inset LatexCommand \index{-\/-cyclomatic}
8244
8245 \end_inset 
8246
8247
8248 \bar under 
8249  
8250 \series default 
8251 \bar default 
8252 This option will cause the compiler to generate an information message for
8253  each function in the source file.
8254  The message contains some 
8255 \emph on 
8256 important
8257 \emph default 
8258  information about the function.
8259  The number of edges and nodes the compiler detected in the control flow
8260  graph of the function, and most importantly the 
8261 \emph on 
8262 cyclomatic complexity
8263 \begin_inset LatexCommand \index{Cyclomatic complexity}
8264
8265 \end_inset 
8266
8267
8268 \emph default 
8269  see section on Cyclomatic Complexity for more details.
8270 \layout List
8271 \labelwidthstring 00.00.0000
8272
8273
8274 \series bold 
8275 -
8276 \begin_inset ERT
8277 status Collapsed
8278
8279 \layout Standard
8280
8281 \backslash 
8282 /
8283 \end_inset 
8284
8285 -float-reent
8286 \begin_inset LatexCommand \index{-\/-float-reent}
8287
8288 \end_inset 
8289
8290
8291 \series default 
8292  Floating point library is compiled as reentrant
8293 \begin_inset LatexCommand \index{reentrant}
8294
8295 \end_inset 
8296
8297 .
8298  See section Installation for more details.
8299 \layout List
8300 \labelwidthstring 00.00.0000
8301
8302
8303 \series bold 
8304 -
8305 \begin_inset ERT
8306 status Collapsed
8307
8308 \layout Standard
8309
8310 \backslash 
8311 /
8312 \end_inset 
8313
8314 -funsigned-char
8315 \begin_inset LatexCommand \index{-\/-funsigned-char}
8316
8317 \end_inset 
8318
8319
8320 \series default 
8321  The default signedness for every type is
8322 \family typewriter 
8323  signed
8324 \family default 
8325 .
8326  In some embedded environments the default signedness of
8327 \family typewriter 
8328  char
8329 \family default 
8330  is
8331 \family typewriter 
8332  unsigned
8333 \family default 
8334 .
8335  To set the signess for characters to unsigned, use the option --funsigned-char.
8336  If this option is set and no signedness keyword (unsigned/signed) is given,
8337  a char will be signed.
8338  All other types are unaffected.
8339 \layout List
8340 \labelwidthstring 00.00.0000
8341
8342
8343 \series bold 
8344 -
8345 \begin_inset ERT
8346 status Collapsed
8347
8348 \layout Standard
8349
8350 \backslash 
8351 /
8352 \end_inset 
8353
8354 -main-return
8355 \begin_inset LatexCommand \index{-\/-main-return}
8356
8357 \end_inset 
8358
8359
8360 \series default 
8361  This option can be used if the code generated is called by a monitor program
8362  or if the main routine includes an endless loop.
8363  This option results in slightly smaller code and saves two bytes of stack
8364  space.
8365  The return from the 'main'
8366 \begin_inset LatexCommand \index{main return}
8367
8368 \end_inset 
8369
8370  function will return to the function calling main.
8371  The default setting is to lock up i.e.
8372  generate a '
8373 \family typewriter 
8374 sjmp .
8375 \family default 
8376 '.
8377 \layout List
8378 \labelwidthstring 00.00.0000
8379
8380
8381 \series bold 
8382 -
8383 \begin_inset ERT
8384 status Collapsed
8385
8386 \layout Standard
8387
8388 \backslash 
8389 /
8390 \end_inset 
8391
8392 -nostdinc
8393 \begin_inset LatexCommand \index{-\/-nostdinc}
8394
8395 \end_inset 
8396
8397
8398 \series default 
8399  This will prevent the compiler from passing on the default include path
8400  to the preprocessor.
8401 \layout List
8402 \labelwidthstring 00.00.0000
8403
8404
8405 \series bold 
8406 -
8407 \begin_inset ERT
8408 status Collapsed
8409
8410 \layout Standard
8411
8412 \backslash 
8413 /
8414 \end_inset 
8415
8416 -nostdlib
8417 \begin_inset LatexCommand \index{-\/-nostdlib}
8418
8419 \end_inset 
8420
8421
8422 \series default 
8423  This will prevent the compiler from passing on the default library
8424 \begin_inset LatexCommand \index{Libraries}
8425
8426 \end_inset 
8427
8428  path to the linker.
8429 \layout List
8430 \labelwidthstring 00.00.0000
8431
8432
8433 \series bold 
8434 -
8435 \begin_inset ERT
8436 status Collapsed
8437
8438 \layout Standard
8439
8440 \backslash 
8441 /
8442 \end_inset 
8443
8444 -verbose
8445 \begin_inset LatexCommand \index{-\/-verbose}
8446
8447 \end_inset 
8448
8449
8450 \series default 
8451  Shows the various actions the compiler is performing.
8452 \layout List
8453 \labelwidthstring 00.00.0000
8454
8455
8456 \series bold 
8457 -V
8458 \begin_inset LatexCommand \index{-V}
8459
8460 \end_inset 
8461
8462
8463 \series default 
8464  Shows the actual commands the compiler is executing.
8465 \layout List
8466 \labelwidthstring 00.00.0000
8467
8468
8469 \series bold 
8470 -
8471 \begin_inset ERT
8472 status Collapsed
8473
8474 \layout Standard
8475
8476 \backslash 
8477 /
8478 \end_inset 
8479
8480 -no-c-code-in-asm
8481 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
8482
8483 \end_inset 
8484
8485
8486 \series default 
8487  Hides your ugly and inefficient c-code from the asm file, so you can always
8488  blame the compiler :)
8489 \layout List
8490 \labelwidthstring 00.00.0000
8491
8492
8493 \series bold 
8494 -
8495 \begin_inset ERT
8496 status Collapsed
8497
8498 \layout Standard
8499
8500 \backslash 
8501 /
8502 \end_inset 
8503
8504 -no-peep-comments
8505 \begin_inset LatexCommand \index{-\/-no-peep-comments}
8506
8507 \end_inset 
8508
8509
8510 \series default 
8511  Will not include peep-hole comments in the generated files.
8512 \layout List
8513 \labelwidthstring 00.00.0000
8514
8515
8516 \series bold 
8517 -
8518 \begin_inset ERT
8519 status Collapsed
8520
8521 \layout Standard
8522
8523 \backslash 
8524 /
8525 \end_inset 
8526
8527 -i-code-in-asm
8528 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
8529
8530 \end_inset 
8531
8532
8533 \series default 
8534  Include i-codes in the asm file.
8535  Sounds like noise but is most helpful for debugging the compiler itself.
8536 \layout List
8537 \labelwidthstring 00.00.0000
8538
8539
8540 \series bold 
8541 -
8542 \begin_inset ERT
8543 status Collapsed
8544
8545 \layout Standard
8546
8547 \backslash 
8548 /
8549 \end_inset 
8550
8551 -less-pedantic
8552 \begin_inset LatexCommand \index{-\/-less-pedantic}
8553
8554 \end_inset 
8555
8556
8557 \series default 
8558  Disable some of the more pedantic warnings
8559 \begin_inset LatexCommand \index{Warnings}
8560
8561 \end_inset 
8562
8563  (jwk burps: please be more specific here, please!).
8564 \layout List
8565 \labelwidthstring 00.00.0000
8566
8567
8568 \series bold 
8569 -
8570 \begin_inset ERT
8571 status Collapsed
8572
8573 \layout Standard
8574
8575 \backslash 
8576 /
8577 \end_inset 
8578
8579 -disable-warning\SpecialChar ~
8580 <nnnn>
8581 \begin_inset LatexCommand \index{-\/-disable-warning}
8582
8583 \end_inset 
8584
8585
8586 \series default 
8587  Disable specific warning with number <nnnn>.
8588 \layout List
8589 \labelwidthstring 00.00.0000
8590
8591
8592 \series bold 
8593 -
8594 \begin_inset ERT
8595 status Collapsed
8596
8597 \layout Standard
8598
8599 \backslash 
8600 /
8601 \end_inset 
8602
8603 -print-search-dirs
8604 \begin_inset LatexCommand \index{-\/-print-search-dirs}
8605
8606 \end_inset 
8607
8608
8609 \series default 
8610  Display the directories in the compiler's search path
8611 \layout List
8612 \labelwidthstring 00.00.0000
8613
8614
8615 \series bold 
8616 -
8617 \begin_inset ERT
8618 status Collapsed
8619
8620 \layout Standard
8621
8622 \backslash 
8623 /
8624 \end_inset 
8625
8626 -vc
8627 \begin_inset LatexCommand \index{-\/-vc}
8628
8629 \end_inset 
8630
8631
8632 \series default 
8633  Display errors and warnings using MSVC style, so you can use SDCC with
8634  the visual studio IDE
8635 \begin_inset LatexCommand \index{IDE}
8636
8637 \end_inset 
8638
8639 .
8640  With SDCC both offering a GCC-like (the default) and a MSVC-like
8641 \begin_inset LatexCommand \index{MSVC output style}
8642
8643 \end_inset 
8644
8645  output style, integration into most programming editors should be straightforwa
8646 rd.
8647 \layout List
8648 \labelwidthstring 00.00.0000
8649
8650
8651 \series bold 
8652 -
8653 \begin_inset ERT
8654 status Collapsed
8655
8656 \layout Standard
8657
8658 \backslash 
8659 /
8660 \end_inset 
8661
8662 -use-stdout
8663 \begin_inset LatexCommand \index{-\/-use-stdout}
8664
8665 \end_inset 
8666
8667
8668 \series default 
8669  Send errors and warnings to stdout instead of stderr.
8670 \layout List
8671 \labelwidthstring 00.00.0000
8672
8673
8674 \series bold 
8675 -Wa\SpecialChar ~
8676 asmOption[,asmOption]
8677 \series default 
8678
8679 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
8680
8681 \end_inset 
8682
8683 ...
8684  Pass the asmOption to the assembler
8685 \begin_inset LatexCommand \index{Options assembler}
8686
8687 \end_inset 
8688
8689
8690 \begin_inset LatexCommand \index{Assembler options}
8691
8692 \end_inset 
8693
8694 .
8695  See file sdcc/as/doc/asxhtm.html for assembler options.cd
8696 \layout List
8697 \labelwidthstring 00.00.0000
8698
8699
8700 \series bold 
8701 -
8702 \begin_inset ERT
8703 status Collapsed
8704
8705 \layout Standard
8706
8707 \backslash 
8708 /
8709 \end_inset 
8710
8711 -std-sdcc89
8712 \begin_inset LatexCommand \index{-\/-std-sdcc89}
8713
8714 \end_inset 
8715
8716
8717 \series default 
8718  Generally follow the C89 standard, but allow SDCC features that conflict
8719  with the standard (default).
8720 \layout List
8721 \labelwidthstring 00.00.0000
8722
8723
8724 \series bold 
8725 -
8726 \begin_inset ERT
8727 status Collapsed
8728
8729 \layout Standard
8730
8731 \backslash 
8732 /
8733 \end_inset 
8734
8735 -std-c89
8736 \begin_inset LatexCommand \index{-\/-std-c89}
8737
8738 \end_inset 
8739
8740
8741 \series default 
8742  Follow the C89 standard and disable SDCC features that conflict with the
8743  standard.
8744 \layout List
8745 \labelwidthstring 00.00.0000
8746
8747
8748 \series bold 
8749 -
8750 \begin_inset ERT
8751 status Collapsed
8752
8753 \layout Standard
8754
8755 \backslash 
8756 /
8757 \end_inset 
8758
8759 -std-sdcc99
8760 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8761
8762 \end_inset 
8763
8764
8765 \series default 
8766  Generally follow the C99 standard, but allow SDCC features that conflict
8767  with the standard (incomplete support).
8768 \layout List
8769 \labelwidthstring 00.00.0000
8770
8771
8772 \series bold 
8773 -
8774 \begin_inset ERT
8775 status Collapsed
8776
8777 \layout Standard
8778
8779 \backslash 
8780 /
8781 \end_inset 
8782
8783 -std-c99
8784 \begin_inset LatexCommand \index{-\/-std-sdcc99}
8785
8786 \end_inset 
8787
8788
8789 \series default 
8790  Follow the C99 standard and disable SDCC features that conflict with the
8791  standard (incomplete support).
8792 \layout List
8793 \labelwidthstring 00.00.0000
8794
8795
8796 \series bold 
8797 -
8798 \begin_inset ERT
8799 status Collapsed
8800
8801 \layout Standard
8802
8803 \backslash 
8804 /
8805 \end_inset 
8806
8807 -codeseg
8808 \series default 
8809
8810 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
8811
8812 \end_inset 
8813
8814 \SpecialChar ~
8815 <Name> The name to be used for the code
8816 \begin_inset LatexCommand \index{code}
8817
8818 \end_inset 
8819
8820  segment, default CSEG.
8821  This is useful if you need to tell the compiler to put the code in a special
8822  segment so you can later on tell the linker to put this segment in a special
8823  place in memory.
8824  Can be used for instance when using bank switching to put the code in a
8825  bank.
8826 \layout List
8827 \labelwidthstring 00.00.0000
8828
8829
8830 \series bold 
8831 -
8832 \begin_inset ERT
8833 status Collapsed
8834
8835 \layout Standard
8836
8837 \backslash 
8838 /
8839 \end_inset 
8840
8841 -constseg
8842 \series default 
8843
8844 \begin_inset LatexCommand \index{-\/-constseg <Value>}
8845
8846 \end_inset 
8847
8848 \SpecialChar ~
8849 <Name> The name to be used for the const
8850 \begin_inset LatexCommand \index{code}
8851
8852 \end_inset 
8853
8854  segment, default CONST.
8855  This is useful if you need to tell the compiler to put the const data in
8856  a special segment so you can later on tell the linker to put this segment
8857  in a special place in memory.
8858  Can be used for instance when using bank switching to put the const data
8859  in a bank.
8860 \layout List
8861 \labelwidthstring 00.00.0000
8862
8863
8864 \series bold 
8865 -
8866 \begin_inset ERT
8867 status Collapsed
8868
8869 \layout Standard
8870
8871 \backslash 
8872 /
8873 \end_inset 
8874
8875 -fdollars-in-identifiers
8876 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
8877
8878 \end_inset 
8879
8880
8881 \series default 
8882  Permit '$' as an identifier character
8883 \layout List
8884 \added_space_bottom bigskip \labelwidthstring 00.00.0000
8885
8886
8887 \series bold 
8888 more-pedantic
8889 \series default 
8890  Actually this is 
8891 \series bold 
8892 \emph on 
8893 not
8894 \series default 
8895 \emph default 
8896  a SDCC compiler option but if you want 
8897 \emph on 
8898 more
8899 \emph default 
8900  warnings you can use a separate tool dedicated to syntax checking like
8901  splint
8902 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
8903
8904 \end_inset 
8905
8906
8907 \begin_inset LatexCommand \index{lint (syntax checking tool)}
8908
8909 \end_inset 
8910
8911  
8912 \begin_inset LatexCommand \url{http://www.splint.org}
8913
8914 \end_inset 
8915
8916 .
8917  To make your source files parseable by splint you will have to include
8918  
8919 \family sans 
8920 lint.h
8921 \family default 
8922
8923 \begin_inset LatexCommand \index{splint (syntax checking tool)}
8924
8925 \end_inset 
8926
8927  in your source file and add brackets around extended keywords (like 
8928 \family sans 
8929
8930 \begin_inset Quotes sld
8931 \end_inset 
8932
8933 __at\SpecialChar ~
8934
8935 \series bold 
8936 (
8937 \series default 
8938 0xab
8939 \series bold 
8940 )
8941 \series default 
8942
8943 \begin_inset Quotes srd
8944 \end_inset 
8945
8946
8947 \family default 
8948  and 
8949 \family sans 
8950
8951 \begin_inset Quotes sld
8952 \end_inset 
8953
8954 __interrupt\SpecialChar ~
8955 (2)
8956 \begin_inset Quotes srd
8957 \end_inset 
8958
8959
8960 \family default 
8961 ).
8962  
8963 \newline 
8964 Splint has an excellent on line manual at 
8965 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
8966
8967 \end_inset 
8968
8969  and it's capabilities go beyond pure syntax checking.
8970  You'll need to tell splint the location of SDCC's include files so a typical
8971  command line could look like this: 
8972 \newline 
8973
8974 \family sans 
8975 splint\SpecialChar ~
8976 -I\SpecialChar ~
8977 /usr/local/share/sdcc/include/mcs51/\SpecialChar ~
8978 \SpecialChar ~
8979 myprogram.c
8980 \layout Subsection
8981
8982 Intermediate Dump Options
8983 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
8984
8985 \end_inset 
8986
8987
8988 \begin_inset LatexCommand \index{Options intermediate dump}
8989
8990 \end_inset 
8991
8992
8993 \begin_inset LatexCommand \index{Intermediate dump options}
8994
8995 \end_inset 
8996
8997
8998 \layout Standard
8999
9000 The following options are provided for the purpose of retargetting and debugging
9001  the compiler.
9002  They provide a means to dump the intermediate code (iCode
9003 \begin_inset LatexCommand \index{iCode}
9004
9005 \end_inset 
9006
9007 ) generated by the compiler in human readable form at various stages of
9008  the compilation process.
9009  More on iCodes see chapter 
9010 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
9011
9012 \end_inset 
9013
9014  
9015 \begin_inset Quotes srd
9016 \end_inset 
9017
9018 The anatomy of the compiler
9019 \begin_inset Quotes srd
9020 \end_inset 
9021
9022 .
9023 \layout List
9024 \labelwidthstring 00.00.0000
9025
9026
9027 \series bold 
9028 -
9029 \begin_inset ERT
9030 status Collapsed
9031
9032 \layout Standard
9033
9034 \backslash 
9035 /
9036 \end_inset 
9037
9038 -dumpraw
9039 \begin_inset LatexCommand \index{-\/-dumpraw}
9040
9041 \end_inset 
9042
9043
9044 \series default 
9045  This option will cause the compiler to dump the intermediate code into
9046  a file of named 
9047 \emph on 
9048 <source filename>.dumpraw
9049 \emph default 
9050  just after the intermediate code has been generated for a function, i.e.
9051  before any optimizations are done.
9052  The basic blocks
9053 \begin_inset LatexCommand \index{Basic blocks}
9054
9055 \end_inset 
9056
9057  at this stage ordered in the depth first number, so they may not be in
9058  sequence of execution.
9059 \layout List
9060 \labelwidthstring 00.00.0000
9061
9062
9063 \series bold 
9064 -
9065 \begin_inset ERT
9066 status Collapsed
9067
9068 \layout Standard
9069
9070 \backslash 
9071 /
9072 \end_inset 
9073
9074 -dumpgcse
9075 \begin_inset LatexCommand \index{-\/-dumpgcse}
9076
9077 \end_inset 
9078
9079
9080 \series default 
9081  Will create a dump of iCode's, after global subexpression elimination
9082 \begin_inset LatexCommand \index{Global subexpression elimination}
9083
9084 \end_inset 
9085
9086 , into a file named 
9087 \emph on 
9088 <source filename>.dumpgcse.
9089 \layout List
9090 \labelwidthstring 00.00.0000
9091
9092
9093 \series bold 
9094 -
9095 \begin_inset ERT
9096 status Collapsed
9097
9098 \layout Standard
9099
9100 \backslash 
9101 /
9102 \end_inset 
9103
9104 -dumpdeadcode
9105 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
9106
9107 \end_inset 
9108
9109
9110 \series default 
9111  Will create a dump of iCode's, after deadcode elimination
9112 \begin_inset LatexCommand \index{Dead-code elimination}
9113
9114 \end_inset 
9115
9116 , into a file named 
9117 \emph on 
9118 <source filename>.dumpdeadcode.
9119 \layout List
9120 \labelwidthstring 00.00.0000
9121
9122
9123 \series bold 
9124 -
9125 \begin_inset ERT
9126 status Collapsed
9127
9128 \layout Standard
9129
9130 \backslash 
9131 /
9132 \end_inset 
9133
9134 -dumploop
9135 \begin_inset LatexCommand \index{-\/-dumploop}
9136
9137 \end_inset 
9138
9139
9140 \series default 
9141 \size large 
9142  
9143 \size default 
9144 Will create a dump of iCode's, after loop optimizations
9145 \begin_inset LatexCommand \index{Loop optimization}
9146
9147 \end_inset 
9148
9149 , into a file named 
9150 \emph on 
9151 <source filename>.dumploop.
9152 \layout List
9153 \labelwidthstring 00.00.0000
9154
9155
9156 \series bold 
9157 -
9158 \begin_inset ERT
9159 status Collapsed
9160
9161 \layout Standard
9162
9163 \backslash 
9164 /
9165 \end_inset 
9166
9167 -dumprange
9168 \begin_inset LatexCommand \index{-\/-dumprange}
9169
9170 \end_inset 
9171
9172
9173 \series default 
9174 \size large 
9175  
9176 \size default 
9177 Will create a dump of iCode's, after live range analysis
9178 \begin_inset LatexCommand \index{Live range analysis}
9179
9180 \end_inset 
9181
9182 , into a file named 
9183 \emph on 
9184 <source filename>.dumprange.
9185 \layout List
9186 \labelwidthstring 00.00.0000
9187
9188
9189 \series bold 
9190 -
9191 \begin_inset ERT
9192 status Collapsed
9193
9194 \layout Standard
9195
9196 \backslash 
9197 /
9198 \end_inset 
9199
9200 -dumlrange
9201 \begin_inset LatexCommand \index{-\/-dumlrange}
9202
9203 \end_inset 
9204
9205
9206 \series default 
9207  Will dump the life ranges
9208 \begin_inset LatexCommand \index{Live range analysis}
9209
9210 \end_inset 
9211
9212  for all symbols.
9213 \layout List
9214 \labelwidthstring 00.00.0000
9215
9216
9217 \series bold 
9218 -
9219 \begin_inset ERT
9220 status Collapsed
9221
9222 \layout Standard
9223
9224 \backslash 
9225 /
9226 \end_inset 
9227
9228 -dumpregassign
9229 \begin_inset LatexCommand \index{-\/-dumpregassign}
9230
9231 \end_inset 
9232
9233
9234 \bar under 
9235  
9236 \series default 
9237 \bar default 
9238 Will create a dump of iCode's, after register assignment
9239 \begin_inset LatexCommand \index{Register assignment}
9240
9241 \end_inset 
9242
9243 , into a file named 
9244 \emph on 
9245 <source filename>.dumprassgn.
9246 \layout List
9247 \labelwidthstring 00.00.0000
9248
9249
9250 \series bold 
9251 -
9252 \begin_inset ERT
9253 status Collapsed
9254
9255 \layout Standard
9256
9257 \backslash 
9258 /
9259 \end_inset 
9260
9261 -dumplrange
9262 \begin_inset LatexCommand \index{-\/-dumplrange}
9263
9264 \end_inset 
9265
9266
9267 \series default 
9268  Will create a dump of the live ranges of iTemp's
9269 \layout List
9270 \added_space_bottom bigskip \labelwidthstring 00.00.0000
9271
9272
9273 \series bold 
9274 -
9275 \begin_inset ERT
9276 status Collapsed
9277
9278 \layout Standard
9279
9280 \backslash 
9281 /
9282 \end_inset 
9283
9284 -dumpall
9285 \begin_inset LatexCommand \index{-\/-dumpall}
9286
9287 \end_inset 
9288
9289
9290 \size large 
9291 \bar under 
9292  
9293 \series default 
9294 \size default 
9295 \bar default 
9296 Will cause all the above mentioned dumps to be created.
9297 \layout Subsection
9298
9299 Redirecting output on Windows Shells
9300 \layout Standard
9301 \added_space_bottom bigskip 
9302 By default SDCC writes it's error messages to 
9303 \begin_inset Quotes sld
9304 \end_inset 
9305
9306 standard error
9307 \begin_inset Quotes srd
9308 \end_inset 
9309
9310 .
9311  To force all messages to 
9312 \begin_inset Quotes sld
9313 \end_inset 
9314
9315 standard output
9316 \begin_inset Quotes srd
9317 \end_inset 
9318
9319  use 
9320 \series bold 
9321 -
9322 \series default 
9323 \emph on 
9324
9325 \begin_inset ERT
9326 status Collapsed
9327
9328 \layout Standard
9329
9330 \backslash 
9331 /
9332 \end_inset 
9333
9334
9335 \series bold 
9336 \emph default 
9337 -
9338 \series default 
9339 use-stdout
9340 \begin_inset LatexCommand \index{-\/-use-stdout}
9341
9342 \end_inset 
9343
9344 .
9345  Additionally, if you happen to have visual studio installed in your windows
9346  machine, you can use it to compile your sources using a custom build and
9347  the SDCC -
9348 \emph on 
9349
9350 \begin_inset ERT
9351 status Collapsed
9352
9353 \layout Standard
9354
9355 \backslash 
9356 /
9357 \end_inset 
9358
9359
9360 \emph default 
9361 -vc
9362 \begin_inset LatexCommand \index{-\/-vc}
9363
9364 \end_inset 
9365
9366  option.
9367  Something like this should work:
9368 \newline 
9369
9370 \newline 
9371
9372 \series bold 
9373 c:
9374 \backslash 
9375 sdcc
9376 \backslash 
9377 bin
9378 \backslash 
9379 sdcc.exe -
9380 \series default 
9381 \emph on 
9382
9383 \begin_inset ERT
9384 status Collapsed
9385
9386 \layout Standard
9387
9388 \backslash 
9389 /
9390 \end_inset 
9391
9392
9393 \series bold 
9394 \emph default 
9395 -vc -
9396 \series default 
9397 \emph on 
9398
9399 \begin_inset ERT
9400 status Collapsed
9401
9402 \layout Standard
9403
9404 \backslash 
9405 /
9406 \end_inset 
9407
9408
9409 \series bold 
9410 \emph default 
9411 -model-large -c $(InputPath)
9412 \layout Section
9413
9414 Environment variables
9415 \begin_inset LatexCommand \index{Environment variables}
9416
9417 \end_inset 
9418
9419
9420 \layout Standard
9421
9422 SDCC recognizes the following environment variables:
9423 \layout List
9424 \labelwidthstring 00.00.0000
9425
9426
9427 \series bold 
9428 SDCC_LEAVE_SIGNALS
9429 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
9430
9431 \end_inset 
9432
9433
9434 \series default 
9435  SDCC installs a signal handler
9436 \begin_inset LatexCommand \index{signal handler}
9437
9438 \end_inset 
9439
9440  to be able to delete temporary files after an user break (^C) or an exception.
9441  If this environment variable is set, SDCC won't install the signal handler
9442  in order to be able to debug SDCC.
9443 \layout List
9444 \labelwidthstring 00.00.0000
9445
9446
9447 \series bold 
9448 TMP,\SpecialChar ~
9449 TEMP,\SpecialChar ~
9450 TMPDIR
9451 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
9452
9453 \end_inset 
9454
9455
9456 \series default 
9457  Path, where temporary files will be created.
9458  The order of the variables is the search order.
9459  In a standard *nix environment these variables are not set, and there's
9460  no need to set them.
9461  On Windows it's recommended to set one of them.
9462 \layout List
9463 \labelwidthstring 00.00.0000
9464
9465
9466 \series bold 
9467 SDCC_HOME
9468 \begin_inset LatexCommand \index{SDCC\_HOME}
9469
9470 \end_inset 
9471
9472
9473 \series default 
9474  Path, see section 
9475 \begin_inset LatexCommand \ref{sub:Install-paths}
9476
9477 \end_inset 
9478
9479 \SpecialChar ~
9480
9481 \begin_inset Quotes sld
9482 \end_inset 
9483
9484  Install Paths
9485 \begin_inset Quotes srd
9486 \end_inset 
9487
9488 .
9489 \layout List
9490 \labelwidthstring 00.00.0000
9491
9492
9493 \series bold 
9494 SDCC_INCLUDE
9495 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
9496
9497 \end_inset 
9498
9499
9500 \series default 
9501  Path, see section 
9502 \begin_inset LatexCommand \ref{sub:Search-Paths}
9503
9504 \end_inset 
9505
9506 \SpecialChar ~
9507
9508 \begin_inset Quotes sld
9509 \end_inset 
9510
9511 Search Paths
9512 \begin_inset Quotes srd
9513 \end_inset 
9514
9515 .
9516 \layout List
9517 \labelwidthstring 00.00.0000
9518
9519
9520 \series bold 
9521 SDCC_LIB
9522 \begin_inset LatexCommand \index{SDCC\_LIB}
9523
9524 \end_inset 
9525
9526
9527 \series default 
9528  Path, see section 
9529 \begin_inset LatexCommand \ref{sub:Search-Paths}
9530
9531 \end_inset 
9532
9533 \SpecialChar ~
9534
9535 \begin_inset Quotes sld
9536 \end_inset 
9537
9538 Search Paths
9539 \begin_inset Quotes srd
9540 \end_inset 
9541
9542 ..
9543 \layout Standard
9544 \added_space_bottom bigskip 
9545 There are some more environment variables recognized by SDCC, but these
9546  are solely used for debugging purposes.
9547  They can change or disappear very quickly, and will never be documented.
9548 \layout Section
9549
9550 Storage Class Language Extensions
9551 \layout Subsection
9552
9553 MCS51/DS390 Storage Class
9554 \begin_inset LatexCommand \index{Storage class}
9555
9556 \end_inset 
9557
9558  Language Extensions
9559 \layout Standard
9560
9561 In addition to the ANSI storage classes SDCC allows the following MCS51
9562  specific storage classes:
9563 \layout Subsubsection
9564
9565 data
9566 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9567
9568 \end_inset 
9569
9570
9571 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
9572
9573 \end_inset 
9574
9575  / near
9576 \begin_inset LatexCommand \index{near (storage class)}
9577
9578 \end_inset 
9579
9580
9581 \begin_inset LatexCommand \index{\_\_near (storage class)}
9582
9583 \end_inset 
9584
9585
9586 \layout Standard
9587
9588 This is the 
9589 \series bold 
9590 default
9591 \series default 
9592  storage class for the Small Memory model (
9593 \emph on 
9594 data
9595 \emph default 
9596  and 
9597 \emph on 
9598 near
9599 \emph default 
9600  or the more ANSI-C compliant forms 
9601 \emph on 
9602 __data
9603 \emph default 
9604  and 
9605 \emph on 
9606 __near
9607 \emph default 
9608  can be used synonymously).
9609  Variables declared with this storage class will be allocated in the directly
9610  addressable portion of the internal RAM of a 8051, e.g.:
9611 \layout Verse
9612
9613
9614 \family typewriter 
9615 __data unsigned char test_data;
9616 \layout Standard
9617
9618 Writing 0x01 to this variable generates the assembly code:
9619 \layout Verse
9620
9621
9622 \family typewriter 
9623 75*00 01\SpecialChar ~
9624 \SpecialChar ~
9625 \SpecialChar ~
9626 mov\SpecialChar ~
9627 \SpecialChar ~
9628 _test_data,#0x01
9629 \layout Subsubsection
9630
9631 xdata
9632 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9633
9634 \end_inset 
9635
9636
9637 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
9638
9639 \end_inset 
9640
9641  / far
9642 \begin_inset LatexCommand \index{far (storage class)}
9643
9644 \end_inset 
9645
9646
9647 \begin_inset LatexCommand \index{\_\_far (storage class)}
9648
9649 \end_inset 
9650
9651
9652 \layout Standard
9653
9654 Variables declared with this storage class will be placed in the external
9655  RAM.
9656  This is the 
9657 \series bold 
9658 default
9659 \series default 
9660  storage class for the Large Memory model, e.g.:
9661 \layout Verse
9662
9663
9664 \family typewriter 
9665 __xdata unsigned char test_xdata;
9666 \layout Standard
9667
9668 Writing 0x01 to this variable generates the assembly code:
9669 \layout Verse
9670
9671
9672 \family typewriter 
9673 90s00r00\SpecialChar ~
9674 \SpecialChar ~
9675 \SpecialChar ~
9676 mov\SpecialChar ~
9677 \SpecialChar ~
9678 dptr,#_test_xdata 
9679 \newline 
9680 74\SpecialChar ~
9681 01\SpecialChar ~
9682 \SpecialChar ~
9683 \SpecialChar ~
9684 \SpecialChar ~
9685 \SpecialChar ~
9686 \SpecialChar ~
9687 mov\SpecialChar ~
9688 \SpecialChar ~
9689 a,#0x01 
9690 \newline 
9691 F0\SpecialChar ~
9692 \SpecialChar ~
9693 \SpecialChar ~
9694 \SpecialChar ~
9695 \SpecialChar ~
9696 \SpecialChar ~
9697 \SpecialChar ~
9698 \SpecialChar ~
9699 \SpecialChar ~
9700 movx\SpecialChar ~
9701 @dptr,a 
9702 \layout Subsubsection
9703
9704 idata
9705 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
9706
9707 \end_inset 
9708
9709
9710 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
9711
9712 \end_inset 
9713
9714
9715 \layout Standard
9716
9717 Variables declared with this storage class will be allocated into the indirectly
9718  addressable portion of the internal ram of a 8051, e.g.:
9719 \layout Verse
9720
9721
9722 \family typewriter 
9723 __idata unsigned char test_idata;
9724 \layout Standard
9725
9726 Writing 0x01 to this variable generates the assembly code:
9727 \layout Verse
9728
9729
9730 \family typewriter 
9731 78r00\SpecialChar ~
9732 \SpecialChar ~
9733 \SpecialChar ~
9734 \SpecialChar ~
9735 \SpecialChar ~
9736 \SpecialChar ~
9737 \SpecialChar ~
9738 mov\SpecialChar ~
9739 \SpecialChar ~
9740 r0,#_test_idata
9741 \newline 
9742 76\SpecialChar ~
9743 01\SpecialChar ~
9744 \SpecialChar ~
9745 \SpecialChar ~
9746 \SpecialChar ~
9747 \SpecialChar ~
9748 \SpecialChar ~
9749 \SpecialChar ~
9750 mov\SpecialChar ~
9751 \SpecialChar ~
9752 @r0,#0x01
9753 \layout Standard
9754
9755 Please note, the first 128 byte of idata physically access the same RAM
9756  as the data memory.
9757  The original 8051 had 128 byte idata memory, nowadays most devices have
9758  256 byte idata memory.
9759  The stack
9760 \begin_inset LatexCommand \index{stack}
9761
9762 \end_inset 
9763
9764  is located in idata memory.
9765 \layout Subsubsection
9766
9767 pdata
9768 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
9769
9770 \end_inset 
9771
9772
9773 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
9774
9775 \end_inset 
9776
9777
9778 \layout Standard
9779
9780 Paged xdata access is just as straightforward as using the other addressing
9781  modes of a 8051.
9782  It is typically located at the start of xdata and has a maximum size of
9783  256 bytes.
9784  The following example writes 0x01 to the pdata variable.
9785  Please note, pdata access physically accesses xdata memory.
9786  The high byte of the address is determined by port P2 
9787 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
9788
9789 \end_inset 
9790
9791 (or in case of some 8051 variants by a separate Special Function Register,
9792  see section 
9793 \begin_inset LatexCommand \ref{sub:MCS51-variants}
9794
9795 \end_inset 
9796
9797 ).
9798  This is the 
9799 \series bold 
9800 default
9801 \series default 
9802  storage class for the Medium Memory model, e.g.:
9803 \layout Verse
9804
9805
9806 \family typewriter 
9807 __pdata unsigned char test_pdata;
9808 \layout Standard
9809
9810 Writing 0x01 to this variable generates the assembly code:
9811 \layout Verse
9812
9813
9814 \family typewriter 
9815 78r00\SpecialChar ~
9816 \SpecialChar ~
9817 \SpecialChar ~
9818 \SpecialChar ~
9819 \SpecialChar ~
9820 \SpecialChar ~
9821 mov r0,#_test_pdata
9822 \newline 
9823 74 01\SpecialChar ~
9824 \SpecialChar ~
9825 \SpecialChar ~
9826 \SpecialChar ~
9827 \SpecialChar ~
9828 \SpecialChar ~
9829 mov a,#0x01 
9830 \newline 
9831 F2\SpecialChar ~
9832 \SpecialChar ~
9833 \SpecialChar ~
9834 \SpecialChar ~
9835 \SpecialChar ~
9836 \SpecialChar ~
9837 \SpecialChar ~
9838 \SpecialChar ~
9839 \SpecialChar ~
9840 movx @r0,a
9841 \layout Standard
9842
9843 If the -
9844 \begin_inset ERT
9845 status Collapsed
9846
9847 \layout Standard
9848
9849 \backslash 
9850 /
9851 \end_inset 
9852
9853 -xstack
9854 \begin_inset LatexCommand \index{-\/-xstack}
9855
9856 \end_inset 
9857
9858  option is used the pdata memory area is followed by the xstack memory area
9859  and the sum of their sizes is limited to 256 bytes.
9860 \layout Subsubsection
9861
9862 code
9863 \begin_inset LatexCommand \index{code}
9864
9865 \end_inset 
9866
9867
9868 \begin_inset LatexCommand \index{\_\_code}
9869
9870 \end_inset 
9871
9872
9873 \layout Standard
9874
9875 'Variables' declared with this storage class will be placed in the code
9876  memory:
9877 \layout Verse
9878
9879
9880 \family typewriter 
9881 __code unsigned char test_code;
9882 \layout Standard
9883
9884 Read access to this variable generates the assembly code:
9885 \layout Verse
9886
9887
9888 \family typewriter 
9889 90s00r6F\SpecialChar ~
9890 \SpecialChar ~
9891 \SpecialChar ~
9892 mov dptr,#_test_code
9893 \newline 
9894 E4\SpecialChar ~
9895 \SpecialChar ~
9896 \SpecialChar ~
9897 \SpecialChar ~
9898 \SpecialChar ~
9899 \SpecialChar ~
9900 \SpecialChar ~
9901 \SpecialChar ~
9902 \SpecialChar ~
9903 clr a
9904 \newline 
9905 93\SpecialChar ~
9906 \SpecialChar ~
9907 \SpecialChar ~
9908 \SpecialChar ~
9909 \SpecialChar ~
9910 \SpecialChar ~
9911 \SpecialChar ~
9912 \SpecialChar ~
9913 \SpecialChar ~
9914 movc a,@a+dptr 
9915 \layout Standard
9916
9917
9918 \family typewriter 
9919 char
9920 \family default 
9921  indexed arrays of characters in code memory can be accessed efficiently:
9922 \layout Verse
9923
9924
9925 \family typewriter 
9926 __code char test_array[] = {'c','h','e','a','p'}; 
9927 \layout Standard
9928
9929 Read access to this array using an 8-bit unsigned index generates the assembly
9930  code:
9931 \layout Verse
9932
9933
9934 \family typewriter 
9935 E5*00\SpecialChar ~
9936 \SpecialChar ~
9937 \SpecialChar ~
9938 \SpecialChar ~
9939 \SpecialChar ~
9940 \SpecialChar ~
9941 mov a,_index 
9942 \layout Verse
9943
9944
9945 \family typewriter 
9946 90s00r41\SpecialChar ~
9947 \SpecialChar ~
9948 \SpecialChar ~
9949 mov dptr,#_test_array
9950 \layout Verse
9951
9952
9953 \family typewriter 
9954 93\SpecialChar ~
9955 \SpecialChar ~
9956 \SpecialChar ~
9957 \SpecialChar ~
9958 \SpecialChar ~
9959 \SpecialChar ~
9960 \SpecialChar ~
9961 \SpecialChar ~
9962 \SpecialChar ~
9963 movc a,@a+dptr 
9964 \layout Subsubsection
9965
9966 bit
9967 \begin_inset LatexCommand \index{bit}
9968
9969 \end_inset 
9970
9971
9972 \begin_inset LatexCommand \index{\_\_bit}
9973
9974 \end_inset 
9975
9976
9977 \layout Standard
9978
9979 This is a data-type and a storage class specifier.
9980  When a variable is declared as a bit, it is allocated into the bit addressable
9981  memory of 8051, e.g.:
9982 \layout Verse
9983
9984
9985 \family typewriter 
9986 __bit test_bit;
9987 \layout Standard
9988
9989 Writing 1 to this variable generates the assembly code:
9990 \layout Verse
9991
9992
9993 \family typewriter 
9994 D2*00\SpecialChar ~
9995 \SpecialChar ~
9996 \SpecialChar ~
9997 \SpecialChar ~
9998 \SpecialChar ~
9999 \SpecialChar ~
10000 \SpecialChar ~
10001 setb\SpecialChar ~
10002 _test_bit
10003 \layout Standard
10004
10005 The bit addressable memory consists of 128 bits which are located from 0x20
10006  to 0x2f in data memory.
10007  
10008 \newline 
10009 Apart from this 8051 specific storage class most architectures support ANSI-C
10010  bitfields
10011 \begin_inset LatexCommand \index{bitfields}
10012
10013 \end_inset 
10014
10015
10016 \begin_inset Foot
10017 collapsed false
10018
10019 \layout Standard
10020
10021 Not really meant as examples, but nevertheless showing what bitfields are
10022  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
10023 \end_inset 
10024
10025 .
10026  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
10027  signed modifier are implemented as unsigned.
10028 \layout Subsubsection
10029
10030 sfr
10031 \begin_inset LatexCommand \index{sfr}
10032
10033 \end_inset 
10034
10035
10036 \begin_inset LatexCommand \index{\_\_sfr}
10037
10038 \end_inset 
10039
10040  / sfr16
10041 \begin_inset LatexCommand \index{sfr16}
10042
10043 \end_inset 
10044
10045
10046 \begin_inset LatexCommand \index{\_\_sfr16}
10047
10048 \end_inset 
10049
10050  / sfr32
10051 \begin_inset LatexCommand \index{sfr32}
10052
10053 \end_inset 
10054
10055
10056 \begin_inset LatexCommand \index{\_\_sfr32}
10057
10058 \end_inset 
10059
10060  / sbit
10061 \begin_inset LatexCommand \index{\_\_sbit}
10062
10063 \end_inset 
10064
10065
10066 \begin_inset LatexCommand \index{sbit}
10067
10068 \end_inset 
10069
10070
10071 \layout Standard
10072
10073 Like the bit keyword, 
10074 \emph on 
10075 sfr / sfr16 / sfr32 / sbit 
10076 \emph default 
10077 signify both a data-type and storage class, they are used to describe the
10078  
10079 \emph on 
10080 s
10081 \emph default 
10082 pecial 
10083 \emph on 
10084 f
10085 \emph default 
10086 unction 
10087 \emph on 
10088 r
10089 \emph default 
10090 egisters and 
10091 \emph on 
10092 s
10093 \emph default 
10094 pecial 
10095 \emph on 
10096 bit
10097 \emph default 
10098  variables of a 8051, eg:
10099 \layout Verse
10100
10101
10102 \family typewriter 
10103 __sfr __at
10104 \begin_inset LatexCommand \index{at}
10105
10106 \end_inset 
10107
10108
10109 \begin_inset LatexCommand \index{\_\_at}
10110
10111 \end_inset 
10112
10113  (0x80) P0;\SpecialChar ~
10114  /* special function register P0 at location 0x80 */
10115 \newline 
10116
10117 \newline 
10118 /* 16 bit special function register combination for timer 0
10119 \newline 
10120 \SpecialChar ~
10121 \SpecialChar ~
10122  with the high byte at location 0x8C and the low byte at location 0x8A */
10123 \newline 
10124 __sfr16 __at (0x8C8A) TMR0;
10125 \newline 
10126
10127 \newline 
10128 __sbit __at
10129 \begin_inset LatexCommand \index{at}
10130
10131 \end_inset 
10132
10133
10134 \begin_inset LatexCommand \index{\_\_at}
10135
10136 \end_inset 
10137
10138  (0xd7) CY;\SpecialChar ~
10139  /* CY (Carry Flag
10140 \begin_inset LatexCommand \index{Flags}
10141
10142 \end_inset 
10143
10144
10145 \begin_inset LatexCommand \index{Carry flag}
10146
10147 \end_inset 
10148
10149 ) */
10150 \layout Standard
10151
10152 Special function registers which are located on an address dividable by
10153  8 are bit-addressable, an
10154 \emph on 
10155  sbit
10156 \emph default 
10157  addresses a specific bit within these sfr.
10158 \newline 
10159 16 Bit and 32 bit special function register combinations which require a
10160  certain access order are better not declared using 
10161 \emph on 
10162 sfr16
10163 \emph default 
10164  or 
10165 \emph on 
10166 sfr32.
10167
10168 \emph default 
10169  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
10170  this is not guaranteed.
10171 \newline 
10172
10173 \layout Standard
10174
10175 Please note, if you use a header file which was written for another compiler
10176  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
10177  likely be 
10178 \emph on 
10179 not 
10180 \emph default 
10181 compatible.
10182  Specifically the syntax 
10183 \family typewriter 
10184 \SpecialChar ~
10185 sfr P0 = 0x80;\SpecialChar ~
10186
10187 \family default 
10188  is compiled 
10189 \emph on 
10190 without warning
10191 \emph default 
10192  by SDCC to an assignment of 0x80 to a variable called P0 
10193 \family typewriter 
10194
10195 \begin_inset Marginal
10196 collapsed true
10197
10198 \layout Standard
10199
10200
10201 \series bold 
10202 \SpecialChar ~
10203 !
10204 \end_inset 
10205
10206 .
10207  
10208 \family default 
10209 Nevertheless it is possible to write header files
10210 \begin_inset LatexCommand \index{Header files}
10211
10212 \end_inset 
10213
10214
10215 \begin_inset LatexCommand \index{Include files}
10216
10217 \end_inset 
10218
10219  which can be shared among different compilers (see section 
10220 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
10221
10222 \end_inset 
10223
10224 ).
10225  
10226 \layout Subsubsection
10227
10228 Pointers
10229 \begin_inset LatexCommand \index{Pointer}
10230
10231 \end_inset 
10232
10233  to MCS51/DS390 specific memory spaces
10234 \layout Standard
10235
10236 SDCC allows (via language extensions) pointers to explicitly point to any
10237  of the memory spaces
10238 \begin_inset LatexCommand \index{Memory model}
10239
10240 \end_inset 
10241
10242  of the 8051.
10243  In addition to the explicit pointers, the compiler uses (by default) generic
10244  pointers which can be used to point to any of the memory spaces.
10245 \newline 
10246
10247 \newline 
10248 Pointer declaration examples:
10249 \layout Verse
10250
10251
10252 \family typewriter 
10253 /* pointer physically in internal ram pointing to object in external ram
10254  */ 
10255 \newline 
10256 __xdata unsigned char * __data p;
10257 \newline 
10258
10259 \newline 
10260 /* pointer physically in external ram pointing to object in internal ram
10261  */ 
10262 \newline 
10263 __data unsigned char * __xdata p;
10264 \newline 
10265
10266 \newline 
10267 /* pointer physically in code rom pointing to data in xdata space */ 
10268 \newline 
10269 __xdata unsigned char * __code p;
10270 \newline 
10271
10272 \newline 
10273 /* pointer physically in code space pointing to data in code space */ 
10274 \newline 
10275 __code unsigned char * __code p;
10276 \newline 
10277
10278 \newline 
10279 /* generic pointer physically located in xdata space */
10280 \newline 
10281 unsigned char * __xdata p;
10282 \newline 
10283
10284 \newline 
10285 /* generic pointer physically located in default memory space */
10286 \newline 
10287 unsigned char * p;
10288 \newline 
10289
10290 \newline 
10291 /* the following is a function pointer
10292 \begin_inset LatexCommand \index{function pointer}
10293
10294 \end_inset 
10295
10296  physically located in data space */
10297 \newline 
10298 char (* __data fp)(void);
10299 \layout Standard
10300
10301 Well you get the idea.
10302  
10303 \newline 
10304
10305 \newline 
10306 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
10307 \emph on 
10308 generic
10309 \emph default 
10310  pointers.
10311  
10312 \size small 
10313
10314 \newline 
10315
10316 \newline 
10317
10318 \size default 
10319 The highest order byte of the 
10320 \emph on 
10321 generic
10322 \emph default 
10323  pointers contains the data space information.
10324  Assembler support routines are called whenever data is stored or retrieved
10325  using 
10326 \emph on 
10327 generic
10328 \emph default 
10329  pointers.
10330  These are useful for developing reusable library
10331 \begin_inset LatexCommand \index{Libraries}
10332
10333 \end_inset 
10334
10335  routines.
10336  Explicitly specifying the pointer
10337 \begin_inset LatexCommand \index{pointer}
10338
10339 \end_inset 
10340
10341  type will generate the most efficient code.
10342 \layout Subsubsection
10343
10344 Notes on MCS51 memory
10345 \begin_inset LatexCommand \index{MCS51 memory}
10346
10347 \end_inset 
10348
10349  layout
10350 \layout Standard
10351
10352 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
10353  RAM memory which is structured as follows:
10354 \newline 
10355
10356 \newline 
10357 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
10358  
10359 \newline 
10360 - Bytes 20-2F - 16 bytes to hold 128 bit
10361 \begin_inset LatexCommand \index{bit}
10362
10363 \end_inset 
10364
10365  variables and, 
10366 \newline 
10367 - Bytes 30-7F - 80 bytes for general purpose use.
10368 \newline 
10369
10370 \layout Standard
10371
10372 Additionally some members of the MCS51 family may have up to 128 bytes of
10373  additional, indirectly addressable, internal RAM memory (
10374 \emph on 
10375 idata
10376 \emph default 
10377
10378 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
10379
10380 \end_inset 
10381
10382
10383 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
10384
10385 \end_inset 
10386
10387 ).
10388  Furthermore, some chips may have some built in external memory (
10389 \emph on 
10390 xdata
10391 \emph default 
10392
10393 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10394
10395 \end_inset 
10396
10397
10398 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10399
10400 \end_inset 
10401
10402 ) which should not be confused with the internal, directly addressable RAM
10403  memory (
10404 \emph on 
10405 data
10406 \emph default 
10407
10408 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10409
10410 \end_inset 
10411
10412
10413 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10414
10415 \end_inset 
10416
10417 ).
10418  Sometimes this built in 
10419 \emph on 
10420 xdata
10421 \emph default 
10422  memory has to be activated before using it (you can probably find this
10423  information on the datasheet of the microcontroller your are using, see
10424  also section 
10425 \begin_inset LatexCommand \ref{sub:Startup-Code}
10426
10427 \end_inset 
10428
10429 \SpecialChar ~
10430 Startup-Code).
10431 \layout Standard
10432
10433 Normally SDCC will only use the first bank
10434 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10435
10436 \end_inset 
10437
10438  of registers (register bank 0), but it is possible to specify that other
10439  banks of registers (keyword 
10440 \emph on 
10441 using
10442 \emph default 
10443  
10444 \emph on 
10445
10446 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10447
10448 \end_inset 
10449
10450
10451 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
10452
10453 \end_inset 
10454
10455
10456 \emph default 
10457 ) should be used in interrupt
10458 \begin_inset LatexCommand \index{interrupt}
10459
10460 \end_inset 
10461
10462
10463 \begin_inset LatexCommand \index{\_\_interrupt}
10464
10465 \end_inset 
10466
10467  routines.
10468  By default, the compiler will place the stack after the last byte of allocated
10469  memory for variables.
10470  For example, if the first 2 banks of registers are used, and only four
10471  bytes are used for 
10472 \emph on 
10473 data
10474 \emph default 
10475  variables, it will position the base of the internal stack at address 20
10476  (0x14).
10477  This implies that as the stack
10478 \begin_inset LatexCommand \index{stack}
10479
10480 \end_inset 
10481
10482  grows, it will use up the remaining register banks, and the 16 bytes used
10483  by the 128 bit variables, and 80 bytes for general purpose use.
10484  If any bit variables are used, the data variables will be placed in unused
10485  register banks and after the byte holding the last bit variable.
10486  For example, if register banks 0 and 1 are used, and there are 9 bit variables
10487  (two bytes used), 
10488 \emph on 
10489 data
10490 \emph default 
10491  variables will be placed starting from address 0x10 to 0x20 and continue
10492  at address 0x22.
10493  You can also use -
10494 \begin_inset ERT
10495 status Collapsed
10496
10497 \layout Standard
10498
10499 \backslash 
10500 /
10501 \end_inset 
10502
10503 -data-loc
10504 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
10505
10506 \end_inset 
10507
10508  to specify the start address of the 
10509 \emph on 
10510 data
10511 \emph default 
10512  and -
10513 \begin_inset ERT
10514 status Collapsed
10515
10516 \layout Standard
10517
10518 \backslash 
10519 /
10520 \end_inset 
10521
10522 -iram-size
10523 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
10524
10525 \end_inset 
10526
10527  to specify the size of the total internal RAM (
10528 \emph on 
10529 data
10530 \emph default 
10531 +
10532 \emph on 
10533 idata
10534 \emph default 
10535 ).
10536  
10537 \newline 
10538
10539 \layout Standard
10540
10541 By default the 8051 linker will place the stack after the last byte of (i)data
10542  variables.
10543  Option -
10544 \begin_inset ERT
10545 status Collapsed
10546
10547 \layout Standard
10548
10549 \backslash 
10550 /
10551 \end_inset 
10552
10553 -stack-loc
10554 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
10555
10556 \end_inset 
10557
10558  allows you to specify the start of the stack, i.e.
10559  you could start it after any data in the general purpose area.
10560  If your microcontroller has additional indirectly addressable internal
10561  RAM (
10562 \emph on 
10563 idata
10564 \emph default 
10565 ) you can place the stack on it.
10566  You may also need to use -
10567 \begin_inset ERT
10568 status Collapsed
10569
10570 \layout Standard
10571
10572 \backslash 
10573 /
10574 \end_inset 
10575
10576 -xdata-loc
10577 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
10578
10579 \end_inset 
10580
10581  to set the start address of the external RAM (
10582 \emph on 
10583 xdata
10584 \emph default 
10585 ) and -
10586 \begin_inset ERT
10587 status Collapsed
10588
10589 \layout Standard
10590
10591 \backslash 
10592 /
10593 \end_inset 
10594
10595 -xram-size
10596 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
10597
10598 \end_inset 
10599
10600  to specify its size.
10601  Same goes for the code memory, using -
10602 \begin_inset ERT
10603 status Collapsed
10604
10605 \layout Standard
10606
10607 \backslash 
10608 /
10609 \end_inset 
10610
10611 -code-loc
10612 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
10613
10614 \end_inset 
10615
10616  and -
10617 \begin_inset ERT
10618 status Collapsed
10619
10620 \layout Standard
10621
10622 \backslash 
10623 /
10624 \end_inset 
10625
10626 -code-size
10627 \begin_inset LatexCommand \index{-\/-code-size <Value>}
10628
10629 \end_inset 
10630
10631 .
10632  If in doubt, don't specify any options and see if the resulting memory
10633  layout is appropriate, then you can adjust it.
10634 \layout Standard
10635 \added_space_bottom bigskip 
10636 The linker generates two files with memory allocation information.
10637  The first, with extension .map
10638 \begin_inset LatexCommand \index{<file>.map}
10639
10640 \end_inset 
10641
10642  shows all the variables and segments.
10643  The second with extension .mem
10644 \begin_inset LatexCommand \index{<file>.mem}
10645
10646 \end_inset 
10647
10648  shows the final memory layout.
10649  The linker will complain either if memory segments overlap, there is not
10650  enough memory, or there is not enough space for stack.
10651  If you get any linking warnings and/or errors related to stack or segments
10652  allocation, take a look at either the .map or .mem files to find out what
10653  the problem is.
10654  The .mem file may even suggest a solution to the problem.
10655 \layout Subsection
10656
10657 Z80/Z180 Storage Class
10658 \begin_inset LatexCommand \index{Z80!Storage class}
10659
10660 \end_inset 
10661
10662  Language Extensions
10663 \layout Subsubsection
10664
10665 sfr
10666 \begin_inset LatexCommand \index{sfr}
10667
10668 \end_inset 
10669
10670
10671 \begin_inset LatexCommand \index{\_\_sfr}
10672
10673 \end_inset 
10674
10675  (in/out to 8-bit addresses)
10676 \layout Standard
10677
10678 The Z80
10679 \begin_inset LatexCommand \index{Z80}
10680
10681 \end_inset 
10682
10683  family has separate address spaces for memory and 
10684 \emph on 
10685 i
10686 \emph default 
10687 nput/
10688 \emph on 
10689 o
10690 \emph default 
10691 utput memory.
10692  I/O memory
10693 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
10694
10695 \end_inset 
10696
10697
10698 \begin_inset LatexCommand \index{Z80!I/O memory}
10699
10700 \end_inset 
10701
10702
10703 \begin_inset LatexCommand \index{Z180!I/O memory}
10704
10705 \end_inset 
10706
10707  is accessed with special instructions, e.g.:
10708 \layout Verse
10709
10710
10711 \family typewriter 
10712 sfr at 0x78 IoPort;\SpecialChar ~
10713 \SpecialChar ~
10714 /* define a var in I/O space at 78h called IoPort */
10715  
10716 \layout Standard
10717
10718 Writing 0x01 to this variable generates the assembly code:
10719 \layout Verse
10720
10721
10722 \family typewriter 
10723 3E 01\SpecialChar ~
10724 \SpecialChar ~
10725 \SpecialChar ~
10726 \SpecialChar ~
10727 \SpecialChar ~
10728 \SpecialChar ~
10729 ld a,#0x01
10730 \newline 
10731 D3 78\SpecialChar ~
10732 \SpecialChar ~
10733 \SpecialChar ~
10734 \SpecialChar ~
10735 \SpecialChar ~
10736 \SpecialChar ~
10737 out (_IoPort),a 
10738 \layout Subsubsection
10739
10740 banked sfr
10741 \begin_inset LatexCommand \index{sfr}
10742
10743 \end_inset 
10744
10745
10746 \begin_inset LatexCommand \index{\_\_sfr}
10747
10748 \end_inset 
10749
10750  (in/out to 16-bit addresses)
10751 \layout Standard
10752
10753 The keyword 
10754 \emph on 
10755 banked
10756 \emph default 
10757  is used to support 16 bit addresses in I/O memory e.g.:
10758 \layout Verse
10759
10760
10761 \family typewriter 
10762 sfr banked at
10763 \begin_inset LatexCommand \index{at}
10764
10765 \end_inset 
10766
10767
10768 \begin_inset LatexCommand \index{\_\_at}
10769
10770 \end_inset 
10771
10772  0x123 IoPort; 
10773 \layout Standard
10774
10775 Writing 0x01 to this variable generates the assembly code:
10776 \layout Verse
10777
10778
10779 \family typewriter 
10780 01 23 01\SpecialChar ~
10781 \SpecialChar ~
10782 \SpecialChar ~
10783 ld bc,#_IoPort
10784 \newline 
10785 3E 01\SpecialChar ~
10786 \SpecialChar ~
10787 \SpecialChar ~
10788 \SpecialChar ~
10789 \SpecialChar ~
10790 \SpecialChar ~
10791 ld a,#0x01 
10792 \newline 
10793 ED 79\SpecialChar ~
10794 \SpecialChar ~
10795 \SpecialChar ~
10796 \SpecialChar ~
10797 \SpecialChar ~
10798 \SpecialChar ~
10799 out (c),a 
10800 \layout Subsubsection
10801
10802 sfr
10803 \begin_inset LatexCommand \index{sfr}
10804
10805 \end_inset 
10806
10807
10808 \begin_inset LatexCommand \index{\_\_sfr}
10809
10810 \end_inset 
10811
10812  (in0/out0 to 8 bit addresses on Z180
10813 \begin_inset LatexCommand \index{Z180}
10814
10815 \end_inset 
10816
10817 /HD64180
10818 \begin_inset LatexCommand \index{HD64180 (see Z180)}
10819
10820 \end_inset 
10821
10822 )
10823 \layout Standard
10824 \added_space_bottom bigskip 
10825 The compiler option -
10826 \begin_inset ERT
10827 status Collapsed
10828
10829 \layout Standard
10830
10831 \backslash 
10832 /
10833 \end_inset 
10834
10835 -portmode
10836 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
10837
10838 \end_inset 
10839
10840 =180 (80) and a compiler #pragma\SpecialChar ~
10841 portmode
10842 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
10843
10844 \end_inset 
10845
10846  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
10847 ns 
10848 \family typewriter 
10849 in0/out0
10850 \family default 
10851  instead of 
10852 \family typewriter 
10853 in/out
10854 \family default 
10855 .
10856  If you include the file z180.h this will be set automatically.
10857 \layout Subsection
10858
10859 HC08 Storage Class
10860 \begin_inset LatexCommand \index{HC08!Storage class}
10861
10862 \end_inset 
10863
10864  Language Extensions
10865 \layout Subsubsection
10866
10867 data
10868 \begin_inset LatexCommand \index{data (hc08 storage class)}
10869
10870 \end_inset 
10871
10872
10873 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
10874
10875 \end_inset 
10876
10877  
10878 \layout Standard
10879
10880 The data storage class declares a variable that resides in the first 256
10881  bytes of memory (the direct page).
10882  The HC08
10883 \begin_inset LatexCommand \index{HC08}
10884
10885 \end_inset 
10886
10887  is most efficient at accessing variables (especially pointers) stored here.
10888 \layout Subsubsection
10889
10890 xdata
10891 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
10892
10893 \end_inset 
10894
10895
10896 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
10897
10898 \end_inset 
10899
10900  
10901 \layout Standard
10902 \added_space_bottom bigskip 
10903 The xdata storage class declares a variable that can reside anywhere in
10904  memory.
10905  This is the default if no storage class is specified.
10906  
10907 \layout Section
10908
10909 Absolute Addressing
10910 \begin_inset LatexCommand \index{Absolute addressing}
10911
10912 \end_inset 
10913
10914
10915 \layout Standard
10916
10917 Data items can be assigned an absolute address with the 
10918 \emph on 
10919 at
10920 \begin_inset LatexCommand \index{at}
10921
10922 \end_inset 
10923
10924
10925 \begin_inset LatexCommand \index{\_\_at}
10926
10927 \end_inset 
10928
10929  <address>
10930 \emph default 
10931  keyword, in addition to a storage class, e.g.:
10932 \layout Verse
10933
10934
10935 \family typewriter 
10936 xdata
10937 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
10938
10939 \end_inset 
10940
10941
10942 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
10943
10944 \end_inset 
10945
10946  at
10947 \begin_inset LatexCommand \index{at}
10948
10949 \end_inset 
10950
10951
10952 \begin_inset LatexCommand \index{\_\_at}
10953
10954 \end_inset 
10955
10956  0x7ffe unsigned int chksum;
10957 \layout Standard
10958
10959 or, better conforming to ISO/IEC 9899 C:
10960 \layout Verse
10961
10962
10963 \family typewriter 
10964 __xdata __at (0x7ffe) unsigned int chksum;
10965 \layout Standard
10966
10967 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
10968  of the external ram.
10969  The compiler does 
10970 \emph on 
10971 not
10972 \emph default 
10973  reserve any space for variables declared in this way
10974 \begin_inset Marginal
10975 collapsed true
10976
10977 \layout Standard
10978
10979
10980 \series bold 
10981 \SpecialChar ~
10982 !
10983 \end_inset 
10984
10985  (they are implemented with an equate in the assembler).
10986  Thus it is left to the programmer to make sure there are no overlaps with
10987  other variables that are declared without the absolute address.
10988  The assembler listing file (.lst
10989 \begin_inset LatexCommand \index{<file>.lst}
10990
10991 \end_inset 
10992
10993 ) and the linker output files (.rst
10994 \begin_inset LatexCommand \index{<file>.rst}
10995
10996 \end_inset 
10997
10998 ) and (.map
10999 \begin_inset LatexCommand \index{<file>.map}
11000
11001 \end_inset 
11002
11003 ) are good places to look for such overlaps.
11004  Variables with an absolute address are 
11005 \emph on 
11006 not
11007 \begin_inset Marginal
11008 collapsed true
11009
11010 \layout Standard
11011
11012
11013 \series bold 
11014 \SpecialChar ~
11015 !
11016 \end_inset 
11017
11018
11019 \emph default 
11020  initialized
11021 \begin_inset LatexCommand \index{Variable initialization}
11022
11023 \end_inset 
11024
11025 .
11026 \layout Standard
11027
11028 In case of memory mapped I/O devices the keyword 
11029 \emph on 
11030 volatile
11031 \emph default 
11032  has to be used to tell the compiler that accesses might not be removed:
11033 \layout Verse
11034
11035
11036 \family typewriter 
11037 volatile
11038 \begin_inset LatexCommand \index{volatile}
11039
11040 \end_inset 
11041
11042  __xdata
11043 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11044
11045 \end_inset 
11046
11047  __at
11048 \begin_inset LatexCommand \index{at}
11049
11050 \end_inset 
11051
11052  (0x8000) unsigned char PORTA_8255;
11053 \layout Standard
11054
11055 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
11056 r) array
11057 \family typewriter 
11058 \size footnotesize 
11059
11060 \begin_inset LatexCommand \index{Aligned array}
11061
11062 \end_inset 
11063
11064
11065 \family default 
11066 \size default 
11067  starts at a block (256 byte) boundary
11068 \begin_inset LatexCommand \index{block boundary}
11069
11070 \end_inset 
11071
11072  (section 
11073 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
11074
11075 \end_inset 
11076
11077  has an example).
11078 \newline 
11079 Absolute addresses can be specified for variables in all storage classes,
11080  e.g.:
11081 \layout Verse
11082
11083
11084 \family typewriter 
11085 __bit
11086 \begin_inset LatexCommand \index{bit}
11087
11088 \end_inset 
11089
11090  __at
11091 \begin_inset LatexCommand \index{at}
11092
11093 \end_inset 
11094
11095  (0x02) bvar;
11096 \layout Standard
11097
11098 The above example will allocate the variable at offset 0x02 in the bit-addressab
11099 le space.
11100  There is no real advantage to assigning absolute addresses to variables
11101  in this manner, unless you want strict control over all the variables allocated.
11102  One possible use would be to write hardware portable code.
11103  For example, if you have a routine that uses one or more of the microcontroller
11104  I/O pins, and such pins are different for two different hardwares, you
11105  can declare the I/O pins in your routine using:
11106 \layout Verse
11107
11108
11109 \family typewriter 
11110 extern volatile
11111 \begin_inset LatexCommand \index{volatile}
11112
11113 \end_inset 
11114
11115  __bit MOSI;\SpecialChar ~
11116 \SpecialChar ~
11117 \SpecialChar ~
11118 \SpecialChar ~
11119 /* master out, slave in */
11120 \newline 
11121 extern volatile __bit MISO;\SpecialChar ~
11122 \SpecialChar ~
11123 \SpecialChar ~
11124 \SpecialChar ~
11125 /* master in, slave out */
11126 \newline 
11127 extern volatile __bit MCLK;\SpecialChar ~
11128 \SpecialChar ~
11129 \SpecialChar ~
11130 \SpecialChar ~
11131 /* master clock */
11132 \newline 
11133
11134 \newline 
11135 /* Input and Output of a byte on a 3-wire serial bus.
11136 \newline 
11137 \SpecialChar ~
11138 \SpecialChar ~
11139 \SpecialChar ~
11140 If needed adapt polarity of clock, polarity of data and bit order
11141 \newline 
11142 \SpecialChar ~
11143 */
11144 \newline 
11145 unsigned char spi_io(unsigned char out_byte) 
11146 \newline 
11147
11148 \newline 
11149 \SpecialChar ~
11150 \SpecialChar ~
11151 \SpecialChar ~
11152 \SpecialChar ~
11153 unsigned char i=8;
11154 \newline 
11155 \SpecialChar ~
11156 \SpecialChar ~
11157 \SpecialChar ~
11158 \SpecialChar ~
11159 do { 
11160 \newline 
11161 \SpecialChar ~
11162 \SpecialChar ~
11163 \SpecialChar ~
11164 \SpecialChar ~
11165 \SpecialChar ~
11166 \SpecialChar ~
11167 \SpecialChar ~
11168 \SpecialChar ~
11169 MOSI = out_byte & 0x80; 
11170 \newline 
11171 \SpecialChar ~
11172 \SpecialChar ~
11173 \SpecialChar ~
11174 \SpecialChar ~
11175 \SpecialChar ~
11176 \SpecialChar ~
11177 \SpecialChar ~
11178 \SpecialChar ~
11179 out_byte <<= 1;
11180 \newline 
11181 \SpecialChar ~
11182 \SpecialChar ~
11183 \SpecialChar ~
11184 \SpecialChar ~
11185 \SpecialChar ~
11186 \SpecialChar ~
11187 \SpecialChar ~
11188 \SpecialChar ~
11189 MCLK = 1; 
11190 \newline 
11191 \SpecialChar ~
11192 \SpecialChar ~
11193 \SpecialChar ~
11194 \SpecialChar ~
11195 \SpecialChar ~
11196 \SpecialChar ~
11197 \SpecialChar ~
11198 \SpecialChar ~
11199 /* _asm nop _endasm; */\SpecialChar ~
11200 \SpecialChar ~
11201 \SpecialChar ~
11202 \SpecialChar ~
11203 \SpecialChar ~
11204 \SpecialChar ~
11205 \SpecialChar ~
11206 \SpecialChar ~
11207 /* for slow peripherals */
11208 \newline 
11209 \SpecialChar ~
11210 \SpecialChar ~
11211 \SpecialChar ~
11212 \SpecialChar ~
11213 \SpecialChar ~
11214 \SpecialChar ~
11215 \SpecialChar ~
11216 \SpecialChar ~
11217 if(MISO) 
11218 \newline 
11219 \SpecialChar ~
11220 \SpecialChar ~
11221 \SpecialChar ~
11222 \SpecialChar ~
11223 \SpecialChar ~
11224 \SpecialChar ~
11225 \SpecialChar ~
11226 \SpecialChar ~
11227 \SpecialChar ~
11228 \SpecialChar ~
11229 \SpecialChar ~
11230 \SpecialChar ~
11231 out_byte += 1; 
11232 \newline 
11233 \SpecialChar ~
11234 \SpecialChar ~
11235 \SpecialChar ~
11236 \SpecialChar ~
11237 \SpecialChar ~
11238 \SpecialChar ~
11239 \SpecialChar ~
11240 \SpecialChar ~
11241 MCLK = 0; 
11242 \newline 
11243 \SpecialChar ~
11244 \SpecialChar ~
11245 \SpecialChar ~
11246 \SpecialChar ~
11247 } while(--i);
11248 \newline 
11249 \SpecialChar ~
11250 \SpecialChar ~
11251 \SpecialChar ~
11252 \SpecialChar ~
11253 return out_byte; 
11254 \newline 
11255 }
11256 \layout Standard
11257
11258 Then, someplace in the code for the first hardware you would use
11259 \layout Verse
11260
11261
11262 \family typewriter 
11263 __bit __at
11264 \begin_inset LatexCommand \index{at}
11265
11266 \end_inset 
11267
11268
11269 \begin_inset LatexCommand \index{\_\_at}
11270
11271 \end_inset 
11272
11273  (0x80) MOSI;\SpecialChar ~
11274 \SpecialChar ~
11275 \SpecialChar ~
11276 \SpecialChar ~
11277 /* I/O port 0, bit 0 */
11278 \newline 
11279 __bit __at (0x81) MISO;\SpecialChar ~
11280 \SpecialChar ~
11281 \SpecialChar ~
11282 \SpecialChar ~
11283 /* I/O port 0, bit 1 */
11284 \newline 
11285 __bit __at (0x82) MCLK;\SpecialChar ~
11286 \SpecialChar ~
11287 \SpecialChar ~
11288 \SpecialChar ~
11289 /* I/O port 0, bit 2 */
11290 \layout Standard
11291
11292 Similarly, for the second hardware you would use
11293 \layout Verse
11294
11295
11296 \family typewriter 
11297 __bit __at (0x83) MOSI;\SpecialChar ~
11298 \SpecialChar ~
11299 \SpecialChar ~
11300 \SpecialChar ~
11301 /* I/O port 0, bit 3 */
11302 \newline 
11303 __bit __at (0x91) MISO;\SpecialChar ~
11304 \SpecialChar ~
11305 \SpecialChar ~
11306 \SpecialChar ~
11307 /* I/O port 1, bit 1 */
11308 \newline 
11309 __bit
11310 \begin_inset LatexCommand \index{bit}
11311
11312 \end_inset 
11313
11314  __at (0x92) MCLK;\SpecialChar ~
11315 \SpecialChar ~
11316 \SpecialChar ~
11317 \SpecialChar ~
11318 /* I/O port 1, bit 2 */
11319 \layout Standard
11320 \added_space_bottom bigskip 
11321 and you can use the same hardware dependent routine without changes, as
11322  for example in a library.
11323  This is somehow similar to sbit, but only one absolute address has to be
11324  specified in the whole project.
11325 \layout Section
11326
11327 Parameters
11328 \begin_inset LatexCommand \index{Parameters}
11329
11330 \end_inset 
11331
11332
11333 \begin_inset LatexCommand \index{function parameter}
11334
11335 \end_inset 
11336
11337  & Local Variables
11338 \begin_inset LatexCommand \index{local variables}
11339
11340 \end_inset 
11341
11342
11343 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
11344
11345 \end_inset 
11346
11347
11348 \layout Standard
11349
11350 Automatic (local) variables and parameters to functions can either be placed
11351  on the stack or in data-space.
11352  The default action of the compiler is to place these variables in the internal
11353  RAM (for small model) or external RAM (for large model).
11354  This in fact makes them similar to 
11355 \emph on 
11356 static
11357 \begin_inset LatexCommand \index{static}
11358
11359 \end_inset 
11360
11361
11362 \emph default 
11363  so by default functions are non-reentrant
11364 \begin_inset LatexCommand \index{reentrant}
11365
11366 \end_inset 
11367
11368 .
11369  
11370 \newline 
11371
11372 \newline 
11373 They can be placed on the stack
11374 \begin_inset LatexCommand \index{stack}
11375
11376 \end_inset 
11377
11378  by using the
11379 \emph on 
11380  -
11381 \begin_inset ERT
11382 status Collapsed
11383
11384 \layout Standard
11385
11386 \backslash 
11387 /
11388 \end_inset 
11389
11390 -stack-auto
11391 \begin_inset LatexCommand \index{-\/-stack-auto}
11392
11393 \end_inset 
11394
11395
11396 \emph default 
11397  option, by using 
11398 \emph on 
11399 #pragma\SpecialChar ~
11400 stackauto
11401 \emph default 
11402
11403 \begin_inset LatexCommand \index{\#pragma stackauto}
11404
11405 \end_inset 
11406
11407  or by using the 
11408 \emph on 
11409 reentrant
11410 \begin_inset LatexCommand \index{reentrant}
11411
11412 \end_inset 
11413
11414
11415 \emph default 
11416  keyword in the function declaration, e.g.:
11417 \layout Verse
11418
11419
11420 \family typewriter 
11421 unsigned char foo(char i) __reentrant 
11422 \newline 
11423
11424 \newline 
11425 \SpecialChar ~
11426 \SpecialChar ~
11427 \SpecialChar ~
11428 \SpecialChar ~
11429 ...
11430  
11431 \newline 
11432 }
11433 \layout Standard
11434
11435 Since stack space on 8051 is limited, the 
11436 \emph on 
11437 reentrant 
11438 \emph default 
11439 keyword or the
11440 \emph on 
11441  -
11442 \begin_inset ERT
11443 status Collapsed
11444
11445 \layout Standard
11446
11447 \backslash 
11448 /
11449 \end_inset 
11450
11451 -stack-auto
11452 \emph default 
11453  option should be used sparingly.
11454  Note that the reentrant keyword just means that the parameters & local
11455  variables will be allocated to the stack, it 
11456 \emph on 
11457 does not
11458 \emph default 
11459  mean that the function is register bank
11460 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11461
11462 \end_inset 
11463
11464  independent.
11465 \newline 
11466
11467 \newline 
11468 Local variables
11469 \begin_inset LatexCommand \index{local variables}
11470
11471 \end_inset 
11472
11473  can be assigned storage classes and absolute
11474 \begin_inset LatexCommand \index{Absolute addressing}
11475
11476 \end_inset 
11477
11478  addresses, e.g.: 
11479 \layout Verse
11480
11481
11482 \family typewriter 
11483 unsigned char foo() 
11484 \newline 
11485 {
11486 \newline 
11487 \SpecialChar ~
11488 \SpecialChar ~
11489 \SpecialChar ~
11490 \SpecialChar ~
11491 __xdata unsigned char i;
11492 \newline 
11493 \SpecialChar ~
11494 \SpecialChar ~
11495 \SpecialChar ~
11496 \SpecialChar ~
11497 __bit bvar;
11498 \newline 
11499 \SpecialChar ~
11500 \SpecialChar ~
11501 \SpecialChar ~
11502 \SpecialChar ~
11503 __data __at
11504 \begin_inset LatexCommand \index{at}
11505
11506 \end_inset 
11507
11508  (0x31) unsigned char j;
11509 \newline 
11510 \SpecialChar ~
11511 \SpecialChar ~
11512 \SpecialChar ~
11513 \SpecialChar ~
11514 ...
11515  
11516 \newline 
11517 }
11518 \layout Standard
11519
11520 In the above example the variable 
11521 \emph on 
11522 i
11523 \emph default 
11524  will be allocated in the external ram, 
11525 \emph on 
11526 bvar
11527 \emph default 
11528  in bit addressable space and
11529 \emph on 
11530  j
11531 \emph default 
11532  in internal ram.
11533  When compiled with 
11534 \emph on 
11535 -
11536 \begin_inset ERT
11537 status Collapsed
11538
11539 \layout Standard
11540
11541 \backslash 
11542 /
11543 \end_inset 
11544
11545 -stack-auto
11546 \emph default 
11547  or when a function is declared as 
11548 \emph on 
11549 reentrant
11550 \emph default 
11551  this should only be done for static variables.
11552 \layout Standard
11553
11554 Parameters
11555 \begin_inset LatexCommand \index{function parameter}
11556
11557 \end_inset 
11558
11559  however are not allowed any storage class
11560 \begin_inset LatexCommand \index{Storage class}
11561
11562 \end_inset 
11563
11564 , (storage classes for parameters will be ignored), their allocation is
11565  governed by the memory model in use, and the reentrancy options.
11566 \layout Standard
11567
11568 It is however allowed to use bit parameters in reentrant functions and also
11569  non-static local bit variables are supported.
11570  Efficient use is limited to 8 semi-bitregisters in bit space.
11571  They are pushed and popped to stack
11572 \begin_inset LatexCommand \index{stack}
11573
11574 \end_inset 
11575
11576  as a single byte just like the normal registers.
11577 \layout Section
11578
11579 Overlaying
11580 \begin_inset LatexCommand \label{sub:Overlaying}
11581
11582 \end_inset 
11583
11584
11585 \begin_inset LatexCommand \index{Overlaying}
11586
11587 \end_inset 
11588
11589
11590 \layout Standard
11591
11592 For non-reentrant
11593 \begin_inset LatexCommand \index{reentrant}
11594
11595 \end_inset 
11596
11597  functions SDCC will try to reduce internal ram space usage by overlaying
11598  parameters and local variables of a function (if possible).
11599  Parameters and local variables
11600 \begin_inset LatexCommand \index{local variables}
11601
11602 \end_inset 
11603
11604  of a function will be allocated to an overlayable segment if the function
11605  has 
11606 \emph on 
11607 no other function calls and the function is non-reentrant and the memory
11608  model
11609 \begin_inset LatexCommand \index{Memory model}
11610
11611 \end_inset 
11612
11613  is small.
11614
11615 \emph default 
11616  If an explicit storage class
11617 \begin_inset LatexCommand \index{Storage class}
11618
11619 \end_inset 
11620
11621  is specified for a local variable, it will NOT be overlayed.
11622 \layout Standard
11623
11624 Note that the compiler (not the linkage editor) makes the decision for overlayin
11625 g the data items.
11626  Functions that are called from an interrupt service routine
11627 \begin_inset Marginal
11628 collapsed true
11629
11630 \layout Standard
11631
11632
11633 \series bold 
11634 !
11635 \end_inset 
11636
11637  should be preceded by a #pragma\SpecialChar ~
11638 nooverlay
11639 \begin_inset LatexCommand \index{\#pragma nooverlay}
11640
11641 \end_inset 
11642
11643  if they are not reentrant.
11644 \layout Standard
11645
11646 Also note that the compiler does not do any processing of inline assembler
11647  code, so the compiler might incorrectly assign local variables and parameters
11648  of a function into the overlay segment if the inline assembler code calls
11649  other c-functions that might use the overlay.
11650  In that case the #pragma\SpecialChar ~
11651 nooverlay should be used.
11652 \layout Standard
11653
11654 Parameters and local variables of functions that contain 16 or 32 bit multiplica
11655 tion
11656 \begin_inset LatexCommand \index{Multiplication}
11657
11658 \end_inset 
11659
11660  or division
11661 \begin_inset LatexCommand \index{Division}
11662
11663 \end_inset 
11664
11665  will NOT be overlayed since these are implemented using external functions,
11666  e.g.:
11667 \layout Verse
11668
11669
11670 \family typewriter 
11671 #pragma save 
11672 \newline 
11673 #pragma nooverlay
11674 \begin_inset LatexCommand \index{\#pragma nooverlay}
11675
11676 \end_inset 
11677
11678  
11679 \newline 
11680 void set_error(unsigned char errcd) 
11681 \newline 
11682 {
11683 \newline 
11684 \SpecialChar ~
11685 \SpecialChar ~
11686 \SpecialChar ~
11687 \SpecialChar ~
11688 P3 = errcd;
11689 \newline 
11690
11691 \newline 
11692 #pragma restore 
11693 \newline 
11694
11695 \newline 
11696 void some_isr () __interrupt
11697 \begin_inset LatexCommand \index{interrupt}
11698
11699 \end_inset 
11700
11701  (2)
11702 \newline 
11703 {
11704 \newline 
11705 \SpecialChar ~
11706 \SpecialChar ~
11707 \SpecialChar ~
11708 \SpecialChar ~
11709 ...
11710 \newline 
11711 \SpecialChar ~
11712 \SpecialChar ~
11713 \SpecialChar ~
11714 \SpecialChar ~
11715 set_error(10);
11716 \newline 
11717 \SpecialChar ~
11718 \SpecialChar ~
11719 \SpecialChar ~
11720 \SpecialChar ~
11721 ...
11722  
11723 \newline 
11724 }
11725 \layout Standard
11726 \added_space_bottom bigskip 
11727 In the above example the parameter 
11728 \emph on 
11729 errcd
11730 \emph default 
11731  for the function 
11732 \emph on 
11733 set_error
11734 \emph default 
11735  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
11736 nooverlay was
11737  not present, this could cause unpredictable runtime behavior when called
11738  from an interrupt service routine.
11739  The #pragma\SpecialChar ~
11740 nooverlay ensures that the parameters and local variables for
11741  the function are NOT overlayed.
11742 \layout Section
11743
11744 Interrupt Service Routines
11745 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
11746
11747 \end_inset 
11748
11749
11750 \layout Subsection
11751
11752 General Information
11753 \layout Standard
11754
11755 SDCC allows 
11756 \emph on 
11757 i
11758 \emph default 
11759 nterrupt 
11760 \emph on 
11761 s
11762 \emph default 
11763 ervice 
11764 \emph on 
11765 r
11766 \emph default 
11767 outines to be coded in C, with some extended keywords.
11768 \layout Verse
11769
11770
11771 \family typewriter 
11772 void timer_isr (void) __interrupt (1) __using (1) 
11773 \newline 
11774
11775 \newline 
11776 \SpecialChar ~
11777 \SpecialChar ~
11778 \SpecialChar ~
11779 \SpecialChar ~
11780 ...
11781  
11782 \newline 
11783 }
11784 \layout Standard
11785
11786 The optional number following the 
11787 \emph on 
11788 interrupt
11789 \begin_inset LatexCommand \index{interrupt}
11790
11791 \end_inset 
11792
11793
11794 \begin_inset LatexCommand \index{\_\_interrupt}
11795
11796 \end_inset 
11797
11798
11799 \emph default 
11800  keyword is the interrupt number this routine will service.
11801  When present, the compiler will insert a call to this routine in the interrupt
11802  vector table
11803 \begin_inset LatexCommand \index{interrupt vector table}
11804
11805 \end_inset 
11806
11807  for the interrupt number specified.
11808  If you have multiple source files in your project, interrupt service routines
11809  can be present in any of them, but a prototype of the isr MUST be present
11810  or included in the file that contains the function 
11811 \emph on 
11812 main
11813 \emph default 
11814 .
11815  The optional (8051 specific) keyword 
11816 \emph on 
11817 using
11818 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11819
11820 \end_inset 
11821
11822
11823 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11824
11825 \end_inset 
11826
11827
11828 \emph default 
11829  can be used to tell the compiler to use the specified register bank when
11830  generating code for this function.
11831  
11832 \newline 
11833 Interrupt service routines open the door for some very interesting bugs:
11834 \layout Subsubsection
11835
11836
11837 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
11838
11839 \end_inset 
11840
11841 Common interrupt pitfall: variable not declared 
11842 \emph on 
11843 volatile
11844 \layout Standard
11845
11846 If an interrupt service routine changes variables which are accessed by
11847  other functions these variables have to be declared 
11848 \emph on 
11849 volatile
11850 \emph default 
11851
11852 \begin_inset LatexCommand \index{volatile}
11853
11854 \end_inset 
11855
11856 .
11857  See 
11858 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
11859
11860 \end_inset 
11861
11862  .
11863 \layout Subsubsection
11864
11865
11866 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
11867
11868 \end_inset 
11869
11870 Common interrupt pitfall: 
11871 \emph on 
11872 non-atomic access
11873 \layout Standard
11874
11875 If the access to these variables is not 
11876 \emph on 
11877 atomic
11878 \begin_inset LatexCommand \index{atomic}
11879
11880 \end_inset 
11881
11882
11883 \emph default 
11884  (i.e.
11885  the processor needs more than one instruction for the access and could
11886  be interrupted while accessing the variable) the interrupt must be disabled
11887  during the access to avoid inconsistent data.
11888  
11889 \newline 
11890 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs and
11891  should be protected by disabling interrupts.
11892  You're not automatically on the safe side if you use 8 bit variables though.
11893  We need an example here: f.e.
11894  on the 8051 the harmless looking 
11895 \begin_inset Quotes srd
11896 \end_inset 
11897
11898
11899 \family typewriter 
11900 flags\SpecialChar ~
11901 |=\SpecialChar ~
11902 0x80;
11903 \family default 
11904
11905 \begin_inset Quotes sld
11906 \end_inset 
11907
11908  is not atomic if 
11909 \family typewriter 
11910 flags
11911 \family default 
11912  resides in xdata.
11913  Setting 
11914 \begin_inset Quotes srd
11915 \end_inset 
11916
11917
11918 \family typewriter 
11919 flags\SpecialChar ~
11920 |=\SpecialChar ~
11921 0x40;
11922 \family default 
11923
11924 \begin_inset Quotes sld
11925 \end_inset 
11926
11927  from within an interrupt routine might get lost if the interrupt occurs
11928  at the wrong time.
11929  
11930 \begin_inset Quotes sld
11931 \end_inset 
11932
11933
11934 \family typewriter 
11935 counter\SpecialChar ~
11936 +=\SpecialChar ~
11937 8;
11938 \family default 
11939
11940 \begin_inset Quotes srd
11941 \end_inset 
11942
11943  is not atomic on the 8051 even if 
11944 \family typewriter 
11945 counter
11946 \family default 
11947  is located in data memory.
11948 \newline 
11949 Bugs like these are hard to reproduce and can cause a lot of trouble.
11950  
11951 \layout Subsubsection
11952
11953
11954 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
11955
11956 \end_inset 
11957
11958 Common interrupt pitfall: 
11959 \emph on 
11960 stack overflow
11961 \layout Standard
11962
11963 The return address and the registers used in the interrupt service routine
11964  are saved on the stack
11965 \begin_inset LatexCommand \index{stack}
11966
11967 \end_inset 
11968
11969  so there must be sufficient stack space.
11970  If there isn't variables or registers (or even the return address itself)
11971  will be corrupted.
11972  This 
11973 \emph on 
11974 stack overflow
11975 \emph default 
11976
11977 \begin_inset LatexCommand \index{stack overflow}
11978
11979 \end_inset 
11980
11981  is most likely to happen if the interrupt occurs during the 
11982 \begin_inset Quotes sld
11983 \end_inset 
11984
11985 deepest
11986 \begin_inset Quotes srd
11987 \end_inset 
11988
11989  subroutine when the stack is already in use for f.e.
11990  many return addresses.
11991 \layout Subsubsection
11992
11993
11994 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
11995
11996 \end_inset 
11997
11998 Common interrupt pitfall: 
11999 \emph on 
12000 use of non-reentrant functions
12001 \layout Standard
12002
12003 A special note here, int (16 bit) and long (32 bit) integer division
12004 \begin_inset LatexCommand \index{Division}
12005
12006 \end_inset 
12007
12008 , multiplication
12009 \begin_inset LatexCommand \index{Multiplication}
12010
12011 \end_inset 
12012
12013  & modulus
12014 \begin_inset LatexCommand \index{Modulus}
12015
12016 \end_inset 
12017
12018  and floating-point
12019 \begin_inset LatexCommand \index{Floating point support}
12020
12021 \end_inset 
12022
12023  operations are implemented using external support routines.
12024  If an interrupt service routine needs to do any of these operations then
12025  the support routines (as mentioned in a following section) will have to
12026  be recompiled using the
12027 \emph on 
12028  -
12029 \begin_inset ERT
12030 status Collapsed
12031
12032 \layout Standard
12033
12034 \backslash 
12035 /
12036 \end_inset 
12037
12038 -stack-auto
12039 \begin_inset LatexCommand \index{-\/-stack-auto}
12040
12041 \end_inset 
12042
12043
12044 \emph default 
12045  option and the source file will need to be compiled using the 
12046 \emph on 
12047 -
12048 \begin_inset ERT
12049 status Collapsed
12050
12051 \layout Standard
12052
12053 \backslash 
12054 /
12055 \end_inset 
12056
12057 -int-long-reent
12058 \emph default 
12059
12060 \begin_inset LatexCommand \index{-\/-int-long-reent}
12061
12062 \end_inset 
12063
12064  compiler option.
12065  
12066 \newline 
12067 Note, the type promotion
12068 \begin_inset LatexCommand \index{type promotion}
12069
12070 \end_inset 
12071
12072  required by ANSI C can cause 16 bit routines to be used
12073 \begin_inset Marginal
12074 collapsed true
12075
12076 \layout Standard
12077
12078
12079 \series bold 
12080 \SpecialChar ~
12081 !
12082 \end_inset 
12083
12084  without the programmer being aware of it.
12085  See f.e.
12086  the cast 
12087 \family typewriter 
12088 (unsigned char)(tail-1)
12089 \family default 
12090  within the if clause in section 
12091 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12092
12093 \end_inset 
12094
12095 .
12096 \layout Standard
12097 \added_space_bottom bigskip 
12098 Calling other functions from an interrupt service routine is not recommended,
12099  avoid it if possible.
12100  Note that when some function is called from an interrupt service routine
12101  it should be preceded by a #pragma\SpecialChar ~
12102 nooverlay
12103 \begin_inset LatexCommand \index{\#pragma nooverlay}
12104
12105 \end_inset 
12106
12107  if it is not reentrant.
12108  Furthermore nonreentrant functions should not be called from the main program
12109  while the interrupt service routine might be active.
12110  They also must not be called from low priority interrupt service routines
12111  while a high priority interrupt service routine might be active.
12112  You could use semaphores or make the function
12113 \emph on 
12114  critical
12115 \emph default 
12116  if all parameters are passed in registers.
12117 \newline 
12118  Also see section 
12119 \begin_inset LatexCommand \ref{sub:Overlaying}
12120
12121 \end_inset 
12122
12123 \SpecialChar ~
12124 about Overlaying and section 
12125 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
12126
12127 \end_inset 
12128
12129 \SpecialChar ~
12130 about Functions using private register banks.
12131 \layout Subsection
12132
12133 MCS51/DS390 Interrupt Service Routines
12134 \layout Standard
12135
12136 Interrupt
12137 \begin_inset LatexCommand \index{interrupt}
12138
12139 \end_inset 
12140
12141  numbers and the corresponding address & descriptions for the Standard 8051/8052
12142  are listed below.
12143  SDCC will automatically adjust the 
12144 \begin_inset LatexCommand \index{interrupt vector table}
12145
12146 \end_inset 
12147
12148  to the maximum interrupt number specified.
12149 \newline 
12150
12151 \layout Standard
12152 \align center 
12153
12154 \begin_inset  Tabular
12155 <lyxtabular version="3" rows="9" columns="3">
12156 <features>
12157 <column alignment="center" valignment="top" leftline="true" width="0in">
12158 <column alignment="left" valignment="top" leftline="true" width="0in">
12159 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
12160 <row topline="true" bottomline="true">
12161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12162 \begin_inset Text
12163
12164 \layout Standard
12165
12166 Interrupt #
12167 \end_inset 
12168 </cell>
12169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12170 \begin_inset Text
12171
12172 \layout Standard
12173
12174 Description
12175 \end_inset 
12176 </cell>
12177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12178 \begin_inset Text
12179
12180 \layout Standard
12181
12182 Vector Address
12183 \end_inset 
12184 </cell>
12185 </row>
12186 <row topline="true">
12187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12188 \begin_inset Text
12189
12190 \layout Standard
12191
12192 0
12193 \end_inset 
12194 </cell>
12195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12196 \begin_inset Text
12197
12198 \layout Standard
12199
12200 External 0
12201 \end_inset 
12202 </cell>
12203 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12204 \begin_inset Text
12205
12206 \layout Standard
12207
12208 0x0003
12209 \end_inset 
12210 </cell>
12211 </row>
12212 <row topline="true">
12213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12214 \begin_inset Text
12215
12216 \layout Standard
12217
12218 1
12219 \end_inset 
12220 </cell>
12221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12222 \begin_inset Text
12223
12224 \layout Standard
12225
12226 Timer 0
12227 \end_inset 
12228 </cell>
12229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12230 \begin_inset Text
12231
12232 \layout Standard
12233
12234 0x000b
12235 \end_inset 
12236 </cell>
12237 </row>
12238 <row topline="true">
12239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12240 \begin_inset Text
12241
12242 \layout Standard
12243
12244 2
12245 \end_inset 
12246 </cell>
12247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12248 \begin_inset Text
12249
12250 \layout Standard
12251
12252 External 1
12253 \end_inset 
12254 </cell>
12255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12256 \begin_inset Text
12257
12258 \layout Standard
12259
12260 0x0013
12261 \end_inset 
12262 </cell>
12263 </row>
12264 <row topline="true">
12265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12266 \begin_inset Text
12267
12268 \layout Standard
12269
12270 3
12271 \end_inset 
12272 </cell>
12273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12274 \begin_inset Text
12275
12276 \layout Standard
12277
12278 Timer 1
12279 \end_inset 
12280 </cell>
12281 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12282 \begin_inset Text
12283
12284 \layout Standard
12285
12286 0x001b
12287 \end_inset 
12288 </cell>
12289 </row>
12290 <row topline="true">
12291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12292 \begin_inset Text
12293
12294 \layout Standard
12295
12296 4
12297 \end_inset 
12298 </cell>
12299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12300 \begin_inset Text
12301
12302 \layout Standard
12303
12304 Serial
12305 \end_inset 
12306 </cell>
12307 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12308 \begin_inset Text
12309
12310 \layout Standard
12311
12312 0x0023
12313 \end_inset 
12314 </cell>
12315 </row>
12316 <row topline="true">
12317 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12318 \begin_inset Text
12319
12320 \layout Standard
12321
12322 5
12323 \end_inset 
12324 </cell>
12325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12326 \begin_inset Text
12327
12328 \layout Standard
12329
12330 Timer 2 (8052)
12331 \end_inset 
12332 </cell>
12333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12334 \begin_inset Text
12335
12336 \layout Standard
12337
12338 0x002b
12339 \end_inset 
12340 </cell>
12341 </row>
12342 <row topline="true">
12343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12344 \begin_inset Text
12345
12346 \layout Standard
12347
12348 ...
12349 \end_inset 
12350 </cell>
12351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12352 \begin_inset Text
12353
12354 \layout Standard
12355
12356 \end_inset 
12357 </cell>
12358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12359 \begin_inset Text
12360
12361 \layout Standard
12362
12363 ...
12364 \end_inset 
12365 </cell>
12366 </row>
12367 <row topline="true" bottomline="true">
12368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12369 \begin_inset Text
12370
12371 \layout Standard
12372
12373 n
12374 \end_inset 
12375 </cell>
12376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12377 \begin_inset Text
12378
12379 \layout Standard
12380
12381 \end_inset 
12382 </cell>
12383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12384 \begin_inset Text
12385
12386 \layout Standard
12387
12388 0x0003 + 8*n
12389 \end_inset 
12390 </cell>
12391 </row>
12392 </lyxtabular>
12393
12394 \end_inset 
12395
12396
12397 \newline 
12398
12399 \layout Standard
12400
12401 If the interrupt service routine is defined without 
12402 \emph on 
12403 using
12404 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12405
12406 \end_inset 
12407
12408
12409 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12410
12411 \end_inset 
12412
12413
12414 \emph default 
12415  a register bank or with register bank 0 (
12416 \emph on 
12417 using
12418 \emph default 
12419  0), the compiler will save the registers used by itself on the stack upon
12420  entry and restore them at exit, however if such an interrupt service routine
12421  calls another function then the entire register bank will be saved on the
12422  stack.
12423  This scheme may be advantageous for small interrupt service routines which
12424  have low register usage.
12425 \layout Standard
12426 \added_space_bottom bigskip 
12427 If the interrupt service routine is defined to be using a specific register
12428  bank then only 
12429 \emph on 
12430 a, b, dptr
12431 \emph default 
12432  & psw are saved and restored, if such an interrupt service routine calls
12433  another function (using another register bank) then the entire register
12434  bank of the called function will be saved on the stack
12435 \begin_inset LatexCommand \index{stack}
12436
12437 \end_inset 
12438
12439 .
12440  This scheme is recommended for larger interrupt service routines.
12441 \layout Subsection
12442
12443 HC08
12444 \begin_inset LatexCommand \index{HC08}
12445
12446 \end_inset 
12447
12448  Interrupt Service Routines
12449 \layout Standard
12450 \added_space_bottom bigskip 
12451 Since the number of interrupts
12452 \begin_inset LatexCommand \index{HC08!interrupt}
12453
12454 \end_inset 
12455
12456  available is chip specific and the interrupt vector table always ends at
12457  the last byte of memory, the interrupt numbers corresponds to the interrupt
12458  vectors in reverse order of address.
12459  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
12460  2 will use the interrupt vector at 0xfffa, and so on.
12461  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
12462  this way; instead see section 
12463 \begin_inset LatexCommand \ref{sub:Startup-Code}
12464
12465 \end_inset 
12466
12467  for details on customizing startup.
12468 \layout Subsection
12469
12470 Z80 Interrupt Service Routines
12471 \layout Standard
12472
12473 The Z80
12474 \begin_inset LatexCommand \index{Z80}
12475
12476 \end_inset 
12477
12478  uses several different methods for determining the correct interrupt
12479 \begin_inset LatexCommand \index{Z80!interrupt}
12480
12481 \end_inset 
12482
12483  vector depending on the hardware implementation.
12484  Therefore, SDCC ignores the optional interrupt number and does not attempt
12485  to generate an interrupt vector table.
12486 \layout Standard
12487
12488 By default, SDCC generates code for a maskable interrupt, which uses a RETI
12489  instruction to return from the interrupt.
12490  To write an interrupt handler for the non-maskable interrupt, which needs
12491  a RETN instruction instead, add the 
12492 \emph on 
12493 critical
12494 \emph default 
12495  keyword:
12496 \layout Verse
12497
12498
12499 \family typewriter 
12500 void nmi_isr (void) critical interrupt
12501 \newline 
12502
12503 \newline 
12504 \SpecialChar ~
12505 \SpecialChar ~
12506 \SpecialChar ~
12507 \SpecialChar ~
12508 ...
12509  
12510 \newline 
12511 }
12512 \layout Standard
12513 \added_space_bottom bigskip 
12514 However if you need to create a non-interruptable interrupt service routine
12515  you would also require the 
12516 \emph on 
12517 critical
12518 \emph default 
12519  keyword.
12520  To distinguish between this and an nmi_isr you must provide an interrupt
12521  number.
12522 \layout Section
12523
12524 Enabling and Disabling Interrupts
12525 \layout Subsection
12526
12527 Critical Functions and Critical Statements
12528 \layout Standard
12529
12530 A special keyword may be associated with a block or a function declaring
12531  it as 
12532 \emph on 
12533 critical
12534 \emph default 
12535 .
12536  SDCC will generate code to disable all interrupts
12537 \begin_inset LatexCommand \index{interrupt}
12538
12539 \end_inset 
12540
12541  upon entry to a critical function and restore the interrupt enable to the
12542  previous state before returning.
12543  Nesting critical functions will need one additional byte on the stack
12544 \begin_inset LatexCommand \index{stack}
12545
12546 \end_inset 
12547
12548  for each call.
12549 \layout Verse
12550
12551
12552 \family typewriter 
12553 int foo () __critical
12554 \begin_inset LatexCommand \index{critical}
12555
12556 \end_inset 
12557
12558
12559 \begin_inset LatexCommand \index{\_\_critical}
12560
12561 \end_inset 
12562
12563  
12564 \newline 
12565
12566 \newline 
12567 \SpecialChar ~
12568 \SpecialChar ~
12569 \SpecialChar ~
12570 \SpecialChar ~
12571 ...
12572  
12573 \newline 
12574 \SpecialChar ~
12575 \SpecialChar ~
12576 \SpecialChar ~
12577 \SpecialChar ~
12578 ...
12579  
12580 \newline 
12581 }
12582 \layout Standard
12583
12584 The critical attribute maybe used with other attributes like 
12585 \emph on 
12586 reentrant.
12587 \emph default 
12588
12589 \newline 
12590 The keyword 
12591 \emph on 
12592 critical
12593 \emph default 
12594  may also be used to disable interrupts more locally:
12595 \layout Verse
12596
12597
12598 \family typewriter 
12599 __critical{ i++; }
12600 \layout Standard
12601
12602 More than one statement could have been included in the block.
12603 \layout Subsection
12604
12605 Enabling and Disabling Interrupts directly
12606 \layout Standard
12607
12608 Interrupts
12609 \begin_inset LatexCommand \index{interrupt}
12610
12611 \end_inset 
12612
12613  can also be disabled and enabled directly (8051):
12614 \layout Verse
12615
12616
12617 \family typewriter 
12618 EA = 0;\SpecialChar ~
12619 \SpecialChar ~
12620 \SpecialChar ~
12621 \SpecialChar ~
12622 \SpecialChar ~
12623 \SpecialChar ~
12624 \SpecialChar ~
12625 \SpecialChar ~
12626 \SpecialChar ~
12627 \SpecialChar ~
12628 \SpecialChar ~
12629 \SpecialChar ~
12630 or:\SpecialChar ~
12631 \SpecialChar ~
12632 \SpecialChar ~
12633 \SpecialChar ~
12634 \SpecialChar ~
12635 \SpecialChar ~
12636 \SpecialChar ~
12637 \SpecialChar ~
12638 \SpecialChar ~
12639 \SpecialChar ~
12640 \SpecialChar ~
12641 EA_SAVE = EA;
12642 \layout Verse
12643
12644
12645 \family typewriter 
12646 ...\SpecialChar ~
12647 \SpecialChar ~
12648 \SpecialChar ~
12649 \SpecialChar ~
12650 \SpecialChar ~
12651 \SpecialChar ~
12652 \SpecialChar ~
12653 \SpecialChar ~
12654 \SpecialChar ~
12655 \SpecialChar ~
12656 \SpecialChar ~
12657 \SpecialChar ~
12658 \SpecialChar ~
12659 \SpecialChar ~
12660 \SpecialChar ~
12661 \SpecialChar ~
12662 \SpecialChar ~
12663 \SpecialChar ~
12664 \SpecialChar ~
12665 \SpecialChar ~
12666 \SpecialChar ~
12667 \SpecialChar ~
12668 \SpecialChar ~
12669 \SpecialChar ~
12670 \SpecialChar ~
12671 \SpecialChar ~
12672 \SpecialChar ~
12673 \SpecialChar ~
12674 \SpecialChar ~
12675 \SpecialChar ~
12676 EA = 0;
12677 \layout Verse
12678
12679
12680 \family typewriter 
12681 EA = 1;\SpecialChar ~
12682 \SpecialChar ~
12683 \SpecialChar ~
12684 \SpecialChar ~
12685 \SpecialChar ~
12686 \SpecialChar ~
12687 \SpecialChar ~
12688 \SpecialChar ~
12689 \SpecialChar ~
12690 \SpecialChar ~
12691 \SpecialChar ~
12692 \SpecialChar ~
12693 \SpecialChar ~
12694 \SpecialChar ~
12695 \SpecialChar ~
12696 \SpecialChar ~
12697 \SpecialChar ~
12698 \SpecialChar ~
12699 \SpecialChar ~
12700 \SpecialChar ~
12701 \SpecialChar ~
12702 \SpecialChar ~
12703 \SpecialChar ~
12704 \SpecialChar ~
12705 \SpecialChar ~
12706 \SpecialChar ~
12707 ...
12708 \layout Verse
12709
12710
12711 \family typewriter 
12712 \SpecialChar ~
12713 \SpecialChar ~
12714 \SpecialChar ~
12715 \SpecialChar ~
12716 \SpecialChar ~
12717 \SpecialChar ~
12718 \SpecialChar ~
12719 \SpecialChar ~
12720 \SpecialChar ~
12721 \SpecialChar ~
12722 \SpecialChar ~
12723 \SpecialChar ~
12724 \SpecialChar ~
12725 \SpecialChar ~
12726 \SpecialChar ~
12727 \SpecialChar ~
12728 \SpecialChar ~
12729 \SpecialChar ~
12730 \SpecialChar ~
12731 \SpecialChar ~
12732 \SpecialChar ~
12733 \SpecialChar ~
12734 \SpecialChar ~
12735 \SpecialChar ~
12736 \SpecialChar ~
12737 \SpecialChar ~
12738 \SpecialChar ~
12739 \SpecialChar ~
12740 \SpecialChar ~
12741 \SpecialChar ~
12742 \SpecialChar ~
12743 \SpecialChar ~
12744 \SpecialChar ~
12745 EA = EA_SAVE;
12746 \layout Standard
12747
12748 On other architectures which have seperate opcodes for enabling and disabling
12749  interrupts you might want to make use of defines with inline assembly
12750 \begin_inset LatexCommand \index{Assembler routines}
12751
12752 \end_inset 
12753
12754  (HC08
12755 \begin_inset LatexCommand \index{HC08!interrupt}
12756
12757 \end_inset 
12758
12759 ):
12760 \layout Verse
12761
12762
12763 \family typewriter 
12764 #define CLI _asm
12765 \begin_inset LatexCommand \index{\_asm}
12766
12767 \end_inset 
12768
12769 \SpecialChar ~
12770 \SpecialChar ~
12771 cli\SpecialChar ~
12772 \SpecialChar ~
12773 _endasm
12774 \begin_inset LatexCommand \index{\_endasm}
12775
12776 \end_inset 
12777
12778
12779 \layout Verse
12780
12781
12782 \family typewriter 
12783 #define SEI _asm\SpecialChar ~
12784 \SpecialChar ~
12785 sei\SpecialChar ~
12786 \SpecialChar ~
12787 _endasm; 
12788 \layout Verse
12789
12790
12791 \family typewriter 
12792 ...
12793 \layout Standard
12794
12795 Note: it is sometimes sufficient to disable only a specific interrupt source
12796  like f.e.
12797  a timer or serial interrupt by manipulating an 
12798 \emph on 
12799 interrupt mask
12800 \begin_inset LatexCommand \index{interrupt mask}
12801
12802 \end_inset 
12803
12804
12805 \emph default 
12806  register.
12807  
12808 \layout Standard
12809
12810 Usually the time during which interrupts are disabled should be kept as
12811  short as possible.
12812  This minimizes both 
12813 \emph on 
12814 interrupt latency
12815 \emph default 
12816
12817 \begin_inset LatexCommand \index{interrupt latency}
12818
12819 \end_inset 
12820
12821  (the time between the occurrence of the interrupt and the execution of
12822  the first code in the interrupt routine) and 
12823 \emph on 
12824 interrupt jitter
12825 \emph default 
12826
12827 \begin_inset LatexCommand \index{interrupt jitter}
12828
12829 \end_inset 
12830
12831  (the difference between the shortest and the longest interrupt latency).
12832  These really are something different, f.e.
12833  a serial interrupt has to be served before its buffer overruns so it cares
12834  for the maximum interrupt latency, whereas it does not care about jitter.
12835  On a loudspeaker driven via a digital to analog converter which is fed
12836  by an interrupt a latency of a few milliseconds might be tolerable, whereas
12837  a much smaller jitter will be very audible.
12838 \layout Standard
12839
12840 You can reenable interrupts within an interrupt routine and on some architecture
12841 s you can make use of two (or more) levels of 
12842 \emph on 
12843 interrupt priorities
12844 \emph default 
12845
12846 \begin_inset LatexCommand \index{interrupt priority}
12847
12848 \end_inset 
12849
12850 .
12851  On some architectures which don't support interrupt priorities these can
12852  be implemented by manipulating the interrupt mask and reenabling interrupts
12853  within the interrupt routine.
12854  Check there is sufficient space on the stack
12855 \begin_inset LatexCommand \index{stack}
12856
12857 \end_inset 
12858
12859  and don't add complexity unless you have to.
12860  
12861 \layout Subsection
12862
12863 Semaphore
12864 \begin_inset LatexCommand \index{semaphore}
12865
12866 \end_inset 
12867
12868  locking (mcs51/ds390)
12869 \layout Standard
12870
12871 Some architectures (mcs51/ds390) have an atomic
12872 \begin_inset LatexCommand \index{atomic}
12873
12874 \end_inset 
12875
12876  bit test and
12877 \emph on 
12878  
12879 \emph default 
12880 clear
12881 \emph on 
12882  
12883 \emph default 
12884 instruction.
12885  These type of instructions are typically used in preemptive multitasking
12886  systems, where a routine f.e.
12887  claims the use of a data structure ('acquires a lock
12888 \begin_inset LatexCommand \index{lock}
12889
12890 \end_inset 
12891
12892  on it'), makes some modifications and then releases the lock when the data
12893  structure is consistent again.
12894  The instruction may also be used if interrupt and non-interrupt code have
12895  to compete for a resource.
12896  With the atomic bit test and clear instruction interrupts
12897 \begin_inset LatexCommand \index{interrupt}
12898
12899 \end_inset 
12900
12901  don't have to be disabled for the locking operation.
12902  
12903 \layout Standard
12904
12905 SDCC generates this instruction if the source follows this pattern:
12906 \layout Verse
12907
12908
12909 \family typewriter 
12910 volatile
12911 \begin_inset LatexCommand \index{volatile}
12912
12913 \end_inset 
12914
12915  bit resource_is_free; 
12916 \newline 
12917
12918 \newline 
12919 if (resource_is_free) 
12920 \newline 
12921 \SpecialChar ~
12922 \SpecialChar ~
12923
12924 \newline 
12925 \SpecialChar ~
12926 \SpecialChar ~
12927 \SpecialChar ~
12928 \SpecialChar ~
12929 resource_is_free=0; 
12930 \newline 
12931 \SpecialChar ~
12932 \SpecialChar ~
12933 \SpecialChar ~
12934 \SpecialChar ~
12935 ...
12936  
12937 \newline 
12938 \SpecialChar ~
12939 \SpecialChar ~
12940 \SpecialChar ~
12941 \SpecialChar ~
12942 resource_is_free=1;
12943 \newline 
12944 \SpecialChar ~
12945 \SpecialChar ~
12946
12947 \layout Standard
12948
12949 Note, mcs51 and ds390 support only an atomic
12950 \begin_inset LatexCommand \index{atomic}
12951
12952 \end_inset 
12953
12954  bit test and 
12955 \emph on 
12956 clear
12957 \emph default 
12958  instruction (as opposed to atomic bit test and 
12959 \emph on 
12960 set).
12961 \layout Section
12962
12963 Functions using private register banks
12964 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
12965
12966 \end_inset 
12967
12968  (mcs51/ds390)
12969 \layout Standard
12970
12971 Some architectures have support for quickly changing register sets.
12972  SDCC supports this feature with the 
12973 \emph on 
12974 using
12975 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12976
12977 \end_inset 
12978
12979
12980 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12981
12982 \end_inset 
12983
12984
12985 \emph default 
12986  attribute (which tells the compiler to use a register bank
12987 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12988
12989 \end_inset 
12990
12991  other than the default bank zero).
12992  It should only be applied to 
12993 \emph on 
12994 interrupt
12995 \begin_inset LatexCommand \index{interrupt}
12996
12997 \end_inset 
12998
12999
13000 \emph default 
13001  functions (see footnote below).
13002  This will in most circumstances make the generated ISR code more efficient
13003  since it will not have to save registers on the stack.
13004 \layout Standard
13005
13006 The 
13007 \emph on 
13008 using
13009 \emph default 
13010  attribute will have no effect on the generated code for a 
13011 \emph on 
13012 non-interrupt
13013 \emph default 
13014  function (but may occasionally be useful anyway
13015 \begin_inset Foot
13016 collapsed false
13017
13018 \layout Standard
13019
13020 possible exception: if a function is called ONLY from 'interrupt' functions
13021  using a particular bank, it can be declared with the same 'using' attribute
13022  as the calling 'interrupt' functions.
13023  For instance, if you have several ISRs using bank one, and all of them
13024  call memcpy(), it might make sense to create a specialized version of memcpy()
13025  'using 1', since this would prevent the ISR from having to save bank zero
13026  to the stack on entry and switch to bank zero before calling the function
13027 \end_inset 
13028
13029 ).
13030 \newline 
13031
13032 \emph on 
13033 (pending: Note, nowadays the 
13034 \emph default 
13035 using
13036 \emph on 
13037  attribute has an effect on
13038 \emph default 
13039  
13040 \emph on 
13041 the generated code for a 
13042 \emph default 
13043 non-interrupt
13044 \emph on 
13045  function
13046 \emph default 
13047 .
13048 \emph on 
13049 )
13050 \layout Standard
13051
13052 An 
13053 \emph on 
13054 interrupt
13055 \emph default 
13056  function using a non-zero bank will assume that it can trash that register
13057  bank, and will not save it.
13058  Since high-priority interrupts
13059 \begin_inset LatexCommand \index{interrupts}
13060
13061 \end_inset 
13062
13063
13064 \begin_inset LatexCommand \index{interrupt priority}
13065
13066 \end_inset 
13067
13068  can interrupt low-priority ones on the 8051 and friends, this means that
13069  if a high-priority ISR 
13070 \emph on 
13071 using
13072 \emph default 
13073  a particular bank occurs while processing a low-priority ISR 
13074 \emph on 
13075 using
13076 \emph default 
13077  the same bank, terrible and bad things can happen.
13078  To prevent this, no single register bank should be 
13079 \emph on 
13080 used
13081 \emph default 
13082  by both a high priority and a low priority ISR.
13083  This is probably most easily done by having all high priority ISRs use
13084  one bank and all low priority ISRs use another.
13085  If you have an ISR which can change priority at runtime, you're on your
13086  own: I suggest using the default bank zero and taking the small performance
13087  hit.
13088 \layout Standard
13089 \added_space_bottom bigskip 
13090 It is most efficient if your ISR calls no other functions.
13091  If your ISR must call other functions, it is most efficient if those functions
13092  use the same bank as the ISR (see note 1 below); the next best is if the
13093  called functions use bank zero.
13094  It is very inefficient to call a function using a different, non-zero bank
13095  from an ISR.
13096  
13097 \layout Section
13098
13099 Startup Code
13100 \begin_inset LatexCommand \label{sub:Startup-Code}
13101
13102 \end_inset 
13103
13104
13105 \begin_inset LatexCommand \index{Startup code}
13106
13107 \end_inset 
13108
13109
13110 \layout Subsection
13111
13112 MCS51/DS390 Startup Code
13113 \layout Standard
13114
13115 The compiler triggers the linker to link certain initialization modules
13116  from the runtime library
13117 \begin_inset LatexCommand \index{Runtime library}
13118
13119 \end_inset 
13120
13121  called crt<something>.
13122  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
13123  GSINIT5) is not linked unless the --xstack option is used.
13124  These modules are highly entangled by the use of special segments/areas,
13125  but a common layout is shown below:
13126 \layout Verse
13127
13128
13129 \family typewriter 
13130 \series bold 
13131 \size footnotesize 
13132 (main.asm)
13133 \layout Verse
13134
13135
13136 \family typewriter 
13137 \size footnotesize 
13138 \SpecialChar ~
13139 \SpecialChar ~
13140 \SpecialChar ~
13141 \SpecialChar ~
13142 \SpecialChar ~
13143 \SpecialChar ~
13144 \SpecialChar ~
13145 \SpecialChar ~
13146 .area HOME (CODE)
13147 \newline 
13148 __interrupt_vect:
13149 \newline 
13150 \SpecialChar ~
13151 \SpecialChar ~
13152 \SpecialChar ~
13153 \SpecialChar ~
13154 \SpecialChar ~
13155 \SpecialChar ~
13156 \SpecialChar ~
13157 \SpecialChar ~
13158 ljmp __sdcc_gsinit_startup
13159 \layout Verse
13160
13161
13162 \family typewriter 
13163 \series bold 
13164 \size footnotesize 
13165 (crtstart.asm)
13166 \layout Verse
13167
13168
13169 \family typewriter 
13170 \size footnotesize 
13171 \SpecialChar ~
13172 \SpecialChar ~
13173 \SpecialChar ~
13174 \SpecialChar ~
13175 \SpecialChar ~
13176 \SpecialChar ~
13177 \SpecialChar ~
13178 \SpecialChar ~
13179 .area GSINIT0 (CODE)
13180 \newline 
13181 __sdcc_gsinit_startup::
13182 \newline 
13183 \SpecialChar ~
13184 \SpecialChar ~
13185 \SpecialChar ~
13186 \SpecialChar ~
13187 \SpecialChar ~
13188 \SpecialChar ~
13189 \SpecialChar ~
13190 \SpecialChar ~
13191 mov sp,#__start__stack - 1
13192 \layout Verse
13193
13194
13195 \family typewriter 
13196 \series bold 
13197 \size footnotesize 
13198 (crtxstack.asm)
13199 \layout Verse
13200
13201
13202 \family typewriter 
13203 \size footnotesize 
13204 \SpecialChar ~
13205 \SpecialChar ~
13206 \SpecialChar ~
13207 \SpecialChar ~
13208 \SpecialChar ~
13209 \SpecialChar ~
13210 \SpecialChar ~
13211 \SpecialChar ~
13212 .area GSINIT1 (CODE)
13213 \newline 
13214 __sdcc_init_xstack::
13215 \newline 
13216 ; Need to initialize in GSINIT1 in case the user's __sdcc_external_startup
13217  uses the xstack.
13218 \newline 
13219 \SpecialChar ~
13220 \SpecialChar ~
13221 \SpecialChar ~
13222 \SpecialChar ~
13223 \SpecialChar ~
13224 \SpecialChar ~
13225 \SpecialChar ~
13226 \SpecialChar ~
13227 mov __XPAGE,#(__start__xstack >> 8)
13228 \newline 
13229 \SpecialChar ~
13230 \SpecialChar ~
13231 \SpecialChar ~
13232 \SpecialChar ~
13233 \SpecialChar ~
13234 \SpecialChar ~
13235 \SpecialChar ~
13236 \SpecialChar ~
13237 mov _spx,#__start__xstack
13238 \layout Verse
13239
13240
13241 \family typewriter 
13242 \series bold 
13243 \size footnotesize 
13244 (crtstart.asm)
13245 \layout Verse
13246
13247
13248 \family typewriter 
13249 \size footnotesize 
13250 \SpecialChar ~
13251 \SpecialChar ~
13252 \SpecialChar ~
13253 \SpecialChar ~
13254 \SpecialChar ~
13255 \SpecialChar ~
13256 \SpecialChar ~
13257 \SpecialChar ~
13258 .area GSINIT2 (CODE)
13259 \newline 
13260 \SpecialChar ~
13261 \SpecialChar ~
13262 \SpecialChar ~
13263 \SpecialChar ~
13264 \SpecialChar ~
13265 \SpecialChar ~
13266 \SpecialChar ~
13267 \SpecialChar ~
13268 lcall __sdcc_external_startup
13269 \newline 
13270 \SpecialChar ~
13271 \SpecialChar ~
13272 \SpecialChar ~
13273 \SpecialChar ~
13274 \SpecialChar ~
13275 \SpecialChar ~
13276 \SpecialChar ~
13277 \SpecialChar ~
13278 mov a,dpl
13279 \newline 
13280 \SpecialChar ~
13281 \SpecialChar ~
13282 \SpecialChar ~
13283 \SpecialChar ~
13284 \SpecialChar ~
13285 \SpecialChar ~
13286 \SpecialChar ~
13287 \SpecialChar ~
13288 jz __sdcc_init_data
13289 \newline 
13290 \SpecialChar ~
13291 \SpecialChar ~
13292 \SpecialChar ~
13293 \SpecialChar ~
13294 \SpecialChar ~
13295 \SpecialChar ~
13296 \SpecialChar ~
13297 \SpecialChar ~
13298 ljmp __sdcc_program_startup
13299 \newline 
13300 __sdcc_init_data:
13301 \layout Verse
13302
13303
13304 \family typewriter 
13305 \series bold 
13306 \size footnotesize 
13307 (crtxinit.asm)
13308 \layout Verse
13309
13310
13311 \family typewriter 
13312 \size footnotesize 
13313 \SpecialChar ~
13314 \SpecialChar ~
13315 \SpecialChar ~
13316 \SpecialChar ~
13317 \SpecialChar ~
13318 \SpecialChar ~
13319 \SpecialChar ~
13320 \SpecialChar ~
13321 .area GSINIT3 (CODE)
13322 \newline 
13323 __mcs51_genXINIT::
13324 \newline 
13325 \SpecialChar ~
13326 \SpecialChar ~
13327 \SpecialChar ~
13328 \SpecialChar ~
13329 \SpecialChar ~
13330 \SpecialChar ~
13331 \SpecialChar ~
13332 \SpecialChar ~
13333 mov r1,#l_XINIT
13334 \newline 
13335 \SpecialChar ~
13336 \SpecialChar ~
13337 \SpecialChar ~
13338 \SpecialChar ~
13339 \SpecialChar ~
13340 \SpecialChar ~
13341 \SpecialChar ~
13342 \SpecialChar ~
13343 mov a,r1
13344 \newline 
13345 \SpecialChar ~
13346 \SpecialChar ~
13347 \SpecialChar ~
13348 \SpecialChar ~
13349 \SpecialChar ~
13350 \SpecialChar ~
13351 \SpecialChar ~
13352 \SpecialChar ~
13353 orl a,#(l_XINIT >> 8)
13354 \newline 
13355 \SpecialChar ~
13356 \SpecialChar ~
13357 \SpecialChar ~
13358 \SpecialChar ~
13359 \SpecialChar ~
13360 \SpecialChar ~
13361 \SpecialChar ~
13362 \SpecialChar ~
13363 jz 00003$
13364 \newline 
13365 \SpecialChar ~
13366 \SpecialChar ~
13367 \SpecialChar ~
13368 \SpecialChar ~
13369 \SpecialChar ~
13370 \SpecialChar ~
13371 \SpecialChar ~
13372 \SpecialChar ~
13373 mov r2,#((l_XINIT+255) >> 8)
13374 \newline 
13375 \SpecialChar ~
13376 \SpecialChar ~
13377 \SpecialChar ~
13378 \SpecialChar ~
13379 \SpecialChar ~
13380 \SpecialChar ~
13381 \SpecialChar ~
13382 \SpecialChar ~
13383 mov dptr,#s_XINIT
13384 \newline 
13385 \SpecialChar ~
13386 \SpecialChar ~
13387 \SpecialChar ~
13388 \SpecialChar ~
13389 \SpecialChar ~
13390 \SpecialChar ~
13391 \SpecialChar ~
13392 \SpecialChar ~
13393 mov r0,#s_XISEG
13394 \newline 
13395 \SpecialChar ~
13396 \SpecialChar ~
13397 \SpecialChar ~
13398 \SpecialChar ~
13399 \SpecialChar ~
13400 \SpecialChar ~
13401 \SpecialChar ~
13402 \SpecialChar ~
13403 mov __XPAGE,#(s_XISEG >> 8)
13404 \newline 
13405 00001$:\SpecialChar ~
13406 clr a
13407 \newline 
13408 \SpecialChar ~
13409 \SpecialChar ~
13410 \SpecialChar ~
13411 \SpecialChar ~
13412 \SpecialChar ~
13413 \SpecialChar ~
13414 \SpecialChar ~
13415 \SpecialChar ~
13416 movc a,@a+dptr
13417 \newline 
13418 \SpecialChar ~
13419 \SpecialChar ~
13420 \SpecialChar ~
13421 \SpecialChar ~
13422 \SpecialChar ~
13423 \SpecialChar ~
13424 \SpecialChar ~
13425 \SpecialChar ~
13426 movx @r0,a
13427 \newline 
13428 \SpecialChar ~
13429 \SpecialChar ~
13430 \SpecialChar ~
13431 \SpecialChar ~
13432 \SpecialChar ~
13433 \SpecialChar ~
13434 \SpecialChar ~
13435 \SpecialChar ~
13436 inc dptr
13437 \newline 
13438 \SpecialChar ~
13439 \SpecialChar ~
13440 \SpecialChar ~
13441 \SpecialChar ~
13442 \SpecialChar ~
13443 \SpecialChar ~
13444 \SpecialChar ~
13445 \SpecialChar ~
13446 inc r0
13447 \newline 
13448 \SpecialChar ~
13449 \SpecialChar ~
13450 \SpecialChar ~
13451 \SpecialChar ~
13452 \SpecialChar ~
13453 \SpecialChar ~
13454 \SpecialChar ~
13455 \SpecialChar ~
13456 cjne r0,#0,00002$
13457 \newline 
13458 \SpecialChar ~
13459 \SpecialChar ~
13460 \SpecialChar ~
13461 \SpecialChar ~
13462 \SpecialChar ~
13463 \SpecialChar ~
13464 \SpecialChar ~
13465 \SpecialChar ~
13466 inc __XPAGE
13467 \newline 
13468 00002$:\SpecialChar ~
13469 djnz r1,00001$
13470 \newline 
13471 \SpecialChar ~
13472 \SpecialChar ~
13473 \SpecialChar ~
13474 \SpecialChar ~
13475 \SpecialChar ~
13476 \SpecialChar ~
13477 \SpecialChar ~
13478 \SpecialChar ~
13479 djnz r2,00001$
13480 \newline 
13481 \SpecialChar ~
13482 \SpecialChar ~
13483 \SpecialChar ~
13484 \SpecialChar ~
13485 \SpecialChar ~
13486 \SpecialChar ~
13487 \SpecialChar ~
13488 \SpecialChar ~
13489 mov __XPAGE,#0xFF
13490 \newline 
13491 00003$:
13492 \layout Verse
13493
13494
13495 \family typewriter 
13496 \series bold 
13497 \size footnotesize 
13498 (crtclear.asm)
13499 \layout Verse
13500
13501
13502 \family typewriter 
13503 \size footnotesize 
13504 \SpecialChar ~
13505 \SpecialChar ~
13506 \SpecialChar ~
13507 \SpecialChar ~
13508 \SpecialChar ~
13509 \SpecialChar ~
13510 \SpecialChar ~
13511 \SpecialChar ~
13512 .area GSINIT4 (CODE)
13513 \newline 
13514 __mcs51_genRAMCLEAR::
13515 \newline 
13516 \SpecialChar ~
13517 \SpecialChar ~
13518 \SpecialChar ~
13519 \SpecialChar ~
13520 \SpecialChar ~
13521 \SpecialChar ~
13522 \SpecialChar ~
13523 \SpecialChar ~
13524 clr a
13525 \newline 
13526 \SpecialChar ~
13527 \SpecialChar ~
13528 \SpecialChar ~
13529 \SpecialChar ~
13530 \SpecialChar ~
13531 \SpecialChar ~
13532 \SpecialChar ~
13533 \SpecialChar ~
13534 mov r0,#(l_IRAM-1)
13535 \newline 
13536 00004$:\SpecialChar ~
13537 mov @r0,a
13538 \newline 
13539 \SpecialChar ~
13540 \SpecialChar ~
13541 \SpecialChar ~
13542 \SpecialChar ~
13543 \SpecialChar ~
13544 \SpecialChar ~
13545 \SpecialChar ~
13546 \SpecialChar ~
13547 djnz r0,00004$
13548 \newline 
13549 ; _mcs51_genRAMCLEAR() end
13550 \layout Verse
13551
13552
13553 \family typewriter 
13554 \series bold 
13555 \size footnotesize 
13556 (crtxclear.asm)
13557 \layout Verse
13558
13559
13560 \family typewriter 
13561 \size footnotesize 
13562 \SpecialChar ~
13563 \SpecialChar ~
13564 \SpecialChar ~
13565 \SpecialChar ~
13566 \SpecialChar ~
13567 \SpecialChar ~
13568 \SpecialChar ~
13569 \SpecialChar ~
13570 .area GSINIT4 (CODE)
13571 \newline 
13572 __mcs51_genXRAMCLEAR::
13573 \newline 
13574 \SpecialChar ~
13575 \SpecialChar ~
13576 \SpecialChar ~
13577 \SpecialChar ~
13578 \SpecialChar ~
13579 \SpecialChar ~
13580 \SpecialChar ~
13581 \SpecialChar ~
13582 mov r0,#l_PSEG
13583 \newline 
13584 \SpecialChar ~
13585 \SpecialChar ~
13586 \SpecialChar ~
13587 \SpecialChar ~
13588 \SpecialChar ~
13589 \SpecialChar ~
13590 \SpecialChar ~
13591 \SpecialChar ~
13592 mov a,r0
13593 \newline 
13594 \SpecialChar ~
13595 \SpecialChar ~
13596 \SpecialChar ~
13597 \SpecialChar ~
13598 \SpecialChar ~
13599 \SpecialChar ~
13600 \SpecialChar ~
13601 \SpecialChar ~
13602 jz 00006$
13603 \newline 
13604 \SpecialChar ~
13605 \SpecialChar ~
13606 \SpecialChar ~
13607 \SpecialChar ~
13608 \SpecialChar ~
13609 \SpecialChar ~
13610 \SpecialChar ~
13611 \SpecialChar ~
13612 mov r1,#s_PSEG
13613 \newline 
13614 \SpecialChar ~
13615 \SpecialChar ~
13616 \SpecialChar ~
13617 \SpecialChar ~
13618 \SpecialChar ~
13619 \SpecialChar ~
13620 \SpecialChar ~
13621 \SpecialChar ~
13622 mov __XPAGE,#(s_PSEG >> 8)
13623 \newline 
13624 \SpecialChar ~
13625 \SpecialChar ~
13626 \SpecialChar ~
13627 \SpecialChar ~
13628 \SpecialChar ~
13629 \SpecialChar ~
13630 \SpecialChar ~
13631 \SpecialChar ~
13632 clr a
13633 \newline 
13634 00005$:\SpecialChar ~
13635 movx @r1,a
13636 \newline 
13637 \SpecialChar ~
13638 \SpecialChar ~
13639 \SpecialChar ~
13640 \SpecialChar ~
13641 \SpecialChar ~
13642 \SpecialChar ~
13643 \SpecialChar ~
13644 \SpecialChar ~
13645 inc r1
13646 \newline 
13647 \SpecialChar ~
13648 \SpecialChar ~
13649 \SpecialChar ~
13650 \SpecialChar ~
13651 \SpecialChar ~
13652 \SpecialChar ~
13653 \SpecialChar ~
13654 \SpecialChar ~
13655 djnz r0,00005$
13656 \newline 
13657 00006$:
13658 \newline 
13659 \SpecialChar ~
13660 \SpecialChar ~
13661 \SpecialChar ~
13662 \SpecialChar ~
13663 \SpecialChar ~
13664 \SpecialChar ~
13665 \SpecialChar ~
13666 \SpecialChar ~
13667 mov r0,#l_XSEG
13668 \newline 
13669 \SpecialChar ~
13670 \SpecialChar ~
13671 \SpecialChar ~
13672 \SpecialChar ~
13673 \SpecialChar ~
13674 \SpecialChar ~
13675 \SpecialChar ~
13676 \SpecialChar ~
13677 mov a,r0
13678 \newline 
13679 \SpecialChar ~
13680 \SpecialChar ~
13681 \SpecialChar ~
13682 \SpecialChar ~
13683 \SpecialChar ~
13684 \SpecialChar ~
13685 \SpecialChar ~
13686 \SpecialChar ~
13687 orl a,#(l_XSEG >> 8)
13688 \newline 
13689 \SpecialChar ~
13690 \SpecialChar ~
13691 \SpecialChar ~
13692 \SpecialChar ~
13693 \SpecialChar ~
13694 \SpecialChar ~
13695 \SpecialChar ~
13696 \SpecialChar ~
13697 jz 00008$
13698 \newline 
13699 \SpecialChar ~
13700 \SpecialChar ~
13701 \SpecialChar ~
13702 \SpecialChar ~
13703 \SpecialChar ~
13704 \SpecialChar ~
13705 \SpecialChar ~
13706 \SpecialChar ~
13707 mov r1,#((l_XSEG + 255) >> 8)
13708 \newline 
13709 \SpecialChar ~
13710 \SpecialChar ~
13711 \SpecialChar ~
13712 \SpecialChar ~
13713 \SpecialChar ~
13714 \SpecialChar ~
13715 \SpecialChar ~
13716 \SpecialChar ~
13717 mov dptr,#s_XSEG
13718 \newline 
13719 \SpecialChar ~
13720 \SpecialChar ~
13721 \SpecialChar ~
13722 \SpecialChar ~
13723 \SpecialChar ~
13724 \SpecialChar ~
13725 \SpecialChar ~
13726 \SpecialChar ~
13727 clr a
13728 \newline 
13729 00007$:\SpecialChar ~
13730 movx @dptr,a
13731 \newline 
13732 \SpecialChar ~
13733 \SpecialChar ~
13734 \SpecialChar ~
13735 \SpecialChar ~
13736 \SpecialChar ~
13737 \SpecialChar ~
13738 \SpecialChar ~
13739 \SpecialChar ~
13740 inc dptr
13741 \newline 
13742 \SpecialChar ~
13743 \SpecialChar ~
13744 \SpecialChar ~
13745 \SpecialChar ~
13746 \SpecialChar ~
13747 \SpecialChar ~
13748 \SpecialChar ~
13749 \SpecialChar ~
13750 djnz r0,00007$
13751 \newline 
13752 \SpecialChar ~
13753 \SpecialChar ~
13754 \SpecialChar ~
13755 \SpecialChar ~
13756 \SpecialChar ~
13757 \SpecialChar ~
13758 \SpecialChar ~
13759 \SpecialChar ~
13760 djnz r1,00007$
13761 \newline 
13762 00008$:
13763 \layout Verse
13764
13765
13766 \family typewriter 
13767 \series bold 
13768 \size footnotesize 
13769 (crtxstack.asm)
13770 \layout Verse
13771
13772
13773 \family typewriter 
13774 \size footnotesize 
13775 \SpecialChar ~
13776 \SpecialChar ~
13777 \SpecialChar ~
13778 \SpecialChar ~
13779 \SpecialChar ~
13780 \SpecialChar ~
13781 \SpecialChar ~
13782 \SpecialChar ~
13783 .area GSINIT5 (CODE)
13784 \newline 
13785 ; Need to initialize in GSINIT5 because __mcs51_genXINIT modifies __XPAGE
13786 \newline 
13787 ; and __mcs51_genRAMCLEAR modifies _spx.
13788 \newline 
13789 \SpecialChar ~
13790 \SpecialChar ~
13791 \SpecialChar ~
13792 \SpecialChar ~
13793 \SpecialChar ~
13794 \SpecialChar ~
13795 \SpecialChar ~
13796 \SpecialChar ~
13797 mov __XPAGE,#(__start__xstack >> 8)
13798 \newline 
13799 \SpecialChar ~
13800 \SpecialChar ~
13801 \SpecialChar ~
13802 \SpecialChar ~
13803 \SpecialChar ~
13804 \SpecialChar ~
13805 \SpecialChar ~
13806 \SpecialChar ~
13807 mov _spx,#__start__xstack
13808 \layout Verse
13809
13810
13811 \family typewriter 
13812 \series bold 
13813 \size footnotesize 
13814 (application modules)
13815 \layout Verse
13816
13817
13818 \family typewriter 
13819 \size footnotesize 
13820 \SpecialChar ~
13821 \SpecialChar ~
13822 \SpecialChar ~
13823 \SpecialChar ~
13824 \SpecialChar ~
13825 \SpecialChar ~
13826 \SpecialChar ~
13827 \SpecialChar ~
13828 .area GSINIT (CODE)
13829 \layout Verse
13830
13831
13832 \family typewriter 
13833 \series bold 
13834 \size footnotesize 
13835 (main.asm)
13836 \layout Verse
13837
13838
13839 \family typewriter 
13840 \size footnotesize 
13841 \SpecialChar ~
13842 \SpecialChar ~
13843 \SpecialChar ~
13844 \SpecialChar ~
13845 \SpecialChar ~
13846 \SpecialChar ~
13847 \SpecialChar ~
13848 \SpecialChar ~
13849 .area GSFINAL (CODE)
13850 \newline 
13851 \SpecialChar ~
13852 \SpecialChar ~
13853 \SpecialChar ~
13854 \SpecialChar ~
13855 \SpecialChar ~
13856 \SpecialChar ~
13857 \SpecialChar ~
13858 \SpecialChar ~
13859 ljmp __sdcc_program_startup
13860 \newline 
13861 ;--------------------------------------------------------
13862 \newline 
13863 ; Home
13864 \newline 
13865 ;--------------------------------------------------------
13866 \newline 
13867 \SpecialChar ~
13868 \SpecialChar ~
13869 \SpecialChar ~
13870 \SpecialChar ~
13871 \SpecialChar ~
13872 \SpecialChar ~
13873 \SpecialChar ~
13874 \SpecialChar ~
13875 .area HOME (CODE)
13876 \newline 
13877 \SpecialChar ~
13878 \SpecialChar ~
13879 \SpecialChar ~
13880 \SpecialChar ~
13881 \SpecialChar ~
13882 \SpecialChar ~
13883 \SpecialChar ~
13884 \SpecialChar ~
13885 .area CSEG (CODE)
13886 \newline 
13887 __sdcc_program_startup:
13888 \newline 
13889 \SpecialChar ~
13890 \SpecialChar ~
13891 \SpecialChar ~
13892 \SpecialChar ~
13893 \SpecialChar ~
13894 \SpecialChar ~
13895 \SpecialChar ~
13896 \SpecialChar ~
13897 lcall _main
13898 \newline 
13899 ; return from main will lock up
13900 \newline 
13901 \SpecialChar ~
13902 \SpecialChar ~
13903 \SpecialChar ~
13904 \SpecialChar ~
13905 \SpecialChar ~
13906 \SpecialChar ~
13907 \SpecialChar ~
13908 \SpecialChar ~
13909 sjmp .
13910 \layout Standard
13911
13912 One of these modules (crtstart.asm) contains a call to the C routine 
13913 \emph on 
13914 _sdcc_external_startup()
13915 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
13916
13917 \end_inset 
13918
13919
13920 \series bold 
13921 \emph default 
13922  
13923 \series default 
13924 at the start of the CODE area.
13925  This routine is also in the runtime library
13926 \begin_inset LatexCommand \index{Runtime library}
13927
13928 \end_inset 
13929
13930  and returns 0 by default.
13931  If this routine returns a non-zero value, the static & global variable
13932  initialization will be skipped and the function main will be invoked.
13933  Otherwise static & global variables will be initialized before the function
13934  main is invoked.
13935  You could add an 
13936 \emph on 
13937 _sdcc_external_startup()
13938 \emph default 
13939  routine to your program to override the default if you need to setup hardware
13940  or perform some other critical operation prior to static & global variable
13941  initialization
13942 \begin_inset LatexCommand \index{Variable initialization}
13943
13944 \end_inset 
13945
13946 .
13947  On some mcs51 variants xdata
13948 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
13949
13950 \end_inset 
13951
13952  memory has to be explicitly enabled before it can be accessed or if the
13953  watchdog
13954 \begin_inset LatexCommand \index{watchdog}
13955
13956 \end_inset 
13957
13958  needs to be disabled, this is the place to do it.
13959  The startup code clears all internal data memory, 256 bytes by default,
13960  but from 0 to n-1 if 
13961 \emph on 
13962 -
13963 \begin_inset ERT
13964 status Collapsed
13965
13966 \layout Standard
13967
13968 \backslash 
13969 /
13970 \end_inset 
13971
13972 -iram-size
13973 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
13974
13975 \end_inset 
13976
13977 n
13978 \emph default 
13979  is used.
13980  (recommended for Chipcon CC1010).
13981 \layout Standard
13982 \added_space_bottom bigskip 
13983 See also the compiler options 
13984 \emph on 
13985 -
13986 \begin_inset ERT
13987 status Collapsed
13988
13989 \layout Standard
13990
13991 \backslash 
13992 /
13993 \end_inset 
13994
13995 -no-xinit
13996 \emph default 
13997 -
13998 \emph on 
13999 opt
14000 \emph default 
14001
14002 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
14003
14004 \end_inset 
14005
14006
14007 \emph on 
14008 -
14009 \begin_inset ERT
14010 status Collapsed
14011
14012 \layout Standard
14013
14014 \backslash 
14015 /
14016 \end_inset 
14017
14018 -main-return
14019 \emph default 
14020
14021 \begin_inset LatexCommand \index{-\/-main-return}
14022
14023 \end_inset 
14024
14025  and section 
14026 \begin_inset LatexCommand \ref{sub:MCS51-variants}
14027
14028 \end_inset 
14029
14030  about MCS51-variants.
14031 \layout Subsection
14032
14033 HC08 Startup Code
14034 \layout Standard
14035 \added_space_bottom bigskip 
14036 The HC08
14037 \begin_inset LatexCommand \index{HC08}
14038
14039 \end_inset 
14040
14041  startup code follows the same scheme as the MCS51 startup code.
14042 \layout Subsection
14043
14044 Z80 Startup Code
14045 \layout Standard
14046 \added_space_bottom bigskip 
14047 On the Z80
14048 \begin_inset LatexCommand \index{Z80}
14049
14050 \end_inset 
14051
14052  the startup code is inserted by linking with crt0.o which is generated from
14053  sdcc/device/lib/z80/crt0.s.
14054  If you need a different startup code you can use the compiler option 
14055 \emph on 
14056 -
14057 \series bold 
14058 \emph default 
14059
14060 \begin_inset ERT
14061 status Collapsed
14062
14063 \layout Standard
14064
14065 \backslash 
14066 /
14067 \end_inset 
14068
14069
14070 \series default 
14071 \emph on 
14072 -no-std-crt0
14073 \emph default 
14074
14075 \begin_inset LatexCommand \index{-\/-no-std-crt0}
14076
14077 \end_inset 
14078
14079  and provide your own crt0.o.
14080  
14081 \layout Section
14082
14083 Inline Assembler Code
14084 \begin_inset LatexCommand \index{Assembler routines}
14085
14086 \end_inset 
14087
14088
14089 \layout Subsection
14090
14091 A Step by Step Introduction
14092 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
14093
14094 \end_inset 
14095
14096
14097 \layout Standard
14098
14099 Starting from a small snippet of c-code this example shows for the MCS51
14100  how to use inline assembly, access variables, a function parameter and
14101  an array in xdata memory.
14102  The example uses an MCS51 here but is easily adapted for other architectures.
14103  This is a buffer routine which should be optimized:
14104 \layout Verse
14105
14106
14107 \family typewriter 
14108 \size footnotesize 
14109 unsigned char __far
14110 \begin_inset LatexCommand \index{far (storage class)}
14111
14112 \end_inset 
14113
14114
14115 \begin_inset LatexCommand \index{\_\_far (storage class)}
14116
14117 \end_inset 
14118
14119  __at
14120 \begin_inset LatexCommand \index{at}
14121
14122 \end_inset 
14123
14124
14125 \begin_inset LatexCommand \index{\_\_at}
14126
14127 \end_inset 
14128
14129 (0x7f00) buf[0x100];
14130 \begin_inset LatexCommand \index{Aligned array}
14131
14132 \end_inset 
14133
14134
14135 \newline 
14136 unsigned char head, tail;\SpecialChar ~
14137 \SpecialChar ~
14138 \SpecialChar ~
14139 \SpecialChar ~
14140 \SpecialChar ~
14141 \SpecialChar ~
14142 \SpecialChar ~
14143 \SpecialChar ~
14144 \SpecialChar ~
14145 \SpecialChar ~
14146 \SpecialChar ~
14147 \SpecialChar ~
14148 \SpecialChar ~
14149 \SpecialChar ~
14150 \SpecialChar ~
14151 \SpecialChar ~
14152 \SpecialChar ~
14153 /* if interrupts
14154 \begin_inset LatexCommand \index{interrupt}
14155
14156 \end_inset 
14157
14158  are involved see
14159 \newline 
14160 \SpecialChar ~
14161 \SpecialChar ~
14162 \SpecialChar ~
14163 \SpecialChar ~
14164 \SpecialChar ~
14165 \SpecialChar ~
14166 \SpecialChar ~
14167 \SpecialChar ~
14168 \SpecialChar ~
14169 \SpecialChar ~
14170 \SpecialChar ~
14171 \SpecialChar ~
14172 \SpecialChar ~
14173 \SpecialChar ~
14174 \SpecialChar ~
14175 \SpecialChar ~
14176 \SpecialChar ~
14177 \SpecialChar ~
14178 \SpecialChar ~
14179 \SpecialChar ~
14180 \SpecialChar ~
14181 \SpecialChar ~
14182 \SpecialChar ~
14183 \SpecialChar ~
14184 \SpecialChar ~
14185 \SpecialChar ~
14186 \SpecialChar ~
14187 \SpecialChar ~
14188 \SpecialChar ~
14189 \SpecialChar ~
14190 \SpecialChar ~
14191 \SpecialChar ~
14192 \SpecialChar ~
14193 \SpecialChar ~
14194 \SpecialChar ~
14195 \SpecialChar ~
14196 \SpecialChar ~
14197 \SpecialChar ~
14198 \SpecialChar ~
14199 \SpecialChar ~
14200 \SpecialChar ~
14201 \SpecialChar ~
14202 \SpecialChar ~
14203 \SpecialChar ~
14204 \SpecialChar ~
14205 section 
14206 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
14207
14208 \end_inset 
14209
14210  about
14211 \series bold 
14212  volatile
14213 \series default 
14214  */
14215 \newline 
14216
14217 \newline 
14218 void to_buffer( unsigned char c ) 
14219 \newline 
14220 {
14221 \newline 
14222 \SpecialChar ~
14223 \SpecialChar ~
14224 \SpecialChar ~
14225 \SpecialChar ~
14226 if( head != (unsigned char)(tail-1) )\SpecialChar ~
14227 /* cast 
14228 \series bold 
14229 needed
14230 \series default 
14231  to avoid promotion
14232 \begin_inset LatexCommand \index{promotion to signed int}
14233
14234 \end_inset 
14235
14236
14237 \begin_inset LatexCommand \index{type promotion}
14238
14239 \end_inset 
14240
14241  to integer */
14242 \begin_inset Marginal
14243 collapsed true
14244
14245 \layout Standard
14246
14247
14248 \series bold 
14249 \SpecialChar ~
14250 !
14251 \end_inset 
14252
14253
14254 \newline 
14255 \SpecialChar ~
14256 \SpecialChar ~
14257 \SpecialChar ~
14258 \SpecialChar ~
14259 \SpecialChar ~
14260 \SpecialChar ~
14261 \SpecialChar ~
14262 \SpecialChar ~
14263 buf[ head++ ] = c;\SpecialChar ~
14264 \SpecialChar ~
14265 \SpecialChar ~
14266 \SpecialChar ~
14267 \SpecialChar ~
14268 \SpecialChar ~
14269 \SpecialChar ~
14270 \SpecialChar ~
14271 \SpecialChar ~
14272 \SpecialChar ~
14273 \SpecialChar ~
14274 \SpecialChar ~
14275 \SpecialChar ~
14276 \SpecialChar ~
14277 \SpecialChar ~
14278 \SpecialChar ~
14279 /* access to a 256 byte aligned array */
14280 \newline 
14281
14282 \layout Standard
14283
14284 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
14285  then a corresponding buffer.asm file is generated.
14286  We define a new function 
14287 \family typewriter 
14288 to_buffer_asm()
14289 \family default 
14290  in file buffer.c in which we cut and paste the generated code, removing
14291  unwanted comments and some ':'.
14292  Then add 
14293 \begin_inset Quotes sld
14294 \end_inset 
14295
14296 _asm
14297 \begin_inset Quotes srd
14298 \end_inset 
14299
14300  and 
14301 \begin_inset Quotes sld
14302 \end_inset 
14303
14304 _endasm;
14305 \begin_inset Quotes srd
14306 \end_inset 
14307
14308  to the beginning and the end of the function body:
14309 \layout Verse
14310
14311
14312 \family typewriter 
14313 \size footnotesize 
14314 /* With a cut and paste from the .asm file, we have something to start with.
14315 \newline 
14316 \SpecialChar ~
14317 \SpecialChar ~
14318 \SpecialChar ~
14319 The function is not yet OK! (registers aren't saved) */ 
14320 \newline 
14321 void to_buffer_asm( unsigned char c ) 
14322 \newline 
14323
14324 \newline 
14325 \SpecialChar ~
14326 \SpecialChar ~
14327 \SpecialChar ~
14328 \SpecialChar ~
14329 _asm
14330 \begin_inset LatexCommand \index{\_asm}
14331
14332 \end_inset 
14333
14334
14335 \begin_inset LatexCommand \index{\_\_asm}
14336
14337 \end_inset 
14338
14339
14340 \newline 
14341 \SpecialChar ~
14342 \SpecialChar ~
14343 \SpecialChar ~
14344 \SpecialChar ~
14345 mov\SpecialChar ~
14346 \SpecialChar ~
14347 r2,dpl 
14348 \newline 
14349 ;buffer.c if( head != (unsigned char)(tail-1) ) \SpecialChar ~
14350 /* cast 
14351 \series bold 
14352 needed
14353 \series default 
14354  to avoid promotion
14355 \begin_inset LatexCommand \index{promotion to signed int}
14356
14357 \end_inset 
14358
14359
14360 \begin_inset LatexCommand \index{type promotion}
14361
14362 \end_inset 
14363
14364  to integer */
14365 \newline 
14366 \SpecialChar ~
14367 \SpecialChar ~
14368 \SpecialChar ~
14369 \SpecialChar ~
14370 mov\SpecialChar ~
14371 \SpecialChar ~
14372 a,_tail 
14373 \newline 
14374 \SpecialChar ~
14375 \SpecialChar ~
14376 \SpecialChar ~
14377 \SpecialChar ~
14378 dec\SpecialChar ~
14379 \SpecialChar ~
14380
14381 \newline 
14382 \SpecialChar ~
14383 \SpecialChar ~
14384 \SpecialChar ~
14385 \SpecialChar ~
14386 mov\SpecialChar ~
14387 \SpecialChar ~
14388 r3,a 
14389 \newline 
14390 \SpecialChar ~
14391 \SpecialChar ~
14392 \SpecialChar ~
14393 \SpecialChar ~
14394 mov\SpecialChar ~
14395 \SpecialChar ~
14396 a,_head 
14397 \newline 
14398 \SpecialChar ~
14399 \SpecialChar ~
14400 \SpecialChar ~
14401 \SpecialChar ~
14402 cjne a,ar3,00106$ 
14403 \newline 
14404 \SpecialChar ~
14405 \SpecialChar ~
14406 \SpecialChar ~
14407 \SpecialChar ~
14408 ret
14409 \newline 
14410 00106$: 
14411 \newline 
14412 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
14413 \begin_inset LatexCommand \index{Aligned array}
14414
14415 \end_inset 
14416
14417
14418 \newline 
14419 \SpecialChar ~
14420 \SpecialChar ~
14421 \SpecialChar ~
14422 \SpecialChar ~
14423 mov\SpecialChar ~
14424 \SpecialChar ~
14425 r3,_head 
14426 \newline 
14427 \SpecialChar ~
14428 \SpecialChar ~
14429 \SpecialChar ~
14430 \SpecialChar ~
14431 inc\SpecialChar ~
14432 \SpecialChar ~
14433 _head 
14434 \newline 
14435 \SpecialChar ~
14436 \SpecialChar ~
14437 \SpecialChar ~
14438 \SpecialChar ~
14439 mov\SpecialChar ~
14440 \SpecialChar ~
14441 dpl,r3 
14442 \newline 
14443 \SpecialChar ~
14444 \SpecialChar ~
14445 \SpecialChar ~
14446 \SpecialChar ~
14447 mov\SpecialChar ~
14448 \SpecialChar ~
14449 dph,#(_buf >> 8) 
14450 \newline 
14451 \SpecialChar ~
14452 \SpecialChar ~
14453 \SpecialChar ~
14454 \SpecialChar ~
14455 mov\SpecialChar ~
14456 \SpecialChar ~
14457 a,r2 
14458 \newline 
14459 \SpecialChar ~
14460 \SpecialChar ~
14461 \SpecialChar ~
14462 \SpecialChar ~
14463 movx @dptr,a 
14464 \newline 
14465 00103$: 
14466 \newline 
14467 \SpecialChar ~
14468 \SpecialChar ~
14469 \SpecialChar ~
14470 \SpecialChar ~
14471 ret
14472 \newline 
14473 \SpecialChar ~
14474 \SpecialChar ~
14475 \SpecialChar ~
14476 \SpecialChar ~
14477 _endasm
14478 \begin_inset LatexCommand \index{\_endasm}
14479
14480 \end_inset 
14481
14482
14483 \begin_inset LatexCommand \index{\_\_endasm}
14484
14485 \end_inset 
14486
14487 ;
14488 \newline 
14489
14490 \layout Standard
14491
14492 The new file buffer.c should compile with only one warning about the unreferenced
14493  function argument 'c'.
14494  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
14495  (1) and finally have:
14496 \layout Verse
14497
14498
14499 \family typewriter 
14500 \size footnotesize 
14501 unsigned char __far __at(0x7f00) buf[0x100];
14502 \newline 
14503 unsigned char head, tail;
14504 \newline 
14505 #define USE_ASSEMBLY (1)
14506 \newline 
14507
14508 \newline 
14509 #if !USE_ASSEMBLY
14510 \newline 
14511
14512 \newline 
14513 void to_buffer( unsigned char c )
14514 \newline 
14515 {
14516 \newline 
14517 \SpecialChar ~
14518 \SpecialChar ~
14519 \SpecialChar ~
14520 \SpecialChar ~
14521 if( head != (unsigned char)(tail-1) )
14522 \newline 
14523 \SpecialChar ~
14524 \SpecialChar ~
14525 \SpecialChar ~
14526 \SpecialChar ~
14527 \SpecialChar ~
14528 \SpecialChar ~
14529 \SpecialChar ~
14530 \SpecialChar ~
14531 buf[ head++ ] = c;
14532 \newline 
14533 }
14534 \newline 
14535
14536 \newline 
14537 #else
14538 \newline 
14539
14540 \newline 
14541 void to_buffer( unsigned char c )
14542 \newline 
14543 {
14544 \newline 
14545 \SpecialChar ~
14546 \SpecialChar ~
14547 \SpecialChar ~
14548 \SpecialChar ~
14549 c; // to avoid warning: unreferenced function argument
14550 \newline 
14551 \SpecialChar ~
14552 \SpecialChar ~
14553 \SpecialChar ~
14554 \SpecialChar ~
14555 _asm
14556 \begin_inset LatexCommand \index{\_asm}
14557
14558 \end_inset 
14559
14560
14561 \begin_inset LatexCommand \index{\_\_asm}
14562
14563 \end_inset 
14564
14565
14566 \newline 
14567 \SpecialChar ~
14568 \SpecialChar ~
14569 \SpecialChar ~
14570 \SpecialChar ~
14571 \SpecialChar ~
14572 \SpecialChar ~
14573 \SpecialChar ~
14574 \SpecialChar ~
14575 ; save used registers here.
14576  
14577 \newline 
14578 \SpecialChar ~
14579 \SpecialChar ~
14580 \SpecialChar ~
14581 \SpecialChar ~
14582 \SpecialChar ~
14583 \SpecialChar ~
14584 \SpecialChar ~
14585 \SpecialChar ~
14586 ; If we were still using r2,r3 we would have to push them here.
14587  
14588 \newline 
14589 ; if( head != (unsigned char)(tail-1) )
14590 \newline 
14591 \SpecialChar ~
14592 \SpecialChar ~
14593 \SpecialChar ~
14594 \SpecialChar ~
14595 \SpecialChar ~
14596 \SpecialChar ~
14597 \SpecialChar ~
14598 \SpecialChar ~
14599 mov\SpecialChar ~
14600  a,_tail
14601 \newline 
14602 \SpecialChar ~
14603 \SpecialChar ~
14604 \SpecialChar ~
14605 \SpecialChar ~
14606 \SpecialChar ~
14607 \SpecialChar ~
14608 \SpecialChar ~
14609 \SpecialChar ~
14610 dec\SpecialChar ~
14611  a
14612 \newline 
14613 \SpecialChar ~
14614 \SpecialChar ~
14615 \SpecialChar ~
14616 \SpecialChar ~
14617 \SpecialChar ~
14618 \SpecialChar ~
14619 \SpecialChar ~
14620 \SpecialChar ~
14621 xrl\SpecialChar ~
14622  a,_head
14623 \newline 
14624 \SpecialChar ~
14625 \SpecialChar ~
14626 \SpecialChar ~
14627 \SpecialChar ~
14628 \SpecialChar ~
14629 \SpecialChar ~
14630 \SpecialChar ~
14631 \SpecialChar ~
14632 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
14633 \newline 
14634 \SpecialChar ~
14635 \SpecialChar ~
14636 \SpecialChar ~
14637 \SpecialChar ~
14638 \SpecialChar ~
14639 \SpecialChar ~
14640 \SpecialChar ~
14641 \SpecialChar ~
14642 jz\SpecialChar ~
14643 \SpecialChar ~
14644  t_b_end$
14645 \newline 
14646 \SpecialChar ~
14647 \SpecialChar ~
14648 \SpecialChar ~
14649 \SpecialChar ~
14650 \SpecialChar ~
14651 \SpecialChar ~
14652 \SpecialChar ~
14653 \SpecialChar ~
14654 ;
14655 \newline 
14656 ; buf[ head++ ] = c;
14657 \newline 
14658 \SpecialChar ~
14659 \SpecialChar ~
14660 \SpecialChar ~
14661 \SpecialChar ~
14662 \SpecialChar ~
14663 \SpecialChar ~
14664 \SpecialChar ~
14665 \SpecialChar ~
14666 mov\SpecialChar ~
14667  a,dpl \SpecialChar ~
14668 \SpecialChar ~
14669 \SpecialChar ~
14670 \SpecialChar ~
14671 \SpecialChar ~
14672 \SpecialChar ~
14673 \SpecialChar ~
14674 ; dpl holds lower byte of function argument
14675 \newline 
14676 \SpecialChar ~
14677 \SpecialChar ~
14678 \SpecialChar ~
14679 \SpecialChar ~
14680 \SpecialChar ~
14681 \SpecialChar ~
14682 \SpecialChar ~
14683 \SpecialChar ~
14684 mov\SpecialChar ~
14685  dpl,_head \SpecialChar ~
14686 \SpecialChar ~
14687 \SpecialChar ~
14688 ; buf is 0x100 byte aligned so head can be used directly
14689 \newline 
14690 \SpecialChar ~
14691 \SpecialChar ~
14692 \SpecialChar ~
14693 \SpecialChar ~
14694 \SpecialChar ~
14695 \SpecialChar ~
14696 \SpecialChar ~
14697 \SpecialChar ~
14698 mov\SpecialChar ~
14699  dph,#(_buf>>8)
14700 \newline 
14701 \SpecialChar ~
14702 \SpecialChar ~
14703 \SpecialChar ~
14704 \SpecialChar ~
14705 \SpecialChar ~
14706 \SpecialChar ~
14707 \SpecialChar ~
14708 \SpecialChar ~
14709 movx @dptr,a
14710 \newline 
14711 \SpecialChar ~
14712 \SpecialChar ~
14713 \SpecialChar ~
14714 \SpecialChar ~
14715 \SpecialChar ~
14716 \SpecialChar ~
14717 \SpecialChar ~
14718 \SpecialChar ~
14719 inc \SpecialChar ~
14720 _head
14721 \newline 
14722 \SpecialChar ~
14723 \SpecialChar ~
14724 \SpecialChar ~
14725 \SpecialChar ~
14726 \SpecialChar ~
14727 \SpecialChar ~
14728 \SpecialChar ~
14729 \SpecialChar ~
14730 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
14731 \newline 
14732 t_b_end$:
14733 \newline 
14734 \SpecialChar ~
14735 \SpecialChar ~
14736 \SpecialChar ~
14737 \SpecialChar ~
14738 \SpecialChar ~
14739 \SpecialChar ~
14740 \SpecialChar ~
14741 \SpecialChar ~
14742 ; restore used registers here 
14743 \newline 
14744 \SpecialChar ~
14745 \SpecialChar ~
14746 \SpecialChar ~
14747 \SpecialChar ~
14748 _endasm
14749 \begin_inset LatexCommand \index{\_endasm}
14750
14751 \end_inset 
14752
14753
14754 \begin_inset LatexCommand \index{\_\_endasm}
14755
14756 \end_inset 
14757
14758 ;
14759 \newline 
14760 }
14761 \newline 
14762 #endif
14763 \layout Standard
14764
14765 The inline assembler code can contain any valid code understood by the assembler
14766 , this includes any assembler directives and comment lines.
14767  The assembler does not like some characters like ':' or ''' in comments.
14768  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
14769 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
14770
14771 \end_inset 
14772
14773
14774 \begin_inset LatexCommand \index{Assembler documentation}
14775
14776 \end_inset 
14777
14778  or online at 
14779 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
14780
14781 \end_inset 
14782
14783 \SpecialChar ~
14784 .
14785 \layout Standard
14786
14787 The compiler does not do any validation of the code within the 
14788 \family typewriter 
14789 _asm
14790 \begin_inset LatexCommand \index{\_asm}
14791
14792 \end_inset 
14793
14794
14795 \begin_inset LatexCommand \index{\_\_asm}
14796
14797 \end_inset 
14798
14799  ...
14800  _endasm
14801 \size footnotesize 
14802
14803 \begin_inset LatexCommand \index{\_endasm}
14804
14805 \end_inset 
14806
14807
14808 \begin_inset LatexCommand \index{\_\_endasm}
14809
14810 \end_inset 
14811
14812
14813 \size default 
14814 ;
14815 \family default 
14816  keyword pair.
14817  Specifically it will not know which registers are used and thus register
14818  pushing/popping
14819 \begin_inset LatexCommand \index{push/pop}
14820
14821 \end_inset 
14822
14823  has to be done manually.
14824  
14825 \layout Standard
14826
14827 It is recommended that each assembly instruction (including labels) be placed
14828  in a separate line (as the example shows).
14829  When the -
14830 \begin_inset ERT
14831 status Collapsed
14832
14833 \layout Standard
14834
14835 \backslash 
14836 /
14837 \end_inset 
14838
14839 -
14840 \emph on 
14841 peep-asm
14842 \begin_inset LatexCommand \index{-\/-peep-asm}
14843
14844 \end_inset 
14845
14846
14847 \emph default 
14848  command line option is used, the inline assembler code will be passed through
14849  the peephole optimizer
14850 \begin_inset LatexCommand \index{Peephole optimizer}
14851
14852 \end_inset 
14853
14854 .
14855  There are only a few (if any) cases where this option makes sense, it might
14856  cause some unexpected changes in the inline assembler code.
14857  Please go through the peephole optimizer rules defined in file 
14858 \emph on 
14859 SDCCpeeph.def
14860 \emph default 
14861  before using this option.
14862 \layout Subsection
14863
14864 Naked Functions
14865 \begin_inset LatexCommand \label{sub:Naked-Functions}
14866
14867 \end_inset 
14868
14869
14870 \begin_inset LatexCommand \index{Naked functions}
14871
14872 \end_inset 
14873
14874
14875 \layout Standard
14876
14877 A special keyword may be associated with a function declaring it as 
14878 \emph on 
14879 _naked
14880 \begin_inset LatexCommand \index{\_naked}
14881
14882 \end_inset 
14883
14884
14885 \begin_inset LatexCommand \index{\_\_naked}
14886
14887 \end_inset 
14888
14889 .
14890  
14891 \emph default 
14892 The 
14893 \emph on 
14894 _naked
14895 \emph default 
14896  function modifier attribute prevents the compiler from generating prologue
14897 \begin_inset LatexCommand \index{function prologue}
14898
14899 \end_inset 
14900
14901  and epilogue
14902 \begin_inset LatexCommand \index{function epilogue}
14903
14904 \end_inset 
14905
14906  code for that function.
14907  This means that the user is entirely responsible for such things as saving
14908  any registers that may need to be preserved, selecting the proper register
14909  bank, generating the 
14910 \emph on 
14911 return
14912 \emph default 
14913  instruction at the end, etc.
14914  Practically, this means that the contents of the function must be written
14915  in inline assembler.
14916  This is particularly useful for interrupt functions, which can have a large
14917  (and often unnecessary) prologue/epilogue.
14918  For example, compare the code generated by these two functions:
14919 \layout Verse
14920
14921
14922 \family typewriter 
14923 volatile
14924 \begin_inset LatexCommand \index{volatile}
14925
14926 \end_inset 
14927
14928  data unsigned char counter;
14929 \newline 
14930
14931 \newline 
14932 void simpleInterrupt(void) __interrupt
14933 \begin_inset LatexCommand \index{interrupt}
14934
14935 \end_inset 
14936
14937
14938 \begin_inset LatexCommand \index{\_\_interrupt}
14939
14940 \end_inset 
14941
14942  (1)
14943 \newline 
14944 {
14945 \newline 
14946 \SpecialChar ~
14947 \SpecialChar ~
14948 \SpecialChar ~
14949 \SpecialChar ~
14950 counter++;
14951 \newline 
14952 }
14953 \newline 
14954
14955 \newline 
14956 void nakedInterrupt(void) __interrupt (2) __naked
14957 \newline 
14958 {
14959 \newline 
14960 \SpecialChar ~
14961 \SpecialChar ~
14962 \SpecialChar ~
14963 \SpecialChar ~
14964 _asm
14965 \begin_inset LatexCommand \index{\_asm}
14966
14967 \end_inset 
14968
14969
14970 \begin_inset LatexCommand \index{\_\_asm}
14971
14972 \end_inset 
14973
14974
14975 \newline 
14976 \SpecialChar ~
14977 \SpecialChar ~
14978 \SpecialChar ~
14979 \SpecialChar ~
14980 \SpecialChar ~
14981 \SpecialChar ~
14982 inc\SpecialChar ~
14983 \SpecialChar ~
14984 \SpecialChar ~
14985 \SpecialChar ~
14986 \SpecialChar ~
14987 _counter ; does not change flags, no need to save psw
14988 \newline 
14989 \SpecialChar ~
14990 \SpecialChar ~
14991 \SpecialChar ~
14992 \SpecialChar ~
14993 \SpecialChar ~
14994 \SpecialChar ~
14995 reti\SpecialChar ~
14996 \SpecialChar ~
14997 \SpecialChar ~
14998 \SpecialChar ~
14999 ; MUST explicitly include ret or reti in _naked function.
15000 \newline 
15001 \SpecialChar ~
15002 \SpecialChar ~
15003 \SpecialChar ~
15004 \SpecialChar ~
15005 _endasm
15006 \begin_inset LatexCommand \index{\_endasm}
15007
15008 \end_inset 
15009
15010
15011 \begin_inset LatexCommand \index{\_\_endasm}
15012
15013 \end_inset 
15014
15015 ;
15016 \newline 
15017 }
15018 \layout Standard
15019
15020 For an 8051 target, the generated simpleInterrupt looks like:
15021 \layout Verse
15022
15023
15024 \family typewriter 
15025 Note, this is an 
15026 \emph on 
15027 outdated
15028 \emph default 
15029  example, recent versions of SDCC generate
15030 \newline 
15031 the 
15032 \emph on 
15033 same
15034 \emph default 
15035  code for simpleInterrupt() and nakedInterrupt()!
15036 \newline 
15037
15038 \newline 
15039 _simpleInterrupt:
15040 \newline 
15041 \SpecialChar ~
15042 \SpecialChar ~
15043 \SpecialChar ~
15044 \SpecialChar ~
15045 push\SpecialChar ~
15046 \SpecialChar ~
15047 \SpecialChar ~
15048 \SpecialChar ~
15049 acc
15050 \newline 
15051 \SpecialChar ~
15052 \SpecialChar ~
15053 \SpecialChar ~
15054 \SpecialChar ~
15055 push\SpecialChar ~
15056 \SpecialChar ~
15057 \SpecialChar ~
15058 \SpecialChar ~
15059 b
15060 \newline 
15061 \SpecialChar ~
15062 \SpecialChar ~
15063 \SpecialChar ~
15064 \SpecialChar ~
15065 push\SpecialChar ~
15066 \SpecialChar ~
15067 \SpecialChar ~
15068 \SpecialChar ~
15069 dpl
15070 \newline 
15071 \SpecialChar ~
15072 \SpecialChar ~
15073 \SpecialChar ~
15074 \SpecialChar ~
15075 push\SpecialChar ~
15076 \SpecialChar ~
15077 \SpecialChar ~
15078 \SpecialChar ~
15079 dph
15080 \newline 
15081 \SpecialChar ~
15082 \SpecialChar ~
15083 \SpecialChar ~
15084 \SpecialChar ~
15085 push\SpecialChar ~
15086 \SpecialChar ~
15087 \SpecialChar ~
15088 \SpecialChar ~
15089 psw
15090 \newline 
15091 \SpecialChar ~
15092 \SpecialChar ~
15093 \SpecialChar ~
15094 \SpecialChar ~
15095 mov\SpecialChar ~
15096 \SpecialChar ~
15097 \SpecialChar ~
15098 \SpecialChar ~
15099 \SpecialChar ~
15100 psw,#0x00
15101 \newline 
15102 \SpecialChar ~
15103 \SpecialChar ~
15104 \SpecialChar ~
15105 \SpecialChar ~
15106 inc\SpecialChar ~
15107 \SpecialChar ~
15108 \SpecialChar ~
15109 \SpecialChar ~
15110 \SpecialChar ~
15111 _counter
15112 \newline 
15113 \SpecialChar ~
15114 \SpecialChar ~
15115 \SpecialChar ~
15116 \SpecialChar ~
15117 pop\SpecialChar ~
15118 \SpecialChar ~
15119 \SpecialChar ~
15120 \SpecialChar ~
15121 \SpecialChar ~
15122 psw
15123 \newline 
15124 \SpecialChar ~
15125 \SpecialChar ~
15126 \SpecialChar ~
15127 \SpecialChar ~
15128 pop\SpecialChar ~
15129 \SpecialChar ~
15130 \SpecialChar ~
15131 \SpecialChar ~
15132 \SpecialChar ~
15133 dph
15134 \newline 
15135 \SpecialChar ~
15136 \SpecialChar ~
15137 \SpecialChar ~
15138 \SpecialChar ~
15139 pop\SpecialChar ~
15140 \SpecialChar ~
15141 \SpecialChar ~
15142 \SpecialChar ~
15143 \SpecialChar ~
15144 dpl
15145 \newline 
15146 \SpecialChar ~
15147 \SpecialChar ~
15148 \SpecialChar ~
15149 \SpecialChar ~
15150 pop\SpecialChar ~
15151 \SpecialChar ~
15152 \SpecialChar ~
15153 \SpecialChar ~
15154 \SpecialChar ~
15155 b
15156 \newline 
15157 \SpecialChar ~
15158 \SpecialChar ~
15159 \SpecialChar ~
15160 \SpecialChar ~
15161 pop\SpecialChar ~
15162 \SpecialChar ~
15163 \SpecialChar ~
15164 \SpecialChar ~
15165 \SpecialChar ~
15166 acc
15167 \newline 
15168 \SpecialChar ~
15169 \SpecialChar ~
15170 \SpecialChar ~
15171 \SpecialChar ~
15172 reti
15173 \layout Standard
15174
15175 whereas nakedInterrupt looks like:
15176 \layout Verse
15177
15178
15179 \family typewriter 
15180 _nakedInterrupt:
15181 \newline 
15182 \SpecialChar ~
15183 \SpecialChar ~
15184 \SpecialChar ~
15185 \SpecialChar ~
15186 inc\SpecialChar ~
15187 \SpecialChar ~
15188 \SpecialChar ~
15189 \SpecialChar ~
15190 _counter ; does not change flags, no need to save psw
15191 \newline 
15192 \SpecialChar ~
15193 \SpecialChar ~
15194 \SpecialChar ~
15195 \SpecialChar ~
15196 reti\SpecialChar ~
15197 \SpecialChar ~
15198 \SpecialChar ~
15199 \SpecialChar ~
15200 \SpecialChar ~
15201 \SpecialChar ~
15202 \SpecialChar ~
15203 \SpecialChar ~
15204 \SpecialChar ~
15205 \SpecialChar ~
15206 \SpecialChar ~
15207 \SpecialChar ~
15208 ; MUST explicitly include ret or reti in _naked function
15209 \layout Standard
15210
15211 The related directive #pragma exclude
15212 \begin_inset LatexCommand \index{\#pragma exclude}
15213
15214 \end_inset 
15215
15216  allows a more fine grained control over pushing & popping
15217 \begin_inset LatexCommand \index{push/pop}
15218
15219 \end_inset 
15220
15221  the registers.
15222 \layout Standard
15223
15224 While there is nothing preventing you from writing C code inside a 
15225 \family typewriter 
15226 _naked
15227 \family default 
15228  function, there are many ways to shoot yourself in the foot doing this,
15229  and it is recommended that you stick to inline assembler.
15230 \layout Subsection
15231
15232 Use of Labels within Inline Assembler
15233 \layout Standard
15234
15235 SDCC allows the use of in-line assembler with a few restrictions regarding
15236  labels.
15237  In older versions of the compiler all labels defined within inline assembler
15238  code 
15239 \emph on 
15240 had to be
15241 \emph default 
15242  of the form 
15243 \emph on 
15244 nnnnn$
15245 \emph default 
15246  where nnnn is a number less than 100 (which implies a limit of utmost 100
15247  inline assembler labels 
15248 \emph on 
15249 per function
15250 \emph default 
15251 \noun on 
15252 )
15253 \noun default 
15254 .
15255  
15256 \layout Verse
15257
15258
15259 \family typewriter 
15260 _asm
15261 \begin_inset LatexCommand \index{\_asm}
15262
15263 \end_inset 
15264
15265
15266 \begin_inset LatexCommand \index{\_\_asm}
15267
15268 \end_inset 
15269
15270  
15271 \newline 
15272 \SpecialChar ~
15273 \SpecialChar ~
15274 \SpecialChar ~
15275 \SpecialChar ~
15276 mov\SpecialChar ~
15277 \SpecialChar ~
15278 \SpecialChar ~
15279 \SpecialChar ~
15280 \SpecialChar ~
15281 b,#10 
15282 \newline 
15283 00001$: 
15284 \newline 
15285 \SpecialChar ~
15286 \SpecialChar ~
15287 \SpecialChar ~
15288 \SpecialChar ~
15289 djnz\SpecialChar ~
15290 \SpecialChar ~
15291 \SpecialChar ~
15292 \SpecialChar ~
15293 b,00001$ 
15294 \newline 
15295 _endasm
15296 \begin_inset LatexCommand \index{\_endasm}
15297
15298 \end_inset 
15299
15300
15301 \begin_inset LatexCommand \index{\_\_endasm}
15302
15303 \end_inset 
15304
15305  ;
15306 \layout Standard
15307
15308 Inline assembler code cannot reference any C-Labels, however it can reference
15309  labels
15310 \begin_inset LatexCommand \index{Labels}
15311
15312 \end_inset 
15313
15314  defined by the inline assembler, e.g.:
15315 \layout Verse
15316
15317
15318 \family typewriter 
15319 foo() { 
15320 \newline 
15321 \SpecialChar ~
15322 \SpecialChar ~
15323 \SpecialChar ~
15324 \SpecialChar ~
15325 /* some c code */ 
15326 \newline 
15327 \SpecialChar ~
15328 \SpecialChar ~
15329 \SpecialChar ~
15330 \SpecialChar ~
15331 _asm 
15332 \newline 
15333 \SpecialChar ~
15334 \SpecialChar ~
15335 \SpecialChar ~
15336 \SpecialChar ~
15337 \SpecialChar ~
15338 \SpecialChar ~
15339 ; some assembler code 
15340 \newline 
15341 \SpecialChar ~
15342 \SpecialChar ~
15343 \SpecialChar ~
15344 \SpecialChar ~
15345 \SpecialChar ~
15346 \SpecialChar ~
15347 ljmp $0003 
15348 \newline 
15349 \SpecialChar ~
15350 \SpecialChar ~
15351 \SpecialChar ~
15352 \SpecialChar ~
15353 _endasm; 
15354 \newline 
15355 \SpecialChar ~
15356 \SpecialChar ~
15357 \SpecialChar ~
15358 \SpecialChar ~
15359 /* some more c code */ 
15360 \newline 
15361 clabel:\SpecialChar ~
15362 \SpecialChar ~
15363 /* inline assembler cannot reference this label */ 
15364 \newline 
15365 \SpecialChar ~
15366 \SpecialChar ~
15367 \SpecialChar ~
15368 \SpecialChar ~
15369 _asm
15370 \newline 
15371 \SpecialChar ~
15372 \SpecialChar ~
15373 \SpecialChar ~
15374 \SpecialChar ~
15375 $0003: ;label (can be referenced by inline assembler only) 
15376 \newline 
15377 \SpecialChar ~
15378 \SpecialChar ~
15379 \SpecialChar ~
15380 \SpecialChar ~
15381 _endasm
15382 \begin_inset LatexCommand \index{\_endasm}
15383
15384 \end_inset 
15385
15386
15387 \begin_inset LatexCommand \index{\_\_endasm}
15388
15389 \end_inset 
15390
15391  ; 
15392 \newline 
15393 \SpecialChar ~
15394 \SpecialChar ~
15395 \SpecialChar ~
15396 \SpecialChar ~
15397 /* some more c code */
15398 \newline 
15399 }
15400 \layout Standard
15401
15402 In other words inline assembly code can access labels defined in inline
15403  assembly within the scope of the function.
15404  The same goes the other way, i.e.
15405  labels defines in inline assembly can not be accessed by C statements.
15406 \layout Section
15407
15408 Interfacing with Assembler Code
15409 \begin_inset LatexCommand \index{Assembler routines}
15410
15411 \end_inset 
15412
15413
15414 \layout Subsection
15415
15416 Global Registers used for Parameter Passing
15417 \begin_inset LatexCommand \index{Parameter passing}
15418
15419 \end_inset 
15420
15421
15422 \layout Standard
15423
15424 The compiler always uses the global registers 
15425 \emph on 
15426 DPL, DPH
15427 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
15428
15429 \end_inset 
15430
15431
15432 \begin_inset LatexCommand \index{DPTR}
15433
15434 \end_inset 
15435
15436 , B
15437 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
15438
15439 \end_inset 
15440
15441  
15442 \emph default 
15443 and
15444 \emph on 
15445  ACC
15446 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
15447
15448 \end_inset 
15449
15450
15451 \emph default 
15452  to pass the first parameter to a routine.
15453  The second parameter onwards is either allocated on the stack (for reentrant
15454  routines or if -
15455 \begin_inset ERT
15456 status Collapsed
15457
15458 \layout Standard
15459
15460 \backslash 
15461 /
15462 \end_inset 
15463
15464 -stack-auto is used) or in data / xdata memory (depending on the memory
15465  model).
15466  
15467 \layout Subsection
15468
15469 Assembler Routine (non-reentrant)
15470 \layout Standard
15471
15472 In the following example
15473 \begin_inset LatexCommand \index{reentrant}
15474
15475 \end_inset 
15476
15477
15478 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
15479
15480 \end_inset 
15481
15482  the function c_func calls an assembler routine asm_func, which takes two
15483  parameters
15484 \begin_inset LatexCommand \index{function parameter}
15485
15486 \end_inset 
15487
15488 .
15489 \layout Verse
15490
15491
15492 \family typewriter 
15493 extern int asm_func(unsigned char, unsigned char);
15494 \newline 
15495
15496 \newline 
15497 int c_func (unsigned char i, unsigned char j)
15498 \newline 
15499 {
15500 \newline 
15501 \SpecialChar ~
15502 \SpecialChar ~
15503 \SpecialChar ~
15504 \SpecialChar ~
15505 return asm_func(i,j);
15506 \newline 
15507 }
15508 \newline 
15509
15510 \newline 
15511 int main()
15512 \newline 
15513 {
15514 \newline 
15515 \SpecialChar ~
15516 \SpecialChar ~
15517 \SpecialChar ~
15518 \SpecialChar ~
15519 return c_func(10,9);
15520 \newline 
15521 }
15522 \layout Standard
15523
15524 The corresponding assembler function is:
15525 \layout Verse
15526
15527
15528 \family typewriter 
15529 .globl _asm_func_PARM_2 
15530 \newline 
15531 \SpecialChar ~
15532 \SpecialChar ~
15533 \SpecialChar ~
15534 \SpecialChar ~
15535 \SpecialChar ~
15536 \SpecialChar ~
15537 \SpecialChar ~
15538 \SpecialChar ~
15539 .globl _asm_func 
15540 \newline 
15541 \SpecialChar ~
15542 \SpecialChar ~
15543 \SpecialChar ~
15544 \SpecialChar ~
15545 \SpecialChar ~
15546 \SpecialChar ~
15547 \SpecialChar ~
15548 \SpecialChar ~
15549 .area OSEG 
15550 \newline 
15551 _asm_func_PARM_2:
15552 \newline 
15553 \SpecialChar ~
15554 \SpecialChar ~
15555 \SpecialChar ~
15556 \SpecialChar ~
15557 \SpecialChar ~
15558 \SpecialChar ~
15559 \SpecialChar ~
15560 \SpecialChar ~
15561 .ds    1 
15562 \newline 
15563 \SpecialChar ~
15564 \SpecialChar ~
15565 \SpecialChar ~
15566 \SpecialChar ~
15567 \SpecialChar ~
15568 \SpecialChar ~
15569 \SpecialChar ~
15570 \SpecialChar ~
15571 .area CSEG 
15572 \newline 
15573 _asm_func: 
15574 \newline 
15575 \SpecialChar ~
15576 \SpecialChar ~
15577 \SpecialChar ~
15578 \SpecialChar ~
15579 \SpecialChar ~
15580 \SpecialChar ~
15581 \SpecialChar ~
15582 \SpecialChar ~
15583 mov\SpecialChar ~
15584 \SpecialChar ~
15585 \SpecialChar ~
15586 \SpecialChar ~
15587 a,dpl 
15588 \newline 
15589 \SpecialChar ~
15590 \SpecialChar ~
15591 \SpecialChar ~
15592 \SpecialChar ~
15593 \SpecialChar ~
15594 \SpecialChar ~
15595 \SpecialChar ~
15596 \SpecialChar ~
15597 add\SpecialChar ~
15598 \SpecialChar ~
15599 \SpecialChar ~
15600 \SpecialChar ~
15601 a,_asm_func_PARM_2 
15602 \newline 
15603 \SpecialChar ~
15604 \SpecialChar ~
15605 \SpecialChar ~
15606 \SpecialChar ~
15607 \SpecialChar ~
15608 \SpecialChar ~
15609 \SpecialChar ~
15610 \SpecialChar ~
15611 mov\SpecialChar ~
15612 \SpecialChar ~
15613 \SpecialChar ~
15614 \SpecialChar ~
15615 dpl,a 
15616 \newline 
15617 \SpecialChar ~
15618 \SpecialChar ~
15619 \SpecialChar ~
15620 \SpecialChar ~
15621 \SpecialChar ~
15622 \SpecialChar ~
15623 \SpecialChar ~
15624 \SpecialChar ~
15625 mov\SpecialChar ~
15626 \SpecialChar ~
15627 \SpecialChar ~
15628 \SpecialChar ~
15629 dph
15630 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
15631
15632 \end_inset 
15633
15634 ,#0x00 
15635 \newline 
15636 \SpecialChar ~
15637 \SpecialChar ~
15638 \SpecialChar ~
15639 \SpecialChar ~
15640 \SpecialChar ~
15641 \SpecialChar ~
15642 \SpecialChar ~
15643 \SpecialChar ~
15644 ret
15645 \layout Standard
15646
15647 Note here that the return values
15648 \begin_inset LatexCommand \index{return value}
15649
15650 \end_inset 
15651
15652  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
15653  two byte values.
15654  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
15655 b' & 'acc' for four byte values.
15656 \layout Standard
15657
15658 The parameter naming convention is _<function_name>_PARM_<n>, where n is
15659  the parameter number starting from 1, and counting from the left.
15660  The first parameter is passed in 
15661 \begin_inset Quotes eld
15662 \end_inset 
15663
15664 dpl
15665 \begin_inset Quotes erd
15666 \end_inset 
15667
15668  for a one byte parameter, 
15669 \begin_inset Quotes eld
15670 \end_inset 
15671
15672 dptr
15673 \begin_inset Quotes erd
15674 \end_inset 
15675
15676  for two bytes, 
15677 \begin_inset Quotes eld
15678 \end_inset 
15679
15680 b,dptr
15681 \begin_inset Quotes erd
15682 \end_inset 
15683
15684  for three bytes and 
15685 \begin_inset Quotes eld
15686 \end_inset 
15687
15688 acc,b,dptr
15689 \begin_inset Quotes erd
15690 \end_inset 
15691
15692  for a four bytes parameter.
15693  The variable name for the second parameter will be _<function_name>_PARM_2.
15694 \newline 
15695
15696 \newline 
15697 Assemble the assembler routine with the following command:
15698 \newline 
15699
15700 \newline 
15701
15702 \family sans 
15703 \series bold 
15704 asx8051 -losg asmfunc.asm
15705 \newline 
15706
15707 \newline 
15708
15709 \family default 
15710 \series default 
15711 Then compile and link the assembler routine to the C source file with the
15712  following command:
15713 \newline 
15714
15715 \newline 
15716
15717 \family sans 
15718 \series bold 
15719 sdcc cfunc.c asmfunc.rel
15720 \layout Subsection
15721
15722 Assembler Routine (reentrant)
15723 \layout Standard
15724
15725 In this case
15726 \begin_inset LatexCommand \index{reentrant}
15727
15728 \end_inset 
15729
15730
15731 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
15732
15733 \end_inset 
15734
15735  the second parameter
15736 \begin_inset LatexCommand \index{function parameter}
15737
15738 \end_inset 
15739
15740  onwards will be passed on the stack, the parameters are pushed from right
15741  to left i.e.
15742  after the call the leftmost parameter will be on the top of the stack.
15743  Here is an example:
15744 \layout Verse
15745
15746
15747 \family typewriter 
15748 extern int asm_func(unsigned char, unsigned char);
15749 \newline 
15750
15751 \newline 
15752 int c_func (unsigned char i, unsigned char j) reentrant 
15753 \newline 
15754
15755 \newline 
15756 \SpecialChar ~
15757 \SpecialChar ~
15758 \SpecialChar ~
15759 \SpecialChar ~
15760 return asm_func(i,j); 
15761 \newline 
15762
15763 \newline 
15764
15765 \newline 
15766 int main() 
15767 \newline 
15768
15769 \newline 
15770 \SpecialChar ~
15771 \SpecialChar ~
15772 \SpecialChar ~
15773 \SpecialChar ~
15774 return c_func(10,9); 
15775 \newline 
15776 }
15777 \layout Standard
15778
15779 The corresponding assembler routine is:
15780 \layout Verse
15781
15782
15783 \family typewriter 
15784 .globl _asm_func 
15785 \newline 
15786 _asm_func: 
15787 \newline 
15788 \SpecialChar ~
15789 \SpecialChar ~
15790 \SpecialChar ~
15791 \SpecialChar ~
15792 push  _bp 
15793 \newline 
15794 \SpecialChar ~
15795 \SpecialChar ~
15796 \SpecialChar ~
15797 \SpecialChar ~
15798 mov _bp,sp 
15799 \newline 
15800 \SpecialChar ~
15801 \SpecialChar ~
15802 \SpecialChar ~
15803 \SpecialChar ~
15804 mov r2,dpl
15805 \newline 
15806 \SpecialChar ~
15807 \SpecialChar ~
15808 \SpecialChar ~
15809 \SpecialChar ~
15810 mov a,_bp 
15811 \newline 
15812 \SpecialChar ~
15813 \SpecialChar ~
15814 \SpecialChar ~
15815 \SpecialChar ~
15816 add a,#0xfd 
15817 \newline 
15818 \SpecialChar ~
15819 \SpecialChar ~
15820 \SpecialChar ~
15821 \SpecialChar ~
15822 mov r0,a 
15823 \newline 
15824 \SpecialChar ~
15825 \SpecialChar ~
15826 \SpecialChar ~
15827 \SpecialChar ~
15828 add  a,#0xfc ;?
15829 \newline 
15830 \SpecialChar ~
15831 \SpecialChar ~
15832 \SpecialChar ~
15833 \SpecialChar ~
15834 mov  r1,a 
15835 \newline 
15836 \SpecialChar ~
15837 \SpecialChar ~
15838 \SpecialChar ~
15839 \SpecialChar ~
15840 mov  a,@r0 
15841 \newline 
15842 \SpecialChar ~
15843 \SpecialChar ~
15844 \SpecialChar ~
15845 \SpecialChar ~
15846 add  a,r2 ;?
15847 \newline 
15848 \SpecialChar ~
15849 \SpecialChar ~
15850 \SpecialChar ~
15851 \SpecialChar ~
15852 mov  dpl,a 
15853 \newline 
15854 \SpecialChar ~
15855 \SpecialChar ~
15856 \SpecialChar ~
15857 \SpecialChar ~
15858 mov  dph,#0x00 
15859 \newline 
15860 \SpecialChar ~
15861 \SpecialChar ~
15862 \SpecialChar ~
15863 \SpecialChar ~
15864 mov  sp,_bp 
15865 \newline 
15866 \SpecialChar ~
15867 \SpecialChar ~
15868 \SpecialChar ~
15869 \SpecialChar ~
15870 pop  _bp 
15871 \newline 
15872 \SpecialChar ~
15873 \SpecialChar ~
15874 \SpecialChar ~
15875 \SpecialChar ~
15876 ret
15877 \layout Standard
15878 \added_space_bottom bigskip 
15879 The compiling and linking procedure remains the same, however note the extra
15880  entry & exit linkage required for the assembler code, _bp is the stack
15881  frame pointer and is used to compute the offset into the stack for parameters
15882  and local variables.
15883 \layout Section
15884
15885 int (16 bit)
15886 \begin_inset LatexCommand \index{int (16 bit)}
15887
15888 \end_inset 
15889
15890  and long (32 bit)
15891 \begin_inset LatexCommand \index{long (32 bit)}
15892
15893 \end_inset 
15894
15895  Support
15896 \layout Standard
15897
15898 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
15899  multiplication and modulus operations are implemented by support routines.
15900  These support routines are all developed in ANSI-C to facilitate porting
15901  to other MCUs, although some model specific assembler optimizations are
15902  used.
15903  The following files contain the described routines, all of them can be
15904  found in <installdir>/share/sdcc/lib.
15905 \newline 
15906
15907 \layout Standard
15908 \align center 
15909
15910 \begin_inset  Tabular
15911 <lyxtabular version="3" rows="11" columns="2">
15912 <features>
15913 <column alignment="left" valignment="top" leftline="true" width="0">
15914 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
15915 <row topline="true" bottomline="true">
15916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15917 \begin_inset Text
15918
15919 \layout Standard
15920
15921
15922 \series bold 
15923 Function
15924 \end_inset 
15925 </cell>
15926 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15927 \begin_inset Text
15928
15929 \layout Standard
15930
15931
15932 \series bold 
15933 Description
15934 \end_inset 
15935 </cell>
15936 </row>
15937 <row topline="true">
15938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15939 \begin_inset Text
15940
15941 \layout Standard
15942
15943 _mulint.c 
15944 \end_inset 
15945 </cell>
15946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15947 \begin_inset Text
15948
15949 \layout Standard
15950
15951 16 bit multiplication
15952 \end_inset 
15953 </cell>
15954 </row>
15955 <row topline="true">
15956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15957 \begin_inset Text
15958
15959 \layout Standard
15960
15961 _divsint.c 
15962 \end_inset 
15963 </cell>
15964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15965 \begin_inset Text
15966
15967 \layout Standard
15968
15969  signed 16 bit division (calls _divuint)
15970 \end_inset 
15971 </cell>
15972 </row>
15973 <row topline="true">
15974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15975 \begin_inset Text
15976
15977 \layout Standard
15978
15979 _divuint.c 
15980 \end_inset 
15981 </cell>
15982 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15983 \begin_inset Text
15984
15985 \layout Standard
15986
15987  unsigned 16 bit division
15988 \end_inset 
15989 </cell>
15990 </row>
15991 <row topline="true">
15992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15993 \begin_inset Text
15994
15995 \layout Standard
15996
15997 _modsint.c
15998 \end_inset 
15999 </cell>
16000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16001 \begin_inset Text
16002
16003 \layout Standard
16004
16005 signed 16 bit modulus (calls _moduint)
16006 \end_inset 
16007 </cell>
16008 </row>
16009 <row topline="true">
16010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16011 \begin_inset Text
16012
16013 \layout Standard
16014
16015 _moduint.c
16016 \end_inset 
16017 </cell>
16018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16019 \begin_inset Text
16020
16021 \layout Standard
16022
16023 unsigned 16 bit modulus
16024 \end_inset 
16025 </cell>
16026 </row>
16027 <row topline="true">
16028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16029 \begin_inset Text
16030
16031 \layout Standard
16032
16033 _mullong.c
16034 \end_inset 
16035 </cell>
16036 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16037 \begin_inset Text
16038
16039 \layout Standard
16040
16041 32 bit multiplication
16042 \end_inset 
16043 </cell>
16044 </row>
16045 <row topline="true">
16046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16047 \begin_inset Text
16048
16049 \layout Standard
16050
16051 _divslong.c 
16052 \end_inset 
16053 </cell>
16054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16055 \begin_inset Text
16056
16057 \layout Standard
16058
16059  signed 32 division (calls _divulong)
16060 \end_inset 
16061 </cell>
16062 </row>
16063 <row topline="true">
16064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16065 \begin_inset Text
16066
16067 \layout Standard
16068
16069 _divulong.c 
16070 \end_inset 
16071 </cell>
16072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16073 \begin_inset Text
16074
16075 \layout Standard
16076
16077 unsigned 32 division
16078 \end_inset 
16079 </cell>
16080 </row>
16081 <row topline="true">
16082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16083 \begin_inset Text
16084
16085 \layout Standard
16086
16087 _modslong.c
16088 \end_inset 
16089 </cell>
16090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16091 \begin_inset Text
16092
16093 \layout Standard
16094
16095  signed 32 bit modulus (calls _modulong)
16096 \end_inset 
16097 </cell>
16098 </row>
16099 <row topline="true" bottomline="true">
16100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16101 \begin_inset Text
16102
16103 \layout Standard
16104
16105 _modulong.c
16106 \end_inset 
16107 </cell>
16108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16109 \begin_inset Text
16110
16111 \layout Standard
16112
16113 unsigned 32 bit modulus
16114 \end_inset 
16115 </cell>
16116 </row>
16117 </lyxtabular>
16118
16119 \end_inset 
16120
16121
16122 \newline 
16123
16124 \layout Standard
16125
16126 Since they are compiled as 
16127 \emph on 
16128 non-reentrant
16129 \emph default 
16130
16131 \begin_inset LatexCommand \index{reentrant}
16132
16133 \end_inset 
16134
16135 , interrupt
16136 \begin_inset LatexCommand \index{interrupt}
16137
16138 \end_inset 
16139
16140  service routines should not do any of the above operations.
16141  If this is unavoidable then the above routines will need to be compiled
16142  with the 
16143 \emph on 
16144 -
16145 \begin_inset ERT
16146 status Collapsed
16147
16148 \layout Standard
16149
16150 \backslash 
16151 /
16152 \end_inset 
16153
16154 -stack-auto
16155 \begin_inset LatexCommand \index{-\/-stack-auto}
16156
16157 \end_inset 
16158
16159
16160 \emph default 
16161  option, after which the source program will have to be compiled with 
16162 \emph on 
16163 -
16164 \begin_inset ERT
16165 status Collapsed
16166
16167 \layout Standard
16168
16169 \backslash 
16170 /
16171 \end_inset 
16172
16173 -int-long-reent
16174 \begin_inset LatexCommand \index{-\/-int-long-reent}
16175
16176 \end_inset 
16177
16178
16179 \emph default 
16180  option.
16181  Notice that you don't have to call these routines directly.
16182  The compiler will use them automatically every time an integer operation
16183  is required.
16184 \layout Section
16185
16186 Floating Point Support
16187 \begin_inset LatexCommand \index{Floating point support}
16188
16189 \end_inset 
16190
16191
16192 \layout Standard
16193
16194 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
16195  The floating point support routines are derived from gcc's floatlib.c and
16196  consist of the following routines:
16197 \newline 
16198
16199 \layout Standard
16200 \align center 
16201
16202 \size footnotesize 
16203
16204 \begin_inset  Tabular
16205 <lyxtabular version="3" rows="17" columns="2">
16206 <features>
16207 <column alignment="left" valignment="top" leftline="true" width="0">
16208 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
16209 <row topline="true" bottomline="true">
16210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16211 \begin_inset Text
16212
16213 \layout Standard
16214
16215
16216 \family roman 
16217 \series medium 
16218 \shape up 
16219 \size normal 
16220 \emph off 
16221 \bar no 
16222 \noun off 
16223 \color none
16224 Function 
16225 \end_inset 
16226 </cell>
16227 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16228 \begin_inset Text
16229
16230 \layout Standard
16231
16232 Description
16233 \end_inset 
16234 </cell>
16235 </row>
16236 <row topline="true">
16237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16238 \begin_inset Text
16239
16240 \layout Standard
16241
16242
16243 \family roman 
16244 \series medium 
16245 \shape up 
16246 \size normal 
16247 \emph off 
16248 \bar no 
16249 \noun off 
16250 \color none
16251 _fsadd.c
16252 \end_inset 
16253 </cell>
16254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16255 \begin_inset Text
16256
16257 \layout Standard
16258
16259
16260 \family roman 
16261 \series medium 
16262 \shape up 
16263 \size normal 
16264 \emph off 
16265 \bar no 
16266 \noun off 
16267 \color none
16268 add floating point numbers
16269 \end_inset 
16270 </cell>
16271 </row>
16272 <row topline="true">
16273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16274 \begin_inset Text
16275
16276 \layout Standard
16277
16278
16279 \family roman 
16280 \series medium 
16281 \shape up 
16282 \size normal 
16283 \emph off 
16284 \bar no 
16285 \noun off 
16286 \color none
16287 _fssub.c 
16288 \end_inset 
16289 </cell>
16290 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16291 \begin_inset Text
16292
16293 \layout Standard
16294
16295
16296 \family roman 
16297 \series medium 
16298 \shape up 
16299 \size normal 
16300 \emph off 
16301 \bar no 
16302 \noun off 
16303 \color none
16304 subtract floating point numbers 
16305 \end_inset 
16306 </cell>
16307 </row>
16308 <row topline="true">
16309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16310 \begin_inset Text
16311
16312 \layout Standard
16313
16314
16315 \family roman 
16316 \series medium 
16317 \shape up 
16318 \size normal 
16319 \emph off 
16320 \bar no 
16321 \noun off 
16322 \color none
16323 _fsdiv.c 
16324 \end_inset 
16325 </cell>
16326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16327 \begin_inset Text
16328
16329 \layout Standard
16330
16331
16332 \family roman 
16333 \series medium 
16334 \shape up 
16335 \size normal 
16336 \emph off 
16337 \bar no 
16338 \noun off 
16339 \color none
16340 divide floating point numbers 
16341 \end_inset 
16342 </cell>
16343 </row>
16344 <row topline="true">
16345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16346 \begin_inset Text
16347
16348 \layout Standard
16349
16350
16351 \family roman 
16352 \series medium 
16353 \shape up 
16354 \size normal 
16355 \emph off 
16356 \bar no 
16357 \noun off 
16358 \color none
16359 _fsmul.c 
16360 \end_inset 
16361 </cell>
16362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16363 \begin_inset Text
16364
16365 \layout Standard
16366
16367
16368 \family roman 
16369 \series medium 
16370 \shape up 
16371 \size normal 
16372 \emph off 
16373 \bar no 
16374 \noun off 
16375 \color none
16376 multiply floating point numbers 
16377 \end_inset 
16378 </cell>
16379 </row>
16380 <row topline="true">
16381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16382 \begin_inset Text
16383
16384 \layout Standard
16385
16386
16387 \family roman 
16388 \series medium 
16389 \shape up 
16390 \size normal 
16391 \emph off 
16392 \bar no 
16393 \noun off 
16394 \color none
16395 _fs2uchar.c
16396 \end_inset 
16397 </cell>
16398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16399 \begin_inset Text
16400
16401 \layout Standard
16402
16403
16404 \family roman 
16405 \series medium 
16406 \shape up 
16407 \size normal 
16408 \emph off 
16409 \bar no 
16410 \noun off 
16411 \color none
16412 convert floating point to unsigned char
16413 \end_inset 
16414 </cell>
16415 </row>
16416 <row topline="true">
16417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16418 \begin_inset Text
16419
16420 \layout Standard
16421
16422
16423 \family roman 
16424 \series medium 
16425 \shape up 
16426 \size normal 
16427 \emph off 
16428 \bar no 
16429 \noun off 
16430 \color none
16431 _fs2char.c
16432 \end_inset 
16433 </cell>
16434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16435 \begin_inset Text
16436
16437 \layout Standard
16438
16439
16440 \family roman 
16441 \series medium 
16442 \shape up 
16443 \size normal 
16444 \emph off 
16445 \bar no 
16446 \noun off 
16447 \color none
16448 convert floating point to signed char
16449 \end_inset 
16450 </cell>
16451 </row>
16452 <row topline="true">
16453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16454 \begin_inset Text
16455
16456 \layout Standard
16457
16458
16459 \family roman 
16460 \series medium 
16461 \shape up 
16462 \size normal 
16463 \emph off 
16464 \bar no 
16465 \noun off 
16466 \color none
16467 _fs2uint.c
16468 \end_inset 
16469 </cell>
16470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16471 \begin_inset Text
16472
16473 \layout Standard
16474
16475
16476 \family roman 
16477 \series medium 
16478 \shape up 
16479 \size normal 
16480 \emph off 
16481 \bar no 
16482 \noun off 
16483 \color none
16484 convert floating point to unsigned int
16485 \end_inset 
16486 </cell>
16487 </row>
16488 <row topline="true">
16489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16490 \begin_inset Text
16491
16492 \layout Standard
16493
16494
16495 \family roman 
16496 \series medium 
16497 \shape up 
16498 \size normal 
16499 \emph off 
16500 \bar no 
16501 \noun off 
16502 \color none
16503 _fs2int.c
16504 \end_inset 
16505 </cell>
16506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16507 \begin_inset Text
16508
16509 \layout Standard
16510
16511
16512 \family roman 
16513 \series medium 
16514 \shape up 
16515 \size normal 
16516 \emph off 
16517 \bar no 
16518 \noun off 
16519 \color none
16520 convert floating point to signed int
16521 \end_inset 
16522 </cell>
16523 </row>
16524 <row topline="true">
16525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16526 \begin_inset Text
16527
16528 \layout Standard
16529
16530
16531 \family roman 
16532 \series medium 
16533 \shape up 
16534 \size normal 
16535 \emph off 
16536 \bar no 
16537 \noun off 
16538 \color none
16539 _fs2ulong.
16540 \family default 
16541 \series default 
16542 \shape default 
16543 \size default 
16544 \emph default 
16545 \bar default 
16546 \noun default 
16547 c
16548 \end_inset 
16549 </cell>
16550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16551 \begin_inset Text
16552
16553 \layout Standard
16554
16555
16556 \family roman 
16557 \series medium 
16558 \shape up 
16559 \size normal 
16560 \emph off 
16561 \bar no 
16562 \noun off 
16563 \color none
16564 convert floating point to unsigned long
16565 \end_inset 
16566 </cell>
16567 </row>
16568 <row topline="true">
16569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16570 \begin_inset Text
16571
16572 \layout Standard
16573
16574
16575 \family roman 
16576 \series medium 
16577 \shape up 
16578 \size normal 
16579 \emph off 
16580 \bar no 
16581 \noun off 
16582 \color none
16583 _fs2long.c
16584 \end_inset 
16585 </cell>
16586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16587 \begin_inset Text
16588
16589 \layout Standard
16590
16591
16592 \family roman 
16593 \series medium 
16594 \shape up 
16595 \size normal 
16596 \emph off 
16597 \bar no 
16598 \noun off 
16599 \color none
16600 convert floating point to signed long
16601 \end_inset 
16602 </cell>
16603 </row>
16604 <row topline="true">
16605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16606 \begin_inset Text
16607
16608 \layout Standard
16609
16610
16611 \family roman 
16612 \series medium 
16613 \shape up 
16614 \size normal 
16615 \emph off 
16616 \bar no 
16617 \noun off 
16618 \color none
16619 _uchar2fs.c
16620 \end_inset 
16621 </cell>
16622 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16623 \begin_inset Text
16624
16625 \layout Standard
16626
16627
16628 \family roman 
16629 \series medium 
16630 \shape up 
16631 \size normal 
16632 \emph off 
16633 \bar no 
16634 \noun off 
16635 \color none
16636 convert unsigned char to floating point
16637 \end_inset 
16638 </cell>
16639 </row>
16640 <row topline="true">
16641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16642 \begin_inset Text
16643
16644 \layout Standard
16645
16646
16647 \family roman 
16648 \series medium 
16649 \shape up 
16650 \size normal 
16651 \emph off 
16652 \bar no 
16653 \noun off 
16654 \color none
16655 _char2fs.c
16656 \end_inset 
16657 </cell>
16658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16659 \begin_inset Text
16660
16661 \layout Standard
16662
16663
16664 \family roman 
16665 \series medium 
16666 \shape up 
16667 \size normal 
16668 \emph off 
16669 \bar no 
16670 \noun off 
16671 \color none
16672 convert char to floating point number
16673 \end_inset 
16674 </cell>
16675 </row>
16676 <row topline="true">
16677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16678 \begin_inset Text
16679
16680 \layout Standard
16681
16682
16683 \family roman 
16684 \series medium 
16685 \shape up 
16686 \size normal 
16687 \emph off 
16688 \bar no 
16689 \noun off 
16690 \color none
16691 _uint2fs.c
16692 \end_inset 
16693 </cell>
16694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16695 \begin_inset Text
16696
16697 \layout Standard
16698
16699
16700 \family roman 
16701 \series medium 
16702 \shape up 
16703 \size normal 
16704 \emph off 
16705 \bar no 
16706 \noun off 
16707 \color none
16708 convert unsigned int to floating point
16709 \end_inset 
16710 </cell>
16711 </row>
16712 <row topline="true">
16713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16714 \begin_inset Text
16715
16716 \layout Standard
16717
16718
16719 \family roman 
16720 \series medium 
16721 \shape up 
16722 \size normal 
16723 \emph off 
16724 \bar no 
16725 \noun off 
16726 \color none
16727 _int2fs.c
16728 \end_inset 
16729 </cell>
16730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16731 \begin_inset Text
16732
16733 \layout Standard
16734
16735
16736 \family roman 
16737 \series medium 
16738 \shape up 
16739 \size normal 
16740 \emph off 
16741 \bar no 
16742 \noun off 
16743 \color none
16744 convert int to floating point numbers
16745 \end_inset 
16746 </cell>
16747 </row>
16748 <row topline="true">
16749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16750 \begin_inset Text
16751
16752 \layout Standard
16753
16754
16755 \family roman 
16756 \series medium 
16757 \shape up 
16758 \size normal 
16759 \emph off 
16760 \bar no 
16761 \noun off 
16762 \color none
16763 _ulong2fs.c
16764 \end_inset 
16765 </cell>
16766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16767 \begin_inset Text
16768
16769 \layout Standard
16770
16771
16772 \family roman 
16773 \series medium 
16774 \shape up 
16775 \size normal 
16776 \emph off 
16777 \bar no 
16778 \noun off 
16779 \color none
16780 convert unsigned long to floating point number
16781 \end_inset 
16782 </cell>
16783 </row>
16784 <row topline="true" bottomline="true">
16785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16786 \begin_inset Text
16787
16788 \layout Standard
16789
16790
16791 \family roman 
16792 \series medium 
16793 \shape up 
16794 \size normal 
16795 \emph off 
16796 \bar no 
16797 \noun off 
16798 \color none
16799 _long2fs.c
16800 \end_inset 
16801 </cell>
16802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16803 \begin_inset Text
16804
16805 \layout Standard
16806
16807
16808 \family roman 
16809 \series medium 
16810 \shape up 
16811 \size normal 
16812 \emph off 
16813 \bar no 
16814 \noun off 
16815 \color none
16816 convert long to floating point number
16817 \end_inset 
16818 </cell>
16819 </row>
16820 </lyxtabular>
16821
16822 \end_inset 
16823
16824
16825 \newline 
16826
16827 \layout Standard
16828 \added_space_bottom bigskip 
16829 These support routines are developed in ANSI-C so there is room for space
16830  and speed improvement
16831 \begin_inset Foot
16832 collapsed false
16833
16834 \layout Standard
16835
16836 These floating point routines (
16837 \emph on 
16838 not
16839 \emph default 
16840  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
16841  
16842 \end_inset 
16843
16844 .
16845  Note if all these routines are used simultaneously the data space might
16846  overflow.
16847  For serious floating point usage the large model might be needed.
16848  Also notice that you don't have to call this routines directly.
16849  The compiler will use them automatically every time a floating point operation
16850  is required.
16851 \layout Section
16852
16853 Library Routines
16854 \begin_inset LatexCommand \index{Libraries}
16855
16856 \end_inset 
16857
16858
16859 \layout Standard
16860
16861
16862 \emph on 
16863 <pending: this is messy and incomplete - a little more information is in
16864  sdcc/doc/libdoc.txt
16865 \emph default 
16866  >
16867 \layout Subsection
16868
16869 Compiler support routines (_gptrget, _mulint etc.)
16870 \layout Subsection
16871
16872 Stdclib functions (puts, printf, strcat etc.)
16873 \layout Subsubsection
16874
16875 <stdio.h>
16876 \layout Paragraph
16877
16878 getchar(), putchar()
16879 \layout Standard
16880
16881
16882 \begin_inset LatexCommand \index{<stdio.h>}
16883
16884 \end_inset 
16885
16886 As usual on embedded systems you have to provide your own 
16887 \family typewriter 
16888 getchar()
16889 \begin_inset LatexCommand \index{getchar()}
16890
16891 \end_inset 
16892
16893  
16894 \family default 
16895 and 
16896 \family typewriter 
16897 putchar()
16898 \begin_inset LatexCommand \index{putchar()}
16899
16900 \end_inset 
16901
16902
16903 \family default 
16904  routines.
16905  SDCC does not know whether the system connects to a serial line with or
16906  without handshake, LCD, keyboard or other device.
16907  And whether a 
16908 \family typewriter 
16909 lf
16910 \family default 
16911  to 
16912 \family typewriter 
16913 crlf
16914 \family default 
16915  conversion within 
16916 \family typewriter 
16917 putchar()
16918 \family default 
16919  is intended.
16920  You'll find examples for serial routines f.e.
16921  in sdcc/device/lib.
16922  For the mcs51 this minimalistic polling 
16923 \family typewriter 
16924 putchar()
16925 \family default 
16926  routine might be a start:
16927 \layout Verse
16928
16929
16930 \family typewriter 
16931 void putchar (char c) { 
16932 \newline 
16933 \SpecialChar ~
16934 \SpecialChar ~
16935 \SpecialChar ~
16936 \SpecialChar ~
16937 while (!TI)\SpecialChar ~
16938 \SpecialChar ~
16939 \SpecialChar ~
16940  /* assumes UART is initialized */
16941 \newline 
16942 \SpecialChar ~
16943 \SpecialChar ~
16944 \SpecialChar ~
16945 \SpecialChar ~
16946 \SpecialChar ~
16947 \SpecialChar ~
16948 \SpecialChar ~
16949 \SpecialChar ~
16950 ;
16951 \newline 
16952 \SpecialChar ~
16953 \SpecialChar ~
16954 \SpecialChar ~
16955 \SpecialChar ~
16956 TI = 0;
16957 \newline 
16958 \SpecialChar ~
16959 \SpecialChar ~
16960 \SpecialChar ~
16961 \SpecialChar ~
16962 SBUF = c;
16963 \newline 
16964 }
16965 \layout Paragraph
16966
16967 printf()
16968 \layout Standard
16969
16970 The default
16971 \family typewriter 
16972  printf()
16973 \begin_inset LatexCommand \index{printf()}
16974
16975 \end_inset 
16976
16977
16978 \family default 
16979  implementation in
16980 \family typewriter 
16981  printf_large.c
16982 \family default 
16983  does not support float (except on ds390).
16984  To enable this recompile it with the option 
16985 \emph on 
16986 -
16987 \begin_inset ERT
16988 status Collapsed
16989
16990 \layout Standard
16991
16992 \backslash 
16993 /
16994 \end_inset 
16995
16996 DUSE_FLOATS=1
16997 \begin_inset LatexCommand \index{USE\_FLOATS}
16998
16999 \end_inset 
17000
17001
17002 \emph default 
17003  on the command line.
17004  Use
17005 \emph on 
17006  -
17007 \begin_inset ERT
17008 status Collapsed
17009
17010 \layout Standard
17011
17012 \backslash 
17013 /
17014 \end_inset 
17015
17016 -model-large
17017 \begin_inset LatexCommand \index{-\/-model-large}
17018
17019 \end_inset 
17020
17021
17022 \emph default 
17023  for the mcs51 port, since this uses a lot of memory.
17024 \layout Standard
17025
17026 If you're short on code memory you might want to use 
17027 \family typewriter 
17028 printf_small()
17029 \begin_inset LatexCommand \index{printf\_small()}
17030
17031 \end_inset 
17032
17033
17034 \family default 
17035  
17036 \emph on 
17037 instead
17038 \emph default 
17039  of
17040 \family typewriter 
17041  printf().
17042
17043 \family default 
17044  For the mcs51 there additionally are assembly versions 
17045 \family typewriter 
17046 printf_tiny()
17047 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
17048
17049 \end_inset 
17050
17051
17052 \family default 
17053  (subset of printf using less than 270 bytes) and 
17054 \family typewriter 
17055 printf_fast()
17056 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
17057
17058 \end_inset 
17059
17060  
17061 \family default 
17062 and
17063 \family typewriter 
17064  printf_fast_f()
17065 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
17066
17067 \end_inset 
17068
17069
17070 \family default 
17071  (floating-point aware version of printf_fast) which should fit the requirements
17072  of many embedded systems (printf_fast() can be customized by unsetting
17073  #defines to 
17074 \emph on 
17075 not
17076 \emph default 
17077  support long variables and field widths).
17078  Be sure to use only one of these printf options within a project.
17079 \newline 
17080
17081 \layout Standard
17082
17083 Feature matrix of different 
17084 \emph on 
17085 printf
17086 \emph default 
17087  options on mcs51.
17088 \layout Standard
17089
17090
17091 \begin_inset  Tabular
17092 <lyxtabular version="3" rows="14" columns="7">
17093 <features islongtable="true">
17094 <column alignment="left" valignment="center" leftline="true" width="14col%">
17095 <column alignment="center" valignment="top" leftline="true" width="0">
17096 <column alignment="center" valignment="top" leftline="true" width="12col%">
17097 <column alignment="center" valignment="top" leftline="true" width="10col%">
17098 <column alignment="center" valignment="top" leftline="true" width="0">
17099 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
17100 <column alignment="center" valignment="top" rightline="true" width="0">
17101 <row topline="true" bottomline="true" endhead="true">
17102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17103 \begin_inset Text
17104
17105 \layout Standard
17106
17107
17108 \series bold 
17109 \size large 
17110 mcs51
17111 \end_inset 
17112 </cell>
17113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17114 \begin_inset Text
17115
17116 \layout Standard
17117
17118 printf
17119 \begin_inset LatexCommand \index{printf}
17120
17121 \end_inset 
17122
17123
17124 \end_inset 
17125 </cell>
17126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17127 \begin_inset Text
17128
17129 \layout Standard
17130
17131 printf 
17132 \size scriptsize 
17133 USE_FLOATS=1
17134 \end_inset 
17135 </cell>
17136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17137 \begin_inset Text
17138
17139 \layout Standard
17140
17141 printf_small
17142 \end_inset 
17143 </cell>
17144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17145 \begin_inset Text
17146
17147 \layout Standard
17148
17149 printf_fast
17150 \end_inset 
17151 </cell>
17152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17153 \begin_inset Text
17154
17155 \layout Standard
17156
17157 printf_fast_f
17158 \end_inset 
17159 </cell>
17160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17161 \begin_inset Text
17162
17163 \layout Standard
17164
17165 printf_tiny
17166 \end_inset 
17167 </cell>
17168 </row>
17169 <row topline="true" endhead="true">
17170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17171 \begin_inset Text
17172
17173 \layout Standard
17174
17175 filename
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
17183
17184 \size scriptsize 
17185 printf_large.c
17186 \end_inset 
17187 </cell>
17188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17189 \begin_inset Text
17190
17191 \layout Standard
17192
17193
17194 \size scriptsize 
17195 printf_large.c
17196 \end_inset 
17197 </cell>
17198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17199 \begin_inset Text
17200
17201 \layout Standard
17202
17203
17204 \size scriptsize 
17205 printfl.c
17206 \end_inset 
17207 </cell>
17208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17209 \begin_inset Text
17210
17211 \layout Standard
17212
17213
17214 \size scriptsize 
17215 printf_fast.c
17216 \end_inset 
17217 </cell>
17218 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17219 \begin_inset Text
17220
17221 \layout Standard
17222
17223
17224 \size scriptsize 
17225 printf_fast_f.c
17226 \end_inset 
17227 </cell>
17228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17229 \begin_inset Text
17230
17231 \layout Standard
17232
17233
17234 \size scriptsize 
17235 printf_tiny.c
17236 \end_inset 
17237 </cell>
17238 </row>
17239 <row topline="true" endhead="true">
17240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17241 \begin_inset Text
17242
17243 \layout Standard
17244
17245
17246 \begin_inset Quotes sld
17247 \end_inset 
17248
17249 Hello World
17250 \begin_inset Quotes srd
17251 \end_inset 
17252
17253  size
17254 \layout Standard
17255
17256 small / large
17257 \end_inset 
17258 </cell>
17259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17260 \begin_inset Text
17261
17262 \layout Standard
17263
17264 1.7k / 2.4k
17265 \end_inset 
17266 </cell>
17267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17268 \begin_inset Text
17269
17270 \layout Standard
17271
17272 4.3k / 5.6k
17273 \end_inset 
17274 </cell>
17275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17276 \begin_inset Text
17277
17278 \layout Standard
17279
17280 1.2k / 1.8k
17281 \end_inset 
17282 </cell>
17283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17284 \begin_inset Text
17285
17286 \layout Standard
17287
17288 1.3k / 1.3k
17289 \end_inset 
17290 </cell>
17291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17292 \begin_inset Text
17293
17294 \layout Standard
17295
17296 1.9k / 1.9k
17297 \end_inset 
17298 </cell>
17299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17300 \begin_inset Text
17301
17302 \layout Standard
17303
17304 0.44k / 0.44k
17305 \end_inset 
17306 </cell>
17307 </row>
17308 <row topline="true" endhead="true">
17309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17310 \begin_inset Text
17311
17312 \layout Standard
17313
17314 code size
17315 \layout Standard
17316
17317 small / large
17318 \end_inset 
17319 </cell>
17320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17321 \begin_inset Text
17322
17323 \layout Standard
17324
17325 1.4k / 2.0k
17326 \end_inset 
17327 </cell>
17328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17329 \begin_inset Text
17330
17331 \layout Standard
17332
17333 2.8k / 3.7k
17334 \end_inset 
17335 </cell>
17336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17337 \begin_inset Text
17338
17339 \layout Standard
17340
17341 0.45k / 0.47k (+ _ltoa)
17342 \end_inset 
17343 </cell>
17344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17345 \begin_inset Text
17346
17347 \layout Standard
17348
17349 1.2k / 1.2k
17350 \end_inset 
17351 </cell>
17352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17353 \begin_inset Text
17354
17355 \layout Standard
17356
17357 1.6k / 1.6k
17358 \end_inset 
17359 </cell>
17360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17361 \begin_inset Text
17362
17363 \layout Standard
17364
17365 0.26k / 0.26k
17366 \end_inset 
17367 </cell>
17368 </row>
17369 <row topline="true">
17370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17371 \begin_inset Text
17372
17373 \layout Standard
17374
17375 formats
17376 \end_inset 
17377 </cell>
17378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17379 \begin_inset Text
17380
17381 \layout Standard
17382
17383 cdi
17384 \emph on 
17385 o
17386 \emph default 
17387 psux
17388 \end_inset 
17389 </cell>
17390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17391 \begin_inset Text
17392
17393 \layout Standard
17394
17395
17396 \family roman 
17397 \series medium 
17398 \shape up 
17399 \size normal 
17400 \emph off 
17401 \bar no 
17402 \noun off 
17403 \color none
17404 cd
17405 \family default 
17406 \series default 
17407 \shape default 
17408 \size default 
17409 \emph default 
17410 \bar default 
17411 \noun default 
17412 f
17413 \family roman 
17414 \series medium 
17415 \shape up 
17416 \size normal 
17417 \emph off 
17418 \bar no 
17419 \noun off 
17420 i
17421 \family default 
17422 \series default 
17423 \shape default 
17424 \size default 
17425 \emph on 
17426 \bar default 
17427 \noun default 
17428 o
17429 \family roman 
17430 \series medium 
17431 \shape up 
17432 \size normal 
17433 \emph off 
17434 \bar no 
17435 \noun off 
17436 psux
17437 \end_inset 
17438 </cell>
17439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17440 \begin_inset Text
17441
17442 \layout Standard
17443
17444 c
17445 \family roman 
17446 \series medium 
17447 \shape up 
17448 \size normal 
17449 \emph off 
17450 \bar no 
17451 \noun off 
17452 \color none
17453 d
17454 \family default 
17455 \series default 
17456 \shape default 
17457 \size default 
17458 \emph on 
17459 \bar default 
17460 \noun default 
17461 o
17462 \family roman 
17463 \series medium 
17464 \shape up 
17465 \size normal 
17466 \emph off 
17467 \bar no 
17468 \noun off 
17469 s
17470 \family default 
17471 \series default 
17472 \shape default 
17473 \size default 
17474 \emph default 
17475 \bar default 
17476 \noun default 
17477 x
17478 \end_inset 
17479 </cell>
17480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17481 \begin_inset Text
17482
17483 \layout Standard
17484
17485 cdsux
17486 \end_inset 
17487 </cell>
17488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17489 \begin_inset Text
17490
17491 \layout Standard
17492
17493 cdfsux
17494 \end_inset 
17495 </cell>
17496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17497 \begin_inset Text
17498
17499 \layout Standard
17500
17501 cdsux
17502 \end_inset 
17503 </cell>
17504 </row>
17505 <row topline="true">
17506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17507 \begin_inset Text
17508
17509 \layout Standard
17510
17511 long (32 bit) support
17512 \end_inset 
17513 </cell>
17514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17515 \begin_inset Text
17516
17517 \layout Standard
17518
17519 x
17520 \end_inset 
17521 </cell>
17522 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17523 \begin_inset Text
17524
17525 \layout Standard
17526
17527 x
17528 \end_inset 
17529 </cell>
17530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17531 \begin_inset Text
17532
17533 \layout Standard
17534
17535 x
17536 \end_inset 
17537 </cell>
17538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17539 \begin_inset Text
17540
17541 \layout Standard
17542
17543 x
17544 \end_inset 
17545 </cell>
17546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17547 \begin_inset Text
17548
17549 \layout Standard
17550
17551
17552 \family roman 
17553 \series medium 
17554 \shape up 
17555 \size normal 
17556 \emph off 
17557 \bar no 
17558 \noun off 
17559 \color none
17560 x
17561 \end_inset 
17562 </cell>
17563 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17564 \begin_inset Text
17565
17566 \layout Standard
17567
17568 -
17569 \end_inset 
17570 </cell>
17571 </row>
17572 <row topline="true">
17573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17574 \begin_inset Text
17575
17576 \layout Standard
17577
17578 byte arguments on stack
17579 \end_inset 
17580 </cell>
17581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17582 \begin_inset Text
17583
17584 \layout Standard
17585
17586 b
17587 \end_inset 
17588 </cell>
17589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17590 \begin_inset Text
17591
17592 \layout Standard
17593
17594 b
17595 \end_inset 
17596 </cell>
17597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17598 \begin_inset Text
17599
17600 \layout Standard
17601
17602 -
17603 \end_inset 
17604 </cell>
17605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17606 \begin_inset Text
17607
17608 \layout Standard
17609
17610 -
17611 \end_inset 
17612 </cell>
17613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17614 \begin_inset Text
17615
17616 \layout Standard
17617
17618 -
17619 \end_inset 
17620 </cell>
17621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17622 \begin_inset Text
17623
17624 \layout Standard
17625
17626 -
17627 \end_inset 
17628 </cell>
17629 </row>
17630 <row topline="true">
17631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17632 \begin_inset Text
17633
17634 \layout Standard
17635
17636 float format
17637 \begin_inset LatexCommand \index{Floating point support}
17638
17639 \end_inset 
17640
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
17649 -
17650 \end_inset 
17651 </cell>
17652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17653 \begin_inset Text
17654
17655 \layout Standard
17656
17657 %f
17658 \end_inset 
17659 </cell>
17660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17661 \begin_inset Text
17662
17663 \layout Standard
17664
17665 -
17666 \end_inset 
17667 </cell>
17668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17669 \begin_inset Text
17670
17671 \layout Standard
17672
17673 -
17674 \end_inset 
17675 </cell>
17676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17677 \begin_inset Text
17678
17679 \layout Standard
17680
17681 %f
17682 \begin_inset Foot
17683 collapsed true
17684
17685 \layout Standard
17686
17687 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
17688 \end_inset 
17689
17690
17691 \end_inset 
17692 </cell>
17693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17694 \begin_inset Text
17695
17696 \layout Standard
17697
17698 -
17699 \end_inset 
17700 </cell>
17701 </row>
17702 <row topline="true">
17703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17704 \begin_inset Text
17705
17706 \layout Standard
17707
17708 float formats %e %g
17709 \end_inset 
17710 </cell>
17711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17712 \begin_inset Text
17713
17714 \layout Standard
17715
17716 -
17717 \end_inset 
17718 </cell>
17719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17720 \begin_inset Text
17721
17722 \layout Standard
17723
17724 -
17725 \end_inset 
17726 </cell>
17727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17728 \begin_inset Text
17729
17730 \layout Standard
17731
17732 -
17733 \end_inset 
17734 </cell>
17735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17736 \begin_inset Text
17737
17738 \layout Standard
17739
17740 -
17741 \end_inset 
17742 </cell>
17743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17744 \begin_inset Text
17745
17746 \layout Standard
17747
17748 -
17749 \end_inset 
17750 </cell>
17751 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17752 \begin_inset Text
17753
17754 \layout Standard
17755
17756 -
17757 \end_inset 
17758 </cell>
17759 </row>
17760 <row topline="true" bottomline="true">
17761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17762 \begin_inset Text
17763
17764 \layout Standard
17765
17766 field width
17767 \end_inset 
17768 </cell>
17769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17770 \begin_inset Text
17771
17772 \layout Standard
17773
17774 x
17775 \end_inset 
17776 </cell>
17777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17778 \begin_inset Text
17779
17780 \layout Standard
17781
17782 x
17783 \end_inset 
17784 </cell>
17785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17786 \begin_inset Text
17787
17788 \layout Standard
17789
17790 -
17791 \end_inset 
17792 </cell>
17793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17794 \begin_inset Text
17795
17796 \layout Standard
17797
17798 x
17799 \end_inset 
17800 </cell>
17801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17802 \begin_inset Text
17803
17804 \layout Standard
17805
17806 x
17807 \end_inset 
17808 </cell>
17809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17810 \begin_inset Text
17811
17812 \layout Standard
17813
17814 -
17815 \end_inset 
17816 </cell>
17817 </row>
17818 <row bottomline="true">
17819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17820 \begin_inset Text
17821
17822 \layout Standard
17823
17824 string speed
17825 \begin_inset Foot
17826 collapsed true
17827
17828 \layout Standard
17829
17830 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
17831 \backslash 
17832 r', '
17833 \backslash 
17834 n'); standard 8051 @ 22.1184 MHz, empty putchar()
17835 \end_inset 
17836
17837 ,
17838 \layout Standard
17839
17840 small / large
17841 \end_inset 
17842 </cell>
17843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17844 \begin_inset Text
17845
17846 \layout Standard
17847
17848 1.52 / 2.59 ms
17849 \end_inset 
17850 </cell>
17851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17852 \begin_inset Text
17853
17854 \layout Standard
17855
17856 1.53 / 2.62 ms
17857 \end_inset 
17858 </cell>
17859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17860 \begin_inset Text
17861
17862 \layout Standard
17863
17864 0.92 / 0.93 ms
17865 \end_inset 
17866 </cell>
17867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17868 \begin_inset Text
17869
17870 \layout Standard
17871
17872 0.45 / 0.45 ms
17873 \end_inset 
17874 </cell>
17875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17876 \begin_inset Text
17877
17878 \layout Standard
17879
17880 0.46 / 0.46 ms
17881 \end_inset 
17882 </cell>
17883 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17884 \begin_inset Text
17885
17886 \layout Standard
17887
17888 0.45 / 0.45 ms
17889 \end_inset 
17890 </cell>
17891 </row>
17892 <row bottomline="true">
17893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17894 \begin_inset Text
17895
17896 \layout Standard
17897
17898 int speed
17899 \begin_inset Foot
17900 collapsed true
17901
17902 \layout Standard
17903
17904 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
17905  putchar()
17906 \end_inset 
17907
17908 ,
17909 \layout Standard
17910
17911 small / large
17912 \end_inset 
17913 </cell>
17914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17915 \begin_inset Text
17916
17917 \layout Standard
17918
17919 3.01 / 3.61 ms
17920 \end_inset 
17921 </cell>
17922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17923 \begin_inset Text
17924
17925 \layout Standard
17926
17927 3.01 / 3.61 ms
17928 \end_inset 
17929 </cell>
17930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17931 \begin_inset Text
17932
17933 \layout Standard
17934
17935 3.51 / 18.13 ms
17936 \end_inset 
17937 </cell>
17938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17939 \begin_inset Text
17940
17941 \layout Standard
17942
17943 0.22 / 0.22 ms
17944 \end_inset 
17945 </cell>
17946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17947 \begin_inset Text
17948
17949 \layout Standard
17950
17951 0.23 / 0.23 ms
17952 \end_inset 
17953 </cell>
17954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17955 \begin_inset Text
17956
17957 \layout Standard
17958
17959 0.25 / 0.25 ms
17960 \begin_inset Foot
17961 collapsed true
17962
17963 \layout Standard
17964
17965 printf_tiny integer speed is data dependent, worst case is 0.33 ms
17966 \end_inset 
17967
17968
17969 \end_inset 
17970 </cell>
17971 </row>
17972 <row bottomline="true">
17973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17974 \begin_inset Text
17975
17976 \layout Standard
17977
17978 long speed
17979 \begin_inset Foot
17980 collapsed true
17981
17982 \layout Standard
17983
17984 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
17985  empty putchar()
17986 \end_inset 
17987
17988 ,
17989 \layout Standard
17990
17991 small / large
17992 \end_inset 
17993 </cell>
17994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17995 \begin_inset Text
17996
17997 \layout Standard
17998
17999 5.37 / 6.31 ms
18000 \end_inset 
18001 </cell>
18002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18003 \begin_inset Text
18004
18005 \layout Standard
18006
18007 5.37 / 6.31 ms
18008 \end_inset 
18009 </cell>
18010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18011 \begin_inset Text
18012
18013 \layout Standard
18014
18015 8.71 / 40.65 ms
18016 \end_inset 
18017 </cell>
18018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18019 \begin_inset Text
18020
18021 \layout Standard
18022
18023 0.40 / 0.40 ms
18024 \end_inset 
18025 </cell>
18026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18027 \begin_inset Text
18028
18029 \layout Standard
18030
18031 0.40 / 0.40 ms
18032 \end_inset 
18033 </cell>
18034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18035 \begin_inset Text
18036
18037 \layout Standard
18038
18039 -
18040 \end_inset 
18041 </cell>
18042 </row>
18043 <row bottomline="true">
18044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18045 \begin_inset Text
18046
18047 \layout Standard
18048
18049 float speed
18050 \begin_inset Foot
18051 collapsed true
18052
18053 \layout Standard
18054
18055 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
18056  empty putchar()
18057 \end_inset 
18058
18059 ,
18060 \layout Standard
18061
18062 small / large
18063 \end_inset 
18064 </cell>
18065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18066 \begin_inset Text
18067
18068 \layout Standard
18069
18070 -
18071 \end_inset 
18072 </cell>
18073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18074 \begin_inset Text
18075
18076 \layout Standard
18077
18078 7.49 / 22.47 ms
18079 \end_inset 
18080 </cell>
18081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18082 \begin_inset Text
18083
18084 \layout Standard
18085
18086 -
18087 \end_inset 
18088 </cell>
18089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18090 \begin_inset Text
18091
18092 \layout Standard
18093
18094 -
18095 \end_inset 
18096 </cell>
18097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18098 \begin_inset Text
18099
18100 \layout Standard
18101
18102 1.04 / 1.04 ms
18103 \end_inset 
18104 </cell>
18105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18106 \begin_inset Text
18107
18108 \layout Standard
18109
18110 -
18111 \end_inset 
18112 </cell>
18113 </row>
18114 </lyxtabular>
18115
18116 \end_inset 
18117
18118
18119 \layout Subsubsection
18120
18121 <malloc.h>
18122 \begin_inset LatexCommand \index{malloc.h}
18123
18124 \end_inset 
18125
18126
18127 \layout Standard
18128
18129 As of SDCC 2.6.2 you no longer need to call an initialization routine before
18130  using dynamic memory allocation
18131 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
18132
18133 \end_inset 
18134
18135  and a default heap
18136 \begin_inset LatexCommand \index{heap (malloc)}
18137
18138 \end_inset 
18139
18140  space of 1024 bytes is provided for malloc to allocate memory from.
18141  If you need a different heap size you need to recompile _heap.c with the
18142  required size defined in HEAP_SIZE.
18143  It is recommended to make a copy of this file into your project directory
18144  and compile it there with:
18145 \layout Verse
18146
18147
18148 \family typewriter 
18149 sdcc -c _heap.c -D HEAD_SIZE=2048
18150 \layout Standard
18151
18152 And then link it with:
18153 \layout Verse
18154
18155
18156 \family typewriter 
18157 sdcc main.rel _heap.rel
18158 \layout Subsection
18159
18160 Math functions (sinf, powf, sqrtf etc.)
18161 \layout Subsubsection
18162
18163 <math.h>
18164 \layout Standard
18165
18166 See definitions in file <math.h>.
18167 \layout Subsection
18168
18169 Other libraries
18170 \layout Standard
18171
18172 Libraries
18173 \begin_inset LatexCommand \index{Libraries}
18174
18175 \end_inset 
18176
18177  included in SDCC should have a license at least as liberal as the GNU Lesser
18178  General Public License
18179 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
18180
18181 \end_inset 
18182
18183  
18184 \emph on 
18185 LGPL
18186 \emph default 
18187 .
18188 \layout Standard
18189
18190
18191 \begin_inset Note
18192 collapsed true
18193
18194 \layout Standard
18195
18196 license statements for the libraries are missing.
18197  sdcc/device/lib/ser_ir.c
18198 \layout Standard
18199
18200 or _decdptr f.e.
18201  come with a GPL (as opposed to LGPL) License - this will not be liberal
18202  enough for many embedded programmers.
18203 \end_inset 
18204
18205
18206 \layout Standard
18207
18208 If you have ported some library or want to share experience about some code
18209  which f.e.
18210  falls into any of these categories Busses (I
18211 \begin_inset Formula $^{\textrm{2}}$
18212 \end_inset 
18213
18214 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
18215  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
18216  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
18217 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
18218
18219 \end_inset 
18220
18221 \SpecialChar ~
18222 would certainly like to hear about it.
18223 \layout Standard
18224 \added_space_bottom bigskip 
18225 Programmers coding for embedded systems are not especially famous for being
18226  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
18227 e these references are very valuable.
18228  Let's help to create a climate where information is shared.
18229 \layout Section
18230
18231 Memory Models
18232 \layout Subsection
18233
18234 MCS51 Memory Models
18235 \begin_inset LatexCommand \index{Memory model}
18236
18237 \end_inset 
18238
18239
18240 \begin_inset LatexCommand \index{MCS51 memory model}
18241
18242 \end_inset 
18243
18244
18245 \layout Subsubsection
18246
18247 Small, Medium and Large
18248 \layout Standard
18249
18250 SDCC allows three memory models for MCS51 code, 
18251 \shape slanted 
18252 small, medium
18253 \shape default 
18254  and 
18255 \shape slanted 
18256 large
18257 \shape default 
18258 .
18259  Modules compiled with different memory models should 
18260 \emph on 
18261 never
18262 \emph default 
18263  be combined together or the results would be unpredictable.
18264  The library routines supplied with the compiler are compiled as small,
18265  medium and large.
18266  The compiled library modules are contained in separate directories as small,
18267  medium and large so that you can link to the appropriate set.
18268 \layout Standard
18269
18270 When the medium or large model is used all variables declared without a
18271  storage class will be allocated into the external ram, this includes all
18272  parameters and local variables (for non-reentrant
18273 \begin_inset LatexCommand \index{reentrant}
18274
18275 \end_inset 
18276
18277  functions).
18278  When the small model is used variables without storage class are allocated
18279  in the internal ram.
18280 \layout Standard
18281
18282 Judicious usage of the processor specific storage classes
18283 \begin_inset LatexCommand \index{Storage class}
18284
18285 \end_inset 
18286
18287  and the 'reentrant' function type will yield much more efficient code,
18288  than using the large model.
18289  Several optimizations are disabled when the program is compiled using the
18290  large model, it is therefore recommended that the small model be used unless
18291  absolutely required.
18292 \layout Subsubsection
18293
18294 External Stack
18295 \begin_inset LatexCommand \label{sub:External-Stack}
18296
18297 \end_inset 
18298
18299
18300 \begin_inset LatexCommand \index{stack}
18301
18302 \end_inset 
18303
18304
18305 \begin_inset LatexCommand \index{External stack (mcs51)}
18306
18307 \end_inset 
18308
18309
18310 \layout Standard
18311
18312 The external stack (-
18313 \begin_inset ERT
18314 status Collapsed
18315
18316 \layout Standard
18317
18318 \backslash 
18319 /
18320 \end_inset 
18321
18322 -xstack option
18323 \begin_inset LatexCommand \index{-\/-xstack}
18324
18325 \end_inset 
18326
18327 ) is located in pdata
18328 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
18329
18330 \end_inset 
18331
18332  memory (usually at the start of the external ram segment) and uses all
18333  unused space in pdata (max.
18334  256 bytes).
18335  When -
18336 \begin_inset ERT
18337 status Collapsed
18338
18339 \layout Standard
18340
18341 \backslash 
18342 /
18343 \end_inset 
18344
18345 -xstack option is used to compile the program, the parameters and local
18346  variables
18347 \begin_inset LatexCommand \index{local variables}
18348
18349 \end_inset 
18350
18351  of all reentrant functions are allocated in this area.
18352  This option is provided for programs with large stack space requirements.
18353  When used with the -
18354 \begin_inset ERT
18355 status Collapsed
18356
18357 \layout Standard
18358
18359 \backslash 
18360 /
18361 \end_inset 
18362
18363 -stack-auto
18364 \begin_inset LatexCommand \index{-\/-stack-auto}
18365
18366 \end_inset 
18367
18368  option, all parameters and local variables are allocated on the external
18369  stack (note: support libraries will need to be recompiled with the same
18370  options.
18371  There is a predefined target in the library makefile).
18372 \layout Standard
18373
18374 The compiler outputs the higher order address byte of the external ram segment
18375  into port P2
18376 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
18377
18378 \end_inset 
18379
18380  (see also section 
18381 \begin_inset LatexCommand \ref{sub:MCS51-variants}
18382
18383 \end_inset 
18384
18385 ), therefore when using the External Stack option, this port 
18386 \emph on 
18387 may not
18388 \emph default 
18389  be used by the application program.
18390 \layout Subsection
18391
18392 DS390 Memory Model
18393 \begin_inset LatexCommand \index{Memory model}
18394
18395 \end_inset 
18396
18397
18398 \begin_inset LatexCommand \index{DS390 memory model}
18399
18400 \end_inset 
18401
18402
18403 \layout Standard
18404
18405 The only model supported is Flat 24
18406 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
18407
18408 \end_inset 
18409
18410 .
18411  This generates code for the 24 bit contiguous addressing mode of the Dallas
18412  DS80C390 part.
18413  In this mode, up to four meg of external RAM or code space can be directly
18414  addressed.
18415  See the data sheets at www.dalsemi.com for further information on this part.
18416 \newline 
18417
18418 \newline 
18419 Note that the compiler does not generate any code to place the processor
18420  into 24 bitmode (although 
18421 \emph on 
18422 tinibios
18423 \emph default 
18424  in the ds390 libraries will do that for you).
18425  If you don't use 
18426 \emph on 
18427 tinibios
18428 \emph default 
18429
18430 \begin_inset LatexCommand \index{Tinibios (DS390)}
18431
18432 \end_inset 
18433
18434 , the boot loader or similar code must ensure that the processor is in 24
18435  bit contiguous addressing mode before calling the SDCC startup code.
18436 \newline 
18437
18438 \newline 
18439 Like the 
18440 \emph on 
18441 -
18442 \begin_inset ERT
18443 status Collapsed
18444
18445 \layout Standard
18446
18447 \backslash 
18448 /
18449 \end_inset 
18450
18451 -model-large
18452 \emph default 
18453  option, variables will by default be placed into the XDATA segment.
18454  
18455 \newline 
18456
18457 \newline 
18458 Segments may be placed anywhere in the 4 meg address space using the usual
18459  -
18460 \begin_inset ERT
18461 status Collapsed
18462
18463 \layout Standard
18464
18465 \backslash 
18466 /
18467 \end_inset 
18468
18469 -*-loc options.
18470  Note that if any segments are located above 64K, the -r flag must be passed
18471  to the linker to generate the proper segment relocations, and the Intel
18472  HEX output format must be used.
18473  The -r flag can be passed to the linker by using the option 
18474 \emph on 
18475 -Wl-r
18476 \emph default 
18477  on the SDCC command line.
18478  However, currently the linker can not handle code segments > 64k.
18479 \layout Section
18480
18481 Pragmas
18482 \begin_inset LatexCommand \label{sec:Pragmas}
18483
18484 \end_inset 
18485
18486
18487 \begin_inset LatexCommand \index{Pragmas}
18488
18489 \end_inset 
18490
18491
18492 \layout Standard
18493
18494 SDCC supports the following #pragma directives:
18495 \layout Itemize
18496
18497
18498 \series bold 
18499 save
18500 \series default 
18501
18502 \begin_inset LatexCommand \index{\#pragma save}
18503
18504 \end_inset 
18505
18506  - this will save most current options to the save/restore stack.
18507  See #pragma\SpecialChar ~
18508 restore.
18509 \layout Itemize
18510
18511
18512 \series bold 
18513 restore
18514 \series default 
18515
18516 \begin_inset LatexCommand \index{\#pragma restore}
18517
18518 \end_inset 
18519
18520  - will restore saved options from the last save.
18521  saves & restores can be nested.
18522  SDCC uses a save/restore stack: save pushes current options to the stack,
18523  restore pulls current options from the stack.
18524  See #pragma\SpecialChar ~
18525 save.
18526 \newline 
18527
18528 \layout Itemize
18529
18530
18531 \series bold 
18532 callee_saves
18533 \series default 
18534
18535 \begin_inset LatexCommand \index{\#pragma callee\_saves}
18536
18537 \end_inset 
18538
18539
18540 \begin_inset LatexCommand \index{function prologue}
18541
18542 \end_inset 
18543
18544  function1[,function2[,function3...]] - The compiler by default uses a caller
18545  saves convention for register saving across function calls, however this
18546  can cause unnecessary register pushing & popping
18547 \begin_inset LatexCommand \index{push/pop}
18548
18549 \end_inset 
18550
18551  when calling small functions from larger functions.
18552  This option can be used to switch off the register saving convention for
18553  the function names specified.
18554  The compiler will not save registers when calling these functions, extra
18555  code need to be manually inserted at the entry & exit for these functions
18556  to save & restore the registers used by these functions, this can SUBSTANTIALLY
18557  reduce code & improve run time performance of the generated code.
18558  In the future the compiler (with inter procedural analysis) may be able
18559  to determine the appropriate scheme to use for each function call.
18560  If -
18561 \begin_inset ERT
18562 status Collapsed
18563
18564 \layout Standard
18565
18566 \backslash 
18567 /
18568 \end_inset 
18569
18570 -callee-saves command line option is used, the function names specified
18571  in #pragma\SpecialChar ~
18572 callee_saves
18573 \begin_inset LatexCommand \index{\#pragma callee\_saves}
18574
18575 \end_inset 
18576
18577  is appended to the list of functions specified in the command line.
18578 \layout Itemize
18579
18580
18581 \series bold 
18582 exclude
18583 \series default 
18584
18585 \begin_inset LatexCommand \index{\#pragma exclude}
18586
18587 \end_inset 
18588
18589  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
18590  of pairs of push/pop
18591 \begin_inset LatexCommand \index{push/pop}
18592
18593 \end_inset 
18594
18595  instructions in 
18596 \emph on 
18597 I
18598 \emph default 
18599 nterrupt
18600 \begin_inset LatexCommand \index{interrupt}
18601
18602 \end_inset 
18603
18604  
18605 \emph on 
18606 S
18607 \emph default 
18608 ervice 
18609 \emph on 
18610 R
18611 \emph default 
18612 outines.
18613  The directive should be placed immediately before the ISR function definition
18614  and it affects ALL ISR functions following it.
18615  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
18616 exclude\SpecialChar ~
18617 none
18618 \begin_inset LatexCommand \index{\#pragma exclude}
18619
18620 \end_inset 
18621
18622 .
18623  See also the related keyword _naked
18624 \begin_inset LatexCommand \index{\_naked}
18625
18626 \end_inset 
18627
18628
18629 \begin_inset LatexCommand \index{\_\_naked}
18630
18631 \end_inset 
18632
18633 .
18634 \layout Itemize
18635
18636
18637 \series bold 
18638 less_pedantic
18639 \series default 
18640
18641 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
18642
18643 \end_inset 
18644
18645  - the compiler will not warn you anymore for obvious mistakes, you'r on
18646  your own now ;-(
18647 \layout Itemize
18648
18649
18650 \series bold 
18651 disable_warning
18652 \series default 
18653  <nnnn>
18654 \begin_inset LatexCommand \index{\#pragma disable\_warning}
18655
18656 \end_inset 
18657
18658  - the compiler will not warn you anymore about warning number <nnnn>.
18659 \layout Itemize
18660
18661
18662 \series bold 
18663 nogcse
18664 \series default 
18665
18666 \begin_inset LatexCommand \index{\#pragma nogcse}
18667
18668 \end_inset 
18669
18670  - will stop global common subexpression elimination.
18671 \layout Itemize
18672
18673
18674 \series bold 
18675 noinduction
18676 \series default 
18677
18678 \begin_inset LatexCommand \index{\#pragma noinduction}
18679
18680 \end_inset 
18681
18682  - will stop loop induction optimizations.
18683 \layout Itemize
18684
18685
18686 \series bold 
18687 noinvariant
18688 \series default 
18689
18690 \begin_inset LatexCommand \index{\#pragma noinvariant}
18691
18692 \end_inset 
18693
18694  - will not do loop invariant optimizations.
18695  For more details see Loop Invariants in section
18696 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
18697
18698 \end_inset 
18699
18700 .
18701 \layout Itemize
18702
18703
18704 \series bold 
18705 noiv
18706 \series default 
18707
18708 \begin_inset LatexCommand \index{\#pragma noiv}
18709
18710 \end_inset 
18711
18712  - Do not generate interrupt
18713 \begin_inset LatexCommand \index{interrupt}
18714
18715 \end_inset 
18716
18717  vector table
18718 \begin_inset LatexCommand \index{interrupt vector table}
18719
18720 \end_inset 
18721
18722  entries for all ISR functions defined after the pragma.
18723  This is useful in cases where the interrupt vector table must be defined
18724  manually, or when there is a secondary, manually defined interrupt vector
18725  table (e.g.
18726  for the autovector feature of the Cypress EZ-USB FX2).
18727  More elegantly this can be achieved by obmitting the optional interrupt
18728  number after the interrupt keyword, see section 
18729 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
18730
18731 \end_inset 
18732
18733 \SpecialChar ~
18734 about interrupts.
18735 \layout Itemize
18736
18737
18738 \series bold 
18739 nojtbound
18740 \series default 
18741
18742 \begin_inset LatexCommand \index{\#pragma nojtbound}
18743
18744 \end_inset 
18745
18746  - will not generate code for boundary value checking, when switch statements
18747  are turned into jump-tables (dangerous).
18748  For more details see section 
18749 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
18750
18751 \end_inset 
18752
18753 .
18754 \layout Itemize
18755
18756
18757 \series bold 
18758 noloopreverse
18759 \series default 
18760
18761 \begin_inset LatexCommand \index{\#pragma noloopreverse}
18762
18763 \end_inset 
18764
18765  - Will not do loop reversal optimization
18766 \layout Itemize
18767
18768
18769 \series bold 
18770 nooverlay
18771 \series default 
18772
18773 \begin_inset LatexCommand \index{\#pragma nooverlay}
18774
18775 \end_inset 
18776
18777  - the compiler will not overlay the parameters and local variables of a
18778  function.
18779 \layout Itemize
18780
18781
18782 \series bold 
18783 stackauto
18784 \series default 
18785
18786 \begin_inset LatexCommand \index{\#pragma stackauto}
18787
18788 \end_inset 
18789
18790 - See option -
18791 \begin_inset ERT
18792 status Collapsed
18793
18794 \layout Standard
18795
18796 \backslash 
18797 /
18798 \end_inset 
18799
18800 -stack-auto
18801 \begin_inset LatexCommand \index{-\/-stack-auto}
18802
18803 \end_inset 
18804
18805  and section 
18806 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
18807
18808 \end_inset 
18809
18810  Parameters and Local Variables.
18811 \layout Itemize
18812
18813
18814 \series bold 
18815 opt_code_speed
18816 \series default 
18817  
18818 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
18819
18820 \end_inset 
18821
18822 - The compiler will optimize code generation towards fast code, possibly
18823  at the expense of code size.
18824  Currently this has little effect.
18825 \layout Itemize
18826
18827
18828 \series bold 
18829 opt_code_size
18830 \series default 
18831  
18832 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
18833
18834 \end_inset 
18835
18836 - The compiler will optimize code generation towards compact code, possibly
18837  at the expense of code speed.
18838  Currently this has little effect.
18839 \layout Itemize
18840
18841
18842 \series bold 
18843 opt_code_balanced
18844 \series default 
18845  
18846 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
18847
18848 \end_inset 
18849
18850 - The compiler will attempt to generate code that is both compact and fast,
18851  as long as meeting one goal is not a detriment to the other (this is the
18852  default).
18853  
18854 \layout Itemize
18855
18856
18857 \series bold 
18858 std_sdcc89
18859 \series default 
18860  
18861 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
18862
18863 \end_inset 
18864
18865 - Generally follow the C89 standard, but allow SDCC features that conflict
18866  with the standard (default).
18867 \layout Itemize
18868
18869
18870 \series bold 
18871 std_c89
18872 \series default 
18873  
18874 \begin_inset LatexCommand \index{\#pragma std\_c89}
18875
18876 \end_inset 
18877
18878 - Follow the C89 standard and disable SDCC features that conflict with the
18879  standard.
18880 \layout Itemize
18881
18882
18883 \series bold 
18884 std_sdcc99
18885 \series default 
18886  
18887 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
18888
18889 \end_inset 
18890
18891 - Generally follow the C99 standard, but allow SDCC features that conflict
18892  with the standard (incomplete support).
18893 \layout Itemize
18894
18895
18896 \series bold 
18897 std_c99
18898 \series default 
18899  
18900 \begin_inset LatexCommand \index{\#pragma std\_c99}
18901
18902 \end_inset 
18903
18904 - Follow the C99 standard and disable SDCC features that conflict with the
18905  standard (incomplete support).
18906 \layout Itemize
18907
18908
18909 \series bold 
18910 codeseg
18911 \series default 
18912  <name>
18913 \begin_inset LatexCommand \index{\#pragma codeseg}
18914
18915 \end_inset 
18916
18917 - Use this name (max.
18918  8 characters) for the code segment.
18919  See option -
18920 \begin_inset ERT
18921 status Collapsed
18922
18923 \layout Standard
18924
18925 \backslash 
18926 /
18927 \end_inset 
18928
18929 -codeseg.
18930 \layout Itemize
18931
18932
18933 \series bold 
18934 constseg
18935 \series default 
18936  <name>
18937 \begin_inset LatexCommand \index{\#pragma constseg}
18938
18939 \end_inset 
18940
18941 - Use this name (max.
18942  8 characters) for the const segment.
18943  See option -
18944 \begin_inset ERT
18945 status Collapsed
18946
18947 \layout Standard
18948
18949 \backslash 
18950 /
18951 \end_inset 
18952
18953 -constseg.
18954 \layout Standard
18955
18956 The preprocessor SDCPP
18957 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
18958
18959 \end_inset 
18960
18961  supports the following #pragma directives:
18962 \layout Itemize
18963
18964
18965 \series bold 
18966 pedantic_parse_number
18967 \series default 
18968
18969 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
18970
18971 \end_inset 
18972
18973  (+ | -) - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are
18974  parsed properly and the macro LO_B(3) gets expanded.
18975  Default is off.
18976  Below is an example on how to use this pragma.
18977
18978 \emph on 
18979  Note: this functionality is not in conformance with standard!
18980 \layout Verse
18981
18982
18983 \family typewriter 
18984 #pragma pedantic_parse_number +
18985 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
18986
18987 \end_inset 
18988
18989
18990 \newline 
18991
18992 \newline 
18993 #define LO_B(x) ((x) & 0xff)
18994 \newline 
18995
18996 \newline 
18997 unsigned char foo(void)
18998 \newline 
18999 {
19000 \newline 
19001 \SpecialChar ~
19002 \SpecialChar ~
19003 \SpecialChar ~
19004 unsigned char c=0xfe-LO_B(3);
19005 \newline 
19006
19007 \newline 
19008 \SpecialChar ~
19009 \SpecialChar ~
19010 \SpecialChar ~
19011 return c;
19012 \newline 
19013 }
19014 \newline 
19015
19016 \layout Itemize
19017
19018
19019 \series bold 
19020 preproc_asm
19021 \series default 
19022
19023 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
19024
19025 \end_inset 
19026
19027  (+ | -) - switch _asm _endasm block preprocessing on / off.
19028  Default is on.
19029  You use this prama to define multilines of assembly code.
19030  This will prevent the preprocessor from changing the formating required
19031  by assembly code.
19032  Below is an example on how to use this pragma.
19033 \layout Verse
19034
19035
19036 \family typewriter 
19037 #pragma preproc_asm -
19038 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
19039
19040 \end_inset 
19041
19042
19043 \newline 
19044 #define MYDELAY _asm
19045 \newline 
19046 \SpecialChar ~
19047 \SpecialChar ~
19048 \SpecialChar ~
19049 nop ;my assembly comment...
19050 \newline 
19051 \SpecialChar ~
19052 \SpecialChar ~
19053 \SpecialChar ~
19054 nop
19055 \newline 
19056 \SpecialChar ~
19057 \SpecialChar ~
19058 \SpecialChar ~
19059 nop
19060 \newline 
19061 _endasm
19062 \newline 
19063 #pragma preproc_asm +
19064 \newline 
19065
19066 \newline 
19067 void foo (void) 
19068 \newline 
19069
19070 \newline 
19071 \SpecialChar ~
19072 \SpecialChar ~
19073 \SpecialChar ~
19074  ...
19075  
19076 \newline 
19077 \SpecialChar ~
19078 \SpecialChar ~
19079 \SpecialChar ~
19080  MYDELAY;
19081 \newline 
19082 \SpecialChar ~
19083 \SpecialChar ~
19084 \SpecialChar ~
19085  ...
19086  
19087 \newline 
19088
19089 \newline 
19090
19091 \layout Itemize
19092
19093
19094 \series bold 
19095 sdcc_hash
19096 \series default 
19097
19098 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
19099
19100 \end_inset 
19101
19102  (+ | -) - Allow "naked" hash in macro definition, for example:
19103 \newline 
19104
19105 \family typewriter 
19106 #define DIR_LO(x) #(x & 0xff)
19107 \family default 
19108
19109 \newline 
19110 Default is off.
19111  Below is an example on how to use this pragma.
19112 \layout Verse
19113
19114
19115 \family typewriter 
19116 #pragma preproc_asm +
19117 \newline 
19118 #pragma sdcc_hash +
19119 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
19120
19121 \end_inset 
19122
19123
19124 \newline 
19125
19126 \newline 
19127 #define ROMCALL(x) 
19128 \backslash 
19129
19130 \newline 
19131 \SpecialChar ~
19132 \SpecialChar ~
19133 \SpecialChar ~
19134 mov R6_B3, #(x & 0xff) 
19135 \backslash 
19136
19137 \newline 
19138 \SpecialChar ~
19139 \SpecialChar ~
19140 \SpecialChar ~
19141 mov R7_B3, #((x >> 8) & 0xff) 
19142 \backslash 
19143
19144 \newline 
19145 \SpecialChar ~
19146 \SpecialChar ~
19147 \SpecialChar ~
19148 lcall __romcall
19149 \newline 
19150
19151 \newline 
19152 ...
19153 \newline 
19154 _asm
19155 \newline 
19156 ROMCALL(72)
19157 \newline 
19158 _endasm;
19159 \newline 
19160 ...
19161 \newline 
19162
19163 \layout Standard
19164
19165 The pragma's are intended to be used to turn-on or off certain optimizations
19166  which might cause the compiler to generate extra stack / data space to
19167  store compiler generated temporary variables.
19168  This usually happens in large functions.
19169  Pragma directives should be used as shown in the following example, they
19170  are used to control options & optimizations for a given function; pragmas
19171  should be placed before and/or after a function, placing pragma's inside
19172  a function body could have unpredictable results.
19173 \layout Verse
19174
19175
19176 \family typewriter 
19177 #pragma save
19178 \begin_inset LatexCommand \index{\#pragma save}
19179
19180 \end_inset 
19181
19182  \SpecialChar ~
19183 \SpecialChar ~
19184 \SpecialChar ~
19185 \SpecialChar ~
19186 \SpecialChar ~
19187 \SpecialChar ~
19188 \SpecialChar ~
19189 /* save the current settings */ 
19190 \newline 
19191 #pragma nogcse
19192 \begin_inset LatexCommand \index{\#pragma nogcse}
19193
19194 \end_inset 
19195
19196  \SpecialChar ~
19197 \SpecialChar ~
19198 \SpecialChar ~
19199 \SpecialChar ~
19200 \SpecialChar ~
19201 /* turnoff global subexpression elimination */ 
19202 \newline 
19203 #pragma noinduction
19204 \begin_inset LatexCommand \index{\#pragma noinduction}
19205
19206 \end_inset 
19207
19208  /* turn off induction optimizations */ 
19209 \newline 
19210 int foo () 
19211 \newline 
19212
19213 \newline 
19214 \SpecialChar ~
19215  \SpecialChar ~
19216  ...
19217  
19218 \newline 
19219 \SpecialChar ~
19220  \SpecialChar ~
19221  /* large code */ 
19222 \newline 
19223 \SpecialChar ~
19224  \SpecialChar ~
19225  ...
19226  
19227 \newline 
19228
19229 \newline 
19230 #pragma restore
19231 \begin_inset LatexCommand \index{\#pragma restore}
19232
19233 \end_inset 
19234
19235  /* turn the optimizations back on */
19236 \layout Standard
19237
19238 The compiler will generate a warning message when extra space is allocated.
19239  It is strongly recommended that the save and restore pragma's be used when
19240  changing options for a function.
19241 \newline 
19242
19243 \newline 
19244
19245 \newline 
19246
19247 \layout Section
19248
19249 Defines Created by the Compiler
19250 \layout Standard
19251
19252 The compiler creates the following #defines
19253 \begin_inset LatexCommand \index{\#defines}
19254
19255 \end_inset 
19256
19257
19258 \begin_inset LatexCommand \index{Defines created by the compiler}
19259
19260 \end_inset 
19261
19262 :
19263 \newline 
19264
19265 \layout Standard
19266
19267
19268 \begin_inset  Tabular
19269 <lyxtabular version="3" rows="11" columns="2">
19270 <features>
19271 <column alignment="left" valignment="top" leftline="true" width="3in">
19272 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
19273 <row topline="true" bottomline="true">
19274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19275 \begin_inset Text
19276
19277 \layout Standard
19278
19279
19280 \series bold 
19281 #define
19282 \end_inset 
19283 </cell>
19284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19285 \begin_inset Text
19286
19287 \layout Standard
19288
19289
19290 \series bold 
19291 Description
19292 \end_inset 
19293 </cell>
19294 </row>
19295 <row topline="true">
19296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19297 \begin_inset Text
19298
19299 \layout Standard
19300
19301 SDCC
19302 \begin_inset LatexCommand \index{SDCC}
19303
19304 \end_inset 
19305
19306  
19307 \end_inset 
19308 </cell>
19309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19310 \begin_inset Text
19311
19312 \layout Standard
19313
19314 Always defined.
19315  Since version 2.5.6 the version number as an int (ex.
19316  256)
19317 \end_inset 
19318 </cell>
19319 </row>
19320 <row topline="true">
19321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19322 \begin_inset Text
19323
19324 \layout Standard
19325
19326 SDCC_mcs51
19327 \begin_inset LatexCommand \index{SDCC\_mcs51}
19328
19329 \end_inset 
19330
19331  or SDCC_ds390
19332 \begin_inset LatexCommand \index{SDCC\_ds390}
19333
19334 \end_inset 
19335
19336  or SDCC_z80
19337 \begin_inset LatexCommand \index{SDCC\_z80}
19338
19339 \end_inset 
19340
19341 , etc.
19342 \end_inset 
19343 </cell>
19344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19345 \begin_inset Text
19346
19347 \layout Standard
19348
19349 depending on the model used (e.g.: -mds390)
19350 \end_inset 
19351 </cell>
19352 </row>
19353 <row topline="true">
19354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19355 \begin_inset Text
19356
19357 \layout Standard
19358
19359 __mcs51
19360 \begin_inset LatexCommand \index{\_\_mcs51}
19361
19362 \end_inset 
19363
19364 , __ds390
19365 \begin_inset LatexCommand \index{\_\_ds390}
19366
19367 \end_inset 
19368
19369 , __hc08
19370 \begin_inset LatexCommand \index{\_\_hc08}
19371
19372 \end_inset 
19373
19374 , __z80
19375 \begin_inset LatexCommand \index{\_\_z80}
19376
19377 \end_inset 
19378
19379 , etc
19380 \end_inset 
19381 </cell>
19382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19383 \begin_inset Text
19384
19385 \layout Standard
19386
19387 depending on the model used (e.g.
19388  -mz80)
19389 \end_inset 
19390 </cell>
19391 </row>
19392 <row topline="true">
19393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19394 \begin_inset Text
19395
19396 \layout Standard
19397
19398 SDCC_STACK_AUTO
19399 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
19400
19401 \end_inset 
19402
19403
19404 \end_inset 
19405 </cell>
19406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19407 \begin_inset Text
19408
19409 \layout Standard
19410
19411 when 
19412 \emph on 
19413 -
19414 \begin_inset ERT
19415 status Collapsed
19416
19417 \layout Standard
19418
19419 \backslash 
19420 /
19421 \end_inset 
19422
19423 -stack-auto
19424 \emph default 
19425  option is used
19426 \end_inset 
19427 </cell>
19428 </row>
19429 <row topline="true">
19430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19431 \begin_inset Text
19432
19433 \layout Standard
19434
19435 SDCC_MODEL_SMALL
19436 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
19437
19438 \end_inset 
19439
19440
19441 \end_inset 
19442 </cell>
19443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19444 \begin_inset Text
19445
19446 \layout Standard
19447
19448 when 
19449 \emph on 
19450 -
19451 \begin_inset ERT
19452 status Collapsed
19453
19454 \layout Standard
19455
19456 \backslash 
19457 /
19458 \end_inset 
19459
19460 -model-small
19461 \emph default 
19462  is used
19463 \end_inset 
19464 </cell>
19465 </row>
19466 <row topline="true">
19467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19468 \begin_inset Text
19469
19470 \layout Standard
19471
19472 SDCC_MODEL_MEDIUM
19473 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
19474
19475 \end_inset 
19476
19477
19478 \end_inset 
19479 </cell>
19480 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19481 \begin_inset Text
19482
19483 \layout Standard
19484
19485 when 
19486 \emph on 
19487 -
19488 \begin_inset ERT
19489 status Collapsed
19490
19491 \layout Standard
19492
19493 \backslash 
19494 /
19495 \end_inset 
19496
19497 -model-medium
19498 \emph default 
19499  is used
19500 \end_inset 
19501 </cell>
19502 </row>
19503 <row topline="true">
19504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19505 \begin_inset Text
19506
19507 \layout Standard
19508
19509 SDCC_MODEL_LARGE
19510 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
19511
19512 \end_inset 
19513
19514
19515 \end_inset 
19516 </cell>
19517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19518 \begin_inset Text
19519
19520 \layout Standard
19521
19522 when 
19523 \emph on 
19524 -
19525 \begin_inset ERT
19526 status Collapsed
19527
19528 \layout Standard
19529
19530 \backslash 
19531 /
19532 \end_inset 
19533
19534 -model-large
19535 \emph default 
19536  is used
19537 \end_inset 
19538 </cell>
19539 </row>
19540 <row topline="true">
19541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19542 \begin_inset Text
19543
19544 \layout Standard
19545
19546 SDCC_USE_XSTACK
19547 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
19548
19549 \end_inset 
19550
19551
19552 \end_inset 
19553 </cell>
19554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19555 \begin_inset Text
19556
19557 \layout Standard
19558
19559 when 
19560 \emph on 
19561 -
19562 \begin_inset ERT
19563 status Collapsed
19564
19565 \layout Standard
19566
19567 \backslash 
19568 /
19569 \end_inset 
19570
19571 -xstack
19572 \emph default 
19573  option is used
19574 \end_inset 
19575 </cell>
19576 </row>
19577 <row topline="true">
19578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19579 \begin_inset Text
19580
19581 \layout Standard
19582
19583 SDCC_STACK_TENBIT
19584 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
19585
19586 \end_inset 
19587
19588  
19589 \end_inset 
19590 </cell>
19591 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19592 \begin_inset Text
19593
19594 \layout Standard
19595
19596 when 
19597 \emph on 
19598 -mds390
19599 \emph default 
19600  is used
19601 \end_inset 
19602 </cell>
19603 </row>
19604 <row topline="true" bottomline="true">
19605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19606 \begin_inset Text
19607
19608 \layout Standard
19609
19610 SDCC_MODEL_FLAT24
19611 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
19612
19613 \end_inset 
19614
19615
19616 \end_inset 
19617 </cell>
19618 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19619 \begin_inset Text
19620
19621 \layout Standard
19622
19623 when 
19624 \emph on 
19625 -mds390
19626 \emph default 
19627  is used
19628 \end_inset 
19629 </cell>
19630 </row>
19631 </lyxtabular>
19632
19633 \end_inset 
19634
19635
19636 \layout Chapter
19637
19638 Notes on supported Processors
19639 \layout Section
19640
19641 MCS51 variants
19642 \begin_inset LatexCommand \label{sub:MCS51-variants}
19643
19644 \end_inset 
19645
19646
19647 \begin_inset LatexCommand \index{MCS51 variants}
19648
19649 \end_inset 
19650
19651
19652 \layout Standard
19653
19654 MCS51 processors are available from many vendors and come in many different
19655  flavours.
19656  While they might differ considerably in respect to Special Function Registers
19657  the core MCS51 is usually not modified or is kept compatible.
19658  
19659 \layout Subsection
19660
19661 pdata access by SFR 
19662 \layout Standard
19663
19664 With the upcome of devices with internal xdata and flash memory devices
19665  using port P2
19666 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
19667
19668 \end_inset 
19669
19670  as dedicated I/O port is becoming more popular.
19671  Switching the high byte for pdata
19672 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
19673
19674 \end_inset 
19675
19676  access which was formerly done by port P2 is then achieved by a Special
19677  Function Register
19678 \begin_inset LatexCommand \index{sfr}
19679
19680 \end_inset 
19681
19682 .
19683  In well-established MCS51 tradition the address of this 
19684 \emph on 
19685 sfr
19686 \emph default 
19687  is where the chip designers decided to put it.
19688  Needless to say that they didn't agree on a common name either.
19689  So that the startup code can correctly initialize xdata variables, you
19690  should define an sfr with the name _XPAGE
19691 \family typewriter 
19692
19693 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
19694
19695 \end_inset 
19696
19697
19698 \family default 
19699  at the appropriate location if the default, port P2, is not used for this.
19700  Some examples are:
19701 \layout Verse
19702
19703
19704 \family typewriter 
19705 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
19706  MPAGE */
19707 \layout Verse
19708
19709
19710 \family typewriter 
19711 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
19712  a.k.a.
19713  MPAGE */
19714 \layout Verse
19715
19716
19717 \family typewriter 
19718 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
19719  XPAGE */
19720 \layout Verse
19721
19722
19723 \family typewriter 
19724 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
19725  EMI0CN */
19726 \layout Verse
19727
19728
19729 \family typewriter 
19730 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
19731  EMI0CN */
19732 \layout Standard
19733
19734 For more exotic implementations further customizations may be needed.
19735  See section 
19736 \begin_inset LatexCommand \ref{sub:Startup-Code}
19737
19738 \end_inset 
19739
19740  for other possibilities.
19741 \layout Subsection
19742
19743 Other Features available by SFR
19744 \layout Standard
19745 \added_space_bottom bigskip 
19746 Some MCS51 variants offer features like Double DPTR
19747 \begin_inset LatexCommand \index{DPTR}
19748
19749 \end_inset 
19750
19751 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
19752  These are currently not used for the MCS51 port.
19753  If you absolutely need them you can fall back to inline assembly or submit
19754  a patch to SDCC.
19755 \layout Section
19756
19757 DS400 port
19758 \layout Standard
19759 \added_space_bottom bigskip 
19760 The DS80C400
19761 \begin_inset LatexCommand \index{DS80C400}
19762
19763 \end_inset 
19764
19765
19766 \begin_inset LatexCommand \index{DS400}
19767
19768 \end_inset 
19769
19770  microcontroller has a rich set of peripherals.
19771  In its built-in ROM library it includes functions to access some of the
19772  features, among them is a TCP stack with IP4 and IP6 support.
19773  Library headers (currently in beta status) and other files are provided
19774  at 
19775 \size footnotesize 
19776
19777 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
19778
19779 \end_inset 
19780
19781 .
19782  
19783 \layout Section
19784
19785 The Z80 and gbz80 port
19786 \layout Standard
19787
19788 SDCC can target both the Zilog Z80
19789 \begin_inset LatexCommand \index{Z80}
19790
19791 \end_inset 
19792
19793  and the Nintendo Gameboy's Z80-like gbz80
19794 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
19795
19796 \end_inset 
19797
19798 .
19799  The Z80 port is passed through the same 
19800 \emph on 
19801 regressions tests
19802 \begin_inset LatexCommand \index{Regression test}
19803
19804 \end_inset 
19805
19806
19807 \emph default 
19808  (see section 
19809 \begin_inset LatexCommand \ref{sec:Quality-control}
19810
19811 \end_inset 
19812
19813 ) as the MCS51 and DS390 ports, so floating point support, support for long
19814  variables and bitfield support is fine.
19815  See mailing lists and forums about interrupt routines.
19816 \layout Standard
19817 \added_space_bottom bigskip 
19818 As always, the code is the authoritative reference - see z80/ralloc.c and
19819  z80/gen.c.
19820  The stack
19821 \begin_inset LatexCommand \index{Z80!stack}
19822
19823 \end_inset 
19824
19825  frame is similar to that generated by the IAR Z80 compiler.
19826  IX is used as the base pointer, HL and IY are used as a temporary registers,
19827  and BC and DE are available for holding variables.
19828  Return values
19829 \begin_inset LatexCommand \index{Z80!return value}
19830
19831 \end_inset 
19832
19833  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
19834  bytes).
19835  The gbz80 port use the same set of registers for the return values, but
19836  in a different order of significance: E (one byte), DE (two bytes), or
19837  HLDE (four bytes).
19838 \layout Section
19839
19840 The HC08 port
19841 \layout Standard
19842
19843 The port to the Freescale/Motorola HC08
19844 \begin_inset LatexCommand \index{HC08}
19845
19846 \end_inset 
19847
19848  family has been added in October 2003, and is still undergoing some basic
19849  development.
19850  The code generator is complete, but the register allocation is still quite
19851  unoptimized.
19852  Some of the SDCC's standard C library functions have embedded non-HC08
19853  inline assembly and so are not yet usable.
19854 \layout Standard
19855 \added_space_bottom bigskip \pagebreak_bottom 
19856 The HC08 port passes the regression test suite (see section 
19857 \begin_inset LatexCommand \ref{sec:Quality-control}
19858
19859 \end_inset 
19860
19861 ).
19862 \layout Section
19863
19864 The PIC14 port
19865 \layout Standard
19866
19867 The 14bit PIC
19868 \begin_inset LatexCommand \index{PIC14}
19869
19870 \end_inset 
19871
19872  port still requires a major effort from the development community.
19873  However it can work for simple code.
19874  It passes its (smaller set of) regression tests
19875 \begin_inset LatexCommand \index{Regression test (PIC14)}
19876
19877 \end_inset 
19878
19879  in the directory 
19880 \shape italic 
19881 sdcc/src/regression
19882 \shape default 
19883 .
19884 \layout Subsection
19885
19886 C code and 14bit PIC code page
19887 \begin_inset LatexCommand \index{code page (pic14)}
19888
19889 \end_inset 
19890
19891  and RAM banks
19892 \begin_inset LatexCommand \index{RAM bank (pic14)}
19893
19894 \end_inset 
19895
19896
19897 \layout Standard
19898
19899 The linker organizes allocation for the code page and RAM banks.
19900  It does not have intimate knowledge of the code flow.
19901  It will put all the code section of a single asm file into a single code
19902  page.
19903  In order to make use of multiple code pages, separate asm files must be
19904  used.
19905  The compiler treats all functions of a single C file as being in the same
19906  code page unless it is non static.
19907 \newline 
19908
19909 \newline 
19910 To get the best follow these guide lines:
19911 \layout Enumerate
19912
19913 Make local functions static, as non static functions require code page selection
19914  overhead.
19915 \layout Enumerate
19916
19917 For devices that have multiple code pages it is more efficient to use the
19918  same number of files as pages, i.e.
19919  for the 16F877 use 4 separate files and i.e.
19920  for the 16F874 use 2 separate files.
19921  This way the linker can put the code for each file into different code
19922  pages and there's less page selection overhead.
19923 \layout Enumerate
19924
19925 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
19926  instruction set), use 'unsigned char' whereever possible instead of 'int'.
19927 \layout Subsection
19928
19929 Creating a device include file 
19930 \layout Standard
19931
19932 For generating a device include file
19933 \begin_inset LatexCommand \index{PIC14!Header files}
19934
19935 \end_inset 
19936
19937  use the support perl script inc2h.pl kept in directory support/script.
19938 \layout Subsection
19939
19940 Interrupt code
19941 \layout Standard
19942
19943 For the interrupt function, use the keyword '__interrupt'
19944 \begin_inset LatexCommand \index{PIC14!interrupt}
19945
19946 \end_inset 
19947
19948  with level number of 0 (PIC14 only has 1 interrupt so this number is only
19949  there to avoid a syntax error - it ought to be fixed).
19950  E.g.:
19951 \layout Verse
19952
19953
19954 \family typewriter 
19955 void Intr(void) __interrupt 0
19956 \newline 
19957 {
19958 \newline 
19959 \SpecialChar ~
19960 \SpecialChar ~
19961 T0IF = 0; /* Clear timer interrupt */
19962 \newline 
19963 }
19964 \layout Subsection
19965
19966 Linking and assembling
19967 \layout Standard
19968
19969 For assembling you can use either GPUTILS'
19970 \begin_inset LatexCommand \index{gputils (pic tools)}
19971
19972 \end_inset 
19973
19974  gpasm.exe or MPLAB's mpasmwin.exe.
19975  GPUTILS is available from 
19976 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
19977
19978 \end_inset 
19979
19980 .
19981  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
19982  If you use MPLAB and an interrupt function then the linker script file
19983  vectors section will need to be enlarged to link with mplink.
19984 \newline 
19985
19986 \newline 
19987 Here is a 
19988 \family typewriter 
19989 Makefile
19990 \family default 
19991  using GPUTILS:
19992 \layout Verse
19993
19994
19995 \family typewriter 
19996 .c.o:
19997 \newline 
19998 \SpecialChar ~
19999 \SpecialChar ~
20000 \SpecialChar ~
20001 \SpecialChar ~
20002 \SpecialChar ~
20003 \SpecialChar ~
20004 \SpecialChar ~
20005 \SpecialChar ~
20006 sdcc -S -V -mpic14 -p16F877 $< 
20007 \newline 
20008 \SpecialChar ~
20009 \SpecialChar ~
20010 \SpecialChar ~
20011 \SpecialChar ~
20012 \SpecialChar ~
20013 \SpecialChar ~
20014 \SpecialChar ~
20015 \SpecialChar ~
20016 gpasm -c $*.asm
20017 \newline 
20018
20019 \newline 
20020 $(PRJ).hex: $(OBJS) 
20021 \newline 
20022 \SpecialChar ~
20023 \SpecialChar ~
20024 \SpecialChar ~
20025 \SpecialChar ~
20026 \SpecialChar ~
20027 \SpecialChar ~
20028 \SpecialChar ~
20029 \SpecialChar ~
20030 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
20031 \layout Standard
20032
20033 Here is a 
20034 \family typewriter 
20035 Makefile
20036 \family default 
20037  using MPLAB:
20038 \layout Verse
20039
20040
20041 \family typewriter 
20042 .c.o: 
20043 \newline 
20044 \SpecialChar ~
20045 \SpecialChar ~
20046 \SpecialChar ~
20047 \SpecialChar ~
20048 \SpecialChar ~
20049 \SpecialChar ~
20050 \SpecialChar ~
20051 \SpecialChar ~
20052 sdcc -S -V -mpic14 -p16F877 $< 
20053 \newline 
20054 \SpecialChar ~
20055 \SpecialChar ~
20056 \SpecialChar ~
20057 \SpecialChar ~
20058 \SpecialChar ~
20059 \SpecialChar ~
20060 \SpecialChar ~
20061 \SpecialChar ~
20062 mpasmwin /q /o $*.asm
20063 \newline 
20064
20065 \newline 
20066 $(PRJ).hex: $(OBJS) 
20067 \newline 
20068 \SpecialChar ~
20069 \SpecialChar ~
20070 \SpecialChar ~
20071 \SpecialChar ~
20072 \SpecialChar ~
20073 \SpecialChar ~
20074 \SpecialChar ~
20075 \SpecialChar ~
20076 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
20077 \layout Standard
20078
20079 Please note that indentations within a
20080 \family typewriter 
20081  Makefile
20082 \family default 
20083  have to be done with a tabulator character.
20084 \layout Subsection
20085
20086 Command-line options
20087 \layout Standard
20088
20089 Besides the switches common to all SDCC backends, the PIC14 port accepts
20090  the following options (for an updated list see sdcc -
20091 \begin_inset ERT
20092 status Collapsed
20093
20094 \layout Standard
20095
20096 \backslash 
20097 /
20098 \end_inset 
20099
20100 -help):
20101 \layout List
20102 \labelwidthstring 00.00.0000
20103
20104 -
20105 \begin_inset ERT
20106 status Collapsed
20107
20108 \layout Standard
20109
20110 \backslash 
20111 /
20112 \end_inset 
20113
20114 -debug-extra
20115 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
20116
20117 \end_inset 
20118
20119  emit debug info in assembly output
20120 \layout List
20121 \labelwidthstring 00.00.0000
20122
20123 -
20124 \begin_inset ERT
20125 status Collapsed
20126
20127 \layout Standard
20128
20129 \backslash 
20130 /
20131 \end_inset 
20132
20133 -no-pcode-opt
20134 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
20135
20136 \end_inset 
20137
20138  disable (slightly faulty) optimization on pCode
20139 \layout List
20140 \labelwidthstring 00.00.0000
20141
20142 -
20143 \begin_inset ERT
20144 status Collapsed
20145
20146 \layout Standard
20147
20148 \backslash 
20149 /
20150 \end_inset 
20151
20152 -stack-loc
20153 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
20154
20155 \end_inset 
20156
20157  sets the lowest address of the argument passing stack (defaults to a suitably
20158  large shared databank to reduce BANKSEL overhead)
20159 \layout List
20160 \labelwidthstring 00.00.0000
20161
20162 -
20163 \begin_inset ERT
20164 status Collapsed
20165
20166 \layout Standard
20167
20168 \backslash 
20169 /
20170 \end_inset 
20171
20172 -stack-size
20173 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
20174
20175 \end_inset 
20176
20177  sets the size if the argument passing stack (default: 16, minimum: 4)
20178 \layout Subsection
20179
20180 The library
20181 \layout Subsubsection
20182
20183 error: missing definition for symbol 
20184 \begin_inset Quotes sld
20185 \end_inset 
20186
20187 __gptrget1
20188 \begin_inset Quotes srd
20189 \end_inset 
20190
20191
20192 \layout Standard
20193
20194 The PIC14 port uses library routines to provide more complex operations
20195  like multiplication, division/modulus and (generic) pointer dereferencing.
20196  In order to add these routines to your project, you must link with PIC14's
20197  
20198 \family typewriter 
20199 libsdcc.lib
20200 \family default 
20201 .
20202  For single source file projects this is done automatically, more complex
20203  projects must add 
20204 \family typewriter 
20205 libsdcc.lib
20206 \family default 
20207  to the linker's arguments.
20208  Make sure you also add an include path for the library (using the -I switch
20209  to the linker)!
20210 \layout Subsubsection
20211
20212 Processor mismatch in file 
20213 \begin_inset Quotes sld
20214 \end_inset 
20215
20216 XXX
20217 \begin_inset Quotes srd
20218 \end_inset 
20219
20220 .
20221 \layout Standard
20222
20223 This warning can usually be ignored due to the very good compatibility amongst
20224  14 bit PIC
20225 \begin_inset LatexCommand \index{PIC14}
20226
20227 \end_inset 
20228
20229  devices.
20230 \layout Standard
20231
20232 You might also consider recompiling the library for your specific device
20233  by changing the ARCH=p16f877 (default target) entry in 
20234 \family typewriter 
20235 device/lib/pic/Makefile.in
20236 \family default 
20237  and 
20238 \family typewriter 
20239 device/lib/pic/Makefile
20240 \family default 
20241  to reflect your device.
20242  This might even improve performance for smaller devices as unneccesary
20243  BANKSELs migth be removed.
20244 \layout Subsection
20245
20246 Known bugs
20247 \layout Subsubsection
20248
20249 initialized data
20250 \layout Standard
20251 \pagebreak_bottom 
20252 Currently, data can only be initialized if it resides in the source file
20253  together with 
20254 \emph on 
20255 main()
20256 \emph default 
20257 .
20258  Data in other source files will silently 
20259 \series bold 
20260 not
20261 \series default 
20262  be initialized.
20263 \family typewriter 
20264 \size footnotesize 
20265
20266 \begin_inset Marginal
20267 collapsed true
20268
20269 \layout Standard
20270
20271
20272 \series bold 
20273 \SpecialChar ~
20274 !
20275 \end_inset 
20276
20277
20278 \layout Section
20279
20280 The PIC16
20281 \begin_inset LatexCommand \index{PIC16}
20282
20283 \end_inset 
20284
20285  port
20286 \layout Standard
20287
20288 The PIC16
20289 \begin_inset LatexCommand \index{PIC16}
20290
20291 \end_inset 
20292
20293  port is the portion of SDCC that is responsible to produce code for the
20294  Microchip
20295 \begin_inset LatexCommand \index{Microchip}
20296
20297 \end_inset 
20298
20299 (TM) microcontrollers with 16 bit core.
20300  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
20301  Currently supported devices are:
20302 \layout Standard
20303 \align center 
20304
20305 \begin_inset  Tabular
20306 <lyxtabular version="3" rows="4" columns="6">
20307 <features>
20308 <column alignment="center" valignment="top" leftline="true" width="0">
20309 <column alignment="center" valignment="top" leftline="true" width="0">
20310 <column alignment="center" valignment="top" leftline="true" width="0">
20311 <column alignment="center" valignment="top" leftline="true" width="0">
20312 <column alignment="center" valignment="top" leftline="true" width="0">
20313 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
20314 <row topline="true">
20315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20316 \begin_inset Text
20317
20318 \layout Standard
20319
20320 18F242
20321 \end_inset 
20322 </cell>
20323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20324 \begin_inset Text
20325
20326 \layout Standard
20327
20328 18F248
20329 \end_inset 
20330 </cell>
20331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20332 \begin_inset Text
20333
20334 \layout Standard
20335
20336 18F252
20337 \end_inset 
20338 </cell>
20339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20340 \begin_inset Text
20341
20342 \layout Standard
20343
20344 18F258
20345 \end_inset 
20346 </cell>
20347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20348 \begin_inset Text
20349
20350 \layout Standard
20351
20352 18F442
20353 \end_inset 
20354 </cell>
20355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20356 \begin_inset Text
20357
20358 \layout Standard
20359
20360 18F448
20361 \end_inset 
20362 </cell>
20363 </row>
20364 <row topline="true">
20365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20366 \begin_inset Text
20367
20368 \layout Standard
20369
20370 18F452
20371 \end_inset 
20372 </cell>
20373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20374 \begin_inset Text
20375
20376 \layout Standard
20377
20378 18F458
20379 \end_inset 
20380 </cell>
20381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20382 \begin_inset Text
20383
20384 \layout Standard
20385
20386 18F1220
20387 \end_inset 
20388 </cell>
20389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20390 \begin_inset Text
20391
20392 \layout Standard
20393
20394 18F2220
20395 \end_inset 
20396 </cell>
20397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20398 \begin_inset Text
20399
20400 \layout Standard
20401
20402 18F2550
20403 \end_inset 
20404 </cell>
20405 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20406 \begin_inset Text
20407
20408 \layout Standard
20409
20410 18F4331
20411 \end_inset 
20412 </cell>
20413 </row>
20414 <row topline="true">
20415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20416 \begin_inset Text
20417
20418 \layout Standard
20419
20420 18F4455
20421 \end_inset 
20422 </cell>
20423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20424 \begin_inset Text
20425
20426 \layout Standard
20427
20428 18F6520
20429 \end_inset 
20430 </cell>
20431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20432 \begin_inset Text
20433
20434 \layout Standard
20435
20436 18F6620
20437 \end_inset 
20438 </cell>
20439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20440 \begin_inset Text
20441
20442 \layout Standard
20443
20444 18F6680
20445 \end_inset 
20446 </cell>
20447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20448 \begin_inset Text
20449
20450 \layout Standard
20451
20452 18F6720
20453 \end_inset 
20454 </cell>
20455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20456 \begin_inset Text
20457
20458 \layout Standard
20459
20460 18F8520
20461 \end_inset 
20462 </cell>
20463 </row>
20464 <row topline="true" bottomline="true">
20465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20466 \begin_inset Text
20467
20468 \layout Standard
20469
20470 18F8620
20471 \end_inset 
20472 </cell>
20473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20474 \begin_inset Text
20475
20476 \layout Standard
20477
20478 18F8680
20479 \end_inset 
20480 </cell>
20481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20482 \begin_inset Text
20483
20484 \layout Standard
20485
20486 18F8720
20487 \end_inset 
20488 </cell>
20489 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20490 \begin_inset Text
20491
20492 \layout Standard
20493
20494 \end_inset 
20495 </cell>
20496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20497 \begin_inset Text
20498
20499 \layout Standard
20500
20501 \end_inset 
20502 </cell>
20503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20504 \begin_inset Text
20505
20506 \layout Standard
20507
20508 \end_inset 
20509 </cell>
20510 </row>
20511 </lyxtabular>
20512
20513 \end_inset 
20514
20515
20516 \layout Subsection
20517
20518 Global Options
20519 \layout Standard
20520
20521 PIC16 port supports the standard command line arguments as supposed, with
20522  the exception of certain cases that will be mentioned in the following
20523  list:
20524 \layout List
20525 \labelwidthstring 00.00.0000
20526
20527 -
20528 \begin_inset ERT
20529 status Collapsed
20530
20531 \layout Standard
20532
20533 \backslash 
20534 /
20535 \end_inset 
20536
20537 -callee-saves
20538 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
20539
20540 \end_inset 
20541
20542  See -
20543 \begin_inset ERT
20544 status Collapsed
20545
20546 \layout Standard
20547
20548 \backslash 
20549 /
20550 \end_inset 
20551
20552 -all-callee-saves
20553 \layout List
20554 \labelwidthstring 00.00.0000
20555
20556 -
20557 \begin_inset ERT
20558 status Collapsed
20559
20560 \layout Standard
20561
20562 \backslash 
20563 /
20564 \end_inset 
20565
20566 -all-callee-saves
20567 \begin_inset LatexCommand \index{PIC16!Options!-\/-all-callee-saves}
20568
20569 \end_inset 
20570
20571  All function arguments are passed on stack by default.
20572  
20573 \emph on 
20574 There is no need to specify this in the command line.
20575 \layout List
20576 \labelwidthstring 00.00.0000
20577
20578 -
20579 \begin_inset ERT
20580 status Collapsed
20581
20582 \layout Standard
20583
20584 \backslash 
20585 /
20586 \end_inset 
20587
20588 -fommit-frame-pointer
20589 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
20590
20591 \end_inset 
20592
20593  Frame pointer will be omitted when the function uses no local variables.
20594 \layout Subsection
20595
20596 Port Specific Options
20597 \begin_inset LatexCommand \index{Options PIC16}
20598
20599 \end_inset 
20600
20601
20602 \layout Standard
20603
20604 The port specific options appear after the global options in the sdcc --help
20605  output.
20606 \layout Subsubsection
20607
20608 General Options
20609 \layout Standard
20610
20611 General options enable certain port features and optimizations.
20612 \layout List
20613 \labelwidthstring 00.00.0000
20614
20615 -
20616 \begin_inset ERT
20617 status Collapsed
20618
20619 \layout Standard
20620
20621 \backslash 
20622 /
20623 \end_inset 
20624
20625 -pstack-model=[model] Used in conjuction with the command above.
20626  Defines the stack model to be used, valid stack models are : 
20627 \begin_deeper 
20628 \layout List
20629 \labelwidthstring 00.00.0000
20630
20631
20632 \emph on 
20633 small
20634 \emph default 
20635  Selects small stack model.
20636  8 bit stack and frame pointers.
20637  Supports 256 bytes stack size.
20638 \layout List
20639 \labelwidthstring 00.00.0000
20640
20641
20642 \emph on 
20643 large
20644 \emph default 
20645  Selects large stack model.
20646  16 bit stack and frame pointers.
20647  Supports 65536 bytes stack size.
20648 \end_deeper 
20649 \layout List
20650 \labelwidthstring 00.00.0000
20651
20652 -
20653 \begin_inset ERT
20654 status Collapsed
20655
20656 \layout Standard
20657
20658 \backslash 
20659 /
20660 \end_inset 
20661
20662 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
20663  unitialized data variables with [kword].
20664  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
20665 \layout List
20666 \labelwidthstring 00.00.0000
20667
20668 -
20669 \begin_inset ERT
20670 status Collapsed
20671
20672 \layout Standard
20673
20674 \backslash 
20675 /
20676 \end_inset 
20677
20678 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
20679  Useful for bootloaders.
20680 \layout List
20681 \labelwidthstring 00.00.0000
20682
20683 -
20684 \begin_inset ERT
20685 status Collapsed
20686
20687 \layout Standard
20688
20689 \backslash 
20690 /
20691 \end_inset 
20692
20693 -asm= sets the full path and name of an external assembler to call.
20694 \layout List
20695 \labelwidthstring 00.00.0000
20696
20697 -
20698 \begin_inset ERT
20699 status Collapsed
20700
20701 \layout Standard
20702
20703 \backslash 
20704 /
20705 \end_inset 
20706
20707 -link= sets the full path and name of an external linker to call.
20708 \layout List
20709 \labelwidthstring 00.00.0000
20710
20711 -
20712 \begin_inset ERT
20713 status Collapsed
20714
20715 \layout Standard
20716
20717 \backslash 
20718 /
20719 \end_inset 
20720
20721 -mplab-comp MPLAB
20722 \begin_inset LatexCommand \index{PIC16!MPLAB}
20723
20724 \end_inset 
20725
20726  compatibility option.
20727  Currently only suppresses special gpasm directives.
20728 \layout Subsubsection
20729
20730 Optimization Options
20731 \layout List
20732 \labelwidthstring 00.00.0000
20733
20734 -
20735 \begin_inset ERT
20736 status Collapsed
20737
20738 \layout Standard
20739
20740 \backslash 
20741 /
20742 \end_inset 
20743
20744 -optimize-goto Try to use (conditional) BRA instead of GOTO
20745 \layout List
20746 \labelwidthstring 00.00.0000
20747
20748 -
20749 \begin_inset ERT
20750 status Collapsed
20751
20752 \layout Standard
20753
20754 \backslash 
20755 /
20756 \end_inset 
20757
20758 -optimize-cmp Try to optimize some compares.
20759 \layout List
20760 \labelwidthstring 00.00.0000
20761
20762 -
20763 \begin_inset ERT
20764 status Collapsed
20765
20766 \layout Standard
20767
20768 \backslash 
20769 /
20770 \end_inset 
20771
20772 -optimize-df Analyze the dataflow of the generated code and improve it.
20773 \layout List
20774 \labelwidthstring 00.00.0000
20775
20776 -
20777 \begin_inset ERT
20778 status Collapsed
20779
20780 \layout Standard
20781
20782 \backslash 
20783 /
20784 \end_inset 
20785
20786 -obanksel=nn Set optimization level for inserting BANKSELs.
20787 \newline 
20788
20789 \begin_deeper 
20790 \layout List
20791 \labelwidthstring 00.00.0000
20792
20793 0 no optimization
20794 \layout List
20795 \labelwidthstring 00.00.0000
20796
20797 1 checks previous used register and if it is the same then does not emit
20798  BANKSEL, accounts only for labels.
20799 \layout List
20800 \labelwidthstring 00.00.0000
20801
20802 2 tries to check the location of (even different) symbols and removes BANKSELs
20803  if they are in the same bank.
20804  
20805 \newline 
20806
20807 \emph on 
20808 Important: There might be problems if the linker script has data sections
20809  across bank borders!
20810 \end_deeper 
20811 \layout Subsubsection
20812
20813 Linking Options
20814 \layout List
20815 \labelwidthstring 00.00.0000
20816
20817 -
20818 \begin_inset ERT
20819 status Collapsed
20820
20821 \layout Standard
20822
20823 \backslash 
20824 /
20825 \end_inset 
20826
20827 -nodefaultlibs do not link default libraries when linking
20828 \layout List
20829 \labelwidthstring 00.00.0000
20830
20831 -
20832 \begin_inset ERT
20833 status Collapsed
20834
20835 \layout Standard
20836
20837 \backslash 
20838 /
20839 \end_inset 
20840
20841 -no-crt Don't link the default run-time modules
20842 \layout List
20843 \labelwidthstring 00.00.0000
20844
20845 -
20846 \begin_inset ERT
20847 status Collapsed
20848
20849 \layout Standard
20850
20851 \backslash 
20852 /
20853 \end_inset 
20854
20855 -use-crt= Use a custom run-time module instead of the defaults.
20856 \layout Subsubsection
20857
20858 Debugging Options
20859 \layout Standard
20860
20861 Debugging options enable extra debugging information in the output files.
20862 \layout List
20863 \labelwidthstring 00.00.0000
20864
20865 -
20866 \begin_inset ERT
20867 status Collapsed
20868
20869 \layout Standard
20870
20871 \backslash 
20872 /
20873 \end_inset 
20874
20875 -debug-xtra Similar to -
20876 \begin_inset ERT
20877 status Collapsed
20878
20879 \layout Standard
20880
20881 \backslash 
20882 /
20883 \end_inset 
20884
20885 -debug
20886 \begin_inset LatexCommand \index{-\/-debug}
20887
20888 \end_inset 
20889
20890 , but dumps more information.
20891 \layout List
20892 \labelwidthstring 00.00.0000
20893
20894 -
20895 \begin_inset ERT
20896 status Collapsed
20897
20898 \layout Standard
20899
20900 \backslash 
20901 /
20902 \end_inset 
20903
20904 -debug-ralloc Force register allocator to dump <source>.d file with debugging
20905  information.
20906  <source> is the name of the file compiled.
20907 \layout List
20908 \labelwidthstring 00.00.0000
20909
20910 -
20911 \begin_inset ERT
20912 status Collapsed
20913
20914 \layout Standard
20915
20916 \backslash 
20917 /
20918 \end_inset 
20919
20920 -pcode-verbose Enable pcode debugging information in translation.
20921 \layout List
20922 \labelwidthstring 00.00.0000
20923
20924 -
20925 \begin_inset ERT
20926 status Collapsed
20927
20928 \layout Standard
20929
20930 \backslash 
20931 /
20932 \end_inset 
20933
20934 -denable-peeps Force the usage of peepholes.
20935  Use with care.
20936 \layout List
20937 \labelwidthstring 00.00.0000
20938
20939 -
20940 \begin_inset ERT
20941 status Collapsed
20942
20943 \layout Standard
20944
20945 \backslash 
20946 /
20947 \end_inset 
20948
20949 -gstack Trace push/pops for stack pointer overflow
20950 \layout List
20951 \labelwidthstring 00.00.0000
20952
20953 -
20954 \begin_inset ERT
20955 status Collapsed
20956
20957 \layout Standard
20958
20959 \backslash 
20960 /
20961 \end_inset 
20962
20963 -call-tree dump call tree in .calltree file
20964 \layout Subsection
20965
20966 Enviromental Variables
20967 \layout Standard
20968
20969 There is a number of enviromental variables that can be used when running
20970  SDCC to enable certain optimizations or force a specific program behaviour.
20971  these variables are primarily for debugging purposes so they can be enabled/dis
20972 abled at will.
20973 \layout Standard
20974
20975 Currently there is only two such variables available:
20976 \layout List
20977 \labelwidthstring 00.00.0000
20978
20979 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
20980  bitfields is optimized by directly loading FSR0 with the address of the
20981  bitfield structure.
20982  Normally SDCC will cast the bitfield structure to a bitfield pointer and
20983  then load FSR0.
20984  This step saves data ram and code space for functions that perform heavy
20985  use of bitfields.
20986  (ie.
20987  80 bytes of code space are saved when compiling malloc.c with this option).
20988  
20989 \layout List
20990 \labelwidthstring 00.00.0000
20991
20992 NO_REG_OPT do not perform pCode registers optimization.
20993  This should be used for debugging purposes.
20994  In some where bugs in the pcode optimizer are found, users can benefit
20995  from temporarily disabling the optimizer until the bug is fixed.
20996 \layout Subsection
20997
20998 Preprocessor Macros
20999 \layout Standard
21000
21001 PIC16
21002 \begin_inset LatexCommand \index{PIC16}
21003
21004 \end_inset 
21005
21006  port defines the following preprocessor macros while translating a source.
21007 \layout Standard
21008 \align center 
21009
21010 \begin_inset  Tabular
21011 <lyxtabular version="3" rows="6" columns="2">
21012 <features>
21013 <column alignment="center" valignment="top" leftline="true" width="0">
21014 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21015 <row topline="true" bottomline="true">
21016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21017 \begin_inset Text
21018
21019 \layout Standard
21020
21021 Macro
21022 \end_inset 
21023 </cell>
21024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21025 \begin_inset Text
21026
21027 \layout Standard
21028
21029 Description
21030 \end_inset 
21031 </cell>
21032 </row>
21033 <row topline="true">
21034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21035 \begin_inset Text
21036
21037 \layout Standard
21038
21039 SDCC_pic16
21040 \end_inset 
21041 </cell>
21042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21043 \begin_inset Text
21044
21045 \layout Standard
21046
21047 Port identification
21048 \end_inset 
21049 </cell>
21050 </row>
21051 <row topline="true">
21052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21053 \begin_inset Text
21054
21055 \layout Standard
21056
21057 _
21058 \begin_inset ERT
21059 status Collapsed
21060
21061 \layout Standard
21062
21063 \backslash 
21064 /
21065 \end_inset 
21066
21067 _pic16
21068 \end_inset 
21069 </cell>
21070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21071 \begin_inset Text
21072
21073 \layout Standard
21074
21075 Port identification (same as above)
21076 \end_inset 
21077 </cell>
21078 </row>
21079 <row topline="true">
21080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21081 \begin_inset Text
21082
21083 \layout Standard
21084
21085 pic18fxxxx
21086 \end_inset 
21087 </cell>
21088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21089 \begin_inset Text
21090
21091 \layout Standard
21092
21093 MCU Identification.
21094  
21095 \emph on 
21096 xxxx
21097 \emph default 
21098  is the microcontrol identification number, i.e.
21099  452, 6620, etc
21100 \end_inset 
21101 </cell>
21102 </row>
21103 <row topline="true">
21104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21105 \begin_inset Text
21106
21107 \layout Standard
21108
21109 _
21110 \begin_inset ERT
21111 status Collapsed
21112
21113 \layout Standard
21114
21115 \backslash 
21116 /
21117 \end_inset 
21118
21119 _18Fxxxx
21120 \end_inset 
21121 </cell>
21122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21123 \begin_inset Text
21124
21125 \layout Standard
21126
21127 MCU Identification (same as above)
21128 \end_inset 
21129 </cell>
21130 </row>
21131 <row topline="true" bottomline="true">
21132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21133 \begin_inset Text
21134
21135 \layout Standard
21136
21137 STACK_MODEL_nnn
21138 \end_inset 
21139 </cell>
21140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21141 \begin_inset Text
21142
21143 \layout Standard
21144
21145 nnn = SMALL or LARGE respectively according to the stack model used
21146 \end_inset 
21147 </cell>
21148 </row>
21149 </lyxtabular>
21150
21151 \end_inset 
21152
21153
21154 \layout Standard
21155
21156 In addition the following macros are defined when calling assembler:
21157 \layout Standard
21158 \align center 
21159
21160 \begin_inset  Tabular
21161 <lyxtabular version="3" rows="4" columns="2">
21162 <features>
21163 <column alignment="center" valignment="top" leftline="true" width="0">
21164 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21165 <row topline="true" bottomline="true">
21166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21167 \begin_inset Text
21168
21169 \layout Standard
21170
21171 Macro
21172 \end_inset 
21173 </cell>
21174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21175 \begin_inset Text
21176
21177 \layout Standard
21178
21179 Description
21180 \end_inset 
21181 </cell>
21182 </row>
21183 <row topline="true">
21184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21185 \begin_inset Text
21186
21187 \layout Standard
21188
21189 __18Fxxxx
21190 \end_inset 
21191 </cell>
21192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21193 \begin_inset Text
21194
21195 \layout Standard
21196
21197 MCU Identification.
21198  
21199 \emph on 
21200 xxxx
21201 \emph default 
21202  is the microcontrol identification number, i.e.
21203  452, 6620, etc
21204 \end_inset 
21205 </cell>
21206 </row>
21207 <row topline="true">
21208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21209 \begin_inset Text
21210
21211 \layout Standard
21212
21213 SDCC_MODEL_nnn
21214 \end_inset 
21215 </cell>
21216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21217 \begin_inset Text
21218
21219 \layout Standard
21220
21221 nnn = SMALL or LARGE respectively according to the memory model used for
21222  SDCC
21223 \end_inset 
21224 </cell>
21225 </row>
21226 <row topline="true" bottomline="true">
21227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21228 \begin_inset Text
21229
21230 \layout Standard
21231
21232 STACK_MODEL_nnn
21233 \end_inset 
21234 </cell>
21235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21236 \begin_inset Text
21237
21238 \layout Standard
21239
21240 nnn = SMALL or LARGE respectively according to the stack model used
21241 \end_inset 
21242 </cell>
21243 </row>
21244 </lyxtabular>
21245
21246 \end_inset 
21247
21248
21249 \layout Subsection
21250
21251 Directories
21252 \layout Standard
21253
21254 PIC16
21255 \begin_inset LatexCommand \index{PIC16}
21256
21257 \end_inset 
21258
21259  port uses the following directories for searching header files and libraries.
21260 \layout Standard
21261 \align center 
21262
21263 \begin_inset  Tabular
21264 <lyxtabular version="3" rows="3" columns="4">
21265 <features>
21266 <column alignment="center" valignment="top" leftline="true" width="0">
21267 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21268 <column alignment="center" valignment="top" width="0">
21269 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21270 <row topline="true" bottomline="true">
21271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21272 \begin_inset Text
21273
21274 \layout Standard
21275
21276 Directory
21277 \end_inset 
21278 </cell>
21279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21280 \begin_inset Text
21281
21282 \layout Standard
21283
21284 Description
21285 \end_inset 
21286 </cell>
21287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21288 \begin_inset Text
21289
21290 \layout Standard
21291
21292 Target
21293 \end_inset 
21294 </cell>
21295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21296 \begin_inset Text
21297
21298 \layout Standard
21299
21300 Command prefix
21301 \end_inset 
21302 </cell>
21303 </row>
21304 <row topline="true">
21305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21306 \begin_inset Text
21307
21308 \layout Standard
21309
21310 PREFIX/sdcc/include/pic16
21311 \end_inset 
21312 </cell>
21313 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21314 \begin_inset Text
21315
21316 \layout Standard
21317
21318 PIC16 specific headers
21319 \end_inset 
21320 </cell>
21321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21322 \begin_inset Text
21323
21324 \layout Standard
21325
21326 Compiler
21327 \end_inset 
21328 </cell>
21329 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21330 \begin_inset Text
21331
21332 \layout Standard
21333
21334 -I
21335 \end_inset 
21336 </cell>
21337 </row>
21338 <row topline="true" bottomline="true">
21339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21340 \begin_inset Text
21341
21342 \layout Standard
21343
21344 PREFIX/sdcc/lib/pic16
21345 \end_inset 
21346 </cell>
21347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21348 \begin_inset Text
21349
21350 \layout Standard
21351
21352 PIC16 specific libraries
21353 \end_inset 
21354 </cell>
21355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21356 \begin_inset Text
21357
21358 \layout Standard
21359
21360 Linker
21361 \end_inset 
21362 </cell>
21363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21364 \begin_inset Text
21365
21366 \layout Standard
21367
21368 -L
21369 \end_inset 
21370 </cell>
21371 </row>
21372 </lyxtabular>
21373
21374 \end_inset 
21375
21376
21377 \layout Subsection
21378
21379 Pragmas
21380 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
21381
21382 \end_inset 
21383
21384
21385 \layout Standard
21386
21387 PIC16
21388 \begin_inset LatexCommand \index{PIC16}
21389
21390 \end_inset 
21391
21392  port currently supports the following pragmas:
21393 \layout List
21394 \labelwidthstring 00.00.0000
21395
21396 stack
21397 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
21398
21399 \end_inset 
21400
21401  pragma stack
21402 \begin_inset LatexCommand \index{PIC16!stack}
21403
21404 \end_inset 
21405
21406  forces the code generator to initialize the stack & frame pointers at a
21407  specific address.
21408  This is an adhoc solution for cases where no STACK directive is available
21409  in the linker script or gplink is not instructed to create a stack section.
21410 \newline 
21411 The stack pragma should be used only once in a project.
21412  Multiple pragmas may result in indeterminate behaviour of the program.
21413 \begin_inset Foot
21414 collapsed false
21415
21416 \layout Standard
21417
21418 The old format (ie.
21419  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
21420  cross page boundaries (or even exceed the available data RAM) and crash
21421  the program.
21422  Make sure that stack does not cross page boundaries when using the SMALL
21423  stack model.
21424 \end_inset 
21425
21426
21427 \newline 
21428 The format is as follows:
21429 \layout LyX-Code
21430
21431 #pragma stack bottom_address [stack_size]
21432 \layout Standard
21433
21434
21435 \emph on 
21436 bottom_address
21437 \emph default 
21438  is the lower bound of the stack section.
21439  The stack pointer initially will point at address (bottom_address+stack_size-1).
21440 \layout LyX-Code
21441
21442 Example:
21443 \layout LyX-Code
21444
21445 \layout LyX-Code
21446
21447 /* initializes stack of 100 bytes at RAM address 0x200 */
21448 \layout LyX-Code
21449
21450 #pragma stack 0x200 100
21451 \layout Standard
21452
21453 If the stack_size field is omitted then a stack is created with the default
21454  size of 64.
21455  This size might be enough for most programs, but its not enough for operations
21456  with deep function nesting or excessive stack usage.
21457 \layout List
21458 \labelwidthstring 00.00.0000
21459
21460 code
21461 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
21462
21463 \end_inset 
21464
21465  place a function symbol at static FLASH address
21466 \layout LyX-Code
21467
21468 Example:
21469 \layout LyX-Code
21470
21471 \layout LyX-Code
21472
21473 /* place function test_func at 0x4000 */
21474 \layout LyX-Code
21475
21476 #pragma code test_func 0x4000
21477 \layout LyX-Code
21478
21479 \layout List
21480 \labelwidthstring 00.00.0000
21481
21482 library instructs the linker to use a library module.
21483 \newline 
21484 Usage:
21485 \layout LyX-Code
21486
21487 #pragma library module_name
21488 \layout Standard
21489
21490
21491 \emph on 
21492 module_name
21493 \emph default 
21494  can be any library or object file (including its path).
21495  Note that there are four reserved keywords which have special meaning.
21496  These are:
21497 \layout Standard
21498 \align center 
21499
21500 \begin_inset  Tabular
21501 <lyxtabular version="3" rows="6" columns="3">
21502 <features>
21503 <column alignment="center" valignment="top" leftline="true" width="0">
21504 <column alignment="block" valignment="top" leftline="true" width="20page%">
21505 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
21506 <row topline="true" bottomline="true">
21507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21508 \begin_inset Text
21509
21510 \layout Standard
21511
21512 Keyword
21513 \end_inset 
21514 </cell>
21515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21516 \begin_inset Text
21517
21518 \layout Standard
21519
21520 Description
21521 \end_inset 
21522 </cell>
21523 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21524 \begin_inset Text
21525
21526 \layout Standard
21527
21528 Module to link
21529 \end_inset 
21530 </cell>
21531 </row>
21532 <row topline="true">
21533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21534 \begin_inset Text
21535
21536 \layout Standard
21537
21538
21539 \series bold 
21540 ignore
21541 \end_inset 
21542 </cell>
21543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21544 \begin_inset Text
21545
21546 \layout Standard
21547
21548 ignore all library pragmas
21549 \end_inset 
21550 </cell>
21551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21552 \begin_inset Text
21553
21554 \layout Standard
21555
21556
21557 \emph on 
21558 (none)
21559 \end_inset 
21560 </cell>
21561 </row>
21562 <row topline="true">
21563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21564 \begin_inset Text
21565
21566 \layout Standard
21567
21568
21569 \series bold 
21570 c
21571 \end_inset 
21572 </cell>
21573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21574 \begin_inset Text
21575
21576 \layout Standard
21577
21578 link the C library
21579 \end_inset 
21580 </cell>
21581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21582 \begin_inset Text
21583
21584 \layout Standard
21585
21586
21587 \emph on 
21588 libc18f
21589 \emph default 
21590 .lib
21591 \end_inset 
21592 </cell>
21593 </row>
21594 <row topline="true">
21595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21596 \begin_inset Text
21597
21598 \layout Standard
21599
21600
21601 \series bold 
21602 math
21603 \end_inset 
21604 </cell>
21605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21606 \begin_inset Text
21607
21608 \layout Standard
21609
21610 link the Math libarary
21611 \end_inset 
21612 </cell>
21613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21614 \begin_inset Text
21615
21616 \layout Standard
21617
21618
21619 \emph on 
21620 libm18f
21621 \emph default 
21622 .lib
21623 \end_inset 
21624 </cell>
21625 </row>
21626 <row topline="true">
21627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21628 \begin_inset Text
21629
21630 \layout Standard
21631
21632
21633 \series bold 
21634 io
21635 \end_inset 
21636 </cell>
21637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21638 \begin_inset Text
21639
21640 \layout Standard
21641
21642 link the I/O library
21643 \end_inset 
21644 </cell>
21645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21646 \begin_inset Text
21647
21648 \layout Standard
21649
21650
21651 \emph on 
21652 libio18f*
21653 \emph default 
21654 .lib
21655 \end_inset 
21656 </cell>
21657 </row>
21658 <row topline="true" bottomline="true">
21659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21660 \begin_inset Text
21661
21662 \layout Standard
21663
21664
21665 \series bold 
21666 debug
21667 \end_inset 
21668 </cell>
21669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21670 \begin_inset Text
21671
21672 \layout Standard
21673
21674 link the debug library
21675 \end_inset 
21676 </cell>
21677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21678 \begin_inset Text
21679
21680 \layout Standard
21681
21682
21683 \emph on 
21684 libdebug
21685 \emph default 
21686 .lib
21687 \end_inset 
21688 </cell>
21689 </row>
21690 </lyxtabular>
21691
21692 \end_inset 
21693
21694
21695 \newline 
21696 * is the device number, i.e.
21697  452 for PIC18F452 MCU.
21698 \layout Standard
21699
21700 This feature allows for linking with specific libraries withoug having to
21701  explicit name them in the command line.
21702  Note that the 
21703 \noun on 
21704 ignore
21705 \noun default 
21706  keyword will reject all modules specified by the library pragma.
21707 \layout List
21708 \labelwidthstring 00.00.0000
21709
21710 udata pragma udata instructs the compiler to emit code so that linker will
21711  place a variable at a specific memory bank
21712 \layout LyX-Code
21713
21714 Example:
21715 \layout LyX-Code
21716
21717 \layout LyX-Code
21718
21719 /* places variable foo at bank2 */
21720 \layout LyX-Code
21721
21722 #pragma udata bank2 foo
21723 \layout LyX-Code
21724
21725 char foo;
21726 \layout Standard
21727
21728 In order for this pragma to work extra SECTION directives should be added
21729  in the .lkr script.
21730  In the following example a sample .lkr file is shown:
21731 \layout LyX-Code
21732
21733 \layout LyX-Code
21734
21735 // Sample linker script for the PIC18F452 processor
21736 \layout LyX-Code
21737
21738 LIBPATH .
21739 \layout LyX-Code
21740
21741 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
21742 \layout LyX-Code
21743
21744 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
21745 \layout LyX-Code
21746
21747 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
21748 \layout LyX-Code
21749
21750 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
21751 \layout LyX-Code
21752
21753 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
21754 \layout LyX-Code
21755
21756 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
21757 \layout LyX-Code
21758
21759 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
21760 \layout LyX-Code
21761
21762 \layout LyX-Code
21763
21764 DATABANK   NAME=gpr0       START=0x80           END=0xFF
21765 \layout LyX-Code
21766
21767 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
21768 \layout LyX-Code
21769
21770 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
21771 \layout LyX-Code
21772
21773 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
21774 \layout LyX-Code
21775
21776 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
21777 \layout LyX-Code
21778
21779 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
21780 \layout LyX-Code
21781
21782 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
21783 \layout LyX-Code
21784
21785 \layout LyX-Code
21786
21787 SECTION    NAME=CONFIG     ROM=config
21788 \layout LyX-Code
21789
21790 \layout LyX-Code
21791
21792 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
21793 \layout LyX-Code
21794
21795 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
21796 \layout LyX-Code
21797
21798 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
21799 \layout LyX-Code
21800
21801 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
21802 \layout LyX-Code
21803
21804 SECTION    NAME=bank4      RAM=gpr4
21805 \layout LyX-Code
21806
21807 SECTION    NAME=bank5      RAM=gpr5
21808 \layout Standard
21809
21810 The linker will recognise the section name set in the pragma statement and
21811  will position the variable at the memory bank set with the RAM field at
21812  the SECTION line in the linker script file.
21813 \layout Subsection
21814
21815 Header Files
21816 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
21817
21818 \end_inset 
21819
21820
21821 \layout Standard
21822
21823 There is one main header file
21824 \begin_inset LatexCommand \index{PIC16!Header files}
21825
21826 \end_inset 
21827
21828  that can be included to the source files using the pic16
21829 \begin_inset LatexCommand \index{PIC16}
21830
21831 \end_inset 
21832
21833  port.
21834  That file is the 
21835 \series bold 
21836 pic18fregs.h
21837 \series default 
21838 .
21839  This header file contains the definitions for the processor special registers,
21840  so it is necessary if the source accesses them.
21841  It can be included by adding the following line in the beginning of the
21842  file:
21843 \layout LyX-Code
21844
21845 #include <pic18fregs.h>
21846 \layout Standard
21847
21848 The specific microcontroller is selected within the pic18fregs.h automatically,
21849  so the same source can be used with a variety of devices.
21850 \layout Subsection
21851
21852 Libraries
21853 \layout Standard
21854
21855 The libraries
21856 \begin_inset LatexCommand \index{PIC16!Libraries}
21857
21858 \end_inset 
21859
21860  that PIC16
21861 \begin_inset LatexCommand \index{PIC16}
21862
21863 \end_inset 
21864
21865  port depends on are the microcontroller device libraries which contain
21866  the symbol definitions for the microcontroller special function registers.
21867  These libraries have the format pic18fxxxx.lib, where 
21868 \emph on 
21869 xxxx
21870 \emph default 
21871  is the microcontroller identification number.
21872  The specific library is selected automatically by the compiler at link
21873  stage according to the selected device.
21874 \layout Standard
21875
21876 Libraries are created with gplib which is part of the gputils package 
21877 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
21878
21879 \end_inset 
21880
21881 .
21882 \layout Subsubsection*
21883
21884 Building the libraries
21885 \layout Standard
21886
21887 Before using SDCC/pic16 there are some libraries that need to be compiled.
21888  This process is not done automatically by SDCC since not all users use
21889  SDCC for pic16 projects.
21890  So each user should compile the libraries separately.
21891 \layout Standard
21892
21893 The steps to compile the pic16 libraries under Linux are:
21894 \layout LyX-Code
21895
21896 cd device/lib/pic16
21897 \layout LyX-Code
21898
21899 ./configure
21900 \layout LyX-Code
21901
21902 make
21903 \layout LyX-Code
21904
21905 cd ..
21906 \layout LyX-Code
21907
21908 make model-pic16
21909 \layout LyX-Code
21910
21911 su -c 'make install'     # install the libraries, you need the root password
21912 \layout Standard
21913
21914 If you need to install the headers too, do:
21915 \layout LyX-Code
21916
21917 cd device/include
21918 \layout LyX-Code
21919
21920 su -c 'make install'     # install the headers, you need the root password
21921 \layout Standard
21922
21923 There exist a special target to build the I/O libraries.
21924  This target is not automatically build because it will build the I/O library
21925  for 
21926 \emph on 
21927 every
21928 \emph default 
21929  supported device.
21930  This way building will take quite a lot of time.
21931  Users are advised to edit the 
21932 \series bold 
21933 device/lib/pic16/pics.build
21934 \series default 
21935  file and then execute:
21936 \layout LyX-Code
21937
21938 make lib-io
21939 \layout Subsection
21940
21941 Memory Models
21942 \layout Standard
21943
21944 The following memory models are supported by the PIC16 port:
21945 \layout Itemize
21946
21947 small model
21948 \layout Itemize
21949
21950 large model
21951 \layout Standard
21952
21953 Memory model affects the default size of pointers within the source.
21954  The sizes are shown in the next table:
21955 \layout Standard
21956 \align center 
21957
21958 \begin_inset  Tabular
21959 <lyxtabular version="3" rows="3" columns="3">
21960 <features>
21961 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21962 <column alignment="center" valignment="top" leftline="true" width="0">
21963 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
21964 <row topline="true" bottomline="true">
21965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21966 \begin_inset Text
21967
21968 \layout Standard
21969
21970 Pointer sizes according to memory model
21971 \end_inset 
21972 </cell>
21973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21974 \begin_inset Text
21975
21976 \layout Standard
21977
21978 small model
21979 \end_inset 
21980 </cell>
21981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21982 \begin_inset Text
21983
21984 \layout Standard
21985
21986 large model
21987 \end_inset 
21988 </cell>
21989 </row>
21990 <row topline="true" bottomline="true">
21991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21992 \begin_inset Text
21993
21994 \layout Standard
21995
21996 code pointers
21997 \end_inset 
21998 </cell>
21999 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22000 \begin_inset Text
22001
22002 \layout Standard
22003
22004 16-bits
22005 \end_inset 
22006 </cell>
22007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22008 \begin_inset Text
22009
22010 \layout Standard
22011
22012 24-bits
22013 \end_inset 
22014 </cell>
22015 </row>
22016 <row topline="true" bottomline="true">
22017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22018 \begin_inset Text
22019
22020 \layout Standard
22021
22022 data pointers
22023 \end_inset 
22024 </cell>
22025 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
22026 \begin_inset Text
22027
22028 \layout Standard
22029
22030 16-bits
22031 \end_inset 
22032 </cell>
22033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22034 \begin_inset Text
22035
22036 \layout Standard
22037
22038 16-bits
22039 \end_inset 
22040 </cell>
22041 </row>
22042 </lyxtabular>
22043
22044 \end_inset 
22045
22046
22047 \layout Standard
22048
22049 It is advisable that all sources within a project are compiled with the
22050  same memory model.
22051  If one wants to override the default memory model, this can be done by
22052  declaring a pointer as 
22053 \series bold 
22054 far
22055 \series default 
22056  or 
22057 \series bold 
22058 near
22059 \series default 
22060 .
22061  Far selects large memory model's pointers, while near selects small memory
22062  model's pointers.
22063 \layout Standard
22064
22065 The standard device libraries (see 
22066 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
22067
22068 \end_inset 
22069
22070 ) contain no reference to pointers, so they can be used with both memory
22071  models.
22072 \layout Subsection
22073
22074 Stack
22075 \layout Standard
22076
22077 The stack
22078 \begin_inset LatexCommand \index{PIC16!stack}
22079
22080 \end_inset 
22081
22082  implementation for the PIC16 port uses two indirect registers, FSR1 and
22083  FSR2.
22084 \layout List
22085 \labelwidthstring 00.00.0000
22086
22087 FSR1 is assigned as stack pointer
22088 \layout List
22089 \labelwidthstring 00.00.0000
22090
22091 FSR2 is assigned as frame pointer
22092 \layout Standard
22093
22094 The following stack models are supported by the PIC16 port
22095 \layout Itemize
22096
22097
22098 \noun on 
22099 small
22100 \noun default 
22101  model
22102 \layout Itemize
22103
22104
22105 \noun on 
22106 large
22107 \noun default 
22108  model
22109 \layout Standard
22110
22111
22112 \noun on 
22113 Small
22114 \noun default 
22115  model means that only the FSRxL byte is used to access stack and frame,
22116  while 
22117 \emph on 
22118 \noun on 
22119 large
22120 \emph default 
22121 \noun default 
22122  uses both FSRxL and FSRxH registers.
22123  The following table shows the stack/frame pointers sizes according to stack
22124  model and the maximum space they can address:
22125 \layout Standard
22126 \align center 
22127
22128 \begin_inset  Tabular
22129 <lyxtabular version="3" rows="3" columns="3">
22130 <features>
22131 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22132 <column alignment="center" valignment="top" leftline="true" width="0">
22133 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22134 <row topline="true" bottomline="true">
22135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22136 \begin_inset Text
22137
22138 \layout Standard
22139
22140 Stack & Frame pointer sizes according to stack model
22141 \end_inset 
22142 </cell>
22143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22144 \begin_inset Text
22145
22146 \layout Standard
22147
22148 small
22149 \end_inset 
22150 </cell>
22151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22152 \begin_inset Text
22153
22154 \layout Standard
22155
22156 large
22157 \end_inset 
22158 </cell>
22159 </row>
22160 <row topline="true">
22161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22162 \begin_inset Text
22163
22164 \layout Standard
22165
22166 Stack pointer FSR1
22167 \end_inset 
22168 </cell>
22169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22170 \begin_inset Text
22171
22172 \layout Standard
22173
22174 8-bits
22175 \end_inset 
22176 </cell>
22177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22178 \begin_inset Text
22179
22180 \layout Standard
22181
22182 16-bits
22183 \end_inset 
22184 </cell>
22185 </row>
22186 <row topline="true" bottomline="true">
22187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22188 \begin_inset Text
22189
22190 \layout Standard
22191
22192 Frame pointer FSR2
22193 \end_inset 
22194 </cell>
22195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22196 \begin_inset Text
22197
22198 \layout Standard
22199
22200 8-bits
22201 \end_inset 
22202 </cell>
22203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22204 \begin_inset Text
22205
22206 \layout Standard
22207
22208 16-bits
22209 \end_inset 
22210 </cell>
22211 </row>
22212 </lyxtabular>
22213
22214 \end_inset 
22215
22216
22217 \layout Standard
22218
22219
22220 \noun on 
22221 Large 
22222 \noun default 
22223 stack model is currently not working properly throughout the code generator.
22224  So its use is not advised.
22225  Also there are some other points that need special care:
22226 \newline 
22227
22228 \layout Enumerate
22229
22230 Do not create stack sections with size more than one physical bank (that
22231  is 256 bytes)
22232 \layout Enumerate
22233
22234 Stack sections should no cross physical bank limits (i.e.
22235  #pragma stack 0x50 0x100)
22236 \layout Standard
22237
22238 These limitations are caused by the fact that only FSRxL is modified when
22239  using SMALL stack model, so no more than 256 bytes of stack can be used.
22240  This problem will disappear after LARGE model is fully implemented.
22241 \layout Subsection
22242
22243 Functions
22244 \layout Standard
22245
22246 In addition to the standard SDCC function keywords, PIC16
22247 \begin_inset LatexCommand \index{PIC16}
22248
22249 \end_inset 
22250
22251  port makes available two more:
22252 \layout List
22253 \labelwidthstring 00.00.0000
22254
22255 wparam
22256 \begin_inset LatexCommand \index{PIC16!wparam}
22257
22258 \end_inset 
22259
22260  Use the WREG to pass one byte of the first function argument.
22261  This improves speed but you may not use this for functions with arguments
22262  that are called via function pointers, otherwise the first byte of the
22263  first parameter will get lost.
22264  Usage:
22265 \layout LyX-Code
22266
22267 void func_wparam(int a) wparam
22268 \layout LyX-Code
22269
22270 {
22271 \layout LyX-Code
22272
22273     /* WREG hold the lower part of a */
22274 \layout LyX-Code
22275
22276     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
22277  */
22278 \layout LyX-Code
22279
22280 ...
22281 \layout LyX-Code
22282
22283 }
22284 \layout List
22285 \labelwidthstring 00.00.0000
22286
22287 shadowregs
22288 \begin_inset LatexCommand \index{PIC16!shadowregs}
22289
22290 \end_inset 
22291
22292  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
22293  hardware shadow registers which hold the values of WREG, STATUS and BSR
22294  registers.
22295  This can be done by adding the keyword 
22296 \emph on 
22297 shadowregs
22298 \emph default 
22299  before the 
22300 \emph on 
22301 interrupt
22302 \emph default 
22303  keyword in the function's header.
22304 \layout LyX-Code
22305
22306 void isr_shadow(void) shadowregs interrupt 1
22307 \layout LyX-Code
22308
22309 {
22310 \layout LyX-Code
22311
22312 ...
22313 \layout LyX-Code
22314
22315 }
22316 \layout Standard
22317
22318
22319 \emph on 
22320 shadowregs
22321 \emph default 
22322  instructs the code generator not to store/restore WREG, STATUS, BSR when
22323  entering/exiting the ISR.
22324 \layout Subsection
22325
22326 Function return values
22327 \layout Standard
22328
22329 Return values from functions are placed to the appropriate registers following
22330  a modified Microchip policy optimized for SDCC.
22331  The following table shows these registers:
22332 \layout Standard
22333 \align center 
22334
22335 \begin_inset  Tabular
22336 <lyxtabular version="3" rows="6" columns="2">
22337 <features>
22338 <column alignment="center" valignment="top" leftline="true" width="0">
22339 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22340 <row topline="true" bottomline="true">
22341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22342 \begin_inset Text
22343
22344 \layout Standard
22345
22346 size
22347 \end_inset 
22348 </cell>
22349 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22350 \begin_inset Text
22351
22352 \layout Standard
22353
22354 destination register
22355 \end_inset 
22356 </cell>
22357 </row>
22358 <row topline="true">
22359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22360 \begin_inset Text
22361
22362 \layout Standard
22363
22364 8 bits
22365 \end_inset 
22366 </cell>
22367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22368 \begin_inset Text
22369
22370 \layout Standard
22371
22372 WREG
22373 \end_inset 
22374 </cell>
22375 </row>
22376 <row topline="true">
22377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22378 \begin_inset Text
22379
22380 \layout Standard
22381
22382 16 bits
22383 \end_inset 
22384 </cell>
22385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22386 \begin_inset Text
22387
22388 \layout Standard
22389
22390 PRODL:WREG
22391 \end_inset 
22392 </cell>
22393 </row>
22394 <row topline="true">
22395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22396 \begin_inset Text
22397
22398 \layout Standard
22399
22400 24 bits
22401 \end_inset 
22402 </cell>
22403 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22404 \begin_inset Text
22405
22406 \layout Standard
22407
22408 PRODH:PRODL:WREG
22409 \end_inset 
22410 </cell>
22411 </row>
22412 <row topline="true">
22413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22414 \begin_inset Text
22415
22416 \layout Standard
22417
22418 32 bits
22419 \end_inset 
22420 </cell>
22421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22422 \begin_inset Text
22423
22424 \layout Standard
22425
22426 FSR0L:PRODH:PRODL:WREG
22427 \end_inset 
22428 </cell>
22429 </row>
22430 <row topline="true" bottomline="true">
22431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22432 \begin_inset Text
22433
22434 \layout Standard
22435
22436 >32 bits
22437 \end_inset 
22438 </cell>
22439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22440 \begin_inset Text
22441
22442 \layout Standard
22443
22444 on stack, FSR0 points to the beginning
22445 \end_inset 
22446 </cell>
22447 </row>
22448 </lyxtabular>
22449
22450 \end_inset 
22451
22452
22453 \layout Subsection
22454
22455 Interrupts
22456 \layout Standard
22457
22458 An interrupt
22459 \begin_inset LatexCommand \index{PIC16!interrupt}
22460
22461 \end_inset 
22462
22463  service routine (ISR) is declared using the 
22464 \emph on 
22465 interrupt
22466 \emph default 
22467  keyword.
22468 \layout LyX-Code
22469
22470 void isr(void) interrupt 
22471 \emph on 
22472 n
22473 \layout LyX-Code
22474
22475 {
22476 \layout LyX-Code
22477
22478 ...
22479 \layout LyX-Code
22480
22481 }
22482 \layout Standard
22483
22484
22485 \emph on 
22486 n
22487 \emph default 
22488  is the interrupt number, which for PIC18F devices can be:
22489 \layout Standard
22490 \align center 
22491
22492 \begin_inset  Tabular
22493 <lyxtabular version="3" rows="4" columns="3">
22494 <features>
22495 <column alignment="center" valignment="top" leftline="true" width="0">
22496 <column alignment="center" valignment="top" leftline="true" width="0">
22497 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22498 <row topline="true" bottomline="true">
22499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22500 \begin_inset Text
22501
22502 \layout Standard
22503
22504
22505 \emph on 
22506 n
22507 \end_inset 
22508 </cell>
22509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22510 \begin_inset Text
22511
22512 \layout Standard
22513
22514 Interrupt Vector
22515 \end_inset 
22516 </cell>
22517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22518 \begin_inset Text
22519
22520 \layout Standard
22521
22522 Interrupt Vector Address
22523 \end_inset 
22524 </cell>
22525 </row>
22526 <row topline="true">
22527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22528 \begin_inset Text
22529
22530 \layout Standard
22531
22532 0
22533 \end_inset 
22534 </cell>
22535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22536 \begin_inset Text
22537
22538 \layout Standard
22539
22540 RESET vector
22541 \end_inset 
22542 </cell>
22543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22544 \begin_inset Text
22545
22546 \layout Standard
22547
22548 0x000000
22549 \end_inset 
22550 </cell>
22551 </row>
22552 <row topline="true">
22553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22554 \begin_inset Text
22555
22556 \layout Standard
22557
22558
22559 \family roman 
22560 \series medium 
22561 \shape up 
22562 \size normal 
22563 \emph off 
22564 \bar no 
22565 \noun off 
22566 \color none
22567 1
22568 \end_inset 
22569 </cell>
22570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22571 \begin_inset Text
22572
22573 \layout Standard
22574
22575
22576 \family roman 
22577 \series medium 
22578 \shape up 
22579 \size normal 
22580 \emph off 
22581 \bar no 
22582 \noun off 
22583 \color none
22584 HIGH priority interrupts
22585 \end_inset 
22586 </cell>
22587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22588 \begin_inset Text
22589
22590 \layout Standard
22591
22592 0x000008
22593 \end_inset 
22594 </cell>
22595 </row>
22596 <row topline="true" bottomline="true">
22597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22598 \begin_inset Text
22599
22600 \layout Standard
22601
22602 2
22603 \end_inset 
22604 </cell>
22605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22606 \begin_inset Text
22607
22608 \layout Standard
22609
22610 LOW priority interrupts
22611 \end_inset 
22612 </cell>
22613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22614 \begin_inset Text
22615
22616 \layout Standard
22617
22618 0x000018
22619 \end_inset 
22620 </cell>
22621 </row>
22622 </lyxtabular>
22623
22624 \end_inset 
22625
22626
22627 \layout Standard
22628
22629 When generating assembly code for ISR the code generator places a 
22630 \noun on 
22631 goto 
22632 \noun default 
22633 instruction at the 
22634 \emph on 
22635 Interrupt Vector Address
22636 \emph default 
22637  which points at the genetated ISR.
22638  This single GOTO instruction is part of an automatically generated 
22639 \emph on 
22640 interrupt entry point
22641 \emph default 
22642  function.
22643  The actuall ISR code is placed as normally would in the code space.
22644  Upon interrupt request, the GOTO instruction is executed which jumps to
22645  the ISR code.
22646  When declaring interrupt functions as _naked this GOTO instruction is 
22647 \series bold 
22648 not
22649 \series default 
22650  generated.
22651  The whole interrupt functions is therefore placed at the Interrupt Vector
22652  Address of the specific interrupt.
22653  This is not a problem for the LOW priority interrupts, but it is a problem
22654  for the RESET and the HIGH priority interrupts because code may be written
22655  at the next interrupt´s vector address and cause undeterminate program
22656  behaviour if that interrupt is raised.
22657 \begin_inset Foot
22658 collapsed false
22659
22660 \layout Standard
22661
22662 This is not a problem when
22663 \layout Enumerate
22664
22665 this is a HIGH interrupt ISR and LOW interrupts are 
22666 \emph on 
22667 disabled
22668 \emph default 
22669  or not used.
22670 \layout Enumerate
22671
22672 when the ISR is small enough not to reach the next interrupt´s vector address.
22673 \end_inset 
22674
22675
22676 \layout Standard
22677
22678
22679 \emph on 
22680 n
22681 \emph default 
22682  is possible to be omitted.
22683  This way a function is generated similar to an ISR, but it is not assigned
22684  to any interrupt.
22685 \layout Standard
22686
22687 When entering an interrupt, currently the PIC16
22688 \begin_inset LatexCommand \index{PIC16}
22689
22690 \end_inset 
22691
22692  port automatically saves the following registers:
22693 \layout Itemize
22694
22695 WREG
22696 \layout Itemize
22697
22698 STATUS
22699 \layout Itemize
22700
22701 BSR
22702 \layout Itemize
22703
22704 PROD (PRODL and PRODH)
22705 \layout Itemize
22706
22707 FSR0 (FSR0L and FSR0H)
22708 \layout Standard
22709
22710 These registers are restored upon return from the interrupt routine.
22711 \begin_inset Foot
22712 collapsed false
22713
22714 \layout Standard
22715
22716 NOTE that when the _naked attribute is specified for an interrupt routine,
22717  then NO registers are stored or restored.
22718 \end_inset 
22719
22720
22721 \layout Subsection
22722
22723 Generic Pointers
22724 \layout Standard
22725
22726 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
22727  There are 3 types of generic pointers currently implemented data, code
22728  and eeprom pointers.
22729  They are differentiated by the value of the 7th and 6th bits of the upper
22730  byte:
22731 \layout Standard
22732 \align center 
22733
22734 \begin_inset  Tabular
22735 <lyxtabular version="3" rows="5" columns="5">
22736 <features>
22737 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22738 <column alignment="center" valignment="top" width="0">
22739 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22740 <column alignment="center" valignment="top" width="0">
22741 <column alignment="left" valignment="top" rightline="true" width="0">
22742 <row topline="true" bottomline="true">
22743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22744 \begin_inset Text
22745
22746 \layout Standard
22747
22748 pointer type
22749 \end_inset 
22750 </cell>
22751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22752 \begin_inset Text
22753
22754 \layout Standard
22755
22756 7th bit
22757 \end_inset 
22758 </cell>
22759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22760 \begin_inset Text
22761
22762 \layout Standard
22763
22764 6th bit
22765 \end_inset 
22766 </cell>
22767 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22768 \begin_inset Text
22769
22770 \layout Standard
22771
22772 rest of the pointer
22773 \end_inset 
22774 </cell>
22775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22776 \begin_inset Text
22777
22778 \layout Standard
22779
22780 description
22781 \end_inset 
22782 </cell>
22783 </row>
22784 <row topline="true" bottomline="true">
22785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22786 \begin_inset Text
22787
22788 \layout Standard
22789
22790 data 
22791 \end_inset 
22792 </cell>
22793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22794 \begin_inset Text
22795
22796 \layout Standard
22797
22798 1
22799 \end_inset 
22800 </cell>
22801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22802 \begin_inset Text
22803
22804 \layout Standard
22805
22806 0
22807 \end_inset 
22808 </cell>
22809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22810 \begin_inset Text
22811
22812 \layout Standard
22813
22814
22815 \family typewriter 
22816 \shape slanted 
22817 \emph on 
22818 uuuuuu uuuuxxxx xxxxxxxx
22819 \end_inset 
22820 </cell>
22821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22822 \begin_inset Text
22823
22824 \layout Standard
22825
22826 a 12-bit data pointer in data RAM memory
22827 \end_inset 
22828 </cell>
22829 </row>
22830 <row bottomline="true">
22831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22832 \begin_inset Text
22833
22834 \layout Standard
22835
22836 code
22837 \end_inset 
22838 </cell>
22839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22840 \begin_inset Text
22841
22842 \layout Standard
22843
22844 0
22845 \end_inset 
22846 </cell>
22847 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22848 \begin_inset Text
22849
22850 \layout Standard
22851
22852 0
22853 \end_inset 
22854 </cell>
22855 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22856 \begin_inset Text
22857
22858 \layout Standard
22859
22860
22861 \family typewriter 
22862 \shape slanted 
22863 \emph on 
22864 uxxxxx xxxxxxxx xxxxxxxx
22865 \end_inset 
22866 </cell>
22867 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22868 \begin_inset Text
22869
22870 \layout Standard
22871
22872 a 21-bit code pointer in FLASH memory
22873 \end_inset 
22874 </cell>
22875 </row>
22876 <row bottomline="true">
22877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22878 \begin_inset Text
22879
22880 \layout Standard
22881
22882 eeprom
22883 \end_inset 
22884 </cell>
22885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22886 \begin_inset Text
22887
22888 \layout Standard
22889
22890 0
22891 \end_inset 
22892 </cell>
22893 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22894 \begin_inset Text
22895
22896 \layout Standard
22897
22898 1
22899 \end_inset 
22900 </cell>
22901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22902 \begin_inset Text
22903
22904 \layout Standard
22905
22906
22907 \family typewriter 
22908 \shape slanted 
22909 \emph on 
22910 uuuuuu uuuuuuxx xxxxxxxx
22911 \end_inset 
22912 </cell>
22913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22914 \begin_inset Text
22915
22916 \layout Standard
22917
22918 a 10-bit eeprom pointer in EEPROM memory
22919 \end_inset 
22920 </cell>
22921 </row>
22922 <row bottomline="true">
22923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22924 \begin_inset Text
22925
22926 \layout Standard
22927
22928 (unimplemented)
22929 \end_inset 
22930 </cell>
22931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22932 \begin_inset Text
22933
22934 \layout Standard
22935
22936 1
22937 \end_inset 
22938 </cell>
22939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22940 \begin_inset Text
22941
22942 \layout Standard
22943
22944 1
22945 \end_inset 
22946 </cell>
22947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22948 \begin_inset Text
22949
22950 \layout Standard
22951
22952
22953 \family typewriter 
22954 \shape slanted 
22955 \emph on 
22956 xxxxxx xxxxxxxx xxxxxxxx
22957 \end_inset 
22958 </cell>
22959 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22960 \begin_inset Text
22961
22962 \layout Standard
22963
22964 unimplemented pointer type
22965 \end_inset 
22966 </cell>
22967 </row>
22968 </lyxtabular>
22969
22970 \end_inset 
22971
22972
22973 \layout Standard
22974
22975 Generic pointer are read and written with a set of library functions which
22976  read/write 1, 2, 3, 4 bytes.
22977 \layout Subsection
22978
22979 PIC16 C Libraries
22980 \layout Subsubsection
22981
22982 Standard I/O Streams
22983 \layout Standard
22984
22985 In the 
22986 \emph on 
22987 stdio.h
22988 \emph default 
22989  the type FILE is defined as:
22990 \layout LyX-Code
22991
22992 typedef char * FILE;
22993 \layout Standard
22994
22995 This type is the stream type implemented I/O in the PIC18F devices.
22996  Also the standard input and output streams are declared in stdio.h:
22997 \layout LyX-Code
22998
22999 extern FILE * stdin;
23000 \layout LyX-Code
23001
23002 extern FILE * stdout;
23003 \layout Standard
23004
23005 The FILE type is actually a generic pointer which defines one more type
23006  of generic pointers, the 
23007 \emph on 
23008 stream 
23009 \emph default 
23010 pointer.
23011  This new type has the format:
23012 \layout Standard
23013 \align center 
23014
23015 \begin_inset  Tabular
23016 <lyxtabular version="3" rows="2" columns="7">
23017 <features>
23018 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23019 <column alignment="center" valignment="top" width="0">
23020 <column alignment="center" valignment="top" leftline="true" width="0">
23021 <column alignment="center" valignment="top" leftline="true" width="0">
23022 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23023 <column alignment="center" valignment="top" width="0">
23024 <column alignment="left" valignment="top" rightline="true" width="0">
23025 <row topline="true" bottomline="true">
23026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23027 \begin_inset Text
23028
23029 \layout Standard
23030
23031 pointer type
23032 \end_inset 
23033 </cell>
23034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23035 \begin_inset Text
23036
23037 \layout Standard
23038
23039 <7:6>
23040 \end_inset 
23041 </cell>
23042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23043 \begin_inset Text
23044
23045 \layout Standard
23046
23047 <5>
23048 \end_inset 
23049 </cell>
23050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23051 \begin_inset Text
23052
23053 \layout Standard
23054
23055 <4>
23056 \end_inset 
23057 </cell>
23058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23059 \begin_inset Text
23060
23061 \layout Standard
23062
23063 <3:0>
23064 \end_inset 
23065 </cell>
23066 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23067 \begin_inset Text
23068
23069 \layout Standard
23070
23071 rest of the pointer
23072 \end_inset 
23073 </cell>
23074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23075 \begin_inset Text
23076
23077 \layout Standard
23078
23079 descrption
23080 \end_inset 
23081 </cell>
23082 </row>
23083 <row topline="true" bottomline="true">
23084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23085 \begin_inset Text
23086
23087 \layout Standard
23088
23089 stream
23090 \end_inset 
23091 </cell>
23092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23093 \begin_inset Text
23094
23095 \layout Standard
23096
23097 00
23098 \end_inset 
23099 </cell>
23100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23101 \begin_inset Text
23102
23103 \layout Standard
23104
23105 1
23106 \end_inset 
23107 </cell>
23108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23109 \begin_inset Text
23110
23111 \layout Standard
23112
23113 0
23114 \end_inset 
23115 </cell>
23116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23117 \begin_inset Text
23118
23119 \layout Standard
23120
23121 nnnn
23122 \end_inset 
23123 </cell>
23124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23125 \begin_inset Text
23126
23127 \layout Standard
23128
23129
23130 \family typewriter 
23131 \shape slanted 
23132 \emph on 
23133 uuuuuuuu uuuuuuuu
23134 \end_inset 
23135 </cell>
23136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23137 \begin_inset Text
23138
23139 \layout Standard
23140
23141 upper byte high nubble is 0x2n, the rest are zeroes
23142 \end_inset 
23143 </cell>
23144 </row>
23145 </lyxtabular>
23146
23147 \end_inset 
23148
23149
23150 \layout Standard
23151
23152 Currently implemented there are 3 types of streams defined:
23153 \layout Standard
23154 \align center 
23155
23156 \begin_inset  Tabular
23157 <lyxtabular version="3" rows="4" columns="4">
23158 <features>
23159 <column alignment="center" valignment="top" leftline="true" width="0">
23160 <column alignment="center" valignment="top" leftline="true" width="0">
23161 <column alignment="center" valignment="top" leftline="true" width="0">
23162 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23163 <row topline="true" bottomline="true">
23164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23165 \begin_inset Text
23166
23167 \layout Standard
23168
23169 stream type
23170 \end_inset 
23171 </cell>
23172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23173 \begin_inset Text
23174
23175 \layout Standard
23176
23177 value
23178 \end_inset 
23179 </cell>
23180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23181 \begin_inset Text
23182
23183 \layout Standard
23184
23185 module
23186 \end_inset 
23187 </cell>
23188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23189 \begin_inset Text
23190
23191 \layout Standard
23192
23193 description
23194 \end_inset 
23195 </cell>
23196 </row>
23197 <row topline="true">
23198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23199 \begin_inset Text
23200
23201 \layout Standard
23202
23203 STREAM_USART
23204 \end_inset 
23205 </cell>
23206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23207 \begin_inset Text
23208
23209 \layout Standard
23210
23211
23212 \family typewriter 
23213 0x200000UL
23214 \end_inset 
23215 </cell>
23216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23217 \begin_inset Text
23218
23219 \layout Standard
23220
23221 USART
23222 \end_inset 
23223 </cell>
23224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23225 \begin_inset Text
23226
23227 \layout Standard
23228
23229 Writes/Reads characters via the USART peripheral
23230 \end_inset 
23231 </cell>
23232 </row>
23233 <row topline="true">
23234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23235 \begin_inset Text
23236
23237 \layout Standard
23238
23239 STREAM_MSSP
23240 \end_inset 
23241 </cell>
23242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23243 \begin_inset Text
23244
23245 \layout Standard
23246
23247
23248 \family typewriter 
23249 0x210000UL
23250 \end_inset 
23251 </cell>
23252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23253 \begin_inset Text
23254
23255 \layout Standard
23256
23257 MSSP
23258 \end_inset 
23259 </cell>
23260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23261 \begin_inset Text
23262
23263 \layout Standard
23264
23265 Writes/Reads characters via the MSSP peripheral
23266 \end_inset 
23267 </cell>
23268 </row>
23269 <row topline="true" bottomline="true">
23270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23271 \begin_inset Text
23272
23273 \layout Standard
23274
23275 STREAM_USER
23276 \end_inset 
23277 </cell>
23278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23279 \begin_inset Text
23280
23281 \layout Standard
23282
23283
23284 \family typewriter 
23285 0x2f0000UL
23286 \end_inset 
23287 </cell>
23288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23289 \begin_inset Text
23290
23291 \layout Standard
23292
23293 (none)
23294 \end_inset 
23295 </cell>
23296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23297 \begin_inset Text
23298
23299 \layout Standard
23300
23301 Writes/Reads characters via used defined functions
23302 \end_inset 
23303 </cell>
23304 </row>
23305 </lyxtabular>
23306
23307 \end_inset 
23308
23309
23310 \layout Standard
23311
23312 The stream identifiers are declared as macros in the stdio.h header.
23313 \layout Standard
23314
23315 In the libc library there exist the functions that are used to write to
23316  each of the above streams.
23317  These are
23318 \layout List
23319 \labelwidthstring 00.00.0000
23320
23321 _
23322 \begin_inset ERT
23323 status Collapsed
23324
23325 \layout Standard
23326
23327 \backslash 
23328 /
23329 \end_inset 
23330
23331 _stream_usart_putchar writes a character at the USART stream
23332 \layout List
23333 \labelwidthstring 00.00.0000
23334
23335 _
23336 \begin_inset ERT
23337 status Collapsed
23338
23339 \layout Standard
23340
23341 \backslash 
23342 /
23343 \end_inset 
23344
23345 _stream_mssp_putchar writes a character at the MSSP stream
23346 \layout List
23347 \labelwidthstring 00.00.0000
23348
23349 putchar dummy function.
23350  This writes a character to a user specified manner.
23351 \layout Standard
23352
23353 In order to increase performance 
23354 \emph on 
23355 putchar 
23356 \emph default 
23357 is declared in stdio.h as having its parameter in WREG (it has the wparam
23358  keyword).
23359  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
23360  in a user-friendly way.
23361  
23362 \emph on 
23363 arg
23364 \emph default 
23365  is the name of the variable that holds the character to print.
23366  An example follows:
23367 \layout LyX-Code
23368
23369 #include <pic18fregs.h>
23370 \newline 
23371 #include <stdio.h>
23372 \newline 
23373
23374 \newline 
23375 PUTCHAR( c )
23376 \layout LyX-Code
23377
23378 {
23379 \layout LyX-Code
23380
23381     PORTA = c;    /* dump character c to PORTA */
23382 \layout LyX-Code
23383
23384
23385 \newline 
23386
23387 \newline 
23388 void main(void)
23389 \layout LyX-Code
23390
23391 {
23392 \layout LyX-Code
23393
23394     stdout = STREAM_USER;    /* this is not necessary, since stdout points
23395 \layout LyX-Code
23396
23397                               * by default to STREAM_USER */
23398 \layout LyX-Code
23399
23400     printf (¨This is a printf test
23401 \backslash 
23402 n¨);
23403 \layout LyX-Code
23404
23405 }
23406 \layout LyX-Code
23407
23408 \layout Subsubsection
23409
23410 Printing functions
23411 \layout Standard
23412
23413 PIC16 contains an implementation of the printf-family of functions.
23414  There exist the following functions:
23415 \layout LyX-Code
23416
23417 extern unsigned int sprintf(char *buf, char *fmt, ...);
23418 \layout LyX-Code
23419
23420 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
23421 \layout LyX-Code
23422
23423 \layout LyX-Code
23424
23425 extern unsigned int printf(char *fmt, ...);
23426 \layout LyX-Code
23427
23428 extern unsigned int vprintf(char *fmt, va_lista ap);
23429 \layout LyX-Code
23430
23431 \layout LyX-Code
23432
23433 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
23434 \layout LyX-Code
23435
23436 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
23437 \layout Standard
23438
23439 For sprintf and vsprintf 
23440 \emph on 
23441 buf 
23442 \emph default 
23443 should normally be a data pointer where the resulting string will be placed.
23444  No range checking is done so the user should allocate the necessery buffer.
23445  For fprintf and vfprintf 
23446 \emph on 
23447 fp
23448 \emph default 
23449  should be a stream pointer (i.e.
23450  stdout, STREAM_MSSP, etc...).
23451 \layout Subsubsection
23452
23453 Signals
23454 \layout Standard
23455
23456 The PIC18F family of microcontrollers supports a number of interrupt sources.
23457  A list of these interrupts is shown in the following table:
23458 \layout Standard
23459 \align center 
23460
23461 \begin_inset  Tabular
23462 <lyxtabular version="3" rows="11" columns="4">
23463 <features>
23464 <column alignment="left" valignment="top" leftline="true" width="0">
23465 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23466 <column alignment="left" valignment="top" leftline="true" width="0">
23467 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23468 <row topline="true" bottomline="true">
23469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23470 \begin_inset Text
23471
23472 \layout Standard
23473
23474 signal name
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
23482 description
23483 \end_inset 
23484 </cell>
23485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23486 \begin_inset Text
23487
23488 \layout Standard
23489
23490 signal name
23491 \end_inset 
23492 </cell>
23493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23494 \begin_inset Text
23495
23496 \layout Standard
23497
23498 descritpion
23499 \end_inset 
23500 </cell>
23501 </row>
23502 <row topline="true">
23503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23504 \begin_inset Text
23505
23506 \layout Standard
23507
23508 SIG_RB
23509 \end_inset 
23510 </cell>
23511 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23512 \begin_inset Text
23513
23514 \layout Standard
23515
23516 PORTB change interrupt
23517 \end_inset 
23518 </cell>
23519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23520 \begin_inset Text
23521
23522 \layout Standard
23523
23524 SIG_EE
23525 \end_inset 
23526 </cell>
23527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23528 \begin_inset Text
23529
23530 \layout Standard
23531
23532 EEPROM/FLASH write complete interrupt
23533 \end_inset 
23534 </cell>
23535 </row>
23536 <row topline="true">
23537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23538 \begin_inset Text
23539
23540 \layout Standard
23541
23542 SIG_INT0
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
23550 INT0 external interrupt
23551 \end_inset 
23552 </cell>
23553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23554 \begin_inset Text
23555
23556 \layout Standard
23557
23558 SIG_BCOL
23559 \end_inset 
23560 </cell>
23561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23562 \begin_inset Text
23563
23564 \layout Standard
23565
23566 Bus collision interrupt
23567 \end_inset 
23568 </cell>
23569 </row>
23570 <row topline="true">
23571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23572 \begin_inset Text
23573
23574 \layout Standard
23575
23576 SIG_INT1
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
23584 INT1 external interrupt
23585 \end_inset 
23586 </cell>
23587 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23588 \begin_inset Text
23589
23590 \layout Standard
23591
23592 SIG_LVD
23593 \end_inset 
23594 </cell>
23595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23596 \begin_inset Text
23597
23598 \layout Standard
23599
23600 Low voltage detect interrupt
23601 \end_inset 
23602 </cell>
23603 </row>
23604 <row topline="true">
23605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23606 \begin_inset Text
23607
23608 \layout Standard
23609
23610 SIG_INT2
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 INT2 external interrupt
23619 \end_inset 
23620 </cell>
23621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23622 \begin_inset Text
23623
23624 \layout Standard
23625
23626 SIG_PSP
23627 \end_inset 
23628 </cell>
23629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23630 \begin_inset Text
23631
23632 \layout Standard
23633
23634 Parallel slave port interrupt
23635 \end_inset 
23636 </cell>
23637 </row>
23638 <row topline="true">
23639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23640 \begin_inset Text
23641
23642 \layout Standard
23643
23644 SIG_CCP1
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 CCP1 module interrupt
23653 \end_inset 
23654 </cell>
23655 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23656 \begin_inset Text
23657
23658 \layout Standard
23659
23660 SIG_AD
23661 \end_inset 
23662 </cell>
23663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23664 \begin_inset Text
23665
23666 \layout Standard
23667
23668 AD convertion complete interrupt
23669 \end_inset 
23670 </cell>
23671 </row>
23672 <row topline="true">
23673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23674 \begin_inset Text
23675
23676 \layout Standard
23677
23678 SIG_CCP2
23679 \end_inset 
23680 </cell>
23681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23682 \begin_inset Text
23683
23684 \layout Standard
23685
23686 CCP2 module interrupt
23687 \end_inset 
23688 </cell>
23689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23690 \begin_inset Text
23691
23692 \layout Standard
23693
23694 SIG_RC
23695 \end_inset 
23696 </cell>
23697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23698 \begin_inset Text
23699
23700 \layout Standard
23701
23702 USART receive interrupt
23703 \end_inset 
23704 </cell>
23705 </row>
23706 <row topline="true">
23707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23708 \begin_inset Text
23709
23710 \layout Standard
23711
23712 SIG_TMR0
23713 \end_inset 
23714 </cell>
23715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23716 \begin_inset Text
23717
23718 \layout Standard
23719
23720 TMR0 overflow interrupt
23721 \end_inset 
23722 </cell>
23723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23724 \begin_inset Text
23725
23726 \layout Standard
23727
23728 SIG_TX
23729 \end_inset 
23730 </cell>
23731 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23732 \begin_inset Text
23733
23734 \layout Standard
23735
23736 USART transmit interrupt
23737 \end_inset 
23738 </cell>
23739 </row>
23740 <row topline="true">
23741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23742 \begin_inset Text
23743
23744 \layout Standard
23745
23746 SIG_TMR1
23747 \end_inset 
23748 </cell>
23749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23750 \begin_inset Text
23751
23752 \layout Standard
23753
23754 TMR1 overflow interrupt
23755 \end_inset 
23756 </cell>
23757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23758 \begin_inset Text
23759
23760 \layout Standard
23761
23762 SIG_MSSP
23763 \end_inset 
23764 </cell>
23765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23766 \begin_inset Text
23767
23768 \layout Standard
23769
23770 SSP receive/transmit interrupt
23771 \end_inset 
23772 </cell>
23773 </row>
23774 <row topline="true">
23775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23776 \begin_inset Text
23777
23778 \layout Standard
23779
23780 SIG_TMR2
23781 \end_inset 
23782 </cell>
23783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23784 \begin_inset Text
23785
23786 \layout Standard
23787
23788 TMR2 matches PR2 interrupt
23789 \end_inset 
23790 </cell>
23791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23792 \begin_inset Text
23793
23794 \layout Standard
23795
23796 \end_inset 
23797 </cell>
23798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23799 \begin_inset Text
23800
23801 \layout Standard
23802
23803 \end_inset 
23804 </cell>
23805 </row>
23806 <row topline="true" bottomline="true">
23807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23808 \begin_inset Text
23809
23810 \layout Standard
23811
23812 SIG_TMR3
23813 \end_inset 
23814 </cell>
23815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23816 \begin_inset Text
23817
23818 \layout Standard
23819
23820 TMR3 overflow interrupt
23821 \end_inset 
23822 </cell>
23823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23824 \begin_inset Text
23825
23826 \layout Standard
23827
23828 \end_inset 
23829 </cell>
23830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23831 \begin_inset Text
23832
23833 \layout Standard
23834
23835 \end_inset 
23836 </cell>
23837 </row>
23838 </lyxtabular>
23839
23840 \end_inset 
23841
23842
23843 \layout Standard
23844
23845 The prototypes for these names are defined in the header file 
23846 \emph on 
23847 signal.h
23848 \emph default 
23849  .
23850 \layout Standard
23851
23852 In order to simplify signal handling, a number of macros is provided:
23853 \layout List
23854 \labelwidthstring 00.00.0000
23855
23856 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
23857  high priority interrupts.
23858  
23859 \emph on 
23860 name
23861 \emph default 
23862  is the function name to use.
23863 \layout List
23864 \labelwidthstring 00.00.0000
23865
23866 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
23867  low priority interrupt.
23868  
23869 \emph on 
23870 name
23871 \emph default 
23872  is the function name to use.
23873 \layout List
23874 \labelwidthstring 00.00.0000
23875
23876 DEF_HANDLER(sig,handler) define a handler for signal 
23877 \emph on 
23878 sig.
23879 \layout List
23880 \labelwidthstring 00.00.0000
23881
23882 END_DEF end the declaration of the dispatch table.
23883 \layout Standard
23884
23885 Additionally there are two more macros to simplify the declaration of the
23886  signal handler:
23887 \layout List
23888 \labelwidthstring 00.00.0000
23889
23890
23891 \series medium 
23892 SIGHANDLER(handler) 
23893 \series default 
23894 this declares the function prototype for the 
23895 \emph on 
23896 handler
23897 \emph default 
23898  function.
23899 \layout List
23900 \labelwidthstring 00.00.0000
23901
23902 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
23903 \layout Standard
23904
23905 An example of using the macros above is shown below:
23906 \layout LyX-Code
23907
23908 #include <pic18fregs.h>
23909 \layout LyX-Code
23910
23911 #include <signal.h>
23912 \newline 
23913
23914 \newline 
23915 DEF_INTHIGH(high_int)
23916 \layout LyX-Code
23917
23918 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
23919 \layout LyX-Code
23920
23921 DEF_HANDLER(SIG_BCOL, _bcol_handler)
23922 \layout LyX-Code
23923
23924 END_DEF
23925 \newline 
23926
23927 \newline 
23928 SIGHANDLER(_tmr0_handler)
23929 \layout LyX-Code
23930
23931 {
23932 \layout LyX-Code
23933
23934   /* action to be taken when timer 0 overflows */
23935 \layout LyX-Code
23936
23937 }
23938 \newline 
23939
23940 \newline 
23941 SIGHANDLERNAKED(_bcol_handler)
23942 \layout LyX-Code
23943
23944 {
23945 \layout LyX-Code
23946
23947   _asm
23948 \layout LyX-Code
23949
23950     /* action to be taken when bus collision occurs */
23951 \layout LyX-Code
23952
23953     retfie
23954 \layout LyX-Code
23955
23956  _endasm;
23957 \layout LyX-Code
23958
23959 }
23960 \layout Standard
23961
23962
23963 \series bold 
23964 NOTES:
23965 \series default 
23966  Special care should be taken when using the above scheme:
23967 \layout Itemize
23968
23969 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
23970 \layout Itemize
23971
23972 when declaring SIGHANDLERNAKED handler never forget to use 
23973 \emph on 
23974 retfie
23975 \emph default 
23976  for proper returning.
23977 \layout Subsection
23978
23979 PIC16 Port -- Tips
23980 \layout Standard
23981
23982 Here you can find some general tips for compiling programs with SDCC/pic16.
23983 \layout Subsubsection
23984
23985 Stack size
23986 \layout Standard
23987
23988 The default stack
23989 \begin_inset LatexCommand \index{PIC16!stack}
23990
23991 \end_inset 
23992
23993  size (that is 64 bytes) probably is enough for many programs.
23994  One must take care that when there are many levels of function nesting,
23995  or there is excessive usage of stack, its size should be extended.
23996  An example of such a case is the printf/sprintf family of functions.
23997  If you encounter problems like not being able to print integers, then you
23998  need to set the stack size around the maximum (256 for small stack model).
23999  The following diagram shows what happens when calling printf to print an
24000  integer:
24001 \layout LyX-Code
24002
24003 printf () --> ltoa () --> ultoa () --> divschar ()
24004 \layout Standard
24005
24006 It is should be understood that stack is easily consumed when calling complicate
24007 d functions.
24008  Using command line arguments like -
24009 \begin_inset ERT
24010 status Collapsed
24011
24012 \layout Standard
24013
24014 \backslash 
24015 /
24016 \end_inset 
24017
24018 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
24019  stack frames.
24020  Other ways to reduce stack usage may exist.
24021 \layout Subsection
24022
24023 Known bugs
24024 \layout Standard
24025
24026 The PIC16 Port currently does not pass SDCC's regression test
24027 \begin_inset LatexCommand \index{Regression test (PIC16)}
24028
24029 \end_inset 
24030
24031  suite (see section 
24032 \begin_inset LatexCommand \ref{sec:Quality-control}
24033
24034 \end_inset 
24035
24036 ) and thus the nightly regression tests for the PIC16 target are currently
24037  disabled for all hosts except for 
24038 \emph on 
24039 Linux on Opteron.
24040
24041 \emph default 
24042  This means you can see the result of the PIC16 regression tests f.e.
24043  by checking the log files in 
24044 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/regression_test_results/amd64-unknown-linux2.3/}
24045
24046 \end_inset 
24047
24048  (pick the most up to date file there, scroll down, lend a hand).
24049 \layout Chapter
24050
24051 Debugging
24052 \layout Standard
24053
24054 There are several approaches to debugging your code.
24055  This chapter is meant to show your options and to give detail on some of
24056  them:
24057 \newline 
24058
24059 \newline 
24060 When writing your code:
24061 \layout Itemize
24062
24063 write your code with debugging in mind (avoid duplicating code, put conceptually
24064  similar variables into structs, use structured code, have strategic points
24065  within your code where all variables are consistent, ...)
24066 \layout Itemize
24067
24068 run a syntax-checking tool like splint
24069 \begin_inset LatexCommand \index{splint (syntax checking tool)}
24070
24071 \end_inset 
24072
24073
24074 \begin_inset LatexCommand \index{lint (syntax checking tool)}
24075
24076 \end_inset 
24077
24078  (see -
24079 \begin_inset ERT
24080 status Collapsed
24081
24082 \layout Standard
24083
24084 \backslash 
24085 /
24086 \end_inset 
24087
24088 -more-pedantic 
24089 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
24090
24091 \end_inset 
24092
24093 ) over the code.
24094 \layout Itemize
24095
24096 for the high level code use a C-compiler (like f.e.
24097  GCC) to compile run and debug the code on your host.
24098  See (see -
24099 \begin_inset ERT
24100 status Collapsed
24101
24102 \layout Standard
24103
24104 \backslash 
24105 /
24106 \end_inset 
24107
24108 -more-pedantic 
24109 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
24110
24111 \end_inset 
24112
24113  ) on howto handle syntax extensions like __xdata, __at(), ...
24114  
24115 \layout Itemize
24116
24117 use another C-compiler to compile code for your target.
24118  Always an option but not recommended:) And not very likely to help you.
24119  If you seriously consider walking this path you should at least occasionally
24120  check portability of your code.
24121  Most commercial compiler vendors will offer an evaluation version so you
24122  can test compile your code or snippets of your code.
24123 \layout Standard
24124
24125 Debugging on a simulator:
24126 \layout Itemize
24127
24128 there is a separate section about SDCDB (section 
24129 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
24130
24131 \end_inset 
24132
24133 ) below.
24134 \layout Itemize
24135
24136 or (8051 specific) use a freeware/commercial simulator which interfaces
24137  to the AOMF
24138 \begin_inset LatexCommand \index{AOMF, AOMF51}
24139
24140 \end_inset 
24141
24142  file (see 
24143 \begin_inset LatexCommand \ref{OMF file}
24144
24145 \end_inset 
24146
24147 ) optionally generated by SDCC.
24148 \layout Standard
24149
24150 Debugging On-target: 
24151 \layout Itemize
24152
24153 use a MCU port pin to serially output debug data to the RS232 port of your
24154  host.
24155  You'll probably want some level shifting device typically involving a MAX232
24156  or similar IC.
24157  If the hardware serial port of the MCU is not available search for 'Software
24158  UART' in your favourite search machine.
24159 \layout Itemize
24160
24161 use an on-target monitor.
24162  In this context a monitor is a small program which usually accepts commands
24163  via a serial line and allows to set program counter, to single step through
24164  a program and read/write memory locations.
24165  For the 8051 good examples of monitors are paulmon and cmon51 (see section
24166  
24167 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
24168
24169 \end_inset 
24170
24171 ).
24172 \layout Itemize
24173
24174 toggle MCU port pins at strategic points within your code and use an oscilloscop
24175 e.
24176  A 
24177 \emph on 
24178 digital oscilloscope
24179 \emph default 
24180
24181 \begin_inset LatexCommand \index{Oscilloscope}
24182
24183 \end_inset 
24184
24185  with deep trace memory is really helpful especially if you have to debug
24186  a realtime application.
24187  If you need to monitor more pins than your oscilloscope provides you can
24188  sometimes get away with a small R-2R network.
24189  On a single channel oscilloscope you could f.e.
24190  monitor 2 push-pull driven pins by connecting one via a 10\SpecialChar ~
24191 k
24192 \begin_inset Formula $\Omega$
24193 \end_inset 
24194
24195  resistor and the other one by a 5\SpecialChar ~
24196 k
24197 \begin_inset Formula $\Omega$
24198 \end_inset 
24199
24200  resistor to the oscilloscope probe (check output drive capability of the
24201  pins you want to monitor).
24202  If you need to monitor many more pins a 
24203 \emph on 
24204 logic analyzer
24205 \emph default 
24206  will be handy.
24207 \layout Itemize
24208
24209 use an ICE (
24210 \emph on 
24211 i
24212 \emph default 
24213
24214 \emph on 
24215 c
24216 \emph default 
24217 ircuit 
24218 \emph on 
24219 e
24220 \emph default 
24221 mulator
24222 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
24223
24224 \end_inset 
24225
24226 ).
24227  Usually very expensive.
24228  And very nice to have too.
24229  And usually locks you (for years...) to the devices the ICE can emulate.
24230  
24231 \layout Itemize
24232
24233 use a remote debugger.
24234  In most 8-bit systems the symbol information is not available on the target,
24235  and a complete debugger is too bulky for the target system.
24236  Therefore usually a debugger on the host system connects to an on-target
24237  debugging stub which accepts only primitive commands.
24238  
24239 \newline 
24240 Terms to enter into your favourite search engine could be 'remote debugging',
24241  'gdb stub' or 'inferior debugger'.
24242  (is there one?)
24243 \layout Itemize
24244
24245 use an on target hardware debugger.
24246  Some of the more modern MCUs include hardware support for setting break
24247  points and monitoring/changing variables by using dedicated hardware pins.
24248  This facility doesn't require additional code to run on the target and
24249  
24250 \emph on 
24251 usually
24252 \emph default 
24253  doesn't affect runtime behaviour until a breakpoint is hit.
24254  For the mcs51 most hardware debuggers use the AOMF
24255 \begin_inset LatexCommand \index{AOMF, AOMF51}
24256
24257 \end_inset 
24258
24259  file (see 
24260 \begin_inset LatexCommand \ref{OMF file}
24261
24262 \end_inset 
24263
24264 ) as input file.
24265  
24266 \layout Standard
24267
24268 Last not least:
24269 \layout Itemize
24270
24271 if you are not familiar with any of the following terms you're likely to
24272  run into problems rather sooner than later: 
24273 \emph on 
24274 volatile
24275 \emph default 
24276
24277 \emph on 
24278 atomic
24279 \emph default 
24280
24281 \emph on 
24282 memory map
24283 \emph default 
24284
24285 \emph on 
24286 overlay
24287 \emph default 
24288 .
24289  As an embedded programmer you 
24290 \emph on 
24291 have
24292 \emph default 
24293  to know them so why not look them up 
24294 \emph on 
24295 before
24296 \emph default 
24297  you have problems?)
24298 \layout Itemize
24299
24300 tell someone else about your problem (actually this is a surprisingly effective
24301  means to hunt down the bug even if the listener is not familiar with your
24302  environment).
24303  As 'failure to communicate' is probably one of the job-induced deformations
24304  of an embedded programmer this is highly encouraged.
24305 \layout Section
24306
24307 Debugging with SDCDB
24308 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
24309
24310 \end_inset 
24311
24312
24313 \begin_inset LatexCommand \index{SDCDB (debugger)}
24314
24315 \end_inset 
24316
24317  
24318 \layout Standard
24319
24320 SDCC is distributed with a source level debugger
24321 \begin_inset LatexCommand \index{Debugger}
24322
24323 \end_inset 
24324
24325 .
24326  The debugger uses a command line interface, the command repertoire of the
24327  debugger has been kept as close to gdb
24328 \begin_inset LatexCommand \index{gdb}
24329
24330 \end_inset 
24331
24332  (the GNU debugger) as possible.
24333  The configuration and build process is part of the standard compiler installati
24334 on, which also builds and installs the debugger in the target directory
24335  specified during configuration.
24336  The debugger allows you debug BOTH at the C source and at the ASM source
24337  level.
24338 \layout Subsection
24339
24340 Compiling for Debugging
24341 \layout Standard
24342
24343 The -
24344 \begin_inset ERT
24345 status Collapsed
24346
24347 \layout Standard
24348
24349 \backslash 
24350 /
24351 \end_inset 
24352
24353 -debug
24354 \begin_inset LatexCommand \index{-\/-debug}
24355
24356 \end_inset 
24357
24358  option must be specified for all files for which debug information is to
24359  be generated.
24360  The compiler generates a .adb file for each of these files.
24361  The linker creates the .cdb
24362 \begin_inset LatexCommand \index{<file>.cdb}
24363
24364 \end_inset 
24365
24366  file from the .adb
24367 \begin_inset LatexCommand \index{<file>.adb}
24368
24369 \end_inset 
24370
24371  files and the address information.
24372  This .cdb is used by the debugger.
24373 \layout Subsection
24374
24375 How the Debugger Works
24376 \layout Standard
24377
24378 When the -
24379 \begin_inset ERT
24380 status Collapsed
24381
24382 \layout Standard
24383
24384 \backslash 
24385 /
24386 \end_inset 
24387
24388 -debug option is specified the compiler generates extra symbol information
24389  some of which are put into the assembler source and some are put into the
24390  .adb file.
24391  Then the linker creates the .cdb file from the individual .adb files with
24392  the address information for the symbols.
24393  The debugger reads the symbolic information generated by the compiler &
24394  the address information generated by the linker.
24395  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
24396  execution is controlled by the debugger.
24397  When a command is issued for the debugger, it translates it into appropriate
24398  commands for the simulator.
24399  (Currently SDCDM only connects to the simulator but 
24400 \emph on 
24401 newcdb
24402 \emph default 
24403  at 
24404 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
24405
24406 \end_inset 
24407
24408  is an effort to connect directly to the hardware.) 
24409 \layout Subsection
24410
24411 Starting the Debugger SDCDB
24412 \layout Standard
24413
24414 The debugger can be started using the following command line.
24415  (Assume the file you are debugging has the file name foo).
24416 \newline 
24417
24418 \newline 
24419
24420 \family sans 
24421 \series bold 
24422 sdcdb foo
24423 \newline 
24424
24425 \family default 
24426 \series default 
24427
24428 \newline 
24429 The debugger will look for the following files.
24430 \layout Itemize
24431
24432 foo.c - the source file.
24433 \layout Itemize
24434
24435 foo.cdb - the debugger symbol information file.
24436 \layout Itemize
24437
24438 foo.ihx - the Intel hex format
24439 \begin_inset LatexCommand \index{Intel hex format}
24440
24441 \end_inset 
24442
24443  object file.
24444 \layout Subsection
24445
24446 SDCDB Command Line Options
24447 \layout Itemize
24448
24449 -
24450 \begin_inset ERT
24451 status Collapsed
24452
24453 \layout Standard
24454
24455 \backslash 
24456 /
24457 \end_inset 
24458
24459 -directory=<source file directory> this option can used to specify the directory
24460  search list.
24461  The debugger will look into the directory list specified for source, cdb
24462  & ihx files.
24463  The items in the directory list must be separated by ':', e.g.
24464  if the source files can be in the directories /home/src1 and /home/src2,
24465  the -
24466 \begin_inset ERT
24467 status Collapsed
24468
24469 \layout Standard
24470
24471 \backslash 
24472 /
24473 \end_inset 
24474
24475 -directory option should be -
24476 \begin_inset ERT
24477 status Collapsed
24478
24479 \layout Standard
24480
24481 \backslash 
24482 /
24483 \end_inset 
24484
24485 -directory=/home/src1:/home/src2.
24486  Note there can be no spaces in the option.
24487  
24488 \layout Itemize
24489
24490 -cd <directory> - change to the <directory>.
24491 \layout Itemize
24492
24493 -fullname - used by GUI front ends.
24494 \layout Itemize
24495
24496 -cpu <cpu-type> - this argument is passed to the simulator please see the
24497  simulator docs for details.
24498 \layout Itemize
24499
24500 -X <Clock frequency > this options is passed to the simulator please see
24501  the simulator docs for details.
24502 \layout Itemize
24503
24504 -s <serial port file> passed to simulator see the simulator docs for details.
24505 \layout Itemize
24506
24507 -S <serial in,out> passed to simulator see the simulator docs for details.
24508 \layout Itemize
24509
24510 -k <port number> passed to simulator see the simulator docs for details.
24511 \layout Subsection
24512
24513 SDCDB Debugger Commands
24514 \layout Standard
24515
24516 As mentioned earlier the command interface for the debugger has been deliberatel
24517 y kept as close the GNU debugger gdb, as possible.
24518  This will help the integration with existing graphical user interfaces
24519  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
24520  If you use a graphical user interface for the debugger you can skip this
24521  section.
24522 \layout Subsubsection*
24523
24524 break [line | file:line | function | file:function]
24525 \layout Standard
24526
24527 Set breakpoint at specified line or function:
24528 \newline 
24529
24530 \newline 
24531
24532 \family sans 
24533 \series bold 
24534 sdcdb>break 100 
24535 \newline 
24536 sdcdb>break foo.c:100
24537 \newline 
24538 sdcdb>break funcfoo
24539 \newline 
24540 sdcdb>break foo.c:funcfoo
24541 \layout Subsubsection*
24542
24543 clear [line | file:line | function | file:function ]
24544 \layout Standard
24545
24546 Clear breakpoint at specified line or function:
24547 \newline 
24548
24549 \newline 
24550
24551 \family sans 
24552 \series bold 
24553 sdcdb>clear 100
24554 \newline 
24555 sdcdb>clear foo.c:100
24556 \newline 
24557 sdcdb>clear funcfoo
24558 \newline 
24559 sdcdb>clear foo.c:funcfoo
24560 \layout Subsubsection*
24561
24562 continue
24563 \layout Standard
24564
24565 Continue program being debugged, after breakpoint.
24566 \layout Subsubsection*
24567
24568 finish
24569 \layout Standard
24570
24571 Execute till the end of the current function.
24572 \layout Subsubsection*
24573
24574 delete [n]
24575 \layout Standard
24576
24577 Delete breakpoint number 'n'.
24578  If used without any option clear ALL user defined break points.
24579 \layout Subsubsection*
24580
24581 info [break | stack | frame | registers ]
24582 \layout Itemize
24583
24584 info break - list all breakpoints
24585 \layout Itemize
24586
24587 info stack - show the function call stack.
24588 \layout Itemize
24589
24590 info frame - show information about the current execution frame.
24591 \layout Itemize
24592
24593 info registers - show content of all registers.
24594 \layout Subsubsection*
24595
24596 step
24597 \layout Standard
24598
24599 Step program until it reaches a different source line.
24600  Note: pressing <return> repeats the last command.
24601 \layout Subsubsection*
24602
24603 next
24604 \layout Standard
24605
24606 Step program, proceeding through subroutine calls.
24607 \layout Subsubsection*
24608
24609 run
24610 \layout Standard
24611
24612 Start debugged program.
24613 \layout Subsubsection*
24614
24615 ptype variable 
24616 \layout Standard
24617
24618 Print type information of the variable.
24619 \layout Subsubsection*
24620
24621 print variable
24622 \layout Standard
24623
24624 print value of variable.
24625 \layout Subsubsection*
24626
24627 file filename
24628 \layout Standard
24629
24630 load the given file name.
24631  Note this is an alternate method of loading file for debugging.
24632 \layout Subsubsection*
24633
24634 frame
24635 \layout Standard
24636
24637 print information about current frame.
24638 \layout Subsubsection*
24639
24640 set srcmode
24641 \layout Standard
24642
24643 Toggle between C source & assembly source.
24644 \layout Subsubsection*
24645
24646 ! simulator command
24647 \layout Standard
24648
24649 Send the string following '!' to the simulator, the simulator response is
24650  displayed.
24651  Note the debugger does not interpret the command being sent to the simulator,
24652  so if a command like 'go' is sent the debugger can loose its execution
24653  context and may display incorrect values.
24654 \layout Subsubsection*
24655
24656 quit
24657 \layout Standard
24658
24659 "Watch me now.
24660  Iam going Down.
24661  My name is Bobby Brown"
24662 \layout Subsection
24663
24664 Interfacing SDCDB with DDD
24665 \layout Standard
24666
24667
24668 \begin_inset Note
24669 collapsed true
24670
24671 \layout Standard
24672
24673 The screenshot was converted from png to eps with: 
24674 \begin_inset Quotes sld
24675 \end_inset 
24676
24677 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
24678 \begin_inset Quotes srd
24679 \end_inset 
24680
24681  which produces a pretty compact eps file which is free from compression
24682  artifacts.
24683 \layout Standard
24684
24685 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
24686  as this broke the build system on Sourceforge (pdf-file was broken.
24687  pdflatex does not accept eps files).
24688 \end_inset 
24689
24690
24691 \layout Standard
24692
24693 The 
24694 \emph on 
24695 p
24696 \emph default 
24697 ortable 
24698 \emph on 
24699 n
24700 \emph default 
24701 etwork 
24702 \emph on 
24703 g
24704 \emph default 
24705 raphics File 
24706 \size footnotesize 
24707
24708 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
24709
24710 \end_inset 
24711
24712
24713 \size default 
24714  shows a screenshot of a debugging session with DDD
24715 \begin_inset LatexCommand \index{DDD (debugger)}
24716
24717 \end_inset 
24718
24719  (Unix only) on a simulated 8032.
24720  The debugging session might not run as smoothly as the screenshot suggests.
24721  The debugger allows setting of breakpoints, displaying and changing variables,
24722  single stepping through C and assembler code.
24723  
24724 \newline 
24725 The source was compiled with 
24726 \family sans 
24727 \series bold 
24728
24729 \newline 
24730
24731 \newline 
24732 sdcc -
24733 \family default 
24734 \series default 
24735
24736 \begin_inset ERT
24737 status Collapsed
24738
24739 \layout Standard
24740
24741 \backslash 
24742 /
24743 \end_inset 
24744
24745
24746 \family sans 
24747 \series bold 
24748 -debug ddd_example.c
24749 \family default 
24750 \series default 
24751  
24752 \family sans 
24753 \series bold 
24754
24755 \newline 
24756
24757 \family default 
24758 \series default 
24759
24760 \newline 
24761 and DDD was invoked with 
24762 \family sans 
24763 \series bold 
24764
24765 \newline 
24766
24767 \newline 
24768 ddd -debugger "sdcdb -cpu 8032 ddd_example"
24769 \layout Standard
24770
24771
24772 \begin_inset Note
24773 collapsed false
24774
24775 \layout Standard
24776
24777 Check that the double quotes or an apostroph within the command line survive
24778  the LyX tool chain.
24779  Previously the apostrophs got slanted in the PDF output so a cut and paste
24780  did not work.
24781 \end_inset 
24782
24783
24784 \layout Subsection
24785
24786 Interfacing SDCDB with XEmacs
24787 \begin_inset LatexCommand \index{XEmacs}
24788
24789 \end_inset 
24790
24791
24792 \begin_inset LatexCommand \index{Emacs}
24793
24794 \end_inset 
24795
24796
24797 \layout Standard
24798
24799 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
24800  sdcdb.el and sdcdbsrc.el.
24801  These two files can be found in the $(prefix)/bin directory after the installat
24802 ion is complete.
24803  These files need to be loaded into XEmacs for the interface to work.
24804  This can be done at XEmacs startup time by inserting the following into
24805  your '.xemacs' file (which can be found in your HOME directory): 
24806 \newline 
24807
24808 \newline 
24809
24810 \family typewriter 
24811 (load-file sdcdbsrc.el) 
24812 \family default 
24813
24814 \newline 
24815
24816 \newline 
24817 .xemacs is a lisp file so the () around the command is REQUIRED.
24818  The files can also be loaded dynamically while XEmacs is running, set the
24819  environment variable 'EMACSLOADPATH' to the installation bin directory
24820  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
24821  To start the interface enter the following command: 
24822 \newline 
24823
24824 \newline 
24825
24826 \family sans 
24827 \series bold 
24828 ESC-x sdcdbsrc
24829 \family default 
24830 \series default 
24831
24832 \newline 
24833
24834 \newline 
24835 You will prompted to enter the file name to be debugged.
24836  
24837 \newline 
24838
24839 \newline 
24840 The command line options that are passed to the simulator directly are bound
24841  to default values in the file sdcdbsrc.el.
24842  The variables are listed below, these values maybe changed as required.
24843 \layout Itemize
24844
24845 sdcdbsrc-cpu-type '51
24846 \layout Itemize
24847
24848 sdcdbsrc-frequency '11059200
24849 \layout Itemize
24850
24851 sdcdbsrc-serial nil
24852 \layout Standard
24853
24854 The following is a list of key mapping for the debugger interface.
24855 \layout Standard
24856 \pagebreak_bottom 
24857 \SpecialChar ~
24858
24859 \family typewriter 
24860
24861 \newline 
24862 ;;\SpecialChar ~
24863 Current Listing :: 
24864 \newline 
24865 ;;key\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 binding\SpecialChar ~
24880 \SpecialChar ~
24881 \SpecialChar ~
24882 \SpecialChar ~
24883 \SpecialChar ~
24884 \SpecialChar ~
24885 \SpecialChar ~
24886 \SpecialChar ~
24887 \SpecialChar ~
24888 \SpecialChar ~
24889 \SpecialChar ~
24890 \SpecialChar ~
24891 \SpecialChar ~
24892 \SpecialChar ~
24893 \SpecialChar ~
24894 \SpecialChar ~
24895 \SpecialChar ~
24896 \SpecialChar ~
24897 \SpecialChar ~
24898 \SpecialChar ~
24899 \SpecialChar ~
24900 \SpecialChar ~
24901 Comment 
24902 \newline 
24903 ;;---\SpecialChar ~
24904 \SpecialChar ~
24905 \SpecialChar ~
24906 \SpecialChar ~
24907 \SpecialChar ~
24908 \SpecialChar ~
24909 \SpecialChar ~
24910 \SpecialChar ~
24911 \SpecialChar ~
24912 \SpecialChar ~
24913 \SpecialChar ~
24914 \SpecialChar ~
24915 \SpecialChar ~
24916 \SpecialChar ~
24917 -------\SpecialChar ~
24918 \SpecialChar ~
24919 \SpecialChar ~
24920 \SpecialChar ~
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 -------
24940 \newline 
24941 ;; 
24942 \newline 
24943 ;;\SpecialChar ~
24944 n\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 sdcdb-next-from-src\SpecialChar ~
24960 \SpecialChar ~
24961 \SpecialChar ~
24962 \SpecialChar ~
24963 \SpecialChar ~
24964 \SpecialChar ~
24965 \SpecialChar ~
24966 \SpecialChar ~
24967 \SpecialChar ~
24968 \SpecialChar ~
24969 SDCDB next command 
24970 \newline 
24971 ;;\SpecialChar ~
24972 b\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 \SpecialChar ~
24987 sdcdb-back-from-src\SpecialChar ~
24988 \SpecialChar ~
24989 \SpecialChar ~
24990 \SpecialChar ~
24991 \SpecialChar ~
24992 \SpecialChar ~
24993 \SpecialChar ~
24994 \SpecialChar ~
24995 \SpecialChar ~
24996 \SpecialChar ~
24997 SDCDB back command 
24998 \newline 
24999 ;;\SpecialChar ~
25000 c\SpecialChar ~
25001 \SpecialChar ~
25002 \SpecialChar ~
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 sdcdb-cont-from-src\SpecialChar ~
25016 \SpecialChar ~
25017 \SpecialChar ~
25018 \SpecialChar ~
25019 \SpecialChar ~
25020 \SpecialChar ~
25021 \SpecialChar ~
25022 \SpecialChar ~
25023 \SpecialChar ~
25024 \SpecialChar ~
25025 SDCDB continue command
25026 \newline 
25027 ;;\SpecialChar ~
25028 s\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 sdcdb-step-from-src\SpecialChar ~
25044 \SpecialChar ~
25045 \SpecialChar ~
25046 \SpecialChar ~
25047 \SpecialChar ~
25048 \SpecialChar ~
25049 \SpecialChar ~
25050 \SpecialChar ~
25051 \SpecialChar ~
25052 \SpecialChar ~
25053 SDCDB step command 
25054 \newline 
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 \SpecialChar ~
25069 \SpecialChar ~
25070 \SpecialChar ~
25071 sdcdb-whatis-c-sexp\SpecialChar ~
25072 \SpecialChar ~
25073 \SpecialChar ~
25074 \SpecialChar ~
25075 \SpecialChar ~
25076 \SpecialChar ~
25077 \SpecialChar ~
25078 \SpecialChar ~
25079 \SpecialChar ~
25080 \SpecialChar ~
25081 SDCDB ptypecommand for data at 
25082 \newline 
25083 ;;\SpecialChar ~
25084 \SpecialChar ~
25085 \SpecialChar ~
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 buffer point 
25131 \newline 
25132 ;;\SpecialChar ~
25133 x\SpecialChar ~
25134 \SpecialChar ~
25135 \SpecialChar ~
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 sdcdbsrc-delete\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 SDCDB Delete all breakpoints if no arg 
25163 \newline 
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 \SpecialChar ~
25184 \SpecialChar ~
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 \SpecialChar ~
25202 \SpecialChar ~
25203 \SpecialChar ~
25204 \SpecialChar ~
25205 \SpecialChar ~
25206 \SpecialChar ~
25207 \SpecialChar ~
25208 \SpecialChar ~
25209 \SpecialChar ~
25210 \SpecialChar ~
25211 given or delete arg (C-u arg x) 
25212 \newline 
25213 ;;\SpecialChar ~
25214 m\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 sdcdbsrc-frame\SpecialChar ~
25230 \SpecialChar ~
25231 \SpecialChar ~
25232 \SpecialChar ~
25233 \SpecialChar ~
25234 \SpecialChar ~
25235 \SpecialChar ~
25236 \SpecialChar ~
25237 \SpecialChar ~
25238 \SpecialChar ~
25239 \SpecialChar ~
25240 \SpecialChar ~
25241 \SpecialChar ~
25242 \SpecialChar ~
25243 \SpecialChar ~
25244 SDCDB Display current frame if no arg, 
25245 \newline 
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 \SpecialChar ~
25291 \SpecialChar ~
25292 \SpecialChar ~
25293 given or display frame arg 
25294 \newline 
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 \SpecialChar ~
25309 \SpecialChar ~
25310 \SpecialChar ~
25311 \SpecialChar ~
25312 \SpecialChar ~
25313 \SpecialChar ~
25314 \SpecialChar ~
25315 \SpecialChar ~
25316 \SpecialChar ~
25317 \SpecialChar ~
25318 \SpecialChar ~
25319 \SpecialChar ~
25320 \SpecialChar ~
25321 \SpecialChar ~
25322 \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 \SpecialChar ~
25338 \SpecialChar ~
25339 \SpecialChar ~
25340 \SpecialChar ~
25341 \SpecialChar ~
25342 buffer point 
25343 \newline 
25344 ;;\SpecialChar ~
25345 !\SpecialChar ~
25346 \SpecialChar ~
25347 \SpecialChar ~
25348 \SpecialChar ~
25349 \SpecialChar ~
25350 \SpecialChar ~
25351 \SpecialChar ~
25352 \SpecialChar ~
25353 \SpecialChar ~
25354 \SpecialChar ~
25355 \SpecialChar ~
25356 \SpecialChar ~
25357 \SpecialChar ~
25358 \SpecialChar ~
25359 \SpecialChar ~
25360 sdcdbsrc-goto-sdcdb\SpecialChar ~
25361 \SpecialChar ~
25362 \SpecialChar ~
25363 \SpecialChar ~
25364 \SpecialChar ~
25365 \SpecialChar ~
25366 \SpecialChar ~
25367 \SpecialChar ~
25368 \SpecialChar ~
25369 \SpecialChar ~
25370 Goto the SDCDB output buffer 
25371 \newline 
25372 ;;\SpecialChar ~
25373 p\SpecialChar ~
25374 \SpecialChar ~
25375 \SpecialChar ~
25376 \SpecialChar ~
25377 \SpecialChar ~
25378 \SpecialChar ~
25379 \SpecialChar ~
25380 \SpecialChar ~
25381 \SpecialChar ~
25382 \SpecialChar ~
25383 \SpecialChar ~
25384 \SpecialChar ~
25385 \SpecialChar ~
25386 \SpecialChar ~
25387 \SpecialChar ~
25388 sdcdb-print-c-sexp\SpecialChar ~
25389 \SpecialChar ~
25390 \SpecialChar ~
25391 \SpecialChar ~
25392 \SpecialChar ~
25393 \SpecialChar ~
25394 \SpecialChar ~
25395 \SpecialChar ~
25396 \SpecialChar ~
25397 \SpecialChar ~
25398 \SpecialChar ~
25399 SDCDB print command for data at 
25400 \newline 
25401 ;;\SpecialChar ~
25402 \SpecialChar ~
25403 \SpecialChar ~
25404 \SpecialChar ~
25405 \SpecialChar ~
25406 \SpecialChar ~
25407 \SpecialChar ~
25408 \SpecialChar ~
25409 \SpecialChar ~
25410 \SpecialChar ~
25411 \SpecialChar ~
25412 \SpecialChar ~
25413 \SpecialChar ~
25414 \SpecialChar ~
25415 \SpecialChar ~
25416 \SpecialChar ~
25417 \SpecialChar ~
25418 \SpecialChar ~
25419 \SpecialChar ~
25420 \SpecialChar ~
25421 \SpecialChar ~
25422 \SpecialChar ~
25423 \SpecialChar ~
25424 \SpecialChar ~
25425 \SpecialChar ~
25426 \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 \SpecialChar ~
25443 \SpecialChar ~
25444 \SpecialChar ~
25445 \SpecialChar ~
25446 \SpecialChar ~
25447 \SpecialChar ~
25448 buffer point 
25449 \newline 
25450 ;;\SpecialChar ~
25451 g\SpecialChar ~
25452 \SpecialChar ~
25453 \SpecialChar ~
25454 \SpecialChar ~
25455 \SpecialChar ~
25456 \SpecialChar ~
25457 \SpecialChar ~
25458 \SpecialChar ~
25459 \SpecialChar ~
25460 \SpecialChar ~
25461 \SpecialChar ~
25462 \SpecialChar ~
25463 \SpecialChar ~
25464 \SpecialChar ~
25465 \SpecialChar ~
25466 sdcdbsrc-goto-sdcdb\SpecialChar ~
25467 \SpecialChar ~
25468 \SpecialChar ~
25469 \SpecialChar ~
25470 \SpecialChar ~
25471 \SpecialChar ~
25472 \SpecialChar ~
25473 \SpecialChar ~
25474 \SpecialChar ~
25475 \SpecialChar ~
25476 Goto the SDCDB output buffer 
25477 \newline 
25478 ;;\SpecialChar ~
25479 t\SpecialChar ~
25480 \SpecialChar ~
25481 \SpecialChar ~
25482 \SpecialChar ~
25483 \SpecialChar ~
25484 \SpecialChar ~
25485 \SpecialChar ~
25486 \SpecialChar ~
25487 \SpecialChar ~
25488 \SpecialChar ~
25489 \SpecialChar ~
25490 \SpecialChar ~
25491 \SpecialChar ~
25492 \SpecialChar ~
25493 \SpecialChar ~
25494 sdcdbsrc-mode\SpecialChar ~
25495 \SpecialChar ~
25496 \SpecialChar ~
25497 \SpecialChar ~
25498 \SpecialChar ~
25499 \SpecialChar ~
25500 \SpecialChar ~
25501 \SpecialChar ~
25502 \SpecialChar ~
25503 \SpecialChar ~
25504 \SpecialChar ~
25505 \SpecialChar ~
25506 \SpecialChar ~
25507 \SpecialChar ~
25508 \SpecialChar ~
25509 \SpecialChar ~
25510 Toggles Sdcdbsrc mode (turns it off) 
25511 \newline 
25512 ;; 
25513 \newline 
25514 ;;\SpecialChar ~
25515 C-c\SpecialChar ~
25516 C-f\SpecialChar ~
25517 \SpecialChar ~
25518 \SpecialChar ~
25519 \SpecialChar ~
25520 \SpecialChar ~
25521 \SpecialChar ~
25522 \SpecialChar ~
25523 \SpecialChar ~
25524 \SpecialChar ~
25525 sdcdb-finish-from-src\SpecialChar ~
25526 \SpecialChar ~
25527 \SpecialChar ~
25528 \SpecialChar ~
25529 \SpecialChar ~
25530 \SpecialChar ~
25531 \SpecialChar ~
25532 \SpecialChar ~
25533 SDCDB finish command 
25534 \newline 
25535 ;; 
25536 \newline 
25537 ;;\SpecialChar ~
25538 C-x\SpecialChar ~
25539 SPC\SpecialChar ~
25540 \SpecialChar ~
25541 \SpecialChar ~
25542 \SpecialChar ~
25543 \SpecialChar ~
25544 \SpecialChar ~
25545 \SpecialChar ~
25546 \SpecialChar ~
25547 \SpecialChar ~
25548 sdcdb-break\SpecialChar ~
25549 \SpecialChar ~
25550 \SpecialChar ~
25551 \SpecialChar ~
25552 \SpecialChar ~
25553 \SpecialChar ~
25554 \SpecialChar ~
25555 \SpecialChar ~
25556 \SpecialChar ~
25557 \SpecialChar ~
25558 \SpecialChar ~
25559 \SpecialChar ~
25560 \SpecialChar ~
25561 \SpecialChar ~
25562 \SpecialChar ~
25563 \SpecialChar ~
25564 \SpecialChar ~
25565 \SpecialChar ~
25566 Set break for line with point 
25567 \newline 
25568 ;;\SpecialChar ~
25569 ESC\SpecialChar ~
25570 t\SpecialChar ~
25571 \SpecialChar ~
25572 \SpecialChar ~
25573 \SpecialChar ~
25574 \SpecialChar ~
25575 \SpecialChar ~
25576 \SpecialChar ~
25577 \SpecialChar ~
25578 \SpecialChar ~
25579 \SpecialChar ~
25580 \SpecialChar ~
25581 sdcdbsrc-mode\SpecialChar ~
25582 \SpecialChar ~
25583 \SpecialChar ~
25584 \SpecialChar ~
25585 \SpecialChar ~
25586 \SpecialChar ~
25587 \SpecialChar ~
25588 \SpecialChar ~
25589 \SpecialChar ~
25590 \SpecialChar ~
25591 \SpecialChar ~
25592 \SpecialChar ~
25593 \SpecialChar ~
25594 \SpecialChar ~
25595 \SpecialChar ~
25596 \SpecialChar ~
25597 Toggle Sdcdbsrc mode 
25598 \newline 
25599 ;;\SpecialChar ~
25600 ESC\SpecialChar ~
25601 m\SpecialChar ~
25602 \SpecialChar ~
25603 \SpecialChar ~
25604 \SpecialChar ~
25605 \SpecialChar ~
25606 \SpecialChar ~
25607 \SpecialChar ~
25608 \SpecialChar ~
25609 \SpecialChar ~
25610 \SpecialChar ~
25611 \SpecialChar ~
25612 sdcdbsrc-srcmode\SpecialChar ~
25613 \SpecialChar ~
25614 \SpecialChar ~
25615 \SpecialChar ~
25616 \SpecialChar ~
25617 \SpecialChar ~
25618 \SpecialChar ~
25619 \SpecialChar ~
25620 \SpecialChar ~
25621 \SpecialChar ~
25622 \SpecialChar ~
25623 \SpecialChar ~
25624 \SpecialChar ~
25625 Toggle list mode 
25626 \newline 
25627 ;; 
25628 \newline 
25629
25630 \layout Chapter
25631
25632 TIPS
25633 \layout Standard
25634
25635 Here are a few guidelines that will help the compiler generate more efficient
25636  code, some of the tips are specific to this compiler others are generally
25637  good programming practice.
25638 \layout Itemize
25639
25640 Use the smallest data type to represent your data-value.
25641  If it is known in advance that the value is going to be less than 256 then
25642  use an 'unsigned char' instead of a 'short' or 'int'.
25643  Please note, that ANSI C requires both signed and unsigned chars to be
25644  promoted to 'signed int'
25645 \begin_inset LatexCommand \index{promotion to signed int}
25646
25647 \end_inset 
25648
25649
25650 \begin_inset Marginal
25651 collapsed true
25652
25653 \layout Standard
25654
25655
25656 \series bold 
25657 \SpecialChar ~
25658 !
25659 \end_inset 
25660
25661  before doing any operation.
25662  This promotion
25663 \begin_inset LatexCommand \index{type promotion}
25664
25665 \end_inset 
25666
25667
25668 \begin_inset LatexCommand \label{type promotion}
25669
25670 \end_inset 
25671
25672  can be omitted, if the result is the same.
25673  The effect of the promotion rules together with the sign-extension is often
25674  surprising:
25675 \begin_deeper 
25676 \layout Verse
25677
25678
25679 \family typewriter 
25680 unsigned char uc = 0xfe;
25681 \newline 
25682 if (uc * uc < 0) /* this is true! */
25683 \newline 
25684 {
25685 \newline 
25686 \SpecialChar ~
25687 \SpecialChar ~
25688 \SpecialChar ~
25689 \SpecialChar ~
25690 ....
25691 \newline 
25692 }
25693 \layout Standard
25694
25695
25696 \family typewriter 
25697 uc * uc
25698 \family default 
25699  is evaluated as 
25700 \family typewriter 
25701 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
25702 \family default 
25703 .
25704  
25705 \newline 
25706 Another one:
25707 \layout Verse
25708
25709
25710 \family typewriter 
25711 (unsigned char) -12 / (signed char) -3 = ...
25712 \layout Standard
25713
25714 No, the result is not 4:
25715 \layout Verse
25716
25717
25718 \family typewriter 
25719 (int) (unsigned char) -12 / (int) (signed char) -3 =
25720 \newline 
25721 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
25722 \newline 
25723 (int) 0x00f4 / (int) 0xfffd =
25724 \newline 
25725 (int) 0x00f4 / (int) 0xfffd =
25726 \newline 
25727 (int) 244 / (int) -3 =
25728 \newline 
25729 (int) -81 = (int) 0xffaf;
25730 \layout Standard
25731
25732 Don't complain, that gcc gives you a different result.
25733  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
25734  Therefore the results are different.
25735 \newline 
25736 From 
25737 \begin_inset Quotes sld
25738 \end_inset 
25739
25740 comp.lang.c FAQ
25741 \begin_inset Quotes srd
25742 \end_inset 
25743
25744 :
25745 \layout Quote
25746
25747
25748 \emph on 
25749 If well-defined overflow characteristics are important and negative values
25750  are not, or if you want to steer clear of sign-extension problems when
25751  manipulating bits or bytes, use one of the corresponding unsigned types.
25752  (Beware when mixing signed and unsigned values in expressions, though.)
25753 \newline 
25754 Although character types (especially unsigned char) can be used as "tiny"
25755  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
25756 ble sign extension and increased code size.
25757 \end_deeper 
25758 \layout Itemize
25759
25760 Use unsigned when it is known in advance that the value is not going to
25761  be negative.
25762  This helps especially if you are doing division or multiplication, bit-shifting
25763  or are using an array index.
25764 \layout Itemize
25765
25766 NEVER jump into a LOOP.
25767 \layout Itemize
25768
25769 Declare the variables to be local
25770 \begin_inset LatexCommand \index{local variables}
25771
25772 \end_inset 
25773
25774  whenever possible, especially loop control variables (induction).
25775 \layout Itemize
25776
25777 Have a look at the assembly listing to get a 
25778 \begin_inset Quotes sld
25779 \end_inset 
25780
25781 feeling
25782 \begin_inset Quotes srd
25783 \end_inset 
25784
25785  for the code generation.
25786 \layout Section
25787
25788 Porting code from or to other compilers
25789 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
25790
25791 \end_inset 
25792
25793
25794 \layout Itemize
25795
25796 check whether endianness of the compilers differs and adapt where needed.
25797 \layout Itemize
25798
25799 check the device specific header files
25800 \begin_inset LatexCommand \index{Header files}
25801
25802 \end_inset 
25803
25804
25805 \begin_inset LatexCommand \index{Include files}
25806
25807 \end_inset 
25808
25809  for compiler specific syntax.
25810  Eventually include the file <compiler.h
25811 \begin_inset LatexCommand \index{compiler.h (include file)}
25812
25813 \end_inset 
25814
25815
25816 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
25817
25818 \end_inset 
25819
25820  to allow using common header files.
25821  (see f.e.
25822  cc2510fx.h 
25823 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
25824
25825 \end_inset 
25826
25827 ).
25828 \layout Itemize
25829
25830 check whether the startup code contains the correct initialization (watchdog,
25831  peripherals).
25832 \layout Itemize
25833
25834 check whether the sizes of short, int, long match.
25835 \layout Itemize
25836
25837 check if some 16 or 32 bit hardware registers require a specific addressing
25838  order (least significant or most significant byte first) and adapt if needed
25839  (
25840 \emph on 
25841 first
25842 \emph default 
25843  and 
25844 \emph on 
25845 last
25846 \emph default 
25847  relate to time and not to lower/upper memory location here, so this is
25848  
25849 \emph on 
25850 not
25851 \emph default 
25852  the same as endianness).
25853 \layout Itemize
25854
25855 check whether the keyword 
25856 \emph on 
25857 volatile
25858 \emph default 
25859  is used where needed.
25860  The compilers might differ in their optimization characteristics (as different
25861  versions of the same compiler might also use more clever optimizations
25862  this is good idea anyway).
25863  See section 
25864 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
25865
25866 \end_inset 
25867
25868 .
25869 \layout Itemize
25870
25871 check that the compilers are not told to supress warnings.
25872 \layout Itemize
25873
25874 check and convert compiler specific extensions (interrupts, memory areas,
25875  pragmas etc.).
25876 \layout Itemize
25877
25878 check for differences in type promotion.
25879  Especially check for math operations on 
25880 \family typewriter 
25881 char
25882 \family default 
25883  or 
25884 \family typewriter 
25885 unsigned char
25886 \family default 
25887  variables.
25888  For the sake of C99 compatibility SDCC will probably promote these to 
25889 \family typewriter 
25890 int
25891 \family default 
25892  more often than other compilers.
25893  Eventually insert explicit casts to 
25894 \family typewriter 
25895 (char) 
25896 \family default 
25897 or
25898 \family typewriter 
25899  (unsigned char)
25900 \family default 
25901 .
25902  Also check that the ~\SpecialChar ~
25903 operator
25904 \begin_inset LatexCommand \index{\~\/ Operator}
25905
25906 \end_inset 
25907
25908  is not used on 
25909 \family typewriter 
25910 bit
25911 \begin_inset LatexCommand \index{bit}
25912
25913 \end_inset 
25914
25915
25916 \family default 
25917  variables, use the !\SpecialChar ~
25918 operator instead.
25919  See sections 
25920 \begin_inset LatexCommand \ref{type promotion}
25921
25922 \end_inset 
25923
25924  and 
25925 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
25926
25927 \end_inset 
25928
25929 .
25930 \layout Itemize
25931
25932 check the assembly code generated for interrupt routines (f.e.
25933  for calls to possibly non-reentrant library functions).
25934 \layout Itemize
25935
25936 check whether timing loops result in proper timing (or preferably consider
25937  a rewrite of the code with timer based delays instead).
25938 \layout Itemize
25939
25940 check for differences in printf parameters (some compilers push (va_arg
25941 \begin_inset LatexCommand \index{vararg, va\_arg}
25942
25943 \end_inset 
25944
25945 ) char variables as 
25946 \family typewriter 
25947 int
25948 \family default 
25949  others push them as 
25950 \family typewriter 
25951 char
25952 \family default 
25953 .
25954  See section 
25955 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
25956
25957 \end_inset 
25958
25959 ).
25960 \layout Itemize
25961
25962 check the resulting memory map
25963 \begin_inset LatexCommand \index{Memory map}
25964
25965 \end_inset 
25966
25967 .
25968  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
25969 ly idata, pdata, xdata).
25970  Eventually check if unexpected library functions are included.
25971 \layout Section
25972
25973 Tools
25974 \begin_inset LatexCommand \index{Tools}
25975
25976 \end_inset 
25977
25978  included in the distribution
25979 \layout Standard
25980 \align left 
25981
25982 \begin_inset  Tabular
25983 <lyxtabular version="3" rows="12" columns="3">
25984 <features>
25985 <column alignment="left" valignment="top" leftline="true" width="0pt">
25986 <column alignment="left" valignment="top" leftline="true" width="0pt">
25987 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
25988 <row topline="true" bottomline="true">
25989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25990 \begin_inset Text
25991
25992 \layout Standard
25993
25994
25995 \series bold 
25996 Name
25997 \end_inset 
25998 </cell>
25999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26000 \begin_inset Text
26001
26002 \layout Standard
26003
26004
26005 \series bold 
26006 Purpose
26007 \end_inset 
26008 </cell>
26009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26010 \begin_inset Text
26011
26012 \layout Standard
26013
26014
26015 \series bold 
26016 Directory
26017 \end_inset 
26018 </cell>
26019 </row>
26020 <row topline="true">
26021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26022 \begin_inset Text
26023
26024 \layout Standard
26025
26026 uCsim
26027 \begin_inset LatexCommand \index{uCsim}
26028
26029 \end_inset 
26030
26031
26032 \end_inset 
26033 </cell>
26034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26035 \begin_inset Text
26036
26037 \layout Standard
26038
26039 Simulator for various architectures
26040 \end_inset 
26041 </cell>
26042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26043 \begin_inset Text
26044
26045 \layout Standard
26046
26047 sdcc/sim/ucsim
26048 \end_inset 
26049 </cell>
26050 </row>
26051 <row topline="true">
26052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26053 \begin_inset Text
26054
26055 \layout Standard
26056
26057 keil2sdcc.pl
26058 \end_inset 
26059 </cell>
26060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26061 \begin_inset Text
26062
26063 \layout Standard
26064
26065 header file
26066 \begin_inset LatexCommand \index{Header files}
26067
26068 \end_inset 
26069
26070
26071 \begin_inset LatexCommand \index{Include files}
26072
26073 \end_inset 
26074
26075  conversion
26076 \end_inset 
26077 </cell>
26078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26079 \begin_inset Text
26080
26081 \layout Standard
26082
26083 sdcc/support/scripts
26084 \end_inset 
26085 </cell>
26086 </row>
26087 <row topline="true">
26088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26089 \begin_inset Text
26090
26091 \layout Standard
26092
26093 mh2h.c
26094 \end_inset 
26095 </cell>
26096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26097 \begin_inset Text
26098
26099 \layout Standard
26100
26101 header file conversion
26102 \end_inset 
26103 </cell>
26104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26105 \begin_inset Text
26106
26107 \layout Standard
26108
26109 sdcc/support/scripts
26110 \end_inset 
26111 </cell>
26112 </row>
26113 <row topline="true">
26114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26115 \begin_inset Text
26116
26117 \layout Standard
26118
26119 as-gbz80
26120 \end_inset 
26121 </cell>
26122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26123 \begin_inset Text
26124
26125 \layout Standard
26126
26127 Assembler
26128 \end_inset 
26129 </cell>
26130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26131 \begin_inset Text
26132
26133 \layout Standard
26134
26135
26136 \family roman 
26137 \series medium 
26138 \shape up 
26139 \size normal 
26140 \emph off 
26141 \bar no 
26142 \noun off 
26143 \color none
26144 sdcc/bin
26145 \end_inset 
26146 </cell>
26147 </row>
26148 <row topline="true">
26149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26150 \begin_inset Text
26151
26152 \layout Standard
26153
26154 as-z80
26155 \end_inset 
26156 </cell>
26157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26158 \begin_inset Text
26159
26160 \layout Standard
26161
26162 Assembler
26163 \end_inset 
26164 </cell>
26165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26166 \begin_inset Text
26167
26168 \layout Standard
26169
26170
26171 \family roman 
26172 \series medium 
26173 \shape up 
26174 \size normal 
26175 \emph off 
26176 \bar no 
26177 \noun off 
26178 \color none
26179 sdcc/bin
26180 \end_inset 
26181 </cell>
26182 </row>
26183 <row topline="true">
26184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26185 \begin_inset Text
26186
26187 \layout Standard
26188
26189 asx8051
26190 \end_inset 
26191 </cell>
26192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26193 \begin_inset Text
26194
26195 \layout Standard
26196
26197 Assembler
26198 \end_inset 
26199 </cell>
26200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26201 \begin_inset Text
26202
26203 \layout Standard
26204
26205
26206 \family roman 
26207 \series medium 
26208 \shape up 
26209 \size normal 
26210 \emph off 
26211 \bar no 
26212 \noun off 
26213 \color none
26214 sdcc/bin
26215 \end_inset 
26216 </cell>
26217 </row>
26218 <row topline="true">
26219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26220 \begin_inset Text
26221
26222 \layout Standard
26223
26224 SDCDB
26225 \end_inset 
26226 </cell>
26227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26228 \begin_inset Text
26229
26230 \layout Standard
26231
26232 Simulator
26233 \end_inset 
26234 </cell>
26235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26236 \begin_inset Text
26237
26238 \layout Standard
26239
26240
26241 \family roman 
26242 \series medium 
26243 \shape up 
26244 \size normal 
26245 \emph off 
26246 \bar no 
26247 \noun off 
26248 \color none
26249 sdcc/bin
26250 \end_inset 
26251 </cell>
26252 </row>
26253 <row topline="true">
26254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26255 \begin_inset Text
26256
26257 \layout Standard
26258
26259 aslink
26260 \end_inset 
26261 </cell>
26262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26263 \begin_inset Text
26264
26265 \layout Standard
26266
26267 Linker
26268 \end_inset 
26269 </cell>
26270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26271 \begin_inset Text
26272
26273 \layout Standard
26274
26275
26276 \family roman 
26277 \series medium 
26278 \shape up 
26279 \size normal 
26280 \emph off 
26281 \bar no 
26282 \noun off 
26283 \color none
26284 sdcc/bin
26285 \end_inset 
26286 </cell>
26287 </row>
26288 <row topline="true">
26289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26290 \begin_inset Text
26291
26292 \layout Standard
26293
26294 link-z80
26295 \end_inset 
26296 </cell>
26297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26298 \begin_inset Text
26299
26300 \layout Standard
26301
26302 Linker
26303 \end_inset 
26304 </cell>
26305 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26306 \begin_inset Text
26307
26308 \layout Standard
26309
26310
26311 \family roman 
26312 \series medium 
26313 \shape up 
26314 \size normal 
26315 \emph off 
26316 \bar no 
26317 \noun off 
26318 \color none
26319 sdcc/bin
26320 \end_inset 
26321 </cell>
26322 </row>
26323 <row topline="true">
26324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26325 \begin_inset Text
26326
26327 \layout Standard
26328
26329 link-gbz80
26330 \end_inset 
26331 </cell>
26332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26333 \begin_inset Text
26334
26335 \layout Standard
26336
26337 Linker
26338 \end_inset 
26339 </cell>
26340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26341 \begin_inset Text
26342
26343 \layout Standard
26344
26345
26346 \family roman 
26347 \series medium 
26348 \shape up 
26349 \size normal 
26350 \emph off 
26351 \bar no 
26352 \noun off 
26353 \color none
26354 sdcc/bin
26355 \end_inset 
26356 </cell>
26357 </row>
26358 <row topline="true" bottomline="true">
26359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26360 \begin_inset Text
26361
26362 \layout Standard
26363
26364 packihx
26365 \end_inset 
26366 </cell>
26367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26368 \begin_inset Text
26369
26370 \layout Standard
26371
26372 Intel Hex packer 
26373 \begin_inset LatexCommand \index{packihx (tool)}
26374
26375 \end_inset 
26376
26377
26378 \end_inset 
26379 </cell>
26380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26381 \begin_inset Text
26382
26383 \layout Standard
26384
26385
26386 \family roman 
26387 \series medium 
26388 \shape up 
26389 \size normal 
26390 \emph off 
26391 \bar no 
26392 \noun off 
26393 \color none
26394 sdcc/bin
26395 \end_inset 
26396 </cell>
26397 </row>
26398 </lyxtabular>
26399
26400 \end_inset 
26401
26402
26403 \newline 
26404
26405 \layout Section
26406
26407 Documentation
26408 \begin_inset LatexCommand \index{Documentation}
26409
26410 \end_inset 
26411
26412  included in the distribution
26413 \layout Standard
26414 \align left 
26415
26416 \begin_inset  Tabular
26417 <lyxtabular version="3" rows="10" columns="2">
26418 <features>
26419 <column alignment="block" valignment="top" leftline="true" width="40col%">
26420 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
26421 <row topline="true" bottomline="true" endhead="true">
26422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26423 \begin_inset Text
26424
26425 \layout Standard
26426
26427
26428 \series bold 
26429 Subject / Title
26430 \end_inset 
26431 </cell>
26432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26433 \begin_inset Text
26434
26435 \layout Standard
26436
26437
26438 \series bold 
26439 Filename / Where to get
26440 \end_inset 
26441 </cell>
26442 </row>
26443 <row topline="true">
26444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26445 \begin_inset Text
26446
26447 \layout Standard
26448
26449 SDCC Compiler User Guide
26450 \end_inset 
26451 </cell>
26452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26453 \begin_inset Text
26454
26455 \layout Standard
26456
26457 You're reading it right now
26458 \emph on 
26459  \SpecialChar ~
26460 \SpecialChar ~
26461 \SpecialChar ~
26462
26463 \hfill 
26464 online at:
26465 \emph default 
26466
26467 \newline 
26468
26469 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
26470
26471 \end_inset 
26472
26473
26474 \end_inset 
26475 </cell>
26476 </row>
26477 <row topline="true">
26478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26479 \begin_inset Text
26480
26481 \layout Standard
26482
26483 Changelog of SDCC
26484 \end_inset 
26485 </cell>
26486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26487 \begin_inset Text
26488
26489 \layout Standard
26490
26491 sdcc/Changelog
26492 \emph on 
26493  \SpecialChar ~
26494 \SpecialChar ~
26495 \SpecialChar ~
26496
26497 \hfill 
26498 online at:
26499 \emph default 
26500
26501 \newline 
26502
26503 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
26504
26505 \end_inset 
26506
26507
26508 \end_inset 
26509 </cell>
26510 </row>
26511 <row topline="true">
26512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26513 \begin_inset Text
26514
26515 \layout Standard
26516
26517 ASXXXX
26518 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
26519
26520 \end_inset 
26521
26522
26523 \begin_inset LatexCommand \index{Assembler documentation}
26524
26525 \end_inset 
26526
26527  Assemblers and
26528 \newline 
26529 ASLINK
26530 \begin_inset LatexCommand \index{aslink}
26531
26532 \end_inset 
26533
26534
26535 \begin_inset LatexCommand \index{Linker documentation}
26536
26537 \end_inset 
26538
26539  Relocating Linker
26540 \end_inset 
26541 </cell>
26542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26543 \begin_inset Text
26544
26545 \layout Standard
26546
26547 sdcc/as/doc/asxhtm.html 
26548 \emph on 
26549 \SpecialChar ~
26550 \SpecialChar ~
26551 \SpecialChar ~
26552
26553 \hfill 
26554 online at:
26555 \emph default 
26556
26557 \newline 
26558
26559 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
26560
26561 \end_inset 
26562
26563
26564 \end_inset 
26565 </cell>
26566 </row>
26567 <row topline="true">
26568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26569 \begin_inset Text
26570
26571 \layout Standard
26572
26573 SDCC regression test
26574 \begin_inset LatexCommand \index{Regression test}
26575
26576 \end_inset 
26577
26578
26579 \end_inset 
26580 </cell>
26581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26582 \begin_inset Text
26583
26584 \layout Standard
26585
26586 sdcc/doc/test_suite_spec.pdf 
26587 \emph on 
26588 \SpecialChar ~
26589 \SpecialChar ~
26590 \SpecialChar ~
26591
26592 \hfill 
26593 online at:
26594 \emph default 
26595
26596 \newline 
26597
26598 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
26599
26600 \end_inset 
26601
26602
26603 \end_inset 
26604 </cell>
26605 </row>
26606 <row topline="true">
26607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26608 \begin_inset Text
26609
26610 \layout Standard
26611
26612 Various notes
26613 \end_inset 
26614 </cell>
26615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26616 \begin_inset Text
26617
26618 \layout Standard
26619
26620 sdcc/doc/* 
26621 \emph on 
26622 \SpecialChar ~
26623 \SpecialChar ~
26624 \SpecialChar ~
26625
26626 \hfill 
26627 online at:
26628 \emph default 
26629
26630 \newline 
26631
26632 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
26633
26634 \end_inset 
26635
26636
26637 \end_inset 
26638 </cell>
26639 </row>
26640 <row topline="true">
26641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26642 \begin_inset Text
26643
26644 \layout Standard
26645
26646 Notes on debugging with SDCDB
26647 \begin_inset LatexCommand \index{SDCDB (debugger)}
26648
26649 \end_inset 
26650
26651
26652 \end_inset 
26653 </cell>
26654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26655 \begin_inset Text
26656
26657 \layout Standard
26658
26659 sdcc/debugger/README 
26660 \emph on 
26661 \SpecialChar ~
26662 \SpecialChar ~
26663 \SpecialChar ~
26664
26665 \hfill 
26666 online at
26667 \emph default 
26668 :
26669 \newline 
26670
26671 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
26672
26673 \end_inset 
26674
26675
26676 \end_inset 
26677 </cell>
26678 </row>
26679 <row topline="true">
26680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26681 \begin_inset Text
26682
26683 \layout Standard
26684
26685 uCsim
26686 \begin_inset LatexCommand \index{uCsim}
26687
26688 \end_inset 
26689
26690  Software simulator for microcontrollers
26691 \end_inset 
26692 </cell>
26693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26694 \begin_inset Text
26695
26696 \layout Standard
26697
26698
26699 \family roman 
26700 \series medium 
26701 \shape up 
26702 \size normal 
26703 \emph off 
26704 \bar no 
26705 \noun off 
26706 \color none
26707 sdcc/sim/ucsim/doc
26708 \family default 
26709 \series default 
26710 \shape default 
26711 \size default 
26712 \emph default 
26713 \bar default 
26714 \noun default 
26715 /index.html 
26716 \emph on 
26717 \SpecialChar ~
26718 \SpecialChar ~
26719 \SpecialChar ~
26720
26721 \hfill 
26722 online at:
26723 \emph default 
26724
26725 \newline 
26726
26727 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
26728
26729 \end_inset 
26730
26731
26732 \end_inset 
26733 </cell>
26734 </row>
26735 <row topline="true">
26736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26737 \begin_inset Text
26738
26739 \layout Standard
26740
26741 Temporary notes on the pic16
26742 \begin_inset LatexCommand \index{PIC16}
26743
26744 \end_inset 
26745
26746  port
26747 \end_inset 
26748 </cell>
26749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26750 \begin_inset Text
26751
26752 \layout Standard
26753
26754 sdcc/src/pic16/NOTES 
26755 \emph on 
26756 \SpecialChar ~
26757 \SpecialChar ~
26758 \SpecialChar ~
26759
26760 \hfill 
26761 online at:
26762 \newline 
26763
26764 \emph default 
26765
26766 \begin_inset LatexCommand \url{http://svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
26767
26768 \end_inset 
26769
26770
26771 \end_inset 
26772 </cell>
26773 </row>
26774 <row topline="true" bottomline="true">
26775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26776 \begin_inset Text
26777
26778 \layout Standard
26779
26780 SDCC internal documentation (debugging file format)
26781 \end_inset 
26782 </cell>
26783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26784 \begin_inset Text
26785
26786 \layout Standard
26787
26788 sdcc/doc/
26789 \family roman 
26790 \series medium 
26791 \shape up 
26792 \size normal 
26793 \emph off 
26794 \bar no 
26795 \noun off 
26796 \color none
26797 cdbfileformat.pd
26798 \family default 
26799 \series default 
26800 \shape default 
26801 \size default 
26802 \emph default 
26803 \bar default 
26804 \noun default 
26805 f
26806 \emph on 
26807  \SpecialChar ~
26808 \SpecialChar ~
26809 \SpecialChar ~
26810
26811 \hfill 
26812 online at:
26813 \emph default 
26814
26815 \newline 
26816
26817 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
26818
26819 \end_inset 
26820
26821
26822 \end_inset 
26823 </cell>
26824 </row>
26825 </lyxtabular>
26826
26827 \end_inset 
26828
26829
26830 \newline 
26831
26832 \layout Section
26833
26834 Related open source tools
26835 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
26836
26837 \end_inset 
26838
26839
26840 \begin_inset LatexCommand \index{Related tools}
26841
26842 \end_inset 
26843
26844
26845 \layout Standard
26846 \align left 
26847
26848 \begin_inset  Tabular
26849 <lyxtabular version="3" rows="14" columns="3">
26850 <features>
26851 <column alignment="left" valignment="top" leftline="true" width="0pt">
26852 <column alignment="block" valignment="top" leftline="true" width="30line%">
26853 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
26854 <row topline="true" bottomline="true">
26855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26856 \begin_inset Text
26857
26858 \layout Standard
26859
26860
26861 \series bold 
26862 Name
26863 \end_inset 
26864 </cell>
26865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26866 \begin_inset Text
26867
26868 \layout Standard
26869
26870
26871 \series bold 
26872 Purpose
26873 \end_inset 
26874 </cell>
26875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26876 \begin_inset Text
26877
26878 \layout Standard
26879
26880
26881 \series bold 
26882 Where to get
26883 \end_inset 
26884 </cell>
26885 </row>
26886 <row topline="true">
26887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26888 \begin_inset Text
26889
26890 \layout Standard
26891
26892 gpsim
26893 \begin_inset LatexCommand \index{gpsim (pic simulator)}
26894
26895 \end_inset 
26896
26897
26898 \end_inset 
26899 </cell>
26900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26901 \begin_inset Text
26902
26903 \layout Standard
26904
26905 PIC simulator
26906 \end_inset 
26907 </cell>
26908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26909 \begin_inset Text
26910
26911 \layout Standard
26912
26913
26914 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
26915
26916 \end_inset 
26917
26918
26919 \end_inset 
26920 </cell>
26921 </row>
26922 <row topline="true">
26923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26924 \begin_inset Text
26925
26926 \layout Standard
26927
26928 gputils
26929 \begin_inset LatexCommand \index{gputils (pic tools)}
26930
26931 \end_inset 
26932
26933
26934 \end_inset 
26935 </cell>
26936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26937 \begin_inset Text
26938
26939 \layout Standard
26940
26941 GNU PIC utilities
26942 \end_inset 
26943 </cell>
26944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26945 \begin_inset Text
26946
26947 \layout Standard
26948
26949
26950 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
26951
26952 \end_inset 
26953
26954
26955 \end_inset 
26956 </cell>
26957 </row>
26958 <row topline="true">
26959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26960 \begin_inset Text
26961
26962 \layout Standard
26963
26964 flP5
26965 \end_inset 
26966 </cell>
26967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26968 \begin_inset Text
26969
26970 \layout Standard
26971
26972 PIC programmer
26973 \end_inset 
26974 </cell>
26975 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26976 \begin_inset Text
26977
26978 \layout Standard
26979
26980
26981 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
26982
26983 \end_inset 
26984
26985
26986 \end_inset 
26987 </cell>
26988 </row>
26989 <row topline="true">
26990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26991 \begin_inset Text
26992
26993 \layout Standard
26994
26995 ec2drv/newcdb
26996 \end_inset 
26997 </cell>
26998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26999 \begin_inset Text
27000
27001 \layout Standard
27002
27003 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
27004  (Unix only)
27005 \end_inset 
27006 </cell>
27007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27008 \begin_inset Text
27009
27010 \layout Standard
27011
27012
27013 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
27014
27015 \end_inset 
27016
27017
27018 \end_inset 
27019 </cell>
27020 </row>
27021 <row topline="true">
27022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27023 \begin_inset Text
27024
27025 \layout Standard
27026
27027 indent
27028 \begin_inset LatexCommand \index{indent (source formatting tool)}
27029
27030 \end_inset 
27031
27032
27033 \end_inset 
27034 </cell>
27035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27036 \begin_inset Text
27037
27038 \layout Standard
27039
27040 Formats C source - Master of the white spaces
27041 \end_inset 
27042 </cell>
27043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27044 \begin_inset Text
27045
27046 \layout Standard
27047
27048
27049 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
27050
27051 \end_inset 
27052
27053
27054 \end_inset 
27055 </cell>
27056 </row>
27057 <row topline="true">
27058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27059 \begin_inset Text
27060
27061 \layout Standard
27062
27063 srecord
27064 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
27065
27066 \end_inset 
27067
27068
27069 \end_inset 
27070 </cell>
27071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27072 \begin_inset Text
27073
27074 \layout Standard
27075
27076 Object file conversion, checksumming, ...
27077 \end_inset 
27078 </cell>
27079 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27080 \begin_inset Text
27081
27082 \layout Standard
27083
27084
27085 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
27086
27087 \end_inset 
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
27099 objdump
27100 \begin_inset LatexCommand \index{objdump (tool)}
27101
27102 \end_inset 
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
27112 Object file conversion, ...
27113 \end_inset 
27114 </cell>
27115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27116 \begin_inset Text
27117
27118 \layout Standard
27119
27120 Part of binutils (should be there anyway)
27121 \end_inset 
27122 </cell>
27123 </row>
27124 <row topline="true">
27125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27126 \begin_inset Text
27127
27128 \layout Standard
27129
27130 cmon51
27131 \end_inset 
27132 </cell>
27133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27134 \begin_inset Text
27135
27136 \layout Standard
27137
27138 8051 monitor (hex up-/download, single step, disassemble)
27139 \end_inset 
27140 </cell>
27141 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27142 \begin_inset Text
27143
27144 \layout Standard
27145
27146
27147 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
27148
27149 \end_inset 
27150
27151
27152 \end_inset 
27153 </cell>
27154 </row>
27155 <row topline="true">
27156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27157 \begin_inset Text
27158
27159 \layout Standard
27160
27161 doxygen
27162 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
27163
27164 \end_inset 
27165
27166
27167 \end_inset 
27168 </cell>
27169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27170 \begin_inset Text
27171
27172 \layout Standard
27173
27174 Source code documentation system
27175 \end_inset 
27176 </cell>
27177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27178 \begin_inset Text
27179
27180 \layout Standard
27181
27182
27183 \begin_inset LatexCommand \url{http://www.doxygen.org}
27184
27185 \end_inset 
27186
27187
27188 \end_inset 
27189 </cell>
27190 </row>
27191 <row topline="true">
27192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27193 \begin_inset Text
27194
27195 \layout Standard
27196
27197 kdevelop
27198 \end_inset 
27199 </cell>
27200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27201 \begin_inset Text
27202
27203 \layout Standard
27204
27205 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
27206 \end_inset 
27207 </cell>
27208 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27209 \begin_inset Text
27210
27211 \layout Standard
27212
27213
27214 \begin_inset LatexCommand \url{http://www.kdevelop.org}
27215
27216 \end_inset 
27217
27218
27219 \end_inset 
27220 </cell>
27221 </row>
27222 <row topline="true">
27223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27224 \begin_inset Text
27225
27226 \layout Standard
27227
27228 paulmon
27229 \end_inset 
27230 </cell>
27231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27232 \begin_inset Text
27233
27234 \layout Standard
27235
27236 8051 monitor (hex up-/download, single step, disassemble)
27237 \end_inset 
27238 </cell>
27239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27240 \begin_inset Text
27241
27242 \layout Standard
27243
27244
27245 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
27246
27247 \end_inset 
27248
27249
27250 \end_inset 
27251 </cell>
27252 </row>
27253 <row topline="true">
27254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27255 \begin_inset Text
27256
27257 \layout Standard
27258
27259 splint
27260 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27261
27262 \end_inset 
27263
27264
27265 \end_inset 
27266 </cell>
27267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27268 \begin_inset Text
27269
27270 \layout Standard
27271
27272 Statically checks c sources (see 
27273 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27274
27275 \end_inset 
27276
27277 )
27278 \end_inset 
27279 </cell>
27280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27281 \begin_inset Text
27282
27283 \layout Standard
27284
27285
27286 \begin_inset LatexCommand \url{http://www.splint.org}
27287
27288 \end_inset 
27289
27290
27291 \end_inset 
27292 </cell>
27293 </row>
27294 <row topline="true" bottomline="true">
27295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27296 \begin_inset Text
27297
27298 \layout Standard
27299
27300 ddd
27301 \begin_inset LatexCommand \index{DDD (debugger)}
27302
27303 \end_inset 
27304
27305
27306 \end_inset 
27307 </cell>
27308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27309 \begin_inset Text
27310
27311 \layout Standard
27312
27313 Debugger, serves nicely as GUI to SDCDB
27314 \begin_inset LatexCommand \index{SDCDB (debugger)}
27315
27316 \end_inset 
27317
27318  (Unix only)
27319 \end_inset 
27320 </cell>
27321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27322 \begin_inset Text
27323
27324 \layout Standard
27325
27326
27327 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
27328
27329 \end_inset 
27330
27331
27332 \end_inset 
27333 </cell>
27334 </row>
27335 </lyxtabular>
27336
27337 \end_inset 
27338
27339
27340 \newline 
27341
27342 \layout Section
27343
27344 Related documentation / recommended reading
27345 \layout Standard
27346 \align left 
27347
27348 \begin_inset  Tabular
27349 <lyxtabular version="3" rows="7" columns="3">
27350 <features>
27351 <column alignment="left" valignment="top" leftline="true" width="0pt">
27352 <column alignment="left" valignment="top" leftline="true" width="0">
27353 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
27354 <row topline="true" bottomline="true">
27355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27356 \begin_inset Text
27357
27358 \layout Standard
27359
27360
27361 \series bold 
27362 Name
27363 \end_inset 
27364 </cell>
27365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27366 \begin_inset Text
27367
27368 \layout Standard
27369
27370
27371 \series bold 
27372 Subject / Title
27373 \end_inset 
27374 </cell>
27375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27376 \begin_inset Text
27377
27378 \layout Standard
27379
27380
27381 \series bold 
27382 Where to get
27383 \end_inset 
27384 </cell>
27385 </row>
27386 <row topline="true">
27387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27388 \begin_inset Text
27389
27390 \layout Standard
27391
27392
27393 \family roman 
27394 \series medium 
27395 \shape up 
27396 \size normal 
27397 \emph off 
27398 \bar no 
27399 \noun off 
27400 \color none
27401 c-refcard.pdf
27402 \end_inset 
27403 </cell>
27404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27405 \begin_inset Text
27406
27407 \layout Standard
27408
27409 C Reference Card
27410 \begin_inset LatexCommand \index{C Reference card}
27411
27412 \end_inset 
27413
27414 , 2 pages
27415 \end_inset 
27416 </cell>
27417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27418 \begin_inset Text
27419
27420 \layout Standard
27421
27422
27423 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
27424
27425 \end_inset 
27426
27427
27428 \end_inset 
27429 </cell>
27430 </row>
27431 <row topline="true">
27432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27433 \begin_inset Text
27434
27435 \layout Standard
27436
27437 c-faq
27438 \end_inset 
27439 </cell>
27440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27441 \begin_inset Text
27442
27443 \layout Standard
27444
27445 C-FAQ
27446 \begin_inset LatexCommand \index{C FAQ}
27447
27448 \end_inset 
27449
27450
27451 \end_inset 
27452 </cell>
27453 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27454 \begin_inset Text
27455
27456 \layout Standard
27457
27458
27459 \begin_inset LatexCommand \url{http://www.c-faq.com}
27460
27461 \end_inset 
27462
27463
27464 \end_inset 
27465 </cell>
27466 </row>
27467 <row topline="true">
27468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27469 \begin_inset Text
27470
27471 \layout Standard
27472
27473 ISO/IEC 9899:TC2
27474 \end_inset 
27475 </cell>
27476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27477 \begin_inset Text
27478
27479 \layout Standard
27480
27481
27482 \begin_inset Quotes sld
27483 \end_inset 
27484
27485 C-Standard
27486 \begin_inset Quotes srd
27487 \end_inset 
27488
27489
27490 \end_inset 
27491 </cell>
27492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27493 \begin_inset Text
27494
27495 \layout Standard
27496
27497
27498 \size footnotesize 
27499
27500 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
27501
27502 \end_inset 
27503
27504
27505 \end_inset 
27506 </cell>
27507 </row>
27508 <row topline="true">
27509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27510 \begin_inset Text
27511
27512 \layout Standard
27513
27514 ISO/IEC DTR 18037
27515 \end_inset 
27516 </cell>
27517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27518 \begin_inset Text
27519
27520 \layout Standard
27521
27522
27523 \begin_inset Quotes sld
27524 \end_inset 
27525
27526 Extensions for Embedded C
27527 \begin_inset Quotes srd
27528 \end_inset 
27529
27530
27531 \end_inset 
27532 </cell>
27533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27534 \begin_inset Text
27535
27536 \layout Standard
27537
27538
27539 \size footnotesize 
27540
27541 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
27542
27543 \end_inset 
27544
27545
27546 \end_inset 
27547 </cell>
27548 </row>
27549 <row topline="true">
27550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27551 \begin_inset Text
27552
27553 \layout Standard
27554
27555 \end_inset 
27556 </cell>
27557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27558 \begin_inset Text
27559
27560 \layout Standard
27561
27562 Latest datasheet of target CPU
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 vendor
27571 \end_inset 
27572 </cell>
27573 </row>
27574 <row topline="true" bottomline="true">
27575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27576 \begin_inset Text
27577
27578 \layout Standard
27579
27580 \end_inset 
27581 </cell>
27582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27583 \begin_inset Text
27584
27585 \layout Standard
27586
27587 Revision history of datasheet
27588 \end_inset 
27589 </cell>
27590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27591 \begin_inset Text
27592
27593 \layout Standard
27594
27595 vendor
27596 \end_inset 
27597 </cell>
27598 </row>
27599 </lyxtabular>
27600
27601 \end_inset 
27602
27603
27604 \newline 
27605
27606 \layout Section
27607
27608 Application notes specifically for SDCC
27609 \layout Standard
27610
27611 SDCC makes no claims about the completeness of this list and about up-to-datenes
27612 s or correctness of the application notes
27613 \begin_inset LatexCommand \index{Application notes}
27614
27615 \end_inset 
27616
27617 .
27618 \layout Standard
27619 \align left 
27620
27621 \size footnotesize 
27622
27623 \begin_inset  Tabular
27624 <lyxtabular version="3" rows="7" columns="3">
27625 <features>
27626 <column alignment="block" valignment="top" leftline="true" width="17col%">
27627 <column alignment="block" valignment="top" leftline="true" width="27col%">
27628 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
27629 <row topline="true" bottomline="true">
27630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27631 \begin_inset Text
27632
27633 \layout Standard
27634
27635
27636 \series bold 
27637 \size footnotesize 
27638 Vendor
27639 \end_inset 
27640 </cell>
27641 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
27642 \begin_inset Text
27643
27644 \layout Standard
27645
27646
27647 \series bold 
27648 \size footnotesize 
27649 Subject / Title
27650 \end_inset 
27651 </cell>
27652 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27653 \begin_inset Text
27654
27655 \layout Standard
27656
27657
27658 \series bold 
27659 \size footnotesize 
27660 Where to get
27661 \end_inset 
27662 </cell>
27663 </row>
27664 <row topline="true">
27665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27666 \begin_inset Text
27667
27668 \layout Standard
27669
27670
27671 \size footnotesize 
27672 Maxim / Dallas
27673 \end_inset 
27674 </cell>
27675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27676 \begin_inset Text
27677
27678 \layout Standard
27679
27680
27681 \size footnotesize 
27682 Using the SDCC Compiler for the DS80C400
27683 \begin_inset LatexCommand \index{DS80C400}
27684
27685 \end_inset 
27686
27687
27688 \end_inset 
27689 </cell>
27690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27691 \begin_inset Text
27692
27693 \layout Standard
27694
27695
27696 \size footnotesize 
27697
27698 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
27699
27700 \end_inset 
27701
27702
27703 \end_inset 
27704 </cell>
27705 </row>
27706 <row topline="true">
27707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27708 \begin_inset Text
27709
27710 \layout Standard
27711
27712
27713 \size footnotesize 
27714 Maxim / Dallas
27715 \end_inset 
27716 </cell>
27717 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
27718 \begin_inset Text
27719
27720 \layout Standard
27721
27722
27723 \size footnotesize 
27724 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
27725 \begin_inset LatexCommand \index{DS89C4x0}
27726
27727 \end_inset 
27728
27729  Family of Microcontrollers
27730 \end_inset 
27731 </cell>
27732 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27733 \begin_inset Text
27734
27735 \layout Standard
27736
27737
27738 \size footnotesize 
27739
27740 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
27741
27742 \end_inset 
27743
27744
27745 \end_inset 
27746 </cell>
27747 </row>
27748 <row topline="true">
27749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27750 \begin_inset Text
27751
27752 \layout Standard
27753
27754
27755 \size footnotesize 
27756 Silicon Laboratories / Cygnal
27757 \end_inset 
27758 </cell>
27759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27760 \begin_inset Text
27761
27762 \layout Standard
27763
27764
27765 \size footnotesize 
27766 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
27767 \begin_inset LatexCommand \index{IDE}
27768
27769 \end_inset 
27770
27771
27772 \end_inset 
27773 </cell>
27774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27775 \begin_inset Text
27776
27777 \layout Standard
27778
27779
27780 \size footnotesize 
27781
27782 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
27783
27784 \end_inset 
27785
27786
27787 \end_inset 
27788 </cell>
27789 </row>
27790 <row topline="true">
27791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27792 \begin_inset Text
27793
27794 \layout Standard
27795
27796
27797 \size footnotesize 
27798 Ramtron / Goal Semiconductor
27799 \end_inset 
27800 </cell>
27801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27802 \begin_inset Text
27803
27804 \layout Standard
27805
27806
27807 \size footnotesize 
27808 Interfacing SDCC to Syn and Textpad
27809 \end_inset 
27810 </cell>
27811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27812 \begin_inset Text
27813
27814 \layout Standard
27815
27816
27817 \size footnotesize 
27818
27819 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
27820
27821 \end_inset 
27822
27823
27824 \end_inset 
27825 </cell>
27826 </row>
27827 <row topline="true">
27828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27829 \begin_inset Text
27830
27831 \layout Standard
27832
27833
27834 \size footnotesize 
27835 Ramtron / Goal Semiconductor
27836 \end_inset 
27837 </cell>
27838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27839 \begin_inset Text
27840
27841 \layout Standard
27842
27843
27844 \size footnotesize 
27845 Installing and Configuring SDCC and Crimson Editor 
27846 \end_inset 
27847 </cell>
27848 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27849 \begin_inset Text
27850
27851 \layout Standard
27852
27853
27854 \size footnotesize 
27855
27856 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
27857
27858 \end_inset 
27859
27860
27861 \end_inset 
27862 </cell>
27863 </row>
27864 <row topline="true" bottomline="true">
27865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27866 \begin_inset Text
27867
27868 \layout Standard
27869
27870
27871 \size footnotesize 
27872 Texas Instruments
27873 \end_inset 
27874 </cell>
27875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27876 \begin_inset Text
27877
27878 \layout Standard
27879
27880
27881 \size footnotesize 
27882 MSC12xx Programming with SDCC
27883 \end_inset 
27884 </cell>
27885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27886 \begin_inset Text
27887
27888 \layout Standard
27889
27890
27891 \size footnotesize 
27892
27893 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
27894
27895 \end_inset 
27896
27897
27898 \end_inset 
27899 </cell>
27900 </row>
27901 </lyxtabular>
27902
27903 \end_inset 
27904
27905
27906 \layout Section
27907
27908 Some Questions
27909 \layout Standard
27910
27911 Some questions answered, some pointers given - it might be time to in turn
27912  ask 
27913 \emph on 
27914 you
27915 \emph default 
27916  some questions: 
27917 \layout Itemize
27918
27919 can you solve your project with the selected microcontroller? Would you
27920  find out early or rather late that your target is too small/slow/whatever?
27921  Can you switch to a slightly better device if it doesn't fit?
27922 \layout Itemize
27923
27924 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
27925  and/or another programming language be more adequate? Would an operating
27926  system on the target device help?
27927 \layout Itemize
27928
27929 if you solved the problem, will the marketing department be happy?
27930 \layout Itemize
27931
27932 if the marketing department is happy, will customers be happy?
27933 \layout Itemize
27934
27935 if you're the project manager, marketing department and maybe even the customer
27936  in one person, have you tried to see the project from the outside?
27937 \layout Itemize
27938
27939 is the project done if you think it is done? Or is just that other interface/pro
27940 tocol/feature/configuration/option missing? How about website, manual(s),
27941  internationali(z|s)ation, packaging, labels, 2nd source for components,
27942  electromagnetic compatability/interference, documentation for production,
27943  production test software, update mechanism, patent issues?
27944 \layout Itemize
27945
27946 is your project adequately positioned in that magic triangle: fame, fortune,
27947  fun?
27948 \layout Standard
27949
27950 Maybe not all answers to these questions are known and some answers may
27951  even be 
27952 \emph on 
27953 no
27954 \emph default 
27955 , nevertheless knowing these questions may help you to avoid burnout
27956 \begin_inset Foot
27957 collapsed false
27958
27959 \layout Standard
27960
27961 burnout is bad for electronic devices, programmers and motorcycle tyres
27962 \end_inset 
27963
27964 .
27965  Chances are you didn't want to hear some of them...
27966 \layout Chapter
27967
27968 Support
27969 \begin_inset LatexCommand \index{Support}
27970
27971 \end_inset 
27972
27973
27974 \layout Standard
27975
27976 SDCC has grown to be a large project.
27977  The compiler alone (without the preprocessor, assembler and linker) is
27978  well over 150,000 lines of code (blank stripped).
27979  The open source nature of this project is a key to its continued growth
27980  and support.
27981  You gain the benefit and support of many active software developers and
27982  end users.
27983  Is SDCC perfect? No, that's why we need your help.
27984  The developers take pride in fixing reported bugs.
27985  You can help by reporting the bugs and helping other SDCC users.
27986  There are lots of ways to contribute, and we encourage you to take part
27987  in making SDCC a great software package.
27988  
27989 \layout Standard
27990
27991 The SDCC project is hosted on the SDCC sourceforge site at 
27992 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
27993
27994 \end_inset 
27995
27996 .
27997  You'll find the complete set of mailing lists
27998 \begin_inset LatexCommand \index{Mailing list(s)}
27999
28000 \end_inset 
28001
28002 , forums, bug reporting system, patch submission
28003 \begin_inset LatexCommand \index{Patch submission}
28004
28005 \end_inset 
28006
28007  system, download
28008 \begin_inset LatexCommand \index{download}
28009
28010 \end_inset 
28011
28012  area and Subversion code repository
28013 \begin_inset LatexCommand \index{Subversion code repository}
28014
28015 \end_inset 
28016
28017  there.
28018 \layout Section
28019
28020 Reporting Bugs
28021 \begin_inset LatexCommand \index{Bug reporting}
28022
28023 \end_inset 
28024
28025
28026 \begin_inset LatexCommand \index{Reporting bugs}
28027
28028 \end_inset 
28029
28030
28031 \layout Standard
28032
28033 The recommended way of reporting bugs is using the infrastructure of the
28034  sourceforge site.
28035  You can follow the status of bug reports there and have an overview about
28036  the known bugs.
28037 \layout Standard
28038
28039 Bug reports are automatically forwarded to the developer mailing list and
28040  will be fixed ASAP.
28041  When reporting a bug, it is very useful to include a small test program
28042  (the smaller the better) which reproduces the problem.
28043  If you can isolate the problem by looking at the generated assembly code,
28044  this can be very helpful.
28045  Compiling your program with the -
28046 \begin_inset ERT
28047 status Collapsed
28048
28049 \layout Standard
28050
28051 \backslash 
28052 /
28053 \end_inset 
28054
28055 -dumpall
28056 \begin_inset LatexCommand \index{-\/-dumpall}
28057
28058 \end_inset 
28059
28060  option can sometimes be useful in locating optimization problems.
28061  When reporting a bug please make sure you:
28062 \layout Enumerate
28063
28064 Attach the code you are compiling with SDCC.
28065  
28066 \layout Enumerate
28067
28068 Specify the exact command you use to run SDCC, or attach your Makefile.
28069  
28070 \layout Enumerate
28071
28072 Specify the SDCC version (type "
28073 \family sans 
28074 \series bold 
28075 sdcc -v
28076 \family default 
28077 \series default 
28078 "), your platform, and operating system.
28079  
28080 \layout Enumerate
28081
28082 Provide an exact copy of any error message or incorrect output.
28083  
28084 \layout Enumerate
28085
28086 Put something meaningful in the subject of your message.
28087 \layout Standard
28088
28089 Please attempt to include these 5 important parts, as applicable, in all
28090  requests for support or when reporting any problems or bugs with SDCC.
28091  Though this will make your message lengthy, it will greatly improve your
28092  chance that SDCC users and developers will be able to help you.
28093  Some SDCC developers are frustrated by bug reports without code provided
28094  that they can use to reproduce and ultimately fix the problem, so please
28095  be sure to provide sample code if you are reporting a bug! 
28096 \layout Standard
28097
28098 Please have a short check that you are using a recent version of SDCC and
28099  the bug is not yet known.
28100  This is the link for reporting bugs: 
28101 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
28102
28103 \end_inset 
28104
28105 .
28106  With SDCC on average having more than 200 downloads
28107 \begin_inset LatexCommand \index{download}
28108
28109 \end_inset 
28110
28111  on sourceforge per day
28112 \begin_inset Foot
28113 collapsed false
28114
28115 \layout Standard
28116
28117 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
28118  between 2002 and 2005.
28119  This does not include other methods of distribution.
28120 \end_inset 
28121
28122  there must be some users.
28123  So it's not exactly easy to find a new bug.
28124  If you find one we need it: 
28125 \emph on 
28126 reporting bugs is good
28127 \emph default 
28128 .
28129 \layout Section
28130
28131 Requesting Features
28132 \begin_inset LatexCommand \label{sub:Requesting-Features}
28133
28134 \end_inset 
28135
28136
28137 \begin_inset LatexCommand \index{Feature request}
28138
28139 \end_inset 
28140
28141
28142 \begin_inset LatexCommand \index{Requesting features}
28143
28144 \end_inset 
28145
28146
28147 \layout Standard
28148
28149 Like bug reports feature requests are forwarded to the developer mailing
28150  list.
28151  This is the link for requesting features: 
28152 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
28153
28154 \end_inset 
28155
28156 .
28157 \layout Section
28158
28159 Submitting patches
28160 \layout Standard
28161
28162 Like bug reports contributed patches are forwarded to the developer mailing
28163  list.
28164  This is the link for submitting patches
28165 \begin_inset LatexCommand \index{Patch submission}
28166
28167 \end_inset 
28168
28169
28170 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
28171
28172 \end_inset 
28173
28174 .
28175 \layout Standard
28176
28177 You need to specify some parameters to the 
28178 \family typewriter 
28179 diff
28180 \family default 
28181  command for the patches to be useful.
28182  If you modified more than one file a patch created f.e.
28183  with 
28184 \family sans 
28185 \series bold 
28186
28187 \begin_inset Quotes sld
28188 \end_inset 
28189
28190 diff -Naur unmodified_directory modified_directory >my_changes.patch
28191 \begin_inset Quotes srd
28192 \end_inset 
28193
28194
28195 \family default 
28196 \series default 
28197  will be fine, otherwise 
28198 \family sans 
28199 \series bold 
28200
28201 \begin_inset Quotes sld
28202 \end_inset 
28203
28204 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
28205 \begin_inset Quotes srd
28206 \end_inset 
28207
28208
28209 \series default 
28210  
28211 \family default 
28212 will do.
28213 \layout Section
28214
28215 Getting Help
28216 \layout Standard
28217
28218 These links should take you directly to the 
28219 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
28220
28221 \end_inset 
28222
28223
28224 \begin_inset Foot
28225 collapsed false
28226
28227 \layout Standard
28228
28229 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
28230  automated messages (mid 2003)
28231 \end_inset 
28232
28233  and the 
28234 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
28235
28236 \end_inset 
28237
28238 , lists
28239 \begin_inset LatexCommand \index{Mailing list(s)}
28240
28241 \end_inset 
28242
28243  and forums are archived and searchable so if you are lucky someone already
28244  had a similar problem.
28245  While mails to the lists themselves are delivered promptly their web front
28246  end on sourceforge sometimes shows a severe time lag (up to several weeks),
28247  if you're seriously using SDCC please consider subscribing to the lists.
28248 \layout Section
28249
28250 ChangeLog
28251 \layout Standard
28252
28253 You can follow the status of the Subversion version
28254 \begin_inset LatexCommand \index{version}
28255
28256 \end_inset 
28257
28258  of SDCC by watching the Changelog
28259 \begin_inset LatexCommand \index{Changelog}
28260
28261 \end_inset 
28262
28263  in the Subversion repository
28264 \size footnotesize 
28265  
28266 \begin_inset LatexCommand \htmlurl{http://svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
28267
28268 \end_inset 
28269
28270 .
28271 \layout Section
28272
28273 Subversion Source Code Repository
28274 \layout Standard
28275
28276 The output of 
28277 \family sans 
28278 \series bold 
28279 sdcc --version
28280 \family default 
28281 \series default 
28282  or the filenames of the snapshot versions of SDCC include date and its
28283  Subversion
28284 \begin_inset LatexCommand \index{Subversion code repository}
28285
28286 \end_inset 
28287
28288  number.
28289  Subversion allows to download the source of recent or previous versions
28290  
28291 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
28292
28293 \end_inset 
28294
28295  (by number or by date).
28296  An on-line source code browser and detailled instructions are also available
28297  there.
28298  SDCC versions starting from 1999 up to now are available (currently the
28299  versions prior to the conversion from cvs
28300 \begin_inset LatexCommand \index{cvs|see{Subversion}}
28301
28302 \end_inset 
28303
28304  to Subversion (April 2006) are either by accessible by Subversion or by
28305  cvs).
28306 \layout Section
28307
28308 Release policy
28309 \begin_inset LatexCommand \index{Release policy}
28310
28311 \end_inset 
28312
28313
28314 \layout Standard
28315
28316 Historically there often were long delays between official releases and
28317  the sourceforge download area tends to get not updated at all.
28318  Excuses in the past might have referred to problems with live range analysis,
28319  but as this was fixed a while ago, the current problem is that another
28320  excuse has to be found.
28321  Kidding aside, we have to get better there! On the other hand there are
28322  daily snapshots available at 
28323 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
28324
28325 \end_inset 
28326
28327 , and you can always build the very last version (hopefully with many bugs
28328  fixed, and features added) from the source code available at 
28329 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
28330
28331 \end_inset 
28332
28333 .
28334  A release wiki
28335 \begin_inset LatexCommand \index{wiki}
28336
28337 \end_inset 
28338
28339
28340 \begin_inset LatexCommand \index{Release wiki}
28341
28342 \end_inset 
28343
28344  at 
28345 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
28346
28347 \end_inset 
28348
28349  also holds some information about past and future releases.
28350 \layout Section
28351
28352 Examples
28353 \begin_inset LatexCommand \index{Examples}
28354
28355 \end_inset 
28356
28357
28358 \layout Standard
28359
28360 You'll find some small examples in the directory 
28361 \emph on 
28362 sdcc/device/examples/.
28363  
28364 \emph default 
28365 More examples and libraries are available at
28366 \emph on 
28367  The SDCC Open Knowledge Resource 
28368 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
28369
28370 \end_inset 
28371
28372  
28373 \emph default 
28374 web site or at 
28375 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
28376
28377 \end_inset 
28378
28379 .
28380 \layout Standard
28381
28382
28383 \begin_inset Note
28384 collapsed true
28385
28386 \layout Standard
28387
28388 I did insert a reference to Paul's web site here although it seems rather
28389  dedicated to a specific 8032 board (I think it's okay because it f.e.
28390  shows LCD/Harddisc interface and has a free 8051 monitor.
28391  Independent 8032 board vendors face hard competition of heavily subsidized
28392  development boards anyway).
28393 \layout Standard
28394
28395 Maybe we should include some links to real world applications.
28396  Preferably pointer to pointers (one for each architecture) so this stays
28397  manageable here?
28398 \end_inset 
28399
28400
28401 \layout Section
28402
28403 Quality control
28404 \begin_inset LatexCommand \label{sec:Quality-control}
28405
28406 \end_inset 
28407
28408
28409 \begin_inset LatexCommand \index{Quality control}
28410
28411 \end_inset 
28412
28413
28414 \layout Standard
28415
28416 The compiler is passed through nightly compile and build checks.
28417  The so called 
28418 \shape italic 
28419 regression tests
28420 \shape default 
28421
28422 \begin_inset LatexCommand \index{Regression test}
28423
28424 \end_inset 
28425
28426  check that SDCC itself compiles flawlessly on several host platforms (i386,
28427  Opteron, 64 bit Alpha, ppc64, MacOS X on PPC, Solaris on Sparc) and checks
28428  the quality of the code generated by SDCC by running the code for several
28429  target platforms through simulators.
28430  The regression test suite comprises more than 100 files which expand to
28431  more than 500 test cases which include more than 4500 tests.
28432  The results of these tests are published daily on SDCC's snapshot page
28433  (click on the red or green symbols on the right side of 
28434 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
28435
28436 \end_inset 
28437
28438 ).
28439 \layout Standard
28440
28441 There is a separate document 
28442 \shape italic 
28443 test_suite.pdf 
28444 \begin_inset LatexCommand \index{Test suite}
28445
28446 \end_inset 
28447
28448
28449 \shape default 
28450  
28451 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
28452
28453 \end_inset 
28454
28455  about the regression test suite.
28456 \layout Standard
28457
28458 You'll find the test code in the directory 
28459 \shape italic 
28460 sdcc/support/regression
28461 \shape default 
28462 .
28463  You can run these tests manually by running 
28464 \family sans 
28465 make
28466 \family default 
28467  in this directory (or f.e.
28468  
28469 \family sans 
28470 \series bold 
28471
28472 \begin_inset Quotes sld
28473 \end_inset 
28474
28475 make test-mcs51
28476 \begin_inset Quotes srd
28477 \end_inset 
28478
28479
28480 \family default 
28481 \series default 
28482  if you don't want to run the complete tests).
28483  The test code might also be interesting if you want to look for examples
28484 \begin_inset LatexCommand \index{Examples}
28485
28486 \end_inset 
28487
28488  checking corner cases of SDCC or if you plan to submit patches
28489 \begin_inset LatexCommand \index{Patch submission}
28490
28491 \end_inset 
28492
28493 .
28494 \layout Standard
28495
28496 The 14bit pic port uses a different set of regression tests 
28497 \begin_inset LatexCommand \index{Regression test (PIC14)}
28498
28499 \end_inset 
28500
28501 , you'll find them in the directory 
28502 \shape italic 
28503 sdcc/src/regression
28504 \shape default 
28505 .
28506 \layout Section
28507
28508 Use of SDCC in Education
28509 \layout Standard
28510
28511 In short: 
28512 \emph on 
28513 highly
28514 \emph default 
28515  encouraged
28516 \begin_inset Foot
28517 collapsed false
28518
28519 \layout Standard
28520
28521 the phrase "use in education" might evoke the association "
28522 \emph on 
28523 only
28524 \emph default 
28525  fit for use in education".
28526  This connotation is not intended but nevertheless risked as the licensing
28527  of SDCC makes it difficult to offer educational discounts
28528 \end_inset 
28529
28530 .
28531  If your rationales are to:
28532 \layout Enumerate
28533
28534 give students a chance to understand the 
28535 \emph on 
28536 complete
28537 \emph default 
28538  steps of code generation
28539 \layout Enumerate
28540
28541 have a curriculum that can be extended for years.
28542  Then you could use an fpga board as target and your curriculum will seamlessly
28543  extend from logic synthesis (
28544 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
28545
28546 \end_inset 
28547
28548
28549 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
28550
28551 \end_inset 
28552
28553 ), over assembly programming, to C to FPGA compilers (
28554 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
28555
28556 \end_inset 
28557
28558 ) and to C.
28559 \layout Enumerate
28560
28561 be able to insert excursions about skills like using a revision control
28562  system, submitting/applying patches, using a type-setting (as opposed to
28563  word-processing) engine LyX/LaTeX, using 
28564 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
28565
28566 \end_inset 
28567
28568 , following some 
28569 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
28570
28571 \end_inset 
28572
28573 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
28574  Source Software, CPU simulation, compiler regression tests
28575 \begin_inset LatexCommand \index{Regression test}
28576
28577 \end_inset 
28578
28579 .
28580  
28581 \newline 
28582 And if there should be a shortage of ideas then you can always point students
28583  to the ever-growing feature request list 
28584 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
28585
28586 \end_inset 
28587
28588 .
28589 \layout Enumerate
28590
28591 not tie students to a specific host platform and instead allow them to use
28592  a host platform of 
28593 \emph on 
28594 their
28595 \emph default 
28596  choice (among them Alpha, i386, i386_64, MacOs, Mips, Sparc, Windows and
28597  eventually 
28598 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
28599
28600 \end_inset 
28601
28602 )
28603 \layout Enumerate
28604
28605 not encourage students to use illegal copies of educational software
28606 \layout Enumerate
28607
28608 be immune to licensing/availability/price changes of the chosen tool chain
28609 \layout Enumerate
28610
28611 be able to change to a new target platform without having to adopt a new
28612  tool chain
28613 \layout Enumerate
28614
28615 have complete control over and insight into the tool chain
28616 \layout Enumerate
28617
28618 make your students aware about the pros and cons of open source software
28619  development
28620 \layout Enumerate
28621
28622 give back to the public as you are probably at least partially publically
28623  funded
28624 \layout Enumerate
28625
28626 give students a chance to publically prove their skills and to possibly
28627  see a world wide impact
28628 \layout Standard
28629 \pagebreak_bottom 
28630 then SDCC is probably among the first choices.
28631  Well, probably SDCC might be the only choice.
28632 \layout Chapter
28633
28634 SDCC Technical Data
28635 \layout Section
28636
28637 Optimizations
28638 \begin_inset LatexCommand \index{Optimizations}
28639
28640 \end_inset 
28641
28642
28643 \layout Standard
28644
28645 SDCC performs a host of standard optimizations in addition to some MCU specific
28646  optimizations.
28647  
28648 \layout Subsection
28649
28650 Sub-expression Elimination
28651 \begin_inset LatexCommand \index{Subexpression elimination}
28652
28653 \end_inset 
28654
28655
28656 \layout Standard
28657
28658 The compiler does local and 
28659 \emph on 
28660 g
28661 \emph default 
28662 lobal 
28663 \emph on 
28664 c
28665 \emph default 
28666 ommon 
28667 \emph on 
28668 s
28669 \emph default 
28670 ubexpression 
28671 \emph on 
28672 e
28673 \emph default 
28674 limination, e.g.: 
28675 \layout Verse
28676
28677
28678 \family typewriter 
28679 i = x + y + 1; 
28680 \newline 
28681 j = x + y;
28682 \layout Standard
28683
28684 will be translated to
28685 \layout Verse
28686
28687
28688 \family typewriter 
28689 iTemp = x + y; 
28690 \newline 
28691 i = iTemp + 1; 
28692 \newline 
28693 j = iTemp;
28694 \layout Standard
28695
28696 Some subexpressions are not as obvious as the above example, e.g.:
28697 \layout Verse
28698
28699
28700 \family typewriter 
28701 a->b[i].c = 10; 
28702 \newline 
28703 a->b[i].d = 11;
28704 \layout Standard
28705
28706 In this case the address arithmetic a->b[i] will be computed only once;
28707  the equivalent code in C would be.
28708 \layout Verse
28709
28710
28711 \family typewriter 
28712 iTemp = a->b[i]; 
28713 \newline 
28714 iTemp.c = 10; 
28715 \newline 
28716 iTemp.d = 11;
28717 \layout Standard
28718
28719 The compiler will try to keep these temporary variables in registers.
28720 \layout Subsection
28721
28722 Dead-Code Elimination
28723 \begin_inset LatexCommand \index{Dead-code elimination}
28724
28725 \end_inset 
28726
28727
28728 \layout Verse
28729
28730
28731 \family typewriter 
28732 int global;
28733 \newline 
28734
28735 \newline 
28736 void f () { 
28737 \newline 
28738 \SpecialChar ~
28739 \SpecialChar ~
28740 int i; 
28741 \newline 
28742 \SpecialChar ~
28743 \SpecialChar ~
28744 i = 1; \SpecialChar ~
28745 \SpecialChar ~
28746 \SpecialChar ~
28747 \SpecialChar ~
28748 \SpecialChar ~
28749 /* dead store */ 
28750 \newline 
28751 \SpecialChar ~
28752 \SpecialChar ~
28753 global = 1;\SpecialChar ~
28754 /* dead store */ 
28755 \newline 
28756 \SpecialChar ~
28757 \SpecialChar ~
28758 global = 2; 
28759 \newline 
28760 \SpecialChar ~
28761 \SpecialChar ~
28762 return; 
28763 \newline 
28764 \SpecialChar ~
28765 \SpecialChar ~
28766 global = 3;\SpecialChar ~
28767 /* unreachable */ 
28768 \newline 
28769 }
28770 \layout Standard
28771
28772 will be changed to
28773 \layout Verse
28774
28775
28776 \family typewriter 
28777 int global;
28778 \newline 
28779
28780 \newline 
28781 void f () {
28782 \newline 
28783 \SpecialChar ~
28784 \SpecialChar ~
28785 global = 2; 
28786 \newline 
28787 }
28788 \layout Subsection
28789
28790 Copy-Propagation
28791 \begin_inset LatexCommand \index{Copy propagation}
28792
28793 \end_inset 
28794
28795
28796 \layout Verse
28797
28798
28799 \family typewriter 
28800 int f() { 
28801 \newline 
28802 \SpecialChar ~
28803 \SpecialChar ~
28804 int i, j; 
28805 \newline 
28806 \SpecialChar ~
28807 \SpecialChar ~
28808 i = 10; 
28809 \newline 
28810 \SpecialChar ~
28811 \SpecialChar ~
28812 j = i; 
28813 \newline 
28814 \SpecialChar ~
28815 \SpecialChar ~
28816 return j; 
28817 \newline 
28818 }
28819 \layout Standard
28820
28821 will be changed to 
28822 \layout Verse
28823
28824
28825 \family typewriter 
28826 int f() { 
28827 \newline 
28828 \SpecialChar ~
28829 \SpecialChar ~
28830 int i, j; 
28831 \newline 
28832 \SpecialChar ~
28833 \SpecialChar ~
28834 i = 10; 
28835 \newline 
28836 \SpecialChar ~
28837 \SpecialChar ~
28838 j = 10; 
28839 \newline 
28840 \SpecialChar ~
28841 \SpecialChar ~
28842 return 10; 
28843 \newline 
28844 }
28845 \layout Standard
28846
28847 Note: the dead stores created by this copy propagation will be eliminated
28848  by dead-code elimination.
28849 \layout Subsection
28850
28851 Loop Optimizations
28852 \begin_inset LatexCommand \index{Loop optimization}
28853
28854 \end_inset 
28855
28856
28857 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
28858
28859 \end_inset 
28860
28861
28862 \layout Standard
28863
28864 Two types of loop optimizations are done by SDCC 
28865 \emph on 
28866 loop invariant
28867 \emph default 
28868  lifting and
28869 \emph on 
28870  strength reduction
28871 \emph default 
28872  of loop induction variables.
28873  In addition to the strength reduction the optimizer marks the induction
28874  variables and the register allocator tries to keep the induction variables
28875  in registers for the duration of the loop.
28876  Because of this preference of the register allocator
28877 \begin_inset LatexCommand \index{Register allocation}
28878
28879 \end_inset 
28880
28881 , loop induction optimization causes an increase in register pressure, which
28882  may cause unwanted spilling of other temporary variables into the stack
28883 \begin_inset LatexCommand \index{stack}
28884
28885 \end_inset 
28886
28887  / data space.
28888  The compiler will generate a warning message when it is forced to allocate
28889  extra space either on the stack or data space.
28890  If this extra space allocation is undesirable then induction optimization
28891  can be eliminated either for the entire source file (with -
28892 \begin_inset ERT
28893 status Collapsed
28894
28895 \layout Standard
28896
28897 \backslash 
28898 /
28899 \end_inset 
28900
28901 -noinduction option) or for a given function only using #pragma\SpecialChar ~
28902 noinduction
28903 \begin_inset LatexCommand \index{\#pragma noinduction}
28904
28905 \end_inset 
28906
28907 .
28908 \newline 
28909
28910 \newline 
28911 Loop Invariant:
28912 \layout Verse
28913
28914
28915 \family typewriter 
28916 for (i = 0 ; i < 100 ; i ++) 
28917 \newline 
28918 \SpecialChar ~
28919 \SpecialChar ~
28920 \SpecialChar ~
28921 \SpecialChar ~
28922 f += k + l;
28923 \layout Standard
28924
28925 changed to
28926 \layout Verse
28927
28928
28929 \family typewriter 
28930 itemp = k + l; 
28931 \newline 
28932 for (i = 0; i < 100; i++) 
28933 \newline 
28934 \SpecialChar ~
28935 \SpecialChar ~
28936 \SpecialChar ~
28937 \SpecialChar ~
28938 f += itemp;
28939 \layout Standard
28940
28941 As mentioned previously some loop invariants are not as apparent, all static
28942  address computations are also moved out of the loop.
28943 \newline 
28944
28945 \newline 
28946 Strength Reduction
28947 \begin_inset LatexCommand \index{Strength reduction}
28948
28949 \end_inset 
28950
28951 , this optimization substitutes an expression by a cheaper expression:
28952 \layout Verse
28953
28954
28955 \family typewriter 
28956 for (i=0;i < 100; i++)
28957 \newline 
28958 \SpecialChar ~
28959 \SpecialChar ~
28960 \SpecialChar ~
28961 \SpecialChar ~
28962 ar[i*5] = i*3;
28963 \layout Standard
28964
28965 changed to
28966 \layout Verse
28967
28968
28969 \family typewriter 
28970 itemp1 = 0; 
28971 \newline 
28972 itemp2 = 0; 
28973 \newline 
28974 for (i=0;i< 100;i++) { 
28975 \newline 
28976 \SpecialChar ~
28977 \SpecialChar ~
28978 \SpecialChar ~
28979 \SpecialChar ~
28980 ar[itemp1] = itemp2; 
28981 \newline 
28982 \SpecialChar ~
28983 \SpecialChar ~
28984 \SpecialChar ~
28985 \SpecialChar ~
28986 itemp1 += 5; 
28987 \newline 
28988 \SpecialChar ~
28989 \SpecialChar ~
28990 \SpecialChar ~
28991 \SpecialChar ~
28992 itemp2 += 3; 
28993 \newline 
28994 }
28995 \layout Standard
28996
28997 The more expensive multiplication
28998 \begin_inset LatexCommand \index{Multiplication}
28999
29000 \end_inset 
29001
29002  is changed to a less expensive addition.
29003 \layout Subsection
29004
29005 Loop Reversing
29006 \begin_inset LatexCommand \index{Loop reversing}
29007
29008 \end_inset 
29009
29010
29011 \layout Standard
29012
29013 This optimization is done to reduce the overhead of checking loop boundaries
29014  for every iteration.
29015  Some simple loops can be reversed and implemented using a 
29016 \begin_inset Quotes eld
29017 \end_inset 
29018
29019 decrement and jump if not zero
29020 \begin_inset Quotes erd
29021 \end_inset 
29022
29023  instruction.
29024  SDCC checks for the following criterion to determine if a loop is reversible
29025  (note: more sophisticated compilers use data-dependency analysis to make
29026  this determination, SDCC uses a more simple minded analysis).
29027 \layout Itemize
29028
29029 The 'for' loop is of the form 
29030 \newline 
29031
29032 \newline 
29033
29034 \family typewriter 
29035 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
29036  += 1])
29037 \newline 
29038 \SpecialChar ~
29039 \SpecialChar ~
29040 \SpecialChar ~
29041 \SpecialChar ~
29042 <for body>
29043 \layout Itemize
29044
29045 The <for body> does not contain 
29046 \begin_inset Quotes eld
29047 \end_inset 
29048
29049 continue
29050 \begin_inset Quotes erd
29051 \end_inset 
29052
29053  or 'break
29054 \begin_inset Quotes erd
29055 \end_inset 
29056
29057 .
29058 \layout Itemize
29059
29060 All goto's are contained within the loop.
29061 \layout Itemize
29062
29063 No function calls within the loop.
29064 \layout Itemize
29065
29066 The loop control variable <sym> is not assigned any value within the loop
29067 \layout Itemize
29068
29069 The loop control variable does NOT participate in any arithmetic operation
29070  within the loop.
29071 \layout Itemize
29072
29073 There are NO switch statements in the loop.
29074 \layout Subsection
29075
29076 Algebraic Simplifications
29077 \layout Standard
29078
29079 SDCC does numerous algebraic simplifications, the following is a small sub-set
29080  of these optimizations.
29081 \layout Verse
29082
29083
29084 \family typewriter 
29085 i = j + 0;\SpecialChar ~
29086 \SpecialChar ~
29087 \SpecialChar ~
29088 \SpecialChar ~
29089  /* changed to: */\SpecialChar ~
29090 \SpecialChar ~
29091 \SpecialChar ~
29092 \SpecialChar ~
29093  i = j; 
29094 \newline 
29095 i /= 2;\SpecialChar ~
29096 \SpecialChar ~
29097 \SpecialChar ~
29098 \SpecialChar ~
29099 \SpecialChar ~
29100 \SpecialChar ~
29101 \SpecialChar ~
29102  /* changed to: */\SpecialChar ~
29103 \SpecialChar ~
29104 \SpecialChar ~
29105 \SpecialChar ~
29106  i >>= 1; 
29107 \newline 
29108 i = j - j;\SpecialChar ~
29109 \SpecialChar ~
29110 \SpecialChar ~
29111 \SpecialChar ~
29112  /* changed to: */\SpecialChar ~
29113 \SpecialChar ~
29114 \SpecialChar ~
29115 \SpecialChar ~
29116  i = 0; 
29117 \newline 
29118 i = j / 1;\SpecialChar ~
29119 \SpecialChar ~
29120 \SpecialChar ~
29121 \SpecialChar ~
29122  /* changed to: */\SpecialChar ~
29123 \SpecialChar ~
29124 \SpecialChar ~
29125 \SpecialChar ~
29126  i = j;
29127 \layout Standard
29128
29129 Note the subexpressions
29130 \begin_inset LatexCommand \index{Subexpression}
29131
29132 \end_inset 
29133
29134  given above are generally introduced by macro expansions or as a result
29135  of copy/constant propagation.
29136 \layout Subsection
29137
29138 'switch' Statements
29139 \begin_inset LatexCommand \label{sub:'switch'-Statements}
29140
29141 \end_inset 
29142
29143
29144 \begin_inset LatexCommand \index{switch statement}
29145
29146 \end_inset 
29147
29148
29149 \layout Standard
29150
29151 SDCC can optimize switch statements to jump tables
29152 \begin_inset LatexCommand \index{jump tables}
29153
29154 \end_inset 
29155
29156 .
29157  It makes the decision based on an estimate of the generated code size.
29158  SDCC is quite liberal in the requirements for jump table generation: 
29159 \layout Itemize
29160
29161 The labels need not be in order, and the starting number need not be one
29162  or zero, the case labels are in numerical sequence or not too many case
29163  labels are missing.
29164 \begin_deeper 
29165 \layout Verse
29166
29167
29168 \family typewriter 
29169 switch(i) {\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 \SpecialChar ~
29190 \SpecialChar ~
29191 \SpecialChar ~
29192 \SpecialChar ~
29193 \SpecialChar ~
29194 \SpecialChar ~
29195 switch (i) { 
29196 \newline 
29197 \SpecialChar ~
29198 \SpecialChar ~
29199 \SpecialChar ~
29200 case 4: ...\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 \SpecialChar ~
29222 \SpecialChar ~
29223 \SpecialChar ~
29224 \SpecialChar ~
29225 \SpecialChar ~
29226 case 0: ...
29227  
29228 \newline 
29229 \SpecialChar ~
29230 \SpecialChar ~
29231 \SpecialChar ~
29232 case 5: ...\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 \SpecialChar ~
29254 \SpecialChar ~
29255 \SpecialChar ~
29256 \SpecialChar ~
29257 \SpecialChar ~
29258 case 1: ...
29259  
29260 \newline 
29261 \SpecialChar ~
29262 \SpecialChar ~
29263 \SpecialChar ~
29264 case 3: ...\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 \SpecialChar ~
29285 \SpecialChar ~
29286 \SpecialChar ~
29287 \SpecialChar ~
29288 \SpecialChar ~
29289 \SpecialChar ~
29290
29291 \newline 
29292 \SpecialChar ~
29293 \SpecialChar ~
29294 \SpecialChar ~
29295 case 6: ...\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 \SpecialChar ~
29316 \SpecialChar ~
29317 \SpecialChar ~
29318 \SpecialChar ~
29319 \SpecialChar ~
29320 \SpecialChar ~
29321 case 3: ...
29322  
29323 \newline 
29324 \SpecialChar ~
29325 \SpecialChar ~
29326 \SpecialChar ~
29327 case 7: ...\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 case 4: ...
29354  
29355 \newline 
29356 \SpecialChar ~
29357 \SpecialChar ~
29358 \SpecialChar ~
29359 case 8: ...\SpecialChar ~
29360 \SpecialChar ~
29361 \SpecialChar ~
29362 \SpecialChar ~
29363 \SpecialChar ~
29364 \SpecialChar ~
29365 \SpecialChar ~
29366 \SpecialChar ~
29367 \SpecialChar ~
29368 \SpecialChar ~
29369 \SpecialChar ~
29370 \SpecialChar ~
29371 \SpecialChar ~
29372 \SpecialChar ~
29373 \SpecialChar ~
29374 \SpecialChar ~
29375 \SpecialChar ~
29376 \SpecialChar ~
29377 \SpecialChar ~
29378 \SpecialChar ~
29379 \SpecialChar ~
29380 \SpecialChar ~
29381 \SpecialChar ~
29382 \SpecialChar ~
29383 \SpecialChar ~
29384 \SpecialChar ~
29385 case 5: ...
29386  
29387 \newline 
29388 \SpecialChar ~
29389 \SpecialChar ~
29390 \SpecialChar ~
29391 case 9: ...\SpecialChar ~
29392 \SpecialChar ~
29393 \SpecialChar ~
29394 \SpecialChar ~
29395 \SpecialChar ~
29396 \SpecialChar ~
29397 \SpecialChar ~
29398 \SpecialChar ~
29399 \SpecialChar ~
29400 \SpecialChar ~
29401 \SpecialChar ~
29402 \SpecialChar ~
29403 \SpecialChar ~
29404 \SpecialChar ~
29405 \SpecialChar ~
29406 \SpecialChar ~
29407 \SpecialChar ~
29408 \SpecialChar ~
29409 \SpecialChar ~
29410 \SpecialChar ~
29411 \SpecialChar ~
29412 \SpecialChar ~
29413 \SpecialChar ~
29414 \SpecialChar ~
29415 \SpecialChar ~
29416 \SpecialChar ~
29417 case 6: ...
29418  
29419 \newline 
29420 \SpecialChar ~
29421 \SpecialChar ~
29422 \SpecialChar ~
29423 case 10: ...\SpecialChar ~
29424 \SpecialChar ~
29425 \SpecialChar ~
29426 \SpecialChar ~
29427 \SpecialChar ~
29428 \SpecialChar ~
29429 \SpecialChar ~
29430 \SpecialChar ~
29431 \SpecialChar ~
29432 \SpecialChar ~
29433 \SpecialChar ~
29434 \SpecialChar ~
29435 \SpecialChar ~
29436 \SpecialChar ~
29437 \SpecialChar ~
29438 \SpecialChar ~
29439 \SpecialChar ~
29440 \SpecialChar ~
29441 \SpecialChar ~
29442 \SpecialChar ~
29443 \SpecialChar ~
29444 \SpecialChar ~
29445 \SpecialChar ~
29446 \SpecialChar ~
29447 \SpecialChar ~
29448 case 7: ...
29449  
29450 \newline 
29451 \SpecialChar ~
29452 \SpecialChar ~
29453 \SpecialChar ~
29454 case 11: ...\SpecialChar ~
29455 \SpecialChar ~
29456 \SpecialChar ~
29457 \SpecialChar ~
29458 \SpecialChar ~
29459 \SpecialChar ~
29460 \SpecialChar ~
29461 \SpecialChar ~
29462 \SpecialChar ~
29463 \SpecialChar ~
29464 \SpecialChar ~
29465 \SpecialChar ~
29466 \SpecialChar ~
29467 \SpecialChar ~
29468 \SpecialChar ~
29469 \SpecialChar ~
29470 \SpecialChar ~
29471 \SpecialChar ~
29472 \SpecialChar ~
29473 \SpecialChar ~
29474 \SpecialChar ~
29475 \SpecialChar ~
29476 \SpecialChar ~
29477 \SpecialChar ~
29478 \SpecialChar ~
29479 case 8: ...
29480  
29481 \newline 
29482 }\SpecialChar ~
29483 \SpecialChar ~
29484 \SpecialChar ~
29485 \SpecialChar ~
29486 \SpecialChar ~
29487 \SpecialChar ~
29488 \SpecialChar ~
29489 \SpecialChar ~
29490 \SpecialChar ~
29491 \SpecialChar ~
29492 \SpecialChar ~
29493 \SpecialChar ~
29494 \SpecialChar ~
29495 \SpecialChar ~
29496 \SpecialChar ~
29497 \SpecialChar ~
29498 \SpecialChar ~
29499 \SpecialChar ~
29500 \SpecialChar ~
29501 \SpecialChar ~
29502 \SpecialChar ~
29503 \SpecialChar ~
29504 \SpecialChar ~
29505 \SpecialChar ~
29506 \SpecialChar ~
29507 \SpecialChar ~
29508 \SpecialChar ~
29509 \SpecialChar ~
29510 \SpecialChar ~
29511 \SpecialChar ~
29512 \SpecialChar ~
29513 \SpecialChar ~
29514 \SpecialChar ~
29515 \SpecialChar ~
29516 \SpecialChar ~
29517 \SpecialChar ~
29518 }
29519 \layout Standard
29520
29521 Both the above switch statements will be implemented using a jump-table.
29522  The example to the right side is slightly more efficient as the check for
29523  the lower boundary of the jump-table is not needed.
29524 \end_deeper 
29525 \layout Itemize
29526
29527 The number of case labels is not larger than supported by the target architectur
29528 e.
29529 \layout Itemize
29530
29531 If the case labels are not in numerical sequence ('gaps' between cases)
29532  SDCC checks whether a jump table with additionally inserted dummy cases
29533  is still attractive.
29534  
29535 \layout Itemize
29536
29537 If the starting number is not zero and a check for the lower boundary of
29538  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
29539  ...
29540  .
29541 \layout Standard
29542
29543 Switch statements which have large gaps in the numeric sequence or those
29544  that have too many case labels can be split into more than one switch statement
29545  for efficient code generation, e.g.:
29546 \layout Verse
29547
29548
29549 \family typewriter 
29550 switch (i) { 
29551 \newline 
29552 \SpecialChar ~
29553 \SpecialChar ~
29554 case 1: ...
29555  
29556 \newline 
29557 \SpecialChar ~
29558 \SpecialChar ~
29559 case 2: ...
29560  
29561 \newline 
29562 \SpecialChar ~
29563 \SpecialChar ~
29564 case 3: ...
29565  
29566 \newline 
29567 \SpecialChar ~
29568 \SpecialChar ~
29569 case 4: ...
29570  
29571 \newline 
29572 \SpecialChar ~
29573 \SpecialChar ~
29574 case 5: ...
29575  
29576 \newline 
29577 \SpecialChar ~
29578 \SpecialChar ~
29579 case 6: ...
29580  
29581 \newline 
29582 \SpecialChar ~
29583 \SpecialChar ~
29584 case 7: ...
29585  
29586 \newline 
29587 \SpecialChar ~
29588 \SpecialChar ~
29589 case 101: ...
29590  
29591 \newline 
29592 \SpecialChar ~
29593 \SpecialChar ~
29594 case 102: ...
29595  
29596 \newline 
29597 \SpecialChar ~
29598 \SpecialChar ~
29599 case 103: ...
29600  
29601 \newline 
29602 \SpecialChar ~
29603 \SpecialChar ~
29604 case 104: ...
29605  
29606 \newline 
29607 \SpecialChar ~
29608 \SpecialChar ~
29609 case 105: ...
29610  
29611 \newline 
29612 \SpecialChar ~
29613 \SpecialChar ~
29614 case 106: ...
29615  
29616 \newline 
29617 \SpecialChar ~
29618 \SpecialChar ~
29619 case 107: ...
29620  
29621 \newline 
29622 }
29623 \layout Standard
29624
29625 If the above switch statement is broken down into two switch statements
29626 \layout Verse
29627
29628
29629 \family typewriter 
29630 switch (i) { 
29631 \newline 
29632 \SpecialChar ~
29633 \SpecialChar ~
29634 case 1: ...
29635  
29636 \newline 
29637 \SpecialChar ~
29638 \SpecialChar ~
29639 case 2: ...
29640  
29641 \newline 
29642 \SpecialChar ~
29643 \SpecialChar ~
29644 case 3: ...
29645  
29646 \newline 
29647 \SpecialChar ~
29648 \SpecialChar ~
29649 case 4: ...
29650  
29651 \newline 
29652 \SpecialChar ~
29653 \SpecialChar ~
29654 case 5: ...
29655  
29656 \newline 
29657 \SpecialChar ~
29658 \SpecialChar ~
29659 case 6: ...
29660  
29661 \newline 
29662 \SpecialChar ~
29663 \SpecialChar ~
29664 case 7: ...
29665  
29666 \newline 
29667 }
29668 \layout Standard
29669
29670 and
29671 \layout Verse
29672
29673
29674 \family typewriter 
29675 switch (i) { 
29676 \newline 
29677 \SpecialChar ~
29678 \SpecialChar ~
29679 case 101: ...
29680  
29681 \newline 
29682 \SpecialChar ~
29683 \SpecialChar ~
29684 case 102: ...
29685  
29686 \newline 
29687 \SpecialChar ~
29688 \SpecialChar ~
29689 case 103: ...
29690  
29691 \newline 
29692 \SpecialChar ~
29693 \SpecialChar ~
29694 case 104: ...
29695  
29696 \newline 
29697 \SpecialChar ~
29698 \SpecialChar ~
29699 case 105: ...
29700  
29701 \newline 
29702 \SpecialChar ~
29703 \SpecialChar ~
29704 case 106: ...
29705  
29706 \newline 
29707 \SpecialChar ~
29708 \SpecialChar ~
29709 case 107: ...
29710  
29711 \newline 
29712 }
29713 \layout Standard
29714
29715 then both the switch statements will be implemented using jump-tables whereas
29716  the unmodified switch statement will not be.
29717 \layout Standard
29718
29719
29720 \begin_inset Note
29721 collapsed true
29722
29723 \layout Standard
29724
29725 There might be reasons which SDCC cannot know about to either favour or
29726  not favour jump tables.
29727  If the target system has to be as quick for the last switch case as for
29728  the first (pro jump table), or if the switch argument is known to be zero
29729  in the majority of the cases (contra jump table).
29730 \end_inset 
29731
29732
29733 \layout Standard
29734
29735 The pragma nojtbound
29736 \begin_inset LatexCommand \index{\#pragma nojtbound}
29737
29738 \end_inset 
29739
29740  can be used to turn off checking the 
29741 \emph on 
29742 j
29743 \emph default 
29744 ump 
29745 \emph on 
29746 t
29747 \emph default 
29748 able 
29749 \emph on 
29750 bound
29751 \emph default 
29752 aries.
29753  It has no effect if a default label is supplied.
29754  Use of this pragma is dangerous: if the switch
29755 \begin_inset LatexCommand \index{switch statement}
29756
29757 \end_inset 
29758
29759  argument is not matched by a case statement the processor will happily
29760  jump into Nirvana.
29761 \layout Subsection
29762
29763 Bit-shifting Operations
29764 \begin_inset LatexCommand \index{Bit shifting}
29765
29766 \end_inset 
29767
29768 .
29769 \layout Standard
29770
29771 Bit shifting is one of the most frequently used operation in embedded programmin
29772 g.
29773  SDCC tries to implement bit-shift operations in the most efficient way
29774  possible, e.g.:
29775 \layout Verse
29776
29777
29778 \family typewriter 
29779 unsigned char i;
29780 \newline 
29781 ...
29782  
29783 \newline 
29784 i >>= 4; 
29785 \newline 
29786 ...
29787 \layout Standard
29788
29789 generates the following code:
29790 \layout Verse
29791
29792
29793 \family typewriter 
29794 mov\SpecialChar ~
29795  a,_i 
29796 \newline 
29797 swap a 
29798 \newline 
29799 anl\SpecialChar ~
29800  a,#0x0f 
29801 \newline 
29802 mov\SpecialChar ~
29803  _i,a
29804 \layout Standard
29805
29806 In general SDCC will never setup a loop if the shift count is known.
29807  Another example:
29808 \layout Verse
29809
29810
29811 \family typewriter 
29812 unsigned int i; 
29813 \newline 
29814 ...
29815  
29816 \newline 
29817 i >>= 9; 
29818 \newline 
29819 ...
29820 \layout Standard
29821
29822 will generate:
29823 \layout Verse
29824
29825
29826 \family typewriter 
29827 mov\SpecialChar ~
29828 \SpecialChar ~
29829 a,(_i + 1) 
29830 \newline 
29831 mov\SpecialChar ~
29832 \SpecialChar ~
29833 (_i + 1),#0x00 
29834 \newline 
29835 clr\SpecialChar ~
29836 \SpecialChar ~
29837
29838 \newline 
29839 rrc\SpecialChar ~
29840 \SpecialChar ~
29841
29842 \newline 
29843 mov\SpecialChar ~
29844 \SpecialChar ~
29845 _i,a
29846 \layout Subsection
29847
29848 Bit-rotation
29849 \begin_inset LatexCommand \index{Bit rotation}
29850
29851 \end_inset 
29852
29853
29854 \layout Standard
29855
29856 A special case of the bit-shift operation is bit rotation
29857 \begin_inset LatexCommand \index{rotating bits}
29858
29859 \end_inset 
29860
29861 , SDCC recognizes the following expression to be a left bit-rotation:
29862 \layout Verse
29863
29864
29865 \family typewriter 
29866 \series bold 
29867 unsigned
29868 \series default 
29869 \SpecialChar ~
29870 \SpecialChar ~
29871 char i;\SpecialChar ~
29872 \SpecialChar ~
29873 \SpecialChar ~
29874 \SpecialChar ~
29875 \SpecialChar ~
29876 \SpecialChar ~
29877 \SpecialChar ~
29878 \SpecialChar ~
29879 \SpecialChar ~
29880 \SpecialChar ~
29881 \SpecialChar ~
29882 /* unsigned is needed for rotation */ 
29883 \newline 
29884 ...
29885  
29886 \newline 
29887 i = ((i << 1) | (i >> 7)); 
29888 \family default 
29889
29890 \newline 
29891
29892 \family typewriter 
29893 ...
29894 \layout Standard
29895
29896 will generate the following code:
29897 \layout Verse
29898
29899
29900 \family typewriter 
29901 mov\SpecialChar ~
29902 \SpecialChar ~
29903 a,_i 
29904 \newline 
29905 rl\SpecialChar ~
29906 \SpecialChar ~
29907 \SpecialChar ~
29908
29909 \newline 
29910 mov\SpecialChar ~
29911 \SpecialChar ~
29912 _i,a
29913 \layout Standard
29914
29915 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
29916 ns of this case will also be recognized as bit-rotation, i.e.: 
29917 \layout Verse
29918
29919
29920 \family typewriter 
29921 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
29922 \layout Subsection
29923
29924 Nibble and Byte Swapping
29925 \layout Standard
29926
29927 Other special cases of the bit-shift operations are nibble or byte swapping
29928 \begin_inset LatexCommand \index{swapping nibbles/bytes}
29929
29930 \end_inset 
29931
29932 , SDCC recognizes the following expressions:
29933 \layout Verse
29934
29935
29936 \family typewriter 
29937 \series bold 
29938 unsigned
29939 \series default 
29940 \SpecialChar ~
29941 \SpecialChar ~
29942 char i; 
29943 \newline 
29944
29945 \series bold 
29946 unsigned
29947 \series default 
29948 \SpecialChar ~
29949 \SpecialChar ~
29950 int j; 
29951 \newline 
29952 ...
29953  
29954 \newline 
29955 i = ((i << 4) | (i >> 4)); 
29956 \family default 
29957
29958 \newline 
29959
29960 \family typewriter 
29961 j = ((j << 8) | (j >> 8)); 
29962 \layout Standard
29963
29964 and generates a swap instruction for the nibble swapping
29965 \begin_inset LatexCommand \index{Nibble swapping}
29966
29967 \end_inset 
29968
29969  or move instructions for the byte swapping
29970 \begin_inset LatexCommand \index{Byte swapping}
29971
29972 \end_inset 
29973
29974 .
29975  The 
29976 \begin_inset Quotes sld
29977 \end_inset 
29978
29979 j
29980 \begin_inset Quotes srd
29981 \end_inset 
29982
29983  example can be used to convert from little to big-endian or vice versa.
29984  If you want to change the endianness of a 
29985 \emph on 
29986 signed
29987 \emph default 
29988  integer you have to cast to 
29989 \family typewriter 
29990 (unsigned int)
29991 \family default 
29992  first.
29993 \layout Standard
29994
29995 Note that SDCC stores numbers in little-endian
29996 \begin_inset Foot
29997 collapsed false
29998
29999 \layout Standard
30000
30001 Usually 8-bit processors don't care much about endianness.
30002  This is not the case for the standard 8051 which only has an instruction
30003  to increment its 
30004 \emph on 
30005 dptr
30006 \emph default 
30007
30008 \begin_inset LatexCommand \index{DPTR}
30009
30010 \end_inset 
30011
30012 -datapointer
30013 \emph on 
30014  
30015 \emph default 
30016 so little-endian is the more efficient byte order.
30017 \end_inset 
30018
30019
30020 \begin_inset LatexCommand \index{little-endian}
30021
30022 \end_inset 
30023
30024
30025 \begin_inset LatexCommand \index{Endianness}
30026
30027 \end_inset 
30028
30029  format (i.e.
30030  lowest order first).
30031 \layout Subsection
30032
30033 Highest Order Bit
30034 \begin_inset LatexCommand \index{Highest Order Bit}
30035
30036 \end_inset 
30037
30038  / Any Order Bit
30039 \begin_inset LatexCommand \index{Any Order Bit}
30040
30041 \end_inset 
30042
30043
30044 \layout Standard
30045
30046 It is frequently required to obtain the highest order bit of an integral
30047  type (long, int, short or char types).
30048  Also obtaining any other order bit is not uncommon.
30049  SDCC recognizes the following expressions to yield the highest order bit
30050  and generates optimized code for it, e.g.:
30051 \layout Verse
30052
30053
30054 \family typewriter 
30055 unsigned int gint; 
30056 \newline 
30057
30058 \newline 
30059 foo () { 
30060 \newline 
30061 \SpecialChar ~
30062 \SpecialChar ~
30063 unsigned char hob1, aob1; 
30064 \newline 
30065 \SpecialChar ~
30066 \SpecialChar ~
30067 bit hob2, hob3, aob2, aob3; 
30068 \newline 
30069 \SpecialChar ~
30070 \SpecialChar ~
30071 ...
30072  
30073 \newline 
30074 \SpecialChar ~
30075 \SpecialChar ~
30076 hob1 = (gint >> 15) & 1; 
30077 \newline 
30078 \SpecialChar ~
30079 \SpecialChar ~
30080 hob2 = (gint >> 15) & 1; 
30081 \newline 
30082 \SpecialChar ~
30083 \SpecialChar ~
30084 hob3 = gint & 0x8000; 
30085 \newline 
30086 \SpecialChar ~
30087 \SpecialChar ~
30088 aob1 = (gint >> 9) & 1; 
30089 \newline 
30090 \SpecialChar ~
30091 \SpecialChar ~
30092 aob2 = (gint >> 8) & 1; 
30093 \newline 
30094 \SpecialChar ~
30095 \SpecialChar ~
30096 aob3 = gint & 0x0800; 
30097 \newline 
30098 \SpecialChar ~
30099 \SpecialChar ~
30100 ..
30101  
30102 \newline 
30103 }
30104 \layout Standard
30105
30106 will generate the following code:
30107 \layout Verse
30108
30109
30110 \family typewriter 
30111 \SpecialChar ~
30112 \SpecialChar ~
30113 \SpecialChar ~
30114 \SpecialChar ~
30115 \SpecialChar ~
30116 \SpecialChar ~
30117 \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 \SpecialChar ~
30133 \SpecialChar ~
30134 \SpecialChar ~
30135 \SpecialChar ~
30136  61 ;\SpecialChar ~
30137  hob.c 7 
30138 \newline 
30139 000A E5*01\SpecialChar ~
30140 \SpecialChar ~
30141 \SpecialChar ~
30142 \SpecialChar ~
30143 \SpecialChar ~
30144 \SpecialChar ~
30145 \SpecialChar ~
30146 \SpecialChar ~
30147 \SpecialChar ~
30148 \SpecialChar ~
30149 \SpecialChar ~
30150 \SpecialChar ~
30151 \SpecialChar ~
30152 \SpecialChar ~
30153 \SpecialChar ~
30154  62\SpecialChar ~
30155 \SpecialChar ~
30156 \SpecialChar ~
30157 \SpecialChar ~
30158 \SpecialChar ~
30159 \SpecialChar ~
30160 \SpecialChar ~
30161 \SpecialChar ~
30162  mov\SpecialChar ~
30163 \SpecialChar ~
30164  a,(_gint + 1) 
30165 \newline 
30166 000C 23\SpecialChar ~
30167 \SpecialChar ~
30168 \SpecialChar ~
30169 \SpecialChar ~
30170 \SpecialChar ~
30171 \SpecialChar ~
30172 \SpecialChar ~
30173 \SpecialChar ~
30174 \SpecialChar ~
30175 \SpecialChar ~
30176 \SpecialChar ~
30177 \SpecialChar ~
30178 \SpecialChar ~
30179 \SpecialChar ~
30180 \SpecialChar ~
30181 \SpecialChar ~
30182 \SpecialChar ~
30183 \SpecialChar ~
30184  63\SpecialChar ~
30185 \SpecialChar ~
30186 \SpecialChar ~
30187 \SpecialChar ~
30188 \SpecialChar ~
30189 \SpecialChar ~
30190 \SpecialChar ~
30191 \SpecialChar ~
30192  rl\SpecialChar ~
30193 \SpecialChar ~
30194 \SpecialChar ~
30195  a 
30196 \newline 
30197 000D 54 01\SpecialChar ~
30198 \SpecialChar ~
30199 \SpecialChar ~
30200 \SpecialChar ~
30201 \SpecialChar ~
30202 \SpecialChar ~
30203 \SpecialChar ~
30204 \SpecialChar ~
30205 \SpecialChar ~
30206 \SpecialChar ~
30207 \SpecialChar ~
30208 \SpecialChar ~
30209 \SpecialChar ~
30210 \SpecialChar ~
30211 \SpecialChar ~
30212  64\SpecialChar ~
30213 \SpecialChar ~
30214 \SpecialChar ~
30215 \SpecialChar ~
30216 \SpecialChar ~
30217 \SpecialChar ~
30218 \SpecialChar ~
30219 \SpecialChar ~
30220  anl\SpecialChar ~
30221 \SpecialChar ~
30222  a,#0x01 
30223 \newline 
30224 000F F5*02\SpecialChar ~
30225 \SpecialChar ~
30226 \SpecialChar ~
30227 \SpecialChar ~
30228 \SpecialChar ~
30229 \SpecialChar ~
30230 \SpecialChar ~
30231 \SpecialChar ~
30232 \SpecialChar ~
30233 \SpecialChar ~
30234 \SpecialChar ~
30235 \SpecialChar ~
30236 \SpecialChar ~
30237 \SpecialChar ~
30238 \SpecialChar ~
30239  65\SpecialChar ~
30240 \SpecialChar ~
30241 \SpecialChar ~
30242 \SpecialChar ~
30243 \SpecialChar ~
30244 \SpecialChar ~
30245 \SpecialChar ~
30246 \SpecialChar ~
30247  mov\SpecialChar ~
30248 \SpecialChar ~
30249  _foo_hob1_1_1,a 
30250 \newline 
30251 \SpecialChar ~
30252 \SpecialChar ~
30253 \SpecialChar ~
30254 \SpecialChar ~
30255 \SpecialChar ~
30256 \SpecialChar ~
30257 \SpecialChar ~
30258 \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  66 ;\SpecialChar ~
30277  hob.c 8 
30278 \newline 
30279 0011 E5*01\SpecialChar ~
30280 \SpecialChar ~
30281 \SpecialChar ~
30282 \SpecialChar ~
30283 \SpecialChar ~
30284 \SpecialChar ~
30285 \SpecialChar ~
30286 \SpecialChar ~
30287 \SpecialChar ~
30288 \SpecialChar ~
30289 \SpecialChar ~
30290 \SpecialChar ~
30291 \SpecialChar ~
30292 \SpecialChar ~
30293 \SpecialChar ~
30294  67\SpecialChar ~
30295 \SpecialChar ~
30296 \SpecialChar ~
30297 \SpecialChar ~
30298 \SpecialChar ~
30299 \SpecialChar ~
30300 \SpecialChar ~
30301 \SpecialChar ~
30302  mov\SpecialChar ~
30303 \SpecialChar ~
30304  a,(_gint + 1) 
30305 \newline 
30306 0013 33\SpecialChar ~
30307 \SpecialChar ~
30308 \SpecialChar ~
30309 \SpecialChar ~
30310 \SpecialChar ~
30311 \SpecialChar ~
30312 \SpecialChar ~
30313 \SpecialChar ~
30314 \SpecialChar ~
30315 \SpecialChar ~
30316 \SpecialChar ~
30317 \SpecialChar ~
30318 \SpecialChar ~
30319 \SpecialChar ~
30320 \SpecialChar ~
30321 \SpecialChar ~
30322 \SpecialChar ~
30323 \SpecialChar ~
30324  68\SpecialChar ~
30325 \SpecialChar ~
30326 \SpecialChar ~
30327 \SpecialChar ~
30328 \SpecialChar ~
30329 \SpecialChar ~
30330 \SpecialChar ~
30331 \SpecialChar ~
30332  rlc\SpecialChar ~
30333 \SpecialChar ~
30334  a 
30335 \newline 
30336 0014 92*00\SpecialChar ~
30337 \SpecialChar ~
30338 \SpecialChar ~
30339 \SpecialChar ~
30340 \SpecialChar ~
30341 \SpecialChar ~
30342 \SpecialChar ~
30343 \SpecialChar ~
30344 \SpecialChar ~
30345 \SpecialChar ~
30346 \SpecialChar ~
30347 \SpecialChar ~
30348 \SpecialChar ~
30349 \SpecialChar ~
30350 \SpecialChar ~
30351  69\SpecialChar ~
30352 \SpecialChar ~
30353 \SpecialChar ~
30354 \SpecialChar ~
30355 \SpecialChar ~
30356 \SpecialChar ~
30357 \SpecialChar ~
30358 \SpecialChar ~
30359  mov\SpecialChar ~
30360 \SpecialChar ~
30361  _foo_hob2_1_1,c 
30362 \newline 
30363 \SpecialChar ~
30364 \SpecialChar ~
30365 \SpecialChar ~
30366 \SpecialChar ~
30367 \SpecialChar ~
30368 \SpecialChar ~
30369 \SpecialChar ~
30370 \SpecialChar ~
30371 \SpecialChar ~
30372 \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  66 ;\SpecialChar ~
30389  hob.c 9 
30390 \newline 
30391 0016 E5*01\SpecialChar ~
30392 \SpecialChar ~
30393 \SpecialChar ~
30394 \SpecialChar ~
30395 \SpecialChar ~
30396 \SpecialChar ~
30397 \SpecialChar ~
30398 \SpecialChar ~
30399 \SpecialChar ~
30400 \SpecialChar ~
30401 \SpecialChar ~
30402 \SpecialChar ~
30403 \SpecialChar ~
30404 \SpecialChar ~
30405 \SpecialChar ~
30406  67\SpecialChar ~
30407 \SpecialChar ~
30408 \SpecialChar ~
30409 \SpecialChar ~
30410 \SpecialChar ~
30411 \SpecialChar ~
30412 \SpecialChar ~
30413 \SpecialChar ~
30414  mov\SpecialChar ~
30415 \SpecialChar ~
30416  a,(_gint + 1) 
30417 \newline 
30418 0018 33\SpecialChar ~
30419 \SpecialChar ~
30420 \SpecialChar ~
30421 \SpecialChar ~
30422 \SpecialChar ~
30423 \SpecialChar ~
30424 \SpecialChar ~
30425 \SpecialChar ~
30426 \SpecialChar ~
30427 \SpecialChar ~
30428 \SpecialChar ~
30429 \SpecialChar ~
30430 \SpecialChar ~
30431 \SpecialChar ~
30432 \SpecialChar ~
30433 \SpecialChar ~
30434 \SpecialChar ~
30435 \SpecialChar ~
30436  68\SpecialChar ~
30437 \SpecialChar ~
30438 \SpecialChar ~
30439 \SpecialChar ~
30440 \SpecialChar ~
30441 \SpecialChar ~
30442 \SpecialChar ~
30443 \SpecialChar ~
30444  rlc\SpecialChar ~
30445 \SpecialChar ~
30446  a 
30447 \newline 
30448 0019 92*01\SpecialChar ~
30449 \SpecialChar ~
30450 \SpecialChar ~
30451 \SpecialChar ~
30452 \SpecialChar ~
30453 \SpecialChar ~
30454 \SpecialChar ~
30455 \SpecialChar ~
30456 \SpecialChar ~
30457 \SpecialChar ~
30458 \SpecialChar ~
30459 \SpecialChar ~
30460 \SpecialChar ~
30461 \SpecialChar ~
30462 \SpecialChar ~
30463  69\SpecialChar ~
30464 \SpecialChar ~
30465 \SpecialChar ~
30466 \SpecialChar ~
30467 \SpecialChar ~
30468 \SpecialChar ~
30469 \SpecialChar ~
30470 \SpecialChar ~
30471  mov\SpecialChar ~
30472 \SpecialChar ~
30473  _foo_hob3_1_1,c 
30474 \newline 
30475 \SpecialChar ~
30476 \SpecialChar ~
30477 \SpecialChar ~
30478 \SpecialChar ~
30479 \SpecialChar ~
30480 \SpecialChar ~
30481 \SpecialChar ~
30482 \SpecialChar ~
30483 \SpecialChar ~
30484 \SpecialChar ~
30485 \SpecialChar ~
30486 \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  70 ;\SpecialChar ~
30501  hob.c 10 
30502 \newline 
30503 001B E5*01\SpecialChar ~
30504 \SpecialChar ~
30505 \SpecialChar ~
30506 \SpecialChar ~
30507 \SpecialChar ~
30508 \SpecialChar ~
30509 \SpecialChar ~
30510 \SpecialChar ~
30511 \SpecialChar ~
30512 \SpecialChar ~
30513 \SpecialChar ~
30514 \SpecialChar ~
30515 \SpecialChar ~
30516 \SpecialChar ~
30517 \SpecialChar ~
30518  71\SpecialChar ~
30519 \SpecialChar ~
30520 \SpecialChar ~
30521 \SpecialChar ~
30522 \SpecialChar ~
30523 \SpecialChar ~
30524 \SpecialChar ~
30525 \SpecialChar ~
30526  mov\SpecialChar ~
30527 \SpecialChar ~
30528  a,(_gint + 1) 
30529 \newline 
30530 001D 03\SpecialChar ~
30531 \SpecialChar ~
30532 \SpecialChar ~
30533 \SpecialChar ~
30534 \SpecialChar ~
30535 \SpecialChar ~
30536 \SpecialChar ~
30537 \SpecialChar ~
30538 \SpecialChar ~
30539 \SpecialChar ~
30540 \SpecialChar ~
30541 \SpecialChar ~
30542 \SpecialChar ~
30543 \SpecialChar ~
30544 \SpecialChar ~
30545 \SpecialChar ~
30546 \SpecialChar ~
30547 \SpecialChar ~
30548  72\SpecialChar ~
30549 \SpecialChar ~
30550 \SpecialChar ~
30551 \SpecialChar ~
30552 \SpecialChar ~
30553 \SpecialChar ~
30554 \SpecialChar ~
30555 \SpecialChar ~
30556  rr\SpecialChar ~
30557 \SpecialChar ~
30558 \SpecialChar ~
30559  a 
30560 \newline 
30561 001E 54 01\SpecialChar ~
30562 \SpecialChar ~
30563 \SpecialChar ~
30564 \SpecialChar ~
30565 \SpecialChar ~
30566 \SpecialChar ~
30567 \SpecialChar ~
30568 \SpecialChar ~
30569 \SpecialChar ~
30570 \SpecialChar ~
30571 \SpecialChar ~
30572 \SpecialChar ~
30573 \SpecialChar ~
30574 \SpecialChar ~
30575 \SpecialChar ~
30576  73\SpecialChar ~
30577 \SpecialChar ~
30578 \SpecialChar ~
30579 \SpecialChar ~
30580 \SpecialChar ~
30581 \SpecialChar ~
30582 \SpecialChar ~
30583 \SpecialChar ~
30584  anl\SpecialChar ~
30585 \SpecialChar ~
30586  a,#0x01 
30587 \newline 
30588 0020 F5*03\SpecialChar ~
30589 \SpecialChar ~
30590 \SpecialChar ~
30591 \SpecialChar ~
30592 \SpecialChar ~
30593 \SpecialChar ~
30594 \SpecialChar ~
30595 \SpecialChar ~
30596 \SpecialChar ~
30597 \SpecialChar ~
30598 \SpecialChar ~
30599 \SpecialChar ~
30600 \SpecialChar ~
30601 \SpecialChar ~
30602 \SpecialChar ~
30603  74\SpecialChar ~
30604 \SpecialChar ~
30605 \SpecialChar ~
30606 \SpecialChar ~
30607 \SpecialChar ~
30608 \SpecialChar ~
30609 \SpecialChar ~
30610 \SpecialChar ~
30611  mov\SpecialChar ~
30612 \SpecialChar ~
30613  _foo_aob1_1_1,a 
30614 \newline 
30615 \SpecialChar ~
30616 \SpecialChar ~
30617 \SpecialChar ~
30618 \SpecialChar ~
30619 \SpecialChar ~
30620 \SpecialChar ~
30621 \SpecialChar ~
30622 \SpecialChar ~
30623 \SpecialChar ~
30624 \SpecialChar ~
30625 \SpecialChar ~
30626 \SpecialChar ~
30627 \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  75 ;\SpecialChar ~
30641  hob.c 11 
30642 \newline 
30643 0022 E5*01\SpecialChar ~
30644 \SpecialChar ~
30645 \SpecialChar ~
30646 \SpecialChar ~
30647 \SpecialChar ~
30648 \SpecialChar ~
30649 \SpecialChar ~
30650 \SpecialChar ~
30651 \SpecialChar ~
30652 \SpecialChar ~
30653 \SpecialChar ~
30654 \SpecialChar ~
30655 \SpecialChar ~
30656 \SpecialChar ~
30657 \SpecialChar ~
30658  76\SpecialChar ~
30659 \SpecialChar ~
30660 \SpecialChar ~
30661 \SpecialChar ~
30662 \SpecialChar ~
30663 \SpecialChar ~
30664 \SpecialChar ~
30665 \SpecialChar ~
30666  mov\SpecialChar ~
30667 \SpecialChar ~
30668  a,(_gint + 1) 
30669 \newline 
30670 0024 13\SpecialChar ~
30671 \SpecialChar ~
30672 \SpecialChar ~
30673 \SpecialChar ~
30674 \SpecialChar ~
30675 \SpecialChar ~
30676 \SpecialChar ~
30677 \SpecialChar ~
30678 \SpecialChar ~
30679 \SpecialChar ~
30680 \SpecialChar ~
30681 \SpecialChar ~
30682 \SpecialChar ~
30683 \SpecialChar ~
30684 \SpecialChar ~
30685 \SpecialChar ~
30686 \SpecialChar ~
30687 \SpecialChar ~
30688  77\SpecialChar ~
30689 \SpecialChar ~
30690 \SpecialChar ~
30691 \SpecialChar ~
30692 \SpecialChar ~
30693 \SpecialChar ~
30694 \SpecialChar ~
30695 \SpecialChar ~
30696  rrc\SpecialChar ~
30697 \SpecialChar ~
30698  a 
30699 \newline 
30700 0025 92*02\SpecialChar ~
30701 \SpecialChar ~
30702 \SpecialChar ~
30703 \SpecialChar ~
30704 \SpecialChar ~
30705 \SpecialChar ~
30706 \SpecialChar ~
30707 \SpecialChar ~
30708 \SpecialChar ~
30709 \SpecialChar ~
30710 \SpecialChar ~
30711 \SpecialChar ~
30712 \SpecialChar ~
30713 \SpecialChar ~
30714 \SpecialChar ~
30715  78\SpecialChar ~
30716 \SpecialChar ~
30717 \SpecialChar ~
30718 \SpecialChar ~
30719 \SpecialChar ~
30720 \SpecialChar ~
30721 \SpecialChar ~
30722 \SpecialChar ~
30723  mov\SpecialChar ~
30724 \SpecialChar ~
30725  _foo_aob2_1_1,c 
30726 \newline 
30727 \SpecialChar ~
30728 \SpecialChar ~
30729 \SpecialChar ~
30730 \SpecialChar ~
30731 \SpecialChar ~
30732 \SpecialChar ~
30733 \SpecialChar ~
30734 \SpecialChar ~
30735 \SpecialChar ~
30736 \SpecialChar ~
30737 \SpecialChar ~
30738 \SpecialChar ~
30739 \SpecialChar ~
30740 \SpecialChar ~
30741 \SpecialChar ~
30742 \SpecialChar ~
30743 \SpecialChar ~
30744 \SpecialChar ~
30745 \SpecialChar ~
30746 \SpecialChar ~
30747 \SpecialChar ~
30748 \SpecialChar ~
30749 \SpecialChar ~
30750 \SpecialChar ~
30751 \SpecialChar ~
30752  79 ;\SpecialChar ~
30753  hob.c 12 
30754 \newline 
30755 0027 E5*01\SpecialChar ~
30756 \SpecialChar ~
30757 \SpecialChar ~
30758 \SpecialChar ~
30759 \SpecialChar ~
30760 \SpecialChar ~
30761 \SpecialChar ~
30762 \SpecialChar ~
30763 \SpecialChar ~
30764 \SpecialChar ~
30765 \SpecialChar ~
30766 \SpecialChar ~
30767 \SpecialChar ~
30768 \SpecialChar ~
30769 \SpecialChar ~
30770  80\SpecialChar ~
30771 \SpecialChar ~
30772 \SpecialChar ~
30773 \SpecialChar ~
30774 \SpecialChar ~
30775 \SpecialChar ~
30776 \SpecialChar ~
30777 \SpecialChar ~
30778  mov\SpecialChar ~
30779 \SpecialChar ~
30780  a,(_gint + 1) 
30781 \newline 
30782 0029 A2 E3\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  81\SpecialChar ~
30798 \SpecialChar ~
30799 \SpecialChar ~
30800 \SpecialChar ~
30801 \SpecialChar ~
30802 \SpecialChar ~
30803 \SpecialChar ~
30804 \SpecialChar ~
30805  mov\SpecialChar ~
30806 \SpecialChar ~
30807  c,acc[3] 
30808 \newline 
30809 002B 92*03\SpecialChar ~
30810 \SpecialChar ~
30811 \SpecialChar ~
30812 \SpecialChar ~
30813 \SpecialChar ~
30814 \SpecialChar ~
30815 \SpecialChar ~
30816 \SpecialChar ~
30817 \SpecialChar ~
30818 \SpecialChar ~
30819 \SpecialChar ~
30820 \SpecialChar ~
30821 \SpecialChar ~
30822 \SpecialChar ~
30823 \SpecialChar ~
30824  82\SpecialChar ~
30825 \SpecialChar ~
30826 \SpecialChar ~
30827 \SpecialChar ~
30828 \SpecialChar ~
30829 \SpecialChar ~
30830 \SpecialChar ~
30831 \SpecialChar ~
30832  mov\SpecialChar ~
30833 \SpecialChar ~
30834  _foo_aob3_1_1,c 
30835 \layout Standard
30836
30837 Other variations of these cases however will 
30838 \emph on 
30839 not
30840 \emph default 
30841  be recognized.
30842  They are standard C expressions, so I heartily recommend these be the only
30843  way to get the highest order bit, (it is portable).
30844  Of course it will be recognized even if it is embedded in other expressions,
30845  e.g.:
30846 \layout Verse
30847
30848
30849 \family typewriter 
30850 xyz = gint + ((gint >> 15) & 1);
30851 \layout Standard
30852
30853 will still be recognized.
30854 \layout Subsection
30855
30856 Higher Order Byte
30857 \begin_inset LatexCommand \index{Higher Order Byte}
30858
30859 \end_inset 
30860
30861  / Higher Order Word
30862 \begin_inset LatexCommand \index{Higher Order Word}
30863
30864 \end_inset 
30865
30866
30867 \layout Standard
30868
30869 It is also frequently required to obtain a higher order byte or word of
30870  a larger integral type (long, int or short types).
30871  SDCC recognizes the following expressions to yield the higher order byte
30872  or word and generates optimized code for it, e.g.:
30873 \layout Verse
30874
30875
30876 \family typewriter 
30877 unsigned int gint; 
30878 \newline 
30879 unsigned long int glong; 
30880 \newline 
30881
30882 \newline 
30883 foo () { 
30884 \newline 
30885 \SpecialChar ~
30886 \SpecialChar ~
30887 unsigned char hob1, hob2; 
30888 \newline 
30889 \SpecialChar ~
30890 \SpecialChar ~
30891 unsigned int how1, how2; 
30892 \newline 
30893 \SpecialChar ~
30894 \SpecialChar ~
30895 ...
30896  
30897 \newline 
30898 \SpecialChar ~
30899 \SpecialChar ~
30900 hob1 = (gint >> 8) & 0xFF; 
30901 \newline 
30902 \SpecialChar ~
30903 \SpecialChar ~
30904 hob2 = glong >> 24; 
30905 \newline 
30906 \SpecialChar ~
30907 \SpecialChar ~
30908 how1 = (glong >> 16) & 0xFFFF; 
30909 \newline 
30910 \SpecialChar ~
30911 \SpecialChar ~
30912 how2 = glong >> 8; 
30913 \newline 
30914 \SpecialChar ~
30915 \SpecialChar ~
30916 ..
30917  
30918 \newline 
30919 }
30920 \layout Standard
30921
30922 will generate the following code:
30923 \layout Verse
30924
30925
30926 \family typewriter 
30927 \SpecialChar ~
30928 \SpecialChar ~
30929 \SpecialChar ~
30930 \SpecialChar ~
30931 \SpecialChar ~
30932 \SpecialChar ~
30933 \SpecialChar ~
30934 \SpecialChar ~
30935 \SpecialChar ~
30936 \SpecialChar ~
30937 \SpecialChar ~
30938 \SpecialChar ~
30939 \SpecialChar ~
30940 \SpecialChar ~
30941 \SpecialChar ~
30942 \SpecialChar ~
30943 \SpecialChar ~
30944 \SpecialChar ~
30945 \SpecialChar ~
30946 \SpecialChar ~
30947 \SpecialChar ~
30948 \SpecialChar ~
30949 \SpecialChar ~
30950 \SpecialChar ~
30951 \SpecialChar ~
30952  91 ;\SpecialChar ~
30953  hob.c 15 
30954 \newline 
30955 0037 85*01*06\SpecialChar ~
30956 \SpecialChar ~
30957 \SpecialChar ~
30958 \SpecialChar ~
30959 \SpecialChar ~
30960 \SpecialChar ~
30961 \SpecialChar ~
30962 \SpecialChar ~
30963 \SpecialChar ~
30964 \SpecialChar ~
30965 \SpecialChar ~
30966 \SpecialChar ~
30967  92\SpecialChar ~
30968 \SpecialChar ~
30969 \SpecialChar ~
30970 \SpecialChar ~
30971 \SpecialChar ~
30972 \SpecialChar ~
30973 \SpecialChar ~
30974 \SpecialChar ~
30975  mov\SpecialChar ~
30976 \SpecialChar ~
30977  _foo_hob1_1_1,(_gint + 1) 
30978 \newline 
30979 \SpecialChar ~
30980 \SpecialChar ~
30981 \SpecialChar ~
30982 \SpecialChar ~
30983 \SpecialChar ~
30984 \SpecialChar ~
30985 \SpecialChar ~
30986 \SpecialChar ~
30987 \SpecialChar ~
30988 \SpecialChar ~
30989 \SpecialChar ~
30990 \SpecialChar ~
30991 \SpecialChar ~
30992 \SpecialChar ~
30993 \SpecialChar ~
30994 \SpecialChar ~
30995 \SpecialChar ~
30996 \SpecialChar ~
30997 \SpecialChar ~
30998 \SpecialChar ~
30999 \SpecialChar ~
31000 \SpecialChar ~
31001 \SpecialChar ~
31002 \SpecialChar ~
31003 \SpecialChar ~
31004  93 ;\SpecialChar ~
31005  hob.c 16 
31006 \newline 
31007 003A 85*05*07\SpecialChar ~
31008 \SpecialChar ~
31009 \SpecialChar ~
31010 \SpecialChar ~
31011 \SpecialChar ~
31012 \SpecialChar ~
31013 \SpecialChar ~
31014 \SpecialChar ~
31015 \SpecialChar ~
31016 \SpecialChar ~
31017 \SpecialChar ~
31018 \SpecialChar ~
31019  94\SpecialChar ~
31020 \SpecialChar ~
31021 \SpecialChar ~
31022 \SpecialChar ~
31023 \SpecialChar ~
31024 \SpecialChar ~
31025 \SpecialChar ~
31026 \SpecialChar ~
31027  mov\SpecialChar ~
31028 \SpecialChar ~
31029  _foo_hob2_1_1,(_glong + 3) 
31030 \newline 
31031 \SpecialChar ~
31032 \SpecialChar ~
31033 \SpecialChar ~
31034 \SpecialChar ~
31035 \SpecialChar ~
31036 \SpecialChar ~
31037 \SpecialChar ~
31038 \SpecialChar ~
31039 \SpecialChar ~
31040 \SpecialChar ~
31041 \SpecialChar ~
31042 \SpecialChar ~
31043 \SpecialChar ~
31044 \SpecialChar ~
31045 \SpecialChar ~
31046 \SpecialChar ~
31047 \SpecialChar ~
31048 \SpecialChar ~
31049 \SpecialChar ~
31050 \SpecialChar ~
31051 \SpecialChar ~
31052 \SpecialChar ~
31053 \SpecialChar ~
31054 \SpecialChar ~
31055 \SpecialChar ~
31056  95 ;\SpecialChar ~
31057  hob.c 17 
31058 \newline 
31059 003D 85*04*08\SpecialChar ~
31060 \SpecialChar ~
31061 \SpecialChar ~
31062 \SpecialChar ~
31063 \SpecialChar ~
31064 \SpecialChar ~
31065 \SpecialChar ~
31066 \SpecialChar ~
31067 \SpecialChar ~
31068 \SpecialChar ~
31069 \SpecialChar ~
31070 \SpecialChar ~
31071  96\SpecialChar ~
31072 \SpecialChar ~
31073 \SpecialChar ~
31074 \SpecialChar ~
31075 \SpecialChar ~
31076 \SpecialChar ~
31077 \SpecialChar ~
31078 \SpecialChar ~
31079  mov\SpecialChar ~
31080 \SpecialChar ~
31081  _foo_how1_1_1,(_glong + 2) 
31082 \newline 
31083 0040 85*05*09\SpecialChar ~
31084 \SpecialChar ~
31085 \SpecialChar ~
31086 \SpecialChar ~
31087 \SpecialChar ~
31088 \SpecialChar ~
31089 \SpecialChar ~
31090 \SpecialChar ~
31091 \SpecialChar ~
31092 \SpecialChar ~
31093 \SpecialChar ~
31094 \SpecialChar ~
31095  97\SpecialChar ~
31096 \SpecialChar ~
31097 \SpecialChar ~
31098 \SpecialChar ~
31099 \SpecialChar ~
31100 \SpecialChar ~
31101 \SpecialChar ~
31102 \SpecialChar ~
31103  mov\SpecialChar ~
31104 \SpecialChar ~
31105  (_foo_how1_1_1 + 1),(_glong + 3) 
31106 \newline 
31107 0043 85*03*0A\SpecialChar ~
31108 \SpecialChar ~
31109 \SpecialChar ~
31110 \SpecialChar ~
31111 \SpecialChar ~
31112 \SpecialChar ~
31113 \SpecialChar ~
31114 \SpecialChar ~
31115 \SpecialChar ~
31116 \SpecialChar ~
31117 \SpecialChar ~
31118 \SpecialChar ~
31119  98\SpecialChar ~
31120 \SpecialChar ~
31121 \SpecialChar ~
31122 \SpecialChar ~
31123 \SpecialChar ~
31124 \SpecialChar ~
31125 \SpecialChar ~
31126 \SpecialChar ~
31127  mov\SpecialChar ~
31128 \SpecialChar ~
31129  _foo_how2_1_1,(_glong + 1) 
31130 \newline 
31131 0046 85*04*0B\SpecialChar ~
31132 \SpecialChar ~
31133 \SpecialChar ~
31134 \SpecialChar ~
31135 \SpecialChar ~
31136 \SpecialChar ~
31137 \SpecialChar ~
31138 \SpecialChar ~
31139 \SpecialChar ~
31140 \SpecialChar ~
31141 \SpecialChar ~
31142 \SpecialChar ~
31143  99\SpecialChar ~
31144 \SpecialChar ~
31145 \SpecialChar ~
31146 \SpecialChar ~
31147 \SpecialChar ~
31148 \SpecialChar ~
31149 \SpecialChar ~
31150 \SpecialChar ~
31151  mov\SpecialChar ~
31152 \SpecialChar ~
31153  (_foo_how2_1_1 + 1),(_glong + 2) 
31154 \layout Standard
31155
31156 Again, variations of these cases may 
31157 \emph on 
31158 not
31159 \emph default 
31160  be recognized.
31161  They are standard C expressions, so I heartily recommend these be the only
31162  way to get the higher order byte/word, (it is portable).
31163  Of course it will be recognized even if it is embedded in other expressions,
31164  e.g.:
31165 \layout Verse
31166
31167
31168 \family typewriter 
31169 xyz = gint + ((gint >> 8) & 0xFF);
31170 \layout Standard
31171
31172 will still be recognized.
31173 \layout Subsection
31174
31175 Peephole Optimizer
31176 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
31177
31178 \end_inset 
31179
31180
31181 \begin_inset LatexCommand \index{Peephole optimizer}
31182
31183 \end_inset 
31184
31185
31186 \layout Standard
31187
31188 The compiler uses a rule based, pattern matching and re-writing mechanism
31189  for peep-hole optimization.
31190  It is inspired by 
31191 \emph on 
31192 copt
31193 \emph default 
31194  a peep-hole optimizer by Christopher W.
31195  Fraser (cwfraser\SpecialChar ~
31196 @\SpecialChar ~
31197 microsoft.com).
31198  A default set of rules are compiled into the compiler, additional rules
31199  may be added with the 
31200 \emph on 
31201 -
31202 \begin_inset ERT
31203 status Collapsed
31204
31205 \layout Standard
31206
31207 \backslash 
31208 /
31209 \end_inset 
31210
31211 -peep-file
31212 \begin_inset LatexCommand \index{-\/-peep-file}
31213
31214 \end_inset 
31215
31216  <filename>
31217 \emph default 
31218  option.
31219  The rule language is best illustrated with examples.
31220 \layout Verse
31221
31222
31223 \family typewriter 
31224 replace { 
31225 \newline 
31226 \SpecialChar ~
31227 \SpecialChar ~
31228 mov %1,a 
31229 \newline 
31230 \SpecialChar ~
31231 \SpecialChar ~
31232 mov a,%1
31233 \newline 
31234 } by {
31235 \newline 
31236 \SpecialChar ~
31237 \SpecialChar ~
31238 mov %1,a
31239 \newline 
31240 }
31241 \layout Standard
31242
31243 The above rule will change the following assembly
31244 \begin_inset LatexCommand \index{Assembler routines}
31245
31246 \end_inset 
31247
31248  sequence:
31249 \layout Verse
31250
31251
31252 \family typewriter 
31253 mov r1,a 
31254 \newline 
31255 mov a,r1
31256 \layout Standard
31257
31258 to
31259 \layout Verse
31260
31261
31262 \family typewriter 
31263 mov r1,a
31264 \layout Standard
31265
31266 Note: All occurrences of a 
31267 \emph on 
31268 %n
31269 \emph default 
31270  (pattern variable) must denote the same string.
31271  With the above rule, the assembly sequence:
31272 \layout Verse
31273
31274
31275 \family typewriter 
31276 mov r1,a 
31277 \newline 
31278 mov a,r2
31279 \layout Standard
31280
31281 will remain unmodified.
31282 \newline 
31283
31284 \newline 
31285 Other special case optimizations may be added by the user (via 
31286 \emph on 
31287 -
31288 \begin_inset ERT
31289 status Collapsed
31290
31291 \layout Standard
31292
31293 \backslash 
31294 /
31295 \end_inset 
31296
31297 -peep-file option
31298 \emph default 
31299 ).
31300  E.g.
31301  some variants of the 8051 MCU
31302 \begin_inset LatexCommand \index{MCS51 variants}
31303
31304 \end_inset 
31305
31306  allow only 
31307 \family typewriter 
31308 ajmp
31309 \family default 
31310  and 
31311 \family typewriter 
31312 acall
31313 \family default 
31314 .
31315  The following two rules will change all 
31316 \family typewriter 
31317 ljmp
31318 \family default 
31319  and 
31320 \family typewriter 
31321 lcall
31322 \family default 
31323  to 
31324 \family typewriter 
31325 ajmp
31326 \family default 
31327  and 
31328 \family typewriter 
31329 acall
31330 \layout Verse
31331
31332
31333 \family typewriter 
31334 replace { lcall %1 } by { acall %1 } 
31335 \newline 
31336 replace { ljmp %1 } by { ajmp %1 }
31337 \layout Standard
31338
31339 The 
31340 \emph on 
31341 inline-assembler code
31342 \emph default 
31343  is also passed through the peep hole optimizer, thus the peephole optimizer
31344  can also be used as an assembly level macro expander.
31345  The rules themselves are MCU dependent whereas the rule language infra-structur
31346 e is MCU independent.
31347  Peephole optimization rules for other MCU can be easily programmed using
31348  the rule language.
31349 \newline 
31350
31351 \newline 
31352 The syntax for a rule is as follows:
31353 \layout Verse
31354
31355
31356 \family typewriter 
31357 rule := replace [ restart ] '{' <assembly sequence> '
31358 \backslash 
31359 n' 
31360 \newline 
31361 \SpecialChar ~
31362  \SpecialChar ~
31363  \SpecialChar ~
31364  \SpecialChar ~
31365  \SpecialChar ~
31366  \SpecialChar ~
31367  \SpecialChar ~
31368  \SpecialChar ~
31369  \SpecialChar ~
31370  \SpecialChar ~
31371  \SpecialChar ~
31372  \SpecialChar ~
31373  \SpecialChar ~
31374  \SpecialChar ~
31375  '}' by '{' '
31376 \backslash 
31377 n' 
31378 \newline 
31379 \SpecialChar ~
31380  \SpecialChar ~
31381  \SpecialChar ~
31382  \SpecialChar ~
31383  \SpecialChar ~
31384  \SpecialChar ~
31385  \SpecialChar ~
31386  \SpecialChar ~
31387  \SpecialChar ~
31388  \SpecialChar ~
31389  \SpecialChar ~
31390  \SpecialChar ~
31391  \SpecialChar ~
31392  \SpecialChar ~
31393  \SpecialChar ~
31394  \SpecialChar ~
31395  <assembly sequence> '
31396 \backslash 
31397 n' 
31398 \newline 
31399 \SpecialChar ~
31400  \SpecialChar ~
31401  \SpecialChar ~
31402  \SpecialChar ~
31403  \SpecialChar ~
31404  \SpecialChar ~
31405  \SpecialChar ~
31406  \SpecialChar ~
31407  \SpecialChar ~
31408  \SpecialChar ~
31409  \SpecialChar ~
31410  \SpecialChar ~
31411  \SpecialChar ~
31412  \SpecialChar ~
31413  '}' [if <functionName> ] '
31414 \backslash 
31415 n' 
31416 \layout Standard
31417
31418 <assembly sequence> := assembly instruction (each instruction including
31419  labels must be on a separate line).
31420 \newline 
31421
31422 \newline 
31423 The optimizer will apply to the rules one by one from the top in the sequence
31424  of their appearance, it will terminate when all rules are exhausted.
31425  If the 'restart' option is specified, then the optimizer will start matching
31426  the rules again from the top, this option for a rule is expensive (performance)
31427 , it is intended to be used in situations where a transformation will trigger
31428  the same rule again.
31429  An example of this (not a good one, it has side effects) is the following
31430  rule:
31431 \layout Verse
31432
31433
31434 \family typewriter 
31435 replace restart { 
31436 \newline 
31437 \SpecialChar ~
31438 \SpecialChar ~
31439 pop %1 
31440 \newline 
31441 \SpecialChar ~
31442 \SpecialChar ~
31443 push %1 } by { 
31444 \newline 
31445 \SpecialChar ~
31446 \SpecialChar ~
31447 ; nop 
31448 \newline 
31449 }
31450 \layout Standard
31451
31452 Note that the replace pattern cannot be a blank, but can be a comment line.
31453  Without the 'restart' option only the innermost 'pop' 'push' pair would
31454  be eliminated, i.e.:
31455 \layout Verse
31456
31457
31458 \family typewriter 
31459 pop ar1 
31460 \newline 
31461 pop ar2 
31462 \newline 
31463 push ar2 
31464 \newline 
31465 push ar1
31466 \layout Standard
31467
31468 would result in:
31469 \layout Verse
31470
31471
31472 \family typewriter 
31473 pop ar1 
31474 \newline 
31475 ; nop 
31476 \newline 
31477 push ar1
31478 \layout Standard
31479
31480
31481 \emph on 
31482 with
31483 \emph default 
31484  the restart option the rule will be applied again to the resulting code
31485  and then all the pop-push pairs will be eliminated to yield:
31486 \layout Verse
31487
31488
31489 \family typewriter 
31490 ; nop 
31491 \newline 
31492 ; nop
31493 \layout Standard
31494
31495 A conditional function can be attached to a rule.
31496  Attaching rules are somewhat more involved, let me illustrate this with
31497  an example.
31498 \layout Verse
31499
31500
31501 \family typewriter 
31502 replace { 
31503 \newline 
31504 \SpecialChar ~
31505  \SpecialChar ~
31506  \SpecialChar ~
31507 ljmp %5 
31508 \newline 
31509 %2:
31510 \newline 
31511 } by { 
31512 \newline 
31513 \SpecialChar ~
31514  \SpecialChar ~
31515  \SpecialChar ~
31516 sjmp %5 
31517 \newline 
31518 %2:
31519 \newline 
31520 } if labelInRange
31521 \layout Standard
31522
31523 The optimizer does a look-up of a function name table defined in function
31524  
31525 \emph on 
31526 callFuncByName
31527 \emph default 
31528  in the source file SDCCpeeph.c, with the name 
31529 \emph on 
31530 labelInRange
31531 \emph default 
31532 .
31533  If it finds a corresponding entry the function is called.
31534  Note there can be no parameters specified for these functions, in this
31535  case the use of 
31536 \emph on 
31537 %5
31538 \emph default 
31539  is crucial, since the function 
31540 \emph on 
31541 labelInRange
31542 \emph default 
31543  expects to find the label in that particular variable (the hash table containin
31544 g the variable bindings is passed as a parameter).
31545  If you want to code more such functions, take a close look at the function
31546  labelInRange and the calling mechanism in source file SDCCpeeph.c.
31547  Currently implemented are 
31548 \emph on 
31549 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
31550  24bitMode, portIsDS390, 24bitModeAndPortDS390 
31551 \emph default 
31552 and
31553 \emph on 
31554  notVolatile
31555 \emph default 
31556 .
31557 \layout Standard
31558
31559 I know this whole thing is a little kludgey, but maybe some day we will
31560  have some better means.
31561  If you are looking at this file, you will see the default rules that are
31562  compiled into the compiler, you can add your own rules in the default set
31563  there if you get tired of specifying the -
31564 \begin_inset ERT
31565 status Collapsed
31566
31567 \layout Standard
31568
31569 \backslash 
31570 /
31571 \end_inset 
31572
31573 -peep-file option.
31574 \layout Section
31575
31576 ANSI-Compliance
31577 \begin_inset LatexCommand \index{ANSI-compliance}
31578
31579 \end_inset 
31580
31581
31582 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
31583
31584 \end_inset 
31585
31586
31587 \layout Standard
31588
31589 The latest publically available version of the standard 
31590 \emph on 
31591 ISO/IEC 9899 - Programming languages - C
31592 \emph default 
31593  should be available at: 
31594 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31595
31596 \end_inset 
31597
31598 .
31599 \newline 
31600
31601 \layout Standard
31602
31603 Deviations from the compliance:
31604 \layout Itemize
31605
31606 functions are not reentrant
31607 \begin_inset LatexCommand \index{reentrant}
31608
31609 \end_inset 
31610
31611  unless explicitly declared as such or the 
31612 \series bold 
31613 -
31614 \begin_inset ERT
31615 status Collapsed
31616
31617 \layout Standard
31618
31619 \backslash 
31620 /
31621 \end_inset 
31622
31623 -stack-auto
31624 \begin_inset LatexCommand \index{-\/-stack-auto}
31625
31626 \end_inset 
31627
31628
31629 \series default 
31630  command line option is specified.
31631 \layout Itemize
31632
31633 structures
31634 \begin_inset LatexCommand \index{struct}
31635
31636 \end_inset 
31637
31638  and unions
31639 \begin_inset LatexCommand \index{union}
31640
31641 \end_inset 
31642
31643  cannot be assigned values directly, cannot be passed as function parameters
31644  or assigned to each other and cannot be a return value
31645 \begin_inset LatexCommand \index{return value}
31646
31647 \end_inset 
31648
31649  from a function, e.g.:
31650 \begin_deeper 
31651 \layout Verse
31652
31653
31654 \family typewriter 
31655 struct s { ...
31656  }; 
31657 \newline 
31658 struct s s1, s2; 
31659 \newline 
31660 foo() 
31661 \newline 
31662
31663 \newline 
31664 \SpecialChar ~
31665 \SpecialChar ~
31666 \SpecialChar ~
31667 \SpecialChar ~
31668 ...
31669  
31670 \newline 
31671 \SpecialChar ~
31672 \SpecialChar ~
31673 \SpecialChar ~
31674 \SpecialChar ~
31675 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
31676 \newline 
31677 \SpecialChar ~
31678 \SpecialChar ~
31679 \SpecialChar ~
31680 \SpecialChar ~
31681 ...
31682  
31683 \newline 
31684 }
31685 \newline 
31686
31687 \series bold 
31688 struct
31689 \series default 
31690  s foo1 (
31691 \series bold 
31692 struct
31693 \series default 
31694  s parms) /* invalid in SDCC although allowed in ANSI */
31695 \newline 
31696
31697 \newline 
31698 \SpecialChar ~
31699 \SpecialChar ~
31700 \SpecialChar ~
31701 \SpecialChar ~
31702 struct s rets; 
31703 \newline 
31704 \SpecialChar ~
31705 \SpecialChar ~
31706 \SpecialChar ~
31707 \SpecialChar ~
31708 ...
31709  
31710 \newline 
31711 \SpecialChar ~
31712 \SpecialChar ~
31713 \SpecialChar ~
31714 \SpecialChar ~
31715 return rets; /* is invalid in SDCC although allowed in ANSI */ 
31716 \newline 
31717 }
31718 \end_deeper 
31719 \layout Itemize
31720
31721 initialization of structure arrays must be fully braced.
31722 \begin_deeper 
31723 \layout Verse
31724
31725
31726 \family typewriter 
31727 struct s { char x } a[] = {1, 2};\SpecialChar ~
31728 \SpecialChar ~
31729 \SpecialChar ~
31730 \SpecialChar ~
31731 \SpecialChar ~
31732 /* invalid in SDCC */
31733 \newline 
31734 struct s { char x } a[] = {{1}, {2}}; /* OK */
31735 \end_deeper 
31736 \layout Itemize
31737
31738 'long long
31739 \begin_inset LatexCommand \index{long long (not supported)}
31740
31741 \end_inset 
31742
31743 ' (64 bit integers
31744 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
31745
31746 \end_inset 
31747
31748 ) not supported.
31749 \layout Itemize
31750
31751 'double
31752 \begin_inset LatexCommand \index{double (not supported)}
31753
31754 \end_inset 
31755
31756 ' precision floating point 
31757 \begin_inset LatexCommand \index{Floating point support}
31758
31759 \end_inset 
31760
31761 not supported.
31762 \layout Itemize
31763
31764 Old K&R style
31765 \begin_inset LatexCommand \index{K\&R style}
31766
31767 \end_inset 
31768
31769  function declarations are NOT allowed.
31770 \begin_deeper 
31771 \layout Verse
31772
31773
31774 \family typewriter 
31775 foo(i,j) /* this old style of function declarations */ 
31776 \newline 
31777 int i,j; /* are valid in ANSI but not valid in SDCC */ 
31778 \newline 
31779
31780 \newline 
31781 \SpecialChar ~
31782 \SpecialChar ~
31783 \SpecialChar ~
31784 \SpecialChar ~
31785 ...
31786  
31787 \newline 
31788 }
31789 \end_deeper 
31790 \layout Itemize
31791
31792 Most enhancements in C99 are not supported, f.e.:
31793 \begin_deeper 
31794 \layout Verse
31795
31796
31797 \family typewriter 
31798 \series bold 
31799 inline
31800 \begin_inset LatexCommand \index{inline (not supported)}
31801
31802 \end_inset 
31803
31804
31805 \series default 
31806  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
31807  in C99.
31808  An empty define 
31809 \emph on 
31810 #define inline
31811 \emph default 
31812  can be used as a work around */
31813 \newline 
31814
31815 \newline 
31816 for (
31817 \series bold 
31818 int
31819 \series default 
31820  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
31821 \end_deeper 
31822 \layout Itemize
31823
31824 Certain words that are valid identifiers in the standard may be reserved
31825  words in SDCC unless the 
31826 \series bold 
31827 -
31828 \begin_inset ERT
31829 status Collapsed
31830
31831 \layout Standard
31832
31833 \backslash 
31834 /
31835 \end_inset 
31836
31837 -std-c89
31838 \begin_inset LatexCommand \index{-\/-std-c89}
31839
31840 \end_inset 
31841
31842  or -
31843 \begin_inset ERT
31844 status Collapsed
31845
31846 \layout Standard
31847
31848 \backslash 
31849 /
31850 \end_inset 
31851
31852 -std-c99
31853 \begin_inset LatexCommand \index{-\/-std-c99}
31854
31855 \end_inset 
31856
31857
31858 \series default 
31859  command line options are used.
31860  These may include (depending on the selected processor): 'at', 'banked',
31861  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
31862 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
31863  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
31864  '_naked'.
31865  Compliant equivalents of these keywords are always available in a form
31866  that begin with two underscores
31867 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
31868
31869 \end_inset 
31870
31871 , f.e.
31872  '__data' instead of 'data'.
31873 \layout Section
31874
31875 Cyclomatic Complexity
31876 \begin_inset LatexCommand \index{Cyclomatic complexity}
31877
31878 \end_inset 
31879
31880
31881 \layout Standard
31882
31883 Cyclomatic complexity of a function is defined as the number of independent
31884  paths the program can take during execution of the function.
31885  This is an important number since it defines the number test cases you
31886  have to generate to validate the function.
31887  The accepted industry standard for complexity number is 10, if the cyclomatic
31888  complexity reported by SDCC exceeds 10 you should think about simplification
31889  of the function logic.
31890  Note that the complexity level is not related to the number of lines of
31891  code in a function.
31892  Large functions can have low complexity, and small functions can have large
31893  complexity levels.
31894  
31895 \newline 
31896
31897 \newline 
31898 SDCC uses the following formula to compute the complexity:
31899 \newline 
31900
31901 \layout Standard
31902
31903 complexity = (number of edges in control flow graph) - (number of nodes
31904  in control flow graph) + 2;
31905 \newline 
31906
31907 \newline 
31908 Having said that the industry standard is 10, you should be aware that in
31909  some cases it be may unavoidable to have a complexity level of less than
31910  10.
31911  For example if you have switch statement with more than 10 case labels,
31912  each case label adds one to the complexity level.
31913  The complexity level is by no means an absolute measure of the algorithmic
31914  complexity of the function, it does however provide a good starting point
31915  for which functions you might look at for further optimization.
31916 \layout Section
31917
31918 Retargetting for other Processors
31919 \layout Standard
31920
31921 The issues for retargetting the compiler are far too numerous to be covered
31922  by this document.
31923  What follows is a brief description of each of the seven phases of the
31924  compiler and its MCU dependency.
31925 \layout Itemize
31926
31927 Parsing the source and building the annotated parse tree.
31928  This phase is largely MCU independent (except for the language extensions).
31929  Syntax & semantic checks are also done in this phase, along with some initial
31930  optimizations like back patching labels and the pattern matching optimizations
31931  like bit-rotation etc.
31932 \layout Itemize
31933
31934 The second phase involves generating an intermediate code which can be easy
31935  manipulated during the later phases.
31936  This phase is entirely MCU independent.
31937  The intermediate code generation assumes the target machine has unlimited
31938  number of registers, and designates them with the name iTemp.
31939  The compiler can be made to dump a human readable form of the code generated
31940  by using the -
31941 \begin_inset ERT
31942 status Collapsed
31943
31944 \layout Standard
31945
31946 \backslash 
31947 /
31948 \end_inset 
31949
31950 -dumpraw option.
31951 \layout Itemize
31952
31953 This phase does the bulk of the standard optimizations and is also MCU independe
31954 nt.
31955  This phase can be broken down into several sub-phases:
31956 \newline 
31957
31958 \newline 
31959 Break down intermediate code (iCode) into basic blocks.
31960 \newline 
31961 Do control flow & data flow analysis on the basic blocks.
31962 \newline 
31963 Do local common subexpression elimination, then global subexpression elimination
31964 \newline 
31965 Dead code elimination
31966 \newline 
31967 Loop optimizations
31968 \newline 
31969 If loop optimizations caused any changes then do 'global subexpression eliminati
31970 on' and 'dead code elimination' again.
31971 \layout Itemize
31972
31973 This phase determines the live-ranges; by live range I mean those iTemp
31974  variables defined by the compiler that still survive after all the optimization
31975 s.
31976  Live range analysis
31977 \begin_inset LatexCommand \index{Live range analysis}
31978
31979 \end_inset 
31980
31981  is essential for register allocation, since these computation determines
31982  which of these iTemps will be assigned to registers, and for how long.
31983 \layout Itemize
31984
31985 Phase five is register allocation.
31986  There are two parts to this process.
31987 \newline 
31988
31989 \newline 
31990 The first part I call 'register packing' (for lack of a better term).
31991  In this case several MCU specific expression folding is done to reduce
31992  register pressure.
31993 \newline 
31994
31995 \newline 
31996 The second part is more MCU independent and deals with allocating registers
31997  to the remaining live ranges.
31998  A lot of MCU specific code does creep into this phase because of the limited
31999  number of index registers available in the 8051.
32000 \layout Itemize
32001
32002 The Code generation phase is (unhappily), entirely MCU dependent and very
32003  little (if any at all) of this code can be reused for other MCU.
32004  However the scheme for allocating a homogenized assembler operand for each
32005  iCode operand may be reused.
32006 \layout Itemize
32007
32008 As mentioned in the optimization section the peep-hole optimizer is rule
32009  based system, which can reprogrammed for other MCUs.
32010 \layout Standard
32011
32012 More information is available in a wiki
32013 \begin_inset LatexCommand \index{wiki}
32014
32015 \end_inset 
32016
32017  (preliminary link 
32018 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
32019
32020 \end_inset 
32021
32022 ) and in the thread 
32023 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
32024
32025 \end_inset 
32026
32027  .
32028 \layout Chapter
32029
32030 Compiler internals
32031 \begin_inset LatexCommand \index{Compiler internals}
32032
32033 \end_inset 
32034
32035
32036 \layout Section
32037
32038 The anatomy of the compiler
32039 \begin_inset LatexCommand \label{sub:The-anatomy-of}
32040
32041 \end_inset 
32042
32043
32044 \layout Standard
32045
32046
32047 \shape italic 
32048 This is an excerpt from an article published in Circuit Cellar Magazine
32049  in 
32050 \series bold 
32051 August 2000
32052 \series default 
32053 .
32054  It's a little outdated (the compiler is much more efficient now and user/develo
32055 per friendly), but pretty well exposes the guts of it all.
32056 \shape default 
32057
32058 \newline 
32059
32060 \newline 
32061 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
32062  It is fairly easy to retarget for other 8-bit MCU.
32063  Here we take a look at some of the internals of the compiler.
32064  
32065 \layout Paragraph*
32066
32067 Parsing
32068 \begin_inset LatexCommand \index{Parsing}
32069
32070 \end_inset 
32071
32072  
32073 \layout Standard
32074
32075 Parsing the input source file and creating an AST (Annotated Syntax Tree
32076 \begin_inset LatexCommand \index{Annotated syntax tree}
32077
32078 \end_inset 
32079
32080 ).
32081  This phase also involves propagating types (annotating each node of the
32082  parse tree with type information) and semantic analysis.
32083  There are some MCU specific parsing rules.
32084  For example the storage classes, the extended storage classes are MCU specific
32085  while there may be a xdata storage class for 8051 there is no such storage
32086  class for z80 or Atmel AVR.
32087  SDCC allows MCU specific storage class extensions, i.e.
32088  xdata will be treated as a storage class specifier when parsing 8051 C
32089  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
32090  C code.
32091 \layout Paragraph*
32092
32093 Generating iCode
32094 \begin_inset LatexCommand \index{iCode}
32095
32096 \end_inset 
32097
32098
32099 \layout Standard
32100
32101 Intermediate code generation.
32102  In this phase the AST is broken down into three-operand form (iCode).
32103  These three operand forms are represented as doubly linked lists.
32104  ICode is the term given to the intermediate form generated by the compiler.
32105  ICode example section shows some examples of iCode generated for some simple
32106  C source functions.
32107 \layout Paragraph*
32108
32109 Optimizations
32110 \begin_inset LatexCommand \index{Optimizations}
32111
32112 \end_inset 
32113
32114 .
32115 \layout Standard
32116
32117 Bulk of the target independent optimizations is performed in this phase.
32118  The optimizations include constant propagation, common sub-expression eliminati
32119 on, loop invariant code movement, strength reduction of loop induction variables
32120  and dead-code elimination.
32121 \layout Paragraph*
32122
32123 Live range analysis
32124 \begin_inset LatexCommand \index{Live range analysis}
32125
32126 \end_inset 
32127
32128
32129 \layout Standard
32130
32131 During intermediate code generation phase, the compiler assumes the target
32132  machine has infinite number of registers and generates a lot of temporary
32133  variables.
32134  The live range computation determines the lifetime of each of these compiler-ge
32135 nerated temporaries.
32136  A picture speaks a thousand words.
32137  ICode example sections show the live range annotations for each of the
32138  operand.
32139  It is important to note here, each iCode is assigned a number in the order
32140  of its execution in the function.
32141  The live ranges are computed in terms of these numbers.
32142  The from number is the number of the iCode which first defines the operand
32143  and the to number signifies the iCode which uses this operand last.
32144 \layout Paragraph*
32145
32146 Register Allocation
32147 \begin_inset LatexCommand \index{Register allocation}
32148
32149 \end_inset 
32150
32151
32152 \layout Standard
32153
32154 The register allocation determines the type and number of registers needed
32155  by each operand.
32156  In most MCUs only a few registers can be used for indirect addressing.
32157  In case of 8051 for example the registers R0 & R1 can be used to indirectly
32158  address the internal ram and DPTR to indirectly address the external ram.
32159  The compiler will try to allocate the appropriate register to pointer variables
32160  if it can.
32161  ICode example section shows the operands annotated with the registers assigned
32162  to them.
32163  The compiler will try to keep operands in registers as much as possible;
32164  there are several schemes the compiler uses to do achieve this.
32165  When the compiler runs out of registers the compiler will check to see
32166  if there are any live operands which is not used or defined in the current
32167  basic block being processed, if there are any found then it will push that
32168  operand and use the registers in this block, the operand will then be popped
32169  at the end of the basic block.
32170  
32171 \layout Standard
32172
32173 There are other MCU specific considerations in this phase.
32174  Some MCUs have an accumulator; very short-lived operands could be assigned
32175  to the accumulator instead of a general-purpose register.
32176 \layout Paragraph*
32177
32178 Code generation
32179 \layout Standard
32180
32181 Figure II gives a table of iCode
32182 \begin_inset LatexCommand \index{iCode}
32183
32184 \end_inset 
32185
32186  operations supported by the compiler.
32187  The code generation involves translating these operations into corresponding
32188  assembly code for the processor.
32189  This sounds overly simple but that is the essence of code generation.
32190  Some of the iCode operations are generated on a MCU specific manner for
32191  example, the z80 port does not use registers to pass parameters so the
32192  SEND and RECV iCode operations will not be generated, and it also does
32193  not support JUMPTABLES.
32194  
32195 \newline 
32196
32197 \layout Standard
32198
32199
32200 \size footnotesize 
32201 Figure II 
32202 \begin_inset  Tabular
32203 <lyxtabular version="3" rows="39" columns="4">
32204 <features islongtable="true" headBottomDL="true">
32205 <column alignment="block" valignment="top" leftline="true" width="13col%">
32206 <column alignment="left" valignment="top" leftline="true" width="13col%">
32207 <column alignment="block" valignment="top" leftline="true" width="22col%">
32208 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
32209 <row topline="true" bottomline="true" endhead="true">
32210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32211 \begin_inset Text
32212
32213 \layout Standard
32214
32215
32216 \series bold 
32217 iCode
32218 \series default 
32219
32220 \begin_inset LatexCommand \index{iCode}
32221
32222 \end_inset 
32223
32224
32225 \end_inset 
32226 </cell>
32227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32228 \begin_inset Text
32229
32230 \layout Standard
32231
32232
32233 \series bold 
32234 Operands
32235 \end_inset 
32236 </cell>
32237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32238 \begin_inset Text
32239
32240 \layout Standard
32241
32242
32243 \series bold 
32244 Description
32245 \end_inset 
32246 </cell>
32247 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32248 \begin_inset Text
32249
32250 \layout Standard
32251
32252
32253 \series bold 
32254 C Equivalent
32255 \end_inset 
32256 </cell>
32257 </row>
32258 <row topline="true">
32259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32260 \begin_inset Text
32261
32262 \layout Standard
32263
32264
32265 \size footnotesize 
32266 '!'
32267 \end_inset 
32268 </cell>
32269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32270 \begin_inset Text
32271
32272 \layout Standard
32273
32274
32275 \size footnotesize 
32276 IC_LEFT() IC_RESULT()
32277 \end_inset 
32278 </cell>
32279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32280 \begin_inset Text
32281
32282 \layout Standard
32283
32284
32285 \size footnotesize 
32286 NOT operation 
32287 \end_inset 
32288 </cell>
32289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32290 \begin_inset Text
32291
32292 \layout Standard
32293
32294
32295 \size footnotesize 
32296 IC_RESULT = ! IC_LEFT;
32297 \end_inset 
32298 </cell>
32299 </row>
32300 <row topline="true">
32301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32302 \begin_inset Text
32303
32304 \layout Standard
32305
32306
32307 \size footnotesize 
32308 '~'
32309 \end_inset 
32310 </cell>
32311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32312 \begin_inset Text
32313
32314 \layout Standard
32315
32316
32317 \size footnotesize 
32318 IC_LEFT() IC_RESULT()
32319 \end_inset 
32320 </cell>
32321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32322 \begin_inset Text
32323
32324 \layout Standard
32325
32326
32327 \size footnotesize 
32328 Bitwise complement of 
32329 \end_inset 
32330 </cell>
32331 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32332 \begin_inset Text
32333
32334 \layout Standard
32335
32336
32337 \size footnotesize 
32338 IC_RESULT = ~IC_LEFT;
32339 \end_inset 
32340 </cell>
32341 </row>
32342 <row topline="true">
32343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32344 \begin_inset Text
32345
32346 \layout Standard
32347
32348
32349 \size footnotesize 
32350 RRC
32351 \end_inset 
32352 </cell>
32353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32354 \begin_inset Text
32355
32356 \layout Standard
32357
32358
32359 \size footnotesize 
32360 IC_LEFT() IC_RESULT()
32361 \end_inset 
32362 </cell>
32363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32364 \begin_inset Text
32365
32366 \layout Standard
32367
32368
32369 \size footnotesize 
32370 Rotate right with carry
32371 \end_inset 
32372 </cell>
32373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32374 \begin_inset Text
32375
32376 \layout Standard
32377
32378
32379 \size footnotesize 
32380 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
32381 \end_inset 
32382 </cell>
32383 </row>
32384 <row topline="true">
32385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32386 \begin_inset Text
32387
32388 \layout Standard
32389
32390
32391 \size footnotesize 
32392 RLC
32393 \end_inset 
32394 </cell>
32395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32396 \begin_inset Text
32397
32398 \layout Standard
32399
32400
32401 \size footnotesize 
32402 IC_LEFT() IC_RESULT()
32403 \end_inset 
32404 </cell>
32405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32406 \begin_inset Text
32407
32408 \layout Standard
32409
32410
32411 \size footnotesize 
32412 Rotate left with carry
32413 \end_inset 
32414 </cell>
32415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32416 \begin_inset Text
32417
32418 \layout Standard
32419
32420
32421 \size footnotesize 
32422 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
32423 \end_inset 
32424 </cell>
32425 </row>
32426 <row topline="true">
32427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32428 \begin_inset Text
32429
32430 \layout Standard
32431
32432
32433 \size footnotesize 
32434 GETHBIT
32435 \end_inset 
32436 </cell>
32437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32438 \begin_inset Text
32439
32440 \layout Standard
32441
32442
32443 \size footnotesize 
32444 IC_LEFT() IC_RESULT()
32445 \end_inset 
32446 </cell>
32447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32448 \begin_inset Text
32449
32450 \layout Standard
32451
32452
32453 \size footnotesize 
32454 Get the highest order bit of IC_LEFT
32455 \end_inset 
32456 </cell>
32457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32458 \begin_inset Text
32459
32460 \layout Standard
32461
32462
32463 \size footnotesize 
32464 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
32465 \end_inset 
32466 </cell>
32467 </row>
32468 <row topline="true">
32469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32470 \begin_inset Text
32471
32472 \layout Standard
32473
32474
32475 \size footnotesize 
32476 UNARYMINUS
32477 \end_inset 
32478 </cell>
32479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32480 \begin_inset Text
32481
32482 \layout Standard
32483
32484
32485 \size footnotesize 
32486 IC_LEFT() IC_RESULT()
32487 \end_inset 
32488 </cell>
32489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32490 \begin_inset Text
32491
32492 \layout Standard
32493
32494
32495 \size footnotesize 
32496 Unary minus
32497 \end_inset 
32498 </cell>
32499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32500 \begin_inset Text
32501
32502 \layout Standard
32503
32504
32505 \size footnotesize 
32506 IC_RESULT = - IC_LEFT;
32507 \end_inset 
32508 </cell>
32509 </row>
32510 <row topline="true">
32511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32512 \begin_inset Text
32513
32514 \layout Standard
32515
32516
32517 \size footnotesize 
32518 IPUSH
32519 \end_inset 
32520 </cell>
32521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32522 \begin_inset Text
32523
32524 \layout Standard
32525
32526
32527 \size footnotesize 
32528 IC_LEFT()
32529 \end_inset 
32530 </cell>
32531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32532 \begin_inset Text
32533
32534 \layout Standard
32535
32536
32537 \size footnotesize 
32538 Push the operand into stack
32539 \end_inset 
32540 </cell>
32541 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32542 \begin_inset Text
32543
32544 \layout Standard
32545
32546
32547 \size footnotesize 
32548 NONE
32549 \end_inset 
32550 </cell>
32551 </row>
32552 <row topline="true">
32553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32554 \begin_inset Text
32555
32556 \layout Standard
32557
32558
32559 \size footnotesize 
32560 IPOP
32561 \end_inset 
32562 </cell>
32563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32564 \begin_inset Text
32565
32566 \layout Standard
32567
32568
32569 \size footnotesize 
32570 IC_LEFT()
32571 \end_inset 
32572 </cell>
32573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32574 \begin_inset Text
32575
32576 \layout Standard
32577
32578
32579 \size footnotesize 
32580 Pop the operand from the stack 
32581 \end_inset 
32582 </cell>
32583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32584 \begin_inset Text
32585
32586 \layout Standard
32587
32588
32589 \size footnotesize 
32590 NONE
32591 \end_inset 
32592 </cell>
32593 </row>
32594 <row topline="true">
32595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32596 \begin_inset Text
32597
32598 \layout Standard
32599
32600
32601 \size footnotesize 
32602 CALL
32603 \end_inset 
32604 </cell>
32605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32606 \begin_inset Text
32607
32608 \layout Standard
32609
32610
32611 \size footnotesize 
32612 IC_LEFT() IC_RESULT()
32613 \end_inset 
32614 </cell>
32615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32616 \begin_inset Text
32617
32618 \layout Standard
32619
32620
32621 \size footnotesize 
32622 Call the function represented by IC_LEFT 
32623 \end_inset 
32624 </cell>
32625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32626 \begin_inset Text
32627
32628 \layout Standard
32629
32630
32631 \size footnotesize 
32632 IC_RESULT = IC_LEFT();
32633 \end_inset 
32634 </cell>
32635 </row>
32636 <row topline="true">
32637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32638 \begin_inset Text
32639
32640 \layout Standard
32641
32642
32643 \size footnotesize 
32644 PCALL
32645 \end_inset 
32646 </cell>
32647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32648 \begin_inset Text
32649
32650 \layout Standard
32651
32652
32653 \size footnotesize 
32654 IC_LEFT() IC_RESULT()
32655 \end_inset 
32656 </cell>
32657 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32658 \begin_inset Text
32659
32660 \layout Standard
32661
32662
32663 \size footnotesize 
32664 Call via function pointer
32665 \end_inset 
32666 </cell>
32667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32668 \begin_inset Text
32669
32670 \layout Standard
32671
32672
32673 \size footnotesize 
32674 IC_RESULT = (*IC_LEFT)();
32675 \end_inset 
32676 </cell>
32677 </row>
32678 <row topline="true">
32679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32680 \begin_inset Text
32681
32682 \layout Standard
32683
32684
32685 \size footnotesize 
32686 RETURN
32687 \end_inset 
32688 </cell>
32689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32690 \begin_inset Text
32691
32692 \layout Standard
32693
32694
32695 \size footnotesize 
32696 IC_LEFT()
32697 \end_inset 
32698 </cell>
32699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32700 \begin_inset Text
32701
32702 \layout Standard
32703
32704
32705 \size footnotesize 
32706 Return the value in operand IC_LEFT 
32707 \end_inset 
32708 </cell>
32709 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32710 \begin_inset Text
32711
32712 \layout Standard
32713
32714
32715 \size footnotesize 
32716 return IC_LEFT;
32717 \end_inset 
32718 </cell>
32719 </row>
32720 <row topline="true">
32721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32722 \begin_inset Text
32723
32724 \layout Standard
32725
32726
32727 \size footnotesize 
32728 LABEL
32729 \end_inset 
32730 </cell>
32731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32732 \begin_inset Text
32733
32734 \layout Standard
32735
32736
32737 \size footnotesize 
32738 IC_LABEL() 
32739 \end_inset 
32740 </cell>
32741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32742 \begin_inset Text
32743
32744 \layout Standard
32745
32746
32747 \size footnotesize 
32748 Label
32749 \end_inset 
32750 </cell>
32751 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32752 \begin_inset Text
32753
32754 \layout Standard
32755
32756
32757 \size footnotesize 
32758 IC_LABEL:
32759 \end_inset 
32760 </cell>
32761 </row>
32762 <row topline="true">
32763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32764 \begin_inset Text
32765
32766 \layout Standard
32767
32768
32769 \size footnotesize 
32770 GOTO
32771 \end_inset 
32772 </cell>
32773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32774 \begin_inset Text
32775
32776 \layout Standard
32777
32778
32779 \size footnotesize 
32780 IC_LABEL() 
32781 \end_inset 
32782 </cell>
32783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32784 \begin_inset Text
32785
32786 \layout Standard
32787
32788
32789 \size footnotesize 
32790 Goto label
32791 \end_inset 
32792 </cell>
32793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32794 \begin_inset Text
32795
32796 \layout Standard
32797
32798
32799 \size footnotesize 
32800 goto IC_LABEL();
32801 \end_inset 
32802 </cell>
32803 </row>
32804 <row topline="true">
32805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32806 \begin_inset Text
32807
32808 \layout Standard
32809
32810
32811 \size footnotesize 
32812 '+'
32813 \end_inset 
32814 </cell>
32815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32816 \begin_inset Text
32817
32818 \layout Standard
32819
32820
32821 \size footnotesize 
32822 IC_LEFT() IC_RIGHT() IC_RESULT()
32823 \end_inset 
32824 </cell>
32825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32826 \begin_inset Text
32827
32828 \layout Standard
32829
32830
32831 \size footnotesize 
32832 Addition
32833 \end_inset 
32834 </cell>
32835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32836 \begin_inset Text
32837
32838 \layout Standard
32839
32840
32841 \size footnotesize 
32842 IC_RESULT = IC_LEFT + IC_RIGHT
32843 \end_inset 
32844 </cell>
32845 </row>
32846 <row topline="true">
32847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32848 \begin_inset Text
32849
32850 \layout Standard
32851
32852
32853 \size footnotesize 
32854 '-'
32855 \end_inset 
32856 </cell>
32857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32858 \begin_inset Text
32859
32860 \layout Standard
32861
32862
32863 \size footnotesize 
32864 IC_LEFT() IC_RIGHT() IC_RESULT()
32865 \end_inset 
32866 </cell>
32867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32868 \begin_inset Text
32869
32870 \layout Standard
32871
32872
32873 \size footnotesize 
32874 Subtraction
32875 \end_inset 
32876 </cell>
32877 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32878 \begin_inset Text
32879
32880 \layout Standard
32881
32882
32883 \size footnotesize 
32884 IC_RESULT = IC_LEFT - IC_RIGHT 
32885 \end_inset 
32886 </cell>
32887 </row>
32888 <row topline="true">
32889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32890 \begin_inset Text
32891
32892 \layout Standard
32893
32894
32895 \size footnotesize 
32896 '*'
32897 \end_inset 
32898 </cell>
32899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32900 \begin_inset Text
32901
32902 \layout Standard
32903
32904
32905 \size footnotesize 
32906 IC_LEFT() IC_RIGHT() IC_RESULT()
32907 \end_inset 
32908 </cell>
32909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32910 \begin_inset Text
32911
32912 \layout Standard
32913
32914
32915 \size footnotesize 
32916 Multiplication 
32917 \end_inset 
32918 </cell>
32919 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32920 \begin_inset Text
32921
32922 \layout Standard
32923
32924
32925 \size footnotesize 
32926 IC_RESULT = IC_LEFT * IC_RIGHT;
32927 \end_inset 
32928 </cell>
32929 </row>
32930 <row topline="true">
32931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32932 \begin_inset Text
32933
32934 \layout Standard
32935
32936
32937 \size footnotesize 
32938 '/'
32939 \end_inset 
32940 </cell>
32941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32942 \begin_inset Text
32943
32944 \layout Standard
32945
32946
32947 \size footnotesize 
32948 IC_LEFT() IC_RIGHT() IC_RESULT()
32949 \end_inset 
32950 </cell>
32951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32952 \begin_inset Text
32953
32954 \layout Standard
32955
32956
32957 \size footnotesize 
32958 Division
32959 \end_inset 
32960 </cell>
32961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32962 \begin_inset Text
32963
32964 \layout Standard
32965
32966
32967 \size footnotesize 
32968 IC_RESULT = IC_LEFT / IC_RIGHT;
32969 \end_inset 
32970 </cell>
32971 </row>
32972 <row topline="true">
32973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32974 \begin_inset Text
32975
32976 \layout Standard
32977
32978
32979 \size footnotesize 
32980 '%'
32981 \end_inset 
32982 </cell>
32983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32984 \begin_inset Text
32985
32986 \layout Standard
32987
32988
32989 \size footnotesize 
32990 IC_LEFT() IC_RIGHT() IC_RESULT()
32991 \end_inset 
32992 </cell>
32993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32994 \begin_inset Text
32995
32996 \layout Standard
32997
32998
32999 \size footnotesize 
33000 Modulus
33001 \end_inset 
33002 </cell>
33003 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33004 \begin_inset Text
33005
33006 \layout Standard
33007
33008
33009 \size footnotesize 
33010 IC_RESULT = IC_LEFT % IC_RIGHT;
33011 \end_inset 
33012 </cell>
33013 </row>
33014 <row topline="true">
33015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33016 \begin_inset Text
33017
33018 \layout Standard
33019
33020
33021 \size footnotesize 
33022 '<'
33023 \end_inset 
33024 </cell>
33025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33026 \begin_inset Text
33027
33028 \layout Standard
33029
33030
33031 \size footnotesize 
33032 IC_LEFT() IC_RIGHT() IC_RESULT()
33033 \end_inset 
33034 </cell>
33035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33036 \begin_inset Text
33037
33038 \layout Standard
33039
33040
33041 \size footnotesize 
33042 Less than
33043 \end_inset 
33044 </cell>
33045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33046 \begin_inset Text
33047
33048 \layout Standard
33049
33050
33051 \size footnotesize 
33052 IC_RESULT = IC_LEFT < IC_RIGHT;
33053 \end_inset 
33054 </cell>
33055 </row>
33056 <row topline="true">
33057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33058 \begin_inset Text
33059
33060 \layout Standard
33061
33062
33063 \size footnotesize 
33064 '>'
33065 \end_inset 
33066 </cell>
33067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33068 \begin_inset Text
33069
33070 \layout Standard
33071
33072
33073 \size footnotesize 
33074 IC_LEFT() IC_RIGHT() IC_RESULT()
33075 \end_inset 
33076 </cell>
33077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33078 \begin_inset Text
33079
33080 \layout Standard
33081
33082
33083 \size footnotesize 
33084 Greater than 
33085 \end_inset 
33086 </cell>
33087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33088 \begin_inset Text
33089
33090 \layout Standard
33091
33092
33093 \size footnotesize 
33094 IC_RESULT = IC_LEFT > IC_RIGHT;
33095 \end_inset 
33096 </cell>
33097 </row>
33098 <row topline="true">
33099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33100 \begin_inset Text
33101
33102 \layout Standard
33103
33104
33105 \size footnotesize 
33106 EQ_OP
33107 \end_inset 
33108 </cell>
33109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33110 \begin_inset Text
33111
33112 \layout Standard
33113
33114
33115 \size footnotesize 
33116 IC_LEFT() IC_RIGHT() IC_RESULT()
33117 \end_inset 
33118 </cell>
33119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33120 \begin_inset Text
33121
33122 \layout Standard
33123
33124
33125 \size footnotesize 
33126 Equal to 
33127 \end_inset 
33128 </cell>
33129 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33130 \begin_inset Text
33131
33132 \layout Standard
33133
33134
33135 \size footnotesize 
33136 IC_RESULT = IC_LEFT == IC_RIGHT;
33137 \end_inset 
33138 </cell>
33139 </row>
33140 <row topline="true">
33141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33142 \begin_inset Text
33143
33144 \layout Standard
33145
33146
33147 \size footnotesize 
33148 AND_OP
33149 \end_inset 
33150 </cell>
33151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33152 \begin_inset Text
33153
33154 \layout Standard
33155
33156
33157 \size footnotesize 
33158 IC_LEFT() IC_RIGHT() IC_RESULT() 
33159 \end_inset 
33160 </cell>
33161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33162 \begin_inset Text
33163
33164 \layout Standard
33165
33166
33167 \size footnotesize 
33168 Logical and operation
33169 \end_inset 
33170 </cell>
33171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33172 \begin_inset Text
33173
33174 \layout Standard
33175
33176
33177 \size footnotesize 
33178 IC_RESULT = IC_LEFT && IC_RIGHT; 
33179 \end_inset 
33180 </cell>
33181 </row>
33182 <row topline="true">
33183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33184 \begin_inset Text
33185
33186 \layout Standard
33187
33188
33189 \size footnotesize 
33190 OR_OP
33191 \end_inset 
33192 </cell>
33193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33194 \begin_inset Text
33195
33196 \layout Standard
33197
33198
33199 \size footnotesize 
33200 IC_LEFT() IC_RIGHT() IC_RESULT() 
33201 \end_inset 
33202 </cell>
33203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33204 \begin_inset Text
33205
33206 \layout Standard
33207
33208
33209 \size footnotesize 
33210 Logical or operation 
33211 \end_inset 
33212 </cell>
33213 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33214 \begin_inset Text
33215
33216 \layout Standard
33217
33218
33219 \size footnotesize 
33220 IC_RESULT = IC_LEFT || IC_RIGHT; 
33221 \end_inset 
33222 </cell>
33223 </row>
33224 <row topline="true">
33225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33226 \begin_inset Text
33227
33228 \layout Standard
33229
33230
33231 \size footnotesize 
33232 '^'
33233 \end_inset 
33234 </cell>
33235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33236 \begin_inset Text
33237
33238 \layout Standard
33239
33240
33241 \size footnotesize 
33242 IC_LEFT() IC_RIGHT() IC_RESULT() 
33243 \end_inset 
33244 </cell>
33245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33246 \begin_inset Text
33247
33248 \layout Standard
33249
33250
33251 \size footnotesize 
33252 Exclusive OR
33253 \end_inset 
33254 </cell>
33255 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33256 \begin_inset Text
33257
33258 \layout Standard
33259
33260
33261 \size footnotesize 
33262 IC_RESULT = IC_LEFT ^ IC_RIGHT;
33263 \end_inset 
33264 </cell>
33265 </row>
33266 <row topline="true">
33267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33268 \begin_inset Text
33269
33270 \layout Standard
33271
33272
33273 \size footnotesize 
33274 '|'
33275 \end_inset 
33276 </cell>
33277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33278 \begin_inset Text
33279
33280 \layout Standard
33281
33282
33283 \size footnotesize 
33284 IC_LEFT() IC_RIGHT() IC_RESULT() 
33285 \end_inset 
33286 </cell>
33287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33288 \begin_inset Text
33289
33290 \layout Standard
33291
33292
33293 \size footnotesize 
33294 Bitwise OR 
33295 \end_inset 
33296 </cell>
33297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33298 \begin_inset Text
33299
33300 \layout Standard
33301
33302
33303 \size footnotesize 
33304 IC_RESULT = IC_LEFT | IC_RIGHT;
33305 \end_inset 
33306 </cell>
33307 </row>
33308 <row topline="true">
33309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33310 \begin_inset Text
33311
33312 \layout Standard
33313
33314
33315 \size footnotesize 
33316 BITWISEAND
33317 \end_inset 
33318 </cell>
33319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33320 \begin_inset Text
33321
33322 \layout Standard
33323
33324
33325 \size footnotesize 
33326 IC_LEFT() IC_RIGHT() IC_RESULT()
33327 \end_inset 
33328 </cell>
33329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33330 \begin_inset Text
33331
33332 \layout Standard
33333
33334
33335 \size footnotesize 
33336 Bitwise AND 
33337 \end_inset 
33338 </cell>
33339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33340 \begin_inset Text
33341
33342 \layout Standard
33343
33344
33345 \size footnotesize 
33346 IC_RESULT = IC_LEFT & IC_RIGHT;
33347 \end_inset 
33348 </cell>
33349 </row>
33350 <row topline="true">
33351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33352 \begin_inset Text
33353
33354 \layout Standard
33355
33356
33357 \size footnotesize 
33358 LEFT_OP
33359 \end_inset 
33360 </cell>
33361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33362 \begin_inset Text
33363
33364 \layout Standard
33365
33366
33367 \size footnotesize 
33368 IC_LEFT() IC_RIGHT() IC_RESULT()
33369 \end_inset 
33370 </cell>
33371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33372 \begin_inset Text
33373
33374 \layout Standard
33375
33376
33377 \size footnotesize 
33378 Left shift 
33379 \end_inset 
33380 </cell>
33381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33382 \begin_inset Text
33383
33384 \layout Standard
33385
33386
33387 \size footnotesize 
33388 IC_RESULT = IC_LEFT << IC_RIGHT 
33389 \end_inset 
33390 </cell>
33391 </row>
33392 <row topline="true">
33393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33394 \begin_inset Text
33395
33396 \layout Standard
33397
33398
33399 \size footnotesize 
33400 RIGHT_OP
33401 \end_inset 
33402 </cell>
33403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33404 \begin_inset Text
33405
33406 \layout Standard
33407
33408
33409 \size footnotesize 
33410 IC_LEFT() IC_RIGHT() IC_RESULT()
33411 \end_inset 
33412 </cell>
33413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33414 \begin_inset Text
33415
33416 \layout Standard
33417
33418
33419 \size footnotesize 
33420 Right shift
33421 \end_inset 
33422 </cell>
33423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33424 \begin_inset Text
33425
33426 \layout Standard
33427
33428
33429 \size footnotesize 
33430 IC_RESULT = IC_LEFT >> IC_RIGHT 
33431 \end_inset 
33432 </cell>
33433 </row>
33434 <row topline="true">
33435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33436 \begin_inset Text
33437
33438 \layout Standard
33439
33440
33441 \size footnotesize 
33442 GET_VALUE_
33443 \newline 
33444 AT_ ADDRESS
33445 \end_inset 
33446 </cell>
33447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33448 \begin_inset Text
33449
33450 \layout Standard
33451
33452
33453 \size footnotesize 
33454 IC_LEFT() IC_RESULT()
33455 \end_inset 
33456 </cell>
33457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33458 \begin_inset Text
33459
33460 \layout Standard
33461
33462
33463 \size footnotesize 
33464 Indirect fetch 
33465 \end_inset 
33466 </cell>
33467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33468 \begin_inset Text
33469
33470 \layout Standard
33471
33472
33473 \size footnotesize 
33474 IC_RESULT = (*IC_LEFT);
33475 \end_inset 
33476 </cell>
33477 </row>
33478 <row topline="true">
33479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33480 \begin_inset Text
33481
33482 \layout Standard
33483
33484
33485 \size footnotesize 
33486 POINTER_SET
33487 \end_inset 
33488 </cell>
33489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33490 \begin_inset Text
33491
33492 \layout Standard
33493
33494
33495 \size footnotesize 
33496 IC_RIGHT() IC_RESULT() 
33497 \end_inset 
33498 </cell>
33499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33500 \begin_inset Text
33501
33502 \layout Standard
33503
33504
33505 \size footnotesize 
33506 Indirect set
33507 \end_inset 
33508 </cell>
33509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33510 \begin_inset Text
33511
33512 \layout Standard
33513
33514
33515 \size footnotesize 
33516 (*IC_RESULT) = IC_RIGHT;
33517 \end_inset 
33518 </cell>
33519 </row>
33520 <row topline="true">
33521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33522 \begin_inset Text
33523
33524 \layout Standard
33525
33526
33527 \size footnotesize 
33528 '='
33529 \end_inset 
33530 </cell>
33531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33532 \begin_inset Text
33533
33534 \layout Standard
33535
33536
33537 \size footnotesize 
33538 IC_RIGHT() IC_RESULT()
33539 \end_inset 
33540 </cell>
33541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33542 \begin_inset Text
33543
33544 \layout Standard
33545
33546
33547 \size footnotesize 
33548 Assignment
33549 \end_inset 
33550 </cell>
33551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33552 \begin_inset Text
33553
33554 \layout Standard
33555
33556
33557 \size footnotesize 
33558 IC_RESULT = IC_RIGHT;
33559 \end_inset 
33560 </cell>
33561 </row>
33562 <row topline="true">
33563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33564 \begin_inset Text
33565
33566 \layout Standard
33567
33568
33569 \size footnotesize 
33570 IFX
33571 \end_inset 
33572 </cell>
33573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33574 \begin_inset Text
33575
33576 \layout Standard
33577
33578
33579 \size footnotesize 
33580 IC_COND IC_TRUE IC_LABEL
33581 \end_inset 
33582 </cell>
33583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33584 \begin_inset Text
33585
33586 \layout Standard
33587
33588
33589 \size footnotesize 
33590 Conditional jump.
33591  If true label is present then jump to true label if condition is true else
33592  jump to false label if condition is false 
33593 \end_inset 
33594 </cell>
33595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33596 \begin_inset Text
33597
33598 \layout Standard
33599
33600
33601 \size footnotesize 
33602 if (IC_COND) goto IC_TRUE; 
33603 \newline 
33604 \SpecialChar ~
33605 \SpecialChar ~
33606 Or 
33607 \newline 
33608 If (!IC_COND) goto IC_FALSE;
33609 \end_inset 
33610 </cell>
33611 </row>
33612 <row topline="true">
33613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33614 \begin_inset Text
33615
33616 \layout Standard
33617
33618
33619 \size footnotesize 
33620 ADDRESS_OF
33621 \end_inset 
33622 </cell>
33623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33624 \begin_inset Text
33625
33626 \layout Standard
33627
33628
33629 \size footnotesize 
33630 IC_LEFT() IC_RESULT()
33631 \end_inset 
33632 </cell>
33633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33634 \begin_inset Text
33635
33636 \layout Standard
33637
33638
33639 \size footnotesize 
33640 Address of 
33641 \end_inset 
33642 </cell>
33643 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33644 \begin_inset Text
33645
33646 \layout Standard
33647
33648
33649 \size footnotesize 
33650 IC_RESULT = &IC_LEFT();
33651 \end_inset 
33652 </cell>
33653 </row>
33654 <row topline="true">
33655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33656 \begin_inset Text
33657
33658 \layout Standard
33659
33660
33661 \size footnotesize 
33662 JUMPTABLE
33663 \end_inset 
33664 </cell>
33665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33666 \begin_inset Text
33667
33668 \layout Standard
33669
33670
33671 \size footnotesize 
33672 IC_JTCOND IC_JTLABELS
33673 \end_inset 
33674 </cell>
33675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33676 \begin_inset Text
33677
33678 \layout Standard
33679
33680
33681 \size footnotesize 
33682 Jump to list of labels depending on the value of JTCOND
33683 \end_inset 
33684 </cell>
33685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33686 \begin_inset Text
33687
33688 \layout Standard
33689
33690
33691 \size footnotesize 
33692 Switch statement
33693 \end_inset 
33694 </cell>
33695 </row>
33696 <row topline="true">
33697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33698 \begin_inset Text
33699
33700 \layout Standard
33701
33702
33703 \size footnotesize 
33704 CAST
33705 \end_inset 
33706 </cell>
33707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33708 \begin_inset Text
33709
33710 \layout Standard
33711
33712
33713 \size footnotesize 
33714 IC_RIGHT() IC_LEFT() IC_RESULT()
33715 \end_inset 
33716 </cell>
33717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33718 \begin_inset Text
33719
33720 \layout Standard
33721
33722
33723 \size footnotesize 
33724 Cast types 
33725 \end_inset 
33726 </cell>
33727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33728 \begin_inset Text
33729
33730 \layout Standard
33731
33732
33733 \size footnotesize 
33734 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
33735 \end_inset 
33736 </cell>
33737 </row>
33738 <row topline="true">
33739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33740 \begin_inset Text
33741
33742 \layout Standard
33743
33744
33745 \size footnotesize 
33746 SEND
33747 \end_inset 
33748 </cell>
33749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33750 \begin_inset Text
33751
33752 \layout Standard
33753
33754
33755 \size footnotesize 
33756 IC_LEFT()
33757 \end_inset 
33758 </cell>
33759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33760 \begin_inset Text
33761
33762 \layout Standard
33763
33764
33765 \size footnotesize 
33766 This is used for passing parameters in registers; 
33767 \newline 
33768 move IC_LEFT to the next available parameter register.
33769 \end_inset 
33770 </cell>
33771 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33772 \begin_inset Text
33773
33774 \layout Standard
33775
33776
33777 \size footnotesize 
33778 None
33779 \end_inset 
33780 </cell>
33781 </row>
33782 <row topline="true">
33783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33784 \begin_inset Text
33785
33786 \layout Standard
33787
33788
33789 \size footnotesize 
33790 RECV
33791 \end_inset 
33792 </cell>
33793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33794 \begin_inset Text
33795
33796 \layout Standard
33797
33798
33799 \size footnotesize 
33800 IC_RESULT()
33801 \end_inset 
33802 </cell>
33803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33804 \begin_inset Text
33805
33806 \layout Standard
33807
33808
33809 \size footnotesize 
33810 This is used for receiving parameters passed in registers;
33811 \newline 
33812 Move the values in the next parameter register to IC_RESULT 
33813 \end_inset 
33814 </cell>
33815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33816 \begin_inset Text
33817
33818 \layout Standard
33819
33820
33821 \size footnotesize 
33822 None
33823 \end_inset 
33824 </cell>
33825 </row>
33826 <row topline="true" bottomline="true">
33827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33828 \begin_inset Text
33829
33830 \layout Standard
33831
33832
33833 \shape slanted 
33834 \size footnotesize 
33835 (some more have been added)
33836 \end_inset 
33837 </cell>
33838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33839 \begin_inset Text
33840
33841 \layout Standard
33842
33843 \end_inset 
33844 </cell>
33845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33846 \begin_inset Text
33847
33848 \layout Standard
33849
33850 \end_inset 
33851 </cell>
33852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33853 \begin_inset Text
33854
33855 \layout Standard
33856
33857
33858 \shape slanted 
33859 \size footnotesize 
33860 see f.e.
33861  
33862 \family typewriter 
33863 gen51Code()
33864 \family default 
33865  in 
33866 \family typewriter 
33867 src/mcs51/gen.c
33868 \end_inset 
33869 </cell>
33870 </row>
33871 </lyxtabular>
33872
33873 \end_inset 
33874
33875
33876 \layout Standard
33877
33878
33879 \begin_inset Note
33880 collapsed true
33881
33882 \layout Standard
33883
33884 In the original article Figure II was announced to be downloadable on 
33885 \shape italic 
33886 Circuit Cellar
33887 \shape default 
33888 's web site.
33889  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
33890 \end_inset 
33891
33892
33893 \layout Paragraph*
33894
33895 ICode Example
33896 \begin_inset LatexCommand \index{iCode}
33897
33898 \end_inset 
33899
33900
33901 \layout Standard
33902
33903 This section shows some details of iCode.
33904  The example C code does not do anything useful; it is used as an example
33905  to illustrate the intermediate code generated by the compiler.
33906 \layout Verse
33907
33908
33909 \family typewriter 
33910 1.\SpecialChar ~
33911 xdata int * p;
33912 \newline 
33913 2.\SpecialChar ~
33914 int gint;
33915 \newline 
33916 3.\SpecialChar ~
33917 /* This function does nothing useful.
33918  It is used
33919 \newline 
33920 4.\SpecialChar ~
33921 \SpecialChar ~
33922 \SpecialChar ~
33923 \SpecialChar ~
33924 for the purpose of explaining iCode */
33925 \newline 
33926 5.\SpecialChar ~
33927 short function (data int *x)
33928 \newline 
33929 6.\SpecialChar ~
33930 {
33931 \newline 
33932 7.\SpecialChar ~
33933 \SpecialChar ~
33934 \SpecialChar ~
33935 short i=10; \SpecialChar ~
33936 \SpecialChar ~
33937 /* dead initialization eliminated */
33938 \newline 
33939 8.\SpecialChar ~
33940 \SpecialChar ~
33941 \SpecialChar ~
33942 short sum=10; /* dead initialization eliminated */
33943 \newline 
33944 9.\SpecialChar ~
33945 \SpecialChar ~
33946 \SpecialChar ~
33947 short mul;
33948 \newline 
33949 10.\SpecialChar ~
33950 \SpecialChar ~
33951 int j ;
33952 \newline 
33953 11.\SpecialChar ~
33954 \SpecialChar ~
33955 while (*x) *x++ = *p++; 
33956 \newline 
33957 12.\SpecialChar ~
33958 \SpecialChar ~
33959 \SpecialChar ~
33960 \SpecialChar ~
33961 sum = 0 ; 
33962 \newline 
33963 13.\SpecialChar ~
33964 \SpecialChar ~
33965 mul = 0;
33966 \newline 
33967 14.\SpecialChar ~
33968 \SpecialChar ~
33969 /* compiler detects i,j to be induction variables */
33970 \newline 
33971 15.\SpecialChar ~
33972 \SpecialChar ~
33973 for (i = 0, j = 10 ; i < 10 ; i++, j
33974 \family default 
33975 -
33976 \begin_inset ERT
33977 status Collapsed
33978
33979 \layout Standard
33980
33981 \backslash 
33982 /
33983 \end_inset 
33984
33985 -
33986 \family typewriter 
33987 ) {
33988 \newline 
33989 16.\SpecialChar ~
33990 \SpecialChar ~
33991 \SpecialChar ~
33992 \SpecialChar ~
33993 sum += i;
33994 \newline 
33995 17.\SpecialChar ~
33996 \SpecialChar ~
33997 \SpecialChar ~
33998 \SpecialChar ~
33999 mul += i * 3; \SpecialChar ~
34000 \SpecialChar ~
34001 /* this multiplication remains */
34002 \newline 
34003 18.\SpecialChar ~
34004 \SpecialChar ~
34005 \SpecialChar ~
34006 \SpecialChar ~
34007 gint += j * 3;\SpecialChar ~
34008 \SpecialChar ~
34009 /* this multiplication changed to addition */
34010 \newline 
34011 19.\SpecialChar ~
34012 \SpecialChar ~
34013 }
34014 \newline 
34015 20.\SpecialChar ~
34016 \SpecialChar ~
34017 return sum+mul;
34018 \newline 
34019 21.\SpecialChar ~
34020 }
34021 \layout Standard
34022
34023 In addition to the operands each iCode contains information about the filename
34024  and line it corresponds to in the source file.
34025  The first field in the listing should be interpreted as follows:
34026 \newline 
34027
34028 \shape italic 
34029 \size footnotesize 
34030 Filename(linenumber: iCode Execution sequence number : ICode hash table
34031  key : loop depth of the iCode).
34032 \shape default 
34033 \size default 
34034
34035 \newline 
34036 Then follows the human readable form of the ICode operation.
34037  Each operand of this triplet form can be of three basic types a) compiler
34038  generated temporary b) user defined variable c) a constant value.
34039  Note that local variables and parameters are replaced by compiler generated
34040  temporaries.
34041  Live ranges
34042 \begin_inset LatexCommand \index{Live range analysis}
34043
34044 \end_inset 
34045
34046  are computed only for temporaries (i.e.
34047  live ranges are not computed for global variables).
34048  Registers
34049 \begin_inset LatexCommand \index{Register allocation}
34050
34051 \end_inset 
34052
34053  are allocated for temporaries only.
34054  Operands are formatted in the following manner:
34055 \newline 
34056
34057 \shape italic 
34058 \size footnotesize 
34059 Operand Name [lr live-from : live-to ] { type information } [ registers
34060  allocated ].
34061 \shape default 
34062 \size default 
34063
34064 \newline 
34065 As mentioned earlier the live ranges are computed in terms of the execution
34066  sequence number of the iCodes, for example 
34067 \newline 
34068 the iTemp0 is live from (i.e.
34069  first defined in iCode with execution sequence number 3, and is last used
34070  in the iCode with sequence number 5).
34071  For induction variables such as iTemp21 the live range computation extends
34072  the lifetime from the start to the end of the loop.
34073 \newline 
34074 The register allocator used the live range information to allocate registers,
34075  the same registers may be used for different temporaries if their live
34076  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
34077  iTemp17 since their live ranges do not overlap.
34078  In addition the allocator also takes into consideration the type and usage
34079  of a temporary, for example itemp6 is a pointer to near space and is used
34080  as to fetch data from (i.e.
34081  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
34082  Some short lived temporaries are allocated to special registers which have
34083  meaning to the code generator e.g.
34084  iTemp13 is allocated to a pseudo register CC which tells the back end that
34085  the temporary is used only for a conditional jump the code generation makes
34086  use of this information to optimize a compare and jump ICode.
34087 \newline 
34088 There are several loop optimizations
34089 \begin_inset LatexCommand \index{Loop optimization}
34090
34091 \end_inset 
34092
34093  performed by the compiler.
34094  It can detect induction variables iTemp21(i) and iTemp23(j).
34095  Also note the compiler does selective strength reduction
34096 \begin_inset LatexCommand \index{Strength reduction}
34097
34098 \end_inset 
34099
34100 , i.e.
34101  the multiplication of an induction variable in line 18 (gint = j * 3) is
34102  changed to addition, a new temporary iTemp17 is allocated and assigned
34103  a initial value, a constant 3 is then added for each iteration of the loop.
34104  The compiler does not change the multiplication
34105 \begin_inset LatexCommand \index{Multiplication}
34106
34107 \end_inset 
34108
34109  in line 17 however since the processor does support an 8 * 8 bit multiplication.
34110 \newline 
34111 Note the dead code elimination
34112 \begin_inset LatexCommand \index{Dead-code elimination}
34113
34114 \end_inset 
34115
34116  optimization eliminated the dead assignments in line 7 & 8 to I and sum
34117  respectively.
34118 \newline 
34119
34120 \layout Standard
34121
34122
34123 \size footnotesize 
34124 Sample.c (5:1:0:0) _entry($9) :
34125 \layout Standard
34126
34127
34128 \size footnotesize 
34129 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
34130 \layout Standard
34131
34132
34133 \size footnotesize 
34134 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
34135 \layout Standard
34136
34137
34138 \size footnotesize 
34139 Sample.c(11:4:53:0) preHeaderLbl0($11) :
34140 \layout Standard
34141
34142
34143 \size footnotesize 
34144 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
34145  * int}[r2]
34146 \layout Standard
34147
34148
34149 \size footnotesize 
34150 Sample.c(11:6:5:1) _whilecontinue_0($1) :
34151 \layout Standard
34152
34153
34154 \size footnotesize 
34155 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
34156  int}[r0]]
34157 \layout Standard
34158
34159
34160 \size footnotesize 
34161 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
34162 \layout Standard
34163
34164
34165 \size footnotesize 
34166 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
34167  * int}
34168 \layout Standard
34169
34170
34171 \size footnotesize 
34172 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
34173  {short}
34174 \layout Standard
34175
34176
34177 \size footnotesize 
34178 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
34179  * int}[DPTR]]
34180 \layout Standard
34181
34182
34183 \size footnotesize 
34184 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
34185 }[r2 r3]
34186 \layout Standard
34187
34188
34189 \size footnotesize 
34190 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
34191  * int}[r0] + 0x2 {short}
34192 \layout Standard
34193
34194
34195 \size footnotesize 
34196 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
34197 \layout Standard
34198
34199
34200 \size footnotesize 
34201 Sample.c(11:17:21:0)_whilebreak_0($3) :
34202 \layout Standard
34203
34204
34205 \size footnotesize 
34206 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
34207 \layout Standard
34208
34209
34210 \size footnotesize 
34211 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
34212 \layout Standard
34213
34214
34215 \size footnotesize 
34216 Sample.c(15:20:54:0)preHeaderLbl1($13) :
34217 \layout Standard
34218
34219
34220 \size footnotesize 
34221 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
34222 \layout Standard
34223
34224
34225 \size footnotesize 
34226 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
34227 \layout Standard
34228
34229
34230 \size footnotesize 
34231 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
34232 \layout Standard
34233
34234
34235 \size footnotesize 
34236 Sample.c(15:24:26:1)_forcond_0($4) :
34237 \layout Standard
34238
34239
34240 \size footnotesize 
34241 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
34242  < 0xa {short}
34243 \layout Standard
34244
34245
34246 \size footnotesize 
34247 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
34248 \layout Standard
34249
34250
34251 \size footnotesize 
34252 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
34253  + ITemp21 [lr21:38]{short}[r4]
34254 \layout Standard
34255
34256
34257 \size footnotesize 
34258 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
34259  * 0x3 {short}
34260 \layout Standard
34261
34262
34263 \size footnotesize 
34264 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
34265  + iTemp15 [lr29:30]{short}[r1]
34266 \layout Standard
34267
34268
34269 \size footnotesize 
34270 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
34271  r0]- 0x3 {short}
34272 \layout Standard
34273
34274
34275 \size footnotesize 
34276 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
34277 int}[r7 r0]
34278 \layout Standard
34279
34280
34281 \size footnotesize 
34282 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
34283  + 0x1 {short}
34284 \layout Standard
34285
34286
34287 \size footnotesize 
34288 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
34289  r6]- 0x1 {short}
34290 \layout Standard
34291
34292
34293 \size footnotesize 
34294 Sample.c(19:38:47:1) goto _forcond_0($4)
34295 \layout Standard
34296
34297
34298 \size footnotesize 
34299 Sample.c(19:39:48:0)_forbreak_0($7) :
34300 \layout Standard
34301
34302
34303 \size footnotesize 
34304 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
34305  + ITemp11 [lr19:40]{short}[r3]
34306 \layout Standard
34307
34308
34309 \size footnotesize 
34310 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
34311 \layout Standard
34312
34313
34314 \size footnotesize 
34315 Sample.c(20:42:51:0)_return($8) :
34316 \layout Standard
34317
34318
34319 \size footnotesize 
34320 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
34321 \size default 
34322
34323 \newline 
34324
34325 \newline 
34326 Finally the code generated for this function:
34327 \newline 
34328
34329 \layout Standard
34330
34331
34332 \size footnotesize 
34333 .area DSEG (DATA)
34334 \layout Standard
34335
34336
34337 \size footnotesize 
34338 _p::
34339 \layout Standard
34340
34341
34342 \size footnotesize 
34343 \SpecialChar ~
34344 \SpecialChar ~
34345 .ds 2
34346 \layout Standard
34347
34348
34349 \size footnotesize 
34350 _gint::
34351 \layout Standard
34352
34353
34354 \size footnotesize 
34355 \SpecialChar ~
34356 \SpecialChar ~
34357 .ds 2
34358 \layout Standard
34359
34360
34361 \size footnotesize 
34362 ; sample.c 5
34363 \layout Standard
34364
34365
34366 \size footnotesize 
34367 ; ----------------------------------------------
34368 \layout Standard
34369
34370
34371 \size footnotesize 
34372 ; function function
34373 \layout Standard
34374
34375
34376 \size footnotesize 
34377 ; ----------------------------------------------
34378 \layout Standard
34379
34380
34381 \size footnotesize 
34382 _function:
34383 \layout Standard
34384
34385
34386 \size footnotesize 
34387 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
34388 \layout Standard
34389
34390
34391 \size footnotesize 
34392 \SpecialChar ~
34393 \SpecialChar ~
34394 mov r2,dpl
34395 \layout Standard
34396
34397
34398 \size footnotesize 
34399 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
34400 \layout Standard
34401
34402
34403 \size footnotesize 
34404 \SpecialChar ~
34405 \SpecialChar ~
34406 mov ar0,r2
34407 \layout Standard
34408
34409
34410 \size footnotesize 
34411 ;_whilecontinue_0($1) :
34412 \layout Standard
34413
34414
34415 \size footnotesize 
34416 00101$:
34417 \layout Standard
34418
34419
34420 \size footnotesize 
34421 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
34422 \layout Standard
34423
34424
34425 \size footnotesize 
34426 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
34427 \layout Standard
34428
34429
34430 \size footnotesize 
34431 \SpecialChar ~
34432 \SpecialChar ~
34433 mov ar2,@r0
34434 \layout Standard
34435
34436
34437 \size footnotesize 
34438 \SpecialChar ~
34439 \SpecialChar ~
34440 inc r0
34441 \layout Standard
34442
34443
34444 \size footnotesize 
34445 \SpecialChar ~
34446 \SpecialChar ~
34447 mov ar3,@r0
34448 \layout Standard
34449
34450
34451 \size footnotesize 
34452 \SpecialChar ~
34453 \SpecialChar ~
34454 dec r0
34455 \layout Standard
34456
34457
34458 \size footnotesize 
34459 \SpecialChar ~
34460 \SpecialChar ~
34461 mov a,r2
34462 \layout Standard
34463
34464
34465 \size footnotesize 
34466 \SpecialChar ~
34467 \SpecialChar ~
34468 orl a,r3
34469 \layout Standard
34470
34471
34472 \size footnotesize 
34473 \SpecialChar ~
34474 \SpecialChar ~
34475 jz 00103$
34476 \layout Standard
34477
34478
34479 \size footnotesize 
34480 00114$:
34481 \layout Standard
34482
34483
34484 \size footnotesize 
34485 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
34486 \layout Standard
34487
34488
34489 \size footnotesize 
34490 \SpecialChar ~
34491 \SpecialChar ~
34492 mov dpl,_p
34493 \layout Standard
34494
34495
34496 \size footnotesize 
34497 \SpecialChar ~
34498 \SpecialChar ~
34499 mov dph,(_p + 1)
34500 \layout Standard
34501
34502
34503 \size footnotesize 
34504 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
34505 \layout Standard
34506
34507
34508 \size footnotesize 
34509 \SpecialChar ~
34510 \SpecialChar ~
34511 mov a,#0x02
34512 \layout Standard
34513
34514
34515 \size footnotesize 
34516 \SpecialChar ~
34517 \SpecialChar ~
34518 add a,_p
34519 \layout Standard
34520
34521
34522 \size footnotesize 
34523 \SpecialChar ~
34524 \SpecialChar ~
34525 mov _p,a
34526 \layout Standard
34527
34528
34529 \size footnotesize 
34530 \SpecialChar ~
34531 \SpecialChar ~
34532 clr a
34533 \layout Standard
34534
34535
34536 \size footnotesize 
34537 \SpecialChar ~
34538 \SpecialChar ~
34539 addc a,(_p + 1)
34540 \layout Standard
34541
34542
34543 \size footnotesize 
34544 \SpecialChar ~
34545 \SpecialChar ~
34546 mov (_p + 1),a
34547 \layout Standard
34548
34549
34550 \size footnotesize 
34551 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
34552 \layout Standard
34553
34554
34555 \size footnotesize 
34556 \SpecialChar ~
34557 \SpecialChar ~
34558 movx a,@dptr
34559 \layout Standard
34560
34561
34562 \size footnotesize 
34563 \SpecialChar ~
34564 \SpecialChar ~
34565 mov r2,a
34566 \layout Standard
34567
34568
34569 \size footnotesize 
34570 \SpecialChar ~
34571 \SpecialChar ~
34572 inc dptr
34573 \layout Standard
34574
34575
34576 \size footnotesize 
34577 \SpecialChar ~
34578 \SpecialChar ~
34579 movx a,@dptr
34580 \layout Standard
34581
34582
34583 \size footnotesize 
34584 \SpecialChar ~
34585 \SpecialChar ~
34586 mov r3,a
34587 \layout Standard
34588
34589
34590 \size footnotesize 
34591 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
34592 \layout Standard
34593
34594
34595 \size footnotesize 
34596 \SpecialChar ~
34597 \SpecialChar ~
34598 mov @r0,ar2
34599 \layout Standard
34600
34601
34602 \size footnotesize 
34603 \SpecialChar ~
34604 \SpecialChar ~
34605 inc r0
34606 \layout Standard
34607
34608
34609 \size footnotesize 
34610 \SpecialChar ~
34611 \SpecialChar ~
34612 mov @r0,ar3
34613 \layout Standard
34614
34615
34616 \size footnotesize 
34617 ; iTemp6 [lr5:16]{_near * int}[r0] = 
34618 \layout Standard
34619
34620
34621 \size footnotesize 
34622 ; iTemp6 [lr5:16]{_near * int}[r0] + 
34623 \layout Standard
34624
34625
34626 \size footnotesize 
34627 ; 0x2 {short}
34628 \layout Standard
34629
34630
34631 \size footnotesize 
34632 \SpecialChar ~
34633 \SpecialChar ~
34634 inc r0
34635 \layout Standard
34636
34637
34638 \size footnotesize 
34639 ; goto _whilecontinue_0($1)
34640 \layout Standard
34641
34642
34643 \size footnotesize 
34644 \SpecialChar ~
34645 \SpecialChar ~
34646 sjmp 00101$
34647 \layout Standard
34648
34649
34650 \size footnotesize 
34651 ; _whilebreak_0($3) :
34652 \layout Standard
34653
34654
34655 \size footnotesize 
34656 00103$:
34657 \layout Standard
34658
34659
34660 \size footnotesize 
34661 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
34662 \layout Standard
34663
34664
34665 \size footnotesize 
34666 \SpecialChar ~
34667 \SpecialChar ~
34668 mov r2,#0x00
34669 \layout Standard
34670
34671
34672 \size footnotesize 
34673 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
34674 \layout Standard
34675
34676
34677 \size footnotesize 
34678 \SpecialChar ~
34679 \SpecialChar ~
34680 mov r3,#0x00
34681 \layout Standard
34682
34683
34684 \size footnotesize 
34685 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
34686 \layout Standard
34687
34688
34689 \size footnotesize 
34690 \SpecialChar ~
34691 \SpecialChar ~
34692 mov r4,#0x00
34693 \layout Standard
34694
34695
34696 \size footnotesize 
34697 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
34698 \layout Standard
34699
34700
34701 \size footnotesize 
34702 \SpecialChar ~
34703 \SpecialChar ~
34704 mov r5,#0x0A
34705 \layout Standard
34706
34707
34708 \size footnotesize 
34709 \SpecialChar ~
34710 \SpecialChar ~
34711 mov r6,#0x00
34712 \layout Standard
34713
34714
34715 \size footnotesize 
34716 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
34717 \layout Standard
34718
34719
34720 \size footnotesize 
34721 \SpecialChar ~
34722 \SpecialChar ~
34723 mov r7,#0x1E
34724 \layout Standard
34725
34726
34727 \size footnotesize 
34728 \SpecialChar ~
34729 \SpecialChar ~
34730 mov r0,#0x00
34731 \layout Standard
34732
34733
34734 \size footnotesize 
34735 ; _forcond_0($4) :
34736 \layout Standard
34737
34738
34739 \size footnotesize 
34740 00104$:
34741 \layout Standard
34742
34743
34744 \size footnotesize 
34745 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
34746 \layout Standard
34747
34748
34749 \size footnotesize 
34750 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
34751 \layout Standard
34752
34753
34754 \size footnotesize 
34755 \SpecialChar ~
34756 \SpecialChar ~
34757 clr c
34758 \layout Standard
34759
34760
34761 \size footnotesize 
34762 \SpecialChar ~
34763 \SpecialChar ~
34764 mov a,r4
34765 \layout Standard
34766
34767
34768 \size footnotesize 
34769 \SpecialChar ~
34770 \SpecialChar ~
34771 xrl a,#0x80
34772 \layout Standard
34773
34774
34775 \size footnotesize 
34776 \SpecialChar ~
34777 \SpecialChar ~
34778 subb a,#0x8a
34779 \layout Standard
34780
34781
34782 \size footnotesize 
34783 \SpecialChar ~
34784 \SpecialChar ~
34785 jnc 00107$
34786 \layout Standard
34787
34788
34789 \size footnotesize 
34790 00115$:
34791 \layout Standard
34792
34793
34794 \size footnotesize 
34795 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
34796 \layout Standard
34797
34798
34799 \size footnotesize 
34800 ; iTemp21 [lr21:38]{short}[r4]
34801 \layout Standard
34802
34803
34804 \size footnotesize 
34805 \SpecialChar ~
34806 \SpecialChar ~
34807 mov a,r4
34808 \layout Standard
34809
34810
34811 \size footnotesize 
34812 \SpecialChar ~
34813 \SpecialChar ~
34814 add a,r2
34815 \layout Standard
34816
34817
34818 \size footnotesize 
34819 \SpecialChar ~
34820 \SpecialChar ~
34821 mov r2,a
34822 \layout Standard
34823
34824
34825 \size footnotesize 
34826 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
34827 \layout Standard
34828
34829
34830 \size footnotesize 
34831 \SpecialChar ~
34832 \SpecialChar ~
34833 mov b,#0x03
34834 \layout Standard
34835
34836
34837 \size footnotesize 
34838 \SpecialChar ~
34839 \SpecialChar ~
34840 mov a,r4
34841 \layout Standard
34842
34843
34844 \size footnotesize 
34845 \SpecialChar ~
34846 \SpecialChar ~
34847 mul ab
34848 \layout Standard
34849
34850
34851 \size footnotesize 
34852 \SpecialChar ~
34853 \SpecialChar ~
34854 mov r1,a
34855 \layout Standard
34856
34857
34858 \size footnotesize 
34859 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
34860 \layout Standard
34861
34862
34863 \size footnotesize 
34864 ; iTemp15 [lr29:30]{short}[r1]
34865 \layout Standard
34866
34867
34868 \size footnotesize 
34869 \SpecialChar ~
34870 \SpecialChar ~
34871 add a,r3
34872 \layout Standard
34873
34874
34875 \size footnotesize 
34876 \SpecialChar ~
34877 \SpecialChar ~
34878 mov r3,a
34879 \layout Standard
34880
34881
34882 \size footnotesize 
34883 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
34884 \layout Standard
34885
34886
34887 \size footnotesize 
34888 \SpecialChar ~
34889 \SpecialChar ~
34890 mov a,r7
34891 \layout Standard
34892
34893
34894 \size footnotesize 
34895 \SpecialChar ~
34896 \SpecialChar ~
34897 add a,#0xfd
34898 \layout Standard
34899
34900
34901 \size footnotesize 
34902 \SpecialChar ~
34903 \SpecialChar ~
34904 mov r7,a
34905 \layout Standard
34906
34907
34908 \size footnotesize 
34909 \SpecialChar ~
34910 \SpecialChar ~
34911 mov a,r0
34912 \layout Standard
34913
34914
34915 \size footnotesize 
34916 \SpecialChar ~
34917 \SpecialChar ~
34918 addc a,#0xff
34919 \layout Standard
34920
34921
34922 \size footnotesize 
34923 \SpecialChar ~
34924 \SpecialChar ~
34925 mov r0,a
34926 \layout Standard
34927
34928
34929 \size footnotesize 
34930 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
34931 \layout Standard
34932
34933
34934 \size footnotesize 
34935 \SpecialChar ~
34936 \SpecialChar ~
34937 mov a,r7
34938 \layout Standard
34939
34940
34941 \size footnotesize 
34942 \SpecialChar ~
34943 \SpecialChar ~
34944 add a,_gint
34945 \layout Standard
34946
34947
34948 \size footnotesize 
34949 \SpecialChar ~
34950 \SpecialChar ~
34951 mov _gint,a
34952 \layout Standard
34953
34954
34955 \size footnotesize 
34956 \SpecialChar ~
34957 \SpecialChar ~
34958 mov a,r0
34959 \layout Standard
34960
34961
34962 \size footnotesize 
34963 \SpecialChar ~
34964 \SpecialChar ~
34965 addc a,(_gint + 1)
34966 \layout Standard
34967
34968
34969 \size footnotesize 
34970 \SpecialChar ~
34971 \SpecialChar ~
34972 mov (_gint + 1),a
34973 \layout Standard
34974
34975
34976 \size footnotesize 
34977 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
34978 \layout Standard
34979
34980
34981 \size footnotesize 
34982 \SpecialChar ~
34983 \SpecialChar ~
34984 inc r4
34985 \layout Standard
34986
34987
34988 \size footnotesize 
34989 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
34990 \layout Standard
34991
34992
34993 \size footnotesize 
34994 \SpecialChar ~
34995 \SpecialChar ~
34996 dec r5
34997 \layout Standard
34998
34999
35000 \size footnotesize 
35001 \SpecialChar ~
35002 \SpecialChar ~
35003 cjne r5,#0xff,00104$
35004 \layout Standard
35005
35006
35007 \size footnotesize 
35008 \SpecialChar ~
35009 \SpecialChar ~
35010 dec r6
35011 \layout Standard
35012
35013
35014 \size footnotesize 
35015 ; goto _forcond_0($4)
35016 \layout Standard
35017
35018
35019 \size footnotesize 
35020 \SpecialChar ~
35021 \SpecialChar ~
35022 sjmp 00104$
35023 \layout Standard
35024
35025
35026 \size footnotesize 
35027 ; _forbreak_0($7) :
35028 \layout Standard
35029
35030
35031 \size footnotesize 
35032 00107$:
35033 \layout Standard
35034
35035
35036 \size footnotesize 
35037 ; ret iTemp24 [lr40:41]{short}
35038 \layout Standard
35039
35040
35041 \size footnotesize 
35042 \SpecialChar ~
35043 \SpecialChar ~
35044 mov a,r3
35045 \layout Standard
35046
35047
35048 \size footnotesize 
35049 \SpecialChar ~
35050 \SpecialChar ~
35051 add a,r2
35052 \layout Standard
35053
35054
35055 \size footnotesize 
35056 \SpecialChar ~
35057 \SpecialChar ~
35058 mov dpl,a
35059 \layout Standard
35060
35061
35062 \size footnotesize 
35063 ; _return($8) :
35064 \layout Standard
35065
35066
35067 \size footnotesize 
35068 00108$:
35069 \layout Standard
35070
35071
35072 \size footnotesize 
35073 \SpecialChar ~
35074 \SpecialChar ~
35075 ret
35076 \newline 
35077
35078 \layout Section
35079
35080 A few words about basic block successors, predecessors and dominators
35081 \layout Standard
35082
35083 Successors are basic blocks
35084 \begin_inset LatexCommand \index{Basic blocks}
35085
35086 \end_inset 
35087
35088  that might execute after this basic block.
35089 \newline 
35090 Predecessors are basic blocks that might execute before reaching this basic
35091  block.
35092 \newline 
35093 Dominators are basic blocks that WILL execute before reaching this basic
35094  block.
35095 \newline 
35096
35097 \layout Standard
35098
35099 [basic block 1]
35100 \layout Standard
35101
35102 if (something)
35103 \layout Standard
35104
35105 \SpecialChar ~
35106 \SpecialChar ~
35107 \SpecialChar ~
35108 \SpecialChar ~
35109 [basic block 2]
35110 \layout Standard
35111
35112 else
35113 \layout Standard
35114
35115 \SpecialChar ~
35116 \SpecialChar ~
35117 \SpecialChar ~
35118 \SpecialChar ~
35119 [basic block 3]
35120 \layout Standard
35121
35122 [basic block 4]
35123 \newline 
35124
35125 \layout Standard
35126
35127 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
35128 \layout Standard
35129
35130 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
35131 \layout Standard
35132
35133 c) domVect of [BB4] = BB1 ...
35134  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
35135  was executed.
35136 \layout Chapter
35137
35138 Acknowledgments
35139 \layout Standard
35140
35141
35142 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
35143
35144 \end_inset 
35145
35146
35147 \newline 
35148
35149 \newline 
35150
35151 \emph on 
35152 Thanks to all the other volunteer developers who have helped with coding,
35153  testing, web-page creation, distribution sets, etc.
35154  You know who you are :-)
35155 \emph default 
35156
35157 \newline 
35158
35159 \newline 
35160
35161 \emph on 
35162 Also thanks to Sourceforge 
35163 \begin_inset LatexCommand \url{http://www.sf.net}
35164
35165 \end_inset 
35166
35167  which has hosted the project since 1999 and donates significant download
35168  bandwidth and probably more than 
35169 \begin_inset ERT
35170 status Collapsed
35171
35172 \layout Standard
35173 $10^{13}$
35174 \end_inset 
35175
35176 CPU cycles per day.
35177 \newline 
35178  
35179 \begin_inset Note
35180 collapsed false
35181
35182 \layout Standard
35183
35184 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
35185  minutes for (configure+make+regression test), and there is (i386, amd64,
35186  alpha, ppc64, (mingw32), sparc, macosx).
35187  
35188 \end_inset 
35189
35190
35191 \layout Standard
35192
35193 This document was initially written by Sandeep Dutta
35194 \layout Standard
35195
35196 All product names mentioned herein may be trademarks
35197 \begin_inset LatexCommand \index{Trademarks}
35198
35199 \end_inset 
35200
35201  of their respective companies.
35202  
35203 \layout Section*
35204
35205 Alphabetical index
35206 \layout Standard
35207
35208 To avoid confusion, the installation and building options for SDCC itself
35209  (chapter 2) are not part of the index.
35210 \layout Standard
35211
35212
35213 \begin_inset LatexCommand \printindex{}
35214
35215 \end_inset 
35216
35217
35218 \the_end