* doc/sdccman.lyx, doc/random-notes.txt, doc/avr/avr_design.txt,
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.5.7 created this file. For more info see http://www.lyx.org/
2 \lyxformat 276
3 \begin_document
4 \begin_header
5 \textclass book
6 \begin_preamble
7 \pdfoptionpdfminorversion=3
8 \usepackage[
9   pdftitle={SDCC Compiler User Guide},
10   pdfauthor={SDCC development team},
11   pdfsubject={installation, user manual},
12   pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
13   pdfpagemode=UseOutlines,
14   colorlinks=true,
15   linkcolor=blue] {hyperref}
16 %
17 \sloppy
18 \tolerance=500          
19 \emergencystretch=30pt 
20 %
21 \date{}
22 \end_preamble
23 \language english
24 \inputencoding default
25 \font_roman times
26 \font_sans helvet
27 \font_typewriter courier
28 \font_default_family default
29 \font_sc false
30 \font_osf false
31 \font_sf_scale 100
32 \font_tt_scale 100
33 \graphics default
34 \paperfontsize default
35 \spacing single
36 \papersize letterpaper
37 \use_geometry true
38 \use_amsmath 1
39 \use_esint 0
40 \cite_engine basic
41 \use_bibtopic false
42 \paperorientation portrait
43 \leftmargin 30mm
44 \topmargin 20mm
45 \rightmargin 25mm
46 \bottommargin 20mm
47 \secnumdepth 3
48 \tocdepth 3
49 \paragraph_separation indent
50 \defskip medskip
51 \quotes_language swedish
52 \papercolumns 1
53 \papersides 1
54 \paperpagestyle fancy
55 \tracking_changes false
56 \output_changes false
57 \author "" 
58 \end_header
59
60 \begin_body
61
62 \begin_layout Standard
63 \begin_inset Note Note
64 status collapsed
65
66 \begin_layout Standard
67 Please note: double dashed longoptions (e.g.
68  --version) are written this way: -
69 \begin_inset ERT
70 status collapsed
71
72 \begin_layout Standard
73
74
75 \backslash
76 /
77 \end_layout
78
79 \end_inset
80
81 -
82 \end_layout
83
84 \begin_layout Standard
85 Two resp.
86  three consecutive dashes would otherwise result in a long resp.
87  extra long dash.
88 \end_layout
89
90 \begin_layout Standard
91 Architecture specific stuff (like memory models, code examples) should maybe
92  later go
93 \end_layout
94
95 \begin_layout Standard
96 into separate sections/chapters/appendices (it is hard to document PIC or
97  Z80 in 
98 \end_layout
99
100 \begin_layout Standard
101 a 8051 centered document) - for now simply add.
102 \end_layout
103
104 \end_inset
105
106
107 \end_layout
108
109 \begin_layout Title
110 SDCC Compiler User Guide
111 \end_layout
112
113 \begin_layout Date
114
115 \size normal
116 SDCC 2.8.5
117 \size footnotesize
118
119 \newline
120 $Date: 2008-11-16#$ 
121 \newline
122 $Revision: 5272$
123 \end_layout
124
125 \begin_layout Standard
126 \begin_inset Note Note
127 status collapsed
128
129 \begin_layout Standard
130 The above strings enclosed in $ are automatically updated by Subversion
131 \end_layout
132
133 \end_inset
134
135
136 \end_layout
137
138 \begin_layout Standard
139 \begin_inset LatexCommand tableofcontents
140
141 \end_inset
142
143
144 \end_layout
145
146 \begin_layout Chapter
147 Introduction
148 \end_layout
149
150 \begin_layout Section
151 About SDCC
152 \end_layout
153
154 \begin_layout Standard
155
156 \series bold
157 SDCC
158 \series default
159  (
160 \emph on
161 S
162 \emph default
163 mall 
164 \emph on
165 D
166 \emph default
167 evice 
168 \emph on
169 C
170 \emph default
171  
172 \emph on
173 C
174 \emph default
175 ompiler) is free open source, retargettable, optimizing ANSI-C compiler
176  by 
177 \series bold
178 Sandeep Dutta
179 \series default
180  designed for 8 bit Microprocessors.
181  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
182  8051, 8052
183 \begin_inset LatexCommand index
184 name "8031, 8032, 8051, 8052, mcs51 CPU"
185
186 \end_inset
187
188 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
189  Zilog Z80 based MCUs.
190  It can be retargeted for other microprocessors, support for Microchip PIC,
191  Atmel AVR is under development.
192  The entire source code for the compiler is distributed under GPL.
193  SDCC uses ASXXXX
194 \begin_inset LatexCommand index
195 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
196
197 \end_inset
198
199  & ASLINK
200 \begin_inset LatexCommand index
201 name "aslink"
202
203 \end_inset
204
205 , an open source retargetable assembler & linker.
206  SDCC has extensive language extensions suitable for utilizing various microcont
207 rollers and underlying hardware effectively.
208  
209 \newline
210
211 \newline
212 In addition to the MCU specific optimizations SDCC also does a host of
213  standard optimizations like:
214 \end_layout
215
216 \begin_layout Itemize
217 global sub expression elimination, 
218 \end_layout
219
220 \begin_layout Itemize
221 loop optimizations (loop invariant, strength reduction of induction variables
222  and loop reversing), 
223 \end_layout
224
225 \begin_layout Itemize
226 constant folding & propagation, 
227 \end_layout
228
229 \begin_layout Itemize
230 copy propagation, 
231 \end_layout
232
233 \begin_layout Itemize
234 dead code elimination 
235 \end_layout
236
237 \begin_layout Itemize
238 jump tables for 
239 \emph on
240 switch
241 \emph default
242  statements.
243 \end_layout
244
245 \begin_layout Standard
246 For the back-end SDCC uses a global register allocation scheme which should
247  be well suited for other 8 bit MCUs.
248  
249 \newline
250
251 \newline
252 The peep hole optimizer uses a rule based substitution mechanism which
253  is MCU independent.
254  
255 \newline
256
257 \newline
258 Supported data-types are:
259 \end_layout
260
261 \begin_layout Standard
262 \begin_inset Tabular
263 <lyxtabular version="3" rows="8" columns="5">
264 <features>
265 <column alignment="center" valignment="top" leftline="true" width="0">
266 <column alignment="center" valignment="top" leftline="true" width="0">
267 <column alignment="center" valignment="top" leftline="true" width="0">
268 <column alignment="center" valignment="top" leftline="true" width="0">
269 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
270 <row topline="true" bottomline="true">
271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
272 \begin_inset Text
273
274 \begin_layout Standard
275 type
276 \end_layout
277
278 \end_inset
279 </cell>
280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
281 \begin_inset Text
282
283 \begin_layout Standard
284 width
285 \end_layout
286
287 \end_inset
288 </cell>
289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
290 \begin_inset Text
291
292 \begin_layout Standard
293 default
294 \end_layout
295
296 \end_inset
297 </cell>
298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
299 \begin_inset Text
300
301 \begin_layout Standard
302 signed range
303 \end_layout
304
305 \end_inset
306 </cell>
307 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
308 \begin_inset Text
309
310 \begin_layout Standard
311 unsigned range
312 \end_layout
313
314 \end_inset
315 </cell>
316 </row>
317 <row topline="true">
318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
319 \begin_inset Text
320
321 \begin_layout Standard
322 bool
323 \end_layout
324
325 \end_inset
326 </cell>
327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
328 \begin_inset Text
329
330 \begin_layout Standard
331 1 bit
332 \end_layout
333
334 \end_inset
335 </cell>
336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
337 \begin_inset Text
338
339 \begin_layout Standard
340 unsigned
341 \end_layout
342
343 \end_inset
344 </cell>
345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
346 \begin_inset Text
347
348 \begin_layout Standard
349 -
350 \end_layout
351
352 \end_inset
353 </cell>
354 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
355 \begin_inset Text
356
357 \begin_layout Standard
358 0, 1
359 \end_layout
360
361 \end_inset
362 </cell>
363 </row>
364 <row topline="true">
365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
366 \begin_inset Text
367
368 \begin_layout Standard
369 char
370 \end_layout
371
372 \end_inset
373 </cell>
374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
375 \begin_inset Text
376
377 \begin_layout Standard
378 8 bits, 1 byte
379 \end_layout
380
381 \end_inset
382 </cell>
383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
384 \begin_inset Text
385
386 \begin_layout Standard
387 signed
388 \end_layout
389
390 \end_inset
391 </cell>
392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
393 \begin_inset Text
394
395 \begin_layout Standard
396 -128, +127
397 \end_layout
398
399 \end_inset
400 </cell>
401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
402 \begin_inset Text
403
404 \begin_layout Standard
405 0, +255
406 \end_layout
407
408 \end_inset
409 </cell>
410 </row>
411 <row topline="true">
412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
413 \begin_inset Text
414
415 \begin_layout Standard
416 short
417 \end_layout
418
419 \end_inset
420 </cell>
421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
422 \begin_inset Text
423
424 \begin_layout Standard
425 16 bits, 2 bytes
426 \end_layout
427
428 \end_inset
429 </cell>
430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
431 \begin_inset Text
432
433 \begin_layout Standard
434 signed
435 \end_layout
436
437 \end_inset
438 </cell>
439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
440 \begin_inset Text
441
442 \begin_layout Standard
443 -32.768, +32.767
444 \end_layout
445
446 \end_inset
447 </cell>
448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
449 \begin_inset Text
450
451 \begin_layout Standard
452 0, +65.535
453 \end_layout
454
455 \end_inset
456 </cell>
457 </row>
458 <row topline="true">
459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
460 \begin_inset Text
461
462 \begin_layout Standard
463 int
464 \end_layout
465
466 \end_inset
467 </cell>
468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
469 \begin_inset Text
470
471 \begin_layout Standard
472 16 bits, 2 bytes
473 \end_layout
474
475 \end_inset
476 </cell>
477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
478 \begin_inset Text
479
480 \begin_layout Standard
481 signed
482 \end_layout
483
484 \end_inset
485 </cell>
486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
487 \begin_inset Text
488
489 \begin_layout Standard
490 -32.768, +32.767
491 \end_layout
492
493 \end_inset
494 </cell>
495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
496 \begin_inset Text
497
498 \begin_layout Standard
499 0, +65.535
500 \end_layout
501
502 \end_inset
503 </cell>
504 </row>
505 <row topline="true" bottomline="true">
506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
507 \begin_inset Text
508
509 \begin_layout Standard
510 long
511 \end_layout
512
513 \end_inset
514 </cell>
515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
516 \begin_inset Text
517
518 \begin_layout Standard
519 32 bits, 4 bytes
520 \end_layout
521
522 \end_inset
523 </cell>
524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
525 \begin_inset Text
526
527 \begin_layout Standard
528 signed
529 \end_layout
530
531 \end_inset
532 </cell>
533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
534 \begin_inset Text
535
536 \begin_layout Standard
537 -2.147.483.648, +2.147.483.647
538 \end_layout
539
540 \end_inset
541 </cell>
542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
543 \begin_inset Text
544
545 \begin_layout Standard
546 0, +4.294.967.295
547 \end_layout
548
549 \end_inset
550 </cell>
551 </row>
552 <row topline="true" bottomline="true">
553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
554 \begin_inset Text
555
556 \begin_layout Standard
557 float
558 \end_layout
559
560 \end_inset
561 </cell>
562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
563 \begin_inset Text
564
565 \begin_layout Standard
566 4 bytes IEEE 754
567 \end_layout
568
569 \end_inset
570 </cell>
571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
572 \begin_inset Text
573
574 \begin_layout Standard
575 signed
576 \end_layout
577
578 \end_inset
579 </cell>
580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
581 \begin_inset Text
582
583 \begin_layout Standard
584
585 \end_layout
586
587 \end_inset
588 </cell>
589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
590 \begin_inset Text
591
592 \begin_layout Standard
593 1.175494351E-38, 
594 \family roman
595 \series medium
596 \shape up
597 \size normal
598 \emph off
599 \bar no
600 \noun off
601 \color none
602 3.402823466E+38
603 \end_layout
604
605 \end_inset
606 </cell>
607 </row>
608 <row topline="true" bottomline="true">
609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
610 \begin_inset Text
611
612 \begin_layout Standard
613 pointer
614 \end_layout
615
616 \end_inset
617 </cell>
618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
619 \begin_inset Text
620
621 \begin_layout Standard
622 1, 2, 3 or 4 bytes
623 \end_layout
624
625 \end_inset
626 </cell>
627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
628 \begin_inset Text
629
630 \begin_layout Standard
631 generic
632 \end_layout
633
634 \end_inset
635 </cell>
636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
637 \begin_inset Text
638
639 \begin_layout Standard
640
641 \end_layout
642
643 \end_inset
644 </cell>
645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
646 \begin_inset Text
647
648 \begin_layout Standard
649
650 \end_layout
651
652 \end_inset
653 </cell>
654 </row>
655 </lyxtabular>
656
657 \end_inset
658
659
660 \newline
661 The compiler also allows 
662 \emph on
663 inline assembler code
664 \emph default
665  to be embedded anywhere in a function.
666  In addition, routines developed in assembly can also be called.
667 \newline
668
669 \newline
670 SDCC also
671  provides an option (-
672 \begin_inset ERT
673 status collapsed
674
675 \begin_layout Standard
676
677
678 \backslash
679 /
680 \end_layout
681
682 \end_inset
683
684 -cyclomatic) to report the relative complexity of a function.
685  These functions can then be further optimized, or hand coded in assembly
686  if needed.
687  
688 \newline
689
690 \newline
691 SDCC also comes with a companion source level debugger SDCDB.
692  The debugger currently uses ucSim, a free open source simulator for 8051
693  and other micro-controllers.
694 \newline
695
696 \newline
697 The latest SDCC version can be downloaded from
698  
699 \begin_inset LatexCommand url
700 target "http://sdcc.sourceforge.net/snap.php"
701
702 \end_inset
703
704 .
705  
706 \emph on
707 Please note: the compiler will probably always be some steps ahead of this
708  documentation
709 \series bold
710 \emph default
711
712 \begin_inset LatexCommand index
713 name "Status of documentation"
714
715 \end_inset
716
717
718 \begin_inset Foot
719 status open
720
721 \begin_layout Standard
722 Obviously this has pros and cons
723 \end_layout
724
725 \end_inset
726
727 .
728 \end_layout
729
730 \begin_layout Section
731 Open Source
732 \end_layout
733
734 \begin_layout Standard
735 All packages used in this compiler system are 
736 \emph on
737 open source
738 \emph default
739  and 
740 \emph on
741 freeware
742 \emph default
743 ; source code for all the sub-packages (pre-processor, assemblers, linkers
744  etc.) is distributed with the package.
745  This documentation is maintained using a free open source word processor
746  (LyX).
747 \newline
748 This program is free software; you can redistribute it and/or modify
749  it under the terms of the GNU General Public License
750 \begin_inset LatexCommand index
751 name "GNU General Public License, GPL"
752
753 \end_inset
754
755  as published by the Free Software Foundation; either version 2, or (at
756  your option) any later version.
757  This program is distributed in the hope that it will be useful, but WITHOUT
758  ANY WARRANTY; without even the implied warranty
759 \begin_inset LatexCommand index
760 name "warranty"
761
762 \end_inset
763
764  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
765  See the GNU General Public License for more details.
766  You should have received a copy of the GNU General Public License along
767  with this program; if not, write to the Free Software Foundation, 59 Temple
768  Place - Suite 330, Boston, MA 02111-1307, USA.
769  In other words, you are welcome to use, share and improve this program.
770  You are forbidden to forbid anyone else to use, share and improve what
771  you give them.
772  Help stamp out software-hoarding! 
773 \end_layout
774
775 \begin_layout Section
776 Typographic conventions
777 \begin_inset LatexCommand index
778 name "Typographic conventions"
779
780 \end_inset
781
782
783 \end_layout
784
785 \begin_layout Standard
786 Throughout this manual, we will use the following convention.
787  Commands you have to type in are printed in 
788 \family sans
789 \series bold
790 "sans serif"
791 \series default
792 .
793
794 \family default
795  Code samples are printed in 
796 \family typewriter
797 typewriter font.
798
799 \family default
800  Interesting items and new terms are printed in 
801 \emph on
802 italic.
803 \end_layout
804
805 \begin_layout Section
806 Compatibility
807 \begin_inset LatexCommand label
808 name "sec:Compatibility-with-previous"
809
810 \end_inset
811
812  with previous versions
813 \begin_inset LatexCommand index
814 name "Compatibility with previous versions"
815
816 \end_inset
817
818
819 \end_layout
820
821 \begin_layout Standard
822 Newer versions have usually numerous bug fixes compared with the previous
823  version.
824  But we also sometimes introduce some incompatibilities with older versions.
825  Not just for the fun of it, but to make the compiler more stable, efficient
826  and ANSI compliant
827 \begin_inset LatexCommand index
828 name "ANSI-compliance"
829
830 \end_inset
831
832  (see section 
833 \begin_inset LatexCommand ref
834 reference "sub:ANSI-Compliance"
835
836 \end_inset
837
838  for ANSI-Compliance).
839  
840 \begin_inset Note Note
841 status collapsed
842
843 \begin_layout Standard
844 It would be fine to add to each item, in which version was it changed.
845 \end_layout
846
847 \end_inset
848
849
850 \newline
851
852 \end_layout
853
854 \begin_layout Itemize
855 short is now equivalent to int (16 bits), it used to be equivalent to char
856  (8 bits) which is not ANSI compliant.
857  To maintain compatibility, old programs may be compiled using the -
858 \begin_inset ERT
859 status collapsed
860
861 \begin_layout Standard
862
863
864 \backslash
865 /
866 \end_layout
867
868 \end_inset
869
870 -short-is-8bits commandline option (see 
871 \begin_inset LatexCommand vref
872 reference "lyx:--short-is-8bits"
873
874 \end_inset
875
876 ).
877 \end_layout
878
879 \begin_layout Itemize
880 the default directory for gcc-builds where include, library and documentation
881  files are stored is now in /usr/local/share.
882 \end_layout
883
884 \begin_layout Itemize
885 char type parameters to vararg
886 \begin_inset LatexCommand index
887 name "vararg, va\\_arg"
888
889 \end_inset
890
891  functions are casted to int unless explicitly casted and 
892 \series bold
893 -
894 \begin_inset ERT
895 status collapsed
896
897 \begin_layout Standard
898
899
900 \backslash
901 /
902 \end_layout
903
904 \end_inset
905
906 -std-c89
907 \begin_inset LatexCommand index
908 name "-\\/-std-c89"
909
910 \end_inset
911
912
913 \series default
914  and 
915 \series bold
916 -
917 \begin_inset ERT
918 status collapsed
919
920 \begin_layout Standard
921
922
923 \backslash
924 /
925 \end_layout
926
927 \end_inset
928
929 -std-c99
930 \begin_inset LatexCommand index
931 name "-\\/-std-c99"
932
933 \end_inset
934
935
936 \series default
937  command line option are not defined 
938 \begin_inset Marginal
939 status collapsed
940
941 \begin_layout Standard
942
943 \series bold
944 \InsetSpace ~
945 !
946 \end_layout
947
948 \end_inset
949
950 , e.g.: 
951 \newline
952
953 \family typewriter
954 \InsetSpace ~
955 \InsetSpace ~
956 char a=3;
957 \newline
958 \InsetSpace ~
959 \InsetSpace ~
960 printf ("%d %c
961 \backslash
962 n", a, (char)a);
963 \family default
964
965 \newline
966  will push a as an int and as a char resp if 
967 \series bold
968 -
969 \begin_inset ERT
970 status collapsed
971
972 \begin_layout Standard
973
974
975 \backslash
976 /
977 \end_layout
978
979 \end_inset
980
981 -std-c89
982 \begin_inset LatexCommand index
983 name "-\\/-std-c89"
984
985 \end_inset
986
987
988 \series default
989  and 
990 \series bold
991 -
992 \begin_inset ERT
993 status collapsed
994
995 \begin_layout Standard
996
997
998 \backslash
999 /
1000 \end_layout
1001
1002 \end_inset
1003
1004 -std-c99
1005 \begin_inset LatexCommand index
1006 name "-\\/-std-c99"
1007
1008 \end_inset
1009
1010
1011 \series default
1012  command line options are not defined,
1013 \newline
1014  will push a as two ints if 
1015 \series bold
1016 -
1017 \begin_inset ERT
1018 status collapsed
1019
1020 \begin_layout Standard
1021
1022
1023 \backslash
1024 /
1025 \end_layout
1026
1027 \end_inset
1028
1029 -std-c89
1030 \begin_inset LatexCommand index
1031 name "-\\/-std-c89"
1032
1033 \end_inset
1034
1035
1036 \series default
1037  or 
1038 \series bold
1039 -
1040 \begin_inset ERT
1041 status collapsed
1042
1043 \begin_layout Standard
1044
1045
1046 \backslash
1047 /
1048 \end_layout
1049
1050 \end_inset
1051
1052 -std-c99
1053 \begin_inset LatexCommand index
1054 name "-\\/-std-c99"
1055
1056 \end_inset
1057
1058
1059 \series default
1060  command line option is defined.
1061 \end_layout
1062
1063 \begin_layout Itemize
1064 option -
1065 \begin_inset ERT
1066 status collapsed
1067
1068 \begin_layout Standard
1069
1070
1071 \backslash
1072 /
1073 \end_layout
1074
1075 \end_inset
1076
1077 -regextend has been removed.
1078 \end_layout
1079
1080 \begin_layout Itemize
1081 option -
1082 \begin_inset ERT
1083 status collapsed
1084
1085 \begin_layout Standard
1086
1087
1088 \backslash
1089 /
1090 \end_layout
1091
1092 \end_inset
1093
1094 -noregparms has been removed.
1095 \end_layout
1096
1097 \begin_layout Itemize
1098 option -
1099 \begin_inset ERT
1100 status collapsed
1101
1102 \begin_layout Standard
1103
1104
1105 \backslash
1106 /
1107 \end_layout
1108
1109 \end_inset
1110
1111 -stack-after-data has been removed.
1112 \end_layout
1113
1114 \begin_layout Itemize
1115 bit
1116 \begin_inset LatexCommand index
1117 name "bit"
1118
1119 \end_inset
1120
1121  and sbit
1122 \begin_inset LatexCommand index
1123 name "sbit"
1124
1125 \end_inset
1126
1127
1128 \begin_inset LatexCommand index
1129 name "\\_\\_sbit"
1130
1131 \end_inset
1132
1133  types now consistently behave like the C99 _Bool type with respect to type
1134  conversion
1135 \begin_inset LatexCommand index
1136 name "type conversion"
1137
1138 \end_inset
1139
1140
1141 \begin_inset LatexCommand index
1142 name "type promotion"
1143
1144 \end_inset
1145
1146 .
1147  The most common incompatibility resulting from this change is related to
1148  bit toggling
1149 \begin_inset LatexCommand index
1150 name "Bit toggling"
1151
1152 \end_inset
1153
1154  idioms, e.g.:
1155 \newline
1156
1157 \family typewriter
1158 \InsetSpace ~
1159 \InsetSpace ~
1160 bit b;
1161 \newline
1162 \InsetSpace ~
1163 \InsetSpace ~
1164 b = ~
1165 \begin_inset LatexCommand index
1166 name "\\~\\/ Operator"
1167
1168 \end_inset
1169
1170 b; /* equivalent to b=1 instead of toggling b */
1171 \begin_inset Marginal
1172 status collapsed
1173
1174 \begin_layout Standard
1175
1176 \series bold
1177 \InsetSpace ~
1178 !
1179 \end_layout
1180
1181 \end_inset
1182
1183
1184 \newline
1185 \InsetSpace ~
1186 \InsetSpace ~
1187 b = !b; /* toggles b */
1188 \newline
1189
1190 \family default
1191 In previous versions, both forms would have toggled the bit.
1192 \end_layout
1193
1194 \begin_layout Itemize
1195 in older versions, the preprocessor was always called with 
1196 \series bold
1197 -
1198 \begin_inset ERT
1199 status collapsed
1200
1201 \begin_layout Standard
1202
1203
1204 \backslash
1205 /
1206 \end_layout
1207
1208 \end_inset
1209
1210 -std-c99
1211 \begin_inset LatexCommand index
1212 name "-\\/-std-c99"
1213
1214 \end_inset
1215
1216
1217 \series default
1218  regardless of the 
1219 \series bold
1220 -
1221 \begin_inset ERT
1222 status collapsed
1223
1224 \begin_layout Standard
1225
1226
1227 \backslash
1228 /
1229 \end_layout
1230
1231 \end_inset
1232
1233 -std-xxx
1234 \series default
1235  setting.
1236  This is no longer true, and can cause compilation failures on code built
1237  with 
1238 \series bold
1239 -
1240 \begin_inset ERT
1241 status collapsed
1242
1243 \begin_layout Standard
1244
1245
1246 \backslash
1247 /
1248 \end_layout
1249
1250 \end_inset
1251
1252 -std-c89
1253 \begin_inset LatexCommand index
1254 name "-\\/-std-c89"
1255
1256 \end_inset
1257
1258
1259 \series default
1260  but using c99 preprocessor features, such as one-line (//) comments
1261 \end_layout
1262
1263 \begin_layout Itemize
1264 in versions older then 2.8.4 the pic16 *printf() and printf_tiny() library
1265  functions supported undocumented and not standard compliant 'b' binary
1266  format specifier ("%b", "%hb" and "%lb").
1267  The 'b' specifier is now disabled by default.
1268  It can be enabled by defining BINARY_SPECIFIER macro in files device/lib/pic16/
1269 libc/stdio/vfprintf.c and device/lib/pic16/libc/stdio/printf_tiny.c and recompilin
1270 g the library.
1271 \end_layout
1272
1273 \begin_layout Itemize
1274 in versions older then 2.8.5 the unnamed bitfield structure members participated
1275  in initialization, which is not conforming with ISO/IEC 9899:1999 standard
1276  (see section Section 6.7.8 Initialization, clause 9)
1277 \newline
1278
1279 \newline
1280 Old behavior, before
1281  version 2.8.5:
1282 \family typewriter
1283
1284 \newline
1285 \InsetSpace ~
1286 \InsetSpace ~
1287 struct {
1288 \newline
1289 \InsetSpace ~
1290 \InsetSpace ~
1291 \InsetSpace ~
1292 \InsetSpace ~
1293 int a : 2;
1294 \newline
1295 \InsetSpace ~
1296 \InsetSpace ~
1297 \InsetSpace ~
1298 \InsetSpace ~
1299 char\InsetSpace ~
1300  : 2;
1301 \newline
1302 \InsetSpace ~
1303 \InsetSpace ~
1304 \InsetSpace ~
1305 \InsetSpace ~
1306 int b : 2;
1307 \newline
1308 \InsetSpace ~
1309 \InsetSpace ~
1310 } s = {1, 2, 3};
1311 \family default
1312
1313 \newline
1314
1315 \family typewriter
1316 /* s.a = 1, s.b = 3 */
1317 \family default
1318
1319 \newline
1320
1321 \newline
1322 New behavior:
1323 \family typewriter
1324
1325 \newline
1326 \InsetSpace ~
1327 \InsetSpace ~
1328 struct {
1329 \newline
1330 \InsetSpace ~
1331 \InsetSpace ~
1332 \InsetSpace ~
1333 \InsetSpace ~
1334 int a : 2;
1335 \newline
1336 \InsetSpace ~
1337 \InsetSpace ~
1338 \InsetSpace ~
1339 \InsetSpace ~
1340 char\InsetSpace ~
1341  : 2;
1342 \newline
1343 \InsetSpace ~
1344 \InsetSpace ~
1345 \InsetSpace ~
1346 \InsetSpace ~
1347 int b : 2;
1348 \newline
1349 \InsetSpace ~
1350 \InsetSpace ~
1351 } s = {1, 2};
1352 \family default
1353
1354 \newline
1355
1356 \family typewriter
1357 /* s.a = 1, s.b = 2 */
1358 \end_layout
1359
1360 \begin_layout Section
1361 System Requirements
1362 \end_layout
1363
1364 \begin_layout Standard
1365 What do you need before you start installation of SDCC? A computer, and
1366  a desire to compute.
1367  The preferred method of installation is to compile SDCC from source using
1368  GNU gcc and make.
1369  For Windows some pre-compiled binary distributions are available for your
1370  convenience.
1371  You should have some experience with command line tools and compiler use.
1372 \end_layout
1373
1374 \begin_layout Section
1375 Other Resources
1376 \end_layout
1377
1378 \begin_layout Standard
1379 The SDCC home page at 
1380 \begin_inset LatexCommand url
1381 target "http://sdcc.sourceforge.net/"
1382
1383 \end_inset
1384
1385  is a great place to find distribution sets.
1386  You can also find links to the user mailing lists that offer help or discuss
1387  SDCC with other SDCC users.
1388  Web links to other SDCC related sites can also be found here.
1389  This document can be found in the DOC directory of the source package as
1390  a text or HTML file.
1391  A pdf version of this document is available at 
1392 \begin_inset LatexCommand url
1393 target "http://sdcc.sourceforge.net/doc/sdccman.pdf"
1394
1395 \end_inset
1396
1397 .
1398  Some of the other tools (simulator and assembler) included with SDCC contain
1399  their own documentation and can be found in the source distribution.
1400  If you want the latest unreleased software, the complete source package
1401  is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1402 sdcc/trunk/sdcc.
1403 \end_layout
1404
1405 \begin_layout Section
1406 Wishes for the future
1407 \end_layout
1408
1409 \begin_layout Standard
1410 There are (and always will be) some things that could be done.
1411  Here are some I can think of:
1412 \newline
1413
1414 \end_layout
1415
1416 \begin_layout Standard
1417
1418 \family typewriter
1419 char KernelFunction3(char p) at 0x340;
1420 \newline
1421
1422 \end_layout
1423
1424 \begin_layout Standard
1425
1426 \family typewriter
1427 better code banking
1428 \begin_inset LatexCommand index
1429 name "code banking (limited support)"
1430
1431 \end_inset
1432
1433  support for mcs51
1434 \newline
1435
1436 \newline
1437
1438 \family default
1439 If you can think of some more, please see the section 
1440 \begin_inset LatexCommand ref
1441 reference "sub:Requesting-Features"
1442
1443 \end_inset
1444
1445  about filing feature requests
1446 \begin_inset LatexCommand index
1447 name "Requesting features"
1448
1449 \end_inset
1450
1451
1452 \begin_inset LatexCommand index
1453 name "Feature request"
1454
1455 \end_inset
1456
1457 .
1458 \newline
1459
1460 \end_layout
1461
1462 \begin_layout Chapter
1463 Installing SDCC
1464 \begin_inset LatexCommand index
1465 name "Installation"
1466
1467 \end_inset
1468
1469
1470 \end_layout
1471
1472 \begin_layout Standard
1473 For most users it is sufficient to skip to either section 
1474 \begin_inset LatexCommand ref
1475 reference "sub:Building-SDCC-on-Linux"
1476
1477 \end_inset
1478
1479  (Unix) or section 
1480 \begin_inset LatexCommand ref
1481 reference "sub:Windows-Install"
1482
1483 \end_inset
1484
1485  (Windows).
1486  More detailed instructions follow below.
1487 \end_layout
1488
1489 \begin_layout Section
1490 Configure Options
1491 \begin_inset LatexCommand index
1492 name "Options SDCC configuration"
1493
1494 \end_inset
1495
1496
1497 \end_layout
1498
1499 \begin_layout Standard
1500 The install paths, search paths and other options are defined when running
1501  'configure'.
1502  The defaults can be overridden by:
1503 \end_layout
1504
1505 \begin_layout List
1506 \labelwidthstring 00.00.0000
1507 -
1508 \begin_inset ERT
1509 status collapsed
1510
1511 \begin_layout Standard
1512
1513
1514 \backslash
1515 /
1516 \end_layout
1517
1518 \end_inset
1519
1520 -prefix see table below
1521 \end_layout
1522
1523 \begin_layout List
1524 \labelwidthstring 00.00.0000
1525 -
1526 \begin_inset ERT
1527 status collapsed
1528
1529 \begin_layout Standard
1530
1531
1532 \backslash
1533 /
1534 \end_layout
1535
1536 \end_inset
1537
1538 -exec_prefix see table below
1539 \end_layout
1540
1541 \begin_layout List
1542 \labelwidthstring 00.00.0000
1543 -
1544 \begin_inset ERT
1545 status collapsed
1546
1547 \begin_layout Standard
1548
1549
1550 \backslash
1551 /
1552 \end_layout
1553
1554 \end_inset
1555
1556 -bindir see table below
1557 \end_layout
1558
1559 \begin_layout List
1560 \labelwidthstring 00.00.0000
1561 -
1562 \begin_inset ERT
1563 status collapsed
1564
1565 \begin_layout Standard
1566
1567
1568 \backslash
1569 /
1570 \end_layout
1571
1572 \end_inset
1573
1574 -datadir see table below
1575 \end_layout
1576
1577 \begin_layout List
1578 \labelwidthstring 00.00.0000
1579 -
1580 \begin_inset ERT
1581 status collapsed
1582
1583 \begin_layout Standard
1584
1585
1586 \backslash
1587 /
1588 \end_layout
1589
1590 \end_inset
1591
1592 -datarootdir see table below
1593 \newline
1594
1595 \end_layout
1596
1597 \begin_layout List
1598 \labelwidthstring 00.00.0000
1599 \InsetSpace ~
1600 \InsetSpace ~
1601 docdir environment variable, see table below
1602 \end_layout
1603
1604 \begin_layout List
1605 \labelwidthstring 00.00.0000
1606 \InsetSpace ~
1607 \InsetSpace ~
1608 include_dir_suffix environment variable, see table below
1609 \end_layout
1610
1611 \begin_layout List
1612 \labelwidthstring 00.00.0000
1613 \InsetSpace ~
1614 \InsetSpace ~
1615 lib_dir_suffix environment variable, see table below
1616 \end_layout
1617
1618 \begin_layout List
1619 \labelwidthstring 00.00.0000
1620 \InsetSpace ~
1621 \InsetSpace ~
1622 sdccconf_h_dir_separator environment variable, either / or 
1623 \backslash
1624
1625 \backslash
1626  makes sense here.
1627  This character will only be used in sdccconf.h; don't forget it's a C-header,
1628  therefore a double-backslash is needed there.
1629 \newline
1630
1631 \end_layout
1632
1633 \begin_layout List
1634 \labelwidthstring 00.00.0000
1635 -
1636 \begin_inset ERT
1637 status collapsed
1638
1639 \begin_layout Standard
1640
1641
1642 \backslash
1643 /
1644 \end_layout
1645
1646 \end_inset
1647
1648 -disable-mcs51-port Excludes the Intel mcs51 port
1649 \end_layout
1650
1651 \begin_layout List
1652 \labelwidthstring 00.00.0000
1653 -
1654 \begin_inset ERT
1655 status collapsed
1656
1657 \begin_layout Standard
1658
1659
1660 \backslash
1661 /
1662 \end_layout
1663
1664 \end_inset
1665
1666 -disable-gbz80-port Excludes the Gameboy gbz80 port
1667 \end_layout
1668
1669 \begin_layout List
1670 \labelwidthstring 00.00.0000
1671 -
1672 \begin_inset ERT
1673 status collapsed
1674
1675 \begin_layout Standard
1676
1677
1678 \backslash
1679 /
1680 \end_layout
1681
1682 \end_inset
1683
1684 -disable-z80-port Excludes the z80 port
1685 \end_layout
1686
1687 \begin_layout List
1688 \labelwidthstring 00.00.0000
1689 -
1690 \begin_inset ERT
1691 status collapsed
1692
1693 \begin_layout Standard
1694
1695
1696 \backslash
1697 /
1698 \end_layout
1699
1700 \end_inset
1701
1702 -disable-avr-port Excludes the AVR port
1703 \end_layout
1704
1705 \begin_layout List
1706 \labelwidthstring 00.00.0000
1707 -
1708 \begin_inset ERT
1709 status collapsed
1710
1711 \begin_layout Standard
1712
1713
1714 \backslash
1715 /
1716 \end_layout
1717
1718 \end_inset
1719
1720 -disable-ds390-port Excludes the DS390 port
1721 \end_layout
1722
1723 \begin_layout List
1724 \labelwidthstring 00.00.0000
1725 -
1726 \begin_inset ERT
1727 status collapsed
1728
1729 \begin_layout Standard
1730
1731
1732 \backslash
1733 /
1734 \end_layout
1735
1736 \end_inset
1737
1738 -disable-hc08-port Excludes the HC08 port
1739 \end_layout
1740
1741 \begin_layout List
1742 \labelwidthstring 00.00.0000
1743 -
1744 \begin_inset ERT
1745 status collapsed
1746
1747 \begin_layout Standard
1748
1749
1750 \backslash
1751 /
1752 \end_layout
1753
1754 \end_inset
1755
1756 -disable-pic-port Excludes the PIC14 port
1757 \end_layout
1758
1759 \begin_layout List
1760 \labelwidthstring 00.00.0000
1761 -
1762 \begin_inset ERT
1763 status collapsed
1764
1765 \begin_layout Standard
1766
1767
1768 \backslash
1769 /
1770 \end_layout
1771
1772 \end_inset
1773
1774 -disable-pic16-port Excludes the PIC16 port
1775 \end_layout
1776
1777 \begin_layout List
1778 \labelwidthstring 00.00.0000
1779 -
1780 \begin_inset ERT
1781 status collapsed
1782
1783 \begin_layout Standard
1784
1785
1786 \backslash
1787 /
1788 \end_layout
1789
1790 \end_inset
1791
1792 -disable-xa51-port Excludes the XA51 port
1793 \end_layout
1794
1795 \begin_layout List
1796 \labelwidthstring 00.00.0000
1797 -
1798 \begin_inset ERT
1799 status collapsed
1800
1801 \begin_layout Standard
1802
1803
1804 \backslash
1805 /
1806 \end_layout
1807
1808 \end_inset
1809
1810 -disable-ucsim Disables configuring and building of ucsim
1811 \end_layout
1812
1813 \begin_layout List
1814 \labelwidthstring 00.00.0000
1815 -
1816 \begin_inset ERT
1817 status collapsed
1818
1819 \begin_layout Standard
1820
1821
1822 \backslash
1823 /
1824 \end_layout
1825
1826 \end_inset
1827
1828 -disable-device-lib Disables automatically building device libraries
1829 \end_layout
1830
1831 \begin_layout List
1832 \labelwidthstring 00.00.0000
1833 -
1834 \begin_inset ERT
1835 status collapsed
1836
1837 \begin_layout Standard
1838
1839
1840 \backslash
1841 /
1842 \end_layout
1843
1844 \end_inset
1845
1846 -disable-packihx Disables building packihx
1847 \newline
1848
1849 \end_layout
1850
1851 \begin_layout List
1852 \labelwidthstring 00.00.0000
1853 -
1854 \begin_inset ERT
1855 status collapsed
1856
1857 \begin_layout Standard
1858
1859
1860 \backslash
1861 /
1862 \end_layout
1863
1864 \end_inset
1865
1866 -enable-doc Build pdf, html and txt files from the lyx sources
1867 \end_layout
1868
1869 \begin_layout List
1870 \labelwidthstring 00.00.0000
1871 -
1872 \begin_inset ERT
1873 status collapsed
1874
1875 \begin_layout Standard
1876
1877
1878 \backslash
1879 /
1880 \end_layout
1881
1882 \end_inset
1883
1884 -enable-libgc Use the Bohem memory allocator.
1885  Lower runtime footprint.
1886 \end_layout
1887
1888 \begin_layout List
1889 \labelwidthstring 00.00.0000
1890 -
1891 \begin_inset ERT
1892 status collapsed
1893
1894 \begin_layout Standard
1895
1896
1897 \backslash
1898 /
1899 \end_layout
1900
1901 \end_inset
1902
1903 -without-ccache Do not use ccache even if available
1904 \end_layout
1905
1906 \begin_layout Standard
1907 Furthermore the environment variables CC, CFLAGS, ...
1908  the tools and their arguments can be influenced.
1909  Please see `configure -
1910 \begin_inset ERT
1911 status collapsed
1912
1913 \begin_layout Standard
1914
1915
1916 \backslash
1917 /
1918 \end_layout
1919
1920 \end_inset
1921
1922 -help' and the man/info pages of `configure' for details.
1923 \newline
1924
1925 \newline
1926 The names of the
1927  standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1928 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1929  SDCC_LIB_NAME are defined by `configure' too.
1930  At the moment it's not possible to change the default settings (it was
1931  simply never required).
1932 \newline
1933
1934 \newline
1935 These configure options are compiled into the binaries,
1936  and can only be changed by rerunning 'configure' and recompiling SDCC.
1937  The configure options are written in 
1938 \emph on
1939 italics
1940 \emph default
1941  to distinguish them from run time environment variables (see section search
1942  paths).
1943 \newline
1944
1945 \newline
1946 The settings for 
1947 \begin_inset Quotes sld
1948 \end_inset
1949
1950 Win32 builds
1951 \begin_inset Quotes srd
1952 \end_inset
1953
1954  are used by the SDCC team to build the official Win32 binaries.
1955  The SDCC team uses Mingw32 to build the official Windows binaries, because
1956  it's
1957 \end_layout
1958
1959 \begin_layout Enumerate
1960 open source, 
1961 \end_layout
1962
1963 \begin_layout Enumerate
1964 a gcc compiler and last but not least
1965 \end_layout
1966
1967 \begin_layout Enumerate
1968 the binaries can be built by cross compiling on SDCC Distributed Compile
1969  Farm.
1970 \end_layout
1971
1972 \begin_layout Standard
1973 See the examples, how to pass the Win32 settings to 'configure'.
1974  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1975  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1976  for Win32.
1977 \newline
1978
1979 \newline
1980 These defaults are:
1981 \newline
1982
1983 \end_layout
1984
1985 \begin_layout Standard
1986 \align center
1987 \begin_inset Tabular
1988 <lyxtabular version="3" rows="9" columns="3">
1989 <features>
1990 <column alignment="block" valignment="top" leftline="true" width="0in">
1991 <column alignment="block" valignment="top" leftline="true" width="0in">
1992 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1993 <row topline="true" bottomline="true">
1994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1995 \begin_inset Text
1996
1997 \begin_layout Standard
1998 Variable
1999 \end_layout
2000
2001 \end_inset
2002 </cell>
2003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2004 \begin_inset Text
2005
2006 \begin_layout Standard
2007 default
2008 \end_layout
2009
2010 \end_inset
2011 </cell>
2012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2013 \begin_inset Text
2014
2015 \begin_layout Standard
2016 Win32 builds
2017 \end_layout
2018
2019 \end_inset
2020 </cell>
2021 </row>
2022 <row topline="true">
2023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2024 \begin_inset Text
2025
2026 \begin_layout Standard
2027
2028 \emph on
2029 PREFIX
2030 \end_layout
2031
2032 \end_inset
2033 </cell>
2034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2035 \begin_inset Text
2036
2037 \begin_layout Standard
2038 /usr/local
2039 \end_layout
2040
2041 \end_inset
2042 </cell>
2043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2044 \begin_inset Text
2045
2046 \begin_layout Standard
2047
2048 \backslash
2049 sdcc
2050 \end_layout
2051
2052 \end_inset
2053 </cell>
2054 </row>
2055 <row topline="true">
2056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2057 \begin_inset Text
2058
2059 \begin_layout Standard
2060
2061 \emph on
2062 EXEC_PREFIX
2063 \end_layout
2064
2065 \end_inset
2066 </cell>
2067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2068 \begin_inset Text
2069
2070 \begin_layout Standard
2071
2072 \emph on
2073 $PREFIX
2074 \end_layout
2075
2076 \end_inset
2077 </cell>
2078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2079 \begin_inset Text
2080
2081 \begin_layout Standard
2082
2083 \emph on
2084 $PREFIX
2085 \end_layout
2086
2087 \end_inset
2088 </cell>
2089 </row>
2090 <row topline="true">
2091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2092 \begin_inset Text
2093
2094 \begin_layout Standard
2095
2096 \emph on
2097 BINDIR
2098 \end_layout
2099
2100 \end_inset
2101 </cell>
2102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2103 \begin_inset Text
2104
2105 \begin_layout Standard
2106
2107 \emph on
2108 $EXEC_PREFIX
2109 \emph default
2110 /bin
2111 \end_layout
2112
2113 \end_inset
2114 </cell>
2115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2116 \begin_inset Text
2117
2118 \begin_layout Standard
2119
2120 \emph on
2121 $EXEC_PREFIX
2122 \emph default
2123
2124 \backslash
2125 bin
2126 \end_layout
2127
2128 \end_inset
2129 </cell>
2130 </row>
2131 <row topline="true">
2132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2133 \begin_inset Text
2134
2135 \begin_layout Standard
2136
2137 \emph on
2138 DATADIR
2139 \end_layout
2140
2141 \end_inset
2142 </cell>
2143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2144 \begin_inset Text
2145
2146 \begin_layout Standard
2147
2148 \emph on
2149 $DATAROOTDIR
2150 \end_layout
2151
2152 \end_inset
2153 </cell>
2154 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2155 \begin_inset Text
2156
2157 \begin_layout Standard
2158
2159 \emph on
2160 $DATAROOTDIR
2161 \end_layout
2162
2163 \end_inset
2164 </cell>
2165 </row>
2166 <row topline="true">
2167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2168 \begin_inset Text
2169
2170 \begin_layout Standard
2171
2172 \emph on
2173 DATAROOTDIR
2174 \end_layout
2175
2176 \end_inset
2177 </cell>
2178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2179 \begin_inset Text
2180
2181 \begin_layout Standard
2182
2183 \emph on
2184 $PREFIX
2185 \emph default
2186 /share
2187 \end_layout
2188
2189 \end_inset
2190 </cell>
2191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2192 \begin_inset Text
2193
2194 \begin_layout Standard
2195
2196 \emph on
2197 $PREFIX
2198 \end_layout
2199
2200 \end_inset
2201 </cell>
2202 </row>
2203 <row topline="true">
2204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2205 \begin_inset Text
2206
2207 \begin_layout Standard
2208
2209 \emph on
2210 DOCDIR
2211 \end_layout
2212
2213 \end_inset
2214 </cell>
2215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2216 \begin_inset Text
2217
2218 \begin_layout Standard
2219
2220 \emph on
2221 $DATAROOTDIR
2222 \emph default
2223 /sdcc/doc
2224 \end_layout
2225
2226 \end_inset
2227 </cell>
2228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2229 \begin_inset Text
2230
2231 \begin_layout Standard
2232
2233 \emph on
2234 $DATAROOTDIR
2235 \emph default
2236
2237 \backslash
2238 doc
2239 \end_layout
2240
2241 \end_inset
2242 </cell>
2243 </row>
2244 <row topline="true">
2245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2246 \begin_inset Text
2247
2248 \begin_layout Standard
2249
2250 \emph on
2251 INCLUDE_DIR_SUFFIX
2252 \end_layout
2253
2254 \end_inset
2255 </cell>
2256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2257 \begin_inset Text
2258
2259 \begin_layout Standard
2260 sdcc/include
2261 \end_layout
2262
2263 \end_inset
2264 </cell>
2265 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2266 \begin_inset Text
2267
2268 \begin_layout Standard
2269 include
2270 \end_layout
2271
2272 \end_inset
2273 </cell>
2274 </row>
2275 <row topline="true" bottomline="true">
2276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2277 \begin_inset Text
2278
2279 \begin_layout Standard
2280
2281 \emph on
2282 LIB_DIR_SUFFIX
2283 \end_layout
2284
2285 \end_inset
2286 </cell>
2287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2288 \begin_inset Text
2289
2290 \begin_layout Standard
2291 sdcc/lib
2292 \end_layout
2293
2294 \end_inset
2295 </cell>
2296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2297 \begin_inset Text
2298
2299 \begin_layout Standard
2300 lib
2301 \end_layout
2302
2303 \end_inset
2304 </cell>
2305 </row>
2306 </lyxtabular>
2307
2308 \end_inset
2309
2310
2311 \newline
2312
2313 \end_layout
2314
2315 \begin_layout Standard
2316 \noindent
2317 'configure' also computes relative paths.
2318  This is needed for full relocatability of a binary package and to complete
2319  search paths (see section search paths below):
2320 \newline
2321  
2322 \end_layout
2323
2324 \begin_layout Standard
2325 \align center
2326 \begin_inset Tabular
2327 <lyxtabular version="3" rows="4" columns="3">
2328 <features>
2329 <column alignment="block" valignment="top" leftline="true" width="0in">
2330 <column alignment="block" valignment="top" leftline="true" width="0in">
2331 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2332 <row topline="true" bottomline="true">
2333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2334 \begin_inset Text
2335
2336 \begin_layout Standard
2337 Variable (computed)
2338 \end_layout
2339
2340 \end_inset
2341 </cell>
2342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2343 \begin_inset Text
2344
2345 \begin_layout Standard
2346 default
2347 \end_layout
2348
2349 \end_inset
2350 </cell>
2351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2352 \begin_inset Text
2353
2354 \begin_layout Standard
2355 Win32 builds
2356 \end_layout
2357
2358 \end_inset
2359 </cell>
2360 </row>
2361 <row topline="true" bottomline="true">
2362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2363 \begin_inset Text
2364
2365 \begin_layout Standard
2366
2367 \emph on
2368 BIN2DATA_DIR
2369 \end_layout
2370
2371 \end_inset
2372 </cell>
2373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2374 \begin_inset Text
2375
2376 \begin_layout Standard
2377 ../share
2378 \end_layout
2379
2380 \end_inset
2381 </cell>
2382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2383 \begin_inset Text
2384
2385 \begin_layout Standard
2386 ..
2387 \end_layout
2388
2389 \end_inset
2390 </cell>
2391 </row>
2392 <row bottomline="true">
2393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2394 \begin_inset Text
2395
2396 \begin_layout Standard
2397
2398 \emph on
2399 PREFIX2BIN_DIR
2400 \end_layout
2401
2402 \end_inset
2403 </cell>
2404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2405 \begin_inset Text
2406
2407 \begin_layout Standard
2408 bin
2409 \end_layout
2410
2411 \end_inset
2412 </cell>
2413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2414 \begin_inset Text
2415
2416 \begin_layout Standard
2417 bin
2418 \end_layout
2419
2420 \end_inset
2421 </cell>
2422 </row>
2423 <row bottomline="true">
2424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2425 \begin_inset Text
2426
2427 \begin_layout Standard
2428
2429 \emph on
2430 PREFIX2DATA_DIR
2431 \end_layout
2432
2433 \end_inset
2434 </cell>
2435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2436 \begin_inset Text
2437
2438 \begin_layout Standard
2439 share/sdcc
2440 \end_layout
2441
2442 \end_inset
2443 </cell>
2444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2445 \begin_inset Text
2446
2447 \begin_layout Standard
2448
2449 \end_layout
2450
2451 \end_inset
2452 </cell>
2453 </row>
2454 </lyxtabular>
2455
2456 \end_inset
2457
2458
2459 \newline
2460
2461 \end_layout
2462
2463 \begin_layout Standard
2464 \noindent
2465 Examples:
2466 \end_layout
2467
2468 \begin_layout LyX-Code
2469 ./configure
2470 \newline
2471 ./configure -
2472 \begin_inset ERT
2473 status collapsed
2474
2475 \begin_layout Standard
2476
2477
2478 \backslash
2479 /
2480 \end_layout
2481
2482 \end_inset
2483
2484 -prefix=
2485 \begin_inset Quotes srd
2486 \end_inset
2487
2488 /usr/bin
2489 \begin_inset Quotes srd
2490 \end_inset
2491
2492  -
2493 \begin_inset ERT
2494 status collapsed
2495
2496 \begin_layout Standard
2497
2498
2499 \backslash
2500 /
2501 \end_layout
2502
2503 \end_inset
2504
2505 -datarootdir=
2506 \begin_inset Quotes srd
2507 \end_inset
2508
2509 /usr/share
2510 \begin_inset Quotes srd
2511 \end_inset
2512
2513
2514 \newline
2515 ./configure -
2516 \begin_inset ERT
2517 status collapsed
2518
2519 \begin_layout Standard
2520
2521
2522 \backslash
2523 /
2524 \end_layout
2525
2526 \end_inset
2527
2528 -disable-avr-port -
2529 \begin_inset ERT
2530 status collapsed
2531
2532 \begin_layout Standard
2533
2534
2535 \backslash
2536 /
2537 \end_layout
2538
2539 \end_inset
2540
2541 -disable-xa51-port
2542 \end_layout
2543
2544 \begin_layout Standard
2545 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2546 32'):
2547 \end_layout
2548
2549 \begin_layout LyX-Code
2550 ./configure 
2551 \backslash
2552
2553 \newline
2554 CC=
2555 \begin_inset Quotes srd
2556 \end_inset
2557
2558 i586-mingw32msvc-gcc
2559 \begin_inset Quotes srd
2560 \end_inset
2561
2562  CXX=
2563 \begin_inset Quotes srd
2564 \end_inset
2565
2566 i586-mingw32msvc-g++
2567 \begin_inset Quotes srd
2568 \end_inset
2569
2570  
2571 \backslash
2572  
2573 \newline
2574 RANLIB=
2575 \begin_inset Quotes srd
2576 \end_inset
2577
2578 i586-mingw32msvc-ranlib
2579 \begin_inset Quotes srd
2580 \end_inset
2581
2582  
2583 \backslash
2584
2585 \newline
2586 STRIP=
2587 \begin_inset Quotes srd
2588 \end_inset
2589
2590 i586-mingw32msvc-strip
2591 \begin_inset Quotes srd
2592 \end_inset
2593
2594  
2595 \backslash
2596
2597 \newline
2598 -
2599 \begin_inset ERT
2600 status collapsed
2601
2602 \begin_layout Standard
2603
2604
2605 \backslash
2606 /
2607 \end_layout
2608
2609 \end_inset
2610
2611 -prefix=
2612 \begin_inset Quotes srd
2613 \end_inset
2614
2615 /sdcc
2616 \begin_inset Quotes srd
2617 \end_inset
2618
2619  
2620 \backslash
2621
2622 \newline
2623 -
2624 \begin_inset ERT
2625 status collapsed
2626
2627 \begin_layout Standard
2628
2629
2630 \backslash
2631 /
2632 \end_layout
2633
2634 \end_inset
2635
2636 -datarootdir=
2637 \begin_inset Quotes srd
2638 \end_inset
2639
2640 /sdcc
2641 \begin_inset Quotes srd
2642 \end_inset
2643
2644  
2645 \backslash
2646
2647 \newline
2648 docdir=
2649 \begin_inset Quotes srd
2650 \end_inset
2651
2652
2653 \backslash
2654 ${datarootdir}/doc
2655 \begin_inset Quotes srd
2656 \end_inset
2657
2658  
2659 \backslash
2660
2661 \newline
2662 include_dir_suffix=
2663 \begin_inset Quotes srd
2664 \end_inset
2665
2666 include
2667 \begin_inset Quotes srd
2668 \end_inset
2669
2670  
2671 \backslash
2672
2673 \newline
2674 lib_dir_suffix=
2675 \begin_inset Quotes srd
2676 \end_inset
2677
2678 lib
2679 \begin_inset Quotes srd
2680 \end_inset
2681
2682  
2683 \backslash
2684
2685 \newline
2686 sdccconf_h_dir_separator=
2687 \begin_inset Quotes srd
2688 \end_inset
2689
2690
2691 \backslash
2692
2693 \backslash
2694
2695 \backslash
2696
2697 \backslash
2698
2699 \begin_inset Quotes srd
2700 \end_inset
2701
2702  
2703 \backslash
2704
2705 \newline
2706 -
2707 \begin_inset ERT
2708 status collapsed
2709
2710 \begin_layout Standard
2711
2712
2713 \backslash
2714 /
2715 \end_layout
2716
2717 \end_inset
2718
2719 -disable-device-lib
2720 \backslash
2721
2722 \newline
2723 -
2724 \begin_inset ERT
2725 status collapsed
2726
2727 \begin_layout Standard
2728
2729
2730 \backslash
2731 /
2732 \end_layout
2733
2734 \end_inset
2735
2736 -host=i586-mingw32msvc
2737 \backslash
2738
2739 \newline
2740 -
2741 \begin_inset ERT
2742 status collapsed
2743
2744 \begin_layout Standard
2745
2746
2747 \backslash
2748 /
2749 \end_layout
2750
2751 \end_inset
2752
2753 -build=unknown-unknown-linux-gnu
2754 \end_layout
2755
2756 \begin_layout Standard
2757 To 
2758 \begin_inset Quotes sld
2759 \end_inset
2760
2761 cross
2762 \begin_inset Quotes srd
2763 \end_inset
2764
2765 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2766 ):
2767 \end_layout
2768
2769 \begin_layout LyX-Code
2770 ./configure -C 
2771 \backslash
2772
2773 \newline
2774 -
2775 \begin_inset ERT
2776 status collapsed
2777
2778 \begin_layout Standard
2779
2780
2781 \backslash
2782 /
2783 \end_layout
2784
2785 \end_inset
2786
2787 -prefix=
2788 \begin_inset Quotes srd
2789 \end_inset
2790
2791 /sdcc
2792 \begin_inset Quotes srd
2793 \end_inset
2794
2795  
2796 \backslash
2797
2798 \newline
2799 -
2800 \begin_inset ERT
2801 status collapsed
2802
2803 \begin_layout Standard
2804
2805
2806 \backslash
2807 /
2808 \end_layout
2809
2810 \end_inset
2811
2812 -datarootdir=
2813 \begin_inset Quotes srd
2814 \end_inset
2815
2816 /sdcc
2817 \begin_inset Quotes srd
2818 \end_inset
2819
2820  
2821 \backslash
2822
2823 \newline
2824 docdir=
2825 \begin_inset Quotes srd
2826 \end_inset
2827
2828
2829 \backslash
2830 ${datarootdir}/doc
2831 \begin_inset Quotes srd
2832 \end_inset
2833
2834  
2835 \backslash
2836  
2837 \newline
2838 include_dir_suffix=
2839 \begin_inset Quotes srd
2840 \end_inset
2841
2842 include
2843 \begin_inset Quotes srd
2844 \end_inset
2845
2846  
2847 \backslash
2848
2849 \newline
2850 lib_dir_suffix=
2851 \begin_inset Quotes srd
2852 \end_inset
2853
2854 lib
2855 \begin_inset Quotes srd
2856 \end_inset
2857
2858  
2859 \backslash
2860
2861 \newline
2862 sdccconf_h_dir_separator=
2863 \begin_inset Quotes srd
2864 \end_inset
2865
2866
2867 \backslash
2868
2869 \backslash
2870
2871 \backslash
2872
2873 \backslash
2874
2875 \begin_inset Quotes srd
2876 \end_inset
2877
2878  
2879 \backslash
2880
2881 \newline
2882 CC=
2883 \begin_inset Quotes srd
2884 \end_inset
2885
2886 gcc -mno-cygwin
2887 \begin_inset Quotes srd
2888 \end_inset
2889
2890  
2891 \backslash
2892
2893 \newline
2894 CXX=
2895 \begin_inset Quotes srd
2896 \end_inset
2897
2898 g++ -mno-cygwin
2899 \begin_inset Quotes srd
2900 \end_inset
2901
2902  
2903 \end_layout
2904
2905 \begin_layout Standard
2906 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2907  The option '-
2908 \begin_inset ERT
2909 status collapsed
2910
2911 \begin_layout Standard
2912
2913
2914 \backslash
2915 /
2916 \end_layout
2917
2918 \end_inset
2919
2920 -C' turns on caching, which gives a little bit extra speed.
2921  However if options are changed, it can be necessary to delete the config.cache
2922  file.
2923 \end_layout
2924
2925 \begin_layout Section
2926 Install paths
2927 \begin_inset LatexCommand label
2928 name "sub:Install-paths"
2929
2930 \end_inset
2931
2932
2933 \begin_inset LatexCommand index
2934 name "Install paths"
2935
2936 \end_inset
2937
2938
2939 \end_layout
2940
2941 \begin_layout Standard
2942 \begin_inset VSpace medskip
2943 \end_inset
2944
2945
2946 \end_layout
2947
2948 \begin_layout Standard
2949 \align center
2950 \begin_inset Tabular
2951 <lyxtabular version="3" rows="5" columns="4">
2952 <features>
2953 <column alignment="left" valignment="top" leftline="true" width="0">
2954 <column alignment="left" valignment="top" leftline="true" width="0">
2955 <column alignment="left" valignment="top" leftline="true" width="0">
2956 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2957 <row topline="true" bottomline="true">
2958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2959 \begin_inset Text
2960
2961 \begin_layout Standard
2962
2963 \series bold
2964 Description
2965 \end_layout
2966
2967 \end_inset
2968 </cell>
2969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2970 \begin_inset Text
2971
2972 \begin_layout Standard
2973
2974 \series bold
2975 Path
2976 \end_layout
2977
2978 \end_inset
2979 </cell>
2980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2981 \begin_inset Text
2982
2983 \begin_layout Standard
2984
2985 \series bold
2986 Default
2987 \end_layout
2988
2989 \end_inset
2990 </cell>
2991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2992 \begin_inset Text
2993
2994 \begin_layout Standard
2995
2996 \series bold
2997 Win32 builds
2998 \end_layout
2999
3000 \end_inset
3001 </cell>
3002 </row>
3003 <row topline="true">
3004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3005 \begin_inset Text
3006
3007 \begin_layout Standard
3008 Binary files*
3009 \end_layout
3010
3011 \end_inset
3012 </cell>
3013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3014 \begin_inset Text
3015
3016 \begin_layout Standard
3017
3018 \emph on
3019 $EXEC_PREFIX
3020 \end_layout
3021
3022 \end_inset
3023 </cell>
3024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3025 \begin_inset Text
3026
3027 \begin_layout Standard
3028 /usr/local/bin
3029 \end_layout
3030
3031 \end_inset
3032 </cell>
3033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3034 \begin_inset Text
3035
3036 \begin_layout Standard
3037
3038 \backslash
3039 sdcc
3040 \backslash
3041 bin
3042 \end_layout
3043
3044 \end_inset
3045 </cell>
3046 </row>
3047 <row topline="true">
3048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3049 \begin_inset Text
3050
3051 \begin_layout Standard
3052 Include files
3053 \end_layout
3054
3055 \end_inset
3056 </cell>
3057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3058 \begin_inset Text
3059
3060 \begin_layout Standard
3061
3062 \emph on
3063 $DATADIR/ $INCLUDE_DIR_SUFFIX
3064 \end_layout
3065
3066 \end_inset
3067 </cell>
3068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3069 \begin_inset Text
3070
3071 \begin_layout Standard
3072 /usr/local/share/sdcc/include
3073 \end_layout
3074
3075 \end_inset
3076 </cell>
3077 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3078 \begin_inset Text
3079
3080 \begin_layout Standard
3081
3082 \backslash
3083 sdcc
3084 \backslash
3085 include
3086 \end_layout
3087
3088 \end_inset
3089 </cell>
3090 </row>
3091 <row topline="true">
3092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3093 \begin_inset Text
3094
3095 \begin_layout Standard
3096 Library file**
3097 \end_layout
3098
3099 \end_inset
3100 </cell>
3101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3102 \begin_inset Text
3103
3104 \begin_layout Standard
3105
3106 \emph on
3107 $DATADIR/$LIB_DIR_SUFFIX
3108 \end_layout
3109
3110 \end_inset
3111 </cell>
3112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3113 \begin_inset Text
3114
3115 \begin_layout Standard
3116 /usr/local/share/sdcc/lib
3117 \end_layout
3118
3119 \end_inset
3120 </cell>
3121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3122 \begin_inset Text
3123
3124 \begin_layout Standard
3125
3126 \backslash
3127 sdcc
3128 \backslash
3129 lib
3130 \end_layout
3131
3132 \end_inset
3133 </cell>
3134 </row>
3135 <row topline="true" bottomline="true">
3136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3137 \begin_inset Text
3138
3139 \begin_layout Standard
3140 Documentation
3141 \end_layout
3142
3143 \end_inset
3144 </cell>
3145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3146 \begin_inset Text
3147
3148 \begin_layout Standard
3149
3150 \emph on
3151 $DOCDIR
3152 \end_layout
3153
3154 \end_inset
3155 </cell>
3156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3157 \begin_inset Text
3158
3159 \begin_layout Standard
3160 /usr/local/share/sdcc/doc
3161 \end_layout
3162
3163 \end_inset
3164 </cell>
3165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3166 \begin_inset Text
3167
3168 \begin_layout Standard
3169
3170 \backslash
3171 sdcc
3172 \backslash
3173 doc
3174 \end_layout
3175
3176 \end_inset
3177 </cell>
3178 </row>
3179 </lyxtabular>
3180
3181 \end_inset
3182
3183
3184 \end_layout
3185
3186 \begin_layout Verse
3187
3188 \size footnotesize
3189 *compiler, preprocessor, assembler, and linker
3190 \newline
3191 **the 
3192 \shape italic
3193 model
3194 \shape default
3195  is auto-appended by the compiler, e.g.
3196  small, large, z80, ds390 etc
3197 \end_layout
3198
3199 \begin_layout Standard
3200 \noindent
3201 The install paths can still be changed during `make install' with e.g.:
3202 \end_layout
3203
3204 \begin_layout LyX-Code
3205 make install prefix=$(HOME)/local/sdcc
3206 \end_layout
3207
3208 \begin_layout Standard
3209 Of course this doesn't change the search paths compiled into the binaries.
3210 \newline
3211
3212 \newline
3213 Moreove
3214 r the install path can be changed by defining DESTDIR
3215 \begin_inset LatexCommand index
3216 name "DESTDIR"
3217
3218 \end_inset
3219
3220 :
3221 \end_layout
3222
3223 \begin_layout LyX-Code
3224 make install DESTDIR=$(HOME)/sdcc.rpm/
3225 \end_layout
3226
3227 \begin_layout Standard
3228 Please note that DESTDIR must have a trailing slash!
3229 \end_layout
3230
3231 \begin_layout Section
3232 Search Paths
3233 \begin_inset LatexCommand label
3234 name "sub:Search-Paths"
3235
3236 \end_inset
3237
3238
3239 \begin_inset LatexCommand index
3240 name "Search path"
3241
3242 \end_inset
3243
3244
3245 \end_layout
3246
3247 \begin_layout Standard
3248 Some search paths or parts of them are determined by configure variables
3249  (in 
3250 \emph on
3251 italics
3252 \emph default
3253 , see section above).
3254  Further search paths are determined by environment variables during runtime.
3255  
3256 \newline
3257 The paths searched when running the compiler are as follows (the first
3258  catch wins):
3259 \newline
3260
3261 \newline
3262 1.
3263  Binary files (preprocessor, assembler and linker)
3264 \newline
3265
3266 \end_layout
3267
3268 \begin_layout Standard
3269 \align center
3270 \begin_inset Tabular
3271 <lyxtabular version="3" rows="4" columns="3">
3272 <features>
3273 <column alignment="block" valignment="top" leftline="true" width="0in">
3274 <column alignment="block" valignment="top" leftline="true" width="0in">
3275 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3276 <row topline="true" bottomline="true">
3277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3278 \begin_inset Text
3279
3280 \begin_layout Standard
3281 Search path
3282 \end_layout
3283
3284 \end_inset
3285 </cell>
3286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3287 \begin_inset Text
3288
3289 \begin_layout Standard
3290 default
3291 \end_layout
3292
3293 \end_inset
3294 </cell>
3295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3296 \begin_inset Text
3297
3298 \begin_layout Standard
3299 Win32 builds
3300 \end_layout
3301
3302 \end_inset
3303 </cell>
3304 </row>
3305 <row topline="true">
3306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3307 \begin_inset Text
3308
3309 \begin_layout Standard
3310 $SDCC_HOME/
3311 \emph on
3312 $PPREFIX2BIN_DIR
3313 \end_layout
3314
3315 \end_inset
3316 </cell>
3317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3318 \begin_inset Text
3319
3320 \begin_layout Standard
3321 $SDCC_HOME/bin
3322 \end_layout
3323
3324 \end_inset
3325 </cell>
3326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3327 \begin_inset Text
3328
3329 \begin_layout Standard
3330 $SDCC_HOME
3331 \backslash
3332 bin
3333 \end_layout
3334
3335 \end_inset
3336 </cell>
3337 </row>
3338 <row topline="true">
3339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3340 \begin_inset Text
3341
3342 \begin_layout Standard
3343 Path of argv[0] (if available)
3344 \end_layout
3345
3346 \end_inset
3347 </cell>
3348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3349 \begin_inset Text
3350
3351 \begin_layout Standard
3352 Path of argv[0]
3353 \end_layout
3354
3355 \end_inset
3356 </cell>
3357 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3358 \begin_inset Text
3359
3360 \begin_layout Standard
3361 Path of argv[0]
3362 \end_layout
3363
3364 \end_inset
3365 </cell>
3366 </row>
3367 <row topline="true" bottomline="true">
3368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3369 \begin_inset Text
3370
3371 \begin_layout Standard
3372 $PATH
3373 \end_layout
3374
3375 \end_inset
3376 </cell>
3377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3378 \begin_inset Text
3379
3380 \begin_layout Standard
3381 $PATH
3382 \end_layout
3383
3384 \end_inset
3385 </cell>
3386 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3387 \begin_inset Text
3388
3389 \begin_layout Standard
3390 $PATH
3391 \end_layout
3392
3393 \end_inset
3394 </cell>
3395 </row>
3396 </lyxtabular>
3397
3398 \end_inset
3399
3400  
3401 \newline
3402
3403 \end_layout
3404
3405 \begin_layout Standard
3406 \noindent
3407 2.
3408  Include files
3409 \newline
3410
3411 \end_layout
3412
3413 \begin_layout Standard
3414 \align center
3415 \begin_inset Tabular
3416 <lyxtabular version="3" rows="6" columns="3">
3417 <features>
3418 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3419 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3420 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3421 <row topline="true" bottomline="true">
3422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3423 \begin_inset Text
3424
3425 \begin_layout Standard
3426 Search path
3427 \end_layout
3428
3429 \end_inset
3430 </cell>
3431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3432 \begin_inset Text
3433
3434 \begin_layout Standard
3435 default
3436 \end_layout
3437
3438 \end_inset
3439 </cell>
3440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3441 \begin_inset Text
3442
3443 \begin_layout Standard
3444 Win32 builds
3445 \end_layout
3446
3447 \end_inset
3448 </cell>
3449 </row>
3450 <row topline="true">
3451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3452 \begin_inset Text
3453
3454 \begin_layout Standard
3455 -
3456 \begin_inset ERT
3457 status collapsed
3458
3459 \begin_layout Standard
3460
3461
3462 \backslash
3463 /
3464 \end_layout
3465
3466 \end_inset
3467
3468 -I dir
3469 \end_layout
3470
3471 \end_inset
3472 </cell>
3473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3474 \begin_inset Text
3475
3476 \begin_layout Standard
3477 -
3478 \begin_inset ERT
3479 status collapsed
3480
3481 \begin_layout Standard
3482
3483
3484 \backslash
3485 /
3486 \end_layout
3487
3488 \end_inset
3489
3490 -I dir
3491 \end_layout
3492
3493 \end_inset
3494 </cell>
3495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3496 \begin_inset Text
3497
3498 \begin_layout Standard
3499 -
3500 \begin_inset ERT
3501 status collapsed
3502
3503 \begin_layout Standard
3504
3505
3506 \backslash
3507 /
3508 \end_layout
3509
3510 \end_inset
3511
3512 -I dir
3513 \end_layout
3514
3515 \end_inset
3516 </cell>
3517 </row>
3518 <row topline="true">
3519 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3520 \begin_inset Text
3521
3522 \begin_layout Standard
3523 $SDCC_INCLUDE
3524 \end_layout
3525
3526 \end_inset
3527 </cell>
3528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3529 \begin_inset Text
3530
3531 \begin_layout Standard
3532 $SDCC_INCLUDE
3533 \end_layout
3534
3535 \end_inset
3536 </cell>
3537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3538 \begin_inset Text
3539
3540 \begin_layout Standard
3541 $SDCC_INCLUDE
3542 \end_layout
3543
3544 \end_inset
3545 </cell>
3546 </row>
3547 <row topline="true">
3548 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3549 \begin_inset Text
3550
3551 \begin_layout Standard
3552 $SDCC_HOME/
3553 \newline
3554
3555 \emph on
3556 $PREFIX2DATA_DIR/
3557 \newline
3558 $INCLUDE_DIR_SUFFIX
3559 \end_layout
3560
3561 \end_inset
3562 </cell>
3563 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3564 \begin_inset Text
3565
3566 \begin_layout Standard
3567 $SDCC_ HOME/
3568 \newline
3569 share/sdcc/
3570 \newline
3571 include
3572 \end_layout
3573
3574 \end_inset
3575 </cell>
3576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3577 \begin_inset Text
3578
3579 \begin_layout Standard
3580 $SDCC_HOME
3581 \backslash
3582 include
3583 \end_layout
3584
3585 \end_inset
3586 </cell>
3587 </row>
3588 <row topline="true">
3589 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3590 \begin_inset Text
3591
3592 \begin_layout Standard
3593 path(argv[0])/
3594 \newline
3595
3596 \emph on
3597 $BIN2DATADIR/
3598 \emph default
3599
3600 \newline
3601
3602 \emph on
3603 $INCLUDE_DIR_SUFFIX
3604 \end_layout
3605
3606 \end_inset
3607 </cell>
3608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3609 \begin_inset Text
3610
3611 \begin_layout Standard
3612 path(argv[0])/
3613 \newline
3614 ../sdcc/include
3615 \newline
3616 \InsetSpace ~
3617 \InsetSpace ~
3618 \InsetSpace ~
3619 \InsetSpace ~
3620 \InsetSpace ~
3621 \InsetSpace ~
3622 \InsetSpace ~
3623 \InsetSpace ~
3624 \InsetSpace ~
3625 \InsetSpace ~
3626 \InsetSpace ~
3627 \InsetSpace ~
3628 \InsetSpace ~
3629 \InsetSpace ~
3630 \InsetSpace ~
3631 \InsetSpace ~
3632 \InsetSpace ~
3633 \InsetSpace ~
3634 \InsetSpace ~
3635 \InsetSpace ~
3636 \InsetSpace ~
3637 \InsetSpace ~
3638 \InsetSpace ~
3639 \InsetSpace ~
3640 \InsetSpace ~
3641 \InsetSpace ~
3642 \InsetSpace ~
3643 \InsetSpace ~
3644 \InsetSpace ~
3645 \InsetSpace ~
3646 \InsetSpace ~
3647 \InsetSpace ~
3648 \InsetSpace ~
3649 \InsetSpace ~
3650 \InsetSpace ~
3651 \InsetSpace ~
3652 \InsetSpace ~
3653 \InsetSpace ~
3654
3655 \end_layout
3656
3657 \end_inset
3658 </cell>
3659 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3660 \begin_inset Text
3661
3662 \begin_layout Standard
3663 path(argv[0])
3664 \backslash
3665 ..
3666 \backslash
3667 include
3668 \end_layout
3669
3670 \end_inset
3671 </cell>
3672 </row>
3673 <row topline="true" bottomline="true">
3674 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3675 \begin_inset Text
3676
3677 \begin_layout Standard
3678
3679 \emph on
3680 $DATADIR/
3681 \emph default
3682
3683 \newline
3684
3685 \emph on
3686 $INCLUDE_DIR_SUFFIX
3687 \end_layout
3688
3689 \end_inset
3690 </cell>
3691 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3692 \begin_inset Text
3693
3694 \begin_layout Standard
3695 /usr/local/share/sdcc/
3696 \newline
3697 include
3698 \end_layout
3699
3700 \end_inset
3701 </cell>
3702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3703 \begin_inset Text
3704
3705 \begin_layout Standard
3706 (not on Win32)
3707 \end_layout
3708
3709 \end_inset
3710 </cell>
3711 </row>
3712 </lyxtabular>
3713
3714 \end_inset
3715
3716  
3717 \newline
3718
3719 \end_layout
3720
3721 \begin_layout Standard
3722 \noindent
3723 The option -
3724 \begin_inset ERT
3725 status collapsed
3726
3727 \begin_layout Standard
3728
3729
3730 \backslash
3731 /
3732 \end_layout
3733
3734 \end_inset
3735
3736 -nostdinc disables the last two search paths.
3737 \newline
3738
3739 \newline
3740 3.
3741  Library files 
3742 \newline
3743
3744 \end_layout
3745
3746 \begin_layout Standard
3747 With the exception of 
3748 \begin_inset Quotes sld
3749 \end_inset
3750
3751 -
3752 \begin_inset ERT
3753 status collapsed
3754
3755 \begin_layout Standard
3756
3757
3758 \backslash
3759 /
3760 \end_layout
3761
3762 \end_inset
3763
3764 -L dir
3765 \begin_inset Quotes srd
3766 \end_inset
3767
3768  the 
3769 \shape italic
3770 model
3771 \shape default
3772  is auto-appended by the compiler (e.g.
3773  small, large, z80, ds390 etc.).
3774  
3775 \newline
3776
3777 \end_layout
3778
3779 \begin_layout Standard
3780 \align center
3781 \begin_inset Tabular
3782 <lyxtabular version="3" rows="6" columns="3">
3783 <features>
3784 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3785 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3786 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3787 <row topline="true" bottomline="true">
3788 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3789 \begin_inset Text
3790
3791 \begin_layout Standard
3792 Search path
3793 \end_layout
3794
3795 \end_inset
3796 </cell>
3797 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3798 \begin_inset Text
3799
3800 \begin_layout Standard
3801 default
3802 \end_layout
3803
3804 \end_inset
3805 </cell>
3806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3807 \begin_inset Text
3808
3809 \begin_layout Standard
3810 Win32 builds
3811 \end_layout
3812
3813 \end_inset
3814 </cell>
3815 </row>
3816 <row topline="true">
3817 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3818 \begin_inset Text
3819
3820 \begin_layout Standard
3821 -
3822 \begin_inset ERT
3823 status collapsed
3824
3825 \begin_layout Standard
3826
3827
3828 \backslash
3829 /
3830 \end_layout
3831
3832 \end_inset
3833
3834 -L dir
3835 \end_layout
3836
3837 \end_inset
3838 </cell>
3839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3840 \begin_inset Text
3841
3842 \begin_layout Standard
3843 -
3844 \begin_inset ERT
3845 status collapsed
3846
3847 \begin_layout Standard
3848
3849
3850 \backslash
3851 /
3852 \end_layout
3853
3854 \end_inset
3855
3856 -L dir
3857 \end_layout
3858
3859 \end_inset
3860 </cell>
3861 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3862 \begin_inset Text
3863
3864 \begin_layout Standard
3865 -
3866 \begin_inset ERT
3867 status collapsed
3868
3869 \begin_layout Standard
3870
3871
3872 \backslash
3873 /
3874 \end_layout
3875
3876 \end_inset
3877
3878 -L dir
3879 \end_layout
3880
3881 \end_inset
3882 </cell>
3883 </row>
3884 <row topline="true">
3885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3886 \begin_inset Text
3887
3888 \begin_layout Standard
3889 $SDCC_LIB/
3890 \newline
3891
3892 \emph on
3893 <model>
3894 \end_layout
3895
3896 \end_inset
3897 </cell>
3898 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3899 \begin_inset Text
3900
3901 \begin_layout Standard
3902 $SDCC_LIB/
3903 \newline
3904
3905 \emph on
3906 <model>
3907 \end_layout
3908
3909 \end_inset
3910 </cell>
3911 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3912 \begin_inset Text
3913
3914 \begin_layout Standard
3915 $SDCC_LIB
3916 \backslash
3917
3918 \newline
3919
3920 \emph on
3921 <model>
3922 \end_layout
3923
3924 \end_inset
3925 </cell>
3926 </row>
3927 <row topline="true">
3928 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3929 \begin_inset Text
3930
3931 \begin_layout Standard
3932 $SDCC_HOME/
3933 \newline
3934
3935 \emph on
3936 $PREFIX2DATA_DIR/
3937 \newline
3938 $LIB_DIR_SUFFIX/<model>
3939 \end_layout
3940
3941 \end_inset
3942 </cell>
3943 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3944 \begin_inset Text
3945
3946 \begin_layout Standard
3947 $SDCC_HOME/
3948 \newline
3949 share/sdcc/
3950 \newline
3951 lib/
3952 \emph on
3953 <model>
3954 \end_layout
3955
3956 \end_inset
3957 </cell>
3958 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3959 \begin_inset Text
3960
3961 \begin_layout Standard
3962 $SDCC_HOME
3963 \backslash
3964 lib
3965 \backslash
3966
3967 \emph on
3968
3969 \newline
3970 <model>
3971 \end_layout
3972
3973 \end_inset
3974 </cell>
3975 </row>
3976 <row topline="true">
3977 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3978 \begin_inset Text
3979
3980 \begin_layout Standard
3981 path(argv[0])/
3982 \newline
3983
3984 \emph on
3985 $BIN2DATADIR/
3986 \emph default
3987
3988 \newline
3989
3990 \emph on
3991 $LIB_DIR_SUFFIX/<model>
3992 \end_layout
3993
3994 \end_inset
3995 </cell>
3996 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3997 \begin_inset Text
3998
3999 \begin_layout Standard
4000 path(argv[0])/
4001 \newline
4002 ../sdcc/lib/
4003 \emph on
4004 <model>
4005 \newline
4006 \InsetSpace ~
4007 \InsetSpace ~
4008 \InsetSpace ~
4009 \InsetSpace ~
4010 \InsetSpace ~
4011 \InsetSpace ~
4012 \InsetSpace ~
4013 \InsetSpace ~
4014 \InsetSpace ~
4015 \InsetSpace ~
4016 \InsetSpace ~
4017 \InsetSpace ~
4018 \InsetSpace ~
4019 \InsetSpace ~
4020 \InsetSpace ~
4021 \InsetSpace ~
4022 \InsetSpace ~
4023 \InsetSpace ~
4024 \InsetSpace ~
4025 \InsetSpace ~
4026 \InsetSpace ~
4027 \InsetSpace ~
4028 \InsetSpace ~
4029 \InsetSpace ~
4030 \InsetSpace ~
4031 \InsetSpace ~
4032 \InsetSpace ~
4033 \InsetSpace ~
4034 \InsetSpace ~
4035 \InsetSpace ~
4036 \InsetSpace ~
4037 \InsetSpace ~
4038 \InsetSpace ~
4039 \InsetSpace ~
4040 \InsetSpace ~
4041 \InsetSpace ~
4042 \InsetSpace ~
4043 \InsetSpace ~
4044 \InsetSpace ~
4045
4046 \end_layout
4047
4048 \end_inset
4049 </cell>
4050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4051 \begin_inset Text
4052
4053 \begin_layout Standard
4054 path(argv[0])
4055 \backslash
4056
4057 \newline
4058 ..
4059 \backslash
4060 lib
4061 \backslash
4062
4063 \emph on
4064 <model>
4065 \newline
4066 \InsetSpace ~
4067 \InsetSpace ~
4068 \InsetSpace ~
4069 \InsetSpace ~
4070 \InsetSpace ~
4071 \InsetSpace ~
4072 \InsetSpace ~
4073 \InsetSpace ~
4074 \InsetSpace ~
4075 \InsetSpace ~
4076 \InsetSpace ~
4077 \InsetSpace ~
4078 \InsetSpace ~
4079 \InsetSpace ~
4080 \InsetSpace ~
4081 \InsetSpace ~
4082 \InsetSpace ~
4083 \InsetSpace ~
4084 \InsetSpace ~
4085 \InsetSpace ~
4086 \InsetSpace ~
4087 \InsetSpace ~
4088 \InsetSpace ~
4089 \InsetSpace ~
4090 \InsetSpace ~
4091 \InsetSpace ~
4092 \InsetSpace ~
4093 \InsetSpace ~
4094 \InsetSpace ~
4095 \InsetSpace ~
4096 \InsetSpace ~
4097 \InsetSpace ~
4098 \InsetSpace ~
4099 \InsetSpace ~
4100 \InsetSpace ~
4101
4102 \end_layout
4103
4104 \end_inset
4105 </cell>
4106 </row>
4107 <row topline="true" bottomline="true">
4108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4109 \begin_inset Text
4110
4111 \begin_layout Standard
4112
4113 \emph on
4114 $DATADIR/
4115 \newline
4116 $LIB_DIR_SUFFIX/<model>
4117 \end_layout
4118
4119 \end_inset
4120 </cell>
4121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4122 \begin_inset Text
4123
4124 \begin_layout Standard
4125 /usr/local/share/sdcc/
4126 \newline
4127 lib/
4128 \emph on
4129 <model>
4130 \end_layout
4131
4132 \end_inset
4133 </cell>
4134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4135 \begin_inset Text
4136
4137 \begin_layout Standard
4138 (not on Win32)
4139 \end_layout
4140
4141 \end_inset
4142 </cell>
4143 </row>
4144 </lyxtabular>
4145
4146 \end_inset
4147
4148
4149 \newline
4150
4151 \end_layout
4152
4153 \begin_layout Standard
4154 \begin_inset Note Note
4155 status collapsed
4156
4157 \begin_layout Standard
4158 Don't delete any of the stray spaces in the table above without checking
4159  the HTML output (last line)!
4160 \end_layout
4161
4162 \end_inset
4163
4164
4165 \end_layout
4166
4167 \begin_layout Standard
4168 \InsetSpace ~
4169
4170 \newline
4171 The option -
4172 \begin_inset ERT
4173 status collapsed
4174
4175 \begin_layout Standard
4176
4177
4178 \backslash
4179 /
4180 \end_layout
4181
4182 \end_inset
4183
4184 -nostdlib disables the last two search paths.
4185 \end_layout
4186
4187 \begin_layout Section
4188 Building SDCC
4189 \begin_inset LatexCommand index
4190 name "Building SDCC"
4191
4192 \end_inset
4193
4194
4195 \end_layout
4196
4197 \begin_layout Subsection
4198 Building SDCC on Linux
4199 \begin_inset LatexCommand label
4200 name "sub:Building-SDCC-on-Linux"
4201
4202 \end_inset
4203
4204
4205 \end_layout
4206
4207 \begin_layout Enumerate
4208
4209 \series medium
4210 Download the source package
4211 \series default
4212  either from the SDCC Subversion repository or from snapshot builds
4213 \series medium
4214 , it will be named something like sdcc
4215 \series default
4216 -src
4217 \series medium
4218 -yyyymmdd-rrrr.t
4219 \series default
4220 ar.
4221 \series medium
4222 bz2
4223 \series default
4224  
4225 \begin_inset LatexCommand url
4226 target "http://sdcc.sourceforge.net/snap.php"
4227
4228 \end_inset
4229
4230 .
4231 \end_layout
4232
4233 \begin_layout Enumerate
4234
4235 \series medium
4236 Bring up a command line terminal, such as xterm.
4237 \end_layout
4238
4239 \begin_layout Enumerate
4240
4241 \series medium
4242 Unpack the file using a command like:
4243 \series default
4244  
4245 \family sans
4246 \series bold
4247 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
4248 \begin_inset Quotes srd
4249 \end_inset
4250
4251
4252 \family default
4253 \series medium
4254 , this will create a sub-directory called sdcc with all of the sources.
4255 \end_layout
4256
4257 \begin_layout Enumerate
4258 Change directory into the main SDCC directory, for example type: 
4259 \family sans
4260 \series bold
4261 "cd sdcc
4262 \series default
4263 ".
4264 \end_layout
4265
4266 \begin_layout Enumerate
4267
4268 \series medium
4269 Type
4270 \series default
4271  
4272 \family sans
4273 \series bold
4274 "./configure
4275 \family default
4276 \series default
4277 ".
4278  This configures the package for compilation on your system.
4279 \end_layout
4280
4281 \begin_layout Enumerate
4282
4283 \series medium
4284 Type
4285 \series default
4286  
4287 \family sans
4288 \series bold
4289 "make
4290 \family default
4291 \series default
4292 "
4293 \series medium
4294 .
4295
4296 \series default
4297  All of the source packages will compile, this can take a while.
4298 \end_layout
4299
4300 \begin_layout Enumerate
4301
4302 \series medium
4303 Type
4304 \series default
4305  
4306 \family sans
4307 \series bold
4308 "make install"
4309 \family default
4310 \series default
4311  as root
4312 \series medium
4313 .
4314
4315 \series default
4316  This copies the binary executables, the include files, the libraries and
4317  the documentation to the install directories.
4318  Proceed with section 
4319 \begin_inset LatexCommand ref
4320 reference "sec:Testing-the-SDCC"
4321
4322 \end_inset
4323
4324 .
4325 \end_layout
4326
4327 \begin_layout Subsection
4328 Building SDCC on Mac OS X
4329 \end_layout
4330
4331 \begin_layout Standard
4332 Follow the instruction for Linux.
4333 \newline
4334
4335 \newline
4336 On Mac OS X 10.2.x it was reported, that the
4337  default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
4338  Fortunately there's also gcc 2.9.x installed, which works fine.
4339  This compiler can be selected by running 'configure' with:
4340 \end_layout
4341
4342 \begin_layout LyX-Code
4343 ./configure CC=gcc2 CXX=g++2
4344 \end_layout
4345
4346 \begin_layout Standard
4347 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
4348  Xcode.
4349  Run 'configure' with:
4350 \end_layout
4351
4352 \begin_layout LyX-Code
4353 ./configure 
4354 \backslash
4355
4356 \end_layout
4357
4358 \begin_layout LyX-Code
4359 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4360  ppc" 
4361 \backslash
4362
4363 \end_layout
4364
4365 \begin_layout LyX-Code
4366 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4367  ppc" 
4368 \backslash
4369
4370 \end_layout
4371
4372 \begin_layout LyX-Code
4373 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
4374 \end_layout
4375
4376 \begin_layout Subsection
4377 Cross compiling SDCC on Linux for Windows
4378 \end_layout
4379
4380 \begin_layout Standard
4381 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
4382  See section 'Configure Options'.
4383 \end_layout
4384
4385 \begin_layout Subsection
4386 Building SDCC using Cygwin and Mingw32
4387 \end_layout
4388
4389 \begin_layout Standard
4390 For building and installing a Cygwin executable follow the instructions
4391  for Linux.
4392 \newline
4393
4394 \newline
4395 On Cygwin a 
4396 \begin_inset Quotes sld
4397 \end_inset
4398
4399 native
4400 \begin_inset Quotes srd
4401 \end_inset
4402
4403  Win32-binary can be built, which will not need the Cygwin-DLL.
4404  For the necessary 'configure' options see section 'configure options' or
4405  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4406 \newline
4407
4408 \newline
4409 In order to install
4410  Cygwin on Windows download setup.exe from 
4411 \begin_inset LatexCommand url
4412 name "www.cygwin.com"
4413 target "http://www.cygwin.com/"
4414
4415 \end_inset
4416
4417 .
4418  Run it, set the 
4419 \begin_inset Quotes sld
4420 \end_inset
4421
4422 default text file type
4423 \begin_inset Quotes srd
4424 \end_inset
4425
4426  to 
4427 \begin_inset Quotes sld
4428 \end_inset
4429
4430 unix
4431 \begin_inset Quotes srd
4432 \end_inset
4433
4434  and download/install at least the following packages.
4435  Some packages are selected by default, others will be automatically selected
4436  because of dependencies with the manually selected packages.
4437  Never deselect these packages!
4438 \end_layout
4439
4440 \begin_layout Itemize
4441 flex
4442 \end_layout
4443
4444 \begin_layout Itemize
4445 bison
4446 \end_layout
4447
4448 \begin_layout Itemize
4449 gcc ; version 3.x is fine, no need to use the old 2.9x
4450 \end_layout
4451
4452 \begin_layout Itemize
4453 binutils ; selected with gcc
4454 \end_layout
4455
4456 \begin_layout Itemize
4457 make
4458 \end_layout
4459
4460 \begin_layout Itemize
4461 rxvt ; a nice console, which makes life much easier under windoze (see below)
4462 \end_layout
4463
4464 \begin_layout Itemize
4465 man ; not really needed for building SDCC, but you'll miss it sooner or
4466  later
4467 \end_layout
4468
4469 \begin_layout Itemize
4470 less ; not really needed for building SDCC, but you'll miss it sooner or
4471  later
4472 \end_layout
4473
4474 \begin_layout Itemize
4475 svn ; only if you use Subversion access
4476 \end_layout
4477
4478 \begin_layout Standard
4479 If you want to develop something you'll need:
4480 \end_layout
4481
4482 \begin_layout Itemize
4483 python ; for the regression tests
4484 \end_layout
4485
4486 \begin_layout Itemize
4487 gdb ; the gnu debugger, together with the nice GUI 
4488 \begin_inset Quotes sld
4489 \end_inset
4490
4491 insight
4492 \begin_inset Quotes srd
4493 \end_inset
4494
4495
4496 \end_layout
4497
4498 \begin_layout Itemize
4499 openssh ; to access the CF or commit changes
4500 \end_layout
4501
4502 \begin_layout Itemize
4503 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4504  use autoconf-stable!
4505 \end_layout
4506
4507 \begin_layout Standard
4508 rxvt is a nice console with history.
4509  Replace in your cygwin.bat the line
4510 \end_layout
4511
4512 \begin_layout LyX-Code
4513 bash -
4514 \begin_inset ERT
4515 status collapsed
4516
4517 \begin_layout Standard
4518
4519
4520 \backslash
4521 /
4522 \end_layout
4523
4524 \end_inset
4525
4526 -login -i 
4527 \end_layout
4528
4529 \begin_layout Standard
4530 with (one line):
4531 \end_layout
4532
4533 \begin_layout LyX-Code
4534 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4535 \end_layout
4536
4537 \begin_layout LyX-Code
4538      -bg black -fg white -geometry 100x65 -e bash -
4539 \begin_inset ERT
4540 status collapsed
4541
4542 \begin_layout Standard
4543
4544
4545 \backslash
4546 /
4547 \end_layout
4548
4549 \end_inset
4550
4551 -login
4552 \end_layout
4553
4554 \begin_layout Standard
4555 Text selected with the mouse is automatically copied to the clipboard, pasting
4556  works with shift-insert.
4557 \newline
4558
4559 \newline
4560 The other good tip is to make sure you have no //c/-styl
4561 e paths anywhere, use /cygdrive/c/ instead.
4562  Using // invokes a network lookup which is very slow.
4563  If you think 
4564 \begin_inset Quotes sld
4565 \end_inset
4566
4567 cygdrive
4568 \begin_inset Quotes srd
4569 \end_inset
4570
4571  is too long, you can change it with e.g.
4572 \end_layout
4573
4574 \begin_layout LyX-Code
4575 mount -s -u -c /mnt
4576 \end_layout
4577
4578 \begin_layout Standard
4579 SDCC sources use the unix line ending LF.
4580  Life is much easier, if you store the source tree on a drive which is mounted
4581  in binary mode.
4582  And use an editor which can handle LF-only line endings.
4583  Make sure not to commit files with windows line endings.
4584  The tabulator spacing
4585 \begin_inset LatexCommand index
4586 name "tabulator spacing (8 columns)"
4587
4588 \end_inset
4589
4590  used in the project is 8.
4591  Although a tabulator spacing of 8 is a sensible choice for programmers
4592  (it's a power of 2 and allows to display 8/16 bit signed variables without
4593  loosing columns) the plan is to move towards using only spaces in the source.
4594 \end_layout
4595
4596 \begin_layout Subsection
4597 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4598 \end_layout
4599
4600 \begin_layout Standard
4601
4602 \series medium
4603 Download the source package
4604 \series default
4605  either from the SDCC Subversion repository or from the 
4606 \begin_inset LatexCommand url
4607 name "snapshot builds"
4608 target "http://sdcc.sourceforge.net/snap.php"
4609
4610 \end_inset
4611
4612
4613 \series medium
4614 , it will be named something like sdcc
4615 \series default
4616 -src
4617 \series medium
4618 -yyyymmdd-rrrr.tar.bz2.
4619
4620 \series default
4621  SDCC is distributed with all the projects, workspaces, and files you need
4622  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4623  The workspace name is 'sdcc.dsw'.
4624  Please note that as it is now, all the executables are created in a folder
4625  called sdcc
4626 \backslash
4627 bin_vc.
4628  Once built you need to copy the executables from sdcc
4629 \backslash
4630 bin_vc to sdcc
4631 \backslash
4632 bin before running SDCC.
4633  
4634 \newline
4635
4636 \newline
4637 WARNING: Visual studio is very picky with line terminations; it expects
4638  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4639  When using the Subversion repository it's easiest to configure the svn
4640  client to convert automatically for you.
4641  If however you are getting a message such as "This makefile was not generated
4642  by Developer Studio etc.
4643  etc.
4644 \begin_inset Quotes srd
4645 \end_inset
4646
4647  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4648  need to convert the Unix style line endings to DOS style line endings.
4649  To do so you can use the 
4650 \begin_inset Quotes sld
4651 \end_inset
4652
4653 unix2dos
4654 \begin_inset Quotes srd
4655 \end_inset
4656
4657  utility freely available on the internet.
4658  Doug Hawkins reported in the sdcc-user list that this works:
4659 \newline
4660
4661 \newline
4662 C:
4663 \backslash
4664 Programming
4665 \backslash
4666 SDCC> unix2dos sdcc.dsw
4667 \newline
4668 C:
4669 \backslash
4670 Programming
4671 \backslash
4672 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4673 \newline
4674
4675 \newline
4676 In order to build SDCC with MSVC
4677  you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4678  One good place to get them is 
4679 \begin_inset LatexCommand url
4680 name "here"
4681 target "http://unxutils.sourceforge.net"
4682
4683 \end_inset
4684
4685
4686 \newline
4687
4688 \newline
4689 Download the file UnxUtils
4690 \begin_inset LatexCommand index
4691 name "UnxUtils"
4692
4693 \end_inset
4694
4695 .zip.
4696  Now you have to install the utilities and setup MSVC so it can locate the
4697  required programs.
4698  Here there are two alternatives (choose one!):
4699 \end_layout
4700
4701 \begin_layout Enumerate
4702 The easy way:
4703 \newline
4704
4705 \newline
4706 a) Extract UnxUtils.zip to your C:
4707 \backslash
4708  hard disk PRESERVING the original paths, otherwise bison won't work.
4709  (If you are using WinZip make certain that 'Use folder names' is selected)
4710 \newline
4711
4712 \newline
4713 b)
4714  In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4715  'Show directories for:' select 'Executable files', and in the directories
4716  window add a new path: 'C:
4717 \backslash
4718 user
4719 \backslash
4720 local
4721 \backslash
4722 wbin', click ok.
4723 \newline
4724
4725 \newline
4726 (As a side effect, you get a bunch of Unix utilities that
4727  could be useful, such as diff and patch.)
4728 \end_layout
4729
4730 \begin_layout Enumerate
4731 A more compact way:
4732 \newline
4733
4734 \newline
4735 This one avoids extracting a bunch of files you may not
4736  use, but requires some extra work:
4737 \newline
4738
4739 \newline
4740 a) Create a directory were to put the
4741  tools needed, or use a directory already present.
4742  Say for example 'C:
4743 \backslash
4744 util'.
4745 \newline
4746
4747 \newline
4748 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4749  gawk.exe to such directory WITHOUT preserving the original paths.
4750  (If you are using WinZip make certain that 'Use folder names' is not selected)
4751 \newline
4752
4753 \newline
4754 c
4755 ) Rename bison.exe to '_bison.exe'.
4756 \newline
4757
4758 \newline
4759 d) Create a batch file 'bison.bat' in 'C:
4760 \backslash
4761 util
4762 \backslash
4763 ' and add these lines: 
4764 \newline
4765 \InsetSpace ~
4766 \InsetSpace ~
4767 set BISON_SIMPLE=C:
4768 \backslash
4769 util
4770 \backslash
4771 bison.simple 
4772 \newline
4773 \InsetSpace ~
4774 \InsetSpace ~
4775 set BISON_HAIRY=C:
4776 \backslash
4777 util
4778 \backslash
4779 bison.hairy
4780 \newline
4781 \InsetSpace ~
4782 \InsetSpace ~
4783 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4784 \newline
4785
4786 \newline
4787 Steps 'c' and 'd' are needed
4788  because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4789  reside in some weird Unix directory, '/usr/local/share/' I think.
4790  So it is necessary to tell bison where those files are located if they
4791  are not in such directory.
4792  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4793 \newline
4794
4795 \newline
4796 e
4797 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4798  in 'Show directories for:' select 'Executable files', and in the directories
4799  window add a new path: 'c:
4800 \backslash
4801 util', click ok.
4802  Note that you can use any other path instead of 'c:
4803 \backslash
4804 util', even the path where the Visual C++ tools are, probably: 'C:
4805 \backslash
4806 Program Files
4807 \backslash
4808 Microsoft Visual Studio
4809 \backslash
4810 Common
4811 \backslash
4812 Tools'.
4813  So you don't have to execute step 'e' :)
4814 \end_layout
4815
4816 \begin_layout Standard
4817 That is it.
4818  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4819  the executables from sdcc
4820 \backslash
4821 bin_vc to sdcc
4822 \backslash
4823 bin, and you can compile using SDCC.
4824 \end_layout
4825
4826 \begin_layout Subsection
4827 Building SDCC Using Borland
4828 \end_layout
4829
4830 \begin_layout Enumerate
4831 From the sdcc directory, run the command "make -f Makefile.bcc".
4832  This should regenerate all the .exe files in the bin directory except for
4833  SDCDB and ucSim.
4834 \end_layout
4835
4836 \begin_layout Enumerate
4837 If you modify any source files and need to rebuild, be aware that the dependenci
4838 es may not be correctly calculated.
4839  The safest option is to delete all .obj files and run the build again.
4840  From a Cygwin BASH prompt, this can easily be done with the command (be
4841  sure you are in the sdcc directory):
4842 \newline
4843
4844 \newline
4845
4846 \family sans
4847 \series bold
4848 find .
4849  
4850 \backslash
4851 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
4852 \backslash
4853 ) -print -exec rm {} 
4854 \backslash
4855 ;
4856 \family default
4857 \series default
4858
4859 \newline
4860
4861 \newline
4862 or on Windows NT/2000/XP from the command prompt with the command:
4863 \newline
4864
4865 \family sans
4866 \series bold
4867
4868 \newline
4869 del /s *.obj *.lib *.rul
4870 \family default
4871 \series default
4872  from the sdcc directory.
4873 \end_layout
4874
4875 \begin_layout Subsection
4876 Windows Install Using a ZIP Package
4877 \end_layout
4878
4879 \begin_layout Enumerate
4880 Download the binary zip package from 
4881 \begin_inset LatexCommand url
4882 target "http://sdcc.sf.net/snap.php"
4883
4884 \end_inset
4885
4886  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4887  This should unpack to a group of sub-directories.
4888  An example directory structure after unpacking the mingw32 package is:
4889  c:
4890 \backslash
4891 sdcc
4892 \backslash
4893 bin for the executables, c:
4894 \backslash
4895 sdcc
4896 \backslash
4897 include and c:
4898 \backslash
4899 sdcc
4900 \backslash
4901 lib for the include and libraries.
4902 \end_layout
4903
4904 \begin_layout Enumerate
4905 Adjust your environment variable PATH to include the location of the bin
4906  directory or start sdcc using the full path.
4907 \end_layout
4908
4909 \begin_layout Subsection
4910 Windows Install Using the Setup Program
4911 \begin_inset LatexCommand label
4912 name "sub:Windows-Install"
4913
4914 \end_inset
4915
4916
4917 \end_layout
4918
4919 \begin_layout Standard
4920 Download the setup program 
4921 \emph on
4922 sdcc-x.y.z-setup.exe
4923 \emph default
4924  for an official release from 
4925 \newline
4926
4927 \begin_inset LatexCommand url
4928 target "http://sf.net/project/showfiles.php?group_id=599"
4929
4930 \end_inset
4931
4932  or a setup program for one of the snapshots 
4933 \emph on
4934 sdcc-yyyymmdd-xxxx-setup.exe
4935 \emph default
4936  from 
4937 \begin_inset LatexCommand url
4938 target "http://sdcc.sf.net/snap.php"
4939
4940 \end_inset
4941
4942  and execute it.
4943  A windows typical installer will guide you through the installation process.
4944 \end_layout
4945
4946 \begin_layout Subsection
4947 VPATH
4948 \begin_inset LatexCommand index
4949 name "VPATH"
4950
4951 \end_inset
4952
4953  feature
4954 \end_layout
4955
4956 \begin_layout Standard
4957 SDCC supports the VPATH feature provided by configure and make.
4958  It allows to separate the source and build trees.
4959  Here's an example:
4960 \end_layout
4961
4962 \begin_layout Standard
4963
4964 \family typewriter
4965 cd ~\InsetSpace ~
4966 \InsetSpace ~
4967 \InsetSpace ~
4968 \InsetSpace ~
4969 \InsetSpace ~
4970 \InsetSpace ~
4971 \InsetSpace ~
4972 \InsetSpace ~
4973 \InsetSpace ~
4974 \InsetSpace ~
4975 \InsetSpace ~
4976 \InsetSpace ~
4977 \InsetSpace ~
4978 \InsetSpace ~
4979 \InsetSpace ~
4980 \InsetSpace ~
4981 \InsetSpace ~
4982 \InsetSpace ~
4983 \InsetSpace ~
4984 \InsetSpace ~
4985 \InsetSpace ~
4986 # cd $HOME
4987 \end_layout
4988
4989 \begin_layout Standard
4990
4991 \family typewriter
4992 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4993 # extract source to directory sdcc
4994 \end_layout
4995
4996 \begin_layout Standard
4997
4998 \family typewriter
4999 mkdir sdcc.build\InsetSpace ~
5000 \InsetSpace ~
5001 \InsetSpace ~
5002 \InsetSpace ~
5003 \InsetSpace ~
5004 \InsetSpace ~
5005 \InsetSpace ~
5006 \InsetSpace ~
5007 \InsetSpace ~
5008 # put output in sdcc.build
5009 \end_layout
5010
5011 \begin_layout Standard
5012
5013 \family typewriter
5014 cd sdcc.build
5015 \end_layout
5016
5017 \begin_layout Standard
5018
5019 \family typewriter
5020 ../sdcc/configure\InsetSpace ~
5021 \InsetSpace ~
5022 \InsetSpace ~
5023 \InsetSpace ~
5024 \InsetSpace ~
5025 \InsetSpace ~
5026 \InsetSpace ~
5027 \InsetSpace ~
5028 # configure is doing all the magic!
5029 \end_layout
5030
5031 \begin_layout Standard
5032
5033 \family typewriter
5034 make
5035 \end_layout
5036
5037 \begin_layout Standard
5038 \noindent
5039 That's it! 
5040 \series bold
5041 configure
5042 \series default
5043  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
5044  It automagically computes the variables srcdir, top_srcdir and top_buildir
5045  for each directory.
5046  After running 
5047 \series bold
5048 make
5049 \series default
5050  the generated files will be in ~/sdcc.build, while the source files stay
5051  in ~/sdcc.
5052 \newline
5053 This is not only usefull for building different binaries, e.g.
5054  when cross compiling.
5055  It also gives you a much better overview in the source tree when all the
5056  generated files are not scattered between the source files.
5057  And the best thing is: if you want to change a file you can leave the original
5058  file untouched in the source directory.
5059  Simply copy it to the build directory, edit it, enter `make clean', `rm
5060  Makefile.dep' and `make'.
5061  
5062 \series bold
5063 make
5064 \series default
5065  will do the rest for you!
5066 \end_layout
5067
5068 \begin_layout Section
5069 Building the Documentation
5070 \end_layout
5071
5072 \begin_layout Standard
5073 Add -
5074 \begin_inset ERT
5075 status collapsed
5076
5077 \begin_layout Standard
5078
5079
5080 \backslash
5081 /
5082 \end_layout
5083
5084 \end_inset
5085
5086 -enable-doc to the configure arguments to build the documentation together
5087  with all the other stuff.
5088  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
5089  dvips and makeindex) to get the job done.
5090  Another possibility is to change to the doc directory and to type 
5091 \family sans
5092 \series bold
5093
5094 \begin_inset Quotes srd
5095 \end_inset
5096
5097 make
5098 \begin_inset Quotes srd
5099 \end_inset
5100
5101
5102 \family default
5103 \series default
5104  there.
5105  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
5106 x).
5107  Using LyX 
5108 \begin_inset LatexCommand url
5109 target "http://www.lyx.org"
5110
5111 \end_inset
5112
5113  as editor is straightforward.
5114  Prebuilt documentation in html and pdf format is available from 
5115 \begin_inset LatexCommand url
5116 target "http://sdcc.sf.net/snap.php"
5117
5118 \end_inset
5119
5120 .
5121 \end_layout
5122
5123 \begin_layout Section
5124 Reading the Documentation
5125 \begin_inset LatexCommand index
5126 name "Documentation"
5127
5128 \end_inset
5129
5130
5131 \end_layout
5132
5133 \begin_layout Standard
5134 Currently reading the document in pdf format is recommended, as for unknown
5135  reason the hyperlinks are working there whereas in the html version they
5136  are not
5137 \begin_inset Foot
5138 status open
5139
5140 \begin_layout Standard
5141 If you should know why please drop us a note
5142 \end_layout
5143
5144 \end_inset
5145
5146 .
5147  
5148 \newline
5149 You'll find the pdf version
5150 \begin_inset LatexCommand index
5151 name "PDF version of this document"
5152
5153 \end_inset
5154
5155  at 
5156 \begin_inset LatexCommand url
5157 target "http://sdcc.sf.net/doc/sdccman.pdf"
5158
5159 \end_inset
5160
5161 .
5162  
5163 \newline
5164 A html version
5165 \begin_inset LatexCommand index
5166 name "HTML version of this document"
5167
5168 \end_inset
5169
5170  should be online at 
5171 \begin_inset LatexCommand url
5172 target "http://sdcc.sf.net/doc/sdccman.html/index.html"
5173
5174 \end_inset
5175
5176 .
5177 \newline
5178 This documentation is in some aspects different from a commercial documentation:
5179  
5180 \end_layout
5181
5182 \begin_layout Itemize
5183 It tries to document SDCC for several processor architectures in one document
5184  (commercially these probably would be separate documents/products).
5185  This document
5186 \begin_inset LatexCommand index
5187 name "Status of documentation"
5188
5189 \end_inset
5190
5191  currently matches SDCC for mcs51 and DS390 best and does give too few informati
5192 on about f.e.
5193  Z80, PIC14, PIC16 and HC08.
5194 \end_layout
5195
5196 \begin_layout Itemize
5197 There are many references pointing away from this documentation.
5198  Don't let this distract you.
5199  If there f.e.
5200  was a reference like 
5201 \begin_inset LatexCommand url
5202 target "http://www.opencores.org"
5203
5204 \end_inset
5205
5206  together with a statement 
5207 \begin_inset Quotes sld
5208 \end_inset
5209
5210 some processors which are targetted by SDCC can be implemented in a 
5211 \emph on
5212 f
5213 \emph default
5214 ield 
5215 \emph on
5216 p
5217 \emph default
5218 rogrammable 
5219 \emph on
5220 g
5221 \emph default
5222 ate 
5223 \emph on
5224 a
5225 \emph default
5226 rray
5227 \begin_inset LatexCommand index
5228 name "FPGA (field programmable gate array)"
5229
5230 \end_inset
5231
5232
5233 \begin_inset Quotes srd
5234 \end_inset
5235
5236  or 
5237 \begin_inset LatexCommand url
5238 target "http://sf.net/projects/fpgac"
5239
5240 \end_inset
5241
5242
5243 \begin_inset LatexCommand index
5244 name "FpgaC ((subset of) C to FPGA compiler)"
5245
5246 \end_inset
5247
5248  
5249 \begin_inset Quotes sld
5250 \end_inset
5251
5252 have you ever heard of an open source compiler that compiles a subset of
5253  C for an FPGA?
5254 \begin_inset Quotes srd
5255 \end_inset
5256
5257  we expect you to have a quick look there and come back.
5258  If you read this you are on the right track.
5259 \end_layout
5260
5261 \begin_layout Itemize
5262 Some sections attribute more space to problems, restrictions and warnings
5263  than to the solution.
5264 \end_layout
5265
5266 \begin_layout Itemize
5267 The installation section and the section about the debugger is intimidating.
5268 \end_layout
5269
5270 \begin_layout Itemize
5271 There are still lots of typos and there are more different writing styles
5272  than pictures.
5273 \end_layout
5274
5275 \begin_layout Section
5276 Testing the SDCC Compiler
5277 \begin_inset LatexCommand label
5278 name "sec:Testing-the-SDCC"
5279
5280 \end_inset
5281
5282
5283 \end_layout
5284
5285 \begin_layout Standard
5286 The first thing you should do after installing your SDCC compiler is to
5287  see if it runs.
5288  Type 
5289 \family sans
5290 \series bold
5291 "sdcc -
5292 \begin_inset ERT
5293 status collapsed
5294
5295 \begin_layout Standard
5296
5297
5298 \backslash
5299 /
5300 \end_layout
5301
5302 \end_inset
5303
5304 -version"
5305 \begin_inset LatexCommand index
5306 name "version"
5307
5308 \end_inset
5309
5310
5311 \family default
5312 \series default
5313  at the prompt, and the program should run and output its version like:
5314  
5315 \newline
5316
5317 \family typewriter
5318 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
5319  (UNIX)
5320 \end_layout
5321
5322 \begin_layout Standard
5323 If it doesn't run, or gives a message about not finding sdcc program, then
5324  you need to check over your installation.
5325  Make sure that the sdcc bin directory is in your executable search path
5326  defined by the PATH environment setting (
5327 \series medium
5328 see
5329 \series default
5330  section 
5331 \begin_inset LatexCommand ref
5332 reference "sub:Install-Trouble-shooting"
5333
5334 \end_inset
5335
5336 \InsetSpace ~
5337
5338 \series medium
5339 Install trouble-shooting for suggestions
5340 \series default
5341 ).
5342  Make sure that the sdcc program is in the bin folder, if not perhaps something
5343  did not install correctly.
5344 \newline
5345
5346 \newline
5347
5348 \series medium
5349 SDCC
5350 \series default
5351  is commonly installed as described in section 
5352 \begin_inset Quotes sld
5353 \end_inset
5354
5355 Install and search paths
5356 \begin_inset Quotes srd
5357 \end_inset
5358
5359 .
5360 \newline
5361
5362 \newline
5363
5364 \series medium
5365 Make sure the compiler works on a very simple example.
5366  Type in the following test.c program using your favorite
5367 \series default
5368  ASCII 
5369 \series medium
5370 editor:
5371 \end_layout
5372
5373 \begin_layout Verse
5374
5375 \family typewriter
5376 char test;
5377 \newline
5378
5379 \newline
5380 void main(void) {
5381 \newline
5382 \InsetSpace ~
5383 \InsetSpace ~
5384 \InsetSpace ~
5385 \InsetSpace ~
5386 test=0;
5387 \newline
5388 }
5389 \end_layout
5390
5391 \begin_layout Standard
5392
5393 \series medium
5394 Compile this using the following command:
5395 \series default
5396  
5397 \family sans
5398 \series bold
5399 "sdcc -c test.c".
5400
5401 \family default
5402 \series default
5403  
5404 \series medium
5405 If all goes well, the compiler will generate a test.asm and test.rel file.
5406  Congratulations, you've just compiled your first program with SDCC.
5407  We used the -c option to tell SDCC not to link the generated code, just
5408  to keep things simple for this step.
5409 \series default
5410
5411 \newline
5412
5413 \newline
5414
5415 \series medium
5416 The next step is to try it with the linker.
5417  Type in
5418 \series default
5419  
5420 \family sans
5421 \series bold
5422 "sdcc test.c
5423 \family default
5424 \series default
5425 "
5426 \series medium
5427 .
5428  If all goes well the compiler will link with the libraries and produce
5429  a test.ihx output file.
5430  If this step fails
5431 \series default
5432  
5433 \series medium
5434 (no test.ihx, and the linker generates warnings), then the problem is most
5435  likely that
5436 \series default
5437  SDCC 
5438 \series medium
5439 cannot find the
5440 \series default
5441  /
5442 \series medium
5443 usr/local/share/sdcc/lib directory
5444 \series default
5445  
5446 \series medium
5447 (see
5448 \series default
5449  section 
5450 \begin_inset LatexCommand ref
5451 reference "sub:Install-Trouble-shooting"
5452
5453 \end_inset
5454
5455 \InsetSpace ~
5456
5457 \series medium
5458 Install trouble-shooting for suggestions).
5459 \series default
5460
5461 \newline
5462
5463 \newline
5464
5465 \series medium
5466 The final test is to ensure
5467 \series default
5468  SDCC 
5469 \series medium
5470 can use the
5471 \series default
5472  standard 
5473 \series medium
5474 header files and libraries.
5475  Edit test.c and change it to the following:
5476 \end_layout
5477
5478 \begin_layout Verse
5479
5480 \family typewriter
5481 #include <string.h>
5482 \newline
5483
5484 \newline
5485 char str1[10];
5486 \newline
5487
5488 \newline
5489 void main(void) {
5490 \newline
5491 \InsetSpace ~
5492 \InsetSpace ~
5493 strcpy(str1, "testing");
5494 \newline
5495 }
5496 \end_layout
5497
5498 \begin_layout Standard
5499
5500 \series medium
5501 Compile this by typing
5502 \series default
5503  
5504 \family sans
5505 \series bold
5506 "sdcc test.c"
5507 \family default
5508 \series medium
5509 .
5510  This should generate a test.ihx output file, and it should give no warnings
5511  such as not finding the string.h file.
5512  If it cannot find the string.h file, then the problem is that
5513 \series default
5514  SDCC 
5515 \series medium
5516 cannot find the /usr/local/share/sdcc/include directory
5517 \series default
5518  
5519 \series medium
5520 (see the
5521 \series default
5522  section 
5523 \begin_inset LatexCommand ref
5524 reference "sub:Install-Trouble-shooting"
5525
5526 \end_inset
5527
5528 \InsetSpace ~
5529
5530 \series medium
5531 Install trouble-shooting section for suggestions).
5532
5533 \series default
5534  Use option 
5535 \series bold
5536 -
5537 \begin_inset ERT
5538 status collapsed
5539
5540 \begin_layout Standard
5541
5542
5543 \backslash
5544 /
5545 \end_layout
5546
5547 \end_inset
5548
5549 -print-search-dirs
5550 \series default
5551
5552 \begin_inset LatexCommand index
5553 name "-\\/-print-search-dirs"
5554
5555 \end_inset
5556
5557  to find exactly where SDCC is looking for the include and lib files.
5558 \end_layout
5559
5560 \begin_layout Section
5561 Install Trouble-shooting
5562 \begin_inset LatexCommand label
5563 name "sub:Install-Trouble-shooting"
5564
5565 \end_inset
5566
5567
5568 \begin_inset LatexCommand index
5569 name "Install trouble-shooting"
5570
5571 \end_inset
5572
5573
5574 \end_layout
5575
5576 \begin_layout Subsection
5577 If SDCC does not build correctly
5578 \end_layout
5579
5580 \begin_layout Standard
5581 A thing to try is starting from scratch by unpacking the .tgz source package
5582  again in an empty directory.
5583  Configure it like:
5584 \newline
5585
5586 \newline
5587
5588 \family sans
5589 \series bold
5590 ./configure 2>&1 | tee configure.log
5591 \family default
5592 \series default
5593
5594 \newline
5595
5596 \newline
5597 and build it like:
5598 \newline
5599
5600 \newline
5601
5602 \family sans
5603 \series bold
5604 make 2>&1 | tee make.log
5605 \family default
5606 \series default
5607
5608 \newline
5609
5610 \newline
5611 If anything goes wrong, you can review the log files to locate the problem.
5612  Or a relevant part of this can be attached to an email that could be helpful
5613  when requesting help from the mailing list.
5614 \end_layout
5615
5616 \begin_layout Subsection
5617 What the 
5618 \begin_inset Quotes sld
5619 \end_inset
5620
5621 ./configure
5622 \begin_inset Quotes srd
5623 \end_inset
5624
5625  does
5626 \end_layout
5627
5628 \begin_layout Standard
5629 The 
5630 \begin_inset Quotes sld
5631 \end_inset
5632
5633 ./configure
5634 \begin_inset Quotes srd
5635 \end_inset
5636
5637  command is a script that analyzes your system and performs some configuration
5638  to ensure the source package compiles on your system.
5639  It will take a few minutes to run, and will compile a few tests to determine
5640  what compiler features are installed.
5641 \end_layout
5642
5643 \begin_layout Subsection
5644 What the 
5645 \begin_inset Quotes sld
5646 \end_inset
5647
5648 make
5649 \begin_inset Quotes srd
5650 \end_inset
5651
5652  does
5653 \end_layout
5654
5655 \begin_layout Standard
5656 This runs the GNU make tool, which automatically compiles all the source
5657  packages into the final installed binary executables.
5658 \end_layout
5659
5660 \begin_layout Subsection
5661 What the 
5662 \begin_inset Quotes sld
5663 \end_inset
5664
5665 make install
5666 \begin_inset Quotes erd
5667 \end_inset
5668
5669  command does.
5670 \end_layout
5671
5672 \begin_layout Standard
5673 This will install the compiler, other executables libraries and include
5674  files into the appropriate directories.
5675  See sections 
5676 \begin_inset LatexCommand ref
5677 reference "sub:Install-paths"
5678
5679 \end_inset
5680
5681 ,\InsetSpace ~
5682
5683 \begin_inset LatexCommand ref
5684 reference "sub:Search-Paths"
5685
5686 \end_inset
5687
5688 \InsetSpace ~
5689 about install and search paths.
5690 \newline
5691 On most systems you will need super-user privilege
5692 s to do this.
5693 \end_layout
5694
5695 \begin_layout Section
5696 Components of SDCC
5697 \end_layout
5698
5699 \begin_layout Standard
5700 SDCC is not just a compiler, but a collection of tools by various developers.
5701  These include linkers, assemblers, simulators and other components.
5702  Here is a summary of some of the components.
5703  Note that the included simulator and assembler have separate documentation
5704  which you can find in the source package in their respective directories.
5705  As SDCC grows to include support for other processors, other packages from
5706  various developers are included and may have their own sets of documentation.
5707 \newline
5708
5709 \newline
5710 You
5711  might want to look at the files which are installed in <installdir>.
5712  At the time of this writing, we find the following programs for gcc-builds:
5713 \newline
5714
5715  
5716 \newline
5717 In <installdir>/bin:
5718 \end_layout
5719
5720 \begin_layout Itemize
5721 sdcc - The compiler.
5722 \end_layout
5723
5724 \begin_layout Itemize
5725 sdcpp - The C preprocessor.
5726 \end_layout
5727
5728 \begin_layout Itemize
5729 asx8051 - The assembler for 8051 type processors.
5730 \end_layout
5731
5732 \begin_layout Itemize
5733 as-z80
5734 \series bold
5735 ,
5736 \series default
5737  as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5738 \end_layout
5739
5740 \begin_layout Itemize
5741 aslink -The linker for 8051 type processors.
5742 \end_layout
5743
5744 \begin_layout Itemize
5745 link-z80
5746 \series bold
5747 ,
5748 \series default
5749  link-gbz80 - The Z80 and GameBoy Z80 linkers.
5750 \end_layout
5751
5752 \begin_layout Itemize
5753 s51 - The ucSim 8051 simulator.
5754 \end_layout
5755
5756 \begin_layout Itemize
5757 sdcdb - The source debugger.
5758 \end_layout
5759
5760 \begin_layout Itemize
5761 packihx - A tool to pack (compress) Intel hex files.
5762 \end_layout
5763
5764 \begin_layout Standard
5765 In <installdir>/share/sdcc/include
5766 \end_layout
5767
5768 \begin_layout Itemize
5769 the include files
5770 \end_layout
5771
5772 \begin_layout Standard
5773 In <installdir>/share/sdcc/lib
5774 \end_layout
5775
5776 \begin_layout Itemize
5777 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5778  relocatables.
5779 \end_layout
5780
5781 \begin_layout Standard
5782 In <installdir>/share/sdcc/doc
5783 \end_layout
5784
5785 \begin_layout Itemize
5786 the documentation
5787 \end_layout
5788
5789 \begin_layout Standard
5790 As development for other processors proceeds, this list will expand to include
5791  executables to support processors like AVR, PIC, etc.
5792 \end_layout
5793
5794 \begin_layout Subsection
5795 sdcc - The Compiler
5796 \end_layout
5797
5798 \begin_layout Standard
5799 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5800  the assembler and linkage editor.
5801 \end_layout
5802
5803 \begin_layout Subsection
5804 sdcpp - The C-Preprocessor
5805 \end_layout
5806
5807 \begin_layout Standard
5808 The preprocessor
5809 \begin_inset LatexCommand index
5810 name "sdcpp (preprocessor)"
5811
5812 \end_inset
5813
5814  is a modified version of the GNU cpp
5815 \begin_inset LatexCommand index
5816 name "cpp|see{sdcpp}"
5817
5818 \end_inset
5819
5820  preprocessor 
5821 \begin_inset LatexCommand url
5822 target "http://gcc.gnu.org/"
5823
5824 \end_inset
5825
5826 .
5827  The C preprocessor is used to pull in #include sources, process #ifdef
5828  statements, #defines and so on.
5829 \end_layout
5830
5831 \begin_layout Subsection
5832 as
5833 \emph on
5834 xxxx
5835 \emph default
5836 , aslink, link-
5837 \emph on
5838 xxx
5839 \emph default
5840  - The Assemblers and Linkage Editors
5841 \end_layout
5842
5843 \begin_layout Standard
5844 This is retargettable assembler & linkage editor, it was developed by Alan
5845  Baldwin.
5846  John Hartman created the version for 8051, and I (Sandeep) have made some
5847  enhancements and bug fixes for it to work properly with SDCC.
5848 \end_layout
5849
5850 \begin_layout Subsection
5851 s51 - The Simulator
5852 \end_layout
5853
5854 \begin_layout Standard
5855 S51
5856 \begin_inset LatexCommand index
5857 name "s51"
5858
5859 \end_inset
5860
5861  is a free open source simulator developed by Daniel Drotos.
5862  The simulator is built as part of the build process.
5863  For more information visit Daniel's web site at: 
5864 \begin_inset LatexCommand url
5865 target "http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51"
5866
5867 \end_inset
5868
5869 .
5870  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5871  XA51 family.
5872 \end_layout
5873
5874 \begin_layout Subsection
5875 sdcdb - Source Level Debugger
5876 \end_layout
5877
5878 \begin_layout Standard
5879 SDCDB
5880 \begin_inset LatexCommand index
5881 name "SDCDB (debugger)"
5882
5883 \end_inset
5884
5885  is the companion source level debugger.
5886  More about SDCDB in section 
5887 \begin_inset LatexCommand ref
5888 reference "cha:Debugging-with-SDCDB"
5889
5890 \end_inset
5891
5892 .
5893  The current version of the debugger uses Daniel's Simulator S51
5894 \begin_inset LatexCommand index
5895 name "s51"
5896
5897 \end_inset
5898
5899 , but can be easily changed to use other simulators.
5900 \end_layout
5901
5902 \begin_layout Chapter
5903 Using SDCC
5904 \end_layout
5905
5906 \begin_layout Section
5907 Compiling
5908 \end_layout
5909
5910 \begin_layout Subsection
5911 Single Source File Projects
5912 \end_layout
5913
5914 \begin_layout Standard
5915 For single source file 8051 projects the process is very simple.
5916  Compile your programs with the following command 
5917 \family sans
5918 \series bold
5919 "sdcc sourcefile.c".
5920
5921 \family default
5922 \series default
5923  This will compile, assemble and link your source file.
5924  Output files are as follows:
5925 \end_layout
5926
5927 \begin_layout Itemize
5928 sourcefile.asm
5929 \begin_inset LatexCommand index
5930 name "<file>.asm"
5931
5932 \end_inset
5933
5934  - Assembler source
5935 \begin_inset LatexCommand index
5936 name "Assembler source"
5937
5938 \end_inset
5939
5940  file created by the compiler
5941 \end_layout
5942
5943 \begin_layout Itemize
5944 sourcefile.lst
5945 \begin_inset LatexCommand index
5946 name "<file>.lst"
5947
5948 \end_inset
5949
5950  - Assembler listing
5951 \begin_inset LatexCommand index
5952 name "Assembler listing"
5953
5954 \end_inset
5955
5956  file created by the Assembler
5957 \end_layout
5958
5959 \begin_layout Itemize
5960 sourcefile.rst
5961 \begin_inset LatexCommand index
5962 name "<file>.rst"
5963
5964 \end_inset
5965
5966  - Assembler listing
5967 \begin_inset LatexCommand index
5968 name "Assembler listing"
5969
5970 \end_inset
5971
5972  file updated with linkedit information, created by linkage editor
5973 \end_layout
5974
5975 \begin_layout Itemize
5976 sourcefile.sym
5977 \begin_inset LatexCommand index
5978 name "<file>.sym"
5979
5980 \end_inset
5981
5982  - symbol listing
5983 \begin_inset LatexCommand index
5984 name "Symbol listing"
5985
5986 \end_inset
5987
5988  for the sourcefile, created by the assembler
5989 \end_layout
5990
5991 \begin_layout Itemize
5992 sourcefile.rel
5993 \begin_inset LatexCommand index
5994 name "<file>.rel"
5995
5996 \end_inset
5997
5998  or sourcefile.o
5999 \begin_inset LatexCommand index
6000 name "<file>.o"
6001
6002 \end_inset
6003
6004  - Object file
6005 \begin_inset LatexCommand index
6006 name "Object file"
6007
6008 \end_inset
6009
6010  created by the assembler, input to Linkage editor
6011 \end_layout
6012
6013 \begin_layout Itemize
6014 sourcefile.map
6015 \begin_inset LatexCommand index
6016 name "<file>.map"
6017
6018 \end_inset
6019
6020  - The memory map
6021 \begin_inset LatexCommand index
6022 name "Memory map"
6023
6024 \end_inset
6025
6026  for the load module, created by the Linker
6027 \end_layout
6028
6029 \begin_layout Itemize
6030 sourcefile.mem
6031 \begin_inset LatexCommand index
6032 name "<file>.mem"
6033
6034 \end_inset
6035
6036  - A file with a summary of the memory usage
6037 \end_layout
6038
6039 \begin_layout Itemize
6040 sourcefile.ihx
6041 \begin_inset LatexCommand index
6042 name "<file>.ihx"
6043
6044 \end_inset
6045
6046  - The load module in Intel hex format
6047 \begin_inset LatexCommand index
6048 name "Intel hex format"
6049
6050 \end_inset
6051
6052  (you can select the Motorola S19 format
6053 \begin_inset LatexCommand index
6054 name "Motorola S19 format"
6055
6056 \end_inset
6057
6058  with -
6059 \begin_inset ERT
6060 status collapsed
6061
6062 \begin_layout Standard
6063
6064
6065 \backslash
6066 /
6067 \end_layout
6068
6069 \end_inset
6070
6071 -out-fmt-s19
6072 \begin_inset LatexCommand index
6073 name "-\\/-out-fmt-s19"
6074
6075 \end_inset
6076
6077 .
6078  If you need another format you might want to use 
6079 \family sans
6080 \shape italic
6081 objdump
6082 \family default
6083 \shape default
6084
6085 \begin_inset LatexCommand index
6086 name "objdump (tool)"
6087
6088 \end_inset
6089
6090  or 
6091 \family sans
6092 \shape italic
6093 srecord
6094 \family default
6095 \shape default
6096
6097 \begin_inset LatexCommand index
6098 name "srecord (bin, hex, ... tool)"
6099
6100 \end_inset
6101
6102
6103 \begin_inset Note Note
6104 status collapsed
6105
6106 \begin_layout Standard
6107 hyperlinks needed
6108 \end_layout
6109
6110 \end_inset
6111
6112  - see also section 
6113 \begin_inset LatexCommand vref
6114 reference "sub:Postprocessing-the-Intel"
6115
6116 \end_inset
6117
6118 ).
6119  Both formats are documented in the documentation of srecord
6120 \begin_inset LatexCommand index
6121 name "srecord (bin, hex, ... tool)"
6122
6123 \end_inset
6124
6125
6126 \end_layout
6127
6128 \begin_layout Itemize
6129 sourcefile.adb
6130 \begin_inset LatexCommand index
6131 name "<file>.adb"
6132
6133 \end_inset
6134
6135  - An intermediate file containing debug information needed to create the
6136  .cdb file (with -
6137 \begin_inset ERT
6138 status collapsed
6139
6140 \begin_layout Standard
6141
6142
6143 \backslash
6144 /
6145 \end_layout
6146
6147 \end_inset
6148
6149 -debug
6150 \begin_inset LatexCommand index
6151 name "-\\/-debug"
6152
6153 \end_inset
6154
6155
6156 \end_layout
6157
6158 \begin_layout Itemize
6159 sourcefile.cdb
6160 \begin_inset LatexCommand index
6161 name "<file>.cdb"
6162
6163 \end_inset
6164
6165  - An optional file (with -
6166 \begin_inset ERT
6167 status collapsed
6168
6169 \begin_layout Standard
6170
6171
6172 \backslash
6173 /
6174 \end_layout
6175
6176 \end_inset
6177
6178 -debug) containing debug information.
6179  The format is documented in cdbfileformat.pdf
6180 \end_layout
6181
6182 \begin_layout Itemize
6183 sourcefile.
6184  - (no extension)
6185 \begin_inset LatexCommand index
6186 name "<file> (no extension)"
6187
6188 \end_inset
6189
6190  An optional AOMF or AOMF51
6191 \begin_inset LatexCommand index
6192 name "AOMF, AOMF51"
6193
6194 \end_inset
6195
6196  
6197 \begin_inset LatexCommand label
6198 name "OMF file"
6199
6200 \end_inset
6201
6202 file containing debug information (generated with option -
6203 \begin_inset ERT
6204 status collapsed
6205
6206 \begin_layout Standard
6207
6208
6209 \backslash
6210 /
6211 \end_layout
6212
6213 \end_inset
6214
6215 -debug).
6216  The (Intel) 
6217 \emph on
6218 a
6219 \emph default
6220 bsolute 
6221 \emph on
6222 o
6223 \emph default
6224 bject 
6225 \emph on
6226 m
6227 \emph default
6228 odule 
6229 \emph on
6230 f
6231 \emph default
6232 ormat is a subformat of the OMF51 format and is commonly used by third party
6233  tools (debuggers
6234 \begin_inset LatexCommand index
6235 name "Debugger"
6236
6237 \end_inset
6238
6239 , simulators, emulators).
6240 \end_layout
6241
6242 \begin_layout Itemize
6243 sourcefile.dump*
6244 \begin_inset LatexCommand index
6245 name "<file>.dump*"
6246
6247 \end_inset
6248
6249  - Dump file to debug the compiler it self (generated with option -
6250 \begin_inset ERT
6251 status collapsed
6252
6253 \begin_layout Standard
6254
6255
6256 \backslash
6257 /
6258 \end_layout
6259
6260 \end_inset
6261
6262 -dumpall) (see section 
6263 \begin_inset LatexCommand ref
6264 reference "sub:Intermediate-Dump-Options"
6265
6266 \end_inset
6267
6268 \InsetSpace ~
6269  and section 
6270 \begin_inset LatexCommand ref
6271 reference "sub:The-anatomy-of"
6272
6273 \end_inset
6274
6275 \InsetSpace ~
6276
6277 \begin_inset Quotes sld
6278 \end_inset
6279
6280 Anatomy of the compiler
6281 \begin_inset Quotes srd
6282 \end_inset
6283
6284 ).
6285 \end_layout
6286
6287 \begin_layout Subsection
6288 Postprocessing the Intel Hex
6289 \begin_inset LatexCommand index
6290 name "Intel hex format"
6291
6292 \end_inset
6293
6294  file
6295 \begin_inset LatexCommand label
6296 name "sub:Postprocessing-the-Intel"
6297
6298 \end_inset
6299
6300
6301 \end_layout
6302
6303 \begin_layout Standard
6304 In most cases this won't be needed but the Intel Hex file
6305 \begin_inset LatexCommand index
6306 name "<file>.ihx"
6307
6308 \end_inset
6309
6310  which is generated by SDCC might include lines of varying length and the
6311  addresses within the file are not guaranteed to be strictly ascending.
6312  If your toolchain or a bootloader does not like this you can use the tool
6313  
6314 \family typewriter
6315 packihx
6316 \family default
6317
6318 \begin_inset LatexCommand index
6319 name "packihx (tool)"
6320
6321 \end_inset
6322
6323  which is part of the SDCC distribution: 
6324 \newline
6325
6326 \newline
6327  
6328 \family sans
6329 \series bold
6330 packihx sourcefile.ihx >sourcefile.hex
6331 \family default
6332 \series default
6333
6334 \newline
6335
6336 \newline
6337 The separately available 
6338 \emph on
6339 srecord
6340 \emph default
6341
6342 \begin_inset LatexCommand index
6343 name "srecord (bin, hex, ... tool)"
6344
6345 \end_inset
6346
6347  package additionally allows to set undefined locations to a predefined
6348  value, to insert checksums
6349 \begin_inset LatexCommand index
6350 name "checksum"
6351
6352 \end_inset
6353
6354  of various flavours (crc, add, xor) and to perform other manipulations
6355  (convert, split, crop, offset, ...).
6356  
6357 \newline
6358
6359 \newline
6360
6361 \family sans
6362 \series bold
6363 srec_cat\InsetSpace ~
6364 \InsetSpace ~
6365 sourcefile.ihx -intel\InsetSpace ~
6366 \InsetSpace ~
6367 -o sourcefile.hex -intel
6368 \newline
6369
6370 \newline
6371
6372 \family default
6373 \series default
6374 An example for a more complex command line
6375 \begin_inset Foot
6376 status open
6377
6378 \begin_layout Standard
6379 the command backfills
6380 \begin_inset LatexCommand index
6381 name "backfill unused memory"
6382
6383 \end_inset
6384
6385  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
6386  block is zero.
6387  If the program counter on an mcs51 runs wild the backfill pattern 0x12
6388  will be interpreted as an 
6389 \family typewriter
6390 lcall
6391 \family default
6392  to address 
6393 \family typewriter
6394 0x1212
6395 \family default
6396  (where an emergency routine could sit).
6397 \end_layout
6398
6399 \end_inset
6400
6401  could look like:
6402 \newline
6403
6404 \newline
6405
6406 \family sans
6407 \series bold
6408 \size footnotesize
6409 srec_cat\InsetSpace ~
6410 sourcefile.ihx -intel\InsetSpace ~
6411 \InsetSpace ~
6412 -fill 0x12 0x0000 0xfffe\InsetSpace ~
6413 -little-endian-checksum-nega
6414 tive 0xfffe 0x02 0x02\InsetSpace ~
6415 \InsetSpace ~
6416 -o sourcefile.hex -intel
6417 \size default
6418
6419 \newline
6420
6421 \newline
6422
6423 \family default
6424 \series default
6425 The srecord package is available at 
6426 \begin_inset LatexCommand url
6427 target "http://sf.net/projects/srecord"
6428
6429 \end_inset
6430
6431  .
6432 \end_layout
6433
6434 \begin_layout Subsection
6435 Projects with Multiple Source Files
6436 \end_layout
6437
6438 \begin_layout Standard
6439 SDCC can compile only ONE file at a time.
6440  Let us for example assume that you have a project containing the following
6441  files:
6442 \newline
6443
6444 \newline
6445 foo1.c (contains some functions)
6446 \newline
6447 foo2.c (contains some more functions)
6448 \newline
6449 foomai
6450 n.c (contains more functions and the function main)
6451 \newline
6452
6453 \size footnotesize
6454
6455 \newline
6456
6457 \size default
6458 The first two files will need to be compiled separately with the commands:
6459 \size footnotesize
6460  
6461 \size default
6462
6463 \newline
6464
6465 \newline
6466
6467 \family sans
6468 \series bold
6469 sdcc\InsetSpace ~
6470 -c\InsetSpace ~
6471 foo1.c
6472 \family default
6473 \series default
6474 \size footnotesize
6475
6476 \newline
6477
6478 \family sans
6479 \series bold
6480 \size default
6481 sdcc\InsetSpace ~
6482 -c\InsetSpace ~
6483 foo2.c
6484 \family default
6485 \series default
6486
6487 \newline
6488
6489 \newline
6490 Then compile the source file containing the 
6491 \emph on
6492 main()
6493 \emph default
6494  function and link
6495 \begin_inset LatexCommand index
6496 name "Linker"
6497
6498 \end_inset
6499
6500  the files together with the following command: 
6501 \newline
6502
6503 \newline
6504
6505 \family sans
6506 \series bold
6507 sdcc\InsetSpace ~
6508 foomain.c\InsetSpace ~
6509 foo1.rel\InsetSpace ~
6510 foo2.rel
6511 \family default
6512 \series default
6513
6514 \begin_inset LatexCommand index
6515 name "<file>.rel"
6516
6517 \end_inset
6518
6519
6520 \newline
6521
6522 \newline
6523 Alternatively, 
6524 \emph on
6525 foomain.c
6526 \emph default
6527  can be separately compiled as well: 
6528 \family sans
6529 \series bold
6530
6531 \newline
6532
6533 \newline
6534 sdcc\InsetSpace ~
6535 -c\InsetSpace ~
6536 foomain.c
6537 \newline
6538 sdcc foomain.rel foo1.rel foo2.rel
6539 \newline
6540
6541 \newline
6542
6543 \family default
6544 \series default
6545 The file containing the 
6546 \emph on
6547 main()
6548 \emph default
6549  function 
6550 \noun on
6551 must
6552 \noun default
6553  be the 
6554 \noun on
6555 first
6556 \noun default
6557  file specified in the command line, since the linkage editor processes
6558  file in the order they are presented to it.
6559  The linker is invoked from SDCC using a script file with extension .lnk
6560 \begin_inset LatexCommand index
6561 name "<file>.lnk"
6562
6563 \end_inset
6564
6565 .
6566  You can view this file to troubleshoot linking problems such as those arising
6567  from missing libraries.
6568 \end_layout
6569
6570 \begin_layout Subsection
6571 Projects with Additional Libraries
6572 \begin_inset LatexCommand index
6573 name "Libraries"
6574
6575 \end_inset
6576
6577
6578 \end_layout
6579
6580 \begin_layout Standard
6581 Some reusable routines may be compiled into a library, see the documentation
6582  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6583  for how to create a 
6584 \emph on
6585 .lib
6586 \begin_inset LatexCommand index
6587 name "<file>.lib"
6588
6589 \end_inset
6590
6591
6592 \emph default
6593  library file.
6594  Libraries created in this manner can be included in the command line.
6595  Make sure you include the -L <library-path> option to tell the linker where
6596  to look for these files if they are not in the current directory.
6597  Here is an example, assuming you have the source file 
6598 \emph on
6599 foomain.c
6600 \emph default
6601  and a library 
6602 \emph on
6603 foolib.lib
6604 \emph default
6605  in the directory 
6606 \emph on
6607 mylib
6608 \emph default
6609  (if that is not the same as your current project):
6610 \newline
6611
6612 \newline
6613
6614 \family sans
6615 \series bold
6616 sdcc foomain.c foolib.lib -L mylib
6617 \newline
6618
6619 \newline
6620
6621 \family default
6622 \series default
6623 Note here that 
6624 \emph on
6625 mylib
6626 \emph default
6627  must be an absolute path name.
6628 \newline
6629
6630 \newline
6631 The most efficient way to use libraries is
6632  to keep separate modules in separate source files.
6633  The lib file now should name all the modules.rel
6634 \begin_inset LatexCommand index
6635 name "<file>.rel"
6636
6637 \end_inset
6638
6639  files.
6640  For an example see the standard library file 
6641 \emph on
6642 libsdcc.lib
6643 \emph default
6644  in the directory <installdir>/share/lib/small.
6645 \end_layout
6646
6647 \begin_layout Subsection
6648 Using sdcclib to Create and Manage Libraries
6649 \begin_inset LatexCommand index
6650 name "sdcclib"
6651
6652 \end_inset
6653
6654
6655 \end_layout
6656
6657 \begin_layout Standard
6658 Alternatively, instead of having a .rel file for each entry on the library
6659  file as described in the preceding section, sdcclib can be used to embed
6660  all the modules belonging to such library in the library file itself.
6661  This results in a larger library file, but it greatly reduces the number
6662  of disk files accessed by the linker.
6663   Additionally, the packed library file contains an index of all include
6664  modules and symbols that significantly speeds up the linking process.
6665  To display a list of options supported by sdcclib type:
6666 \newline
6667
6668 \end_layout
6669
6670 \begin_layout Standard
6671
6672 \family sans
6673 \series bold
6674 sdcclib -?
6675 \begin_inset LatexCommand index
6676 name "sdcclib"
6677
6678 \end_inset
6679
6680
6681 \newline
6682
6683 \newline
6684
6685 \family default
6686 \series default
6687 To create a new library file, start by compiling all the required modules.
6688  For example:
6689 \newline
6690
6691 \end_layout
6692
6693 \begin_layout Standard
6694
6695 \family sans
6696 \series bold
6697 sdcc -c _divsint.c
6698 \end_layout
6699
6700 \begin_layout Standard
6701
6702 \family sans
6703 \series bold
6704 sdcc -c _divuint.c
6705 \end_layout
6706
6707 \begin_layout Standard
6708
6709 \family sans
6710 \series bold
6711 sdcc -c _modsint.c
6712 \end_layout
6713
6714 \begin_layout Standard
6715
6716 \family sans
6717 \series bold
6718 sdcc -c _moduint.c
6719 \end_layout
6720
6721 \begin_layout Standard
6722
6723 \family sans
6724 \series bold
6725 sdcc -c _mulint.c
6726 \newline
6727
6728 \end_layout
6729
6730 \begin_layout Standard
6731 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6732  and _mulint.rel.
6733  The next step is to add the .rel files to the library file:
6734 \newline
6735
6736 \end_layout
6737
6738 \begin_layout Standard
6739
6740 \family sans
6741 \series bold
6742 sdcclib libint.lib _divsint.rel
6743 \family default
6744
6745 \begin_inset LatexCommand index
6746 name "sdcclib"
6747
6748 \end_inset
6749
6750
6751 \end_layout
6752
6753 \begin_layout Standard
6754
6755 \family sans
6756 \series bold
6757 sdcclib libint.lib _divuint.rel
6758 \end_layout
6759
6760 \begin_layout Standard
6761
6762 \family sans
6763 \series bold
6764 sdcclib libint.lib _modsint.rel
6765 \end_layout
6766
6767 \begin_layout Standard
6768
6769 \family sans
6770 \series bold
6771 sdcclib libint.lib _moduint.rel
6772 \end_layout
6773
6774 \begin_layout Standard
6775
6776 \family sans
6777 \series bold
6778 sdcclib libint.lib _mulint.rel
6779 \family default
6780 \series default
6781
6782 \newline
6783
6784 \end_layout
6785
6786 \begin_layout Standard
6787 Or, if you preffer:
6788 \family sans
6789 \series bold
6790
6791 \newline
6792
6793 \end_layout
6794
6795 \begin_layout Standard
6796
6797 \family sans
6798 \series bold
6799 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6800 \family default
6801 \series default
6802
6803 \newline
6804
6805 \end_layout
6806
6807 \begin_layout Standard
6808 If the file already exists in the library, it will be replaced.
6809  If a list of .rel files is available, you can tell sdcclib to add those
6810  files to a library.
6811  For example, if the file 'myliblist.txt' contains
6812 \family sans
6813 \series bold
6814
6815 \newline
6816
6817 \end_layout
6818
6819 \begin_layout Standard
6820
6821 \family sans
6822 \series bold
6823 _divsint.rel
6824 \end_layout
6825
6826 \begin_layout Standard
6827
6828 \family sans
6829 \series bold
6830 _divuint.rel
6831 \end_layout
6832
6833 \begin_layout Standard
6834
6835 \family sans
6836 \series bold
6837 _modsint.rel
6838 \end_layout
6839
6840 \begin_layout Standard
6841
6842 \family sans
6843 \series bold
6844 _moduint.rel
6845 \end_layout
6846
6847 \begin_layout Standard
6848
6849 \family sans
6850 \series bold
6851 _mulint.rel
6852 \family default
6853 \series default
6854
6855 \newline
6856
6857 \end_layout
6858
6859 \begin_layout Standard
6860 Use
6861 \family sans
6862 \series bold
6863
6864 \newline
6865
6866 \end_layout
6867
6868 \begin_layout Standard
6869
6870 \family sans
6871 \series bold
6872 sdcclib -l libint.lib myliblist.txt
6873 \family default
6874 \series default
6875
6876 \newline
6877
6878 \end_layout
6879
6880 \begin_layout Standard
6881 Additionally, you can instruct sdcclib to compiles the files before adding
6882  them to the library.
6883  This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6884  For example:
6885 \family sans
6886 \series bold
6887
6888 \newline
6889
6890 \end_layout
6891
6892 \begin_layout Standard
6893
6894 \family sans
6895 \series bold
6896 set SDCCLIB_CC=sdcc -c
6897 \end_layout
6898
6899 \begin_layout Standard
6900
6901 \family sans
6902 \series bold
6903 sdcclib -l libint.lib myliblist.txt
6904 \family default
6905 \series default
6906
6907 \newline
6908
6909 \end_layout
6910
6911 \begin_layout Standard
6912 To see what modules and symbols are included in the library, options -s
6913  and -m are available.
6914  For example:
6915 \newline
6916
6917 \newline
6918
6919 \family sans
6920 \series bold
6921 sdcclib -s libint.lib
6922 \family default
6923
6924 \begin_inset LatexCommand index
6925 name "sdcclib"
6926
6927 \end_inset
6928
6929
6930 \newline
6931
6932 \family typewriter
6933 \series default
6934 _divsint.rel:
6935 \end_layout
6936
6937 \begin_layout Standard
6938
6939 \family typewriter
6940 __divsint_a_1_1
6941 \end_layout
6942
6943 \begin_layout Standard
6944
6945 \family typewriter
6946 __divsint_PARM_2
6947 \end_layout
6948
6949 \begin_layout Standard
6950
6951 \family typewriter
6952 __divsint
6953 \newline
6954 _divuint.rel:
6955 \end_layout
6956
6957 \begin_layout Standard
6958
6959 \family typewriter
6960 __divuint_a_1_1
6961 \end_layout
6962
6963 \begin_layout Standard
6964
6965 \family typewriter
6966 __divuint_PARM_2
6967 \end_layout
6968
6969 \begin_layout Standard
6970
6971 \family typewriter
6972 __divuint_reste_1_1
6973 \end_layout
6974
6975 \begin_layout Standard
6976
6977 \family typewriter
6978 __divuint_count_1_1
6979 \end_layout
6980
6981 \begin_layout Standard
6982
6983 \family typewriter
6984 __divuint
6985 \newline
6986 _modsint.rel:
6987 \end_layout
6988
6989 \begin_layout Standard
6990
6991 \family typewriter
6992 __modsint_a_1_1
6993 \end_layout
6994
6995 \begin_layout Standard
6996
6997 \family typewriter
6998 __modsint_PARM_2
6999 \end_layout
7000
7001 \begin_layout Standard
7002
7003 \family typewriter
7004 __modsint
7005 \newline
7006 _moduint.rel:
7007 \end_layout
7008
7009 \begin_layout Standard
7010
7011 \family typewriter
7012 __moduint_a_1_1
7013 \end_layout
7014
7015 \begin_layout Standard
7016
7017 \family typewriter
7018 __moduint_PARM_2
7019 \end_layout
7020
7021 \begin_layout Standard
7022
7023 \family typewriter
7024 __moduint_count_1_1
7025 \end_layout
7026
7027 \begin_layout Standard
7028
7029 \family typewriter
7030 __moduint
7031 \newline
7032 _mulint.rel:
7033 \end_layout
7034
7035 \begin_layout Standard
7036
7037 \family typewriter
7038 __mulint_PARM_2
7039 \end_layout
7040
7041 \begin_layout Standard
7042
7043 \family typewriter
7044 __mulint
7045 \family default
7046 \series bold
7047
7048 \newline
7049
7050 \end_layout
7051
7052 \begin_layout Standard
7053 If the source files are compiled using -
7054 \begin_inset ERT
7055 status collapsed
7056
7057 \begin_layout Standard
7058
7059
7060 \backslash
7061 /
7062 \end_layout
7063
7064 \end_inset
7065
7066 -debug
7067 \begin_inset LatexCommand index
7068 name "-\\/-debug"
7069
7070 \end_inset
7071
7072 , the corresponding debug information file .adb will be include in the library
7073  file as well.
7074  The library files created with sdcclib are plain text files, so they can
7075  be viewed with a text editor.
7076  It is not recommended to modify a library file created with sdcclib using
7077  a text editor, as there are file indexes numbers located across the file
7078  used by the linker to quickly locate the required module to link.
7079  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
7080  it can be safely deleted, since all the information required for linking
7081  is embedded in the library file itself.
7082  Library files created using sdcclib are used as described in the preceding
7083  sections.
7084 \begin_inset VSpace bigskip
7085 \end_inset
7086
7087
7088 \end_layout
7089
7090 \begin_layout Section
7091 Command Line Options
7092 \begin_inset LatexCommand index
7093 name "Command Line Options"
7094
7095 \end_inset
7096
7097
7098 \begin_inset LatexCommand label
7099 name "sec:Command-Line-Options"
7100
7101 \end_inset
7102
7103
7104 \end_layout
7105
7106 \begin_layout Subsection
7107 Processor Selection Options
7108 \begin_inset LatexCommand index
7109 name "Options processor selection"
7110
7111 \end_inset
7112
7113
7114 \begin_inset LatexCommand index
7115 name "Processor selection options"
7116
7117 \end_inset
7118
7119
7120 \end_layout
7121
7122 \begin_layout List
7123 \labelwidthstring 00.00.0000
7124
7125 \series bold
7126 -mmcs51
7127 \begin_inset LatexCommand index
7128 name "-mmcs51"
7129
7130 \end_inset
7131
7132
7133 \series default
7134  Generate code for the Intel MCS51
7135 \begin_inset LatexCommand index
7136 name "MCS51"
7137
7138 \end_inset
7139
7140  family of processors.
7141  This is the default processor target.
7142 \end_layout
7143
7144 \begin_layout List
7145 \labelwidthstring 00.00.0000
7146
7147 \series bold
7148 -mds390
7149 \begin_inset LatexCommand index
7150 name "-mds390"
7151
7152 \end_inset
7153
7154
7155 \series default
7156  Generate code for the Dallas DS80C390
7157 \begin_inset LatexCommand index
7158 name "DS80C390"
7159
7160 \end_inset
7161
7162  processor.
7163 \end_layout
7164
7165 \begin_layout List
7166 \labelwidthstring 00.00.0000
7167
7168 \series bold
7169 -mds400
7170 \begin_inset LatexCommand index
7171 name "-mds400"
7172
7173 \end_inset
7174
7175
7176 \series default
7177  Generate code for the Dallas DS80C400
7178 \begin_inset LatexCommand index
7179 name "DS80C400"
7180
7181 \end_inset
7182
7183  processor.
7184 \end_layout
7185
7186 \begin_layout List
7187 \labelwidthstring 00.00.0000
7188
7189 \series bold
7190 -mhc08
7191 \begin_inset LatexCommand index
7192 name "-mhc08"
7193
7194 \end_inset
7195
7196
7197 \series default
7198  Generate code for the Freescale/Motorola HC08
7199 \begin_inset LatexCommand index
7200 name "HC08"
7201
7202 \end_inset
7203
7204  family of processors.
7205 \end_layout
7206
7207 \begin_layout List
7208 \labelwidthstring 00.00.0000
7209
7210 \series bold
7211 -mz80
7212 \begin_inset LatexCommand index
7213 name "-mz80"
7214
7215 \end_inset
7216
7217
7218 \series default
7219  Generate code for the Zilog Z80
7220 \begin_inset LatexCommand index
7221 name "Z80"
7222
7223 \end_inset
7224
7225  family of processors.
7226 \end_layout
7227
7228 \begin_layout List
7229 \labelwidthstring 00.00.0000
7230
7231 \series bold
7232 -mgbz80
7233 \begin_inset LatexCommand index
7234 name "-mgbz80"
7235
7236 \end_inset
7237
7238
7239 \series default
7240  Generate code for the GameBoy Z80
7241 \begin_inset LatexCommand index
7242 name "gbz80 (GameBoy Z80)"
7243
7244 \end_inset
7245
7246  processor (Not actively maintained).
7247 \end_layout
7248
7249 \begin_layout List
7250 \labelwidthstring 00.00.0000
7251
7252 \series bold
7253 -mavr
7254 \begin_inset LatexCommand index
7255 name "-mavr"
7256
7257 \end_inset
7258
7259
7260 \series default
7261  Generate code for the Atmel AVR
7262 \begin_inset LatexCommand index
7263 name "AVR"
7264
7265 \end_inset
7266
7267  processor (Not maintained, not complete).
7268  AVR users should probably have a look at winavr 
7269 \begin_inset LatexCommand url
7270 target "http://sourceforge.net/projects/winavr"
7271
7272 \end_inset
7273
7274  or 
7275 \begin_inset LatexCommand url
7276 target "http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index"
7277
7278 \end_inset
7279
7280 , which is based on AVR-port of the gcc compiler.
7281 \end_layout
7282
7283 \begin_layout Standard
7284 \begin_inset Note Note
7285 status collapsed
7286
7287 \begin_layout Standard
7288 I think it is fair to direct users there for now.
7289  Open source is also about avoiding unnecessary work .
7290  But I didn't find the 'official' link.
7291 \end_layout
7292
7293 \end_inset
7294
7295
7296 \end_layout
7297
7298 \begin_layout List
7299 \labelwidthstring 00.00.0000
7300
7301 \series bold
7302 -mpic14
7303 \begin_inset LatexCommand index
7304 name "-mpic14"
7305
7306 \end_inset
7307
7308
7309 \series default
7310  Generate code for the Microchip PIC 14
7311 \begin_inset LatexCommand index
7312 name "PIC14"
7313
7314 \end_inset
7315
7316 -bit processors (p16f84 and variants.
7317  In development, not complete).
7318 \end_layout
7319
7320 \begin_layout Standard
7321 \begin_inset Note Note
7322 status collapsed
7323
7324 \begin_layout Standard
7325 p16f627 p16f628 p16f84 p16f873 p16f877?
7326 \end_layout
7327
7328 \end_inset
7329
7330
7331 \end_layout
7332
7333 \begin_layout List
7334 \labelwidthstring 00.00.0000
7335
7336 \series bold
7337 -mpic16
7338 \begin_inset LatexCommand index
7339 name "-mpic16"
7340
7341 \end_inset
7342
7343
7344 \series default
7345  Generate code for the Microchip PIC 16
7346 \begin_inset LatexCommand index
7347 name "PIC16"
7348
7349 \end_inset
7350
7351 -bit processors (p18f452 and variants.
7352  In development, not complete).
7353 \end_layout
7354
7355 \begin_layout List
7356 \labelwidthstring 00.00.0000
7357
7358 \series bold
7359 -mtlcs900h
7360 \series default
7361  Generate code for the Toshiba TLCS-900H
7362 \begin_inset LatexCommand index
7363 name "TLCS-900H"
7364
7365 \end_inset
7366
7367  processor (Not maintained, not complete).
7368 \end_layout
7369
7370 \begin_layout List
7371 \labelwidthstring 00.00.0000
7372
7373 \series bold
7374 -mxa51
7375 \begin_inset LatexCommand index
7376 name "-mxa51"
7377
7378 \end_inset
7379
7380
7381 \series default
7382  Generate code for the Phillips XA51
7383 \begin_inset LatexCommand index
7384 name "XA51"
7385
7386 \end_inset
7387
7388  processor (Not maintained, not complete).
7389 \end_layout
7390
7391 \begin_layout Standard
7392 \begin_inset VSpace bigskip
7393 \end_inset
7394
7395
7396 \end_layout
7397
7398 \begin_layout Subsection
7399 Preprocessor Options
7400 \begin_inset LatexCommand index
7401 name "Options preprocessor"
7402
7403 \end_inset
7404
7405
7406 \begin_inset LatexCommand index
7407 name "Preprocessor options"
7408
7409 \end_inset
7410
7411
7412 \begin_inset LatexCommand index
7413 name "sdcpp (preprocessor)"
7414
7415 \end_inset
7416
7417
7418 \end_layout
7419
7420 \begin_layout List
7421 \labelwidthstring 00.00.0000
7422
7423 \series bold
7424 -I<path>
7425 \begin_inset LatexCommand index
7426 name "-I<path>"
7427
7428 \end_inset
7429
7430
7431 \series default
7432  The additional location where the preprocessor will look for <..h> or 
7433 \begin_inset Quotes eld
7434 \end_inset
7435
7436 ..h
7437 \begin_inset Quotes erd
7438 \end_inset
7439
7440  files.
7441 \end_layout
7442
7443 \begin_layout List
7444 \labelwidthstring 00.00.0000
7445
7446 \series bold
7447 -D<macro[=value]>
7448 \begin_inset LatexCommand index
7449 name "-D<macro[=value]>"
7450
7451 \end_inset
7452
7453
7454 \series default
7455  Command line definition of macros.
7456  Passed to the preprocessor.
7457 \end_layout
7458
7459 \begin_layout List
7460 \labelwidthstring 00.00.0000
7461
7462 \series bold
7463 -M
7464 \begin_inset LatexCommand index
7465 name "-M"
7466
7467 \end_inset
7468
7469
7470 \series default
7471  Tell the preprocessor to output a rule suitable for make describing the
7472  dependencies of each object file.
7473  For each source file, the preprocessor outputs one make-rule whose target
7474  is the object file name for that source file and whose dependencies are
7475  all the files `#include'd in it.
7476  This rule may be a single line or may be continued with `
7477 \backslash
7478 '-newline if it is long.
7479  The list of rules is printed on standard output instead of the preprocessed
7480  C program.
7481  `-M' implies `-E
7482 \begin_inset LatexCommand index
7483 name "-E"
7484
7485 \end_inset
7486
7487 '.
7488 \end_layout
7489
7490 \begin_layout List
7491 \labelwidthstring 00.00.0000
7492
7493 \series bold
7494 -C
7495 \begin_inset LatexCommand index
7496 name "-C"
7497
7498 \end_inset
7499
7500
7501 \series default
7502  Tell the preprocessor not to discard comments.
7503  Used with the `-E' option.
7504 \end_layout
7505
7506 \begin_layout List
7507 \labelwidthstring 00.00.0000
7508
7509 \series bold
7510 -MM
7511 \begin_inset LatexCommand index
7512 name "-MM"
7513
7514 \end_inset
7515
7516
7517 \series default
7518 \size large
7519  
7520 \size default
7521 Like `-M' but the output mentions only the user header files included with
7522  `#include 
7523 \begin_inset Quotes eld
7524 \end_inset
7525
7526 file"'.
7527  System header files included with `#include <file>' are omitted.
7528 \end_layout
7529
7530 \begin_layout List
7531 \labelwidthstring 00.00.0000
7532
7533 \series bold
7534 -Aquestion(answer)
7535 \begin_inset LatexCommand index
7536 name "-Aquestion(answer)"
7537
7538 \end_inset
7539
7540
7541 \series default
7542  Assert the answer answer for question, in case it is tested with a preprocessor
7543  conditional such as `#if #question(answer)'.
7544  `-A-' disables the standard assertions that normally describe the target
7545  machine.
7546 \end_layout
7547
7548 \begin_layout List
7549 \labelwidthstring 00.00.0000
7550
7551 \series bold
7552 -Umacro
7553 \begin_inset LatexCommand index
7554 name "-Umacro"
7555
7556 \end_inset
7557
7558
7559 \series default
7560  Undefine macro macro.
7561  `-U' options are evaluated after all `-D' options, but before any `-include'
7562  and `-imacros' options.
7563 \end_layout
7564
7565 \begin_layout List
7566 \labelwidthstring 00.00.0000
7567
7568 \series bold
7569 -dM
7570 \begin_inset LatexCommand index
7571 name "-dM"
7572
7573 \end_inset
7574
7575
7576 \series default
7577  Tell the preprocessor to output only a list of the macro definitions that
7578  are in effect at the end of preprocessing.
7579  Used with the `-E' option.
7580 \end_layout
7581
7582 \begin_layout List
7583 \labelwidthstring 00.00.0000
7584
7585 \series bold
7586 -dD
7587 \begin_inset LatexCommand index
7588 name "-dD"
7589
7590 \end_inset
7591
7592
7593 \series default
7594  Tell the preprocessor to pass all macro definitions into the output, in
7595  their proper sequence in the rest of the output.
7596 \end_layout
7597
7598 \begin_layout List
7599 \labelwidthstring 00.00.0000
7600
7601 \series bold
7602 -dN
7603 \begin_inset LatexCommand index
7604 name "-dN"
7605
7606 \end_inset
7607
7608
7609 \series default
7610 \size large
7611  
7612 \size default
7613 Like `-dD' except that the macro arguments and contents are omitted.
7614  Only `#define name' is included in the output.
7615 \end_layout
7616
7617 \begin_layout List
7618 \labelwidthstring 00.00.0000
7619
7620 \series bold
7621 -pedantic-parse-number
7622 \begin_inset LatexCommand index
7623 name "pedantic"
7624
7625 \end_inset
7626
7627
7628 \begin_inset LatexCommand index
7629 name "-pedantic-parse-number"
7630
7631 \end_inset
7632
7633
7634 \size large
7635 \bar under
7636
7637 \begin_inset LatexCommand label
7638 name "lyx:-pedantic-parse-number"
7639
7640 \end_inset
7641
7642
7643 \series default
7644 \bar default
7645  
7646 \size default
7647 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7648  and the macro LO_B(3) gets expanded.
7649  See also #pragma pedantic_parse_number 
7650 \begin_inset LatexCommand vpageref
7651 reference "ite:pedantic_parse_number"
7652
7653 \end_inset
7654
7655  in section
7656 \begin_inset LatexCommand ref
7657 reference "sec:Pragmas"
7658
7659 \end_inset
7660
7661  
7662 \emph on
7663 Note: this functionality is not in conformance with C99 standard!
7664 \end_layout
7665
7666 \begin_layout List
7667 \labelwidthstring 00.00.0000
7668
7669 \series bold
7670 -Wp\InsetSpace ~
7671 preprocessorOption[,preprocessorOption]
7672 \series default
7673
7674 \begin_inset LatexCommand index
7675 name "-Wp preprocessorOption[,preprocessorOption]"
7676
7677 \end_inset
7678
7679 ...
7680  Pass the preprocessorOption to the preprocessor 
7681 \family typewriter
7682 sdcpp
7683 \family default
7684
7685 \begin_inset LatexCommand index
7686 name "sdcpp (preprocessor)"
7687
7688 \end_inset
7689
7690 .
7691  SDCC uses an adapted version of the preprocessor 
7692 \emph on
7693 cpp
7694 \emph default
7695  of the GNU Compiler Collection
7696 \begin_inset LatexCommand index
7697 name "gcc (GNU Compiler Collection)"
7698
7699 \end_inset
7700
7701  (
7702 \emph on
7703 gcc
7704 \emph default
7705  
7706 \begin_inset LatexCommand url
7707 target "http://gcc.gnu.org/"
7708
7709 \end_inset
7710
7711 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7712 4.1.1\InsetSpace ~
7713 CPP\InsetSpace ~
7714 Manual
7715  at 
7716 \begin_inset LatexCommand htmlurl
7717 target "http://www.gnu.org/software/gcc/onlinedocs/"
7718
7719 \end_inset
7720
7721 .
7722 \end_layout
7723
7724 \begin_layout Standard
7725 \begin_inset VSpace bigskip
7726 \end_inset
7727
7728
7729 \end_layout
7730
7731 \begin_layout Subsection
7732 Linker Options
7733 \begin_inset LatexCommand index
7734 name "Options linker"
7735
7736 \end_inset
7737
7738
7739 \begin_inset LatexCommand index
7740 name "Linker options"
7741
7742 \end_inset
7743
7744
7745 \end_layout
7746
7747 \begin_layout List
7748 \labelwidthstring 00.00.0000
7749
7750 \series bold
7751 -L\InsetSpace ~
7752 -
7753 \series default
7754
7755 \begin_inset ERT
7756 status collapsed
7757
7758 \begin_layout Standard
7759
7760
7761 \backslash
7762 /
7763 \end_layout
7764
7765 \end_inset
7766
7767
7768 \series bold
7769 -lib-path
7770 \begin_inset LatexCommand index
7771 name "-\\/-lib-path <path>"
7772
7773 \end_inset
7774
7775
7776 \begin_inset LatexCommand index
7777 name "-L -\\/-lib-path"
7778
7779 \end_inset
7780
7781
7782 \series default
7783 \InsetSpace ~
7784 <absolute path to additional libraries> This option is passed to the linkage
7785  editor's additional libraries
7786 \begin_inset LatexCommand index
7787 name "Libraries"
7788
7789 \end_inset
7790
7791  search path.
7792  The path name must be absolute.
7793  Additional library files may be specified in the command line.
7794  See section Compiling programs for more details.
7795 \end_layout
7796
7797 \begin_layout List
7798 \labelwidthstring 00.00.0000
7799
7800 \series bold
7801 -
7802 \begin_inset ERT
7803 status collapsed
7804
7805 \begin_layout Standard
7806
7807
7808 \backslash
7809 /
7810 \end_layout
7811
7812 \end_inset
7813
7814 -xram-loc
7815 \series default
7816
7817 \begin_inset LatexCommand index
7818 name "-\\/-xram-loc <Value>"
7819
7820 \end_inset
7821
7822 \InsetSpace ~
7823 <Value> The start location of the external ram
7824 \begin_inset LatexCommand index
7825 name "xdata (mcs51, ds390 storage class)"
7826
7827 \end_inset
7828
7829 , default value is 0.
7830  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7831 \begin_inset ERT
7832 status collapsed
7833
7834 \begin_layout Standard
7835
7836
7837 \backslash
7838 /
7839 \end_layout
7840
7841 \end_inset
7842
7843 -xram-loc 0x8000 or -
7844 \begin_inset ERT
7845 status collapsed
7846
7847 \begin_layout Standard
7848
7849
7850 \backslash
7851 /
7852 \end_layout
7853
7854 \end_inset
7855
7856 -xram-loc 32768.
7857 \end_layout
7858
7859 \begin_layout List
7860 \labelwidthstring 00.00.0000
7861
7862 \series bold
7863 -
7864 \begin_inset ERT
7865 status collapsed
7866
7867 \begin_layout Standard
7868
7869
7870 \backslash
7871 /
7872 \end_layout
7873
7874 \end_inset
7875
7876 -code-loc
7877 \series default
7878
7879 \begin_inset LatexCommand index
7880 name "-\\/-code-loc <Value>"
7881
7882 \end_inset
7883
7884 \InsetSpace ~
7885 <Value> The start location of the code
7886 \begin_inset LatexCommand index
7887 name "code"
7888
7889 \end_inset
7890
7891  segment, default value 0.
7892  Note when this option is used the interrupt vector table
7893 \begin_inset LatexCommand index
7894 name "interrupt vector table"
7895
7896 \end_inset
7897
7898  is also relocated to the given address.
7899  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7900 \begin_inset ERT
7901 status collapsed
7902
7903 \begin_layout Standard
7904
7905
7906 \backslash
7907 /
7908 \end_layout
7909
7910 \end_inset
7911
7912 -code-loc 0x8000 or -
7913 \begin_inset ERT
7914 status collapsed
7915
7916 \begin_layout Standard
7917
7918
7919 \backslash
7920 /
7921 \end_layout
7922
7923 \end_inset
7924
7925 -code-loc 32768.
7926 \end_layout
7927
7928 \begin_layout List
7929 \labelwidthstring 00.00.0000
7930
7931 \series bold
7932 -
7933 \begin_inset ERT
7934 status collapsed
7935
7936 \begin_layout Standard
7937
7938
7939 \backslash
7940 /
7941 \end_layout
7942
7943 \end_inset
7944
7945 -stack-loc
7946 \series default
7947
7948 \begin_inset LatexCommand index
7949 name "-\\/-stack-loc <Value>"
7950
7951 \end_inset
7952
7953 \InsetSpace ~
7954 <Value> By default the stack
7955 \begin_inset LatexCommand index
7956 name "stack"
7957
7958 \end_inset
7959
7960  is placed after the data segment.
7961  Using this option the stack can be placed anywhere in the internal memory
7962  space of the 8051.
7963  The value entered can be in Hexadecimal or Decimal format, e.g.
7964  -
7965 \begin_inset ERT
7966 status collapsed
7967
7968 \begin_layout Standard
7969
7970
7971 \backslash
7972 /
7973 \end_layout
7974
7975 \end_inset
7976
7977 -stack-loc 0x20 or -
7978 \begin_inset ERT
7979 status collapsed
7980
7981 \begin_layout Standard
7982
7983
7984 \backslash
7985 /
7986 \end_layout
7987
7988 \end_inset
7989
7990 -stack-loc 32.
7991  Since the sp register is incremented before a push or call, the initial
7992  sp will be set to one byte prior the provided value.
7993  The provided value should not overlap any other memory areas such as used
7994  register banks or the data segment and with enough space for the current
7995  application.
7996  The 
7997 \series bold
7998 -
7999 \begin_inset ERT
8000 status collapsed
8001
8002 \begin_layout Standard
8003
8004
8005 \backslash
8006 /
8007 \end_layout
8008
8009 \end_inset
8010
8011 -pack-iram
8012 \series default
8013 \InsetSpace ~
8014
8015 \begin_inset LatexCommand index
8016 name "-\\/-pack-iram"
8017
8018 \end_inset
8019
8020  option (which is now a default setting) will override this setting, so
8021  you should also specify the 
8022 \series bold
8023 -
8024 \begin_inset ERT
8025 status collapsed
8026
8027 \begin_layout Standard
8028
8029
8030 \backslash
8031 /
8032 \end_layout
8033
8034 \end_inset
8035
8036 -no-pack-iram
8037 \series default
8038 \InsetSpace ~
8039
8040 \begin_inset LatexCommand index
8041 name "-\\/-no-pack-iram"
8042
8043 \end_inset
8044
8045  option if you need to manually place the stack.
8046 \end_layout
8047
8048 \begin_layout List
8049 \labelwidthstring 00.00.0000
8050
8051 \series bold
8052 -
8053 \begin_inset ERT
8054 status collapsed
8055
8056 \begin_layout Standard
8057
8058
8059 \backslash
8060 /
8061 \end_layout
8062
8063 \end_inset
8064
8065 -xstack-loc
8066 \series default
8067
8068 \begin_inset LatexCommand index
8069 name "-\\/-xstack-loc <Value>"
8070
8071 \end_inset
8072
8073 \InsetSpace ~
8074 <Value> By default the external stack
8075 \begin_inset LatexCommand index
8076 name "xstack"
8077
8078 \end_inset
8079
8080  is placed after the pdata
8081 \begin_inset LatexCommand index
8082 name "pdata (mcs51, ds390 storage class)"
8083
8084 \end_inset
8085
8086  segment.
8087  Using this option the xstack can be placed anywhere in the external memory
8088  space of the 8051.
8089  The value entered can be in Hexadecimal or Decimal format, e.g.
8090  -
8091 \begin_inset ERT
8092 status collapsed
8093
8094 \begin_layout Standard
8095
8096
8097 \backslash
8098 /
8099 \end_layout
8100
8101 \end_inset
8102
8103 -xstack-loc 0x8000 or -
8104 \begin_inset ERT
8105 status collapsed
8106
8107 \begin_layout Standard
8108
8109
8110 \backslash
8111 /
8112 \end_layout
8113
8114 \end_inset
8115
8116 -stack-loc 32768.
8117  The provided value should not overlap any other memory areas such as the
8118  pdata or xdata segment and with enough space for the current application.
8119 \end_layout
8120
8121 \begin_layout List
8122 \labelwidthstring 00.00.0000
8123
8124 \series bold
8125 -
8126 \begin_inset ERT
8127 status collapsed
8128
8129 \begin_layout Standard
8130
8131
8132 \backslash
8133 /
8134 \end_layout
8135
8136 \end_inset
8137
8138 -data-loc
8139 \series default
8140
8141 \begin_inset LatexCommand index
8142 name "-\\/-data-loc <Value>"
8143
8144 \end_inset
8145
8146 \InsetSpace ~
8147 <Value> The start location of the internal ram data
8148 \begin_inset LatexCommand index
8149 name "data (mcs51, ds390 storage class)"
8150
8151 \end_inset
8152
8153  segment.
8154  The value entered can be in Hexadecimal or Decimal format, eg.
8155  -
8156 \begin_inset ERT
8157 status collapsed
8158
8159 \begin_layout Standard
8160
8161
8162 \backslash
8163 /
8164 \end_layout
8165
8166 \end_inset
8167
8168 -data-loc 0x20 or -
8169 \begin_inset ERT
8170 status collapsed
8171
8172 \begin_layout Standard
8173
8174
8175 \backslash
8176 /
8177 \end_layout
8178
8179 \end_inset
8180
8181 -data-loc 32.
8182  (By default, the start location of the internal ram data segment  is set
8183  as low as possible in memory, taking into account the used register banks
8184  and the bit segment at address 0x20.
8185  For example if register banks 0 and 1 are used without bit variables, the
8186  data segment will be set, if -
8187 \begin_inset ERT
8188 status collapsed
8189
8190 \begin_layout Standard
8191
8192
8193 \backslash
8194 /
8195 \end_layout
8196
8197 \end_inset
8198
8199 -data-loc is not used, to location 0x10.)
8200 \end_layout
8201
8202 \begin_layout List
8203 \labelwidthstring 00.00.0000
8204
8205 \series bold
8206 -
8207 \begin_inset ERT
8208 status collapsed
8209
8210 \begin_layout Standard
8211
8212
8213 \backslash
8214 /
8215 \end_layout
8216
8217 \end_inset
8218
8219 -idata-loc
8220 \series default
8221
8222 \begin_inset LatexCommand index
8223 name "-\\/-idata-loc <Value>"
8224
8225 \end_inset
8226
8227 \InsetSpace ~
8228 <Value> The start location of the indirectly addressable internal ram
8229 \begin_inset LatexCommand index
8230 name "idata (mcs51, ds390 storage class)"
8231
8232 \end_inset
8233
8234  of the 8051, default value is 0x80.
8235  The value entered can be in Hexadecimal or Decimal format, eg.
8236  -
8237 \begin_inset ERT
8238 status collapsed
8239
8240 \begin_layout Standard
8241
8242
8243 \backslash
8244 /
8245 \end_layout
8246
8247 \end_inset
8248
8249 -idata-loc 0x88 or -
8250 \begin_inset ERT
8251 status collapsed
8252
8253 \begin_layout Standard
8254
8255
8256 \backslash
8257 /
8258 \end_layout
8259
8260 \end_inset
8261
8262 -idata-loc 136.
8263 \end_layout
8264
8265 \begin_layout List
8266 \labelwidthstring 00.00.0000
8267
8268 \series bold
8269 -
8270 \begin_inset ERT
8271 status collapsed
8272
8273 \begin_layout Standard
8274
8275
8276 \backslash
8277 /
8278 \end_layout
8279
8280 \end_inset
8281
8282 -bit-loc
8283 \series default
8284 \InsetSpace ~
8285 <Value> The start location of the bit
8286 \begin_inset LatexCommand index
8287 name "bit"
8288
8289 \end_inset
8290
8291  addressable internal ram of the 8051.
8292  This is 
8293 \emph on
8294 not
8295 \emph default
8296  implemented yet.
8297  Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
8298 -bBSEG=<Value>.
8299 \end_layout
8300
8301 \begin_layout List
8302 \labelwidthstring 00.00.0000
8303
8304 \series bold
8305 -
8306 \begin_inset ERT
8307 status collapsed
8308
8309 \begin_layout Standard
8310
8311
8312 \backslash
8313 /
8314 \end_layout
8315
8316 \end_inset
8317
8318 -out-fmt-ihx
8319 \begin_inset LatexCommand index
8320 name "-\\/-out-fmt-ihx"
8321
8322 \end_inset
8323
8324  
8325 \series default
8326 The linker output (final object code) is in Intel Hex format.
8327 \begin_inset LatexCommand index
8328 name "Intel hex format"
8329
8330 \end_inset
8331
8332  This is the default option.
8333  The format itself is documented in the documentation of srecord
8334 \begin_inset LatexCommand index
8335 name "srecord (bin, hex, ... tool)"
8336
8337 \end_inset
8338
8339 .
8340 \end_layout
8341
8342 \begin_layout List
8343 \labelwidthstring 00.00.0000
8344
8345 \series bold
8346 -
8347 \begin_inset ERT
8348 status collapsed
8349
8350 \begin_layout Standard
8351
8352
8353 \backslash
8354 /
8355 \end_layout
8356
8357 \end_inset
8358
8359 -out-fmt-s19
8360 \begin_inset LatexCommand index
8361 name "-\\/-out-fmt-s19"
8362
8363 \end_inset
8364
8365  
8366 \series default
8367 The linker output (final object code) is in Motorola S19 format
8368 \begin_inset LatexCommand index
8369 name "Motorola S19 format"
8370
8371 \end_inset
8372
8373 .
8374  The format itself is documented in the documentation of srecord.
8375 \end_layout
8376
8377 \begin_layout List
8378 \labelwidthstring 00.00.0000
8379
8380 \series bold
8381 -
8382 \begin_inset ERT
8383 status collapsed
8384
8385 \begin_layout Standard
8386
8387
8388 \backslash
8389 /
8390 \end_layout
8391
8392 \end_inset
8393
8394 -out-fmt-elf
8395 \begin_inset LatexCommand index
8396 name "-\\/-out-fmt-s19"
8397
8398 \end_inset
8399
8400
8401 \begin_inset LatexCommand index
8402 name "HC08!Options!-\\/-out-fmt-elf"
8403
8404 \end_inset
8405
8406  
8407 \series default
8408 The linker output (final object code) is in ELF format
8409 \begin_inset LatexCommand index
8410 name "ELF format"
8411
8412 \end_inset
8413
8414 .
8415  (Currently only supported for the HC08
8416 \begin_inset LatexCommand index
8417 name "HC08"
8418
8419 \end_inset
8420
8421  processors)
8422 \end_layout
8423
8424 \begin_layout List
8425 \labelwidthstring 00.00.0000
8426
8427 \series bold
8428 -Wl\InsetSpace ~
8429 linkOption[,linkOption]
8430 \series default
8431
8432 \begin_inset LatexCommand index
8433 name "-Wl linkOption[,linkOption]"
8434
8435 \end_inset
8436
8437
8438 \begin_inset LatexCommand label
8439 name "lyx:-Wl option"
8440
8441 \end_inset
8442
8443 ...
8444  Pass the linkOption to the linker.
8445  If a bootloader is used an option like 
8446 \begin_inset Quotes sld
8447 \end_inset
8448
8449 -Wl\InsetSpace ~
8450 -bCSEG=0x1000
8451 \begin_inset Quotes srd
8452 \end_inset
8453
8454  would be typical to set the start of the code segment.
8455  Either use the double quotes around this option or use no space (e.g.
8456  -Wl-bCSEG=0x1000).
8457  See also #pragma constseg and #pragma codeseg in section 
8458 \begin_inset LatexCommand ref
8459 reference "sec:Pragmas"
8460
8461 \end_inset
8462
8463  .
8464  File sdcc/as/doc/asxhtm.html has more on linker options.
8465 \end_layout
8466
8467 \begin_layout Standard
8468 \begin_inset VSpace bigskip
8469 \end_inset
8470
8471
8472 \end_layout
8473
8474 \begin_layout Subsection
8475 MCS51 Options
8476 \begin_inset LatexCommand index
8477 name "Options MCS51"
8478
8479 \end_inset
8480
8481
8482 \begin_inset LatexCommand index
8483 name "MCS51 options"
8484
8485 \end_inset
8486
8487
8488 \end_layout
8489
8490 \begin_layout List
8491 \labelwidthstring 00.00.0000
8492
8493 \series bold
8494 -
8495 \begin_inset ERT
8496 status collapsed
8497
8498 \begin_layout Standard
8499
8500
8501 \backslash
8502 /
8503 \end_layout
8504
8505 \end_inset
8506
8507 -model-small
8508 \begin_inset LatexCommand index
8509 name "-\\/-model-small"
8510
8511 \end_inset
8512
8513
8514 \series default
8515 \size large
8516  
8517 \size default
8518 Generate code for Small Model programs, see section Memory Models for more
8519  details.
8520  This is the default model.
8521 \end_layout
8522
8523 \begin_layout List
8524 \labelwidthstring 00.00.0000
8525
8526 \series bold
8527 -
8528 \begin_inset ERT
8529 status collapsed
8530
8531 \begin_layout Standard
8532
8533
8534 \backslash
8535 /
8536 \end_layout
8537
8538 \end_inset
8539
8540 -model-medium
8541 \begin_inset LatexCommand index
8542 name "-\\/-model-medium"
8543
8544 \end_inset
8545
8546
8547 \series default
8548  Generate code for Medium model programs, see section Memory Models for
8549  more details.
8550  If this option is used all source files in the project have to be compiled
8551  with this option.
8552  It must also be used when invoking the linker.
8553 \end_layout
8554
8555 \begin_layout List
8556 \labelwidthstring 00.00.0000
8557
8558 \series bold
8559 -
8560 \begin_inset ERT
8561 status collapsed
8562
8563 \begin_layout Standard
8564
8565
8566 \backslash
8567 /
8568 \end_layout
8569
8570 \end_inset
8571
8572 -model-large
8573 \begin_inset LatexCommand index
8574 name "-\\/-model-large"
8575
8576 \end_inset
8577
8578
8579 \series default
8580  Generate code for Large model programs, see section Memory Models for more
8581  details.
8582  If this option is used all source files in the project have to be compiled
8583  with this option.
8584  It must also be used when invoking the linker.
8585 \end_layout
8586
8587 \begin_layout List
8588 \labelwidthstring 00.00.0000
8589
8590 \series bold
8591 -
8592 \begin_inset ERT
8593 status collapsed
8594
8595 \begin_layout Standard
8596
8597
8598 \backslash
8599 /
8600 \end_layout
8601
8602 \end_inset
8603
8604 -xstack
8605 \begin_inset LatexCommand index
8606 name "-\\/-xstack"
8607
8608 \end_inset
8609
8610
8611 \series default
8612  Uses a pseudo stack in the pdata
8613 \begin_inset LatexCommand index
8614 name "pdata (mcs51, ds390 storage class)"
8615
8616 \end_inset
8617
8618  area (usually the first 256 bytes in the external ram) for allocating variables
8619  and passing parameters.
8620  See section 
8621 \begin_inset LatexCommand ref
8622 reference "sub:External-Stack"
8623
8624 \end_inset
8625
8626 \InsetSpace ~
8627  External Stack for more details.
8628 \end_layout
8629
8630 \begin_layout List
8631 \labelwidthstring 00.00.0000
8632
8633 \series bold
8634 -
8635 \begin_inset ERT
8636 status collapsed
8637
8638 \begin_layout Standard
8639
8640
8641 \backslash
8642 /
8643 \end_layout
8644
8645 \end_inset
8646
8647 -iram-size
8648 \series default
8649 \InsetSpace ~
8650 <Value>
8651 \begin_inset LatexCommand index
8652 name "-\\/-iram-size <Value>"
8653
8654 \end_inset
8655
8656  Causes the linker to check if the internal ram usage is within limits of
8657  the given value.
8658 \end_layout
8659
8660 \begin_layout List
8661 \labelwidthstring 00.00.0000
8662
8663 \series bold
8664 -
8665 \begin_inset ERT
8666 status collapsed
8667
8668 \begin_layout Standard
8669
8670
8671 \backslash
8672 /
8673 \end_layout
8674
8675 \end_inset
8676
8677 -xram-size
8678 \series default
8679 \InsetSpace ~
8680 <Value>
8681 \begin_inset LatexCommand index
8682 name "-\\/-xram-size <Value>"
8683
8684 \end_inset
8685
8686  Causes the linker to check if the external ram usage is within limits of
8687  the given value.
8688 \end_layout
8689
8690 \begin_layout List
8691 \labelwidthstring 00.00.0000
8692
8693 \series bold
8694 -
8695 \begin_inset ERT
8696 status collapsed
8697
8698 \begin_layout Standard
8699
8700
8701 \backslash
8702 /
8703 \end_layout
8704
8705 \end_inset
8706
8707 -code-size
8708 \series default
8709 \InsetSpace ~
8710 <Value>
8711 \begin_inset LatexCommand index
8712 name "-\\/-code-size <Value>"
8713
8714 \end_inset
8715
8716  Causes the linker to check if the code memory usage is within limits of
8717  the given value.
8718 \end_layout
8719
8720 \begin_layout List
8721 \labelwidthstring 00.00.0000
8722
8723 \series bold
8724 -
8725 \begin_inset ERT
8726 status collapsed
8727
8728 \begin_layout Standard
8729
8730
8731 \backslash
8732 /
8733 \end_layout
8734
8735 \end_inset
8736
8737 -stack-size
8738 \series default
8739 \InsetSpace ~
8740 <Value>
8741 \begin_inset LatexCommand index
8742 name "-\\/-stack-size <Value>"
8743
8744 \end_inset
8745
8746  Causes the linker to check if there is at minimum <Value> bytes for stack.
8747 \end_layout
8748
8749 \begin_layout List
8750 \labelwidthstring 00.00.0000
8751
8752 \series bold
8753 -
8754 \begin_inset ERT
8755 status collapsed
8756
8757 \begin_layout Standard
8758
8759
8760 \backslash
8761 /
8762 \end_layout
8763
8764 \end_inset
8765
8766 -pack-iram
8767 \series default
8768 \InsetSpace ~
8769
8770 \begin_inset LatexCommand index
8771 name "-\\/-pack-iram"
8772
8773 \end_inset
8774
8775  Causes the linker to use unused register banks for data variables and pack
8776  data, idata and stack together.
8777  This is the default now.
8778 \end_layout
8779
8780 \begin_layout List
8781 \labelwidthstring 00.00.0000
8782
8783 \series bold
8784 -
8785 \begin_inset ERT
8786 status collapsed
8787
8788 \begin_layout Standard
8789
8790
8791 \backslash
8792 /
8793 \end_layout
8794
8795 \end_inset
8796
8797 -no-pack-iram
8798 \series default
8799 \InsetSpace ~
8800
8801 \begin_inset LatexCommand index
8802 name "-\\/-no-pack-iram"
8803
8804 \end_inset
8805
8806  Causes the linker to use old style for allocating memory areas.
8807 \end_layout
8808
8809 \begin_layout List
8810 \labelwidthstring 00.00.0000
8811
8812 \series bold
8813 -
8814 \begin_inset ERT
8815 status collapsed
8816
8817 \begin_layout Standard
8818
8819
8820 \backslash
8821 /
8822 \end_layout
8823
8824 \end_inset
8825
8826 -acall-ajmp
8827 \series default
8828 \InsetSpace ~
8829
8830 \begin_inset LatexCommand index
8831 name "-\\/-acall-ajmp"
8832
8833 \end_inset
8834
8835  Replaces the three byte instructions lcall/ljmp with the two byte instructions
8836  acall/ajmp.
8837  Only use this option if your code is in the same 2k block of memory.
8838  You may need to use this option for some 8051 derivatives which lack the
8839  lcall/ljmp instructions..
8840 \end_layout
8841
8842 \begin_layout Standard
8843 \begin_inset VSpace bigskip
8844 \end_inset
8845
8846
8847 \end_layout
8848
8849 \begin_layout Subsection
8850 DS390 / DS400 Options
8851 \begin_inset LatexCommand index
8852 name "Options DS390"
8853
8854 \end_inset
8855
8856
8857 \begin_inset LatexCommand index
8858 name "DS390"
8859
8860 \end_inset
8861
8862
8863 \end_layout
8864
8865 \begin_layout List
8866 \labelwidthstring 00.00.0000
8867
8868 \series bold
8869 -
8870 \begin_inset ERT
8871 status collapsed
8872
8873 \begin_layout Standard
8874
8875
8876 \backslash
8877 /
8878 \end_layout
8879
8880 \end_inset
8881
8882 -model-flat24
8883 \series default
8884
8885 \begin_inset LatexCommand index
8886 name "DS390!Options!-\\/-model-flat24"
8887
8888 \end_inset
8889
8890
8891 \size large
8892  
8893 \size default
8894 Generate 24-bit flat mode code.
8895  This is the one and only that the ds390 code generator supports right now
8896  and is default when using 
8897 \emph on
8898 -mds390
8899 \emph default
8900 .
8901  See section Memory Models for more details.
8902 \end_layout
8903
8904 \begin_layout List
8905 \labelwidthstring 00.00.0000
8906
8907 \series bold
8908 -
8909 \begin_inset ERT
8910 status collapsed
8911
8912 \begin_layout Standard
8913
8914
8915 \backslash
8916 /
8917 \end_layout
8918
8919 \end_inset
8920
8921 -protect-sp-update
8922 \begin_inset LatexCommand index
8923 name "DS390!Options!-\\/-protect-sp-update"
8924
8925 \end_inset
8926
8927
8928 \series default
8929  disable interrupts during ESP:SP updates.
8930 \end_layout
8931
8932 \begin_layout List
8933 \labelwidthstring 00.00.0000
8934
8935 \series bold
8936 -
8937 \begin_inset ERT
8938 status collapsed
8939
8940 \begin_layout Standard
8941
8942
8943 \backslash
8944 /
8945 \end_layout
8946
8947 \end_inset
8948
8949 -stack-10bit
8950 \series default
8951
8952 \begin_inset LatexCommand index
8953 name "DS390!Options!-\\/-stack-10bit"
8954
8955 \end_inset
8956
8957  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8958  This is the one and only that the ds390 code generator supports right now
8959  and is default when using 
8960 \emph on
8961 -mds390
8962 \emph default
8963 .
8964  In this mode, the stack is located in the lower 1K of the internal RAM,
8965  which is mapped to 0x400000.
8966  Note that the support is incomplete, since it still uses a single byte
8967  as the stack pointer.
8968  This means that only the lower 256 bytes of the potential 1K stack space
8969  will actually be used.
8970  However, this does allow you to reclaim the precious 256 bytes of low RAM
8971  for use for the DATA and IDATA segments.
8972  The compiler will not generate any code to put the processor into 10 bit
8973  stack mode.
8974  It is important to ensure that the processor is in this mode before calling
8975  any re-entrant functions compiled with this option.
8976  In principle, this should work with the 
8977 \emph on
8978 -
8979 \begin_inset ERT
8980 status collapsed
8981
8982 \begin_layout Standard
8983
8984
8985 \backslash
8986 /
8987 \end_layout
8988
8989 \end_inset
8990
8991 -stack-auto
8992 \begin_inset LatexCommand index
8993 name "-\\/-stack-auto"
8994
8995 \end_inset
8996
8997
8998 \emph default
8999  option, but that has not been tested.
9000  It is incompatible with the 
9001 \emph on
9002 -
9003 \begin_inset ERT
9004 status collapsed
9005
9006 \begin_layout Standard
9007
9008
9009 \backslash
9010 /
9011 \end_layout
9012
9013 \end_inset
9014
9015 -xstack
9016 \begin_inset LatexCommand index
9017 name "-\\/-xstack"
9018
9019 \end_inset
9020
9021
9022 \emph default
9023  option.
9024  It also only makes sense if the processor is in 24 bit contiguous addressing
9025  mode (see the 
9026 \emph on
9027 -
9028 \begin_inset ERT
9029 status collapsed
9030
9031 \begin_layout Standard
9032
9033
9034 \backslash
9035 /
9036 \end_layout
9037
9038 \end_inset
9039
9040 -model-flat24 option
9041 \emph default
9042 ).
9043 \series bold
9044
9045 \begin_inset Note Note
9046 status collapsed
9047
9048 \begin_layout List
9049 \labelwidthstring 00.00.0000
9050
9051 \series bold
9052 -
9053 \begin_inset ERT
9054 status open
9055
9056 \begin_layout Standard
9057
9058
9059 \backslash
9060 /
9061 \end_layout
9062
9063 \end_inset
9064
9065 -stack-8-bit - switches off the 10-bit mode
9066 \end_layout
9067
9068 \end_inset
9069
9070
9071 \end_layout
9072
9073 \begin_layout List
9074 \labelwidthstring 00.00.0000
9075
9076 \series bold
9077 -
9078 \begin_inset ERT
9079 status collapsed
9080
9081 \begin_layout Standard
9082
9083
9084 \backslash
9085 /
9086 \end_layout
9087
9088 \end_inset
9089
9090 -stack-probe
9091 \begin_inset LatexCommand index
9092 name "DS390!Options!-\\/-stack-probe"
9093
9094 \end_inset
9095
9096
9097 \series default
9098  insert call to function __stack_probe at each function prologue.
9099 \end_layout
9100
9101 \begin_layout List
9102 \labelwidthstring 00.00.0000
9103
9104 \series bold
9105 -
9106 \begin_inset ERT
9107 status open
9108
9109 \begin_layout Standard
9110
9111
9112 \backslash
9113 /
9114 \end_layout
9115
9116 \end_inset
9117
9118 -tini-libid
9119 \begin_inset LatexCommand index
9120 name "DS390!Options!-\\/-tini-libid"
9121
9122 \end_inset
9123
9124
9125 \series default
9126  <nnnn> LibraryID used in -mTININative.
9127  
9128 \end_layout
9129
9130 \begin_layout List
9131 \labelwidthstring 00.00.0000
9132
9133 \series bold
9134 -
9135 \begin_inset ERT
9136 status collapsed
9137
9138 \begin_layout Standard
9139
9140
9141 \backslash
9142 /
9143 \end_layout
9144
9145 \end_inset
9146
9147 -use-accelerator
9148 \begin_inset LatexCommand index
9149 name "DS390!Options!-\\/-use-accelerator"
9150
9151 \end_inset
9152
9153
9154 \series default
9155  generate code for DS390 Arithmetic Accelerator.
9156  
9157 \end_layout
9158
9159 \begin_layout Standard
9160 \begin_inset VSpace bigskip
9161 \end_inset
9162
9163
9164 \end_layout
9165
9166 \begin_layout Subsection
9167 Z80 Options
9168 \begin_inset LatexCommand index
9169 name "Options Z80"
9170
9171 \end_inset
9172
9173
9174 \begin_inset LatexCommand index
9175 name "Z80"
9176
9177 \end_inset
9178
9179
9180 \end_layout
9181
9182 \begin_layout List
9183 \labelwidthstring 00.00.0000
9184
9185 \series bold
9186 -
9187 \begin_inset ERT
9188 status collapsed
9189
9190 \begin_layout Standard
9191
9192
9193 \backslash
9194 /
9195 \end_layout
9196
9197 \end_inset
9198
9199 -callee-saves-bc
9200 \series default
9201
9202 \begin_inset LatexCommand index
9203 name "Z80!Options!-\\/-callee-saves-bc"
9204
9205 \end_inset
9206
9207
9208 \size large
9209  
9210 \size default
9211 Force a called function to always save BC.
9212 \end_layout
9213
9214 \begin_layout List
9215 \labelwidthstring 00.00.0000
9216
9217 \series bold
9218 -
9219 \begin_inset ERT
9220 status collapsed
9221
9222 \begin_layout Standard
9223
9224
9225 \backslash
9226 /
9227 \end_layout
9228
9229 \end_inset
9230
9231 -no-std-crt0
9232 \series default
9233
9234 \begin_inset LatexCommand index
9235 name "Z80!Options!-\\/-no-std-crt0"
9236
9237 \end_inset
9238
9239  When linking, skip the standard crt0.o object file.
9240  You must provide your own crt0.o for your system when linking.
9241 \end_layout
9242
9243 \begin_layout List
9244 \labelwidthstring 00.00.0000
9245
9246 \series bold
9247 -
9248 \begin_inset ERT
9249 status collapsed
9250
9251 \begin_layout Standard
9252
9253
9254 \backslash
9255 /
9256 \end_layout
9257
9258 \end_inset
9259
9260 -portmode=
9261 \series default
9262 <Value>
9263 \begin_inset LatexCommand index
9264 name "Z80!Options!-\\/-portmode=<Value>"
9265
9266 \end_inset
9267
9268  Determinate PORT I/O mode (<Value> is z80 or z180).
9269 \end_layout
9270
9271 \begin_layout List
9272 \labelwidthstring 00.00.0000
9273
9274 \series bold
9275 -
9276 \begin_inset ERT
9277 status collapsed
9278
9279 \begin_layout Standard
9280
9281
9282 \backslash
9283 /
9284 \end_layout
9285
9286 \end_inset
9287
9288 -asm=
9289 \series default
9290 <Value>
9291 \begin_inset LatexCommand index
9292 name "Z80!Options!-\\/-asm=<Value>"
9293
9294 \end_inset
9295
9296  Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
9297 \end_layout
9298
9299 \begin_layout List
9300 \labelwidthstring 00.00.0000
9301
9302 \series bold
9303 -
9304 \begin_inset ERT
9305 status collapsed
9306
9307 \begin_layout Standard
9308
9309
9310 \backslash
9311 /
9312 \end_layout
9313
9314 \end_inset
9315
9316 -codeseg
9317 \series default
9318 \InsetSpace ~
9319 <Value>
9320 \begin_inset LatexCommand index
9321 name "Z80!Options!-\\/-codeseg <Value>"
9322
9323 \end_inset
9324
9325  Use <Value> for the code segment name.
9326 \end_layout
9327
9328 \begin_layout List
9329 \labelwidthstring 00.00.0000
9330
9331 \series bold
9332 -
9333 \begin_inset ERT
9334 status collapsed
9335
9336 \begin_layout Standard
9337
9338
9339 \backslash
9340 /
9341 \end_layout
9342
9343 \end_inset
9344
9345 -constseg
9346 \series default
9347 \InsetSpace ~
9348 <Value>
9349 \begin_inset LatexCommand index
9350 name "Z80!Options!-\\/-constseg <Value>"
9351
9352 \end_inset
9353
9354  Use <Value> for the const segment name.
9355 \end_layout
9356
9357 \begin_layout List
9358 \labelwidthstring 00.00.0000
9359 \begin_inset VSpace bigskip
9360 \end_inset
9361
9362
9363 \end_layout
9364
9365 \begin_layout Subsection
9366 GBZ80 Options
9367 \begin_inset LatexCommand index
9368 name "Options GBZ80"
9369
9370 \end_inset
9371
9372
9373 \begin_inset LatexCommand index
9374 name "GBZ80"
9375
9376 \end_inset
9377
9378
9379 \end_layout
9380
9381 \begin_layout List
9382 \labelwidthstring 00.00.0000
9383
9384 \series bold
9385 -
9386 \begin_inset ERT
9387 status collapsed
9388
9389 \begin_layout Standard
9390
9391
9392 \backslash
9393 /
9394 \end_layout
9395
9396 \end_inset
9397
9398 -callee-saves-bc
9399 \series default
9400
9401 \begin_inset LatexCommand index
9402 name "GBZ80!Options!-\\/-callee-saves-bc"
9403
9404 \end_inset
9405
9406
9407 \size large
9408  
9409 \size default
9410 Force a called function to always save BC.
9411 \end_layout
9412
9413 \begin_layout List
9414 \labelwidthstring 00.00.0000
9415
9416 \series bold
9417 -
9418 \begin_inset ERT
9419 status collapsed
9420
9421 \begin_layout Standard
9422
9423
9424 \backslash
9425 /
9426 \end_layout
9427
9428 \end_inset
9429
9430 -no-std-crt0
9431 \series default
9432
9433 \begin_inset LatexCommand index
9434 name "Z80!Options!-\\/-no-std-crt0"
9435
9436 \end_inset
9437
9438  When linking, skip the standard crt0.o object file.
9439  You must provide your own crt0.o for your system when linking.
9440 \end_layout
9441
9442 \begin_layout List
9443 \labelwidthstring 00.00.0000
9444
9445 \series bold
9446 -bo
9447 \series default
9448 \InsetSpace ~
9449 <Num>
9450 \begin_inset LatexCommand index
9451 name "GBZ80!Options!-bo <Num>"
9452
9453 \end_inset
9454
9455  Use code bank <Num>.
9456 \end_layout
9457
9458 \begin_layout List
9459 \labelwidthstring 00.00.0000
9460
9461 \series bold
9462 -ba
9463 \series default
9464 \InsetSpace ~
9465 <Num>
9466 \begin_inset LatexCommand index
9467 name "GBZ80!Options!-ba <Num>"
9468
9469 \end_inset
9470
9471  Use data bank <Num>.
9472 \end_layout
9473
9474 \begin_layout List
9475 \labelwidthstring 00.00.0000
9476
9477 \series bold
9478 -
9479 \begin_inset ERT
9480 status collapsed
9481
9482 \begin_layout Standard
9483
9484
9485 \backslash
9486 /
9487 \end_layout
9488
9489 \end_inset
9490
9491 -codeseg
9492 \series default
9493 \InsetSpace ~
9494 <Value>
9495 \begin_inset LatexCommand index
9496 name "GBZ80!Options!-\\/-codeseg <Value>"
9497
9498 \end_inset
9499
9500  Use <Value> for the code segment name.
9501 \end_layout
9502
9503 \begin_layout List
9504 \labelwidthstring 00.00.0000
9505
9506 \series bold
9507 -
9508 \begin_inset ERT
9509 status collapsed
9510
9511 \begin_layout Standard
9512
9513
9514 \backslash
9515 /
9516 \end_layout
9517
9518 \end_inset
9519
9520 -constseg
9521 \series default
9522 \InsetSpace ~
9523 <Value>
9524 \begin_inset LatexCommand index
9525 name "GBZ80!Options!-\\/-constseg <Value>"
9526
9527 \end_inset
9528
9529  Use <Value> for the const segment name.
9530 \end_layout
9531
9532 \begin_layout Standard
9533 \begin_inset VSpace bigskip
9534 \end_inset
9535
9536
9537 \end_layout
9538
9539 \begin_layout Subsection
9540 Optimization Options
9541 \begin_inset LatexCommand index
9542 name "Options optimization"
9543
9544 \end_inset
9545
9546
9547 \begin_inset LatexCommand index
9548 name "Optimization options"
9549
9550 \end_inset
9551
9552
9553 \end_layout
9554
9555 \begin_layout List
9556 \labelwidthstring 00.00.0000
9557
9558 \series bold
9559 -
9560 \begin_inset ERT
9561 status collapsed
9562
9563 \begin_layout Standard
9564
9565
9566 \backslash
9567 /
9568 \end_layout
9569
9570 \end_inset
9571
9572 -nogcse
9573 \begin_inset LatexCommand index
9574 name "-\\/-nogcse"
9575
9576 \end_inset
9577
9578
9579 \series default
9580  Will not do global subexpression elimination, this option may be used when
9581  the compiler creates undesirably large stack/data spaces to store compiler
9582  temporaries (
9583 \emph on
9584 s
9585 \emph default
9586 pill 
9587 \emph on
9588 loc
9589 \emph default
9590 ations, sloc
9591 \begin_inset LatexCommand index
9592 name "sloc (spill location)"
9593
9594 \end_inset
9595
9596 ).
9597  A warning message will be generated when this happens and the compiler
9598  will indicate the number of extra bytes it allocated.
9599  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9600 nogcse
9601 \begin_inset LatexCommand index
9602 name "\\#pragma nogcse"
9603
9604 \end_inset
9605
9606  can be used to turn off global subexpression elimination
9607 \begin_inset LatexCommand index
9608 name "Subexpression elimination"
9609
9610 \end_inset
9611
9612  for a given function only.
9613 \end_layout
9614
9615 \begin_layout List
9616 \labelwidthstring 00.00.0000
9617
9618 \series bold
9619 -
9620 \begin_inset ERT
9621 status collapsed
9622
9623 \begin_layout Standard
9624
9625
9626 \backslash
9627 /
9628 \end_layout
9629
9630 \end_inset
9631
9632 -noinvariant
9633 \begin_inset LatexCommand index
9634 name "-\\/-noinvariant"
9635
9636 \end_inset
9637
9638
9639 \series default
9640  Will not do loop invariant optimizations, this may be turned off for reasons
9641  explained for the previous option.
9642  For more details of loop optimizations performed see Loop Invariants in
9643  section 
9644 \begin_inset LatexCommand ref
9645 reference "sub:Loop-Optimizations"
9646
9647 \end_inset
9648
9649 .
9650  It is recommended that this option NOT be used, #pragma\InsetSpace ~
9651 noinvariant
9652 \begin_inset LatexCommand index
9653 name "\\#pragma noinvariant"
9654
9655 \end_inset
9656
9657  can be used to turn off invariant optimizations for a given function only.
9658 \end_layout
9659
9660 \begin_layout List
9661 \labelwidthstring 00.00.0000
9662
9663 \series bold
9664 -
9665 \begin_inset ERT
9666 status collapsed
9667
9668 \begin_layout Standard
9669
9670
9671 \backslash
9672 /
9673 \end_layout
9674
9675 \end_inset
9676
9677 -noinduction
9678 \begin_inset LatexCommand index
9679 name "-\\/-noinduction"
9680
9681 \end_inset
9682
9683
9684 \series default
9685  Will not do loop induction optimizations, see section strength reduction
9686  for more details.
9687  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9688 noinduction
9689 \begin_inset LatexCommand index
9690 name "\\#pragma noinduction"
9691
9692 \end_inset
9693
9694  can be used to turn off induction optimizations for a given function only.
9695 \end_layout
9696
9697 \begin_layout List
9698 \labelwidthstring 00.00.0000
9699
9700 \series bold
9701 -
9702 \begin_inset ERT
9703 status collapsed
9704
9705 \begin_layout Standard
9706
9707
9708 \backslash
9709 /
9710 \end_layout
9711
9712 \end_inset
9713
9714 -nojtbound
9715 \begin_inset LatexCommand index
9716 name "-\\/-nojtbound"
9717
9718 \end_inset
9719
9720
9721 \size large
9722  
9723 \series default
9724 \size default
9725  Will not generate boundary condition check when switch statements
9726 \begin_inset LatexCommand index
9727 name "switch statement"
9728
9729 \end_inset
9730
9731  are implemented using jump-tables.
9732  See section 
9733 \begin_inset LatexCommand ref
9734 reference "sub:'switch'-Statements"
9735
9736 \end_inset
9737
9738 \InsetSpace ~
9739 Switch Statements for more details.
9740  It is recommended that this option is NOT used, #pragma\InsetSpace ~
9741 nojtbound
9742 \begin_inset LatexCommand index
9743 name "\\#pragma nojtbound"
9744
9745 \end_inset
9746
9747  can be used to turn off boundary checking for jump tables for a given function
9748  only.
9749 \end_layout
9750
9751 \begin_layout List
9752 \labelwidthstring 00.00.0000
9753
9754 \series bold
9755 -
9756 \begin_inset ERT
9757 status collapsed
9758
9759 \begin_layout Standard
9760
9761
9762 \backslash
9763 /
9764 \end_layout
9765
9766 \end_inset
9767
9768 -noloopreverse
9769 \begin_inset LatexCommand index
9770 name "-\\/-noloopreverse"
9771
9772 \end_inset
9773
9774
9775 \series default
9776 \size large
9777  
9778 \size default
9779 Will not do loop reversal 
9780 \begin_inset LatexCommand index
9781 name "Loop reversing"
9782
9783 \end_inset
9784
9785 optimization.
9786 \end_layout
9787
9788 \begin_layout List
9789 \labelwidthstring 00.00.0000
9790 -
9791 \begin_inset ERT
9792 status collapsed
9793
9794 \begin_layout Standard
9795
9796
9797 \backslash
9798 /
9799 \end_layout
9800
9801 \end_inset
9802
9803 -
9804 \series bold
9805 nolabelopt
9806 \series default
9807  
9808 \begin_inset LatexCommand index
9809 name "-\\/-nolabelopt "
9810
9811 \end_inset
9812
9813 Will not optimize labels (makes the dumpfiles more readable).
9814 \end_layout
9815
9816 \begin_layout List
9817 \labelwidthstring 00.00.0000
9818
9819 \series bold
9820 -
9821 \begin_inset ERT
9822 status collapsed
9823
9824 \begin_layout Standard
9825
9826
9827 \backslash
9828 /
9829 \end_layout
9830
9831 \end_inset
9832
9833 -no-xinit-opt
9834 \begin_inset LatexCommand index
9835 name "-\\/-no-xinit-opt"
9836
9837 \end_inset
9838
9839
9840 \series default
9841  Will not memcpy initialized data from code space into xdata space.
9842  This saves a few bytes in code space if you don't have initialized data
9843 \begin_inset LatexCommand index
9844 name "Variable initialization"
9845
9846 \end_inset
9847
9848 .
9849 \end_layout
9850
9851 \begin_layout List
9852 \labelwidthstring 00.00.0000
9853
9854 \series bold
9855 -
9856 \begin_inset ERT
9857 status collapsed
9858
9859 \begin_layout Standard
9860
9861
9862 \backslash
9863 /
9864 \end_layout
9865
9866 \end_inset
9867
9868 -nooverlay
9869 \begin_inset LatexCommand index
9870 name "-\\/-nooverlay"
9871
9872 \end_inset
9873
9874
9875 \series default
9876   The compiler will not overlay parameters and local variables of any function,
9877  see section Parameters and local variables for more details.
9878 \end_layout
9879
9880 \begin_layout List
9881 \labelwidthstring 00.00.0000
9882
9883 \series bold
9884 -
9885 \begin_inset ERT
9886 status collapsed
9887
9888 \begin_layout Standard
9889
9890
9891 \backslash
9892 /
9893 \end_layout
9894
9895 \end_inset
9896
9897 -no-peep
9898 \begin_inset LatexCommand index
9899 name "-\\/-no-peep"
9900
9901 \end_inset
9902
9903
9904 \series default
9905  Disable peep-hole optimization with built-in rules.
9906 \end_layout
9907
9908 \begin_layout List
9909 \labelwidthstring 00.00.0000
9910
9911 \series bold
9912 -
9913 \begin_inset ERT
9914 status collapsed
9915
9916 \begin_layout Standard
9917
9918
9919 \backslash
9920 /
9921 \end_layout
9922
9923 \end_inset
9924
9925 -peep-file
9926 \series default
9927
9928 \begin_inset LatexCommand index
9929 name "-\\/-peep-file"
9930
9931 \end_inset
9932
9933 \InsetSpace ~
9934 <filename> This option can be used to use additional rules to be used by
9935  the peep hole optimizer.
9936  See section 
9937 \begin_inset LatexCommand ref
9938 reference "sub:Peephole-Optimizer"
9939
9940 \end_inset
9941
9942 \InsetSpace ~
9943 Peep Hole optimizations for details on how to write these rules.
9944 \end_layout
9945
9946 \begin_layout List
9947 \labelwidthstring 00.00.0000
9948
9949 \series bold
9950 -
9951 \begin_inset ERT
9952 status collapsed
9953
9954 \begin_layout Standard
9955
9956
9957 \backslash
9958 /
9959 \end_layout
9960
9961 \end_inset
9962
9963 -peep-asm
9964 \begin_inset LatexCommand index
9965 name "-\\/-peep-asm"
9966
9967 \end_inset
9968
9969
9970 \series default
9971  Pass the inline assembler code through the peep hole optimizer.
9972  This can cause unexpected changes to inline assembler code, please go through
9973  the peephole optimizer
9974 \begin_inset LatexCommand index
9975 name "Peephole optimizer"
9976
9977 \end_inset
9978
9979  rules defined in the source file tree '<target>/peeph.def' before using
9980  this option.
9981 \end_layout
9982
9983 \begin_layout List
9984 \labelwidthstring 00.00.0000
9985
9986 \series bold
9987 -
9988 \begin_inset ERT
9989 status collapsed
9990
9991 \begin_layout Standard
9992
9993
9994 \backslash
9995 /
9996 \end_layout
9997
9998 \end_inset
9999
10000 -opt-code-speed
10001 \begin_inset LatexCommand index
10002 name "-\\/-opt-code-speed"
10003
10004 \end_inset
10005
10006
10007 \series default
10008  The compiler will optimize code generation towards fast code, possibly
10009  at the expense of code size.
10010 \end_layout
10011
10012 \begin_layout List
10013 \labelwidthstring 00.00.0000
10014
10015 \series bold
10016 -
10017 \begin_inset ERT
10018 status collapsed
10019
10020 \begin_layout Standard
10021
10022
10023 \backslash
10024 /
10025 \end_layout
10026
10027 \end_inset
10028
10029 -opt-code-size
10030 \begin_inset LatexCommand index
10031 name "-\\/-opt-code-size"
10032
10033 \end_inset
10034
10035
10036 \series default
10037  The compiler will optimize code generation towards compact code, possibly
10038  at the expense of code speed.
10039 \end_layout
10040
10041 \begin_layout Standard
10042 \begin_inset VSpace bigskip
10043 \end_inset
10044
10045
10046 \end_layout
10047
10048 \begin_layout Subsection
10049 Other Options
10050 \begin_inset LatexCommand index
10051 name "Options other"
10052
10053 \end_inset
10054
10055
10056 \end_layout
10057
10058 \begin_layout List
10059 \labelwidthstring 00.00.0000
10060
10061 \series bold
10062 -c\InsetSpace ~
10063 -
10064 \begin_inset ERT
10065 status collapsed
10066
10067 \begin_layout Standard
10068
10069
10070 \backslash
10071 /
10072 \end_layout
10073
10074 \end_inset
10075
10076 -compile-only
10077 \begin_inset LatexCommand index
10078 name "-\\/-compile-only"
10079
10080 \end_inset
10081
10082
10083 \begin_inset LatexCommand index
10084 name "-c -\\/-compile-only"
10085
10086 \end_inset
10087
10088
10089 \series default
10090  will compile and assemble the source, but will not call the linkage editor.
10091 \end_layout
10092
10093 \begin_layout List
10094 \labelwidthstring 00.00.0000
10095
10096 \series bold
10097 -
10098 \series default
10099
10100 \begin_inset ERT
10101 status collapsed
10102
10103 \begin_layout Standard
10104
10105
10106 \backslash
10107 /
10108 \end_layout
10109
10110 \end_inset
10111
10112
10113 \series bold
10114 -c1mode
10115 \begin_inset LatexCommand index
10116 name "-\\/-c1mode"
10117
10118 \end_inset
10119
10120
10121 \series default
10122  reads the preprocessed source from standard input and compiles it.
10123  The file name for the assembler output must be specified using the -o option.
10124 \end_layout
10125
10126 \begin_layout List
10127 \labelwidthstring 00.00.0000
10128
10129 \series bold
10130 -E
10131 \begin_inset LatexCommand index
10132 name "-E"
10133
10134 \end_inset
10135
10136
10137 \series default
10138  Run only the C preprocessor.
10139  Preprocess all the C source files specified and output the results to standard
10140  output.
10141 \end_layout
10142
10143 \begin_layout List
10144 \labelwidthstring 00.00.0000
10145
10146 \series bold
10147 -o\InsetSpace ~
10148 <path/file>
10149 \begin_inset LatexCommand index
10150 name "-o <path/file>"
10151
10152 \end_inset
10153
10154
10155 \series default
10156  The output path where everything will be placed or the file name used for
10157  all generated output files.
10158  If the parameter is a path, it must have a trailing slash (or backslash
10159  for the Windows binaries) to be recognized as a path.
10160  Note for Windows users: if the path contains spaces, it should be surrounded
10161  by quotes.
10162  The trailing backslash should be doubled in order to prevent escaping the
10163  final quote, for example: 
10164 \emph on
10165 -o 
10166 \begin_inset Quotes sld
10167 \end_inset
10168
10169 F:
10170 \backslash
10171 Projects
10172 \backslash
10173 test3
10174 \backslash
10175 output 1
10176 \backslash
10177
10178 \backslash
10179
10180 \begin_inset Quotes srd
10181 \end_inset
10182
10183
10184 \emph default
10185  or put after the final quote, for example: 
10186 \emph on
10187 -o 
10188 \begin_inset Quotes sld
10189 \end_inset
10190
10191 F:
10192 \backslash
10193 Projects
10194 \backslash
10195 test3
10196 \backslash
10197 output 1
10198 \begin_inset Quotes srd
10199 \end_inset
10200
10201
10202 \backslash
10203
10204 \emph default
10205 .
10206  The path using slashes for directory delimiters can be used too, for example:
10207  
10208 \emph on
10209 -o 
10210 \begin_inset Quotes sld
10211 \end_inset
10212
10213 F:/Projects/test3/output 1/
10214 \begin_inset Quotes srd
10215 \end_inset
10216
10217
10218 \emph default
10219 .
10220 \end_layout
10221
10222 \begin_layout List
10223 \labelwidthstring 00.00.0000
10224
10225 \series bold
10226 -
10227 \begin_inset ERT
10228 status collapsed
10229
10230 \begin_layout Standard
10231
10232
10233 \backslash
10234 /
10235 \end_layout
10236
10237 \end_inset
10238
10239 -stack-auto
10240 \begin_inset LatexCommand index
10241 name "-\\/-stack-auto"
10242
10243 \end_inset
10244
10245
10246 \series default
10247 \size large
10248  
10249 \size default
10250 All functions in the source file will be compiled as 
10251 \emph on
10252 reentrant
10253 \emph default
10254
10255 \begin_inset LatexCommand index
10256 name "reentrant"
10257
10258 \end_inset
10259
10260 , i.e.
10261  the parameters and local variables will be allocated on the stack
10262 \begin_inset LatexCommand index
10263 name "stack"
10264
10265 \end_inset
10266
10267 .
10268  See section 
10269 \begin_inset LatexCommand ref
10270 reference "sec:Parameters-and-Local-Variables"
10271
10272 \end_inset
10273
10274  Parameters and Local Variables for more details.
10275  If this option is used all source files in the project should be compiled
10276  with this option.
10277  It automatically implies -
10278 \series bold
10279
10280 \begin_inset ERT
10281 status open
10282
10283 \begin_layout Standard
10284
10285
10286 \backslash
10287 /
10288 \end_layout
10289
10290 \end_inset
10291
10292
10293 \series default
10294 -int-long-reent and -
10295 \series bold
10296
10297 \begin_inset ERT
10298 status open
10299
10300 \begin_layout Standard
10301
10302
10303 \backslash
10304 /
10305 \end_layout
10306
10307 \end_inset
10308
10309
10310 \series default
10311 -float-reent.
10312  
10313 \end_layout
10314
10315 \begin_layout List
10316 \labelwidthstring 00.00.0000
10317
10318 \series bold
10319 -
10320 \begin_inset ERT
10321 status collapsed
10322
10323 \begin_layout Standard
10324
10325
10326 \backslash
10327 /
10328 \end_layout
10329
10330 \end_inset
10331
10332 -callee-saves
10333 \begin_inset LatexCommand index
10334 name "-\\/-callee-saves"
10335
10336 \end_inset
10337
10338  
10339 \begin_inset LatexCommand label
10340 name "lyx:--callee-saves-function1[,function2][,function3]..."
10341
10342 \end_inset
10343
10344 function1[,function2][,function3]....
10345
10346 \series default
10347  The compiler by default uses a caller saves convention for register saving
10348  across function calls, however this can cause unnecessary register pushing
10349  and popping when calling small functions from larger functions.
10350  This option can be used to switch the register saving convention for the
10351  function names specified.
10352  The compiler will not save registers when calling these functions, no extra
10353  code will be generated at the entry and exit (function prologue
10354 \series bold
10355
10356 \begin_inset LatexCommand index
10357 name "function prologue"
10358
10359 \end_inset
10360
10361
10362 \series default
10363  and epilogue
10364 \series bold
10365
10366 \begin_inset LatexCommand index
10367 name "function epilogue"
10368
10369 \end_inset
10370
10371
10372 \series default
10373 ) for these functions to save and restore the registers used by these functions,
10374  this can SUBSTANTIALLY reduce code and improve run time performance of
10375  the generated code.
10376  In the future the compiler (with inter procedural analysis) will be able
10377  to determine the appropriate scheme to use for each function call.
10378  DO NOT use this option for built-in functions such as _mulint..., if this
10379  option is used for a library function the appropriate library function
10380  needs to be recompiled with the same option.
10381  If the project consists of multiple source files then all the source file
10382  should be compiled with the same -
10383 \begin_inset ERT
10384 status collapsed
10385
10386 \begin_layout Standard
10387
10388
10389 \backslash
10390 /
10391 \end_layout
10392
10393 \end_inset
10394
10395 -callee-saves option string.
10396  Also see #pragma\InsetSpace ~
10397 callee_saves 
10398 \begin_inset LatexCommand index
10399 name "\\#pragma callee\\_saves"
10400
10401 \end_inset
10402
10403  
10404 \begin_inset LatexCommand vpageref
10405 reference "ite:callee_saves-function1[,function2[,function3...]]--"
10406
10407 \end_inset
10408
10409 .
10410 \end_layout
10411
10412 \begin_layout List
10413 \labelwidthstring 00.00.0000
10414
10415 \series bold
10416 -
10417 \begin_inset ERT
10418 status collapsed
10419
10420 \begin_layout Standard
10421
10422
10423 \backslash
10424 /
10425 \end_layout
10426
10427 \end_inset
10428
10429 -all-callee-saves
10430 \begin_inset LatexCommand index
10431 name "-\\/-all-callee-saves"
10432
10433 \end_inset
10434
10435
10436 \series default
10437  Function of -
10438 \begin_inset ERT
10439 status collapsed
10440
10441 \begin_layout Standard
10442
10443
10444 \backslash
10445 /
10446 \end_layout
10447
10448 \end_inset
10449
10450 -callee-saves will be applied to all functions by default.
10451 \end_layout
10452
10453 \begin_layout List
10454 \labelwidthstring 00.00.0000
10455
10456 \series bold
10457 -
10458 \begin_inset ERT
10459 status collapsed
10460
10461 \begin_layout Standard
10462
10463
10464 \backslash
10465 /
10466 \end_layout
10467
10468 \end_inset
10469
10470 -debug
10471 \begin_inset LatexCommand index
10472 name "-\\/-debug"
10473
10474 \end_inset
10475
10476  
10477 \series default
10478 When this option is used the compiler will generate debug information.
10479  The debug information collected in a file with .cdb extension can be used
10480  with the SDCDB.
10481  For more information see documentation for SDCDB.
10482  Another file with no extension contains debug information in AOMF or AOMF51
10483 \begin_inset LatexCommand index
10484 name "AOMF, AOMF51"
10485
10486 \end_inset
10487
10488  format which is commonly used by third party tools.
10489 \end_layout
10490
10491 \begin_layout List
10492 \labelwidthstring 00.00.0000
10493
10494 \series bold
10495 -S
10496 \begin_inset LatexCommand index
10497 name "-S"
10498
10499 \end_inset
10500
10501
10502 \series default
10503 \size large
10504  
10505 \size default
10506 Stop after the stage of compilation proper; do not assemble.
10507  The output is an assembler code file for the input file specified.
10508 \end_layout
10509
10510 \begin_layout List
10511 \labelwidthstring 00.00.0000
10512
10513 \series bold
10514 -
10515 \begin_inset ERT
10516 status collapsed
10517
10518 \begin_layout Standard
10519
10520
10521 \backslash
10522 /
10523 \end_layout
10524
10525 \end_inset
10526
10527 -int-long-reent
10528 \begin_inset LatexCommand index
10529 name "-\\/-int-long-reent"
10530
10531 \end_inset
10532
10533
10534 \series default
10535  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10536  Note by default these libraries are compiled as non-reentrant.
10537  See section Installation for more details.
10538 \end_layout
10539
10540 \begin_layout List
10541 \labelwidthstring 00.00.0000
10542
10543 \series bold
10544 -
10545 \begin_inset ERT
10546 status collapsed
10547
10548 \begin_layout Standard
10549
10550
10551 \backslash
10552 /
10553 \end_layout
10554
10555 \end_inset
10556
10557 -cyclomatic
10558 \begin_inset LatexCommand index
10559 name "-\\/-cyclomatic"
10560
10561 \end_inset
10562
10563  
10564 \series default
10565 This option will cause the compiler to generate an information message for
10566  each function in the source file.
10567  The message contains some 
10568 \emph on
10569 important
10570 \emph default
10571  information about the function.
10572  The number of edges and nodes the compiler detected in the control flow
10573  graph of the function, and most importantly the 
10574 \emph on
10575 cyclomatic complexity
10576 \begin_inset LatexCommand index
10577 name "Cyclomatic complexity"
10578
10579 \end_inset
10580
10581
10582 \emph default
10583  see section on Cyclomatic Complexity for more details.
10584 \end_layout
10585
10586 \begin_layout List
10587 \labelwidthstring 00.00.0000
10588
10589 \series bold
10590 -
10591 \begin_inset ERT
10592 status collapsed
10593
10594 \begin_layout Standard
10595
10596
10597 \backslash
10598 /
10599 \end_layout
10600
10601 \end_inset
10602
10603 -float-reent
10604 \begin_inset LatexCommand index
10605 name "-\\/-float-reent"
10606
10607 \end_inset
10608
10609
10610 \series default
10611  Floating point library is compiled as reentrant
10612 \begin_inset LatexCommand index
10613 name "reentrant"
10614
10615 \end_inset
10616
10617 .
10618  See section Installation for more details.
10619 \end_layout
10620
10621 \begin_layout List
10622 \labelwidthstring 00.00.0000
10623
10624 \series bold
10625 -
10626 \begin_inset ERT
10627 status collapsed
10628
10629 \begin_layout Standard
10630
10631
10632 \backslash
10633 /
10634 \end_layout
10635
10636 \end_inset
10637
10638 -funsigned-char
10639 \begin_inset LatexCommand index
10640 name "-\\/-funsigned-char"
10641
10642 \end_inset
10643
10644
10645 \series default
10646  The default signedness for every type is 
10647 \family typewriter
10648 signed
10649 \family default
10650 .
10651  In some embedded environments the default signedness of 
10652 \family typewriter
10653 char
10654 \family default
10655  is 
10656 \family typewriter
10657 unsigned
10658 \family default
10659 .
10660  To set the signess for characters to unsigned, use the option -
10661 \series bold
10662
10663 \begin_inset ERT
10664 status open
10665
10666 \begin_layout Standard
10667
10668
10669 \backslash
10670 /
10671 \end_layout
10672
10673 \end_inset
10674
10675
10676 \series default
10677 -funsigned-char.
10678  If this option is set and no signedness keyword (unsigned/signed) is given,
10679  a char will be signed.
10680  All other types are unaffected.
10681 \end_layout
10682
10683 \begin_layout List
10684 \labelwidthstring 00.00.0000
10685
10686 \series bold
10687 -
10688 \begin_inset ERT
10689 status collapsed
10690
10691 \begin_layout Standard
10692
10693
10694 \backslash
10695 /
10696 \end_layout
10697
10698 \end_inset
10699
10700 -main-return
10701 \begin_inset LatexCommand index
10702 name "-\\/-main-return"
10703
10704 \end_inset
10705
10706
10707 \series default
10708  This option can be used if the code generated is called by a monitor program
10709  or if the main routine includes an endless loop.
10710  This option results in slightly smaller code and saves two bytes of stack
10711  space.
10712  The return from the 'main'
10713 \begin_inset LatexCommand index
10714 name "main return"
10715
10716 \end_inset
10717
10718  function will return to the function calling main.
10719  The default setting is to lock up i.e.
10720  generate a '
10721 \family typewriter
10722 sjmp .
10723 \family default
10724 '.
10725 \end_layout
10726
10727 \begin_layout List
10728 \labelwidthstring 00.00.0000
10729
10730 \series bold
10731 -
10732 \begin_inset ERT
10733 status collapsed
10734
10735 \begin_layout Standard
10736
10737
10738 \backslash
10739 /
10740 \end_layout
10741
10742 \end_inset
10743
10744 -nostdinc
10745 \begin_inset LatexCommand index
10746 name "-\\/-nostdinc"
10747
10748 \end_inset
10749
10750
10751 \series default
10752  This will prevent the compiler from passing on the default include path
10753  to the preprocessor.
10754 \end_layout
10755
10756 \begin_layout List
10757 \labelwidthstring 00.00.0000
10758
10759 \series bold
10760 -
10761 \begin_inset ERT
10762 status collapsed
10763
10764 \begin_layout Standard
10765
10766
10767 \backslash
10768 /
10769 \end_layout
10770
10771 \end_inset
10772
10773 -nostdlib
10774 \begin_inset LatexCommand index
10775 name "-\\/-nostdlib"
10776
10777 \end_inset
10778
10779
10780 \series default
10781  This will prevent the compiler from passing on the default library
10782 \begin_inset LatexCommand index
10783 name "Libraries"
10784
10785 \end_inset
10786
10787  path to the linker.
10788 \end_layout
10789
10790 \begin_layout List
10791 \labelwidthstring 00.00.0000
10792
10793 \series bold
10794 -
10795 \begin_inset ERT
10796 status collapsed
10797
10798 \begin_layout Standard
10799
10800
10801 \backslash
10802 /
10803 \end_layout
10804
10805 \end_inset
10806
10807 -verbose
10808 \begin_inset LatexCommand index
10809 name "-\\/-verbose"
10810
10811 \end_inset
10812
10813
10814 \series default
10815  Shows the various actions the compiler is performing.
10816 \end_layout
10817
10818 \begin_layout List
10819 \labelwidthstring 00.00.0000
10820
10821 \series bold
10822 -V
10823 \begin_inset LatexCommand index
10824 name "-V"
10825
10826 \end_inset
10827
10828
10829 \series default
10830  Shows the actual commands the compiler is executing.
10831 \end_layout
10832
10833 \begin_layout List
10834 \labelwidthstring 00.00.0000
10835
10836 \series bold
10837 -
10838 \begin_inset ERT
10839 status collapsed
10840
10841 \begin_layout Standard
10842
10843
10844 \backslash
10845 /
10846 \end_layout
10847
10848 \end_inset
10849
10850 -no-c-code-in-asm
10851 \begin_inset LatexCommand index
10852 name "-\\/-no-c-code-in-asm"
10853
10854 \end_inset
10855
10856
10857 \series default
10858  Hides your ugly and inefficient c-code from the asm file, so you can always
10859  blame the compiler :)
10860 \end_layout
10861
10862 \begin_layout List
10863 \labelwidthstring 00.00.0000
10864
10865 \series bold
10866 -
10867 \begin_inset ERT
10868 status collapsed
10869
10870 \begin_layout Standard
10871
10872
10873 \backslash
10874 /
10875 \end_layout
10876
10877 \end_inset
10878
10879 -fverbose-asm
10880 \begin_inset LatexCommand index
10881 name "-\\/-no-gen-comments"
10882
10883 \end_inset
10884
10885
10886 \series default
10887  Include code generator and peep-hole comments in the generated asm files.
10888 \end_layout
10889
10890 \begin_layout List
10891 \labelwidthstring 00.00.0000
10892
10893 \series bold
10894 -
10895 \begin_inset ERT
10896 status collapsed
10897
10898 \begin_layout Standard
10899
10900
10901 \backslash
10902 /
10903 \end_layout
10904
10905 \end_inset
10906
10907 -no-peep-comments
10908 \begin_inset LatexCommand index
10909 name "-\\/-no-peep-comments"
10910
10911 \end_inset
10912
10913
10914 \series default
10915  Don't include peep-hole comments in the generated asm files even if -
10916 \series bold
10917
10918 \begin_inset ERT
10919 status open
10920
10921 \begin_layout Standard
10922
10923
10924 \backslash
10925 /
10926 \end_layout
10927
10928 \end_inset
10929
10930
10931 \series default
10932 -fverbose-asm option is specified.
10933 \end_layout
10934
10935 \begin_layout List
10936 \labelwidthstring 00.00.0000
10937
10938 \series bold
10939 -
10940 \begin_inset ERT
10941 status collapsed
10942
10943 \begin_layout Standard
10944
10945
10946 \backslash
10947 /
10948 \end_layout
10949
10950 \end_inset
10951
10952 -i-code-in-asm
10953 \begin_inset LatexCommand index
10954 name "-\\/-i-code-in-asm"
10955
10956 \end_inset
10957
10958
10959 \series default
10960  Include i-codes in the asm file.
10961  Sounds like noise but is most helpful for debugging the compiler itself.
10962 \end_layout
10963
10964 \begin_layout List
10965 \labelwidthstring 00.00.0000
10966
10967 \series bold
10968 -
10969 \begin_inset ERT
10970 status collapsed
10971
10972 \begin_layout Standard
10973
10974
10975 \backslash
10976 /
10977 \end_layout
10978
10979 \end_inset
10980
10981 -less-pedantic
10982 \begin_inset LatexCommand index
10983 name "pedantic"
10984
10985 \end_inset
10986
10987
10988 \begin_inset LatexCommand index
10989 name "-\\/-less-pedantic"
10990
10991 \end_inset
10992
10993
10994 \series default
10995
10996 \begin_inset LatexCommand label
10997 name "lyx:--less-pedantic"
10998
10999 \end_inset
11000
11001  Disable some of the more pedantic warnings
11002 \begin_inset LatexCommand index
11003 name "Warnings"
11004
11005 \end_inset
11006
11007 .
11008  For more details, see the less_pedantic pragma 
11009 \begin_inset LatexCommand vpageref
11010 reference "ite:less_pedantic"
11011
11012 \end_inset
11013
11014 .
11015 \end_layout
11016
11017 \begin_layout List
11018 \labelwidthstring 00.00.0000
11019
11020 \series bold
11021 -
11022 \begin_inset ERT
11023 status collapsed
11024
11025 \begin_layout Standard
11026
11027
11028 \backslash
11029 /
11030 \end_layout
11031
11032 \end_inset
11033
11034 -disable-warning\InsetSpace ~
11035 <nnnn>
11036 \begin_inset LatexCommand index
11037 name "-\\/-disable-warning"
11038
11039 \end_inset
11040
11041
11042 \series default
11043  Disable specific warning with number <nnnn>.
11044 \end_layout
11045
11046 \begin_layout List
11047 \labelwidthstring 00.00.0000
11048
11049 \series bold
11050 -
11051 \begin_inset ERT
11052 status collapsed
11053
11054 \begin_layout Standard
11055
11056
11057 \backslash
11058 /
11059 \end_layout
11060
11061 \end_inset
11062
11063 -Werror
11064 \begin_inset LatexCommand index
11065 name "-\\/-Werror"
11066
11067 \end_inset
11068
11069
11070 \series default
11071  Treat all warnings as errors.
11072 \end_layout
11073
11074 \begin_layout List
11075 \labelwidthstring 00.00.0000
11076
11077 \series bold
11078 -
11079 \begin_inset ERT
11080 status collapsed
11081
11082 \begin_layout Standard
11083
11084
11085 \backslash
11086 /
11087 \end_layout
11088
11089 \end_inset
11090
11091 -print-search-dirs
11092 \begin_inset LatexCommand index
11093 name "-\\/-print-search-dirs"
11094
11095 \end_inset
11096
11097
11098 \series default
11099  Display the directories in the compiler's search path
11100 \end_layout
11101
11102 \begin_layout List
11103 \labelwidthstring 00.00.0000
11104
11105 \series bold
11106 -
11107 \begin_inset ERT
11108 status collapsed
11109
11110 \begin_layout Standard
11111
11112
11113 \backslash
11114 /
11115 \end_layout
11116
11117 \end_inset
11118
11119 -vc
11120 \begin_inset LatexCommand index
11121 name "-\\/-vc"
11122
11123 \end_inset
11124
11125
11126 \series default
11127  Display errors and warnings using MSVC style, so you can use SDCC with
11128  the visual studio IDE
11129 \begin_inset LatexCommand index
11130 name "IDE"
11131
11132 \end_inset
11133
11134 .
11135  With SDCC both offering a GCC-like (the default) and a MSVC-like
11136 \begin_inset LatexCommand index
11137 name "MSVC output style"
11138
11139 \end_inset
11140
11141  output style, integration into most programming editors should be straightforwa
11142 rd.
11143 \end_layout
11144
11145 \begin_layout List
11146 \labelwidthstring 00.00.0000
11147
11148 \series bold
11149 -
11150 \begin_inset ERT
11151 status collapsed
11152
11153 \begin_layout Standard
11154
11155
11156 \backslash
11157 /
11158 \end_layout
11159
11160 \end_inset
11161
11162 -use-stdout
11163 \begin_inset LatexCommand index
11164 name "-\\/-use-stdout"
11165
11166 \end_inset
11167
11168
11169 \series default
11170  Send errors and warnings to stdout instead of stderr.
11171 \end_layout
11172
11173 \begin_layout List
11174 \labelwidthstring 00.00.0000
11175
11176 \series bold
11177 -Wa\InsetSpace ~
11178 asmOption[,asmOption]
11179 \series default
11180
11181 \begin_inset LatexCommand index
11182 name "-Wa asmOption[,asmOption]"
11183
11184 \end_inset
11185
11186 ...
11187  Pass the asmOption to the assembler
11188 \begin_inset LatexCommand index
11189 name "Options assembler"
11190
11191 \end_inset
11192
11193
11194 \begin_inset LatexCommand index
11195 name "Assembler options"
11196
11197 \end_inset
11198
11199 .
11200  See file sdcc/as/doc/asxhtm.html for assembler options.cd
11201 \end_layout
11202
11203 \begin_layout List
11204 \labelwidthstring 00.00.0000
11205
11206 \series bold
11207 -
11208 \begin_inset ERT
11209 status collapsed
11210
11211 \begin_layout Standard
11212
11213
11214 \backslash
11215 /
11216 \end_layout
11217
11218 \end_inset
11219
11220 -std-sdcc89
11221 \begin_inset LatexCommand index
11222 name "-\\/-std-sdcc89"
11223
11224 \end_inset
11225
11226
11227 \series default
11228  Generally follow the C89 standard, but allow SDCC features that conflict
11229  with the standard (default).
11230 \end_layout
11231
11232 \begin_layout List
11233 \labelwidthstring 00.00.0000
11234
11235 \series bold
11236 -
11237 \begin_inset ERT
11238 status collapsed
11239
11240 \begin_layout Standard
11241
11242
11243 \backslash
11244 /
11245 \end_layout
11246
11247 \end_inset
11248
11249 -std-c89
11250 \begin_inset LatexCommand index
11251 name "-\\/-std-c89"
11252
11253 \end_inset
11254
11255
11256 \series default
11257  Follow the C89 standard and disable SDCC features that conflict with the
11258  standard.
11259 \end_layout
11260
11261 \begin_layout List
11262 \labelwidthstring 00.00.0000
11263
11264 \series bold
11265 -
11266 \begin_inset ERT
11267 status collapsed
11268
11269 \begin_layout Standard
11270
11271
11272 \backslash
11273 /
11274 \end_layout
11275
11276 \end_inset
11277
11278 -std-sdcc99
11279 \begin_inset LatexCommand index
11280 name "-\\/-std-sdcc99"
11281
11282 \end_inset
11283
11284
11285 \series default
11286  Generally follow the C99 standard, but allow SDCC features that conflict
11287  with the standard (incomplete support).
11288 \end_layout
11289
11290 \begin_layout List
11291 \labelwidthstring 00.00.0000
11292
11293 \series bold
11294 -
11295 \begin_inset ERT
11296 status collapsed
11297
11298 \begin_layout Standard
11299
11300
11301 \backslash
11302 /
11303 \end_layout
11304
11305 \end_inset
11306
11307 -std-c99
11308 \begin_inset LatexCommand index
11309 name "-\\/-std-sdcc99"
11310
11311 \end_inset
11312
11313
11314 \series default
11315  Follow the C99 standard and disable SDCC features that conflict with the
11316  standard (incomplete support).
11317 \end_layout
11318
11319 \begin_layout List
11320 \labelwidthstring 00.00.0000
11321
11322 \series bold
11323 -
11324 \begin_inset ERT
11325 status collapsed
11326
11327 \begin_layout Standard
11328
11329
11330 \backslash
11331 /
11332 \end_layout
11333
11334 \end_inset
11335
11336 -codeseg
11337 \series default
11338
11339 \begin_inset LatexCommand index
11340 name "-\\/-codeseg <Value>"
11341
11342 \end_inset
11343
11344
11345 \begin_inset LatexCommand label
11346 name "lyx:-codeseg"
11347
11348 \end_inset
11349
11350 \InsetSpace ~
11351 <Name> The name to be used for the code
11352 \begin_inset LatexCommand index
11353 name "code"
11354
11355 \end_inset
11356
11357  segment, default CSEG.
11358  This is useful if you need to tell the compiler to put the code in a special
11359  segment so you can later on tell the linker to put this segment in a special
11360  place in memory.
11361  Can be used for instance when using bank switching to put the code in a
11362  bank.
11363 \end_layout
11364
11365 \begin_layout List
11366 \labelwidthstring 00.00.0000
11367
11368 \series bold
11369 -
11370 \begin_inset ERT
11371 status collapsed
11372
11373 \begin_layout Standard
11374
11375
11376 \backslash
11377 /
11378 \end_layout
11379
11380 \end_inset
11381
11382 -constseg
11383 \series default
11384
11385 \begin_inset LatexCommand index
11386 name "-\\/-constseg <Value>"
11387
11388 \end_inset
11389
11390 \InsetSpace ~
11391 <Name> The name to be used for the const
11392 \begin_inset LatexCommand index
11393 name "const"
11394
11395 \end_inset
11396
11397  segment, default CONST.
11398  This is useful if you need to tell the compiler to put the const data in
11399  a special segment so you can later on tell the linker to put this segment
11400  in a special place in memory.
11401  Can be used for instance when using bank switching to put the const data
11402  in a bank.
11403 \end_layout
11404
11405 \begin_layout List
11406 \labelwidthstring 00.00.0000
11407
11408 \series bold
11409 -
11410 \begin_inset ERT
11411 status collapsed
11412
11413 \begin_layout Standard
11414
11415
11416 \backslash
11417 /
11418 \end_layout
11419
11420 \end_inset
11421
11422 -fdollars-in-identifiers
11423 \begin_inset LatexCommand index
11424 name "-\\/-fdollars-in-identifiers"
11425
11426 \end_inset
11427
11428
11429 \series default
11430  Permit '$' as an identifier character.
11431 \end_layout
11432
11433 \begin_layout List
11434 \labelwidthstring 00.00.0000
11435
11436 \series bold
11437 -
11438 \begin_inset ERT
11439 status collapsed
11440
11441 \begin_layout Standard
11442
11443
11444 \backslash
11445 /
11446 \end_layout
11447
11448 \end_inset
11449
11450 -more-pedantic
11451 \series default
11452
11453 \begin_inset LatexCommand index
11454 name "-\\/-more-pedantic"
11455
11456 \end_inset
11457
11458
11459 \begin_inset LatexCommand index
11460 name "pedantic"
11461
11462 \end_inset
11463
11464  Actually this is 
11465 \series bold
11466 \emph on
11467 not
11468 \series default
11469 \emph default
11470  a SDCC compiler option but if you want 
11471 \emph on
11472 more
11473 \emph default
11474  warnings you can use a separate tool dedicated to syntax checking like
11475  splint
11476 \begin_inset LatexCommand label
11477 name "lyx:more-pedantic-SPLINT"
11478
11479 \end_inset
11480
11481
11482 \begin_inset LatexCommand index
11483 name "lint (syntax checking tool)"
11484
11485 \end_inset
11486
11487  
11488 \begin_inset LatexCommand url
11489 target "http://www.splint.org"
11490
11491 \end_inset
11492
11493 .
11494  To make your source files parseable by splint you will have to include
11495  
11496 \family sans
11497 lint.h
11498 \family default
11499
11500 \begin_inset LatexCommand index
11501 name "splint (syntax checking tool)"
11502
11503 \end_inset
11504
11505  in your source file and add brackets around extended keywords (like 
11506 \family sans
11507
11508 \begin_inset Quotes sld
11509 \end_inset
11510
11511 __at\InsetSpace ~
11512
11513 \series bold
11514 (
11515 \series default
11516 0xab
11517 \series bold
11518 )
11519 \series default
11520
11521 \begin_inset Quotes srd
11522 \end_inset
11523
11524
11525 \family default
11526  and 
11527 \family sans
11528
11529 \begin_inset Quotes sld
11530 \end_inset
11531
11532 __interrupt\InsetSpace ~
11533 (2)
11534 \begin_inset Quotes srd
11535 \end_inset
11536
11537
11538 \family default
11539 ).
11540  
11541 \newline
11542 Splint has an excellent on line manual at 
11543 \begin_inset LatexCommand url
11544 target "http://www.splint.org/manual/"
11545
11546 \end_inset
11547
11548  and it's capabilities go beyond pure syntax checking.
11549  You'll need to tell splint the location of SDCC's include files so a typical
11550  command line could look like this: 
11551 \newline
11552
11553 \family sans
11554 splint\InsetSpace ~
11555 -I\InsetSpace ~
11556 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
11557 \InsetSpace ~
11558 myprogram.c
11559 \end_layout
11560
11561 \begin_layout List
11562 \labelwidthstring 00.00.0000
11563
11564 \series bold
11565 -
11566 \begin_inset ERT
11567 status collapsed
11568
11569 \begin_layout Standard
11570
11571
11572 \backslash
11573 /
11574 \end_layout
11575
11576 \end_inset
11577
11578 -short-is-8bits
11579 \series default
11580
11581 \begin_inset LatexCommand index
11582 name "-\\/-short-is-8bits"
11583
11584 \end_inset
11585
11586
11587 \begin_inset LatexCommand label
11588 name "lyx:--short-is-8bits"
11589
11590 \end_inset
11591
11592  Treat short as 8-bit (for backward compatibility with older versions of
11593  compiler - see section 
11594 \begin_inset LatexCommand ref
11595 reference "sec:Compatibility-with-previous"
11596
11597 \end_inset
11598
11599 )
11600 \end_layout
11601
11602 \begin_layout Standard
11603 \begin_inset VSpace bigskip
11604 \end_inset
11605
11606
11607 \end_layout
11608
11609 \begin_layout Subsection
11610 Intermediate Dump Options
11611 \begin_inset LatexCommand label
11612 name "sub:Intermediate-Dump-Options"
11613
11614 \end_inset
11615
11616
11617 \begin_inset LatexCommand index
11618 name "Options intermediate dump"
11619
11620 \end_inset
11621
11622
11623 \begin_inset LatexCommand index
11624 name "Intermediate dump options"
11625
11626 \end_inset
11627
11628
11629 \end_layout
11630
11631 \begin_layout Standard
11632 The following options are provided for the purpose of retargetting and debugging
11633  the compiler.
11634  They provide a means to dump the intermediate code (iCode
11635 \begin_inset LatexCommand index
11636 name "iCode"
11637
11638 \end_inset
11639
11640 ) generated by the compiler in human readable form at various stages of
11641  the compilation process.
11642  More on iCodes see chapter 
11643 \begin_inset LatexCommand ref
11644 reference "sub:The-anatomy-of"
11645
11646 \end_inset
11647
11648  
11649 \begin_inset Quotes srd
11650 \end_inset
11651
11652 The anatomy of the compiler
11653 \begin_inset Quotes srd
11654 \end_inset
11655
11656 .
11657 \end_layout
11658
11659 \begin_layout List
11660 \labelwidthstring 00.00.0000
11661
11662 \series bold
11663 -
11664 \begin_inset ERT
11665 status collapsed
11666
11667 \begin_layout Standard
11668
11669
11670 \backslash
11671 /
11672 \end_layout
11673
11674 \end_inset
11675
11676 -dumpraw
11677 \begin_inset LatexCommand index
11678 name "-\\/-dumpraw"
11679
11680 \end_inset
11681
11682
11683 \series default
11684  This option will cause the compiler to dump the intermediate code into
11685  a file of named 
11686 \emph on
11687 <source filename>.dumpraw
11688 \emph default
11689  just after the intermediate code has been generated for a function, i.e.
11690  before any optimizations are done.
11691  The basic blocks
11692 \begin_inset LatexCommand index
11693 name "Basic blocks"
11694
11695 \end_inset
11696
11697  at this stage ordered in the depth first number, so they may not be in
11698  sequence of execution.
11699 \end_layout
11700
11701 \begin_layout List
11702 \labelwidthstring 00.00.0000
11703
11704 \series bold
11705 -
11706 \begin_inset ERT
11707 status collapsed
11708
11709 \begin_layout Standard
11710
11711
11712 \backslash
11713 /
11714 \end_layout
11715
11716 \end_inset
11717
11718 -dumpgcse
11719 \begin_inset LatexCommand index
11720 name "-\\/-dumpgcse"
11721
11722 \end_inset
11723
11724
11725 \series default
11726  Will create a dump of iCodes, after global subexpression elimination
11727 \begin_inset LatexCommand index
11728 name "Global subexpression elimination"
11729
11730 \end_inset
11731
11732 , into a file named 
11733 \emph on
11734 <source filename>.dumpgcse.
11735 \end_layout
11736
11737 \begin_layout List
11738 \labelwidthstring 00.00.0000
11739
11740 \series bold
11741 -
11742 \begin_inset ERT
11743 status collapsed
11744
11745 \begin_layout Standard
11746
11747
11748 \backslash
11749 /
11750 \end_layout
11751
11752 \end_inset
11753
11754 -dumpdeadcode
11755 \begin_inset LatexCommand index
11756 name "-\\/-dumpdeadcode"
11757
11758 \end_inset
11759
11760
11761 \series default
11762  Will create a dump of iCodes, after deadcode elimination
11763 \begin_inset LatexCommand index
11764 name "Dead-code elimination"
11765
11766 \end_inset
11767
11768 , into a file named 
11769 \emph on
11770 <source filename>.dumpdeadcode.
11771 \end_layout
11772
11773 \begin_layout List
11774 \labelwidthstring 00.00.0000
11775
11776 \series bold
11777 -
11778 \begin_inset ERT
11779 status collapsed
11780
11781 \begin_layout Standard
11782
11783
11784 \backslash
11785 /
11786 \end_layout
11787
11788 \end_inset
11789
11790 -dumploop
11791 \begin_inset LatexCommand index
11792 name "-\\/-dumploop"
11793
11794 \end_inset
11795
11796
11797 \series default
11798 \size large
11799  
11800 \size default
11801 Will create a dump of iCodes, after loop optimizations
11802 \begin_inset LatexCommand index
11803 name "Loop optimization"
11804
11805 \end_inset
11806
11807 , into a file named 
11808 \emph on
11809 <source filename>.dumploop.
11810 \end_layout
11811
11812 \begin_layout List
11813 \labelwidthstring 00.00.0000
11814
11815 \series bold
11816 -
11817 \begin_inset ERT
11818 status collapsed
11819
11820 \begin_layout Standard
11821
11822
11823 \backslash
11824 /
11825 \end_layout
11826
11827 \end_inset
11828
11829 -dumprange
11830 \begin_inset LatexCommand index
11831 name "-\\/-dumprange"
11832
11833 \end_inset
11834
11835
11836 \series default
11837 \size large
11838  
11839 \size default
11840 Will create a dump of iCodes, after live range analysis
11841 \begin_inset LatexCommand index
11842 name "Live range analysis"
11843
11844 \end_inset
11845
11846 , into a file named 
11847 \emph on
11848 <source filename>.dumprange.
11849 \end_layout
11850
11851 \begin_layout List
11852 \labelwidthstring 00.00.0000
11853
11854 \series bold
11855 -
11856 \begin_inset ERT
11857 status collapsed
11858
11859 \begin_layout Standard
11860
11861
11862 \backslash
11863 /
11864 \end_layout
11865
11866 \end_inset
11867
11868 -dumlrange
11869 \begin_inset LatexCommand index
11870 name "-\\/-dumlrange"
11871
11872 \end_inset
11873
11874
11875 \series default
11876  Will dump the life ranges
11877 \begin_inset LatexCommand index
11878 name "Live range analysis"
11879
11880 \end_inset
11881
11882  for all symbols.
11883 \end_layout
11884
11885 \begin_layout List
11886 \labelwidthstring 00.00.0000
11887
11888 \series bold
11889 -
11890 \begin_inset ERT
11891 status collapsed
11892
11893 \begin_layout Standard
11894
11895
11896 \backslash
11897 /
11898 \end_layout
11899
11900 \end_inset
11901
11902 -dumpregassign
11903 \begin_inset LatexCommand index
11904 name "-\\/-dumpregassign"
11905
11906 \end_inset
11907
11908  
11909 \series default
11910 Will create a dump of iCodes, after register assignment
11911 \begin_inset LatexCommand index
11912 name "Register assignment"
11913
11914 \end_inset
11915
11916 , into a file named 
11917 \emph on
11918 <source filename>.dumprassgn.
11919 \end_layout
11920
11921 \begin_layout List
11922 \labelwidthstring 00.00.0000
11923
11924 \series bold
11925 -
11926 \begin_inset ERT
11927 status collapsed
11928
11929 \begin_layout Standard
11930
11931
11932 \backslash
11933 /
11934 \end_layout
11935
11936 \end_inset
11937
11938 -dumplrange
11939 \begin_inset LatexCommand index
11940 name "-\\/-dumplrange"
11941
11942 \end_inset
11943
11944
11945 \series default
11946  Will create a dump of the live ranges of iTemp's
11947 \end_layout
11948
11949 \begin_layout List
11950 \labelwidthstring 00.00.0000
11951
11952 \series bold
11953 -
11954 \begin_inset ERT
11955 status collapsed
11956
11957 \begin_layout Standard
11958
11959
11960 \backslash
11961 /
11962 \end_layout
11963
11964 \end_inset
11965
11966 -dumpall
11967 \begin_inset LatexCommand index
11968 name "-\\/-dumpall"
11969
11970 \end_inset
11971
11972
11973 \size large
11974  
11975 \series default
11976 \size default
11977 Will cause all the above mentioned dumps to be created.
11978 \end_layout
11979
11980 \begin_layout Standard
11981 \begin_inset VSpace bigskip
11982 \end_inset
11983
11984
11985 \end_layout
11986
11987 \begin_layout Subsection
11988 Redirecting output on Windows Shells
11989 \end_layout
11990
11991 \begin_layout Standard
11992 By default SDCC writes its error messages to 
11993 \begin_inset Quotes sld
11994 \end_inset
11995
11996 standard error
11997 \begin_inset Quotes srd
11998 \end_inset
11999
12000 .
12001  To force all messages to 
12002 \begin_inset Quotes sld
12003 \end_inset
12004
12005 standard output
12006 \begin_inset Quotes srd
12007 \end_inset
12008
12009  use 
12010 \series bold
12011 -
12012 \series default
12013 \emph on
12014
12015 \begin_inset ERT
12016 status collapsed
12017
12018 \begin_layout Standard
12019
12020
12021 \backslash
12022 /
12023 \end_layout
12024
12025 \end_inset
12026
12027
12028 \series bold
12029 \emph default
12030 -
12031 \series default
12032 use-stdout
12033 \begin_inset LatexCommand index
12034 name "-\\/-use-stdout"
12035
12036 \end_inset
12037
12038 .
12039  Additionally, if you happen to have visual studio installed in your windows
12040  machine, you can use it to compile your sources using a custom build and
12041  the SDCC -
12042 \emph on
12043
12044 \begin_inset ERT
12045 status collapsed
12046
12047 \begin_layout Standard
12048
12049
12050 \backslash
12051 /
12052 \end_layout
12053
12054 \end_inset
12055
12056
12057 \emph default
12058 -vc
12059 \begin_inset LatexCommand index
12060 name "-\\/-vc"
12061
12062 \end_inset
12063
12064  option.
12065  Something like this should work:
12066 \newline
12067
12068 \newline
12069
12070 \series bold
12071 c:
12072 \backslash
12073 sdcc
12074 \backslash
12075 bin
12076 \backslash
12077 sdcc.exe -
12078 \series default
12079 \emph on
12080
12081 \begin_inset ERT
12082 status collapsed
12083
12084 \begin_layout Standard
12085
12086
12087 \backslash
12088 /
12089 \end_layout
12090
12091 \end_inset
12092
12093
12094 \series bold
12095 \emph default
12096 -vc -
12097 \series default
12098 \emph on
12099
12100 \begin_inset ERT
12101 status collapsed
12102
12103 \begin_layout Standard
12104
12105
12106 \backslash
12107 /
12108 \end_layout
12109
12110 \end_inset
12111
12112
12113 \series bold
12114 \emph default
12115 -model-large -c $(InputPath)
12116 \series default
12117
12118 \begin_inset VSpace bigskip
12119 \end_inset
12120
12121
12122 \end_layout
12123
12124 \begin_layout Section
12125 Environment variables
12126 \begin_inset LatexCommand index
12127 name "Environment variables"
12128
12129 \end_inset
12130
12131
12132 \end_layout
12133
12134 \begin_layout Standard
12135 SDCC recognizes the following environment variables:
12136 \end_layout
12137
12138 \begin_layout List
12139 \labelwidthstring 00.00.0000
12140
12141 \series bold
12142 SDCC_LEAVE_SIGNALS
12143 \begin_inset LatexCommand index
12144 name "SDCC\\_LEAVE\\_SIGNALS"
12145
12146 \end_inset
12147
12148
12149 \series default
12150  SDCC installs a signal handler
12151 \begin_inset LatexCommand index
12152 name "signal handler"
12153
12154 \end_inset
12155
12156  to be able to delete temporary files after an user break (^C) or an exception.
12157  If this environment variable is set, SDCC won't install the signal handler
12158  in order to be able to debug SDCC.
12159 \end_layout
12160
12161 \begin_layout List
12162 \labelwidthstring 00.00.0000
12163
12164 \series bold
12165 TMP,\InsetSpace ~
12166 TEMP,\InsetSpace ~
12167 TMPDIR
12168 \begin_inset LatexCommand index
12169 name "TMP, TEMP, TMPDIR"
12170
12171 \end_inset
12172
12173
12174 \series default
12175  Path, where temporary files will be created.
12176  The order of the variables is the search order.
12177  In a standard *nix environment these variables are not set, and there's
12178  no need to set them.
12179  On Windows it's recommended to set one of them.
12180 \end_layout
12181
12182 \begin_layout List
12183 \labelwidthstring 00.00.0000
12184
12185 \series bold
12186 SDCC_HOME
12187 \begin_inset LatexCommand index
12188 name "SDCC\\_HOME"
12189
12190 \end_inset
12191
12192
12193 \series default
12194  Path, see section 
12195 \begin_inset LatexCommand ref
12196 reference "sub:Install-paths"
12197
12198 \end_inset
12199
12200 \InsetSpace ~
12201
12202 \begin_inset Quotes sld
12203 \end_inset
12204
12205  Install Paths
12206 \begin_inset Quotes srd
12207 \end_inset
12208
12209 .
12210 \end_layout
12211
12212 \begin_layout List
12213 \labelwidthstring 00.00.0000
12214
12215 \series bold
12216 SDCC_INCLUDE
12217 \begin_inset LatexCommand index
12218 name "SDCC\\_INCLUDE"
12219
12220 \end_inset
12221
12222
12223 \series default
12224  Path, see section 
12225 \begin_inset LatexCommand ref
12226 reference "sub:Search-Paths"
12227
12228 \end_inset
12229
12230 \InsetSpace ~
12231
12232 \begin_inset Quotes sld
12233 \end_inset
12234
12235 Search Paths
12236 \begin_inset Quotes srd
12237 \end_inset
12238
12239 .
12240 \end_layout
12241
12242 \begin_layout List
12243 \labelwidthstring 00.00.0000
12244
12245 \series bold
12246 SDCC_LIB
12247 \begin_inset LatexCommand index
12248 name "SDCC\\_LIB"
12249
12250 \end_inset
12251
12252
12253 \series default
12254  Path, see section 
12255 \begin_inset LatexCommand ref
12256 reference "sub:Search-Paths"
12257
12258 \end_inset
12259
12260 \InsetSpace ~
12261
12262 \begin_inset Quotes sld
12263 \end_inset
12264
12265 Search Paths
12266 \begin_inset Quotes srd
12267 \end_inset
12268
12269 ..
12270 \end_layout
12271
12272 \begin_layout Standard
12273 There are some more environment variables recognized by SDCC, but these
12274  are solely used for debugging purposes.
12275  They can change or disappear very quickly, and will never be documented.
12276 \begin_inset VSpace bigskip
12277 \end_inset
12278
12279
12280 \end_layout
12281
12282 \begin_layout Section
12283 Storage Class Language Extensions
12284 \end_layout
12285
12286 \begin_layout Subsection
12287 MCS51/DS390 Storage Class
12288 \begin_inset LatexCommand index
12289 name "Storage class"
12290
12291 \end_inset
12292
12293  Language Extensions
12294 \end_layout
12295
12296 \begin_layout Standard
12297 In addition to the ANSI storage classes SDCC allows the following MCS51
12298  specific storage classes:
12299 \end_layout
12300
12301 \begin_layout Subsubsection
12302 data
12303 \begin_inset LatexCommand index
12304 name "data (mcs51, ds390 storage class)"
12305
12306 \end_inset
12307
12308
12309 \begin_inset LatexCommand index
12310 name "\\_\\_data (mcs51, ds390 storage class)"
12311
12312 \end_inset
12313
12314  / near
12315 \begin_inset LatexCommand index
12316 name "near (storage class)"
12317
12318 \end_inset
12319
12320
12321 \begin_inset LatexCommand index
12322 name "\\_\\_near (storage class)"
12323
12324 \end_inset
12325
12326
12327 \end_layout
12328
12329 \begin_layout Standard
12330 This is the 
12331 \series bold
12332 default
12333 \series default
12334  storage class for the Small Memory model (
12335 \emph on
12336 data
12337 \emph default
12338  and 
12339 \emph on
12340 near
12341 \emph default
12342  or the more ANSI-C compliant forms 
12343 \emph on
12344 __data
12345 \emph default
12346  and 
12347 \emph on
12348 __near
12349 \emph default
12350  can be used synonymously).
12351  Variables declared with this storage class will be allocated in the directly
12352  addressable portion of the internal RAM of a 8051, e.g.:
12353 \end_layout
12354
12355 \begin_layout Verse
12356
12357 \family typewriter
12358 __data unsigned char test_data;
12359 \end_layout
12360
12361 \begin_layout Standard
12362 Writing 0x01 to this variable generates the assembly code:
12363 \end_layout
12364
12365 \begin_layout Verse
12366
12367 \family typewriter
12368 75*00 01\InsetSpace ~
12369 \InsetSpace ~
12370 \InsetSpace ~
12371 mov\InsetSpace ~
12372 \InsetSpace ~
12373 _test_data,#0x01
12374 \end_layout
12375
12376 \begin_layout Subsubsection
12377 xdata
12378 \begin_inset LatexCommand index
12379 name "xdata (mcs51, ds390 storage class)"
12380
12381 \end_inset
12382
12383
12384 \begin_inset LatexCommand index
12385 name "\\_\\_xdata (mcs51, ds390 storage class)"
12386
12387 \end_inset
12388
12389  / far
12390 \begin_inset LatexCommand index
12391 name "far (storage class)"
12392
12393 \end_inset
12394
12395
12396 \begin_inset LatexCommand index
12397 name "\\_\\_far (storage class)"
12398
12399 \end_inset
12400
12401
12402 \end_layout
12403
12404 \begin_layout Standard
12405 Variables declared with this storage class will be placed in the external
12406  RAM.
12407  This is the 
12408 \series bold
12409 default
12410 \series default
12411  storage class for the Large Memory model, e.g.:
12412 \end_layout
12413
12414 \begin_layout Verse
12415
12416 \family typewriter
12417 __xdata unsigned char test_xdata;
12418 \end_layout
12419
12420 \begin_layout Standard
12421 Writing 0x01 to this variable generates the assembly code:
12422 \end_layout
12423
12424 \begin_layout Verse
12425
12426 \family typewriter
12427 90s00r00\InsetSpace ~
12428 \InsetSpace ~
12429 \InsetSpace ~
12430 mov\InsetSpace ~
12431 \InsetSpace ~
12432 dptr,#_test_xdata 
12433 \newline
12434 74\InsetSpace ~
12435 01\InsetSpace ~
12436 \InsetSpace ~
12437 \InsetSpace ~
12438 \InsetSpace ~
12439 \InsetSpace ~
12440 \InsetSpace ~
12441 mov\InsetSpace ~
12442 \InsetSpace ~
12443 a,#0x01 
12444 \newline
12445 F0\InsetSpace ~
12446 \InsetSpace ~
12447 \InsetSpace ~
12448 \InsetSpace ~
12449 \InsetSpace ~
12450 \InsetSpace ~
12451 \InsetSpace ~
12452 \InsetSpace ~
12453 \InsetSpace ~
12454 movx\InsetSpace ~
12455 @dptr,a 
12456 \end_layout
12457
12458 \begin_layout Subsubsection
12459 idata
12460 \begin_inset LatexCommand index
12461 name "idata (mcs51, ds390 storage class)"
12462
12463 \end_inset
12464
12465
12466 \begin_inset LatexCommand index
12467 name "\\_\\_idata (mcs51, ds390 storage class)"
12468
12469 \end_inset
12470
12471
12472 \end_layout
12473
12474 \begin_layout Standard
12475 Variables declared with this storage class will be allocated into the indirectly
12476  addressable portion of the internal ram of a 8051, e.g.:
12477 \end_layout
12478
12479 \begin_layout Verse
12480
12481 \family typewriter
12482 __idata unsigned char test_idata;
12483 \end_layout
12484
12485 \begin_layout Standard
12486 Writing 0x01 to this variable generates the assembly code:
12487 \end_layout
12488
12489 \begin_layout Verse
12490
12491 \family typewriter
12492 78r00\InsetSpace ~
12493 \InsetSpace ~
12494 \InsetSpace ~
12495 \InsetSpace ~
12496 \InsetSpace ~
12497 \InsetSpace ~
12498 \InsetSpace ~
12499 mov\InsetSpace ~
12500 \InsetSpace ~
12501 r0,#_test_idata
12502 \newline
12503 76\InsetSpace ~
12504 01\InsetSpace ~
12505 \InsetSpace ~
12506 \InsetSpace ~
12507 \InsetSpace ~
12508 \InsetSpace ~
12509 \InsetSpace ~
12510 \InsetSpace ~
12511 mov\InsetSpace ~
12512 \InsetSpace ~
12513 @r0,#0x01
12514 \end_layout
12515
12516 \begin_layout Standard
12517 Please note, the first 128 byte of idata physically access the same RAM
12518  as the data memory.
12519  The original 8051 had 128 byte idata memory, nowadays most devices have
12520  256 byte idata memory.
12521  The stack
12522 \begin_inset LatexCommand index
12523 name "stack"
12524
12525 \end_inset
12526
12527  is located in idata memory.
12528 \end_layout
12529
12530 \begin_layout Subsubsection
12531 pdata
12532 \begin_inset LatexCommand index
12533 name "pdata (mcs51, ds390 storage class)"
12534
12535 \end_inset
12536
12537
12538 \begin_inset LatexCommand index
12539 name "\\_\\_pdata (mcs51, ds390 storage class)"
12540
12541 \end_inset
12542
12543
12544 \end_layout
12545
12546 \begin_layout Standard
12547 Paged xdata access is just as straightforward as using the other addressing
12548  modes of a 8051.
12549  It is typically located at the start of xdata and has a maximum size of
12550  256 bytes.
12551  The following example writes 0x01 to the pdata variable.
12552  Please note, pdata access physically accesses xdata memory.
12553  The high byte of the address is determined by port P2 
12554 \begin_inset LatexCommand index
12555 name "P2 (mcs51 sfr)"
12556
12557 \end_inset
12558
12559 (or in case of some 8051 variants by a separate Special Function Register,
12560  see section 
12561 \begin_inset LatexCommand ref
12562 reference "sub:MCS51-variants"
12563
12564 \end_inset
12565
12566 ).
12567  This is the 
12568 \series bold
12569 default
12570 \series default
12571  storage class for the Medium Memory model, e.g.:
12572 \end_layout
12573
12574 \begin_layout Verse
12575
12576 \family typewriter
12577 __pdata unsigned char test_pdata;
12578 \end_layout
12579
12580 \begin_layout Standard
12581 Writing 0x01 to this variable generates the assembly code:
12582 \end_layout
12583
12584 \begin_layout Verse
12585
12586 \family typewriter
12587 78r00\InsetSpace ~
12588 \InsetSpace ~
12589 \InsetSpace ~
12590 \InsetSpace ~
12591 \InsetSpace ~
12592 \InsetSpace ~
12593 mov r0,#_test_pdata
12594 \newline
12595 74 01\InsetSpace ~
12596 \InsetSpace ~
12597 \InsetSpace ~
12598 \InsetSpace ~
12599 \InsetSpace ~
12600 \InsetSpace ~
12601 mov a,#0x01 
12602 \newline
12603 F2\InsetSpace ~
12604 \InsetSpace ~
12605 \InsetSpace ~
12606 \InsetSpace ~
12607 \InsetSpace ~
12608 \InsetSpace ~
12609 \InsetSpace ~
12610 \InsetSpace ~
12611 \InsetSpace ~
12612 movx @r0,a
12613 \end_layout
12614
12615 \begin_layout Standard
12616 If the -
12617 \begin_inset ERT
12618 status collapsed
12619
12620 \begin_layout Standard
12621
12622
12623 \backslash
12624 /
12625 \end_layout
12626
12627 \end_inset
12628
12629 -xstack
12630 \begin_inset LatexCommand index
12631 name "-\\/-xstack"
12632
12633 \end_inset
12634
12635  option is used the pdata memory area is followed by the xstack memory area
12636  and the sum of their sizes is limited to 256 bytes.
12637 \end_layout
12638
12639 \begin_layout Subsubsection
12640 code
12641 \begin_inset LatexCommand index
12642 name "code"
12643
12644 \end_inset
12645
12646
12647 \begin_inset LatexCommand index
12648 name "\\_\\_code"
12649
12650 \end_inset
12651
12652
12653 \end_layout
12654
12655 \begin_layout Standard
12656 'Variables' declared with this storage class will be placed in the code
12657  memory:
12658 \end_layout
12659
12660 \begin_layout Verse
12661
12662 \family typewriter
12663 __code unsigned char test_code;
12664 \end_layout
12665
12666 \begin_layout Standard
12667 Read access to this variable generates the assembly code:
12668 \end_layout
12669
12670 \begin_layout Verse
12671
12672 \family typewriter
12673 90s00r6F\InsetSpace ~
12674 \InsetSpace ~
12675 \InsetSpace ~
12676 mov dptr,#_test_code
12677 \newline
12678 E4\InsetSpace ~
12679 \InsetSpace ~
12680 \InsetSpace ~
12681 \InsetSpace ~
12682 \InsetSpace ~
12683 \InsetSpace ~
12684 \InsetSpace ~
12685 \InsetSpace ~
12686 \InsetSpace ~
12687 clr a
12688 \newline
12689 93\InsetSpace ~
12690 \InsetSpace ~
12691 \InsetSpace ~
12692 \InsetSpace ~
12693 \InsetSpace ~
12694 \InsetSpace ~
12695 \InsetSpace ~
12696 \InsetSpace ~
12697 \InsetSpace ~
12698 movc a,@a+dptr 
12699 \end_layout
12700
12701 \begin_layout Standard
12702
12703 \family typewriter
12704 char
12705 \family default
12706  indexed arrays of characters in code memory can be accessed efficiently:
12707 \end_layout
12708
12709 \begin_layout Verse
12710
12711 \family typewriter
12712 __code char test_array[] = {'c','h','e','a','p'}; 
12713 \end_layout
12714
12715 \begin_layout Standard
12716 Read access to this array using an 8-bit unsigned index generates the assembly
12717  code:
12718 \end_layout
12719
12720 \begin_layout Verse
12721
12722 \family typewriter
12723 E5*00\InsetSpace ~
12724 \InsetSpace ~
12725 \InsetSpace ~
12726 \InsetSpace ~
12727 \InsetSpace ~
12728 \InsetSpace ~
12729 mov a,_index 
12730 \end_layout
12731
12732 \begin_layout Verse
12733
12734 \family typewriter
12735 90s00r41\InsetSpace ~
12736 \InsetSpace ~
12737 \InsetSpace ~
12738 mov dptr,#_test_array
12739 \end_layout
12740
12741 \begin_layout Verse
12742
12743 \family typewriter
12744 93\InsetSpace ~
12745 \InsetSpace ~
12746 \InsetSpace ~
12747 \InsetSpace ~
12748 \InsetSpace ~
12749 \InsetSpace ~
12750 \InsetSpace ~
12751 \InsetSpace ~
12752 \InsetSpace ~
12753 movc a,@a+dptr 
12754 \end_layout
12755
12756 \begin_layout Subsubsection
12757 bit
12758 \begin_inset LatexCommand index
12759 name "bit"
12760
12761 \end_inset
12762
12763
12764 \begin_inset LatexCommand index
12765 name "\\_\\_bit"
12766
12767 \end_inset
12768
12769
12770 \end_layout
12771
12772 \begin_layout Standard
12773 This is a data-type and a storage class specifier.
12774  When a variable is declared as a bit, it is allocated into the bit addressable
12775  memory of 8051, e.g.:
12776 \end_layout
12777
12778 \begin_layout Verse
12779
12780 \family typewriter
12781 __bit test_bit;
12782 \end_layout
12783
12784 \begin_layout Standard
12785 Writing 1 to this variable generates the assembly code:
12786 \end_layout
12787
12788 \begin_layout Verse
12789
12790 \family typewriter
12791 D2*00\InsetSpace ~
12792 \InsetSpace ~
12793 \InsetSpace ~
12794 \InsetSpace ~
12795 \InsetSpace ~
12796 \InsetSpace ~
12797 \InsetSpace ~
12798 setb\InsetSpace ~
12799 _test_bit
12800 \end_layout
12801
12802 \begin_layout Standard
12803 The bit addressable memory consists of 128 bits which are located from 0x20
12804  to 0x2f in data memory.
12805  
12806 \newline
12807 Apart from this 8051 specific storage class most architectures support
12808  ANSI-C bitfields
12809 \begin_inset LatexCommand index
12810 name "bitfields"
12811
12812 \end_inset
12813
12814
12815 \begin_inset Foot
12816 status open
12817
12818 \begin_layout Standard
12819 Not really meant as examples, but nevertheless showing what bitfields are
12820  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12821 \end_layout
12822
12823 \end_inset
12824
12825 .
12826  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12827  signed modifier are implemented as unsigned.
12828 \end_layout
12829
12830 \begin_layout Subsubsection
12831 sfr
12832 \begin_inset LatexCommand index
12833 name "sfr"
12834
12835 \end_inset
12836
12837
12838 \begin_inset LatexCommand index
12839 name "\\_\\_sfr"
12840
12841 \end_inset
12842
12843  / sfr16
12844 \begin_inset LatexCommand index
12845 name "sfr16"
12846
12847 \end_inset
12848
12849
12850 \begin_inset LatexCommand index
12851 name "\\_\\_sfr16"
12852
12853 \end_inset
12854
12855  / sfr32
12856 \begin_inset LatexCommand index
12857 name "sfr32"
12858
12859 \end_inset
12860
12861
12862 \begin_inset LatexCommand index
12863 name "\\_\\_sfr32"
12864
12865 \end_inset
12866
12867  / sbit
12868 \begin_inset LatexCommand index
12869 name "\\_\\_sbit"
12870
12871 \end_inset
12872
12873
12874 \begin_inset LatexCommand index
12875 name "sbit"
12876
12877 \end_inset
12878
12879
12880 \end_layout
12881
12882 \begin_layout Standard
12883 Like the bit keyword, 
12884 \emph on
12885 sfr / sfr16 / sfr32 / sbit
12886 \emph default
12887  signify both a data-type and storage class, they are used to describe the
12888  
12889 \emph on
12890 s
12891 \emph default
12892 pecial 
12893 \emph on
12894 f
12895 \emph default
12896 unction 
12897 \emph on
12898 r
12899 \emph default
12900 egisters and 
12901 \emph on
12902 s
12903 \emph default
12904 pecial 
12905 \emph on
12906 bit
12907 \emph default
12908  variables of a 8051, eg:
12909 \end_layout
12910
12911 \begin_layout Verse
12912
12913 \family typewriter
12914 __sfr __at
12915 \begin_inset LatexCommand index
12916 name "at"
12917
12918 \end_inset
12919
12920
12921 \begin_inset LatexCommand index
12922 name "\\_\\_at"
12923
12924 \end_inset
12925
12926  (0x80) P0;\InsetSpace ~
12927  /* special function register P0 at location 0x80 */
12928 \newline
12929
12930 \newline
12931 /* 16 bit
12932  special function register combination for timer 0
12933 \newline
12934 \InsetSpace ~
12935 \InsetSpace ~
12936  with the high byte at
12937  location 0x8C and the low byte at location 0x8A */
12938 \newline
12939 __sfr16 __at (0x8C8A)
12940  TMR0;
12941 \newline
12942
12943 \newline
12944 __sbit __at
12945 \begin_inset LatexCommand index
12946 name "at"
12947
12948 \end_inset
12949
12950
12951 \begin_inset LatexCommand index
12952 name "\\_\\_at"
12953
12954 \end_inset
12955
12956  (0xd7) CY;\InsetSpace ~
12957  /* CY (Carry Flag
12958 \begin_inset LatexCommand index
12959 name "Flags"
12960
12961 \end_inset
12962
12963
12964 \begin_inset LatexCommand index
12965 name "Carry flag"
12966
12967 \end_inset
12968
12969 ) */
12970 \end_layout
12971
12972 \begin_layout Standard
12973 Special function registers which are located on an address dividable by
12974  8 are bit-addressable, an 
12975 \emph on
12976 sbit
12977 \emph default
12978  addresses a specific bit within these sfr.
12979 \newline
12980 16 Bit and 32 bit special function
12981  register combinations which require a certain access order are better not
12982  declared using 
12983 \emph on
12984 sfr16
12985 \emph default
12986  or 
12987 \emph on
12988 sfr32.
12989
12990 \emph default
12991  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12992  this is not guaranteed.
12993 \newline
12994
12995 \end_layout
12996
12997 \begin_layout Standard
12998 Please note, if you use a header file which was written for another compiler
12999  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
13000  likely be 
13001 \emph on
13002 not
13003 \emph default
13004  compatible.
13005  Specifically the syntax 
13006 \family typewriter
13007 \InsetSpace ~
13008 sfr P0 = 0x80;\InsetSpace ~
13009
13010 \family default
13011  is compiled 
13012 \emph on
13013 without warning
13014 \emph default
13015  by SDCC to an assignment of 0x80 to a variable called P0 
13016 \family typewriter
13017
13018 \begin_inset Marginal
13019 status collapsed
13020
13021 \begin_layout Standard
13022
13023 \series bold
13024 \InsetSpace ~
13025 !
13026 \end_layout
13027
13028 \end_inset
13029
13030 .
13031
13032 \family default
13033  
13034 \series bold
13035 Nevertheless it is possible to write header files
13036 \begin_inset LatexCommand index
13037 name "Header files"
13038
13039 \end_inset
13040
13041
13042 \begin_inset LatexCommand index
13043 name "Include files"
13044
13045 \end_inset
13046
13047  which can be shared among different compilers (see section 
13048 \begin_inset LatexCommand ref
13049 reference "sec:Porting-code-to-other-compilers"
13050
13051 \end_inset
13052
13053 ).
13054  
13055 \end_layout
13056
13057 \begin_layout Subsubsection
13058 Pointers
13059 \begin_inset LatexCommand index
13060 name "Pointer"
13061
13062 \end_inset
13063
13064  to MCS51/DS390 specific memory spaces
13065 \end_layout
13066
13067 \begin_layout Standard
13068 SDCC allows (via language extensions) pointers to explicitly point to any
13069  of the memory spaces
13070 \begin_inset LatexCommand index
13071 name "Memory model"
13072
13073 \end_inset
13074
13075  of the 8051.
13076  In addition to the explicit pointers, the compiler uses (by default) generic
13077  pointers which can be used to point to any of the memory spaces.
13078 \newline
13079
13080 \newline
13081 Pointer
13082  declaration examples:
13083 \end_layout
13084
13085 \begin_layout Verse
13086
13087 \family typewriter
13088 /* pointer physically in internal ram pointing to object in external ram
13089  */ 
13090 \newline
13091 __xdata unsigned char * __data p;
13092 \newline
13093
13094 \newline
13095 /* pointer physically in external ram
13096  pointing to object in internal ram */ 
13097 \newline
13098 __data unsigned char * __xdata p;
13099 \newline
13100
13101 \newline
13102 /*
13103  pointer physically in code rom pointing to data in xdata space */ 
13104 \newline
13105 __xdata
13106  unsigned char * __code p;
13107 \newline
13108
13109 \newline
13110 /* pointer physically in code space pointing to
13111  data in code space */ 
13112 \newline
13113 __code unsigned char * __code p;
13114 \newline
13115
13116 \newline
13117 /* generic pointer
13118  physically located in xdata space */
13119 \newline
13120 unsigned char * __xdata p;
13121 \newline
13122
13123 \newline
13124 /* generic
13125  pointer physically located in default memory space */
13126 \newline
13127 unsigned char * p;
13128 \newline
13129
13130 \newline
13131 /*
13132  the following is a function pointer
13133 \begin_inset LatexCommand index
13134 name "function pointer"
13135
13136 \end_inset
13137
13138  physically located in data space */
13139 \newline
13140 char (* __data fp)(void);
13141 \end_layout
13142
13143 \begin_layout Standard
13144 Well you get the idea.
13145  
13146 \newline
13147
13148 \newline
13149 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
13150 \emph on
13151 generic
13152 \emph default
13153  pointers.
13154  
13155 \size small
13156
13157 \newline
13158
13159 \newline
13160
13161 \size default
13162 The highest order byte of the 
13163 \emph on
13164 generic
13165 \emph default
13166  pointers contains the data space information.
13167  Assembler support routines are called whenever data is stored or retrieved
13168  using 
13169 \emph on
13170 generic
13171 \emph default
13172  pointers.
13173  These are useful for developing reusable library
13174 \begin_inset LatexCommand index
13175 name "Libraries"
13176
13177 \end_inset
13178
13179  routines.
13180  Explicitly specifying the pointer
13181 \begin_inset LatexCommand index
13182 name "pointer"
13183
13184 \end_inset
13185
13186  type will generate the most efficient code.
13187 \end_layout
13188
13189 \begin_layout Subsubsection
13190 Notes on MCS51 memory
13191 \begin_inset LatexCommand index
13192 name "MCS51 memory"
13193
13194 \end_inset
13195
13196  layout
13197 \end_layout
13198
13199 \begin_layout Standard
13200 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
13201  RAM memory which is structured as follows:
13202 \newline
13203
13204 \newline
13205 - Bytes 00-1F - 32 bytes to hold
13206  up to 4 banks of the registers R0 to R7, 
13207 \newline
13208 - Bytes 20-2F - 16 bytes to hold
13209  128 bit
13210 \begin_inset LatexCommand index
13211 name "bit"
13212
13213 \end_inset
13214
13215  variables and, 
13216 \newline
13217 - Bytes 30-7F - 80 bytes for general purpose use.
13218 \newline
13219
13220 \end_layout
13221
13222 \begin_layout Standard
13223 Additionally some members of the MCS51 family may have up to 128 bytes of
13224  additional, indirectly addressable, internal RAM memory (
13225 \emph on
13226 idata
13227 \emph default
13228
13229 \begin_inset LatexCommand index
13230 name "idata (mcs51, ds390 storage class)"
13231
13232 \end_inset
13233
13234
13235 \begin_inset LatexCommand index
13236 name "\\_\\_idata (mcs51, ds390 storage class)"
13237
13238 \end_inset
13239
13240 ).
13241  Furthermore, some chips may have some built in external memory (
13242 \emph on
13243 xdata
13244 \emph default
13245
13246 \begin_inset LatexCommand index
13247 name "xdata (mcs51, ds390 storage class)"
13248
13249 \end_inset
13250
13251
13252 \begin_inset LatexCommand index
13253 name "\\_\\_xdata (mcs51, ds390 storage class)"
13254
13255 \end_inset
13256
13257 ) which should not be confused with the internal, directly addressable RAM
13258  memory (
13259 \emph on
13260 data
13261 \emph default
13262
13263 \begin_inset LatexCommand index
13264 name "data (mcs51, ds390 storage class)"
13265
13266 \end_inset
13267
13268
13269 \begin_inset LatexCommand index
13270 name "\\_\\_data (mcs51, ds390 storage class)"
13271
13272 \end_inset
13273
13274 ).
13275  Sometimes this built in 
13276 \emph on
13277 xdata
13278 \emph default
13279  memory has to be activated before using it (you can probably find this
13280  information on the datasheet of the microcontroller your are using, see
13281  also section 
13282 \begin_inset LatexCommand ref
13283 reference "sub:Startup-Code"
13284
13285 \end_inset
13286
13287 \InsetSpace ~
13288 Startup-Code).
13289 \end_layout
13290
13291 \begin_layout Standard
13292 Normally SDCC will only use the first bank
13293 \begin_inset LatexCommand index
13294 name "register bank (mcs51, ds390)"
13295
13296 \end_inset
13297
13298  of registers (register bank 0), but it is possible to specify that other
13299  banks of registers (keyword 
13300 \emph on
13301 using
13302 \emph default
13303  
13304 \emph on
13305
13306 \begin_inset LatexCommand index
13307 name "using (mcs51, ds390 register bank)"
13308
13309 \end_inset
13310
13311
13312 \begin_inset LatexCommand index
13313 name "\\_\\_using (mcs51, ds390 register bank)"
13314
13315 \end_inset
13316
13317
13318 \emph default
13319 ) should be used for example in interrupt
13320 \begin_inset LatexCommand index
13321 name "interrupt"
13322
13323 \end_inset
13324
13325
13326 \begin_inset LatexCommand index
13327 name "\\_\\_interrupt"
13328
13329 \end_inset
13330
13331  routines.
13332  By default, the compiler will place the stack after the last byte of allocated
13333  memory for variables.
13334  For example, if the first 2 banks of registers are used, and only four
13335  bytes are used for 
13336 \emph on
13337 data
13338 \emph default
13339  variables, it will position the base of the internal stack at address 20
13340  (0x14).
13341  This implies that as the stack
13342 \begin_inset LatexCommand index
13343 name "stack"
13344
13345 \end_inset
13346
13347  grows, it will use up the remaining register banks, and the 16 bytes used
13348  by the 128 bit variables, and 80 bytes for general purpose use.
13349  If any bit variables are used, the data variables will be placed in unused
13350  register banks and after the byte holding the last bit variable.
13351  For example, if register banks 0 and 1 are used, and there are 9 bit variables
13352  (two bytes used), 
13353 \emph on
13354 data
13355 \emph default
13356  variables will be placed starting from address 0x10 to 0x20 and continue
13357  at address 0x22.
13358  You can also use -
13359 \begin_inset ERT
13360 status collapsed
13361
13362 \begin_layout Standard
13363
13364
13365 \backslash
13366 /
13367 \end_layout
13368
13369 \end_inset
13370
13371 -data-loc
13372 \begin_inset LatexCommand index
13373 name "-\\/-data-loc <Value>"
13374
13375 \end_inset
13376
13377  to specify the start address of the 
13378 \emph on
13379 data
13380 \emph default
13381  and -
13382 \begin_inset ERT
13383 status collapsed
13384
13385 \begin_layout Standard
13386
13387
13388 \backslash
13389 /
13390 \end_layout
13391
13392 \end_inset
13393
13394 -iram-size
13395 \begin_inset LatexCommand index
13396 name "-\\/-iram-size <Value>"
13397
13398 \end_inset
13399
13400  to specify the size of the total internal RAM (
13401 \emph on
13402 data
13403 \emph default
13404 +
13405 \emph on
13406 idata
13407 \emph default
13408 ).
13409  
13410 \newline
13411
13412 \end_layout
13413
13414 \begin_layout Standard
13415 By default the 8051 linker will place the stack after the last byte of (i)data
13416  variables.
13417  Option -
13418 \begin_inset ERT
13419 status collapsed
13420
13421 \begin_layout Standard
13422
13423
13424 \backslash
13425 /
13426 \end_layout
13427
13428 \end_inset
13429
13430 -stack-loc
13431 \begin_inset LatexCommand index
13432 name "-\\/-stack-loc <Value>"
13433
13434 \end_inset
13435
13436  allows you to specify the start of the stack, i.e.
13437  you could start it after any data in the general purpose area.
13438  If your microcontroller has additional indirectly addressable internal
13439  RAM (
13440 \emph on
13441 idata
13442 \emph default
13443 ) you can place the stack on it.
13444  You may also need to use -
13445 \begin_inset ERT
13446 status collapsed
13447
13448 \begin_layout Standard
13449
13450
13451 \backslash
13452 /
13453 \end_layout
13454
13455 \end_inset
13456
13457 -xdata-loc
13458 \begin_inset LatexCommand index
13459 name "-\\/-xdata-loc<Value>"
13460
13461 \end_inset
13462
13463  to set the start address of the external RAM (
13464 \emph on
13465 xdata
13466 \emph default
13467 ) and -
13468 \begin_inset ERT
13469 status collapsed
13470
13471 \begin_layout Standard
13472
13473
13474 \backslash
13475 /
13476 \end_layout
13477
13478 \end_inset
13479
13480 -xram-size
13481 \begin_inset LatexCommand index
13482 name "-\\/-xram-size <Value>"
13483
13484 \end_inset
13485
13486  to specify its size.
13487  Same goes for the code memory, using -
13488 \begin_inset ERT
13489 status collapsed
13490
13491 \begin_layout Standard
13492
13493
13494 \backslash
13495 /
13496 \end_layout
13497
13498 \end_inset
13499
13500 -code-loc
13501 \begin_inset LatexCommand index
13502 name "-\\/-code-loc <Value>"
13503
13504 \end_inset
13505
13506  and -
13507 \begin_inset ERT
13508 status collapsed
13509
13510 \begin_layout Standard
13511
13512
13513 \backslash
13514 /
13515 \end_layout
13516
13517 \end_inset
13518
13519 -code-size
13520 \begin_inset LatexCommand index
13521 name "-\\/-code-size <Value>"
13522
13523 \end_inset
13524
13525 .
13526  If in doubt, don't specify any options and see if the resulting memory
13527  layout is appropriate, then you can adjust it.
13528 \end_layout
13529
13530 \begin_layout Standard
13531 The linker generates two files with memory allocation information.
13532  The first, with extension .map
13533 \begin_inset LatexCommand index
13534 name "<file>.map"
13535
13536 \end_inset
13537
13538  shows all the variables and segments.
13539  The second with extension .mem
13540 \begin_inset LatexCommand index
13541 name "<file>.mem"
13542
13543 \end_inset
13544
13545  shows the final memory layout.
13546  The linker will complain either if memory segments overlap, there is not
13547  enough memory, or there is not enough space for stack.
13548  If you get any linking warnings and/or errors related to stack or segments
13549  allocation, take a look at either the .map or .mem files to find out what
13550  the problem is.
13551  The .mem file may even suggest a solution to the problem.
13552 \begin_inset VSpace bigskip
13553 \end_inset
13554
13555
13556 \end_layout
13557
13558 \begin_layout Subsection
13559 Z80/Z180 Storage Class
13560 \begin_inset LatexCommand index
13561 name "Z80!Storage class"
13562
13563 \end_inset
13564
13565  Language Extensions
13566 \end_layout
13567
13568 \begin_layout Subsubsection
13569 sfr
13570 \begin_inset LatexCommand index
13571 name "sfr"
13572
13573 \end_inset
13574
13575
13576 \begin_inset LatexCommand index
13577 name "\\_\\_sfr"
13578
13579 \end_inset
13580
13581  (in/out to 8-bit addresses)
13582 \end_layout
13583
13584 \begin_layout Standard
13585 The Z80
13586 \begin_inset LatexCommand index
13587 name "Z80"
13588
13589 \end_inset
13590
13591  family has separate address spaces for memory and 
13592 \emph on
13593 i
13594 \emph default
13595 nput/
13596 \emph on
13597 o
13598 \emph default
13599 utput memory.
13600  I/O memory
13601 \begin_inset LatexCommand index
13602 name "I/O memory (Z80, Z180)"
13603
13604 \end_inset
13605
13606
13607 \begin_inset LatexCommand index
13608 name "Z80!I/O memory"
13609
13610 \end_inset
13611
13612
13613 \begin_inset LatexCommand index
13614 name "Z180!I/O memory"
13615
13616 \end_inset
13617
13618  is accessed with special instructions, e.g.:
13619 \end_layout
13620
13621 \begin_layout Verse
13622
13623 \family typewriter
13624 sfr at 0x78 IoPort;\InsetSpace ~
13625 \InsetSpace ~
13626 /* define a var in I/O space at 78h called IoPort */
13627  
13628 \end_layout
13629
13630 \begin_layout Standard
13631 Writing 0x01 to this variable generates the assembly code:
13632 \end_layout
13633
13634 \begin_layout Verse
13635
13636 \family typewriter
13637 3E 01\InsetSpace ~
13638 \InsetSpace ~
13639 \InsetSpace ~
13640 \InsetSpace ~
13641 \InsetSpace ~
13642 \InsetSpace ~
13643 ld a,#0x01
13644 \newline
13645 D3 78\InsetSpace ~
13646 \InsetSpace ~
13647 \InsetSpace ~
13648 \InsetSpace ~
13649 \InsetSpace ~
13650 \InsetSpace ~
13651 out (_IoPort),a 
13652 \end_layout
13653
13654 \begin_layout Subsubsection
13655 banked sfr
13656 \begin_inset LatexCommand index
13657 name "sfr"
13658
13659 \end_inset
13660
13661
13662 \begin_inset LatexCommand index
13663 name "\\_\\_sfr"
13664
13665 \end_inset
13666
13667  (in/out to 16-bit addresses)
13668 \end_layout
13669
13670 \begin_layout Standard
13671 The keyword 
13672 \emph on
13673 banked
13674 \emph default
13675  is used to support 16 bit addresses in I/O memory e.g.:
13676 \end_layout
13677
13678 \begin_layout Verse
13679
13680 \family typewriter
13681 sfr banked at
13682 \begin_inset LatexCommand index
13683 name "at"
13684
13685 \end_inset
13686
13687
13688 \begin_inset LatexCommand index
13689 name "\\_\\_at"
13690
13691 \end_inset
13692
13693  0x123 IoPort; 
13694 \end_layout
13695
13696 \begin_layout Standard
13697 Writing 0x01 to this variable generates the assembly code:
13698 \end_layout
13699
13700 \begin_layout Verse
13701
13702 \family typewriter
13703 01 23 01\InsetSpace ~
13704 \InsetSpace ~
13705 \InsetSpace ~
13706 ld bc,#_IoPort
13707 \newline
13708 3E 01\InsetSpace ~
13709 \InsetSpace ~
13710 \InsetSpace ~
13711 \InsetSpace ~
13712 \InsetSpace ~
13713 \InsetSpace ~
13714 ld a,#0x01 
13715 \newline
13716 ED 79\InsetSpace ~
13717 \InsetSpace ~
13718 \InsetSpace ~
13719 \InsetSpace ~
13720 \InsetSpace ~
13721 \InsetSpace ~
13722 out (c),a 
13723 \end_layout
13724
13725 \begin_layout Subsubsection
13726 sfr
13727 \begin_inset LatexCommand index
13728 name "sfr"
13729
13730 \end_inset
13731
13732
13733 \begin_inset LatexCommand index
13734 name "\\_\\_sfr"
13735
13736 \end_inset
13737
13738  (in0/out0 to 8 bit addresses on Z180
13739 \begin_inset LatexCommand index
13740 name "Z180"
13741
13742 \end_inset
13743
13744 /HD64180
13745 \begin_inset LatexCommand index
13746 name "HD64180 (see Z180)"
13747
13748 \end_inset
13749
13750 )
13751 \end_layout
13752
13753 \begin_layout Standard
13754 The compiler option -
13755 \begin_inset ERT
13756 status collapsed
13757
13758 \begin_layout Standard
13759
13760
13761 \backslash
13762 /
13763 \end_layout
13764
13765 \end_inset
13766
13767 -portmode
13768 \begin_inset LatexCommand index
13769 name "Z180!Options!-\\/-portmode"
13770
13771 \end_inset
13772
13773 =180 (80) and a compiler #pragma\InsetSpace ~
13774 portmode
13775 \begin_inset LatexCommand index
13776 name "Z180!Pragmas!\\#pragma portmode"
13777
13778 \end_inset
13779
13780  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13781 ns 
13782 \family typewriter
13783 in0/out0
13784 \family default
13785  instead of 
13786 \family typewriter
13787 in/out
13788 \family default
13789 .
13790  If you include the file z180.h this will be set automatically.
13791 \begin_inset VSpace bigskip
13792 \end_inset
13793
13794
13795 \end_layout
13796
13797 \begin_layout Subsection
13798 HC08 Storage Class
13799 \begin_inset LatexCommand index
13800 name "HC08!Storage class"
13801
13802 \end_inset
13803
13804  Language Extensions
13805 \end_layout
13806
13807 \begin_layout Subsubsection
13808 data
13809 \begin_inset LatexCommand index
13810 name "data (hc08 storage class)"
13811
13812 \end_inset
13813
13814
13815 \begin_inset LatexCommand index
13816 name "\\_\\_data (hc08 storage class)"
13817
13818 \end_inset
13819
13820  
13821 \end_layout
13822
13823 \begin_layout Standard
13824 The data storage class declares a variable that resides in the first 256
13825  bytes of memory (the direct page).
13826  The HC08
13827 \begin_inset LatexCommand index
13828 name "HC08"
13829
13830 \end_inset
13831
13832  is most efficient at accessing variables (especially pointers) stored here.
13833 \end_layout
13834
13835 \begin_layout Subsubsection
13836 xdata
13837 \begin_inset LatexCommand index
13838 name "xdata (hc08 storage class)"
13839
13840 \end_inset
13841
13842
13843 \begin_inset LatexCommand index
13844 name "\\_\\_xdata (hc08 storage class)"
13845
13846 \end_inset
13847
13848  
13849 \end_layout
13850
13851 \begin_layout Standard
13852 The xdata storage class declares a variable that can reside anywhere in
13853  memory.
13854  This is the default if no storage class is specified.
13855  
13856 \begin_inset VSpace bigskip
13857 \end_inset
13858
13859
13860 \end_layout
13861
13862 \begin_layout Section
13863 Other SDCC language extensions
13864 \begin_inset LatexCommand index
13865 name "Other SDCC language extensions"
13866
13867 \end_inset
13868
13869
13870 \end_layout
13871
13872 \begin_layout Subsection
13873 Binary constants
13874 \end_layout
13875
13876 \begin_layout Standard
13877 SDCC supports the use of binary constants, such as 0b01100010.
13878  This feature is only enabled when the compiler is invoked using --std-sdccxx.
13879 \end_layout
13880
13881 \begin_layout Standard
13882 \begin_inset VSpace bigskip
13883 \end_inset
13884
13885
13886 \end_layout
13887
13888 \begin_layout Section
13889 Absolute Addressing
13890 \begin_inset LatexCommand index
13891 name "Absolute addressing"
13892
13893 \end_inset
13894
13895
13896 \end_layout
13897
13898 \begin_layout Standard
13899 Data items can be assigned an absolute address with the 
13900 \emph on
13901 at
13902 \begin_inset LatexCommand index
13903 name "at"
13904
13905 \end_inset
13906
13907
13908 \begin_inset LatexCommand index
13909 name "\\_\\_at"
13910
13911 \end_inset
13912
13913  <address>
13914 \emph default
13915  keyword, in addition to a storage class, e.g.:
13916 \end_layout
13917
13918 \begin_layout Verse
13919
13920 \family typewriter
13921 xdata
13922 \begin_inset LatexCommand index
13923 name "xdata (mcs51, ds390 storage class)"
13924
13925 \end_inset
13926
13927
13928 \begin_inset LatexCommand index
13929 name "\\_\\_xdata (mcs51, ds390 storage class)"
13930
13931 \end_inset
13932
13933  at
13934 \begin_inset LatexCommand index
13935 name "at"
13936
13937 \end_inset
13938
13939
13940 \begin_inset LatexCommand index
13941 name "\\_\\_at"
13942
13943 \end_inset
13944
13945  0x7ffe unsigned int chksum;
13946 \end_layout
13947
13948 \begin_layout Standard
13949 or, better conforming to ISO/IEC 9899 C:
13950 \end_layout
13951
13952 \begin_layout Verse
13953
13954 \family typewriter
13955 __xdata __at (0x7ffe) unsigned int chksum;
13956 \end_layout
13957
13958 \begin_layout Standard
13959 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13960  of the external ram.
13961  The compiler does 
13962 \emph on
13963 not
13964 \emph default
13965  reserve any space for variables declared in this way
13966 \begin_inset Marginal
13967 status collapsed
13968
13969 \begin_layout Standard
13970
13971 \series bold
13972 \InsetSpace ~
13973 !
13974 \end_layout
13975
13976 \end_inset
13977
13978  (they are implemented with an equate in the assembler).
13979  Thus it is left to the programmer to make sure there are no overlaps with
13980  other variables that are declared without the absolute address.
13981  The assembler listing file (.lst
13982 \begin_inset LatexCommand index
13983 name "<file>.lst"
13984
13985 \end_inset
13986
13987 ) and the linker output files (.rst
13988 \begin_inset LatexCommand index
13989 name "<file>.rst"
13990
13991 \end_inset
13992
13993 ) and (.map
13994 \begin_inset LatexCommand index
13995 name "<file>.map"
13996
13997 \end_inset
13998
13999 ) are good places to look for such overlaps.
14000 \end_layout
14001
14002 \begin_layout Standard
14003 If however you provide an initializer
14004 \begin_inset LatexCommand index
14005 name "Variable initialization"
14006
14007 \end_inset
14008
14009  actual memory allocation will take place and overlaps will be detected
14010  by the linker.
14011  E.g.:
14012 \end_layout
14013
14014 \begin_layout Verse
14015
14016 \family typewriter
14017 __code __at (0x7ff0) char Id[5] = 
14018 \begin_inset Quotes sld
14019 \end_inset
14020
14021 SDCC
14022 \begin_inset Quotes srd
14023 \end_inset
14024
14025 ;
14026 \end_layout
14027
14028 \begin_layout Standard
14029 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
14030  in code memory.
14031 \end_layout
14032
14033 \begin_layout Standard
14034 In case of memory mapped I/O devices the keyword 
14035 \emph on
14036 volatile
14037 \emph default
14038  has to be used to tell the compiler that accesses might not be removed:
14039 \end_layout
14040
14041 \begin_layout Verse
14042
14043 \family typewriter
14044 volatile
14045 \begin_inset LatexCommand index
14046 name "volatile"
14047
14048 \end_inset
14049
14050  __xdata
14051 \begin_inset LatexCommand index
14052 name "xdata (mcs51, ds390 storage class)"
14053
14054 \end_inset
14055
14056  __at
14057 \begin_inset LatexCommand index
14058 name "at"
14059
14060 \end_inset
14061
14062  (0x8000) unsigned char PORTA_8255;
14063 \end_layout
14064
14065 \begin_layout Standard
14066 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
14067 r) array
14068 \family typewriter
14069 \size footnotesize
14070
14071 \begin_inset LatexCommand index
14072 name "Aligned array"
14073
14074 \end_inset
14075
14076
14077 \family default
14078 \size default
14079  starts at a block (256 byte) boundary
14080 \begin_inset LatexCommand index
14081 name "block boundary"
14082
14083 \end_inset
14084
14085  (section 
14086 \begin_inset LatexCommand ref
14087 reference "sub:A-Step-by Assembler Introduction"
14088
14089 \end_inset
14090
14091  has an example).
14092 \newline
14093 Absolute addresses can be specified for variables in all
14094  storage classes, e.g.:
14095 \end_layout
14096
14097 \begin_layout Verse
14098
14099 \family typewriter
14100 __bit
14101 \begin_inset LatexCommand index
14102 name "bit"
14103
14104 \end_inset
14105
14106  __at
14107 \begin_inset LatexCommand index
14108 name "at"
14109
14110 \end_inset
14111
14112  (0x02) bvar;
14113 \end_layout
14114
14115 \begin_layout Standard
14116 The above example will allocate the variable at offset 0x02 in the bit-addressab
14117 le space.
14118  There is no real advantage to assigning absolute addresses to variables
14119  in this manner, unless you want strict control over all the variables allocated.
14120  One possible use would be to write hardware portable code.
14121  For example, if you have a routine that uses one or more of the microcontroller
14122  I/O pins, and such pins are different for two different hardwares, you
14123  can declare the I/O pins in your routine using:
14124 \end_layout
14125
14126 \begin_layout Verse
14127
14128 \family typewriter
14129 extern volatile
14130 \begin_inset LatexCommand index
14131 name "volatile"
14132
14133 \end_inset
14134
14135  __bit MOSI;\InsetSpace ~
14136 \InsetSpace ~
14137 \InsetSpace ~
14138 \InsetSpace ~
14139 /* master out, slave in */
14140 \newline
14141 extern volatile __bit MISO;\InsetSpace ~
14142 \InsetSpace ~
14143 \InsetSpace ~
14144 \InsetSpace ~
14145 /* master
14146  in, slave out */
14147 \newline
14148 extern volatile __bit MCLK;\InsetSpace ~
14149 \InsetSpace ~
14150 \InsetSpace ~
14151 \InsetSpace ~
14152 /* master clock */
14153 \newline
14154
14155 \newline
14156 /* Input and
14157  Output of a byte on a 3-wire serial bus.
14158 \newline
14159 \InsetSpace ~
14160 \InsetSpace ~
14161 \InsetSpace ~
14162 If needed adapt polarity of clock,
14163  polarity of data and bit order
14164 \newline
14165 \InsetSpace ~
14166 */
14167 \newline
14168 unsigned char spi_io(unsigned char out_byte)
14169  
14170 \newline
14171
14172 \newline
14173 \InsetSpace ~
14174 \InsetSpace ~
14175 \InsetSpace ~
14176 \InsetSpace ~
14177 unsigned char i=8;
14178 \newline
14179 \InsetSpace ~
14180 \InsetSpace ~
14181 \InsetSpace ~
14182 \InsetSpace ~
14183 do { 
14184 \newline
14185 \InsetSpace ~
14186 \InsetSpace ~
14187 \InsetSpace ~
14188 \InsetSpace ~
14189 \InsetSpace ~
14190 \InsetSpace ~
14191 \InsetSpace ~
14192 \InsetSpace ~
14193 MOSI = out_byte & 0x80; 
14194 \newline
14195 \InsetSpace ~
14196 \InsetSpace ~
14197 \InsetSpace ~
14198 \InsetSpace ~
14199 \InsetSpace ~
14200 \InsetSpace ~
14201 \InsetSpace ~
14202 \InsetSpace ~
14203 out_byte <<= 1;
14204 \newline
14205 \InsetSpace ~
14206 \InsetSpace ~
14207 \InsetSpace ~
14208 \InsetSpace ~
14209 \InsetSpace ~
14210 \InsetSpace ~
14211 \InsetSpace ~
14212 \InsetSpace ~
14213 MCLK =
14214  1; 
14215 \newline
14216 \InsetSpace ~
14217 \InsetSpace ~
14218 \InsetSpace ~
14219 \InsetSpace ~
14220 \InsetSpace ~
14221 \InsetSpace ~
14222 \InsetSpace ~
14223 \InsetSpace ~
14224 /* _asm nop _endasm; */\InsetSpace ~
14225 \InsetSpace ~
14226 \InsetSpace ~
14227 \InsetSpace ~
14228 \InsetSpace ~
14229 \InsetSpace ~
14230 \InsetSpace ~
14231 \InsetSpace ~
14232 /* for slow peripherals */
14233 \newline
14234 \InsetSpace ~
14235 \InsetSpace ~
14236 \InsetSpace ~
14237 \InsetSpace ~
14238 \InsetSpace ~
14239 \InsetSpace ~
14240 \InsetSpace ~
14241 \InsetSpace ~
14242 if(MISO) 
14243 \newline
14244 \InsetSpace ~
14245 \InsetSpace ~
14246 \InsetSpace ~
14247 \InsetSpace ~
14248 \InsetSpace ~
14249 \InsetSpace ~
14250 \InsetSpace ~
14251 \InsetSpace ~
14252 \InsetSpace ~
14253 \InsetSpace ~
14254 \InsetSpace ~
14255 \InsetSpace ~
14256 out_byte +=
14257  1; 
14258 \newline
14259 \InsetSpace ~
14260 \InsetSpace ~
14261 \InsetSpace ~
14262 \InsetSpace ~
14263 \InsetSpace ~
14264 \InsetSpace ~
14265 \InsetSpace ~
14266 \InsetSpace ~
14267 MCLK = 0; 
14268 \newline
14269 \InsetSpace ~
14270 \InsetSpace ~
14271 \InsetSpace ~
14272 \InsetSpace ~
14273 } while(--i);
14274 \newline
14275 \InsetSpace ~
14276 \InsetSpace ~
14277 \InsetSpace ~
14278 \InsetSpace ~
14279 return out_byte; 
14280 \newline
14281 }
14282 \end_layout
14283
14284 \begin_layout Standard
14285 Then, someplace in the code for the first hardware you would use
14286 \end_layout
14287
14288 \begin_layout Verse
14289
14290 \family typewriter
14291 __bit __at
14292 \begin_inset LatexCommand index
14293 name "at"
14294
14295 \end_inset
14296
14297
14298 \begin_inset LatexCommand index
14299 name "\\_\\_at"
14300
14301 \end_inset
14302
14303  (0x80) MOSI;\InsetSpace ~
14304 \InsetSpace ~
14305 \InsetSpace ~
14306 \InsetSpace ~
14307 /* I/O port 0, bit 0 */
14308 \newline
14309 __bit __at (0x81) MISO;\InsetSpace ~
14310 \InsetSpace ~
14311 \InsetSpace ~
14312 \InsetSpace ~
14313 /* I/O port 0,
14314  bit 1 */
14315 \newline
14316 __bit __at (0x82) MCLK;\InsetSpace ~
14317 \InsetSpace ~
14318 \InsetSpace ~
14319 \InsetSpace ~
14320 /* I/O port 0, bit 2 */
14321 \end_layout
14322
14323 \begin_layout Standard
14324 Similarly, for the second hardware you would use
14325 \end_layout
14326
14327 \begin_layout Verse
14328
14329 \family typewriter
14330 __bit __at (0x83) MOSI;\InsetSpace ~
14331 \InsetSpace ~
14332 \InsetSpace ~
14333 \InsetSpace ~
14334 /* I/O port 0, bit 3 */
14335 \newline
14336 __bit __at (0x91) MISO;\InsetSpace ~
14337 \InsetSpace ~
14338 \InsetSpace ~
14339 \InsetSpace ~
14340 /*
14341  I/O port 1, bit 1 */
14342 \newline
14343 __bit
14344 \begin_inset LatexCommand index
14345 name "bit"
14346
14347 \end_inset
14348
14349  __at (0x92) MCLK;\InsetSpace ~
14350 \InsetSpace ~
14351 \InsetSpace ~
14352 \InsetSpace ~
14353 /* I/O port 1, bit 2 */
14354 \end_layout
14355
14356 \begin_layout Standard
14357 and you can use the same hardware dependent routine without changes, as
14358  for example in a library.
14359  This is somehow similar to sbit, but only one absolute address has to be
14360  specified in the whole project.
14361 \begin_inset VSpace bigskip
14362 \end_inset
14363
14364
14365 \end_layout
14366
14367 \begin_layout Section
14368 Parameters
14369 \begin_inset LatexCommand index
14370 name "Parameters"
14371
14372 \end_inset
14373
14374
14375 \begin_inset LatexCommand index
14376 name "function parameter"
14377
14378 \end_inset
14379
14380  & Local Variables
14381 \begin_inset LatexCommand index
14382 name "local variables"
14383
14384 \end_inset
14385
14386
14387 \begin_inset LatexCommand label
14388 name "sec:Parameters-and-Local-Variables"
14389
14390 \end_inset
14391
14392
14393 \end_layout
14394
14395 \begin_layout Standard
14396 Automatic (local) variables and parameters to functions can either be placed
14397  on the stack or in data-space.
14398  The default action of the compiler is to place these variables in the internal
14399  RAM (for small model) or external RAM (for medium or large model).
14400  This in fact makes them similar to 
14401 \emph on
14402 static
14403 \begin_inset LatexCommand index
14404 name "static"
14405
14406 \end_inset
14407
14408
14409 \emph default
14410  so by default functions are non-reentrant
14411 \begin_inset LatexCommand index
14412 name "reentrant"
14413
14414 \end_inset
14415
14416 .
14417  
14418 \newline
14419
14420 \newline
14421 They can be placed on the stack
14422 \begin_inset LatexCommand index
14423 name "stack"
14424
14425 \end_inset
14426
14427  by using the 
14428 \emph on
14429 -
14430 \begin_inset ERT
14431 status collapsed
14432
14433 \begin_layout Standard
14434
14435
14436 \backslash
14437 /
14438 \end_layout
14439
14440 \end_inset
14441
14442 -stack-auto
14443 \begin_inset LatexCommand index
14444 name "-\\/-stack-auto"
14445
14446 \end_inset
14447
14448
14449 \emph default
14450  option, by using 
14451 \emph on
14452 #pragma\InsetSpace ~
14453 stackauto
14454 \emph default
14455
14456 \begin_inset LatexCommand index
14457 name "\\#pragma stackauto"
14458
14459 \end_inset
14460
14461  or by using the 
14462 \emph on
14463 reentrant
14464 \begin_inset LatexCommand index
14465 name "reentrant"
14466
14467 \end_inset
14468
14469
14470 \emph default
14471  keyword in the function declaration, e.g.:
14472 \end_layout
14473
14474 \begin_layout Verse
14475
14476 \family typewriter
14477 unsigned char foo(char i) __reentrant 
14478 \newline
14479
14480 \newline
14481 \InsetSpace ~
14482 \InsetSpace ~
14483 \InsetSpace ~
14484 \InsetSpace ~
14485 ...
14486  
14487 \newline
14488 }
14489 \end_layout
14490
14491 \begin_layout Standard
14492 Since stack space on 8051 is limited, the 
14493 \emph on
14494 reentrant
14495 \emph default
14496  keyword or the 
14497 \emph on
14498 -
14499 \begin_inset ERT
14500 status collapsed
14501
14502 \begin_layout Standard
14503
14504
14505 \backslash
14506 /
14507 \end_layout
14508
14509 \end_inset
14510
14511 -stack-auto
14512 \emph default
14513  option should be used sparingly.
14514  Note that the reentrant keyword just means that the parameters & local
14515  variables will be allocated to the stack, it 
14516 \emph on
14517 does not
14518 \emph default
14519  mean that the function is register bank
14520 \begin_inset LatexCommand index
14521 name "register bank (mcs51, ds390)"
14522
14523 \end_inset
14524
14525  independent.
14526 \newline
14527
14528 \newline
14529 Local variables
14530 \begin_inset LatexCommand index
14531 name "local variables"
14532
14533 \end_inset
14534
14535  can be assigned storage classes and absolute
14536 \begin_inset LatexCommand index
14537 name "Absolute addressing"
14538
14539 \end_inset
14540
14541  addresses, e.g.: 
14542 \end_layout
14543
14544 \begin_layout Verse
14545
14546 \family typewriter
14547 unsigned char foo() 
14548 \newline
14549 {
14550 \newline
14551 \InsetSpace ~
14552 \InsetSpace ~
14553 \InsetSpace ~
14554 \InsetSpace ~
14555 __xdata unsigned char i;
14556 \newline
14557 \InsetSpace ~
14558 \InsetSpace ~
14559 \InsetSpace ~
14560 \InsetSpace ~
14561 __bit bvar;
14562 \newline
14563 \InsetSpace ~
14564 \InsetSpace ~
14565 \InsetSpace ~
14566 \InsetSpace ~
14567 __data __at
14568 \begin_inset LatexCommand index
14569 name "at"
14570
14571 \end_inset
14572
14573  (0x31) unsigned char j;
14574 \newline
14575 \InsetSpace ~
14576 \InsetSpace ~
14577 \InsetSpace ~
14578 \InsetSpace ~
14579 ...
14580  
14581 \newline
14582 }
14583 \end_layout
14584
14585 \begin_layout Standard
14586 In the above example the variable 
14587 \emph on
14588 i
14589 \emph default
14590  will be allocated in the external ram, 
14591 \emph on
14592 bvar
14593 \emph default
14594  in bit addressable space and 
14595 \emph on
14596 j
14597 \emph default
14598  in internal ram.
14599  When compiled with 
14600 \emph on
14601 -
14602 \begin_inset ERT
14603 status collapsed
14604
14605 \begin_layout Standard
14606
14607
14608 \backslash
14609 /
14610 \end_layout
14611
14612 \end_inset
14613
14614 -stack-auto
14615 \emph default
14616  or when a function is declared as 
14617 \emph on
14618 reentrant
14619 \emph default
14620  this should only be done for static variables.
14621 \end_layout
14622
14623 \begin_layout Standard
14624 Parameters
14625 \begin_inset LatexCommand index
14626 name "function parameter"
14627
14628 \end_inset
14629
14630  however are not allowed any storage class
14631 \begin_inset LatexCommand index
14632 name "Storage class"
14633
14634 \end_inset
14635
14636 , (storage classes for parameters will be ignored), their allocation is
14637  governed by the memory model in use, and the reentrancy options.
14638 \end_layout
14639
14640 \begin_layout Standard
14641 It is however allowed to use bit parameters in reentrant functions and also
14642  non-static local bit variables are supported.
14643  Efficient use is limited to 8 semi-bitregisters in bit space.
14644  They are pushed and popped to stack
14645 \begin_inset LatexCommand index
14646 name "stack"
14647
14648 \end_inset
14649
14650  as a single byte just like the normal registers.
14651 \end_layout
14652
14653 \begin_layout Section
14654 Overlaying
14655 \begin_inset LatexCommand label
14656 name "sub:Overlaying"
14657
14658 \end_inset
14659
14660
14661 \begin_inset LatexCommand index
14662 name "Overlaying"
14663
14664 \end_inset
14665
14666
14667 \end_layout
14668
14669 \begin_layout Standard
14670 For non-reentrant
14671 \begin_inset LatexCommand index
14672 name "reentrant"
14673
14674 \end_inset
14675
14676  functions SDCC will try to reduce internal ram space usage by overlaying
14677  parameters and local variables of a function (if possible).
14678  Parameters and local variables
14679 \begin_inset LatexCommand index
14680 name "local variables"
14681
14682 \end_inset
14683
14684  of a function will be allocated to an overlayable segment if the function
14685  has 
14686 \emph on
14687 no other function calls and the function is non-reentrant and the memory
14688  model
14689 \begin_inset LatexCommand index
14690 name "Memory model"
14691
14692 \end_inset
14693
14694  is small.
14695
14696 \emph default
14697  If an explicit storage class
14698 \begin_inset LatexCommand index
14699 name "Storage class"
14700
14701 \end_inset
14702
14703  is specified for a local variable, it will NOT be overlaid.
14704 \end_layout
14705
14706 \begin_layout Standard
14707 Note that the compiler (not the linkage editor) makes the decision for overlayin
14708 g the data items.
14709  Functions that are called from an interrupt service routine
14710 \begin_inset Marginal
14711 status collapsed
14712
14713 \begin_layout Standard
14714
14715 \series bold
14716 !
14717 \end_layout
14718
14719 \end_inset
14720
14721  should be preceded by a #pragma\InsetSpace ~
14722 nooverlay
14723 \begin_inset LatexCommand index
14724 name "\\#pragma nooverlay"
14725
14726 \end_inset
14727
14728  if they are not reentrant.
14729 \end_layout
14730
14731 \begin_layout Standard
14732 Also note that the compiler does not do any processing of inline assembler
14733  code, so the compiler might incorrectly assign local variables and parameters
14734  of a function into the overlay segment if the inline assembler code calls
14735  other c-functions that might use the overlay.
14736  In that case the #pragma\InsetSpace ~
14737 nooverlay should be used.
14738 \end_layout
14739
14740 \begin_layout Standard
14741 Parameters and local variables of functions that contain 16 or 32 bit multiplica
14742 tion
14743 \begin_inset LatexCommand index
14744 name "Multiplication"
14745
14746 \end_inset
14747
14748  or division
14749 \begin_inset LatexCommand index
14750 name "Division"
14751
14752 \end_inset
14753
14754  will NOT be overlaid since these are implemented using external functions,
14755  e.g.:
14756 \end_layout
14757
14758 \begin_layout Verse
14759
14760 \family typewriter
14761 #pragma save 
14762 \newline
14763 #pragma nooverlay
14764 \begin_inset LatexCommand index
14765 name "\\#pragma nooverlay"
14766
14767 \end_inset
14768
14769  
14770 \newline
14771 void set_error(unsigned char errcd) 
14772 \newline
14773 {
14774 \newline
14775 \InsetSpace ~
14776 \InsetSpace ~
14777 \InsetSpace ~
14778 \InsetSpace ~
14779 P3 = errcd;
14780 \newline
14781
14782 \newline
14783 #pragma restore 
14784 \newline
14785
14786 \newline
14787 void
14788  some_isr () __interrupt
14789 \begin_inset LatexCommand index
14790 name "interrupt"
14791
14792 \end_inset
14793
14794  (2)
14795 \newline
14796 {
14797 \newline
14798 \InsetSpace ~
14799 \InsetSpace ~
14800 \InsetSpace ~
14801 \InsetSpace ~
14802 ...
14803 \newline
14804 \InsetSpace ~
14805 \InsetSpace ~
14806 \InsetSpace ~
14807 \InsetSpace ~
14808 set_error(10);
14809 \newline
14810 \InsetSpace ~
14811 \InsetSpace ~
14812 \InsetSpace ~
14813 \InsetSpace ~
14814 ...
14815  
14816 \newline
14817 }
14818 \end_layout
14819
14820 \begin_layout Standard
14821 In the above example the parameter 
14822 \emph on
14823 errcd
14824 \emph default
14825  for the function 
14826 \emph on
14827 set_error
14828 \emph default
14829  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14830 nooverlay was
14831  not present, this could cause unpredictable runtime behavior when called
14832  from an interrupt service routine.
14833  The #pragma\InsetSpace ~
14834 nooverlay ensures that the parameters and local variables for
14835  the function are NOT overlaid.
14836 \begin_inset VSpace bigskip
14837 \end_inset
14838
14839
14840 \end_layout
14841
14842 \begin_layout Section
14843 Interrupt Service Routines
14844 \begin_inset LatexCommand label
14845 name "sub:Interrupt-Service-Routines"
14846
14847 \end_inset
14848
14849
14850 \end_layout
14851
14852 \begin_layout Subsection
14853 General Information
14854 \end_layout
14855
14856 \begin_layout Standard
14857 SDCC allows 
14858 \emph on
14859 i
14860 \emph default
14861 nterrupt 
14862 \emph on
14863 s
14864 \emph default
14865 ervice 
14866 \emph on
14867 r
14868 \emph default
14869 outines to be coded in C, with some extended keywords.
14870 \end_layout
14871
14872 \begin_layout Verse
14873
14874 \family typewriter
14875 void timer_isr (void) __interrupt (1) __using (1) 
14876 \newline
14877
14878 \newline
14879 \InsetSpace ~
14880 \InsetSpace ~
14881 \InsetSpace ~
14882 \InsetSpace ~
14883 ...
14884  
14885 \newline
14886 }
14887 \end_layout
14888
14889 \begin_layout Standard
14890 The optional number following the 
14891 \emph on
14892 interrupt
14893 \begin_inset LatexCommand index
14894 name "interrupt"
14895
14896 \end_inset
14897
14898
14899 \begin_inset LatexCommand index
14900 name "\\_\\_interrupt"
14901
14902 \end_inset
14903
14904
14905 \emph default
14906  keyword is the interrupt number this routine will service.
14907  When present, the compiler will insert a call to this routine in the interrupt
14908  vector table
14909 \begin_inset LatexCommand index
14910 name "interrupt vector table"
14911
14912 \end_inset
14913
14914  for the interrupt number specified.
14915  If you have multiple source files in your project, interrupt service routines
14916  can be present in any of them, but a prototype of the isr MUST be present
14917  or included in the file that contains the function 
14918 \emph on
14919 main
14920 \emph default
14921 .
14922  The optional (8051 specific) keyword 
14923 \emph on
14924 using
14925 \begin_inset LatexCommand index
14926 name "using (mcs51, ds390 register bank)"
14927
14928 \end_inset
14929
14930
14931 \begin_inset LatexCommand index
14932 name "\\_\\_using (mcs51, ds390 register bank)"
14933
14934 \end_inset
14935
14936
14937 \emph default
14938  can be used to tell the compiler to use the specified register bank when
14939  generating code for this function.
14940  
14941 \newline
14942 Interrupt service routines open the door for some very interesting bugs:
14943 \end_layout
14944
14945 \begin_layout Subsubsection
14946 \begin_inset LatexCommand label
14947 name "sub:Common-interrupt-pitfall-volatile"
14948
14949 \end_inset
14950
14951 Common interrupt pitfall: variable not declared 
14952 \emph on
14953 volatile
14954 \end_layout
14955
14956 \begin_layout Standard
14957 If an interrupt service routine changes variables which are accessed by
14958  other functions these variables have to be declared 
14959 \emph on
14960 volatile
14961 \emph default
14962
14963 \begin_inset LatexCommand index
14964 name "volatile"
14965
14966 \end_inset
14967
14968 .
14969  See 
14970 \begin_inset LatexCommand url
14971 target "http://en.wikipedia.org/wiki/Volatile_variable"
14972
14973 \end_inset
14974
14975  .
14976 \end_layout
14977
14978 \begin_layout Subsubsection
14979 \begin_inset LatexCommand label
14980 name "sub:Common-interrupt-pitfall-non-atomic"
14981
14982 \end_inset
14983
14984 Common interrupt pitfall: 
14985 \emph on
14986 non-atomic access
14987 \end_layout
14988
14989 \begin_layout Standard
14990 If the access to these variables is not 
14991 \emph on
14992 atomic
14993 \begin_inset LatexCommand index
14994 name "atomic"
14995
14996 \end_inset
14997
14998
14999 \emph default
15000  (i.e.
15001  the processor needs more than one instruction for the access and could
15002  be interrupted while accessing the variable) the interrupt must be disabled
15003  during the access to avoid inconsistent data.
15004  
15005 \newline
15006 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
15007  and should be protected by disabling interrupts.
15008  You're not automatically on the safe side if you use 8 bit variables though.
15009  We need an example here: f.e.
15010  on the 8051 the harmless looking 
15011 \begin_inset Quotes srd
15012 \end_inset
15013
15014
15015 \family typewriter
15016 flags\InsetSpace ~
15017 |=\InsetSpace ~
15018 0x80;
15019 \family default
15020
15021 \begin_inset Quotes sld
15022 \end_inset
15023
15024  is not atomic if 
15025 \family typewriter
15026 flags
15027 \family default
15028  resides in xdata.
15029  Setting 
15030 \begin_inset Quotes srd
15031 \end_inset
15032
15033
15034 \family typewriter
15035 flags\InsetSpace ~
15036 |=\InsetSpace ~
15037 0x40;
15038 \family default
15039
15040 \begin_inset Quotes sld
15041 \end_inset
15042
15043  from within an interrupt routine might get lost if the interrupt occurs
15044  at the wrong time.
15045  
15046 \begin_inset Quotes sld
15047 \end_inset
15048
15049
15050 \family typewriter
15051 counter\InsetSpace ~
15052 +=\InsetSpace ~
15053 8;
15054 \family default
15055
15056 \begin_inset Quotes srd
15057 \end_inset
15058
15059  is not atomic on the 8051 even if 
15060 \family typewriter
15061 counter
15062 \family default
15063  is located in data memory.
15064 \newline
15065 Bugs like these are hard to reproduce and can
15066  cause a lot of trouble.
15067  
15068 \end_layout
15069
15070 \begin_layout Subsubsection
15071 \begin_inset LatexCommand label
15072 name "sub:Common-interrupt-pitfall-stack-overflow"
15073
15074 \end_inset
15075
15076 Common interrupt pitfall: 
15077 \emph on
15078 stack overflow
15079 \end_layout
15080
15081 \begin_layout Standard
15082 The return address and the registers used in the interrupt service routine
15083  are saved on the stack
15084 \begin_inset LatexCommand index
15085 name "stack"
15086
15087 \end_inset
15088
15089  so there must be sufficient stack space.
15090  If there isn't variables or registers (or even the return address itself)
15091  will be corrupted.
15092  This 
15093 \emph on
15094 stack overflow
15095 \emph default
15096
15097 \begin_inset LatexCommand index
15098 name "stack overflow"
15099
15100 \end_inset
15101
15102  is most likely to happen if the interrupt occurs during the 
15103 \begin_inset Quotes sld
15104 \end_inset
15105
15106 deepest
15107 \begin_inset Quotes srd
15108 \end_inset
15109
15110  subroutine when the stack is already in use for f.e.
15111  many return addresses.
15112 \end_layout
15113
15114 \begin_layout Subsubsection
15115 \begin_inset LatexCommand label
15116 name "sub:Common-interrupt-pitfall-non-reentrant"
15117
15118 \end_inset
15119
15120 Common interrupt pitfall: 
15121 \emph on
15122 use of non-reentrant functions
15123 \end_layout
15124
15125 \begin_layout Standard
15126 A special note here, int (16 bit) and long (32 bit) integer division
15127 \begin_inset LatexCommand index
15128 name "Division"
15129
15130 \end_inset
15131
15132 , multiplication
15133 \begin_inset LatexCommand index
15134 name "Multiplication"
15135
15136 \end_inset
15137
15138  & modulus
15139 \begin_inset LatexCommand index
15140 name "Modulus"
15141
15142 \end_inset
15143
15144  and floating-point
15145 \begin_inset LatexCommand index
15146 name "Floating point support"
15147
15148 \end_inset
15149
15150  operations are implemented using external support routines.
15151  If an interrupt service routine needs to do any of these operations then
15152  the support routines (as mentioned in a following section) will have to
15153  be recompiled using the 
15154 \emph on
15155 -
15156 \begin_inset ERT
15157 status collapsed
15158
15159 \begin_layout Standard
15160
15161
15162 \backslash
15163 /
15164 \end_layout
15165
15166 \end_inset
15167
15168 -stack-auto
15169 \begin_inset LatexCommand index
15170 name "-\\/-stack-auto"
15171
15172 \end_inset
15173
15174
15175 \emph default
15176  option and the source file will need to be compiled using the 
15177 \emph on
15178 -
15179 \begin_inset ERT
15180 status collapsed
15181
15182 \begin_layout Standard
15183
15184
15185 \backslash
15186 /
15187 \end_layout
15188
15189 \end_inset
15190
15191 -int-long-reent
15192 \emph default
15193
15194 \begin_inset LatexCommand index
15195 name "-\\/-int-long-reent"
15196
15197 \end_inset
15198
15199  compiler option.
15200  
15201 \newline
15202 Note, the type promotion
15203 \begin_inset LatexCommand index
15204 name "type promotion"
15205
15206 \end_inset
15207
15208  required by ANSI C can cause 16 bit routines to be used
15209 \begin_inset Marginal
15210 status collapsed
15211
15212 \begin_layout Standard
15213
15214 \series bold
15215 \InsetSpace ~
15216 !
15217 \end_layout
15218
15219 \end_inset
15220
15221  without the programmer being aware of it.
15222  See f.e.
15223  the cast 
15224 \family typewriter
15225 \series bold
15226 (unsigned char)(tail-1)
15227 \family default
15228 \series default
15229  
15230 \series bold
15231 within the if clause in section 
15232 \begin_inset LatexCommand ref
15233 reference "sub:A-Step-by Assembler Introduction"
15234
15235 \end_inset
15236
15237 .
15238 \end_layout
15239
15240 \begin_layout Standard
15241 Calling other functions from an interrupt service routine is not recommended,
15242  avoid it if possible.
15243  Note that when some function is called from an interrupt service routine
15244  it should be preceded by a #pragma\InsetSpace ~
15245 nooverlay
15246 \begin_inset LatexCommand index
15247 name "\\#pragma nooverlay"
15248
15249 \end_inset
15250
15251  if it is not reentrant.
15252  Furthermore nonreentrant functions should not be called from the main program
15253  while the interrupt service routine might be active.
15254  They also must not be called from low priority interrupt service routines
15255  while a high priority interrupt service routine might be active.
15256  You could use semaphores or make the function 
15257 \emph on
15258 critical
15259 \emph default
15260  if all parameters are passed in registers.
15261 \newline
15262  Also see section 
15263 \begin_inset LatexCommand ref
15264 reference "sub:Overlaying"
15265
15266 \end_inset
15267
15268 \InsetSpace ~
15269 about Overlaying and section 
15270 \begin_inset LatexCommand ref
15271 reference "sub:Functions-using-private-banks"
15272
15273 \end_inset
15274
15275 \InsetSpace ~
15276 about Functions using private register banks.
15277 \begin_inset VSpace bigskip
15278 \end_inset
15279
15280
15281 \end_layout
15282
15283 \begin_layout Subsection
15284 MCS51/DS390 Interrupt Service Routines
15285 \end_layout
15286
15287 \begin_layout Standard
15288 Interrupt
15289 \begin_inset LatexCommand index
15290 name "interrupt"
15291
15292 \end_inset
15293
15294  numbers and the corresponding address & descriptions for the Standard 8051/8052
15295  are listed below.
15296  SDCC will automatically adjust the 
15297 \begin_inset LatexCommand index
15298 name "interrupt vector table"
15299
15300 \end_inset
15301
15302  to the maximum interrupt number specified.
15303 \newline
15304
15305 \end_layout
15306
15307 \begin_layout Standard
15308 \align center
15309 \begin_inset Tabular
15310 <lyxtabular version="3" rows="9" columns="3">
15311 <features>
15312 <column alignment="center" valignment="top" leftline="true" width="0in">
15313 <column alignment="left" valignment="top" leftline="true" width="0in">
15314 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
15315 <row topline="true" bottomline="true">
15316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15317 \begin_inset Text
15318
15319 \begin_layout Standard
15320 Interrupt #
15321 \end_layout
15322
15323 \end_inset
15324 </cell>
15325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15326 \begin_inset Text
15327
15328 \begin_layout Standard
15329 Description
15330 \end_layout
15331
15332 \end_inset
15333 </cell>
15334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15335 \begin_inset Text
15336
15337 \begin_layout Standard
15338 Vector Address
15339 \end_layout
15340
15341 \end_inset
15342 </cell>
15343 </row>
15344 <row topline="true">
15345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15346 \begin_inset Text
15347
15348 \begin_layout Standard
15349 0
15350 \end_layout
15351
15352 \end_inset
15353 </cell>
15354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15355 \begin_inset Text
15356
15357 \begin_layout Standard
15358 External 0
15359 \end_layout
15360
15361 \end_inset
15362 </cell>
15363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15364 \begin_inset Text
15365
15366 \begin_layout Standard
15367 0x0003
15368 \end_layout
15369
15370 \end_inset
15371 </cell>
15372 </row>
15373 <row topline="true">
15374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15375 \begin_inset Text
15376
15377 \begin_layout Standard
15378 1
15379 \end_layout
15380
15381 \end_inset
15382 </cell>
15383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15384 \begin_inset Text
15385
15386 \begin_layout Standard
15387 Timer 0
15388 \end_layout
15389
15390 \end_inset
15391 </cell>
15392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15393 \begin_inset Text
15394
15395 \begin_layout Standard
15396 0x000b
15397 \end_layout
15398
15399 \end_inset
15400 </cell>
15401 </row>
15402 <row topline="true">
15403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15404 \begin_inset Text
15405
15406 \begin_layout Standard
15407 2
15408 \end_layout
15409
15410 \end_inset
15411 </cell>
15412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15413 \begin_inset Text
15414
15415 \begin_layout Standard
15416 External 1
15417 \end_layout
15418
15419 \end_inset
15420 </cell>
15421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15422 \begin_inset Text
15423
15424 \begin_layout Standard
15425 0x0013
15426 \end_layout
15427
15428 \end_inset
15429 </cell>
15430 </row>
15431 <row topline="true">
15432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15433 \begin_inset Text
15434
15435 \begin_layout Standard
15436 3
15437 \end_layout
15438
15439 \end_inset
15440 </cell>
15441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15442 \begin_inset Text
15443
15444 \begin_layout Standard
15445 Timer 1
15446 \end_layout
15447
15448 \end_inset
15449 </cell>
15450 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15451 \begin_inset Text
15452
15453 \begin_layout Standard
15454 0x001b
15455 \end_layout
15456
15457 \end_inset
15458 </cell>
15459 </row>
15460 <row topline="true">
15461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15462 \begin_inset Text
15463
15464 \begin_layout Standard
15465 4
15466 \end_layout
15467
15468 \end_inset
15469 </cell>
15470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15471 \begin_inset Text
15472
15473 \begin_layout Standard
15474 Serial
15475 \end_layout
15476
15477 \end_inset
15478 </cell>
15479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15480 \begin_inset Text
15481
15482 \begin_layout Standard
15483 0x0023
15484 \end_layout
15485
15486 \end_inset
15487 </cell>
15488 </row>
15489 <row topline="true">
15490 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15491 \begin_inset Text
15492
15493 \begin_layout Standard
15494 5
15495 \end_layout
15496
15497 \end_inset
15498 </cell>
15499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15500 \begin_inset Text
15501
15502 \begin_layout Standard
15503 Timer 2 (8052)
15504 \end_layout
15505
15506 \end_inset
15507 </cell>
15508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15509 \begin_inset Text
15510
15511 \begin_layout Standard
15512 0x002b
15513 \end_layout
15514
15515 \end_inset
15516 </cell>
15517 </row>
15518 <row topline="true">
15519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15520 \begin_inset Text
15521
15522 \begin_layout Standard
15523 ...
15524 \end_layout
15525
15526 \end_inset
15527 </cell>
15528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15529 \begin_inset Text
15530
15531 \begin_layout Standard
15532
15533 \end_layout
15534
15535 \end_inset
15536 </cell>
15537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15538 \begin_inset Text
15539
15540 \begin_layout Standard
15541 ...
15542 \end_layout
15543
15544 \end_inset
15545 </cell>
15546 </row>
15547 <row topline="true" bottomline="true">
15548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15549 \begin_inset Text
15550
15551 \begin_layout Standard
15552 n
15553 \end_layout
15554
15555 \end_inset
15556 </cell>
15557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15558 \begin_inset Text
15559
15560 \begin_layout Standard
15561
15562 \end_layout
15563
15564 \end_inset
15565 </cell>
15566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15567 \begin_inset Text
15568
15569 \begin_layout Standard
15570 0x0003 + 8*n
15571 \end_layout
15572
15573 \end_inset
15574 </cell>
15575 </row>
15576 </lyxtabular>
15577
15578 \end_inset
15579
15580
15581 \newline
15582
15583 \end_layout
15584
15585 \begin_layout Standard
15586 If the interrupt service routine is defined without 
15587 \emph on
15588 using
15589 \begin_inset LatexCommand index
15590 name "using (mcs51, ds390 register bank)"
15591
15592 \end_inset
15593
15594
15595 \begin_inset LatexCommand index
15596 name "\\_\\_using (mcs51, ds390 register bank)"
15597
15598 \end_inset
15599
15600
15601 \emph default
15602  a register bank or with register bank 0 (
15603 \emph on
15604 using
15605 \emph default
15606  0), the compiler will save the registers used by itself on the stack upon
15607  entry and restore them at exit, however if such an interrupt service routine
15608  calls another function then the entire register bank will be saved on the
15609  stack.
15610  This scheme may be advantageous for small interrupt service routines which
15611  have low register usage.
15612 \end_layout
15613
15614 \begin_layout Standard
15615 If the interrupt service routine is defined to be using a specific register
15616  bank then only 
15617 \emph on
15618 a, b, dptr
15619 \emph default
15620  & psw are saved and restored, if such an interrupt service routine calls
15621  another function (using another register bank) then the entire register
15622  bank of the called function will be saved on the stack
15623 \begin_inset LatexCommand index
15624 name "stack"
15625
15626 \end_inset
15627
15628 .
15629  This scheme is recommended for larger interrupt service routines.
15630 \begin_inset VSpace bigskip
15631 \end_inset
15632
15633
15634 \end_layout
15635
15636 \begin_layout Subsection
15637 HC08
15638 \begin_inset LatexCommand index
15639 name "HC08"
15640
15641 \end_inset
15642
15643  Interrupt Service Routines
15644 \end_layout
15645
15646 \begin_layout Standard
15647 Since the number of interrupts
15648 \begin_inset LatexCommand index
15649 name "HC08!interrupt"
15650
15651 \end_inset
15652
15653  available is chip specific and the interrupt vector table always ends at
15654  the last byte of memory, the interrupt numbers corresponds to the interrupt
15655  vectors in reverse order of address.
15656  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
15657  2 will use the interrupt vector at 0xfffa, and so on.
15658  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
15659  this way; instead see section 
15660 \begin_inset LatexCommand ref
15661 reference "sub:Startup-Code"
15662
15663 \end_inset
15664
15665  for details on customizing startup.
15666 \begin_inset VSpace bigskip
15667 \end_inset
15668
15669
15670 \end_layout
15671
15672 \begin_layout Subsection
15673 Z80 Interrupt Service Routines
15674 \end_layout
15675
15676 \begin_layout Standard
15677 The Z80
15678 \begin_inset LatexCommand index
15679 name "Z80"
15680
15681 \end_inset
15682
15683  uses several different methods for determining the correct interrupt
15684 \begin_inset LatexCommand index
15685 name "Z80!interrupt"
15686
15687 \end_inset
15688
15689  vector depending on the hardware implementation.
15690  Therefore, SDCC ignores the optional interrupt number and does not attempt
15691  to generate an interrupt vector table.
15692 \end_layout
15693
15694 \begin_layout Standard
15695 By default, SDCC generates code for a maskable interrupt, which uses a RETI
15696  instruction to return from the interrupt.
15697  To write an interrupt handler for the non-maskable interrupt, which needs
15698  a RETN instruction instead, add the 
15699 \emph on
15700 critical
15701 \emph default
15702  keyword:
15703 \end_layout
15704
15705 \begin_layout Verse
15706
15707 \family typewriter
15708 void nmi_isr (void) critical interrupt
15709 \newline
15710
15711 \newline
15712 \InsetSpace ~
15713 \InsetSpace ~
15714 \InsetSpace ~
15715 \InsetSpace ~
15716 ...
15717  
15718 \newline
15719 }
15720 \end_layout
15721
15722 \begin_layout Standard
15723 However if you need to create a non-interruptable interrupt service routine
15724  you would also require the 
15725 \emph on
15726 critical
15727 \emph default
15728  keyword.
15729  To distinguish between this and an nmi_isr you must provide an interrupt
15730  number.
15731 \begin_inset VSpace bigskip
15732 \end_inset
15733
15734
15735 \end_layout
15736
15737 \begin_layout Section
15738 Enabling and Disabling Interrupts
15739 \end_layout
15740
15741 \begin_layout Subsection
15742 Critical Functions and Critical Statements
15743 \end_layout
15744
15745 \begin_layout Standard
15746 A special keyword may be associated with a block or a function declaring
15747  it as 
15748 \emph on
15749 critical
15750 \emph default
15751 .
15752  SDCC will generate code to disable all interrupts
15753 \begin_inset LatexCommand index
15754 name "interrupt"
15755
15756 \end_inset
15757
15758  upon entry to a critical function and restore the interrupt enable to the
15759  previous state before returning.
15760  Nesting critical functions will need one additional byte on the stack
15761 \begin_inset LatexCommand index
15762 name "stack"
15763
15764 \end_inset
15765
15766  for each call.
15767 \end_layout
15768
15769 \begin_layout Verse
15770
15771 \family typewriter
15772 int foo () __critical
15773 \begin_inset LatexCommand index
15774 name "critical"
15775
15776 \end_inset
15777
15778
15779 \begin_inset LatexCommand index
15780 name "\\_\\_critical"
15781
15782 \end_inset
15783
15784  
15785 \newline
15786
15787 \newline
15788 \InsetSpace ~
15789 \InsetSpace ~
15790 \InsetSpace ~
15791 \InsetSpace ~
15792 ...
15793  
15794 \newline
15795 \InsetSpace ~
15796 \InsetSpace ~
15797 \InsetSpace ~
15798 \InsetSpace ~
15799 ...
15800  
15801 \newline
15802 }
15803 \end_layout
15804
15805 \begin_layout Standard
15806 The critical attribute maybe used with other attributes like 
15807 \emph on
15808 reentrant.
15809 \emph default
15810
15811 \newline
15812 The keyword 
15813 \emph on
15814 critical
15815 \emph default
15816  may also be used to disable interrupts more locally:
15817 \end_layout
15818
15819 \begin_layout Verse
15820
15821 \family typewriter
15822 __critical{ i++; }
15823 \end_layout
15824
15825 \begin_layout Standard
15826 More than one statement could have been included in the block.
15827 \end_layout
15828
15829 \begin_layout Subsection
15830 Enabling and Disabling Interrupts directly
15831 \end_layout
15832
15833 \begin_layout Standard
15834 Interrupts
15835 \begin_inset LatexCommand index
15836 name "interrupt"
15837
15838 \end_inset
15839
15840  can also be disabled and enabled directly (8051):
15841 \end_layout
15842
15843 \begin_layout Verse
15844
15845 \family typewriter
15846 EA = 0;\InsetSpace ~
15847 \InsetSpace ~
15848 \InsetSpace ~
15849 \InsetSpace ~
15850 \InsetSpace ~
15851 \InsetSpace ~
15852 \InsetSpace ~
15853 \InsetSpace ~
15854 \InsetSpace ~
15855 \InsetSpace ~
15856 \InsetSpace ~
15857 \InsetSpace ~
15858 or:\InsetSpace ~
15859 \InsetSpace ~
15860 \InsetSpace ~
15861 \InsetSpace ~
15862 \InsetSpace ~
15863 \InsetSpace ~
15864 \InsetSpace ~
15865 \InsetSpace ~
15866 \InsetSpace ~
15867 \InsetSpace ~
15868 \InsetSpace ~
15869 EA_SAVE = EA;
15870 \end_layout
15871
15872 \begin_layout Verse
15873
15874 \family typewriter
15875 ...\InsetSpace ~
15876 \InsetSpace ~
15877 \InsetSpace ~
15878 \InsetSpace ~
15879 \InsetSpace ~
15880 \InsetSpace ~
15881 \InsetSpace ~
15882 \InsetSpace ~
15883 \InsetSpace ~
15884 \InsetSpace ~
15885 \InsetSpace ~
15886 \InsetSpace ~
15887 \InsetSpace ~
15888 \InsetSpace ~
15889 \InsetSpace ~
15890 \InsetSpace ~
15891 \InsetSpace ~
15892 \InsetSpace ~
15893 \InsetSpace ~
15894 \InsetSpace ~
15895 \InsetSpace ~
15896 \InsetSpace ~
15897 \InsetSpace ~
15898 \InsetSpace ~
15899 \InsetSpace ~
15900 \InsetSpace ~
15901 \InsetSpace ~
15902 \InsetSpace ~
15903 \InsetSpace ~
15904 \InsetSpace ~
15905 EA = 0;
15906 \end_layout
15907
15908 \begin_layout Verse
15909
15910 \family typewriter
15911 EA = 1;\InsetSpace ~
15912 \InsetSpace ~
15913 \InsetSpace ~
15914 \InsetSpace ~
15915 \InsetSpace ~
15916 \InsetSpace ~
15917 \InsetSpace ~
15918 \InsetSpace ~
15919 \InsetSpace ~
15920 \InsetSpace ~
15921 \InsetSpace ~
15922 \InsetSpace ~
15923 \InsetSpace ~
15924 \InsetSpace ~
15925 \InsetSpace ~
15926 \InsetSpace ~
15927 \InsetSpace ~
15928 \InsetSpace ~
15929 \InsetSpace ~
15930 \InsetSpace ~
15931 \InsetSpace ~
15932 \InsetSpace ~
15933 \InsetSpace ~
15934 \InsetSpace ~
15935 \InsetSpace ~
15936 \InsetSpace ~
15937 ...
15938 \end_layout
15939
15940 \begin_layout Verse
15941
15942 \family typewriter
15943 \InsetSpace ~
15944 \InsetSpace ~
15945 \InsetSpace ~
15946 \InsetSpace ~
15947 \InsetSpace ~
15948 \InsetSpace ~
15949 \InsetSpace ~
15950 \InsetSpace ~
15951 \InsetSpace ~
15952 \InsetSpace ~
15953 \InsetSpace ~
15954 \InsetSpace ~
15955 \InsetSpace ~
15956 \InsetSpace ~
15957 \InsetSpace ~
15958 \InsetSpace ~
15959 \InsetSpace ~
15960 \InsetSpace ~
15961 \InsetSpace ~
15962 \InsetSpace ~
15963 \InsetSpace ~
15964 \InsetSpace ~
15965 \InsetSpace ~
15966 \InsetSpace ~
15967 \InsetSpace ~
15968 \InsetSpace ~
15969 \InsetSpace ~
15970 \InsetSpace ~
15971 \InsetSpace ~
15972 \InsetSpace ~
15973 \InsetSpace ~
15974 \InsetSpace ~
15975 \InsetSpace ~
15976 EA = EA_SAVE;
15977 \end_layout
15978
15979 \begin_layout Standard
15980 On other architectures which have separate opcodes for enabling and disabling
15981  interrupts you might want to make use of defines with inline assembly
15982 \begin_inset LatexCommand index
15983 name "Assembler routines"
15984
15985 \end_inset
15986
15987  (HC08
15988 \begin_inset LatexCommand index
15989 name "HC08!interrupt"
15990
15991 \end_inset
15992
15993 ):
15994 \end_layout
15995
15996 \begin_layout Verse
15997
15998 \family typewriter
15999 #define CLI _asm
16000 \begin_inset LatexCommand index
16001 name "\\_asm"
16002
16003 \end_inset
16004
16005 \InsetSpace ~
16006 \InsetSpace ~
16007 cli\InsetSpace ~
16008 \InsetSpace ~
16009 _endasm
16010 \begin_inset LatexCommand index
16011 name "\\_endasm"
16012
16013 \end_inset
16014
16015
16016 \end_layout
16017
16018 \begin_layout Verse
16019
16020 \family typewriter
16021 #define SEI _asm\InsetSpace ~
16022 \InsetSpace ~
16023 sei\InsetSpace ~
16024 \InsetSpace ~
16025 _endasm; 
16026 \end_layout
16027
16028 \begin_layout Verse
16029
16030 \family typewriter
16031 ...
16032 \end_layout
16033
16034 \begin_layout Standard
16035 Note: it is sometimes sufficient to disable only a specific interrupt source
16036  like f.e.
16037  a timer or serial interrupt by manipulating an 
16038 \emph on
16039 interrupt mask
16040 \begin_inset LatexCommand index
16041 name "interrupt mask"
16042
16043 \end_inset
16044
16045
16046 \emph default
16047  register.
16048  
16049 \end_layout
16050
16051 \begin_layout Standard
16052 Usually the time during which interrupts are disabled should be kept as
16053  short as possible.
16054  This minimizes both 
16055 \emph on
16056 interrupt latency
16057 \emph default
16058
16059 \begin_inset LatexCommand index
16060 name "interrupt latency"
16061
16062 \end_inset
16063
16064  (the time between the occurrence of the interrupt and the execution of
16065  the first code in the interrupt routine) and 
16066 \emph on
16067 interrupt jitter
16068 \emph default
16069
16070 \begin_inset LatexCommand index
16071 name "interrupt jitter"
16072
16073 \end_inset
16074
16075  (the difference between the shortest and the longest interrupt latency).
16076  These really are something different, f.e.
16077  a serial interrupt has to be served before its buffer overruns so it cares
16078  for the maximum interrupt latency, whereas it does not care about jitter.
16079  On a loudspeaker driven via a digital to analog converter which is fed
16080  by an interrupt a latency of a few milliseconds might be tolerable, whereas
16081  a much smaller jitter will be very audible.
16082 \end_layout
16083
16084 \begin_layout Standard
16085 You can reenable interrupts within an interrupt routine and on some architecture
16086 s you can make use of two (or more) levels of 
16087 \emph on
16088 interrupt priorities
16089 \emph default
16090
16091 \begin_inset LatexCommand index
16092 name "interrupt priority"
16093
16094 \end_inset
16095
16096 .
16097  On some architectures which don't support interrupt priorities these can
16098  be implemented by manipulating the interrupt mask and reenabling interrupts
16099  within the interrupt routine.
16100  Check there is sufficient space on the stack
16101 \begin_inset LatexCommand index
16102 name "stack"
16103
16104 \end_inset
16105
16106  and don't add complexity unless you have to.
16107  
16108 \end_layout
16109
16110 \begin_layout Subsection
16111 Semaphore
16112 \begin_inset LatexCommand index
16113 name "semaphore"
16114
16115 \end_inset
16116
16117  locking (mcs51/ds390)
16118 \end_layout
16119
16120 \begin_layout Standard
16121 Some architectures (mcs51/ds390) have an atomic
16122 \begin_inset LatexCommand index
16123 name "atomic"
16124
16125 \end_inset
16126
16127  bit test and clear instruction.
16128  These type of instructions are typically used in preemptive multitasking
16129  systems, where a routine f.e.
16130  claims the use of a data structure ('acquires a lock
16131 \begin_inset LatexCommand index
16132 name "lock"
16133
16134 \end_inset
16135
16136  on it'), makes some modifications and then releases the lock when the data
16137  structure is consistent again.
16138  The instruction may also be used if interrupt and non-interrupt code have
16139  to compete for a resource.
16140  With the atomic bit test and clear instruction interrupts
16141 \begin_inset LatexCommand index
16142 name "interrupt"
16143
16144 \end_inset
16145
16146  don't have to be disabled for the locking operation.
16147  
16148 \end_layout
16149
16150 \begin_layout Standard
16151 SDCC generates this instruction if the source follows this pattern:
16152 \end_layout
16153
16154 \begin_layout Verse
16155
16156 \family typewriter
16157 volatile
16158 \begin_inset LatexCommand index
16159 name "volatile"
16160
16161 \end_inset
16162
16163  bit resource_is_free; 
16164 \newline
16165
16166 \newline
16167 if (resource_is_free) 
16168 \newline
16169 \InsetSpace ~
16170 \InsetSpace ~
16171
16172 \newline
16173 \InsetSpace ~
16174 \InsetSpace ~
16175 \InsetSpace ~
16176 \InsetSpace ~
16177 resource_is_free=0; 
16178 \newline
16179 \InsetSpace ~
16180 \InsetSpace ~
16181 \InsetSpace ~
16182 \InsetSpace ~
16183 ...
16184  
16185 \newline
16186 \InsetSpace ~
16187 \InsetSpace ~
16188 \InsetSpace ~
16189 \InsetSpace ~
16190 resource_is_free=1;
16191 \newline
16192 \InsetSpace ~
16193 \InsetSpace ~
16194
16195 \end_layout
16196
16197 \begin_layout Standard
16198 Note, mcs51 and ds390 support only an atomic
16199 \begin_inset LatexCommand index
16200 name "atomic"
16201
16202 \end_inset
16203
16204  bit test and 
16205 \emph on
16206 clear
16207 \emph default
16208  instruction (as opposed to atomic bit test and 
16209 \emph on
16210 set).
16211 \end_layout
16212
16213 \begin_layout Section
16214 Functions using private register banks
16215 \begin_inset LatexCommand label
16216 name "sub:Functions-using-private-banks"
16217
16218 \end_inset
16219
16220  (mcs51/ds390)
16221 \end_layout
16222
16223 \begin_layout Standard
16224 Some architectures have support for quickly changing register sets.
16225  SDCC supports this feature with the 
16226 \emph on
16227 using
16228 \begin_inset LatexCommand index
16229 name "using (mcs51, ds390 register bank)"
16230
16231 \end_inset
16232
16233
16234 \begin_inset LatexCommand index
16235 name "\\_\\_using (mcs51, ds390 register bank)"
16236
16237 \end_inset
16238
16239
16240 \emph default
16241  attribute (which tells the compiler to use a register bank
16242 \begin_inset LatexCommand index
16243 name "register bank (mcs51, ds390)"
16244
16245 \end_inset
16246
16247  other than the default bank zero).
16248  It should only be applied to 
16249 \emph on
16250 interrupt
16251 \begin_inset LatexCommand index
16252 name "interrupt"
16253
16254 \end_inset
16255
16256
16257 \emph default
16258  functions (see footnote below).
16259  This will in most circumstances make the generated ISR code more efficient
16260  since it will not have to save registers on the stack.
16261 \end_layout
16262
16263 \begin_layout Standard
16264 The 
16265 \emph on
16266 using
16267 \emph default
16268  attribute will have no effect on the generated code for a 
16269 \emph on
16270 non-interrupt
16271 \emph default
16272  function (but may occasionally be useful anyway
16273 \begin_inset Foot
16274 status open
16275
16276 \begin_layout Standard
16277 possible exception: if a function is called ONLY from 'interrupt' functions
16278  using a particular bank, it can be declared with the same 'using' attribute
16279  as the calling 'interrupt' functions.
16280  For instance, if you have several ISRs using bank one, and all of them
16281  call memcpy(), it might make sense to create a specialized version of memcpy()
16282  'using 1', since this would prevent the ISR from having to save bank zero
16283  to the stack on entry and switch to bank zero before calling the function
16284 \end_layout
16285
16286 \end_inset
16287
16288 ).
16289 \newline
16290
16291 \emph on
16292 (pending: Note, nowadays the
16293 \emph default
16294  using 
16295 \emph on
16296 attribute has an effect on
16297 \emph default
16298  
16299 \emph on
16300 the generated code for a
16301 \emph default
16302  non-interrupt 
16303 \emph on
16304 function
16305 \emph default
16306 .
16307 \emph on
16308 )
16309 \end_layout
16310
16311 \begin_layout Standard
16312 An 
16313 \emph on
16314 interrupt
16315 \emph default
16316  function using a non-zero bank will assume that it can trash that register
16317  bank, and will not save it.
16318  Since high-priority interrupts
16319 \begin_inset LatexCommand index
16320 name "interrupts"
16321
16322 \end_inset
16323
16324
16325 \begin_inset LatexCommand index
16326 name "interrupt priority"
16327
16328 \end_inset
16329
16330  can interrupt low-priority ones on the 8051 and friends, this means that
16331  if a high-priority ISR 
16332 \emph on
16333 using
16334 \emph default
16335  a particular bank occurs while processing a low-priority ISR 
16336 \emph on
16337 using
16338 \emph default
16339  the same bank, terrible and bad things can happen.
16340  To prevent this, no single register bank should be 
16341 \emph on
16342 used
16343 \emph default
16344  by both a high priority and a low priority ISR.
16345  This is probably most easily done by having all high priority ISRs use
16346  one bank and all low priority ISRs use another.
16347  If you have an ISR which can change priority at runtime, you're on your
16348  own: I suggest using the default bank zero and taking the small performance
16349  hit.
16350 \end_layout
16351
16352 \begin_layout Standard
16353 It is most efficient if your ISR calls no other functions.
16354  If your ISR must call other functions, it is most efficient if those functions
16355  use the same bank as the ISR (see note 1 below); the next best is if the
16356  called functions use bank zero.
16357  It is very inefficient to call a function using a different, non-zero bank
16358  from an ISR.
16359  
16360 \begin_inset VSpace bigskip
16361 \end_inset
16362
16363
16364 \end_layout
16365
16366 \begin_layout Section
16367 Startup Code
16368 \begin_inset LatexCommand label
16369 name "sub:Startup-Code"
16370
16371 \end_inset
16372
16373
16374 \begin_inset LatexCommand index
16375 name "Startup code"
16376
16377 \end_inset
16378
16379
16380 \end_layout
16381
16382 \begin_layout Subsection
16383 MCS51/DS390 Startup Code
16384 \end_layout
16385
16386 \begin_layout Standard
16387 The compiler triggers the linker to link certain initialization modules
16388  from the runtime library
16389 \begin_inset LatexCommand index
16390 name "Runtime library"
16391
16392 \end_inset
16393
16394  called crt<something>.
16395  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
16396  GSINIT5) is not linked unless the -
16397 \series bold
16398
16399 \begin_inset ERT
16400 status open
16401
16402 \begin_layout Standard
16403
16404
16405 \backslash
16406 /
16407 \end_layout
16408
16409 \end_inset
16410
16411
16412 \series default
16413 -xstack option is used.
16414  These modules are highly entangled by the use of special segments/areas,
16415  but a common layout is shown below:
16416 \end_layout
16417
16418 \begin_layout Verse
16419
16420 \family typewriter
16421 \series bold
16422 \size footnotesize
16423 (main.asm)
16424 \end_layout
16425
16426 \begin_layout Verse
16427
16428 \family typewriter
16429 \size footnotesize
16430 \InsetSpace ~
16431 \InsetSpace ~
16432 \InsetSpace ~
16433 \InsetSpace ~
16434 \InsetSpace ~
16435 \InsetSpace ~
16436 \InsetSpace ~
16437 \InsetSpace ~
16438 .area HOME (CODE)
16439 \newline
16440 __interrupt_vect:
16441 \newline
16442 \InsetSpace ~
16443 \InsetSpace ~
16444 \InsetSpace ~
16445 \InsetSpace ~
16446 \InsetSpace ~
16447 \InsetSpace ~
16448 \InsetSpace ~
16449 \InsetSpace ~
16450 ljmp __sdcc_gsinit_startup
16451 \end_layout
16452
16453 \begin_layout Verse
16454
16455 \family typewriter
16456 \series bold
16457 \size footnotesize
16458 (crtstart.asm)
16459 \end_layout
16460
16461 \begin_layout Verse
16462
16463 \family typewriter
16464 \size footnotesize
16465 \InsetSpace ~
16466 \InsetSpace ~
16467 \InsetSpace ~
16468 \InsetSpace ~
16469 \InsetSpace ~
16470 \InsetSpace ~
16471 \InsetSpace ~
16472 \InsetSpace ~
16473 .area GSINIT0 (CODE)
16474 \newline
16475 __sdcc_gsinit_startup::
16476 \newline
16477 \InsetSpace ~
16478 \InsetSpace ~
16479 \InsetSpace ~
16480 \InsetSpace ~
16481 \InsetSpace ~
16482 \InsetSpace ~
16483 \InsetSpace ~
16484 \InsetSpace ~
16485 mov sp,#__start__stack - 1
16486 \end_layout
16487
16488 \begin_layout Verse
16489
16490 \family typewriter
16491 \series bold
16492 \size footnotesize
16493 (crtxstack.asm)
16494 \end_layout
16495
16496 \begin_layout Verse
16497
16498 \family typewriter
16499 \size footnotesize
16500 \InsetSpace ~
16501 \InsetSpace ~
16502 \InsetSpace ~
16503 \InsetSpace ~
16504 \InsetSpace ~
16505 \InsetSpace ~
16506 \InsetSpace ~
16507 \InsetSpace ~
16508 .area GSINIT1 (CODE)
16509 \newline
16510 __sdcc_init_xstack::
16511 \newline
16512 ; Need to initialize in GSINIT1 in
16513  case the user's __sdcc_external_startup uses the xstack.
16514 \newline
16515 \InsetSpace ~
16516 \InsetSpace ~
16517 \InsetSpace ~
16518 \InsetSpace ~
16519 \InsetSpace ~
16520 \InsetSpace ~
16521 \InsetSpace ~
16522 \InsetSpace ~
16523 mov __XPAGE,#(__start__x
16524 stack >> 8)
16525 \newline
16526 \InsetSpace ~
16527 \InsetSpace ~
16528 \InsetSpace ~
16529 \InsetSpace ~
16530 \InsetSpace ~
16531 \InsetSpace ~
16532 \InsetSpace ~
16533 \InsetSpace ~
16534 mov _spx,#__start__xstack
16535 \end_layout
16536
16537 \begin_layout Verse
16538
16539 \family typewriter
16540 \series bold
16541 \size footnotesize
16542 (crtstart.asm)
16543 \end_layout
16544
16545 \begin_layout Verse
16546
16547 \family typewriter
16548 \size footnotesize
16549 \InsetSpace ~
16550 \InsetSpace ~
16551 \InsetSpace ~
16552 \InsetSpace ~
16553 \InsetSpace ~
16554 \InsetSpace ~
16555 \InsetSpace ~
16556 \InsetSpace ~
16557 .area GSINIT2 (CODE)
16558 \newline
16559 \InsetSpace ~
16560 \InsetSpace ~
16561 \InsetSpace ~
16562 \InsetSpace ~
16563 \InsetSpace ~
16564 \InsetSpace ~
16565 \InsetSpace ~
16566 \InsetSpace ~
16567 lcall __sdcc_external_startup
16568 \newline
16569 \InsetSpace ~
16570 \InsetSpace ~
16571 \InsetSpace ~
16572 \InsetSpace ~
16573 \InsetSpace ~
16574 \InsetSpace ~
16575 \InsetSpace ~
16576 \InsetSpace ~
16577 mov a,dpl
16578 \newline
16579 \InsetSpace ~
16580 \InsetSpace ~
16581 \InsetSpace ~
16582 \InsetSpace ~
16583 \InsetSpace ~
16584 \InsetSpace ~
16585 \InsetSpace ~
16586 \InsetSpace ~
16587 jz __sdcc_init_data
16588 \newline
16589 \InsetSpace ~
16590 \InsetSpace ~
16591 \InsetSpace ~
16592 \InsetSpace ~
16593 \InsetSpace ~
16594 \InsetSpace ~
16595 \InsetSpace ~
16596 \InsetSpace ~
16597 ljmp
16598  __sdcc_program_startup
16599 \newline
16600 __sdcc_init_data:
16601 \end_layout
16602
16603 \begin_layout Verse
16604
16605 \family typewriter
16606 \series bold
16607 \size footnotesize
16608 (crtxinit.asm)
16609 \end_layout
16610
16611 \begin_layout Verse
16612
16613 \family typewriter
16614 \size footnotesize
16615 \InsetSpace ~
16616 \InsetSpace ~
16617 \InsetSpace ~
16618 \InsetSpace ~
16619 \InsetSpace ~
16620 \InsetSpace ~
16621 \InsetSpace ~
16622 \InsetSpace ~
16623 .area GSINIT3 (CODE)
16624 \newline
16625 __mcs51_genXINIT::
16626 \newline
16627 \InsetSpace ~
16628 \InsetSpace ~
16629 \InsetSpace ~
16630 \InsetSpace ~
16631 \InsetSpace ~
16632 \InsetSpace ~
16633 \InsetSpace ~
16634 \InsetSpace ~
16635 mov r1,#l_XINIT
16636 \newline
16637 \InsetSpace ~
16638 \InsetSpace ~
16639 \InsetSpace ~
16640 \InsetSpace ~
16641 \InsetSpace ~
16642 \InsetSpace ~
16643 \InsetSpace ~
16644 \InsetSpace ~
16645 mov a,r1
16646 \newline
16647 \InsetSpace ~
16648 \InsetSpace ~
16649 \InsetSpace ~
16650 \InsetSpace ~
16651 \InsetSpace ~
16652 \InsetSpace ~
16653 \InsetSpace ~
16654 \InsetSpace ~
16655 orl a,#(l_XINIT
16656  >> 8)
16657 \newline
16658 \InsetSpace ~
16659 \InsetSpace ~
16660 \InsetSpace ~
16661 \InsetSpace ~
16662 \InsetSpace ~
16663 \InsetSpace ~
16664 \InsetSpace ~
16665 \InsetSpace ~
16666 jz 00003$
16667 \newline
16668 \InsetSpace ~
16669 \InsetSpace ~
16670 \InsetSpace ~
16671 \InsetSpace ~
16672 \InsetSpace ~
16673 \InsetSpace ~
16674 \InsetSpace ~
16675 \InsetSpace ~
16676 mov r2,#((l_XINIT+255) >> 8)
16677 \newline
16678 \InsetSpace ~
16679 \InsetSpace ~
16680 \InsetSpace ~
16681 \InsetSpace ~
16682 \InsetSpace ~
16683 \InsetSpace ~
16684 \InsetSpace ~
16685 \InsetSpace ~
16686 mov dptr,#s_XINIT
16687 \newline
16688 \InsetSpace ~
16689 \InsetSpace ~
16690 \InsetSpace ~
16691 \InsetSpace ~
16692 \InsetSpace ~
16693 \InsetSpace ~
16694 \InsetSpace ~
16695 \InsetSpace ~
16696 mov r0,#s_XISEG
16697 \newline
16698 \InsetSpace ~
16699 \InsetSpace ~
16700 \InsetSpace ~
16701 \InsetSpace ~
16702 \InsetSpace ~
16703 \InsetSpace ~
16704 \InsetSpace ~
16705 \InsetSpace ~
16706 mov
16707  __XPAGE,#(s_XISEG >> 8)
16708 \newline
16709 00001$:\InsetSpace ~
16710 clr a
16711 \newline
16712 \InsetSpace ~
16713 \InsetSpace ~
16714 \InsetSpace ~
16715 \InsetSpace ~
16716 \InsetSpace ~
16717 \InsetSpace ~
16718 \InsetSpace ~
16719 \InsetSpace ~
16720 movc a,@a+dptr
16721 \newline
16722 \InsetSpace ~
16723 \InsetSpace ~
16724 \InsetSpace ~
16725 \InsetSpace ~
16726 \InsetSpace ~
16727 \InsetSpace ~
16728 \InsetSpace ~
16729 \InsetSpace ~
16730 movx @r0,a
16731 \newline
16732 \InsetSpace ~
16733 \InsetSpace ~
16734 \InsetSpace ~
16735 \InsetSpace ~
16736 \InsetSpace ~
16737 \InsetSpace ~
16738 \InsetSpace ~
16739 \InsetSpace ~
16740 inc dptr
16741 \newline
16742 \InsetSpace ~
16743 \InsetSpace ~
16744 \InsetSpace ~
16745 \InsetSpace ~
16746 \InsetSpace ~
16747 \InsetSpace ~
16748 \InsetSpace ~
16749 \InsetSpace ~
16750 inc
16751  r0
16752 \newline
16753 \InsetSpace ~
16754 \InsetSpace ~
16755 \InsetSpace ~
16756 \InsetSpace ~
16757 \InsetSpace ~
16758 \InsetSpace ~
16759 \InsetSpace ~
16760 \InsetSpace ~
16761 cjne r0,#0,00002$
16762 \newline
16763 \InsetSpace ~
16764 \InsetSpace ~
16765 \InsetSpace ~
16766 \InsetSpace ~
16767 \InsetSpace ~
16768 \InsetSpace ~
16769 \InsetSpace ~
16770 \InsetSpace ~
16771 inc __XPAGE
16772 \newline
16773 00002$:\InsetSpace ~
16774 djnz r1,00001$
16775 \newline
16776 \InsetSpace ~
16777 \InsetSpace ~
16778 \InsetSpace ~
16779 \InsetSpace ~
16780 \InsetSpace ~
16781 \InsetSpace ~
16782 \InsetSpace ~
16783 \InsetSpace ~
16784 djnz r2,00001$
16785 \newline
16786 \InsetSpace ~
16787 \InsetSpace ~
16788 \InsetSpace ~
16789 \InsetSpace ~
16790 \InsetSpace ~
16791 \InsetSpace ~
16792 \InsetSpace ~
16793 \InsetSpace ~
16794 mov __XPAGE,#0
16795 xFF
16796 \newline
16797 00003$:
16798 \end_layout
16799
16800 \begin_layout Verse
16801
16802 \family typewriter
16803 \series bold
16804 \size footnotesize
16805 (crtclear.asm)
16806 \end_layout
16807
16808 \begin_layout Verse
16809
16810 \family typewriter
16811 \size footnotesize
16812 \InsetSpace ~
16813 \InsetSpace ~
16814 \InsetSpace ~
16815 \InsetSpace ~
16816 \InsetSpace ~
16817 \InsetSpace ~
16818 \InsetSpace ~
16819 \InsetSpace ~
16820 .area GSINIT4 (CODE)
16821 \newline
16822 __mcs51_genRAMCLEAR::
16823 \newline
16824 \InsetSpace ~
16825 \InsetSpace ~
16826 \InsetSpace ~
16827 \InsetSpace ~
16828 \InsetSpace ~
16829 \InsetSpace ~
16830 \InsetSpace ~
16831 \InsetSpace ~
16832 clr a
16833 \newline
16834 \InsetSpace ~
16835 \InsetSpace ~
16836 \InsetSpace ~
16837 \InsetSpace ~
16838 \InsetSpace ~
16839 \InsetSpace ~
16840 \InsetSpace ~
16841 \InsetSpace ~
16842 mov r0,#(l_IRAM-1)
16843 \newline
16844 00004$:\InsetSpace ~
16845 mov
16846  @r0,a
16847 \newline
16848 \InsetSpace ~
16849 \InsetSpace ~
16850 \InsetSpace ~
16851 \InsetSpace ~
16852 \InsetSpace ~
16853 \InsetSpace ~
16854 \InsetSpace ~
16855 \InsetSpace ~
16856 djnz r0,00004$
16857 \newline
16858 ; _mcs51_genRAMCLEAR() end
16859 \end_layout
16860
16861 \begin_layout Verse
16862
16863 \family typewriter
16864 \series bold
16865 \size footnotesize
16866 (crtxclear.asm)
16867 \end_layout
16868
16869 \begin_layout Verse
16870
16871 \family typewriter
16872 \size footnotesize
16873 \InsetSpace ~
16874 \InsetSpace ~
16875 \InsetSpace ~
16876 \InsetSpace ~
16877 \InsetSpace ~
16878 \InsetSpace ~
16879 \InsetSpace ~
16880 \InsetSpace ~
16881 .area GSINIT4 (CODE)
16882 \newline
16883 __mcs51_genXRAMCLEAR::
16884 \newline
16885 \InsetSpace ~
16886 \InsetSpace ~
16887 \InsetSpace ~
16888 \InsetSpace ~
16889 \InsetSpace ~
16890 \InsetSpace ~
16891 \InsetSpace ~
16892 \InsetSpace ~
16893 mov r0,#l_PSEG
16894 \newline
16895 \InsetSpace ~
16896 \InsetSpace ~
16897 \InsetSpace ~
16898 \InsetSpace ~
16899 \InsetSpace ~
16900 \InsetSpace ~
16901 \InsetSpace ~
16902 \InsetSpace ~
16903 mov a,r0
16904 \newline
16905 \InsetSpace ~
16906 \InsetSpace ~
16907 \InsetSpace ~
16908 \InsetSpace ~
16909 \InsetSpace ~
16910 \InsetSpace ~
16911 \InsetSpace ~
16912 \InsetSpace ~
16913 orl a,#(l_PSEG
16914  >> 8)
16915 \newline
16916 \InsetSpace ~
16917 \InsetSpace ~
16918 \InsetSpace ~
16919 \InsetSpace ~
16920 \InsetSpace ~
16921 \InsetSpace ~
16922 \InsetSpace ~
16923 \InsetSpace ~
16924 jz 00006$
16925 \newline
16926 \InsetSpace ~
16927 \InsetSpace ~
16928 \InsetSpace ~
16929 \InsetSpace ~
16930 \InsetSpace ~
16931 \InsetSpace ~
16932 \InsetSpace ~
16933 \InsetSpace ~
16934 mov r1,#s_PSEG
16935 \newline
16936 \InsetSpace ~
16937 \InsetSpace ~
16938 \InsetSpace ~
16939 \InsetSpace ~
16940 \InsetSpace ~
16941 \InsetSpace ~
16942 \InsetSpace ~
16943 \InsetSpace ~
16944 mov __XPAGE,#(s_PSEG >> 8)
16945 \newline
16946 \InsetSpace ~
16947 \InsetSpace ~
16948 \InsetSpace ~
16949 \InsetSpace ~
16950 \InsetSpace ~
16951 \InsetSpace ~
16952 \InsetSpace ~
16953 \InsetSpace ~
16954 clr a
16955 \newline
16956 00005$:\InsetSpace ~
16957 movx
16958  @r1,a
16959 \newline
16960 \InsetSpace ~
16961 \InsetSpace ~
16962 \InsetSpace ~
16963 \InsetSpace ~
16964 \InsetSpace ~
16965 \InsetSpace ~
16966 \InsetSpace ~
16967 \InsetSpace ~
16968 inc r1
16969 \newline
16970 \InsetSpace ~
16971 \InsetSpace ~
16972 \InsetSpace ~
16973 \InsetSpace ~
16974 \InsetSpace ~
16975 \InsetSpace ~
16976 \InsetSpace ~
16977 \InsetSpace ~
16978 djnz r0,00005$
16979 \newline
16980 00006$:
16981 \newline
16982 \InsetSpace ~
16983 \InsetSpace ~
16984 \InsetSpace ~
16985 \InsetSpace ~
16986 \InsetSpace ~
16987 \InsetSpace ~
16988 \InsetSpace ~
16989 \InsetSpace ~
16990 mov r0,#l_XSEG
16991 \newline
16992 \InsetSpace ~
16993 \InsetSpace ~
16994 \InsetSpace ~
16995 \InsetSpace ~
16996 \InsetSpace ~
16997 \InsetSpace ~
16998 \InsetSpace ~
16999 \InsetSpace ~
17000 mov a,r0
17001 \newline
17002 \InsetSpace ~
17003 \InsetSpace ~
17004 \InsetSpace ~
17005 \InsetSpace ~
17006 \InsetSpace ~
17007 \InsetSpace ~
17008 \InsetSpace ~
17009 \InsetSpace ~
17010 orl a,#(l_XSEG >>
17011  8)
17012 \newline
17013 \InsetSpace ~
17014 \InsetSpace ~
17015 \InsetSpace ~
17016 \InsetSpace ~
17017 \InsetSpace ~
17018 \InsetSpace ~
17019 \InsetSpace ~
17020 \InsetSpace ~
17021 jz 00008$
17022 \newline
17023 \InsetSpace ~
17024 \InsetSpace ~
17025 \InsetSpace ~
17026 \InsetSpace ~
17027 \InsetSpace ~
17028 \InsetSpace ~
17029 \InsetSpace ~
17030 \InsetSpace ~
17031 mov r1,#((l_XSEG + 255) >> 8)
17032 \newline
17033 \InsetSpace ~
17034 \InsetSpace ~
17035 \InsetSpace ~
17036 \InsetSpace ~
17037 \InsetSpace ~
17038 \InsetSpace ~
17039 \InsetSpace ~
17040 \InsetSpace ~
17041 mov dptr,#s_XSEG
17042 \newline
17043 \InsetSpace ~
17044 \InsetSpace ~
17045 \InsetSpace ~
17046 \InsetSpace ~
17047 \InsetSpace ~
17048 \InsetSpace ~
17049 \InsetSpace ~
17050 \InsetSpace ~
17051 clr a
17052 \newline
17053 00007$:\InsetSpace ~
17054 movx
17055  @dptr,a
17056 \newline
17057 \InsetSpace ~
17058 \InsetSpace ~
17059 \InsetSpace ~
17060 \InsetSpace ~
17061 \InsetSpace ~
17062 \InsetSpace ~
17063 \InsetSpace ~
17064 \InsetSpace ~
17065 inc dptr
17066 \newline
17067 \InsetSpace ~
17068 \InsetSpace ~
17069 \InsetSpace ~
17070 \InsetSpace ~
17071 \InsetSpace ~
17072 \InsetSpace ~
17073 \InsetSpace ~
17074 \InsetSpace ~
17075 djnz r0,00007$
17076 \newline
17077 \InsetSpace ~
17078 \InsetSpace ~
17079 \InsetSpace ~
17080 \InsetSpace ~
17081 \InsetSpace ~
17082 \InsetSpace ~
17083 \InsetSpace ~
17084 \InsetSpace ~
17085 djnz r1,00007$
17086 \newline
17087 00008$:
17088 \end_layout
17089
17090 \begin_layout Verse
17091
17092 \family typewriter
17093 \series bold
17094 \size footnotesize
17095 (crtxstack.asm)
17096 \end_layout
17097
17098 \begin_layout Verse
17099
17100 \family typewriter
17101 \size footnotesize
17102 \InsetSpace ~
17103 \InsetSpace ~
17104 \InsetSpace ~
17105 \InsetSpace ~
17106 \InsetSpace ~
17107 \InsetSpace ~
17108 \InsetSpace ~
17109 \InsetSpace ~
17110 .area GSINIT5 (CODE)
17111 \newline
17112 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
17113  modifies __XPAGE
17114 \newline
17115 ; and __mcs51_genRAMCLEAR modifies _spx.
17116 \newline
17117 \InsetSpace ~
17118 \InsetSpace ~
17119 \InsetSpace ~
17120 \InsetSpace ~
17121 \InsetSpace ~
17122 \InsetSpace ~
17123 \InsetSpace ~
17124 \InsetSpace ~
17125 mov __XPAGE,#(__start__x
17126 stack >> 8)
17127 \newline
17128 \InsetSpace ~
17129 \InsetSpace ~
17130 \InsetSpace ~
17131 \InsetSpace ~
17132 \InsetSpace ~
17133 \InsetSpace ~
17134 \InsetSpace ~
17135 \InsetSpace ~
17136 mov _spx,#__start__xstack
17137 \end_layout
17138
17139 \begin_layout Verse
17140
17141 \family typewriter
17142 \series bold
17143 \size footnotesize
17144 (application modules)
17145 \end_layout
17146
17147 \begin_layout Verse
17148
17149 \family typewriter
17150 \size footnotesize
17151 \InsetSpace ~
17152 \InsetSpace ~
17153 \InsetSpace ~
17154 \InsetSpace ~
17155 \InsetSpace ~
17156 \InsetSpace ~
17157 \InsetSpace ~
17158 \InsetSpace ~
17159 .area GSINIT (CODE)
17160 \end_layout
17161
17162 \begin_layout Verse
17163
17164 \family typewriter
17165 \series bold
17166 \size footnotesize
17167 (main.asm)
17168 \end_layout
17169
17170 \begin_layout Verse
17171
17172 \family typewriter
17173 \size footnotesize
17174 \InsetSpace ~
17175 \InsetSpace ~
17176 \InsetSpace ~
17177 \InsetSpace ~
17178 \InsetSpace ~
17179 \InsetSpace ~
17180 \InsetSpace ~
17181 \InsetSpace ~
17182 .area GSFINAL (CODE)
17183 \newline
17184 \InsetSpace ~
17185 \InsetSpace ~
17186 \InsetSpace ~
17187 \InsetSpace ~
17188 \InsetSpace ~
17189 \InsetSpace ~
17190 \InsetSpace ~
17191 \InsetSpace ~
17192 ljmp __sdcc_program_startup
17193 \newline
17194 ;---------------------------------
17195 -----------------------
17196 \newline
17197 ; Home
17198 \newline
17199 ;--------------------------------------------------
17200 ------
17201 \newline
17202 \InsetSpace ~
17203 \InsetSpace ~
17204 \InsetSpace ~
17205 \InsetSpace ~
17206 \InsetSpace ~
17207 \InsetSpace ~
17208 \InsetSpace ~
17209 \InsetSpace ~
17210 .area HOME (CODE)
17211 \newline
17212 \InsetSpace ~
17213 \InsetSpace ~
17214 \InsetSpace ~
17215 \InsetSpace ~
17216 \InsetSpace ~
17217 \InsetSpace ~
17218 \InsetSpace ~
17219 \InsetSpace ~
17220 .area CSEG (CODE)
17221 \newline
17222 __sdcc_program_startup:
17223 \newline
17224 \InsetSpace ~
17225 \InsetSpace ~
17226 \InsetSpace ~
17227 \InsetSpace ~
17228 \InsetSpace ~
17229 \InsetSpace ~
17230 \InsetSpace ~
17231 \InsetSpace ~
17232 lcall _main
17233 \newline
17234 ;
17235  return from main will lock up
17236 \newline
17237 \InsetSpace ~
17238 \InsetSpace ~
17239 \InsetSpace ~
17240 \InsetSpace ~
17241 \InsetSpace ~
17242 \InsetSpace ~
17243 \InsetSpace ~
17244 \InsetSpace ~
17245 sjmp .
17246 \end_layout
17247
17248 \begin_layout Standard
17249 One of these modules (crtstart.asm) contains a call to the C routine 
17250 \emph on
17251 _sdcc_external_startup()
17252 \begin_inset LatexCommand index
17253 name "\\_sdcc\\_external\\_startup()"
17254
17255 \end_inset
17256
17257
17258 \emph default
17259  at the start of the CODE area.
17260  This routine is also in the runtime library
17261 \begin_inset LatexCommand index
17262 name "Runtime library"
17263
17264 \end_inset
17265
17266  and returns 0 by default.
17267  If this routine returns a non-zero value, the static & global variable
17268  initialization will be skipped and the function main will be invoked.
17269  Otherwise static & global variables will be initialized before the function
17270  main is invoked.
17271  You could add an 
17272 \emph on
17273 _sdcc_external_startup()
17274 \emph default
17275  routine to your program to override the default if you need to setup hardware
17276  or perform some other critical operation prior to static & global variable
17277  initialization
17278 \begin_inset LatexCommand index
17279 name "Variable initialization"
17280
17281 \end_inset
17282
17283 .
17284  On some mcs51 variants xdata
17285 \begin_inset LatexCommand index
17286 name "xdata (mcs51, ds390 storage class)"
17287
17288 \end_inset
17289
17290  memory has to be explicitly enabled before it can be accessed or if the
17291  watchdog
17292 \begin_inset LatexCommand index
17293 name "watchdog"
17294
17295 \end_inset
17296
17297  needs to be disabled, this is the place to do it.
17298  The startup code clears all internal data memory, 256 bytes by default,
17299  but from 0 to n-1 if 
17300 \emph on
17301 -
17302 \begin_inset ERT
17303 status collapsed
17304
17305 \begin_layout Standard
17306
17307
17308 \backslash
17309 /
17310 \end_layout
17311
17312 \end_inset
17313
17314 -iram-size
17315 \begin_inset LatexCommand index
17316 name "-\\/-iram-size <Value>"
17317
17318 \end_inset
17319
17320 n
17321 \emph default
17322  is used.
17323  (recommended for Chipcon CC1010).
17324 \end_layout
17325
17326 \begin_layout Standard
17327 See also the compiler options 
17328 \emph on
17329 -
17330 \begin_inset ERT
17331 status collapsed
17332
17333 \begin_layout Standard
17334
17335
17336 \backslash
17337 /
17338 \end_layout
17339
17340 \end_inset
17341
17342 -no-xinit
17343 \emph default
17344 -
17345 \emph on
17346 opt
17347 \emph default
17348
17349 \begin_inset LatexCommand index
17350 name "-\\/-no-xinit-opt"
17351
17352 \end_inset
17353
17354
17355 \emph on
17356 -
17357 \begin_inset ERT
17358 status collapsed
17359
17360 \begin_layout Standard
17361
17362
17363 \backslash
17364 /
17365 \end_layout
17366
17367 \end_inset
17368
17369 -main-return
17370 \emph default
17371
17372 \begin_inset LatexCommand index
17373 name "-\\/-main-return"
17374
17375 \end_inset
17376
17377  and section 
17378 \begin_inset LatexCommand ref
17379 reference "sub:MCS51-variants"
17380
17381 \end_inset
17382
17383  about MCS51-variants.
17384 \newline
17385
17386 \end_layout
17387
17388 \begin_layout Standard
17389 While these initialization modules are meant as generic startup code there
17390  might be the need for customization.
17391  Let's assume the return value of 
17392 \emph on
17393 _sdcc_external_startup()
17394 \emph default
17395  in 
17396 \emph on
17397 crtstart.asm
17398 \emph default
17399  should not be checked (or 
17400 \emph on
17401 _sdcc_external_startup()
17402 \emph default
17403  should not be called at all).
17404  The recommended way would be to copy 
17405 \emph on
17406 crtstart.asm
17407 \emph default
17408  (f.e.
17409  from 
17410 \begin_inset LatexCommand url
17411 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm"
17412
17413 \end_inset
17414
17415 ) into the source directory, adapt it there, then assemble it with 
17416 \emph on
17417 asx8051 -plosgff
17418 \begin_inset Foot
17419 status open
17420
17421 \begin_layout Standard
17422 \begin_inset Quotes sld
17423 \end_inset
17424
17425 -plosgff
17426 \begin_inset Quotes srd
17427 \end_inset
17428
17429  are the assembler options used in 
17430 \begin_inset LatexCommand url
17431 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup "
17432
17433 \end_inset
17434
17435
17436 \end_layout
17437
17438 \end_inset
17439
17440  crtstart.asm
17441 \emph default
17442  and when linking your project explicitly specify 
17443 \emph on
17444 crtstart.rel
17445 \emph default
17446 .
17447  As a bonus a listing of the relocated object file 
17448 \emph on
17449 crtstart.rst
17450 \emph default
17451  is generated.
17452 \end_layout
17453
17454 \begin_layout Standard
17455 \begin_inset VSpace bigskip
17456 \end_inset
17457
17458
17459 \end_layout
17460
17461 \begin_layout Subsection
17462 HC08 Startup Code
17463 \end_layout
17464
17465 \begin_layout Standard
17466 The HC08
17467 \begin_inset LatexCommand index
17468 name "HC08"
17469
17470 \end_inset
17471
17472  startup code follows the same scheme as the MCS51 startup code.
17473 \begin_inset VSpace bigskip
17474 \end_inset
17475
17476
17477 \end_layout
17478
17479 \begin_layout Subsection
17480 Z80 Startup Code
17481 \end_layout
17482
17483 \begin_layout Standard
17484 On the Z80
17485 \begin_inset LatexCommand index
17486 name "Z80"
17487
17488 \end_inset
17489
17490  the startup code is inserted by linking with crt0.o which is generated from
17491  sdcc/device/lib/z80/crt0.s.
17492  If you need a different startup code you can use the compiler option 
17493 \emph on
17494 -
17495 \series bold
17496 \emph default
17497
17498 \begin_inset ERT
17499 status collapsed
17500
17501 \begin_layout Standard
17502
17503
17504 \backslash
17505 /
17506 \end_layout
17507
17508 \end_inset
17509
17510
17511 \series default
17512 \emph on
17513 -no-std-crt0
17514 \emph default
17515
17516 \begin_inset LatexCommand index
17517 name "-\\/-no-std-crt0"
17518
17519 \end_inset
17520
17521  and provide your own crt0.o.
17522  
17523 \begin_inset VSpace bigskip
17524 \end_inset
17525
17526
17527 \end_layout
17528
17529 \begin_layout Section
17530 Inline Assembler Code
17531 \begin_inset LatexCommand index
17532 name "Assembler routines"
17533
17534 \end_inset
17535
17536
17537 \end_layout
17538
17539 \begin_layout Subsection
17540 A Step by Step Introduction
17541 \begin_inset LatexCommand label
17542 name "sub:A-Step-by Assembler Introduction"
17543
17544 \end_inset
17545
17546
17547 \end_layout
17548
17549 \begin_layout Standard
17550 Starting from a small snippet of c-code this example shows for the MCS51
17551  how to use inline assembly, access variables, a function parameter and
17552  an array in xdata memory.
17553  The example uses an MCS51 here but is easily adapted for other architectures.
17554  This is a buffer routine which should be optimized:
17555 \end_layout
17556
17557 \begin_layout Verse
17558
17559 \family typewriter
17560 \size footnotesize
17561 unsigned char __far
17562 \begin_inset LatexCommand index
17563 name "far (storage class)"
17564
17565 \end_inset
17566
17567
17568 \begin_inset LatexCommand index
17569 name "\\_\\_far (storage class)"
17570
17571 \end_inset
17572
17573  __at
17574 \begin_inset LatexCommand index
17575 name "at"
17576
17577 \end_inset
17578
17579
17580 \begin_inset LatexCommand index
17581 name "\\_\\_at"
17582
17583 \end_inset
17584
17585 (0x7f00) buf[0x100];
17586 \begin_inset LatexCommand index
17587 name "Aligned array"
17588
17589 \end_inset
17590
17591
17592 \newline
17593 unsigned char head, tail;\InsetSpace ~
17594 \InsetSpace ~
17595 \InsetSpace ~
17596 \InsetSpace ~
17597 \InsetSpace ~
17598 \InsetSpace ~
17599 \InsetSpace ~
17600 \InsetSpace ~
17601 \InsetSpace ~
17602 \InsetSpace ~
17603 \InsetSpace ~
17604 \InsetSpace ~
17605 \InsetSpace ~
17606 \InsetSpace ~
17607 \InsetSpace ~
17608 \InsetSpace ~
17609 \InsetSpace ~
17610 /* if interrupts
17611 \begin_inset LatexCommand index
17612 name "interrupt"
17613
17614 \end_inset
17615
17616  are involved see
17617 \newline
17618 \InsetSpace ~
17619 \InsetSpace ~
17620 \InsetSpace ~
17621 \InsetSpace ~
17622 \InsetSpace ~
17623 \InsetSpace ~
17624 \InsetSpace ~
17625 \InsetSpace ~
17626 \InsetSpace ~
17627 \InsetSpace ~
17628 \InsetSpace ~
17629 \InsetSpace ~
17630 \InsetSpace ~
17631 \InsetSpace ~
17632 \InsetSpace ~
17633 \InsetSpace ~
17634 \InsetSpace ~
17635 \InsetSpace ~
17636 \InsetSpace ~
17637 \InsetSpace ~
17638 \InsetSpace ~
17639 \InsetSpace ~
17640 \InsetSpace ~
17641 \InsetSpace ~
17642 \InsetSpace ~
17643 \InsetSpace ~
17644 \InsetSpace ~
17645 \InsetSpace ~
17646 \InsetSpace ~
17647 \InsetSpace ~
17648 \InsetSpace ~
17649 \InsetSpace ~
17650 \InsetSpace ~
17651 \InsetSpace ~
17652 \InsetSpace ~
17653 \InsetSpace ~
17654 \InsetSpace ~
17655 \InsetSpace ~
17656 \InsetSpace ~
17657 \InsetSpace ~
17658 \InsetSpace ~
17659 \InsetSpace ~
17660 \InsetSpace ~
17661 \InsetSpace ~
17662 \InsetSpace ~
17663 section 
17664 \begin_inset LatexCommand ref
17665 reference "sub:Common-interrupt-pitfall-volatile"
17666
17667 \end_inset
17668
17669  about
17670 \family default
17671  
17672 \family typewriter
17673 \series bold
17674 volatile
17675 \family default
17676 \series default
17677  
17678 \family typewriter
17679 */
17680 \newline
17681
17682 \newline
17683 void to_buffer( unsigned char c ) 
17684 \newline
17685 {
17686 \newline
17687 \InsetSpace ~
17688 \InsetSpace ~
17689 \InsetSpace ~
17690 \InsetSpace ~
17691 if( head != (unsigned char)(tail-1)
17692  )\InsetSpace ~
17693 /* cast
17694 \family default
17695  
17696 \family typewriter
17697 \series bold
17698 needed
17699 \family default
17700 \series default
17701  
17702 \family typewriter
17703 to avoid promotion
17704 \begin_inset LatexCommand index
17705 name "promotion to signed int"
17706
17707 \end_inset
17708
17709
17710 \begin_inset LatexCommand index
17711 name "type promotion"
17712
17713 \end_inset
17714
17715  to integer */
17716 \begin_inset Marginal
17717 status collapsed
17718
17719 \begin_layout Standard
17720
17721 \series bold
17722 \InsetSpace ~
17723 !
17724 \end_layout
17725
17726 \end_inset
17727
17728
17729 \newline
17730 \InsetSpace ~
17731 \InsetSpace ~
17732 \InsetSpace ~
17733 \InsetSpace ~
17734 \InsetSpace ~
17735 \InsetSpace ~
17736 \InsetSpace ~
17737 \InsetSpace ~
17738 buf[ head++ ] = c;\InsetSpace ~
17739 \InsetSpace ~
17740 \InsetSpace ~
17741 \InsetSpace ~
17742 \InsetSpace ~
17743 \InsetSpace ~
17744 \InsetSpace ~
17745 \InsetSpace ~
17746 \InsetSpace ~
17747 \InsetSpace ~
17748 \InsetSpace ~
17749 \InsetSpace ~
17750 \InsetSpace ~
17751 \InsetSpace ~
17752 \InsetSpace ~
17753 \InsetSpace ~
17754 /* access to a 256 byte aligned array */
17755 \newline
17756
17757 \end_layout
17758
17759 \begin_layout Standard
17760 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
17761  then a corresponding buffer.asm file is generated.
17762  We define a new function 
17763 \family typewriter
17764 to_buffer_asm()
17765 \family default
17766  in file buffer.c in which we cut and paste the generated code, removing
17767  unwanted comments and some ':'.
17768  Then add 
17769 \begin_inset Quotes sld
17770 \end_inset
17771
17772
17773 \series bold
17774 _asm
17775 \series default
17776
17777 \begin_inset Quotes srd
17778 \end_inset
17779
17780  and 
17781 \begin_inset Quotes sld
17782 \end_inset
17783
17784
17785 \series bold
17786 _endasm;
17787 \series default
17788
17789 \begin_inset Quotes srd
17790 \end_inset
17791
17792
17793 \begin_inset Foot
17794 status open
17795
17796 \begin_layout Standard
17797 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
17798  and for C-99 compatibility, the double-underscore form (__asm and __endasm)
17799  has to be used.
17800  The latter is also used in the library functions.
17801 \end_layout
17802
17803 \end_inset
17804
17805  to the beginning and the end of the function body:
17806 \end_layout
17807
17808 \begin_layout Verse
17809
17810 \family typewriter
17811 \size footnotesize
17812 /* With a cut and paste from the .asm file, we have something to start with.
17813 \newline
17814 \InsetSpace ~
17815 \InsetSpace ~
17816 \InsetSpace ~
17817 The
17818  function is not yet OK! (registers aren't saved) */ 
17819 \newline
17820 void to_buffer_asm(
17821  unsigned char c ) 
17822 \newline
17823
17824 \newline
17825 \InsetSpace ~
17826 \InsetSpace ~
17827 \InsetSpace ~
17828 \InsetSpace ~
17829 _asm
17830 \begin_inset LatexCommand index
17831 name "\\_asm"
17832
17833 \end_inset
17834
17835
17836 \begin_inset LatexCommand index
17837 name "\\_\\_asm"
17838
17839 \end_inset
17840
17841
17842 \newline
17843 \InsetSpace ~
17844 \InsetSpace ~
17845 \InsetSpace ~
17846 \InsetSpace ~
17847 mov\InsetSpace ~
17848 \InsetSpace ~
17849 r2,dpl 
17850 \newline
17851 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
17852 /* cast
17853 \family default
17854  
17855 \family typewriter
17856 \series bold
17857 needed
17858 \family default
17859 \series default
17860  
17861 \family typewriter
17862 to avoid promotion
17863 \begin_inset LatexCommand index
17864 name "promotion to signed int"
17865
17866 \end_inset
17867
17868
17869 \begin_inset LatexCommand index
17870 name "type promotion"
17871
17872 \end_inset
17873
17874  to integer */
17875 \newline
17876 \InsetSpace ~
17877 \InsetSpace ~
17878 \InsetSpace ~
17879 \InsetSpace ~
17880 mov\InsetSpace ~
17881 \InsetSpace ~
17882 a,_tail 
17883 \newline
17884 \InsetSpace ~
17885 \InsetSpace ~
17886 \InsetSpace ~
17887 \InsetSpace ~
17888 dec\InsetSpace ~
17889 \InsetSpace ~
17890
17891 \newline
17892 \InsetSpace ~
17893 \InsetSpace ~
17894 \InsetSpace ~
17895 \InsetSpace ~
17896 mov\InsetSpace ~
17897 \InsetSpace ~
17898 r3,a 
17899 \newline
17900 \InsetSpace ~
17901 \InsetSpace ~
17902 \InsetSpace ~
17903 \InsetSpace ~
17904 mov\InsetSpace ~
17905 \InsetSpace ~
17906 a,_head 
17907 \newline
17908 \InsetSpace ~
17909 \InsetSpace ~
17910 \InsetSpace ~
17911 \InsetSpace ~
17912 cjne a,ar3,00106$ 
17913 \newline
17914 \InsetSpace ~
17915 \InsetSpace ~
17916 \InsetSpace ~
17917 \InsetSpace ~
17918 ret
17919 \newline
17920 00106$:
17921  
17922 \newline
17923 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
17924 \begin_inset LatexCommand index
17925 name "Aligned array"
17926
17927 \end_inset
17928
17929
17930 \newline
17931 \InsetSpace ~
17932 \InsetSpace ~
17933 \InsetSpace ~
17934 \InsetSpace ~
17935 mov\InsetSpace ~
17936 \InsetSpace ~
17937 r3,_head 
17938 \newline
17939 \InsetSpace ~
17940 \InsetSpace ~
17941 \InsetSpace ~
17942 \InsetSpace ~
17943 inc\InsetSpace ~
17944 \InsetSpace ~
17945 _head 
17946 \newline
17947 \InsetSpace ~
17948 \InsetSpace ~
17949 \InsetSpace ~
17950 \InsetSpace ~
17951 mov\InsetSpace ~
17952 \InsetSpace ~
17953 dpl,r3 
17954 \newline
17955 \InsetSpace ~
17956 \InsetSpace ~
17957 \InsetSpace ~
17958 \InsetSpace ~
17959 mov\InsetSpace ~
17960 \InsetSpace ~
17961 dph,#(_buf >> 8) 
17962 \newline
17963 \InsetSpace ~
17964 \InsetSpace ~
17965 \InsetSpace ~
17966 \InsetSpace ~
17967 mov\InsetSpace ~
17968 \InsetSpace ~
17969 a,r2 
17970 \newline
17971 \InsetSpace ~
17972 \InsetSpace ~
17973 \InsetSpace ~
17974 \InsetSpace ~
17975 movx @dptr,a
17976  
17977 \newline
17978 00103$: 
17979 \newline
17980 \InsetSpace ~
17981 \InsetSpace ~
17982 \InsetSpace ~
17983 \InsetSpace ~
17984 ret
17985 \newline
17986 \InsetSpace ~
17987 \InsetSpace ~
17988 \InsetSpace ~
17989 \InsetSpace ~
17990 _endasm
17991 \begin_inset LatexCommand index
17992 name "\\_endasm"
17993
17994 \end_inset
17995
17996
17997 \begin_inset LatexCommand index
17998 name "\\_\\_endasm"
17999
18000 \end_inset
18001
18002 ;
18003 \newline
18004
18005 \end_layout
18006
18007 \begin_layout Standard
18008 The new file buffer.c should compile with only one warning about the unreferenced
18009  function argument 'c'.
18010  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
18011  (1) and finally have:
18012 \end_layout
18013
18014 \begin_layout Verse
18015
18016 \family typewriter
18017 \size footnotesize
18018 unsigned char __far __at(0x7f00) buf[0x100];
18019 \newline
18020 unsigned char head, tail;
18021 \newline
18022 #define
18023  USE_ASSEMBLY (1)
18024 \newline
18025
18026 \newline
18027 #if !USE_ASSEMBLY
18028 \newline
18029
18030 \newline
18031 void to_buffer( unsigned char c )
18032 \newline
18033 {
18034 \newline
18035 \InsetSpace ~
18036 \InsetSpace ~
18037 \InsetSpace ~
18038 \InsetSpace ~
18039 if(
18040  head != (unsigned char)(tail-1) )
18041 \newline
18042 \InsetSpace ~
18043 \InsetSpace ~
18044 \InsetSpace ~
18045 \InsetSpace ~
18046 \InsetSpace ~
18047 \InsetSpace ~
18048 \InsetSpace ~
18049 \InsetSpace ~
18050 buf[ head++ ] = c;
18051 \newline
18052 }
18053 \newline
18054
18055 \newline
18056 #else
18057 \newline
18058
18059 \newline
18060 void to_buffer(
18061  unsigned char c )
18062 \newline
18063 {
18064 \newline
18065 \InsetSpace ~
18066 \InsetSpace ~
18067 \InsetSpace ~
18068 \InsetSpace ~
18069 c; // to avoid warning: unreferenced function argument
18070 \newline
18071 \InsetSpace ~
18072 \InsetSpace ~
18073 \InsetSpace ~
18074 \InsetSpace ~
18075 _asm
18076 \begin_inset LatexCommand index
18077 name "\\_asm"
18078
18079 \end_inset
18080
18081
18082 \begin_inset LatexCommand index
18083 name "\\_\\_asm"
18084
18085 \end_inset
18086
18087
18088 \newline
18089 \InsetSpace ~
18090 \InsetSpace ~
18091 \InsetSpace ~
18092 \InsetSpace ~
18093 \InsetSpace ~
18094 \InsetSpace ~
18095 \InsetSpace ~
18096 \InsetSpace ~
18097 ; save used registers here.
18098  
18099 \newline
18100 \InsetSpace ~
18101 \InsetSpace ~
18102 \InsetSpace ~
18103 \InsetSpace ~
18104 \InsetSpace ~
18105 \InsetSpace ~
18106 \InsetSpace ~
18107 \InsetSpace ~
18108 ; If we were still using r2,r3 we would have to push them here.
18109  
18110 \newline
18111 ; if( head != (unsigned char)(tail-1) )
18112 \newline
18113 \InsetSpace ~
18114 \InsetSpace ~
18115 \InsetSpace ~
18116 \InsetSpace ~
18117 \InsetSpace ~
18118 \InsetSpace ~
18119 \InsetSpace ~
18120 \InsetSpace ~
18121 mov\InsetSpace ~
18122  a,_tail
18123 \newline
18124 \InsetSpace ~
18125 \InsetSpace ~
18126 \InsetSpace ~
18127 \InsetSpace ~
18128 \InsetSpace ~
18129 \InsetSpace ~
18130 \InsetSpace ~
18131 \InsetSpace ~
18132 dec\InsetSpace ~
18133  a
18134 \newline
18135 \InsetSpace ~
18136 \InsetSpace ~
18137 \InsetSpace ~
18138 \InsetSpace ~
18139 \InsetSpace ~
18140 \InsetSpace ~
18141 \InsetSpace ~
18142 \InsetSpace ~
18143 xrl\InsetSpace ~
18144  a,_head
18145 \newline
18146 \InsetSpace ~
18147 \InsetSpace ~
18148 \InsetSpace ~
18149 \InsetSpace ~
18150 \InsetSpace ~
18151 \InsetSpace ~
18152 \InsetSpace ~
18153 \InsetSpace ~
18154 ; we
18155  could do an ANL a,#0x0f here to use a smaller buffer (see below)
18156 \newline
18157 \InsetSpace ~
18158 \InsetSpace ~
18159 \InsetSpace ~
18160 \InsetSpace ~
18161 \InsetSpace ~
18162 \InsetSpace ~
18163 \InsetSpace ~
18164 \InsetSpace ~
18165 jz\InsetSpace ~
18166 \InsetSpace ~
18167  t_b_end$
18168 \newline
18169 \InsetSpace ~
18170 \InsetSpace ~
18171 \InsetSpace ~
18172 \InsetSpace ~
18173 \InsetSpace ~
18174 \InsetSpace ~
18175 \InsetSpace ~
18176 \InsetSpace ~
18177 ;
18178 \newline
18179 ;
18180  buf[ head++ ] = c;
18181 \newline
18182 \InsetSpace ~
18183 \InsetSpace ~
18184 \InsetSpace ~
18185 \InsetSpace ~
18186 \InsetSpace ~
18187 \InsetSpace ~
18188 \InsetSpace ~
18189 \InsetSpace ~
18190 mov\InsetSpace ~
18191  a,dpl \InsetSpace ~
18192 \InsetSpace ~
18193 \InsetSpace ~
18194 \InsetSpace ~
18195 \InsetSpace ~
18196 \InsetSpace ~
18197 \InsetSpace ~
18198 ; dpl holds lower byte of function argument
18199 \newline
18200 \InsetSpace ~
18201 \InsetSpace ~
18202 \InsetSpace ~
18203 \InsetSpace ~
18204 \InsetSpace ~
18205 \InsetSpace ~
18206 \InsetSpace ~
18207 \InsetSpace ~
18208 mov\InsetSpace ~
18209
18210  dpl,_head \InsetSpace ~
18211 \InsetSpace ~
18212 \InsetSpace ~
18213 ; buf is 0x100 byte aligned so head can be used directly
18214 \newline
18215 \InsetSpace ~
18216 \InsetSpace ~
18217 \InsetSpace ~
18218 \InsetSpace ~
18219 \InsetSpace ~
18220 \InsetSpace ~
18221 \InsetSpace ~
18222 \InsetSpace ~
18223 mov\InsetSpace ~
18224  dph,#(_bu
18225 f>>8)
18226 \newline
18227 \InsetSpace ~
18228 \InsetSpace ~
18229 \InsetSpace ~
18230 \InsetSpace ~
18231 \InsetSpace ~
18232 \InsetSpace ~
18233 \InsetSpace ~
18234 \InsetSpace ~
18235 movx @dptr,a
18236 \newline
18237 \InsetSpace ~
18238 \InsetSpace ~
18239 \InsetSpace ~
18240 \InsetSpace ~
18241 \InsetSpace ~
18242 \InsetSpace ~
18243 \InsetSpace ~
18244 \InsetSpace ~
18245 inc \InsetSpace ~
18246 _head
18247 \newline
18248 \InsetSpace ~
18249 \InsetSpace ~
18250 \InsetSpace ~
18251 \InsetSpace ~
18252 \InsetSpace ~
18253 \InsetSpace ~
18254 \InsetSpace ~
18255 \InsetSpace ~
18256 ; we could do an ANL _head,#0x0f here to use a
18257  smaller buffer (see above)
18258 \newline
18259 t_b_end$:
18260 \newline
18261 \InsetSpace ~
18262 \InsetSpace ~
18263 \InsetSpace ~
18264 \InsetSpace ~
18265 \InsetSpace ~
18266 \InsetSpace ~
18267 \InsetSpace ~
18268 \InsetSpace ~
18269 ; restore used registers here 
18270 \newline
18271 \InsetSpace ~
18272 \InsetSpace ~
18273 \InsetSpace ~
18274 \InsetSpace ~
18275 _endasm
18276 \begin_inset LatexCommand index
18277 name "\\_endasm"
18278
18279 \end_inset
18280
18281
18282 \begin_inset LatexCommand index
18283 name "\\_\\_endasm"
18284
18285 \end_inset
18286
18287 ;
18288 \newline
18289 }
18290 \newline
18291 #endif
18292 \end_layout
18293
18294 \begin_layout Standard
18295 The inline assembler code can contain any valid code understood by the assembler
18296 , this includes any assembler directives and comment lines.
18297  The assembler does not like some characters like ':' or ''' in comments.
18298  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
18299 \begin_inset LatexCommand index
18300 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
18301
18302 \end_inset
18303
18304
18305 \begin_inset LatexCommand index
18306 name "Assembler documentation"
18307
18308 \end_inset
18309
18310  or online at 
18311 \begin_inset LatexCommand url
18312 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html"
18313
18314 \end_inset
18315
18316 \InsetSpace ~
18317 .
18318 \end_layout
18319
18320 \begin_layout Standard
18321 The compiler does not do any validation of the code within the 
18322 \family typewriter
18323 _asm
18324 \begin_inset LatexCommand index
18325 name "\\_asm"
18326
18327 \end_inset
18328
18329
18330 \begin_inset LatexCommand index
18331 name "\\_\\_asm"
18332
18333 \end_inset
18334
18335  ...
18336  _endasm
18337 \size footnotesize
18338
18339 \begin_inset LatexCommand index
18340 name "\\_endasm"
18341
18342 \end_inset
18343
18344
18345 \begin_inset LatexCommand index
18346 name "\\_\\_endasm"
18347
18348 \end_inset
18349
18350
18351 \size default
18352 ;
18353 \family default
18354  keyword pair.
18355  Specifically it will not know which registers are used and thus register
18356  pushing/popping
18357 \begin_inset LatexCommand index
18358 name "push/pop"
18359
18360 \end_inset
18361
18362  has to be done manually.
18363  
18364 \end_layout
18365
18366 \begin_layout Standard
18367 It is recommended that each assembly instruction (including labels) be placed
18368  in a separate line (as the example shows).
18369  When the -
18370 \begin_inset ERT
18371 status collapsed
18372
18373 \begin_layout Standard
18374
18375
18376 \backslash
18377 /
18378 \end_layout
18379
18380 \end_inset
18381
18382 -
18383 \emph on
18384 peep-asm
18385 \begin_inset LatexCommand index
18386 name "-\\/-peep-asm"
18387
18388 \end_inset
18389
18390
18391 \emph default
18392  command line option is used, the inline assembler code will be passed through
18393  the peephole optimizer
18394 \begin_inset LatexCommand index
18395 name "Peephole optimizer"
18396
18397 \end_inset
18398
18399 .
18400  There are only a few (if any) cases where this option makes sense, it might
18401  cause some unexpected changes in the inline assembler code.
18402  Please go through the peephole optimizer rules defined in file 
18403 \emph on
18404 SDCCpeeph.def
18405 \emph default
18406  before using this option.
18407 \end_layout
18408
18409 \begin_layout Subsection
18410 Naked Functions
18411 \begin_inset LatexCommand label
18412 name "sub:Naked-Functions"
18413
18414 \end_inset
18415
18416
18417 \begin_inset LatexCommand index
18418 name "Naked functions"
18419
18420 \end_inset
18421
18422
18423 \end_layout
18424
18425 \begin_layout Standard
18426 A special keyword may be associated with a function declaring it as 
18427 \emph on
18428 _naked
18429 \begin_inset LatexCommand index
18430 name "\\_naked"
18431
18432 \end_inset
18433
18434
18435 \begin_inset LatexCommand index
18436 name "\\_\\_naked"
18437
18438 \end_inset
18439
18440 .
18441
18442 \emph default
18443  The 
18444 \emph on
18445 _naked
18446 \emph default
18447  function modifier attribute prevents the compiler from generating prologue
18448 \begin_inset LatexCommand index
18449 name "function prologue"
18450
18451 \end_inset
18452
18453  and epilogue
18454 \begin_inset LatexCommand index
18455 name "function epilogue"
18456
18457 \end_inset
18458
18459  code for that function.
18460  This means that the user is entirely responsible for such things as saving
18461  any registers that may need to be preserved, selecting the proper register
18462  bank, generating the 
18463 \emph on
18464 return
18465 \emph default
18466  instruction at the end, etc.
18467  Practically, this means that the contents of the function must be written
18468  in inline assembler.
18469  This is particularly useful for interrupt functions, which can have a large
18470  (and often unnecessary) prologue/epilogue.
18471  For example, compare the code generated by these two functions:
18472 \end_layout
18473
18474 \begin_layout Verse
18475
18476 \family typewriter
18477 volatile
18478 \begin_inset LatexCommand index
18479 name "volatile"
18480
18481 \end_inset
18482
18483  data unsigned char counter;
18484 \newline
18485
18486 \newline
18487 void simpleInterrupt(void) __interrupt
18488 \begin_inset LatexCommand index
18489 name "interrupt"
18490
18491 \end_inset
18492
18493
18494 \begin_inset LatexCommand index
18495 name "\\_\\_interrupt"
18496
18497 \end_inset
18498
18499  (1)
18500 \newline
18501 {
18502 \newline
18503 \InsetSpace ~
18504 \InsetSpace ~
18505 \InsetSpace ~
18506 \InsetSpace ~
18507 counter++;
18508 \newline
18509 }
18510 \newline
18511
18512 \newline
18513 void nakedInterrupt(void) __interrupt (2) __naked
18514 \newline
18515 {
18516 \newline
18517 \InsetSpace ~
18518 \InsetSpace ~
18519 \InsetSpace ~
18520 \InsetSpace ~
18521 _asm
18522 \begin_inset LatexCommand index
18523 name "\\_asm"
18524
18525 \end_inset
18526
18527
18528 \begin_inset LatexCommand index
18529 name "\\_\\_asm"
18530
18531 \end_inset
18532
18533
18534 \newline
18535 \InsetSpace ~
18536 \InsetSpace ~
18537 \InsetSpace ~
18538 \InsetSpace ~
18539 \InsetSpace ~
18540 \InsetSpace ~
18541 inc\InsetSpace ~
18542 \InsetSpace ~
18543 \InsetSpace ~
18544 \InsetSpace ~
18545 \InsetSpace ~
18546 _counter ; does not change flags, no need to save psw
18547 \newline
18548 \InsetSpace ~
18549 \InsetSpace ~
18550 \InsetSpace ~
18551 \InsetSpace ~
18552 \InsetSpace ~
18553 \InsetSpace ~
18554 reti\InsetSpace ~
18555 \InsetSpace ~
18556 \InsetSpace ~
18557 \InsetSpace ~
18558 ; MUST explicitly
18559  include ret or reti in _naked function.
18560 \newline
18561 \InsetSpace ~
18562 \InsetSpace ~
18563 \InsetSpace ~
18564 \InsetSpace ~
18565 _endasm
18566 \begin_inset LatexCommand index
18567 name "\\_endasm"
18568
18569 \end_inset
18570
18571
18572 \begin_inset LatexCommand index
18573 name "\\_\\_endasm"
18574
18575 \end_inset
18576
18577 ;
18578 \newline
18579 }
18580 \end_layout
18581
18582 \begin_layout Standard
18583 For an 8051 target, the generated simpleInterrupt looks like:
18584 \end_layout
18585
18586 \begin_layout Verse
18587
18588 \family typewriter
18589 Note, this is an
18590 \family default
18591  
18592 \family typewriter
18593 \emph on
18594 outdated
18595 \family default
18596 \emph default
18597  
18598 \family typewriter
18599 example, recent versions of SDCC generate
18600 \newline
18601 the
18602 \family default
18603  
18604 \family typewriter
18605 \emph on
18606 same
18607 \family default
18608 \emph default
18609  
18610 \family typewriter
18611 code for simpleInterrupt() and nakedInterrupt()!
18612 \newline
18613
18614 \newline
18615 _simpleInterrupt:
18616 \newline
18617 \InsetSpace ~
18618 \InsetSpace ~
18619 \InsetSpace ~
18620 \InsetSpace ~
18621 push\InsetSpace ~
18622 \InsetSpace ~
18623 \InsetSpace ~
18624 \InsetSpace ~
18625 acc
18626 \newline
18627 \InsetSpace ~
18628 \InsetSpace ~
18629 \InsetSpace ~
18630 \InsetSpace ~
18631 push\InsetSpace ~
18632 \InsetSpace ~
18633 \InsetSpace ~
18634 \InsetSpace ~
18635 b
18636 \newline
18637 \InsetSpace ~
18638 \InsetSpace ~
18639 \InsetSpace ~
18640 \InsetSpace ~
18641 pus
18642 h\InsetSpace ~
18643 \InsetSpace ~
18644 \InsetSpace ~
18645 \InsetSpace ~
18646 dpl
18647 \newline
18648 \InsetSpace ~
18649 \InsetSpace ~
18650 \InsetSpace ~
18651 \InsetSpace ~
18652 push\InsetSpace ~
18653 \InsetSpace ~
18654 \InsetSpace ~
18655 \InsetSpace ~
18656 dph
18657 \newline
18658 \InsetSpace ~
18659 \InsetSpace ~
18660 \InsetSpace ~
18661 \InsetSpace ~
18662 push\InsetSpace ~
18663 \InsetSpace ~
18664 \InsetSpace ~
18665 \InsetSpace ~
18666 psw
18667 \newline
18668 \InsetSpace ~
18669 \InsetSpace ~
18670 \InsetSpace ~
18671 \InsetSpace ~
18672 mov\InsetSpace ~
18673 \InsetSpace ~
18674 \InsetSpace ~
18675 \InsetSpace ~
18676 \InsetSpace ~
18677 psw,#0x00
18678 \newline
18679 \InsetSpace ~
18680 \InsetSpace ~
18681 \InsetSpace ~
18682 \InsetSpace ~
18683 inc\InsetSpace ~
18684 \InsetSpace ~
18685 \InsetSpace ~
18686 \InsetSpace ~
18687 \InsetSpace ~
18688 _counter
18689 \newline
18690 \InsetSpace ~
18691 \InsetSpace ~
18692 \InsetSpace ~
18693 \InsetSpace ~
18694 pop\InsetSpace ~
18695 \InsetSpace ~
18696 \InsetSpace ~
18697 \InsetSpace ~
18698 \InsetSpace ~
18699 psw
18700 \newline
18701 \InsetSpace ~
18702 \InsetSpace ~
18703 \InsetSpace ~
18704 \InsetSpace ~
18705 pop\InsetSpace ~
18706 \InsetSpace ~
18707 \InsetSpace ~
18708 \InsetSpace ~
18709 \InsetSpace ~
18710 dph
18711 \newline
18712 \InsetSpace ~
18713 \InsetSpace ~
18714 \InsetSpace ~
18715 \InsetSpace ~
18716 pop\InsetSpace ~
18717 \InsetSpace ~
18718 \InsetSpace ~
18719 \InsetSpace ~
18720 \InsetSpace ~
18721 dpl
18722 \newline
18723 \InsetSpace ~
18724 \InsetSpace ~
18725 \InsetSpace ~
18726 \InsetSpace ~
18727 pop\InsetSpace ~
18728 \InsetSpace ~
18729 \InsetSpace ~
18730 \InsetSpace ~
18731 \InsetSpace ~
18732 b
18733 \newline
18734 \InsetSpace ~
18735 \InsetSpace ~
18736 \InsetSpace ~
18737 \InsetSpace ~
18738 pop\InsetSpace ~
18739 \InsetSpace ~
18740 \InsetSpace ~
18741 \InsetSpace ~
18742 \InsetSpace ~
18743 acc
18744 \newline
18745 \InsetSpace ~
18746 \InsetSpace ~
18747 \InsetSpace ~
18748 \InsetSpace ~
18749 reti
18750 \end_layout
18751
18752 \begin_layout Standard
18753 whereas nakedInterrupt looks like:
18754 \end_layout
18755
18756 \begin_layout Verse
18757
18758 \family typewriter
18759 _nakedInterrupt:
18760 \newline
18761 \InsetSpace ~
18762 \InsetSpace ~
18763 \InsetSpace ~
18764 \InsetSpace ~
18765 inc\InsetSpace ~
18766 \InsetSpace ~
18767 \InsetSpace ~
18768 \InsetSpace ~
18769 _counter ; does not change flags, no need to save psw
18770 \newline
18771 \InsetSpace ~
18772 \InsetSpace ~
18773 \InsetSpace ~
18774 \InsetSpace ~
18775 reti\InsetSpace ~
18776 \InsetSpace ~
18777 \InsetSpace ~
18778 \InsetSpace ~
18779 \InsetSpace ~
18780 \InsetSpace ~
18781 \InsetSpace ~
18782 \InsetSpace ~
18783 \InsetSpace ~
18784 \InsetSpace ~
18785 \InsetSpace ~
18786 \InsetSpace ~
18787 ;
18788  MUST explicitly include ret or reti in _naked function
18789 \end_layout
18790
18791 \begin_layout Standard
18792 The related directive #pragma exclude
18793 \begin_inset LatexCommand index
18794 name "\\#pragma exclude"
18795
18796 \end_inset
18797
18798  allows a more fine grained control over pushing & popping
18799 \begin_inset LatexCommand index
18800 name "push/pop"
18801
18802 \end_inset
18803
18804  the registers.
18805 \end_layout
18806
18807 \begin_layout Standard
18808 While there is nothing preventing you from writing C code inside a 
18809 \family typewriter
18810 _naked
18811 \family default
18812  function, there are many ways to shoot yourself in the foot doing this,
18813  and it is recommended that you stick to inline assembler.
18814 \end_layout
18815
18816 \begin_layout Subsection
18817 Use of Labels within Inline Assembler
18818 \end_layout
18819
18820 \begin_layout Standard
18821 SDCC allows the use of in-line assembler with a few restrictions regarding
18822  labels.
18823  All labels defined within inline assembler code have to be of the form
18824  
18825 \emph on
18826 nnnnn$
18827 \emph default
18828  where nnnnn is a number less than 100 (which implies a limit of utmost
18829  100 inline assembler labels 
18830 \emph on
18831 per function
18832 \emph default
18833 \noun on
18834 )
18835 \noun default
18836 .
18837 \begin_inset Foot
18838 status open
18839
18840 \begin_layout Standard
18841 This is a slightly more stringent rule than absolutely necessary, but stays
18842  always on the safe side.
18843  Labels in the form of nnnnn$ are local labels in the assembler, locality
18844  of which is confined within two labels of the standard form.
18845  The compiler uses the same form for labels within a function (but starting
18846  from nnnnn=00100); and places always a standard label at the beginning
18847  of a function, thus limiting the locality of labels within the scope of
18848  the function.
18849  So, if the inline assembler part would be embedded into C-code, an improperly
18850  placed non-local label in the assembler would break up the reference space
18851  for labels created by the compiler for the C-code, leading to an assembling
18852  error.
18853 \end_layout
18854
18855 \begin_layout Standard
18856 The numeric part of local labels does not need to have 5 digits (although
18857  this is the form of labels output by the compiler), any valid integer will
18858  do.
18859  Please refer to the assemblers documentation for further details.
18860 \end_layout
18861
18862 \end_inset
18863
18864  
18865 \end_layout
18866
18867 \begin_layout Verse
18868
18869 \family typewriter
18870 _asm
18871 \begin_inset LatexCommand index
18872 name "\\_asm"
18873
18874 \end_inset
18875
18876
18877 \begin_inset LatexCommand index
18878 name "\\_\\_asm"
18879
18880 \end_inset
18881
18882  
18883 \newline
18884 \InsetSpace ~
18885 \InsetSpace ~
18886 \InsetSpace ~
18887 \InsetSpace ~
18888 mov\InsetSpace ~
18889 \InsetSpace ~
18890 \InsetSpace ~
18891 \InsetSpace ~
18892 \InsetSpace ~
18893 b,#10 
18894 \newline
18895 00001$: 
18896 \newline
18897 \InsetSpace ~
18898 \InsetSpace ~
18899 \InsetSpace ~
18900 \InsetSpace ~
18901 djnz\InsetSpace ~
18902 \InsetSpace ~
18903 \InsetSpace ~
18904 \InsetSpace ~
18905 b,00001$ 
18906 \newline
18907 _endasm
18908 \begin_inset LatexCommand index
18909 name "\\_endasm"
18910
18911 \end_inset
18912
18913
18914 \begin_inset LatexCommand index
18915 name "\\_\\_endasm"
18916
18917 \end_inset
18918
18919  ;
18920 \end_layout
18921
18922 \begin_layout Standard
18923 Inline assembler code cannot reference any C-labels, however it can reference
18924  labels
18925 \begin_inset LatexCommand index
18926 name "Labels"
18927
18928 \end_inset
18929
18930  defined by the inline assembler, e.g.:
18931 \end_layout
18932
18933 \begin_layout Verse
18934
18935 \family typewriter
18936 foo() { 
18937 \newline
18938 \InsetSpace ~
18939 \InsetSpace ~
18940 \InsetSpace ~
18941 \InsetSpace ~
18942 /* some c code */ 
18943 \newline
18944 \InsetSpace ~
18945 \InsetSpace ~
18946 \InsetSpace ~
18947 \InsetSpace ~
18948 _asm 
18949 \newline
18950 \InsetSpace ~
18951 \InsetSpace ~
18952 \InsetSpace ~
18953 \InsetSpace ~
18954 \InsetSpace ~
18955 \InsetSpace ~
18956 ; some assembler code 
18957 \newline
18958 \InsetSpace ~
18959 \InsetSpace ~
18960 \InsetSpace ~
18961 \InsetSpace ~
18962 \InsetSpace ~
18963 \InsetSpace ~
18964 ljmp 0003$ 
18965 \newline
18966 \InsetSpace ~
18967 \InsetSpace ~
18968 \InsetSpace ~
18969 \InsetSpace ~
18970 _endasm;
18971  
18972 \newline
18973 \InsetSpace ~
18974 \InsetSpace ~
18975 \InsetSpace ~
18976 \InsetSpace ~
18977 /* some more c code */ 
18978 \newline
18979 clabel:\InsetSpace ~
18980 \InsetSpace ~
18981 /* inline assembler cannot reference this
18982  label */ 
18983 \begin_inset Foot
18984 status open
18985
18986 \begin_layout Standard
18987 Here, the C-label 
18988 \family typewriter
18989 clabel
18990 \family default
18991  is translated by the compiler into a local label, so the locality of labels
18992  within the function is not broken.
18993 \end_layout
18994
18995 \end_inset
18996
18997
18998 \newline
18999 \InsetSpace ~
19000 \InsetSpace ~
19001 \InsetSpace ~
19002 \InsetSpace ~
19003 _asm
19004 \newline
19005 \InsetSpace ~
19006 \InsetSpace ~
19007 \InsetSpace ~
19008 \InsetSpace ~
19009 0003$: ;label (can be referenced by inline assembler only) 
19010 \newline
19011 \InsetSpace ~
19012 \InsetSpace ~
19013 \InsetSpace ~
19014 \InsetSpace ~
19015 _endasm
19016 \begin_inset LatexCommand index
19017 name "\\_endasm"
19018
19019 \end_inset
19020
19021
19022 \begin_inset LatexCommand index
19023 name "\\_\\_endasm"
19024
19025 \end_inset
19026
19027  ; 
19028 \newline
19029 \InsetSpace ~
19030 \InsetSpace ~
19031 \InsetSpace ~
19032 \InsetSpace ~
19033 /* some more c code */
19034 \newline
19035 }
19036 \end_layout
19037
19038 \begin_layout Standard
19039 In other words inline assembly code can access labels defined in inline
19040  assembly within the scope of the function.
19041  The same goes the other way, i.e.
19042  labels defines in inline assembly can not be accessed by C statements.
19043 \end_layout
19044
19045 \begin_layout Section
19046 Interfacing with Assembler Code
19047 \begin_inset LatexCommand index
19048 name "Assembler routines"
19049
19050 \end_inset
19051
19052
19053 \end_layout
19054
19055 \begin_layout Subsection
19056 Global Registers used for Parameter Passing
19057 \begin_inset LatexCommand index
19058 name "Parameter passing"
19059
19060 \end_inset
19061
19062
19063 \end_layout
19064
19065 \begin_layout Standard
19066 The compiler always uses the global registers 
19067 \emph on
19068 DPL, DPH
19069 \begin_inset LatexCommand index
19070 name "DPTR, DPH, DPL"
19071
19072 \end_inset
19073
19074
19075 \begin_inset LatexCommand index
19076 name "DPTR"
19077
19078 \end_inset
19079
19080 , B
19081 \begin_inset LatexCommand index
19082 name "B (mcs51, ds390 register)"
19083
19084 \end_inset
19085
19086
19087 \emph default
19088  and 
19089 \emph on
19090 ACC
19091 \begin_inset LatexCommand index
19092 name "ACC (mcs51, ds390 register)"
19093
19094 \end_inset
19095
19096
19097 \emph default
19098  to pass the first (non-bit) parameter to a function, and also to pass the
19099  return value 
19100 \begin_inset LatexCommand index
19101 name "return value"
19102
19103 \end_inset
19104
19105 of function; according to the following scheme: one byte return value in
19106  
19107 \emph on
19108 DPL
19109 \emph default
19110 , two byte value in 
19111 \emph on
19112 DPL
19113 \emph default
19114  (LSB) and 
19115 \emph on
19116 DPH
19117 \emph default
19118  (MSB).
19119  three byte values (generic pointers) in 
19120 \emph on
19121 DPH
19122 \emph default
19123
19124 \emph on
19125 DPL
19126 \emph default
19127  and 
19128 \emph on
19129 B
19130 \emph default
19131 , and four byte values in 
19132 \emph on
19133 DPH
19134 \emph default
19135
19136 \emph on
19137 DPL
19138 \emph default
19139
19140 \emph on
19141 B
19142 \emph default
19143  and 
19144 \emph on
19145 ACC
19146 \emph default
19147 .
19148  Generic pointers
19149 \begin_inset LatexCommand index
19150 name "generic pointer"
19151
19152 \end_inset
19153
19154  contain type of accessed memory in 
19155 \emph on
19156 B
19157 \emph default
19158
19159 \series bold
19160 0x00
19161 \series default
19162  -- xdata/far, 
19163 \series bold
19164 0x40
19165 \series default
19166  -- idata/near -- , 
19167 \series bold
19168 0x60
19169 \series default
19170  -- pdata, 
19171 \series bold
19172 0x80
19173 \series default
19174  -- code
19175 \begin_inset Note Note
19176 status collapsed
19177
19178 \begin_layout Standard
19179 This might not be the case of certain memory models (medium???)
19180 \end_layout
19181
19182 \end_inset
19183
19184 .
19185 \end_layout
19186
19187 \begin_layout Standard
19188 The second parameter onwards is either allocated on the stack (for reentrant
19189  routines or if -
19190 \begin_inset ERT
19191 status collapsed
19192
19193 \begin_layout Standard
19194
19195
19196 \backslash
19197 /
19198 \end_layout
19199
19200 \end_inset
19201
19202 -stack-auto is used) or in data/xdata memory (depending on the memory model).
19203 \end_layout
19204
19205 \begin_layout Standard
19206 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
19207  space for reentrant functions or allocated directly in bit memory otherwise.
19208 \end_layout
19209
19210 \begin_layout Standard
19211 Functions (with two or more parameters or bit parameters) that are called
19212  through function pointers
19213 \begin_inset LatexCommand index
19214 name "function pointers"
19215
19216 \end_inset
19217
19218  must therefor be reentrant so the compiler knows how to pass the parameters.
19219 \end_layout
19220
19221 \begin_layout Subsection
19222 Registers usage
19223 \end_layout
19224
19225 \begin_layout Standard
19226 Unless the called function is declared as 
19227 \family typewriter
19228 _naked
19229 \family default
19230
19231 \begin_inset LatexCommand index
19232 name "naked"
19233
19234 \end_inset
19235
19236 , or the -
19237 \begin_inset ERT
19238 status collapsed
19239
19240 \begin_layout Standard
19241
19242
19243 \backslash
19244 /
19245 \end_layout
19246
19247 \end_inset
19248
19249 -callee-saves
19250 \begin_inset LatexCommand index
19251 name "-\\/-callee-saves"
19252
19253 \end_inset
19254
19255 /-
19256 \begin_inset ERT
19257 status collapsed
19258
19259 \begin_layout Standard
19260
19261
19262 \backslash
19263 /
19264 \end_layout
19265
19266 \end_inset
19267
19268 -all-callee-saves command line option or the corresponding callee_saves
19269  pragma are used, the caller will save the registers (
19270 \emph on
19271 R0-R7
19272 \emph default
19273 ) around the call, so the called function can destroy they content freely.
19274 \end_layout
19275
19276 \begin_layout Standard
19277 If the called function is not declared as 
19278 \family typewriter
19279 _naked
19280 \family default
19281 , the caller will swap register banks around the call, if caller and callee
19282  use different register banks (having them defined by the 
19283 \family typewriter
19284 _using
19285 \family default
19286  modifier).
19287  
19288 \end_layout
19289
19290 \begin_layout Standard
19291 The called function can also use 
19292 \emph on
19293 DPL
19294 \emph default
19295
19296 \emph on
19297 DPH
19298 \emph default
19299
19300 \emph on
19301 B
19302 \emph default
19303  and 
19304 \emph on
19305 ACC
19306 \emph default
19307  observing that they are used for parameter/return value passing.
19308 \end_layout
19309
19310 \begin_layout Subsection
19311 Assembler Routine (non-reentrant)
19312 \end_layout
19313
19314 \begin_layout Standard
19315 In the following example
19316 \begin_inset LatexCommand index
19317 name "reentrant"
19318
19319 \end_inset
19320
19321
19322 \begin_inset LatexCommand index
19323 name "Assembler routines (non-reentrant)"
19324
19325 \end_inset
19326
19327  the function c_func calls an assembler routine asm_func, which takes two
19328  parameters
19329 \begin_inset LatexCommand index
19330 name "function parameter"
19331
19332 \end_inset
19333
19334 .
19335 \end_layout
19336
19337 \begin_layout Verse
19338
19339 \family typewriter
19340 extern int asm_func(unsigned char, unsigned char);
19341 \newline
19342
19343 \newline
19344 int c_func (unsigned char
19345  i, unsigned char j)
19346 \newline
19347 {
19348 \newline
19349 \InsetSpace ~
19350 \InsetSpace ~
19351 \InsetSpace ~
19352 \InsetSpace ~
19353 return asm_func(i,j);
19354 \newline
19355 }
19356 \newline
19357
19358 \newline
19359 int main()
19360 \newline
19361 {
19362 \newline
19363 \InsetSpace ~
19364 \InsetSpace ~
19365 \InsetSpace ~
19366 \InsetSpace ~
19367 return c_func(10,9);
19368 \newline
19369 }
19370 \end_layout
19371
19372 \begin_layout Standard
19373 The corresponding assembler function is:
19374 \end_layout
19375
19376 \begin_layout Verse
19377
19378 \family typewriter
19379 .globl _asm_func_PARM_2 
19380 \newline
19381 \InsetSpace ~
19382 \InsetSpace ~
19383 \InsetSpace ~
19384 \InsetSpace ~
19385 \InsetSpace ~
19386 \InsetSpace ~
19387 \InsetSpace ~
19388 \InsetSpace ~
19389 .globl _asm_func 
19390 \newline
19391 \InsetSpace ~
19392 \InsetSpace ~
19393 \InsetSpace ~
19394 \InsetSpace ~
19395 \InsetSpace ~
19396 \InsetSpace ~
19397 \InsetSpace ~
19398 \InsetSpace ~
19399 .area OSEG 
19400 \newline
19401 _asm_func_PARM_2:
19402 \newline
19403 \InsetSpace ~
19404 \InsetSpace ~
19405 \InsetSpace ~
19406 \InsetSpace ~
19407 \InsetSpace ~
19408 \InsetSpace ~
19409 \InsetSpace ~
19410 \InsetSpace ~
19411 .ds   
19412  1 
19413 \newline
19414 \InsetSpace ~
19415 \InsetSpace ~
19416 \InsetSpace ~
19417 \InsetSpace ~
19418 \InsetSpace ~
19419 \InsetSpace ~
19420 \InsetSpace ~
19421 \InsetSpace ~
19422 .area CSEG 
19423 \newline
19424 _asm_func: 
19425 \newline
19426 \InsetSpace ~
19427 \InsetSpace ~
19428 \InsetSpace ~
19429 \InsetSpace ~
19430 \InsetSpace ~
19431 \InsetSpace ~
19432 \InsetSpace ~
19433 \InsetSpace ~
19434 mov\InsetSpace ~
19435 \InsetSpace ~
19436 \InsetSpace ~
19437 \InsetSpace ~
19438 a,dpl 
19439 \newline
19440 \InsetSpace ~
19441 \InsetSpace ~
19442 \InsetSpace ~
19443 \InsetSpace ~
19444 \InsetSpace ~
19445 \InsetSpace ~
19446 \InsetSpace ~
19447 \InsetSpace ~
19448 add\InsetSpace ~
19449 \InsetSpace ~
19450 \InsetSpace ~
19451 \InsetSpace ~
19452 a,_asm_func_PARM_2 
19453 \newline
19454 \InsetSpace ~
19455 \InsetSpace ~
19456 \InsetSpace ~
19457 \InsetSpace ~
19458 \InsetSpace ~
19459 \InsetSpace ~
19460 \InsetSpace ~
19461 \InsetSpace ~
19462 mov\InsetSpace ~
19463 \InsetSpace ~
19464 \InsetSpace ~
19465 \InsetSpace ~
19466 dpl,a 
19467 \newline
19468 \InsetSpace ~
19469 \InsetSpace ~
19470 \InsetSpace ~
19471 \InsetSpace ~
19472 \InsetSpace ~
19473 \InsetSpace ~
19474 \InsetSpace ~
19475 \InsetSpace ~
19476 mov\InsetSpace ~
19477 \InsetSpace ~
19478 \InsetSpace ~
19479 \InsetSpace ~
19480 dph
19481 \begin_inset LatexCommand index
19482 name "DPTR, DPH, DPL"
19483
19484 \end_inset
19485
19486 ,#0x00 
19487 \newline
19488 \InsetSpace ~
19489 \InsetSpace ~
19490 \InsetSpace ~
19491 \InsetSpace ~
19492 \InsetSpace ~
19493 \InsetSpace ~
19494 \InsetSpace ~
19495 \InsetSpace ~
19496 ret
19497 \end_layout
19498
19499 \begin_layout Standard
19500 The parameter naming convention is _<function_name>_PARM_<n>, where n is
19501  the parameter number starting from 1, and counting from the left.
19502  The first parameter is passed in 
19503 \emph on
19504 DPH
19505 \emph default
19506
19507 \emph on
19508 DPL
19509 \emph default
19510
19511 \emph on
19512 B
19513 \emph default
19514  and 
19515 \emph on
19516 ACC
19517 \emph default
19518  according to the description above.
19519  The variable name for the second parameter will be _<function_name>_PARM_2.
19520 \newline
19521
19522 \newline
19523 Assem
19524 ble the assembler routine with the following command:
19525 \newline
19526
19527 \newline
19528
19529 \family sans
19530 \series bold
19531 asx8051 -losg asmfunc.asm
19532 \newline
19533
19534 \newline
19535
19536 \family default
19537 \series default
19538 Then compile and link the assembler routine to the C source file with the
19539  following command:
19540 \newline
19541
19542 \newline
19543
19544 \family sans
19545 \series bold
19546 sdcc cfunc.c asmfunc.rel
19547 \end_layout
19548
19549 \begin_layout Subsection
19550 Assembler Routine (reentrant)
19551 \end_layout
19552
19553 \begin_layout Standard
19554 In this case
19555 \begin_inset LatexCommand index
19556 name "reentrant"
19557
19558 \end_inset
19559
19560
19561 \begin_inset LatexCommand index
19562 name "Assembler routines (reentrant)"
19563
19564 \end_inset
19565
19566  the second parameter
19567 \begin_inset LatexCommand index
19568 name "function parameter"
19569
19570 \end_inset
19571
19572  onwards will be passed on the stack, the parameters are pushed from right
19573  to left i.e.
19574  before the call the second leftmost parameter will be on the top of the
19575  stack (the leftmost parameter is passed in registers).
19576  Here is an example:
19577 \end_layout
19578
19579 \begin_layout Verse
19580
19581 \family typewriter
19582 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
19583 \newline
19584
19585 \newline
19586 int
19587  c_func (unsigned char i, unsigned char j, unsigned char k) reentrant 
19588 \newline
19589 {
19590  
19591 \newline
19592 \InsetSpace ~
19593 \InsetSpace ~
19594 \InsetSpace ~
19595 \InsetSpace ~
19596 return asm_func(i,j,k); 
19597 \newline
19598
19599 \newline
19600
19601 \newline
19602 int main() 
19603 \newline
19604
19605 \newline
19606 \InsetSpace ~
19607 \InsetSpace ~
19608 \InsetSpace ~
19609 \InsetSpace ~
19610 return c_func(10,9,8); 
19611 \newline
19612 }
19613 \end_layout
19614
19615 \begin_layout Standard
19616 The corresponding (unoptimized) assembler routine is:
19617 \end_layout
19618
19619 \begin_layout Verse
19620
19621 \family typewriter
19622 .globl _asm_func 
19623 \newline
19624 _asm_func: 
19625 \newline
19626 \InsetSpace ~
19627 \InsetSpace ~
19628 \InsetSpace ~
19629 \InsetSpace ~
19630 push\InsetSpace ~
19631 _bp 
19632 \newline
19633 \InsetSpace ~
19634 \InsetSpace ~
19635 \InsetSpace ~
19636 \InsetSpace ~
19637 mov\InsetSpace ~
19638 \InsetSpace ~
19639 _bp,sp\InsetSpace ~
19640 \InsetSpace ~
19641 \InsetSpace ~
19642 \InsetSpace ~
19643 \InsetSpace ~
19644 \InsetSpace ~
19645 ;stack contains: _bp, return
19646  address, second parameter, third parameter
19647 \newline
19648 \InsetSpace ~
19649 \InsetSpace ~
19650 \InsetSpace ~
19651 \InsetSpace ~
19652 mov\InsetSpace ~
19653 \InsetSpace ~
19654 r2,dpl
19655 \newline
19656 \InsetSpace ~
19657 \InsetSpace ~
19658 \InsetSpace ~
19659 \InsetSpace ~
19660 mov\InsetSpace ~
19661 \InsetSpace ~
19662 a,_bp
19663 \newline
19664 \InsetSpace ~
19665 \InsetSpace ~
19666 \InsetSpace ~
19667 \InsetSpace ~
19668 add\InsetSpace ~
19669 \InsetSpace ~
19670 a,#0xfd\InsetSpace ~
19671 \InsetSpace ~
19672 \InsetSpace ~
19673 \InsetSpace ~
19674 \InsetSpace ~
19675 ;calculate
19676  pointer to the second parameter
19677 \newline
19678 \InsetSpace ~
19679 \InsetSpace ~
19680 \InsetSpace ~
19681 \InsetSpace ~
19682 mov\InsetSpace ~
19683 \InsetSpace ~
19684 r0,a 
19685 \newline
19686 \InsetSpace ~
19687 \InsetSpace ~
19688 \InsetSpace ~
19689 \InsetSpace ~
19690 mov\InsetSpace ~
19691 \InsetSpace ~
19692 a,_bp 
19693 \newline
19694 \InsetSpace ~
19695 \InsetSpace ~
19696 \InsetSpace ~
19697 \InsetSpace ~
19698 add\InsetSpace ~
19699 \InsetSpace ~
19700 a,#0xfc\InsetSpace ~
19701 \InsetSpace ~
19702 \InsetSpace ~
19703 \InsetSpace ~
19704 \InsetSpace ~
19705 ;calculate pointer
19706  to the rightmost parameter
19707 \newline
19708 \InsetSpace ~
19709 \InsetSpace ~
19710 \InsetSpace ~
19711 \InsetSpace ~
19712 mov\InsetSpace ~
19713 \InsetSpace ~
19714 r1,a 
19715 \newline
19716 \InsetSpace ~
19717 \InsetSpace ~
19718 \InsetSpace ~
19719 \InsetSpace ~
19720 mov\InsetSpace ~
19721 \InsetSpace ~
19722 a,@r0
19723 \newline
19724 \InsetSpace ~
19725 \InsetSpace ~
19726 \InsetSpace ~
19727 \InsetSpace ~
19728 add\InsetSpace ~
19729 \InsetSpace ~
19730 a,@r1
19731 \newline
19732 \InsetSpace ~
19733 \InsetSpace ~
19734 \InsetSpace ~
19735 \InsetSpace ~
19736 add\InsetSpace ~
19737 \InsetSpace ~
19738 a,r2\InsetSpace ~
19739 \InsetSpace ~
19740 \InsetSpace ~
19741 \InsetSpace ~
19742 \InsetSpace ~
19743 \InsetSpace ~
19744 \InsetSpace ~
19745 \InsetSpace ~
19746 ;calculate the
19747  result (= sum of all three parameters)
19748 \newline
19749 \InsetSpace ~
19750 \InsetSpace ~
19751 \InsetSpace ~
19752 \InsetSpace ~
19753 mov\InsetSpace ~
19754 \InsetSpace ~
19755 dpl,a\InsetSpace ~
19756 \InsetSpace ~
19757 \InsetSpace ~
19758 \InsetSpace ~
19759 \InsetSpace ~
19760 \InsetSpace ~
19761 \InsetSpace ~
19762 ;return value goes into dptr
19763  (cast into int)
19764 \newline
19765 \InsetSpace ~
19766 \InsetSpace ~
19767 \InsetSpace ~
19768 \InsetSpace ~
19769 mov\InsetSpace ~
19770 \InsetSpace ~
19771 dph,#0x00 
19772 \newline
19773 \InsetSpace ~
19774 \InsetSpace ~
19775 \InsetSpace ~
19776 \InsetSpace ~
19777 mov\InsetSpace ~
19778 \InsetSpace ~
19779 sp,_bp 
19780 \newline
19781 \InsetSpace ~
19782 \InsetSpace ~
19783 \InsetSpace ~
19784 \InsetSpace ~
19785 pop\InsetSpace ~
19786 \InsetSpace ~
19787 _bp 
19788 \newline
19789 \InsetSpace ~
19790 \InsetSpace ~
19791 \InsetSpace ~
19792 \InsetSpace ~
19793 ret
19794 \end_layout
19795
19796 \begin_layout Standard
19797 The compiling and linking procedure remains the same, however note the extra
19798  entry & exit linkage required for the assembler code, _bp is the stack
19799  frame pointer and is used to compute the offset into the stack for parameters
19800  and local variables.
19801 \begin_inset VSpace bigskip
19802 \end_inset
19803
19804
19805 \end_layout
19806
19807 \begin_layout Section
19808 int (16 bit)
19809 \begin_inset LatexCommand index
19810 name "int (16 bit)"
19811
19812 \end_inset
19813
19814  and long (32 bit)
19815 \begin_inset LatexCommand index
19816 name "long (32 bit)"
19817
19818 \end_inset
19819
19820  Support
19821 \end_layout
19822
19823 \begin_layout Standard
19824 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
19825  multiplication and modulus operations are implemented by support routines.
19826  These support routines are all developed in ANSI-C to facilitate porting
19827  to other MCUs, although some model specific assembler optimizations are
19828  used.
19829  The following files contain the described routines, all of them can be
19830  found in <installdir>/share/sdcc/lib.
19831 \newline
19832
19833 \end_layout
19834
19835 \begin_layout Standard
19836 \align center
19837 \begin_inset Tabular
19838 <lyxtabular version="3" rows="11" columns="2">
19839 <features>
19840 <column alignment="left" valignment="top" leftline="true" width="0">
19841 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19842 <row topline="true" bottomline="true">
19843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19844 \begin_inset Text
19845
19846 \begin_layout Standard
19847
19848 \series bold
19849 Function
19850 \end_layout
19851
19852 \end_inset
19853 </cell>
19854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19855 \begin_inset Text
19856
19857 \begin_layout Standard
19858
19859 \series bold
19860 Description
19861 \end_layout
19862
19863 \end_inset
19864 </cell>
19865 </row>
19866 <row topline="true">
19867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19868 \begin_inset Text
19869
19870 \begin_layout Standard
19871 _mulint.c 
19872 \end_layout
19873
19874 \end_inset
19875 </cell>
19876 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19877 \begin_inset Text
19878
19879 \begin_layout Standard
19880 16 bit multiplication
19881 \end_layout
19882
19883 \end_inset
19884 </cell>
19885 </row>
19886 <row topline="true">
19887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19888 \begin_inset Text
19889
19890 \begin_layout Standard
19891 _divsint.c 
19892 \end_layout
19893
19894 \end_inset
19895 </cell>
19896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19897 \begin_inset Text
19898
19899 \begin_layout Standard
19900  signed 16 bit division (calls _divuint)
19901 \end_layout
19902
19903 \end_inset
19904 </cell>
19905 </row>
19906 <row topline="true">
19907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19908 \begin_inset Text
19909
19910 \begin_layout Standard
19911 _divuint.c 
19912 \end_layout
19913
19914 \end_inset
19915 </cell>
19916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19917 \begin_inset Text
19918
19919 \begin_layout Standard
19920  unsigned 16 bit division
19921 \end_layout
19922
19923 \end_inset
19924 </cell>
19925 </row>
19926 <row topline="true">
19927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19928 \begin_inset Text
19929
19930 \begin_layout Standard
19931 _modsint.c
19932 \end_layout
19933
19934 \end_inset
19935 </cell>
19936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19937 \begin_inset Text
19938
19939 \begin_layout Standard
19940 signed 16 bit modulus (calls _moduint)
19941 \end_layout
19942
19943 \end_inset
19944 </cell>
19945 </row>
19946 <row topline="true">
19947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19948 \begin_inset Text
19949
19950 \begin_layout Standard
19951 _moduint.c
19952 \end_layout
19953
19954 \end_inset
19955 </cell>
19956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19957 \begin_inset Text
19958
19959 \begin_layout Standard
19960 unsigned 16 bit modulus
19961 \end_layout
19962
19963 \end_inset
19964 </cell>
19965 </row>
19966 <row topline="true">
19967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19968 \begin_inset Text
19969
19970 \begin_layout Standard
19971 _mullong.c
19972 \end_layout
19973
19974 \end_inset
19975 </cell>
19976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19977 \begin_inset Text
19978
19979 \begin_layout Standard
19980 32 bit multiplication
19981 \end_layout
19982
19983 \end_inset
19984 </cell>
19985 </row>
19986 <row topline="true">
19987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19988 \begin_inset Text
19989
19990 \begin_layout Standard
19991 _divslong.c 
19992 \end_layout
19993
19994 \end_inset
19995 </cell>
19996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19997 \begin_inset Text
19998
19999 \begin_layout Standard
20000  signed 32 division (calls _divulong)
20001 \end_layout
20002
20003 \end_inset
20004 </cell>
20005 </row>
20006 <row topline="true">
20007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20008 \begin_inset Text
20009
20010 \begin_layout Standard
20011 _divulong.c 
20012 \end_layout
20013
20014 \end_inset
20015 </cell>
20016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20017 \begin_inset Text
20018
20019 \begin_layout Standard
20020 unsigned 32 division
20021 \end_layout
20022
20023 \end_inset
20024 </cell>
20025 </row>
20026 <row topline="true">
20027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20028 \begin_inset Text
20029
20030 \begin_layout Standard
20031 _modslong.c
20032 \end_layout
20033
20034 \end_inset
20035 </cell>
20036 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20037 \begin_inset Text
20038
20039 \begin_layout Standard
20040  signed 32 bit modulus (calls _modulong)
20041 \end_layout
20042
20043 \end_inset
20044 </cell>
20045 </row>
20046 <row topline="true" bottomline="true">
20047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20048 \begin_inset Text
20049
20050 \begin_layout Standard
20051 _modulong.c
20052 \end_layout
20053
20054 \end_inset
20055 </cell>
20056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20057 \begin_inset Text
20058
20059 \begin_layout Standard
20060 unsigned 32 bit modulus
20061 \end_layout
20062
20063 \end_inset
20064 </cell>
20065 </row>
20066 </lyxtabular>
20067
20068 \end_inset
20069
20070
20071 \newline
20072
20073 \end_layout
20074
20075 \begin_layout Standard
20076 Since they are compiled as 
20077 \emph on
20078 non-reentrant
20079 \emph default
20080
20081 \begin_inset LatexCommand index
20082 name "reentrant"
20083
20084 \end_inset
20085
20086 , interrupt
20087 \begin_inset LatexCommand index
20088 name "interrupt"
20089
20090 \end_inset
20091
20092  service routines should not do any of the above operations.
20093  If this is unavoidable then the above routines will need to be compiled
20094  with the 
20095 \emph on
20096 -
20097 \begin_inset ERT
20098 status collapsed
20099
20100 \begin_layout Standard
20101
20102
20103 \backslash
20104 /
20105 \end_layout
20106
20107 \end_inset
20108
20109 -stack-auto
20110 \begin_inset LatexCommand index
20111 name "-\\/-stack-auto"
20112
20113 \end_inset
20114
20115
20116 \emph default
20117  option, after which the source program will have to be compiled with 
20118 \emph on
20119 -
20120 \begin_inset ERT
20121 status collapsed
20122
20123 \begin_layout Standard
20124
20125
20126 \backslash
20127 /
20128 \end_layout
20129
20130 \end_inset
20131
20132 -int-long-reent
20133 \begin_inset LatexCommand index
20134 name "-\\/-int-long-reent"
20135
20136 \end_inset
20137
20138
20139 \emph default
20140  option.
20141  Notice that you don't have to call these routines directly.
20142  The compiler will use them automatically every time an integer operation
20143  is required.
20144 \end_layout
20145
20146 \begin_layout Section
20147 Floating Point Support
20148 \begin_inset LatexCommand index
20149 name "Floating point support"
20150
20151 \end_inset
20152
20153
20154 \end_layout
20155
20156 \begin_layout Standard
20157 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
20158  The floating point support routines are derived from gcc's floatlib.c and
20159  consist of the following routines:
20160 \newline
20161
20162 \end_layout
20163
20164 \begin_layout Standard
20165 \align center
20166
20167 \size footnotesize
20168 \begin_inset Tabular
20169 <lyxtabular version="3" rows="17" columns="2">
20170 <features>
20171 <column alignment="left" valignment="top" leftline="true" width="0">
20172 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
20173 <row topline="true" bottomline="true">
20174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20175 \begin_inset Text
20176
20177 \begin_layout Standard
20178
20179 \family roman
20180 \series medium
20181 \shape up
20182 \size normal
20183 \emph off
20184 \bar no
20185 \noun off
20186 \color none
20187 Function 
20188 \end_layout
20189
20190 \end_inset
20191 </cell>
20192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20193 \begin_inset Text
20194
20195 \begin_layout Standard
20196 Description
20197 \end_layout
20198
20199 \end_inset
20200 </cell>
20201 </row>
20202 <row topline="true">
20203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20204 \begin_inset Text
20205
20206 \begin_layout Standard
20207
20208 \family roman
20209 \series medium
20210 \shape up
20211 \size normal
20212 \emph off
20213 \bar no
20214 \noun off
20215 \color none
20216 _fsadd.c
20217 \end_layout
20218
20219 \end_inset
20220 </cell>
20221 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20222 \begin_inset Text
20223
20224 \begin_layout Standard
20225
20226 \family roman
20227 \series medium
20228 \shape up
20229 \size normal
20230 \emph off
20231 \bar no
20232 \noun off
20233 \color none
20234 add floating point numbers
20235 \end_layout
20236
20237 \end_inset
20238 </cell>
20239 </row>
20240 <row topline="true">
20241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20242 \begin_inset Text
20243
20244 \begin_layout Standard
20245
20246 \family roman
20247 \series medium
20248 \shape up
20249 \size normal
20250 \emph off
20251 \bar no
20252 \noun off
20253 \color none
20254 _fssub.c 
20255 \end_layout
20256
20257 \end_inset
20258 </cell>
20259 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20260 \begin_inset Text
20261
20262 \begin_layout Standard
20263
20264 \family roman
20265 \series medium
20266 \shape up
20267 \size normal
20268 \emph off
20269 \bar no
20270 \noun off
20271 \color none
20272 subtract floating point numbers 
20273 \end_layout
20274
20275 \end_inset
20276 </cell>
20277 </row>
20278 <row topline="true">
20279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20280 \begin_inset Text
20281
20282 \begin_layout Standard
20283
20284 \family roman
20285 \series medium
20286 \shape up
20287 \size normal
20288 \emph off
20289 \bar no
20290 \noun off
20291 \color none
20292 _fsdiv.c 
20293 \end_layout
20294
20295 \end_inset
20296 </cell>
20297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20298 \begin_inset Text
20299
20300 \begin_layout Standard
20301
20302 \family roman
20303 \series medium
20304 \shape up
20305 \size normal
20306 \emph off
20307 \bar no
20308 \noun off
20309 \color none
20310 divide floating point numbers 
20311 \end_layout
20312
20313 \end_inset
20314 </cell>
20315 </row>
20316 <row topline="true">
20317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20318 \begin_inset Text
20319
20320 \begin_layout Standard
20321
20322 \family roman
20323 \series medium
20324 \shape up
20325 \size normal
20326 \emph off
20327 \bar no
20328 \noun off
20329 \color none
20330 _fsmul.c 
20331 \end_layout
20332
20333 \end_inset
20334 </cell>
20335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20336 \begin_inset Text
20337
20338 \begin_layout Standard
20339
20340 \family roman
20341 \series medium
20342 \shape up
20343 \size normal
20344 \emph off
20345 \bar no
20346 \noun off
20347 \color none
20348 multiply floating point numbers 
20349 \end_layout
20350
20351 \end_inset
20352 </cell>
20353 </row>
20354 <row topline="true">
20355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20356 \begin_inset Text
20357
20358 \begin_layout Standard
20359
20360 \family roman
20361 \series medium
20362 \shape up
20363 \size normal
20364 \emph off
20365 \bar no
20366 \noun off
20367 \color none
20368 _fs2uchar.c
20369 \end_layout
20370
20371 \end_inset
20372 </cell>
20373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20374 \begin_inset Text
20375
20376 \begin_layout Standard
20377
20378 \family roman
20379 \series medium
20380 \shape up
20381 \size normal
20382 \emph off
20383 \bar no
20384 \noun off
20385 \color none
20386 convert floating point to unsigned char
20387 \end_layout
20388
20389 \end_inset
20390 </cell>
20391 </row>
20392 <row topline="true">
20393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20394 \begin_inset Text
20395
20396 \begin_layout Standard
20397
20398 \family roman
20399 \series medium
20400 \shape up
20401 \size normal
20402 \emph off
20403 \bar no
20404 \noun off
20405 \color none
20406 _fs2char.c
20407 \end_layout
20408
20409 \end_inset
20410 </cell>
20411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20412 \begin_inset Text
20413
20414 \begin_layout Standard
20415
20416 \family roman
20417 \series medium
20418 \shape up
20419 \size normal
20420 \emph off
20421 \bar no
20422 \noun off
20423 \color none
20424 convert floating point to signed char
20425 \end_layout
20426
20427 \end_inset
20428 </cell>
20429 </row>
20430 <row topline="true">
20431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20432 \begin_inset Text
20433
20434 \begin_layout Standard
20435
20436 \family roman
20437 \series medium
20438 \shape up
20439 \size normal
20440 \emph off
20441 \bar no
20442 \noun off
20443 \color none
20444 _fs2uint.c
20445 \end_layout
20446
20447 \end_inset
20448 </cell>
20449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20450 \begin_inset Text
20451
20452 \begin_layout Standard
20453
20454 \family roman
20455 \series medium
20456 \shape up
20457 \size normal
20458 \emph off
20459 \bar no
20460 \noun off
20461 \color none
20462 convert floating point to unsigned int
20463 \end_layout
20464
20465 \end_inset
20466 </cell>
20467 </row>
20468 <row topline="true">
20469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20470 \begin_inset Text
20471
20472 \begin_layout Standard
20473
20474 \family roman
20475 \series medium
20476 \shape up
20477 \size normal
20478 \emph off
20479 \bar no
20480 \noun off
20481 \color none
20482 _fs2int.c
20483 \end_layout
20484
20485 \end_inset
20486 </cell>
20487 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20488 \begin_inset Text
20489
20490 \begin_layout Standard
20491
20492 \family roman
20493 \series medium
20494 \shape up
20495 \size normal
20496 \emph off
20497 \bar no
20498 \noun off
20499 \color none
20500 convert floating point to signed int
20501 \end_layout
20502
20503 \end_inset
20504 </cell>
20505 </row>
20506 <row topline="true">
20507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20508 \begin_inset Text
20509
20510 \begin_layout Standard
20511
20512 \family roman
20513 \series medium
20514 \shape up
20515 \size normal
20516 \emph off
20517 \bar no
20518 \noun off
20519 \color none
20520 _fs2ulong.
20521 \family default
20522 \series default
20523 \shape default
20524 \size default
20525 \emph default
20526 \bar default
20527 \noun default
20528 c
20529 \end_layout
20530
20531 \end_inset
20532 </cell>
20533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20534 \begin_inset Text
20535
20536 \begin_layout Standard
20537
20538 \family roman
20539 \series medium
20540 \shape up
20541 \size normal
20542 \emph off
20543 \bar no
20544 \noun off
20545 \color none
20546 convert floating point to unsigned long
20547 \end_layout
20548
20549 \end_inset
20550 </cell>
20551 </row>
20552 <row topline="true">
20553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20554 \begin_inset Text
20555
20556 \begin_layout Standard
20557
20558 \family roman
20559 \series medium
20560 \shape up
20561 \size normal
20562 \emph off
20563 \bar no
20564 \noun off
20565 \color none
20566 _fs2long.c
20567 \end_layout
20568
20569 \end_inset
20570 </cell>
20571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20572 \begin_inset Text
20573
20574 \begin_layout Standard
20575
20576 \family roman
20577 \series medium
20578 \shape up
20579 \size normal
20580 \emph off
20581 \bar no
20582 \noun off
20583 \color none
20584 convert floating point to signed long
20585 \end_layout
20586
20587 \end_inset
20588 </cell>
20589 </row>
20590 <row topline="true">
20591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20592 \begin_inset Text
20593
20594 \begin_layout Standard
20595
20596 \family roman
20597 \series medium
20598 \shape up
20599 \size normal
20600 \emph off
20601 \bar no
20602 \noun off
20603 \color none
20604 _uchar2fs.c
20605 \end_layout
20606
20607 \end_inset
20608 </cell>
20609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20610 \begin_inset Text
20611
20612 \begin_layout Standard
20613
20614 \family roman
20615 \series medium
20616 \shape up
20617 \size normal
20618 \emph off
20619 \bar no
20620 \noun off
20621 \color none
20622 convert unsigned char to floating point
20623 \end_layout
20624
20625 \end_inset
20626 </cell>
20627 </row>
20628 <row topline="true">
20629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20630 \begin_inset Text
20631
20632 \begin_layout Standard
20633
20634 \family roman
20635 \series medium
20636 \shape up
20637 \size normal
20638 \emph off
20639 \bar no
20640 \noun off
20641 \color none
20642 _char2fs.c
20643 \end_layout
20644
20645 \end_inset
20646 </cell>
20647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20648 \begin_inset Text
20649
20650 \begin_layout Standard
20651
20652 \family roman
20653 \series medium
20654 \shape up
20655 \size normal
20656 \emph off
20657 \bar no
20658 \noun off
20659 \color none
20660 convert char to floating point number
20661 \end_layout
20662
20663 \end_inset
20664 </cell>
20665 </row>
20666 <row topline="true">
20667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20668 \begin_inset Text
20669
20670 \begin_layout Standard
20671
20672 \family roman
20673 \series medium
20674 \shape up
20675 \size normal
20676 \emph off
20677 \bar no
20678 \noun off
20679 \color none
20680 _uint2fs.c
20681 \end_layout
20682
20683 \end_inset
20684 </cell>
20685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20686 \begin_inset Text
20687
20688 \begin_layout Standard
20689
20690 \family roman
20691 \series medium
20692 \shape up
20693 \size normal
20694 \emph off
20695 \bar no
20696 \noun off
20697 \color none
20698 convert unsigned int to floating point
20699 \end_layout
20700
20701 \end_inset
20702 </cell>
20703 </row>
20704 <row topline="true">
20705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20706 \begin_inset Text
20707
20708 \begin_layout Standard
20709
20710 \family roman
20711 \series medium
20712 \shape up
20713 \size normal
20714 \emph off
20715 \bar no
20716 \noun off
20717 \color none
20718 _int2fs.c
20719 \end_layout
20720
20721 \end_inset
20722 </cell>
20723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20724 \begin_inset Text
20725
20726 \begin_layout Standard
20727
20728 \family roman
20729 \series medium
20730 \shape up
20731 \size normal
20732 \emph off
20733 \bar no
20734 \noun off
20735 \color none
20736 convert int to floating point numbers
20737 \end_layout
20738
20739 \end_inset
20740 </cell>
20741 </row>
20742 <row topline="true">
20743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20744 \begin_inset Text
20745
20746 \begin_layout Standard
20747
20748 \family roman
20749 \series medium
20750 \shape up
20751 \size normal
20752 \emph off
20753 \bar no
20754 \noun off
20755 \color none
20756 _ulong2fs.c
20757 \end_layout
20758
20759 \end_inset
20760 </cell>
20761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20762 \begin_inset Text
20763
20764 \begin_layout Standard
20765
20766 \family roman
20767 \series medium
20768 \shape up
20769 \size normal
20770 \emph off
20771 \bar no
20772 \noun off
20773 \color none
20774 convert unsigned long to floating point number
20775 \end_layout
20776
20777 \end_inset
20778 </cell>
20779 </row>
20780 <row topline="true" bottomline="true">
20781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20782 \begin_inset Text
20783
20784 \begin_layout Standard
20785
20786 \family roman
20787 \series medium
20788 \shape up
20789 \size normal
20790 \emph off
20791 \bar no
20792 \noun off
20793 \color none
20794 _long2fs.c
20795 \end_layout
20796
20797 \end_inset
20798 </cell>
20799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20800 \begin_inset Text
20801
20802 \begin_layout Standard
20803
20804 \family roman
20805 \series medium
20806 \shape up
20807 \size normal
20808 \emph off
20809 \bar no
20810 \noun off
20811 \color none
20812 convert long to floating point number
20813 \end_layout
20814
20815 \end_inset
20816 </cell>
20817 </row>
20818 </lyxtabular>
20819
20820 \end_inset
20821
20822
20823 \newline
20824
20825 \end_layout
20826
20827 \begin_layout Standard
20828 These support routines are developed in ANSI-C so there is room for space
20829  and speed improvement
20830 \begin_inset Foot
20831 status open
20832
20833 \begin_layout Standard
20834 These floating point routines (
20835 \emph on
20836 not
20837 \emph default
20838  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
20839  
20840 \end_layout
20841
20842 \end_inset
20843
20844 .
20845  Note if all these routines are used simultaneously the data space might
20846  overflow.
20847  For serious floating point usage the large model might be needed.
20848  Also notice that you don't have to call this routines directly.
20849  The compiler will use them automatically every time a floating point operation
20850  is required.
20851 \begin_inset VSpace bigskip
20852 \end_inset
20853
20854
20855 \end_layout
20856
20857 \begin_layout Section
20858 Library Routines
20859 \begin_inset LatexCommand index
20860 name "Libraries"
20861
20862 \end_inset
20863
20864
20865 \end_layout
20866
20867 \begin_layout Standard
20868
20869 \emph on
20870 <pending: this is messy and incomplete - a little more information is in
20871  sdcc/doc/libdoc.txt
20872 \emph default
20873  >
20874 \end_layout
20875
20876 \begin_layout Subsection
20877 Compiler support routines (_gptrget, _mulint etc.)
20878 \end_layout
20879
20880 \begin_layout Subsection
20881 Stdclib functions (puts, printf, strcat etc.)
20882 \end_layout
20883
20884 \begin_layout Subsubsection
20885 <stdio.h>
20886 \end_layout
20887
20888 \begin_layout Paragraph
20889 getchar(), putchar()
20890 \end_layout
20891
20892 \begin_layout Standard
20893 \begin_inset LatexCommand index
20894 name "<stdio.h>"
20895
20896 \end_inset
20897
20898 As usual on embedded systems you have to provide your own 
20899 \family typewriter
20900 getchar()
20901 \begin_inset LatexCommand index
20902 name "getchar()"
20903
20904 \end_inset
20905
20906
20907 \family default
20908  and 
20909 \family typewriter
20910 putchar()
20911 \begin_inset LatexCommand index
20912 name "putchar()"
20913
20914 \end_inset
20915
20916
20917 \family default
20918  routines.
20919  SDCC does not know whether the system connects to a serial line with or
20920  without handshake, LCD, keyboard or other device.
20921  And whether a 
20922 \family typewriter
20923 lf
20924 \family default
20925  to 
20926 \family typewriter
20927 crlf
20928 \family default
20929  conversion within 
20930 \family typewriter
20931 putchar()
20932 \family default
20933  is intended.
20934  You'll find examples for serial routines f.e.
20935  in sdcc/device/lib.
20936  For the mcs51 this minimalistic polling 
20937 \family typewriter
20938 putchar()
20939 \family default
20940  routine might be a start:
20941 \end_layout
20942
20943 \begin_layout Verse
20944
20945 \family typewriter
20946 void putchar (char c) { 
20947 \newline
20948 \InsetSpace ~
20949 \InsetSpace ~
20950 \InsetSpace ~
20951 \InsetSpace ~
20952 while (!TI)\InsetSpace ~
20953 \InsetSpace ~
20954 \InsetSpace ~
20955  /* assumes UART is initialized */
20956 \newline
20957 \InsetSpace ~
20958 \InsetSpace ~
20959 \InsetSpace ~
20960 \InsetSpace ~
20961 \InsetSpace ~
20962 \InsetSpace ~
20963 \InsetSpace ~
20964 \InsetSpace ~
20965 ;
20966 \newline
20967 \InsetSpace ~
20968 \InsetSpace ~
20969 \InsetSpace ~
20970 \InsetSpace ~
20971 TI
20972  = 0;
20973 \newline
20974 \InsetSpace ~
20975 \InsetSpace ~
20976 \InsetSpace ~
20977 \InsetSpace ~
20978 SBUF = c;
20979 \newline
20980 }
20981 \end_layout
20982
20983 \begin_layout Paragraph
20984 printf()
20985 \end_layout
20986
20987 \begin_layout Standard
20988 The default 
20989 \family typewriter
20990 printf()
20991 \begin_inset LatexCommand index
20992 name "printf()"
20993
20994 \end_inset
20995
20996
20997 \family default
20998  implementation in 
20999 \family typewriter
21000 printf_large.c
21001 \family default
21002  does not support float (except on ds390).
21003  To enable this recompile it with the option 
21004 \emph on
21005 -
21006 \begin_inset ERT
21007 status collapsed
21008
21009 \begin_layout Standard
21010
21011
21012 \backslash
21013 /
21014 \end_layout
21015
21016 \end_inset
21017
21018 DUSE_FLOATS=1
21019 \begin_inset LatexCommand index
21020 name "USE\\_FLOATS"
21021
21022 \end_inset
21023
21024
21025 \emph default
21026  on the command line.
21027  Use 
21028 \emph on
21029 -
21030 \begin_inset ERT
21031 status collapsed
21032
21033 \begin_layout Standard
21034
21035
21036 \backslash
21037 /
21038 \end_layout
21039
21040 \end_inset
21041
21042 -model-large
21043 \begin_inset LatexCommand index
21044 name "-\\/-model-large"
21045
21046 \end_inset
21047
21048
21049 \emph default
21050  for the mcs51 port, since this uses a lot of memory.
21051 \end_layout
21052
21053 \begin_layout Standard
21054 If you're short on code memory you might want to use 
21055 \family typewriter
21056 printf_small()
21057 \begin_inset LatexCommand index
21058 name "printf\\_small()"
21059
21060 \end_inset
21061
21062
21063 \family default
21064  
21065 \emph on
21066 instead
21067 \emph default
21068  of 
21069 \family typewriter
21070 printf().
21071
21072 \family default
21073  For the mcs51 there additionally are assembly versions 
21074 \family typewriter
21075 printf_tiny()
21076 \begin_inset LatexCommand index
21077 name "printf\\_tiny() (mcs51)"
21078
21079 \end_inset
21080
21081
21082 \family default
21083  (subset of printf using less than 270 bytes) and 
21084 \family typewriter
21085 printf_fast()
21086 \begin_inset LatexCommand index
21087 name "printf\\_fast() (mcs51)"
21088
21089 \end_inset
21090
21091
21092 \family default
21093  and 
21094 \family typewriter
21095 printf_fast_f()
21096 \begin_inset LatexCommand index
21097 name "printf\\_fast\\_f() (mcs51)"
21098
21099 \end_inset
21100
21101
21102 \family default
21103  (floating-point aware version of printf_fast) which should fit the requirements
21104  of many embedded systems (printf_fast() can be customized by unsetting
21105  #defines to 
21106 \emph on
21107 not
21108 \emph default
21109  support long variables and field widths).
21110  Be sure to use only one of these printf options within a project.
21111 \newline
21112
21113 \end_layout
21114
21115 \begin_layout Standard
21116 Feature matrix of different 
21117 \emph on
21118 printf
21119 \emph default
21120  options on mcs51.
21121 \end_layout
21122
21123 \begin_layout Standard
21124 \begin_inset Tabular
21125 <lyxtabular version="3" rows="14" columns="7">
21126 <features islongtable="true">
21127 <column alignment="left" valignment="middle" leftline="true" width="14col%">
21128 <column alignment="center" valignment="top" leftline="true" width="0">
21129 <column alignment="center" valignment="top" leftline="true" width="12col%">
21130 <column alignment="center" valignment="top" leftline="true" width="10col%">
21131 <column alignment="center" valignment="top" leftline="true" width="0">
21132 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
21133 <column alignment="center" valignment="top" rightline="true" width="0">
21134 <row topline="true" bottomline="true" endhead="true">
21135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21136 \begin_inset Text
21137
21138 \begin_layout Standard
21139
21140 \series bold
21141 \size large
21142 mcs51
21143 \end_layout
21144
21145 \end_inset
21146 </cell>
21147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21148 \begin_inset Text
21149
21150 \begin_layout Standard
21151 printf
21152 \begin_inset LatexCommand index
21153 name "printf"
21154
21155 \end_inset
21156
21157
21158 \end_layout
21159
21160 \end_inset
21161 </cell>
21162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21163 \begin_inset Text
21164
21165 \begin_layout Standard
21166 printf 
21167 \size scriptsize
21168 USE_FLOATS=1
21169 \end_layout
21170
21171 \end_inset
21172 </cell>
21173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21174 \begin_inset Text
21175
21176 \begin_layout Standard
21177 printf_small
21178 \end_layout
21179
21180 \end_inset
21181 </cell>
21182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21183 \begin_inset Text
21184
21185 \begin_layout Standard
21186 printf_fast
21187 \end_layout
21188
21189 \end_inset
21190 </cell>
21191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21192 \begin_inset Text
21193
21194 \begin_layout Standard
21195 printf_fast_f
21196 \end_layout
21197
21198 \end_inset
21199 </cell>
21200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21201 \begin_inset Text
21202
21203 \begin_layout Standard
21204 printf_tiny
21205 \end_layout
21206
21207 \end_inset
21208 </cell>
21209 </row>
21210 <row topline="true" endhead="true">
21211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21212 \begin_inset Text
21213
21214 \begin_layout Standard
21215 filename
21216 \end_layout
21217
21218 \end_inset
21219 </cell>
21220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21221 \begin_inset Text
21222
21223 \begin_layout Standard
21224
21225 \size scriptsize
21226 printf_large.c
21227 \end_layout
21228
21229 \end_inset
21230 </cell>
21231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21232 \begin_inset Text
21233
21234 \begin_layout Standard
21235
21236 \size scriptsize
21237 printf_large.c
21238 \end_layout
21239
21240 \end_inset
21241 </cell>
21242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21243 \begin_inset Text
21244
21245 \begin_layout Standard
21246
21247 \size scriptsize
21248 printfl.c
21249 \end_layout
21250
21251 \end_inset
21252 </cell>
21253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21254 \begin_inset Text
21255
21256 \begin_layout Standard
21257
21258 \size scriptsize
21259 printf_fast.c
21260 \end_layout
21261
21262 \end_inset
21263 </cell>
21264 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21265 \begin_inset Text
21266
21267 \begin_layout Standard
21268
21269 \size scriptsize
21270 printf_fast_f.c
21271 \end_layout
21272
21273 \end_inset
21274 </cell>
21275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21276 \begin_inset Text
21277
21278 \begin_layout Standard
21279
21280 \size scriptsize
21281 printf_tiny.c
21282 \end_layout
21283
21284 \end_inset
21285 </cell>
21286 </row>
21287 <row topline="true" endhead="true">
21288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21289 \begin_inset Text
21290
21291 \begin_layout Standard
21292 \begin_inset Quotes sld
21293 \end_inset
21294
21295 Hello World
21296 \begin_inset Quotes srd
21297 \end_inset
21298
21299  size
21300 \end_layout
21301
21302 \begin_layout Standard
21303 small / large
21304 \end_layout
21305
21306 \end_inset
21307 </cell>
21308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21309 \begin_inset Text
21310
21311 \begin_layout Standard
21312 1.7k / 2.4k
21313 \end_layout
21314
21315 \end_inset
21316 </cell>
21317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21318 \begin_inset Text
21319
21320 \begin_layout Standard
21321 4.3k / 5.6k
21322 \end_layout
21323
21324 \end_inset
21325 </cell>
21326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21327 \begin_inset Text
21328
21329 \begin_layout Standard
21330 1.2k / 1.8k
21331 \end_layout
21332
21333 \end_inset
21334 </cell>
21335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21336 \begin_inset Text
21337
21338 \begin_layout Standard
21339 1.3k / 1.3k
21340 \end_layout
21341
21342 \end_inset
21343 </cell>
21344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21345 \begin_inset Text
21346
21347 \begin_layout Standard
21348 1.9k / 1.9k
21349 \end_layout
21350
21351 \end_inset
21352 </cell>
21353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21354 \begin_inset Text
21355
21356 \begin_layout Standard
21357 0.44k / 0.44k
21358 \end_layout
21359
21360 \end_inset
21361 </cell>
21362 </row>
21363 <row topline="true" endhead="true">
21364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21365 \begin_inset Text
21366
21367 \begin_layout Standard
21368 code size
21369 \end_layout
21370
21371 \begin_layout Standard
21372 small / large
21373 \end_layout
21374
21375 \end_inset
21376 </cell>
21377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21378 \begin_inset Text
21379
21380 \begin_layout Standard
21381 1.4k / 2.0k
21382 \end_layout
21383
21384 \end_inset
21385 </cell>
21386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21387 \begin_inset Text
21388
21389 \begin_layout Standard
21390 2.8k / 3.7k
21391 \end_layout
21392
21393 \end_inset
21394 </cell>
21395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21396 \begin_inset Text
21397
21398 \begin_layout Standard
21399 0.45k / 0.47k (+ _ltoa)
21400 \end_layout
21401
21402 \end_inset
21403 </cell>
21404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21405 \begin_inset Text
21406
21407 \begin_layout Standard
21408 1.2k / 1.2k
21409 \end_layout
21410
21411 \end_inset
21412 </cell>
21413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21414 \begin_inset Text
21415
21416 \begin_layout Standard
21417 1.6k / 1.6k
21418 \end_layout
21419
21420 \end_inset
21421 </cell>
21422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21423 \begin_inset Text
21424
21425 \begin_layout Standard
21426 0.26k / 0.26k
21427 \end_layout
21428
21429 \end_inset
21430 </cell>
21431 </row>
21432 <row topline="true">
21433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21434 \begin_inset Text
21435
21436 \begin_layout Standard
21437 formats
21438 \end_layout
21439
21440 \end_inset
21441 </cell>
21442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21443 \begin_inset Text
21444
21445 \begin_layout Standard
21446 cdi
21447 \emph on
21448 o
21449 \emph default
21450 psux
21451 \end_layout
21452
21453 \end_inset
21454 </cell>
21455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21456 \begin_inset Text
21457
21458 \begin_layout Standard
21459
21460 \family roman
21461 \series medium
21462 \shape up
21463 \size normal
21464 \emph off
21465 \bar no
21466 \noun off
21467 \color none
21468 cd
21469 \family default
21470 \series default
21471 \shape default
21472 \size default
21473 \emph default
21474 \bar default
21475 \noun default
21476 f
21477 \family roman
21478 \series medium
21479 \shape up
21480 \size normal
21481 \emph off
21482 \bar no
21483 \noun off
21484 i
21485 \family default
21486 \series default
21487 \shape default
21488 \size default
21489 \emph on
21490 \bar default
21491 \noun default
21492 o
21493 \family roman
21494 \series medium
21495 \shape up
21496 \size normal
21497 \emph off
21498 \bar no
21499 \noun off
21500 psux
21501 \end_layout
21502
21503 \end_inset
21504 </cell>
21505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21506 \begin_inset Text
21507
21508 \begin_layout Standard
21509 c
21510 \family roman
21511 \series medium
21512 \shape up
21513 \size normal
21514 \emph off
21515 \bar no
21516 \noun off
21517 \color none
21518 d
21519 \family default
21520 \series default
21521 \shape default
21522 \size default
21523 \emph on
21524 \bar default
21525 \noun default
21526 o
21527 \family roman
21528 \series medium
21529 \shape up
21530 \size normal
21531 \emph off
21532 \bar no
21533 \noun off
21534 s
21535 \family default
21536 \series default
21537 \shape default
21538 \size default
21539 \emph default
21540 \bar default
21541 \noun default
21542 x
21543 \end_layout
21544
21545 \end_inset
21546 </cell>
21547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21548 \begin_inset Text
21549
21550 \begin_layout Standard
21551 cdsux
21552 \end_layout
21553
21554 \end_inset
21555 </cell>
21556 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21557 \begin_inset Text
21558
21559 \begin_layout Standard
21560 cdfsux
21561 \end_layout
21562
21563 \end_inset
21564 </cell>
21565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21566 \begin_inset Text
21567
21568 \begin_layout Standard
21569 cdsux
21570 \end_layout
21571
21572 \end_inset
21573 </cell>
21574 </row>
21575 <row topline="true">
21576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21577 \begin_inset Text
21578
21579 \begin_layout Standard
21580 long (32 bit) support
21581 \end_layout
21582
21583 \end_inset
21584 </cell>
21585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21586 \begin_inset Text
21587
21588 \begin_layout Standard
21589 x
21590 \end_layout
21591
21592 \end_inset
21593 </cell>
21594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21595 \begin_inset Text
21596
21597 \begin_layout Standard
21598 x
21599 \end_layout
21600
21601 \end_inset
21602 </cell>
21603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21604 \begin_inset Text
21605
21606 \begin_layout Standard
21607 x
21608 \end_layout
21609
21610 \end_inset
21611 </cell>
21612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21613 \begin_inset Text
21614
21615 \begin_layout Standard
21616 x
21617 \end_layout
21618
21619 \end_inset
21620 </cell>
21621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21622 \begin_inset Text
21623
21624 \begin_layout Standard
21625
21626 \family roman
21627 \series medium
21628 \shape up
21629 \size normal
21630 \emph off
21631 \bar no
21632 \noun off
21633 \color none
21634 x
21635 \end_layout
21636
21637 \end_inset
21638 </cell>
21639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21640 \begin_inset Text
21641
21642 \begin_layout Standard
21643 -
21644 \end_layout
21645
21646 \end_inset
21647 </cell>
21648 </row>
21649 <row topline="true">
21650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21651 \begin_inset Text
21652
21653 \begin_layout Standard
21654 byte arguments on stack
21655 \end_layout
21656
21657 \end_inset
21658 </cell>
21659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21660 \begin_inset Text
21661
21662 \begin_layout Standard
21663 b
21664 \end_layout
21665
21666 \end_inset
21667 </cell>
21668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21669 \begin_inset Text
21670
21671 \begin_layout Standard
21672 b
21673 \end_layout
21674
21675 \end_inset
21676 </cell>
21677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21678 \begin_inset Text
21679
21680 \begin_layout Standard
21681 -
21682 \end_layout
21683
21684 \end_inset
21685 </cell>
21686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21687 \begin_inset Text
21688
21689 \begin_layout Standard
21690 -
21691 \end_layout
21692
21693 \end_inset
21694 </cell>
21695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21696 \begin_inset Text
21697
21698 \begin_layout Standard
21699 -
21700 \end_layout
21701
21702 \end_inset
21703 </cell>
21704 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21705 \begin_inset Text
21706
21707 \begin_layout Standard
21708 -
21709 \end_layout
21710
21711 \end_inset
21712 </cell>
21713 </row>
21714 <row topline="true">
21715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21716 \begin_inset Text
21717
21718 \begin_layout Standard
21719 float format
21720 \begin_inset LatexCommand index
21721 name "Floating point support"
21722
21723 \end_inset
21724
21725
21726 \end_layout
21727
21728 \end_inset
21729 </cell>
21730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21731 \begin_inset Text
21732
21733 \begin_layout Standard
21734 -
21735 \end_layout
21736
21737 \end_inset
21738 </cell>
21739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21740 \begin_inset Text
21741
21742 \begin_layout Standard
21743 %f
21744 \end_layout
21745
21746 \end_inset
21747 </cell>
21748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21749 \begin_inset Text
21750
21751 \begin_layout Standard
21752 -
21753 \end_layout
21754
21755 \end_inset
21756 </cell>
21757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21758 \begin_inset Text
21759
21760 \begin_layout Standard
21761 -
21762 \end_layout
21763
21764 \end_inset
21765 </cell>
21766 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21767 \begin_inset Text
21768
21769 \begin_layout Standard
21770 %f
21771 \begin_inset Foot
21772 status collapsed
21773
21774 \begin_layout Standard
21775 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
21776 \end_layout
21777
21778 \end_inset
21779
21780
21781 \end_layout
21782
21783 \end_inset
21784 </cell>
21785 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21786 \begin_inset Text
21787
21788 \begin_layout Standard
21789 -
21790 \end_layout
21791
21792 \end_inset
21793 </cell>
21794 </row>
21795 <row topline="true">
21796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21797 \begin_inset Text
21798
21799 \begin_layout Standard
21800 float formats %e %g
21801 \end_layout
21802
21803 \end_inset
21804 </cell>
21805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21806 \begin_inset Text
21807
21808 \begin_layout Standard
21809 -
21810 \end_layout
21811
21812 \end_inset
21813 </cell>
21814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21815 \begin_inset Text
21816
21817 \begin_layout Standard
21818 -
21819 \end_layout
21820
21821 \end_inset
21822 </cell>
21823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21824 \begin_inset Text
21825
21826 \begin_layout Standard
21827 -
21828 \end_layout
21829
21830 \end_inset
21831 </cell>
21832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21833 \begin_inset Text
21834
21835 \begin_layout Standard
21836 -
21837 \end_layout
21838
21839 \end_inset
21840 </cell>
21841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21842 \begin_inset Text
21843
21844 \begin_layout Standard
21845 -
21846 \end_layout
21847
21848 \end_inset
21849 </cell>
21850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21851 \begin_inset Text
21852
21853 \begin_layout Standard
21854 -
21855 \end_layout
21856
21857 \end_inset
21858 </cell>
21859 </row>
21860 <row topline="true" bottomline="true">
21861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21862 \begin_inset Text
21863
21864 \begin_layout Standard
21865 field width
21866 \end_layout
21867
21868 \end_inset
21869 </cell>
21870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21871 \begin_inset Text
21872
21873 \begin_layout Standard
21874 x
21875 \end_layout
21876
21877 \end_inset
21878 </cell>
21879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21880 \begin_inset Text
21881
21882 \begin_layout Standard
21883 x
21884 \end_layout
21885
21886 \end_inset
21887 </cell>
21888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21889 \begin_inset Text
21890
21891 \begin_layout Standard
21892 -
21893 \end_layout
21894
21895 \end_inset
21896 </cell>
21897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21898 \begin_inset Text
21899
21900 \begin_layout Standard
21901 x
21902 \end_layout
21903
21904 \end_inset
21905 </cell>
21906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21907 \begin_inset Text
21908
21909 \begin_layout Standard
21910 x
21911 \end_layout
21912
21913 \end_inset
21914 </cell>
21915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21916 \begin_inset Text
21917
21918 \begin_layout Standard
21919 -
21920 \end_layout
21921
21922 \end_inset
21923 </cell>
21924 </row>
21925 <row bottomline="true">
21926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21927 \begin_inset Text
21928
21929 \begin_layout Standard
21930 string speed
21931 \begin_inset Foot
21932 status collapsed
21933
21934 \begin_layout Standard
21935 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
21936 \backslash
21937 r', '
21938 \backslash
21939 n'); standard 8051 @ 22.1184 MHz, empty putchar()
21940 \end_layout
21941
21942 \end_inset
21943
21944 ,
21945 \end_layout
21946
21947 \begin_layout Standard
21948 small / large
21949 \end_layout
21950
21951 \end_inset
21952 </cell>
21953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21954 \begin_inset Text
21955
21956 \begin_layout Standard
21957 1.52 / 2.59 ms
21958 \end_layout
21959
21960 \end_inset
21961 </cell>
21962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21963 \begin_inset Text
21964
21965 \begin_layout Standard
21966 1.53 / 2.62 ms
21967 \end_layout
21968
21969 \end_inset
21970 </cell>
21971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21972 \begin_inset Text
21973
21974 \begin_layout Standard
21975 0.92 / 0.93 ms
21976 \end_layout
21977
21978 \end_inset
21979 </cell>
21980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21981 \begin_inset Text
21982
21983 \begin_layout Standard
21984 0.45 / 0.45 ms
21985 \end_layout
21986
21987 \end_inset
21988 </cell>
21989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21990 \begin_inset Text
21991
21992 \begin_layout Standard
21993 0.46 / 0.46 ms
21994 \end_layout
21995
21996 \end_inset
21997 </cell>
21998 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21999 \begin_inset Text
22000
22001 \begin_layout Standard
22002 0.45 / 0.45 ms
22003 \end_layout
22004
22005 \end_inset
22006 </cell>
22007 </row>
22008 <row bottomline="true">
22009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22010 \begin_inset Text
22011
22012 \begin_layout Standard
22013 int speed
22014 \begin_inset Foot
22015 status collapsed
22016
22017 \begin_layout Standard
22018 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
22019  putchar()
22020 \end_layout
22021
22022 \end_inset
22023
22024 ,
22025 \end_layout
22026
22027 \begin_layout Standard
22028 small / large
22029 \end_layout
22030
22031 \end_inset
22032 </cell>
22033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22034 \begin_inset Text
22035
22036 \begin_layout Standard
22037 3.01 / 3.61 ms
22038 \end_layout
22039
22040 \end_inset
22041 </cell>
22042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22043 \begin_inset Text
22044
22045 \begin_layout Standard
22046 3.01 / 3.61 ms
22047 \end_layout
22048
22049 \end_inset
22050 </cell>
22051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22052 \begin_inset Text
22053
22054 \begin_layout Standard
22055 3.51 / 18.13 ms
22056 \end_layout
22057
22058 \end_inset
22059 </cell>
22060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22061 \begin_inset Text
22062
22063 \begin_layout Standard
22064 0.22 / 0.22 ms
22065 \end_layout
22066
22067 \end_inset
22068 </cell>
22069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22070 \begin_inset Text
22071
22072 \begin_layout Standard
22073 0.23 / 0.23 ms
22074 \end_layout
22075
22076 \end_inset
22077 </cell>
22078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22079 \begin_inset Text
22080
22081 \begin_layout Standard
22082 0.25 / 0.25 ms
22083 \begin_inset Foot
22084 status collapsed
22085
22086 \begin_layout Standard
22087 printf_tiny integer speed is data dependent, worst case is 0.33 ms
22088 \end_layout
22089
22090 \end_inset
22091
22092
22093 \end_layout
22094
22095 \end_inset
22096 </cell>
22097 </row>
22098 <row bottomline="true">
22099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22100 \begin_inset Text
22101
22102 \begin_layout Standard
22103 long speed
22104 \begin_inset Foot
22105 status collapsed
22106
22107 \begin_layout Standard
22108 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
22109  empty putchar()
22110 \end_layout
22111
22112 \end_inset
22113
22114 ,
22115 \end_layout
22116
22117 \begin_layout Standard
22118 small / large
22119 \end_layout
22120
22121 \end_inset
22122 </cell>
22123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22124 \begin_inset Text
22125
22126 \begin_layout Standard
22127 5.37 / 6.31 ms
22128 \end_layout
22129
22130 \end_inset
22131 </cell>
22132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22133 \begin_inset Text
22134
22135 \begin_layout Standard
22136 5.37 / 6.31 ms
22137 \end_layout
22138
22139 \end_inset
22140 </cell>
22141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22142 \begin_inset Text
22143
22144 \begin_layout Standard
22145 8.71 / 40.65 ms
22146 \end_layout
22147
22148 \end_inset
22149 </cell>
22150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22151 \begin_inset Text
22152
22153 \begin_layout Standard
22154 0.40 / 0.40 ms
22155 \end_layout
22156
22157 \end_inset
22158 </cell>
22159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22160 \begin_inset Text
22161
22162 \begin_layout Standard
22163 0.40 / 0.40 ms
22164 \end_layout
22165
22166 \end_inset
22167 </cell>
22168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22169 \begin_inset Text
22170
22171 \begin_layout Standard
22172 -
22173 \end_layout
22174
22175 \end_inset
22176 </cell>
22177 </row>
22178 <row bottomline="true">
22179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22180 \begin_inset Text
22181
22182 \begin_layout Standard
22183 float speed
22184 \begin_inset Foot
22185 status collapsed
22186
22187 \begin_layout Standard
22188 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
22189  empty putchar()
22190 \end_layout
22191
22192 \end_inset
22193
22194 ,
22195 \end_layout
22196
22197 \begin_layout Standard
22198 small / large
22199 \end_layout
22200
22201 \end_inset
22202 </cell>
22203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22204 \begin_inset Text
22205
22206 \begin_layout Standard
22207 -
22208 \end_layout
22209
22210 \end_inset
22211 </cell>
22212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22213 \begin_inset Text
22214
22215 \begin_layout Standard
22216 7.49 / 22.47 ms
22217 \end_layout
22218
22219 \end_inset
22220 </cell>
22221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22222 \begin_inset Text
22223
22224 \begin_layout Standard
22225 -
22226 \end_layout
22227
22228 \end_inset
22229 </cell>
22230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22231 \begin_inset Text
22232
22233 \begin_layout Standard
22234 -
22235 \end_layout
22236
22237 \end_inset
22238 </cell>
22239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22240 \begin_inset Text
22241
22242 \begin_layout Standard
22243 1.04 / 1.04 ms
22244 \end_layout
22245
22246 \end_inset
22247 </cell>
22248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22249 \begin_inset Text
22250
22251 \begin_layout Standard
22252 -
22253 \end_layout
22254
22255 \end_inset
22256 </cell>
22257 </row>
22258 </lyxtabular>
22259
22260 \end_inset
22261
22262
22263 \end_layout
22264
22265 \begin_layout Subsubsection
22266 <malloc.h>
22267 \begin_inset LatexCommand index
22268 name "malloc.h"
22269
22270 \end_inset
22271
22272
22273 \end_layout
22274
22275 \begin_layout Standard
22276 As of SDCC 2.6.2 you no longer need to call an initialization routine before
22277  using dynamic memory allocation
22278 \begin_inset LatexCommand index
22279 name "dynamic memory allocation (malloc)"
22280
22281 \end_inset
22282
22283  and a default heap
22284 \begin_inset LatexCommand index
22285 name "heap (malloc)"
22286
22287 \end_inset
22288
22289  space of 1024 bytes is provided for malloc to allocate memory from.
22290  If you need a different heap size you need to recompile _heap.c with the
22291  required size defined in HEAP_SIZE.
22292  It is recommended to make a copy of this file into your project directory
22293  and compile it there with:
22294 \end_layout
22295
22296 \begin_layout Verse
22297
22298 \family typewriter
22299 sdcc -c _heap.c -D HEAD_SIZE=2048
22300 \end_layout
22301
22302 \begin_layout Standard
22303 And then link it with:
22304 \end_layout
22305
22306 \begin_layout Verse
22307
22308 \family typewriter
22309 sdcc main.rel _heap.rel
22310 \end_layout
22311
22312 \begin_layout Subsection
22313 Math functions (sinf, powf, sqrtf etc.)
22314 \end_layout
22315
22316 \begin_layout Subsubsection
22317 <math.h>
22318 \end_layout
22319
22320 \begin_layout Standard
22321 See definitions in file <math.h>.
22322 \end_layout
22323
22324 \begin_layout Subsection
22325 Other libraries
22326 \end_layout
22327
22328 \begin_layout Standard
22329 Libraries
22330 \begin_inset LatexCommand index
22331 name "Libraries"
22332
22333 \end_inset
22334
22335  included in SDCC should have a license at least as liberal as the GNU Lesser
22336  General Public License
22337 \begin_inset LatexCommand index
22338 name "GNU Lesser General Public License, LGPL"
22339
22340 \end_inset
22341
22342  
22343 \emph on
22344 LGPL
22345 \emph default
22346 .
22347 \end_layout
22348
22349 \begin_layout Standard
22350 \begin_inset Note Note
22351 status collapsed
22352
22353 \begin_layout Standard
22354 license statements for the libraries are missing.
22355  sdcc/device/lib/ser_ir.c
22356 \end_layout
22357
22358 \begin_layout Standard
22359 or _decdptr f.e.
22360  come with a GPL (as opposed to LGPL) License - this will not be liberal
22361  enough for many embedded programmers.
22362 \end_layout
22363
22364 \end_inset
22365
22366
22367 \end_layout
22368
22369 \begin_layout Standard
22370 If you have ported some library or want to share experience about some code
22371  which f.e.
22372  falls into any of these categories Busses (I
22373 \begin_inset Formula $^{\textrm{2}}$
22374 \end_inset
22375
22376 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
22377  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
22378  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
22379 \begin_inset LatexCommand url
22380 target "http://sourceforge.net/mail/?group_id=599"
22381
22382 \end_inset
22383
22384 \InsetSpace ~
22385 would certainly like to hear about it.
22386 \end_layout
22387
22388 \begin_layout Standard
22389 Programmers coding for embedded systems are not especially famous for being
22390  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
22391 e these references are very valuable.
22392  Let's help to create a climate where information is shared.
22393 \begin_inset VSpace bigskip
22394 \end_inset
22395
22396
22397 \end_layout
22398
22399 \begin_layout Section
22400 Memory Models
22401 \end_layout
22402
22403 \begin_layout Subsection
22404 MCS51 Memory Models
22405 \begin_inset LatexCommand index
22406 name "Memory model"
22407
22408 \end_inset
22409
22410
22411 \begin_inset LatexCommand index
22412 name "MCS51 memory model"
22413
22414 \end_inset
22415
22416
22417 \end_layout
22418
22419 \begin_layout Subsubsection
22420 Small, Medium and Large
22421 \end_layout
22422
22423 \begin_layout Standard
22424 SDCC allows three memory models for MCS51 code, 
22425 \shape slanted
22426 small, medium
22427 \shape default
22428  and 
22429 \shape slanted
22430 large
22431 \shape default
22432 .
22433  Modules compiled with different memory models should 
22434 \emph on
22435 never
22436 \emph default
22437  be combined together or the results would be unpredictable.
22438  The library routines supplied with the compiler are compiled as small,
22439  medium and large.
22440  The compiled library modules are contained in separate directories as small,
22441  medium and large so that you can link to the appropriate set.
22442 \end_layout
22443
22444 \begin_layout Standard
22445 When the medium or large model is used all variables declared without a
22446  storage class will be allocated into the external ram, this includes all
22447  parameters and local variables (for non-reentrant
22448 \begin_inset LatexCommand index
22449 name "reentrant"
22450
22451 \end_inset
22452
22453  functions).
22454  When the small model is used variables without storage class are allocated
22455  in the internal ram.
22456 \end_layout
22457
22458 \begin_layout Standard
22459 Judicious usage of the processor specific storage classes
22460 \begin_inset LatexCommand index
22461 name "Storage class"
22462
22463 \end_inset
22464
22465  and the 'reentrant' function type will yield much more efficient code,
22466  than using the large model.
22467  Several optimizations are disabled when the program is compiled using the
22468  large model, it is therefore recommended that the small model be used unless
22469  absolutely required.
22470 \end_layout
22471
22472 \begin_layout Subsubsection
22473 External Stack
22474 \begin_inset LatexCommand label
22475 name "sub:External-Stack"
22476
22477 \end_inset
22478
22479
22480 \begin_inset LatexCommand index
22481 name "stack"
22482
22483 \end_inset
22484
22485
22486 \begin_inset LatexCommand index
22487 name "External stack (mcs51)"
22488
22489 \end_inset
22490
22491
22492 \end_layout
22493
22494 \begin_layout Standard
22495 The external stack (-
22496 \begin_inset ERT
22497 status collapsed
22498
22499 \begin_layout Standard
22500
22501
22502 \backslash
22503 /
22504 \end_layout
22505
22506 \end_inset
22507
22508 -xstack option
22509 \begin_inset LatexCommand index
22510 name "-\\/-xstack"
22511
22512 \end_inset
22513
22514 ) is located in pdata
22515 \begin_inset LatexCommand index
22516 name "pdata (mcs51, ds390 storage class)"
22517
22518 \end_inset
22519
22520  memory (usually at the start of the external ram segment) and uses all
22521  unused space in pdata (max.
22522  256 bytes).
22523  When -
22524 \begin_inset ERT
22525 status collapsed
22526
22527 \begin_layout Standard
22528
22529
22530 \backslash
22531 /
22532 \end_layout
22533
22534 \end_inset
22535
22536 -xstack option is used to compile the program, the parameters and local
22537  variables
22538 \begin_inset LatexCommand index
22539 name "local variables"
22540
22541 \end_inset
22542
22543  of all reentrant functions are allocated in this area.
22544  This option is provided for programs with large stack space requirements.
22545  When used with the -
22546 \begin_inset ERT
22547 status collapsed
22548
22549 \begin_layout Standard
22550
22551
22552 \backslash
22553 /
22554 \end_layout
22555
22556 \end_inset
22557
22558 -stack-auto
22559 \begin_inset LatexCommand index
22560 name "-\\/-stack-auto"
22561
22562 \end_inset
22563
22564  option, all parameters and local variables are allocated on the external
22565  stack (note: support libraries will need to be recompiled with the same
22566  options.
22567  There is a predefined target in the library makefile).
22568 \end_layout
22569
22570 \begin_layout Standard
22571 The compiler outputs the higher order address byte of the external ram segment
22572  into port P2
22573 \begin_inset LatexCommand index
22574 name "P2 (mcs51 sfr)"
22575
22576 \end_inset
22577
22578  (see also section 
22579 \begin_inset LatexCommand ref
22580 reference "sub:MCS51-variants"
22581
22582 \end_inset
22583
22584 ), therefore when using the External Stack option, this port 
22585 \emph on
22586 may not
22587 \emph default
22588  be used by the application program.
22589 \end_layout
22590
22591 \begin_layout Subsection
22592 DS390 Memory Model
22593 \begin_inset LatexCommand index
22594 name "Memory model"
22595
22596 \end_inset
22597
22598
22599 \begin_inset LatexCommand index
22600 name "DS390 memory model"
22601
22602 \end_inset
22603
22604
22605 \end_layout
22606
22607 \begin_layout Standard
22608 The only model supported is Flat 24
22609 \begin_inset LatexCommand index
22610 name "Flat 24 (DS390 memory model)"
22611
22612 \end_inset
22613
22614 .
22615  This generates code for the 24 bit contiguous addressing mode of the Dallas
22616  DS80C390 part.
22617  In this mode, up to four meg of external RAM or code space can be directly
22618  addressed.
22619  See the data sheets at www.dalsemi.com for further information on this part.
22620 \newline
22621
22622 \newline
22623 Note
22624  that the compiler does not generate any code to place the processor into
22625  24 bitmode (although 
22626 \emph on
22627 tinibios
22628 \emph default
22629  in the ds390 libraries will do that for you).
22630  If you don't use 
22631 \emph on
22632 tinibios
22633 \emph default
22634
22635 \begin_inset LatexCommand index
22636 name "Tinibios (DS390)"
22637
22638 \end_inset
22639
22640 , the boot loader or similar code must ensure that the processor is in 24
22641  bit contiguous addressing mode before calling the SDCC startup code.
22642 \newline
22643
22644 \newline
22645 Like
22646  the 
22647 \emph on
22648 -
22649 \begin_inset ERT
22650 status collapsed
22651
22652 \begin_layout Standard
22653
22654
22655 \backslash
22656 /
22657 \end_layout
22658
22659 \end_inset
22660
22661 -model-large
22662 \emph default
22663  option, variables will by default be placed into the XDATA segment.
22664  
22665 \newline
22666
22667 \newline
22668 Segments may be placed anywhere in the 4 meg address space using the usual
22669  -
22670 \begin_inset ERT
22671 status collapsed
22672
22673 \begin_layout Standard
22674
22675
22676 \backslash
22677 /
22678 \end_layout
22679
22680 \end_inset
22681
22682 -*-loc options.
22683  Note that if any segments are located above 64K, the -r flag must be passed
22684  to the linker to generate the proper segment relocations, and the Intel
22685  HEX output format must be used.
22686  The -r flag can be passed to the linker by using the option 
22687 \emph on
22688 -Wl-r
22689 \emph default
22690  on the SDCC command line.
22691  However, currently the linker can not handle code segments > 64k.
22692 \end_layout
22693
22694 \begin_layout Section
22695 Pragmas
22696 \begin_inset LatexCommand label
22697 name "sec:Pragmas"
22698
22699 \end_inset
22700
22701
22702 \begin_inset LatexCommand index
22703 name "Pragmas"
22704
22705 \end_inset
22706
22707
22708 \end_layout
22709
22710 \begin_layout Standard
22711 Pragmas are used to turn on and/or off certain compiler options.
22712  Some of them are closely related to corresponding command-line options
22713  (see section 
22714 \begin_inset LatexCommand vref
22715 reference "sec:Command-Line-Options"
22716
22717 \end_inset
22718
22719 ).
22720 \newline
22721 Pragmas should be placed before and/or after a function, placing pragmas
22722  inside a function body could have unpredictable results.
22723 \newline
22724
22725 \newline
22726 SDCC supports the
22727  following #pragma directives:
22728 \end_layout
22729
22730 \begin_layout Itemize
22731
22732 \series bold
22733 save
22734 \series default
22735
22736 \begin_inset LatexCommand index
22737 name "\\#pragma save"
22738
22739 \end_inset
22740
22741  - this will save most current options to the save/restore stack.
22742  See #pragma\InsetSpace ~
22743 restore.
22744 \end_layout
22745
22746 \begin_layout Itemize
22747
22748 \series bold
22749 restore
22750 \series default
22751
22752 \begin_inset LatexCommand index
22753 name "\\#pragma restore"
22754
22755 \end_inset
22756
22757  - will restore saved options from the last save.
22758  saves & restores can be nested.
22759  SDCC uses a save/restore stack: save pushes current options to the stack,
22760  restore pulls current options from the stack.
22761  See #pragma\InsetSpace ~
22762 save.
22763 \newline
22764
22765 \end_layout
22766
22767 \begin_layout Itemize
22768
22769 \series bold
22770 callee_saves
22771 \series default
22772
22773 \begin_inset LatexCommand index
22774 name "\\#pragma callee\\_saves"
22775
22776 \end_inset
22777
22778
22779 \begin_inset LatexCommand index
22780 name "function prologue"
22781
22782 \end_inset
22783
22784  function1[,function2[,function3...]] 
22785 \begin_inset LatexCommand label
22786 name "ite:callee_saves-function1[,function2[,function3...]]--"
22787
22788 \end_inset
22789
22790 - The compiler by default uses a caller saves convention for register saving
22791  across function calls, however this can cause unnecessary register pushing
22792  and popping
22793 \begin_inset LatexCommand index
22794 name "push/pop"
22795
22796 \end_inset
22797
22798  when calling small functions from larger functions.
22799  This option can be used to switch off the register saving convention for
22800  the function names specified.
22801  The compiler will not save registers when calling these functions, extra
22802  code need to be manually inserted at the entry and exit for these functions
22803  to save and restore the registers used by these functions, this can SUBSTANTIAL
22804 LY reduce code and improve run time performance of the generated code.
22805  In the future the compiler (with inter procedural analysis) may be able
22806  to determine the appropriate scheme to use for each function call.
22807  If -
22808 \begin_inset ERT
22809 status collapsed
22810
22811 \begin_layout Standard
22812
22813
22814 \backslash
22815 /
22816 \end_layout
22817
22818 \end_inset
22819
22820 -callee-saves command line option is used (see page 
22821 \begin_inset LatexCommand vpageref
22822 reference "lyx:--callee-saves-function1[,function2][,function3]..."
22823
22824 \end_inset
22825
22826 ), the function names specified in #pragma\InsetSpace ~
22827 callee_saves
22828 \begin_inset LatexCommand index
22829 name "\\#pragma callee\\_saves"
22830
22831 \end_inset
22832
22833  is appended to the list of functions specified in the command line.
22834 \end_layout
22835
22836 \begin_layout Itemize
22837
22838 \series bold
22839 exclude
22840 \series default
22841
22842 \begin_inset LatexCommand index
22843 name "\\#pragma exclude"
22844
22845 \end_inset
22846
22847  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
22848  of pairs of push/pop
22849 \begin_inset LatexCommand index
22850 name "push/pop"
22851
22852 \end_inset
22853
22854  instructions in 
22855 \emph on
22856 I
22857 \emph default
22858 nterrupt
22859 \begin_inset LatexCommand index
22860 name "interrupt"
22861
22862 \end_inset
22863
22864  
22865 \emph on
22866 S
22867 \emph default
22868 ervice 
22869 \emph on
22870 R
22871 \emph default
22872 outines.
22873  The directive should be placed immediately before the ISR function definition
22874  and it affects ALL ISR functions following it.
22875  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
22876 exclude\InsetSpace ~
22877 none
22878 \begin_inset LatexCommand index
22879 name "\\#pragma exclude"
22880
22881 \end_inset
22882
22883 .
22884  See also the related keyword _naked
22885 \begin_inset LatexCommand index
22886 name "\\_naked"
22887
22888 \end_inset
22889
22890
22891 \begin_inset LatexCommand index
22892 name "\\_\\_naked"
22893
22894 \end_inset
22895
22896 .
22897 \end_layout
22898
22899 \begin_layout Itemize
22900
22901 \series bold
22902 less_pedantic
22903 \series default
22904
22905 \begin_inset LatexCommand index
22906 name "pedantic"
22907
22908 \end_inset
22909
22910
22911 \begin_inset LatexCommand index
22912 name "\\#pragma less\\_pedantic"
22913
22914 \end_inset
22915
22916  
22917 \begin_inset LatexCommand label
22918 name "ite:less_pedantic"
22919
22920 \end_inset
22921
22922 - the compiler will not warn you anymore for obvious mistakes, you're on
22923  your own now ;-( .
22924  See also the command line option -
22925 \begin_inset ERT
22926 status collapsed
22927
22928 \begin_layout Standard
22929
22930
22931 \backslash
22932 /
22933 \end_layout
22934
22935 \end_inset
22936
22937 -less-pedantic 
22938 \begin_inset LatexCommand vpageref
22939 reference "lyx:--less-pedantic"
22940
22941 \end_inset
22942
22943 .
22944  
22945 \newline
22946 More specifically, the following warnings will be disabled: 
22947 \shape italic
22948 comparison is always [true/false] due to limited range of data type
22949 \shape default
22950  (94); 
22951 \shape italic
22952 overflow in implicit constant conversion
22953 \shape default
22954  (158); [the (in)famous] 
22955 \shape italic
22956 conditional flow changed by optimizer: so said EVELYN the modified DOG
22957 \shape default
22958  (110); 
22959 \shape italic
22960 function '[function name]' must return value
22961 \shape default
22962  (59).
22963  
22964 \newline
22965 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
22966  level) are disabled, too, namely: 
22967 \shape italic
22968 constant value '[
22969 \begin_inset Note Note
22970 status collapsed
22971
22972 \begin_layout Standard
22973 dunno what comes here - this warning appears to be unused altogether
22974 \end_layout
22975
22976 \end_inset
22977
22978 ]', out of range
22979 \shape default
22980  (81); 
22981 \shape italic
22982 [left/right] shifting more than size of object changed to zero
22983 \shape default
22984  (116); 
22985 \shape italic
22986 unreachable code
22987 \shape default
22988  (126); 
22989 \shape italic
22990 integer overflow in expression
22991 \shape default
22992  (165); 
22993 \shape italic
22994 unmatched #pragma save and #pragma restore
22995 \shape default
22996  (170); 
22997 \shape italic
22998 comparison of 'signed char' with 'unsigned char' requires promotion to int
22999 \shape default
23000  (185); 
23001 \shape italic
23002 ISO C90 does not support flexible array members
23003 \shape default
23004  (187); 
23005 \shape italic
23006 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
23007 nam
23008 e]':\InsetSpace ~
23009 [
23010 \begin_inset Note Note
23011 status collapsed
23012
23013 \begin_layout Standard
23014 appears to be always blank - what was supposed to be here?
23015 \end_layout
23016
23017 \end_inset
23018
23019 ]
23020 \shape default
23021  (114); 
23022 \shape italic
23023 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
23024  complexity [number]
23025 \shape default
23026  (121).
23027 \end_layout
23028
23029 \begin_layout Itemize
23030
23031 \series bold
23032 disable_warning
23033 \series default
23034  <nnnn>
23035 \begin_inset LatexCommand index
23036 name "\\#pragma disable\\_warning"
23037
23038 \end_inset
23039
23040  - the compiler will not warn you anymore about warning number <nnnn>.
23041 \end_layout
23042
23043 \begin_layout Itemize
23044
23045 \series bold
23046 nogcse
23047 \series default
23048
23049 \begin_inset LatexCommand index
23050 name "\\#pragma nogcse"
23051
23052 \end_inset
23053
23054  - will stop global common subexpression elimination.
23055 \end_layout
23056
23057 \begin_layout Itemize
23058
23059 \series bold
23060 noinduction
23061 \series default
23062
23063 \begin_inset LatexCommand index
23064 name "\\#pragma noinduction"
23065
23066 \end_inset
23067
23068  - will stop loop induction optimizations.
23069 \end_layout
23070
23071 \begin_layout Itemize
23072
23073 \series bold
23074 noinvariant
23075 \series default
23076
23077 \begin_inset LatexCommand index
23078 name "\\#pragma noinvariant"
23079
23080 \end_inset
23081
23082  - will not do loop invariant optimizations.
23083  For more details see Loop Invariants in section
23084 \begin_inset LatexCommand ref
23085 reference "sub:Loop-Optimizations"
23086
23087 \end_inset
23088
23089 .
23090 \end_layout
23091
23092 \begin_layout Itemize
23093
23094 \series bold
23095 noiv
23096 \series default
23097
23098 \begin_inset LatexCommand index
23099 name "\\#pragma noiv"
23100
23101 \end_inset
23102
23103  - Do not generate interrupt
23104 \begin_inset LatexCommand index
23105 name "interrupt"
23106
23107 \end_inset
23108
23109  vector table
23110 \begin_inset LatexCommand index
23111 name "interrupt vector table"
23112
23113 \end_inset
23114
23115  entries for all ISR functions defined after the pragma.
23116  This is useful in cases where the interrupt vector table must be defined
23117  manually, or when there is a secondary, manually defined interrupt vector
23118  table (e.g.
23119  for the autovector feature of the Cypress EZ-USB FX2).
23120  More elegantly this can be achieved by omitting the optional interrupt
23121  number after the interrupt keyword, see section 
23122 \begin_inset LatexCommand ref
23123 reference "sub:Interrupt-Service-Routines"
23124
23125 \end_inset
23126
23127 \InsetSpace ~
23128 about interrupts.
23129 \end_layout
23130
23131 \begin_layout Itemize
23132
23133 \series bold
23134 nojtbound
23135 \series default
23136
23137 \begin_inset LatexCommand index
23138 name "\\#pragma nojtbound"
23139
23140 \end_inset
23141
23142  - will not generate code for boundary value checking, when switch statements
23143  are turned into jump-tables (dangerous).
23144  For more details see section 
23145 \begin_inset LatexCommand ref
23146 reference "sub:'switch'-Statements"
23147
23148 \end_inset
23149
23150 .
23151 \end_layout
23152
23153 \begin_layout Itemize
23154
23155 \series bold
23156 noloopreverse
23157 \series default
23158
23159 \begin_inset LatexCommand index
23160 name "\\#pragma noloopreverse"
23161
23162 \end_inset
23163
23164  - Will not do loop reversal optimization
23165 \end_layout
23166
23167 \begin_layout Itemize
23168
23169 \series bold
23170 nooverlay
23171 \series default
23172
23173 \begin_inset LatexCommand index
23174 name "\\#pragma nooverlay"
23175
23176 \end_inset
23177
23178  - the compiler will not overlay the parameters and local variables of a
23179  function.
23180 \end_layout
23181
23182 \begin_layout Itemize
23183
23184 \series bold
23185 stackauto
23186 \series default
23187
23188 \begin_inset LatexCommand index
23189 name "\\#pragma stackauto"
23190
23191 \end_inset
23192
23193 - See option -
23194 \begin_inset ERT
23195 status collapsed
23196
23197 \begin_layout Standard
23198
23199
23200 \backslash
23201 /
23202 \end_layout
23203
23204 \end_inset
23205
23206 -stack-auto
23207 \begin_inset LatexCommand index
23208 name "-\\/-stack-auto"
23209
23210 \end_inset
23211
23212  and section 
23213 \begin_inset LatexCommand ref
23214 reference "sec:Parameters-and-Local-Variables"
23215
23216 \end_inset
23217
23218  Parameters and Local Variables.
23219 \end_layout
23220
23221 \begin_layout Itemize
23222
23223 \series bold
23224 opt_code_speed
23225 \series default
23226  
23227 \begin_inset LatexCommand index
23228 name "\\#pragma opt\\_code\\_speed"
23229
23230 \end_inset
23231
23232 - The compiler will optimize code generation towards fast code, possibly
23233  at the expense of code size.
23234  Currently this has little effect.
23235 \end_layout
23236
23237 \begin_layout Itemize
23238
23239 \series bold
23240 opt_code_size
23241 \series default
23242  
23243 \begin_inset LatexCommand index
23244 name "\\#pragma opt\\_code\\_size"
23245
23246 \end_inset
23247
23248 - The compiler will optimize code generation towards compact code, possibly
23249  at the expense of code speed.
23250  Currently this has little effect.
23251 \end_layout
23252
23253 \begin_layout Itemize
23254
23255 \series bold
23256 opt_code_balanced
23257 \series default
23258  
23259 \begin_inset LatexCommand index
23260 name "\\#pragma opt\\_code\\_balanced"
23261
23262 \end_inset
23263
23264 - The compiler will attempt to generate code that is both compact and fast,
23265  as long as meeting one goal is not a detriment to the other (this is the
23266  default).
23267  
23268 \end_layout
23269
23270 \begin_layout Itemize
23271
23272 \series bold
23273 std_sdcc89
23274 \series default
23275  
23276 \begin_inset LatexCommand index
23277 name "\\#pragma std\\_sdcc89"
23278
23279 \end_inset
23280
23281 - Generally follow the C89 standard, but allow SDCC features that conflict
23282  with the standard (default).
23283 \end_layout
23284
23285 \begin_layout Itemize
23286
23287 \series bold
23288 std_c89
23289 \series default
23290  
23291 \begin_inset LatexCommand index
23292 name "\\#pragma std\\_c89"
23293
23294 \end_inset
23295
23296 - Follow the C89 standard and disable SDCC features that conflict with the
23297  standard.
23298 \end_layout
23299
23300 \begin_layout Itemize
23301
23302 \series bold
23303 std_sdcc99
23304 \series default
23305  
23306 \begin_inset LatexCommand index
23307 name "\\#pragma std\\_sdcc99"
23308
23309 \end_inset
23310
23311 - Generally follow the C99 standard, but allow SDCC features that conflict
23312  with the standard (incomplete support).
23313 \end_layout
23314
23315 \begin_layout Itemize
23316
23317 \series bold
23318 std_c99
23319 \series default
23320  
23321 \begin_inset LatexCommand index
23322 name "\\#pragma std\\_c99"
23323
23324 \end_inset
23325
23326 - Follow the C99 standard and disable SDCC features that conflict with the
23327  standard (incomplete support).
23328 \end_layout
23329
23330 \begin_layout Itemize
23331
23332 \series bold
23333 codeseg
23334 \series default
23335  <name>
23336 \begin_inset LatexCommand index
23337 name "\\#pragma codeseg"
23338
23339 \end_inset
23340
23341 - Use this name (max.
23342  8 characters) for the code segment.
23343  See option -
23344 \begin_inset ERT
23345 status collapsed
23346
23347 \begin_layout Standard
23348
23349
23350 \backslash
23351 /
23352 \end_layout
23353
23354 \end_inset
23355
23356 -codeseg.
23357 \end_layout
23358
23359 \begin_layout Itemize
23360
23361 \series bold
23362 constseg
23363 \series default
23364  <name>
23365 \begin_inset LatexCommand index
23366 name "\\#pragma constseg"
23367
23368 \end_inset
23369
23370 - Use this name (max.
23371  8 characters) for the const segment.
23372  See option -
23373 \begin_inset ERT
23374 status collapsed
23375
23376 \begin_layout Standard
23377
23378
23379 \backslash
23380 /
23381 \end_layout
23382
23383 \end_inset
23384
23385 -constseg.
23386 \end_layout
23387
23388 \begin_layout Standard
23389 The preprocessor SDCPP
23390 \begin_inset LatexCommand index
23391 name "sdcpp (preprocessor)"
23392
23393 \end_inset
23394
23395  supports the following #pragma directives:
23396 \end_layout
23397
23398 \begin_layout Itemize
23399
23400 \series bold
23401 pedantic_parse_number
23402 \series default
23403
23404 \begin_inset LatexCommand index
23405 name "pedantic"
23406
23407 \end_inset
23408
23409
23410 \begin_inset LatexCommand index
23411 name "\\#pragma pedantic\\_parse\\_number"
23412
23413 \end_inset
23414
23415  (+ | -) 
23416 \begin_inset LatexCommand label
23417 name "ite:pedantic_parse_number"
23418
23419 \end_inset
23420
23421 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
23422  properly and the macro LO_B(3) gets expanded.
23423  Default is off.
23424  See also the -
23425 \begin_inset ERT
23426 status collapsed
23427
23428 \begin_layout Standard
23429
23430
23431 \backslash
23432 /
23433 \end_layout
23434
23435 \end_inset
23436
23437 -pedantic-parse-number command line option 
23438 \begin_inset LatexCommand vpageref
23439 reference "lyx:-pedantic-parse-number"
23440
23441 \end_inset
23442
23443 .
23444  
23445 \newline
23446 Below is an example on how to use this pragma.
23447  
23448 \emph on
23449 Note: this functionality is not in conformance with standard!
23450 \end_layout
23451
23452 \begin_layout Verse
23453
23454 \family typewriter
23455 #pragma pedantic_parse_number +
23456 \begin_inset LatexCommand index
23457 name "\\#pragma pedantic\\_parse\\_number"
23458
23459 \end_inset
23460
23461
23462 \newline
23463
23464 \newline
23465 #define LO_B(x) ((x) & 0xff)
23466 \newline
23467
23468 \newline
23469 unsigned char foo(void)
23470 \newline
23471 {
23472 \newline
23473 \InsetSpace ~
23474 \InsetSpace ~
23475 \InsetSpace ~
23476 unsigned char c=0xfe-LO_B(3)
23477 ;
23478 \newline
23479
23480 \newline
23481 \InsetSpace ~
23482 \InsetSpace ~
23483 \InsetSpace ~
23484 return c;
23485 \newline
23486 }
23487 \newline
23488
23489 \end_layout
23490
23491 \begin_layout Itemize
23492
23493 \series bold
23494 preproc_asm
23495 \series default
23496
23497 \begin_inset LatexCommand index
23498 name "\\#pragma preproc\\_asm"
23499
23500 \end_inset
23501
23502  (+ | -) - switch _asm _endasm block preprocessing on / off.
23503  Default is on.
23504  You use this pragma to define multilines of assembly code.
23505  This will prevent the preprocessor from changing the formatting required
23506  by assembly code.
23507  Below is an example on how to use this pragma.
23508 \end_layout
23509
23510 \begin_layout Verse
23511
23512 \family typewriter
23513 #pragma preproc_asm -
23514 \begin_inset LatexCommand index
23515 name "\\#pragma preproc\\_asm"
23516
23517 \end_inset
23518
23519
23520 \newline
23521 #define MYDELAY _asm
23522 \newline
23523 \InsetSpace ~
23524 \InsetSpace ~
23525 \InsetSpace ~
23526 nop ;my assembly comment...
23527 \newline
23528 \InsetSpace ~
23529 \InsetSpace ~
23530 \InsetSpace ~
23531 nop
23532 \newline
23533 \InsetSpace ~
23534 \InsetSpace ~
23535 \InsetSpace ~
23536 nop
23537 \newline
23538 _endasm
23539 \newline
23540 #pragma preproc_asm
23541  +
23542 \newline
23543
23544 \newline
23545 void foo (void) 
23546 \newline
23547
23548 \newline
23549 \InsetSpace ~
23550 \InsetSpace ~
23551 \InsetSpace ~
23552  ...
23553  
23554 \newline
23555 \InsetSpace ~
23556 \InsetSpace ~
23557 \InsetSpace ~
23558  MYDELAY;
23559 \newline
23560 \InsetSpace ~
23561 \InsetSpace ~
23562 \InsetSpace ~
23563  ...
23564  
23565 \newline
23566
23567 \newline
23568
23569 \end_layout
23570
23571 \begin_layout Itemize
23572
23573 \series bold
23574 sdcc_hash
23575 \series default
23576
23577 \begin_inset LatexCommand index
23578 name "\\#pragma sdcc\\_hash"
23579
23580 \end_inset
23581
23582  (+ | -) - Allow "naked" hash in macro definition, for example:
23583 \newline
23584
23585 \family typewriter
23586 #define DIR_LO(x) #(x & 0xff)
23587 \family default
23588
23589 \newline
23590 Default is off.
23591  Below is an example on how to use this pragma.
23592 \end_layout
23593
23594 \begin_layout Verse
23595
23596 \family typewriter
23597 #pragma preproc_asm +
23598 \newline
23599 #pragma sdcc_hash +
23600 \begin_inset LatexCommand index
23601 name "\\#pragma sdcc\\_hash"
23602
23603 \end_inset
23604
23605
23606 \newline
23607
23608 \newline
23609 #define ROMCALL(x) 
23610 \backslash
23611
23612 \newline
23613 \InsetSpace ~
23614 \InsetSpace ~
23615 \InsetSpace ~
23616 mov R6_B3, #(x & 0xff) 
23617 \backslash
23618
23619 \newline
23620 \InsetSpace ~
23621 \InsetSpace ~
23622 \InsetSpace ~
23623 mov R7_B3, #((x >> 8) & 0xff) 
23624 \backslash
23625
23626 \newline
23627 \InsetSpace ~
23628 \InsetSpace ~
23629 \InsetSpace ~
23630 lcall __romcall
23631 \newline
23632
23633 \newline
23634 ...
23635 \newline
23636 _asm
23637 \newline
23638 ROMCALL(72)
23639 \newline
23640 _endasm;
23641 \newline
23642 ...
23643 \newline
23644
23645 \end_layout
23646
23647 \begin_layout Standard
23648 Some of the pragmas are intended to be used to turn-on or off certain optimizati
23649 ons which might cause the compiler to generate extra stack and/or data space
23650  to store compiler generated temporary variables.
23651  This usually happens in large functions.
23652  Pragma directives should be used as shown in the following example, they
23653  are used to control options and optimizations for a given function.
23654  
23655 \end_layout
23656
23657 \begin_layout Verse
23658
23659 \family typewriter
23660 #pragma save
23661 \begin_inset LatexCommand index
23662 name "\\#pragma save"
23663
23664 \end_inset
23665
23666  \InsetSpace ~
23667 \InsetSpace ~
23668 \InsetSpace ~
23669 \InsetSpace ~
23670 \InsetSpace ~
23671 \InsetSpace ~
23672 \InsetSpace ~
23673 /* save the current settings */ 
23674 \newline
23675 #pragma nogcse
23676 \begin_inset LatexCommand index
23677 name "\\#pragma nogcse"
23678
23679 \end_inset
23680
23681  \InsetSpace ~
23682 \InsetSpace ~
23683 \InsetSpace ~
23684 \InsetSpace ~
23685 \InsetSpace ~
23686 /* turnoff global subexpression elimination */ 
23687 \newline
23688 #pragma noinduction
23689 \begin_inset LatexCommand index
23690 name "\\#pragma noinduction"
23691
23692 \end_inset
23693
23694  /* turn off induction optimizations */ 
23695 \newline
23696 int foo () 
23697 \newline
23698
23699 \newline
23700 \InsetSpace ~
23701  \InsetSpace ~
23702  ...
23703  
23704 \newline
23705 \InsetSpace ~
23706  \InsetSpace ~
23707  /* large code */ 
23708 \newline
23709 \InsetSpace ~
23710  \InsetSpace ~
23711  ...
23712  
23713 \newline
23714
23715 \newline
23716 #pragma restore
23717 \begin_inset LatexCommand index
23718 name "\\#pragma restore"
23719
23720 \end_inset
23721
23722  /* turn the optimizations back on */
23723 \end_layout
23724
23725 \begin_layout Standard
23726 The compiler will generate a warning message when extra space is allocated.
23727  It is strongly recommended that the save and restore pragmas be used when
23728  changing options for a function.
23729 \newline
23730
23731 \newline
23732
23733 \newline
23734
23735 \end_layout
23736
23737 \begin_layout Section
23738 Defines Created by the Compiler
23739 \end_layout
23740
23741 \begin_layout Standard
23742 The compiler creates the following #defines
23743 \begin_inset LatexCommand index
23744 name "\\#defines"
23745
23746 \end_inset
23747
23748
23749 \begin_inset LatexCommand index
23750 name "Defines created by the compiler"
23751
23752 \end_inset
23753
23754 :
23755 \newline
23756
23757 \end_layout
23758
23759 \begin_layout Standard
23760 \begin_inset Tabular
23761 <lyxtabular version="3" rows="15" columns="2">
23762 <features>
23763 <column alignment="left" valignment="top" leftline="true" width="3in">
23764 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
23765 <row topline="true" bottomline="true">
23766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23767 \begin_inset Text
23768
23769 \begin_layout Standard
23770
23771 \series bold
23772 #define
23773 \end_layout
23774
23775 \end_inset
23776 </cell>
23777 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23778 \begin_inset Text
23779
23780 \begin_layout Standard
23781
23782 \series bold
23783 Description
23784 \end_layout
23785
23786 \end_inset
23787 </cell>
23788 </row>
23789 <row topline="true">
23790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23791 \begin_inset Text
23792
23793 \begin_layout Standard
23794 SDCC
23795 \begin_inset LatexCommand index
23796 name "SDCC"
23797
23798 \end_inset
23799
23800  
23801 \end_layout
23802
23803 \end_inset
23804 </cell>
23805 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23806 \begin_inset Text
23807
23808 \begin_layout Standard
23809 Always defined.
23810  Since version 2.5.6 the version number as an int (ex.
23811  256)
23812 \end_layout
23813
23814 \end_inset
23815 </cell>
23816 </row>
23817 <row topline="true">
23818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23819 \begin_inset Text
23820
23821 \begin_layout Standard
23822 SDCC_mcs51
23823 \begin_inset LatexCommand index
23824 name "SDCC\\_mcs51"
23825
23826 \end_inset
23827
23828  or SDCC_ds390
23829 \begin_inset LatexCommand index
23830 name "SDCC\\_ds390"
23831
23832 \end_inset
23833
23834  or SDCC_z80
23835 \begin_inset LatexCommand index
23836 name "SDCC\\_z80"
23837
23838 \end_inset
23839
23840 , etc.
23841 \end_layout
23842
23843 \end_inset
23844 </cell>
23845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23846 \begin_inset Text
23847
23848 \begin_layout Standard
23849 depending on the model used (e.g.: -mds390)
23850 \end_layout
23851
23852 \end_inset
23853 </cell>
23854 </row>
23855 <row topline="true">
23856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23857 \begin_inset Text
23858
23859 \begin_layout Standard
23860 __mcs51
23861 \begin_inset LatexCommand index
23862 name "\\_\\_mcs51"
23863
23864 \end_inset
23865
23866 , __ds390
23867 \begin_inset LatexCommand index
23868 name "\\_\\_ds390"
23869
23870 \end_inset
23871
23872 , __hc08
23873 \begin_inset LatexCommand index
23874 name "\\_\\_hc08"
23875
23876 \end_inset
23877
23878 , __z80
23879 \begin_inset LatexCommand index
23880 name "\\_\\_z80"
23881
23882 \end_inset
23883
23884 , etc
23885 \end_layout
23886
23887 \end_inset
23888 </cell>
23889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23890 \begin_inset Text
23891
23892 \begin_layout Standard
23893 depending on the model used (e.g.
23894  -mz80)
23895 \end_layout
23896
23897 \end_inset
23898 </cell>
23899 </row>
23900 <row topline="true">
23901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23902 \begin_inset Text
23903
23904 \begin_layout Standard
23905 SDCC_STACK_AUTO
23906 \begin_inset LatexCommand index
23907 name "SDCC\\_STACK\\_AUTO"
23908
23909 \end_inset
23910
23911
23912 \end_layout
23913
23914 \end_inset
23915 </cell>
23916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23917 \begin_inset Text
23918
23919 \begin_layout Standard
23920 when 
23921 \emph on
23922 -
23923 \begin_inset ERT
23924 status collapsed
23925
23926 \begin_layout Standard
23927
23928
23929 \backslash
23930 /
23931 \end_layout
23932
23933 \end_inset
23934
23935 -stack-auto
23936 \emph default
23937  option is used
23938 \end_layout
23939
23940 \end_inset
23941 </cell>
23942 </row>
23943 <row topline="true">
23944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23945 \begin_inset Text
23946
23947 \begin_layout Standard
23948 SDCC_MODEL_SMALL
23949 \begin_inset LatexCommand index
23950 name "SDCC\\_MODEL\\_SMALL"
23951
23952 \end_inset
23953
23954
23955 \end_layout
23956
23957 \end_inset
23958 </cell>
23959 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23960 \begin_inset Text
23961
23962 \begin_layout Standard
23963 when 
23964 \emph on
23965 -
23966 \begin_inset ERT
23967 status collapsed
23968
23969 \begin_layout Standard
23970
23971
23972 \backslash
23973 /
23974 \end_layout
23975
23976 \end_inset
23977
23978 -model-small
23979 \emph default
23980  is used
23981 \end_layout
23982
23983 \end_inset
23984 </cell>
23985 </row>
23986 <row topline="true">
23987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23988 \begin_inset Text
23989
23990 \begin_layout Standard
23991 SDCC_MODEL_MEDIUM
23992 \begin_inset LatexCommand index
23993 name "SDCC\\_MODEL\\_MEDIUM"
23994
23995 \end_inset
23996
23997
23998 \end_layout
23999
24000 \end_inset
24001 </cell>
24002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24003 \begin_inset Text
24004
24005 \begin_layout Standard
24006 when 
24007 \emph on
24008 -
24009 \begin_inset ERT
24010 status collapsed
24011
24012 \begin_layout Standard
24013
24014
24015 \backslash
24016 /
24017 \end_layout
24018
24019 \end_inset
24020
24021 -model-medium
24022 \emph default
24023  is used
24024 \end_layout
24025
24026 \end_inset
24027 </cell>
24028 </row>
24029 <row topline="true">
24030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24031 \begin_inset Text
24032
24033 \begin_layout Standard
24034 SDCC_MODEL_LARGE
24035 \begin_inset LatexCommand index
24036 name "SDCC\\_MODEL\\_LARGE"
24037
24038 \end_inset
24039
24040
24041 \end_layout
24042
24043 \end_inset
24044 </cell>
24045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24046 \begin_inset Text
24047
24048 \begin_layout Standard
24049 when 
24050 \emph on
24051 -
24052 \begin_inset ERT
24053 status collapsed
24054
24055 \begin_layout Standard
24056
24057
24058 \backslash
24059 /
24060 \end_layout
24061
24062 \end_inset
24063
24064 -model-large
24065 \emph default
24066  is used
24067 \end_layout
24068
24069 \end_inset
24070 </cell>
24071 </row>
24072 <row topline="true">
24073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24074 \begin_inset Text
24075
24076 \begin_layout Standard
24077 SDCC_USE_XSTACK
24078 \begin_inset LatexCommand index
24079 name "SDCC\\_USE\\_XSTACK"
24080
24081 \end_inset
24082
24083
24084 \end_layout
24085
24086 \end_inset
24087 </cell>
24088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24089 \begin_inset Text
24090
24091 \begin_layout Standard
24092 when 
24093 \emph on
24094 -
24095 \begin_inset ERT
24096 status collapsed
24097
24098 \begin_layout Standard
24099
24100
24101 \backslash
24102 /
24103 \end_layout
24104
24105 \end_inset
24106
24107 -xstack
24108 \emph default
24109  option is used
24110 \end_layout
24111
24112 \end_inset
24113 </cell>
24114 </row>
24115 <row topline="true">
24116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24117 \begin_inset Text
24118
24119 \begin_layout Standard
24120 SDCC_STACK_TENBIT
24121 \begin_inset LatexCommand index
24122 name "SDCC\\_STACK\\_TENBIT"
24123
24124 \end_inset
24125
24126  
24127 \end_layout
24128
24129 \end_inset
24130 </cell>
24131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24132 \begin_inset Text
24133
24134 \begin_layout Standard
24135 when 
24136 \emph on
24137 -mds390
24138 \emph default
24139  is used
24140 \end_layout
24141
24142 \end_inset
24143 </cell>
24144 </row>
24145 <row topline="true">
24146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24147 \begin_inset Text
24148
24149 \begin_layout Standard
24150 SDCC_MODEL_FLAT24
24151 \begin_inset LatexCommand index
24152 name "SDCC\\_MODEL\\_FLAT24"
24153
24154 \end_inset
24155
24156
24157 \end_layout
24158
24159 \end_inset
24160 </cell>
24161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24162 \begin_inset Text
24163
24164 \begin_layout Standard
24165 when 
24166 \emph on
24167 -mds390
24168 \emph default
24169  is used
24170 \end_layout
24171
24172 \end_inset
24173 </cell>
24174 </row>
24175 <row topline="true">
24176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24177 \begin_inset Text
24178
24179 \begin_layout Standard
24180 SDCC_REVISION
24181 \begin_inset LatexCommand index
24182 name "SDCC\\_REVISION"
24183
24184 \end_inset
24185
24186
24187 \end_layout
24188
24189 \end_inset
24190 </cell>
24191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24192 \begin_inset Text
24193
24194 \begin_layout Standard
24195 Always defined.
24196  SDCC svn revision number
24197 \end_layout
24198
24199 \end_inset
24200 </cell>
24201 </row>
24202 <row topline="true">
24203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24204 \begin_inset Text
24205
24206 \begin_layout Standard
24207 SDCC_PARMS_IN_BANK1
24208 \begin_inset LatexCommand index
24209 name "SDCC\\_PARMS\\_IN\\_BANK1"
24210
24211 \end_inset
24212
24213
24214 \end_layout
24215
24216 \end_inset
24217 </cell>
24218 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24219 \begin_inset Text
24220
24221 \begin_layout Standard
24222 when 
24223 \emph on
24224 -
24225 \begin_inset ERT
24226 status collapsed
24227
24228 \begin_layout Standard
24229
24230
24231 \backslash
24232 /
24233 \end_layout
24234
24235 \end_inset
24236
24237 -parms-in-bank1
24238 \emph default
24239  is used
24240 \end_layout
24241
24242 \end_inset
24243 </cell>
24244 </row>
24245 <row topline="true">
24246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24247 \begin_inset Text
24248
24249 \begin_layout Standard
24250 SDCC_FLOAT_REENT
24251 \begin_inset LatexCommand index
24252 name "SDCC\\_MODEL\\_FLAT24"
24253
24254 \end_inset
24255
24256
24257 \end_layout
24258
24259 \end_inset
24260 </cell>
24261 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24262 \begin_inset Text
24263
24264 \begin_layout Standard
24265 when 
24266 \emph on
24267 -
24268 \begin_inset ERT
24269 status collapsed
24270
24271 \begin_layout Standard
24272
24273
24274 \backslash
24275 /
24276 \end_layout
24277
24278 \end_inset
24279
24280 -float-reent
24281 \emph default
24282  is used
24283 \end_layout
24284
24285 \end_inset
24286 </cell>
24287 </row>
24288 <row topline="true" bottomline="true">
24289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24290 \begin_inset Text
24291
24292 \begin_layout Standard
24293 SDCC_INT_LONG_REENT
24294 \begin_inset LatexCommand index
24295 name "SDCC\\_INT\\_LONG\\_REENT"
24296
24297 \end_inset
24298
24299
24300 \end_layout
24301
24302 \end_inset
24303 </cell>
24304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24305 \begin_inset Text
24306
24307 \begin_layout Standard
24308 when 
24309 \emph on
24310 -
24311 \begin_inset ERT
24312 status collapsed
24313
24314 \begin_layout Standard
24315
24316
24317 \backslash
24318 /
24319 \end_layout
24320
24321 \end_inset
24322
24323 -int-long-reent
24324 \emph default
24325  is used
24326 \end_layout
24327
24328 \end_inset
24329 </cell>
24330 </row>
24331 </lyxtabular>
24332
24333 \end_inset
24334
24335
24336 \end_layout
24337
24338 \begin_layout Chapter
24339 Notes on supported Processors
24340 \end_layout
24341
24342 \begin_layout Section
24343 MCS51 variants
24344 \begin_inset LatexCommand label
24345 name "sub:MCS51-variants"
24346
24347 \end_inset
24348
24349
24350 \begin_inset LatexCommand index
24351 name "MCS51 variants"
24352
24353 \end_inset
24354
24355
24356 \end_layout
24357
24358 \begin_layout Standard
24359 MCS51 processors are available from many vendors and come in many different
24360  flavours.
24361  While they might differ considerably in respect to Special Function Registers
24362  the core MCS51 is usually not modified or is kept compatible.
24363  
24364 \end_layout
24365
24366 \begin_layout Subsection
24367 pdata access by SFR 
24368 \end_layout
24369
24370 \begin_layout Standard
24371 With the upcome of devices with internal xdata and flash memory devices
24372  using port P2
24373 \begin_inset LatexCommand index
24374 name "P2 (mcs51 sfr)"
24375
24376 \end_inset
24377
24378  as dedicated I/O port is becoming more popular.
24379  Switching the high byte for pdata
24380 \begin_inset LatexCommand index
24381 name "pdata (mcs51, ds390 storage class)"
24382
24383 \end_inset
24384
24385  access which was formerly done by port P2 is then achieved by a Special
24386  Function Register
24387 \begin_inset LatexCommand index
24388 name "sfr"
24389
24390 \end_inset
24391
24392 .
24393  In well-established MCS51 tradition the address of this 
24394 \emph on
24395 sfr
24396 \emph default
24397  is where the chip designers decided to put it.
24398  Needless to say that they didn't agree on a common name either.
24399  So that the startup code can correctly initialize xdata variables, you
24400  should define an sfr with the name _XPAGE
24401 \family typewriter
24402
24403 \begin_inset LatexCommand index
24404 name "\\_XPAGE (mcs51)"
24405
24406 \end_inset
24407
24408
24409 \family default
24410  at the appropriate location if the default, port P2, is not used for this.
24411  Some examples are:
24412 \end_layout
24413
24414 \begin_layout Verse
24415
24416 \family typewriter
24417 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
24418  MPAGE */
24419 \end_layout
24420
24421 \begin_layout Verse
24422
24423 \family typewriter
24424 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
24425  a.k.a.
24426  MPAGE */
24427 \end_layout
24428
24429 \begin_layout Verse
24430
24431 \family typewriter
24432 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
24433  XPAGE */
24434 \end_layout
24435
24436 \begin_layout Verse
24437
24438 \family typewriter
24439 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
24440  EMI0CN */
24441 \end_layout
24442
24443 \begin_layout Verse
24444
24445 \family typewriter
24446 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
24447  EMI0CN */
24448 \end_layout
24449
24450 \begin_layout Standard
24451 For more exotic implementations further customizations may be needed.
24452  See section 
24453 \begin_inset LatexCommand ref
24454 reference "sub:Startup-Code"
24455
24456 \end_inset
24457
24458  for other possibilities.
24459 \end_layout
24460
24461 \begin_layout Subsection
24462 Other Features available by SFR
24463 \end_layout
24464
24465 \begin_layout Standard
24466 Some MCS51 variants offer features like Double DPTR
24467 \begin_inset LatexCommand index
24468 name "DPTR"
24469
24470 \end_inset
24471
24472 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
24473  These are currently not used for the MCS51 port.
24474  If you absolutely need them you can fall back to inline assembly or submit
24475  a patch to SDCC.
24476 \end_layout
24477
24478 \begin_layout Subsection
24479 Bankswitching
24480 \end_layout
24481
24482 \begin_layout Standard
24483 Bankswitching
24484 \begin_inset LatexCommand index
24485 name "Bankswitching"
24486
24487 \end_inset
24488
24489  (a.k.a.
24490  code banking
24491 \begin_inset LatexCommand index
24492 name "code banking"
24493
24494 \end_inset
24495
24496 ) is a technique to increase the code space above the 64k limit of the 8051.
24497 \end_layout
24498
24499 \begin_layout Subsubsection
24500 Hardware
24501 \end_layout
24502
24503 \begin_layout Standard
24504 \begin_inset Tabular
24505 <lyxtabular version="3" rows="3" columns="4">
24506 <features>
24507 <column alignment="center" valignment="top" width="0">
24508 <column alignment="center" valignment="top" leftline="true" width="0">
24509 <column alignment="center" valignment="top" leftline="true" width="0">
24510 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24511 <row topline="true" bottomline="true">
24512 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24513 \begin_inset Text
24514
24515 \begin_layout Standard
24516 8000-FFFF
24517 \end_layout
24518
24519 \end_inset
24520 </cell>
24521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24522 \begin_inset Text
24523
24524 \begin_layout Standard
24525 bank1
24526 \end_layout
24527
24528 \end_inset
24529 </cell>
24530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24531 \begin_inset Text
24532
24533 \begin_layout Standard
24534 bank2
24535 \end_layout
24536
24537 \end_inset
24538 </cell>
24539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24540 \begin_inset Text
24541
24542 \begin_layout Standard
24543 bank3
24544 \end_layout
24545
24546 \end_inset
24547 </cell>
24548 </row>
24549 <row topline="true" bottomline="true">
24550 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24551 \begin_inset Text
24552
24553 \begin_layout Standard
24554 0000-7FFF
24555 \end_layout
24556
24557 \end_inset
24558 </cell>
24559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24560 \begin_inset Text
24561
24562 \begin_layout Standard
24563 common
24564 \end_layout
24565
24566 \end_inset
24567 </cell>
24568 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24569 \begin_inset Text
24570
24571 \begin_layout Standard
24572
24573 \end_layout
24574
24575 \end_inset
24576 </cell>
24577 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24578 \begin_inset Text
24579
24580 \begin_layout Standard
24581
24582 \end_layout
24583
24584 \end_inset
24585 </cell>
24586 </row>
24587 <row>
24588 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24589 \begin_inset Text
24590
24591 \begin_layout Standard
24592 SiLabs C8051F120 example
24593 \end_layout
24594
24595 \end_inset
24596 </cell>
24597 <cell multicolumn="2" alignment="center" valignment="top" usebox="none">
24598 \begin_inset Text
24599
24600 \begin_layout Standard
24601
24602 \end_layout
24603
24604 \end_inset
24605 </cell>
24606 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24607 \begin_inset Text
24608
24609 \begin_layout Standard
24610
24611 \end_layout
24612
24613 \end_inset
24614 </cell>
24615 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24616 \begin_inset Text
24617
24618 \begin_layout Standard
24619
24620 \end_layout
24621
24622 \end_inset
24623 </cell>
24624 </row>
24625 </lyxtabular>
24626
24627 \end_inset
24628
24629
24630 \newline
24631
24632 \newline
24633 Usually the hardware uses some sfr (an output port or an internal sfr) to
24634  select a bank and put it in the banked area of the memory map.
24635  The selected bank usually becomes active immediately upon assignment to
24636  this sfr and when running inside a bank it will switch out this code it
24637  is currently running.
24638  Therefor you cannot jump or call directly from one bank to another and
24639  need to use a so-called trampoline in the common area.
24640  For SDCC an example trampoline is in crtbank.asm and you may need to change
24641  it to your 8051 derivative or schematic.
24642  The presented code is written for the C8051F120.
24643 \newline
24644
24645 \newline
24646 When calling a banked function
24647  SDCC will put the LSB of the functions address in register R0, the MSB
24648  in R1 and the bank in R2 and then call this trampoline 
24649 \emph on
24650 __sdcc_banked_call
24651 \emph default
24652 .
24653  The current selected bank is saved on the stack, the new bank is selected
24654  and an indirect jump is made.
24655  When the banked function returns it jumps to 
24656 \emph on
24657 __sdcc_banked_ret
24658 \emph default
24659  which restores the previous bank and returns to the caller.
24660 \end_layout
24661
24662 \begin_layout Subsubsection
24663 Software
24664 \end_layout
24665
24666 \begin_layout Standard
24667 When writing banked software using SDCC you need to use some special keywords
24668  and options.
24669  You also need to take over a bit of work from the linker.
24670 \newline
24671
24672 \newline
24673 To create a function
24674  that can be called from another bank it requires the keyword 
24675 \emph on
24676 banked
24677 \emph default
24678
24679 \begin_inset LatexCommand index
24680 name "banked"
24681
24682 \end_inset
24683
24684 .
24685  The caller must see this in the prototype of the callee and the callee
24686  needs it for a proper return.
24687  Called functions within the same bank as the caller do not need the 
24688 \emph on
24689 banked
24690 \emph default
24691  keyword nor do functions in the common area.
24692  Beware: SDCC does not know or check if functions are in the same bank.
24693  This is your responsibility!
24694 \newline
24695
24696 \newline
24697 Normally all functions you write end up in
24698  the segment CSEG.
24699  If you want a function explicitly to reside in the common area put it in
24700  segment HOME.
24701  This applies for instance to interrupt service routines as they should
24702  not be banked.
24703 \end_layout
24704
24705 \begin_layout Standard
24706 Functions that need to be in a switched bank must be put in a named segment.
24707  The name can be mostly anything up to eight characters (e.g.
24708  BANK1).
24709  To do this you either use -
24710 \begin_inset ERT
24711 status collapsed
24712
24713 \begin_layout Standard
24714
24715
24716 \backslash
24717 /
24718 \end_layout
24719
24720 \end_inset
24721
24722 -codeseg BANK1 (See 
24723 \begin_inset LatexCommand ref
24724 reference "lyx:-codeseg"
24725
24726 \end_inset
24727
24728 ) on the command line when compiling or #pragma codeseg BANK1 (See 
24729 \begin_inset LatexCommand ref
24730 reference "sec:Pragmas"
24731
24732 \end_inset
24733
24734 ) at the top of the C source file.
24735  The segment name always applies to the whole source file and generated
24736  object so functions for different banks need to be defined in different
24737  source files.
24738 \newline
24739
24740 \newline
24741 When linking your objects you need to tell the linker where
24742  to put your segments.
24743  To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180
24744 00 (See 
24745 \begin_inset LatexCommand ref
24746 reference "lyx:-Wl option"
24747
24748 \end_inset
24749
24750 ).
24751  This sets the virtual start address of this segment.
24752  It sets the banknumber to 0x01 and maps the bank to 0x8000 and up.
24753  The linker will not check for overflows, again this is your responsibility.
24754 \end_layout
24755
24756 \begin_layout Standard
24757 \begin_inset VSpace bigskip
24758 \end_inset
24759
24760
24761 \end_layout
24762
24763 \begin_layout Section
24764 DS400 port
24765 \end_layout
24766
24767 \begin_layout Standard
24768 The DS80C400
24769 \begin_inset LatexCommand index
24770 name "DS80C400"
24771
24772 \end_inset
24773
24774
24775 \begin_inset LatexCommand index
24776 name "DS400"
24777
24778 \end_inset
24779
24780  microcontroller has a rich set of peripherals.
24781  In its built-in ROM library it includes functions to access some of the
24782  features, among them is a TCP stack with IP4 and IP6 support.
24783  Library headers (currently in beta status) and other files are provided
24784  at 
24785 \size footnotesize
24786
24787 \begin_inset LatexCommand url
24788 target "ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html"
24789
24790 \end_inset
24791
24792 .
24793  
24794 \begin_inset VSpace bigskip
24795 \end_inset
24796
24797
24798 \end_layout
24799
24800 \begin_layout Section
24801 The Z80 and gbz80 port
24802 \end_layout
24803
24804 \begin_layout Standard
24805 SDCC can target both the Zilog Z80
24806 \begin_inset LatexCommand index
24807 name "Z80"
24808
24809 \end_inset
24810
24811  and the Nintendo Gameboy's Z80-like gbz80
24812 \begin_inset LatexCommand index
24813 name "gbz80 (GameBoy Z80)"
24814
24815 \end_inset
24816
24817 .
24818  The Z80 port is passed through the same 
24819 \emph on
24820 regressions tests
24821 \begin_inset LatexCommand index
24822 name "Regression test"
24823
24824 \end_inset
24825
24826
24827 \emph default
24828  (see section 
24829 \begin_inset LatexCommand ref
24830 reference "sec:Quality-control"
24831
24832 \end_inset
24833
24834 ) as the MCS51 and DS390 ports, so floating point support, support for long
24835  variables and bitfield support is fine.
24836  See mailing lists and forums about interrupt routines.
24837 \end_layout
24838
24839 \begin_layout Standard
24840 As always, the code is the authoritative reference - see z80/ralloc.c and
24841  z80/gen.c.
24842  The stack
24843 \begin_inset LatexCommand index
24844 name "Z80!stack"
24845
24846 \end_inset
24847
24848  frame is similar to that generated by the IAR Z80 compiler.
24849  IX is used as the base pointer, HL and IY are used as a temporary registers,
24850  and BC and DE are available for holding variables.
24851  Return values
24852 \begin_inset LatexCommand index
24853 name "Z80!return value"
24854
24855 \end_inset
24856
24857  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
24858  bytes).
24859  The gbz80 port use the same set of registers for the return values, but
24860  in a different order of significance: E (one byte), DE (two bytes), or
24861  HLDE (four bytes).
24862 \begin_inset VSpace bigskip
24863 \end_inset
24864
24865
24866 \end_layout
24867
24868 \begin_layout Section
24869 The HC08 port
24870 \end_layout
24871
24872 \begin_layout Standard
24873 The port to the Freescale/Motorola HC08
24874 \begin_inset LatexCommand index
24875 name "HC08"
24876
24877 \end_inset
24878
24879  family has been added in October 2003, and is still undergoing some basic
24880  development.
24881  The code generator is complete, but the register allocation is still quite
24882  unoptimized.
24883  Some of the SDCC's standard C library functions have embedded non-HC08
24884  inline assembly and so are not yet usable.
24885 \end_layout
24886
24887 \begin_layout Standard
24888 The HC08 port passes the regression test suite (see section 
24889 \begin_inset LatexCommand ref
24890 reference "sec:Quality-control"
24891
24892 \end_inset
24893
24894 ).
24895 \begin_inset VSpace bigskip
24896 \end_inset
24897
24898
24899 \end_layout
24900
24901 \begin_layout Section
24902 The PIC14
24903 \begin_inset LatexCommand index
24904 name "PIC14"
24905
24906 \end_inset
24907
24908  port
24909 \end_layout
24910
24911 \begin_layout Standard
24912 The PIC14 port adds support for Microchip
24913 \begin_inset LatexCommand index
24914 name "Microchip"
24915
24916 \end_inset
24917
24918
24919 \begin_inset Formula $^{\text{TM}}$
24920 \end_inset
24921
24922  PIC
24923 \begin_inset LatexCommand index
24924 name "PIC14"
24925
24926 \end_inset
24927
24928
24929 \begin_inset Formula $^{\text{TM}}$
24930 \end_inset
24931
24932  MCUs with 14 bit wide instructions.
24933  This port is not yet mature and still lacks many features.
24934  However, it can work for simple code.
24935 \end_layout
24936
24937 \begin_layout Standard
24938 \noindent
24939 Currently supported devices include:
24940 \end_layout
24941
24942 \begin_layout Standard
24943 12F: 629, 635, 675, 683
24944 \end_layout
24945
24946 \begin_layout Standard
24947 16C: 432, 433
24948 \end_layout
24949
24950 \begin_layout Standard
24951 16C: 554, 557, 558
24952 \end_layout
24953
24954 \begin_layout Standard
24955 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
24956 \end_layout
24957
24958 \begin_layout Standard
24959 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
24960  781, 782
24961 \end_layout
24962
24963 \begin_layout Standard
24964 16C: 925, 926
24965 \end_layout
24966
24967 \begin_layout Standard
24968 16CR: 620a, 73, 74, 76, 77
24969 \end_layout
24970
24971 \begin_layout Standard
24972 16F: 616, 627, 627a, 628, 628a, 630, 636, 639, 648, 648a, 676, 684, 685,
24973  687, 688, 689, 690
24974 \end_layout
24975
24976 \begin_layout Standard
24977 16F: 716, 72, 73, 737, 74, 747, 76, 767, 77, 777, 785
24978 \end_layout
24979
24980 \begin_layout Standard
24981 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
24982  877, 877a, 88, 886, 887
24983 \end_layout
24984
24985 \begin_layout Standard
24986 16F: 913, 914, 916, 917, 946
24987 \end_layout
24988
24989 \begin_layout Standard
24990 26HV: 626, 785
24991 \end_layout
24992
24993 \begin_layout Standard
24994 \noindent
24995 An up-to-date list of currently supported devices can be obtained via 
24996 \family typewriter
24997 sdcc -mpic14 -phelp foo.c
24998 \family default
24999  (foo.c must exist...).
25000 \end_layout
25001
25002 \begin_layout Subsection
25003 PIC Code Pages
25004 \begin_inset LatexCommand index
25005 name "code page (pic14)"
25006
25007 \end_inset
25008
25009  and Memory Banks
25010 \begin_inset LatexCommand index
25011 name "Memory bank (pic14)"
25012
25013 \end_inset
25014
25015
25016 \end_layout
25017
25018 \begin_layout Standard
25019 The linker organizes allocation for the code page and RAM banks.
25020  It does not have intimate knowledge of the code flow.
25021  It will put all the code section of a single .asm file into a single code
25022  page.
25023  In order to make use of multiple code pages, separate asm files must be
25024  used.
25025  The compiler assigns all 
25026 \emph on
25027 static
25028 \emph default
25029  functions of a single .c file into the same code page.
25030 \newline
25031
25032 \newline
25033 To get the best results,
25034  follow these guidelines:
25035 \end_layout
25036
25037 \begin_layout Enumerate
25038 Make local functions static, as non static functions require code page selection
25039  overhead.
25040 \newline
25041 Due to the way sdcc handles functions, place called functions prior
25042  to calling functions in the file wherever possible: Otherwise sdcc will
25043  insert unnecessary pagesel directives around the call, believing that
25044  the called function is externally defined.
25045 \end_layout
25046
25047 \begin_layout Enumerate
25048 For devices that have multiple code pages it is more efficient to use the
25049  same number of files as pages: Use up to 4 separate .c files for the 16F877,
25050  but only 2 files for the 16F874.
25051  This way the linker can put the code for each file into different code
25052  pages and there will be less page selection overhead.
25053 \end_layout
25054
25055 \begin_layout Enumerate
25056 And as for any 8 bit micro (especially for PIC14 as they have a very simple
25057  instruction set), use `unsigned char' wherever possible instead of `int'.
25058 \end_layout
25059
25060 \begin_layout Subsection
25061 Adding New Devices to the Port 
25062 \end_layout
25063
25064 \begin_layout Standard
25065 Adding support for a new 14
25066 \begin_inset ERT
25067 status open
25068
25069 \begin_layout Standard
25070
25071
25072 \backslash
25073 ,
25074 \end_layout
25075
25076 \end_inset
25077
25078 bit PIC MCU requires the following steps:
25079 \end_layout
25080
25081 \begin_layout Enumerate
25082 Create a new device description.
25083 \newline
25084 Each device is described in two files: pic16f*.h
25085  and pic16f*.c.
25086  These files primarily define SFRs, structs to access their bits, and symbolic
25087  configuration options.
25088  Both files can be generated from gputils' .inc files using the perl script
25089  
25090 \family typewriter
25091 support/scripts/inc2h.pl
25092 \family default
25093 .
25094  This file also contains further instructions on how to proceed.
25095 \end_layout
25096
25097 \begin_layout Enumerate
25098 Copy the .h file into SDCC's include path and either add the .c file to your
25099  project or copy it to 
25100 \family typewriter
25101 device/lib/pic/libdev
25102 \family default
25103 .
25104  Afterwards, rebuild and install the libraries.
25105 \end_layout
25106
25107 \begin_layout Enumerate
25108 Edit pic14devices.txt in SDCC's include path (
25109 \family typewriter
25110 device/include/pic/
25111 \family default
25112  in the source tree or 
25113 \family typewriter
25114 /usr/local/share/sdcc/include/pic
25115 \family default
25116  after installation).
25117 \newline
25118 You need to add a device specification here to make
25119  the memory layout (code banks, RAM, aliased memory regions, ...) known to
25120  the compiler.
25121  Probably you can copy and modify an existing entry.
25122  The file format is documented at the top of the file.
25123 \end_layout
25124
25125 \begin_layout Subsection
25126 Interrupt Code
25127 \end_layout
25128
25129 \begin_layout Standard
25130 For the interrupt function, use the keyword `__interrupt'
25131 \begin_inset LatexCommand index
25132 name "PIC14!interrupt"
25133
25134 \end_inset
25135
25136  with level number of 0 (PIC14 only has 1 interrupt so this number is only
25137  there to avoid a syntax error - it ought to be fixed).
25138  E.g.:
25139 \end_layout
25140
25141 \begin_layout Verse
25142
25143 \family typewriter
25144 void Intr(void) __interrupt 0
25145 \newline
25146 {
25147 \newline
25148 \InsetSpace ~
25149 \InsetSpace ~
25150 T0IF = 0; /* Clear timer interrupt */
25151 \newline
25152 }
25153 \end_layout
25154
25155 \begin_layout Subsection
25156 Linking and Assembling
25157 \end_layout
25158
25159 \begin_layout Standard
25160 For assembling you can use either GPUTILS'
25161 \begin_inset LatexCommand index
25162 name "gputils (pic tools)"
25163
25164 \end_inset
25165
25166  gpasm.exe or MPLAB's mpasmwin.exe.
25167  GPUTILS are available from 
25168 \begin_inset LatexCommand url
25169 target "http://sourceforge.net/projects/gputils"
25170
25171 \end_inset
25172
25173 .
25174  For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
25175  If you use MPLAB and an interrupt function then the linker script file
25176  vectors section will need to be enlarged to link with mplink.
25177 \newline
25178
25179 \newline
25180 Here is a 
25181 \family typewriter
25182 Makefile
25183 \family default
25184  using GPUTILS:
25185 \end_layout
25186
25187 \begin_layout Verse
25188
25189 \family typewriter
25190 .c.o:
25191 \newline
25192 \InsetSpace ~
25193 \InsetSpace ~
25194 \InsetSpace ~
25195 \InsetSpace ~
25196 \InsetSpace ~
25197 \InsetSpace ~
25198 \InsetSpace ~
25199 \InsetSpace ~
25200 sdcc -V -mpic14 -p16f877 -c $< 
25201 \newline
25202
25203 \newline
25204 $(PRJ).hex: $(OBJS) 
25205 \newline
25206 \InsetSpace ~
25207 \InsetSpace ~
25208 \InsetSpace ~
25209 \InsetSpace ~
25210 \InsetSpace ~
25211 \InsetSpace ~
25212 \InsetSpace ~
25213 \InsetSpace ~
25214 gplink -m -s $(PRJ).lkr
25215  -o $(PRJ).hex $(OBJS) libsdcc.lib
25216 \end_layout
25217
25218 \begin_layout Standard
25219 Here is a 
25220 \family typewriter
25221 Makefile
25222 \family default
25223  using MPLAB:
25224 \end_layout
25225
25226 \begin_layout Verse
25227
25228 \family typewriter
25229 .c.o: 
25230 \newline
25231 \InsetSpace ~
25232 \InsetSpace ~
25233 \InsetSpace ~
25234 \InsetSpace ~
25235 \InsetSpace ~
25236 \InsetSpace ~
25237 \InsetSpace ~
25238 \InsetSpace ~
25239 sdcc -S -V -mpic14 -p16f877 $< 
25240 \newline
25241 \InsetSpace ~
25242 \InsetSpace ~
25243 \InsetSpace ~
25244 \InsetSpace ~
25245 \InsetSpace ~
25246 \InsetSpace ~
25247 \InsetSpace ~
25248 \InsetSpace ~
25249 mpasmwin /q /o $*.asm
25250 \newline
25251
25252 \newline
25253 $(PRJ).hex: $(OBJS)
25254  
25255 \newline
25256 \InsetSpace ~
25257 \InsetSpace ~
25258 \InsetSpace ~
25259 \InsetSpace ~
25260 \InsetSpace ~
25261 \InsetSpace ~
25262 \InsetSpace ~
25263 \InsetSpace ~
25264 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
25265 \end_layout
25266
25267 \begin_layout Standard
25268 Please note that indentations within a 
25269 \family typewriter
25270 Makefile
25271 \family default
25272  have to be done with a tabulator character.
25273 \end_layout
25274
25275 \begin_layout Subsection
25276 Command-Line Options
25277 \end_layout
25278
25279 \begin_layout Standard
25280 Besides the switches common to all SDCC backends, the PIC14 port accepts
25281  the following options (for an updated list see sdcc -
25282 \begin_inset ERT
25283 status collapsed
25284
25285 \begin_layout Standard
25286
25287
25288 \backslash
25289 /
25290 \end_layout
25291
25292 \end_inset
25293
25294 -help):
25295 \end_layout
25296
25297 \begin_layout Description
25298 -
25299 \begin_inset ERT
25300 status collapsed
25301
25302 \begin_layout Standard
25303
25304
25305 \backslash
25306 /
25307 \end_layout
25308
25309 \end_inset
25310
25311 -debug-xtra
25312 \begin_inset LatexCommand index
25313 name "PIC14!Options!-\\/-debug-extra"
25314
25315 \end_inset
25316
25317  emit debug info in assembly output
25318 \end_layout
25319
25320 \begin_layout Description
25321 -
25322 \begin_inset ERT
25323 status collapsed
25324
25325 \begin_layout Standard
25326
25327
25328 \backslash
25329 /
25330 \end_layout
25331
25332 \end_inset
25333
25334 -no-pcode-opt
25335 \begin_inset LatexCommand index
25336 name "PIC14!Options!-\\/-no-pcode-opt"
25337
25338 \end_inset
25339
25340  disable (slightly faulty) optimization on pCode
25341 \end_layout
25342
25343 \begin_layout Description
25344 -
25345 \begin_inset ERT
25346 status collapsed
25347
25348 \begin_layout Standard
25349
25350
25351 \backslash
25352 /
25353 \end_layout
25354
25355 \end_inset
25356
25357 -stack-loc
25358 \begin_inset LatexCommand index
25359 name "PIC14!Options!-\\/-stack-loc"
25360
25361 \end_inset
25362
25363  sets the lowest address of the argument passing stack (defaults to a suitably
25364  large shared databank to reduce BANKSEL overhead)
25365 \end_layout
25366
25367 \begin_layout Description
25368 -
25369 \begin_inset ERT
25370 status collapsed
25371
25372 \begin_layout Standard
25373
25374
25375 \backslash
25376 /
25377 \end_layout
25378
25379 \end_inset
25380
25381 -stack-size
25382 \begin_inset LatexCommand index
25383 name "PIC14!Options!-\\/-stack-size"
25384
25385 \end_inset
25386
25387  sets the size if the argument passing stack (default: 16, minimum: 4)
25388 \end_layout
25389
25390 \begin_layout Subsection
25391 Environment Variables
25392 \end_layout
25393
25394 \begin_layout Standard
25395 The PIC14 port recognizes the following environment variables:
25396 \end_layout
25397
25398 \begin_layout Description
25399 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
25400  register (the ones called r0xNNNN) in a section of its own.
25401  By default (if this variable is unset), sdcc tries to cluster registers
25402  in sections in order to reduce the BANKSEL overhead when accessing them.
25403 \end_layout
25404
25405 \begin_layout Subsection
25406 The Library
25407 \end_layout
25408
25409 \begin_layout Standard
25410 The PIC14 library currently only contains support routines required by the
25411  compiler to implement multiplication, division, and floating point support.
25412  No libc-like replacement is available at the moment, though many of the
25413  common sdcc library sources (in 
25414 \family typewriter
25415 device/lib
25416 \family default
25417 ) should also compile with the PIC14 port.
25418 \end_layout
25419
25420 \begin_layout Subsubsection
25421 error: missing definition for symbol ``__gptrget1''
25422 \end_layout
25423
25424 \begin_layout Standard
25425 The PIC14 port uses library routines to provide more complex operations
25426  like multiplication, division/modulus and (generic) pointer dereferencing.
25427  In order to add these routines to your project, you must link with PIC14's
25428  
25429 \family typewriter
25430 libsdcc.lib
25431 \family default
25432 .
25433  For single source file projects this is done automatically, more complex
25434  projects must add 
25435 \family typewriter
25436 libsdcc.lib
25437 \family default
25438  to the linker's arguments.
25439  Make sure you also add an include path for the library (using the -I switch
25440  to the linker)!
25441 \end_layout
25442
25443 \begin_layout Subsubsection
25444 Processor mismatch in file ``XXX''.
25445 \end_layout
25446
25447 \begin_layout Standard
25448 This warning can usually be ignored due to the very good compatibility amongst
25449  14
25450 \begin_inset ERT
25451 status open
25452
25453 \begin_layout Standard
25454
25455
25456 \backslash
25457 ,
25458 \end_layout
25459
25460 \end_inset
25461
25462 bit PIC
25463 \begin_inset LatexCommand index
25464 name "PIC14"
25465
25466 \end_inset
25467
25468  devices.
25469 \end_layout
25470
25471 \begin_layout Standard
25472 You might also consider recompiling the library for your specific device
25473  by changing the ARCH=p16f877 (default target) entry in 
25474 \family typewriter
25475 device/lib/pic/Makefile.in
25476 \family default
25477  and 
25478 \family typewriter
25479 device/lib/pic/Makefile
25480 \family default
25481  to reflect your device.
25482  This might even improve performance for smaller devices as unnecessary
25483  BANKSELs might be removed.
25484 \end_layout
25485
25486 \begin_layout Subsection
25487 Known Bugs
25488 \end_layout
25489
25490 \begin_layout Subsubsection
25491 Function arguments
25492 \end_layout
25493
25494 \begin_layout Standard
25495 Functions with variable argument lists (like printf) are not yet supported.
25496  Similarly, taking the address of the first argument passed into a function
25497  does not work: It is currently passed in WREG and has no address...
25498 \end_layout
25499
25500 \begin_layout Subsubsection
25501 Regression tests fail
25502 \end_layout
25503
25504 \begin_layout Standard
25505 Though the small subset of regression tests in src/regression passes, SDCC
25506  regression test suite does not, indicating that there are still major bugs
25507  in the port.
25508  However, many smaller projects have successfully used SDCC in the past...
25509 \end_layout
25510
25511 \begin_layout Standard
25512
25513 \size footnotesize
25514
25515 \newpage
25516
25517 \end_layout
25518
25519 \begin_layout Section
25520 The PIC16
25521 \begin_inset LatexCommand index
25522 name "PIC16"
25523
25524 \end_inset
25525
25526  port
25527 \end_layout
25528
25529 \begin_layout Standard
25530 The PIC16 port adds support for Microchip
25531 \begin_inset LatexCommand index
25532 name "Microchip"
25533
25534 \end_inset
25535
25536
25537 \begin_inset Formula $^{\text{TM}}$
25538 \end_inset
25539
25540  PIC
25541 \begin_inset LatexCommand index
25542 name "PIC"
25543
25544 \end_inset
25545
25546
25547 \begin_inset Formula $^{\text{TM}}$
25548 \end_inset
25549
25550  MCUs with 16 bit wide instructions.
25551  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
25552 ; devices supported by the port include:
25553 \end_layout
25554
25555 \begin_layout Standard
25556 18F: 242, 248, 252, 258, 442, 448, 452, 458
25557 \end_layout
25558
25559 \begin_layout Standard
25560 18F: 1220, 1320
25561 \end_layout
25562
25563 \begin_layout Standard
25564 18F: 2220, 2221, 2320, 2321, 2331, 2410, 2420, 2423, 2431, 2450, 2455, 2480,
25565  24j10
25566 \end_layout
25567
25568 \begin_layout Standard
25569 18F: (2510,) 2515, 2520, 2523, 2525, 2550, 2580, 2585, 25j10, 2610, 2620,
25570  2680, 2682, 2685
25571 \end_layout
25572
25573 \begin_layout Standard
25574 18F: 4220, 4221, 4320, 4321, 4331, 4410, 4420, 4423, 4431, 4450, 4455, 4480,
25575  44j10
25576 \end_layout
25577
25578 \begin_layout Standard
25579 18F: 4510, 4515, 4520, 4523, 4525, 4550, 4580, 4585, 45j10, 4610, 4620,
25580  4680, 4682, 4685
25581 \end_layout
25582
25583 \begin_layout Standard
25584 18F: 6520, 6585, 6620, 6680, 66j60, 66j65, 6720, 67j60
25585 \end_layout
25586
25587 \begin_layout Standard
25588 18F: 8520, 8585, 8620, 8680, 86j60, 86j65, 8720, 87j60
25589 \end_layout
25590
25591 \begin_layout Standard
25592 18F: 96j60, 96j65, 97j60
25593 \end_layout
25594
25595 \begin_layout Standard
25596 \noindent
25597 An up-to-date list of supported devices is also available via '
25598 \family typewriter
25599 sdcc -mpic16 -plist
25600 \family default
25601 '.
25602 \end_layout
25603
25604 \begin_layout Subsection
25605 Global Options
25606 \end_layout
25607
25608 \begin_layout Standard
25609 PIC16 port supports the standard command line arguments as supposed, with
25610  the exception of certain cases that will be mentioned in the following
25611  list:
25612 \end_layout
25613
25614 \begin_layout Description
25615 -
25616 \begin_inset ERT
25617 status collapsed
25618
25619 \begin_layout Standard
25620
25621
25622 \backslash
25623 /
25624 \end_layout
25625
25626 \end_inset
25627
25628 -callee-saves
25629 \begin_inset LatexCommand index
25630 name "PIC16!Options!-\\/-callee-saves"
25631
25632 \end_inset
25633
25634  See -
25635 \begin_inset ERT
25636 status collapsed
25637
25638 \begin_layout Standard
25639
25640
25641 \backslash
25642 /
25643 \end_layout
25644
25645 \end_inset
25646
25647 -all-callee-saves
25648 \end_layout
25649
25650 \begin_layout Description
25651 -
25652 \begin_inset ERT
25653 status collapsed
25654
25655 \begin_layout Standard
25656
25657
25658 \backslash
25659 /
25660 \end_layout
25661
25662 \end_inset
25663
25664 -fommit-frame-pointer
25665 \begin_inset LatexCommand index
25666 name "PIC16!Options!-\\/-fommit-frame-pointer"
25667
25668 \end_inset
25669
25670  Frame pointer will be omitted when the function uses no local variables.
25671 \end_layout
25672
25673 \begin_layout Subsection
25674 Port Specific Options
25675 \begin_inset LatexCommand index
25676 name "Options PIC16"
25677
25678 \end_inset
25679
25680
25681 \end_layout
25682
25683 \begin_layout Standard
25684 The port specific options appear after the global options in the sdcc -
25685 \begin_inset ERT
25686 status collapsed
25687
25688 \begin_layout Standard
25689
25690
25691 \backslash
25692 /
25693 \end_layout
25694
25695 \end_inset
25696
25697 -help output.
25698 \end_layout
25699
25700 \begin_layout Subsubsection
25701 Code Generation Options
25702 \end_layout
25703
25704 \begin_layout Standard
25705 These options influence the generated assembler code.
25706 \end_layout
25707
25708 \begin_layout Description
25709 -
25710 \begin_inset ERT
25711 status collapsed
25712
25713 \begin_layout Standard
25714
25715
25716 \backslash
25717 /
25718 \end_layout
25719
25720 \end_inset
25721
25722 -pstack-model=[model] Used in conjunction with the command above.
25723  Defines the stack model to be used, valid stack models are:
25724 \end_layout
25725
25726 \begin_deeper
25727 \begin_layout List
25728 \labelwidthstring 00.00.0000
25729
25730 \emph on
25731 small
25732 \emph default
25733  Selects small stack model.
25734  8 bit stack and frame pointers.
25735  Supports 256 bytes stack size.
25736 \end_layout
25737
25738 \begin_layout List
25739 \labelwidthstring 00.00.0000
25740
25741 \emph on
25742 large
25743 \emph default
25744  Selects large stack model.
25745  16 bit stack and frame pointers.
25746  Supports 65536 bytes stack size.
25747 \end_layout
25748
25749 \end_deeper
25750 \begin_layout Description
25751 -
25752 \begin_inset ERT
25753 status collapsed
25754
25755 \begin_layout Standard
25756
25757
25758 \backslash
25759 /
25760 \end_layout
25761
25762 \end_inset
25763
25764 -pno-banksel Do not generate BANKSEL assembler directives.
25765 \end_layout
25766
25767 \begin_layout Description
25768 -
25769 \begin_inset ERT
25770 status collapsed
25771
25772 \begin_layout Standard
25773
25774
25775 \backslash
25776 /
25777 \end_layout
25778
25779 \end_inset
25780
25781 -extended Enable extended instruction set/literal offset addressing mode.
25782  Use with care!
25783 \end_layout
25784
25785 \begin_layout Subsubsection
25786 Optimization Options
25787 \end_layout
25788
25789 \begin_layout Description
25790 -
25791 \begin_inset ERT
25792 status collapsed
25793
25794 \begin_layout Standard
25795
25796
25797 \backslash
25798 /
25799 \end_layout
25800
25801 \end_inset
25802
25803 -obanksel=n Set optimization level for inserting BANKSELs.
25804 \newline
25805
25806 \end_layout
25807
25808 \begin_deeper
25809 \begin_layout List
25810 \labelwidthstring 00.00.0000
25811 0 no optimization
25812 \end_layout
25813
25814 \begin_layout List
25815 \labelwidthstring 00.00.0000
25816 1 checks previous used register and if it is the same then does not emit
25817  BANKSEL, accounts only for labels.
25818 \end_layout
25819
25820 \begin_layout List
25821 \labelwidthstring 00.00.0000
25822 2 tries to check the location of (even different) symbols and removes BANKSELs
25823  if they are in the same bank.
25824  
25825 \newline
25826
25827 \emph on
25828 Important: There might be problems if the linker script has data sections
25829  across bank borders!
25830 \end_layout
25831
25832 \end_deeper
25833 \begin_layout Description
25834 -
25835 \begin_inset ERT
25836 status collapsed
25837
25838 \begin_layout Standard
25839
25840
25841 \backslash
25842 /
25843 \end_layout
25844
25845 \end_inset
25846
25847 -denable-peeps Force the usage of peepholes.
25848  Use with care.
25849 \end_layout
25850
25851 \begin_layout Description
25852 -
25853 \begin_inset ERT
25854 status collapsed
25855
25856 \begin_layout Standard
25857
25858
25859 \backslash
25860 /
25861 \end_layout
25862
25863 \end_inset
25864
25865 -no-optimize-goto Do not use (conditional) BRA instead of GOTO.
25866 \end_layout
25867
25868 \begin_layout Description
25869 -
25870 \begin_inset ERT
25871 status collapsed
25872
25873 \begin_layout Standard
25874
25875
25876 \backslash
25877 /
25878 \end_layout
25879
25880 \end_inset
25881
25882 -optimize-cmp Try to optimize some compares.
25883 \end_layout
25884
25885 \begin_layout Description
25886 -
25887 \begin_inset ERT
25888 status collapsed
25889
25890 \begin_layout Standard
25891
25892
25893 \backslash
25894 /
25895 \end_layout
25896
25897 \end_inset
25898
25899 -optimize-df Analyze the dataflow of the generated code and improve it.
25900 \end_layout
25901
25902 \begin_layout Subsubsection
25903 Assembling Options
25904 \end_layout
25905
25906 \begin_layout Description
25907 -
25908 \begin_inset ERT
25909 status collapsed
25910
25911 \begin_layout Standard
25912
25913
25914 \backslash
25915 /
25916 \end_layout
25917
25918 \end_inset
25919
25920 -asm= Sets the full path and name of an external assembler to call.
25921 \end_layout
25922
25923 \begin_layout Description
25924 -
25925 \begin_inset ERT
25926 status collapsed
25927
25928 \begin_layout Standard
25929
25930
25931 \backslash
25932 /
25933 \end_layout
25934
25935 \end_inset
25936
25937 -mplab-comp MPLAB
25938 \begin_inset LatexCommand index
25939 name "PIC16!MPLAB"
25940
25941 \end_inset
25942
25943  compatibility option.
25944  Currently only suppresses special gpasm directives.
25945 \end_layout
25946
25947 \begin_layout Subsubsection
25948 Linking Options
25949 \end_layout
25950
25951 \begin_layout Description
25952 -
25953 \begin_inset ERT
25954 status collapsed
25955
25956 \begin_layout Standard
25957
25958
25959 \backslash
25960 /
25961 \end_layout
25962
25963 \end_inset
25964
25965 -link= Sets the full path and name of an external linker to call.
25966 \end_layout
25967
25968 \begin_layout Description
25969 -
25970 \begin_inset ERT
25971 status collapsed
25972
25973 \begin_layout Standard
25974
25975
25976 \backslash
25977 /
25978 \end_layout
25979
25980 \end_inset
25981
25982 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
25983  unitialized data variables with [kword].
25984  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
25985 \end_layout
25986
25987 \begin_layout Description
25988 -
25989 \begin_inset ERT
25990 status collapsed
25991
25992 \begin_layout Standard
25993
25994
25995 \backslash
25996 /
25997 \end_layout
25998
25999 \end_inset
26000
26001 -ivt-loc=n Place the interrupt vector table at address 
26002 \emph on
26003 n
26004 \emph default
26005 .
26006  Useful for bootloaders.
26007 \end_layout
26008
26009 \begin_layout Description
26010 -
26011 \begin_inset ERT
26012 status collapsed
26013
26014 \begin_layout Standard
26015
26016
26017 \backslash
26018 /
26019 \end_layout
26020
26021 \end_inset
26022
26023 -nodefaultlibs Do not link default libraries when linking.
26024 \end_layout
26025
26026 \begin_layout Description
26027 -
26028 \begin_inset ERT
26029 status collapsed
26030
26031 \begin_layout Standard
26032
26033
26034 \backslash
26035 /
26036 \end_layout
26037
26038 \end_inset
26039
26040 -use-crt= Use a custom run-time module instead of the defaults.
26041 \end_layout
26042
26043 \begin_layout Description
26044 -
26045 \begin_inset ERT
26046 status collapsed
26047
26048 \begin_layout Standard
26049
26050
26051 \backslash
26052 /
26053 \end_layout
26054
26055 \end_inset
26056
26057 -no-crt Don't link the default run-time modules
26058 \end_layout
26059
26060 \begin_layout Subsubsection
26061 Debugging Options
26062 \end_layout
26063
26064 \begin_layout Standard
26065 Debugging options enable extra debugging information in the output files.
26066 \end_layout
26067
26068 \begin_layout Description
26069 -
26070 \begin_inset ERT
26071 status collapsed
26072
26073 \begin_layout Standard
26074
26075
26076 \backslash
26077 /
26078 \end_layout
26079
26080 \end_inset
26081
26082 -debug-xtra Similar to -
26083 \begin_inset ERT
26084 status collapsed
26085
26086 \begin_layout Standard
26087
26088
26089 \backslash
26090 /
26091 \end_layout
26092
26093 \end_inset
26094
26095 -debug
26096 \begin_inset LatexCommand index
26097 name "-\\/-debug"
26098
26099 \end_inset
26100
26101 , but dumps more information.
26102 \end_layout
26103
26104 \begin_layout Description
26105 -
26106 \begin_inset ERT
26107 status collapsed
26108
26109 \begin_layout Standard
26110
26111
26112 \backslash
26113 /
26114 \end_layout
26115
26116 \end_inset
26117
26118 -debug-ralloc Force register allocator to dump <source>.d file with debugging
26119  information.
26120  <source> is the name of the file being compiled.
26121 \end_layout
26122
26123 \begin_layout Description
26124 -
26125 \begin_inset ERT
26126 status collapsed
26127
26128 \begin_layout Standard
26129
26130
26131 \backslash
26132 /
26133 \end_layout
26134
26135 \end_inset
26136
26137 -pcode-verbose Enable pcode debugging information in translation.
26138 \end_layout
26139
26140 \begin_layout Description
26141 -
26142 \begin_inset ERT
26143 status collapsed
26144
26145 \begin_layout Standard
26146
26147
26148 \backslash
26149 /
26150 \end_layout
26151
26152 \end_inset
26153
26154 -calltree Dump call tree in .calltree file.
26155 \end_layout
26156
26157 \begin_layout Description
26158 -
26159 \begin_inset ERT
26160 status collapsed
26161
26162 \begin_layout Standard
26163
26164
26165 \backslash
26166 /
26167 \end_layout
26168
26169 \end_inset
26170
26171 -gstack Trace push/pops for stack pointer overflow.
26172 \end_layout
26173
26174 \begin_layout Subsection
26175 Environment Variables
26176 \end_layout
26177
26178 \begin_layout Standard
26179 There is a number of environmental variables that can be used when running
26180  SDCC to enable certain optimizations or force a specific program behaviour.
26181  these variables are primarily for debugging purposes so they can be enabled/dis
26182 abled at will.
26183 \end_layout
26184
26185 \begin_layout Standard
26186 Currently there is only two such variables available:
26187 \end_layout
26188
26189 \begin_layout Description
26190 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
26191  bitfields is optimized by directly loading FSR0 with the address of the
26192  bitfield structure.
26193  Normally SDCC will cast the bitfield structure to a bitfield pointer and
26194  then load FSR0.
26195  This step saves data ram and code space for functions that make heavy use
26196  of bitfields.
26197  (i.e., 80 bytes of code space are saved when compiling malloc.c with this
26198  option).
26199  
26200 \end_layout
26201
26202 \begin_layout Description
26203 NO_REG_OPT Do not perform pCode registers optimization.
26204  This should be used for debugging purposes.
26205  If bugs in the pcode optimizer are found, users can benefit from temporarily
26206  disabling the optimizer until the bug is fixed.
26207 \end_layout
26208
26209 \begin_layout Subsection
26210 Preprocessor Macros
26211 \end_layout
26212
26213 \begin_layout Standard
26214 PIC16
26215 \begin_inset LatexCommand index
26216 name "PIC16"
26217
26218 \end_inset
26219
26220  port defines the following preprocessor macros while translating a source.
26221 \end_layout
26222
26223 \begin_layout Standard
26224 \align center
26225 \begin_inset Tabular
26226 <lyxtabular version="3" rows="6" columns="2">
26227 <features>
26228 <column alignment="center" valignment="top" leftline="true" width="0">
26229 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26230 <row topline="true" bottomline="true">
26231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26232 \begin_inset Text
26233
26234 \begin_layout Standard
26235 Macro
26236 \end_layout
26237
26238 \end_inset
26239 </cell>
26240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26241 \begin_inset Text
26242
26243 \begin_layout Standard
26244 Description
26245 \end_layout
26246
26247 \end_inset
26248 </cell>
26249 </row>
26250 <row topline="true">
26251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26252 \begin_inset Text
26253
26254 \begin_layout Standard
26255 SDCC_pic16
26256 \end_layout
26257
26258 \end_inset
26259 </cell>
26260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26261 \begin_inset Text
26262
26263 \begin_layout Standard
26264 Port identification
26265 \end_layout
26266
26267 \end_inset
26268 </cell>
26269 </row>
26270 <row topline="true">
26271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26272 \begin_inset Text
26273
26274 \begin_layout Standard
26275 _
26276 \begin_inset ERT
26277 status collapsed
26278
26279 \begin_layout Standard
26280
26281
26282 \backslash
26283 /
26284 \end_layout
26285
26286 \end_inset
26287
26288 _pic16
26289 \end_layout
26290
26291 \end_inset
26292 </cell>
26293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26294 \begin_inset Text
26295
26296 \begin_layout Standard
26297 Port identification (same as above)
26298 \end_layout
26299
26300 \end_inset
26301 </cell>
26302 </row>
26303 <row topline="true">
26304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26305 \begin_inset Text
26306
26307 \begin_layout Standard
26308 pic18fxxxx
26309 \end_layout
26310
26311 \end_inset
26312 </cell>
26313 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26314 \begin_inset Text
26315
26316 \begin_layout Standard
26317 MCU Identification.
26318  
26319 \emph on
26320 xxxx
26321 \emph default
26322  is the microcontrol identification number, i.e.
26323  452, 6620, etc
26324 \end_layout
26325
26326 \end_inset
26327 </cell>
26328 </row>
26329 <row topline="true">
26330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26331 \begin_inset Text
26332
26333 \begin_layout Standard
26334 _
26335 \begin_inset ERT
26336 status collapsed
26337
26338 \begin_layout Standard
26339
26340
26341 \backslash
26342 /
26343 \end_layout
26344
26345 \end_inset
26346
26347 _18Fxxxx
26348 \end_layout
26349
26350 \end_inset
26351 </cell>
26352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26353 \begin_inset Text
26354
26355 \begin_layout Standard
26356 MCU Identification (same as above)
26357 \end_layout
26358
26359 \end_inset
26360 </cell>
26361 </row>
26362 <row topline="true" bottomline="true">
26363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26364 \begin_inset Text
26365
26366 \begin_layout Standard
26367 STACK_MODEL_nnn
26368 \end_layout
26369
26370 \end_inset
26371 </cell>
26372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26373 \begin_inset Text
26374
26375 \begin_layout Standard
26376 nnn = SMALL or LARGE respectively according to the stack model used
26377 \end_layout
26378
26379 \end_inset
26380 </cell>
26381 </row>
26382 </lyxtabular>
26383
26384 \end_inset
26385
26386
26387 \end_layout
26388
26389 \begin_layout Standard
26390 \noindent
26391 In addition the following macros are defined when calling assembler:
26392 \end_layout
26393
26394 \begin_layout Standard
26395 \align center
26396 \begin_inset Tabular
26397 <lyxtabular version="3" rows="4" columns="2">
26398 <features>
26399 <column alignment="center" valignment="top" leftline="true" width="0">
26400 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26401 <row topline="true" bottomline="true">
26402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26403 \begin_inset Text
26404
26405 \begin_layout Standard
26406 Macro
26407 \end_layout
26408
26409 \end_inset
26410 </cell>
26411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26412 \begin_inset Text
26413
26414 \begin_layout Standard
26415 Description
26416 \end_layout
26417
26418 \end_inset
26419 </cell>
26420 </row>
26421 <row topline="true">
26422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26423 \begin_inset Text
26424
26425 \begin_layout Standard
26426 __18Fxxxx
26427 \end_layout
26428
26429 \end_inset
26430 </cell>
26431 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26432 \begin_inset Text
26433
26434 \begin_layout Standard
26435 MCU Identification.
26436  
26437 \emph on
26438 xxxx
26439 \emph default
26440  is the microcontrol identification number, i.e.
26441  452, 6620, etc
26442 \end_layout
26443
26444 \end_inset
26445 </cell>
26446 </row>
26447 <row topline="true">
26448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26449 \begin_inset Text
26450
26451 \begin_layout Standard
26452 SDCC_MODEL_nnn
26453 \end_layout
26454
26455 \end_inset
26456 </cell>
26457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26458 \begin_inset Text
26459
26460 \begin_layout Standard
26461 nnn = SMALL or LARGE respectively according to the memory model used for
26462  SDCC
26463 \end_layout
26464
26465 \end_inset
26466 </cell>
26467 </row>
26468 <row topline="true" bottomline="true">
26469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26470 \begin_inset Text
26471
26472 \begin_layout Standard
26473 STACK_MODEL_nnn
26474 \end_layout
26475
26476 \end_inset
26477 </cell>
26478 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26479 \begin_inset Text
26480
26481 \begin_layout Standard
26482 nnn = SMALL or LARGE respectively according to the stack model used
26483 \end_layout
26484
26485 \end_inset
26486 </cell>
26487 </row>
26488 </lyxtabular>
26489
26490 \end_inset
26491
26492
26493 \end_layout
26494
26495 \begin_layout Subsection
26496 Directories
26497 \end_layout
26498
26499 \begin_layout Standard
26500 PIC16
26501 \begin_inset LatexCommand index
26502 name "PIC16"
26503
26504 \end_inset
26505
26506  port uses the following directories for searching header files and libraries.
26507 \end_layout
26508
26509 \begin_layout Standard
26510 \align center
26511 \begin_inset Tabular
26512 <lyxtabular version="3" rows="3" columns="4">
26513 <features>
26514 <column alignment="center" valignment="top" leftline="true" width="0">
26515 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26516 <column alignment="center" valignment="top" width="0">
26517 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26518 <row topline="true" bottomline="true">
26519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26520 \begin_inset Text
26521
26522 \begin_layout Standard
26523 Directory
26524 \end_layout
26525
26526 \end_inset
26527 </cell>
26528 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26529 \begin_inset Text
26530
26531 \begin_layout Standard
26532 Description
26533 \end_layout
26534
26535 \end_inset
26536 </cell>
26537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26538 \begin_inset Text
26539
26540 \begin_layout Standard
26541 Target
26542 \end_layout
26543
26544 \end_inset
26545 </cell>
26546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26547 \begin_inset Text
26548
26549 \begin_layout Standard
26550 Command prefix
26551 \end_layout
26552
26553 \end_inset
26554 </cell>
26555 </row>
26556 <row topline="true">
26557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26558 \begin_inset Text
26559
26560 \begin_layout Standard
26561 PREFIX/sdcc/include/pic16
26562 \end_layout
26563
26564 \end_inset
26565 </cell>
26566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26567 \begin_inset Text
26568
26569 \begin_layout Standard
26570 PIC16 specific headers
26571 \end_layout
26572
26573 \end_inset
26574 </cell>
26575 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26576 \begin_inset Text
26577
26578 \begin_layout Standard
26579 Compiler
26580 \end_layout
26581
26582 \end_inset
26583 </cell>
26584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26585 \begin_inset Text
26586
26587 \begin_layout Standard
26588 -I
26589 \end_layout
26590
26591 \end_inset
26592 </cell>
26593 </row>
26594 <row topline="true" bottomline="true">
26595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26596 \begin_inset Text
26597
26598 \begin_layout Standard
26599 PREFIX/sdcc/lib/pic16
26600 \end_layout
26601
26602 \end_inset
26603 </cell>
26604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26605 \begin_inset Text
26606
26607 \begin_layout Standard
26608 PIC16 specific libraries
26609 \end_layout
26610
26611 \end_inset
26612 </cell>
26613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26614 \begin_inset Text
26615
26616 \begin_layout Standard
26617 Linker
26618 \end_layout
26619
26620 \end_inset
26621 </cell>
26622 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26623 \begin_inset Text
26624
26625 \begin_layout Standard
26626 -L
26627 \end_layout
26628
26629 \end_inset
26630 </cell>
26631 </row>
26632 </lyxtabular>
26633
26634 \end_inset
26635
26636
26637 \end_layout
26638
26639 \begin_layout Subsection
26640 Pragmas
26641 \begin_inset LatexCommand label
26642 name "sub:PIC16_Pragmas"
26643
26644 \end_inset
26645
26646
26647 \end_layout
26648
26649 \begin_layout Standard
26650 The PIC16
26651 \begin_inset LatexCommand index
26652 name "PIC16"
26653
26654 \end_inset
26655
26656  port currently supports the following pragmas:
26657 \end_layout
26658
26659 \begin_layout Description
26660 stack
26661 \begin_inset LatexCommand index
26662 name "PIC16!Pragmas!\\#pragma stack"
26663
26664 \end_inset
26665
26666  This forces the code generator to initialize the stack & frame pointers
26667  at a specific address.
26668  This is an ad hoc solution for cases where no STACK directive is available
26669  in the linker script or gplink is not instructed to create a stack section.
26670 \newline
26671 The
26672  stack pragma should be used only once in a project.
26673  Multiple pragmas may result in indeterminate behaviour of the program.
26674 \begin_inset Foot
26675 status open
26676
26677 \begin_layout Standard
26678 The old format (ie.
26679  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
26680  cross page boundaries (or even exceed the available data RAM) and crash
26681  the program.
26682  Make sure that stack does not cross page boundaries when using the SMALL
26683  stack model.
26684 \end_layout
26685
26686 \end_inset
26687
26688
26689 \newline
26690 The format is as follows:
26691 \newline
26692
26693 \end_layout
26694
26695 \begin_layout LyX-Code
26696 #pragma stack bottom_address [stack_size]
26697 \newline
26698
26699 \end_layout
26700
26701 \begin_layout Standard
26702
26703 \emph on
26704 bottom_address
26705 \emph default
26706  is the lower bound of the stack section.
26707  The stack pointer initially will point at address (bottom_address+stack_size-1).
26708 \end_layout
26709
26710 \begin_layout LyX-Code
26711 Example:
26712 \end_layout
26713
26714 \begin_layout LyX-Code
26715
26716 \end_layout
26717
26718 \begin_layout LyX-Code
26719 /* initializes stack of 100 bytes at RAM address 0x200 */
26720 \end_layout
26721
26722 \begin_layout LyX-Code
26723 #pragma stack 0x200 100
26724 \end_layout
26725
26726 \begin_layout Standard
26727 If the stack_size field is omitted then a stack is created with the default
26728  size of 64.
26729  This size might be enough for most programs, but its not enough for operations
26730  with deep function nesting or excessive stack usage.
26731 \end_layout
26732
26733 \begin_layout Description
26734 code
26735 \begin_inset LatexCommand index
26736 name "PIC16!Pragmas!\\#pragma code"
26737
26738 \end_inset
26739
26740  Force a function to a static FLASH address.
26741 \end_layout
26742
26743 \begin_layout LyX-Code
26744 Example:
26745 \end_layout
26746
26747 \begin_layout LyX-Code
26748
26749 \end_layout
26750
26751 \begin_layout LyX-Code
26752 /* place function test_func at 0x4000 */
26753 \end_layout
26754
26755 \begin_layout LyX-Code
26756 #pragma code test_func 0x4000
26757 \end_layout
26758
26759 \begin_layout LyX-Code
26760
26761 \end_layout
26762
26763 \begin_layout Description
26764 library instructs the linker to use a library module.
26765 \newline
26766 Usage:
26767 \end_layout
26768
26769 \begin_layout LyX-Code
26770 #pragma library module_name
26771 \end_layout
26772
26773 \begin_layout Standard
26774
26775 \emph on
26776 module_name
26777 \emph default
26778  can be any library or object file (including its path).
26779  Note that there are four reserved keywords which have special meaning.
26780  These are:
26781 \end_layout
26782
26783 \begin_layout Standard
26784 \align center
26785 \begin_inset Tabular
26786 <lyxtabular version="3" rows="6" columns="3">
26787 <features>
26788 <column alignment="center" valignment="top" leftline="true" width="0">
26789 <column alignment="block" valignment="top" leftline="true" width="20page%">
26790 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
26791 <row topline="true" bottomline="true">
26792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26793 \begin_inset Text
26794
26795 \begin_layout Standard
26796 Keyword
26797 \end_layout
26798
26799 \end_inset
26800 </cell>
26801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26802 \begin_inset Text
26803
26804 \begin_layout Standard
26805 Description
26806 \end_layout
26807
26808 \end_inset
26809 </cell>
26810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26811 \begin_inset Text
26812
26813 \begin_layout Standard
26814 Module to link
26815 \end_layout
26816
26817 \end_inset
26818 </cell>
26819 </row>
26820 <row topline="true">
26821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26822 \begin_inset Text
26823
26824 \begin_layout Standard
26825
26826 \series bold
26827 ignore
26828 \end_layout
26829
26830 \end_inset
26831 </cell>
26832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26833 \begin_inset Text
26834
26835 \begin_layout Standard
26836 ignore all library pragmas
26837 \end_layout
26838
26839 \end_inset
26840 </cell>
26841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26842 \begin_inset Text
26843
26844 \begin_layout Standard
26845
26846 \emph on
26847 (none)
26848 \end_layout
26849
26850 \end_inset
26851 </cell>
26852 </row>
26853 <row topline="true">
26854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26855 \begin_inset Text
26856
26857 \begin_layout Standard
26858
26859 \series bold
26860 c
26861 \end_layout
26862
26863 \end_inset
26864 </cell>
26865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26866 \begin_inset Text
26867
26868 \begin_layout Standard
26869 link the C library
26870 \end_layout
26871
26872 \end_inset
26873 </cell>
26874 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26875 \begin_inset Text
26876
26877 \begin_layout Standard
26878
26879 \emph on
26880 libc18f
26881 \emph default
26882 .lib
26883 \end_layout
26884
26885 \end_inset
26886 </cell>
26887 </row>
26888 <row topline="true">
26889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26890 \begin_inset Text
26891
26892 \begin_layout Standard
26893
26894 \series bold
26895 math
26896 \end_layout
26897
26898 \end_inset
26899 </cell>
26900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26901 \begin_inset Text
26902
26903 \begin_layout Standard
26904 link the Math libarary
26905 \end_layout
26906
26907 \end_inset
26908 </cell>
26909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26910 \begin_inset Text
26911
26912 \begin_layout Standard
26913
26914 \emph on
26915 libm18f
26916 \emph default
26917 .lib
26918 \end_layout
26919
26920 \end_inset
26921 </cell>
26922 </row>
26923 <row topline="true">
26924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26925 \begin_inset Text
26926
26927 \begin_layout Standard
26928
26929 \series bold
26930 io
26931 \end_layout
26932
26933 \end_inset
26934 </cell>
26935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26936 \begin_inset Text
26937
26938 \begin_layout Standard
26939 link the I/O library
26940 \end_layout
26941
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 \begin_layout Standard
26948
26949 \emph on
26950 libio18f*
26951 \emph default
26952 .lib
26953 \end_layout
26954
26955 \end_inset
26956 </cell>
26957 </row>
26958 <row topline="true" bottomline="true">
26959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26960 \begin_inset Text
26961
26962 \begin_layout Standard
26963
26964 \series bold
26965 debug
26966 \end_layout
26967
26968 \end_inset
26969 </cell>
26970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26971 \begin_inset Text
26972
26973 \begin_layout Standard
26974 link the debug library
26975 \end_layout
26976
26977 \end_inset
26978 </cell>
26979 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26980 \begin_inset Text
26981
26982 \begin_layout Standard
26983
26984 \emph on
26985 libdebug
26986 \emph default
26987 .lib
26988 \end_layout
26989
26990 \end_inset
26991 </cell>
26992 </row>
26993 </lyxtabular>
26994
26995 \end_inset
26996
26997
26998 \newline
26999 * is the device number, i.e.
27000  452 for PIC18F452 MCU.
27001 \end_layout
27002
27003 \begin_layout Standard
27004 \noindent
27005 This feature allows for linking with specific libraries without having to
27006  explicit name them in the command line.
27007  Note that the 
27008 \noun on
27009 ignore
27010 \noun default
27011  keyword will reject all modules specified by the library pragma.
27012 \end_layout
27013
27014 \begin_layout Description
27015 udata The pragma udata instructs the compiler to emit code so that linker
27016  will place a variable at a specific memory bank.
27017 \end_layout
27018
27019 \begin_layout LyX-Code
27020 Example:
27021 \end_layout
27022
27023 \begin_layout LyX-Code
27024
27025 \end_layout
27026
27027 \begin_layout LyX-Code
27028 /* places variable foo at bank2 */
27029 \end_layout
27030
27031 \begin_layout LyX-Code
27032 #pragma udata bank2 foo
27033 \end_layout
27034
27035 \begin_layout LyX-Code
27036 char foo;
27037 \end_layout
27038
27039 \begin_layout Standard
27040 In order for this pragma to work extra SECTION directives should be added
27041  in the .lkr script.
27042  In the following example a sample .lkr file is shown:
27043 \end_layout
27044
27045 \begin_layout LyX-Code
27046
27047 \end_layout
27048
27049 \begin_layout LyX-Code
27050 // Sample linker script for the PIC18F452 processor
27051 \end_layout
27052
27053 \begin_layout LyX-Code
27054 LIBPATH .
27055 \end_layout
27056
27057 \begin_layout LyX-Code
27058 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
27059 \end_layout
27060
27061 \begin_layout LyX-Code
27062 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
27063 \end_layout
27064
27065 \begin_layout LyX-Code
27066 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
27067 \end_layout
27068
27069 \begin_layout LyX-Code
27070 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
27071 \end_layout
27072
27073 \begin_layout LyX-Code
27074 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
27075 \end_layout
27076
27077 \begin_layout LyX-Code
27078 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
27079 \end_layout
27080
27081 \begin_layout LyX-Code
27082 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
27083 \end_layout
27084
27085 \begin_layout LyX-Code
27086
27087 \end_layout
27088
27089 \begin_layout LyX-Code
27090 DATABANK   NAME=gpr0       START=0x80           END=0xFF
27091 \end_layout
27092
27093 \begin_layout LyX-Code
27094 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
27095 \end_layout
27096
27097 \begin_layout LyX-Code
27098 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
27099 \end_layout
27100
27101 \begin_layout LyX-Code
27102 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
27103 \end_layout
27104
27105 \begin_layout LyX-Code
27106 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
27107 \end_layout
27108
27109 \begin_layout LyX-Code
27110 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
27111 \end_layout
27112
27113 \begin_layout LyX-Code
27114 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
27115 \end_layout
27116
27117 \begin_layout LyX-Code
27118
27119 \end_layout
27120
27121 \begin_layout LyX-Code
27122 SECTION    NAME=CONFIG     ROM=config
27123 \end_layout
27124
27125 \begin_layout LyX-Code
27126
27127 \end_layout
27128
27129 \begin_layout LyX-Code
27130 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
27131 \end_layout
27132
27133 \begin_layout LyX-Code
27134 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
27135 \end_layout
27136
27137 \begin_layout LyX-Code
27138 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
27139 \end_layout
27140
27141 \begin_layout LyX-Code
27142 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
27143 \end_layout
27144
27145 \begin_layout LyX-Code
27146 SECTION    NAME=bank4      RAM=gpr4
27147 \end_layout
27148
27149 \begin_layout LyX-Code
27150 SECTION    NAME=bank5      RAM=gpr5
27151 \end_layout
27152
27153 \begin_layout Standard
27154 The linker will recognise the section name set in the pragma statement and
27155  will position the variable at the memory bank set with the RAM field at
27156  the SECTION line in the linker script file.
27157 \end_layout
27158
27159 \begin_layout Subsection
27160 Header Files
27161 \begin_inset LatexCommand label
27162 name "sub:PIC16_Header-Files"
27163
27164 \end_inset
27165
27166
27167 \end_layout
27168
27169 \begin_layout Standard
27170 There is one main header file
27171 \begin_inset LatexCommand index
27172 name "PIC16!Header files"
27173
27174 \end_inset
27175
27176  that can be included to the source files using the pic16
27177 \begin_inset LatexCommand index
27178 name "PIC16"
27179
27180 \end_inset
27181
27182  port.
27183  That file is the 
27184 \series bold
27185 pic18fregs.h
27186 \series default
27187 .
27188  This header file contains the definitions for the processor special registers,
27189  so it is necessary if the source accesses them.
27190  It can be included by adding the following line in the beginning of the
27191  file:
27192 \end_layout
27193
27194 \begin_layout LyX-Code
27195 #include <pic18fregs.h>
27196 \end_layout
27197
27198 \begin_layout Standard
27199 The specific microcontroller is selected within the pic18fregs.h automatically,
27200  so the same source can be used with a variety of devices.
27201 \end_layout
27202
27203 \begin_layout Subsection
27204 Libraries
27205 \begin_inset LatexCommand label
27206 name "sub:pic16Libraries"
27207
27208 \end_inset
27209
27210
27211 \end_layout
27212
27213 \begin_layout Standard
27214 The libraries
27215 \begin_inset LatexCommand index
27216 name "PIC16!Libraries"
27217
27218 \end_inset
27219
27220  that PIC16
27221 \begin_inset LatexCommand index
27222 name "PIC16"
27223
27224 \end_inset
27225
27226  port depends on are the microcontroller device libraries which contain
27227  the symbol definitions for the microcontroller special function registers.
27228  These libraries have the format pic18fxxxx.lib, where 
27229 \emph on
27230 xxxx
27231 \emph default
27232  is the microcontroller identification number.
27233  The specific library is selected automatically by the compiler at link
27234  stage according to the selected device.
27235 \end_layout
27236
27237 \begin_layout Standard
27238 \noindent
27239 Libraries are created with gplib which is part of the gputils package 
27240 \begin_inset LatexCommand url
27241 target "http://sourceforge.net/projects/gputils"
27242
27243 \end_inset
27244
27245 .
27246 \end_layout
27247
27248 \begin_layout Subsubsection*
27249 Building the libraries
27250 \end_layout
27251
27252 \begin_layout Standard
27253 Before using SDCC/pic16 there are some libraries that need to be compiled.
27254  This process is done automatically if gputils are found at SDCC's compile
27255  time.
27256  Should you require to rebuild the pic16 libraries manually, these are the
27257  steps required to do so under Linux or Mac OS X (cygwin might work as well,
27258  but is untested):
27259 \end_layout
27260
27261 \begin_layout LyX-Code
27262 cd device/lib/pic16
27263 \end_layout
27264
27265 \begin_layout LyX-Code
27266 ./configure.gnu
27267 \end_layout
27268
27269 \begin_layout LyX-Code
27270 cd ..
27271 \end_layout
27272
27273 \begin_layout LyX-Code
27274 make model-pic16
27275 \end_layout
27276
27277 \begin_layout LyX-Code
27278 su -c 'make install'     # install the libraries, you need the root password
27279 \end_layout
27280
27281 \begin_layout LyX-Code
27282 cd ../..
27283 \end_layout
27284
27285 \begin_layout Standard
27286 If you need to install the headers too, do:
27287 \end_layout
27288
27289 \begin_layout LyX-Code
27290 cd device/include
27291 \end_layout
27292
27293 \begin_layout LyX-Code
27294 su -c 'make install'     # install the headers, you need the root password
27295 \end_layout
27296
27297 \begin_layout Subsection
27298 Adding New Devices to the Port
27299 \end_layout
27300
27301 \begin_layout Standard
27302 Adding support for a new 16
27303 \begin_inset ERT
27304 status collapsed
27305
27306 \begin_layout Standard
27307
27308
27309 \backslash
27310 ,
27311 \end_layout
27312
27313 \end_inset
27314
27315 bit PIC MCU requires the following steps:
27316 \end_layout
27317
27318 \begin_layout Enumerate
27319 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
27320 \newline
27321
27322 \family typewriter
27323 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
27324 inc
27325 \end_layout
27326
27327 \begin_layout Enumerate
27328
27329 \family typewriter
27330 mv picDEVICE.h /path/to/sdcc/device/include/pic16
27331 \end_layout
27332
27333 \begin_layout Enumerate
27334
27335 \family typewriter
27336 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
27337 \end_layout
27338
27339 \begin_layout Enumerate
27340 Add DEVICE to 
27341 \family typewriter
27342 /path/to/sdcc/device/lib/pic16/pics.all
27343 \family default
27344
27345 \newline
27346 Note: No 18f prefix here!
27347 \end_layout
27348
27349 \begin_layout Enumerate
27350 Edit 
27351 \family typewriter
27352 /path/to/sdcc/device/include/pic16/adc.h
27353 \newline
27354
27355 \family default
27356 Add the new devices to the correct ADC style class (depending on the number
27357  of ADC channels).
27358 \newline
27359 Do not touch 
27360 \family typewriter
27361 adc.h
27362 \family default
27363  if the device does not offer any ADC at all.
27364 \end_layout
27365
27366 \begin_layout Enumerate
27367 Edit 
27368 \family typewriter
27369 /path/to/sdcc/device/include/pic16/pic18fregs.h
27370 \family default
27371
27372 \newline
27373 The file format is self-explanatory, just add
27374 \newline
27375
27376 \family typewriter
27377 #elif defined(picDEVICE)
27378 \newline
27379 #
27380 \begin_inset ERT
27381 status collapsed
27382
27383 \begin_layout Standard
27384
27385
27386 \backslash
27387  
27388 \backslash
27389  
27390 \end_layout
27391
27392 \end_inset
27393
27394 include <picDEVICE.h>
27395 \family default
27396
27397 \newline
27398 at the right place (keep the file sorted, please).
27399 \end_layout
27400
27401 \begin_layout Enumerate
27402 Edit 
27403 \family typewriter
27404 /path/to/sdcc/device/include/pic16devices.txt
27405 \newline
27406
27407 \family default
27408 Copy and modify an existing entry or create a new one and insert it at the
27409  correct place (keep the file sorted, please).
27410 \end_layout
27411
27412 \begin_layout Enumerate
27413 Add the device to 
27414 \family typewriter
27415 /path/to/sdcc/device/lib/pic16/libdev/Makefile.am
27416 \family default
27417
27418 \newline
27419 Copy an existing entry and adjust the device name.
27420 \end_layout
27421
27422 \begin_layout Enumerate
27423 Add the device to 
27424 \family typewriter
27425 /path/to/sdcc/device/lib/pic16/libio/Makefile.am
27426 \family default
27427
27428 \newline
27429 Copy the record from the 18f2220 and adjust the device name.
27430 \newline
27431 If the new device
27432  does not offer ADC, I
27433 \begin_inset Formula $^{\text{2}}$
27434 \end_inset
27435
27436 C, and/or (E)USART functionality as assumed by the library, remove the lines
27437  with references to 
27438 \family typewriter
27439 adc/*.c
27440 \family default
27441
27442 \family typewriter
27443 usart/*.c
27444 \family default
27445 , or 
27446 \family typewriter
27447 usart/*.c
27448 \family default
27449 , respectively.
27450 \end_layout
27451
27452 \begin_layout Enumerate
27453 Update 
27454 \family typewriter
27455 libdev/Makefile.in
27456 \family default
27457  and 
27458 \family typewriter
27459 libio/Makefile.in
27460 \family default
27461  using
27462 \newline
27463
27464 \family typewriter
27465 ./bootstrap.sh
27466 \family default
27467
27468 \newline
27469 in 
27470 \family typewriter
27471 /path/to/sdcc/device/lib/pic16
27472 \family default
27473 .
27474 \end_layout
27475
27476 \begin_layout Enumerate
27477 Recompile the pic16 libraries as described in 
27478 \begin_inset LatexCommand ref
27479 reference "sub:pic16Libraries"
27480
27481 \end_inset
27482
27483 .
27484 \end_layout
27485
27486 \begin_layout Subsection
27487 Memory Models
27488 \end_layout
27489
27490 \begin_layout Standard
27491 The following memory models are supported by the PIC16 port:
27492 \end_layout
27493
27494 \begin_layout Itemize
27495 small model
27496 \end_layout
27497
27498 \begin_layout Itemize
27499 large model
27500 \end_layout
27501
27502 \begin_layout Standard
27503 Memory model affects the default size of pointers within the source.
27504  The sizes are shown in the next table:
27505 \end_layout
27506
27507 \begin_layout Standard
27508 \align center
27509 \begin_inset Tabular
27510 <lyxtabular version="3" rows="3" columns="3">
27511 <features>
27512 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27513 <column alignment="center" valignment="top" leftline="true" width="0">
27514 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27515 <row topline="true" bottomline="true">
27516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27517 \begin_inset Text
27518
27519 \begin_layout Standard
27520 Pointer sizes according to memory model
27521 \end_layout
27522
27523 \end_inset
27524 </cell>
27525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27526 \begin_inset Text
27527
27528 \begin_layout Standard
27529 small model
27530 \end_layout
27531
27532 \end_inset
27533 </cell>
27534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27535 \begin_inset Text
27536
27537 \begin_layout Standard
27538 large model
27539 \end_layout
27540
27541 \end_inset
27542 </cell>
27543 </row>
27544 <row topline="true" bottomline="true">
27545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27546 \begin_inset Text
27547
27548 \begin_layout Standard
27549 code pointers
27550 \end_layout
27551
27552 \end_inset
27553 </cell>
27554 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27555 \begin_inset Text
27556
27557 \begin_layout Standard
27558 16-bits
27559 \end_layout
27560
27561 \end_inset
27562 </cell>
27563 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27564 \begin_inset Text
27565
27566 \begin_layout Standard
27567 24-bits
27568 \end_layout
27569
27570 \end_inset
27571 </cell>
27572 </row>
27573 <row topline="true" bottomline="true">
27574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27575 \begin_inset Text
27576
27577 \begin_layout Standard
27578 data pointers
27579 \end_layout
27580
27581 \end_inset
27582 </cell>
27583 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
27584 \begin_inset Text
27585
27586 \begin_layout Standard
27587 16-bits
27588 \end_layout
27589
27590 \end_inset
27591 </cell>
27592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27593 \begin_inset Text
27594
27595 \begin_layout Standard
27596 16-bits
27597 \end_layout
27598
27599 \end_inset
27600 </cell>
27601 </row>
27602 </lyxtabular>
27603
27604 \end_inset
27605
27606
27607 \end_layout
27608
27609 \begin_layout Standard
27610 It is advisable that all sources within a project are compiled with the
27611  same memory model.
27612  If one wants to override the default memory model, this can be done by
27613  declaring a pointer as 
27614 \series bold
27615 far
27616 \series default
27617  or 
27618 \series bold
27619 near
27620 \series default
27621 .
27622  Far selects large memory model's pointers, while near selects small memory
27623  model's pointers.
27624 \end_layout
27625
27626 \begin_layout Standard
27627 The standard device libraries (see 
27628 \begin_inset LatexCommand ref
27629 reference "sub:PIC16_Header-Files"
27630
27631 \end_inset
27632
27633 ) contain no reference to pointers, so they can be used with both memory
27634  models.
27635 \end_layout
27636
27637 \begin_layout Subsection
27638 Stack
27639 \end_layout
27640
27641 \begin_layout Standard
27642 The stack
27643 \begin_inset LatexCommand index
27644 name "PIC16!stack"
27645
27646 \end_inset
27647
27648  implementation for the PIC16 port uses two indirect registers, FSR1 and
27649  FSR2.
27650 \end_layout
27651
27652 \begin_layout Description
27653 FSR1 is assigned as stack pointer
27654 \end_layout
27655
27656 \begin_layout Description
27657 FSR2 is assigned as frame pointer
27658 \end_layout
27659
27660 \begin_layout Standard
27661 The following stack models are supported by the PIC16 port
27662 \end_layout
27663
27664 \begin_layout Itemize
27665
27666 \noun on
27667 small
27668 \noun default
27669  model
27670 \end_layout
27671
27672 \begin_layout Itemize
27673
27674 \noun on
27675 large
27676 \noun default
27677  model
27678 \end_layout
27679
27680 \begin_layout Standard
27681
27682 \noun on
27683 Small
27684 \noun default
27685  model means that only the FSRxL byte is used to access stack and frame,
27686  while 
27687 \emph on
27688 \noun on
27689 large
27690 \emph default
27691 \noun default
27692  uses both FSRxL and FSRxH registers.
27693  The following table shows the stack/frame pointers sizes according to stack
27694  model and the maximum space they can address:
27695 \end_layout
27696
27697 \begin_layout Standard
27698 \align center
27699 \begin_inset Tabular
27700 <lyxtabular version="3" rows="3" columns="3">
27701 <features>
27702 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27703 <column alignment="center" valignment="top" leftline="true" width="0">
27704 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27705 <row topline="true" bottomline="true">
27706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27707 \begin_inset Text
27708
27709 \begin_layout Standard
27710 Stack & Frame pointer sizes according to stack model
27711 \end_layout
27712
27713 \end_inset
27714 </cell>
27715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27716 \begin_inset Text
27717
27718 \begin_layout Standard
27719 small
27720 \end_layout
27721
27722 \end_inset
27723 </cell>
27724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27725 \begin_inset Text
27726
27727 \begin_layout Standard
27728 large
27729 \end_layout
27730
27731 \end_inset
27732 </cell>
27733 </row>
27734 <row topline="true">
27735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27736 \begin_inset Text
27737
27738 \begin_layout Standard
27739 Stack pointer FSR1
27740 \end_layout
27741
27742 \end_inset
27743 </cell>
27744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27745 \begin_inset Text
27746
27747 \begin_layout Standard
27748 8-bits
27749 \end_layout
27750
27751 \end_inset
27752 </cell>
27753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27754 \begin_inset Text
27755
27756 \begin_layout Standard
27757 16-bits
27758 \end_layout
27759
27760 \end_inset
27761 </cell>
27762 </row>
27763 <row topline="true" bottomline="true">
27764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27765 \begin_inset Text
27766
27767 \begin_layout Standard
27768 Frame pointer FSR2
27769 \end_layout
27770
27771 \end_inset
27772 </cell>
27773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27774 \begin_inset Text
27775
27776 \begin_layout Standard
27777 8-bits
27778 \end_layout
27779
27780 \end_inset
27781 </cell>
27782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27783 \begin_inset Text
27784
27785 \begin_layout Standard
27786 16-bits
27787 \end_layout
27788
27789 \end_inset
27790 </cell>
27791 </row>
27792 </lyxtabular>
27793
27794 \end_inset
27795
27796
27797 \end_layout
27798
27799 \begin_layout Standard
27800 \noindent
27801
27802 \noun on
27803 Large 
27804 \noun default
27805 stack model is currently not working properly throughout the code generator.
27806  So its use is not advised.
27807  Also there are some other points that need special care:
27808 \newline
27809
27810 \end_layout
27811
27812 \begin_layout Enumerate
27813 Do not create stack sections with size more than one physical bank (that
27814  is 256 bytes)
27815 \end_layout
27816
27817 \begin_layout Enumerate
27818 Stack sections should no cross physical bank limits (i.e.
27819  #pragma stack 0x50 0x100)
27820 \end_layout
27821
27822 \begin_layout Standard
27823 These limitations are caused by the fact that only FSRxL is modified when
27824  using SMALL stack model, so no more than 256 bytes of stack can be used.
27825  This problem will disappear after LARGE model is fully implemented.
27826 \end_layout
27827
27828 \begin_layout Subsection
27829 Functions
27830 \end_layout
27831
27832 \begin_layout Standard
27833 In addition to the standard SDCC function keywords, PIC16
27834 \begin_inset LatexCommand index
27835 name "PIC16"
27836
27837 \end_inset
27838
27839  port makes available two more:
27840 \end_layout
27841
27842 \begin_layout Description
27843 wparam
27844 \begin_inset LatexCommand index
27845 name "PIC16!wparam"
27846
27847 \end_inset
27848
27849  Use the WREG to pass one byte of the first function argument.
27850  This improves speed but you may not use this for functions with arguments
27851  that are called via function pointers, otherwise the first byte of the
27852  first parameter will get lost.
27853  Usage:
27854 \end_layout
27855
27856 \begin_layout LyX-Code
27857 void func_wparam(int a) wparam
27858 \end_layout
27859
27860 \begin_layout LyX-Code
27861 {
27862 \end_layout
27863
27864 \begin_layout LyX-Code
27865     /* WREG hold the lower part of a */
27866 \end_layout
27867
27868 \begin_layout LyX-Code
27869     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
27870  */
27871 \end_layout
27872
27873 \begin_layout LyX-Code
27874 ...
27875 \end_layout
27876
27877 \begin_layout LyX-Code
27878 }
27879 \end_layout
27880
27881 \begin_layout Description
27882 shadowregs
27883 \begin_inset LatexCommand index
27884 name "PIC16!shadowregs"
27885
27886 \end_inset
27887
27888  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
27889  hardware shadow registers which hold the values of WREG, STATUS and BSR
27890  registers.
27891  This can be done by adding the keyword 
27892 \emph on
27893 shadowregs
27894 \emph default
27895  before the 
27896 \emph on
27897 interrupt
27898 \emph default
27899  keyword in the function's header.
27900 \end_layout
27901
27902 \begin_layout LyX-Code
27903 void isr_shadow(void) shadowregs interrupt 1
27904 \end_layout
27905
27906 \begin_layout LyX-Code
27907 {
27908 \end_layout
27909
27910 \begin_layout LyX-Code
27911 ...
27912 \end_layout
27913
27914 \begin_layout LyX-Code
27915 }
27916 \end_layout
27917
27918 \begin_layout Standard
27919
27920 \emph on
27921 shadowregs
27922 \emph default
27923  instructs the code generator not to store/restore WREG, STATUS, BSR when
27924  entering/exiting the ISR.
27925 \end_layout
27926
27927 \begin_layout Subsection
27928 Function return values
27929 \end_layout
27930
27931 \begin_layout Standard
27932 Return values from functions are placed to the appropriate registers following
27933  a modified Microchip policy optimized for SDCC.
27934  The following table shows these registers:
27935 \end_layout
27936
27937 \begin_layout Standard
27938 \align center
27939 \begin_inset Tabular
27940 <lyxtabular version="3" rows="6" columns="2">
27941 <features>
27942 <column alignment="center" valignment="top" leftline="true" width="0">
27943 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27944 <row topline="true" bottomline="true">
27945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27946 \begin_inset Text
27947
27948 \begin_layout Standard
27949 size
27950 \end_layout
27951
27952 \end_inset
27953 </cell>
27954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27955 \begin_inset Text
27956
27957 \begin_layout Standard
27958 destination register
27959 \end_layout
27960
27961 \end_inset
27962 </cell>
27963 </row>
27964 <row topline="true">
27965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27966 \begin_inset Text
27967
27968 \begin_layout Standard
27969 8 bits
27970 \end_layout
27971
27972 \end_inset
27973 </cell>
27974 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27975 \begin_inset Text
27976
27977 \begin_layout Standard
27978 WREG
27979 \end_layout
27980
27981 \end_inset
27982 </cell>
27983 </row>
27984 <row topline="true">
27985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27986 \begin_inset Text
27987
27988 \begin_layout Standard
27989 16 bits
27990 \end_layout
27991
27992 \end_inset
27993 </cell>
27994 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27995 \begin_inset Text
27996
27997 \begin_layout Standard
27998 PRODL:WREG
27999 \end_layout
28000
28001 \end_inset
28002 </cell>
28003 </row>
28004 <row topline="true">
28005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28006 \begin_inset Text
28007
28008 \begin_layout Standard
28009 24 bits
28010 \end_layout
28011
28012 \end_inset
28013 </cell>
28014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28015 \begin_inset Text
28016
28017 \begin_layout Standard
28018 PRODH:PRODL:WREG
28019 \end_layout
28020
28021 \end_inset
28022 </cell>
28023 </row>
28024 <row topline="true">
28025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28026 \begin_inset Text
28027
28028 \begin_layout Standard
28029 32 bits
28030 \end_layout
28031
28032 \end_inset
28033 </cell>
28034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28035 \begin_inset Text
28036
28037 \begin_layout Standard
28038 FSR0L:PRODH:PRODL:WREG
28039 \end_layout
28040
28041 \end_inset
28042 </cell>
28043 </row>
28044 <row topline="true" bottomline="true">
28045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28046 \begin_inset Text
28047
28048 \begin_layout Standard
28049 >32 bits
28050 \end_layout
28051
28052 \end_inset
28053 </cell>
28054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28055 \begin_inset Text
28056
28057 \begin_layout Standard
28058 on stack, FSR0 points to the beginning
28059 \end_layout
28060
28061 \end_inset
28062 </cell>
28063 </row>
28064 </lyxtabular>
28065
28066 \end_inset
28067
28068
28069 \end_layout
28070
28071 \begin_layout Subsection
28072 Interrupts
28073 \end_layout
28074
28075 \begin_layout Standard
28076 An interrupt
28077 \begin_inset LatexCommand index
28078 name "PIC16!interrupt"
28079
28080 \end_inset
28081
28082  service routine (ISR) is declared using the 
28083 \emph on
28084 interrupt
28085 \emph default
28086  keyword.
28087 \end_layout
28088
28089 \begin_layout LyX-Code
28090 void isr(void) interrupt 
28091 \emph on
28092 n
28093 \end_layout
28094
28095 \begin_layout LyX-Code
28096 {
28097 \end_layout
28098
28099 \begin_layout LyX-Code
28100 ...
28101 \end_layout
28102
28103 \begin_layout LyX-Code
28104 }
28105 \end_layout
28106
28107 \begin_layout Standard
28108
28109 \emph on
28110 n
28111 \emph default
28112  is the interrupt number, which for PIC18F devices can be:
28113 \end_layout
28114
28115 \begin_layout Standard
28116 \align center
28117 \begin_inset Tabular
28118 <lyxtabular version="3" rows="4" columns="3">
28119 <features>
28120 <column alignment="center" valignment="top" leftline="true" width="0">
28121 <column alignment="center" valignment="top" leftline="true" width="0">
28122 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28123 <row topline="true" bottomline="true">
28124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28125 \begin_inset Text
28126
28127 \begin_layout Standard
28128
28129 \emph on
28130 n
28131 \end_layout
28132
28133 \end_inset
28134 </cell>
28135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28136 \begin_inset Text
28137
28138 \begin_layout Standard
28139 Interrupt Vector
28140 \end_layout
28141
28142 \end_inset
28143 </cell>
28144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28145 \begin_inset Text
28146
28147 \begin_layout Standard
28148 Interrupt Vector Address
28149 \end_layout
28150
28151 \end_inset
28152 </cell>
28153 </row>
28154 <row topline="true">
28155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28156 \begin_inset Text
28157
28158 \begin_layout Standard
28159 0
28160 \end_layout
28161
28162 \end_inset
28163 </cell>
28164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28165 \begin_inset Text
28166
28167 \begin_layout Standard
28168 RESET vector
28169 \end_layout
28170
28171 \end_inset
28172 </cell>
28173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28174 \begin_inset Text
28175
28176 \begin_layout Standard
28177 0x000000
28178 \end_layout
28179
28180 \end_inset
28181 </cell>
28182 </row>
28183 <row topline="true">
28184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28185 \begin_inset Text
28186
28187 \begin_layout Standard
28188
28189 \family roman
28190 \series medium
28191 \shape up
28192 \size normal
28193 \emph off
28194 \bar no
28195 \noun off
28196 \color none
28197 1
28198 \end_layout
28199
28200 \end_inset
28201 </cell>
28202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28203 \begin_inset Text
28204
28205 \begin_layout Standard
28206
28207 \family roman
28208 \series medium
28209 \shape up
28210 \size normal
28211 \emph off
28212 \bar no
28213 \noun off
28214 \color none
28215 HIGH priority interrupts
28216 \end_layout
28217
28218 \end_inset
28219 </cell>
28220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28221 \begin_inset Text
28222
28223 \begin_layout Standard
28224 0x000008
28225 \end_layout
28226
28227 \end_inset
28228 </cell>
28229 </row>
28230 <row topline="true" bottomline="true">
28231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28232 \begin_inset Text
28233
28234 \begin_layout Standard
28235 2
28236 \end_layout
28237
28238 \end_inset
28239 </cell>
28240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28241 \begin_inset Text
28242
28243 \begin_layout Standard
28244 LOW priority interrupts
28245 \end_layout
28246
28247 \end_inset
28248 </cell>
28249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28250 \begin_inset Text
28251
28252 \begin_layout Standard
28253 0x000018
28254 \end_layout
28255
28256 \end_inset
28257 </cell>
28258 </row>
28259 </lyxtabular>
28260
28261 \end_inset
28262
28263
28264 \end_layout
28265
28266 \begin_layout Standard
28267 When generating assembly code for ISR the code generator places a 
28268 \noun on
28269 goto 
28270 \noun default
28271 instruction at the 
28272 \emph on
28273 Interrupt Vector Address
28274 \emph default
28275  which points at the generated ISR.
28276  This single GOTO instruction is part of an automatically generated 
28277 \emph on
28278 interrupt entry point
28279 \emph default
28280  function.
28281  The actuall ISR code is placed as normally would in the code space.
28282  Upon interrupt request, the GOTO instruction is executed which jumps to
28283  the ISR code.
28284  When declaring interrupt functions as _naked this GOTO instruction is 
28285 \series bold
28286 not
28287 \series default
28288  generated.
28289  The whole interrupt functions is therefore placed at the Interrupt Vector
28290  Address of the specific interrupt.
28291  This is not a problem for the LOW priority interrupts, but it is a problem
28292  for the RESET and the HIGH priority interrupts because code may be written
28293  at the next interrupt's vector address and cause indeterminate program
28294  behaviour if that interrupt is raised.
28295 \begin_inset Foot
28296 status open
28297
28298 \begin_layout Standard
28299 This is not a problem when
28300 \end_layout
28301
28302 \begin_layout Enumerate
28303 this is a HIGH interrupt ISR and LOW interrupts are 
28304 \emph on
28305 disabled
28306 \emph default
28307  or not used.
28308 \end_layout
28309
28310 \begin_layout Enumerate
28311 when the ISR is small enough not to reach the next interrupt's vector address.
28312 \end_layout
28313
28314 \end_inset
28315
28316
28317 \end_layout
28318
28319 \begin_layout Standard
28320
28321 \emph on
28322 n
28323 \emph default
28324  may be omitted.
28325  This way a function is generated similar to an ISR, but it is not assigned
28326  to any interrupt.
28327 \end_layout
28328
28329 \begin_layout Standard
28330 When entering an interrupt, currently the PIC16
28331 \begin_inset LatexCommand index
28332 name "PIC16"
28333
28334 \end_inset
28335
28336  port automatically saves the following registers:
28337 \end_layout
28338
28339 \begin_layout Itemize
28340 WREG
28341 \end_layout
28342
28343 \begin_layout Itemize
28344 STATUS
28345 \end_layout
28346
28347 \begin_layout Itemize
28348 BSR
28349 \end_layout
28350
28351 \begin_layout Itemize
28352 PROD (PRODL and PRODH)
28353 \end_layout
28354
28355 \begin_layout Itemize
28356 FSR0 (FSR0L and FSR0H)
28357 \end_layout
28358
28359 \begin_layout Standard
28360 These registers are restored upon return from the interrupt routine.
28361 \begin_inset Foot
28362 status open
28363
28364 \begin_layout Standard
28365 NOTE that when the _naked attribute is specified for an interrupt routine,
28366  then NO registers are stored or restored.
28367 \end_layout
28368
28369 \end_inset
28370
28371
28372 \end_layout
28373
28374 \begin_layout Subsection
28375 Generic Pointers
28376 \end_layout
28377
28378 \begin_layout Standard
28379 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
28380  There are 3 types of generic pointers currently implemented data, code
28381  and eeprom pointers.
28382  They are differentiated by the value of the 7th and 6th bits of the upper
28383  byte:
28384 \end_layout
28385
28386 \begin_layout Standard
28387 \align center
28388 \begin_inset Tabular
28389 <lyxtabular version="3" rows="5" columns="5">
28390 <features>
28391 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28392 <column alignment="center" valignment="top" width="0">
28393 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28394 <column alignment="center" valignment="top" width="0">
28395 <column alignment="left" valignment="top" rightline="true" width="0">
28396 <row topline="true" bottomline="true">
28397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28398 \begin_inset Text
28399
28400 \begin_layout Standard
28401 pointer type
28402 \end_layout
28403
28404 \end_inset
28405 </cell>
28406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28407 \begin_inset Text
28408
28409 \begin_layout Standard
28410 7th bit
28411 \end_layout
28412
28413 \end_inset
28414 </cell>
28415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28416 \begin_inset Text
28417
28418 \begin_layout Standard
28419 6th bit
28420 \end_layout
28421
28422 \end_inset
28423 </cell>
28424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28425 \begin_inset Text
28426
28427 \begin_layout Standard
28428 rest of the pointer
28429 \end_layout
28430
28431 \end_inset
28432 </cell>
28433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28434 \begin_inset Text
28435
28436 \begin_layout Standard
28437 description
28438 \end_layout
28439
28440 \end_inset
28441 </cell>
28442 </row>
28443 <row topline="true" bottomline="true">
28444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28445 \begin_inset Text
28446
28447 \begin_layout Standard
28448 data 
28449 \end_layout
28450
28451 \end_inset
28452 </cell>
28453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28454 \begin_inset Text
28455
28456 \begin_layout Standard
28457 1
28458 \end_layout
28459
28460 \end_inset
28461 </cell>
28462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28463 \begin_inset Text
28464
28465 \begin_layout Standard
28466 0
28467 \end_layout
28468
28469 \end_inset
28470 </cell>
28471 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28472 \begin_inset Text
28473
28474 \begin_layout Standard
28475
28476 \family typewriter
28477 \shape slanted
28478 \emph on
28479 uuuuuu uuuuxxxx xxxxxxxx
28480 \end_layout
28481
28482 \end_inset
28483 </cell>
28484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28485 \begin_inset Text
28486
28487 \begin_layout Standard
28488 a 12-bit data pointer in data RAM memory
28489 \end_layout
28490
28491 \end_inset
28492 </cell>
28493 </row>
28494 <row bottomline="true">
28495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28496 \begin_inset Text
28497
28498 \begin_layout Standard
28499 code
28500 \end_layout
28501
28502 \end_inset
28503 </cell>
28504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28505 \begin_inset Text
28506
28507 \begin_layout Standard
28508 0
28509 \end_layout
28510
28511 \end_inset
28512 </cell>
28513 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28514 \begin_inset Text
28515
28516 \begin_layout Standard
28517 0
28518 \end_layout
28519
28520 \end_inset
28521 </cell>
28522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28523 \begin_inset Text
28524
28525 \begin_layout Standard
28526
28527 \family typewriter
28528 \shape slanted
28529 \emph on
28530 uxxxxx xxxxxxxx xxxxxxxx
28531 \end_layout
28532
28533 \end_inset
28534 </cell>
28535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28536 \begin_inset Text
28537
28538 \begin_layout Standard
28539 a 21-bit code pointer in FLASH memory
28540 \end_layout
28541
28542 \end_inset
28543 </cell>
28544 </row>
28545 <row bottomline="true">
28546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28547 \begin_inset Text
28548
28549 \begin_layout Standard
28550 eeprom
28551 \end_layout
28552
28553 \end_inset
28554 </cell>
28555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28556 \begin_inset Text
28557
28558 \begin_layout Standard
28559 0
28560 \end_layout
28561
28562 \end_inset
28563 </cell>
28564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28565 \begin_inset Text
28566
28567 \begin_layout Standard
28568 1
28569 \end_layout
28570
28571 \end_inset
28572 </cell>
28573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28574 \begin_inset Text
28575
28576 \begin_layout Standard
28577
28578 \family typewriter
28579 \shape slanted
28580 \emph on
28581 uuuuuu uuuuuuxx xxxxxxxx
28582 \end_layout
28583
28584 \end_inset
28585 </cell>
28586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28587 \begin_inset Text
28588
28589 \begin_layout Standard
28590 a 10-bit eeprom pointer in EEPROM memory
28591 \end_layout
28592
28593 \end_inset
28594 </cell>
28595 </row>
28596 <row bottomline="true">
28597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28598 \begin_inset Text
28599
28600 \begin_layout Standard
28601 (unimplemented)
28602 \end_layout
28603
28604 \end_inset
28605 </cell>
28606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28607 \begin_inset Text
28608
28609 \begin_layout Standard
28610 1
28611 \end_layout
28612
28613 \end_inset
28614 </cell>
28615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28616 \begin_inset Text
28617
28618 \begin_layout Standard
28619 1
28620 \end_layout
28621
28622 \end_inset
28623 </cell>
28624 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28625 \begin_inset Text
28626
28627 \begin_layout Standard
28628
28629 \family typewriter
28630 \shape slanted
28631 \emph on
28632 xxxxxx xxxxxxxx xxxxxxxx
28633 \end_layout
28634
28635 \end_inset
28636 </cell>
28637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28638 \begin_inset Text
28639
28640 \begin_layout Standard
28641 unimplemented pointer type
28642 \end_layout
28643
28644 \end_inset
28645 </cell>
28646 </row>
28647 </lyxtabular>
28648
28649 \end_inset
28650
28651
28652 \end_layout
28653
28654 \begin_layout Standard
28655 \noindent
28656 Generic pointer are read and written with a set of library functions which
28657  read/write 1, 2, 3, 4 bytes.
28658 \end_layout
28659
28660 \begin_layout Subsection
28661 PIC16 C Libraries
28662 \end_layout
28663
28664 \begin_layout Subsubsection
28665 Standard I/O Streams
28666 \end_layout
28667
28668 \begin_layout Standard
28669 In the 
28670 \emph on
28671 stdio.h
28672 \emph default
28673  the type FILE is defined as:
28674 \end_layout
28675
28676 \begin_layout LyX-Code
28677 typedef char * FILE;
28678 \end_layout
28679
28680 \begin_layout Standard
28681 This type is the stream type implemented I/O in the PIC18F devices.
28682  Also the standard input and output streams are declared in stdio.h:
28683 \end_layout
28684
28685 \begin_layout LyX-Code
28686 extern FILE * stdin;
28687 \end_layout
28688
28689 \begin_layout LyX-Code
28690 extern FILE * stdout;
28691 \end_layout
28692
28693 \begin_layout Standard
28694 The FILE type is actually a generic pointer which defines one more type
28695  of generic pointers, the 
28696 \emph on
28697 stream
28698 \emph default
28699  pointer.
28700  This new type has the format:
28701 \end_layout
28702
28703 \begin_layout Standard
28704 \noindent
28705 \align center
28706 \begin_inset Tabular
28707 <lyxtabular version="3" rows="2" columns="7">
28708 <features>
28709 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28710 <column alignment="center" valignment="top" width="0">
28711 <column alignment="center" valignment="top" leftline="true" width="0">
28712 <column alignment="center" valignment="top" leftline="true" width="0">
28713 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28714 <column alignment="center" valignment="top" width="0">
28715 <column alignment="left" valignment="top" rightline="true" width="0">
28716 <row topline="true" bottomline="true">
28717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28718 \begin_inset Text
28719
28720 \begin_layout Standard
28721 pointer type
28722 \end_layout
28723
28724 \end_inset
28725 </cell>
28726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28727 \begin_inset Text
28728
28729 \begin_layout Standard
28730 <7:6>
28731 \end_layout
28732
28733 \end_inset
28734 </cell>
28735 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28736 \begin_inset Text
28737
28738 \begin_layout Standard
28739 <5>
28740 \end_layout
28741
28742 \end_inset
28743 </cell>
28744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28745 \begin_inset Text
28746
28747 \begin_layout Standard
28748 <4>
28749 \end_layout
28750
28751 \end_inset
28752 </cell>
28753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28754 \begin_inset Text
28755
28756 \begin_layout Standard
28757 <3:0>
28758 \end_layout
28759
28760 \end_inset
28761 </cell>
28762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28763 \begin_inset Text
28764
28765 \begin_layout Standard
28766 rest of the pointer
28767 \end_layout
28768
28769 \end_inset
28770 </cell>
28771 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28772 \begin_inset Text
28773
28774 \begin_layout Standard
28775 descrption
28776 \end_layout
28777
28778 \end_inset
28779 </cell>
28780 </row>
28781 <row topline="true" bottomline="true">
28782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28783 \begin_inset Text
28784
28785 \begin_layout Standard
28786 stream
28787 \end_layout
28788
28789 \end_inset
28790 </cell>
28791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28792 \begin_inset Text
28793
28794 \begin_layout Standard
28795 00
28796 \end_layout
28797
28798 \end_inset
28799 </cell>
28800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28801 \begin_inset Text
28802
28803 \begin_layout Standard
28804 1
28805 \end_layout
28806
28807 \end_inset
28808 </cell>
28809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28810 \begin_inset Text
28811
28812 \begin_layout Standard
28813 0
28814 \end_layout
28815
28816 \end_inset
28817 </cell>
28818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28819 \begin_inset Text
28820
28821 \begin_layout Standard
28822 nnnn
28823 \end_layout
28824
28825 \end_inset
28826 </cell>
28827 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28828 \begin_inset Text
28829
28830 \begin_layout Standard
28831
28832 \family typewriter
28833 \shape slanted
28834 \emph on
28835 uuuuuuuu uuuuuuuu
28836 \end_layout
28837
28838 \end_inset
28839 </cell>
28840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28841 \begin_inset Text
28842
28843 \begin_layout Standard
28844 upper byte high nubble is 0x2n, the rest are zeroes
28845 \end_layout
28846
28847 \end_inset
28848 </cell>
28849 </row>
28850 </lyxtabular>
28851
28852 \end_inset
28853
28854
28855 \end_layout
28856
28857 \begin_layout Standard
28858 \noindent
28859 Currently implemented there are 3 types of streams defined:
28860 \end_layout
28861
28862 \begin_layout Standard
28863 \noindent
28864 \align center
28865 \begin_inset Tabular
28866 <lyxtabular version="3" rows="4" columns="4">
28867 <features>
28868 <column alignment="center" valignment="top" leftline="true" width="0">
28869 <column alignment="center" valignment="top" leftline="true" width="0">
28870 <column alignment="center" valignment="top" leftline="true" width="0">
28871 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28872 <row topline="true" bottomline="true">
28873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28874 \begin_inset Text
28875
28876 \begin_layout Standard
28877 stream type
28878 \end_layout
28879
28880 \end_inset
28881 </cell>
28882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28883 \begin_inset Text
28884
28885 \begin_layout Standard
28886 value
28887 \end_layout
28888
28889 \end_inset
28890 </cell>
28891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28892 \begin_inset Text
28893
28894 \begin_layout Standard
28895 module
28896 \end_layout
28897
28898 \end_inset
28899 </cell>
28900 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28901 \begin_inset Text
28902
28903 \begin_layout Standard
28904 description
28905 \end_layout
28906
28907 \end_inset
28908 </cell>
28909 </row>
28910 <row topline="true">
28911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28912 \begin_inset Text
28913
28914 \begin_layout Standard
28915 STREAM_USART
28916 \end_layout
28917
28918 \end_inset
28919 </cell>
28920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28921 \begin_inset Text
28922
28923 \begin_layout Standard
28924
28925 \family typewriter
28926 0x200000UL
28927 \end_layout
28928
28929 \end_inset
28930 </cell>
28931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28932 \begin_inset Text
28933
28934 \begin_layout Standard
28935 USART
28936 \end_layout
28937
28938 \end_inset
28939 </cell>
28940 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28941 \begin_inset Text
28942
28943 \begin_layout Standard
28944 Writes/Reads characters via the USART peripheral
28945 \end_layout
28946
28947 \end_inset
28948 </cell>
28949 </row>
28950 <row topline="true">
28951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28952 \begin_inset Text
28953
28954 \begin_layout Standard
28955 STREAM_MSSP
28956 \end_layout
28957
28958 \end_inset
28959 </cell>
28960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28961 \begin_inset Text
28962
28963 \begin_layout Standard
28964
28965 \family typewriter
28966 0x210000UL
28967 \end_layout
28968
28969 \end_inset
28970 </cell>
28971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28972 \begin_inset Text
28973
28974 \begin_layout Standard
28975 MSSP
28976 \end_layout
28977
28978 \end_inset
28979 </cell>
28980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28981 \begin_inset Text
28982
28983 \begin_layout Standard
28984 Writes/Reads characters via the MSSP peripheral
28985 \end_layout
28986
28987 \end_inset
28988 </cell>
28989 </row>
28990 <row topline="true" bottomline="true">
28991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28992 \begin_inset Text
28993
28994 \begin_layout Standard
28995 STREAM_USER
28996 \end_layout
28997
28998 \end_inset
28999 </cell>
29000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29001 \begin_inset Text
29002
29003 \begin_layout Standard
29004
29005 \family typewriter
29006 0x2f0000UL
29007 \end_layout
29008
29009 \end_inset
29010 </cell>
29011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29012 \begin_inset Text
29013
29014 \begin_layout Standard
29015 (none)
29016 \end_layout
29017
29018 \end_inset
29019 </cell>
29020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29021 \begin_inset Text
29022
29023 \begin_layout Standard
29024 Writes/Reads characters via used defined functions
29025 \end_layout
29026
29027 \end_inset
29028 </cell>
29029 </row>
29030 </lyxtabular>
29031
29032 \end_inset
29033
29034
29035 \end_layout
29036
29037 \begin_layout Standard
29038 \noindent
29039 The stream identifiers are declared as macros in the stdio.h header.
29040 \end_layout
29041
29042 \begin_layout Standard
29043 \noindent
29044 In the libc library there exist the functions that are used to write to
29045  each of the above streams.
29046  These are
29047 \end_layout
29048
29049 \begin_layout Description
29050 _
29051 \begin_inset ERT
29052 status collapsed
29053
29054 \begin_layout Standard
29055
29056
29057 \backslash
29058 /
29059 \end_layout
29060
29061 \end_inset
29062
29063 _stream_usart_putchar writes a character at the USART stream
29064 \end_layout
29065
29066 \begin_layout Description
29067 _
29068 \begin_inset ERT
29069 status collapsed
29070
29071 \begin_layout Standard
29072
29073
29074 \backslash
29075 /
29076 \end_layout
29077
29078 \end_inset
29079
29080 _stream_mssp_putchar writes a character at the MSSP stream
29081 \end_layout
29082
29083 \begin_layout Description
29084 putchar dummy function.
29085  This writes a character to a user specified manner.
29086 \end_layout
29087
29088 \begin_layout Standard
29089 In order to increase performance 
29090 \emph on
29091 putchar
29092 \emph default
29093  is declared in stdio.h as having its parameter in WREG (it has the wparam
29094  keyword).
29095  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
29096  in a user-friendly way.
29097  
29098 \emph on
29099 arg
29100 \emph default
29101  is the name of the variable that holds the character to print.
29102  An example follows:
29103 \end_layout
29104
29105 \begin_layout LyX-Code
29106 #include <pic18fregs.h>
29107 \newline
29108 #include <stdio.h>
29109 \newline
29110
29111 \newline
29112 PUTCHAR( c )
29113 \end_layout
29114
29115 \begin_layout LyX-Code
29116 {
29117 \end_layout
29118
29119 \begin_layout LyX-Code
29120     PORTA = c;    /* dump character c to PORTA */
29121 \end_layout
29122
29123 \begin_layout LyX-Code
29124
29125 \newline
29126
29127 \newline
29128 void main(void)
29129 \end_layout
29130
29131 \begin_layout LyX-Code
29132 {
29133 \end_layout
29134
29135 \begin_layout LyX-Code
29136     stdout = STREAM_USER;    /* this is not necessary, since stdout points
29137 \end_layout
29138
29139 \begin_layout LyX-Code
29140                               * by default to STREAM_USER */
29141 \end_layout
29142
29143 \begin_layout LyX-Code
29144     printf (
29145 \begin_inset Quotes sld
29146 \end_inset
29147
29148 This is a printf test
29149 \backslash
29150 n
29151 \begin_inset Quotes srd
29152 \end_inset
29153
29154 );
29155 \end_layout
29156
29157 \begin_layout LyX-Code
29158 }
29159 \end_layout
29160
29161 \begin_layout LyX-Code
29162
29163 \end_layout
29164
29165 \begin_layout Subsubsection
29166 Printing functions
29167 \end_layout
29168
29169 \begin_layout Standard
29170 PIC16 contains an implementation of the printf-family of functions.
29171  There exist the following functions:
29172 \end_layout
29173
29174 \begin_layout LyX-Code
29175 extern unsigned int sprintf(char *buf, char *fmt, ...);
29176 \end_layout
29177
29178 \begin_layout LyX-Code
29179 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
29180 \end_layout
29181
29182 \begin_layout LyX-Code
29183
29184 \end_layout
29185
29186 \begin_layout LyX-Code
29187 extern unsigned int printf(char *fmt, ...);
29188 \end_layout
29189
29190 \begin_layout LyX-Code
29191 extern unsigned int vprintf(char *fmt, va_lista ap);
29192 \end_layout
29193
29194 \begin_layout LyX-Code
29195
29196 \end_layout
29197
29198 \begin_layout LyX-Code
29199 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
29200 \end_layout
29201
29202 \begin_layout LyX-Code
29203 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
29204 \end_layout
29205
29206 \begin_layout Standard
29207 For sprintf and vsprintf 
29208 \emph on
29209 buf
29210 \emph default
29211  should normally be a data pointer where the resulting string will be placed.
29212  No range checking is done so the user should allocate the necessary buffer.
29213  For fprintf and vfprintf 
29214 \emph on
29215 fp
29216 \emph default
29217  should be a stream pointer (i.e.
29218  stdout, STREAM_MSSP, etc...).
29219 \end_layout
29220
29221 \begin_layout Subsubsection
29222 Signals
29223 \end_layout
29224
29225 \begin_layout Standard
29226 The PIC18F family of microcontrollers supports a number of interrupt sources.
29227  A list of these interrupts is shown in the following table:
29228 \end_layout
29229
29230 \begin_layout Standard
29231 \align center
29232 \begin_inset Tabular
29233 <lyxtabular version="3" rows="11" columns="4">
29234 <features>
29235 <column alignment="left" valignment="top" leftline="true" width="0">
29236 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29237 <column alignment="left" valignment="top" leftline="true" width="0">
29238 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29239 <row topline="true" bottomline="true">
29240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29241 \begin_inset Text
29242
29243 \begin_layout Standard
29244 signal name
29245 \end_layout
29246
29247 \end_inset
29248 </cell>
29249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29250 \begin_inset Text
29251
29252 \begin_layout Standard
29253 description
29254 \end_layout
29255
29256 \end_inset
29257 </cell>
29258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29259 \begin_inset Text
29260
29261 \begin_layout Standard
29262 signal name
29263 \end_layout
29264
29265 \end_inset
29266 </cell>
29267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29268 \begin_inset Text
29269
29270 \begin_layout Standard
29271 description
29272 \end_layout
29273
29274 \end_inset
29275 </cell>
29276 </row>
29277 <row topline="true">
29278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29279 \begin_inset Text
29280
29281 \begin_layout Standard
29282 SIG_RB
29283 \end_layout
29284
29285 \end_inset
29286 </cell>
29287 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29288 \begin_inset Text
29289
29290 \begin_layout Standard
29291 PORTB change interrupt
29292 \end_layout
29293
29294 \end_inset
29295 </cell>
29296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29297 \begin_inset Text
29298
29299 \begin_layout Standard
29300 SIG_EE
29301 \end_layout
29302
29303 \end_inset
29304 </cell>
29305 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29306 \begin_inset Text
29307
29308 \begin_layout Standard
29309 EEPROM/FLASH write complete interrupt
29310 \end_layout
29311
29312 \end_inset
29313 </cell>
29314 </row>
29315 <row topline="true">
29316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29317 \begin_inset Text
29318
29319 \begin_layout Standard
29320 SIG_INT0
29321 \end_layout
29322
29323 \end_inset
29324 </cell>
29325 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29326 \begin_inset Text
29327
29328 \begin_layout Standard
29329 INT0 external interrupt
29330 \end_layout
29331
29332 \end_inset
29333 </cell>
29334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29335 \begin_inset Text
29336
29337 \begin_layout Standard
29338 SIG_BCOL
29339 \end_layout
29340
29341 \end_inset
29342 </cell>
29343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29344 \begin_inset Text
29345
29346 \begin_layout Standard
29347 Bus collision interrupt
29348 \end_layout
29349
29350 \end_inset
29351 </cell>
29352 </row>
29353 <row topline="true">
29354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29355 \begin_inset Text
29356
29357 \begin_layout Standard
29358 SIG_INT1
29359 \end_layout
29360
29361 \end_inset
29362 </cell>
29363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29364 \begin_inset Text
29365
29366 \begin_layout Standard
29367 INT1 external interrupt
29368 \end_layout
29369
29370 \end_inset
29371 </cell>
29372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29373 \begin_inset Text
29374
29375 \begin_layout Standard
29376 SIG_LVD
29377 \end_layout
29378
29379 \end_inset
29380 </cell>
29381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29382 \begin_inset Text
29383
29384 \begin_layout Standard
29385 Low voltage detect interrupt
29386 \end_layout
29387
29388 \end_inset
29389 </cell>
29390 </row>
29391 <row topline="true">
29392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29393 \begin_inset Text
29394
29395 \begin_layout Standard
29396 SIG_INT2
29397 \end_layout
29398
29399 \end_inset
29400 </cell>
29401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29402 \begin_inset Text
29403
29404 \begin_layout Standard
29405 INT2 external interrupt
29406 \end_layout
29407
29408 \end_inset
29409 </cell>
29410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29411 \begin_inset Text
29412
29413 \begin_layout Standard
29414 SIG_PSP
29415 \end_layout
29416
29417 \end_inset
29418 </cell>
29419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29420 \begin_inset Text
29421
29422 \begin_layout Standard
29423 Parallel slave port interrupt
29424 \end_layout
29425
29426 \end_inset
29427 </cell>
29428 </row>
29429 <row topline="true">
29430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29431 \begin_inset Text
29432
29433 \begin_layout Standard
29434 SIG_CCP1
29435 \end_layout
29436
29437 \end_inset
29438 </cell>
29439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29440 \begin_inset Text
29441
29442 \begin_layout Standard
29443 CCP1 module interrupt
29444 \end_layout
29445
29446 \end_inset
29447 </cell>
29448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29449 \begin_inset Text
29450
29451 \begin_layout Standard
29452 SIG_AD
29453 \end_layout
29454
29455 \end_inset
29456 </cell>
29457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29458 \begin_inset Text
29459
29460 \begin_layout Standard
29461 AD convertion complete interrupt
29462 \end_layout
29463
29464 \end_inset
29465 </cell>
29466 </row>
29467 <row topline="true">
29468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29469 \begin_inset Text
29470
29471 \begin_layout Standard
29472 SIG_CCP2
29473 \end_layout
29474
29475 \end_inset
29476 </cell>
29477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29478 \begin_inset Text
29479
29480 \begin_layout Standard
29481 CCP2 module interrupt
29482 \end_layout
29483
29484 \end_inset
29485 </cell>
29486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29487 \begin_inset Text
29488
29489 \begin_layout Standard
29490 SIG_RC
29491 \end_layout
29492
29493 \end_inset
29494 </cell>
29495 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29496 \begin_inset Text
29497
29498 \begin_layout Standard
29499 USART receive interrupt
29500 \end_layout
29501
29502 \end_inset
29503 </cell>
29504 </row>
29505 <row topline="true">
29506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29507 \begin_inset Text
29508
29509 \begin_layout Standard
29510 SIG_TMR0
29511 \end_layout
29512
29513 \end_inset
29514 </cell>
29515 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29516 \begin_inset Text
29517
29518 \begin_layout Standard
29519 TMR0 overflow interrupt
29520 \end_layout
29521
29522 \end_inset
29523 </cell>
29524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29525 \begin_inset Text
29526
29527 \begin_layout Standard
29528 SIG_TX
29529 \end_layout
29530
29531 \end_inset
29532 </cell>
29533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29534 \begin_inset Text
29535
29536 \begin_layout Standard
29537 USART transmit interrupt
29538 \end_layout
29539
29540 \end_inset
29541 </cell>
29542 </row>
29543 <row topline="true">
29544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29545 \begin_inset Text
29546
29547 \begin_layout Standard
29548 SIG_TMR1
29549 \end_layout
29550
29551 \end_inset
29552 </cell>
29553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29554 \begin_inset Text
29555
29556 \begin_layout Standard
29557 TMR1 overflow interrupt
29558 \end_layout
29559
29560 \end_inset
29561 </cell>
29562 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29563 \begin_inset Text
29564
29565 \begin_layout Standard
29566 SIG_MSSP
29567 \end_layout
29568
29569 \end_inset
29570 </cell>
29571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29572 \begin_inset Text
29573
29574 \begin_layout Standard
29575 SSP receive/transmit interrupt
29576 \end_layout
29577
29578 \end_inset
29579 </cell>
29580 </row>
29581 <row topline="true">
29582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29583 \begin_inset Text
29584
29585 \begin_layout Standard
29586 SIG_TMR2
29587 \end_layout
29588
29589 \end_inset
29590 </cell>
29591 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29592 \begin_inset Text
29593
29594 \begin_layout Standard
29595 TMR2 matches PR2 interrupt
29596 \end_layout
29597
29598 \end_inset
29599 </cell>
29600 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29601 \begin_inset Text
29602
29603 \begin_layout Standard
29604
29605 \end_layout
29606
29607 \end_inset
29608 </cell>
29609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29610 \begin_inset Text
29611
29612 \begin_layout Standard
29613
29614 \end_layout
29615
29616 \end_inset
29617 </cell>
29618 </row>
29619 <row topline="true" bottomline="true">
29620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29621 \begin_inset Text
29622
29623 \begin_layout Standard
29624 SIG_TMR3
29625 \end_layout
29626
29627 \end_inset
29628 </cell>
29629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29630 \begin_inset Text
29631
29632 \begin_layout Standard
29633 TMR3 overflow interrupt
29634 \end_layout
29635
29636 \end_inset
29637 </cell>
29638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29639 \begin_inset Text
29640
29641 \begin_layout Standard
29642
29643 \end_layout
29644
29645 \end_inset
29646 </cell>
29647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29648 \begin_inset Text
29649
29650 \begin_layout Standard
29651
29652 \end_layout
29653
29654 \end_inset
29655 </cell>
29656 </row>
29657 </lyxtabular>
29658
29659 \end_inset
29660
29661
29662 \end_layout
29663
29664 \begin_layout Standard
29665 \noindent
29666 The prototypes for these names are defined in the header file 
29667 \emph on
29668 signal.h
29669 \emph default
29670  .
29671 \end_layout
29672
29673 \begin_layout Standard
29674 \noindent
29675 In order to simplify signal handling, a number of macros is provided:
29676 \end_layout
29677
29678 \begin_layout List
29679 \labelwidthstring 00.00.0000
29680 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
29681  high priority interrupts.
29682  
29683 \emph on
29684 name
29685 \emph default
29686  is the function name to use.
29687 \end_layout
29688
29689 \begin_layout List
29690 \labelwidthstring 00.00.0000
29691 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
29692  low priority interrupt.
29693  
29694 \emph on
29695 name
29696 \emph default
29697  is the function name to use.
29698 \end_layout
29699
29700 \begin_layout List
29701 \labelwidthstring 00.00.0000
29702 DEF_HANDLER(sig,handler) define a handler for signal 
29703 \emph on
29704 sig.
29705 \end_layout
29706
29707 \begin_layout List
29708 \labelwidthstring 00.00.0000
29709 END_DEF end the declaration of the dispatch table.
29710 \end_layout
29711
29712 \begin_layout Standard
29713 Additionally there are two more macros to simplify the declaration of the
29714  signal handler:
29715 \end_layout
29716
29717 \begin_layout List
29718 \labelwidthstring 00.00.0000
29719
29720 \series medium
29721 SIGHANDLER(handler)
29722 \series default
29723  this declares the function prototype for the 
29724 \emph on
29725 handler
29726 \emph default
29727  function.
29728 \end_layout
29729
29730 \begin_layout List
29731 \labelwidthstring 00.00.0000
29732 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
29733 \end_layout
29734
29735 \begin_layout Standard
29736 An example of using the macros above is shown below:
29737 \end_layout
29738
29739 \begin_layout LyX-Code
29740 #include <pic18fregs.h>
29741 \end_layout
29742
29743 \begin_layout LyX-Code
29744 #include <signal.h>
29745 \newline
29746
29747 \newline
29748 DEF_INTHIGH(high_int)
29749 \end_layout
29750
29751 \begin_layout LyX-Code
29752 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
29753 \end_layout
29754
29755 \begin_layout LyX-Code
29756 DEF_HANDLER(SIG_BCOL, _bcol_handler)
29757 \end_layout
29758
29759 \begin_layout LyX-Code
29760 END_DEF
29761 \newline
29762
29763 \newline
29764 SIGHANDLER(_tmr0_handler)
29765 \end_layout
29766
29767 \begin_layout LyX-Code
29768 {
29769 \end_layout
29770
29771 \begin_layout LyX-Code
29772   /* action to be taken when timer 0 overflows */
29773 \end_layout
29774
29775 \begin_layout LyX-Code
29776 }
29777 \newline
29778
29779 \newline
29780 SIGHANDLERNAKED(_bcol_handler)
29781 \end_layout
29782
29783 \begin_layout LyX-Code
29784 {
29785 \end_layout
29786
29787 \begin_layout LyX-Code
29788   _asm
29789 \end_layout
29790
29791 \begin_layout LyX-Code
29792     /* action to be taken when bus collision occurs */
29793 \end_layout
29794
29795 \begin_layout LyX-Code
29796     retfie
29797 \end_layout
29798
29799 \begin_layout LyX-Code
29800  _endasm;
29801 \end_layout
29802
29803 \begin_layout LyX-Code
29804 }
29805 \end_layout
29806
29807 \begin_layout Standard
29808
29809 \series bold
29810 NOTES:
29811 \series default
29812  Special care should be taken when using the above scheme:
29813 \end_layout
29814
29815 \begin_layout Itemize
29816 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
29817 \end_layout
29818
29819 \begin_layout Itemize
29820 when declaring SIGHANDLERNAKED handler never forget to use 
29821 \emph on
29822 retfie
29823 \emph default
29824  for proper returning.
29825 \end_layout
29826
29827 \begin_layout Subsection
29828 PIC16 Port -- Tips
29829 \end_layout
29830
29831 \begin_layout Standard
29832 Here you can find some general tips for compiling programs with SDCC/pic16.
29833 \end_layout
29834
29835 \begin_layout Subsubsection
29836 Stack size
29837 \end_layout
29838
29839 \begin_layout Standard
29840 The default stack
29841 \begin_inset LatexCommand index
29842 name "PIC16!stack"
29843
29844 \end_inset
29845
29846  size (that is 64 bytes) probably is enough for many programs.
29847  One must take care that when there are many levels of function nesting,
29848  or there is excessive usage of stack, its size should be extended.
29849  An example of such a case is the printf/sprintf family of functions.
29850  If you encounter problems like not being able to print integers, then you
29851  need to set the stack size around the maximum (256 for small stack model).
29852  The following diagram shows what happens when calling printf to print an
29853  integer:
29854 \end_layout
29855
29856 \begin_layout LyX-Code
29857 printf () --> ltoa () --> ultoa () --> divschar ()
29858 \end_layout
29859
29860 \begin_layout Standard
29861 It is should be understood that stack is easily consumed when calling complicate
29862 d functions.
29863  Using command line arguments like -
29864 \begin_inset ERT
29865 status collapsed
29866
29867 \begin_layout Standard
29868
29869
29870 \backslash
29871 /
29872 \end_layout
29873
29874 \end_inset
29875
29876 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
29877  stack frames.
29878  Other ways to reduce stack usage may exist.
29879 \end_layout
29880
29881 \begin_layout Subsection
29882 Known Bugs
29883 \end_layout
29884
29885 \begin_layout Subsubsection
29886 Extended Instruction Set
29887 \end_layout
29888
29889 \begin_layout Standard
29890 The PIC16 port emits code which is incompatible with the extended instruction
29891  set available with many newer devices.
29892  Make sure to always explicitly disable it, usually using
29893 \end_layout
29894
29895 \begin_layout Standard
29896
29897 \family typewriter
29898 static __code char __at(__CONFIG4L) conf4l = /* more flags & */ _XINST_OFF_4L;
29899 \end_layout
29900
29901 \begin_layout Standard
29902 \noindent
29903 Some devices (namely 18f2455, 18f2550, 18f4455, and 18f4550) use _ENHCPU_OFF_4L
29904  instead of _XINST_OFF_4L.
29905 \end_layout
29906
29907 \begin_layout Subsubsection
29908 Regression Tests
29909 \end_layout
29910
29911 \begin_layout Standard
29912 The PIC16 port currently passes most but not all of the tests in SDCC's
29913  regression test
29914 \begin_inset LatexCommand index
29915 name "Regression test (PIC16)"
29916
29917 \end_inset
29918
29919  suite (see section 
29920 \begin_inset LatexCommand ref
29921 reference "sec:Quality-control"
29922
29923 \end_inset
29924
29925 ), thus no automatic regression tests are currently performed for the PIC16
29926  target.
29927 \end_layout
29928
29929 \begin_layout Chapter
29930 Debugging
29931 \end_layout
29932
29933 \begin_layout Standard
29934 There are several approaches to debugging your code.
29935  This chapter is meant to show your options and to give detail on some of
29936  them:
29937 \newline
29938
29939 \newline
29940 When writing your code:
29941 \end_layout
29942
29943 \begin_layout Itemize
29944 write your code with debugging in mind (avoid duplicating code, put conceptually
29945  similar variables into structs, use structured code, have strategic points
29946  within your code where all variables are consistent, ...)
29947 \end_layout
29948
29949 \begin_layout Itemize
29950 run a syntax-checking tool like splint
29951 \begin_inset LatexCommand index
29952 name "splint (syntax checking tool)"
29953
29954 \end_inset
29955
29956
29957 \begin_inset LatexCommand index
29958 name "lint (syntax checking tool)"
29959
29960 \end_inset
29961
29962  (see -
29963 \begin_inset ERT
29964 status collapsed
29965
29966 \begin_layout Standard
29967
29968
29969 \backslash
29970 /
29971 \end_layout
29972
29973 \end_inset
29974
29975 -more-pedantic 
29976 \begin_inset LatexCommand ref
29977 reference "lyx:more-pedantic-SPLINT"
29978
29979 \end_inset
29980
29981 ) over the code.
29982 \end_layout
29983
29984 \begin_layout Itemize
29985 for the high level code use a C-compiler (like f.e.
29986  GCC) to compile run and debug the code on your host.
29987  See (see -
29988 \begin_inset ERT
29989 status collapsed
29990
29991 \begin_layout Standard
29992
29993
29994 \backslash
29995 /
29996 \end_layout
29997
29998 \end_inset
29999
30000 -more-pedantic 
30001 \begin_inset LatexCommand ref
30002 reference "lyx:more-pedantic-SPLINT"
30003
30004 \end_inset
30005
30006 ) on how to handle syntax extensions like __xdata, __at(), ...
30007  
30008 \end_layout
30009
30010 \begin_layout Itemize
30011 use another C-compiler to compile code for your target.
30012  Always an option but not recommended:) And not very likely to help you.
30013  If you seriously consider walking this path you should at least occasionally
30014  check portability of your code.
30015  Most commercial compiler vendors will offer an evaluation version so you
30016  can test compile your code or snippets of your code.
30017 \end_layout
30018
30019 \begin_layout Standard
30020 Debugging on a simulator:
30021 \end_layout
30022
30023 \begin_layout Itemize
30024 there is a separate section about SDCDB (section 
30025 \begin_inset LatexCommand ref
30026 reference "cha:Debugging-with-SDCDB"
30027
30028 \end_inset
30029
30030 ) below.
30031 \end_layout
30032
30033 \begin_layout Itemize
30034 or (8051 specific) use a freeware/commercial simulator which interfaces
30035  to the AOMF
30036 \begin_inset LatexCommand index
30037 name "AOMF, AOMF51"
30038
30039 \end_inset
30040
30041  file (see 
30042 \begin_inset LatexCommand ref
30043 reference "OMF file"
30044
30045 \end_inset
30046
30047 ) optionally generated by SDCC.
30048 \end_layout
30049
30050 \begin_layout Standard
30051 Debugging On-target: 
30052 \end_layout
30053
30054 \begin_layout Itemize
30055 use a MCU port pin to serially output debug data to the RS232 port of your
30056  host.
30057  You'll probably want some level shifting device typically involving a MAX232
30058  or similar IC.
30059  If the hardware serial port of the MCU is not available search for 'Software
30060  UART' in your favourite search machine.
30061 \end_layout
30062
30063 \begin_layout Itemize
30064 use an on-target monitor.
30065  In this context a monitor is a small program which usually accepts commands
30066  via a serial line and allows to set program counter, to single step through
30067  a program and read/write memory locations.
30068  For the 8051 good examples of monitors are paulmon and cmon51 (see section
30069  
30070 \begin_inset LatexCommand ref
30071 reference "sec:Related-open-source-tools"
30072
30073 \end_inset
30074
30075 ).
30076 \end_layout
30077
30078 \begin_layout Itemize
30079 toggle MCU port pins at strategic points within your code and use an oscilloscop
30080 e.
30081  A 
30082 \emph on
30083 digital oscilloscope
30084 \emph default
30085
30086 \begin_inset LatexCommand index
30087 name "Oscilloscope"
30088
30089 \end_inset
30090
30091  with deep trace memory is really helpful especially if you have to debug
30092  a realtime application.
30093  If you need to monitor more pins than your oscilloscope provides you can
30094  sometimes get away with a small R-2R network.
30095  On a single channel oscilloscope you could f.e.
30096  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
30097 k
30098 \begin_inset Formula $\Omega$
30099 \end_inset
30100
30101  resistor and the other one by a 5\InsetSpace ~
30102 k
30103 \begin_inset Formula $\Omega$
30104 \end_inset
30105
30106  resistor to the oscilloscope probe (check output drive capability of the
30107  pins you want to monitor).
30108  If you need to monitor many more pins a 
30109 \emph on
30110 logic analyzer
30111 \emph default
30112  will be handy.
30113 \end_layout
30114
30115 \begin_layout Itemize
30116 use an ICE (
30117 \emph on
30118 i
30119 \emph default
30120
30121 \emph on
30122 c
30123 \emph default
30124 ircuit 
30125 \emph on
30126 e
30127 \emph default
30128 mulator
30129 \begin_inset LatexCommand index
30130 name "ICE (in circuit emulator)"
30131
30132 \end_inset
30133
30134 ).
30135  Usually very expensive.
30136  And very nice to have too.
30137  And usually locks you (for years...) to the devices the ICE can emulate.
30138  
30139 \end_layout
30140
30141 \begin_layout Itemize
30142 use a remote debugger.
30143  In most 8-bit systems the symbol information is not available on the target,
30144  and a complete debugger is too bulky for the target system.
30145  Therefore usually a debugger on the host system connects to an on-target
30146  debugging stub which accepts only primitive commands.
30147  
30148 \newline
30149 Terms to enter into your favourite search engine could be 'remote debugging',
30150  'gdb stub' or 'inferior debugger'.
30151  (is there one?)
30152 \end_layout
30153
30154 \begin_layout Itemize
30155 use an on target hardware debugger.
30156  Some of the more modern MCUs include hardware support for setting break
30157  points and monitoring/changing variables by using dedicated hardware pins.
30158  This facility doesn't require additional code to run on the target and
30159  
30160 \emph on
30161 usually
30162 \emph default
30163  doesn't affect runtime behaviour until a breakpoint is hit.
30164  For the mcs51 most hardware debuggers use the AOMF
30165 \begin_inset LatexCommand index
30166 name "AOMF, AOMF51"
30167
30168 \end_inset
30169
30170  file (see 
30171 \begin_inset LatexCommand ref
30172 reference "OMF file"
30173
30174 \end_inset
30175
30176 ) as input file.
30177  
30178 \end_layout
30179
30180 \begin_layout Standard
30181 Last not least:
30182 \end_layout
30183
30184 \begin_layout Itemize
30185 if you are not familiar with any of the following terms you're likely to
30186  run into problems rather sooner than later: 
30187 \emph on
30188 volatile
30189 \emph default
30190
30191 \emph on
30192 atomic
30193 \emph default
30194
30195 \emph on
30196 memory map
30197 \emph default
30198
30199 \emph on
30200 overlay
30201 \emph default
30202 .
30203  As an embedded programmer you 
30204 \emph on
30205 have
30206 \emph default
30207  to know them so why not look them up 
30208 \emph on
30209 before
30210 \emph default
30211  you have problems?)
30212 \end_layout
30213
30214 \begin_layout Itemize
30215 tell someone else about your problem (actually this is a surprisingly effective
30216  means to hunt down the bug even if the listener is not familiar with your
30217  environment).
30218  As 'failure to communicate' is probably one of the job-induced deformations
30219  of an embedded programmer this is highly encouraged.
30220 \end_layout
30221
30222 \begin_layout Section
30223 Debugging with SDCDB
30224 \begin_inset LatexCommand label
30225 name "cha:Debugging-with-SDCDB"
30226
30227 \end_inset
30228
30229
30230 \begin_inset LatexCommand index
30231 name "SDCDB (debugger)"
30232
30233 \end_inset
30234
30235  
30236 \end_layout
30237
30238 \begin_layout Standard
30239 SDCC is distributed with a source level debugger
30240 \begin_inset LatexCommand index
30241 name "Debugger"
30242
30243 \end_inset
30244
30245 .
30246  The debugger uses a command line interface, the command repertoire of the
30247  debugger has been kept as close to gdb
30248 \begin_inset LatexCommand index
30249 name "gdb"
30250
30251 \end_inset
30252
30253  (the GNU debugger) as possible.
30254  The configuration and build process is part of the standard compiler installati
30255 on, which also builds and installs the debugger in the target directory
30256  specified during configuration.
30257  The debugger allows you debug BOTH at the C source and at the ASM source
30258  level.
30259 \end_layout
30260
30261 \begin_layout Subsection
30262 Compiling for Debugging
30263 \end_layout
30264
30265 \begin_layout Standard
30266 The -
30267 \begin_inset ERT
30268 status collapsed
30269
30270 \begin_layout Standard
30271
30272
30273 \backslash
30274 /
30275 \end_layout
30276
30277 \end_inset
30278
30279 -debug
30280 \begin_inset LatexCommand index
30281 name "-\\/-debug"
30282
30283 \end_inset
30284
30285  option must be specified for all files for which debug information is to
30286  be generated.
30287  The compiler generates a .adb file for each of these files.
30288  The linker creates the .cdb
30289 \begin_inset LatexCommand index
30290 name "<file>.cdb"
30291
30292 \end_inset
30293
30294  file from the .adb
30295 \begin_inset LatexCommand index
30296 name "<file>.adb"
30297
30298 \end_inset
30299
30300  files and the address information.
30301  This .cdb is used by the debugger.
30302 \end_layout
30303
30304 \begin_layout Subsection
30305 How the Debugger Works
30306 \end_layout
30307
30308 \begin_layout Standard
30309 When the -
30310 \begin_inset ERT
30311 status collapsed
30312
30313 \begin_layout Standard
30314
30315
30316 \backslash
30317 /
30318 \end_layout
30319
30320 \end_inset
30321
30322 -debug option is specified the compiler generates extra symbol information
30323  some of which are put into the assembler source and some are put into the
30324  .adb file.
30325  Then the linker creates the .cdb file from the individual .adb files with
30326  the address information for the symbols.
30327  The debugger reads the symbolic information generated by the compiler &
30328  the address information generated by the linker.
30329  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
30330  execution is controlled by the debugger.
30331  When a command is issued for the debugger, it translates it into appropriate
30332  commands for the simulator.
30333  (Currently SDCDM only connects to the simulator but 
30334 \emph on
30335 newcdb
30336 \emph default
30337  at 
30338 \begin_inset LatexCommand url
30339 target "http://ec2drv.sf.net/"
30340
30341 \end_inset
30342
30343  is an effort to connect directly to the hardware.) 
30344 \end_layout
30345
30346 \begin_layout Subsection
30347 Starting the Debugger SDCDB
30348 \end_layout
30349
30350 \begin_layout Standard
30351 The debugger can be started using the following command line.
30352  (Assume the file you are debugging has the file name foo).
30353 \newline
30354
30355 \newline
30356
30357 \family sans
30358 \series bold
30359 sdcdb foo
30360 \newline
30361
30362 \family default
30363 \series default
30364
30365 \newline
30366 The debugger will look for the following files.
30367 \end_layout
30368
30369 \begin_layout Itemize
30370 foo.c - the source file.
30371 \end_layout
30372
30373 \begin_layout Itemize
30374 foo.cdb - the debugger symbol information file.
30375 \end_layout
30376
30377 \begin_layout Itemize
30378 foo.ihx - the Intel hex format
30379 \begin_inset LatexCommand index
30380 name "Intel hex format"
30381
30382 \end_inset
30383
30384  object file.
30385 \end_layout
30386
30387 \begin_layout Subsection
30388 SDCDB Command Line Options
30389 \end_layout
30390
30391 \begin_layout Itemize
30392 -
30393 \begin_inset ERT
30394 status collapsed
30395
30396 \begin_layout Standard
30397
30398
30399 \backslash
30400 /
30401 \end_layout
30402
30403 \end_inset
30404
30405 -directory=<source file directory> this option can used to specify the directory
30406  search list.
30407  The debugger will look into the directory list specified for source, cdb
30408  & ihx files.
30409  The items in the directory list must be separated by ':', e.g.
30410  if the source files can be in the directories /home/src1 and /home/src2,
30411  the -
30412 \begin_inset ERT
30413 status collapsed
30414
30415 \begin_layout Standard
30416
30417
30418 \backslash
30419 /
30420 \end_layout
30421
30422 \end_inset
30423
30424 -directory option should be -
30425 \begin_inset ERT
30426 status collapsed
30427
30428 \begin_layout Standard
30429
30430
30431 \backslash
30432 /
30433 \end_layout
30434
30435 \end_inset
30436
30437 -directory=/home/src1:/home/src2.
30438  Note there can be no spaces in the option.
30439  
30440 \end_layout
30441
30442 \begin_layout Itemize
30443 -cd <directory> - change to the <directory>.
30444 \end_layout
30445
30446 \begin_layout Itemize
30447 -fullname - used by GUI front ends.
30448 \end_layout
30449
30450 \begin_layout Itemize
30451 -cpu <cpu-type> - this argument is passed to the simulator please see the
30452  simulator docs for details.
30453 \end_layout
30454
30455 \begin_layout Itemize
30456 -X <Clock frequency > this options is passed to the simulator please see
30457  the simulator docs for details.
30458 \end_layout
30459
30460 \begin_layout Itemize
30461 -s <serial port file> passed to simulator see the simulator docs for details.
30462 \end_layout
30463
30464 \begin_layout Itemize
30465 -S <serial in,out> passed to simulator see the simulator docs for details.
30466 \end_layout
30467
30468 \begin_layout Itemize
30469 -k <port number> passed to simulator see the simulator docs for details.
30470 \end_layout
30471
30472 \begin_layout Subsection
30473 SDCDB Debugger Commands
30474 \end_layout
30475
30476 \begin_layout Standard
30477 As mentioned earlier the command interface for the debugger has been deliberatel
30478 y kept as close the GNU debugger gdb, as possible.
30479  This will help the integration with existing graphical user interfaces
30480  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
30481  If you use a graphical user interface for the debugger you can skip this
30482  section.
30483 \end_layout
30484
30485 \begin_layout Subsubsection*
30486 break [line | file:line | function | file:function]
30487 \end_layout
30488
30489 \begin_layout Standard
30490 Set breakpoint at specified line or function:
30491 \newline
30492
30493 \newline
30494
30495 \family sans
30496 \series bold
30497 sdcdb>break 100 
30498 \newline
30499 sdcdb>break foo.c:100
30500 \newline
30501 sdcdb>break funcfoo
30502 \newline
30503 sdcdb>break foo.c:funcfoo
30504 \end_layout
30505
30506 \begin_layout Subsubsection*
30507 clear [line | file:line | function | file:function ]
30508 \end_layout
30509
30510 \begin_layout Standard
30511 Clear breakpoint at specified line or function:
30512 \newline
30513
30514 \newline
30515
30516 \family sans
30517 \series bold
30518 sdcdb>clear 100
30519 \newline
30520 sdcdb>clear foo.c:100
30521 \newline
30522 sdcdb>clear funcfoo
30523 \newline
30524 sdcdb>clear foo.c:funcfoo
30525 \end_layout
30526
30527 \begin_layout Subsubsection*
30528 continue
30529 \end_layout
30530
30531 \begin_layout Standard
30532 Continue program being debugged, after breakpoint.
30533 \end_layout
30534
30535 \begin_layout Subsubsection*
30536 finish
30537 \end_layout
30538
30539 \begin_layout Standard
30540 Execute till the end of the current function.
30541 \end_layout
30542
30543 \begin_layout Subsubsection*
30544 delete [n]
30545 \end_layout
30546
30547 \begin_layout Standard
30548 Delete breakpoint number 'n'.
30549  If used without any option clear ALL user defined break points.
30550 \end_layout
30551
30552 \begin_layout Subsubsection*
30553 info [break | stack | frame | registers ]
30554 \end_layout
30555
30556 \begin_layout Itemize
30557 info break - list all breakpoints
30558 \end_layout
30559
30560 \begin_layout Itemize
30561 info stack - show the function call stack.
30562 \end_layout
30563
30564 \begin_layout Itemize
30565 info frame - show information about the current execution frame.
30566 \end_layout
30567
30568 \begin_layout Itemize
30569 info registers - show content of all registers.
30570 \end_layout
30571
30572 \begin_layout Subsubsection*
30573 step
30574 \end_layout
30575
30576 \begin_layout Standard
30577 Step program until it reaches a different source line.
30578  Note: pressing <return> repeats the last command.
30579 \end_layout
30580
30581 \begin_layout Subsubsection*
30582 next
30583 \end_layout
30584
30585 \begin_layout Standard
30586 Step program, proceeding through subroutine calls.
30587 \end_layout
30588
30589 \begin_layout Subsubsection*
30590 run
30591 \end_layout
30592
30593 \begin_layout Standard
30594 Start debugged program.
30595 \end_layout
30596
30597 \begin_layout Subsubsection*
30598 ptype variable 
30599 \end_layout
30600
30601 \begin_layout Standard
30602 Print type information of the variable.
30603 \end_layout
30604
30605 \begin_layout Subsubsection*
30606 print variable
30607 \end_layout
30608
30609 \begin_layout Standard
30610 print value of variable.
30611 \end_layout
30612
30613 \begin_layout Subsubsection*
30614 file filename
30615 \end_layout
30616
30617 \begin_layout Standard
30618 load the given file name.
30619  Note this is an alternate method of loading file for debugging.
30620 \end_layout
30621
30622 \begin_layout Subsubsection*
30623 frame
30624 \end_layout
30625
30626 \begin_layout Standard
30627 print information about current frame.
30628 \end_layout
30629
30630 \begin_layout Subsubsection*
30631 set srcmode
30632 \end_layout
30633
30634 \begin_layout Standard
30635 Toggle between C source & assembly source.
30636 \end_layout
30637
30638 \begin_layout Subsubsection*
30639 ! simulator command
30640 \end_layout
30641
30642 \begin_layout Standard
30643 Send the string following '!' to the simulator, the simulator response is
30644  displayed.
30645  Note the debugger does not interpret the command being sent to the simulator,
30646  so if a command like 'go' is sent the debugger can loose its execution
30647  context and may display incorrect values.
30648 \end_layout
30649
30650 \begin_layout Subsubsection*
30651 quit
30652 \end_layout
30653
30654 \begin_layout Standard
30655 "Watch me now.
30656  Iam going Down.
30657  My name is Bobby Brown"
30658 \end_layout
30659
30660 \begin_layout Subsection
30661 Interfacing SDCDB with DDD
30662 \end_layout
30663
30664 \begin_layout Standard
30665 \begin_inset Note Note
30666 status collapsed
30667
30668 \begin_layout Standard
30669 The screenshot was converted from png to eps with: 
30670 \begin_inset Quotes sld
30671 \end_inset
30672
30673 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
30674 \begin_inset Quotes srd
30675 \end_inset
30676
30677  which produces a pretty compact eps file which is free from compression
30678  artifacts.
30679 \end_layout
30680
30681 \begin_layout Standard
30682 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
30683  as this broke the build system on Sourceforge (pdf-file was broken.
30684  pdflatex does not accept eps files).
30685 \end_layout
30686
30687 \end_inset
30688
30689
30690 \end_layout
30691
30692 \begin_layout Standard
30693 The 
30694 \emph on
30695 p
30696 \emph default
30697 ortable 
30698 \emph on
30699 n
30700 \emph default
30701 etwork 
30702 \emph on
30703 g
30704 \emph default
30705 raphics File 
30706 \size footnotesize
30707
30708 \begin_inset LatexCommand url
30709 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png"
30710
30711 \end_inset
30712
30713
30714 \size default
30715  shows a screenshot of a debugging session with DDD
30716 \begin_inset LatexCommand index
30717 name "DDD (debugger)"
30718
30719 \end_inset
30720
30721  (Unix only) on a simulated 8032.
30722  The debugging session might not run as smoothly as the screenshot suggests.
30723  The debugger allows setting of breakpoints, displaying and changing variables,
30724  single stepping through C and assembler code.
30725  
30726 \newline
30727 The source was compiled with 
30728 \family sans
30729 \series bold
30730
30731 \newline
30732
30733 \newline
30734 sdcc -
30735 \family default
30736 \series default
30737
30738 \begin_inset ERT
30739 status collapsed
30740
30741 \begin_layout Standard
30742
30743
30744 \backslash
30745 /
30746 \end_layout
30747
30748 \end_inset
30749
30750
30751 \family sans
30752 \series bold
30753 -debug ddd_example.c
30754 \family default
30755 \series default
30756  
30757 \family sans
30758 \series bold
30759
30760 \newline
30761
30762 \family default
30763 \series default
30764
30765 \newline
30766 and DDD was invoked with 
30767 \family sans
30768 \series bold
30769
30770 \newline
30771
30772 \newline
30773 ddd -debugger "sdcdb -cpu 8032 ddd_example"
30774 \end_layout
30775
30776 \begin_layout Standard
30777 \begin_inset Note Note
30778 status open
30779
30780 \begin_layout Standard
30781 Check that the double quotes or an apostrophe within the command line survive
30782  the LyX tool chain.
30783  Previously the apostrophes got slanted in the PDF output so a cut and paste
30784  did not work.
30785 \end_layout
30786
30787 \end_inset
30788
30789
30790 \end_layout
30791
30792 \begin_layout Subsection
30793 Interfacing SDCDB with XEmacs
30794 \begin_inset LatexCommand index
30795 name "XEmacs"
30796
30797 \end_inset
30798
30799
30800 \begin_inset LatexCommand index
30801 name "Emacs"
30802
30803 \end_inset
30804
30805
30806 \end_layout
30807
30808 \begin_layout Standard
30809 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
30810  sdcdb.el and sdcdbsrc.el.
30811  These two files can be found in the $(prefix)/bin directory after the installat
30812 ion is complete.
30813  These files need to be loaded into XEmacs for the interface to work.
30814  This can be done at XEmacs startup time by inserting the following into
30815  your '.xemacs' file (which can be found in your HOME directory): 
30816 \newline
30817
30818 \newline
30819
30820 \family typewriter
30821 (load-file sdcdbsrc.el)
30822 \family default
30823  
30824 \newline
30825
30826 \newline
30827 .xemacs is a lisp file so the () around the command is REQUIRED.
30828  The files can also be loaded dynamically while XEmacs is running, set the
30829  environment variable 'EMACSLOADPATH' to the installation bin directory
30830  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
30831  To start the interface enter the following command: 
30832 \newline
30833
30834 \newline
30835
30836 \family sans
30837 \series bold
30838 ESC-x sdcdbsrc
30839 \family default
30840 \series default
30841
30842 \newline
30843
30844 \newline
30845 You will prompted to enter the file name to be debugged.
30846  
30847 \newline
30848
30849 \newline
30850 The command line options that are passed to the simulator directly are
30851  bound to default values in the file sdcdbsrc.el.
30852  The variables are listed below, these values maybe changed as required.
30853 \end_layout
30854
30855 \begin_layout Itemize
30856 sdcdbsrc-cpu-type '51
30857 \end_layout
30858
30859 \begin_layout Itemize
30860 sdcdbsrc-frequency '11059200
30861 \end_layout
30862
30863 \begin_layout Itemize
30864 sdcdbsrc-serial nil
30865 \end_layout
30866
30867 \begin_layout Standard
30868 The following is a list of key mapping for the debugger interface.
30869 \end_layout
30870
30871 \begin_layout Standard
30872 \InsetSpace ~
30873
30874 \family typewriter
30875
30876 \newline
30877 ;;\InsetSpace ~
30878 Current Listing :: 
30879 \newline
30880 ;;key\InsetSpace ~
30881 \InsetSpace ~
30882 \InsetSpace ~
30883 \InsetSpace ~
30884 \InsetSpace ~
30885 \InsetSpace ~
30886 \InsetSpace ~
30887 \InsetSpace ~
30888 \InsetSpace ~
30889 \InsetSpace ~
30890 \InsetSpace ~
30891 \InsetSpace ~
30892 \InsetSpace ~
30893 \InsetSpace ~
30894 binding\InsetSpace ~
30895 \InsetSpace ~
30896 \InsetSpace ~
30897 \InsetSpace ~
30898 \InsetSpace ~
30899 \InsetSpace ~
30900 \InsetSpace ~
30901 \InsetSpace ~
30902 \InsetSpace ~
30903 \InsetSpace ~
30904 \InsetSpace ~
30905 \InsetSpace ~
30906 \InsetSpace ~
30907 \InsetSpace ~
30908 \InsetSpace ~
30909 \InsetSpace ~
30910 \InsetSpace ~
30911 \InsetSpace ~
30912 \InsetSpace ~
30913 \InsetSpace ~
30914 \InsetSpace ~
30915 \InsetSpace ~
30916 Comment 
30917 \newline
30918 ;;---\InsetSpace ~
30919 \InsetSpace ~
30920 \InsetSpace ~
30921 \InsetSpace ~
30922 \InsetSpace ~
30923 \InsetSpace ~
30924 \InsetSpace ~
30925 \InsetSpace ~
30926 \InsetSpace ~
30927 \InsetSpace ~
30928 \InsetSpace ~
30929 \InsetSpace ~
30930 \InsetSpace ~
30931 \InsetSpace ~
30932 -------\InsetSpace ~
30933 \InsetSpace ~
30934 \InsetSpace ~
30935 \InsetSpace ~
30936 \InsetSpace ~
30937 \InsetSpace ~
30938 \InsetSpace ~
30939 \InsetSpace ~
30940 \InsetSpace ~
30941 \InsetSpace ~
30942 \InsetSpace ~
30943 \InsetSpace ~
30944 \InsetSpace ~
30945 \InsetSpace ~
30946 \InsetSpace ~
30947 \InsetSpace ~
30948 \InsetSpace ~
30949 \InsetSpace ~
30950 \InsetSpace ~
30951 \InsetSpace ~
30952 \InsetSpace ~
30953 \InsetSpace ~
30954 -------
30955 \newline
30956 ;; 
30957 \newline
30958 ;;\InsetSpace ~
30959 n\InsetSpace ~
30960 \InsetSpace ~
30961 \InsetSpace ~
30962 \InsetSpace ~
30963 \InsetSpace ~
30964 \InsetSpace ~
30965 \InsetSpace ~
30966 \InsetSpace ~
30967 \InsetSpace ~
30968 \InsetSpace ~
30969 \InsetSpace ~
30970 \InsetSpace ~
30971 \InsetSpace ~
30972 \InsetSpace ~
30973 \InsetSpace ~
30974 sdcdb-next-fro
30975 m-src\InsetSpace ~
30976 \InsetSpace ~
30977 \InsetSpace ~
30978 \InsetSpace ~
30979 \InsetSpace ~
30980 \InsetSpace ~
30981 \InsetSpace ~
30982 \InsetSpace ~
30983 \InsetSpace ~
30984 \InsetSpace ~
30985 SDCDB next command 
30986 \newline
30987 ;;\InsetSpace ~
30988 b\InsetSpace ~
30989 \InsetSpace ~
30990 \InsetSpace ~
30991 \InsetSpace ~
30992 \InsetSpace ~
30993 \InsetSpace ~
30994 \InsetSpace ~
30995 \InsetSpace ~
30996 \InsetSpace ~
30997 \InsetSpace ~
30998 \InsetSpace ~
30999 \InsetSpace ~
31000 \InsetSpace ~
31001 \InsetSpace ~
31002 \InsetSpace ~
31003 sdcdb-back-from-src\InsetSpace ~
31004 \InsetSpace ~
31005 \InsetSpace ~
31006 \InsetSpace ~
31007 \InsetSpace ~
31008 \InsetSpace ~
31009 \InsetSpace ~
31010 \InsetSpace ~
31011 \InsetSpace ~
31012 \InsetSpace ~
31013 SDCDB back command 
31014 \newline
31015 ;;\InsetSpace ~
31016 c\InsetSpace ~
31017 \InsetSpace ~
31018 \InsetSpace ~
31019 \InsetSpace ~
31020 \InsetSpace ~
31021 \InsetSpace ~
31022 \InsetSpace ~
31023 \InsetSpace ~
31024 \InsetSpace ~
31025 \InsetSpace ~
31026 \InsetSpace ~
31027 \InsetSpace ~
31028 \InsetSpace ~
31029 \InsetSpace ~
31030 \InsetSpace ~
31031 sdcdb-cont-f
31032 rom-src\InsetSpace ~
31033 \InsetSpace ~
31034 \InsetSpace ~
31035 \InsetSpace ~
31036 \InsetSpace ~
31037 \InsetSpace ~
31038 \InsetSpace ~
31039 \InsetSpace ~
31040 \InsetSpace ~
31041 \InsetSpace ~
31042 SDCDB continue command
31043 \newline
31044 ;;\InsetSpace ~
31045 s\InsetSpace ~
31046 \InsetSpace ~
31047 \InsetSpace ~
31048 \InsetSpace ~
31049 \InsetSpace ~
31050 \InsetSpace ~
31051 \InsetSpace ~
31052 \InsetSpace ~
31053 \InsetSpace ~
31054 \InsetSpace ~
31055 \InsetSpace ~
31056 \InsetSpace ~
31057 \InsetSpace ~
31058 \InsetSpace ~
31059 \InsetSpace ~
31060 sdcdb-step-from-src\InsetSpace ~
31061 \InsetSpace ~
31062 \InsetSpace ~
31063 \InsetSpace ~
31064 \InsetSpace ~
31065 \InsetSpace ~
31066 \InsetSpace ~
31067 \InsetSpace ~
31068 \InsetSpace ~
31069 \InsetSpace ~
31070 SDCDB step command 
31071 \newline
31072 ;;\InsetSpace ~
31073 ?\InsetSpace ~
31074 \InsetSpace ~
31075 \InsetSpace ~
31076 \InsetSpace ~
31077 \InsetSpace ~
31078 \InsetSpace ~
31079 \InsetSpace ~
31080 \InsetSpace ~
31081 \InsetSpace ~
31082 \InsetSpace ~
31083 \InsetSpace ~
31084 \InsetSpace ~
31085 \InsetSpace ~
31086 \InsetSpace ~
31087 \InsetSpace ~
31088 sdcdb-w
31089 hatis-c-sexp\InsetSpace ~
31090 \InsetSpace ~
31091 \InsetSpace ~
31092 \InsetSpace ~
31093 \InsetSpace ~
31094 \InsetSpace ~
31095 \InsetSpace ~
31096 \InsetSpace ~
31097 \InsetSpace ~
31098 \InsetSpace ~
31099 SDCDB ptypecommand for data at 
31100 \newline
31101 ;;\InsetSpace ~
31102 \InsetSpace ~
31103 \InsetSpace ~
31104 \InsetSpace ~
31105 \InsetSpace ~
31106 \InsetSpace ~
31107 \InsetSpace ~
31108 \InsetSpace ~
31109 \InsetSpace ~
31110 \InsetSpace ~
31111 \InsetSpace ~
31112 \InsetSpace ~
31113 \InsetSpace ~
31114 \InsetSpace ~
31115 \InsetSpace ~
31116 \InsetSpace ~
31117 \InsetSpace ~
31118 \InsetSpace ~
31119 \InsetSpace ~
31120 \InsetSpace ~
31121 \InsetSpace ~
31122 \InsetSpace ~
31123 \InsetSpace ~
31124 \InsetSpace ~
31125 \InsetSpace ~
31126 \InsetSpace ~
31127 \InsetSpace ~
31128 \InsetSpace ~
31129 \InsetSpace ~
31130 \InsetSpace ~
31131 \InsetSpace ~
31132 \InsetSpace ~
31133 \InsetSpace ~
31134 \InsetSpace ~
31135 \InsetSpace ~
31136 \InsetSpace ~
31137 \InsetSpace ~
31138 \InsetSpace ~
31139 \InsetSpace ~
31140 \InsetSpace ~
31141 \InsetSpace ~
31142 \InsetSpace ~
31143 \InsetSpace ~
31144 \InsetSpace ~
31145 \InsetSpace ~
31146 \InsetSpace ~
31147 \InsetSpace ~
31148 buffer point 
31149 \newline
31150 ;;\InsetSpace ~
31151 x\InsetSpace ~
31152 \InsetSpace ~
31153 \InsetSpace ~
31154 \InsetSpace ~
31155 \InsetSpace ~
31156 \InsetSpace ~
31157 \InsetSpace ~
31158 \InsetSpace ~
31159 \InsetSpace ~
31160 \InsetSpace ~
31161 \InsetSpace ~
31162 \InsetSpace ~
31163 \InsetSpace ~
31164 \InsetSpace ~
31165 \InsetSpace ~
31166 sdcdbsrc-delete\InsetSpace ~
31167 \InsetSpace ~
31168 \InsetSpace ~
31169 \InsetSpace ~
31170 \InsetSpace ~
31171 \InsetSpace ~
31172 \InsetSpace ~
31173 \InsetSpace ~
31174 \InsetSpace ~
31175 \InsetSpace ~
31176 \InsetSpace ~
31177 \InsetSpace ~
31178 \InsetSpace ~
31179 \InsetSpace ~
31180 SDCD
31181 B Delete all breakpoints if no arg 
31182 \newline
31183 ;;\InsetSpace ~
31184 \InsetSpace ~
31185 \InsetSpace ~
31186 \InsetSpace ~
31187 \InsetSpace ~
31188 \InsetSpace ~
31189 \InsetSpace ~
31190 \InsetSpace ~
31191 \InsetSpace ~
31192 \InsetSpace ~
31193 \InsetSpace ~
31194 \InsetSpace ~
31195 \InsetSpace ~
31196 \InsetSpace ~
31197 \InsetSpace ~
31198 \InsetSpace ~
31199 \InsetSpace ~
31200 \InsetSpace ~
31201 \InsetSpace ~
31202 \InsetSpace ~
31203 \InsetSpace ~
31204 \InsetSpace ~
31205 \InsetSpace ~
31206 \InsetSpace ~
31207 \InsetSpace ~
31208 \InsetSpace ~
31209 \InsetSpace ~
31210 \InsetSpace ~
31211 \InsetSpace ~
31212 \InsetSpace ~
31213 \InsetSpace ~
31214 \InsetSpace ~
31215 \InsetSpace ~
31216 \InsetSpace ~
31217 \InsetSpace ~
31218 \InsetSpace ~
31219 \InsetSpace ~
31220 \InsetSpace ~
31221 \InsetSpace ~
31222 \InsetSpace ~
31223 \InsetSpace ~
31224 \InsetSpace ~
31225 \InsetSpace ~
31226 \InsetSpace ~
31227 \InsetSpace ~
31228 \InsetSpace ~
31229 \InsetSpace ~
31230 given or delete arg (C-u arg x) 
31231 \newline
31232 ;;\InsetSpace ~
31233 m\InsetSpace ~
31234 \InsetSpace ~
31235 \InsetSpace ~
31236 \InsetSpace ~
31237 \InsetSpace ~
31238 \InsetSpace ~
31239 \InsetSpace ~
31240 \InsetSpace ~
31241 \InsetSpace ~
31242 \InsetSpace ~
31243 \InsetSpace ~
31244 \InsetSpace ~
31245 \InsetSpace ~
31246 \InsetSpace ~
31247 \InsetSpace ~
31248 sdcdbsrc
31249 -frame\InsetSpace ~
31250 \InsetSpace ~
31251 \InsetSpace ~
31252 \InsetSpace ~
31253 \InsetSpace ~
31254 \InsetSpace ~
31255 \InsetSpace ~
31256 \InsetSpace ~
31257 \InsetSpace ~
31258 \InsetSpace ~
31259 \InsetSpace ~
31260 \InsetSpace ~
31261 \InsetSpace ~
31262 \InsetSpace ~
31263 \InsetSpace ~
31264 SDCDB Display current frame if no arg, 
31265 \newline
31266 ;;\InsetSpace ~
31267 \InsetSpace ~
31268 \InsetSpace ~
31269 \InsetSpace ~
31270 \InsetSpace ~
31271 \InsetSpace ~
31272 \InsetSpace ~
31273 \InsetSpace ~
31274 \InsetSpace ~
31275 \InsetSpace ~
31276 \InsetSpace ~
31277 \InsetSpace ~
31278 \InsetSpace ~
31279 \InsetSpace ~
31280 \InsetSpace ~
31281 \InsetSpace ~
31282 \InsetSpace ~
31283 \InsetSpace ~
31284 \InsetSpace ~
31285 \InsetSpace ~
31286 \InsetSpace ~
31287 \InsetSpace ~
31288 \InsetSpace ~
31289 \InsetSpace ~
31290 \InsetSpace ~
31291 \InsetSpace ~
31292 \InsetSpace ~
31293 \InsetSpace ~
31294 \InsetSpace ~
31295 \InsetSpace ~
31296 \InsetSpace ~
31297 \InsetSpace ~
31298 \InsetSpace ~
31299 \InsetSpace ~
31300 \InsetSpace ~
31301 \InsetSpace ~
31302 \InsetSpace ~
31303 \InsetSpace ~
31304 \InsetSpace ~
31305 \InsetSpace ~
31306 \InsetSpace ~
31307 \InsetSpace ~
31308 \InsetSpace ~
31309 \InsetSpace ~
31310 \InsetSpace ~
31311 \InsetSpace ~
31312 \InsetSpace ~
31313 given or display frame arg
31314  
31315 \newline
31316 ;;\InsetSpace ~
31317 \InsetSpace ~
31318 \InsetSpace ~
31319 \InsetSpace ~
31320 \InsetSpace ~
31321 \InsetSpace ~
31322 \InsetSpace ~
31323 \InsetSpace ~
31324 \InsetSpace ~
31325 \InsetSpace ~
31326 \InsetSpace ~
31327 \InsetSpace ~
31328 \InsetSpace ~
31329 \InsetSpace ~
31330 \InsetSpace ~
31331 \InsetSpace ~
31332 \InsetSpace ~
31333 \InsetSpace ~
31334 \InsetSpace ~
31335 \InsetSpace ~
31336 \InsetSpace ~
31337 \InsetSpace ~
31338 \InsetSpace ~
31339 \InsetSpace ~
31340 \InsetSpace ~
31341 \InsetSpace ~
31342 \InsetSpace ~
31343 \InsetSpace ~
31344 \InsetSpace ~
31345 \InsetSpace ~
31346 \InsetSpace ~
31347 \InsetSpace ~
31348 \InsetSpace ~
31349 \InsetSpace ~
31350 \InsetSpace ~
31351 \InsetSpace ~
31352 \InsetSpace ~
31353 \InsetSpace ~
31354 \InsetSpace ~
31355 \InsetSpace ~
31356 \InsetSpace ~
31357 \InsetSpace ~
31358 \InsetSpace ~
31359 \InsetSpace ~
31360 \InsetSpace ~
31361 \InsetSpace ~
31362 \InsetSpace ~
31363 buffer point 
31364 \newline
31365 ;;\InsetSpace ~
31366 !\InsetSpace ~
31367 \InsetSpace ~
31368 \InsetSpace ~
31369 \InsetSpace ~
31370 \InsetSpace ~
31371 \InsetSpace ~
31372 \InsetSpace ~
31373 \InsetSpace ~
31374 \InsetSpace ~
31375 \InsetSpace ~
31376 \InsetSpace ~
31377 \InsetSpace ~
31378 \InsetSpace ~
31379 \InsetSpace ~
31380 \InsetSpace ~
31381 sdcdbsrc-goto-sdcdb\InsetSpace ~
31382 \InsetSpace ~
31383 \InsetSpace ~
31384 \InsetSpace ~
31385 \InsetSpace ~
31386 \InsetSpace ~
31387 \InsetSpace ~
31388 \InsetSpace ~
31389 \InsetSpace ~
31390 \InsetSpace ~
31391 Goto the SDCDB output buffer 
31392 \newline
31393 ;;\InsetSpace ~
31394 p\InsetSpace ~
31395 \InsetSpace ~
31396 \InsetSpace ~
31397 \InsetSpace ~
31398 \InsetSpace ~
31399 \InsetSpace ~
31400 \InsetSpace ~
31401 \InsetSpace ~
31402 \InsetSpace ~
31403 \InsetSpace ~
31404 \InsetSpace ~
31405 \InsetSpace ~
31406 \InsetSpace ~
31407 \InsetSpace ~
31408 \InsetSpace ~
31409 sdcdb-prin
31410 t-c-sexp\InsetSpace ~
31411 \InsetSpace ~
31412 \InsetSpace ~
31413 \InsetSpace ~
31414 \InsetSpace ~
31415 \InsetSpace ~
31416 \InsetSpace ~
31417 \InsetSpace ~
31418 \InsetSpace ~
31419 \InsetSpace ~
31420 \InsetSpace ~
31421 SDCDB print command for data at 
31422 \newline
31423 ;;\InsetSpace ~
31424 \InsetSpace ~
31425 \InsetSpace ~
31426 \InsetSpace ~
31427 \InsetSpace ~
31428 \InsetSpace ~
31429 \InsetSpace ~
31430 \InsetSpace ~
31431 \InsetSpace ~
31432 \InsetSpace ~
31433 \InsetSpace ~
31434 \InsetSpace ~
31435 \InsetSpace ~
31436 \InsetSpace ~
31437 \InsetSpace ~
31438 \InsetSpace ~
31439 \InsetSpace ~
31440 \InsetSpace ~
31441 \InsetSpace ~
31442 \InsetSpace ~
31443 \InsetSpace ~
31444 \InsetSpace ~
31445 \InsetSpace ~
31446 \InsetSpace ~
31447 \InsetSpace ~
31448 \InsetSpace ~
31449 \InsetSpace ~
31450 \InsetSpace ~
31451 \InsetSpace ~
31452 \InsetSpace ~
31453 \InsetSpace ~
31454 \InsetSpace ~
31455 \InsetSpace ~
31456 \InsetSpace ~
31457 \InsetSpace ~
31458 \InsetSpace ~
31459 \InsetSpace ~
31460 \InsetSpace ~
31461 \InsetSpace ~
31462 \InsetSpace ~
31463 \InsetSpace ~
31464 \InsetSpace ~
31465 \InsetSpace ~
31466 \InsetSpace ~
31467 \InsetSpace ~
31468 \InsetSpace ~
31469 \InsetSpace ~
31470 buffer point 
31471 \newline
31472 ;;\InsetSpace ~
31473 g\InsetSpace ~
31474 \InsetSpace ~
31475 \InsetSpace ~
31476 \InsetSpace ~
31477 \InsetSpace ~
31478 \InsetSpace ~
31479 \InsetSpace ~
31480 \InsetSpace ~
31481 \InsetSpace ~
31482 \InsetSpace ~
31483 \InsetSpace ~
31484 \InsetSpace ~
31485 \InsetSpace ~
31486 \InsetSpace ~
31487 \InsetSpace ~
31488 sdcdbsrc-goto-sdcdb\InsetSpace ~
31489 \InsetSpace ~
31490 \InsetSpace ~
31491 \InsetSpace ~
31492 \InsetSpace ~
31493 \InsetSpace ~
31494 \InsetSpace ~
31495 \InsetSpace ~
31496 \InsetSpace ~
31497 \InsetSpace ~
31498 Got
31499 o the SDCDB output buffer 
31500 \newline
31501 ;;\InsetSpace ~
31502 t\InsetSpace ~
31503 \InsetSpace ~
31504 \InsetSpace ~
31505 \InsetSpace ~
31506 \InsetSpace ~
31507 \InsetSpace ~
31508 \InsetSpace ~
31509 \InsetSpace ~
31510 \InsetSpace ~
31511 \InsetSpace ~
31512 \InsetSpace ~
31513 \InsetSpace ~
31514 \InsetSpace ~
31515 \InsetSpace ~
31516 \InsetSpace ~
31517 sdcdbsrc-mode\InsetSpace ~
31518 \InsetSpace ~
31519 \InsetSpace ~
31520 \InsetSpace ~
31521 \InsetSpace ~
31522 \InsetSpace ~
31523 \InsetSpace ~
31524 \InsetSpace ~
31525 \InsetSpace ~
31526 \InsetSpace ~
31527 \InsetSpace ~
31528 \InsetSpace ~
31529 \InsetSpace ~
31530 \InsetSpace ~
31531 \InsetSpace ~
31532 \InsetSpace ~
31533 Toggles Sdcdbsrc mode (turns it
31534  off) 
31535 \newline
31536 ;; 
31537 \newline
31538 ;;\InsetSpace ~
31539 C-c\InsetSpace ~
31540 C-f\InsetSpace ~
31541 \InsetSpace ~
31542 \InsetSpace ~
31543 \InsetSpace ~
31544 \InsetSpace ~
31545 \InsetSpace ~
31546 \InsetSpace ~
31547 \InsetSpace ~
31548 \InsetSpace ~
31549 sdcdb-finish-from-src\InsetSpace ~
31550 \InsetSpace ~
31551 \InsetSpace ~
31552 \InsetSpace ~
31553 \InsetSpace ~
31554 \InsetSpace ~
31555 \InsetSpace ~
31556 \InsetSpace ~
31557 SDCDB finish command 
31558 \newline
31559 ;; 
31560 \newline
31561 ;;\InsetSpace ~
31562 C-x\InsetSpace ~
31563 SPC\InsetSpace ~
31564 \InsetSpace ~
31565 \InsetSpace ~
31566 \InsetSpace ~
31567 \InsetSpace ~
31568 \InsetSpace ~
31569 \InsetSpace ~
31570 \InsetSpace ~
31571 \InsetSpace ~
31572 sdcdb-brea
31573 k\InsetSpace ~
31574 \InsetSpace ~
31575 \InsetSpace ~
31576 \InsetSpace ~
31577 \InsetSpace ~
31578 \InsetSpace ~
31579 \InsetSpace ~
31580 \InsetSpace ~
31581 \InsetSpace ~
31582 \InsetSpace ~
31583 \InsetSpace ~
31584 \InsetSpace ~
31585 \InsetSpace ~
31586 \InsetSpace ~
31587 \InsetSpace ~
31588 \InsetSpace ~
31589 \InsetSpace ~
31590 \InsetSpace ~
31591 Set break for line with point 
31592 \newline
31593 ;;\InsetSpace ~
31594 ESC\InsetSpace ~
31595 t\InsetSpace ~
31596 \InsetSpace ~
31597 \InsetSpace ~
31598 \InsetSpace ~
31599 \InsetSpace ~
31600 \InsetSpace ~
31601 \InsetSpace ~
31602 \InsetSpace ~
31603 \InsetSpace ~
31604 \InsetSpace ~
31605 \InsetSpace ~
31606 sdcdbsrc-mode\InsetSpace ~
31607 \InsetSpace ~
31608 \InsetSpace ~
31609 \InsetSpace ~
31610 \InsetSpace ~
31611 \InsetSpace ~
31612 \InsetSpace ~
31613 \InsetSpace ~
31614 \InsetSpace ~
31615 \InsetSpace ~
31616 \InsetSpace ~
31617 \InsetSpace ~
31618 \InsetSpace ~
31619 \InsetSpace ~
31620 \InsetSpace ~
31621 \InsetSpace ~
31622 Toggle Sdcdbsrc mode 
31623 \newline
31624 ;;\InsetSpace ~
31625 ESC\InsetSpace ~
31626 m\InsetSpace ~
31627 \InsetSpace ~
31628 \InsetSpace ~
31629 \InsetSpace ~
31630 \InsetSpace ~
31631 \InsetSpace ~
31632 \InsetSpace ~
31633 \InsetSpace ~
31634 \InsetSpace ~
31635 \InsetSpace ~
31636 \InsetSpace ~
31637 sdc
31638 dbsrc-srcmode\InsetSpace ~
31639 \InsetSpace ~
31640 \InsetSpace ~
31641 \InsetSpace ~
31642 \InsetSpace ~
31643 \InsetSpace ~
31644 \InsetSpace ~
31645 \InsetSpace ~
31646 \InsetSpace ~
31647 \InsetSpace ~
31648 \InsetSpace ~
31649 \InsetSpace ~
31650 \InsetSpace ~
31651 Toggle list mode 
31652 \newline
31653 ;; 
31654 \newline
31655
31656 \family default
31657
31658 \newpage
31659
31660 \end_layout
31661
31662 \begin_layout Chapter
31663 TIPS
31664 \end_layout
31665
31666 \begin_layout Standard
31667 Here are a few guidelines that will help the compiler generate more efficient
31668  code, some of the tips are specific to this compiler others are generally
31669  good programming practice.
31670 \end_layout
31671
31672 \begin_layout Itemize
31673 Use the smallest data type to represent your data-value.
31674  If it is known in advance that the value is going to be less than 256 then
31675  use an 'unsigned char' instead of a 'short' or 'int'.
31676  Please note, that ANSI C requires both signed and unsigned chars to be
31677  promoted to 'signed int'
31678 \begin_inset LatexCommand index
31679 name "promotion to signed int"
31680
31681 \end_inset
31682
31683
31684 \begin_inset Marginal
31685 status collapsed
31686
31687 \begin_layout Standard
31688
31689 \series bold
31690 \InsetSpace ~
31691 !
31692 \end_layout
31693
31694 \end_inset
31695
31696  before doing any operation.
31697  This promotion
31698 \begin_inset LatexCommand index
31699 name "type promotion"
31700
31701 \end_inset
31702
31703
31704 \begin_inset LatexCommand label
31705 name "type promotion"
31706
31707 \end_inset
31708
31709  can be omitted, if the result is the same.
31710  The effect of the promotion rules together with the sign-extension is often
31711  surprising:
31712 \end_layout
31713
31714 \begin_deeper
31715 \begin_layout Verse
31716
31717 \family typewriter
31718 unsigned char uc = 0xfe;
31719 \newline
31720 if (uc * uc < 0) /* this is true! */
31721 \newline
31722 {
31723 \newline
31724 \InsetSpace ~
31725 \InsetSpace ~
31726 \InsetSpace ~
31727 \InsetSpace ~
31728 ....
31729 \newline
31730 }
31731 \end_layout
31732
31733 \begin_layout Standard
31734
31735 \family typewriter
31736 uc * uc
31737 \family default
31738  is evaluated as 
31739 \family typewriter
31740 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
31741 \family default
31742 .
31743  
31744 \newline
31745 Another one:
31746 \end_layout
31747
31748 \begin_layout Verse
31749
31750 \family typewriter
31751 (unsigned char) -12 / (signed char) -3 = ...
31752 \end_layout
31753
31754 \begin_layout Standard
31755 No, the result is not 4:
31756 \end_layout
31757
31758 \begin_layout Verse
31759
31760 \family typewriter
31761 (int) (unsigned char) -12 / (int) (signed char) -3 =
31762 \newline
31763 (int) (unsigned char)
31764  0xf4 / (int) (signed char) 0xfd =
31765 \newline
31766 (int) 0x00f4 / (int) 0xfffd =
31767 \newline
31768 (int) 0x00f4
31769  / (int) 0xfffd =
31770 \newline
31771 (int) 244 / (int) -3 =
31772 \newline
31773 (int) -81 = (int) 0xffaf;
31774 \end_layout
31775
31776 \begin_layout Standard
31777 Don't complain, that gcc gives you a different result.
31778  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
31779  Therefore the results are different.
31780 \newline
31781 From 
31782 \begin_inset Quotes sld
31783 \end_inset
31784
31785 comp.lang.c FAQ
31786 \begin_inset Quotes srd
31787 \end_inset
31788
31789 :
31790 \end_layout
31791
31792 \begin_layout Quote
31793
31794 \emph on
31795 If well-defined overflow characteristics are important and negative values
31796  are not, or if you want to steer clear of sign-extension problems when
31797  manipulating bits or bytes, use one of the corresponding unsigned types.
31798  (Beware when mixing signed and unsigned values in expressions, though.)
31799 \newline
31800 Although
31801  character types (especially unsigned char) can be used as "tiny" integers,
31802  doing so is sometimes more trouble than it's worth, due to unpredictable
31803  sign extension and increased code size.
31804 \end_layout
31805
31806 \end_deeper
31807 \begin_layout Itemize
31808 Use unsigned when it is known in advance that the value is not going to
31809  be negative.
31810  This helps especially if you are doing division or multiplication, bit-shifting
31811  or are using an array index.
31812 \end_layout
31813
31814 \begin_layout Itemize
31815 NEVER jump into a LOOP.
31816 \end_layout
31817
31818 \begin_layout Itemize
31819 Declare the variables to be local
31820 \begin_inset LatexCommand index
31821 name "local variables"
31822
31823 \end_inset
31824
31825  whenever possible, especially loop control variables (induction).
31826 \end_layout
31827
31828 \begin_layout Itemize
31829 Have a look at the assembly listing to get a 
31830 \begin_inset Quotes sld
31831 \end_inset
31832
31833 feeling
31834 \begin_inset Quotes srd
31835 \end_inset
31836
31837  for the code generation.
31838 \end_layout
31839
31840 \begin_layout Section
31841 Porting code from or to other compilers
31842 \begin_inset LatexCommand label
31843 name "sec:Porting-code-to-other-compilers"
31844
31845 \end_inset
31846
31847
31848 \end_layout
31849
31850 \begin_layout Itemize
31851 check whether endianness of the compilers differs and adapt where needed.
31852 \end_layout
31853
31854 \begin_layout Itemize
31855 check the device specific header files
31856 \begin_inset LatexCommand index
31857 name "Header files"
31858
31859 \end_inset
31860
31861
31862 \begin_inset LatexCommand index
31863 name "Include files"
31864
31865 \end_inset
31866
31867  for compiler specific syntax.
31868  Eventually include the file <compiler.h
31869 \begin_inset LatexCommand index
31870 name "compiler.h (include file)"
31871
31872 \end_inset
31873
31874
31875 \begin_inset LatexCommand url
31876 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup"
31877
31878 \end_inset
31879
31880  to allow using common header files.
31881  (see f.e.
31882  cc2510fx.h 
31883 \begin_inset LatexCommand url
31884 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup"
31885
31886 \end_inset
31887
31888 ).
31889 \end_layout
31890
31891 \begin_layout Itemize
31892 check whether the startup code contains the correct initialization (watchdog,
31893  peripherals).
31894 \end_layout
31895
31896 \begin_layout Itemize
31897 check whether the sizes of short, int, long match.
31898 \end_layout
31899
31900 \begin_layout Itemize
31901 check if some 16 or 32 bit hardware registers require a specific addressing
31902  order (least significant or most significant byte first) and adapt if needed
31903  (
31904 \emph on
31905 first
31906 \emph default
31907  and 
31908 \emph on
31909 last
31910 \emph default
31911  relate to time and not to lower/upper memory location here, so this is
31912  
31913 \emph on
31914 not
31915 \emph default
31916  the same as endianness).
31917 \end_layout
31918
31919 \begin_layout Itemize
31920 check whether the keyword 
31921 \emph on
31922 volatile
31923 \emph default
31924  is used where needed.
31925  The compilers might differ in their optimization characteristics (as different
31926  versions of the same compiler might also use more clever optimizations
31927  this is good idea anyway).
31928  See section 
31929 \begin_inset LatexCommand ref
31930 reference "sub:Common-interrupt-pitfall-volatile"
31931
31932 \end_inset
31933
31934 .
31935 \end_layout
31936
31937 \begin_layout Itemize
31938 check that the compilers are not told to suppress warnings.
31939 \end_layout
31940
31941 \begin_layout Itemize
31942 check and convert compiler specific extensions (interrupts, memory areas,
31943  pragmas etc.).
31944 \end_layout
31945
31946 \begin_layout Itemize
31947 check for differences in type promotion.
31948  Especially check for math operations on 
31949 \family typewriter
31950 char
31951 \family default
31952  or 
31953 \family typewriter
31954 unsigned char
31955 \family default
31956  variables.
31957  For the sake of C99 compatibility SDCC will probably promote these to 
31958 \family typewriter
31959 int
31960 \family default
31961  more often than other compilers.
31962  Eventually insert explicit casts to 
31963 \family typewriter
31964 (char)
31965 \family default
31966  or 
31967 \family typewriter
31968 (unsigned char)
31969 \family default
31970 .
31971  Also check that the ~\InsetSpace ~
31972 operator
31973 \begin_inset LatexCommand index
31974 name "\\~\\/ Operator"
31975
31976 \end_inset
31977
31978  is not used on 
31979 \family typewriter
31980 bit
31981 \begin_inset LatexCommand index
31982 name "bit"
31983
31984 \end_inset
31985
31986
31987 \family default
31988  variables, use the !\InsetSpace ~
31989 operator instead.
31990  See sections 
31991 \begin_inset LatexCommand ref
31992 reference "type promotion"
31993
31994 \end_inset
31995
31996  and 
31997 \begin_inset LatexCommand ref
31998 reference "sec:Compatibility-with-previous"
31999
32000 \end_inset
32001
32002 .
32003 \end_layout
32004
32005 \begin_layout Itemize
32006 check the assembly code generated for interrupt routines (f.e.
32007  for calls to possibly non-reentrant library functions).
32008 \end_layout
32009
32010 \begin_layout Itemize
32011 check whether timing loops result in proper timing (or preferably consider
32012  a rewrite of the code with timer based delays instead).
32013 \end_layout
32014
32015 \begin_layout Itemize
32016 check for differences in printf parameters (some compilers push (va_arg
32017 \begin_inset LatexCommand index
32018 name "vararg, va\\_arg"
32019
32020 \end_inset
32021
32022 ) char variables as 
32023 \family typewriter
32024 int
32025 \family default
32026  others push them as 
32027 \family typewriter
32028 char
32029 \family default
32030 .
32031  See section 
32032 \begin_inset LatexCommand ref
32033 reference "sec:Compatibility-with-previous"
32034
32035 \end_inset
32036
32037 ).
32038 \end_layout
32039
32040 \begin_layout Itemize
32041 check the resulting memory map
32042 \begin_inset LatexCommand index
32043 name "Memory map"
32044
32045 \end_inset
32046
32047 .
32048  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
32049 ly idata, pdata, xdata).
32050  Eventually check if unexpected library functions are included.
32051 \end_layout
32052
32053 \begin_layout Section
32054 Tools
32055 \begin_inset LatexCommand index
32056 name "Tools"
32057
32058 \end_inset
32059
32060  included in the distribution
32061 \end_layout
32062
32063 \begin_layout Standard
32064 \align left
32065 \begin_inset Tabular
32066 <lyxtabular version="3" rows="12" columns="3">
32067 <features>
32068 <column alignment="left" valignment="top" leftline="true" width="0pt">
32069 <column alignment="left" valignment="top" leftline="true" width="0pt">
32070 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32071 <row topline="true" bottomline="true">
32072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32073 \begin_inset Text
32074
32075 \begin_layout Standard
32076
32077 \series bold
32078 Name
32079 \end_layout
32080
32081 \end_inset
32082 </cell>
32083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32084 \begin_inset Text
32085
32086 \begin_layout Standard
32087
32088 \series bold
32089 Purpose
32090 \end_layout
32091
32092 \end_inset
32093 </cell>
32094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32095 \begin_inset Text
32096
32097 \begin_layout Standard
32098
32099 \series bold
32100 Directory
32101 \end_layout
32102
32103 \end_inset
32104 </cell>
32105 </row>
32106 <row topline="true">
32107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32108 \begin_inset Text
32109
32110 \begin_layout Standard
32111 uCsim
32112 \begin_inset LatexCommand index
32113 name "uCsim"
32114
32115 \end_inset
32116
32117
32118 \end_layout
32119
32120 \end_inset
32121 </cell>
32122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32123 \begin_inset Text
32124
32125 \begin_layout Standard
32126 Simulator for various architectures
32127 \end_layout
32128
32129 \end_inset
32130 </cell>
32131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32132 \begin_inset Text
32133
32134 \begin_layout Standard
32135 sdcc/sim/ucsim
32136 \end_layout
32137
32138 \end_inset
32139 </cell>
32140 </row>
32141 <row topline="true">
32142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32143 \begin_inset Text
32144
32145 \begin_layout Standard
32146 keil2sdcc.pl
32147 \end_layout
32148
32149 \end_inset
32150 </cell>
32151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32152 \begin_inset Text
32153
32154 \begin_layout Standard
32155 header file
32156 \begin_inset LatexCommand index
32157 name "Header files"
32158
32159 \end_inset
32160
32161
32162 \begin_inset LatexCommand index
32163 name "Include files"
32164
32165 \end_inset
32166
32167  conversion
32168 \end_layout
32169
32170 \end_inset
32171 </cell>
32172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32173 \begin_inset Text
32174
32175 \begin_layout Standard
32176 sdcc/support/scripts
32177 \end_layout
32178
32179 \end_inset
32180 </cell>
32181 </row>
32182 <row topline="true">
32183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32184 \begin_inset Text
32185
32186 \begin_layout Standard
32187 mh2h.c
32188 \end_layout
32189
32190 \end_inset
32191 </cell>
32192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32193 \begin_inset Text
32194
32195 \begin_layout Standard
32196 header file conversion
32197 \end_layout
32198
32199 \end_inset
32200 </cell>
32201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32202 \begin_inset Text
32203
32204 \begin_layout Standard
32205 sdcc/support/scripts
32206 \end_layout
32207
32208 \end_inset
32209 </cell>
32210 </row>
32211 <row topline="true">
32212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32213 \begin_inset Text
32214
32215 \begin_layout Standard
32216 as-gbz80
32217 \end_layout
32218
32219 \end_inset
32220 </cell>
32221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32222 \begin_inset Text
32223
32224 \begin_layout Standard
32225 Assembler
32226 \end_layout
32227
32228 \end_inset
32229 </cell>
32230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32231 \begin_inset Text
32232
32233 \begin_layout Standard
32234
32235 \family roman
32236 \series medium
32237 \shape up
32238 \size normal
32239 \emph off
32240 \bar no
32241 \noun off
32242 \color none
32243 sdcc/bin
32244 \end_layout
32245
32246 \end_inset
32247 </cell>
32248 </row>
32249 <row topline="true">
32250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32251 \begin_inset Text
32252
32253 \begin_layout Standard
32254 as-z80
32255 \end_layout
32256
32257 \end_inset
32258 </cell>
32259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32260 \begin_inset Text
32261
32262 \begin_layout Standard
32263 Assembler
32264 \end_layout
32265
32266 \end_inset
32267 </cell>
32268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32269 \begin_inset Text
32270
32271 \begin_layout Standard
32272
32273 \family roman
32274 \series medium
32275 \shape up
32276 \size normal
32277 \emph off
32278 \bar no
32279 \noun off
32280 \color none
32281 sdcc/bin
32282 \end_layout
32283
32284 \end_inset
32285 </cell>
32286 </row>
32287 <row topline="true">
32288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32289 \begin_inset Text
32290
32291 \begin_layout Standard
32292 asx8051
32293 \end_layout
32294
32295 \end_inset
32296 </cell>
32297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32298 \begin_inset Text
32299
32300 \begin_layout Standard
32301 Assembler
32302 \end_layout
32303
32304 \end_inset
32305 </cell>
32306 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32307 \begin_inset Text
32308
32309 \begin_layout Standard
32310
32311 \family roman
32312 \series medium
32313 \shape up
32314 \size normal
32315 \emph off
32316 \bar no
32317 \noun off
32318 \color none
32319 sdcc/bin
32320 \end_layout
32321
32322 \end_inset
32323 </cell>
32324 </row>
32325 <row topline="true">
32326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32327 \begin_inset Text
32328
32329 \begin_layout Standard
32330 SDCDB
32331 \end_layout
32332
32333 \end_inset
32334 </cell>
32335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32336 \begin_inset Text
32337
32338 \begin_layout Standard
32339 Simulator
32340 \end_layout
32341
32342 \end_inset
32343 </cell>
32344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32345 \begin_inset Text
32346
32347 \begin_layout Standard
32348
32349 \family roman
32350 \series medium
32351 \shape up
32352 \size normal
32353 \emph off
32354 \bar no
32355 \noun off
32356 \color none
32357 sdcc/bin
32358 \end_layout
32359
32360 \end_inset
32361 </cell>
32362 </row>
32363 <row topline="true">
32364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32365 \begin_inset Text
32366
32367 \begin_layout Standard
32368 aslink
32369 \end_layout
32370
32371 \end_inset
32372 </cell>
32373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32374 \begin_inset Text
32375
32376 \begin_layout Standard
32377 Linker
32378 \end_layout
32379
32380 \end_inset
32381 </cell>
32382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32383 \begin_inset Text
32384
32385 \begin_layout Standard
32386
32387 \family roman
32388 \series medium
32389 \shape up
32390 \size normal
32391 \emph off
32392 \bar no
32393 \noun off
32394 \color none
32395 sdcc/bin
32396 \end_layout
32397
32398 \end_inset
32399 </cell>
32400 </row>
32401 <row topline="true">
32402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32403 \begin_inset Text
32404
32405 \begin_layout Standard
32406 link-z80
32407 \end_layout
32408
32409 \end_inset
32410 </cell>
32411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32412 \begin_inset Text
32413
32414 \begin_layout Standard
32415 Linker
32416 \end_layout
32417
32418 \end_inset
32419 </cell>
32420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32421 \begin_inset Text
32422
32423 \begin_layout Standard
32424
32425 \family roman
32426 \series medium
32427 \shape up
32428 \size normal
32429 \emph off
32430 \bar no
32431 \noun off
32432 \color none
32433 sdcc/bin
32434 \end_layout
32435
32436 \end_inset
32437 </cell>
32438 </row>
32439 <row topline="true">
32440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32441 \begin_inset Text
32442
32443 \begin_layout Standard
32444 link-gbz80
32445 \end_layout
32446
32447 \end_inset
32448 </cell>
32449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32450 \begin_inset Text
32451
32452 \begin_layout Standard
32453 Linker
32454 \end_layout
32455
32456 \end_inset
32457 </cell>
32458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32459 \begin_inset Text
32460
32461 \begin_layout Standard
32462
32463 \family roman
32464 \series medium
32465 \shape up
32466 \size normal
32467 \emph off
32468 \bar no
32469 \noun off
32470 \color none
32471 sdcc/bin
32472 \end_layout
32473
32474 \end_inset
32475 </cell>
32476 </row>
32477 <row topline="true" bottomline="true">
32478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32479 \begin_inset Text
32480
32481 \begin_layout Standard
32482 packihx
32483 \end_layout
32484
32485 \end_inset
32486 </cell>
32487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32488 \begin_inset Text
32489
32490 \begin_layout Standard
32491 Intel Hex packer 
32492 \begin_inset LatexCommand index
32493 name "packihx (tool)"
32494
32495 \end_inset
32496
32497
32498 \end_layout
32499
32500 \end_inset
32501 </cell>
32502 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32503 \begin_inset Text
32504
32505 \begin_layout Standard
32506
32507 \family roman
32508 \series medium
32509 \shape up
32510 \size normal
32511 \emph off
32512 \bar no
32513 \noun off
32514 \color none
32515 sdcc/bin
32516 \end_layout
32517
32518 \end_inset
32519 </cell>
32520 </row>
32521 </lyxtabular>
32522
32523 \end_inset
32524
32525
32526 \newline
32527
32528 \end_layout
32529
32530 \begin_layout Section
32531 Documentation
32532 \begin_inset LatexCommand index
32533 name "Documentation"
32534
32535 \end_inset
32536
32537  included in the distribution
32538 \end_layout
32539
32540 \begin_layout Standard
32541 \align left
32542 \begin_inset Tabular
32543 <lyxtabular version="3" rows="10" columns="2">
32544 <features>
32545 <column alignment="block" valignment="top" leftline="true" width="40col%">
32546 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
32547 <row topline="true" bottomline="true" endhead="true">
32548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32549 \begin_inset Text
32550
32551 \begin_layout Standard
32552
32553 \series bold
32554 Subject / Title
32555 \end_layout
32556
32557 \end_inset
32558 </cell>
32559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32560 \begin_inset Text
32561
32562 \begin_layout Standard
32563
32564 \series bold
32565 Filename / Where to get
32566 \end_layout
32567
32568 \end_inset
32569 </cell>
32570 </row>
32571 <row topline="true">
32572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32573 \begin_inset Text
32574
32575 \begin_layout Standard
32576 SDCC Compiler User Guide
32577 \end_layout
32578
32579 \end_inset
32580 </cell>
32581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32582 \begin_inset Text
32583
32584 \begin_layout Standard
32585 You're reading it right now 
32586 \emph on
32587 \InsetSpace ~
32588 \InsetSpace ~
32589 \InsetSpace ~
32590
32591 \hfill
32592 online at:
32593 \emph default
32594
32595 \newline
32596
32597 \begin_inset LatexCommand url
32598 target "http://sdcc.sourceforge.net/doc/sdccman.pdf"
32599
32600 \end_inset
32601
32602
32603 \end_layout
32604
32605 \end_inset
32606 </cell>
32607 </row>
32608 <row topline="true">
32609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32610 \begin_inset Text
32611
32612 \begin_layout Standard
32613 Changelog of SDCC
32614 \end_layout
32615
32616 \end_inset
32617 </cell>
32618 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32619 \begin_inset Text
32620
32621 \begin_layout Standard
32622 sdcc/Changelog 
32623 \emph on
32624 \InsetSpace ~
32625 \InsetSpace ~
32626 \InsetSpace ~
32627
32628 \hfill
32629 online at:
32630 \emph default
32631
32632 \newline
32633
32634 \begin_inset LatexCommand url
32635 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog"
32636
32637 \end_inset
32638
32639
32640 \end_layout
32641
32642 \end_inset
32643 </cell>
32644 </row>
32645 <row topline="true">
32646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32647 \begin_inset Text
32648
32649 \begin_layout Standard
32650 ASXXXX
32651 \begin_inset LatexCommand index
32652 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
32653
32654 \end_inset
32655
32656
32657 \begin_inset LatexCommand index
32658 name "Assembler documentation"
32659
32660 \end_inset
32661
32662  Assemblers and
32663 \newline
32664 ASLINK
32665 \begin_inset LatexCommand index
32666 name "aslink"
32667
32668 \end_inset
32669
32670
32671 \begin_inset LatexCommand index
32672 name "Linker documentation"
32673
32674 \end_inset
32675
32676  Relocating Linker
32677 \end_layout
32678
32679 \end_inset
32680 </cell>
32681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32682 \begin_inset Text
32683
32684 \begin_layout Standard
32685 sdcc/as/doc/asxhtm.html 
32686 \emph on
32687 \InsetSpace ~
32688 \InsetSpace ~
32689 \InsetSpace ~
32690
32691 \hfill
32692 online at:
32693 \emph default
32694
32695 \newline
32696
32697 \begin_inset LatexCommand url
32698 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html"
32699
32700 \end_inset
32701
32702
32703 \end_layout
32704
32705 \end_inset
32706 </cell>
32707 </row>
32708 <row topline="true">
32709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32710 \begin_inset Text
32711
32712 \begin_layout Standard
32713 SDCC regression test
32714 \begin_inset LatexCommand index
32715 name "Regression test"
32716
32717 \end_inset
32718
32719
32720 \end_layout
32721
32722 \end_inset
32723 </cell>
32724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32725 \begin_inset Text
32726
32727 \begin_layout Standard
32728 sdcc/doc/test_suite_spec.pdf 
32729 \emph on
32730 \InsetSpace ~
32731 \InsetSpace ~
32732 \InsetSpace ~
32733
32734 \hfill
32735 online at:
32736 \emph default
32737
32738 \newline
32739
32740 \begin_inset LatexCommand url
32741 target "http://sdcc.sourceforge.net/doc/test_suite_spec.pdf"
32742
32743 \end_inset
32744
32745
32746 \end_layout
32747
32748 \end_inset
32749 </cell>
32750 </row>
32751 <row topline="true">
32752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32753 \begin_inset Text
32754
32755 \begin_layout Standard
32756 Various notes
32757 \end_layout
32758
32759 \end_inset
32760 </cell>
32761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32762 \begin_inset Text
32763
32764 \begin_layout Standard
32765 sdcc/doc/* 
32766 \emph on
32767 \InsetSpace ~
32768 \InsetSpace ~
32769 \InsetSpace ~
32770
32771 \hfill
32772 online at:
32773 \emph default
32774
32775 \newline
32776
32777 \begin_inset LatexCommand url
32778 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/"
32779
32780 \end_inset
32781
32782
32783 \end_layout
32784
32785 \end_inset
32786 </cell>
32787 </row>
32788 <row topline="true">
32789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32790 \begin_inset Text
32791
32792 \begin_layout Standard
32793 Notes on debugging with SDCDB
32794 \begin_inset LatexCommand index
32795 name "SDCDB (debugger)"
32796
32797 \end_inset
32798
32799
32800 \end_layout
32801
32802 \end_inset
32803 </cell>
32804 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32805 \begin_inset Text
32806
32807 \begin_layout Standard
32808 sdcc/debugger/README 
32809 \emph on
32810 \InsetSpace ~
32811 \InsetSpace ~
32812 \InsetSpace ~
32813
32814 \hfill
32815 online at
32816 \emph default
32817 :
32818 \newline
32819
32820 \begin_inset LatexCommand url
32821 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README"
32822
32823 \end_inset
32824
32825
32826 \end_layout
32827
32828 \end_inset
32829 </cell>
32830 </row>
32831 <row topline="true">
32832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32833 \begin_inset Text
32834
32835 \begin_layout Standard
32836 uCsim
32837 \begin_inset LatexCommand index
32838 name "uCsim"
32839
32840 \end_inset
32841
32842  Software simulator for microcontrollers
32843 \end_layout
32844
32845 \end_inset
32846 </cell>
32847 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32848 \begin_inset Text
32849
32850 \begin_layout Standard
32851
32852 \family roman
32853 \series medium
32854 \shape up
32855 \size normal
32856 \emph off
32857 \bar no
32858 \noun off
32859 \color none
32860 sdcc/sim/ucsim/doc
32861 \family default
32862 \series default
32863 \shape default
32864 \size default
32865 \emph default
32866 \bar default
32867 \noun default
32868 /index.html 
32869 \emph on
32870 \InsetSpace ~
32871 \InsetSpace ~
32872 \InsetSpace ~
32873
32874 \hfill
32875 online at:
32876 \emph default
32877
32878 \newline
32879
32880 \begin_inset LatexCommand url
32881 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html"
32882
32883 \end_inset
32884
32885
32886 \end_layout
32887
32888 \end_inset
32889 </cell>
32890 </row>
32891 <row topline="true">
32892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32893 \begin_inset Text
32894
32895 \begin_layout Standard
32896 Temporary notes on the pic16
32897 \begin_inset LatexCommand index
32898 name "PIC16"
32899
32900 \end_inset
32901
32902  port
32903 \end_layout
32904
32905 \end_inset
32906 </cell>
32907 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32908 \begin_inset Text
32909
32910 \begin_layout Standard
32911 sdcc/src/pic16/NOTES 
32912 \emph on
32913 \InsetSpace ~
32914 \InsetSpace ~
32915 \InsetSpace ~
32916
32917 \hfill
32918 online at:
32919 \newline
32920
32921 \emph default
32922
32923 \begin_inset LatexCommand url
32924 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES"
32925
32926 \end_inset
32927
32928
32929 \end_layout
32930
32931 \end_inset
32932 </cell>
32933 </row>
32934 <row topline="true" bottomline="true">
32935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32936 \begin_inset Text
32937
32938 \begin_layout Standard
32939 SDCC internal documentation (debugging file format)
32940 \end_layout
32941
32942 \end_inset
32943 </cell>
32944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32945 \begin_inset Text
32946
32947 \begin_layout Standard
32948 sdcc/doc/
32949 \family roman
32950 \series medium
32951 \shape up
32952 \size normal
32953 \emph off
32954 \bar no
32955 \noun off
32956 \color none
32957 cdbfileformat.pd
32958 \family default
32959 \series default
32960 \shape default
32961 \size default
32962 \emph default
32963 \bar default
32964 \noun default
32965
32966 \emph on
32967 \InsetSpace ~
32968 \InsetSpace ~
32969 \InsetSpace ~
32970
32971 \hfill
32972 online at:
32973 \emph default
32974
32975 \newline
32976
32977 \begin_inset LatexCommand url
32978 target "http://sdcc.sourceforge.net/doc/cdbfileformat.pdf"
32979
32980 \end_inset
32981
32982
32983 \end_layout
32984
32985 \end_inset
32986 </cell>
32987 </row>
32988 </lyxtabular>
32989
32990 \end_inset
32991
32992
32993 \newline
32994
32995 \end_layout
32996
32997 \begin_layout Section
32998 Related open source tools
32999 \begin_inset LatexCommand label
33000 name "sec:Related-open-source-tools"
33001
33002 \end_inset
33003
33004
33005 \begin_inset LatexCommand index
33006 name "Related tools"
33007
33008 \end_inset
33009
33010
33011 \end_layout
33012
33013 \begin_layout Standard
33014 \align left
33015 \begin_inset Tabular
33016 <lyxtabular version="3" rows="16" columns="3">
33017 <features>
33018 <column alignment="left" valignment="top" leftline="true" width="0pt">
33019 <column alignment="block" valignment="top" leftline="true" width="30line%">
33020 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
33021 <row topline="true" bottomline="true">
33022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33023 \begin_inset Text
33024
33025 \begin_layout Standard
33026
33027 \series bold
33028 Name
33029 \end_layout
33030
33031 \end_inset
33032 </cell>
33033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33034 \begin_inset Text
33035
33036 \begin_layout Standard
33037
33038 \series bold
33039 Purpose
33040 \end_layout
33041
33042 \end_inset
33043 </cell>
33044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33045 \begin_inset Text
33046
33047 \begin_layout Standard
33048
33049 \series bold
33050 Where to get
33051 \end_layout
33052
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 \begin_layout Standard
33061 gpsim
33062 \begin_inset LatexCommand index
33063 name "gpsim (pic simulator)"
33064
33065 \end_inset
33066
33067
33068 \end_layout
33069
33070 \end_inset
33071 </cell>
33072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33073 \begin_inset Text
33074
33075 \begin_layout Standard
33076 PIC simulator
33077 \end_layout
33078
33079 \end_inset
33080 </cell>
33081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33082 \begin_inset Text
33083
33084 \begin_layout Standard
33085 \begin_inset LatexCommand url
33086 target "http://www.dattalo.com/gnupic/gpsim.html"
33087
33088 \end_inset
33089
33090
33091 \end_layout
33092
33093 \end_inset
33094 </cell>
33095 </row>
33096 <row topline="true">
33097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33098 \begin_inset Text
33099
33100 \begin_layout Standard
33101 gputils
33102 \begin_inset LatexCommand index
33103 name "gputils (pic tools)"
33104
33105 \end_inset
33106
33107
33108 \end_layout
33109
33110 \end_inset
33111 </cell>
33112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33113 \begin_inset Text
33114
33115 \begin_layout Standard
33116 GNU PIC utilities
33117 \end_layout
33118
33119 \end_inset
33120 </cell>
33121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33122 \begin_inset Text
33123
33124 \begin_layout Standard
33125 \begin_inset LatexCommand url
33126 target "http://sourceforge.net/projects/gputils"
33127
33128 \end_inset
33129
33130
33131 \end_layout
33132
33133 \end_inset
33134 </cell>
33135 </row>
33136 <row topline="true">
33137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33138 \begin_inset Text
33139
33140 \begin_layout Standard
33141 flP5
33142 \end_layout
33143
33144 \end_inset
33145 </cell>
33146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33147 \begin_inset Text
33148
33149 \begin_layout Standard
33150 PIC programmer
33151 \end_layout
33152
33153 \end_inset
33154 </cell>
33155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33156 \begin_inset Text
33157
33158 \begin_layout Standard
33159 \begin_inset LatexCommand url
33160 target "http://freshmeat.net/projects/flp5/"
33161
33162 \end_inset
33163
33164
33165 \end_layout
33166
33167 \end_inset
33168 </cell>
33169 </row>
33170 <row topline="true">
33171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33172 \begin_inset Text
33173
33174 \begin_layout Standard
33175 ec2drv/newcdb
33176 \end_layout
33177
33178 \end_inset
33179 </cell>
33180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33181 \begin_inset Text
33182
33183 \begin_layout Standard
33184 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
33185  (Unix only)
33186 \end_layout
33187
33188 \end_inset
33189 </cell>
33190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33191 \begin_inset Text
33192
33193 \begin_layout Standard
33194 \begin_inset LatexCommand url
33195 target "http://sourceforge.net/projects/ec2drv"
33196
33197 \end_inset
33198
33199
33200 \end_layout
33201
33202 \end_inset
33203 </cell>
33204 </row>
33205 <row topline="true">
33206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33207 \begin_inset Text
33208
33209 \begin_layout Standard
33210 indent
33211 \begin_inset LatexCommand index
33212 name "indent (source formatting tool)"
33213
33214 \end_inset
33215
33216
33217 \end_layout
33218
33219 \end_inset
33220 </cell>
33221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33222 \begin_inset Text
33223
33224 \begin_layout Standard
33225 Formats C source - Master of the white spaces
33226 \end_layout
33227
33228 \end_inset
33229 </cell>
33230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33231 \begin_inset Text
33232
33233 \begin_layout Standard
33234 \begin_inset LatexCommand url
33235 target "http://directory.fsf.org/GNU/indent.html"
33236
33237 \end_inset
33238
33239
33240 \end_layout
33241
33242 \end_inset
33243 </cell>
33244 </row>
33245 <row topline="true">
33246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33247 \begin_inset Text
33248
33249 \begin_layout Standard
33250 srecord
33251 \begin_inset LatexCommand index
33252 name "srecord (bin, hex, ... tool)"
33253
33254 \end_inset
33255
33256
33257 \end_layout
33258
33259 \end_inset
33260 </cell>
33261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33262 \begin_inset Text
33263
33264 \begin_layout Standard
33265 Object file conversion, checksumming, ...
33266 \end_layout
33267
33268 \end_inset
33269 </cell>
33270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33271 \begin_inset Text
33272
33273 \begin_layout Standard
33274 \begin_inset LatexCommand url
33275 target "http://sourceforge.net/projects/srecord"
33276
33277 \end_inset
33278
33279
33280 \end_layout
33281
33282 \end_inset
33283 </cell>
33284 </row>
33285 <row topline="true">
33286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33287 \begin_inset Text
33288
33289 \begin_layout Standard
33290 objdump
33291 \begin_inset LatexCommand index
33292 name "objdump (tool)"
33293
33294 \end_inset
33295
33296
33297 \end_layout
33298
33299 \end_inset
33300 </cell>
33301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33302 \begin_inset Text
33303
33304 \begin_layout Standard
33305 Object file conversion, ...
33306 \end_layout
33307
33308 \end_inset
33309 </cell>
33310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33311 \begin_inset Text
33312
33313 \begin_layout Standard
33314 Part of binutils (should be there anyway)
33315 \end_layout
33316
33317 \end_inset
33318 </cell>
33319 </row>
33320 <row topline="true">
33321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33322 \begin_inset Text
33323
33324 \begin_layout Standard
33325 cmon51
33326 \end_layout
33327
33328 \end_inset
33329 </cell>
33330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33331 \begin_inset Text
33332
33333 \begin_layout Standard
33334 8051 monitor (hex up-/download, single step, disassemble)
33335 \end_layout
33336
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 \begin_layout Standard
33343 \begin_inset LatexCommand url
33344 target "http://sourceforge.net/projects/cmon51"
33345
33346 \end_inset
33347
33348
33349 \end_layout
33350
33351 \end_inset
33352 </cell>
33353 </row>
33354 <row topline="true">
33355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33356 \begin_inset Text
33357
33358 \begin_layout Standard
33359 doxygen
33360 \begin_inset LatexCommand index
33361 name "doxygen (source documentation tool)"
33362
33363 \end_inset
33364
33365
33366 \end_layout
33367
33368 \end_inset
33369 </cell>
33370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33371 \begin_inset Text
33372
33373 \begin_layout Standard
33374 Source code documentation system
33375 \end_layout
33376
33377 \end_inset
33378 </cell>
33379 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33380 \begin_inset Text
33381
33382 \begin_layout Standard
33383 \begin_inset LatexCommand url
33384 target "http://www.doxygen.org"
33385
33386 \end_inset
33387
33388
33389 \end_layout
33390
33391 \end_inset
33392 </cell>
33393 </row>
33394 <row topline="true">
33395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33396 \begin_inset Text
33397
33398 \begin_layout Standard
33399 kdevelop
33400 \end_layout
33401
33402 \end_inset
33403 </cell>
33404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33405 \begin_inset Text
33406
33407 \begin_layout Standard
33408 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
33409 \end_layout
33410
33411 \end_inset
33412 </cell>
33413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33414 \begin_inset Text
33415
33416 \begin_layout Standard
33417 \begin_inset LatexCommand url
33418 target "http://www.kdevelop.org"
33419
33420 \end_inset
33421
33422
33423 \end_layout
33424
33425 \end_inset
33426 </cell>
33427 </row>
33428 <row topline="true">
33429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33430 \begin_inset Text
33431
33432 \begin_layout Standard
33433 paulmon
33434 \end_layout
33435
33436 \end_inset
33437 </cell>
33438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33439 \begin_inset Text
33440
33441 \begin_layout Standard
33442 8051 monitor (hex up-/download, single step, disassemble)
33443 \end_layout
33444
33445 \end_inset
33446 </cell>
33447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33448 \begin_inset Text
33449
33450 \begin_layout Standard
33451 \begin_inset LatexCommand url
33452 target "http://www.pjrc.com/tech/8051/paulmon2.html"
33453
33454 \end_inset
33455
33456
33457 \end_layout
33458
33459 \end_inset
33460 </cell>
33461 </row>
33462 <row topline="true">
33463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33464 \begin_inset Text
33465
33466 \begin_layout Standard
33467 splint
33468 \begin_inset LatexCommand index
33469 name "splint (syntax checking tool)"
33470
33471 \end_inset
33472
33473
33474 \end_layout
33475
33476 \end_inset
33477 </cell>
33478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33479 \begin_inset Text
33480
33481 \begin_layout Standard
33482 Statically checks c sources (see 
33483 \begin_inset LatexCommand ref
33484 reference "lyx:more-pedantic-SPLINT"
33485
33486 \end_inset
33487
33488 )
33489 \end_layout
33490
33491 \end_inset
33492 </cell>
33493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33494 \begin_inset Text
33495
33496 \begin_layout Standard
33497 \begin_inset LatexCommand url
33498 target "http://www.splint.org"
33499
33500 \end_inset
33501
33502
33503 \end_layout
33504
33505 \end_inset
33506 </cell>
33507 </row>
33508 <row topline="true" bottomline="true">
33509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33510 \begin_inset Text
33511
33512 \begin_layout Standard
33513 ddd
33514 \begin_inset LatexCommand index
33515 name "DDD (debugger)"
33516
33517 \end_inset
33518
33519
33520 \end_layout
33521
33522 \end_inset
33523 </cell>
33524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33525 \begin_inset Text
33526
33527 \begin_layout Standard
33528 Debugger, serves nicely as GUI to SDCDB
33529 \begin_inset LatexCommand index
33530 name "SDCDB (debugger)"
33531
33532 \end_inset
33533
33534  (Unix only)
33535 \end_layout
33536
33537 \end_inset
33538 </cell>
33539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33540 \begin_inset Text
33541
33542 \begin_layout Standard
33543 \begin_inset LatexCommand url
33544 target "http://www.gnu.org/software/ddd/"
33545
33546 \end_inset
33547
33548
33549 \end_layout
33550
33551 \end_inset
33552 </cell>
33553 </row>
33554 <row bottomline="true">
33555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33556 \begin_inset Text
33557
33558 \begin_layout Standard
33559 d52
33560 \begin_inset LatexCommand index
33561 name "d52"
33562
33563 \end_inset
33564
33565
33566 \begin_inset LatexCommand index
33567 name "d52 (disassembler)"
33568
33569 \end_inset
33570
33571
33572 \end_layout
33573
33574 \end_inset
33575 </cell>
33576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33577 \begin_inset Text
33578
33579 \begin_layout Standard
33580 Disassembler, can count instruction cycles
33581 \begin_inset LatexCommand index
33582 name "instruction cycles (count)"
33583
33584 \end_inset
33585
33586 , use with options -pnd
33587 \end_layout
33588
33589 \end_inset
33590 </cell>
33591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33592 \begin_inset Text
33593
33594 \begin_layout Standard
33595 \begin_inset LatexCommand url
33596 target "http://www.8052.com/users/disasm/"
33597
33598 \end_inset
33599
33600
33601 \end_layout
33602
33603 \end_inset
33604 </cell>
33605 </row>
33606 <row bottomline="true">
33607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33608 \begin_inset Text
33609
33610 \begin_layout Standard
33611 cmake
33612 \begin_inset LatexCommand index
33613 name "cmake"
33614
33615 \end_inset
33616
33617
33618 \end_layout
33619
33620 \end_inset
33621 </cell>
33622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33623 \begin_inset Text
33624
33625 \begin_layout Standard
33626 Cross platform build system, generates Makefiles
33627 \begin_inset LatexCommand index
33628 name "Makefile"
33629
33630 \end_inset
33631
33632  and project workspaces
33633 \begin_inset LatexCommand index
33634 name "project workspace"
33635
33636 \end_inset
33637
33638
33639 \end_layout
33640
33641 \end_inset
33642 </cell>
33643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33644 \begin_inset Text
33645
33646 \begin_layout Standard
33647 \begin_inset LatexCommand url
33648 target "http://www.cmake.org"
33649
33650 \end_inset
33651
33652  \InsetSpace ~
33653 \InsetSpace ~
33654 \InsetSpace ~
33655 \InsetSpace ~
33656 and a dedicated wiki entry: 
33657 \begin_inset LatexCommand url
33658 target "http://www.cmake.org/Wiki/CmakeSdcc"
33659
33660 \end_inset
33661
33662
33663 \end_layout
33664
33665 \end_inset
33666 </cell>
33667 </row>
33668 </lyxtabular>
33669
33670 \end_inset
33671
33672
33673 \newline
33674
33675 \end_layout
33676
33677 \begin_layout Section
33678 Related documentation / recommended reading
33679 \end_layout
33680
33681 \begin_layout Standard
33682 \align left
33683 \begin_inset Tabular
33684 <lyxtabular version="3" rows="7" columns="3">
33685 <features>
33686 <column alignment="left" valignment="top" leftline="true" width="0pt">
33687 <column alignment="left" valignment="top" leftline="true" width="0">
33688 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
33689 <row topline="true" bottomline="true">
33690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33691 \begin_inset Text
33692
33693 \begin_layout Standard
33694
33695 \series bold
33696 Name
33697 \end_layout
33698
33699 \end_inset
33700 </cell>
33701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33702 \begin_inset Text
33703
33704 \begin_layout Standard
33705
33706 \series bold
33707 Subject / Title
33708 \end_layout
33709
33710 \end_inset
33711 </cell>
33712 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33713 \begin_inset Text
33714
33715 \begin_layout Standard
33716
33717 \series bold
33718 Where to get
33719 \end_layout
33720
33721 \end_inset
33722 </cell>
33723 </row>
33724 <row topline="true">
33725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33726 \begin_inset Text
33727
33728 \begin_layout Standard
33729
33730 \family roman
33731 \series medium
33732 \shape up
33733 \size normal
33734 \emph off
33735 \bar no
33736 \noun off
33737 \color none
33738 c-refcard.pdf
33739 \end_layout
33740
33741 \end_inset
33742 </cell>
33743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33744 \begin_inset Text
33745
33746 \begin_layout Standard
33747 C Reference Card
33748 \begin_inset LatexCommand index
33749 name "C Reference card"
33750
33751 \end_inset
33752
33753 , 2 pages
33754 \end_layout
33755
33756 \end_inset
33757 </cell>
33758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33759 \begin_inset Text
33760
33761 \begin_layout Standard
33762 \begin_inset LatexCommand url
33763 target "http://refcards.com/refcards/c/index.html"
33764
33765 \end_inset
33766
33767
33768 \end_layout
33769
33770 \end_inset
33771 </cell>
33772 </row>
33773 <row topline="true">
33774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33775 \begin_inset Text
33776
33777 \begin_layout Standard
33778 c-faq
33779 \end_layout
33780
33781 \end_inset
33782 </cell>
33783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33784 \begin_inset Text
33785
33786 \begin_layout Standard
33787 C-FAQ
33788 \begin_inset LatexCommand index
33789 name "C FAQ"
33790
33791 \end_inset
33792
33793
33794 \end_layout
33795
33796 \end_inset
33797 </cell>
33798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33799 \begin_inset Text
33800
33801 \begin_layout Standard
33802 \begin_inset LatexCommand url
33803 target "http://www.c-faq.com"
33804
33805 \end_inset
33806
33807
33808 \end_layout
33809
33810 \end_inset
33811 </cell>
33812 </row>
33813 <row topline="true">
33814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33815 \begin_inset Text
33816
33817 \begin_layout Standard
33818 ISO/IEC 9899:TC2
33819 \end_layout
33820
33821 \end_inset
33822 </cell>
33823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33824 \begin_inset Text
33825
33826 \begin_layout Standard
33827 \begin_inset Quotes sld
33828 \end_inset
33829
33830 C-Standard
33831 \begin_inset Quotes srd
33832 \end_inset
33833
33834
33835 \end_layout
33836
33837 \end_inset
33838 </cell>
33839 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33840 \begin_inset Text
33841
33842 \begin_layout Standard
33843
33844 \size footnotesize
33845 \begin_inset LatexCommand url
33846 target "http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899"
33847
33848 \end_inset
33849
33850
33851 \end_layout
33852
33853 \end_inset
33854 </cell>
33855 </row>
33856 <row topline="true">
33857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33858 \begin_inset Text
33859
33860 \begin_layout Standard
33861 ISO/IEC DTR 18037
33862 \end_layout
33863
33864 \end_inset
33865 </cell>
33866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33867 \begin_inset Text
33868
33869 \begin_layout Standard
33870 \begin_inset Quotes sld
33871 \end_inset
33872
33873 Extensions for Embedded C
33874 \begin_inset Quotes srd
33875 \end_inset
33876
33877
33878 \end_layout
33879
33880 \end_inset
33881 </cell>
33882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33883 \begin_inset Text
33884
33885 \begin_layout Standard
33886
33887 \size footnotesize
33888 \begin_inset LatexCommand url
33889 target "http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf"
33890
33891 \end_inset
33892
33893
33894 \end_layout
33895
33896 \end_inset
33897 </cell>
33898 </row>
33899 <row topline="true">
33900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33901 \begin_inset Text
33902
33903 \begin_layout Standard
33904
33905 \end_layout
33906
33907 \end_inset
33908 </cell>
33909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33910 \begin_inset Text
33911
33912 \begin_layout Standard
33913 Latest datasheet of target CPU
33914 \end_layout
33915
33916 \end_inset
33917 </cell>
33918 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33919 \begin_inset Text
33920
33921 \begin_layout Standard
33922 vendor
33923 \end_layout
33924
33925 \end_inset
33926 </cell>
33927 </row>
33928 <row topline="true" bottomline="true">
33929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33930 \begin_inset Text
33931
33932 \begin_layout Standard
33933
33934 \end_layout
33935
33936 \end_inset
33937 </cell>
33938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33939 \begin_inset Text
33940
33941 \begin_layout Standard
33942 Revision history of datasheet
33943 \end_layout
33944
33945 \end_inset
33946 </cell>
33947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33948 \begin_inset Text
33949
33950 \begin_layout Standard
33951 vendor
33952 \end_layout
33953
33954 \end_inset
33955 </cell>
33956 </row>
33957 </lyxtabular>
33958
33959 \end_inset
33960
33961
33962 \newline
33963
33964 \end_layout
33965
33966 \begin_layout Section
33967 Application notes specifically for SDCC
33968 \end_layout
33969
33970 \begin_layout Standard
33971 SDCC makes no claims about the completeness of this list and about up-to-datenes
33972 s or correctness of the application notes
33973 \begin_inset LatexCommand index
33974 name "Application notes"
33975
33976 \end_inset
33977
33978 .
33979 \end_layout
33980
33981 \begin_layout Standard
33982 \align left
33983
33984 \size footnotesize
33985 \begin_inset Tabular
33986 <lyxtabular version="3" rows="7" columns="3">
33987 <features>
33988 <column alignment="block" valignment="top" leftline="true" width="17col%">
33989 <column alignment="block" valignment="top" leftline="true" width="27col%">
33990 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
33991 <row topline="true" bottomline="true">
33992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33993 \begin_inset Text
33994
33995 \begin_layout Standard
33996
33997 \series bold
33998 \size footnotesize
33999 Vendor
34000 \end_layout
34001
34002 \end_inset
34003 </cell>
34004 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
34005 \begin_inset Text
34006
34007 \begin_layout Standard
34008
34009 \series bold
34010 \size footnotesize
34011 Subject / Title
34012 \end_layout
34013
34014 \end_inset
34015 </cell>
34016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34017 \begin_inset Text
34018
34019 \begin_layout Standard
34020
34021 \series bold
34022 \size footnotesize
34023 Where to get
34024 \end_layout
34025
34026 \end_inset
34027 </cell>
34028 </row>
34029 <row topline="true">
34030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34031 \begin_inset Text
34032
34033 \begin_layout Standard
34034
34035 \size footnotesize
34036 Maxim / Dallas
34037 \end_layout
34038
34039 \end_inset
34040 </cell>
34041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34042 \begin_inset Text
34043
34044 \begin_layout Standard
34045
34046 \size footnotesize
34047 Using the SDCC Compiler for the DS80C400
34048 \begin_inset LatexCommand index
34049 name "DS80C400"
34050
34051 \end_inset
34052
34053
34054 \end_layout
34055
34056 \end_inset
34057 </cell>
34058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34059 \begin_inset Text
34060
34061 \begin_layout Standard
34062
34063 \size footnotesize
34064 \begin_inset LatexCommand url
34065 target "http://pdfserv.maxim-ic.com/en/an/AN3346.pdf"
34066
34067 \end_inset
34068
34069
34070 \end_layout
34071
34072 \end_inset
34073 </cell>
34074 </row>
34075 <row topline="true">
34076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34077 \begin_inset Text
34078
34079 \begin_layout Standard
34080
34081 \size footnotesize
34082 Maxim / Dallas
34083 \end_layout
34084
34085 \end_inset
34086 </cell>
34087 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
34088 \begin_inset Text
34089
34090 \begin_layout Standard
34091
34092 \size footnotesize
34093 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
34094 \begin_inset LatexCommand index
34095 name "DS89C4x0"
34096
34097 \end_inset
34098
34099  Family of Microcontrollers
34100 \end_layout
34101
34102 \end_inset
34103 </cell>
34104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34105 \begin_inset Text
34106
34107 \begin_layout Standard
34108
34109 \size footnotesize
34110 \begin_inset LatexCommand url
34111 target "http://pdfserv.maxim-ic.com/en/an/AN3477.pdf"
34112
34113 \end_inset
34114
34115
34116 \end_layout
34117
34118 \end_inset
34119 </cell>
34120 </row>
34121 <row topline="true">
34122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34123 \begin_inset Text
34124
34125 \begin_layout Standard
34126
34127 \size footnotesize
34128 Silicon Laboratories / Cygnal
34129 \end_layout
34130
34131 \end_inset
34132 </cell>
34133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34134 \begin_inset Text
34135
34136 \begin_layout Standard
34137
34138 \size footnotesize
34139 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
34140 \begin_inset LatexCommand index
34141 name "IDE"
34142
34143 \end_inset
34144
34145
34146 \end_layout
34147
34148 \end_inset
34149 </cell>
34150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34151 \begin_inset Text
34152
34153 \begin_layout Standard
34154
34155 \size footnotesize
34156 \begin_inset LatexCommand url
34157 target "http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf"
34158
34159 \end_inset
34160
34161
34162 \end_layout
34163
34164 \end_inset
34165 </cell>
34166 </row>
34167 <row topline="true">
34168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34169 \begin_inset Text
34170
34171 \begin_layout Standard
34172
34173 \size footnotesize
34174 Ramtron / Goal Semiconductor
34175 \end_layout
34176
34177 \end_inset
34178 </cell>
34179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34180 \begin_inset Text
34181
34182 \begin_layout Standard
34183
34184 \size footnotesize
34185 Interfacing SDCC to Syn and Textpad
34186 \end_layout
34187
34188 \end_inset
34189 </cell>
34190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34191 \begin_inset Text
34192
34193 \begin_layout Standard
34194
34195 \size footnotesize
34196 \begin_inset LatexCommand url
34197 target "http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp"
34198
34199 \end_inset
34200
34201
34202 \end_layout
34203
34204 \end_inset
34205 </cell>
34206 </row>
34207 <row topline="true">
34208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34209 \begin_inset Text
34210
34211 \begin_layout Standard
34212
34213 \size footnotesize
34214 Ramtron / Goal Semiconductor
34215 \end_layout
34216
34217 \end_inset
34218 </cell>
34219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34220 \begin_inset Text
34221
34222 \begin_layout Standard
34223
34224 \size footnotesize
34225 Installing and Configuring SDCC and Crimson Editor 
34226 \end_layout
34227
34228 \end_inset
34229 </cell>
34230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34231 \begin_inset Text
34232
34233 \begin_layout Standard
34234
34235 \size footnotesize
34236 \begin_inset LatexCommand url
34237 target "http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp"
34238
34239 \end_inset
34240
34241
34242 \end_layout
34243
34244 \end_inset
34245 </cell>
34246 </row>
34247 <row topline="true" bottomline="true">
34248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34249 \begin_inset Text
34250
34251 \begin_layout Standard
34252
34253 \size footnotesize
34254 Texas Instruments
34255 \end_layout
34256
34257 \end_inset
34258 </cell>
34259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34260 \begin_inset Text
34261
34262 \begin_layout Standard
34263
34264 \size footnotesize
34265 MSC12xx Programming with SDCC
34266 \end_layout
34267
34268 \end_inset
34269 </cell>
34270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34271 \begin_inset Text
34272
34273 \begin_layout Standard
34274
34275 \size footnotesize
34276 \begin_inset LatexCommand url
34277 target "http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf"
34278
34279 \end_inset
34280
34281
34282 \end_layout
34283
34284 \end_inset
34285 </cell>
34286 </row>
34287 </lyxtabular>
34288
34289 \end_inset
34290
34291
34292 \end_layout
34293
34294 \begin_layout Section
34295 Some Questions
34296 \end_layout
34297
34298 \begin_layout Standard
34299 Some questions answered, some pointers given - it might be time to in turn
34300  ask 
34301 \emph on
34302 you
34303 \emph default
34304  some questions: 
34305 \end_layout
34306
34307 \begin_layout Itemize
34308 can you solve your project with the selected microcontroller? Would you
34309  find out early or rather late that your target is too small/slow/whatever?
34310  Can you switch to a slightly better device if it doesn't fit?
34311 \end_layout
34312
34313 \begin_layout Itemize
34314 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
34315  and/or another programming language be more adequate? Would an operating
34316  system on the target device help?
34317 \end_layout
34318
34319 \begin_layout Itemize
34320 if you solved the problem, will the marketing department be happy?
34321 \end_layout
34322
34323 \begin_layout Itemize
34324 if the marketing department is happy, will customers be happy?
34325 \end_layout
34326
34327 \begin_layout Itemize
34328 if you're the project manager, marketing department and maybe even the customer
34329  in one person, have you tried to see the project from the outside?
34330 \end_layout
34331
34332 \begin_layout Itemize
34333 is the project done if you think it is done? Or is just that other interface/pro
34334 tocol/feature/configuration/option missing? How about website, manual(s),
34335  internationali(z|s)ation, packaging, labels, 2nd source for components,
34336  electromagnetic compatability/interference, documentation for production,
34337  production test software, update mechanism, patent issues?
34338 \end_layout
34339
34340 \begin_layout Itemize
34341 is your project adequately positioned in that magic triangle: fame, fortune,
34342  fun?
34343 \end_layout
34344
34345 \begin_layout Standard
34346 Maybe not all answers to these questions are known and some answers may
34347  even be 
34348 \emph on
34349 no
34350 \emph default
34351 , nevertheless knowing these questions may help you to avoid burnout
34352 \begin_inset Foot
34353 status open
34354
34355 \begin_layout Standard
34356 burnout is bad for electronic devices, programmers and motorcycle tyres
34357 \end_layout
34358
34359 \end_inset
34360
34361 .
34362  Chances are you didn't want to hear some of them...
34363 \end_layout
34364
34365 \begin_layout Chapter
34366 Support
34367 \begin_inset LatexCommand index
34368 name "Support"
34369
34370 \end_inset
34371
34372
34373 \end_layout
34374
34375 \begin_layout Standard
34376 SDCC has grown to be a large project.
34377  The compiler alone (without the preprocessor, assembler and linker) is
34378  well over 150,000 lines of code (blank stripped).
34379  The open source nature of this project is a key to its continued growth
34380  and support.
34381  You gain the benefit and support of many active software developers and
34382  end users.
34383  Is SDCC perfect? No, that's why we need your help.
34384  The developers take pride in fixing reported bugs.
34385  You can help by reporting the bugs and helping other SDCC users.
34386  There are lots of ways to contribute, and we encourage you to take part
34387  in making SDCC a great software package.
34388  
34389 \end_layout
34390
34391 \begin_layout Standard
34392 The SDCC project is hosted on the SDCC sourceforge site at 
34393 \begin_inset LatexCommand htmlurl
34394 target "http://sourceforge.net/projects/sdcc"
34395
34396 \end_inset
34397
34398 .
34399  You'll find the complete set of mailing lists
34400 \begin_inset LatexCommand index
34401 name "Mailing list(s)"
34402
34403 \end_inset
34404
34405 , forums, bug reporting system, patch submission
34406 \begin_inset LatexCommand index
34407 name "Patch submission"
34408
34409 \end_inset
34410
34411  system, download
34412 \begin_inset LatexCommand index
34413 name "download"
34414
34415 \end_inset
34416
34417  area and Subversion code repository
34418 \begin_inset LatexCommand index
34419 name "Subversion code repository"
34420
34421 \end_inset
34422
34423  there.
34424 \end_layout
34425
34426 \begin_layout Section
34427 Reporting Bugs
34428 \begin_inset LatexCommand index
34429 name "Bug reporting"
34430
34431 \end_inset
34432
34433
34434 \begin_inset LatexCommand index
34435 name "Reporting bugs"
34436
34437 \end_inset
34438
34439
34440 \end_layout
34441
34442 \begin_layout Standard
34443 The recommended way of reporting bugs is using the infrastructure of the
34444  sourceforge site.
34445  You can follow the status of bug reports there and have an overview about
34446  the known bugs.
34447 \end_layout
34448
34449 \begin_layout Standard
34450 Bug reports are automatically forwarded to the developer mailing list and
34451  will be fixed ASAP.
34452  When reporting a bug, it is very useful to include a small test program
34453  (the smaller the better) which reproduces the problem.
34454  If you can isolate the problem by looking at the generated assembly code,
34455  this can be very helpful.
34456  Compiling your program with the -
34457 \begin_inset ERT
34458 status collapsed
34459
34460 \begin_layout Standard
34461
34462
34463 \backslash
34464 /
34465 \end_layout
34466
34467 \end_inset
34468
34469 -dumpall
34470 \begin_inset LatexCommand index
34471 name "-\\/-dumpall"
34472
34473 \end_inset
34474
34475  option can sometimes be useful in locating optimization problems.
34476  When reporting a bug please make sure you:
34477 \end_layout
34478
34479 \begin_layout Enumerate
34480 Attach the code you are compiling with SDCC.
34481  
34482 \end_layout
34483
34484 \begin_layout Enumerate
34485 Specify the exact command you use to run SDCC, or attach your Makefile.
34486  
34487 \end_layout
34488
34489 \begin_layout Enumerate
34490 Specify the SDCC version (type "
34491 \family sans
34492 \series bold
34493 sdcc -v
34494 \family default
34495 \series default
34496 "), your platform, and operating system.
34497  
34498 \end_layout
34499
34500 \begin_layout Enumerate
34501 Provide an exact copy of any error message or incorrect output.
34502  
34503 \end_layout
34504
34505 \begin_layout Enumerate
34506 Put something meaningful in the subject of your message.
34507 \end_layout
34508
34509 \begin_layout Standard
34510 Please attempt to include these 5 important parts, as applicable, in all
34511  requests for support or when reporting any problems or bugs with SDCC.
34512  Though this will make your message lengthy, it will greatly improve your
34513  chance that SDCC users and developers will be able to help you.
34514  Some SDCC developers are frustrated by bug reports without code provided
34515  that they can use to reproduce and ultimately fix the problem, so please
34516  be sure to provide sample code if you are reporting a bug! 
34517 \end_layout
34518
34519 \begin_layout Standard
34520 Please have a short check that you are using a recent version of SDCC and
34521  the bug is not yet known.
34522  This is the link for reporting bugs: 
34523 \begin_inset LatexCommand htmlurl
34524 target "http://sourceforge.net/tracker/?group_id=599&atid=100599"
34525
34526 \end_inset
34527
34528 .
34529  With SDCC on average having more than 200 downloads
34530 \begin_inset LatexCommand index
34531 name "download"
34532
34533 \end_inset
34534
34535  on sourceforge per day
34536 \begin_inset Foot
34537 status open
34538
34539 \begin_layout Standard
34540 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
34541  between 2002 and 2005.
34542  This does not include other methods of distribution.
34543 \end_layout
34544
34545 \end_inset
34546
34547  there must be some users.
34548  So it's not exactly easy to find a new bug.
34549  If you find one we need it: 
34550 \emph on
34551 reporting bugs is good
34552 \emph default
34553 .
34554 \end_layout
34555
34556 \begin_layout Section
34557 Requesting Features
34558 \begin_inset LatexCommand label
34559 name "sub:Requesting-Features"
34560
34561 \end_inset
34562
34563
34564 \begin_inset LatexCommand index
34565 name "Feature request"
34566
34567 \end_inset
34568
34569
34570 \begin_inset LatexCommand index
34571 name "Requesting features"
34572
34573 \end_inset
34574
34575
34576 \end_layout
34577
34578 \begin_layout Standard
34579 Like bug reports feature requests are forwarded to the developer mailing
34580  list.
34581  This is the link for requesting features: 
34582 \begin_inset LatexCommand htmlurl
34583 target "http://sourceforge.net/tracker/?group_id=599&atid=350599"
34584
34585 \end_inset
34586
34587 .
34588 \end_layout
34589
34590 \begin_layout Section
34591 Submitting patches
34592 \end_layout
34593
34594 \begin_layout Standard
34595 Like bug reports contributed patches are forwarded to the developer mailing
34596  list.
34597  This is the link for submitting patches
34598 \begin_inset LatexCommand index
34599 name "Patch submission"
34600
34601 \end_inset
34602
34603
34604 \begin_inset LatexCommand url
34605 target "http://sourceforge.net/tracker/?group_id=599&atid=300599"
34606
34607 \end_inset
34608
34609 .
34610 \end_layout
34611
34612 \begin_layout Standard
34613 You need to specify some parameters to the 
34614 \family typewriter
34615 diff
34616 \family default
34617  command for the patches to be useful.
34618  If you modified more than one file a patch created f.e.
34619  with 
34620 \family sans
34621 \series bold
34622
34623 \begin_inset Quotes sld
34624 \end_inset
34625
34626 diff -Naur unmodified_directory modified_directory >my_changes.patch
34627 \begin_inset Quotes srd
34628 \end_inset
34629
34630
34631 \family default
34632 \series default
34633  will be fine, otherwise 
34634 \family sans
34635 \series bold
34636
34637 \begin_inset Quotes sld
34638 \end_inset
34639
34640 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
34641 \begin_inset Quotes srd
34642 \end_inset
34643
34644
34645 \family default
34646 \series default
34647  will do.
34648 \end_layout
34649
34650 \begin_layout Section
34651 Getting Help
34652 \end_layout
34653
34654 \begin_layout Standard
34655 These links should take you directly to the 
34656 \begin_inset LatexCommand url
34657 name "Mailing lists"
34658 target "http://sourceforge.net/mail/?group_id=599"
34659
34660 \end_inset
34661
34662
34663 \begin_inset Foot
34664 status open
34665
34666 \begin_layout Standard
34667 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
34668  automated messages (mid 2003)
34669 \end_layout
34670
34671 \end_inset
34672
34673  and the 
34674 \begin_inset LatexCommand url
34675 name "Forums"
34676 target "http://sourceforge.net/forum/?group_id=599"
34677
34678 \end_inset
34679
34680 , lists
34681 \begin_inset LatexCommand index
34682 name "Mailing list(s)"
34683
34684 \end_inset
34685
34686  and forums are archived and searchable so if you are lucky someone already
34687  had a similar problem.
34688  While mails to the lists themselves are delivered promptly their web front
34689  end on sourceforge sometimes shows a severe time lag (up to several weeks),
34690  if you're seriously using SDCC please consider subscribing to the lists.
34691 \end_layout
34692
34693 \begin_layout Section
34694 ChangeLog
34695 \end_layout
34696
34697 \begin_layout Standard
34698 You can follow the status of the Subversion version
34699 \begin_inset LatexCommand index
34700 name "version"
34701
34702 \end_inset
34703
34704  of SDCC by watching the Changelog
34705 \begin_inset LatexCommand index
34706 name "Changelog"
34707
34708 \end_inset
34709
34710  in the Subversion repository
34711 \size footnotesize
34712  
34713 \begin_inset LatexCommand htmlurl
34714 target "http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog"
34715
34716 \end_inset
34717
34718 .
34719 \end_layout
34720
34721 \begin_layout Section
34722 Subversion Source Code Repository
34723 \end_layout
34724
34725 \begin_layout Standard
34726 The output of 
34727 \family sans
34728 \series bold
34729 sdcc -
34730 \family default
34731
34732 \begin_inset ERT
34733 status open
34734
34735 \begin_layout Standard
34736
34737
34738 \backslash
34739 /
34740 \end_layout
34741
34742 \end_inset
34743
34744
34745 \family sans
34746 -version
34747 \family default
34748 \series default
34749  or the filenames of the snapshot versions of SDCC include date and its
34750  Subversion
34751 \begin_inset LatexCommand index
34752 name "Subversion code repository"
34753
34754 \end_inset
34755
34756  number.
34757  Subversion allows to download the source of recent or previous versions
34758  
34759 \begin_inset LatexCommand url
34760 target "http://sourceforge.net/svn/?group_id=599"
34761
34762 \end_inset
34763
34764  (by number or by date).
34765  An on-line source code browser and detailled instructions are also available
34766  there.
34767  SDCC versions starting from 1999 up to now are available (currently the
34768  versions prior to the conversion from cvs
34769 \begin_inset LatexCommand index
34770 name "cvs|see{Subversion}"
34771
34772 \end_inset
34773
34774  to Subversion (April 2006) are either by accessible by Subversion or by
34775  cvs).
34776 \end_layout
34777
34778 \begin_layout Section
34779 Release policy
34780 \begin_inset LatexCommand index
34781 name "Release policy"
34782
34783 \end_inset
34784
34785
34786 \end_layout
34787
34788 \begin_layout Standard
34789 Historically there often were long delays between official releases and
34790  the sourceforge download area tends to get not updated at all.
34791  Excuses in the past might have referred to problems with live range analysis,
34792  but as this was fixed a while ago, the current problem is that another
34793  excuse has to be found.
34794  Kidding aside, we have to get better there! On the other hand there are
34795  daily snapshots available at 
34796 \begin_inset LatexCommand htmlurl
34797 name "snap"
34798 target "http://sdcc.sourceforge.net/snap.php"
34799
34800 \end_inset
34801
34802 , and you can always build the very last version (hopefully with many bugs
34803  fixed, and features added) from the source code available at 
34804 \begin_inset LatexCommand htmlurl
34805 name "Source"
34806 target "http://sdcc.sourceforge.net/snap.php#Source"
34807
34808 \end_inset
34809
34810 .
34811  The SDCC Wiki
34812 \begin_inset LatexCommand index
34813 name "wiki"
34814
34815 \end_inset
34816
34817
34818 \begin_inset LatexCommand index
34819 name "SDCC Wiki"
34820
34821 \end_inset
34822
34823  at 
34824 \begin_inset LatexCommand url
34825 target "http://sdcc.wiki.sourceforge.net/"
34826
34827 \end_inset
34828
34829  also holds some information about past and future releases.
34830 \end_layout
34831
34832 \begin_layout Section
34833 Examples
34834 \begin_inset LatexCommand index
34835 name "Examples"
34836
34837 \end_inset
34838
34839
34840 \end_layout
34841
34842 \begin_layout Standard
34843 You'll find some small examples in the directory 
34844 \emph on
34845 sdcc/device/examples/.
34846
34847 \emph default
34848  More examples and libraries are available at 
34849 \emph on
34850 The SDCC Open Knowledge Resource 
34851 \begin_inset LatexCommand url
34852 target "http://sdccokr.dl9sec.de/"
34853
34854 \end_inset
34855
34856
34857 \emph default
34858  web site or at 
34859 \begin_inset LatexCommand url
34860 target "http://www.pjrc.com/tech/8051/"
34861
34862 \end_inset
34863
34864 .
34865 \end_layout
34866
34867 \begin_layout Standard
34868 \begin_inset Note Note
34869 status collapsed
34870
34871 \begin_layout Standard
34872 I did insert a reference to Paul's web site here although it seems rather
34873  dedicated to a specific 8032 board (I think it's okay because it f.e.
34874  shows LCD/Harddisc interface and has a free 8051 monitor.
34875  Independent 8032 board vendors face hard competition of heavily subsidized
34876  development boards anyway).
34877 \end_layout
34878
34879 \begin_layout Standard
34880 Maybe we should include some links to real world applications.
34881  Preferably pointer to pointers (one for each architecture) so this stays
34882  manageable here?
34883 \end_layout
34884
34885 \end_inset
34886
34887
34888 \end_layout
34889
34890 \begin_layout Section
34891 Quality control
34892 \begin_inset LatexCommand label
34893 name "sec:Quality-control"
34894
34895 \end_inset
34896
34897
34898 \begin_inset LatexCommand index
34899 name "Quality control"
34900
34901 \end_inset
34902
34903
34904 \end_layout
34905
34906 \begin_layout Standard
34907 The compiler is passed through snaphot build compile and build checks.
34908  The so called 
34909 \shape italic
34910 regression tests
34911 \shape default
34912
34913 \begin_inset LatexCommand index
34914 name "Regression test"
34915
34916 \end_inset
34917
34918  check that SDCC itself compiles flawlessly on several host platforms (i386,
34919  Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
34920  and checks the quality of the code generated by SDCC by running the code
34921  for several target platforms through simulators.
34922  The regression test suite comprises more than 100 files which expand to
34923  more than 500 test cases which include more than 4500 tests.
34924  The results of these tests are published daily on SDCC's snapshot page
34925  (click on the red or green symbols on the right side of 
34926 \begin_inset LatexCommand url
34927 target "http://sdcc.sourceforge.net/snap.php"
34928
34929 \end_inset
34930
34931 ).
34932 \end_layout
34933
34934 \begin_layout Standard
34935 There is a separate document 
34936 \shape italic
34937 test_suite.pdf 
34938 \begin_inset LatexCommand index
34939 name "Test suite"
34940
34941 \end_inset
34942
34943
34944 \shape default
34945  
34946 \begin_inset LatexCommand url
34947 target "http://sdcc.sourceforge.net/doc/test_suite_spec.pdf"
34948
34949 \end_inset
34950
34951  about the regression test suite.
34952 \end_layout
34953
34954 \begin_layout Standard
34955 You'll find the test code in the directory 
34956 \shape italic
34957 sdcc/support/regression
34958 \shape default
34959 .
34960  You can run these tests manually by running 
34961 \family sans
34962 make
34963 \family default
34964  in this directory (or f.e.
34965  
34966 \family sans
34967 \series bold
34968
34969 \begin_inset Quotes sld
34970 \end_inset
34971
34972 make test-mcs51
34973 \begin_inset Quotes srd
34974 \end_inset
34975
34976
34977 \family default
34978 \series default
34979  if you don't want to run the complete tests).
34980  The test code might also be interesting if you want to look for examples
34981 \begin_inset LatexCommand index
34982 name "Examples"
34983
34984 \end_inset
34985
34986  checking corner cases of SDCC or if you plan to submit patches
34987 \begin_inset LatexCommand index
34988 name "Patch submission"
34989
34990 \end_inset
34991
34992 .
34993 \end_layout
34994
34995 \begin_layout Standard
34996 The PIC14 port uses a different set of regression tests 
34997 \begin_inset LatexCommand index
34998 name "Regression test (PIC14)"
34999
35000 \end_inset
35001
35002 , you'll find them in the directory 
35003 \shape italic
35004 sdcc/src/regression
35005 \shape default
35006 .
35007 \end_layout
35008
35009 \begin_layout Section
35010 Use of SDCC in Education
35011 \end_layout
35012
35013 \begin_layout Standard
35014 In short: 
35015 \emph on
35016 highly
35017 \emph default
35018  encouraged
35019 \begin_inset Foot
35020 status open
35021
35022 \begin_layout Standard
35023 the phrase "use in education" might evoke the association "
35024 \emph on
35025 only
35026 \emph default
35027  fit for use in education".
35028  This connotation is not intended but nevertheless risked as the licensing
35029  of SDCC makes it difficult to offer educational discounts
35030 \end_layout
35031
35032 \end_inset
35033
35034 .
35035  If your rationales are to:
35036 \end_layout
35037
35038 \begin_layout Enumerate
35039 give students a chance to understand the 
35040 \emph on
35041 complete
35042 \emph default
35043  steps of code generation
35044 \end_layout
35045
35046 \begin_layout Enumerate
35047 have a curriculum that can be extended for years.
35048  Then you could use an fpga board as target and your curriculum will seamlessly
35049  extend from logic synthesis (
35050 \begin_inset LatexCommand url
35051 name "http://www.opencores.org"
35052 target "opencores.org"
35053
35054 \end_inset
35055
35056
35057 \begin_inset LatexCommand url
35058 name "Oregano"
35059 target "http://www.oregano.at/ip/ip01.htm"
35060
35061 \end_inset
35062
35063 ), over assembly programming, to C to FPGA compilers (
35064 \begin_inset LatexCommand url
35065 name "FPGAC"
35066 target "http://sf.net/projects/fpgac"
35067
35068 \end_inset
35069
35070 ) and to C.
35071 \end_layout
35072
35073 \begin_layout Enumerate
35074 be able to insert excursions about skills like using a revision control
35075  system, submitting/applying patches, using a type-setting (as opposed to
35076  word-processing) engine LyX/LaTeX, using 
35077 \begin_inset LatexCommand url
35078 name "SourceForge"
35079 target "http://www.sf.net"
35080
35081 \end_inset
35082
35083 , following some 
35084 \begin_inset LatexCommand url
35085 name "netiquette"
35086 target "http://en.wikipedia.org/wiki/Netiquette"
35087
35088 \end_inset
35089
35090 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
35091  Source Software, CPU simulation, compiler regression tests
35092 \begin_inset LatexCommand index
35093 name "Regression test"
35094
35095 \end_inset
35096
35097 .
35098  
35099 \newline
35100 And if there should be a shortage of ideas then you can always point students
35101  to the ever-growing feature request list 
35102 \begin_inset LatexCommand htmlurl
35103 target "http://sourceforge.net/tracker/?group_id=599&atid=350599"
35104
35105 \end_inset
35106
35107 .
35108 \end_layout
35109
35110 \begin_layout Enumerate
35111 not tie students to a specific host platform and instead allow them to use
35112  a host platform of 
35113 \emph on
35114 their
35115 \emph default
35116  choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
35117  and eventually 
35118 \begin_inset LatexCommand url
35119 name "OLPC"
35120 target "http://www.laptop.org"
35121
35122 \end_inset
35123
35124 )
35125 \end_layout
35126
35127 \begin_layout Enumerate
35128 not encourage students to use illegal copies of educational software
35129 \end_layout
35130
35131 \begin_layout Enumerate
35132 be immune to licensing/availability/price changes of the chosen tool chain
35133 \end_layout
35134
35135 \begin_layout Enumerate
35136 be able to change to a new target platform without having to adopt a new
35137  tool chain
35138 \end_layout
35139
35140 \begin_layout Enumerate
35141 have complete control over and insight into the tool chain
35142 \end_layout
35143
35144 \begin_layout Enumerate
35145 make your students aware about the pros and cons of open source software
35146  development
35147 \end_layout
35148
35149 \begin_layout Enumerate
35150 give back to the public as you are probably at least partially publicly
35151  funded
35152 \end_layout
35153
35154 \begin_layout Enumerate
35155 give students a chance to publicly prove their skills and to possibly
35156  see a world wide impact
35157 \end_layout
35158
35159 \begin_layout Standard
35160 then SDCC is probably among the first choices.
35161  Well, probably SDCC might be the only choice.
35162 \newpage
35163
35164 \end_layout
35165
35166 \begin_layout Chapter
35167 SDCC Technical Data
35168 \end_layout
35169
35170 \begin_layout Section
35171 Optimizations
35172 \begin_inset LatexCommand index
35173 name "Optimizations"
35174
35175 \end_inset
35176
35177
35178 \end_layout
35179
35180 \begin_layout Standard
35181 SDCC performs a host of standard optimizations in addition to some MCU specific
35182  optimizations.
35183  
35184 \end_layout
35185
35186 \begin_layout Subsection
35187 Sub-expression Elimination
35188 \begin_inset LatexCommand index
35189 name "Subexpression elimination"
35190
35191 \end_inset
35192
35193
35194 \end_layout
35195
35196 \begin_layout Standard
35197 The compiler does local and 
35198 \emph on
35199 g
35200 \emph default
35201 lobal 
35202 \emph on
35203 c
35204 \emph default
35205 ommon 
35206 \emph on
35207 s
35208 \emph default
35209 ubexpression 
35210 \emph on
35211 e
35212 \emph default
35213 limination, e.g.: 
35214 \end_layout
35215
35216 \begin_layout Verse
35217
35218 \family typewriter
35219 i = x + y + 1; 
35220 \newline
35221 j = x + y;
35222 \end_layout
35223
35224 \begin_layout Standard
35225 will be translated to
35226 \end_layout
35227
35228 \begin_layout Verse
35229
35230 \family typewriter
35231 iTemp = x + y; 
35232 \newline
35233 i = iTemp + 1; 
35234 \newline
35235 j = iTemp;
35236 \end_layout
35237
35238 \begin_layout Standard
35239 Some subexpressions are not as obvious as the above example, e.g.:
35240 \end_layout
35241
35242 \begin_layout Verse
35243
35244 \family typewriter
35245 a->b[i].c = 10; 
35246 \newline
35247 a->b[i].d = 11;
35248 \end_layout
35249
35250 \begin_layout Standard
35251 In this case the address arithmetic a->b[i] will be computed only once;
35252  the equivalent code in C would be.
35253 \end_layout
35254
35255 \begin_layout Verse
35256
35257 \family typewriter
35258 iTemp = a->b[i]; 
35259 \newline
35260 iTemp.c = 10; 
35261 \newline
35262 iTemp.d = 11;
35263 \end_layout
35264
35265 \begin_layout Standard
35266 The compiler will try to keep these temporary variables in registers.
35267 \end_layout
35268
35269 \begin_layout Subsection
35270 Dead-Code Elimination
35271 \begin_inset LatexCommand index
35272 name "Dead-code elimination"
35273
35274 \end_inset
35275
35276
35277 \end_layout
35278
35279 \begin_layout Verse
35280
35281 \family typewriter
35282 int global;
35283 \newline
35284
35285 \newline
35286 void f () { 
35287 \newline
35288 \InsetSpace ~
35289 \InsetSpace ~
35290 int i; 
35291 \newline
35292 \InsetSpace ~
35293 \InsetSpace ~
35294 i = 1; \InsetSpace ~
35295 \InsetSpace ~
35296 \InsetSpace ~
35297 \InsetSpace ~
35298 \InsetSpace ~
35299 /* dead store */ 
35300 \newline
35301 \InsetSpace ~
35302 \InsetSpace ~
35303 global = 1;\InsetSpace ~
35304 /* dead
35305  store */ 
35306 \newline
35307 \InsetSpace ~
35308 \InsetSpace ~
35309 global = 2; 
35310 \newline
35311 \InsetSpace ~
35312 \InsetSpace ~
35313 return; 
35314 \newline
35315 \InsetSpace ~
35316 \InsetSpace ~
35317 global = 3;\InsetSpace ~
35318 /* unreachable */ 
35319 \newline
35320 }
35321 \end_layout
35322
35323 \begin_layout Standard
35324 will be changed to
35325 \end_layout
35326
35327 \begin_layout Verse
35328
35329 \family typewriter
35330 int global;
35331 \newline
35332
35333 \newline
35334 void f () {
35335 \newline
35336 \InsetSpace ~
35337 \InsetSpace ~
35338 global = 2; 
35339 \newline
35340 }
35341 \end_layout
35342
35343 \begin_layout Subsection
35344 Copy-Propagation
35345 \begin_inset LatexCommand index
35346 name "Copy propagation"
35347
35348 \end_inset
35349
35350
35351 \end_layout
35352
35353 \begin_layout Verse
35354
35355 \family typewriter
35356 int f() { 
35357 \newline
35358 \InsetSpace ~
35359 \InsetSpace ~
35360 int i, j; 
35361 \newline
35362 \InsetSpace ~
35363 \InsetSpace ~
35364 i = 10; 
35365 \newline
35366 \InsetSpace ~
35367 \InsetSpace ~
35368 j = i; 
35369 \newline
35370 \InsetSpace ~
35371 \InsetSpace ~
35372 return j; 
35373 \newline
35374 }
35375 \end_layout
35376
35377 \begin_layout Standard
35378 will be changed to 
35379 \end_layout
35380
35381 \begin_layout Verse
35382
35383 \family typewriter
35384 int f() { 
35385 \newline
35386 \InsetSpace ~
35387 \InsetSpace ~
35388 int i, j; 
35389 \newline
35390 \InsetSpace ~
35391 \InsetSpace ~
35392 i = 10; 
35393 \newline
35394 \InsetSpace ~
35395 \InsetSpace ~
35396 j = 10; 
35397 \newline
35398 \InsetSpace ~
35399 \InsetSpace ~
35400 return 10; 
35401 \newline
35402 }
35403 \end_layout
35404
35405 \begin_layout Standard
35406 Note: the dead stores created by this copy propagation will be eliminated
35407  by dead-code elimination.
35408 \end_layout
35409
35410 \begin_layout Subsection
35411 Loop Optimizations
35412 \begin_inset LatexCommand index
35413 name "Loop optimization"
35414
35415 \end_inset
35416
35417
35418 \begin_inset LatexCommand label
35419 name "sub:Loop-Optimizations"
35420
35421 \end_inset
35422
35423
35424 \end_layout
35425
35426 \begin_layout Standard
35427 Two types of loop optimizations are done by SDCC 
35428 \emph on
35429 loop invariant
35430 \emph default
35431  lifting and 
35432 \emph on
35433 strength reduction
35434 \emph default
35435  of loop induction variables.
35436  In addition to the strength reduction the optimizer marks the induction
35437  variables and the register allocator tries to keep the induction variables
35438  in registers for the duration of the loop.
35439  Because of this preference of the register allocator
35440 \begin_inset LatexCommand index
35441 name "Register allocation"
35442
35443 \end_inset
35444
35445 , loop induction optimization causes an increase in register pressure, which
35446  may cause unwanted spilling of other temporary variables into the stack
35447 \begin_inset LatexCommand index
35448 name "stack"
35449
35450 \end_inset
35451
35452  / data space.
35453  The compiler will generate a warning message when it is forced to allocate
35454  extra space either on the stack or data space.
35455  If this extra space allocation is undesirable then induction optimization
35456  can be eliminated either for the entire source file (with -
35457 \begin_inset ERT
35458 status collapsed
35459
35460 \begin_layout Standard
35461
35462
35463 \backslash
35464 /
35465 \end_layout
35466
35467 \end_inset
35468
35469 -noinduction option) or for a given function only using #pragma\InsetSpace ~
35470 noinduction
35471 \begin_inset LatexCommand index
35472 name "\\#pragma noinduction"
35473
35474 \end_inset
35475
35476 .
35477 \newline
35478
35479 \newline
35480 Loop Invariant:
35481 \end_layout
35482
35483 \begin_layout Verse
35484
35485 \family typewriter
35486 for (i = 0 ; i < 100 ; i ++) 
35487 \newline
35488 \InsetSpace ~
35489 \InsetSpace ~
35490 \InsetSpace ~
35491 \InsetSpace ~
35492 f += k + l;
35493 \end_layout
35494
35495 \begin_layout Standard
35496 changed to
35497 \end_layout
35498
35499 \begin_layout Verse
35500
35501 \family typewriter
35502 itemp = k + l; 
35503 \newline
35504 for (i = 0; i < 100; i++) 
35505 \newline
35506 \InsetSpace ~
35507 \InsetSpace ~
35508 \InsetSpace ~
35509 \InsetSpace ~
35510 f += itemp;
35511 \end_layout
35512
35513 \begin_layout Standard
35514 As mentioned previously some loop invariants are not as apparent, all static
35515  address computations are also moved out of the loop.
35516 \newline
35517
35518 \newline
35519 Strength Reduction
35520 \begin_inset LatexCommand index
35521 name "Strength reduction"
35522
35523 \end_inset
35524
35525 , this optimization substitutes an expression by a cheaper expression:
35526 \end_layout
35527
35528 \begin_layout Verse
35529
35530 \family typewriter
35531 for (i=0;i < 100; i++)
35532 \newline
35533 \InsetSpace ~
35534 \InsetSpace ~
35535 \InsetSpace ~
35536 \InsetSpace ~
35537 ar[i*5] = i*3;
35538 \end_layout
35539
35540 \begin_layout Standard
35541 changed to
35542 \end_layout
35543
35544 \begin_layout Verse
35545
35546 \family typewriter
35547 itemp1 = 0; 
35548 \newline
35549 itemp2 = 0; 
35550 \newline
35551 for (i=0;i< 100;i++) { 
35552 \newline
35553 \InsetSpace ~
35554 \InsetSpace ~
35555 \InsetSpace ~
35556 \InsetSpace ~
35557 ar[itemp1] = itemp2; 
35558 \newline
35559 \InsetSpace ~
35560 \InsetSpace ~
35561 \InsetSpace ~
35562 \InsetSpace ~
35563 itemp1
35564  += 5; 
35565 \newline
35566 \InsetSpace ~
35567 \InsetSpace ~
35568 \InsetSpace ~
35569 \InsetSpace ~
35570 itemp2 += 3; 
35571 \newline
35572 }
35573 \end_layout
35574
35575 \begin_layout Standard
35576 The more expensive multiplication
35577 \begin_inset LatexCommand index
35578 name "Multiplication"
35579
35580 \end_inset
35581
35582  is changed to a less expensive addition.
35583 \end_layout
35584
35585 \begin_layout Subsection
35586 Loop Reversing
35587 \begin_inset LatexCommand index
35588 name "Loop reversing"
35589
35590 \end_inset
35591
35592
35593 \end_layout
35594
35595 \begin_layout Standard
35596 This optimization is done to reduce the overhead of checking loop boundaries
35597  for every iteration.
35598  Some simple loops can be reversed and implemented using a 
35599 \begin_inset Quotes eld
35600 \end_inset
35601
35602 decrement and jump if not zero
35603 \begin_inset Quotes erd
35604 \end_inset
35605
35606  instruction.
35607  SDCC checks for the following criterion to determine if a loop is reversible
35608  (note: more sophisticated compilers use data-dependency analysis to make
35609  this determination, SDCC uses a more simple minded analysis).
35610 \end_layout
35611
35612 \begin_layout Itemize
35613 The 'for' loop is of the form 
35614 \newline
35615
35616 \newline
35617
35618 \family typewriter
35619 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
35620  += 1])
35621 \newline
35622 \InsetSpace ~
35623 \InsetSpace ~
35624 \InsetSpace ~
35625 \InsetSpace ~
35626 <for body>
35627 \end_layout
35628
35629 \begin_layout Itemize
35630 The <for body> does not contain 
35631 \begin_inset Quotes eld
35632 \end_inset
35633
35634 continue
35635 \begin_inset Quotes erd
35636 \end_inset
35637
35638  or 'break
35639 \begin_inset Quotes erd
35640 \end_inset
35641
35642 .
35643 \end_layout
35644
35645 \begin_layout Itemize
35646 All goto's are contained within the loop.
35647 \end_layout
35648
35649 \begin_layout Itemize
35650 No function calls within the loop.
35651 \end_layout
35652
35653 \begin_layout Itemize
35654 The loop control variable <sym> is not assigned any value within the loop
35655 \end_layout
35656
35657 \begin_layout Itemize
35658 The loop control variable does NOT participate in any arithmetic operation
35659  within the loop.
35660 \end_layout
35661
35662 \begin_layout Itemize
35663 There are NO switch statements in the loop.
35664 \end_layout
35665
35666 \begin_layout Subsection
35667 Algebraic Simplifications
35668 \end_layout
35669
35670 \begin_layout Standard
35671 SDCC does numerous algebraic simplifications, the following is a small sub-set
35672  of these optimizations.
35673 \end_layout
35674
35675 \begin_layout Verse
35676
35677 \family typewriter
35678 i = j + 0;\InsetSpace ~
35679 \InsetSpace ~
35680 \InsetSpace ~
35681 \InsetSpace ~
35682  /* changed to: */\InsetSpace ~
35683 \InsetSpace ~
35684 \InsetSpace ~
35685 \InsetSpace ~
35686  i = j; 
35687 \newline
35688 i /= 2;\InsetSpace ~
35689 \InsetSpace ~
35690 \InsetSpace ~
35691 \InsetSpace ~
35692 \InsetSpace ~
35693 \InsetSpace ~
35694 \InsetSpace ~
35695  /* changed to: */\InsetSpace ~
35696 \InsetSpace ~
35697 \InsetSpace ~
35698 \InsetSpace ~
35699  i >>= 1; 
35700 \newline
35701 i
35702  = j - j;\InsetSpace ~
35703 \InsetSpace ~
35704 \InsetSpace ~
35705 \InsetSpace ~
35706  /* changed to: */\InsetSpace ~
35707 \InsetSpace ~
35708 \InsetSpace ~
35709 \InsetSpace ~
35710  i = 0; 
35711 \newline
35712 i = j / 1;\InsetSpace ~
35713 \InsetSpace ~
35714 \InsetSpace ~
35715 \InsetSpace ~
35716  /* changed to: */\InsetSpace ~
35717 \InsetSpace ~
35718 \InsetSpace ~
35719 \InsetSpace ~
35720  i = j;
35721 \end_layout
35722
35723 \begin_layout Standard
35724 Note the subexpressions
35725 \begin_inset LatexCommand index
35726 name "Subexpression"
35727
35728 \end_inset
35729
35730  given above are generally introduced by macro expansions or as a result
35731  of copy/constant propagation.
35732 \end_layout
35733
35734 \begin_layout Subsection
35735 'switch' Statements
35736 \begin_inset LatexCommand label
35737 name "sub:'switch'-Statements"
35738
35739 \end_inset
35740
35741
35742 \begin_inset LatexCommand index
35743 name "switch statement"
35744
35745 \end_inset
35746
35747
35748 \end_layout
35749
35750 \begin_layout Standard
35751 SDCC can optimize switch statements to jump tables
35752 \begin_inset LatexCommand index
35753 name "jump tables"
35754
35755 \end_inset
35756
35757 .
35758  It makes the decision based on an estimate of the generated code size.
35759  SDCC is quite liberal in the requirements for jump table generation: 
35760 \end_layout
35761
35762 \begin_layout Itemize
35763 The labels need not be in order, and the starting number need not be one
35764  or zero, the case labels are in numerical sequence or not too many case
35765  labels are missing.
35766 \end_layout
35767
35768 \begin_deeper
35769 \begin_layout Verse
35770
35771 \family typewriter
35772 switch(i) {\InsetSpace ~
35773 \InsetSpace ~
35774 \InsetSpace ~
35775 \InsetSpace ~
35776 \InsetSpace ~
35777 \InsetSpace ~
35778 \InsetSpace ~
35779 \InsetSpace ~
35780 \InsetSpace ~
35781 \InsetSpace ~
35782 \InsetSpace ~
35783 \InsetSpace ~
35784 \InsetSpace ~
35785 \InsetSpace ~
35786 \InsetSpace ~
35787 \InsetSpace ~
35788 \InsetSpace ~
35789 \InsetSpace ~
35790 \InsetSpace ~
35791 \InsetSpace ~
35792 \InsetSpace ~
35793 \InsetSpace ~
35794 \InsetSpace ~
35795 \InsetSpace ~
35796 \InsetSpace ~
35797 \InsetSpace ~
35798 switch (i) { 
35799 \newline
35800 \InsetSpace ~
35801 \InsetSpace ~
35802 \InsetSpace ~
35803 case 4: ...\InsetSpace ~
35804 \InsetSpace ~
35805 \InsetSpace ~
35806 \InsetSpace ~
35807 \InsetSpace ~
35808 \InsetSpace ~
35809 \InsetSpace ~
35810 \InsetSpace ~
35811 \InsetSpace ~
35812 \InsetSpace ~
35813 \InsetSpace ~
35814 \InsetSpace ~
35815 \InsetSpace ~
35816 \InsetSpace ~
35817 \InsetSpace ~
35818 \InsetSpace ~
35819 \InsetSpace ~
35820 \InsetSpace ~
35821 \InsetSpace ~
35822 \InsetSpace ~
35823 \InsetSpace ~
35824 \InsetSpace ~
35825 \InsetSpace ~
35826 \InsetSpace ~
35827 \InsetSpace ~
35828 \InsetSpace ~
35829 case 0: ...
35830  
35831 \newline
35832 \InsetSpace ~
35833 \InsetSpace ~
35834 \InsetSpace ~
35835 case 5: ...\InsetSpace ~
35836 \InsetSpace ~
35837 \InsetSpace ~
35838 \InsetSpace ~
35839 \InsetSpace ~
35840 \InsetSpace ~
35841 \InsetSpace ~
35842 \InsetSpace ~
35843 \InsetSpace ~
35844 \InsetSpace ~
35845 \InsetSpace ~
35846 \InsetSpace ~
35847 \InsetSpace ~
35848 \InsetSpace ~
35849 \InsetSpace ~
35850 \InsetSpace ~
35851 \InsetSpace ~
35852 \InsetSpace ~
35853 \InsetSpace ~
35854 \InsetSpace ~
35855 \InsetSpace ~
35856 \InsetSpace ~
35857 \InsetSpace ~
35858 \InsetSpace ~
35859 \InsetSpace ~
35860 \InsetSpace ~
35861 case 1: ...
35862  
35863 \newline
35864 \InsetSpace ~
35865 \InsetSpace ~
35866 \InsetSpace ~
35867 case 3: ...\InsetSpace ~
35868 \InsetSpace ~
35869 \InsetSpace ~
35870 \InsetSpace ~
35871 \InsetSpace ~
35872 \InsetSpace ~
35873 \InsetSpace ~
35874 \InsetSpace ~
35875 \InsetSpace ~
35876 \InsetSpace ~
35877 \InsetSpace ~
35878 \InsetSpace ~
35879 \InsetSpace ~
35880 \InsetSpace ~
35881 \InsetSpace ~
35882 \InsetSpace ~
35883 \InsetSpace ~
35884 \InsetSpace ~
35885 \InsetSpace ~
35886 \InsetSpace ~
35887 \InsetSpace ~
35888 \InsetSpace ~
35889 \InsetSpace ~
35890 \InsetSpace ~
35891 \InsetSpace ~
35892 \InsetSpace ~
35893
35894 \newline
35895 \InsetSpace ~
35896 \InsetSpace ~
35897 \InsetSpace ~
35898 case 6: ...\InsetSpace ~
35899 \InsetSpace ~
35900 \InsetSpace ~
35901 \InsetSpace ~
35902 \InsetSpace ~
35903 \InsetSpace ~
35904 \InsetSpace ~
35905 \InsetSpace ~
35906 \InsetSpace ~
35907 \InsetSpace ~
35908 \InsetSpace ~
35909 \InsetSpace ~
35910 \InsetSpace ~
35911 \InsetSpace ~
35912 \InsetSpace ~
35913 \InsetSpace ~
35914 \InsetSpace ~
35915 \InsetSpace ~
35916 \InsetSpace ~
35917 \InsetSpace ~
35918 \InsetSpace ~
35919 \InsetSpace ~
35920 \InsetSpace ~
35921 \InsetSpace ~
35922 \InsetSpace ~
35923 \InsetSpace ~
35924 case 3: ...
35925  
35926 \newline
35927 \InsetSpace ~
35928 \InsetSpace ~
35929 \InsetSpace ~
35930 case 7: ...\InsetSpace ~
35931 \InsetSpace ~
35932 \InsetSpace ~
35933 \InsetSpace ~
35934 \InsetSpace ~
35935 \InsetSpace ~
35936 \InsetSpace ~
35937 \InsetSpace ~
35938 \InsetSpace ~
35939 \InsetSpace ~
35940 \InsetSpace ~
35941 \InsetSpace ~
35942 \InsetSpace ~
35943 \InsetSpace ~
35944 \InsetSpace ~
35945 \InsetSpace ~
35946 \InsetSpace ~
35947 \InsetSpace ~
35948 \InsetSpace ~
35949 \InsetSpace ~
35950 \InsetSpace ~
35951 \InsetSpace ~
35952 \InsetSpace ~
35953 \InsetSpace ~
35954 \InsetSpace ~
35955 \InsetSpace ~
35956 case 4: ...
35957  
35958 \newline
35959 \InsetSpace ~
35960 \InsetSpace ~
35961 \InsetSpace ~
35962 case 8: ...\InsetSpace ~
35963 \InsetSpace ~
35964 \InsetSpace ~
35965 \InsetSpace ~
35966 \InsetSpace ~
35967 \InsetSpace ~
35968 \InsetSpace ~
35969 \InsetSpace ~
35970 \InsetSpace ~
35971 \InsetSpace ~
35972 \InsetSpace ~
35973 \InsetSpace ~
35974 \InsetSpace ~
35975 \InsetSpace ~
35976 \InsetSpace ~
35977 \InsetSpace ~
35978 \InsetSpace ~
35979 \InsetSpace ~
35980 \InsetSpace ~
35981 \InsetSpace ~
35982 \InsetSpace ~
35983 \InsetSpace ~
35984 \InsetSpace ~
35985 \InsetSpace ~
35986 \InsetSpace ~
35987 \InsetSpace ~
35988 case 5: ...
35989  
35990 \newline
35991 \InsetSpace ~
35992 \InsetSpace ~
35993 \InsetSpace ~
35994 case 9: ...\InsetSpace ~
35995 \InsetSpace ~
35996 \InsetSpace ~
35997 \InsetSpace ~
35998 \InsetSpace ~
35999 \InsetSpace ~
36000 \InsetSpace ~
36001 \InsetSpace ~
36002 \InsetSpace ~
36003 \InsetSpace ~
36004 \InsetSpace ~
36005 \InsetSpace ~
36006 \InsetSpace ~
36007 \InsetSpace ~
36008 \InsetSpace ~
36009 \InsetSpace ~
36010 \InsetSpace ~
36011 \InsetSpace ~
36012 \InsetSpace ~
36013 \InsetSpace ~
36014 \InsetSpace ~
36015 \InsetSpace ~
36016 \InsetSpace ~
36017 \InsetSpace ~
36018 \InsetSpace ~
36019 \InsetSpace ~
36020 case 6: ...
36021  
36022 \newline
36023 \InsetSpace ~
36024 \InsetSpace ~
36025 \InsetSpace ~
36026 case 10: ...\InsetSpace ~
36027 \InsetSpace ~
36028 \InsetSpace ~
36029 \InsetSpace ~
36030 \InsetSpace ~
36031 \InsetSpace ~
36032 \InsetSpace ~
36033 \InsetSpace ~
36034 \InsetSpace ~
36035 \InsetSpace ~
36036 \InsetSpace ~
36037 \InsetSpace ~
36038 \InsetSpace ~
36039 \InsetSpace ~
36040 \InsetSpace ~
36041 \InsetSpace ~
36042 \InsetSpace ~
36043 \InsetSpace ~
36044 \InsetSpace ~
36045 \InsetSpace ~
36046 \InsetSpace ~
36047 \InsetSpace ~
36048 \InsetSpace ~
36049 \InsetSpace ~
36050 \InsetSpace ~
36051 case 7: ...
36052  
36053 \newline
36054 \InsetSpace ~
36055 \InsetSpace ~
36056 \InsetSpace ~
36057 case 11: ...\InsetSpace ~
36058 \InsetSpace ~
36059 \InsetSpace ~
36060 \InsetSpace ~
36061 \InsetSpace ~
36062 \InsetSpace ~
36063 \InsetSpace ~
36064 \InsetSpace ~
36065 \InsetSpace ~
36066 \InsetSpace ~
36067 \InsetSpace ~
36068 \InsetSpace ~
36069 \InsetSpace ~
36070 \InsetSpace ~
36071 \InsetSpace ~
36072 \InsetSpace ~
36073 \InsetSpace ~
36074 \InsetSpace ~
36075 \InsetSpace ~
36076 \InsetSpace ~
36077 \InsetSpace ~
36078 \InsetSpace ~
36079 \InsetSpace ~
36080 \InsetSpace ~
36081 \InsetSpace ~
36082 case 8: ...
36083  
36084 \newline
36085 }\InsetSpace ~
36086 \InsetSpace ~
36087 \InsetSpace ~
36088 \InsetSpace ~
36089 \InsetSpace ~
36090 \InsetSpace ~
36091 \InsetSpace ~
36092 \InsetSpace ~
36093 \InsetSpace ~
36094 \InsetSpace ~
36095 \InsetSpace ~
36096 \InsetSpace ~
36097 \InsetSpace ~
36098 \InsetSpace ~
36099 \InsetSpace ~
36100 \InsetSpace ~
36101 \InsetSpace ~
36102 \InsetSpace ~
36103 \InsetSpace ~
36104 \InsetSpace ~
36105 \InsetSpace ~
36106 \InsetSpace ~
36107 \InsetSpace ~
36108 \InsetSpace ~
36109 \InsetSpace ~
36110 \InsetSpace ~
36111 \InsetSpace ~
36112 \InsetSpace ~
36113 \InsetSpace ~
36114 \InsetSpace ~
36115 \InsetSpace ~
36116 \InsetSpace ~
36117 \InsetSpace ~
36118 \InsetSpace ~
36119 \InsetSpace ~
36120 \InsetSpace ~
36121 }
36122 \end_layout
36123
36124 \begin_layout Standard
36125 Both the above switch statements will be implemented using a jump-table.
36126  The example to the right side is slightly more efficient as the check for
36127  the lower boundary of the jump-table is not needed.
36128 \end_layout
36129
36130 \end_deeper
36131 \begin_layout Itemize
36132 The number of case labels is not larger than supported by the target architectur
36133 e.
36134 \end_layout
36135
36136 \begin_layout Itemize
36137 If the case labels are not in numerical sequence ('gaps' between cases)
36138  SDCC checks whether a jump table with additionally inserted dummy cases
36139  is still attractive.
36140  
36141 \end_layout
36142
36143 \begin_layout Itemize
36144 If the starting number is not zero and a check for the lower boundary of
36145  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
36146  ...
36147  .
36148 \end_layout
36149
36150 \begin_layout Standard
36151 Switch statements which have large gaps in the numeric sequence or those
36152  that have too many case labels can be split into more than one switch statement
36153  for efficient code generation, e.g.:
36154 \end_layout
36155
36156 \begin_layout Verse
36157
36158 \family typewriter
36159 switch (i) { 
36160 \newline
36161 \InsetSpace ~
36162 \InsetSpace ~
36163 case 1: ...
36164  
36165 \newline
36166 \InsetSpace ~
36167 \InsetSpace ~
36168 case 2: ...
36169  
36170 \newline
36171 \InsetSpace ~
36172 \InsetSpace ~
36173 case 3: ...
36174  
36175 \newline
36176 \InsetSpace ~
36177 \InsetSpace ~
36178 case 4: ...
36179  
36180 \newline
36181 \InsetSpace ~
36182 \InsetSpace ~
36183 case 5: ...
36184  
36185 \newline
36186 \InsetSpace ~
36187 \InsetSpace ~
36188 case 6: ...
36189  
36190 \newline
36191 \InsetSpace ~
36192 \InsetSpace ~
36193 case 7: ...
36194  
36195 \newline
36196 \InsetSpace ~
36197 \InsetSpace ~
36198 case 101: ...
36199  
36200 \newline
36201 \InsetSpace ~
36202 \InsetSpace ~
36203 case 102: ...
36204  
36205 \newline
36206 \InsetSpace ~
36207 \InsetSpace ~
36208 case 103: ...
36209  
36210 \newline
36211 \InsetSpace ~
36212 \InsetSpace ~
36213 case 104: ...
36214  
36215 \newline
36216 \InsetSpace ~
36217 \InsetSpace ~
36218 case 105: ...
36219  
36220 \newline
36221 \InsetSpace ~
36222 \InsetSpace ~
36223 case 106: ...
36224  
36225 \newline
36226 \InsetSpace ~
36227 \InsetSpace ~
36228 case 107: ...
36229  
36230 \newline
36231 }
36232 \end_layout
36233
36234 \begin_layout Standard
36235 If the above switch statement is broken down into two switch statements
36236 \end_layout
36237
36238 \begin_layout Verse
36239
36240 \family typewriter
36241 switch (i) { 
36242 \newline
36243 \InsetSpace ~
36244 \InsetSpace ~
36245 case 1: ...
36246  
36247 \newline
36248 \InsetSpace ~
36249 \InsetSpace ~
36250 case 2: ...
36251  
36252 \newline
36253 \InsetSpace ~
36254 \InsetSpace ~
36255 case 3: ...
36256  
36257 \newline
36258 \InsetSpace ~
36259 \InsetSpace ~
36260 case 4: ...
36261  
36262 \newline
36263 \InsetSpace ~
36264 \InsetSpace ~
36265 case 5: ...
36266  
36267 \newline
36268 \InsetSpace ~
36269 \InsetSpace ~
36270 case 6: ...
36271  
36272 \newline
36273 \InsetSpace ~
36274 \InsetSpace ~
36275 case 7: ...
36276  
36277 \newline
36278 }
36279 \end_layout
36280
36281 \begin_layout Standard
36282 and
36283 \end_layout
36284
36285 \begin_layout Verse
36286
36287 \family typewriter
36288 switch (i) { 
36289 \newline
36290 \InsetSpace ~
36291 \InsetSpace ~
36292 case 101: ...
36293  
36294 \newline
36295 \InsetSpace ~
36296 \InsetSpace ~
36297 case 102: ...
36298  
36299 \newline
36300 \InsetSpace ~
36301 \InsetSpace ~
36302 case 103: ...
36303  
36304 \newline
36305 \InsetSpace ~
36306 \InsetSpace ~
36307 case 104: ...
36308  
36309 \newline
36310 \InsetSpace ~
36311 \InsetSpace ~
36312 case 105: ...
36313  
36314 \newline
36315 \InsetSpace ~
36316 \InsetSpace ~
36317 case 106: ...
36318  
36319 \newline
36320 \InsetSpace ~
36321 \InsetSpace ~
36322 case 107: ...
36323  
36324 \newline
36325 }
36326 \end_layout
36327
36328 \begin_layout Standard
36329 then both the switch statements will be implemented using jump-tables whereas
36330  the unmodified switch statement will not be.
36331 \end_layout
36332
36333 \begin_layout Standard
36334 \begin_inset Note Note
36335 status collapsed
36336
36337 \begin_layout Standard
36338 There might be reasons which SDCC cannot know about to either favour or
36339  not favour jump tables.
36340  If the target system has to be as quick for the last switch case as for
36341  the first (pro jump table), or if the switch argument is known to be zero
36342  in the majority of the cases (contra jump table).
36343 \end_layout
36344
36345 \end_inset
36346
36347
36348 \end_layout
36349
36350 \begin_layout Standard
36351 The pragma nojtbound
36352 \begin_inset LatexCommand index
36353 name "\\#pragma nojtbound"
36354
36355 \end_inset
36356
36357  can be used to turn off checking the 
36358 \emph on
36359 j
36360 \emph default
36361 ump 
36362 \emph on
36363 t
36364 \emph default
36365 able 
36366 \emph on
36367 bound
36368 \emph default
36369 aries.
36370  It has no effect if a default label is supplied.
36371  Use of this pragma is dangerous: if the switch
36372 \begin_inset LatexCommand index
36373 name "switch statement"
36374
36375 \end_inset
36376
36377  argument is not matched by a case statement the processor will happily
36378  jump into Nirvana.
36379 \end_layout
36380
36381 \begin_layout Subsection
36382 Bit-shifting Operations
36383 \begin_inset LatexCommand index
36384 name "Bit shifting"
36385
36386 \end_inset
36387
36388 .
36389 \end_layout
36390
36391 \begin_layout Standard
36392 Bit shifting is one of the most frequently used operation in embedded programmin
36393 g.
36394  SDCC tries to implement bit-shift operations in the most efficient way
36395  possible, e.g.:
36396 \end_layout
36397
36398 \begin_layout Verse
36399
36400 \family typewriter
36401 unsigned char i;
36402 \newline
36403 ...
36404  
36405 \newline
36406 i >>= 4; 
36407 \newline
36408 ...
36409 \end_layout
36410
36411 \begin_layout Standard
36412 generates the following code:
36413 \end_layout
36414
36415 \begin_layout Verse
36416
36417 \family typewriter
36418 mov\InsetSpace ~
36419  a,_i 
36420 \newline
36421 swap a 
36422 \newline
36423 anl\InsetSpace ~
36424  a,#0x0f 
36425 \newline
36426 mov\InsetSpace ~
36427  _i,a
36428 \end_layout
36429
36430 \begin_layout Standard
36431 In general SDCC will never setup a loop if the shift count is known.
36432  Another example:
36433 \end_layout
36434
36435 \begin_layout Verse
36436
36437 \family typewriter
36438 unsigned int i; 
36439 \newline
36440 ...
36441  
36442 \newline
36443 i >>= 9; 
36444 \newline
36445 ...
36446 \end_layout
36447
36448 \begin_layout Standard
36449 will generate:
36450 \end_layout
36451
36452 \begin_layout Verse
36453
36454 \family typewriter
36455 mov\InsetSpace ~
36456 \InsetSpace ~
36457 a,(_i + 1) 
36458 \newline
36459 mov\InsetSpace ~
36460 \InsetSpace ~
36461 (_i + 1),#0x00 
36462 \newline
36463 clr\InsetSpace ~
36464 \InsetSpace ~
36465
36466 \newline
36467 rrc\InsetSpace ~
36468 \InsetSpace ~
36469
36470 \newline
36471 mov\InsetSpace ~
36472 \InsetSpace ~
36473 _i,a
36474 \end_layout
36475
36476 \begin_layout Subsection
36477 Bit-rotation
36478 \begin_inset LatexCommand index
36479 name "Bit rotation"
36480
36481 \end_inset
36482
36483
36484 \end_layout
36485
36486 \begin_layout Standard
36487 A special case of the bit-shift operation is bit rotation
36488 \begin_inset LatexCommand index
36489 name "rotating bits"
36490
36491 \end_inset
36492
36493 , SDCC recognizes the following expression to be a left bit-rotation:
36494 \end_layout
36495
36496 \begin_layout Verse
36497
36498 \family typewriter
36499 \series bold
36500 unsigned
36501 \series default
36502 \InsetSpace ~
36503 \InsetSpace ~
36504 char i;\InsetSpace ~
36505 \InsetSpace ~
36506 \InsetSpace ~
36507 \InsetSpace ~
36508 \InsetSpace ~
36509 \InsetSpace ~
36510 \InsetSpace ~
36511 \InsetSpace ~
36512 \InsetSpace ~
36513 \InsetSpace ~
36514 \InsetSpace ~
36515 /* unsigned is needed for rotation */ 
36516 \newline
36517 ...
36518  
36519 \newline
36520 i = ((i << 1) | (i >> 7));
36521 \family default
36522  
36523 \newline
36524
36525 \family typewriter
36526 ...
36527 \end_layout
36528
36529 \begin_layout Standard
36530 will generate the following code:
36531 \end_layout
36532
36533 \begin_layout Verse
36534
36535 \family typewriter
36536 mov\InsetSpace ~
36537 \InsetSpace ~
36538 a,_i 
36539 \newline
36540 rl\InsetSpace ~
36541 \InsetSpace ~
36542 \InsetSpace ~
36543
36544 \newline
36545 mov\InsetSpace ~
36546 \InsetSpace ~
36547 _i,a
36548 \end_layout
36549
36550 \begin_layout Standard
36551 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
36552 ns of this case will also be recognized as bit-rotation, i.e.: 
36553 \end_layout
36554
36555 \begin_layout Verse
36556
36557 \family typewriter
36558 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
36559 \end_layout
36560
36561 \begin_layout Subsection
36562 Nibble and Byte Swapping
36563 \end_layout
36564
36565 \begin_layout Standard
36566 Other special cases of the bit-shift operations are nibble or byte swapping
36567 \begin_inset LatexCommand index
36568 name "swapping nibbles/bytes"
36569
36570 \end_inset
36571
36572 , SDCC recognizes the following expressions:
36573 \end_layout
36574
36575 \begin_layout Verse
36576
36577 \family typewriter
36578 \series bold
36579 unsigned
36580 \series default
36581 \InsetSpace ~
36582 \InsetSpace ~
36583 char i; 
36584 \newline
36585
36586 \series bold
36587 unsigned
36588 \series default
36589 \InsetSpace ~
36590 \InsetSpace ~
36591 int j; 
36592 \newline
36593 ...
36594  
36595 \newline
36596 i = ((i << 4) | (i >> 4));
36597 \family default
36598  
36599 \newline
36600
36601 \family typewriter
36602 j = ((j << 8) | (j >> 8)); 
36603 \end_layout
36604
36605 \begin_layout Standard
36606 and generates a swap instruction for the nibble swapping
36607 \begin_inset LatexCommand index
36608 name "Nibble swapping"
36609
36610 \end_inset
36611
36612  or move instructions for the byte swapping
36613 \begin_inset LatexCommand index
36614 name "Byte swapping"
36615
36616 \end_inset
36617
36618 .
36619  The 
36620 \begin_inset Quotes sld
36621 \end_inset
36622
36623 j
36624 \begin_inset Quotes srd
36625 \end_inset
36626
36627  example can be used to convert from little to big-endian or vice versa.
36628  If you want to change the endianness of a 
36629 \emph on
36630 signed
36631 \emph default
36632  integer you have to cast to 
36633 \family typewriter
36634 (unsigned int)
36635 \family default
36636  first.
36637 \end_layout
36638
36639 \begin_layout Standard
36640 Note that SDCC stores numbers in little-endian
36641 \begin_inset Foot
36642 status open
36643
36644 \begin_layout Standard
36645 Usually 8-bit processors don't care much about endianness.
36646  This is not the case for the standard 8051 which only has an instruction
36647  to increment its 
36648 \emph on
36649 dptr
36650 \emph default
36651
36652 \begin_inset LatexCommand index
36653 name "DPTR"
36654
36655 \end_inset
36656
36657 -datapointer so little-endian is the more efficient byte order.
36658 \end_layout
36659
36660 \end_inset
36661
36662
36663 \begin_inset LatexCommand index
36664 name "little-endian"
36665
36666 \end_inset
36667
36668
36669 \begin_inset LatexCommand index
36670 name "Endianness"
36671
36672 \end_inset
36673
36674  format (i.e.
36675  lowest order first).
36676 \end_layout
36677
36678 \begin_layout Subsection
36679 Highest Order Bit
36680 \begin_inset LatexCommand index
36681 name "Highest Order Bit"
36682
36683 \end_inset
36684
36685  / Any Order Bit
36686 \begin_inset LatexCommand index
36687 name "Any Order Bit"
36688
36689 \end_inset
36690
36691
36692 \end_layout
36693
36694 \begin_layout Standard
36695 It is frequently required to obtain the highest order bit of an integral
36696  type (long, int, short or char types).
36697  Also obtaining any other order bit is not uncommon.
36698  SDCC recognizes the following expressions to yield the highest order bit
36699  and generates optimized code for it, e.g.:
36700 \end_layout
36701
36702 \begin_layout Verse
36703
36704 \family typewriter
36705 unsigned int gint; 
36706 \newline
36707
36708 \newline
36709 foo () { 
36710 \newline
36711 \InsetSpace ~
36712 \InsetSpace ~
36713 unsigned char hob1, aob1; 
36714 \newline
36715 \InsetSpace ~
36716 \InsetSpace ~
36717 bit hob2, hob3, aob2,
36718  aob3; 
36719 \newline
36720 \InsetSpace ~
36721 \InsetSpace ~
36722 ...
36723  
36724 \newline
36725 \InsetSpace ~
36726 \InsetSpace ~
36727 hob1 = (gint >> 15) & 1; 
36728 \newline
36729 \InsetSpace ~
36730 \InsetSpace ~
36731 hob2 = (gint >> 15) & 1; 
36732 \newline
36733 \InsetSpace ~
36734 \InsetSpace ~
36735 hob3 = gint & 0x8000;
36736  
36737 \newline
36738 \InsetSpace ~
36739 \InsetSpace ~
36740 aob1 = (gint >> 9) & 1; 
36741 \newline
36742 \InsetSpace ~
36743 \InsetSpace ~
36744 aob2 = (gint >> 8) & 1; 
36745 \newline
36746 \InsetSpace ~
36747 \InsetSpace ~
36748 aob3 = gint & 0x0800; 
36749 \newline
36750 \InsetSpace ~
36751 \InsetSpace ~
36752 ..
36753  
36754 \newline
36755 }
36756 \end_layout
36757
36758 \begin_layout Standard
36759 will generate the following code:
36760 \end_layout
36761
36762 \begin_layout Verse
36763
36764 \family typewriter
36765 \InsetSpace ~
36766 \InsetSpace ~
36767 \InsetSpace ~
36768 \InsetSpace ~
36769 \InsetSpace ~
36770 \InsetSpace ~
36771 \InsetSpace ~
36772 \InsetSpace ~
36773 \InsetSpace ~
36774 \InsetSpace ~
36775 \InsetSpace ~
36776 \InsetSpace ~
36777 \InsetSpace ~
36778 \InsetSpace ~
36779 \InsetSpace ~
36780 \InsetSpace ~
36781 \InsetSpace ~
36782 \InsetSpace ~
36783 \InsetSpace ~
36784 \InsetSpace ~
36785 \InsetSpace ~
36786 \InsetSpace ~
36787 \InsetSpace ~
36788 \InsetSpace ~
36789 \InsetSpace ~
36790  61 ;\InsetSpace ~
36791  hob.c 7 
36792 \newline
36793 000A E5*01\InsetSpace ~
36794 \InsetSpace ~
36795 \InsetSpace ~
36796 \InsetSpace ~
36797 \InsetSpace ~
36798 \InsetSpace ~
36799 \InsetSpace ~
36800 \InsetSpace ~
36801 \InsetSpace ~
36802 \InsetSpace ~
36803 \InsetSpace ~
36804 \InsetSpace ~
36805 \InsetSpace ~
36806 \InsetSpace ~
36807 \InsetSpace ~
36808  62\InsetSpace ~
36809 \InsetSpace ~
36810 \InsetSpace ~
36811 \InsetSpace ~
36812 \InsetSpace ~
36813 \InsetSpace ~
36814 \InsetSpace ~
36815 \InsetSpace ~
36816  mov\InsetSpace ~
36817 \InsetSpace ~
36818  a,(_gint + 1) 
36819 \newline
36820 000C 23\InsetSpace ~
36821 \InsetSpace ~
36822 \InsetSpace ~
36823 \InsetSpace ~
36824 \InsetSpace ~
36825 \InsetSpace ~
36826 \InsetSpace ~
36827 \InsetSpace ~
36828 \InsetSpace ~
36829 \InsetSpace ~
36830 \InsetSpace ~
36831 \InsetSpace ~
36832 \InsetSpace ~
36833 \InsetSpace ~
36834 \InsetSpace ~
36835 \InsetSpace ~
36836 \InsetSpace ~
36837 \InsetSpace ~
36838  63\InsetSpace ~
36839 \InsetSpace ~
36840 \InsetSpace ~
36841 \InsetSpace ~
36842 \InsetSpace ~
36843 \InsetSpace ~
36844 \InsetSpace ~
36845 \InsetSpace ~
36846  rl\InsetSpace ~
36847 \InsetSpace ~
36848 \InsetSpace ~
36849  a 
36850 \newline
36851 000D 54 01\InsetSpace ~
36852 \InsetSpace ~
36853 \InsetSpace ~
36854 \InsetSpace ~
36855 \InsetSpace ~
36856 \InsetSpace ~
36857 \InsetSpace ~
36858 \InsetSpace ~
36859 \InsetSpace ~
36860 \InsetSpace ~
36861 \InsetSpace ~
36862 \InsetSpace ~
36863 \InsetSpace ~
36864 \InsetSpace ~
36865 \InsetSpace ~
36866
36867  64\InsetSpace ~
36868 \InsetSpace ~
36869 \InsetSpace ~
36870 \InsetSpace ~
36871 \InsetSpace ~
36872 \InsetSpace ~
36873 \InsetSpace ~
36874 \InsetSpace ~
36875  anl\InsetSpace ~
36876 \InsetSpace ~
36877  a,#0x01 
36878 \newline
36879 000F F5*02\InsetSpace ~
36880 \InsetSpace ~
36881 \InsetSpace ~
36882 \InsetSpace ~
36883 \InsetSpace ~
36884 \InsetSpace ~
36885 \InsetSpace ~
36886 \InsetSpace ~
36887 \InsetSpace ~
36888 \InsetSpace ~
36889 \InsetSpace ~
36890 \InsetSpace ~
36891 \InsetSpace ~
36892 \InsetSpace ~
36893 \InsetSpace ~
36894  65\InsetSpace ~
36895 \InsetSpace ~
36896 \InsetSpace ~
36897 \InsetSpace ~
36898 \InsetSpace ~
36899 \InsetSpace ~
36900 \InsetSpace ~
36901 \InsetSpace ~
36902  mov\InsetSpace ~
36903 \InsetSpace ~
36904  _foo_hob1_1_1,a 
36905 \newline
36906 \InsetSpace ~
36907 \InsetSpace ~
36908 \InsetSpace ~
36909 \InsetSpace ~
36910 \InsetSpace ~
36911 \InsetSpace ~
36912 \InsetSpace ~
36913 \InsetSpace ~
36914 \InsetSpace ~
36915 \InsetSpace ~
36916 \InsetSpace ~
36917 \InsetSpace ~
36918 \InsetSpace ~
36919 \InsetSpace ~
36920 \InsetSpace ~
36921 \InsetSpace ~
36922 \InsetSpace ~
36923 \InsetSpace ~
36924 \InsetSpace ~
36925 \InsetSpace ~
36926 \InsetSpace ~
36927 \InsetSpace ~
36928 \InsetSpace ~
36929 \InsetSpace ~
36930 \InsetSpace ~
36931  66 ;\InsetSpace ~
36932  hob.c 8 
36933 \newline
36934 0011 E5*01\InsetSpace ~
36935 \InsetSpace ~
36936 \InsetSpace ~
36937 \InsetSpace ~
36938 \InsetSpace ~
36939 \InsetSpace ~
36940 \InsetSpace ~
36941 \InsetSpace ~
36942 \InsetSpace ~
36943 \InsetSpace ~
36944 \InsetSpace ~
36945 \InsetSpace ~
36946 \InsetSpace ~
36947 \InsetSpace ~
36948 \InsetSpace ~
36949
36950  67\InsetSpace ~
36951 \InsetSpace ~
36952 \InsetSpace ~
36953 \InsetSpace ~
36954 \InsetSpace ~
36955 \InsetSpace ~
36956 \InsetSpace ~
36957 \InsetSpace ~
36958  mov\InsetSpace ~
36959 \InsetSpace ~
36960  a,(_gint + 1) 
36961 \newline
36962 0013 33\InsetSpace ~
36963 \InsetSpace ~
36964 \InsetSpace ~
36965 \InsetSpace ~
36966 \InsetSpace ~
36967 \InsetSpace ~
36968 \InsetSpace ~
36969 \InsetSpace ~
36970 \InsetSpace ~
36971 \InsetSpace ~
36972 \InsetSpace ~
36973 \InsetSpace ~
36974 \InsetSpace ~
36975 \InsetSpace ~
36976 \InsetSpace ~
36977 \InsetSpace ~
36978 \InsetSpace ~
36979 \InsetSpace ~
36980  68\InsetSpace ~
36981 \InsetSpace ~
36982 \InsetSpace ~
36983 \InsetSpace ~
36984 \InsetSpace ~
36985 \InsetSpace ~
36986 \InsetSpace ~
36987 \InsetSpace ~
36988  rlc\InsetSpace ~
36989 \InsetSpace ~
36990  a 
36991 \newline
36992 0014 92*00\InsetSpace ~
36993 \InsetSpace ~
36994 \InsetSpace ~
36995 \InsetSpace ~
36996 \InsetSpace ~
36997 \InsetSpace ~
36998 \InsetSpace ~
36999 \InsetSpace ~
37000 \InsetSpace ~
37001 \InsetSpace ~
37002 \InsetSpace ~
37003 \InsetSpace ~
37004 \InsetSpace ~
37005 \InsetSpace ~
37006 \InsetSpace ~
37007  69\InsetSpace ~
37008 \InsetSpace ~
37009 \InsetSpace ~
37010 \InsetSpace ~
37011 \InsetSpace ~
37012 \InsetSpace ~
37013 \InsetSpace ~
37014 \InsetSpace ~
37015  mov\InsetSpace ~
37016 \InsetSpace ~
37017  _foo_hob2_1_1,c
37018  
37019 \newline
37020 \InsetSpace ~
37021 \InsetSpace ~
37022 \InsetSpace ~
37023 \InsetSpace ~
37024 \InsetSpace ~
37025 \InsetSpace ~
37026 \InsetSpace ~
37027 \InsetSpace ~
37028 \InsetSpace ~
37029 \InsetSpace ~
37030 \InsetSpace ~
37031 \InsetSpace ~
37032 \InsetSpace ~
37033 \InsetSpace ~
37034 \InsetSpace ~
37035 \InsetSpace ~
37036 \InsetSpace ~
37037 \InsetSpace ~
37038 \InsetSpace ~
37039 \InsetSpace ~
37040 \InsetSpace ~
37041 \InsetSpace ~
37042 \InsetSpace ~
37043 \InsetSpace ~
37044 \InsetSpace ~
37045  66 ;\InsetSpace ~
37046  hob.c 9 
37047 \newline
37048 0016 E5*01\InsetSpace ~
37049 \InsetSpace ~
37050 \InsetSpace ~
37051 \InsetSpace ~
37052 \InsetSpace ~
37053 \InsetSpace ~
37054 \InsetSpace ~
37055 \InsetSpace ~
37056 \InsetSpace ~
37057 \InsetSpace ~
37058 \InsetSpace ~
37059 \InsetSpace ~
37060 \InsetSpace ~
37061 \InsetSpace ~
37062 \InsetSpace ~
37063  67\InsetSpace ~
37064 \InsetSpace ~
37065 \InsetSpace ~
37066 \InsetSpace ~
37067 \InsetSpace ~
37068 \InsetSpace ~
37069 \InsetSpace ~
37070 \InsetSpace ~
37071  mov\InsetSpace ~
37072 \InsetSpace ~
37073  a,(_gint + 1) 
37074 \newline
37075 0018 33\InsetSpace ~
37076 \InsetSpace ~
37077 \InsetSpace ~
37078 \InsetSpace ~
37079 \InsetSpace ~
37080 \InsetSpace ~
37081 \InsetSpace ~
37082 \InsetSpace ~
37083 \InsetSpace ~
37084 \InsetSpace ~
37085 \InsetSpace ~
37086 \InsetSpace ~
37087 \InsetSpace ~
37088 \InsetSpace ~
37089 \InsetSpace ~
37090 \InsetSpace ~
37091 \InsetSpace ~
37092 \InsetSpace ~
37093  68\InsetSpace ~
37094 \InsetSpace ~
37095 \InsetSpace ~
37096 \InsetSpace ~
37097 \InsetSpace ~
37098 \InsetSpace ~
37099 \InsetSpace ~
37100 \InsetSpace ~
37101  rlc\InsetSpace ~
37102 \InsetSpace ~
37103  a 
37104 \newline
37105 0019 92*01\InsetSpace ~
37106 \InsetSpace ~
37107 \InsetSpace ~
37108 \InsetSpace ~
37109 \InsetSpace ~
37110 \InsetSpace ~
37111 \InsetSpace ~
37112 \InsetSpace ~
37113 \InsetSpace ~
37114 \InsetSpace ~
37115 \InsetSpace ~
37116 \InsetSpace ~
37117 \InsetSpace ~
37118 \InsetSpace ~
37119 \InsetSpace ~
37120
37121  69\InsetSpace ~
37122 \InsetSpace ~
37123 \InsetSpace ~
37124 \InsetSpace ~
37125 \InsetSpace ~
37126 \InsetSpace ~
37127 \InsetSpace ~
37128 \InsetSpace ~
37129  mov\InsetSpace ~
37130 \InsetSpace ~
37131  _foo_hob3_1_1,c 
37132 \newline
37133 \InsetSpace ~
37134 \InsetSpace ~
37135 \InsetSpace ~
37136 \InsetSpace ~
37137 \InsetSpace ~
37138 \InsetSpace ~
37139 \InsetSpace ~
37140 \InsetSpace ~
37141 \InsetSpace ~
37142 \InsetSpace ~
37143 \InsetSpace ~
37144 \InsetSpace ~
37145 \InsetSpace ~
37146 \InsetSpace ~
37147 \InsetSpace ~
37148 \InsetSpace ~
37149 \InsetSpace ~
37150 \InsetSpace ~
37151 \InsetSpace ~
37152 \InsetSpace ~
37153 \InsetSpace ~
37154 \InsetSpace ~
37155 \InsetSpace ~
37156 \InsetSpace ~
37157 \InsetSpace ~
37158  70 ;\InsetSpace ~
37159  hob.c 10 
37160 \newline
37161 001B E5*01\InsetSpace ~
37162 \InsetSpace ~
37163 \InsetSpace ~
37164 \InsetSpace ~
37165 \InsetSpace ~
37166 \InsetSpace ~
37167 \InsetSpace ~
37168 \InsetSpace ~
37169 \InsetSpace ~
37170 \InsetSpace ~
37171 \InsetSpace ~
37172 \InsetSpace ~
37173 \InsetSpace ~
37174 \InsetSpace ~
37175 \InsetSpace ~
37176  71\InsetSpace ~
37177 \InsetSpace ~
37178 \InsetSpace ~
37179 \InsetSpace ~
37180 \InsetSpace ~
37181 \InsetSpace ~
37182 \InsetSpace ~
37183 \InsetSpace ~
37184  mov\InsetSpace ~
37185 \InsetSpace ~
37186  a,(_gint + 1) 
37187 \newline
37188 001D
37189  03\InsetSpace ~
37190 \InsetSpace ~
37191 \InsetSpace ~
37192 \InsetSpace ~
37193 \InsetSpace ~
37194 \InsetSpace ~
37195 \InsetSpace ~
37196 \InsetSpace ~
37197 \InsetSpace ~
37198 \InsetSpace ~
37199 \InsetSpace ~
37200 \InsetSpace ~
37201 \InsetSpace ~
37202 \InsetSpace ~
37203 \InsetSpace ~
37204 \InsetSpace ~
37205 \InsetSpace ~
37206 \InsetSpace ~
37207  72\InsetSpace ~
37208 \InsetSpace ~
37209 \InsetSpace ~
37210 \InsetSpace ~
37211 \InsetSpace ~
37212 \InsetSpace ~
37213 \InsetSpace ~
37214 \InsetSpace ~
37215  rr\InsetSpace ~
37216 \InsetSpace ~
37217 \InsetSpace ~
37218  a 
37219 \newline
37220 001E 54 01\InsetSpace ~
37221 \InsetSpace ~
37222 \InsetSpace ~
37223 \InsetSpace ~
37224 \InsetSpace ~
37225 \InsetSpace ~
37226 \InsetSpace ~
37227 \InsetSpace ~
37228 \InsetSpace ~
37229 \InsetSpace ~
37230 \InsetSpace ~
37231 \InsetSpace ~
37232 \InsetSpace ~
37233 \InsetSpace ~
37234 \InsetSpace ~
37235  73\InsetSpace ~
37236 \InsetSpace ~
37237 \InsetSpace ~
37238 \InsetSpace ~
37239 \InsetSpace ~
37240 \InsetSpace ~
37241 \InsetSpace ~
37242 \InsetSpace ~
37243  anl\InsetSpace ~
37244 \InsetSpace ~
37245  a,#0x01 
37246 \newline
37247 0020 F5*03\InsetSpace ~
37248 \InsetSpace ~
37249 \InsetSpace ~
37250 \InsetSpace ~
37251 \InsetSpace ~
37252 \InsetSpace ~
37253 \InsetSpace ~
37254 \InsetSpace ~
37255 \InsetSpace ~
37256 \InsetSpace ~
37257 \InsetSpace ~
37258 \InsetSpace ~
37259 \InsetSpace ~
37260 \InsetSpace ~
37261 \InsetSpace ~
37262  74\InsetSpace ~
37263 \InsetSpace ~
37264 \InsetSpace ~
37265 \InsetSpace ~
37266 \InsetSpace ~
37267 \InsetSpace ~
37268 \InsetSpace ~
37269 \InsetSpace ~
37270  mov\InsetSpace ~
37271 \InsetSpace ~
37272  _foo_aob1_1_1,a
37273  
37274 \newline
37275 \InsetSpace ~
37276 \InsetSpace ~
37277 \InsetSpace ~
37278 \InsetSpace ~
37279 \InsetSpace ~
37280 \InsetSpace ~
37281 \InsetSpace ~
37282 \InsetSpace ~
37283 \InsetSpace ~
37284 \InsetSpace ~
37285 \InsetSpace ~
37286 \InsetSpace ~
37287 \InsetSpace ~
37288 \InsetSpace ~
37289 \InsetSpace ~
37290 \InsetSpace ~
37291 \InsetSpace ~
37292 \InsetSpace ~
37293 \InsetSpace ~
37294 \InsetSpace ~
37295 \InsetSpace ~
37296 \InsetSpace ~
37297 \InsetSpace ~
37298 \InsetSpace ~
37299 \InsetSpace ~
37300  75 ;\InsetSpace ~
37301  hob.c 11 
37302 \newline
37303 0022 E5*01\InsetSpace ~
37304 \InsetSpace ~
37305 \InsetSpace ~
37306 \InsetSpace ~
37307 \InsetSpace ~
37308 \InsetSpace ~
37309 \InsetSpace ~
37310 \InsetSpace ~
37311 \InsetSpace ~
37312 \InsetSpace ~
37313 \InsetSpace ~
37314 \InsetSpace ~
37315 \InsetSpace ~
37316 \InsetSpace ~
37317 \InsetSpace ~
37318  76\InsetSpace ~
37319 \InsetSpace ~
37320 \InsetSpace ~
37321 \InsetSpace ~
37322 \InsetSpace ~
37323 \InsetSpace ~
37324 \InsetSpace ~
37325 \InsetSpace ~
37326  mov\InsetSpace ~
37327 \InsetSpace ~
37328  a,(_gint + 1) 
37329 \newline
37330 0024 13\InsetSpace ~
37331 \InsetSpace ~
37332 \InsetSpace ~
37333 \InsetSpace ~
37334 \InsetSpace ~
37335 \InsetSpace ~
37336 \InsetSpace ~
37337 \InsetSpace ~
37338 \InsetSpace ~
37339 \InsetSpace ~
37340 \InsetSpace ~
37341 \InsetSpace ~
37342 \InsetSpace ~
37343 \InsetSpace ~
37344 \InsetSpace ~
37345 \InsetSpace ~
37346 \InsetSpace ~
37347 \InsetSpace ~
37348  77\InsetSpace ~
37349 \InsetSpace ~
37350 \InsetSpace ~
37351 \InsetSpace ~
37352 \InsetSpace ~
37353 \InsetSpace ~
37354 \InsetSpace ~
37355 \InsetSpace ~
37356  rrc\InsetSpace ~
37357 \InsetSpace ~
37358  a 
37359 \newline
37360 0025 92*02\InsetSpace ~
37361 \InsetSpace ~
37362 \InsetSpace ~
37363 \InsetSpace ~
37364 \InsetSpace ~
37365 \InsetSpace ~
37366 \InsetSpace ~
37367 \InsetSpace ~
37368 \InsetSpace ~
37369 \InsetSpace ~
37370 \InsetSpace ~
37371 \InsetSpace ~
37372 \InsetSpace ~
37373 \InsetSpace ~
37374 \InsetSpace ~
37375
37376  78\InsetSpace ~
37377 \InsetSpace ~
37378 \InsetSpace ~
37379 \InsetSpace ~
37380 \InsetSpace ~
37381 \InsetSpace ~
37382 \InsetSpace ~
37383 \InsetSpace ~
37384  mov\InsetSpace ~
37385 \InsetSpace ~
37386  _foo_aob2_1_1,c 
37387 \newline
37388 \InsetSpace ~
37389 \InsetSpace ~
37390 \InsetSpace ~
37391 \InsetSpace ~
37392 \InsetSpace ~
37393 \InsetSpace ~
37394 \InsetSpace ~
37395 \InsetSpace ~
37396 \InsetSpace ~
37397 \InsetSpace ~
37398 \InsetSpace ~
37399 \InsetSpace ~
37400 \InsetSpace ~
37401 \InsetSpace ~
37402 \InsetSpace ~
37403 \InsetSpace ~
37404 \InsetSpace ~
37405 \InsetSpace ~
37406 \InsetSpace ~
37407 \InsetSpace ~
37408 \InsetSpace ~
37409 \InsetSpace ~
37410 \InsetSpace ~
37411 \InsetSpace ~
37412 \InsetSpace ~
37413  79 ;\InsetSpace ~
37414  hob.c 12 
37415 \newline
37416 0027 E5*01\InsetSpace ~
37417 \InsetSpace ~
37418 \InsetSpace ~
37419 \InsetSpace ~
37420 \InsetSpace ~
37421 \InsetSpace ~
37422 \InsetSpace ~
37423 \InsetSpace ~
37424 \InsetSpace ~
37425 \InsetSpace ~
37426 \InsetSpace ~
37427 \InsetSpace ~
37428 \InsetSpace ~
37429 \InsetSpace ~
37430 \InsetSpace ~
37431  80\InsetSpace ~
37432 \InsetSpace ~
37433 \InsetSpace ~
37434 \InsetSpace ~
37435 \InsetSpace ~
37436 \InsetSpace ~
37437 \InsetSpace ~
37438 \InsetSpace ~
37439  mov\InsetSpace ~
37440 \InsetSpace ~
37441  a,(_gint + 1) 
37442 \newline
37443 0029
37444  A2 E3\InsetSpace ~
37445 \InsetSpace ~
37446 \InsetSpace ~
37447 \InsetSpace ~
37448 \InsetSpace ~
37449 \InsetSpace ~
37450 \InsetSpace ~
37451 \InsetSpace ~
37452 \InsetSpace ~
37453 \InsetSpace ~
37454 \InsetSpace ~
37455 \InsetSpace ~
37456 \InsetSpace ~
37457 \InsetSpace ~
37458 \InsetSpace ~
37459  81\InsetSpace ~
37460 \InsetSpace ~
37461 \InsetSpace ~
37462 \InsetSpace ~
37463 \InsetSpace ~
37464 \InsetSpace ~
37465 \InsetSpace ~
37466 \InsetSpace ~
37467  mov\InsetSpace ~
37468 \InsetSpace ~
37469  c,acc[3] 
37470 \newline
37471 002B 92*03\InsetSpace ~
37472 \InsetSpace ~
37473 \InsetSpace ~
37474 \InsetSpace ~
37475 \InsetSpace ~
37476 \InsetSpace ~
37477 \InsetSpace ~
37478 \InsetSpace ~
37479 \InsetSpace ~
37480 \InsetSpace ~
37481 \InsetSpace ~
37482 \InsetSpace ~
37483 \InsetSpace ~
37484 \InsetSpace ~
37485 \InsetSpace ~
37486  82\InsetSpace ~
37487 \InsetSpace ~
37488 \InsetSpace ~
37489 \InsetSpace ~
37490 \InsetSpace ~
37491 \InsetSpace ~
37492 \InsetSpace ~
37493 \InsetSpace ~
37494  mov\InsetSpace ~
37495 \InsetSpace ~
37496  _foo_aob3_1_1,c 
37497 \end_layout
37498
37499 \begin_layout Standard
37500 Other variations of these cases however will 
37501 \emph on
37502 not
37503 \emph default
37504  be recognized.
37505  They are standard C expressions, so I heartily recommend these be the only
37506  way to get the highest order bit, (it is portable).
37507  Of course it will be recognized even if it is embedded in other expressions,
37508  e.g.:
37509 \end_layout
37510
37511 \begin_layout Verse
37512
37513 \family typewriter
37514 xyz = gint + ((gint >> 15) & 1);
37515 \end_layout
37516
37517 \begin_layout Standard
37518 will still be recognized.
37519 \end_layout
37520
37521 \begin_layout Subsection
37522 Higher Order Byte
37523 \begin_inset LatexCommand index
37524 name "Higher Order Byte"
37525
37526 \end_inset
37527
37528  / Higher Order Word
37529 \begin_inset LatexCommand index
37530 name "Higher Order Word"
37531
37532 \end_inset
37533
37534
37535 \end_layout
37536
37537 \begin_layout Standard
37538 It is also frequently required to obtain a higher order byte or word of
37539  a larger integral type (long, int or short types).
37540  SDCC recognizes the following expressions to yield the higher order byte
37541  or word and generates optimized code for it, e.g.:
37542 \end_layout
37543
37544 \begin_layout Verse
37545
37546 \family typewriter
37547 unsigned int gint; 
37548 \newline
37549 unsigned long int glong; 
37550 \newline
37551
37552 \newline
37553 foo () { 
37554 \newline
37555 \InsetSpace ~
37556 \InsetSpace ~
37557 unsigned char hob1,
37558  hob2; 
37559 \newline
37560 \InsetSpace ~
37561 \InsetSpace ~
37562 unsigned int how1, how2; 
37563 \newline
37564 \InsetSpace ~
37565 \InsetSpace ~
37566 ...
37567  
37568 \newline
37569 \InsetSpace ~
37570 \InsetSpace ~
37571 hob1 = (gint >> 8) & 0xFF; 
37572 \newline
37573 \InsetSpace ~
37574 \InsetSpace ~
37575 hob2 = glong >> 24; 
37576 \newline
37577 \InsetSpace ~
37578 \InsetSpace ~
37579 how1 = (glong >> 16) & 0xFFFF;
37580  
37581 \newline
37582 \InsetSpace ~
37583 \InsetSpace ~
37584 how2 = glong >> 8; 
37585 \newline
37586 \InsetSpace ~
37587 \InsetSpace ~
37588 ..
37589  
37590 \newline
37591 }
37592 \end_layout
37593
37594 \begin_layout Standard
37595 will generate the following code:
37596 \end_layout
37597
37598 \begin_layout Verse
37599
37600 \family typewriter
37601 \InsetSpace ~
37602 \InsetSpace ~
37603 \InsetSpace ~
37604 \InsetSpace ~
37605 \InsetSpace ~
37606 \InsetSpace ~
37607 \InsetSpace ~
37608 \InsetSpace ~
37609 \InsetSpace ~
37610 \InsetSpace ~
37611 \InsetSpace ~
37612 \InsetSpace ~
37613 \InsetSpace ~
37614 \InsetSpace ~
37615 \InsetSpace ~
37616 \InsetSpace ~
37617 \InsetSpace ~
37618 \InsetSpace ~
37619 \InsetSpace ~
37620 \InsetSpace ~
37621 \InsetSpace ~
37622 \InsetSpace ~
37623 \InsetSpace ~
37624 \InsetSpace ~
37625 \InsetSpace ~
37626  91 ;\InsetSpace ~
37627  hob.c 15 
37628 \newline
37629 0037 85*01*06\InsetSpace ~
37630 \InsetSpace ~
37631 \InsetSpace ~
37632 \InsetSpace ~
37633 \InsetSpace ~
37634 \InsetSpace ~
37635 \InsetSpace ~
37636 \InsetSpace ~
37637 \InsetSpace ~
37638 \InsetSpace ~
37639 \InsetSpace ~
37640 \InsetSpace ~
37641  92\InsetSpace ~
37642 \InsetSpace ~
37643 \InsetSpace ~
37644 \InsetSpace ~
37645 \InsetSpace ~
37646 \InsetSpace ~
37647 \InsetSpace ~
37648 \InsetSpace ~
37649  mov\InsetSpace ~
37650 \InsetSpace ~
37651  _foo_hob1_1_1,(_gint + 1) 
37652 \newline
37653 \InsetSpace ~
37654 \InsetSpace ~
37655 \InsetSpace ~
37656 \InsetSpace ~
37657 \InsetSpace ~
37658 \InsetSpace ~
37659 \InsetSpace ~
37660 \InsetSpace ~
37661 \InsetSpace ~
37662 \InsetSpace ~
37663 \InsetSpace ~
37664 \InsetSpace ~
37665 \InsetSpace ~
37666 \InsetSpace ~
37667 \InsetSpace ~
37668 \InsetSpace ~
37669 \InsetSpace ~
37670 \InsetSpace ~
37671 \InsetSpace ~
37672 \InsetSpace ~
37673 \InsetSpace ~
37674 \InsetSpace ~
37675 \InsetSpace ~
37676 \InsetSpace ~
37677 \InsetSpace ~
37678  93 ;\InsetSpace ~
37679  hob.c
37680  16 
37681 \newline
37682 003A 85*05*07\InsetSpace ~
37683 \InsetSpace ~
37684 \InsetSpace ~
37685 \InsetSpace ~
37686 \InsetSpace ~
37687 \InsetSpace ~
37688 \InsetSpace ~
37689 \InsetSpace ~
37690 \InsetSpace ~
37691 \InsetSpace ~
37692 \InsetSpace ~
37693 \InsetSpace ~
37694  94\InsetSpace ~
37695 \InsetSpace ~
37696 \InsetSpace ~
37697 \InsetSpace ~
37698 \InsetSpace ~
37699 \InsetSpace ~
37700 \InsetSpace ~
37701 \InsetSpace ~
37702  mov\InsetSpace ~
37703 \InsetSpace ~
37704  _foo_hob2_1_1,(_glong + 3) 
37705 \newline
37706 \InsetSpace ~
37707 \InsetSpace ~
37708 \InsetSpace ~
37709 \InsetSpace ~
37710 \InsetSpace ~
37711 \InsetSpace ~
37712 \InsetSpace ~
37713 \InsetSpace ~
37714 \InsetSpace ~
37715 \InsetSpace ~
37716 \InsetSpace ~
37717 \InsetSpace ~
37718 \InsetSpace ~
37719 \InsetSpace ~
37720 \InsetSpace ~
37721 \InsetSpace ~
37722 \InsetSpace ~
37723 \InsetSpace ~
37724 \InsetSpace ~
37725 \InsetSpace ~
37726 \InsetSpace ~
37727 \InsetSpace ~
37728 \InsetSpace ~
37729 \InsetSpace ~
37730 \InsetSpace ~
37731  95 ;\InsetSpace ~
37732  hob.c 17 
37733 \newline
37734 003D 85*04*08\InsetSpace ~
37735 \InsetSpace ~
37736 \InsetSpace ~
37737 \InsetSpace ~
37738 \InsetSpace ~
37739 \InsetSpace ~
37740 \InsetSpace ~
37741 \InsetSpace ~
37742 \InsetSpace ~
37743 \InsetSpace ~
37744 \InsetSpace ~
37745 \InsetSpace ~
37746
37747  96\InsetSpace ~
37748 \InsetSpace ~
37749 \InsetSpace ~
37750 \InsetSpace ~
37751 \InsetSpace ~
37752 \InsetSpace ~
37753 \InsetSpace ~
37754 \InsetSpace ~
37755  mov\InsetSpace ~
37756 \InsetSpace ~
37757  _foo_how1_1_1,(_glong + 2) 
37758 \newline
37759 0040 85*05*09\InsetSpace ~
37760 \InsetSpace ~
37761 \InsetSpace ~
37762 \InsetSpace ~
37763 \InsetSpace ~
37764 \InsetSpace ~
37765 \InsetSpace ~
37766 \InsetSpace ~
37767 \InsetSpace ~
37768 \InsetSpace ~
37769 \InsetSpace ~
37770 \InsetSpace ~
37771  97\InsetSpace ~
37772 \InsetSpace ~
37773 \InsetSpace ~
37774 \InsetSpace ~
37775 \InsetSpace ~
37776 \InsetSpace ~
37777 \InsetSpace ~
37778 \InsetSpace ~
37779  mov\InsetSpace ~
37780 \InsetSpace ~
37781  (_foo_how1_1_1 +
37782  1),(_glong + 3) 
37783 \newline
37784 0043 85*03*0A\InsetSpace ~
37785 \InsetSpace ~
37786 \InsetSpace ~
37787 \InsetSpace ~
37788 \InsetSpace ~
37789 \InsetSpace ~
37790 \InsetSpace ~
37791 \InsetSpace ~
37792 \InsetSpace ~
37793 \InsetSpace ~
37794 \InsetSpace ~
37795 \InsetSpace ~
37796  98\InsetSpace ~
37797 \InsetSpace ~
37798 \InsetSpace ~
37799 \InsetSpace ~
37800 \InsetSpace ~
37801 \InsetSpace ~
37802 \InsetSpace ~
37803 \InsetSpace ~
37804  mov\InsetSpace ~
37805 \InsetSpace ~
37806  _foo_how2_1_1,(_glong + 1) 
37807 \newline
37808 0046 85*04*0B\InsetSpace ~
37809 \InsetSpace ~
37810 \InsetSpace ~
37811 \InsetSpace ~
37812 \InsetSpace ~
37813 \InsetSpace ~
37814 \InsetSpace ~
37815 \InsetSpace ~
37816 \InsetSpace ~
37817 \InsetSpace ~
37818 \InsetSpace ~
37819 \InsetSpace ~
37820
37821  99\InsetSpace ~
37822 \InsetSpace ~
37823 \InsetSpace ~
37824 \InsetSpace ~
37825 \InsetSpace ~
37826 \InsetSpace ~
37827 \InsetSpace ~
37828 \InsetSpace ~
37829  mov\InsetSpace ~
37830 \InsetSpace ~
37831  (_foo_how2_1_1 + 1),(_glong + 2) 
37832 \end_layout
37833
37834 \begin_layout Standard
37835 Again, variations of these cases may 
37836 \emph on
37837 not
37838 \emph default
37839  be recognized.
37840  They are standard C expressions, so I heartily recommend these be the only
37841  way to get the higher order byte/word, (it is portable).
37842  Of course it will be recognized even if it is embedded in other expressions,
37843  e.g.:
37844 \end_layout
37845
37846 \begin_layout Verse
37847
37848 \family typewriter
37849 xyz = gint + ((gint >> 8) & 0xFF);
37850 \end_layout
37851
37852 \begin_layout Standard
37853 will still be recognized.
37854 \end_layout
37855
37856 \begin_layout Subsection
37857 Peephole Optimizer
37858 \begin_inset LatexCommand label
37859 name "sub:Peephole-Optimizer"
37860
37861 \end_inset
37862
37863
37864 \begin_inset LatexCommand index
37865 name "Peephole optimizer"
37866
37867 \end_inset
37868
37869
37870 \end_layout
37871
37872 \begin_layout Standard
37873 The compiler uses a rule based, pattern matching and re-writing mechanism
37874  for peep-hole optimization.
37875  It is inspired by 
37876 \emph on
37877 copt
37878 \emph default
37879  a peep-hole optimizer by Christopher W.
37880  Fraser (cwfraser\InsetSpace ~
37881 @\InsetSpace ~
37882 microsoft.com).
37883  A default set of rules are compiled into the compiler, additional rules
37884  may be added with the 
37885 \emph on
37886 -
37887 \begin_inset ERT
37888 status collapsed
37889
37890 \begin_layout Standard
37891
37892
37893 \backslash
37894 /
37895 \end_layout
37896
37897 \end_inset
37898
37899 -peep-file
37900 \begin_inset LatexCommand index
37901 name "-\\/-peep-file"
37902
37903 \end_inset
37904
37905  <filename>
37906 \emph default
37907  option.
37908  The rule language is best illustrated with examples.
37909 \end_layout
37910
37911 \begin_layout Verse
37912
37913 \family typewriter
37914 replace { 
37915 \newline
37916 \InsetSpace ~
37917 \InsetSpace ~
37918 mov %1,a 
37919 \newline
37920 \InsetSpace ~
37921 \InsetSpace ~
37922 mov a,%1
37923 \newline
37924 } by {
37925 \newline
37926 \InsetSpace ~
37927 \InsetSpace ~
37928 mov %1,a
37929 \newline
37930 }
37931 \end_layout
37932
37933 \begin_layout Standard
37934 The above rule will change the following assembly
37935 \begin_inset LatexCommand index
37936 name "Assembler routines"
37937
37938 \end_inset
37939
37940  sequence:
37941 \end_layout
37942
37943 \begin_layout Verse
37944
37945 \family typewriter
37946 mov r1,a 
37947 \newline
37948 mov a,r1
37949 \end_layout
37950
37951 \begin_layout Standard
37952 to
37953 \end_layout
37954
37955 \begin_layout Verse
37956
37957 \family typewriter
37958 mov r1,a
37959 \end_layout
37960
37961 \begin_layout Standard
37962 Note: All occurrences of a 
37963 \emph on
37964 %n
37965 \emph default
37966  (pattern variable) must denote the same string.
37967  With the above rule, the assembly sequence:
37968 \end_layout
37969
37970 \begin_layout Verse
37971
37972 \family typewriter
37973 mov r1,a 
37974 \newline
37975 mov a,r2
37976 \end_layout
37977
37978 \begin_layout Standard
37979 will remain unmodified.
37980 \newline
37981
37982 \newline
37983 Other special case optimizations may be added by the
37984  user (via 
37985 \emph on
37986 -
37987 \begin_inset ERT
37988 status collapsed
37989
37990 \begin_layout Standard
37991
37992
37993 \backslash
37994 /
37995 \end_layout
37996
37997 \end_inset
37998
37999 -peep-file option
38000 \emph default
38001 ).
38002  E.g.
38003  some variants of the 8051 MCU
38004 \begin_inset LatexCommand index
38005 name "MCS51 variants"
38006
38007 \end_inset
38008
38009  allow only 
38010 \family typewriter
38011 ajmp
38012 \family default
38013  and 
38014 \family typewriter
38015 acall
38016 \family default
38017 .
38018  The following two rules will change all 
38019 \family typewriter
38020 ljmp
38021 \family default
38022  and 
38023 \family typewriter
38024 lcall
38025 \family default
38026  to 
38027 \family typewriter
38028 ajmp
38029 \family default
38030  and 
38031 \family typewriter
38032 acall
38033 \end_layout
38034
38035 \begin_layout Verse
38036
38037 \family typewriter
38038 replace { lcall %1 } by { acall %1 } 
38039 \newline
38040 replace { ljmp %1 } by { ajmp %1 }
38041 \end_layout
38042
38043 \begin_layout Standard
38044 (NOTE: from version 2.7.3 on, you can use option -
38045 \emph on
38046
38047 \begin_inset ERT
38048 status collapsed
38049
38050 \begin_layout Standard
38051
38052
38053 \backslash
38054 /
38055 \end_layout
38056
38057 \end_inset
38058
38059
38060 \emph default
38061 -acall-ajmp
38062 \begin_inset LatexCommand index
38063 name "-\\/-acall-ajmp"
38064
38065 \end_inset
38066
38067 , which also takes care of aligning the interrupt vectors properly.)
38068 \newline
38069
38070 \end_layout
38071
38072 \begin_layout Standard
38073 The 
38074 \emph on
38075 inline-assembler code
38076 \emph default
38077  is also passed through the peep hole optimizer, thus the peephole optimizer
38078  can also be used as an assembly level macro expander.
38079  The rules themselves are MCU dependent whereas the rule language infra-structur
38080 e is MCU independent.
38081  Peephole optimization rules for other MCU can be easily programmed using
38082  the rule language.
38083 \newline
38084
38085 \newline
38086 The syntax for a rule is as follows:
38087 \end_layout
38088
38089 \begin_layout Verse
38090
38091 \family typewriter
38092 rule := replace [ restart ] '{' <assembly sequence> '
38093 \backslash
38094 n' 
38095 \newline
38096 \InsetSpace ~
38097  \InsetSpace ~
38098  \InsetSpace ~
38099  \InsetSpace ~
38100  \InsetSpace ~
38101  \InsetSpace ~
38102  \InsetSpace ~
38103  \InsetSpace ~
38104  \InsetSpace ~
38105  \InsetSpace ~
38106  \InsetSpace ~
38107  \InsetSpace ~
38108  \InsetSpace ~
38109  \InsetSpace ~
38110  '}' by '{' '
38111 \backslash
38112 n' 
38113 \newline
38114 \InsetSpace ~
38115  \InsetSpace ~
38116  \InsetSpace ~
38117  \InsetSpace ~
38118  \InsetSpace ~
38119  \InsetSpace ~
38120  \InsetSpace ~
38121  \InsetSpace ~
38122  \InsetSpace ~
38123  \InsetSpace ~
38124  \InsetSpace ~
38125  \InsetSpace ~
38126  \InsetSpace ~
38127  \InsetSpace ~
38128  \InsetSpace ~
38129  \InsetSpace ~
38130  <assembly sequence> '
38131 \backslash
38132 n' 
38133 \newline
38134 \InsetSpace ~
38135  \InsetSpace ~
38136  \InsetSpace ~
38137  \InsetSpace ~
38138  \InsetSpace ~
38139  \InsetSpace ~
38140  \InsetSpace ~
38141  \InsetSpace ~
38142  \InsetSpace ~
38143  \InsetSpace ~
38144  \InsetSpace ~
38145  \InsetSpace ~
38146  \InsetSpace ~
38147  \InsetSpace ~
38148  '}' [if <functionName> ] '
38149 \backslash
38150 n' 
38151 \end_layout
38152
38153 \begin_layout Standard
38154 <assembly sequence> := assembly instruction (each instruction including
38155  labels must be on a separate line).
38156 \newline
38157
38158 \newline
38159 The optimizer will apply to the rules
38160  one by one from the top in the sequence of their appearance, it will terminate
38161  when all rules are exhausted.
38162  If the 'restart' option is specified, then the optimizer will start matching
38163  the rules again from the top, this option for a rule is expensive (performance)
38164 , it is intended to be used in situations where a transformation will trigger
38165  the same rule again.
38166  An example of this (not a good one, it has side effects) is the following
38167  rule:
38168 \end_layout
38169
38170 \begin_layout Verse
38171
38172 \family typewriter
38173 replace restart { 
38174 \newline
38175 \InsetSpace ~
38176 \InsetSpace ~
38177 pop %1 
38178 \newline
38179 \InsetSpace ~
38180 \InsetSpace ~
38181 push %1 } by { 
38182 \newline
38183 \InsetSpace ~
38184 \InsetSpace ~
38185 ; nop 
38186 \newline
38187 }
38188 \end_layout
38189
38190 \begin_layout Standard
38191 Note that the replace pattern cannot be a blank, but can be a comment line.
38192  Without the 'restart' option only the innermost 'pop' 'push' pair would
38193  be eliminated, i.e.:
38194 \end_layout
38195
38196 \begin_layout Verse
38197
38198 \family typewriter
38199 pop ar1 
38200 \newline
38201 pop ar2 
38202 \newline
38203 push ar2 
38204 \newline
38205 push ar1
38206 \end_layout
38207
38208 \begin_layout Standard
38209 would result in:
38210 \end_layout
38211
38212 \begin_layout Verse
38213
38214 \family typewriter
38215 pop ar1 
38216 \newline
38217 ; nop 
38218 \newline
38219 push ar1
38220 \end_layout
38221
38222 \begin_layout Standard
38223
38224 \emph on
38225 with
38226 \emph default
38227  the restart option the rule will be applied again to the resulting code
38228  and then all the pop-push pairs will be eliminated to yield:
38229 \end_layout
38230
38231 \begin_layout Verse
38232
38233 \family typewriter
38234 ; nop 
38235 \newline
38236 ; nop
38237 \end_layout
38238
38239 \begin_layout Standard
38240 A conditional function can be attached to a rule.
38241  Attaching rules are somewhat more involved, let me illustrate this with
38242  an example.
38243 \end_layout
38244
38245 \begin_layout Verse
38246
38247 \family typewriter
38248 replace { 
38249 \newline
38250 \InsetSpace ~
38251  \InsetSpace ~
38252  \InsetSpace ~
38253 ljmp %5 
38254 \newline
38255 %2:
38256 \newline
38257 } by { 
38258 \newline
38259 \InsetSpace ~
38260  \InsetSpace ~
38261  \InsetSpace ~
38262 sjmp %5 
38263 \newline
38264 %2:
38265 \newline
38266 } if labelInRange
38267 \end_layout
38268
38269 \begin_layout Standard
38270 The optimizer does a look-up of a function name table defined in function
38271  
38272 \emph on
38273 callFuncByName
38274 \emph default
38275  in the source file SDCCpeeph.c, with the name 
38276 \emph on
38277 labelInRange
38278 \emph default
38279 .
38280  If it finds a corresponding entry the function is called.
38281  Note there can be no parameters specified for these functions, in this
38282  case the use of 
38283 \emph on
38284 %5
38285 \emph default
38286  is crucial, since the function 
38287 \emph on
38288 labelInRange
38289 \emph default
38290  expects to find the label in that particular variable (the hash table containin
38291 g the variable bindings is passed as a parameter).
38292  If you want to code more such functions, take a close look at the function
38293  labelInRange and the calling mechanism in source file SDCCpeeph.c.
38294  Currently implemented are 
38295 \emph on
38296 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
38297  24bitMode, portIsDS390, 24bitModeAndPortDS390
38298 \emph default
38299  and 
38300 \emph on
38301 notVolatile
38302 \emph default
38303 .
38304 \end_layout
38305
38306 \begin_layout Standard
38307 I know this whole thing is a little kludgey, but maybe some day we will
38308  have some better means.
38309  If you are looking at this file, you will see the default rules that are
38310  compiled into the compiler, you can add your own rules in the default set
38311  there if you get tired of specifying the -
38312 \begin_inset ERT
38313 status collapsed
38314
38315 \begin_layout Standard
38316
38317
38318 \backslash
38319 /
38320 \end_layout
38321
38322 \end_inset
38323
38324 -peep-file option.
38325 \end_layout
38326
38327 \begin_layout Section
38328 ANSI-Compliance
38329 \begin_inset LatexCommand index
38330 name "ANSI-compliance"
38331
38332 \end_inset
38333
38334
38335 \begin_inset LatexCommand label
38336 name "sub:ANSI-Compliance"
38337
38338 \end_inset
38339
38340
38341 \end_layout
38342
38343 \begin_layout Standard
38344 The latest publicly available version of the standard 
38345 \emph on
38346 ISO/IEC 9899 - Programming languages - C
38347 \emph default
38348  should be available at: 
38349 \begin_inset LatexCommand url
38350 target "http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899"
38351
38352 \end_inset
38353
38354 .
38355 \newline
38356
38357 \end_layout
38358
38359 \begin_layout Standard
38360 Deviations from the compliance:
38361 \end_layout
38362
38363 \begin_layout Itemize
38364 functions are not reentrant
38365 \begin_inset LatexCommand index
38366 name "reentrant"
38367
38368 \end_inset
38369
38370  unless explicitly declared as such or the 
38371 \series bold
38372 -
38373 \begin_inset ERT
38374 status collapsed
38375
38376 \begin_layout Standard
38377
38378
38379 \backslash
38380 /
38381 \end_layout
38382
38383 \end_inset
38384
38385 -stack-auto
38386 \begin_inset LatexCommand index
38387 name "-\\/-stack-auto"
38388
38389 \end_inset
38390
38391
38392 \series default
38393  command line option is specified.
38394 \end_layout
38395
38396 \begin_layout Itemize
38397 structures
38398 \begin_inset LatexCommand index
38399 name "struct"
38400
38401 \end_inset
38402
38403  and unions
38404 \begin_inset LatexCommand index
38405 name "union"
38406
38407 \end_inset
38408
38409  cannot be assigned values directly, cannot be passed as function parameters
38410  or assigned to each other and cannot be a return value
38411 \begin_inset LatexCommand index
38412 name "return value"
38413
38414 \end_inset
38415
38416  from a function, e.g.:
38417 \end_layout
38418
38419 \begin_deeper
38420 \begin_layout Verse
38421
38422 \family typewriter
38423 struct s { ...
38424  }; 
38425 \newline
38426 struct s s1, s2; 
38427 \newline
38428 foo() 
38429 \newline
38430
38431 \newline
38432 \InsetSpace ~
38433 \InsetSpace ~
38434 \InsetSpace ~
38435 \InsetSpace ~
38436 ...
38437  
38438 \newline
38439 \InsetSpace ~
38440 \InsetSpace ~
38441 \InsetSpace ~
38442 \InsetSpace ~
38443 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
38444 \newline
38445 \InsetSpace ~
38446 \InsetSpace ~
38447 \InsetSpace ~
38448 \InsetSpace ~
38449 ...
38450  
38451 \newline
38452 }
38453 \newline
38454
38455 \series bold
38456 struct
38457 \family default
38458 \series default
38459  
38460 \family typewriter
38461 s foo1 (
38462 \series bold
38463 struct
38464 \family default
38465 \series default
38466  
38467 \family typewriter
38468 s parms) /* invalid in SDCC although allowed in ANSI */
38469 \newline
38470
38471 \newline
38472 \InsetSpace ~
38473 \InsetSpace ~
38474 \InsetSpace ~
38475 \InsetSpace ~
38476 struct s rets;
38477  
38478 \newline
38479 \InsetSpace ~
38480 \InsetSpace ~
38481 \InsetSpace ~
38482 \InsetSpace ~
38483 ...
38484  
38485 \newline
38486 \InsetSpace ~
38487 \InsetSpace ~
38488 \InsetSpace ~
38489 \InsetSpace ~
38490 return rets; /* is invalid in SDCC although allowed in ANSI */ 
38491 \newline
38492 }
38493 \end_layout
38494
38495 \end_deeper
38496 \begin_layout Itemize
38497 initialization of structure arrays must be fully braced.
38498 \end_layout
38499
38500 \begin_deeper
38501 \begin_layout Verse
38502
38503 \family typewriter
38504 struct s { char x } a[] = {1, 2};\InsetSpace ~
38505 \InsetSpace ~
38506 \InsetSpace ~
38507 \InsetSpace ~
38508 \InsetSpace ~
38509 /* invalid in SDCC */
38510 \newline
38511 struct s { char x
38512  } a[] = {{1}, {2}}; /* OK */
38513 \end_layout
38514
38515 \end_deeper
38516 \begin_layout Itemize
38517 'long long
38518 \begin_inset LatexCommand index
38519 name "long long (not supported)"
38520
38521 \end_inset
38522
38523 ' (64 bit integers
38524 \begin_inset LatexCommand index
38525 name "int (64 bit) (not supported)"
38526
38527 \end_inset
38528
38529 ) not supported.
38530 \end_layout
38531
38532 \begin_layout Itemize
38533 'double
38534 \begin_inset LatexCommand index
38535 name "double (not supported)"
38536
38537 \end_inset
38538
38539 ' precision floating point 
38540 \begin_inset LatexCommand index
38541 name "Floating point support"
38542
38543 \end_inset
38544
38545 not supported.
38546 \end_layout
38547
38548 \begin_layout Itemize
38549 Old K&R style
38550 \begin_inset LatexCommand index
38551 name "K\\&R style"
38552
38553 \end_inset
38554
38555  function declarations are NOT allowed.
38556 \end_layout
38557
38558 \begin_deeper
38559 \begin_layout Verse
38560
38561 \family typewriter
38562 foo(i,j) /* this old style of function declarations */ 
38563 \newline
38564 int i,j; /* is valid
38565  in ANSI but not valid in SDCC */ 
38566 \newline
38567
38568 \newline
38569 \InsetSpace ~
38570 \InsetSpace ~
38571 \InsetSpace ~
38572 \InsetSpace ~
38573 ...
38574  
38575 \newline
38576 }
38577 \end_layout
38578
38579 \end_deeper
38580 \begin_layout Itemize
38581 Most enhancements in C99 are not supported, e.g.:
38582 \end_layout
38583
38584 \begin_deeper
38585 \begin_layout Verse
38586
38587 \family typewriter
38588 for (
38589 \series bold
38590 int
38591 \family default
38592 \series default
38593  
38594 \family typewriter
38595 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
38596 \end_layout
38597
38598 \end_deeper
38599 \begin_layout Itemize
38600 But some have been added recently in SDCC 2.7.0.
38601  They must be considered alpha quality however.
38602 \end_layout
38603
38604 \begin_deeper
38605 \begin_layout Verse
38606
38607 \family typewriter
38608 \series bold
38609 inline
38610 \begin_inset LatexCommand index
38611 name "inline (not supported)"
38612
38613 \end_inset
38614
38615
38616 \family default
38617 \series default
38618  
38619 \family typewriter
38620 int increment (int a) { return a+1; } /* inlines the increment without function
38621  call overhead */
38622 \newline
38623 int *
38624 \family default
38625  
38626 \family typewriter
38627 \series bold
38628 restrict
38629 \begin_inset LatexCommand index
38630 name "inline (not supported)"
38631
38632 \end_inset
38633
38634
38635 \family default
38636 \series default
38637  
38638 \family typewriter
38639 p; /* accepted but ignored */
38640 \end_layout
38641
38642 \end_deeper
38643 \begin_layout Itemize
38644 Certain words that are valid identifiers in the standard may be reserved
38645  words in SDCC unless the 
38646 \series bold
38647 -
38648 \begin_inset ERT
38649 status collapsed
38650
38651 \begin_layout Standard
38652
38653
38654 \backslash
38655 /
38656 \end_layout
38657
38658 \end_inset
38659
38660 -std-c89
38661 \begin_inset LatexCommand index
38662 name "-\\/-std-c89"
38663
38664 \end_inset
38665
38666
38667 \series default
38668  or 
38669 \series bold
38670 -
38671 \begin_inset ERT
38672 status collapsed
38673
38674 \begin_layout Standard
38675
38676
38677 \backslash
38678 /
38679 \end_layout
38680
38681 \end_inset
38682
38683 -std-c99
38684 \begin_inset LatexCommand index
38685 name "-\\/-std-c99"
38686
38687 \end_inset
38688
38689
38690 \series default
38691  command line options are used.
38692  These may include (depending on the selected processor): 'at', 'banked',
38693  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
38694 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
38695  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
38696  '_naked'.
38697  Compliant equivalents of these keywords are always available in a form
38698  that begin with two underscores
38699 \begin_inset LatexCommand index
38700 name "\\_\\_ (prefix for extended keywords)"
38701
38702 \end_inset
38703
38704 , f.e.
38705  '__data' instead of 'data'.
38706 \end_layout
38707
38708 \begin_layout Itemize
38709 Integer promotion of variable arguments is not performed if the argument
38710  is explicitly taypecasted unless the 
38711 \series bold
38712 -
38713 \begin_inset ERT
38714 status collapsed
38715
38716 \begin_layout Standard
38717
38718
38719 \backslash
38720 /
38721 \end_layout
38722
38723 \end_inset
38724
38725 -std-c89
38726 \begin_inset LatexCommand index
38727 name "-\\/-std-c89"
38728
38729 \end_inset
38730
38731
38732 \series default
38733  or 
38734 \series bold
38735 -
38736 \begin_inset ERT
38737 status collapsed
38738
38739 \begin_layout Standard
38740
38741
38742 \backslash
38743 /
38744 \end_layout
38745
38746 \end_inset
38747
38748 -std-c99
38749 \begin_inset LatexCommand index
38750 name "-\\/-std-c99"
38751
38752 \end_inset
38753
38754
38755 \series default
38756  command line options are used.
38757 \end_layout
38758
38759 \begin_deeper
38760 \begin_layout Verse
38761
38762 \family typewriter
38763 void vararg_func (char *str, ...) { str; }
38764 \newline
38765
38766 \newline
38767 void main (void)
38768 \newline
38769 {
38770 \newline
38771 \InsetSpace ~
38772 \InsetSpace ~
38773 char c = 10;
38774 \newline
38775
38776 \newline
38777 \InsetSpace ~
38778 \InsetSpace ~
38779 /* argument
38780  u is promoted to int before
38781 \newline
38782 \InsetSpace ~
38783 \InsetSpace ~
38784 \InsetSpace ~
38785 * passing to function */
38786 \newline
38787 \InsetSpace ~
38788 \InsetSpace ~
38789 vararg_func ("%c", c);
38790 \newline
38791
38792 \newline
38793 \InsetSpace ~
38794 \InsetSpace ~
38795 /*
38796  argument u is not promoted to int,
38797 \newline
38798 \InsetSpace ~
38799 \InsetSpace ~
38800 \InsetSpace ~
38801 * it is passed as char to function
38802 \newline
38803 \InsetSpace ~
38804 \InsetSpace ~
38805 \InsetSpace ~
38806 * if
38807  --std-cXX is not defined;
38808 \newline
38809 \InsetSpace ~
38810 \InsetSpace ~
38811 \InsetSpace ~
38812 * is promoted to int before passing
38813 \newline
38814 \InsetSpace ~
38815 \InsetSpace ~
38816 \InsetSpace ~
38817 * to function
38818  if --std-cXX is defined */
38819 \newline
38820 \InsetSpace ~
38821 \InsetSpace ~
38822 vararg_func ("%bc", (char)u);
38823 \newline
38824 }
38825 \end_layout
38826
38827 \end_deeper
38828 \begin_layout Section
38829 Cyclomatic Complexity
38830 \begin_inset LatexCommand index
38831 name "Cyclomatic complexity"
38832
38833 \end_inset
38834
38835
38836 \end_layout
38837
38838 \begin_layout Standard
38839 Cyclomatic complexity of a function is defined as the number of independent
38840  paths the program can take during execution of the function.
38841  This is an important number since it defines the number test cases you
38842  have to generate to validate the function.
38843  The accepted industry standard for complexity number is 10, if the cyclomatic
38844  complexity reported by SDCC exceeds 10 you should think about simplification
38845  of the function logic.
38846  Note that the complexity level is not related to the number of lines of
38847  code in a function.
38848  Large functions can have low complexity, and small functions can have large
38849  complexity levels.
38850  
38851 \newline
38852
38853 \newline
38854 SDCC uses the following formula to compute the complexity:
38855 \newline
38856
38857 \end_layout
38858
38859 \begin_layout Standard
38860 complexity = (number of edges in control flow graph) - (number of nodes
38861  in control flow graph) + 2;
38862 \newline
38863
38864 \newline
38865 Having said that the industry standard is 10,
38866  you should be aware that in some cases it be may unavoidable to have a
38867  complexity level of less than 10.
38868  For example if you have switch statement with more than 10 case labels,
38869  each case label adds one to the complexity level.
38870  The complexity level is by no means an absolute measure of the algorithmic
38871  complexity of the function, it does however provide a good starting point
38872  for which functions you might look at for further optimization.
38873 \end_layout
38874
38875 \begin_layout Section
38876 Retargetting for other Processors
38877 \end_layout
38878
38879 \begin_layout Standard
38880 The issues for retargetting the compiler are far too numerous to be covered
38881  by this document.
38882  What follows is a brief description of each of the seven phases of the
38883  compiler and its MCU dependency.
38884 \end_layout
38885
38886 \begin_layout Itemize
38887 Parsing the source and building the annotated parse tree.
38888  This phase is largely MCU independent (except for the language extensions).
38889  Syntax & semantic checks are also done in this phase, along with some initial
38890  optimizations like back patching labels and the pattern matching optimizations
38891  like bit-rotation etc.
38892 \end_layout
38893
38894 \begin_layout Itemize
38895 The second phase involves generating an intermediate code which can be easy
38896  manipulated during the later phases.
38897  This phase is entirely MCU independent.
38898  The intermediate code generation assumes the target machine has unlimited
38899  number of registers, and designates them with the name iTemp.
38900  The compiler can be made to dump a human readable form of the code generated
38901  by using the -
38902 \begin_inset ERT
38903 status collapsed
38904
38905 \begin_layout Standard
38906
38907
38908 \backslash
38909 /
38910 \end_layout
38911
38912 \end_inset
38913
38914 -dumpraw option.
38915 \end_layout
38916
38917 \begin_layout Itemize
38918 This phase does the bulk of the standard optimizations and is also MCU independe
38919 nt.
38920  This phase can be broken down into several sub-phases:
38921 \newline
38922
38923 \newline
38924 Break down intermediate
38925  code (iCode) into basic blocks.
38926 \newline
38927 Do control flow & data flow analysis on the
38928  basic blocks.
38929 \newline
38930 Do local common subexpression elimination, then global subexpressio
38931 n elimination
38932 \newline
38933 Dead code elimination
38934 \newline
38935 Loop optimizations
38936 \newline
38937 If loop optimizations
38938  caused any changes then do 'global subexpression elimination' and 'dead
38939  code elimination' again.
38940 \end_layout
38941
38942 \begin_layout Itemize
38943 This phase determines the live-ranges; by live range I mean those iTemp
38944  variables defined by the compiler that still survive after all the optimization
38945 s.
38946  Live range analysis
38947 \begin_inset LatexCommand index
38948 name "Live range analysis"
38949
38950 \end_inset
38951
38952  is essential for register allocation, since these computation determines
38953  which of these iTemps will be assigned to registers, and for how long.
38954 \end_layout
38955
38956 \begin_layout Itemize
38957 Phase five is register allocation.
38958  There are two parts to this process.
38959 \newline
38960
38961 \newline
38962 The first part I call 'register packing'
38963  (for lack of a better term).
38964  In this case several MCU specific expression folding is done to reduce
38965  register pressure.
38966 \newline
38967
38968 \newline
38969 The second part is more MCU independent and deals with
38970  allocating registers to the remaining live ranges.
38971  A lot of MCU specific code does creep into this phase because of the limited
38972  number of index registers available in the 8051.
38973 \end_layout
38974
38975 \begin_layout Itemize
38976 The Code generation phase is (unhappily), entirely MCU dependent and very
38977  little (if any at all) of this code can be reused for other MCU.
38978  However the scheme for allocating a homogenized assembler operand for each
38979  iCode operand may be reused.
38980 \end_layout
38981
38982 \begin_layout Itemize
38983 As mentioned in the optimization section the peep-hole optimizer is rule
38984  based system, which can reprogrammed for other MCUs.
38985 \end_layout
38986
38987 \begin_layout Standard
38988 More information is available on SDCC Wiki
38989 \begin_inset LatexCommand index
38990 name "wiki"
38991
38992 \end_inset
38993
38994  (preliminary link 
38995 \begin_inset LatexCommand url
38996 target "http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting"
38997
38998 \end_inset
38999
39000 ) and in the thread 
39001 \begin_inset LatexCommand url
39002 target "http://sf.net/mailarchive/message.php?msg_id=13954144"
39003
39004 \end_inset
39005
39006  .
39007 \end_layout
39008
39009 \begin_layout Chapter
39010 Compiler internals
39011 \begin_inset LatexCommand index
39012 name "Compiler internals"
39013
39014 \end_inset
39015
39016
39017 \end_layout
39018
39019 \begin_layout Section
39020 The anatomy of the compiler
39021 \begin_inset LatexCommand label
39022 name "sub:The-anatomy-of"
39023
39024 \end_inset
39025
39026
39027 \end_layout
39028
39029 \begin_layout Standard
39030
39031 \shape italic
39032 This is an excerpt from an article published in Circuit Cellar Magazine
39033  in
39034 \shape default
39035  
39036 \series bold
39037 \shape italic
39038 August 2000
39039 \series default
39040 .
39041  It's a little outdated (the compiler is much more efficient now and user/develo
39042 per friendly), but pretty well exposes the guts of it all.
39043 \shape default
39044
39045 \newline
39046
39047 \newline
39048 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
39049  It is fairly easy to retarget for other 8-bit MCU.
39050  Here we take a look at some of the internals of the compiler.
39051  
39052 \end_layout
39053
39054 \begin_layout Paragraph*
39055 Parsing
39056 \begin_inset LatexCommand index
39057 name "Parsing"
39058
39059 \end_inset
39060
39061  
39062 \end_layout
39063
39064 \begin_layout Standard
39065 Parsing the input source file and creating an AST (Annotated Syntax Tree
39066 \begin_inset LatexCommand index
39067 name "Annotated syntax tree"
39068
39069 \end_inset
39070
39071 ).
39072  This phase also involves propagating types (annotating each node of the
39073  parse tree with type information) and semantic analysis.
39074  There are some MCU specific parsing rules.
39075  For example the storage classes, the extended storage classes are MCU specific
39076  while there may be a xdata storage class for 8051 there is no such storage
39077  class for z80 or Atmel AVR.
39078  SDCC allows MCU specific storage class extensions, i.e.
39079  xdata will be treated as a storage class specifier when parsing 8051 C
39080  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
39081  C code.
39082 \end_layout
39083
39084 \begin_layout Paragraph*
39085 Generating iCode
39086 \begin_inset LatexCommand index
39087 name "iCode"
39088
39089 \end_inset
39090
39091
39092 \end_layout
39093
39094 \begin_layout Standard
39095 Intermediate code generation.
39096  In this phase the AST is broken down into three-operand form (iCode).
39097  These three operand forms are represented as doubly linked lists.
39098  ICode is the term given to the intermediate form generated by the compiler.
39099  ICode example section shows some examples of iCode generated for some simple
39100  C source functions.
39101 \end_layout
39102
39103 \begin_layout Paragraph*
39104 Optimizations
39105 \begin_inset LatexCommand index
39106 name "Optimizations"
39107
39108 \end_inset
39109
39110 .
39111 \end_layout
39112
39113 \begin_layout Standard
39114 Bulk of the target independent optimizations is performed in this phase.
39115  The optimizations include constant propagation, common sub-expression eliminati
39116 on, loop invariant code movement, strength reduction of loop induction variables
39117  and dead-code elimination.
39118 \end_layout
39119
39120 \begin_layout Paragraph*
39121 Live range analysis
39122 \begin_inset LatexCommand index
39123 name "Live range analysis"
39124
39125 \end_inset
39126
39127
39128 \end_layout
39129
39130 \begin_layout Standard
39131 During intermediate code generation phase, the compiler assumes the target
39132  machine has infinite number of registers and generates a lot of temporary
39133  variables.
39134  The live range computation determines the lifetime of each of these compiler-ge
39135 nerated temporaries.
39136  A picture speaks a thousand words.
39137  ICode example sections show the live range annotations for each of the
39138  operand.
39139  It is important to note here, each iCode is assigned a number in the order
39140  of its execution in the function.
39141  The live ranges are computed in terms of these numbers.
39142  The from number is the number of the iCode which first defines the operand
39143  and the to number signifies the iCode which uses this operand last.
39144 \end_layout
39145
39146 \begin_layout Paragraph*
39147 Register Allocation
39148 \begin_inset LatexCommand index
39149 name "Register allocation"
39150
39151 \end_inset
39152
39153
39154 \end_layout
39155
39156 \begin_layout Standard
39157 The register allocation determines the type and number of registers needed
39158  by each operand.
39159  In most MCUs only a few registers can be used for indirect addressing.
39160  In case of 8051 for example the registers R0 & R1 can be used to indirectly
39161  address the internal ram and DPTR to indirectly address the external ram.
39162  The compiler will try to allocate the appropriate register to pointer variables
39163  if it can.
39164  ICode example section shows the operands annotated with the registers assigned
39165  to them.
39166  The compiler will try to keep operands in registers as much as possible;
39167  there are several schemes the compiler uses to do achieve this.
39168  When the compiler runs out of registers the compiler will check to see
39169  if there are any live operands which is not used or defined in the current
39170  basic block being processed, if there are any found then it will push that
39171  operand and use the registers in this block, the operand will then be popped
39172  at the end of the basic block.
39173  
39174 \end_layout
39175
39176 \begin_layout Standard
39177 There are other MCU specific considerations in this phase.
39178  Some MCUs have an accumulator; very short-lived operands could be assigned
39179  to the accumulator instead of a general-purpose register.
39180 \end_layout
39181
39182 \begin_layout Paragraph*
39183 Code generation
39184 \end_layout
39185
39186 \begin_layout Standard
39187 Figure II gives a table of iCode
39188 \begin_inset LatexCommand index
39189 name "iCode"
39190
39191 \end_inset
39192
39193  operations supported by the compiler.
39194  The code generation involves translating these operations into corresponding
39195  assembly code for the processor.
39196  This sounds overly simple but that is the essence of code generation.
39197  Some of the iCode operations are generated on a MCU specific manner for
39198  example, the z80 port does not use registers to pass parameters so the
39199  SEND and RECV iCode operations will not be generated, and it also does
39200  not support JUMPTABLES.
39201  
39202 \newline
39203
39204 \end_layout
39205
39206 \begin_layout Standard
39207
39208 \size footnotesize
39209 Figure II 
39210 \begin_inset Tabular
39211 <lyxtabular version="3" rows="39" columns="4">
39212 <features islongtable="true" headBottomDL="true">
39213 <column alignment="block" valignment="top" leftline="true" width="13col%">
39214 <column alignment="left" valignment="top" leftline="true" width="13col%">
39215 <column alignment="block" valignment="top" leftline="true" width="22col%">
39216 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
39217 <row topline="true" bottomline="true" endhead="true">
39218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39219 \begin_inset Text
39220
39221 \begin_layout Standard
39222
39223 \series bold
39224 iCode
39225 \series default
39226
39227 \begin_inset LatexCommand index
39228 name "iCode"
39229
39230 \end_inset
39231
39232
39233 \end_layout
39234
39235 \end_inset
39236 </cell>
39237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39238 \begin_inset Text
39239
39240 \begin_layout Standard
39241
39242 \series bold
39243 Operands
39244 \end_layout
39245
39246 \end_inset
39247 </cell>
39248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39249 \begin_inset Text
39250
39251 \begin_layout Standard
39252
39253 \series bold
39254 Description
39255 \end_layout
39256
39257 \end_inset
39258 </cell>
39259 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39260 \begin_inset Text
39261
39262 \begin_layout Standard
39263
39264 \series bold
39265 C Equivalent
39266 \end_layout
39267
39268 \end_inset
39269 </cell>
39270 </row>
39271 <row topline="true">
39272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39273 \begin_inset Text
39274
39275 \begin_layout Standard
39276
39277 \size footnotesize
39278 '!'
39279 \end_layout
39280
39281 \end_inset
39282 </cell>
39283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39284 \begin_inset Text
39285
39286 \begin_layout Standard
39287
39288 \size footnotesize
39289 IC_LEFT() IC_RESULT()
39290 \end_layout
39291
39292 \end_inset
39293 </cell>
39294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39295 \begin_inset Text
39296
39297 \begin_layout Standard
39298
39299 \size footnotesize
39300 NOT operation 
39301 \end_layout
39302
39303 \end_inset
39304 </cell>
39305 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39306 \begin_inset Text
39307
39308 \begin_layout Standard
39309
39310 \size footnotesize
39311 IC_RESULT = ! IC_LEFT;
39312 \end_layout
39313
39314 \end_inset
39315 </cell>
39316 </row>
39317 <row topline="true">
39318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39319 \begin_inset Text
39320
39321 \begin_layout Standard
39322
39323 \size footnotesize
39324 '~'
39325 \end_layout
39326
39327 \end_inset
39328 </cell>
39329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39330 \begin_inset Text
39331
39332 \begin_layout Standard
39333
39334 \size footnotesize
39335 IC_LEFT() IC_RESULT()
39336 \end_layout
39337
39338 \end_inset
39339 </cell>
39340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39341 \begin_inset Text
39342
39343 \begin_layout Standard
39344
39345 \size footnotesize
39346 Bitwise complement of 
39347 \end_layout
39348
39349 \end_inset
39350 </cell>
39351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39352 \begin_inset Text
39353
39354 \begin_layout Standard
39355
39356 \size footnotesize
39357 IC_RESULT = ~IC_LEFT;
39358 \end_layout
39359
39360 \end_inset
39361 </cell>
39362 </row>
39363 <row topline="true">
39364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39365 \begin_inset Text
39366
39367 \begin_layout Standard
39368
39369 \size footnotesize
39370 RRC
39371 \end_layout
39372
39373 \end_inset
39374 </cell>
39375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39376 \begin_inset Text
39377
39378 \begin_layout Standard
39379
39380 \size footnotesize
39381 IC_LEFT() IC_RESULT()
39382 \end_layout
39383
39384 \end_inset
39385 </cell>
39386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39387 \begin_inset Text
39388
39389 \begin_layout Standard
39390
39391 \size footnotesize
39392 Rotate right with carry
39393 \end_layout
39394
39395 \end_inset
39396 </cell>
39397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39398 \begin_inset Text
39399
39400 \begin_layout Standard
39401
39402 \size footnotesize
39403 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
39404 \end_layout
39405
39406 \end_inset
39407 </cell>
39408 </row>
39409 <row topline="true">
39410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39411 \begin_inset Text
39412
39413 \begin_layout Standard
39414
39415 \size footnotesize
39416 RLC
39417 \end_layout
39418
39419 \end_inset
39420 </cell>
39421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39422 \begin_inset Text
39423
39424 \begin_layout Standard
39425
39426 \size footnotesize
39427 IC_LEFT() IC_RESULT()
39428 \end_layout
39429
39430 \end_inset
39431 </cell>
39432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39433 \begin_inset Text
39434
39435 \begin_layout Standard
39436
39437 \size footnotesize
39438 Rotate left with carry
39439 \end_layout
39440
39441 \end_inset
39442 </cell>
39443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39444 \begin_inset Text
39445
39446 \begin_layout Standard
39447
39448 \size footnotesize
39449 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
39450 \end_layout
39451
39452 \end_inset
39453 </cell>
39454 </row>
39455 <row topline="true">
39456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39457 \begin_inset Text
39458
39459 \begin_layout Standard
39460
39461 \size footnotesize
39462 GETHBIT
39463 \end_layout
39464
39465 \end_inset
39466 </cell>
39467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39468 \begin_inset Text
39469
39470 \begin_layout Standard
39471
39472 \size footnotesize
39473 IC_LEFT() IC_RESULT()
39474 \end_layout
39475
39476 \end_inset
39477 </cell>
39478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39479 \begin_inset Text
39480
39481 \begin_layout Standard
39482
39483 \size footnotesize
39484 Get the highest order bit of IC_LEFT
39485 \end_layout
39486
39487 \end_inset
39488 </cell>
39489 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39490 \begin_inset Text
39491
39492 \begin_layout Standard
39493
39494 \size footnotesize
39495 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
39496 \end_layout
39497
39498 \end_inset
39499 </cell>
39500 </row>
39501 <row topline="true">
39502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39503 \begin_inset Text
39504
39505 \begin_layout Standard
39506
39507 \size footnotesize
39508 UNARYMINUS
39509 \end_layout
39510
39511 \end_inset
39512 </cell>
39513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39514 \begin_inset Text
39515
39516 \begin_layout Standard
39517
39518 \size footnotesize
39519 IC_LEFT() IC_RESULT()
39520 \end_layout
39521
39522 \end_inset
39523 </cell>
39524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39525 \begin_inset Text
39526
39527 \begin_layout Standard
39528
39529 \size footnotesize
39530 Unary minus
39531 \end_layout
39532
39533 \end_inset
39534 </cell>
39535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39536 \begin_inset Text
39537
39538 \begin_layout Standard
39539
39540 \size footnotesize
39541 IC_RESULT = - IC_LEFT;
39542 \end_layout
39543
39544 \end_inset
39545 </cell>
39546 </row>
39547 <row topline="true">
39548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39549 \begin_inset Text
39550
39551 \begin_layout Standard
39552
39553 \size footnotesize
39554 IPUSH
39555 \end_layout
39556
39557 \end_inset
39558 </cell>
39559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39560 \begin_inset Text
39561
39562 \begin_layout Standard
39563
39564 \size footnotesize
39565 IC_LEFT()
39566 \end_layout
39567
39568 \end_inset
39569 </cell>
39570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39571 \begin_inset Text
39572
39573 \begin_layout Standard
39574
39575 \size footnotesize
39576 Push the operand into stack
39577 \end_layout
39578
39579 \end_inset
39580 </cell>
39581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39582 \begin_inset Text
39583
39584 \begin_layout Standard
39585
39586 \size footnotesize
39587 NONE
39588 \end_layout
39589
39590 \end_inset
39591 </cell>
39592 </row>
39593 <row topline="true">
39594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39595 \begin_inset Text
39596
39597 \begin_layout Standard
39598
39599 \size footnotesize
39600 IPOP
39601 \end_layout
39602
39603 \end_inset
39604 </cell>
39605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39606 \begin_inset Text
39607
39608 \begin_layout Standard
39609
39610 \size footnotesize
39611 IC_LEFT()
39612 \end_layout
39613
39614 \end_inset
39615 </cell>
39616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39617 \begin_inset Text
39618
39619 \begin_layout Standard
39620
39621 \size footnotesize
39622 Pop the operand from the stack 
39623 \end_layout
39624
39625 \end_inset
39626 </cell>
39627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39628 \begin_inset Text
39629
39630 \begin_layout Standard
39631
39632 \size footnotesize
39633 NONE
39634 \end_layout
39635
39636 \end_inset
39637 </cell>
39638 </row>
39639 <row topline="true">
39640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39641 \begin_inset Text
39642
39643 \begin_layout Standard
39644
39645 \size footnotesize
39646 CALL
39647 \end_layout
39648
39649 \end_inset
39650 </cell>
39651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39652 \begin_inset Text
39653
39654 \begin_layout Standard
39655
39656 \size footnotesize
39657 IC_LEFT() IC_RESULT()
39658 \end_layout
39659
39660 \end_inset
39661 </cell>
39662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39663 \begin_inset Text
39664
39665 \begin_layout Standard
39666
39667 \size footnotesize
39668 Call the function represented by IC_LEFT 
39669 \end_layout
39670
39671 \end_inset
39672 </cell>
39673 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39674 \begin_inset Text
39675
39676 \begin_layout Standard
39677
39678 \size footnotesize
39679 IC_RESULT = IC_LEFT();
39680 \end_layout
39681
39682 \end_inset
39683 </cell>
39684 </row>
39685 <row topline="true">
39686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39687 \begin_inset Text
39688
39689 \begin_layout Standard
39690
39691 \size footnotesize
39692 PCALL
39693 \end_layout
39694
39695 \end_inset
39696 </cell>
39697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39698 \begin_inset Text
39699
39700 \begin_layout Standard
39701
39702 \size footnotesize
39703 IC_LEFT() IC_RESULT()
39704 \end_layout
39705
39706 \end_inset
39707 </cell>
39708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39709 \begin_inset Text
39710
39711 \begin_layout Standard
39712
39713 \size footnotesize
39714 Call via function pointer
39715 \end_layout
39716
39717 \end_inset
39718 </cell>
39719 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39720 \begin_inset Text
39721
39722 \begin_layout Standard
39723
39724 \size footnotesize
39725 IC_RESULT = (*IC_LEFT)();
39726 \end_layout
39727
39728 \end_inset
39729 </cell>
39730 </row>
39731 <row topline="true">
39732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39733 \begin_inset Text
39734
39735 \begin_layout Standard
39736
39737 \size footnotesize
39738 RETURN
39739 \end_layout
39740
39741 \end_inset
39742 </cell>
39743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39744 \begin_inset Text
39745
39746 \begin_layout Standard
39747
39748 \size footnotesize
39749 IC_LEFT()
39750 \end_layout
39751
39752 \end_inset
39753 </cell>
39754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39755 \begin_inset Text
39756
39757 \begin_layout Standard
39758
39759 \size footnotesize
39760 Return the value in operand IC_LEFT 
39761 \end_layout
39762
39763 \end_inset
39764 </cell>
39765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39766 \begin_inset Text
39767
39768 \begin_layout Standard
39769
39770 \size footnotesize
39771 return IC_LEFT;
39772 \end_layout
39773
39774 \end_inset
39775 </cell>
39776 </row>
39777 <row topline="true">
39778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39779 \begin_inset Text
39780
39781 \begin_layout Standard
39782
39783 \size footnotesize
39784 LABEL
39785 \end_layout
39786
39787 \end_inset
39788 </cell>
39789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39790 \begin_inset Text
39791
39792 \begin_layout Standard
39793
39794 \size footnotesize
39795 IC_LABEL() 
39796 \end_layout
39797
39798 \end_inset
39799 </cell>
39800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39801 \begin_inset Text
39802
39803 \begin_layout Standard
39804
39805 \size footnotesize
39806 Label
39807 \end_layout
39808
39809 \end_inset
39810 </cell>
39811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39812 \begin_inset Text
39813
39814 \begin_layout Standard
39815
39816 \size footnotesize
39817 IC_LABEL:
39818 \end_layout
39819
39820 \end_inset
39821 </cell>
39822 </row>
39823 <row topline="true">
39824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39825 \begin_inset Text
39826
39827 \begin_layout Standard
39828
39829 \size footnotesize
39830 GOTO
39831 \end_layout
39832
39833 \end_inset
39834 </cell>
39835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39836 \begin_inset Text
39837
39838 \begin_layout Standard
39839
39840 \size footnotesize
39841 IC_LABEL() 
39842 \end_layout
39843
39844 \end_inset
39845 </cell>
39846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39847 \begin_inset Text
39848
39849 \begin_layout Standard
39850
39851 \size footnotesize
39852 Goto label
39853 \end_layout
39854
39855 \end_inset
39856 </cell>
39857 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39858 \begin_inset Text
39859
39860 \begin_layout Standard
39861
39862 \size footnotesize
39863 goto IC_LABEL();
39864 \end_layout
39865
39866 \end_inset
39867 </cell>
39868 </row>
39869 <row topline="true">
39870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39871 \begin_inset Text
39872
39873 \begin_layout Standard
39874
39875 \size footnotesize
39876 '+'
39877 \end_layout
39878
39879 \end_inset
39880 </cell>
39881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39882 \begin_inset Text
39883
39884 \begin_layout Standard
39885
39886 \size footnotesize
39887 IC_LEFT() IC_RIGHT() IC_RESULT()
39888 \end_layout
39889
39890 \end_inset
39891 </cell>
39892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39893 \begin_inset Text
39894
39895 \begin_layout Standard
39896
39897 \size footnotesize
39898 Addition
39899 \end_layout
39900
39901 \end_inset
39902 </cell>
39903 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39904 \begin_inset Text
39905
39906 \begin_layout Standard
39907
39908 \size footnotesize
39909 IC_RESULT = IC_LEFT + IC_RIGHT
39910 \end_layout
39911
39912 \end_inset
39913 </cell>
39914 </row>
39915 <row topline="true">
39916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39917 \begin_inset Text
39918
39919 \begin_layout Standard
39920
39921 \size footnotesize
39922 '-'
39923 \end_layout
39924
39925 \end_inset
39926 </cell>
39927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39928 \begin_inset Text
39929
39930 \begin_layout Standard
39931
39932 \size footnotesize
39933 IC_LEFT() IC_RIGHT() IC_RESULT()
39934 \end_layout
39935
39936 \end_inset
39937 </cell>
39938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39939 \begin_inset Text
39940
39941 \begin_layout Standard
39942
39943 \size footnotesize
39944 Subtraction
39945 \end_layout
39946
39947 \end_inset
39948 </cell>
39949 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39950 \begin_inset Text
39951
39952 \begin_layout Standard
39953
39954 \size footnotesize
39955 IC_RESULT = IC_LEFT - IC_RIGHT 
39956 \end_layout
39957
39958 \end_inset
39959 </cell>
39960 </row>
39961 <row topline="true">
39962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39963 \begin_inset Text
39964
39965 \begin_layout Standard
39966
39967 \size footnotesize
39968 '*'
39969 \end_layout
39970
39971 \end_inset
39972 </cell>
39973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39974 \begin_inset Text
39975
39976 \begin_layout Standard
39977
39978 \size footnotesize
39979 IC_LEFT() IC_RIGHT() IC_RESULT()
39980 \end_layout
39981
39982 \end_inset
39983 </cell>
39984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39985 \begin_inset Text
39986
39987 \begin_layout Standard
39988
39989 \size footnotesize
39990 Multiplication 
39991 \end_layout
39992
39993 \end_inset
39994 </cell>
39995 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39996 \begin_inset Text
39997
39998 \begin_layout Standard
39999
40000 \size footnotesize
40001 IC_RESULT = IC_LEFT * IC_RIGHT;
40002 \end_layout
40003
40004 \end_inset
40005 </cell>
40006 </row>
40007 <row topline="true">
40008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40009 \begin_inset Text
40010
40011 \begin_layout Standard
40012
40013 \size footnotesize
40014 '/'
40015 \end_layout
40016
40017 \end_inset
40018 </cell>
40019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40020 \begin_inset Text
40021
40022 \begin_layout Standard
40023
40024 \size footnotesize
40025 IC_LEFT() IC_RIGHT() IC_RESULT()
40026 \end_layout
40027
40028 \end_inset
40029 </cell>
40030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40031 \begin_inset Text
40032
40033 \begin_layout Standard
40034
40035 \size footnotesize
40036 Division
40037 \end_layout
40038
40039 \end_inset
40040 </cell>
40041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40042 \begin_inset Text
40043
40044 \begin_layout Standard
40045
40046 \size footnotesize
40047 IC_RESULT = IC_LEFT / IC_RIGHT;
40048 \end_layout
40049
40050 \end_inset
40051 </cell>
40052 </row>
40053 <row topline="true">
40054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40055 \begin_inset Text
40056
40057 \begin_layout Standard
40058
40059 \size footnotesize
40060 '%'
40061 \end_layout
40062
40063 \end_inset
40064 </cell>
40065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40066 \begin_inset Text
40067
40068 \begin_layout Standard
40069
40070 \size footnotesize
40071 IC_LEFT() IC_RIGHT() IC_RESULT()
40072 \end_layout
40073
40074 \end_inset
40075 </cell>
40076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40077 \begin_inset Text
40078
40079 \begin_layout Standard
40080
40081 \size footnotesize
40082 Modulus
40083 \end_layout
40084
40085 \end_inset
40086 </cell>
40087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40088 \begin_inset Text
40089
40090 \begin_layout Standard
40091
40092 \size footnotesize
40093 IC_RESULT = IC_LEFT % IC_RIGHT;
40094 \end_layout
40095
40096 \end_inset
40097 </cell>
40098 </row>
40099 <row topline="true">
40100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40101 \begin_inset Text
40102
40103 \begin_layout Standard
40104
40105 \size footnotesize
40106 '<'
40107 \end_layout
40108
40109 \end_inset
40110 </cell>
40111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40112 \begin_inset Text
40113
40114 \begin_layout Standard
40115
40116 \size footnotesize
40117 IC_LEFT() IC_RIGHT() IC_RESULT()
40118 \end_layout
40119
40120 \end_inset
40121 </cell>
40122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40123 \begin_inset Text
40124
40125 \begin_layout Standard
40126
40127 \size footnotesize
40128 Less than
40129 \end_layout
40130
40131 \end_inset
40132 </cell>
40133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40134 \begin_inset Text
40135
40136 \begin_layout Standard
40137
40138 \size footnotesize
40139 IC_RESULT = IC_LEFT < IC_RIGHT;
40140 \end_layout
40141
40142 \end_inset
40143 </cell>
40144 </row>
40145 <row topline="true">
40146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40147 \begin_inset Text
40148
40149 \begin_layout Standard
40150
40151 \size footnotesize
40152 '>'
40153 \end_layout
40154
40155 \end_inset
40156 </cell>
40157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40158 \begin_inset Text
40159
40160 \begin_layout Standard
40161
40162 \size footnotesize
40163 IC_LEFT() IC_RIGHT() IC_RESULT()
40164 \end_layout
40165
40166 \end_inset
40167 </cell>
40168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40169 \begin_inset Text
40170
40171 \begin_layout Standard
40172
40173 \size footnotesize
40174 Greater than 
40175 \end_layout
40176
40177 \end_inset
40178 </cell>
40179 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40180 \begin_inset Text
40181
40182 \begin_layout Standard
40183
40184 \size footnotesize
40185 IC_RESULT = IC_LEFT > IC_RIGHT;
40186 \end_layout
40187
40188 \end_inset
40189 </cell>
40190 </row>
40191 <row topline="true">
40192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40193 \begin_inset Text
40194
40195 \begin_layout Standard
40196
40197 \size footnotesize
40198 EQ_OP
40199 \end_layout
40200
40201 \end_inset
40202 </cell>
40203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40204 \begin_inset Text
40205
40206 \begin_layout Standard
40207
40208 \size footnotesize
40209 IC_LEFT() IC_RIGHT() IC_RESULT()
40210 \end_layout
40211
40212 \end_inset
40213 </cell>
40214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40215 \begin_inset Text
40216
40217 \begin_layout Standard
40218
40219 \size footnotesize
40220 Equal to 
40221 \end_layout
40222
40223 \end_inset
40224 </cell>
40225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40226 \begin_inset Text
40227
40228 \begin_layout Standard
40229
40230 \size footnotesize
40231 IC_RESULT = IC_LEFT == IC_RIGHT;
40232 \end_layout
40233
40234 \end_inset
40235 </cell>
40236 </row>
40237 <row topline="true">
40238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40239 \begin_inset Text
40240
40241 \begin_layout Standard
40242
40243 \size footnotesize
40244 AND_OP
40245 \end_layout
40246
40247 \end_inset
40248 </cell>
40249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40250 \begin_inset Text
40251
40252 \begin_layout Standard
40253
40254 \size footnotesize
40255 IC_LEFT() IC_RIGHT() IC_RESULT() 
40256 \end_layout
40257
40258 \end_inset
40259 </cell>
40260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40261 \begin_inset Text
40262
40263 \begin_layout Standard
40264
40265 \size footnotesize
40266 Logical and operation
40267 \end_layout
40268
40269 \end_inset
40270 </cell>
40271 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40272 \begin_inset Text
40273
40274 \begin_layout Standard
40275
40276 \size footnotesize
40277 IC_RESULT = IC_LEFT && IC_RIGHT; 
40278 \end_layout
40279
40280 \end_inset
40281 </cell>
40282 </row>
40283 <row topline="true">
40284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40285 \begin_inset Text
40286
40287 \begin_layout Standard
40288
40289 \size footnotesize
40290 OR_OP
40291 \end_layout
40292
40293 \end_inset
40294 </cell>
40295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40296 \begin_inset Text
40297
40298 \begin_layout Standard
40299
40300 \size footnotesize
40301 IC_LEFT() IC_RIGHT() IC_RESULT() 
40302 \end_layout
40303
40304 \end_inset
40305 </cell>
40306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40307 \begin_inset Text
40308
40309 \begin_layout Standard
40310
40311 \size footnotesize
40312 Logical or operation 
40313 \end_layout
40314
40315 \end_inset
40316 </cell>
40317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40318 \begin_inset Text
40319
40320 \begin_layout Standard
40321
40322 \size footnotesize
40323 IC_RESULT = IC_LEFT || IC_RIGHT; 
40324 \end_layout
40325
40326 \end_inset
40327 </cell>
40328 </row>
40329 <row topline="true">
40330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40331 \begin_inset Text
40332
40333 \begin_layout Standard
40334
40335 \size footnotesize
40336 '^'
40337 \end_layout
40338
40339 \end_inset
40340 </cell>
40341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40342 \begin_inset Text
40343
40344 \begin_layout Standard
40345
40346 \size footnotesize
40347 IC_LEFT() IC_RIGHT() IC_RESULT() 
40348 \end_layout
40349
40350 \end_inset
40351 </cell>
40352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40353 \begin_inset Text
40354
40355 \begin_layout Standard
40356
40357 \size footnotesize
40358 Exclusive OR
40359 \end_layout
40360
40361 \end_inset
40362 </cell>
40363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40364 \begin_inset Text
40365
40366 \begin_layout Standard
40367
40368 \size footnotesize
40369 IC_RESULT = IC_LEFT ^ IC_RIGHT;
40370 \end_layout
40371
40372 \end_inset
40373 </cell>
40374 </row>
40375 <row topline="true">
40376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40377 \begin_inset Text
40378
40379 \begin_layout Standard
40380
40381 \size footnotesize
40382 '|'
40383 \end_layout
40384
40385 \end_inset
40386 </cell>
40387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40388 \begin_inset Text
40389
40390 \begin_layout Standard
40391
40392 \size footnotesize
40393 IC_LEFT() IC_RIGHT() IC_RESULT() 
40394 \end_layout
40395
40396 \end_inset
40397 </cell>
40398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40399 \begin_inset Text
40400
40401 \begin_layout Standard
40402
40403 \size footnotesize
40404 Bitwise OR 
40405 \end_layout
40406
40407 \end_inset
40408 </cell>
40409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40410 \begin_inset Text
40411
40412 \begin_layout Standard
40413
40414 \size footnotesize
40415 IC_RESULT = IC_LEFT | IC_RIGHT;
40416 \end_layout
40417
40418 \end_inset
40419 </cell>
40420 </row>
40421 <row topline="true">
40422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40423 \begin_inset Text
40424
40425 \begin_layout Standard
40426
40427 \size footnotesize
40428 BITWISEAND
40429 \end_layout
40430
40431 \end_inset
40432 </cell>
40433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40434 \begin_inset Text
40435
40436 \begin_layout Standard
40437
40438 \size footnotesize
40439 IC_LEFT() IC_RIGHT() IC_RESULT()
40440 \end_layout
40441
40442 \end_inset
40443 </cell>
40444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40445 \begin_inset Text
40446
40447 \begin_layout Standard
40448
40449 \size footnotesize
40450 Bitwise AND 
40451 \end_layout
40452
40453 \end_inset
40454 </cell>
40455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40456 \begin_inset Text
40457
40458 \begin_layout Standard
40459
40460 \size footnotesize
40461 IC_RESULT = IC_LEFT & IC_RIGHT;
40462 \end_layout
40463
40464 \end_inset
40465 </cell>
40466 </row>
40467 <row topline="true">
40468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40469 \begin_inset Text
40470
40471 \begin_layout Standard
40472
40473 \size footnotesize
40474 LEFT_OP
40475 \end_layout
40476
40477 \end_inset
40478 </cell>
40479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40480 \begin_inset Text
40481
40482 \begin_layout Standard
40483
40484 \size footnotesize
40485 IC_LEFT() IC_RIGHT() IC_RESULT()
40486 \end_layout
40487
40488 \end_inset
40489 </cell>
40490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40491 \begin_inset Text
40492
40493 \begin_layout Standard
40494
40495 \size footnotesize
40496 Left shift 
40497 \end_layout
40498
40499 \end_inset
40500 </cell>
40501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40502 \begin_inset Text
40503
40504 \begin_layout Standard
40505
40506 \size footnotesize
40507 IC_RESULT = IC_LEFT << IC_RIGHT 
40508 \end_layout
40509
40510 \end_inset
40511 </cell>
40512 </row>
40513 <row topline="true">
40514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40515 \begin_inset Text
40516
40517 \begin_layout Standard
40518
40519 \size footnotesize
40520 RIGHT_OP
40521 \end_layout
40522
40523 \end_inset
40524 </cell>
40525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40526 \begin_inset Text
40527
40528 \begin_layout Standard
40529
40530 \size footnotesize
40531 IC_LEFT() IC_RIGHT() IC_RESULT()
40532 \end_layout
40533
40534 \end_inset
40535 </cell>
40536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40537 \begin_inset Text
40538
40539 \begin_layout Standard
40540
40541 \size footnotesize
40542 Right shift
40543 \end_layout
40544
40545 \end_inset
40546 </cell>
40547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40548 \begin_inset Text
40549
40550 \begin_layout Standard
40551
40552 \size footnotesize
40553 IC_RESULT = IC_LEFT >> IC_RIGHT 
40554 \end_layout
40555
40556 \end_inset
40557 </cell>
40558 </row>
40559 <row topline="true">
40560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40561 \begin_inset Text
40562
40563 \begin_layout Standard
40564
40565 \size footnotesize
40566 GET_VALUE_
40567 \newline
40568 AT_ ADDRESS
40569 \end_layout
40570
40571 \end_inset
40572 </cell>
40573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40574 \begin_inset Text
40575
40576 \begin_layout Standard
40577
40578 \size footnotesize
40579 IC_LEFT() IC_RESULT()
40580 \end_layout
40581
40582 \end_inset
40583 </cell>
40584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40585 \begin_inset Text
40586
40587 \begin_layout Standard
40588
40589 \size footnotesize
40590 Indirect fetch 
40591 \end_layout
40592
40593 \end_inset
40594 </cell>
40595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40596 \begin_inset Text
40597
40598 \begin_layout Standard
40599
40600 \size footnotesize
40601 IC_RESULT = (*IC_LEFT);
40602 \end_layout
40603
40604 \end_inset
40605 </cell>
40606 </row>
40607 <row topline="true">
40608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40609 \begin_inset Text
40610
40611 \begin_layout Standard
40612
40613 \size footnotesize
40614 POINTER_SET
40615 \end_layout
40616
40617 \end_inset
40618 </cell>
40619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40620 \begin_inset Text
40621
40622 \begin_layout Standard
40623
40624 \size footnotesize
40625 IC_RIGHT() IC_RESULT() 
40626 \end_layout
40627
40628 \end_inset
40629 </cell>
40630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40631 \begin_inset Text
40632
40633 \begin_layout Standard
40634
40635 \size footnotesize
40636 Indirect set
40637 \end_layout
40638
40639 \end_inset
40640 </cell>
40641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40642 \begin_inset Text
40643
40644 \begin_layout Standard
40645
40646 \size footnotesize
40647 (*IC_RESULT) = IC_RIGHT;
40648 \end_layout
40649
40650 \end_inset
40651 </cell>
40652 </row>
40653 <row topline="true">
40654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40655 \begin_inset Text
40656
40657 \begin_layout Standard
40658
40659 \size footnotesize
40660 '='
40661 \end_layout
40662
40663 \end_inset
40664 </cell>
40665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40666 \begin_inset Text
40667
40668 \begin_layout Standard
40669
40670 \size footnotesize
40671 IC_RIGHT() IC_RESULT()
40672 \end_layout
40673
40674 \end_inset
40675 </cell>
40676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40677 \begin_inset Text
40678
40679 \begin_layout Standard
40680
40681 \size footnotesize
40682 Assignment
40683 \end_layout
40684
40685 \end_inset
40686 </cell>
40687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40688 \begin_inset Text
40689
40690 \begin_layout Standard
40691
40692 \size footnotesize
40693 IC_RESULT = IC_RIGHT;
40694 \end_layout
40695
40696 \end_inset
40697 </cell>
40698 </row>
40699 <row topline="true">
40700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40701 \begin_inset Text
40702
40703 \begin_layout Standard
40704
40705 \size footnotesize
40706 IFX
40707 \end_layout
40708
40709 \end_inset
40710 </cell>
40711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40712 \begin_inset Text
40713
40714 \begin_layout Standard
40715
40716 \size footnotesize
40717 IC_COND IC_TRUE IC_LABEL
40718 \end_layout
40719
40720 \end_inset
40721 </cell>
40722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40723 \begin_inset Text
40724
40725 \begin_layout Standard
40726
40727 \size footnotesize
40728 Conditional jump.
40729  If true label is present then jump to true label if condition is true else
40730  jump to false label if condition is false 
40731 \end_layout
40732
40733 \end_inset
40734 </cell>
40735 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40736 \begin_inset Text
40737
40738 \begin_layout Standard
40739
40740 \size footnotesize
40741 if (IC_COND) goto IC_TRUE; 
40742 \newline
40743 \InsetSpace ~
40744 \InsetSpace ~
40745 Or 
40746 \newline
40747 If (!IC_COND) goto IC_FALSE;
40748 \end_layout
40749
40750 \end_inset
40751 </cell>
40752 </row>
40753 <row topline="true">
40754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40755 \begin_inset Text
40756
40757 \begin_layout Standard
40758
40759 \size footnotesize
40760 ADDRESS_OF
40761 \end_layout
40762
40763 \end_inset
40764 </cell>
40765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40766 \begin_inset Text
40767
40768 \begin_layout Standard
40769
40770 \size footnotesize
40771 IC_LEFT() IC_RESULT()
40772 \end_layout
40773
40774 \end_inset
40775 </cell>
40776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40777 \begin_inset Text
40778
40779 \begin_layout Standard
40780
40781 \size footnotesize
40782 Address of 
40783 \end_layout
40784
40785 \end_inset
40786 </cell>
40787 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40788 \begin_inset Text
40789
40790 \begin_layout Standard
40791
40792 \size footnotesize
40793 IC_RESULT = &IC_LEFT();
40794 \end_layout
40795
40796 \end_inset
40797 </cell>
40798 </row>
40799 <row topline="true">
40800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40801 \begin_inset Text
40802
40803 \begin_layout Standard
40804
40805 \size footnotesize
40806 JUMPTABLE
40807 \end_layout
40808
40809 \end_inset
40810 </cell>
40811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40812 \begin_inset Text
40813
40814 \begin_layout Standard
40815
40816 \size footnotesize
40817 IC_JTCOND IC_JTLABELS
40818 \end_layout
40819
40820 \end_inset
40821 </cell>
40822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40823 \begin_inset Text
40824
40825 \begin_layout Standard
40826
40827 \size footnotesize
40828 Jump to list of labels depending on the value of JTCOND
40829 \end_layout
40830
40831 \end_inset
40832 </cell>
40833 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40834 \begin_inset Text
40835
40836 \begin_layout Standard
40837
40838 \size footnotesize
40839 Switch statement
40840 \end_layout
40841
40842 \end_inset
40843 </cell>
40844 </row>
40845 <row topline="true">
40846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40847 \begin_inset Text
40848
40849 \begin_layout Standard
40850
40851 \size footnotesize
40852 CAST
40853 \end_layout
40854
40855 \end_inset
40856 </cell>
40857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40858 \begin_inset Text
40859
40860 \begin_layout Standard
40861
40862 \size footnotesize
40863 IC_RIGHT() IC_LEFT() IC_RESULT()
40864 \end_layout
40865
40866 \end_inset
40867 </cell>
40868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40869 \begin_inset Text
40870
40871 \begin_layout Standard
40872
40873 \size footnotesize
40874 Cast types 
40875 \end_layout
40876
40877 \end_inset
40878 </cell>
40879 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40880 \begin_inset Text
40881
40882 \begin_layout Standard
40883
40884 \size footnotesize
40885 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
40886 \end_layout
40887
40888 \end_inset
40889 </cell>
40890 </row>
40891 <row topline="true">
40892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40893 \begin_inset Text
40894
40895 \begin_layout Standard
40896
40897 \size footnotesize
40898 SEND
40899 \end_layout
40900
40901 \end_inset
40902 </cell>
40903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40904 \begin_inset Text
40905
40906 \begin_layout Standard
40907
40908 \size footnotesize
40909 IC_LEFT()
40910 \end_layout
40911
40912 \end_inset
40913 </cell>
40914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40915 \begin_inset Text
40916
40917 \begin_layout Standard
40918
40919 \size footnotesize
40920 This is used for passing parameters in registers; 
40921 \newline
40922 move IC_LEFT to the next
40923  available parameter register.
40924 \end_layout
40925
40926 \end_inset
40927 </cell>
40928 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40929 \begin_inset Text
40930
40931 \begin_layout Standard
40932
40933 \size footnotesize
40934 None
40935 \end_layout
40936
40937 \end_inset
40938 </cell>
40939 </row>
40940 <row topline="true">
40941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40942 \begin_inset Text
40943
40944 \begin_layout Standard
40945
40946 \size footnotesize
40947 RECV
40948 \end_layout
40949
40950 \end_inset
40951 </cell>
40952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40953 \begin_inset Text
40954
40955 \begin_layout Standard
40956
40957 \size footnotesize
40958 IC_RESULT()
40959 \end_layout
40960
40961 \end_inset
40962 </cell>
40963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40964 \begin_inset Text
40965
40966 \begin_layout Standard
40967
40968 \size footnotesize
40969 This is used for receiving parameters passed in registers;
40970 \newline
40971 Move the values
40972  in the next parameter register to IC_RESULT 
40973 \end_layout
40974
40975 \end_inset
40976 </cell>
40977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40978 \begin_inset Text
40979
40980 \begin_layout Standard
40981
40982 \size footnotesize
40983 None
40984 \end_layout
40985
40986 \end_inset
40987 </cell>
40988 </row>
40989 <row topline="true" bottomline="true">
40990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40991 \begin_inset Text
40992
40993 \begin_layout Standard
40994
40995 \shape slanted
40996 \size footnotesize
40997 (some more have been added)
40998 \end_layout
40999
41000 \end_inset
41001 </cell>
41002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41003 \begin_inset Text
41004
41005 \begin_layout Standard
41006
41007 \end_layout
41008
41009 \end_inset
41010 </cell>
41011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41012 \begin_inset Text
41013
41014 \begin_layout Standard
41015
41016 \end_layout
41017
41018 \end_inset
41019 </cell>
41020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41021 \begin_inset Text
41022
41023 \begin_layout Standard
41024
41025 \shape slanted
41026 \size footnotesize
41027 see f.e.
41028
41029 \shape default
41030  
41031 \family typewriter
41032 \shape slanted
41033 gen51Code()
41034 \family default
41035 \shape default
41036  
41037 \shape slanted
41038 in
41039 \shape default
41040  
41041 \family typewriter
41042 \shape slanted
41043 src/mcs51/gen.c
41044 \end_layout
41045
41046 \end_inset
41047 </cell>
41048 </row>
41049 </lyxtabular>
41050
41051 \end_inset
41052
41053
41054 \end_layout
41055
41056 \begin_layout Standard
41057 \begin_inset Note Note
41058 status collapsed
41059
41060 \begin_layout Standard
41061 In the original article Figure II was announced to be downloadable on 
41062 \shape italic
41063 Circuit Cellar
41064 \shape default
41065 's web site.
41066  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
41067 \end_layout
41068
41069 \end_inset
41070
41071
41072 \end_layout
41073
41074 \begin_layout Paragraph*
41075 ICode Example
41076 \begin_inset LatexCommand index
41077 name "iCode"
41078
41079 \end_inset
41080
41081
41082 \end_layout
41083
41084 \begin_layout Standard
41085 This section shows some details of iCode.
41086  The example C code does not do anything useful; it is used as an example
41087  to illustrate the intermediate code generated by the compiler.
41088 \end_layout
41089
41090 \begin_layout Verse
41091
41092 \family typewriter
41093 1.\InsetSpace ~
41094 xdata int * p;
41095 \newline
41096 2.\InsetSpace ~
41097 int gint;
41098 \newline
41099 3.\InsetSpace ~
41100 /* This function does nothing useful.
41101  It is used
41102 \newline
41103 4.\InsetSpace ~
41104 \InsetSpace ~
41105 \InsetSpace ~
41106 \InsetSpace ~
41107 for the purpose of explaining iCode */
41108 \newline
41109 5.\InsetSpace ~
41110 short function (data
41111  int *x)
41112 \newline
41113 6.\InsetSpace ~
41114 {
41115 \newline
41116 7.\InsetSpace ~
41117 \InsetSpace ~
41118 \InsetSpace ~
41119 short i=10; \InsetSpace ~
41120 \InsetSpace ~
41121 /* dead initialization eliminated */
41122 \newline
41123 8.\InsetSpace ~
41124 \InsetSpace ~
41125 \InsetSpace ~
41126 short sum=10;
41127  /* dead initialization eliminated */
41128 \newline
41129 9.\InsetSpace ~
41130 \InsetSpace ~
41131 \InsetSpace ~
41132 short mul;
41133 \newline
41134 10.\InsetSpace ~
41135 \InsetSpace ~
41136 int j ;
41137 \newline
41138 11.\InsetSpace ~
41139 \InsetSpace ~
41140 while (*x) *x++
41141  = *p++; 
41142 \newline
41143 12.\InsetSpace ~
41144 \InsetSpace ~
41145 \InsetSpace ~
41146 \InsetSpace ~
41147 sum = 0 ; 
41148 \newline
41149 13.\InsetSpace ~
41150 \InsetSpace ~
41151 mul = 0;
41152 \newline
41153 14.\InsetSpace ~
41154 \InsetSpace ~
41155 /* compiler detects i,j to be induction
41156  variables */
41157 \newline
41158 15.\InsetSpace ~
41159 \InsetSpace ~
41160 for (i = 0, j = 10 ; i < 10 ; i++, j
41161 \family default
41162 -
41163 \begin_inset ERT
41164 status collapsed
41165
41166 \begin_layout Standard
41167
41168
41169 \backslash
41170 /
41171 \end_layout
41172
41173 \end_inset
41174
41175 -
41176 \family typewriter
41177 ) {
41178 \newline
41179 16.\InsetSpace ~
41180 \InsetSpace ~
41181 \InsetSpace ~
41182 \InsetSpace ~
41183 sum += i;
41184 \newline
41185 17.\InsetSpace ~
41186 \InsetSpace ~
41187 \InsetSpace ~
41188 \InsetSpace ~
41189 mul += i * 3; \InsetSpace ~
41190 \InsetSpace ~
41191 /* this multiplication remains */
41192 \newline
41193 18.\InsetSpace ~
41194 \InsetSpace ~
41195 \InsetSpace ~
41196 \InsetSpace ~
41197 gint +=
41198  j * 3;\InsetSpace ~
41199 \InsetSpace ~
41200 /* this multiplication changed to addition */
41201 \newline
41202 19.\InsetSpace ~
41203 \InsetSpace ~
41204 }
41205 \newline
41206 20.\InsetSpace ~
41207 \InsetSpace ~
41208 return sum+mul;
41209 \newline
41210 21.\InsetSpace ~
41211 }
41212 \end_layout
41213
41214 \begin_layout Standard
41215 In addition to the operands each iCode contains information about the filename
41216  and line it corresponds to in the source file.
41217  The first field in the listing should be interpreted as follows:
41218 \newline
41219
41220 \shape italic
41221 \size footnotesize
41222 Filename(linenumber: iCode Execution sequence number : ICode hash table
41223  key : loop depth of the iCode).
41224 \shape default
41225 \size default
41226
41227 \newline
41228 Then follows the human readable form of the ICode operation.
41229  Each operand of this triplet form can be of three basic types a) compiler
41230  generated temporary b) user defined variable c) a constant value.
41231  Note that local variables and parameters are replaced by compiler generated
41232  temporaries.
41233  Live ranges
41234 \begin_inset LatexCommand index
41235 name "Live range analysis"
41236
41237 \end_inset
41238
41239  are computed only for temporaries (i.e.
41240  live ranges are not computed for global variables).
41241  Registers
41242 \begin_inset LatexCommand index
41243 name "Register allocation"
41244
41245 \end_inset
41246
41247  are allocated for temporaries only.
41248  Operands are formatted in the following manner:
41249 \newline
41250
41251 \shape italic
41252 \size footnotesize
41253 Operand Name [lr live-from : live-to ] { type information } [ registers
41254  allocated ].
41255 \shape default
41256 \size default
41257
41258 \newline
41259 As mentioned earlier the live ranges are computed in terms of the execution
41260  sequence number of the iCodes, for example 
41261 \newline
41262 the iTemp0 is live from (i.e.
41263  first defined in iCode with execution sequence number 3, and is last used
41264  in the iCode with sequence number 5).
41265  For induction variables such as iTemp21 the live range computation extends
41266  the lifetime from the start to the end of the loop.
41267 \newline
41268 The register allocator
41269  used the live range information to allocate registers, the same registers
41270  may be used for different temporaries if their live ranges do not overlap,
41271  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
41272  ranges do not overlap.
41273  In addition the allocator also takes into consideration the type and usage
41274  of a temporary, for example itemp6 is a pointer to near space and is used
41275  as to fetch data from (i.e.
41276  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
41277  Some short lived temporaries are allocated to special registers which have
41278  meaning to the code generator e.g.
41279  iTemp13 is allocated to a pseudo register CC which tells the back end that
41280  the temporary is used only for a conditional jump the code generation makes
41281  use of this information to optimize a compare and jump ICode.
41282 \newline
41283 There are several
41284  loop optimizations
41285 \begin_inset LatexCommand index
41286 name "Loop optimization"
41287
41288 \end_inset
41289
41290  performed by the compiler.
41291  It can detect induction variables iTemp21(i) and iTemp23(j).
41292  Also note the compiler does selective strength reduction
41293 \begin_inset LatexCommand index
41294 name "Strength reduction"
41295
41296 \end_inset
41297
41298 , i.e.
41299  the multiplication of an induction variable in line 18 (gint = j * 3) is
41300  changed to addition, a new temporary iTemp17 is allocated and assigned
41301  a initial value, a constant 3 is then added for each iteration of the loop.
41302  The compiler does not change the multiplication
41303 \begin_inset LatexCommand index
41304 name "Multiplication"
41305
41306 \end_inset
41307
41308  in line 17 however since the processor does support an 8 * 8 bit multiplication.
41309 \newline
41310
41311 Note the dead code elimination
41312 \begin_inset LatexCommand index
41313 name "Dead-code elimination"
41314
41315 \end_inset
41316
41317  optimization eliminated the dead assignments in line 7 & 8 to I and sum
41318  respectively.
41319 \newline
41320
41321 \end_layout
41322
41323 \begin_layout Standard
41324
41325 \size footnotesize
41326 Sample.c (5:1:0:0) _entry($9) :
41327 \end_layout
41328
41329 \begin_layout Standard
41330
41331 \size footnotesize
41332 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
41333 \end_layout
41334
41335 \begin_layout Standard
41336
41337 \size footnotesize
41338 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
41339 \end_layout
41340
41341 \begin_layout Standard
41342
41343 \size footnotesize
41344 Sample.c(11:4:53:0) preHeaderLbl0($11) :
41345 \end_layout
41346
41347 \begin_layout Standard
41348
41349 \size footnotesize
41350 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
41351  * int}[r2]
41352 \end_layout
41353
41354 \begin_layout Standard
41355
41356 \size footnotesize
41357 Sample.c(11:6:5:1) _whilecontinue_0($1) :
41358 \end_layout
41359
41360 \begin_layout Standard
41361
41362 \size footnotesize
41363 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
41364  int}[r0]]
41365 \end_layout
41366
41367 \begin_layout Standard
41368
41369 \size footnotesize
41370 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
41371 \end_layout
41372
41373 \begin_layout Standard
41374
41375 \size footnotesize
41376 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
41377  * int}
41378 \end_layout
41379
41380 \begin_layout Standard
41381
41382 \size footnotesize
41383 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
41384  {short}
41385 \end_layout
41386
41387 \begin_layout Standard
41388
41389 \size footnotesize
41390 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
41391  * int}[DPTR]]
41392 \end_layout
41393
41394 \begin_layout Standard
41395
41396 \size footnotesize
41397 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
41398 }[r2 r3]
41399 \end_layout
41400
41401 \begin_layout Standard
41402
41403 \size footnotesize
41404 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
41405  * int}[r0] + 0x2 {short}
41406 \end_layout
41407
41408 \begin_layout Standard
41409
41410 \size footnotesize
41411 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
41412 \end_layout
41413
41414 \begin_layout Standard
41415
41416 \size footnotesize
41417 Sample.c(11:17:21:0)_whilebreak_0($3) :
41418 \end_layout
41419
41420 \begin_layout Standard
41421
41422 \size footnotesize
41423 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
41424 \end_layout
41425
41426 \begin_layout Standard
41427
41428 \size footnotesize
41429 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
41430 \end_layout
41431
41432 \begin_layout Standard
41433
41434 \size footnotesize
41435 Sample.c(15:20:54:0)preHeaderLbl1($13) :
41436 \end_layout
41437
41438 \begin_layout Standard
41439
41440 \size footnotesize
41441 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
41442 \end_layout
41443
41444 \begin_layout Standard
41445
41446 \size footnotesize
41447 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
41448 \end_layout
41449
41450 \begin_layout Standard
41451
41452 \size footnotesize
41453 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
41454 \end_layout
41455
41456 \begin_layout Standard
41457
41458 \size footnotesize
41459 Sample.c(15:24:26:1)_forcond_0($4) :
41460 \end_layout
41461
41462 \begin_layout Standard
41463
41464 \size footnotesize
41465 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
41466  < 0xa {short}
41467 \end_layout
41468
41469 \begin_layout Standard
41470
41471 \size footnotesize
41472 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
41473 \end_layout
41474
41475 \begin_layout Standard
41476
41477 \size footnotesize
41478 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
41479  + ITemp21 [lr21:38]{short}[r4]
41480 \end_layout
41481
41482 \begin_layout Standard
41483
41484 \size footnotesize
41485 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
41486  * 0x3 {short}
41487 \end_layout
41488
41489 \begin_layout Standard
41490
41491 \size footnotesize
41492 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
41493  + iTemp15 [lr29:30]{short}[r1]
41494 \end_layout
41495
41496 \begin_layout Standard
41497
41498 \size footnotesize
41499 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
41500  r0]- 0x3 {short}
41501 \end_layout
41502
41503 \begin_layout Standard
41504
41505 \size footnotesize
41506 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
41507 int}[r7 r0]
41508 \end_layout
41509
41510 \begin_layout Standard
41511
41512 \size footnotesize
41513 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
41514  + 0x1 {short}
41515 \end_layout
41516
41517 \begin_layout Standard
41518
41519 \size footnotesize
41520 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
41521  r6]- 0x1 {short}
41522 \end_layout
41523
41524 \begin_layout Standard
41525
41526 \size footnotesize
41527 Sample.c(19:38:47:1) goto _forcond_0($4)
41528 \end_layout
41529
41530 \begin_layout Standard
41531
41532 \size footnotesize
41533 Sample.c(19:39:48:0)_forbreak_0($7) :
41534 \end_layout
41535
41536 \begin_layout Standard
41537
41538 \size footnotesize
41539 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
41540  + ITemp11 [lr19:40]{short}[r3]
41541 \end_layout
41542
41543 \begin_layout Standard
41544
41545 \size footnotesize
41546 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
41547 \end_layout
41548
41549 \begin_layout Standard
41550
41551 \size footnotesize
41552 Sample.c(20:42:51:0)_return($8) :
41553 \end_layout
41554
41555 \begin_layout Standard
41556
41557 \size footnotesize
41558 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
41559 \size default
41560
41561 \newline
41562
41563 \newline
41564 Finally the code generated for this function:
41565 \newline
41566
41567 \end_layout
41568
41569 \begin_layout Standard
41570
41571 \size footnotesize
41572 .area DSEG (DATA)
41573 \end_layout
41574
41575 \begin_layout Standard
41576
41577 \size footnotesize
41578 _p::
41579 \end_layout
41580
41581 \begin_layout Standard
41582
41583 \size footnotesize
41584 \InsetSpace ~
41585 \InsetSpace ~
41586 .ds 2
41587 \end_layout
41588
41589 \begin_layout Standard
41590
41591 \size footnotesize
41592 _gint::
41593 \end_layout
41594
41595 \begin_layout Standard
41596
41597 \size footnotesize
41598 \InsetSpace ~
41599 \InsetSpace ~
41600 .ds 2
41601 \end_layout
41602
41603 \begin_layout Standard
41604
41605 \size footnotesize
41606 ; sample.c 5
41607 \end_layout
41608
41609 \begin_layout Standard
41610
41611 \size footnotesize
41612 ; ----------------------------------------------
41613 \end_layout
41614
41615 \begin_layout Standard
41616
41617 \size footnotesize
41618 ; function function
41619 \end_layout
41620
41621 \begin_layout Standard
41622
41623 \size footnotesize
41624 ; ----------------------------------------------
41625 \end_layout
41626
41627 \begin_layout Standard
41628
41629 \size footnotesize
41630 _function:
41631 \end_layout
41632
41633 \begin_layout Standard
41634
41635 \size footnotesize
41636 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
41637 \end_layout
41638
41639 \begin_layout Standard
41640
41641 \size footnotesize
41642 \InsetSpace ~
41643 \InsetSpace ~
41644 mov r2,dpl
41645 \end_layout
41646
41647 \begin_layout Standard
41648
41649 \size footnotesize
41650 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
41651 \end_layout
41652
41653 \begin_layout Standard
41654
41655 \size footnotesize
41656 \InsetSpace ~
41657 \InsetSpace ~
41658 mov ar0,r2
41659 \end_layout
41660
41661 \begin_layout Standard
41662
41663 \size footnotesize
41664 ;_whilecontinue_0($1) :
41665 \end_layout
41666
41667 \begin_layout Standard
41668
41669 \size footnotesize
41670 00101$:
41671 \end_layout
41672
41673 \begin_layout Standard
41674
41675 \size footnotesize
41676 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
41677 \end_layout
41678
41679 \begin_layout Standard
41680
41681 \size footnotesize
41682 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
41683 \end_layout
41684
41685 \begin_layout Standard
41686
41687 \size footnotesize
41688 \InsetSpace ~
41689 \InsetSpace ~
41690 mov ar2,@r0
41691 \end_layout
41692
41693 \begin_layout Standard
41694
41695 \size footnotesize
41696 \InsetSpace ~
41697 \InsetSpace ~
41698 inc r0
41699 \end_layout
41700
41701 \begin_layout Standard
41702
41703 \size footnotesize
41704 \InsetSpace ~
41705 \InsetSpace ~
41706 mov ar3,@r0
41707 \end_layout
41708
41709 \begin_layout Standard
41710
41711 \size footnotesize
41712 \InsetSpace ~
41713 \InsetSpace ~
41714 dec r0
41715 \end_layout
41716
41717 \begin_layout Standard
41718
41719 \size footnotesize
41720 \InsetSpace ~
41721 \InsetSpace ~
41722 mov a,r2
41723 \end_layout
41724
41725 \begin_layout Standard
41726
41727 \size footnotesize
41728 \InsetSpace ~
41729 \InsetSpace ~
41730 orl a,r3
41731 \end_layout
41732
41733 \begin_layout Standard
41734
41735 \size footnotesize
41736 \InsetSpace ~
41737 \InsetSpace ~
41738 jz 00103$
41739 \end_layout
41740
41741 \begin_layout Standard
41742
41743 \size footnotesize
41744 00114$:
41745 \end_layout
41746
41747 \begin_layout Standard
41748
41749 \size footnotesize
41750 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
41751 \end_layout
41752
41753 \begin_layout Standard
41754
41755 \size footnotesize
41756 \InsetSpace ~
41757 \InsetSpace ~
41758 mov dpl,_p
41759 \end_layout
41760
41761 \begin_layout Standard
41762
41763 \size footnotesize
41764 \InsetSpace ~
41765 \InsetSpace ~
41766 mov dph,(_p + 1)
41767 \end_layout
41768
41769 \begin_layout Standard
41770
41771 \size footnotesize
41772 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
41773 \end_layout
41774
41775 \begin_layout Standard
41776
41777 \size footnotesize
41778 \InsetSpace ~
41779 \InsetSpace ~
41780 mov a,#0x02
41781 \end_layout
41782
41783 \begin_layout Standard
41784
41785 \size footnotesize
41786 \InsetSpace ~
41787 \InsetSpace ~
41788 add a,_p
41789 \end_layout
41790
41791 \begin_layout Standard
41792
41793 \size footnotesize
41794 \InsetSpace ~
41795 \InsetSpace ~
41796 mov _p,a
41797 \end_layout
41798
41799 \begin_layout Standard
41800
41801 \size footnotesize
41802 \InsetSpace ~
41803 \InsetSpace ~
41804 clr a
41805 \end_layout
41806
41807 \begin_layout Standard
41808
41809 \size footnotesize
41810 \InsetSpace ~
41811 \InsetSpace ~
41812 addc a,(_p + 1)
41813 \end_layout
41814
41815 \begin_layout Standard
41816
41817 \size footnotesize
41818 \InsetSpace ~
41819 \InsetSpace ~
41820 mov (_p + 1),a
41821 \end_layout
41822
41823 \begin_layout Standard
41824
41825 \size footnotesize
41826 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
41827 \end_layout
41828
41829 \begin_layout Standard
41830
41831 \size footnotesize
41832 \InsetSpace ~
41833 \InsetSpace ~
41834 movx a,@dptr
41835 \end_layout
41836
41837 \begin_layout Standard
41838
41839 \size footnotesize
41840 \InsetSpace ~
41841 \InsetSpace ~
41842 mov r2,a
41843 \end_layout
41844
41845 \begin_layout Standard
41846
41847 \size footnotesize
41848 \InsetSpace ~
41849 \InsetSpace ~
41850 inc dptr
41851 \end_layout
41852
41853 \begin_layout Standard
41854
41855 \size footnotesize
41856 \InsetSpace ~
41857 \InsetSpace ~
41858 movx a,@dptr
41859 \end_layout
41860
41861 \begin_layout Standard
41862
41863 \size footnotesize
41864 \InsetSpace ~
41865 \InsetSpace ~
41866 mov r3,a
41867 \end_layout
41868
41869 \begin_layout Standard
41870
41871 \size footnotesize
41872 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
41873 \end_layout
41874
41875 \begin_layout Standard
41876
41877 \size footnotesize
41878 \InsetSpace ~
41879 \InsetSpace ~
41880 mov @r0,ar2
41881 \end_layout
41882
41883 \begin_layout Standard
41884
41885 \size footnotesize
41886 \InsetSpace ~
41887 \InsetSpace ~
41888 inc r0
41889 \end_layout
41890
41891 \begin_layout Standard
41892
41893 \size footnotesize
41894 \InsetSpace ~
41895 \InsetSpace ~
41896 mov @r0,ar3
41897 \end_layout
41898
41899 \begin_layout Standard
41900
41901 \size footnotesize
41902 ; iTemp6 [lr5:16]{_near * int}[r0] = 
41903 \end_layout
41904
41905 \begin_layout Standard
41906
41907 \size footnotesize
41908 ; iTemp6 [lr5:16]{_near * int}[r0] + 
41909 \end_layout
41910
41911 \begin_layout Standard
41912
41913 \size footnotesize
41914 ; 0x2 {short}
41915 \end_layout
41916
41917 \begin_layout Standard
41918
41919 \size footnotesize
41920 \InsetSpace ~
41921 \InsetSpace ~
41922 inc r0
41923 \end_layout
41924
41925 \begin_layout Standard
41926
41927 \size footnotesize
41928 ; goto _whilecontinue_0($1)
41929 \end_layout
41930
41931 \begin_layout Standard
41932
41933 \size footnotesize
41934 \InsetSpace ~
41935 \InsetSpace ~
41936 sjmp 00101$
41937 \end_layout
41938
41939 \begin_layout Standard
41940
41941 \size footnotesize
41942 ; _whilebreak_0($3) :
41943 \end_layout
41944
41945 \begin_layout Standard
41946
41947 \size footnotesize
41948 00103$:
41949 \end_layout
41950
41951 \begin_layout Standard
41952
41953 \size footnotesize
41954 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
41955 \end_layout
41956
41957 \begin_layout Standard
41958
41959 \size footnotesize
41960 \InsetSpace ~
41961 \InsetSpace ~
41962 mov r2,#0x00
41963 \end_layout
41964
41965 \begin_layout Standard
41966
41967 \size footnotesize
41968 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
41969 \end_layout
41970
41971 \begin_layout Standard
41972
41973 \size footnotesize
41974 \InsetSpace ~
41975 \InsetSpace ~
41976 mov r3,#0x00
41977 \end_layout
41978
41979 \begin_layout Standard
41980
41981 \size footnotesize
41982 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
41983 \end_layout
41984
41985 \begin_layout Standard
41986
41987 \size footnotesize
41988 \InsetSpace ~
41989 \InsetSpace ~
41990 mov r4,#0x00
41991 \end_layout
41992
41993 \begin_layout Standard
41994
41995 \size footnotesize
41996 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
41997 \end_layout
41998
41999 \begin_layout Standard
42000
42001 \size footnotesize
42002 \InsetSpace ~
42003 \InsetSpace ~
42004 mov r5,#0x0A
42005 \end_layout
42006
42007 \begin_layout Standard
42008
42009 \size footnotesize
42010 \InsetSpace ~
42011 \InsetSpace ~
42012 mov r6,#0x00
42013 \end_layout
42014
42015 \begin_layout Standard
42016
42017 \size footnotesize
42018 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
42019 \end_layout
42020
42021 \begin_layout Standard
42022
42023 \size footnotesize
42024 \InsetSpace ~
42025 \InsetSpace ~
42026 mov r7,#0x1E
42027 \end_layout
42028
42029 \begin_layout Standard
42030
42031 \size footnotesize
42032 \InsetSpace ~
42033 \InsetSpace ~
42034 mov r0,#0x00
42035 \end_layout
42036
42037 \begin_layout Standard
42038
42039 \size footnotesize
42040 ; _forcond_0($4) :
42041 \end_layout
42042
42043 \begin_layout Standard
42044
42045 \size footnotesize
42046 00104$:
42047 \end_layout
42048
42049 \begin_layout Standard
42050
42051 \size footnotesize
42052 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
42053 \end_layout
42054
42055 \begin_layout Standard
42056
42057 \size footnotesize
42058 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
42059 \end_layout
42060
42061 \begin_layout Standard
42062
42063 \size footnotesize
42064 \InsetSpace ~
42065 \InsetSpace ~
42066 clr c
42067 \end_layout
42068
42069 \begin_layout Standard
42070
42071 \size footnotesize
42072 \InsetSpace ~
42073 \InsetSpace ~
42074 mov a,r4
42075 \end_layout
42076
42077 \begin_layout Standard
42078
42079 \size footnotesize
42080 \InsetSpace ~
42081 \InsetSpace ~
42082 xrl a,#0x80
42083 \end_layout
42084
42085 \begin_layout Standard
42086
42087 \size footnotesize
42088 \InsetSpace ~
42089 \InsetSpace ~
42090 subb a,#0x8a
42091 \end_layout
42092
42093 \begin_layout Standard
42094
42095 \size footnotesize
42096 \InsetSpace ~
42097 \InsetSpace ~
42098 jnc 00107$
42099 \end_layout
42100
42101 \begin_layout Standard
42102
42103 \size footnotesize
42104 00115$:
42105 \end_layout
42106
42107 \begin_layout Standard
42108
42109 \size footnotesize
42110 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
42111 \end_layout
42112
42113 \begin_layout Standard
42114
42115 \size footnotesize
42116 ; iTemp21 [lr21:38]{short}[r4]
42117 \end_layout
42118
42119 \begin_layout Standard
42120
42121 \size footnotesize
42122 \InsetSpace ~
42123 \InsetSpace ~
42124 mov a,r4
42125 \end_layout
42126
42127 \begin_layout Standard
42128
42129 \size footnotesize
42130 \InsetSpace ~
42131 \InsetSpace ~
42132 add a,r2
42133 \end_layout
42134
42135 \begin_layout Standard
42136
42137 \size footnotesize
42138 \InsetSpace ~
42139 \InsetSpace ~
42140 mov r2,a
42141 \end_layout
42142
42143 \begin_layout Standard
42144
42145 \size footnotesize
42146 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
42147 \end_layout
42148
42149 \begin_layout Standard
42150
42151 \size footnotesize
42152 \InsetSpace ~
42153 \InsetSpace ~
42154 mov b,#0x03
42155 \end_layout
42156
42157 \begin_layout Standard
42158
42159 \size footnotesize
42160 \InsetSpace ~
42161 \InsetSpace ~
42162 mov a,r4
42163 \end_layout
42164
42165 \begin_layout Standard
42166
42167 \size footnotesize
42168 \InsetSpace ~
42169 \InsetSpace ~
42170 mul ab
42171 \end_layout
42172
42173 \begin_layout Standard
42174
42175 \size footnotesize
42176 \InsetSpace ~
42177 \InsetSpace ~
42178 mov r1,a
42179 \end_layout
42180
42181 \begin_layout Standard
42182
42183 \size footnotesize
42184 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
42185 \end_layout
42186
42187 \begin_layout Standard
42188
42189 \size footnotesize
42190 ; iTemp15 [lr29:30]{short}[r1]
42191 \end_layout
42192
42193 \begin_layout Standard
42194
42195 \size footnotesize
42196 \InsetSpace ~
42197 \InsetSpace ~
42198 add a,r3
42199 \end_layout
42200
42201 \begin_layout Standard
42202
42203 \size footnotesize
42204 \InsetSpace ~
42205 \InsetSpace ~
42206 mov r3,a
42207 \end_layout
42208
42209 \begin_layout Standard
42210
42211 \size footnotesize
42212 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
42213 \end_layout
42214
42215 \begin_layout Standard
42216
42217 \size footnotesize
42218 \InsetSpace ~
42219 \InsetSpace ~
42220 mov a,r7
42221 \end_layout
42222
42223 \begin_layout Standard
42224
42225 \size footnotesize
42226 \InsetSpace ~
42227 \InsetSpace ~
42228 add a,#0xfd
42229 \end_layout
42230
42231 \begin_layout Standard
42232
42233 \size footnotesize
42234 \InsetSpace ~
42235 \InsetSpace ~
42236 mov r7,a
42237 \end_layout
42238
42239 \begin_layout Standard
42240
42241 \size footnotesize
42242 \InsetSpace ~
42243 \InsetSpace ~
42244 mov a,r0
42245 \end_layout
42246
42247 \begin_layout Standard
42248
42249 \size footnotesize
42250 \InsetSpace ~
42251 \InsetSpace ~
42252 addc a,#0xff
42253 \end_layout
42254
42255 \begin_layout Standard
42256
42257 \size footnotesize
42258 \InsetSpace ~
42259 \InsetSpace ~
42260 mov r0,a
42261 \end_layout
42262
42263 \begin_layout Standard
42264
42265 \size footnotesize
42266 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
42267 \end_layout
42268
42269 \begin_layout Standard
42270
42271 \size footnotesize
42272 \InsetSpace ~
42273 \InsetSpace ~
42274 mov a,r7
42275 \end_layout
42276
42277 \begin_layout Standard
42278
42279 \size footnotesize
42280 \InsetSpace ~
42281 \InsetSpace ~
42282 add a,_gint
42283 \end_layout
42284
42285 \begin_layout Standard
42286
42287 \size footnotesize
42288 \InsetSpace ~
42289 \InsetSpace ~
42290 mov _gint,a
42291 \end_layout
42292
42293 \begin_layout Standard
42294
42295 \size footnotesize
42296 \InsetSpace ~
42297 \InsetSpace ~
42298 mov a,r0
42299 \end_layout
42300
42301 \begin_layout Standard
42302
42303 \size footnotesize
42304 \InsetSpace ~
42305 \InsetSpace ~
42306 addc a,(_gint + 1)
42307 \end_layout
42308
42309 \begin_layout Standard
42310
42311 \size footnotesize
42312 \InsetSpace ~
42313 \InsetSpace ~
42314 mov (_gint + 1),a
42315 \end_layout
42316
42317 \begin_layout Standard
42318
42319 \size footnotesize
42320 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
42321 \end_layout
42322
42323 \begin_layout Standard
42324
42325 \size footnotesize
42326 \InsetSpace ~
42327 \InsetSpace ~
42328 inc r4
42329 \end_layout
42330
42331 \begin_layout Standard
42332
42333 \size footnotesize
42334 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
42335 \end_layout
42336
42337 \begin_layout Standard
42338
42339 \size footnotesize
42340 \InsetSpace ~
42341 \InsetSpace ~
42342 dec r5
42343 \end_layout
42344
42345 \begin_layout Standard
42346
42347 \size footnotesize
42348 \InsetSpace ~
42349 \InsetSpace ~
42350 cjne r5,#0xff,00104$
42351 \end_layout
42352
42353 \begin_layout Standard
42354
42355 \size footnotesize
42356 \InsetSpace ~
42357 \InsetSpace ~
42358 dec r6
42359 \end_layout
42360
42361 \begin_layout Standard
42362
42363 \size footnotesize
42364 ; goto _forcond_0($4)
42365 \end_layout
42366
42367 \begin_layout Standard
42368
42369 \size footnotesize
42370 \InsetSpace ~
42371 \InsetSpace ~
42372 sjmp 00104$
42373 \end_layout
42374
42375 \begin_layout Standard
42376
42377 \size footnotesize
42378 ; _forbreak_0($7) :
42379 \end_layout
42380
42381 \begin_layout Standard
42382
42383 \size footnotesize
42384 00107$:
42385 \end_layout
42386
42387 \begin_layout Standard
42388
42389 \size footnotesize
42390 ; ret iTemp24 [lr40:41]{short}
42391 \end_layout
42392
42393 \begin_layout Standard
42394
42395 \size footnotesize
42396 \InsetSpace ~
42397 \InsetSpace ~
42398 mov a,r3
42399 \end_layout
42400
42401 \begin_layout Standard
42402
42403 \size footnotesize
42404 \InsetSpace ~
42405 \InsetSpace ~
42406 add a,r2
42407 \end_layout
42408
42409 \begin_layout Standard
42410
42411 \size footnotesize
42412 \InsetSpace ~
42413 \InsetSpace ~
42414 mov dpl,a
42415 \end_layout
42416
42417 \begin_layout Standard
42418
42419 \size footnotesize
42420 ; _return($8) :
42421 \end_layout
42422
42423 \begin_layout Standard
42424
42425 \size footnotesize
42426 00108$:
42427 \end_layout
42428
42429 \begin_layout Standard
42430
42431 \size footnotesize
42432 \InsetSpace ~
42433 \InsetSpace ~
42434 ret
42435 \newline
42436
42437 \end_layout
42438
42439 \begin_layout Section
42440 A few words about basic block successors, predecessors and dominators
42441 \end_layout
42442
42443 \begin_layout Standard
42444 Successors are basic blocks
42445 \begin_inset LatexCommand index
42446 name "Basic blocks"
42447
42448 \end_inset
42449
42450  that might execute after this basic block.
42451 \newline
42452 Predecessors are basic blocks
42453  that might execute before reaching this basic block.
42454 \newline
42455 Dominators are basic
42456  blocks that WILL execute before reaching this basic block.
42457 \newline
42458
42459 \end_layout
42460
42461 \begin_layout Standard
42462 [basic block 1]
42463 \end_layout
42464
42465 \begin_layout Standard
42466 if (something)
42467 \end_layout
42468
42469 \begin_layout Standard
42470 \InsetSpace ~
42471 \InsetSpace ~
42472 \InsetSpace ~
42473 \InsetSpace ~
42474 [basic block 2]
42475 \end_layout
42476
42477 \begin_layout Standard
42478 else
42479 \end_layout
42480
42481 \begin_layout Standard
42482 \InsetSpace ~
42483 \InsetSpace ~
42484 \InsetSpace ~
42485 \InsetSpace ~
42486 [basic block 3]
42487 \end_layout
42488
42489 \begin_layout Standard
42490 [basic block 4]
42491 \newline
42492
42493 \end_layout
42494
42495 \begin_layout Standard
42496 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
42497 \end_layout
42498
42499 \begin_layout Standard
42500 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
42501 \end_layout
42502
42503 \begin_layout Standard
42504 c) domVect of [BB4] = BB1 ...
42505  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
42506  was executed.
42507 \end_layout
42508
42509 \begin_layout Chapter
42510 Acknowledgments
42511 \end_layout
42512
42513 \begin_layout Standard
42514 \begin_inset LatexCommand url
42515 target "http://sdcc.sourceforge.net/#Who"
42516
42517 \end_inset
42518
42519
42520 \newline
42521
42522 \newline
42523
42524 \emph on
42525 Thanks to all the other volunteer developers who have helped with coding,
42526  testing, web-page creation, distribution sets, etc.
42527  You know who you are :-)
42528 \emph default
42529
42530 \newline
42531
42532 \newline
42533
42534 \emph on
42535 Thanks to Sourceforge 
42536 \begin_inset LatexCommand url
42537 target "http://www.sf.net"
42538
42539 \end_inset
42540
42541  which has hosted the project since 1999 and donates significant download
42542  bandwidth.
42543 \emph default
42544
42545 \newline
42546
42547 \newline
42548
42549 \emph on
42550 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
42551  cycles and bandwidth for snapshot builds.
42552 \newline
42553
42554 \end_layout
42555
42556 \begin_layout Standard
42557 This document was initially written by Sandeep Dutta
42558 \end_layout
42559
42560 \begin_layout Standard
42561 All product names mentioned herein may be trademarks
42562 \begin_inset LatexCommand index
42563 name "Trademarks"
42564
42565 \end_inset
42566
42567  of their respective companies.
42568  
42569 \end_layout
42570
42571 \begin_layout Section*
42572 Alphabetical index
42573 \end_layout
42574
42575 \begin_layout Standard
42576 To avoid confusion, the installation and building options for SDCC itself
42577  (chapter 2) are not part of the index.
42578 \end_layout
42579
42580 \begin_layout Standard
42581 \begin_inset LatexCommand printindex
42582
42583 \end_inset
42584
42585
42586 \end_layout
42587
42588 \end_body
42589 \end_document