* Small Device C Compiler 2.7.0 released
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.4.4 created this file. For more info see http://www.lyx.org/
2 \lyxformat 245
3 \begin_document
4 \begin_header
5 \textclass book
6 \begin_preamble
7 \pdfoptionpdfminorversion=3
8 \usepackage[
9   pdftitle={SDCC Compiler User Guide},
10   pdfauthor={SDCC development team},
11   pdfsubject={installation, user manual},
12   pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
13   pdfpagemode=UseOutlines,
14   colorlinks=true,
15   linkcolor=blue] {hyperref}
16 %
17 \sloppy
18 \tolerance=500          
19 \emergencystretch=30pt 
20 %
21 \date{}
22 \end_preamble
23 \language english
24 \inputencoding default
25 \fontscheme pslatex
26 \graphics default
27 \paperfontsize default
28 \spacing single
29 \papersize letterpaper
30 \use_geometry true
31 \use_amsmath 1
32 \cite_engine basic
33 \use_bibtopic false
34 \paperorientation portrait
35 \leftmargin 30mm
36 \topmargin 20mm
37 \rightmargin 25mm
38 \bottommargin 20mm
39 \secnumdepth 3
40 \tocdepth 3
41 \paragraph_separation indent
42 \defskip medskip
43 \quotes_language swedish
44 \papercolumns 1
45 \papersides 1
46 \paperpagestyle fancy
47 \tracking_changes false
48 \output_changes true
49 \end_header
50
51 \begin_body
52
53 \begin_layout Standard
54 \begin_inset Note Note
55 status collapsed
56
57 \begin_layout Standard
58 Please note: double dashed longoptions (e.g.
59  --version) are written this way: -
60 \begin_inset ERT
61 status collapsed
62
63 \begin_layout Standard
64
65
66 \backslash
67 /
68 \end_layout
69
70 \end_inset
71
72 -
73 \end_layout
74
75 \begin_layout Standard
76 Two resp.
77  three consecutive dashes would otherwise result in a long resp.
78  extra long dash.
79 \end_layout
80
81 \begin_layout Standard
82 Architecture specific stuff (like memory models, code examples) should maybe
83  later go
84 \end_layout
85
86 \begin_layout Standard
87 into seperate sections/chapters/appendices (it is hard to document PIC or
88  Z80 in 
89 \end_layout
90
91 \begin_layout Standard
92 a 8051 centered document) - for now simply add.
93 \end_layout
94
95 \end_inset
96
97
98 \end_layout
99
100 \begin_layout Title
101 SDCC Compiler User Guide
102 \end_layout
103
104 \begin_layout Date
105
106 \size normal
107 SDCC 2.7.1
108 \size footnotesize
109
110 \newline
111 $Date::             $ 
112 \newline
113 $Revision$
114 \end_layout
115
116 \begin_layout Standard
117 \begin_inset Note Note
118 status collapsed
119
120 \begin_layout Standard
121 The above strings enclosed in $ are automatically updated by Subversion
122 \end_layout
123
124 \end_inset
125
126
127 \end_layout
128
129 \begin_layout Standard
130 \begin_inset LatexCommand \tableofcontents{}
131
132 \end_inset
133
134
135 \end_layout
136
137 \begin_layout Chapter
138 Introduction
139 \end_layout
140
141 \begin_layout Section
142 About SDCC
143 \end_layout
144
145 \begin_layout Standard
146
147 \series bold
148 SDCC
149 \series default
150  (
151 \emph on
152 S
153 \emph default
154 mall 
155 \emph on
156 D
157 \emph default
158 evice 
159 \emph on
160 C
161 \emph default
162  
163 \emph on
164 C
165 \emph default
166 ompiler) is free open source, retargettable, optimizing ANSI-C compiler
167  by 
168 \series bold
169 Sandeep Dutta
170 \series default
171  designed for 8 bit Microprocessors.
172  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
173  8051, 8052
174 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
175
176 \end_inset
177
178 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
179  Zilog Z80 based MCUs.
180  It can be retargeted for other microprocessors, support for Microchip PIC,
181  Atmel AVR is under development.
182  The entire source code for the compiler is distributed under GPL.
183  SDCC uses ASXXXX
184 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
185
186 \end_inset
187
188  & ASLINK
189 \begin_inset LatexCommand \index{aslink}
190
191 \end_inset
192
193 , an open source retargetable assembler & linker.
194  SDCC has extensive language extensions suitable for utilizing various microcont
195 rollers and underlying hardware effectively.
196  
197 \newline
198
199 \newline
200 In addition to the MCU specific optimizations SDCC also does a host of
201  standard optimizations like:
202 \end_layout
203
204 \begin_layout Itemize
205 global sub expression elimination, 
206 \end_layout
207
208 \begin_layout Itemize
209 loop optimizations (loop invariant, strength reduction of induction variables
210  and loop reversing), 
211 \end_layout
212
213 \begin_layout Itemize
214 constant folding & propagation, 
215 \end_layout
216
217 \begin_layout Itemize
218 copy propagation, 
219 \end_layout
220
221 \begin_layout Itemize
222 dead code elimination 
223 \end_layout
224
225 \begin_layout Itemize
226 jump tables for 
227 \emph on
228 switch
229 \emph default
230  statements.
231 \end_layout
232
233 \begin_layout Standard
234 For the back-end SDCC uses a global register allocation scheme which should
235  be well suited for other 8 bit MCUs.
236  
237 \newline
238
239 \newline
240 The peep hole optimizer uses a rule based substitution mechanism which
241  is MCU independent.
242  
243 \newline
244
245 \newline
246 Supported data-types are:
247 \end_layout
248
249 \begin_layout Standard
250 \begin_inset Tabular
251 <lyxtabular version="3" rows="8" columns="5">
252 <features>
253 <column alignment="center" valignment="top" leftline="true" width="0">
254 <column alignment="center" valignment="top" leftline="true" width="0">
255 <column alignment="center" valignment="top" leftline="true" width="0">
256 <column alignment="center" valignment="top" leftline="true" width="0">
257 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
258 <row topline="true" bottomline="true">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
260 \begin_inset Text
261
262 \begin_layout Standard
263 type
264 \end_layout
265
266 \end_inset
267 </cell>
268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
269 \begin_inset Text
270
271 \begin_layout Standard
272 width
273 \end_layout
274
275 \end_inset
276 </cell>
277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
278 \begin_inset Text
279
280 \begin_layout Standard
281 default
282 \end_layout
283
284 \end_inset
285 </cell>
286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
287 \begin_inset Text
288
289 \begin_layout Standard
290 signed range
291 \end_layout
292
293 \end_inset
294 </cell>
295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
296 \begin_inset Text
297
298 \begin_layout Standard
299 unsigned range
300 \end_layout
301
302 \end_inset
303 </cell>
304 </row>
305 <row topline="true">
306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
307 \begin_inset Text
308
309 \begin_layout Standard
310 bool
311 \end_layout
312
313 \end_inset
314 </cell>
315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
316 \begin_inset Text
317
318 \begin_layout Standard
319 1 bit
320 \end_layout
321
322 \end_inset
323 </cell>
324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
325 \begin_inset Text
326
327 \begin_layout Standard
328 unsigned
329 \end_layout
330
331 \end_inset
332 </cell>
333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
334 \begin_inset Text
335
336 \begin_layout Standard
337 -
338 \end_layout
339
340 \end_inset
341 </cell>
342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
343 \begin_inset Text
344
345 \begin_layout Standard
346 0, 1
347 \end_layout
348
349 \end_inset
350 </cell>
351 </row>
352 <row topline="true">
353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
354 \begin_inset Text
355
356 \begin_layout Standard
357 char
358 \end_layout
359
360 \end_inset
361 </cell>
362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
363 \begin_inset Text
364
365 \begin_layout Standard
366 8 bits, 1 byte
367 \end_layout
368
369 \end_inset
370 </cell>
371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
372 \begin_inset Text
373
374 \begin_layout Standard
375 signed
376 \end_layout
377
378 \end_inset
379 </cell>
380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
381 \begin_inset Text
382
383 \begin_layout Standard
384 -128, +127
385 \end_layout
386
387 \end_inset
388 </cell>
389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
390 \begin_inset Text
391
392 \begin_layout Standard
393 0, +255
394 \end_layout
395
396 \end_inset
397 </cell>
398 </row>
399 <row topline="true">
400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
401 \begin_inset Text
402
403 \begin_layout Standard
404 short
405 \end_layout
406
407 \end_inset
408 </cell>
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
410 \begin_inset Text
411
412 \begin_layout Standard
413 16 bits, 2 bytes
414 \end_layout
415
416 \end_inset
417 </cell>
418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
419 \begin_inset Text
420
421 \begin_layout Standard
422 signed
423 \end_layout
424
425 \end_inset
426 </cell>
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
428 \begin_inset Text
429
430 \begin_layout Standard
431 -32.768, +32.767
432 \end_layout
433
434 \end_inset
435 </cell>
436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
437 \begin_inset Text
438
439 \begin_layout Standard
440 0, +65.535
441 \end_layout
442
443 \end_inset
444 </cell>
445 </row>
446 <row topline="true">
447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
448 \begin_inset Text
449
450 \begin_layout Standard
451 int
452 \end_layout
453
454 \end_inset
455 </cell>
456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
457 \begin_inset Text
458
459 \begin_layout Standard
460 16 bits, 2 bytes
461 \end_layout
462
463 \end_inset
464 </cell>
465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
466 \begin_inset Text
467
468 \begin_layout Standard
469 signed
470 \end_layout
471
472 \end_inset
473 </cell>
474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
475 \begin_inset Text
476
477 \begin_layout Standard
478 -32.768, +32.767
479 \end_layout
480
481 \end_inset
482 </cell>
483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
484 \begin_inset Text
485
486 \begin_layout Standard
487 0, +65.535
488 \end_layout
489
490 \end_inset
491 </cell>
492 </row>
493 <row topline="true" bottomline="true">
494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
495 \begin_inset Text
496
497 \begin_layout Standard
498 long
499 \end_layout
500
501 \end_inset
502 </cell>
503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
504 \begin_inset Text
505
506 \begin_layout Standard
507 32 bits, 4 bytes
508 \end_layout
509
510 \end_inset
511 </cell>
512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
513 \begin_inset Text
514
515 \begin_layout Standard
516 signed
517 \end_layout
518
519 \end_inset
520 </cell>
521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
522 \begin_inset Text
523
524 \begin_layout Standard
525 -2.147.483.648, +2.147.483.647
526 \end_layout
527
528 \end_inset
529 </cell>
530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
531 \begin_inset Text
532
533 \begin_layout Standard
534 0, +4.294.967.295
535 \end_layout
536
537 \end_inset
538 </cell>
539 </row>
540 <row topline="true" bottomline="true">
541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
542 \begin_inset Text
543
544 \begin_layout Standard
545 float
546 \end_layout
547
548 \end_inset
549 </cell>
550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
551 \begin_inset Text
552
553 \begin_layout Standard
554 4 bytes IEEE 754
555 \end_layout
556
557 \end_inset
558 </cell>
559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
560 \begin_inset Text
561
562 \begin_layout Standard
563 signed
564 \end_layout
565
566 \end_inset
567 </cell>
568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
569 \begin_inset Text
570
571 \begin_layout Standard
572
573 \end_layout
574
575 \end_inset
576 </cell>
577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
578 \begin_inset Text
579
580 \begin_layout Standard
581 1.175494351E-38, 
582 \family roman
583 \series medium
584 \shape up
585 \size normal
586 \emph off
587 \bar no
588 \noun off
589 \color none
590 3.402823466E+38
591 \end_layout
592
593 \end_inset
594 </cell>
595 </row>
596 <row topline="true" bottomline="true">
597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
598 \begin_inset Text
599
600 \begin_layout Standard
601 pointer
602 \end_layout
603
604 \end_inset
605 </cell>
606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
607 \begin_inset Text
608
609 \begin_layout Standard
610 1, 2, 3 or 4 bytes
611 \end_layout
612
613 \end_inset
614 </cell>
615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
616 \begin_inset Text
617
618 \begin_layout Standard
619 generic
620 \end_layout
621
622 \end_inset
623 </cell>
624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
625 \begin_inset Text
626
627 \begin_layout Standard
628
629 \end_layout
630
631 \end_inset
632 </cell>
633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
634 \begin_inset Text
635
636 \begin_layout Standard
637
638 \end_layout
639
640 \end_inset
641 </cell>
642 </row>
643 </lyxtabular>
644
645 \end_inset
646
647
648 \newline
649 The compiler also allows 
650 \emph on
651 inline assembler code
652 \emph default
653  to be embedded anywhere in a function.
654  In addition, routines developed in assembly can also be called.
655 \newline
656
657 \newline
658 SDCC also
659  provides an option (-
660 \begin_inset ERT
661 status collapsed
662
663 \begin_layout Standard
664
665
666 \backslash
667 /
668 \end_layout
669
670 \end_inset
671
672 -cyclomatic) to report the relative complexity of a function.
673  These functions can then be further optimized, or hand coded in assembly
674  if needed.
675  
676 \newline
677
678 \newline
679 SDCC also comes with a companion source level debugger SDCDB.
680  The debugger currently uses ucSim, a free open source simulator for 8051
681  and other micro-controllers.
682 \newline
683
684 \newline
685 The latest SDCC version can be downloaded from
686  
687 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
688
689 \end_inset
690
691 .
692
693 \series bold
694  
695 \series default
696 \emph on
697 Please note: the compiler will probably always be some steps ahead of this
698  documentation
699 \series bold
700 \emph default
701
702 \begin_inset LatexCommand \index{Status of documentation}
703
704 \end_inset
705
706
707 \begin_inset Foot
708 status open
709
710 \begin_layout Standard
711 Obviously this has pros and cons
712 \end_layout
713
714 \end_inset
715
716 .
717 \end_layout
718
719 \begin_layout Section
720 Open Source
721 \end_layout
722
723 \begin_layout Standard
724 All packages used in this compiler system are 
725 \emph on
726 open source
727 \emph default
728  and 
729 \emph on
730 freeware
731 \emph default
732 ; source code for all the sub-packages (pre-processor, assemblers, linkers
733  etc) is distributed with the package.
734  This documentation is maintained using a free open source word processor
735  (LyX).
736 \newline
737 This program is free software; you can redistribute it and/or modify
738  it under the terms of the GNU General Public License
739 \begin_inset LatexCommand \index{GNU General Public License, GPL}
740
741 \end_inset
742
743  as published by the Free Software Foundation; either version 2, or (at
744  your option) any later version.
745  This program is distributed in the hope that it will be useful, but WITHOUT
746  ANY WARRANTY; without even the implied warranty
747 \begin_inset LatexCommand \index{warranty}
748
749 \end_inset
750
751  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
752  See the GNU General Public License for more details.
753  You should have received a copy of the GNU General Public License along
754  with this program; if not, write to the Free Software Foundation, 59 Temple
755  Place - Suite 330, Boston, MA 02111-1307, USA.
756  In other words, you are welcome to use, share and improve this program.
757  You are forbidden to forbid anyone else to use, share and improve what
758  you give them.
759  Help stamp out software-hoarding! 
760 \end_layout
761
762 \begin_layout Section
763 Typographic conventions
764 \begin_inset LatexCommand \index{Typographic conventions}
765
766 \end_inset
767
768
769 \end_layout
770
771 \begin_layout Standard
772 Throughout this manual, we will use the following convention.
773  Commands you have to type in are printed in 
774 \family sans
775 \series bold
776 "sans serif"
777 \series default
778 .
779
780 \family default
781  Code samples are printed in 
782 \family typewriter
783 typewriter font.
784
785 \family default
786  Interesting items and new terms are printed in 
787 \emph on
788 italic.
789 \end_layout
790
791 \begin_layout Section
792 Compatibility
793 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
794
795 \end_inset
796
797  with previous versions
798 \begin_inset LatexCommand \index{Compatibility with previous versions}
799
800 \end_inset
801
802
803 \end_layout
804
805 \begin_layout Standard
806 Newer versions have usually numerous bug fixes compared with the previous
807  version.
808  But we also sometimes introduce some incompatibilities with older versions.
809  Not just for the fun of it, but to make the compiler more stable, efficient
810  and ANSI compliant
811 \begin_inset LatexCommand \index{ANSI-compliance}
812
813 \end_inset
814
815  (see section 
816 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
817
818 \end_inset
819
820  for ANSI-Compliance).
821  
822 \begin_inset Note Note
823 status collapsed
824
825 \begin_layout Standard
826 It would be fine to add to each item, in which version was it changed.
827 \end_layout
828
829 \end_inset
830
831
832 \newline
833
834 \end_layout
835
836 \begin_layout Itemize
837 short is now equivalent to int (16 bits), it used to be equivalent to char
838  (8 bits) which is not ANSI compliant.
839  To maintain compatibility, old programs may be compiled using the --short-is-8b
840 its commandline option (see 
841 \begin_inset LatexCommand \vref{lyx:--short-is-8bits}
842
843 \end_inset
844
845 ).
846 \end_layout
847
848 \begin_layout Itemize
849 the default directory for gcc-builds where include, library and documentation
850  files are stored is now in /usr/local/share.
851 \end_layout
852
853 \begin_layout Itemize
854 char type parameters to vararg
855 \begin_inset LatexCommand \index{vararg, va\_arg}
856
857 \end_inset
858
859  functions are casted to int unless explicitly casted
860 \begin_inset Marginal
861 status collapsed
862
863 \begin_layout Standard
864
865 \series bold
866 \InsetSpace ~
867 !
868 \end_layout
869
870 \end_inset
871
872 , e.g.: 
873 \newline
874
875 \family typewriter
876 \InsetSpace ~
877 \InsetSpace ~
878 char a=3;
879 \newline
880 \InsetSpace ~
881 \InsetSpace ~
882 printf ("%d %c
883 \backslash
884 n", a, (char)a);
885 \family default
886
887 \newline
888  will push a as an int and as a char resp.
889 \end_layout
890
891 \begin_layout Itemize
892 option -
893 \begin_inset ERT
894 status collapsed
895
896 \begin_layout Standard
897
898
899 \backslash
900 /
901 \end_layout
902
903 \end_inset
904
905 -regextend has been removed.
906 \end_layout
907
908 \begin_layout Itemize
909 option -
910 \begin_inset ERT
911 status collapsed
912
913 \begin_layout Standard
914
915
916 \backslash
917 /
918 \end_layout
919
920 \end_inset
921
922 -noregparms has been removed.
923 \end_layout
924
925 \begin_layout Itemize
926 option -
927 \begin_inset ERT
928 status collapsed
929
930 \begin_layout Standard
931
932
933 \backslash
934 /
935 \end_layout
936
937 \end_inset
938
939 -stack-after-data has been removed.
940 \end_layout
941
942 \begin_layout Itemize
943 bit
944 \begin_inset LatexCommand \index{bit}
945
946 \end_inset
947
948  and sbit
949 \begin_inset LatexCommand \index{sbit}
950
951 \end_inset
952
953
954 \begin_inset LatexCommand \index{\_\_sbit}
955
956 \end_inset
957
958  types now consistently behave like the C99 _Bool type with respect to type
959  conversion
960 \begin_inset LatexCommand \index{type conversion}
961
962 \end_inset
963
964
965 \begin_inset LatexCommand \index{type promotion}
966
967 \end_inset
968
969 .
970  The most common incompatibility resulting from this change is related to
971  bit toggling
972 \begin_inset LatexCommand \index{Bit toggling}
973
974 \end_inset
975
976  idioms, e.g.:
977 \newline
978
979 \family typewriter
980 \InsetSpace ~
981 \InsetSpace ~
982 bit b;
983 \newline
984 \InsetSpace ~
985 \InsetSpace ~
986 b = ~
987 \begin_inset LatexCommand \index{\~\/ Operator}
988
989 \end_inset
990
991 b; /* equivalent to b=1 instead of toggling b */
992 \begin_inset Marginal
993 status collapsed
994
995 \begin_layout Standard
996
997 \series bold
998 \InsetSpace ~
999 !
1000 \end_layout
1001
1002 \end_inset
1003
1004
1005 \newline
1006 \InsetSpace ~
1007 \InsetSpace ~
1008 b = !b; /* toggles b */
1009 \newline
1010
1011 \family default
1012 In previous versions, both forms would have toggled the bit.
1013 \end_layout
1014
1015 \begin_layout Standard
1016
1017 \emph on
1018 <pending: more incompatibilities?>
1019 \end_layout
1020
1021 \begin_layout Section
1022 System Requirements
1023 \end_layout
1024
1025 \begin_layout Standard
1026 What do you need before you start installation of SDCC? A computer, and
1027  a desire to compute.
1028  The preferred method of installation is to compile SDCC from source using
1029  GNU gcc and make.
1030  For Windows some pre-compiled binary distributions are available for your
1031  convenience.
1032  You should have some experience with command line tools and compiler use.
1033 \end_layout
1034
1035 \begin_layout Section
1036 Other Resources
1037 \end_layout
1038
1039 \begin_layout Standard
1040 The SDCC home page at 
1041 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
1042
1043 \end_inset
1044
1045  is a great place to find distribution sets.
1046  You can also find links to the user mailing lists that offer help or discuss
1047  SDCC with other SDCC users.
1048  Web links to other SDCC related sites can also be found here.
1049  This document can be found in the DOC directory of the source package as
1050  a text or HTML file.
1051  A pdf version of this document is available at 
1052 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
1053
1054 \end_inset
1055
1056 .
1057  Some of the other tools (simulator and assembler) included with SDCC contain
1058  their own documentation and can be found in the source distribution.
1059  If you want the latest unreleased software, the complete source package
1060  is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1061 sdcc/trunk/sdcc.
1062 \end_layout
1063
1064 \begin_layout Section
1065 Wishes for the future
1066 \end_layout
1067
1068 \begin_layout Standard
1069 There are (and always will be) some things that could be done.
1070  Here are some I can think of:
1071 \newline
1072
1073 \end_layout
1074
1075 \begin_layout Standard
1076
1077 \family typewriter
1078 char KernelFunction3(char p) at 0x340;
1079 \newline
1080
1081 \end_layout
1082
1083 \begin_layout Standard
1084
1085 \family typewriter
1086 better code banking
1087 \begin_inset LatexCommand \index{code banking (limited support)}
1088
1089 \end_inset
1090
1091  support for mcs51
1092 \newline
1093
1094 \newline
1095
1096 \family default
1097 If you can think of some more, please see the section 
1098 \begin_inset LatexCommand \ref{sub:Requesting-Features}
1099
1100 \end_inset
1101
1102  about filing feature requests
1103 \begin_inset LatexCommand \index{Requesting features}
1104
1105 \end_inset
1106
1107
1108 \begin_inset LatexCommand \index{Feature request}
1109
1110 \end_inset
1111
1112 .
1113 \newline
1114
1115 \end_layout
1116
1117 \begin_layout Chapter
1118 Installing SDCC
1119 \begin_inset LatexCommand \index{Installation}
1120
1121 \end_inset
1122
1123
1124 \end_layout
1125
1126 \begin_layout Standard
1127 For most users it is sufficient to skip to either section 
1128 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
1129
1130 \end_inset
1131
1132  (Unix) or section 
1133 \begin_inset LatexCommand \ref{sub:Windows-Install}
1134
1135 \end_inset
1136
1137  (Windows).
1138  More detailed instructions follow below.
1139 \end_layout
1140
1141 \begin_layout Section
1142 Configure Options
1143 \begin_inset LatexCommand \index{Options SDCC configuration}
1144
1145 \end_inset
1146
1147
1148 \end_layout
1149
1150 \begin_layout Standard
1151 The install paths, search paths and other options are defined when running
1152  'configure'.
1153  The defaults can be overridden by:
1154 \end_layout
1155
1156 \begin_layout List
1157 \labelwidthstring 00.00.0000
1158 -
1159 \begin_inset ERT
1160 status collapsed
1161
1162 \begin_layout Standard
1163
1164
1165 \backslash
1166 /
1167 \end_layout
1168
1169 \end_inset
1170
1171 -prefix see table below
1172 \end_layout
1173
1174 \begin_layout List
1175 \labelwidthstring 00.00.0000
1176 -
1177 \begin_inset ERT
1178 status collapsed
1179
1180 \begin_layout Standard
1181
1182
1183 \backslash
1184 /
1185 \end_layout
1186
1187 \end_inset
1188
1189 -exec_prefix see table below
1190 \end_layout
1191
1192 \begin_layout List
1193 \labelwidthstring 00.00.0000
1194 -
1195 \begin_inset ERT
1196 status collapsed
1197
1198 \begin_layout Standard
1199
1200
1201 \backslash
1202 /
1203 \end_layout
1204
1205 \end_inset
1206
1207 -bindir see table below
1208 \end_layout
1209
1210 \begin_layout List
1211 \labelwidthstring 00.00.0000
1212 -
1213 \begin_inset ERT
1214 status collapsed
1215
1216 \begin_layout Standard
1217
1218
1219 \backslash
1220 /
1221 \end_layout
1222
1223 \end_inset
1224
1225 -datadir see table below
1226 \end_layout
1227
1228 \begin_layout List
1229 \labelwidthstring 00.00.0000
1230 -
1231 \begin_inset ERT
1232 status collapsed
1233
1234 \begin_layout Standard
1235
1236
1237 \backslash
1238 /
1239 \end_layout
1240
1241 \end_inset
1242
1243 -datarootdir see table below
1244 \newline
1245
1246 \end_layout
1247
1248 \begin_layout List
1249 \labelwidthstring 00.00.0000
1250 \InsetSpace ~
1251 \InsetSpace ~
1252 docdir environment variable, see table below
1253 \end_layout
1254
1255 \begin_layout List
1256 \labelwidthstring 00.00.0000
1257 \InsetSpace ~
1258 \InsetSpace ~
1259 include_dir_suffix environment variable, see table below
1260 \end_layout
1261
1262 \begin_layout List
1263 \labelwidthstring 00.00.0000
1264 \InsetSpace ~
1265 \InsetSpace ~
1266 lib_dir_suffix environment variable, see table below
1267 \end_layout
1268
1269 \begin_layout List
1270 \labelwidthstring 00.00.0000
1271 \InsetSpace ~
1272 \InsetSpace ~
1273 sdccconf_h_dir_separator environment variable, either / or 
1274 \backslash
1275
1276 \backslash
1277  makes sense here.
1278  This character will only be used in sdccconf.h; don't forget it's a C-header,
1279  therefore a double-backslash is needed there.
1280 \newline
1281
1282 \end_layout
1283
1284 \begin_layout List
1285 \labelwidthstring 00.00.0000
1286 -
1287 \begin_inset ERT
1288 status collapsed
1289
1290 \begin_layout Standard
1291
1292
1293 \backslash
1294 /
1295 \end_layout
1296
1297 \end_inset
1298
1299 -disable-mcs51-port Excludes the Intel mcs51 port
1300 \end_layout
1301
1302 \begin_layout List
1303 \labelwidthstring 00.00.0000
1304 -
1305 \begin_inset ERT
1306 status collapsed
1307
1308 \begin_layout Standard
1309
1310
1311 \backslash
1312 /
1313 \end_layout
1314
1315 \end_inset
1316
1317 -disable-gbz80-port Excludes the Gameboy gbz80 port
1318 \end_layout
1319
1320 \begin_layout List
1321 \labelwidthstring 00.00.0000
1322 -
1323 \begin_inset ERT
1324 status collapsed
1325
1326 \begin_layout Standard
1327
1328
1329 \backslash
1330 /
1331 \end_layout
1332
1333 \end_inset
1334
1335 -disable-z80-port Excludes the z80 port
1336 \end_layout
1337
1338 \begin_layout List
1339 \labelwidthstring 00.00.0000
1340 -
1341 \begin_inset ERT
1342 status collapsed
1343
1344 \begin_layout Standard
1345
1346
1347 \backslash
1348 /
1349 \end_layout
1350
1351 \end_inset
1352
1353 -disable-avr-port Excludes the AVR port
1354 \end_layout
1355
1356 \begin_layout List
1357 \labelwidthstring 00.00.0000
1358 -
1359 \begin_inset ERT
1360 status collapsed
1361
1362 \begin_layout Standard
1363
1364
1365 \backslash
1366 /
1367 \end_layout
1368
1369 \end_inset
1370
1371 -disable-ds390-port Excludes the DS390 port
1372 \end_layout
1373
1374 \begin_layout List
1375 \labelwidthstring 00.00.0000
1376 -
1377 \begin_inset ERT
1378 status collapsed
1379
1380 \begin_layout Standard
1381
1382
1383 \backslash
1384 /
1385 \end_layout
1386
1387 \end_inset
1388
1389 -disable-hc08-port Excludes the HC08 port
1390 \end_layout
1391
1392 \begin_layout List
1393 \labelwidthstring 00.00.0000
1394 -
1395 \begin_inset ERT
1396 status collapsed
1397
1398 \begin_layout Standard
1399
1400
1401 \backslash
1402 /
1403 \end_layout
1404
1405 \end_inset
1406
1407 -disable-pic-port Excludes the PIC port
1408 \end_layout
1409
1410 \begin_layout List
1411 \labelwidthstring 00.00.0000
1412 -
1413 \begin_inset ERT
1414 status collapsed
1415
1416 \begin_layout Standard
1417
1418
1419 \backslash
1420 /
1421 \end_layout
1422
1423 \end_inset
1424
1425 -disable-xa51-port Excludes the XA51 port
1426 \end_layout
1427
1428 \begin_layout List
1429 \labelwidthstring 00.00.0000
1430 -
1431 \begin_inset ERT
1432 status collapsed
1433
1434 \begin_layout Standard
1435
1436
1437 \backslash
1438 /
1439 \end_layout
1440
1441 \end_inset
1442
1443 -disable-ucsim Disables configuring and building of ucsim
1444 \end_layout
1445
1446 \begin_layout List
1447 \labelwidthstring 00.00.0000
1448 -
1449 \begin_inset ERT
1450 status collapsed
1451
1452 \begin_layout Standard
1453
1454
1455 \backslash
1456 /
1457 \end_layout
1458
1459 \end_inset
1460
1461 -disable-device-lib Disables automatically building device libraries
1462 \end_layout
1463
1464 \begin_layout List
1465 \labelwidthstring 00.00.0000
1466 -
1467 \begin_inset ERT
1468 status collapsed
1469
1470 \begin_layout Standard
1471
1472
1473 \backslash
1474 /
1475 \end_layout
1476
1477 \end_inset
1478
1479 -disable-packihx Disables building packihx
1480 \newline
1481
1482 \end_layout
1483
1484 \begin_layout List
1485 \labelwidthstring 00.00.0000
1486 -
1487 \begin_inset ERT
1488 status collapsed
1489
1490 \begin_layout Standard
1491
1492
1493 \backslash
1494 /
1495 \end_layout
1496
1497 \end_inset
1498
1499 -enable-doc Build pdf, html and txt files from the lyx sources
1500 \end_layout
1501
1502 \begin_layout List
1503 \labelwidthstring 00.00.0000
1504 -
1505 \begin_inset ERT
1506 status collapsed
1507
1508 \begin_layout Standard
1509
1510
1511 \backslash
1512 /
1513 \end_layout
1514
1515 \end_inset
1516
1517 -enable-libgc Use the Bohem memory allocator.
1518  Lower runtime footprint.
1519 \end_layout
1520
1521 \begin_layout Standard
1522 Furthermore the environment variables CC, CFLAGS, ...
1523  the tools and their arguments can be influenced.
1524  Please see `configure -
1525 \begin_inset ERT
1526 status collapsed
1527
1528 \begin_layout Standard
1529
1530
1531 \backslash
1532 /
1533 \end_layout
1534
1535 \end_inset
1536
1537 -help` and the man/info pages of `configure` for details.
1538 \newline
1539
1540 \newline
1541 The names of the
1542  standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1543 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1544  SDCC_LIB_NAME are defined by `configure` too.
1545  At the moment it's not possible to change the default settings (it was
1546  simply never required).
1547 \newline
1548
1549 \newline
1550 These configure options are compiled into the binaries,
1551  and can only be changed by rerunning 'configure' and recompiling SDCC.
1552  The configure options are written in 
1553 \emph on
1554 italics
1555 \emph default
1556  to distinguish them from run time environment variables (see section search
1557  paths).
1558 \newline
1559
1560 \newline
1561 The settings for 
1562 \begin_inset Quotes sld
1563 \end_inset
1564
1565 Win32 builds
1566 \begin_inset Quotes srd
1567 \end_inset
1568
1569  are used by the SDCC team to build the official Win32 binaries.
1570  The SDCC team uses Mingw32 to build the official Windows binaries, because
1571  it's
1572 \end_layout
1573
1574 \begin_layout Enumerate
1575 open source, 
1576 \end_layout
1577
1578 \begin_layout Enumerate
1579 a gcc compiler and last but not least
1580 \end_layout
1581
1582 \begin_layout Enumerate
1583 the binaries can be built by cross compiling on SDCC Distributed Compile
1584  Farm.
1585 \end_layout
1586
1587 \begin_layout Standard
1588 See the examples, how to pass the Win32 settings to 'configure'.
1589  The other Win32 builds using Borland, VC or whatever don't use 'configure',
1590  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1591  for Win32.
1592 \newline
1593
1594 \newline
1595 These defaults are:
1596 \newline
1597
1598 \end_layout
1599
1600 \begin_layout Standard
1601 \align center
1602 \begin_inset Tabular
1603 <lyxtabular version="3" rows="9" columns="3">
1604 <features>
1605 <column alignment="block" valignment="top" leftline="true" width="0in">
1606 <column alignment="block" valignment="top" leftline="true" width="0in">
1607 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1608 <row topline="true" bottomline="true">
1609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1610 \begin_inset Text
1611
1612 \begin_layout Standard
1613 Variable
1614 \end_layout
1615
1616 \end_inset
1617 </cell>
1618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1619 \begin_inset Text
1620
1621 \begin_layout Standard
1622 default
1623 \end_layout
1624
1625 \end_inset
1626 </cell>
1627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1628 \begin_inset Text
1629
1630 \begin_layout Standard
1631 Win32 builds
1632 \end_layout
1633
1634 \end_inset
1635 </cell>
1636 </row>
1637 <row topline="true">
1638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1639 \begin_inset Text
1640
1641 \begin_layout Standard
1642
1643 \emph on
1644 PREFIX
1645 \end_layout
1646
1647 \end_inset
1648 </cell>
1649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1650 \begin_inset Text
1651
1652 \begin_layout Standard
1653 /usr/local
1654 \end_layout
1655
1656 \end_inset
1657 </cell>
1658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1659 \begin_inset Text
1660
1661 \begin_layout Standard
1662
1663 \backslash
1664 sdcc
1665 \end_layout
1666
1667 \end_inset
1668 </cell>
1669 </row>
1670 <row topline="true">
1671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1672 \begin_inset Text
1673
1674 \begin_layout Standard
1675
1676 \emph on
1677 EXEC_PREFIX
1678 \end_layout
1679
1680 \end_inset
1681 </cell>
1682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1683 \begin_inset Text
1684
1685 \begin_layout Standard
1686
1687 \emph on
1688 $PREFIX
1689 \end_layout
1690
1691 \end_inset
1692 </cell>
1693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1694 \begin_inset Text
1695
1696 \begin_layout Standard
1697
1698 \emph on
1699 $PREFIX
1700 \end_layout
1701
1702 \end_inset
1703 </cell>
1704 </row>
1705 <row topline="true">
1706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1707 \begin_inset Text
1708
1709 \begin_layout Standard
1710
1711 \emph on
1712 BINDIR
1713 \end_layout
1714
1715 \end_inset
1716 </cell>
1717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1718 \begin_inset Text
1719
1720 \begin_layout Standard
1721
1722 \emph on
1723 $EXEC_PREFIX
1724 \emph default
1725 /bin
1726 \end_layout
1727
1728 \end_inset
1729 </cell>
1730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1731 \begin_inset Text
1732
1733 \begin_layout Standard
1734
1735 \emph on
1736 $EXEC_PREFIX
1737 \emph default
1738
1739 \backslash
1740 bin
1741 \end_layout
1742
1743 \end_inset
1744 </cell>
1745 </row>
1746 <row topline="true">
1747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1748 \begin_inset Text
1749
1750 \begin_layout Standard
1751
1752 \emph on
1753 DATADIR
1754 \end_layout
1755
1756 \end_inset
1757 </cell>
1758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1759 \begin_inset Text
1760
1761 \begin_layout Standard
1762
1763 \emph on
1764 $DATAROOTDIR
1765 \end_layout
1766
1767 \end_inset
1768 </cell>
1769 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1770 \begin_inset Text
1771
1772 \begin_layout Standard
1773
1774 \emph on
1775 $DATAROOTDIR
1776 \end_layout
1777
1778 \end_inset
1779 </cell>
1780 </row>
1781 <row topline="true">
1782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1783 \begin_inset Text
1784
1785 \begin_layout Standard
1786
1787 \emph on
1788 DATAROOTDIR
1789 \end_layout
1790
1791 \end_inset
1792 </cell>
1793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1794 \begin_inset Text
1795
1796 \begin_layout Standard
1797
1798 \emph on
1799 $PREFIX
1800 \emph default
1801 /share
1802 \end_layout
1803
1804 \end_inset
1805 </cell>
1806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1807 \begin_inset Text
1808
1809 \begin_layout Standard
1810
1811 \emph on
1812 $PREFIX
1813 \end_layout
1814
1815 \end_inset
1816 </cell>
1817 </row>
1818 <row topline="true">
1819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1820 \begin_inset Text
1821
1822 \begin_layout Standard
1823
1824 \emph on
1825 DOCDIR
1826 \end_layout
1827
1828 \end_inset
1829 </cell>
1830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1831 \begin_inset Text
1832
1833 \begin_layout Standard
1834
1835 \emph on
1836 $DATAROOTDIR
1837 \emph default
1838 /sdcc/doc
1839 \end_layout
1840
1841 \end_inset
1842 </cell>
1843 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1844 \begin_inset Text
1845
1846 \begin_layout Standard
1847
1848 \emph on
1849 $DATAROOTDIR
1850 \emph default
1851
1852 \backslash
1853 doc
1854 \end_layout
1855
1856 \end_inset
1857 </cell>
1858 </row>
1859 <row topline="true">
1860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1861 \begin_inset Text
1862
1863 \begin_layout Standard
1864
1865 \emph on
1866 INCLUDE_DIR_SUFFIX
1867 \end_layout
1868
1869 \end_inset
1870 </cell>
1871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1872 \begin_inset Text
1873
1874 \begin_layout Standard
1875 sdcc/include
1876 \end_layout
1877
1878 \end_inset
1879 </cell>
1880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1881 \begin_inset Text
1882
1883 \begin_layout Standard
1884 include
1885 \end_layout
1886
1887 \end_inset
1888 </cell>
1889 </row>
1890 <row topline="true" bottomline="true">
1891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1892 \begin_inset Text
1893
1894 \begin_layout Standard
1895
1896 \emph on
1897 LIB_DIR_SUFFIX
1898 \end_layout
1899
1900 \end_inset
1901 </cell>
1902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1903 \begin_inset Text
1904
1905 \begin_layout Standard
1906 sdcc/lib
1907 \end_layout
1908
1909 \end_inset
1910 </cell>
1911 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1912 \begin_inset Text
1913
1914 \begin_layout Standard
1915 lib
1916 \end_layout
1917
1918 \end_inset
1919 </cell>
1920 </row>
1921 </lyxtabular>
1922
1923 \end_inset
1924
1925
1926 \newline
1927
1928 \end_layout
1929
1930 \begin_layout Standard
1931 \noindent
1932 'configure' also computes relative paths.
1933  This is needed for full relocatability of a binary package and to complete
1934  search paths (see section search paths below):
1935 \newline
1936  
1937 \end_layout
1938
1939 \begin_layout Standard
1940 \align center
1941 \begin_inset Tabular
1942 <lyxtabular version="3" rows="4" columns="3">
1943 <features>
1944 <column alignment="block" valignment="top" leftline="true" width="0in">
1945 <column alignment="block" valignment="top" leftline="true" width="0in">
1946 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1947 <row topline="true" bottomline="true">
1948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1949 \begin_inset Text
1950
1951 \begin_layout Standard
1952 Variable (computed)
1953 \end_layout
1954
1955 \end_inset
1956 </cell>
1957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1958 \begin_inset Text
1959
1960 \begin_layout Standard
1961 default
1962 \end_layout
1963
1964 \end_inset
1965 </cell>
1966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1967 \begin_inset Text
1968
1969 \begin_layout Standard
1970 Win32 builds
1971 \end_layout
1972
1973 \end_inset
1974 </cell>
1975 </row>
1976 <row topline="true" bottomline="true">
1977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1978 \begin_inset Text
1979
1980 \begin_layout Standard
1981
1982 \emph on
1983 BIN2DATA_DIR
1984 \end_layout
1985
1986 \end_inset
1987 </cell>
1988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1989 \begin_inset Text
1990
1991 \begin_layout Standard
1992 ../share
1993 \end_layout
1994
1995 \end_inset
1996 </cell>
1997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1998 \begin_inset Text
1999
2000 \begin_layout Standard
2001 ..
2002 \end_layout
2003
2004 \end_inset
2005 </cell>
2006 </row>
2007 <row bottomline="true">
2008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2009 \begin_inset Text
2010
2011 \begin_layout Standard
2012
2013 \emph on
2014 PREFIX2BIN_DIR
2015 \end_layout
2016
2017 \end_inset
2018 </cell>
2019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2020 \begin_inset Text
2021
2022 \begin_layout Standard
2023 bin
2024 \end_layout
2025
2026 \end_inset
2027 </cell>
2028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2029 \begin_inset Text
2030
2031 \begin_layout Standard
2032 bin
2033 \end_layout
2034
2035 \end_inset
2036 </cell>
2037 </row>
2038 <row bottomline="true">
2039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2040 \begin_inset Text
2041
2042 \begin_layout Standard
2043
2044 \emph on
2045 PREFIX2DATA_DIR
2046 \end_layout
2047
2048 \end_inset
2049 </cell>
2050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2051 \begin_inset Text
2052
2053 \begin_layout Standard
2054 share/sdcc
2055 \end_layout
2056
2057 \end_inset
2058 </cell>
2059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2060 \begin_inset Text
2061
2062 \begin_layout Standard
2063
2064 \end_layout
2065
2066 \end_inset
2067 </cell>
2068 </row>
2069 </lyxtabular>
2070
2071 \end_inset
2072
2073
2074 \newline
2075
2076 \end_layout
2077
2078 \begin_layout Standard
2079 \noindent
2080 Examples:
2081 \end_layout
2082
2083 \begin_layout LyX-Code
2084 ./configure
2085 \newline
2086 ./configure -
2087 \begin_inset ERT
2088 status collapsed
2089
2090 \begin_layout Standard
2091
2092
2093 \backslash
2094 /
2095 \end_layout
2096
2097 \end_inset
2098
2099 -prefix=
2100 \begin_inset Quotes srd
2101 \end_inset
2102
2103 /usr/bin
2104 \begin_inset Quotes srd
2105 \end_inset
2106
2107  -
2108 \begin_inset ERT
2109 status collapsed
2110
2111 \begin_layout Standard
2112
2113
2114 \backslash
2115 /
2116 \end_layout
2117
2118 \end_inset
2119
2120 -datarootdir=
2121 \begin_inset Quotes srd
2122 \end_inset
2123
2124 /usr/share
2125 \begin_inset Quotes srd
2126 \end_inset
2127
2128
2129 \newline
2130 ./configure -
2131 \begin_inset ERT
2132 status collapsed
2133
2134 \begin_layout Standard
2135
2136
2137 \backslash
2138 /
2139 \end_layout
2140
2141 \end_inset
2142
2143 -disable-avr-port -
2144 \begin_inset ERT
2145 status collapsed
2146
2147 \begin_layout Standard
2148
2149
2150 \backslash
2151 /
2152 \end_layout
2153
2154 \end_inset
2155
2156 -disable-xa51-port
2157 \end_layout
2158
2159 \begin_layout Standard
2160 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2161 32'):
2162 \end_layout
2163
2164 \begin_layout LyX-Code
2165 ./configure 
2166 \backslash
2167
2168 \newline
2169 CC=
2170 \begin_inset Quotes srd
2171 \end_inset
2172
2173 i586-mingw32msvc-gcc
2174 \begin_inset Quotes srd
2175 \end_inset
2176
2177  CXX=
2178 \begin_inset Quotes srd
2179 \end_inset
2180
2181 i586-mingw32msvc-g++
2182 \begin_inset Quotes srd
2183 \end_inset
2184
2185  
2186 \backslash
2187  
2188 \newline
2189 RANLIB=
2190 \begin_inset Quotes srd
2191 \end_inset
2192
2193 i586-mingw32msvc-ranlib
2194 \begin_inset Quotes srd
2195 \end_inset
2196
2197  
2198 \backslash
2199
2200 \newline
2201 STRIP=
2202 \begin_inset Quotes srd
2203 \end_inset
2204
2205 i586-mingw32msvc-strip
2206 \begin_inset Quotes srd
2207 \end_inset
2208
2209  
2210 \backslash
2211
2212 \newline
2213 -
2214 \begin_inset ERT
2215 status collapsed
2216
2217 \begin_layout Standard
2218
2219
2220 \backslash
2221 /
2222 \end_layout
2223
2224 \end_inset
2225
2226 -prefix=
2227 \begin_inset Quotes srd
2228 \end_inset
2229
2230 /sdcc
2231 \begin_inset Quotes srd
2232 \end_inset
2233
2234  
2235 \backslash
2236
2237 \newline
2238 -
2239 \begin_inset ERT
2240 status collapsed
2241
2242 \begin_layout Standard
2243
2244
2245 \backslash
2246 /
2247 \end_layout
2248
2249 \end_inset
2250
2251 -datarootdir=
2252 \begin_inset Quotes srd
2253 \end_inset
2254
2255 /sdcc
2256 \begin_inset Quotes srd
2257 \end_inset
2258
2259  
2260 \backslash
2261
2262 \newline
2263 docdir=
2264 \begin_inset Quotes srd
2265 \end_inset
2266
2267
2268 \backslash
2269 ${datarootdir}/doc
2270 \begin_inset Quotes srd
2271 \end_inset
2272
2273  
2274 \backslash
2275
2276 \newline
2277 include_dir_suffix=
2278 \begin_inset Quotes srd
2279 \end_inset
2280
2281 include
2282 \begin_inset Quotes srd
2283 \end_inset
2284
2285  
2286 \backslash
2287
2288 \newline
2289 lib_dir_suffix=
2290 \begin_inset Quotes srd
2291 \end_inset
2292
2293 lib
2294 \begin_inset Quotes srd
2295 \end_inset
2296
2297  
2298 \backslash
2299
2300 \newline
2301 sdccconf_h_dir_separator=
2302 \begin_inset Quotes srd
2303 \end_inset
2304
2305
2306 \backslash
2307
2308 \backslash
2309
2310 \backslash
2311
2312 \backslash
2313
2314 \begin_inset Quotes srd
2315 \end_inset
2316
2317  
2318 \backslash
2319
2320 \newline
2321 -
2322 \begin_inset ERT
2323 status collapsed
2324
2325 \begin_layout Standard
2326
2327
2328 \backslash
2329 /
2330 \end_layout
2331
2332 \end_inset
2333
2334 -disable-device-lib
2335 \backslash
2336
2337 \newline
2338 -
2339 \begin_inset ERT
2340 status collapsed
2341
2342 \begin_layout Standard
2343
2344
2345 \backslash
2346 /
2347 \end_layout
2348
2349 \end_inset
2350
2351 -host=i586-mingw32msvc
2352 \backslash
2353
2354 \newline
2355 -
2356 \begin_inset ERT
2357 status collapsed
2358
2359 \begin_layout Standard
2360
2361
2362 \backslash
2363 /
2364 \end_layout
2365
2366 \end_inset
2367
2368 -build=unknown-unknown-linux-gnu
2369 \end_layout
2370
2371 \begin_layout Standard
2372 To 
2373 \begin_inset Quotes sld
2374 \end_inset
2375
2376 cross
2377 \begin_inset Quotes srd
2378 \end_inset
2379
2380 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2381 ):
2382 \end_layout
2383
2384 \begin_layout LyX-Code
2385 ./configure -C 
2386 \backslash
2387
2388 \newline
2389 -
2390 \begin_inset ERT
2391 status collapsed
2392
2393 \begin_layout Standard
2394
2395
2396 \backslash
2397 /
2398 \end_layout
2399
2400 \end_inset
2401
2402 -prefix=
2403 \begin_inset Quotes srd
2404 \end_inset
2405
2406 /sdcc
2407 \begin_inset Quotes srd
2408 \end_inset
2409
2410  
2411 \backslash
2412
2413 \newline
2414 -
2415 \begin_inset ERT
2416 status collapsed
2417
2418 \begin_layout Standard
2419
2420
2421 \backslash
2422 /
2423 \end_layout
2424
2425 \end_inset
2426
2427 -datarootdir=
2428 \begin_inset Quotes srd
2429 \end_inset
2430
2431 /sdcc
2432 \begin_inset Quotes srd
2433 \end_inset
2434
2435  
2436 \backslash
2437
2438 \newline
2439 docdir=
2440 \begin_inset Quotes srd
2441 \end_inset
2442
2443
2444 \backslash
2445 ${datarootdir}/doc
2446 \begin_inset Quotes srd
2447 \end_inset
2448
2449  
2450 \backslash
2451  
2452 \newline
2453 include_dir_suffix=
2454 \begin_inset Quotes srd
2455 \end_inset
2456
2457 include
2458 \begin_inset Quotes srd
2459 \end_inset
2460
2461  
2462 \backslash
2463
2464 \newline
2465 lib_dir_suffix=
2466 \begin_inset Quotes srd
2467 \end_inset
2468
2469 lib
2470 \begin_inset Quotes srd
2471 \end_inset
2472
2473  
2474 \backslash
2475
2476 \newline
2477 sdccconf_h_dir_separator=
2478 \begin_inset Quotes srd
2479 \end_inset
2480
2481
2482 \backslash
2483
2484 \backslash
2485
2486 \backslash
2487
2488 \backslash
2489
2490 \begin_inset Quotes srd
2491 \end_inset
2492
2493  
2494 \backslash
2495
2496 \newline
2497 CC=
2498 \begin_inset Quotes srd
2499 \end_inset
2500
2501 gcc -mno-cygwin
2502 \begin_inset Quotes srd
2503 \end_inset
2504
2505  
2506 \backslash
2507
2508 \newline
2509 CXX=
2510 \begin_inset Quotes srd
2511 \end_inset
2512
2513 g++ -mno-cygwin
2514 \begin_inset Quotes srd
2515 \end_inset
2516
2517  
2518 \end_layout
2519
2520 \begin_layout Standard
2521 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2522  The option '-
2523 \begin_inset ERT
2524 status collapsed
2525
2526 \begin_layout Standard
2527
2528
2529 \backslash
2530 /
2531 \end_layout
2532
2533 \end_inset
2534
2535 -C' turns on caching, which gives a little bit extra speed.
2536  However if options are changed, it can be necessary to delete the config.cache
2537  file.
2538 \end_layout
2539
2540 \begin_layout Section
2541 Install paths
2542 \begin_inset LatexCommand \label{sub:Install-paths}
2543
2544 \end_inset
2545
2546
2547 \begin_inset LatexCommand \index{Install paths}
2548
2549 \end_inset
2550
2551
2552 \end_layout
2553
2554 \begin_layout Standard
2555 \begin_inset VSpace medskip
2556 \end_inset
2557
2558
2559 \end_layout
2560
2561 \begin_layout Standard
2562 \align center
2563 \begin_inset Tabular
2564 <lyxtabular version="3" rows="5" columns="4">
2565 <features>
2566 <column alignment="left" valignment="top" leftline="true" width="0">
2567 <column alignment="left" valignment="top" leftline="true" width="0">
2568 <column alignment="left" valignment="top" leftline="true" width="0">
2569 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2570 <row topline="true" bottomline="true">
2571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2572 \begin_inset Text
2573
2574 \begin_layout Standard
2575
2576 \series bold
2577 Description
2578 \end_layout
2579
2580 \end_inset
2581 </cell>
2582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2583 \begin_inset Text
2584
2585 \begin_layout Standard
2586
2587 \series bold
2588 Path
2589 \end_layout
2590
2591 \end_inset
2592 </cell>
2593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2594 \begin_inset Text
2595
2596 \begin_layout Standard
2597
2598 \series bold
2599 Default
2600 \end_layout
2601
2602 \end_inset
2603 </cell>
2604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2605 \begin_inset Text
2606
2607 \begin_layout Standard
2608
2609 \series bold
2610 Win32 builds
2611 \end_layout
2612
2613 \end_inset
2614 </cell>
2615 </row>
2616 <row topline="true">
2617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2618 \begin_inset Text
2619
2620 \begin_layout Standard
2621 Binary files*
2622 \end_layout
2623
2624 \end_inset
2625 </cell>
2626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2627 \begin_inset Text
2628
2629 \begin_layout Standard
2630
2631 \emph on
2632 $EXEC_PREFIX
2633 \end_layout
2634
2635 \end_inset
2636 </cell>
2637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2638 \begin_inset Text
2639
2640 \begin_layout Standard
2641 /usr/local/bin
2642 \end_layout
2643
2644 \end_inset
2645 </cell>
2646 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2647 \begin_inset Text
2648
2649 \begin_layout Standard
2650
2651 \backslash
2652 sdcc
2653 \backslash
2654 bin
2655 \end_layout
2656
2657 \end_inset
2658 </cell>
2659 </row>
2660 <row topline="true">
2661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2662 \begin_inset Text
2663
2664 \begin_layout Standard
2665 Include files
2666 \end_layout
2667
2668 \end_inset
2669 </cell>
2670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2671 \begin_inset Text
2672
2673 \begin_layout Standard
2674
2675 \emph on
2676 $DATADIR/ $INCLUDE_DIR_SUFFIX
2677 \end_layout
2678
2679 \end_inset
2680 </cell>
2681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2682 \begin_inset Text
2683
2684 \begin_layout Standard
2685 /usr/local/share/sdcc/include
2686 \end_layout
2687
2688 \end_inset
2689 </cell>
2690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2691 \begin_inset Text
2692
2693 \begin_layout Standard
2694
2695 \backslash
2696 sdcc
2697 \backslash
2698 include
2699 \end_layout
2700
2701 \end_inset
2702 </cell>
2703 </row>
2704 <row topline="true">
2705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2706 \begin_inset Text
2707
2708 \begin_layout Standard
2709 Library file**
2710 \end_layout
2711
2712 \end_inset
2713 </cell>
2714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2715 \begin_inset Text
2716
2717 \begin_layout Standard
2718
2719 \emph on
2720 $DATADIR/$LIB_DIR_SUFFIX
2721 \end_layout
2722
2723 \end_inset
2724 </cell>
2725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2726 \begin_inset Text
2727
2728 \begin_layout Standard
2729 /usr/local/share/sdcc/lib
2730 \end_layout
2731
2732 \end_inset
2733 </cell>
2734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2735 \begin_inset Text
2736
2737 \begin_layout Standard
2738
2739 \backslash
2740 sdcc
2741 \backslash
2742 lib
2743 \end_layout
2744
2745 \end_inset
2746 </cell>
2747 </row>
2748 <row topline="true" bottomline="true">
2749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2750 \begin_inset Text
2751
2752 \begin_layout Standard
2753 Documentation
2754 \end_layout
2755
2756 \end_inset
2757 </cell>
2758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2759 \begin_inset Text
2760
2761 \begin_layout Standard
2762
2763 \emph on
2764 $DOCDIR
2765 \end_layout
2766
2767 \end_inset
2768 </cell>
2769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2770 \begin_inset Text
2771
2772 \begin_layout Standard
2773 /usr/local/share/sdcc/doc
2774 \end_layout
2775
2776 \end_inset
2777 </cell>
2778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2779 \begin_inset Text
2780
2781 \begin_layout Standard
2782
2783 \backslash
2784 sdcc
2785 \backslash
2786 doc
2787 \end_layout
2788
2789 \end_inset
2790 </cell>
2791 </row>
2792 </lyxtabular>
2793
2794 \end_inset
2795
2796
2797 \end_layout
2798
2799 \begin_layout Verse
2800
2801 \size footnotesize
2802 *compiler, preprocessor, assembler, and linker
2803 \newline
2804 **the 
2805 \shape italic
2806 model
2807 \shape default
2808  is auto-appended by the compiler, e.g.
2809  small, large, z80, ds390 etc
2810 \end_layout
2811
2812 \begin_layout Standard
2813 \noindent
2814 The install paths can still be changed during `make install` with e.g.:
2815 \end_layout
2816
2817 \begin_layout LyX-Code
2818 make install prefix=$(HOME)/local/sdcc
2819 \end_layout
2820
2821 \begin_layout Standard
2822 Of course this doesn't change the search paths compiled into the binaries.
2823 \newline
2824
2825 \newline
2826 Moreove
2827 r the install path can be changed by defining DESTDIR
2828 \begin_inset LatexCommand \index{DESTDIR}
2829
2830 \end_inset
2831
2832 :
2833 \end_layout
2834
2835 \begin_layout LyX-Code
2836 make install DESTDIR=$(HOME)/sdcc.rpm/
2837 \end_layout
2838
2839 \begin_layout Standard
2840 Please note that DESTDIR must have a trailing slash!
2841 \end_layout
2842
2843 \begin_layout Section
2844 Search Paths
2845 \begin_inset LatexCommand \label{sub:Search-Paths}
2846
2847 \end_inset
2848
2849
2850 \begin_inset LatexCommand \index{Search path}
2851
2852 \end_inset
2853
2854
2855 \end_layout
2856
2857 \begin_layout Standard
2858 Some search paths or parts of them are determined by configure variables
2859  (in 
2860 \emph on
2861 italics
2862 \emph default
2863 , see section above).
2864  Further search paths are determined by environment variables during runtime.
2865  
2866 \newline
2867 The paths searched when running the compiler are as follows (the first
2868  catch wins):
2869 \newline
2870
2871 \newline
2872 1.
2873  Binary files (preprocessor, assembler and linker)
2874 \newline
2875
2876 \end_layout
2877
2878 \begin_layout Standard
2879 \align center
2880 \begin_inset Tabular
2881 <lyxtabular version="3" rows="4" columns="3">
2882 <features>
2883 <column alignment="block" valignment="top" leftline="true" width="0in">
2884 <column alignment="block" valignment="top" leftline="true" width="0in">
2885 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2886 <row topline="true" bottomline="true">
2887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2888 \begin_inset Text
2889
2890 \begin_layout Standard
2891 Search path
2892 \end_layout
2893
2894 \end_inset
2895 </cell>
2896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2897 \begin_inset Text
2898
2899 \begin_layout Standard
2900 default
2901 \end_layout
2902
2903 \end_inset
2904 </cell>
2905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2906 \begin_inset Text
2907
2908 \begin_layout Standard
2909 Win32 builds
2910 \end_layout
2911
2912 \end_inset
2913 </cell>
2914 </row>
2915 <row topline="true">
2916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2917 \begin_inset Text
2918
2919 \begin_layout Standard
2920 $SDCC_HOME/
2921 \emph on
2922 $PPREFIX2BIN_DIR
2923 \end_layout
2924
2925 \end_inset
2926 </cell>
2927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2928 \begin_inset Text
2929
2930 \begin_layout Standard
2931 $SDCC_HOME/bin
2932 \end_layout
2933
2934 \end_inset
2935 </cell>
2936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2937 \begin_inset Text
2938
2939 \begin_layout Standard
2940 $SDCC_HOME
2941 \backslash
2942 bin
2943 \end_layout
2944
2945 \end_inset
2946 </cell>
2947 </row>
2948 <row topline="true">
2949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2950 \begin_inset Text
2951
2952 \begin_layout Standard
2953 Path of argv[0] (if available)
2954 \end_layout
2955
2956 \end_inset
2957 </cell>
2958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2959 \begin_inset Text
2960
2961 \begin_layout Standard
2962 Path of argv[0]
2963 \end_layout
2964
2965 \end_inset
2966 </cell>
2967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2968 \begin_inset Text
2969
2970 \begin_layout Standard
2971 Path of argv[0]
2972 \end_layout
2973
2974 \end_inset
2975 </cell>
2976 </row>
2977 <row topline="true" bottomline="true">
2978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2979 \begin_inset Text
2980
2981 \begin_layout Standard
2982 $PATH
2983 \end_layout
2984
2985 \end_inset
2986 </cell>
2987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2988 \begin_inset Text
2989
2990 \begin_layout Standard
2991 $PATH
2992 \end_layout
2993
2994 \end_inset
2995 </cell>
2996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2997 \begin_inset Text
2998
2999 \begin_layout Standard
3000 $PATH
3001 \end_layout
3002
3003 \end_inset
3004 </cell>
3005 </row>
3006 </lyxtabular>
3007
3008 \end_inset
3009
3010  
3011 \newline
3012
3013 \end_layout
3014
3015 \begin_layout Standard
3016 \noindent
3017 2.
3018  Include files
3019 \newline
3020
3021 \end_layout
3022
3023 \begin_layout Standard
3024 \align center
3025 \begin_inset Tabular
3026 <lyxtabular version="3" rows="6" columns="3">
3027 <features>
3028 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3029 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3030 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3031 <row topline="true" bottomline="true">
3032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3033 \begin_inset Text
3034
3035 \begin_layout Standard
3036 Search path
3037 \end_layout
3038
3039 \end_inset
3040 </cell>
3041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3042 \begin_inset Text
3043
3044 \begin_layout Standard
3045 default
3046 \end_layout
3047
3048 \end_inset
3049 </cell>
3050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3051 \begin_inset Text
3052
3053 \begin_layout Standard
3054 Win32 builds
3055 \end_layout
3056
3057 \end_inset
3058 </cell>
3059 </row>
3060 <row topline="true">
3061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3062 \begin_inset Text
3063
3064 \begin_layout Standard
3065 -
3066 \begin_inset ERT
3067 status collapsed
3068
3069 \begin_layout Standard
3070
3071
3072 \backslash
3073 /
3074 \end_layout
3075
3076 \end_inset
3077
3078 -I dir
3079 \end_layout
3080
3081 \end_inset
3082 </cell>
3083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3084 \begin_inset Text
3085
3086 \begin_layout Standard
3087 -
3088 \begin_inset ERT
3089 status collapsed
3090
3091 \begin_layout Standard
3092
3093
3094 \backslash
3095 /
3096 \end_layout
3097
3098 \end_inset
3099
3100 -I dir
3101 \end_layout
3102
3103 \end_inset
3104 </cell>
3105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3106 \begin_inset Text
3107
3108 \begin_layout Standard
3109 -
3110 \begin_inset ERT
3111 status collapsed
3112
3113 \begin_layout Standard
3114
3115
3116 \backslash
3117 /
3118 \end_layout
3119
3120 \end_inset
3121
3122 -I dir
3123 \end_layout
3124
3125 \end_inset
3126 </cell>
3127 </row>
3128 <row topline="true">
3129 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3130 \begin_inset Text
3131
3132 \begin_layout Standard
3133 $SDCC_INCLUDE
3134 \end_layout
3135
3136 \end_inset
3137 </cell>
3138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3139 \begin_inset Text
3140
3141 \begin_layout Standard
3142 $SDCC_INCLUDE
3143 \end_layout
3144
3145 \end_inset
3146 </cell>
3147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3148 \begin_inset Text
3149
3150 \begin_layout Standard
3151 $SDCC_INCLUDE
3152 \end_layout
3153
3154 \end_inset
3155 </cell>
3156 </row>
3157 <row topline="true">
3158 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3159 \begin_inset Text
3160
3161 \begin_layout Standard
3162 $SDCC_HOME/
3163 \newline
3164
3165 \emph on
3166 $PREFIX2DATA_DIR/
3167 \newline
3168 $INCLUDE_DIR_SUFFIX
3169 \end_layout
3170
3171 \end_inset
3172 </cell>
3173 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3174 \begin_inset Text
3175
3176 \begin_layout Standard
3177 $SDCC_ HOME/
3178 \newline
3179 share/sdcc/
3180 \newline
3181 include
3182 \end_layout
3183
3184 \end_inset
3185 </cell>
3186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3187 \begin_inset Text
3188
3189 \begin_layout Standard
3190 $SDCC_HOME
3191 \backslash
3192 include
3193 \end_layout
3194
3195 \end_inset
3196 </cell>
3197 </row>
3198 <row topline="true">
3199 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3200 \begin_inset Text
3201
3202 \begin_layout Standard
3203 path(argv[0])/
3204 \newline
3205
3206 \emph on
3207 $BIN2DATADIR/
3208 \emph default
3209
3210 \newline
3211
3212 \emph on
3213 $INCLUDE_DIR_SUFFIX
3214 \end_layout
3215
3216 \end_inset
3217 </cell>
3218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3219 \begin_inset Text
3220
3221 \begin_layout Standard
3222 path(argv[0])/
3223 \newline
3224 ../sdcc/include
3225 \newline
3226 \InsetSpace ~
3227 \InsetSpace ~
3228 \InsetSpace ~
3229 \InsetSpace ~
3230 \InsetSpace ~
3231 \InsetSpace ~
3232 \InsetSpace ~
3233 \InsetSpace ~
3234 \InsetSpace ~
3235 \InsetSpace ~
3236 \InsetSpace ~
3237 \InsetSpace ~
3238 \InsetSpace ~
3239 \InsetSpace ~
3240 \InsetSpace ~
3241 \InsetSpace ~
3242 \InsetSpace ~
3243 \InsetSpace ~
3244 \InsetSpace ~
3245 \InsetSpace ~
3246 \InsetSpace ~
3247 \InsetSpace ~
3248 \InsetSpace ~
3249 \InsetSpace ~
3250 \InsetSpace ~
3251 \InsetSpace ~
3252 \InsetSpace ~
3253 \InsetSpace ~
3254 \InsetSpace ~
3255 \InsetSpace ~
3256 \InsetSpace ~
3257 \InsetSpace ~
3258 \InsetSpace ~
3259 \InsetSpace ~
3260 \InsetSpace ~
3261 \InsetSpace ~
3262 \InsetSpace ~
3263 \InsetSpace ~
3264
3265 \end_layout
3266
3267 \end_inset
3268 </cell>
3269 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3270 \begin_inset Text
3271
3272 \begin_layout Standard
3273 path(argv[0])
3274 \backslash
3275 ..
3276 \backslash
3277 include
3278 \end_layout
3279
3280 \end_inset
3281 </cell>
3282 </row>
3283 <row topline="true" bottomline="true">
3284 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3285 \begin_inset Text
3286
3287 \begin_layout Standard
3288
3289 \emph on
3290 $DATADIR/
3291 \emph default
3292
3293 \newline
3294
3295 \emph on
3296 $INCLUDE_DIR_SUFFIX
3297 \end_layout
3298
3299 \end_inset
3300 </cell>
3301 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3302 \begin_inset Text
3303
3304 \begin_layout Standard
3305 /usr/local/share/sdcc/
3306 \newline
3307 include
3308 \end_layout
3309
3310 \end_inset
3311 </cell>
3312 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3313 \begin_inset Text
3314
3315 \begin_layout Standard
3316 (not on Win32)
3317 \end_layout
3318
3319 \end_inset
3320 </cell>
3321 </row>
3322 </lyxtabular>
3323
3324 \end_inset
3325
3326  
3327 \newline
3328
3329 \end_layout
3330
3331 \begin_layout Standard
3332 \noindent
3333 The option -
3334 \begin_inset ERT
3335 status collapsed
3336
3337 \begin_layout Standard
3338
3339
3340 \backslash
3341 /
3342 \end_layout
3343
3344 \end_inset
3345
3346 -nostdinc disables the last two search paths.
3347 \newline
3348
3349 \newline
3350 3.
3351  Library files 
3352 \newline
3353
3354 \end_layout
3355
3356 \begin_layout Standard
3357 With the exception of 
3358 \begin_inset Quotes sld
3359 \end_inset
3360
3361 -
3362 \begin_inset ERT
3363 status collapsed
3364
3365 \begin_layout Standard
3366
3367
3368 \backslash
3369 /
3370 \end_layout
3371
3372 \end_inset
3373
3374 -L dir
3375 \begin_inset Quotes srd
3376 \end_inset
3377
3378  the 
3379 \shape italic
3380 model
3381 \shape default
3382  is auto-appended by the compiler (e.g.
3383  small, large, z80, ds390 etc.).
3384  
3385 \newline
3386
3387 \end_layout
3388
3389 \begin_layout Standard
3390 \align center
3391 \begin_inset Tabular
3392 <lyxtabular version="3" rows="6" columns="3">
3393 <features>
3394 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3395 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3396 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3397 <row topline="true" bottomline="true">
3398 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3399 \begin_inset Text
3400
3401 \begin_layout Standard
3402 Search path
3403 \end_layout
3404
3405 \end_inset
3406 </cell>
3407 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3408 \begin_inset Text
3409
3410 \begin_layout Standard
3411 default
3412 \end_layout
3413
3414 \end_inset
3415 </cell>
3416 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3417 \begin_inset Text
3418
3419 \begin_layout Standard
3420 Win32 builds
3421 \end_layout
3422
3423 \end_inset
3424 </cell>
3425 </row>
3426 <row topline="true">
3427 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3428 \begin_inset Text
3429
3430 \begin_layout Standard
3431 -
3432 \begin_inset ERT
3433 status collapsed
3434
3435 \begin_layout Standard
3436
3437
3438 \backslash
3439 /
3440 \end_layout
3441
3442 \end_inset
3443
3444 -L dir
3445 \end_layout
3446
3447 \end_inset
3448 </cell>
3449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3450 \begin_inset Text
3451
3452 \begin_layout Standard
3453 -
3454 \begin_inset ERT
3455 status collapsed
3456
3457 \begin_layout Standard
3458
3459
3460 \backslash
3461 /
3462 \end_layout
3463
3464 \end_inset
3465
3466 -L dir
3467 \end_layout
3468
3469 \end_inset
3470 </cell>
3471 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3472 \begin_inset Text
3473
3474 \begin_layout Standard
3475 -
3476 \begin_inset ERT
3477 status collapsed
3478
3479 \begin_layout Standard
3480
3481
3482 \backslash
3483 /
3484 \end_layout
3485
3486 \end_inset
3487
3488 -L dir
3489 \end_layout
3490
3491 \end_inset
3492 </cell>
3493 </row>
3494 <row topline="true">
3495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3496 \begin_inset Text
3497
3498 \begin_layout Standard
3499 $SDCC_LIB/
3500 \newline
3501
3502 \emph on
3503 <model>
3504 \end_layout
3505
3506 \end_inset
3507 </cell>
3508 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3509 \begin_inset Text
3510
3511 \begin_layout Standard
3512 $SDCC_LIB/
3513 \newline
3514
3515 \emph on
3516 <model>
3517 \end_layout
3518
3519 \end_inset
3520 </cell>
3521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3522 \begin_inset Text
3523
3524 \begin_layout Standard
3525 $SDCC_LIB
3526 \backslash
3527
3528 \newline
3529
3530 \emph on
3531 <model>
3532 \end_layout
3533
3534 \end_inset
3535 </cell>
3536 </row>
3537 <row topline="true">
3538 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3539 \begin_inset Text
3540
3541 \begin_layout Standard
3542 $SDCC_HOME/
3543 \newline
3544
3545 \emph on
3546 $PREFIX2DATA_DIR/
3547 \newline
3548 $LIB_DIR_SUFFIX/<model>
3549 \end_layout
3550
3551 \end_inset
3552 </cell>
3553 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3554 \begin_inset Text
3555
3556 \begin_layout Standard
3557 $SDCC_HOME/
3558 \newline
3559 share/sdcc/
3560 \newline
3561 lib/
3562 \emph on
3563 <model>
3564 \end_layout
3565
3566 \end_inset
3567 </cell>
3568 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3569 \begin_inset Text
3570
3571 \begin_layout Standard
3572 $SDCC_HOME
3573 \backslash
3574 lib
3575 \backslash
3576
3577 \emph on
3578
3579 \newline
3580 <model>
3581 \end_layout
3582
3583 \end_inset
3584 </cell>
3585 </row>
3586 <row topline="true">
3587 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3588 \begin_inset Text
3589
3590 \begin_layout Standard
3591 path(argv[0])/
3592 \newline
3593
3594 \emph on
3595 $BIN2DATADIR/
3596 \emph default
3597
3598 \newline
3599
3600 \emph on
3601 $LIB_DIR_SUFFIX/<model>
3602 \end_layout
3603
3604 \end_inset
3605 </cell>
3606 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3607 \begin_inset Text
3608
3609 \begin_layout Standard
3610 path(argv[0])/
3611 \newline
3612 ../sdcc/lib/
3613 \emph on
3614 <model>
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 \InsetSpace ~
3655
3656 \end_layout
3657
3658 \end_inset
3659 </cell>
3660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3661 \begin_inset Text
3662
3663 \begin_layout Standard
3664 path(argv[0])
3665 \backslash
3666
3667 \newline
3668 ..
3669 \backslash
3670 lib
3671 \backslash
3672
3673 \emph on
3674 <model>
3675 \newline
3676 \InsetSpace ~
3677 \InsetSpace ~
3678 \InsetSpace ~
3679 \InsetSpace ~
3680 \InsetSpace ~
3681 \InsetSpace ~
3682 \InsetSpace ~
3683 \InsetSpace ~
3684 \InsetSpace ~
3685 \InsetSpace ~
3686 \InsetSpace ~
3687 \InsetSpace ~
3688 \InsetSpace ~
3689 \InsetSpace ~
3690 \InsetSpace ~
3691 \InsetSpace ~
3692 \InsetSpace ~
3693 \InsetSpace ~
3694 \InsetSpace ~
3695 \InsetSpace ~
3696 \InsetSpace ~
3697 \InsetSpace ~
3698 \InsetSpace ~
3699 \InsetSpace ~
3700 \InsetSpace ~
3701 \InsetSpace ~
3702 \InsetSpace ~
3703 \InsetSpace ~
3704 \InsetSpace ~
3705 \InsetSpace ~
3706 \InsetSpace ~
3707 \InsetSpace ~
3708 \InsetSpace ~
3709 \InsetSpace ~
3710 \InsetSpace ~
3711
3712 \end_layout
3713
3714 \end_inset
3715 </cell>
3716 </row>
3717 <row topline="true" bottomline="true">
3718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3719 \begin_inset Text
3720
3721 \begin_layout Standard
3722
3723 \emph on
3724 $DATADIR/
3725 \newline
3726 $LIB_DIR_SUFFIX/<model>
3727 \end_layout
3728
3729 \end_inset
3730 </cell>
3731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3732 \begin_inset Text
3733
3734 \begin_layout Standard
3735 /usr/local/share/sdcc/
3736 \newline
3737 lib/
3738 \emph on
3739 <model>
3740 \end_layout
3741
3742 \end_inset
3743 </cell>
3744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3745 \begin_inset Text
3746
3747 \begin_layout Standard
3748 (not on Win32)
3749 \end_layout
3750
3751 \end_inset
3752 </cell>
3753 </row>
3754 </lyxtabular>
3755
3756 \end_inset
3757
3758
3759 \newline
3760
3761 \end_layout
3762
3763 \begin_layout Standard
3764 \begin_inset Note Note
3765 status collapsed
3766
3767 \begin_layout Standard
3768 Don't delete any of the stray spaces in the table above without checking
3769  the HTML output (last line)!
3770 \end_layout
3771
3772 \end_inset
3773
3774
3775 \end_layout
3776
3777 \begin_layout Standard
3778 \InsetSpace ~
3779
3780 \newline
3781 The option -
3782 \begin_inset ERT
3783 status collapsed
3784
3785 \begin_layout Standard
3786
3787
3788 \backslash
3789 /
3790 \end_layout
3791
3792 \end_inset
3793
3794 -nostdlib disables the last two search paths.
3795 \end_layout
3796
3797 \begin_layout Section
3798 Building SDCC
3799 \begin_inset LatexCommand \index{Building SDCC}
3800
3801 \end_inset
3802
3803
3804 \end_layout
3805
3806 \begin_layout Subsection
3807 Building SDCC on Linux
3808 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
3809
3810 \end_inset
3811
3812
3813 \end_layout
3814
3815 \begin_layout Enumerate
3816
3817 \series medium
3818 Download the source package
3819 \series default
3820  either from the SDCC Subversion repository or from snapshot builds
3821 \series medium
3822 , it will be named something like sdcc
3823 \series default
3824 -src
3825 \series medium
3826 -yyyymmdd-rrrr.t
3827 \series default
3828 ar.
3829 \series medium
3830 bz2
3831 \series default
3832  
3833 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3834
3835 \end_inset
3836
3837 .
3838 \end_layout
3839
3840 \begin_layout Enumerate
3841
3842 \series medium
3843 Bring up a command line terminal, such as xterm.
3844 \end_layout
3845
3846 \begin_layout Enumerate
3847
3848 \series medium
3849 Unpack the file using a command like: 
3850 \family sans
3851 \series bold
3852 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
3853 \begin_inset Quotes srd
3854 \end_inset
3855
3856
3857 \family default
3858 \series medium
3859 , this will create a sub-directory called sdcc with all of the sources.
3860 \end_layout
3861
3862 \begin_layout Enumerate
3863 Change directory into the main SDCC directory, for example type: 
3864 \family sans
3865 \series bold
3866 "cd sdcc
3867 \series default
3868 ".
3869 \end_layout
3870
3871 \begin_layout Enumerate
3872
3873 \series medium
3874 Type 
3875 \family sans
3876 \series bold
3877 "./configure
3878 \family default
3879 \series default
3880 ".
3881  This configures the package for compilation on your system.
3882 \end_layout
3883
3884 \begin_layout Enumerate
3885
3886 \series medium
3887 Type 
3888 \family sans
3889 \series bold
3890 "make
3891 \family default
3892 \series default
3893 "
3894 \series medium
3895 .
3896
3897 \series default
3898  All of the source packages will compile, this can take a while.
3899 \end_layout
3900
3901 \begin_layout Enumerate
3902
3903 \series medium
3904 Type 
3905 \family sans
3906 \series bold
3907 "make install"
3908 \family default
3909 \series default
3910  as root
3911 \series medium
3912 .
3913
3914 \series default
3915  This copies the binary executables, the include files, the libraries and
3916  the documentation to the install directories.
3917  Proceed with section 
3918 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
3919
3920 \end_inset
3921
3922 .
3923 \end_layout
3924
3925 \begin_layout Subsection
3926 Building SDCC on Mac OS X
3927 \end_layout
3928
3929 \begin_layout Standard
3930 Follow the instruction for Linux.
3931 \newline
3932
3933 \newline
3934 On Mac OS X 10.2.x it was reported, that the
3935  default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
3936  Fortunately there's also gcc 2.9.x installed, which works fine.
3937  This compiler can be selected by running 'configure' with:
3938 \end_layout
3939
3940 \begin_layout LyX-Code
3941 ./configure CC=gcc2 CXX=g++2
3942 \end_layout
3943
3944 \begin_layout Subsection
3945 Cross compiling SDCC on Linux for Windows
3946 \end_layout
3947
3948 \begin_layout Standard
3949 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
3950  See section 'Configure Options'.
3951 \end_layout
3952
3953 \begin_layout Subsection
3954 Building SDCC using Cygwin and Mingw32
3955 \end_layout
3956
3957 \begin_layout Standard
3958 For building and installing a Cygwin executable follow the instructions
3959  for Linux.
3960 \newline
3961
3962 \newline
3963 On Cygwin a 
3964 \begin_inset Quotes sld
3965 \end_inset
3966
3967 native
3968 \begin_inset Quotes srd
3969 \end_inset
3970
3971  Win32-binary can be built, which will not need the Cygwin-DLL.
3972  For the necessary 'configure' options see section 'configure options' or
3973  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3974 \newline
3975
3976 \newline
3977 In order to install
3978  Cygwin on Windows download setup.exe from 
3979 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3980
3981 \end_inset
3982
3983 .
3984  Run it, set the 
3985 \begin_inset Quotes sld
3986 \end_inset
3987
3988 default text file type
3989 \begin_inset Quotes srd
3990 \end_inset
3991
3992  to 
3993 \begin_inset Quotes sld
3994 \end_inset
3995
3996 unix
3997 \begin_inset Quotes srd
3998 \end_inset
3999
4000  and download/install at least the following packages.
4001  Some packages are selected by default, others will be automatically selected
4002  because of dependencies with the manually selected packages.
4003  Never deselect these packages!
4004 \end_layout
4005
4006 \begin_layout Itemize
4007 flex
4008 \end_layout
4009
4010 \begin_layout Itemize
4011 bison
4012 \end_layout
4013
4014 \begin_layout Itemize
4015 gcc ; version 3.x is fine, no need to use the old 2.9x
4016 \end_layout
4017
4018 \begin_layout Itemize
4019 binutils ; selected with gcc
4020 \end_layout
4021
4022 \begin_layout Itemize
4023 make
4024 \end_layout
4025
4026 \begin_layout Itemize
4027 rxvt ; a nice console, which makes life much easier under windoze (see below)
4028 \end_layout
4029
4030 \begin_layout Itemize
4031 man ; not really needed for building SDCC, but you'll miss it sooner or
4032  later
4033 \end_layout
4034
4035 \begin_layout Itemize
4036 less ; not really needed for building SDCC, but you'll miss it sooner or
4037  later
4038 \end_layout
4039
4040 \begin_layout Itemize
4041 svn ; only if you use Subversion access
4042 \end_layout
4043
4044 \begin_layout Standard
4045 If you want to develop something you'll need:
4046 \end_layout
4047
4048 \begin_layout Itemize
4049 python ; for the regression tests
4050 \end_layout
4051
4052 \begin_layout Itemize
4053 gdb ; the gnu debugger, together with the nice GUI 
4054 \begin_inset Quotes sld
4055 \end_inset
4056
4057 insight
4058 \begin_inset Quotes srd
4059 \end_inset
4060
4061
4062 \end_layout
4063
4064 \begin_layout Itemize
4065 openssh ; to access the CF or commit changes
4066 \end_layout
4067
4068 \begin_layout Itemize
4069 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4070  use autoconf-stable!
4071 \end_layout
4072
4073 \begin_layout Standard
4074 rxvt is a nice console with history.
4075  Replace in your cygwin.bat the line
4076 \end_layout
4077
4078 \begin_layout LyX-Code
4079 bash -
4080 \begin_inset ERT
4081 status collapsed
4082
4083 \begin_layout Standard
4084
4085
4086 \backslash
4087 /
4088 \end_layout
4089
4090 \end_inset
4091
4092 -login -i 
4093 \end_layout
4094
4095 \begin_layout Standard
4096 with (one line):
4097 \end_layout
4098
4099 \begin_layout LyX-Code
4100 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4101 \end_layout
4102
4103 \begin_layout LyX-Code
4104      -bg black -fg white -geometry 100x65 -e bash -
4105 \begin_inset ERT
4106 status collapsed
4107
4108 \begin_layout Standard
4109
4110
4111 \backslash
4112 /
4113 \end_layout
4114
4115 \end_inset
4116
4117 -login
4118 \end_layout
4119
4120 \begin_layout Standard
4121 Text selected with the mouse is automatically copied to the clipboard, pasting
4122  works with shift-insert.
4123 \newline
4124
4125 \newline
4126 The other good tip is to make sure you have no //c/-styl
4127 e paths anywhere, use /cygdrive/c/ instead.
4128  Using // invokes a network lookup which is very slow.
4129  If you think 
4130 \begin_inset Quotes sld
4131 \end_inset
4132
4133 cygdrive
4134 \begin_inset Quotes srd
4135 \end_inset
4136
4137  is too long, you can change it with e.g.
4138 \end_layout
4139
4140 \begin_layout LyX-Code
4141 mount -s -u -c /mnt
4142 \end_layout
4143
4144 \begin_layout Standard
4145 SDCC sources use the unix line ending LF.
4146  Life is much easier, if you store the source tree on a drive which is mounted
4147  in binary mode.
4148  And use an editor which can handle LF-only line endings.
4149  Make sure not to commit files with windows line endings.
4150  The tabulator spacing
4151 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
4152
4153 \end_inset
4154
4155  used in the project is 8.
4156  Although a tabulator spacing of 8 is a sensible choice for programmers
4157  (it's a power of 2 and allows to display 8/16 bit signed variables without
4158  loosing columns) the plan is to move towards using only spaces in the source.
4159 \end_layout
4160
4161 \begin_layout Subsection
4162 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4163 \end_layout
4164
4165 \begin_layout Standard
4166
4167 \series medium
4168 Download the source package
4169 \series default
4170  either from the SDCC Subversion repository or from the 
4171 \begin_inset LatexCommand \url[snapshot builds]{http://sdcc.sourceforge.net/snap.php}
4172
4173 \end_inset
4174
4175
4176 \series medium
4177 , it will be named something like sdcc
4178 \series default
4179 -src
4180 \series medium
4181 -yyyymmdd-rrrr.tar.bz2.
4182
4183 \series default
4184  SDCC is distributed with all the projects, workspaces, and files you need
4185  to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4186  The workspace name is 'sdcc.dsw'.
4187  Please note that as it is now, all the executables are created in a folder
4188  called sdcc
4189 \backslash
4190 bin_vc.
4191  Once built you need to copy the executables from sdcc
4192 \backslash
4193 bin_vc to sdcc
4194 \backslash
4195 bin before running SDCC.
4196  
4197 \newline
4198
4199 \newline
4200 WARNING: Visual studio is very picky with line terminations; it expects
4201  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4202  When using the Subversion repository it's easiest to configure the svn
4203  client to convert automatically for you.
4204  If however you are getting a message such as "This makefile was not generated
4205  by Developer Studio etc.
4206  etc.
4207 \begin_inset Quotes srd
4208 \end_inset
4209
4210  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4211  need to convert the Unix style line endings to DOS style line endings.
4212  To do so you can use the 
4213 \begin_inset Quotes sld
4214 \end_inset
4215
4216 unix2dos
4217 \begin_inset Quotes srd
4218 \end_inset
4219
4220  utility freely available on the internet.
4221  Doug Hawkins reported in the sdcc-user list that this works:
4222 \newline
4223
4224 \newline
4225 C:
4226 \backslash
4227 Programming
4228 \backslash
4229 SDCC> unix2dos sdcc.dsw
4230 \newline
4231 C:
4232 \backslash
4233 Programming
4234 \backslash
4235 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4236 \newline
4237
4238 \newline
4239 In order to build SDCC with MSVC
4240  you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4241  One good place to get them is 
4242 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
4243
4244 \end_inset
4245
4246
4247 \newline
4248
4249 \newline
4250 Download the file UnxUtils
4251 \begin_inset LatexCommand \index{UnxUtils}
4252
4253 \end_inset
4254
4255 .zip.
4256  Now you have to install the utilities and setup MSVC so it can locate the
4257  required programs.
4258  Here there are two alternatives (choose one!):
4259 \end_layout
4260
4261 \begin_layout Enumerate
4262 The easy way:
4263 \newline
4264
4265 \newline
4266 a) Extract UnxUtils.zip to your C:
4267 \backslash
4268  hard disk PRESERVING the original paths, otherwise bison won't work.
4269  (If you are using WinZip make certain that 'Use folder names' is selected)
4270 \newline
4271
4272 \newline
4273 b)
4274  In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4275  'Show directories for:' select 'Executable files', and in the directories
4276  window add a new path: 'C:
4277 \backslash
4278 user
4279 \backslash
4280 local
4281 \backslash
4282 wbin', click ok.
4283 \newline
4284
4285 \newline
4286 (As a side effect, you get a bunch of Unix utilities that
4287  could be useful, such as diff and patch.)
4288 \end_layout
4289
4290 \begin_layout Enumerate
4291 A more compact way:
4292 \newline
4293
4294 \newline
4295 This one avoids extracting a bunch of files you may not
4296  use, but requires some extra work:
4297 \newline
4298
4299 \newline
4300 a) Create a directory were to put the
4301  tools needed, or use a directory already present.
4302  Say for example 'C:
4303 \backslash
4304 util'.
4305 \newline
4306
4307 \newline
4308 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4309  gawk.exe to such directory WITHOUT preserving the original paths.
4310  (If you are using WinZip make certain that 'Use folder names' is not selected)
4311 \newline
4312
4313 \newline
4314 c
4315 ) Rename bison.exe to '_bison.exe'.
4316 \newline
4317
4318 \newline
4319 d) Create a batch file 'bison.bat' in 'C:
4320 \backslash
4321 util
4322 \backslash
4323 ' and add these lines: 
4324 \newline
4325 \InsetSpace ~
4326 \InsetSpace ~
4327 set BISON_SIMPLE=C:
4328 \backslash
4329 util
4330 \backslash
4331 bison.simple 
4332 \newline
4333 \InsetSpace ~
4334 \InsetSpace ~
4335 set BISON_HAIRY=C:
4336 \backslash
4337 util
4338 \backslash
4339 bison.hairy
4340 \newline
4341 \InsetSpace ~
4342 \InsetSpace ~
4343 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4344 \newline
4345
4346 \newline
4347 Steps 'c' and 'd' are needed
4348  because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4349  reside in some weird Unix directory, '/usr/local/share/' I think.
4350  So it is necessary to tell bison where those files are located if they
4351  are not in such directory.
4352  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4353 \newline
4354
4355 \newline
4356 e
4357 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4358  in 'Show directories for:' select 'Executable files', and in the directories
4359  window add a new path: 'c:
4360 \backslash
4361 util', click ok.
4362  Note that you can use any other path instead of 'c:
4363 \backslash
4364 util', even the path where the Visual C++ tools are, probably: 'C:
4365 \backslash
4366 Program Files
4367 \backslash
4368 Microsoft Visual Studio
4369 \backslash
4370 Common
4371 \backslash
4372 Tools'.
4373  So you don't have to execute step 'e' :)
4374 \end_layout
4375
4376 \begin_layout Standard
4377 That is it.
4378  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4379  the executables from sdcc
4380 \backslash
4381 bin_vc to sdcc
4382 \backslash
4383 bin, and you can compile using SDCC.
4384 \end_layout
4385
4386 \begin_layout Subsection
4387 Building SDCC Using Borland
4388 \end_layout
4389
4390 \begin_layout Enumerate
4391 From the sdcc directory, run the command "make -f Makefile.bcc".
4392  This should regenerate all the .exe files in the bin directory except for
4393  SDCDB and ucSim.
4394 \end_layout
4395
4396 \begin_layout Enumerate
4397 If you modify any source files and need to rebuild, be aware that the dependenci
4398 es may not be correctly calculated.
4399  The safest option is to delete all .obj files and run the build again.
4400  From a Cygwin BASH prompt, this can easily be done with the command (be
4401  sure you are in the sdcc directory):
4402 \newline
4403
4404 \newline
4405
4406 \family sans
4407 \series bold
4408 find .
4409  
4410 \backslash
4411 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
4412 \backslash
4413 ) -print -exec rm {} 
4414 \backslash
4415 ;
4416 \family default
4417 \series default
4418
4419 \newline
4420
4421 \newline
4422 or on Windows NT/2000/XP from the command prompt with the command:
4423 \newline
4424
4425 \family sans
4426 \series bold
4427
4428 \newline
4429 del /s *.obj *.lib *.rul
4430 \family default
4431 \series default
4432  from the sdcc directory.
4433 \end_layout
4434
4435 \begin_layout Subsection
4436 Windows Install Using a ZIP Package
4437 \end_layout
4438
4439 \begin_layout Enumerate
4440 Download the binary zip package from 
4441 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4442
4443 \end_inset
4444
4445  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4446  This should unpack to a group of sub-directories.
4447  An example directory structure after unpacking the mingw32 package is:
4448  c:
4449 \backslash
4450 sdcc
4451 \backslash
4452 bin for the executables, c:
4453 \backslash
4454 sdcc
4455 \backslash
4456 include and c:
4457 \backslash
4458 sdcc
4459 \backslash
4460 lib for the include and libraries.
4461 \end_layout
4462
4463 \begin_layout Enumerate
4464 Adjust your environment variable PATH to include the location of the bin
4465  directory or start sdcc using the full path.
4466 \end_layout
4467
4468 \begin_layout Subsection
4469 Windows Install Using the Setup Program
4470 \begin_inset LatexCommand \label{sub:Windows-Install}
4471
4472 \end_inset
4473
4474
4475 \end_layout
4476
4477 \begin_layout Standard
4478 Download the setup program 
4479 \emph on
4480 sdcc-x.y.z-setup.exe
4481 \emph default
4482  for an official release from 
4483 \newline
4484
4485 \begin_inset LatexCommand \url{http://sf.net/project/showfiles.php?group_id=599}
4486
4487 \end_inset
4488
4489  or a setup program for one of the snapshots 
4490 \emph on
4491 sdcc-yyyymmdd-xxxx-setup.exe
4492 \emph default
4493  from 
4494 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4495
4496 \end_inset
4497
4498  and execute it.
4499  A windows typical installer will guide you through the installation process.
4500 \end_layout
4501
4502 \begin_layout Subsection
4503 VPATH
4504 \begin_inset LatexCommand \index{VPATH}
4505
4506 \end_inset
4507
4508  feature
4509 \end_layout
4510
4511 \begin_layout Standard
4512 SDCC supports the VPATH feature provided by configure and make.
4513  It allows to separate the source and build trees.
4514  Here's an example:
4515 \end_layout
4516
4517 \begin_layout Standard
4518
4519 \family typewriter
4520 cd ~\InsetSpace ~
4521 \InsetSpace ~
4522 \InsetSpace ~
4523 \InsetSpace ~
4524 \InsetSpace ~
4525 \InsetSpace ~
4526 \InsetSpace ~
4527 \InsetSpace ~
4528 \InsetSpace ~
4529 \InsetSpace ~
4530 \InsetSpace ~
4531 \InsetSpace ~
4532 \InsetSpace ~
4533 \InsetSpace ~
4534 \InsetSpace ~
4535 \InsetSpace ~
4536 \InsetSpace ~
4537 \InsetSpace ~
4538 \InsetSpace ~
4539 \InsetSpace ~
4540 \InsetSpace ~
4541 # cd $HOME
4542 \end_layout
4543
4544 \begin_layout Standard
4545
4546 \family typewriter
4547 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4548 # extract source to directory sdcc
4549 \end_layout
4550
4551 \begin_layout Standard
4552
4553 \family typewriter
4554 mkdir sdcc.build\InsetSpace ~
4555 \InsetSpace ~
4556 \InsetSpace ~
4557 \InsetSpace ~
4558 \InsetSpace ~
4559 \InsetSpace ~
4560 \InsetSpace ~
4561 \InsetSpace ~
4562 \InsetSpace ~
4563 # put output in sdcc.build
4564 \end_layout
4565
4566 \begin_layout Standard
4567
4568 \family typewriter
4569 cd sdcc.build
4570 \end_layout
4571
4572 \begin_layout Standard
4573
4574 \family typewriter
4575 ../sdcc/configure\InsetSpace ~
4576 \InsetSpace ~
4577 \InsetSpace ~
4578 \InsetSpace ~
4579 \InsetSpace ~
4580 \InsetSpace ~
4581 \InsetSpace ~
4582 \InsetSpace ~
4583 # configure is doing all the magic!
4584 \end_layout
4585
4586 \begin_layout Standard
4587
4588 \family typewriter
4589 make
4590 \end_layout
4591
4592 \begin_layout Standard
4593 \noindent
4594 That's it! 
4595 \series bold
4596 configure
4597 \series default
4598  will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
4599  It automagically computes the variables srcdir, top_srcdir and top_buildir
4600  for each directory.
4601  After running 
4602 \series bold
4603 make
4604 \series default
4605  the generated files will be in ~/sdcc.build, while the source files stay
4606  in ~/sdcc.
4607 \newline
4608 This is not only usefull for building different binaries, e.g.
4609  when cross compiling.
4610  It also gives you a much better overview in the source tree when all the
4611  generated files are not scattered between the source files.
4612  And the best thing is: if you want to change a file you can leave the original
4613  file untouched in the source directory.
4614  Simply copy it to the build directory, edit it, enter `make clean`, `rm
4615  Makefile.dep` and `make`.
4616  
4617 \series bold
4618 make
4619 \series default
4620  will do the rest for you!
4621 \end_layout
4622
4623 \begin_layout Section
4624 Building the Documentation
4625 \end_layout
4626
4627 \begin_layout Standard
4628 Add -
4629 \begin_inset ERT
4630 status collapsed
4631
4632 \begin_layout Standard
4633
4634
4635 \backslash
4636 /
4637 \end_layout
4638
4639 \end_inset
4640
4641 -enable-doc to the configure arguments to build the documentation together
4642  with all the other stuff.
4643  You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
4644  dvips and makeindex) to get the job done.
4645  Another possibility is to change to the doc directory and to type 
4646 \family sans
4647 \series bold
4648
4649 \begin_inset Quotes srd
4650 \end_inset
4651
4652 make
4653 \begin_inset Quotes srd
4654 \end_inset
4655
4656
4657 \family default
4658 \series default
4659  there.
4660  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
4661 x).
4662  Using LyX 
4663 \begin_inset LatexCommand \url{http://www.lyx.org}
4664
4665 \end_inset
4666
4667  as editor is straightforward.
4668  Prebuilt documentation in html and pdf format is available from 
4669 \begin_inset LatexCommand \url{http://sdcc.sf.net/snap.php}
4670
4671 \end_inset
4672
4673 .
4674 \end_layout
4675
4676 \begin_layout Section
4677 Reading the Documentation
4678 \begin_inset LatexCommand \index{Documentation}
4679
4680 \end_inset
4681
4682
4683 \end_layout
4684
4685 \begin_layout Standard
4686 Currently reading the document in pdf format is recommended, as for unknown
4687  reason the hyperlinks are working there whereas in the html version they
4688  are not
4689 \begin_inset Foot
4690 status open
4691
4692 \begin_layout Standard
4693 If you should know why please drop us a note
4694 \end_layout
4695
4696 \end_inset
4697
4698 .
4699  
4700 \newline
4701 You'll find the pdf version
4702 \begin_inset LatexCommand \index{PDF version of this document}
4703
4704 \end_inset
4705
4706  at 
4707 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.pdf}
4708
4709 \end_inset
4710
4711 .
4712  
4713 \newline
4714 A html version
4715 \begin_inset LatexCommand \index{HTML version of this document}
4716
4717 \end_inset
4718
4719  should be online at 
4720 \begin_inset LatexCommand \url{http://sdcc.sf.net/doc/sdccman.html/index.html}
4721
4722 \end_inset
4723
4724 .
4725 \newline
4726 This documentation is in some aspects different from a commercial documentation:
4727  
4728 \end_layout
4729
4730 \begin_layout Itemize
4731 It tries to document SDCC for several processor architectures in one document
4732  (commercially these probably would be separate documents/products).
4733  This document
4734 \begin_inset LatexCommand \index{Status of documentation}
4735
4736 \end_inset
4737
4738  currently matches SDCC for mcs51 and DS390 best and does give too few informati
4739 on about f.e.
4740  Z80, PIC14, PIC16 and HC08.
4741 \end_layout
4742
4743 \begin_layout Itemize
4744 There are many references pointing away from this documentation.
4745  Don't let this distract you.
4746  If there f.e.
4747  was a reference like 
4748 \begin_inset LatexCommand \url{http://www.opencores.org}
4749
4750 \end_inset
4751
4752  together with a statement 
4753 \begin_inset Quotes sld
4754 \end_inset
4755
4756 some processors which are targetted by SDCC can be implemented in a 
4757 \emph on
4758 f
4759 \emph default
4760 ield 
4761 \emph on
4762 p
4763 \emph default
4764 rogrammable 
4765 \emph on
4766 g
4767 \emph default
4768 ate 
4769 \emph on
4770 a
4771 \emph default
4772 rray
4773 \begin_inset LatexCommand \index{FPGA (field programmable gate array)}
4774
4775 \end_inset
4776
4777
4778 \begin_inset Quotes srd
4779 \end_inset
4780
4781  or 
4782 \begin_inset LatexCommand \url{http://sf.net/projects/fpgac}
4783
4784 \end_inset
4785
4786
4787 \begin_inset LatexCommand \index{FpgaC ((subset of) C to FPGA compiler)}
4788
4789 \end_inset
4790
4791  
4792 \begin_inset Quotes sld
4793 \end_inset
4794
4795 have you ever heard of an open source compiler that compiles a subset of
4796  C for an FPGA?
4797 \begin_inset Quotes srd
4798 \end_inset
4799
4800  we expect you to have a quick look there and come back.
4801  If you read this you are on the right track.
4802 \end_layout
4803
4804 \begin_layout Itemize
4805 Some sections attribute more space to problems, restrictions and warnings
4806  than to the solution.
4807 \end_layout
4808
4809 \begin_layout Itemize
4810 The installation section and the section about the debugger is intimidating.
4811 \end_layout
4812
4813 \begin_layout Itemize
4814 There are still lots of typos and there are more different writing styles
4815  than pictures.
4816 \end_layout
4817
4818 \begin_layout Section
4819 Testing the SDCC Compiler
4820 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
4821
4822 \end_inset
4823
4824
4825 \end_layout
4826
4827 \begin_layout Standard
4828 The first thing you should do after installing your SDCC compiler is to
4829  see if it runs.
4830  Type 
4831 \family sans
4832 \series bold
4833 "sdcc -
4834 \begin_inset ERT
4835 status collapsed
4836
4837 \begin_layout Standard
4838
4839
4840 \backslash
4841 /
4842 \end_layout
4843
4844 \end_inset
4845
4846 -version"
4847 \begin_inset LatexCommand \index{version}
4848
4849 \end_inset
4850
4851
4852 \family default
4853 \series default
4854  at the prompt, and the program should run and output its version like:
4855  
4856 \newline
4857
4858 \family typewriter
4859 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
4860  (UNIX)
4861 \end_layout
4862
4863 \begin_layout Standard
4864 If it doesn't run, or gives a message about not finding sdcc program, then
4865  you need to check over your installation.
4866  Make sure that the sdcc bin directory is in your executable search path
4867  defined by the PATH environment setting (
4868 \series medium
4869 see 
4870 \series default
4871 section 
4872 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4873
4874 \end_inset
4875
4876 \InsetSpace ~
4877
4878 \series medium
4879 Install trouble-shooting for suggestions
4880 \series default
4881 ).
4882  Make sure that the sdcc program is in the bin folder, if not perhaps something
4883  did not install correctly.
4884 \newline
4885
4886 \newline
4887
4888 \series medium
4889 SDCC 
4890 \series default
4891 is commonly installed as described in section 
4892 \begin_inset Quotes sld
4893 \end_inset
4894
4895 Install and search paths
4896 \begin_inset Quotes srd
4897 \end_inset
4898
4899 .
4900 \newline
4901
4902 \newline
4903
4904 \series medium
4905 Make sure the compiler works on a very simple example.
4906  Type in the following test.c program using your favorite 
4907 \series default
4908 ASCII 
4909 \series medium
4910 editor:
4911 \end_layout
4912
4913 \begin_layout Verse
4914
4915 \family typewriter
4916 char test;
4917 \newline
4918
4919 \newline
4920 void main(void) {
4921 \newline
4922 \InsetSpace ~
4923 \InsetSpace ~
4924 \InsetSpace ~
4925 \InsetSpace ~
4926 test=0;
4927 \newline
4928 }
4929 \end_layout
4930
4931 \begin_layout Standard
4932
4933 \series medium
4934 Compile this using the following command: 
4935 \family sans
4936 \series bold
4937 "sdcc -c test.c".
4938
4939 \family default
4940 \series default
4941  
4942 \series medium
4943 If all goes well, the compiler will generate a test.asm and test.rel file.
4944  Congratulations, you've just compiled your first program with SDCC.
4945  We used the -c option to tell SDCC not to link the generated code, just
4946  to keep things simple for this step.
4947 \series default
4948
4949 \newline
4950
4951 \newline
4952
4953 \series medium
4954 The next step is to try it with the linker.
4955  Type in 
4956 \family sans
4957 \series bold
4958 "sdcc test.c
4959 \family default
4960 \series default
4961 "
4962 \series medium
4963 .
4964  If all goes well the compiler will link with the libraries and produce
4965  a test.ihx output file.
4966  If this step fails
4967 \series default
4968  
4969 \series medium
4970 (no test.ihx, and the linker generates warnings), then the problem is most
4971  likely that 
4972 \series default
4973 SDCC
4974 \series medium
4975  cannot find the 
4976 \series default
4977 /
4978 \series medium
4979 usr/local/share/sdcc/lib directory
4980 \series default
4981  
4982 \series medium
4983 (see 
4984 \series default
4985 section 
4986 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
4987
4988 \end_inset
4989
4990 \InsetSpace ~
4991
4992 \series medium
4993 Install trouble-shooting for suggestions).
4994 \series default
4995
4996 \newline
4997
4998 \newline
4999
5000 \series medium
5001 The final test is to ensure 
5002 \series default
5003 SDCC
5004 \series medium
5005  can use the 
5006 \series default
5007 standard
5008 \series medium
5009  header files and libraries.
5010  Edit test.c and change it to the following:
5011 \end_layout
5012
5013 \begin_layout Verse
5014
5015 \family typewriter
5016 #include <string.h>
5017 \newline
5018
5019 \newline
5020 char str1[10];
5021 \newline
5022
5023 \newline
5024 void main(void) {
5025 \newline
5026 \InsetSpace ~
5027 \InsetSpace ~
5028 strcpy(str1, "testing");
5029 \newline
5030 }
5031 \end_layout
5032
5033 \begin_layout Standard
5034
5035 \series medium
5036 Compile this by typing 
5037 \family sans
5038 \series bold
5039 "sdcc test.c"
5040 \family default
5041 \series medium
5042 .
5043  This should generate a test.ihx output file, and it should give no warnings
5044  such as not finding the string.h file.
5045  If it cannot find the string.h file, then the problem is that 
5046 \series default
5047 SDCC
5048 \series medium
5049  cannot find the /usr/local/share/sdcc/include directory
5050 \series default
5051  
5052 \series medium
5053 (see the 
5054 \series default
5055 section 
5056 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
5057
5058 \end_inset
5059
5060 \InsetSpace ~
5061
5062 \series medium
5063 Install trouble-shooting section for suggestions).
5064
5065 \series default
5066  Use option 
5067 \series bold
5068 -
5069 \begin_inset ERT
5070 status collapsed
5071
5072 \begin_layout Standard
5073
5074
5075 \backslash
5076 /
5077 \end_layout
5078
5079 \end_inset
5080
5081 -print-search-dirs
5082 \series default
5083
5084 \begin_inset LatexCommand \index{-\/-print-search-dirs}
5085
5086 \end_inset
5087
5088  to find exactly where SDCC is looking for the include and lib files.
5089 \end_layout
5090
5091 \begin_layout Section
5092 Install Trouble-shooting
5093 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
5094
5095 \end_inset
5096
5097
5098 \begin_inset LatexCommand \index{Install trouble-shooting}
5099
5100 \end_inset
5101
5102
5103 \end_layout
5104
5105 \begin_layout Subsection
5106 If SDCC does not build correctly
5107 \end_layout
5108
5109 \begin_layout Standard
5110 A thing to try is starting from scratch by unpacking the .tgz source package
5111  again in an empty directory.
5112  Configure it like:
5113 \newline
5114
5115 \newline
5116
5117 \family sans
5118 \series bold
5119 ./configure 2>&1 | tee configure.log
5120 \family default
5121 \series default
5122
5123 \newline
5124
5125 \newline
5126 and build it like:
5127 \newline
5128
5129 \newline
5130
5131 \family sans
5132 \series bold
5133 make 2>&1 | tee make.log
5134 \family default
5135 \series default
5136
5137 \newline
5138
5139 \newline
5140 If anything goes wrong, you can review the log files to locate the problem.
5141  Or a relevant part of this can be attached to an email that could be helpful
5142  when requesting help from the mailing list.
5143 \end_layout
5144
5145 \begin_layout Subsection
5146 What the 
5147 \begin_inset Quotes sld
5148 \end_inset
5149
5150 ./configure
5151 \begin_inset Quotes srd
5152 \end_inset
5153
5154  does
5155 \end_layout
5156
5157 \begin_layout Standard
5158 The 
5159 \begin_inset Quotes sld
5160 \end_inset
5161
5162 ./configure
5163 \begin_inset Quotes srd
5164 \end_inset
5165
5166  command is a script that analyzes your system and performs some configuration
5167  to ensure the source package compiles on your system.
5168  It will take a few minutes to run, and will compile a few tests to determine
5169  what compiler features are installed.
5170 \end_layout
5171
5172 \begin_layout Subsection
5173 What the 
5174 \begin_inset Quotes sld
5175 \end_inset
5176
5177 make
5178 \begin_inset Quotes srd
5179 \end_inset
5180
5181  does
5182 \end_layout
5183
5184 \begin_layout Standard
5185 This runs the GNU make tool, which automatically compiles all the source
5186  packages into the final installed binary executables.
5187 \end_layout
5188
5189 \begin_layout Subsection
5190 What the 
5191 \begin_inset Quotes sld
5192 \end_inset
5193
5194 make install
5195 \begin_inset Quotes erd
5196 \end_inset
5197
5198  command does.
5199 \end_layout
5200
5201 \begin_layout Standard
5202 This will install the compiler, other executables libraries and include
5203  files into the appropriate directories.
5204  See sections 
5205 \begin_inset LatexCommand \ref{sub:Install-paths}
5206
5207 \end_inset
5208
5209 ,\InsetSpace ~
5210
5211 \begin_inset LatexCommand \ref{sub:Search-Paths}
5212
5213 \end_inset
5214
5215 \InsetSpace ~
5216 about install and search paths.
5217 \newline
5218 On most systems you will need super-user privilege
5219 s to do this.
5220 \end_layout
5221
5222 \begin_layout Section
5223 Components of SDCC
5224 \end_layout
5225
5226 \begin_layout Standard
5227 SDCC is not just a compiler, but a collection of tools by various developers.
5228  These include linkers, assemblers, simulators and other components.
5229  Here is a summary of some of the components.
5230  Note that the included simulator and assembler have separate documentation
5231  which you can find in the source package in their respective directories.
5232  As SDCC grows to include support for other processors, other packages from
5233  various developers are included and may have their own sets of documentation.
5234 \newline
5235
5236 \newline
5237 You
5238  might want to look at the files which are installed in <installdir>.
5239  At the time of this writing, we find the following programs for gcc-builds:
5240 \newline
5241
5242  
5243 \newline
5244 In <installdir>/bin:
5245 \end_layout
5246
5247 \begin_layout Itemize
5248 sdcc - The compiler.
5249 \end_layout
5250
5251 \begin_layout Itemize
5252 sdcpp - The C preprocessor.
5253 \end_layout
5254
5255 \begin_layout Itemize
5256 asx8051 - The assembler for 8051 type processors.
5257 \end_layout
5258
5259 \begin_layout Itemize
5260 as-z80
5261 \series bold
5262
5263 \series default
5264 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5265 \end_layout
5266
5267 \begin_layout Itemize
5268 aslink -The linker for 8051 type processors.
5269 \end_layout
5270
5271 \begin_layout Itemize
5272 link-z80
5273 \series bold
5274
5275 \series default
5276 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5277 \end_layout
5278
5279 \begin_layout Itemize
5280 s51 - The ucSim 8051 simulator.
5281 \end_layout
5282
5283 \begin_layout Itemize
5284 sdcdb - The source debugger.
5285 \end_layout
5286
5287 \begin_layout Itemize
5288 packihx - A tool to pack (compress) Intel hex files.
5289 \end_layout
5290
5291 \begin_layout Standard
5292 In <installdir>/share/sdcc/include
5293 \end_layout
5294
5295 \begin_layout Itemize
5296 the include files
5297 \end_layout
5298
5299 \begin_layout Standard
5300 In <installdir>/share/sdcc/lib
5301 \end_layout
5302
5303 \begin_layout Itemize
5304 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5305  relocatables.
5306 \end_layout
5307
5308 \begin_layout Standard
5309 In <installdir>/share/sdcc/doc
5310 \end_layout
5311
5312 \begin_layout Itemize
5313 the documentation
5314 \end_layout
5315
5316 \begin_layout Standard
5317 As development for other processors proceeds, this list will expand to include
5318  executables to support processors like AVR, PIC, etc.
5319 \end_layout
5320
5321 \begin_layout Subsection
5322 sdcc - The Compiler
5323 \end_layout
5324
5325 \begin_layout Standard
5326 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5327  the assembler and linkage editor.
5328 \end_layout
5329
5330 \begin_layout Subsection
5331 sdcpp - The C-Preprocessor
5332 \end_layout
5333
5334 \begin_layout Standard
5335 The preprocessor
5336 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5337
5338 \end_inset
5339
5340  is a modified version of the GNU cpp
5341 \begin_inset LatexCommand \index{cpp|see{sdcpp}}
5342
5343 \end_inset
5344
5345  preprocessor 
5346 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
5347
5348 \end_inset
5349
5350 .
5351  The C preprocessor is used to pull in #include sources, process #ifdef
5352  statements, #defines and so on.
5353 \end_layout
5354
5355 \begin_layout Subsection
5356 as
5357 \emph on
5358 xxxx
5359 \emph default
5360 , aslink, link-
5361 \emph on
5362 xxx
5363 \emph default
5364  - The Assemblers and Linkage Editors
5365 \end_layout
5366
5367 \begin_layout Standard
5368 This is retargettable assembler & linkage editor, it was developed by Alan
5369  Baldwin.
5370  John Hartman created the version for 8051, and I (Sandeep) have made some
5371  enhancements and bug fixes for it to work properly with SDCC.
5372 \end_layout
5373
5374 \begin_layout Subsection
5375 s51 - The Simulator
5376 \end_layout
5377
5378 \begin_layout Standard
5379 S51
5380 \begin_inset LatexCommand \index{s51}
5381
5382 \end_inset
5383
5384  is a free open source simulator developed by Daniel Drotos.
5385  The simulator is built as part of the build process.
5386  For more information visit Daniel's web site at: 
5387 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
5388
5389 \end_inset
5390
5391 .
5392  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5393  XA51 family.
5394 \end_layout
5395
5396 \begin_layout Subsection
5397 sdcdb - Source Level Debugger
5398 \end_layout
5399
5400 \begin_layout Standard
5401 SDCDB
5402 \begin_inset LatexCommand \index{SDCDB (debugger)}
5403
5404 \end_inset
5405
5406  is the companion source level debugger.
5407  More about SDCDB in section 
5408 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
5409
5410 \end_inset
5411
5412 .
5413  The current version of the debugger uses Daniel's Simulator S51
5414 \begin_inset LatexCommand \index{s51}
5415
5416 \end_inset
5417
5418 , but can be easily changed to use other simulators.
5419 \end_layout
5420
5421 \begin_layout Chapter
5422 Using SDCC
5423 \end_layout
5424
5425 \begin_layout Section
5426 Compiling
5427 \end_layout
5428
5429 \begin_layout Subsection
5430 Single Source File Projects
5431 \end_layout
5432
5433 \begin_layout Standard
5434 For single source file 8051 projects the process is very simple.
5435  Compile your programs with the following command 
5436 \family sans
5437 \series bold
5438 "sdcc sourcefile.c".
5439
5440 \family default
5441 \series default
5442  This will compile, assemble and link your source file.
5443  Output files are as follows:
5444 \end_layout
5445
5446 \begin_layout Itemize
5447 sourcefile.asm
5448 \begin_inset LatexCommand \index{<file>.asm}
5449
5450 \end_inset
5451
5452  - Assembler source
5453 \begin_inset LatexCommand \index{Assembler source}
5454
5455 \end_inset
5456
5457  file created by the compiler
5458 \end_layout
5459
5460 \begin_layout Itemize
5461 sourcefile.lst
5462 \begin_inset LatexCommand \index{<file>.lst}
5463
5464 \end_inset
5465
5466  - Assembler listing
5467 \begin_inset LatexCommand \index{Assembler listing}
5468
5469 \end_inset
5470
5471  file created by the Assembler
5472 \end_layout
5473
5474 \begin_layout Itemize
5475 sourcefile.rst
5476 \begin_inset LatexCommand \index{<file>.rst}
5477
5478 \end_inset
5479
5480  - Assembler listing
5481 \begin_inset LatexCommand \index{Assembler listing}
5482
5483 \end_inset
5484
5485  file updated with linkedit information, created by linkage editor
5486 \end_layout
5487
5488 \begin_layout Itemize
5489 sourcefile.sym
5490 \begin_inset LatexCommand \index{<file>.sym}
5491
5492 \end_inset
5493
5494  - symbol listing
5495 \begin_inset LatexCommand \index{Symbol listing}
5496
5497 \end_inset
5498
5499  for the sourcefile, created by the assembler
5500 \end_layout
5501
5502 \begin_layout Itemize
5503 sourcefile.rel
5504 \begin_inset LatexCommand \index{<file>.rel}
5505
5506 \end_inset
5507
5508  or sourcefile.o
5509 \begin_inset LatexCommand \index{<file>.o}
5510
5511 \end_inset
5512
5513  - Object file
5514 \begin_inset LatexCommand \index{Object file}
5515
5516 \end_inset
5517
5518  created by the assembler, input to Linkage editor
5519 \end_layout
5520
5521 \begin_layout Itemize
5522 sourcefile.map
5523 \begin_inset LatexCommand \index{<file>.map}
5524
5525 \end_inset
5526
5527  - The memory map
5528 \begin_inset LatexCommand \index{Memory map}
5529
5530 \end_inset
5531
5532  for the load module, created by the Linker
5533 \end_layout
5534
5535 \begin_layout Itemize
5536 sourcefile.mem
5537 \begin_inset LatexCommand \index{<file>.mem}
5538
5539 \end_inset
5540
5541  - A file with a summary of the memory usage
5542 \end_layout
5543
5544 \begin_layout Itemize
5545 sourcefile.ihx
5546 \begin_inset LatexCommand \index{<file>.ihx}
5547
5548 \end_inset
5549
5550  - The load module in Intel hex format
5551 \begin_inset LatexCommand \index{Intel hex format}
5552
5553 \end_inset
5554
5555  (you can select the Motorola S19 format
5556 \begin_inset LatexCommand \index{Motorola S19 format}
5557
5558 \end_inset
5559
5560  with -
5561 \begin_inset ERT
5562 status collapsed
5563
5564 \begin_layout Standard
5565
5566
5567 \backslash
5568 /
5569 \end_layout
5570
5571 \end_inset
5572
5573 -out-fmt-s19
5574 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5575
5576 \end_inset
5577
5578 .
5579  If you need another format you might want to use 
5580 \family sans
5581 \shape italic
5582 objdump
5583 \family default
5584 \shape default
5585
5586 \begin_inset LatexCommand \index{objdump (tool)}
5587
5588 \end_inset
5589
5590  or
5591 \family sans
5592 \shape italic
5593  srecord
5594 \family default
5595 \shape default
5596
5597 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5598
5599 \end_inset
5600
5601
5602 \begin_inset Note Note
5603 status collapsed
5604
5605 \begin_layout Standard
5606 hyperlinks needed
5607 \end_layout
5608
5609 \end_inset
5610
5611  - see also section 
5612 \begin_inset LatexCommand \vref{sub:Postprocessing-the-Intel}
5613
5614 \end_inset
5615
5616 ).
5617  Both formats are documented in the documentation of srecord
5618 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5619
5620 \end_inset
5621
5622
5623 \end_layout
5624
5625 \begin_layout Itemize
5626 sourcefile.adb
5627 \begin_inset LatexCommand \index{<file>.adb}
5628
5629 \end_inset
5630
5631  - An intermediate file containing debug information needed to create the
5632  .cdb file (with -
5633 \begin_inset ERT
5634 status collapsed
5635
5636 \begin_layout Standard
5637
5638
5639 \backslash
5640 /
5641 \end_layout
5642
5643 \end_inset
5644
5645 -debug
5646 \begin_inset LatexCommand \index{-\/-debug}
5647
5648 \end_inset
5649
5650
5651 \end_layout
5652
5653 \begin_layout Itemize
5654 sourcefile.cdb
5655 \begin_inset LatexCommand \index{<file>.cdb}
5656
5657 \end_inset
5658
5659  - An optional file (with -
5660 \begin_inset ERT
5661 status collapsed
5662
5663 \begin_layout Standard
5664
5665
5666 \backslash
5667 /
5668 \end_layout
5669
5670 \end_inset
5671
5672 -debug) containing debug information.
5673  The format is documented in cdbfileformat.pdf
5674 \end_layout
5675
5676 \begin_layout Itemize
5677 sourcefile.
5678  - (no extension)
5679 \begin_inset LatexCommand \index{<file> (no extension)}
5680
5681 \end_inset
5682
5683  An optional AOMF or AOMF51
5684 \begin_inset LatexCommand \index{AOMF, AOMF51}
5685
5686 \end_inset
5687
5688  
5689 \begin_inset LatexCommand \label{OMF file}
5690
5691 \end_inset
5692
5693 file containing debug information (generated with option -
5694 \begin_inset ERT
5695 status collapsed
5696
5697 \begin_layout Standard
5698
5699
5700 \backslash
5701 /
5702 \end_layout
5703
5704 \end_inset
5705
5706 -debug).
5707  The (Intel)
5708 \emph on
5709  a
5710 \emph default
5711 bsolute 
5712 \emph on
5713 o
5714 \emph default
5715 bject 
5716 \emph on
5717 m
5718 \emph default
5719 odule 
5720 \emph on
5721 f
5722 \emph default
5723 ormat is a subformat of the OMF51 format and is commonly used by third party
5724  tools (debuggers
5725 \begin_inset LatexCommand \index{Debugger}
5726
5727 \end_inset
5728
5729 , simulators, emulators).
5730 \end_layout
5731
5732 \begin_layout Itemize
5733 sourcefile.dump*
5734 \begin_inset LatexCommand \index{<file>.dump*}
5735
5736 \end_inset
5737
5738  - Dump file to debug the compiler it self (generated with option -
5739 \begin_inset ERT
5740 status collapsed
5741
5742 \begin_layout Standard
5743
5744
5745 \backslash
5746 /
5747 \end_layout
5748
5749 \end_inset
5750
5751 -dumpall) (see section 
5752 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
5753
5754 \end_inset
5755
5756 \InsetSpace ~
5757  and section 
5758 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
5759
5760 \end_inset
5761
5762 \InsetSpace ~
5763
5764 \begin_inset Quotes sld
5765 \end_inset
5766
5767 Anatomy of the compiler
5768 \begin_inset Quotes srd
5769 \end_inset
5770
5771 ).
5772 \end_layout
5773
5774 \begin_layout Subsection
5775 Postprocessing the Intel Hex
5776 \begin_inset LatexCommand \index{Intel hex format}
5777
5778 \end_inset
5779
5780  file
5781 \begin_inset LatexCommand \label{sub:Postprocessing-the-Intel}
5782
5783 \end_inset
5784
5785
5786 \end_layout
5787
5788 \begin_layout Standard
5789 In most cases this won't be needed but the Intel Hex file
5790 \begin_inset LatexCommand \index{<file>.ihx}
5791
5792 \end_inset
5793
5794  which is generated by SDCC might include lines of varying length and the
5795  addresses within the file are not guaranteed to be strictly ascending.
5796  If your toolchain or a bootloader does not like this you can use the tool
5797  
5798 \family typewriter
5799 packihx
5800 \family default
5801
5802 \begin_inset LatexCommand \index{packihx (tool)}
5803
5804 \end_inset
5805
5806  which is part of the SDCC distribution: 
5807 \newline
5808
5809 \newline
5810
5811 \family sans
5812 \series bold
5813  packihx sourcefile.ihx >sourcefile.hex
5814 \family default
5815 \series default
5816
5817 \newline
5818
5819 \newline
5820 The separately available
5821 \emph on
5822  srecord
5823 \emph default
5824
5825 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
5826
5827 \end_inset
5828
5829  package additionally allows to set undefined locations to a predefined
5830  value, to insert checksums
5831 \begin_inset LatexCommand \index{checksum}
5832
5833 \end_inset
5834
5835  of various flavours (crc, add, xor) and to perform other manipulations
5836  (convert, split, crop, offset, ...).
5837  
5838 \newline
5839
5840 \newline
5841
5842 \family sans
5843 \series bold
5844 srec_cat\InsetSpace ~
5845 \InsetSpace ~
5846 sourcefile.ihx -intel\InsetSpace ~
5847 \InsetSpace ~
5848 -o sourcefile.hex -intel
5849 \newline
5850
5851 \newline
5852
5853 \family default
5854 \series default
5855 An example for a more complex command line
5856 \begin_inset Foot
5857 status open
5858
5859 \begin_layout Standard
5860 the command backfills
5861 \begin_inset LatexCommand \index{backfill unused memory}
5862
5863 \end_inset
5864
5865  unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
5866  block is zero.
5867  If the program counter on an mcs51 runs wild the backfill pattern 0x12
5868  will be interpreted as an 
5869 \family typewriter
5870 lcall
5871 \family default
5872  to address 
5873 \family typewriter
5874 0x1212
5875 \family default
5876  (where an emergency routine could sit).
5877 \end_layout
5878
5879 \end_inset
5880
5881  could look like:
5882 \newline
5883
5884 \newline
5885
5886 \family sans
5887 \series bold
5888 \size footnotesize
5889 srec_cat\InsetSpace ~
5890 sourcefile.ihx -intel\InsetSpace ~
5891 \InsetSpace ~
5892 -fill 0x12 0x0000 0xfffe\InsetSpace ~
5893 -little-endian-checksum-nega
5894 tive 0xfffe 0x02 0x02\InsetSpace ~
5895 \InsetSpace ~
5896 -o sourcefile.hex -intel
5897 \size default
5898
5899 \newline
5900
5901 \newline
5902
5903 \family default
5904 \series default
5905 The srecord package is available at 
5906 \begin_inset LatexCommand \url{http://sf.net/projects/srecord}
5907
5908 \end_inset
5909
5910  .
5911 \end_layout
5912
5913 \begin_layout Subsection
5914 Projects with Multiple Source Files
5915 \end_layout
5916
5917 \begin_layout Standard
5918 SDCC can compile only ONE file at a time.
5919  Let us for example assume that you have a project containing the following
5920  files:
5921 \newline
5922
5923 \newline
5924 foo1.c (contains some functions)
5925 \newline
5926 foo2.c (contains some more functions)
5927 \newline
5928 foomai
5929 n.c (contains more functions and the function main)
5930 \newline
5931
5932 \size footnotesize
5933
5934 \newline
5935
5936 \size default
5937 The first two files will need to be compiled separately with the commands:
5938 \size footnotesize
5939  
5940 \size default
5941
5942 \newline
5943
5944 \newline
5945
5946 \family sans
5947 \series bold
5948 sdcc\InsetSpace ~
5949 -c\InsetSpace ~
5950 foo1.c
5951 \family default
5952 \series default
5953 \size footnotesize
5954
5955 \newline
5956
5957 \family sans
5958 \series bold
5959 \size default
5960 sdcc\InsetSpace ~
5961 -c\InsetSpace ~
5962 foo2.c
5963 \family default
5964 \series default
5965
5966 \newline
5967
5968 \newline
5969 Then compile the source file containing the 
5970 \emph on
5971 main()
5972 \emph default
5973  function and link
5974 \begin_inset LatexCommand \index{Linker}
5975
5976 \end_inset
5977
5978  the files together with the following command: 
5979 \newline
5980
5981 \newline
5982
5983 \family sans
5984 \series bold
5985 sdcc\InsetSpace ~
5986 foomain.c\InsetSpace ~
5987 foo1.rel\InsetSpace ~
5988 foo2.rel
5989 \family default
5990 \series default
5991
5992 \begin_inset LatexCommand \index{<file>.rel}
5993
5994 \end_inset
5995
5996
5997 \newline
5998
5999 \newline
6000 Alternatively, 
6001 \emph on
6002 foomain.c 
6003 \emph default
6004 can be separately compiled as well: 
6005 \family sans
6006 \series bold
6007
6008 \newline
6009
6010 \newline
6011 sdcc\InsetSpace ~
6012 -c\InsetSpace ~
6013 foomain.c
6014 \newline
6015 sdcc foomain.rel foo1.rel foo2.rel
6016 \newline
6017
6018 \newline
6019
6020 \family default
6021 \series default
6022 The file containing the 
6023 \emph on
6024 main()
6025 \emph default
6026  function
6027 \emph on
6028  
6029 \emph default
6030 \noun on
6031 must
6032 \noun default
6033  be the 
6034 \noun on
6035 first
6036 \noun default
6037  file specified in the command line, since the linkage editor processes
6038  file in the order they are presented to it.
6039  The linker is invoked from SDCC using a script file with extension .lnk
6040 \begin_inset LatexCommand \index{<file>.lnk}
6041
6042 \end_inset
6043
6044 .
6045  You can view this file to troubleshoot linking problems such as those arising
6046  from missing libraries.
6047 \end_layout
6048
6049 \begin_layout Subsection
6050 Projects with Additional Libraries
6051 \begin_inset LatexCommand \index{Libraries}
6052
6053 \end_inset
6054
6055
6056 \end_layout
6057
6058 \begin_layout Standard
6059 Some reusable routines may be compiled into a library, see the documentation
6060  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6061  for how to create a 
6062 \emph on
6063 .lib
6064 \begin_inset LatexCommand \index{<file>.lib}
6065
6066 \end_inset
6067
6068
6069 \emph default
6070  library file.
6071  Libraries created in this manner can be included in the command line.
6072  Make sure you include the -L <library-path> option to tell the linker where
6073  to look for these files if they are not in the current directory.
6074  Here is an example, assuming you have the source file 
6075 \emph on
6076 foomain.c
6077 \emph default
6078  and a library
6079 \emph on
6080  foolib.lib
6081 \emph default
6082  in the directory 
6083 \emph on
6084 mylib
6085 \emph default
6086  (if that is not the same as your current project):
6087 \newline
6088
6089 \newline
6090
6091 \family sans
6092 \series bold
6093 sdcc foomain.c foolib.lib -L mylib
6094 \newline
6095
6096 \newline
6097
6098 \family default
6099 \series default
6100 Note here that
6101 \emph on
6102  mylib
6103 \emph default
6104  must be an absolute path name.
6105 \newline
6106
6107 \newline
6108 The most efficient way to use libraries is
6109  to keep separate modules in separate source files.
6110  The lib file now should name all the modules.rel
6111 \begin_inset LatexCommand \index{<file>.rel}
6112
6113 \end_inset
6114
6115  files.
6116  For an example see the standard library file 
6117 \emph on
6118 libsdcc.lib
6119 \emph default
6120  in the directory <installdir>/share/lib/small.
6121 \end_layout
6122
6123 \begin_layout Subsection
6124 Using sdcclib to Create and Manage Libraries
6125 \begin_inset LatexCommand \index{sdcclib}
6126
6127 \end_inset
6128
6129
6130 \end_layout
6131
6132 \begin_layout Standard
6133 Alternatively, instead of having a .rel file for each entry on the library
6134  file as described in the preceding section, sdcclib can be used to embed
6135  all the modules belonging to such library in the library file itself.
6136  This results in a larger library file, but it greatly reduces the number
6137  of disk files accessed by the linker.
6138   Additionally, the packed library file contains an index of all include
6139  modules and symbols that significantly speeds up the linking process.
6140  To display a list of options supported by sdcclib type:
6141 \newline
6142
6143 \end_layout
6144
6145 \begin_layout Standard
6146
6147 \family sans
6148 \series bold
6149 sdcclib -?
6150 \begin_inset LatexCommand \index{sdcclib}
6151
6152 \end_inset
6153
6154
6155 \newline
6156
6157 \newline
6158
6159 \family default
6160 \series default
6161 To create a new library file, start by compiling all the required modules.
6162  For example:
6163 \newline
6164
6165 \end_layout
6166
6167 \begin_layout Standard
6168
6169 \family sans
6170 \series bold
6171 sdcc -c _divsint.c
6172 \end_layout
6173
6174 \begin_layout Standard
6175
6176 \family sans
6177 \series bold
6178 sdcc -c _divuint.c
6179 \end_layout
6180
6181 \begin_layout Standard
6182
6183 \family sans
6184 \series bold
6185 sdcc -c _modsint.c
6186 \end_layout
6187
6188 \begin_layout Standard
6189
6190 \family sans
6191 \series bold
6192 sdcc -c _moduint.c
6193 \end_layout
6194
6195 \begin_layout Standard
6196
6197 \family sans
6198 \series bold
6199 sdcc -c _mulint.c
6200 \newline
6201
6202 \end_layout
6203
6204 \begin_layout Standard
6205 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6206  and _mulint.rel.
6207  The next step is to add the .rel files to the library file:
6208 \newline
6209
6210 \end_layout
6211
6212 \begin_layout Standard
6213
6214 \family sans
6215 \series bold
6216 sdcclib libint.lib _divsint.rel
6217 \family default
6218
6219 \begin_inset LatexCommand \index{sdcclib}
6220
6221 \end_inset
6222
6223
6224 \end_layout
6225
6226 \begin_layout Standard
6227
6228 \family sans
6229 \series bold
6230 sdcclib libint.lib _divuint.rel
6231 \end_layout
6232
6233 \begin_layout Standard
6234
6235 \family sans
6236 \series bold
6237 sdcclib libint.lib _modsint.rel
6238 \end_layout
6239
6240 \begin_layout Standard
6241
6242 \family sans
6243 \series bold
6244 sdcclib libint.lib _moduint.rel
6245 \end_layout
6246
6247 \begin_layout Standard
6248
6249 \family sans
6250 \series bold
6251 sdcclib libint.lib _mulint.rel
6252 \series default
6253
6254 \newline
6255
6256 \end_layout
6257
6258 \begin_layout Standard
6259 If the file already exists in the library, it will be replaced.
6260  To see what modules and symbols are included in the library, options -s
6261  and -m are available.
6262  For example:
6263 \newline
6264
6265 \newline
6266
6267 \family sans
6268 \series bold
6269 sdcclib -s libint.lib
6270 \family default
6271
6272 \begin_inset LatexCommand \index{sdcclib}
6273
6274 \end_inset
6275
6276
6277 \newline
6278
6279 \family typewriter
6280 \series default
6281 _divsint.rel:
6282 \end_layout
6283
6284 \begin_layout Standard
6285
6286 \family typewriter
6287 __divsint_a_1_1
6288 \end_layout
6289
6290 \begin_layout Standard
6291
6292 \family typewriter
6293 __divsint_PARM_2
6294 \end_layout
6295
6296 \begin_layout Standard
6297
6298 \family typewriter
6299 __divsint
6300 \newline
6301 _divuint.rel:
6302 \end_layout
6303
6304 \begin_layout Standard
6305
6306 \family typewriter
6307 __divuint_a_1_1
6308 \end_layout
6309
6310 \begin_layout Standard
6311
6312 \family typewriter
6313 __divuint_PARM_2
6314 \end_layout
6315
6316 \begin_layout Standard
6317
6318 \family typewriter
6319 __divuint_reste_1_1
6320 \end_layout
6321
6322 \begin_layout Standard
6323
6324 \family typewriter
6325 __divuint_count_1_1
6326 \end_layout
6327
6328 \begin_layout Standard
6329
6330 \family typewriter
6331 __divuint
6332 \newline
6333 _modsint.rel:
6334 \end_layout
6335
6336 \begin_layout Standard
6337
6338 \family typewriter
6339 __modsint_a_1_1
6340 \end_layout
6341
6342 \begin_layout Standard
6343
6344 \family typewriter
6345 __modsint_PARM_2
6346 \end_layout
6347
6348 \begin_layout Standard
6349
6350 \family typewriter
6351 __modsint
6352 \newline
6353 _moduint.rel:
6354 \end_layout
6355
6356 \begin_layout Standard
6357
6358 \family typewriter
6359 __moduint_a_1_1
6360 \end_layout
6361
6362 \begin_layout Standard
6363
6364 \family typewriter
6365 __moduint_PARM_2
6366 \end_layout
6367
6368 \begin_layout Standard
6369
6370 \family typewriter
6371 __moduint_count_1_1
6372 \end_layout
6373
6374 \begin_layout Standard
6375
6376 \family typewriter
6377 __moduint
6378 \newline
6379 _mulint.rel:
6380 \end_layout
6381
6382 \begin_layout Standard
6383
6384 \family typewriter
6385 __mulint_PARM_2
6386 \end_layout
6387
6388 \begin_layout Standard
6389
6390 \family typewriter
6391 __mulint
6392 \family default
6393 \series bold
6394
6395 \newline
6396
6397 \end_layout
6398
6399 \begin_layout Standard
6400 If the source files are compiled using -
6401 \begin_inset ERT
6402 status collapsed
6403
6404 \begin_layout Standard
6405
6406
6407 \backslash
6408 /
6409 \end_layout
6410
6411 \end_inset
6412
6413 -debug
6414 \begin_inset LatexCommand \index{-\/-debug}
6415
6416 \end_inset
6417
6418 , the corresponding debug information file .adb will be include in the library
6419  file as well.
6420  The library files created with sdcclib are plain text files, so they can
6421  be viewed with a text editor.
6422  It is not recomended to modify a library file created with sdcclib using
6423  a text editor, as there are file indexes numbers located accross the file
6424  used by the linker to quickly locate the required module to link.
6425  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
6426  it can be safely deleted, since all the information required for linking
6427  is embedded in the library file itself.
6428  Library files created using sdcclib are used as described in the preceding
6429  sections.
6430 \begin_inset VSpace bigskip
6431 \end_inset
6432
6433
6434 \end_layout
6435
6436 \begin_layout Section
6437 Command Line Options
6438 \begin_inset LatexCommand \index{Command Line Options}
6439
6440 \end_inset
6441
6442
6443 \begin_inset LatexCommand \label{sec:Command-Line-Options}
6444
6445 \end_inset
6446
6447
6448 \end_layout
6449
6450 \begin_layout Subsection
6451 Processor Selection Options
6452 \begin_inset LatexCommand \index{Options processor selection}
6453
6454 \end_inset
6455
6456
6457 \begin_inset LatexCommand \index{Processor selection options}
6458
6459 \end_inset
6460
6461
6462 \end_layout
6463
6464 \begin_layout List
6465 \labelwidthstring 00.00.0000
6466
6467 \series bold
6468 -mmcs51
6469 \begin_inset LatexCommand \index{-mmcs51}
6470
6471 \end_inset
6472
6473
6474 \series default
6475  Generate code for the Intel MCS51
6476 \begin_inset LatexCommand \index{MCS51}
6477
6478 \end_inset
6479
6480  family of processors.
6481  This is the default processor target.
6482 \end_layout
6483
6484 \begin_layout List
6485 \labelwidthstring 00.00.0000
6486
6487 \series bold
6488 -mds390
6489 \begin_inset LatexCommand \index{-mds390}
6490
6491 \end_inset
6492
6493
6494 \series default
6495  Generate code for the Dallas DS80C390
6496 \begin_inset LatexCommand \index{DS80C390}
6497
6498 \end_inset
6499
6500  processor.
6501 \end_layout
6502
6503 \begin_layout List
6504 \labelwidthstring 00.00.0000
6505
6506 \series bold
6507 -mds400
6508 \begin_inset LatexCommand \index{-mds400}
6509
6510 \end_inset
6511
6512
6513 \series default
6514  Generate code for the Dallas DS80C400
6515 \begin_inset LatexCommand \index{DS80C400}
6516
6517 \end_inset
6518
6519  processor.
6520 \end_layout
6521
6522 \begin_layout List
6523 \labelwidthstring 00.00.0000
6524
6525 \series bold
6526 -mhc08
6527 \begin_inset LatexCommand \index{-mhc08}
6528
6529 \end_inset
6530
6531
6532 \series default
6533  Generate code for the Freescale/Motorola HC08
6534 \begin_inset LatexCommand \index{HC08}
6535
6536 \end_inset
6537
6538  family of processors.
6539 \end_layout
6540
6541 \begin_layout List
6542 \labelwidthstring 00.00.0000
6543
6544 \series bold
6545 -mz80
6546 \begin_inset LatexCommand \index{-mz80}
6547
6548 \end_inset
6549
6550
6551 \series default
6552  Generate code for the Zilog Z80
6553 \begin_inset LatexCommand \index{Z80}
6554
6555 \end_inset
6556
6557  family of processors.
6558 \end_layout
6559
6560 \begin_layout List
6561 \labelwidthstring 00.00.0000
6562
6563 \series bold
6564 -mgbz80
6565 \begin_inset LatexCommand \index{-mgbz80}
6566
6567 \end_inset
6568
6569
6570 \series default
6571  Generate code for the GameBoy Z80
6572 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
6573
6574 \end_inset
6575
6576  processor (Not actively maintained).
6577 \end_layout
6578
6579 \begin_layout List
6580 \labelwidthstring 00.00.0000
6581
6582 \series bold
6583 -mavr
6584 \begin_inset LatexCommand \index{-mavr}
6585
6586 \end_inset
6587
6588
6589 \series default
6590  Generate code for the Atmel AVR
6591 \begin_inset LatexCommand \index{AVR}
6592
6593 \end_inset
6594
6595  processor (Not maintained, not complete).
6596  AVR users should probably have a look at winavr 
6597 \begin_inset LatexCommand \url{http://sourceforge.net/projects/winavr}
6598
6599 \end_inset
6600
6601  or 
6602 \begin_inset LatexCommand \url{http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index}
6603
6604 \end_inset
6605
6606 , which is based on AVR-port of the gcc compiler.
6607 \end_layout
6608
6609 \begin_layout Standard
6610 \begin_inset Note Note
6611 status collapsed
6612
6613 \begin_layout Standard
6614 I think it is fair to direct users there for now.
6615  Open source is also about avoiding unnecessary work .
6616  But I didn't find the 'official' link.
6617 \end_layout
6618
6619 \end_inset
6620
6621
6622 \end_layout
6623
6624 \begin_layout List
6625 \labelwidthstring 00.00.0000
6626
6627 \series bold
6628 -mpic14
6629 \begin_inset LatexCommand \index{-mpic14}
6630
6631 \end_inset
6632
6633
6634 \series default
6635  Generate code for the Microchip PIC 14
6636 \begin_inset LatexCommand \index{PIC14}
6637
6638 \end_inset
6639
6640 -bit processors (p16f84 and variants.
6641  In development, not complete).
6642 \end_layout
6643
6644 \begin_layout Standard
6645 \begin_inset Note Note
6646 status collapsed
6647
6648 \begin_layout Standard
6649 p16f627 p16f628 p16f84 p16f873 p16f877?
6650 \end_layout
6651
6652 \end_inset
6653
6654
6655 \end_layout
6656
6657 \begin_layout List
6658 \labelwidthstring 00.00.0000
6659
6660 \series bold
6661 -mpic16
6662 \begin_inset LatexCommand \index{-mpic16}
6663
6664 \end_inset
6665
6666
6667 \series default
6668  Generate code for the Microchip PIC 16
6669 \begin_inset LatexCommand \index{PIC16}
6670
6671 \end_inset
6672
6673 -bit processors (p18f452 and variants.
6674  In development, not complete).
6675 \end_layout
6676
6677 \begin_layout List
6678 \labelwidthstring 00.00.0000
6679
6680 \series bold
6681 -mtlcs900h
6682 \series default
6683  Generate code for the Toshiba TLCS-900H
6684 \begin_inset LatexCommand \index{TLCS-900H}
6685
6686 \end_inset
6687
6688  processor (Not maintained, not complete).
6689 \end_layout
6690
6691 \begin_layout List
6692 \labelwidthstring 00.00.0000
6693
6694 \series bold
6695 -mxa51
6696 \begin_inset LatexCommand \index{-mxa51}
6697
6698 \end_inset
6699
6700
6701 \series default
6702  Generate code for the Phillips XA51
6703 \begin_inset LatexCommand \index{XA51}
6704
6705 \end_inset
6706
6707  processor (Not maintained, not complete).
6708 \end_layout
6709
6710 \begin_layout Standard
6711 \begin_inset VSpace bigskip
6712 \end_inset
6713
6714
6715 \end_layout
6716
6717 \begin_layout Subsection
6718 Preprocessor Options
6719 \begin_inset LatexCommand \index{Options preprocessor}
6720
6721 \end_inset
6722
6723
6724 \begin_inset LatexCommand \index{Preprocessor options}
6725
6726 \end_inset
6727
6728
6729 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6730
6731 \end_inset
6732
6733
6734 \end_layout
6735
6736 \begin_layout List
6737 \labelwidthstring 00.00.0000
6738
6739 \series bold
6740 -I<path>
6741 \begin_inset LatexCommand \index{-I<path>}
6742
6743 \end_inset
6744
6745
6746 \series default
6747  The additional location where the preprocessor will look for <..h> or 
6748 \begin_inset Quotes eld
6749 \end_inset
6750
6751 ..h
6752 \begin_inset Quotes erd
6753 \end_inset
6754
6755  files.
6756 \end_layout
6757
6758 \begin_layout List
6759 \labelwidthstring 00.00.0000
6760
6761 \series bold
6762 -D<macro[=value]>
6763 \begin_inset LatexCommand \index{-D<macro[=value]>}
6764
6765 \end_inset
6766
6767
6768 \series default
6769  Command line definition of macros.
6770  Passed to the preprocessor.
6771 \end_layout
6772
6773 \begin_layout List
6774 \labelwidthstring 00.00.0000
6775
6776 \series bold
6777 -M
6778 \begin_inset LatexCommand \index{-M}
6779
6780 \end_inset
6781
6782
6783 \series default
6784  Tell the preprocessor to output a rule suitable for make describing the
6785  dependencies of each object file.
6786  For each source file, the preprocessor outputs one make-rule whose target
6787  is the object file name for that source file and whose dependencies are
6788  all the files `#include'd in it.
6789  This rule may be a single line or may be continued with `
6790 \backslash
6791 '-newline if it is long.
6792  The list of rules is printed on standard output instead of the preprocessed
6793  C program.
6794  `-M' implies `-E
6795 \begin_inset LatexCommand \index{-E}
6796
6797 \end_inset
6798
6799 '.
6800 \end_layout
6801
6802 \begin_layout List
6803 \labelwidthstring 00.00.0000
6804
6805 \series bold
6806 -C
6807 \begin_inset LatexCommand \index{-C}
6808
6809 \end_inset
6810
6811
6812 \series default
6813  Tell the preprocessor not to discard comments.
6814  Used with the `-E' option.
6815 \end_layout
6816
6817 \begin_layout List
6818 \labelwidthstring 00.00.0000
6819
6820 \series bold
6821 -MM
6822 \begin_inset LatexCommand \index{-MM}
6823
6824 \end_inset
6825
6826
6827 \size large
6828 \bar under
6829  
6830 \series default
6831 \size default
6832 \bar default
6833 Like `-M' but the output mentions only the user header files included with
6834  `#include 
6835 \begin_inset Quotes eld
6836 \end_inset
6837
6838 file"'.
6839  System header files included with `#include <file>' are omitted.
6840 \end_layout
6841
6842 \begin_layout List
6843 \labelwidthstring 00.00.0000
6844
6845 \series bold
6846 -Aquestion(answer)
6847 \begin_inset LatexCommand \index{-Aquestion(answer)}
6848
6849 \end_inset
6850
6851
6852 \series default
6853  Assert the answer answer for question, in case it is tested with a preprocessor
6854  conditional such as `#if #question(answer)'.
6855  `-A-' disables the standard assertions that normally describe the target
6856  machine.
6857 \end_layout
6858
6859 \begin_layout List
6860 \labelwidthstring 00.00.0000
6861
6862 \series bold
6863 -Umacro
6864 \begin_inset LatexCommand \index{-Umacro}
6865
6866 \end_inset
6867
6868
6869 \series default
6870  Undefine macro macro.
6871  `-U' options are evaluated after all `-D' options, but before any `-include'
6872  and `-imacros' options.
6873 \end_layout
6874
6875 \begin_layout List
6876 \labelwidthstring 00.00.0000
6877
6878 \series bold
6879 -dM
6880 \begin_inset LatexCommand \index{-dM}
6881
6882 \end_inset
6883
6884
6885 \series default
6886  Tell the preprocessor to output only a list of the macro definitions that
6887  are in effect at the end of preprocessing.
6888  Used with the `-E' option.
6889 \end_layout
6890
6891 \begin_layout List
6892 \labelwidthstring 00.00.0000
6893
6894 \series bold
6895 -dD
6896 \begin_inset LatexCommand \index{-dD}
6897
6898 \end_inset
6899
6900
6901 \series default
6902  Tell the preprocessor to pass all macro definitions into the output, in
6903  their proper sequence in the rest of the output.
6904 \end_layout
6905
6906 \begin_layout List
6907 \labelwidthstring 00.00.0000
6908
6909 \series bold
6910 -dN
6911 \begin_inset LatexCommand \index{-dN}
6912
6913 \end_inset
6914
6915
6916 \size large
6917 \bar under
6918  
6919 \series default
6920 \size default
6921 \bar default
6922 Like `-dD' except that the macro arguments and contents are omitted.
6923  Only `#define name' is included in the output.
6924 \end_layout
6925
6926 \begin_layout List
6927 \labelwidthstring 00.00.0000
6928
6929 \series bold
6930 -pedantic-parse-number
6931 \begin_inset LatexCommand \index{pedantic}
6932
6933 \end_inset
6934
6935
6936 \begin_inset LatexCommand \index{-pedantic-parse-number}
6937
6938 \end_inset
6939
6940
6941 \size large
6942 \bar under
6943
6944 \begin_inset LatexCommand \label{lyx:-pedantic-parse-number}
6945
6946 \end_inset
6947
6948  
6949 \series default
6950 \size default
6951 \bar default
6952 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
6953  and the macro LO_B(3) gets expanded.
6954  See also #pragma pedantic_parse_number 
6955 \begin_inset LatexCommand \vpageref{ite:pedantic_parse_number}
6956
6957 \end_inset
6958
6959  in section
6960 \begin_inset LatexCommand \ref{sec:Pragmas}
6961
6962 \end_inset
6963
6964  
6965 \emph on
6966 Note: this functionality is not in conformance with C99 standard!
6967 \end_layout
6968
6969 \begin_layout List
6970 \labelwidthstring 00.00.0000
6971
6972 \series bold
6973 -Wp\InsetSpace ~
6974 preprocessorOption[,preprocessorOption]
6975 \series default
6976
6977 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
6978
6979 \end_inset
6980
6981 ...
6982  Pass the preprocessorOption to the preprocessor 
6983 \family typewriter
6984 sdcpp
6985 \family default
6986
6987 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
6988
6989 \end_inset
6990
6991 .
6992  SDCC uses an adapted version of the preprocessor 
6993 \emph on
6994 cpp
6995 \emph default
6996  of the GNU Compiler Collection
6997 \begin_inset LatexCommand \index{gcc (GNU Compiler Collection)}
6998
6999 \end_inset
7000
7001  (
7002 \emph on
7003 gcc
7004 \emph default
7005  
7006 \begin_inset LatexCommand \url{http://gcc.gnu.org/}
7007
7008 \end_inset
7009
7010 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7011 4.1.1\InsetSpace ~
7012 CPP\InsetSpace ~
7013 Manual
7014  at 
7015 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
7016
7017 \end_inset
7018
7019 .
7020 \end_layout
7021
7022 \begin_layout Standard
7023 \begin_inset VSpace bigskip
7024 \end_inset
7025
7026
7027 \end_layout
7028
7029 \begin_layout Subsection
7030 Linker Options
7031 \begin_inset LatexCommand \index{Options linker}
7032
7033 \end_inset
7034
7035
7036 \begin_inset LatexCommand \index{Linker options}
7037
7038 \end_inset
7039
7040
7041 \end_layout
7042
7043 \begin_layout List
7044 \labelwidthstring 00.00.0000
7045
7046 \series bold
7047 -L\InsetSpace ~
7048 -
7049 \series default
7050
7051 \begin_inset ERT
7052 status collapsed
7053
7054 \begin_layout Standard
7055
7056
7057 \backslash
7058 /
7059 \end_layout
7060
7061 \end_inset
7062
7063
7064 \series bold
7065 -lib-path
7066 \begin_inset LatexCommand \index{-\/-lib-path <path>}
7067
7068 \end_inset
7069
7070
7071 \begin_inset LatexCommand \index{-L -\/-lib-path}
7072
7073 \end_inset
7074
7075
7076 \series default
7077 \InsetSpace ~
7078 <absolute path to additional libraries> This option is passed to the linkage
7079  editor's additional libraries
7080 \begin_inset LatexCommand \index{Libraries}
7081
7082 \end_inset
7083
7084  search path.
7085  The path name must be absolute.
7086  Additional library files may be specified in the command line.
7087  See section Compiling programs for more details.
7088 \end_layout
7089
7090 \begin_layout List
7091 \labelwidthstring 00.00.0000
7092
7093 \series bold
7094 -
7095 \begin_inset ERT
7096 status collapsed
7097
7098 \begin_layout Standard
7099
7100
7101 \backslash
7102 /
7103 \end_layout
7104
7105 \end_inset
7106
7107 -xram-loc
7108 \series default
7109
7110 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
7111
7112 \end_inset
7113
7114 \InsetSpace ~
7115 <Value> The start location of the external ram
7116 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7117
7118 \end_inset
7119
7120 , default value is 0.
7121  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7122 \begin_inset ERT
7123 status collapsed
7124
7125 \begin_layout Standard
7126
7127
7128 \backslash
7129 /
7130 \end_layout
7131
7132 \end_inset
7133
7134 -xram-loc 0x8000 or -
7135 \begin_inset ERT
7136 status collapsed
7137
7138 \begin_layout Standard
7139
7140
7141 \backslash
7142 /
7143 \end_layout
7144
7145 \end_inset
7146
7147 -xram-loc 32768.
7148 \end_layout
7149
7150 \begin_layout List
7151 \labelwidthstring 00.00.0000
7152
7153 \series bold
7154 -
7155 \begin_inset ERT
7156 status collapsed
7157
7158 \begin_layout Standard
7159
7160
7161 \backslash
7162 /
7163 \end_layout
7164
7165 \end_inset
7166
7167 -code-loc
7168 \series default
7169
7170 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
7171
7172 \end_inset
7173
7174 \InsetSpace ~
7175 <Value> The start location of the code
7176 \begin_inset LatexCommand \index{code}
7177
7178 \end_inset
7179
7180  segment, default value 0.
7181  Note when this option is used the interrupt vector table
7182 \begin_inset LatexCommand \index{interrupt vector table}
7183
7184 \end_inset
7185
7186  is also relocated to the given address.
7187  The value entered can be in Hexadecimal or Decimal format, e.g.: -
7188 \begin_inset ERT
7189 status collapsed
7190
7191 \begin_layout Standard
7192
7193
7194 \backslash
7195 /
7196 \end_layout
7197
7198 \end_inset
7199
7200 -code-loc 0x8000 or -
7201 \begin_inset ERT
7202 status collapsed
7203
7204 \begin_layout Standard
7205
7206
7207 \backslash
7208 /
7209 \end_layout
7210
7211 \end_inset
7212
7213 -code-loc 32768.
7214 \end_layout
7215
7216 \begin_layout List
7217 \labelwidthstring 00.00.0000
7218
7219 \series bold
7220 -
7221 \begin_inset ERT
7222 status collapsed
7223
7224 \begin_layout Standard
7225
7226
7227 \backslash
7228 /
7229 \end_layout
7230
7231 \end_inset
7232
7233 -stack-loc
7234 \series default
7235
7236 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
7237
7238 \end_inset
7239
7240 \InsetSpace ~
7241 <Value> By default the stack
7242 \begin_inset LatexCommand \index{stack}
7243
7244 \end_inset
7245
7246  is placed after the data segment.
7247  Using this option the stack can be placed anywhere in the internal memory
7248  space of the 8051.
7249  The value entered can be in Hexadecimal or Decimal format, e.g.
7250  -
7251 \begin_inset ERT
7252 status collapsed
7253
7254 \begin_layout Standard
7255
7256
7257 \backslash
7258 /
7259 \end_layout
7260
7261 \end_inset
7262
7263 -stack-loc 0x20 or -
7264 \begin_inset ERT
7265 status collapsed
7266
7267 \begin_layout Standard
7268
7269
7270 \backslash
7271 /
7272 \end_layout
7273
7274 \end_inset
7275
7276 -stack-loc 32.
7277  Since the sp register is incremented before a push or call, the initial
7278  sp will be set to one byte prior the provided value.
7279  The provided value should not overlap any other memory areas such as used
7280  register banks or the data segment and with enough space for the current
7281  application.
7282  The 
7283 \series bold
7284 -
7285 \begin_inset ERT
7286 status collapsed
7287
7288 \begin_layout Standard
7289
7290
7291 \backslash
7292 /
7293 \end_layout
7294
7295 \end_inset
7296
7297 -pack-iram
7298 \series default
7299 \InsetSpace ~
7300
7301 \begin_inset LatexCommand \index{-\/-pack-iram}
7302
7303 \end_inset
7304
7305  option (which is now a default setting) will override this setting, so
7306  you should also specify the 
7307 \series bold
7308 -
7309 \begin_inset ERT
7310 status collapsed
7311
7312 \begin_layout Standard
7313
7314
7315 \backslash
7316 /
7317 \end_layout
7318
7319 \end_inset
7320
7321 -no-pack-iram
7322 \series default
7323 \InsetSpace ~
7324
7325 \begin_inset LatexCommand \index{-\/-no-pack-iram}
7326
7327 \end_inset
7328
7329  option if you need to manually place the stack.
7330 \end_layout
7331
7332 \begin_layout List
7333 \labelwidthstring 00.00.0000
7334
7335 \series bold
7336 -
7337 \begin_inset ERT
7338 status collapsed
7339
7340 \begin_layout Standard
7341
7342
7343 \backslash
7344 /
7345 \end_layout
7346
7347 \end_inset
7348
7349 -xstack-loc
7350 \series default
7351
7352 \begin_inset LatexCommand \index{-\/-xstack-loc <Value>}
7353
7354 \end_inset
7355
7356 \InsetSpace ~
7357 <Value> By default the external stack
7358 \begin_inset LatexCommand \index{xstack}
7359
7360 \end_inset
7361
7362  is placed after the pdata
7363 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7364
7365 \end_inset
7366
7367  segment.
7368  Using this option the xstack can be placed anywhere in the external memory
7369  space of the 8051.
7370  The value entered can be in Hexadecimal or Decimal format, e.g.
7371  -
7372 \begin_inset ERT
7373 status collapsed
7374
7375 \begin_layout Standard
7376
7377
7378 \backslash
7379 /
7380 \end_layout
7381
7382 \end_inset
7383
7384 -xstack-loc 0x8000 or -
7385 \begin_inset ERT
7386 status collapsed
7387
7388 \begin_layout Standard
7389
7390
7391 \backslash
7392 /
7393 \end_layout
7394
7395 \end_inset
7396
7397 -stack-loc 32768.
7398  The provided value should not overlap any other memory areas such as the
7399  pdata or xdata segment and with enough space for the current application.
7400 \end_layout
7401
7402 \begin_layout List
7403 \labelwidthstring 00.00.0000
7404
7405 \series bold
7406 -
7407 \begin_inset ERT
7408 status collapsed
7409
7410 \begin_layout Standard
7411
7412
7413 \backslash
7414 /
7415 \end_layout
7416
7417 \end_inset
7418
7419 -data-loc
7420 \series default
7421
7422 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
7423
7424 \end_inset
7425
7426 \InsetSpace ~
7427 <Value> The start location of the internal ram data
7428 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7429
7430 \end_inset
7431
7432  segment.
7433  The value entered can be in Hexadecimal or Decimal format, eg.
7434  -
7435 \begin_inset ERT
7436 status collapsed
7437
7438 \begin_layout Standard
7439
7440
7441 \backslash
7442 /
7443 \end_layout
7444
7445 \end_inset
7446
7447 -data-loc 0x20 or -
7448 \begin_inset ERT
7449 status collapsed
7450
7451 \begin_layout Standard
7452
7453
7454 \backslash
7455 /
7456 \end_layout
7457
7458 \end_inset
7459
7460 -data-loc 32.
7461  (By default, the start location of the internal ram data segment  is set
7462  as low as possible in memory, taking into account the used register banks
7463  and the bit segment at address 0x20.
7464  For example if register banks 0 and 1 are used without bit variables, the
7465  data segment will be set, if -
7466 \begin_inset ERT
7467 status collapsed
7468
7469 \begin_layout Standard
7470
7471
7472 \backslash
7473 /
7474 \end_layout
7475
7476 \end_inset
7477
7478 -data-loc is not used, to location 0x10.)
7479 \end_layout
7480
7481 \begin_layout List
7482 \labelwidthstring 00.00.0000
7483
7484 \series bold
7485 -
7486 \begin_inset ERT
7487 status collapsed
7488
7489 \begin_layout Standard
7490
7491
7492 \backslash
7493 /
7494 \end_layout
7495
7496 \end_inset
7497
7498 -idata-loc
7499 \series default
7500
7501 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
7502
7503 \end_inset
7504
7505 \InsetSpace ~
7506 <Value> The start location of the indirectly addressable internal ram
7507 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7508
7509 \end_inset
7510
7511  of the 8051, default value is 0x80.
7512  The value entered can be in Hexadecimal or Decimal format, eg.
7513  -
7514 \begin_inset ERT
7515 status collapsed
7516
7517 \begin_layout Standard
7518
7519
7520 \backslash
7521 /
7522 \end_layout
7523
7524 \end_inset
7525
7526 -idata-loc 0x88 or -
7527 \begin_inset ERT
7528 status collapsed
7529
7530 \begin_layout Standard
7531
7532
7533 \backslash
7534 /
7535 \end_layout
7536
7537 \end_inset
7538
7539 -idata-loc 136.
7540 \end_layout
7541
7542 \begin_layout List
7543 \labelwidthstring 00.00.0000
7544
7545 \series bold
7546 -
7547 \begin_inset ERT
7548 status collapsed
7549
7550 \begin_layout Standard
7551
7552
7553 \backslash
7554 /
7555 \end_layout
7556
7557 \end_inset
7558
7559 -bit-loc
7560 \series default
7561 \InsetSpace ~
7562 <Value> The start location of the bit
7563 \begin_inset LatexCommand \index{bit}
7564
7565 \end_inset
7566
7567  addressable internal ram of the 8051.
7568  This is 
7569 \emph on
7570 not
7571 \emph default
7572  implemented yet.
7573  Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
7574 -bBSEG=<Value>.
7575 \end_layout
7576
7577 \begin_layout List
7578 \labelwidthstring 00.00.0000
7579
7580 \series bold
7581 -
7582 \begin_inset ERT
7583 status collapsed
7584
7585 \begin_layout Standard
7586
7587
7588 \backslash
7589 /
7590 \end_layout
7591
7592 \end_inset
7593
7594 -out-fmt-ihx
7595 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
7596
7597 \end_inset
7598
7599
7600 \bar under
7601  
7602 \series default
7603 \bar default
7604 The linker output (final object code) is in Intel Hex format.
7605 \begin_inset LatexCommand \index{Intel hex format}
7606
7607 \end_inset
7608
7609  This is the default option.
7610  The format itself is documented in the documentation of srecord
7611 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
7612
7613 \end_inset
7614
7615 .
7616 \end_layout
7617
7618 \begin_layout List
7619 \labelwidthstring 00.00.0000
7620
7621 \series bold
7622 -
7623 \begin_inset ERT
7624 status collapsed
7625
7626 \begin_layout Standard
7627
7628
7629 \backslash
7630 /
7631 \end_layout
7632
7633 \end_inset
7634
7635 -out-fmt-s19
7636 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7637
7638 \end_inset
7639
7640
7641 \bar under
7642  
7643 \series default
7644 \bar default
7645 The linker output (final object code) is in Motorola S19 format
7646 \begin_inset LatexCommand \index{Motorola S19 format}
7647
7648 \end_inset
7649
7650 .
7651  The format itself is documented in the documentation of srecord.
7652 \end_layout
7653
7654 \begin_layout List
7655 \labelwidthstring 00.00.0000
7656
7657 \series bold
7658 -
7659 \begin_inset ERT
7660 status collapsed
7661
7662 \begin_layout Standard
7663
7664
7665 \backslash
7666 /
7667 \end_layout
7668
7669 \end_inset
7670
7671 -out-fmt-elf
7672 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
7673
7674 \end_inset
7675
7676
7677 \begin_inset LatexCommand \index{HC08!Options!-\/-out-fmt-elf}
7678
7679 \end_inset
7680
7681
7682 \bar under
7683  
7684 \series default
7685 \bar default
7686 The linker output (final object code) is in ELF format
7687 \begin_inset LatexCommand \index{ELF format}
7688
7689 \end_inset
7690
7691 .
7692  (Currently only supported for the HC08
7693 \begin_inset LatexCommand \index{HC08}
7694
7695 \end_inset
7696
7697  processors)
7698 \end_layout
7699
7700 \begin_layout List
7701 \labelwidthstring 00.00.0000
7702
7703 \series bold
7704 -Wl\InsetSpace ~
7705 linkOption[,linkOption]
7706 \series default
7707
7708 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
7709
7710 \end_inset
7711
7712 ...
7713  Pass the linkOption to the linker.
7714  If a bootloader is used an option like 
7715 \begin_inset Quotes sld
7716 \end_inset
7717
7718 -Wl\InsetSpace ~
7719 -bCSEG=0x1000
7720 \begin_inset Quotes srd
7721 \end_inset
7722
7723  would be typical to set the start of the code segment.
7724  See also #pragma constseg and #pragma codeseg in section 
7725 \begin_inset LatexCommand \ref{sec:Pragmas}
7726
7727 \end_inset
7728
7729  .
7730  File sdcc/as/doc/asxhtm.html has more on linker options.
7731 \end_layout
7732
7733 \begin_layout Standard
7734 \begin_inset VSpace bigskip
7735 \end_inset
7736
7737
7738 \end_layout
7739
7740 \begin_layout Subsection
7741 MCS51 Options
7742 \begin_inset LatexCommand \index{Options MCS51}
7743
7744 \end_inset
7745
7746
7747 \begin_inset LatexCommand \index{MCS51 options}
7748
7749 \end_inset
7750
7751
7752 \end_layout
7753
7754 \begin_layout List
7755 \labelwidthstring 00.00.0000
7756
7757 \series bold
7758 -
7759 \begin_inset ERT
7760 status collapsed
7761
7762 \begin_layout Standard
7763
7764
7765 \backslash
7766 /
7767 \end_layout
7768
7769 \end_inset
7770
7771 -model-small
7772 \begin_inset LatexCommand \index{-\/-model-small}
7773
7774 \end_inset
7775
7776
7777 \series default
7778 \size large
7779 \emph on
7780  
7781 \size default
7782 \emph default
7783 Generate code for Small Model programs, see section Memory Models for more
7784  details.
7785  This is the default model.
7786 \end_layout
7787
7788 \begin_layout List
7789 \labelwidthstring 00.00.0000
7790
7791 \series bold
7792 -
7793 \begin_inset ERT
7794 status collapsed
7795
7796 \begin_layout Standard
7797
7798
7799 \backslash
7800 /
7801 \end_layout
7802
7803 \end_inset
7804
7805 -model-medium
7806 \begin_inset LatexCommand \index{-\/-model-medium}
7807
7808 \end_inset
7809
7810
7811 \series default
7812  Generate code for Medium model programs, see section Memory Models for
7813  more details.
7814  If this option is used all source files in the project have to be compiled
7815  with this option.
7816  It must also be used when invoking the linker.
7817 \end_layout
7818
7819 \begin_layout List
7820 \labelwidthstring 00.00.0000
7821
7822 \series bold
7823 -
7824 \begin_inset ERT
7825 status collapsed
7826
7827 \begin_layout Standard
7828
7829
7830 \backslash
7831 /
7832 \end_layout
7833
7834 \end_inset
7835
7836 -model-large
7837 \begin_inset LatexCommand \index{-\/-model-large}
7838
7839 \end_inset
7840
7841
7842 \series default
7843  Generate code for Large model programs, see section Memory Models for more
7844  details.
7845  If this option is used all source files in the project have to be compiled
7846  with this option.
7847  It must also be used when invoking the linker.
7848 \end_layout
7849
7850 \begin_layout List
7851 \labelwidthstring 00.00.0000
7852
7853 \series bold
7854 -
7855 \begin_inset ERT
7856 status collapsed
7857
7858 \begin_layout Standard
7859
7860
7861 \backslash
7862 /
7863 \end_layout
7864
7865 \end_inset
7866
7867 -xstack
7868 \begin_inset LatexCommand \index{-\/-xstack}
7869
7870 \end_inset
7871
7872
7873 \series default
7874  Uses a pseudo stack in the pdata
7875 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
7876
7877 \end_inset
7878
7879  area (usually the first 256 bytes in the external ram) for allocating variables
7880  and passing parameters.
7881  See section 
7882 \begin_inset LatexCommand \ref{sub:External-Stack}
7883
7884 \end_inset
7885
7886 \InsetSpace ~
7887  External Stack for more details.
7888 \end_layout
7889
7890 \begin_layout List
7891 \labelwidthstring 00.00.0000
7892
7893 \series bold
7894 -
7895 \begin_inset ERT
7896 status collapsed
7897
7898 \begin_layout Standard
7899
7900
7901 \backslash
7902 /
7903 \end_layout
7904
7905 \end_inset
7906
7907 -iram-size
7908 \series default
7909 \InsetSpace ~
7910 <Value>
7911 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
7912
7913 \end_inset
7914
7915  Causes the linker to check if the internal ram usage is within limits of
7916  the given value.
7917 \end_layout
7918
7919 \begin_layout List
7920 \labelwidthstring 00.00.0000
7921
7922 \series bold
7923 -
7924 \begin_inset ERT
7925 status collapsed
7926
7927 \begin_layout Standard
7928
7929
7930 \backslash
7931 /
7932 \end_layout
7933
7934 \end_inset
7935
7936 -xram-size
7937 \series default
7938 \InsetSpace ~
7939 <Value>
7940 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
7941
7942 \end_inset
7943
7944  Causes the linker to check if the external ram usage is within limits of
7945  the given value.
7946 \end_layout
7947
7948 \begin_layout List
7949 \labelwidthstring 00.00.0000
7950
7951 \series bold
7952 -
7953 \begin_inset ERT
7954 status collapsed
7955
7956 \begin_layout Standard
7957
7958
7959 \backslash
7960 /
7961 \end_layout
7962
7963 \end_inset
7964
7965 -code-size
7966 \series default
7967 \InsetSpace ~
7968 <Value>
7969 \begin_inset LatexCommand \index{-\/-code-size <Value>}
7970
7971 \end_inset
7972
7973  Causes the linker to check if the code memory usage is within limits of
7974  the given value.
7975 \end_layout
7976
7977 \begin_layout List
7978 \labelwidthstring 00.00.0000
7979
7980 \series bold
7981 -
7982 \begin_inset ERT
7983 status collapsed
7984
7985 \begin_layout Standard
7986
7987
7988 \backslash
7989 /
7990 \end_layout
7991
7992 \end_inset
7993
7994 -stack-size
7995 \series default
7996 \InsetSpace ~
7997 <Value>
7998 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
7999
8000 \end_inset
8001
8002  Causes the linker to check if there is at minimum <Value> bytes for stack.
8003 \end_layout
8004
8005 \begin_layout List
8006 \labelwidthstring 00.00.0000
8007
8008 \series bold
8009 -
8010 \begin_inset ERT
8011 status collapsed
8012
8013 \begin_layout Standard
8014
8015
8016 \backslash
8017 /
8018 \end_layout
8019
8020 \end_inset
8021
8022 -pack-iram
8023 \series default
8024 \InsetSpace ~
8025
8026 \begin_inset LatexCommand \index{-\/-pack-iram}
8027
8028 \end_inset
8029
8030  Causes the linker to use unused register banks for data variables and pack
8031  data, idata and stack together.
8032  This is the default now.
8033 \end_layout
8034
8035 \begin_layout List
8036 \labelwidthstring 00.00.0000
8037
8038 \series bold
8039 -
8040 \begin_inset ERT
8041 status collapsed
8042
8043 \begin_layout Standard
8044
8045
8046 \backslash
8047 /
8048 \end_layout
8049
8050 \end_inset
8051
8052 -no-pack-iram
8053 \series default
8054 \InsetSpace ~
8055
8056 \begin_inset LatexCommand \index{-\/-no-pack-iram}
8057
8058 \end_inset
8059
8060  Causes the linker to use old style for allocating memory areas.
8061 \end_layout
8062
8063 \begin_layout Standard
8064 \begin_inset VSpace bigskip
8065 \end_inset
8066
8067
8068 \end_layout
8069
8070 \begin_layout Subsection
8071 DS390 / DS400 Options
8072 \begin_inset LatexCommand \index{Options DS390}
8073
8074 \end_inset
8075
8076
8077 \begin_inset LatexCommand \index{DS390}
8078
8079 \end_inset
8080
8081
8082 \end_layout
8083
8084 \begin_layout List
8085 \labelwidthstring 00.00.0000
8086
8087 \series bold
8088 -
8089 \begin_inset ERT
8090 status collapsed
8091
8092 \begin_layout Standard
8093
8094
8095 \backslash
8096 /
8097 \end_layout
8098
8099 \end_inset
8100
8101 -model-flat24
8102 \series default
8103
8104 \begin_inset LatexCommand \index{DS390!Options!-\/-model-flat24}
8105
8106 \end_inset
8107
8108
8109 \size large
8110 \emph on
8111  
8112 \size default
8113 \emph default
8114 Generate 24-bit flat mode code.
8115  This is the one and only that the ds390 code generator supports right now
8116  and is default when using 
8117 \emph on
8118 -mds390
8119 \emph default
8120 .
8121  See section Memory Models for more details.
8122 \end_layout
8123
8124 \begin_layout List
8125 \labelwidthstring 00.00.0000
8126
8127 \series bold
8128 -
8129 \begin_inset ERT
8130 status collapsed
8131
8132 \begin_layout Standard
8133
8134
8135 \backslash
8136 /
8137 \end_layout
8138
8139 \end_inset
8140
8141 -protect-sp-update
8142 \begin_inset LatexCommand \index{DS390!Options!-\/-protect-sp-update}
8143
8144 \end_inset
8145
8146
8147 \series default
8148  disable interrupts during ESP:SP updates.
8149 \end_layout
8150
8151 \begin_layout List
8152 \labelwidthstring 00.00.0000
8153
8154 \series bold
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 -stack-10bit
8169 \series default
8170
8171 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-10bit}
8172
8173 \end_inset
8174
8175  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8176  This is the one and only that the ds390 code generator supports right now
8177  and is default when using 
8178 \emph on
8179 -mds390
8180 \emph default
8181 .
8182  In this mode, the stack is located in the lower 1K of the internal RAM,
8183  which is mapped to 0x400000.
8184  Note that the support is incomplete, since it still uses a single byte
8185  as the stack pointer.
8186  This means that only the lower 256 bytes of the potential 1K stack space
8187  will actually be used.
8188  However, this does allow you to reclaim the precious 256 bytes of low RAM
8189  for use for the DATA and IDATA segments.
8190  The compiler will not generate any code to put the processor into 10 bit
8191  stack mode.
8192  It is important to ensure that the processor is in this mode before calling
8193  any re-entrant functions compiled with this option.
8194  In principle, this should work with the 
8195 \emph on
8196 -
8197 \begin_inset ERT
8198 status collapsed
8199
8200 \begin_layout Standard
8201
8202
8203 \backslash
8204 /
8205 \end_layout
8206
8207 \end_inset
8208
8209 -stack-auto
8210 \begin_inset LatexCommand \index{-\/-stack-auto}
8211
8212 \end_inset
8213
8214
8215 \emph default
8216  option, but that has not been tested.
8217  It is incompatible with the 
8218 \emph on
8219 -
8220 \begin_inset ERT
8221 status collapsed
8222
8223 \begin_layout Standard
8224
8225
8226 \backslash
8227 /
8228 \end_layout
8229
8230 \end_inset
8231
8232 -xstack
8233 \begin_inset LatexCommand \index{-\/-xstack}
8234
8235 \end_inset
8236
8237
8238 \emph default
8239  option.
8240  It also only makes sense if the processor is in 24 bit contiguous addressing
8241  mode (see the 
8242 \emph on
8243 -
8244 \begin_inset ERT
8245 status collapsed
8246
8247 \begin_layout Standard
8248
8249
8250 \backslash
8251 /
8252 \end_layout
8253
8254 \end_inset
8255
8256 -model-flat24 option
8257 \emph default
8258 ).
8259 \series bold
8260
8261 \begin_inset Note Note
8262 status collapsed
8263
8264 \begin_layout List
8265 \labelwidthstring 00.00.0000
8266
8267 \series bold
8268 --stack-8-bit - switches off the 10-bit mode
8269 \end_layout
8270
8271 \end_inset
8272
8273
8274 \end_layout
8275
8276 \begin_layout List
8277 \labelwidthstring 00.00.0000
8278
8279 \series bold
8280 -
8281 \begin_inset ERT
8282 status collapsed
8283
8284 \begin_layout Standard
8285
8286
8287 \backslash
8288 /
8289 \end_layout
8290
8291 \end_inset
8292
8293 -stack-probe
8294 \begin_inset LatexCommand \index{DS390!Options!-\/-stack-probe}
8295
8296 \end_inset
8297
8298
8299 \series default
8300  insert call to function __stack_probe at each function prologue.
8301 \end_layout
8302
8303 \begin_layout List
8304 \labelwidthstring 00.00.0000
8305
8306 \series bold
8307 -
8308 \begin_inset ERT
8309 status collapsed
8310
8311 \begin_layout Standard
8312
8313
8314 \backslash
8315 /
8316 \end_layout
8317
8318 \end_inset
8319
8320 -tini-libid
8321 \begin_inset LatexCommand \index{DS390!Options!-\/-tini-libid}
8322
8323 \end_inset
8324
8325
8326 \series default
8327  <nnnn> LibraryID used in -mTININative.
8328  
8329 \end_layout
8330
8331 \begin_layout List
8332 \labelwidthstring 00.00.0000
8333
8334 \series bold
8335 -
8336 \begin_inset ERT
8337 status collapsed
8338
8339 \begin_layout Standard
8340
8341
8342 \backslash
8343 /
8344 \end_layout
8345
8346 \end_inset
8347
8348 -use-accelerator
8349 \begin_inset LatexCommand \index{DS390!Options!-\/-use-accelerator}
8350
8351 \end_inset
8352
8353
8354 \series default
8355  generate code for DS390 Arithmetic Accelerator.
8356  
8357 \end_layout
8358
8359 \begin_layout Standard
8360 \begin_inset VSpace bigskip
8361 \end_inset
8362
8363
8364 \end_layout
8365
8366 \begin_layout Subsection
8367 Z80 Options
8368 \begin_inset LatexCommand \index{Options Z80}
8369
8370 \end_inset
8371
8372
8373 \begin_inset LatexCommand \index{Z80}
8374
8375 \end_inset
8376
8377
8378 \end_layout
8379
8380 \begin_layout List
8381 \labelwidthstring 00.00.0000
8382
8383 \series bold
8384 -
8385 \begin_inset ERT
8386 status collapsed
8387
8388 \begin_layout Standard
8389
8390
8391 \backslash
8392 /
8393 \end_layout
8394
8395 \end_inset
8396
8397 -callee-saves-bc
8398 \series default
8399
8400 \begin_inset LatexCommand \index{Z80!Options!-\/-callee-saves-bc}
8401
8402 \end_inset
8403
8404
8405 \size large
8406 \emph on
8407  
8408 \size default
8409 \emph default
8410 Force a called function to always save BC.
8411 \end_layout
8412
8413 \begin_layout List
8414 \labelwidthstring 00.00.0000
8415
8416 \series bold
8417 -
8418 \begin_inset ERT
8419 status collapsed
8420
8421 \begin_layout Standard
8422
8423
8424 \backslash
8425 /
8426 \end_layout
8427
8428 \end_inset
8429
8430 -no-std-crt0
8431 \series default
8432
8433 \begin_inset LatexCommand \index{Z80!Options!-\/-no-std-crt0}
8434
8435 \end_inset
8436
8437  When linking, skip the standard crt0.o object file.
8438  You must provide your own crt0.o for your system when linking.
8439 \end_layout
8440
8441 \begin_layout List
8442 \labelwidthstring 00.00.0000
8443
8444 \series bold
8445 -
8446 \begin_inset ERT
8447 status collapsed
8448
8449 \begin_layout Standard
8450
8451
8452 \backslash
8453 /
8454 \end_layout
8455
8456 \end_inset
8457
8458 -portmode=
8459 \series default
8460 <Value>
8461 \begin_inset LatexCommand \index{Z80!Options!-\/-portmode=<Value>}
8462
8463 \end_inset
8464
8465  Determinate PORT I/O mode (<Value> is z80 or z180).
8466 \end_layout
8467
8468 \begin_layout List
8469 \labelwidthstring 00.00.0000
8470
8471 \series bold
8472 -
8473 \begin_inset ERT
8474 status collapsed
8475
8476 \begin_layout Standard
8477
8478
8479 \backslash
8480 /
8481 \end_layout
8482
8483 \end_inset
8484
8485 -asm=
8486 \series default
8487 <Value>
8488 \begin_inset LatexCommand \index{Z80!Options!-\/-asm=<Value>}
8489
8490 \end_inset
8491
8492  Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
8493 \end_layout
8494
8495 \begin_layout List
8496 \labelwidthstring 00.00.0000
8497
8498 \series bold
8499 -
8500 \begin_inset ERT
8501 status collapsed
8502
8503 \begin_layout Standard
8504
8505
8506 \backslash
8507 /
8508 \end_layout
8509
8510 \end_inset
8511
8512 -codeseg
8513 \series default
8514 \InsetSpace ~
8515 <Value>
8516 \begin_inset LatexCommand \index{Z80!Options!-\/-codeseg <Value>}
8517
8518 \end_inset
8519
8520  Use <Value> for the code segment name.
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 -constseg
8541 \series default
8542 \InsetSpace ~
8543 <Value>
8544 \begin_inset LatexCommand \index{Z80!Options!-\/-constseg <Value>}
8545
8546 \end_inset
8547
8548  Use <Value> for the const segment name.
8549 \end_layout
8550
8551 \begin_layout List
8552 \labelwidthstring 00.00.0000
8553 \begin_inset VSpace bigskip
8554 \end_inset
8555
8556
8557 \end_layout
8558
8559 \begin_layout Subsection
8560 GBZ80 Options
8561 \begin_inset LatexCommand \index{Options GBZ80}
8562
8563 \end_inset
8564
8565
8566 \begin_inset LatexCommand \index{GBZ80}
8567
8568 \end_inset
8569
8570
8571 \end_layout
8572
8573 \begin_layout List
8574 \labelwidthstring 00.00.0000
8575
8576 \series bold
8577 -
8578 \begin_inset ERT
8579 status collapsed
8580
8581 \begin_layout Standard
8582
8583
8584 \backslash
8585 /
8586 \end_layout
8587
8588 \end_inset
8589
8590 -callee-saves-bc
8591 \series default
8592
8593 \begin_inset LatexCommand \index{GBZ80!Options!-\/-callee-saves-bc}
8594
8595 \end_inset
8596
8597
8598 \size large
8599 \emph on
8600  
8601 \size default
8602 \emph default
8603 Force a called function to always save BC.
8604 \end_layout
8605
8606 \begin_layout List
8607 \labelwidthstring 00.00.0000
8608
8609 \series bold
8610 -bo
8611 \series default
8612 \InsetSpace ~
8613 <Num>
8614 \begin_inset LatexCommand \index{GBZ80!Options!-bo <Num>}
8615
8616 \end_inset
8617
8618  Use code bank <Num>.
8619 \end_layout
8620
8621 \begin_layout List
8622 \labelwidthstring 00.00.0000
8623
8624 \series bold
8625 -ba
8626 \series default
8627 \InsetSpace ~
8628 <Num>
8629 \begin_inset LatexCommand \index{GBZ80!Options!-ba <Num>}
8630
8631 \end_inset
8632
8633  Use data bank <Num>.
8634 \end_layout
8635
8636 \begin_layout List
8637 \labelwidthstring 00.00.0000
8638
8639 \series bold
8640 -
8641 \begin_inset ERT
8642 status collapsed
8643
8644 \begin_layout Standard
8645
8646
8647 \backslash
8648 /
8649 \end_layout
8650
8651 \end_inset
8652
8653 -codeseg
8654 \series default
8655 \InsetSpace ~
8656 <Value>
8657 \begin_inset LatexCommand \index{GBZ80!Options!-\/-codeseg <Value>}
8658
8659 \end_inset
8660
8661  Use <Value> for the code segment name.
8662 \end_layout
8663
8664 \begin_layout List
8665 \labelwidthstring 00.00.0000
8666
8667 \series bold
8668 -
8669 \begin_inset ERT
8670 status collapsed
8671
8672 \begin_layout Standard
8673
8674
8675 \backslash
8676 /
8677 \end_layout
8678
8679 \end_inset
8680
8681 -constseg
8682 \series default
8683 \InsetSpace ~
8684 <Value>
8685 \begin_inset LatexCommand \index{GBZ80!Options!-\/-constseg <Value>}
8686
8687 \end_inset
8688
8689  Use <Value> for the const segment name.
8690 \end_layout
8691
8692 \begin_layout Standard
8693 \begin_inset VSpace bigskip
8694 \end_inset
8695
8696
8697 \end_layout
8698
8699 \begin_layout Subsection
8700 Optimization Options
8701 \begin_inset LatexCommand \index{Options optimization}
8702
8703 \end_inset
8704
8705
8706 \begin_inset LatexCommand \index{Optimization options}
8707
8708 \end_inset
8709
8710
8711 \end_layout
8712
8713 \begin_layout List
8714 \labelwidthstring 00.00.0000
8715
8716 \series bold
8717 -
8718 \begin_inset ERT
8719 status collapsed
8720
8721 \begin_layout Standard
8722
8723
8724 \backslash
8725 /
8726 \end_layout
8727
8728 \end_inset
8729
8730 -nogcse
8731 \begin_inset LatexCommand \index{-\/-nogcse}
8732
8733 \end_inset
8734
8735
8736 \series default
8737  Will not do global subexpression elimination, this option may be used when
8738  the compiler creates undesirably large stack/data spaces to store compiler
8739  temporaries (
8740 \emph on
8741 s
8742 \emph default
8743 pill 
8744 \emph on
8745 loc
8746 \emph default
8747 ations, sloc
8748 \begin_inset LatexCommand \index{sloc (spill location)}
8749
8750 \end_inset
8751
8752 ).
8753  A warning message will be generated when this happens and the compiler
8754  will indicate the number of extra bytes it allocated.
8755  It is recommended that this option NOT be used, #pragma\InsetSpace ~
8756 nogcse
8757 \begin_inset LatexCommand \index{\#pragma nogcse}
8758
8759 \end_inset
8760
8761  can be used to turn off global subexpression elimination
8762 \begin_inset LatexCommand \index{Subexpression elimination}
8763
8764 \end_inset
8765
8766  for a given function only.
8767 \end_layout
8768
8769 \begin_layout List
8770 \labelwidthstring 00.00.0000
8771
8772 \series bold
8773 -
8774 \begin_inset ERT
8775 status collapsed
8776
8777 \begin_layout Standard
8778
8779
8780 \backslash
8781 /
8782 \end_layout
8783
8784 \end_inset
8785
8786 -noinvariant
8787 \begin_inset LatexCommand \index{-\/-noinvariant}
8788
8789 \end_inset
8790
8791
8792 \series default
8793  Will not do loop invariant optimizations, this may be turned off for reasons
8794  explained for the previous option.
8795  For more details of loop optimizations performed see Loop Invariants in
8796  section 
8797 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
8798
8799 \end_inset
8800
8801 .
8802  It is recommended that this option NOT be used, #pragma\InsetSpace ~
8803 noinvariant
8804 \begin_inset LatexCommand \index{\#pragma noinvariant}
8805
8806 \end_inset
8807
8808  can be used to turn off invariant optimizations for a given function only.
8809 \end_layout
8810
8811 \begin_layout List
8812 \labelwidthstring 00.00.0000
8813
8814 \series bold
8815 -
8816 \begin_inset ERT
8817 status collapsed
8818
8819 \begin_layout Standard
8820
8821
8822 \backslash
8823 /
8824 \end_layout
8825
8826 \end_inset
8827
8828 -noinduction
8829 \begin_inset LatexCommand \index{-\/-noinduction}
8830
8831 \end_inset
8832
8833
8834 \series default
8835  Will not do loop induction optimizations, see section strength reduction
8836  for more details.
8837  It is recommended that this option is NOT used, #pragma\InsetSpace ~
8838 noinduction
8839 \begin_inset LatexCommand \index{\#pragma noinduction}
8840
8841 \end_inset
8842
8843  can be used to turn off induction optimizations for a given function only.
8844 \end_layout
8845
8846 \begin_layout List
8847 \labelwidthstring 00.00.0000
8848
8849 \series bold
8850 -
8851 \begin_inset ERT
8852 status collapsed
8853
8854 \begin_layout Standard
8855
8856
8857 \backslash
8858 /
8859 \end_layout
8860
8861 \end_inset
8862
8863 -nojtbound
8864 \begin_inset LatexCommand \index{-\/-nojtbound}
8865
8866 \end_inset
8867
8868
8869 \size large
8870 \bar under
8871  
8872 \series default
8873 \size default
8874 \bar default
8875  Will not generate boundary condition check when switch statements
8876 \begin_inset LatexCommand \index{switch statement}
8877
8878 \end_inset
8879
8880  are implemented using jump-tables.
8881  See section 
8882 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
8883
8884 \end_inset
8885
8886 \InsetSpace ~
8887 Switch Statements for more details.
8888  It is recommended that this option is NOT used, #pragma\InsetSpace ~
8889 nojtbound
8890 \begin_inset LatexCommand \index{\#pragma nojtbound}
8891
8892 \end_inset
8893
8894  can be used to turn off boundary checking for jump tables for a given function
8895  only.
8896 \end_layout
8897
8898 \begin_layout List
8899 \labelwidthstring 00.00.0000
8900
8901 \series bold
8902 -
8903 \begin_inset ERT
8904 status collapsed
8905
8906 \begin_layout Standard
8907
8908
8909 \backslash
8910 /
8911 \end_layout
8912
8913 \end_inset
8914
8915 -noloopreverse
8916 \begin_inset LatexCommand \index{-\/-noloopreverse}
8917
8918 \end_inset
8919
8920
8921 \series default
8922 \size large
8923  
8924 \size default
8925 Will not do loop reversal 
8926 \begin_inset LatexCommand \index{Loop reversing}
8927
8928 \end_inset
8929
8930 optimization.
8931 \end_layout
8932
8933 \begin_layout List
8934 \labelwidthstring 00.00.0000
8935 -
8936 \begin_inset ERT
8937 status collapsed
8938
8939 \begin_layout Standard
8940
8941
8942 \backslash
8943 /
8944 \end_layout
8945
8946 \end_inset
8947
8948 -
8949 \series bold
8950 nolabelopt
8951 \series default
8952  
8953 \begin_inset LatexCommand \index{-\/-nolabelopt }
8954
8955 \end_inset
8956
8957 Will not optimize labels (makes the dumpfiles more readable).
8958 \end_layout
8959
8960 \begin_layout List
8961 \labelwidthstring 00.00.0000
8962
8963 \series bold
8964 -
8965 \begin_inset ERT
8966 status collapsed
8967
8968 \begin_layout Standard
8969
8970
8971 \backslash
8972 /
8973 \end_layout
8974
8975 \end_inset
8976
8977 -no-xinit-opt
8978 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8979
8980 \end_inset
8981
8982
8983 \series default
8984  Will not memcpy initialized data from code space into xdata space.
8985  This saves a few bytes in code space if you don't have initialized data
8986 \begin_inset LatexCommand \index{Variable initialization}
8987
8988 \end_inset
8989
8990 .
8991 \end_layout
8992
8993 \begin_layout List
8994 \labelwidthstring 00.00.0000
8995
8996 \series bold
8997 -
8998 \begin_inset ERT
8999 status collapsed
9000
9001 \begin_layout Standard
9002
9003
9004 \backslash
9005 /
9006 \end_layout
9007
9008 \end_inset
9009
9010 -nooverlay
9011 \begin_inset LatexCommand \index{-\/-nooverlay}
9012
9013 \end_inset
9014
9015
9016 \series default
9017   The compiler will not overlay parameters and local variables of any function,
9018  see section Parameters and local variables for more details.
9019 \end_layout
9020
9021 \begin_layout List
9022 \labelwidthstring 00.00.0000
9023
9024 \series bold
9025 -
9026 \begin_inset ERT
9027 status collapsed
9028
9029 \begin_layout Standard
9030
9031
9032 \backslash
9033 /
9034 \end_layout
9035
9036 \end_inset
9037
9038 -no-peep
9039 \begin_inset LatexCommand \index{-\/-no-peep}
9040
9041 \end_inset
9042
9043
9044 \series default
9045  Disable peep-hole optimization with built-in rules.
9046 \end_layout
9047
9048 \begin_layout List
9049 \labelwidthstring 00.00.0000
9050
9051 \series bold
9052 -
9053 \begin_inset ERT
9054 status collapsed
9055
9056 \begin_layout Standard
9057
9058
9059 \backslash
9060 /
9061 \end_layout
9062
9063 \end_inset
9064
9065 -peep-file
9066 \series default
9067
9068 \begin_inset LatexCommand \index{-\/-peep-file}
9069
9070 \end_inset
9071
9072 \InsetSpace ~
9073 <filename> This option can be used to use additional rules to be used by
9074  the peep hole optimizer.
9075  See section 
9076 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
9077
9078 \end_inset
9079
9080 \InsetSpace ~
9081 Peep Hole optimizations for details on how to write these rules.
9082 \end_layout
9083
9084 \begin_layout List
9085 \labelwidthstring 00.00.0000
9086
9087 \series bold
9088 -
9089 \begin_inset ERT
9090 status collapsed
9091
9092 \begin_layout Standard
9093
9094
9095 \backslash
9096 /
9097 \end_layout
9098
9099 \end_inset
9100
9101 -peep-asm
9102 \begin_inset LatexCommand \index{-\/-peep-asm}
9103
9104 \end_inset
9105
9106
9107 \series default
9108  Pass the inline assembler code through the peep hole optimizer.
9109  This can cause unexpected changes to inline assembler code, please go through
9110  the peephole optimizer
9111 \begin_inset LatexCommand \index{Peephole optimizer}
9112
9113 \end_inset
9114
9115  rules defined in the source file tree '<target>/peeph.def' before using
9116  this option.
9117 \end_layout
9118
9119 \begin_layout List
9120 \labelwidthstring 00.00.0000
9121
9122 \series bold
9123 -
9124 \begin_inset ERT
9125 status collapsed
9126
9127 \begin_layout Standard
9128
9129
9130 \backslash
9131 /
9132 \end_layout
9133
9134 \end_inset
9135
9136 -opt-code-speed
9137 \begin_inset LatexCommand \index{-\/-opt-code-speed}
9138
9139 \end_inset
9140
9141
9142 \series default
9143  The compiler will optimize code generation towards fast code, possibly
9144  at the expense of code size.
9145 \end_layout
9146
9147 \begin_layout List
9148 \labelwidthstring 00.00.0000
9149
9150 \series bold
9151 -
9152 \begin_inset ERT
9153 status collapsed
9154
9155 \begin_layout Standard
9156
9157
9158 \backslash
9159 /
9160 \end_layout
9161
9162 \end_inset
9163
9164 -opt-code-size
9165 \begin_inset LatexCommand \index{-\/-opt-code-size}
9166
9167 \end_inset
9168
9169
9170 \series default
9171  The compiler will optimize code generation towards compact code, possibly
9172  at the expense of code speed.
9173 \end_layout
9174
9175 \begin_layout Standard
9176 \begin_inset VSpace bigskip
9177 \end_inset
9178
9179
9180 \end_layout
9181
9182 \begin_layout Subsection
9183 Other Options
9184 \begin_inset LatexCommand \index{Options other}
9185
9186 \end_inset
9187
9188
9189 \end_layout
9190
9191 \begin_layout List
9192 \labelwidthstring 00.00.0000
9193
9194 \series bold
9195 -c\InsetSpace ~
9196 -
9197 \begin_inset ERT
9198 status collapsed
9199
9200 \begin_layout Standard
9201
9202
9203 \backslash
9204 /
9205 \end_layout
9206
9207 \end_inset
9208
9209 -compile-only
9210 \begin_inset LatexCommand \index{-\/-compile-only}
9211
9212 \end_inset
9213
9214
9215 \begin_inset LatexCommand \index{-c -\/-compile-only}
9216
9217 \end_inset
9218
9219
9220 \series default
9221  will compile and assemble the source, but will not call the linkage editor.
9222 \end_layout
9223
9224 \begin_layout List
9225 \labelwidthstring 00.00.0000
9226
9227 \series bold
9228 -
9229 \series default
9230
9231 \begin_inset ERT
9232 status collapsed
9233
9234 \begin_layout Standard
9235
9236
9237 \backslash
9238 /
9239 \end_layout
9240
9241 \end_inset
9242
9243
9244 \series bold
9245 -c1mode
9246 \begin_inset LatexCommand \index{-\/-c1mode}
9247
9248 \end_inset
9249
9250
9251 \series default
9252  reads the preprocessed source from standard input and compiles it.
9253  The file name for the assembler output must be specified using the -o option.
9254 \end_layout
9255
9256 \begin_layout List
9257 \labelwidthstring 00.00.0000
9258
9259 \series bold
9260 -E
9261 \begin_inset LatexCommand \index{-E}
9262
9263 \end_inset
9264
9265
9266 \series default
9267  Run only the C preprocessor.
9268  Preprocess all the C source files specified and output the results to standard
9269  output.
9270 \end_layout
9271
9272 \begin_layout List
9273 \labelwidthstring 00.00.0000
9274
9275 \series bold
9276 -o\InsetSpace ~
9277 <path/file>
9278 \begin_inset LatexCommand \index{-o <path/file>}
9279
9280 \end_inset
9281
9282  
9283 \series default
9284 The output path where everything will be placed or the file name used for
9285  all generated output files.
9286  If the parameter is a path, it must have a trailing slash (or backslash
9287  for the Windows binaries) to be recognized as a path.
9288
9289 \emph on
9290  
9291 \emph default
9292 Note for Windows users: if the path contains spaces, it should be surrounded
9293  by quotes.
9294  The trailing backslash should be doubled in order to prevent escaping the
9295  final quote, for example: 
9296 \emph on
9297 -o 
9298 \begin_inset Quotes sld
9299 \end_inset
9300
9301 F:
9302 \backslash
9303 Projects
9304 \backslash
9305 test3
9306 \backslash
9307 output 1
9308 \backslash
9309
9310 \backslash
9311
9312 \begin_inset Quotes srd
9313 \end_inset
9314
9315
9316 \emph default
9317  or put after the final quote, for example: 
9318 \emph on
9319 -o 
9320 \begin_inset Quotes sld
9321 \end_inset
9322
9323 F:
9324 \backslash
9325 Projects
9326 \backslash
9327 test3
9328 \backslash
9329 output 1
9330 \begin_inset Quotes srd
9331 \end_inset
9332
9333
9334 \backslash
9335
9336 \emph default
9337 .
9338  The path using slashes for directory delimiters can be used too, for example:
9339  
9340 \emph on
9341 -o 
9342 \begin_inset Quotes sld
9343 \end_inset
9344
9345 F:/Projects/test3/output 1/
9346 \begin_inset Quotes srd
9347 \end_inset
9348
9349
9350 \emph default
9351 .
9352 \end_layout
9353
9354 \begin_layout List
9355 \labelwidthstring 00.00.0000
9356
9357 \series bold
9358 -
9359 \begin_inset ERT
9360 status collapsed
9361
9362 \begin_layout Standard
9363
9364
9365 \backslash
9366 /
9367 \end_layout
9368
9369 \end_inset
9370
9371 -stack-auto
9372 \begin_inset LatexCommand \index{-\/-stack-auto}
9373
9374 \end_inset
9375
9376
9377 \series default
9378 \size large
9379 \emph on
9380  
9381 \size default
9382 \emph default
9383 All functions in the source file will be compiled as 
9384 \emph on
9385 reentrant
9386 \emph default
9387
9388 \begin_inset LatexCommand \index{reentrant}
9389
9390 \end_inset
9391
9392 , i.e.
9393  the parameters and local variables will be allocated on the stack
9394 \begin_inset LatexCommand \index{stack}
9395
9396 \end_inset
9397
9398 .
9399  See section 
9400 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9401
9402 \end_inset
9403
9404  Parameters and Local Variables for more details.
9405  If this option is used all source files in the project should be compiled
9406  with this option.
9407  It automatically implies --int-long-reent and --float-reent.
9408  
9409 \end_layout
9410
9411 \begin_layout List
9412 \labelwidthstring 00.00.0000
9413
9414 \series bold
9415 -
9416 \begin_inset ERT
9417 status collapsed
9418
9419 \begin_layout Standard
9420
9421
9422 \backslash
9423 /
9424 \end_layout
9425
9426 \end_inset
9427
9428 -callee-saves
9429 \begin_inset LatexCommand \index{-\/-callee-saves}
9430
9431 \end_inset
9432
9433  
9434 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9435
9436 \end_inset
9437
9438 function1[,function2][,function3]....
9439
9440 \series default
9441  The compiler by default uses a caller saves convention for register saving
9442  across function calls, however this can cause unnecessary register pushing
9443  and popping when calling small functions from larger functions.
9444  This option can be used to switch the register saving convention for the
9445  function names specified.
9446  The compiler will not save registers when calling these functions, no extra
9447  code will be generated at the entry and exit (function prologue
9448 \series bold
9449
9450 \begin_inset LatexCommand \index{function prologue}
9451
9452 \end_inset
9453
9454
9455 \series default
9456  and epilogue
9457 \series bold
9458
9459 \begin_inset LatexCommand \index{function epilogue}
9460
9461 \end_inset
9462
9463
9464 \series default
9465 ) for these functions to save and restore the registers used by these functions,
9466  this can SUBSTANTIALLY reduce code and improve run time performance of
9467  the generated code.
9468  In the future the compiler (with inter procedural analysis) will be able
9469  to determine the appropriate scheme to use for each function call.
9470  DO NOT use this option for built-in functions such as _mulint..., if this
9471  option is used for a library function the appropriate library function
9472  needs to be recompiled with the same option.
9473  If the project consists of multiple source files then all the source file
9474  should be compiled with the same -
9475 \begin_inset ERT
9476 status collapsed
9477
9478 \begin_layout Standard
9479
9480
9481 \backslash
9482 /
9483 \end_layout
9484
9485 \end_inset
9486
9487 -callee-saves option string.
9488  Also see #pragma\InsetSpace ~
9489 callee_saves 
9490 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9491
9492 \end_inset
9493
9494  
9495 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9496
9497 \end_inset
9498
9499 .
9500 \end_layout
9501
9502 \begin_layout List
9503 \labelwidthstring 00.00.0000
9504
9505 \series bold
9506 -
9507 \begin_inset ERT
9508 status collapsed
9509
9510 \begin_layout Standard
9511
9512
9513 \backslash
9514 /
9515 \end_layout
9516
9517 \end_inset
9518
9519 -all-callee-saves
9520 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9521
9522 \end_inset
9523
9524  
9525 \series default
9526 Function of
9527 \series bold
9528  
9529 \series default
9530 -
9531 \begin_inset ERT
9532 status collapsed
9533
9534 \begin_layout Standard
9535
9536
9537 \backslash
9538 /
9539 \end_layout
9540
9541 \end_inset
9542
9543 -callee-saves will be applied to all functions by default.
9544 \end_layout
9545
9546 \begin_layout List
9547 \labelwidthstring 00.00.0000
9548
9549 \series bold
9550 -
9551 \begin_inset ERT
9552 status collapsed
9553
9554 \begin_layout Standard
9555
9556
9557 \backslash
9558 /
9559 \end_layout
9560
9561 \end_inset
9562
9563 -debug
9564 \begin_inset LatexCommand \index{-\/-debug}
9565
9566 \end_inset
9567
9568
9569 \bar under
9570  
9571 \series default
9572 \bar default
9573 When this option is used the compiler will generate debug information.
9574  The debug information collected in a file with .cdb extension can be used
9575  with the SDCDB.
9576  For more information see documentation for SDCDB.
9577  Another file with no extension contains debug information in AOMF or AOMF51
9578 \begin_inset LatexCommand \index{AOMF, AOMF51}
9579
9580 \end_inset
9581
9582  format which is commonly used by third party tools.
9583 \end_layout
9584
9585 \begin_layout List
9586 \labelwidthstring 00.00.0000
9587
9588 \series bold
9589 -S
9590 \begin_inset LatexCommand \index{-S}
9591
9592 \end_inset
9593
9594
9595 \size large
9596 \bar under
9597  
9598 \series default
9599 \size default
9600 \bar default
9601 Stop after the stage of compilation proper; do not assemble.
9602  The output is an assembler code file for the input file specified.
9603 \end_layout
9604
9605 \begin_layout List
9606 \labelwidthstring 00.00.0000
9607
9608 \series bold
9609 -
9610 \begin_inset ERT
9611 status collapsed
9612
9613 \begin_layout Standard
9614
9615
9616 \backslash
9617 /
9618 \end_layout
9619
9620 \end_inset
9621
9622 -int-long-reent
9623 \begin_inset LatexCommand \index{-\/-int-long-reent}
9624
9625 \end_inset
9626
9627
9628 \series default
9629  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9630  Note by default these libraries are compiled as non-reentrant.
9631  See section Installation for more details.
9632 \end_layout
9633
9634 \begin_layout List
9635 \labelwidthstring 00.00.0000
9636
9637 \series bold
9638 -
9639 \begin_inset ERT
9640 status collapsed
9641
9642 \begin_layout Standard
9643
9644
9645 \backslash
9646 /
9647 \end_layout
9648
9649 \end_inset
9650
9651 -cyclomatic
9652 \begin_inset LatexCommand \index{-\/-cyclomatic}
9653
9654 \end_inset
9655
9656
9657 \bar under
9658  
9659 \series default
9660 \bar default
9661 This option will cause the compiler to generate an information message for
9662  each function in the source file.
9663  The message contains some 
9664 \emph on
9665 important
9666 \emph default
9667  information about the function.
9668  The number of edges and nodes the compiler detected in the control flow
9669  graph of the function, and most importantly the 
9670 \emph on
9671 cyclomatic complexity
9672 \begin_inset LatexCommand \index{Cyclomatic complexity}
9673
9674 \end_inset
9675
9676
9677 \emph default
9678  see section on Cyclomatic Complexity for more details.
9679 \end_layout
9680
9681 \begin_layout List
9682 \labelwidthstring 00.00.0000
9683
9684 \series bold
9685 -
9686 \begin_inset ERT
9687 status collapsed
9688
9689 \begin_layout Standard
9690
9691
9692 \backslash
9693 /
9694 \end_layout
9695
9696 \end_inset
9697
9698 -float-reent
9699 \begin_inset LatexCommand \index{-\/-float-reent}
9700
9701 \end_inset
9702
9703
9704 \series default
9705  Floating point library is compiled as reentrant
9706 \begin_inset LatexCommand \index{reentrant}
9707
9708 \end_inset
9709
9710 .
9711  See section Installation for more details.
9712 \end_layout
9713
9714 \begin_layout List
9715 \labelwidthstring 00.00.0000
9716
9717 \series bold
9718 -
9719 \begin_inset ERT
9720 status collapsed
9721
9722 \begin_layout Standard
9723
9724
9725 \backslash
9726 /
9727 \end_layout
9728
9729 \end_inset
9730
9731 -funsigned-char
9732 \begin_inset LatexCommand \index{-\/-funsigned-char}
9733
9734 \end_inset
9735
9736
9737 \series default
9738  The default signedness for every type is
9739 \family typewriter
9740  signed
9741 \family default
9742 .
9743  In some embedded environments the default signedness of
9744 \family typewriter
9745  char
9746 \family default
9747  is
9748 \family typewriter
9749  unsigned
9750 \family default
9751 .
9752  To set the signess for characters to unsigned, use the option --funsigned-char.
9753  If this option is set and no signedness keyword (unsigned/signed) is given,
9754  a char will be signed.
9755  All other types are unaffected.
9756 \end_layout
9757
9758 \begin_layout List
9759 \labelwidthstring 00.00.0000
9760
9761 \series bold
9762 -
9763 \begin_inset ERT
9764 status collapsed
9765
9766 \begin_layout Standard
9767
9768
9769 \backslash
9770 /
9771 \end_layout
9772
9773 \end_inset
9774
9775 -main-return
9776 \begin_inset LatexCommand \index{-\/-main-return}
9777
9778 \end_inset
9779
9780
9781 \series default
9782  This option can be used if the code generated is called by a monitor program
9783  or if the main routine includes an endless loop.
9784  This option results in slightly smaller code and saves two bytes of stack
9785  space.
9786  The return from the 'main'
9787 \begin_inset LatexCommand \index{main return}
9788
9789 \end_inset
9790
9791  function will return to the function calling main.
9792  The default setting is to lock up i.e.
9793  generate a '
9794 \family typewriter
9795 sjmp .
9796 \family default
9797 '.
9798 \end_layout
9799
9800 \begin_layout List
9801 \labelwidthstring 00.00.0000
9802
9803 \series bold
9804 -
9805 \begin_inset ERT
9806 status collapsed
9807
9808 \begin_layout Standard
9809
9810
9811 \backslash
9812 /
9813 \end_layout
9814
9815 \end_inset
9816
9817 -nostdinc
9818 \begin_inset LatexCommand \index{-\/-nostdinc}
9819
9820 \end_inset
9821
9822
9823 \series default
9824  This will prevent the compiler from passing on the default include path
9825  to the preprocessor.
9826 \end_layout
9827
9828 \begin_layout List
9829 \labelwidthstring 00.00.0000
9830
9831 \series bold
9832 -
9833 \begin_inset ERT
9834 status collapsed
9835
9836 \begin_layout Standard
9837
9838
9839 \backslash
9840 /
9841 \end_layout
9842
9843 \end_inset
9844
9845 -nostdlib
9846 \begin_inset LatexCommand \index{-\/-nostdlib}
9847
9848 \end_inset
9849
9850
9851 \series default
9852  This will prevent the compiler from passing on the default library
9853 \begin_inset LatexCommand \index{Libraries}
9854
9855 \end_inset
9856
9857  path to the linker.
9858 \end_layout
9859
9860 \begin_layout List
9861 \labelwidthstring 00.00.0000
9862
9863 \series bold
9864 -
9865 \begin_inset ERT
9866 status collapsed
9867
9868 \begin_layout Standard
9869
9870
9871 \backslash
9872 /
9873 \end_layout
9874
9875 \end_inset
9876
9877 -verbose
9878 \begin_inset LatexCommand \index{-\/-verbose}
9879
9880 \end_inset
9881
9882
9883 \series default
9884  Shows the various actions the compiler is performing.
9885 \end_layout
9886
9887 \begin_layout List
9888 \labelwidthstring 00.00.0000
9889
9890 \series bold
9891 -V
9892 \begin_inset LatexCommand \index{-V}
9893
9894 \end_inset
9895
9896
9897 \series default
9898  Shows the actual commands the compiler is executing.
9899 \end_layout
9900
9901 \begin_layout List
9902 \labelwidthstring 00.00.0000
9903
9904 \series bold
9905 -
9906 \begin_inset ERT
9907 status collapsed
9908
9909 \begin_layout Standard
9910
9911
9912 \backslash
9913 /
9914 \end_layout
9915
9916 \end_inset
9917
9918 -no-c-code-in-asm
9919 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
9920
9921 \end_inset
9922
9923
9924 \series default
9925  Hides your ugly and inefficient c-code from the asm file, so you can always
9926  blame the compiler :)
9927 \end_layout
9928
9929 \begin_layout List
9930 \labelwidthstring 00.00.0000
9931
9932 \series bold
9933 -
9934 \begin_inset ERT
9935 status collapsed
9936
9937 \begin_layout Standard
9938
9939
9940 \backslash
9941 /
9942 \end_layout
9943
9944 \end_inset
9945
9946 -fverbose-asm
9947 \begin_inset LatexCommand \index{-\/-no-gen-comments}
9948
9949 \end_inset
9950
9951
9952 \series default
9953  Include code generator and peep-hole comments in the generated asm files.
9954 \end_layout
9955
9956 \begin_layout List
9957 \labelwidthstring 00.00.0000
9958
9959 \series bold
9960 -
9961 \begin_inset ERT
9962 status collapsed
9963
9964 \begin_layout Standard
9965
9966
9967 \backslash
9968 /
9969 \end_layout
9970
9971 \end_inset
9972
9973 -no-peep-comments
9974 \begin_inset LatexCommand \index{-\/-no-peep-comments}
9975
9976 \end_inset
9977
9978
9979 \series default
9980  Don't include peep-hole comments in the generated asm files even if --fverbose-
9981 asm option is specified.
9982 \end_layout
9983
9984 \begin_layout List
9985 \labelwidthstring 00.00.0000
9986
9987 \series bold
9988 -
9989 \begin_inset ERT
9990 status collapsed
9991
9992 \begin_layout Standard
9993
9994
9995 \backslash
9996 /
9997 \end_layout
9998
9999 \end_inset
10000
10001 -i-code-in-asm
10002 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
10003
10004 \end_inset
10005
10006
10007 \series default
10008  Include i-codes in the asm file.
10009  Sounds like noise but is most helpful for debugging the compiler itself.
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 -less-pedantic
10030 \begin_inset LatexCommand \index{pedantic}
10031
10032 \end_inset
10033
10034
10035 \begin_inset LatexCommand \index{-\/-less-pedantic}
10036
10037 \end_inset
10038
10039
10040 \series default
10041
10042 \begin_inset LatexCommand \label{lyx:--less-pedantic}
10043
10044 \end_inset
10045
10046  Disable some of the more pedantic warnings
10047 \begin_inset LatexCommand \index{Warnings}
10048
10049 \end_inset
10050
10051 .
10052  For more details, see the less_pedantic pragma 
10053 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
10054
10055 \end_inset
10056
10057 .
10058 \end_layout
10059
10060 \begin_layout List
10061 \labelwidthstring 00.00.0000
10062
10063 \series bold
10064 -
10065 \begin_inset ERT
10066 status collapsed
10067
10068 \begin_layout Standard
10069
10070
10071 \backslash
10072 /
10073 \end_layout
10074
10075 \end_inset
10076
10077 -disable-warning\InsetSpace ~
10078 <nnnn>
10079 \begin_inset LatexCommand \index{-\/-disable-warning}
10080
10081 \end_inset
10082
10083
10084 \series default
10085  Disable specific warning with number <nnnn>.
10086 \end_layout
10087
10088 \begin_layout List
10089 \labelwidthstring 00.00.0000
10090
10091 \series bold
10092 -
10093 \begin_inset ERT
10094 status collapsed
10095
10096 \begin_layout Standard
10097
10098
10099 \backslash
10100 /
10101 \end_layout
10102
10103 \end_inset
10104
10105 -print-search-dirs
10106 \begin_inset LatexCommand \index{-\/-print-search-dirs}
10107
10108 \end_inset
10109
10110
10111 \series default
10112  Display the directories in the compiler's search path
10113 \end_layout
10114
10115 \begin_layout List
10116 \labelwidthstring 00.00.0000
10117
10118 \series bold
10119 -
10120 \begin_inset ERT
10121 status collapsed
10122
10123 \begin_layout Standard
10124
10125
10126 \backslash
10127 /
10128 \end_layout
10129
10130 \end_inset
10131
10132 -vc
10133 \begin_inset LatexCommand \index{-\/-vc}
10134
10135 \end_inset
10136
10137
10138 \series default
10139  Display errors and warnings using MSVC style, so you can use SDCC with
10140  the visual studio IDE
10141 \begin_inset LatexCommand \index{IDE}
10142
10143 \end_inset
10144
10145 .
10146  With SDCC both offering a GCC-like (the default) and a MSVC-like
10147 \begin_inset LatexCommand \index{MSVC output style}
10148
10149 \end_inset
10150
10151  output style, integration into most programming editors should be straightforwa
10152 rd.
10153 \end_layout
10154
10155 \begin_layout List
10156 \labelwidthstring 00.00.0000
10157
10158 \series bold
10159 -
10160 \begin_inset ERT
10161 status collapsed
10162
10163 \begin_layout Standard
10164
10165
10166 \backslash
10167 /
10168 \end_layout
10169
10170 \end_inset
10171
10172 -use-stdout
10173 \begin_inset LatexCommand \index{-\/-use-stdout}
10174
10175 \end_inset
10176
10177
10178 \series default
10179  Send errors and warnings to stdout instead of stderr.
10180 \end_layout
10181
10182 \begin_layout List
10183 \labelwidthstring 00.00.0000
10184
10185 \series bold
10186 -Wa\InsetSpace ~
10187 asmOption[,asmOption]
10188 \series default
10189
10190 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
10191
10192 \end_inset
10193
10194 ...
10195  Pass the asmOption to the assembler
10196 \begin_inset LatexCommand \index{Options assembler}
10197
10198 \end_inset
10199
10200
10201 \begin_inset LatexCommand \index{Assembler options}
10202
10203 \end_inset
10204
10205 .
10206  See file sdcc/as/doc/asxhtm.html for assembler options.cd
10207 \end_layout
10208
10209 \begin_layout List
10210 \labelwidthstring 00.00.0000
10211
10212 \series bold
10213 -
10214 \begin_inset ERT
10215 status collapsed
10216
10217 \begin_layout Standard
10218
10219
10220 \backslash
10221 /
10222 \end_layout
10223
10224 \end_inset
10225
10226 -std-sdcc89
10227 \begin_inset LatexCommand \index{-\/-std-sdcc89}
10228
10229 \end_inset
10230
10231
10232 \series default
10233  Generally follow the C89 standard, but allow SDCC features that conflict
10234  with the standard (default).
10235 \end_layout
10236
10237 \begin_layout List
10238 \labelwidthstring 00.00.0000
10239
10240 \series bold
10241 -
10242 \begin_inset ERT
10243 status collapsed
10244
10245 \begin_layout Standard
10246
10247
10248 \backslash
10249 /
10250 \end_layout
10251
10252 \end_inset
10253
10254 -std-c89
10255 \begin_inset LatexCommand \index{-\/-std-c89}
10256
10257 \end_inset
10258
10259
10260 \series default
10261  Follow the C89 standard and disable SDCC features that conflict with the
10262  standard.
10263 \end_layout
10264
10265 \begin_layout List
10266 \labelwidthstring 00.00.0000
10267
10268 \series bold
10269 -
10270 \begin_inset ERT
10271 status collapsed
10272
10273 \begin_layout Standard
10274
10275
10276 \backslash
10277 /
10278 \end_layout
10279
10280 \end_inset
10281
10282 -std-sdcc99
10283 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10284
10285 \end_inset
10286
10287
10288 \series default
10289  Generally follow the C99 standard, but allow SDCC features that conflict
10290  with the standard (incomplete support).
10291 \end_layout
10292
10293 \begin_layout List
10294 \labelwidthstring 00.00.0000
10295
10296 \series bold
10297 -
10298 \begin_inset ERT
10299 status collapsed
10300
10301 \begin_layout Standard
10302
10303
10304 \backslash
10305 /
10306 \end_layout
10307
10308 \end_inset
10309
10310 -std-c99
10311 \begin_inset LatexCommand \index{-\/-std-sdcc99}
10312
10313 \end_inset
10314
10315
10316 \series default
10317  Follow the C99 standard and disable SDCC features that conflict with the
10318  standard (incomplete support).
10319 \end_layout
10320
10321 \begin_layout List
10322 \labelwidthstring 00.00.0000
10323
10324 \series bold
10325 -
10326 \begin_inset ERT
10327 status collapsed
10328
10329 \begin_layout Standard
10330
10331
10332 \backslash
10333 /
10334 \end_layout
10335
10336 \end_inset
10337
10338 -codeseg
10339 \series default
10340
10341 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10342
10343 \end_inset
10344
10345 \InsetSpace ~
10346 <Name> The name to be used for the code
10347 \begin_inset LatexCommand \index{code}
10348
10349 \end_inset
10350
10351  segment, default CSEG.
10352  This is useful if you need to tell the compiler to put the code in a special
10353  segment so you can later on tell the linker to put this segment in a special
10354  place in memory.
10355  Can be used for instance when using bank switching to put the code in a
10356  bank.
10357 \end_layout
10358
10359 \begin_layout List
10360 \labelwidthstring 00.00.0000
10361
10362 \series bold
10363 -
10364 \begin_inset ERT
10365 status collapsed
10366
10367 \begin_layout Standard
10368
10369
10370 \backslash
10371 /
10372 \end_layout
10373
10374 \end_inset
10375
10376 -constseg
10377 \series default
10378
10379 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10380
10381 \end_inset
10382
10383 \InsetSpace ~
10384 <Name> The name to be used for the const
10385 \begin_inset LatexCommand \index{const}
10386
10387 \end_inset
10388
10389  segment, default CONST.
10390  This is useful if you need to tell the compiler to put the const data in
10391  a special segment so you can later on tell the linker to put this segment
10392  in a special place in memory.
10393  Can be used for instance when using bank switching to put the const data
10394  in a bank.
10395 \end_layout
10396
10397 \begin_layout List
10398 \labelwidthstring 00.00.0000
10399
10400 \series bold
10401 -
10402 \begin_inset ERT
10403 status collapsed
10404
10405 \begin_layout Standard
10406
10407
10408 \backslash
10409 /
10410 \end_layout
10411
10412 \end_inset
10413
10414 -fdollars-in-identifiers
10415 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10416
10417 \end_inset
10418
10419
10420 \series default
10421  Permit '$' as an identifier character.
10422 \end_layout
10423
10424 \begin_layout List
10425 \labelwidthstring 00.00.0000
10426
10427 \series bold
10428 -
10429 \begin_inset ERT
10430 status collapsed
10431
10432 \begin_layout Standard
10433
10434
10435 \backslash
10436 /
10437 \end_layout
10438
10439 \end_inset
10440
10441 -more-pedantic
10442 \series default
10443
10444 \begin_inset LatexCommand \index{-\/-more-pedantic}
10445
10446 \end_inset
10447
10448
10449 \begin_inset LatexCommand \index{pedantic}
10450
10451 \end_inset
10452
10453  Actually this is 
10454 \series bold
10455 \emph on
10456 not
10457 \series default
10458 \emph default
10459  a SDCC compiler option but if you want 
10460 \emph on
10461 more
10462 \emph default
10463  warnings you can use a separate tool dedicated to syntax checking like
10464  splint
10465 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10466
10467 \end_inset
10468
10469
10470 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10471
10472 \end_inset
10473
10474  
10475 \begin_inset LatexCommand \url{http://www.splint.org}
10476
10477 \end_inset
10478
10479 .
10480  To make your source files parseable by splint you will have to include
10481  
10482 \family sans
10483 lint.h
10484 \family default
10485
10486 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10487
10488 \end_inset
10489
10490  in your source file and add brackets around extended keywords (like 
10491 \family sans
10492
10493 \begin_inset Quotes sld
10494 \end_inset
10495
10496 __at\InsetSpace ~
10497
10498 \series bold
10499 (
10500 \series default
10501 0xab
10502 \series bold
10503 )
10504 \series default
10505
10506 \begin_inset Quotes srd
10507 \end_inset
10508
10509
10510 \family default
10511  and 
10512 \family sans
10513
10514 \begin_inset Quotes sld
10515 \end_inset
10516
10517 __interrupt\InsetSpace ~
10518 (2)
10519 \begin_inset Quotes srd
10520 \end_inset
10521
10522
10523 \family default
10524 ).
10525  
10526 \newline
10527 Splint has an excellent on line manual at 
10528 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10529
10530 \end_inset
10531
10532  and it's capabilities go beyond pure syntax checking.
10533  You'll need to tell splint the location of SDCC's include files so a typical
10534  command line could look like this: 
10535 \newline
10536
10537 \family sans
10538 splint\InsetSpace ~
10539 -I\InsetSpace ~
10540 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10541 \InsetSpace ~
10542 myprogram.c
10543 \end_layout
10544
10545 \begin_layout List
10546 \labelwidthstring 00.00.0000
10547
10548 \series bold
10549 -
10550 \begin_inset ERT
10551 status collapsed
10552
10553 \begin_layout Standard
10554
10555
10556 \backslash
10557 /
10558 \end_layout
10559
10560 \end_inset
10561
10562 -short-is-8bits
10563 \series default
10564
10565 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10566
10567 \end_inset
10568
10569
10570 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10571
10572 \end_inset
10573
10574  Treat short as 8-bit (for backward compatibility with older versions of
10575  compiler - see section 
10576 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10577
10578 \end_inset
10579
10580 )
10581 \end_layout
10582
10583 \begin_layout Standard
10584 \begin_inset VSpace bigskip
10585 \end_inset
10586
10587
10588 \end_layout
10589
10590 \begin_layout Subsection
10591 Intermediate Dump Options
10592 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10593
10594 \end_inset
10595
10596
10597 \begin_inset LatexCommand \index{Options intermediate dump}
10598
10599 \end_inset
10600
10601
10602 \begin_inset LatexCommand \index{Intermediate dump options}
10603
10604 \end_inset
10605
10606
10607 \end_layout
10608
10609 \begin_layout Standard
10610 The following options are provided for the purpose of retargetting and debugging
10611  the compiler.
10612  They provide a means to dump the intermediate code (iCode
10613 \begin_inset LatexCommand \index{iCode}
10614
10615 \end_inset
10616
10617 ) generated by the compiler in human readable form at various stages of
10618  the compilation process.
10619  More on iCodes see chapter 
10620 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10621
10622 \end_inset
10623
10624  
10625 \begin_inset Quotes srd
10626 \end_inset
10627
10628 The anatomy of the compiler
10629 \begin_inset Quotes srd
10630 \end_inset
10631
10632 .
10633 \end_layout
10634
10635 \begin_layout List
10636 \labelwidthstring 00.00.0000
10637
10638 \series bold
10639 -
10640 \begin_inset ERT
10641 status collapsed
10642
10643 \begin_layout Standard
10644
10645
10646 \backslash
10647 /
10648 \end_layout
10649
10650 \end_inset
10651
10652 -dumpraw
10653 \begin_inset LatexCommand \index{-\/-dumpraw}
10654
10655 \end_inset
10656
10657
10658 \series default
10659  This option will cause the compiler to dump the intermediate code into
10660  a file of named 
10661 \emph on
10662 <source filename>.dumpraw
10663 \emph default
10664  just after the intermediate code has been generated for a function, i.e.
10665  before any optimizations are done.
10666  The basic blocks
10667 \begin_inset LatexCommand \index{Basic blocks}
10668
10669 \end_inset
10670
10671  at this stage ordered in the depth first number, so they may not be in
10672  sequence of execution.
10673 \end_layout
10674
10675 \begin_layout List
10676 \labelwidthstring 00.00.0000
10677
10678 \series bold
10679 -
10680 \begin_inset ERT
10681 status collapsed
10682
10683 \begin_layout Standard
10684
10685
10686 \backslash
10687 /
10688 \end_layout
10689
10690 \end_inset
10691
10692 -dumpgcse
10693 \begin_inset LatexCommand \index{-\/-dumpgcse}
10694
10695 \end_inset
10696
10697
10698 \series default
10699  Will create a dump of iCode's, after global subexpression elimination
10700 \begin_inset LatexCommand \index{Global subexpression elimination}
10701
10702 \end_inset
10703
10704 , into a file named 
10705 \emph on
10706 <source filename>.dumpgcse.
10707 \end_layout
10708
10709 \begin_layout List
10710 \labelwidthstring 00.00.0000
10711
10712 \series bold
10713 -
10714 \begin_inset ERT
10715 status collapsed
10716
10717 \begin_layout Standard
10718
10719
10720 \backslash
10721 /
10722 \end_layout
10723
10724 \end_inset
10725
10726 -dumpdeadcode
10727 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
10728
10729 \end_inset
10730
10731
10732 \series default
10733  Will create a dump of iCode's, after deadcode elimination
10734 \begin_inset LatexCommand \index{Dead-code elimination}
10735
10736 \end_inset
10737
10738 , into a file named 
10739 \emph on
10740 <source filename>.dumpdeadcode.
10741 \end_layout
10742
10743 \begin_layout List
10744 \labelwidthstring 00.00.0000
10745
10746 \series bold
10747 -
10748 \begin_inset ERT
10749 status collapsed
10750
10751 \begin_layout Standard
10752
10753
10754 \backslash
10755 /
10756 \end_layout
10757
10758 \end_inset
10759
10760 -dumploop
10761 \begin_inset LatexCommand \index{-\/-dumploop}
10762
10763 \end_inset
10764
10765
10766 \series default
10767 \size large
10768  
10769 \size default
10770 Will create a dump of iCode's, after loop optimizations
10771 \begin_inset LatexCommand \index{Loop optimization}
10772
10773 \end_inset
10774
10775 , into a file named 
10776 \emph on
10777 <source filename>.dumploop.
10778 \end_layout
10779
10780 \begin_layout List
10781 \labelwidthstring 00.00.0000
10782
10783 \series bold
10784 -
10785 \begin_inset ERT
10786 status collapsed
10787
10788 \begin_layout Standard
10789
10790
10791 \backslash
10792 /
10793 \end_layout
10794
10795 \end_inset
10796
10797 -dumprange
10798 \begin_inset LatexCommand \index{-\/-dumprange}
10799
10800 \end_inset
10801
10802
10803 \series default
10804 \size large
10805  
10806 \size default
10807 Will create a dump of iCode's, after live range analysis
10808 \begin_inset LatexCommand \index{Live range analysis}
10809
10810 \end_inset
10811
10812 , into a file named 
10813 \emph on
10814 <source filename>.dumprange.
10815 \end_layout
10816
10817 \begin_layout List
10818 \labelwidthstring 00.00.0000
10819
10820 \series bold
10821 -
10822 \begin_inset ERT
10823 status collapsed
10824
10825 \begin_layout Standard
10826
10827
10828 \backslash
10829 /
10830 \end_layout
10831
10832 \end_inset
10833
10834 -dumlrange
10835 \begin_inset LatexCommand \index{-\/-dumlrange}
10836
10837 \end_inset
10838
10839
10840 \series default
10841  Will dump the life ranges
10842 \begin_inset LatexCommand \index{Live range analysis}
10843
10844 \end_inset
10845
10846  for all symbols.
10847 \end_layout
10848
10849 \begin_layout List
10850 \labelwidthstring 00.00.0000
10851
10852 \series bold
10853 -
10854 \begin_inset ERT
10855 status collapsed
10856
10857 \begin_layout Standard
10858
10859
10860 \backslash
10861 /
10862 \end_layout
10863
10864 \end_inset
10865
10866 -dumpregassign
10867 \begin_inset LatexCommand \index{-\/-dumpregassign}
10868
10869 \end_inset
10870
10871
10872 \bar under
10873  
10874 \series default
10875 \bar default
10876 Will create a dump of iCode's, after register assignment
10877 \begin_inset LatexCommand \index{Register assignment}
10878
10879 \end_inset
10880
10881 , into a file named 
10882 \emph on
10883 <source filename>.dumprassgn.
10884 \end_layout
10885
10886 \begin_layout List
10887 \labelwidthstring 00.00.0000
10888
10889 \series bold
10890 -
10891 \begin_inset ERT
10892 status collapsed
10893
10894 \begin_layout Standard
10895
10896
10897 \backslash
10898 /
10899 \end_layout
10900
10901 \end_inset
10902
10903 -dumplrange
10904 \begin_inset LatexCommand \index{-\/-dumplrange}
10905
10906 \end_inset
10907
10908
10909 \series default
10910  Will create a dump of the live ranges of iTemp's
10911 \end_layout
10912
10913 \begin_layout List
10914 \labelwidthstring 00.00.0000
10915
10916 \series bold
10917 -
10918 \begin_inset ERT
10919 status collapsed
10920
10921 \begin_layout Standard
10922
10923
10924 \backslash
10925 /
10926 \end_layout
10927
10928 \end_inset
10929
10930 -dumpall
10931 \begin_inset LatexCommand \index{-\/-dumpall}
10932
10933 \end_inset
10934
10935
10936 \size large
10937 \bar under
10938  
10939 \series default
10940 \size default
10941 \bar default
10942 Will cause all the above mentioned dumps to be created.
10943 \end_layout
10944
10945 \begin_layout Standard
10946 \begin_inset VSpace bigskip
10947 \end_inset
10948
10949
10950 \end_layout
10951
10952 \begin_layout Subsection
10953 Redirecting output on Windows Shells
10954 \end_layout
10955
10956 \begin_layout Standard
10957 By default SDCC writes it's error messages to 
10958 \begin_inset Quotes sld
10959 \end_inset
10960
10961 standard error
10962 \begin_inset Quotes srd
10963 \end_inset
10964
10965 .
10966  To force all messages to 
10967 \begin_inset Quotes sld
10968 \end_inset
10969
10970 standard output
10971 \begin_inset Quotes srd
10972 \end_inset
10973
10974  use 
10975 \series bold
10976 -
10977 \series default
10978 \emph on
10979
10980 \begin_inset ERT
10981 status collapsed
10982
10983 \begin_layout Standard
10984
10985
10986 \backslash
10987 /
10988 \end_layout
10989
10990 \end_inset
10991
10992
10993 \series bold
10994 \emph default
10995 -
10996 \series default
10997 use-stdout
10998 \begin_inset LatexCommand \index{-\/-use-stdout}
10999
11000 \end_inset
11001
11002 .
11003  Additionally, if you happen to have visual studio installed in your windows
11004  machine, you can use it to compile your sources using a custom build and
11005  the SDCC -
11006 \emph on
11007
11008 \begin_inset ERT
11009 status collapsed
11010
11011 \begin_layout Standard
11012
11013
11014 \backslash
11015 /
11016 \end_layout
11017
11018 \end_inset
11019
11020
11021 \emph default
11022 -vc
11023 \begin_inset LatexCommand \index{-\/-vc}
11024
11025 \end_inset
11026
11027  option.
11028  Something like this should work:
11029 \newline
11030
11031 \newline
11032
11033 \series bold
11034 c:
11035 \backslash
11036 sdcc
11037 \backslash
11038 bin
11039 \backslash
11040 sdcc.exe -
11041 \series default
11042 \emph on
11043
11044 \begin_inset ERT
11045 status collapsed
11046
11047 \begin_layout Standard
11048
11049
11050 \backslash
11051 /
11052 \end_layout
11053
11054 \end_inset
11055
11056
11057 \series bold
11058 \emph default
11059 -vc -
11060 \series default
11061 \emph on
11062
11063 \begin_inset ERT
11064 status collapsed
11065
11066 \begin_layout Standard
11067
11068
11069 \backslash
11070 /
11071 \end_layout
11072
11073 \end_inset
11074
11075
11076 \series bold
11077 \emph default
11078 -model-large -c $(InputPath)
11079 \series default
11080
11081 \begin_inset VSpace bigskip
11082 \end_inset
11083
11084
11085 \end_layout
11086
11087 \begin_layout Section
11088 Environment variables
11089 \begin_inset LatexCommand \index{Environment variables}
11090
11091 \end_inset
11092
11093
11094 \end_layout
11095
11096 \begin_layout Standard
11097 SDCC recognizes the following environment variables:
11098 \end_layout
11099
11100 \begin_layout List
11101 \labelwidthstring 00.00.0000
11102
11103 \series bold
11104 SDCC_LEAVE_SIGNALS
11105 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
11106
11107 \end_inset
11108
11109
11110 \series default
11111  SDCC installs a signal handler
11112 \begin_inset LatexCommand \index{signal handler}
11113
11114 \end_inset
11115
11116  to be able to delete temporary files after an user break (^C) or an exception.
11117  If this environment variable is set, SDCC won't install the signal handler
11118  in order to be able to debug SDCC.
11119 \end_layout
11120
11121 \begin_layout List
11122 \labelwidthstring 00.00.0000
11123
11124 \series bold
11125 TMP,\InsetSpace ~
11126 TEMP,\InsetSpace ~
11127 TMPDIR
11128 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
11129
11130 \end_inset
11131
11132
11133 \series default
11134  Path, where temporary files will be created.
11135  The order of the variables is the search order.
11136  In a standard *nix environment these variables are not set, and there's
11137  no need to set them.
11138  On Windows it's recommended to set one of them.
11139 \end_layout
11140
11141 \begin_layout List
11142 \labelwidthstring 00.00.0000
11143
11144 \series bold
11145 SDCC_HOME
11146 \begin_inset LatexCommand \index{SDCC\_HOME}
11147
11148 \end_inset
11149
11150
11151 \series default
11152  Path, see section 
11153 \begin_inset LatexCommand \ref{sub:Install-paths}
11154
11155 \end_inset
11156
11157 \InsetSpace ~
11158
11159 \begin_inset Quotes sld
11160 \end_inset
11161
11162  Install Paths
11163 \begin_inset Quotes srd
11164 \end_inset
11165
11166 .
11167 \end_layout
11168
11169 \begin_layout List
11170 \labelwidthstring 00.00.0000
11171
11172 \series bold
11173 SDCC_INCLUDE
11174 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
11175
11176 \end_inset
11177
11178
11179 \series default
11180  Path, see section 
11181 \begin_inset LatexCommand \ref{sub:Search-Paths}
11182
11183 \end_inset
11184
11185 \InsetSpace ~
11186
11187 \begin_inset Quotes sld
11188 \end_inset
11189
11190 Search Paths
11191 \begin_inset Quotes srd
11192 \end_inset
11193
11194 .
11195 \end_layout
11196
11197 \begin_layout List
11198 \labelwidthstring 00.00.0000
11199
11200 \series bold
11201 SDCC_LIB
11202 \begin_inset LatexCommand \index{SDCC\_LIB}
11203
11204 \end_inset
11205
11206
11207 \series default
11208  Path, see section 
11209 \begin_inset LatexCommand \ref{sub:Search-Paths}
11210
11211 \end_inset
11212
11213 \InsetSpace ~
11214
11215 \begin_inset Quotes sld
11216 \end_inset
11217
11218 Search Paths
11219 \begin_inset Quotes srd
11220 \end_inset
11221
11222 ..
11223 \end_layout
11224
11225 \begin_layout Standard
11226 There are some more environment variables recognized by SDCC, but these
11227  are solely used for debugging purposes.
11228  They can change or disappear very quickly, and will never be documented.
11229 \begin_inset VSpace bigskip
11230 \end_inset
11231
11232
11233 \end_layout
11234
11235 \begin_layout Section
11236 Storage Class Language Extensions
11237 \end_layout
11238
11239 \begin_layout Subsection
11240 MCS51/DS390 Storage Class
11241 \begin_inset LatexCommand \index{Storage class}
11242
11243 \end_inset
11244
11245  Language Extensions
11246 \end_layout
11247
11248 \begin_layout Standard
11249 In addition to the ANSI storage classes SDCC allows the following MCS51
11250  specific storage classes:
11251 \end_layout
11252
11253 \begin_layout Subsubsection
11254 data
11255 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11256
11257 \end_inset
11258
11259
11260 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11261
11262 \end_inset
11263
11264  / near
11265 \begin_inset LatexCommand \index{near (storage class)}
11266
11267 \end_inset
11268
11269
11270 \begin_inset LatexCommand \index{\_\_near (storage class)}
11271
11272 \end_inset
11273
11274
11275 \end_layout
11276
11277 \begin_layout Standard
11278 This is the 
11279 \series bold
11280 default
11281 \series default
11282  storage class for the Small Memory model (
11283 \emph on
11284 data
11285 \emph default
11286  and 
11287 \emph on
11288 near
11289 \emph default
11290  or the more ANSI-C compliant forms 
11291 \emph on
11292 __data
11293 \emph default
11294  and 
11295 \emph on
11296 __near
11297 \emph default
11298  can be used synonymously).
11299  Variables declared with this storage class will be allocated in the directly
11300  addressable portion of the internal RAM of a 8051, e.g.:
11301 \end_layout
11302
11303 \begin_layout Verse
11304
11305 \family typewriter
11306 __data unsigned char test_data;
11307 \end_layout
11308
11309 \begin_layout Standard
11310 Writing 0x01 to this variable generates the assembly code:
11311 \end_layout
11312
11313 \begin_layout Verse
11314
11315 \family typewriter
11316 75*00 01\InsetSpace ~
11317 \InsetSpace ~
11318 \InsetSpace ~
11319 mov\InsetSpace ~
11320 \InsetSpace ~
11321 _test_data,#0x01
11322 \end_layout
11323
11324 \begin_layout Subsubsection
11325 xdata
11326 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11327
11328 \end_inset
11329
11330
11331 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11332
11333 \end_inset
11334
11335  / far
11336 \begin_inset LatexCommand \index{far (storage class)}
11337
11338 \end_inset
11339
11340
11341 \begin_inset LatexCommand \index{\_\_far (storage class)}
11342
11343 \end_inset
11344
11345
11346 \end_layout
11347
11348 \begin_layout Standard
11349 Variables declared with this storage class will be placed in the external
11350  RAM.
11351  This is the 
11352 \series bold
11353 default
11354 \series default
11355  storage class for the Large Memory model, e.g.:
11356 \end_layout
11357
11358 \begin_layout Verse
11359
11360 \family typewriter
11361 __xdata unsigned char test_xdata;
11362 \end_layout
11363
11364 \begin_layout Standard
11365 Writing 0x01 to this variable generates the assembly code:
11366 \end_layout
11367
11368 \begin_layout Verse
11369
11370 \family typewriter
11371 90s00r00\InsetSpace ~
11372 \InsetSpace ~
11373 \InsetSpace ~
11374 mov\InsetSpace ~
11375 \InsetSpace ~
11376 dptr,#_test_xdata 
11377 \newline
11378 74\InsetSpace ~
11379 01\InsetSpace ~
11380 \InsetSpace ~
11381 \InsetSpace ~
11382 \InsetSpace ~
11383 \InsetSpace ~
11384 \InsetSpace ~
11385 mov\InsetSpace ~
11386 \InsetSpace ~
11387 a,#0x01 
11388 \newline
11389 F0\InsetSpace ~
11390 \InsetSpace ~
11391 \InsetSpace ~
11392 \InsetSpace ~
11393 \InsetSpace ~
11394 \InsetSpace ~
11395 \InsetSpace ~
11396 \InsetSpace ~
11397 \InsetSpace ~
11398 movx\InsetSpace ~
11399 @dptr,a 
11400 \end_layout
11401
11402 \begin_layout Subsubsection
11403 idata
11404 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11405
11406 \end_inset
11407
11408
11409 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11410
11411 \end_inset
11412
11413
11414 \end_layout
11415
11416 \begin_layout Standard
11417 Variables declared with this storage class will be allocated into the indirectly
11418  addressable portion of the internal ram of a 8051, e.g.:
11419 \end_layout
11420
11421 \begin_layout Verse
11422
11423 \family typewriter
11424 __idata unsigned char test_idata;
11425 \end_layout
11426
11427 \begin_layout Standard
11428 Writing 0x01 to this variable generates the assembly code:
11429 \end_layout
11430
11431 \begin_layout Verse
11432
11433 \family typewriter
11434 78r00\InsetSpace ~
11435 \InsetSpace ~
11436 \InsetSpace ~
11437 \InsetSpace ~
11438 \InsetSpace ~
11439 \InsetSpace ~
11440 \InsetSpace ~
11441 mov\InsetSpace ~
11442 \InsetSpace ~
11443 r0,#_test_idata
11444 \newline
11445 76\InsetSpace ~
11446 01\InsetSpace ~
11447 \InsetSpace ~
11448 \InsetSpace ~
11449 \InsetSpace ~
11450 \InsetSpace ~
11451 \InsetSpace ~
11452 \InsetSpace ~
11453 mov\InsetSpace ~
11454 \InsetSpace ~
11455 @r0,#0x01
11456 \end_layout
11457
11458 \begin_layout Standard
11459 Please note, the first 128 byte of idata physically access the same RAM
11460  as the data memory.
11461  The original 8051 had 128 byte idata memory, nowadays most devices have
11462  256 byte idata memory.
11463  The stack
11464 \begin_inset LatexCommand \index{stack}
11465
11466 \end_inset
11467
11468  is located in idata memory.
11469 \end_layout
11470
11471 \begin_layout Subsubsection
11472 pdata
11473 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11474
11475 \end_inset
11476
11477
11478 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11479
11480 \end_inset
11481
11482
11483 \end_layout
11484
11485 \begin_layout Standard
11486 Paged xdata access is just as straightforward as using the other addressing
11487  modes of a 8051.
11488  It is typically located at the start of xdata and has a maximum size of
11489  256 bytes.
11490  The following example writes 0x01 to the pdata variable.
11491  Please note, pdata access physically accesses xdata memory.
11492  The high byte of the address is determined by port P2 
11493 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11494
11495 \end_inset
11496
11497 (or in case of some 8051 variants by a separate Special Function Register,
11498  see section 
11499 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11500
11501 \end_inset
11502
11503 ).
11504  This is the 
11505 \series bold
11506 default
11507 \series default
11508  storage class for the Medium Memory model, e.g.:
11509 \end_layout
11510
11511 \begin_layout Verse
11512
11513 \family typewriter
11514 __pdata unsigned char test_pdata;
11515 \end_layout
11516
11517 \begin_layout Standard
11518 Writing 0x01 to this variable generates the assembly code:
11519 \end_layout
11520
11521 \begin_layout Verse
11522
11523 \family typewriter
11524 78r00\InsetSpace ~
11525 \InsetSpace ~
11526 \InsetSpace ~
11527 \InsetSpace ~
11528 \InsetSpace ~
11529 \InsetSpace ~
11530 mov r0,#_test_pdata
11531 \newline
11532 74 01\InsetSpace ~
11533 \InsetSpace ~
11534 \InsetSpace ~
11535 \InsetSpace ~
11536 \InsetSpace ~
11537 \InsetSpace ~
11538 mov a,#0x01 
11539 \newline
11540 F2\InsetSpace ~
11541 \InsetSpace ~
11542 \InsetSpace ~
11543 \InsetSpace ~
11544 \InsetSpace ~
11545 \InsetSpace ~
11546 \InsetSpace ~
11547 \InsetSpace ~
11548 \InsetSpace ~
11549 movx @r0,a
11550 \end_layout
11551
11552 \begin_layout Standard
11553 If the -
11554 \begin_inset ERT
11555 status collapsed
11556
11557 \begin_layout Standard
11558
11559
11560 \backslash
11561 /
11562 \end_layout
11563
11564 \end_inset
11565
11566 -xstack
11567 \begin_inset LatexCommand \index{-\/-xstack}
11568
11569 \end_inset
11570
11571  option is used the pdata memory area is followed by the xstack memory area
11572  and the sum of their sizes is limited to 256 bytes.
11573 \end_layout
11574
11575 \begin_layout Subsubsection
11576 code
11577 \begin_inset LatexCommand \index{code}
11578
11579 \end_inset
11580
11581
11582 \begin_inset LatexCommand \index{\_\_code}
11583
11584 \end_inset
11585
11586
11587 \end_layout
11588
11589 \begin_layout Standard
11590 'Variables' declared with this storage class will be placed in the code
11591  memory:
11592 \end_layout
11593
11594 \begin_layout Verse
11595
11596 \family typewriter
11597 __code unsigned char test_code;
11598 \end_layout
11599
11600 \begin_layout Standard
11601 Read access to this variable generates the assembly code:
11602 \end_layout
11603
11604 \begin_layout Verse
11605
11606 \family typewriter
11607 90s00r6F\InsetSpace ~
11608 \InsetSpace ~
11609 \InsetSpace ~
11610 mov dptr,#_test_code
11611 \newline
11612 E4\InsetSpace ~
11613 \InsetSpace ~
11614 \InsetSpace ~
11615 \InsetSpace ~
11616 \InsetSpace ~
11617 \InsetSpace ~
11618 \InsetSpace ~
11619 \InsetSpace ~
11620 \InsetSpace ~
11621 clr a
11622 \newline
11623 93\InsetSpace ~
11624 \InsetSpace ~
11625 \InsetSpace ~
11626 \InsetSpace ~
11627 \InsetSpace ~
11628 \InsetSpace ~
11629 \InsetSpace ~
11630 \InsetSpace ~
11631 \InsetSpace ~
11632 movc a,@a+dptr 
11633 \end_layout
11634
11635 \begin_layout Standard
11636
11637 \family typewriter
11638 char
11639 \family default
11640  indexed arrays of characters in code memory can be accessed efficiently:
11641 \end_layout
11642
11643 \begin_layout Verse
11644
11645 \family typewriter
11646 __code char test_array[] = {'c','h','e','a','p'}; 
11647 \end_layout
11648
11649 \begin_layout Standard
11650 Read access to this array using an 8-bit unsigned index generates the assembly
11651  code:
11652 \end_layout
11653
11654 \begin_layout Verse
11655
11656 \family typewriter
11657 E5*00\InsetSpace ~
11658 \InsetSpace ~
11659 \InsetSpace ~
11660 \InsetSpace ~
11661 \InsetSpace ~
11662 \InsetSpace ~
11663 mov a,_index 
11664 \end_layout
11665
11666 \begin_layout Verse
11667
11668 \family typewriter
11669 90s00r41\InsetSpace ~
11670 \InsetSpace ~
11671 \InsetSpace ~
11672 mov dptr,#_test_array
11673 \end_layout
11674
11675 \begin_layout Verse
11676
11677 \family typewriter
11678 93\InsetSpace ~
11679 \InsetSpace ~
11680 \InsetSpace ~
11681 \InsetSpace ~
11682 \InsetSpace ~
11683 \InsetSpace ~
11684 \InsetSpace ~
11685 \InsetSpace ~
11686 \InsetSpace ~
11687 movc a,@a+dptr 
11688 \end_layout
11689
11690 \begin_layout Subsubsection
11691 bit
11692 \begin_inset LatexCommand \index{bit}
11693
11694 \end_inset
11695
11696
11697 \begin_inset LatexCommand \index{\_\_bit}
11698
11699 \end_inset
11700
11701
11702 \end_layout
11703
11704 \begin_layout Standard
11705 This is a data-type and a storage class specifier.
11706  When a variable is declared as a bit, it is allocated into the bit addressable
11707  memory of 8051, e.g.:
11708 \end_layout
11709
11710 \begin_layout Verse
11711
11712 \family typewriter
11713 __bit test_bit;
11714 \end_layout
11715
11716 \begin_layout Standard
11717 Writing 1 to this variable generates the assembly code:
11718 \end_layout
11719
11720 \begin_layout Verse
11721
11722 \family typewriter
11723 D2*00\InsetSpace ~
11724 \InsetSpace ~
11725 \InsetSpace ~
11726 \InsetSpace ~
11727 \InsetSpace ~
11728 \InsetSpace ~
11729 \InsetSpace ~
11730 setb\InsetSpace ~
11731 _test_bit
11732 \end_layout
11733
11734 \begin_layout Standard
11735 The bit addressable memory consists of 128 bits which are located from 0x20
11736  to 0x2f in data memory.
11737  
11738 \newline
11739 Apart from this 8051 specific storage class most architectures support
11740  ANSI-C bitfields
11741 \begin_inset LatexCommand \index{bitfields}
11742
11743 \end_inset
11744
11745
11746 \begin_inset Foot
11747 status open
11748
11749 \begin_layout Standard
11750 Not really meant as examples, but nevertheless showing what bitfields are
11751  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
11752 \end_layout
11753
11754 \end_inset
11755
11756 .
11757  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
11758  signed modifier are implemented as unsigned.
11759 \end_layout
11760
11761 \begin_layout Subsubsection
11762 sfr
11763 \begin_inset LatexCommand \index{sfr}
11764
11765 \end_inset
11766
11767
11768 \begin_inset LatexCommand \index{\_\_sfr}
11769
11770 \end_inset
11771
11772  / sfr16
11773 \begin_inset LatexCommand \index{sfr16}
11774
11775 \end_inset
11776
11777
11778 \begin_inset LatexCommand \index{\_\_sfr16}
11779
11780 \end_inset
11781
11782  / sfr32
11783 \begin_inset LatexCommand \index{sfr32}
11784
11785 \end_inset
11786
11787
11788 \begin_inset LatexCommand \index{\_\_sfr32}
11789
11790 \end_inset
11791
11792  / sbit
11793 \begin_inset LatexCommand \index{\_\_sbit}
11794
11795 \end_inset
11796
11797
11798 \begin_inset LatexCommand \index{sbit}
11799
11800 \end_inset
11801
11802
11803 \end_layout
11804
11805 \begin_layout Standard
11806 Like the bit keyword, 
11807 \emph on
11808 sfr / sfr16 / sfr32 / sbit 
11809 \emph default
11810 signify both a data-type and storage class, they are used to describe the
11811  
11812 \emph on
11813 s
11814 \emph default
11815 pecial 
11816 \emph on
11817 f
11818 \emph default
11819 unction 
11820 \emph on
11821 r
11822 \emph default
11823 egisters and 
11824 \emph on
11825 s
11826 \emph default
11827 pecial 
11828 \emph on
11829 bit
11830 \emph default
11831  variables of a 8051, eg:
11832 \end_layout
11833
11834 \begin_layout Verse
11835
11836 \family typewriter
11837 __sfr __at
11838 \begin_inset LatexCommand \index{at}
11839
11840 \end_inset
11841
11842
11843 \begin_inset LatexCommand \index{\_\_at}
11844
11845 \end_inset
11846
11847  (0x80) P0;\InsetSpace ~
11848  /* special function register P0 at location 0x80 */
11849 \newline
11850
11851 \newline
11852 /* 16 bit
11853  special function register combination for timer 0
11854 \newline
11855 \InsetSpace ~
11856 \InsetSpace ~
11857  with the high byte at
11858  location 0x8C and the low byte at location 0x8A */
11859 \newline
11860 __sfr16 __at (0x8C8A)
11861  TMR0;
11862 \newline
11863
11864 \newline
11865 __sbit __at
11866 \begin_inset LatexCommand \index{at}
11867
11868 \end_inset
11869
11870
11871 \begin_inset LatexCommand \index{\_\_at}
11872
11873 \end_inset
11874
11875  (0xd7) CY;\InsetSpace ~
11876  /* CY (Carry Flag
11877 \begin_inset LatexCommand \index{Flags}
11878
11879 \end_inset
11880
11881
11882 \begin_inset LatexCommand \index{Carry flag}
11883
11884 \end_inset
11885
11886 ) */
11887 \end_layout
11888
11889 \begin_layout Standard
11890 Special function registers which are located on an address dividable by
11891  8 are bit-addressable, an
11892 \emph on
11893  sbit
11894 \emph default
11895  addresses a specific bit within these sfr.
11896 \newline
11897 16 Bit and 32 bit special function
11898  register combinations which require a certain access order are better not
11899  declared using 
11900 \emph on
11901 sfr16
11902 \emph default
11903  or 
11904 \emph on
11905 sfr32.
11906
11907 \emph default
11908  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
11909  this is not guaranteed.
11910 \newline
11911
11912 \end_layout
11913
11914 \begin_layout Standard
11915 Please note, if you use a header file which was written for another compiler
11916  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
11917  likely be 
11918 \emph on
11919 not 
11920 \emph default
11921 compatible.
11922  Specifically the syntax 
11923 \family typewriter
11924 \InsetSpace ~
11925 sfr P0 = 0x80;\InsetSpace ~
11926
11927 \family default
11928  is compiled 
11929 \emph on
11930 without warning
11931 \emph default
11932  by SDCC to an assignment of 0x80 to a variable called P0 
11933 \family typewriter
11934
11935 \begin_inset Marginal
11936 status collapsed
11937
11938 \begin_layout Standard
11939
11940 \series bold
11941 \InsetSpace ~
11942 !
11943 \end_layout
11944
11945 \end_inset
11946
11947 .
11948  
11949 \family default
11950 Nevertheless it is possible to write header files
11951 \begin_inset LatexCommand \index{Header files}
11952
11953 \end_inset
11954
11955
11956 \begin_inset LatexCommand \index{Include files}
11957
11958 \end_inset
11959
11960  which can be shared among different compilers (see section 
11961 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
11962
11963 \end_inset
11964
11965 ).
11966  
11967 \end_layout
11968
11969 \begin_layout Subsubsection
11970 Pointers
11971 \begin_inset LatexCommand \index{Pointer}
11972
11973 \end_inset
11974
11975  to MCS51/DS390 specific memory spaces
11976 \end_layout
11977
11978 \begin_layout Standard
11979 SDCC allows (via language extensions) pointers to explicitly point to any
11980  of the memory spaces
11981 \begin_inset LatexCommand \index{Memory model}
11982
11983 \end_inset
11984
11985  of the 8051.
11986  In addition to the explicit pointers, the compiler uses (by default) generic
11987  pointers which can be used to point to any of the memory spaces.
11988 \newline
11989
11990 \newline
11991 Pointer
11992  declaration examples:
11993 \end_layout
11994
11995 \begin_layout Verse
11996
11997 \family typewriter
11998 /* pointer physically in internal ram pointing to object in external ram
11999  */ 
12000 \newline
12001 __xdata unsigned char * __data p;
12002 \newline
12003
12004 \newline
12005 /* pointer physically in external ram
12006  pointing to object in internal ram */ 
12007 \newline
12008 __data unsigned char * __xdata p;
12009 \newline
12010
12011 \newline
12012 /*
12013  pointer physically in code rom pointing to data in xdata space */ 
12014 \newline
12015 __xdata
12016  unsigned char * __code p;
12017 \newline
12018
12019 \newline
12020 /* pointer physically in code space pointing to
12021  data in code space */ 
12022 \newline
12023 __code unsigned char * __code p;
12024 \newline
12025
12026 \newline
12027 /* generic pointer
12028  physically located in xdata space */
12029 \newline
12030 unsigned char * __xdata p;
12031 \newline
12032
12033 \newline
12034 /* generic
12035  pointer physically located in default memory space */
12036 \newline
12037 unsigned char * p;
12038 \newline
12039
12040 \newline
12041 /*
12042  the following is a function pointer
12043 \begin_inset LatexCommand \index{function pointer}
12044
12045 \end_inset
12046
12047  physically located in data space */
12048 \newline
12049 char (* __data fp)(void);
12050 \end_layout
12051
12052 \begin_layout Standard
12053 Well you get the idea.
12054  
12055 \newline
12056
12057 \newline
12058 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
12059 \emph on
12060 generic
12061 \emph default
12062  pointers.
12063  
12064 \size small
12065
12066 \newline
12067
12068 \newline
12069
12070 \size default
12071 The highest order byte of the 
12072 \emph on
12073 generic
12074 \emph default
12075  pointers contains the data space information.
12076  Assembler support routines are called whenever data is stored or retrieved
12077  using 
12078 \emph on
12079 generic
12080 \emph default
12081  pointers.
12082  These are useful for developing reusable library
12083 \begin_inset LatexCommand \index{Libraries}
12084
12085 \end_inset
12086
12087  routines.
12088  Explicitly specifying the pointer
12089 \begin_inset LatexCommand \index{pointer}
12090
12091 \end_inset
12092
12093  type will generate the most efficient code.
12094 \end_layout
12095
12096 \begin_layout Subsubsection
12097 Notes on MCS51 memory
12098 \begin_inset LatexCommand \index{MCS51 memory}
12099
12100 \end_inset
12101
12102  layout
12103 \end_layout
12104
12105 \begin_layout Standard
12106 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12107  RAM memory which is structured as follows:
12108 \newline
12109
12110 \newline
12111 - Bytes 00-1F - 32 bytes to hold
12112  up to 4 banks of the registers R0 to R7, 
12113 \newline
12114 - Bytes 20-2F - 16 bytes to hold
12115  128 bit
12116 \begin_inset LatexCommand \index{bit}
12117
12118 \end_inset
12119
12120  variables and, 
12121 \newline
12122 - Bytes 30-7F - 80 bytes for general purpose use.
12123 \newline
12124
12125 \end_layout
12126
12127 \begin_layout Standard
12128 Additionally some members of the MCS51 family may have up to 128 bytes of
12129  additional, indirectly addressable, internal RAM memory (
12130 \emph on
12131 idata
12132 \emph default
12133
12134 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
12135
12136 \end_inset
12137
12138
12139 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
12140
12141 \end_inset
12142
12143 ).
12144  Furthermore, some chips may have some built in external memory (
12145 \emph on
12146 xdata
12147 \emph default
12148
12149 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12150
12151 \end_inset
12152
12153
12154 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12155
12156 \end_inset
12157
12158 ) which should not be confused with the internal, directly addressable RAM
12159  memory (
12160 \emph on
12161 data
12162 \emph default
12163
12164 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
12165
12166 \end_inset
12167
12168
12169 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
12170
12171 \end_inset
12172
12173 ).
12174  Sometimes this built in 
12175 \emph on
12176 xdata
12177 \emph default
12178  memory has to be activated before using it (you can probably find this
12179  information on the datasheet of the microcontroller your are using, see
12180  also section 
12181 \begin_inset LatexCommand \ref{sub:Startup-Code}
12182
12183 \end_inset
12184
12185 \InsetSpace ~
12186 Startup-Code).
12187 \end_layout
12188
12189 \begin_layout Standard
12190 Normally SDCC will only use the first bank
12191 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
12192
12193 \end_inset
12194
12195  of registers (register bank 0), but it is possible to specify that other
12196  banks of registers (keyword 
12197 \emph on
12198 using
12199 \emph default
12200  
12201 \emph on
12202
12203 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
12204
12205 \end_inset
12206
12207
12208 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
12209
12210 \end_inset
12211
12212
12213 \emph default
12214 ) should be used for example in interrupt
12215 \begin_inset LatexCommand \index{interrupt}
12216
12217 \end_inset
12218
12219
12220 \begin_inset LatexCommand \index{\_\_interrupt}
12221
12222 \end_inset
12223
12224  routines.
12225  By default, the compiler will place the stack after the last byte of allocated
12226  memory for variables.
12227  For example, if the first 2 banks of registers are used, and only four
12228  bytes are used for 
12229 \emph on
12230 data
12231 \emph default
12232  variables, it will position the base of the internal stack at address 20
12233  (0x14).
12234  This implies that as the stack
12235 \begin_inset LatexCommand \index{stack}
12236
12237 \end_inset
12238
12239  grows, it will use up the remaining register banks, and the 16 bytes used
12240  by the 128 bit variables, and 80 bytes for general purpose use.
12241  If any bit variables are used, the data variables will be placed in unused
12242  register banks and after the byte holding the last bit variable.
12243  For example, if register banks 0 and 1 are used, and there are 9 bit variables
12244  (two bytes used), 
12245 \emph on
12246 data
12247 \emph default
12248  variables will be placed starting from address 0x10 to 0x20 and continue
12249  at address 0x22.
12250  You can also use -
12251 \begin_inset ERT
12252 status collapsed
12253
12254 \begin_layout Standard
12255
12256
12257 \backslash
12258 /
12259 \end_layout
12260
12261 \end_inset
12262
12263 -data-loc
12264 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
12265
12266 \end_inset
12267
12268  to specify the start address of the 
12269 \emph on
12270 data
12271 \emph default
12272  and -
12273 \begin_inset ERT
12274 status collapsed
12275
12276 \begin_layout Standard
12277
12278
12279 \backslash
12280 /
12281 \end_layout
12282
12283 \end_inset
12284
12285 -iram-size
12286 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
12287
12288 \end_inset
12289
12290  to specify the size of the total internal RAM (
12291 \emph on
12292 data
12293 \emph default
12294 +
12295 \emph on
12296 idata
12297 \emph default
12298 ).
12299  
12300 \newline
12301
12302 \end_layout
12303
12304 \begin_layout Standard
12305 By default the 8051 linker will place the stack after the last byte of (i)data
12306  variables.
12307  Option -
12308 \begin_inset ERT
12309 status collapsed
12310
12311 \begin_layout Standard
12312
12313
12314 \backslash
12315 /
12316 \end_layout
12317
12318 \end_inset
12319
12320 -stack-loc
12321 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12322
12323 \end_inset
12324
12325  allows you to specify the start of the stack, i.e.
12326  you could start it after any data in the general purpose area.
12327  If your microcontroller has additional indirectly addressable internal
12328  RAM (
12329 \emph on
12330 idata
12331 \emph default
12332 ) you can place the stack on it.
12333  You may also need to use -
12334 \begin_inset ERT
12335 status collapsed
12336
12337 \begin_layout Standard
12338
12339
12340 \backslash
12341 /
12342 \end_layout
12343
12344 \end_inset
12345
12346 -xdata-loc
12347 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12348
12349 \end_inset
12350
12351  to set the start address of the external RAM (
12352 \emph on
12353 xdata
12354 \emph default
12355 ) and -
12356 \begin_inset ERT
12357 status collapsed
12358
12359 \begin_layout Standard
12360
12361
12362 \backslash
12363 /
12364 \end_layout
12365
12366 \end_inset
12367
12368 -xram-size
12369 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12370
12371 \end_inset
12372
12373  to specify its size.
12374  Same goes for the code memory, using -
12375 \begin_inset ERT
12376 status collapsed
12377
12378 \begin_layout Standard
12379
12380
12381 \backslash
12382 /
12383 \end_layout
12384
12385 \end_inset
12386
12387 -code-loc
12388 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12389
12390 \end_inset
12391
12392  and -
12393 \begin_inset ERT
12394 status collapsed
12395
12396 \begin_layout Standard
12397
12398
12399 \backslash
12400 /
12401 \end_layout
12402
12403 \end_inset
12404
12405 -code-size
12406 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12407
12408 \end_inset
12409
12410 .
12411  If in doubt, don't specify any options and see if the resulting memory
12412  layout is appropriate, then you can adjust it.
12413 \end_layout
12414
12415 \begin_layout Standard
12416 The linker generates two files with memory allocation information.
12417  The first, with extension .map
12418 \begin_inset LatexCommand \index{<file>.map}
12419
12420 \end_inset
12421
12422  shows all the variables and segments.
12423  The second with extension .mem
12424 \begin_inset LatexCommand \index{<file>.mem}
12425
12426 \end_inset
12427
12428  shows the final memory layout.
12429  The linker will complain either if memory segments overlap, there is not
12430  enough memory, or there is not enough space for stack.
12431  If you get any linking warnings and/or errors related to stack or segments
12432  allocation, take a look at either the .map or .mem files to find out what
12433  the problem is.
12434  The .mem file may even suggest a solution to the problem.
12435 \begin_inset VSpace bigskip
12436 \end_inset
12437
12438
12439 \end_layout
12440
12441 \begin_layout Subsection
12442 Z80/Z180 Storage Class
12443 \begin_inset LatexCommand \index{Z80!Storage class}
12444
12445 \end_inset
12446
12447  Language Extensions
12448 \end_layout
12449
12450 \begin_layout Subsubsection
12451 sfr
12452 \begin_inset LatexCommand \index{sfr}
12453
12454 \end_inset
12455
12456
12457 \begin_inset LatexCommand \index{\_\_sfr}
12458
12459 \end_inset
12460
12461  (in/out to 8-bit addresses)
12462 \end_layout
12463
12464 \begin_layout Standard
12465 The Z80
12466 \begin_inset LatexCommand \index{Z80}
12467
12468 \end_inset
12469
12470  family has separate address spaces for memory and 
12471 \emph on
12472 i
12473 \emph default
12474 nput/
12475 \emph on
12476 o
12477 \emph default
12478 utput memory.
12479  I/O memory
12480 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12481
12482 \end_inset
12483
12484
12485 \begin_inset LatexCommand \index{Z80!I/O memory}
12486
12487 \end_inset
12488
12489
12490 \begin_inset LatexCommand \index{Z180!I/O memory}
12491
12492 \end_inset
12493
12494  is accessed with special instructions, e.g.:
12495 \end_layout
12496
12497 \begin_layout Verse
12498
12499 \family typewriter
12500 sfr at 0x78 IoPort;\InsetSpace ~
12501 \InsetSpace ~
12502 /* define a var in I/O space at 78h called IoPort */
12503  
12504 \end_layout
12505
12506 \begin_layout Standard
12507 Writing 0x01 to this variable generates the assembly code:
12508 \end_layout
12509
12510 \begin_layout Verse
12511
12512 \family typewriter
12513 3E 01\InsetSpace ~
12514 \InsetSpace ~
12515 \InsetSpace ~
12516 \InsetSpace ~
12517 \InsetSpace ~
12518 \InsetSpace ~
12519 ld a,#0x01
12520 \newline
12521 D3 78\InsetSpace ~
12522 \InsetSpace ~
12523 \InsetSpace ~
12524 \InsetSpace ~
12525 \InsetSpace ~
12526 \InsetSpace ~
12527 out (_IoPort),a 
12528 \end_layout
12529
12530 \begin_layout Subsubsection
12531 banked sfr
12532 \begin_inset LatexCommand \index{sfr}
12533
12534 \end_inset
12535
12536
12537 \begin_inset LatexCommand \index{\_\_sfr}
12538
12539 \end_inset
12540
12541  (in/out to 16-bit addresses)
12542 \end_layout
12543
12544 \begin_layout Standard
12545 The keyword 
12546 \emph on
12547 banked
12548 \emph default
12549  is used to support 16 bit addresses in I/O memory e.g.:
12550 \end_layout
12551
12552 \begin_layout Verse
12553
12554 \family typewriter
12555 sfr banked at
12556 \begin_inset LatexCommand \index{at}
12557
12558 \end_inset
12559
12560
12561 \begin_inset LatexCommand \index{\_\_at}
12562
12563 \end_inset
12564
12565  0x123 IoPort; 
12566 \end_layout
12567
12568 \begin_layout Standard
12569 Writing 0x01 to this variable generates the assembly code:
12570 \end_layout
12571
12572 \begin_layout Verse
12573
12574 \family typewriter
12575 01 23 01\InsetSpace ~
12576 \InsetSpace ~
12577 \InsetSpace ~
12578 ld bc,#_IoPort
12579 \newline
12580 3E 01\InsetSpace ~
12581 \InsetSpace ~
12582 \InsetSpace ~
12583 \InsetSpace ~
12584 \InsetSpace ~
12585 \InsetSpace ~
12586 ld a,#0x01 
12587 \newline
12588 ED 79\InsetSpace ~
12589 \InsetSpace ~
12590 \InsetSpace ~
12591 \InsetSpace ~
12592 \InsetSpace ~
12593 \InsetSpace ~
12594 out (c),a 
12595 \end_layout
12596
12597 \begin_layout Subsubsection
12598 sfr
12599 \begin_inset LatexCommand \index{sfr}
12600
12601 \end_inset
12602
12603
12604 \begin_inset LatexCommand \index{\_\_sfr}
12605
12606 \end_inset
12607
12608  (in0/out0 to 8 bit addresses on Z180
12609 \begin_inset LatexCommand \index{Z180}
12610
12611 \end_inset
12612
12613 /HD64180
12614 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12615
12616 \end_inset
12617
12618 )
12619 \end_layout
12620
12621 \begin_layout Standard
12622 The compiler option -
12623 \begin_inset ERT
12624 status collapsed
12625
12626 \begin_layout Standard
12627
12628
12629 \backslash
12630 /
12631 \end_layout
12632
12633 \end_inset
12634
12635 -portmode
12636 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12637
12638 \end_inset
12639
12640 =180 (80) and a compiler #pragma\InsetSpace ~
12641 portmode
12642 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12643
12644 \end_inset
12645
12646  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12647 ns 
12648 \family typewriter
12649 in0/out0
12650 \family default
12651  instead of 
12652 \family typewriter
12653 in/out
12654 \family default
12655 .
12656  If you include the file z180.h this will be set automatically.
12657 \begin_inset VSpace bigskip
12658 \end_inset
12659
12660
12661 \end_layout
12662
12663 \begin_layout Subsection
12664 HC08 Storage Class
12665 \begin_inset LatexCommand \index{HC08!Storage class}
12666
12667 \end_inset
12668
12669  Language Extensions
12670 \end_layout
12671
12672 \begin_layout Subsubsection
12673 data
12674 \begin_inset LatexCommand \index{data (hc08 storage class)}
12675
12676 \end_inset
12677
12678
12679 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12680
12681 \end_inset
12682
12683  
12684 \end_layout
12685
12686 \begin_layout Standard
12687 The data storage class declares a variable that resides in the first 256
12688  bytes of memory (the direct page).
12689  The HC08
12690 \begin_inset LatexCommand \index{HC08}
12691
12692 \end_inset
12693
12694  is most efficient at accessing variables (especially pointers) stored here.
12695 \end_layout
12696
12697 \begin_layout Subsubsection
12698 xdata
12699 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12700
12701 \end_inset
12702
12703
12704 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12705
12706 \end_inset
12707
12708  
12709 \end_layout
12710
12711 \begin_layout Standard
12712 The xdata storage class declares a variable that can reside anywhere in
12713  memory.
12714  This is the default if no storage class is specified.
12715  
12716 \begin_inset VSpace bigskip
12717 \end_inset
12718
12719
12720 \end_layout
12721
12722 \begin_layout Section
12723 Absolute Addressing
12724 \begin_inset LatexCommand \index{Absolute addressing}
12725
12726 \end_inset
12727
12728
12729 \end_layout
12730
12731 \begin_layout Standard
12732 Data items can be assigned an absolute address with the 
12733 \emph on
12734 at
12735 \begin_inset LatexCommand \index{at}
12736
12737 \end_inset
12738
12739
12740 \begin_inset LatexCommand \index{\_\_at}
12741
12742 \end_inset
12743
12744  <address>
12745 \emph default
12746  keyword, in addition to a storage class, e.g.:
12747 \end_layout
12748
12749 \begin_layout Verse
12750
12751 \family typewriter
12752 xdata
12753 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12754
12755 \end_inset
12756
12757
12758 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12759
12760 \end_inset
12761
12762  at
12763 \begin_inset LatexCommand \index{at}
12764
12765 \end_inset
12766
12767
12768 \begin_inset LatexCommand \index{\_\_at}
12769
12770 \end_inset
12771
12772  0x7ffe unsigned int chksum;
12773 \end_layout
12774
12775 \begin_layout Standard
12776 or, better conforming to ISO/IEC 9899 C:
12777 \end_layout
12778
12779 \begin_layout Verse
12780
12781 \family typewriter
12782 __xdata __at (0x7ffe) unsigned int chksum;
12783 \end_layout
12784
12785 \begin_layout Standard
12786 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
12787  of the external ram.
12788  The compiler does 
12789 \emph on
12790 not
12791 \emph default
12792  reserve any space for variables declared in this way
12793 \begin_inset Marginal
12794 status collapsed
12795
12796 \begin_layout Standard
12797
12798 \series bold
12799 \InsetSpace ~
12800 !
12801 \end_layout
12802
12803 \end_inset
12804
12805  (they are implemented with an equate in the assembler).
12806  Thus it is left to the programmer to make sure there are no overlaps with
12807  other variables that are declared without the absolute address.
12808  The assembler listing file (.lst
12809 \begin_inset LatexCommand \index{<file>.lst}
12810
12811 \end_inset
12812
12813 ) and the linker output files (.rst
12814 \begin_inset LatexCommand \index{<file>.rst}
12815
12816 \end_inset
12817
12818 ) and (.map
12819 \begin_inset LatexCommand \index{<file>.map}
12820
12821 \end_inset
12822
12823 ) are good places to look for such overlaps.
12824 \end_layout
12825
12826 \begin_layout Standard
12827 If however you provide an initializer
12828 \begin_inset LatexCommand \index{Variable initialization}
12829
12830 \end_inset
12831
12832  actual memory allocation will take place and overlaps will be detected
12833  by the linker.
12834  E.g.:
12835 \end_layout
12836
12837 \begin_layout Verse
12838
12839 \family typewriter
12840 __code __at (0x7ff0) char Id[5] = 
12841 \begin_inset Quotes sld
12842 \end_inset
12843
12844 SDCC
12845 \begin_inset Quotes srd
12846 \end_inset
12847
12848 ;
12849 \end_layout
12850
12851 \begin_layout Standard
12852 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
12853  in code memory.
12854 \end_layout
12855
12856 \begin_layout Standard
12857 In case of memory mapped I/O devices the keyword 
12858 \emph on
12859 volatile
12860 \emph default
12861  has to be used to tell the compiler that accesses might not be removed:
12862 \end_layout
12863
12864 \begin_layout Verse
12865
12866 \family typewriter
12867 volatile
12868 \begin_inset LatexCommand \index{volatile}
12869
12870 \end_inset
12871
12872  __xdata
12873 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12874
12875 \end_inset
12876
12877  __at
12878 \begin_inset LatexCommand \index{at}
12879
12880 \end_inset
12881
12882  (0x8000) unsigned char PORTA_8255;
12883 \end_layout
12884
12885 \begin_layout Standard
12886 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
12887 r) array
12888 \family typewriter
12889 \size footnotesize
12890
12891 \begin_inset LatexCommand \index{Aligned array}
12892
12893 \end_inset
12894
12895
12896 \family default
12897 \size default
12898  starts at a block (256 byte) boundary
12899 \begin_inset LatexCommand \index{block boundary}
12900
12901 \end_inset
12902
12903  (section 
12904 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12905
12906 \end_inset
12907
12908  has an example).
12909 \newline
12910 Absolute addresses can be specified for variables in all
12911  storage classes, e.g.:
12912 \end_layout
12913
12914 \begin_layout Verse
12915
12916 \family typewriter
12917 __bit
12918 \begin_inset LatexCommand \index{bit}
12919
12920 \end_inset
12921
12922  __at
12923 \begin_inset LatexCommand \index{at}
12924
12925 \end_inset
12926
12927  (0x02) bvar;
12928 \end_layout
12929
12930 \begin_layout Standard
12931 The above example will allocate the variable at offset 0x02 in the bit-addressab
12932 le space.
12933  There is no real advantage to assigning absolute addresses to variables
12934  in this manner, unless you want strict control over all the variables allocated.
12935  One possible use would be to write hardware portable code.
12936  For example, if you have a routine that uses one or more of the microcontroller
12937  I/O pins, and such pins are different for two different hardwares, you
12938  can declare the I/O pins in your routine using:
12939 \end_layout
12940
12941 \begin_layout Verse
12942
12943 \family typewriter
12944 extern volatile
12945 \begin_inset LatexCommand \index{volatile}
12946
12947 \end_inset
12948
12949  __bit MOSI;\InsetSpace ~
12950 \InsetSpace ~
12951 \InsetSpace ~
12952 \InsetSpace ~
12953 /* master out, slave in */
12954 \newline
12955 extern volatile __bit MISO;\InsetSpace ~
12956 \InsetSpace ~
12957 \InsetSpace ~
12958 \InsetSpace ~
12959 /* master
12960  in, slave out */
12961 \newline
12962 extern volatile __bit MCLK;\InsetSpace ~
12963 \InsetSpace ~
12964 \InsetSpace ~
12965 \InsetSpace ~
12966 /* master clock */
12967 \newline
12968
12969 \newline
12970 /* Input and
12971  Output of a byte on a 3-wire serial bus.
12972 \newline
12973 \InsetSpace ~
12974 \InsetSpace ~
12975 \InsetSpace ~
12976 If needed adapt polarity of clock,
12977  polarity of data and bit order
12978 \newline
12979 \InsetSpace ~
12980 */
12981 \newline
12982 unsigned char spi_io(unsigned char out_byte)
12983  
12984 \newline
12985
12986 \newline
12987 \InsetSpace ~
12988 \InsetSpace ~
12989 \InsetSpace ~
12990 \InsetSpace ~
12991 unsigned char i=8;
12992 \newline
12993 \InsetSpace ~
12994 \InsetSpace ~
12995 \InsetSpace ~
12996 \InsetSpace ~
12997 do { 
12998 \newline
12999 \InsetSpace ~
13000 \InsetSpace ~
13001 \InsetSpace ~
13002 \InsetSpace ~
13003 \InsetSpace ~
13004 \InsetSpace ~
13005 \InsetSpace ~
13006 \InsetSpace ~
13007 MOSI = out_byte & 0x80; 
13008 \newline
13009 \InsetSpace ~
13010 \InsetSpace ~
13011 \InsetSpace ~
13012 \InsetSpace ~
13013 \InsetSpace ~
13014 \InsetSpace ~
13015 \InsetSpace ~
13016 \InsetSpace ~
13017 out_byte <<= 1;
13018 \newline
13019 \InsetSpace ~
13020 \InsetSpace ~
13021 \InsetSpace ~
13022 \InsetSpace ~
13023 \InsetSpace ~
13024 \InsetSpace ~
13025 \InsetSpace ~
13026 \InsetSpace ~
13027 MCLK =
13028  1; 
13029 \newline
13030 \InsetSpace ~
13031 \InsetSpace ~
13032 \InsetSpace ~
13033 \InsetSpace ~
13034 \InsetSpace ~
13035 \InsetSpace ~
13036 \InsetSpace ~
13037 \InsetSpace ~
13038 /* _asm nop _endasm; */\InsetSpace ~
13039 \InsetSpace ~
13040 \InsetSpace ~
13041 \InsetSpace ~
13042 \InsetSpace ~
13043 \InsetSpace ~
13044 \InsetSpace ~
13045 \InsetSpace ~
13046 /* for slow peripherals */
13047 \newline
13048 \InsetSpace ~
13049 \InsetSpace ~
13050 \InsetSpace ~
13051 \InsetSpace ~
13052 \InsetSpace ~
13053 \InsetSpace ~
13054 \InsetSpace ~
13055 \InsetSpace ~
13056 if(MISO) 
13057 \newline
13058 \InsetSpace ~
13059 \InsetSpace ~
13060 \InsetSpace ~
13061 \InsetSpace ~
13062 \InsetSpace ~
13063 \InsetSpace ~
13064 \InsetSpace ~
13065 \InsetSpace ~
13066 \InsetSpace ~
13067 \InsetSpace ~
13068 \InsetSpace ~
13069 \InsetSpace ~
13070 out_byte +=
13071  1; 
13072 \newline
13073 \InsetSpace ~
13074 \InsetSpace ~
13075 \InsetSpace ~
13076 \InsetSpace ~
13077 \InsetSpace ~
13078 \InsetSpace ~
13079 \InsetSpace ~
13080 \InsetSpace ~
13081 MCLK = 0; 
13082 \newline
13083 \InsetSpace ~
13084 \InsetSpace ~
13085 \InsetSpace ~
13086 \InsetSpace ~
13087 } while(--i);
13088 \newline
13089 \InsetSpace ~
13090 \InsetSpace ~
13091 \InsetSpace ~
13092 \InsetSpace ~
13093 return out_byte; 
13094 \newline
13095 }
13096 \end_layout
13097
13098 \begin_layout Standard
13099 Then, someplace in the code for the first hardware you would use
13100 \end_layout
13101
13102 \begin_layout Verse
13103
13104 \family typewriter
13105 __bit __at
13106 \begin_inset LatexCommand \index{at}
13107
13108 \end_inset
13109
13110
13111 \begin_inset LatexCommand \index{\_\_at}
13112
13113 \end_inset
13114
13115  (0x80) MOSI;\InsetSpace ~
13116 \InsetSpace ~
13117 \InsetSpace ~
13118 \InsetSpace ~
13119 /* I/O port 0, bit 0 */
13120 \newline
13121 __bit __at (0x81) MISO;\InsetSpace ~
13122 \InsetSpace ~
13123 \InsetSpace ~
13124 \InsetSpace ~
13125 /* I/O port 0,
13126  bit 1 */
13127 \newline
13128 __bit __at (0x82) MCLK;\InsetSpace ~
13129 \InsetSpace ~
13130 \InsetSpace ~
13131 \InsetSpace ~
13132 /* I/O port 0, bit 2 */
13133 \end_layout
13134
13135 \begin_layout Standard
13136 Similarly, for the second hardware you would use
13137 \end_layout
13138
13139 \begin_layout Verse
13140
13141 \family typewriter
13142 __bit __at (0x83) MOSI;\InsetSpace ~
13143 \InsetSpace ~
13144 \InsetSpace ~
13145 \InsetSpace ~
13146 /* I/O port 0, bit 3 */
13147 \newline
13148 __bit __at (0x91) MISO;\InsetSpace ~
13149 \InsetSpace ~
13150 \InsetSpace ~
13151 \InsetSpace ~
13152 /*
13153  I/O port 1, bit 1 */
13154 \newline
13155 __bit
13156 \begin_inset LatexCommand \index{bit}
13157
13158 \end_inset
13159
13160  __at (0x92) MCLK;\InsetSpace ~
13161 \InsetSpace ~
13162 \InsetSpace ~
13163 \InsetSpace ~
13164 /* I/O port 1, bit 2 */
13165 \end_layout
13166
13167 \begin_layout Standard
13168 and you can use the same hardware dependent routine without changes, as
13169  for example in a library.
13170  This is somehow similar to sbit, but only one absolute address has to be
13171  specified in the whole project.
13172 \begin_inset VSpace bigskip
13173 \end_inset
13174
13175
13176 \end_layout
13177
13178 \begin_layout Section
13179 Parameters
13180 \begin_inset LatexCommand \index{Parameters}
13181
13182 \end_inset
13183
13184
13185 \begin_inset LatexCommand \index{function parameter}
13186
13187 \end_inset
13188
13189  & Local Variables
13190 \begin_inset LatexCommand \index{local variables}
13191
13192 \end_inset
13193
13194
13195 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13196
13197 \end_inset
13198
13199
13200 \end_layout
13201
13202 \begin_layout Standard
13203 Automatic (local) variables and parameters to functions can either be placed
13204  on the stack or in data-space.
13205  The default action of the compiler is to place these variables in the internal
13206  RAM (for small model) or external RAM (for medium or large model).
13207  This in fact makes them similar to 
13208 \emph on
13209 static
13210 \begin_inset LatexCommand \index{static}
13211
13212 \end_inset
13213
13214
13215 \emph default
13216  so by default functions are non-reentrant
13217 \begin_inset LatexCommand \index{reentrant}
13218
13219 \end_inset
13220
13221 .
13222  
13223 \newline
13224
13225 \newline
13226 They can be placed on the stack
13227 \begin_inset LatexCommand \index{stack}
13228
13229 \end_inset
13230
13231  by using the
13232 \emph on
13233  -
13234 \begin_inset ERT
13235 status collapsed
13236
13237 \begin_layout Standard
13238
13239
13240 \backslash
13241 /
13242 \end_layout
13243
13244 \end_inset
13245
13246 -stack-auto
13247 \begin_inset LatexCommand \index{-\/-stack-auto}
13248
13249 \end_inset
13250
13251
13252 \emph default
13253  option, by using 
13254 \emph on
13255 #pragma\InsetSpace ~
13256 stackauto
13257 \emph default
13258
13259 \begin_inset LatexCommand \index{\#pragma stackauto}
13260
13261 \end_inset
13262
13263  or by using the 
13264 \emph on
13265 reentrant
13266 \begin_inset LatexCommand \index{reentrant}
13267
13268 \end_inset
13269
13270
13271 \emph default
13272  keyword in the function declaration, e.g.:
13273 \end_layout
13274
13275 \begin_layout Verse
13276
13277 \family typewriter
13278 unsigned char foo(char i) __reentrant 
13279 \newline
13280
13281 \newline
13282 \InsetSpace ~
13283 \InsetSpace ~
13284 \InsetSpace ~
13285 \InsetSpace ~
13286 ...
13287  
13288 \newline
13289 }
13290 \end_layout
13291
13292 \begin_layout Standard
13293 Since stack space on 8051 is limited, the 
13294 \emph on
13295 reentrant 
13296 \emph default
13297 keyword or the
13298 \emph on
13299  -
13300 \begin_inset ERT
13301 status collapsed
13302
13303 \begin_layout Standard
13304
13305
13306 \backslash
13307 /
13308 \end_layout
13309
13310 \end_inset
13311
13312 -stack-auto
13313 \emph default
13314  option should be used sparingly.
13315  Note that the reentrant keyword just means that the parameters & local
13316  variables will be allocated to the stack, it 
13317 \emph on
13318 does not
13319 \emph default
13320  mean that the function is register bank
13321 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13322
13323 \end_inset
13324
13325  independent.
13326 \newline
13327
13328 \newline
13329 Local variables
13330 \begin_inset LatexCommand \index{local variables}
13331
13332 \end_inset
13333
13334  can be assigned storage classes and absolute
13335 \begin_inset LatexCommand \index{Absolute addressing}
13336
13337 \end_inset
13338
13339  addresses, e.g.: 
13340 \end_layout
13341
13342 \begin_layout Verse
13343
13344 \family typewriter
13345 unsigned char foo() 
13346 \newline
13347 {
13348 \newline
13349 \InsetSpace ~
13350 \InsetSpace ~
13351 \InsetSpace ~
13352 \InsetSpace ~
13353 __xdata unsigned char i;
13354 \newline
13355 \InsetSpace ~
13356 \InsetSpace ~
13357 \InsetSpace ~
13358 \InsetSpace ~
13359 __bit bvar;
13360 \newline
13361 \InsetSpace ~
13362 \InsetSpace ~
13363 \InsetSpace ~
13364 \InsetSpace ~
13365 __data __at
13366 \begin_inset LatexCommand \index{at}
13367
13368 \end_inset
13369
13370  (0x31) unsigned char j;
13371 \newline
13372 \InsetSpace ~
13373 \InsetSpace ~
13374 \InsetSpace ~
13375 \InsetSpace ~
13376 ...
13377  
13378 \newline
13379 }
13380 \end_layout
13381
13382 \begin_layout Standard
13383 In the above example the variable 
13384 \emph on
13385 i
13386 \emph default
13387  will be allocated in the external ram, 
13388 \emph on
13389 bvar
13390 \emph default
13391  in bit addressable space and
13392 \emph on
13393  j
13394 \emph default
13395  in internal ram.
13396  When compiled with 
13397 \emph on
13398 -
13399 \begin_inset ERT
13400 status collapsed
13401
13402 \begin_layout Standard
13403
13404
13405 \backslash
13406 /
13407 \end_layout
13408
13409 \end_inset
13410
13411 -stack-auto
13412 \emph default
13413  or when a function is declared as 
13414 \emph on
13415 reentrant
13416 \emph default
13417  this should only be done for static variables.
13418 \end_layout
13419
13420 \begin_layout Standard
13421 Parameters
13422 \begin_inset LatexCommand \index{function parameter}
13423
13424 \end_inset
13425
13426  however are not allowed any storage class
13427 \begin_inset LatexCommand \index{Storage class}
13428
13429 \end_inset
13430
13431 , (storage classes for parameters will be ignored), their allocation is
13432  governed by the memory model in use, and the reentrancy options.
13433 \end_layout
13434
13435 \begin_layout Standard
13436 It is however allowed to use bit parameters in reentrant functions and also
13437  non-static local bit variables are supported.
13438  Efficient use is limited to 8 semi-bitregisters in bit space.
13439  They are pushed and popped to stack
13440 \begin_inset LatexCommand \index{stack}
13441
13442 \end_inset
13443
13444  as a single byte just like the normal registers.
13445 \end_layout
13446
13447 \begin_layout Section
13448 Overlaying
13449 \begin_inset LatexCommand \label{sub:Overlaying}
13450
13451 \end_inset
13452
13453
13454 \begin_inset LatexCommand \index{Overlaying}
13455
13456 \end_inset
13457
13458
13459 \end_layout
13460
13461 \begin_layout Standard
13462 For non-reentrant
13463 \begin_inset LatexCommand \index{reentrant}
13464
13465 \end_inset
13466
13467  functions SDCC will try to reduce internal ram space usage by overlaying
13468  parameters and local variables of a function (if possible).
13469  Parameters and local variables
13470 \begin_inset LatexCommand \index{local variables}
13471
13472 \end_inset
13473
13474  of a function will be allocated to an overlayable segment if the function
13475  has 
13476 \emph on
13477 no other function calls and the function is non-reentrant and the memory
13478  model
13479 \begin_inset LatexCommand \index{Memory model}
13480
13481 \end_inset
13482
13483  is small.
13484
13485 \emph default
13486  If an explicit storage class
13487 \begin_inset LatexCommand \index{Storage class}
13488
13489 \end_inset
13490
13491  is specified for a local variable, it will NOT be overlayed.
13492 \end_layout
13493
13494 \begin_layout Standard
13495 Note that the compiler (not the linkage editor) makes the decision for overlayin
13496 g the data items.
13497  Functions that are called from an interrupt service routine
13498 \begin_inset Marginal
13499 status collapsed
13500
13501 \begin_layout Standard
13502
13503 \series bold
13504 !
13505 \end_layout
13506
13507 \end_inset
13508
13509  should be preceded by a #pragma\InsetSpace ~
13510 nooverlay
13511 \begin_inset LatexCommand \index{\#pragma nooverlay}
13512
13513 \end_inset
13514
13515  if they are not reentrant.
13516 \end_layout
13517
13518 \begin_layout Standard
13519 Also note that the compiler does not do any processing of inline assembler
13520  code, so the compiler might incorrectly assign local variables and parameters
13521  of a function into the overlay segment if the inline assembler code calls
13522  other c-functions that might use the overlay.
13523  In that case the #pragma\InsetSpace ~
13524 nooverlay should be used.
13525 \end_layout
13526
13527 \begin_layout Standard
13528 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13529 tion
13530 \begin_inset LatexCommand \index{Multiplication}
13531
13532 \end_inset
13533
13534  or division
13535 \begin_inset LatexCommand \index{Division}
13536
13537 \end_inset
13538
13539  will NOT be overlayed since these are implemented using external functions,
13540  e.g.:
13541 \end_layout
13542
13543 \begin_layout Verse
13544
13545 \family typewriter
13546 #pragma save 
13547 \newline
13548 #pragma nooverlay
13549 \begin_inset LatexCommand \index{\#pragma nooverlay}
13550
13551 \end_inset
13552
13553  
13554 \newline
13555 void set_error(unsigned char errcd) 
13556 \newline
13557 {
13558 \newline
13559 \InsetSpace ~
13560 \InsetSpace ~
13561 \InsetSpace ~
13562 \InsetSpace ~
13563 P3 = errcd;
13564 \newline
13565
13566 \newline
13567 #pragma restore 
13568 \newline
13569
13570 \newline
13571 void
13572  some_isr () __interrupt
13573 \begin_inset LatexCommand \index{interrupt}
13574
13575 \end_inset
13576
13577  (2)
13578 \newline
13579 {
13580 \newline
13581 \InsetSpace ~
13582 \InsetSpace ~
13583 \InsetSpace ~
13584 \InsetSpace ~
13585 ...
13586 \newline
13587 \InsetSpace ~
13588 \InsetSpace ~
13589 \InsetSpace ~
13590 \InsetSpace ~
13591 set_error(10);
13592 \newline
13593 \InsetSpace ~
13594 \InsetSpace ~
13595 \InsetSpace ~
13596 \InsetSpace ~
13597 ...
13598  
13599 \newline
13600 }
13601 \end_layout
13602
13603 \begin_layout Standard
13604 In the above example the parameter 
13605 \emph on
13606 errcd
13607 \emph default
13608  for the function 
13609 \emph on
13610 set_error
13611 \emph default
13612  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13613 nooverlay was
13614  not present, this could cause unpredictable runtime behavior when called
13615  from an interrupt service routine.
13616  The #pragma\InsetSpace ~
13617 nooverlay ensures that the parameters and local variables for
13618  the function are NOT overlayed.
13619 \begin_inset VSpace bigskip
13620 \end_inset
13621
13622
13623 \end_layout
13624
13625 \begin_layout Section
13626 Interrupt Service Routines
13627 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13628
13629 \end_inset
13630
13631
13632 \end_layout
13633
13634 \begin_layout Subsection
13635 General Information
13636 \end_layout
13637
13638 \begin_layout Standard
13639 SDCC allows 
13640 \emph on
13641 i
13642 \emph default
13643 nterrupt 
13644 \emph on
13645 s
13646 \emph default
13647 ervice 
13648 \emph on
13649 r
13650 \emph default
13651 outines to be coded in C, with some extended keywords.
13652 \end_layout
13653
13654 \begin_layout Verse
13655
13656 \family typewriter
13657 void timer_isr (void) __interrupt (1) __using (1) 
13658 \newline
13659
13660 \newline
13661 \InsetSpace ~
13662 \InsetSpace ~
13663 \InsetSpace ~
13664 \InsetSpace ~
13665 ...
13666  
13667 \newline
13668 }
13669 \end_layout
13670
13671 \begin_layout Standard
13672 The optional number following the 
13673 \emph on
13674 interrupt
13675 \begin_inset LatexCommand \index{interrupt}
13676
13677 \end_inset
13678
13679
13680 \begin_inset LatexCommand \index{\_\_interrupt}
13681
13682 \end_inset
13683
13684
13685 \emph default
13686  keyword is the interrupt number this routine will service.
13687  When present, the compiler will insert a call to this routine in the interrupt
13688  vector table
13689 \begin_inset LatexCommand \index{interrupt vector table}
13690
13691 \end_inset
13692
13693  for the interrupt number specified.
13694  If you have multiple source files in your project, interrupt service routines
13695  can be present in any of them, but a prototype of the isr MUST be present
13696  or included in the file that contains the function 
13697 \emph on
13698 main
13699 \emph default
13700 .
13701  The optional (8051 specific) keyword 
13702 \emph on
13703 using
13704 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13705
13706 \end_inset
13707
13708
13709 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13710
13711 \end_inset
13712
13713
13714 \emph default
13715  can be used to tell the compiler to use the specified register bank when
13716  generating code for this function.
13717  
13718 \newline
13719 Interrupt service routines open the door for some very interesting bugs:
13720 \end_layout
13721
13722 \begin_layout Subsubsection
13723 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13724
13725 \end_inset
13726
13727 Common interrupt pitfall: variable not declared 
13728 \emph on
13729 volatile
13730 \end_layout
13731
13732 \begin_layout Standard
13733 If an interrupt service routine changes variables which are accessed by
13734  other functions these variables have to be declared 
13735 \emph on
13736 volatile
13737 \emph default
13738
13739 \begin_inset LatexCommand \index{volatile}
13740
13741 \end_inset
13742
13743 .
13744  See 
13745 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
13746
13747 \end_inset
13748
13749  .
13750 \end_layout
13751
13752 \begin_layout Subsubsection
13753 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
13754
13755 \end_inset
13756
13757 Common interrupt pitfall: 
13758 \emph on
13759 non-atomic access
13760 \end_layout
13761
13762 \begin_layout Standard
13763 If the access to these variables is not 
13764 \emph on
13765 atomic
13766 \begin_inset LatexCommand \index{atomic}
13767
13768 \end_inset
13769
13770
13771 \emph default
13772  (i.e.
13773  the processor needs more than one instruction for the access and could
13774  be interrupted while accessing the variable) the interrupt must be disabled
13775  during the access to avoid inconsistent data.
13776  
13777 \newline
13778 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
13779  and should be protected by disabling interrupts.
13780  You're not automatically on the safe side if you use 8 bit variables though.
13781  We need an example here: f.e.
13782  on the 8051 the harmless looking 
13783 \begin_inset Quotes srd
13784 \end_inset
13785
13786
13787 \family typewriter
13788 flags\InsetSpace ~
13789 |=\InsetSpace ~
13790 0x80;
13791 \family default
13792
13793 \begin_inset Quotes sld
13794 \end_inset
13795
13796  is not atomic if 
13797 \family typewriter
13798 flags
13799 \family default
13800  resides in xdata.
13801  Setting 
13802 \begin_inset Quotes srd
13803 \end_inset
13804
13805
13806 \family typewriter
13807 flags\InsetSpace ~
13808 |=\InsetSpace ~
13809 0x40;
13810 \family default
13811
13812 \begin_inset Quotes sld
13813 \end_inset
13814
13815  from within an interrupt routine might get lost if the interrupt occurs
13816  at the wrong time.
13817  
13818 \begin_inset Quotes sld
13819 \end_inset
13820
13821
13822 \family typewriter
13823 counter\InsetSpace ~
13824 +=\InsetSpace ~
13825 8;
13826 \family default
13827
13828 \begin_inset Quotes srd
13829 \end_inset
13830
13831  is not atomic on the 8051 even if 
13832 \family typewriter
13833 counter
13834 \family default
13835  is located in data memory.
13836 \newline
13837 Bugs like these are hard to reproduce and can
13838  cause a lot of trouble.
13839  
13840 \end_layout
13841
13842 \begin_layout Subsubsection
13843 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
13844
13845 \end_inset
13846
13847 Common interrupt pitfall: 
13848 \emph on
13849 stack overflow
13850 \end_layout
13851
13852 \begin_layout Standard
13853 The return address and the registers used in the interrupt service routine
13854  are saved on the stack
13855 \begin_inset LatexCommand \index{stack}
13856
13857 \end_inset
13858
13859  so there must be sufficient stack space.
13860  If there isn't variables or registers (or even the return address itself)
13861  will be corrupted.
13862  This 
13863 \emph on
13864 stack overflow
13865 \emph default
13866
13867 \begin_inset LatexCommand \index{stack overflow}
13868
13869 \end_inset
13870
13871  is most likely to happen if the interrupt occurs during the 
13872 \begin_inset Quotes sld
13873 \end_inset
13874
13875 deepest
13876 \begin_inset Quotes srd
13877 \end_inset
13878
13879  subroutine when the stack is already in use for f.e.
13880  many return addresses.
13881 \end_layout
13882
13883 \begin_layout Subsubsection
13884 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
13885
13886 \end_inset
13887
13888 Common interrupt pitfall: 
13889 \emph on
13890 use of non-reentrant functions
13891 \end_layout
13892
13893 \begin_layout Standard
13894 A special note here, int (16 bit) and long (32 bit) integer division
13895 \begin_inset LatexCommand \index{Division}
13896
13897 \end_inset
13898
13899 , multiplication
13900 \begin_inset LatexCommand \index{Multiplication}
13901
13902 \end_inset
13903
13904  & modulus
13905 \begin_inset LatexCommand \index{Modulus}
13906
13907 \end_inset
13908
13909  and floating-point
13910 \begin_inset LatexCommand \index{Floating point support}
13911
13912 \end_inset
13913
13914  operations are implemented using external support routines.
13915  If an interrupt service routine needs to do any of these operations then
13916  the support routines (as mentioned in a following section) will have to
13917  be recompiled using the
13918 \emph on
13919  -
13920 \begin_inset ERT
13921 status collapsed
13922
13923 \begin_layout Standard
13924
13925
13926 \backslash
13927 /
13928 \end_layout
13929
13930 \end_inset
13931
13932 -stack-auto
13933 \begin_inset LatexCommand \index{-\/-stack-auto}
13934
13935 \end_inset
13936
13937
13938 \emph default
13939  option and the source file will need to be compiled using the 
13940 \emph on
13941 -
13942 \begin_inset ERT
13943 status collapsed
13944
13945 \begin_layout Standard
13946
13947
13948 \backslash
13949 /
13950 \end_layout
13951
13952 \end_inset
13953
13954 -int-long-reent
13955 \emph default
13956
13957 \begin_inset LatexCommand \index{-\/-int-long-reent}
13958
13959 \end_inset
13960
13961  compiler option.
13962  
13963 \newline
13964 Note, the type promotion
13965 \begin_inset LatexCommand \index{type promotion}
13966
13967 \end_inset
13968
13969  required by ANSI C can cause 16 bit routines to be used
13970 \begin_inset Marginal
13971 status collapsed
13972
13973 \begin_layout Standard
13974
13975 \series bold
13976 \InsetSpace ~
13977 !
13978 \end_layout
13979
13980 \end_inset
13981
13982  without the programmer being aware of it.
13983  See f.e.
13984  the cast 
13985 \family typewriter
13986 (unsigned char)(tail-1)
13987 \family default
13988  within the if clause in section 
13989 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13990
13991 \end_inset
13992
13993 .
13994 \end_layout
13995
13996 \begin_layout Standard
13997 Calling other functions from an interrupt service routine is not recommended,
13998  avoid it if possible.
13999  Note that when some function is called from an interrupt service routine
14000  it should be preceded by a #pragma\InsetSpace ~
14001 nooverlay
14002 \begin_inset LatexCommand \index{\#pragma nooverlay}
14003
14004 \end_inset
14005
14006  if it is not reentrant.
14007  Furthermore nonreentrant functions should not be called from the main program
14008  while the interrupt service routine might be active.
14009  They also must not be called from low priority interrupt service routines
14010  while a high priority interrupt service routine might be active.
14011  You could use semaphores or make the function
14012 \emph on
14013  critical
14014 \emph default
14015  if all parameters are passed in registers.
14016 \newline
14017  Also see section 
14018 \begin_inset LatexCommand \ref{sub:Overlaying}
14019
14020 \end_inset
14021
14022 \InsetSpace ~
14023 about Overlaying and section 
14024 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14025
14026 \end_inset
14027
14028 \InsetSpace ~
14029 about Functions using private register banks.
14030 \begin_inset VSpace bigskip
14031 \end_inset
14032
14033
14034 \end_layout
14035
14036 \begin_layout Subsection
14037 MCS51/DS390 Interrupt Service Routines
14038 \end_layout
14039
14040 \begin_layout Standard
14041 Interrupt
14042 \begin_inset LatexCommand \index{interrupt}
14043
14044 \end_inset
14045
14046  numbers and the corresponding address & descriptions for the Standard 8051/8052
14047  are listed below.
14048  SDCC will automatically adjust the 
14049 \begin_inset LatexCommand \index{interrupt vector table}
14050
14051 \end_inset
14052
14053  to the maximum interrupt number specified.
14054 \newline
14055
14056 \end_layout
14057
14058 \begin_layout Standard
14059 \align center
14060 \begin_inset Tabular
14061 <lyxtabular version="3" rows="9" columns="3">
14062 <features>
14063 <column alignment="center" valignment="top" leftline="true" width="0in">
14064 <column alignment="left" valignment="top" leftline="true" width="0in">
14065 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14066 <row topline="true" bottomline="true">
14067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14068 \begin_inset Text
14069
14070 \begin_layout Standard
14071 Interrupt #
14072 \end_layout
14073
14074 \end_inset
14075 </cell>
14076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14077 \begin_inset Text
14078
14079 \begin_layout Standard
14080 Description
14081 \end_layout
14082
14083 \end_inset
14084 </cell>
14085 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14086 \begin_inset Text
14087
14088 \begin_layout Standard
14089 Vector Address
14090 \end_layout
14091
14092 \end_inset
14093 </cell>
14094 </row>
14095 <row topline="true">
14096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14097 \begin_inset Text
14098
14099 \begin_layout Standard
14100 0
14101 \end_layout
14102
14103 \end_inset
14104 </cell>
14105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14106 \begin_inset Text
14107
14108 \begin_layout Standard
14109 External 0
14110 \end_layout
14111
14112 \end_inset
14113 </cell>
14114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14115 \begin_inset Text
14116
14117 \begin_layout Standard
14118 0x0003
14119 \end_layout
14120
14121 \end_inset
14122 </cell>
14123 </row>
14124 <row topline="true">
14125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14126 \begin_inset Text
14127
14128 \begin_layout Standard
14129 1
14130 \end_layout
14131
14132 \end_inset
14133 </cell>
14134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14135 \begin_inset Text
14136
14137 \begin_layout Standard
14138 Timer 0
14139 \end_layout
14140
14141 \end_inset
14142 </cell>
14143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14144 \begin_inset Text
14145
14146 \begin_layout Standard
14147 0x000b
14148 \end_layout
14149
14150 \end_inset
14151 </cell>
14152 </row>
14153 <row topline="true">
14154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14155 \begin_inset Text
14156
14157 \begin_layout Standard
14158 2
14159 \end_layout
14160
14161 \end_inset
14162 </cell>
14163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14164 \begin_inset Text
14165
14166 \begin_layout Standard
14167 External 1
14168 \end_layout
14169
14170 \end_inset
14171 </cell>
14172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14173 \begin_inset Text
14174
14175 \begin_layout Standard
14176 0x0013
14177 \end_layout
14178
14179 \end_inset
14180 </cell>
14181 </row>
14182 <row topline="true">
14183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14184 \begin_inset Text
14185
14186 \begin_layout Standard
14187 3
14188 \end_layout
14189
14190 \end_inset
14191 </cell>
14192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14193 \begin_inset Text
14194
14195 \begin_layout Standard
14196 Timer 1
14197 \end_layout
14198
14199 \end_inset
14200 </cell>
14201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14202 \begin_inset Text
14203
14204 \begin_layout Standard
14205 0x001b
14206 \end_layout
14207
14208 \end_inset
14209 </cell>
14210 </row>
14211 <row topline="true">
14212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14213 \begin_inset Text
14214
14215 \begin_layout Standard
14216 4
14217 \end_layout
14218
14219 \end_inset
14220 </cell>
14221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14222 \begin_inset Text
14223
14224 \begin_layout Standard
14225 Serial
14226 \end_layout
14227
14228 \end_inset
14229 </cell>
14230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14231 \begin_inset Text
14232
14233 \begin_layout Standard
14234 0x0023
14235 \end_layout
14236
14237 \end_inset
14238 </cell>
14239 </row>
14240 <row topline="true">
14241 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14242 \begin_inset Text
14243
14244 \begin_layout Standard
14245 5
14246 \end_layout
14247
14248 \end_inset
14249 </cell>
14250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14251 \begin_inset Text
14252
14253 \begin_layout Standard
14254 Timer 2 (8052)
14255 \end_layout
14256
14257 \end_inset
14258 </cell>
14259 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14260 \begin_inset Text
14261
14262 \begin_layout Standard
14263 0x002b
14264 \end_layout
14265
14266 \end_inset
14267 </cell>
14268 </row>
14269 <row topline="true">
14270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14271 \begin_inset Text
14272
14273 \begin_layout Standard
14274 ...
14275 \end_layout
14276
14277 \end_inset
14278 </cell>
14279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14280 \begin_inset Text
14281
14282 \begin_layout Standard
14283
14284 \end_layout
14285
14286 \end_inset
14287 </cell>
14288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14289 \begin_inset Text
14290
14291 \begin_layout Standard
14292 ...
14293 \end_layout
14294
14295 \end_inset
14296 </cell>
14297 </row>
14298 <row topline="true" bottomline="true">
14299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14300 \begin_inset Text
14301
14302 \begin_layout Standard
14303 n
14304 \end_layout
14305
14306 \end_inset
14307 </cell>
14308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14309 \begin_inset Text
14310
14311 \begin_layout Standard
14312
14313 \end_layout
14314
14315 \end_inset
14316 </cell>
14317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14318 \begin_inset Text
14319
14320 \begin_layout Standard
14321 0x0003 + 8*n
14322 \end_layout
14323
14324 \end_inset
14325 </cell>
14326 </row>
14327 </lyxtabular>
14328
14329 \end_inset
14330
14331
14332 \newline
14333
14334 \end_layout
14335
14336 \begin_layout Standard
14337 If the interrupt service routine is defined without 
14338 \emph on
14339 using
14340 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14341
14342 \end_inset
14343
14344
14345 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14346
14347 \end_inset
14348
14349
14350 \emph default
14351  a register bank or with register bank 0 (
14352 \emph on
14353 using
14354 \emph default
14355  0), the compiler will save the registers used by itself on the stack upon
14356  entry and restore them at exit, however if such an interrupt service routine
14357  calls another function then the entire register bank will be saved on the
14358  stack.
14359  This scheme may be advantageous for small interrupt service routines which
14360  have low register usage.
14361 \end_layout
14362
14363 \begin_layout Standard
14364 If the interrupt service routine is defined to be using a specific register
14365  bank then only 
14366 \emph on
14367 a, b, dptr
14368 \emph default
14369  & psw are saved and restored, if such an interrupt service routine calls
14370  another function (using another register bank) then the entire register
14371  bank of the called function will be saved on the stack
14372 \begin_inset LatexCommand \index{stack}
14373
14374 \end_inset
14375
14376 .
14377  This scheme is recommended for larger interrupt service routines.
14378 \begin_inset VSpace bigskip
14379 \end_inset
14380
14381
14382 \end_layout
14383
14384 \begin_layout Subsection
14385 HC08
14386 \begin_inset LatexCommand \index{HC08}
14387
14388 \end_inset
14389
14390  Interrupt Service Routines
14391 \end_layout
14392
14393 \begin_layout Standard
14394 Since the number of interrupts
14395 \begin_inset LatexCommand \index{HC08!interrupt}
14396
14397 \end_inset
14398
14399  available is chip specific and the interrupt vector table always ends at
14400  the last byte of memory, the interrupt numbers corresponds to the interrupt
14401  vectors in reverse order of address.
14402  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14403  2 will use the interrupt vector at 0xfffa, and so on.
14404  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14405  this way; instead see section 
14406 \begin_inset LatexCommand \ref{sub:Startup-Code}
14407
14408 \end_inset
14409
14410  for details on customizing startup.
14411 \begin_inset VSpace bigskip
14412 \end_inset
14413
14414
14415 \end_layout
14416
14417 \begin_layout Subsection
14418 Z80 Interrupt Service Routines
14419 \end_layout
14420
14421 \begin_layout Standard
14422 The Z80
14423 \begin_inset LatexCommand \index{Z80}
14424
14425 \end_inset
14426
14427  uses several different methods for determining the correct interrupt
14428 \begin_inset LatexCommand \index{Z80!interrupt}
14429
14430 \end_inset
14431
14432  vector depending on the hardware implementation.
14433  Therefore, SDCC ignores the optional interrupt number and does not attempt
14434  to generate an interrupt vector table.
14435 \end_layout
14436
14437 \begin_layout Standard
14438 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14439  instruction to return from the interrupt.
14440  To write an interrupt handler for the non-maskable interrupt, which needs
14441  a RETN instruction instead, add the 
14442 \emph on
14443 critical
14444 \emph default
14445  keyword:
14446 \end_layout
14447
14448 \begin_layout Verse
14449
14450 \family typewriter
14451 void nmi_isr (void) critical interrupt
14452 \newline
14453
14454 \newline
14455 \InsetSpace ~
14456 \InsetSpace ~
14457 \InsetSpace ~
14458 \InsetSpace ~
14459 ...
14460  
14461 \newline
14462 }
14463 \end_layout
14464
14465 \begin_layout Standard
14466 However if you need to create a non-interruptable interrupt service routine
14467  you would also require the 
14468 \emph on
14469 critical
14470 \emph default
14471  keyword.
14472  To distinguish between this and an nmi_isr you must provide an interrupt
14473  number.
14474 \begin_inset VSpace bigskip
14475 \end_inset
14476
14477
14478 \end_layout
14479
14480 \begin_layout Section
14481 Enabling and Disabling Interrupts
14482 \end_layout
14483
14484 \begin_layout Subsection
14485 Critical Functions and Critical Statements
14486 \end_layout
14487
14488 \begin_layout Standard
14489 A special keyword may be associated with a block or a function declaring
14490  it as 
14491 \emph on
14492 critical
14493 \emph default
14494 .
14495  SDCC will generate code to disable all interrupts
14496 \begin_inset LatexCommand \index{interrupt}
14497
14498 \end_inset
14499
14500  upon entry to a critical function and restore the interrupt enable to the
14501  previous state before returning.
14502  Nesting critical functions will need one additional byte on the stack
14503 \begin_inset LatexCommand \index{stack}
14504
14505 \end_inset
14506
14507  for each call.
14508 \end_layout
14509
14510 \begin_layout Verse
14511
14512 \family typewriter
14513 int foo () __critical
14514 \begin_inset LatexCommand \index{critical}
14515
14516 \end_inset
14517
14518
14519 \begin_inset LatexCommand \index{\_\_critical}
14520
14521 \end_inset
14522
14523  
14524 \newline
14525
14526 \newline
14527 \InsetSpace ~
14528 \InsetSpace ~
14529 \InsetSpace ~
14530 \InsetSpace ~
14531 ...
14532  
14533 \newline
14534 \InsetSpace ~
14535 \InsetSpace ~
14536 \InsetSpace ~
14537 \InsetSpace ~
14538 ...
14539  
14540 \newline
14541 }
14542 \end_layout
14543
14544 \begin_layout Standard
14545 The critical attribute maybe used with other attributes like 
14546 \emph on
14547 reentrant.
14548 \emph default
14549
14550 \newline
14551 The keyword 
14552 \emph on
14553 critical
14554 \emph default
14555  may also be used to disable interrupts more locally:
14556 \end_layout
14557
14558 \begin_layout Verse
14559
14560 \family typewriter
14561 __critical{ i++; }
14562 \end_layout
14563
14564 \begin_layout Standard
14565 More than one statement could have been included in the block.
14566 \end_layout
14567
14568 \begin_layout Subsection
14569 Enabling and Disabling Interrupts directly
14570 \end_layout
14571
14572 \begin_layout Standard
14573 Interrupts
14574 \begin_inset LatexCommand \index{interrupt}
14575
14576 \end_inset
14577
14578  can also be disabled and enabled directly (8051):
14579 \end_layout
14580
14581 \begin_layout Verse
14582
14583 \family typewriter
14584 EA = 0;\InsetSpace ~
14585 \InsetSpace ~
14586 \InsetSpace ~
14587 \InsetSpace ~
14588 \InsetSpace ~
14589 \InsetSpace ~
14590 \InsetSpace ~
14591 \InsetSpace ~
14592 \InsetSpace ~
14593 \InsetSpace ~
14594 \InsetSpace ~
14595 \InsetSpace ~
14596 or:\InsetSpace ~
14597 \InsetSpace ~
14598 \InsetSpace ~
14599 \InsetSpace ~
14600 \InsetSpace ~
14601 \InsetSpace ~
14602 \InsetSpace ~
14603 \InsetSpace ~
14604 \InsetSpace ~
14605 \InsetSpace ~
14606 \InsetSpace ~
14607 EA_SAVE = EA;
14608 \end_layout
14609
14610 \begin_layout Verse
14611
14612 \family typewriter
14613 ...\InsetSpace ~
14614 \InsetSpace ~
14615 \InsetSpace ~
14616 \InsetSpace ~
14617 \InsetSpace ~
14618 \InsetSpace ~
14619 \InsetSpace ~
14620 \InsetSpace ~
14621 \InsetSpace ~
14622 \InsetSpace ~
14623 \InsetSpace ~
14624 \InsetSpace ~
14625 \InsetSpace ~
14626 \InsetSpace ~
14627 \InsetSpace ~
14628 \InsetSpace ~
14629 \InsetSpace ~
14630 \InsetSpace ~
14631 \InsetSpace ~
14632 \InsetSpace ~
14633 \InsetSpace ~
14634 \InsetSpace ~
14635 \InsetSpace ~
14636 \InsetSpace ~
14637 \InsetSpace ~
14638 \InsetSpace ~
14639 \InsetSpace ~
14640 \InsetSpace ~
14641 \InsetSpace ~
14642 \InsetSpace ~
14643 EA = 0;
14644 \end_layout
14645
14646 \begin_layout Verse
14647
14648 \family typewriter
14649 EA = 1;\InsetSpace ~
14650 \InsetSpace ~
14651 \InsetSpace ~
14652 \InsetSpace ~
14653 \InsetSpace ~
14654 \InsetSpace ~
14655 \InsetSpace ~
14656 \InsetSpace ~
14657 \InsetSpace ~
14658 \InsetSpace ~
14659 \InsetSpace ~
14660 \InsetSpace ~
14661 \InsetSpace ~
14662 \InsetSpace ~
14663 \InsetSpace ~
14664 \InsetSpace ~
14665 \InsetSpace ~
14666 \InsetSpace ~
14667 \InsetSpace ~
14668 \InsetSpace ~
14669 \InsetSpace ~
14670 \InsetSpace ~
14671 \InsetSpace ~
14672 \InsetSpace ~
14673 \InsetSpace ~
14674 \InsetSpace ~
14675 ...
14676 \end_layout
14677
14678 \begin_layout Verse
14679
14680 \family typewriter
14681 \InsetSpace ~
14682 \InsetSpace ~
14683 \InsetSpace ~
14684 \InsetSpace ~
14685 \InsetSpace ~
14686 \InsetSpace ~
14687 \InsetSpace ~
14688 \InsetSpace ~
14689 \InsetSpace ~
14690 \InsetSpace ~
14691 \InsetSpace ~
14692 \InsetSpace ~
14693 \InsetSpace ~
14694 \InsetSpace ~
14695 \InsetSpace ~
14696 \InsetSpace ~
14697 \InsetSpace ~
14698 \InsetSpace ~
14699 \InsetSpace ~
14700 \InsetSpace ~
14701 \InsetSpace ~
14702 \InsetSpace ~
14703 \InsetSpace ~
14704 \InsetSpace ~
14705 \InsetSpace ~
14706 \InsetSpace ~
14707 \InsetSpace ~
14708 \InsetSpace ~
14709 \InsetSpace ~
14710 \InsetSpace ~
14711 \InsetSpace ~
14712 \InsetSpace ~
14713 \InsetSpace ~
14714 EA = EA_SAVE;
14715 \end_layout
14716
14717 \begin_layout Standard
14718 On other architectures which have seperate opcodes for enabling and disabling
14719  interrupts you might want to make use of defines with inline assembly
14720 \begin_inset LatexCommand \index{Assembler routines}
14721
14722 \end_inset
14723
14724  (HC08
14725 \begin_inset LatexCommand \index{HC08!interrupt}
14726
14727 \end_inset
14728
14729 ):
14730 \end_layout
14731
14732 \begin_layout Verse
14733
14734 \family typewriter
14735 #define CLI _asm
14736 \begin_inset LatexCommand \index{\_asm}
14737
14738 \end_inset
14739
14740 \InsetSpace ~
14741 \InsetSpace ~
14742 cli\InsetSpace ~
14743 \InsetSpace ~
14744 _endasm
14745 \begin_inset LatexCommand \index{\_endasm}
14746
14747 \end_inset
14748
14749
14750 \end_layout
14751
14752 \begin_layout Verse
14753
14754 \family typewriter
14755 #define SEI _asm\InsetSpace ~
14756 \InsetSpace ~
14757 sei\InsetSpace ~
14758 \InsetSpace ~
14759 _endasm; 
14760 \end_layout
14761
14762 \begin_layout Verse
14763
14764 \family typewriter
14765 ...
14766 \end_layout
14767
14768 \begin_layout Standard
14769 Note: it is sometimes sufficient to disable only a specific interrupt source
14770  like f.e.
14771  a timer or serial interrupt by manipulating an 
14772 \emph on
14773 interrupt mask
14774 \begin_inset LatexCommand \index{interrupt mask}
14775
14776 \end_inset
14777
14778
14779 \emph default
14780  register.
14781  
14782 \end_layout
14783
14784 \begin_layout Standard
14785 Usually the time during which interrupts are disabled should be kept as
14786  short as possible.
14787  This minimizes both 
14788 \emph on
14789 interrupt latency
14790 \emph default
14791
14792 \begin_inset LatexCommand \index{interrupt latency}
14793
14794 \end_inset
14795
14796  (the time between the occurrence of the interrupt and the execution of
14797  the first code in the interrupt routine) and 
14798 \emph on
14799 interrupt jitter
14800 \emph default
14801
14802 \begin_inset LatexCommand \index{interrupt jitter}
14803
14804 \end_inset
14805
14806  (the difference between the shortest and the longest interrupt latency).
14807  These really are something different, f.e.
14808  a serial interrupt has to be served before its buffer overruns so it cares
14809  for the maximum interrupt latency, whereas it does not care about jitter.
14810  On a loudspeaker driven via a digital to analog converter which is fed
14811  by an interrupt a latency of a few milliseconds might be tolerable, whereas
14812  a much smaller jitter will be very audible.
14813 \end_layout
14814
14815 \begin_layout Standard
14816 You can reenable interrupts within an interrupt routine and on some architecture
14817 s you can make use of two (or more) levels of 
14818 \emph on
14819 interrupt priorities
14820 \emph default
14821
14822 \begin_inset LatexCommand \index{interrupt priority}
14823
14824 \end_inset
14825
14826 .
14827  On some architectures which don't support interrupt priorities these can
14828  be implemented by manipulating the interrupt mask and reenabling interrupts
14829  within the interrupt routine.
14830  Check there is sufficient space on the stack
14831 \begin_inset LatexCommand \index{stack}
14832
14833 \end_inset
14834
14835  and don't add complexity unless you have to.
14836  
14837 \end_layout
14838
14839 \begin_layout Subsection
14840 Semaphore
14841 \begin_inset LatexCommand \index{semaphore}
14842
14843 \end_inset
14844
14845  locking (mcs51/ds390)
14846 \end_layout
14847
14848 \begin_layout Standard
14849 Some architectures (mcs51/ds390) have an atomic
14850 \begin_inset LatexCommand \index{atomic}
14851
14852 \end_inset
14853
14854  bit test and
14855 \emph on
14856  
14857 \emph default
14858 clear
14859 \emph on
14860  
14861 \emph default
14862 instruction.
14863  These type of instructions are typically used in preemptive multitasking
14864  systems, where a routine f.e.
14865  claims the use of a data structure ('acquires a lock
14866 \begin_inset LatexCommand \index{lock}
14867
14868 \end_inset
14869
14870  on it'), makes some modifications and then releases the lock when the data
14871  structure is consistent again.
14872  The instruction may also be used if interrupt and non-interrupt code have
14873  to compete for a resource.
14874  With the atomic bit test and clear instruction interrupts
14875 \begin_inset LatexCommand \index{interrupt}
14876
14877 \end_inset
14878
14879  don't have to be disabled for the locking operation.
14880  
14881 \end_layout
14882
14883 \begin_layout Standard
14884 SDCC generates this instruction if the source follows this pattern:
14885 \end_layout
14886
14887 \begin_layout Verse
14888
14889 \family typewriter
14890 volatile
14891 \begin_inset LatexCommand \index{volatile}
14892
14893 \end_inset
14894
14895  bit resource_is_free; 
14896 \newline
14897
14898 \newline
14899 if (resource_is_free) 
14900 \newline
14901 \InsetSpace ~
14902 \InsetSpace ~
14903
14904 \newline
14905 \InsetSpace ~
14906 \InsetSpace ~
14907 \InsetSpace ~
14908 \InsetSpace ~
14909 resource_is_free=0; 
14910 \newline
14911 \InsetSpace ~
14912 \InsetSpace ~
14913 \InsetSpace ~
14914 \InsetSpace ~
14915 ...
14916  
14917 \newline
14918 \InsetSpace ~
14919 \InsetSpace ~
14920 \InsetSpace ~
14921 \InsetSpace ~
14922 resource_is_free=1;
14923 \newline
14924 \InsetSpace ~
14925 \InsetSpace ~
14926
14927 \end_layout
14928
14929 \begin_layout Standard
14930 Note, mcs51 and ds390 support only an atomic
14931 \begin_inset LatexCommand \index{atomic}
14932
14933 \end_inset
14934
14935  bit test and 
14936 \emph on
14937 clear
14938 \emph default
14939  instruction (as opposed to atomic bit test and 
14940 \emph on
14941 set).
14942 \end_layout
14943
14944 \begin_layout Section
14945 Functions using private register banks
14946 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
14947
14948 \end_inset
14949
14950  (mcs51/ds390)
14951 \end_layout
14952
14953 \begin_layout Standard
14954 Some architectures have support for quickly changing register sets.
14955  SDCC supports this feature with the 
14956 \emph on
14957 using
14958 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14959
14960 \end_inset
14961
14962
14963 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14964
14965 \end_inset
14966
14967
14968 \emph default
14969  attribute (which tells the compiler to use a register bank
14970 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
14971
14972 \end_inset
14973
14974  other than the default bank zero).
14975  It should only be applied to 
14976 \emph on
14977 interrupt
14978 \begin_inset LatexCommand \index{interrupt}
14979
14980 \end_inset
14981
14982
14983 \emph default
14984  functions (see footnote below).
14985  This will in most circumstances make the generated ISR code more efficient
14986  since it will not have to save registers on the stack.
14987 \end_layout
14988
14989 \begin_layout Standard
14990 The 
14991 \emph on
14992 using
14993 \emph default
14994  attribute will have no effect on the generated code for a 
14995 \emph on
14996 non-interrupt
14997 \emph default
14998  function (but may occasionally be useful anyway
14999 \begin_inset Foot
15000 status open
15001
15002 \begin_layout Standard
15003 possible exception: if a function is called ONLY from 'interrupt' functions
15004  using a particular bank, it can be declared with the same 'using' attribute
15005  as the calling 'interrupt' functions.
15006  For instance, if you have several ISRs using bank one, and all of them
15007  call memcpy(), it might make sense to create a specialized version of memcpy()
15008  'using 1', since this would prevent the ISR from having to save bank zero
15009  to the stack on entry and switch to bank zero before calling the function
15010 \end_layout
15011
15012 \end_inset
15013
15014 ).
15015 \newline
15016
15017 \emph on
15018 (pending: Note, nowadays the 
15019 \emph default
15020 using
15021 \emph on
15022  attribute has an effect on
15023 \emph default
15024  
15025 \emph on
15026 the generated code for a 
15027 \emph default
15028 non-interrupt
15029 \emph on
15030  function
15031 \emph default
15032 .
15033 \emph on
15034 )
15035 \end_layout
15036
15037 \begin_layout Standard
15038 An 
15039 \emph on
15040 interrupt
15041 \emph default
15042  function using a non-zero bank will assume that it can trash that register
15043  bank, and will not save it.
15044  Since high-priority interrupts
15045 \begin_inset LatexCommand \index{interrupts}
15046
15047 \end_inset
15048
15049
15050 \begin_inset LatexCommand \index{interrupt priority}
15051
15052 \end_inset
15053
15054  can interrupt low-priority ones on the 8051 and friends, this means that
15055  if a high-priority ISR 
15056 \emph on
15057 using
15058 \emph default
15059  a particular bank occurs while processing a low-priority ISR 
15060 \emph on
15061 using
15062 \emph default
15063  the same bank, terrible and bad things can happen.
15064  To prevent this, no single register bank should be 
15065 \emph on
15066 used
15067 \emph default
15068  by both a high priority and a low priority ISR.
15069  This is probably most easily done by having all high priority ISRs use
15070  one bank and all low priority ISRs use another.
15071  If you have an ISR which can change priority at runtime, you're on your
15072  own: I suggest using the default bank zero and taking the small performance
15073  hit.
15074 \end_layout
15075
15076 \begin_layout Standard
15077 It is most efficient if your ISR calls no other functions.
15078  If your ISR must call other functions, it is most efficient if those functions
15079  use the same bank as the ISR (see note 1 below); the next best is if the
15080  called functions use bank zero.
15081  It is very inefficient to call a function using a different, non-zero bank
15082  from an ISR.
15083  
15084 \begin_inset VSpace bigskip
15085 \end_inset
15086
15087
15088 \end_layout
15089
15090 \begin_layout Section
15091 Startup Code
15092 \begin_inset LatexCommand \label{sub:Startup-Code}
15093
15094 \end_inset
15095
15096
15097 \begin_inset LatexCommand \index{Startup code}
15098
15099 \end_inset
15100
15101
15102 \end_layout
15103
15104 \begin_layout Subsection
15105 MCS51/DS390 Startup Code
15106 \end_layout
15107
15108 \begin_layout Standard
15109 The compiler triggers the linker to link certain initialization modules
15110  from the runtime library
15111 \begin_inset LatexCommand \index{Runtime library}
15112
15113 \end_inset
15114
15115  called crt<something>.
15116  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15117  GSINIT5) is not linked unless the --xstack option is used.
15118  These modules are highly entangled by the use of special segments/areas,
15119  but a common layout is shown below:
15120 \end_layout
15121
15122 \begin_layout Verse
15123
15124 \family typewriter
15125 \series bold
15126 \size footnotesize
15127 (main.asm)
15128 \end_layout
15129
15130 \begin_layout Verse
15131
15132 \family typewriter
15133 \size footnotesize
15134 \InsetSpace ~
15135 \InsetSpace ~
15136 \InsetSpace ~
15137 \InsetSpace ~
15138 \InsetSpace ~
15139 \InsetSpace ~
15140 \InsetSpace ~
15141 \InsetSpace ~
15142 .area HOME (CODE)
15143 \newline
15144 __interrupt_vect:
15145 \newline
15146 \InsetSpace ~
15147 \InsetSpace ~
15148 \InsetSpace ~
15149 \InsetSpace ~
15150 \InsetSpace ~
15151 \InsetSpace ~
15152 \InsetSpace ~
15153 \InsetSpace ~
15154 ljmp __sdcc_gsinit_startup
15155 \end_layout
15156
15157 \begin_layout Verse
15158
15159 \family typewriter
15160 \series bold
15161 \size footnotesize
15162 (crtstart.asm)
15163 \end_layout
15164
15165 \begin_layout Verse
15166
15167 \family typewriter
15168 \size footnotesize
15169 \InsetSpace ~
15170 \InsetSpace ~
15171 \InsetSpace ~
15172 \InsetSpace ~
15173 \InsetSpace ~
15174 \InsetSpace ~
15175 \InsetSpace ~
15176 \InsetSpace ~
15177 .area GSINIT0 (CODE)
15178 \newline
15179 __sdcc_gsinit_startup::
15180 \newline
15181 \InsetSpace ~
15182 \InsetSpace ~
15183 \InsetSpace ~
15184 \InsetSpace ~
15185 \InsetSpace ~
15186 \InsetSpace ~
15187 \InsetSpace ~
15188 \InsetSpace ~
15189 mov sp,#__start__stack - 1
15190 \end_layout
15191
15192 \begin_layout Verse
15193
15194 \family typewriter
15195 \series bold
15196 \size footnotesize
15197 (crtxstack.asm)
15198 \end_layout
15199
15200 \begin_layout Verse
15201
15202 \family typewriter
15203 \size footnotesize
15204 \InsetSpace ~
15205 \InsetSpace ~
15206 \InsetSpace ~
15207 \InsetSpace ~
15208 \InsetSpace ~
15209 \InsetSpace ~
15210 \InsetSpace ~
15211 \InsetSpace ~
15212 .area GSINIT1 (CODE)
15213 \newline
15214 __sdcc_init_xstack::
15215 \newline
15216 ; Need to initialize in GSINIT1 in
15217  case the user's __sdcc_external_startup uses the xstack.
15218 \newline
15219 \InsetSpace ~
15220 \InsetSpace ~
15221 \InsetSpace ~
15222 \InsetSpace ~
15223 \InsetSpace ~
15224 \InsetSpace ~
15225 \InsetSpace ~
15226 \InsetSpace ~
15227 mov __XPAGE,#(__start__x
15228 stack >> 8)
15229 \newline
15230 \InsetSpace ~
15231 \InsetSpace ~
15232 \InsetSpace ~
15233 \InsetSpace ~
15234 \InsetSpace ~
15235 \InsetSpace ~
15236 \InsetSpace ~
15237 \InsetSpace ~
15238 mov _spx,#__start__xstack
15239 \end_layout
15240
15241 \begin_layout Verse
15242
15243 \family typewriter
15244 \series bold
15245 \size footnotesize
15246 (crtstart.asm)
15247 \end_layout
15248
15249 \begin_layout Verse
15250
15251 \family typewriter
15252 \size footnotesize
15253 \InsetSpace ~
15254 \InsetSpace ~
15255 \InsetSpace ~
15256 \InsetSpace ~
15257 \InsetSpace ~
15258 \InsetSpace ~
15259 \InsetSpace ~
15260 \InsetSpace ~
15261 .area GSINIT2 (CODE)
15262 \newline
15263 \InsetSpace ~
15264 \InsetSpace ~
15265 \InsetSpace ~
15266 \InsetSpace ~
15267 \InsetSpace ~
15268 \InsetSpace ~
15269 \InsetSpace ~
15270 \InsetSpace ~
15271 lcall __sdcc_external_startup
15272 \newline
15273 \InsetSpace ~
15274 \InsetSpace ~
15275 \InsetSpace ~
15276 \InsetSpace ~
15277 \InsetSpace ~
15278 \InsetSpace ~
15279 \InsetSpace ~
15280 \InsetSpace ~
15281 mov a,dpl
15282 \newline
15283 \InsetSpace ~
15284 \InsetSpace ~
15285 \InsetSpace ~
15286 \InsetSpace ~
15287 \InsetSpace ~
15288 \InsetSpace ~
15289 \InsetSpace ~
15290 \InsetSpace ~
15291 jz __sdcc_init_data
15292 \newline
15293 \InsetSpace ~
15294 \InsetSpace ~
15295 \InsetSpace ~
15296 \InsetSpace ~
15297 \InsetSpace ~
15298 \InsetSpace ~
15299 \InsetSpace ~
15300 \InsetSpace ~
15301 ljmp
15302  __sdcc_program_startup
15303 \newline
15304 __sdcc_init_data:
15305 \end_layout
15306
15307 \begin_layout Verse
15308
15309 \family typewriter
15310 \series bold
15311 \size footnotesize
15312 (crtxinit.asm)
15313 \end_layout
15314
15315 \begin_layout Verse
15316
15317 \family typewriter
15318 \size footnotesize
15319 \InsetSpace ~
15320 \InsetSpace ~
15321 \InsetSpace ~
15322 \InsetSpace ~
15323 \InsetSpace ~
15324 \InsetSpace ~
15325 \InsetSpace ~
15326 \InsetSpace ~
15327 .area GSINIT3 (CODE)
15328 \newline
15329 __mcs51_genXINIT::
15330 \newline
15331 \InsetSpace ~
15332 \InsetSpace ~
15333 \InsetSpace ~
15334 \InsetSpace ~
15335 \InsetSpace ~
15336 \InsetSpace ~
15337 \InsetSpace ~
15338 \InsetSpace ~
15339 mov r1,#l_XINIT
15340 \newline
15341 \InsetSpace ~
15342 \InsetSpace ~
15343 \InsetSpace ~
15344 \InsetSpace ~
15345 \InsetSpace ~
15346 \InsetSpace ~
15347 \InsetSpace ~
15348 \InsetSpace ~
15349 mov a,r1
15350 \newline
15351 \InsetSpace ~
15352 \InsetSpace ~
15353 \InsetSpace ~
15354 \InsetSpace ~
15355 \InsetSpace ~
15356 \InsetSpace ~
15357 \InsetSpace ~
15358 \InsetSpace ~
15359 orl a,#(l_XINIT
15360  >> 8)
15361 \newline
15362 \InsetSpace ~
15363 \InsetSpace ~
15364 \InsetSpace ~
15365 \InsetSpace ~
15366 \InsetSpace ~
15367 \InsetSpace ~
15368 \InsetSpace ~
15369 \InsetSpace ~
15370 jz 00003$
15371 \newline
15372 \InsetSpace ~
15373 \InsetSpace ~
15374 \InsetSpace ~
15375 \InsetSpace ~
15376 \InsetSpace ~
15377 \InsetSpace ~
15378 \InsetSpace ~
15379 \InsetSpace ~
15380 mov r2,#((l_XINIT+255) >> 8)
15381 \newline
15382 \InsetSpace ~
15383 \InsetSpace ~
15384 \InsetSpace ~
15385 \InsetSpace ~
15386 \InsetSpace ~
15387 \InsetSpace ~
15388 \InsetSpace ~
15389 \InsetSpace ~
15390 mov dptr,#s_XINIT
15391 \newline
15392 \InsetSpace ~
15393 \InsetSpace ~
15394 \InsetSpace ~
15395 \InsetSpace ~
15396 \InsetSpace ~
15397 \InsetSpace ~
15398 \InsetSpace ~
15399 \InsetSpace ~
15400 mov r0,#s_XISEG
15401 \newline
15402 \InsetSpace ~
15403 \InsetSpace ~
15404 \InsetSpace ~
15405 \InsetSpace ~
15406 \InsetSpace ~
15407 \InsetSpace ~
15408 \InsetSpace ~
15409 \InsetSpace ~
15410 mov
15411  __XPAGE,#(s_XISEG >> 8)
15412 \newline
15413 00001$:\InsetSpace ~
15414 clr a
15415 \newline
15416 \InsetSpace ~
15417 \InsetSpace ~
15418 \InsetSpace ~
15419 \InsetSpace ~
15420 \InsetSpace ~
15421 \InsetSpace ~
15422 \InsetSpace ~
15423 \InsetSpace ~
15424 movc a,@a+dptr
15425 \newline
15426 \InsetSpace ~
15427 \InsetSpace ~
15428 \InsetSpace ~
15429 \InsetSpace ~
15430 \InsetSpace ~
15431 \InsetSpace ~
15432 \InsetSpace ~
15433 \InsetSpace ~
15434 movx @r0,a
15435 \newline
15436 \InsetSpace ~
15437 \InsetSpace ~
15438 \InsetSpace ~
15439 \InsetSpace ~
15440 \InsetSpace ~
15441 \InsetSpace ~
15442 \InsetSpace ~
15443 \InsetSpace ~
15444 inc dptr
15445 \newline
15446 \InsetSpace ~
15447 \InsetSpace ~
15448 \InsetSpace ~
15449 \InsetSpace ~
15450 \InsetSpace ~
15451 \InsetSpace ~
15452 \InsetSpace ~
15453 \InsetSpace ~
15454 inc
15455  r0
15456 \newline
15457 \InsetSpace ~
15458 \InsetSpace ~
15459 \InsetSpace ~
15460 \InsetSpace ~
15461 \InsetSpace ~
15462 \InsetSpace ~
15463 \InsetSpace ~
15464 \InsetSpace ~
15465 cjne r0,#0,00002$
15466 \newline
15467 \InsetSpace ~
15468 \InsetSpace ~
15469 \InsetSpace ~
15470 \InsetSpace ~
15471 \InsetSpace ~
15472 \InsetSpace ~
15473 \InsetSpace ~
15474 \InsetSpace ~
15475 inc __XPAGE
15476 \newline
15477 00002$:\InsetSpace ~
15478 djnz r1,00001$
15479 \newline
15480 \InsetSpace ~
15481 \InsetSpace ~
15482 \InsetSpace ~
15483 \InsetSpace ~
15484 \InsetSpace ~
15485 \InsetSpace ~
15486 \InsetSpace ~
15487 \InsetSpace ~
15488 djnz r2,00001$
15489 \newline
15490 \InsetSpace ~
15491 \InsetSpace ~
15492 \InsetSpace ~
15493 \InsetSpace ~
15494 \InsetSpace ~
15495 \InsetSpace ~
15496 \InsetSpace ~
15497 \InsetSpace ~
15498 mov __XPAGE,#0
15499 xFF
15500 \newline
15501 00003$:
15502 \end_layout
15503
15504 \begin_layout Verse
15505
15506 \family typewriter
15507 \series bold
15508 \size footnotesize
15509 (crtclear.asm)
15510 \end_layout
15511
15512 \begin_layout Verse
15513
15514 \family typewriter
15515 \size footnotesize
15516 \InsetSpace ~
15517 \InsetSpace ~
15518 \InsetSpace ~
15519 \InsetSpace ~
15520 \InsetSpace ~
15521 \InsetSpace ~
15522 \InsetSpace ~
15523 \InsetSpace ~
15524 .area GSINIT4 (CODE)
15525 \newline
15526 __mcs51_genRAMCLEAR::
15527 \newline
15528 \InsetSpace ~
15529 \InsetSpace ~
15530 \InsetSpace ~
15531 \InsetSpace ~
15532 \InsetSpace ~
15533 \InsetSpace ~
15534 \InsetSpace ~
15535 \InsetSpace ~
15536 clr a
15537 \newline
15538 \InsetSpace ~
15539 \InsetSpace ~
15540 \InsetSpace ~
15541 \InsetSpace ~
15542 \InsetSpace ~
15543 \InsetSpace ~
15544 \InsetSpace ~
15545 \InsetSpace ~
15546 mov r0,#(l_IRAM-1)
15547 \newline
15548 00004$:\InsetSpace ~
15549 mov
15550  @r0,a
15551 \newline
15552 \InsetSpace ~
15553 \InsetSpace ~
15554 \InsetSpace ~
15555 \InsetSpace ~
15556 \InsetSpace ~
15557 \InsetSpace ~
15558 \InsetSpace ~
15559 \InsetSpace ~
15560 djnz r0,00004$
15561 \newline
15562 ; _mcs51_genRAMCLEAR() end
15563 \end_layout
15564
15565 \begin_layout Verse
15566
15567 \family typewriter
15568 \series bold
15569 \size footnotesize
15570 (crtxclear.asm)
15571 \end_layout
15572
15573 \begin_layout Verse
15574
15575 \family typewriter
15576 \size footnotesize
15577 \InsetSpace ~
15578 \InsetSpace ~
15579 \InsetSpace ~
15580 \InsetSpace ~
15581 \InsetSpace ~
15582 \InsetSpace ~
15583 \InsetSpace ~
15584 \InsetSpace ~
15585 .area GSINIT4 (CODE)
15586 \newline
15587 __mcs51_genXRAMCLEAR::
15588 \newline
15589 \InsetSpace ~
15590 \InsetSpace ~
15591 \InsetSpace ~
15592 \InsetSpace ~
15593 \InsetSpace ~
15594 \InsetSpace ~
15595 \InsetSpace ~
15596 \InsetSpace ~
15597 mov r0,#l_PSEG
15598 \newline
15599 \InsetSpace ~
15600 \InsetSpace ~
15601 \InsetSpace ~
15602 \InsetSpace ~
15603 \InsetSpace ~
15604 \InsetSpace ~
15605 \InsetSpace ~
15606 \InsetSpace ~
15607 mov a,r0
15608 \newline
15609 \InsetSpace ~
15610 \InsetSpace ~
15611 \InsetSpace ~
15612 \InsetSpace ~
15613 \InsetSpace ~
15614 \InsetSpace ~
15615 \InsetSpace ~
15616 \InsetSpace ~
15617 jz 00006$
15618 \newline
15619 \InsetSpace ~
15620 \InsetSpace ~
15621 \InsetSpace ~
15622 \InsetSpace ~
15623 \InsetSpace ~
15624 \InsetSpace ~
15625 \InsetSpace ~
15626 \InsetSpace ~
15627 mov
15628  r1,#s_PSEG
15629 \newline
15630 \InsetSpace ~
15631 \InsetSpace ~
15632 \InsetSpace ~
15633 \InsetSpace ~
15634 \InsetSpace ~
15635 \InsetSpace ~
15636 \InsetSpace ~
15637 \InsetSpace ~
15638 mov __XPAGE,#(s_PSEG >> 8)
15639 \newline
15640 \InsetSpace ~
15641 \InsetSpace ~
15642 \InsetSpace ~
15643 \InsetSpace ~
15644 \InsetSpace ~
15645 \InsetSpace ~
15646 \InsetSpace ~
15647 \InsetSpace ~
15648 clr a
15649 \newline
15650 00005$:\InsetSpace ~
15651 movx @r1,a
15652 \newline
15653 \InsetSpace ~
15654 \InsetSpace ~
15655 \InsetSpace ~
15656 \InsetSpace ~
15657 \InsetSpace ~
15658 \InsetSpace ~
15659 \InsetSpace ~
15660 \InsetSpace ~
15661 inc r1
15662 \newline
15663 \InsetSpace ~
15664 \InsetSpace ~
15665 \InsetSpace ~
15666 \InsetSpace ~
15667 \InsetSpace ~
15668 \InsetSpace ~
15669 \InsetSpace ~
15670 \InsetSpace ~
15671 djnz r0,00005$
15672 \newline
15673 0
15674 0006$:
15675 \newline
15676 \InsetSpace ~
15677 \InsetSpace ~
15678 \InsetSpace ~
15679 \InsetSpace ~
15680 \InsetSpace ~
15681 \InsetSpace ~
15682 \InsetSpace ~
15683 \InsetSpace ~
15684 mov r0,#l_XSEG
15685 \newline
15686 \InsetSpace ~
15687 \InsetSpace ~
15688 \InsetSpace ~
15689 \InsetSpace ~
15690 \InsetSpace ~
15691 \InsetSpace ~
15692 \InsetSpace ~
15693 \InsetSpace ~
15694 mov a,r0
15695 \newline
15696 \InsetSpace ~
15697 \InsetSpace ~
15698 \InsetSpace ~
15699 \InsetSpace ~
15700 \InsetSpace ~
15701 \InsetSpace ~
15702 \InsetSpace ~
15703 \InsetSpace ~
15704 orl a,#(l_XSEG >> 8)
15705 \newline
15706 \InsetSpace ~
15707 \InsetSpace ~
15708 \InsetSpace ~
15709 \InsetSpace ~
15710 \InsetSpace ~
15711 \InsetSpace ~
15712 \InsetSpace ~
15713 \InsetSpace ~
15714 jz 00008$
15715 \newline
15716 \InsetSpace ~
15717 \InsetSpace ~
15718 \InsetSpace ~
15719 \InsetSpace ~
15720 \InsetSpace ~
15721 \InsetSpace ~
15722 \InsetSpace ~
15723 \InsetSpace ~
15724 mov r1,#((l_XSEG
15725  + 255) >> 8)
15726 \newline
15727 \InsetSpace ~
15728 \InsetSpace ~
15729 \InsetSpace ~
15730 \InsetSpace ~
15731 \InsetSpace ~
15732 \InsetSpace ~
15733 \InsetSpace ~
15734 \InsetSpace ~
15735 mov dptr,#s_XSEG
15736 \newline
15737 \InsetSpace ~
15738 \InsetSpace ~
15739 \InsetSpace ~
15740 \InsetSpace ~
15741 \InsetSpace ~
15742 \InsetSpace ~
15743 \InsetSpace ~
15744 \InsetSpace ~
15745 clr a
15746 \newline
15747 00007$:\InsetSpace ~
15748 movx @dptr,a
15749 \newline
15750 \InsetSpace ~
15751 \InsetSpace ~
15752 \InsetSpace ~
15753 \InsetSpace ~
15754 \InsetSpace ~
15755 \InsetSpace ~
15756 \InsetSpace ~
15757 \InsetSpace ~
15758 inc dptr
15759 \newline
15760 \InsetSpace ~
15761 \InsetSpace ~
15762 \InsetSpace ~
15763 \InsetSpace ~
15764 \InsetSpace ~
15765 \InsetSpace ~
15766 \InsetSpace ~
15767 \InsetSpace ~
15768 djnz r0,00007$
15769 \newline
15770 \InsetSpace ~
15771 \InsetSpace ~
15772 \InsetSpace ~
15773 \InsetSpace ~
15774 \InsetSpace ~
15775 \InsetSpace ~
15776 \InsetSpace ~
15777 \InsetSpace ~
15778 djnz
15779  r1,00007$
15780 \newline
15781 00008$:
15782 \end_layout
15783
15784 \begin_layout Verse
15785
15786 \family typewriter
15787 \series bold
15788 \size footnotesize
15789 (crtxstack.asm)
15790 \end_layout
15791
15792 \begin_layout Verse
15793
15794 \family typewriter
15795 \size footnotesize
15796 \InsetSpace ~
15797 \InsetSpace ~
15798 \InsetSpace ~
15799 \InsetSpace ~
15800 \InsetSpace ~
15801 \InsetSpace ~
15802 \InsetSpace ~
15803 \InsetSpace ~
15804 .area GSINIT5 (CODE)
15805 \newline
15806 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
15807  modifies __XPAGE
15808 \newline
15809 ; and __mcs51_genRAMCLEAR modifies _spx.
15810 \newline
15811 \InsetSpace ~
15812 \InsetSpace ~
15813 \InsetSpace ~
15814 \InsetSpace ~
15815 \InsetSpace ~
15816 \InsetSpace ~
15817 \InsetSpace ~
15818 \InsetSpace ~
15819 mov __XPAGE,#(__start__x
15820 stack >> 8)
15821 \newline
15822 \InsetSpace ~
15823 \InsetSpace ~
15824 \InsetSpace ~
15825 \InsetSpace ~
15826 \InsetSpace ~
15827 \InsetSpace ~
15828 \InsetSpace ~
15829 \InsetSpace ~
15830 mov _spx,#__start__xstack
15831 \end_layout
15832
15833 \begin_layout Verse
15834
15835 \family typewriter
15836 \series bold
15837 \size footnotesize
15838 (application modules)
15839 \end_layout
15840
15841 \begin_layout Verse
15842
15843 \family typewriter
15844 \size footnotesize
15845 \InsetSpace ~
15846 \InsetSpace ~
15847 \InsetSpace ~
15848 \InsetSpace ~
15849 \InsetSpace ~
15850 \InsetSpace ~
15851 \InsetSpace ~
15852 \InsetSpace ~
15853 .area GSINIT (CODE)
15854 \end_layout
15855
15856 \begin_layout Verse
15857
15858 \family typewriter
15859 \series bold
15860 \size footnotesize
15861 (main.asm)
15862 \end_layout
15863
15864 \begin_layout Verse
15865
15866 \family typewriter
15867 \size footnotesize
15868 \InsetSpace ~
15869 \InsetSpace ~
15870 \InsetSpace ~
15871 \InsetSpace ~
15872 \InsetSpace ~
15873 \InsetSpace ~
15874 \InsetSpace ~
15875 \InsetSpace ~
15876 .area GSFINAL (CODE)
15877 \newline
15878 \InsetSpace ~
15879 \InsetSpace ~
15880 \InsetSpace ~
15881 \InsetSpace ~
15882 \InsetSpace ~
15883 \InsetSpace ~
15884 \InsetSpace ~
15885 \InsetSpace ~
15886 ljmp __sdcc_program_startup
15887 \newline
15888 ;---------------------------------
15889 -----------------------
15890 \newline
15891 ; Home
15892 \newline
15893 ;--------------------------------------------------
15894 ------
15895 \newline
15896 \InsetSpace ~
15897 \InsetSpace ~
15898 \InsetSpace ~
15899 \InsetSpace ~
15900 \InsetSpace ~
15901 \InsetSpace ~
15902 \InsetSpace ~
15903 \InsetSpace ~
15904 .area HOME (CODE)
15905 \newline
15906 \InsetSpace ~
15907 \InsetSpace ~
15908 \InsetSpace ~
15909 \InsetSpace ~
15910 \InsetSpace ~
15911 \InsetSpace ~
15912 \InsetSpace ~
15913 \InsetSpace ~
15914 .area CSEG (CODE)
15915 \newline
15916 __sdcc_program_startup:
15917 \newline
15918 \InsetSpace ~
15919 \InsetSpace ~
15920 \InsetSpace ~
15921 \InsetSpace ~
15922 \InsetSpace ~
15923 \InsetSpace ~
15924 \InsetSpace ~
15925 \InsetSpace ~
15926 lcall _main
15927 \newline
15928 ;
15929  return from main will lock up
15930 \newline
15931 \InsetSpace ~
15932 \InsetSpace ~
15933 \InsetSpace ~
15934 \InsetSpace ~
15935 \InsetSpace ~
15936 \InsetSpace ~
15937 \InsetSpace ~
15938 \InsetSpace ~
15939 sjmp .
15940 \end_layout
15941
15942 \begin_layout Standard
15943 One of these modules (crtstart.asm) contains a call to the C routine 
15944 \emph on
15945 _sdcc_external_startup()
15946 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
15947
15948 \end_inset
15949
15950
15951 \series bold
15952 \emph default
15953  
15954 \series default
15955 at the start of the CODE area.
15956  This routine is also in the runtime library
15957 \begin_inset LatexCommand \index{Runtime library}
15958
15959 \end_inset
15960
15961  and returns 0 by default.
15962  If this routine returns a non-zero value, the static & global variable
15963  initialization will be skipped and the function main will be invoked.
15964  Otherwise static & global variables will be initialized before the function
15965  main is invoked.
15966  You could add an 
15967 \emph on
15968 _sdcc_external_startup()
15969 \emph default
15970  routine to your program to override the default if you need to setup hardware
15971  or perform some other critical operation prior to static & global variable
15972  initialization
15973 \begin_inset LatexCommand \index{Variable initialization}
15974
15975 \end_inset
15976
15977 .
15978  On some mcs51 variants xdata
15979 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
15980
15981 \end_inset
15982
15983  memory has to be explicitly enabled before it can be accessed or if the
15984  watchdog
15985 \begin_inset LatexCommand \index{watchdog}
15986
15987 \end_inset
15988
15989  needs to be disabled, this is the place to do it.
15990  The startup code clears all internal data memory, 256 bytes by default,
15991  but from 0 to n-1 if 
15992 \emph on
15993 -
15994 \begin_inset ERT
15995 status collapsed
15996
15997 \begin_layout Standard
15998
15999
16000 \backslash
16001 /
16002 \end_layout
16003
16004 \end_inset
16005
16006 -iram-size
16007 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16008
16009 \end_inset
16010
16011 n
16012 \emph default
16013  is used.
16014  (recommended for Chipcon CC1010).
16015 \end_layout
16016
16017 \begin_layout Standard
16018 See also the compiler options 
16019 \emph on
16020 -
16021 \begin_inset ERT
16022 status collapsed
16023
16024 \begin_layout Standard
16025
16026
16027 \backslash
16028 /
16029 \end_layout
16030
16031 \end_inset
16032
16033 -no-xinit
16034 \emph default
16035 -
16036 \emph on
16037 opt
16038 \emph default
16039
16040 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16041
16042 \end_inset
16043
16044
16045 \emph on
16046 -
16047 \begin_inset ERT
16048 status collapsed
16049
16050 \begin_layout Standard
16051
16052
16053 \backslash
16054 /
16055 \end_layout
16056
16057 \end_inset
16058
16059 -main-return
16060 \emph default
16061
16062 \begin_inset LatexCommand \index{-\/-main-return}
16063
16064 \end_inset
16065
16066  and section 
16067 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16068
16069 \end_inset
16070
16071  about MCS51-variants.
16072 \begin_inset VSpace bigskip
16073 \end_inset
16074
16075
16076 \end_layout
16077
16078 \begin_layout Subsection
16079 HC08 Startup Code
16080 \end_layout
16081
16082 \begin_layout Standard
16083 The HC08
16084 \begin_inset LatexCommand \index{HC08}
16085
16086 \end_inset
16087
16088  startup code follows the same scheme as the MCS51 startup code.
16089 \begin_inset VSpace bigskip
16090 \end_inset
16091
16092
16093 \end_layout
16094
16095 \begin_layout Subsection
16096 Z80 Startup Code
16097 \end_layout
16098
16099 \begin_layout Standard
16100 On the Z80
16101 \begin_inset LatexCommand \index{Z80}
16102
16103 \end_inset
16104
16105  the startup code is inserted by linking with crt0.o which is generated from
16106  sdcc/device/lib/z80/crt0.s.
16107  If you need a different startup code you can use the compiler option 
16108 \emph on
16109 -
16110 \series bold
16111 \emph default
16112
16113 \begin_inset ERT
16114 status collapsed
16115
16116 \begin_layout Standard
16117
16118
16119 \backslash
16120 /
16121 \end_layout
16122
16123 \end_inset
16124
16125
16126 \series default
16127 \emph on
16128 -no-std-crt0
16129 \emph default
16130
16131 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16132
16133 \end_inset
16134
16135  and provide your own crt0.o.
16136  
16137 \begin_inset VSpace bigskip
16138 \end_inset
16139
16140
16141 \end_layout
16142
16143 \begin_layout Section
16144 Inline Assembler Code
16145 \begin_inset LatexCommand \index{Assembler routines}
16146
16147 \end_inset
16148
16149
16150 \end_layout
16151
16152 \begin_layout Subsection
16153 A Step by Step Introduction
16154 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16155
16156 \end_inset
16157
16158
16159 \end_layout
16160
16161 \begin_layout Standard
16162 Starting from a small snippet of c-code this example shows for the MCS51
16163  how to use inline assembly, access variables, a function parameter and
16164  an array in xdata memory.
16165  The example uses an MCS51 here but is easily adapted for other architectures.
16166  This is a buffer routine which should be optimized:
16167 \end_layout
16168
16169 \begin_layout Verse
16170
16171 \family typewriter
16172 \size footnotesize
16173 unsigned char __far
16174 \begin_inset LatexCommand \index{far (storage class)}
16175
16176 \end_inset
16177
16178
16179 \begin_inset LatexCommand \index{\_\_far (storage class)}
16180
16181 \end_inset
16182
16183  __at
16184 \begin_inset LatexCommand \index{at}
16185
16186 \end_inset
16187
16188
16189 \begin_inset LatexCommand \index{\_\_at}
16190
16191 \end_inset
16192
16193 (0x7f00) buf[0x100];
16194 \begin_inset LatexCommand \index{Aligned array}
16195
16196 \end_inset
16197
16198
16199 \newline
16200 unsigned char head, tail;\InsetSpace ~
16201 \InsetSpace ~
16202 \InsetSpace ~
16203 \InsetSpace ~
16204 \InsetSpace ~
16205 \InsetSpace ~
16206 \InsetSpace ~
16207 \InsetSpace ~
16208 \InsetSpace ~
16209 \InsetSpace ~
16210 \InsetSpace ~
16211 \InsetSpace ~
16212 \InsetSpace ~
16213 \InsetSpace ~
16214 \InsetSpace ~
16215 \InsetSpace ~
16216 \InsetSpace ~
16217 /* if interrupts
16218 \begin_inset LatexCommand \index{interrupt}
16219
16220 \end_inset
16221
16222  are involved see
16223 \newline
16224 \InsetSpace ~
16225 \InsetSpace ~
16226 \InsetSpace ~
16227 \InsetSpace ~
16228 \InsetSpace ~
16229 \InsetSpace ~
16230 \InsetSpace ~
16231 \InsetSpace ~
16232 \InsetSpace ~
16233 \InsetSpace ~
16234 \InsetSpace ~
16235 \InsetSpace ~
16236 \InsetSpace ~
16237 \InsetSpace ~
16238 \InsetSpace ~
16239 \InsetSpace ~
16240 \InsetSpace ~
16241 \InsetSpace ~
16242 \InsetSpace ~
16243 \InsetSpace ~
16244 \InsetSpace ~
16245 \InsetSpace ~
16246 \InsetSpace ~
16247 \InsetSpace ~
16248 \InsetSpace ~
16249 \InsetSpace ~
16250 \InsetSpace ~
16251 \InsetSpace ~
16252 \InsetSpace ~
16253 \InsetSpace ~
16254 \InsetSpace ~
16255 \InsetSpace ~
16256 \InsetSpace ~
16257 \InsetSpace ~
16258 \InsetSpace ~
16259 \InsetSpace ~
16260 \InsetSpace ~
16261 \InsetSpace ~
16262 \InsetSpace ~
16263 \InsetSpace ~
16264 \InsetSpace ~
16265 \InsetSpace ~
16266 \InsetSpace ~
16267 \InsetSpace ~
16268 \InsetSpace ~
16269 section 
16270 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16271
16272 \end_inset
16273
16274  about
16275 \series bold
16276  volatile
16277 \series default
16278  */
16279 \newline
16280
16281 \newline
16282 void to_buffer( unsigned char c ) 
16283 \newline
16284 {
16285 \newline
16286 \InsetSpace ~
16287 \InsetSpace ~
16288 \InsetSpace ~
16289 \InsetSpace ~
16290 if( head != (unsigned char)(tail-1)
16291  )\InsetSpace ~
16292 /* cast 
16293 \series bold
16294 needed
16295 \series default
16296  to avoid promotion
16297 \begin_inset LatexCommand \index{promotion to signed int}
16298
16299 \end_inset
16300
16301
16302 \begin_inset LatexCommand \index{type promotion}
16303
16304 \end_inset
16305
16306  to integer */
16307 \begin_inset Marginal
16308 status collapsed
16309
16310 \begin_layout Standard
16311
16312 \series bold
16313 \InsetSpace ~
16314 !
16315 \end_layout
16316
16317 \end_inset
16318
16319
16320 \newline
16321 \InsetSpace ~
16322 \InsetSpace ~
16323 \InsetSpace ~
16324 \InsetSpace ~
16325 \InsetSpace ~
16326 \InsetSpace ~
16327 \InsetSpace ~
16328 \InsetSpace ~
16329 buf[ head++ ] = c;\InsetSpace ~
16330 \InsetSpace ~
16331 \InsetSpace ~
16332 \InsetSpace ~
16333 \InsetSpace ~
16334 \InsetSpace ~
16335 \InsetSpace ~
16336 \InsetSpace ~
16337 \InsetSpace ~
16338 \InsetSpace ~
16339 \InsetSpace ~
16340 \InsetSpace ~
16341 \InsetSpace ~
16342 \InsetSpace ~
16343 \InsetSpace ~
16344 \InsetSpace ~
16345 /* access to a 256 byte aligned array */
16346 \newline
16347
16348 \end_layout
16349
16350 \begin_layout Standard
16351 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16352  then a corresponding buffer.asm file is generated.
16353  We define a new function 
16354 \family typewriter
16355 to_buffer_asm()
16356 \family default
16357  in file buffer.c in which we cut and paste the generated code, removing
16358  unwanted comments and some ':'.
16359  Then add 
16360 \begin_inset Quotes sld
16361 \end_inset
16362
16363
16364 \series bold
16365 _asm
16366 \series default
16367
16368 \begin_inset Quotes srd
16369 \end_inset
16370
16371  and 
16372 \begin_inset Quotes sld
16373 \end_inset
16374
16375
16376 \series bold
16377 _endasm;
16378 \series default
16379
16380 \begin_inset Quotes srd
16381 \end_inset
16382
16383
16384 \begin_inset Foot
16385 status open
16386
16387 \begin_layout Standard
16388 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16389  and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16390  has to be used.
16391  The latter is also used in the library functions.
16392 \end_layout
16393
16394 \end_inset
16395
16396  to the beginning and the end of the function body:
16397 \end_layout
16398
16399 \begin_layout Verse
16400
16401 \family typewriter
16402 \size footnotesize
16403 /* With a cut and paste from the .asm file, we have something to start with.
16404 \newline
16405 \InsetSpace ~
16406 \InsetSpace ~
16407 \InsetSpace ~
16408 The
16409  function is not yet OK! (registers aren't saved) */ 
16410 \newline
16411 void to_buffer_asm(
16412  unsigned char c ) 
16413 \newline
16414
16415 \newline
16416 \InsetSpace ~
16417 \InsetSpace ~
16418 \InsetSpace ~
16419 \InsetSpace ~
16420 _asm
16421 \begin_inset LatexCommand \index{\_asm}
16422
16423 \end_inset
16424
16425
16426 \begin_inset LatexCommand \index{\_\_asm}
16427
16428 \end_inset
16429
16430
16431 \newline
16432 \InsetSpace ~
16433 \InsetSpace ~
16434 \InsetSpace ~
16435 \InsetSpace ~
16436 mov\InsetSpace ~
16437 \InsetSpace ~
16438 r2,dpl 
16439 \newline
16440 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16441 /* cast 
16442 \series bold
16443 needed
16444 \series default
16445  to avoid promotion
16446 \begin_inset LatexCommand \index{promotion to signed int}
16447
16448 \end_inset
16449
16450
16451 \begin_inset LatexCommand \index{type promotion}
16452
16453 \end_inset
16454
16455  to integer */
16456 \newline
16457 \InsetSpace ~
16458 \InsetSpace ~
16459 \InsetSpace ~
16460 \InsetSpace ~
16461 mov\InsetSpace ~
16462 \InsetSpace ~
16463 a,_tail 
16464 \newline
16465 \InsetSpace ~
16466 \InsetSpace ~
16467 \InsetSpace ~
16468 \InsetSpace ~
16469 dec\InsetSpace ~
16470 \InsetSpace ~
16471
16472 \newline
16473 \InsetSpace ~
16474 \InsetSpace ~
16475 \InsetSpace ~
16476 \InsetSpace ~
16477 mov\InsetSpace ~
16478 \InsetSpace ~
16479 r3,a 
16480 \newline
16481 \InsetSpace ~
16482 \InsetSpace ~
16483 \InsetSpace ~
16484 \InsetSpace ~
16485 mov\InsetSpace ~
16486 \InsetSpace ~
16487 a,_head 
16488 \newline
16489 \InsetSpace ~
16490 \InsetSpace ~
16491 \InsetSpace ~
16492 \InsetSpace ~
16493 cjne a,ar3,00106$ 
16494 \newline
16495 \InsetSpace ~
16496 \InsetSpace ~
16497 \InsetSpace ~
16498 \InsetSpace ~
16499 ret
16500 \newline
16501 00106$:
16502  
16503 \newline
16504 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16505 \begin_inset LatexCommand \index{Aligned array}
16506
16507 \end_inset
16508
16509
16510 \newline
16511 \InsetSpace ~
16512 \InsetSpace ~
16513 \InsetSpace ~
16514 \InsetSpace ~
16515 mov\InsetSpace ~
16516 \InsetSpace ~
16517 r3,_head 
16518 \newline
16519 \InsetSpace ~
16520 \InsetSpace ~
16521 \InsetSpace ~
16522 \InsetSpace ~
16523 inc\InsetSpace ~
16524 \InsetSpace ~
16525 _head 
16526 \newline
16527 \InsetSpace ~
16528 \InsetSpace ~
16529 \InsetSpace ~
16530 \InsetSpace ~
16531 mov\InsetSpace ~
16532 \InsetSpace ~
16533 dpl,r3 
16534 \newline
16535 \InsetSpace ~
16536 \InsetSpace ~
16537 \InsetSpace ~
16538 \InsetSpace ~
16539 mov\InsetSpace ~
16540 \InsetSpace ~
16541 dph,#(_buf >> 8) 
16542 \newline
16543 \InsetSpace ~
16544 \InsetSpace ~
16545 \InsetSpace ~
16546 \InsetSpace ~
16547 mov\InsetSpace ~
16548 \InsetSpace ~
16549 a,r2 
16550 \newline
16551 \InsetSpace ~
16552 \InsetSpace ~
16553 \InsetSpace ~
16554 \InsetSpace ~
16555 movx @dptr,a
16556  
16557 \newline
16558 00103$: 
16559 \newline
16560 \InsetSpace ~
16561 \InsetSpace ~
16562 \InsetSpace ~
16563 \InsetSpace ~
16564 ret
16565 \newline
16566 \InsetSpace ~
16567 \InsetSpace ~
16568 \InsetSpace ~
16569 \InsetSpace ~
16570 _endasm
16571 \begin_inset LatexCommand \index{\_endasm}
16572
16573 \end_inset
16574
16575
16576 \begin_inset LatexCommand \index{\_\_endasm}
16577
16578 \end_inset
16579
16580 ;
16581 \newline
16582
16583 \end_layout
16584
16585 \begin_layout Standard
16586 The new file buffer.c should compile with only one warning about the unreferenced
16587  function argument 'c'.
16588  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16589  (1) and finally have:
16590 \end_layout
16591
16592 \begin_layout Verse
16593
16594 \family typewriter
16595 \size footnotesize
16596 unsigned char __far __at(0x7f00) buf[0x100];
16597 \newline
16598 unsigned char head, tail;
16599 \newline
16600 #define
16601  USE_ASSEMBLY (1)
16602 \newline
16603
16604 \newline
16605 #if !USE_ASSEMBLY
16606 \newline
16607
16608 \newline
16609 void to_buffer( unsigned char c )
16610 \newline
16611 {
16612 \newline
16613 \InsetSpace ~
16614 \InsetSpace ~
16615 \InsetSpace ~
16616 \InsetSpace ~
16617 if(
16618  head != (unsigned char)(tail-1) )
16619 \newline
16620 \InsetSpace ~
16621 \InsetSpace ~
16622 \InsetSpace ~
16623 \InsetSpace ~
16624 \InsetSpace ~
16625 \InsetSpace ~
16626 \InsetSpace ~
16627 \InsetSpace ~
16628 buf[ head++ ] = c;
16629 \newline
16630 }
16631 \newline
16632
16633 \newline
16634 #else
16635 \newline
16636
16637 \newline
16638 void to_buffer(
16639  unsigned char c )
16640 \newline
16641 {
16642 \newline
16643 \InsetSpace ~
16644 \InsetSpace ~
16645 \InsetSpace ~
16646 \InsetSpace ~
16647 c; // to avoid warning: unreferenced function argument
16648 \newline
16649 \InsetSpace ~
16650 \InsetSpace ~
16651 \InsetSpace ~
16652 \InsetSpace ~
16653 _asm
16654 \begin_inset LatexCommand \index{\_asm}
16655
16656 \end_inset
16657
16658
16659 \begin_inset LatexCommand \index{\_\_asm}
16660
16661 \end_inset
16662
16663
16664 \newline
16665 \InsetSpace ~
16666 \InsetSpace ~
16667 \InsetSpace ~
16668 \InsetSpace ~
16669 \InsetSpace ~
16670 \InsetSpace ~
16671 \InsetSpace ~
16672 \InsetSpace ~
16673 ; save used registers here.
16674  
16675 \newline
16676 \InsetSpace ~
16677 \InsetSpace ~
16678 \InsetSpace ~
16679 \InsetSpace ~
16680 \InsetSpace ~
16681 \InsetSpace ~
16682 \InsetSpace ~
16683 \InsetSpace ~
16684 ; If we were still using r2,r3 we would have to push them here.
16685  
16686 \newline
16687 ; if( head != (unsigned char)(tail-1) )
16688 \newline
16689 \InsetSpace ~
16690 \InsetSpace ~
16691 \InsetSpace ~
16692 \InsetSpace ~
16693 \InsetSpace ~
16694 \InsetSpace ~
16695 \InsetSpace ~
16696 \InsetSpace ~
16697 mov\InsetSpace ~
16698  a,_tail
16699 \newline
16700 \InsetSpace ~
16701 \InsetSpace ~
16702 \InsetSpace ~
16703 \InsetSpace ~
16704 \InsetSpace ~
16705 \InsetSpace ~
16706 \InsetSpace ~
16707 \InsetSpace ~
16708 dec\InsetSpace ~
16709  a
16710 \newline
16711 \InsetSpace ~
16712 \InsetSpace ~
16713 \InsetSpace ~
16714 \InsetSpace ~
16715 \InsetSpace ~
16716 \InsetSpace ~
16717 \InsetSpace ~
16718 \InsetSpace ~
16719 xrl\InsetSpace ~
16720  a,_head
16721 \newline
16722 \InsetSpace ~
16723 \InsetSpace ~
16724 \InsetSpace ~
16725 \InsetSpace ~
16726 \InsetSpace ~
16727 \InsetSpace ~
16728 \InsetSpace ~
16729 \InsetSpace ~
16730 ; we
16731  could do an ANL a,#0x0f here to use a smaller buffer (see below)
16732 \newline
16733 \InsetSpace ~
16734 \InsetSpace ~
16735 \InsetSpace ~
16736 \InsetSpace ~
16737 \InsetSpace ~
16738 \InsetSpace ~
16739 \InsetSpace ~
16740 \InsetSpace ~
16741 jz\InsetSpace ~
16742 \InsetSpace ~
16743  t_b_end$
16744 \newline
16745 \InsetSpace ~
16746 \InsetSpace ~
16747 \InsetSpace ~
16748 \InsetSpace ~
16749 \InsetSpace ~
16750 \InsetSpace ~
16751 \InsetSpace ~
16752 \InsetSpace ~
16753 ;
16754 \newline
16755 ;
16756  buf[ head++ ] = c;
16757 \newline
16758 \InsetSpace ~
16759 \InsetSpace ~
16760 \InsetSpace ~
16761 \InsetSpace ~
16762 \InsetSpace ~
16763 \InsetSpace ~
16764 \InsetSpace ~
16765 \InsetSpace ~
16766 mov\InsetSpace ~
16767  a,dpl \InsetSpace ~
16768 \InsetSpace ~
16769 \InsetSpace ~
16770 \InsetSpace ~
16771 \InsetSpace ~
16772 \InsetSpace ~
16773 \InsetSpace ~
16774 ; dpl holds lower byte of function argument
16775 \newline
16776 \InsetSpace ~
16777 \InsetSpace ~
16778 \InsetSpace ~
16779 \InsetSpace ~
16780 \InsetSpace ~
16781 \InsetSpace ~
16782 \InsetSpace ~
16783 \InsetSpace ~
16784 mov\InsetSpace ~
16785
16786  dpl,_head \InsetSpace ~
16787 \InsetSpace ~
16788 \InsetSpace ~
16789 ; buf is 0x100 byte aligned so head can be used directly
16790 \newline
16791 \InsetSpace ~
16792 \InsetSpace ~
16793 \InsetSpace ~
16794 \InsetSpace ~
16795 \InsetSpace ~
16796 \InsetSpace ~
16797 \InsetSpace ~
16798 \InsetSpace ~
16799 mov\InsetSpace ~
16800  dph,#(_bu
16801 f>>8)
16802 \newline
16803 \InsetSpace ~
16804 \InsetSpace ~
16805 \InsetSpace ~
16806 \InsetSpace ~
16807 \InsetSpace ~
16808 \InsetSpace ~
16809 \InsetSpace ~
16810 \InsetSpace ~
16811 movx @dptr,a
16812 \newline
16813 \InsetSpace ~
16814 \InsetSpace ~
16815 \InsetSpace ~
16816 \InsetSpace ~
16817 \InsetSpace ~
16818 \InsetSpace ~
16819 \InsetSpace ~
16820 \InsetSpace ~
16821 inc \InsetSpace ~
16822 _head
16823 \newline
16824 \InsetSpace ~
16825 \InsetSpace ~
16826 \InsetSpace ~
16827 \InsetSpace ~
16828 \InsetSpace ~
16829 \InsetSpace ~
16830 \InsetSpace ~
16831 \InsetSpace ~
16832 ; we could do an ANL _head,#0x0f here to use a
16833  smaller buffer (see above)
16834 \newline
16835 t_b_end$:
16836 \newline
16837 \InsetSpace ~
16838 \InsetSpace ~
16839 \InsetSpace ~
16840 \InsetSpace ~
16841 \InsetSpace ~
16842 \InsetSpace ~
16843 \InsetSpace ~
16844 \InsetSpace ~
16845 ; restore used registers here 
16846 \newline
16847 \InsetSpace ~
16848 \InsetSpace ~
16849 \InsetSpace ~
16850 \InsetSpace ~
16851 _endasm
16852 \begin_inset LatexCommand \index{\_endasm}
16853
16854 \end_inset
16855
16856
16857 \begin_inset LatexCommand \index{\_\_endasm}
16858
16859 \end_inset
16860
16861 ;
16862 \newline
16863 }
16864 \newline
16865 #endif
16866 \end_layout
16867
16868 \begin_layout Standard
16869 The inline assembler code can contain any valid code understood by the assembler
16870 , this includes any assembler directives and comment lines.
16871  The assembler does not like some characters like ':' or ''' in comments.
16872  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
16873 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
16874
16875 \end_inset
16876
16877
16878 \begin_inset LatexCommand \index{Assembler documentation}
16879
16880 \end_inset
16881
16882  or online at 
16883 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
16884
16885 \end_inset
16886
16887 \InsetSpace ~
16888 .
16889 \end_layout
16890
16891 \begin_layout Standard
16892 The compiler does not do any validation of the code within the 
16893 \family typewriter
16894 _asm
16895 \begin_inset LatexCommand \index{\_asm}
16896
16897 \end_inset
16898
16899
16900 \begin_inset LatexCommand \index{\_\_asm}
16901
16902 \end_inset
16903
16904  ...
16905  _endasm
16906 \size footnotesize
16907
16908 \begin_inset LatexCommand \index{\_endasm}
16909
16910 \end_inset
16911
16912
16913 \begin_inset LatexCommand \index{\_\_endasm}
16914
16915 \end_inset
16916
16917
16918 \size default
16919 ;
16920 \family default
16921  keyword pair.
16922  Specifically it will not know which registers are used and thus register
16923  pushing/popping
16924 \begin_inset LatexCommand \index{push/pop}
16925
16926 \end_inset
16927
16928  has to be done manually.
16929  
16930 \end_layout
16931
16932 \begin_layout Standard
16933 It is recommended that each assembly instruction (including labels) be placed
16934  in a separate line (as the example shows).
16935  When the -
16936 \begin_inset ERT
16937 status collapsed
16938
16939 \begin_layout Standard
16940
16941
16942 \backslash
16943 /
16944 \end_layout
16945
16946 \end_inset
16947
16948 -
16949 \emph on
16950 peep-asm
16951 \begin_inset LatexCommand \index{-\/-peep-asm}
16952
16953 \end_inset
16954
16955
16956 \emph default
16957  command line option is used, the inline assembler code will be passed through
16958  the peephole optimizer
16959 \begin_inset LatexCommand \index{Peephole optimizer}
16960
16961 \end_inset
16962
16963 .
16964  There are only a few (if any) cases where this option makes sense, it might
16965  cause some unexpected changes in the inline assembler code.
16966  Please go through the peephole optimizer rules defined in file 
16967 \emph on
16968 SDCCpeeph.def
16969 \emph default
16970  before using this option.
16971 \end_layout
16972
16973 \begin_layout Subsection
16974 Naked Functions
16975 \begin_inset LatexCommand \label{sub:Naked-Functions}
16976
16977 \end_inset
16978
16979
16980 \begin_inset LatexCommand \index{Naked functions}
16981
16982 \end_inset
16983
16984
16985 \end_layout
16986
16987 \begin_layout Standard
16988 A special keyword may be associated with a function declaring it as 
16989 \emph on
16990 _naked
16991 \begin_inset LatexCommand \index{\_naked}
16992
16993 \end_inset
16994
16995
16996 \begin_inset LatexCommand \index{\_\_naked}
16997
16998 \end_inset
16999
17000 .
17001  
17002 \emph default
17003 The 
17004 \emph on
17005 _naked
17006 \emph default
17007  function modifier attribute prevents the compiler from generating prologue
17008 \begin_inset LatexCommand \index{function prologue}
17009
17010 \end_inset
17011
17012  and epilogue
17013 \begin_inset LatexCommand \index{function epilogue}
17014
17015 \end_inset
17016
17017  code for that function.
17018  This means that the user is entirely responsible for such things as saving
17019  any registers that may need to be preserved, selecting the proper register
17020  bank, generating the 
17021 \emph on
17022 return
17023 \emph default
17024  instruction at the end, etc.
17025  Practically, this means that the contents of the function must be written
17026  in inline assembler.
17027  This is particularly useful for interrupt functions, which can have a large
17028  (and often unnecessary) prologue/epilogue.
17029  For example, compare the code generated by these two functions:
17030 \end_layout
17031
17032 \begin_layout Verse
17033
17034 \family typewriter
17035 volatile
17036 \begin_inset LatexCommand \index{volatile}
17037
17038 \end_inset
17039
17040  data unsigned char counter;
17041 \newline
17042
17043 \newline
17044 void simpleInterrupt(void) __interrupt
17045 \begin_inset LatexCommand \index{interrupt}
17046
17047 \end_inset
17048
17049
17050 \begin_inset LatexCommand \index{\_\_interrupt}
17051
17052 \end_inset
17053
17054  (1)
17055 \newline
17056 {
17057 \newline
17058 \InsetSpace ~
17059 \InsetSpace ~
17060 \InsetSpace ~
17061 \InsetSpace ~
17062 counter++;
17063 \newline
17064 }
17065 \newline
17066
17067 \newline
17068 void nakedInterrupt(void) __interrupt (2) __naked
17069 \newline
17070 {
17071 \newline
17072 \InsetSpace ~
17073 \InsetSpace ~
17074 \InsetSpace ~
17075 \InsetSpace ~
17076 _asm
17077 \begin_inset LatexCommand \index{\_asm}
17078
17079 \end_inset
17080
17081
17082 \begin_inset LatexCommand \index{\_\_asm}
17083
17084 \end_inset
17085
17086
17087 \newline
17088 \InsetSpace ~
17089 \InsetSpace ~
17090 \InsetSpace ~
17091 \InsetSpace ~
17092 \InsetSpace ~
17093 \InsetSpace ~
17094 inc\InsetSpace ~
17095 \InsetSpace ~
17096 \InsetSpace ~
17097 \InsetSpace ~
17098 \InsetSpace ~
17099 _counter ; does not change flags, no need to save psw
17100 \newline
17101 \InsetSpace ~
17102 \InsetSpace ~
17103 \InsetSpace ~
17104 \InsetSpace ~
17105 \InsetSpace ~
17106 \InsetSpace ~
17107 reti\InsetSpace ~
17108 \InsetSpace ~
17109 \InsetSpace ~
17110 \InsetSpace ~
17111 ; MUST explicitly
17112  include ret or reti in _naked function.
17113 \newline
17114 \InsetSpace ~
17115 \InsetSpace ~
17116 \InsetSpace ~
17117 \InsetSpace ~
17118 _endasm
17119 \begin_inset LatexCommand \index{\_endasm}
17120
17121 \end_inset
17122
17123
17124 \begin_inset LatexCommand \index{\_\_endasm}
17125
17126 \end_inset
17127
17128 ;
17129 \newline
17130 }
17131 \end_layout
17132
17133 \begin_layout Standard
17134 For an 8051 target, the generated simpleInterrupt looks like:
17135 \end_layout
17136
17137 \begin_layout Verse
17138
17139 \family typewriter
17140 Note, this is an 
17141 \emph on
17142 outdated
17143 \emph default
17144  example, recent versions of SDCC generate
17145 \newline
17146 the 
17147 \emph on
17148 same
17149 \emph default
17150  code for simpleInterrupt() and nakedInterrupt()!
17151 \newline
17152
17153 \newline
17154 _simpleInterrupt:
17155 \newline
17156 \InsetSpace ~
17157 \InsetSpace ~
17158 \InsetSpace ~
17159 \InsetSpace ~
17160 push\InsetSpace ~
17161 \InsetSpace ~
17162 \InsetSpace ~
17163 \InsetSpace ~
17164 acc
17165 \newline
17166 \InsetSpace ~
17167 \InsetSpace ~
17168 \InsetSpace ~
17169 \InsetSpace ~
17170 push\InsetSpace ~
17171 \InsetSpace ~
17172 \InsetSpace ~
17173 \InsetSpace ~
17174 b
17175 \newline
17176 \InsetSpace ~
17177 \InsetSpace ~
17178 \InsetSpace ~
17179 \InsetSpace ~
17180 pu
17181 sh\InsetSpace ~
17182 \InsetSpace ~
17183 \InsetSpace ~
17184 \InsetSpace ~
17185 dpl
17186 \newline
17187 \InsetSpace ~
17188 \InsetSpace ~
17189 \InsetSpace ~
17190 \InsetSpace ~
17191 push\InsetSpace ~
17192 \InsetSpace ~
17193 \InsetSpace ~
17194 \InsetSpace ~
17195 dph
17196 \newline
17197 \InsetSpace ~
17198 \InsetSpace ~
17199 \InsetSpace ~
17200 \InsetSpace ~
17201 push\InsetSpace ~
17202 \InsetSpace ~
17203 \InsetSpace ~
17204 \InsetSpace ~
17205 psw
17206 \newline
17207 \InsetSpace ~
17208 \InsetSpace ~
17209 \InsetSpace ~
17210 \InsetSpace ~
17211 mov\InsetSpace ~
17212 \InsetSpace ~
17213 \InsetSpace ~
17214 \InsetSpace ~
17215 \InsetSpace ~
17216 psw,#0x00
17217 \newline
17218 \InsetSpace ~
17219 \InsetSpace ~
17220 \InsetSpace ~
17221 \InsetSpace ~
17222 inc\InsetSpace ~
17223 \InsetSpace ~
17224 \InsetSpace ~
17225 \InsetSpace ~
17226 \InsetSpace ~
17227 _counter
17228 \newline
17229 \InsetSpace ~
17230 \InsetSpace ~
17231 \InsetSpace ~
17232 \InsetSpace ~
17233 pop\InsetSpace ~
17234 \InsetSpace ~
17235 \InsetSpace ~
17236 \InsetSpace ~
17237 \InsetSpace ~
17238 psw
17239 \newline
17240 \InsetSpace ~
17241 \InsetSpace ~
17242 \InsetSpace ~
17243 \InsetSpace ~
17244 pop\InsetSpace ~
17245 \InsetSpace ~
17246 \InsetSpace ~
17247 \InsetSpace ~
17248 \InsetSpace ~
17249 dph
17250 \newline
17251 \InsetSpace ~
17252 \InsetSpace ~
17253 \InsetSpace ~
17254 \InsetSpace ~
17255 pop\InsetSpace ~
17256 \InsetSpace ~
17257 \InsetSpace ~
17258 \InsetSpace ~
17259 \InsetSpace ~
17260 dpl
17261 \newline
17262 \InsetSpace ~
17263 \InsetSpace ~
17264 \InsetSpace ~
17265 \InsetSpace ~
17266 pop\InsetSpace ~
17267 \InsetSpace ~
17268 \InsetSpace ~
17269 \InsetSpace ~
17270 \InsetSpace ~
17271 b
17272 \newline
17273 \InsetSpace ~
17274 \InsetSpace ~
17275 \InsetSpace ~
17276 \InsetSpace ~
17277 pop\InsetSpace ~
17278 \InsetSpace ~
17279 \InsetSpace ~
17280 \InsetSpace ~
17281 \InsetSpace ~
17282 acc
17283 \newline
17284 \InsetSpace ~
17285 \InsetSpace ~
17286 \InsetSpace ~
17287 \InsetSpace ~
17288 reti
17289 \end_layout
17290
17291 \begin_layout Standard
17292 whereas nakedInterrupt looks like:
17293 \end_layout
17294
17295 \begin_layout Verse
17296
17297 \family typewriter
17298 _nakedInterrupt:
17299 \newline
17300 \InsetSpace ~
17301 \InsetSpace ~
17302 \InsetSpace ~
17303 \InsetSpace ~
17304 inc\InsetSpace ~
17305 \InsetSpace ~
17306 \InsetSpace ~
17307 \InsetSpace ~
17308 _counter ; does not change flags, no need to save psw
17309 \newline
17310 \InsetSpace ~
17311 \InsetSpace ~
17312 \InsetSpace ~
17313 \InsetSpace ~
17314 reti\InsetSpace ~
17315 \InsetSpace ~
17316 \InsetSpace ~
17317 \InsetSpace ~
17318 \InsetSpace ~
17319 \InsetSpace ~
17320 \InsetSpace ~
17321 \InsetSpace ~
17322 \InsetSpace ~
17323 \InsetSpace ~
17324 \InsetSpace ~
17325 \InsetSpace ~
17326 ;
17327  MUST explicitly include ret or reti in _naked function
17328 \end_layout
17329
17330 \begin_layout Standard
17331 The related directive #pragma exclude
17332 \begin_inset LatexCommand \index{\#pragma exclude}
17333
17334 \end_inset
17335
17336  allows a more fine grained control over pushing & popping
17337 \begin_inset LatexCommand \index{push/pop}
17338
17339 \end_inset
17340
17341  the registers.
17342 \end_layout
17343
17344 \begin_layout Standard
17345 While there is nothing preventing you from writing C code inside a 
17346 \family typewriter
17347 _naked
17348 \family default
17349  function, there are many ways to shoot yourself in the foot doing this,
17350  and it is recommended that you stick to inline assembler.
17351 \end_layout
17352
17353 \begin_layout Subsection
17354 Use of Labels within Inline Assembler
17355 \end_layout
17356
17357 \begin_layout Standard
17358 SDCC allows the use of in-line assembler with a few restrictions regarding
17359  labels.
17360  All labels defined within inline assembler code have to be of the form
17361  
17362 \emph on
17363 nnnnn$
17364 \emph default
17365  where nnnnn is a number less than 100 (which implies a limit of utmost
17366  100 inline assembler labels 
17367 \emph on
17368 per function
17369 \emph default
17370 \noun on
17371 )
17372 \noun default
17373 .
17374 \begin_inset Foot
17375 status open
17376
17377 \begin_layout Standard
17378 This is a slightly more stringent rule than absolutely necessary, but stays
17379  always on the safe side.
17380  Labels in the form of nnnnn$ are local labels in the assembler, locality
17381  of which is confined within two labels of the standard form.
17382  The compiler uses the same form for labels within a function (but starting
17383  from nnnnn=00100); and places always a standard label at the beginning
17384  of a function, thus limiting the locality of labels within the scope of
17385  the function.
17386  So, if the inline assembler part would be embedded into C-code, an improperly
17387  placed non-local label in the assembler would break up the reference space
17388  for labels created by the compiler for the C-code, leading to an assembling
17389  error.
17390 \end_layout
17391
17392 \begin_layout Standard
17393 The numeric part of local labels does not need to have 5 digits (although
17394  this is the form of labels output by the compiler), any valid integer will
17395  do.
17396  Please refer to the assemblers documentation for further details.
17397 \end_layout
17398
17399 \end_inset
17400
17401  
17402 \end_layout
17403
17404 \begin_layout Verse
17405
17406 \family typewriter
17407 _asm
17408 \begin_inset LatexCommand \index{\_asm}
17409
17410 \end_inset
17411
17412
17413 \begin_inset LatexCommand \index{\_\_asm}
17414
17415 \end_inset
17416
17417  
17418 \newline
17419 \InsetSpace ~
17420 \InsetSpace ~
17421 \InsetSpace ~
17422 \InsetSpace ~
17423 mov\InsetSpace ~
17424 \InsetSpace ~
17425 \InsetSpace ~
17426 \InsetSpace ~
17427 \InsetSpace ~
17428 b,#10 
17429 \newline
17430 00001$: 
17431 \newline
17432 \InsetSpace ~
17433 \InsetSpace ~
17434 \InsetSpace ~
17435 \InsetSpace ~
17436 djnz\InsetSpace ~
17437 \InsetSpace ~
17438 \InsetSpace ~
17439 \InsetSpace ~
17440 b,00001$ 
17441 \newline
17442 _endasm
17443 \begin_inset LatexCommand \index{\_endasm}
17444
17445 \end_inset
17446
17447
17448 \begin_inset LatexCommand \index{\_\_endasm}
17449
17450 \end_inset
17451
17452  ;
17453 \end_layout
17454
17455 \begin_layout Standard
17456 Inline assembler code cannot reference any C-labels, however it can reference
17457  labels
17458 \begin_inset LatexCommand \index{Labels}
17459
17460 \end_inset
17461
17462  defined by the inline assembler, e.g.:
17463 \end_layout
17464
17465 \begin_layout Verse
17466
17467 \family typewriter
17468 foo() { 
17469 \newline
17470 \InsetSpace ~
17471 \InsetSpace ~
17472 \InsetSpace ~
17473 \InsetSpace ~
17474 /* some c code */ 
17475 \newline
17476 \InsetSpace ~
17477 \InsetSpace ~
17478 \InsetSpace ~
17479 \InsetSpace ~
17480 _asm 
17481 \newline
17482 \InsetSpace ~
17483 \InsetSpace ~
17484 \InsetSpace ~
17485 \InsetSpace ~
17486 \InsetSpace ~
17487 \InsetSpace ~
17488 ; some assembler code 
17489 \newline
17490 \InsetSpace ~
17491 \InsetSpace ~
17492 \InsetSpace ~
17493 \InsetSpace ~
17494 \InsetSpace ~
17495 \InsetSpace ~
17496 ljmp 0003$ 
17497 \newline
17498 \InsetSpace ~
17499 \InsetSpace ~
17500 \InsetSpace ~
17501 \InsetSpace ~
17502 _endasm;
17503  
17504 \newline
17505 \InsetSpace ~
17506 \InsetSpace ~
17507 \InsetSpace ~
17508 \InsetSpace ~
17509 /* some more c code */ 
17510 \newline
17511 clabel:\InsetSpace ~
17512 \InsetSpace ~
17513 /* inline assembler cannot reference this
17514  label */ 
17515 \begin_inset Foot
17516 status open
17517
17518 \begin_layout Standard
17519 Here, the C-label 
17520 \family typewriter
17521 clabel
17522 \family default
17523  is translated by the compiler into a local label, so the locality of labels
17524  within the function is not broken.
17525 \end_layout
17526
17527 \end_inset
17528
17529
17530 \newline
17531 \InsetSpace ~
17532 \InsetSpace ~
17533 \InsetSpace ~
17534 \InsetSpace ~
17535 _asm
17536 \newline
17537 \InsetSpace ~
17538 \InsetSpace ~
17539 \InsetSpace ~
17540 \InsetSpace ~
17541 0003$: ;label (can be referenced by inline assembler only) 
17542 \newline
17543 \InsetSpace ~
17544 \InsetSpace ~
17545 \InsetSpace ~
17546 \InsetSpace ~
17547 _endasm
17548 \begin_inset LatexCommand \index{\_endasm}
17549
17550 \end_inset
17551
17552
17553 \begin_inset LatexCommand \index{\_\_endasm}
17554
17555 \end_inset
17556
17557  ; 
17558 \newline
17559 \InsetSpace ~
17560 \InsetSpace ~
17561 \InsetSpace ~
17562 \InsetSpace ~
17563 /* some more c code */
17564 \newline
17565 }
17566 \end_layout
17567
17568 \begin_layout Standard
17569 In other words inline assembly code can access labels defined in inline
17570  assembly within the scope of the function.
17571  The same goes the other way, i.e.
17572  labels defines in inline assembly can not be accessed by C statements.
17573 \end_layout
17574
17575 \begin_layout Section
17576 Interfacing with Assembler Code
17577 \begin_inset LatexCommand \index{Assembler routines}
17578
17579 \end_inset
17580
17581
17582 \end_layout
17583
17584 \begin_layout Subsection
17585 Global Registers used for Parameter Passing
17586 \begin_inset LatexCommand \index{Parameter passing}
17587
17588 \end_inset
17589
17590
17591 \end_layout
17592
17593 \begin_layout Standard
17594 The compiler always uses the global registers 
17595 \emph on
17596 DPL, DPH
17597 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17598
17599 \end_inset
17600
17601
17602 \begin_inset LatexCommand \index{DPTR}
17603
17604 \end_inset
17605
17606 , B
17607 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17608
17609 \end_inset
17610
17611  
17612 \emph default
17613 and
17614 \emph on
17615  ACC
17616 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17617
17618 \end_inset
17619
17620
17621 \emph default
17622  to pass the first (non-bit) parameter to a function, and also to pass the
17623  return value 
17624 \begin_inset LatexCommand \index{return value}
17625
17626 \end_inset
17627
17628 of function; according to the following scheme: one byte return value in
17629  
17630 \emph on
17631 DPL
17632 \emph default
17633 , two byte value in 
17634 \emph on
17635 DPL
17636 \emph default
17637  (LSB) and 
17638 \emph on
17639 DPH
17640 \emph default
17641  (MSB).
17642  three byte values (generic pointers) in 
17643 \emph on
17644 DPH
17645 \emph default
17646
17647 \emph on
17648 DPL
17649 \emph default
17650  and 
17651 \emph on
17652 B
17653 \emph default
17654 , and four byte values in 
17655 \emph on
17656 DPH
17657 \emph default
17658
17659 \emph on
17660 DPL
17661 \emph default
17662 ,
17663 \emph on
17664  B
17665 \emph default
17666  and 
17667 \emph on
17668 ACC
17669 \emph default
17670 .
17671  Generic pointers
17672 \begin_inset LatexCommand \index{generic pointer}
17673
17674 \end_inset
17675
17676  contain type of accessed memory in 
17677 \emph on
17678 B
17679 \emph default
17680
17681 \series bold
17682 0x00
17683 \series default
17684  -- xdata/far, 
17685 \series bold
17686 0x40
17687 \series default
17688  -- idata/near -- , 
17689 \series bold
17690 0x60
17691 \series default
17692  -- pdata, 
17693 \series bold
17694 0x80
17695 \series default
17696  -- code
17697 \begin_inset Note Note
17698 status collapsed
17699
17700 \begin_layout Standard
17701 This might not be the case of certain memory models (medium???)
17702 \end_layout
17703
17704 \end_inset
17705
17706 .
17707 \end_layout
17708
17709 \begin_layout Standard
17710 The second parameter onwards is either allocated on the stack (for reentrant
17711  routines or if -
17712 \begin_inset ERT
17713 status collapsed
17714
17715 \begin_layout Standard
17716
17717
17718 \backslash
17719 /
17720 \end_layout
17721
17722 \end_inset
17723
17724 -stack-auto is used) or in data/xdata memory (depending on the memory model).
17725 \end_layout
17726
17727 \begin_layout Standard
17728 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
17729  space for reentrant functions or allocated directly in bit memory otherwise.
17730 \end_layout
17731
17732 \begin_layout Standard
17733 Functions (with two or more parameters or bit parameters) that are called
17734  through function pointers
17735 \begin_inset LatexCommand \index{function pointers}
17736
17737 \end_inset
17738
17739  must therefor be reentrant so the compiler knows how to pass the parameters.
17740 \end_layout
17741
17742 \begin_layout Subsection
17743 Registers usage
17744 \end_layout
17745
17746 \begin_layout Standard
17747 Unless the called function is declared as 
17748 \family typewriter
17749 _naked
17750 \family default
17751
17752 \begin_inset LatexCommand \index{naked}
17753
17754 \end_inset
17755
17756 , or the -
17757 \begin_inset ERT
17758 status collapsed
17759
17760 \begin_layout Standard
17761
17762
17763 \backslash
17764 /
17765 \end_layout
17766
17767 \end_inset
17768
17769 -callee-saves
17770 \begin_inset LatexCommand \index{-\/-callee-saves}
17771
17772 \end_inset
17773
17774 /-
17775 \begin_inset ERT
17776 status collapsed
17777
17778 \begin_layout Standard
17779
17780
17781 \backslash
17782 /
17783 \end_layout
17784
17785 \end_inset
17786
17787 -all-callee-saves command line option or the corresponding callee_saves
17788  pragma are used, the caller will save the registers (
17789 \emph on
17790 R0-R7
17791 \emph default
17792 ) around the call, so the called function can destroy they content freely.
17793 \end_layout
17794
17795 \begin_layout Standard
17796 If the called function is not declared as 
17797 \family typewriter
17798 _naked
17799 \family default
17800 , the caller will swap register banks around the call, if caller and callee
17801  use different register banks (having them defined by the 
17802 \family typewriter
17803 _using
17804 \family default
17805  modifier).
17806  
17807 \end_layout
17808
17809 \begin_layout Standard
17810 The called function can also use 
17811 \emph on
17812 DPL
17813 \emph default
17814
17815 \emph on
17816 DPH
17817 \emph default
17818
17819 \emph on
17820 B
17821 \emph default
17822  and 
17823 \emph on
17824 ACC
17825 \emph default
17826  observing that they are used for parameter/return value passing.
17827 \end_layout
17828
17829 \begin_layout Subsection
17830 Assembler Routine (non-reentrant)
17831 \end_layout
17832
17833 \begin_layout Standard
17834 In the following example
17835 \begin_inset LatexCommand \index{reentrant}
17836
17837 \end_inset
17838
17839
17840 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
17841
17842 \end_inset
17843
17844  the function c_func calls an assembler routine asm_func, which takes two
17845  parameters
17846 \begin_inset LatexCommand \index{function parameter}
17847
17848 \end_inset
17849
17850 .
17851 \end_layout
17852
17853 \begin_layout Verse
17854
17855 \family typewriter
17856 extern int asm_func(unsigned char, unsigned char);
17857 \newline
17858
17859 \newline
17860 int c_func (unsigned char
17861  i, unsigned char j)
17862 \newline
17863 {
17864 \newline
17865 \InsetSpace ~
17866 \InsetSpace ~
17867 \InsetSpace ~
17868 \InsetSpace ~
17869 return asm_func(i,j);
17870 \newline
17871 }
17872 \newline
17873
17874 \newline
17875 int main()
17876 \newline
17877 {
17878 \newline
17879 \InsetSpace ~
17880 \InsetSpace ~
17881 \InsetSpace ~
17882 \InsetSpace ~
17883 return c_func(10,9);
17884 \newline
17885 }
17886 \end_layout
17887
17888 \begin_layout Standard
17889 The corresponding assembler function is:
17890 \end_layout
17891
17892 \begin_layout Verse
17893
17894 \family typewriter
17895 .globl _asm_func_PARM_2 
17896 \newline
17897 \InsetSpace ~
17898 \InsetSpace ~
17899 \InsetSpace ~
17900 \InsetSpace ~
17901 \InsetSpace ~
17902 \InsetSpace ~
17903 \InsetSpace ~
17904 \InsetSpace ~
17905 .globl _asm_func 
17906 \newline
17907 \InsetSpace ~
17908 \InsetSpace ~
17909 \InsetSpace ~
17910 \InsetSpace ~
17911 \InsetSpace ~
17912 \InsetSpace ~
17913 \InsetSpace ~
17914 \InsetSpace ~
17915 .area OSEG 
17916 \newline
17917 _asm_func_PARM_2:
17918 \newline
17919 \InsetSpace ~
17920 \InsetSpace ~
17921 \InsetSpace ~
17922 \InsetSpace ~
17923 \InsetSpace ~
17924 \InsetSpace ~
17925 \InsetSpace ~
17926 \InsetSpace ~
17927 .ds   
17928  1 
17929 \newline
17930 \InsetSpace ~
17931 \InsetSpace ~
17932 \InsetSpace ~
17933 \InsetSpace ~
17934 \InsetSpace ~
17935 \InsetSpace ~
17936 \InsetSpace ~
17937 \InsetSpace ~
17938 .area CSEG 
17939 \newline
17940 _asm_func: 
17941 \newline
17942 \InsetSpace ~
17943 \InsetSpace ~
17944 \InsetSpace ~
17945 \InsetSpace ~
17946 \InsetSpace ~
17947 \InsetSpace ~
17948 \InsetSpace ~
17949 \InsetSpace ~
17950 mov\InsetSpace ~
17951 \InsetSpace ~
17952 \InsetSpace ~
17953 \InsetSpace ~
17954 a,dpl 
17955 \newline
17956 \InsetSpace ~
17957 \InsetSpace ~
17958 \InsetSpace ~
17959 \InsetSpace ~
17960 \InsetSpace ~
17961 \InsetSpace ~
17962 \InsetSpace ~
17963 \InsetSpace ~
17964 add\InsetSpace ~
17965 \InsetSpace ~
17966 \InsetSpace ~
17967 \InsetSpace ~
17968 a,_asm_func_PARM_2 
17969 \newline
17970 \InsetSpace ~
17971 \InsetSpace ~
17972 \InsetSpace ~
17973 \InsetSpace ~
17974 \InsetSpace ~
17975 \InsetSpace ~
17976 \InsetSpace ~
17977 \InsetSpace ~
17978 mov\InsetSpace ~
17979 \InsetSpace ~
17980 \InsetSpace ~
17981 \InsetSpace ~
17982 dpl,a 
17983 \newline
17984 \InsetSpace ~
17985 \InsetSpace ~
17986 \InsetSpace ~
17987 \InsetSpace ~
17988 \InsetSpace ~
17989 \InsetSpace ~
17990 \InsetSpace ~
17991 \InsetSpace ~
17992 mov\InsetSpace ~
17993 \InsetSpace ~
17994 \InsetSpace ~
17995 \InsetSpace ~
17996 dph
17997 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17998
17999 \end_inset
18000
18001 ,#0x00 
18002 \newline
18003 \InsetSpace ~
18004 \InsetSpace ~
18005 \InsetSpace ~
18006 \InsetSpace ~
18007 \InsetSpace ~
18008 \InsetSpace ~
18009 \InsetSpace ~
18010 \InsetSpace ~
18011 ret
18012 \end_layout
18013
18014 \begin_layout Standard
18015 The parameter naming convention is _<function_name>_PARM_<n>, where n is
18016  the parameter number starting from 1, and counting from the left.
18017  The first parameter is passed in 
18018 \emph on
18019 DPH
18020 \emph default
18021
18022 \emph on
18023 DPL
18024 \emph default
18025
18026 \emph on
18027 B
18028 \emph default
18029  and 
18030 \emph on
18031 ACC
18032 \emph default
18033  according to the description above.
18034  The variable name for the second parameter will be _<function_name>_PARM_2.
18035 \newline
18036
18037 \newline
18038 Assem
18039 ble the assembler routine with the following command:
18040 \newline
18041
18042 \newline
18043
18044 \family sans
18045 \series bold
18046 asx8051 -losg asmfunc.asm
18047 \newline
18048
18049 \newline
18050
18051 \family default
18052 \series default
18053 Then compile and link the assembler routine to the C source file with the
18054  following command:
18055 \newline
18056
18057 \newline
18058
18059 \family sans
18060 \series bold
18061 sdcc cfunc.c asmfunc.rel
18062 \end_layout
18063
18064 \begin_layout Subsection
18065 Assembler Routine (reentrant)
18066 \end_layout
18067
18068 \begin_layout Standard
18069 In this case
18070 \begin_inset LatexCommand \index{reentrant}
18071
18072 \end_inset
18073
18074
18075 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18076
18077 \end_inset
18078
18079  the second parameter
18080 \begin_inset LatexCommand \index{function parameter}
18081
18082 \end_inset
18083
18084  onwards will be passed on the stack, the parameters are pushed from right
18085  to left i.e.
18086  before the call the second leftmost parameter will be on the top of the
18087  stack (the leftmost parameter is passed in registers).
18088  Here is an example:
18089 \end_layout
18090
18091 \begin_layout Verse
18092
18093 \family typewriter
18094 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18095 \newline
18096
18097 \newline
18098 int
18099  c_func (unsigned char i, unsigned char j, unsigned char k) reentrant 
18100 \newline
18101 {
18102  
18103 \newline
18104 \InsetSpace ~
18105 \InsetSpace ~
18106 \InsetSpace ~
18107 \InsetSpace ~
18108 return asm_func(i,j,k); 
18109 \newline
18110
18111 \newline
18112
18113 \newline
18114 int main() 
18115 \newline
18116
18117 \newline
18118 \InsetSpace ~
18119 \InsetSpace ~
18120 \InsetSpace ~
18121 \InsetSpace ~
18122 return c_func(10,9,8); 
18123 \newline
18124 }
18125 \end_layout
18126
18127 \begin_layout Standard
18128 The corresponding (unoptimized) assembler routine is:
18129 \end_layout
18130
18131 \begin_layout Verse
18132
18133 \family typewriter
18134 .globl _asm_func 
18135 \newline
18136 _asm_func: 
18137 \newline
18138 \InsetSpace ~
18139 \InsetSpace ~
18140 \InsetSpace ~
18141 \InsetSpace ~
18142 push\InsetSpace ~
18143 _bp 
18144 \newline
18145 \InsetSpace ~
18146 \InsetSpace ~
18147 \InsetSpace ~
18148 \InsetSpace ~
18149 mov\InsetSpace ~
18150 \InsetSpace ~
18151 _bp,sp\InsetSpace ~
18152 \InsetSpace ~
18153 \InsetSpace ~
18154 \InsetSpace ~
18155 \InsetSpace ~
18156 \InsetSpace ~
18157 ;stack contains: _bp, return
18158  address, second parameter, third parameter
18159 \newline
18160 \InsetSpace ~
18161 \InsetSpace ~
18162 \InsetSpace ~
18163 \InsetSpace ~
18164 mov\InsetSpace ~
18165 \InsetSpace ~
18166 r2,dpl
18167 \newline
18168 \InsetSpace ~
18169 \InsetSpace ~
18170 \InsetSpace ~
18171 \InsetSpace ~
18172 mov\InsetSpace ~
18173 \InsetSpace ~
18174 a,_bp
18175 \newline
18176 \InsetSpace ~
18177 \InsetSpace ~
18178 \InsetSpace ~
18179 \InsetSpace ~
18180 add\InsetSpace ~
18181 \InsetSpace ~
18182 a,#0xfd\InsetSpace ~
18183 \InsetSpace ~
18184 \InsetSpace ~
18185 \InsetSpace ~
18186 \InsetSpace ~
18187 ;calculate
18188  pointer to the second parameter
18189 \newline
18190 \InsetSpace ~
18191 \InsetSpace ~
18192 \InsetSpace ~
18193 \InsetSpace ~
18194 mov\InsetSpace ~
18195 \InsetSpace ~
18196 r0,a 
18197 \newline
18198 \InsetSpace ~
18199 \InsetSpace ~
18200 \InsetSpace ~
18201 \InsetSpace ~
18202 mov\InsetSpace ~
18203 \InsetSpace ~
18204 a,_bp 
18205 \newline
18206 \InsetSpace ~
18207 \InsetSpace ~
18208 \InsetSpace ~
18209 \InsetSpace ~
18210 add\InsetSpace ~
18211 \InsetSpace ~
18212 a,#0xfc\InsetSpace ~
18213 \InsetSpace ~
18214 \InsetSpace ~
18215 \InsetSpace ~
18216 \InsetSpace ~
18217 ;calculate pointer
18218  to the rightmost parameter
18219 \newline
18220 \InsetSpace ~
18221 \InsetSpace ~
18222 \InsetSpace ~
18223 \InsetSpace ~
18224 mov\InsetSpace ~
18225 \InsetSpace ~
18226 r1,a 
18227 \newline
18228 \InsetSpace ~
18229 \InsetSpace ~
18230 \InsetSpace ~
18231 \InsetSpace ~
18232 mov\InsetSpace ~
18233 \InsetSpace ~
18234 a,@r0
18235 \newline
18236 \InsetSpace ~
18237 \InsetSpace ~
18238 \InsetSpace ~
18239 \InsetSpace ~
18240 add\InsetSpace ~
18241 \InsetSpace ~
18242 a,@r1
18243 \newline
18244 \InsetSpace ~
18245 \InsetSpace ~
18246 \InsetSpace ~
18247 \InsetSpace ~
18248 add\InsetSpace ~
18249 \InsetSpace ~
18250 a,r2\InsetSpace ~
18251 \InsetSpace ~
18252 \InsetSpace ~
18253 \InsetSpace ~
18254 \InsetSpace ~
18255 \InsetSpace ~
18256 \InsetSpace ~
18257 \InsetSpace ~
18258 ;calculate the
18259  result (= sum of all three parameters)
18260 \newline
18261 \InsetSpace ~
18262 \InsetSpace ~
18263 \InsetSpace ~
18264 \InsetSpace ~
18265 mov\InsetSpace ~
18266 \InsetSpace ~
18267 dpl,a\InsetSpace ~
18268 \InsetSpace ~
18269 \InsetSpace ~
18270 \InsetSpace ~
18271 \InsetSpace ~
18272 \InsetSpace ~
18273 \InsetSpace ~
18274 ;return value goes into dptr
18275  (cast into int)
18276 \newline
18277 \InsetSpace ~
18278 \InsetSpace ~
18279 \InsetSpace ~
18280 \InsetSpace ~
18281 mov\InsetSpace ~
18282 \InsetSpace ~
18283 dph,#0x00 
18284 \newline
18285 \InsetSpace ~
18286 \InsetSpace ~
18287 \InsetSpace ~
18288 \InsetSpace ~
18289 mov\InsetSpace ~
18290 \InsetSpace ~
18291 sp,_bp 
18292 \newline
18293 \InsetSpace ~
18294 \InsetSpace ~
18295 \InsetSpace ~
18296 \InsetSpace ~
18297 pop\InsetSpace ~
18298 \InsetSpace ~
18299 _bp 
18300 \newline
18301 \InsetSpace ~
18302 \InsetSpace ~
18303 \InsetSpace ~
18304 \InsetSpace ~
18305 ret
18306 \end_layout
18307
18308 \begin_layout Standard
18309 The compiling and linking procedure remains the same, however note the extra
18310  entry & exit linkage required for the assembler code, _bp is the stack
18311  frame pointer and is used to compute the offset into the stack for parameters
18312  and local variables.
18313 \begin_inset VSpace bigskip
18314 \end_inset
18315
18316
18317 \end_layout
18318
18319 \begin_layout Section
18320 int (16 bit)
18321 \begin_inset LatexCommand \index{int (16 bit)}
18322
18323 \end_inset
18324
18325  and long (32 bit)
18326 \begin_inset LatexCommand \index{long (32 bit)}
18327
18328 \end_inset
18329
18330  Support
18331 \end_layout
18332
18333 \begin_layout Standard
18334 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18335  multiplication and modulus operations are implemented by support routines.
18336  These support routines are all developed in ANSI-C to facilitate porting
18337  to other MCUs, although some model specific assembler optimizations are
18338  used.
18339  The following files contain the described routines, all of them can be
18340  found in <installdir>/share/sdcc/lib.
18341 \newline
18342
18343 \end_layout
18344
18345 \begin_layout Standard
18346 \align center
18347 \begin_inset Tabular
18348 <lyxtabular version="3" rows="11" columns="2">
18349 <features>
18350 <column alignment="left" valignment="top" leftline="true" width="0">
18351 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18352 <row topline="true" bottomline="true">
18353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18354 \begin_inset Text
18355
18356 \begin_layout Standard
18357
18358 \series bold
18359 Function
18360 \end_layout
18361
18362 \end_inset
18363 </cell>
18364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18365 \begin_inset Text
18366
18367 \begin_layout Standard
18368
18369 \series bold
18370 Description
18371 \end_layout
18372
18373 \end_inset
18374 </cell>
18375 </row>
18376 <row topline="true">
18377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18378 \begin_inset Text
18379
18380 \begin_layout Standard
18381 _mulint.c 
18382 \end_layout
18383
18384 \end_inset
18385 </cell>
18386 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18387 \begin_inset Text
18388
18389 \begin_layout Standard
18390 16 bit multiplication
18391 \end_layout
18392
18393 \end_inset
18394 </cell>
18395 </row>
18396 <row topline="true">
18397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18398 \begin_inset Text
18399
18400 \begin_layout Standard
18401 _divsint.c 
18402 \end_layout
18403
18404 \end_inset
18405 </cell>
18406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18407 \begin_inset Text
18408
18409 \begin_layout Standard
18410  signed 16 bit division (calls _divuint)
18411 \end_layout
18412
18413 \end_inset
18414 </cell>
18415 </row>
18416 <row topline="true">
18417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18418 \begin_inset Text
18419
18420 \begin_layout Standard
18421 _divuint.c 
18422 \end_layout
18423
18424 \end_inset
18425 </cell>
18426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18427 \begin_inset Text
18428
18429 \begin_layout Standard
18430  unsigned 16 bit division
18431 \end_layout
18432
18433 \end_inset
18434 </cell>
18435 </row>
18436 <row topline="true">
18437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18438 \begin_inset Text
18439
18440 \begin_layout Standard
18441 _modsint.c
18442 \end_layout
18443
18444 \end_inset
18445 </cell>
18446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18447 \begin_inset Text
18448
18449 \begin_layout Standard
18450 signed 16 bit modulus (calls _moduint)
18451 \end_layout
18452
18453 \end_inset
18454 </cell>
18455 </row>
18456 <row topline="true">
18457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18458 \begin_inset Text
18459
18460 \begin_layout Standard
18461 _moduint.c
18462 \end_layout
18463
18464 \end_inset
18465 </cell>
18466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18467 \begin_inset Text
18468
18469 \begin_layout Standard
18470 unsigned 16 bit modulus
18471 \end_layout
18472
18473 \end_inset
18474 </cell>
18475 </row>
18476 <row topline="true">
18477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18478 \begin_inset Text
18479
18480 \begin_layout Standard
18481 _mullong.c
18482 \end_layout
18483
18484 \end_inset
18485 </cell>
18486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18487 \begin_inset Text
18488
18489 \begin_layout Standard
18490 32 bit multiplication
18491 \end_layout
18492
18493 \end_inset
18494 </cell>
18495 </row>
18496 <row topline="true">
18497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18498 \begin_inset Text
18499
18500 \begin_layout Standard
18501 _divslong.c 
18502 \end_layout
18503
18504 \end_inset
18505 </cell>
18506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18507 \begin_inset Text
18508
18509 \begin_layout Standard
18510  signed 32 division (calls _divulong)
18511 \end_layout
18512
18513 \end_inset
18514 </cell>
18515 </row>
18516 <row topline="true">
18517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18518 \begin_inset Text
18519
18520 \begin_layout Standard
18521 _divulong.c 
18522 \end_layout
18523
18524 \end_inset
18525 </cell>
18526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18527 \begin_inset Text
18528
18529 \begin_layout Standard
18530 unsigned 32 division
18531 \end_layout
18532
18533 \end_inset
18534 </cell>
18535 </row>
18536 <row topline="true">
18537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18538 \begin_inset Text
18539
18540 \begin_layout Standard
18541 _modslong.c
18542 \end_layout
18543
18544 \end_inset
18545 </cell>
18546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18547 \begin_inset Text
18548
18549 \begin_layout Standard
18550  signed 32 bit modulus (calls _modulong)
18551 \end_layout
18552
18553 \end_inset
18554 </cell>
18555 </row>
18556 <row topline="true" bottomline="true">
18557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18558 \begin_inset Text
18559
18560 \begin_layout Standard
18561 _modulong.c
18562 \end_layout
18563
18564 \end_inset
18565 </cell>
18566 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18567 \begin_inset Text
18568
18569 \begin_layout Standard
18570 unsigned 32 bit modulus
18571 \end_layout
18572
18573 \end_inset
18574 </cell>
18575 </row>
18576 </lyxtabular>
18577
18578 \end_inset
18579
18580
18581 \newline
18582
18583 \end_layout
18584
18585 \begin_layout Standard
18586 Since they are compiled as 
18587 \emph on
18588 non-reentrant
18589 \emph default
18590
18591 \begin_inset LatexCommand \index{reentrant}
18592
18593 \end_inset
18594
18595 , interrupt
18596 \begin_inset LatexCommand \index{interrupt}
18597
18598 \end_inset
18599
18600  service routines should not do any of the above operations.
18601  If this is unavoidable then the above routines will need to be compiled
18602  with the 
18603 \emph on
18604 -
18605 \begin_inset ERT
18606 status collapsed
18607
18608 \begin_layout Standard
18609
18610
18611 \backslash
18612 /
18613 \end_layout
18614
18615 \end_inset
18616
18617 -stack-auto
18618 \begin_inset LatexCommand \index{-\/-stack-auto}
18619
18620 \end_inset
18621
18622
18623 \emph default
18624  option, after which the source program will have to be compiled with 
18625 \emph on
18626 -
18627 \begin_inset ERT
18628 status collapsed
18629
18630 \begin_layout Standard
18631
18632
18633 \backslash
18634 /
18635 \end_layout
18636
18637 \end_inset
18638
18639 -int-long-reent
18640 \begin_inset LatexCommand \index{-\/-int-long-reent}
18641
18642 \end_inset
18643
18644
18645 \emph default
18646  option.
18647  Notice that you don't have to call these routines directly.
18648  The compiler will use them automatically every time an integer operation
18649  is required.
18650 \end_layout
18651
18652 \begin_layout Section
18653 Floating Point Support
18654 \begin_inset LatexCommand \index{Floating point support}
18655
18656 \end_inset
18657
18658
18659 \end_layout
18660
18661 \begin_layout Standard
18662 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
18663  The floating point support routines are derived from gcc's floatlib.c and
18664  consist of the following routines:
18665 \newline
18666
18667 \end_layout
18668
18669 \begin_layout Standard
18670 \align center
18671
18672 \size footnotesize
18673 \begin_inset Tabular
18674 <lyxtabular version="3" rows="17" columns="2">
18675 <features>
18676 <column alignment="left" valignment="top" leftline="true" width="0">
18677 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18678 <row topline="true" bottomline="true">
18679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18680 \begin_inset Text
18681
18682 \begin_layout Standard
18683
18684 \family roman
18685 \series medium
18686 \shape up
18687 \size normal
18688 \emph off
18689 \bar no
18690 \noun off
18691 \color none
18692 Function 
18693 \end_layout
18694
18695 \end_inset
18696 </cell>
18697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18698 \begin_inset Text
18699
18700 \begin_layout Standard
18701 Description
18702 \end_layout
18703
18704 \end_inset
18705 </cell>
18706 </row>
18707 <row topline="true">
18708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18709 \begin_inset Text
18710
18711 \begin_layout Standard
18712
18713 \family roman
18714 \series medium
18715 \shape up
18716 \size normal
18717 \emph off
18718 \bar no
18719 \noun off
18720 \color none
18721 _fsadd.c
18722 \end_layout
18723
18724 \end_inset
18725 </cell>
18726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18727 \begin_inset Text
18728
18729 \begin_layout Standard
18730
18731 \family roman
18732 \series medium
18733 \shape up
18734 \size normal
18735 \emph off
18736 \bar no
18737 \noun off
18738 \color none
18739 add floating point numbers
18740 \end_layout
18741
18742 \end_inset
18743 </cell>
18744 </row>
18745 <row topline="true">
18746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18747 \begin_inset Text
18748
18749 \begin_layout Standard
18750
18751 \family roman
18752 \series medium
18753 \shape up
18754 \size normal
18755 \emph off
18756 \bar no
18757 \noun off
18758 \color none
18759 _fssub.c 
18760 \end_layout
18761
18762 \end_inset
18763 </cell>
18764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18765 \begin_inset Text
18766
18767 \begin_layout Standard
18768
18769 \family roman
18770 \series medium
18771 \shape up
18772 \size normal
18773 \emph off
18774 \bar no
18775 \noun off
18776 \color none
18777 subtract floating point numbers 
18778 \end_layout
18779
18780 \end_inset
18781 </cell>
18782 </row>
18783 <row topline="true">
18784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18785 \begin_inset Text
18786
18787 \begin_layout Standard
18788
18789 \family roman
18790 \series medium
18791 \shape up
18792 \size normal
18793 \emph off
18794 \bar no
18795 \noun off
18796 \color none
18797 _fsdiv.c 
18798 \end_layout
18799
18800 \end_inset
18801 </cell>
18802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18803 \begin_inset Text
18804
18805 \begin_layout Standard
18806
18807 \family roman
18808 \series medium
18809 \shape up
18810 \size normal
18811 \emph off
18812 \bar no
18813 \noun off
18814 \color none
18815 divide floating point numbers 
18816 \end_layout
18817
18818 \end_inset
18819 </cell>
18820 </row>
18821 <row topline="true">
18822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18823 \begin_inset Text
18824
18825 \begin_layout Standard
18826
18827 \family roman
18828 \series medium
18829 \shape up
18830 \size normal
18831 \emph off
18832 \bar no
18833 \noun off
18834 \color none
18835 _fsmul.c 
18836 \end_layout
18837
18838 \end_inset
18839 </cell>
18840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18841 \begin_inset Text
18842
18843 \begin_layout Standard
18844
18845 \family roman
18846 \series medium
18847 \shape up
18848 \size normal
18849 \emph off
18850 \bar no
18851 \noun off
18852 \color none
18853 multiply floating point numbers 
18854 \end_layout
18855
18856 \end_inset
18857 </cell>
18858 </row>
18859 <row topline="true">
18860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18861 \begin_inset Text
18862
18863 \begin_layout Standard
18864
18865 \family roman
18866 \series medium
18867 \shape up
18868 \size normal
18869 \emph off
18870 \bar no
18871 \noun off
18872 \color none
18873 _fs2uchar.c
18874 \end_layout
18875
18876 \end_inset
18877 </cell>
18878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18879 \begin_inset Text
18880
18881 \begin_layout Standard
18882
18883 \family roman
18884 \series medium
18885 \shape up
18886 \size normal
18887 \emph off
18888 \bar no
18889 \noun off
18890 \color none
18891 convert floating point to unsigned char
18892 \end_layout
18893
18894 \end_inset
18895 </cell>
18896 </row>
18897 <row topline="true">
18898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18899 \begin_inset Text
18900
18901 \begin_layout Standard
18902
18903 \family roman
18904 \series medium
18905 \shape up
18906 \size normal
18907 \emph off
18908 \bar no
18909 \noun off
18910 \color none
18911 _fs2char.c
18912 \end_layout
18913
18914 \end_inset
18915 </cell>
18916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18917 \begin_inset Text
18918
18919 \begin_layout Standard
18920
18921 \family roman
18922 \series medium
18923 \shape up
18924 \size normal
18925 \emph off
18926 \bar no
18927 \noun off
18928 \color none
18929 convert floating point to signed char
18930 \end_layout
18931
18932 \end_inset
18933 </cell>
18934 </row>
18935 <row topline="true">
18936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18937 \begin_inset Text
18938
18939 \begin_layout Standard
18940
18941 \family roman
18942 \series medium
18943 \shape up
18944 \size normal
18945 \emph off
18946 \bar no
18947 \noun off
18948 \color none
18949 _fs2uint.c
18950 \end_layout
18951
18952 \end_inset
18953 </cell>
18954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18955 \begin_inset Text
18956
18957 \begin_layout Standard
18958
18959 \family roman
18960 \series medium
18961 \shape up
18962 \size normal
18963 \emph off
18964 \bar no
18965 \noun off
18966 \color none
18967 convert floating point to unsigned int
18968 \end_layout
18969
18970 \end_inset
18971 </cell>
18972 </row>
18973 <row topline="true">
18974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18975 \begin_inset Text
18976
18977 \begin_layout Standard
18978
18979 \family roman
18980 \series medium
18981 \shape up
18982 \size normal
18983 \emph off
18984 \bar no
18985 \noun off
18986 \color none
18987 _fs2int.c
18988 \end_layout
18989
18990 \end_inset
18991 </cell>
18992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18993 \begin_inset Text
18994
18995 \begin_layout Standard
18996
18997 \family roman
18998 \series medium
18999 \shape up
19000 \size normal
19001 \emph off
19002 \bar no
19003 \noun off
19004 \color none
19005 convert floating point to signed int
19006 \end_layout
19007
19008 \end_inset
19009 </cell>
19010 </row>
19011 <row topline="true">
19012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19013 \begin_inset Text
19014
19015 \begin_layout Standard
19016
19017 \family roman
19018 \series medium
19019 \shape up
19020 \size normal
19021 \emph off
19022 \bar no
19023 \noun off
19024 \color none
19025 _fs2ulong.
19026 \family default
19027 \series default
19028 \shape default
19029 \size default
19030 \emph default
19031 \bar default
19032 \noun default
19033 c
19034 \end_layout
19035
19036 \end_inset
19037 </cell>
19038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19039 \begin_inset Text
19040
19041 \begin_layout Standard
19042
19043 \family roman
19044 \series medium
19045 \shape up
19046 \size normal
19047 \emph off
19048 \bar no
19049 \noun off
19050 \color none
19051 convert floating point to unsigned long
19052 \end_layout
19053
19054 \end_inset
19055 </cell>
19056 </row>
19057 <row topline="true">
19058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19059 \begin_inset Text
19060
19061 \begin_layout Standard
19062
19063 \family roman
19064 \series medium
19065 \shape up
19066 \size normal
19067 \emph off
19068 \bar no
19069 \noun off
19070 \color none
19071 _fs2long.c
19072 \end_layout
19073
19074 \end_inset
19075 </cell>
19076 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19077 \begin_inset Text
19078
19079 \begin_layout Standard
19080
19081 \family roman
19082 \series medium
19083 \shape up
19084 \size normal
19085 \emph off
19086 \bar no
19087 \noun off
19088 \color none
19089 convert floating point to signed long
19090 \end_layout
19091
19092 \end_inset
19093 </cell>
19094 </row>
19095 <row topline="true">
19096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19097 \begin_inset Text
19098
19099 \begin_layout Standard
19100
19101 \family roman
19102 \series medium
19103 \shape up
19104 \size normal
19105 \emph off
19106 \bar no
19107 \noun off
19108 \color none
19109 _uchar2fs.c
19110 \end_layout
19111
19112 \end_inset
19113 </cell>
19114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19115 \begin_inset Text
19116
19117 \begin_layout Standard
19118
19119 \family roman
19120 \series medium
19121 \shape up
19122 \size normal
19123 \emph off
19124 \bar no
19125 \noun off
19126 \color none
19127 convert unsigned char to floating point
19128 \end_layout
19129
19130 \end_inset
19131 </cell>
19132 </row>
19133 <row topline="true">
19134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19135 \begin_inset Text
19136
19137 \begin_layout Standard
19138
19139 \family roman
19140 \series medium
19141 \shape up
19142 \size normal
19143 \emph off
19144 \bar no
19145 \noun off
19146 \color none
19147 _char2fs.c
19148 \end_layout
19149
19150 \end_inset
19151 </cell>
19152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19153 \begin_inset Text
19154
19155 \begin_layout Standard
19156
19157 \family roman
19158 \series medium
19159 \shape up
19160 \size normal
19161 \emph off
19162 \bar no
19163 \noun off
19164 \color none
19165 convert char to floating point number
19166 \end_layout
19167
19168 \end_inset
19169 </cell>
19170 </row>
19171 <row topline="true">
19172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19173 \begin_inset Text
19174
19175 \begin_layout Standard
19176
19177 \family roman
19178 \series medium
19179 \shape up
19180 \size normal
19181 \emph off
19182 \bar no
19183 \noun off
19184 \color none
19185 _uint2fs.c
19186 \end_layout
19187
19188 \end_inset
19189 </cell>
19190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19191 \begin_inset Text
19192
19193 \begin_layout Standard
19194
19195 \family roman
19196 \series medium
19197 \shape up
19198 \size normal
19199 \emph off
19200 \bar no
19201 \noun off
19202 \color none
19203 convert unsigned int to floating point
19204 \end_layout
19205
19206 \end_inset
19207 </cell>
19208 </row>
19209 <row topline="true">
19210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19211 \begin_inset Text
19212
19213 \begin_layout Standard
19214
19215 \family roman
19216 \series medium
19217 \shape up
19218 \size normal
19219 \emph off
19220 \bar no
19221 \noun off
19222 \color none
19223 _int2fs.c
19224 \end_layout
19225
19226 \end_inset
19227 </cell>
19228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19229 \begin_inset Text
19230
19231 \begin_layout Standard
19232
19233 \family roman
19234 \series medium
19235 \shape up
19236 \size normal
19237 \emph off
19238 \bar no
19239 \noun off
19240 \color none
19241 convert int to floating point numbers
19242 \end_layout
19243
19244 \end_inset
19245 </cell>
19246 </row>
19247 <row topline="true">
19248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19249 \begin_inset Text
19250
19251 \begin_layout Standard
19252
19253 \family roman
19254 \series medium
19255 \shape up
19256 \size normal
19257 \emph off
19258 \bar no
19259 \noun off
19260 \color none
19261 _ulong2fs.c
19262 \end_layout
19263
19264 \end_inset
19265 </cell>
19266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19267 \begin_inset Text
19268
19269 \begin_layout Standard
19270
19271 \family roman
19272 \series medium
19273 \shape up
19274 \size normal
19275 \emph off
19276 \bar no
19277 \noun off
19278 \color none
19279 convert unsigned long to floating point number
19280 \end_layout
19281
19282 \end_inset
19283 </cell>
19284 </row>
19285 <row topline="true" bottomline="true">
19286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19287 \begin_inset Text
19288
19289 \begin_layout Standard
19290
19291 \family roman
19292 \series medium
19293 \shape up
19294 \size normal
19295 \emph off
19296 \bar no
19297 \noun off
19298 \color none
19299 _long2fs.c
19300 \end_layout
19301
19302 \end_inset
19303 </cell>
19304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19305 \begin_inset Text
19306
19307 \begin_layout Standard
19308
19309 \family roman
19310 \series medium
19311 \shape up
19312 \size normal
19313 \emph off
19314 \bar no
19315 \noun off
19316 \color none
19317 convert long to floating point number
19318 \end_layout
19319
19320 \end_inset
19321 </cell>
19322 </row>
19323 </lyxtabular>
19324
19325 \end_inset
19326
19327
19328 \newline
19329
19330 \end_layout
19331
19332 \begin_layout Standard
19333 These support routines are developed in ANSI-C so there is room for space
19334  and speed improvement
19335 \begin_inset Foot
19336 status open
19337
19338 \begin_layout Standard
19339 These floating point routines (
19340 \emph on
19341 not
19342 \emph default
19343  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19344  
19345 \end_layout
19346
19347 \end_inset
19348
19349 .
19350  Note if all these routines are used simultaneously the data space might
19351  overflow.
19352  For serious floating point usage the large model might be needed.
19353  Also notice that you don't have to call this routines directly.
19354  The compiler will use them automatically every time a floating point operation
19355  is required.
19356 \begin_inset VSpace bigskip
19357 \end_inset
19358
19359
19360 \end_layout
19361
19362 \begin_layout Section
19363 Library Routines
19364 \begin_inset LatexCommand \index{Libraries}
19365
19366 \end_inset
19367
19368
19369 \end_layout
19370
19371 \begin_layout Standard
19372
19373 \emph on
19374 <pending: this is messy and incomplete - a little more information is in
19375  sdcc/doc/libdoc.txt
19376 \emph default
19377  >
19378 \end_layout
19379
19380 \begin_layout Subsection
19381 Compiler support routines (_gptrget, _mulint etc.)
19382 \end_layout
19383
19384 \begin_layout Subsection
19385 Stdclib functions (puts, printf, strcat etc.)
19386 \end_layout
19387
19388 \begin_layout Subsubsection
19389 <stdio.h>
19390 \end_layout
19391
19392 \begin_layout Paragraph
19393 getchar(), putchar()
19394 \end_layout
19395
19396 \begin_layout Standard
19397 \begin_inset LatexCommand \index{<stdio.h>}
19398
19399 \end_inset
19400
19401 As usual on embedded systems you have to provide your own 
19402 \family typewriter
19403 getchar()
19404 \begin_inset LatexCommand \index{getchar()}
19405
19406 \end_inset
19407
19408  
19409 \family default
19410 and 
19411 \family typewriter
19412 putchar()
19413 \begin_inset LatexCommand \index{putchar()}
19414
19415 \end_inset
19416
19417
19418 \family default
19419  routines.
19420  SDCC does not know whether the system connects to a serial line with or
19421  without handshake, LCD, keyboard or other device.
19422  And whether a 
19423 \family typewriter
19424 lf
19425 \family default
19426  to 
19427 \family typewriter
19428 crlf
19429 \family default
19430  conversion within 
19431 \family typewriter
19432 putchar()
19433 \family default
19434  is intended.
19435  You'll find examples for serial routines f.e.
19436  in sdcc/device/lib.
19437  For the mcs51 this minimalistic polling 
19438 \family typewriter
19439 putchar()
19440 \family default
19441  routine might be a start:
19442 \end_layout
19443
19444 \begin_layout Verse
19445
19446 \family typewriter
19447 void putchar (char c) { 
19448 \newline
19449 \InsetSpace ~
19450 \InsetSpace ~
19451 \InsetSpace ~
19452 \InsetSpace ~
19453 while (!TI)\InsetSpace ~
19454 \InsetSpace ~
19455 \InsetSpace ~
19456  /* assumes UART is initialized */
19457 \newline
19458 \InsetSpace ~
19459 \InsetSpace ~
19460 \InsetSpace ~
19461 \InsetSpace ~
19462 \InsetSpace ~
19463 \InsetSpace ~
19464 \InsetSpace ~
19465 \InsetSpace ~
19466 ;
19467 \newline
19468 \InsetSpace ~
19469 \InsetSpace ~
19470 \InsetSpace ~
19471 \InsetSpace ~
19472 TI
19473  = 0;
19474 \newline
19475 \InsetSpace ~
19476 \InsetSpace ~
19477 \InsetSpace ~
19478 \InsetSpace ~
19479 SBUF = c;
19480 \newline
19481 }
19482 \end_layout
19483
19484 \begin_layout Paragraph
19485 printf()
19486 \end_layout
19487
19488 \begin_layout Standard
19489 The default
19490 \family typewriter
19491  printf()
19492 \begin_inset LatexCommand \index{printf()}
19493
19494 \end_inset
19495
19496
19497 \family default
19498  implementation in
19499 \family typewriter
19500  printf_large.c
19501 \family default
19502  does not support float (except on ds390).
19503  To enable this recompile it with the option 
19504 \emph on
19505 -
19506 \begin_inset ERT
19507 status collapsed
19508
19509 \begin_layout Standard
19510
19511
19512 \backslash
19513 /
19514 \end_layout
19515
19516 \end_inset
19517
19518 DUSE_FLOATS=1
19519 \begin_inset LatexCommand \index{USE\_FLOATS}
19520
19521 \end_inset
19522
19523
19524 \emph default
19525  on the command line.
19526  Use
19527 \emph on
19528  -
19529 \begin_inset ERT
19530 status collapsed
19531
19532 \begin_layout Standard
19533
19534
19535 \backslash
19536 /
19537 \end_layout
19538
19539 \end_inset
19540
19541 -model-large
19542 \begin_inset LatexCommand \index{-\/-model-large}
19543
19544 \end_inset
19545
19546
19547 \emph default
19548  for the mcs51 port, since this uses a lot of memory.
19549 \end_layout
19550
19551 \begin_layout Standard
19552 If you're short on code memory you might want to use 
19553 \family typewriter
19554 printf_small()
19555 \begin_inset LatexCommand \index{printf\_small()}
19556
19557 \end_inset
19558
19559
19560 \family default
19561  
19562 \emph on
19563 instead
19564 \emph default
19565  of
19566 \family typewriter
19567  printf().
19568
19569 \family default
19570  For the mcs51 there additionally are assembly versions 
19571 \family typewriter
19572 printf_tiny()
19573 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19574
19575 \end_inset
19576
19577
19578 \family default
19579  (subset of printf using less than 270 bytes) and 
19580 \family typewriter
19581 printf_fast()
19582 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19583
19584 \end_inset
19585
19586  
19587 \family default
19588 and
19589 \family typewriter
19590  printf_fast_f()
19591 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19592
19593 \end_inset
19594
19595
19596 \family default
19597  (floating-point aware version of printf_fast) which should fit the requirements
19598  of many embedded systems (printf_fast() can be customized by unsetting
19599  #defines to 
19600 \emph on
19601 not
19602 \emph default
19603  support long variables and field widths).
19604  Be sure to use only one of these printf options within a project.
19605 \newline
19606
19607 \end_layout
19608
19609 \begin_layout Standard
19610 Feature matrix of different 
19611 \emph on
19612 printf
19613 \emph default
19614  options on mcs51.
19615 \end_layout
19616
19617 \begin_layout Standard
19618 \begin_inset Tabular
19619 <lyxtabular version="3" rows="14" columns="7">
19620 <features islongtable="true">
19621 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19622 <column alignment="center" valignment="top" leftline="true" width="0">
19623 <column alignment="center" valignment="top" leftline="true" width="12col%">
19624 <column alignment="center" valignment="top" leftline="true" width="10col%">
19625 <column alignment="center" valignment="top" leftline="true" width="0">
19626 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19627 <column alignment="center" valignment="top" rightline="true" width="0">
19628 <row topline="true" bottomline="true" endhead="true">
19629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19630 \begin_inset Text
19631
19632 \begin_layout Standard
19633
19634 \series bold
19635 \size large
19636 mcs51
19637 \end_layout
19638
19639 \end_inset
19640 </cell>
19641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19642 \begin_inset Text
19643
19644 \begin_layout Standard
19645 printf
19646 \begin_inset LatexCommand \index{printf}
19647
19648 \end_inset
19649
19650
19651 \end_layout
19652
19653 \end_inset
19654 </cell>
19655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19656 \begin_inset Text
19657
19658 \begin_layout Standard
19659 printf 
19660 \size scriptsize
19661 USE_FLOATS=1
19662 \end_layout
19663
19664 \end_inset
19665 </cell>
19666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19667 \begin_inset Text
19668
19669 \begin_layout Standard
19670 printf_small
19671 \end_layout
19672
19673 \end_inset
19674 </cell>
19675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19676 \begin_inset Text
19677
19678 \begin_layout Standard
19679 printf_fast
19680 \end_layout
19681
19682 \end_inset
19683 </cell>
19684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19685 \begin_inset Text
19686
19687 \begin_layout Standard
19688 printf_fast_f
19689 \end_layout
19690
19691 \end_inset
19692 </cell>
19693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19694 \begin_inset Text
19695
19696 \begin_layout Standard
19697 printf_tiny
19698 \end_layout
19699
19700 \end_inset
19701 </cell>
19702 </row>
19703 <row topline="true" endhead="true">
19704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19705 \begin_inset Text
19706
19707 \begin_layout Standard
19708 filename
19709 \end_layout
19710
19711 \end_inset
19712 </cell>
19713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19714 \begin_inset Text
19715
19716 \begin_layout Standard
19717
19718 \size scriptsize
19719 printf_large.c
19720 \end_layout
19721
19722 \end_inset
19723 </cell>
19724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19725 \begin_inset Text
19726
19727 \begin_layout Standard
19728
19729 \size scriptsize
19730 printf_large.c
19731 \end_layout
19732
19733 \end_inset
19734 </cell>
19735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19736 \begin_inset Text
19737
19738 \begin_layout Standard
19739
19740 \size scriptsize
19741 printfl.c
19742 \end_layout
19743
19744 \end_inset
19745 </cell>
19746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19747 \begin_inset Text
19748
19749 \begin_layout Standard
19750
19751 \size scriptsize
19752 printf_fast.c
19753 \end_layout
19754
19755 \end_inset
19756 </cell>
19757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19758 \begin_inset Text
19759
19760 \begin_layout Standard
19761
19762 \size scriptsize
19763 printf_fast_f.c
19764 \end_layout
19765
19766 \end_inset
19767 </cell>
19768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19769 \begin_inset Text
19770
19771 \begin_layout Standard
19772
19773 \size scriptsize
19774 printf_tiny.c
19775 \end_layout
19776
19777 \end_inset
19778 </cell>
19779 </row>
19780 <row topline="true" endhead="true">
19781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19782 \begin_inset Text
19783
19784 \begin_layout Standard
19785 \begin_inset Quotes sld
19786 \end_inset
19787
19788 Hello World
19789 \begin_inset Quotes srd
19790 \end_inset
19791
19792  size
19793 \end_layout
19794
19795 \begin_layout Standard
19796 small / large
19797 \end_layout
19798
19799 \end_inset
19800 </cell>
19801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19802 \begin_inset Text
19803
19804 \begin_layout Standard
19805 1.7k / 2.4k
19806 \end_layout
19807
19808 \end_inset
19809 </cell>
19810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19811 \begin_inset Text
19812
19813 \begin_layout Standard
19814 4.3k / 5.6k
19815 \end_layout
19816
19817 \end_inset
19818 </cell>
19819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19820 \begin_inset Text
19821
19822 \begin_layout Standard
19823 1.2k / 1.8k
19824 \end_layout
19825
19826 \end_inset
19827 </cell>
19828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19829 \begin_inset Text
19830
19831 \begin_layout Standard
19832 1.3k / 1.3k
19833 \end_layout
19834
19835 \end_inset
19836 </cell>
19837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19838 \begin_inset Text
19839
19840 \begin_layout Standard
19841 1.9k / 1.9k
19842 \end_layout
19843
19844 \end_inset
19845 </cell>
19846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19847 \begin_inset Text
19848
19849 \begin_layout Standard
19850 0.44k / 0.44k
19851 \end_layout
19852
19853 \end_inset
19854 </cell>
19855 </row>
19856 <row topline="true" endhead="true">
19857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19858 \begin_inset Text
19859
19860 \begin_layout Standard
19861 code size
19862 \end_layout
19863
19864 \begin_layout Standard
19865 small / large
19866 \end_layout
19867
19868 \end_inset
19869 </cell>
19870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19871 \begin_inset Text
19872
19873 \begin_layout Standard
19874 1.4k / 2.0k
19875 \end_layout
19876
19877 \end_inset
19878 </cell>
19879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19880 \begin_inset Text
19881
19882 \begin_layout Standard
19883 2.8k / 3.7k
19884 \end_layout
19885
19886 \end_inset
19887 </cell>
19888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19889 \begin_inset Text
19890
19891 \begin_layout Standard
19892 0.45k / 0.47k (+ _ltoa)
19893 \end_layout
19894
19895 \end_inset
19896 </cell>
19897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19898 \begin_inset Text
19899
19900 \begin_layout Standard
19901 1.2k / 1.2k
19902 \end_layout
19903
19904 \end_inset
19905 </cell>
19906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19907 \begin_inset Text
19908
19909 \begin_layout Standard
19910 1.6k / 1.6k
19911 \end_layout
19912
19913 \end_inset
19914 </cell>
19915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19916 \begin_inset Text
19917
19918 \begin_layout Standard
19919 0.26k / 0.26k
19920 \end_layout
19921
19922 \end_inset
19923 </cell>
19924 </row>
19925 <row topline="true">
19926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19927 \begin_inset Text
19928
19929 \begin_layout Standard
19930 formats
19931 \end_layout
19932
19933 \end_inset
19934 </cell>
19935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19936 \begin_inset Text
19937
19938 \begin_layout Standard
19939 cdi
19940 \emph on
19941 o
19942 \emph default
19943 psux
19944 \end_layout
19945
19946 \end_inset
19947 </cell>
19948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19949 \begin_inset Text
19950
19951 \begin_layout Standard
19952
19953 \family roman
19954 \series medium
19955 \shape up
19956 \size normal
19957 \emph off
19958 \bar no
19959 \noun off
19960 \color none
19961 cd
19962 \family default
19963 \series default
19964 \shape default
19965 \size default
19966 \emph default
19967 \bar default
19968 \noun default
19969 f
19970 \family roman
19971 \series medium
19972 \shape up
19973 \size normal
19974 \emph off
19975 \bar no
19976 \noun off
19977 i
19978 \family default
19979 \series default
19980 \shape default
19981 \size default
19982 \emph on
19983 \bar default
19984 \noun default
19985 o
19986 \family roman
19987 \series medium
19988 \shape up
19989 \size normal
19990 \emph off
19991 \bar no
19992 \noun off
19993 psux
19994 \end_layout
19995
19996 \end_inset
19997 </cell>
19998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19999 \begin_inset Text
20000
20001 \begin_layout Standard
20002 c
20003 \family roman
20004 \series medium
20005 \shape up
20006 \size normal
20007 \emph off
20008 \bar no
20009 \noun off
20010 \color none
20011 d
20012 \family default
20013 \series default
20014 \shape default
20015 \size default
20016 \emph on
20017 \bar default
20018 \noun default
20019 o
20020 \family roman
20021 \series medium
20022 \shape up
20023 \size normal
20024 \emph off
20025 \bar no
20026 \noun off
20027 s
20028 \family default
20029 \series default
20030 \shape default
20031 \size default
20032 \emph default
20033 \bar default
20034 \noun default
20035 x
20036 \end_layout
20037
20038 \end_inset
20039 </cell>
20040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20041 \begin_inset Text
20042
20043 \begin_layout Standard
20044 cdsux
20045 \end_layout
20046
20047 \end_inset
20048 </cell>
20049 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20050 \begin_inset Text
20051
20052 \begin_layout Standard
20053 cdfsux
20054 \end_layout
20055
20056 \end_inset
20057 </cell>
20058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20059 \begin_inset Text
20060
20061 \begin_layout Standard
20062 cdsux
20063 \end_layout
20064
20065 \end_inset
20066 </cell>
20067 </row>
20068 <row topline="true">
20069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20070 \begin_inset Text
20071
20072 \begin_layout Standard
20073 long (32 bit) support
20074 \end_layout
20075
20076 \end_inset
20077 </cell>
20078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20079 \begin_inset Text
20080
20081 \begin_layout Standard
20082 x
20083 \end_layout
20084
20085 \end_inset
20086 </cell>
20087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20088 \begin_inset Text
20089
20090 \begin_layout Standard
20091 x
20092 \end_layout
20093
20094 \end_inset
20095 </cell>
20096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20097 \begin_inset Text
20098
20099 \begin_layout Standard
20100 x
20101 \end_layout
20102
20103 \end_inset
20104 </cell>
20105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20106 \begin_inset Text
20107
20108 \begin_layout Standard
20109 x
20110 \end_layout
20111
20112 \end_inset
20113 </cell>
20114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20115 \begin_inset Text
20116
20117 \begin_layout Standard
20118
20119 \family roman
20120 \series medium
20121 \shape up
20122 \size normal
20123 \emph off
20124 \bar no
20125 \noun off
20126 \color none
20127 x
20128 \end_layout
20129
20130 \end_inset
20131 </cell>
20132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20133 \begin_inset Text
20134
20135 \begin_layout Standard
20136 -
20137 \end_layout
20138
20139 \end_inset
20140 </cell>
20141 </row>
20142 <row topline="true">
20143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20144 \begin_inset Text
20145
20146 \begin_layout Standard
20147 byte arguments on stack
20148 \end_layout
20149
20150 \end_inset
20151 </cell>
20152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20153 \begin_inset Text
20154
20155 \begin_layout Standard
20156 b
20157 \end_layout
20158
20159 \end_inset
20160 </cell>
20161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20162 \begin_inset Text
20163
20164 \begin_layout Standard
20165 b
20166 \end_layout
20167
20168 \end_inset
20169 </cell>
20170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20171 \begin_inset Text
20172
20173 \begin_layout Standard
20174 -
20175 \end_layout
20176
20177 \end_inset
20178 </cell>
20179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20180 \begin_inset Text
20181
20182 \begin_layout Standard
20183 -
20184 \end_layout
20185
20186 \end_inset
20187 </cell>
20188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20189 \begin_inset Text
20190
20191 \begin_layout Standard
20192 -
20193 \end_layout
20194
20195 \end_inset
20196 </cell>
20197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20198 \begin_inset Text
20199
20200 \begin_layout Standard
20201 -
20202 \end_layout
20203
20204 \end_inset
20205 </cell>
20206 </row>
20207 <row topline="true">
20208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20209 \begin_inset Text
20210
20211 \begin_layout Standard
20212 float format
20213 \begin_inset LatexCommand \index{Floating point support}
20214
20215 \end_inset
20216
20217
20218 \end_layout
20219
20220 \end_inset
20221 </cell>
20222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20223 \begin_inset Text
20224
20225 \begin_layout Standard
20226 -
20227 \end_layout
20228
20229 \end_inset
20230 </cell>
20231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20232 \begin_inset Text
20233
20234 \begin_layout Standard
20235 %f
20236 \end_layout
20237
20238 \end_inset
20239 </cell>
20240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20241 \begin_inset Text
20242
20243 \begin_layout Standard
20244 -
20245 \end_layout
20246
20247 \end_inset
20248 </cell>
20249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20250 \begin_inset Text
20251
20252 \begin_layout Standard
20253 -
20254 \end_layout
20255
20256 \end_inset
20257 </cell>
20258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20259 \begin_inset Text
20260
20261 \begin_layout Standard
20262 %f
20263 \begin_inset Foot
20264 status collapsed
20265
20266 \begin_layout Standard
20267 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20268 \end_layout
20269
20270 \end_inset
20271
20272
20273 \end_layout
20274
20275 \end_inset
20276 </cell>
20277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20278 \begin_inset Text
20279
20280 \begin_layout Standard
20281 -
20282 \end_layout
20283
20284 \end_inset
20285 </cell>
20286 </row>
20287 <row topline="true">
20288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20289 \begin_inset Text
20290
20291 \begin_layout Standard
20292 float formats %e %g
20293 \end_layout
20294
20295 \end_inset
20296 </cell>
20297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20298 \begin_inset Text
20299
20300 \begin_layout Standard
20301 -
20302 \end_layout
20303
20304 \end_inset
20305 </cell>
20306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20307 \begin_inset Text
20308
20309 \begin_layout Standard
20310 -
20311 \end_layout
20312
20313 \end_inset
20314 </cell>
20315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20316 \begin_inset Text
20317
20318 \begin_layout Standard
20319 -
20320 \end_layout
20321
20322 \end_inset
20323 </cell>
20324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20325 \begin_inset Text
20326
20327 \begin_layout Standard
20328 -
20329 \end_layout
20330
20331 \end_inset
20332 </cell>
20333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20334 \begin_inset Text
20335
20336 \begin_layout Standard
20337 -
20338 \end_layout
20339
20340 \end_inset
20341 </cell>
20342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20343 \begin_inset Text
20344
20345 \begin_layout Standard
20346 -
20347 \end_layout
20348
20349 \end_inset
20350 </cell>
20351 </row>
20352 <row topline="true" bottomline="true">
20353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20354 \begin_inset Text
20355
20356 \begin_layout Standard
20357 field width
20358 \end_layout
20359
20360 \end_inset
20361 </cell>
20362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20363 \begin_inset Text
20364
20365 \begin_layout Standard
20366 x
20367 \end_layout
20368
20369 \end_inset
20370 </cell>
20371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20372 \begin_inset Text
20373
20374 \begin_layout Standard
20375 x
20376 \end_layout
20377
20378 \end_inset
20379 </cell>
20380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20381 \begin_inset Text
20382
20383 \begin_layout Standard
20384 -
20385 \end_layout
20386
20387 \end_inset
20388 </cell>
20389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20390 \begin_inset Text
20391
20392 \begin_layout Standard
20393 x
20394 \end_layout
20395
20396 \end_inset
20397 </cell>
20398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20399 \begin_inset Text
20400
20401 \begin_layout Standard
20402 x
20403 \end_layout
20404
20405 \end_inset
20406 </cell>
20407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20408 \begin_inset Text
20409
20410 \begin_layout Standard
20411 -
20412 \end_layout
20413
20414 \end_inset
20415 </cell>
20416 </row>
20417 <row bottomline="true">
20418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20419 \begin_inset Text
20420
20421 \begin_layout Standard
20422 string speed
20423 \begin_inset Foot
20424 status collapsed
20425
20426 \begin_layout Standard
20427 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20428 \backslash
20429 r', '
20430 \backslash
20431 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20432 \end_layout
20433
20434 \end_inset
20435
20436 ,
20437 \end_layout
20438
20439 \begin_layout Standard
20440 small / large
20441 \end_layout
20442
20443 \end_inset
20444 </cell>
20445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20446 \begin_inset Text
20447
20448 \begin_layout Standard
20449 1.52 / 2.59 ms
20450 \end_layout
20451
20452 \end_inset
20453 </cell>
20454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20455 \begin_inset Text
20456
20457 \begin_layout Standard
20458 1.53 / 2.62 ms
20459 \end_layout
20460
20461 \end_inset
20462 </cell>
20463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20464 \begin_inset Text
20465
20466 \begin_layout Standard
20467 0.92 / 0.93 ms
20468 \end_layout
20469
20470 \end_inset
20471 </cell>
20472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20473 \begin_inset Text
20474
20475 \begin_layout Standard
20476 0.45 / 0.45 ms
20477 \end_layout
20478
20479 \end_inset
20480 </cell>
20481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20482 \begin_inset Text
20483
20484 \begin_layout Standard
20485 0.46 / 0.46 ms
20486 \end_layout
20487
20488 \end_inset
20489 </cell>
20490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20491 \begin_inset Text
20492
20493 \begin_layout Standard
20494 0.45 / 0.45 ms
20495 \end_layout
20496
20497 \end_inset
20498 </cell>
20499 </row>
20500 <row bottomline="true">
20501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20502 \begin_inset Text
20503
20504 \begin_layout Standard
20505 int speed
20506 \begin_inset Foot
20507 status collapsed
20508
20509 \begin_layout Standard
20510 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20511  putchar()
20512 \end_layout
20513
20514 \end_inset
20515
20516 ,
20517 \end_layout
20518
20519 \begin_layout Standard
20520 small / large
20521 \end_layout
20522
20523 \end_inset
20524 </cell>
20525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20526 \begin_inset Text
20527
20528 \begin_layout Standard
20529 3.01 / 3.61 ms
20530 \end_layout
20531
20532 \end_inset
20533 </cell>
20534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20535 \begin_inset Text
20536
20537 \begin_layout Standard
20538 3.01 / 3.61 ms
20539 \end_layout
20540
20541 \end_inset
20542 </cell>
20543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20544 \begin_inset Text
20545
20546 \begin_layout Standard
20547 3.51 / 18.13 ms
20548 \end_layout
20549
20550 \end_inset
20551 </cell>
20552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20553 \begin_inset Text
20554
20555 \begin_layout Standard
20556 0.22 / 0.22 ms
20557 \end_layout
20558
20559 \end_inset
20560 </cell>
20561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20562 \begin_inset Text
20563
20564 \begin_layout Standard
20565 0.23 / 0.23 ms
20566 \end_layout
20567
20568 \end_inset
20569 </cell>
20570 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20571 \begin_inset Text
20572
20573 \begin_layout Standard
20574 0.25 / 0.25 ms
20575 \begin_inset Foot
20576 status collapsed
20577
20578 \begin_layout Standard
20579 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20580 \end_layout
20581
20582 \end_inset
20583
20584
20585 \end_layout
20586
20587 \end_inset
20588 </cell>
20589 </row>
20590 <row bottomline="true">
20591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20592 \begin_inset Text
20593
20594 \begin_layout Standard
20595 long speed
20596 \begin_inset Foot
20597 status collapsed
20598
20599 \begin_layout Standard
20600 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20601  empty putchar()
20602 \end_layout
20603
20604 \end_inset
20605
20606 ,
20607 \end_layout
20608
20609 \begin_layout Standard
20610 small / large
20611 \end_layout
20612
20613 \end_inset
20614 </cell>
20615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20616 \begin_inset Text
20617
20618 \begin_layout Standard
20619 5.37 / 6.31 ms
20620 \end_layout
20621
20622 \end_inset
20623 </cell>
20624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20625 \begin_inset Text
20626
20627 \begin_layout Standard
20628 5.37 / 6.31 ms
20629 \end_layout
20630
20631 \end_inset
20632 </cell>
20633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20634 \begin_inset Text
20635
20636 \begin_layout Standard
20637 8.71 / 40.65 ms
20638 \end_layout
20639
20640 \end_inset
20641 </cell>
20642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20643 \begin_inset Text
20644
20645 \begin_layout Standard
20646 0.40 / 0.40 ms
20647 \end_layout
20648
20649 \end_inset
20650 </cell>
20651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20652 \begin_inset Text
20653
20654 \begin_layout Standard
20655 0.40 / 0.40 ms
20656 \end_layout
20657
20658 \end_inset
20659 </cell>
20660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20661 \begin_inset Text
20662
20663 \begin_layout Standard
20664 -
20665 \end_layout
20666
20667 \end_inset
20668 </cell>
20669 </row>
20670 <row bottomline="true">
20671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20672 \begin_inset Text
20673
20674 \begin_layout Standard
20675 float speed
20676 \begin_inset Foot
20677 status collapsed
20678
20679 \begin_layout Standard
20680 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
20681  empty putchar()
20682 \end_layout
20683
20684 \end_inset
20685
20686 ,
20687 \end_layout
20688
20689 \begin_layout Standard
20690 small / large
20691 \end_layout
20692
20693 \end_inset
20694 </cell>
20695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20696 \begin_inset Text
20697
20698 \begin_layout Standard
20699 -
20700 \end_layout
20701
20702 \end_inset
20703 </cell>
20704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20705 \begin_inset Text
20706
20707 \begin_layout Standard
20708 7.49 / 22.47 ms
20709 \end_layout
20710
20711 \end_inset
20712 </cell>
20713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20714 \begin_inset Text
20715
20716 \begin_layout Standard
20717 -
20718 \end_layout
20719
20720 \end_inset
20721 </cell>
20722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20723 \begin_inset Text
20724
20725 \begin_layout Standard
20726 -
20727 \end_layout
20728
20729 \end_inset
20730 </cell>
20731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20732 \begin_inset Text
20733
20734 \begin_layout Standard
20735 1.04 / 1.04 ms
20736 \end_layout
20737
20738 \end_inset
20739 </cell>
20740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20741 \begin_inset Text
20742
20743 \begin_layout Standard
20744 -
20745 \end_layout
20746
20747 \end_inset
20748 </cell>
20749 </row>
20750 </lyxtabular>
20751
20752 \end_inset
20753
20754
20755 \end_layout
20756
20757 \begin_layout Subsubsection
20758 <malloc.h>
20759 \begin_inset LatexCommand \index{malloc.h}
20760
20761 \end_inset
20762
20763
20764 \end_layout
20765
20766 \begin_layout Standard
20767 As of SDCC 2.6.2 you no longer need to call an initialization routine before
20768  using dynamic memory allocation
20769 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
20770
20771 \end_inset
20772
20773  and a default heap
20774 \begin_inset LatexCommand \index{heap (malloc)}
20775
20776 \end_inset
20777
20778  space of 1024 bytes is provided for malloc to allocate memory from.
20779  If you need a different heap size you need to recompile _heap.c with the
20780  required size defined in HEAP_SIZE.
20781  It is recommended to make a copy of this file into your project directory
20782  and compile it there with:
20783 \end_layout
20784
20785 \begin_layout Verse
20786
20787 \family typewriter
20788 sdcc -c _heap.c -D HEAD_SIZE=2048
20789 \end_layout
20790
20791 \begin_layout Standard
20792 And then link it with:
20793 \end_layout
20794
20795 \begin_layout Verse
20796
20797 \family typewriter
20798 sdcc main.rel _heap.rel
20799 \end_layout
20800
20801 \begin_layout Subsection
20802 Math functions (sinf, powf, sqrtf etc.)
20803 \end_layout
20804
20805 \begin_layout Subsubsection
20806 <math.h>
20807 \end_layout
20808
20809 \begin_layout Standard
20810 See definitions in file <math.h>.
20811 \end_layout
20812
20813 \begin_layout Subsection
20814 Other libraries
20815 \end_layout
20816
20817 \begin_layout Standard
20818 Libraries
20819 \begin_inset LatexCommand \index{Libraries}
20820
20821 \end_inset
20822
20823  included in SDCC should have a license at least as liberal as the GNU Lesser
20824  General Public License
20825 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
20826
20827 \end_inset
20828
20829  
20830 \emph on
20831 LGPL
20832 \emph default
20833 .
20834 \end_layout
20835
20836 \begin_layout Standard
20837 \begin_inset Note Note
20838 status collapsed
20839
20840 \begin_layout Standard
20841 license statements for the libraries are missing.
20842  sdcc/device/lib/ser_ir.c
20843 \end_layout
20844
20845 \begin_layout Standard
20846 or _decdptr f.e.
20847  come with a GPL (as opposed to LGPL) License - this will not be liberal
20848  enough for many embedded programmers.
20849 \end_layout
20850
20851 \end_inset
20852
20853
20854 \end_layout
20855
20856 \begin_layout Standard
20857 If you have ported some library or want to share experience about some code
20858  which f.e.
20859  falls into any of these categories Busses (I
20860 \begin_inset Formula $^{\textrm{2}}$
20861 \end_inset
20862
20863 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
20864  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
20865  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
20866 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
20867
20868 \end_inset
20869
20870 \InsetSpace ~
20871 would certainly like to hear about it.
20872 \end_layout
20873
20874 \begin_layout Standard
20875 Programmers coding for embedded systems are not especially famous for being
20876  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
20877 e these references are very valuable.
20878  Let's help to create a climate where information is shared.
20879 \begin_inset VSpace bigskip
20880 \end_inset
20881
20882
20883 \end_layout
20884
20885 \begin_layout Section
20886 Memory Models
20887 \end_layout
20888
20889 \begin_layout Subsection
20890 MCS51 Memory Models
20891 \begin_inset LatexCommand \index{Memory model}
20892
20893 \end_inset
20894
20895
20896 \begin_inset LatexCommand \index{MCS51 memory model}
20897
20898 \end_inset
20899
20900
20901 \end_layout
20902
20903 \begin_layout Subsubsection
20904 Small, Medium and Large
20905 \end_layout
20906
20907 \begin_layout Standard
20908 SDCC allows three memory models for MCS51 code, 
20909 \shape slanted
20910 small, medium
20911 \shape default
20912  and 
20913 \shape slanted
20914 large
20915 \shape default
20916 .
20917  Modules compiled with different memory models should 
20918 \emph on
20919 never
20920 \emph default
20921  be combined together or the results would be unpredictable.
20922  The library routines supplied with the compiler are compiled as small,
20923  medium and large.
20924  The compiled library modules are contained in separate directories as small,
20925  medium and large so that you can link to the appropriate set.
20926 \end_layout
20927
20928 \begin_layout Standard
20929 When the medium or large model is used all variables declared without a
20930  storage class will be allocated into the external ram, this includes all
20931  parameters and local variables (for non-reentrant
20932 \begin_inset LatexCommand \index{reentrant}
20933
20934 \end_inset
20935
20936  functions).
20937  When the small model is used variables without storage class are allocated
20938  in the internal ram.
20939 \end_layout
20940
20941 \begin_layout Standard
20942 Judicious usage of the processor specific storage classes
20943 \begin_inset LatexCommand \index{Storage class}
20944
20945 \end_inset
20946
20947  and the 'reentrant' function type will yield much more efficient code,
20948  than using the large model.
20949  Several optimizations are disabled when the program is compiled using the
20950  large model, it is therefore recommended that the small model be used unless
20951  absolutely required.
20952 \end_layout
20953
20954 \begin_layout Subsubsection
20955 External Stack
20956 \begin_inset LatexCommand \label{sub:External-Stack}
20957
20958 \end_inset
20959
20960
20961 \begin_inset LatexCommand \index{stack}
20962
20963 \end_inset
20964
20965
20966 \begin_inset LatexCommand \index{External stack (mcs51)}
20967
20968 \end_inset
20969
20970
20971 \end_layout
20972
20973 \begin_layout Standard
20974 The external stack (-
20975 \begin_inset ERT
20976 status collapsed
20977
20978 \begin_layout Standard
20979
20980
20981 \backslash
20982 /
20983 \end_layout
20984
20985 \end_inset
20986
20987 -xstack option
20988 \begin_inset LatexCommand \index{-\/-xstack}
20989
20990 \end_inset
20991
20992 ) is located in pdata
20993 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20994
20995 \end_inset
20996
20997  memory (usually at the start of the external ram segment) and uses all
20998  unused space in pdata (max.
20999  256 bytes).
21000  When -
21001 \begin_inset ERT
21002 status collapsed
21003
21004 \begin_layout Standard
21005
21006
21007 \backslash
21008 /
21009 \end_layout
21010
21011 \end_inset
21012
21013 -xstack option is used to compile the program, the parameters and local
21014  variables
21015 \begin_inset LatexCommand \index{local variables}
21016
21017 \end_inset
21018
21019  of all reentrant functions are allocated in this area.
21020  This option is provided for programs with large stack space requirements.
21021  When used with the -
21022 \begin_inset ERT
21023 status collapsed
21024
21025 \begin_layout Standard
21026
21027
21028 \backslash
21029 /
21030 \end_layout
21031
21032 \end_inset
21033
21034 -stack-auto
21035 \begin_inset LatexCommand \index{-\/-stack-auto}
21036
21037 \end_inset
21038
21039  option, all parameters and local variables are allocated on the external
21040  stack (note: support libraries will need to be recompiled with the same
21041  options.
21042  There is a predefined target in the library makefile).
21043 \end_layout
21044
21045 \begin_layout Standard
21046 The compiler outputs the higher order address byte of the external ram segment
21047  into port P2
21048 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
21049
21050 \end_inset
21051
21052  (see also section 
21053 \begin_inset LatexCommand \ref{sub:MCS51-variants}
21054
21055 \end_inset
21056
21057 ), therefore when using the External Stack option, this port 
21058 \emph on
21059 may not
21060 \emph default
21061  be used by the application program.
21062 \end_layout
21063
21064 \begin_layout Subsection
21065 DS390 Memory Model
21066 \begin_inset LatexCommand \index{Memory model}
21067
21068 \end_inset
21069
21070
21071 \begin_inset LatexCommand \index{DS390 memory model}
21072
21073 \end_inset
21074
21075
21076 \end_layout
21077
21078 \begin_layout Standard
21079 The only model supported is Flat 24
21080 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21081
21082 \end_inset
21083
21084 .
21085  This generates code for the 24 bit contiguous addressing mode of the Dallas
21086  DS80C390 part.
21087  In this mode, up to four meg of external RAM or code space can be directly
21088  addressed.
21089  See the data sheets at www.dalsemi.com for further information on this part.
21090 \newline
21091
21092 \newline
21093 Note
21094  that the compiler does not generate any code to place the processor into
21095  24 bitmode (although 
21096 \emph on
21097 tinibios
21098 \emph default
21099  in the ds390 libraries will do that for you).
21100  If you don't use 
21101 \emph on
21102 tinibios
21103 \emph default
21104
21105 \begin_inset LatexCommand \index{Tinibios (DS390)}
21106
21107 \end_inset
21108
21109 , the boot loader or similar code must ensure that the processor is in 24
21110  bit contiguous addressing mode before calling the SDCC startup code.
21111 \newline
21112
21113 \newline
21114 Like
21115  the 
21116 \emph on
21117 -
21118 \begin_inset ERT
21119 status collapsed
21120
21121 \begin_layout Standard
21122
21123
21124 \backslash
21125 /
21126 \end_layout
21127
21128 \end_inset
21129
21130 -model-large
21131 \emph default
21132  option, variables will by default be placed into the XDATA segment.
21133  
21134 \newline
21135
21136 \newline
21137 Segments may be placed anywhere in the 4 meg address space using the usual
21138  -
21139 \begin_inset ERT
21140 status collapsed
21141
21142 \begin_layout Standard
21143
21144
21145 \backslash
21146 /
21147 \end_layout
21148
21149 \end_inset
21150
21151 -*-loc options.
21152  Note that if any segments are located above 64K, the -r flag must be passed
21153  to the linker to generate the proper segment relocations, and the Intel
21154  HEX output format must be used.
21155  The -r flag can be passed to the linker by using the option 
21156 \emph on
21157 -Wl-r
21158 \emph default
21159  on the SDCC command line.
21160  However, currently the linker can not handle code segments > 64k.
21161 \end_layout
21162
21163 \begin_layout Section
21164 Pragmas
21165 \begin_inset LatexCommand \label{sec:Pragmas}
21166
21167 \end_inset
21168
21169
21170 \begin_inset LatexCommand \index{Pragmas}
21171
21172 \end_inset
21173
21174
21175 \end_layout
21176
21177 \begin_layout Standard
21178 Pragmas are used to turn on and/or off certain compiler options.
21179  Some of them are closely related to corresponding command-line options
21180  (see section 
21181 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21182
21183 \end_inset
21184
21185 ).
21186 \newline
21187 Pragmas should be placed before and/or after a function, placing pragmas
21188  inside a function body could have unpredictable results.
21189 \newline
21190
21191 \newline
21192 SDCC supports the
21193  following #pragma directives:
21194 \end_layout
21195
21196 \begin_layout Itemize
21197
21198 \series bold
21199 save
21200 \series default
21201
21202 \begin_inset LatexCommand \index{\#pragma save}
21203
21204 \end_inset
21205
21206  - this will save most current options to the save/restore stack.
21207  See #pragma\InsetSpace ~
21208 restore.
21209 \end_layout
21210
21211 \begin_layout Itemize
21212
21213 \series bold
21214 restore
21215 \series default
21216
21217 \begin_inset LatexCommand \index{\#pragma restore}
21218
21219 \end_inset
21220
21221  - will restore saved options from the last save.
21222  saves & restores can be nested.
21223  SDCC uses a save/restore stack: save pushes current options to the stack,
21224  restore pulls current options from the stack.
21225  See #pragma\InsetSpace ~
21226 save.
21227 \newline
21228
21229 \end_layout
21230
21231 \begin_layout Itemize
21232
21233 \series bold
21234 callee_saves
21235 \series default
21236
21237 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21238
21239 \end_inset
21240
21241
21242 \begin_inset LatexCommand \index{function prologue}
21243
21244 \end_inset
21245
21246  function1[,function2[,function3...]] 
21247 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21248
21249 \end_inset
21250
21251 - The compiler by default uses a caller saves convention for register saving
21252  across function calls, however this can cause unnecessary register pushing
21253  and popping
21254 \begin_inset LatexCommand \index{push/pop}
21255
21256 \end_inset
21257
21258  when calling small functions from larger functions.
21259  This option can be used to switch off the register saving convention for
21260  the function names specified.
21261  The compiler will not save registers when calling these functions, extra
21262  code need to be manually inserted at the entry and exit for these functions
21263  to save and restore the registers used by these functions, this can SUBSTANTIAL
21264 LY reduce code and improve run time performance of the generated code.
21265  In the future the compiler (with inter procedural analysis) may be able
21266  to determine the appropriate scheme to use for each function call.
21267  If -
21268 \begin_inset ERT
21269 status collapsed
21270
21271 \begin_layout Standard
21272
21273
21274 \backslash
21275 /
21276 \end_layout
21277
21278 \end_inset
21279
21280 -callee-saves command line option is used (see page 
21281 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21282
21283 \end_inset
21284
21285 ), the function names specified in #pragma\InsetSpace ~
21286 callee_saves
21287 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21288
21289 \end_inset
21290
21291  is appended to the list of functions specified in the command line.
21292 \end_layout
21293
21294 \begin_layout Itemize
21295
21296 \series bold
21297 exclude
21298 \series default
21299
21300 \begin_inset LatexCommand \index{\#pragma exclude}
21301
21302 \end_inset
21303
21304  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21305  of pairs of push/pop
21306 \begin_inset LatexCommand \index{push/pop}
21307
21308 \end_inset
21309
21310  instructions in 
21311 \emph on
21312 I
21313 \emph default
21314 nterrupt
21315 \begin_inset LatexCommand \index{interrupt}
21316
21317 \end_inset
21318
21319  
21320 \emph on
21321 S
21322 \emph default
21323 ervice 
21324 \emph on
21325 R
21326 \emph default
21327 outines.
21328  The directive should be placed immediately before the ISR function definition
21329  and it affects ALL ISR functions following it.
21330  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21331 exclude\InsetSpace ~
21332 none
21333 \begin_inset LatexCommand \index{\#pragma exclude}
21334
21335 \end_inset
21336
21337 .
21338  See also the related keyword _naked
21339 \begin_inset LatexCommand \index{\_naked}
21340
21341 \end_inset
21342
21343
21344 \begin_inset LatexCommand \index{\_\_naked}
21345
21346 \end_inset
21347
21348 .
21349 \end_layout
21350
21351 \begin_layout Itemize
21352
21353 \series bold
21354 less_pedantic
21355 \series default
21356
21357 \begin_inset LatexCommand \index{pedantic}
21358
21359 \end_inset
21360
21361
21362 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21363
21364 \end_inset
21365
21366  
21367 \begin_inset LatexCommand \label{ite:less_pedantic}
21368
21369 \end_inset
21370
21371 - the compiler will not warn you anymore for obvious mistakes, you'r on
21372  your own now ;-( .
21373  See also the command line option -
21374 \begin_inset ERT
21375 status collapsed
21376
21377 \begin_layout Standard
21378
21379
21380 \backslash
21381 /
21382 \end_layout
21383
21384 \end_inset
21385
21386 -less-pedantic 
21387 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21388
21389 \end_inset
21390
21391 .
21392  
21393 \newline
21394 More specifically, the following warnings will be disabled: 
21395 \shape italic
21396 comparison is always [true/false] due to limited range of data type
21397 \shape default
21398  (94); 
21399 \shape italic
21400 overflow in implicit constant conversion
21401 \shape default
21402  (158); [the (in)famous] 
21403 \shape italic
21404 conditional flow changed by optimizer: so said EVELYN the modified DOG
21405 \shape default
21406  (110); 
21407 \shape italic
21408 function '[function name]' must return value
21409 \shape default
21410  (59).
21411  
21412 \newline
21413 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21414  level) are disabled, too, namely: 
21415 \shape italic
21416 constant value '[
21417 \begin_inset Note Note
21418 status collapsed
21419
21420 \begin_layout Standard
21421 dunno what comes here - this warning appears to be unused altogether
21422 \end_layout
21423
21424 \end_inset
21425
21426 ]', out of range
21427 \shape default
21428  (81); 
21429 \shape italic
21430 [left/right] shifting more than size of object changed to zero
21431 \shape default
21432  (116); 
21433 \shape italic
21434 unreachable code
21435 \shape default
21436  (126); 
21437 \shape italic
21438 integer overflow in expression
21439 \shape default
21440  (165); 
21441 \shape italic
21442 unmatched #pragma save and #pragma restore
21443 \shape default
21444  (170); 
21445 \shape italic
21446 comparison of 'signed char' with 'unsigned char' requires promotion to int
21447 \shape default
21448  (185); 
21449 \shape italic
21450 ISO C90 does not support flexible array members
21451 \shape default
21452  (187); 
21453 \shape italic
21454 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21455 nam
21456 e]':\InsetSpace ~
21457 [
21458 \begin_inset Note Note
21459 status collapsed
21460
21461 \begin_layout Standard
21462 appears to be always blank - what was supposed to be here?
21463 \end_layout
21464
21465 \end_inset
21466
21467 ]
21468 \shape default
21469  (114); 
21470 \shape italic
21471 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21472  complexity [number]
21473 \shape default
21474  (121).
21475 \end_layout
21476
21477 \begin_layout Itemize
21478
21479 \series bold
21480 disable_warning
21481 \series default
21482  <nnnn>
21483 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21484
21485 \end_inset
21486
21487  - the compiler will not warn you anymore about warning number <nnnn>.
21488 \end_layout
21489
21490 \begin_layout Itemize
21491
21492 \series bold
21493 nogcse
21494 \series default
21495
21496 \begin_inset LatexCommand \index{\#pragma nogcse}
21497
21498 \end_inset
21499
21500  - will stop global common subexpression elimination.
21501 \end_layout
21502
21503 \begin_layout Itemize
21504
21505 \series bold
21506 noinduction
21507 \series default
21508
21509 \begin_inset LatexCommand \index{\#pragma noinduction}
21510
21511 \end_inset
21512
21513  - will stop loop induction optimizations.
21514 \end_layout
21515
21516 \begin_layout Itemize
21517
21518 \series bold
21519 noinvariant
21520 \series default
21521
21522 \begin_inset LatexCommand \index{\#pragma noinvariant}
21523
21524 \end_inset
21525
21526  - will not do loop invariant optimizations.
21527  For more details see Loop Invariants in section
21528 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21529
21530 \end_inset
21531
21532 .
21533 \end_layout
21534
21535 \begin_layout Itemize
21536
21537 \series bold
21538 noiv
21539 \series default
21540
21541 \begin_inset LatexCommand \index{\#pragma noiv}
21542
21543 \end_inset
21544
21545  - Do not generate interrupt
21546 \begin_inset LatexCommand \index{interrupt}
21547
21548 \end_inset
21549
21550  vector table
21551 \begin_inset LatexCommand \index{interrupt vector table}
21552
21553 \end_inset
21554
21555  entries for all ISR functions defined after the pragma.
21556  This is useful in cases where the interrupt vector table must be defined
21557  manually, or when there is a secondary, manually defined interrupt vector
21558  table (e.g.
21559  for the autovector feature of the Cypress EZ-USB FX2).
21560  More elegantly this can be achieved by obmitting the optional interrupt
21561  number after the interrupt keyword, see section 
21562 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21563
21564 \end_inset
21565
21566 \InsetSpace ~
21567 about interrupts.
21568 \end_layout
21569
21570 \begin_layout Itemize
21571
21572 \series bold
21573 nojtbound
21574 \series default
21575
21576 \begin_inset LatexCommand \index{\#pragma nojtbound}
21577
21578 \end_inset
21579
21580  - will not generate code for boundary value checking, when switch statements
21581  are turned into jump-tables (dangerous).
21582  For more details see section 
21583 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21584
21585 \end_inset
21586
21587 .
21588 \end_layout
21589
21590 \begin_layout Itemize
21591
21592 \series bold
21593 noloopreverse
21594 \series default
21595
21596 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21597
21598 \end_inset
21599
21600  - Will not do loop reversal optimization
21601 \end_layout
21602
21603 \begin_layout Itemize
21604
21605 \series bold
21606 nooverlay
21607 \series default
21608
21609 \begin_inset LatexCommand \index{\#pragma nooverlay}
21610
21611 \end_inset
21612
21613  - the compiler will not overlay the parameters and local variables of a
21614  function.
21615 \end_layout
21616
21617 \begin_layout Itemize
21618
21619 \series bold
21620 stackauto
21621 \series default
21622
21623 \begin_inset LatexCommand \index{\#pragma stackauto}
21624
21625 \end_inset
21626
21627 - See option -
21628 \begin_inset ERT
21629 status collapsed
21630
21631 \begin_layout Standard
21632
21633
21634 \backslash
21635 /
21636 \end_layout
21637
21638 \end_inset
21639
21640 -stack-auto
21641 \begin_inset LatexCommand \index{-\/-stack-auto}
21642
21643 \end_inset
21644
21645  and section 
21646 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
21647
21648 \end_inset
21649
21650  Parameters and Local Variables.
21651 \end_layout
21652
21653 \begin_layout Itemize
21654
21655 \series bold
21656 opt_code_speed
21657 \series default
21658  
21659 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
21660
21661 \end_inset
21662
21663 - The compiler will optimize code generation towards fast code, possibly
21664  at the expense of code size.
21665  Currently this has little effect.
21666 \end_layout
21667
21668 \begin_layout Itemize
21669
21670 \series bold
21671 opt_code_size
21672 \series default
21673  
21674 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
21675
21676 \end_inset
21677
21678 - The compiler will optimize code generation towards compact code, possibly
21679  at the expense of code speed.
21680  Currently this has little effect.
21681 \end_layout
21682
21683 \begin_layout Itemize
21684
21685 \series bold
21686 opt_code_balanced
21687 \series default
21688  
21689 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
21690
21691 \end_inset
21692
21693 - The compiler will attempt to generate code that is both compact and fast,
21694  as long as meeting one goal is not a detriment to the other (this is the
21695  default).
21696  
21697 \end_layout
21698
21699 \begin_layout Itemize
21700
21701 \series bold
21702 std_sdcc89
21703 \series default
21704  
21705 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
21706
21707 \end_inset
21708
21709 - Generally follow the C89 standard, but allow SDCC features that conflict
21710  with the standard (default).
21711 \end_layout
21712
21713 \begin_layout Itemize
21714
21715 \series bold
21716 std_c89
21717 \series default
21718  
21719 \begin_inset LatexCommand \index{\#pragma std\_c89}
21720
21721 \end_inset
21722
21723 - Follow the C89 standard and disable SDCC features that conflict with the
21724  standard.
21725 \end_layout
21726
21727 \begin_layout Itemize
21728
21729 \series bold
21730 std_sdcc99
21731 \series default
21732  
21733 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
21734
21735 \end_inset
21736
21737 - Generally follow the C99 standard, but allow SDCC features that conflict
21738  with the standard (incomplete support).
21739 \end_layout
21740
21741 \begin_layout Itemize
21742
21743 \series bold
21744 std_c99
21745 \series default
21746  
21747 \begin_inset LatexCommand \index{\#pragma std\_c99}
21748
21749 \end_inset
21750
21751 - Follow the C99 standard and disable SDCC features that conflict with the
21752  standard (incomplete support).
21753 \end_layout
21754
21755 \begin_layout Itemize
21756
21757 \series bold
21758 codeseg
21759 \series default
21760  <name>
21761 \begin_inset LatexCommand \index{\#pragma codeseg}
21762
21763 \end_inset
21764
21765 - Use this name (max.
21766  8 characters) for the code segment.
21767  See option -
21768 \begin_inset ERT
21769 status collapsed
21770
21771 \begin_layout Standard
21772
21773
21774 \backslash
21775 /
21776 \end_layout
21777
21778 \end_inset
21779
21780 -codeseg.
21781 \end_layout
21782
21783 \begin_layout Itemize
21784
21785 \series bold
21786 constseg
21787 \series default
21788  <name>
21789 \begin_inset LatexCommand \index{\#pragma constseg}
21790
21791 \end_inset
21792
21793 - Use this name (max.
21794  8 characters) for the const segment.
21795  See option -
21796 \begin_inset ERT
21797 status collapsed
21798
21799 \begin_layout Standard
21800
21801
21802 \backslash
21803 /
21804 \end_layout
21805
21806 \end_inset
21807
21808 -constseg.
21809 \end_layout
21810
21811 \begin_layout Standard
21812 The preprocessor SDCPP
21813 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
21814
21815 \end_inset
21816
21817  supports the following #pragma directives:
21818 \end_layout
21819
21820 \begin_layout Itemize
21821
21822 \series bold
21823 pedantic_parse_number
21824 \series default
21825
21826 \begin_inset LatexCommand \index{pedantic}
21827
21828 \end_inset
21829
21830
21831 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21832
21833 \end_inset
21834
21835  (+ | -) 
21836 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
21837
21838 \end_inset
21839
21840 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
21841  properly and the macro LO_B(3) gets expanded.
21842  Default is off.
21843  See also the -
21844 \begin_inset ERT
21845 status collapsed
21846
21847 \begin_layout Standard
21848
21849
21850 \backslash
21851 /
21852 \end_layout
21853
21854 \end_inset
21855
21856 -pedantic-parse-number command line option 
21857 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
21858
21859 \end_inset
21860
21861 .
21862  
21863 \newline
21864 Below is an example on how to use this pragma.
21865
21866 \emph on
21867  Note: this functionality is not in conformance with standard!
21868 \end_layout
21869
21870 \begin_layout Verse
21871
21872 \family typewriter
21873 #pragma pedantic_parse_number +
21874 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21875
21876 \end_inset
21877
21878
21879 \newline
21880
21881 \newline
21882 #define LO_B(x) ((x) & 0xff)
21883 \newline
21884
21885 \newline
21886 unsigned char foo(void)
21887 \newline
21888 {
21889 \newline
21890 \InsetSpace ~
21891 \InsetSpace ~
21892 \InsetSpace ~
21893 unsigned char c=0xfe-LO_B(3)
21894 ;
21895 \newline
21896
21897 \newline
21898 \InsetSpace ~
21899 \InsetSpace ~
21900 \InsetSpace ~
21901 return c;
21902 \newline
21903 }
21904 \newline
21905
21906 \end_layout
21907
21908 \begin_layout Itemize
21909
21910 \series bold
21911 preproc_asm
21912 \series default
21913
21914 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21915
21916 \end_inset
21917
21918  (+ | -) - switch _asm _endasm block preprocessing on / off.
21919  Default is on.
21920  You use this prama to define multilines of assembly code.
21921  This will prevent the preprocessor from changing the formating required
21922  by assembly code.
21923  Below is an example on how to use this pragma.
21924 \end_layout
21925
21926 \begin_layout Verse
21927
21928 \family typewriter
21929 #pragma preproc_asm -
21930 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21931
21932 \end_inset
21933
21934
21935 \newline
21936 #define MYDELAY _asm
21937 \newline
21938 \InsetSpace ~
21939 \InsetSpace ~
21940 \InsetSpace ~
21941 nop ;my assembly comment...
21942 \newline
21943 \InsetSpace ~
21944 \InsetSpace ~
21945 \InsetSpace ~
21946 nop
21947 \newline
21948 \InsetSpace ~
21949 \InsetSpace ~
21950 \InsetSpace ~
21951 nop
21952 \newline
21953 _endasm
21954 \newline
21955 #pragma preproc_asm
21956  +
21957 \newline
21958
21959 \newline
21960 void foo (void) 
21961 \newline
21962
21963 \newline
21964 \InsetSpace ~
21965 \InsetSpace ~
21966 \InsetSpace ~
21967  ...
21968  
21969 \newline
21970 \InsetSpace ~
21971 \InsetSpace ~
21972 \InsetSpace ~
21973  MYDELAY;
21974 \newline
21975 \InsetSpace ~
21976 \InsetSpace ~
21977 \InsetSpace ~
21978  ...
21979  
21980 \newline
21981
21982 \newline
21983
21984 \end_layout
21985
21986 \begin_layout Itemize
21987
21988 \series bold
21989 sdcc_hash
21990 \series default
21991
21992 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21993
21994 \end_inset
21995
21996  (+ | -) - Allow "naked" hash in macro definition, for example:
21997 \newline
21998
21999 \family typewriter
22000 #define DIR_LO(x) #(x & 0xff)
22001 \family default
22002
22003 \newline
22004 Default is off.
22005  Below is an example on how to use this pragma.
22006 \end_layout
22007
22008 \begin_layout Verse
22009
22010 \family typewriter
22011 #pragma preproc_asm +
22012 \newline
22013 #pragma sdcc_hash +
22014 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
22015
22016 \end_inset
22017
22018
22019 \newline
22020
22021 \newline
22022 #define ROMCALL(x) 
22023 \backslash
22024
22025 \newline
22026 \InsetSpace ~
22027 \InsetSpace ~
22028 \InsetSpace ~
22029 mov R6_B3, #(x & 0xff) 
22030 \backslash
22031
22032 \newline
22033 \InsetSpace ~
22034 \InsetSpace ~
22035 \InsetSpace ~
22036 mov R7_B3, #((x >> 8) & 0xff) 
22037 \backslash
22038
22039 \newline
22040 \InsetSpace ~
22041 \InsetSpace ~
22042 \InsetSpace ~
22043 lcall __romcall
22044 \newline
22045
22046 \newline
22047 ...
22048 \newline
22049 _asm
22050 \newline
22051 ROMCALL(72)
22052 \newline
22053 _endasm;
22054 \newline
22055 ...
22056 \newline
22057
22058 \end_layout
22059
22060 \begin_layout Standard
22061 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22062 ons which might cause the compiler to generate extra stack and/or data space
22063  to store compiler generated temporary variables.
22064  This usually happens in large functions.
22065  Pragma directives should be used as shown in the following example, they
22066  are used to control options and optimizations for a given function.
22067  
22068 \end_layout
22069
22070 \begin_layout Verse
22071
22072 \family typewriter
22073 #pragma save
22074 \begin_inset LatexCommand \index{\#pragma save}
22075
22076 \end_inset
22077
22078  \InsetSpace ~
22079 \InsetSpace ~
22080 \InsetSpace ~
22081 \InsetSpace ~
22082 \InsetSpace ~
22083 \InsetSpace ~
22084 \InsetSpace ~
22085 /* save the current settings */ 
22086 \newline
22087 #pragma nogcse
22088 \begin_inset LatexCommand \index{\#pragma nogcse}
22089
22090 \end_inset
22091
22092  \InsetSpace ~
22093 \InsetSpace ~
22094 \InsetSpace ~
22095 \InsetSpace ~
22096 \InsetSpace ~
22097 /* turnoff global subexpression elimination */ 
22098 \newline
22099 #pragma noinduction
22100 \begin_inset LatexCommand \index{\#pragma noinduction}
22101
22102 \end_inset
22103
22104  /* turn off induction optimizations */ 
22105 \newline
22106 int foo () 
22107 \newline
22108
22109 \newline
22110 \InsetSpace ~
22111  \InsetSpace ~
22112  ...
22113  
22114 \newline
22115 \InsetSpace ~
22116  \InsetSpace ~
22117  /* large code */ 
22118 \newline
22119 \InsetSpace ~
22120  \InsetSpace ~
22121  ...
22122  
22123 \newline
22124
22125 \newline
22126 #pragma restore
22127 \begin_inset LatexCommand \index{\#pragma restore}
22128
22129 \end_inset
22130
22131  /* turn the optimizations back on */
22132 \end_layout
22133
22134 \begin_layout Standard
22135 The compiler will generate a warning message when extra space is allocated.
22136  It is strongly recommended that the save and restore pragma's be used when
22137  changing options for a function.
22138 \newline
22139
22140 \newline
22141
22142 \newline
22143
22144 \end_layout
22145
22146 \begin_layout Section
22147 Defines Created by the Compiler
22148 \end_layout
22149
22150 \begin_layout Standard
22151 The compiler creates the following #defines
22152 \begin_inset LatexCommand \index{\#defines}
22153
22154 \end_inset
22155
22156
22157 \begin_inset LatexCommand \index{Defines created by the compiler}
22158
22159 \end_inset
22160
22161 :
22162 \newline
22163
22164 \end_layout
22165
22166 \begin_layout Standard
22167 \begin_inset Tabular
22168 <lyxtabular version="3" rows="11" columns="2">
22169 <features>
22170 <column alignment="left" valignment="top" leftline="true" width="3in">
22171 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22172 <row topline="true" bottomline="true">
22173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22174 \begin_inset Text
22175
22176 \begin_layout Standard
22177
22178 \series bold
22179 #define
22180 \end_layout
22181
22182 \end_inset
22183 </cell>
22184 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22185 \begin_inset Text
22186
22187 \begin_layout Standard
22188
22189 \series bold
22190 Description
22191 \end_layout
22192
22193 \end_inset
22194 </cell>
22195 </row>
22196 <row topline="true">
22197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22198 \begin_inset Text
22199
22200 \begin_layout Standard
22201 SDCC
22202 \begin_inset LatexCommand \index{SDCC}
22203
22204 \end_inset
22205
22206  
22207 \end_layout
22208
22209 \end_inset
22210 </cell>
22211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22212 \begin_inset Text
22213
22214 \begin_layout Standard
22215 Always defined.
22216  Since version 2.5.6 the version number as an int (ex.
22217  256)
22218 \end_layout
22219
22220 \end_inset
22221 </cell>
22222 </row>
22223 <row topline="true">
22224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22225 \begin_inset Text
22226
22227 \begin_layout Standard
22228 SDCC_mcs51
22229 \begin_inset LatexCommand \index{SDCC\_mcs51}
22230
22231 \end_inset
22232
22233  or SDCC_ds390
22234 \begin_inset LatexCommand \index{SDCC\_ds390}
22235
22236 \end_inset
22237
22238  or SDCC_z80
22239 \begin_inset LatexCommand \index{SDCC\_z80}
22240
22241 \end_inset
22242
22243 , etc.
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 depending on the model used (e.g.: -mds390)
22253 \end_layout
22254
22255 \end_inset
22256 </cell>
22257 </row>
22258 <row topline="true">
22259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22260 \begin_inset Text
22261
22262 \begin_layout Standard
22263 __mcs51
22264 \begin_inset LatexCommand \index{\_\_mcs51}
22265
22266 \end_inset
22267
22268 , __ds390
22269 \begin_inset LatexCommand \index{\_\_ds390}
22270
22271 \end_inset
22272
22273 , __hc08
22274 \begin_inset LatexCommand \index{\_\_hc08}
22275
22276 \end_inset
22277
22278 , __z80
22279 \begin_inset LatexCommand \index{\_\_z80}
22280
22281 \end_inset
22282
22283 , etc
22284 \end_layout
22285
22286 \end_inset
22287 </cell>
22288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22289 \begin_inset Text
22290
22291 \begin_layout Standard
22292 depending on the model used (e.g.
22293  -mz80)
22294 \end_layout
22295
22296 \end_inset
22297 </cell>
22298 </row>
22299 <row topline="true">
22300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22301 \begin_inset Text
22302
22303 \begin_layout Standard
22304 SDCC_STACK_AUTO
22305 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22306
22307 \end_inset
22308
22309
22310 \end_layout
22311
22312 \end_inset
22313 </cell>
22314 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22315 \begin_inset Text
22316
22317 \begin_layout Standard
22318 when 
22319 \emph on
22320 -
22321 \begin_inset ERT
22322 status collapsed
22323
22324 \begin_layout Standard
22325
22326
22327 \backslash
22328 /
22329 \end_layout
22330
22331 \end_inset
22332
22333 -stack-auto
22334 \emph default
22335  option is used
22336 \end_layout
22337
22338 \end_inset
22339 </cell>
22340 </row>
22341 <row topline="true">
22342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22343 \begin_inset Text
22344
22345 \begin_layout Standard
22346 SDCC_MODEL_SMALL
22347 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22348
22349 \end_inset
22350
22351
22352 \end_layout
22353
22354 \end_inset
22355 </cell>
22356 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22357 \begin_inset Text
22358
22359 \begin_layout Standard
22360 when 
22361 \emph on
22362 -
22363 \begin_inset ERT
22364 status collapsed
22365
22366 \begin_layout Standard
22367
22368
22369 \backslash
22370 /
22371 \end_layout
22372
22373 \end_inset
22374
22375 -model-small
22376 \emph default
22377  is used
22378 \end_layout
22379
22380 \end_inset
22381 </cell>
22382 </row>
22383 <row topline="true">
22384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22385 \begin_inset Text
22386
22387 \begin_layout Standard
22388 SDCC_MODEL_MEDIUM
22389 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22390
22391 \end_inset
22392
22393
22394 \end_layout
22395
22396 \end_inset
22397 </cell>
22398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22399 \begin_inset Text
22400
22401 \begin_layout Standard
22402 when 
22403 \emph on
22404 -
22405 \begin_inset ERT
22406 status collapsed
22407
22408 \begin_layout Standard
22409
22410
22411 \backslash
22412 /
22413 \end_layout
22414
22415 \end_inset
22416
22417 -model-medium
22418 \emph default
22419  is used
22420 \end_layout
22421
22422 \end_inset
22423 </cell>
22424 </row>
22425 <row topline="true">
22426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22427 \begin_inset Text
22428
22429 \begin_layout Standard
22430 SDCC_MODEL_LARGE
22431 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22432
22433 \end_inset
22434
22435
22436 \end_layout
22437
22438 \end_inset
22439 </cell>
22440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22441 \begin_inset Text
22442
22443 \begin_layout Standard
22444 when 
22445 \emph on
22446 -
22447 \begin_inset ERT
22448 status collapsed
22449
22450 \begin_layout Standard
22451
22452
22453 \backslash
22454 /
22455 \end_layout
22456
22457 \end_inset
22458
22459 -model-large
22460 \emph default
22461  is used
22462 \end_layout
22463
22464 \end_inset
22465 </cell>
22466 </row>
22467 <row topline="true">
22468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22469 \begin_inset Text
22470
22471 \begin_layout Standard
22472 SDCC_USE_XSTACK
22473 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22474
22475 \end_inset
22476
22477
22478 \end_layout
22479
22480 \end_inset
22481 </cell>
22482 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22483 \begin_inset Text
22484
22485 \begin_layout Standard
22486 when 
22487 \emph on
22488 -
22489 \begin_inset ERT
22490 status collapsed
22491
22492 \begin_layout Standard
22493
22494
22495 \backslash
22496 /
22497 \end_layout
22498
22499 \end_inset
22500
22501 -xstack
22502 \emph default
22503  option is used
22504 \end_layout
22505
22506 \end_inset
22507 </cell>
22508 </row>
22509 <row topline="true">
22510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22511 \begin_inset Text
22512
22513 \begin_layout Standard
22514 SDCC_STACK_TENBIT
22515 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22516
22517 \end_inset
22518
22519  
22520 \end_layout
22521
22522 \end_inset
22523 </cell>
22524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22525 \begin_inset Text
22526
22527 \begin_layout Standard
22528 when 
22529 \emph on
22530 -mds390
22531 \emph default
22532  is used
22533 \end_layout
22534
22535 \end_inset
22536 </cell>
22537 </row>
22538 <row topline="true" bottomline="true">
22539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22540 \begin_inset Text
22541
22542 \begin_layout Standard
22543 SDCC_MODEL_FLAT24
22544 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22545
22546 \end_inset
22547
22548
22549 \end_layout
22550
22551 \end_inset
22552 </cell>
22553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22554 \begin_inset Text
22555
22556 \begin_layout Standard
22557 when 
22558 \emph on
22559 -mds390
22560 \emph default
22561  is used
22562 \end_layout
22563
22564 \end_inset
22565 </cell>
22566 </row>
22567 </lyxtabular>
22568
22569 \end_inset
22570
22571
22572 \end_layout
22573
22574 \begin_layout Chapter
22575 Notes on supported Processors
22576 \end_layout
22577
22578 \begin_layout Section
22579 MCS51 variants
22580 \begin_inset LatexCommand \label{sub:MCS51-variants}
22581
22582 \end_inset
22583
22584
22585 \begin_inset LatexCommand \index{MCS51 variants}
22586
22587 \end_inset
22588
22589
22590 \end_layout
22591
22592 \begin_layout Standard
22593 MCS51 processors are available from many vendors and come in many different
22594  flavours.
22595  While they might differ considerably in respect to Special Function Registers
22596  the core MCS51 is usually not modified or is kept compatible.
22597  
22598 \end_layout
22599
22600 \begin_layout Subsection
22601 pdata access by SFR 
22602 \end_layout
22603
22604 \begin_layout Standard
22605 With the upcome of devices with internal xdata and flash memory devices
22606  using port P2
22607 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22608
22609 \end_inset
22610
22611  as dedicated I/O port is becoming more popular.
22612  Switching the high byte for pdata
22613 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22614
22615 \end_inset
22616
22617  access which was formerly done by port P2 is then achieved by a Special
22618  Function Register
22619 \begin_inset LatexCommand \index{sfr}
22620
22621 \end_inset
22622
22623 .
22624  In well-established MCS51 tradition the address of this 
22625 \emph on
22626 sfr
22627 \emph default
22628  is where the chip designers decided to put it.
22629  Needless to say that they didn't agree on a common name either.
22630  So that the startup code can correctly initialize xdata variables, you
22631  should define an sfr with the name _XPAGE
22632 \family typewriter
22633
22634 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
22635
22636 \end_inset
22637
22638
22639 \family default
22640  at the appropriate location if the default, port P2, is not used for this.
22641  Some examples are:
22642 \end_layout
22643
22644 \begin_layout Verse
22645
22646 \family typewriter
22647 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
22648  MPAGE */
22649 \end_layout
22650
22651 \begin_layout Verse
22652
22653 \family typewriter
22654 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
22655  a.k.a.
22656  MPAGE */
22657 \end_layout
22658
22659 \begin_layout Verse
22660
22661 \family typewriter
22662 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
22663  XPAGE */
22664 \end_layout
22665
22666 \begin_layout Verse
22667
22668 \family typewriter
22669 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22670  EMI0CN */
22671 \end_layout
22672
22673 \begin_layout Verse
22674
22675 \family typewriter
22676 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22677  EMI0CN */
22678 \end_layout
22679
22680 \begin_layout Standard
22681 For more exotic implementations further customizations may be needed.
22682  See section 
22683 \begin_inset LatexCommand \ref{sub:Startup-Code}
22684
22685 \end_inset
22686
22687  for other possibilities.
22688 \end_layout
22689
22690 \begin_layout Subsection
22691 Other Features available by SFR
22692 \end_layout
22693
22694 \begin_layout Standard
22695 Some MCS51 variants offer features like Double DPTR
22696 \begin_inset LatexCommand \index{DPTR}
22697
22698 \end_inset
22699
22700 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
22701  These are currently not used for the MCS51 port.
22702  If you absolutely need them you can fall back to inline assembly or submit
22703  a patch to SDCC.
22704 \begin_inset VSpace bigskip
22705 \end_inset
22706
22707
22708 \end_layout
22709
22710 \begin_layout Section
22711 DS400 port
22712 \end_layout
22713
22714 \begin_layout Standard
22715 The DS80C400
22716 \begin_inset LatexCommand \index{DS80C400}
22717
22718 \end_inset
22719
22720
22721 \begin_inset LatexCommand \index{DS400}
22722
22723 \end_inset
22724
22725  microcontroller has a rich set of peripherals.
22726  In its built-in ROM library it includes functions to access some of the
22727  features, among them is a TCP stack with IP4 and IP6 support.
22728  Library headers (currently in beta status) and other files are provided
22729  at 
22730 \size footnotesize
22731
22732 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
22733
22734 \end_inset
22735
22736 .
22737  
22738 \begin_inset VSpace bigskip
22739 \end_inset
22740
22741
22742 \end_layout
22743
22744 \begin_layout Section
22745 The Z80 and gbz80 port
22746 \end_layout
22747
22748 \begin_layout Standard
22749 SDCC can target both the Zilog Z80
22750 \begin_inset LatexCommand \index{Z80}
22751
22752 \end_inset
22753
22754  and the Nintendo Gameboy's Z80-like gbz80
22755 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
22756
22757 \end_inset
22758
22759 .
22760  The Z80 port is passed through the same 
22761 \emph on
22762 regressions tests
22763 \begin_inset LatexCommand \index{Regression test}
22764
22765 \end_inset
22766
22767
22768 \emph default
22769  (see section 
22770 \begin_inset LatexCommand \ref{sec:Quality-control}
22771
22772 \end_inset
22773
22774 ) as the MCS51 and DS390 ports, so floating point support, support for long
22775  variables and bitfield support is fine.
22776  See mailing lists and forums about interrupt routines.
22777 \end_layout
22778
22779 \begin_layout Standard
22780 As always, the code is the authoritative reference - see z80/ralloc.c and
22781  z80/gen.c.
22782  The stack
22783 \begin_inset LatexCommand \index{Z80!stack}
22784
22785 \end_inset
22786
22787  frame is similar to that generated by the IAR Z80 compiler.
22788  IX is used as the base pointer, HL and IY are used as a temporary registers,
22789  and BC and DE are available for holding variables.
22790  Return values
22791 \begin_inset LatexCommand \index{Z80!return value}
22792
22793 \end_inset
22794
22795  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
22796  bytes).
22797  The gbz80 port use the same set of registers for the return values, but
22798  in a different order of significance: E (one byte), DE (two bytes), or
22799  HLDE (four bytes).
22800 \begin_inset VSpace bigskip
22801 \end_inset
22802
22803
22804 \end_layout
22805
22806 \begin_layout Section
22807 The HC08 port
22808 \end_layout
22809
22810 \begin_layout Standard
22811 The port to the Freescale/Motorola HC08
22812 \begin_inset LatexCommand \index{HC08}
22813
22814 \end_inset
22815
22816  family has been added in October 2003, and is still undergoing some basic
22817  development.
22818  The code generator is complete, but the register allocation is still quite
22819  unoptimized.
22820  Some of the SDCC's standard C library functions have embedded non-HC08
22821  inline assembly and so are not yet usable.
22822 \end_layout
22823
22824 \begin_layout Standard
22825 The HC08 port passes the regression test suite (see section 
22826 \begin_inset LatexCommand \ref{sec:Quality-control}
22827
22828 \end_inset
22829
22830 ).
22831 \begin_inset VSpace bigskip
22832 \end_inset
22833
22834
22835 \newpage
22836
22837 \end_layout
22838
22839 \begin_layout Section
22840 The PIC14 port
22841 \end_layout
22842
22843 \begin_layout Standard
22844 The PIC14 port adds support for Microchip(TM)'s 14
22845 \begin_inset ERT
22846 status open
22847
22848 \begin_layout Standard
22849
22850
22851 \backslash
22852 ,
22853 \end_layout
22854
22855 \end_inset
22856
22857 bit PIC
22858 \begin_inset LatexCommand \index{PIC14}
22859
22860 \end_inset
22861
22862  MCUs.
22863  This port is not yet mature and still lacks many features.
22864  However, it can work for simple code.
22865 \end_layout
22866
22867 \begin_layout Standard
22868 Currently supported devices include:
22869 \end_layout
22870
22871 \begin_layout Standard
22872 12F: 629, 635, 675, 683
22873 \end_layout
22874
22875 \begin_layout Standard
22876 16C: 432, 433
22877 \end_layout
22878
22879 \begin_layout Standard
22880 16C: 554, 557, 558
22881 \end_layout
22882
22883 \begin_layout Standard
22884 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
22885 \end_layout
22886
22887 \begin_layout Standard
22888 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
22889  781, 782
22890 \end_layout
22891
22892 \begin_layout Standard
22893 16C: 925, 926
22894 \end_layout
22895
22896 \begin_layout Standard
22897 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
22898  689, 690
22899 \end_layout
22900
22901 \begin_layout Standard
22902 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
22903 \end_layout
22904
22905 \begin_layout Standard
22906 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
22907  877, 877a, 88
22908 \end_layout
22909
22910 \begin_layout Standard
22911 16F: 913, 914, 916, 917
22912 \end_layout
22913
22914 \begin_layout Standard
22915 An up-to-date list of currently supported devices can be obtained via 
22916 \family typewriter
22917 sdcc -mpic14 -phelp foo.c
22918 \family default
22919  (foo.c must exist...).
22920 \end_layout
22921
22922 \begin_layout Subsection
22923 PIC Code Pages
22924 \begin_inset LatexCommand \index{code page (pic14)}
22925
22926 \end_inset
22927
22928  and Memory Banks
22929 \begin_inset LatexCommand \index{Memory bank (pic14)}
22930
22931 \end_inset
22932
22933
22934 \end_layout
22935
22936 \begin_layout Standard
22937 The linker organizes allocation for the code page and RAM banks.
22938  It does not have intimate knowledge of the code flow.
22939  It will put all the code section of a single .asm file into a single code
22940  page.
22941  In order to make use of multiple code pages, separate asm files must be
22942  used.
22943  The compiler assigns all 
22944 \emph on
22945 static
22946 \emph default
22947  functions of a single .c file into the same code page.
22948 \newline
22949
22950 \newline
22951 To get the best results,
22952  follow these guidelines:
22953 \end_layout
22954
22955 \begin_layout Enumerate
22956 Make local functions static, as non static functions require code page selection
22957  overhead.
22958 \newline
22959 Due to the way sdcc handles functions, place called functions prior
22960  to calling functions in the file wherever possible: Otherwise sdcc will
22961  insert unneccessary pagesel directives around the call, believing that
22962  the called function is externally defined.
22963 \end_layout
22964
22965 \begin_layout Enumerate
22966 For devices that have multiple code pages it is more efficient to use the
22967  same number of files as pages: Use up to 4 separate .c files for the 16F877,
22968  but only 2 files for the 16F874.
22969  This way the linker can put the code for each file into different code
22970  pages and there will be less page selection overhead.
22971 \end_layout
22972
22973 \begin_layout Enumerate
22974 And as for any 8 bit micro (especially for PIC14 as they have a very simple
22975  instruction set), use 'unsigned char' wherever possible instead of 'int'.
22976 \end_layout
22977
22978 \begin_layout Subsection
22979 Adding New Devices to the Port 
22980 \end_layout
22981
22982 \begin_layout Standard
22983 Adding support for a new 14
22984 \begin_inset ERT
22985 status open
22986
22987 \begin_layout Standard
22988
22989
22990 \backslash
22991 ,
22992 \end_layout
22993
22994 \end_inset
22995
22996 bit PIC MCU requires the following steps:
22997 \end_layout
22998
22999 \begin_layout Enumerate
23000 Create a new device description.
23001 \newline
23002 Each device is described in two files: pic16f*.h
23003  and pic16f*.c.
23004  These files primarily define SFRs, structs to access their bits, and symbolic
23005  configuration options.
23006  Both files can be generated from gputils' .inc files using the perl script
23007  
23008 \family typewriter
23009 support/scripts/inc2h.pl
23010 \family default
23011 .
23012  This file also contains further instructions on how to proceed.
23013 \end_layout
23014
23015 \begin_layout Enumerate
23016 Copy the .h file into SDCC's include path and either add the .c file to your
23017  project or copy it to 
23018 \family typewriter
23019 device/lib/pic/libdev
23020 \family default
23021 .
23022  Afterwards, rebuild and install the libraries.
23023 \end_layout
23024
23025 \begin_layout Enumerate
23026 Edit pic14devices.txt in SDCC's include path (
23027 \family typewriter
23028 device/include/pic/
23029 \family default
23030  in the source tree or 
23031 \family typewriter
23032 /usr/local/share/sdcc/include/pic
23033 \family default
23034  after installation).
23035 \newline
23036 You need to add a device specification here to make
23037  the memory layout (code banks, RAM, aliased memory regions, ...) known to
23038  the compiler.
23039  Probably you can copy and modify an existing entry.
23040  The file format is documented at the top of the file.
23041 \end_layout
23042
23043 \begin_layout Subsection
23044 Interrupt Code
23045 \end_layout
23046
23047 \begin_layout Standard
23048 For the interrupt function, use the keyword '__interrupt'
23049 \begin_inset LatexCommand \index{PIC14!interrupt}
23050
23051 \end_inset
23052
23053  with level number of 0 (PIC14 only has 1 interrupt so this number is only
23054  there to avoid a syntax error - it ought to be fixed).
23055  E.g.:
23056 \end_layout
23057
23058 \begin_layout Verse
23059
23060 \family typewriter
23061 void Intr(void) __interrupt 0
23062 \newline
23063 {
23064 \newline
23065 \InsetSpace ~
23066 \InsetSpace ~
23067 T0IF = 0; /* Clear timer interrupt */
23068 \newline
23069 }
23070 \end_layout
23071
23072 \begin_layout Subsection
23073 Linking and Assembling
23074 \end_layout
23075
23076 \begin_layout Standard
23077 For assembling you can use either GPUTILS'
23078 \begin_inset LatexCommand \index{gputils (pic tools)}
23079
23080 \end_inset
23081
23082  gpasm.exe or MPLAB's mpasmwin.exe.
23083  GPUTILS are available from 
23084 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23085
23086 \end_inset
23087
23088 .
23089  For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
23090  If you use MPLAB and an interrupt function then the linker script file
23091  vectors section will need to be enlarged to link with mplink.
23092 \newline
23093
23094 \newline
23095 Here is a 
23096 \family typewriter
23097 Makefile
23098 \family default
23099  using GPUTILS:
23100 \end_layout
23101
23102 \begin_layout Verse
23103
23104 \family typewriter
23105 .c.o:
23106 \newline
23107 \InsetSpace ~
23108 \InsetSpace ~
23109 \InsetSpace ~
23110 \InsetSpace ~
23111 \InsetSpace ~
23112 \InsetSpace ~
23113 \InsetSpace ~
23114 \InsetSpace ~
23115 sdcc -V -mpic14 -p16f877 -c $< 
23116 \newline
23117
23118 \newline
23119 $(PRJ).hex: $(OBJS) 
23120 \newline
23121 \InsetSpace ~
23122 \InsetSpace ~
23123 \InsetSpace ~
23124 \InsetSpace ~
23125 \InsetSpace ~
23126 \InsetSpace ~
23127 \InsetSpace ~
23128 \InsetSpace ~
23129 gplink -m -s $(PRJ).lkr
23130  -o $(PRJ).hex $(OBJS) libsdcc.lib
23131 \end_layout
23132
23133 \begin_layout Standard
23134 Here is a 
23135 \family typewriter
23136 Makefile
23137 \family default
23138  using MPLAB:
23139 \end_layout
23140
23141 \begin_layout Verse
23142
23143 \family typewriter
23144 .c.o: 
23145 \newline
23146 \InsetSpace ~
23147 \InsetSpace ~
23148 \InsetSpace ~
23149 \InsetSpace ~
23150 \InsetSpace ~
23151 \InsetSpace ~
23152 \InsetSpace ~
23153 \InsetSpace ~
23154 sdcc -S -V -mpic14 -p16f877 $< 
23155 \newline
23156 \InsetSpace ~
23157 \InsetSpace ~
23158 \InsetSpace ~
23159 \InsetSpace ~
23160 \InsetSpace ~
23161 \InsetSpace ~
23162 \InsetSpace ~
23163 \InsetSpace ~
23164 mpasmwin /q /o $*.asm
23165 \newline
23166
23167 \newline
23168 $(PRJ).hex: $(OBJS)
23169  
23170 \newline
23171 \InsetSpace ~
23172 \InsetSpace ~
23173 \InsetSpace ~
23174 \InsetSpace ~
23175 \InsetSpace ~
23176 \InsetSpace ~
23177 \InsetSpace ~
23178 \InsetSpace ~
23179 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
23180 \end_layout
23181
23182 \begin_layout Standard
23183 Please note that indentations within a
23184 \family typewriter
23185  Makefile
23186 \family default
23187  have to be done with a tabulator character.
23188 \end_layout
23189
23190 \begin_layout Subsection
23191 Command-Line Options
23192 \end_layout
23193
23194 \begin_layout Standard
23195 Besides the switches common to all SDCC backends, the PIC14 port accepts
23196  the following options (for an updated list see sdcc -
23197 \begin_inset ERT
23198 status collapsed
23199
23200 \begin_layout Standard
23201
23202
23203 \backslash
23204 /
23205 \end_layout
23206
23207 \end_inset
23208
23209 -help):
23210 \end_layout
23211
23212 \begin_layout Description
23213 -
23214 \begin_inset ERT
23215 status collapsed
23216
23217 \begin_layout Standard
23218
23219
23220 \backslash
23221 /
23222 \end_layout
23223
23224 \end_inset
23225
23226 -debug-xtra
23227 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
23228
23229 \end_inset
23230
23231  emit debug info in assembly output
23232 \end_layout
23233
23234 \begin_layout Description
23235 -
23236 \begin_inset ERT
23237 status collapsed
23238
23239 \begin_layout Standard
23240
23241
23242 \backslash
23243 /
23244 \end_layout
23245
23246 \end_inset
23247
23248 -no-pcode-opt
23249 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
23250
23251 \end_inset
23252
23253  disable (slightly faulty) optimization on pCode
23254 \end_layout
23255
23256 \begin_layout Description
23257 -
23258 \begin_inset ERT
23259 status collapsed
23260
23261 \begin_layout Standard
23262
23263
23264 \backslash
23265 /
23266 \end_layout
23267
23268 \end_inset
23269
23270 -stack-loc
23271 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
23272
23273 \end_inset
23274
23275  sets the lowest address of the argument passing stack (defaults to a suitably
23276  large shared databank to reduce BANKSEL overhead)
23277 \end_layout
23278
23279 \begin_layout Description
23280 -
23281 \begin_inset ERT
23282 status collapsed
23283
23284 \begin_layout Standard
23285
23286
23287 \backslash
23288 /
23289 \end_layout
23290
23291 \end_inset
23292
23293 -stack-size
23294 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
23295
23296 \end_inset
23297
23298  sets the size if the argument passing stack (default: 16, minimum: 4)
23299 \end_layout
23300
23301 \begin_layout Subsection
23302 Environment Variables
23303 \end_layout
23304
23305 \begin_layout Standard
23306 The PIC14 port recognizes the following environment variables:
23307 \end_layout
23308
23309 \begin_layout Description
23310 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
23311  register (the ones called r0xNNNN) in a section of its own.
23312  By default (if this variable is unset), sdcc tries to cluster registers
23313  in sections in order to reduce the BANKSEL overhead when accessing them.
23314 \end_layout
23315
23316 \begin_layout Subsection
23317 The Library
23318 \end_layout
23319
23320 \begin_layout Standard
23321 The PIC14 library currently only contains support routines required by the
23322  compiler to implement multiplication, division, and floating point support.
23323  No libc-like replacement is available at the moment, though many of the
23324  common sdcc library sources (in 
23325 \family typewriter
23326 device/lib
23327 \family default
23328 ) should also compile with the PIC14 port.
23329 \end_layout
23330
23331 \begin_layout Subsubsection
23332 error: missing definition for symbol 
23333 \begin_inset Quotes sld
23334 \end_inset
23335
23336 __gptrget1
23337 \begin_inset Quotes srd
23338 \end_inset
23339
23340
23341 \end_layout
23342
23343 \begin_layout Standard
23344 The PIC14 port uses library routines to provide more complex operations
23345  like multiplication, division/modulus and (generic) pointer dereferencing.
23346  In order to add these routines to your project, you must link with PIC14's
23347  
23348 \family typewriter
23349 libsdcc.lib
23350 \family default
23351 .
23352  For single source file projects this is done automatically, more complex
23353  projects must add 
23354 \family typewriter
23355 libsdcc.lib
23356 \family default
23357  to the linker's arguments.
23358  Make sure you also add an include path for the library (using the -I switch
23359  to the linker)!
23360 \end_layout
23361
23362 \begin_layout Subsubsection
23363 Processor mismatch in file 
23364 \begin_inset Quotes sld
23365 \end_inset
23366
23367 XXX
23368 \begin_inset Quotes srd
23369 \end_inset
23370
23371 .
23372 \end_layout
23373
23374 \begin_layout Standard
23375 This warning can usually be ignored due to the very good compatibility amongst
23376  14
23377 \begin_inset ERT
23378 status open
23379
23380 \begin_layout Standard
23381
23382
23383 \backslash
23384 ,
23385 \end_layout
23386
23387 \end_inset
23388
23389 bit PIC
23390 \begin_inset LatexCommand \index{PIC14}
23391
23392 \end_inset
23393
23394  devices.
23395 \end_layout
23396
23397 \begin_layout Standard
23398 You might also consider recompiling the library for your specific device
23399  by changing the ARCH=p16f877 (default target) entry in 
23400 \family typewriter
23401 device/lib/pic/Makefile.in
23402 \family default
23403  and 
23404 \family typewriter
23405 device/lib/pic/Makefile
23406 \family default
23407  to reflect your device.
23408  This might even improve performance for smaller devices as unneccesary
23409  BANKSELs might be removed.
23410 \end_layout
23411
23412 \begin_layout Subsection
23413 Known Bugs
23414 \end_layout
23415
23416 \begin_layout Subsubsection
23417 Function arguments
23418 \end_layout
23419
23420 \begin_layout Standard
23421 Functions with variable argument lists (like printf) are not yet supported.
23422  Similarly, taking the argument of the first argument passed into a function
23423  does not work: It is currently passed in WREG and has no address...
23424 \end_layout
23425
23426 \begin_layout Subsubsection
23427 Regression tests fail
23428 \end_layout
23429
23430 \begin_layout Standard
23431 Though the small subset of regression tests in src/regression passes, SDCC
23432  regression test suite does not, indicating that there are still major bugs
23433  in the port.
23434  However, many smaller projects have successfully used SDCC in the past...
23435 \end_layout
23436
23437 \begin_layout Standard
23438
23439 \size footnotesize
23440
23441 \newpage
23442
23443 \end_layout
23444
23445 \begin_layout Section
23446 The PIC16
23447 \begin_inset LatexCommand \index{PIC16}
23448
23449 \end_inset
23450
23451  port
23452 \end_layout
23453
23454 \begin_layout Standard
23455 The PIC16
23456 \begin_inset LatexCommand \index{PIC16}
23457
23458 \end_inset
23459
23460  port is the portion of SDCC that is responsible to produce code for the
23461  Microchip
23462 \begin_inset LatexCommand \index{Microchip}
23463
23464 \end_inset
23465
23466 (TM) microcontrollers with 16 bit core.
23467  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
23468  Currently supported devices are:
23469 \end_layout
23470
23471 \begin_layout Standard
23472 18F: 242, 248, 252, 258, 442, 448, 452, 458
23473 \end_layout
23474
23475 \begin_layout Standard
23476 18F: 1220, 1320
23477 \end_layout
23478
23479 \begin_layout Standard
23480 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 2525, 2550, 2620
23481 \end_layout
23482
23483 \begin_layout Standard
23484 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 4520, 4525, 4550, 4620
23485 \end_layout
23486
23487 \begin_layout Standard
23488 18F: 6520, 6620, 6680, 6720
23489 \end_layout
23490
23491 \begin_layout Standard
23492 18F: 8520, 8620, 8680, 8720
23493 \end_layout
23494
23495 \begin_layout Subsection
23496 Global Options
23497 \end_layout
23498
23499 \begin_layout Standard
23500 PIC16 port supports the standard command line arguments as supposed, with
23501  the exception of certain cases that will be mentioned in the following
23502  list:
23503 \end_layout
23504
23505 \begin_layout Description
23506 -
23507 \begin_inset ERT
23508 status collapsed
23509
23510 \begin_layout Standard
23511
23512
23513 \backslash
23514 /
23515 \end_layout
23516
23517 \end_inset
23518
23519 -callee-saves
23520 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23521
23522 \end_inset
23523
23524  See -
23525 \begin_inset ERT
23526 status collapsed
23527
23528 \begin_layout Standard
23529
23530
23531 \backslash
23532 /
23533 \end_layout
23534
23535 \end_inset
23536
23537 -all-callee-saves
23538 \end_layout
23539
23540 \begin_layout Description
23541 -
23542 \begin_inset ERT
23543 status collapsed
23544
23545 \begin_layout Standard
23546
23547
23548 \backslash
23549 /
23550 \end_layout
23551
23552 \end_inset
23553
23554 -fommit-frame-pointer
23555 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23556
23557 \end_inset
23558
23559  Frame pointer will be omitted when the function uses no local variables.
23560 \end_layout
23561
23562 \begin_layout Subsection
23563 Port Specific Options
23564 \begin_inset LatexCommand \index{Options PIC16}
23565
23566 \end_inset
23567
23568
23569 \end_layout
23570
23571 \begin_layout Standard
23572 The port specific options appear after the global options in the sdcc -
23573 \begin_inset ERT
23574 status collapsed
23575
23576 \begin_layout Standard
23577
23578
23579 \backslash
23580 /
23581 \end_layout
23582
23583 \end_inset
23584
23585 -help output.
23586 \end_layout
23587
23588 \begin_layout Subsubsection
23589 Code Generation Options
23590 \end_layout
23591
23592 \begin_layout Standard
23593 These options influence the generated assembler code.
23594 \end_layout
23595
23596 \begin_layout Description
23597 -
23598 \begin_inset ERT
23599 status collapsed
23600
23601 \begin_layout Standard
23602
23603
23604 \backslash
23605 /
23606 \end_layout
23607
23608 \end_inset
23609
23610 -pstack-model=[model] Used in conjuction with the command above.
23611  Defines the stack model to be used, valid stack models are:
23612 \end_layout
23613
23614 \begin_deeper
23615 \begin_layout List
23616 \labelwidthstring 00.00.0000
23617
23618 \emph on
23619 small
23620 \emph default
23621  Selects small stack model.
23622  8 bit stack and frame pointers.
23623  Supports 256 bytes stack size.
23624 \end_layout
23625
23626 \begin_layout List
23627 \labelwidthstring 00.00.0000
23628
23629 \emph on
23630 large
23631 \emph default
23632  Selects large stack model.
23633  16 bit stack and frame pointers.
23634  Supports 65536 bytes stack size.
23635 \end_layout
23636
23637 \end_deeper
23638 \begin_layout Description
23639 -
23640 \begin_inset ERT
23641 status collapsed
23642
23643 \begin_layout Standard
23644
23645
23646 \backslash
23647 /
23648 \end_layout
23649
23650 \end_inset
23651
23652 -pno-banksel Do not generate BANKSEL assembler directives.
23653 \end_layout
23654
23655 \begin_layout Description
23656 -
23657 \begin_inset ERT
23658 status collapsed
23659
23660 \begin_layout Standard
23661
23662
23663 \backslash
23664 /
23665 \end_layout
23666
23667 \end_inset
23668
23669 -extended Enable extended instruction set/literal offset addressing mode.
23670  Use with care!
23671 \end_layout
23672
23673 \begin_layout Subsubsection
23674 Optimization Options
23675 \end_layout
23676
23677 \begin_layout Description
23678 -
23679 \begin_inset ERT
23680 status collapsed
23681
23682 \begin_layout Standard
23683
23684
23685 \backslash
23686 /
23687 \end_layout
23688
23689 \end_inset
23690
23691 -obanksel=n Set optimization level for inserting BANKSELs.
23692 \newline
23693
23694 \end_layout
23695
23696 \begin_deeper
23697 \begin_layout List
23698 \labelwidthstring 00.00.0000
23699 0 no optimization
23700 \end_layout
23701
23702 \begin_layout List
23703 \labelwidthstring 00.00.0000
23704 1 checks previous used register and if it is the same then does not emit
23705  BANKSEL, accounts only for labels.
23706 \end_layout
23707
23708 \begin_layout List
23709 \labelwidthstring 00.00.0000
23710 2 tries to check the location of (even different) symbols and removes BANKSELs
23711  if they are in the same bank.
23712  
23713 \newline
23714
23715 \emph on
23716 Important: There might be problems if the linker script has data sections
23717  across bank borders!
23718 \end_layout
23719
23720 \end_deeper
23721 \begin_layout Description
23722 -
23723 \begin_inset ERT
23724 status collapsed
23725
23726 \begin_layout Standard
23727
23728
23729 \backslash
23730 /
23731 \end_layout
23732
23733 \end_inset
23734
23735 -denable-peeps Force the usage of peepholes.
23736  Use with care.
23737 \end_layout
23738
23739 \begin_layout Description
23740 -
23741 \begin_inset ERT
23742 status collapsed
23743
23744 \begin_layout Standard
23745
23746
23747 \backslash
23748 /
23749 \end_layout
23750
23751 \end_inset
23752
23753 -optimize-goto Try to use (conditional) BRA instead of GOTO.
23754 \end_layout
23755
23756 \begin_layout Description
23757 -
23758 \begin_inset ERT
23759 status collapsed
23760
23761 \begin_layout Standard
23762
23763
23764 \backslash
23765 /
23766 \end_layout
23767
23768 \end_inset
23769
23770 -optimize-cmp Try to optimize some compares.
23771 \end_layout
23772
23773 \begin_layout Description
23774 -
23775 \begin_inset ERT
23776 status collapsed
23777
23778 \begin_layout Standard
23779
23780
23781 \backslash
23782 /
23783 \end_layout
23784
23785 \end_inset
23786
23787 -optimize-df Analyze the dataflow of the generated code and improve it.
23788 \end_layout
23789
23790 \begin_layout Subsubsection
23791 Assembling Options
23792 \end_layout
23793
23794 \begin_layout Description
23795 -
23796 \begin_inset ERT
23797 status collapsed
23798
23799 \begin_layout Standard
23800
23801
23802 \backslash
23803 /
23804 \end_layout
23805
23806 \end_inset
23807
23808 -asm= Sets the full path and name of an external assembler to call.
23809 \end_layout
23810
23811 \begin_layout Description
23812 -
23813 \begin_inset ERT
23814 status collapsed
23815
23816 \begin_layout Standard
23817
23818
23819 \backslash
23820 /
23821 \end_layout
23822
23823 \end_inset
23824
23825 -mplab-comp MPLAB
23826 \begin_inset LatexCommand \index{PIC16!MPLAB}
23827
23828 \end_inset
23829
23830  compatibility option.
23831  Currently only suppresses special gpasm directives.
23832 \end_layout
23833
23834 \begin_layout Subsubsection
23835 Linking Options
23836 \end_layout
23837
23838 \begin_layout Description
23839 -
23840 \begin_inset ERT
23841 status collapsed
23842
23843 \begin_layout Standard
23844
23845
23846 \backslash
23847 /
23848 \end_layout
23849
23850 \end_inset
23851
23852 -link= Sets the full path and name of an external linker to call.
23853 \end_layout
23854
23855 \begin_layout Description
23856 -
23857 \begin_inset ERT
23858 status collapsed
23859
23860 \begin_layout Standard
23861
23862
23863 \backslash
23864 /
23865 \end_layout
23866
23867 \end_inset
23868
23869 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
23870  unitialized data variables with [kword].
23871  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
23872 \end_layout
23873
23874 \begin_layout Description
23875 -
23876 \begin_inset ERT
23877 status collapsed
23878
23879 \begin_layout Standard
23880
23881
23882 \backslash
23883 /
23884 \end_layout
23885
23886 \end_inset
23887
23888 -ivt-loc=n Place the interrupt vector table at address 
23889 \emph on
23890 n
23891 \emph default
23892 .
23893  Useful for bootloaders.
23894 \end_layout
23895
23896 \begin_layout Description
23897 -
23898 \begin_inset ERT
23899 status collapsed
23900
23901 \begin_layout Standard
23902
23903
23904 \backslash
23905 /
23906 \end_layout
23907
23908 \end_inset
23909
23910 -nodefaultlibs Do not link default libraries when linking.
23911 \end_layout
23912
23913 \begin_layout Description
23914 -
23915 \begin_inset ERT
23916 status collapsed
23917
23918 \begin_layout Standard
23919
23920
23921 \backslash
23922 /
23923 \end_layout
23924
23925 \end_inset
23926
23927 -use-crt= Use a custom run-time module instead of the defaults.
23928 \end_layout
23929
23930 \begin_layout Description
23931 -
23932 \begin_inset ERT
23933 status collapsed
23934
23935 \begin_layout Standard
23936
23937
23938 \backslash
23939 /
23940 \end_layout
23941
23942 \end_inset
23943
23944 -no-crt Don't link the default run-time modules
23945 \end_layout
23946
23947 \begin_layout Subsubsection
23948 Debugging Options
23949 \end_layout
23950
23951 \begin_layout Standard
23952 Debugging options enable extra debugging information in the output files.
23953 \end_layout
23954
23955 \begin_layout Description
23956 -
23957 \begin_inset ERT
23958 status collapsed
23959
23960 \begin_layout Standard
23961
23962
23963 \backslash
23964 /
23965 \end_layout
23966
23967 \end_inset
23968
23969 -debug-xtra Similar to -
23970 \begin_inset ERT
23971 status collapsed
23972
23973 \begin_layout Standard
23974
23975
23976 \backslash
23977 /
23978 \end_layout
23979
23980 \end_inset
23981
23982 -debug
23983 \begin_inset LatexCommand \index{-\/-debug}
23984
23985 \end_inset
23986
23987 , but dumps more information.
23988 \end_layout
23989
23990 \begin_layout Description
23991 -
23992 \begin_inset ERT
23993 status collapsed
23994
23995 \begin_layout Standard
23996
23997
23998 \backslash
23999 /
24000 \end_layout
24001
24002 \end_inset
24003
24004 -debug-ralloc Force register allocator to dump <source>.d file with debugging
24005  information.
24006  <source> is the name of the file being compiled.
24007 \end_layout
24008
24009 \begin_layout Description
24010 -
24011 \begin_inset ERT
24012 status collapsed
24013
24014 \begin_layout Standard
24015
24016
24017 \backslash
24018 /
24019 \end_layout
24020
24021 \end_inset
24022
24023 -pcode-verbose Enable pcode debugging information in translation.
24024 \end_layout
24025
24026 \begin_layout Description
24027 -
24028 \begin_inset ERT
24029 status collapsed
24030
24031 \begin_layout Standard
24032
24033
24034 \backslash
24035 /
24036 \end_layout
24037
24038 \end_inset
24039
24040 -calltree Dump call tree in .calltree file.
24041 \end_layout
24042
24043 \begin_layout Description
24044 -
24045 \begin_inset ERT
24046 status collapsed
24047
24048 \begin_layout Standard
24049
24050
24051 \backslash
24052 /
24053 \end_layout
24054
24055 \end_inset
24056
24057 -gstack Trace push/pops for stack pointer overflow.
24058 \end_layout
24059
24060 \begin_layout Subsection
24061 Enviroment Variables
24062 \end_layout
24063
24064 \begin_layout Standard
24065 There is a number of enviromental variables that can be used when running
24066  SDCC to enable certain optimizations or force a specific program behaviour.
24067  these variables are primarily for debugging purposes so they can be enabled/dis
24068 abled at will.
24069 \end_layout
24070
24071 \begin_layout Standard
24072 Currently there is only two such variables available:
24073 \end_layout
24074
24075 \begin_layout Description
24076 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
24077  bitfields is optimized by directly loading FSR0 with the address of the
24078  bitfield structure.
24079  Normally SDCC will cast the bitfield structure to a bitfield pointer and
24080  then load FSR0.
24081  This step saves data ram and code space for functions that make heavy use
24082  of bitfields.
24083  (i.e., 80 bytes of code space are saved when compiling malloc.c with this
24084  option).
24085  
24086 \end_layout
24087
24088 \begin_layout Description
24089 NO_REG_OPT Do not perform pCode registers optimization.
24090  This should be used for debugging purposes.
24091  If bugs in the pcode optimizer are found, users can benefit from temporarily
24092  disabling the optimizer until the bug is fixed.
24093 \end_layout
24094
24095 \begin_layout Subsection
24096 Preprocessor Macros
24097 \end_layout
24098
24099 \begin_layout Standard
24100 PIC16
24101 \begin_inset LatexCommand \index{PIC16}
24102
24103 \end_inset
24104
24105  port defines the following preprocessor macros while translating a source.
24106 \end_layout
24107
24108 \begin_layout Standard
24109 \align center
24110 \begin_inset Tabular
24111 <lyxtabular version="3" rows="6" columns="2">
24112 <features>
24113 <column alignment="center" valignment="top" leftline="true" width="0">
24114 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24115 <row topline="true" bottomline="true">
24116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24117 \begin_inset Text
24118
24119 \begin_layout Standard
24120 Macro
24121 \end_layout
24122
24123 \end_inset
24124 </cell>
24125 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24126 \begin_inset Text
24127
24128 \begin_layout Standard
24129 Description
24130 \end_layout
24131
24132 \end_inset
24133 </cell>
24134 </row>
24135 <row topline="true">
24136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24137 \begin_inset Text
24138
24139 \begin_layout Standard
24140 SDCC_pic16
24141 \end_layout
24142
24143 \end_inset
24144 </cell>
24145 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24146 \begin_inset Text
24147
24148 \begin_layout Standard
24149 Port identification
24150 \end_layout
24151
24152 \end_inset
24153 </cell>
24154 </row>
24155 <row topline="true">
24156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24157 \begin_inset Text
24158
24159 \begin_layout Standard
24160 _
24161 \begin_inset ERT
24162 status collapsed
24163
24164 \begin_layout Standard
24165
24166
24167 \backslash
24168 /
24169 \end_layout
24170
24171 \end_inset
24172
24173 _pic16
24174 \end_layout
24175
24176 \end_inset
24177 </cell>
24178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24179 \begin_inset Text
24180
24181 \begin_layout Standard
24182 Port identification (same as above)
24183 \end_layout
24184
24185 \end_inset
24186 </cell>
24187 </row>
24188 <row topline="true">
24189 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24190 \begin_inset Text
24191
24192 \begin_layout Standard
24193 pic18fxxxx
24194 \end_layout
24195
24196 \end_inset
24197 </cell>
24198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24199 \begin_inset Text
24200
24201 \begin_layout Standard
24202 MCU Identification.
24203  
24204 \emph on
24205 xxxx
24206 \emph default
24207  is the microcontrol identification number, i.e.
24208  452, 6620, etc
24209 \end_layout
24210
24211 \end_inset
24212 </cell>
24213 </row>
24214 <row topline="true">
24215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24216 \begin_inset Text
24217
24218 \begin_layout Standard
24219 _
24220 \begin_inset ERT
24221 status collapsed
24222
24223 \begin_layout Standard
24224
24225
24226 \backslash
24227 /
24228 \end_layout
24229
24230 \end_inset
24231
24232 _18Fxxxx
24233 \end_layout
24234
24235 \end_inset
24236 </cell>
24237 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24238 \begin_inset Text
24239
24240 \begin_layout Standard
24241 MCU Identification (same as above)
24242 \end_layout
24243
24244 \end_inset
24245 </cell>
24246 </row>
24247 <row topline="true" bottomline="true">
24248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24249 \begin_inset Text
24250
24251 \begin_layout Standard
24252 STACK_MODEL_nnn
24253 \end_layout
24254
24255 \end_inset
24256 </cell>
24257 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24258 \begin_inset Text
24259
24260 \begin_layout Standard
24261 nnn = SMALL or LARGE respectively according to the stack model used
24262 \end_layout
24263
24264 \end_inset
24265 </cell>
24266 </row>
24267 </lyxtabular>
24268
24269 \end_inset
24270
24271
24272 \end_layout
24273
24274 \begin_layout Standard
24275 In addition the following macros are defined when calling assembler:
24276 \end_layout
24277
24278 \begin_layout Standard
24279 \align center
24280 \begin_inset Tabular
24281 <lyxtabular version="3" rows="4" columns="2">
24282 <features>
24283 <column alignment="center" valignment="top" leftline="true" width="0">
24284 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24285 <row topline="true" bottomline="true">
24286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24287 \begin_inset Text
24288
24289 \begin_layout Standard
24290 Macro
24291 \end_layout
24292
24293 \end_inset
24294 </cell>
24295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24296 \begin_inset Text
24297
24298 \begin_layout Standard
24299 Description
24300 \end_layout
24301
24302 \end_inset
24303 </cell>
24304 </row>
24305 <row topline="true">
24306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24307 \begin_inset Text
24308
24309 \begin_layout Standard
24310 __18Fxxxx
24311 \end_layout
24312
24313 \end_inset
24314 </cell>
24315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24316 \begin_inset Text
24317
24318 \begin_layout Standard
24319 MCU Identification.
24320  
24321 \emph on
24322 xxxx
24323 \emph default
24324  is the microcontrol identification number, i.e.
24325  452, 6620, etc
24326 \end_layout
24327
24328 \end_inset
24329 </cell>
24330 </row>
24331 <row topline="true">
24332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24333 \begin_inset Text
24334
24335 \begin_layout Standard
24336 SDCC_MODEL_nnn
24337 \end_layout
24338
24339 \end_inset
24340 </cell>
24341 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24342 \begin_inset Text
24343
24344 \begin_layout Standard
24345 nnn = SMALL or LARGE respectively according to the memory model used for
24346  SDCC
24347 \end_layout
24348
24349 \end_inset
24350 </cell>
24351 </row>
24352 <row topline="true" bottomline="true">
24353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24354 \begin_inset Text
24355
24356 \begin_layout Standard
24357 STACK_MODEL_nnn
24358 \end_layout
24359
24360 \end_inset
24361 </cell>
24362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24363 \begin_inset Text
24364
24365 \begin_layout Standard
24366 nnn = SMALL or LARGE respectively according to the stack model used
24367 \end_layout
24368
24369 \end_inset
24370 </cell>
24371 </row>
24372 </lyxtabular>
24373
24374 \end_inset
24375
24376
24377 \end_layout
24378
24379 \begin_layout Subsection
24380 Directories
24381 \end_layout
24382
24383 \begin_layout Standard
24384 PIC16
24385 \begin_inset LatexCommand \index{PIC16}
24386
24387 \end_inset
24388
24389  port uses the following directories for searching header files and libraries.
24390 \end_layout
24391
24392 \begin_layout Standard
24393 \align center
24394 \begin_inset Tabular
24395 <lyxtabular version="3" rows="3" columns="4">
24396 <features>
24397 <column alignment="center" valignment="top" leftline="true" width="0">
24398 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24399 <column alignment="center" valignment="top" width="0">
24400 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24401 <row topline="true" bottomline="true">
24402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24403 \begin_inset Text
24404
24405 \begin_layout Standard
24406 Directory
24407 \end_layout
24408
24409 \end_inset
24410 </cell>
24411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24412 \begin_inset Text
24413
24414 \begin_layout Standard
24415 Description
24416 \end_layout
24417
24418 \end_inset
24419 </cell>
24420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24421 \begin_inset Text
24422
24423 \begin_layout Standard
24424 Target
24425 \end_layout
24426
24427 \end_inset
24428 </cell>
24429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24430 \begin_inset Text
24431
24432 \begin_layout Standard
24433 Command prefix
24434 \end_layout
24435
24436 \end_inset
24437 </cell>
24438 </row>
24439 <row topline="true">
24440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24441 \begin_inset Text
24442
24443 \begin_layout Standard
24444 PREFIX/sdcc/include/pic16
24445 \end_layout
24446
24447 \end_inset
24448 </cell>
24449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24450 \begin_inset Text
24451
24452 \begin_layout Standard
24453 PIC16 specific headers
24454 \end_layout
24455
24456 \end_inset
24457 </cell>
24458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24459 \begin_inset Text
24460
24461 \begin_layout Standard
24462 Compiler
24463 \end_layout
24464
24465 \end_inset
24466 </cell>
24467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24468 \begin_inset Text
24469
24470 \begin_layout Standard
24471 -I
24472 \end_layout
24473
24474 \end_inset
24475 </cell>
24476 </row>
24477 <row topline="true" bottomline="true">
24478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24479 \begin_inset Text
24480
24481 \begin_layout Standard
24482 PREFIX/sdcc/lib/pic16
24483 \end_layout
24484
24485 \end_inset
24486 </cell>
24487 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24488 \begin_inset Text
24489
24490 \begin_layout Standard
24491 PIC16 specific libraries
24492 \end_layout
24493
24494 \end_inset
24495 </cell>
24496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24497 \begin_inset Text
24498
24499 \begin_layout Standard
24500 Linker
24501 \end_layout
24502
24503 \end_inset
24504 </cell>
24505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24506 \begin_inset Text
24507
24508 \begin_layout Standard
24509 -L
24510 \end_layout
24511
24512 \end_inset
24513 </cell>
24514 </row>
24515 </lyxtabular>
24516
24517 \end_inset
24518
24519
24520 \end_layout
24521
24522 \begin_layout Subsection
24523 Pragmas
24524 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24525
24526 \end_inset
24527
24528
24529 \end_layout
24530
24531 \begin_layout Standard
24532 The PIC16
24533 \begin_inset LatexCommand \index{PIC16}
24534
24535 \end_inset
24536
24537  port currently supports the following pragmas:
24538 \end_layout
24539
24540 \begin_layout Description
24541 stack
24542 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24543
24544 \end_inset
24545
24546  This forces the code generator to initialize the stack & frame pointers
24547  at a specific address.
24548  This is an ad hoc solution for cases where no STACK directive is available
24549  in the linker script or gplink is not instructed to create a stack section.
24550 \newline
24551 The
24552  stack pragma should be used only once in a project.
24553  Multiple pragmas may result in indeterminate behaviour of the program.
24554 \begin_inset Foot
24555 status open
24556
24557 \begin_layout Standard
24558 The old format (ie.
24559  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24560  cross page boundaries (or even exceed the available data RAM) and crash
24561  the program.
24562  Make sure that stack does not cross page boundaries when using the SMALL
24563  stack model.
24564 \end_layout
24565
24566 \end_inset
24567
24568
24569 \newline
24570 The format is as follows:
24571 \newline
24572
24573 \end_layout
24574
24575 \begin_layout LyX-Code
24576 #pragma stack bottom_address [stack_size]
24577 \newline
24578
24579 \end_layout
24580
24581 \begin_layout Standard
24582
24583 \emph on
24584 bottom_address
24585 \emph default
24586  is the lower bound of the stack section.
24587  The stack pointer initially will point at address (bottom_address+stack_size-1).
24588 \end_layout
24589
24590 \begin_layout LyX-Code
24591 Example:
24592 \end_layout
24593
24594 \begin_layout LyX-Code
24595
24596 \end_layout
24597
24598 \begin_layout LyX-Code
24599 /* initializes stack of 100 bytes at RAM address 0x200 */
24600 \end_layout
24601
24602 \begin_layout LyX-Code
24603 #pragma stack 0x200 100
24604 \end_layout
24605
24606 \begin_layout Standard
24607 If the stack_size field is omitted then a stack is created with the default
24608  size of 64.
24609  This size might be enough for most programs, but its not enough for operations
24610  with deep function nesting or excessive stack usage.
24611 \end_layout
24612
24613 \begin_layout Description
24614 code
24615 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24616
24617 \end_inset
24618
24619  Force a function to a static FLASH address.
24620 \end_layout
24621
24622 \begin_layout LyX-Code
24623 Example:
24624 \end_layout
24625
24626 \begin_layout LyX-Code
24627
24628 \end_layout
24629
24630 \begin_layout LyX-Code
24631 /* place function test_func at 0x4000 */
24632 \end_layout
24633
24634 \begin_layout LyX-Code
24635 #pragma code test_func 0x4000
24636 \end_layout
24637
24638 \begin_layout LyX-Code
24639
24640 \end_layout
24641
24642 \begin_layout Description
24643 library instructs the linker to use a library module.
24644 \newline
24645 Usage:
24646 \end_layout
24647
24648 \begin_layout LyX-Code
24649 #pragma library module_name
24650 \end_layout
24651
24652 \begin_layout Standard
24653
24654 \emph on
24655 module_name
24656 \emph default
24657  can be any library or object file (including its path).
24658  Note that there are four reserved keywords which have special meaning.
24659  These are:
24660 \end_layout
24661
24662 \begin_layout Standard
24663 \align center
24664 \begin_inset Tabular
24665 <lyxtabular version="3" rows="6" columns="3">
24666 <features>
24667 <column alignment="center" valignment="top" leftline="true" width="0">
24668 <column alignment="block" valignment="top" leftline="true" width="20page%">
24669 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24670 <row topline="true" bottomline="true">
24671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24672 \begin_inset Text
24673
24674 \begin_layout Standard
24675 Keyword
24676 \end_layout
24677
24678 \end_inset
24679 </cell>
24680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24681 \begin_inset Text
24682
24683 \begin_layout Standard
24684 Description
24685 \end_layout
24686
24687 \end_inset
24688 </cell>
24689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24690 \begin_inset Text
24691
24692 \begin_layout Standard
24693 Module to link
24694 \end_layout
24695
24696 \end_inset
24697 </cell>
24698 </row>
24699 <row topline="true">
24700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24701 \begin_inset Text
24702
24703 \begin_layout Standard
24704
24705 \series bold
24706 ignore
24707 \end_layout
24708
24709 \end_inset
24710 </cell>
24711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24712 \begin_inset Text
24713
24714 \begin_layout Standard
24715 ignore all library pragmas
24716 \end_layout
24717
24718 \end_inset
24719 </cell>
24720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24721 \begin_inset Text
24722
24723 \begin_layout Standard
24724
24725 \emph on
24726 (none)
24727 \end_layout
24728
24729 \end_inset
24730 </cell>
24731 </row>
24732 <row topline="true">
24733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24734 \begin_inset Text
24735
24736 \begin_layout Standard
24737
24738 \series bold
24739 c
24740 \end_layout
24741
24742 \end_inset
24743 </cell>
24744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24745 \begin_inset Text
24746
24747 \begin_layout Standard
24748 link the C library
24749 \end_layout
24750
24751 \end_inset
24752 </cell>
24753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24754 \begin_inset Text
24755
24756 \begin_layout Standard
24757
24758 \emph on
24759 libc18f
24760 \emph default
24761 .lib
24762 \end_layout
24763
24764 \end_inset
24765 </cell>
24766 </row>
24767 <row topline="true">
24768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24769 \begin_inset Text
24770
24771 \begin_layout Standard
24772
24773 \series bold
24774 math
24775 \end_layout
24776
24777 \end_inset
24778 </cell>
24779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24780 \begin_inset Text
24781
24782 \begin_layout Standard
24783 link the Math libarary
24784 \end_layout
24785
24786 \end_inset
24787 </cell>
24788 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24789 \begin_inset Text
24790
24791 \begin_layout Standard
24792
24793 \emph on
24794 libm18f
24795 \emph default
24796 .lib
24797 \end_layout
24798
24799 \end_inset
24800 </cell>
24801 </row>
24802 <row topline="true">
24803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24804 \begin_inset Text
24805
24806 \begin_layout Standard
24807
24808 \series bold
24809 io
24810 \end_layout
24811
24812 \end_inset
24813 </cell>
24814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24815 \begin_inset Text
24816
24817 \begin_layout Standard
24818 link the I/O library
24819 \end_layout
24820
24821 \end_inset
24822 </cell>
24823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24824 \begin_inset Text
24825
24826 \begin_layout Standard
24827
24828 \emph on
24829 libio18f*
24830 \emph default
24831 .lib
24832 \end_layout
24833
24834 \end_inset
24835 </cell>
24836 </row>
24837 <row topline="true" bottomline="true">
24838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24839 \begin_inset Text
24840
24841 \begin_layout Standard
24842
24843 \series bold
24844 debug
24845 \end_layout
24846
24847 \end_inset
24848 </cell>
24849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24850 \begin_inset Text
24851
24852 \begin_layout Standard
24853 link the debug library
24854 \end_layout
24855
24856 \end_inset
24857 </cell>
24858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24859 \begin_inset Text
24860
24861 \begin_layout Standard
24862
24863 \emph on
24864 libdebug
24865 \emph default
24866 .lib
24867 \end_layout
24868
24869 \end_inset
24870 </cell>
24871 </row>
24872 </lyxtabular>
24873
24874 \end_inset
24875
24876
24877 \newline
24878 * is the device number, i.e.
24879  452 for PIC18F452 MCU.
24880 \end_layout
24881
24882 \begin_layout Standard
24883 This feature allows for linking with specific libraries withoug having to
24884  explicit name them in the command line.
24885  Note that the 
24886 \noun on
24887 ignore
24888 \noun default
24889  keyword will reject all modules specified by the library pragma.
24890 \end_layout
24891
24892 \begin_layout Description
24893 udata The pragma udata instructs the compiler to emit code so that linker
24894  will place a variable at a specific memory bank.
24895 \end_layout
24896
24897 \begin_layout LyX-Code
24898 Example:
24899 \end_layout
24900
24901 \begin_layout LyX-Code
24902
24903 \end_layout
24904
24905 \begin_layout LyX-Code
24906 /* places variable foo at bank2 */
24907 \end_layout
24908
24909 \begin_layout LyX-Code
24910 #pragma udata bank2 foo
24911 \end_layout
24912
24913 \begin_layout LyX-Code
24914 char foo;
24915 \end_layout
24916
24917 \begin_layout Standard
24918 In order for this pragma to work extra SECTION directives should be added
24919  in the .lkr script.
24920  In the following example a sample .lkr file is shown:
24921 \end_layout
24922
24923 \begin_layout LyX-Code
24924
24925 \end_layout
24926
24927 \begin_layout LyX-Code
24928 // Sample linker script for the PIC18F452 processor
24929 \end_layout
24930
24931 \begin_layout LyX-Code
24932 LIBPATH .
24933 \end_layout
24934
24935 \begin_layout LyX-Code
24936 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
24937 \end_layout
24938
24939 \begin_layout LyX-Code
24940 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
24941 \end_layout
24942
24943 \begin_layout LyX-Code
24944 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
24945 \end_layout
24946
24947 \begin_layout LyX-Code
24948 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
24949 \end_layout
24950
24951 \begin_layout LyX-Code
24952 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
24953 \end_layout
24954
24955 \begin_layout LyX-Code
24956 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
24957 \end_layout
24958
24959 \begin_layout LyX-Code
24960 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
24961 \end_layout
24962
24963 \begin_layout LyX-Code
24964
24965 \end_layout
24966
24967 \begin_layout LyX-Code
24968 DATABANK   NAME=gpr0       START=0x80           END=0xFF
24969 \end_layout
24970
24971 \begin_layout LyX-Code
24972 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
24973 \end_layout
24974
24975 \begin_layout LyX-Code
24976 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
24977 \end_layout
24978
24979 \begin_layout LyX-Code
24980 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
24981 \end_layout
24982
24983 \begin_layout LyX-Code
24984 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
24985 \end_layout
24986
24987 \begin_layout LyX-Code
24988 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
24989 \end_layout
24990
24991 \begin_layout LyX-Code
24992 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
24993 \end_layout
24994
24995 \begin_layout LyX-Code
24996
24997 \end_layout
24998
24999 \begin_layout LyX-Code
25000 SECTION    NAME=CONFIG     ROM=config
25001 \end_layout
25002
25003 \begin_layout LyX-Code
25004
25005 \end_layout
25006
25007 \begin_layout LyX-Code
25008 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
25009 \end_layout
25010
25011 \begin_layout LyX-Code
25012 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
25013 \end_layout
25014
25015 \begin_layout LyX-Code
25016 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
25017 \end_layout
25018
25019 \begin_layout LyX-Code
25020 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
25021 \end_layout
25022
25023 \begin_layout LyX-Code
25024 SECTION    NAME=bank4      RAM=gpr4
25025 \end_layout
25026
25027 \begin_layout LyX-Code
25028 SECTION    NAME=bank5      RAM=gpr5
25029 \end_layout
25030
25031 \begin_layout Standard
25032 The linker will recognise the section name set in the pragma statement and
25033  will position the variable at the memory bank set with the RAM field at
25034  the SECTION line in the linker script file.
25035 \end_layout
25036
25037 \begin_layout Subsection
25038 Header Files
25039 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
25040
25041 \end_inset
25042
25043
25044 \end_layout
25045
25046 \begin_layout Standard
25047 There is one main header file
25048 \begin_inset LatexCommand \index{PIC16!Header files}
25049
25050 \end_inset
25051
25052  that can be included to the source files using the pic16
25053 \begin_inset LatexCommand \index{PIC16}
25054
25055 \end_inset
25056
25057  port.
25058  That file is the 
25059 \series bold
25060 pic18fregs.h
25061 \series default
25062 .
25063  This header file contains the definitions for the processor special registers,
25064  so it is necessary if the source accesses them.
25065  It can be included by adding the following line in the beginning of the
25066  file:
25067 \end_layout
25068
25069 \begin_layout LyX-Code
25070 #include <pic18fregs.h>
25071 \end_layout
25072
25073 \begin_layout Standard
25074 The specific microcontroller is selected within the pic18fregs.h automatically,
25075  so the same source can be used with a variety of devices.
25076 \end_layout
25077
25078 \begin_layout Subsection
25079 Libraries
25080 \end_layout
25081
25082 \begin_layout Standard
25083 The libraries
25084 \begin_inset LatexCommand \index{PIC16!Libraries}
25085
25086 \end_inset
25087
25088  that PIC16
25089 \begin_inset LatexCommand \index{PIC16}
25090
25091 \end_inset
25092
25093  port depends on are the microcontroller device libraries which contain
25094  the symbol definitions for the microcontroller special function registers.
25095  These libraries have the format pic18fxxxx.lib, where 
25096 \emph on
25097 xxxx
25098 \emph default
25099  is the microcontroller identification number.
25100  The specific library is selected automatically by the compiler at link
25101  stage according to the selected device.
25102 \end_layout
25103
25104 \begin_layout Standard
25105 Libraries are created with gplib which is part of the gputils package 
25106 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
25107
25108 \end_inset
25109
25110 .
25111 \end_layout
25112
25113 \begin_layout Subsubsection*
25114 Building the libraries
25115 \end_layout
25116
25117 \begin_layout Standard
25118 Before using SDCC/pic16 there are some libraries that need to be compiled.
25119  This process is not done automatically by SDCC since not all users use
25120  SDCC for pic16 projects.
25121  So each user should compile the libraries separately.
25122 \end_layout
25123
25124 \begin_layout Standard
25125 The steps to compile the pic16 libraries under Linux and Mac OS X are:
25126 \end_layout
25127
25128 \begin_layout LyX-Code
25129 cd device/lib/pic16
25130 \end_layout
25131
25132 \begin_layout LyX-Code
25133 ./configure
25134 \end_layout
25135
25136 \begin_layout LyX-Code
25137 make
25138 \end_layout
25139
25140 \begin_layout LyX-Code
25141 cd ..
25142 \end_layout
25143
25144 \begin_layout LyX-Code
25145 make model-pic16
25146 \end_layout
25147
25148 \begin_layout LyX-Code
25149 su -c 'make install'     # install the libraries, you need the root password
25150 \end_layout
25151
25152 \begin_layout Standard
25153 If you need to install the headers too, do:
25154 \end_layout
25155
25156 \begin_layout LyX-Code
25157 cd device/include
25158 \end_layout
25159
25160 \begin_layout LyX-Code
25161 su -c 'make install'     # install the headers, you need the root password
25162 \end_layout
25163
25164 \begin_layout Standard
25165 There exist a special target to build the I/O libraries.
25166  This target is not automatically build because it will build the I/O library
25167  for 
25168 \emph on
25169 every
25170 \emph default
25171  supported device.
25172  This way building will take quite a lot of time.
25173  Users are advised to edit the 
25174 \series bold
25175 device/lib/pic16/pics.build
25176 \series default
25177  file and then execute:
25178 \end_layout
25179
25180 \begin_layout LyX-Code
25181 make lib-io
25182 \end_layout
25183
25184 \begin_layout Subsection
25185 Adding New Devices to the Port
25186 \end_layout
25187
25188 \begin_layout Standard
25189 Adding support for a new 16
25190 \begin_inset ERT
25191 status open
25192
25193 \begin_layout Standard
25194
25195
25196 \backslash
25197 ,
25198 \end_layout
25199
25200 \end_inset
25201
25202 bit PIC MCU requires the following steps:
25203 \end_layout
25204
25205 \begin_layout Enumerate
25206 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
25207 \newline
25208
25209 \family typewriter
25210 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
25211 inc
25212 \end_layout
25213
25214 \begin_layout Enumerate
25215
25216 \family typewriter
25217 mv picDEVICE.h /path/to/sdcc/device/include/pic16
25218 \end_layout
25219
25220 \begin_layout Enumerate
25221
25222 \family typewriter
25223 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
25224 \end_layout
25225
25226 \begin_layout Enumerate
25227 Add DEVICE to 
25228 \family typewriter
25229 /path/to/sdcc/device/lib/pics.all
25230 \family default
25231  (and 
25232 \family typewriter
25233 .build
25234 \family default
25235 ).
25236 \newline
25237 Note: No 18f prefix here!
25238 \end_layout
25239
25240 \begin_layout Enumerate
25241 Adjust 
25242 \family typewriter
25243 /path/to/sdcc/device/lib/pic16/libio/*.ignore
25244 \family default
25245
25246 \newline
25247 Add your DEVICE if it does not compile in 
25248 \family typewriter
25249 adc
25250 \family default
25251
25252 \family typewriter
25253 i2c
25254 \family default
25255 , or 
25256 \family typewriter
25257 usart
25258 \family default
25259 .
25260 \end_layout
25261
25262 \begin_layout Enumerate
25263 Edit 
25264 \family typewriter
25265 /path/to/sdcc/device/include/pic16/pic18fregs.h
25266 \family default
25267 .
25268  The file format is self-explanatory, just add
25269 \newline
25270
25271 \family typewriter
25272 #elif defined(picDEVICE)
25273 \newline
25274 # include <picDEVICE.h>
25275 \family default
25276
25277 \newline
25278 at the right place (keep it sorted).
25279 \end_layout
25280
25281 \begin_layout Enumerate
25282 Edit 
25283 \family typewriter
25284 /path/to/sdcc/src/pic16/devices.inc
25285 \family default
25286 .
25287  Copy and modify an existing entry and insert it at the correct place (keep
25288  the file sorted).
25289  The file is hardly documented, look at the entries for the 18f2221...
25290 \end_layout
25291
25292 \begin_layout Enumerate
25293 Recompile SDCC, including the pic16 libraries.
25294 \end_layout
25295
25296 \begin_layout Subsection
25297 Memory Models
25298 \end_layout
25299
25300 \begin_layout Standard
25301 The following memory models are supported by the PIC16 port:
25302 \end_layout
25303
25304 \begin_layout Itemize
25305 small model
25306 \end_layout
25307
25308 \begin_layout Itemize
25309 large model
25310 \end_layout
25311
25312 \begin_layout Standard
25313 Memory model affects the default size of pointers within the source.
25314  The sizes are shown in the next table:
25315 \end_layout
25316
25317 \begin_layout Standard
25318 \align center
25319 \begin_inset Tabular
25320 <lyxtabular version="3" rows="3" columns="3">
25321 <features>
25322 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25323 <column alignment="center" valignment="top" leftline="true" width="0">
25324 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25325 <row topline="true" bottomline="true">
25326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25327 \begin_inset Text
25328
25329 \begin_layout Standard
25330 Pointer sizes according to memory model
25331 \end_layout
25332
25333 \end_inset
25334 </cell>
25335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25336 \begin_inset Text
25337
25338 \begin_layout Standard
25339 small model
25340 \end_layout
25341
25342 \end_inset
25343 </cell>
25344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25345 \begin_inset Text
25346
25347 \begin_layout Standard
25348 large model
25349 \end_layout
25350
25351 \end_inset
25352 </cell>
25353 </row>
25354 <row topline="true" bottomline="true">
25355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25356 \begin_inset Text
25357
25358 \begin_layout Standard
25359 code pointers
25360 \end_layout
25361
25362 \end_inset
25363 </cell>
25364 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25365 \begin_inset Text
25366
25367 \begin_layout Standard
25368 16-bits
25369 \end_layout
25370
25371 \end_inset
25372 </cell>
25373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25374 \begin_inset Text
25375
25376 \begin_layout Standard
25377 24-bits
25378 \end_layout
25379
25380 \end_inset
25381 </cell>
25382 </row>
25383 <row topline="true" bottomline="true">
25384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25385 \begin_inset Text
25386
25387 \begin_layout Standard
25388 data pointers
25389 \end_layout
25390
25391 \end_inset
25392 </cell>
25393 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25394 \begin_inset Text
25395
25396 \begin_layout Standard
25397 16-bits
25398 \end_layout
25399
25400 \end_inset
25401 </cell>
25402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25403 \begin_inset Text
25404
25405 \begin_layout Standard
25406 16-bits
25407 \end_layout
25408
25409 \end_inset
25410 </cell>
25411 </row>
25412 </lyxtabular>
25413
25414 \end_inset
25415
25416
25417 \end_layout
25418
25419 \begin_layout Standard
25420 It is advisable that all sources within a project are compiled with the
25421  same memory model.
25422  If one wants to override the default memory model, this can be done by
25423  declaring a pointer as 
25424 \series bold
25425 far
25426 \series default
25427  or 
25428 \series bold
25429 near
25430 \series default
25431 .
25432  Far selects large memory model's pointers, while near selects small memory
25433  model's pointers.
25434 \end_layout
25435
25436 \begin_layout Standard
25437 The standard device libraries (see 
25438 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25439
25440 \end_inset
25441
25442 ) contain no reference to pointers, so they can be used with both memory
25443  models.
25444 \end_layout
25445
25446 \begin_layout Subsection
25447 Stack
25448 \end_layout
25449
25450 \begin_layout Standard
25451 The stack
25452 \begin_inset LatexCommand \index{PIC16!stack}
25453
25454 \end_inset
25455
25456  implementation for the PIC16 port uses two indirect registers, FSR1 and
25457  FSR2.
25458 \end_layout
25459
25460 \begin_layout Description
25461 FSR1 is assigned as stack pointer
25462 \end_layout
25463
25464 \begin_layout Description
25465 FSR2 is assigned as frame pointer
25466 \end_layout
25467
25468 \begin_layout Standard
25469 The following stack models are supported by the PIC16 port
25470 \end_layout
25471
25472 \begin_layout Itemize
25473
25474 \noun on
25475 small
25476 \noun default
25477  model
25478 \end_layout
25479
25480 \begin_layout Itemize
25481
25482 \noun on
25483 large
25484 \noun default
25485  model
25486 \end_layout
25487
25488 \begin_layout Standard
25489
25490 \noun on
25491 Small
25492 \noun default
25493  model means that only the FSRxL byte is used to access stack and frame,
25494  while 
25495 \emph on
25496 \noun on
25497 large
25498 \emph default
25499 \noun default
25500  uses both FSRxL and FSRxH registers.
25501  The following table shows the stack/frame pointers sizes according to stack
25502  model and the maximum space they can address:
25503 \end_layout
25504
25505 \begin_layout Standard
25506 \align center
25507 \begin_inset Tabular
25508 <lyxtabular version="3" rows="3" columns="3">
25509 <features>
25510 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25511 <column alignment="center" valignment="top" leftline="true" width="0">
25512 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25513 <row topline="true" bottomline="true">
25514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25515 \begin_inset Text
25516
25517 \begin_layout Standard
25518 Stack & Frame pointer sizes according to stack model
25519 \end_layout
25520
25521 \end_inset
25522 </cell>
25523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25524 \begin_inset Text
25525
25526 \begin_layout Standard
25527 small
25528 \end_layout
25529
25530 \end_inset
25531 </cell>
25532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25533 \begin_inset Text
25534
25535 \begin_layout Standard
25536 large
25537 \end_layout
25538
25539 \end_inset
25540 </cell>
25541 </row>
25542 <row topline="true">
25543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25544 \begin_inset Text
25545
25546 \begin_layout Standard
25547 Stack pointer FSR1
25548 \end_layout
25549
25550 \end_inset
25551 </cell>
25552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25553 \begin_inset Text
25554
25555 \begin_layout Standard
25556 8-bits
25557 \end_layout
25558
25559 \end_inset
25560 </cell>
25561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25562 \begin_inset Text
25563
25564 \begin_layout Standard
25565 16-bits
25566 \end_layout
25567
25568 \end_inset
25569 </cell>
25570 </row>
25571 <row topline="true" bottomline="true">
25572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25573 \begin_inset Text
25574
25575 \begin_layout Standard
25576 Frame pointer FSR2
25577 \end_layout
25578
25579 \end_inset
25580 </cell>
25581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25582 \begin_inset Text
25583
25584 \begin_layout Standard
25585 8-bits
25586 \end_layout
25587
25588 \end_inset
25589 </cell>
25590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25591 \begin_inset Text
25592
25593 \begin_layout Standard
25594 16-bits
25595 \end_layout
25596
25597 \end_inset
25598 </cell>
25599 </row>
25600 </lyxtabular>
25601
25602 \end_inset
25603
25604
25605 \end_layout
25606
25607 \begin_layout Standard
25608
25609 \noun on
25610 Large 
25611 \noun default
25612 stack model is currently not working properly throughout the code generator.
25613  So its use is not advised.
25614  Also there are some other points that need special care:
25615 \newline
25616
25617 \end_layout
25618
25619 \begin_layout Enumerate
25620 Do not create stack sections with size more than one physical bank (that
25621  is 256 bytes)
25622 \end_layout
25623
25624 \begin_layout Enumerate
25625 Stack sections should no cross physical bank limits (i.e.
25626  #pragma stack 0x50 0x100)
25627 \end_layout
25628
25629 \begin_layout Standard
25630 These limitations are caused by the fact that only FSRxL is modified when
25631  using SMALL stack model, so no more than 256 bytes of stack can be used.
25632  This problem will disappear after LARGE model is fully implemented.
25633 \end_layout
25634
25635 \begin_layout Subsection
25636 Functions
25637 \end_layout
25638
25639 \begin_layout Standard
25640 In addition to the standard SDCC function keywords, PIC16
25641 \begin_inset LatexCommand \index{PIC16}
25642
25643 \end_inset
25644
25645  port makes available two more:
25646 \end_layout
25647
25648 \begin_layout Description
25649 wparam
25650 \begin_inset LatexCommand \index{PIC16!wparam}
25651
25652 \end_inset
25653
25654  Use the WREG to pass one byte of the first function argument.
25655  This improves speed but you may not use this for functions with arguments
25656  that are called via function pointers, otherwise the first byte of the
25657  first parameter will get lost.
25658  Usage:
25659 \end_layout
25660
25661 \begin_layout LyX-Code
25662 void func_wparam(int a) wparam
25663 \end_layout
25664
25665 \begin_layout LyX-Code
25666 {
25667 \end_layout
25668
25669 \begin_layout LyX-Code
25670     /* WREG hold the lower part of a */
25671 \end_layout
25672
25673 \begin_layout LyX-Code
25674     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25675  */
25676 \end_layout
25677
25678 \begin_layout LyX-Code
25679 ...
25680 \end_layout
25681
25682 \begin_layout LyX-Code
25683 }
25684 \end_layout
25685
25686 \begin_layout Description
25687 shadowregs
25688 \begin_inset LatexCommand \index{PIC16!shadowregs}
25689
25690 \end_inset
25691
25692  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25693  hardware shadow registers which hold the values of WREG, STATUS and BSR
25694  registers.
25695  This can be done by adding the keyword 
25696 \emph on
25697 shadowregs
25698 \emph default
25699  before the 
25700 \emph on
25701 interrupt
25702 \emph default
25703  keyword in the function's header.
25704 \end_layout
25705
25706 \begin_layout LyX-Code
25707 void isr_shadow(void) shadowregs interrupt 1
25708 \end_layout
25709
25710 \begin_layout LyX-Code
25711 {
25712 \end_layout
25713
25714 \begin_layout LyX-Code
25715 ...
25716 \end_layout
25717
25718 \begin_layout LyX-Code
25719 }
25720 \end_layout
25721
25722 \begin_layout Standard
25723
25724 \emph on
25725 shadowregs
25726 \emph default
25727  instructs the code generator not to store/restore WREG, STATUS, BSR when
25728  entering/exiting the ISR.
25729 \end_layout
25730
25731 \begin_layout Subsection
25732 Function return values
25733 \end_layout
25734
25735 \begin_layout Standard
25736 Return values from functions are placed to the appropriate registers following
25737  a modified Microchip policy optimized for SDCC.
25738  The following table shows these registers:
25739 \end_layout
25740
25741 \begin_layout Standard
25742 \align center
25743 \begin_inset Tabular
25744 <lyxtabular version="3" rows="6" columns="2">
25745 <features>
25746 <column alignment="center" valignment="top" leftline="true" width="0">
25747 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25748 <row topline="true" bottomline="true">
25749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25750 \begin_inset Text
25751
25752 \begin_layout Standard
25753 size
25754 \end_layout
25755
25756 \end_inset
25757 </cell>
25758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25759 \begin_inset Text
25760
25761 \begin_layout Standard
25762 destination register
25763 \end_layout
25764
25765 \end_inset
25766 </cell>
25767 </row>
25768 <row topline="true">
25769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25770 \begin_inset Text
25771
25772 \begin_layout Standard
25773 8 bits
25774 \end_layout
25775
25776 \end_inset
25777 </cell>
25778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25779 \begin_inset Text
25780
25781 \begin_layout Standard
25782 WREG
25783 \end_layout
25784
25785 \end_inset
25786 </cell>
25787 </row>
25788 <row topline="true">
25789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25790 \begin_inset Text
25791
25792 \begin_layout Standard
25793 16 bits
25794 \end_layout
25795
25796 \end_inset
25797 </cell>
25798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25799 \begin_inset Text
25800
25801 \begin_layout Standard
25802 PRODL:WREG
25803 \end_layout
25804
25805 \end_inset
25806 </cell>
25807 </row>
25808 <row topline="true">
25809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25810 \begin_inset Text
25811
25812 \begin_layout Standard
25813 24 bits
25814 \end_layout
25815
25816 \end_inset
25817 </cell>
25818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25819 \begin_inset Text
25820
25821 \begin_layout Standard
25822 PRODH:PRODL:WREG
25823 \end_layout
25824
25825 \end_inset
25826 </cell>
25827 </row>
25828 <row topline="true">
25829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25830 \begin_inset Text
25831
25832 \begin_layout Standard
25833 32 bits
25834 \end_layout
25835
25836 \end_inset
25837 </cell>
25838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25839 \begin_inset Text
25840
25841 \begin_layout Standard
25842 FSR0L:PRODH:PRODL:WREG
25843 \end_layout
25844
25845 \end_inset
25846 </cell>
25847 </row>
25848 <row topline="true" bottomline="true">
25849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25850 \begin_inset Text
25851
25852 \begin_layout Standard
25853 >32 bits
25854 \end_layout
25855
25856 \end_inset
25857 </cell>
25858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25859 \begin_inset Text
25860
25861 \begin_layout Standard
25862 on stack, FSR0 points to the beginning
25863 \end_layout
25864
25865 \end_inset
25866 </cell>
25867 </row>
25868 </lyxtabular>
25869
25870 \end_inset
25871
25872
25873 \end_layout
25874
25875 \begin_layout Subsection
25876 Interrupts
25877 \end_layout
25878
25879 \begin_layout Standard
25880 An interrupt
25881 \begin_inset LatexCommand \index{PIC16!interrupt}
25882
25883 \end_inset
25884
25885  service routine (ISR) is declared using the 
25886 \emph on
25887 interrupt
25888 \emph default
25889  keyword.
25890 \end_layout
25891
25892 \begin_layout LyX-Code
25893 void isr(void) interrupt 
25894 \emph on
25895 n
25896 \end_layout
25897
25898 \begin_layout LyX-Code
25899 {
25900 \end_layout
25901
25902 \begin_layout LyX-Code
25903 ...
25904 \end_layout
25905
25906 \begin_layout LyX-Code
25907 }
25908 \end_layout
25909
25910 \begin_layout Standard
25911
25912 \emph on
25913 n
25914 \emph default
25915  is the interrupt number, which for PIC18F devices can be:
25916 \end_layout
25917
25918 \begin_layout Standard
25919 \align center
25920 \begin_inset Tabular
25921 <lyxtabular version="3" rows="4" columns="3">
25922 <features>
25923 <column alignment="center" valignment="top" leftline="true" width="0">
25924 <column alignment="center" valignment="top" leftline="true" width="0">
25925 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25926 <row topline="true" bottomline="true">
25927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25928 \begin_inset Text
25929
25930 \begin_layout Standard
25931
25932 \emph on
25933 n
25934 \end_layout
25935
25936 \end_inset
25937 </cell>
25938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25939 \begin_inset Text
25940
25941 \begin_layout Standard
25942 Interrupt Vector
25943 \end_layout
25944
25945 \end_inset
25946 </cell>
25947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25948 \begin_inset Text
25949
25950 \begin_layout Standard
25951 Interrupt Vector Address
25952 \end_layout
25953
25954 \end_inset
25955 </cell>
25956 </row>
25957 <row topline="true">
25958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25959 \begin_inset Text
25960
25961 \begin_layout Standard
25962 0
25963 \end_layout
25964
25965 \end_inset
25966 </cell>
25967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25968 \begin_inset Text
25969
25970 \begin_layout Standard
25971 RESET vector
25972 \end_layout
25973
25974 \end_inset
25975 </cell>
25976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25977 \begin_inset Text
25978
25979 \begin_layout Standard
25980 0x000000
25981 \end_layout
25982
25983 \end_inset
25984 </cell>
25985 </row>
25986 <row topline="true">
25987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25988 \begin_inset Text
25989
25990 \begin_layout Standard
25991
25992 \family roman
25993 \series medium
25994 \shape up
25995 \size normal
25996 \emph off
25997 \bar no
25998 \noun off
25999 \color none
26000 1
26001 \end_layout
26002
26003 \end_inset
26004 </cell>
26005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26006 \begin_inset Text
26007
26008 \begin_layout Standard
26009
26010 \family roman
26011 \series medium
26012 \shape up
26013 \size normal
26014 \emph off
26015 \bar no
26016 \noun off
26017 \color none
26018 HIGH priority interrupts
26019 \end_layout
26020
26021 \end_inset
26022 </cell>
26023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26024 \begin_inset Text
26025
26026 \begin_layout Standard
26027 0x000008
26028 \end_layout
26029
26030 \end_inset
26031 </cell>
26032 </row>
26033 <row topline="true" bottomline="true">
26034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26035 \begin_inset Text
26036
26037 \begin_layout Standard
26038 2
26039 \end_layout
26040
26041 \end_inset
26042 </cell>
26043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26044 \begin_inset Text
26045
26046 \begin_layout Standard
26047 LOW priority interrupts
26048 \end_layout
26049
26050 \end_inset
26051 </cell>
26052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26053 \begin_inset Text
26054
26055 \begin_layout Standard
26056 0x000018
26057 \end_layout
26058
26059 \end_inset
26060 </cell>
26061 </row>
26062 </lyxtabular>
26063
26064 \end_inset
26065
26066
26067 \end_layout
26068
26069 \begin_layout Standard
26070 When generating assembly code for ISR the code generator places a 
26071 \noun on
26072 goto 
26073 \noun default
26074 instruction at the 
26075 \emph on
26076 Interrupt Vector Address
26077 \emph default
26078  which points at the genetated ISR.
26079  This single GOTO instruction is part of an automatically generated 
26080 \emph on
26081 interrupt entry point
26082 \emph default
26083  function.
26084  The actuall ISR code is placed as normally would in the code space.
26085  Upon interrupt request, the GOTO instruction is executed which jumps to
26086  the ISR code.
26087  When declaring interrupt functions as _naked this GOTO instruction is 
26088 \series bold
26089 not
26090 \series default
26091  generated.
26092  The whole interrupt functions is therefore placed at the Interrupt Vector
26093  Address of the specific interrupt.
26094  This is not a problem for the LOW priority interrupts, but it is a problem
26095  for the RESET and the HIGH priority interrupts because code may be written
26096  at the next interrupt´s vector address and cause undeterminate program
26097  behaviour if that interrupt is raised.
26098 \begin_inset Foot
26099 status open
26100
26101 \begin_layout Standard
26102 This is not a problem when
26103 \end_layout
26104
26105 \begin_layout Enumerate
26106 this is a HIGH interrupt ISR and LOW interrupts are 
26107 \emph on
26108 disabled
26109 \emph default
26110  or not used.
26111 \end_layout
26112
26113 \begin_layout Enumerate
26114 when the ISR is small enough not to reach the next interrupt´s vector address.
26115 \end_layout
26116
26117 \end_inset
26118
26119
26120 \end_layout
26121
26122 \begin_layout Standard
26123
26124 \emph on
26125 n
26126 \emph default
26127  is possible to be omitted.
26128  This way a function is generated similar to an ISR, but it is not assigned
26129  to any interrupt.
26130 \end_layout
26131
26132 \begin_layout Standard
26133 When entering an interrupt, currently the PIC16
26134 \begin_inset LatexCommand \index{PIC16}
26135
26136 \end_inset
26137
26138  port automatically saves the following registers:
26139 \end_layout
26140
26141 \begin_layout Itemize
26142 WREG
26143 \end_layout
26144
26145 \begin_layout Itemize
26146 STATUS
26147 \end_layout
26148
26149 \begin_layout Itemize
26150 BSR
26151 \end_layout
26152
26153 \begin_layout Itemize
26154 PROD (PRODL and PRODH)
26155 \end_layout
26156
26157 \begin_layout Itemize
26158 FSR0 (FSR0L and FSR0H)
26159 \end_layout
26160
26161 \begin_layout Standard
26162 These registers are restored upon return from the interrupt routine.
26163 \begin_inset Foot
26164 status open
26165
26166 \begin_layout Standard
26167 NOTE that when the _naked attribute is specified for an interrupt routine,
26168  then NO registers are stored or restored.
26169 \end_layout
26170
26171 \end_inset
26172
26173
26174 \end_layout
26175
26176 \begin_layout Subsection
26177 Generic Pointers
26178 \end_layout
26179
26180 \begin_layout Standard
26181 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
26182  There are 3 types of generic pointers currently implemented data, code
26183  and eeprom pointers.
26184  They are differentiated by the value of the 7th and 6th bits of the upper
26185  byte:
26186 \end_layout
26187
26188 \begin_layout Standard
26189 \align center
26190 \begin_inset Tabular
26191 <lyxtabular version="3" rows="5" columns="5">
26192 <features>
26193 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26194 <column alignment="center" valignment="top" width="0">
26195 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26196 <column alignment="center" valignment="top" width="0">
26197 <column alignment="left" valignment="top" rightline="true" width="0">
26198 <row topline="true" bottomline="true">
26199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26200 \begin_inset Text
26201
26202 \begin_layout Standard
26203 pointer type
26204 \end_layout
26205
26206 \end_inset
26207 </cell>
26208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26209 \begin_inset Text
26210
26211 \begin_layout Standard
26212 7th bit
26213 \end_layout
26214
26215 \end_inset
26216 </cell>
26217 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26218 \begin_inset Text
26219
26220 \begin_layout Standard
26221 6th bit
26222 \end_layout
26223
26224 \end_inset
26225 </cell>
26226 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26227 \begin_inset Text
26228
26229 \begin_layout Standard
26230 rest of the pointer
26231 \end_layout
26232
26233 \end_inset
26234 </cell>
26235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26236 \begin_inset Text
26237
26238 \begin_layout Standard
26239 description
26240 \end_layout
26241
26242 \end_inset
26243 </cell>
26244 </row>
26245 <row topline="true" bottomline="true">
26246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26247 \begin_inset Text
26248
26249 \begin_layout Standard
26250 data 
26251 \end_layout
26252
26253 \end_inset
26254 </cell>
26255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26256 \begin_inset Text
26257
26258 \begin_layout Standard
26259 1
26260 \end_layout
26261
26262 \end_inset
26263 </cell>
26264 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26265 \begin_inset Text
26266
26267 \begin_layout Standard
26268 0
26269 \end_layout
26270
26271 \end_inset
26272 </cell>
26273 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26274 \begin_inset Text
26275
26276 \begin_layout Standard
26277
26278 \family typewriter
26279 \shape slanted
26280 \emph on
26281 uuuuuu uuuuxxxx xxxxxxxx
26282 \end_layout
26283
26284 \end_inset
26285 </cell>
26286 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26287 \begin_inset Text
26288
26289 \begin_layout Standard
26290 a 12-bit data pointer in data RAM memory
26291 \end_layout
26292
26293 \end_inset
26294 </cell>
26295 </row>
26296 <row bottomline="true">
26297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26298 \begin_inset Text
26299
26300 \begin_layout Standard
26301 code
26302 \end_layout
26303
26304 \end_inset
26305 </cell>
26306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26307 \begin_inset Text
26308
26309 \begin_layout Standard
26310 0
26311 \end_layout
26312
26313 \end_inset
26314 </cell>
26315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26316 \begin_inset Text
26317
26318 \begin_layout Standard
26319 0
26320 \end_layout
26321
26322 \end_inset
26323 </cell>
26324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26325 \begin_inset Text
26326
26327 \begin_layout Standard
26328
26329 \family typewriter
26330 \shape slanted
26331 \emph on
26332 uxxxxx xxxxxxxx xxxxxxxx
26333 \end_layout
26334
26335 \end_inset
26336 </cell>
26337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26338 \begin_inset Text
26339
26340 \begin_layout Standard
26341 a 21-bit code pointer in FLASH memory
26342 \end_layout
26343
26344 \end_inset
26345 </cell>
26346 </row>
26347 <row bottomline="true">
26348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26349 \begin_inset Text
26350
26351 \begin_layout Standard
26352 eeprom
26353 \end_layout
26354
26355 \end_inset
26356 </cell>
26357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26358 \begin_inset Text
26359
26360 \begin_layout Standard
26361 0
26362 \end_layout
26363
26364 \end_inset
26365 </cell>
26366 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26367 \begin_inset Text
26368
26369 \begin_layout Standard
26370 1
26371 \end_layout
26372
26373 \end_inset
26374 </cell>
26375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26376 \begin_inset Text
26377
26378 \begin_layout Standard
26379
26380 \family typewriter
26381 \shape slanted
26382 \emph on
26383 uuuuuu uuuuuuxx xxxxxxxx
26384 \end_layout
26385
26386 \end_inset
26387 </cell>
26388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26389 \begin_inset Text
26390
26391 \begin_layout Standard
26392 a 10-bit eeprom pointer in EEPROM memory
26393 \end_layout
26394
26395 \end_inset
26396 </cell>
26397 </row>
26398 <row bottomline="true">
26399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26400 \begin_inset Text
26401
26402 \begin_layout Standard
26403 (unimplemented)
26404 \end_layout
26405
26406 \end_inset
26407 </cell>
26408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26409 \begin_inset Text
26410
26411 \begin_layout Standard
26412 1
26413 \end_layout
26414
26415 \end_inset
26416 </cell>
26417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26418 \begin_inset Text
26419
26420 \begin_layout Standard
26421 1
26422 \end_layout
26423
26424 \end_inset
26425 </cell>
26426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26427 \begin_inset Text
26428
26429 \begin_layout Standard
26430
26431 \family typewriter
26432 \shape slanted
26433 \emph on
26434 xxxxxx xxxxxxxx xxxxxxxx
26435 \end_layout
26436
26437 \end_inset
26438 </cell>
26439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26440 \begin_inset Text
26441
26442 \begin_layout Standard
26443 unimplemented pointer type
26444 \end_layout
26445
26446 \end_inset
26447 </cell>
26448 </row>
26449 </lyxtabular>
26450
26451 \end_inset
26452
26453
26454 \end_layout
26455
26456 \begin_layout Standard
26457 Generic pointer are read and written with a set of library functions which
26458  read/write 1, 2, 3, 4 bytes.
26459 \end_layout
26460
26461 \begin_layout Subsection
26462 PIC16 C Libraries
26463 \end_layout
26464
26465 \begin_layout Subsubsection
26466 Standard I/O Streams
26467 \end_layout
26468
26469 \begin_layout Standard
26470 In the 
26471 \emph on
26472 stdio.h
26473 \emph default
26474  the type FILE is defined as:
26475 \end_layout
26476
26477 \begin_layout LyX-Code
26478 typedef char * FILE;
26479 \end_layout
26480
26481 \begin_layout Standard
26482 This type is the stream type implemented I/O in the PIC18F devices.
26483  Also the standard input and output streams are declared in stdio.h:
26484 \end_layout
26485
26486 \begin_layout LyX-Code
26487 extern FILE * stdin;
26488 \end_layout
26489
26490 \begin_layout LyX-Code
26491 extern FILE * stdout;
26492 \end_layout
26493
26494 \begin_layout Standard
26495 The FILE type is actually a generic pointer which defines one more type
26496  of generic pointers, the 
26497 \emph on
26498 stream 
26499 \emph default
26500 pointer.
26501  This new type has the format:
26502 \end_layout
26503
26504 \begin_layout Standard
26505 \align center
26506 \begin_inset Tabular
26507 <lyxtabular version="3" rows="2" columns="7">
26508 <features>
26509 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26510 <column alignment="center" valignment="top" width="0">
26511 <column alignment="center" valignment="top" leftline="true" width="0">
26512 <column alignment="center" valignment="top" leftline="true" width="0">
26513 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26514 <column alignment="center" valignment="top" width="0">
26515 <column alignment="left" valignment="top" rightline="true" width="0">
26516 <row topline="true" bottomline="true">
26517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26518 \begin_inset Text
26519
26520 \begin_layout Standard
26521 pointer type
26522 \end_layout
26523
26524 \end_inset
26525 </cell>
26526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26527 \begin_inset Text
26528
26529 \begin_layout Standard
26530 <7:6>
26531 \end_layout
26532
26533 \end_inset
26534 </cell>
26535 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26536 \begin_inset Text
26537
26538 \begin_layout Standard
26539 <5>
26540 \end_layout
26541
26542 \end_inset
26543 </cell>
26544 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26545 \begin_inset Text
26546
26547 \begin_layout Standard
26548 <4>
26549 \end_layout
26550
26551 \end_inset
26552 </cell>
26553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26554 \begin_inset Text
26555
26556 \begin_layout Standard
26557 <3:0>
26558 \end_layout
26559
26560 \end_inset
26561 </cell>
26562 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26563 \begin_inset Text
26564
26565 \begin_layout Standard
26566 rest of the pointer
26567 \end_layout
26568
26569 \end_inset
26570 </cell>
26571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26572 \begin_inset Text
26573
26574 \begin_layout Standard
26575 descrption
26576 \end_layout
26577
26578 \end_inset
26579 </cell>
26580 </row>
26581 <row topline="true" bottomline="true">
26582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26583 \begin_inset Text
26584
26585 \begin_layout Standard
26586 stream
26587 \end_layout
26588
26589 \end_inset
26590 </cell>
26591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26592 \begin_inset Text
26593
26594 \begin_layout Standard
26595 00
26596 \end_layout
26597
26598 \end_inset
26599 </cell>
26600 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26601 \begin_inset Text
26602
26603 \begin_layout Standard
26604 1
26605 \end_layout
26606
26607 \end_inset
26608 </cell>
26609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26610 \begin_inset Text
26611
26612 \begin_layout Standard
26613 0
26614 \end_layout
26615
26616 \end_inset
26617 </cell>
26618 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26619 \begin_inset Text
26620
26621 \begin_layout Standard
26622 nnnn
26623 \end_layout
26624
26625 \end_inset
26626 </cell>
26627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26628 \begin_inset Text
26629
26630 \begin_layout Standard
26631
26632 \family typewriter
26633 \shape slanted
26634 \emph on
26635 uuuuuuuu uuuuuuuu
26636 \end_layout
26637
26638 \end_inset
26639 </cell>
26640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26641 \begin_inset Text
26642
26643 \begin_layout Standard
26644 upper byte high nubble is 0x2n, the rest are zeroes
26645 \end_layout
26646
26647 \end_inset
26648 </cell>
26649 </row>
26650 </lyxtabular>
26651
26652 \end_inset
26653
26654
26655 \end_layout
26656
26657 \begin_layout Standard
26658 Currently implemented there are 3 types of streams defined:
26659 \end_layout
26660
26661 \begin_layout Standard
26662 \align center
26663 \begin_inset Tabular
26664 <lyxtabular version="3" rows="4" columns="4">
26665 <features>
26666 <column alignment="center" valignment="top" leftline="true" width="0">
26667 <column alignment="center" valignment="top" leftline="true" width="0">
26668 <column alignment="center" valignment="top" leftline="true" width="0">
26669 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26670 <row topline="true" bottomline="true">
26671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26672 \begin_inset Text
26673
26674 \begin_layout Standard
26675 stream type
26676 \end_layout
26677
26678 \end_inset
26679 </cell>
26680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26681 \begin_inset Text
26682
26683 \begin_layout Standard
26684 value
26685 \end_layout
26686
26687 \end_inset
26688 </cell>
26689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26690 \begin_inset Text
26691
26692 \begin_layout Standard
26693 module
26694 \end_layout
26695
26696 \end_inset
26697 </cell>
26698 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26699 \begin_inset Text
26700
26701 \begin_layout Standard
26702 description
26703 \end_layout
26704
26705 \end_inset
26706 </cell>
26707 </row>
26708 <row topline="true">
26709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26710 \begin_inset Text
26711
26712 \begin_layout Standard
26713 STREAM_USART
26714 \end_layout
26715
26716 \end_inset
26717 </cell>
26718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26719 \begin_inset Text
26720
26721 \begin_layout Standard
26722
26723 \family typewriter
26724 0x200000UL
26725 \end_layout
26726
26727 \end_inset
26728 </cell>
26729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26730 \begin_inset Text
26731
26732 \begin_layout Standard
26733 USART
26734 \end_layout
26735
26736 \end_inset
26737 </cell>
26738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26739 \begin_inset Text
26740
26741 \begin_layout Standard
26742 Writes/Reads characters via the USART peripheral
26743 \end_layout
26744
26745 \end_inset
26746 </cell>
26747 </row>
26748 <row topline="true">
26749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26750 \begin_inset Text
26751
26752 \begin_layout Standard
26753 STREAM_MSSP
26754 \end_layout
26755
26756 \end_inset
26757 </cell>
26758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26759 \begin_inset Text
26760
26761 \begin_layout Standard
26762
26763 \family typewriter
26764 0x210000UL
26765 \end_layout
26766
26767 \end_inset
26768 </cell>
26769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26770 \begin_inset Text
26771
26772 \begin_layout Standard
26773 MSSP
26774 \end_layout
26775
26776 \end_inset
26777 </cell>
26778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26779 \begin_inset Text
26780
26781 \begin_layout Standard
26782 Writes/Reads characters via the MSSP peripheral
26783 \end_layout
26784
26785 \end_inset
26786 </cell>
26787 </row>
26788 <row topline="true" bottomline="true">
26789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26790 \begin_inset Text
26791
26792 \begin_layout Standard
26793 STREAM_USER
26794 \end_layout
26795
26796 \end_inset
26797 </cell>
26798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26799 \begin_inset Text
26800
26801 \begin_layout Standard
26802
26803 \family typewriter
26804 0x2f0000UL
26805 \end_layout
26806
26807 \end_inset
26808 </cell>
26809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26810 \begin_inset Text
26811
26812 \begin_layout Standard
26813 (none)
26814 \end_layout
26815
26816 \end_inset
26817 </cell>
26818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26819 \begin_inset Text
26820
26821 \begin_layout Standard
26822 Writes/Reads characters via used defined functions
26823 \end_layout
26824
26825 \end_inset
26826 </cell>
26827 </row>
26828 </lyxtabular>
26829
26830 \end_inset
26831
26832
26833 \end_layout
26834
26835 \begin_layout Standard
26836 The stream identifiers are declared as macros in the stdio.h header.
26837 \end_layout
26838
26839 \begin_layout Standard
26840 In the libc library there exist the functions that are used to write to
26841  each of the above streams.
26842  These are
26843 \end_layout
26844
26845 \begin_layout Description
26846 _
26847 \begin_inset ERT
26848 status collapsed
26849
26850 \begin_layout Standard
26851
26852
26853 \backslash
26854 /
26855 \end_layout
26856
26857 \end_inset
26858
26859 _stream_usart_putchar writes a character at the USART stream
26860 \end_layout
26861
26862 \begin_layout Description
26863 _
26864 \begin_inset ERT
26865 status collapsed
26866
26867 \begin_layout Standard
26868
26869
26870 \backslash
26871 /
26872 \end_layout
26873
26874 \end_inset
26875
26876 _stream_mssp_putchar writes a character at the MSSP stream
26877 \end_layout
26878
26879 \begin_layout Description
26880 putchar dummy function.
26881  This writes a character to a user specified manner.
26882 \end_layout
26883
26884 \begin_layout Standard
26885 In order to increase performance 
26886 \emph on
26887 putchar 
26888 \emph default
26889 is declared in stdio.h as having its parameter in WREG (it has the wparam
26890  keyword).
26891  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
26892  in a user-friendly way.
26893  
26894 \emph on
26895 arg
26896 \emph default
26897  is the name of the variable that holds the character to print.
26898  An example follows:
26899 \end_layout
26900
26901 \begin_layout LyX-Code
26902 #include <pic18fregs.h>
26903 \newline
26904 #include <stdio.h>
26905 \newline
26906
26907 \newline
26908 PUTCHAR( c )
26909 \end_layout
26910
26911 \begin_layout LyX-Code
26912 {
26913 \end_layout
26914
26915 \begin_layout LyX-Code
26916     PORTA = c;    /* dump character c to PORTA */
26917 \end_layout
26918
26919 \begin_layout LyX-Code
26920
26921 \newline
26922
26923 \newline
26924 void main(void)
26925 \end_layout
26926
26927 \begin_layout LyX-Code
26928 {
26929 \end_layout
26930
26931 \begin_layout LyX-Code
26932     stdout = STREAM_USER;    /* this is not necessary, since stdout points
26933 \end_layout
26934
26935 \begin_layout LyX-Code
26936                               * by default to STREAM_USER */
26937 \end_layout
26938
26939 \begin_layout LyX-Code
26940     printf (
26941 \begin_inset Quotes sld
26942 \end_inset
26943
26944 This is a printf test
26945 \backslash
26946 n
26947 \begin_inset Quotes srd
26948 \end_inset
26949
26950 );
26951 \end_layout
26952
26953 \begin_layout LyX-Code
26954 }
26955 \end_layout
26956
26957 \begin_layout LyX-Code
26958
26959 \end_layout
26960
26961 \begin_layout Subsubsection
26962 Printing functions
26963 \end_layout
26964
26965 \begin_layout Standard
26966 PIC16 contains an implementation of the printf-family of functions.
26967  There exist the following functions:
26968 \end_layout
26969
26970 \begin_layout LyX-Code
26971 extern unsigned int sprintf(char *buf, char *fmt, ...);
26972 \end_layout
26973
26974 \begin_layout LyX-Code
26975 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
26976 \end_layout
26977
26978 \begin_layout LyX-Code
26979
26980 \end_layout
26981
26982 \begin_layout LyX-Code
26983 extern unsigned int printf(char *fmt, ...);
26984 \end_layout
26985
26986 \begin_layout LyX-Code
26987 extern unsigned int vprintf(char *fmt, va_lista ap);
26988 \end_layout
26989
26990 \begin_layout LyX-Code
26991
26992 \end_layout
26993
26994 \begin_layout LyX-Code
26995 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
26996 \end_layout
26997
26998 \begin_layout LyX-Code
26999 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
27000 \end_layout
27001
27002 \begin_layout Standard
27003 For sprintf and vsprintf 
27004 \emph on
27005 buf 
27006 \emph default
27007 should normally be a data pointer where the resulting string will be placed.
27008  No range checking is done so the user should allocate the necessery buffer.
27009  For fprintf and vfprintf 
27010 \emph on
27011 fp
27012 \emph default
27013  should be a stream pointer (i.e.
27014  stdout, STREAM_MSSP, etc...).
27015 \end_layout
27016
27017 \begin_layout Subsubsection
27018 Signals
27019 \end_layout
27020
27021 \begin_layout Standard
27022 The PIC18F family of microcontrollers supports a number of interrupt sources.
27023  A list of these interrupts is shown in the following table:
27024 \end_layout
27025
27026 \begin_layout Standard
27027 \align center
27028 \begin_inset Tabular
27029 <lyxtabular version="3" rows="11" columns="4">
27030 <features>
27031 <column alignment="left" valignment="top" leftline="true" width="0">
27032 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27033 <column alignment="left" valignment="top" leftline="true" width="0">
27034 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27035 <row topline="true" bottomline="true">
27036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27037 \begin_inset Text
27038
27039 \begin_layout Standard
27040 signal name
27041 \end_layout
27042
27043 \end_inset
27044 </cell>
27045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27046 \begin_inset Text
27047
27048 \begin_layout Standard
27049 description
27050 \end_layout
27051
27052 \end_inset
27053 </cell>
27054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27055 \begin_inset Text
27056
27057 \begin_layout Standard
27058 signal name
27059 \end_layout
27060
27061 \end_inset
27062 </cell>
27063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27064 \begin_inset Text
27065
27066 \begin_layout Standard
27067 descritpion
27068 \end_layout
27069
27070 \end_inset
27071 </cell>
27072 </row>
27073 <row topline="true">
27074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27075 \begin_inset Text
27076
27077 \begin_layout Standard
27078 SIG_RB
27079 \end_layout
27080
27081 \end_inset
27082 </cell>
27083 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27084 \begin_inset Text
27085
27086 \begin_layout Standard
27087 PORTB change interrupt
27088 \end_layout
27089
27090 \end_inset
27091 </cell>
27092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27093 \begin_inset Text
27094
27095 \begin_layout Standard
27096 SIG_EE
27097 \end_layout
27098
27099 \end_inset
27100 </cell>
27101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27102 \begin_inset Text
27103
27104 \begin_layout Standard
27105 EEPROM/FLASH write complete interrupt
27106 \end_layout
27107
27108 \end_inset
27109 </cell>
27110 </row>
27111 <row topline="true">
27112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27113 \begin_inset Text
27114
27115 \begin_layout Standard
27116 SIG_INT0
27117 \end_layout
27118
27119 \end_inset
27120 </cell>
27121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27122 \begin_inset Text
27123
27124 \begin_layout Standard
27125 INT0 external interrupt
27126 \end_layout
27127
27128 \end_inset
27129 </cell>
27130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27131 \begin_inset Text
27132
27133 \begin_layout Standard
27134 SIG_BCOL
27135 \end_layout
27136
27137 \end_inset
27138 </cell>
27139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27140 \begin_inset Text
27141
27142 \begin_layout Standard
27143 Bus collision interrupt
27144 \end_layout
27145
27146 \end_inset
27147 </cell>
27148 </row>
27149 <row topline="true">
27150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27151 \begin_inset Text
27152
27153 \begin_layout Standard
27154 SIG_INT1
27155 \end_layout
27156
27157 \end_inset
27158 </cell>
27159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27160 \begin_inset Text
27161
27162 \begin_layout Standard
27163 INT1 external interrupt
27164 \end_layout
27165
27166 \end_inset
27167 </cell>
27168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27169 \begin_inset Text
27170
27171 \begin_layout Standard
27172 SIG_LVD
27173 \end_layout
27174
27175 \end_inset
27176 </cell>
27177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27178 \begin_inset Text
27179
27180 \begin_layout Standard
27181 Low voltage detect interrupt
27182 \end_layout
27183
27184 \end_inset
27185 </cell>
27186 </row>
27187 <row topline="true">
27188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27189 \begin_inset Text
27190
27191 \begin_layout Standard
27192 SIG_INT2
27193 \end_layout
27194
27195 \end_inset
27196 </cell>
27197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27198 \begin_inset Text
27199
27200 \begin_layout Standard
27201 INT2 external interrupt
27202 \end_layout
27203
27204 \end_inset
27205 </cell>
27206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27207 \begin_inset Text
27208
27209 \begin_layout Standard
27210 SIG_PSP
27211 \end_layout
27212
27213 \end_inset
27214 </cell>
27215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27216 \begin_inset Text
27217
27218 \begin_layout Standard
27219 Parallel slave port interrupt
27220 \end_layout
27221
27222 \end_inset
27223 </cell>
27224 </row>
27225 <row topline="true">
27226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27227 \begin_inset Text
27228
27229 \begin_layout Standard
27230 SIG_CCP1
27231 \end_layout
27232
27233 \end_inset
27234 </cell>
27235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27236 \begin_inset Text
27237
27238 \begin_layout Standard
27239 CCP1 module interrupt
27240 \end_layout
27241
27242 \end_inset
27243 </cell>
27244 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27245 \begin_inset Text
27246
27247 \begin_layout Standard
27248 SIG_AD
27249 \end_layout
27250
27251 \end_inset
27252 </cell>
27253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27254 \begin_inset Text
27255
27256 \begin_layout Standard
27257 AD convertion complete interrupt
27258 \end_layout
27259
27260 \end_inset
27261 </cell>
27262 </row>
27263 <row topline="true">
27264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27265 \begin_inset Text
27266
27267 \begin_layout Standard
27268 SIG_CCP2
27269 \end_layout
27270
27271 \end_inset
27272 </cell>
27273 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27274 \begin_inset Text
27275
27276 \begin_layout Standard
27277 CCP2 module interrupt
27278 \end_layout
27279
27280 \end_inset
27281 </cell>
27282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27283 \begin_inset Text
27284
27285 \begin_layout Standard
27286 SIG_RC
27287 \end_layout
27288
27289 \end_inset
27290 </cell>
27291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27292 \begin_inset Text
27293
27294 \begin_layout Standard
27295 USART receive interrupt
27296 \end_layout
27297
27298 \end_inset
27299 </cell>
27300 </row>
27301 <row topline="true">
27302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27303 \begin_inset Text
27304
27305 \begin_layout Standard
27306 SIG_TMR0
27307 \end_layout
27308
27309 \end_inset
27310 </cell>
27311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27312 \begin_inset Text
27313
27314 \begin_layout Standard
27315 TMR0 overflow interrupt
27316 \end_layout
27317
27318 \end_inset
27319 </cell>
27320 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27321 \begin_inset Text
27322
27323 \begin_layout Standard
27324 SIG_TX
27325 \end_layout
27326
27327 \end_inset
27328 </cell>
27329 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27330 \begin_inset Text
27331
27332 \begin_layout Standard
27333 USART transmit interrupt
27334 \end_layout
27335
27336 \end_inset
27337 </cell>
27338 </row>
27339 <row topline="true">
27340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27341 \begin_inset Text
27342
27343 \begin_layout Standard
27344 SIG_TMR1
27345 \end_layout
27346
27347 \end_inset
27348 </cell>
27349 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27350 \begin_inset Text
27351
27352 \begin_layout Standard
27353 TMR1 overflow interrupt
27354 \end_layout
27355
27356 \end_inset
27357 </cell>
27358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27359 \begin_inset Text
27360
27361 \begin_layout Standard
27362 SIG_MSSP
27363 \end_layout
27364
27365 \end_inset
27366 </cell>
27367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27368 \begin_inset Text
27369
27370 \begin_layout Standard
27371 SSP receive/transmit interrupt
27372 \end_layout
27373
27374 \end_inset
27375 </cell>
27376 </row>
27377 <row topline="true">
27378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27379 \begin_inset Text
27380
27381 \begin_layout Standard
27382 SIG_TMR2
27383 \end_layout
27384
27385 \end_inset
27386 </cell>
27387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27388 \begin_inset Text
27389
27390 \begin_layout Standard
27391 TMR2 matches PR2 interrupt
27392 \end_layout
27393
27394 \end_inset
27395 </cell>
27396 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27397 \begin_inset Text
27398
27399 \begin_layout Standard
27400
27401 \end_layout
27402
27403 \end_inset
27404 </cell>
27405 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27406 \begin_inset Text
27407
27408 \begin_layout Standard
27409
27410 \end_layout
27411
27412 \end_inset
27413 </cell>
27414 </row>
27415 <row topline="true" bottomline="true">
27416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27417 \begin_inset Text
27418
27419 \begin_layout Standard
27420 SIG_TMR3
27421 \end_layout
27422
27423 \end_inset
27424 </cell>
27425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27426 \begin_inset Text
27427
27428 \begin_layout Standard
27429 TMR3 overflow interrupt
27430 \end_layout
27431
27432 \end_inset
27433 </cell>
27434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27435 \begin_inset Text
27436
27437 \begin_layout Standard
27438
27439 \end_layout
27440
27441 \end_inset
27442 </cell>
27443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27444 \begin_inset Text
27445
27446 \begin_layout Standard
27447
27448 \end_layout
27449
27450 \end_inset
27451 </cell>
27452 </row>
27453 </lyxtabular>
27454
27455 \end_inset
27456
27457
27458 \end_layout
27459
27460 \begin_layout Standard
27461 The prototypes for these names are defined in the header file 
27462 \emph on
27463 signal.h
27464 \emph default
27465  .
27466 \end_layout
27467
27468 \begin_layout Standard
27469 In order to simplify signal handling, a number of macros is provided:
27470 \end_layout
27471
27472 \begin_layout List
27473 \labelwidthstring 00.00.0000
27474 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27475  high priority interrupts.
27476  
27477 \emph on
27478 name
27479 \emph default
27480  is the function name to use.
27481 \end_layout
27482
27483 \begin_layout List
27484 \labelwidthstring 00.00.0000
27485 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27486  low priority interrupt.
27487  
27488 \emph on
27489 name
27490 \emph default
27491  is the function name to use.
27492 \end_layout
27493
27494 \begin_layout List
27495 \labelwidthstring 00.00.0000
27496 DEF_HANDLER(sig,handler) define a handler for signal 
27497 \emph on
27498 sig.
27499 \end_layout
27500
27501 \begin_layout List
27502 \labelwidthstring 00.00.0000
27503 END_DEF end the declaration of the dispatch table.
27504 \end_layout
27505
27506 \begin_layout Standard
27507 Additionally there are two more macros to simplify the declaration of the
27508  signal handler:
27509 \end_layout
27510
27511 \begin_layout List
27512 \labelwidthstring 00.00.0000
27513
27514 \series medium
27515 SIGHANDLER(handler) 
27516 \series default
27517 this declares the function prototype for the 
27518 \emph on
27519 handler
27520 \emph default
27521  function.
27522 \end_layout
27523
27524 \begin_layout List
27525 \labelwidthstring 00.00.0000
27526 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27527 \end_layout
27528
27529 \begin_layout Standard
27530 An example of using the macros above is shown below:
27531 \end_layout
27532
27533 \begin_layout LyX-Code
27534 #include <pic18fregs.h>
27535 \end_layout
27536
27537 \begin_layout LyX-Code
27538 #include <signal.h>
27539 \newline
27540
27541 \newline
27542 DEF_INTHIGH(high_int)
27543 \end_layout
27544
27545 \begin_layout LyX-Code
27546 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27547 \end_layout
27548
27549 \begin_layout LyX-Code
27550 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27551 \end_layout
27552
27553 \begin_layout LyX-Code
27554 END_DEF
27555 \newline
27556
27557 \newline
27558 SIGHANDLER(_tmr0_handler)
27559 \end_layout
27560
27561 \begin_layout LyX-Code
27562 {
27563 \end_layout
27564
27565 \begin_layout LyX-Code
27566   /* action to be taken when timer 0 overflows */
27567 \end_layout
27568
27569 \begin_layout LyX-Code
27570 }
27571 \newline
27572
27573 \newline
27574 SIGHANDLERNAKED(_bcol_handler)
27575 \end_layout
27576
27577 \begin_layout LyX-Code
27578 {
27579 \end_layout
27580
27581 \begin_layout LyX-Code
27582   _asm
27583 \end_layout
27584
27585 \begin_layout LyX-Code
27586     /* action to be taken when bus collision occurs */
27587 \end_layout
27588
27589 \begin_layout LyX-Code
27590     retfie
27591 \end_layout
27592
27593 \begin_layout LyX-Code
27594  _endasm;
27595 \end_layout
27596
27597 \begin_layout LyX-Code
27598 }
27599 \end_layout
27600
27601 \begin_layout Standard
27602
27603 \series bold
27604 NOTES:
27605 \series default
27606  Special care should be taken when using the above scheme:
27607 \end_layout
27608
27609 \begin_layout Itemize
27610 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27611 \end_layout
27612
27613 \begin_layout Itemize
27614 when declaring SIGHANDLERNAKED handler never forget to use 
27615 \emph on
27616 retfie
27617 \emph default
27618  for proper returning.
27619 \end_layout
27620
27621 \begin_layout Subsection
27622 PIC16 Port -- Tips
27623 \end_layout
27624
27625 \begin_layout Standard
27626 Here you can find some general tips for compiling programs with SDCC/pic16.
27627 \end_layout
27628
27629 \begin_layout Subsubsection
27630 Stack size
27631 \end_layout
27632
27633 \begin_layout Standard
27634 The default stack
27635 \begin_inset LatexCommand \index{PIC16!stack}
27636
27637 \end_inset
27638
27639  size (that is 64 bytes) probably is enough for many programs.
27640  One must take care that when there are many levels of function nesting,
27641  or there is excessive usage of stack, its size should be extended.
27642  An example of such a case is the printf/sprintf family of functions.
27643  If you encounter problems like not being able to print integers, then you
27644  need to set the stack size around the maximum (256 for small stack model).
27645  The following diagram shows what happens when calling printf to print an
27646  integer:
27647 \end_layout
27648
27649 \begin_layout LyX-Code
27650 printf () --> ltoa () --> ultoa () --> divschar ()
27651 \end_layout
27652
27653 \begin_layout Standard
27654 It is should be understood that stack is easily consumed when calling complicate
27655 d functions.
27656  Using command line arguments like -
27657 \begin_inset ERT
27658 status collapsed
27659
27660 \begin_layout Standard
27661
27662
27663 \backslash
27664 /
27665 \end_layout
27666
27667 \end_inset
27668
27669 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27670  stack frames.
27671  Other ways to reduce stack usage may exist.
27672 \end_layout
27673
27674 \begin_layout Subsection
27675 Known Bugs
27676 \end_layout
27677
27678 \begin_layout Standard
27679 The PIC16 Port currently does not pass SDCC's regression test
27680 \begin_inset LatexCommand \index{Regression test (PIC16)}
27681
27682 \end_inset
27683
27684  suite (see section 
27685 \begin_inset LatexCommand \ref{sec:Quality-control}
27686
27687 \end_inset
27688
27689 ) and thus the snapshot build regression tests for the PIC16 target are
27690  currently disabled for all hosts
27691 \emph on
27692 .
27693 \end_layout
27694
27695 \begin_layout Chapter
27696 Debugging
27697 \end_layout
27698
27699 \begin_layout Standard
27700 There are several approaches to debugging your code.
27701  This chapter is meant to show your options and to give detail on some of
27702  them:
27703 \newline
27704
27705 \newline
27706 When writing your code:
27707 \end_layout
27708
27709 \begin_layout Itemize
27710 write your code with debugging in mind (avoid duplicating code, put conceptually
27711  similar variables into structs, use structured code, have strategic points
27712  within your code where all variables are consistent, ...)
27713 \end_layout
27714
27715 \begin_layout Itemize
27716 run a syntax-checking tool like splint
27717 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27718
27719 \end_inset
27720
27721
27722 \begin_inset LatexCommand \index{lint (syntax checking tool)}
27723
27724 \end_inset
27725
27726  (see -
27727 \begin_inset ERT
27728 status collapsed
27729
27730 \begin_layout Standard
27731
27732
27733 \backslash
27734 /
27735 \end_layout
27736
27737 \end_inset
27738
27739 -more-pedantic 
27740 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27741
27742 \end_inset
27743
27744 ) over the code.
27745 \end_layout
27746
27747 \begin_layout Itemize
27748 for the high level code use a C-compiler (like f.e.
27749  GCC) to compile run and debug the code on your host.
27750  See (see -
27751 \begin_inset ERT
27752 status collapsed
27753
27754 \begin_layout Standard
27755
27756
27757 \backslash
27758 /
27759 \end_layout
27760
27761 \end_inset
27762
27763 -more-pedantic 
27764 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27765
27766 \end_inset
27767
27768 ) on how to handle syntax extensions like __xdata, __at(), ...
27769  
27770 \end_layout
27771
27772 \begin_layout Itemize
27773 use another C-compiler to compile code for your target.
27774  Always an option but not recommended:) And not very likely to help you.
27775  If you seriously consider walking this path you should at least occasionally
27776  check portability of your code.
27777  Most commercial compiler vendors will offer an evaluation version so you
27778  can test compile your code or snippets of your code.
27779 \end_layout
27780
27781 \begin_layout Standard
27782 Debugging on a simulator:
27783 \end_layout
27784
27785 \begin_layout Itemize
27786 there is a separate section about SDCDB (section 
27787 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
27788
27789 \end_inset
27790
27791 ) below.
27792 \end_layout
27793
27794 \begin_layout Itemize
27795 or (8051 specific) use a freeware/commercial simulator which interfaces
27796  to the AOMF
27797 \begin_inset LatexCommand \index{AOMF, AOMF51}
27798
27799 \end_inset
27800
27801  file (see 
27802 \begin_inset LatexCommand \ref{OMF file}
27803
27804 \end_inset
27805
27806 ) optionally generated by SDCC.
27807 \end_layout
27808
27809 \begin_layout Standard
27810 Debugging On-target: 
27811 \end_layout
27812
27813 \begin_layout Itemize
27814 use a MCU port pin to serially output debug data to the RS232 port of your
27815  host.
27816  You'll probably want some level shifting device typically involving a MAX232
27817  or similar IC.
27818  If the hardware serial port of the MCU is not available search for 'Software
27819  UART' in your favourite search machine.
27820 \end_layout
27821
27822 \begin_layout Itemize
27823 use an on-target monitor.
27824  In this context a monitor is a small program which usually accepts commands
27825  via a serial line and allows to set program counter, to single step through
27826  a program and read/write memory locations.
27827  For the 8051 good examples of monitors are paulmon and cmon51 (see section
27828  
27829 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
27830
27831 \end_inset
27832
27833 ).
27834 \end_layout
27835
27836 \begin_layout Itemize
27837 toggle MCU port pins at strategic points within your code and use an oscilloscop
27838 e.
27839  A 
27840 \emph on
27841 digital oscilloscope
27842 \emph default
27843
27844 \begin_inset LatexCommand \index{Oscilloscope}
27845
27846 \end_inset
27847
27848  with deep trace memory is really helpful especially if you have to debug
27849  a realtime application.
27850  If you need to monitor more pins than your oscilloscope provides you can
27851  sometimes get away with a small R-2R network.
27852  On a single channel oscilloscope you could f.e.
27853  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
27854 k
27855 \begin_inset Formula $\Omega$
27856 \end_inset
27857
27858  resistor and the other one by a 5\InsetSpace ~
27859 k
27860 \begin_inset Formula $\Omega$
27861 \end_inset
27862
27863  resistor to the oscilloscope probe (check output drive capability of the
27864  pins you want to monitor).
27865  If you need to monitor many more pins a 
27866 \emph on
27867 logic analyzer
27868 \emph default
27869  will be handy.
27870 \end_layout
27871
27872 \begin_layout Itemize
27873 use an ICE (
27874 \emph on
27875 i
27876 \emph default
27877
27878 \emph on
27879 c
27880 \emph default
27881 ircuit 
27882 \emph on
27883 e
27884 \emph default
27885 mulator
27886 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
27887
27888 \end_inset
27889
27890 ).
27891  Usually very expensive.
27892  And very nice to have too.
27893  And usually locks you (for years...) to the devices the ICE can emulate.
27894  
27895 \end_layout
27896
27897 \begin_layout Itemize
27898 use a remote debugger.
27899  In most 8-bit systems the symbol information is not available on the target,
27900  and a complete debugger is too bulky for the target system.
27901  Therefore usually a debugger on the host system connects to an on-target
27902  debugging stub which accepts only primitive commands.
27903  
27904 \newline
27905 Terms to enter into your favourite search engine could be 'remote debugging',
27906  'gdb stub' or 'inferior debugger'.
27907  (is there one?)
27908 \end_layout
27909
27910 \begin_layout Itemize
27911 use an on target hardware debugger.
27912  Some of the more modern MCUs include hardware support for setting break
27913  points and monitoring/changing variables by using dedicated hardware pins.
27914  This facility doesn't require additional code to run on the target and
27915  
27916 \emph on
27917 usually
27918 \emph default
27919  doesn't affect runtime behaviour until a breakpoint is hit.
27920  For the mcs51 most hardware debuggers use the AOMF
27921 \begin_inset LatexCommand \index{AOMF, AOMF51}
27922
27923 \end_inset
27924
27925  file (see 
27926 \begin_inset LatexCommand \ref{OMF file}
27927
27928 \end_inset
27929
27930 ) as input file.
27931  
27932 \end_layout
27933
27934 \begin_layout Standard
27935 Last not least:
27936 \end_layout
27937
27938 \begin_layout Itemize
27939 if you are not familiar with any of the following terms you're likely to
27940  run into problems rather sooner than later: 
27941 \emph on
27942 volatile
27943 \emph default
27944
27945 \emph on
27946 atomic
27947 \emph default
27948
27949 \emph on
27950 memory map
27951 \emph default
27952
27953 \emph on
27954 overlay
27955 \emph default
27956 .
27957  As an embedded programmer you 
27958 \emph on
27959 have
27960 \emph default
27961  to know them so why not look them up 
27962 \emph on
27963 before
27964 \emph default
27965  you have problems?)
27966 \end_layout
27967
27968 \begin_layout Itemize
27969 tell someone else about your problem (actually this is a surprisingly effective
27970  means to hunt down the bug even if the listener is not familiar with your
27971  environment).
27972  As 'failure to communicate' is probably one of the job-induced deformations
27973  of an embedded programmer this is highly encouraged.
27974 \end_layout
27975
27976 \begin_layout Section
27977 Debugging with SDCDB
27978 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
27979
27980 \end_inset
27981
27982
27983 \begin_inset LatexCommand \index{SDCDB (debugger)}
27984
27985 \end_inset
27986
27987  
27988 \end_layout
27989
27990 \begin_layout Standard
27991 SDCC is distributed with a source level debugger
27992 \begin_inset LatexCommand \index{Debugger}
27993
27994 \end_inset
27995
27996 .
27997  The debugger uses a command line interface, the command repertoire of the
27998  debugger has been kept as close to gdb
27999 \begin_inset LatexCommand \index{gdb}
28000
28001 \end_inset
28002
28003  (the GNU debugger) as possible.
28004  The configuration and build process is part of the standard compiler installati
28005 on, which also builds and installs the debugger in the target directory
28006  specified during configuration.
28007  The debugger allows you debug BOTH at the C source and at the ASM source
28008  level.
28009 \end_layout
28010
28011 \begin_layout Subsection
28012 Compiling for Debugging
28013 \end_layout
28014
28015 \begin_layout Standard
28016 The -
28017 \begin_inset ERT
28018 status collapsed
28019
28020 \begin_layout Standard
28021
28022
28023 \backslash
28024 /
28025 \end_layout
28026
28027 \end_inset
28028
28029 -debug
28030 \begin_inset LatexCommand \index{-\/-debug}
28031
28032 \end_inset
28033
28034  option must be specified for all files for which debug information is to
28035  be generated.
28036  The compiler generates a .adb file for each of these files.
28037  The linker creates the .cdb
28038 \begin_inset LatexCommand \index{<file>.cdb}
28039
28040 \end_inset
28041
28042  file from the .adb
28043 \begin_inset LatexCommand \index{<file>.adb}
28044
28045 \end_inset
28046
28047  files and the address information.
28048  This .cdb is used by the debugger.
28049 \end_layout
28050
28051 \begin_layout Subsection
28052 How the Debugger Works
28053 \end_layout
28054
28055 \begin_layout Standard
28056 When the -
28057 \begin_inset ERT
28058 status collapsed
28059
28060 \begin_layout Standard
28061
28062
28063 \backslash
28064 /
28065 \end_layout
28066
28067 \end_inset
28068
28069 -debug option is specified the compiler generates extra symbol information
28070  some of which are put into the assembler source and some are put into the
28071  .adb file.
28072  Then the linker creates the .cdb file from the individual .adb files with
28073  the address information for the symbols.
28074  The debugger reads the symbolic information generated by the compiler &
28075  the address information generated by the linker.
28076  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
28077  execution is controlled by the debugger.
28078  When a command is issued for the debugger, it translates it into appropriate
28079  commands for the simulator.
28080  (Currently SDCDM only connects to the simulator but 
28081 \emph on
28082 newcdb
28083 \emph default
28084  at 
28085 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
28086
28087 \end_inset
28088
28089  is an effort to connect directly to the hardware.) 
28090 \end_layout
28091
28092 \begin_layout Subsection
28093 Starting the Debugger SDCDB
28094 \end_layout
28095
28096 \begin_layout Standard
28097 The debugger can be started using the following command line.
28098  (Assume the file you are debugging has the file name foo).
28099 \newline
28100
28101 \newline
28102
28103 \family sans
28104 \series bold
28105 sdcdb foo
28106 \newline
28107
28108 \family default
28109 \series default
28110
28111 \newline
28112 The debugger will look for the following files.
28113 \end_layout
28114
28115 \begin_layout Itemize
28116 foo.c - the source file.
28117 \end_layout
28118
28119 \begin_layout Itemize
28120 foo.cdb - the debugger symbol information file.
28121 \end_layout
28122
28123 \begin_layout Itemize
28124 foo.ihx - the Intel hex format
28125 \begin_inset LatexCommand \index{Intel hex format}
28126
28127 \end_inset
28128
28129  object file.
28130 \end_layout
28131
28132 \begin_layout Subsection
28133 SDCDB Command Line Options
28134 \end_layout
28135
28136 \begin_layout Itemize
28137 -
28138 \begin_inset ERT
28139 status collapsed
28140
28141 \begin_layout Standard
28142
28143
28144 \backslash
28145 /
28146 \end_layout
28147
28148 \end_inset
28149
28150 -directory=<source file directory> this option can used to specify the directory
28151  search list.
28152  The debugger will look into the directory list specified for source, cdb
28153  & ihx files.
28154  The items in the directory list must be separated by ':', e.g.
28155  if the source files can be in the directories /home/src1 and /home/src2,
28156  the -
28157 \begin_inset ERT
28158 status collapsed
28159
28160 \begin_layout Standard
28161
28162
28163 \backslash
28164 /
28165 \end_layout
28166
28167 \end_inset
28168
28169 -directory option should be -
28170 \begin_inset ERT
28171 status collapsed
28172
28173 \begin_layout Standard
28174
28175
28176 \backslash
28177 /
28178 \end_layout
28179
28180 \end_inset
28181
28182 -directory=/home/src1:/home/src2.
28183  Note there can be no spaces in the option.
28184  
28185 \end_layout
28186
28187 \begin_layout Itemize
28188 -cd <directory> - change to the <directory>.
28189 \end_layout
28190
28191 \begin_layout Itemize
28192 -fullname - used by GUI front ends.
28193 \end_layout
28194
28195 \begin_layout Itemize
28196 -cpu <cpu-type> - this argument is passed to the simulator please see the
28197  simulator docs for details.
28198 \end_layout
28199
28200 \begin_layout Itemize
28201 -X <Clock frequency > this options is passed to the simulator please see
28202  the simulator docs for details.
28203 \end_layout
28204
28205 \begin_layout Itemize
28206 -s <serial port file> passed to simulator see the simulator docs for details.
28207 \end_layout
28208
28209 \begin_layout Itemize
28210 -S <serial in,out> passed to simulator see the simulator docs for details.
28211 \end_layout
28212
28213 \begin_layout Itemize
28214 -k <port number> passed to simulator see the simulator docs for details.
28215 \end_layout
28216
28217 \begin_layout Subsection
28218 SDCDB Debugger Commands
28219 \end_layout
28220
28221 \begin_layout Standard
28222 As mentioned earlier the command interface for the debugger has been deliberatel
28223 y kept as close the GNU debugger gdb, as possible.
28224  This will help the integration with existing graphical user interfaces
28225  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
28226  If you use a graphical user interface for the debugger you can skip this
28227  section.
28228 \end_layout
28229
28230 \begin_layout Subsubsection*
28231 break [line | file:line | function | file:function]
28232 \end_layout
28233
28234 \begin_layout Standard
28235 Set breakpoint at specified line or function:
28236 \newline
28237
28238 \newline
28239
28240 \family sans
28241 \series bold
28242 sdcdb>break 100 
28243 \newline
28244 sdcdb>break foo.c:100
28245 \newline
28246 sdcdb>break funcfoo
28247 \newline
28248 sdcdb>break foo.c:funcfoo
28249 \end_layout
28250
28251 \begin_layout Subsubsection*
28252 clear [line | file:line | function | file:function ]
28253 \end_layout
28254
28255 \begin_layout Standard
28256 Clear breakpoint at specified line or function:
28257 \newline
28258
28259 \newline
28260
28261 \family sans
28262 \series bold
28263 sdcdb>clear 100
28264 \newline
28265 sdcdb>clear foo.c:100
28266 \newline
28267 sdcdb>clear funcfoo
28268 \newline
28269 sdcdb>clear foo.c:funcfoo
28270 \end_layout
28271
28272 \begin_layout Subsubsection*
28273 continue
28274 \end_layout
28275
28276 \begin_layout Standard
28277 Continue program being debugged, after breakpoint.
28278 \end_layout
28279
28280 \begin_layout Subsubsection*
28281 finish
28282 \end_layout
28283
28284 \begin_layout Standard
28285 Execute till the end of the current function.
28286 \end_layout
28287
28288 \begin_layout Subsubsection*
28289 delete [n]
28290 \end_layout
28291
28292 \begin_layout Standard
28293 Delete breakpoint number 'n'.
28294  If used without any option clear ALL user defined break points.
28295 \end_layout
28296
28297 \begin_layout Subsubsection*
28298 info [break | stack | frame | registers ]
28299 \end_layout
28300
28301 \begin_layout Itemize
28302 info break - list all breakpoints
28303 \end_layout
28304
28305 \begin_layout Itemize
28306 info stack - show the function call stack.
28307 \end_layout
28308
28309 \begin_layout Itemize
28310 info frame - show information about the current execution frame.
28311 \end_layout
28312
28313 \begin_layout Itemize
28314 info registers - show content of all registers.
28315 \end_layout
28316
28317 \begin_layout Subsubsection*
28318 step
28319 \end_layout
28320
28321 \begin_layout Standard
28322 Step program until it reaches a different source line.
28323  Note: pressing <return> repeats the last command.
28324 \end_layout
28325
28326 \begin_layout Subsubsection*
28327 next
28328 \end_layout
28329
28330 \begin_layout Standard
28331 Step program, proceeding through subroutine calls.
28332 \end_layout
28333
28334 \begin_layout Subsubsection*
28335 run
28336 \end_layout
28337
28338 \begin_layout Standard
28339 Start debugged program.
28340 \end_layout
28341
28342 \begin_layout Subsubsection*
28343 ptype variable 
28344 \end_layout
28345
28346 \begin_layout Standard
28347 Print type information of the variable.
28348 \end_layout
28349
28350 \begin_layout Subsubsection*
28351 print variable
28352 \end_layout
28353
28354 \begin_layout Standard
28355 print value of variable.
28356 \end_layout
28357
28358 \begin_layout Subsubsection*
28359 file filename
28360 \end_layout
28361
28362 \begin_layout Standard
28363 load the given file name.
28364  Note this is an alternate method of loading file for debugging.
28365 \end_layout
28366
28367 \begin_layout Subsubsection*
28368 frame
28369 \end_layout
28370
28371 \begin_layout Standard
28372 print information about current frame.
28373 \end_layout
28374
28375 \begin_layout Subsubsection*
28376 set srcmode
28377 \end_layout
28378
28379 \begin_layout Standard
28380 Toggle between C source & assembly source.
28381 \end_layout
28382
28383 \begin_layout Subsubsection*
28384 ! simulator command
28385 \end_layout
28386
28387 \begin_layout Standard
28388 Send the string following '!' to the simulator, the simulator response is
28389  displayed.
28390  Note the debugger does not interpret the command being sent to the simulator,
28391  so if a command like 'go' is sent the debugger can loose its execution
28392  context and may display incorrect values.
28393 \end_layout
28394
28395 \begin_layout Subsubsection*
28396 quit
28397 \end_layout
28398
28399 \begin_layout Standard
28400 "Watch me now.
28401  Iam going Down.
28402  My name is Bobby Brown"
28403 \end_layout
28404
28405 \begin_layout Subsection
28406 Interfacing SDCDB with DDD
28407 \end_layout
28408
28409 \begin_layout Standard
28410 \begin_inset Note Note
28411 status collapsed
28412
28413 \begin_layout Standard
28414 The screenshot was converted from png to eps with: 
28415 \begin_inset Quotes sld
28416 \end_inset
28417
28418 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28419 \begin_inset Quotes srd
28420 \end_inset
28421
28422  which produces a pretty compact eps file which is free from compression
28423  artifacts.
28424 \end_layout
28425
28426 \begin_layout Standard
28427 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28428  as this broke the build system on Sourceforge (pdf-file was broken.
28429  pdflatex does not accept eps files).
28430 \end_layout
28431
28432 \end_inset
28433
28434
28435 \end_layout
28436
28437 \begin_layout Standard
28438 The 
28439 \emph on
28440 p
28441 \emph default
28442 ortable 
28443 \emph on
28444 n
28445 \emph default
28446 etwork 
28447 \emph on
28448 g
28449 \emph default
28450 raphics File 
28451 \size footnotesize
28452
28453 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28454
28455 \end_inset
28456
28457
28458 \size default
28459  shows a screenshot of a debugging session with DDD
28460 \begin_inset LatexCommand \index{DDD (debugger)}
28461
28462 \end_inset
28463
28464  (Unix only) on a simulated 8032.
28465  The debugging session might not run as smoothly as the screenshot suggests.
28466  The debugger allows setting of breakpoints, displaying and changing variables,
28467  single stepping through C and assembler code.
28468  
28469 \newline
28470 The source was compiled with 
28471 \family sans
28472 \series bold
28473
28474 \newline
28475
28476 \newline
28477 sdcc -
28478 \family default
28479 \series default
28480
28481 \begin_inset ERT
28482 status collapsed
28483
28484 \begin_layout Standard
28485
28486
28487 \backslash
28488 /
28489 \end_layout
28490
28491 \end_inset
28492
28493
28494 \family sans
28495 \series bold
28496 -debug ddd_example.c
28497 \family default
28498 \series default
28499  
28500 \family sans
28501 \series bold
28502
28503 \newline
28504
28505 \family default
28506 \series default
28507
28508 \newline
28509 and DDD was invoked with 
28510 \family sans
28511 \series bold
28512
28513 \newline
28514
28515 \newline
28516 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28517 \end_layout
28518
28519 \begin_layout Standard
28520 \begin_inset Note Note
28521 status open
28522
28523 \begin_layout Standard
28524 Check that the double quotes or an apostroph within the command line survive
28525  the LyX tool chain.
28526  Previously the apostrophs got slanted in the PDF output so a cut and paste
28527  did not work.
28528 \end_layout
28529
28530 \end_inset
28531
28532
28533 \end_layout
28534
28535 \begin_layout Subsection
28536 Interfacing SDCDB with XEmacs
28537 \begin_inset LatexCommand \index{XEmacs}
28538
28539 \end_inset
28540
28541
28542 \begin_inset LatexCommand \index{Emacs}
28543
28544 \end_inset
28545
28546
28547 \end_layout
28548
28549 \begin_layout Standard
28550 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28551  sdcdb.el and sdcdbsrc.el.
28552  These two files can be found in the $(prefix)/bin directory after the installat
28553 ion is complete.
28554  These files need to be loaded into XEmacs for the interface to work.
28555  This can be done at XEmacs startup time by inserting the following into
28556  your '.xemacs' file (which can be found in your HOME directory): 
28557 \newline
28558
28559 \newline
28560
28561 \family typewriter
28562 (load-file sdcdbsrc.el) 
28563 \family default
28564
28565 \newline
28566
28567 \newline
28568 .xemacs is a lisp file so the () around the command is REQUIRED.
28569  The files can also be loaded dynamically while XEmacs is running, set the
28570  environment variable 'EMACSLOADPATH' to the installation bin directory
28571  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28572  To start the interface enter the following command: 
28573 \newline
28574
28575 \newline
28576
28577 \family sans
28578 \series bold
28579 ESC-x sdcdbsrc
28580 \family default
28581 \series default
28582
28583 \newline
28584
28585 \newline
28586 You will prompted to enter the file name to be debugged.
28587  
28588 \newline
28589
28590 \newline
28591 The command line options that are passed to the simulator directly are
28592  bound to default values in the file sdcdbsrc.el.
28593  The variables are listed below, these values maybe changed as required.
28594 \end_layout
28595
28596 \begin_layout Itemize
28597 sdcdbsrc-cpu-type '51
28598 \end_layout
28599
28600 \begin_layout Itemize
28601 sdcdbsrc-frequency '11059200
28602 \end_layout
28603
28604 \begin_layout Itemize
28605 sdcdbsrc-serial nil
28606 \end_layout
28607
28608 \begin_layout Standard
28609 The following is a list of key mapping for the debugger interface.
28610 \end_layout
28611
28612 \begin_layout Standard
28613 \InsetSpace ~
28614
28615 \family typewriter
28616
28617 \newline
28618 ;;\InsetSpace ~
28619 Current Listing :: 
28620 \newline
28621 ;;key\InsetSpace ~
28622 \InsetSpace ~
28623 \InsetSpace ~
28624 \InsetSpace ~
28625 \InsetSpace ~
28626 \InsetSpace ~
28627 \InsetSpace ~
28628 \InsetSpace ~
28629 \InsetSpace ~
28630 \InsetSpace ~
28631 \InsetSpace ~
28632 \InsetSpace ~
28633 \InsetSpace ~
28634 \InsetSpace ~
28635 binding\InsetSpace ~
28636 \InsetSpace ~
28637 \InsetSpace ~
28638 \InsetSpace ~
28639 \InsetSpace ~
28640 \InsetSpace ~
28641 \InsetSpace ~
28642 \InsetSpace ~
28643 \InsetSpace ~
28644 \InsetSpace ~
28645 \InsetSpace ~
28646 \InsetSpace ~
28647 \InsetSpace ~
28648 \InsetSpace ~
28649 \InsetSpace ~
28650 \InsetSpace ~
28651 \InsetSpace ~
28652 \InsetSpace ~
28653 \InsetSpace ~
28654 \InsetSpace ~
28655 \InsetSpace ~
28656 \InsetSpace ~
28657 Comment 
28658 \newline
28659 ;;---\InsetSpace ~
28660 \InsetSpace ~
28661 \InsetSpace ~
28662 \InsetSpace ~
28663 \InsetSpace ~
28664 \InsetSpace ~
28665 \InsetSpace ~
28666 \InsetSpace ~
28667 \InsetSpace ~
28668 \InsetSpace ~
28669 \InsetSpace ~
28670 \InsetSpace ~
28671 \InsetSpace ~
28672 \InsetSpace ~
28673 -------\InsetSpace ~
28674 \InsetSpace ~
28675 \InsetSpace ~
28676 \InsetSpace ~
28677 \InsetSpace ~
28678 \InsetSpace ~
28679 \InsetSpace ~
28680 \InsetSpace ~
28681 \InsetSpace ~
28682 \InsetSpace ~
28683 \InsetSpace ~
28684 \InsetSpace ~
28685 \InsetSpace ~
28686 \InsetSpace ~
28687 \InsetSpace ~
28688 \InsetSpace ~
28689 \InsetSpace ~
28690 \InsetSpace ~
28691 \InsetSpace ~
28692 \InsetSpace ~
28693 \InsetSpace ~
28694 \InsetSpace ~
28695 -------
28696 \newline
28697 ;; 
28698 \newline
28699 ;;\InsetSpace ~
28700 n\InsetSpace ~
28701 \InsetSpace ~
28702 \InsetSpace ~
28703 \InsetSpace ~
28704 \InsetSpace ~
28705 \InsetSpace ~
28706 \InsetSpace ~
28707 \InsetSpace ~
28708 \InsetSpace ~
28709 \InsetSpace ~
28710 \InsetSpace ~
28711 \InsetSpace ~
28712 \InsetSpace ~
28713 \InsetSpace ~
28714 \InsetSpace ~
28715 sdcdb-next-fro
28716 m-src\InsetSpace ~
28717 \InsetSpace ~
28718 \InsetSpace ~
28719 \InsetSpace ~
28720 \InsetSpace ~
28721 \InsetSpace ~
28722 \InsetSpace ~
28723 \InsetSpace ~
28724 \InsetSpace ~
28725 \InsetSpace ~
28726 SDCDB next command 
28727 \newline
28728 ;;\InsetSpace ~
28729 b\InsetSpace ~
28730 \InsetSpace ~
28731 \InsetSpace ~
28732 \InsetSpace ~
28733 \InsetSpace ~
28734 \InsetSpace ~
28735 \InsetSpace ~
28736 \InsetSpace ~
28737 \InsetSpace ~
28738 \InsetSpace ~
28739 \InsetSpace ~
28740 \InsetSpace ~
28741 \InsetSpace ~
28742 \InsetSpace ~
28743 \InsetSpace ~
28744 sdcdb-back-from-src\InsetSpace ~
28745 \InsetSpace ~
28746 \InsetSpace ~
28747 \InsetSpace ~
28748 \InsetSpace ~
28749 \InsetSpace ~
28750 \InsetSpace ~
28751 \InsetSpace ~
28752 \InsetSpace ~
28753 \InsetSpace ~
28754 SDCDB back command 
28755 \newline
28756 ;;\InsetSpace ~
28757 c\InsetSpace ~
28758 \InsetSpace ~
28759 \InsetSpace ~
28760 \InsetSpace ~
28761 \InsetSpace ~
28762 \InsetSpace ~
28763 \InsetSpace ~
28764 \InsetSpace ~
28765 \InsetSpace ~
28766 \InsetSpace ~
28767 \InsetSpace ~
28768 \InsetSpace ~
28769 \InsetSpace ~
28770 \InsetSpace ~
28771 \InsetSpace ~
28772 sdcdb-cont-f
28773 rom-src\InsetSpace ~
28774 \InsetSpace ~
28775 \InsetSpace ~
28776 \InsetSpace ~
28777 \InsetSpace ~
28778 \InsetSpace ~
28779 \InsetSpace ~
28780 \InsetSpace ~
28781 \InsetSpace ~
28782 \InsetSpace ~
28783 SDCDB continue command
28784 \newline
28785 ;;\InsetSpace ~
28786 s\InsetSpace ~
28787 \InsetSpace ~
28788 \InsetSpace ~
28789 \InsetSpace ~
28790 \InsetSpace ~
28791 \InsetSpace ~
28792 \InsetSpace ~
28793 \InsetSpace ~
28794 \InsetSpace ~
28795 \InsetSpace ~
28796 \InsetSpace ~
28797 \InsetSpace ~
28798 \InsetSpace ~
28799 \InsetSpace ~
28800 \InsetSpace ~
28801 sdcdb-step-from-src\InsetSpace ~
28802 \InsetSpace ~
28803 \InsetSpace ~
28804 \InsetSpace ~
28805 \InsetSpace ~
28806 \InsetSpace ~
28807 \InsetSpace ~
28808 \InsetSpace ~
28809 \InsetSpace ~
28810 \InsetSpace ~
28811 SDCDB step command 
28812 \newline
28813 ;;\InsetSpace ~
28814 ?\InsetSpace ~
28815 \InsetSpace ~
28816 \InsetSpace ~
28817 \InsetSpace ~
28818 \InsetSpace ~
28819 \InsetSpace ~
28820 \InsetSpace ~
28821 \InsetSpace ~
28822 \InsetSpace ~
28823 \InsetSpace ~
28824 \InsetSpace ~
28825 \InsetSpace ~
28826 \InsetSpace ~
28827 \InsetSpace ~
28828 \InsetSpace ~
28829 sdcdb-w
28830 hatis-c-sexp\InsetSpace ~
28831 \InsetSpace ~
28832 \InsetSpace ~
28833 \InsetSpace ~
28834 \InsetSpace ~
28835 \InsetSpace ~
28836 \InsetSpace ~
28837 \InsetSpace ~
28838 \InsetSpace ~
28839 \InsetSpace ~
28840 SDCDB ptypecommand for data at 
28841 \newline
28842 ;;\InsetSpace ~
28843 \InsetSpace ~
28844 \InsetSpace ~
28845 \InsetSpace ~
28846 \InsetSpace ~
28847 \InsetSpace ~
28848 \InsetSpace ~
28849 \InsetSpace ~
28850 \InsetSpace ~
28851 \InsetSpace ~
28852 \InsetSpace ~
28853 \InsetSpace ~
28854 \InsetSpace ~
28855 \InsetSpace ~
28856 \InsetSpace ~
28857 \InsetSpace ~
28858 \InsetSpace ~
28859 \InsetSpace ~
28860 \InsetSpace ~
28861 \InsetSpace ~
28862 \InsetSpace ~
28863 \InsetSpace ~
28864 \InsetSpace ~
28865 \InsetSpace ~
28866 \InsetSpace ~
28867 \InsetSpace ~
28868 \InsetSpace ~
28869 \InsetSpace ~
28870 \InsetSpace ~
28871 \InsetSpace ~
28872 \InsetSpace ~
28873 \InsetSpace ~
28874 \InsetSpace ~
28875 \InsetSpace ~
28876 \InsetSpace ~
28877 \InsetSpace ~
28878 \InsetSpace ~
28879 \InsetSpace ~
28880 \InsetSpace ~
28881 \InsetSpace ~
28882 \InsetSpace ~
28883 \InsetSpace ~
28884 \InsetSpace ~
28885 \InsetSpace ~
28886 \InsetSpace ~
28887 \InsetSpace ~
28888 \InsetSpace ~
28889 buffer point 
28890 \newline
28891 ;;\InsetSpace ~
28892 x\InsetSpace ~
28893 \InsetSpace ~
28894 \InsetSpace ~
28895 \InsetSpace ~
28896 \InsetSpace ~
28897 \InsetSpace ~
28898 \InsetSpace ~
28899 \InsetSpace ~
28900 \InsetSpace ~
28901 \InsetSpace ~
28902 \InsetSpace ~
28903 \InsetSpace ~
28904 \InsetSpace ~
28905 \InsetSpace ~
28906 \InsetSpace ~
28907 sdcdbsrc-delete\InsetSpace ~
28908 \InsetSpace ~
28909 \InsetSpace ~
28910 \InsetSpace ~
28911 \InsetSpace ~
28912 \InsetSpace ~
28913 \InsetSpace ~
28914 \InsetSpace ~
28915 \InsetSpace ~
28916 \InsetSpace ~
28917 \InsetSpace ~
28918 \InsetSpace ~
28919 \InsetSpace ~
28920 \InsetSpace ~
28921 SDCD
28922 B Delete all breakpoints if no arg 
28923 \newline
28924 ;;\InsetSpace ~
28925 \InsetSpace ~
28926 \InsetSpace ~
28927 \InsetSpace ~
28928 \InsetSpace ~
28929 \InsetSpace ~
28930 \InsetSpace ~
28931 \InsetSpace ~
28932 \InsetSpace ~
28933 \InsetSpace ~
28934 \InsetSpace ~
28935 \InsetSpace ~
28936 \InsetSpace ~
28937 \InsetSpace ~
28938 \InsetSpace ~
28939 \InsetSpace ~
28940 \InsetSpace ~
28941 \InsetSpace ~
28942 \InsetSpace ~
28943 \InsetSpace ~
28944 \InsetSpace ~
28945 \InsetSpace ~
28946 \InsetSpace ~
28947 \InsetSpace ~
28948 \InsetSpace ~
28949 \InsetSpace ~
28950 \InsetSpace ~
28951 \InsetSpace ~
28952 \InsetSpace ~
28953 \InsetSpace ~
28954 \InsetSpace ~
28955 \InsetSpace ~
28956 \InsetSpace ~
28957 \InsetSpace ~
28958 \InsetSpace ~
28959 \InsetSpace ~
28960 \InsetSpace ~
28961 \InsetSpace ~
28962 \InsetSpace ~
28963 \InsetSpace ~
28964 \InsetSpace ~
28965 \InsetSpace ~
28966 \InsetSpace ~
28967 \InsetSpace ~
28968 \InsetSpace ~
28969 \InsetSpace ~
28970 \InsetSpace ~
28971 given or delete arg (C-u arg x) 
28972 \newline
28973 ;;\InsetSpace ~
28974 m\InsetSpace ~
28975 \InsetSpace ~
28976 \InsetSpace ~
28977 \InsetSpace ~
28978 \InsetSpace ~
28979 \InsetSpace ~
28980 \InsetSpace ~
28981 \InsetSpace ~
28982 \InsetSpace ~
28983 \InsetSpace ~
28984 \InsetSpace ~
28985 \InsetSpace ~
28986 \InsetSpace ~
28987 \InsetSpace ~
28988 \InsetSpace ~
28989 sdcdbsrc
28990 -frame\InsetSpace ~
28991 \InsetSpace ~
28992 \InsetSpace ~
28993 \InsetSpace ~
28994 \InsetSpace ~
28995 \InsetSpace ~
28996 \InsetSpace ~
28997 \InsetSpace ~
28998 \InsetSpace ~
28999 \InsetSpace ~
29000 \InsetSpace ~
29001 \InsetSpace ~
29002 \InsetSpace ~
29003 \InsetSpace ~
29004 \InsetSpace ~
29005 SDCDB Display current frame if no arg, 
29006 \newline
29007 ;;\InsetSpace ~
29008 \InsetSpace ~
29009 \InsetSpace ~
29010 \InsetSpace ~
29011 \InsetSpace ~
29012 \InsetSpace ~
29013 \InsetSpace ~
29014 \InsetSpace ~
29015 \InsetSpace ~
29016 \InsetSpace ~
29017 \InsetSpace ~
29018 \InsetSpace ~
29019 \InsetSpace ~
29020 \InsetSpace ~
29021 \InsetSpace ~
29022 \InsetSpace ~
29023 \InsetSpace ~
29024 \InsetSpace ~
29025 \InsetSpace ~
29026 \InsetSpace ~
29027 \InsetSpace ~
29028 \InsetSpace ~
29029 \InsetSpace ~
29030 \InsetSpace ~
29031 \InsetSpace ~
29032 \InsetSpace ~
29033 \InsetSpace ~
29034 \InsetSpace ~
29035 \InsetSpace ~
29036 \InsetSpace ~
29037 \InsetSpace ~
29038 \InsetSpace ~
29039 \InsetSpace ~
29040 \InsetSpace ~
29041 \InsetSpace ~
29042 \InsetSpace ~
29043 \InsetSpace ~
29044 \InsetSpace ~
29045 \InsetSpace ~
29046 \InsetSpace ~
29047 \InsetSpace ~
29048 \InsetSpace ~
29049 \InsetSpace ~
29050 \InsetSpace ~
29051 \InsetSpace ~
29052 \InsetSpace ~
29053 \InsetSpace ~
29054 given or display frame arg
29055  
29056 \newline
29057 ;;\InsetSpace ~
29058 \InsetSpace ~
29059 \InsetSpace ~
29060 \InsetSpace ~
29061 \InsetSpace ~
29062 \InsetSpace ~
29063 \InsetSpace ~
29064 \InsetSpace ~
29065 \InsetSpace ~
29066 \InsetSpace ~
29067 \InsetSpace ~
29068 \InsetSpace ~
29069 \InsetSpace ~
29070 \InsetSpace ~
29071 \InsetSpace ~
29072 \InsetSpace ~
29073 \InsetSpace ~
29074 \InsetSpace ~
29075 \InsetSpace ~
29076 \InsetSpace ~
29077 \InsetSpace ~
29078 \InsetSpace ~
29079 \InsetSpace ~
29080 \InsetSpace ~
29081 \InsetSpace ~
29082 \InsetSpace ~
29083 \InsetSpace ~
29084 \InsetSpace ~
29085 \InsetSpace ~
29086 \InsetSpace ~
29087 \InsetSpace ~
29088 \InsetSpace ~
29089 \InsetSpace ~
29090 \InsetSpace ~
29091 \InsetSpace ~
29092 \InsetSpace ~
29093 \InsetSpace ~
29094 \InsetSpace ~
29095 \InsetSpace ~
29096 \InsetSpace ~
29097 \InsetSpace ~
29098 \InsetSpace ~
29099 \InsetSpace ~
29100 \InsetSpace ~
29101 \InsetSpace ~
29102 \InsetSpace ~
29103 \InsetSpace ~
29104 buffer point 
29105 \newline
29106 ;;\InsetSpace ~
29107 !\InsetSpace ~
29108 \InsetSpace ~
29109 \InsetSpace ~
29110 \InsetSpace ~
29111 \InsetSpace ~
29112 \InsetSpace ~
29113 \InsetSpace ~
29114 \InsetSpace ~
29115 \InsetSpace ~
29116 \InsetSpace ~
29117 \InsetSpace ~
29118 \InsetSpace ~
29119 \InsetSpace ~
29120 \InsetSpace ~
29121 \InsetSpace ~
29122 sdcdbsrc-goto-sdcdb\InsetSpace ~
29123 \InsetSpace ~
29124 \InsetSpace ~
29125 \InsetSpace ~
29126 \InsetSpace ~
29127 \InsetSpace ~
29128 \InsetSpace ~
29129 \InsetSpace ~
29130 \InsetSpace ~
29131 \InsetSpace ~
29132 Goto the SDCDB output buffer 
29133 \newline
29134 ;;\InsetSpace ~
29135 p\InsetSpace ~
29136 \InsetSpace ~
29137 \InsetSpace ~
29138 \InsetSpace ~
29139 \InsetSpace ~
29140 \InsetSpace ~
29141 \InsetSpace ~
29142 \InsetSpace ~
29143 \InsetSpace ~
29144 \InsetSpace ~
29145 \InsetSpace ~
29146 \InsetSpace ~
29147 \InsetSpace ~
29148 \InsetSpace ~
29149 \InsetSpace ~
29150 sdcdb-prin
29151 t-c-sexp\InsetSpace ~
29152 \InsetSpace ~
29153 \InsetSpace ~
29154 \InsetSpace ~
29155 \InsetSpace ~
29156 \InsetSpace ~
29157 \InsetSpace ~
29158 \InsetSpace ~
29159 \InsetSpace ~
29160 \InsetSpace ~
29161 \InsetSpace ~
29162 SDCDB print command for data at 
29163 \newline
29164 ;;\InsetSpace ~
29165 \InsetSpace ~
29166 \InsetSpace ~
29167 \InsetSpace ~
29168 \InsetSpace ~
29169 \InsetSpace ~
29170 \InsetSpace ~
29171 \InsetSpace ~
29172 \InsetSpace ~
29173 \InsetSpace ~
29174 \InsetSpace ~
29175 \InsetSpace ~
29176 \InsetSpace ~
29177 \InsetSpace ~
29178 \InsetSpace ~
29179 \InsetSpace ~
29180 \InsetSpace ~
29181 \InsetSpace ~
29182 \InsetSpace ~
29183 \InsetSpace ~
29184 \InsetSpace ~
29185 \InsetSpace ~
29186 \InsetSpace ~
29187 \InsetSpace ~
29188 \InsetSpace ~
29189 \InsetSpace ~
29190 \InsetSpace ~
29191 \InsetSpace ~
29192 \InsetSpace ~
29193 \InsetSpace ~
29194 \InsetSpace ~
29195 \InsetSpace ~
29196 \InsetSpace ~
29197 \InsetSpace ~
29198 \InsetSpace ~
29199 \InsetSpace ~
29200 \InsetSpace ~
29201 \InsetSpace ~
29202 \InsetSpace ~
29203 \InsetSpace ~
29204 \InsetSpace ~
29205 \InsetSpace ~
29206 \InsetSpace ~
29207 \InsetSpace ~
29208 \InsetSpace ~
29209 \InsetSpace ~
29210 \InsetSpace ~
29211 buffer point 
29212 \newline
29213 ;;\InsetSpace ~
29214 g\InsetSpace ~
29215 \InsetSpace ~
29216 \InsetSpace ~
29217 \InsetSpace ~
29218 \InsetSpace ~
29219 \InsetSpace ~
29220 \InsetSpace ~
29221 \InsetSpace ~
29222 \InsetSpace ~
29223 \InsetSpace ~
29224 \InsetSpace ~
29225 \InsetSpace ~
29226 \InsetSpace ~
29227 \InsetSpace ~
29228 \InsetSpace ~
29229 sdcdbsrc-goto-sdcdb\InsetSpace ~
29230 \InsetSpace ~
29231 \InsetSpace ~
29232 \InsetSpace ~
29233 \InsetSpace ~
29234 \InsetSpace ~
29235 \InsetSpace ~
29236 \InsetSpace ~
29237 \InsetSpace ~
29238 \InsetSpace ~
29239 Got
29240 o the SDCDB output buffer 
29241 \newline
29242 ;;\InsetSpace ~
29243 t\InsetSpace ~
29244 \InsetSpace ~
29245 \InsetSpace ~
29246 \InsetSpace ~
29247 \InsetSpace ~
29248 \InsetSpace ~
29249 \InsetSpace ~
29250 \InsetSpace ~
29251 \InsetSpace ~
29252 \InsetSpace ~
29253 \InsetSpace ~
29254 \InsetSpace ~
29255 \InsetSpace ~
29256 \InsetSpace ~
29257 \InsetSpace ~
29258 sdcdbsrc-mode\InsetSpace ~
29259 \InsetSpace ~
29260 \InsetSpace ~
29261 \InsetSpace ~
29262 \InsetSpace ~
29263 \InsetSpace ~
29264 \InsetSpace ~
29265 \InsetSpace ~
29266 \InsetSpace ~
29267 \InsetSpace ~
29268 \InsetSpace ~
29269 \InsetSpace ~
29270 \InsetSpace ~
29271 \InsetSpace ~
29272 \InsetSpace ~
29273 \InsetSpace ~
29274 Toggles Sdcdbsrc mode (turns it
29275  off) 
29276 \newline
29277 ;; 
29278 \newline
29279 ;;\InsetSpace ~
29280 C-c\InsetSpace ~
29281 C-f\InsetSpace ~
29282 \InsetSpace ~
29283 \InsetSpace ~
29284 \InsetSpace ~
29285 \InsetSpace ~
29286 \InsetSpace ~
29287 \InsetSpace ~
29288 \InsetSpace ~
29289 \InsetSpace ~
29290 sdcdb-finish-from-src\InsetSpace ~
29291 \InsetSpace ~
29292 \InsetSpace ~
29293 \InsetSpace ~
29294 \InsetSpace ~
29295 \InsetSpace ~
29296 \InsetSpace ~
29297 \InsetSpace ~
29298 SDCDB finish command 
29299 \newline
29300 ;; 
29301 \newline
29302 ;;\InsetSpace ~
29303 C-x\InsetSpace ~
29304 SPC\InsetSpace ~
29305 \InsetSpace ~
29306 \InsetSpace ~
29307 \InsetSpace ~
29308 \InsetSpace ~
29309 \InsetSpace ~
29310 \InsetSpace ~
29311 \InsetSpace ~
29312 \InsetSpace ~
29313 sdcdb-brea
29314 k\InsetSpace ~
29315 \InsetSpace ~
29316 \InsetSpace ~
29317 \InsetSpace ~
29318 \InsetSpace ~
29319 \InsetSpace ~
29320 \InsetSpace ~
29321 \InsetSpace ~
29322 \InsetSpace ~
29323 \InsetSpace ~
29324 \InsetSpace ~
29325 \InsetSpace ~
29326 \InsetSpace ~
29327 \InsetSpace ~
29328 \InsetSpace ~
29329 \InsetSpace ~
29330 \InsetSpace ~
29331 \InsetSpace ~
29332 Set break for line with point 
29333 \newline
29334 ;;\InsetSpace ~
29335 ESC\InsetSpace ~
29336 t\InsetSpace ~
29337 \InsetSpace ~
29338 \InsetSpace ~
29339 \InsetSpace ~
29340 \InsetSpace ~
29341 \InsetSpace ~
29342 \InsetSpace ~
29343 \InsetSpace ~
29344 \InsetSpace ~
29345 \InsetSpace ~
29346 \InsetSpace ~
29347 sdcdbsrc-mode\InsetSpace ~
29348 \InsetSpace ~
29349 \InsetSpace ~
29350 \InsetSpace ~
29351 \InsetSpace ~
29352 \InsetSpace ~
29353 \InsetSpace ~
29354 \InsetSpace ~
29355 \InsetSpace ~
29356 \InsetSpace ~
29357 \InsetSpace ~
29358 \InsetSpace ~
29359 \InsetSpace ~
29360 \InsetSpace ~
29361 \InsetSpace ~
29362 \InsetSpace ~
29363 Toggle Sdcdbsrc mode 
29364 \newline
29365 ;;\InsetSpace ~
29366 ESC\InsetSpace ~
29367 m\InsetSpace ~
29368 \InsetSpace ~
29369 \InsetSpace ~
29370 \InsetSpace ~
29371 \InsetSpace ~
29372 \InsetSpace ~
29373 \InsetSpace ~
29374 \InsetSpace ~
29375 \InsetSpace ~
29376 \InsetSpace ~
29377 \InsetSpace ~
29378 sdc
29379 dbsrc-srcmode\InsetSpace ~
29380 \InsetSpace ~
29381 \InsetSpace ~
29382 \InsetSpace ~
29383 \InsetSpace ~
29384 \InsetSpace ~
29385 \InsetSpace ~
29386 \InsetSpace ~
29387 \InsetSpace ~
29388 \InsetSpace ~
29389 \InsetSpace ~
29390 \InsetSpace ~
29391 \InsetSpace ~
29392 Toggle list mode 
29393 \newline
29394 ;; 
29395 \newline
29396
29397 \family default
29398
29399 \newpage
29400
29401 \end_layout
29402
29403 \begin_layout Chapter
29404 TIPS
29405 \end_layout
29406
29407 \begin_layout Standard
29408 Here are a few guidelines that will help the compiler generate more efficient
29409  code, some of the tips are specific to this compiler others are generally
29410  good programming practice.
29411 \end_layout
29412
29413 \begin_layout Itemize
29414 Use the smallest data type to represent your data-value.
29415  If it is known in advance that the value is going to be less than 256 then
29416  use an 'unsigned char' instead of a 'short' or 'int'.
29417  Please note, that ANSI C requires both signed and unsigned chars to be
29418  promoted to 'signed int'
29419 \begin_inset LatexCommand \index{promotion to signed int}
29420
29421 \end_inset
29422
29423
29424 \begin_inset Marginal
29425 status collapsed
29426
29427 \begin_layout Standard
29428
29429 \series bold
29430 \InsetSpace ~
29431 !
29432 \end_layout
29433
29434 \end_inset
29435
29436  before doing any operation.
29437  This promotion
29438 \begin_inset LatexCommand \index{type promotion}
29439
29440 \end_inset
29441
29442
29443 \begin_inset LatexCommand \label{type promotion}
29444
29445 \end_inset
29446
29447  can be omitted, if the result is the same.
29448  The effect of the promotion rules together with the sign-extension is often
29449  surprising:
29450 \end_layout
29451
29452 \begin_deeper
29453 \begin_layout Verse
29454
29455 \family typewriter
29456 unsigned char uc = 0xfe;
29457 \newline
29458 if (uc * uc < 0) /* this is true! */
29459 \newline
29460 {
29461 \newline
29462 \InsetSpace ~
29463 \InsetSpace ~
29464 \InsetSpace ~
29465 \InsetSpace ~
29466 ....
29467 \newline
29468 }
29469 \end_layout
29470
29471 \begin_layout Standard
29472
29473 \family typewriter
29474 uc * uc
29475 \family default
29476  is evaluated as 
29477 \family typewriter
29478 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29479 \family default
29480 .
29481  
29482 \newline
29483 Another one:
29484 \end_layout
29485
29486 \begin_layout Verse
29487
29488 \family typewriter
29489 (unsigned char) -12 / (signed char) -3 = ...
29490 \end_layout
29491
29492 \begin_layout Standard
29493 No, the result is not 4:
29494 \end_layout
29495
29496 \begin_layout Verse
29497
29498 \family typewriter
29499 (int) (unsigned char) -12 / (int) (signed char) -3 =
29500 \newline
29501 (int) (unsigned char)
29502  0xf4 / (int) (signed char) 0xfd =
29503 \newline
29504 (int) 0x00f4 / (int) 0xfffd =
29505 \newline
29506 (int) 0x00f4
29507  / (int) 0xfffd =
29508 \newline
29509 (int) 244 / (int) -3 =
29510 \newline
29511 (int) -81 = (int) 0xffaf;
29512 \end_layout
29513
29514 \begin_layout Standard
29515 Don't complain, that gcc gives you a different result.
29516  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29517  Therefore the results are different.
29518 \newline
29519 From 
29520 \begin_inset Quotes sld
29521 \end_inset
29522
29523 comp.lang.c FAQ
29524 \begin_inset Quotes srd
29525 \end_inset
29526
29527 :
29528 \end_layout
29529
29530 \begin_layout Quote
29531
29532 \emph on
29533 If well-defined overflow characteristics are important and negative values
29534  are not, or if you want to steer clear of sign-extension problems when
29535  manipulating bits or bytes, use one of the corresponding unsigned types.
29536  (Beware when mixing signed and unsigned values in expressions, though.)
29537 \newline
29538 Although
29539  character types (especially unsigned char) can be used as "tiny" integers,
29540  doing so is sometimes more trouble than it's worth, due to unpredictable
29541  sign extension and increased code size.
29542 \end_layout
29543
29544 \end_deeper
29545 \begin_layout Itemize
29546 Use unsigned when it is known in advance that the value is not going to
29547  be negative.
29548  This helps especially if you are doing division or multiplication, bit-shifting
29549  or are using an array index.
29550 \end_layout
29551
29552 \begin_layout Itemize
29553 NEVER jump into a LOOP.
29554 \end_layout
29555
29556 \begin_layout Itemize
29557 Declare the variables to be local
29558 \begin_inset LatexCommand \index{local variables}
29559
29560 \end_inset
29561
29562  whenever possible, especially loop control variables (induction).
29563 \end_layout
29564
29565 \begin_layout Itemize
29566 Have a look at the assembly listing to get a 
29567 \begin_inset Quotes sld
29568 \end_inset
29569
29570 feeling
29571 \begin_inset Quotes srd
29572 \end_inset
29573
29574  for the code generation.
29575 \end_layout
29576
29577 \begin_layout Section
29578 Porting code from or to other compilers
29579 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29580
29581 \end_inset
29582
29583
29584 \end_layout
29585
29586 \begin_layout Itemize
29587 check whether endianness of the compilers differs and adapt where needed.
29588 \end_layout
29589
29590 \begin_layout Itemize
29591 check the device specific header files
29592 \begin_inset LatexCommand \index{Header files}
29593
29594 \end_inset
29595
29596
29597 \begin_inset LatexCommand \index{Include files}
29598
29599 \end_inset
29600
29601  for compiler specific syntax.
29602  Eventually include the file <compiler.h
29603 \begin_inset LatexCommand \index{compiler.h (include file)}
29604
29605 \end_inset
29606
29607
29608 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29609
29610 \end_inset
29611
29612  to allow using common header files.
29613  (see f.e.
29614  cc2510fx.h 
29615 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29616
29617 \end_inset
29618
29619 ).
29620 \end_layout
29621
29622 \begin_layout Itemize
29623 check whether the startup code contains the correct initialization (watchdog,
29624  peripherals).
29625 \end_layout
29626
29627 \begin_layout Itemize
29628 check whether the sizes of short, int, long match.
29629 \end_layout
29630
29631 \begin_layout Itemize
29632 check if some 16 or 32 bit hardware registers require a specific addressing
29633  order (least significant or most significant byte first) and adapt if needed
29634  (
29635 \emph on
29636 first
29637 \emph default
29638  and 
29639 \emph on
29640 last
29641 \emph default
29642  relate to time and not to lower/upper memory location here, so this is
29643  
29644 \emph on
29645 not
29646 \emph default
29647  the same as endianness).
29648 \end_layout
29649
29650 \begin_layout Itemize
29651 check whether the keyword 
29652 \emph on
29653 volatile
29654 \emph default
29655  is used where needed.
29656  The compilers might differ in their optimization characteristics (as different
29657  versions of the same compiler might also use more clever optimizations
29658  this is good idea anyway).
29659  See section 
29660 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29661
29662 \end_inset
29663
29664 .
29665 \end_layout
29666
29667 \begin_layout Itemize
29668 check that the compilers are not told to supress warnings.
29669 \end_layout
29670
29671 \begin_layout Itemize
29672 check and convert compiler specific extensions (interrupts, memory areas,
29673  pragmas etc.).
29674 \end_layout
29675
29676 \begin_layout Itemize
29677 check for differences in type promotion.
29678  Especially check for math operations on 
29679 \family typewriter
29680 char
29681 \family default
29682  or 
29683 \family typewriter
29684 unsigned char
29685 \family default
29686  variables.
29687  For the sake of C99 compatibility SDCC will probably promote these to 
29688 \family typewriter
29689 int
29690 \family default
29691  more often than other compilers.
29692  Eventually insert explicit casts to 
29693 \family typewriter
29694 (char) 
29695 \family default
29696 or
29697 \family typewriter
29698  (unsigned char)
29699 \family default
29700 .
29701  Also check that the ~\InsetSpace ~
29702 operator
29703 \begin_inset LatexCommand \index{\~\/ Operator}
29704
29705 \end_inset
29706
29707  is not used on 
29708 \family typewriter
29709 bit
29710 \begin_inset LatexCommand \index{bit}
29711
29712 \end_inset
29713
29714
29715 \family default
29716  variables, use the !\InsetSpace ~
29717 operator instead.
29718  See sections 
29719 \begin_inset LatexCommand \ref{type promotion}
29720
29721 \end_inset
29722
29723  and 
29724 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29725
29726 \end_inset
29727
29728 .
29729 \end_layout
29730
29731 \begin_layout Itemize
29732 check the assembly code generated for interrupt routines (f.e.
29733  for calls to possibly non-reentrant library functions).
29734 \end_layout
29735
29736 \begin_layout Itemize
29737 check whether timing loops result in proper timing (or preferably consider
29738  a rewrite of the code with timer based delays instead).
29739 \end_layout
29740
29741 \begin_layout Itemize
29742 check for differences in printf parameters (some compilers push (va_arg
29743 \begin_inset LatexCommand \index{vararg, va\_arg}
29744
29745 \end_inset
29746
29747 ) char variables as 
29748 \family typewriter
29749 int
29750 \family default
29751  others push them as 
29752 \family typewriter
29753 char
29754 \family default
29755 .
29756  See section 
29757 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29758
29759 \end_inset
29760
29761 ).
29762 \end_layout
29763
29764 \begin_layout Itemize
29765 check the resulting memory map
29766 \begin_inset LatexCommand \index{Memory map}
29767
29768 \end_inset
29769
29770 .
29771  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
29772 ly idata, pdata, xdata).
29773  Eventually check if unexpected library functions are included.
29774 \end_layout
29775
29776 \begin_layout Section
29777 Tools
29778 \begin_inset LatexCommand \index{Tools}
29779
29780 \end_inset
29781
29782  included in the distribution
29783 \end_layout
29784
29785 \begin_layout Standard
29786 \align left
29787 \begin_inset Tabular
29788 <lyxtabular version="3" rows="12" columns="3">
29789 <features>
29790 <column alignment="left" valignment="top" leftline="true" width="0pt">
29791 <column alignment="left" valignment="top" leftline="true" width="0pt">
29792 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29793 <row topline="true" bottomline="true">
29794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29795 \begin_inset Text
29796
29797 \begin_layout Standard
29798
29799 \series bold
29800 Name
29801 \end_layout
29802
29803 \end_inset
29804 </cell>
29805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29806 \begin_inset Text
29807
29808 \begin_layout Standard
29809
29810 \series bold
29811 Purpose
29812 \end_layout
29813
29814 \end_inset
29815 </cell>
29816 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29817 \begin_inset Text
29818
29819 \begin_layout Standard
29820
29821 \series bold
29822 Directory
29823 \end_layout
29824
29825 \end_inset
29826 </cell>
29827 </row>
29828 <row topline="true">
29829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29830 \begin_inset Text
29831
29832 \begin_layout Standard
29833 uCsim
29834 \begin_inset LatexCommand \index{uCsim}
29835
29836 \end_inset
29837
29838
29839 \end_layout
29840
29841 \end_inset
29842 </cell>
29843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29844 \begin_inset Text
29845
29846 \begin_layout Standard
29847 Simulator for various architectures
29848 \end_layout
29849
29850 \end_inset
29851 </cell>
29852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29853 \begin_inset Text
29854
29855 \begin_layout Standard
29856 sdcc/sim/ucsim
29857 \end_layout
29858
29859 \end_inset
29860 </cell>
29861 </row>
29862 <row topline="true">
29863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29864 \begin_inset Text
29865
29866 \begin_layout Standard
29867 keil2sdcc.pl
29868 \end_layout
29869
29870 \end_inset
29871 </cell>
29872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29873 \begin_inset Text
29874
29875 \begin_layout Standard
29876 header file
29877 \begin_inset LatexCommand \index{Header files}
29878
29879 \end_inset
29880
29881
29882 \begin_inset LatexCommand \index{Include files}
29883
29884 \end_inset
29885
29886  conversion
29887 \end_layout
29888
29889 \end_inset
29890 </cell>
29891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29892 \begin_inset Text
29893
29894 \begin_layout Standard
29895 sdcc/support/scripts
29896 \end_layout
29897
29898 \end_inset
29899 </cell>
29900 </row>
29901 <row topline="true">
29902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29903 \begin_inset Text
29904
29905 \begin_layout Standard
29906 mh2h.c
29907 \end_layout
29908
29909 \end_inset
29910 </cell>
29911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29912 \begin_inset Text
29913
29914 \begin_layout Standard
29915 header file conversion
29916 \end_layout
29917
29918 \end_inset
29919 </cell>
29920 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29921 \begin_inset Text
29922
29923 \begin_layout Standard
29924 sdcc/support/scripts
29925 \end_layout
29926
29927 \end_inset
29928 </cell>
29929 </row>
29930 <row topline="true">
29931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29932 \begin_inset Text
29933
29934 \begin_layout Standard
29935 as-gbz80
29936 \end_layout
29937
29938 \end_inset
29939 </cell>
29940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29941 \begin_inset Text
29942
29943 \begin_layout Standard
29944 Assembler
29945 \end_layout
29946
29947 \end_inset
29948 </cell>
29949 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29950 \begin_inset Text
29951
29952 \begin_layout Standard
29953
29954 \family roman
29955 \series medium
29956 \shape up
29957 \size normal
29958 \emph off
29959 \bar no
29960 \noun off
29961 \color none
29962 sdcc/bin
29963 \end_layout
29964
29965 \end_inset
29966 </cell>
29967 </row>
29968 <row topline="true">
29969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29970 \begin_inset Text
29971
29972 \begin_layout Standard
29973 as-z80
29974 \end_layout
29975
29976 \end_inset
29977 </cell>
29978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29979 \begin_inset Text
29980
29981 \begin_layout Standard
29982 Assembler
29983 \end_layout
29984
29985 \end_inset
29986 </cell>
29987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29988 \begin_inset Text
29989
29990 \begin_layout Standard
29991
29992 \family roman
29993 \series medium
29994 \shape up
29995 \size normal
29996 \emph off
29997 \bar no
29998 \noun off
29999 \color none
30000 sdcc/bin
30001 \end_layout
30002
30003 \end_inset
30004 </cell>
30005 </row>
30006 <row topline="true">
30007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30008 \begin_inset Text
30009
30010 \begin_layout Standard
30011 asx8051
30012 \end_layout
30013
30014 \end_inset
30015 </cell>
30016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30017 \begin_inset Text
30018
30019 \begin_layout Standard
30020 Assembler
30021 \end_layout
30022
30023 \end_inset
30024 </cell>
30025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30026 \begin_inset Text
30027
30028 \begin_layout Standard
30029
30030 \family roman
30031 \series medium
30032 \shape up
30033 \size normal
30034 \emph off
30035 \bar no
30036 \noun off
30037 \color none
30038 sdcc/bin
30039 \end_layout
30040
30041 \end_inset
30042 </cell>
30043 </row>
30044 <row topline="true">
30045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30046 \begin_inset Text
30047
30048 \begin_layout Standard
30049 SDCDB
30050 \end_layout
30051
30052 \end_inset
30053 </cell>
30054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30055 \begin_inset Text
30056
30057 \begin_layout Standard
30058 Simulator
30059 \end_layout
30060
30061 \end_inset
30062 </cell>
30063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30064 \begin_inset Text
30065
30066 \begin_layout Standard
30067
30068 \family roman
30069 \series medium
30070 \shape up
30071 \size normal
30072 \emph off
30073 \bar no
30074 \noun off
30075 \color none
30076 sdcc/bin
30077 \end_layout
30078
30079 \end_inset
30080 </cell>
30081 </row>
30082 <row topline="true">
30083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30084 \begin_inset Text
30085
30086 \begin_layout Standard
30087 aslink
30088 \end_layout
30089
30090 \end_inset
30091 </cell>
30092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30093 \begin_inset Text
30094
30095 \begin_layout Standard
30096 Linker
30097 \end_layout
30098
30099 \end_inset
30100 </cell>
30101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30102 \begin_inset Text
30103
30104 \begin_layout Standard
30105
30106 \family roman
30107 \series medium
30108 \shape up
30109 \size normal
30110 \emph off
30111 \bar no
30112 \noun off
30113 \color none
30114 sdcc/bin
30115 \end_layout
30116
30117 \end_inset
30118 </cell>
30119 </row>
30120 <row topline="true">
30121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30122 \begin_inset Text
30123
30124 \begin_layout Standard
30125 link-z80
30126 \end_layout
30127
30128 \end_inset
30129 </cell>
30130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30131 \begin_inset Text
30132
30133 \begin_layout Standard
30134 Linker
30135 \end_layout
30136
30137 \end_inset
30138 </cell>
30139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30140 \begin_inset Text
30141
30142 \begin_layout Standard
30143
30144 \family roman
30145 \series medium
30146 \shape up
30147 \size normal
30148 \emph off
30149 \bar no
30150 \noun off
30151 \color none
30152 sdcc/bin
30153 \end_layout
30154
30155 \end_inset
30156 </cell>
30157 </row>
30158 <row topline="true">
30159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30160 \begin_inset Text
30161
30162 \begin_layout Standard
30163 link-gbz80
30164 \end_layout
30165
30166 \end_inset
30167 </cell>
30168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30169 \begin_inset Text
30170
30171 \begin_layout Standard
30172 Linker
30173 \end_layout
30174
30175 \end_inset
30176 </cell>
30177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30178 \begin_inset Text
30179
30180 \begin_layout Standard
30181
30182 \family roman
30183 \series medium
30184 \shape up
30185 \size normal
30186 \emph off
30187 \bar no
30188 \noun off
30189 \color none
30190 sdcc/bin
30191 \end_layout
30192
30193 \end_inset
30194 </cell>
30195 </row>
30196 <row topline="true" bottomline="true">
30197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30198 \begin_inset Text
30199
30200 \begin_layout Standard
30201 packihx
30202 \end_layout
30203
30204 \end_inset
30205 </cell>
30206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30207 \begin_inset Text
30208
30209 \begin_layout Standard
30210 Intel Hex packer 
30211 \begin_inset LatexCommand \index{packihx (tool)}
30212
30213 \end_inset
30214
30215
30216 \end_layout
30217
30218 \end_inset
30219 </cell>
30220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30221 \begin_inset Text
30222
30223 \begin_layout Standard
30224
30225 \family roman
30226 \series medium
30227 \shape up
30228 \size normal
30229 \emph off
30230 \bar no
30231 \noun off
30232 \color none
30233 sdcc/bin
30234 \end_layout
30235
30236 \end_inset
30237 </cell>
30238 </row>
30239 </lyxtabular>
30240
30241 \end_inset
30242
30243
30244 \newline
30245
30246 \end_layout
30247
30248 \begin_layout Section
30249 Documentation
30250 \begin_inset LatexCommand \index{Documentation}
30251
30252 \end_inset
30253
30254  included in the distribution
30255 \end_layout
30256
30257 \begin_layout Standard
30258 \align left
30259 \begin_inset Tabular
30260 <lyxtabular version="3" rows="10" columns="2">
30261 <features>
30262 <column alignment="block" valignment="top" leftline="true" width="40col%">
30263 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
30264 <row topline="true" bottomline="true" endhead="true">
30265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30266 \begin_inset Text
30267
30268 \begin_layout Standard
30269
30270 \series bold
30271 Subject / Title
30272 \end_layout
30273
30274 \end_inset
30275 </cell>
30276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30277 \begin_inset Text
30278
30279 \begin_layout Standard
30280
30281 \series bold
30282 Filename / Where to get
30283 \end_layout
30284
30285 \end_inset
30286 </cell>
30287 </row>
30288 <row topline="true">
30289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30290 \begin_inset Text
30291
30292 \begin_layout Standard
30293 SDCC Compiler User Guide
30294 \end_layout
30295
30296 \end_inset
30297 </cell>
30298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30299 \begin_inset Text
30300
30301 \begin_layout Standard
30302 You're reading it right now
30303 \emph on
30304  \InsetSpace ~
30305 \InsetSpace ~
30306 \InsetSpace ~
30307
30308 \hfill
30309 online at:
30310 \emph default
30311
30312 \newline
30313
30314 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
30315
30316 \end_inset
30317
30318
30319 \end_layout
30320
30321 \end_inset
30322 </cell>
30323 </row>
30324 <row topline="true">
30325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30326 \begin_inset Text
30327
30328 \begin_layout Standard
30329 Changelog of SDCC
30330 \end_layout
30331
30332 \end_inset
30333 </cell>
30334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30335 \begin_inset Text
30336
30337 \begin_layout Standard
30338 sdcc/Changelog
30339 \emph on
30340  \InsetSpace ~
30341 \InsetSpace ~
30342 \InsetSpace ~
30343
30344 \hfill
30345 online at:
30346 \emph default
30347
30348 \newline
30349
30350 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
30351
30352 \end_inset
30353
30354
30355 \end_layout
30356
30357 \end_inset
30358 </cell>
30359 </row>
30360 <row topline="true">
30361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30362 \begin_inset Text
30363
30364 \begin_layout Standard
30365 ASXXXX
30366 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
30367
30368 \end_inset
30369
30370
30371 \begin_inset LatexCommand \index{Assembler documentation}
30372
30373 \end_inset
30374
30375  Assemblers and
30376 \newline
30377 ASLINK
30378 \begin_inset LatexCommand \index{aslink}
30379
30380 \end_inset
30381
30382
30383 \begin_inset LatexCommand \index{Linker documentation}
30384
30385 \end_inset
30386
30387  Relocating Linker
30388 \end_layout
30389
30390 \end_inset
30391 </cell>
30392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30393 \begin_inset Text
30394
30395 \begin_layout Standard
30396 sdcc/as/doc/asxhtm.html 
30397 \emph on
30398 \InsetSpace ~
30399 \InsetSpace ~
30400 \InsetSpace ~
30401
30402 \hfill
30403 online at:
30404 \emph default
30405
30406 \newline
30407
30408 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
30409
30410 \end_inset
30411
30412
30413 \end_layout
30414
30415 \end_inset
30416 </cell>
30417 </row>
30418 <row topline="true">
30419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30420 \begin_inset Text
30421
30422 \begin_layout Standard
30423 SDCC regression test
30424 \begin_inset LatexCommand \index{Regression test}
30425
30426 \end_inset
30427
30428
30429 \end_layout
30430
30431 \end_inset
30432 </cell>
30433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30434 \begin_inset Text
30435
30436 \begin_layout Standard
30437 sdcc/doc/test_suite_spec.pdf 
30438 \emph on
30439 \InsetSpace ~
30440 \InsetSpace ~
30441 \InsetSpace ~
30442
30443 \hfill
30444 online at:
30445 \emph default
30446
30447 \newline
30448
30449 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30450
30451 \end_inset
30452
30453
30454 \end_layout
30455
30456 \end_inset
30457 </cell>
30458 </row>
30459 <row topline="true">
30460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30461 \begin_inset Text
30462
30463 \begin_layout Standard
30464 Various notes
30465 \end_layout
30466
30467 \end_inset
30468 </cell>
30469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30470 \begin_inset Text
30471
30472 \begin_layout Standard
30473 sdcc/doc/* 
30474 \emph on
30475 \InsetSpace ~
30476 \InsetSpace ~
30477 \InsetSpace ~
30478
30479 \hfill
30480 online at:
30481 \emph default
30482
30483 \newline
30484
30485 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30486
30487 \end_inset
30488
30489
30490 \end_layout
30491
30492 \end_inset
30493 </cell>
30494 </row>
30495 <row topline="true">
30496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30497 \begin_inset Text
30498
30499 \begin_layout Standard
30500 Notes on debugging with SDCDB
30501 \begin_inset LatexCommand \index{SDCDB (debugger)}
30502
30503 \end_inset
30504
30505
30506 \end_layout
30507
30508 \end_inset
30509 </cell>
30510 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30511 \begin_inset Text
30512
30513 \begin_layout Standard
30514 sdcc/debugger/README 
30515 \emph on
30516 \InsetSpace ~
30517 \InsetSpace ~
30518 \InsetSpace ~
30519
30520 \hfill
30521 online at
30522 \emph default
30523 :
30524 \newline
30525
30526 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30527
30528 \end_inset
30529
30530
30531 \end_layout
30532
30533 \end_inset
30534 </cell>
30535 </row>
30536 <row topline="true">
30537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30538 \begin_inset Text
30539
30540 \begin_layout Standard
30541 uCsim
30542 \begin_inset LatexCommand \index{uCsim}
30543
30544 \end_inset
30545
30546  Software simulator for microcontrollers
30547 \end_layout
30548
30549 \end_inset
30550 </cell>
30551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30552 \begin_inset Text
30553
30554 \begin_layout Standard
30555
30556 \family roman
30557 \series medium
30558 \shape up
30559 \size normal
30560 \emph off
30561 \bar no
30562 \noun off
30563 \color none
30564 sdcc/sim/ucsim/doc
30565 \family default
30566 \series default
30567 \shape default
30568 \size default
30569 \emph default
30570 \bar default
30571 \noun default
30572 /index.html 
30573 \emph on
30574 \InsetSpace ~
30575 \InsetSpace ~
30576 \InsetSpace ~
30577
30578 \hfill
30579 online at:
30580 \emph default
30581
30582 \newline
30583
30584 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30585
30586 \end_inset
30587
30588
30589 \end_layout
30590
30591 \end_inset
30592 </cell>
30593 </row>
30594 <row topline="true">
30595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30596 \begin_inset Text
30597
30598 \begin_layout Standard
30599 Temporary notes on the pic16
30600 \begin_inset LatexCommand \index{PIC16}
30601
30602 \end_inset
30603
30604  port
30605 \end_layout
30606
30607 \end_inset
30608 </cell>
30609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30610 \begin_inset Text
30611
30612 \begin_layout Standard
30613 sdcc/src/pic16/NOTES 
30614 \emph on
30615 \InsetSpace ~
30616 \InsetSpace ~
30617 \InsetSpace ~
30618
30619 \hfill
30620 online at:
30621 \newline
30622
30623 \emph default
30624
30625 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30626
30627 \end_inset
30628
30629
30630 \end_layout
30631
30632 \end_inset
30633 </cell>
30634 </row>
30635 <row topline="true" bottomline="true">
30636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30637 \begin_inset Text
30638
30639 \begin_layout Standard
30640 SDCC internal documentation (debugging file format)
30641 \end_layout
30642
30643 \end_inset
30644 </cell>
30645 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30646 \begin_inset Text
30647
30648 \begin_layout Standard
30649 sdcc/doc/
30650 \family roman
30651 \series medium
30652 \shape up
30653 \size normal
30654 \emph off
30655 \bar no
30656 \noun off
30657 \color none
30658 cdbfileformat.pd
30659 \family default
30660 \series default
30661 \shape default
30662 \size default
30663 \emph default
30664 \bar default
30665 \noun default
30666 f
30667 \emph on
30668  \InsetSpace ~
30669 \InsetSpace ~
30670 \InsetSpace ~
30671
30672 \hfill
30673 online at:
30674 \emph default
30675
30676 \newline
30677
30678 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30679
30680 \end_inset
30681
30682
30683 \end_layout
30684
30685 \end_inset
30686 </cell>
30687 </row>
30688 </lyxtabular>
30689
30690 \end_inset
30691
30692
30693 \newline
30694
30695 \end_layout
30696
30697 \begin_layout Section
30698 Related open source tools
30699 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
30700
30701 \end_inset
30702
30703
30704 \begin_inset LatexCommand \index{Related tools}
30705
30706 \end_inset
30707
30708
30709 \end_layout
30710
30711 \begin_layout Standard
30712 \align left
30713 \begin_inset Tabular
30714 <lyxtabular version="3" rows="14" columns="3">
30715 <features>
30716 <column alignment="left" valignment="top" leftline="true" width="0pt">
30717 <column alignment="block" valignment="top" leftline="true" width="30line%">
30718 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30719 <row topline="true" bottomline="true">
30720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30721 \begin_inset Text
30722
30723 \begin_layout Standard
30724
30725 \series bold
30726 Name
30727 \end_layout
30728
30729 \end_inset
30730 </cell>
30731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30732 \begin_inset Text
30733
30734 \begin_layout Standard
30735
30736 \series bold
30737 Purpose
30738 \end_layout
30739
30740 \end_inset
30741 </cell>
30742 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30743 \begin_inset Text
30744
30745 \begin_layout Standard
30746
30747 \series bold
30748 Where to get
30749 \end_layout
30750
30751 \end_inset
30752 </cell>
30753 </row>
30754 <row topline="true">
30755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30756 \begin_inset Text
30757
30758 \begin_layout Standard
30759 gpsim
30760 \begin_inset LatexCommand \index{gpsim (pic simulator)}
30761
30762 \end_inset
30763
30764
30765 \end_layout
30766
30767 \end_inset
30768 </cell>
30769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30770 \begin_inset Text
30771
30772 \begin_layout Standard
30773 PIC simulator
30774 \end_layout
30775
30776 \end_inset
30777 </cell>
30778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30779 \begin_inset Text
30780
30781 \begin_layout Standard
30782 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
30783
30784 \end_inset
30785
30786
30787 \end_layout
30788
30789 \end_inset
30790 </cell>
30791 </row>
30792 <row topline="true">
30793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30794 \begin_inset Text
30795
30796 \begin_layout Standard
30797 gputils
30798 \begin_inset LatexCommand \index{gputils (pic tools)}
30799
30800 \end_inset
30801
30802
30803 \end_layout
30804
30805 \end_inset
30806 </cell>
30807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30808 \begin_inset Text
30809
30810 \begin_layout Standard
30811 GNU PIC utilities
30812 \end_layout
30813
30814 \end_inset
30815 </cell>
30816 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30817 \begin_inset Text
30818
30819 \begin_layout Standard
30820 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
30821
30822 \end_inset
30823
30824
30825 \end_layout
30826
30827 \end_inset
30828 </cell>
30829 </row>
30830 <row topline="true">
30831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30832 \begin_inset Text
30833
30834 \begin_layout Standard
30835 flP5
30836 \end_layout
30837
30838 \end_inset
30839 </cell>
30840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30841 \begin_inset Text
30842
30843 \begin_layout Standard
30844 PIC programmer
30845 \end_layout
30846
30847 \end_inset
30848 </cell>
30849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30850 \begin_inset Text
30851
30852 \begin_layout Standard
30853 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
30854
30855 \end_inset
30856
30857
30858 \end_layout
30859
30860 \end_inset
30861 </cell>
30862 </row>
30863 <row topline="true">
30864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30865 \begin_inset Text
30866
30867 \begin_layout Standard
30868 ec2drv/newcdb
30869 \end_layout
30870
30871 \end_inset
30872 </cell>
30873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30874 \begin_inset Text
30875
30876 \begin_layout Standard
30877 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
30878  (Unix only)
30879 \end_layout
30880
30881 \end_inset
30882 </cell>
30883 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30884 \begin_inset Text
30885
30886 \begin_layout Standard
30887 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
30888
30889 \end_inset
30890
30891
30892 \end_layout
30893
30894 \end_inset
30895 </cell>
30896 </row>
30897 <row topline="true">
30898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30899 \begin_inset Text
30900
30901 \begin_layout Standard
30902 indent
30903 \begin_inset LatexCommand \index{indent (source formatting tool)}
30904
30905 \end_inset
30906
30907
30908 \end_layout
30909
30910 \end_inset
30911 </cell>
30912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30913 \begin_inset Text
30914
30915 \begin_layout Standard
30916 Formats C source - Master of the white spaces
30917 \end_layout
30918
30919 \end_inset
30920 </cell>
30921 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30922 \begin_inset Text
30923
30924 \begin_layout Standard
30925 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
30926
30927 \end_inset
30928
30929
30930 \end_layout
30931
30932 \end_inset
30933 </cell>
30934 </row>
30935 <row topline="true">
30936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30937 \begin_inset Text
30938
30939 \begin_layout Standard
30940 srecord
30941 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
30942
30943 \end_inset
30944
30945
30946 \end_layout
30947
30948 \end_inset
30949 </cell>
30950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30951 \begin_inset Text
30952
30953 \begin_layout Standard
30954 Object file conversion, checksumming, ...
30955 \end_layout
30956
30957 \end_inset
30958 </cell>
30959 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30960 \begin_inset Text
30961
30962 \begin_layout Standard
30963 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
30964
30965 \end_inset
30966
30967
30968 \end_layout
30969
30970 \end_inset
30971 </cell>
30972 </row>
30973 <row topline="true">
30974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30975 \begin_inset Text
30976
30977 \begin_layout Standard
30978 objdump
30979 \begin_inset LatexCommand \index{objdump (tool)}
30980
30981 \end_inset
30982
30983
30984 \end_layout
30985
30986 \end_inset
30987 </cell>
30988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30989 \begin_inset Text
30990
30991 \begin_layout Standard
30992 Object file conversion, ...
30993 \end_layout
30994
30995 \end_inset
30996 </cell>
30997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30998 \begin_inset Text
30999
31000 \begin_layout Standard
31001 Part of binutils (should be there anyway)
31002 \end_layout
31003
31004 \end_inset
31005 </cell>
31006 </row>
31007 <row topline="true">
31008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31009 \begin_inset Text
31010
31011 \begin_layout Standard
31012 cmon51
31013 \end_layout
31014
31015 \end_inset
31016 </cell>
31017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31018 \begin_inset Text
31019
31020 \begin_layout Standard
31021 8051 monitor (hex up-/download, single step, disassemble)
31022 \end_layout
31023
31024 \end_inset
31025 </cell>
31026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31027 \begin_inset Text
31028
31029 \begin_layout Standard
31030 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
31031
31032 \end_inset
31033
31034
31035 \end_layout
31036
31037 \end_inset
31038 </cell>
31039 </row>
31040 <row topline="true">
31041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31042 \begin_inset Text
31043
31044 \begin_layout Standard
31045 doxygen
31046 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
31047
31048 \end_inset
31049
31050
31051 \end_layout
31052
31053 \end_inset
31054 </cell>
31055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31056 \begin_inset Text
31057
31058 \begin_layout Standard
31059 Source code documentation system
31060 \end_layout
31061
31062 \end_inset
31063 </cell>
31064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31065 \begin_inset Text
31066
31067 \begin_layout Standard
31068 \begin_inset LatexCommand \url{http://www.doxygen.org}
31069
31070 \end_inset
31071
31072
31073 \end_layout
31074
31075 \end_inset
31076 </cell>
31077 </row>
31078 <row topline="true">
31079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31080 \begin_inset Text
31081
31082 \begin_layout Standard
31083 kdevelop
31084 \end_layout
31085
31086 \end_inset
31087 </cell>
31088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31089 \begin_inset Text
31090
31091 \begin_layout Standard
31092 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
31093 \end_layout
31094
31095 \end_inset
31096 </cell>
31097 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31098 \begin_inset Text
31099
31100 \begin_layout Standard
31101 \begin_inset LatexCommand \url{http://www.kdevelop.org}
31102
31103 \end_inset
31104
31105
31106 \end_layout
31107
31108 \end_inset
31109 </cell>
31110 </row>
31111 <row topline="true">
31112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31113 \begin_inset Text
31114
31115 \begin_layout Standard
31116 paulmon
31117 \end_layout
31118
31119 \end_inset
31120 </cell>
31121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31122 \begin_inset Text
31123
31124 \begin_layout Standard
31125 8051 monitor (hex up-/download, single step, disassemble)
31126 \end_layout
31127
31128 \end_inset
31129 </cell>
31130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31131 \begin_inset Text
31132
31133 \begin_layout Standard
31134 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
31135
31136 \end_inset
31137
31138
31139 \end_layout
31140
31141 \end_inset
31142 </cell>
31143 </row>
31144 <row topline="true">
31145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31146 \begin_inset Text
31147
31148 \begin_layout Standard
31149 splint
31150 \begin_inset LatexCommand \index{splint (syntax checking tool)}
31151
31152 \end_inset
31153
31154
31155 \end_layout
31156
31157 \end_inset
31158 </cell>
31159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31160 \begin_inset Text
31161
31162 \begin_layout Standard
31163 Statically checks c sources (see 
31164 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
31165
31166 \end_inset
31167
31168 )
31169 \end_layout
31170
31171 \end_inset
31172 </cell>
31173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31174 \begin_inset Text
31175
31176 \begin_layout Standard
31177 \begin_inset LatexCommand \url{http://www.splint.org}
31178
31179 \end_inset
31180
31181
31182 \end_layout
31183
31184 \end_inset
31185 </cell>
31186 </row>
31187 <row topline="true" bottomline="true">
31188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31189 \begin_inset Text
31190
31191 \begin_layout Standard
31192 ddd
31193 \begin_inset LatexCommand \index{DDD (debugger)}
31194
31195 \end_inset
31196
31197
31198 \end_layout
31199
31200 \end_inset
31201 </cell>
31202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31203 \begin_inset Text
31204
31205 \begin_layout Standard
31206 Debugger, serves nicely as GUI to SDCDB
31207 \begin_inset LatexCommand \index{SDCDB (debugger)}
31208
31209 \end_inset
31210
31211  (Unix only)
31212 \end_layout
31213
31214 \end_inset
31215 </cell>
31216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31217 \begin_inset Text
31218
31219 \begin_layout Standard
31220 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
31221
31222 \end_inset
31223
31224
31225 \end_layout
31226
31227 \end_inset
31228 </cell>
31229 </row>
31230 </lyxtabular>
31231
31232 \end_inset
31233
31234
31235 \newline
31236
31237 \end_layout
31238
31239 \begin_layout Section
31240 Related documentation / recommended reading
31241 \end_layout
31242
31243 \begin_layout Standard
31244 \align left
31245 \begin_inset Tabular
31246 <lyxtabular version="3" rows="7" columns="3">
31247 <features>
31248 <column alignment="left" valignment="top" leftline="true" width="0pt">
31249 <column alignment="left" valignment="top" leftline="true" width="0">
31250 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
31251 <row topline="true" bottomline="true">
31252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31253 \begin_inset Text
31254
31255 \begin_layout Standard
31256
31257 \series bold
31258 Name
31259 \end_layout
31260
31261 \end_inset
31262 </cell>
31263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31264 \begin_inset Text
31265
31266 \begin_layout Standard
31267
31268 \series bold
31269 Subject / Title
31270 \end_layout
31271
31272 \end_inset
31273 </cell>
31274 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31275 \begin_inset Text
31276
31277 \begin_layout Standard
31278
31279 \series bold
31280 Where to get
31281 \end_layout
31282
31283 \end_inset
31284 </cell>
31285 </row>
31286 <row topline="true">
31287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31288 \begin_inset Text
31289
31290 \begin_layout Standard
31291
31292 \family roman
31293 \series medium
31294 \shape up
31295 \size normal
31296 \emph off
31297 \bar no
31298 \noun off
31299 \color none
31300 c-refcard.pdf
31301 \end_layout
31302
31303 \end_inset
31304 </cell>
31305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31306 \begin_inset Text
31307
31308 \begin_layout Standard
31309 C Reference Card
31310 \begin_inset LatexCommand \index{C Reference card}
31311
31312 \end_inset
31313
31314 , 2 pages
31315 \end_layout
31316
31317 \end_inset
31318 </cell>
31319 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31320 \begin_inset Text
31321
31322 \begin_layout Standard
31323 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
31324
31325 \end_inset
31326
31327
31328 \end_layout
31329
31330 \end_inset
31331 </cell>
31332 </row>
31333 <row topline="true">
31334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31335 \begin_inset Text
31336
31337 \begin_layout Standard
31338 c-faq
31339 \end_layout
31340
31341 \end_inset
31342 </cell>
31343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31344 \begin_inset Text
31345
31346 \begin_layout Standard
31347 C-FAQ
31348 \begin_inset LatexCommand \index{C FAQ}
31349
31350 \end_inset
31351
31352
31353 \end_layout
31354
31355 \end_inset
31356 </cell>
31357 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31358 \begin_inset Text
31359
31360 \begin_layout Standard
31361 \begin_inset LatexCommand \url{http://www.c-faq.com}
31362
31363 \end_inset
31364
31365
31366 \end_layout
31367
31368 \end_inset
31369 </cell>
31370 </row>
31371 <row topline="true">
31372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31373 \begin_inset Text
31374
31375 \begin_layout Standard
31376 ISO/IEC 9899:TC2
31377 \end_layout
31378
31379 \end_inset
31380 </cell>
31381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31382 \begin_inset Text
31383
31384 \begin_layout Standard
31385 \begin_inset Quotes sld
31386 \end_inset
31387
31388 C-Standard
31389 \begin_inset Quotes srd
31390 \end_inset
31391
31392
31393 \end_layout
31394
31395 \end_inset
31396 </cell>
31397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31398 \begin_inset Text
31399
31400 \begin_layout Standard
31401
31402 \size footnotesize
31403 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31404
31405 \end_inset
31406
31407
31408 \end_layout
31409
31410 \end_inset
31411 </cell>
31412 </row>
31413 <row topline="true">
31414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31415 \begin_inset Text
31416
31417 \begin_layout Standard
31418 ISO/IEC DTR 18037
31419 \end_layout
31420
31421 \end_inset
31422 </cell>
31423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31424 \begin_inset Text
31425
31426 \begin_layout Standard
31427 \begin_inset Quotes sld
31428 \end_inset
31429
31430 Extensions for Embedded C
31431 \begin_inset Quotes srd
31432 \end_inset
31433
31434
31435 \end_layout
31436
31437 \end_inset
31438 </cell>
31439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31440 \begin_inset Text
31441
31442 \begin_layout Standard
31443
31444 \size footnotesize
31445 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31446
31447 \end_inset
31448
31449
31450 \end_layout
31451
31452 \end_inset
31453 </cell>
31454 </row>
31455 <row topline="true">
31456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31457 \begin_inset Text
31458
31459 \begin_layout Standard
31460
31461 \end_layout
31462
31463 \end_inset
31464 </cell>
31465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31466 \begin_inset Text
31467
31468 \begin_layout Standard
31469 Latest datasheet of target CPU
31470 \end_layout
31471
31472 \end_inset
31473 </cell>
31474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31475 \begin_inset Text
31476
31477 \begin_layout Standard
31478 vendor
31479 \end_layout
31480
31481 \end_inset
31482 </cell>
31483 </row>
31484 <row topline="true" bottomline="true">
31485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31486 \begin_inset Text
31487
31488 \begin_layout Standard
31489
31490 \end_layout
31491
31492 \end_inset
31493 </cell>
31494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31495 \begin_inset Text
31496
31497 \begin_layout Standard
31498 Revision history of datasheet
31499 \end_layout
31500
31501 \end_inset
31502 </cell>
31503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31504 \begin_inset Text
31505
31506 \begin_layout Standard
31507 vendor
31508 \end_layout
31509
31510 \end_inset
31511 </cell>
31512 </row>
31513 </lyxtabular>
31514
31515 \end_inset
31516
31517
31518 \newline
31519
31520 \end_layout
31521
31522 \begin_layout Section
31523 Application notes specifically for SDCC
31524 \end_layout
31525
31526 \begin_layout Standard
31527 SDCC makes no claims about the completeness of this list and about up-to-datenes
31528 s or correctness of the application notes
31529 \begin_inset LatexCommand \index{Application notes}
31530
31531 \end_inset
31532
31533 .
31534 \end_layout
31535
31536 \begin_layout Standard
31537 \align left
31538
31539 \size footnotesize
31540 \begin_inset Tabular
31541 <lyxtabular version="3" rows="7" columns="3">
31542 <features>
31543 <column alignment="block" valignment="top" leftline="true" width="17col%">
31544 <column alignment="block" valignment="top" leftline="true" width="27col%">
31545 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
31546 <row topline="true" bottomline="true">
31547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31548 \begin_inset Text
31549
31550 \begin_layout Standard
31551
31552 \series bold
31553 \size footnotesize
31554 Vendor
31555 \end_layout
31556
31557 \end_inset
31558 </cell>
31559 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31560 \begin_inset Text
31561
31562 \begin_layout Standard
31563
31564 \series bold
31565 \size footnotesize
31566 Subject / Title
31567 \end_layout
31568
31569 \end_inset
31570 </cell>
31571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31572 \begin_inset Text
31573
31574 \begin_layout Standard
31575
31576 \series bold
31577 \size footnotesize
31578 Where to get
31579 \end_layout
31580
31581 \end_inset
31582 </cell>
31583 </row>
31584 <row topline="true">
31585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31586 \begin_inset Text
31587
31588 \begin_layout Standard
31589
31590 \size footnotesize
31591 Maxim / Dallas
31592 \end_layout
31593
31594 \end_inset
31595 </cell>
31596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31597 \begin_inset Text
31598
31599 \begin_layout Standard
31600
31601 \size footnotesize
31602 Using the SDCC Compiler for the DS80C400
31603 \begin_inset LatexCommand \index{DS80C400}
31604
31605 \end_inset
31606
31607
31608 \end_layout
31609
31610 \end_inset
31611 </cell>
31612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31613 \begin_inset Text
31614
31615 \begin_layout Standard
31616
31617 \size footnotesize
31618 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31619
31620 \end_inset
31621
31622
31623 \end_layout
31624
31625 \end_inset
31626 </cell>
31627 </row>
31628 <row topline="true">
31629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31630 \begin_inset Text
31631
31632 \begin_layout Standard
31633
31634 \size footnotesize
31635 Maxim / Dallas
31636 \end_layout
31637
31638 \end_inset
31639 </cell>
31640 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31641 \begin_inset Text
31642
31643 \begin_layout Standard
31644
31645 \size footnotesize
31646 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31647 \begin_inset LatexCommand \index{DS89C4x0}
31648
31649 \end_inset
31650
31651  Family of Microcontrollers
31652 \end_layout
31653
31654 \end_inset
31655 </cell>
31656 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31657 \begin_inset Text
31658
31659 \begin_layout Standard
31660
31661 \size footnotesize
31662 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31663
31664 \end_inset
31665
31666
31667 \end_layout
31668
31669 \end_inset
31670 </cell>
31671 </row>
31672 <row topline="true">
31673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31674 \begin_inset Text
31675
31676 \begin_layout Standard
31677
31678 \size footnotesize
31679 Silicon Laboratories / Cygnal
31680 \end_layout
31681
31682 \end_inset
31683 </cell>
31684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31685 \begin_inset Text
31686
31687 \begin_layout Standard
31688
31689 \size footnotesize
31690 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31691 \begin_inset LatexCommand \index{IDE}
31692
31693 \end_inset
31694
31695
31696 \end_layout
31697
31698 \end_inset
31699 </cell>
31700 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31701 \begin_inset Text
31702
31703 \begin_layout Standard
31704
31705 \size footnotesize
31706 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
31707
31708 \end_inset
31709
31710
31711 \end_layout
31712
31713 \end_inset
31714 </cell>
31715 </row>
31716 <row topline="true">
31717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31718 \begin_inset Text
31719
31720 \begin_layout Standard
31721
31722 \size footnotesize
31723 Ramtron / Goal Semiconductor
31724 \end_layout
31725
31726 \end_inset
31727 </cell>
31728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31729 \begin_inset Text
31730
31731 \begin_layout Standard
31732
31733 \size footnotesize
31734 Interfacing SDCC to Syn and Textpad
31735 \end_layout
31736
31737 \end_inset
31738 </cell>
31739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31740 \begin_inset Text
31741
31742 \begin_layout Standard
31743
31744 \size footnotesize
31745 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31746
31747 \end_inset
31748
31749
31750 \end_layout
31751
31752 \end_inset
31753 </cell>
31754 </row>
31755 <row topline="true">
31756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31757 \begin_inset Text
31758
31759 \begin_layout Standard
31760
31761 \size footnotesize
31762 Ramtron / Goal Semiconductor
31763 \end_layout
31764
31765 \end_inset
31766 </cell>
31767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31768 \begin_inset Text
31769
31770 \begin_layout Standard
31771
31772 \size footnotesize
31773 Installing and Configuring SDCC and Crimson Editor 
31774 \end_layout
31775
31776 \end_inset
31777 </cell>
31778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31779 \begin_inset Text
31780
31781 \begin_layout Standard
31782
31783 \size footnotesize
31784 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31785
31786 \end_inset
31787
31788
31789 \end_layout
31790
31791 \end_inset
31792 </cell>
31793 </row>
31794 <row topline="true" bottomline="true">
31795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31796 \begin_inset Text
31797
31798 \begin_layout Standard
31799
31800 \size footnotesize
31801 Texas Instruments
31802 \end_layout
31803
31804 \end_inset
31805 </cell>
31806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31807 \begin_inset Text
31808
31809 \begin_layout Standard
31810
31811 \size footnotesize
31812 MSC12xx Programming with SDCC
31813 \end_layout
31814
31815 \end_inset
31816 </cell>
31817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31818 \begin_inset Text
31819
31820 \begin_layout Standard
31821
31822 \size footnotesize
31823 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
31824
31825 \end_inset
31826
31827
31828 \end_layout
31829
31830 \end_inset
31831 </cell>
31832 </row>
31833 </lyxtabular>
31834
31835 \end_inset
31836
31837
31838 \end_layout
31839
31840 \begin_layout Section
31841 Some Questions
31842 \end_layout
31843
31844 \begin_layout Standard
31845 Some questions answered, some pointers given - it might be time to in turn
31846  ask 
31847 \emph on
31848 you
31849 \emph default
31850  some questions: 
31851 \end_layout
31852
31853 \begin_layout Itemize
31854 can you solve your project with the selected microcontroller? Would you
31855  find out early or rather late that your target is too small/slow/whatever?
31856  Can you switch to a slightly better device if it doesn't fit?
31857 \end_layout
31858
31859 \begin_layout Itemize
31860 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
31861  and/or another programming language be more adequate? Would an operating
31862  system on the target device help?
31863 \end_layout
31864
31865 \begin_layout Itemize
31866 if you solved the problem, will the marketing department be happy?
31867 \end_layout
31868
31869 \begin_layout Itemize
31870 if the marketing department is happy, will customers be happy?
31871 \end_layout
31872
31873 \begin_layout Itemize
31874 if you're the project manager, marketing department and maybe even the customer
31875  in one person, have you tried to see the project from the outside?
31876 \end_layout
31877
31878 \begin_layout Itemize
31879 is the project done if you think it is done? Or is just that other interface/pro
31880 tocol/feature/configuration/option missing? How about website, manual(s),
31881  internationali(z|s)ation, packaging, labels, 2nd source for components,
31882  electromagnetic compatability/interference, documentation for production,
31883  production test software, update mechanism, patent issues?
31884 \end_layout
31885
31886 \begin_layout Itemize
31887 is your project adequately positioned in that magic triangle: fame, fortune,
31888  fun?
31889 \end_layout
31890
31891 \begin_layout Standard
31892 Maybe not all answers to these questions are known and some answers may
31893  even be 
31894 \emph on
31895 no
31896 \emph default
31897 , nevertheless knowing these questions may help you to avoid burnout
31898 \begin_inset Foot
31899 status open
31900
31901 \begin_layout Standard
31902 burnout is bad for electronic devices, programmers and motorcycle tyres
31903 \end_layout
31904
31905 \end_inset
31906
31907 .
31908  Chances are you didn't want to hear some of them...
31909 \end_layout
31910
31911 \begin_layout Chapter
31912 Support
31913 \begin_inset LatexCommand \index{Support}
31914
31915 \end_inset
31916
31917
31918 \end_layout
31919
31920 \begin_layout Standard
31921 SDCC has grown to be a large project.
31922  The compiler alone (without the preprocessor, assembler and linker) is
31923  well over 150,000 lines of code (blank stripped).
31924  The open source nature of this project is a key to its continued growth
31925  and support.
31926  You gain the benefit and support of many active software developers and
31927  end users.
31928  Is SDCC perfect? No, that's why we need your help.
31929  The developers take pride in fixing reported bugs.
31930  You can help by reporting the bugs and helping other SDCC users.
31931  There are lots of ways to contribute, and we encourage you to take part
31932  in making SDCC a great software package.
31933  
31934 \end_layout
31935
31936 \begin_layout Standard
31937 The SDCC project is hosted on the SDCC sourceforge site at 
31938 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
31939
31940 \end_inset
31941
31942 .
31943  You'll find the complete set of mailing lists
31944 \begin_inset LatexCommand \index{Mailing list(s)}
31945
31946 \end_inset
31947
31948 , forums, bug reporting system, patch submission
31949 \begin_inset LatexCommand \index{Patch submission}
31950
31951 \end_inset
31952
31953  system, download
31954 \begin_inset LatexCommand \index{download}
31955
31956 \end_inset
31957
31958  area and Subversion code repository
31959 \begin_inset LatexCommand \index{Subversion code repository}
31960
31961 \end_inset
31962
31963  there.
31964 \end_layout
31965
31966 \begin_layout Section
31967 Reporting Bugs
31968 \begin_inset LatexCommand \index{Bug reporting}
31969
31970 \end_inset
31971
31972
31973 \begin_inset LatexCommand \index{Reporting bugs}
31974
31975 \end_inset
31976
31977
31978 \end_layout
31979
31980 \begin_layout Standard
31981 The recommended way of reporting bugs is using the infrastructure of the
31982  sourceforge site.
31983  You can follow the status of bug reports there and have an overview about
31984  the known bugs.
31985 \end_layout
31986
31987 \begin_layout Standard
31988 Bug reports are automatically forwarded to the developer mailing list and
31989  will be fixed ASAP.
31990  When reporting a bug, it is very useful to include a small test program
31991  (the smaller the better) which reproduces the problem.
31992  If you can isolate the problem by looking at the generated assembly code,
31993  this can be very helpful.
31994  Compiling your program with the -
31995 \begin_inset ERT
31996 status collapsed
31997
31998 \begin_layout Standard
31999
32000
32001 \backslash
32002 /
32003 \end_layout
32004
32005 \end_inset
32006
32007 -dumpall
32008 \begin_inset LatexCommand \index{-\/-dumpall}
32009
32010 \end_inset
32011
32012  option can sometimes be useful in locating optimization problems.
32013  When reporting a bug please make sure you:
32014 \end_layout
32015
32016 \begin_layout Enumerate
32017 Attach the code you are compiling with SDCC.
32018  
32019 \end_layout
32020
32021 \begin_layout Enumerate
32022 Specify the exact command you use to run SDCC, or attach your Makefile.
32023  
32024 \end_layout
32025
32026 \begin_layout Enumerate
32027 Specify the SDCC version (type "
32028 \family sans
32029 \series bold
32030 sdcc -v
32031 \family default
32032 \series default
32033 "), your platform, and operating system.
32034  
32035 \end_layout
32036
32037 \begin_layout Enumerate
32038 Provide an exact copy of any error message or incorrect output.
32039  
32040 \end_layout
32041
32042 \begin_layout Enumerate
32043 Put something meaningful in the subject of your message.
32044 \end_layout
32045
32046 \begin_layout Standard
32047 Please attempt to include these 5 important parts, as applicable, in all
32048  requests for support or when reporting any problems or bugs with SDCC.
32049  Though this will make your message lengthy, it will greatly improve your
32050  chance that SDCC users and developers will be able to help you.
32051  Some SDCC developers are frustrated by bug reports without code provided
32052  that they can use to reproduce and ultimately fix the problem, so please
32053  be sure to provide sample code if you are reporting a bug! 
32054 \end_layout
32055
32056 \begin_layout Standard
32057 Please have a short check that you are using a recent version of SDCC and
32058  the bug is not yet known.
32059  This is the link for reporting bugs: 
32060 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
32061
32062 \end_inset
32063
32064 .
32065  With SDCC on average having more than 200 downloads
32066 \begin_inset LatexCommand \index{download}
32067
32068 \end_inset
32069
32070  on sourceforge per day
32071 \begin_inset Foot
32072 status open
32073
32074 \begin_layout Standard
32075 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
32076  between 2002 and 2005.
32077  This does not include other methods of distribution.
32078 \end_layout
32079
32080 \end_inset
32081
32082  there must be some users.
32083  So it's not exactly easy to find a new bug.
32084  If you find one we need it: 
32085 \emph on
32086 reporting bugs is good
32087 \emph default
32088 .
32089 \end_layout
32090
32091 \begin_layout Section
32092 Requesting Features
32093 \begin_inset LatexCommand \label{sub:Requesting-Features}
32094
32095 \end_inset
32096
32097
32098 \begin_inset LatexCommand \index{Feature request}
32099
32100 \end_inset
32101
32102
32103 \begin_inset LatexCommand \index{Requesting features}
32104
32105 \end_inset
32106
32107
32108 \end_layout
32109
32110 \begin_layout Standard
32111 Like bug reports feature requests are forwarded to the developer mailing
32112  list.
32113  This is the link for requesting features: 
32114 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32115
32116 \end_inset
32117
32118 .
32119 \end_layout
32120
32121 \begin_layout Section
32122 Submitting patches
32123 \end_layout
32124
32125 \begin_layout Standard
32126 Like bug reports contributed patches are forwarded to the developer mailing
32127  list.
32128  This is the link for submitting patches
32129 \begin_inset LatexCommand \index{Patch submission}
32130
32131 \end_inset
32132
32133
32134 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
32135
32136 \end_inset
32137
32138 .
32139 \end_layout
32140
32141 \begin_layout Standard
32142 You need to specify some parameters to the 
32143 \family typewriter
32144 diff
32145 \family default
32146  command for the patches to be useful.
32147  If you modified more than one file a patch created f.e.
32148  with 
32149 \family sans
32150 \series bold
32151
32152 \begin_inset Quotes sld
32153 \end_inset
32154
32155 diff -Naur unmodified_directory modified_directory >my_changes.patch
32156 \begin_inset Quotes srd
32157 \end_inset
32158
32159
32160 \family default
32161 \series default
32162  will be fine, otherwise 
32163 \family sans
32164 \series bold
32165
32166 \begin_inset Quotes sld
32167 \end_inset
32168
32169 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
32170 \begin_inset Quotes srd
32171 \end_inset
32172
32173
32174 \series default
32175  
32176 \family default
32177 will do.
32178 \end_layout
32179
32180 \begin_layout Section
32181 Getting Help
32182 \end_layout
32183
32184 \begin_layout Standard
32185 These links should take you directly to the 
32186 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
32187
32188 \end_inset
32189
32190
32191 \begin_inset Foot
32192 status open
32193
32194 \begin_layout Standard
32195 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
32196  automated messages (mid 2003)
32197 \end_layout
32198
32199 \end_inset
32200
32201  and the 
32202 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
32203
32204 \end_inset
32205
32206 , lists
32207 \begin_inset LatexCommand \index{Mailing list(s)}
32208
32209 \end_inset
32210
32211  and forums are archived and searchable so if you are lucky someone already
32212  had a similar problem.
32213  While mails to the lists themselves are delivered promptly their web front
32214  end on sourceforge sometimes shows a severe time lag (up to several weeks),
32215  if you're seriously using SDCC please consider subscribing to the lists.
32216 \end_layout
32217
32218 \begin_layout Section
32219 ChangeLog
32220 \end_layout
32221
32222 \begin_layout Standard
32223 You can follow the status of the Subversion version
32224 \begin_inset LatexCommand \index{version}
32225
32226 \end_inset
32227
32228  of SDCC by watching the Changelog
32229 \begin_inset LatexCommand \index{Changelog}
32230
32231 \end_inset
32232
32233  in the Subversion repository
32234 \size footnotesize
32235  
32236 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
32237
32238 \end_inset
32239
32240 .
32241 \end_layout
32242
32243 \begin_layout Section
32244 Subversion Source Code Repository
32245 \end_layout
32246
32247 \begin_layout Standard
32248 The output of 
32249 \family sans
32250 \series bold
32251 sdcc --version
32252 \family default
32253 \series default
32254  or the filenames of the snapshot versions of SDCC include date and its
32255  Subversion
32256 \begin_inset LatexCommand \index{Subversion code repository}
32257
32258 \end_inset
32259
32260  number.
32261  Subversion allows to download the source of recent or previous versions
32262  
32263 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
32264
32265 \end_inset
32266
32267  (by number or by date).
32268  An on-line source code browser and detailled instructions are also available
32269  there.
32270  SDCC versions starting from 1999 up to now are available (currently the
32271  versions prior to the conversion from cvs
32272 \begin_inset LatexCommand \index{cvs|see{Subversion}}
32273
32274 \end_inset
32275
32276  to Subversion (April 2006) are either by accessible by Subversion or by
32277  cvs).
32278 \end_layout
32279
32280 \begin_layout Section
32281 Release policy
32282 \begin_inset LatexCommand \index{Release policy}
32283
32284 \end_inset
32285
32286
32287 \end_layout
32288
32289 \begin_layout Standard
32290 Historically there often were long delays between official releases and
32291  the sourceforge download area tends to get not updated at all.
32292  Excuses in the past might have referred to problems with live range analysis,
32293  but as this was fixed a while ago, the current problem is that another
32294  excuse has to be found.
32295  Kidding aside, we have to get better there! On the other hand there are
32296  daily snapshots available at 
32297 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
32298
32299 \end_inset
32300
32301 , and you can always build the very last version (hopefully with many bugs
32302  fixed, and features added) from the source code available at 
32303 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
32304
32305 \end_inset
32306
32307 .
32308  A release wiki
32309 \begin_inset LatexCommand \index{wiki}
32310
32311 \end_inset
32312
32313
32314 \begin_inset LatexCommand \index{Release wiki}
32315
32316 \end_inset
32317
32318  at 
32319 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
32320
32321 \end_inset
32322
32323  also holds some information about past and future releases.
32324 \end_layout
32325
32326 \begin_layout Section
32327 Examples
32328 \begin_inset LatexCommand \index{Examples}
32329
32330 \end_inset
32331
32332
32333 \end_layout
32334
32335 \begin_layout Standard
32336 You'll find some small examples in the directory 
32337 \emph on
32338 sdcc/device/examples/.
32339  
32340 \emph default
32341 More examples and libraries are available at
32342 \emph on
32343  The SDCC Open Knowledge Resource 
32344 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
32345
32346 \end_inset
32347
32348  
32349 \emph default
32350 web site or at 
32351 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
32352
32353 \end_inset
32354
32355 .
32356 \end_layout
32357
32358 \begin_layout Standard
32359 \begin_inset Note Note
32360 status collapsed
32361
32362 \begin_layout Standard
32363 I did insert a reference to Paul's web site here although it seems rather
32364  dedicated to a specific 8032 board (I think it's okay because it f.e.
32365  shows LCD/Harddisc interface and has a free 8051 monitor.
32366  Independent 8032 board vendors face hard competition of heavily subsidized
32367  development boards anyway).
32368 \end_layout
32369
32370 \begin_layout Standard
32371 Maybe we should include some links to real world applications.
32372  Preferably pointer to pointers (one for each architecture) so this stays
32373  manageable here?
32374 \end_layout
32375
32376 \end_inset
32377
32378
32379 \end_layout
32380
32381 \begin_layout Section
32382 Quality control
32383 \begin_inset LatexCommand \label{sec:Quality-control}
32384
32385 \end_inset
32386
32387
32388 \begin_inset LatexCommand \index{Quality control}
32389
32390 \end_inset
32391
32392
32393 \end_layout
32394
32395 \begin_layout Standard
32396 The compiler is passed through snaphot build compile and build checks.
32397  The so called 
32398 \shape italic
32399 regression tests
32400 \shape default
32401
32402 \begin_inset LatexCommand \index{Regression test}
32403
32404 \end_inset
32405
32406  check that SDCC itself compiles flawlessly on several host platforms (i386,
32407  Opteron, 64 bit Alpha, ppc64, Mac OS X on PPC, Solaris on Sparc) and checks
32408  the quality of the code generated by SDCC by running the code for several
32409  target platforms through simulators.
32410  The regression test suite comprises more than 100 files which expand to
32411  more than 500 test cases which include more than 4500 tests.
32412  The results of these tests are published daily on SDCC's snapshot page
32413  (click on the red or green symbols on the right side of 
32414 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32415
32416 \end_inset
32417
32418 ).
32419 \end_layout
32420
32421 \begin_layout Standard
32422 There is a separate document 
32423 \shape italic
32424 test_suite.pdf 
32425 \begin_inset LatexCommand \index{Test suite}
32426
32427 \end_inset
32428
32429
32430 \shape default
32431  
32432 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32433
32434 \end_inset
32435
32436  about the regression test suite.
32437 \end_layout
32438
32439 \begin_layout Standard
32440 You'll find the test code in the directory 
32441 \shape italic
32442 sdcc/support/regression
32443 \shape default
32444 .
32445  You can run these tests manually by running 
32446 \family sans
32447 make
32448 \family default
32449  in this directory (or f.e.
32450  
32451 \family sans
32452 \series bold
32453
32454 \begin_inset Quotes sld
32455 \end_inset
32456
32457 make test-mcs51
32458 \begin_inset Quotes srd
32459 \end_inset
32460
32461
32462 \family default
32463 \series default
32464  if you don't want to run the complete tests).
32465  The test code might also be interesting if you want to look for examples
32466 \begin_inset LatexCommand \index{Examples}
32467
32468 \end_inset
32469
32470  checking corner cases of SDCC or if you plan to submit patches
32471 \begin_inset LatexCommand \index{Patch submission}
32472
32473 \end_inset
32474
32475 .
32476 \end_layout
32477
32478 \begin_layout Standard
32479 The PIC14 port uses a different set of regression tests 
32480 \begin_inset LatexCommand \index{Regression test (PIC14)}
32481
32482 \end_inset
32483
32484 , you'll find them in the directory 
32485 \shape italic
32486 sdcc/src/regression
32487 \shape default
32488 .
32489 \end_layout
32490
32491 \begin_layout Section
32492 Use of SDCC in Education
32493 \end_layout
32494
32495 \begin_layout Standard
32496 In short: 
32497 \emph on
32498 highly
32499 \emph default
32500  encouraged
32501 \begin_inset Foot
32502 status open
32503
32504 \begin_layout Standard
32505 the phrase "use in education" might evoke the association "
32506 \emph on
32507 only
32508 \emph default
32509  fit for use in education".
32510  This connotation is not intended but nevertheless risked as the licensing
32511  of SDCC makes it difficult to offer educational discounts
32512 \end_layout
32513
32514 \end_inset
32515
32516 .
32517  If your rationales are to:
32518 \end_layout
32519
32520 \begin_layout Enumerate
32521 give students a chance to understand the 
32522 \emph on
32523 complete
32524 \emph default
32525  steps of code generation
32526 \end_layout
32527
32528 \begin_layout Enumerate
32529 have a curriculum that can be extended for years.
32530  Then you could use an fpga board as target and your curriculum will seamlessly
32531  extend from logic synthesis (
32532 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32533
32534 \end_inset
32535
32536
32537 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32538
32539 \end_inset
32540
32541 ), over assembly programming, to C to FPGA compilers (
32542 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32543
32544 \end_inset
32545
32546 ) and to C.
32547 \end_layout
32548
32549 \begin_layout Enumerate
32550 be able to insert excursions about skills like using a revision control
32551  system, submitting/applying patches, using a type-setting (as opposed to
32552  word-processing) engine LyX/LaTeX, using 
32553 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32554
32555 \end_inset
32556
32557 , following some 
32558 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32559
32560 \end_inset
32561
32562 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32563  Source Software, CPU simulation, compiler regression tests
32564 \begin_inset LatexCommand \index{Regression test}
32565
32566 \end_inset
32567
32568 .
32569  
32570 \newline
32571 And if there should be a shortage of ideas then you can always point students
32572  to the ever-growing feature request list 
32573 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32574
32575 \end_inset
32576
32577 .
32578 \end_layout
32579
32580 \begin_layout Enumerate
32581 not tie students to a specific host platform and instead allow them to use
32582  a host platform of 
32583 \emph on
32584 their
32585 \emph default
32586  choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
32587  and eventually 
32588 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32589
32590 \end_inset
32591
32592 )
32593 \end_layout
32594
32595 \begin_layout Enumerate
32596 not encourage students to use illegal copies of educational software
32597 \end_layout
32598
32599 \begin_layout Enumerate
32600 be immune to licensing/availability/price changes of the chosen tool chain
32601 \end_layout
32602
32603 \begin_layout Enumerate
32604 be able to change to a new target platform without having to adopt a new
32605  tool chain
32606 \end_layout
32607
32608 \begin_layout Enumerate
32609 have complete control over and insight into the tool chain
32610 \end_layout
32611
32612 \begin_layout Enumerate
32613 make your students aware about the pros and cons of open source software
32614  development
32615 \end_layout
32616
32617 \begin_layout Enumerate
32618 give back to the public as you are probably at least partially publically
32619  funded
32620 \end_layout
32621
32622 \begin_layout Enumerate
32623 give students a chance to publically prove their skills and to possibly
32624  see a world wide impact
32625 \end_layout
32626
32627 \begin_layout Standard
32628 then SDCC is probably among the first choices.
32629  Well, probably SDCC might be the only choice.
32630 \newpage
32631
32632 \end_layout
32633
32634 \begin_layout Chapter
32635 SDCC Technical Data
32636 \end_layout
32637
32638 \begin_layout Section
32639 Optimizations
32640 \begin_inset LatexCommand \index{Optimizations}
32641
32642 \end_inset
32643
32644
32645 \end_layout
32646
32647 \begin_layout Standard
32648 SDCC performs a host of standard optimizations in addition to some MCU specific
32649  optimizations.
32650  
32651 \end_layout
32652
32653 \begin_layout Subsection
32654 Sub-expression Elimination
32655 \begin_inset LatexCommand \index{Subexpression elimination}
32656
32657 \end_inset
32658
32659
32660 \end_layout
32661
32662 \begin_layout Standard
32663 The compiler does local and 
32664 \emph on
32665 g
32666 \emph default
32667 lobal 
32668 \emph on
32669 c
32670 \emph default
32671 ommon 
32672 \emph on
32673 s
32674 \emph default
32675 ubexpression 
32676 \emph on
32677 e
32678 \emph default
32679 limination, e.g.: 
32680 \end_layout
32681
32682 \begin_layout Verse
32683
32684 \family typewriter
32685 i = x + y + 1; 
32686 \newline
32687 j = x + y;
32688 \end_layout
32689
32690 \begin_layout Standard
32691 will be translated to
32692 \end_layout
32693
32694 \begin_layout Verse
32695
32696 \family typewriter
32697 iTemp = x + y; 
32698 \newline
32699 i = iTemp + 1; 
32700 \newline
32701 j = iTemp;
32702 \end_layout
32703
32704 \begin_layout Standard
32705 Some subexpressions are not as obvious as the above example, e.g.:
32706 \end_layout
32707
32708 \begin_layout Verse
32709
32710 \family typewriter
32711 a->b[i].c = 10; 
32712 \newline
32713 a->b[i].d = 11;
32714 \end_layout
32715
32716 \begin_layout Standard
32717 In this case the address arithmetic a->b[i] will be computed only once;
32718  the equivalent code in C would be.
32719 \end_layout
32720
32721 \begin_layout Verse
32722
32723 \family typewriter
32724 iTemp = a->b[i]; 
32725 \newline
32726 iTemp.c = 10; 
32727 \newline
32728 iTemp.d = 11;
32729 \end_layout
32730
32731 \begin_layout Standard
32732 The compiler will try to keep these temporary variables in registers.
32733 \end_layout
32734
32735 \begin_layout Subsection
32736 Dead-Code Elimination
32737 \begin_inset LatexCommand \index{Dead-code elimination}
32738
32739 \end_inset
32740
32741
32742 \end_layout
32743
32744 \begin_layout Verse
32745
32746 \family typewriter
32747 int global;
32748 \newline
32749
32750 \newline
32751 void f () { 
32752 \newline
32753 \InsetSpace ~
32754 \InsetSpace ~
32755 int i; 
32756 \newline
32757 \InsetSpace ~
32758 \InsetSpace ~
32759 i = 1; \InsetSpace ~
32760 \InsetSpace ~
32761 \InsetSpace ~
32762 \InsetSpace ~
32763 \InsetSpace ~
32764 /* dead store */ 
32765 \newline
32766 \InsetSpace ~
32767 \InsetSpace ~
32768 global = 1;\InsetSpace ~
32769 /* dead
32770  store */ 
32771 \newline
32772 \InsetSpace ~
32773 \InsetSpace ~
32774 global = 2; 
32775 \newline
32776 \InsetSpace ~
32777 \InsetSpace ~
32778 return; 
32779 \newline
32780 \InsetSpace ~
32781 \InsetSpace ~
32782 global = 3;\InsetSpace ~
32783 /* unreachable */ 
32784 \newline
32785 }
32786 \end_layout
32787
32788 \begin_layout Standard
32789 will be changed to
32790 \end_layout
32791
32792 \begin_layout Verse
32793
32794 \family typewriter
32795 int global;
32796 \newline
32797
32798 \newline
32799 void f () {
32800 \newline
32801 \InsetSpace ~
32802 \InsetSpace ~
32803 global = 2; 
32804 \newline
32805 }
32806 \end_layout
32807
32808 \begin_layout Subsection
32809 Copy-Propagation
32810 \begin_inset LatexCommand \index{Copy propagation}
32811
32812 \end_inset
32813
32814
32815 \end_layout
32816
32817 \begin_layout Verse
32818
32819 \family typewriter
32820 int f() { 
32821 \newline
32822 \InsetSpace ~
32823 \InsetSpace ~
32824 int i, j; 
32825 \newline
32826 \InsetSpace ~
32827 \InsetSpace ~
32828 i = 10; 
32829 \newline
32830 \InsetSpace ~
32831 \InsetSpace ~
32832 j = i; 
32833 \newline
32834 \InsetSpace ~
32835 \InsetSpace ~
32836 return j; 
32837 \newline
32838 }
32839 \end_layout
32840
32841 \begin_layout Standard
32842 will be changed to 
32843 \end_layout
32844
32845 \begin_layout Verse
32846
32847 \family typewriter
32848 int f() { 
32849 \newline
32850 \InsetSpace ~
32851 \InsetSpace ~
32852 int i, j; 
32853 \newline
32854 \InsetSpace ~
32855 \InsetSpace ~
32856 i = 10; 
32857 \newline
32858 \InsetSpace ~
32859 \InsetSpace ~
32860 j = 10; 
32861 \newline
32862 \InsetSpace ~
32863 \InsetSpace ~
32864 return 10; 
32865 \newline
32866 }
32867 \end_layout
32868
32869 \begin_layout Standard
32870 Note: the dead stores created by this copy propagation will be eliminated
32871  by dead-code elimination.
32872 \end_layout
32873
32874 \begin_layout Subsection
32875 Loop Optimizations
32876 \begin_inset LatexCommand \index{Loop optimization}
32877
32878 \end_inset
32879
32880
32881 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
32882
32883 \end_inset
32884
32885
32886 \end_layout
32887
32888 \begin_layout Standard
32889 Two types of loop optimizations are done by SDCC 
32890 \emph on
32891 loop invariant
32892 \emph default
32893  lifting and
32894 \emph on
32895  strength reduction
32896 \emph default
32897  of loop induction variables.
32898  In addition to the strength reduction the optimizer marks the induction
32899  variables and the register allocator tries to keep the induction variables
32900  in registers for the duration of the loop.
32901  Because of this preference of the register allocator
32902 \begin_inset LatexCommand \index{Register allocation}
32903
32904 \end_inset
32905
32906 , loop induction optimization causes an increase in register pressure, which
32907  may cause unwanted spilling of other temporary variables into the stack
32908 \begin_inset LatexCommand \index{stack}
32909
32910 \end_inset
32911
32912  / data space.
32913  The compiler will generate a warning message when it is forced to allocate
32914  extra space either on the stack or data space.
32915  If this extra space allocation is undesirable then induction optimization
32916  can be eliminated either for the entire source file (with -
32917 \begin_inset ERT
32918 status collapsed
32919
32920 \begin_layout Standard
32921
32922
32923 \backslash
32924 /
32925 \end_layout
32926
32927 \end_inset
32928
32929 -noinduction option) or for a given function only using #pragma\InsetSpace ~
32930 noinduction
32931 \begin_inset LatexCommand \index{\#pragma noinduction}
32932
32933 \end_inset
32934
32935 .
32936 \newline
32937
32938 \newline
32939 Loop Invariant:
32940 \end_layout
32941
32942 \begin_layout Verse
32943
32944 \family typewriter
32945 for (i = 0 ; i < 100 ; i ++) 
32946 \newline
32947 \InsetSpace ~
32948 \InsetSpace ~
32949 \InsetSpace ~
32950 \InsetSpace ~
32951 f += k + l;
32952 \end_layout
32953
32954 \begin_layout Standard
32955 changed to
32956 \end_layout
32957
32958 \begin_layout Verse
32959
32960 \family typewriter
32961 itemp = k + l; 
32962 \newline
32963 for (i = 0; i < 100; i++) 
32964 \newline
32965 \InsetSpace ~
32966 \InsetSpace ~
32967 \InsetSpace ~
32968 \InsetSpace ~
32969 f += itemp;
32970 \end_layout
32971
32972 \begin_layout Standard
32973 As mentioned previously some loop invariants are not as apparent, all static
32974  address computations are also moved out of the loop.
32975 \newline
32976
32977 \newline
32978 Strength Reduction
32979 \begin_inset LatexCommand \index{Strength reduction}
32980
32981 \end_inset
32982
32983 , this optimization substitutes an expression by a cheaper expression:
32984 \end_layout
32985
32986 \begin_layout Verse
32987
32988 \family typewriter
32989 for (i=0;i < 100; i++)
32990 \newline
32991 \InsetSpace ~
32992 \InsetSpace ~
32993 \InsetSpace ~
32994 \InsetSpace ~
32995 ar[i*5] = i*3;
32996 \end_layout
32997
32998 \begin_layout Standard
32999 changed to
33000 \end_layout
33001
33002 \begin_layout Verse
33003
33004 \family typewriter
33005 itemp1 = 0; 
33006 \newline
33007 itemp2 = 0; 
33008 \newline
33009 for (i=0;i< 100;i++) { 
33010 \newline
33011 \InsetSpace ~
33012 \InsetSpace ~
33013 \InsetSpace ~
33014 \InsetSpace ~
33015 ar[itemp1] = itemp2; 
33016 \newline
33017 \InsetSpace ~
33018 \InsetSpace ~
33019 \InsetSpace ~
33020 \InsetSpace ~
33021 itemp1
33022  += 5; 
33023 \newline
33024 \InsetSpace ~
33025 \InsetSpace ~
33026 \InsetSpace ~
33027 \InsetSpace ~
33028 itemp2 += 3; 
33029 \newline
33030 }
33031 \end_layout
33032
33033 \begin_layout Standard
33034 The more expensive multiplication
33035 \begin_inset LatexCommand \index{Multiplication}
33036
33037 \end_inset
33038
33039  is changed to a less expensive addition.
33040 \end_layout
33041
33042 \begin_layout Subsection
33043 Loop Reversing
33044 \begin_inset LatexCommand \index{Loop reversing}
33045
33046 \end_inset
33047
33048
33049 \end_layout
33050
33051 \begin_layout Standard
33052 This optimization is done to reduce the overhead of checking loop boundaries
33053  for every iteration.
33054  Some simple loops can be reversed and implemented using a 
33055 \begin_inset Quotes eld
33056 \end_inset
33057
33058 decrement and jump if not zero
33059 \begin_inset Quotes erd
33060 \end_inset
33061
33062  instruction.
33063  SDCC checks for the following criterion to determine if a loop is reversible
33064  (note: more sophisticated compilers use data-dependency analysis to make
33065  this determination, SDCC uses a more simple minded analysis).
33066 \end_layout
33067
33068 \begin_layout Itemize
33069 The 'for' loop is of the form 
33070 \newline
33071
33072 \newline
33073
33074 \family typewriter
33075 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
33076  += 1])
33077 \newline
33078 \InsetSpace ~
33079 \InsetSpace ~
33080 \InsetSpace ~
33081 \InsetSpace ~
33082 <for body>
33083 \end_layout
33084
33085 \begin_layout Itemize
33086 The <for body> does not contain 
33087 \begin_inset Quotes eld
33088 \end_inset
33089
33090 continue
33091 \begin_inset Quotes erd
33092 \end_inset
33093
33094  or 'break
33095 \begin_inset Quotes erd
33096 \end_inset
33097
33098 .
33099 \end_layout
33100
33101 \begin_layout Itemize
33102 All goto's are contained within the loop.
33103 \end_layout
33104
33105 \begin_layout Itemize
33106 No function calls within the loop.
33107 \end_layout
33108
33109 \begin_layout Itemize
33110 The loop control variable <sym> is not assigned any value within the loop
33111 \end_layout
33112
33113 \begin_layout Itemize
33114 The loop control variable does NOT participate in any arithmetic operation
33115  within the loop.
33116 \end_layout
33117
33118 \begin_layout Itemize
33119 There are NO switch statements in the loop.
33120 \end_layout
33121
33122 \begin_layout Subsection
33123 Algebraic Simplifications
33124 \end_layout
33125
33126 \begin_layout Standard
33127 SDCC does numerous algebraic simplifications, the following is a small sub-set
33128  of these optimizations.
33129 \end_layout
33130
33131 \begin_layout Verse
33132
33133 \family typewriter
33134 i = j + 0;\InsetSpace ~
33135 \InsetSpace ~
33136 \InsetSpace ~
33137 \InsetSpace ~
33138  /* changed to: */\InsetSpace ~
33139 \InsetSpace ~
33140 \InsetSpace ~
33141 \InsetSpace ~
33142  i = j; 
33143 \newline
33144 i /= 2;\InsetSpace ~
33145 \InsetSpace ~
33146 \InsetSpace ~
33147 \InsetSpace ~
33148 \InsetSpace ~
33149 \InsetSpace ~
33150 \InsetSpace ~
33151  /* changed to: */\InsetSpace ~
33152 \InsetSpace ~
33153 \InsetSpace ~
33154 \InsetSpace ~
33155  i >>= 1; 
33156 \newline
33157 i
33158  = j - j;\InsetSpace ~
33159 \InsetSpace ~
33160 \InsetSpace ~
33161 \InsetSpace ~
33162  /* changed to: */\InsetSpace ~
33163 \InsetSpace ~
33164 \InsetSpace ~
33165 \InsetSpace ~
33166  i = 0; 
33167 \newline
33168 i = j / 1;\InsetSpace ~
33169 \InsetSpace ~
33170 \InsetSpace ~
33171 \InsetSpace ~
33172  /* changed to: */\InsetSpace ~
33173 \InsetSpace ~
33174 \InsetSpace ~
33175 \InsetSpace ~
33176  i = j;
33177 \end_layout
33178
33179 \begin_layout Standard
33180 Note the subexpressions
33181 \begin_inset LatexCommand \index{Subexpression}
33182
33183 \end_inset
33184
33185  given above are generally introduced by macro expansions or as a result
33186  of copy/constant propagation.
33187 \end_layout
33188
33189 \begin_layout Subsection
33190 'switch' Statements
33191 \begin_inset LatexCommand \label{sub:'switch'-Statements}
33192
33193 \end_inset
33194
33195
33196 \begin_inset LatexCommand \index{switch statement}
33197
33198 \end_inset
33199
33200
33201 \end_layout
33202
33203 \begin_layout Standard
33204 SDCC can optimize switch statements to jump tables
33205 \begin_inset LatexCommand \index{jump tables}
33206
33207 \end_inset
33208
33209 .
33210  It makes the decision based on an estimate of the generated code size.
33211  SDCC is quite liberal in the requirements for jump table generation: 
33212 \end_layout
33213
33214 \begin_layout Itemize
33215 The labels need not be in order, and the starting number need not be one
33216  or zero, the case labels are in numerical sequence or not too many case
33217  labels are missing.
33218 \end_layout
33219
33220 \begin_deeper
33221 \begin_layout Verse
33222
33223 \family typewriter
33224 switch(i) {\InsetSpace ~
33225 \InsetSpace ~
33226 \InsetSpace ~
33227 \InsetSpace ~
33228 \InsetSpace ~
33229 \InsetSpace ~
33230 \InsetSpace ~
33231 \InsetSpace ~
33232 \InsetSpace ~
33233 \InsetSpace ~
33234 \InsetSpace ~
33235 \InsetSpace ~
33236 \InsetSpace ~
33237 \InsetSpace ~
33238 \InsetSpace ~
33239 \InsetSpace ~
33240 \InsetSpace ~
33241 \InsetSpace ~
33242 \InsetSpace ~
33243 \InsetSpace ~
33244 \InsetSpace ~
33245 \InsetSpace ~
33246 \InsetSpace ~
33247 \InsetSpace ~
33248 \InsetSpace ~
33249 \InsetSpace ~
33250 switch (i) { 
33251 \newline
33252 \InsetSpace ~
33253 \InsetSpace ~
33254 \InsetSpace ~
33255 case 4: ...\InsetSpace ~
33256 \InsetSpace ~
33257 \InsetSpace ~
33258 \InsetSpace ~
33259 \InsetSpace ~
33260 \InsetSpace ~
33261 \InsetSpace ~
33262 \InsetSpace ~
33263 \InsetSpace ~
33264 \InsetSpace ~
33265 \InsetSpace ~
33266 \InsetSpace ~
33267 \InsetSpace ~
33268 \InsetSpace ~
33269 \InsetSpace ~
33270 \InsetSpace ~
33271 \InsetSpace ~
33272 \InsetSpace ~
33273 \InsetSpace ~
33274 \InsetSpace ~
33275 \InsetSpace ~
33276 \InsetSpace ~
33277 \InsetSpace ~
33278 \InsetSpace ~
33279 \InsetSpace ~
33280 \InsetSpace ~
33281 case 0: ...
33282  
33283 \newline
33284 \InsetSpace ~
33285 \InsetSpace ~
33286 \InsetSpace ~
33287 case 5: ...\InsetSpace ~
33288 \InsetSpace ~
33289 \InsetSpace ~
33290 \InsetSpace ~
33291 \InsetSpace ~
33292 \InsetSpace ~
33293 \InsetSpace ~
33294 \InsetSpace ~
33295 \InsetSpace ~
33296 \InsetSpace ~
33297 \InsetSpace ~
33298 \InsetSpace ~
33299 \InsetSpace ~
33300 \InsetSpace ~
33301 \InsetSpace ~
33302 \InsetSpace ~
33303 \InsetSpace ~
33304 \InsetSpace ~
33305 \InsetSpace ~
33306 \InsetSpace ~
33307 \InsetSpace ~
33308 \InsetSpace ~
33309 \InsetSpace ~
33310 \InsetSpace ~
33311 \InsetSpace ~
33312 \InsetSpace ~
33313 case 1: ...
33314  
33315 \newline
33316 \InsetSpace ~
33317 \InsetSpace ~
33318 \InsetSpace ~
33319 case 3: ...\InsetSpace ~
33320 \InsetSpace ~
33321 \InsetSpace ~
33322 \InsetSpace ~
33323 \InsetSpace ~
33324 \InsetSpace ~
33325 \InsetSpace ~
33326 \InsetSpace ~
33327 \InsetSpace ~
33328 \InsetSpace ~
33329 \InsetSpace ~
33330 \InsetSpace ~
33331 \InsetSpace ~
33332 \InsetSpace ~
33333 \InsetSpace ~
33334 \InsetSpace ~
33335 \InsetSpace ~
33336 \InsetSpace ~
33337 \InsetSpace ~
33338 \InsetSpace ~
33339 \InsetSpace ~
33340 \InsetSpace ~
33341 \InsetSpace ~
33342 \InsetSpace ~
33343 \InsetSpace ~
33344 \InsetSpace ~
33345
33346 \newline
33347 \InsetSpace ~
33348 \InsetSpace ~
33349 \InsetSpace ~
33350 case 6: ...\InsetSpace ~
33351 \InsetSpace ~
33352 \InsetSpace ~
33353 \InsetSpace ~
33354 \InsetSpace ~
33355 \InsetSpace ~
33356 \InsetSpace ~
33357 \InsetSpace ~
33358 \InsetSpace ~
33359 \InsetSpace ~
33360 \InsetSpace ~
33361 \InsetSpace ~
33362 \InsetSpace ~
33363 \InsetSpace ~
33364 \InsetSpace ~
33365 \InsetSpace ~
33366 \InsetSpace ~
33367 \InsetSpace ~
33368 \InsetSpace ~
33369 \InsetSpace ~
33370 \InsetSpace ~
33371 \InsetSpace ~
33372 \InsetSpace ~
33373 \InsetSpace ~
33374 \InsetSpace ~
33375 \InsetSpace ~
33376 case 3: ...
33377  
33378 \newline
33379 \InsetSpace ~
33380 \InsetSpace ~
33381 \InsetSpace ~
33382 case 7: ...\InsetSpace ~
33383 \InsetSpace ~
33384 \InsetSpace ~
33385 \InsetSpace ~
33386 \InsetSpace ~
33387 \InsetSpace ~
33388 \InsetSpace ~
33389 \InsetSpace ~
33390 \InsetSpace ~
33391 \InsetSpace ~
33392 \InsetSpace ~
33393 \InsetSpace ~
33394 \InsetSpace ~
33395 \InsetSpace ~
33396 \InsetSpace ~
33397 \InsetSpace ~
33398 \InsetSpace ~
33399 \InsetSpace ~
33400 \InsetSpace ~
33401 \InsetSpace ~
33402 \InsetSpace ~
33403 \InsetSpace ~
33404 \InsetSpace ~
33405 \InsetSpace ~
33406 \InsetSpace ~
33407 \InsetSpace ~
33408 case 4: ...
33409  
33410 \newline
33411 \InsetSpace ~
33412 \InsetSpace ~
33413 \InsetSpace ~
33414 case 8: ...\InsetSpace ~
33415 \InsetSpace ~
33416 \InsetSpace ~
33417 \InsetSpace ~
33418 \InsetSpace ~
33419 \InsetSpace ~
33420 \InsetSpace ~
33421 \InsetSpace ~
33422 \InsetSpace ~
33423 \InsetSpace ~
33424 \InsetSpace ~
33425 \InsetSpace ~
33426 \InsetSpace ~
33427 \InsetSpace ~
33428 \InsetSpace ~
33429 \InsetSpace ~
33430 \InsetSpace ~
33431 \InsetSpace ~
33432 \InsetSpace ~
33433 \InsetSpace ~
33434 \InsetSpace ~
33435 \InsetSpace ~
33436 \InsetSpace ~
33437 \InsetSpace ~
33438 \InsetSpace ~
33439 \InsetSpace ~
33440 case 5: ...
33441  
33442 \newline
33443 \InsetSpace ~
33444 \InsetSpace ~
33445 \InsetSpace ~
33446 case 9: ...\InsetSpace ~
33447 \InsetSpace ~
33448 \InsetSpace ~
33449 \InsetSpace ~
33450 \InsetSpace ~
33451 \InsetSpace ~
33452 \InsetSpace ~
33453 \InsetSpace ~
33454 \InsetSpace ~
33455 \InsetSpace ~
33456 \InsetSpace ~
33457 \InsetSpace ~
33458 \InsetSpace ~
33459 \InsetSpace ~
33460 \InsetSpace ~
33461 \InsetSpace ~
33462 \InsetSpace ~
33463 \InsetSpace ~
33464 \InsetSpace ~
33465 \InsetSpace ~
33466 \InsetSpace ~
33467 \InsetSpace ~
33468 \InsetSpace ~
33469 \InsetSpace ~
33470 \InsetSpace ~
33471 \InsetSpace ~
33472 case 6: ...
33473  
33474 \newline
33475 \InsetSpace ~
33476 \InsetSpace ~
33477 \InsetSpace ~
33478 case 10: ...\InsetSpace ~
33479 \InsetSpace ~
33480 \InsetSpace ~
33481 \InsetSpace ~
33482 \InsetSpace ~
33483 \InsetSpace ~
33484 \InsetSpace ~
33485 \InsetSpace ~
33486 \InsetSpace ~
33487 \InsetSpace ~
33488 \InsetSpace ~
33489 \InsetSpace ~
33490 \InsetSpace ~
33491 \InsetSpace ~
33492 \InsetSpace ~
33493 \InsetSpace ~
33494 \InsetSpace ~
33495 \InsetSpace ~
33496 \InsetSpace ~
33497 \InsetSpace ~
33498 \InsetSpace ~
33499 \InsetSpace ~
33500 \InsetSpace ~
33501 \InsetSpace ~
33502 \InsetSpace ~
33503 case 7: ...
33504  
33505 \newline
33506 \InsetSpace ~
33507 \InsetSpace ~
33508 \InsetSpace ~
33509 case 11: ...\InsetSpace ~
33510 \InsetSpace ~
33511 \InsetSpace ~
33512 \InsetSpace ~
33513 \InsetSpace ~
33514 \InsetSpace ~
33515 \InsetSpace ~
33516 \InsetSpace ~
33517 \InsetSpace ~
33518 \InsetSpace ~
33519 \InsetSpace ~
33520 \InsetSpace ~
33521 \InsetSpace ~
33522 \InsetSpace ~
33523 \InsetSpace ~
33524 \InsetSpace ~
33525 \InsetSpace ~
33526 \InsetSpace ~
33527 \InsetSpace ~
33528 \InsetSpace ~
33529 \InsetSpace ~
33530 \InsetSpace ~
33531 \InsetSpace ~
33532 \InsetSpace ~
33533 \InsetSpace ~
33534 case 8: ...
33535  
33536 \newline
33537 }\InsetSpace ~
33538 \InsetSpace ~
33539 \InsetSpace ~
33540 \InsetSpace ~
33541 \InsetSpace ~
33542 \InsetSpace ~
33543 \InsetSpace ~
33544 \InsetSpace ~
33545 \InsetSpace ~
33546 \InsetSpace ~
33547 \InsetSpace ~
33548 \InsetSpace ~
33549 \InsetSpace ~
33550 \InsetSpace ~
33551 \InsetSpace ~
33552 \InsetSpace ~
33553 \InsetSpace ~
33554 \InsetSpace ~
33555 \InsetSpace ~
33556 \InsetSpace ~
33557 \InsetSpace ~
33558 \InsetSpace ~
33559 \InsetSpace ~
33560 \InsetSpace ~
33561 \InsetSpace ~
33562 \InsetSpace ~
33563 \InsetSpace ~
33564 \InsetSpace ~
33565 \InsetSpace ~
33566 \InsetSpace ~
33567 \InsetSpace ~
33568 \InsetSpace ~
33569 \InsetSpace ~
33570 \InsetSpace ~
33571 \InsetSpace ~
33572 \InsetSpace ~
33573 }
33574 \end_layout
33575
33576 \begin_layout Standard
33577 Both the above switch statements will be implemented using a jump-table.
33578  The example to the right side is slightly more efficient as the check for
33579  the lower boundary of the jump-table is not needed.
33580 \end_layout
33581
33582 \end_deeper
33583 \begin_layout Itemize
33584 The number of case labels is not larger than supported by the target architectur
33585 e.
33586 \end_layout
33587
33588 \begin_layout Itemize
33589 If the case labels are not in numerical sequence ('gaps' between cases)
33590  SDCC checks whether a jump table with additionally inserted dummy cases
33591  is still attractive.
33592  
33593 \end_layout
33594
33595 \begin_layout Itemize
33596 If the starting number is not zero and a check for the lower boundary of
33597  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33598  ...
33599  .
33600 \end_layout
33601
33602 \begin_layout Standard
33603 Switch statements which have large gaps in the numeric sequence or those
33604  that have too many case labels can be split into more than one switch statement
33605  for efficient code generation, e.g.:
33606 \end_layout
33607
33608 \begin_layout Verse
33609
33610 \family typewriter
33611 switch (i) { 
33612 \newline
33613 \InsetSpace ~
33614 \InsetSpace ~
33615 case 1: ...
33616  
33617 \newline
33618 \InsetSpace ~
33619 \InsetSpace ~
33620 case 2: ...
33621  
33622 \newline
33623 \InsetSpace ~
33624 \InsetSpace ~
33625 case 3: ...
33626  
33627 \newline
33628 \InsetSpace ~
33629 \InsetSpace ~
33630 case 4: ...
33631  
33632 \newline
33633 \InsetSpace ~
33634 \InsetSpace ~
33635 case 5: ...
33636  
33637 \newline
33638 \InsetSpace ~
33639 \InsetSpace ~
33640 case 6: ...
33641  
33642 \newline
33643 \InsetSpace ~
33644 \InsetSpace ~
33645 case 7: ...
33646  
33647 \newline
33648 \InsetSpace ~
33649 \InsetSpace ~
33650 case 101: ...
33651  
33652 \newline
33653 \InsetSpace ~
33654 \InsetSpace ~
33655 case 102: ...
33656  
33657 \newline
33658 \InsetSpace ~
33659 \InsetSpace ~
33660 case 103: ...
33661  
33662 \newline
33663 \InsetSpace ~
33664 \InsetSpace ~
33665 case 104: ...
33666  
33667 \newline
33668 \InsetSpace ~
33669 \InsetSpace ~
33670 case 105: ...
33671  
33672 \newline
33673 \InsetSpace ~
33674 \InsetSpace ~
33675 case 106: ...
33676  
33677 \newline
33678 \InsetSpace ~
33679 \InsetSpace ~
33680 case 107: ...
33681  
33682 \newline
33683 }
33684 \end_layout
33685
33686 \begin_layout Standard
33687 If the above switch statement is broken down into two switch statements
33688 \end_layout
33689
33690 \begin_layout Verse
33691
33692 \family typewriter
33693 switch (i) { 
33694 \newline
33695 \InsetSpace ~
33696 \InsetSpace ~
33697 case 1: ...
33698  
33699 \newline
33700 \InsetSpace ~
33701 \InsetSpace ~
33702 case 2: ...
33703  
33704 \newline
33705 \InsetSpace ~
33706 \InsetSpace ~
33707 case 3: ...
33708  
33709 \newline
33710 \InsetSpace ~
33711 \InsetSpace ~
33712 case 4: ...
33713  
33714 \newline
33715 \InsetSpace ~
33716 \InsetSpace ~
33717 case 5: ...
33718  
33719 \newline
33720 \InsetSpace ~
33721 \InsetSpace ~
33722 case 6: ...
33723  
33724 \newline
33725 \InsetSpace ~
33726 \InsetSpace ~
33727 case 7: ...
33728  
33729 \newline
33730 }
33731 \end_layout
33732
33733 \begin_layout Standard
33734 and
33735 \end_layout
33736
33737 \begin_layout Verse
33738
33739 \family typewriter
33740 switch (i) { 
33741 \newline
33742 \InsetSpace ~
33743 \InsetSpace ~
33744 case 101: ...
33745  
33746 \newline
33747 \InsetSpace ~
33748 \InsetSpace ~
33749 case 102: ...
33750  
33751 \newline
33752 \InsetSpace ~
33753 \InsetSpace ~
33754 case 103: ...
33755  
33756 \newline
33757 \InsetSpace ~
33758 \InsetSpace ~
33759 case 104: ...
33760  
33761 \newline
33762 \InsetSpace ~
33763 \InsetSpace ~
33764 case 105: ...
33765  
33766 \newline
33767 \InsetSpace ~
33768 \InsetSpace ~
33769 case 106: ...
33770  
33771 \newline
33772 \InsetSpace ~
33773 \InsetSpace ~
33774 case 107: ...
33775  
33776 \newline
33777 }
33778 \end_layout
33779
33780 \begin_layout Standard
33781 then both the switch statements will be implemented using jump-tables whereas
33782  the unmodified switch statement will not be.
33783 \end_layout
33784
33785 \begin_layout Standard
33786 \begin_inset Note Note
33787 status collapsed
33788
33789 \begin_layout Standard
33790 There might be reasons which SDCC cannot know about to either favour or
33791  not favour jump tables.
33792  If the target system has to be as quick for the last switch case as for
33793  the first (pro jump table), or if the switch argument is known to be zero
33794  in the majority of the cases (contra jump table).
33795 \end_layout
33796
33797 \end_inset
33798
33799
33800 \end_layout
33801
33802 \begin_layout Standard
33803 The pragma nojtbound
33804 \begin_inset LatexCommand \index{\#pragma nojtbound}
33805
33806 \end_inset
33807
33808  can be used to turn off checking the 
33809 \emph on
33810 j
33811 \emph default
33812 ump 
33813 \emph on
33814 t
33815 \emph default
33816 able 
33817 \emph on
33818 bound
33819 \emph default
33820 aries.
33821  It has no effect if a default label is supplied.
33822  Use of this pragma is dangerous: if the switch
33823 \begin_inset LatexCommand \index{switch statement}
33824
33825 \end_inset
33826
33827  argument is not matched by a case statement the processor will happily
33828  jump into Nirvana.
33829 \end_layout
33830
33831 \begin_layout Subsection
33832 Bit-shifting Operations
33833 \begin_inset LatexCommand \index{Bit shifting}
33834
33835 \end_inset
33836
33837 .
33838 \end_layout
33839
33840 \begin_layout Standard
33841 Bit shifting is one of the most frequently used operation in embedded programmin
33842 g.
33843  SDCC tries to implement bit-shift operations in the most efficient way
33844  possible, e.g.:
33845 \end_layout
33846
33847 \begin_layout Verse
33848
33849 \family typewriter
33850 unsigned char i;
33851 \newline
33852 ...
33853  
33854 \newline
33855 i >>= 4; 
33856 \newline
33857 ...
33858 \end_layout
33859
33860 \begin_layout Standard
33861 generates the following code:
33862 \end_layout
33863
33864 \begin_layout Verse
33865
33866 \family typewriter
33867 mov\InsetSpace ~
33868  a,_i 
33869 \newline
33870 swap a 
33871 \newline
33872 anl\InsetSpace ~
33873  a,#0x0f 
33874 \newline
33875 mov\InsetSpace ~
33876  _i,a
33877 \end_layout
33878
33879 \begin_layout Standard
33880 In general SDCC will never setup a loop if the shift count is known.
33881  Another example:
33882 \end_layout
33883
33884 \begin_layout Verse
33885
33886 \family typewriter
33887 unsigned int i; 
33888 \newline
33889 ...
33890  
33891 \newline
33892 i >>= 9; 
33893 \newline
33894 ...
33895 \end_layout
33896
33897 \begin_layout Standard
33898 will generate:
33899 \end_layout
33900
33901 \begin_layout Verse
33902
33903 \family typewriter
33904 mov\InsetSpace ~
33905 \InsetSpace ~
33906 a,(_i + 1) 
33907 \newline
33908 mov\InsetSpace ~
33909 \InsetSpace ~
33910 (_i + 1),#0x00 
33911 \newline
33912 clr\InsetSpace ~
33913 \InsetSpace ~
33914
33915 \newline
33916 rrc\InsetSpace ~
33917 \InsetSpace ~
33918
33919 \newline
33920 mov\InsetSpace ~
33921 \InsetSpace ~
33922 _i,a
33923 \end_layout
33924
33925 \begin_layout Subsection
33926 Bit-rotation
33927 \begin_inset LatexCommand \index{Bit rotation}
33928
33929 \end_inset
33930
33931
33932 \end_layout
33933
33934 \begin_layout Standard
33935 A special case of the bit-shift operation is bit rotation
33936 \begin_inset LatexCommand \index{rotating bits}
33937
33938 \end_inset
33939
33940 , SDCC recognizes the following expression to be a left bit-rotation:
33941 \end_layout
33942
33943 \begin_layout Verse
33944
33945 \family typewriter
33946 \series bold
33947 unsigned
33948 \series default
33949 \InsetSpace ~
33950 \InsetSpace ~
33951 char i;\InsetSpace ~
33952 \InsetSpace ~
33953 \InsetSpace ~
33954 \InsetSpace ~
33955 \InsetSpace ~
33956 \InsetSpace ~
33957 \InsetSpace ~
33958 \InsetSpace ~
33959 \InsetSpace ~
33960 \InsetSpace ~
33961 \InsetSpace ~
33962 /* unsigned is needed for rotation */ 
33963 \newline
33964 ...
33965  
33966 \newline
33967 i = ((i << 1) | (i >> 7)); 
33968 \family default
33969
33970 \newline
33971
33972 \family typewriter
33973 ...
33974 \end_layout
33975
33976 \begin_layout Standard
33977 will generate the following code:
33978 \end_layout
33979
33980 \begin_layout Verse
33981
33982 \family typewriter
33983 mov\InsetSpace ~
33984 \InsetSpace ~
33985 a,_i 
33986 \newline
33987 rl\InsetSpace ~
33988 \InsetSpace ~
33989 \InsetSpace ~
33990
33991 \newline
33992 mov\InsetSpace ~
33993 \InsetSpace ~
33994 _i,a
33995 \end_layout
33996
33997 \begin_layout Standard
33998 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
33999 ns of this case will also be recognized as bit-rotation, i.e.: 
34000 \end_layout
34001
34002 \begin_layout Verse
34003
34004 \family typewriter
34005 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
34006 \end_layout
34007
34008 \begin_layout Subsection
34009 Nibble and Byte Swapping
34010 \end_layout
34011
34012 \begin_layout Standard
34013 Other special cases of the bit-shift operations are nibble or byte swapping
34014 \begin_inset LatexCommand \index{swapping nibbles/bytes}
34015
34016 \end_inset
34017
34018 , SDCC recognizes the following expressions:
34019 \end_layout
34020
34021 \begin_layout Verse
34022
34023 \family typewriter
34024 \series bold
34025 unsigned
34026 \series default
34027 \InsetSpace ~
34028 \InsetSpace ~
34029 char i; 
34030 \newline
34031
34032 \series bold
34033 unsigned
34034 \series default
34035 \InsetSpace ~
34036 \InsetSpace ~
34037 int j; 
34038 \newline
34039 ...
34040  
34041 \newline
34042 i = ((i << 4) | (i >> 4)); 
34043 \family default
34044
34045 \newline
34046
34047 \family typewriter
34048 j = ((j << 8) | (j >> 8)); 
34049 \end_layout
34050
34051 \begin_layout Standard
34052 and generates a swap instruction for the nibble swapping
34053 \begin_inset LatexCommand \index{Nibble swapping}
34054
34055 \end_inset
34056
34057  or move instructions for the byte swapping
34058 \begin_inset LatexCommand \index{Byte swapping}
34059
34060 \end_inset
34061
34062 .
34063  The 
34064 \begin_inset Quotes sld
34065 \end_inset
34066
34067 j
34068 \begin_inset Quotes srd
34069 \end_inset
34070
34071  example can be used to convert from little to big-endian or vice versa.
34072  If you want to change the endianness of a 
34073 \emph on
34074 signed
34075 \emph default
34076  integer you have to cast to 
34077 \family typewriter
34078 (unsigned int)
34079 \family default
34080  first.
34081 \end_layout
34082
34083 \begin_layout Standard
34084 Note that SDCC stores numbers in little-endian
34085 \begin_inset Foot
34086 status open
34087
34088 \begin_layout Standard
34089 Usually 8-bit processors don't care much about endianness.
34090  This is not the case for the standard 8051 which only has an instruction
34091  to increment its 
34092 \emph on
34093 dptr
34094 \emph default
34095
34096 \begin_inset LatexCommand \index{DPTR}
34097
34098 \end_inset
34099
34100 -datapointer
34101 \emph on
34102  
34103 \emph default
34104 so little-endian is the more efficient byte order.
34105 \end_layout
34106
34107 \end_inset
34108
34109
34110 \begin_inset LatexCommand \index{little-endian}
34111
34112 \end_inset
34113
34114
34115 \begin_inset LatexCommand \index{Endianness}
34116
34117 \end_inset
34118
34119  format (i.e.
34120  lowest order first).
34121 \end_layout
34122
34123 \begin_layout Subsection
34124 Highest Order Bit
34125 \begin_inset LatexCommand \index{Highest Order Bit}
34126
34127 \end_inset
34128
34129  / Any Order Bit
34130 \begin_inset LatexCommand \index{Any Order Bit}
34131
34132 \end_inset
34133
34134
34135 \end_layout
34136
34137 \begin_layout Standard
34138 It is frequently required to obtain the highest order bit of an integral
34139  type (long, int, short or char types).
34140  Also obtaining any other order bit is not uncommon.
34141  SDCC recognizes the following expressions to yield the highest order bit
34142  and generates optimized code for it, e.g.:
34143 \end_layout
34144
34145 \begin_layout Verse
34146
34147 \family typewriter
34148 unsigned int gint; 
34149 \newline
34150
34151 \newline
34152 foo () { 
34153 \newline
34154 \InsetSpace ~
34155 \InsetSpace ~
34156 unsigned char hob1, aob1; 
34157 \newline
34158 \InsetSpace ~
34159 \InsetSpace ~
34160 bit hob2, hob3, aob2,
34161  aob3; 
34162 \newline
34163 \InsetSpace ~
34164 \InsetSpace ~
34165 ...
34166  
34167 \newline
34168 \InsetSpace ~
34169 \InsetSpace ~
34170 hob1 = (gint >> 15) & 1; 
34171 \newline
34172 \InsetSpace ~
34173 \InsetSpace ~
34174 hob2 = (gint >> 15) & 1; 
34175 \newline
34176 \InsetSpace ~
34177 \InsetSpace ~
34178 hob3 = gint & 0x8000;
34179  
34180 \newline
34181 \InsetSpace ~
34182 \InsetSpace ~
34183 aob1 = (gint >> 9) & 1; 
34184 \newline
34185 \InsetSpace ~
34186 \InsetSpace ~
34187 aob2 = (gint >> 8) & 1; 
34188 \newline
34189 \InsetSpace ~
34190 \InsetSpace ~
34191 aob3 = gint & 0x0800; 
34192 \newline
34193 \InsetSpace ~
34194 \InsetSpace ~
34195 ..
34196  
34197 \newline
34198 }
34199 \end_layout
34200
34201 \begin_layout Standard
34202 will generate the following code:
34203 \end_layout
34204
34205 \begin_layout Verse
34206
34207 \family typewriter
34208 \InsetSpace ~
34209 \InsetSpace ~
34210 \InsetSpace ~
34211 \InsetSpace ~
34212 \InsetSpace ~
34213 \InsetSpace ~
34214 \InsetSpace ~
34215 \InsetSpace ~
34216 \InsetSpace ~
34217 \InsetSpace ~
34218 \InsetSpace ~
34219 \InsetSpace ~
34220 \InsetSpace ~
34221 \InsetSpace ~
34222 \InsetSpace ~
34223 \InsetSpace ~
34224 \InsetSpace ~
34225 \InsetSpace ~
34226 \InsetSpace ~
34227 \InsetSpace ~
34228 \InsetSpace ~
34229 \InsetSpace ~
34230 \InsetSpace ~
34231 \InsetSpace ~
34232 \InsetSpace ~
34233  61 ;\InsetSpace ~
34234  hob.c 7 
34235 \newline
34236 000A E5*01\InsetSpace ~
34237 \InsetSpace ~
34238 \InsetSpace ~
34239 \InsetSpace ~
34240 \InsetSpace ~
34241 \InsetSpace ~
34242 \InsetSpace ~
34243 \InsetSpace ~
34244 \InsetSpace ~
34245 \InsetSpace ~
34246 \InsetSpace ~
34247 \InsetSpace ~
34248 \InsetSpace ~
34249 \InsetSpace ~
34250 \InsetSpace ~
34251  62\InsetSpace ~
34252 \InsetSpace ~
34253 \InsetSpace ~
34254 \InsetSpace ~
34255 \InsetSpace ~
34256 \InsetSpace ~
34257 \InsetSpace ~
34258 \InsetSpace ~
34259  mov\InsetSpace ~
34260 \InsetSpace ~
34261  a,(_gint + 1) 
34262 \newline
34263 000C 23\InsetSpace ~
34264 \InsetSpace ~
34265 \InsetSpace ~
34266 \InsetSpace ~
34267 \InsetSpace ~
34268 \InsetSpace ~
34269 \InsetSpace ~
34270 \InsetSpace ~
34271 \InsetSpace ~
34272 \InsetSpace ~
34273 \InsetSpace ~
34274 \InsetSpace ~
34275 \InsetSpace ~
34276 \InsetSpace ~
34277 \InsetSpace ~
34278 \InsetSpace ~
34279 \InsetSpace ~
34280 \InsetSpace ~
34281  63\InsetSpace ~
34282 \InsetSpace ~
34283 \InsetSpace ~
34284 \InsetSpace ~
34285 \InsetSpace ~
34286 \InsetSpace ~
34287 \InsetSpace ~
34288 \InsetSpace ~
34289  rl\InsetSpace ~
34290 \InsetSpace ~
34291 \InsetSpace ~
34292  a 
34293 \newline
34294 000D 54 01\InsetSpace ~
34295 \InsetSpace ~
34296 \InsetSpace ~
34297 \InsetSpace ~
34298 \InsetSpace ~
34299 \InsetSpace ~
34300 \InsetSpace ~
34301 \InsetSpace ~
34302 \InsetSpace ~
34303 \InsetSpace ~
34304 \InsetSpace ~
34305 \InsetSpace ~
34306 \InsetSpace ~
34307 \InsetSpace ~
34308 \InsetSpace ~
34309
34310  64\InsetSpace ~
34311 \InsetSpace ~
34312 \InsetSpace ~
34313 \InsetSpace ~
34314 \InsetSpace ~
34315 \InsetSpace ~
34316 \InsetSpace ~
34317 \InsetSpace ~
34318  anl\InsetSpace ~
34319 \InsetSpace ~
34320  a,#0x01 
34321 \newline
34322 000F F5*02\InsetSpace ~
34323 \InsetSpace ~
34324 \InsetSpace ~
34325 \InsetSpace ~
34326 \InsetSpace ~
34327 \InsetSpace ~
34328 \InsetSpace ~
34329 \InsetSpace ~
34330 \InsetSpace ~
34331 \InsetSpace ~
34332 \InsetSpace ~
34333 \InsetSpace ~
34334 \InsetSpace ~
34335 \InsetSpace ~
34336 \InsetSpace ~
34337  65\InsetSpace ~
34338 \InsetSpace ~
34339 \InsetSpace ~
34340 \InsetSpace ~
34341 \InsetSpace ~
34342 \InsetSpace ~
34343 \InsetSpace ~
34344 \InsetSpace ~
34345  mov\InsetSpace ~
34346 \InsetSpace ~
34347  _foo_hob1_1_1,a 
34348 \newline
34349 \InsetSpace ~
34350 \InsetSpace ~
34351 \InsetSpace ~
34352 \InsetSpace ~
34353 \InsetSpace ~
34354 \InsetSpace ~
34355 \InsetSpace ~
34356 \InsetSpace ~
34357 \InsetSpace ~
34358 \InsetSpace ~
34359 \InsetSpace ~
34360 \InsetSpace ~
34361 \InsetSpace ~
34362 \InsetSpace ~
34363 \InsetSpace ~
34364 \InsetSpace ~
34365 \InsetSpace ~
34366 \InsetSpace ~
34367 \InsetSpace ~
34368 \InsetSpace ~
34369 \InsetSpace ~
34370 \InsetSpace ~
34371 \InsetSpace ~
34372 \InsetSpace ~
34373 \InsetSpace ~
34374  66 ;\InsetSpace ~
34375  hob.c 8 
34376 \newline
34377 0011 E5*01\InsetSpace ~
34378 \InsetSpace ~
34379 \InsetSpace ~
34380 \InsetSpace ~
34381 \InsetSpace ~
34382 \InsetSpace ~
34383 \InsetSpace ~
34384 \InsetSpace ~
34385 \InsetSpace ~
34386 \InsetSpace ~
34387 \InsetSpace ~
34388 \InsetSpace ~
34389 \InsetSpace ~
34390 \InsetSpace ~
34391 \InsetSpace ~
34392
34393  67\InsetSpace ~
34394 \InsetSpace ~
34395 \InsetSpace ~
34396 \InsetSpace ~
34397 \InsetSpace ~
34398 \InsetSpace ~
34399 \InsetSpace ~
34400 \InsetSpace ~
34401  mov\InsetSpace ~
34402 \InsetSpace ~
34403  a,(_gint + 1) 
34404 \newline
34405 0013 33\InsetSpace ~
34406 \InsetSpace ~
34407 \InsetSpace ~
34408 \InsetSpace ~
34409 \InsetSpace ~
34410 \InsetSpace ~
34411 \InsetSpace ~
34412 \InsetSpace ~
34413 \InsetSpace ~
34414 \InsetSpace ~
34415 \InsetSpace ~
34416 \InsetSpace ~
34417 \InsetSpace ~
34418 \InsetSpace ~
34419 \InsetSpace ~
34420 \InsetSpace ~
34421 \InsetSpace ~
34422 \InsetSpace ~
34423  68\InsetSpace ~
34424 \InsetSpace ~
34425 \InsetSpace ~
34426 \InsetSpace ~
34427 \InsetSpace ~
34428 \InsetSpace ~
34429 \InsetSpace ~
34430 \InsetSpace ~
34431  rlc\InsetSpace ~
34432 \InsetSpace ~
34433  a 
34434 \newline
34435 0014 92*00\InsetSpace ~
34436 \InsetSpace ~
34437 \InsetSpace ~
34438 \InsetSpace ~
34439 \InsetSpace ~
34440 \InsetSpace ~
34441 \InsetSpace ~
34442 \InsetSpace ~
34443 \InsetSpace ~
34444 \InsetSpace ~
34445 \InsetSpace ~
34446 \InsetSpace ~
34447 \InsetSpace ~
34448 \InsetSpace ~
34449 \InsetSpace ~
34450  69\InsetSpace ~
34451 \InsetSpace ~
34452 \InsetSpace ~
34453 \InsetSpace ~
34454 \InsetSpace ~
34455 \InsetSpace ~
34456 \InsetSpace ~
34457 \InsetSpace ~
34458  mov\InsetSpace ~
34459 \InsetSpace ~
34460  _foo_hob2_1_1,c
34461  
34462 \newline
34463 \InsetSpace ~
34464 \InsetSpace ~
34465 \InsetSpace ~
34466 \InsetSpace ~
34467 \InsetSpace ~
34468 \InsetSpace ~
34469 \InsetSpace ~
34470 \InsetSpace ~
34471 \InsetSpace ~
34472 \InsetSpace ~
34473 \InsetSpace ~
34474 \InsetSpace ~
34475 \InsetSpace ~
34476 \InsetSpace ~
34477 \InsetSpace ~
34478 \InsetSpace ~
34479 \InsetSpace ~
34480 \InsetSpace ~
34481 \InsetSpace ~
34482 \InsetSpace ~
34483 \InsetSpace ~
34484 \InsetSpace ~
34485 \InsetSpace ~
34486 \InsetSpace ~
34487 \InsetSpace ~
34488  66 ;\InsetSpace ~
34489  hob.c 9 
34490 \newline
34491 0016 E5*01\InsetSpace ~
34492 \InsetSpace ~
34493 \InsetSpace ~
34494 \InsetSpace ~
34495 \InsetSpace ~
34496 \InsetSpace ~
34497 \InsetSpace ~
34498 \InsetSpace ~
34499 \InsetSpace ~
34500 \InsetSpace ~
34501 \InsetSpace ~
34502 \InsetSpace ~
34503 \InsetSpace ~
34504 \InsetSpace ~
34505 \InsetSpace ~
34506  67\InsetSpace ~
34507 \InsetSpace ~
34508 \InsetSpace ~
34509 \InsetSpace ~
34510 \InsetSpace ~
34511 \InsetSpace ~
34512 \InsetSpace ~
34513 \InsetSpace ~
34514  mov\InsetSpace ~
34515 \InsetSpace ~
34516  a,(_gint + 1) 
34517 \newline
34518 0018 33\InsetSpace ~
34519 \InsetSpace ~
34520 \InsetSpace ~
34521 \InsetSpace ~
34522 \InsetSpace ~
34523 \InsetSpace ~
34524 \InsetSpace ~
34525 \InsetSpace ~
34526 \InsetSpace ~
34527 \InsetSpace ~
34528 \InsetSpace ~
34529 \InsetSpace ~
34530 \InsetSpace ~
34531 \InsetSpace ~
34532 \InsetSpace ~
34533 \InsetSpace ~
34534 \InsetSpace ~
34535 \InsetSpace ~
34536  68\InsetSpace ~
34537 \InsetSpace ~
34538 \InsetSpace ~
34539 \InsetSpace ~
34540 \InsetSpace ~
34541 \InsetSpace ~
34542 \InsetSpace ~
34543 \InsetSpace ~
34544  rlc\InsetSpace ~
34545 \InsetSpace ~
34546  a 
34547 \newline
34548 0019 92*01\InsetSpace ~
34549 \InsetSpace ~
34550 \InsetSpace ~
34551 \InsetSpace ~
34552 \InsetSpace ~
34553 \InsetSpace ~
34554 \InsetSpace ~
34555 \InsetSpace ~
34556 \InsetSpace ~
34557 \InsetSpace ~
34558 \InsetSpace ~
34559 \InsetSpace ~
34560 \InsetSpace ~
34561 \InsetSpace ~
34562 \InsetSpace ~
34563
34564  69\InsetSpace ~
34565 \InsetSpace ~
34566 \InsetSpace ~
34567 \InsetSpace ~
34568 \InsetSpace ~
34569 \InsetSpace ~
34570 \InsetSpace ~
34571 \InsetSpace ~
34572  mov\InsetSpace ~
34573 \InsetSpace ~
34574  _foo_hob3_1_1,c 
34575 \newline
34576 \InsetSpace ~
34577 \InsetSpace ~
34578 \InsetSpace ~
34579 \InsetSpace ~
34580 \InsetSpace ~
34581 \InsetSpace ~
34582 \InsetSpace ~
34583 \InsetSpace ~
34584 \InsetSpace ~
34585 \InsetSpace ~
34586 \InsetSpace ~
34587 \InsetSpace ~
34588 \InsetSpace ~
34589 \InsetSpace ~
34590 \InsetSpace ~
34591 \InsetSpace ~
34592 \InsetSpace ~
34593 \InsetSpace ~
34594 \InsetSpace ~
34595 \InsetSpace ~
34596 \InsetSpace ~
34597 \InsetSpace ~
34598 \InsetSpace ~
34599 \InsetSpace ~
34600 \InsetSpace ~
34601  70 ;\InsetSpace ~
34602  hob.c 10 
34603 \newline
34604 001B E5*01\InsetSpace ~
34605 \InsetSpace ~
34606 \InsetSpace ~
34607 \InsetSpace ~
34608 \InsetSpace ~
34609 \InsetSpace ~
34610 \InsetSpace ~
34611 \InsetSpace ~
34612 \InsetSpace ~
34613 \InsetSpace ~
34614 \InsetSpace ~
34615 \InsetSpace ~
34616 \InsetSpace ~
34617 \InsetSpace ~
34618 \InsetSpace ~
34619  71\InsetSpace ~
34620 \InsetSpace ~
34621 \InsetSpace ~
34622 \InsetSpace ~
34623 \InsetSpace ~
34624 \InsetSpace ~
34625 \InsetSpace ~
34626 \InsetSpace ~
34627  mov\InsetSpace ~
34628 \InsetSpace ~
34629  a,(_gint + 1) 
34630 \newline
34631 001D
34632  03\InsetSpace ~
34633 \InsetSpace ~
34634 \InsetSpace ~
34635 \InsetSpace ~
34636 \InsetSpace ~
34637 \InsetSpace ~
34638 \InsetSpace ~
34639 \InsetSpace ~
34640 \InsetSpace ~
34641 \InsetSpace ~
34642 \InsetSpace ~
34643 \InsetSpace ~
34644 \InsetSpace ~
34645 \InsetSpace ~
34646 \InsetSpace ~
34647 \InsetSpace ~
34648 \InsetSpace ~
34649 \InsetSpace ~
34650  72\InsetSpace ~
34651 \InsetSpace ~
34652 \InsetSpace ~
34653 \InsetSpace ~
34654 \InsetSpace ~
34655 \InsetSpace ~
34656 \InsetSpace ~
34657 \InsetSpace ~
34658  rr\InsetSpace ~
34659 \InsetSpace ~
34660 \InsetSpace ~
34661  a 
34662 \newline
34663 001E 54 01\InsetSpace ~
34664 \InsetSpace ~
34665 \InsetSpace ~
34666 \InsetSpace ~
34667 \InsetSpace ~
34668 \InsetSpace ~
34669 \InsetSpace ~
34670 \InsetSpace ~
34671 \InsetSpace ~
34672 \InsetSpace ~
34673 \InsetSpace ~
34674 \InsetSpace ~
34675 \InsetSpace ~
34676 \InsetSpace ~
34677 \InsetSpace ~
34678  73\InsetSpace ~
34679 \InsetSpace ~
34680 \InsetSpace ~
34681 \InsetSpace ~
34682 \InsetSpace ~
34683 \InsetSpace ~
34684 \InsetSpace ~
34685 \InsetSpace ~
34686  anl\InsetSpace ~
34687 \InsetSpace ~
34688  a,#0x01 
34689 \newline
34690 0020 F5*03\InsetSpace ~
34691 \InsetSpace ~
34692 \InsetSpace ~
34693 \InsetSpace ~
34694 \InsetSpace ~
34695 \InsetSpace ~
34696 \InsetSpace ~
34697 \InsetSpace ~
34698 \InsetSpace ~
34699 \InsetSpace ~
34700 \InsetSpace ~
34701 \InsetSpace ~
34702 \InsetSpace ~
34703 \InsetSpace ~
34704 \InsetSpace ~
34705  74\InsetSpace ~
34706 \InsetSpace ~
34707 \InsetSpace ~
34708 \InsetSpace ~
34709 \InsetSpace ~
34710 \InsetSpace ~
34711 \InsetSpace ~
34712 \InsetSpace ~
34713  mov\InsetSpace ~
34714 \InsetSpace ~
34715  _foo_aob1_1_1,a
34716  
34717 \newline
34718 \InsetSpace ~
34719 \InsetSpace ~
34720 \InsetSpace ~
34721 \InsetSpace ~
34722 \InsetSpace ~
34723 \InsetSpace ~
34724 \InsetSpace ~
34725 \InsetSpace ~
34726 \InsetSpace ~
34727 \InsetSpace ~
34728 \InsetSpace ~
34729 \InsetSpace ~
34730 \InsetSpace ~
34731 \InsetSpace ~
34732 \InsetSpace ~
34733 \InsetSpace ~
34734 \InsetSpace ~
34735 \InsetSpace ~
34736 \InsetSpace ~
34737 \InsetSpace ~
34738 \InsetSpace ~
34739 \InsetSpace ~
34740 \InsetSpace ~
34741 \InsetSpace ~
34742 \InsetSpace ~
34743  75 ;\InsetSpace ~
34744  hob.c 11 
34745 \newline
34746 0022 E5*01\InsetSpace ~
34747 \InsetSpace ~
34748 \InsetSpace ~
34749 \InsetSpace ~
34750 \InsetSpace ~
34751 \InsetSpace ~
34752 \InsetSpace ~
34753 \InsetSpace ~
34754 \InsetSpace ~
34755 \InsetSpace ~
34756 \InsetSpace ~
34757 \InsetSpace ~
34758 \InsetSpace ~
34759 \InsetSpace ~
34760 \InsetSpace ~
34761  76\InsetSpace ~
34762 \InsetSpace ~
34763 \InsetSpace ~
34764 \InsetSpace ~
34765 \InsetSpace ~
34766 \InsetSpace ~
34767 \InsetSpace ~
34768 \InsetSpace ~
34769  mov\InsetSpace ~
34770 \InsetSpace ~
34771  a,(_gint + 1) 
34772 \newline
34773 0024 13\InsetSpace ~
34774 \InsetSpace ~
34775 \InsetSpace ~
34776 \InsetSpace ~
34777 \InsetSpace ~
34778 \InsetSpace ~
34779 \InsetSpace ~
34780 \InsetSpace ~
34781 \InsetSpace ~
34782 \InsetSpace ~
34783 \InsetSpace ~
34784 \InsetSpace ~
34785 \InsetSpace ~
34786 \InsetSpace ~
34787 \InsetSpace ~
34788 \InsetSpace ~
34789 \InsetSpace ~
34790 \InsetSpace ~
34791  77\InsetSpace ~
34792 \InsetSpace ~
34793 \InsetSpace ~
34794 \InsetSpace ~
34795 \InsetSpace ~
34796 \InsetSpace ~
34797 \InsetSpace ~
34798 \InsetSpace ~
34799  rrc\InsetSpace ~
34800 \InsetSpace ~
34801  a 
34802 \newline
34803 0025 92*02\InsetSpace ~
34804 \InsetSpace ~
34805 \InsetSpace ~
34806 \InsetSpace ~
34807 \InsetSpace ~
34808 \InsetSpace ~
34809 \InsetSpace ~
34810 \InsetSpace ~
34811 \InsetSpace ~
34812 \InsetSpace ~
34813 \InsetSpace ~
34814 \InsetSpace ~
34815 \InsetSpace ~
34816 \InsetSpace ~
34817 \InsetSpace ~
34818
34819  78\InsetSpace ~
34820 \InsetSpace ~
34821 \InsetSpace ~
34822 \InsetSpace ~
34823 \InsetSpace ~
34824 \InsetSpace ~
34825 \InsetSpace ~
34826 \InsetSpace ~
34827  mov\InsetSpace ~
34828 \InsetSpace ~
34829  _foo_aob2_1_1,c 
34830 \newline
34831 \InsetSpace ~
34832 \InsetSpace ~
34833 \InsetSpace ~
34834 \InsetSpace ~
34835 \InsetSpace ~
34836 \InsetSpace ~
34837 \InsetSpace ~
34838 \InsetSpace ~
34839 \InsetSpace ~
34840 \InsetSpace ~
34841 \InsetSpace ~
34842 \InsetSpace ~
34843 \InsetSpace ~
34844 \InsetSpace ~
34845 \InsetSpace ~
34846 \InsetSpace ~
34847 \InsetSpace ~
34848 \InsetSpace ~
34849 \InsetSpace ~
34850 \InsetSpace ~
34851 \InsetSpace ~
34852 \InsetSpace ~
34853 \InsetSpace ~
34854 \InsetSpace ~
34855 \InsetSpace ~
34856  79 ;\InsetSpace ~
34857  hob.c 12 
34858 \newline
34859 0027 E5*01\InsetSpace ~
34860 \InsetSpace ~
34861 \InsetSpace ~
34862 \InsetSpace ~
34863 \InsetSpace ~
34864 \InsetSpace ~
34865 \InsetSpace ~
34866 \InsetSpace ~
34867 \InsetSpace ~
34868 \InsetSpace ~
34869 \InsetSpace ~
34870 \InsetSpace ~
34871 \InsetSpace ~
34872 \InsetSpace ~
34873 \InsetSpace ~
34874  80\InsetSpace ~
34875 \InsetSpace ~
34876 \InsetSpace ~
34877 \InsetSpace ~
34878 \InsetSpace ~
34879 \InsetSpace ~
34880 \InsetSpace ~
34881 \InsetSpace ~
34882  mov\InsetSpace ~
34883 \InsetSpace ~
34884  a,(_gint + 1) 
34885 \newline
34886 0029
34887  A2 E3\InsetSpace ~
34888 \InsetSpace ~
34889 \InsetSpace ~
34890 \InsetSpace ~
34891 \InsetSpace ~
34892 \InsetSpace ~
34893 \InsetSpace ~
34894 \InsetSpace ~
34895 \InsetSpace ~
34896 \InsetSpace ~
34897 \InsetSpace ~
34898 \InsetSpace ~
34899 \InsetSpace ~
34900 \InsetSpace ~
34901 \InsetSpace ~
34902  81\InsetSpace ~
34903 \InsetSpace ~
34904 \InsetSpace ~
34905 \InsetSpace ~
34906 \InsetSpace ~
34907 \InsetSpace ~
34908 \InsetSpace ~
34909 \InsetSpace ~
34910  mov\InsetSpace ~
34911 \InsetSpace ~
34912  c,acc[3] 
34913 \newline
34914 002B 92*03\InsetSpace ~
34915 \InsetSpace ~
34916 \InsetSpace ~
34917 \InsetSpace ~
34918 \InsetSpace ~
34919 \InsetSpace ~
34920 \InsetSpace ~
34921 \InsetSpace ~
34922 \InsetSpace ~
34923 \InsetSpace ~
34924 \InsetSpace ~
34925 \InsetSpace ~
34926 \InsetSpace ~
34927 \InsetSpace ~
34928 \InsetSpace ~
34929  82\InsetSpace ~
34930 \InsetSpace ~
34931 \InsetSpace ~
34932 \InsetSpace ~
34933 \InsetSpace ~
34934 \InsetSpace ~
34935 \InsetSpace ~
34936 \InsetSpace ~
34937  mov\InsetSpace ~
34938 \InsetSpace ~
34939  _foo_aob3_1_1,c 
34940 \end_layout
34941
34942 \begin_layout Standard
34943 Other variations of these cases however will 
34944 \emph on
34945 not
34946 \emph default
34947  be recognized.
34948  They are standard C expressions, so I heartily recommend these be the only
34949  way to get the highest order bit, (it is portable).
34950  Of course it will be recognized even if it is embedded in other expressions,
34951  e.g.:
34952 \end_layout
34953
34954 \begin_layout Verse
34955
34956 \family typewriter
34957 xyz = gint + ((gint >> 15) & 1);
34958 \end_layout
34959
34960 \begin_layout Standard
34961 will still be recognized.
34962 \end_layout
34963
34964 \begin_layout Subsection
34965 Higher Order Byte
34966 \begin_inset LatexCommand \index{Higher Order Byte}
34967
34968 \end_inset
34969
34970  / Higher Order Word
34971 \begin_inset LatexCommand \index{Higher Order Word}
34972
34973 \end_inset
34974
34975
34976 \end_layout
34977
34978 \begin_layout Standard
34979 It is also frequently required to obtain a higher order byte or word of
34980  a larger integral type (long, int or short types).
34981  SDCC recognizes the following expressions to yield the higher order byte
34982  or word and generates optimized code for it, e.g.:
34983 \end_layout
34984
34985 \begin_layout Verse
34986
34987 \family typewriter
34988 unsigned int gint; 
34989 \newline
34990 unsigned long int glong; 
34991 \newline
34992
34993 \newline
34994 foo () { 
34995 \newline
34996 \InsetSpace ~
34997 \InsetSpace ~
34998 unsigned char hob1,
34999  hob2; 
35000 \newline
35001 \InsetSpace ~
35002 \InsetSpace ~
35003 unsigned int how1, how2; 
35004 \newline
35005 \InsetSpace ~
35006 \InsetSpace ~
35007 ...
35008  
35009 \newline
35010 \InsetSpace ~
35011 \InsetSpace ~
35012 hob1 = (gint >> 8) & 0xFF; 
35013 \newline
35014 \InsetSpace ~
35015 \InsetSpace ~
35016 hob2 = glong >> 24; 
35017 \newline
35018 \InsetSpace ~
35019 \InsetSpace ~
35020 how1 = (glong >> 16) & 0xFFFF;
35021  
35022 \newline
35023 \InsetSpace ~
35024 \InsetSpace ~
35025 how2 = glong >> 8; 
35026 \newline
35027 \InsetSpace ~
35028 \InsetSpace ~
35029 ..
35030  
35031 \newline
35032 }
35033 \end_layout
35034
35035 \begin_layout Standard
35036 will generate the following code:
35037 \end_layout
35038
35039 \begin_layout Verse
35040
35041 \family typewriter
35042 \InsetSpace ~
35043 \InsetSpace ~
35044 \InsetSpace ~
35045 \InsetSpace ~
35046 \InsetSpace ~
35047 \InsetSpace ~
35048 \InsetSpace ~
35049 \InsetSpace ~
35050 \InsetSpace ~
35051 \InsetSpace ~
35052 \InsetSpace ~
35053 \InsetSpace ~
35054 \InsetSpace ~
35055 \InsetSpace ~
35056 \InsetSpace ~
35057 \InsetSpace ~
35058 \InsetSpace ~
35059 \InsetSpace ~
35060 \InsetSpace ~
35061 \InsetSpace ~
35062 \InsetSpace ~
35063 \InsetSpace ~
35064 \InsetSpace ~
35065 \InsetSpace ~
35066 \InsetSpace ~
35067  91 ;\InsetSpace ~
35068  hob.c 15 
35069 \newline
35070 0037 85*01*06\InsetSpace ~
35071 \InsetSpace ~
35072 \InsetSpace ~
35073 \InsetSpace ~
35074 \InsetSpace ~
35075 \InsetSpace ~
35076 \InsetSpace ~
35077 \InsetSpace ~
35078 \InsetSpace ~
35079 \InsetSpace ~
35080 \InsetSpace ~
35081 \InsetSpace ~
35082  92\InsetSpace ~
35083 \InsetSpace ~
35084 \InsetSpace ~
35085 \InsetSpace ~
35086 \InsetSpace ~
35087 \InsetSpace ~
35088 \InsetSpace ~
35089 \InsetSpace ~
35090  mov\InsetSpace ~
35091 \InsetSpace ~
35092  _foo_hob1_1_1,(_gint + 1) 
35093 \newline
35094 \InsetSpace ~
35095 \InsetSpace ~
35096 \InsetSpace ~
35097 \InsetSpace ~
35098 \InsetSpace ~
35099 \InsetSpace ~
35100 \InsetSpace ~
35101 \InsetSpace ~
35102 \InsetSpace ~
35103 \InsetSpace ~
35104 \InsetSpace ~
35105 \InsetSpace ~
35106 \InsetSpace ~
35107 \InsetSpace ~
35108 \InsetSpace ~
35109 \InsetSpace ~
35110 \InsetSpace ~
35111 \InsetSpace ~
35112 \InsetSpace ~
35113 \InsetSpace ~
35114 \InsetSpace ~
35115 \InsetSpace ~
35116 \InsetSpace ~
35117 \InsetSpace ~
35118 \InsetSpace ~
35119  93 ;\InsetSpace ~
35120  hob.c
35121  16 
35122 \newline
35123 003A 85*05*07\InsetSpace ~
35124 \InsetSpace ~
35125 \InsetSpace ~
35126 \InsetSpace ~
35127 \InsetSpace ~
35128 \InsetSpace ~
35129 \InsetSpace ~
35130 \InsetSpace ~
35131 \InsetSpace ~
35132 \InsetSpace ~
35133 \InsetSpace ~
35134 \InsetSpace ~
35135  94\InsetSpace ~
35136 \InsetSpace ~
35137 \InsetSpace ~
35138 \InsetSpace ~
35139 \InsetSpace ~
35140 \InsetSpace ~
35141 \InsetSpace ~
35142 \InsetSpace ~
35143  mov\InsetSpace ~
35144 \InsetSpace ~
35145  _foo_hob2_1_1,(_glong + 3) 
35146 \newline
35147 \InsetSpace ~
35148 \InsetSpace ~
35149 \InsetSpace ~
35150 \InsetSpace ~
35151 \InsetSpace ~
35152 \InsetSpace ~
35153 \InsetSpace ~
35154 \InsetSpace ~
35155 \InsetSpace ~
35156 \InsetSpace ~
35157 \InsetSpace ~
35158 \InsetSpace ~
35159 \InsetSpace ~
35160 \InsetSpace ~
35161 \InsetSpace ~
35162 \InsetSpace ~
35163 \InsetSpace ~
35164 \InsetSpace ~
35165 \InsetSpace ~
35166 \InsetSpace ~
35167 \InsetSpace ~
35168 \InsetSpace ~
35169 \InsetSpace ~
35170 \InsetSpace ~
35171 \InsetSpace ~
35172  95 ;\InsetSpace ~
35173  hob.c 17 
35174 \newline
35175 003D 85*04*08\InsetSpace ~
35176 \InsetSpace ~
35177 \InsetSpace ~
35178 \InsetSpace ~
35179 \InsetSpace ~
35180 \InsetSpace ~
35181 \InsetSpace ~
35182 \InsetSpace ~
35183 \InsetSpace ~
35184 \InsetSpace ~
35185 \InsetSpace ~
35186 \InsetSpace ~
35187
35188  96\InsetSpace ~
35189 \InsetSpace ~
35190 \InsetSpace ~
35191 \InsetSpace ~
35192 \InsetSpace ~
35193 \InsetSpace ~
35194 \InsetSpace ~
35195 \InsetSpace ~
35196  mov\InsetSpace ~
35197 \InsetSpace ~
35198  _foo_how1_1_1,(_glong + 2) 
35199 \newline
35200 0040 85*05*09\InsetSpace ~
35201 \InsetSpace ~
35202 \InsetSpace ~
35203 \InsetSpace ~
35204 \InsetSpace ~
35205 \InsetSpace ~
35206 \InsetSpace ~
35207 \InsetSpace ~
35208 \InsetSpace ~
35209 \InsetSpace ~
35210 \InsetSpace ~
35211 \InsetSpace ~
35212  97\InsetSpace ~
35213 \InsetSpace ~
35214 \InsetSpace ~
35215 \InsetSpace ~
35216 \InsetSpace ~
35217 \InsetSpace ~
35218 \InsetSpace ~
35219 \InsetSpace ~
35220  mov\InsetSpace ~
35221 \InsetSpace ~
35222  (_foo_how1_1_1 +
35223  1),(_glong + 3) 
35224 \newline
35225 0043 85*03*0A\InsetSpace ~
35226 \InsetSpace ~
35227 \InsetSpace ~
35228 \InsetSpace ~
35229 \InsetSpace ~
35230 \InsetSpace ~
35231 \InsetSpace ~
35232 \InsetSpace ~
35233 \InsetSpace ~
35234 \InsetSpace ~
35235 \InsetSpace ~
35236 \InsetSpace ~
35237  98\InsetSpace ~
35238 \InsetSpace ~
35239 \InsetSpace ~
35240 \InsetSpace ~
35241 \InsetSpace ~
35242 \InsetSpace ~
35243 \InsetSpace ~
35244 \InsetSpace ~
35245  mov\InsetSpace ~
35246 \InsetSpace ~
35247  _foo_how2_1_1,(_glong + 1) 
35248 \newline
35249 0046 85*04*0B\InsetSpace ~
35250 \InsetSpace ~
35251 \InsetSpace ~
35252 \InsetSpace ~
35253 \InsetSpace ~
35254 \InsetSpace ~
35255 \InsetSpace ~
35256 \InsetSpace ~
35257 \InsetSpace ~
35258 \InsetSpace ~
35259 \InsetSpace ~
35260 \InsetSpace ~
35261
35262  99\InsetSpace ~
35263 \InsetSpace ~
35264 \InsetSpace ~
35265 \InsetSpace ~
35266 \InsetSpace ~
35267 \InsetSpace ~
35268 \InsetSpace ~
35269 \InsetSpace ~
35270  mov\InsetSpace ~
35271 \InsetSpace ~
35272  (_foo_how2_1_1 + 1),(_glong + 2) 
35273 \end_layout
35274
35275 \begin_layout Standard
35276 Again, variations of these cases may 
35277 \emph on
35278 not
35279 \emph default
35280  be recognized.
35281  They are standard C expressions, so I heartily recommend these be the only
35282  way to get the higher order byte/word, (it is portable).
35283  Of course it will be recognized even if it is embedded in other expressions,
35284  e.g.:
35285 \end_layout
35286
35287 \begin_layout Verse
35288
35289 \family typewriter
35290 xyz = gint + ((gint >> 8) & 0xFF);
35291 \end_layout
35292
35293 \begin_layout Standard
35294 will still be recognized.
35295 \end_layout
35296
35297 \begin_layout Subsection
35298 Peephole Optimizer
35299 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
35300
35301 \end_inset
35302
35303
35304 \begin_inset LatexCommand \index{Peephole optimizer}
35305
35306 \end_inset
35307
35308
35309 \end_layout
35310
35311 \begin_layout Standard
35312 The compiler uses a rule based, pattern matching and re-writing mechanism
35313  for peep-hole optimization.
35314  It is inspired by 
35315 \emph on
35316 copt
35317 \emph default
35318  a peep-hole optimizer by Christopher W.
35319  Fraser (cwfraser\InsetSpace ~
35320 @\InsetSpace ~
35321 microsoft.com).
35322  A default set of rules are compiled into the compiler, additional rules
35323  may be added with the 
35324 \emph on
35325 -
35326 \begin_inset ERT
35327 status collapsed
35328
35329 \begin_layout Standard
35330
35331
35332 \backslash
35333 /
35334 \end_layout
35335
35336 \end_inset
35337
35338 -peep-file
35339 \begin_inset LatexCommand \index{-\/-peep-file}
35340
35341 \end_inset
35342
35343  <filename>
35344 \emph default
35345  option.
35346  The rule language is best illustrated with examples.
35347 \end_layout
35348
35349 \begin_layout Verse
35350
35351 \family typewriter
35352 replace { 
35353 \newline
35354 \InsetSpace ~
35355 \InsetSpace ~
35356 mov %1,a 
35357 \newline
35358 \InsetSpace ~
35359 \InsetSpace ~
35360 mov a,%1
35361 \newline
35362 } by {
35363 \newline
35364 \InsetSpace ~
35365 \InsetSpace ~
35366 mov %1,a
35367 \newline
35368 }
35369 \end_layout
35370
35371 \begin_layout Standard
35372 The above rule will change the following assembly
35373 \begin_inset LatexCommand \index{Assembler routines}
35374
35375 \end_inset
35376
35377  sequence:
35378 \end_layout
35379
35380 \begin_layout Verse
35381
35382 \family typewriter
35383 mov r1,a 
35384 \newline
35385 mov a,r1
35386 \end_layout
35387
35388 \begin_layout Standard
35389 to
35390 \end_layout
35391
35392 \begin_layout Verse
35393
35394 \family typewriter
35395 mov r1,a
35396 \end_layout
35397
35398 \begin_layout Standard
35399 Note: All occurrences of a 
35400 \emph on
35401 %n
35402 \emph default
35403  (pattern variable) must denote the same string.
35404  With the above rule, the assembly sequence:
35405 \end_layout
35406
35407 \begin_layout Verse
35408
35409 \family typewriter
35410 mov r1,a 
35411 \newline
35412 mov a,r2
35413 \end_layout
35414
35415 \begin_layout Standard
35416 will remain unmodified.
35417 \newline
35418
35419 \newline
35420 Other special case optimizations may be added by the
35421  user (via 
35422 \emph on
35423 -
35424 \begin_inset ERT
35425 status collapsed
35426
35427 \begin_layout Standard
35428
35429
35430 \backslash
35431 /
35432 \end_layout
35433
35434 \end_inset
35435
35436 -peep-file option
35437 \emph default
35438 ).
35439  E.g.
35440  some variants of the 8051 MCU
35441 \begin_inset LatexCommand \index{MCS51 variants}
35442
35443 \end_inset
35444
35445  allow only 
35446 \family typewriter
35447 ajmp
35448 \family default
35449  and 
35450 \family typewriter
35451 acall
35452 \family default
35453 .
35454  The following two rules will change all 
35455 \family typewriter
35456 ljmp
35457 \family default
35458  and 
35459 \family typewriter
35460 lcall
35461 \family default
35462  to 
35463 \family typewriter
35464 ajmp
35465 \family default
35466  and 
35467 \family typewriter
35468 acall
35469 \end_layout
35470
35471 \begin_layout Verse
35472
35473 \family typewriter
35474 replace { lcall %1 } by { acall %1 } 
35475 \newline
35476 replace { ljmp %1 } by { ajmp %1 }
35477 \end_layout
35478
35479 \begin_layout Standard
35480 The 
35481 \emph on
35482 inline-assembler code
35483 \emph default
35484  is also passed through the peep hole optimizer, thus the peephole optimizer
35485  can also be used as an assembly level macro expander.
35486  The rules themselves are MCU dependent whereas the rule language infra-structur
35487 e is MCU independent.
35488  Peephole optimization rules for other MCU can be easily programmed using
35489  the rule language.
35490 \newline
35491
35492 \newline
35493 The syntax for a rule is as follows:
35494 \end_layout
35495
35496 \begin_layout Verse
35497
35498 \family typewriter
35499 rule := replace [ restart ] '{' <assembly sequence> '
35500 \backslash
35501 n' 
35502 \newline
35503 \InsetSpace ~
35504  \InsetSpace ~
35505  \InsetSpace ~
35506  \InsetSpace ~
35507  \InsetSpace ~
35508  \InsetSpace ~
35509  \InsetSpace ~
35510  \InsetSpace ~
35511  \InsetSpace ~
35512  \InsetSpace ~
35513  \InsetSpace ~
35514  \InsetSpace ~
35515  \InsetSpace ~
35516  \InsetSpace ~
35517  '}' by '{' '
35518 \backslash
35519 n' 
35520 \newline
35521 \InsetSpace ~
35522  \InsetSpace ~
35523  \InsetSpace ~
35524  \InsetSpace ~
35525  \InsetSpace ~
35526  \InsetSpace ~
35527  \InsetSpace ~
35528  \InsetSpace ~
35529  \InsetSpace ~
35530  \InsetSpace ~
35531  \InsetSpace ~
35532  \InsetSpace ~
35533  \InsetSpace ~
35534  \InsetSpace ~
35535  \InsetSpace ~
35536  \InsetSpace ~
35537  <assembly sequence> '
35538 \backslash
35539 n' 
35540 \newline
35541 \InsetSpace ~
35542  \InsetSpace ~
35543  \InsetSpace ~
35544  \InsetSpace ~
35545  \InsetSpace ~
35546  \InsetSpace ~
35547  \InsetSpace ~
35548  \InsetSpace ~
35549  \InsetSpace ~
35550  \InsetSpace ~
35551  \InsetSpace ~
35552  \InsetSpace ~
35553  \InsetSpace ~
35554  \InsetSpace ~
35555  '}' [if <functionName> ] '
35556 \backslash
35557 n' 
35558 \end_layout
35559
35560 \begin_layout Standard
35561 <assembly sequence> := assembly instruction (each instruction including
35562  labels must be on a separate line).
35563 \newline
35564
35565 \newline
35566 The optimizer will apply to the rules
35567  one by one from the top in the sequence of their appearance, it will terminate
35568  when all rules are exhausted.
35569  If the 'restart' option is specified, then the optimizer will start matching
35570  the rules again from the top, this option for a rule is expensive (performance)
35571 , it is intended to be used in situations where a transformation will trigger
35572  the same rule again.
35573  An example of this (not a good one, it has side effects) is the following
35574  rule:
35575 \end_layout
35576
35577 \begin_layout Verse
35578
35579 \family typewriter
35580 replace restart { 
35581 \newline
35582 \InsetSpace ~
35583 \InsetSpace ~
35584 pop %1 
35585 \newline
35586 \InsetSpace ~
35587 \InsetSpace ~
35588 push %1 } by { 
35589 \newline
35590 \InsetSpace ~
35591 \InsetSpace ~
35592 ; nop 
35593 \newline
35594 }
35595 \end_layout
35596
35597 \begin_layout Standard
35598 Note that the replace pattern cannot be a blank, but can be a comment line.
35599  Without the 'restart' option only the innermost 'pop' 'push' pair would
35600  be eliminated, i.e.:
35601 \end_layout
35602
35603 \begin_layout Verse
35604
35605 \family typewriter
35606 pop ar1 
35607 \newline
35608 pop ar2 
35609 \newline
35610 push ar2 
35611 \newline
35612 push ar1
35613 \end_layout
35614
35615 \begin_layout Standard
35616 would result in:
35617 \end_layout
35618
35619 \begin_layout Verse
35620
35621 \family typewriter
35622 pop ar1 
35623 \newline
35624 ; nop 
35625 \newline
35626 push ar1
35627 \end_layout
35628
35629 \begin_layout Standard
35630
35631 \emph on
35632 with
35633 \emph default
35634  the restart option the rule will be applied again to the resulting code
35635  and then all the pop-push pairs will be eliminated to yield:
35636 \end_layout
35637
35638 \begin_layout Verse
35639
35640 \family typewriter
35641 ; nop 
35642 \newline
35643 ; nop
35644 \end_layout
35645
35646 \begin_layout Standard
35647 A conditional function can be attached to a rule.
35648  Attaching rules are somewhat more involved, let me illustrate this with
35649  an example.
35650 \end_layout
35651
35652 \begin_layout Verse
35653
35654 \family typewriter
35655 replace { 
35656 \newline
35657 \InsetSpace ~
35658  \InsetSpace ~
35659  \InsetSpace ~
35660 ljmp %5 
35661 \newline
35662 %2:
35663 \newline
35664 } by { 
35665 \newline
35666 \InsetSpace ~
35667  \InsetSpace ~
35668  \InsetSpace ~
35669 sjmp %5 
35670 \newline
35671 %2:
35672 \newline
35673 } if labelInRange
35674 \end_layout
35675
35676 \begin_layout Standard
35677 The optimizer does a look-up of a function name table defined in function
35678  
35679 \emph on
35680 callFuncByName
35681 \emph default
35682  in the source file SDCCpeeph.c, with the name 
35683 \emph on
35684 labelInRange
35685 \emph default
35686 .
35687  If it finds a corresponding entry the function is called.
35688  Note there can be no parameters specified for these functions, in this
35689  case the use of 
35690 \emph on
35691 %5
35692 \emph default
35693  is crucial, since the function 
35694 \emph on
35695 labelInRange
35696 \emph default
35697  expects to find the label in that particular variable (the hash table containin
35698 g the variable bindings is passed as a parameter).
35699  If you want to code more such functions, take a close look at the function
35700  labelInRange and the calling mechanism in source file SDCCpeeph.c.
35701  Currently implemented are 
35702 \emph on
35703 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
35704  24bitMode, portIsDS390, 24bitModeAndPortDS390 
35705 \emph default
35706 and
35707 \emph on
35708  notVolatile
35709 \emph default
35710 .
35711 \end_layout
35712
35713 \begin_layout Standard
35714 I know this whole thing is a little kludgey, but maybe some day we will
35715  have some better means.
35716  If you are looking at this file, you will see the default rules that are
35717  compiled into the compiler, you can add your own rules in the default set
35718  there if you get tired of specifying the -
35719 \begin_inset ERT
35720 status collapsed
35721
35722 \begin_layout Standard
35723
35724
35725 \backslash
35726 /
35727 \end_layout
35728
35729 \end_inset
35730
35731 -peep-file option.
35732 \end_layout
35733
35734 \begin_layout Section
35735 ANSI-Compliance
35736 \begin_inset LatexCommand \index{ANSI-compliance}
35737
35738 \end_inset
35739
35740
35741 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
35742
35743 \end_inset
35744
35745
35746 \end_layout
35747
35748 \begin_layout Standard
35749 The latest publically available version of the standard 
35750 \emph on
35751 ISO/IEC 9899 - Programming languages - C
35752 \emph default
35753  should be available at: 
35754 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
35755
35756 \end_inset
35757
35758 .
35759 \newline
35760
35761 \end_layout
35762
35763 \begin_layout Standard
35764 Deviations from the compliance:
35765 \end_layout
35766
35767 \begin_layout Itemize
35768 functions are not reentrant
35769 \begin_inset LatexCommand \index{reentrant}
35770
35771 \end_inset
35772
35773  unless explicitly declared as such or the 
35774 \series bold
35775 -
35776 \begin_inset ERT
35777 status collapsed
35778
35779 \begin_layout Standard
35780
35781
35782 \backslash
35783 /
35784 \end_layout
35785
35786 \end_inset
35787
35788 -stack-auto
35789 \begin_inset LatexCommand \index{-\/-stack-auto}
35790
35791 \end_inset
35792
35793
35794 \series default
35795  command line option is specified.
35796 \end_layout
35797
35798 \begin_layout Itemize
35799 structures
35800 \begin_inset LatexCommand \index{struct}
35801
35802 \end_inset
35803
35804  and unions
35805 \begin_inset LatexCommand \index{union}
35806
35807 \end_inset
35808
35809  cannot be assigned values directly, cannot be passed as function parameters
35810  or assigned to each other and cannot be a return value
35811 \begin_inset LatexCommand \index{return value}
35812
35813 \end_inset
35814
35815  from a function, e.g.:
35816 \end_layout
35817
35818 \begin_deeper
35819 \begin_layout Verse
35820
35821 \family typewriter
35822 struct s { ...
35823  }; 
35824 \newline
35825 struct s s1, s2; 
35826 \newline
35827 foo() 
35828 \newline
35829
35830 \newline
35831 \InsetSpace ~
35832 \InsetSpace ~
35833 \InsetSpace ~
35834 \InsetSpace ~
35835 ...
35836  
35837 \newline
35838 \InsetSpace ~
35839 \InsetSpace ~
35840 \InsetSpace ~
35841 \InsetSpace ~
35842 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
35843 \newline
35844 \InsetSpace ~
35845 \InsetSpace ~
35846 \InsetSpace ~
35847 \InsetSpace ~
35848 ...
35849  
35850 \newline
35851 }
35852 \newline
35853
35854 \series bold
35855 struct
35856 \series default
35857  s foo1 (
35858 \series bold
35859 struct
35860 \series default
35861  s parms) /* invalid in SDCC although allowed in ANSI */
35862 \newline
35863
35864 \newline
35865 \InsetSpace ~
35866 \InsetSpace ~
35867 \InsetSpace ~
35868 \InsetSpace ~
35869 struct s rets;
35870  
35871 \newline
35872 \InsetSpace ~
35873 \InsetSpace ~
35874 \InsetSpace ~
35875 \InsetSpace ~
35876 ...
35877  
35878 \newline
35879 \InsetSpace ~
35880 \InsetSpace ~
35881 \InsetSpace ~
35882 \InsetSpace ~
35883 return rets; /* is invalid in SDCC although allowed in ANSI */ 
35884 \newline
35885 }
35886 \end_layout
35887
35888 \end_deeper
35889 \begin_layout Itemize
35890 initialization of structure arrays must be fully braced.
35891 \end_layout
35892
35893 \begin_deeper
35894 \begin_layout Verse
35895
35896 \family typewriter
35897 struct s { char x } a[] = {1, 2};\InsetSpace ~
35898 \InsetSpace ~
35899 \InsetSpace ~
35900 \InsetSpace ~
35901 \InsetSpace ~
35902 /* invalid in SDCC */
35903 \newline
35904 struct s { char x
35905  } a[] = {{1}, {2}}; /* OK */
35906 \end_layout
35907
35908 \end_deeper
35909 \begin_layout Itemize
35910 'long long
35911 \begin_inset LatexCommand \index{long long (not supported)}
35912
35913 \end_inset
35914
35915 ' (64 bit integers
35916 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
35917
35918 \end_inset
35919
35920 ) not supported.
35921 \end_layout
35922
35923 \begin_layout Itemize
35924 'double
35925 \begin_inset LatexCommand \index{double (not supported)}
35926
35927 \end_inset
35928
35929 ' precision floating point 
35930 \begin_inset LatexCommand \index{Floating point support}
35931
35932 \end_inset
35933
35934 not supported.
35935 \end_layout
35936
35937 \begin_layout Itemize
35938 Old K&R style
35939 \begin_inset LatexCommand \index{K\&R style}
35940
35941 \end_inset
35942
35943  function declarations are NOT allowed.
35944 \end_layout
35945
35946 \begin_deeper
35947 \begin_layout Verse
35948
35949 \family typewriter
35950 foo(i,j) /* this old style of function declarations */ 
35951 \newline
35952 int i,j; /* is valid
35953  in ANSI but not valid in SDCC */ 
35954 \newline
35955
35956 \newline
35957 \InsetSpace ~
35958 \InsetSpace ~
35959 \InsetSpace ~
35960 \InsetSpace ~
35961 ...
35962  
35963 \newline
35964 }
35965 \end_layout
35966
35967 \end_deeper
35968 \begin_layout Itemize
35969 Most enhancements in C99 are not supported, e.g.:
35970 \end_layout
35971
35972 \begin_deeper
35973 \begin_layout Verse
35974
35975 \family typewriter
35976 for (
35977 \series bold
35978 int
35979 \series default
35980  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
35981 \end_layout
35982
35983 \end_deeper
35984 \begin_layout Itemize
35985 But some have been added recently in SDCC 2.7.0.
35986  They must be considered alpha quality however.
35987 \end_layout
35988
35989 \begin_deeper
35990 \begin_layout Verse
35991
35992 \family typewriter
35993 \series bold
35994 inline
35995 \begin_inset LatexCommand \index{inline (not supported)}
35996
35997 \end_inset
35998
35999
36000 \series default
36001  int increment (int a) { return a+1; } /* inlines the increment without
36002  function call overhead */
36003 \newline
36004 int * 
36005 \series bold
36006 restrict
36007 \begin_inset LatexCommand \index{inline (not supported)}
36008
36009 \end_inset
36010
36011
36012 \series default
36013  p; /* accepted but ignored */
36014 \end_layout
36015
36016 \end_deeper
36017 \begin_layout Itemize
36018 Certain words that are valid identifiers in the standard may be reserved
36019  words in SDCC unless the 
36020 \series bold
36021 -
36022 \begin_inset ERT
36023 status collapsed
36024
36025 \begin_layout Standard
36026
36027
36028 \backslash
36029 /
36030 \end_layout
36031
36032 \end_inset
36033
36034 -std-c89
36035 \begin_inset LatexCommand \index{-\/-std-c89}
36036
36037 \end_inset
36038
36039  or -
36040 \begin_inset ERT
36041 status collapsed
36042
36043 \begin_layout Standard
36044
36045
36046 \backslash
36047 /
36048 \end_layout
36049
36050 \end_inset
36051
36052 -std-c99
36053 \begin_inset LatexCommand \index{-\/-std-c99}
36054
36055 \end_inset
36056
36057
36058 \series default
36059  command line options are used.
36060  These may include (depending on the selected processor): 'at', 'banked',
36061  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
36062 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
36063  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
36064  '_naked'.
36065  Compliant equivalents of these keywords are always available in a form
36066  that begin with two underscores
36067 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
36068
36069 \end_inset
36070
36071 , f.e.
36072  '__data' instead of 'data'.
36073 \end_layout
36074
36075 \begin_layout Section
36076 Cyclomatic Complexity
36077 \begin_inset LatexCommand \index{Cyclomatic complexity}
36078
36079 \end_inset
36080
36081
36082 \end_layout
36083
36084 \begin_layout Standard
36085 Cyclomatic complexity of a function is defined as the number of independent
36086  paths the program can take during execution of the function.
36087  This is an important number since it defines the number test cases you
36088  have to generate to validate the function.
36089  The accepted industry standard for complexity number is 10, if the cyclomatic
36090  complexity reported by SDCC exceeds 10 you should think about simplification
36091  of the function logic.
36092  Note that the complexity level is not related to the number of lines of
36093  code in a function.
36094  Large functions can have low complexity, and small functions can have large
36095  complexity levels.
36096  
36097 \newline
36098
36099 \newline
36100 SDCC uses the following formula to compute the complexity:
36101 \newline
36102
36103 \end_layout
36104
36105 \begin_layout Standard
36106 complexity = (number of edges in control flow graph) - (number of nodes
36107  in control flow graph) + 2;
36108 \newline
36109
36110 \newline
36111 Having said that the industry standard is 10,
36112  you should be aware that in some cases it be may unavoidable to have a
36113  complexity level of less than 10.
36114  For example if you have switch statement with more than 10 case labels,
36115  each case label adds one to the complexity level.
36116  The complexity level is by no means an absolute measure of the algorithmic
36117  complexity of the function, it does however provide a good starting point
36118  for which functions you might look at for further optimization.
36119 \end_layout
36120
36121 \begin_layout Section
36122 Retargetting for other Processors
36123 \end_layout
36124
36125 \begin_layout Standard
36126 The issues for retargetting the compiler are far too numerous to be covered
36127  by this document.
36128  What follows is a brief description of each of the seven phases of the
36129  compiler and its MCU dependency.
36130 \end_layout
36131
36132 \begin_layout Itemize
36133 Parsing the source and building the annotated parse tree.
36134  This phase is largely MCU independent (except for the language extensions).
36135  Syntax & semantic checks are also done in this phase, along with some initial
36136  optimizations like back patching labels and the pattern matching optimizations
36137  like bit-rotation etc.
36138 \end_layout
36139
36140 \begin_layout Itemize
36141 The second phase involves generating an intermediate code which can be easy
36142  manipulated during the later phases.
36143  This phase is entirely MCU independent.
36144  The intermediate code generation assumes the target machine has unlimited
36145  number of registers, and designates them with the name iTemp.
36146  The compiler can be made to dump a human readable form of the code generated
36147  by using the -
36148 \begin_inset ERT
36149 status collapsed
36150
36151 \begin_layout Standard
36152
36153
36154 \backslash
36155 /
36156 \end_layout
36157
36158 \end_inset
36159
36160 -dumpraw option.
36161 \end_layout
36162
36163 \begin_layout Itemize
36164 This phase does the bulk of the standard optimizations and is also MCU independe
36165 nt.
36166  This phase can be broken down into several sub-phases:
36167 \newline
36168
36169 \newline
36170 Break down intermediate
36171  code (iCode) into basic blocks.
36172 \newline
36173 Do control flow & data flow analysis on the
36174  basic blocks.
36175 \newline
36176 Do local common subexpression elimination, then global subexpressio
36177 n elimination
36178 \newline
36179 Dead code elimination
36180 \newline
36181 Loop optimizations
36182 \newline
36183 If loop optimizations
36184  caused any changes then do 'global subexpression elimination' and 'dead
36185  code elimination' again.
36186 \end_layout
36187
36188 \begin_layout Itemize
36189 This phase determines the live-ranges; by live range I mean those iTemp
36190  variables defined by the compiler that still survive after all the optimization
36191 s.
36192  Live range analysis
36193 \begin_inset LatexCommand \index{Live range analysis}
36194
36195 \end_inset
36196
36197  is essential for register allocation, since these computation determines
36198  which of these iTemps will be assigned to registers, and for how long.
36199 \end_layout
36200
36201 \begin_layout Itemize
36202 Phase five is register allocation.
36203  There are two parts to this process.
36204 \newline
36205
36206 \newline
36207 The first part I call 'register packing'
36208  (for lack of a better term).
36209  In this case several MCU specific expression folding is done to reduce
36210  register pressure.
36211 \newline
36212
36213 \newline
36214 The second part is more MCU independent and deals with
36215  allocating registers to the remaining live ranges.
36216  A lot of MCU specific code does creep into this phase because of the limited
36217  number of index registers available in the 8051.
36218 \end_layout
36219
36220 \begin_layout Itemize
36221 The Code generation phase is (unhappily), entirely MCU dependent and very
36222  little (if any at all) of this code can be reused for other MCU.
36223  However the scheme for allocating a homogenized assembler operand for each
36224  iCode operand may be reused.
36225 \end_layout
36226
36227 \begin_layout Itemize
36228 As mentioned in the optimization section the peep-hole optimizer is rule
36229  based system, which can reprogrammed for other MCUs.
36230 \end_layout
36231
36232 \begin_layout Standard
36233 More information is available in a wiki
36234 \begin_inset LatexCommand \index{wiki}
36235
36236 \end_inset
36237
36238  (preliminary link 
36239 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
36240
36241 \end_inset
36242
36243 ) and in the thread 
36244 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
36245
36246 \end_inset
36247
36248  .
36249 \end_layout
36250
36251 \begin_layout Chapter
36252 Compiler internals
36253 \begin_inset LatexCommand \index{Compiler internals}
36254
36255 \end_inset
36256
36257
36258 \end_layout
36259
36260 \begin_layout Section
36261 The anatomy of the compiler
36262 \begin_inset LatexCommand \label{sub:The-anatomy-of}
36263
36264 \end_inset
36265
36266
36267 \end_layout
36268
36269 \begin_layout Standard
36270
36271 \shape italic
36272 This is an excerpt from an article published in Circuit Cellar Magazine
36273  in 
36274 \series bold
36275 August 2000
36276 \series default
36277 .
36278  It's a little outdated (the compiler is much more efficient now and user/develo
36279 per friendly), but pretty well exposes the guts of it all.
36280 \shape default
36281
36282 \newline
36283
36284 \newline
36285 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
36286  It is fairly easy to retarget for other 8-bit MCU.
36287  Here we take a look at some of the internals of the compiler.
36288  
36289 \end_layout
36290
36291 \begin_layout Paragraph*
36292 Parsing
36293 \begin_inset LatexCommand \index{Parsing}
36294
36295 \end_inset
36296
36297  
36298 \end_layout
36299
36300 \begin_layout Standard
36301 Parsing the input source file and creating an AST (Annotated Syntax Tree
36302 \begin_inset LatexCommand \index{Annotated syntax tree}
36303
36304 \end_inset
36305
36306 ).
36307  This phase also involves propagating types (annotating each node of the
36308  parse tree with type information) and semantic analysis.
36309  There are some MCU specific parsing rules.
36310  For example the storage classes, the extended storage classes are MCU specific
36311  while there may be a xdata storage class for 8051 there is no such storage
36312  class for z80 or Atmel AVR.
36313  SDCC allows MCU specific storage class extensions, i.e.
36314  xdata will be treated as a storage class specifier when parsing 8051 C
36315  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
36316  C code.
36317 \end_layout
36318
36319 \begin_layout Paragraph*
36320 Generating iCode
36321 \begin_inset LatexCommand \index{iCode}
36322
36323 \end_inset
36324
36325
36326 \end_layout
36327
36328 \begin_layout Standard
36329 Intermediate code generation.
36330  In this phase the AST is broken down into three-operand form (iCode).
36331  These three operand forms are represented as doubly linked lists.
36332  ICode is the term given to the intermediate form generated by the compiler.
36333  ICode example section shows some examples of iCode generated for some simple
36334  C source functions.
36335 \end_layout
36336
36337 \begin_layout Paragraph*
36338 Optimizations
36339 \begin_inset LatexCommand \index{Optimizations}
36340
36341 \end_inset
36342
36343 .
36344 \end_layout
36345
36346 \begin_layout Standard
36347 Bulk of the target independent optimizations is performed in this phase.
36348  The optimizations include constant propagation, common sub-expression eliminati
36349 on, loop invariant code movement, strength reduction of loop induction variables
36350  and dead-code elimination.
36351 \end_layout
36352
36353 \begin_layout Paragraph*
36354 Live range analysis
36355 \begin_inset LatexCommand \index{Live range analysis}
36356
36357 \end_inset
36358
36359
36360 \end_layout
36361
36362 \begin_layout Standard
36363 During intermediate code generation phase, the compiler assumes the target
36364  machine has infinite number of registers and generates a lot of temporary
36365  variables.
36366  The live range computation determines the lifetime of each of these compiler-ge
36367 nerated temporaries.
36368  A picture speaks a thousand words.
36369  ICode example sections show the live range annotations for each of the
36370  operand.
36371  It is important to note here, each iCode is assigned a number in the order
36372  of its execution in the function.
36373  The live ranges are computed in terms of these numbers.
36374  The from number is the number of the iCode which first defines the operand
36375  and the to number signifies the iCode which uses this operand last.
36376 \end_layout
36377
36378 \begin_layout Paragraph*
36379 Register Allocation
36380 \begin_inset LatexCommand \index{Register allocation}
36381
36382 \end_inset
36383
36384
36385 \end_layout
36386
36387 \begin_layout Standard
36388 The register allocation determines the type and number of registers needed
36389  by each operand.
36390  In most MCUs only a few registers can be used for indirect addressing.
36391  In case of 8051 for example the registers R0 & R1 can be used to indirectly
36392  address the internal ram and DPTR to indirectly address the external ram.
36393  The compiler will try to allocate the appropriate register to pointer variables
36394  if it can.
36395  ICode example section shows the operands annotated with the registers assigned
36396  to them.
36397  The compiler will try to keep operands in registers as much as possible;
36398  there are several schemes the compiler uses to do achieve this.
36399  When the compiler runs out of registers the compiler will check to see
36400  if there are any live operands which is not used or defined in the current
36401  basic block being processed, if there are any found then it will push that
36402  operand and use the registers in this block, the operand will then be popped
36403  at the end of the basic block.
36404  
36405 \end_layout
36406
36407 \begin_layout Standard
36408 There are other MCU specific considerations in this phase.
36409  Some MCUs have an accumulator; very short-lived operands could be assigned
36410  to the accumulator instead of a general-purpose register.
36411 \end_layout
36412
36413 \begin_layout Paragraph*
36414 Code generation
36415 \end_layout
36416
36417 \begin_layout Standard
36418 Figure II gives a table of iCode
36419 \begin_inset LatexCommand \index{iCode}
36420
36421 \end_inset
36422
36423  operations supported by the compiler.
36424  The code generation involves translating these operations into corresponding
36425  assembly code for the processor.
36426  This sounds overly simple but that is the essence of code generation.
36427  Some of the iCode operations are generated on a MCU specific manner for
36428  example, the z80 port does not use registers to pass parameters so the
36429  SEND and RECV iCode operations will not be generated, and it also does
36430  not support JUMPTABLES.
36431  
36432 \newline
36433
36434 \end_layout
36435
36436 \begin_layout Standard
36437
36438 \size footnotesize
36439 Figure II 
36440 \begin_inset Tabular
36441 <lyxtabular version="3" rows="39" columns="4">
36442 <features islongtable="true" headBottomDL="true">
36443 <column alignment="block" valignment="top" leftline="true" width="13col%">
36444 <column alignment="left" valignment="top" leftline="true" width="13col%">
36445 <column alignment="block" valignment="top" leftline="true" width="22col%">
36446 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36447 <row topline="true" bottomline="true" endhead="true">
36448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36449 \begin_inset Text
36450
36451 \begin_layout Standard
36452
36453 \series bold
36454 iCode
36455 \series default
36456
36457 \begin_inset LatexCommand \index{iCode}
36458
36459 \end_inset
36460
36461
36462 \end_layout
36463
36464 \end_inset
36465 </cell>
36466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36467 \begin_inset Text
36468
36469 \begin_layout Standard
36470
36471 \series bold
36472 Operands
36473 \end_layout
36474
36475 \end_inset
36476 </cell>
36477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36478 \begin_inset Text
36479
36480 \begin_layout Standard
36481
36482 \series bold
36483 Description
36484 \end_layout
36485
36486 \end_inset
36487 </cell>
36488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36489 \begin_inset Text
36490
36491 \begin_layout Standard
36492
36493 \series bold
36494 C Equivalent
36495 \end_layout
36496
36497 \end_inset
36498 </cell>
36499 </row>
36500 <row topline="true">
36501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36502 \begin_inset Text
36503
36504 \begin_layout Standard
36505
36506 \size footnotesize
36507 '!'
36508 \end_layout
36509
36510 \end_inset
36511 </cell>
36512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36513 \begin_inset Text
36514
36515 \begin_layout Standard
36516
36517 \size footnotesize
36518 IC_LEFT() IC_RESULT()
36519 \end_layout
36520
36521 \end_inset
36522 </cell>
36523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36524 \begin_inset Text
36525
36526 \begin_layout Standard
36527
36528 \size footnotesize
36529 NOT operation 
36530 \end_layout
36531
36532 \end_inset
36533 </cell>
36534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36535 \begin_inset Text
36536
36537 \begin_layout Standard
36538
36539 \size footnotesize
36540 IC_RESULT = ! IC_LEFT;
36541 \end_layout
36542
36543 \end_inset
36544 </cell>
36545 </row>
36546 <row topline="true">
36547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36548 \begin_inset Text
36549
36550 \begin_layout Standard
36551
36552 \size footnotesize
36553 '~'
36554 \end_layout
36555
36556 \end_inset
36557 </cell>
36558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36559 \begin_inset Text
36560
36561 \begin_layout Standard
36562
36563 \size footnotesize
36564 IC_LEFT() IC_RESULT()
36565 \end_layout
36566
36567 \end_inset
36568 </cell>
36569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36570 \begin_inset Text
36571
36572 \begin_layout Standard
36573
36574 \size footnotesize
36575 Bitwise complement of 
36576 \end_layout
36577
36578 \end_inset
36579 </cell>
36580 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36581 \begin_inset Text
36582
36583 \begin_layout Standard
36584
36585 \size footnotesize
36586 IC_RESULT = ~IC_LEFT;
36587 \end_layout
36588
36589 \end_inset
36590 </cell>
36591 </row>
36592 <row topline="true">
36593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36594 \begin_inset Text
36595
36596 \begin_layout Standard
36597
36598 \size footnotesize
36599 RRC
36600 \end_layout
36601
36602 \end_inset
36603 </cell>
36604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36605 \begin_inset Text
36606
36607 \begin_layout Standard
36608
36609 \size footnotesize
36610 IC_LEFT() IC_RESULT()
36611 \end_layout
36612
36613 \end_inset
36614 </cell>
36615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36616 \begin_inset Text
36617
36618 \begin_layout Standard
36619
36620 \size footnotesize
36621 Rotate right with carry
36622 \end_layout
36623
36624 \end_inset
36625 </cell>
36626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36627 \begin_inset Text
36628
36629 \begin_layout Standard
36630
36631 \size footnotesize
36632 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
36633 \end_layout
36634
36635 \end_inset
36636 </cell>
36637 </row>
36638 <row topline="true">
36639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36640 \begin_inset Text
36641
36642 \begin_layout Standard
36643
36644 \size footnotesize
36645 RLC
36646 \end_layout
36647
36648 \end_inset
36649 </cell>
36650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36651 \begin_inset Text
36652
36653 \begin_layout Standard
36654
36655 \size footnotesize
36656 IC_LEFT() IC_RESULT()
36657 \end_layout
36658
36659 \end_inset
36660 </cell>
36661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36662 \begin_inset Text
36663
36664 \begin_layout Standard
36665
36666 \size footnotesize
36667 Rotate left with carry
36668 \end_layout
36669
36670 \end_inset
36671 </cell>
36672 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36673 \begin_inset Text
36674
36675 \begin_layout Standard
36676
36677 \size footnotesize
36678 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
36679 \end_layout
36680
36681 \end_inset
36682 </cell>
36683 </row>
36684 <row topline="true">
36685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36686 \begin_inset Text
36687
36688 \begin_layout Standard
36689
36690 \size footnotesize
36691 GETHBIT
36692 \end_layout
36693
36694 \end_inset
36695 </cell>
36696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36697 \begin_inset Text
36698
36699 \begin_layout Standard
36700
36701 \size footnotesize
36702 IC_LEFT() IC_RESULT()
36703 \end_layout
36704
36705 \end_inset
36706 </cell>
36707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36708 \begin_inset Text
36709
36710 \begin_layout Standard
36711
36712 \size footnotesize
36713 Get the highest order bit of IC_LEFT
36714 \end_layout
36715
36716 \end_inset
36717 </cell>
36718 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36719 \begin_inset Text
36720
36721 \begin_layout Standard
36722
36723 \size footnotesize
36724 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
36725 \end_layout
36726
36727 \end_inset
36728 </cell>
36729 </row>
36730 <row topline="true">
36731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36732 \begin_inset Text
36733
36734 \begin_layout Standard
36735
36736 \size footnotesize
36737 UNARYMINUS
36738 \end_layout
36739
36740 \end_inset
36741 </cell>
36742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36743 \begin_inset Text
36744
36745 \begin_layout Standard
36746
36747 \size footnotesize
36748 IC_LEFT() IC_RESULT()
36749 \end_layout
36750
36751 \end_inset
36752 </cell>
36753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36754 \begin_inset Text
36755
36756 \begin_layout Standard
36757
36758 \size footnotesize
36759 Unary minus
36760 \end_layout
36761
36762 \end_inset
36763 </cell>
36764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36765 \begin_inset Text
36766
36767 \begin_layout Standard
36768
36769 \size footnotesize
36770 IC_RESULT = - IC_LEFT;
36771 \end_layout
36772
36773 \end_inset
36774 </cell>
36775 </row>
36776 <row topline="true">
36777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36778 \begin_inset Text
36779
36780 \begin_layout Standard
36781
36782 \size footnotesize
36783 IPUSH
36784 \end_layout
36785
36786 \end_inset
36787 </cell>
36788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36789 \begin_inset Text
36790
36791 \begin_layout Standard
36792
36793 \size footnotesize
36794 IC_LEFT()
36795 \end_layout
36796
36797 \end_inset
36798 </cell>
36799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36800 \begin_inset Text
36801
36802 \begin_layout Standard
36803
36804 \size footnotesize
36805 Push the operand into stack
36806 \end_layout
36807
36808 \end_inset
36809 </cell>
36810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36811 \begin_inset Text
36812
36813 \begin_layout Standard
36814
36815 \size footnotesize
36816 NONE
36817 \end_layout
36818
36819 \end_inset
36820 </cell>
36821 </row>
36822 <row topline="true">
36823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36824 \begin_inset Text
36825
36826 \begin_layout Standard
36827
36828 \size footnotesize
36829 IPOP
36830 \end_layout
36831
36832 \end_inset
36833 </cell>
36834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36835 \begin_inset Text
36836
36837 \begin_layout Standard
36838
36839 \size footnotesize
36840 IC_LEFT()
36841 \end_layout
36842
36843 \end_inset
36844 </cell>
36845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36846 \begin_inset Text
36847
36848 \begin_layout Standard
36849
36850 \size footnotesize
36851 Pop the operand from the stack 
36852 \end_layout
36853
36854 \end_inset
36855 </cell>
36856 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36857 \begin_inset Text
36858
36859 \begin_layout Standard
36860
36861 \size footnotesize
36862 NONE
36863 \end_layout
36864
36865 \end_inset
36866 </cell>
36867 </row>
36868 <row topline="true">
36869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36870 \begin_inset Text
36871
36872 \begin_layout Standard
36873
36874 \size footnotesize
36875 CALL
36876 \end_layout
36877
36878 \end_inset
36879 </cell>
36880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36881 \begin_inset Text
36882
36883 \begin_layout Standard
36884
36885 \size footnotesize
36886 IC_LEFT() IC_RESULT()
36887 \end_layout
36888
36889 \end_inset
36890 </cell>
36891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36892 \begin_inset Text
36893
36894 \begin_layout Standard
36895
36896 \size footnotesize
36897 Call the function represented by IC_LEFT 
36898 \end_layout
36899
36900 \end_inset
36901 </cell>
36902 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36903 \begin_inset Text
36904
36905 \begin_layout Standard
36906
36907 \size footnotesize
36908 IC_RESULT = IC_LEFT();
36909 \end_layout
36910
36911 \end_inset
36912 </cell>
36913 </row>
36914 <row topline="true">
36915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36916 \begin_inset Text
36917
36918 \begin_layout Standard
36919
36920 \size footnotesize
36921 PCALL
36922 \end_layout
36923
36924 \end_inset
36925 </cell>
36926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36927 \begin_inset Text
36928
36929 \begin_layout Standard
36930
36931 \size footnotesize
36932 IC_LEFT() IC_RESULT()
36933 \end_layout
36934
36935 \end_inset
36936 </cell>
36937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36938 \begin_inset Text
36939
36940 \begin_layout Standard
36941
36942 \size footnotesize
36943 Call via function pointer
36944 \end_layout
36945
36946 \end_inset
36947 </cell>
36948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36949 \begin_inset Text
36950
36951 \begin_layout Standard
36952
36953 \size footnotesize
36954 IC_RESULT = (*IC_LEFT)();
36955 \end_layout
36956
36957 \end_inset
36958 </cell>
36959 </row>
36960 <row topline="true">
36961 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36962 \begin_inset Text
36963
36964 \begin_layout Standard
36965
36966 \size footnotesize
36967 RETURN
36968 \end_layout
36969
36970 \end_inset
36971 </cell>
36972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36973 \begin_inset Text
36974
36975 \begin_layout Standard
36976
36977 \size footnotesize
36978 IC_LEFT()
36979 \end_layout
36980
36981 \end_inset
36982 </cell>
36983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36984 \begin_inset Text
36985
36986 \begin_layout Standard
36987
36988 \size footnotesize
36989 Return the value in operand IC_LEFT 
36990 \end_layout
36991
36992 \end_inset
36993 </cell>
36994 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36995 \begin_inset Text
36996
36997 \begin_layout Standard
36998
36999 \size footnotesize
37000 return IC_LEFT;
37001 \end_layout
37002
37003 \end_inset
37004 </cell>
37005 </row>
37006 <row topline="true">
37007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37008 \begin_inset Text
37009
37010 \begin_layout Standard
37011
37012 \size footnotesize
37013 LABEL
37014 \end_layout
37015
37016 \end_inset
37017 </cell>
37018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37019 \begin_inset Text
37020
37021 \begin_layout Standard
37022
37023 \size footnotesize
37024 IC_LABEL() 
37025 \end_layout
37026
37027 \end_inset
37028 </cell>
37029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37030 \begin_inset Text
37031
37032 \begin_layout Standard
37033
37034 \size footnotesize
37035 Label
37036 \end_layout
37037
37038 \end_inset
37039 </cell>
37040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37041 \begin_inset Text
37042
37043 \begin_layout Standard
37044
37045 \size footnotesize
37046 IC_LABEL:
37047 \end_layout
37048
37049 \end_inset
37050 </cell>
37051 </row>
37052 <row topline="true">
37053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37054 \begin_inset Text
37055
37056 \begin_layout Standard
37057
37058 \size footnotesize
37059 GOTO
37060 \end_layout
37061
37062 \end_inset
37063 </cell>
37064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37065 \begin_inset Text
37066
37067 \begin_layout Standard
37068
37069 \size footnotesize
37070 IC_LABEL() 
37071 \end_layout
37072
37073 \end_inset
37074 </cell>
37075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37076 \begin_inset Text
37077
37078 \begin_layout Standard
37079
37080 \size footnotesize
37081 Goto label
37082 \end_layout
37083
37084 \end_inset
37085 </cell>
37086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37087 \begin_inset Text
37088
37089 \begin_layout Standard
37090
37091 \size footnotesize
37092 goto IC_LABEL();
37093 \end_layout
37094
37095 \end_inset
37096 </cell>
37097 </row>
37098 <row topline="true">
37099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37100 \begin_inset Text
37101
37102 \begin_layout Standard
37103
37104 \size footnotesize
37105 '+'
37106 \end_layout
37107
37108 \end_inset
37109 </cell>
37110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37111 \begin_inset Text
37112
37113 \begin_layout Standard
37114
37115 \size footnotesize
37116 IC_LEFT() IC_RIGHT() IC_RESULT()
37117 \end_layout
37118
37119 \end_inset
37120 </cell>
37121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37122 \begin_inset Text
37123
37124 \begin_layout Standard
37125
37126 \size footnotesize
37127 Addition
37128 \end_layout
37129
37130 \end_inset
37131 </cell>
37132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37133 \begin_inset Text
37134
37135 \begin_layout Standard
37136
37137 \size footnotesize
37138 IC_RESULT = IC_LEFT + IC_RIGHT
37139 \end_layout
37140
37141 \end_inset
37142 </cell>
37143 </row>
37144 <row topline="true">
37145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37146 \begin_inset Text
37147
37148 \begin_layout Standard
37149
37150 \size footnotesize
37151 '-'
37152 \end_layout
37153
37154 \end_inset
37155 </cell>
37156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37157 \begin_inset Text
37158
37159 \begin_layout Standard
37160
37161 \size footnotesize
37162 IC_LEFT() IC_RIGHT() IC_RESULT()
37163 \end_layout
37164
37165 \end_inset
37166 </cell>
37167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37168 \begin_inset Text
37169
37170 \begin_layout Standard
37171
37172 \size footnotesize
37173 Subtraction
37174 \end_layout
37175
37176 \end_inset
37177 </cell>
37178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37179 \begin_inset Text
37180
37181 \begin_layout Standard
37182
37183 \size footnotesize
37184 IC_RESULT = IC_LEFT - IC_RIGHT 
37185 \end_layout
37186
37187 \end_inset
37188 </cell>
37189 </row>
37190 <row topline="true">
37191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37192 \begin_inset Text
37193
37194 \begin_layout Standard
37195
37196 \size footnotesize
37197 '*'
37198 \end_layout
37199
37200 \end_inset
37201 </cell>
37202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37203 \begin_inset Text
37204
37205 \begin_layout Standard
37206
37207 \size footnotesize
37208 IC_LEFT() IC_RIGHT() IC_RESULT()
37209 \end_layout
37210
37211 \end_inset
37212 </cell>
37213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37214 \begin_inset Text
37215
37216 \begin_layout Standard
37217
37218 \size footnotesize
37219 Multiplication 
37220 \end_layout
37221
37222 \end_inset
37223 </cell>
37224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37225 \begin_inset Text
37226
37227 \begin_layout Standard
37228
37229 \size footnotesize
37230 IC_RESULT = IC_LEFT * IC_RIGHT;
37231 \end_layout
37232
37233 \end_inset
37234 </cell>
37235 </row>
37236 <row topline="true">
37237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37238 \begin_inset Text
37239
37240 \begin_layout Standard
37241
37242 \size footnotesize
37243 '/'
37244 \end_layout
37245
37246 \end_inset
37247 </cell>
37248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37249 \begin_inset Text
37250
37251 \begin_layout Standard
37252
37253 \size footnotesize
37254 IC_LEFT() IC_RIGHT() IC_RESULT()
37255 \end_layout
37256
37257 \end_inset
37258 </cell>
37259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37260 \begin_inset Text
37261
37262 \begin_layout Standard
37263
37264 \size footnotesize
37265 Division
37266 \end_layout
37267
37268 \end_inset
37269 </cell>
37270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37271 \begin_inset Text
37272
37273 \begin_layout Standard
37274
37275 \size footnotesize
37276 IC_RESULT = IC_LEFT / IC_RIGHT;
37277 \end_layout
37278
37279 \end_inset
37280 </cell>
37281 </row>
37282 <row topline="true">
37283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37284 \begin_inset Text
37285
37286 \begin_layout Standard
37287
37288 \size footnotesize
37289 '%'
37290 \end_layout
37291
37292 \end_inset
37293 </cell>
37294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37295 \begin_inset Text
37296
37297 \begin_layout Standard
37298
37299 \size footnotesize
37300 IC_LEFT() IC_RIGHT() IC_RESULT()
37301 \end_layout
37302
37303 \end_inset
37304 </cell>
37305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37306 \begin_inset Text
37307
37308 \begin_layout Standard
37309
37310 \size footnotesize
37311 Modulus
37312 \end_layout
37313
37314 \end_inset
37315 </cell>
37316 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37317 \begin_inset Text
37318
37319 \begin_layout Standard
37320
37321 \size footnotesize
37322 IC_RESULT = IC_LEFT % IC_RIGHT;
37323 \end_layout
37324
37325 \end_inset
37326 </cell>
37327 </row>
37328 <row topline="true">
37329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37330 \begin_inset Text
37331
37332 \begin_layout Standard
37333
37334 \size footnotesize
37335 '<'
37336 \end_layout
37337
37338 \end_inset
37339 </cell>
37340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37341 \begin_inset Text
37342
37343 \begin_layout Standard
37344
37345 \size footnotesize
37346 IC_LEFT() IC_RIGHT() IC_RESULT()
37347 \end_layout
37348
37349 \end_inset
37350 </cell>
37351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37352 \begin_inset Text
37353
37354 \begin_layout Standard
37355
37356 \size footnotesize
37357 Less than
37358 \end_layout
37359
37360 \end_inset
37361 </cell>
37362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37363 \begin_inset Text
37364
37365 \begin_layout Standard
37366
37367 \size footnotesize
37368 IC_RESULT = IC_LEFT < IC_RIGHT;
37369 \end_layout
37370
37371 \end_inset
37372 </cell>
37373 </row>
37374 <row topline="true">
37375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37376 \begin_inset Text
37377
37378 \begin_layout Standard
37379
37380 \size footnotesize
37381 '>'
37382 \end_layout
37383
37384 \end_inset
37385 </cell>
37386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37387 \begin_inset Text
37388
37389 \begin_layout Standard
37390
37391 \size footnotesize
37392 IC_LEFT() IC_RIGHT() IC_RESULT()
37393 \end_layout
37394
37395 \end_inset
37396 </cell>
37397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37398 \begin_inset Text
37399
37400 \begin_layout Standard
37401
37402 \size footnotesize
37403 Greater than 
37404 \end_layout
37405
37406 \end_inset
37407 </cell>
37408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37409 \begin_inset Text
37410
37411 \begin_layout Standard
37412
37413 \size footnotesize
37414 IC_RESULT = IC_LEFT > IC_RIGHT;
37415 \end_layout
37416
37417 \end_inset
37418 </cell>
37419 </row>
37420 <row topline="true">
37421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37422 \begin_inset Text
37423
37424 \begin_layout Standard
37425
37426 \size footnotesize
37427 EQ_OP
37428 \end_layout
37429
37430 \end_inset
37431 </cell>
37432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37433 \begin_inset Text
37434
37435 \begin_layout Standard
37436
37437 \size footnotesize
37438 IC_LEFT() IC_RIGHT() IC_RESULT()
37439 \end_layout
37440
37441 \end_inset
37442 </cell>
37443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37444 \begin_inset Text
37445
37446 \begin_layout Standard
37447
37448 \size footnotesize
37449 Equal to 
37450 \end_layout
37451
37452 \end_inset
37453 </cell>
37454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37455 \begin_inset Text
37456
37457 \begin_layout Standard
37458
37459 \size footnotesize
37460 IC_RESULT = IC_LEFT == IC_RIGHT;
37461 \end_layout
37462
37463 \end_inset
37464 </cell>
37465 </row>
37466 <row topline="true">
37467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37468 \begin_inset Text
37469
37470 \begin_layout Standard
37471
37472 \size footnotesize
37473 AND_OP
37474 \end_layout
37475
37476 \end_inset
37477 </cell>
37478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37479 \begin_inset Text
37480
37481 \begin_layout Standard
37482
37483 \size footnotesize
37484 IC_LEFT() IC_RIGHT() IC_RESULT() 
37485 \end_layout
37486
37487 \end_inset
37488 </cell>
37489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37490 \begin_inset Text
37491
37492 \begin_layout Standard
37493
37494 \size footnotesize
37495 Logical and operation
37496 \end_layout
37497
37498 \end_inset
37499 </cell>
37500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37501 \begin_inset Text
37502
37503 \begin_layout Standard
37504
37505 \size footnotesize
37506 IC_RESULT = IC_LEFT && IC_RIGHT; 
37507 \end_layout
37508
37509 \end_inset
37510 </cell>
37511 </row>
37512 <row topline="true">
37513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37514 \begin_inset Text
37515
37516 \begin_layout Standard
37517
37518 \size footnotesize
37519 OR_OP
37520 \end_layout
37521
37522 \end_inset
37523 </cell>
37524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37525 \begin_inset Text
37526
37527 \begin_layout Standard
37528
37529 \size footnotesize
37530 IC_LEFT() IC_RIGHT() IC_RESULT() 
37531 \end_layout
37532
37533 \end_inset
37534 </cell>
37535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37536 \begin_inset Text
37537
37538 \begin_layout Standard
37539
37540 \size footnotesize
37541 Logical or operation 
37542 \end_layout
37543
37544 \end_inset
37545 </cell>
37546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37547 \begin_inset Text
37548
37549 \begin_layout Standard
37550
37551 \size footnotesize
37552 IC_RESULT = IC_LEFT || IC_RIGHT; 
37553 \end_layout
37554
37555 \end_inset
37556 </cell>
37557 </row>
37558 <row topline="true">
37559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37560 \begin_inset Text
37561
37562 \begin_layout Standard
37563
37564 \size footnotesize
37565 '^'
37566 \end_layout
37567
37568 \end_inset
37569 </cell>
37570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37571 \begin_inset Text
37572
37573 \begin_layout Standard
37574
37575 \size footnotesize
37576 IC_LEFT() IC_RIGHT() IC_RESULT() 
37577 \end_layout
37578
37579 \end_inset
37580 </cell>
37581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37582 \begin_inset Text
37583
37584 \begin_layout Standard
37585
37586 \size footnotesize
37587 Exclusive OR
37588 \end_layout
37589
37590 \end_inset
37591 </cell>
37592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37593 \begin_inset Text
37594
37595 \begin_layout Standard
37596
37597 \size footnotesize
37598 IC_RESULT = IC_LEFT ^ IC_RIGHT;
37599 \end_layout
37600
37601 \end_inset
37602 </cell>
37603 </row>
37604 <row topline="true">
37605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37606 \begin_inset Text
37607
37608 \begin_layout Standard
37609
37610 \size footnotesize
37611 '|'
37612 \end_layout
37613
37614 \end_inset
37615 </cell>
37616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37617 \begin_inset Text
37618
37619 \begin_layout Standard
37620
37621 \size footnotesize
37622 IC_LEFT() IC_RIGHT() IC_RESULT() 
37623 \end_layout
37624
37625 \end_inset
37626 </cell>
37627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37628 \begin_inset Text
37629
37630 \begin_layout Standard
37631
37632 \size footnotesize
37633 Bitwise OR 
37634 \end_layout
37635
37636 \end_inset
37637 </cell>
37638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37639 \begin_inset Text
37640
37641 \begin_layout Standard
37642
37643 \size footnotesize
37644 IC_RESULT = IC_LEFT | IC_RIGHT;
37645 \end_layout
37646
37647 \end_inset
37648 </cell>
37649 </row>
37650 <row topline="true">
37651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37652 \begin_inset Text
37653
37654 \begin_layout Standard
37655
37656 \size footnotesize
37657 BITWISEAND
37658 \end_layout
37659
37660 \end_inset
37661 </cell>
37662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37663 \begin_inset Text
37664
37665 \begin_layout Standard
37666
37667 \size footnotesize
37668 IC_LEFT() IC_RIGHT() IC_RESULT()
37669 \end_layout
37670
37671 \end_inset
37672 </cell>
37673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37674 \begin_inset Text
37675
37676 \begin_layout Standard
37677
37678 \size footnotesize
37679 Bitwise AND 
37680 \end_layout
37681
37682 \end_inset
37683 </cell>
37684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37685 \begin_inset Text
37686
37687 \begin_layout Standard
37688
37689 \size footnotesize
37690 IC_RESULT = IC_LEFT & IC_RIGHT;
37691 \end_layout
37692
37693 \end_inset
37694 </cell>
37695 </row>
37696 <row topline="true">
37697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37698 \begin_inset Text
37699
37700 \begin_layout Standard
37701
37702 \size footnotesize
37703 LEFT_OP
37704 \end_layout
37705
37706 \end_inset
37707 </cell>
37708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37709 \begin_inset Text
37710
37711 \begin_layout Standard
37712
37713 \size footnotesize
37714 IC_LEFT() IC_RIGHT() IC_RESULT()
37715 \end_layout
37716
37717 \end_inset
37718 </cell>
37719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37720 \begin_inset Text
37721
37722 \begin_layout Standard
37723
37724 \size footnotesize
37725 Left shift 
37726 \end_layout
37727
37728 \end_inset
37729 </cell>
37730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37731 \begin_inset Text
37732
37733 \begin_layout Standard
37734
37735 \size footnotesize
37736 IC_RESULT = IC_LEFT << IC_RIGHT 
37737 \end_layout
37738
37739 \end_inset
37740 </cell>
37741 </row>
37742 <row topline="true">
37743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37744 \begin_inset Text
37745
37746 \begin_layout Standard
37747
37748 \size footnotesize
37749 RIGHT_OP
37750 \end_layout
37751
37752 \end_inset
37753 </cell>
37754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37755 \begin_inset Text
37756
37757 \begin_layout Standard
37758
37759 \size footnotesize
37760 IC_LEFT() IC_RIGHT() IC_RESULT()
37761 \end_layout
37762
37763 \end_inset
37764 </cell>
37765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37766 \begin_inset Text
37767
37768 \begin_layout Standard
37769
37770 \size footnotesize
37771 Right shift
37772 \end_layout
37773
37774 \end_inset
37775 </cell>
37776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37777 \begin_inset Text
37778
37779 \begin_layout Standard
37780
37781 \size footnotesize
37782 IC_RESULT = IC_LEFT >> IC_RIGHT 
37783 \end_layout
37784
37785 \end_inset
37786 </cell>
37787 </row>
37788 <row topline="true">
37789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37790 \begin_inset Text
37791
37792 \begin_layout Standard
37793
37794 \size footnotesize
37795 GET_VALUE_
37796 \newline
37797 AT_ ADDRESS
37798 \end_layout
37799
37800 \end_inset
37801 </cell>
37802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37803 \begin_inset Text
37804
37805 \begin_layout Standard
37806
37807 \size footnotesize
37808 IC_LEFT() IC_RESULT()
37809 \end_layout
37810
37811 \end_inset
37812 </cell>
37813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37814 \begin_inset Text
37815
37816 \begin_layout Standard
37817
37818 \size footnotesize
37819 Indirect fetch 
37820 \end_layout
37821
37822 \end_inset
37823 </cell>
37824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37825 \begin_inset Text
37826
37827 \begin_layout Standard
37828
37829 \size footnotesize
37830 IC_RESULT = (*IC_LEFT);
37831 \end_layout
37832
37833 \end_inset
37834 </cell>
37835 </row>
37836 <row topline="true">
37837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37838 \begin_inset Text
37839
37840 \begin_layout Standard
37841
37842 \size footnotesize
37843 POINTER_SET
37844 \end_layout
37845
37846 \end_inset
37847 </cell>
37848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37849 \begin_inset Text
37850
37851 \begin_layout Standard
37852
37853 \size footnotesize
37854 IC_RIGHT() IC_RESULT() 
37855 \end_layout
37856
37857 \end_inset
37858 </cell>
37859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37860 \begin_inset Text
37861
37862 \begin_layout Standard
37863
37864 \size footnotesize
37865 Indirect set
37866 \end_layout
37867
37868 \end_inset
37869 </cell>
37870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37871 \begin_inset Text
37872
37873 \begin_layout Standard
37874
37875 \size footnotesize
37876 (*IC_RESULT) = IC_RIGHT;
37877 \end_layout
37878
37879 \end_inset
37880 </cell>
37881 </row>
37882 <row topline="true">
37883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37884 \begin_inset Text
37885
37886 \begin_layout Standard
37887
37888 \size footnotesize
37889 '='
37890 \end_layout
37891
37892 \end_inset
37893 </cell>
37894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37895 \begin_inset Text
37896
37897 \begin_layout Standard
37898
37899 \size footnotesize
37900 IC_RIGHT() IC_RESULT()
37901 \end_layout
37902
37903 \end_inset
37904 </cell>
37905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37906 \begin_inset Text
37907
37908 \begin_layout Standard
37909
37910 \size footnotesize
37911 Assignment
37912 \end_layout
37913
37914 \end_inset
37915 </cell>
37916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37917 \begin_inset Text
37918
37919 \begin_layout Standard
37920
37921 \size footnotesize
37922 IC_RESULT = IC_RIGHT;
37923 \end_layout
37924
37925 \end_inset
37926 </cell>
37927 </row>
37928 <row topline="true">
37929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37930 \begin_inset Text
37931
37932 \begin_layout Standard
37933
37934 \size footnotesize
37935 IFX
37936 \end_layout
37937
37938 \end_inset
37939 </cell>
37940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37941 \begin_inset Text
37942
37943 \begin_layout Standard
37944
37945 \size footnotesize
37946 IC_COND IC_TRUE IC_LABEL
37947 \end_layout
37948
37949 \end_inset
37950 </cell>
37951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37952 \begin_inset Text
37953
37954 \begin_layout Standard
37955
37956 \size footnotesize
37957 Conditional jump.
37958  If true label is present then jump to true label if condition is true else
37959  jump to false label if condition is false 
37960 \end_layout
37961
37962 \end_inset
37963 </cell>
37964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37965 \begin_inset Text
37966
37967 \begin_layout Standard
37968
37969 \size footnotesize
37970 if (IC_COND) goto IC_TRUE; 
37971 \newline
37972 \InsetSpace ~
37973 \InsetSpace ~
37974 Or 
37975 \newline
37976 If (!IC_COND) goto IC_FALSE;
37977 \end_layout
37978
37979 \end_inset
37980 </cell>
37981 </row>
37982 <row topline="true">
37983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37984 \begin_inset Text
37985
37986 \begin_layout Standard
37987
37988 \size footnotesize
37989 ADDRESS_OF
37990 \end_layout
37991
37992 \end_inset
37993 </cell>
37994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37995 \begin_inset Text
37996
37997 \begin_layout Standard
37998
37999 \size footnotesize
38000 IC_LEFT() IC_RESULT()
38001 \end_layout
38002
38003 \end_inset
38004 </cell>
38005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38006 \begin_inset Text
38007
38008 \begin_layout Standard
38009
38010 \size footnotesize
38011 Address of 
38012 \end_layout
38013
38014 \end_inset
38015 </cell>
38016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38017 \begin_inset Text
38018
38019 \begin_layout Standard
38020
38021 \size footnotesize
38022 IC_RESULT = &IC_LEFT();
38023 \end_layout
38024
38025 \end_inset
38026 </cell>
38027 </row>
38028 <row topline="true">
38029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38030 \begin_inset Text
38031
38032 \begin_layout Standard
38033
38034 \size footnotesize
38035 JUMPTABLE
38036 \end_layout
38037
38038 \end_inset
38039 </cell>
38040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38041 \begin_inset Text
38042
38043 \begin_layout Standard
38044
38045 \size footnotesize
38046 IC_JTCOND IC_JTLABELS
38047 \end_layout
38048
38049 \end_inset
38050 </cell>
38051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38052 \begin_inset Text
38053
38054 \begin_layout Standard
38055
38056 \size footnotesize
38057 Jump to list of labels depending on the value of JTCOND
38058 \end_layout
38059
38060 \end_inset
38061 </cell>
38062 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38063 \begin_inset Text
38064
38065 \begin_layout Standard
38066
38067 \size footnotesize
38068 Switch statement
38069 \end_layout
38070
38071 \end_inset
38072 </cell>
38073 </row>
38074 <row topline="true">
38075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38076 \begin_inset Text
38077
38078 \begin_layout Standard
38079
38080 \size footnotesize
38081 CAST
38082 \end_layout
38083
38084 \end_inset
38085 </cell>
38086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38087 \begin_inset Text
38088
38089 \begin_layout Standard
38090
38091 \size footnotesize
38092 IC_RIGHT() IC_LEFT() IC_RESULT()
38093 \end_layout
38094
38095 \end_inset
38096 </cell>
38097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38098 \begin_inset Text
38099
38100 \begin_layout Standard
38101
38102 \size footnotesize
38103 Cast types 
38104 \end_layout
38105
38106 \end_inset
38107 </cell>
38108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38109 \begin_inset Text
38110
38111 \begin_layout Standard
38112
38113 \size footnotesize
38114 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
38115 \end_layout
38116
38117 \end_inset
38118 </cell>
38119 </row>
38120 <row topline="true">
38121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38122 \begin_inset Text
38123
38124 \begin_layout Standard
38125
38126 \size footnotesize
38127 SEND
38128 \end_layout
38129
38130 \end_inset
38131 </cell>
38132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38133 \begin_inset Text
38134
38135 \begin_layout Standard
38136
38137 \size footnotesize
38138 IC_LEFT()
38139 \end_layout
38140
38141 \end_inset
38142 </cell>
38143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38144 \begin_inset Text
38145
38146 \begin_layout Standard
38147
38148 \size footnotesize
38149 This is used for passing parameters in registers; 
38150 \newline
38151 move IC_LEFT to the next
38152  available parameter register.
38153 \end_layout
38154
38155 \end_inset
38156 </cell>
38157 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38158 \begin_inset Text
38159
38160 \begin_layout Standard
38161
38162 \size footnotesize
38163 None
38164 \end_layout
38165
38166 \end_inset
38167 </cell>
38168 </row>
38169 <row topline="true">
38170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38171 \begin_inset Text
38172
38173 \begin_layout Standard
38174
38175 \size footnotesize
38176 RECV
38177 \end_layout
38178
38179 \end_inset
38180 </cell>
38181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38182 \begin_inset Text
38183
38184 \begin_layout Standard
38185
38186 \size footnotesize
38187 IC_RESULT()
38188 \end_layout
38189
38190 \end_inset
38191 </cell>
38192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38193 \begin_inset Text
38194
38195 \begin_layout Standard
38196
38197 \size footnotesize
38198 This is used for receiving parameters passed in registers;
38199 \newline
38200 Move the values
38201  in the next parameter register to IC_RESULT 
38202 \end_layout
38203
38204 \end_inset
38205 </cell>
38206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38207 \begin_inset Text
38208
38209 \begin_layout Standard
38210
38211 \size footnotesize
38212 None
38213 \end_layout
38214
38215 \end_inset
38216 </cell>
38217 </row>
38218 <row topline="true" bottomline="true">
38219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38220 \begin_inset Text
38221
38222 \begin_layout Standard
38223
38224 \shape slanted
38225 \size footnotesize
38226 (some more have been added)
38227 \end_layout
38228
38229 \end_inset
38230 </cell>
38231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38232 \begin_inset Text
38233
38234 \begin_layout Standard
38235
38236 \end_layout
38237
38238 \end_inset
38239 </cell>
38240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38241 \begin_inset Text
38242
38243 \begin_layout Standard
38244
38245 \end_layout
38246
38247 \end_inset
38248 </cell>
38249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38250 \begin_inset Text
38251
38252 \begin_layout Standard
38253
38254 \shape slanted
38255 \size footnotesize
38256 see f.e.
38257  
38258 \family typewriter
38259 gen51Code()
38260 \family default
38261  in 
38262 \family typewriter
38263 src/mcs51/gen.c
38264 \end_layout
38265
38266 \end_inset
38267 </cell>
38268 </row>
38269 </lyxtabular>
38270
38271 \end_inset
38272
38273
38274 \end_layout
38275
38276 \begin_layout Standard
38277 \begin_inset Note Note
38278 status collapsed
38279
38280 \begin_layout Standard
38281 In the original article Figure II was announced to be downloadable on 
38282 \shape italic
38283 Circuit Cellar
38284 \shape default
38285 's web site.
38286  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
38287 \end_layout
38288
38289 \end_inset
38290
38291
38292 \end_layout
38293
38294 \begin_layout Paragraph*
38295 ICode Example
38296 \begin_inset LatexCommand \index{iCode}
38297
38298 \end_inset
38299
38300
38301 \end_layout
38302
38303 \begin_layout Standard
38304 This section shows some details of iCode.
38305  The example C code does not do anything useful; it is used as an example
38306  to illustrate the intermediate code generated by the compiler.
38307 \end_layout
38308
38309 \begin_layout Verse
38310
38311 \family typewriter
38312 1.\InsetSpace ~
38313 xdata int * p;
38314 \newline
38315 2.\InsetSpace ~
38316 int gint;
38317 \newline
38318 3.\InsetSpace ~
38319 /* This function does nothing useful.
38320  It is used
38321 \newline
38322 4.\InsetSpace ~
38323 \InsetSpace ~
38324 \InsetSpace ~
38325 \InsetSpace ~
38326 for the purpose of explaining iCode */
38327 \newline
38328 5.\InsetSpace ~
38329 short function (data
38330  int *x)
38331 \newline
38332 6.\InsetSpace ~
38333 {
38334 \newline
38335 7.\InsetSpace ~
38336 \InsetSpace ~
38337 \InsetSpace ~
38338 short i=10; \InsetSpace ~
38339 \InsetSpace ~
38340 /* dead initialization eliminated */
38341 \newline
38342 8.\InsetSpace ~
38343 \InsetSpace ~
38344 \InsetSpace ~
38345 short sum=10;
38346  /* dead initialization eliminated */
38347 \newline
38348 9.\InsetSpace ~
38349 \InsetSpace ~
38350 \InsetSpace ~
38351 short mul;
38352 \newline
38353 10.\InsetSpace ~
38354 \InsetSpace ~
38355 int j ;
38356 \newline
38357 11.\InsetSpace ~
38358 \InsetSpace ~
38359 while (*x) *x++
38360  = *p++; 
38361 \newline
38362 12.\InsetSpace ~
38363 \InsetSpace ~
38364 \InsetSpace ~
38365 \InsetSpace ~
38366 sum = 0 ; 
38367 \newline
38368 13.\InsetSpace ~
38369 \InsetSpace ~
38370 mul = 0;
38371 \newline
38372 14.\InsetSpace ~
38373 \InsetSpace ~
38374 /* compiler detects i,j to be induction
38375  variables */
38376 \newline
38377 15.\InsetSpace ~
38378 \InsetSpace ~
38379 for (i = 0, j = 10 ; i < 10 ; i++, j
38380 \family default
38381 -
38382 \begin_inset ERT
38383 status collapsed
38384
38385 \begin_layout Standard
38386
38387
38388 \backslash
38389 /
38390 \end_layout
38391
38392 \end_inset
38393
38394 -
38395 \family typewriter
38396 ) {
38397 \newline
38398 16.\InsetSpace ~
38399 \InsetSpace ~
38400 \InsetSpace ~
38401 \InsetSpace ~
38402 sum += i;
38403 \newline
38404 17.\InsetSpace ~
38405 \InsetSpace ~
38406 \InsetSpace ~
38407 \InsetSpace ~
38408 mul += i * 3; \InsetSpace ~
38409 \InsetSpace ~
38410 /* this multiplication remains */
38411 \newline
38412 18.\InsetSpace ~
38413 \InsetSpace ~
38414 \InsetSpace ~
38415 \InsetSpace ~
38416 gint +=
38417  j * 3;\InsetSpace ~
38418 \InsetSpace ~
38419 /* this multiplication changed to addition */
38420 \newline
38421 19.\InsetSpace ~
38422 \InsetSpace ~
38423 }
38424 \newline
38425 20.\InsetSpace ~
38426 \InsetSpace ~
38427 return sum+mul;
38428 \newline
38429 21.\InsetSpace ~
38430 }
38431 \end_layout
38432
38433 \begin_layout Standard
38434 In addition to the operands each iCode contains information about the filename
38435  and line it corresponds to in the source file.
38436  The first field in the listing should be interpreted as follows:
38437 \newline
38438
38439 \shape italic
38440 \size footnotesize
38441 Filename(linenumber: iCode Execution sequence number : ICode hash table
38442  key : loop depth of the iCode).
38443 \shape default
38444 \size default
38445
38446 \newline
38447 Then follows the human readable form of the ICode operation.
38448  Each operand of this triplet form can be of three basic types a) compiler
38449  generated temporary b) user defined variable c) a constant value.
38450  Note that local variables and parameters are replaced by compiler generated
38451  temporaries.
38452  Live ranges
38453 \begin_inset LatexCommand \index{Live range analysis}
38454
38455 \end_inset
38456
38457  are computed only for temporaries (i.e.
38458  live ranges are not computed for global variables).
38459  Registers
38460 \begin_inset LatexCommand \index{Register allocation}
38461
38462 \end_inset
38463
38464  are allocated for temporaries only.
38465  Operands are formatted in the following manner:
38466 \newline
38467
38468 \shape italic
38469 \size footnotesize
38470 Operand Name [lr live-from : live-to ] { type information } [ registers
38471  allocated ].
38472 \shape default
38473 \size default
38474
38475 \newline
38476 As mentioned earlier the live ranges are computed in terms of the execution
38477  sequence number of the iCodes, for example 
38478 \newline
38479 the iTemp0 is live from (i.e.
38480  first defined in iCode with execution sequence number 3, and is last used
38481  in the iCode with sequence number 5).
38482  For induction variables such as iTemp21 the live range computation extends
38483  the lifetime from the start to the end of the loop.
38484 \newline
38485 The register allocator
38486  used the live range information to allocate registers, the same registers
38487  may be used for different temporaries if their live ranges do not overlap,
38488  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38489  ranges do not overlap.
38490  In addition the allocator also takes into consideration the type and usage
38491  of a temporary, for example itemp6 is a pointer to near space and is used
38492  as to fetch data from (i.e.
38493  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38494  Some short lived temporaries are allocated to special registers which have
38495  meaning to the code generator e.g.
38496  iTemp13 is allocated to a pseudo register CC which tells the back end that
38497  the temporary is used only for a conditional jump the code generation makes
38498  use of this information to optimize a compare and jump ICode.
38499 \newline
38500 There are several
38501  loop optimizations
38502 \begin_inset LatexCommand \index{Loop optimization}
38503
38504 \end_inset
38505
38506  performed by the compiler.
38507  It can detect induction variables iTemp21(i) and iTemp23(j).
38508  Also note the compiler does selective strength reduction
38509 \begin_inset LatexCommand \index{Strength reduction}
38510
38511 \end_inset
38512
38513 , i.e.
38514  the multiplication of an induction variable in line 18 (gint = j * 3) is
38515  changed to addition, a new temporary iTemp17 is allocated and assigned
38516  a initial value, a constant 3 is then added for each iteration of the loop.
38517  The compiler does not change the multiplication
38518 \begin_inset LatexCommand \index{Multiplication}
38519
38520 \end_inset
38521
38522  in line 17 however since the processor does support an 8 * 8 bit multiplication.
38523 \newline
38524
38525 Note the dead code elimination
38526 \begin_inset LatexCommand \index{Dead-code elimination}
38527
38528 \end_inset
38529
38530  optimization eliminated the dead assignments in line 7 & 8 to I and sum
38531  respectively.
38532 \newline
38533
38534 \end_layout
38535
38536 \begin_layout Standard
38537
38538 \size footnotesize
38539 Sample.c (5:1:0:0) _entry($9) :
38540 \end_layout
38541
38542 \begin_layout Standard
38543
38544 \size footnotesize
38545 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38546 \end_layout
38547
38548 \begin_layout Standard
38549
38550 \size footnotesize
38551 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
38552 \end_layout
38553
38554 \begin_layout Standard
38555
38556 \size footnotesize
38557 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38558 \end_layout
38559
38560 \begin_layout Standard
38561
38562 \size footnotesize
38563 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38564  * int}[r2]
38565 \end_layout
38566
38567 \begin_layout Standard
38568
38569 \size footnotesize
38570 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38571 \end_layout
38572
38573 \begin_layout Standard
38574
38575 \size footnotesize
38576 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38577  int}[r0]]
38578 \end_layout
38579
38580 \begin_layout Standard
38581
38582 \size footnotesize
38583 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38584 \end_layout
38585
38586 \begin_layout Standard
38587
38588 \size footnotesize
38589 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
38590  * int}
38591 \end_layout
38592
38593 \begin_layout Standard
38594
38595 \size footnotesize
38596 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
38597  {short}
38598 \end_layout
38599
38600 \begin_layout Standard
38601
38602 \size footnotesize
38603 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
38604  * int}[DPTR]]
38605 \end_layout
38606
38607 \begin_layout Standard
38608
38609 \size footnotesize
38610 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
38611 }[r2 r3]
38612 \end_layout
38613
38614 \begin_layout Standard
38615
38616 \size footnotesize
38617 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
38618  * int}[r0] + 0x2 {short}
38619 \end_layout
38620
38621 \begin_layout Standard
38622
38623 \size footnotesize
38624 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
38625 \end_layout
38626
38627 \begin_layout Standard
38628
38629 \size footnotesize
38630 Sample.c(11:17:21:0)_whilebreak_0($3) :
38631 \end_layout
38632
38633 \begin_layout Standard
38634
38635 \size footnotesize
38636 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38637 \end_layout
38638
38639 \begin_layout Standard
38640
38641 \size footnotesize
38642 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38643 \end_layout
38644
38645 \begin_layout Standard
38646
38647 \size footnotesize
38648 Sample.c(15:20:54:0)preHeaderLbl1($13) :
38649 \end_layout
38650
38651 \begin_layout Standard
38652
38653 \size footnotesize
38654 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38655 \end_layout
38656
38657 \begin_layout Standard
38658
38659 \size footnotesize
38660 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38661 \end_layout
38662
38663 \begin_layout Standard
38664
38665 \size footnotesize
38666 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38667 \end_layout
38668
38669 \begin_layout Standard
38670
38671 \size footnotesize
38672 Sample.c(15:24:26:1)_forcond_0($4) :
38673 \end_layout
38674
38675 \begin_layout Standard
38676
38677 \size footnotesize
38678 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
38679  < 0xa {short}
38680 \end_layout
38681
38682 \begin_layout Standard
38683
38684 \size footnotesize
38685 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38686 \end_layout
38687
38688 \begin_layout Standard
38689
38690 \size footnotesize
38691 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
38692  + ITemp21 [lr21:38]{short}[r4]
38693 \end_layout
38694
38695 \begin_layout Standard
38696
38697 \size footnotesize
38698 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
38699  * 0x3 {short}
38700 \end_layout
38701
38702 \begin_layout Standard
38703
38704 \size footnotesize
38705 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
38706  + iTemp15 [lr29:30]{short}[r1]
38707 \end_layout
38708
38709 \begin_layout Standard
38710
38711 \size footnotesize
38712 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
38713  r0]- 0x3 {short}
38714 \end_layout
38715
38716 \begin_layout Standard
38717
38718 \size footnotesize
38719 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
38720 int}[r7 r0]
38721 \end_layout
38722
38723 \begin_layout Standard
38724
38725 \size footnotesize
38726 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
38727  + 0x1 {short}
38728 \end_layout
38729
38730 \begin_layout Standard
38731
38732 \size footnotesize
38733 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
38734  r6]- 0x1 {short}
38735 \end_layout
38736
38737 \begin_layout Standard
38738
38739 \size footnotesize
38740 Sample.c(19:38:47:1) goto _forcond_0($4)
38741 \end_layout
38742
38743 \begin_layout Standard
38744
38745 \size footnotesize
38746 Sample.c(19:39:48:0)_forbreak_0($7) :
38747 \end_layout
38748
38749 \begin_layout Standard
38750
38751 \size footnotesize
38752 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
38753  + ITemp11 [lr19:40]{short}[r3]
38754 \end_layout
38755
38756 \begin_layout Standard
38757
38758 \size footnotesize
38759 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
38760 \end_layout
38761
38762 \begin_layout Standard
38763
38764 \size footnotesize
38765 Sample.c(20:42:51:0)_return($8) :
38766 \end_layout
38767
38768 \begin_layout Standard
38769
38770 \size footnotesize
38771 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
38772 \size default
38773
38774 \newline
38775
38776 \newline
38777 Finally the code generated for this function:
38778 \newline
38779
38780 \end_layout
38781
38782 \begin_layout Standard
38783
38784 \size footnotesize
38785 .area DSEG (DATA)
38786 \end_layout
38787
38788 \begin_layout Standard
38789
38790 \size footnotesize
38791 _p::
38792 \end_layout
38793
38794 \begin_layout Standard
38795
38796 \size footnotesize
38797 \InsetSpace ~
38798 \InsetSpace ~
38799 .ds 2
38800 \end_layout
38801
38802 \begin_layout Standard
38803
38804 \size footnotesize
38805 _gint::
38806 \end_layout
38807
38808 \begin_layout Standard
38809
38810 \size footnotesize
38811 \InsetSpace ~
38812 \InsetSpace ~
38813 .ds 2
38814 \end_layout
38815
38816 \begin_layout Standard
38817
38818 \size footnotesize
38819 ; sample.c 5
38820 \end_layout
38821
38822 \begin_layout Standard
38823
38824 \size footnotesize
38825 ; ----------------------------------------------
38826 \end_layout
38827
38828 \begin_layout Standard
38829
38830 \size footnotesize
38831 ; function function
38832 \end_layout
38833
38834 \begin_layout Standard
38835
38836 \size footnotesize
38837 ; ----------------------------------------------
38838 \end_layout
38839
38840 \begin_layout Standard
38841
38842 \size footnotesize
38843 _function:
38844 \end_layout
38845
38846 \begin_layout Standard
38847
38848 \size footnotesize
38849 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
38850 \end_layout
38851
38852 \begin_layout Standard
38853
38854 \size footnotesize
38855 \InsetSpace ~
38856 \InsetSpace ~
38857 mov r2,dpl
38858 \end_layout
38859
38860 \begin_layout Standard
38861
38862 \size footnotesize
38863 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
38864 \end_layout
38865
38866 \begin_layout Standard
38867
38868 \size footnotesize
38869 \InsetSpace ~
38870 \InsetSpace ~
38871 mov ar0,r2
38872 \end_layout
38873
38874 \begin_layout Standard
38875
38876 \size footnotesize
38877 ;_whilecontinue_0($1) :
38878 \end_layout
38879
38880 \begin_layout Standard
38881
38882 \size footnotesize
38883 00101$:
38884 \end_layout
38885
38886 \begin_layout Standard
38887
38888 \size footnotesize
38889 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
38890 \end_layout
38891
38892 \begin_layout Standard
38893
38894 \size footnotesize
38895 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38896 \end_layout
38897
38898 \begin_layout Standard
38899
38900 \size footnotesize
38901 \InsetSpace ~
38902 \InsetSpace ~
38903 mov ar2,@r0
38904 \end_layout
38905
38906 \begin_layout Standard
38907
38908 \size footnotesize
38909 \InsetSpace ~
38910 \InsetSpace ~
38911 inc r0
38912 \end_layout
38913
38914 \begin_layout Standard
38915
38916 \size footnotesize
38917 \InsetSpace ~
38918 \InsetSpace ~
38919 mov ar3,@r0
38920 \end_layout
38921
38922 \begin_layout Standard
38923
38924 \size footnotesize
38925 \InsetSpace ~
38926 \InsetSpace ~
38927 dec r0
38928 \end_layout
38929
38930 \begin_layout Standard
38931
38932 \size footnotesize
38933 \InsetSpace ~
38934 \InsetSpace ~
38935 mov a,r2
38936 \end_layout
38937
38938 \begin_layout Standard
38939
38940 \size footnotesize
38941 \InsetSpace ~
38942 \InsetSpace ~
38943 orl a,r3
38944 \end_layout
38945
38946 \begin_layout Standard
38947
38948 \size footnotesize
38949 \InsetSpace ~
38950 \InsetSpace ~
38951 jz 00103$
38952 \end_layout
38953
38954 \begin_layout Standard
38955
38956 \size footnotesize
38957 00114$:
38958 \end_layout
38959
38960 \begin_layout Standard
38961
38962 \size footnotesize
38963 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
38964 \end_layout
38965
38966 \begin_layout Standard
38967
38968 \size footnotesize
38969 \InsetSpace ~
38970 \InsetSpace ~
38971 mov dpl,_p
38972 \end_layout
38973
38974 \begin_layout Standard
38975
38976 \size footnotesize
38977 \InsetSpace ~
38978 \InsetSpace ~
38979 mov dph,(_p + 1)
38980 \end_layout
38981
38982 \begin_layout Standard
38983
38984 \size footnotesize
38985 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
38986 \end_layout
38987
38988 \begin_layout Standard
38989
38990 \size footnotesize
38991 \InsetSpace ~
38992 \InsetSpace ~
38993 mov a,#0x02
38994 \end_layout
38995
38996 \begin_layout Standard
38997
38998 \size footnotesize
38999 \InsetSpace ~
39000 \InsetSpace ~
39001 add a,_p
39002 \end_layout
39003
39004 \begin_layout Standard
39005
39006 \size footnotesize
39007 \InsetSpace ~
39008 \InsetSpace ~
39009 mov _p,a
39010 \end_layout
39011
39012 \begin_layout Standard
39013
39014 \size footnotesize
39015 \InsetSpace ~
39016 \InsetSpace ~
39017 clr a
39018 \end_layout
39019
39020 \begin_layout Standard
39021
39022 \size footnotesize
39023 \InsetSpace ~
39024 \InsetSpace ~
39025 addc a,(_p + 1)
39026 \end_layout
39027
39028 \begin_layout Standard
39029
39030 \size footnotesize
39031 \InsetSpace ~
39032 \InsetSpace ~
39033 mov (_p + 1),a
39034 \end_layout
39035
39036 \begin_layout Standard
39037
39038 \size footnotesize
39039 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
39040 \end_layout
39041
39042 \begin_layout Standard
39043
39044 \size footnotesize
39045 \InsetSpace ~
39046 \InsetSpace ~
39047 movx a,@dptr
39048 \end_layout
39049
39050 \begin_layout Standard
39051
39052 \size footnotesize
39053 \InsetSpace ~
39054 \InsetSpace ~
39055 mov r2,a
39056 \end_layout
39057
39058 \begin_layout Standard
39059
39060 \size footnotesize
39061 \InsetSpace ~
39062 \InsetSpace ~
39063 inc dptr
39064 \end_layout
39065
39066 \begin_layout Standard
39067
39068 \size footnotesize
39069 \InsetSpace ~
39070 \InsetSpace ~
39071 movx a,@dptr
39072 \end_layout
39073
39074 \begin_layout Standard
39075
39076 \size footnotesize
39077 \InsetSpace ~
39078 \InsetSpace ~
39079 mov r3,a
39080 \end_layout
39081
39082 \begin_layout Standard
39083
39084 \size footnotesize
39085 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
39086 \end_layout
39087
39088 \begin_layout Standard
39089
39090 \size footnotesize
39091 \InsetSpace ~
39092 \InsetSpace ~
39093 mov @r0,ar2
39094 \end_layout
39095
39096 \begin_layout Standard
39097
39098 \size footnotesize
39099 \InsetSpace ~
39100 \InsetSpace ~
39101 inc r0
39102 \end_layout
39103
39104 \begin_layout Standard
39105
39106 \size footnotesize
39107 \InsetSpace ~
39108 \InsetSpace ~
39109 mov @r0,ar3
39110 \end_layout
39111
39112 \begin_layout Standard
39113
39114 \size footnotesize
39115 ; iTemp6 [lr5:16]{_near * int}[r0] = 
39116 \end_layout
39117
39118 \begin_layout Standard
39119
39120 \size footnotesize
39121 ; iTemp6 [lr5:16]{_near * int}[r0] + 
39122 \end_layout
39123
39124 \begin_layout Standard
39125
39126 \size footnotesize
39127 ; 0x2 {short}
39128 \end_layout
39129
39130 \begin_layout Standard
39131
39132 \size footnotesize
39133 \InsetSpace ~
39134 \InsetSpace ~
39135 inc r0
39136 \end_layout
39137
39138 \begin_layout Standard
39139
39140 \size footnotesize
39141 ; goto _whilecontinue_0($1)
39142 \end_layout
39143
39144 \begin_layout Standard
39145
39146 \size footnotesize
39147 \InsetSpace ~
39148 \InsetSpace ~
39149 sjmp 00101$
39150 \end_layout
39151
39152 \begin_layout Standard
39153
39154 \size footnotesize
39155 ; _whilebreak_0($3) :
39156 \end_layout
39157
39158 \begin_layout Standard
39159
39160 \size footnotesize
39161 00103$:
39162 \end_layout
39163
39164 \begin_layout Standard
39165
39166 \size footnotesize
39167 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39168 \end_layout
39169
39170 \begin_layout Standard
39171
39172 \size footnotesize
39173 \InsetSpace ~
39174 \InsetSpace ~
39175 mov r2,#0x00
39176 \end_layout
39177
39178 \begin_layout Standard
39179
39180 \size footnotesize
39181 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39182 \end_layout
39183
39184 \begin_layout Standard
39185
39186 \size footnotesize
39187 \InsetSpace ~
39188 \InsetSpace ~
39189 mov r3,#0x00
39190 \end_layout
39191
39192 \begin_layout Standard
39193
39194 \size footnotesize
39195 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39196 \end_layout
39197
39198 \begin_layout Standard
39199
39200 \size footnotesize
39201 \InsetSpace ~
39202 \InsetSpace ~
39203 mov r4,#0x00
39204 \end_layout
39205
39206 \begin_layout Standard
39207
39208 \size footnotesize
39209 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39210 \end_layout
39211
39212 \begin_layout Standard
39213
39214 \size footnotesize
39215 \InsetSpace ~
39216 \InsetSpace ~
39217 mov r5,#0x0A
39218 \end_layout
39219
39220 \begin_layout Standard
39221
39222 \size footnotesize
39223 \InsetSpace ~
39224 \InsetSpace ~
39225 mov r6,#0x00
39226 \end_layout
39227
39228 \begin_layout Standard
39229
39230 \size footnotesize
39231 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39232 \end_layout
39233
39234 \begin_layout Standard
39235
39236 \size footnotesize
39237 \InsetSpace ~
39238 \InsetSpace ~
39239 mov r7,#0x1E
39240 \end_layout
39241
39242 \begin_layout Standard
39243
39244 \size footnotesize
39245 \InsetSpace ~
39246 \InsetSpace ~
39247 mov r0,#0x00
39248 \end_layout
39249
39250 \begin_layout Standard
39251
39252 \size footnotesize
39253 ; _forcond_0($4) :
39254 \end_layout
39255
39256 \begin_layout Standard
39257
39258 \size footnotesize
39259 00104$:
39260 \end_layout
39261
39262 \begin_layout Standard
39263
39264 \size footnotesize
39265 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
39266 \end_layout
39267
39268 \begin_layout Standard
39269
39270 \size footnotesize
39271 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39272 \end_layout
39273
39274 \begin_layout Standard
39275
39276 \size footnotesize
39277 \InsetSpace ~
39278 \InsetSpace ~
39279 clr c
39280 \end_layout
39281
39282 \begin_layout Standard
39283
39284 \size footnotesize
39285 \InsetSpace ~
39286 \InsetSpace ~
39287 mov a,r4
39288 \end_layout
39289
39290 \begin_layout Standard
39291
39292 \size footnotesize
39293 \InsetSpace ~
39294 \InsetSpace ~
39295 xrl a,#0x80
39296 \end_layout
39297
39298 \begin_layout Standard
39299
39300 \size footnotesize
39301 \InsetSpace ~
39302 \InsetSpace ~
39303 subb a,#0x8a
39304 \end_layout
39305
39306 \begin_layout Standard
39307
39308 \size footnotesize
39309 \InsetSpace ~
39310 \InsetSpace ~
39311 jnc 00107$
39312 \end_layout
39313
39314 \begin_layout Standard
39315
39316 \size footnotesize
39317 00115$:
39318 \end_layout
39319
39320 \begin_layout Standard
39321
39322 \size footnotesize
39323 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
39324 \end_layout
39325
39326 \begin_layout Standard
39327
39328 \size footnotesize
39329 ; iTemp21 [lr21:38]{short}[r4]
39330 \end_layout
39331
39332 \begin_layout Standard
39333
39334 \size footnotesize
39335 \InsetSpace ~
39336 \InsetSpace ~
39337 mov a,r4
39338 \end_layout
39339
39340 \begin_layout Standard
39341
39342 \size footnotesize
39343 \InsetSpace ~
39344 \InsetSpace ~
39345 add a,r2
39346 \end_layout
39347
39348 \begin_layout Standard
39349
39350 \size footnotesize
39351 \InsetSpace ~
39352 \InsetSpace ~
39353 mov r2,a
39354 \end_layout
39355
39356 \begin_layout Standard
39357
39358 \size footnotesize
39359 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
39360 \end_layout
39361
39362 \begin_layout Standard
39363
39364 \size footnotesize
39365 \InsetSpace ~
39366 \InsetSpace ~
39367 mov b,#0x03
39368 \end_layout
39369
39370 \begin_layout Standard
39371
39372 \size footnotesize
39373 \InsetSpace ~
39374 \InsetSpace ~
39375 mov a,r4
39376 \end_layout
39377
39378 \begin_layout Standard
39379
39380 \size footnotesize
39381 \InsetSpace ~
39382 \InsetSpace ~
39383 mul ab
39384 \end_layout
39385
39386 \begin_layout Standard
39387
39388 \size footnotesize
39389 \InsetSpace ~
39390 \InsetSpace ~
39391 mov r1,a
39392 \end_layout
39393
39394 \begin_layout Standard
39395
39396 \size footnotesize
39397 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
39398 \end_layout
39399
39400 \begin_layout Standard
39401
39402 \size footnotesize
39403 ; iTemp15 [lr29:30]{short}[r1]
39404 \end_layout
39405
39406 \begin_layout Standard
39407
39408 \size footnotesize
39409 \InsetSpace ~
39410 \InsetSpace ~
39411 add a,r3
39412 \end_layout
39413
39414 \begin_layout Standard
39415
39416 \size footnotesize
39417 \InsetSpace ~
39418 \InsetSpace ~
39419 mov r3,a
39420 \end_layout
39421
39422 \begin_layout Standard
39423
39424 \size footnotesize
39425 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
39426 \end_layout
39427
39428 \begin_layout Standard
39429
39430 \size footnotesize
39431 \InsetSpace ~
39432 \InsetSpace ~
39433 mov a,r7
39434 \end_layout
39435
39436 \begin_layout Standard
39437
39438 \size footnotesize
39439 \InsetSpace ~
39440 \InsetSpace ~
39441 add a,#0xfd
39442 \end_layout
39443
39444 \begin_layout Standard
39445
39446 \size footnotesize
39447 \InsetSpace ~
39448 \InsetSpace ~
39449 mov r7,a
39450 \end_layout
39451
39452 \begin_layout Standard
39453
39454 \size footnotesize
39455 \InsetSpace ~
39456 \InsetSpace ~
39457 mov a,r0
39458 \end_layout
39459
39460 \begin_layout Standard
39461
39462 \size footnotesize
39463 \InsetSpace ~
39464 \InsetSpace ~
39465 addc a,#0xff
39466 \end_layout
39467
39468 \begin_layout Standard
39469
39470 \size footnotesize
39471 \InsetSpace ~
39472 \InsetSpace ~
39473 mov r0,a
39474 \end_layout
39475
39476 \begin_layout Standard
39477
39478 \size footnotesize
39479 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39480 \end_layout
39481
39482 \begin_layout Standard
39483
39484 \size footnotesize
39485 \InsetSpace ~
39486 \InsetSpace ~
39487 mov a,r7
39488 \end_layout
39489
39490 \begin_layout Standard
39491
39492 \size footnotesize
39493 \InsetSpace ~
39494 \InsetSpace ~
39495 add a,_gint
39496 \end_layout
39497
39498 \begin_layout Standard
39499
39500 \size footnotesize
39501 \InsetSpace ~
39502 \InsetSpace ~
39503 mov _gint,a
39504 \end_layout
39505
39506 \begin_layout Standard
39507
39508 \size footnotesize
39509 \InsetSpace ~
39510 \InsetSpace ~
39511 mov a,r0
39512 \end_layout
39513
39514 \begin_layout Standard
39515
39516 \size footnotesize
39517 \InsetSpace ~
39518 \InsetSpace ~
39519 addc a,(_gint + 1)
39520 \end_layout
39521
39522 \begin_layout Standard
39523
39524 \size footnotesize
39525 \InsetSpace ~
39526 \InsetSpace ~
39527 mov (_gint + 1),a
39528 \end_layout
39529
39530 \begin_layout Standard
39531
39532 \size footnotesize
39533 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39534 \end_layout
39535
39536 \begin_layout Standard
39537
39538 \size footnotesize
39539 \InsetSpace ~
39540 \InsetSpace ~
39541 inc r4
39542 \end_layout
39543
39544 \begin_layout Standard
39545
39546 \size footnotesize
39547 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39548 \end_layout
39549
39550 \begin_layout Standard
39551
39552 \size footnotesize
39553 \InsetSpace ~
39554 \InsetSpace ~
39555 dec r5
39556 \end_layout
39557
39558 \begin_layout Standard
39559
39560 \size footnotesize
39561 \InsetSpace ~
39562 \InsetSpace ~
39563 cjne r5,#0xff,00104$
39564 \end_layout
39565
39566 \begin_layout Standard
39567
39568 \size footnotesize
39569 \InsetSpace ~
39570 \InsetSpace ~
39571 dec r6
39572 \end_layout
39573
39574 \begin_layout Standard
39575
39576 \size footnotesize
39577 ; goto _forcond_0($4)
39578 \end_layout
39579
39580 \begin_layout Standard
39581
39582 \size footnotesize
39583 \InsetSpace ~
39584 \InsetSpace ~
39585 sjmp 00104$
39586 \end_layout
39587
39588 \begin_layout Standard
39589
39590 \size footnotesize
39591 ; _forbreak_0($7) :
39592 \end_layout
39593
39594 \begin_layout Standard
39595
39596 \size footnotesize
39597 00107$:
39598 \end_layout
39599
39600 \begin_layout Standard
39601
39602 \size footnotesize
39603 ; ret iTemp24 [lr40:41]{short}
39604 \end_layout
39605
39606 \begin_layout Standard
39607
39608 \size footnotesize
39609 \InsetSpace ~
39610 \InsetSpace ~
39611 mov a,r3
39612 \end_layout
39613
39614 \begin_layout Standard
39615
39616 \size footnotesize
39617 \InsetSpace ~
39618 \InsetSpace ~
39619 add a,r2
39620 \end_layout
39621
39622 \begin_layout Standard
39623
39624 \size footnotesize
39625 \InsetSpace ~
39626 \InsetSpace ~
39627 mov dpl,a
39628 \end_layout
39629
39630 \begin_layout Standard
39631
39632 \size footnotesize
39633 ; _return($8) :
39634 \end_layout
39635
39636 \begin_layout Standard
39637
39638 \size footnotesize
39639 00108$:
39640 \end_layout
39641
39642 \begin_layout Standard
39643
39644 \size footnotesize
39645 \InsetSpace ~
39646 \InsetSpace ~
39647 ret
39648 \newline
39649
39650 \end_layout
39651
39652 \begin_layout Section
39653 A few words about basic block successors, predecessors and dominators
39654 \end_layout
39655
39656 \begin_layout Standard
39657 Successors are basic blocks
39658 \begin_inset LatexCommand \index{Basic blocks}
39659
39660 \end_inset
39661
39662  that might execute after this basic block.
39663 \newline
39664 Predecessors are basic blocks
39665  that might execute before reaching this basic block.
39666 \newline
39667 Dominators are basic
39668  blocks that WILL execute before reaching this basic block.
39669 \newline
39670
39671 \end_layout
39672
39673 \begin_layout Standard
39674 [basic block 1]
39675 \end_layout
39676
39677 \begin_layout Standard
39678 if (something)
39679 \end_layout
39680
39681 \begin_layout Standard
39682 \InsetSpace ~
39683 \InsetSpace ~
39684 \InsetSpace ~
39685 \InsetSpace ~
39686 [basic block 2]
39687 \end_layout
39688
39689 \begin_layout Standard
39690 else
39691 \end_layout
39692
39693 \begin_layout Standard
39694 \InsetSpace ~
39695 \InsetSpace ~
39696 \InsetSpace ~
39697 \InsetSpace ~
39698 [basic block 3]
39699 \end_layout
39700
39701 \begin_layout Standard
39702 [basic block 4]
39703 \newline
39704
39705 \end_layout
39706
39707 \begin_layout Standard
39708 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
39709 \end_layout
39710
39711 \begin_layout Standard
39712 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
39713 \end_layout
39714
39715 \begin_layout Standard
39716 c) domVect of [BB4] = BB1 ...
39717  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
39718  was executed.
39719 \end_layout
39720
39721 \begin_layout Chapter
39722 Acknowledgments
39723 \end_layout
39724
39725 \begin_layout Standard
39726 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
39727
39728 \end_inset
39729
39730
39731 \newline
39732
39733 \newline
39734
39735 \emph on
39736 Thanks to all the other volunteer developers who have helped with coding,
39737  testing, web-page creation, distribution sets, etc.
39738  You know who you are :-)
39739 \emph default
39740
39741 \newline
39742
39743 \newline
39744
39745 \emph on
39746 Thanks to Sourceforge 
39747 \begin_inset LatexCommand \url{http://www.sf.net}
39748
39749 \end_inset
39750
39751  which has hosted the project since 1999 and donates significant download
39752  bandwidth.
39753 \emph default
39754
39755 \newline
39756
39757 \newline
39758
39759 \emph on
39760 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
39761  cycles and bandwidth for snapshot builds.
39762 \newline
39763
39764 \end_layout
39765
39766 \begin_layout Standard
39767 This document was initially written by Sandeep Dutta
39768 \end_layout
39769
39770 \begin_layout Standard
39771 All product names mentioned herein may be trademarks
39772 \begin_inset LatexCommand \index{Trademarks}
39773
39774 \end_inset
39775
39776  of their respective companies.
39777  
39778 \end_layout
39779
39780 \begin_layout Section*
39781 Alphabetical index
39782 \end_layout
39783
39784 \begin_layout Standard
39785 To avoid confusion, the installation and building options for SDCC itself
39786  (chapter 2) are not part of the index.
39787 \end_layout
39788
39789 \begin_layout Standard
39790 \begin_inset LatexCommand \printindex{}
39791
39792 \end_inset
39793
39794
39795 \end_layout
39796
39797 \end_body
39798 \end_document