* doc/sdccman.lyx: changed sdcc version to 2.7.0,
[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.0
108 \size footnotesize
109
110 \newline
111 $Date::             $ 
112 \newline
113 $Revision$
114 \end_layout
115
116 \begin_layout Standard
117 \begin_inset Note Note
118 status collapsed
119
120 \begin_layout Standard
121 The above strings enclosed in $ are automatically updated by Subversion
122 \end_layout
123
124 \end_inset
125
126
127 \end_layout
128
129 \begin_layout Standard
130 \begin_inset LatexCommand \tableofcontents{}
131
132 \end_inset
133
134
135 \end_layout
136
137 \begin_layout Chapter
138 Introduction
139 \end_layout
140
141 \begin_layout Section
142 About SDCC
143 \end_layout
144
145 \begin_layout Standard
146
147 \series bold
148 SDCC
149 \series default
150  (
151 \emph on
152 S
153 \emph default
154 mall 
155 \emph on
156 D
157 \emph default
158 evice 
159 \emph on
160 C
161 \emph default
162  
163 \emph on
164 C
165 \emph default
166 ompiler) is free open source, retargettable, optimizing ANSI-C compiler
167  by 
168 \series bold
169 Sandeep Dutta
170 \series default
171  designed for 8 bit Microprocessors.
172  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
173  8051, 8052
174 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
175
176 \end_inset
177
178 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
179  Zilog Z80 based MCUs.
180  It can be retargeted for other microprocessors, support for Microchip PIC,
181  Atmel AVR is under development.
182  The entire source code for the compiler is distributed under GPL.
183  SDCC uses ASXXXX
184 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
185
186 \end_inset
187
188  & ASLINK
189 \begin_inset LatexCommand \index{aslink}
190
191 \end_inset
192
193 , an open source retargetable assembler & linker.
194  SDCC has extensive language extensions suitable for utilizing various microcont
195 rollers and underlying hardware effectively.
196  
197 \newline
198
199 \newline
200 In addition to the MCU specific optimizations SDCC also does a host of
201  standard optimizations like:
202 \end_layout
203
204 \begin_layout Itemize
205 global sub expression elimination, 
206 \end_layout
207
208 \begin_layout Itemize
209 loop optimizations (loop invariant, strength reduction of induction variables
210  and loop reversing), 
211 \end_layout
212
213 \begin_layout Itemize
214 constant folding & propagation, 
215 \end_layout
216
217 \begin_layout Itemize
218 copy propagation, 
219 \end_layout
220
221 \begin_layout Itemize
222 dead code elimination 
223 \end_layout
224
225 \begin_layout Itemize
226 jump tables for 
227 \emph on
228 switch
229 \emph default
230  statements.
231 \end_layout
232
233 \begin_layout Standard
234 For the back-end SDCC uses a global register allocation scheme which should
235  be well suited for other 8 bit MCUs.
236  
237 \newline
238
239 \newline
240 The peep hole optimizer uses a rule based substitution mechanism which
241  is MCU independent.
242  
243 \newline
244
245 \newline
246 Supported data-types are:
247 \end_layout
248
249 \begin_layout Standard
250 \begin_inset Tabular
251 <lyxtabular version="3" rows="8" columns="5">
252 <features>
253 <column alignment="center" valignment="top" leftline="true" width="0">
254 <column alignment="center" valignment="top" leftline="true" width="0">
255 <column alignment="center" valignment="top" leftline="true" width="0">
256 <column alignment="center" valignment="top" leftline="true" width="0">
257 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
258 <row topline="true" bottomline="true">
259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
260 \begin_inset Text
261
262 \begin_layout Standard
263 type
264 \end_layout
265
266 \end_inset
267 </cell>
268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
269 \begin_inset Text
270
271 \begin_layout Standard
272 width
273 \end_layout
274
275 \end_inset
276 </cell>
277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
278 \begin_inset Text
279
280 \begin_layout Standard
281 default
282 \end_layout
283
284 \end_inset
285 </cell>
286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
287 \begin_inset Text
288
289 \begin_layout Standard
290 signed range
291 \end_layout
292
293 \end_inset
294 </cell>
295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
296 \begin_inset Text
297
298 \begin_layout Standard
299 unsigned range
300 \end_layout
301
302 \end_inset
303 </cell>
304 </row>
305 <row topline="true">
306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
307 \begin_inset Text
308
309 \begin_layout Standard
310 bool
311 \end_layout
312
313 \end_inset
314 </cell>
315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
316 \begin_inset Text
317
318 \begin_layout Standard
319 1 bit
320 \end_layout
321
322 \end_inset
323 </cell>
324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
325 \begin_inset Text
326
327 \begin_layout Standard
328 unsigned
329 \end_layout
330
331 \end_inset
332 </cell>
333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
334 \begin_inset Text
335
336 \begin_layout Standard
337 -
338 \end_layout
339
340 \end_inset
341 </cell>
342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
343 \begin_inset Text
344
345 \begin_layout Standard
346 0, 1
347 \end_layout
348
349 \end_inset
350 </cell>
351 </row>
352 <row topline="true">
353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
354 \begin_inset Text
355
356 \begin_layout Standard
357 char
358 \end_layout
359
360 \end_inset
361 </cell>
362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
363 \begin_inset Text
364
365 \begin_layout Standard
366 8 bits, 1 byte
367 \end_layout
368
369 \end_inset
370 </cell>
371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
372 \begin_inset Text
373
374 \begin_layout Standard
375 signed
376 \end_layout
377
378 \end_inset
379 </cell>
380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
381 \begin_inset Text
382
383 \begin_layout Standard
384 -128, +127
385 \end_layout
386
387 \end_inset
388 </cell>
389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
390 \begin_inset Text
391
392 \begin_layout Standard
393 0, +255
394 \end_layout
395
396 \end_inset
397 </cell>
398 </row>
399 <row topline="true">
400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
401 \begin_inset Text
402
403 \begin_layout Standard
404 short
405 \end_layout
406
407 \end_inset
408 </cell>
409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
410 \begin_inset Text
411
412 \begin_layout Standard
413 16 bits, 2 bytes
414 \end_layout
415
416 \end_inset
417 </cell>
418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
419 \begin_inset Text
420
421 \begin_layout Standard
422 signed
423 \end_layout
424
425 \end_inset
426 </cell>
427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
428 \begin_inset Text
429
430 \begin_layout Standard
431 -32.768, +32.767
432 \end_layout
433
434 \end_inset
435 </cell>
436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
437 \begin_inset Text
438
439 \begin_layout Standard
440 0, +65.535
441 \end_layout
442
443 \end_inset
444 </cell>
445 </row>
446 <row topline="true">
447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
448 \begin_inset Text
449
450 \begin_layout Standard
451 int
452 \end_layout
453
454 \end_inset
455 </cell>
456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
457 \begin_inset Text
458
459 \begin_layout Standard
460 16 bits, 2 bytes
461 \end_layout
462
463 \end_inset
464 </cell>
465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
466 \begin_inset Text
467
468 \begin_layout Standard
469 signed
470 \end_layout
471
472 \end_inset
473 </cell>
474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
475 \begin_inset Text
476
477 \begin_layout Standard
478 -32.768, +32.767
479 \end_layout
480
481 \end_inset
482 </cell>
483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
484 \begin_inset Text
485
486 \begin_layout Standard
487 0, +65.535
488 \end_layout
489
490 \end_inset
491 </cell>
492 </row>
493 <row topline="true" bottomline="true">
494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
495 \begin_inset Text
496
497 \begin_layout Standard
498 long
499 \end_layout
500
501 \end_inset
502 </cell>
503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
504 \begin_inset Text
505
506 \begin_layout Standard
507 32 bits, 4 bytes
508 \end_layout
509
510 \end_inset
511 </cell>
512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
513 \begin_inset Text
514
515 \begin_layout Standard
516 signed
517 \end_layout
518
519 \end_inset
520 </cell>
521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
522 \begin_inset Text
523
524 \begin_layout Standard
525 -2.147.483.648, +2.147.483.647
526 \end_layout
527
528 \end_inset
529 </cell>
530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
531 \begin_inset Text
532
533 \begin_layout Standard
534 0, +4.294.967.295
535 \end_layout
536
537 \end_inset
538 </cell>
539 </row>
540 <row topline="true" bottomline="true">
541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
542 \begin_inset Text
543
544 \begin_layout Standard
545 float
546 \end_layout
547
548 \end_inset
549 </cell>
550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
551 \begin_inset Text
552
553 \begin_layout Standard
554 4 bytes IEEE 754
555 \end_layout
556
557 \end_inset
558 </cell>
559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
560 \begin_inset Text
561
562 \begin_layout Standard
563 signed
564 \end_layout
565
566 \end_inset
567 </cell>
568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
569 \begin_inset Text
570
571 \begin_layout Standard
572
573 \end_layout
574
575 \end_inset
576 </cell>
577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
578 \begin_inset Text
579
580 \begin_layout Standard
581 1.175494351E-38, 
582 \family roman
583 \series medium
584 \shape up
585 \size normal
586 \emph off
587 \bar no
588 \noun off
589 \color none
590 3.402823466E+38
591 \end_layout
592
593 \end_inset
594 </cell>
595 </row>
596 <row topline="true" bottomline="true">
597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
598 \begin_inset Text
599
600 \begin_layout Standard
601 pointer
602 \end_layout
603
604 \end_inset
605 </cell>
606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
607 \begin_inset Text
608
609 \begin_layout Standard
610 1, 2, 3 or 4 bytes
611 \end_layout
612
613 \end_inset
614 </cell>
615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
616 \begin_inset Text
617
618 \begin_layout Standard
619 generic
620 \end_layout
621
622 \end_inset
623 </cell>
624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
625 \begin_inset Text
626
627 \begin_layout Standard
628
629 \end_layout
630
631 \end_inset
632 </cell>
633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
634 \begin_inset Text
635
636 \begin_layout Standard
637
638 \end_layout
639
640 \end_inset
641 </cell>
642 </row>
643 </lyxtabular>
644
645 \end_inset
646
647
648 \newline
649 The compiler also allows 
650 \emph on
651 inline assembler code
652 \emph default
653  to be embedded anywhere in a function.
654  In addition, routines developed in assembly can also be called.
655 \newline
656
657 \newline
658 SDCC also
659  provides an option (-
660 \begin_inset ERT
661 status collapsed
662
663 \begin_layout Standard
664
665
666 \backslash
667 /
668 \end_layout
669
670 \end_inset
671
672 -cyclomatic) to report the relative complexity of a function.
673  These functions can then be further optimized, or hand coded in assembly
674  if needed.
675  
676 \newline
677
678 \newline
679 SDCC also comes with a companion source level debugger SDCDB.
680  The debugger currently uses ucSim, a free open source simulator for 8051
681  and other micro-controllers.
682 \newline
683
684 \newline
685 The latest SDCC version can be downloaded from
686  
687 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
688
689 \end_inset
690
691 .
692
693 \series bold
694  
695 \series default
696 \emph on
697 Please note: the compiler will probably always be some steps ahead of this
698  documentation
699 \series bold
700 \emph default
701
702 \begin_inset LatexCommand \index{Status of documentation}
703
704 \end_inset
705
706
707 \begin_inset Foot
708 status open
709
710 \begin_layout Standard
711 Obviously this has pros and cons
712 \end_layout
713
714 \end_inset
715
716 .
717 \end_layout
718
719 \begin_layout Section
720 Open Source
721 \end_layout
722
723 \begin_layout Standard
724 All packages used in this compiler system are 
725 \emph on
726 open source
727 \emph default
728  and 
729 \emph on
730 freeware
731 \emph default
732 ; source code for all the sub-packages (pre-processor, assemblers, linkers
733  etc) is distributed with the package.
734  This documentation is maintained using a free open source word processor
735  (LyX).
736 \newline
737 This program is free software; you can redistribute it and/or modify
738  it under the terms of the GNU General Public License
739 \begin_inset LatexCommand \index{GNU General Public License, GPL}
740
741 \end_inset
742
743  as published by the Free Software Foundation; either version 2, or (at
744  your option) any later version.
745  This program is distributed in the hope that it will be useful, but WITHOUT
746  ANY WARRANTY; without even the implied warranty
747 \begin_inset LatexCommand \index{warranty}
748
749 \end_inset
750
751  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
752  See the GNU General Public License for more details.
753  You should have received a copy of the GNU General Public License along
754  with this program; if not, write to the Free Software Foundation, 59 Temple
755  Place - Suite 330, Boston, MA 02111-1307, USA.
756  In other words, you are welcome to use, share and improve this program.
757  You are forbidden to forbid anyone else to use, share and improve what
758  you give them.
759  Help stamp out software-hoarding! 
760 \end_layout
761
762 \begin_layout Section
763 Typographic conventions
764 \begin_inset LatexCommand \index{Typographic conventions}
765
766 \end_inset
767
768
769 \end_layout
770
771 \begin_layout Standard
772 Throughout this manual, we will use the following convention.
773  Commands you have to type in are printed in 
774 \family sans
775 \series bold
776 "sans serif"
777 \series default
778 .
779
780 \family default
781  Code samples are printed in 
782 \family typewriter
783 typewriter font.
784
785 \family default
786  Interesting items and new terms are printed in 
787 \emph on
788 italic.
789 \end_layout
790
791 \begin_layout Section
792 Compatibility
793 \begin_inset LatexCommand \label{sec:Compatibility-with-previous}
794
795 \end_inset
796
797  with previous versions
798 \begin_inset LatexCommand \index{Compatibility with previous versions}
799
800 \end_inset
801
802
803 \end_layout
804
805 \begin_layout Standard
806 Newer versions have usually numerous bug fixes compared with the previous
807  version.
808  But we also sometimes introduce some incompatibilities with older versions.
809  Not just for the fun of it, but to make the compiler more stable, efficient
810  and ANSI compliant
811 \begin_inset LatexCommand \index{ANSI-compliance}
812
813 \end_inset
814
815  (see section 
816 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
817
818 \end_inset
819
820  for ANSI-Compliance).
821  
822 \begin_inset Note Note
823 status collapsed
824
825 \begin_layout Standard
826 It would be fine to add to each item, in which version was it changed.
827 \end_layout
828
829 \end_inset
830
831
832 \newline
833
834 \end_layout
835
836 \begin_layout Itemize
837 short is now equivalent to int (16 bits), it used to be equivalent to char
838  (8 bits) which is not ANSI compliant.
839  To maintain compatibility, old programs may be compiled using the --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  Variables with an absolute address are 
12825 \emph on
12826 not
12827 \begin_inset Marginal
12828 status collapsed
12829
12830 \begin_layout Standard
12831
12832 \series bold
12833 \InsetSpace ~
12834 !
12835 \end_layout
12836
12837 \end_inset
12838
12839
12840 \emph default
12841  initialized
12842 \begin_inset LatexCommand \index{Variable initialization}
12843
12844 \end_inset
12845
12846 .
12847 \end_layout
12848
12849 \begin_layout Standard
12850 In case of memory mapped I/O devices the keyword 
12851 \emph on
12852 volatile
12853 \emph default
12854  has to be used to tell the compiler that accesses might not be removed:
12855 \end_layout
12856
12857 \begin_layout Verse
12858
12859 \family typewriter
12860 volatile
12861 \begin_inset LatexCommand \index{volatile}
12862
12863 \end_inset
12864
12865  __xdata
12866 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12867
12868 \end_inset
12869
12870  __at
12871 \begin_inset LatexCommand \index{at}
12872
12873 \end_inset
12874
12875  (0x8000) unsigned char PORTA_8255;
12876 \end_layout
12877
12878 \begin_layout Standard
12879 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
12880 r) array
12881 \family typewriter
12882 \size footnotesize
12883
12884 \begin_inset LatexCommand \index{Aligned array}
12885
12886 \end_inset
12887
12888
12889 \family default
12890 \size default
12891  starts at a block (256 byte) boundary
12892 \begin_inset LatexCommand \index{block boundary}
12893
12894 \end_inset
12895
12896  (section 
12897 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12898
12899 \end_inset
12900
12901  has an example).
12902 \newline
12903 Absolute addresses can be specified for variables in all
12904  storage classes, e.g.:
12905 \end_layout
12906
12907 \begin_layout Verse
12908
12909 \family typewriter
12910 __bit
12911 \begin_inset LatexCommand \index{bit}
12912
12913 \end_inset
12914
12915  __at
12916 \begin_inset LatexCommand \index{at}
12917
12918 \end_inset
12919
12920  (0x02) bvar;
12921 \end_layout
12922
12923 \begin_layout Standard
12924 The above example will allocate the variable at offset 0x02 in the bit-addressab
12925 le space.
12926  There is no real advantage to assigning absolute addresses to variables
12927  in this manner, unless you want strict control over all the variables allocated.
12928  One possible use would be to write hardware portable code.
12929  For example, if you have a routine that uses one or more of the microcontroller
12930  I/O pins, and such pins are different for two different hardwares, you
12931  can declare the I/O pins in your routine using:
12932 \end_layout
12933
12934 \begin_layout Verse
12935
12936 \family typewriter
12937 extern volatile
12938 \begin_inset LatexCommand \index{volatile}
12939
12940 \end_inset
12941
12942  __bit MOSI;\InsetSpace ~
12943 \InsetSpace ~
12944 \InsetSpace ~
12945 \InsetSpace ~
12946 /* master out, slave in */
12947 \newline
12948 extern volatile __bit MISO;\InsetSpace ~
12949 \InsetSpace ~
12950 \InsetSpace ~
12951 \InsetSpace ~
12952 /* master
12953  in, slave out */
12954 \newline
12955 extern volatile __bit MCLK;\InsetSpace ~
12956 \InsetSpace ~
12957 \InsetSpace ~
12958 \InsetSpace ~
12959 /* master clock */
12960 \newline
12961
12962 \newline
12963 /* Input and
12964  Output of a byte on a 3-wire serial bus.
12965 \newline
12966 \InsetSpace ~
12967 \InsetSpace ~
12968 \InsetSpace ~
12969 If needed adapt polarity of clock,
12970  polarity of data and bit order
12971 \newline
12972 \InsetSpace ~
12973 */
12974 \newline
12975 unsigned char spi_io(unsigned char out_byte)
12976  
12977 \newline
12978
12979 \newline
12980 \InsetSpace ~
12981 \InsetSpace ~
12982 \InsetSpace ~
12983 \InsetSpace ~
12984 unsigned char i=8;
12985 \newline
12986 \InsetSpace ~
12987 \InsetSpace ~
12988 \InsetSpace ~
12989 \InsetSpace ~
12990 do { 
12991 \newline
12992 \InsetSpace ~
12993 \InsetSpace ~
12994 \InsetSpace ~
12995 \InsetSpace ~
12996 \InsetSpace ~
12997 \InsetSpace ~
12998 \InsetSpace ~
12999 \InsetSpace ~
13000 MOSI = out_byte & 0x80; 
13001 \newline
13002 \InsetSpace ~
13003 \InsetSpace ~
13004 \InsetSpace ~
13005 \InsetSpace ~
13006 \InsetSpace ~
13007 \InsetSpace ~
13008 \InsetSpace ~
13009 \InsetSpace ~
13010 out_byte <<= 1;
13011 \newline
13012 \InsetSpace ~
13013 \InsetSpace ~
13014 \InsetSpace ~
13015 \InsetSpace ~
13016 \InsetSpace ~
13017 \InsetSpace ~
13018 \InsetSpace ~
13019 \InsetSpace ~
13020 MCLK =
13021  1; 
13022 \newline
13023 \InsetSpace ~
13024 \InsetSpace ~
13025 \InsetSpace ~
13026 \InsetSpace ~
13027 \InsetSpace ~
13028 \InsetSpace ~
13029 \InsetSpace ~
13030 \InsetSpace ~
13031 /* _asm nop _endasm; */\InsetSpace ~
13032 \InsetSpace ~
13033 \InsetSpace ~
13034 \InsetSpace ~
13035 \InsetSpace ~
13036 \InsetSpace ~
13037 \InsetSpace ~
13038 \InsetSpace ~
13039 /* for slow peripherals */
13040 \newline
13041 \InsetSpace ~
13042 \InsetSpace ~
13043 \InsetSpace ~
13044 \InsetSpace ~
13045 \InsetSpace ~
13046 \InsetSpace ~
13047 \InsetSpace ~
13048 \InsetSpace ~
13049 if(MISO) 
13050 \newline
13051 \InsetSpace ~
13052 \InsetSpace ~
13053 \InsetSpace ~
13054 \InsetSpace ~
13055 \InsetSpace ~
13056 \InsetSpace ~
13057 \InsetSpace ~
13058 \InsetSpace ~
13059 \InsetSpace ~
13060 \InsetSpace ~
13061 \InsetSpace ~
13062 \InsetSpace ~
13063 out_byte +=
13064  1; 
13065 \newline
13066 \InsetSpace ~
13067 \InsetSpace ~
13068 \InsetSpace ~
13069 \InsetSpace ~
13070 \InsetSpace ~
13071 \InsetSpace ~
13072 \InsetSpace ~
13073 \InsetSpace ~
13074 MCLK = 0; 
13075 \newline
13076 \InsetSpace ~
13077 \InsetSpace ~
13078 \InsetSpace ~
13079 \InsetSpace ~
13080 } while(--i);
13081 \newline
13082 \InsetSpace ~
13083 \InsetSpace ~
13084 \InsetSpace ~
13085 \InsetSpace ~
13086 return out_byte; 
13087 \newline
13088 }
13089 \end_layout
13090
13091 \begin_layout Standard
13092 Then, someplace in the code for the first hardware you would use
13093 \end_layout
13094
13095 \begin_layout Verse
13096
13097 \family typewriter
13098 __bit __at
13099 \begin_inset LatexCommand \index{at}
13100
13101 \end_inset
13102
13103
13104 \begin_inset LatexCommand \index{\_\_at}
13105
13106 \end_inset
13107
13108  (0x80) MOSI;\InsetSpace ~
13109 \InsetSpace ~
13110 \InsetSpace ~
13111 \InsetSpace ~
13112 /* I/O port 0, bit 0 */
13113 \newline
13114 __bit __at (0x81) MISO;\InsetSpace ~
13115 \InsetSpace ~
13116 \InsetSpace ~
13117 \InsetSpace ~
13118 /* I/O port 0,
13119  bit 1 */
13120 \newline
13121 __bit __at (0x82) MCLK;\InsetSpace ~
13122 \InsetSpace ~
13123 \InsetSpace ~
13124 \InsetSpace ~
13125 /* I/O port 0, bit 2 */
13126 \end_layout
13127
13128 \begin_layout Standard
13129 Similarly, for the second hardware you would use
13130 \end_layout
13131
13132 \begin_layout Verse
13133
13134 \family typewriter
13135 __bit __at (0x83) MOSI;\InsetSpace ~
13136 \InsetSpace ~
13137 \InsetSpace ~
13138 \InsetSpace ~
13139 /* I/O port 0, bit 3 */
13140 \newline
13141 __bit __at (0x91) MISO;\InsetSpace ~
13142 \InsetSpace ~
13143 \InsetSpace ~
13144 \InsetSpace ~
13145 /*
13146  I/O port 1, bit 1 */
13147 \newline
13148 __bit
13149 \begin_inset LatexCommand \index{bit}
13150
13151 \end_inset
13152
13153  __at (0x92) MCLK;\InsetSpace ~
13154 \InsetSpace ~
13155 \InsetSpace ~
13156 \InsetSpace ~
13157 /* I/O port 1, bit 2 */
13158 \end_layout
13159
13160 \begin_layout Standard
13161 and you can use the same hardware dependent routine without changes, as
13162  for example in a library.
13163  This is somehow similar to sbit, but only one absolute address has to be
13164  specified in the whole project.
13165 \begin_inset VSpace bigskip
13166 \end_inset
13167
13168
13169 \end_layout
13170
13171 \begin_layout Section
13172 Parameters
13173 \begin_inset LatexCommand \index{Parameters}
13174
13175 \end_inset
13176
13177
13178 \begin_inset LatexCommand \index{function parameter}
13179
13180 \end_inset
13181
13182  & Local Variables
13183 \begin_inset LatexCommand \index{local variables}
13184
13185 \end_inset
13186
13187
13188 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
13189
13190 \end_inset
13191
13192
13193 \end_layout
13194
13195 \begin_layout Standard
13196 Automatic (local) variables and parameters to functions can either be placed
13197  on the stack or in data-space.
13198  The default action of the compiler is to place these variables in the internal
13199  RAM (for small model) or external RAM (for large model).
13200  This in fact makes them similar to 
13201 \emph on
13202 static
13203 \begin_inset LatexCommand \index{static}
13204
13205 \end_inset
13206
13207
13208 \emph default
13209  so by default functions are non-reentrant
13210 \begin_inset LatexCommand \index{reentrant}
13211
13212 \end_inset
13213
13214 .
13215  
13216 \newline
13217
13218 \newline
13219 They can be placed on the stack
13220 \begin_inset LatexCommand \index{stack}
13221
13222 \end_inset
13223
13224  by using the
13225 \emph on
13226  -
13227 \begin_inset ERT
13228 status collapsed
13229
13230 \begin_layout Standard
13231
13232
13233 \backslash
13234 /
13235 \end_layout
13236
13237 \end_inset
13238
13239 -stack-auto
13240 \begin_inset LatexCommand \index{-\/-stack-auto}
13241
13242 \end_inset
13243
13244
13245 \emph default
13246  option, by using 
13247 \emph on
13248 #pragma\InsetSpace ~
13249 stackauto
13250 \emph default
13251
13252 \begin_inset LatexCommand \index{\#pragma stackauto}
13253
13254 \end_inset
13255
13256  or by using the 
13257 \emph on
13258 reentrant
13259 \begin_inset LatexCommand \index{reentrant}
13260
13261 \end_inset
13262
13263
13264 \emph default
13265  keyword in the function declaration, e.g.:
13266 \end_layout
13267
13268 \begin_layout Verse
13269
13270 \family typewriter
13271 unsigned char foo(char i) __reentrant 
13272 \newline
13273
13274 \newline
13275 \InsetSpace ~
13276 \InsetSpace ~
13277 \InsetSpace ~
13278 \InsetSpace ~
13279 ...
13280  
13281 \newline
13282 }
13283 \end_layout
13284
13285 \begin_layout Standard
13286 Since stack space on 8051 is limited, the 
13287 \emph on
13288 reentrant 
13289 \emph default
13290 keyword or the
13291 \emph on
13292  -
13293 \begin_inset ERT
13294 status collapsed
13295
13296 \begin_layout Standard
13297
13298
13299 \backslash
13300 /
13301 \end_layout
13302
13303 \end_inset
13304
13305 -stack-auto
13306 \emph default
13307  option should be used sparingly.
13308  Note that the reentrant keyword just means that the parameters & local
13309  variables will be allocated to the stack, it 
13310 \emph on
13311 does not
13312 \emph default
13313  mean that the function is register bank
13314 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13315
13316 \end_inset
13317
13318  independent.
13319 \newline
13320
13321 \newline
13322 Local variables
13323 \begin_inset LatexCommand \index{local variables}
13324
13325 \end_inset
13326
13327  can be assigned storage classes and absolute
13328 \begin_inset LatexCommand \index{Absolute addressing}
13329
13330 \end_inset
13331
13332  addresses, e.g.: 
13333 \end_layout
13334
13335 \begin_layout Verse
13336
13337 \family typewriter
13338 unsigned char foo() 
13339 \newline
13340 {
13341 \newline
13342 \InsetSpace ~
13343 \InsetSpace ~
13344 \InsetSpace ~
13345 \InsetSpace ~
13346 __xdata unsigned char i;
13347 \newline
13348 \InsetSpace ~
13349 \InsetSpace ~
13350 \InsetSpace ~
13351 \InsetSpace ~
13352 __bit bvar;
13353 \newline
13354 \InsetSpace ~
13355 \InsetSpace ~
13356 \InsetSpace ~
13357 \InsetSpace ~
13358 __data __at
13359 \begin_inset LatexCommand \index{at}
13360
13361 \end_inset
13362
13363  (0x31) unsigned char j;
13364 \newline
13365 \InsetSpace ~
13366 \InsetSpace ~
13367 \InsetSpace ~
13368 \InsetSpace ~
13369 ...
13370  
13371 \newline
13372 }
13373 \end_layout
13374
13375 \begin_layout Standard
13376 In the above example the variable 
13377 \emph on
13378 i
13379 \emph default
13380  will be allocated in the external ram, 
13381 \emph on
13382 bvar
13383 \emph default
13384  in bit addressable space and
13385 \emph on
13386  j
13387 \emph default
13388  in internal ram.
13389  When compiled with 
13390 \emph on
13391 -
13392 \begin_inset ERT
13393 status collapsed
13394
13395 \begin_layout Standard
13396
13397
13398 \backslash
13399 /
13400 \end_layout
13401
13402 \end_inset
13403
13404 -stack-auto
13405 \emph default
13406  or when a function is declared as 
13407 \emph on
13408 reentrant
13409 \emph default
13410  this should only be done for static variables.
13411 \end_layout
13412
13413 \begin_layout Standard
13414 Parameters
13415 \begin_inset LatexCommand \index{function parameter}
13416
13417 \end_inset
13418
13419  however are not allowed any storage class
13420 \begin_inset LatexCommand \index{Storage class}
13421
13422 \end_inset
13423
13424 , (storage classes for parameters will be ignored), their allocation is
13425  governed by the memory model in use, and the reentrancy options.
13426 \end_layout
13427
13428 \begin_layout Standard
13429 It is however allowed to use bit parameters in reentrant functions and also
13430  non-static local bit variables are supported.
13431  Efficient use is limited to 8 semi-bitregisters in bit space.
13432  They are pushed and popped to stack
13433 \begin_inset LatexCommand \index{stack}
13434
13435 \end_inset
13436
13437  as a single byte just like the normal registers.
13438 \end_layout
13439
13440 \begin_layout Section
13441 Overlaying
13442 \begin_inset LatexCommand \label{sub:Overlaying}
13443
13444 \end_inset
13445
13446
13447 \begin_inset LatexCommand \index{Overlaying}
13448
13449 \end_inset
13450
13451
13452 \end_layout
13453
13454 \begin_layout Standard
13455 For non-reentrant
13456 \begin_inset LatexCommand \index{reentrant}
13457
13458 \end_inset
13459
13460  functions SDCC will try to reduce internal ram space usage by overlaying
13461  parameters and local variables of a function (if possible).
13462  Parameters and local variables
13463 \begin_inset LatexCommand \index{local variables}
13464
13465 \end_inset
13466
13467  of a function will be allocated to an overlayable segment if the function
13468  has 
13469 \emph on
13470 no other function calls and the function is non-reentrant and the memory
13471  model
13472 \begin_inset LatexCommand \index{Memory model}
13473
13474 \end_inset
13475
13476  is small.
13477
13478 \emph default
13479  If an explicit storage class
13480 \begin_inset LatexCommand \index{Storage class}
13481
13482 \end_inset
13483
13484  is specified for a local variable, it will NOT be overlayed.
13485 \end_layout
13486
13487 \begin_layout Standard
13488 Note that the compiler (not the linkage editor) makes the decision for overlayin
13489 g the data items.
13490  Functions that are called from an interrupt service routine
13491 \begin_inset Marginal
13492 status collapsed
13493
13494 \begin_layout Standard
13495
13496 \series bold
13497 !
13498 \end_layout
13499
13500 \end_inset
13501
13502  should be preceded by a #pragma\InsetSpace ~
13503 nooverlay
13504 \begin_inset LatexCommand \index{\#pragma nooverlay}
13505
13506 \end_inset
13507
13508  if they are not reentrant.
13509 \end_layout
13510
13511 \begin_layout Standard
13512 Also note that the compiler does not do any processing of inline assembler
13513  code, so the compiler might incorrectly assign local variables and parameters
13514  of a function into the overlay segment if the inline assembler code calls
13515  other c-functions that might use the overlay.
13516  In that case the #pragma\InsetSpace ~
13517 nooverlay should be used.
13518 \end_layout
13519
13520 \begin_layout Standard
13521 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13522 tion
13523 \begin_inset LatexCommand \index{Multiplication}
13524
13525 \end_inset
13526
13527  or division
13528 \begin_inset LatexCommand \index{Division}
13529
13530 \end_inset
13531
13532  will NOT be overlayed since these are implemented using external functions,
13533  e.g.:
13534 \end_layout
13535
13536 \begin_layout Verse
13537
13538 \family typewriter
13539 #pragma save 
13540 \newline
13541 #pragma nooverlay
13542 \begin_inset LatexCommand \index{\#pragma nooverlay}
13543
13544 \end_inset
13545
13546  
13547 \newline
13548 void set_error(unsigned char errcd) 
13549 \newline
13550 {
13551 \newline
13552 \InsetSpace ~
13553 \InsetSpace ~
13554 \InsetSpace ~
13555 \InsetSpace ~
13556 P3 = errcd;
13557 \newline
13558
13559 \newline
13560 #pragma restore 
13561 \newline
13562
13563 \newline
13564 void
13565  some_isr () __interrupt
13566 \begin_inset LatexCommand \index{interrupt}
13567
13568 \end_inset
13569
13570  (2)
13571 \newline
13572 {
13573 \newline
13574 \InsetSpace ~
13575 \InsetSpace ~
13576 \InsetSpace ~
13577 \InsetSpace ~
13578 ...
13579 \newline
13580 \InsetSpace ~
13581 \InsetSpace ~
13582 \InsetSpace ~
13583 \InsetSpace ~
13584 set_error(10);
13585 \newline
13586 \InsetSpace ~
13587 \InsetSpace ~
13588 \InsetSpace ~
13589 \InsetSpace ~
13590 ...
13591  
13592 \newline
13593 }
13594 \end_layout
13595
13596 \begin_layout Standard
13597 In the above example the parameter 
13598 \emph on
13599 errcd
13600 \emph default
13601  for the function 
13602 \emph on
13603 set_error
13604 \emph default
13605  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13606 nooverlay was
13607  not present, this could cause unpredictable runtime behavior when called
13608  from an interrupt service routine.
13609  The #pragma\InsetSpace ~
13610 nooverlay ensures that the parameters and local variables for
13611  the function are NOT overlayed.
13612 \begin_inset VSpace bigskip
13613 \end_inset
13614
13615
13616 \end_layout
13617
13618 \begin_layout Section
13619 Interrupt Service Routines
13620 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13621
13622 \end_inset
13623
13624
13625 \end_layout
13626
13627 \begin_layout Subsection
13628 General Information
13629 \end_layout
13630
13631 \begin_layout Standard
13632 SDCC allows 
13633 \emph on
13634 i
13635 \emph default
13636 nterrupt 
13637 \emph on
13638 s
13639 \emph default
13640 ervice 
13641 \emph on
13642 r
13643 \emph default
13644 outines to be coded in C, with some extended keywords.
13645 \end_layout
13646
13647 \begin_layout Verse
13648
13649 \family typewriter
13650 void timer_isr (void) __interrupt (1) __using (1) 
13651 \newline
13652
13653 \newline
13654 \InsetSpace ~
13655 \InsetSpace ~
13656 \InsetSpace ~
13657 \InsetSpace ~
13658 ...
13659  
13660 \newline
13661 }
13662 \end_layout
13663
13664 \begin_layout Standard
13665 The optional number following the 
13666 \emph on
13667 interrupt
13668 \begin_inset LatexCommand \index{interrupt}
13669
13670 \end_inset
13671
13672
13673 \begin_inset LatexCommand \index{\_\_interrupt}
13674
13675 \end_inset
13676
13677
13678 \emph default
13679  keyword is the interrupt number this routine will service.
13680  When present, the compiler will insert a call to this routine in the interrupt
13681  vector table
13682 \begin_inset LatexCommand \index{interrupt vector table}
13683
13684 \end_inset
13685
13686  for the interrupt number specified.
13687  If you have multiple source files in your project, interrupt service routines
13688  can be present in any of them, but a prototype of the isr MUST be present
13689  or included in the file that contains the function 
13690 \emph on
13691 main
13692 \emph default
13693 .
13694  The optional (8051 specific) keyword 
13695 \emph on
13696 using
13697 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13698
13699 \end_inset
13700
13701
13702 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13703
13704 \end_inset
13705
13706
13707 \emph default
13708  can be used to tell the compiler to use the specified register bank when
13709  generating code for this function.
13710  
13711 \newline
13712 Interrupt service routines open the door for some very interesting bugs:
13713 \end_layout
13714
13715 \begin_layout Subsubsection
13716 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13717
13718 \end_inset
13719
13720 Common interrupt pitfall: variable not declared 
13721 \emph on
13722 volatile
13723 \end_layout
13724
13725 \begin_layout Standard
13726 If an interrupt service routine changes variables which are accessed by
13727  other functions these variables have to be declared 
13728 \emph on
13729 volatile
13730 \emph default
13731
13732 \begin_inset LatexCommand \index{volatile}
13733
13734 \end_inset
13735
13736 .
13737  See 
13738 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
13739
13740 \end_inset
13741
13742  .
13743 \end_layout
13744
13745 \begin_layout Subsubsection
13746 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
13747
13748 \end_inset
13749
13750 Common interrupt pitfall: 
13751 \emph on
13752 non-atomic access
13753 \end_layout
13754
13755 \begin_layout Standard
13756 If the access to these variables is not 
13757 \emph on
13758 atomic
13759 \begin_inset LatexCommand \index{atomic}
13760
13761 \end_inset
13762
13763
13764 \emph default
13765  (i.e.
13766  the processor needs more than one instruction for the access and could
13767  be interrupted while accessing the variable) the interrupt must be disabled
13768  during the access to avoid inconsistent data.
13769  
13770 \newline
13771 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
13772  and should be protected by disabling interrupts.
13773  You're not automatically on the safe side if you use 8 bit variables though.
13774  We need an example here: f.e.
13775  on the 8051 the harmless looking 
13776 \begin_inset Quotes srd
13777 \end_inset
13778
13779
13780 \family typewriter
13781 flags\InsetSpace ~
13782 |=\InsetSpace ~
13783 0x80;
13784 \family default
13785
13786 \begin_inset Quotes sld
13787 \end_inset
13788
13789  is not atomic if 
13790 \family typewriter
13791 flags
13792 \family default
13793  resides in xdata.
13794  Setting 
13795 \begin_inset Quotes srd
13796 \end_inset
13797
13798
13799 \family typewriter
13800 flags\InsetSpace ~
13801 |=\InsetSpace ~
13802 0x40;
13803 \family default
13804
13805 \begin_inset Quotes sld
13806 \end_inset
13807
13808  from within an interrupt routine might get lost if the interrupt occurs
13809  at the wrong time.
13810  
13811 \begin_inset Quotes sld
13812 \end_inset
13813
13814
13815 \family typewriter
13816 counter\InsetSpace ~
13817 +=\InsetSpace ~
13818 8;
13819 \family default
13820
13821 \begin_inset Quotes srd
13822 \end_inset
13823
13824  is not atomic on the 8051 even if 
13825 \family typewriter
13826 counter
13827 \family default
13828  is located in data memory.
13829 \newline
13830 Bugs like these are hard to reproduce and can
13831  cause a lot of trouble.
13832  
13833 \end_layout
13834
13835 \begin_layout Subsubsection
13836 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
13837
13838 \end_inset
13839
13840 Common interrupt pitfall: 
13841 \emph on
13842 stack overflow
13843 \end_layout
13844
13845 \begin_layout Standard
13846 The return address and the registers used in the interrupt service routine
13847  are saved on the stack
13848 \begin_inset LatexCommand \index{stack}
13849
13850 \end_inset
13851
13852  so there must be sufficient stack space.
13853  If there isn't variables or registers (or even the return address itself)
13854  will be corrupted.
13855  This 
13856 \emph on
13857 stack overflow
13858 \emph default
13859
13860 \begin_inset LatexCommand \index{stack overflow}
13861
13862 \end_inset
13863
13864  is most likely to happen if the interrupt occurs during the 
13865 \begin_inset Quotes sld
13866 \end_inset
13867
13868 deepest
13869 \begin_inset Quotes srd
13870 \end_inset
13871
13872  subroutine when the stack is already in use for f.e.
13873  many return addresses.
13874 \end_layout
13875
13876 \begin_layout Subsubsection
13877 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
13878
13879 \end_inset
13880
13881 Common interrupt pitfall: 
13882 \emph on
13883 use of non-reentrant functions
13884 \end_layout
13885
13886 \begin_layout Standard
13887 A special note here, int (16 bit) and long (32 bit) integer division
13888 \begin_inset LatexCommand \index{Division}
13889
13890 \end_inset
13891
13892 , multiplication
13893 \begin_inset LatexCommand \index{Multiplication}
13894
13895 \end_inset
13896
13897  & modulus
13898 \begin_inset LatexCommand \index{Modulus}
13899
13900 \end_inset
13901
13902  and floating-point
13903 \begin_inset LatexCommand \index{Floating point support}
13904
13905 \end_inset
13906
13907  operations are implemented using external support routines.
13908  If an interrupt service routine needs to do any of these operations then
13909  the support routines (as mentioned in a following section) will have to
13910  be recompiled using the
13911 \emph on
13912  -
13913 \begin_inset ERT
13914 status collapsed
13915
13916 \begin_layout Standard
13917
13918
13919 \backslash
13920 /
13921 \end_layout
13922
13923 \end_inset
13924
13925 -stack-auto
13926 \begin_inset LatexCommand \index{-\/-stack-auto}
13927
13928 \end_inset
13929
13930
13931 \emph default
13932  option and the source file will need to be compiled using the 
13933 \emph on
13934 -
13935 \begin_inset ERT
13936 status collapsed
13937
13938 \begin_layout Standard
13939
13940
13941 \backslash
13942 /
13943 \end_layout
13944
13945 \end_inset
13946
13947 -int-long-reent
13948 \emph default
13949
13950 \begin_inset LatexCommand \index{-\/-int-long-reent}
13951
13952 \end_inset
13953
13954  compiler option.
13955  
13956 \newline
13957 Note, the type promotion
13958 \begin_inset LatexCommand \index{type promotion}
13959
13960 \end_inset
13961
13962  required by ANSI C can cause 16 bit routines to be used
13963 \begin_inset Marginal
13964 status collapsed
13965
13966 \begin_layout Standard
13967
13968 \series bold
13969 \InsetSpace ~
13970 !
13971 \end_layout
13972
13973 \end_inset
13974
13975  without the programmer being aware of it.
13976  See f.e.
13977  the cast 
13978 \family typewriter
13979 (unsigned char)(tail-1)
13980 \family default
13981  within the if clause in section 
13982 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13983
13984 \end_inset
13985
13986 .
13987 \end_layout
13988
13989 \begin_layout Standard
13990 Calling other functions from an interrupt service routine is not recommended,
13991  avoid it if possible.
13992  Note that when some function is called from an interrupt service routine
13993  it should be preceded by a #pragma\InsetSpace ~
13994 nooverlay
13995 \begin_inset LatexCommand \index{\#pragma nooverlay}
13996
13997 \end_inset
13998
13999  if it is not reentrant.
14000  Furthermore nonreentrant functions should not be called from the main program
14001  while the interrupt service routine might be active.
14002  They also must not be called from low priority interrupt service routines
14003  while a high priority interrupt service routine might be active.
14004  You could use semaphores or make the function
14005 \emph on
14006  critical
14007 \emph default
14008  if all parameters are passed in registers.
14009 \newline
14010  Also see section 
14011 \begin_inset LatexCommand \ref{sub:Overlaying}
14012
14013 \end_inset
14014
14015 \InsetSpace ~
14016 about Overlaying and section 
14017 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
14018
14019 \end_inset
14020
14021 \InsetSpace ~
14022 about Functions using private register banks.
14023 \begin_inset VSpace bigskip
14024 \end_inset
14025
14026
14027 \end_layout
14028
14029 \begin_layout Subsection
14030 MCS51/DS390 Interrupt Service Routines
14031 \end_layout
14032
14033 \begin_layout Standard
14034 Interrupt
14035 \begin_inset LatexCommand \index{interrupt}
14036
14037 \end_inset
14038
14039  numbers and the corresponding address & descriptions for the Standard 8051/8052
14040  are listed below.
14041  SDCC will automatically adjust the 
14042 \begin_inset LatexCommand \index{interrupt vector table}
14043
14044 \end_inset
14045
14046  to the maximum interrupt number specified.
14047 \newline
14048
14049 \end_layout
14050
14051 \begin_layout Standard
14052 \align center
14053 \begin_inset Tabular
14054 <lyxtabular version="3" rows="9" columns="3">
14055 <features>
14056 <column alignment="center" valignment="top" leftline="true" width="0in">
14057 <column alignment="left" valignment="top" leftline="true" width="0in">
14058 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
14059 <row topline="true" bottomline="true">
14060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14061 \begin_inset Text
14062
14063 \begin_layout Standard
14064 Interrupt #
14065 \end_layout
14066
14067 \end_inset
14068 </cell>
14069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14070 \begin_inset Text
14071
14072 \begin_layout Standard
14073 Description
14074 \end_layout
14075
14076 \end_inset
14077 </cell>
14078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14079 \begin_inset Text
14080
14081 \begin_layout Standard
14082 Vector Address
14083 \end_layout
14084
14085 \end_inset
14086 </cell>
14087 </row>
14088 <row topline="true">
14089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14090 \begin_inset Text
14091
14092 \begin_layout Standard
14093 0
14094 \end_layout
14095
14096 \end_inset
14097 </cell>
14098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14099 \begin_inset Text
14100
14101 \begin_layout Standard
14102 External 0
14103 \end_layout
14104
14105 \end_inset
14106 </cell>
14107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14108 \begin_inset Text
14109
14110 \begin_layout Standard
14111 0x0003
14112 \end_layout
14113
14114 \end_inset
14115 </cell>
14116 </row>
14117 <row topline="true">
14118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14119 \begin_inset Text
14120
14121 \begin_layout Standard
14122 1
14123 \end_layout
14124
14125 \end_inset
14126 </cell>
14127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14128 \begin_inset Text
14129
14130 \begin_layout Standard
14131 Timer 0
14132 \end_layout
14133
14134 \end_inset
14135 </cell>
14136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14137 \begin_inset Text
14138
14139 \begin_layout Standard
14140 0x000b
14141 \end_layout
14142
14143 \end_inset
14144 </cell>
14145 </row>
14146 <row topline="true">
14147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14148 \begin_inset Text
14149
14150 \begin_layout Standard
14151 2
14152 \end_layout
14153
14154 \end_inset
14155 </cell>
14156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14157 \begin_inset Text
14158
14159 \begin_layout Standard
14160 External 1
14161 \end_layout
14162
14163 \end_inset
14164 </cell>
14165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14166 \begin_inset Text
14167
14168 \begin_layout Standard
14169 0x0013
14170 \end_layout
14171
14172 \end_inset
14173 </cell>
14174 </row>
14175 <row topline="true">
14176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14177 \begin_inset Text
14178
14179 \begin_layout Standard
14180 3
14181 \end_layout
14182
14183 \end_inset
14184 </cell>
14185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14186 \begin_inset Text
14187
14188 \begin_layout Standard
14189 Timer 1
14190 \end_layout
14191
14192 \end_inset
14193 </cell>
14194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14195 \begin_inset Text
14196
14197 \begin_layout Standard
14198 0x001b
14199 \end_layout
14200
14201 \end_inset
14202 </cell>
14203 </row>
14204 <row topline="true">
14205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14206 \begin_inset Text
14207
14208 \begin_layout Standard
14209 4
14210 \end_layout
14211
14212 \end_inset
14213 </cell>
14214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14215 \begin_inset Text
14216
14217 \begin_layout Standard
14218 Serial
14219 \end_layout
14220
14221 \end_inset
14222 </cell>
14223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14224 \begin_inset Text
14225
14226 \begin_layout Standard
14227 0x0023
14228 \end_layout
14229
14230 \end_inset
14231 </cell>
14232 </row>
14233 <row topline="true">
14234 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14235 \begin_inset Text
14236
14237 \begin_layout Standard
14238 5
14239 \end_layout
14240
14241 \end_inset
14242 </cell>
14243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14244 \begin_inset Text
14245
14246 \begin_layout Standard
14247 Timer 2 (8052)
14248 \end_layout
14249
14250 \end_inset
14251 </cell>
14252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14253 \begin_inset Text
14254
14255 \begin_layout Standard
14256 0x002b
14257 \end_layout
14258
14259 \end_inset
14260 </cell>
14261 </row>
14262 <row topline="true">
14263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14264 \begin_inset Text
14265
14266 \begin_layout Standard
14267 ...
14268 \end_layout
14269
14270 \end_inset
14271 </cell>
14272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14273 \begin_inset Text
14274
14275 \begin_layout Standard
14276
14277 \end_layout
14278
14279 \end_inset
14280 </cell>
14281 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14282 \begin_inset Text
14283
14284 \begin_layout Standard
14285 ...
14286 \end_layout
14287
14288 \end_inset
14289 </cell>
14290 </row>
14291 <row topline="true" bottomline="true">
14292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14293 \begin_inset Text
14294
14295 \begin_layout Standard
14296 n
14297 \end_layout
14298
14299 \end_inset
14300 </cell>
14301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14302 \begin_inset Text
14303
14304 \begin_layout Standard
14305
14306 \end_layout
14307
14308 \end_inset
14309 </cell>
14310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14311 \begin_inset Text
14312
14313 \begin_layout Standard
14314 0x0003 + 8*n
14315 \end_layout
14316
14317 \end_inset
14318 </cell>
14319 </row>
14320 </lyxtabular>
14321
14322 \end_inset
14323
14324
14325 \newline
14326
14327 \end_layout
14328
14329 \begin_layout Standard
14330 If the interrupt service routine is defined without 
14331 \emph on
14332 using
14333 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14334
14335 \end_inset
14336
14337
14338 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14339
14340 \end_inset
14341
14342
14343 \emph default
14344  a register bank or with register bank 0 (
14345 \emph on
14346 using
14347 \emph default
14348  0), the compiler will save the registers used by itself on the stack upon
14349  entry and restore them at exit, however if such an interrupt service routine
14350  calls another function then the entire register bank will be saved on the
14351  stack.
14352  This scheme may be advantageous for small interrupt service routines which
14353  have low register usage.
14354 \end_layout
14355
14356 \begin_layout Standard
14357 If the interrupt service routine is defined to be using a specific register
14358  bank then only 
14359 \emph on
14360 a, b, dptr
14361 \emph default
14362  & psw are saved and restored, if such an interrupt service routine calls
14363  another function (using another register bank) then the entire register
14364  bank of the called function will be saved on the stack
14365 \begin_inset LatexCommand \index{stack}
14366
14367 \end_inset
14368
14369 .
14370  This scheme is recommended for larger interrupt service routines.
14371 \begin_inset VSpace bigskip
14372 \end_inset
14373
14374
14375 \end_layout
14376
14377 \begin_layout Subsection
14378 HC08
14379 \begin_inset LatexCommand \index{HC08}
14380
14381 \end_inset
14382
14383  Interrupt Service Routines
14384 \end_layout
14385
14386 \begin_layout Standard
14387 Since the number of interrupts
14388 \begin_inset LatexCommand \index{HC08!interrupt}
14389
14390 \end_inset
14391
14392  available is chip specific and the interrupt vector table always ends at
14393  the last byte of memory, the interrupt numbers corresponds to the interrupt
14394  vectors in reverse order of address.
14395  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14396  2 will use the interrupt vector at 0xfffa, and so on.
14397  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14398  this way; instead see section 
14399 \begin_inset LatexCommand \ref{sub:Startup-Code}
14400
14401 \end_inset
14402
14403  for details on customizing startup.
14404 \begin_inset VSpace bigskip
14405 \end_inset
14406
14407
14408 \end_layout
14409
14410 \begin_layout Subsection
14411 Z80 Interrupt Service Routines
14412 \end_layout
14413
14414 \begin_layout Standard
14415 The Z80
14416 \begin_inset LatexCommand \index{Z80}
14417
14418 \end_inset
14419
14420  uses several different methods for determining the correct interrupt
14421 \begin_inset LatexCommand \index{Z80!interrupt}
14422
14423 \end_inset
14424
14425  vector depending on the hardware implementation.
14426  Therefore, SDCC ignores the optional interrupt number and does not attempt
14427  to generate an interrupt vector table.
14428 \end_layout
14429
14430 \begin_layout Standard
14431 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14432  instruction to return from the interrupt.
14433  To write an interrupt handler for the non-maskable interrupt, which needs
14434  a RETN instruction instead, add the 
14435 \emph on
14436 critical
14437 \emph default
14438  keyword:
14439 \end_layout
14440
14441 \begin_layout Verse
14442
14443 \family typewriter
14444 void nmi_isr (void) critical interrupt
14445 \newline
14446
14447 \newline
14448 \InsetSpace ~
14449 \InsetSpace ~
14450 \InsetSpace ~
14451 \InsetSpace ~
14452 ...
14453  
14454 \newline
14455 }
14456 \end_layout
14457
14458 \begin_layout Standard
14459 However if you need to create a non-interruptable interrupt service routine
14460  you would also require the 
14461 \emph on
14462 critical
14463 \emph default
14464  keyword.
14465  To distinguish between this and an nmi_isr you must provide an interrupt
14466  number.
14467 \begin_inset VSpace bigskip
14468 \end_inset
14469
14470
14471 \end_layout
14472
14473 \begin_layout Section
14474 Enabling and Disabling Interrupts
14475 \end_layout
14476
14477 \begin_layout Subsection
14478 Critical Functions and Critical Statements
14479 \end_layout
14480
14481 \begin_layout Standard
14482 A special keyword may be associated with a block or a function declaring
14483  it as 
14484 \emph on
14485 critical
14486 \emph default
14487 .
14488  SDCC will generate code to disable all interrupts
14489 \begin_inset LatexCommand \index{interrupt}
14490
14491 \end_inset
14492
14493  upon entry to a critical function and restore the interrupt enable to the
14494  previous state before returning.
14495  Nesting critical functions will need one additional byte on the stack
14496 \begin_inset LatexCommand \index{stack}
14497
14498 \end_inset
14499
14500  for each call.
14501 \end_layout
14502
14503 \begin_layout Verse
14504
14505 \family typewriter
14506 int foo () __critical
14507 \begin_inset LatexCommand \index{critical}
14508
14509 \end_inset
14510
14511
14512 \begin_inset LatexCommand \index{\_\_critical}
14513
14514 \end_inset
14515
14516  
14517 \newline
14518
14519 \newline
14520 \InsetSpace ~
14521 \InsetSpace ~
14522 \InsetSpace ~
14523 \InsetSpace ~
14524 ...
14525  
14526 \newline
14527 \InsetSpace ~
14528 \InsetSpace ~
14529 \InsetSpace ~
14530 \InsetSpace ~
14531 ...
14532  
14533 \newline
14534 }
14535 \end_layout
14536
14537 \begin_layout Standard
14538 The critical attribute maybe used with other attributes like 
14539 \emph on
14540 reentrant.
14541 \emph default
14542
14543 \newline
14544 The keyword 
14545 \emph on
14546 critical
14547 \emph default
14548  may also be used to disable interrupts more locally:
14549 \end_layout
14550
14551 \begin_layout Verse
14552
14553 \family typewriter
14554 __critical{ i++; }
14555 \end_layout
14556
14557 \begin_layout Standard
14558 More than one statement could have been included in the block.
14559 \end_layout
14560
14561 \begin_layout Subsection
14562 Enabling and Disabling Interrupts directly
14563 \end_layout
14564
14565 \begin_layout Standard
14566 Interrupts
14567 \begin_inset LatexCommand \index{interrupt}
14568
14569 \end_inset
14570
14571  can also be disabled and enabled directly (8051):
14572 \end_layout
14573
14574 \begin_layout Verse
14575
14576 \family typewriter
14577 EA = 0;\InsetSpace ~
14578 \InsetSpace ~
14579 \InsetSpace ~
14580 \InsetSpace ~
14581 \InsetSpace ~
14582 \InsetSpace ~
14583 \InsetSpace ~
14584 \InsetSpace ~
14585 \InsetSpace ~
14586 \InsetSpace ~
14587 \InsetSpace ~
14588 \InsetSpace ~
14589 or:\InsetSpace ~
14590 \InsetSpace ~
14591 \InsetSpace ~
14592 \InsetSpace ~
14593 \InsetSpace ~
14594 \InsetSpace ~
14595 \InsetSpace ~
14596 \InsetSpace ~
14597 \InsetSpace ~
14598 \InsetSpace ~
14599 \InsetSpace ~
14600 EA_SAVE = EA;
14601 \end_layout
14602
14603 \begin_layout Verse
14604
14605 \family typewriter
14606 ...\InsetSpace ~
14607 \InsetSpace ~
14608 \InsetSpace ~
14609 \InsetSpace ~
14610 \InsetSpace ~
14611 \InsetSpace ~
14612 \InsetSpace ~
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 EA = 0;
14637 \end_layout
14638
14639 \begin_layout Verse
14640
14641 \family typewriter
14642 EA = 1;\InsetSpace ~
14643 \InsetSpace ~
14644 \InsetSpace ~
14645 \InsetSpace ~
14646 \InsetSpace ~
14647 \InsetSpace ~
14648 \InsetSpace ~
14649 \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 ...
14669 \end_layout
14670
14671 \begin_layout Verse
14672
14673 \family typewriter
14674 \InsetSpace ~
14675 \InsetSpace ~
14676 \InsetSpace ~
14677 \InsetSpace ~
14678 \InsetSpace ~
14679 \InsetSpace ~
14680 \InsetSpace ~
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 EA = EA_SAVE;
14708 \end_layout
14709
14710 \begin_layout Standard
14711 On other architectures which have seperate opcodes for enabling and disabling
14712  interrupts you might want to make use of defines with inline assembly
14713 \begin_inset LatexCommand \index{Assembler routines}
14714
14715 \end_inset
14716
14717  (HC08
14718 \begin_inset LatexCommand \index{HC08!interrupt}
14719
14720 \end_inset
14721
14722 ):
14723 \end_layout
14724
14725 \begin_layout Verse
14726
14727 \family typewriter
14728 #define CLI _asm
14729 \begin_inset LatexCommand \index{\_asm}
14730
14731 \end_inset
14732
14733 \InsetSpace ~
14734 \InsetSpace ~
14735 cli\InsetSpace ~
14736 \InsetSpace ~
14737 _endasm
14738 \begin_inset LatexCommand \index{\_endasm}
14739
14740 \end_inset
14741
14742
14743 \end_layout
14744
14745 \begin_layout Verse
14746
14747 \family typewriter
14748 #define SEI _asm\InsetSpace ~
14749 \InsetSpace ~
14750 sei\InsetSpace ~
14751 \InsetSpace ~
14752 _endasm; 
14753 \end_layout
14754
14755 \begin_layout Verse
14756
14757 \family typewriter
14758 ...
14759 \end_layout
14760
14761 \begin_layout Standard
14762 Note: it is sometimes sufficient to disable only a specific interrupt source
14763  like f.e.
14764  a timer or serial interrupt by manipulating an 
14765 \emph on
14766 interrupt mask
14767 \begin_inset LatexCommand \index{interrupt mask}
14768
14769 \end_inset
14770
14771
14772 \emph default
14773  register.
14774  
14775 \end_layout
14776
14777 \begin_layout Standard
14778 Usually the time during which interrupts are disabled should be kept as
14779  short as possible.
14780  This minimizes both 
14781 \emph on
14782 interrupt latency
14783 \emph default
14784
14785 \begin_inset LatexCommand \index{interrupt latency}
14786
14787 \end_inset
14788
14789  (the time between the occurrence of the interrupt and the execution of
14790  the first code in the interrupt routine) and 
14791 \emph on
14792 interrupt jitter
14793 \emph default
14794
14795 \begin_inset LatexCommand \index{interrupt jitter}
14796
14797 \end_inset
14798
14799  (the difference between the shortest and the longest interrupt latency).
14800  These really are something different, f.e.
14801  a serial interrupt has to be served before its buffer overruns so it cares
14802  for the maximum interrupt latency, whereas it does not care about jitter.
14803  On a loudspeaker driven via a digital to analog converter which is fed
14804  by an interrupt a latency of a few milliseconds might be tolerable, whereas
14805  a much smaller jitter will be very audible.
14806 \end_layout
14807
14808 \begin_layout Standard
14809 You can reenable interrupts within an interrupt routine and on some architecture
14810 s you can make use of two (or more) levels of 
14811 \emph on
14812 interrupt priorities
14813 \emph default
14814
14815 \begin_inset LatexCommand \index{interrupt priority}
14816
14817 \end_inset
14818
14819 .
14820  On some architectures which don't support interrupt priorities these can
14821  be implemented by manipulating the interrupt mask and reenabling interrupts
14822  within the interrupt routine.
14823  Check there is sufficient space on the stack
14824 \begin_inset LatexCommand \index{stack}
14825
14826 \end_inset
14827
14828  and don't add complexity unless you have to.
14829  
14830 \end_layout
14831
14832 \begin_layout Subsection
14833 Semaphore
14834 \begin_inset LatexCommand \index{semaphore}
14835
14836 \end_inset
14837
14838  locking (mcs51/ds390)
14839 \end_layout
14840
14841 \begin_layout Standard
14842 Some architectures (mcs51/ds390) have an atomic
14843 \begin_inset LatexCommand \index{atomic}
14844
14845 \end_inset
14846
14847  bit test and
14848 \emph on
14849  
14850 \emph default
14851 clear
14852 \emph on
14853  
14854 \emph default
14855 instruction.
14856  These type of instructions are typically used in preemptive multitasking
14857  systems, where a routine f.e.
14858  claims the use of a data structure ('acquires a lock
14859 \begin_inset LatexCommand \index{lock}
14860
14861 \end_inset
14862
14863  on it'), makes some modifications and then releases the lock when the data
14864  structure is consistent again.
14865  The instruction may also be used if interrupt and non-interrupt code have
14866  to compete for a resource.
14867  With the atomic bit test and clear instruction interrupts
14868 \begin_inset LatexCommand \index{interrupt}
14869
14870 \end_inset
14871
14872  don't have to be disabled for the locking operation.
14873  
14874 \end_layout
14875
14876 \begin_layout Standard
14877 SDCC generates this instruction if the source follows this pattern:
14878 \end_layout
14879
14880 \begin_layout Verse
14881
14882 \family typewriter
14883 volatile
14884 \begin_inset LatexCommand \index{volatile}
14885
14886 \end_inset
14887
14888  bit resource_is_free; 
14889 \newline
14890
14891 \newline
14892 if (resource_is_free) 
14893 \newline
14894 \InsetSpace ~
14895 \InsetSpace ~
14896
14897 \newline
14898 \InsetSpace ~
14899 \InsetSpace ~
14900 \InsetSpace ~
14901 \InsetSpace ~
14902 resource_is_free=0; 
14903 \newline
14904 \InsetSpace ~
14905 \InsetSpace ~
14906 \InsetSpace ~
14907 \InsetSpace ~
14908 ...
14909  
14910 \newline
14911 \InsetSpace ~
14912 \InsetSpace ~
14913 \InsetSpace ~
14914 \InsetSpace ~
14915 resource_is_free=1;
14916 \newline
14917 \InsetSpace ~
14918 \InsetSpace ~
14919
14920 \end_layout
14921
14922 \begin_layout Standard
14923 Note, mcs51 and ds390 support only an atomic
14924 \begin_inset LatexCommand \index{atomic}
14925
14926 \end_inset
14927
14928  bit test and 
14929 \emph on
14930 clear
14931 \emph default
14932  instruction (as opposed to atomic bit test and 
14933 \emph on
14934 set).
14935 \end_layout
14936
14937 \begin_layout Section
14938 Functions using private register banks
14939 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
14940
14941 \end_inset
14942
14943  (mcs51/ds390)
14944 \end_layout
14945
14946 \begin_layout Standard
14947 Some architectures have support for quickly changing register sets.
14948  SDCC supports this feature with the 
14949 \emph on
14950 using
14951 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14952
14953 \end_inset
14954
14955
14956 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14957
14958 \end_inset
14959
14960
14961 \emph default
14962  attribute (which tells the compiler to use a register bank
14963 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
14964
14965 \end_inset
14966
14967  other than the default bank zero).
14968  It should only be applied to 
14969 \emph on
14970 interrupt
14971 \begin_inset LatexCommand \index{interrupt}
14972
14973 \end_inset
14974
14975
14976 \emph default
14977  functions (see footnote below).
14978  This will in most circumstances make the generated ISR code more efficient
14979  since it will not have to save registers on the stack.
14980 \end_layout
14981
14982 \begin_layout Standard
14983 The 
14984 \emph on
14985 using
14986 \emph default
14987  attribute will have no effect on the generated code for a 
14988 \emph on
14989 non-interrupt
14990 \emph default
14991  function (but may occasionally be useful anyway
14992 \begin_inset Foot
14993 status open
14994
14995 \begin_layout Standard
14996 possible exception: if a function is called ONLY from 'interrupt' functions
14997  using a particular bank, it can be declared with the same 'using' attribute
14998  as the calling 'interrupt' functions.
14999  For instance, if you have several ISRs using bank one, and all of them
15000  call memcpy(), it might make sense to create a specialized version of memcpy()
15001  'using 1', since this would prevent the ISR from having to save bank zero
15002  to the stack on entry and switch to bank zero before calling the function
15003 \end_layout
15004
15005 \end_inset
15006
15007 ).
15008 \newline
15009
15010 \emph on
15011 (pending: Note, nowadays the 
15012 \emph default
15013 using
15014 \emph on
15015  attribute has an effect on
15016 \emph default
15017  
15018 \emph on
15019 the generated code for a 
15020 \emph default
15021 non-interrupt
15022 \emph on
15023  function
15024 \emph default
15025 .
15026 \emph on
15027 )
15028 \end_layout
15029
15030 \begin_layout Standard
15031 An 
15032 \emph on
15033 interrupt
15034 \emph default
15035  function using a non-zero bank will assume that it can trash that register
15036  bank, and will not save it.
15037  Since high-priority interrupts
15038 \begin_inset LatexCommand \index{interrupts}
15039
15040 \end_inset
15041
15042
15043 \begin_inset LatexCommand \index{interrupt priority}
15044
15045 \end_inset
15046
15047  can interrupt low-priority ones on the 8051 and friends, this means that
15048  if a high-priority ISR 
15049 \emph on
15050 using
15051 \emph default
15052  a particular bank occurs while processing a low-priority ISR 
15053 \emph on
15054 using
15055 \emph default
15056  the same bank, terrible and bad things can happen.
15057  To prevent this, no single register bank should be 
15058 \emph on
15059 used
15060 \emph default
15061  by both a high priority and a low priority ISR.
15062  This is probably most easily done by having all high priority ISRs use
15063  one bank and all low priority ISRs use another.
15064  If you have an ISR which can change priority at runtime, you're on your
15065  own: I suggest using the default bank zero and taking the small performance
15066  hit.
15067 \end_layout
15068
15069 \begin_layout Standard
15070 It is most efficient if your ISR calls no other functions.
15071  If your ISR must call other functions, it is most efficient if those functions
15072  use the same bank as the ISR (see note 1 below); the next best is if the
15073  called functions use bank zero.
15074  It is very inefficient to call a function using a different, non-zero bank
15075  from an ISR.
15076  
15077 \begin_inset VSpace bigskip
15078 \end_inset
15079
15080
15081 \end_layout
15082
15083 \begin_layout Section
15084 Startup Code
15085 \begin_inset LatexCommand \label{sub:Startup-Code}
15086
15087 \end_inset
15088
15089
15090 \begin_inset LatexCommand \index{Startup code}
15091
15092 \end_inset
15093
15094
15095 \end_layout
15096
15097 \begin_layout Subsection
15098 MCS51/DS390 Startup Code
15099 \end_layout
15100
15101 \begin_layout Standard
15102 The compiler triggers the linker to link certain initialization modules
15103  from the runtime library
15104 \begin_inset LatexCommand \index{Runtime library}
15105
15106 \end_inset
15107
15108  called crt<something>.
15109  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
15110  GSINIT5) is not linked unless the --xstack option is used.
15111  These modules are highly entangled by the use of special segments/areas,
15112  but a common layout is shown below:
15113 \end_layout
15114
15115 \begin_layout Verse
15116
15117 \family typewriter
15118 \series bold
15119 \size footnotesize
15120 (main.asm)
15121 \end_layout
15122
15123 \begin_layout Verse
15124
15125 \family typewriter
15126 \size footnotesize
15127 \InsetSpace ~
15128 \InsetSpace ~
15129 \InsetSpace ~
15130 \InsetSpace ~
15131 \InsetSpace ~
15132 \InsetSpace ~
15133 \InsetSpace ~
15134 \InsetSpace ~
15135 .area HOME (CODE)
15136 \newline
15137 __interrupt_vect:
15138 \newline
15139 \InsetSpace ~
15140 \InsetSpace ~
15141 \InsetSpace ~
15142 \InsetSpace ~
15143 \InsetSpace ~
15144 \InsetSpace ~
15145 \InsetSpace ~
15146 \InsetSpace ~
15147 ljmp __sdcc_gsinit_startup
15148 \end_layout
15149
15150 \begin_layout Verse
15151
15152 \family typewriter
15153 \series bold
15154 \size footnotesize
15155 (crtstart.asm)
15156 \end_layout
15157
15158 \begin_layout Verse
15159
15160 \family typewriter
15161 \size footnotesize
15162 \InsetSpace ~
15163 \InsetSpace ~
15164 \InsetSpace ~
15165 \InsetSpace ~
15166 \InsetSpace ~
15167 \InsetSpace ~
15168 \InsetSpace ~
15169 \InsetSpace ~
15170 .area GSINIT0 (CODE)
15171 \newline
15172 __sdcc_gsinit_startup::
15173 \newline
15174 \InsetSpace ~
15175 \InsetSpace ~
15176 \InsetSpace ~
15177 \InsetSpace ~
15178 \InsetSpace ~
15179 \InsetSpace ~
15180 \InsetSpace ~
15181 \InsetSpace ~
15182 mov sp,#__start__stack - 1
15183 \end_layout
15184
15185 \begin_layout Verse
15186
15187 \family typewriter
15188 \series bold
15189 \size footnotesize
15190 (crtxstack.asm)
15191 \end_layout
15192
15193 \begin_layout Verse
15194
15195 \family typewriter
15196 \size footnotesize
15197 \InsetSpace ~
15198 \InsetSpace ~
15199 \InsetSpace ~
15200 \InsetSpace ~
15201 \InsetSpace ~
15202 \InsetSpace ~
15203 \InsetSpace ~
15204 \InsetSpace ~
15205 .area GSINIT1 (CODE)
15206 \newline
15207 __sdcc_init_xstack::
15208 \newline
15209 ; Need to initialize in GSINIT1 in
15210  case the user's __sdcc_external_startup uses the xstack.
15211 \newline
15212 \InsetSpace ~
15213 \InsetSpace ~
15214 \InsetSpace ~
15215 \InsetSpace ~
15216 \InsetSpace ~
15217 \InsetSpace ~
15218 \InsetSpace ~
15219 \InsetSpace ~
15220 mov __XPAGE,#(__start__x
15221 stack >> 8)
15222 \newline
15223 \InsetSpace ~
15224 \InsetSpace ~
15225 \InsetSpace ~
15226 \InsetSpace ~
15227 \InsetSpace ~
15228 \InsetSpace ~
15229 \InsetSpace ~
15230 \InsetSpace ~
15231 mov _spx,#__start__xstack
15232 \end_layout
15233
15234 \begin_layout Verse
15235
15236 \family typewriter
15237 \series bold
15238 \size footnotesize
15239 (crtstart.asm)
15240 \end_layout
15241
15242 \begin_layout Verse
15243
15244 \family typewriter
15245 \size footnotesize
15246 \InsetSpace ~
15247 \InsetSpace ~
15248 \InsetSpace ~
15249 \InsetSpace ~
15250 \InsetSpace ~
15251 \InsetSpace ~
15252 \InsetSpace ~
15253 \InsetSpace ~
15254 .area GSINIT2 (CODE)
15255 \newline
15256 \InsetSpace ~
15257 \InsetSpace ~
15258 \InsetSpace ~
15259 \InsetSpace ~
15260 \InsetSpace ~
15261 \InsetSpace ~
15262 \InsetSpace ~
15263 \InsetSpace ~
15264 lcall __sdcc_external_startup
15265 \newline
15266 \InsetSpace ~
15267 \InsetSpace ~
15268 \InsetSpace ~
15269 \InsetSpace ~
15270 \InsetSpace ~
15271 \InsetSpace ~
15272 \InsetSpace ~
15273 \InsetSpace ~
15274 mov a,dpl
15275 \newline
15276 \InsetSpace ~
15277 \InsetSpace ~
15278 \InsetSpace ~
15279 \InsetSpace ~
15280 \InsetSpace ~
15281 \InsetSpace ~
15282 \InsetSpace ~
15283 \InsetSpace ~
15284 jz __sdcc_init_data
15285 \newline
15286 \InsetSpace ~
15287 \InsetSpace ~
15288 \InsetSpace ~
15289 \InsetSpace ~
15290 \InsetSpace ~
15291 \InsetSpace ~
15292 \InsetSpace ~
15293 \InsetSpace ~
15294 ljmp
15295  __sdcc_program_startup
15296 \newline
15297 __sdcc_init_data:
15298 \end_layout
15299
15300 \begin_layout Verse
15301
15302 \family typewriter
15303 \series bold
15304 \size footnotesize
15305 (crtxinit.asm)
15306 \end_layout
15307
15308 \begin_layout Verse
15309
15310 \family typewriter
15311 \size footnotesize
15312 \InsetSpace ~
15313 \InsetSpace ~
15314 \InsetSpace ~
15315 \InsetSpace ~
15316 \InsetSpace ~
15317 \InsetSpace ~
15318 \InsetSpace ~
15319 \InsetSpace ~
15320 .area GSINIT3 (CODE)
15321 \newline
15322 __mcs51_genXINIT::
15323 \newline
15324 \InsetSpace ~
15325 \InsetSpace ~
15326 \InsetSpace ~
15327 \InsetSpace ~
15328 \InsetSpace ~
15329 \InsetSpace ~
15330 \InsetSpace ~
15331 \InsetSpace ~
15332 mov r1,#l_XINIT
15333 \newline
15334 \InsetSpace ~
15335 \InsetSpace ~
15336 \InsetSpace ~
15337 \InsetSpace ~
15338 \InsetSpace ~
15339 \InsetSpace ~
15340 \InsetSpace ~
15341 \InsetSpace ~
15342 mov a,r1
15343 \newline
15344 \InsetSpace ~
15345 \InsetSpace ~
15346 \InsetSpace ~
15347 \InsetSpace ~
15348 \InsetSpace ~
15349 \InsetSpace ~
15350 \InsetSpace ~
15351 \InsetSpace ~
15352 orl a,#(l_XINIT
15353  >> 8)
15354 \newline
15355 \InsetSpace ~
15356 \InsetSpace ~
15357 \InsetSpace ~
15358 \InsetSpace ~
15359 \InsetSpace ~
15360 \InsetSpace ~
15361 \InsetSpace ~
15362 \InsetSpace ~
15363 jz 00003$
15364 \newline
15365 \InsetSpace ~
15366 \InsetSpace ~
15367 \InsetSpace ~
15368 \InsetSpace ~
15369 \InsetSpace ~
15370 \InsetSpace ~
15371 \InsetSpace ~
15372 \InsetSpace ~
15373 mov r2,#((l_XINIT+255) >> 8)
15374 \newline
15375 \InsetSpace ~
15376 \InsetSpace ~
15377 \InsetSpace ~
15378 \InsetSpace ~
15379 \InsetSpace ~
15380 \InsetSpace ~
15381 \InsetSpace ~
15382 \InsetSpace ~
15383 mov dptr,#s_XINIT
15384 \newline
15385 \InsetSpace ~
15386 \InsetSpace ~
15387 \InsetSpace ~
15388 \InsetSpace ~
15389 \InsetSpace ~
15390 \InsetSpace ~
15391 \InsetSpace ~
15392 \InsetSpace ~
15393 mov r0,#s_XISEG
15394 \newline
15395 \InsetSpace ~
15396 \InsetSpace ~
15397 \InsetSpace ~
15398 \InsetSpace ~
15399 \InsetSpace ~
15400 \InsetSpace ~
15401 \InsetSpace ~
15402 \InsetSpace ~
15403 mov
15404  __XPAGE,#(s_XISEG >> 8)
15405 \newline
15406 00001$:\InsetSpace ~
15407 clr a
15408 \newline
15409 \InsetSpace ~
15410 \InsetSpace ~
15411 \InsetSpace ~
15412 \InsetSpace ~
15413 \InsetSpace ~
15414 \InsetSpace ~
15415 \InsetSpace ~
15416 \InsetSpace ~
15417 movc a,@a+dptr
15418 \newline
15419 \InsetSpace ~
15420 \InsetSpace ~
15421 \InsetSpace ~
15422 \InsetSpace ~
15423 \InsetSpace ~
15424 \InsetSpace ~
15425 \InsetSpace ~
15426 \InsetSpace ~
15427 movx @r0,a
15428 \newline
15429 \InsetSpace ~
15430 \InsetSpace ~
15431 \InsetSpace ~
15432 \InsetSpace ~
15433 \InsetSpace ~
15434 \InsetSpace ~
15435 \InsetSpace ~
15436 \InsetSpace ~
15437 inc dptr
15438 \newline
15439 \InsetSpace ~
15440 \InsetSpace ~
15441 \InsetSpace ~
15442 \InsetSpace ~
15443 \InsetSpace ~
15444 \InsetSpace ~
15445 \InsetSpace ~
15446 \InsetSpace ~
15447 inc
15448  r0
15449 \newline
15450 \InsetSpace ~
15451 \InsetSpace ~
15452 \InsetSpace ~
15453 \InsetSpace ~
15454 \InsetSpace ~
15455 \InsetSpace ~
15456 \InsetSpace ~
15457 \InsetSpace ~
15458 cjne r0,#0,00002$
15459 \newline
15460 \InsetSpace ~
15461 \InsetSpace ~
15462 \InsetSpace ~
15463 \InsetSpace ~
15464 \InsetSpace ~
15465 \InsetSpace ~
15466 \InsetSpace ~
15467 \InsetSpace ~
15468 inc __XPAGE
15469 \newline
15470 00002$:\InsetSpace ~
15471 djnz r1,00001$
15472 \newline
15473 \InsetSpace ~
15474 \InsetSpace ~
15475 \InsetSpace ~
15476 \InsetSpace ~
15477 \InsetSpace ~
15478 \InsetSpace ~
15479 \InsetSpace ~
15480 \InsetSpace ~
15481 djnz r2,00001$
15482 \newline
15483 \InsetSpace ~
15484 \InsetSpace ~
15485 \InsetSpace ~
15486 \InsetSpace ~
15487 \InsetSpace ~
15488 \InsetSpace ~
15489 \InsetSpace ~
15490 \InsetSpace ~
15491 mov __XPAGE,#0
15492 xFF
15493 \newline
15494 00003$:
15495 \end_layout
15496
15497 \begin_layout Verse
15498
15499 \family typewriter
15500 \series bold
15501 \size footnotesize
15502 (crtclear.asm)
15503 \end_layout
15504
15505 \begin_layout Verse
15506
15507 \family typewriter
15508 \size footnotesize
15509 \InsetSpace ~
15510 \InsetSpace ~
15511 \InsetSpace ~
15512 \InsetSpace ~
15513 \InsetSpace ~
15514 \InsetSpace ~
15515 \InsetSpace ~
15516 \InsetSpace ~
15517 .area GSINIT4 (CODE)
15518 \newline
15519 __mcs51_genRAMCLEAR::
15520 \newline
15521 \InsetSpace ~
15522 \InsetSpace ~
15523 \InsetSpace ~
15524 \InsetSpace ~
15525 \InsetSpace ~
15526 \InsetSpace ~
15527 \InsetSpace ~
15528 \InsetSpace ~
15529 clr a
15530 \newline
15531 \InsetSpace ~
15532 \InsetSpace ~
15533 \InsetSpace ~
15534 \InsetSpace ~
15535 \InsetSpace ~
15536 \InsetSpace ~
15537 \InsetSpace ~
15538 \InsetSpace ~
15539 mov r0,#(l_IRAM-1)
15540 \newline
15541 00004$:\InsetSpace ~
15542 mov
15543  @r0,a
15544 \newline
15545 \InsetSpace ~
15546 \InsetSpace ~
15547 \InsetSpace ~
15548 \InsetSpace ~
15549 \InsetSpace ~
15550 \InsetSpace ~
15551 \InsetSpace ~
15552 \InsetSpace ~
15553 djnz r0,00004$
15554 \newline
15555 ; _mcs51_genRAMCLEAR() end
15556 \end_layout
15557
15558 \begin_layout Verse
15559
15560 \family typewriter
15561 \series bold
15562 \size footnotesize
15563 (crtxclear.asm)
15564 \end_layout
15565
15566 \begin_layout Verse
15567
15568 \family typewriter
15569 \size footnotesize
15570 \InsetSpace ~
15571 \InsetSpace ~
15572 \InsetSpace ~
15573 \InsetSpace ~
15574 \InsetSpace ~
15575 \InsetSpace ~
15576 \InsetSpace ~
15577 \InsetSpace ~
15578 .area GSINIT4 (CODE)
15579 \newline
15580 __mcs51_genXRAMCLEAR::
15581 \newline
15582 \InsetSpace ~
15583 \InsetSpace ~
15584 \InsetSpace ~
15585 \InsetSpace ~
15586 \InsetSpace ~
15587 \InsetSpace ~
15588 \InsetSpace ~
15589 \InsetSpace ~
15590 mov r0,#l_PSEG
15591 \newline
15592 \InsetSpace ~
15593 \InsetSpace ~
15594 \InsetSpace ~
15595 \InsetSpace ~
15596 \InsetSpace ~
15597 \InsetSpace ~
15598 \InsetSpace ~
15599 \InsetSpace ~
15600 mov a,r0
15601 \newline
15602 \InsetSpace ~
15603 \InsetSpace ~
15604 \InsetSpace ~
15605 \InsetSpace ~
15606 \InsetSpace ~
15607 \InsetSpace ~
15608 \InsetSpace ~
15609 \InsetSpace ~
15610 jz 00006$
15611 \newline
15612 \InsetSpace ~
15613 \InsetSpace ~
15614 \InsetSpace ~
15615 \InsetSpace ~
15616 \InsetSpace ~
15617 \InsetSpace ~
15618 \InsetSpace ~
15619 \InsetSpace ~
15620 mov
15621  r1,#s_PSEG
15622 \newline
15623 \InsetSpace ~
15624 \InsetSpace ~
15625 \InsetSpace ~
15626 \InsetSpace ~
15627 \InsetSpace ~
15628 \InsetSpace ~
15629 \InsetSpace ~
15630 \InsetSpace ~
15631 mov __XPAGE,#(s_PSEG >> 8)
15632 \newline
15633 \InsetSpace ~
15634 \InsetSpace ~
15635 \InsetSpace ~
15636 \InsetSpace ~
15637 \InsetSpace ~
15638 \InsetSpace ~
15639 \InsetSpace ~
15640 \InsetSpace ~
15641 clr a
15642 \newline
15643 00005$:\InsetSpace ~
15644 movx @r1,a
15645 \newline
15646 \InsetSpace ~
15647 \InsetSpace ~
15648 \InsetSpace ~
15649 \InsetSpace ~
15650 \InsetSpace ~
15651 \InsetSpace ~
15652 \InsetSpace ~
15653 \InsetSpace ~
15654 inc r1
15655 \newline
15656 \InsetSpace ~
15657 \InsetSpace ~
15658 \InsetSpace ~
15659 \InsetSpace ~
15660 \InsetSpace ~
15661 \InsetSpace ~
15662 \InsetSpace ~
15663 \InsetSpace ~
15664 djnz r0,00005$
15665 \newline
15666 0
15667 0006$:
15668 \newline
15669 \InsetSpace ~
15670 \InsetSpace ~
15671 \InsetSpace ~
15672 \InsetSpace ~
15673 \InsetSpace ~
15674 \InsetSpace ~
15675 \InsetSpace ~
15676 \InsetSpace ~
15677 mov r0,#l_XSEG
15678 \newline
15679 \InsetSpace ~
15680 \InsetSpace ~
15681 \InsetSpace ~
15682 \InsetSpace ~
15683 \InsetSpace ~
15684 \InsetSpace ~
15685 \InsetSpace ~
15686 \InsetSpace ~
15687 mov a,r0
15688 \newline
15689 \InsetSpace ~
15690 \InsetSpace ~
15691 \InsetSpace ~
15692 \InsetSpace ~
15693 \InsetSpace ~
15694 \InsetSpace ~
15695 \InsetSpace ~
15696 \InsetSpace ~
15697 orl a,#(l_XSEG >> 8)
15698 \newline
15699 \InsetSpace ~
15700 \InsetSpace ~
15701 \InsetSpace ~
15702 \InsetSpace ~
15703 \InsetSpace ~
15704 \InsetSpace ~
15705 \InsetSpace ~
15706 \InsetSpace ~
15707 jz 00008$
15708 \newline
15709 \InsetSpace ~
15710 \InsetSpace ~
15711 \InsetSpace ~
15712 \InsetSpace ~
15713 \InsetSpace ~
15714 \InsetSpace ~
15715 \InsetSpace ~
15716 \InsetSpace ~
15717 mov r1,#((l_XSEG
15718  + 255) >> 8)
15719 \newline
15720 \InsetSpace ~
15721 \InsetSpace ~
15722 \InsetSpace ~
15723 \InsetSpace ~
15724 \InsetSpace ~
15725 \InsetSpace ~
15726 \InsetSpace ~
15727 \InsetSpace ~
15728 mov dptr,#s_XSEG
15729 \newline
15730 \InsetSpace ~
15731 \InsetSpace ~
15732 \InsetSpace ~
15733 \InsetSpace ~
15734 \InsetSpace ~
15735 \InsetSpace ~
15736 \InsetSpace ~
15737 \InsetSpace ~
15738 clr a
15739 \newline
15740 00007$:\InsetSpace ~
15741 movx @dptr,a
15742 \newline
15743 \InsetSpace ~
15744 \InsetSpace ~
15745 \InsetSpace ~
15746 \InsetSpace ~
15747 \InsetSpace ~
15748 \InsetSpace ~
15749 \InsetSpace ~
15750 \InsetSpace ~
15751 inc dptr
15752 \newline
15753 \InsetSpace ~
15754 \InsetSpace ~
15755 \InsetSpace ~
15756 \InsetSpace ~
15757 \InsetSpace ~
15758 \InsetSpace ~
15759 \InsetSpace ~
15760 \InsetSpace ~
15761 djnz r0,00007$
15762 \newline
15763 \InsetSpace ~
15764 \InsetSpace ~
15765 \InsetSpace ~
15766 \InsetSpace ~
15767 \InsetSpace ~
15768 \InsetSpace ~
15769 \InsetSpace ~
15770 \InsetSpace ~
15771 djnz
15772  r1,00007$
15773 \newline
15774 00008$:
15775 \end_layout
15776
15777 \begin_layout Verse
15778
15779 \family typewriter
15780 \series bold
15781 \size footnotesize
15782 (crtxstack.asm)
15783 \end_layout
15784
15785 \begin_layout Verse
15786
15787 \family typewriter
15788 \size footnotesize
15789 \InsetSpace ~
15790 \InsetSpace ~
15791 \InsetSpace ~
15792 \InsetSpace ~
15793 \InsetSpace ~
15794 \InsetSpace ~
15795 \InsetSpace ~
15796 \InsetSpace ~
15797 .area GSINIT5 (CODE)
15798 \newline
15799 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
15800  modifies __XPAGE
15801 \newline
15802 ; and __mcs51_genRAMCLEAR modifies _spx.
15803 \newline
15804 \InsetSpace ~
15805 \InsetSpace ~
15806 \InsetSpace ~
15807 \InsetSpace ~
15808 \InsetSpace ~
15809 \InsetSpace ~
15810 \InsetSpace ~
15811 \InsetSpace ~
15812 mov __XPAGE,#(__start__x
15813 stack >> 8)
15814 \newline
15815 \InsetSpace ~
15816 \InsetSpace ~
15817 \InsetSpace ~
15818 \InsetSpace ~
15819 \InsetSpace ~
15820 \InsetSpace ~
15821 \InsetSpace ~
15822 \InsetSpace ~
15823 mov _spx,#__start__xstack
15824 \end_layout
15825
15826 \begin_layout Verse
15827
15828 \family typewriter
15829 \series bold
15830 \size footnotesize
15831 (application modules)
15832 \end_layout
15833
15834 \begin_layout Verse
15835
15836 \family typewriter
15837 \size footnotesize
15838 \InsetSpace ~
15839 \InsetSpace ~
15840 \InsetSpace ~
15841 \InsetSpace ~
15842 \InsetSpace ~
15843 \InsetSpace ~
15844 \InsetSpace ~
15845 \InsetSpace ~
15846 .area GSINIT (CODE)
15847 \end_layout
15848
15849 \begin_layout Verse
15850
15851 \family typewriter
15852 \series bold
15853 \size footnotesize
15854 (main.asm)
15855 \end_layout
15856
15857 \begin_layout Verse
15858
15859 \family typewriter
15860 \size footnotesize
15861 \InsetSpace ~
15862 \InsetSpace ~
15863 \InsetSpace ~
15864 \InsetSpace ~
15865 \InsetSpace ~
15866 \InsetSpace ~
15867 \InsetSpace ~
15868 \InsetSpace ~
15869 .area GSFINAL (CODE)
15870 \newline
15871 \InsetSpace ~
15872 \InsetSpace ~
15873 \InsetSpace ~
15874 \InsetSpace ~
15875 \InsetSpace ~
15876 \InsetSpace ~
15877 \InsetSpace ~
15878 \InsetSpace ~
15879 ljmp __sdcc_program_startup
15880 \newline
15881 ;---------------------------------
15882 -----------------------
15883 \newline
15884 ; Home
15885 \newline
15886 ;--------------------------------------------------
15887 ------
15888 \newline
15889 \InsetSpace ~
15890 \InsetSpace ~
15891 \InsetSpace ~
15892 \InsetSpace ~
15893 \InsetSpace ~
15894 \InsetSpace ~
15895 \InsetSpace ~
15896 \InsetSpace ~
15897 .area HOME (CODE)
15898 \newline
15899 \InsetSpace ~
15900 \InsetSpace ~
15901 \InsetSpace ~
15902 \InsetSpace ~
15903 \InsetSpace ~
15904 \InsetSpace ~
15905 \InsetSpace ~
15906 \InsetSpace ~
15907 .area CSEG (CODE)
15908 \newline
15909 __sdcc_program_startup:
15910 \newline
15911 \InsetSpace ~
15912 \InsetSpace ~
15913 \InsetSpace ~
15914 \InsetSpace ~
15915 \InsetSpace ~
15916 \InsetSpace ~
15917 \InsetSpace ~
15918 \InsetSpace ~
15919 lcall _main
15920 \newline
15921 ;
15922  return from main will lock up
15923 \newline
15924 \InsetSpace ~
15925 \InsetSpace ~
15926 \InsetSpace ~
15927 \InsetSpace ~
15928 \InsetSpace ~
15929 \InsetSpace ~
15930 \InsetSpace ~
15931 \InsetSpace ~
15932 sjmp .
15933 \end_layout
15934
15935 \begin_layout Standard
15936 One of these modules (crtstart.asm) contains a call to the C routine 
15937 \emph on
15938 _sdcc_external_startup()
15939 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
15940
15941 \end_inset
15942
15943
15944 \series bold
15945 \emph default
15946  
15947 \series default
15948 at the start of the CODE area.
15949  This routine is also in the runtime library
15950 \begin_inset LatexCommand \index{Runtime library}
15951
15952 \end_inset
15953
15954  and returns 0 by default.
15955  If this routine returns a non-zero value, the static & global variable
15956  initialization will be skipped and the function main will be invoked.
15957  Otherwise static & global variables will be initialized before the function
15958  main is invoked.
15959  You could add an 
15960 \emph on
15961 _sdcc_external_startup()
15962 \emph default
15963  routine to your program to override the default if you need to setup hardware
15964  or perform some other critical operation prior to static & global variable
15965  initialization
15966 \begin_inset LatexCommand \index{Variable initialization}
15967
15968 \end_inset
15969
15970 .
15971  On some mcs51 variants xdata
15972 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
15973
15974 \end_inset
15975
15976  memory has to be explicitly enabled before it can be accessed or if the
15977  watchdog
15978 \begin_inset LatexCommand \index{watchdog}
15979
15980 \end_inset
15981
15982  needs to be disabled, this is the place to do it.
15983  The startup code clears all internal data memory, 256 bytes by default,
15984  but from 0 to n-1 if 
15985 \emph on
15986 -
15987 \begin_inset ERT
15988 status collapsed
15989
15990 \begin_layout Standard
15991
15992
15993 \backslash
15994 /
15995 \end_layout
15996
15997 \end_inset
15998
15999 -iram-size
16000 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
16001
16002 \end_inset
16003
16004 n
16005 \emph default
16006  is used.
16007  (recommended for Chipcon CC1010).
16008 \end_layout
16009
16010 \begin_layout Standard
16011 See also the compiler options 
16012 \emph on
16013 -
16014 \begin_inset ERT
16015 status collapsed
16016
16017 \begin_layout Standard
16018
16019
16020 \backslash
16021 /
16022 \end_layout
16023
16024 \end_inset
16025
16026 -no-xinit
16027 \emph default
16028 -
16029 \emph on
16030 opt
16031 \emph default
16032
16033 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
16034
16035 \end_inset
16036
16037
16038 \emph on
16039 -
16040 \begin_inset ERT
16041 status collapsed
16042
16043 \begin_layout Standard
16044
16045
16046 \backslash
16047 /
16048 \end_layout
16049
16050 \end_inset
16051
16052 -main-return
16053 \emph default
16054
16055 \begin_inset LatexCommand \index{-\/-main-return}
16056
16057 \end_inset
16058
16059  and section 
16060 \begin_inset LatexCommand \ref{sub:MCS51-variants}
16061
16062 \end_inset
16063
16064  about MCS51-variants.
16065 \begin_inset VSpace bigskip
16066 \end_inset
16067
16068
16069 \end_layout
16070
16071 \begin_layout Subsection
16072 HC08 Startup Code
16073 \end_layout
16074
16075 \begin_layout Standard
16076 The HC08
16077 \begin_inset LatexCommand \index{HC08}
16078
16079 \end_inset
16080
16081  startup code follows the same scheme as the MCS51 startup code.
16082 \begin_inset VSpace bigskip
16083 \end_inset
16084
16085
16086 \end_layout
16087
16088 \begin_layout Subsection
16089 Z80 Startup Code
16090 \end_layout
16091
16092 \begin_layout Standard
16093 On the Z80
16094 \begin_inset LatexCommand \index{Z80}
16095
16096 \end_inset
16097
16098  the startup code is inserted by linking with crt0.o which is generated from
16099  sdcc/device/lib/z80/crt0.s.
16100  If you need a different startup code you can use the compiler option 
16101 \emph on
16102 -
16103 \series bold
16104 \emph default
16105
16106 \begin_inset ERT
16107 status collapsed
16108
16109 \begin_layout Standard
16110
16111
16112 \backslash
16113 /
16114 \end_layout
16115
16116 \end_inset
16117
16118
16119 \series default
16120 \emph on
16121 -no-std-crt0
16122 \emph default
16123
16124 \begin_inset LatexCommand \index{-\/-no-std-crt0}
16125
16126 \end_inset
16127
16128  and provide your own crt0.o.
16129  
16130 \begin_inset VSpace bigskip
16131 \end_inset
16132
16133
16134 \end_layout
16135
16136 \begin_layout Section
16137 Inline Assembler Code
16138 \begin_inset LatexCommand \index{Assembler routines}
16139
16140 \end_inset
16141
16142
16143 \end_layout
16144
16145 \begin_layout Subsection
16146 A Step by Step Introduction
16147 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
16148
16149 \end_inset
16150
16151
16152 \end_layout
16153
16154 \begin_layout Standard
16155 Starting from a small snippet of c-code this example shows for the MCS51
16156  how to use inline assembly, access variables, a function parameter and
16157  an array in xdata memory.
16158  The example uses an MCS51 here but is easily adapted for other architectures.
16159  This is a buffer routine which should be optimized:
16160 \end_layout
16161
16162 \begin_layout Verse
16163
16164 \family typewriter
16165 \size footnotesize
16166 unsigned char __far
16167 \begin_inset LatexCommand \index{far (storage class)}
16168
16169 \end_inset
16170
16171
16172 \begin_inset LatexCommand \index{\_\_far (storage class)}
16173
16174 \end_inset
16175
16176  __at
16177 \begin_inset LatexCommand \index{at}
16178
16179 \end_inset
16180
16181
16182 \begin_inset LatexCommand \index{\_\_at}
16183
16184 \end_inset
16185
16186 (0x7f00) buf[0x100];
16187 \begin_inset LatexCommand \index{Aligned array}
16188
16189 \end_inset
16190
16191
16192 \newline
16193 unsigned char head, tail;\InsetSpace ~
16194 \InsetSpace ~
16195 \InsetSpace ~
16196 \InsetSpace ~
16197 \InsetSpace ~
16198 \InsetSpace ~
16199 \InsetSpace ~
16200 \InsetSpace ~
16201 \InsetSpace ~
16202 \InsetSpace ~
16203 \InsetSpace ~
16204 \InsetSpace ~
16205 \InsetSpace ~
16206 \InsetSpace ~
16207 \InsetSpace ~
16208 \InsetSpace ~
16209 \InsetSpace ~
16210 /* if interrupts
16211 \begin_inset LatexCommand \index{interrupt}
16212
16213 \end_inset
16214
16215  are involved see
16216 \newline
16217 \InsetSpace ~
16218 \InsetSpace ~
16219 \InsetSpace ~
16220 \InsetSpace ~
16221 \InsetSpace ~
16222 \InsetSpace ~
16223 \InsetSpace ~
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 section 
16263 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
16264
16265 \end_inset
16266
16267  about
16268 \series bold
16269  volatile
16270 \series default
16271  */
16272 \newline
16273
16274 \newline
16275 void to_buffer( unsigned char c ) 
16276 \newline
16277 {
16278 \newline
16279 \InsetSpace ~
16280 \InsetSpace ~
16281 \InsetSpace ~
16282 \InsetSpace ~
16283 if( head != (unsigned char)(tail-1)
16284  )\InsetSpace ~
16285 /* cast 
16286 \series bold
16287 needed
16288 \series default
16289  to avoid promotion
16290 \begin_inset LatexCommand \index{promotion to signed int}
16291
16292 \end_inset
16293
16294
16295 \begin_inset LatexCommand \index{type promotion}
16296
16297 \end_inset
16298
16299  to integer */
16300 \begin_inset Marginal
16301 status collapsed
16302
16303 \begin_layout Standard
16304
16305 \series bold
16306 \InsetSpace ~
16307 !
16308 \end_layout
16309
16310 \end_inset
16311
16312
16313 \newline
16314 \InsetSpace ~
16315 \InsetSpace ~
16316 \InsetSpace ~
16317 \InsetSpace ~
16318 \InsetSpace ~
16319 \InsetSpace ~
16320 \InsetSpace ~
16321 \InsetSpace ~
16322 buf[ head++ ] = c;\InsetSpace ~
16323 \InsetSpace ~
16324 \InsetSpace ~
16325 \InsetSpace ~
16326 \InsetSpace ~
16327 \InsetSpace ~
16328 \InsetSpace ~
16329 \InsetSpace ~
16330 \InsetSpace ~
16331 \InsetSpace ~
16332 \InsetSpace ~
16333 \InsetSpace ~
16334 \InsetSpace ~
16335 \InsetSpace ~
16336 \InsetSpace ~
16337 \InsetSpace ~
16338 /* access to a 256 byte aligned array */
16339 \newline
16340
16341 \end_layout
16342
16343 \begin_layout Standard
16344 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16345  then a corresponding buffer.asm file is generated.
16346  We define a new function 
16347 \family typewriter
16348 to_buffer_asm()
16349 \family default
16350  in file buffer.c in which we cut and paste the generated code, removing
16351  unwanted comments and some ':'.
16352  Then add 
16353 \begin_inset Quotes sld
16354 \end_inset
16355
16356
16357 \series bold
16358 _asm
16359 \series default
16360
16361 \begin_inset Quotes srd
16362 \end_inset
16363
16364  and 
16365 \begin_inset Quotes sld
16366 \end_inset
16367
16368
16369 \series bold
16370 _endasm;
16371 \series default
16372
16373 \begin_inset Quotes srd
16374 \end_inset
16375
16376
16377 \begin_inset Foot
16378 status open
16379
16380 \begin_layout Standard
16381 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16382  and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16383  has to be used.
16384  The latter is also used in the library functions.
16385 \end_layout
16386
16387 \end_inset
16388
16389  to the beginning and the end of the function body:
16390 \end_layout
16391
16392 \begin_layout Verse
16393
16394 \family typewriter
16395 \size footnotesize
16396 /* With a cut and paste from the .asm file, we have something to start with.
16397 \newline
16398 \InsetSpace ~
16399 \InsetSpace ~
16400 \InsetSpace ~
16401 The
16402  function is not yet OK! (registers aren't saved) */ 
16403 \newline
16404 void to_buffer_asm(
16405  unsigned char c ) 
16406 \newline
16407
16408 \newline
16409 \InsetSpace ~
16410 \InsetSpace ~
16411 \InsetSpace ~
16412 \InsetSpace ~
16413 _asm
16414 \begin_inset LatexCommand \index{\_asm}
16415
16416 \end_inset
16417
16418
16419 \begin_inset LatexCommand \index{\_\_asm}
16420
16421 \end_inset
16422
16423
16424 \newline
16425 \InsetSpace ~
16426 \InsetSpace ~
16427 \InsetSpace ~
16428 \InsetSpace ~
16429 mov\InsetSpace ~
16430 \InsetSpace ~
16431 r2,dpl 
16432 \newline
16433 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16434 /* cast 
16435 \series bold
16436 needed
16437 \series default
16438  to avoid promotion
16439 \begin_inset LatexCommand \index{promotion to signed int}
16440
16441 \end_inset
16442
16443
16444 \begin_inset LatexCommand \index{type promotion}
16445
16446 \end_inset
16447
16448  to integer */
16449 \newline
16450 \InsetSpace ~
16451 \InsetSpace ~
16452 \InsetSpace ~
16453 \InsetSpace ~
16454 mov\InsetSpace ~
16455 \InsetSpace ~
16456 a,_tail 
16457 \newline
16458 \InsetSpace ~
16459 \InsetSpace ~
16460 \InsetSpace ~
16461 \InsetSpace ~
16462 dec\InsetSpace ~
16463 \InsetSpace ~
16464
16465 \newline
16466 \InsetSpace ~
16467 \InsetSpace ~
16468 \InsetSpace ~
16469 \InsetSpace ~
16470 mov\InsetSpace ~
16471 \InsetSpace ~
16472 r3,a 
16473 \newline
16474 \InsetSpace ~
16475 \InsetSpace ~
16476 \InsetSpace ~
16477 \InsetSpace ~
16478 mov\InsetSpace ~
16479 \InsetSpace ~
16480 a,_head 
16481 \newline
16482 \InsetSpace ~
16483 \InsetSpace ~
16484 \InsetSpace ~
16485 \InsetSpace ~
16486 cjne a,ar3,00106$ 
16487 \newline
16488 \InsetSpace ~
16489 \InsetSpace ~
16490 \InsetSpace ~
16491 \InsetSpace ~
16492 ret
16493 \newline
16494 00106$:
16495  
16496 \newline
16497 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16498 \begin_inset LatexCommand \index{Aligned array}
16499
16500 \end_inset
16501
16502
16503 \newline
16504 \InsetSpace ~
16505 \InsetSpace ~
16506 \InsetSpace ~
16507 \InsetSpace ~
16508 mov\InsetSpace ~
16509 \InsetSpace ~
16510 r3,_head 
16511 \newline
16512 \InsetSpace ~
16513 \InsetSpace ~
16514 \InsetSpace ~
16515 \InsetSpace ~
16516 inc\InsetSpace ~
16517 \InsetSpace ~
16518 _head 
16519 \newline
16520 \InsetSpace ~
16521 \InsetSpace ~
16522 \InsetSpace ~
16523 \InsetSpace ~
16524 mov\InsetSpace ~
16525 \InsetSpace ~
16526 dpl,r3 
16527 \newline
16528 \InsetSpace ~
16529 \InsetSpace ~
16530 \InsetSpace ~
16531 \InsetSpace ~
16532 mov\InsetSpace ~
16533 \InsetSpace ~
16534 dph,#(_buf >> 8) 
16535 \newline
16536 \InsetSpace ~
16537 \InsetSpace ~
16538 \InsetSpace ~
16539 \InsetSpace ~
16540 mov\InsetSpace ~
16541 \InsetSpace ~
16542 a,r2 
16543 \newline
16544 \InsetSpace ~
16545 \InsetSpace ~
16546 \InsetSpace ~
16547 \InsetSpace ~
16548 movx @dptr,a
16549  
16550 \newline
16551 00103$: 
16552 \newline
16553 \InsetSpace ~
16554 \InsetSpace ~
16555 \InsetSpace ~
16556 \InsetSpace ~
16557 ret
16558 \newline
16559 \InsetSpace ~
16560 \InsetSpace ~
16561 \InsetSpace ~
16562 \InsetSpace ~
16563 _endasm
16564 \begin_inset LatexCommand \index{\_endasm}
16565
16566 \end_inset
16567
16568
16569 \begin_inset LatexCommand \index{\_\_endasm}
16570
16571 \end_inset
16572
16573 ;
16574 \newline
16575
16576 \end_layout
16577
16578 \begin_layout Standard
16579 The new file buffer.c should compile with only one warning about the unreferenced
16580  function argument 'c'.
16581  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16582  (1) and finally have:
16583 \end_layout
16584
16585 \begin_layout Verse
16586
16587 \family typewriter
16588 \size footnotesize
16589 unsigned char __far __at(0x7f00) buf[0x100];
16590 \newline
16591 unsigned char head, tail;
16592 \newline
16593 #define
16594  USE_ASSEMBLY (1)
16595 \newline
16596
16597 \newline
16598 #if !USE_ASSEMBLY
16599 \newline
16600
16601 \newline
16602 void to_buffer( unsigned char c )
16603 \newline
16604 {
16605 \newline
16606 \InsetSpace ~
16607 \InsetSpace ~
16608 \InsetSpace ~
16609 \InsetSpace ~
16610 if(
16611  head != (unsigned char)(tail-1) )
16612 \newline
16613 \InsetSpace ~
16614 \InsetSpace ~
16615 \InsetSpace ~
16616 \InsetSpace ~
16617 \InsetSpace ~
16618 \InsetSpace ~
16619 \InsetSpace ~
16620 \InsetSpace ~
16621 buf[ head++ ] = c;
16622 \newline
16623 }
16624 \newline
16625
16626 \newline
16627 #else
16628 \newline
16629
16630 \newline
16631 void to_buffer(
16632  unsigned char c )
16633 \newline
16634 {
16635 \newline
16636 \InsetSpace ~
16637 \InsetSpace ~
16638 \InsetSpace ~
16639 \InsetSpace ~
16640 c; // to avoid warning: unreferenced function argument
16641 \newline
16642 \InsetSpace ~
16643 \InsetSpace ~
16644 \InsetSpace ~
16645 \InsetSpace ~
16646 _asm
16647 \begin_inset LatexCommand \index{\_asm}
16648
16649 \end_inset
16650
16651
16652 \begin_inset LatexCommand \index{\_\_asm}
16653
16654 \end_inset
16655
16656
16657 \newline
16658 \InsetSpace ~
16659 \InsetSpace ~
16660 \InsetSpace ~
16661 \InsetSpace ~
16662 \InsetSpace ~
16663 \InsetSpace ~
16664 \InsetSpace ~
16665 \InsetSpace ~
16666 ; save used registers here.
16667  
16668 \newline
16669 \InsetSpace ~
16670 \InsetSpace ~
16671 \InsetSpace ~
16672 \InsetSpace ~
16673 \InsetSpace ~
16674 \InsetSpace ~
16675 \InsetSpace ~
16676 \InsetSpace ~
16677 ; If we were still using r2,r3 we would have to push them here.
16678  
16679 \newline
16680 ; if( head != (unsigned char)(tail-1) )
16681 \newline
16682 \InsetSpace ~
16683 \InsetSpace ~
16684 \InsetSpace ~
16685 \InsetSpace ~
16686 \InsetSpace ~
16687 \InsetSpace ~
16688 \InsetSpace ~
16689 \InsetSpace ~
16690 mov\InsetSpace ~
16691  a,_tail
16692 \newline
16693 \InsetSpace ~
16694 \InsetSpace ~
16695 \InsetSpace ~
16696 \InsetSpace ~
16697 \InsetSpace ~
16698 \InsetSpace ~
16699 \InsetSpace ~
16700 \InsetSpace ~
16701 dec\InsetSpace ~
16702  a
16703 \newline
16704 \InsetSpace ~
16705 \InsetSpace ~
16706 \InsetSpace ~
16707 \InsetSpace ~
16708 \InsetSpace ~
16709 \InsetSpace ~
16710 \InsetSpace ~
16711 \InsetSpace ~
16712 xrl\InsetSpace ~
16713  a,_head
16714 \newline
16715 \InsetSpace ~
16716 \InsetSpace ~
16717 \InsetSpace ~
16718 \InsetSpace ~
16719 \InsetSpace ~
16720 \InsetSpace ~
16721 \InsetSpace ~
16722 \InsetSpace ~
16723 ; we
16724  could do an ANL a,#0x0f here to use a smaller buffer (see below)
16725 \newline
16726 \InsetSpace ~
16727 \InsetSpace ~
16728 \InsetSpace ~
16729 \InsetSpace ~
16730 \InsetSpace ~
16731 \InsetSpace ~
16732 \InsetSpace ~
16733 \InsetSpace ~
16734 jz\InsetSpace ~
16735 \InsetSpace ~
16736  t_b_end$
16737 \newline
16738 \InsetSpace ~
16739 \InsetSpace ~
16740 \InsetSpace ~
16741 \InsetSpace ~
16742 \InsetSpace ~
16743 \InsetSpace ~
16744 \InsetSpace ~
16745 \InsetSpace ~
16746 ;
16747 \newline
16748 ;
16749  buf[ head++ ] = c;
16750 \newline
16751 \InsetSpace ~
16752 \InsetSpace ~
16753 \InsetSpace ~
16754 \InsetSpace ~
16755 \InsetSpace ~
16756 \InsetSpace ~
16757 \InsetSpace ~
16758 \InsetSpace ~
16759 mov\InsetSpace ~
16760  a,dpl \InsetSpace ~
16761 \InsetSpace ~
16762 \InsetSpace ~
16763 \InsetSpace ~
16764 \InsetSpace ~
16765 \InsetSpace ~
16766 \InsetSpace ~
16767 ; dpl holds lower byte of function argument
16768 \newline
16769 \InsetSpace ~
16770 \InsetSpace ~
16771 \InsetSpace ~
16772 \InsetSpace ~
16773 \InsetSpace ~
16774 \InsetSpace ~
16775 \InsetSpace ~
16776 \InsetSpace ~
16777 mov\InsetSpace ~
16778
16779  dpl,_head \InsetSpace ~
16780 \InsetSpace ~
16781 \InsetSpace ~
16782 ; buf is 0x100 byte aligned so head can be used directly
16783 \newline
16784 \InsetSpace ~
16785 \InsetSpace ~
16786 \InsetSpace ~
16787 \InsetSpace ~
16788 \InsetSpace ~
16789 \InsetSpace ~
16790 \InsetSpace ~
16791 \InsetSpace ~
16792 mov\InsetSpace ~
16793  dph,#(_bu
16794 f>>8)
16795 \newline
16796 \InsetSpace ~
16797 \InsetSpace ~
16798 \InsetSpace ~
16799 \InsetSpace ~
16800 \InsetSpace ~
16801 \InsetSpace ~
16802 \InsetSpace ~
16803 \InsetSpace ~
16804 movx @dptr,a
16805 \newline
16806 \InsetSpace ~
16807 \InsetSpace ~
16808 \InsetSpace ~
16809 \InsetSpace ~
16810 \InsetSpace ~
16811 \InsetSpace ~
16812 \InsetSpace ~
16813 \InsetSpace ~
16814 inc \InsetSpace ~
16815 _head
16816 \newline
16817 \InsetSpace ~
16818 \InsetSpace ~
16819 \InsetSpace ~
16820 \InsetSpace ~
16821 \InsetSpace ~
16822 \InsetSpace ~
16823 \InsetSpace ~
16824 \InsetSpace ~
16825 ; we could do an ANL _head,#0x0f here to use a
16826  smaller buffer (see above)
16827 \newline
16828 t_b_end$:
16829 \newline
16830 \InsetSpace ~
16831 \InsetSpace ~
16832 \InsetSpace ~
16833 \InsetSpace ~
16834 \InsetSpace ~
16835 \InsetSpace ~
16836 \InsetSpace ~
16837 \InsetSpace ~
16838 ; restore used registers here 
16839 \newline
16840 \InsetSpace ~
16841 \InsetSpace ~
16842 \InsetSpace ~
16843 \InsetSpace ~
16844 _endasm
16845 \begin_inset LatexCommand \index{\_endasm}
16846
16847 \end_inset
16848
16849
16850 \begin_inset LatexCommand \index{\_\_endasm}
16851
16852 \end_inset
16853
16854 ;
16855 \newline
16856 }
16857 \newline
16858 #endif
16859 \end_layout
16860
16861 \begin_layout Standard
16862 The inline assembler code can contain any valid code understood by the assembler
16863 , this includes any assembler directives and comment lines.
16864  The assembler does not like some characters like ':' or ''' in comments.
16865  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
16866 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
16867
16868 \end_inset
16869
16870
16871 \begin_inset LatexCommand \index{Assembler documentation}
16872
16873 \end_inset
16874
16875  or online at 
16876 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
16877
16878 \end_inset
16879
16880 \InsetSpace ~
16881 .
16882 \end_layout
16883
16884 \begin_layout Standard
16885 The compiler does not do any validation of the code within the 
16886 \family typewriter
16887 _asm
16888 \begin_inset LatexCommand \index{\_asm}
16889
16890 \end_inset
16891
16892
16893 \begin_inset LatexCommand \index{\_\_asm}
16894
16895 \end_inset
16896
16897  ...
16898  _endasm
16899 \size footnotesize
16900
16901 \begin_inset LatexCommand \index{\_endasm}
16902
16903 \end_inset
16904
16905
16906 \begin_inset LatexCommand \index{\_\_endasm}
16907
16908 \end_inset
16909
16910
16911 \size default
16912 ;
16913 \family default
16914  keyword pair.
16915  Specifically it will not know which registers are used and thus register
16916  pushing/popping
16917 \begin_inset LatexCommand \index{push/pop}
16918
16919 \end_inset
16920
16921  has to be done manually.
16922  
16923 \end_layout
16924
16925 \begin_layout Standard
16926 It is recommended that each assembly instruction (including labels) be placed
16927  in a separate line (as the example shows).
16928  When the -
16929 \begin_inset ERT
16930 status collapsed
16931
16932 \begin_layout Standard
16933
16934
16935 \backslash
16936 /
16937 \end_layout
16938
16939 \end_inset
16940
16941 -
16942 \emph on
16943 peep-asm
16944 \begin_inset LatexCommand \index{-\/-peep-asm}
16945
16946 \end_inset
16947
16948
16949 \emph default
16950  command line option is used, the inline assembler code will be passed through
16951  the peephole optimizer
16952 \begin_inset LatexCommand \index{Peephole optimizer}
16953
16954 \end_inset
16955
16956 .
16957  There are only a few (if any) cases where this option makes sense, it might
16958  cause some unexpected changes in the inline assembler code.
16959  Please go through the peephole optimizer rules defined in file 
16960 \emph on
16961 SDCCpeeph.def
16962 \emph default
16963  before using this option.
16964 \end_layout
16965
16966 \begin_layout Subsection
16967 Naked Functions
16968 \begin_inset LatexCommand \label{sub:Naked-Functions}
16969
16970 \end_inset
16971
16972
16973 \begin_inset LatexCommand \index{Naked functions}
16974
16975 \end_inset
16976
16977
16978 \end_layout
16979
16980 \begin_layout Standard
16981 A special keyword may be associated with a function declaring it as 
16982 \emph on
16983 _naked
16984 \begin_inset LatexCommand \index{\_naked}
16985
16986 \end_inset
16987
16988
16989 \begin_inset LatexCommand \index{\_\_naked}
16990
16991 \end_inset
16992
16993 .
16994  
16995 \emph default
16996 The 
16997 \emph on
16998 _naked
16999 \emph default
17000  function modifier attribute prevents the compiler from generating prologue
17001 \begin_inset LatexCommand \index{function prologue}
17002
17003 \end_inset
17004
17005  and epilogue
17006 \begin_inset LatexCommand \index{function epilogue}
17007
17008 \end_inset
17009
17010  code for that function.
17011  This means that the user is entirely responsible for such things as saving
17012  any registers that may need to be preserved, selecting the proper register
17013  bank, generating the 
17014 \emph on
17015 return
17016 \emph default
17017  instruction at the end, etc.
17018  Practically, this means that the contents of the function must be written
17019  in inline assembler.
17020  This is particularly useful for interrupt functions, which can have a large
17021  (and often unnecessary) prologue/epilogue.
17022  For example, compare the code generated by these two functions:
17023 \end_layout
17024
17025 \begin_layout Verse
17026
17027 \family typewriter
17028 volatile
17029 \begin_inset LatexCommand \index{volatile}
17030
17031 \end_inset
17032
17033  data unsigned char counter;
17034 \newline
17035
17036 \newline
17037 void simpleInterrupt(void) __interrupt
17038 \begin_inset LatexCommand \index{interrupt}
17039
17040 \end_inset
17041
17042
17043 \begin_inset LatexCommand \index{\_\_interrupt}
17044
17045 \end_inset
17046
17047  (1)
17048 \newline
17049 {
17050 \newline
17051 \InsetSpace ~
17052 \InsetSpace ~
17053 \InsetSpace ~
17054 \InsetSpace ~
17055 counter++;
17056 \newline
17057 }
17058 \newline
17059
17060 \newline
17061 void nakedInterrupt(void) __interrupt (2) __naked
17062 \newline
17063 {
17064 \newline
17065 \InsetSpace ~
17066 \InsetSpace ~
17067 \InsetSpace ~
17068 \InsetSpace ~
17069 _asm
17070 \begin_inset LatexCommand \index{\_asm}
17071
17072 \end_inset
17073
17074
17075 \begin_inset LatexCommand \index{\_\_asm}
17076
17077 \end_inset
17078
17079
17080 \newline
17081 \InsetSpace ~
17082 \InsetSpace ~
17083 \InsetSpace ~
17084 \InsetSpace ~
17085 \InsetSpace ~
17086 \InsetSpace ~
17087 inc\InsetSpace ~
17088 \InsetSpace ~
17089 \InsetSpace ~
17090 \InsetSpace ~
17091 \InsetSpace ~
17092 _counter ; does not change flags, no need to save psw
17093 \newline
17094 \InsetSpace ~
17095 \InsetSpace ~
17096 \InsetSpace ~
17097 \InsetSpace ~
17098 \InsetSpace ~
17099 \InsetSpace ~
17100 reti\InsetSpace ~
17101 \InsetSpace ~
17102 \InsetSpace ~
17103 \InsetSpace ~
17104 ; MUST explicitly
17105  include ret or reti in _naked function.
17106 \newline
17107 \InsetSpace ~
17108 \InsetSpace ~
17109 \InsetSpace ~
17110 \InsetSpace ~
17111 _endasm
17112 \begin_inset LatexCommand \index{\_endasm}
17113
17114 \end_inset
17115
17116
17117 \begin_inset LatexCommand \index{\_\_endasm}
17118
17119 \end_inset
17120
17121 ;
17122 \newline
17123 }
17124 \end_layout
17125
17126 \begin_layout Standard
17127 For an 8051 target, the generated simpleInterrupt looks like:
17128 \end_layout
17129
17130 \begin_layout Verse
17131
17132 \family typewriter
17133 Note, this is an 
17134 \emph on
17135 outdated
17136 \emph default
17137  example, recent versions of SDCC generate
17138 \newline
17139 the 
17140 \emph on
17141 same
17142 \emph default
17143  code for simpleInterrupt() and nakedInterrupt()!
17144 \newline
17145
17146 \newline
17147 _simpleInterrupt:
17148 \newline
17149 \InsetSpace ~
17150 \InsetSpace ~
17151 \InsetSpace ~
17152 \InsetSpace ~
17153 push\InsetSpace ~
17154 \InsetSpace ~
17155 \InsetSpace ~
17156 \InsetSpace ~
17157 acc
17158 \newline
17159 \InsetSpace ~
17160 \InsetSpace ~
17161 \InsetSpace ~
17162 \InsetSpace ~
17163 push\InsetSpace ~
17164 \InsetSpace ~
17165 \InsetSpace ~
17166 \InsetSpace ~
17167 b
17168 \newline
17169 \InsetSpace ~
17170 \InsetSpace ~
17171 \InsetSpace ~
17172 \InsetSpace ~
17173 pu
17174 sh\InsetSpace ~
17175 \InsetSpace ~
17176 \InsetSpace ~
17177 \InsetSpace ~
17178 dpl
17179 \newline
17180 \InsetSpace ~
17181 \InsetSpace ~
17182 \InsetSpace ~
17183 \InsetSpace ~
17184 push\InsetSpace ~
17185 \InsetSpace ~
17186 \InsetSpace ~
17187 \InsetSpace ~
17188 dph
17189 \newline
17190 \InsetSpace ~
17191 \InsetSpace ~
17192 \InsetSpace ~
17193 \InsetSpace ~
17194 push\InsetSpace ~
17195 \InsetSpace ~
17196 \InsetSpace ~
17197 \InsetSpace ~
17198 psw
17199 \newline
17200 \InsetSpace ~
17201 \InsetSpace ~
17202 \InsetSpace ~
17203 \InsetSpace ~
17204 mov\InsetSpace ~
17205 \InsetSpace ~
17206 \InsetSpace ~
17207 \InsetSpace ~
17208 \InsetSpace ~
17209 psw,#0x00
17210 \newline
17211 \InsetSpace ~
17212 \InsetSpace ~
17213 \InsetSpace ~
17214 \InsetSpace ~
17215 inc\InsetSpace ~
17216 \InsetSpace ~
17217 \InsetSpace ~
17218 \InsetSpace ~
17219 \InsetSpace ~
17220 _counter
17221 \newline
17222 \InsetSpace ~
17223 \InsetSpace ~
17224 \InsetSpace ~
17225 \InsetSpace ~
17226 pop\InsetSpace ~
17227 \InsetSpace ~
17228 \InsetSpace ~
17229 \InsetSpace ~
17230 \InsetSpace ~
17231 psw
17232 \newline
17233 \InsetSpace ~
17234 \InsetSpace ~
17235 \InsetSpace ~
17236 \InsetSpace ~
17237 pop\InsetSpace ~
17238 \InsetSpace ~
17239 \InsetSpace ~
17240 \InsetSpace ~
17241 \InsetSpace ~
17242 dph
17243 \newline
17244 \InsetSpace ~
17245 \InsetSpace ~
17246 \InsetSpace ~
17247 \InsetSpace ~
17248 pop\InsetSpace ~
17249 \InsetSpace ~
17250 \InsetSpace ~
17251 \InsetSpace ~
17252 \InsetSpace ~
17253 dpl
17254 \newline
17255 \InsetSpace ~
17256 \InsetSpace ~
17257 \InsetSpace ~
17258 \InsetSpace ~
17259 pop\InsetSpace ~
17260 \InsetSpace ~
17261 \InsetSpace ~
17262 \InsetSpace ~
17263 \InsetSpace ~
17264 b
17265 \newline
17266 \InsetSpace ~
17267 \InsetSpace ~
17268 \InsetSpace ~
17269 \InsetSpace ~
17270 pop\InsetSpace ~
17271 \InsetSpace ~
17272 \InsetSpace ~
17273 \InsetSpace ~
17274 \InsetSpace ~
17275 acc
17276 \newline
17277 \InsetSpace ~
17278 \InsetSpace ~
17279 \InsetSpace ~
17280 \InsetSpace ~
17281 reti
17282 \end_layout
17283
17284 \begin_layout Standard
17285 whereas nakedInterrupt looks like:
17286 \end_layout
17287
17288 \begin_layout Verse
17289
17290 \family typewriter
17291 _nakedInterrupt:
17292 \newline
17293 \InsetSpace ~
17294 \InsetSpace ~
17295 \InsetSpace ~
17296 \InsetSpace ~
17297 inc\InsetSpace ~
17298 \InsetSpace ~
17299 \InsetSpace ~
17300 \InsetSpace ~
17301 _counter ; does not change flags, no need to save psw
17302 \newline
17303 \InsetSpace ~
17304 \InsetSpace ~
17305 \InsetSpace ~
17306 \InsetSpace ~
17307 reti\InsetSpace ~
17308 \InsetSpace ~
17309 \InsetSpace ~
17310 \InsetSpace ~
17311 \InsetSpace ~
17312 \InsetSpace ~
17313 \InsetSpace ~
17314 \InsetSpace ~
17315 \InsetSpace ~
17316 \InsetSpace ~
17317 \InsetSpace ~
17318 \InsetSpace ~
17319 ;
17320  MUST explicitly include ret or reti in _naked function
17321 \end_layout
17322
17323 \begin_layout Standard
17324 The related directive #pragma exclude
17325 \begin_inset LatexCommand \index{\#pragma exclude}
17326
17327 \end_inset
17328
17329  allows a more fine grained control over pushing & popping
17330 \begin_inset LatexCommand \index{push/pop}
17331
17332 \end_inset
17333
17334  the registers.
17335 \end_layout
17336
17337 \begin_layout Standard
17338 While there is nothing preventing you from writing C code inside a 
17339 \family typewriter
17340 _naked
17341 \family default
17342  function, there are many ways to shoot yourself in the foot doing this,
17343  and it is recommended that you stick to inline assembler.
17344 \end_layout
17345
17346 \begin_layout Subsection
17347 Use of Labels within Inline Assembler
17348 \end_layout
17349
17350 \begin_layout Standard
17351 SDCC allows the use of in-line assembler with a few restrictions regarding
17352  labels.
17353  In older versions of the compiler all labels defined within inline assembler
17354  code had to be of the form 
17355 \emph on
17356 nnnnn$
17357 \emph default
17358  where nnnnn is a number less than 100 (which implies a limit of utmost
17359  100 inline assembler labels 
17360 \emph on
17361 per function
17362 \emph default
17363 \noun on
17364 )
17365 \noun default
17366 .
17367  
17368 \end_layout
17369
17370 \begin_layout Verse
17371
17372 \family typewriter
17373 _asm
17374 \begin_inset LatexCommand \index{\_asm}
17375
17376 \end_inset
17377
17378
17379 \begin_inset LatexCommand \index{\_\_asm}
17380
17381 \end_inset
17382
17383  
17384 \newline
17385 \InsetSpace ~
17386 \InsetSpace ~
17387 \InsetSpace ~
17388 \InsetSpace ~
17389 mov\InsetSpace ~
17390 \InsetSpace ~
17391 \InsetSpace ~
17392 \InsetSpace ~
17393 \InsetSpace ~
17394 b,#10 
17395 \newline
17396 00001$: 
17397 \newline
17398 \InsetSpace ~
17399 \InsetSpace ~
17400 \InsetSpace ~
17401 \InsetSpace ~
17402 djnz\InsetSpace ~
17403 \InsetSpace ~
17404 \InsetSpace ~
17405 \InsetSpace ~
17406 b,00001$ 
17407 \newline
17408 _endasm
17409 \begin_inset LatexCommand \index{\_endasm}
17410
17411 \end_inset
17412
17413
17414 \begin_inset LatexCommand \index{\_\_endasm}
17415
17416 \end_inset
17417
17418  ;
17419 \end_layout
17420
17421 \begin_layout Standard
17422 Inline assembler code cannot reference any C-labels, however it can reference
17423  labels
17424 \begin_inset LatexCommand \index{Labels}
17425
17426 \end_inset
17427
17428  defined by the inline assembler, e.g.:
17429 \end_layout
17430
17431 \begin_layout Verse
17432
17433 \family typewriter
17434 foo() { 
17435 \newline
17436 \InsetSpace ~
17437 \InsetSpace ~
17438 \InsetSpace ~
17439 \InsetSpace ~
17440 /* some c code */ 
17441 \newline
17442 \InsetSpace ~
17443 \InsetSpace ~
17444 \InsetSpace ~
17445 \InsetSpace ~
17446 _asm 
17447 \newline
17448 \InsetSpace ~
17449 \InsetSpace ~
17450 \InsetSpace ~
17451 \InsetSpace ~
17452 \InsetSpace ~
17453 \InsetSpace ~
17454 ; some assembler code 
17455 \newline
17456 \InsetSpace ~
17457 \InsetSpace ~
17458 \InsetSpace ~
17459 \InsetSpace ~
17460 \InsetSpace ~
17461 \InsetSpace ~
17462 ljmp $0003 
17463 \newline
17464 \InsetSpace ~
17465 \InsetSpace ~
17466 \InsetSpace ~
17467 \InsetSpace ~
17468 _endasm;
17469  
17470 \newline
17471 \InsetSpace ~
17472 \InsetSpace ~
17473 \InsetSpace ~
17474 \InsetSpace ~
17475 /* some more c code */ 
17476 \newline
17477 clabel:\InsetSpace ~
17478 \InsetSpace ~
17479 /* inline assembler cannot reference this
17480  label */ 
17481 \newline
17482 \InsetSpace ~
17483 \InsetSpace ~
17484 \InsetSpace ~
17485 \InsetSpace ~
17486 _asm
17487 \newline
17488 \InsetSpace ~
17489 \InsetSpace ~
17490 \InsetSpace ~
17491 \InsetSpace ~
17492 $0003: ;label (can be referenced by inline assembler only)
17493  
17494 \newline
17495 \InsetSpace ~
17496 \InsetSpace ~
17497 \InsetSpace ~
17498 \InsetSpace ~
17499 _endasm
17500 \begin_inset LatexCommand \index{\_endasm}
17501
17502 \end_inset
17503
17504
17505 \begin_inset LatexCommand \index{\_\_endasm}
17506
17507 \end_inset
17508
17509  ; 
17510 \newline
17511 \InsetSpace ~
17512 \InsetSpace ~
17513 \InsetSpace ~
17514 \InsetSpace ~
17515 /* some more c code */
17516 \newline
17517 }
17518 \end_layout
17519
17520 \begin_layout Standard
17521 In other words inline assembly code can access labels defined in inline
17522  assembly within the scope of the function.
17523  The same goes the other way, i.e.
17524  labels defines in inline assembly can not be accessed by C statements.
17525 \end_layout
17526
17527 \begin_layout Section
17528 Interfacing with Assembler Code
17529 \begin_inset LatexCommand \index{Assembler routines}
17530
17531 \end_inset
17532
17533
17534 \end_layout
17535
17536 \begin_layout Subsection
17537 Global Registers used for Parameter Passing
17538 \begin_inset LatexCommand \index{Parameter passing}
17539
17540 \end_inset
17541
17542
17543 \end_layout
17544
17545 \begin_layout Standard
17546 The compiler always uses the global registers 
17547 \emph on
17548 DPL, DPH
17549 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17550
17551 \end_inset
17552
17553
17554 \begin_inset LatexCommand \index{DPTR}
17555
17556 \end_inset
17557
17558 , B
17559 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17560
17561 \end_inset
17562
17563  
17564 \emph default
17565 and
17566 \emph on
17567  ACC
17568 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17569
17570 \end_inset
17571
17572
17573 \emph default
17574  to pass the first parameter to a function, and also to pass the return
17575  value 
17576 \begin_inset LatexCommand \index{return value}
17577
17578 \end_inset
17579
17580 of function; according to the following scheme: one byte return value in
17581  
17582 \emph on
17583 DPL
17584 \emph default
17585 , two byte value in 
17586 \emph on
17587 DPL
17588 \emph default
17589  (LSB) and 
17590 \emph on
17591 DPH
17592 \emph default
17593  (MSB).
17594  three byte values (generic pointers) in 
17595 \emph on
17596 DPH
17597 \emph default
17598
17599 \emph on
17600 DPL
17601 \emph default
17602  and 
17603 \emph on
17604 B
17605 \emph default
17606 , and four byte values in 
17607 \emph on
17608 DPH
17609 \emph default
17610
17611 \emph on
17612 DPL
17613 \emph default
17614 ,
17615 \emph on
17616  B
17617 \emph default
17618  and 
17619 \emph on
17620 ACC
17621 \emph default
17622 .
17623  Generic pointers
17624 \begin_inset LatexCommand \index{generic pointer}
17625
17626 \end_inset
17627
17628  contain type of accessed memory in 
17629 \emph on
17630 B
17631 \emph default
17632
17633 \series bold
17634 0x00
17635 \series default
17636  -- xdata/far, 
17637 \series bold
17638 0x40
17639 \series default
17640  -- idata/near -- , 
17641 \series bold
17642 0x60
17643 \series default
17644  -- pdata, 
17645 \series bold
17646 0x80
17647 \series default
17648  -- code
17649 \begin_inset Note Note
17650 status collapsed
17651
17652 \begin_layout Standard
17653 This might not be the case of certain memory models (medium???)
17654 \end_layout
17655
17656 \end_inset
17657
17658 .
17659 \end_layout
17660
17661 \begin_layout Standard
17662 The second parameter onwards is either allocated on the stack (for reentrant
17663  routines or if -
17664 \begin_inset ERT
17665 status collapsed
17666
17667 \begin_layout Standard
17668
17669
17670 \backslash
17671 /
17672 \end_layout
17673
17674 \end_inset
17675
17676 -stack-auto is used) or in data/xdata memory (depending on the memory model).
17677  
17678 \end_layout
17679
17680 \begin_layout Subsection
17681 Registers usage
17682 \end_layout
17683
17684 \begin_layout Standard
17685 Unless the called function is declared as 
17686 \family typewriter
17687 _naked
17688 \family default
17689
17690 \begin_inset LatexCommand \index{naked}
17691
17692 \end_inset
17693
17694 , or the -
17695 \begin_inset ERT
17696 status collapsed
17697
17698 \begin_layout Standard
17699
17700
17701 \backslash
17702 /
17703 \end_layout
17704
17705 \end_inset
17706
17707 -callee-saves
17708 \begin_inset LatexCommand \index{-\/-callee-saves}
17709
17710 \end_inset
17711
17712 /-
17713 \begin_inset ERT
17714 status collapsed
17715
17716 \begin_layout Standard
17717
17718
17719 \backslash
17720 /
17721 \end_layout
17722
17723 \end_inset
17724
17725 -all-callee-saves command line option or the corresponding callee_saves
17726  pragma are used, the caller will save the registers (
17727 \emph on
17728 R0-R7
17729 \emph default
17730 ) around the call, so the called function can destroy they content freely.
17731 \end_layout
17732
17733 \begin_layout Standard
17734 If the called function is not declared as 
17735 \family typewriter
17736 _naked
17737 \family default
17738 , the caller will swap register banks around the call, if caller and callee
17739  use different register banks (having them defined by the 
17740 \family typewriter
17741 _using
17742 \family default
17743  modifier).
17744  
17745 \end_layout
17746
17747 \begin_layout Standard
17748 The called function can also use 
17749 \emph on
17750 DPL
17751 \emph default
17752
17753 \emph on
17754 DPH
17755 \emph default
17756
17757 \emph on
17758 B
17759 \emph default
17760  and 
17761 \emph on
17762 ACC
17763 \emph default
17764  observing that they are used for parameter/return value passing.
17765 \end_layout
17766
17767 \begin_layout Subsection
17768 Assembler Routine (non-reentrant)
17769 \end_layout
17770
17771 \begin_layout Standard
17772 In the following example
17773 \begin_inset LatexCommand \index{reentrant}
17774
17775 \end_inset
17776
17777
17778 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
17779
17780 \end_inset
17781
17782  the function c_func calls an assembler routine asm_func, which takes two
17783  parameters
17784 \begin_inset LatexCommand \index{function parameter}
17785
17786 \end_inset
17787
17788 .
17789 \end_layout
17790
17791 \begin_layout Verse
17792
17793 \family typewriter
17794 extern int asm_func(unsigned char, unsigned char);
17795 \newline
17796
17797 \newline
17798 int c_func (unsigned char
17799  i, unsigned char j)
17800 \newline
17801 {
17802 \newline
17803 \InsetSpace ~
17804 \InsetSpace ~
17805 \InsetSpace ~
17806 \InsetSpace ~
17807 return asm_func(i,j);
17808 \newline
17809 }
17810 \newline
17811
17812 \newline
17813 int main()
17814 \newline
17815 {
17816 \newline
17817 \InsetSpace ~
17818 \InsetSpace ~
17819 \InsetSpace ~
17820 \InsetSpace ~
17821 return c_func(10,9);
17822 \newline
17823 }
17824 \end_layout
17825
17826 \begin_layout Standard
17827 The corresponding assembler function is:
17828 \end_layout
17829
17830 \begin_layout Verse
17831
17832 \family typewriter
17833 .globl _asm_func_PARM_2 
17834 \newline
17835 \InsetSpace ~
17836 \InsetSpace ~
17837 \InsetSpace ~
17838 \InsetSpace ~
17839 \InsetSpace ~
17840 \InsetSpace ~
17841 \InsetSpace ~
17842 \InsetSpace ~
17843 .globl _asm_func 
17844 \newline
17845 \InsetSpace ~
17846 \InsetSpace ~
17847 \InsetSpace ~
17848 \InsetSpace ~
17849 \InsetSpace ~
17850 \InsetSpace ~
17851 \InsetSpace ~
17852 \InsetSpace ~
17853 .area OSEG 
17854 \newline
17855 _asm_func_PARM_2:
17856 \newline
17857 \InsetSpace ~
17858 \InsetSpace ~
17859 \InsetSpace ~
17860 \InsetSpace ~
17861 \InsetSpace ~
17862 \InsetSpace ~
17863 \InsetSpace ~
17864 \InsetSpace ~
17865 .ds   
17866  1 
17867 \newline
17868 \InsetSpace ~
17869 \InsetSpace ~
17870 \InsetSpace ~
17871 \InsetSpace ~
17872 \InsetSpace ~
17873 \InsetSpace ~
17874 \InsetSpace ~
17875 \InsetSpace ~
17876 .area CSEG 
17877 \newline
17878 _asm_func: 
17879 \newline
17880 \InsetSpace ~
17881 \InsetSpace ~
17882 \InsetSpace ~
17883 \InsetSpace ~
17884 \InsetSpace ~
17885 \InsetSpace ~
17886 \InsetSpace ~
17887 \InsetSpace ~
17888 mov\InsetSpace ~
17889 \InsetSpace ~
17890 \InsetSpace ~
17891 \InsetSpace ~
17892 a,dpl 
17893 \newline
17894 \InsetSpace ~
17895 \InsetSpace ~
17896 \InsetSpace ~
17897 \InsetSpace ~
17898 \InsetSpace ~
17899 \InsetSpace ~
17900 \InsetSpace ~
17901 \InsetSpace ~
17902 add\InsetSpace ~
17903 \InsetSpace ~
17904 \InsetSpace ~
17905 \InsetSpace ~
17906 a,_asm_func_PARM_2 
17907 \newline
17908 \InsetSpace ~
17909 \InsetSpace ~
17910 \InsetSpace ~
17911 \InsetSpace ~
17912 \InsetSpace ~
17913 \InsetSpace ~
17914 \InsetSpace ~
17915 \InsetSpace ~
17916 mov\InsetSpace ~
17917 \InsetSpace ~
17918 \InsetSpace ~
17919 \InsetSpace ~
17920 dpl,a 
17921 \newline
17922 \InsetSpace ~
17923 \InsetSpace ~
17924 \InsetSpace ~
17925 \InsetSpace ~
17926 \InsetSpace ~
17927 \InsetSpace ~
17928 \InsetSpace ~
17929 \InsetSpace ~
17930 mov\InsetSpace ~
17931 \InsetSpace ~
17932 \InsetSpace ~
17933 \InsetSpace ~
17934 dph
17935 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17936
17937 \end_inset
17938
17939 ,#0x00 
17940 \newline
17941 \InsetSpace ~
17942 \InsetSpace ~
17943 \InsetSpace ~
17944 \InsetSpace ~
17945 \InsetSpace ~
17946 \InsetSpace ~
17947 \InsetSpace ~
17948 \InsetSpace ~
17949 ret
17950 \end_layout
17951
17952 \begin_layout Standard
17953 The parameter naming convention is _<function_name>_PARM_<n>, where n is
17954  the parameter number starting from 1, and counting from the left.
17955  The first parameter is passed in 
17956 \emph on
17957 DPH
17958 \emph default
17959
17960 \emph on
17961 DPL
17962 \emph default
17963
17964 \emph on
17965 B
17966 \emph default
17967  and 
17968 \emph on
17969 ACC
17970 \emph default
17971  according to the description above.
17972  The variable name for the second parameter will be _<function_name>_PARM_2.
17973 \newline
17974
17975 \newline
17976 Assem
17977 ble the assembler routine with the following command:
17978 \newline
17979
17980 \newline
17981
17982 \family sans
17983 \series bold
17984 asx8051 -losg asmfunc.asm
17985 \newline
17986
17987 \newline
17988
17989 \family default
17990 \series default
17991 Then compile and link the assembler routine to the C source file with the
17992  following command:
17993 \newline
17994
17995 \newline
17996
17997 \family sans
17998 \series bold
17999 sdcc cfunc.c asmfunc.rel
18000 \end_layout
18001
18002 \begin_layout Subsection
18003 Assembler Routine (reentrant)
18004 \end_layout
18005
18006 \begin_layout Standard
18007 In this case
18008 \begin_inset LatexCommand \index{reentrant}
18009
18010 \end_inset
18011
18012
18013 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
18014
18015 \end_inset
18016
18017  the second parameter
18018 \begin_inset LatexCommand \index{function parameter}
18019
18020 \end_inset
18021
18022  onwards will be passed on the stack, the parameters are pushed from right
18023  to left i.e.
18024  before the call the second leftmost parameter will be on the top of the
18025  stack (the leftmost parameter is passed in registers).
18026  Here is an example:
18027 \end_layout
18028
18029 \begin_layout Verse
18030
18031 \family typewriter
18032 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
18033 \newline
18034
18035 \newline
18036 int
18037  c_func (unsigned char i, unsigned char j, unsigned char k) reentrant 
18038 \newline
18039 {
18040  
18041 \newline
18042 \InsetSpace ~
18043 \InsetSpace ~
18044 \InsetSpace ~
18045 \InsetSpace ~
18046 return asm_func(i,j,k); 
18047 \newline
18048
18049 \newline
18050
18051 \newline
18052 int main() 
18053 \newline
18054
18055 \newline
18056 \InsetSpace ~
18057 \InsetSpace ~
18058 \InsetSpace ~
18059 \InsetSpace ~
18060 return c_func(10,9,8); 
18061 \newline
18062 }
18063 \end_layout
18064
18065 \begin_layout Standard
18066 The corresponding (unoptimized) assembler routine is:
18067 \end_layout
18068
18069 \begin_layout Verse
18070
18071 \family typewriter
18072 .globl _asm_func 
18073 \newline
18074 _asm_func: 
18075 \newline
18076 \InsetSpace ~
18077 \InsetSpace ~
18078 \InsetSpace ~
18079 \InsetSpace ~
18080 push\InsetSpace ~
18081 _bp 
18082 \newline
18083 \InsetSpace ~
18084 \InsetSpace ~
18085 \InsetSpace ~
18086 \InsetSpace ~
18087 mov\InsetSpace ~
18088 \InsetSpace ~
18089 _bp,sp\InsetSpace ~
18090 \InsetSpace ~
18091 \InsetSpace ~
18092 \InsetSpace ~
18093 \InsetSpace ~
18094 \InsetSpace ~
18095 ;stack contains: _bp, return
18096  address, second parameter, third parameter
18097 \newline
18098 \InsetSpace ~
18099 \InsetSpace ~
18100 \InsetSpace ~
18101 \InsetSpace ~
18102 mov\InsetSpace ~
18103 \InsetSpace ~
18104 r2,dpl
18105 \newline
18106 \InsetSpace ~
18107 \InsetSpace ~
18108 \InsetSpace ~
18109 \InsetSpace ~
18110 mov\InsetSpace ~
18111 \InsetSpace ~
18112 a,_bp
18113 \newline
18114 \InsetSpace ~
18115 \InsetSpace ~
18116 \InsetSpace ~
18117 \InsetSpace ~
18118 add\InsetSpace ~
18119 \InsetSpace ~
18120 a,#0xfd\InsetSpace ~
18121 \InsetSpace ~
18122 \InsetSpace ~
18123 \InsetSpace ~
18124 \InsetSpace ~
18125 ;calculate
18126  pointer to the second parameter
18127 \newline
18128 \InsetSpace ~
18129 \InsetSpace ~
18130 \InsetSpace ~
18131 \InsetSpace ~
18132 mov\InsetSpace ~
18133 \InsetSpace ~
18134 r0,a 
18135 \newline
18136 \InsetSpace ~
18137 \InsetSpace ~
18138 \InsetSpace ~
18139 \InsetSpace ~
18140 mov\InsetSpace ~
18141 \InsetSpace ~
18142 a,_bp 
18143 \newline
18144 \InsetSpace ~
18145 \InsetSpace ~
18146 \InsetSpace ~
18147 \InsetSpace ~
18148 add\InsetSpace ~
18149 \InsetSpace ~
18150 a,#0xfc\InsetSpace ~
18151 \InsetSpace ~
18152 \InsetSpace ~
18153 \InsetSpace ~
18154 \InsetSpace ~
18155 ;calculate pointer
18156  to the rightmost parameter
18157 \newline
18158 \InsetSpace ~
18159 \InsetSpace ~
18160 \InsetSpace ~
18161 \InsetSpace ~
18162 mov\InsetSpace ~
18163 \InsetSpace ~
18164 r1,a 
18165 \newline
18166 \InsetSpace ~
18167 \InsetSpace ~
18168 \InsetSpace ~
18169 \InsetSpace ~
18170 mov\InsetSpace ~
18171 \InsetSpace ~
18172 a,@r0
18173 \newline
18174 \InsetSpace ~
18175 \InsetSpace ~
18176 \InsetSpace ~
18177 \InsetSpace ~
18178 add\InsetSpace ~
18179 \InsetSpace ~
18180 a,@r1
18181 \newline
18182 \InsetSpace ~
18183 \InsetSpace ~
18184 \InsetSpace ~
18185 \InsetSpace ~
18186 add\InsetSpace ~
18187 \InsetSpace ~
18188 a,r2\InsetSpace ~
18189 \InsetSpace ~
18190 \InsetSpace ~
18191 \InsetSpace ~
18192 \InsetSpace ~
18193 \InsetSpace ~
18194 \InsetSpace ~
18195 \InsetSpace ~
18196 ;calculate the
18197  result (= sum of all three parameters)
18198 \newline
18199 \InsetSpace ~
18200 \InsetSpace ~
18201 \InsetSpace ~
18202 \InsetSpace ~
18203 mov\InsetSpace ~
18204 \InsetSpace ~
18205 dpl,a\InsetSpace ~
18206 \InsetSpace ~
18207 \InsetSpace ~
18208 \InsetSpace ~
18209 \InsetSpace ~
18210 \InsetSpace ~
18211 \InsetSpace ~
18212 ;return value goes into dptr
18213  (cast into int)
18214 \newline
18215 \InsetSpace ~
18216 \InsetSpace ~
18217 \InsetSpace ~
18218 \InsetSpace ~
18219 mov\InsetSpace ~
18220 \InsetSpace ~
18221 dph,#0x00 
18222 \newline
18223 \InsetSpace ~
18224 \InsetSpace ~
18225 \InsetSpace ~
18226 \InsetSpace ~
18227 mov\InsetSpace ~
18228 \InsetSpace ~
18229 sp,_bp 
18230 \newline
18231 \InsetSpace ~
18232 \InsetSpace ~
18233 \InsetSpace ~
18234 \InsetSpace ~
18235 pop\InsetSpace ~
18236 \InsetSpace ~
18237 _bp 
18238 \newline
18239 \InsetSpace ~
18240 \InsetSpace ~
18241 \InsetSpace ~
18242 \InsetSpace ~
18243 ret
18244 \end_layout
18245
18246 \begin_layout Standard
18247 The compiling and linking procedure remains the same, however note the extra
18248  entry & exit linkage required for the assembler code, _bp is the stack
18249  frame pointer and is used to compute the offset into the stack for parameters
18250  and local variables.
18251 \begin_inset VSpace bigskip
18252 \end_inset
18253
18254
18255 \end_layout
18256
18257 \begin_layout Section
18258 int (16 bit)
18259 \begin_inset LatexCommand \index{int (16 bit)}
18260
18261 \end_inset
18262
18263  and long (32 bit)
18264 \begin_inset LatexCommand \index{long (32 bit)}
18265
18266 \end_inset
18267
18268  Support
18269 \end_layout
18270
18271 \begin_layout Standard
18272 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
18273  multiplication and modulus operations are implemented by support routines.
18274  These support routines are all developed in ANSI-C to facilitate porting
18275  to other MCUs, although some model specific assembler optimizations are
18276  used.
18277  The following files contain the described routines, all of them can be
18278  found in <installdir>/share/sdcc/lib.
18279 \newline
18280
18281 \end_layout
18282
18283 \begin_layout Standard
18284 \align center
18285 \begin_inset Tabular
18286 <lyxtabular version="3" rows="11" columns="2">
18287 <features>
18288 <column alignment="left" valignment="top" leftline="true" width="0">
18289 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18290 <row topline="true" bottomline="true">
18291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18292 \begin_inset Text
18293
18294 \begin_layout Standard
18295
18296 \series bold
18297 Function
18298 \end_layout
18299
18300 \end_inset
18301 </cell>
18302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18303 \begin_inset Text
18304
18305 \begin_layout Standard
18306
18307 \series bold
18308 Description
18309 \end_layout
18310
18311 \end_inset
18312 </cell>
18313 </row>
18314 <row topline="true">
18315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18316 \begin_inset Text
18317
18318 \begin_layout Standard
18319 _mulint.c 
18320 \end_layout
18321
18322 \end_inset
18323 </cell>
18324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18325 \begin_inset Text
18326
18327 \begin_layout Standard
18328 16 bit multiplication
18329 \end_layout
18330
18331 \end_inset
18332 </cell>
18333 </row>
18334 <row topline="true">
18335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18336 \begin_inset Text
18337
18338 \begin_layout Standard
18339 _divsint.c 
18340 \end_layout
18341
18342 \end_inset
18343 </cell>
18344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18345 \begin_inset Text
18346
18347 \begin_layout Standard
18348  signed 16 bit division (calls _divuint)
18349 \end_layout
18350
18351 \end_inset
18352 </cell>
18353 </row>
18354 <row topline="true">
18355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18356 \begin_inset Text
18357
18358 \begin_layout Standard
18359 _divuint.c 
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  unsigned 16 bit division
18369 \end_layout
18370
18371 \end_inset
18372 </cell>
18373 </row>
18374 <row topline="true">
18375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18376 \begin_inset Text
18377
18378 \begin_layout Standard
18379 _modsint.c
18380 \end_layout
18381
18382 \end_inset
18383 </cell>
18384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18385 \begin_inset Text
18386
18387 \begin_layout Standard
18388 signed 16 bit modulus (calls _moduint)
18389 \end_layout
18390
18391 \end_inset
18392 </cell>
18393 </row>
18394 <row topline="true">
18395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18396 \begin_inset Text
18397
18398 \begin_layout Standard
18399 _moduint.c
18400 \end_layout
18401
18402 \end_inset
18403 </cell>
18404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18405 \begin_inset Text
18406
18407 \begin_layout Standard
18408 unsigned 16 bit modulus
18409 \end_layout
18410
18411 \end_inset
18412 </cell>
18413 </row>
18414 <row topline="true">
18415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18416 \begin_inset Text
18417
18418 \begin_layout Standard
18419 _mullong.c
18420 \end_layout
18421
18422 \end_inset
18423 </cell>
18424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18425 \begin_inset Text
18426
18427 \begin_layout Standard
18428 32 bit multiplication
18429 \end_layout
18430
18431 \end_inset
18432 </cell>
18433 </row>
18434 <row topline="true">
18435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18436 \begin_inset Text
18437
18438 \begin_layout Standard
18439 _divslong.c 
18440 \end_layout
18441
18442 \end_inset
18443 </cell>
18444 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18445 \begin_inset Text
18446
18447 \begin_layout Standard
18448  signed 32 division (calls _divulong)
18449 \end_layout
18450
18451 \end_inset
18452 </cell>
18453 </row>
18454 <row topline="true">
18455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18456 \begin_inset Text
18457
18458 \begin_layout Standard
18459 _divulong.c 
18460 \end_layout
18461
18462 \end_inset
18463 </cell>
18464 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18465 \begin_inset Text
18466
18467 \begin_layout Standard
18468 unsigned 32 division
18469 \end_layout
18470
18471 \end_inset
18472 </cell>
18473 </row>
18474 <row topline="true">
18475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18476 \begin_inset Text
18477
18478 \begin_layout Standard
18479 _modslong.c
18480 \end_layout
18481
18482 \end_inset
18483 </cell>
18484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18485 \begin_inset Text
18486
18487 \begin_layout Standard
18488  signed 32 bit modulus (calls _modulong)
18489 \end_layout
18490
18491 \end_inset
18492 </cell>
18493 </row>
18494 <row topline="true" bottomline="true">
18495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18496 \begin_inset Text
18497
18498 \begin_layout Standard
18499 _modulong.c
18500 \end_layout
18501
18502 \end_inset
18503 </cell>
18504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18505 \begin_inset Text
18506
18507 \begin_layout Standard
18508 unsigned 32 bit modulus
18509 \end_layout
18510
18511 \end_inset
18512 </cell>
18513 </row>
18514 </lyxtabular>
18515
18516 \end_inset
18517
18518
18519 \newline
18520
18521 \end_layout
18522
18523 \begin_layout Standard
18524 Since they are compiled as 
18525 \emph on
18526 non-reentrant
18527 \emph default
18528
18529 \begin_inset LatexCommand \index{reentrant}
18530
18531 \end_inset
18532
18533 , interrupt
18534 \begin_inset LatexCommand \index{interrupt}
18535
18536 \end_inset
18537
18538  service routines should not do any of the above operations.
18539  If this is unavoidable then the above routines will need to be compiled
18540  with the 
18541 \emph on
18542 -
18543 \begin_inset ERT
18544 status collapsed
18545
18546 \begin_layout Standard
18547
18548
18549 \backslash
18550 /
18551 \end_layout
18552
18553 \end_inset
18554
18555 -stack-auto
18556 \begin_inset LatexCommand \index{-\/-stack-auto}
18557
18558 \end_inset
18559
18560
18561 \emph default
18562  option, after which the source program will have to be compiled with 
18563 \emph on
18564 -
18565 \begin_inset ERT
18566 status collapsed
18567
18568 \begin_layout Standard
18569
18570
18571 \backslash
18572 /
18573 \end_layout
18574
18575 \end_inset
18576
18577 -int-long-reent
18578 \begin_inset LatexCommand \index{-\/-int-long-reent}
18579
18580 \end_inset
18581
18582
18583 \emph default
18584  option.
18585  Notice that you don't have to call these routines directly.
18586  The compiler will use them automatically every time an integer operation
18587  is required.
18588 \end_layout
18589
18590 \begin_layout Section
18591 Floating Point Support
18592 \begin_inset LatexCommand \index{Floating point support}
18593
18594 \end_inset
18595
18596
18597 \end_layout
18598
18599 \begin_layout Standard
18600 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
18601  The floating point support routines are derived from gcc's floatlib.c and
18602  consist of the following routines:
18603 \newline
18604
18605 \end_layout
18606
18607 \begin_layout Standard
18608 \align center
18609
18610 \size footnotesize
18611 \begin_inset Tabular
18612 <lyxtabular version="3" rows="17" columns="2">
18613 <features>
18614 <column alignment="left" valignment="top" leftline="true" width="0">
18615 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18616 <row topline="true" bottomline="true">
18617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18618 \begin_inset Text
18619
18620 \begin_layout Standard
18621
18622 \family roman
18623 \series medium
18624 \shape up
18625 \size normal
18626 \emph off
18627 \bar no
18628 \noun off
18629 \color none
18630 Function 
18631 \end_layout
18632
18633 \end_inset
18634 </cell>
18635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18636 \begin_inset Text
18637
18638 \begin_layout Standard
18639 Description
18640 \end_layout
18641
18642 \end_inset
18643 </cell>
18644 </row>
18645 <row topline="true">
18646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18647 \begin_inset Text
18648
18649 \begin_layout Standard
18650
18651 \family roman
18652 \series medium
18653 \shape up
18654 \size normal
18655 \emph off
18656 \bar no
18657 \noun off
18658 \color none
18659 _fsadd.c
18660 \end_layout
18661
18662 \end_inset
18663 </cell>
18664 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18665 \begin_inset Text
18666
18667 \begin_layout Standard
18668
18669 \family roman
18670 \series medium
18671 \shape up
18672 \size normal
18673 \emph off
18674 \bar no
18675 \noun off
18676 \color none
18677 add floating point numbers
18678 \end_layout
18679
18680 \end_inset
18681 </cell>
18682 </row>
18683 <row topline="true">
18684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18685 \begin_inset Text
18686
18687 \begin_layout Standard
18688
18689 \family roman
18690 \series medium
18691 \shape up
18692 \size normal
18693 \emph off
18694 \bar no
18695 \noun off
18696 \color none
18697 _fssub.c 
18698 \end_layout
18699
18700 \end_inset
18701 </cell>
18702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18703 \begin_inset Text
18704
18705 \begin_layout Standard
18706
18707 \family roman
18708 \series medium
18709 \shape up
18710 \size normal
18711 \emph off
18712 \bar no
18713 \noun off
18714 \color none
18715 subtract floating point numbers 
18716 \end_layout
18717
18718 \end_inset
18719 </cell>
18720 </row>
18721 <row topline="true">
18722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18723 \begin_inset Text
18724
18725 \begin_layout Standard
18726
18727 \family roman
18728 \series medium
18729 \shape up
18730 \size normal
18731 \emph off
18732 \bar no
18733 \noun off
18734 \color none
18735 _fsdiv.c 
18736 \end_layout
18737
18738 \end_inset
18739 </cell>
18740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18741 \begin_inset Text
18742
18743 \begin_layout Standard
18744
18745 \family roman
18746 \series medium
18747 \shape up
18748 \size normal
18749 \emph off
18750 \bar no
18751 \noun off
18752 \color none
18753 divide floating point numbers 
18754 \end_layout
18755
18756 \end_inset
18757 </cell>
18758 </row>
18759 <row topline="true">
18760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18761 \begin_inset Text
18762
18763 \begin_layout Standard
18764
18765 \family roman
18766 \series medium
18767 \shape up
18768 \size normal
18769 \emph off
18770 \bar no
18771 \noun off
18772 \color none
18773 _fsmul.c 
18774 \end_layout
18775
18776 \end_inset
18777 </cell>
18778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18779 \begin_inset Text
18780
18781 \begin_layout Standard
18782
18783 \family roman
18784 \series medium
18785 \shape up
18786 \size normal
18787 \emph off
18788 \bar no
18789 \noun off
18790 \color none
18791 multiply floating point numbers 
18792 \end_layout
18793
18794 \end_inset
18795 </cell>
18796 </row>
18797 <row topline="true">
18798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18799 \begin_inset Text
18800
18801 \begin_layout Standard
18802
18803 \family roman
18804 \series medium
18805 \shape up
18806 \size normal
18807 \emph off
18808 \bar no
18809 \noun off
18810 \color none
18811 _fs2uchar.c
18812 \end_layout
18813
18814 \end_inset
18815 </cell>
18816 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18817 \begin_inset Text
18818
18819 \begin_layout Standard
18820
18821 \family roman
18822 \series medium
18823 \shape up
18824 \size normal
18825 \emph off
18826 \bar no
18827 \noun off
18828 \color none
18829 convert floating point to unsigned char
18830 \end_layout
18831
18832 \end_inset
18833 </cell>
18834 </row>
18835 <row topline="true">
18836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18837 \begin_inset Text
18838
18839 \begin_layout Standard
18840
18841 \family roman
18842 \series medium
18843 \shape up
18844 \size normal
18845 \emph off
18846 \bar no
18847 \noun off
18848 \color none
18849 _fs2char.c
18850 \end_layout
18851
18852 \end_inset
18853 </cell>
18854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18855 \begin_inset Text
18856
18857 \begin_layout Standard
18858
18859 \family roman
18860 \series medium
18861 \shape up
18862 \size normal
18863 \emph off
18864 \bar no
18865 \noun off
18866 \color none
18867 convert floating point to signed char
18868 \end_layout
18869
18870 \end_inset
18871 </cell>
18872 </row>
18873 <row topline="true">
18874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18875 \begin_inset Text
18876
18877 \begin_layout Standard
18878
18879 \family roman
18880 \series medium
18881 \shape up
18882 \size normal
18883 \emph off
18884 \bar no
18885 \noun off
18886 \color none
18887 _fs2uint.c
18888 \end_layout
18889
18890 \end_inset
18891 </cell>
18892 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18893 \begin_inset Text
18894
18895 \begin_layout Standard
18896
18897 \family roman
18898 \series medium
18899 \shape up
18900 \size normal
18901 \emph off
18902 \bar no
18903 \noun off
18904 \color none
18905 convert floating point to unsigned int
18906 \end_layout
18907
18908 \end_inset
18909 </cell>
18910 </row>
18911 <row topline="true">
18912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18913 \begin_inset Text
18914
18915 \begin_layout Standard
18916
18917 \family roman
18918 \series medium
18919 \shape up
18920 \size normal
18921 \emph off
18922 \bar no
18923 \noun off
18924 \color none
18925 _fs2int.c
18926 \end_layout
18927
18928 \end_inset
18929 </cell>
18930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18931 \begin_inset Text
18932
18933 \begin_layout Standard
18934
18935 \family roman
18936 \series medium
18937 \shape up
18938 \size normal
18939 \emph off
18940 \bar no
18941 \noun off
18942 \color none
18943 convert floating point to signed int
18944 \end_layout
18945
18946 \end_inset
18947 </cell>
18948 </row>
18949 <row topline="true">
18950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18951 \begin_inset Text
18952
18953 \begin_layout Standard
18954
18955 \family roman
18956 \series medium
18957 \shape up
18958 \size normal
18959 \emph off
18960 \bar no
18961 \noun off
18962 \color none
18963 _fs2ulong.
18964 \family default
18965 \series default
18966 \shape default
18967 \size default
18968 \emph default
18969 \bar default
18970 \noun default
18971 c
18972 \end_layout
18973
18974 \end_inset
18975 </cell>
18976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18977 \begin_inset Text
18978
18979 \begin_layout Standard
18980
18981 \family roman
18982 \series medium
18983 \shape up
18984 \size normal
18985 \emph off
18986 \bar no
18987 \noun off
18988 \color none
18989 convert floating point to unsigned long
18990 \end_layout
18991
18992 \end_inset
18993 </cell>
18994 </row>
18995 <row topline="true">
18996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18997 \begin_inset Text
18998
18999 \begin_layout Standard
19000
19001 \family roman
19002 \series medium
19003 \shape up
19004 \size normal
19005 \emph off
19006 \bar no
19007 \noun off
19008 \color none
19009 _fs2long.c
19010 \end_layout
19011
19012 \end_inset
19013 </cell>
19014 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19015 \begin_inset Text
19016
19017 \begin_layout Standard
19018
19019 \family roman
19020 \series medium
19021 \shape up
19022 \size normal
19023 \emph off
19024 \bar no
19025 \noun off
19026 \color none
19027 convert floating point to signed long
19028 \end_layout
19029
19030 \end_inset
19031 </cell>
19032 </row>
19033 <row topline="true">
19034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19035 \begin_inset Text
19036
19037 \begin_layout Standard
19038
19039 \family roman
19040 \series medium
19041 \shape up
19042 \size normal
19043 \emph off
19044 \bar no
19045 \noun off
19046 \color none
19047 _uchar2fs.c
19048 \end_layout
19049
19050 \end_inset
19051 </cell>
19052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19053 \begin_inset Text
19054
19055 \begin_layout Standard
19056
19057 \family roman
19058 \series medium
19059 \shape up
19060 \size normal
19061 \emph off
19062 \bar no
19063 \noun off
19064 \color none
19065 convert unsigned char to floating point
19066 \end_layout
19067
19068 \end_inset
19069 </cell>
19070 </row>
19071 <row topline="true">
19072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19073 \begin_inset Text
19074
19075 \begin_layout Standard
19076
19077 \family roman
19078 \series medium
19079 \shape up
19080 \size normal
19081 \emph off
19082 \bar no
19083 \noun off
19084 \color none
19085 _char2fs.c
19086 \end_layout
19087
19088 \end_inset
19089 </cell>
19090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19091 \begin_inset Text
19092
19093 \begin_layout Standard
19094
19095 \family roman
19096 \series medium
19097 \shape up
19098 \size normal
19099 \emph off
19100 \bar no
19101 \noun off
19102 \color none
19103 convert char to floating point number
19104 \end_layout
19105
19106 \end_inset
19107 </cell>
19108 </row>
19109 <row topline="true">
19110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19111 \begin_inset Text
19112
19113 \begin_layout Standard
19114
19115 \family roman
19116 \series medium
19117 \shape up
19118 \size normal
19119 \emph off
19120 \bar no
19121 \noun off
19122 \color none
19123 _uint2fs.c
19124 \end_layout
19125
19126 \end_inset
19127 </cell>
19128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19129 \begin_inset Text
19130
19131 \begin_layout Standard
19132
19133 \family roman
19134 \series medium
19135 \shape up
19136 \size normal
19137 \emph off
19138 \bar no
19139 \noun off
19140 \color none
19141 convert unsigned int to floating point
19142 \end_layout
19143
19144 \end_inset
19145 </cell>
19146 </row>
19147 <row topline="true">
19148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19149 \begin_inset Text
19150
19151 \begin_layout Standard
19152
19153 \family roman
19154 \series medium
19155 \shape up
19156 \size normal
19157 \emph off
19158 \bar no
19159 \noun off
19160 \color none
19161 _int2fs.c
19162 \end_layout
19163
19164 \end_inset
19165 </cell>
19166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19167 \begin_inset Text
19168
19169 \begin_layout Standard
19170
19171 \family roman
19172 \series medium
19173 \shape up
19174 \size normal
19175 \emph off
19176 \bar no
19177 \noun off
19178 \color none
19179 convert int to floating point numbers
19180 \end_layout
19181
19182 \end_inset
19183 </cell>
19184 </row>
19185 <row topline="true">
19186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19187 \begin_inset Text
19188
19189 \begin_layout Standard
19190
19191 \family roman
19192 \series medium
19193 \shape up
19194 \size normal
19195 \emph off
19196 \bar no
19197 \noun off
19198 \color none
19199 _ulong2fs.c
19200 \end_layout
19201
19202 \end_inset
19203 </cell>
19204 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19205 \begin_inset Text
19206
19207 \begin_layout Standard
19208
19209 \family roman
19210 \series medium
19211 \shape up
19212 \size normal
19213 \emph off
19214 \bar no
19215 \noun off
19216 \color none
19217 convert unsigned long to floating point number
19218 \end_layout
19219
19220 \end_inset
19221 </cell>
19222 </row>
19223 <row topline="true" bottomline="true">
19224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19225 \begin_inset Text
19226
19227 \begin_layout Standard
19228
19229 \family roman
19230 \series medium
19231 \shape up
19232 \size normal
19233 \emph off
19234 \bar no
19235 \noun off
19236 \color none
19237 _long2fs.c
19238 \end_layout
19239
19240 \end_inset
19241 </cell>
19242 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19243 \begin_inset Text
19244
19245 \begin_layout Standard
19246
19247 \family roman
19248 \series medium
19249 \shape up
19250 \size normal
19251 \emph off
19252 \bar no
19253 \noun off
19254 \color none
19255 convert long to floating point number
19256 \end_layout
19257
19258 \end_inset
19259 </cell>
19260 </row>
19261 </lyxtabular>
19262
19263 \end_inset
19264
19265
19266 \newline
19267
19268 \end_layout
19269
19270 \begin_layout Standard
19271 These support routines are developed in ANSI-C so there is room for space
19272  and speed improvement
19273 \begin_inset Foot
19274 status open
19275
19276 \begin_layout Standard
19277 These floating point routines (
19278 \emph on
19279 not
19280 \emph default
19281  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
19282  
19283 \end_layout
19284
19285 \end_inset
19286
19287 .
19288  Note if all these routines are used simultaneously the data space might
19289  overflow.
19290  For serious floating point usage the large model might be needed.
19291  Also notice that you don't have to call this routines directly.
19292  The compiler will use them automatically every time a floating point operation
19293  is required.
19294 \begin_inset VSpace bigskip
19295 \end_inset
19296
19297
19298 \end_layout
19299
19300 \begin_layout Section
19301 Library Routines
19302 \begin_inset LatexCommand \index{Libraries}
19303
19304 \end_inset
19305
19306
19307 \end_layout
19308
19309 \begin_layout Standard
19310
19311 \emph on
19312 <pending: this is messy and incomplete - a little more information is in
19313  sdcc/doc/libdoc.txt
19314 \emph default
19315  >
19316 \end_layout
19317
19318 \begin_layout Subsection
19319 Compiler support routines (_gptrget, _mulint etc.)
19320 \end_layout
19321
19322 \begin_layout Subsection
19323 Stdclib functions (puts, printf, strcat etc.)
19324 \end_layout
19325
19326 \begin_layout Subsubsection
19327 <stdio.h>
19328 \end_layout
19329
19330 \begin_layout Paragraph
19331 getchar(), putchar()
19332 \end_layout
19333
19334 \begin_layout Standard
19335 \begin_inset LatexCommand \index{<stdio.h>}
19336
19337 \end_inset
19338
19339 As usual on embedded systems you have to provide your own 
19340 \family typewriter
19341 getchar()
19342 \begin_inset LatexCommand \index{getchar()}
19343
19344 \end_inset
19345
19346  
19347 \family default
19348 and 
19349 \family typewriter
19350 putchar()
19351 \begin_inset LatexCommand \index{putchar()}
19352
19353 \end_inset
19354
19355
19356 \family default
19357  routines.
19358  SDCC does not know whether the system connects to a serial line with or
19359  without handshake, LCD, keyboard or other device.
19360  And whether a 
19361 \family typewriter
19362 lf
19363 \family default
19364  to 
19365 \family typewriter
19366 crlf
19367 \family default
19368  conversion within 
19369 \family typewriter
19370 putchar()
19371 \family default
19372  is intended.
19373  You'll find examples for serial routines f.e.
19374  in sdcc/device/lib.
19375  For the mcs51 this minimalistic polling 
19376 \family typewriter
19377 putchar()
19378 \family default
19379  routine might be a start:
19380 \end_layout
19381
19382 \begin_layout Verse
19383
19384 \family typewriter
19385 void putchar (char c) { 
19386 \newline
19387 \InsetSpace ~
19388 \InsetSpace ~
19389 \InsetSpace ~
19390 \InsetSpace ~
19391 while (!TI)\InsetSpace ~
19392 \InsetSpace ~
19393 \InsetSpace ~
19394  /* assumes UART is initialized */
19395 \newline
19396 \InsetSpace ~
19397 \InsetSpace ~
19398 \InsetSpace ~
19399 \InsetSpace ~
19400 \InsetSpace ~
19401 \InsetSpace ~
19402 \InsetSpace ~
19403 \InsetSpace ~
19404 ;
19405 \newline
19406 \InsetSpace ~
19407 \InsetSpace ~
19408 \InsetSpace ~
19409 \InsetSpace ~
19410 TI
19411  = 0;
19412 \newline
19413 \InsetSpace ~
19414 \InsetSpace ~
19415 \InsetSpace ~
19416 \InsetSpace ~
19417 SBUF = c;
19418 \newline
19419 }
19420 \end_layout
19421
19422 \begin_layout Paragraph
19423 printf()
19424 \end_layout
19425
19426 \begin_layout Standard
19427 The default
19428 \family typewriter
19429  printf()
19430 \begin_inset LatexCommand \index{printf()}
19431
19432 \end_inset
19433
19434
19435 \family default
19436  implementation in
19437 \family typewriter
19438  printf_large.c
19439 \family default
19440  does not support float (except on ds390).
19441  To enable this recompile it with the option 
19442 \emph on
19443 -
19444 \begin_inset ERT
19445 status collapsed
19446
19447 \begin_layout Standard
19448
19449
19450 \backslash
19451 /
19452 \end_layout
19453
19454 \end_inset
19455
19456 DUSE_FLOATS=1
19457 \begin_inset LatexCommand \index{USE\_FLOATS}
19458
19459 \end_inset
19460
19461
19462 \emph default
19463  on the command line.
19464  Use
19465 \emph on
19466  -
19467 \begin_inset ERT
19468 status collapsed
19469
19470 \begin_layout Standard
19471
19472
19473 \backslash
19474 /
19475 \end_layout
19476
19477 \end_inset
19478
19479 -model-large
19480 \begin_inset LatexCommand \index{-\/-model-large}
19481
19482 \end_inset
19483
19484
19485 \emph default
19486  for the mcs51 port, since this uses a lot of memory.
19487 \end_layout
19488
19489 \begin_layout Standard
19490 If you're short on code memory you might want to use 
19491 \family typewriter
19492 printf_small()
19493 \begin_inset LatexCommand \index{printf\_small()}
19494
19495 \end_inset
19496
19497
19498 \family default
19499  
19500 \emph on
19501 instead
19502 \emph default
19503  of
19504 \family typewriter
19505  printf().
19506
19507 \family default
19508  For the mcs51 there additionally are assembly versions 
19509 \family typewriter
19510 printf_tiny()
19511 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19512
19513 \end_inset
19514
19515
19516 \family default
19517  (subset of printf using less than 270 bytes) and 
19518 \family typewriter
19519 printf_fast()
19520 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19521
19522 \end_inset
19523
19524  
19525 \family default
19526 and
19527 \family typewriter
19528  printf_fast_f()
19529 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19530
19531 \end_inset
19532
19533
19534 \family default
19535  (floating-point aware version of printf_fast) which should fit the requirements
19536  of many embedded systems (printf_fast() can be customized by unsetting
19537  #defines to 
19538 \emph on
19539 not
19540 \emph default
19541  support long variables and field widths).
19542  Be sure to use only one of these printf options within a project.
19543 \newline
19544
19545 \end_layout
19546
19547 \begin_layout Standard
19548 Feature matrix of different 
19549 \emph on
19550 printf
19551 \emph default
19552  options on mcs51.
19553 \end_layout
19554
19555 \begin_layout Standard
19556 \begin_inset Tabular
19557 <lyxtabular version="3" rows="14" columns="7">
19558 <features islongtable="true">
19559 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19560 <column alignment="center" valignment="top" leftline="true" width="0">
19561 <column alignment="center" valignment="top" leftline="true" width="12col%">
19562 <column alignment="center" valignment="top" leftline="true" width="10col%">
19563 <column alignment="center" valignment="top" leftline="true" width="0">
19564 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19565 <column alignment="center" valignment="top" rightline="true" width="0">
19566 <row topline="true" bottomline="true" endhead="true">
19567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19568 \begin_inset Text
19569
19570 \begin_layout Standard
19571
19572 \series bold
19573 \size large
19574 mcs51
19575 \end_layout
19576
19577 \end_inset
19578 </cell>
19579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19580 \begin_inset Text
19581
19582 \begin_layout Standard
19583 printf
19584 \begin_inset LatexCommand \index{printf}
19585
19586 \end_inset
19587
19588
19589 \end_layout
19590
19591 \end_inset
19592 </cell>
19593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19594 \begin_inset Text
19595
19596 \begin_layout Standard
19597 printf 
19598 \size scriptsize
19599 USE_FLOATS=1
19600 \end_layout
19601
19602 \end_inset
19603 </cell>
19604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19605 \begin_inset Text
19606
19607 \begin_layout Standard
19608 printf_small
19609 \end_layout
19610
19611 \end_inset
19612 </cell>
19613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19614 \begin_inset Text
19615
19616 \begin_layout Standard
19617 printf_fast
19618 \end_layout
19619
19620 \end_inset
19621 </cell>
19622 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19623 \begin_inset Text
19624
19625 \begin_layout Standard
19626 printf_fast_f
19627 \end_layout
19628
19629 \end_inset
19630 </cell>
19631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19632 \begin_inset Text
19633
19634 \begin_layout Standard
19635 printf_tiny
19636 \end_layout
19637
19638 \end_inset
19639 </cell>
19640 </row>
19641 <row topline="true" endhead="true">
19642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19643 \begin_inset Text
19644
19645 \begin_layout Standard
19646 filename
19647 \end_layout
19648
19649 \end_inset
19650 </cell>
19651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19652 \begin_inset Text
19653
19654 \begin_layout Standard
19655
19656 \size scriptsize
19657 printf_large.c
19658 \end_layout
19659
19660 \end_inset
19661 </cell>
19662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19663 \begin_inset Text
19664
19665 \begin_layout Standard
19666
19667 \size scriptsize
19668 printf_large.c
19669 \end_layout
19670
19671 \end_inset
19672 </cell>
19673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19674 \begin_inset Text
19675
19676 \begin_layout Standard
19677
19678 \size scriptsize
19679 printfl.c
19680 \end_layout
19681
19682 \end_inset
19683 </cell>
19684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19685 \begin_inset Text
19686
19687 \begin_layout Standard
19688
19689 \size scriptsize
19690 printf_fast.c
19691 \end_layout
19692
19693 \end_inset
19694 </cell>
19695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19696 \begin_inset Text
19697
19698 \begin_layout Standard
19699
19700 \size scriptsize
19701 printf_fast_f.c
19702 \end_layout
19703
19704 \end_inset
19705 </cell>
19706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19707 \begin_inset Text
19708
19709 \begin_layout Standard
19710
19711 \size scriptsize
19712 printf_tiny.c
19713 \end_layout
19714
19715 \end_inset
19716 </cell>
19717 </row>
19718 <row topline="true" endhead="true">
19719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19720 \begin_inset Text
19721
19722 \begin_layout Standard
19723 \begin_inset Quotes sld
19724 \end_inset
19725
19726 Hello World
19727 \begin_inset Quotes srd
19728 \end_inset
19729
19730  size
19731 \end_layout
19732
19733 \begin_layout Standard
19734 small / large
19735 \end_layout
19736
19737 \end_inset
19738 </cell>
19739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19740 \begin_inset Text
19741
19742 \begin_layout Standard
19743 1.7k / 2.4k
19744 \end_layout
19745
19746 \end_inset
19747 </cell>
19748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19749 \begin_inset Text
19750
19751 \begin_layout Standard
19752 4.3k / 5.6k
19753 \end_layout
19754
19755 \end_inset
19756 </cell>
19757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19758 \begin_inset Text
19759
19760 \begin_layout Standard
19761 1.2k / 1.8k
19762 \end_layout
19763
19764 \end_inset
19765 </cell>
19766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19767 \begin_inset Text
19768
19769 \begin_layout Standard
19770 1.3k / 1.3k
19771 \end_layout
19772
19773 \end_inset
19774 </cell>
19775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19776 \begin_inset Text
19777
19778 \begin_layout Standard
19779 1.9k / 1.9k
19780 \end_layout
19781
19782 \end_inset
19783 </cell>
19784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19785 \begin_inset Text
19786
19787 \begin_layout Standard
19788 0.44k / 0.44k
19789 \end_layout
19790
19791 \end_inset
19792 </cell>
19793 </row>
19794 <row topline="true" endhead="true">
19795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19796 \begin_inset Text
19797
19798 \begin_layout Standard
19799 code size
19800 \end_layout
19801
19802 \begin_layout Standard
19803 small / large
19804 \end_layout
19805
19806 \end_inset
19807 </cell>
19808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19809 \begin_inset Text
19810
19811 \begin_layout Standard
19812 1.4k / 2.0k
19813 \end_layout
19814
19815 \end_inset
19816 </cell>
19817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19818 \begin_inset Text
19819
19820 \begin_layout Standard
19821 2.8k / 3.7k
19822 \end_layout
19823
19824 \end_inset
19825 </cell>
19826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19827 \begin_inset Text
19828
19829 \begin_layout Standard
19830 0.45k / 0.47k (+ _ltoa)
19831 \end_layout
19832
19833 \end_inset
19834 </cell>
19835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19836 \begin_inset Text
19837
19838 \begin_layout Standard
19839 1.2k / 1.2k
19840 \end_layout
19841
19842 \end_inset
19843 </cell>
19844 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19845 \begin_inset Text
19846
19847 \begin_layout Standard
19848 1.6k / 1.6k
19849 \end_layout
19850
19851 \end_inset
19852 </cell>
19853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19854 \begin_inset Text
19855
19856 \begin_layout Standard
19857 0.26k / 0.26k
19858 \end_layout
19859
19860 \end_inset
19861 </cell>
19862 </row>
19863 <row topline="true">
19864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19865 \begin_inset Text
19866
19867 \begin_layout Standard
19868 formats
19869 \end_layout
19870
19871 \end_inset
19872 </cell>
19873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19874 \begin_inset Text
19875
19876 \begin_layout Standard
19877 cdi
19878 \emph on
19879 o
19880 \emph default
19881 psux
19882 \end_layout
19883
19884 \end_inset
19885 </cell>
19886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19887 \begin_inset Text
19888
19889 \begin_layout Standard
19890
19891 \family roman
19892 \series medium
19893 \shape up
19894 \size normal
19895 \emph off
19896 \bar no
19897 \noun off
19898 \color none
19899 cd
19900 \family default
19901 \series default
19902 \shape default
19903 \size default
19904 \emph default
19905 \bar default
19906 \noun default
19907 f
19908 \family roman
19909 \series medium
19910 \shape up
19911 \size normal
19912 \emph off
19913 \bar no
19914 \noun off
19915 i
19916 \family default
19917 \series default
19918 \shape default
19919 \size default
19920 \emph on
19921 \bar default
19922 \noun default
19923 o
19924 \family roman
19925 \series medium
19926 \shape up
19927 \size normal
19928 \emph off
19929 \bar no
19930 \noun off
19931 psux
19932 \end_layout
19933
19934 \end_inset
19935 </cell>
19936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19937 \begin_inset Text
19938
19939 \begin_layout Standard
19940 c
19941 \family roman
19942 \series medium
19943 \shape up
19944 \size normal
19945 \emph off
19946 \bar no
19947 \noun off
19948 \color none
19949 d
19950 \family default
19951 \series default
19952 \shape default
19953 \size default
19954 \emph on
19955 \bar default
19956 \noun default
19957 o
19958 \family roman
19959 \series medium
19960 \shape up
19961 \size normal
19962 \emph off
19963 \bar no
19964 \noun off
19965 s
19966 \family default
19967 \series default
19968 \shape default
19969 \size default
19970 \emph default
19971 \bar default
19972 \noun default
19973 x
19974 \end_layout
19975
19976 \end_inset
19977 </cell>
19978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19979 \begin_inset Text
19980
19981 \begin_layout Standard
19982 cdsux
19983 \end_layout
19984
19985 \end_inset
19986 </cell>
19987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19988 \begin_inset Text
19989
19990 \begin_layout Standard
19991 cdfsux
19992 \end_layout
19993
19994 \end_inset
19995 </cell>
19996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19997 \begin_inset Text
19998
19999 \begin_layout Standard
20000 cdsux
20001 \end_layout
20002
20003 \end_inset
20004 </cell>
20005 </row>
20006 <row topline="true">
20007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20008 \begin_inset Text
20009
20010 \begin_layout Standard
20011 long (32 bit) support
20012 \end_layout
20013
20014 \end_inset
20015 </cell>
20016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20017 \begin_inset Text
20018
20019 \begin_layout Standard
20020 x
20021 \end_layout
20022
20023 \end_inset
20024 </cell>
20025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20026 \begin_inset Text
20027
20028 \begin_layout Standard
20029 x
20030 \end_layout
20031
20032 \end_inset
20033 </cell>
20034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20035 \begin_inset Text
20036
20037 \begin_layout Standard
20038 x
20039 \end_layout
20040
20041 \end_inset
20042 </cell>
20043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20044 \begin_inset Text
20045
20046 \begin_layout Standard
20047 x
20048 \end_layout
20049
20050 \end_inset
20051 </cell>
20052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20053 \begin_inset Text
20054
20055 \begin_layout Standard
20056
20057 \family roman
20058 \series medium
20059 \shape up
20060 \size normal
20061 \emph off
20062 \bar no
20063 \noun off
20064 \color none
20065 x
20066 \end_layout
20067
20068 \end_inset
20069 </cell>
20070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20071 \begin_inset Text
20072
20073 \begin_layout Standard
20074 -
20075 \end_layout
20076
20077 \end_inset
20078 </cell>
20079 </row>
20080 <row topline="true">
20081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20082 \begin_inset Text
20083
20084 \begin_layout Standard
20085 byte arguments on stack
20086 \end_layout
20087
20088 \end_inset
20089 </cell>
20090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20091 \begin_inset Text
20092
20093 \begin_layout Standard
20094 b
20095 \end_layout
20096
20097 \end_inset
20098 </cell>
20099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20100 \begin_inset Text
20101
20102 \begin_layout Standard
20103 b
20104 \end_layout
20105
20106 \end_inset
20107 </cell>
20108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20109 \begin_inset Text
20110
20111 \begin_layout Standard
20112 -
20113 \end_layout
20114
20115 \end_inset
20116 </cell>
20117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20118 \begin_inset Text
20119
20120 \begin_layout Standard
20121 -
20122 \end_layout
20123
20124 \end_inset
20125 </cell>
20126 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20127 \begin_inset Text
20128
20129 \begin_layout Standard
20130 -
20131 \end_layout
20132
20133 \end_inset
20134 </cell>
20135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20136 \begin_inset Text
20137
20138 \begin_layout Standard
20139 -
20140 \end_layout
20141
20142 \end_inset
20143 </cell>
20144 </row>
20145 <row topline="true">
20146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20147 \begin_inset Text
20148
20149 \begin_layout Standard
20150 float format
20151 \begin_inset LatexCommand \index{Floating point support}
20152
20153 \end_inset
20154
20155
20156 \end_layout
20157
20158 \end_inset
20159 </cell>
20160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20161 \begin_inset Text
20162
20163 \begin_layout Standard
20164 -
20165 \end_layout
20166
20167 \end_inset
20168 </cell>
20169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20170 \begin_inset Text
20171
20172 \begin_layout Standard
20173 %f
20174 \end_layout
20175
20176 \end_inset
20177 </cell>
20178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20179 \begin_inset Text
20180
20181 \begin_layout Standard
20182 -
20183 \end_layout
20184
20185 \end_inset
20186 </cell>
20187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20188 \begin_inset Text
20189
20190 \begin_layout Standard
20191 -
20192 \end_layout
20193
20194 \end_inset
20195 </cell>
20196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20197 \begin_inset Text
20198
20199 \begin_layout Standard
20200 %f
20201 \begin_inset Foot
20202 status collapsed
20203
20204 \begin_layout Standard
20205 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
20206 \end_layout
20207
20208 \end_inset
20209
20210
20211 \end_layout
20212
20213 \end_inset
20214 </cell>
20215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20216 \begin_inset Text
20217
20218 \begin_layout Standard
20219 -
20220 \end_layout
20221
20222 \end_inset
20223 </cell>
20224 </row>
20225 <row topline="true">
20226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20227 \begin_inset Text
20228
20229 \begin_layout Standard
20230 float formats %e %g
20231 \end_layout
20232
20233 \end_inset
20234 </cell>
20235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20236 \begin_inset Text
20237
20238 \begin_layout Standard
20239 -
20240 \end_layout
20241
20242 \end_inset
20243 </cell>
20244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20245 \begin_inset Text
20246
20247 \begin_layout Standard
20248 -
20249 \end_layout
20250
20251 \end_inset
20252 </cell>
20253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20254 \begin_inset Text
20255
20256 \begin_layout Standard
20257 -
20258 \end_layout
20259
20260 \end_inset
20261 </cell>
20262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20263 \begin_inset Text
20264
20265 \begin_layout Standard
20266 -
20267 \end_layout
20268
20269 \end_inset
20270 </cell>
20271 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20272 \begin_inset Text
20273
20274 \begin_layout Standard
20275 -
20276 \end_layout
20277
20278 \end_inset
20279 </cell>
20280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20281 \begin_inset Text
20282
20283 \begin_layout Standard
20284 -
20285 \end_layout
20286
20287 \end_inset
20288 </cell>
20289 </row>
20290 <row topline="true" bottomline="true">
20291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20292 \begin_inset Text
20293
20294 \begin_layout Standard
20295 field width
20296 \end_layout
20297
20298 \end_inset
20299 </cell>
20300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20301 \begin_inset Text
20302
20303 \begin_layout Standard
20304 x
20305 \end_layout
20306
20307 \end_inset
20308 </cell>
20309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20310 \begin_inset Text
20311
20312 \begin_layout Standard
20313 x
20314 \end_layout
20315
20316 \end_inset
20317 </cell>
20318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20319 \begin_inset Text
20320
20321 \begin_layout Standard
20322 -
20323 \end_layout
20324
20325 \end_inset
20326 </cell>
20327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20328 \begin_inset Text
20329
20330 \begin_layout Standard
20331 x
20332 \end_layout
20333
20334 \end_inset
20335 </cell>
20336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20337 \begin_inset Text
20338
20339 \begin_layout Standard
20340 x
20341 \end_layout
20342
20343 \end_inset
20344 </cell>
20345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20346 \begin_inset Text
20347
20348 \begin_layout Standard
20349 -
20350 \end_layout
20351
20352 \end_inset
20353 </cell>
20354 </row>
20355 <row bottomline="true">
20356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20357 \begin_inset Text
20358
20359 \begin_layout Standard
20360 string speed
20361 \begin_inset Foot
20362 status collapsed
20363
20364 \begin_layout Standard
20365 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20366 \backslash
20367 r', '
20368 \backslash
20369 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20370 \end_layout
20371
20372 \end_inset
20373
20374 ,
20375 \end_layout
20376
20377 \begin_layout Standard
20378 small / large
20379 \end_layout
20380
20381 \end_inset
20382 </cell>
20383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20384 \begin_inset Text
20385
20386 \begin_layout Standard
20387 1.52 / 2.59 ms
20388 \end_layout
20389
20390 \end_inset
20391 </cell>
20392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20393 \begin_inset Text
20394
20395 \begin_layout Standard
20396 1.53 / 2.62 ms
20397 \end_layout
20398
20399 \end_inset
20400 </cell>
20401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20402 \begin_inset Text
20403
20404 \begin_layout Standard
20405 0.92 / 0.93 ms
20406 \end_layout
20407
20408 \end_inset
20409 </cell>
20410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20411 \begin_inset Text
20412
20413 \begin_layout Standard
20414 0.45 / 0.45 ms
20415 \end_layout
20416
20417 \end_inset
20418 </cell>
20419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20420 \begin_inset Text
20421
20422 \begin_layout Standard
20423 0.46 / 0.46 ms
20424 \end_layout
20425
20426 \end_inset
20427 </cell>
20428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20429 \begin_inset Text
20430
20431 \begin_layout Standard
20432 0.45 / 0.45 ms
20433 \end_layout
20434
20435 \end_inset
20436 </cell>
20437 </row>
20438 <row bottomline="true">
20439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20440 \begin_inset Text
20441
20442 \begin_layout Standard
20443 int speed
20444 \begin_inset Foot
20445 status collapsed
20446
20447 \begin_layout Standard
20448 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20449  putchar()
20450 \end_layout
20451
20452 \end_inset
20453
20454 ,
20455 \end_layout
20456
20457 \begin_layout Standard
20458 small / large
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 3.01 / 3.61 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 3.01 / 3.61 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 3.51 / 18.13 ms
20486 \end_layout
20487
20488 \end_inset
20489 </cell>
20490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20491 \begin_inset Text
20492
20493 \begin_layout Standard
20494 0.22 / 0.22 ms
20495 \end_layout
20496
20497 \end_inset
20498 </cell>
20499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20500 \begin_inset Text
20501
20502 \begin_layout Standard
20503 0.23 / 0.23 ms
20504 \end_layout
20505
20506 \end_inset
20507 </cell>
20508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20509 \begin_inset Text
20510
20511 \begin_layout Standard
20512 0.25 / 0.25 ms
20513 \begin_inset Foot
20514 status collapsed
20515
20516 \begin_layout Standard
20517 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20518 \end_layout
20519
20520 \end_inset
20521
20522
20523 \end_layout
20524
20525 \end_inset
20526 </cell>
20527 </row>
20528 <row bottomline="true">
20529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20530 \begin_inset Text
20531
20532 \begin_layout Standard
20533 long speed
20534 \begin_inset Foot
20535 status collapsed
20536
20537 \begin_layout Standard
20538 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20539  empty putchar()
20540 \end_layout
20541
20542 \end_inset
20543
20544 ,
20545 \end_layout
20546
20547 \begin_layout Standard
20548 small / large
20549 \end_layout
20550
20551 \end_inset
20552 </cell>
20553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20554 \begin_inset Text
20555
20556 \begin_layout Standard
20557 5.37 / 6.31 ms
20558 \end_layout
20559
20560 \end_inset
20561 </cell>
20562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20563 \begin_inset Text
20564
20565 \begin_layout Standard
20566 5.37 / 6.31 ms
20567 \end_layout
20568
20569 \end_inset
20570 </cell>
20571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20572 \begin_inset Text
20573
20574 \begin_layout Standard
20575 8.71 / 40.65 ms
20576 \end_layout
20577
20578 \end_inset
20579 </cell>
20580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20581 \begin_inset Text
20582
20583 \begin_layout Standard
20584 0.40 / 0.40 ms
20585 \end_layout
20586
20587 \end_inset
20588 </cell>
20589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20590 \begin_inset Text
20591
20592 \begin_layout Standard
20593 0.40 / 0.40 ms
20594 \end_layout
20595
20596 \end_inset
20597 </cell>
20598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20599 \begin_inset Text
20600
20601 \begin_layout Standard
20602 -
20603 \end_layout
20604
20605 \end_inset
20606 </cell>
20607 </row>
20608 <row bottomline="true">
20609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20610 \begin_inset Text
20611
20612 \begin_layout Standard
20613 float speed
20614 \begin_inset Foot
20615 status collapsed
20616
20617 \begin_layout Standard
20618 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
20619  empty putchar()
20620 \end_layout
20621
20622 \end_inset
20623
20624 ,
20625 \end_layout
20626
20627 \begin_layout Standard
20628 small / large
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 -
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 7.49 / 22.47 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 -
20656 \end_layout
20657
20658 \end_inset
20659 </cell>
20660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20661 \begin_inset Text
20662
20663 \begin_layout Standard
20664 -
20665 \end_layout
20666
20667 \end_inset
20668 </cell>
20669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20670 \begin_inset Text
20671
20672 \begin_layout Standard
20673 1.04 / 1.04 ms
20674 \end_layout
20675
20676 \end_inset
20677 </cell>
20678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20679 \begin_inset Text
20680
20681 \begin_layout Standard
20682 -
20683 \end_layout
20684
20685 \end_inset
20686 </cell>
20687 </row>
20688 </lyxtabular>
20689
20690 \end_inset
20691
20692
20693 \end_layout
20694
20695 \begin_layout Subsubsection
20696 <malloc.h>
20697 \begin_inset LatexCommand \index{malloc.h}
20698
20699 \end_inset
20700
20701
20702 \end_layout
20703
20704 \begin_layout Standard
20705 As of SDCC 2.6.2 you no longer need to call an initialization routine before
20706  using dynamic memory allocation
20707 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
20708
20709 \end_inset
20710
20711  and a default heap
20712 \begin_inset LatexCommand \index{heap (malloc)}
20713
20714 \end_inset
20715
20716  space of 1024 bytes is provided for malloc to allocate memory from.
20717  If you need a different heap size you need to recompile _heap.c with the
20718  required size defined in HEAP_SIZE.
20719  It is recommended to make a copy of this file into your project directory
20720  and compile it there with:
20721 \end_layout
20722
20723 \begin_layout Verse
20724
20725 \family typewriter
20726 sdcc -c _heap.c -D HEAD_SIZE=2048
20727 \end_layout
20728
20729 \begin_layout Standard
20730 And then link it with:
20731 \end_layout
20732
20733 \begin_layout Verse
20734
20735 \family typewriter
20736 sdcc main.rel _heap.rel
20737 \end_layout
20738
20739 \begin_layout Subsection
20740 Math functions (sinf, powf, sqrtf etc.)
20741 \end_layout
20742
20743 \begin_layout Subsubsection
20744 <math.h>
20745 \end_layout
20746
20747 \begin_layout Standard
20748 See definitions in file <math.h>.
20749 \end_layout
20750
20751 \begin_layout Subsection
20752 Other libraries
20753 \end_layout
20754
20755 \begin_layout Standard
20756 Libraries
20757 \begin_inset LatexCommand \index{Libraries}
20758
20759 \end_inset
20760
20761  included in SDCC should have a license at least as liberal as the GNU Lesser
20762  General Public License
20763 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
20764
20765 \end_inset
20766
20767  
20768 \emph on
20769 LGPL
20770 \emph default
20771 .
20772 \end_layout
20773
20774 \begin_layout Standard
20775 \begin_inset Note Note
20776 status collapsed
20777
20778 \begin_layout Standard
20779 license statements for the libraries are missing.
20780  sdcc/device/lib/ser_ir.c
20781 \end_layout
20782
20783 \begin_layout Standard
20784 or _decdptr f.e.
20785  come with a GPL (as opposed to LGPL) License - this will not be liberal
20786  enough for many embedded programmers.
20787 \end_layout
20788
20789 \end_inset
20790
20791
20792 \end_layout
20793
20794 \begin_layout Standard
20795 If you have ported some library or want to share experience about some code
20796  which f.e.
20797  falls into any of these categories Busses (I
20798 \begin_inset Formula $^{\textrm{2}}$
20799 \end_inset
20800
20801 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
20802  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
20803  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
20804 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
20805
20806 \end_inset
20807
20808 \InsetSpace ~
20809 would certainly like to hear about it.
20810 \end_layout
20811
20812 \begin_layout Standard
20813 Programmers coding for embedded systems are not especially famous for being
20814  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
20815 e these references are very valuable.
20816  Let's help to create a climate where information is shared.
20817 \begin_inset VSpace bigskip
20818 \end_inset
20819
20820
20821 \end_layout
20822
20823 \begin_layout Section
20824 Memory Models
20825 \end_layout
20826
20827 \begin_layout Subsection
20828 MCS51 Memory Models
20829 \begin_inset LatexCommand \index{Memory model}
20830
20831 \end_inset
20832
20833
20834 \begin_inset LatexCommand \index{MCS51 memory model}
20835
20836 \end_inset
20837
20838
20839 \end_layout
20840
20841 \begin_layout Subsubsection
20842 Small, Medium and Large
20843 \end_layout
20844
20845 \begin_layout Standard
20846 SDCC allows three memory models for MCS51 code, 
20847 \shape slanted
20848 small, medium
20849 \shape default
20850  and 
20851 \shape slanted
20852 large
20853 \shape default
20854 .
20855  Modules compiled with different memory models should 
20856 \emph on
20857 never
20858 \emph default
20859  be combined together or the results would be unpredictable.
20860  The library routines supplied with the compiler are compiled as small,
20861  medium and large.
20862  The compiled library modules are contained in separate directories as small,
20863  medium and large so that you can link to the appropriate set.
20864 \end_layout
20865
20866 \begin_layout Standard
20867 When the medium or large model is used all variables declared without a
20868  storage class will be allocated into the external ram, this includes all
20869  parameters and local variables (for non-reentrant
20870 \begin_inset LatexCommand \index{reentrant}
20871
20872 \end_inset
20873
20874  functions).
20875  When the small model is used variables without storage class are allocated
20876  in the internal ram.
20877 \end_layout
20878
20879 \begin_layout Standard
20880 Judicious usage of the processor specific storage classes
20881 \begin_inset LatexCommand \index{Storage class}
20882
20883 \end_inset
20884
20885  and the 'reentrant' function type will yield much more efficient code,
20886  than using the large model.
20887  Several optimizations are disabled when the program is compiled using the
20888  large model, it is therefore recommended that the small model be used unless
20889  absolutely required.
20890 \end_layout
20891
20892 \begin_layout Subsubsection
20893 External Stack
20894 \begin_inset LatexCommand \label{sub:External-Stack}
20895
20896 \end_inset
20897
20898
20899 \begin_inset LatexCommand \index{stack}
20900
20901 \end_inset
20902
20903
20904 \begin_inset LatexCommand \index{External stack (mcs51)}
20905
20906 \end_inset
20907
20908
20909 \end_layout
20910
20911 \begin_layout Standard
20912 The external stack (-
20913 \begin_inset ERT
20914 status collapsed
20915
20916 \begin_layout Standard
20917
20918
20919 \backslash
20920 /
20921 \end_layout
20922
20923 \end_inset
20924
20925 -xstack option
20926 \begin_inset LatexCommand \index{-\/-xstack}
20927
20928 \end_inset
20929
20930 ) is located in pdata
20931 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20932
20933 \end_inset
20934
20935  memory (usually at the start of the external ram segment) and uses all
20936  unused space in pdata (max.
20937  256 bytes).
20938  When -
20939 \begin_inset ERT
20940 status collapsed
20941
20942 \begin_layout Standard
20943
20944
20945 \backslash
20946 /
20947 \end_layout
20948
20949 \end_inset
20950
20951 -xstack option is used to compile the program, the parameters and local
20952  variables
20953 \begin_inset LatexCommand \index{local variables}
20954
20955 \end_inset
20956
20957  of all reentrant functions are allocated in this area.
20958  This option is provided for programs with large stack space requirements.
20959  When used with the -
20960 \begin_inset ERT
20961 status collapsed
20962
20963 \begin_layout Standard
20964
20965
20966 \backslash
20967 /
20968 \end_layout
20969
20970 \end_inset
20971
20972 -stack-auto
20973 \begin_inset LatexCommand \index{-\/-stack-auto}
20974
20975 \end_inset
20976
20977  option, all parameters and local variables are allocated on the external
20978  stack (note: support libraries will need to be recompiled with the same
20979  options.
20980  There is a predefined target in the library makefile).
20981 \end_layout
20982
20983 \begin_layout Standard
20984 The compiler outputs the higher order address byte of the external ram segment
20985  into port P2
20986 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
20987
20988 \end_inset
20989
20990  (see also section 
20991 \begin_inset LatexCommand \ref{sub:MCS51-variants}
20992
20993 \end_inset
20994
20995 ), therefore when using the External Stack option, this port 
20996 \emph on
20997 may not
20998 \emph default
20999  be used by the application program.
21000 \end_layout
21001
21002 \begin_layout Subsection
21003 DS390 Memory Model
21004 \begin_inset LatexCommand \index{Memory model}
21005
21006 \end_inset
21007
21008
21009 \begin_inset LatexCommand \index{DS390 memory model}
21010
21011 \end_inset
21012
21013
21014 \end_layout
21015
21016 \begin_layout Standard
21017 The only model supported is Flat 24
21018 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
21019
21020 \end_inset
21021
21022 .
21023  This generates code for the 24 bit contiguous addressing mode of the Dallas
21024  DS80C390 part.
21025  In this mode, up to four meg of external RAM or code space can be directly
21026  addressed.
21027  See the data sheets at www.dalsemi.com for further information on this part.
21028 \newline
21029
21030 \newline
21031 Note
21032  that the compiler does not generate any code to place the processor into
21033  24 bitmode (although 
21034 \emph on
21035 tinibios
21036 \emph default
21037  in the ds390 libraries will do that for you).
21038  If you don't use 
21039 \emph on
21040 tinibios
21041 \emph default
21042
21043 \begin_inset LatexCommand \index{Tinibios (DS390)}
21044
21045 \end_inset
21046
21047 , the boot loader or similar code must ensure that the processor is in 24
21048  bit contiguous addressing mode before calling the SDCC startup code.
21049 \newline
21050
21051 \newline
21052 Like
21053  the 
21054 \emph on
21055 -
21056 \begin_inset ERT
21057 status collapsed
21058
21059 \begin_layout Standard
21060
21061
21062 \backslash
21063 /
21064 \end_layout
21065
21066 \end_inset
21067
21068 -model-large
21069 \emph default
21070  option, variables will by default be placed into the XDATA segment.
21071  
21072 \newline
21073
21074 \newline
21075 Segments may be placed anywhere in the 4 meg address space using the usual
21076  -
21077 \begin_inset ERT
21078 status collapsed
21079
21080 \begin_layout Standard
21081
21082
21083 \backslash
21084 /
21085 \end_layout
21086
21087 \end_inset
21088
21089 -*-loc options.
21090  Note that if any segments are located above 64K, the -r flag must be passed
21091  to the linker to generate the proper segment relocations, and the Intel
21092  HEX output format must be used.
21093  The -r flag can be passed to the linker by using the option 
21094 \emph on
21095 -Wl-r
21096 \emph default
21097  on the SDCC command line.
21098  However, currently the linker can not handle code segments > 64k.
21099 \end_layout
21100
21101 \begin_layout Section
21102 Pragmas
21103 \begin_inset LatexCommand \label{sec:Pragmas}
21104
21105 \end_inset
21106
21107
21108 \begin_inset LatexCommand \index{Pragmas}
21109
21110 \end_inset
21111
21112
21113 \end_layout
21114
21115 \begin_layout Standard
21116 Pragmas are used to turn on and/or off certain compiler options.
21117  Some of them are closely related to corresponding command-line options
21118  (see section 
21119 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
21120
21121 \end_inset
21122
21123 ).
21124 \newline
21125 Pragmas should be placed before and/or after a function, placing pragmas
21126  inside a function body could have unpredictable results.
21127 \newline
21128
21129 \newline
21130 SDCC supports the
21131  following #pragma directives:
21132 \end_layout
21133
21134 \begin_layout Itemize
21135
21136 \series bold
21137 save
21138 \series default
21139
21140 \begin_inset LatexCommand \index{\#pragma save}
21141
21142 \end_inset
21143
21144  - this will save most current options to the save/restore stack.
21145  See #pragma\InsetSpace ~
21146 restore.
21147 \end_layout
21148
21149 \begin_layout Itemize
21150
21151 \series bold
21152 restore
21153 \series default
21154
21155 \begin_inset LatexCommand \index{\#pragma restore}
21156
21157 \end_inset
21158
21159  - will restore saved options from the last save.
21160  saves & restores can be nested.
21161  SDCC uses a save/restore stack: save pushes current options to the stack,
21162  restore pulls current options from the stack.
21163  See #pragma\InsetSpace ~
21164 save.
21165 \newline
21166
21167 \end_layout
21168
21169 \begin_layout Itemize
21170
21171 \series bold
21172 callee_saves
21173 \series default
21174
21175 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21176
21177 \end_inset
21178
21179
21180 \begin_inset LatexCommand \index{function prologue}
21181
21182 \end_inset
21183
21184  function1[,function2[,function3...]] 
21185 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
21186
21187 \end_inset
21188
21189 - The compiler by default uses a caller saves convention for register saving
21190  across function calls, however this can cause unnecessary register pushing
21191  and popping
21192 \begin_inset LatexCommand \index{push/pop}
21193
21194 \end_inset
21195
21196  when calling small functions from larger functions.
21197  This option can be used to switch off the register saving convention for
21198  the function names specified.
21199  The compiler will not save registers when calling these functions, extra
21200  code need to be manually inserted at the entry and exit for these functions
21201  to save and restore the registers used by these functions, this can SUBSTANTIAL
21202 LY reduce code and improve run time performance of the generated code.
21203  In the future the compiler (with inter procedural analysis) may be able
21204  to determine the appropriate scheme to use for each function call.
21205  If -
21206 \begin_inset ERT
21207 status collapsed
21208
21209 \begin_layout Standard
21210
21211
21212 \backslash
21213 /
21214 \end_layout
21215
21216 \end_inset
21217
21218 -callee-saves command line option is used (see page 
21219 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
21220
21221 \end_inset
21222
21223 ), the function names specified in #pragma\InsetSpace ~
21224 callee_saves
21225 \begin_inset LatexCommand \index{\#pragma callee\_saves}
21226
21227 \end_inset
21228
21229  is appended to the list of functions specified in the command line.
21230 \end_layout
21231
21232 \begin_layout Itemize
21233
21234 \series bold
21235 exclude
21236 \series default
21237
21238 \begin_inset LatexCommand \index{\#pragma exclude}
21239
21240 \end_inset
21241
21242  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
21243  of pairs of push/pop
21244 \begin_inset LatexCommand \index{push/pop}
21245
21246 \end_inset
21247
21248  instructions in 
21249 \emph on
21250 I
21251 \emph default
21252 nterrupt
21253 \begin_inset LatexCommand \index{interrupt}
21254
21255 \end_inset
21256
21257  
21258 \emph on
21259 S
21260 \emph default
21261 ervice 
21262 \emph on
21263 R
21264 \emph default
21265 outines.
21266  The directive should be placed immediately before the ISR function definition
21267  and it affects ALL ISR functions following it.
21268  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
21269 exclude\InsetSpace ~
21270 none
21271 \begin_inset LatexCommand \index{\#pragma exclude}
21272
21273 \end_inset
21274
21275 .
21276  See also the related keyword _naked
21277 \begin_inset LatexCommand \index{\_naked}
21278
21279 \end_inset
21280
21281
21282 \begin_inset LatexCommand \index{\_\_naked}
21283
21284 \end_inset
21285
21286 .
21287 \end_layout
21288
21289 \begin_layout Itemize
21290
21291 \series bold
21292 less_pedantic
21293 \series default
21294
21295 \begin_inset LatexCommand \index{pedantic}
21296
21297 \end_inset
21298
21299
21300 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
21301
21302 \end_inset
21303
21304  
21305 \begin_inset LatexCommand \label{ite:less_pedantic}
21306
21307 \end_inset
21308
21309 - the compiler will not warn you anymore for obvious mistakes, you'r on
21310  your own now ;-( .
21311  See also the command line option -
21312 \begin_inset ERT
21313 status collapsed
21314
21315 \begin_layout Standard
21316
21317
21318 \backslash
21319 /
21320 \end_layout
21321
21322 \end_inset
21323
21324 -less-pedantic 
21325 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21326
21327 \end_inset
21328
21329 .
21330  
21331 \newline
21332 More specifically, the following warnings will be disabled: 
21333 \shape italic
21334 comparison is always [true/false] due to limited range of data type
21335 \shape default
21336  (94); 
21337 \shape italic
21338 overflow in implicit constant conversion
21339 \shape default
21340  (158); [the (in)famous] 
21341 \shape italic
21342 conditional flow changed by optimizer: so said EVELYN the modified DOG
21343 \shape default
21344  (110); 
21345 \shape italic
21346 function '[function name]' must return value
21347 \shape default
21348  (59).
21349  
21350 \newline
21351 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21352  level) are disabled, too, namely: 
21353 \shape italic
21354 constant value '[
21355 \begin_inset Note Note
21356 status collapsed
21357
21358 \begin_layout Standard
21359 dunno what comes here - this warning appears to be unused altogether
21360 \end_layout
21361
21362 \end_inset
21363
21364 ]', out of range
21365 \shape default
21366  (81); 
21367 \shape italic
21368 [left/right] shifting more than size of object changed to zero
21369 \shape default
21370  (116); 
21371 \shape italic
21372 unreachable code
21373 \shape default
21374  (126); 
21375 \shape italic
21376 integer overflow in expression
21377 \shape default
21378  (165); 
21379 \shape italic
21380 unmatched #pragma save and #pragma restore
21381 \shape default
21382  (170); 
21383 \shape italic
21384 comparison of 'signed char' with 'unsigned char' requires promotion to int
21385 \shape default
21386  (185); 
21387 \shape italic
21388 ISO C90 does not support flexible array members
21389 \shape default
21390  (187); 
21391 \shape italic
21392 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21393 nam
21394 e]':\InsetSpace ~
21395 [
21396 \begin_inset Note Note
21397 status collapsed
21398
21399 \begin_layout Standard
21400 appears to be always blank - what was supposed to be here?
21401 \end_layout
21402
21403 \end_inset
21404
21405 ]
21406 \shape default
21407  (114); 
21408 \shape italic
21409 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21410  complexity [number]
21411 \shape default
21412  (121).
21413 \end_layout
21414
21415 \begin_layout Itemize
21416
21417 \series bold
21418 disable_warning
21419 \series default
21420  <nnnn>
21421 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21422
21423 \end_inset
21424
21425  - the compiler will not warn you anymore about warning number <nnnn>.
21426 \end_layout
21427
21428 \begin_layout Itemize
21429
21430 \series bold
21431 nogcse
21432 \series default
21433
21434 \begin_inset LatexCommand \index{\#pragma nogcse}
21435
21436 \end_inset
21437
21438  - will stop global common subexpression elimination.
21439 \end_layout
21440
21441 \begin_layout Itemize
21442
21443 \series bold
21444 noinduction
21445 \series default
21446
21447 \begin_inset LatexCommand \index{\#pragma noinduction}
21448
21449 \end_inset
21450
21451  - will stop loop induction optimizations.
21452 \end_layout
21453
21454 \begin_layout Itemize
21455
21456 \series bold
21457 noinvariant
21458 \series default
21459
21460 \begin_inset LatexCommand \index{\#pragma noinvariant}
21461
21462 \end_inset
21463
21464  - will not do loop invariant optimizations.
21465  For more details see Loop Invariants in section
21466 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21467
21468 \end_inset
21469
21470 .
21471 \end_layout
21472
21473 \begin_layout Itemize
21474
21475 \series bold
21476 noiv
21477 \series default
21478
21479 \begin_inset LatexCommand \index{\#pragma noiv}
21480
21481 \end_inset
21482
21483  - Do not generate interrupt
21484 \begin_inset LatexCommand \index{interrupt}
21485
21486 \end_inset
21487
21488  vector table
21489 \begin_inset LatexCommand \index{interrupt vector table}
21490
21491 \end_inset
21492
21493  entries for all ISR functions defined after the pragma.
21494  This is useful in cases where the interrupt vector table must be defined
21495  manually, or when there is a secondary, manually defined interrupt vector
21496  table (e.g.
21497  for the autovector feature of the Cypress EZ-USB FX2).
21498  More elegantly this can be achieved by obmitting the optional interrupt
21499  number after the interrupt keyword, see section 
21500 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21501
21502 \end_inset
21503
21504 \InsetSpace ~
21505 about interrupts.
21506 \end_layout
21507
21508 \begin_layout Itemize
21509
21510 \series bold
21511 nojtbound
21512 \series default
21513
21514 \begin_inset LatexCommand \index{\#pragma nojtbound}
21515
21516 \end_inset
21517
21518  - will not generate code for boundary value checking, when switch statements
21519  are turned into jump-tables (dangerous).
21520  For more details see section 
21521 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21522
21523 \end_inset
21524
21525 .
21526 \end_layout
21527
21528 \begin_layout Itemize
21529
21530 \series bold
21531 noloopreverse
21532 \series default
21533
21534 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21535
21536 \end_inset
21537
21538  - Will not do loop reversal optimization
21539 \end_layout
21540
21541 \begin_layout Itemize
21542
21543 \series bold
21544 nooverlay
21545 \series default
21546
21547 \begin_inset LatexCommand \index{\#pragma nooverlay}
21548
21549 \end_inset
21550
21551  - the compiler will not overlay the parameters and local variables of a
21552  function.
21553 \end_layout
21554
21555 \begin_layout Itemize
21556
21557 \series bold
21558 stackauto
21559 \series default
21560
21561 \begin_inset LatexCommand \index{\#pragma stackauto}
21562
21563 \end_inset
21564
21565 - See option -
21566 \begin_inset ERT
21567 status collapsed
21568
21569 \begin_layout Standard
21570
21571
21572 \backslash
21573 /
21574 \end_layout
21575
21576 \end_inset
21577
21578 -stack-auto
21579 \begin_inset LatexCommand \index{-\/-stack-auto}
21580
21581 \end_inset
21582
21583  and section 
21584 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
21585
21586 \end_inset
21587
21588  Parameters and Local Variables.
21589 \end_layout
21590
21591 \begin_layout Itemize
21592
21593 \series bold
21594 opt_code_speed
21595 \series default
21596  
21597 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
21598
21599 \end_inset
21600
21601 - The compiler will optimize code generation towards fast code, possibly
21602  at the expense of code size.
21603  Currently this has little effect.
21604 \end_layout
21605
21606 \begin_layout Itemize
21607
21608 \series bold
21609 opt_code_size
21610 \series default
21611  
21612 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
21613
21614 \end_inset
21615
21616 - The compiler will optimize code generation towards compact code, possibly
21617  at the expense of code speed.
21618  Currently this has little effect.
21619 \end_layout
21620
21621 \begin_layout Itemize
21622
21623 \series bold
21624 opt_code_balanced
21625 \series default
21626  
21627 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
21628
21629 \end_inset
21630
21631 - The compiler will attempt to generate code that is both compact and fast,
21632  as long as meeting one goal is not a detriment to the other (this is the
21633  default).
21634  
21635 \end_layout
21636
21637 \begin_layout Itemize
21638
21639 \series bold
21640 std_sdcc89
21641 \series default
21642  
21643 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
21644
21645 \end_inset
21646
21647 - Generally follow the C89 standard, but allow SDCC features that conflict
21648  with the standard (default).
21649 \end_layout
21650
21651 \begin_layout Itemize
21652
21653 \series bold
21654 std_c89
21655 \series default
21656  
21657 \begin_inset LatexCommand \index{\#pragma std\_c89}
21658
21659 \end_inset
21660
21661 - Follow the C89 standard and disable SDCC features that conflict with the
21662  standard.
21663 \end_layout
21664
21665 \begin_layout Itemize
21666
21667 \series bold
21668 std_sdcc99
21669 \series default
21670  
21671 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
21672
21673 \end_inset
21674
21675 - Generally follow the C99 standard, but allow SDCC features that conflict
21676  with the standard (incomplete support).
21677 \end_layout
21678
21679 \begin_layout Itemize
21680
21681 \series bold
21682 std_c99
21683 \series default
21684  
21685 \begin_inset LatexCommand \index{\#pragma std\_c99}
21686
21687 \end_inset
21688
21689 - Follow the C99 standard and disable SDCC features that conflict with the
21690  standard (incomplete support).
21691 \end_layout
21692
21693 \begin_layout Itemize
21694
21695 \series bold
21696 codeseg
21697 \series default
21698  <name>
21699 \begin_inset LatexCommand \index{\#pragma codeseg}
21700
21701 \end_inset
21702
21703 - Use this name (max.
21704  8 characters) for the code segment.
21705  See option -
21706 \begin_inset ERT
21707 status collapsed
21708
21709 \begin_layout Standard
21710
21711
21712 \backslash
21713 /
21714 \end_layout
21715
21716 \end_inset
21717
21718 -codeseg.
21719 \end_layout
21720
21721 \begin_layout Itemize
21722
21723 \series bold
21724 constseg
21725 \series default
21726  <name>
21727 \begin_inset LatexCommand \index{\#pragma constseg}
21728
21729 \end_inset
21730
21731 - Use this name (max.
21732  8 characters) for the const segment.
21733  See option -
21734 \begin_inset ERT
21735 status collapsed
21736
21737 \begin_layout Standard
21738
21739
21740 \backslash
21741 /
21742 \end_layout
21743
21744 \end_inset
21745
21746 -constseg.
21747 \end_layout
21748
21749 \begin_layout Standard
21750 The preprocessor SDCPP
21751 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
21752
21753 \end_inset
21754
21755  supports the following #pragma directives:
21756 \end_layout
21757
21758 \begin_layout Itemize
21759
21760 \series bold
21761 pedantic_parse_number
21762 \series default
21763
21764 \begin_inset LatexCommand \index{pedantic}
21765
21766 \end_inset
21767
21768
21769 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21770
21771 \end_inset
21772
21773  (+ | -) 
21774 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
21775
21776 \end_inset
21777
21778 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
21779  properly and the macro LO_B(3) gets expanded.
21780  Default is off.
21781  See also the -
21782 \begin_inset ERT
21783 status collapsed
21784
21785 \begin_layout Standard
21786
21787
21788 \backslash
21789 /
21790 \end_layout
21791
21792 \end_inset
21793
21794 -pedantic-parse-number command line option 
21795 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
21796
21797 \end_inset
21798
21799 .
21800  
21801 \newline
21802 Below is an example on how to use this pragma.
21803
21804 \emph on
21805  Note: this functionality is not in conformance with standard!
21806 \end_layout
21807
21808 \begin_layout Verse
21809
21810 \family typewriter
21811 #pragma pedantic_parse_number +
21812 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21813
21814 \end_inset
21815
21816
21817 \newline
21818
21819 \newline
21820 #define LO_B(x) ((x) & 0xff)
21821 \newline
21822
21823 \newline
21824 unsigned char foo(void)
21825 \newline
21826 {
21827 \newline
21828 \InsetSpace ~
21829 \InsetSpace ~
21830 \InsetSpace ~
21831 unsigned char c=0xfe-LO_B(3)
21832 ;
21833 \newline
21834
21835 \newline
21836 \InsetSpace ~
21837 \InsetSpace ~
21838 \InsetSpace ~
21839 return c;
21840 \newline
21841 }
21842 \newline
21843
21844 \end_layout
21845
21846 \begin_layout Itemize
21847
21848 \series bold
21849 preproc_asm
21850 \series default
21851
21852 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21853
21854 \end_inset
21855
21856  (+ | -) - switch _asm _endasm block preprocessing on / off.
21857  Default is on.
21858  You use this prama to define multilines of assembly code.
21859  This will prevent the preprocessor from changing the formating required
21860  by assembly code.
21861  Below is an example on how to use this pragma.
21862 \end_layout
21863
21864 \begin_layout Verse
21865
21866 \family typewriter
21867 #pragma preproc_asm -
21868 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21869
21870 \end_inset
21871
21872
21873 \newline
21874 #define MYDELAY _asm
21875 \newline
21876 \InsetSpace ~
21877 \InsetSpace ~
21878 \InsetSpace ~
21879 nop ;my assembly comment...
21880 \newline
21881 \InsetSpace ~
21882 \InsetSpace ~
21883 \InsetSpace ~
21884 nop
21885 \newline
21886 \InsetSpace ~
21887 \InsetSpace ~
21888 \InsetSpace ~
21889 nop
21890 \newline
21891 _endasm
21892 \newline
21893 #pragma preproc_asm
21894  +
21895 \newline
21896
21897 \newline
21898 void foo (void) 
21899 \newline
21900
21901 \newline
21902 \InsetSpace ~
21903 \InsetSpace ~
21904 \InsetSpace ~
21905  ...
21906  
21907 \newline
21908 \InsetSpace ~
21909 \InsetSpace ~
21910 \InsetSpace ~
21911  MYDELAY;
21912 \newline
21913 \InsetSpace ~
21914 \InsetSpace ~
21915 \InsetSpace ~
21916  ...
21917  
21918 \newline
21919
21920 \newline
21921
21922 \end_layout
21923
21924 \begin_layout Itemize
21925
21926 \series bold
21927 sdcc_hash
21928 \series default
21929
21930 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21931
21932 \end_inset
21933
21934  (+ | -) - Allow "naked" hash in macro definition, for example:
21935 \newline
21936
21937 \family typewriter
21938 #define DIR_LO(x) #(x & 0xff)
21939 \family default
21940
21941 \newline
21942 Default is off.
21943  Below is an example on how to use this pragma.
21944 \end_layout
21945
21946 \begin_layout Verse
21947
21948 \family typewriter
21949 #pragma preproc_asm +
21950 \newline
21951 #pragma sdcc_hash +
21952 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21953
21954 \end_inset
21955
21956
21957 \newline
21958
21959 \newline
21960 #define ROMCALL(x) 
21961 \backslash
21962
21963 \newline
21964 \InsetSpace ~
21965 \InsetSpace ~
21966 \InsetSpace ~
21967 mov R6_B3, #(x & 0xff) 
21968 \backslash
21969
21970 \newline
21971 \InsetSpace ~
21972 \InsetSpace ~
21973 \InsetSpace ~
21974 mov R7_B3, #((x >> 8) & 0xff) 
21975 \backslash
21976
21977 \newline
21978 \InsetSpace ~
21979 \InsetSpace ~
21980 \InsetSpace ~
21981 lcall __romcall
21982 \newline
21983
21984 \newline
21985 ...
21986 \newline
21987 _asm
21988 \newline
21989 ROMCALL(72)
21990 \newline
21991 _endasm;
21992 \newline
21993 ...
21994 \newline
21995
21996 \end_layout
21997
21998 \begin_layout Standard
21999 Some of the pragmas are intended to be used to turn-on or off certain optimizati
22000 ons which might cause the compiler to generate extra stack and/or data space
22001  to store compiler generated temporary variables.
22002  This usually happens in large functions.
22003  Pragma directives should be used as shown in the following example, they
22004  are used to control options and optimizations for a given function.
22005  
22006 \end_layout
22007
22008 \begin_layout Verse
22009
22010 \family typewriter
22011 #pragma save
22012 \begin_inset LatexCommand \index{\#pragma save}
22013
22014 \end_inset
22015
22016  \InsetSpace ~
22017 \InsetSpace ~
22018 \InsetSpace ~
22019 \InsetSpace ~
22020 \InsetSpace ~
22021 \InsetSpace ~
22022 \InsetSpace ~
22023 /* save the current settings */ 
22024 \newline
22025 #pragma nogcse
22026 \begin_inset LatexCommand \index{\#pragma nogcse}
22027
22028 \end_inset
22029
22030  \InsetSpace ~
22031 \InsetSpace ~
22032 \InsetSpace ~
22033 \InsetSpace ~
22034 \InsetSpace ~
22035 /* turnoff global subexpression elimination */ 
22036 \newline
22037 #pragma noinduction
22038 \begin_inset LatexCommand \index{\#pragma noinduction}
22039
22040 \end_inset
22041
22042  /* turn off induction optimizations */ 
22043 \newline
22044 int foo () 
22045 \newline
22046
22047 \newline
22048 \InsetSpace ~
22049  \InsetSpace ~
22050  ...
22051  
22052 \newline
22053 \InsetSpace ~
22054  \InsetSpace ~
22055  /* large code */ 
22056 \newline
22057 \InsetSpace ~
22058  \InsetSpace ~
22059  ...
22060  
22061 \newline
22062
22063 \newline
22064 #pragma restore
22065 \begin_inset LatexCommand \index{\#pragma restore}
22066
22067 \end_inset
22068
22069  /* turn the optimizations back on */
22070 \end_layout
22071
22072 \begin_layout Standard
22073 The compiler will generate a warning message when extra space is allocated.
22074  It is strongly recommended that the save and restore pragma's be used when
22075  changing options for a function.
22076 \newline
22077
22078 \newline
22079
22080 \newline
22081
22082 \end_layout
22083
22084 \begin_layout Section
22085 Defines Created by the Compiler
22086 \end_layout
22087
22088 \begin_layout Standard
22089 The compiler creates the following #defines
22090 \begin_inset LatexCommand \index{\#defines}
22091
22092 \end_inset
22093
22094
22095 \begin_inset LatexCommand \index{Defines created by the compiler}
22096
22097 \end_inset
22098
22099 :
22100 \newline
22101
22102 \end_layout
22103
22104 \begin_layout Standard
22105 \begin_inset Tabular
22106 <lyxtabular version="3" rows="11" columns="2">
22107 <features>
22108 <column alignment="left" valignment="top" leftline="true" width="3in">
22109 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
22110 <row topline="true" bottomline="true">
22111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22112 \begin_inset Text
22113
22114 \begin_layout Standard
22115
22116 \series bold
22117 #define
22118 \end_layout
22119
22120 \end_inset
22121 </cell>
22122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22123 \begin_inset Text
22124
22125 \begin_layout Standard
22126
22127 \series bold
22128 Description
22129 \end_layout
22130
22131 \end_inset
22132 </cell>
22133 </row>
22134 <row topline="true">
22135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22136 \begin_inset Text
22137
22138 \begin_layout Standard
22139 SDCC
22140 \begin_inset LatexCommand \index{SDCC}
22141
22142 \end_inset
22143
22144  
22145 \end_layout
22146
22147 \end_inset
22148 </cell>
22149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22150 \begin_inset Text
22151
22152 \begin_layout Standard
22153 Always defined.
22154  Since version 2.5.6 the version number as an int (ex.
22155  256)
22156 \end_layout
22157
22158 \end_inset
22159 </cell>
22160 </row>
22161 <row topline="true">
22162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22163 \begin_inset Text
22164
22165 \begin_layout Standard
22166 SDCC_mcs51
22167 \begin_inset LatexCommand \index{SDCC\_mcs51}
22168
22169 \end_inset
22170
22171  or SDCC_ds390
22172 \begin_inset LatexCommand \index{SDCC\_ds390}
22173
22174 \end_inset
22175
22176  or SDCC_z80
22177 \begin_inset LatexCommand \index{SDCC\_z80}
22178
22179 \end_inset
22180
22181 , etc.
22182 \end_layout
22183
22184 \end_inset
22185 </cell>
22186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22187 \begin_inset Text
22188
22189 \begin_layout Standard
22190 depending on the model used (e.g.: -mds390)
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 __mcs51
22202 \begin_inset LatexCommand \index{\_\_mcs51}
22203
22204 \end_inset
22205
22206 , __ds390
22207 \begin_inset LatexCommand \index{\_\_ds390}
22208
22209 \end_inset
22210
22211 , __hc08
22212 \begin_inset LatexCommand \index{\_\_hc08}
22213
22214 \end_inset
22215
22216 , __z80
22217 \begin_inset LatexCommand \index{\_\_z80}
22218
22219 \end_inset
22220
22221 , etc
22222 \end_layout
22223
22224 \end_inset
22225 </cell>
22226 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22227 \begin_inset Text
22228
22229 \begin_layout Standard
22230 depending on the model used (e.g.
22231  -mz80)
22232 \end_layout
22233
22234 \end_inset
22235 </cell>
22236 </row>
22237 <row topline="true">
22238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22239 \begin_inset Text
22240
22241 \begin_layout Standard
22242 SDCC_STACK_AUTO
22243 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
22244
22245 \end_inset
22246
22247
22248 \end_layout
22249
22250 \end_inset
22251 </cell>
22252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22253 \begin_inset Text
22254
22255 \begin_layout Standard
22256 when 
22257 \emph on
22258 -
22259 \begin_inset ERT
22260 status collapsed
22261
22262 \begin_layout Standard
22263
22264
22265 \backslash
22266 /
22267 \end_layout
22268
22269 \end_inset
22270
22271 -stack-auto
22272 \emph default
22273  option is used
22274 \end_layout
22275
22276 \end_inset
22277 </cell>
22278 </row>
22279 <row topline="true">
22280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22281 \begin_inset Text
22282
22283 \begin_layout Standard
22284 SDCC_MODEL_SMALL
22285 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
22286
22287 \end_inset
22288
22289
22290 \end_layout
22291
22292 \end_inset
22293 </cell>
22294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22295 \begin_inset Text
22296
22297 \begin_layout Standard
22298 when 
22299 \emph on
22300 -
22301 \begin_inset ERT
22302 status collapsed
22303
22304 \begin_layout Standard
22305
22306
22307 \backslash
22308 /
22309 \end_layout
22310
22311 \end_inset
22312
22313 -model-small
22314 \emph default
22315  is used
22316 \end_layout
22317
22318 \end_inset
22319 </cell>
22320 </row>
22321 <row topline="true">
22322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22323 \begin_inset Text
22324
22325 \begin_layout Standard
22326 SDCC_MODEL_MEDIUM
22327 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22328
22329 \end_inset
22330
22331
22332 \end_layout
22333
22334 \end_inset
22335 </cell>
22336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22337 \begin_inset Text
22338
22339 \begin_layout Standard
22340 when 
22341 \emph on
22342 -
22343 \begin_inset ERT
22344 status collapsed
22345
22346 \begin_layout Standard
22347
22348
22349 \backslash
22350 /
22351 \end_layout
22352
22353 \end_inset
22354
22355 -model-medium
22356 \emph default
22357  is used
22358 \end_layout
22359
22360 \end_inset
22361 </cell>
22362 </row>
22363 <row topline="true">
22364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22365 \begin_inset Text
22366
22367 \begin_layout Standard
22368 SDCC_MODEL_LARGE
22369 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22370
22371 \end_inset
22372
22373
22374 \end_layout
22375
22376 \end_inset
22377 </cell>
22378 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22379 \begin_inset Text
22380
22381 \begin_layout Standard
22382 when 
22383 \emph on
22384 -
22385 \begin_inset ERT
22386 status collapsed
22387
22388 \begin_layout Standard
22389
22390
22391 \backslash
22392 /
22393 \end_layout
22394
22395 \end_inset
22396
22397 -model-large
22398 \emph default
22399  is used
22400 \end_layout
22401
22402 \end_inset
22403 </cell>
22404 </row>
22405 <row topline="true">
22406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22407 \begin_inset Text
22408
22409 \begin_layout Standard
22410 SDCC_USE_XSTACK
22411 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22412
22413 \end_inset
22414
22415
22416 \end_layout
22417
22418 \end_inset
22419 </cell>
22420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22421 \begin_inset Text
22422
22423 \begin_layout Standard
22424 when 
22425 \emph on
22426 -
22427 \begin_inset ERT
22428 status collapsed
22429
22430 \begin_layout Standard
22431
22432
22433 \backslash
22434 /
22435 \end_layout
22436
22437 \end_inset
22438
22439 -xstack
22440 \emph default
22441  option is used
22442 \end_layout
22443
22444 \end_inset
22445 </cell>
22446 </row>
22447 <row topline="true">
22448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22449 \begin_inset Text
22450
22451 \begin_layout Standard
22452 SDCC_STACK_TENBIT
22453 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22454
22455 \end_inset
22456
22457  
22458 \end_layout
22459
22460 \end_inset
22461 </cell>
22462 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22463 \begin_inset Text
22464
22465 \begin_layout Standard
22466 when 
22467 \emph on
22468 -mds390
22469 \emph default
22470  is used
22471 \end_layout
22472
22473 \end_inset
22474 </cell>
22475 </row>
22476 <row topline="true" bottomline="true">
22477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22478 \begin_inset Text
22479
22480 \begin_layout Standard
22481 SDCC_MODEL_FLAT24
22482 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22483
22484 \end_inset
22485
22486
22487 \end_layout
22488
22489 \end_inset
22490 </cell>
22491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22492 \begin_inset Text
22493
22494 \begin_layout Standard
22495 when 
22496 \emph on
22497 -mds390
22498 \emph default
22499  is used
22500 \end_layout
22501
22502 \end_inset
22503 </cell>
22504 </row>
22505 </lyxtabular>
22506
22507 \end_inset
22508
22509
22510 \end_layout
22511
22512 \begin_layout Chapter
22513 Notes on supported Processors
22514 \end_layout
22515
22516 \begin_layout Section
22517 MCS51 variants
22518 \begin_inset LatexCommand \label{sub:MCS51-variants}
22519
22520 \end_inset
22521
22522
22523 \begin_inset LatexCommand \index{MCS51 variants}
22524
22525 \end_inset
22526
22527
22528 \end_layout
22529
22530 \begin_layout Standard
22531 MCS51 processors are available from many vendors and come in many different
22532  flavours.
22533  While they might differ considerably in respect to Special Function Registers
22534  the core MCS51 is usually not modified or is kept compatible.
22535  
22536 \end_layout
22537
22538 \begin_layout Subsection
22539 pdata access by SFR 
22540 \end_layout
22541
22542 \begin_layout Standard
22543 With the upcome of devices with internal xdata and flash memory devices
22544  using port P2
22545 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22546
22547 \end_inset
22548
22549  as dedicated I/O port is becoming more popular.
22550  Switching the high byte for pdata
22551 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22552
22553 \end_inset
22554
22555  access which was formerly done by port P2 is then achieved by a Special
22556  Function Register
22557 \begin_inset LatexCommand \index{sfr}
22558
22559 \end_inset
22560
22561 .
22562  In well-established MCS51 tradition the address of this 
22563 \emph on
22564 sfr
22565 \emph default
22566  is where the chip designers decided to put it.
22567  Needless to say that they didn't agree on a common name either.
22568  So that the startup code can correctly initialize xdata variables, you
22569  should define an sfr with the name _XPAGE
22570 \family typewriter
22571
22572 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
22573
22574 \end_inset
22575
22576
22577 \family default
22578  at the appropriate location if the default, port P2, is not used for this.
22579  Some examples are:
22580 \end_layout
22581
22582 \begin_layout Verse
22583
22584 \family typewriter
22585 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
22586  MPAGE */
22587 \end_layout
22588
22589 \begin_layout Verse
22590
22591 \family typewriter
22592 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
22593  a.k.a.
22594  MPAGE */
22595 \end_layout
22596
22597 \begin_layout Verse
22598
22599 \family typewriter
22600 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
22601  XPAGE */
22602 \end_layout
22603
22604 \begin_layout Verse
22605
22606 \family typewriter
22607 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22608  EMI0CN */
22609 \end_layout
22610
22611 \begin_layout Verse
22612
22613 \family typewriter
22614 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22615  EMI0CN */
22616 \end_layout
22617
22618 \begin_layout Standard
22619 For more exotic implementations further customizations may be needed.
22620  See section 
22621 \begin_inset LatexCommand \ref{sub:Startup-Code}
22622
22623 \end_inset
22624
22625  for other possibilities.
22626 \end_layout
22627
22628 \begin_layout Subsection
22629 Other Features available by SFR
22630 \end_layout
22631
22632 \begin_layout Standard
22633 Some MCS51 variants offer features like Double DPTR
22634 \begin_inset LatexCommand \index{DPTR}
22635
22636 \end_inset
22637
22638 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
22639  These are currently not used for the MCS51 port.
22640  If you absolutely need them you can fall back to inline assembly or submit
22641  a patch to SDCC.
22642 \begin_inset VSpace bigskip
22643 \end_inset
22644
22645
22646 \end_layout
22647
22648 \begin_layout Section
22649 DS400 port
22650 \end_layout
22651
22652 \begin_layout Standard
22653 The DS80C400
22654 \begin_inset LatexCommand \index{DS80C400}
22655
22656 \end_inset
22657
22658
22659 \begin_inset LatexCommand \index{DS400}
22660
22661 \end_inset
22662
22663  microcontroller has a rich set of peripherals.
22664  In its built-in ROM library it includes functions to access some of the
22665  features, among them is a TCP stack with IP4 and IP6 support.
22666  Library headers (currently in beta status) and other files are provided
22667  at 
22668 \size footnotesize
22669
22670 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
22671
22672 \end_inset
22673
22674 .
22675  
22676 \begin_inset VSpace bigskip
22677 \end_inset
22678
22679
22680 \end_layout
22681
22682 \begin_layout Section
22683 The Z80 and gbz80 port
22684 \end_layout
22685
22686 \begin_layout Standard
22687 SDCC can target both the Zilog Z80
22688 \begin_inset LatexCommand \index{Z80}
22689
22690 \end_inset
22691
22692  and the Nintendo Gameboy's Z80-like gbz80
22693 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
22694
22695 \end_inset
22696
22697 .
22698  The Z80 port is passed through the same 
22699 \emph on
22700 regressions tests
22701 \begin_inset LatexCommand \index{Regression test}
22702
22703 \end_inset
22704
22705
22706 \emph default
22707  (see section 
22708 \begin_inset LatexCommand \ref{sec:Quality-control}
22709
22710 \end_inset
22711
22712 ) as the MCS51 and DS390 ports, so floating point support, support for long
22713  variables and bitfield support is fine.
22714  See mailing lists and forums about interrupt routines.
22715 \end_layout
22716
22717 \begin_layout Standard
22718 As always, the code is the authoritative reference - see z80/ralloc.c and
22719  z80/gen.c.
22720  The stack
22721 \begin_inset LatexCommand \index{Z80!stack}
22722
22723 \end_inset
22724
22725  frame is similar to that generated by the IAR Z80 compiler.
22726  IX is used as the base pointer, HL and IY are used as a temporary registers,
22727  and BC and DE are available for holding variables.
22728  Return values
22729 \begin_inset LatexCommand \index{Z80!return value}
22730
22731 \end_inset
22732
22733  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
22734  bytes).
22735  The gbz80 port use the same set of registers for the return values, but
22736  in a different order of significance: E (one byte), DE (two bytes), or
22737  HLDE (four bytes).
22738 \begin_inset VSpace bigskip
22739 \end_inset
22740
22741
22742 \end_layout
22743
22744 \begin_layout Section
22745 The HC08 port
22746 \end_layout
22747
22748 \begin_layout Standard
22749 The port to the Freescale/Motorola HC08
22750 \begin_inset LatexCommand \index{HC08}
22751
22752 \end_inset
22753
22754  family has been added in October 2003, and is still undergoing some basic
22755  development.
22756  The code generator is complete, but the register allocation is still quite
22757  unoptimized.
22758  Some of the SDCC's standard C library functions have embedded non-HC08
22759  inline assembly and so are not yet usable.
22760 \end_layout
22761
22762 \begin_layout Standard
22763 The HC08 port passes the regression test suite (see section 
22764 \begin_inset LatexCommand \ref{sec:Quality-control}
22765
22766 \end_inset
22767
22768 ).
22769 \begin_inset VSpace bigskip
22770 \end_inset
22771
22772
22773 \newpage
22774
22775 \end_layout
22776
22777 \begin_layout Section
22778 The PIC14 port
22779 \end_layout
22780
22781 \begin_layout Standard
22782 The PIC14 port adds support for Microchip(TM)'s 14
22783 \begin_inset ERT
22784 status open
22785
22786 \begin_layout Standard
22787
22788
22789 \backslash
22790 ,
22791 \end_layout
22792
22793 \end_inset
22794
22795 bit PIC
22796 \begin_inset LatexCommand \index{PIC14}
22797
22798 \end_inset
22799
22800  MCUs.
22801  This port is not yet mature and still lacks many features.
22802  However, it can work for simple code.
22803 \end_layout
22804
22805 \begin_layout Standard
22806 Currently supported devices include:
22807 \end_layout
22808
22809 \begin_layout Standard
22810 12F: 629, 635, 675, 683
22811 \end_layout
22812
22813 \begin_layout Standard
22814 16C: 432, 433
22815 \end_layout
22816
22817 \begin_layout Standard
22818 16C: 554, 557, 558
22819 \end_layout
22820
22821 \begin_layout Standard
22822 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
22823 \end_layout
22824
22825 \begin_layout Standard
22826 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
22827  781, 782
22828 \end_layout
22829
22830 \begin_layout Standard
22831 16C: 925, 926
22832 \end_layout
22833
22834 \begin_layout Standard
22835 16F: 627, 627a, 628, 628a, 630, 636, 639, 648a, 676, 684, 685, 687, 688,
22836  689, 690
22837 \end_layout
22838
22839 \begin_layout Standard
22840 16F: 716, 72, 73, 737, 74, 76, 767, 77, 777, 785
22841 \end_layout
22842
22843 \begin_layout Standard
22844 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
22845  877, 877a, 88
22846 \end_layout
22847
22848 \begin_layout Standard
22849 16F: 913, 914, 916, 917
22850 \end_layout
22851
22852 \begin_layout Standard
22853 An up-to-date list of currently supported devices can be obtained via 
22854 \family typewriter
22855 sdcc -mpic14 -phelp foo.c
22856 \family default
22857  (foo.c must exist...).
22858 \end_layout
22859
22860 \begin_layout Subsection
22861 PIC Code Pages
22862 \begin_inset LatexCommand \index{code page (pic14)}
22863
22864 \end_inset
22865
22866  and Memory Banks
22867 \begin_inset LatexCommand \index{Memory bank (pic14)}
22868
22869 \end_inset
22870
22871
22872 \end_layout
22873
22874 \begin_layout Standard
22875 The linker organizes allocation for the code page and RAM banks.
22876  It does not have intimate knowledge of the code flow.
22877  It will put all the code section of a single .asm file into a single code
22878  page.
22879  In order to make use of multiple code pages, separate asm files must be
22880  used.
22881  The compiler assigns all 
22882 \emph on
22883 static
22884 \emph default
22885  functions of a single .c file into the same code page.
22886 \newline
22887
22888 \newline
22889 To get the best results,
22890  follow these guidelines:
22891 \end_layout
22892
22893 \begin_layout Enumerate
22894 Make local functions static, as non static functions require code page selection
22895  overhead.
22896 \newline
22897 Due to the way sdcc handles functions, place called functions prior
22898  to calling functions in the file wherever possible: Otherwise sdcc will
22899  insert unneccessary pagesel directives around the call, believing that
22900  the called function is externally defined.
22901 \end_layout
22902
22903 \begin_layout Enumerate
22904 For devices that have multiple code pages it is more efficient to use the
22905  same number of files as pages: Use up to 4 separate .c files for the 16F877,
22906  but only 2 files for the 16F874.
22907  This way the linker can put the code for each file into different code
22908  pages and there will be less page selection overhead.
22909 \end_layout
22910
22911 \begin_layout Enumerate
22912 And as for any 8 bit micro (especially for PIC14 as they have a very simple
22913  instruction set), use 'unsigned char' wherever possible instead of 'int'.
22914 \end_layout
22915
22916 \begin_layout Subsection
22917 Adding New Devices to the Port 
22918 \end_layout
22919
22920 \begin_layout Standard
22921 Adding support for a new 14
22922 \begin_inset ERT
22923 status open
22924
22925 \begin_layout Standard
22926
22927
22928 \backslash
22929 ,
22930 \end_layout
22931
22932 \end_inset
22933
22934 bit PIC MCU requires the following steps:
22935 \end_layout
22936
22937 \begin_layout Enumerate
22938 Create a new device description.
22939 \newline
22940 Each device is described in two files: pic16f*.h
22941  and pic16f*.c.
22942  These files primarily define SFRs, structs to access their bits, and symbolic
22943  configuration options.
22944  Both files can be generated from gputils' .inc files using the perl script
22945  
22946 \family typewriter
22947 support/scripts/inc2h.pl
22948 \family default
22949 .
22950  This file also contains further instructions on how to proceed.
22951 \end_layout
22952
22953 \begin_layout Enumerate
22954 Copy the .h file into SDCC's include path and either add the .c file to your
22955  project or copy it to 
22956 \family typewriter
22957 device/lib/pic/libdev
22958 \family default
22959 .
22960  Afterwards, rebuild and install the libraries.
22961 \end_layout
22962
22963 \begin_layout Enumerate
22964 Edit pic14devices.txt in SDCC's include path (
22965 \family typewriter
22966 device/include/pic/
22967 \family default
22968  in the source tree or 
22969 \family typewriter
22970 /usr/local/share/sdcc/include/pic
22971 \family default
22972  after installation).
22973 \newline
22974 You need to add a device specification here to make
22975  the memory layout (code banks, RAM, aliased memory regions, ...) known to
22976  the compiler.
22977  Probably you can copy and modify an existing entry.
22978  The file format is documented at the top of the file.
22979 \end_layout
22980
22981 \begin_layout Subsection
22982 Interrupt Code
22983 \end_layout
22984
22985 \begin_layout Standard
22986 For the interrupt function, use the keyword '__interrupt'
22987 \begin_inset LatexCommand \index{PIC14!interrupt}
22988
22989 \end_inset
22990
22991  with level number of 0 (PIC14 only has 1 interrupt so this number is only
22992  there to avoid a syntax error - it ought to be fixed).
22993  E.g.:
22994 \end_layout
22995
22996 \begin_layout Verse
22997
22998 \family typewriter
22999 void Intr(void) __interrupt 0
23000 \newline
23001 {
23002 \newline
23003 \InsetSpace ~
23004 \InsetSpace ~
23005 T0IF = 0; /* Clear timer interrupt */
23006 \newline
23007 }
23008 \end_layout
23009
23010 \begin_layout Subsection
23011 Linking and Assembling
23012 \end_layout
23013
23014 \begin_layout Standard
23015 For assembling you can use either GPUTILS'
23016 \begin_inset LatexCommand \index{gputils (pic tools)}
23017
23018 \end_inset
23019
23020  gpasm.exe or MPLAB's mpasmwin.exe.
23021  GPUTILS are available from 
23022 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
23023
23024 \end_inset
23025
23026 .
23027  For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
23028  If you use MPLAB and an interrupt function then the linker script file
23029  vectors section will need to be enlarged to link with mplink.
23030 \newline
23031
23032 \newline
23033 Here is a 
23034 \family typewriter
23035 Makefile
23036 \family default
23037  using GPUTILS:
23038 \end_layout
23039
23040 \begin_layout Verse
23041
23042 \family typewriter
23043 .c.o:
23044 \newline
23045 \InsetSpace ~
23046 \InsetSpace ~
23047 \InsetSpace ~
23048 \InsetSpace ~
23049 \InsetSpace ~
23050 \InsetSpace ~
23051 \InsetSpace ~
23052 \InsetSpace ~
23053 sdcc -V -mpic14 -p16f877 -c $< 
23054 \newline
23055
23056 \newline
23057 $(PRJ).hex: $(OBJS) 
23058 \newline
23059 \InsetSpace ~
23060 \InsetSpace ~
23061 \InsetSpace ~
23062 \InsetSpace ~
23063 \InsetSpace ~
23064 \InsetSpace ~
23065 \InsetSpace ~
23066 \InsetSpace ~
23067 gplink -m -s $(PRJ).lkr
23068  -o $(PRJ).hex $(OBJS) libsdcc.lib
23069 \end_layout
23070
23071 \begin_layout Standard
23072 Here is a 
23073 \family typewriter
23074 Makefile
23075 \family default
23076  using MPLAB:
23077 \end_layout
23078
23079 \begin_layout Verse
23080
23081 \family typewriter
23082 .c.o: 
23083 \newline
23084 \InsetSpace ~
23085 \InsetSpace ~
23086 \InsetSpace ~
23087 \InsetSpace ~
23088 \InsetSpace ~
23089 \InsetSpace ~
23090 \InsetSpace ~
23091 \InsetSpace ~
23092 sdcc -S -V -mpic14 -p16f877 $< 
23093 \newline
23094 \InsetSpace ~
23095 \InsetSpace ~
23096 \InsetSpace ~
23097 \InsetSpace ~
23098 \InsetSpace ~
23099 \InsetSpace ~
23100 \InsetSpace ~
23101 \InsetSpace ~
23102 mpasmwin /q /o $*.asm
23103 \newline
23104
23105 \newline
23106 $(PRJ).hex: $(OBJS)
23107  
23108 \newline
23109 \InsetSpace ~
23110 \InsetSpace ~
23111 \InsetSpace ~
23112 \InsetSpace ~
23113 \InsetSpace ~
23114 \InsetSpace ~
23115 \InsetSpace ~
23116 \InsetSpace ~
23117 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
23118 \end_layout
23119
23120 \begin_layout Standard
23121 Please note that indentations within a
23122 \family typewriter
23123  Makefile
23124 \family default
23125  have to be done with a tabulator character.
23126 \end_layout
23127
23128 \begin_layout Subsection
23129 Command-Line Options
23130 \end_layout
23131
23132 \begin_layout Standard
23133 Besides the switches common to all SDCC backends, the PIC14 port accepts
23134  the following options (for an updated list see sdcc -
23135 \begin_inset ERT
23136 status collapsed
23137
23138 \begin_layout Standard
23139
23140
23141 \backslash
23142 /
23143 \end_layout
23144
23145 \end_inset
23146
23147 -help):
23148 \end_layout
23149
23150 \begin_layout Description
23151 -
23152 \begin_inset ERT
23153 status collapsed
23154
23155 \begin_layout Standard
23156
23157
23158 \backslash
23159 /
23160 \end_layout
23161
23162 \end_inset
23163
23164 -debug-xtra
23165 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
23166
23167 \end_inset
23168
23169  emit debug info in assembly output
23170 \end_layout
23171
23172 \begin_layout Description
23173 -
23174 \begin_inset ERT
23175 status collapsed
23176
23177 \begin_layout Standard
23178
23179
23180 \backslash
23181 /
23182 \end_layout
23183
23184 \end_inset
23185
23186 -no-pcode-opt
23187 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
23188
23189 \end_inset
23190
23191  disable (slightly faulty) optimization on pCode
23192 \end_layout
23193
23194 \begin_layout Description
23195 -
23196 \begin_inset ERT
23197 status collapsed
23198
23199 \begin_layout Standard
23200
23201
23202 \backslash
23203 /
23204 \end_layout
23205
23206 \end_inset
23207
23208 -stack-loc
23209 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
23210
23211 \end_inset
23212
23213  sets the lowest address of the argument passing stack (defaults to a suitably
23214  large shared databank to reduce BANKSEL overhead)
23215 \end_layout
23216
23217 \begin_layout Description
23218 -
23219 \begin_inset ERT
23220 status collapsed
23221
23222 \begin_layout Standard
23223
23224
23225 \backslash
23226 /
23227 \end_layout
23228
23229 \end_inset
23230
23231 -stack-size
23232 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
23233
23234 \end_inset
23235
23236  sets the size if the argument passing stack (default: 16, minimum: 4)
23237 \end_layout
23238
23239 \begin_layout Subsection
23240 Environment Variables
23241 \end_layout
23242
23243 \begin_layout Standard
23244 The PIC14 port recognizes the following environment variables:
23245 \end_layout
23246
23247 \begin_layout Description
23248 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
23249  register (the ones called r0xNNNN) in a section of its own.
23250  By default (if this variable is unset), sdcc tries to cluster registers
23251  in sections in order to reduce the BANKSEL overhead when accessing them.
23252 \end_layout
23253
23254 \begin_layout Subsection
23255 The Library
23256 \end_layout
23257
23258 \begin_layout Standard
23259 The PIC14 library currently only contains support routines required by the
23260  compiler to implement multiplication, division, and floating point support.
23261  No libc-like replacement is available at the moment, though many of the
23262  common sdcc library sources (in 
23263 \family typewriter
23264 device/lib
23265 \family default
23266 ) should also compile with the PIC14 port.
23267 \end_layout
23268
23269 \begin_layout Subsubsection
23270 error: missing definition for symbol 
23271 \begin_inset Quotes sld
23272 \end_inset
23273
23274 __gptrget1
23275 \begin_inset Quotes srd
23276 \end_inset
23277
23278
23279 \end_layout
23280
23281 \begin_layout Standard
23282 The PIC14 port uses library routines to provide more complex operations
23283  like multiplication, division/modulus and (generic) pointer dereferencing.
23284  In order to add these routines to your project, you must link with PIC14's
23285  
23286 \family typewriter
23287 libsdcc.lib
23288 \family default
23289 .
23290  For single source file projects this is done automatically, more complex
23291  projects must add 
23292 \family typewriter
23293 libsdcc.lib
23294 \family default
23295  to the linker's arguments.
23296  Make sure you also add an include path for the library (using the -I switch
23297  to the linker)!
23298 \end_layout
23299
23300 \begin_layout Subsubsection
23301 Processor mismatch in file 
23302 \begin_inset Quotes sld
23303 \end_inset
23304
23305 XXX
23306 \begin_inset Quotes srd
23307 \end_inset
23308
23309 .
23310 \end_layout
23311
23312 \begin_layout Standard
23313 This warning can usually be ignored due to the very good compatibility amongst
23314  14
23315 \begin_inset ERT
23316 status open
23317
23318 \begin_layout Standard
23319
23320
23321 \backslash
23322 ,
23323 \end_layout
23324
23325 \end_inset
23326
23327 bit PIC
23328 \begin_inset LatexCommand \index{PIC14}
23329
23330 \end_inset
23331
23332  devices.
23333 \end_layout
23334
23335 \begin_layout Standard
23336 You might also consider recompiling the library for your specific device
23337  by changing the ARCH=p16f877 (default target) entry in 
23338 \family typewriter
23339 device/lib/pic/Makefile.in
23340 \family default
23341  and 
23342 \family typewriter
23343 device/lib/pic/Makefile
23344 \family default
23345  to reflect your device.
23346  This might even improve performance for smaller devices as unneccesary
23347  BANKSELs might be removed.
23348 \end_layout
23349
23350 \begin_layout Subsection
23351 Known Bugs
23352 \end_layout
23353
23354 \begin_layout Subsubsection
23355 Function arguments
23356 \end_layout
23357
23358 \begin_layout Standard
23359 Functions with variable argument lists (like printf) are not yet supported.
23360  Similarly, taking the argument of the first argument passed into a function
23361  does not work: It is currently passed in WREG and has no address...
23362 \end_layout
23363
23364 \begin_layout Subsubsection
23365 Regression tests fail
23366 \end_layout
23367
23368 \begin_layout Standard
23369 Though the small subset of regression tests in src/regression passes, SDCC
23370  regression test suite does not, indicating that there are still major bugs
23371  in the port.
23372  However, many smaller projects have successfully used SDCC in the past...
23373 \end_layout
23374
23375 \begin_layout Standard
23376
23377 \size footnotesize
23378
23379 \newpage
23380
23381 \end_layout
23382
23383 \begin_layout Section
23384 The PIC16
23385 \begin_inset LatexCommand \index{PIC16}
23386
23387 \end_inset
23388
23389  port
23390 \end_layout
23391
23392 \begin_layout Standard
23393 The PIC16
23394 \begin_inset LatexCommand \index{PIC16}
23395
23396 \end_inset
23397
23398  port is the portion of SDCC that is responsible to produce code for the
23399  Microchip
23400 \begin_inset LatexCommand \index{Microchip}
23401
23402 \end_inset
23403
23404 (TM) microcontrollers with 16 bit core.
23405  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
23406  Currently supported devices are:
23407 \end_layout
23408
23409 \begin_layout Standard
23410 18F: 242, 248, 252, 258, 442, 448, 452, 458
23411 \end_layout
23412
23413 \begin_layout Standard
23414 18F: 1220, 1320
23415 \end_layout
23416
23417 \begin_layout Standard
23418 18F: 2220, 2221, 2320, 2321, 2331, 2431, 2455, 2525, 2550, 2620
23419 \end_layout
23420
23421 \begin_layout Standard
23422 18F: 4220, 4221, 4320, 4321, 4331, 4431, 4455, 4520, 4525, 4550, 4620
23423 \end_layout
23424
23425 \begin_layout Standard
23426 18F: 6520, 6620, 6680, 6720
23427 \end_layout
23428
23429 \begin_layout Standard
23430 18F: 8520, 8620, 8680, 8720
23431 \end_layout
23432
23433 \begin_layout Subsection
23434 Global Options
23435 \end_layout
23436
23437 \begin_layout Standard
23438 PIC16 port supports the standard command line arguments as supposed, with
23439  the exception of certain cases that will be mentioned in the following
23440  list:
23441 \end_layout
23442
23443 \begin_layout Description
23444 -
23445 \begin_inset ERT
23446 status collapsed
23447
23448 \begin_layout Standard
23449
23450
23451 \backslash
23452 /
23453 \end_layout
23454
23455 \end_inset
23456
23457 -callee-saves
23458 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23459
23460 \end_inset
23461
23462  See -
23463 \begin_inset ERT
23464 status collapsed
23465
23466 \begin_layout Standard
23467
23468
23469 \backslash
23470 /
23471 \end_layout
23472
23473 \end_inset
23474
23475 -all-callee-saves
23476 \end_layout
23477
23478 \begin_layout Description
23479 -
23480 \begin_inset ERT
23481 status collapsed
23482
23483 \begin_layout Standard
23484
23485
23486 \backslash
23487 /
23488 \end_layout
23489
23490 \end_inset
23491
23492 -fommit-frame-pointer
23493 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23494
23495 \end_inset
23496
23497  Frame pointer will be omitted when the function uses no local variables.
23498 \end_layout
23499
23500 \begin_layout Subsection
23501 Port Specific Options
23502 \begin_inset LatexCommand \index{Options PIC16}
23503
23504 \end_inset
23505
23506
23507 \end_layout
23508
23509 \begin_layout Standard
23510 The port specific options appear after the global options in the sdcc -
23511 \begin_inset ERT
23512 status collapsed
23513
23514 \begin_layout Standard
23515
23516
23517 \backslash
23518 /
23519 \end_layout
23520
23521 \end_inset
23522
23523 -help output.
23524 \end_layout
23525
23526 \begin_layout Subsubsection
23527 Code Generation Options
23528 \end_layout
23529
23530 \begin_layout Standard
23531 These options influence the generated assembler code.
23532 \end_layout
23533
23534 \begin_layout Description
23535 -
23536 \begin_inset ERT
23537 status collapsed
23538
23539 \begin_layout Standard
23540
23541
23542 \backslash
23543 /
23544 \end_layout
23545
23546 \end_inset
23547
23548 -pstack-model=[model] Used in conjuction with the command above.
23549  Defines the stack model to be used, valid stack models are:
23550 \end_layout
23551
23552 \begin_deeper
23553 \begin_layout List
23554 \labelwidthstring 00.00.0000
23555
23556 \emph on
23557 small
23558 \emph default
23559  Selects small stack model.
23560  8 bit stack and frame pointers.
23561  Supports 256 bytes stack size.
23562 \end_layout
23563
23564 \begin_layout List
23565 \labelwidthstring 00.00.0000
23566
23567 \emph on
23568 large
23569 \emph default
23570  Selects large stack model.
23571  16 bit stack and frame pointers.
23572  Supports 65536 bytes stack size.
23573 \end_layout
23574
23575 \end_deeper
23576 \begin_layout Description
23577 -
23578 \begin_inset ERT
23579 status collapsed
23580
23581 \begin_layout Standard
23582
23583
23584 \backslash
23585 /
23586 \end_layout
23587
23588 \end_inset
23589
23590 -pno-banksel Do not generate BANKSEL assembler directives.
23591 \end_layout
23592
23593 \begin_layout Description
23594 -
23595 \begin_inset ERT
23596 status collapsed
23597
23598 \begin_layout Standard
23599
23600
23601 \backslash
23602 /
23603 \end_layout
23604
23605 \end_inset
23606
23607 -extended Enable extended instruction set/literal offset addressing mode.
23608  Use with care!
23609 \end_layout
23610
23611 \begin_layout Subsubsection
23612 Optimization Options
23613 \end_layout
23614
23615 \begin_layout Description
23616 -
23617 \begin_inset ERT
23618 status collapsed
23619
23620 \begin_layout Standard
23621
23622
23623 \backslash
23624 /
23625 \end_layout
23626
23627 \end_inset
23628
23629 -obanksel=n Set optimization level for inserting BANKSELs.
23630 \newline
23631
23632 \end_layout
23633
23634 \begin_deeper
23635 \begin_layout List
23636 \labelwidthstring 00.00.0000
23637 0 no optimization
23638 \end_layout
23639
23640 \begin_layout List
23641 \labelwidthstring 00.00.0000
23642 1 checks previous used register and if it is the same then does not emit
23643  BANKSEL, accounts only for labels.
23644 \end_layout
23645
23646 \begin_layout List
23647 \labelwidthstring 00.00.0000
23648 2 tries to check the location of (even different) symbols and removes BANKSELs
23649  if they are in the same bank.
23650  
23651 \newline
23652
23653 \emph on
23654 Important: There might be problems if the linker script has data sections
23655  across bank borders!
23656 \end_layout
23657
23658 \end_deeper
23659 \begin_layout Description
23660 -
23661 \begin_inset ERT
23662 status collapsed
23663
23664 \begin_layout Standard
23665
23666
23667 \backslash
23668 /
23669 \end_layout
23670
23671 \end_inset
23672
23673 -denable-peeps Force the usage of peepholes.
23674  Use with care.
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 -optimize-goto Try to use (conditional) BRA instead of GOTO.
23692 \end_layout
23693
23694 \begin_layout Description
23695 -
23696 \begin_inset ERT
23697 status collapsed
23698
23699 \begin_layout Standard
23700
23701
23702 \backslash
23703 /
23704 \end_layout
23705
23706 \end_inset
23707
23708 -optimize-cmp Try to optimize some compares.
23709 \end_layout
23710
23711 \begin_layout Description
23712 -
23713 \begin_inset ERT
23714 status collapsed
23715
23716 \begin_layout Standard
23717
23718
23719 \backslash
23720 /
23721 \end_layout
23722
23723 \end_inset
23724
23725 -optimize-df Analyze the dataflow of the generated code and improve it.
23726 \end_layout
23727
23728 \begin_layout Subsubsection
23729 Assembling Options
23730 \end_layout
23731
23732 \begin_layout Description
23733 -
23734 \begin_inset ERT
23735 status collapsed
23736
23737 \begin_layout Standard
23738
23739
23740 \backslash
23741 /
23742 \end_layout
23743
23744 \end_inset
23745
23746 -asm= Sets the full path and name of an external assembler to call.
23747 \end_layout
23748
23749 \begin_layout Description
23750 -
23751 \begin_inset ERT
23752 status collapsed
23753
23754 \begin_layout Standard
23755
23756
23757 \backslash
23758 /
23759 \end_layout
23760
23761 \end_inset
23762
23763 -mplab-comp MPLAB
23764 \begin_inset LatexCommand \index{PIC16!MPLAB}
23765
23766 \end_inset
23767
23768  compatibility option.
23769  Currently only suppresses special gpasm directives.
23770 \end_layout
23771
23772 \begin_layout Subsubsection
23773 Linking Options
23774 \end_layout
23775
23776 \begin_layout Description
23777 -
23778 \begin_inset ERT
23779 status collapsed
23780
23781 \begin_layout Standard
23782
23783
23784 \backslash
23785 /
23786 \end_layout
23787
23788 \end_inset
23789
23790 -link= Sets the full path and name of an external linker to call.
23791 \end_layout
23792
23793 \begin_layout Description
23794 -
23795 \begin_inset ERT
23796 status collapsed
23797
23798 \begin_layout Standard
23799
23800
23801 \backslash
23802 /
23803 \end_layout
23804
23805 \end_inset
23806
23807 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
23808  unitialized data variables with [kword].
23809  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
23810 \end_layout
23811
23812 \begin_layout Description
23813 -
23814 \begin_inset ERT
23815 status collapsed
23816
23817 \begin_layout Standard
23818
23819
23820 \backslash
23821 /
23822 \end_layout
23823
23824 \end_inset
23825
23826 -ivt-loc=n Place the interrupt vector table at address 
23827 \emph on
23828 n
23829 \emph default
23830 .
23831  Useful for bootloaders.
23832 \end_layout
23833
23834 \begin_layout Description
23835 -
23836 \begin_inset ERT
23837 status collapsed
23838
23839 \begin_layout Standard
23840
23841
23842 \backslash
23843 /
23844 \end_layout
23845
23846 \end_inset
23847
23848 -nodefaultlibs Do not link default libraries when linking.
23849 \end_layout
23850
23851 \begin_layout Description
23852 -
23853 \begin_inset ERT
23854 status collapsed
23855
23856 \begin_layout Standard
23857
23858
23859 \backslash
23860 /
23861 \end_layout
23862
23863 \end_inset
23864
23865 -use-crt= Use a custom run-time module instead of the defaults.
23866 \end_layout
23867
23868 \begin_layout Description
23869 -
23870 \begin_inset ERT
23871 status collapsed
23872
23873 \begin_layout Standard
23874
23875
23876 \backslash
23877 /
23878 \end_layout
23879
23880 \end_inset
23881
23882 -no-crt Don't link the default run-time modules
23883 \end_layout
23884
23885 \begin_layout Subsubsection
23886 Debugging Options
23887 \end_layout
23888
23889 \begin_layout Standard
23890 Debugging options enable extra debugging information in the output files.
23891 \end_layout
23892
23893 \begin_layout Description
23894 -
23895 \begin_inset ERT
23896 status collapsed
23897
23898 \begin_layout Standard
23899
23900
23901 \backslash
23902 /
23903 \end_layout
23904
23905 \end_inset
23906
23907 -debug-xtra Similar to -
23908 \begin_inset ERT
23909 status collapsed
23910
23911 \begin_layout Standard
23912
23913
23914 \backslash
23915 /
23916 \end_layout
23917
23918 \end_inset
23919
23920 -debug
23921 \begin_inset LatexCommand \index{-\/-debug}
23922
23923 \end_inset
23924
23925 , but dumps more information.
23926 \end_layout
23927
23928 \begin_layout Description
23929 -
23930 \begin_inset ERT
23931 status collapsed
23932
23933 \begin_layout Standard
23934
23935
23936 \backslash
23937 /
23938 \end_layout
23939
23940 \end_inset
23941
23942 -debug-ralloc Force register allocator to dump <source>.d file with debugging
23943  information.
23944  <source> is the name of the file being compiled.
23945 \end_layout
23946
23947 \begin_layout Description
23948 -
23949 \begin_inset ERT
23950 status collapsed
23951
23952 \begin_layout Standard
23953
23954
23955 \backslash
23956 /
23957 \end_layout
23958
23959 \end_inset
23960
23961 -pcode-verbose Enable pcode debugging information in translation.
23962 \end_layout
23963
23964 \begin_layout Description
23965 -
23966 \begin_inset ERT
23967 status collapsed
23968
23969 \begin_layout Standard
23970
23971
23972 \backslash
23973 /
23974 \end_layout
23975
23976 \end_inset
23977
23978 -calltree Dump call tree in .calltree file.
23979 \end_layout
23980
23981 \begin_layout Description
23982 -
23983 \begin_inset ERT
23984 status collapsed
23985
23986 \begin_layout Standard
23987
23988
23989 \backslash
23990 /
23991 \end_layout
23992
23993 \end_inset
23994
23995 -gstack Trace push/pops for stack pointer overflow.
23996 \end_layout
23997
23998 \begin_layout Subsection
23999 Enviroment Variables
24000 \end_layout
24001
24002 \begin_layout Standard
24003 There is a number of enviromental variables that can be used when running
24004  SDCC to enable certain optimizations or force a specific program behaviour.
24005  these variables are primarily for debugging purposes so they can be enabled/dis
24006 abled at will.
24007 \end_layout
24008
24009 \begin_layout Standard
24010 Currently there is only two such variables available:
24011 \end_layout
24012
24013 \begin_layout Description
24014 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
24015  bitfields is optimized by directly loading FSR0 with the address of the
24016  bitfield structure.
24017  Normally SDCC will cast the bitfield structure to a bitfield pointer and
24018  then load FSR0.
24019  This step saves data ram and code space for functions that make heavy use
24020  of bitfields.
24021  (i.e., 80 bytes of code space are saved when compiling malloc.c with this
24022  option).
24023  
24024 \end_layout
24025
24026 \begin_layout Description
24027 NO_REG_OPT Do not perform pCode registers optimization.
24028  This should be used for debugging purposes.
24029  If bugs in the pcode optimizer are found, users can benefit from temporarily
24030  disabling the optimizer until the bug is fixed.
24031 \end_layout
24032
24033 \begin_layout Subsection
24034 Preprocessor Macros
24035 \end_layout
24036
24037 \begin_layout Standard
24038 PIC16
24039 \begin_inset LatexCommand \index{PIC16}
24040
24041 \end_inset
24042
24043  port defines the following preprocessor macros while translating a source.
24044 \end_layout
24045
24046 \begin_layout Standard
24047 \align center
24048 \begin_inset Tabular
24049 <lyxtabular version="3" rows="6" columns="2">
24050 <features>
24051 <column alignment="center" valignment="top" leftline="true" width="0">
24052 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24053 <row topline="true" bottomline="true">
24054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24055 \begin_inset Text
24056
24057 \begin_layout Standard
24058 Macro
24059 \end_layout
24060
24061 \end_inset
24062 </cell>
24063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24064 \begin_inset Text
24065
24066 \begin_layout Standard
24067 Description
24068 \end_layout
24069
24070 \end_inset
24071 </cell>
24072 </row>
24073 <row topline="true">
24074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24075 \begin_inset Text
24076
24077 \begin_layout Standard
24078 SDCC_pic16
24079 \end_layout
24080
24081 \end_inset
24082 </cell>
24083 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24084 \begin_inset Text
24085
24086 \begin_layout Standard
24087 Port identification
24088 \end_layout
24089
24090 \end_inset
24091 </cell>
24092 </row>
24093 <row topline="true">
24094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24095 \begin_inset Text
24096
24097 \begin_layout Standard
24098 _
24099 \begin_inset ERT
24100 status collapsed
24101
24102 \begin_layout Standard
24103
24104
24105 \backslash
24106 /
24107 \end_layout
24108
24109 \end_inset
24110
24111 _pic16
24112 \end_layout
24113
24114 \end_inset
24115 </cell>
24116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24117 \begin_inset Text
24118
24119 \begin_layout Standard
24120 Port identification (same as above)
24121 \end_layout
24122
24123 \end_inset
24124 </cell>
24125 </row>
24126 <row topline="true">
24127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24128 \begin_inset Text
24129
24130 \begin_layout Standard
24131 pic18fxxxx
24132 \end_layout
24133
24134 \end_inset
24135 </cell>
24136 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24137 \begin_inset Text
24138
24139 \begin_layout Standard
24140 MCU Identification.
24141  
24142 \emph on
24143 xxxx
24144 \emph default
24145  is the microcontrol identification number, i.e.
24146  452, 6620, etc
24147 \end_layout
24148
24149 \end_inset
24150 </cell>
24151 </row>
24152 <row topline="true">
24153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24154 \begin_inset Text
24155
24156 \begin_layout Standard
24157 _
24158 \begin_inset ERT
24159 status collapsed
24160
24161 \begin_layout Standard
24162
24163
24164 \backslash
24165 /
24166 \end_layout
24167
24168 \end_inset
24169
24170 _18Fxxxx
24171 \end_layout
24172
24173 \end_inset
24174 </cell>
24175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24176 \begin_inset Text
24177
24178 \begin_layout Standard
24179 MCU Identification (same as above)
24180 \end_layout
24181
24182 \end_inset
24183 </cell>
24184 </row>
24185 <row topline="true" bottomline="true">
24186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24187 \begin_inset Text
24188
24189 \begin_layout Standard
24190 STACK_MODEL_nnn
24191 \end_layout
24192
24193 \end_inset
24194 </cell>
24195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24196 \begin_inset Text
24197
24198 \begin_layout Standard
24199 nnn = SMALL or LARGE respectively according to the stack model used
24200 \end_layout
24201
24202 \end_inset
24203 </cell>
24204 </row>
24205 </lyxtabular>
24206
24207 \end_inset
24208
24209
24210 \end_layout
24211
24212 \begin_layout Standard
24213 In addition the following macros are defined when calling assembler:
24214 \end_layout
24215
24216 \begin_layout Standard
24217 \align center
24218 \begin_inset Tabular
24219 <lyxtabular version="3" rows="4" columns="2">
24220 <features>
24221 <column alignment="center" valignment="top" leftline="true" width="0">
24222 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24223 <row topline="true" bottomline="true">
24224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24225 \begin_inset Text
24226
24227 \begin_layout Standard
24228 Macro
24229 \end_layout
24230
24231 \end_inset
24232 </cell>
24233 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24234 \begin_inset Text
24235
24236 \begin_layout Standard
24237 Description
24238 \end_layout
24239
24240 \end_inset
24241 </cell>
24242 </row>
24243 <row topline="true">
24244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24245 \begin_inset Text
24246
24247 \begin_layout Standard
24248 __18Fxxxx
24249 \end_layout
24250
24251 \end_inset
24252 </cell>
24253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24254 \begin_inset Text
24255
24256 \begin_layout Standard
24257 MCU Identification.
24258  
24259 \emph on
24260 xxxx
24261 \emph default
24262  is the microcontrol identification number, i.e.
24263  452, 6620, etc
24264 \end_layout
24265
24266 \end_inset
24267 </cell>
24268 </row>
24269 <row topline="true">
24270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24271 \begin_inset Text
24272
24273 \begin_layout Standard
24274 SDCC_MODEL_nnn
24275 \end_layout
24276
24277 \end_inset
24278 </cell>
24279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24280 \begin_inset Text
24281
24282 \begin_layout Standard
24283 nnn = SMALL or LARGE respectively according to the memory model used for
24284  SDCC
24285 \end_layout
24286
24287 \end_inset
24288 </cell>
24289 </row>
24290 <row topline="true" bottomline="true">
24291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24292 \begin_inset Text
24293
24294 \begin_layout Standard
24295 STACK_MODEL_nnn
24296 \end_layout
24297
24298 \end_inset
24299 </cell>
24300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24301 \begin_inset Text
24302
24303 \begin_layout Standard
24304 nnn = SMALL or LARGE respectively according to the stack model used
24305 \end_layout
24306
24307 \end_inset
24308 </cell>
24309 </row>
24310 </lyxtabular>
24311
24312 \end_inset
24313
24314
24315 \end_layout
24316
24317 \begin_layout Subsection
24318 Directories
24319 \end_layout
24320
24321 \begin_layout Standard
24322 PIC16
24323 \begin_inset LatexCommand \index{PIC16}
24324
24325 \end_inset
24326
24327  port uses the following directories for searching header files and libraries.
24328 \end_layout
24329
24330 \begin_layout Standard
24331 \align center
24332 \begin_inset Tabular
24333 <lyxtabular version="3" rows="3" columns="4">
24334 <features>
24335 <column alignment="center" valignment="top" leftline="true" width="0">
24336 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24337 <column alignment="center" valignment="top" width="0">
24338 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24339 <row topline="true" bottomline="true">
24340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24341 \begin_inset Text
24342
24343 \begin_layout Standard
24344 Directory
24345 \end_layout
24346
24347 \end_inset
24348 </cell>
24349 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24350 \begin_inset Text
24351
24352 \begin_layout Standard
24353 Description
24354 \end_layout
24355
24356 \end_inset
24357 </cell>
24358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24359 \begin_inset Text
24360
24361 \begin_layout Standard
24362 Target
24363 \end_layout
24364
24365 \end_inset
24366 </cell>
24367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24368 \begin_inset Text
24369
24370 \begin_layout Standard
24371 Command prefix
24372 \end_layout
24373
24374 \end_inset
24375 </cell>
24376 </row>
24377 <row topline="true">
24378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24379 \begin_inset Text
24380
24381 \begin_layout Standard
24382 PREFIX/sdcc/include/pic16
24383 \end_layout
24384
24385 \end_inset
24386 </cell>
24387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24388 \begin_inset Text
24389
24390 \begin_layout Standard
24391 PIC16 specific headers
24392 \end_layout
24393
24394 \end_inset
24395 </cell>
24396 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24397 \begin_inset Text
24398
24399 \begin_layout Standard
24400 Compiler
24401 \end_layout
24402
24403 \end_inset
24404 </cell>
24405 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24406 \begin_inset Text
24407
24408 \begin_layout Standard
24409 -I
24410 \end_layout
24411
24412 \end_inset
24413 </cell>
24414 </row>
24415 <row topline="true" bottomline="true">
24416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24417 \begin_inset Text
24418
24419 \begin_layout Standard
24420 PREFIX/sdcc/lib/pic16
24421 \end_layout
24422
24423 \end_inset
24424 </cell>
24425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24426 \begin_inset Text
24427
24428 \begin_layout Standard
24429 PIC16 specific libraries
24430 \end_layout
24431
24432 \end_inset
24433 </cell>
24434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24435 \begin_inset Text
24436
24437 \begin_layout Standard
24438 Linker
24439 \end_layout
24440
24441 \end_inset
24442 </cell>
24443 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24444 \begin_inset Text
24445
24446 \begin_layout Standard
24447 -L
24448 \end_layout
24449
24450 \end_inset
24451 </cell>
24452 </row>
24453 </lyxtabular>
24454
24455 \end_inset
24456
24457
24458 \end_layout
24459
24460 \begin_layout Subsection
24461 Pragmas
24462 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24463
24464 \end_inset
24465
24466
24467 \end_layout
24468
24469 \begin_layout Standard
24470 The PIC16
24471 \begin_inset LatexCommand \index{PIC16}
24472
24473 \end_inset
24474
24475  port currently supports the following pragmas:
24476 \end_layout
24477
24478 \begin_layout Description
24479 stack
24480 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24481
24482 \end_inset
24483
24484  This forces the code generator to initialize the stack & frame pointers
24485  at a specific address.
24486  This is an ad hoc solution for cases where no STACK directive is available
24487  in the linker script or gplink is not instructed to create a stack section.
24488 \newline
24489 The
24490  stack pragma should be used only once in a project.
24491  Multiple pragmas may result in indeterminate behaviour of the program.
24492 \begin_inset Foot
24493 status open
24494
24495 \begin_layout Standard
24496 The old format (ie.
24497  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24498  cross page boundaries (or even exceed the available data RAM) and crash
24499  the program.
24500  Make sure that stack does not cross page boundaries when using the SMALL
24501  stack model.
24502 \end_layout
24503
24504 \end_inset
24505
24506
24507 \newline
24508 The format is as follows:
24509 \newline
24510
24511 \end_layout
24512
24513 \begin_layout LyX-Code
24514 #pragma stack bottom_address [stack_size]
24515 \newline
24516
24517 \end_layout
24518
24519 \begin_layout Standard
24520
24521 \emph on
24522 bottom_address
24523 \emph default
24524  is the lower bound of the stack section.
24525  The stack pointer initially will point at address (bottom_address+stack_size-1).
24526 \end_layout
24527
24528 \begin_layout LyX-Code
24529 Example:
24530 \end_layout
24531
24532 \begin_layout LyX-Code
24533
24534 \end_layout
24535
24536 \begin_layout LyX-Code
24537 /* initializes stack of 100 bytes at RAM address 0x200 */
24538 \end_layout
24539
24540 \begin_layout LyX-Code
24541 #pragma stack 0x200 100
24542 \end_layout
24543
24544 \begin_layout Standard
24545 If the stack_size field is omitted then a stack is created with the default
24546  size of 64.
24547  This size might be enough for most programs, but its not enough for operations
24548  with deep function nesting or excessive stack usage.
24549 \end_layout
24550
24551 \begin_layout Description
24552 code
24553 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24554
24555 \end_inset
24556
24557  Force a function to a static FLASH address.
24558 \end_layout
24559
24560 \begin_layout LyX-Code
24561 Example:
24562 \end_layout
24563
24564 \begin_layout LyX-Code
24565
24566 \end_layout
24567
24568 \begin_layout LyX-Code
24569 /* place function test_func at 0x4000 */
24570 \end_layout
24571
24572 \begin_layout LyX-Code
24573 #pragma code test_func 0x4000
24574 \end_layout
24575
24576 \begin_layout LyX-Code
24577
24578 \end_layout
24579
24580 \begin_layout Description
24581 library instructs the linker to use a library module.
24582 \newline
24583 Usage:
24584 \end_layout
24585
24586 \begin_layout LyX-Code
24587 #pragma library module_name
24588 \end_layout
24589
24590 \begin_layout Standard
24591
24592 \emph on
24593 module_name
24594 \emph default
24595  can be any library or object file (including its path).
24596  Note that there are four reserved keywords which have special meaning.
24597  These are:
24598 \end_layout
24599
24600 \begin_layout Standard
24601 \align center
24602 \begin_inset Tabular
24603 <lyxtabular version="3" rows="6" columns="3">
24604 <features>
24605 <column alignment="center" valignment="top" leftline="true" width="0">
24606 <column alignment="block" valignment="top" leftline="true" width="20page%">
24607 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24608 <row topline="true" bottomline="true">
24609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24610 \begin_inset Text
24611
24612 \begin_layout Standard
24613 Keyword
24614 \end_layout
24615
24616 \end_inset
24617 </cell>
24618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24619 \begin_inset Text
24620
24621 \begin_layout Standard
24622 Description
24623 \end_layout
24624
24625 \end_inset
24626 </cell>
24627 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24628 \begin_inset Text
24629
24630 \begin_layout Standard
24631 Module to link
24632 \end_layout
24633
24634 \end_inset
24635 </cell>
24636 </row>
24637 <row topline="true">
24638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24639 \begin_inset Text
24640
24641 \begin_layout Standard
24642
24643 \series bold
24644 ignore
24645 \end_layout
24646
24647 \end_inset
24648 </cell>
24649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24650 \begin_inset Text
24651
24652 \begin_layout Standard
24653 ignore all library pragmas
24654 \end_layout
24655
24656 \end_inset
24657 </cell>
24658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24659 \begin_inset Text
24660
24661 \begin_layout Standard
24662
24663 \emph on
24664 (none)
24665 \end_layout
24666
24667 \end_inset
24668 </cell>
24669 </row>
24670 <row topline="true">
24671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24672 \begin_inset Text
24673
24674 \begin_layout Standard
24675
24676 \series bold
24677 c
24678 \end_layout
24679
24680 \end_inset
24681 </cell>
24682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24683 \begin_inset Text
24684
24685 \begin_layout Standard
24686 link the C library
24687 \end_layout
24688
24689 \end_inset
24690 </cell>
24691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24692 \begin_inset Text
24693
24694 \begin_layout Standard
24695
24696 \emph on
24697 libc18f
24698 \emph default
24699 .lib
24700 \end_layout
24701
24702 \end_inset
24703 </cell>
24704 </row>
24705 <row topline="true">
24706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24707 \begin_inset Text
24708
24709 \begin_layout Standard
24710
24711 \series bold
24712 math
24713 \end_layout
24714
24715 \end_inset
24716 </cell>
24717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24718 \begin_inset Text
24719
24720 \begin_layout Standard
24721 link the Math libarary
24722 \end_layout
24723
24724 \end_inset
24725 </cell>
24726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24727 \begin_inset Text
24728
24729 \begin_layout Standard
24730
24731 \emph on
24732 libm18f
24733 \emph default
24734 .lib
24735 \end_layout
24736
24737 \end_inset
24738 </cell>
24739 </row>
24740 <row topline="true">
24741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24742 \begin_inset Text
24743
24744 \begin_layout Standard
24745
24746 \series bold
24747 io
24748 \end_layout
24749
24750 \end_inset
24751 </cell>
24752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24753 \begin_inset Text
24754
24755 \begin_layout Standard
24756 link the I/O library
24757 \end_layout
24758
24759 \end_inset
24760 </cell>
24761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24762 \begin_inset Text
24763
24764 \begin_layout Standard
24765
24766 \emph on
24767 libio18f*
24768 \emph default
24769 .lib
24770 \end_layout
24771
24772 \end_inset
24773 </cell>
24774 </row>
24775 <row topline="true" bottomline="true">
24776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24777 \begin_inset Text
24778
24779 \begin_layout Standard
24780
24781 \series bold
24782 debug
24783 \end_layout
24784
24785 \end_inset
24786 </cell>
24787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24788 \begin_inset Text
24789
24790 \begin_layout Standard
24791 link the debug library
24792 \end_layout
24793
24794 \end_inset
24795 </cell>
24796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24797 \begin_inset Text
24798
24799 \begin_layout Standard
24800
24801 \emph on
24802 libdebug
24803 \emph default
24804 .lib
24805 \end_layout
24806
24807 \end_inset
24808 </cell>
24809 </row>
24810 </lyxtabular>
24811
24812 \end_inset
24813
24814
24815 \newline
24816 * is the device number, i.e.
24817  452 for PIC18F452 MCU.
24818 \end_layout
24819
24820 \begin_layout Standard
24821 This feature allows for linking with specific libraries withoug having to
24822  explicit name them in the command line.
24823  Note that the 
24824 \noun on
24825 ignore
24826 \noun default
24827  keyword will reject all modules specified by the library pragma.
24828 \end_layout
24829
24830 \begin_layout Description
24831 udata The pragma udata instructs the compiler to emit code so that linker
24832  will place a variable at a specific memory bank.
24833 \end_layout
24834
24835 \begin_layout LyX-Code
24836 Example:
24837 \end_layout
24838
24839 \begin_layout LyX-Code
24840
24841 \end_layout
24842
24843 \begin_layout LyX-Code
24844 /* places variable foo at bank2 */
24845 \end_layout
24846
24847 \begin_layout LyX-Code
24848 #pragma udata bank2 foo
24849 \end_layout
24850
24851 \begin_layout LyX-Code
24852 char foo;
24853 \end_layout
24854
24855 \begin_layout Standard
24856 In order for this pragma to work extra SECTION directives should be added
24857  in the .lkr script.
24858  In the following example a sample .lkr file is shown:
24859 \end_layout
24860
24861 \begin_layout LyX-Code
24862
24863 \end_layout
24864
24865 \begin_layout LyX-Code
24866 // Sample linker script for the PIC18F452 processor
24867 \end_layout
24868
24869 \begin_layout LyX-Code
24870 LIBPATH .
24871 \end_layout
24872
24873 \begin_layout LyX-Code
24874 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
24875 \end_layout
24876
24877 \begin_layout LyX-Code
24878 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
24879 \end_layout
24880
24881 \begin_layout LyX-Code
24882 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
24883 \end_layout
24884
24885 \begin_layout LyX-Code
24886 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
24887 \end_layout
24888
24889 \begin_layout LyX-Code
24890 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
24891 \end_layout
24892
24893 \begin_layout LyX-Code
24894 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
24895 \end_layout
24896
24897 \begin_layout LyX-Code
24898 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
24899 \end_layout
24900
24901 \begin_layout LyX-Code
24902
24903 \end_layout
24904
24905 \begin_layout LyX-Code
24906 DATABANK   NAME=gpr0       START=0x80           END=0xFF
24907 \end_layout
24908
24909 \begin_layout LyX-Code
24910 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
24911 \end_layout
24912
24913 \begin_layout LyX-Code
24914 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
24915 \end_layout
24916
24917 \begin_layout LyX-Code
24918 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
24919 \end_layout
24920
24921 \begin_layout LyX-Code
24922 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
24923 \end_layout
24924
24925 \begin_layout LyX-Code
24926 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
24927 \end_layout
24928
24929 \begin_layout LyX-Code
24930 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
24931 \end_layout
24932
24933 \begin_layout LyX-Code
24934
24935 \end_layout
24936
24937 \begin_layout LyX-Code
24938 SECTION    NAME=CONFIG     ROM=config
24939 \end_layout
24940
24941 \begin_layout LyX-Code
24942
24943 \end_layout
24944
24945 \begin_layout LyX-Code
24946 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
24947 \end_layout
24948
24949 \begin_layout LyX-Code
24950 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
24951 \end_layout
24952
24953 \begin_layout LyX-Code
24954 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
24955 \end_layout
24956
24957 \begin_layout LyX-Code
24958 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
24959 \end_layout
24960
24961 \begin_layout LyX-Code
24962 SECTION    NAME=bank4      RAM=gpr4
24963 \end_layout
24964
24965 \begin_layout LyX-Code
24966 SECTION    NAME=bank5      RAM=gpr5
24967 \end_layout
24968
24969 \begin_layout Standard
24970 The linker will recognise the section name set in the pragma statement and
24971  will position the variable at the memory bank set with the RAM field at
24972  the SECTION line in the linker script file.
24973 \end_layout
24974
24975 \begin_layout Subsection
24976 Header Files
24977 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
24978
24979 \end_inset
24980
24981
24982 \end_layout
24983
24984 \begin_layout Standard
24985 There is one main header file
24986 \begin_inset LatexCommand \index{PIC16!Header files}
24987
24988 \end_inset
24989
24990  that can be included to the source files using the pic16
24991 \begin_inset LatexCommand \index{PIC16}
24992
24993 \end_inset
24994
24995  port.
24996  That file is the 
24997 \series bold
24998 pic18fregs.h
24999 \series default
25000 .
25001  This header file contains the definitions for the processor special registers,
25002  so it is necessary if the source accesses them.
25003  It can be included by adding the following line in the beginning of the
25004  file:
25005 \end_layout
25006
25007 \begin_layout LyX-Code
25008 #include <pic18fregs.h>
25009 \end_layout
25010
25011 \begin_layout Standard
25012 The specific microcontroller is selected within the pic18fregs.h automatically,
25013  so the same source can be used with a variety of devices.
25014 \end_layout
25015
25016 \begin_layout Subsection
25017 Libraries
25018 \end_layout
25019
25020 \begin_layout Standard
25021 The libraries
25022 \begin_inset LatexCommand \index{PIC16!Libraries}
25023
25024 \end_inset
25025
25026  that PIC16
25027 \begin_inset LatexCommand \index{PIC16}
25028
25029 \end_inset
25030
25031  port depends on are the microcontroller device libraries which contain
25032  the symbol definitions for the microcontroller special function registers.
25033  These libraries have the format pic18fxxxx.lib, where 
25034 \emph on
25035 xxxx
25036 \emph default
25037  is the microcontroller identification number.
25038  The specific library is selected automatically by the compiler at link
25039  stage according to the selected device.
25040 \end_layout
25041
25042 \begin_layout Standard
25043 Libraries are created with gplib which is part of the gputils package 
25044 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
25045
25046 \end_inset
25047
25048 .
25049 \end_layout
25050
25051 \begin_layout Subsubsection*
25052 Building the libraries
25053 \end_layout
25054
25055 \begin_layout Standard
25056 Before using SDCC/pic16 there are some libraries that need to be compiled.
25057  This process is not done automatically by SDCC since not all users use
25058  SDCC for pic16 projects.
25059  So each user should compile the libraries separately.
25060 \end_layout
25061
25062 \begin_layout Standard
25063 The steps to compile the pic16 libraries under Linux and Mac OS X are:
25064 \end_layout
25065
25066 \begin_layout LyX-Code
25067 cd device/lib/pic16
25068 \end_layout
25069
25070 \begin_layout LyX-Code
25071 ./configure
25072 \end_layout
25073
25074 \begin_layout LyX-Code
25075 make
25076 \end_layout
25077
25078 \begin_layout LyX-Code
25079 cd ..
25080 \end_layout
25081
25082 \begin_layout LyX-Code
25083 make model-pic16
25084 \end_layout
25085
25086 \begin_layout LyX-Code
25087 su -c 'make install'     # install the libraries, you need the root password
25088 \end_layout
25089
25090 \begin_layout Standard
25091 If you need to install the headers too, do:
25092 \end_layout
25093
25094 \begin_layout LyX-Code
25095 cd device/include
25096 \end_layout
25097
25098 \begin_layout LyX-Code
25099 su -c 'make install'     # install the headers, you need the root password
25100 \end_layout
25101
25102 \begin_layout Standard
25103 There exist a special target to build the I/O libraries.
25104  This target is not automatically build because it will build the I/O library
25105  for 
25106 \emph on
25107 every
25108 \emph default
25109  supported device.
25110  This way building will take quite a lot of time.
25111  Users are advised to edit the 
25112 \series bold
25113 device/lib/pic16/pics.build
25114 \series default
25115  file and then execute:
25116 \end_layout
25117
25118 \begin_layout LyX-Code
25119 make lib-io
25120 \end_layout
25121
25122 \begin_layout Subsection
25123 Adding New Devices to the Port
25124 \end_layout
25125
25126 \begin_layout Standard
25127 Adding support for a new 16
25128 \begin_inset ERT
25129 status open
25130
25131 \begin_layout Standard
25132
25133
25134 \backslash
25135 ,
25136 \end_layout
25137
25138 \end_inset
25139
25140 bit PIC MCU requires the following steps:
25141 \end_layout
25142
25143 \begin_layout Enumerate
25144 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
25145 \newline
25146
25147 \family typewriter
25148 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
25149 inc
25150 \end_layout
25151
25152 \begin_layout Enumerate
25153
25154 \family typewriter
25155 mv picDEVICE.h /path/to/sdcc/device/include/pic16
25156 \end_layout
25157
25158 \begin_layout Enumerate
25159
25160 \family typewriter
25161 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
25162 \end_layout
25163
25164 \begin_layout Enumerate
25165 Add DEVICE to 
25166 \family typewriter
25167 /path/to/sdcc/device/lib/pics.all
25168 \family default
25169  (and 
25170 \family typewriter
25171 .build
25172 \family default
25173 ).
25174 \newline
25175 Note: No 18f prefix here!
25176 \end_layout
25177
25178 \begin_layout Enumerate
25179 Adjust 
25180 \family typewriter
25181 /path/to/sdcc/device/lib/pic16/libio/*.ignore
25182 \family default
25183
25184 \newline
25185 Add your DEVICE if it does not compile in 
25186 \family typewriter
25187 adc
25188 \family default
25189
25190 \family typewriter
25191 i2c
25192 \family default
25193 , or 
25194 \family typewriter
25195 usart
25196 \family default
25197 .
25198 \end_layout
25199
25200 \begin_layout Enumerate
25201 Edit 
25202 \family typewriter
25203 /path/to/sdcc/device/include/pic16/pic18fregs.h
25204 \family default
25205 .
25206  The file format is self-explanatory, just add
25207 \newline
25208
25209 \family typewriter
25210 #elif defined(picDEVICE)
25211 \newline
25212 # include <picDEVICE.h>
25213 \family default
25214
25215 \newline
25216 at the right place (keep it sorted).
25217 \end_layout
25218
25219 \begin_layout Enumerate
25220 Edit 
25221 \family typewriter
25222 /path/to/sdcc/src/pic16/devices.inc
25223 \family default
25224 .
25225  Copy and modify an existing entry and insert it at the correct place (keep
25226  the file sorted).
25227  The file is hardly documented, look at the entries for the 18f2221...
25228 \end_layout
25229
25230 \begin_layout Enumerate
25231 Recompile SDCC, including the pic16 libraries.
25232 \end_layout
25233
25234 \begin_layout Subsection
25235 Memory Models
25236 \end_layout
25237
25238 \begin_layout Standard
25239 The following memory models are supported by the PIC16 port:
25240 \end_layout
25241
25242 \begin_layout Itemize
25243 small model
25244 \end_layout
25245
25246 \begin_layout Itemize
25247 large model
25248 \end_layout
25249
25250 \begin_layout Standard
25251 Memory model affects the default size of pointers within the source.
25252  The sizes are shown in the next table:
25253 \end_layout
25254
25255 \begin_layout Standard
25256 \align center
25257 \begin_inset Tabular
25258 <lyxtabular version="3" rows="3" columns="3">
25259 <features>
25260 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25261 <column alignment="center" valignment="top" leftline="true" width="0">
25262 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25263 <row topline="true" bottomline="true">
25264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25265 \begin_inset Text
25266
25267 \begin_layout Standard
25268 Pointer sizes according to memory model
25269 \end_layout
25270
25271 \end_inset
25272 </cell>
25273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25274 \begin_inset Text
25275
25276 \begin_layout Standard
25277 small model
25278 \end_layout
25279
25280 \end_inset
25281 </cell>
25282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25283 \begin_inset Text
25284
25285 \begin_layout Standard
25286 large model
25287 \end_layout
25288
25289 \end_inset
25290 </cell>
25291 </row>
25292 <row topline="true" bottomline="true">
25293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25294 \begin_inset Text
25295
25296 \begin_layout Standard
25297 code pointers
25298 \end_layout
25299
25300 \end_inset
25301 </cell>
25302 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25303 \begin_inset Text
25304
25305 \begin_layout Standard
25306 16-bits
25307 \end_layout
25308
25309 \end_inset
25310 </cell>
25311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25312 \begin_inset Text
25313
25314 \begin_layout Standard
25315 24-bits
25316 \end_layout
25317
25318 \end_inset
25319 </cell>
25320 </row>
25321 <row topline="true" bottomline="true">
25322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25323 \begin_inset Text
25324
25325 \begin_layout Standard
25326 data pointers
25327 \end_layout
25328
25329 \end_inset
25330 </cell>
25331 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
25332 \begin_inset Text
25333
25334 \begin_layout Standard
25335 16-bits
25336 \end_layout
25337
25338 \end_inset
25339 </cell>
25340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25341 \begin_inset Text
25342
25343 \begin_layout Standard
25344 16-bits
25345 \end_layout
25346
25347 \end_inset
25348 </cell>
25349 </row>
25350 </lyxtabular>
25351
25352 \end_inset
25353
25354
25355 \end_layout
25356
25357 \begin_layout Standard
25358 It is advisable that all sources within a project are compiled with the
25359  same memory model.
25360  If one wants to override the default memory model, this can be done by
25361  declaring a pointer as 
25362 \series bold
25363 far
25364 \series default
25365  or 
25366 \series bold
25367 near
25368 \series default
25369 .
25370  Far selects large memory model's pointers, while near selects small memory
25371  model's pointers.
25372 \end_layout
25373
25374 \begin_layout Standard
25375 The standard device libraries (see 
25376 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25377
25378 \end_inset
25379
25380 ) contain no reference to pointers, so they can be used with both memory
25381  models.
25382 \end_layout
25383
25384 \begin_layout Subsection
25385 Stack
25386 \end_layout
25387
25388 \begin_layout Standard
25389 The stack
25390 \begin_inset LatexCommand \index{PIC16!stack}
25391
25392 \end_inset
25393
25394  implementation for the PIC16 port uses two indirect registers, FSR1 and
25395  FSR2.
25396 \end_layout
25397
25398 \begin_layout Description
25399 FSR1 is assigned as stack pointer
25400 \end_layout
25401
25402 \begin_layout Description
25403 FSR2 is assigned as frame pointer
25404 \end_layout
25405
25406 \begin_layout Standard
25407 The following stack models are supported by the PIC16 port
25408 \end_layout
25409
25410 \begin_layout Itemize
25411
25412 \noun on
25413 small
25414 \noun default
25415  model
25416 \end_layout
25417
25418 \begin_layout Itemize
25419
25420 \noun on
25421 large
25422 \noun default
25423  model
25424 \end_layout
25425
25426 \begin_layout Standard
25427
25428 \noun on
25429 Small
25430 \noun default
25431  model means that only the FSRxL byte is used to access stack and frame,
25432  while 
25433 \emph on
25434 \noun on
25435 large
25436 \emph default
25437 \noun default
25438  uses both FSRxL and FSRxH registers.
25439  The following table shows the stack/frame pointers sizes according to stack
25440  model and the maximum space they can address:
25441 \end_layout
25442
25443 \begin_layout Standard
25444 \align center
25445 \begin_inset Tabular
25446 <lyxtabular version="3" rows="3" columns="3">
25447 <features>
25448 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25449 <column alignment="center" valignment="top" leftline="true" width="0">
25450 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25451 <row topline="true" bottomline="true">
25452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25453 \begin_inset Text
25454
25455 \begin_layout Standard
25456 Stack & Frame pointer sizes according to stack model
25457 \end_layout
25458
25459 \end_inset
25460 </cell>
25461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25462 \begin_inset Text
25463
25464 \begin_layout Standard
25465 small
25466 \end_layout
25467
25468 \end_inset
25469 </cell>
25470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25471 \begin_inset Text
25472
25473 \begin_layout Standard
25474 large
25475 \end_layout
25476
25477 \end_inset
25478 </cell>
25479 </row>
25480 <row topline="true">
25481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25482 \begin_inset Text
25483
25484 \begin_layout Standard
25485 Stack pointer FSR1
25486 \end_layout
25487
25488 \end_inset
25489 </cell>
25490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25491 \begin_inset Text
25492
25493 \begin_layout Standard
25494 8-bits
25495 \end_layout
25496
25497 \end_inset
25498 </cell>
25499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25500 \begin_inset Text
25501
25502 \begin_layout Standard
25503 16-bits
25504 \end_layout
25505
25506 \end_inset
25507 </cell>
25508 </row>
25509 <row topline="true" bottomline="true">
25510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25511 \begin_inset Text
25512
25513 \begin_layout Standard
25514 Frame pointer FSR2
25515 \end_layout
25516
25517 \end_inset
25518 </cell>
25519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25520 \begin_inset Text
25521
25522 \begin_layout Standard
25523 8-bits
25524 \end_layout
25525
25526 \end_inset
25527 </cell>
25528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25529 \begin_inset Text
25530
25531 \begin_layout Standard
25532 16-bits
25533 \end_layout
25534
25535 \end_inset
25536 </cell>
25537 </row>
25538 </lyxtabular>
25539
25540 \end_inset
25541
25542
25543 \end_layout
25544
25545 \begin_layout Standard
25546
25547 \noun on
25548 Large 
25549 \noun default
25550 stack model is currently not working properly throughout the code generator.
25551  So its use is not advised.
25552  Also there are some other points that need special care:
25553 \newline
25554
25555 \end_layout
25556
25557 \begin_layout Enumerate
25558 Do not create stack sections with size more than one physical bank (that
25559  is 256 bytes)
25560 \end_layout
25561
25562 \begin_layout Enumerate
25563 Stack sections should no cross physical bank limits (i.e.
25564  #pragma stack 0x50 0x100)
25565 \end_layout
25566
25567 \begin_layout Standard
25568 These limitations are caused by the fact that only FSRxL is modified when
25569  using SMALL stack model, so no more than 256 bytes of stack can be used.
25570  This problem will disappear after LARGE model is fully implemented.
25571 \end_layout
25572
25573 \begin_layout Subsection
25574 Functions
25575 \end_layout
25576
25577 \begin_layout Standard
25578 In addition to the standard SDCC function keywords, PIC16
25579 \begin_inset LatexCommand \index{PIC16}
25580
25581 \end_inset
25582
25583  port makes available two more:
25584 \end_layout
25585
25586 \begin_layout Description
25587 wparam
25588 \begin_inset LatexCommand \index{PIC16!wparam}
25589
25590 \end_inset
25591
25592  Use the WREG to pass one byte of the first function argument.
25593  This improves speed but you may not use this for functions with arguments
25594  that are called via function pointers, otherwise the first byte of the
25595  first parameter will get lost.
25596  Usage:
25597 \end_layout
25598
25599 \begin_layout LyX-Code
25600 void func_wparam(int a) wparam
25601 \end_layout
25602
25603 \begin_layout LyX-Code
25604 {
25605 \end_layout
25606
25607 \begin_layout LyX-Code
25608     /* WREG hold the lower part of a */
25609 \end_layout
25610
25611 \begin_layout LyX-Code
25612     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25613  */
25614 \end_layout
25615
25616 \begin_layout LyX-Code
25617 ...
25618 \end_layout
25619
25620 \begin_layout LyX-Code
25621 }
25622 \end_layout
25623
25624 \begin_layout Description
25625 shadowregs
25626 \begin_inset LatexCommand \index{PIC16!shadowregs}
25627
25628 \end_inset
25629
25630  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25631  hardware shadow registers which hold the values of WREG, STATUS and BSR
25632  registers.
25633  This can be done by adding the keyword 
25634 \emph on
25635 shadowregs
25636 \emph default
25637  before the 
25638 \emph on
25639 interrupt
25640 \emph default
25641  keyword in the function's header.
25642 \end_layout
25643
25644 \begin_layout LyX-Code
25645 void isr_shadow(void) shadowregs interrupt 1
25646 \end_layout
25647
25648 \begin_layout LyX-Code
25649 {
25650 \end_layout
25651
25652 \begin_layout LyX-Code
25653 ...
25654 \end_layout
25655
25656 \begin_layout LyX-Code
25657 }
25658 \end_layout
25659
25660 \begin_layout Standard
25661
25662 \emph on
25663 shadowregs
25664 \emph default
25665  instructs the code generator not to store/restore WREG, STATUS, BSR when
25666  entering/exiting the ISR.
25667 \end_layout
25668
25669 \begin_layout Subsection
25670 Function return values
25671 \end_layout
25672
25673 \begin_layout Standard
25674 Return values from functions are placed to the appropriate registers following
25675  a modified Microchip policy optimized for SDCC.
25676  The following table shows these registers:
25677 \end_layout
25678
25679 \begin_layout Standard
25680 \align center
25681 \begin_inset Tabular
25682 <lyxtabular version="3" rows="6" columns="2">
25683 <features>
25684 <column alignment="center" valignment="top" leftline="true" width="0">
25685 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25686 <row topline="true" bottomline="true">
25687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25688 \begin_inset Text
25689
25690 \begin_layout Standard
25691 size
25692 \end_layout
25693
25694 \end_inset
25695 </cell>
25696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25697 \begin_inset Text
25698
25699 \begin_layout Standard
25700 destination register
25701 \end_layout
25702
25703 \end_inset
25704 </cell>
25705 </row>
25706 <row topline="true">
25707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25708 \begin_inset Text
25709
25710 \begin_layout Standard
25711 8 bits
25712 \end_layout
25713
25714 \end_inset
25715 </cell>
25716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25717 \begin_inset Text
25718
25719 \begin_layout Standard
25720 WREG
25721 \end_layout
25722
25723 \end_inset
25724 </cell>
25725 </row>
25726 <row topline="true">
25727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25728 \begin_inset Text
25729
25730 \begin_layout Standard
25731 16 bits
25732 \end_layout
25733
25734 \end_inset
25735 </cell>
25736 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25737 \begin_inset Text
25738
25739 \begin_layout Standard
25740 PRODL:WREG
25741 \end_layout
25742
25743 \end_inset
25744 </cell>
25745 </row>
25746 <row topline="true">
25747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25748 \begin_inset Text
25749
25750 \begin_layout Standard
25751 24 bits
25752 \end_layout
25753
25754 \end_inset
25755 </cell>
25756 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25757 \begin_inset Text
25758
25759 \begin_layout Standard
25760 PRODH:PRODL:WREG
25761 \end_layout
25762
25763 \end_inset
25764 </cell>
25765 </row>
25766 <row topline="true">
25767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25768 \begin_inset Text
25769
25770 \begin_layout Standard
25771 32 bits
25772 \end_layout
25773
25774 \end_inset
25775 </cell>
25776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25777 \begin_inset Text
25778
25779 \begin_layout Standard
25780 FSR0L:PRODH:PRODL:WREG
25781 \end_layout
25782
25783 \end_inset
25784 </cell>
25785 </row>
25786 <row topline="true" bottomline="true">
25787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25788 \begin_inset Text
25789
25790 \begin_layout Standard
25791 >32 bits
25792 \end_layout
25793
25794 \end_inset
25795 </cell>
25796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25797 \begin_inset Text
25798
25799 \begin_layout Standard
25800 on stack, FSR0 points to the beginning
25801 \end_layout
25802
25803 \end_inset
25804 </cell>
25805 </row>
25806 </lyxtabular>
25807
25808 \end_inset
25809
25810
25811 \end_layout
25812
25813 \begin_layout Subsection
25814 Interrupts
25815 \end_layout
25816
25817 \begin_layout Standard
25818 An interrupt
25819 \begin_inset LatexCommand \index{PIC16!interrupt}
25820
25821 \end_inset
25822
25823  service routine (ISR) is declared using the 
25824 \emph on
25825 interrupt
25826 \emph default
25827  keyword.
25828 \end_layout
25829
25830 \begin_layout LyX-Code
25831 void isr(void) interrupt 
25832 \emph on
25833 n
25834 \end_layout
25835
25836 \begin_layout LyX-Code
25837 {
25838 \end_layout
25839
25840 \begin_layout LyX-Code
25841 ...
25842 \end_layout
25843
25844 \begin_layout LyX-Code
25845 }
25846 \end_layout
25847
25848 \begin_layout Standard
25849
25850 \emph on
25851 n
25852 \emph default
25853  is the interrupt number, which for PIC18F devices can be:
25854 \end_layout
25855
25856 \begin_layout Standard
25857 \align center
25858 \begin_inset Tabular
25859 <lyxtabular version="3" rows="4" columns="3">
25860 <features>
25861 <column alignment="center" valignment="top" leftline="true" width="0">
25862 <column alignment="center" valignment="top" leftline="true" width="0">
25863 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25864 <row topline="true" bottomline="true">
25865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25866 \begin_inset Text
25867
25868 \begin_layout Standard
25869
25870 \emph on
25871 n
25872 \end_layout
25873
25874 \end_inset
25875 </cell>
25876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25877 \begin_inset Text
25878
25879 \begin_layout Standard
25880 Interrupt Vector
25881 \end_layout
25882
25883 \end_inset
25884 </cell>
25885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25886 \begin_inset Text
25887
25888 \begin_layout Standard
25889 Interrupt Vector Address
25890 \end_layout
25891
25892 \end_inset
25893 </cell>
25894 </row>
25895 <row topline="true">
25896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25897 \begin_inset Text
25898
25899 \begin_layout Standard
25900 0
25901 \end_layout
25902
25903 \end_inset
25904 </cell>
25905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25906 \begin_inset Text
25907
25908 \begin_layout Standard
25909 RESET vector
25910 \end_layout
25911
25912 \end_inset
25913 </cell>
25914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25915 \begin_inset Text
25916
25917 \begin_layout Standard
25918 0x000000
25919 \end_layout
25920
25921 \end_inset
25922 </cell>
25923 </row>
25924 <row topline="true">
25925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25926 \begin_inset Text
25927
25928 \begin_layout Standard
25929
25930 \family roman
25931 \series medium
25932 \shape up
25933 \size normal
25934 \emph off
25935 \bar no
25936 \noun off
25937 \color none
25938 1
25939 \end_layout
25940
25941 \end_inset
25942 </cell>
25943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25944 \begin_inset Text
25945
25946 \begin_layout Standard
25947
25948 \family roman
25949 \series medium
25950 \shape up
25951 \size normal
25952 \emph off
25953 \bar no
25954 \noun off
25955 \color none
25956 HIGH priority interrupts
25957 \end_layout
25958
25959 \end_inset
25960 </cell>
25961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25962 \begin_inset Text
25963
25964 \begin_layout Standard
25965 0x000008
25966 \end_layout
25967
25968 \end_inset
25969 </cell>
25970 </row>
25971 <row topline="true" bottomline="true">
25972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25973 \begin_inset Text
25974
25975 \begin_layout Standard
25976 2
25977 \end_layout
25978
25979 \end_inset
25980 </cell>
25981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25982 \begin_inset Text
25983
25984 \begin_layout Standard
25985 LOW priority interrupts
25986 \end_layout
25987
25988 \end_inset
25989 </cell>
25990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25991 \begin_inset Text
25992
25993 \begin_layout Standard
25994 0x000018
25995 \end_layout
25996
25997 \end_inset
25998 </cell>
25999 </row>
26000 </lyxtabular>
26001
26002 \end_inset
26003
26004
26005 \end_layout
26006
26007 \begin_layout Standard
26008 When generating assembly code for ISR the code generator places a 
26009 \noun on
26010 goto 
26011 \noun default
26012 instruction at the 
26013 \emph on
26014 Interrupt Vector Address
26015 \emph default
26016  which points at the genetated ISR.
26017  This single GOTO instruction is part of an automatically generated 
26018 \emph on
26019 interrupt entry point
26020 \emph default
26021  function.
26022  The actuall ISR code is placed as normally would in the code space.
26023  Upon interrupt request, the GOTO instruction is executed which jumps to
26024  the ISR code.
26025  When declaring interrupt functions as _naked this GOTO instruction is 
26026 \series bold
26027 not
26028 \series default
26029  generated.
26030  The whole interrupt functions is therefore placed at the Interrupt Vector
26031  Address of the specific interrupt.
26032  This is not a problem for the LOW priority interrupts, but it is a problem
26033  for the RESET and the HIGH priority interrupts because code may be written
26034  at the next interrupt´s vector address and cause undeterminate program
26035  behaviour if that interrupt is raised.
26036 \begin_inset Foot
26037 status open
26038
26039 \begin_layout Standard
26040 This is not a problem when
26041 \end_layout
26042
26043 \begin_layout Enumerate
26044 this is a HIGH interrupt ISR and LOW interrupts are 
26045 \emph on
26046 disabled
26047 \emph default
26048  or not used.
26049 \end_layout
26050
26051 \begin_layout Enumerate
26052 when the ISR is small enough not to reach the next interrupt´s vector address.
26053 \end_layout
26054
26055 \end_inset
26056
26057
26058 \end_layout
26059
26060 \begin_layout Standard
26061
26062 \emph on
26063 n
26064 \emph default
26065  is possible to be omitted.
26066  This way a function is generated similar to an ISR, but it is not assigned
26067  to any interrupt.
26068 \end_layout
26069
26070 \begin_layout Standard
26071 When entering an interrupt, currently the PIC16
26072 \begin_inset LatexCommand \index{PIC16}
26073
26074 \end_inset
26075
26076  port automatically saves the following registers:
26077 \end_layout
26078
26079 \begin_layout Itemize
26080 WREG
26081 \end_layout
26082
26083 \begin_layout Itemize
26084 STATUS
26085 \end_layout
26086
26087 \begin_layout Itemize
26088 BSR
26089 \end_layout
26090
26091 \begin_layout Itemize
26092 PROD (PRODL and PRODH)
26093 \end_layout
26094
26095 \begin_layout Itemize
26096 FSR0 (FSR0L and FSR0H)
26097 \end_layout
26098
26099 \begin_layout Standard
26100 These registers are restored upon return from the interrupt routine.
26101 \begin_inset Foot
26102 status open
26103
26104 \begin_layout Standard
26105 NOTE that when the _naked attribute is specified for an interrupt routine,
26106  then NO registers are stored or restored.
26107 \end_layout
26108
26109 \end_inset
26110
26111
26112 \end_layout
26113
26114 \begin_layout Subsection
26115 Generic Pointers
26116 \end_layout
26117
26118 \begin_layout Standard
26119 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
26120  There are 3 types of generic pointers currently implemented data, code
26121  and eeprom pointers.
26122  They are differentiated by the value of the 7th and 6th bits of the upper
26123  byte:
26124 \end_layout
26125
26126 \begin_layout Standard
26127 \align center
26128 \begin_inset Tabular
26129 <lyxtabular version="3" rows="5" columns="5">
26130 <features>
26131 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26132 <column alignment="center" valignment="top" width="0">
26133 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26134 <column alignment="center" valignment="top" width="0">
26135 <column alignment="left" valignment="top" rightline="true" width="0">
26136 <row topline="true" bottomline="true">
26137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26138 \begin_inset Text
26139
26140 \begin_layout Standard
26141 pointer type
26142 \end_layout
26143
26144 \end_inset
26145 </cell>
26146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26147 \begin_inset Text
26148
26149 \begin_layout Standard
26150 7th bit
26151 \end_layout
26152
26153 \end_inset
26154 </cell>
26155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26156 \begin_inset Text
26157
26158 \begin_layout Standard
26159 6th bit
26160 \end_layout
26161
26162 \end_inset
26163 </cell>
26164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26165 \begin_inset Text
26166
26167 \begin_layout Standard
26168 rest of the pointer
26169 \end_layout
26170
26171 \end_inset
26172 </cell>
26173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26174 \begin_inset Text
26175
26176 \begin_layout Standard
26177 description
26178 \end_layout
26179
26180 \end_inset
26181 </cell>
26182 </row>
26183 <row topline="true" bottomline="true">
26184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26185 \begin_inset Text
26186
26187 \begin_layout Standard
26188 data 
26189 \end_layout
26190
26191 \end_inset
26192 </cell>
26193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26194 \begin_inset Text
26195
26196 \begin_layout Standard
26197 1
26198 \end_layout
26199
26200 \end_inset
26201 </cell>
26202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26203 \begin_inset Text
26204
26205 \begin_layout Standard
26206 0
26207 \end_layout
26208
26209 \end_inset
26210 </cell>
26211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26212 \begin_inset Text
26213
26214 \begin_layout Standard
26215
26216 \family typewriter
26217 \shape slanted
26218 \emph on
26219 uuuuuu uuuuxxxx xxxxxxxx
26220 \end_layout
26221
26222 \end_inset
26223 </cell>
26224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26225 \begin_inset Text
26226
26227 \begin_layout Standard
26228 a 12-bit data pointer in data RAM memory
26229 \end_layout
26230
26231 \end_inset
26232 </cell>
26233 </row>
26234 <row bottomline="true">
26235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26236 \begin_inset Text
26237
26238 \begin_layout Standard
26239 code
26240 \end_layout
26241
26242 \end_inset
26243 </cell>
26244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26245 \begin_inset Text
26246
26247 \begin_layout Standard
26248 0
26249 \end_layout
26250
26251 \end_inset
26252 </cell>
26253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26254 \begin_inset Text
26255
26256 \begin_layout Standard
26257 0
26258 \end_layout
26259
26260 \end_inset
26261 </cell>
26262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26263 \begin_inset Text
26264
26265 \begin_layout Standard
26266
26267 \family typewriter
26268 \shape slanted
26269 \emph on
26270 uxxxxx xxxxxxxx xxxxxxxx
26271 \end_layout
26272
26273 \end_inset
26274 </cell>
26275 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26276 \begin_inset Text
26277
26278 \begin_layout Standard
26279 a 21-bit code pointer in FLASH memory
26280 \end_layout
26281
26282 \end_inset
26283 </cell>
26284 </row>
26285 <row bottomline="true">
26286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26287 \begin_inset Text
26288
26289 \begin_layout Standard
26290 eeprom
26291 \end_layout
26292
26293 \end_inset
26294 </cell>
26295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26296 \begin_inset Text
26297
26298 \begin_layout Standard
26299 0
26300 \end_layout
26301
26302 \end_inset
26303 </cell>
26304 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26305 \begin_inset Text
26306
26307 \begin_layout Standard
26308 1
26309 \end_layout
26310
26311 \end_inset
26312 </cell>
26313 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26314 \begin_inset Text
26315
26316 \begin_layout Standard
26317
26318 \family typewriter
26319 \shape slanted
26320 \emph on
26321 uuuuuu uuuuuuxx xxxxxxxx
26322 \end_layout
26323
26324 \end_inset
26325 </cell>
26326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26327 \begin_inset Text
26328
26329 \begin_layout Standard
26330 a 10-bit eeprom pointer in EEPROM memory
26331 \end_layout
26332
26333 \end_inset
26334 </cell>
26335 </row>
26336 <row bottomline="true">
26337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26338 \begin_inset Text
26339
26340 \begin_layout Standard
26341 (unimplemented)
26342 \end_layout
26343
26344 \end_inset
26345 </cell>
26346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26347 \begin_inset Text
26348
26349 \begin_layout Standard
26350 1
26351 \end_layout
26352
26353 \end_inset
26354 </cell>
26355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26356 \begin_inset Text
26357
26358 \begin_layout Standard
26359 1
26360 \end_layout
26361
26362 \end_inset
26363 </cell>
26364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26365 \begin_inset Text
26366
26367 \begin_layout Standard
26368
26369 \family typewriter
26370 \shape slanted
26371 \emph on
26372 xxxxxx xxxxxxxx xxxxxxxx
26373 \end_layout
26374
26375 \end_inset
26376 </cell>
26377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26378 \begin_inset Text
26379
26380 \begin_layout Standard
26381 unimplemented pointer type
26382 \end_layout
26383
26384 \end_inset
26385 </cell>
26386 </row>
26387 </lyxtabular>
26388
26389 \end_inset
26390
26391
26392 \end_layout
26393
26394 \begin_layout Standard
26395 Generic pointer are read and written with a set of library functions which
26396  read/write 1, 2, 3, 4 bytes.
26397 \end_layout
26398
26399 \begin_layout Subsection
26400 PIC16 C Libraries
26401 \end_layout
26402
26403 \begin_layout Subsubsection
26404 Standard I/O Streams
26405 \end_layout
26406
26407 \begin_layout Standard
26408 In the 
26409 \emph on
26410 stdio.h
26411 \emph default
26412  the type FILE is defined as:
26413 \end_layout
26414
26415 \begin_layout LyX-Code
26416 typedef char * FILE;
26417 \end_layout
26418
26419 \begin_layout Standard
26420 This type is the stream type implemented I/O in the PIC18F devices.
26421  Also the standard input and output streams are declared in stdio.h:
26422 \end_layout
26423
26424 \begin_layout LyX-Code
26425 extern FILE * stdin;
26426 \end_layout
26427
26428 \begin_layout LyX-Code
26429 extern FILE * stdout;
26430 \end_layout
26431
26432 \begin_layout Standard
26433 The FILE type is actually a generic pointer which defines one more type
26434  of generic pointers, the 
26435 \emph on
26436 stream 
26437 \emph default
26438 pointer.
26439  This new type has the format:
26440 \end_layout
26441
26442 \begin_layout Standard
26443 \align center
26444 \begin_inset Tabular
26445 <lyxtabular version="3" rows="2" columns="7">
26446 <features>
26447 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26448 <column alignment="center" valignment="top" width="0">
26449 <column alignment="center" valignment="top" leftline="true" width="0">
26450 <column alignment="center" valignment="top" leftline="true" width="0">
26451 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26452 <column alignment="center" valignment="top" width="0">
26453 <column alignment="left" valignment="top" rightline="true" width="0">
26454 <row topline="true" bottomline="true">
26455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26456 \begin_inset Text
26457
26458 \begin_layout Standard
26459 pointer type
26460 \end_layout
26461
26462 \end_inset
26463 </cell>
26464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26465 \begin_inset Text
26466
26467 \begin_layout Standard
26468 <7:6>
26469 \end_layout
26470
26471 \end_inset
26472 </cell>
26473 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26474 \begin_inset Text
26475
26476 \begin_layout Standard
26477 <5>
26478 \end_layout
26479
26480 \end_inset
26481 </cell>
26482 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26483 \begin_inset Text
26484
26485 \begin_layout Standard
26486 <4>
26487 \end_layout
26488
26489 \end_inset
26490 </cell>
26491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26492 \begin_inset Text
26493
26494 \begin_layout Standard
26495 <3:0>
26496 \end_layout
26497
26498 \end_inset
26499 </cell>
26500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26501 \begin_inset Text
26502
26503 \begin_layout Standard
26504 rest of the pointer
26505 \end_layout
26506
26507 \end_inset
26508 </cell>
26509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26510 \begin_inset Text
26511
26512 \begin_layout Standard
26513 descrption
26514 \end_layout
26515
26516 \end_inset
26517 </cell>
26518 </row>
26519 <row topline="true" bottomline="true">
26520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26521 \begin_inset Text
26522
26523 \begin_layout Standard
26524 stream
26525 \end_layout
26526
26527 \end_inset
26528 </cell>
26529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26530 \begin_inset Text
26531
26532 \begin_layout Standard
26533 00
26534 \end_layout
26535
26536 \end_inset
26537 </cell>
26538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26539 \begin_inset Text
26540
26541 \begin_layout Standard
26542 1
26543 \end_layout
26544
26545 \end_inset
26546 </cell>
26547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26548 \begin_inset Text
26549
26550 \begin_layout Standard
26551 0
26552 \end_layout
26553
26554 \end_inset
26555 </cell>
26556 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26557 \begin_inset Text
26558
26559 \begin_layout Standard
26560 nnnn
26561 \end_layout
26562
26563 \end_inset
26564 </cell>
26565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26566 \begin_inset Text
26567
26568 \begin_layout Standard
26569
26570 \family typewriter
26571 \shape slanted
26572 \emph on
26573 uuuuuuuu uuuuuuuu
26574 \end_layout
26575
26576 \end_inset
26577 </cell>
26578 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26579 \begin_inset Text
26580
26581 \begin_layout Standard
26582 upper byte high nubble is 0x2n, the rest are zeroes
26583 \end_layout
26584
26585 \end_inset
26586 </cell>
26587 </row>
26588 </lyxtabular>
26589
26590 \end_inset
26591
26592
26593 \end_layout
26594
26595 \begin_layout Standard
26596 Currently implemented there are 3 types of streams defined:
26597 \end_layout
26598
26599 \begin_layout Standard
26600 \align center
26601 \begin_inset Tabular
26602 <lyxtabular version="3" rows="4" columns="4">
26603 <features>
26604 <column alignment="center" valignment="top" leftline="true" width="0">
26605 <column alignment="center" valignment="top" leftline="true" width="0">
26606 <column alignment="center" valignment="top" leftline="true" width="0">
26607 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26608 <row topline="true" bottomline="true">
26609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26610 \begin_inset Text
26611
26612 \begin_layout Standard
26613 stream type
26614 \end_layout
26615
26616 \end_inset
26617 </cell>
26618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26619 \begin_inset Text
26620
26621 \begin_layout Standard
26622 value
26623 \end_layout
26624
26625 \end_inset
26626 </cell>
26627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26628 \begin_inset Text
26629
26630 \begin_layout Standard
26631 module
26632 \end_layout
26633
26634 \end_inset
26635 </cell>
26636 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26637 \begin_inset Text
26638
26639 \begin_layout Standard
26640 description
26641 \end_layout
26642
26643 \end_inset
26644 </cell>
26645 </row>
26646 <row topline="true">
26647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26648 \begin_inset Text
26649
26650 \begin_layout Standard
26651 STREAM_USART
26652 \end_layout
26653
26654 \end_inset
26655 </cell>
26656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26657 \begin_inset Text
26658
26659 \begin_layout Standard
26660
26661 \family typewriter
26662 0x200000UL
26663 \end_layout
26664
26665 \end_inset
26666 </cell>
26667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26668 \begin_inset Text
26669
26670 \begin_layout Standard
26671 USART
26672 \end_layout
26673
26674 \end_inset
26675 </cell>
26676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26677 \begin_inset Text
26678
26679 \begin_layout Standard
26680 Writes/Reads characters via the USART peripheral
26681 \end_layout
26682
26683 \end_inset
26684 </cell>
26685 </row>
26686 <row topline="true">
26687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26688 \begin_inset Text
26689
26690 \begin_layout Standard
26691 STREAM_MSSP
26692 \end_layout
26693
26694 \end_inset
26695 </cell>
26696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26697 \begin_inset Text
26698
26699 \begin_layout Standard
26700
26701 \family typewriter
26702 0x210000UL
26703 \end_layout
26704
26705 \end_inset
26706 </cell>
26707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26708 \begin_inset Text
26709
26710 \begin_layout Standard
26711 MSSP
26712 \end_layout
26713
26714 \end_inset
26715 </cell>
26716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26717 \begin_inset Text
26718
26719 \begin_layout Standard
26720 Writes/Reads characters via the MSSP peripheral
26721 \end_layout
26722
26723 \end_inset
26724 </cell>
26725 </row>
26726 <row topline="true" bottomline="true">
26727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26728 \begin_inset Text
26729
26730 \begin_layout Standard
26731 STREAM_USER
26732 \end_layout
26733
26734 \end_inset
26735 </cell>
26736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26737 \begin_inset Text
26738
26739 \begin_layout Standard
26740
26741 \family typewriter
26742 0x2f0000UL
26743 \end_layout
26744
26745 \end_inset
26746 </cell>
26747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26748 \begin_inset Text
26749
26750 \begin_layout Standard
26751 (none)
26752 \end_layout
26753
26754 \end_inset
26755 </cell>
26756 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26757 \begin_inset Text
26758
26759 \begin_layout Standard
26760 Writes/Reads characters via used defined functions
26761 \end_layout
26762
26763 \end_inset
26764 </cell>
26765 </row>
26766 </lyxtabular>
26767
26768 \end_inset
26769
26770
26771 \end_layout
26772
26773 \begin_layout Standard
26774 The stream identifiers are declared as macros in the stdio.h header.
26775 \end_layout
26776
26777 \begin_layout Standard
26778 In the libc library there exist the functions that are used to write to
26779  each of the above streams.
26780  These are
26781 \end_layout
26782
26783 \begin_layout Description
26784 _
26785 \begin_inset ERT
26786 status collapsed
26787
26788 \begin_layout Standard
26789
26790
26791 \backslash
26792 /
26793 \end_layout
26794
26795 \end_inset
26796
26797 _stream_usart_putchar writes a character at the USART stream
26798 \end_layout
26799
26800 \begin_layout Description
26801 _
26802 \begin_inset ERT
26803 status collapsed
26804
26805 \begin_layout Standard
26806
26807
26808 \backslash
26809 /
26810 \end_layout
26811
26812 \end_inset
26813
26814 _stream_mssp_putchar writes a character at the MSSP stream
26815 \end_layout
26816
26817 \begin_layout Description
26818 putchar dummy function.
26819  This writes a character to a user specified manner.
26820 \end_layout
26821
26822 \begin_layout Standard
26823 In order to increase performance 
26824 \emph on
26825 putchar 
26826 \emph default
26827 is declared in stdio.h as having its parameter in WREG (it has the wparam
26828  keyword).
26829  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
26830  in a user-friendly way.
26831  
26832 \emph on
26833 arg
26834 \emph default
26835  is the name of the variable that holds the character to print.
26836  An example follows:
26837 \end_layout
26838
26839 \begin_layout LyX-Code
26840 #include <pic18fregs.h>
26841 \newline
26842 #include <stdio.h>
26843 \newline
26844
26845 \newline
26846 PUTCHAR( c )
26847 \end_layout
26848
26849 \begin_layout LyX-Code
26850 {
26851 \end_layout
26852
26853 \begin_layout LyX-Code
26854     PORTA = c;    /* dump character c to PORTA */
26855 \end_layout
26856
26857 \begin_layout LyX-Code
26858
26859 \newline
26860
26861 \newline
26862 void main(void)
26863 \end_layout
26864
26865 \begin_layout LyX-Code
26866 {
26867 \end_layout
26868
26869 \begin_layout LyX-Code
26870     stdout = STREAM_USER;    /* this is not necessary, since stdout points
26871 \end_layout
26872
26873 \begin_layout LyX-Code
26874                               * by default to STREAM_USER */
26875 \end_layout
26876
26877 \begin_layout LyX-Code
26878     printf (
26879 \begin_inset Quotes sld
26880 \end_inset
26881
26882 This is a printf test
26883 \backslash
26884 n
26885 \begin_inset Quotes srd
26886 \end_inset
26887
26888 );
26889 \end_layout
26890
26891 \begin_layout LyX-Code
26892 }
26893 \end_layout
26894
26895 \begin_layout LyX-Code
26896
26897 \end_layout
26898
26899 \begin_layout Subsubsection
26900 Printing functions
26901 \end_layout
26902
26903 \begin_layout Standard
26904 PIC16 contains an implementation of the printf-family of functions.
26905  There exist the following functions:
26906 \end_layout
26907
26908 \begin_layout LyX-Code
26909 extern unsigned int sprintf(char *buf, char *fmt, ...);
26910 \end_layout
26911
26912 \begin_layout LyX-Code
26913 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
26914 \end_layout
26915
26916 \begin_layout LyX-Code
26917
26918 \end_layout
26919
26920 \begin_layout LyX-Code
26921 extern unsigned int printf(char *fmt, ...);
26922 \end_layout
26923
26924 \begin_layout LyX-Code
26925 extern unsigned int vprintf(char *fmt, va_lista ap);
26926 \end_layout
26927
26928 \begin_layout LyX-Code
26929
26930 \end_layout
26931
26932 \begin_layout LyX-Code
26933 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
26934 \end_layout
26935
26936 \begin_layout LyX-Code
26937 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
26938 \end_layout
26939
26940 \begin_layout Standard
26941 For sprintf and vsprintf 
26942 \emph on
26943 buf 
26944 \emph default
26945 should normally be a data pointer where the resulting string will be placed.
26946  No range checking is done so the user should allocate the necessery buffer.
26947  For fprintf and vfprintf 
26948 \emph on
26949 fp
26950 \emph default
26951  should be a stream pointer (i.e.
26952  stdout, STREAM_MSSP, etc...).
26953 \end_layout
26954
26955 \begin_layout Subsubsection
26956 Signals
26957 \end_layout
26958
26959 \begin_layout Standard
26960 The PIC18F family of microcontrollers supports a number of interrupt sources.
26961  A list of these interrupts is shown in the following table:
26962 \end_layout
26963
26964 \begin_layout Standard
26965 \align center
26966 \begin_inset Tabular
26967 <lyxtabular version="3" rows="11" columns="4">
26968 <features>
26969 <column alignment="left" valignment="top" leftline="true" width="0">
26970 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26971 <column alignment="left" valignment="top" leftline="true" width="0">
26972 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26973 <row topline="true" bottomline="true">
26974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26975 \begin_inset Text
26976
26977 \begin_layout Standard
26978 signal name
26979 \end_layout
26980
26981 \end_inset
26982 </cell>
26983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26984 \begin_inset Text
26985
26986 \begin_layout Standard
26987 description
26988 \end_layout
26989
26990 \end_inset
26991 </cell>
26992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26993 \begin_inset Text
26994
26995 \begin_layout Standard
26996 signal name
26997 \end_layout
26998
26999 \end_inset
27000 </cell>
27001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27002 \begin_inset Text
27003
27004 \begin_layout Standard
27005 descritpion
27006 \end_layout
27007
27008 \end_inset
27009 </cell>
27010 </row>
27011 <row topline="true">
27012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27013 \begin_inset Text
27014
27015 \begin_layout Standard
27016 SIG_RB
27017 \end_layout
27018
27019 \end_inset
27020 </cell>
27021 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27022 \begin_inset Text
27023
27024 \begin_layout Standard
27025 PORTB change interrupt
27026 \end_layout
27027
27028 \end_inset
27029 </cell>
27030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27031 \begin_inset Text
27032
27033 \begin_layout Standard
27034 SIG_EE
27035 \end_layout
27036
27037 \end_inset
27038 </cell>
27039 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27040 \begin_inset Text
27041
27042 \begin_layout Standard
27043 EEPROM/FLASH write complete interrupt
27044 \end_layout
27045
27046 \end_inset
27047 </cell>
27048 </row>
27049 <row topline="true">
27050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27051 \begin_inset Text
27052
27053 \begin_layout Standard
27054 SIG_INT0
27055 \end_layout
27056
27057 \end_inset
27058 </cell>
27059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27060 \begin_inset Text
27061
27062 \begin_layout Standard
27063 INT0 external interrupt
27064 \end_layout
27065
27066 \end_inset
27067 </cell>
27068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27069 \begin_inset Text
27070
27071 \begin_layout Standard
27072 SIG_BCOL
27073 \end_layout
27074
27075 \end_inset
27076 </cell>
27077 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27078 \begin_inset Text
27079
27080 \begin_layout Standard
27081 Bus collision interrupt
27082 \end_layout
27083
27084 \end_inset
27085 </cell>
27086 </row>
27087 <row topline="true">
27088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27089 \begin_inset Text
27090
27091 \begin_layout Standard
27092 SIG_INT1
27093 \end_layout
27094
27095 \end_inset
27096 </cell>
27097 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27098 \begin_inset Text
27099
27100 \begin_layout Standard
27101 INT1 external interrupt
27102 \end_layout
27103
27104 \end_inset
27105 </cell>
27106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27107 \begin_inset Text
27108
27109 \begin_layout Standard
27110 SIG_LVD
27111 \end_layout
27112
27113 \end_inset
27114 </cell>
27115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27116 \begin_inset Text
27117
27118 \begin_layout Standard
27119 Low voltage detect interrupt
27120 \end_layout
27121
27122 \end_inset
27123 </cell>
27124 </row>
27125 <row topline="true">
27126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27127 \begin_inset Text
27128
27129 \begin_layout Standard
27130 SIG_INT2
27131 \end_layout
27132
27133 \end_inset
27134 </cell>
27135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27136 \begin_inset Text
27137
27138 \begin_layout Standard
27139 INT2 external interrupt
27140 \end_layout
27141
27142 \end_inset
27143 </cell>
27144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27145 \begin_inset Text
27146
27147 \begin_layout Standard
27148 SIG_PSP
27149 \end_layout
27150
27151 \end_inset
27152 </cell>
27153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27154 \begin_inset Text
27155
27156 \begin_layout Standard
27157 Parallel slave port interrupt
27158 \end_layout
27159
27160 \end_inset
27161 </cell>
27162 </row>
27163 <row topline="true">
27164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27165 \begin_inset Text
27166
27167 \begin_layout Standard
27168 SIG_CCP1
27169 \end_layout
27170
27171 \end_inset
27172 </cell>
27173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27174 \begin_inset Text
27175
27176 \begin_layout Standard
27177 CCP1 module interrupt
27178 \end_layout
27179
27180 \end_inset
27181 </cell>
27182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27183 \begin_inset Text
27184
27185 \begin_layout Standard
27186 SIG_AD
27187 \end_layout
27188
27189 \end_inset
27190 </cell>
27191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27192 \begin_inset Text
27193
27194 \begin_layout Standard
27195 AD convertion complete interrupt
27196 \end_layout
27197
27198 \end_inset
27199 </cell>
27200 </row>
27201 <row topline="true">
27202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27203 \begin_inset Text
27204
27205 \begin_layout Standard
27206 SIG_CCP2
27207 \end_layout
27208
27209 \end_inset
27210 </cell>
27211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27212 \begin_inset Text
27213
27214 \begin_layout Standard
27215 CCP2 module interrupt
27216 \end_layout
27217
27218 \end_inset
27219 </cell>
27220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27221 \begin_inset Text
27222
27223 \begin_layout Standard
27224 SIG_RC
27225 \end_layout
27226
27227 \end_inset
27228 </cell>
27229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27230 \begin_inset Text
27231
27232 \begin_layout Standard
27233 USART receive interrupt
27234 \end_layout
27235
27236 \end_inset
27237 </cell>
27238 </row>
27239 <row topline="true">
27240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27241 \begin_inset Text
27242
27243 \begin_layout Standard
27244 SIG_TMR0
27245 \end_layout
27246
27247 \end_inset
27248 </cell>
27249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27250 \begin_inset Text
27251
27252 \begin_layout Standard
27253 TMR0 overflow interrupt
27254 \end_layout
27255
27256 \end_inset
27257 </cell>
27258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27259 \begin_inset Text
27260
27261 \begin_layout Standard
27262 SIG_TX
27263 \end_layout
27264
27265 \end_inset
27266 </cell>
27267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27268 \begin_inset Text
27269
27270 \begin_layout Standard
27271 USART transmit interrupt
27272 \end_layout
27273
27274 \end_inset
27275 </cell>
27276 </row>
27277 <row topline="true">
27278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27279 \begin_inset Text
27280
27281 \begin_layout Standard
27282 SIG_TMR1
27283 \end_layout
27284
27285 \end_inset
27286 </cell>
27287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27288 \begin_inset Text
27289
27290 \begin_layout Standard
27291 TMR1 overflow interrupt
27292 \end_layout
27293
27294 \end_inset
27295 </cell>
27296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27297 \begin_inset Text
27298
27299 \begin_layout Standard
27300 SIG_MSSP
27301 \end_layout
27302
27303 \end_inset
27304 </cell>
27305 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27306 \begin_inset Text
27307
27308 \begin_layout Standard
27309 SSP receive/transmit interrupt
27310 \end_layout
27311
27312 \end_inset
27313 </cell>
27314 </row>
27315 <row topline="true">
27316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27317 \begin_inset Text
27318
27319 \begin_layout Standard
27320 SIG_TMR2
27321 \end_layout
27322
27323 \end_inset
27324 </cell>
27325 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27326 \begin_inset Text
27327
27328 \begin_layout Standard
27329 TMR2 matches PR2 interrupt
27330 \end_layout
27331
27332 \end_inset
27333 </cell>
27334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27335 \begin_inset Text
27336
27337 \begin_layout Standard
27338
27339 \end_layout
27340
27341 \end_inset
27342 </cell>
27343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27344 \begin_inset Text
27345
27346 \begin_layout Standard
27347
27348 \end_layout
27349
27350 \end_inset
27351 </cell>
27352 </row>
27353 <row topline="true" bottomline="true">
27354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27355 \begin_inset Text
27356
27357 \begin_layout Standard
27358 SIG_TMR3
27359 \end_layout
27360
27361 \end_inset
27362 </cell>
27363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27364 \begin_inset Text
27365
27366 \begin_layout Standard
27367 TMR3 overflow interrupt
27368 \end_layout
27369
27370 \end_inset
27371 </cell>
27372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27373 \begin_inset Text
27374
27375 \begin_layout Standard
27376
27377 \end_layout
27378
27379 \end_inset
27380 </cell>
27381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27382 \begin_inset Text
27383
27384 \begin_layout Standard
27385
27386 \end_layout
27387
27388 \end_inset
27389 </cell>
27390 </row>
27391 </lyxtabular>
27392
27393 \end_inset
27394
27395
27396 \end_layout
27397
27398 \begin_layout Standard
27399 The prototypes for these names are defined in the header file 
27400 \emph on
27401 signal.h
27402 \emph default
27403  .
27404 \end_layout
27405
27406 \begin_layout Standard
27407 In order to simplify signal handling, a number of macros is provided:
27408 \end_layout
27409
27410 \begin_layout List
27411 \labelwidthstring 00.00.0000
27412 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27413  high priority interrupts.
27414  
27415 \emph on
27416 name
27417 \emph default
27418  is the function name to use.
27419 \end_layout
27420
27421 \begin_layout List
27422 \labelwidthstring 00.00.0000
27423 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27424  low priority interrupt.
27425  
27426 \emph on
27427 name
27428 \emph default
27429  is the function name to use.
27430 \end_layout
27431
27432 \begin_layout List
27433 \labelwidthstring 00.00.0000
27434 DEF_HANDLER(sig,handler) define a handler for signal 
27435 \emph on
27436 sig.
27437 \end_layout
27438
27439 \begin_layout List
27440 \labelwidthstring 00.00.0000
27441 END_DEF end the declaration of the dispatch table.
27442 \end_layout
27443
27444 \begin_layout Standard
27445 Additionally there are two more macros to simplify the declaration of the
27446  signal handler:
27447 \end_layout
27448
27449 \begin_layout List
27450 \labelwidthstring 00.00.0000
27451
27452 \series medium
27453 SIGHANDLER(handler) 
27454 \series default
27455 this declares the function prototype for the 
27456 \emph on
27457 handler
27458 \emph default
27459  function.
27460 \end_layout
27461
27462 \begin_layout List
27463 \labelwidthstring 00.00.0000
27464 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27465 \end_layout
27466
27467 \begin_layout Standard
27468 An example of using the macros above is shown below:
27469 \end_layout
27470
27471 \begin_layout LyX-Code
27472 #include <pic18fregs.h>
27473 \end_layout
27474
27475 \begin_layout LyX-Code
27476 #include <signal.h>
27477 \newline
27478
27479 \newline
27480 DEF_INTHIGH(high_int)
27481 \end_layout
27482
27483 \begin_layout LyX-Code
27484 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27485 \end_layout
27486
27487 \begin_layout LyX-Code
27488 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27489 \end_layout
27490
27491 \begin_layout LyX-Code
27492 END_DEF
27493 \newline
27494
27495 \newline
27496 SIGHANDLER(_tmr0_handler)
27497 \end_layout
27498
27499 \begin_layout LyX-Code
27500 {
27501 \end_layout
27502
27503 \begin_layout LyX-Code
27504   /* action to be taken when timer 0 overflows */
27505 \end_layout
27506
27507 \begin_layout LyX-Code
27508 }
27509 \newline
27510
27511 \newline
27512 SIGHANDLERNAKED(_bcol_handler)
27513 \end_layout
27514
27515 \begin_layout LyX-Code
27516 {
27517 \end_layout
27518
27519 \begin_layout LyX-Code
27520   _asm
27521 \end_layout
27522
27523 \begin_layout LyX-Code
27524     /* action to be taken when bus collision occurs */
27525 \end_layout
27526
27527 \begin_layout LyX-Code
27528     retfie
27529 \end_layout
27530
27531 \begin_layout LyX-Code
27532  _endasm;
27533 \end_layout
27534
27535 \begin_layout LyX-Code
27536 }
27537 \end_layout
27538
27539 \begin_layout Standard
27540
27541 \series bold
27542 NOTES:
27543 \series default
27544  Special care should be taken when using the above scheme:
27545 \end_layout
27546
27547 \begin_layout Itemize
27548 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27549 \end_layout
27550
27551 \begin_layout Itemize
27552 when declaring SIGHANDLERNAKED handler never forget to use 
27553 \emph on
27554 retfie
27555 \emph default
27556  for proper returning.
27557 \end_layout
27558
27559 \begin_layout Subsection
27560 PIC16 Port -- Tips
27561 \end_layout
27562
27563 \begin_layout Standard
27564 Here you can find some general tips for compiling programs with SDCC/pic16.
27565 \end_layout
27566
27567 \begin_layout Subsubsection
27568 Stack size
27569 \end_layout
27570
27571 \begin_layout Standard
27572 The default stack
27573 \begin_inset LatexCommand \index{PIC16!stack}
27574
27575 \end_inset
27576
27577  size (that is 64 bytes) probably is enough for many programs.
27578  One must take care that when there are many levels of function nesting,
27579  or there is excessive usage of stack, its size should be extended.
27580  An example of such a case is the printf/sprintf family of functions.
27581  If you encounter problems like not being able to print integers, then you
27582  need to set the stack size around the maximum (256 for small stack model).
27583  The following diagram shows what happens when calling printf to print an
27584  integer:
27585 \end_layout
27586
27587 \begin_layout LyX-Code
27588 printf () --> ltoa () --> ultoa () --> divschar ()
27589 \end_layout
27590
27591 \begin_layout Standard
27592 It is should be understood that stack is easily consumed when calling complicate
27593 d functions.
27594  Using command line arguments like -
27595 \begin_inset ERT
27596 status collapsed
27597
27598 \begin_layout Standard
27599
27600
27601 \backslash
27602 /
27603 \end_layout
27604
27605 \end_inset
27606
27607 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27608  stack frames.
27609  Other ways to reduce stack usage may exist.
27610 \end_layout
27611
27612 \begin_layout Subsection
27613 Known Bugs
27614 \end_layout
27615
27616 \begin_layout Standard
27617 The PIC16 Port currently does not pass SDCC's regression test
27618 \begin_inset LatexCommand \index{Regression test (PIC16)}
27619
27620 \end_inset
27621
27622  suite (see section 
27623 \begin_inset LatexCommand \ref{sec:Quality-control}
27624
27625 \end_inset
27626
27627 ) and thus the snapshot build regression tests for the PIC16 target are
27628  currently disabled for all hosts
27629 \emph on
27630 .
27631 \end_layout
27632
27633 \begin_layout Chapter
27634 Debugging
27635 \end_layout
27636
27637 \begin_layout Standard
27638 There are several approaches to debugging your code.
27639  This chapter is meant to show your options and to give detail on some of
27640  them:
27641 \newline
27642
27643 \newline
27644 When writing your code:
27645 \end_layout
27646
27647 \begin_layout Itemize
27648 write your code with debugging in mind (avoid duplicating code, put conceptually
27649  similar variables into structs, use structured code, have strategic points
27650  within your code where all variables are consistent, ...)
27651 \end_layout
27652
27653 \begin_layout Itemize
27654 run a syntax-checking tool like splint
27655 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27656
27657 \end_inset
27658
27659
27660 \begin_inset LatexCommand \index{lint (syntax checking tool)}
27661
27662 \end_inset
27663
27664  (see -
27665 \begin_inset ERT
27666 status collapsed
27667
27668 \begin_layout Standard
27669
27670
27671 \backslash
27672 /
27673 \end_layout
27674
27675 \end_inset
27676
27677 -more-pedantic 
27678 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27679
27680 \end_inset
27681
27682 ) over the code.
27683 \end_layout
27684
27685 \begin_layout Itemize
27686 for the high level code use a C-compiler (like f.e.
27687  GCC) to compile run and debug the code on your host.
27688  See (see -
27689 \begin_inset ERT
27690 status collapsed
27691
27692 \begin_layout Standard
27693
27694
27695 \backslash
27696 /
27697 \end_layout
27698
27699 \end_inset
27700
27701 -more-pedantic 
27702 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27703
27704 \end_inset
27705
27706 ) on how to handle syntax extensions like __xdata, __at(), ...
27707  
27708 \end_layout
27709
27710 \begin_layout Itemize
27711 use another C-compiler to compile code for your target.
27712  Always an option but not recommended:) And not very likely to help you.
27713  If you seriously consider walking this path you should at least occasionally
27714  check portability of your code.
27715  Most commercial compiler vendors will offer an evaluation version so you
27716  can test compile your code or snippets of your code.
27717 \end_layout
27718
27719 \begin_layout Standard
27720 Debugging on a simulator:
27721 \end_layout
27722
27723 \begin_layout Itemize
27724 there is a separate section about SDCDB (section 
27725 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
27726
27727 \end_inset
27728
27729 ) below.
27730 \end_layout
27731
27732 \begin_layout Itemize
27733 or (8051 specific) use a freeware/commercial simulator which interfaces
27734  to the AOMF
27735 \begin_inset LatexCommand \index{AOMF, AOMF51}
27736
27737 \end_inset
27738
27739  file (see 
27740 \begin_inset LatexCommand \ref{OMF file}
27741
27742 \end_inset
27743
27744 ) optionally generated by SDCC.
27745 \end_layout
27746
27747 \begin_layout Standard
27748 Debugging On-target: 
27749 \end_layout
27750
27751 \begin_layout Itemize
27752 use a MCU port pin to serially output debug data to the RS232 port of your
27753  host.
27754  You'll probably want some level shifting device typically involving a MAX232
27755  or similar IC.
27756  If the hardware serial port of the MCU is not available search for 'Software
27757  UART' in your favourite search machine.
27758 \end_layout
27759
27760 \begin_layout Itemize
27761 use an on-target monitor.
27762  In this context a monitor is a small program which usually accepts commands
27763  via a serial line and allows to set program counter, to single step through
27764  a program and read/write memory locations.
27765  For the 8051 good examples of monitors are paulmon and cmon51 (see section
27766  
27767 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
27768
27769 \end_inset
27770
27771 ).
27772 \end_layout
27773
27774 \begin_layout Itemize
27775 toggle MCU port pins at strategic points within your code and use an oscilloscop
27776 e.
27777  A 
27778 \emph on
27779 digital oscilloscope
27780 \emph default
27781
27782 \begin_inset LatexCommand \index{Oscilloscope}
27783
27784 \end_inset
27785
27786  with deep trace memory is really helpful especially if you have to debug
27787  a realtime application.
27788  If you need to monitor more pins than your oscilloscope provides you can
27789  sometimes get away with a small R-2R network.
27790  On a single channel oscilloscope you could f.e.
27791  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
27792 k
27793 \begin_inset Formula $\Omega$
27794 \end_inset
27795
27796  resistor and the other one by a 5\InsetSpace ~
27797 k
27798 \begin_inset Formula $\Omega$
27799 \end_inset
27800
27801  resistor to the oscilloscope probe (check output drive capability of the
27802  pins you want to monitor).
27803  If you need to monitor many more pins a 
27804 \emph on
27805 logic analyzer
27806 \emph default
27807  will be handy.
27808 \end_layout
27809
27810 \begin_layout Itemize
27811 use an ICE (
27812 \emph on
27813 i
27814 \emph default
27815
27816 \emph on
27817 c
27818 \emph default
27819 ircuit 
27820 \emph on
27821 e
27822 \emph default
27823 mulator
27824 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
27825
27826 \end_inset
27827
27828 ).
27829  Usually very expensive.
27830  And very nice to have too.
27831  And usually locks you (for years...) to the devices the ICE can emulate.
27832  
27833 \end_layout
27834
27835 \begin_layout Itemize
27836 use a remote debugger.
27837  In most 8-bit systems the symbol information is not available on the target,
27838  and a complete debugger is too bulky for the target system.
27839  Therefore usually a debugger on the host system connects to an on-target
27840  debugging stub which accepts only primitive commands.
27841  
27842 \newline
27843 Terms to enter into your favourite search engine could be 'remote debugging',
27844  'gdb stub' or 'inferior debugger'.
27845  (is there one?)
27846 \end_layout
27847
27848 \begin_layout Itemize
27849 use an on target hardware debugger.
27850  Some of the more modern MCUs include hardware support for setting break
27851  points and monitoring/changing variables by using dedicated hardware pins.
27852  This facility doesn't require additional code to run on the target and
27853  
27854 \emph on
27855 usually
27856 \emph default
27857  doesn't affect runtime behaviour until a breakpoint is hit.
27858  For the mcs51 most hardware debuggers use the AOMF
27859 \begin_inset LatexCommand \index{AOMF, AOMF51}
27860
27861 \end_inset
27862
27863  file (see 
27864 \begin_inset LatexCommand \ref{OMF file}
27865
27866 \end_inset
27867
27868 ) as input file.
27869  
27870 \end_layout
27871
27872 \begin_layout Standard
27873 Last not least:
27874 \end_layout
27875
27876 \begin_layout Itemize
27877 if you are not familiar with any of the following terms you're likely to
27878  run into problems rather sooner than later: 
27879 \emph on
27880 volatile
27881 \emph default
27882
27883 \emph on
27884 atomic
27885 \emph default
27886
27887 \emph on
27888 memory map
27889 \emph default
27890
27891 \emph on
27892 overlay
27893 \emph default
27894 .
27895  As an embedded programmer you 
27896 \emph on
27897 have
27898 \emph default
27899  to know them so why not look them up 
27900 \emph on
27901 before
27902 \emph default
27903  you have problems?)
27904 \end_layout
27905
27906 \begin_layout Itemize
27907 tell someone else about your problem (actually this is a surprisingly effective
27908  means to hunt down the bug even if the listener is not familiar with your
27909  environment).
27910  As 'failure to communicate' is probably one of the job-induced deformations
27911  of an embedded programmer this is highly encouraged.
27912 \end_layout
27913
27914 \begin_layout Section
27915 Debugging with SDCDB
27916 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
27917
27918 \end_inset
27919
27920
27921 \begin_inset LatexCommand \index{SDCDB (debugger)}
27922
27923 \end_inset
27924
27925  
27926 \end_layout
27927
27928 \begin_layout Standard
27929 SDCC is distributed with a source level debugger
27930 \begin_inset LatexCommand \index{Debugger}
27931
27932 \end_inset
27933
27934 .
27935  The debugger uses a command line interface, the command repertoire of the
27936  debugger has been kept as close to gdb
27937 \begin_inset LatexCommand \index{gdb}
27938
27939 \end_inset
27940
27941  (the GNU debugger) as possible.
27942  The configuration and build process is part of the standard compiler installati
27943 on, which also builds and installs the debugger in the target directory
27944  specified during configuration.
27945  The debugger allows you debug BOTH at the C source and at the ASM source
27946  level.
27947 \end_layout
27948
27949 \begin_layout Subsection
27950 Compiling for Debugging
27951 \end_layout
27952
27953 \begin_layout Standard
27954 The -
27955 \begin_inset ERT
27956 status collapsed
27957
27958 \begin_layout Standard
27959
27960
27961 \backslash
27962 /
27963 \end_layout
27964
27965 \end_inset
27966
27967 -debug
27968 \begin_inset LatexCommand \index{-\/-debug}
27969
27970 \end_inset
27971
27972  option must be specified for all files for which debug information is to
27973  be generated.
27974  The compiler generates a .adb file for each of these files.
27975  The linker creates the .cdb
27976 \begin_inset LatexCommand \index{<file>.cdb}
27977
27978 \end_inset
27979
27980  file from the .adb
27981 \begin_inset LatexCommand \index{<file>.adb}
27982
27983 \end_inset
27984
27985  files and the address information.
27986  This .cdb is used by the debugger.
27987 \end_layout
27988
27989 \begin_layout Subsection
27990 How the Debugger Works
27991 \end_layout
27992
27993 \begin_layout Standard
27994 When the -
27995 \begin_inset ERT
27996 status collapsed
27997
27998 \begin_layout Standard
27999
28000
28001 \backslash
28002 /
28003 \end_layout
28004
28005 \end_inset
28006
28007 -debug option is specified the compiler generates extra symbol information
28008  some of which are put into the assembler source and some are put into the
28009  .adb file.
28010  Then the linker creates the .cdb file from the individual .adb files with
28011  the address information for the symbols.
28012  The debugger reads the symbolic information generated by the compiler &
28013  the address information generated by the linker.
28014  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
28015  execution is controlled by the debugger.
28016  When a command is issued for the debugger, it translates it into appropriate
28017  commands for the simulator.
28018  (Currently SDCDM only connects to the simulator but 
28019 \emph on
28020 newcdb
28021 \emph default
28022  at 
28023 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
28024
28025 \end_inset
28026
28027  is an effort to connect directly to the hardware.) 
28028 \end_layout
28029
28030 \begin_layout Subsection
28031 Starting the Debugger SDCDB
28032 \end_layout
28033
28034 \begin_layout Standard
28035 The debugger can be started using the following command line.
28036  (Assume the file you are debugging has the file name foo).
28037 \newline
28038
28039 \newline
28040
28041 \family sans
28042 \series bold
28043 sdcdb foo
28044 \newline
28045
28046 \family default
28047 \series default
28048
28049 \newline
28050 The debugger will look for the following files.
28051 \end_layout
28052
28053 \begin_layout Itemize
28054 foo.c - the source file.
28055 \end_layout
28056
28057 \begin_layout Itemize
28058 foo.cdb - the debugger symbol information file.
28059 \end_layout
28060
28061 \begin_layout Itemize
28062 foo.ihx - the Intel hex format
28063 \begin_inset LatexCommand \index{Intel hex format}
28064
28065 \end_inset
28066
28067  object file.
28068 \end_layout
28069
28070 \begin_layout Subsection
28071 SDCDB Command Line Options
28072 \end_layout
28073
28074 \begin_layout Itemize
28075 -
28076 \begin_inset ERT
28077 status collapsed
28078
28079 \begin_layout Standard
28080
28081
28082 \backslash
28083 /
28084 \end_layout
28085
28086 \end_inset
28087
28088 -directory=<source file directory> this option can used to specify the directory
28089  search list.
28090  The debugger will look into the directory list specified for source, cdb
28091  & ihx files.
28092  The items in the directory list must be separated by ':', e.g.
28093  if the source files can be in the directories /home/src1 and /home/src2,
28094  the -
28095 \begin_inset ERT
28096 status collapsed
28097
28098 \begin_layout Standard
28099
28100
28101 \backslash
28102 /
28103 \end_layout
28104
28105 \end_inset
28106
28107 -directory option should be -
28108 \begin_inset ERT
28109 status collapsed
28110
28111 \begin_layout Standard
28112
28113
28114 \backslash
28115 /
28116 \end_layout
28117
28118 \end_inset
28119
28120 -directory=/home/src1:/home/src2.
28121  Note there can be no spaces in the option.
28122  
28123 \end_layout
28124
28125 \begin_layout Itemize
28126 -cd <directory> - change to the <directory>.
28127 \end_layout
28128
28129 \begin_layout Itemize
28130 -fullname - used by GUI front ends.
28131 \end_layout
28132
28133 \begin_layout Itemize
28134 -cpu <cpu-type> - this argument is passed to the simulator please see the
28135  simulator docs for details.
28136 \end_layout
28137
28138 \begin_layout Itemize
28139 -X <Clock frequency > this options is passed to the simulator please see
28140  the simulator docs for details.
28141 \end_layout
28142
28143 \begin_layout Itemize
28144 -s <serial port file> passed to simulator see the simulator docs for details.
28145 \end_layout
28146
28147 \begin_layout Itemize
28148 -S <serial in,out> passed to simulator see the simulator docs for details.
28149 \end_layout
28150
28151 \begin_layout Itemize
28152 -k <port number> passed to simulator see the simulator docs for details.
28153 \end_layout
28154
28155 \begin_layout Subsection
28156 SDCDB Debugger Commands
28157 \end_layout
28158
28159 \begin_layout Standard
28160 As mentioned earlier the command interface for the debugger has been deliberatel
28161 y kept as close the GNU debugger gdb, as possible.
28162  This will help the integration with existing graphical user interfaces
28163  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
28164  If you use a graphical user interface for the debugger you can skip this
28165  section.
28166 \end_layout
28167
28168 \begin_layout Subsubsection*
28169 break [line | file:line | function | file:function]
28170 \end_layout
28171
28172 \begin_layout Standard
28173 Set breakpoint at specified line or function:
28174 \newline
28175
28176 \newline
28177
28178 \family sans
28179 \series bold
28180 sdcdb>break 100 
28181 \newline
28182 sdcdb>break foo.c:100
28183 \newline
28184 sdcdb>break funcfoo
28185 \newline
28186 sdcdb>break foo.c:funcfoo
28187 \end_layout
28188
28189 \begin_layout Subsubsection*
28190 clear [line | file:line | function | file:function ]
28191 \end_layout
28192
28193 \begin_layout Standard
28194 Clear breakpoint at specified line or function:
28195 \newline
28196
28197 \newline
28198
28199 \family sans
28200 \series bold
28201 sdcdb>clear 100
28202 \newline
28203 sdcdb>clear foo.c:100
28204 \newline
28205 sdcdb>clear funcfoo
28206 \newline
28207 sdcdb>clear foo.c:funcfoo
28208 \end_layout
28209
28210 \begin_layout Subsubsection*
28211 continue
28212 \end_layout
28213
28214 \begin_layout Standard
28215 Continue program being debugged, after breakpoint.
28216 \end_layout
28217
28218 \begin_layout Subsubsection*
28219 finish
28220 \end_layout
28221
28222 \begin_layout Standard
28223 Execute till the end of the current function.
28224 \end_layout
28225
28226 \begin_layout Subsubsection*
28227 delete [n]
28228 \end_layout
28229
28230 \begin_layout Standard
28231 Delete breakpoint number 'n'.
28232  If used without any option clear ALL user defined break points.
28233 \end_layout
28234
28235 \begin_layout Subsubsection*
28236 info [break | stack | frame | registers ]
28237 \end_layout
28238
28239 \begin_layout Itemize
28240 info break - list all breakpoints
28241 \end_layout
28242
28243 \begin_layout Itemize
28244 info stack - show the function call stack.
28245 \end_layout
28246
28247 \begin_layout Itemize
28248 info frame - show information about the current execution frame.
28249 \end_layout
28250
28251 \begin_layout Itemize
28252 info registers - show content of all registers.
28253 \end_layout
28254
28255 \begin_layout Subsubsection*
28256 step
28257 \end_layout
28258
28259 \begin_layout Standard
28260 Step program until it reaches a different source line.
28261  Note: pressing <return> repeats the last command.
28262 \end_layout
28263
28264 \begin_layout Subsubsection*
28265 next
28266 \end_layout
28267
28268 \begin_layout Standard
28269 Step program, proceeding through subroutine calls.
28270 \end_layout
28271
28272 \begin_layout Subsubsection*
28273 run
28274 \end_layout
28275
28276 \begin_layout Standard
28277 Start debugged program.
28278 \end_layout
28279
28280 \begin_layout Subsubsection*
28281 ptype variable 
28282 \end_layout
28283
28284 \begin_layout Standard
28285 Print type information of the variable.
28286 \end_layout
28287
28288 \begin_layout Subsubsection*
28289 print variable
28290 \end_layout
28291
28292 \begin_layout Standard
28293 print value of variable.
28294 \end_layout
28295
28296 \begin_layout Subsubsection*
28297 file filename
28298 \end_layout
28299
28300 \begin_layout Standard
28301 load the given file name.
28302  Note this is an alternate method of loading file for debugging.
28303 \end_layout
28304
28305 \begin_layout Subsubsection*
28306 frame
28307 \end_layout
28308
28309 \begin_layout Standard
28310 print information about current frame.
28311 \end_layout
28312
28313 \begin_layout Subsubsection*
28314 set srcmode
28315 \end_layout
28316
28317 \begin_layout Standard
28318 Toggle between C source & assembly source.
28319 \end_layout
28320
28321 \begin_layout Subsubsection*
28322 ! simulator command
28323 \end_layout
28324
28325 \begin_layout Standard
28326 Send the string following '!' to the simulator, the simulator response is
28327  displayed.
28328  Note the debugger does not interpret the command being sent to the simulator,
28329  so if a command like 'go' is sent the debugger can loose its execution
28330  context and may display incorrect values.
28331 \end_layout
28332
28333 \begin_layout Subsubsection*
28334 quit
28335 \end_layout
28336
28337 \begin_layout Standard
28338 "Watch me now.
28339  Iam going Down.
28340  My name is Bobby Brown"
28341 \end_layout
28342
28343 \begin_layout Subsection
28344 Interfacing SDCDB with DDD
28345 \end_layout
28346
28347 \begin_layout Standard
28348 \begin_inset Note Note
28349 status collapsed
28350
28351 \begin_layout Standard
28352 The screenshot was converted from png to eps with: 
28353 \begin_inset Quotes sld
28354 \end_inset
28355
28356 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
28357 \begin_inset Quotes srd
28358 \end_inset
28359
28360  which produces a pretty compact eps file which is free from compression
28361  artifacts.
28362 \end_layout
28363
28364 \begin_layout Standard
28365 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
28366  as this broke the build system on Sourceforge (pdf-file was broken.
28367  pdflatex does not accept eps files).
28368 \end_layout
28369
28370 \end_inset
28371
28372
28373 \end_layout
28374
28375 \begin_layout Standard
28376 The 
28377 \emph on
28378 p
28379 \emph default
28380 ortable 
28381 \emph on
28382 n
28383 \emph default
28384 etwork 
28385 \emph on
28386 g
28387 \emph default
28388 raphics File 
28389 \size footnotesize
28390
28391 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28392
28393 \end_inset
28394
28395
28396 \size default
28397  shows a screenshot of a debugging session with DDD
28398 \begin_inset LatexCommand \index{DDD (debugger)}
28399
28400 \end_inset
28401
28402  (Unix only) on a simulated 8032.
28403  The debugging session might not run as smoothly as the screenshot suggests.
28404  The debugger allows setting of breakpoints, displaying and changing variables,
28405  single stepping through C and assembler code.
28406  
28407 \newline
28408 The source was compiled with 
28409 \family sans
28410 \series bold
28411
28412 \newline
28413
28414 \newline
28415 sdcc -
28416 \family default
28417 \series default
28418
28419 \begin_inset ERT
28420 status collapsed
28421
28422 \begin_layout Standard
28423
28424
28425 \backslash
28426 /
28427 \end_layout
28428
28429 \end_inset
28430
28431
28432 \family sans
28433 \series bold
28434 -debug ddd_example.c
28435 \family default
28436 \series default
28437  
28438 \family sans
28439 \series bold
28440
28441 \newline
28442
28443 \family default
28444 \series default
28445
28446 \newline
28447 and DDD was invoked with 
28448 \family sans
28449 \series bold
28450
28451 \newline
28452
28453 \newline
28454 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28455 \end_layout
28456
28457 \begin_layout Standard
28458 \begin_inset Note Note
28459 status open
28460
28461 \begin_layout Standard
28462 Check that the double quotes or an apostroph within the command line survive
28463  the LyX tool chain.
28464  Previously the apostrophs got slanted in the PDF output so a cut and paste
28465  did not work.
28466 \end_layout
28467
28468 \end_inset
28469
28470
28471 \end_layout
28472
28473 \begin_layout Subsection
28474 Interfacing SDCDB with XEmacs
28475 \begin_inset LatexCommand \index{XEmacs}
28476
28477 \end_inset
28478
28479
28480 \begin_inset LatexCommand \index{Emacs}
28481
28482 \end_inset
28483
28484
28485 \end_layout
28486
28487 \begin_layout Standard
28488 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28489  sdcdb.el and sdcdbsrc.el.
28490  These two files can be found in the $(prefix)/bin directory after the installat
28491 ion is complete.
28492  These files need to be loaded into XEmacs for the interface to work.
28493  This can be done at XEmacs startup time by inserting the following into
28494  your '.xemacs' file (which can be found in your HOME directory): 
28495 \newline
28496
28497 \newline
28498
28499 \family typewriter
28500 (load-file sdcdbsrc.el) 
28501 \family default
28502
28503 \newline
28504
28505 \newline
28506 .xemacs is a lisp file so the () around the command is REQUIRED.
28507  The files can also be loaded dynamically while XEmacs is running, set the
28508  environment variable 'EMACSLOADPATH' to the installation bin directory
28509  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28510  To start the interface enter the following command: 
28511 \newline
28512
28513 \newline
28514
28515 \family sans
28516 \series bold
28517 ESC-x sdcdbsrc
28518 \family default
28519 \series default
28520
28521 \newline
28522
28523 \newline
28524 You will prompted to enter the file name to be debugged.
28525  
28526 \newline
28527
28528 \newline
28529 The command line options that are passed to the simulator directly are
28530  bound to default values in the file sdcdbsrc.el.
28531  The variables are listed below, these values maybe changed as required.
28532 \end_layout
28533
28534 \begin_layout Itemize
28535 sdcdbsrc-cpu-type '51
28536 \end_layout
28537
28538 \begin_layout Itemize
28539 sdcdbsrc-frequency '11059200
28540 \end_layout
28541
28542 \begin_layout Itemize
28543 sdcdbsrc-serial nil
28544 \end_layout
28545
28546 \begin_layout Standard
28547 The following is a list of key mapping for the debugger interface.
28548 \end_layout
28549
28550 \begin_layout Standard
28551 \InsetSpace ~
28552
28553 \family typewriter
28554
28555 \newline
28556 ;;\InsetSpace ~
28557 Current Listing :: 
28558 \newline
28559 ;;key\InsetSpace ~
28560 \InsetSpace ~
28561 \InsetSpace ~
28562 \InsetSpace ~
28563 \InsetSpace ~
28564 \InsetSpace ~
28565 \InsetSpace ~
28566 \InsetSpace ~
28567 \InsetSpace ~
28568 \InsetSpace ~
28569 \InsetSpace ~
28570 \InsetSpace ~
28571 \InsetSpace ~
28572 \InsetSpace ~
28573 binding\InsetSpace ~
28574 \InsetSpace ~
28575 \InsetSpace ~
28576 \InsetSpace ~
28577 \InsetSpace ~
28578 \InsetSpace ~
28579 \InsetSpace ~
28580 \InsetSpace ~
28581 \InsetSpace ~
28582 \InsetSpace ~
28583 \InsetSpace ~
28584 \InsetSpace ~
28585 \InsetSpace ~
28586 \InsetSpace ~
28587 \InsetSpace ~
28588 \InsetSpace ~
28589 \InsetSpace ~
28590 \InsetSpace ~
28591 \InsetSpace ~
28592 \InsetSpace ~
28593 \InsetSpace ~
28594 \InsetSpace ~
28595 Comment 
28596 \newline
28597 ;;---\InsetSpace ~
28598 \InsetSpace ~
28599 \InsetSpace ~
28600 \InsetSpace ~
28601 \InsetSpace ~
28602 \InsetSpace ~
28603 \InsetSpace ~
28604 \InsetSpace ~
28605 \InsetSpace ~
28606 \InsetSpace ~
28607 \InsetSpace ~
28608 \InsetSpace ~
28609 \InsetSpace ~
28610 \InsetSpace ~
28611 -------\InsetSpace ~
28612 \InsetSpace ~
28613 \InsetSpace ~
28614 \InsetSpace ~
28615 \InsetSpace ~
28616 \InsetSpace ~
28617 \InsetSpace ~
28618 \InsetSpace ~
28619 \InsetSpace ~
28620 \InsetSpace ~
28621 \InsetSpace ~
28622 \InsetSpace ~
28623 \InsetSpace ~
28624 \InsetSpace ~
28625 \InsetSpace ~
28626 \InsetSpace ~
28627 \InsetSpace ~
28628 \InsetSpace ~
28629 \InsetSpace ~
28630 \InsetSpace ~
28631 \InsetSpace ~
28632 \InsetSpace ~
28633 -------
28634 \newline
28635 ;; 
28636 \newline
28637 ;;\InsetSpace ~
28638 n\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 sdcdb-next-fro
28654 m-src\InsetSpace ~
28655 \InsetSpace ~
28656 \InsetSpace ~
28657 \InsetSpace ~
28658 \InsetSpace ~
28659 \InsetSpace ~
28660 \InsetSpace ~
28661 \InsetSpace ~
28662 \InsetSpace ~
28663 \InsetSpace ~
28664 SDCDB next command 
28665 \newline
28666 ;;\InsetSpace ~
28667 b\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 sdcdb-back-from-src\InsetSpace ~
28683 \InsetSpace ~
28684 \InsetSpace ~
28685 \InsetSpace ~
28686 \InsetSpace ~
28687 \InsetSpace ~
28688 \InsetSpace ~
28689 \InsetSpace ~
28690 \InsetSpace ~
28691 \InsetSpace ~
28692 SDCDB back command 
28693 \newline
28694 ;;\InsetSpace ~
28695 c\InsetSpace ~
28696 \InsetSpace ~
28697 \InsetSpace ~
28698 \InsetSpace ~
28699 \InsetSpace ~
28700 \InsetSpace ~
28701 \InsetSpace ~
28702 \InsetSpace ~
28703 \InsetSpace ~
28704 \InsetSpace ~
28705 \InsetSpace ~
28706 \InsetSpace ~
28707 \InsetSpace ~
28708 \InsetSpace ~
28709 \InsetSpace ~
28710 sdcdb-cont-f
28711 rom-src\InsetSpace ~
28712 \InsetSpace ~
28713 \InsetSpace ~
28714 \InsetSpace ~
28715 \InsetSpace ~
28716 \InsetSpace ~
28717 \InsetSpace ~
28718 \InsetSpace ~
28719 \InsetSpace ~
28720 \InsetSpace ~
28721 SDCDB continue command
28722 \newline
28723 ;;\InsetSpace ~
28724 s\InsetSpace ~
28725 \InsetSpace ~
28726 \InsetSpace ~
28727 \InsetSpace ~
28728 \InsetSpace ~
28729 \InsetSpace ~
28730 \InsetSpace ~
28731 \InsetSpace ~
28732 \InsetSpace ~
28733 \InsetSpace ~
28734 \InsetSpace ~
28735 \InsetSpace ~
28736 \InsetSpace ~
28737 \InsetSpace ~
28738 \InsetSpace ~
28739 sdcdb-step-from-src\InsetSpace ~
28740 \InsetSpace ~
28741 \InsetSpace ~
28742 \InsetSpace ~
28743 \InsetSpace ~
28744 \InsetSpace ~
28745 \InsetSpace ~
28746 \InsetSpace ~
28747 \InsetSpace ~
28748 \InsetSpace ~
28749 SDCDB step command 
28750 \newline
28751 ;;\InsetSpace ~
28752 ?\InsetSpace ~
28753 \InsetSpace ~
28754 \InsetSpace ~
28755 \InsetSpace ~
28756 \InsetSpace ~
28757 \InsetSpace ~
28758 \InsetSpace ~
28759 \InsetSpace ~
28760 \InsetSpace ~
28761 \InsetSpace ~
28762 \InsetSpace ~
28763 \InsetSpace ~
28764 \InsetSpace ~
28765 \InsetSpace ~
28766 \InsetSpace ~
28767 sdcdb-w
28768 hatis-c-sexp\InsetSpace ~
28769 \InsetSpace ~
28770 \InsetSpace ~
28771 \InsetSpace ~
28772 \InsetSpace ~
28773 \InsetSpace ~
28774 \InsetSpace ~
28775 \InsetSpace ~
28776 \InsetSpace ~
28777 \InsetSpace ~
28778 SDCDB ptypecommand for data at 
28779 \newline
28780 ;;\InsetSpace ~
28781 \InsetSpace ~
28782 \InsetSpace ~
28783 \InsetSpace ~
28784 \InsetSpace ~
28785 \InsetSpace ~
28786 \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 \InsetSpace ~
28802 \InsetSpace ~
28803 \InsetSpace ~
28804 \InsetSpace ~
28805 \InsetSpace ~
28806 \InsetSpace ~
28807 \InsetSpace ~
28808 \InsetSpace ~
28809 \InsetSpace ~
28810 \InsetSpace ~
28811 \InsetSpace ~
28812 \InsetSpace ~
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 buffer point 
28828 \newline
28829 ;;\InsetSpace ~
28830 x\InsetSpace ~
28831 \InsetSpace ~
28832 \InsetSpace ~
28833 \InsetSpace ~
28834 \InsetSpace ~
28835 \InsetSpace ~
28836 \InsetSpace ~
28837 \InsetSpace ~
28838 \InsetSpace ~
28839 \InsetSpace ~
28840 \InsetSpace ~
28841 \InsetSpace ~
28842 \InsetSpace ~
28843 \InsetSpace ~
28844 \InsetSpace ~
28845 sdcdbsrc-delete\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 SDCD
28860 B Delete all breakpoints if no arg 
28861 \newline
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 \InsetSpace ~
28890 \InsetSpace ~
28891 \InsetSpace ~
28892 \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 \InsetSpace ~
28908 \InsetSpace ~
28909 given or delete arg (C-u arg x) 
28910 \newline
28911 ;;\InsetSpace ~
28912 m\InsetSpace ~
28913 \InsetSpace ~
28914 \InsetSpace ~
28915 \InsetSpace ~
28916 \InsetSpace ~
28917 \InsetSpace ~
28918 \InsetSpace ~
28919 \InsetSpace ~
28920 \InsetSpace ~
28921 \InsetSpace ~
28922 \InsetSpace ~
28923 \InsetSpace ~
28924 \InsetSpace ~
28925 \InsetSpace ~
28926 \InsetSpace ~
28927 sdcdbsrc
28928 -frame\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 SDCDB Display current frame if no arg, 
28944 \newline
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 \InsetSpace ~
28972 \InsetSpace ~
28973 \InsetSpace ~
28974 \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 \InsetSpace ~
28990 \InsetSpace ~
28991 \InsetSpace ~
28992 given or display frame arg
28993  
28994 \newline
28995 ;;\InsetSpace ~
28996 \InsetSpace ~
28997 \InsetSpace ~
28998 \InsetSpace ~
28999 \InsetSpace ~
29000 \InsetSpace ~
29001 \InsetSpace ~
29002 \InsetSpace ~
29003 \InsetSpace ~
29004 \InsetSpace ~
29005 \InsetSpace ~
29006 \InsetSpace ~
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 buffer point 
29043 \newline
29044 ;;\InsetSpace ~
29045 !\InsetSpace ~
29046 \InsetSpace ~
29047 \InsetSpace ~
29048 \InsetSpace ~
29049 \InsetSpace ~
29050 \InsetSpace ~
29051 \InsetSpace ~
29052 \InsetSpace ~
29053 \InsetSpace ~
29054 \InsetSpace ~
29055 \InsetSpace ~
29056 \InsetSpace ~
29057 \InsetSpace ~
29058 \InsetSpace ~
29059 \InsetSpace ~
29060 sdcdbsrc-goto-sdcdb\InsetSpace ~
29061 \InsetSpace ~
29062 \InsetSpace ~
29063 \InsetSpace ~
29064 \InsetSpace ~
29065 \InsetSpace ~
29066 \InsetSpace ~
29067 \InsetSpace ~
29068 \InsetSpace ~
29069 \InsetSpace ~
29070 Goto the SDCDB output buffer 
29071 \newline
29072 ;;\InsetSpace ~
29073 p\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 sdcdb-prin
29089 t-c-sexp\InsetSpace ~
29090 \InsetSpace ~
29091 \InsetSpace ~
29092 \InsetSpace ~
29093 \InsetSpace ~
29094 \InsetSpace ~
29095 \InsetSpace ~
29096 \InsetSpace ~
29097 \InsetSpace ~
29098 \InsetSpace ~
29099 \InsetSpace ~
29100 SDCDB print command for data at 
29101 \newline
29102 ;;\InsetSpace ~
29103 \InsetSpace ~
29104 \InsetSpace ~
29105 \InsetSpace ~
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 \InsetSpace ~
29123 \InsetSpace ~
29124 \InsetSpace ~
29125 \InsetSpace ~
29126 \InsetSpace ~
29127 \InsetSpace ~
29128 \InsetSpace ~
29129 \InsetSpace ~
29130 \InsetSpace ~
29131 \InsetSpace ~
29132 \InsetSpace ~
29133 \InsetSpace ~
29134 \InsetSpace ~
29135 \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 buffer point 
29150 \newline
29151 ;;\InsetSpace ~
29152 g\InsetSpace ~
29153 \InsetSpace ~
29154 \InsetSpace ~
29155 \InsetSpace ~
29156 \InsetSpace ~
29157 \InsetSpace ~
29158 \InsetSpace ~
29159 \InsetSpace ~
29160 \InsetSpace ~
29161 \InsetSpace ~
29162 \InsetSpace ~
29163 \InsetSpace ~
29164 \InsetSpace ~
29165 \InsetSpace ~
29166 \InsetSpace ~
29167 sdcdbsrc-goto-sdcdb\InsetSpace ~
29168 \InsetSpace ~
29169 \InsetSpace ~
29170 \InsetSpace ~
29171 \InsetSpace ~
29172 \InsetSpace ~
29173 \InsetSpace ~
29174 \InsetSpace ~
29175 \InsetSpace ~
29176 \InsetSpace ~
29177 Got
29178 o the SDCDB output buffer 
29179 \newline
29180 ;;\InsetSpace ~
29181 t\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 sdcdbsrc-mode\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 \InsetSpace ~
29212 Toggles Sdcdbsrc mode (turns it
29213  off) 
29214 \newline
29215 ;; 
29216 \newline
29217 ;;\InsetSpace ~
29218 C-c\InsetSpace ~
29219 C-f\InsetSpace ~
29220 \InsetSpace ~
29221 \InsetSpace ~
29222 \InsetSpace ~
29223 \InsetSpace ~
29224 \InsetSpace ~
29225 \InsetSpace ~
29226 \InsetSpace ~
29227 \InsetSpace ~
29228 sdcdb-finish-from-src\InsetSpace ~
29229 \InsetSpace ~
29230 \InsetSpace ~
29231 \InsetSpace ~
29232 \InsetSpace ~
29233 \InsetSpace ~
29234 \InsetSpace ~
29235 \InsetSpace ~
29236 SDCDB finish command 
29237 \newline
29238 ;; 
29239 \newline
29240 ;;\InsetSpace ~
29241 C-x\InsetSpace ~
29242 SPC\InsetSpace ~
29243 \InsetSpace ~
29244 \InsetSpace ~
29245 \InsetSpace ~
29246 \InsetSpace ~
29247 \InsetSpace ~
29248 \InsetSpace ~
29249 \InsetSpace ~
29250 \InsetSpace ~
29251 sdcdb-brea
29252 k\InsetSpace ~
29253 \InsetSpace ~
29254 \InsetSpace ~
29255 \InsetSpace ~
29256 \InsetSpace ~
29257 \InsetSpace ~
29258 \InsetSpace ~
29259 \InsetSpace ~
29260 \InsetSpace ~
29261 \InsetSpace ~
29262 \InsetSpace ~
29263 \InsetSpace ~
29264 \InsetSpace ~
29265 \InsetSpace ~
29266 \InsetSpace ~
29267 \InsetSpace ~
29268 \InsetSpace ~
29269 \InsetSpace ~
29270 Set break for line with point 
29271 \newline
29272 ;;\InsetSpace ~
29273 ESC\InsetSpace ~
29274 t\InsetSpace ~
29275 \InsetSpace ~
29276 \InsetSpace ~
29277 \InsetSpace ~
29278 \InsetSpace ~
29279 \InsetSpace ~
29280 \InsetSpace ~
29281 \InsetSpace ~
29282 \InsetSpace ~
29283 \InsetSpace ~
29284 \InsetSpace ~
29285 sdcdbsrc-mode\InsetSpace ~
29286 \InsetSpace ~
29287 \InsetSpace ~
29288 \InsetSpace ~
29289 \InsetSpace ~
29290 \InsetSpace ~
29291 \InsetSpace ~
29292 \InsetSpace ~
29293 \InsetSpace ~
29294 \InsetSpace ~
29295 \InsetSpace ~
29296 \InsetSpace ~
29297 \InsetSpace ~
29298 \InsetSpace ~
29299 \InsetSpace ~
29300 \InsetSpace ~
29301 Toggle Sdcdbsrc mode 
29302 \newline
29303 ;;\InsetSpace ~
29304 ESC\InsetSpace ~
29305 m\InsetSpace ~
29306 \InsetSpace ~
29307 \InsetSpace ~
29308 \InsetSpace ~
29309 \InsetSpace ~
29310 \InsetSpace ~
29311 \InsetSpace ~
29312 \InsetSpace ~
29313 \InsetSpace ~
29314 \InsetSpace ~
29315 \InsetSpace ~
29316 sdc
29317 dbsrc-srcmode\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 Toggle list mode 
29331 \newline
29332 ;; 
29333 \newline
29334
29335 \family default
29336
29337 \newpage
29338
29339 \end_layout
29340
29341 \begin_layout Chapter
29342 TIPS
29343 \end_layout
29344
29345 \begin_layout Standard
29346 Here are a few guidelines that will help the compiler generate more efficient
29347  code, some of the tips are specific to this compiler others are generally
29348  good programming practice.
29349 \end_layout
29350
29351 \begin_layout Itemize
29352 Use the smallest data type to represent your data-value.
29353  If it is known in advance that the value is going to be less than 256 then
29354  use an 'unsigned char' instead of a 'short' or 'int'.
29355  Please note, that ANSI C requires both signed and unsigned chars to be
29356  promoted to 'signed int'
29357 \begin_inset LatexCommand \index{promotion to signed int}
29358
29359 \end_inset
29360
29361
29362 \begin_inset Marginal
29363 status collapsed
29364
29365 \begin_layout Standard
29366
29367 \series bold
29368 \InsetSpace ~
29369 !
29370 \end_layout
29371
29372 \end_inset
29373
29374  before doing any operation.
29375  This promotion
29376 \begin_inset LatexCommand \index{type promotion}
29377
29378 \end_inset
29379
29380
29381 \begin_inset LatexCommand \label{type promotion}
29382
29383 \end_inset
29384
29385  can be omitted, if the result is the same.
29386  The effect of the promotion rules together with the sign-extension is often
29387  surprising:
29388 \end_layout
29389
29390 \begin_deeper
29391 \begin_layout Verse
29392
29393 \family typewriter
29394 unsigned char uc = 0xfe;
29395 \newline
29396 if (uc * uc < 0) /* this is true! */
29397 \newline
29398 {
29399 \newline
29400 \InsetSpace ~
29401 \InsetSpace ~
29402 \InsetSpace ~
29403 \InsetSpace ~
29404 ....
29405 \newline
29406 }
29407 \end_layout
29408
29409 \begin_layout Standard
29410
29411 \family typewriter
29412 uc * uc
29413 \family default
29414  is evaluated as 
29415 \family typewriter
29416 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29417 \family default
29418 .
29419  
29420 \newline
29421 Another one:
29422 \end_layout
29423
29424 \begin_layout Verse
29425
29426 \family typewriter
29427 (unsigned char) -12 / (signed char) -3 = ...
29428 \end_layout
29429
29430 \begin_layout Standard
29431 No, the result is not 4:
29432 \end_layout
29433
29434 \begin_layout Verse
29435
29436 \family typewriter
29437 (int) (unsigned char) -12 / (int) (signed char) -3 =
29438 \newline
29439 (int) (unsigned char)
29440  0xf4 / (int) (signed char) 0xfd =
29441 \newline
29442 (int) 0x00f4 / (int) 0xfffd =
29443 \newline
29444 (int) 0x00f4
29445  / (int) 0xfffd =
29446 \newline
29447 (int) 244 / (int) -3 =
29448 \newline
29449 (int) -81 = (int) 0xffaf;
29450 \end_layout
29451
29452 \begin_layout Standard
29453 Don't complain, that gcc gives you a different result.
29454  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29455  Therefore the results are different.
29456 \newline
29457 From 
29458 \begin_inset Quotes sld
29459 \end_inset
29460
29461 comp.lang.c FAQ
29462 \begin_inset Quotes srd
29463 \end_inset
29464
29465 :
29466 \end_layout
29467
29468 \begin_layout Quote
29469
29470 \emph on
29471 If well-defined overflow characteristics are important and negative values
29472  are not, or if you want to steer clear of sign-extension problems when
29473  manipulating bits or bytes, use one of the corresponding unsigned types.
29474  (Beware when mixing signed and unsigned values in expressions, though.)
29475 \newline
29476 Although
29477  character types (especially unsigned char) can be used as "tiny" integers,
29478  doing so is sometimes more trouble than it's worth, due to unpredictable
29479  sign extension and increased code size.
29480 \end_layout
29481
29482 \end_deeper
29483 \begin_layout Itemize
29484 Use unsigned when it is known in advance that the value is not going to
29485  be negative.
29486  This helps especially if you are doing division or multiplication, bit-shifting
29487  or are using an array index.
29488 \end_layout
29489
29490 \begin_layout Itemize
29491 NEVER jump into a LOOP.
29492 \end_layout
29493
29494 \begin_layout Itemize
29495 Declare the variables to be local
29496 \begin_inset LatexCommand \index{local variables}
29497
29498 \end_inset
29499
29500  whenever possible, especially loop control variables (induction).
29501 \end_layout
29502
29503 \begin_layout Itemize
29504 Have a look at the assembly listing to get a 
29505 \begin_inset Quotes sld
29506 \end_inset
29507
29508 feeling
29509 \begin_inset Quotes srd
29510 \end_inset
29511
29512  for the code generation.
29513 \end_layout
29514
29515 \begin_layout Section
29516 Porting code from or to other compilers
29517 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29518
29519 \end_inset
29520
29521
29522 \end_layout
29523
29524 \begin_layout Itemize
29525 check whether endianness of the compilers differs and adapt where needed.
29526 \end_layout
29527
29528 \begin_layout Itemize
29529 check the device specific header files
29530 \begin_inset LatexCommand \index{Header files}
29531
29532 \end_inset
29533
29534
29535 \begin_inset LatexCommand \index{Include files}
29536
29537 \end_inset
29538
29539  for compiler specific syntax.
29540  Eventually include the file <compiler.h
29541 \begin_inset LatexCommand \index{compiler.h (include file)}
29542
29543 \end_inset
29544
29545
29546 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29547
29548 \end_inset
29549
29550  to allow using common header files.
29551  (see f.e.
29552  cc2510fx.h 
29553 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29554
29555 \end_inset
29556
29557 ).
29558 \end_layout
29559
29560 \begin_layout Itemize
29561 check whether the startup code contains the correct initialization (watchdog,
29562  peripherals).
29563 \end_layout
29564
29565 \begin_layout Itemize
29566 check whether the sizes of short, int, long match.
29567 \end_layout
29568
29569 \begin_layout Itemize
29570 check if some 16 or 32 bit hardware registers require a specific addressing
29571  order (least significant or most significant byte first) and adapt if needed
29572  (
29573 \emph on
29574 first
29575 \emph default
29576  and 
29577 \emph on
29578 last
29579 \emph default
29580  relate to time and not to lower/upper memory location here, so this is
29581  
29582 \emph on
29583 not
29584 \emph default
29585  the same as endianness).
29586 \end_layout
29587
29588 \begin_layout Itemize
29589 check whether the keyword 
29590 \emph on
29591 volatile
29592 \emph default
29593  is used where needed.
29594  The compilers might differ in their optimization characteristics (as different
29595  versions of the same compiler might also use more clever optimizations
29596  this is good idea anyway).
29597  See section 
29598 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29599
29600 \end_inset
29601
29602 .
29603 \end_layout
29604
29605 \begin_layout Itemize
29606 check that the compilers are not told to supress warnings.
29607 \end_layout
29608
29609 \begin_layout Itemize
29610 check and convert compiler specific extensions (interrupts, memory areas,
29611  pragmas etc.).
29612 \end_layout
29613
29614 \begin_layout Itemize
29615 check for differences in type promotion.
29616  Especially check for math operations on 
29617 \family typewriter
29618 char
29619 \family default
29620  or 
29621 \family typewriter
29622 unsigned char
29623 \family default
29624  variables.
29625  For the sake of C99 compatibility SDCC will probably promote these to 
29626 \family typewriter
29627 int
29628 \family default
29629  more often than other compilers.
29630  Eventually insert explicit casts to 
29631 \family typewriter
29632 (char) 
29633 \family default
29634 or
29635 \family typewriter
29636  (unsigned char)
29637 \family default
29638 .
29639  Also check that the ~\InsetSpace ~
29640 operator
29641 \begin_inset LatexCommand \index{\~\/ Operator}
29642
29643 \end_inset
29644
29645  is not used on 
29646 \family typewriter
29647 bit
29648 \begin_inset LatexCommand \index{bit}
29649
29650 \end_inset
29651
29652
29653 \family default
29654  variables, use the !\InsetSpace ~
29655 operator instead.
29656  See sections 
29657 \begin_inset LatexCommand \ref{type promotion}
29658
29659 \end_inset
29660
29661  and 
29662 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29663
29664 \end_inset
29665
29666 .
29667 \end_layout
29668
29669 \begin_layout Itemize
29670 check the assembly code generated for interrupt routines (f.e.
29671  for calls to possibly non-reentrant library functions).
29672 \end_layout
29673
29674 \begin_layout Itemize
29675 check whether timing loops result in proper timing (or preferably consider
29676  a rewrite of the code with timer based delays instead).
29677 \end_layout
29678
29679 \begin_layout Itemize
29680 check for differences in printf parameters (some compilers push (va_arg
29681 \begin_inset LatexCommand \index{vararg, va\_arg}
29682
29683 \end_inset
29684
29685 ) char variables as 
29686 \family typewriter
29687 int
29688 \family default
29689  others push them as 
29690 \family typewriter
29691 char
29692 \family default
29693 .
29694  See section 
29695 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29696
29697 \end_inset
29698
29699 ).
29700 \end_layout
29701
29702 \begin_layout Itemize
29703 check the resulting memory map
29704 \begin_inset LatexCommand \index{Memory map}
29705
29706 \end_inset
29707
29708 .
29709  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
29710 ly idata, pdata, xdata).
29711  Eventually check if unexpected library functions are included.
29712 \end_layout
29713
29714 \begin_layout Section
29715 Tools
29716 \begin_inset LatexCommand \index{Tools}
29717
29718 \end_inset
29719
29720  included in the distribution
29721 \end_layout
29722
29723 \begin_layout Standard
29724 \align left
29725 \begin_inset Tabular
29726 <lyxtabular version="3" rows="12" columns="3">
29727 <features>
29728 <column alignment="left" valignment="top" leftline="true" width="0pt">
29729 <column alignment="left" valignment="top" leftline="true" width="0pt">
29730 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29731 <row topline="true" bottomline="true">
29732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29733 \begin_inset Text
29734
29735 \begin_layout Standard
29736
29737 \series bold
29738 Name
29739 \end_layout
29740
29741 \end_inset
29742 </cell>
29743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29744 \begin_inset Text
29745
29746 \begin_layout Standard
29747
29748 \series bold
29749 Purpose
29750 \end_layout
29751
29752 \end_inset
29753 </cell>
29754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29755 \begin_inset Text
29756
29757 \begin_layout Standard
29758
29759 \series bold
29760 Directory
29761 \end_layout
29762
29763 \end_inset
29764 </cell>
29765 </row>
29766 <row topline="true">
29767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29768 \begin_inset Text
29769
29770 \begin_layout Standard
29771 uCsim
29772 \begin_inset LatexCommand \index{uCsim}
29773
29774 \end_inset
29775
29776
29777 \end_layout
29778
29779 \end_inset
29780 </cell>
29781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29782 \begin_inset Text
29783
29784 \begin_layout Standard
29785 Simulator for various architectures
29786 \end_layout
29787
29788 \end_inset
29789 </cell>
29790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29791 \begin_inset Text
29792
29793 \begin_layout Standard
29794 sdcc/sim/ucsim
29795 \end_layout
29796
29797 \end_inset
29798 </cell>
29799 </row>
29800 <row topline="true">
29801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29802 \begin_inset Text
29803
29804 \begin_layout Standard
29805 keil2sdcc.pl
29806 \end_layout
29807
29808 \end_inset
29809 </cell>
29810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29811 \begin_inset Text
29812
29813 \begin_layout Standard
29814 header file
29815 \begin_inset LatexCommand \index{Header files}
29816
29817 \end_inset
29818
29819
29820 \begin_inset LatexCommand \index{Include files}
29821
29822 \end_inset
29823
29824  conversion
29825 \end_layout
29826
29827 \end_inset
29828 </cell>
29829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29830 \begin_inset Text
29831
29832 \begin_layout Standard
29833 sdcc/support/scripts
29834 \end_layout
29835
29836 \end_inset
29837 </cell>
29838 </row>
29839 <row topline="true">
29840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29841 \begin_inset Text
29842
29843 \begin_layout Standard
29844 mh2h.c
29845 \end_layout
29846
29847 \end_inset
29848 </cell>
29849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29850 \begin_inset Text
29851
29852 \begin_layout Standard
29853 header file conversion
29854 \end_layout
29855
29856 \end_inset
29857 </cell>
29858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29859 \begin_inset Text
29860
29861 \begin_layout Standard
29862 sdcc/support/scripts
29863 \end_layout
29864
29865 \end_inset
29866 </cell>
29867 </row>
29868 <row topline="true">
29869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29870 \begin_inset Text
29871
29872 \begin_layout Standard
29873 as-gbz80
29874 \end_layout
29875
29876 \end_inset
29877 </cell>
29878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29879 \begin_inset Text
29880
29881 \begin_layout Standard
29882 Assembler
29883 \end_layout
29884
29885 \end_inset
29886 </cell>
29887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29888 \begin_inset Text
29889
29890 \begin_layout Standard
29891
29892 \family roman
29893 \series medium
29894 \shape up
29895 \size normal
29896 \emph off
29897 \bar no
29898 \noun off
29899 \color none
29900 sdcc/bin
29901 \end_layout
29902
29903 \end_inset
29904 </cell>
29905 </row>
29906 <row topline="true">
29907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29908 \begin_inset Text
29909
29910 \begin_layout Standard
29911 as-z80
29912 \end_layout
29913
29914 \end_inset
29915 </cell>
29916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29917 \begin_inset Text
29918
29919 \begin_layout Standard
29920 Assembler
29921 \end_layout
29922
29923 \end_inset
29924 </cell>
29925 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29926 \begin_inset Text
29927
29928 \begin_layout Standard
29929
29930 \family roman
29931 \series medium
29932 \shape up
29933 \size normal
29934 \emph off
29935 \bar no
29936 \noun off
29937 \color none
29938 sdcc/bin
29939 \end_layout
29940
29941 \end_inset
29942 </cell>
29943 </row>
29944 <row topline="true">
29945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29946 \begin_inset Text
29947
29948 \begin_layout Standard
29949 asx8051
29950 \end_layout
29951
29952 \end_inset
29953 </cell>
29954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29955 \begin_inset Text
29956
29957 \begin_layout Standard
29958 Assembler
29959 \end_layout
29960
29961 \end_inset
29962 </cell>
29963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29964 \begin_inset Text
29965
29966 \begin_layout Standard
29967
29968 \family roman
29969 \series medium
29970 \shape up
29971 \size normal
29972 \emph off
29973 \bar no
29974 \noun off
29975 \color none
29976 sdcc/bin
29977 \end_layout
29978
29979 \end_inset
29980 </cell>
29981 </row>
29982 <row topline="true">
29983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29984 \begin_inset Text
29985
29986 \begin_layout Standard
29987 SDCDB
29988 \end_layout
29989
29990 \end_inset
29991 </cell>
29992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29993 \begin_inset Text
29994
29995 \begin_layout Standard
29996 Simulator
29997 \end_layout
29998
29999 \end_inset
30000 </cell>
30001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30002 \begin_inset Text
30003
30004 \begin_layout Standard
30005
30006 \family roman
30007 \series medium
30008 \shape up
30009 \size normal
30010 \emph off
30011 \bar no
30012 \noun off
30013 \color none
30014 sdcc/bin
30015 \end_layout
30016
30017 \end_inset
30018 </cell>
30019 </row>
30020 <row topline="true">
30021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30022 \begin_inset Text
30023
30024 \begin_layout Standard
30025 aslink
30026 \end_layout
30027
30028 \end_inset
30029 </cell>
30030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30031 \begin_inset Text
30032
30033 \begin_layout Standard
30034 Linker
30035 \end_layout
30036
30037 \end_inset
30038 </cell>
30039 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30040 \begin_inset Text
30041
30042 \begin_layout Standard
30043
30044 \family roman
30045 \series medium
30046 \shape up
30047 \size normal
30048 \emph off
30049 \bar no
30050 \noun off
30051 \color none
30052 sdcc/bin
30053 \end_layout
30054
30055 \end_inset
30056 </cell>
30057 </row>
30058 <row topline="true">
30059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30060 \begin_inset Text
30061
30062 \begin_layout Standard
30063 link-z80
30064 \end_layout
30065
30066 \end_inset
30067 </cell>
30068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30069 \begin_inset Text
30070
30071 \begin_layout Standard
30072 Linker
30073 \end_layout
30074
30075 \end_inset
30076 </cell>
30077 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30078 \begin_inset Text
30079
30080 \begin_layout Standard
30081
30082 \family roman
30083 \series medium
30084 \shape up
30085 \size normal
30086 \emph off
30087 \bar no
30088 \noun off
30089 \color none
30090 sdcc/bin
30091 \end_layout
30092
30093 \end_inset
30094 </cell>
30095 </row>
30096 <row topline="true">
30097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30098 \begin_inset Text
30099
30100 \begin_layout Standard
30101 link-gbz80
30102 \end_layout
30103
30104 \end_inset
30105 </cell>
30106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30107 \begin_inset Text
30108
30109 \begin_layout Standard
30110 Linker
30111 \end_layout
30112
30113 \end_inset
30114 </cell>
30115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30116 \begin_inset Text
30117
30118 \begin_layout Standard
30119
30120 \family roman
30121 \series medium
30122 \shape up
30123 \size normal
30124 \emph off
30125 \bar no
30126 \noun off
30127 \color none
30128 sdcc/bin
30129 \end_layout
30130
30131 \end_inset
30132 </cell>
30133 </row>
30134 <row topline="true" bottomline="true">
30135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30136 \begin_inset Text
30137
30138 \begin_layout Standard
30139 packihx
30140 \end_layout
30141
30142 \end_inset
30143 </cell>
30144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30145 \begin_inset Text
30146
30147 \begin_layout Standard
30148 Intel Hex packer 
30149 \begin_inset LatexCommand \index{packihx (tool)}
30150
30151 \end_inset
30152
30153
30154 \end_layout
30155
30156 \end_inset
30157 </cell>
30158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30159 \begin_inset Text
30160
30161 \begin_layout Standard
30162
30163 \family roman
30164 \series medium
30165 \shape up
30166 \size normal
30167 \emph off
30168 \bar no
30169 \noun off
30170 \color none
30171 sdcc/bin
30172 \end_layout
30173
30174 \end_inset
30175 </cell>
30176 </row>
30177 </lyxtabular>
30178
30179 \end_inset
30180
30181
30182 \newline
30183
30184 \end_layout
30185
30186 \begin_layout Section
30187 Documentation
30188 \begin_inset LatexCommand \index{Documentation}
30189
30190 \end_inset
30191
30192  included in the distribution
30193 \end_layout
30194
30195 \begin_layout Standard
30196 \align left
30197 \begin_inset Tabular
30198 <lyxtabular version="3" rows="10" columns="2">
30199 <features>
30200 <column alignment="block" valignment="top" leftline="true" width="40col%">
30201 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
30202 <row topline="true" bottomline="true" endhead="true">
30203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30204 \begin_inset Text
30205
30206 \begin_layout Standard
30207
30208 \series bold
30209 Subject / Title
30210 \end_layout
30211
30212 \end_inset
30213 </cell>
30214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30215 \begin_inset Text
30216
30217 \begin_layout Standard
30218
30219 \series bold
30220 Filename / Where to get
30221 \end_layout
30222
30223 \end_inset
30224 </cell>
30225 </row>
30226 <row topline="true">
30227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30228 \begin_inset Text
30229
30230 \begin_layout Standard
30231 SDCC Compiler User Guide
30232 \end_layout
30233
30234 \end_inset
30235 </cell>
30236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30237 \begin_inset Text
30238
30239 \begin_layout Standard
30240 You're reading it right now
30241 \emph on
30242  \InsetSpace ~
30243 \InsetSpace ~
30244 \InsetSpace ~
30245
30246 \hfill
30247 online at:
30248 \emph default
30249
30250 \newline
30251
30252 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
30253
30254 \end_inset
30255
30256
30257 \end_layout
30258
30259 \end_inset
30260 </cell>
30261 </row>
30262 <row topline="true">
30263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30264 \begin_inset Text
30265
30266 \begin_layout Standard
30267 Changelog of SDCC
30268 \end_layout
30269
30270 \end_inset
30271 </cell>
30272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30273 \begin_inset Text
30274
30275 \begin_layout Standard
30276 sdcc/Changelog
30277 \emph on
30278  \InsetSpace ~
30279 \InsetSpace ~
30280 \InsetSpace ~
30281
30282 \hfill
30283 online at:
30284 \emph default
30285
30286 \newline
30287
30288 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
30289
30290 \end_inset
30291
30292
30293 \end_layout
30294
30295 \end_inset
30296 </cell>
30297 </row>
30298 <row topline="true">
30299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30300 \begin_inset Text
30301
30302 \begin_layout Standard
30303 ASXXXX
30304 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
30305
30306 \end_inset
30307
30308
30309 \begin_inset LatexCommand \index{Assembler documentation}
30310
30311 \end_inset
30312
30313  Assemblers and
30314 \newline
30315 ASLINK
30316 \begin_inset LatexCommand \index{aslink}
30317
30318 \end_inset
30319
30320
30321 \begin_inset LatexCommand \index{Linker documentation}
30322
30323 \end_inset
30324
30325  Relocating Linker
30326 \end_layout
30327
30328 \end_inset
30329 </cell>
30330 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30331 \begin_inset Text
30332
30333 \begin_layout Standard
30334 sdcc/as/doc/asxhtm.html 
30335 \emph on
30336 \InsetSpace ~
30337 \InsetSpace ~
30338 \InsetSpace ~
30339
30340 \hfill
30341 online at:
30342 \emph default
30343
30344 \newline
30345
30346 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
30347
30348 \end_inset
30349
30350
30351 \end_layout
30352
30353 \end_inset
30354 </cell>
30355 </row>
30356 <row topline="true">
30357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30358 \begin_inset Text
30359
30360 \begin_layout Standard
30361 SDCC regression test
30362 \begin_inset LatexCommand \index{Regression test}
30363
30364 \end_inset
30365
30366
30367 \end_layout
30368
30369 \end_inset
30370 </cell>
30371 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30372 \begin_inset Text
30373
30374 \begin_layout Standard
30375 sdcc/doc/test_suite_spec.pdf 
30376 \emph on
30377 \InsetSpace ~
30378 \InsetSpace ~
30379 \InsetSpace ~
30380
30381 \hfill
30382 online at:
30383 \emph default
30384
30385 \newline
30386
30387 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30388
30389 \end_inset
30390
30391
30392 \end_layout
30393
30394 \end_inset
30395 </cell>
30396 </row>
30397 <row topline="true">
30398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30399 \begin_inset Text
30400
30401 \begin_layout Standard
30402 Various notes
30403 \end_layout
30404
30405 \end_inset
30406 </cell>
30407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30408 \begin_inset Text
30409
30410 \begin_layout Standard
30411 sdcc/doc/* 
30412 \emph on
30413 \InsetSpace ~
30414 \InsetSpace ~
30415 \InsetSpace ~
30416
30417 \hfill
30418 online at:
30419 \emph default
30420
30421 \newline
30422
30423 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30424
30425 \end_inset
30426
30427
30428 \end_layout
30429
30430 \end_inset
30431 </cell>
30432 </row>
30433 <row topline="true">
30434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30435 \begin_inset Text
30436
30437 \begin_layout Standard
30438 Notes on debugging with SDCDB
30439 \begin_inset LatexCommand \index{SDCDB (debugger)}
30440
30441 \end_inset
30442
30443
30444 \end_layout
30445
30446 \end_inset
30447 </cell>
30448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30449 \begin_inset Text
30450
30451 \begin_layout Standard
30452 sdcc/debugger/README 
30453 \emph on
30454 \InsetSpace ~
30455 \InsetSpace ~
30456 \InsetSpace ~
30457
30458 \hfill
30459 online at
30460 \emph default
30461 :
30462 \newline
30463
30464 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30465
30466 \end_inset
30467
30468
30469 \end_layout
30470
30471 \end_inset
30472 </cell>
30473 </row>
30474 <row topline="true">
30475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30476 \begin_inset Text
30477
30478 \begin_layout Standard
30479 uCsim
30480 \begin_inset LatexCommand \index{uCsim}
30481
30482 \end_inset
30483
30484  Software simulator for microcontrollers
30485 \end_layout
30486
30487 \end_inset
30488 </cell>
30489 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30490 \begin_inset Text
30491
30492 \begin_layout Standard
30493
30494 \family roman
30495 \series medium
30496 \shape up
30497 \size normal
30498 \emph off
30499 \bar no
30500 \noun off
30501 \color none
30502 sdcc/sim/ucsim/doc
30503 \family default
30504 \series default
30505 \shape default
30506 \size default
30507 \emph default
30508 \bar default
30509 \noun default
30510 /index.html 
30511 \emph on
30512 \InsetSpace ~
30513 \InsetSpace ~
30514 \InsetSpace ~
30515
30516 \hfill
30517 online at:
30518 \emph default
30519
30520 \newline
30521
30522 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30523
30524 \end_inset
30525
30526
30527 \end_layout
30528
30529 \end_inset
30530 </cell>
30531 </row>
30532 <row topline="true">
30533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30534 \begin_inset Text
30535
30536 \begin_layout Standard
30537 Temporary notes on the pic16
30538 \begin_inset LatexCommand \index{PIC16}
30539
30540 \end_inset
30541
30542  port
30543 \end_layout
30544
30545 \end_inset
30546 </cell>
30547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30548 \begin_inset Text
30549
30550 \begin_layout Standard
30551 sdcc/src/pic16/NOTES 
30552 \emph on
30553 \InsetSpace ~
30554 \InsetSpace ~
30555 \InsetSpace ~
30556
30557 \hfill
30558 online at:
30559 \newline
30560
30561 \emph default
30562
30563 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30564
30565 \end_inset
30566
30567
30568 \end_layout
30569
30570 \end_inset
30571 </cell>
30572 </row>
30573 <row topline="true" bottomline="true">
30574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30575 \begin_inset Text
30576
30577 \begin_layout Standard
30578 SDCC internal documentation (debugging file format)
30579 \end_layout
30580
30581 \end_inset
30582 </cell>
30583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30584 \begin_inset Text
30585
30586 \begin_layout Standard
30587 sdcc/doc/
30588 \family roman
30589 \series medium
30590 \shape up
30591 \size normal
30592 \emph off
30593 \bar no
30594 \noun off
30595 \color none
30596 cdbfileformat.pd
30597 \family default
30598 \series default
30599 \shape default
30600 \size default
30601 \emph default
30602 \bar default
30603 \noun default
30604 f
30605 \emph on
30606  \InsetSpace ~
30607 \InsetSpace ~
30608 \InsetSpace ~
30609
30610 \hfill
30611 online at:
30612 \emph default
30613
30614 \newline
30615
30616 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30617
30618 \end_inset
30619
30620
30621 \end_layout
30622
30623 \end_inset
30624 </cell>
30625 </row>
30626 </lyxtabular>
30627
30628 \end_inset
30629
30630
30631 \newline
30632
30633 \end_layout
30634
30635 \begin_layout Section
30636 Related open source tools
30637 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
30638
30639 \end_inset
30640
30641
30642 \begin_inset LatexCommand \index{Related tools}
30643
30644 \end_inset
30645
30646
30647 \end_layout
30648
30649 \begin_layout Standard
30650 \align left
30651 \begin_inset Tabular
30652 <lyxtabular version="3" rows="14" columns="3">
30653 <features>
30654 <column alignment="left" valignment="top" leftline="true" width="0pt">
30655 <column alignment="block" valignment="top" leftline="true" width="30line%">
30656 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30657 <row topline="true" bottomline="true">
30658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30659 \begin_inset Text
30660
30661 \begin_layout Standard
30662
30663 \series bold
30664 Name
30665 \end_layout
30666
30667 \end_inset
30668 </cell>
30669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30670 \begin_inset Text
30671
30672 \begin_layout Standard
30673
30674 \series bold
30675 Purpose
30676 \end_layout
30677
30678 \end_inset
30679 </cell>
30680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30681 \begin_inset Text
30682
30683 \begin_layout Standard
30684
30685 \series bold
30686 Where to get
30687 \end_layout
30688
30689 \end_inset
30690 </cell>
30691 </row>
30692 <row topline="true">
30693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30694 \begin_inset Text
30695
30696 \begin_layout Standard
30697 gpsim
30698 \begin_inset LatexCommand \index{gpsim (pic simulator)}
30699
30700 \end_inset
30701
30702
30703 \end_layout
30704
30705 \end_inset
30706 </cell>
30707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30708 \begin_inset Text
30709
30710 \begin_layout Standard
30711 PIC simulator
30712 \end_layout
30713
30714 \end_inset
30715 </cell>
30716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30717 \begin_inset Text
30718
30719 \begin_layout Standard
30720 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
30721
30722 \end_inset
30723
30724
30725 \end_layout
30726
30727 \end_inset
30728 </cell>
30729 </row>
30730 <row topline="true">
30731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30732 \begin_inset Text
30733
30734 \begin_layout Standard
30735 gputils
30736 \begin_inset LatexCommand \index{gputils (pic tools)}
30737
30738 \end_inset
30739
30740
30741 \end_layout
30742
30743 \end_inset
30744 </cell>
30745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30746 \begin_inset Text
30747
30748 \begin_layout Standard
30749 GNU PIC utilities
30750 \end_layout
30751
30752 \end_inset
30753 </cell>
30754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30755 \begin_inset Text
30756
30757 \begin_layout Standard
30758 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
30759
30760 \end_inset
30761
30762
30763 \end_layout
30764
30765 \end_inset
30766 </cell>
30767 </row>
30768 <row topline="true">
30769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30770 \begin_inset Text
30771
30772 \begin_layout Standard
30773 flP5
30774 \end_layout
30775
30776 \end_inset
30777 </cell>
30778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30779 \begin_inset Text
30780
30781 \begin_layout Standard
30782 PIC programmer
30783 \end_layout
30784
30785 \end_inset
30786 </cell>
30787 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30788 \begin_inset Text
30789
30790 \begin_layout Standard
30791 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
30792
30793 \end_inset
30794
30795
30796 \end_layout
30797
30798 \end_inset
30799 </cell>
30800 </row>
30801 <row topline="true">
30802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30803 \begin_inset Text
30804
30805 \begin_layout Standard
30806 ec2drv/newcdb
30807 \end_layout
30808
30809 \end_inset
30810 </cell>
30811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30812 \begin_inset Text
30813
30814 \begin_layout Standard
30815 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
30816  (Unix only)
30817 \end_layout
30818
30819 \end_inset
30820 </cell>
30821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30822 \begin_inset Text
30823
30824 \begin_layout Standard
30825 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
30826
30827 \end_inset
30828
30829
30830 \end_layout
30831
30832 \end_inset
30833 </cell>
30834 </row>
30835 <row topline="true">
30836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30837 \begin_inset Text
30838
30839 \begin_layout Standard
30840 indent
30841 \begin_inset LatexCommand \index{indent (source formatting tool)}
30842
30843 \end_inset
30844
30845
30846 \end_layout
30847
30848 \end_inset
30849 </cell>
30850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30851 \begin_inset Text
30852
30853 \begin_layout Standard
30854 Formats C source - Master of the white spaces
30855 \end_layout
30856
30857 \end_inset
30858 </cell>
30859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30860 \begin_inset Text
30861
30862 \begin_layout Standard
30863 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
30864
30865 \end_inset
30866
30867
30868 \end_layout
30869
30870 \end_inset
30871 </cell>
30872 </row>
30873 <row topline="true">
30874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30875 \begin_inset Text
30876
30877 \begin_layout Standard
30878 srecord
30879 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
30880
30881 \end_inset
30882
30883
30884 \end_layout
30885
30886 \end_inset
30887 </cell>
30888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30889 \begin_inset Text
30890
30891 \begin_layout Standard
30892 Object file conversion, checksumming, ...
30893 \end_layout
30894
30895 \end_inset
30896 </cell>
30897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30898 \begin_inset Text
30899
30900 \begin_layout Standard
30901 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
30902
30903 \end_inset
30904
30905
30906 \end_layout
30907
30908 \end_inset
30909 </cell>
30910 </row>
30911 <row topline="true">
30912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30913 \begin_inset Text
30914
30915 \begin_layout Standard
30916 objdump
30917 \begin_inset LatexCommand \index{objdump (tool)}
30918
30919 \end_inset
30920
30921
30922 \end_layout
30923
30924 \end_inset
30925 </cell>
30926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30927 \begin_inset Text
30928
30929 \begin_layout Standard
30930 Object file conversion, ...
30931 \end_layout
30932
30933 \end_inset
30934 </cell>
30935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30936 \begin_inset Text
30937
30938 \begin_layout Standard
30939 Part of binutils (should be there anyway)
30940 \end_layout
30941
30942 \end_inset
30943 </cell>
30944 </row>
30945 <row topline="true">
30946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30947 \begin_inset Text
30948
30949 \begin_layout Standard
30950 cmon51
30951 \end_layout
30952
30953 \end_inset
30954 </cell>
30955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30956 \begin_inset Text
30957
30958 \begin_layout Standard
30959 8051 monitor (hex up-/download, single step, disassemble)
30960 \end_layout
30961
30962 \end_inset
30963 </cell>
30964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30965 \begin_inset Text
30966
30967 \begin_layout Standard
30968 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
30969
30970 \end_inset
30971
30972
30973 \end_layout
30974
30975 \end_inset
30976 </cell>
30977 </row>
30978 <row topline="true">
30979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30980 \begin_inset Text
30981
30982 \begin_layout Standard
30983 doxygen
30984 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
30985
30986 \end_inset
30987
30988
30989 \end_layout
30990
30991 \end_inset
30992 </cell>
30993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30994 \begin_inset Text
30995
30996 \begin_layout Standard
30997 Source code documentation system
30998 \end_layout
30999
31000 \end_inset
31001 </cell>
31002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31003 \begin_inset Text
31004
31005 \begin_layout Standard
31006 \begin_inset LatexCommand \url{http://www.doxygen.org}
31007
31008 \end_inset
31009
31010
31011 \end_layout
31012
31013 \end_inset
31014 </cell>
31015 </row>
31016 <row topline="true">
31017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31018 \begin_inset Text
31019
31020 \begin_layout Standard
31021 kdevelop
31022 \end_layout
31023
31024 \end_inset
31025 </cell>
31026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31027 \begin_inset Text
31028
31029 \begin_layout Standard
31030 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
31031 \end_layout
31032
31033 \end_inset
31034 </cell>
31035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31036 \begin_inset Text
31037
31038 \begin_layout Standard
31039 \begin_inset LatexCommand \url{http://www.kdevelop.org}
31040
31041 \end_inset
31042
31043
31044 \end_layout
31045
31046 \end_inset
31047 </cell>
31048 </row>
31049 <row topline="true">
31050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31051 \begin_inset Text
31052
31053 \begin_layout Standard
31054 paulmon
31055 \end_layout
31056
31057 \end_inset
31058 </cell>
31059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31060 \begin_inset Text
31061
31062 \begin_layout Standard
31063 8051 monitor (hex up-/download, single step, disassemble)
31064 \end_layout
31065
31066 \end_inset
31067 </cell>
31068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31069 \begin_inset Text
31070
31071 \begin_layout Standard
31072 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
31073
31074 \end_inset
31075
31076
31077 \end_layout
31078
31079 \end_inset
31080 </cell>
31081 </row>
31082 <row topline="true">
31083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31084 \begin_inset Text
31085
31086 \begin_layout Standard
31087 splint
31088 \begin_inset LatexCommand \index{splint (syntax checking tool)}
31089
31090 \end_inset
31091
31092
31093 \end_layout
31094
31095 \end_inset
31096 </cell>
31097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31098 \begin_inset Text
31099
31100 \begin_layout Standard
31101 Statically checks c sources (see 
31102 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
31103
31104 \end_inset
31105
31106 )
31107 \end_layout
31108
31109 \end_inset
31110 </cell>
31111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31112 \begin_inset Text
31113
31114 \begin_layout Standard
31115 \begin_inset LatexCommand \url{http://www.splint.org}
31116
31117 \end_inset
31118
31119
31120 \end_layout
31121
31122 \end_inset
31123 </cell>
31124 </row>
31125 <row topline="true" bottomline="true">
31126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31127 \begin_inset Text
31128
31129 \begin_layout Standard
31130 ddd
31131 \begin_inset LatexCommand \index{DDD (debugger)}
31132
31133 \end_inset
31134
31135
31136 \end_layout
31137
31138 \end_inset
31139 </cell>
31140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31141 \begin_inset Text
31142
31143 \begin_layout Standard
31144 Debugger, serves nicely as GUI to SDCDB
31145 \begin_inset LatexCommand \index{SDCDB (debugger)}
31146
31147 \end_inset
31148
31149  (Unix only)
31150 \end_layout
31151
31152 \end_inset
31153 </cell>
31154 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31155 \begin_inset Text
31156
31157 \begin_layout Standard
31158 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
31159
31160 \end_inset
31161
31162
31163 \end_layout
31164
31165 \end_inset
31166 </cell>
31167 </row>
31168 </lyxtabular>
31169
31170 \end_inset
31171
31172
31173 \newline
31174
31175 \end_layout
31176
31177 \begin_layout Section
31178 Related documentation / recommended reading
31179 \end_layout
31180
31181 \begin_layout Standard
31182 \align left
31183 \begin_inset Tabular
31184 <lyxtabular version="3" rows="7" columns="3">
31185 <features>
31186 <column alignment="left" valignment="top" leftline="true" width="0pt">
31187 <column alignment="left" valignment="top" leftline="true" width="0">
31188 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
31189 <row topline="true" bottomline="true">
31190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31191 \begin_inset Text
31192
31193 \begin_layout Standard
31194
31195 \series bold
31196 Name
31197 \end_layout
31198
31199 \end_inset
31200 </cell>
31201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31202 \begin_inset Text
31203
31204 \begin_layout Standard
31205
31206 \series bold
31207 Subject / Title
31208 \end_layout
31209
31210 \end_inset
31211 </cell>
31212 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31213 \begin_inset Text
31214
31215 \begin_layout Standard
31216
31217 \series bold
31218 Where to get
31219 \end_layout
31220
31221 \end_inset
31222 </cell>
31223 </row>
31224 <row topline="true">
31225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31226 \begin_inset Text
31227
31228 \begin_layout Standard
31229
31230 \family roman
31231 \series medium
31232 \shape up
31233 \size normal
31234 \emph off
31235 \bar no
31236 \noun off
31237 \color none
31238 c-refcard.pdf
31239 \end_layout
31240
31241 \end_inset
31242 </cell>
31243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31244 \begin_inset Text
31245
31246 \begin_layout Standard
31247 C Reference Card
31248 \begin_inset LatexCommand \index{C Reference card}
31249
31250 \end_inset
31251
31252 , 2 pages
31253 \end_layout
31254
31255 \end_inset
31256 </cell>
31257 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31258 \begin_inset Text
31259
31260 \begin_layout Standard
31261 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
31262
31263 \end_inset
31264
31265
31266 \end_layout
31267
31268 \end_inset
31269 </cell>
31270 </row>
31271 <row topline="true">
31272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31273 \begin_inset Text
31274
31275 \begin_layout Standard
31276 c-faq
31277 \end_layout
31278
31279 \end_inset
31280 </cell>
31281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31282 \begin_inset Text
31283
31284 \begin_layout Standard
31285 C-FAQ
31286 \begin_inset LatexCommand \index{C FAQ}
31287
31288 \end_inset
31289
31290
31291 \end_layout
31292
31293 \end_inset
31294 </cell>
31295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31296 \begin_inset Text
31297
31298 \begin_layout Standard
31299 \begin_inset LatexCommand \url{http://www.c-faq.com}
31300
31301 \end_inset
31302
31303
31304 \end_layout
31305
31306 \end_inset
31307 </cell>
31308 </row>
31309 <row topline="true">
31310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31311 \begin_inset Text
31312
31313 \begin_layout Standard
31314 ISO/IEC 9899:TC2
31315 \end_layout
31316
31317 \end_inset
31318 </cell>
31319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31320 \begin_inset Text
31321
31322 \begin_layout Standard
31323 \begin_inset Quotes sld
31324 \end_inset
31325
31326 C-Standard
31327 \begin_inset Quotes srd
31328 \end_inset
31329
31330
31331 \end_layout
31332
31333 \end_inset
31334 </cell>
31335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31336 \begin_inset Text
31337
31338 \begin_layout Standard
31339
31340 \size footnotesize
31341 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
31342
31343 \end_inset
31344
31345
31346 \end_layout
31347
31348 \end_inset
31349 </cell>
31350 </row>
31351 <row topline="true">
31352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31353 \begin_inset Text
31354
31355 \begin_layout Standard
31356 ISO/IEC DTR 18037
31357 \end_layout
31358
31359 \end_inset
31360 </cell>
31361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31362 \begin_inset Text
31363
31364 \begin_layout Standard
31365 \begin_inset Quotes sld
31366 \end_inset
31367
31368 Extensions for Embedded C
31369 \begin_inset Quotes srd
31370 \end_inset
31371
31372
31373 \end_layout
31374
31375 \end_inset
31376 </cell>
31377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31378 \begin_inset Text
31379
31380 \begin_layout Standard
31381
31382 \size footnotesize
31383 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31384
31385 \end_inset
31386
31387
31388 \end_layout
31389
31390 \end_inset
31391 </cell>
31392 </row>
31393 <row topline="true">
31394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31395 \begin_inset Text
31396
31397 \begin_layout Standard
31398
31399 \end_layout
31400
31401 \end_inset
31402 </cell>
31403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31404 \begin_inset Text
31405
31406 \begin_layout Standard
31407 Latest datasheet of target CPU
31408 \end_layout
31409
31410 \end_inset
31411 </cell>
31412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31413 \begin_inset Text
31414
31415 \begin_layout Standard
31416 vendor
31417 \end_layout
31418
31419 \end_inset
31420 </cell>
31421 </row>
31422 <row topline="true" bottomline="true">
31423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31424 \begin_inset Text
31425
31426 \begin_layout Standard
31427
31428 \end_layout
31429
31430 \end_inset
31431 </cell>
31432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31433 \begin_inset Text
31434
31435 \begin_layout Standard
31436 Revision history of datasheet
31437 \end_layout
31438
31439 \end_inset
31440 </cell>
31441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31442 \begin_inset Text
31443
31444 \begin_layout Standard
31445 vendor
31446 \end_layout
31447
31448 \end_inset
31449 </cell>
31450 </row>
31451 </lyxtabular>
31452
31453 \end_inset
31454
31455
31456 \newline
31457
31458 \end_layout
31459
31460 \begin_layout Section
31461 Application notes specifically for SDCC
31462 \end_layout
31463
31464 \begin_layout Standard
31465 SDCC makes no claims about the completeness of this list and about up-to-datenes
31466 s or correctness of the application notes
31467 \begin_inset LatexCommand \index{Application notes}
31468
31469 \end_inset
31470
31471 .
31472 \end_layout
31473
31474 \begin_layout Standard
31475 \align left
31476
31477 \size footnotesize
31478 \begin_inset Tabular
31479 <lyxtabular version="3" rows="7" columns="3">
31480 <features>
31481 <column alignment="block" valignment="top" leftline="true" width="17col%">
31482 <column alignment="block" valignment="top" leftline="true" width="27col%">
31483 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
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 \series bold
31491 \size footnotesize
31492 Vendor
31493 \end_layout
31494
31495 \end_inset
31496 </cell>
31497 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31498 \begin_inset Text
31499
31500 \begin_layout Standard
31501
31502 \series bold
31503 \size footnotesize
31504 Subject / Title
31505 \end_layout
31506
31507 \end_inset
31508 </cell>
31509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31510 \begin_inset Text
31511
31512 \begin_layout Standard
31513
31514 \series bold
31515 \size footnotesize
31516 Where to get
31517 \end_layout
31518
31519 \end_inset
31520 </cell>
31521 </row>
31522 <row topline="true">
31523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31524 \begin_inset Text
31525
31526 \begin_layout Standard
31527
31528 \size footnotesize
31529 Maxim / Dallas
31530 \end_layout
31531
31532 \end_inset
31533 </cell>
31534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31535 \begin_inset Text
31536
31537 \begin_layout Standard
31538
31539 \size footnotesize
31540 Using the SDCC Compiler for the DS80C400
31541 \begin_inset LatexCommand \index{DS80C400}
31542
31543 \end_inset
31544
31545
31546 \end_layout
31547
31548 \end_inset
31549 </cell>
31550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31551 \begin_inset Text
31552
31553 \begin_layout Standard
31554
31555 \size footnotesize
31556 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31557
31558 \end_inset
31559
31560
31561 \end_layout
31562
31563 \end_inset
31564 </cell>
31565 </row>
31566 <row topline="true">
31567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31568 \begin_inset Text
31569
31570 \begin_layout Standard
31571
31572 \size footnotesize
31573 Maxim / Dallas
31574 \end_layout
31575
31576 \end_inset
31577 </cell>
31578 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31579 \begin_inset Text
31580
31581 \begin_layout Standard
31582
31583 \size footnotesize
31584 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31585 \begin_inset LatexCommand \index{DS89C4x0}
31586
31587 \end_inset
31588
31589  Family of Microcontrollers
31590 \end_layout
31591
31592 \end_inset
31593 </cell>
31594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31595 \begin_inset Text
31596
31597 \begin_layout Standard
31598
31599 \size footnotesize
31600 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31601
31602 \end_inset
31603
31604
31605 \end_layout
31606
31607 \end_inset
31608 </cell>
31609 </row>
31610 <row topline="true">
31611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31612 \begin_inset Text
31613
31614 \begin_layout Standard
31615
31616 \size footnotesize
31617 Silicon Laboratories / Cygnal
31618 \end_layout
31619
31620 \end_inset
31621 </cell>
31622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31623 \begin_inset Text
31624
31625 \begin_layout Standard
31626
31627 \size footnotesize
31628 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31629 \begin_inset LatexCommand \index{IDE}
31630
31631 \end_inset
31632
31633
31634 \end_layout
31635
31636 \end_inset
31637 </cell>
31638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31639 \begin_inset Text
31640
31641 \begin_layout Standard
31642
31643 \size footnotesize
31644 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
31645
31646 \end_inset
31647
31648
31649 \end_layout
31650
31651 \end_inset
31652 </cell>
31653 </row>
31654 <row topline="true">
31655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31656 \begin_inset Text
31657
31658 \begin_layout Standard
31659
31660 \size footnotesize
31661 Ramtron / Goal Semiconductor
31662 \end_layout
31663
31664 \end_inset
31665 </cell>
31666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31667 \begin_inset Text
31668
31669 \begin_layout Standard
31670
31671 \size footnotesize
31672 Interfacing SDCC to Syn and Textpad
31673 \end_layout
31674
31675 \end_inset
31676 </cell>
31677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31678 \begin_inset Text
31679
31680 \begin_layout Standard
31681
31682 \size footnotesize
31683 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31684
31685 \end_inset
31686
31687
31688 \end_layout
31689
31690 \end_inset
31691 </cell>
31692 </row>
31693 <row topline="true">
31694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31695 \begin_inset Text
31696
31697 \begin_layout Standard
31698
31699 \size footnotesize
31700 Ramtron / Goal Semiconductor
31701 \end_layout
31702
31703 \end_inset
31704 </cell>
31705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31706 \begin_inset Text
31707
31708 \begin_layout Standard
31709
31710 \size footnotesize
31711 Installing and Configuring SDCC and Crimson Editor 
31712 \end_layout
31713
31714 \end_inset
31715 </cell>
31716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31717 \begin_inset Text
31718
31719 \begin_layout Standard
31720
31721 \size footnotesize
31722 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31723
31724 \end_inset
31725
31726
31727 \end_layout
31728
31729 \end_inset
31730 </cell>
31731 </row>
31732 <row topline="true" bottomline="true">
31733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31734 \begin_inset Text
31735
31736 \begin_layout Standard
31737
31738 \size footnotesize
31739 Texas Instruments
31740 \end_layout
31741
31742 \end_inset
31743 </cell>
31744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31745 \begin_inset Text
31746
31747 \begin_layout Standard
31748
31749 \size footnotesize
31750 MSC12xx Programming with SDCC
31751 \end_layout
31752
31753 \end_inset
31754 </cell>
31755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31756 \begin_inset Text
31757
31758 \begin_layout Standard
31759
31760 \size footnotesize
31761 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
31762
31763 \end_inset
31764
31765
31766 \end_layout
31767
31768 \end_inset
31769 </cell>
31770 </row>
31771 </lyxtabular>
31772
31773 \end_inset
31774
31775
31776 \end_layout
31777
31778 \begin_layout Section
31779 Some Questions
31780 \end_layout
31781
31782 \begin_layout Standard
31783 Some questions answered, some pointers given - it might be time to in turn
31784  ask 
31785 \emph on
31786 you
31787 \emph default
31788  some questions: 
31789 \end_layout
31790
31791 \begin_layout Itemize
31792 can you solve your project with the selected microcontroller? Would you
31793  find out early or rather late that your target is too small/slow/whatever?
31794  Can you switch to a slightly better device if it doesn't fit?
31795 \end_layout
31796
31797 \begin_layout Itemize
31798 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
31799  and/or another programming language be more adequate? Would an operating
31800  system on the target device help?
31801 \end_layout
31802
31803 \begin_layout Itemize
31804 if you solved the problem, will the marketing department be happy?
31805 \end_layout
31806
31807 \begin_layout Itemize
31808 if the marketing department is happy, will customers be happy?
31809 \end_layout
31810
31811 \begin_layout Itemize
31812 if you're the project manager, marketing department and maybe even the customer
31813  in one person, have you tried to see the project from the outside?
31814 \end_layout
31815
31816 \begin_layout Itemize
31817 is the project done if you think it is done? Or is just that other interface/pro
31818 tocol/feature/configuration/option missing? How about website, manual(s),
31819  internationali(z|s)ation, packaging, labels, 2nd source for components,
31820  electromagnetic compatability/interference, documentation for production,
31821  production test software, update mechanism, patent issues?
31822 \end_layout
31823
31824 \begin_layout Itemize
31825 is your project adequately positioned in that magic triangle: fame, fortune,
31826  fun?
31827 \end_layout
31828
31829 \begin_layout Standard
31830 Maybe not all answers to these questions are known and some answers may
31831  even be 
31832 \emph on
31833 no
31834 \emph default
31835 , nevertheless knowing these questions may help you to avoid burnout
31836 \begin_inset Foot
31837 status open
31838
31839 \begin_layout Standard
31840 burnout is bad for electronic devices, programmers and motorcycle tyres
31841 \end_layout
31842
31843 \end_inset
31844
31845 .
31846  Chances are you didn't want to hear some of them...
31847 \end_layout
31848
31849 \begin_layout Chapter
31850 Support
31851 \begin_inset LatexCommand \index{Support}
31852
31853 \end_inset
31854
31855
31856 \end_layout
31857
31858 \begin_layout Standard
31859 SDCC has grown to be a large project.
31860  The compiler alone (without the preprocessor, assembler and linker) is
31861  well over 150,000 lines of code (blank stripped).
31862  The open source nature of this project is a key to its continued growth
31863  and support.
31864  You gain the benefit and support of many active software developers and
31865  end users.
31866  Is SDCC perfect? No, that's why we need your help.
31867  The developers take pride in fixing reported bugs.
31868  You can help by reporting the bugs and helping other SDCC users.
31869  There are lots of ways to contribute, and we encourage you to take part
31870  in making SDCC a great software package.
31871  
31872 \end_layout
31873
31874 \begin_layout Standard
31875 The SDCC project is hosted on the SDCC sourceforge site at 
31876 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
31877
31878 \end_inset
31879
31880 .
31881  You'll find the complete set of mailing lists
31882 \begin_inset LatexCommand \index{Mailing list(s)}
31883
31884 \end_inset
31885
31886 , forums, bug reporting system, patch submission
31887 \begin_inset LatexCommand \index{Patch submission}
31888
31889 \end_inset
31890
31891  system, download
31892 \begin_inset LatexCommand \index{download}
31893
31894 \end_inset
31895
31896  area and Subversion code repository
31897 \begin_inset LatexCommand \index{Subversion code repository}
31898
31899 \end_inset
31900
31901  there.
31902 \end_layout
31903
31904 \begin_layout Section
31905 Reporting Bugs
31906 \begin_inset LatexCommand \index{Bug reporting}
31907
31908 \end_inset
31909
31910
31911 \begin_inset LatexCommand \index{Reporting bugs}
31912
31913 \end_inset
31914
31915
31916 \end_layout
31917
31918 \begin_layout Standard
31919 The recommended way of reporting bugs is using the infrastructure of the
31920  sourceforge site.
31921  You can follow the status of bug reports there and have an overview about
31922  the known bugs.
31923 \end_layout
31924
31925 \begin_layout Standard
31926 Bug reports are automatically forwarded to the developer mailing list and
31927  will be fixed ASAP.
31928  When reporting a bug, it is very useful to include a small test program
31929  (the smaller the better) which reproduces the problem.
31930  If you can isolate the problem by looking at the generated assembly code,
31931  this can be very helpful.
31932  Compiling your program with the -
31933 \begin_inset ERT
31934 status collapsed
31935
31936 \begin_layout Standard
31937
31938
31939 \backslash
31940 /
31941 \end_layout
31942
31943 \end_inset
31944
31945 -dumpall
31946 \begin_inset LatexCommand \index{-\/-dumpall}
31947
31948 \end_inset
31949
31950  option can sometimes be useful in locating optimization problems.
31951  When reporting a bug please make sure you:
31952 \end_layout
31953
31954 \begin_layout Enumerate
31955 Attach the code you are compiling with SDCC.
31956  
31957 \end_layout
31958
31959 \begin_layout Enumerate
31960 Specify the exact command you use to run SDCC, or attach your Makefile.
31961  
31962 \end_layout
31963
31964 \begin_layout Enumerate
31965 Specify the SDCC version (type "
31966 \family sans
31967 \series bold
31968 sdcc -v
31969 \family default
31970 \series default
31971 "), your platform, and operating system.
31972  
31973 \end_layout
31974
31975 \begin_layout Enumerate
31976 Provide an exact copy of any error message or incorrect output.
31977  
31978 \end_layout
31979
31980 \begin_layout Enumerate
31981 Put something meaningful in the subject of your message.
31982 \end_layout
31983
31984 \begin_layout Standard
31985 Please attempt to include these 5 important parts, as applicable, in all
31986  requests for support or when reporting any problems or bugs with SDCC.
31987  Though this will make your message lengthy, it will greatly improve your
31988  chance that SDCC users and developers will be able to help you.
31989  Some SDCC developers are frustrated by bug reports without code provided
31990  that they can use to reproduce and ultimately fix the problem, so please
31991  be sure to provide sample code if you are reporting a bug! 
31992 \end_layout
31993
31994 \begin_layout Standard
31995 Please have a short check that you are using a recent version of SDCC and
31996  the bug is not yet known.
31997  This is the link for reporting bugs: 
31998 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
31999
32000 \end_inset
32001
32002 .
32003  With SDCC on average having more than 200 downloads
32004 \begin_inset LatexCommand \index{download}
32005
32006 \end_inset
32007
32008  on sourceforge per day
32009 \begin_inset Foot
32010 status open
32011
32012 \begin_layout Standard
32013 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
32014  between 2002 and 2005.
32015  This does not include other methods of distribution.
32016 \end_layout
32017
32018 \end_inset
32019
32020  there must be some users.
32021  So it's not exactly easy to find a new bug.
32022  If you find one we need it: 
32023 \emph on
32024 reporting bugs is good
32025 \emph default
32026 .
32027 \end_layout
32028
32029 \begin_layout Section
32030 Requesting Features
32031 \begin_inset LatexCommand \label{sub:Requesting-Features}
32032
32033 \end_inset
32034
32035
32036 \begin_inset LatexCommand \index{Feature request}
32037
32038 \end_inset
32039
32040
32041 \begin_inset LatexCommand \index{Requesting features}
32042
32043 \end_inset
32044
32045
32046 \end_layout
32047
32048 \begin_layout Standard
32049 Like bug reports feature requests are forwarded to the developer mailing
32050  list.
32051  This is the link for requesting features: 
32052 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32053
32054 \end_inset
32055
32056 .
32057 \end_layout
32058
32059 \begin_layout Section
32060 Submitting patches
32061 \end_layout
32062
32063 \begin_layout Standard
32064 Like bug reports contributed patches are forwarded to the developer mailing
32065  list.
32066  This is the link for submitting patches
32067 \begin_inset LatexCommand \index{Patch submission}
32068
32069 \end_inset
32070
32071
32072 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
32073
32074 \end_inset
32075
32076 .
32077 \end_layout
32078
32079 \begin_layout Standard
32080 You need to specify some parameters to the 
32081 \family typewriter
32082 diff
32083 \family default
32084  command for the patches to be useful.
32085  If you modified more than one file a patch created f.e.
32086  with 
32087 \family sans
32088 \series bold
32089
32090 \begin_inset Quotes sld
32091 \end_inset
32092
32093 diff -Naur unmodified_directory modified_directory >my_changes.patch
32094 \begin_inset Quotes srd
32095 \end_inset
32096
32097
32098 \family default
32099 \series default
32100  will be fine, otherwise 
32101 \family sans
32102 \series bold
32103
32104 \begin_inset Quotes sld
32105 \end_inset
32106
32107 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
32108 \begin_inset Quotes srd
32109 \end_inset
32110
32111
32112 \series default
32113  
32114 \family default
32115 will do.
32116 \end_layout
32117
32118 \begin_layout Section
32119 Getting Help
32120 \end_layout
32121
32122 \begin_layout Standard
32123 These links should take you directly to the 
32124 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
32125
32126 \end_inset
32127
32128
32129 \begin_inset Foot
32130 status open
32131
32132 \begin_layout Standard
32133 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
32134  automated messages (mid 2003)
32135 \end_layout
32136
32137 \end_inset
32138
32139  and the 
32140 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
32141
32142 \end_inset
32143
32144 , lists
32145 \begin_inset LatexCommand \index{Mailing list(s)}
32146
32147 \end_inset
32148
32149  and forums are archived and searchable so if you are lucky someone already
32150  had a similar problem.
32151  While mails to the lists themselves are delivered promptly their web front
32152  end on sourceforge sometimes shows a severe time lag (up to several weeks),
32153  if you're seriously using SDCC please consider subscribing to the lists.
32154 \end_layout
32155
32156 \begin_layout Section
32157 ChangeLog
32158 \end_layout
32159
32160 \begin_layout Standard
32161 You can follow the status of the Subversion version
32162 \begin_inset LatexCommand \index{version}
32163
32164 \end_inset
32165
32166  of SDCC by watching the Changelog
32167 \begin_inset LatexCommand \index{Changelog}
32168
32169 \end_inset
32170
32171  in the Subversion repository
32172 \size footnotesize
32173  
32174 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
32175
32176 \end_inset
32177
32178 .
32179 \end_layout
32180
32181 \begin_layout Section
32182 Subversion Source Code Repository
32183 \end_layout
32184
32185 \begin_layout Standard
32186 The output of 
32187 \family sans
32188 \series bold
32189 sdcc --version
32190 \family default
32191 \series default
32192  or the filenames of the snapshot versions of SDCC include date and its
32193  Subversion
32194 \begin_inset LatexCommand \index{Subversion code repository}
32195
32196 \end_inset
32197
32198  number.
32199  Subversion allows to download the source of recent or previous versions
32200  
32201 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
32202
32203 \end_inset
32204
32205  (by number or by date).
32206  An on-line source code browser and detailled instructions are also available
32207  there.
32208  SDCC versions starting from 1999 up to now are available (currently the
32209  versions prior to the conversion from cvs
32210 \begin_inset LatexCommand \index{cvs|see{Subversion}}
32211
32212 \end_inset
32213
32214  to Subversion (April 2006) are either by accessible by Subversion or by
32215  cvs).
32216 \end_layout
32217
32218 \begin_layout Section
32219 Release policy
32220 \begin_inset LatexCommand \index{Release policy}
32221
32222 \end_inset
32223
32224
32225 \end_layout
32226
32227 \begin_layout Standard
32228 Historically there often were long delays between official releases and
32229  the sourceforge download area tends to get not updated at all.
32230  Excuses in the past might have referred to problems with live range analysis,
32231  but as this was fixed a while ago, the current problem is that another
32232  excuse has to be found.
32233  Kidding aside, we have to get better there! On the other hand there are
32234  daily snapshots available at 
32235 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
32236
32237 \end_inset
32238
32239 , and you can always build the very last version (hopefully with many bugs
32240  fixed, and features added) from the source code available at 
32241 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
32242
32243 \end_inset
32244
32245 .
32246  A release wiki
32247 \begin_inset LatexCommand \index{wiki}
32248
32249 \end_inset
32250
32251
32252 \begin_inset LatexCommand \index{Release wiki}
32253
32254 \end_inset
32255
32256  at 
32257 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
32258
32259 \end_inset
32260
32261  also holds some information about past and future releases.
32262 \end_layout
32263
32264 \begin_layout Section
32265 Examples
32266 \begin_inset LatexCommand \index{Examples}
32267
32268 \end_inset
32269
32270
32271 \end_layout
32272
32273 \begin_layout Standard
32274 You'll find some small examples in the directory 
32275 \emph on
32276 sdcc/device/examples/.
32277  
32278 \emph default
32279 More examples and libraries are available at
32280 \emph on
32281  The SDCC Open Knowledge Resource 
32282 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
32283
32284 \end_inset
32285
32286  
32287 \emph default
32288 web site or at 
32289 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
32290
32291 \end_inset
32292
32293 .
32294 \end_layout
32295
32296 \begin_layout Standard
32297 \begin_inset Note Note
32298 status collapsed
32299
32300 \begin_layout Standard
32301 I did insert a reference to Paul's web site here although it seems rather
32302  dedicated to a specific 8032 board (I think it's okay because it f.e.
32303  shows LCD/Harddisc interface and has a free 8051 monitor.
32304  Independent 8032 board vendors face hard competition of heavily subsidized
32305  development boards anyway).
32306 \end_layout
32307
32308 \begin_layout Standard
32309 Maybe we should include some links to real world applications.
32310  Preferably pointer to pointers (one for each architecture) so this stays
32311  manageable here?
32312 \end_layout
32313
32314 \end_inset
32315
32316
32317 \end_layout
32318
32319 \begin_layout Section
32320 Quality control
32321 \begin_inset LatexCommand \label{sec:Quality-control}
32322
32323 \end_inset
32324
32325
32326 \begin_inset LatexCommand \index{Quality control}
32327
32328 \end_inset
32329
32330
32331 \end_layout
32332
32333 \begin_layout Standard
32334 The compiler is passed through snaphot build compile and build checks.
32335  The so called 
32336 \shape italic
32337 regression tests
32338 \shape default
32339
32340 \begin_inset LatexCommand \index{Regression test}
32341
32342 \end_inset
32343
32344  check that SDCC itself compiles flawlessly on several host platforms (i386,
32345  Opteron, 64 bit Alpha, ppc64, Mac OS X on PPC, Solaris on Sparc) and checks
32346  the quality of the code generated by SDCC by running the code for several
32347  target platforms through simulators.
32348  The regression test suite comprises more than 100 files which expand to
32349  more than 500 test cases which include more than 4500 tests.
32350  The results of these tests are published daily on SDCC's snapshot page
32351  (click on the red or green symbols on the right side of 
32352 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
32353
32354 \end_inset
32355
32356 ).
32357 \end_layout
32358
32359 \begin_layout Standard
32360 There is a separate document 
32361 \shape italic
32362 test_suite.pdf 
32363 \begin_inset LatexCommand \index{Test suite}
32364
32365 \end_inset
32366
32367
32368 \shape default
32369  
32370 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32371
32372 \end_inset
32373
32374  about the regression test suite.
32375 \end_layout
32376
32377 \begin_layout Standard
32378 You'll find the test code in the directory 
32379 \shape italic
32380 sdcc/support/regression
32381 \shape default
32382 .
32383  You can run these tests manually by running 
32384 \family sans
32385 make
32386 \family default
32387  in this directory (or f.e.
32388  
32389 \family sans
32390 \series bold
32391
32392 \begin_inset Quotes sld
32393 \end_inset
32394
32395 make test-mcs51
32396 \begin_inset Quotes srd
32397 \end_inset
32398
32399
32400 \family default
32401 \series default
32402  if you don't want to run the complete tests).
32403  The test code might also be interesting if you want to look for examples
32404 \begin_inset LatexCommand \index{Examples}
32405
32406 \end_inset
32407
32408  checking corner cases of SDCC or if you plan to submit patches
32409 \begin_inset LatexCommand \index{Patch submission}
32410
32411 \end_inset
32412
32413 .
32414 \end_layout
32415
32416 \begin_layout Standard
32417 The PIC14 port uses a different set of regression tests 
32418 \begin_inset LatexCommand \index{Regression test (PIC14)}
32419
32420 \end_inset
32421
32422 , you'll find them in the directory 
32423 \shape italic
32424 sdcc/src/regression
32425 \shape default
32426 .
32427 \end_layout
32428
32429 \begin_layout Section
32430 Use of SDCC in Education
32431 \end_layout
32432
32433 \begin_layout Standard
32434 In short: 
32435 \emph on
32436 highly
32437 \emph default
32438  encouraged
32439 \begin_inset Foot
32440 status open
32441
32442 \begin_layout Standard
32443 the phrase "use in education" might evoke the association "
32444 \emph on
32445 only
32446 \emph default
32447  fit for use in education".
32448  This connotation is not intended but nevertheless risked as the licensing
32449  of SDCC makes it difficult to offer educational discounts
32450 \end_layout
32451
32452 \end_inset
32453
32454 .
32455  If your rationales are to:
32456 \end_layout
32457
32458 \begin_layout Enumerate
32459 give students a chance to understand the 
32460 \emph on
32461 complete
32462 \emph default
32463  steps of code generation
32464 \end_layout
32465
32466 \begin_layout Enumerate
32467 have a curriculum that can be extended for years.
32468  Then you could use an fpga board as target and your curriculum will seamlessly
32469  extend from logic synthesis (
32470 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32471
32472 \end_inset
32473
32474
32475 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32476
32477 \end_inset
32478
32479 ), over assembly programming, to C to FPGA compilers (
32480 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32481
32482 \end_inset
32483
32484 ) and to C.
32485 \end_layout
32486
32487 \begin_layout Enumerate
32488 be able to insert excursions about skills like using a revision control
32489  system, submitting/applying patches, using a type-setting (as opposed to
32490  word-processing) engine LyX/LaTeX, using 
32491 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32492
32493 \end_inset
32494
32495 , following some 
32496 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32497
32498 \end_inset
32499
32500 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32501  Source Software, CPU simulation, compiler regression tests
32502 \begin_inset LatexCommand \index{Regression test}
32503
32504 \end_inset
32505
32506 .
32507  
32508 \newline
32509 And if there should be a shortage of ideas then you can always point students
32510  to the ever-growing feature request list 
32511 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32512
32513 \end_inset
32514
32515 .
32516 \end_layout
32517
32518 \begin_layout Enumerate
32519 not tie students to a specific host platform and instead allow them to use
32520  a host platform of 
32521 \emph on
32522 their
32523 \emph default
32524  choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
32525  and eventually 
32526 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32527
32528 \end_inset
32529
32530 )
32531 \end_layout
32532
32533 \begin_layout Enumerate
32534 not encourage students to use illegal copies of educational software
32535 \end_layout
32536
32537 \begin_layout Enumerate
32538 be immune to licensing/availability/price changes of the chosen tool chain
32539 \end_layout
32540
32541 \begin_layout Enumerate
32542 be able to change to a new target platform without having to adopt a new
32543  tool chain
32544 \end_layout
32545
32546 \begin_layout Enumerate
32547 have complete control over and insight into the tool chain
32548 \end_layout
32549
32550 \begin_layout Enumerate
32551 make your students aware about the pros and cons of open source software
32552  development
32553 \end_layout
32554
32555 \begin_layout Enumerate
32556 give back to the public as you are probably at least partially publically
32557  funded
32558 \end_layout
32559
32560 \begin_layout Enumerate
32561 give students a chance to publically prove their skills and to possibly
32562  see a world wide impact
32563 \end_layout
32564
32565 \begin_layout Standard
32566 then SDCC is probably among the first choices.
32567  Well, probably SDCC might be the only choice.
32568 \newpage
32569
32570 \end_layout
32571
32572 \begin_layout Chapter
32573 SDCC Technical Data
32574 \end_layout
32575
32576 \begin_layout Section
32577 Optimizations
32578 \begin_inset LatexCommand \index{Optimizations}
32579
32580 \end_inset
32581
32582
32583 \end_layout
32584
32585 \begin_layout Standard
32586 SDCC performs a host of standard optimizations in addition to some MCU specific
32587  optimizations.
32588  
32589 \end_layout
32590
32591 \begin_layout Subsection
32592 Sub-expression Elimination
32593 \begin_inset LatexCommand \index{Subexpression elimination}
32594
32595 \end_inset
32596
32597
32598 \end_layout
32599
32600 \begin_layout Standard
32601 The compiler does local and 
32602 \emph on
32603 g
32604 \emph default
32605 lobal 
32606 \emph on
32607 c
32608 \emph default
32609 ommon 
32610 \emph on
32611 s
32612 \emph default
32613 ubexpression 
32614 \emph on
32615 e
32616 \emph default
32617 limination, e.g.: 
32618 \end_layout
32619
32620 \begin_layout Verse
32621
32622 \family typewriter
32623 i = x + y + 1; 
32624 \newline
32625 j = x + y;
32626 \end_layout
32627
32628 \begin_layout Standard
32629 will be translated to
32630 \end_layout
32631
32632 \begin_layout Verse
32633
32634 \family typewriter
32635 iTemp = x + y; 
32636 \newline
32637 i = iTemp + 1; 
32638 \newline
32639 j = iTemp;
32640 \end_layout
32641
32642 \begin_layout Standard
32643 Some subexpressions are not as obvious as the above example, e.g.:
32644 \end_layout
32645
32646 \begin_layout Verse
32647
32648 \family typewriter
32649 a->b[i].c = 10; 
32650 \newline
32651 a->b[i].d = 11;
32652 \end_layout
32653
32654 \begin_layout Standard
32655 In this case the address arithmetic a->b[i] will be computed only once;
32656  the equivalent code in C would be.
32657 \end_layout
32658
32659 \begin_layout Verse
32660
32661 \family typewriter
32662 iTemp = a->b[i]; 
32663 \newline
32664 iTemp.c = 10; 
32665 \newline
32666 iTemp.d = 11;
32667 \end_layout
32668
32669 \begin_layout Standard
32670 The compiler will try to keep these temporary variables in registers.
32671 \end_layout
32672
32673 \begin_layout Subsection
32674 Dead-Code Elimination
32675 \begin_inset LatexCommand \index{Dead-code elimination}
32676
32677 \end_inset
32678
32679
32680 \end_layout
32681
32682 \begin_layout Verse
32683
32684 \family typewriter
32685 int global;
32686 \newline
32687
32688 \newline
32689 void f () { 
32690 \newline
32691 \InsetSpace ~
32692 \InsetSpace ~
32693 int i; 
32694 \newline
32695 \InsetSpace ~
32696 \InsetSpace ~
32697 i = 1; \InsetSpace ~
32698 \InsetSpace ~
32699 \InsetSpace ~
32700 \InsetSpace ~
32701 \InsetSpace ~
32702 /* dead store */ 
32703 \newline
32704 \InsetSpace ~
32705 \InsetSpace ~
32706 global = 1;\InsetSpace ~
32707 /* dead
32708  store */ 
32709 \newline
32710 \InsetSpace ~
32711 \InsetSpace ~
32712 global = 2; 
32713 \newline
32714 \InsetSpace ~
32715 \InsetSpace ~
32716 return; 
32717 \newline
32718 \InsetSpace ~
32719 \InsetSpace ~
32720 global = 3;\InsetSpace ~
32721 /* unreachable */ 
32722 \newline
32723 }
32724 \end_layout
32725
32726 \begin_layout Standard
32727 will be changed to
32728 \end_layout
32729
32730 \begin_layout Verse
32731
32732 \family typewriter
32733 int global;
32734 \newline
32735
32736 \newline
32737 void f () {
32738 \newline
32739 \InsetSpace ~
32740 \InsetSpace ~
32741 global = 2; 
32742 \newline
32743 }
32744 \end_layout
32745
32746 \begin_layout Subsection
32747 Copy-Propagation
32748 \begin_inset LatexCommand \index{Copy propagation}
32749
32750 \end_inset
32751
32752
32753 \end_layout
32754
32755 \begin_layout Verse
32756
32757 \family typewriter
32758 int f() { 
32759 \newline
32760 \InsetSpace ~
32761 \InsetSpace ~
32762 int i, j; 
32763 \newline
32764 \InsetSpace ~
32765 \InsetSpace ~
32766 i = 10; 
32767 \newline
32768 \InsetSpace ~
32769 \InsetSpace ~
32770 j = i; 
32771 \newline
32772 \InsetSpace ~
32773 \InsetSpace ~
32774 return j; 
32775 \newline
32776 }
32777 \end_layout
32778
32779 \begin_layout Standard
32780 will be changed to 
32781 \end_layout
32782
32783 \begin_layout Verse
32784
32785 \family typewriter
32786 int f() { 
32787 \newline
32788 \InsetSpace ~
32789 \InsetSpace ~
32790 int i, j; 
32791 \newline
32792 \InsetSpace ~
32793 \InsetSpace ~
32794 i = 10; 
32795 \newline
32796 \InsetSpace ~
32797 \InsetSpace ~
32798 j = 10; 
32799 \newline
32800 \InsetSpace ~
32801 \InsetSpace ~
32802 return 10; 
32803 \newline
32804 }
32805 \end_layout
32806
32807 \begin_layout Standard
32808 Note: the dead stores created by this copy propagation will be eliminated
32809  by dead-code elimination.
32810 \end_layout
32811
32812 \begin_layout Subsection
32813 Loop Optimizations
32814 \begin_inset LatexCommand \index{Loop optimization}
32815
32816 \end_inset
32817
32818
32819 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
32820
32821 \end_inset
32822
32823
32824 \end_layout
32825
32826 \begin_layout Standard
32827 Two types of loop optimizations are done by SDCC 
32828 \emph on
32829 loop invariant
32830 \emph default
32831  lifting and
32832 \emph on
32833  strength reduction
32834 \emph default
32835  of loop induction variables.
32836  In addition to the strength reduction the optimizer marks the induction
32837  variables and the register allocator tries to keep the induction variables
32838  in registers for the duration of the loop.
32839  Because of this preference of the register allocator
32840 \begin_inset LatexCommand \index{Register allocation}
32841
32842 \end_inset
32843
32844 , loop induction optimization causes an increase in register pressure, which
32845  may cause unwanted spilling of other temporary variables into the stack
32846 \begin_inset LatexCommand \index{stack}
32847
32848 \end_inset
32849
32850  / data space.
32851  The compiler will generate a warning message when it is forced to allocate
32852  extra space either on the stack or data space.
32853  If this extra space allocation is undesirable then induction optimization
32854  can be eliminated either for the entire source file (with -
32855 \begin_inset ERT
32856 status collapsed
32857
32858 \begin_layout Standard
32859
32860
32861 \backslash
32862 /
32863 \end_layout
32864
32865 \end_inset
32866
32867 -noinduction option) or for a given function only using #pragma\InsetSpace ~
32868 noinduction
32869 \begin_inset LatexCommand \index{\#pragma noinduction}
32870
32871 \end_inset
32872
32873 .
32874 \newline
32875
32876 \newline
32877 Loop Invariant:
32878 \end_layout
32879
32880 \begin_layout Verse
32881
32882 \family typewriter
32883 for (i = 0 ; i < 100 ; i ++) 
32884 \newline
32885 \InsetSpace ~
32886 \InsetSpace ~
32887 \InsetSpace ~
32888 \InsetSpace ~
32889 f += k + l;
32890 \end_layout
32891
32892 \begin_layout Standard
32893 changed to
32894 \end_layout
32895
32896 \begin_layout Verse
32897
32898 \family typewriter
32899 itemp = k + l; 
32900 \newline
32901 for (i = 0; i < 100; i++) 
32902 \newline
32903 \InsetSpace ~
32904 \InsetSpace ~
32905 \InsetSpace ~
32906 \InsetSpace ~
32907 f += itemp;
32908 \end_layout
32909
32910 \begin_layout Standard
32911 As mentioned previously some loop invariants are not as apparent, all static
32912  address computations are also moved out of the loop.
32913 \newline
32914
32915 \newline
32916 Strength Reduction
32917 \begin_inset LatexCommand \index{Strength reduction}
32918
32919 \end_inset
32920
32921 , this optimization substitutes an expression by a cheaper expression:
32922 \end_layout
32923
32924 \begin_layout Verse
32925
32926 \family typewriter
32927 for (i=0;i < 100; i++)
32928 \newline
32929 \InsetSpace ~
32930 \InsetSpace ~
32931 \InsetSpace ~
32932 \InsetSpace ~
32933 ar[i*5] = i*3;
32934 \end_layout
32935
32936 \begin_layout Standard
32937 changed to
32938 \end_layout
32939
32940 \begin_layout Verse
32941
32942 \family typewriter
32943 itemp1 = 0; 
32944 \newline
32945 itemp2 = 0; 
32946 \newline
32947 for (i=0;i< 100;i++) { 
32948 \newline
32949 \InsetSpace ~
32950 \InsetSpace ~
32951 \InsetSpace ~
32952 \InsetSpace ~
32953 ar[itemp1] = itemp2; 
32954 \newline
32955 \InsetSpace ~
32956 \InsetSpace ~
32957 \InsetSpace ~
32958 \InsetSpace ~
32959 itemp1
32960  += 5; 
32961 \newline
32962 \InsetSpace ~
32963 \InsetSpace ~
32964 \InsetSpace ~
32965 \InsetSpace ~
32966 itemp2 += 3; 
32967 \newline
32968 }
32969 \end_layout
32970
32971 \begin_layout Standard
32972 The more expensive multiplication
32973 \begin_inset LatexCommand \index{Multiplication}
32974
32975 \end_inset
32976
32977  is changed to a less expensive addition.
32978 \end_layout
32979
32980 \begin_layout Subsection
32981 Loop Reversing
32982 \begin_inset LatexCommand \index{Loop reversing}
32983
32984 \end_inset
32985
32986
32987 \end_layout
32988
32989 \begin_layout Standard
32990 This optimization is done to reduce the overhead of checking loop boundaries
32991  for every iteration.
32992  Some simple loops can be reversed and implemented using a 
32993 \begin_inset Quotes eld
32994 \end_inset
32995
32996 decrement and jump if not zero
32997 \begin_inset Quotes erd
32998 \end_inset
32999
33000  instruction.
33001  SDCC checks for the following criterion to determine if a loop is reversible
33002  (note: more sophisticated compilers use data-dependency analysis to make
33003  this determination, SDCC uses a more simple minded analysis).
33004 \end_layout
33005
33006 \begin_layout Itemize
33007 The 'for' loop is of the form 
33008 \newline
33009
33010 \newline
33011
33012 \family typewriter
33013 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
33014  += 1])
33015 \newline
33016 \InsetSpace ~
33017 \InsetSpace ~
33018 \InsetSpace ~
33019 \InsetSpace ~
33020 <for body>
33021 \end_layout
33022
33023 \begin_layout Itemize
33024 The <for body> does not contain 
33025 \begin_inset Quotes eld
33026 \end_inset
33027
33028 continue
33029 \begin_inset Quotes erd
33030 \end_inset
33031
33032  or 'break
33033 \begin_inset Quotes erd
33034 \end_inset
33035
33036 .
33037 \end_layout
33038
33039 \begin_layout Itemize
33040 All goto's are contained within the loop.
33041 \end_layout
33042
33043 \begin_layout Itemize
33044 No function calls within the loop.
33045 \end_layout
33046
33047 \begin_layout Itemize
33048 The loop control variable <sym> is not assigned any value within the loop
33049 \end_layout
33050
33051 \begin_layout Itemize
33052 The loop control variable does NOT participate in any arithmetic operation
33053  within the loop.
33054 \end_layout
33055
33056 \begin_layout Itemize
33057 There are NO switch statements in the loop.
33058 \end_layout
33059
33060 \begin_layout Subsection
33061 Algebraic Simplifications
33062 \end_layout
33063
33064 \begin_layout Standard
33065 SDCC does numerous algebraic simplifications, the following is a small sub-set
33066  of these optimizations.
33067 \end_layout
33068
33069 \begin_layout Verse
33070
33071 \family typewriter
33072 i = j + 0;\InsetSpace ~
33073 \InsetSpace ~
33074 \InsetSpace ~
33075 \InsetSpace ~
33076  /* changed to: */\InsetSpace ~
33077 \InsetSpace ~
33078 \InsetSpace ~
33079 \InsetSpace ~
33080  i = j; 
33081 \newline
33082 i /= 2;\InsetSpace ~
33083 \InsetSpace ~
33084 \InsetSpace ~
33085 \InsetSpace ~
33086 \InsetSpace ~
33087 \InsetSpace ~
33088 \InsetSpace ~
33089  /* changed to: */\InsetSpace ~
33090 \InsetSpace ~
33091 \InsetSpace ~
33092 \InsetSpace ~
33093  i >>= 1; 
33094 \newline
33095 i
33096  = j - j;\InsetSpace ~
33097 \InsetSpace ~
33098 \InsetSpace ~
33099 \InsetSpace ~
33100  /* changed to: */\InsetSpace ~
33101 \InsetSpace ~
33102 \InsetSpace ~
33103 \InsetSpace ~
33104  i = 0; 
33105 \newline
33106 i = j / 1;\InsetSpace ~
33107 \InsetSpace ~
33108 \InsetSpace ~
33109 \InsetSpace ~
33110  /* changed to: */\InsetSpace ~
33111 \InsetSpace ~
33112 \InsetSpace ~
33113 \InsetSpace ~
33114  i = j;
33115 \end_layout
33116
33117 \begin_layout Standard
33118 Note the subexpressions
33119 \begin_inset LatexCommand \index{Subexpression}
33120
33121 \end_inset
33122
33123  given above are generally introduced by macro expansions or as a result
33124  of copy/constant propagation.
33125 \end_layout
33126
33127 \begin_layout Subsection
33128 'switch' Statements
33129 \begin_inset LatexCommand \label{sub:'switch'-Statements}
33130
33131 \end_inset
33132
33133
33134 \begin_inset LatexCommand \index{switch statement}
33135
33136 \end_inset
33137
33138
33139 \end_layout
33140
33141 \begin_layout Standard
33142 SDCC can optimize switch statements to jump tables
33143 \begin_inset LatexCommand \index{jump tables}
33144
33145 \end_inset
33146
33147 .
33148  It makes the decision based on an estimate of the generated code size.
33149  SDCC is quite liberal in the requirements for jump table generation: 
33150 \end_layout
33151
33152 \begin_layout Itemize
33153 The labels need not be in order, and the starting number need not be one
33154  or zero, the case labels are in numerical sequence or not too many case
33155  labels are missing.
33156 \end_layout
33157
33158 \begin_deeper
33159 \begin_layout Verse
33160
33161 \family typewriter
33162 switch(i) {\InsetSpace ~
33163 \InsetSpace ~
33164 \InsetSpace ~
33165 \InsetSpace ~
33166 \InsetSpace ~
33167 \InsetSpace ~
33168 \InsetSpace ~
33169 \InsetSpace ~
33170 \InsetSpace ~
33171 \InsetSpace ~
33172 \InsetSpace ~
33173 \InsetSpace ~
33174 \InsetSpace ~
33175 \InsetSpace ~
33176 \InsetSpace ~
33177 \InsetSpace ~
33178 \InsetSpace ~
33179 \InsetSpace ~
33180 \InsetSpace ~
33181 \InsetSpace ~
33182 \InsetSpace ~
33183 \InsetSpace ~
33184 \InsetSpace ~
33185 \InsetSpace ~
33186 \InsetSpace ~
33187 \InsetSpace ~
33188 switch (i) { 
33189 \newline
33190 \InsetSpace ~
33191 \InsetSpace ~
33192 \InsetSpace ~
33193 case 4: ...\InsetSpace ~
33194 \InsetSpace ~
33195 \InsetSpace ~
33196 \InsetSpace ~
33197 \InsetSpace ~
33198 \InsetSpace ~
33199 \InsetSpace ~
33200 \InsetSpace ~
33201 \InsetSpace ~
33202 \InsetSpace ~
33203 \InsetSpace ~
33204 \InsetSpace ~
33205 \InsetSpace ~
33206 \InsetSpace ~
33207 \InsetSpace ~
33208 \InsetSpace ~
33209 \InsetSpace ~
33210 \InsetSpace ~
33211 \InsetSpace ~
33212 \InsetSpace ~
33213 \InsetSpace ~
33214 \InsetSpace ~
33215 \InsetSpace ~
33216 \InsetSpace ~
33217 \InsetSpace ~
33218 \InsetSpace ~
33219 case 0: ...
33220  
33221 \newline
33222 \InsetSpace ~
33223 \InsetSpace ~
33224 \InsetSpace ~
33225 case 5: ...\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 \InsetSpace ~
33251 case 1: ...
33252  
33253 \newline
33254 \InsetSpace ~
33255 \InsetSpace ~
33256 \InsetSpace ~
33257 case 3: ...\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 \InsetSpace ~
33282 \InsetSpace ~
33283
33284 \newline
33285 \InsetSpace ~
33286 \InsetSpace ~
33287 \InsetSpace ~
33288 case 6: ...\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 \InsetSpace ~
33314 case 3: ...
33315  
33316 \newline
33317 \InsetSpace ~
33318 \InsetSpace ~
33319 \InsetSpace ~
33320 case 7: ...\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 \InsetSpace ~
33346 case 4: ...
33347  
33348 \newline
33349 \InsetSpace ~
33350 \InsetSpace ~
33351 \InsetSpace ~
33352 case 8: ...\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 \InsetSpace ~
33377 \InsetSpace ~
33378 case 5: ...
33379  
33380 \newline
33381 \InsetSpace ~
33382 \InsetSpace ~
33383 \InsetSpace ~
33384 case 9: ...\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 \InsetSpace ~
33409 \InsetSpace ~
33410 case 6: ...
33411  
33412 \newline
33413 \InsetSpace ~
33414 \InsetSpace ~
33415 \InsetSpace ~
33416 case 10: ...\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 \InsetSpace ~
33441 case 7: ...
33442  
33443 \newline
33444 \InsetSpace ~
33445 \InsetSpace ~
33446 \InsetSpace ~
33447 case 11: ...\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 8: ...
33473  
33474 \newline
33475 }\InsetSpace ~
33476 \InsetSpace ~
33477 \InsetSpace ~
33478 \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 \InsetSpace ~
33504 \InsetSpace ~
33505 \InsetSpace ~
33506 \InsetSpace ~
33507 \InsetSpace ~
33508 \InsetSpace ~
33509 \InsetSpace ~
33510 \InsetSpace ~
33511 }
33512 \end_layout
33513
33514 \begin_layout Standard
33515 Both the above switch statements will be implemented using a jump-table.
33516  The example to the right side is slightly more efficient as the check for
33517  the lower boundary of the jump-table is not needed.
33518 \end_layout
33519
33520 \end_deeper
33521 \begin_layout Itemize
33522 The number of case labels is not larger than supported by the target architectur
33523 e.
33524 \end_layout
33525
33526 \begin_layout Itemize
33527 If the case labels are not in numerical sequence ('gaps' between cases)
33528  SDCC checks whether a jump table with additionally inserted dummy cases
33529  is still attractive.
33530  
33531 \end_layout
33532
33533 \begin_layout Itemize
33534 If the starting number is not zero and a check for the lower boundary of
33535  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33536  ...
33537  .
33538 \end_layout
33539
33540 \begin_layout Standard
33541 Switch statements which have large gaps in the numeric sequence or those
33542  that have too many case labels can be split into more than one switch statement
33543  for efficient code generation, e.g.:
33544 \end_layout
33545
33546 \begin_layout Verse
33547
33548 \family typewriter
33549 switch (i) { 
33550 \newline
33551 \InsetSpace ~
33552 \InsetSpace ~
33553 case 1: ...
33554  
33555 \newline
33556 \InsetSpace ~
33557 \InsetSpace ~
33558 case 2: ...
33559  
33560 \newline
33561 \InsetSpace ~
33562 \InsetSpace ~
33563 case 3: ...
33564  
33565 \newline
33566 \InsetSpace ~
33567 \InsetSpace ~
33568 case 4: ...
33569  
33570 \newline
33571 \InsetSpace ~
33572 \InsetSpace ~
33573 case 5: ...
33574  
33575 \newline
33576 \InsetSpace ~
33577 \InsetSpace ~
33578 case 6: ...
33579  
33580 \newline
33581 \InsetSpace ~
33582 \InsetSpace ~
33583 case 7: ...
33584  
33585 \newline
33586 \InsetSpace ~
33587 \InsetSpace ~
33588 case 101: ...
33589  
33590 \newline
33591 \InsetSpace ~
33592 \InsetSpace ~
33593 case 102: ...
33594  
33595 \newline
33596 \InsetSpace ~
33597 \InsetSpace ~
33598 case 103: ...
33599  
33600 \newline
33601 \InsetSpace ~
33602 \InsetSpace ~
33603 case 104: ...
33604  
33605 \newline
33606 \InsetSpace ~
33607 \InsetSpace ~
33608 case 105: ...
33609  
33610 \newline
33611 \InsetSpace ~
33612 \InsetSpace ~
33613 case 106: ...
33614  
33615 \newline
33616 \InsetSpace ~
33617 \InsetSpace ~
33618 case 107: ...
33619  
33620 \newline
33621 }
33622 \end_layout
33623
33624 \begin_layout Standard
33625 If the above switch statement is broken down into two switch statements
33626 \end_layout
33627
33628 \begin_layout Verse
33629
33630 \family typewriter
33631 switch (i) { 
33632 \newline
33633 \InsetSpace ~
33634 \InsetSpace ~
33635 case 1: ...
33636  
33637 \newline
33638 \InsetSpace ~
33639 \InsetSpace ~
33640 case 2: ...
33641  
33642 \newline
33643 \InsetSpace ~
33644 \InsetSpace ~
33645 case 3: ...
33646  
33647 \newline
33648 \InsetSpace ~
33649 \InsetSpace ~
33650 case 4: ...
33651  
33652 \newline
33653 \InsetSpace ~
33654 \InsetSpace ~
33655 case 5: ...
33656  
33657 \newline
33658 \InsetSpace ~
33659 \InsetSpace ~
33660 case 6: ...
33661  
33662 \newline
33663 \InsetSpace ~
33664 \InsetSpace ~
33665 case 7: ...
33666  
33667 \newline
33668 }
33669 \end_layout
33670
33671 \begin_layout Standard
33672 and
33673 \end_layout
33674
33675 \begin_layout Verse
33676
33677 \family typewriter
33678 switch (i) { 
33679 \newline
33680 \InsetSpace ~
33681 \InsetSpace ~
33682 case 101: ...
33683  
33684 \newline
33685 \InsetSpace ~
33686 \InsetSpace ~
33687 case 102: ...
33688  
33689 \newline
33690 \InsetSpace ~
33691 \InsetSpace ~
33692 case 103: ...
33693  
33694 \newline
33695 \InsetSpace ~
33696 \InsetSpace ~
33697 case 104: ...
33698  
33699 \newline
33700 \InsetSpace ~
33701 \InsetSpace ~
33702 case 105: ...
33703  
33704 \newline
33705 \InsetSpace ~
33706 \InsetSpace ~
33707 case 106: ...
33708  
33709 \newline
33710 \InsetSpace ~
33711 \InsetSpace ~
33712 case 107: ...
33713  
33714 \newline
33715 }
33716 \end_layout
33717
33718 \begin_layout Standard
33719 then both the switch statements will be implemented using jump-tables whereas
33720  the unmodified switch statement will not be.
33721 \end_layout
33722
33723 \begin_layout Standard
33724 \begin_inset Note Note
33725 status collapsed
33726
33727 \begin_layout Standard
33728 There might be reasons which SDCC cannot know about to either favour or
33729  not favour jump tables.
33730  If the target system has to be as quick for the last switch case as for
33731  the first (pro jump table), or if the switch argument is known to be zero
33732  in the majority of the cases (contra jump table).
33733 \end_layout
33734
33735 \end_inset
33736
33737
33738 \end_layout
33739
33740 \begin_layout Standard
33741 The pragma nojtbound
33742 \begin_inset LatexCommand \index{\#pragma nojtbound}
33743
33744 \end_inset
33745
33746  can be used to turn off checking the 
33747 \emph on
33748 j
33749 \emph default
33750 ump 
33751 \emph on
33752 t
33753 \emph default
33754 able 
33755 \emph on
33756 bound
33757 \emph default
33758 aries.
33759  It has no effect if a default label is supplied.
33760  Use of this pragma is dangerous: if the switch
33761 \begin_inset LatexCommand \index{switch statement}
33762
33763 \end_inset
33764
33765  argument is not matched by a case statement the processor will happily
33766  jump into Nirvana.
33767 \end_layout
33768
33769 \begin_layout Subsection
33770 Bit-shifting Operations
33771 \begin_inset LatexCommand \index{Bit shifting}
33772
33773 \end_inset
33774
33775 .
33776 \end_layout
33777
33778 \begin_layout Standard
33779 Bit shifting is one of the most frequently used operation in embedded programmin
33780 g.
33781  SDCC tries to implement bit-shift operations in the most efficient way
33782  possible, e.g.:
33783 \end_layout
33784
33785 \begin_layout Verse
33786
33787 \family typewriter
33788 unsigned char i;
33789 \newline
33790 ...
33791  
33792 \newline
33793 i >>= 4; 
33794 \newline
33795 ...
33796 \end_layout
33797
33798 \begin_layout Standard
33799 generates the following code:
33800 \end_layout
33801
33802 \begin_layout Verse
33803
33804 \family typewriter
33805 mov\InsetSpace ~
33806  a,_i 
33807 \newline
33808 swap a 
33809 \newline
33810 anl\InsetSpace ~
33811  a,#0x0f 
33812 \newline
33813 mov\InsetSpace ~
33814  _i,a
33815 \end_layout
33816
33817 \begin_layout Standard
33818 In general SDCC will never setup a loop if the shift count is known.
33819  Another example:
33820 \end_layout
33821
33822 \begin_layout Verse
33823
33824 \family typewriter
33825 unsigned int i; 
33826 \newline
33827 ...
33828  
33829 \newline
33830 i >>= 9; 
33831 \newline
33832 ...
33833 \end_layout
33834
33835 \begin_layout Standard
33836 will generate:
33837 \end_layout
33838
33839 \begin_layout Verse
33840
33841 \family typewriter
33842 mov\InsetSpace ~
33843 \InsetSpace ~
33844 a,(_i + 1) 
33845 \newline
33846 mov\InsetSpace ~
33847 \InsetSpace ~
33848 (_i + 1),#0x00 
33849 \newline
33850 clr\InsetSpace ~
33851 \InsetSpace ~
33852
33853 \newline
33854 rrc\InsetSpace ~
33855 \InsetSpace ~
33856
33857 \newline
33858 mov\InsetSpace ~
33859 \InsetSpace ~
33860 _i,a
33861 \end_layout
33862
33863 \begin_layout Subsection
33864 Bit-rotation
33865 \begin_inset LatexCommand \index{Bit rotation}
33866
33867 \end_inset
33868
33869
33870 \end_layout
33871
33872 \begin_layout Standard
33873 A special case of the bit-shift operation is bit rotation
33874 \begin_inset LatexCommand \index{rotating bits}
33875
33876 \end_inset
33877
33878 , SDCC recognizes the following expression to be a left bit-rotation:
33879 \end_layout
33880
33881 \begin_layout Verse
33882
33883 \family typewriter
33884 \series bold
33885 unsigned
33886 \series default
33887 \InsetSpace ~
33888 \InsetSpace ~
33889 char i;\InsetSpace ~
33890 \InsetSpace ~
33891 \InsetSpace ~
33892 \InsetSpace ~
33893 \InsetSpace ~
33894 \InsetSpace ~
33895 \InsetSpace ~
33896 \InsetSpace ~
33897 \InsetSpace ~
33898 \InsetSpace ~
33899 \InsetSpace ~
33900 /* unsigned is needed for rotation */ 
33901 \newline
33902 ...
33903  
33904 \newline
33905 i = ((i << 1) | (i >> 7)); 
33906 \family default
33907
33908 \newline
33909
33910 \family typewriter
33911 ...
33912 \end_layout
33913
33914 \begin_layout Standard
33915 will generate the following code:
33916 \end_layout
33917
33918 \begin_layout Verse
33919
33920 \family typewriter
33921 mov\InsetSpace ~
33922 \InsetSpace ~
33923 a,_i 
33924 \newline
33925 rl\InsetSpace ~
33926 \InsetSpace ~
33927 \InsetSpace ~
33928
33929 \newline
33930 mov\InsetSpace ~
33931 \InsetSpace ~
33932 _i,a
33933 \end_layout
33934
33935 \begin_layout Standard
33936 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
33937 ns of this case will also be recognized as bit-rotation, i.e.: 
33938 \end_layout
33939
33940 \begin_layout Verse
33941
33942 \family typewriter
33943 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
33944 \end_layout
33945
33946 \begin_layout Subsection
33947 Nibble and Byte Swapping
33948 \end_layout
33949
33950 \begin_layout Standard
33951 Other special cases of the bit-shift operations are nibble or byte swapping
33952 \begin_inset LatexCommand \index{swapping nibbles/bytes}
33953
33954 \end_inset
33955
33956 , SDCC recognizes the following expressions:
33957 \end_layout
33958
33959 \begin_layout Verse
33960
33961 \family typewriter
33962 \series bold
33963 unsigned
33964 \series default
33965 \InsetSpace ~
33966 \InsetSpace ~
33967 char i; 
33968 \newline
33969
33970 \series bold
33971 unsigned
33972 \series default
33973 \InsetSpace ~
33974 \InsetSpace ~
33975 int j; 
33976 \newline
33977 ...
33978  
33979 \newline
33980 i = ((i << 4) | (i >> 4)); 
33981 \family default
33982
33983 \newline
33984
33985 \family typewriter
33986 j = ((j << 8) | (j >> 8)); 
33987 \end_layout
33988
33989 \begin_layout Standard
33990 and generates a swap instruction for the nibble swapping
33991 \begin_inset LatexCommand \index{Nibble swapping}
33992
33993 \end_inset
33994
33995  or move instructions for the byte swapping
33996 \begin_inset LatexCommand \index{Byte swapping}
33997
33998 \end_inset
33999
34000 .
34001  The 
34002 \begin_inset Quotes sld
34003 \end_inset
34004
34005 j
34006 \begin_inset Quotes srd
34007 \end_inset
34008
34009  example can be used to convert from little to big-endian or vice versa.
34010  If you want to change the endianness of a 
34011 \emph on
34012 signed
34013 \emph default
34014  integer you have to cast to 
34015 \family typewriter
34016 (unsigned int)
34017 \family default
34018  first.
34019 \end_layout
34020
34021 \begin_layout Standard
34022 Note that SDCC stores numbers in little-endian
34023 \begin_inset Foot
34024 status open
34025
34026 \begin_layout Standard
34027 Usually 8-bit processors don't care much about endianness.
34028  This is not the case for the standard 8051 which only has an instruction
34029  to increment its 
34030 \emph on
34031 dptr
34032 \emph default
34033
34034 \begin_inset LatexCommand \index{DPTR}
34035
34036 \end_inset
34037
34038 -datapointer
34039 \emph on
34040  
34041 \emph default
34042 so little-endian is the more efficient byte order.
34043 \end_layout
34044
34045 \end_inset
34046
34047
34048 \begin_inset LatexCommand \index{little-endian}
34049
34050 \end_inset
34051
34052
34053 \begin_inset LatexCommand \index{Endianness}
34054
34055 \end_inset
34056
34057  format (i.e.
34058  lowest order first).
34059 \end_layout
34060
34061 \begin_layout Subsection
34062 Highest Order Bit
34063 \begin_inset LatexCommand \index{Highest Order Bit}
34064
34065 \end_inset
34066
34067  / Any Order Bit
34068 \begin_inset LatexCommand \index{Any Order Bit}
34069
34070 \end_inset
34071
34072
34073 \end_layout
34074
34075 \begin_layout Standard
34076 It is frequently required to obtain the highest order bit of an integral
34077  type (long, int, short or char types).
34078  Also obtaining any other order bit is not uncommon.
34079  SDCC recognizes the following expressions to yield the highest order bit
34080  and generates optimized code for it, e.g.:
34081 \end_layout
34082
34083 \begin_layout Verse
34084
34085 \family typewriter
34086 unsigned int gint; 
34087 \newline
34088
34089 \newline
34090 foo () { 
34091 \newline
34092 \InsetSpace ~
34093 \InsetSpace ~
34094 unsigned char hob1, aob1; 
34095 \newline
34096 \InsetSpace ~
34097 \InsetSpace ~
34098 bit hob2, hob3, aob2,
34099  aob3; 
34100 \newline
34101 \InsetSpace ~
34102 \InsetSpace ~
34103 ...
34104  
34105 \newline
34106 \InsetSpace ~
34107 \InsetSpace ~
34108 hob1 = (gint >> 15) & 1; 
34109 \newline
34110 \InsetSpace ~
34111 \InsetSpace ~
34112 hob2 = (gint >> 15) & 1; 
34113 \newline
34114 \InsetSpace ~
34115 \InsetSpace ~
34116 hob3 = gint & 0x8000;
34117  
34118 \newline
34119 \InsetSpace ~
34120 \InsetSpace ~
34121 aob1 = (gint >> 9) & 1; 
34122 \newline
34123 \InsetSpace ~
34124 \InsetSpace ~
34125 aob2 = (gint >> 8) & 1; 
34126 \newline
34127 \InsetSpace ~
34128 \InsetSpace ~
34129 aob3 = gint & 0x0800; 
34130 \newline
34131 \InsetSpace ~
34132 \InsetSpace ~
34133 ..
34134  
34135 \newline
34136 }
34137 \end_layout
34138
34139 \begin_layout Standard
34140 will generate the following code:
34141 \end_layout
34142
34143 \begin_layout Verse
34144
34145 \family typewriter
34146 \InsetSpace ~
34147 \InsetSpace ~
34148 \InsetSpace ~
34149 \InsetSpace ~
34150 \InsetSpace ~
34151 \InsetSpace ~
34152 \InsetSpace ~
34153 \InsetSpace ~
34154 \InsetSpace ~
34155 \InsetSpace ~
34156 \InsetSpace ~
34157 \InsetSpace ~
34158 \InsetSpace ~
34159 \InsetSpace ~
34160 \InsetSpace ~
34161 \InsetSpace ~
34162 \InsetSpace ~
34163 \InsetSpace ~
34164 \InsetSpace ~
34165 \InsetSpace ~
34166 \InsetSpace ~
34167 \InsetSpace ~
34168 \InsetSpace ~
34169 \InsetSpace ~
34170 \InsetSpace ~
34171  61 ;\InsetSpace ~
34172  hob.c 7 
34173 \newline
34174 000A E5*01\InsetSpace ~
34175 \InsetSpace ~
34176 \InsetSpace ~
34177 \InsetSpace ~
34178 \InsetSpace ~
34179 \InsetSpace ~
34180 \InsetSpace ~
34181 \InsetSpace ~
34182 \InsetSpace ~
34183 \InsetSpace ~
34184 \InsetSpace ~
34185 \InsetSpace ~
34186 \InsetSpace ~
34187 \InsetSpace ~
34188 \InsetSpace ~
34189  62\InsetSpace ~
34190 \InsetSpace ~
34191 \InsetSpace ~
34192 \InsetSpace ~
34193 \InsetSpace ~
34194 \InsetSpace ~
34195 \InsetSpace ~
34196 \InsetSpace ~
34197  mov\InsetSpace ~
34198 \InsetSpace ~
34199  a,(_gint + 1) 
34200 \newline
34201 000C 23\InsetSpace ~
34202 \InsetSpace ~
34203 \InsetSpace ~
34204 \InsetSpace ~
34205 \InsetSpace ~
34206 \InsetSpace ~
34207 \InsetSpace ~
34208 \InsetSpace ~
34209 \InsetSpace ~
34210 \InsetSpace ~
34211 \InsetSpace ~
34212 \InsetSpace ~
34213 \InsetSpace ~
34214 \InsetSpace ~
34215 \InsetSpace ~
34216 \InsetSpace ~
34217 \InsetSpace ~
34218 \InsetSpace ~
34219  63\InsetSpace ~
34220 \InsetSpace ~
34221 \InsetSpace ~
34222 \InsetSpace ~
34223 \InsetSpace ~
34224 \InsetSpace ~
34225 \InsetSpace ~
34226 \InsetSpace ~
34227  rl\InsetSpace ~
34228 \InsetSpace ~
34229 \InsetSpace ~
34230  a 
34231 \newline
34232 000D 54 01\InsetSpace ~
34233 \InsetSpace ~
34234 \InsetSpace ~
34235 \InsetSpace ~
34236 \InsetSpace ~
34237 \InsetSpace ~
34238 \InsetSpace ~
34239 \InsetSpace ~
34240 \InsetSpace ~
34241 \InsetSpace ~
34242 \InsetSpace ~
34243 \InsetSpace ~
34244 \InsetSpace ~
34245 \InsetSpace ~
34246 \InsetSpace ~
34247
34248  64\InsetSpace ~
34249 \InsetSpace ~
34250 \InsetSpace ~
34251 \InsetSpace ~
34252 \InsetSpace ~
34253 \InsetSpace ~
34254 \InsetSpace ~
34255 \InsetSpace ~
34256  anl\InsetSpace ~
34257 \InsetSpace ~
34258  a,#0x01 
34259 \newline
34260 000F F5*02\InsetSpace ~
34261 \InsetSpace ~
34262 \InsetSpace ~
34263 \InsetSpace ~
34264 \InsetSpace ~
34265 \InsetSpace ~
34266 \InsetSpace ~
34267 \InsetSpace ~
34268 \InsetSpace ~
34269 \InsetSpace ~
34270 \InsetSpace ~
34271 \InsetSpace ~
34272 \InsetSpace ~
34273 \InsetSpace ~
34274 \InsetSpace ~
34275  65\InsetSpace ~
34276 \InsetSpace ~
34277 \InsetSpace ~
34278 \InsetSpace ~
34279 \InsetSpace ~
34280 \InsetSpace ~
34281 \InsetSpace ~
34282 \InsetSpace ~
34283  mov\InsetSpace ~
34284 \InsetSpace ~
34285  _foo_hob1_1_1,a 
34286 \newline
34287 \InsetSpace ~
34288 \InsetSpace ~
34289 \InsetSpace ~
34290 \InsetSpace ~
34291 \InsetSpace ~
34292 \InsetSpace ~
34293 \InsetSpace ~
34294 \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 \InsetSpace ~
34310 \InsetSpace ~
34311 \InsetSpace ~
34312  66 ;\InsetSpace ~
34313  hob.c 8 
34314 \newline
34315 0011 E5*01\InsetSpace ~
34316 \InsetSpace ~
34317 \InsetSpace ~
34318 \InsetSpace ~
34319 \InsetSpace ~
34320 \InsetSpace ~
34321 \InsetSpace ~
34322 \InsetSpace ~
34323 \InsetSpace ~
34324 \InsetSpace ~
34325 \InsetSpace ~
34326 \InsetSpace ~
34327 \InsetSpace ~
34328 \InsetSpace ~
34329 \InsetSpace ~
34330
34331  67\InsetSpace ~
34332 \InsetSpace ~
34333 \InsetSpace ~
34334 \InsetSpace ~
34335 \InsetSpace ~
34336 \InsetSpace ~
34337 \InsetSpace ~
34338 \InsetSpace ~
34339  mov\InsetSpace ~
34340 \InsetSpace ~
34341  a,(_gint + 1) 
34342 \newline
34343 0013 33\InsetSpace ~
34344 \InsetSpace ~
34345 \InsetSpace ~
34346 \InsetSpace ~
34347 \InsetSpace ~
34348 \InsetSpace ~
34349 \InsetSpace ~
34350 \InsetSpace ~
34351 \InsetSpace ~
34352 \InsetSpace ~
34353 \InsetSpace ~
34354 \InsetSpace ~
34355 \InsetSpace ~
34356 \InsetSpace ~
34357 \InsetSpace ~
34358 \InsetSpace ~
34359 \InsetSpace ~
34360 \InsetSpace ~
34361  68\InsetSpace ~
34362 \InsetSpace ~
34363 \InsetSpace ~
34364 \InsetSpace ~
34365 \InsetSpace ~
34366 \InsetSpace ~
34367 \InsetSpace ~
34368 \InsetSpace ~
34369  rlc\InsetSpace ~
34370 \InsetSpace ~
34371  a 
34372 \newline
34373 0014 92*00\InsetSpace ~
34374 \InsetSpace ~
34375 \InsetSpace ~
34376 \InsetSpace ~
34377 \InsetSpace ~
34378 \InsetSpace ~
34379 \InsetSpace ~
34380 \InsetSpace ~
34381 \InsetSpace ~
34382 \InsetSpace ~
34383 \InsetSpace ~
34384 \InsetSpace ~
34385 \InsetSpace ~
34386 \InsetSpace ~
34387 \InsetSpace ~
34388  69\InsetSpace ~
34389 \InsetSpace ~
34390 \InsetSpace ~
34391 \InsetSpace ~
34392 \InsetSpace ~
34393 \InsetSpace ~
34394 \InsetSpace ~
34395 \InsetSpace ~
34396  mov\InsetSpace ~
34397 \InsetSpace ~
34398  _foo_hob2_1_1,c
34399  
34400 \newline
34401 \InsetSpace ~
34402 \InsetSpace ~
34403 \InsetSpace ~
34404 \InsetSpace ~
34405 \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 \InsetSpace ~
34424 \InsetSpace ~
34425 \InsetSpace ~
34426  66 ;\InsetSpace ~
34427  hob.c 9 
34428 \newline
34429 0016 E5*01\InsetSpace ~
34430 \InsetSpace ~
34431 \InsetSpace ~
34432 \InsetSpace ~
34433 \InsetSpace ~
34434 \InsetSpace ~
34435 \InsetSpace ~
34436 \InsetSpace ~
34437 \InsetSpace ~
34438 \InsetSpace ~
34439 \InsetSpace ~
34440 \InsetSpace ~
34441 \InsetSpace ~
34442 \InsetSpace ~
34443 \InsetSpace ~
34444  67\InsetSpace ~
34445 \InsetSpace ~
34446 \InsetSpace ~
34447 \InsetSpace ~
34448 \InsetSpace ~
34449 \InsetSpace ~
34450 \InsetSpace ~
34451 \InsetSpace ~
34452  mov\InsetSpace ~
34453 \InsetSpace ~
34454  a,(_gint + 1) 
34455 \newline
34456 0018 33\InsetSpace ~
34457 \InsetSpace ~
34458 \InsetSpace ~
34459 \InsetSpace ~
34460 \InsetSpace ~
34461 \InsetSpace ~
34462 \InsetSpace ~
34463 \InsetSpace ~
34464 \InsetSpace ~
34465 \InsetSpace ~
34466 \InsetSpace ~
34467 \InsetSpace ~
34468 \InsetSpace ~
34469 \InsetSpace ~
34470 \InsetSpace ~
34471 \InsetSpace ~
34472 \InsetSpace ~
34473 \InsetSpace ~
34474  68\InsetSpace ~
34475 \InsetSpace ~
34476 \InsetSpace ~
34477 \InsetSpace ~
34478 \InsetSpace ~
34479 \InsetSpace ~
34480 \InsetSpace ~
34481 \InsetSpace ~
34482  rlc\InsetSpace ~
34483 \InsetSpace ~
34484  a 
34485 \newline
34486 0019 92*01\InsetSpace ~
34487 \InsetSpace ~
34488 \InsetSpace ~
34489 \InsetSpace ~
34490 \InsetSpace ~
34491 \InsetSpace ~
34492 \InsetSpace ~
34493 \InsetSpace ~
34494 \InsetSpace ~
34495 \InsetSpace ~
34496 \InsetSpace ~
34497 \InsetSpace ~
34498 \InsetSpace ~
34499 \InsetSpace ~
34500 \InsetSpace ~
34501
34502  69\InsetSpace ~
34503 \InsetSpace ~
34504 \InsetSpace ~
34505 \InsetSpace ~
34506 \InsetSpace ~
34507 \InsetSpace ~
34508 \InsetSpace ~
34509 \InsetSpace ~
34510  mov\InsetSpace ~
34511 \InsetSpace ~
34512  _foo_hob3_1_1,c 
34513 \newline
34514 \InsetSpace ~
34515 \InsetSpace ~
34516 \InsetSpace ~
34517 \InsetSpace ~
34518 \InsetSpace ~
34519 \InsetSpace ~
34520 \InsetSpace ~
34521 \InsetSpace ~
34522 \InsetSpace ~
34523 \InsetSpace ~
34524 \InsetSpace ~
34525 \InsetSpace ~
34526 \InsetSpace ~
34527 \InsetSpace ~
34528 \InsetSpace ~
34529 \InsetSpace ~
34530 \InsetSpace ~
34531 \InsetSpace ~
34532 \InsetSpace ~
34533 \InsetSpace ~
34534 \InsetSpace ~
34535 \InsetSpace ~
34536 \InsetSpace ~
34537 \InsetSpace ~
34538 \InsetSpace ~
34539  70 ;\InsetSpace ~
34540  hob.c 10 
34541 \newline
34542 001B E5*01\InsetSpace ~
34543 \InsetSpace ~
34544 \InsetSpace ~
34545 \InsetSpace ~
34546 \InsetSpace ~
34547 \InsetSpace ~
34548 \InsetSpace ~
34549 \InsetSpace ~
34550 \InsetSpace ~
34551 \InsetSpace ~
34552 \InsetSpace ~
34553 \InsetSpace ~
34554 \InsetSpace ~
34555 \InsetSpace ~
34556 \InsetSpace ~
34557  71\InsetSpace ~
34558 \InsetSpace ~
34559 \InsetSpace ~
34560 \InsetSpace ~
34561 \InsetSpace ~
34562 \InsetSpace ~
34563 \InsetSpace ~
34564 \InsetSpace ~
34565  mov\InsetSpace ~
34566 \InsetSpace ~
34567  a,(_gint + 1) 
34568 \newline
34569 001D
34570  03\InsetSpace ~
34571 \InsetSpace ~
34572 \InsetSpace ~
34573 \InsetSpace ~
34574 \InsetSpace ~
34575 \InsetSpace ~
34576 \InsetSpace ~
34577 \InsetSpace ~
34578 \InsetSpace ~
34579 \InsetSpace ~
34580 \InsetSpace ~
34581 \InsetSpace ~
34582 \InsetSpace ~
34583 \InsetSpace ~
34584 \InsetSpace ~
34585 \InsetSpace ~
34586 \InsetSpace ~
34587 \InsetSpace ~
34588  72\InsetSpace ~
34589 \InsetSpace ~
34590 \InsetSpace ~
34591 \InsetSpace ~
34592 \InsetSpace ~
34593 \InsetSpace ~
34594 \InsetSpace ~
34595 \InsetSpace ~
34596  rr\InsetSpace ~
34597 \InsetSpace ~
34598 \InsetSpace ~
34599  a 
34600 \newline
34601 001E 54 01\InsetSpace ~
34602 \InsetSpace ~
34603 \InsetSpace ~
34604 \InsetSpace ~
34605 \InsetSpace ~
34606 \InsetSpace ~
34607 \InsetSpace ~
34608 \InsetSpace ~
34609 \InsetSpace ~
34610 \InsetSpace ~
34611 \InsetSpace ~
34612 \InsetSpace ~
34613 \InsetSpace ~
34614 \InsetSpace ~
34615 \InsetSpace ~
34616  73\InsetSpace ~
34617 \InsetSpace ~
34618 \InsetSpace ~
34619 \InsetSpace ~
34620 \InsetSpace ~
34621 \InsetSpace ~
34622 \InsetSpace ~
34623 \InsetSpace ~
34624  anl\InsetSpace ~
34625 \InsetSpace ~
34626  a,#0x01 
34627 \newline
34628 0020 F5*03\InsetSpace ~
34629 \InsetSpace ~
34630 \InsetSpace ~
34631 \InsetSpace ~
34632 \InsetSpace ~
34633 \InsetSpace ~
34634 \InsetSpace ~
34635 \InsetSpace ~
34636 \InsetSpace ~
34637 \InsetSpace ~
34638 \InsetSpace ~
34639 \InsetSpace ~
34640 \InsetSpace ~
34641 \InsetSpace ~
34642 \InsetSpace ~
34643  74\InsetSpace ~
34644 \InsetSpace ~
34645 \InsetSpace ~
34646 \InsetSpace ~
34647 \InsetSpace ~
34648 \InsetSpace ~
34649 \InsetSpace ~
34650 \InsetSpace ~
34651  mov\InsetSpace ~
34652 \InsetSpace ~
34653  _foo_aob1_1_1,a
34654  
34655 \newline
34656 \InsetSpace ~
34657 \InsetSpace ~
34658 \InsetSpace ~
34659 \InsetSpace ~
34660 \InsetSpace ~
34661 \InsetSpace ~
34662 \InsetSpace ~
34663 \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 \InsetSpace ~
34679 \InsetSpace ~
34680 \InsetSpace ~
34681  75 ;\InsetSpace ~
34682  hob.c 11 
34683 \newline
34684 0022 E5*01\InsetSpace ~
34685 \InsetSpace ~
34686 \InsetSpace ~
34687 \InsetSpace ~
34688 \InsetSpace ~
34689 \InsetSpace ~
34690 \InsetSpace ~
34691 \InsetSpace ~
34692 \InsetSpace ~
34693 \InsetSpace ~
34694 \InsetSpace ~
34695 \InsetSpace ~
34696 \InsetSpace ~
34697 \InsetSpace ~
34698 \InsetSpace ~
34699  76\InsetSpace ~
34700 \InsetSpace ~
34701 \InsetSpace ~
34702 \InsetSpace ~
34703 \InsetSpace ~
34704 \InsetSpace ~
34705 \InsetSpace ~
34706 \InsetSpace ~
34707  mov\InsetSpace ~
34708 \InsetSpace ~
34709  a,(_gint + 1) 
34710 \newline
34711 0024 13\InsetSpace ~
34712 \InsetSpace ~
34713 \InsetSpace ~
34714 \InsetSpace ~
34715 \InsetSpace ~
34716 \InsetSpace ~
34717 \InsetSpace ~
34718 \InsetSpace ~
34719 \InsetSpace ~
34720 \InsetSpace ~
34721 \InsetSpace ~
34722 \InsetSpace ~
34723 \InsetSpace ~
34724 \InsetSpace ~
34725 \InsetSpace ~
34726 \InsetSpace ~
34727 \InsetSpace ~
34728 \InsetSpace ~
34729  77\InsetSpace ~
34730 \InsetSpace ~
34731 \InsetSpace ~
34732 \InsetSpace ~
34733 \InsetSpace ~
34734 \InsetSpace ~
34735 \InsetSpace ~
34736 \InsetSpace ~
34737  rrc\InsetSpace ~
34738 \InsetSpace ~
34739  a 
34740 \newline
34741 0025 92*02\InsetSpace ~
34742 \InsetSpace ~
34743 \InsetSpace ~
34744 \InsetSpace ~
34745 \InsetSpace ~
34746 \InsetSpace ~
34747 \InsetSpace ~
34748 \InsetSpace ~
34749 \InsetSpace ~
34750 \InsetSpace ~
34751 \InsetSpace ~
34752 \InsetSpace ~
34753 \InsetSpace ~
34754 \InsetSpace ~
34755 \InsetSpace ~
34756
34757  78\InsetSpace ~
34758 \InsetSpace ~
34759 \InsetSpace ~
34760 \InsetSpace ~
34761 \InsetSpace ~
34762 \InsetSpace ~
34763 \InsetSpace ~
34764 \InsetSpace ~
34765  mov\InsetSpace ~
34766 \InsetSpace ~
34767  _foo_aob2_1_1,c 
34768 \newline
34769 \InsetSpace ~
34770 \InsetSpace ~
34771 \InsetSpace ~
34772 \InsetSpace ~
34773 \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 \InsetSpace ~
34792 \InsetSpace ~
34793 \InsetSpace ~
34794  79 ;\InsetSpace ~
34795  hob.c 12 
34796 \newline
34797 0027 E5*01\InsetSpace ~
34798 \InsetSpace ~
34799 \InsetSpace ~
34800 \InsetSpace ~
34801 \InsetSpace ~
34802 \InsetSpace ~
34803 \InsetSpace ~
34804 \InsetSpace ~
34805 \InsetSpace ~
34806 \InsetSpace ~
34807 \InsetSpace ~
34808 \InsetSpace ~
34809 \InsetSpace ~
34810 \InsetSpace ~
34811 \InsetSpace ~
34812  80\InsetSpace ~
34813 \InsetSpace ~
34814 \InsetSpace ~
34815 \InsetSpace ~
34816 \InsetSpace ~
34817 \InsetSpace ~
34818 \InsetSpace ~
34819 \InsetSpace ~
34820  mov\InsetSpace ~
34821 \InsetSpace ~
34822  a,(_gint + 1) 
34823 \newline
34824 0029
34825  A2 E3\InsetSpace ~
34826 \InsetSpace ~
34827 \InsetSpace ~
34828 \InsetSpace ~
34829 \InsetSpace ~
34830 \InsetSpace ~
34831 \InsetSpace ~
34832 \InsetSpace ~
34833 \InsetSpace ~
34834 \InsetSpace ~
34835 \InsetSpace ~
34836 \InsetSpace ~
34837 \InsetSpace ~
34838 \InsetSpace ~
34839 \InsetSpace ~
34840  81\InsetSpace ~
34841 \InsetSpace ~
34842 \InsetSpace ~
34843 \InsetSpace ~
34844 \InsetSpace ~
34845 \InsetSpace ~
34846 \InsetSpace ~
34847 \InsetSpace ~
34848  mov\InsetSpace ~
34849 \InsetSpace ~
34850  c,acc[3] 
34851 \newline
34852 002B 92*03\InsetSpace ~
34853 \InsetSpace ~
34854 \InsetSpace ~
34855 \InsetSpace ~
34856 \InsetSpace ~
34857 \InsetSpace ~
34858 \InsetSpace ~
34859 \InsetSpace ~
34860 \InsetSpace ~
34861 \InsetSpace ~
34862 \InsetSpace ~
34863 \InsetSpace ~
34864 \InsetSpace ~
34865 \InsetSpace ~
34866 \InsetSpace ~
34867  82\InsetSpace ~
34868 \InsetSpace ~
34869 \InsetSpace ~
34870 \InsetSpace ~
34871 \InsetSpace ~
34872 \InsetSpace ~
34873 \InsetSpace ~
34874 \InsetSpace ~
34875  mov\InsetSpace ~
34876 \InsetSpace ~
34877  _foo_aob3_1_1,c 
34878 \end_layout
34879
34880 \begin_layout Standard
34881 Other variations of these cases however will 
34882 \emph on
34883 not
34884 \emph default
34885  be recognized.
34886  They are standard C expressions, so I heartily recommend these be the only
34887  way to get the highest order bit, (it is portable).
34888  Of course it will be recognized even if it is embedded in other expressions,
34889  e.g.:
34890 \end_layout
34891
34892 \begin_layout Verse
34893
34894 \family typewriter
34895 xyz = gint + ((gint >> 15) & 1);
34896 \end_layout
34897
34898 \begin_layout Standard
34899 will still be recognized.
34900 \end_layout
34901
34902 \begin_layout Subsection
34903 Higher Order Byte
34904 \begin_inset LatexCommand \index{Higher Order Byte}
34905
34906 \end_inset
34907
34908  / Higher Order Word
34909 \begin_inset LatexCommand \index{Higher Order Word}
34910
34911 \end_inset
34912
34913
34914 \end_layout
34915
34916 \begin_layout Standard
34917 It is also frequently required to obtain a higher order byte or word of
34918  a larger integral type (long, int or short types).
34919  SDCC recognizes the following expressions to yield the higher order byte
34920  or word and generates optimized code for it, e.g.:
34921 \end_layout
34922
34923 \begin_layout Verse
34924
34925 \family typewriter
34926 unsigned int gint; 
34927 \newline
34928 unsigned long int glong; 
34929 \newline
34930
34931 \newline
34932 foo () { 
34933 \newline
34934 \InsetSpace ~
34935 \InsetSpace ~
34936 unsigned char hob1,
34937  hob2; 
34938 \newline
34939 \InsetSpace ~
34940 \InsetSpace ~
34941 unsigned int how1, how2; 
34942 \newline
34943 \InsetSpace ~
34944 \InsetSpace ~
34945 ...
34946  
34947 \newline
34948 \InsetSpace ~
34949 \InsetSpace ~
34950 hob1 = (gint >> 8) & 0xFF; 
34951 \newline
34952 \InsetSpace ~
34953 \InsetSpace ~
34954 hob2 = glong >> 24; 
34955 \newline
34956 \InsetSpace ~
34957 \InsetSpace ~
34958 how1 = (glong >> 16) & 0xFFFF;
34959  
34960 \newline
34961 \InsetSpace ~
34962 \InsetSpace ~
34963 how2 = glong >> 8; 
34964 \newline
34965 \InsetSpace ~
34966 \InsetSpace ~
34967 ..
34968  
34969 \newline
34970 }
34971 \end_layout
34972
34973 \begin_layout Standard
34974 will generate the following code:
34975 \end_layout
34976
34977 \begin_layout Verse
34978
34979 \family typewriter
34980 \InsetSpace ~
34981 \InsetSpace ~
34982 \InsetSpace ~
34983 \InsetSpace ~
34984 \InsetSpace ~
34985 \InsetSpace ~
34986 \InsetSpace ~
34987 \InsetSpace ~
34988 \InsetSpace ~
34989 \InsetSpace ~
34990 \InsetSpace ~
34991 \InsetSpace ~
34992 \InsetSpace ~
34993 \InsetSpace ~
34994 \InsetSpace ~
34995 \InsetSpace ~
34996 \InsetSpace ~
34997 \InsetSpace ~
34998 \InsetSpace ~
34999 \InsetSpace ~
35000 \InsetSpace ~
35001 \InsetSpace ~
35002 \InsetSpace ~
35003 \InsetSpace ~
35004 \InsetSpace ~
35005  91 ;\InsetSpace ~
35006  hob.c 15 
35007 \newline
35008 0037 85*01*06\InsetSpace ~
35009 \InsetSpace ~
35010 \InsetSpace ~
35011 \InsetSpace ~
35012 \InsetSpace ~
35013 \InsetSpace ~
35014 \InsetSpace ~
35015 \InsetSpace ~
35016 \InsetSpace ~
35017 \InsetSpace ~
35018 \InsetSpace ~
35019 \InsetSpace ~
35020  92\InsetSpace ~
35021 \InsetSpace ~
35022 \InsetSpace ~
35023 \InsetSpace ~
35024 \InsetSpace ~
35025 \InsetSpace ~
35026 \InsetSpace ~
35027 \InsetSpace ~
35028  mov\InsetSpace ~
35029 \InsetSpace ~
35030  _foo_hob1_1_1,(_gint + 1) 
35031 \newline
35032 \InsetSpace ~
35033 \InsetSpace ~
35034 \InsetSpace ~
35035 \InsetSpace ~
35036 \InsetSpace ~
35037 \InsetSpace ~
35038 \InsetSpace ~
35039 \InsetSpace ~
35040 \InsetSpace ~
35041 \InsetSpace ~
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  93 ;\InsetSpace ~
35058  hob.c
35059  16 
35060 \newline
35061 003A 85*05*07\InsetSpace ~
35062 \InsetSpace ~
35063 \InsetSpace ~
35064 \InsetSpace ~
35065 \InsetSpace ~
35066 \InsetSpace ~
35067 \InsetSpace ~
35068 \InsetSpace ~
35069 \InsetSpace ~
35070 \InsetSpace ~
35071 \InsetSpace ~
35072 \InsetSpace ~
35073  94\InsetSpace ~
35074 \InsetSpace ~
35075 \InsetSpace ~
35076 \InsetSpace ~
35077 \InsetSpace ~
35078 \InsetSpace ~
35079 \InsetSpace ~
35080 \InsetSpace ~
35081  mov\InsetSpace ~
35082 \InsetSpace ~
35083  _foo_hob2_1_1,(_glong + 3) 
35084 \newline
35085 \InsetSpace ~
35086 \InsetSpace ~
35087 \InsetSpace ~
35088 \InsetSpace ~
35089 \InsetSpace ~
35090 \InsetSpace ~
35091 \InsetSpace ~
35092 \InsetSpace ~
35093 \InsetSpace ~
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  95 ;\InsetSpace ~
35111  hob.c 17 
35112 \newline
35113 003D 85*04*08\InsetSpace ~
35114 \InsetSpace ~
35115 \InsetSpace ~
35116 \InsetSpace ~
35117 \InsetSpace ~
35118 \InsetSpace ~
35119 \InsetSpace ~
35120 \InsetSpace ~
35121 \InsetSpace ~
35122 \InsetSpace ~
35123 \InsetSpace ~
35124 \InsetSpace ~
35125
35126  96\InsetSpace ~
35127 \InsetSpace ~
35128 \InsetSpace ~
35129 \InsetSpace ~
35130 \InsetSpace ~
35131 \InsetSpace ~
35132 \InsetSpace ~
35133 \InsetSpace ~
35134  mov\InsetSpace ~
35135 \InsetSpace ~
35136  _foo_how1_1_1,(_glong + 2) 
35137 \newline
35138 0040 85*05*09\InsetSpace ~
35139 \InsetSpace ~
35140 \InsetSpace ~
35141 \InsetSpace ~
35142 \InsetSpace ~
35143 \InsetSpace ~
35144 \InsetSpace ~
35145 \InsetSpace ~
35146 \InsetSpace ~
35147 \InsetSpace ~
35148 \InsetSpace ~
35149 \InsetSpace ~
35150  97\InsetSpace ~
35151 \InsetSpace ~
35152 \InsetSpace ~
35153 \InsetSpace ~
35154 \InsetSpace ~
35155 \InsetSpace ~
35156 \InsetSpace ~
35157 \InsetSpace ~
35158  mov\InsetSpace ~
35159 \InsetSpace ~
35160  (_foo_how1_1_1 +
35161  1),(_glong + 3) 
35162 \newline
35163 0043 85*03*0A\InsetSpace ~
35164 \InsetSpace ~
35165 \InsetSpace ~
35166 \InsetSpace ~
35167 \InsetSpace ~
35168 \InsetSpace ~
35169 \InsetSpace ~
35170 \InsetSpace ~
35171 \InsetSpace ~
35172 \InsetSpace ~
35173 \InsetSpace ~
35174 \InsetSpace ~
35175  98\InsetSpace ~
35176 \InsetSpace ~
35177 \InsetSpace ~
35178 \InsetSpace ~
35179 \InsetSpace ~
35180 \InsetSpace ~
35181 \InsetSpace ~
35182 \InsetSpace ~
35183  mov\InsetSpace ~
35184 \InsetSpace ~
35185  _foo_how2_1_1,(_glong + 1) 
35186 \newline
35187 0046 85*04*0B\InsetSpace ~
35188 \InsetSpace ~
35189 \InsetSpace ~
35190 \InsetSpace ~
35191 \InsetSpace ~
35192 \InsetSpace ~
35193 \InsetSpace ~
35194 \InsetSpace ~
35195 \InsetSpace ~
35196 \InsetSpace ~
35197 \InsetSpace ~
35198 \InsetSpace ~
35199
35200  99\InsetSpace ~
35201 \InsetSpace ~
35202 \InsetSpace ~
35203 \InsetSpace ~
35204 \InsetSpace ~
35205 \InsetSpace ~
35206 \InsetSpace ~
35207 \InsetSpace ~
35208  mov\InsetSpace ~
35209 \InsetSpace ~
35210  (_foo_how2_1_1 + 1),(_glong + 2) 
35211 \end_layout
35212
35213 \begin_layout Standard
35214 Again, variations of these cases may 
35215 \emph on
35216 not
35217 \emph default
35218  be recognized.
35219  They are standard C expressions, so I heartily recommend these be the only
35220  way to get the higher order byte/word, (it is portable).
35221  Of course it will be recognized even if it is embedded in other expressions,
35222  e.g.:
35223 \end_layout
35224
35225 \begin_layout Verse
35226
35227 \family typewriter
35228 xyz = gint + ((gint >> 8) & 0xFF);
35229 \end_layout
35230
35231 \begin_layout Standard
35232 will still be recognized.
35233 \end_layout
35234
35235 \begin_layout Subsection
35236 Peephole Optimizer
35237 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
35238
35239 \end_inset
35240
35241
35242 \begin_inset LatexCommand \index{Peephole optimizer}
35243
35244 \end_inset
35245
35246
35247 \end_layout
35248
35249 \begin_layout Standard
35250 The compiler uses a rule based, pattern matching and re-writing mechanism
35251  for peep-hole optimization.
35252  It is inspired by 
35253 \emph on
35254 copt
35255 \emph default
35256  a peep-hole optimizer by Christopher W.
35257  Fraser (cwfraser\InsetSpace ~
35258 @\InsetSpace ~
35259 microsoft.com).
35260  A default set of rules are compiled into the compiler, additional rules
35261  may be added with the 
35262 \emph on
35263 -
35264 \begin_inset ERT
35265 status collapsed
35266
35267 \begin_layout Standard
35268
35269
35270 \backslash
35271 /
35272 \end_layout
35273
35274 \end_inset
35275
35276 -peep-file
35277 \begin_inset LatexCommand \index{-\/-peep-file}
35278
35279 \end_inset
35280
35281  <filename>
35282 \emph default
35283  option.
35284  The rule language is best illustrated with examples.
35285 \end_layout
35286
35287 \begin_layout Verse
35288
35289 \family typewriter
35290 replace { 
35291 \newline
35292 \InsetSpace ~
35293 \InsetSpace ~
35294 mov %1,a 
35295 \newline
35296 \InsetSpace ~
35297 \InsetSpace ~
35298 mov a,%1
35299 \newline
35300 } by {
35301 \newline
35302 \InsetSpace ~
35303 \InsetSpace ~
35304 mov %1,a
35305 \newline
35306 }
35307 \end_layout
35308
35309 \begin_layout Standard
35310 The above rule will change the following assembly
35311 \begin_inset LatexCommand \index{Assembler routines}
35312
35313 \end_inset
35314
35315  sequence:
35316 \end_layout
35317
35318 \begin_layout Verse
35319
35320 \family typewriter
35321 mov r1,a 
35322 \newline
35323 mov a,r1
35324 \end_layout
35325
35326 \begin_layout Standard
35327 to
35328 \end_layout
35329
35330 \begin_layout Verse
35331
35332 \family typewriter
35333 mov r1,a
35334 \end_layout
35335
35336 \begin_layout Standard
35337 Note: All occurrences of a 
35338 \emph on
35339 %n
35340 \emph default
35341  (pattern variable) must denote the same string.
35342  With the above rule, the assembly sequence:
35343 \end_layout
35344
35345 \begin_layout Verse
35346
35347 \family typewriter
35348 mov r1,a 
35349 \newline
35350 mov a,r2
35351 \end_layout
35352
35353 \begin_layout Standard
35354 will remain unmodified.
35355 \newline
35356
35357 \newline
35358 Other special case optimizations may be added by the
35359  user (via 
35360 \emph on
35361 -
35362 \begin_inset ERT
35363 status collapsed
35364
35365 \begin_layout Standard
35366
35367
35368 \backslash
35369 /
35370 \end_layout
35371
35372 \end_inset
35373
35374 -peep-file option
35375 \emph default
35376 ).
35377  E.g.
35378  some variants of the 8051 MCU
35379 \begin_inset LatexCommand \index{MCS51 variants}
35380
35381 \end_inset
35382
35383  allow only 
35384 \family typewriter
35385 ajmp
35386 \family default
35387  and 
35388 \family typewriter
35389 acall
35390 \family default
35391 .
35392  The following two rules will change all 
35393 \family typewriter
35394 ljmp
35395 \family default
35396  and 
35397 \family typewriter
35398 lcall
35399 \family default
35400  to 
35401 \family typewriter
35402 ajmp
35403 \family default
35404  and 
35405 \family typewriter
35406 acall
35407 \end_layout
35408
35409 \begin_layout Verse
35410
35411 \family typewriter
35412 replace { lcall %1 } by { acall %1 } 
35413 \newline
35414 replace { ljmp %1 } by { ajmp %1 }
35415 \end_layout
35416
35417 \begin_layout Standard
35418 The 
35419 \emph on
35420 inline-assembler code
35421 \emph default
35422  is also passed through the peep hole optimizer, thus the peephole optimizer
35423  can also be used as an assembly level macro expander.
35424  The rules themselves are MCU dependent whereas the rule language infra-structur
35425 e is MCU independent.
35426  Peephole optimization rules for other MCU can be easily programmed using
35427  the rule language.
35428 \newline
35429
35430 \newline
35431 The syntax for a rule is as follows:
35432 \end_layout
35433
35434 \begin_layout Verse
35435
35436 \family typewriter
35437 rule := replace [ restart ] '{' <assembly sequence> '
35438 \backslash
35439 n' 
35440 \newline
35441 \InsetSpace ~
35442  \InsetSpace ~
35443  \InsetSpace ~
35444  \InsetSpace ~
35445  \InsetSpace ~
35446  \InsetSpace ~
35447  \InsetSpace ~
35448  \InsetSpace ~
35449  \InsetSpace ~
35450  \InsetSpace ~
35451  \InsetSpace ~
35452  \InsetSpace ~
35453  \InsetSpace ~
35454  \InsetSpace ~
35455  '}' by '{' '
35456 \backslash
35457 n' 
35458 \newline
35459 \InsetSpace ~
35460  \InsetSpace ~
35461  \InsetSpace ~
35462  \InsetSpace ~
35463  \InsetSpace ~
35464  \InsetSpace ~
35465  \InsetSpace ~
35466  \InsetSpace ~
35467  \InsetSpace ~
35468  \InsetSpace ~
35469  \InsetSpace ~
35470  \InsetSpace ~
35471  \InsetSpace ~
35472  \InsetSpace ~
35473  \InsetSpace ~
35474  \InsetSpace ~
35475  <assembly sequence> '
35476 \backslash
35477 n' 
35478 \newline
35479 \InsetSpace ~
35480  \InsetSpace ~
35481  \InsetSpace ~
35482  \InsetSpace ~
35483  \InsetSpace ~
35484  \InsetSpace ~
35485  \InsetSpace ~
35486  \InsetSpace ~
35487  \InsetSpace ~
35488  \InsetSpace ~
35489  \InsetSpace ~
35490  \InsetSpace ~
35491  \InsetSpace ~
35492  \InsetSpace ~
35493  '}' [if <functionName> ] '
35494 \backslash
35495 n' 
35496 \end_layout
35497
35498 \begin_layout Standard
35499 <assembly sequence> := assembly instruction (each instruction including
35500  labels must be on a separate line).
35501 \newline
35502
35503 \newline
35504 The optimizer will apply to the rules
35505  one by one from the top in the sequence of their appearance, it will terminate
35506  when all rules are exhausted.
35507  If the 'restart' option is specified, then the optimizer will start matching
35508  the rules again from the top, this option for a rule is expensive (performance)
35509 , it is intended to be used in situations where a transformation will trigger
35510  the same rule again.
35511  An example of this (not a good one, it has side effects) is the following
35512  rule:
35513 \end_layout
35514
35515 \begin_layout Verse
35516
35517 \family typewriter
35518 replace restart { 
35519 \newline
35520 \InsetSpace ~
35521 \InsetSpace ~
35522 pop %1 
35523 \newline
35524 \InsetSpace ~
35525 \InsetSpace ~
35526 push %1 } by { 
35527 \newline
35528 \InsetSpace ~
35529 \InsetSpace ~
35530 ; nop 
35531 \newline
35532 }
35533 \end_layout
35534
35535 \begin_layout Standard
35536 Note that the replace pattern cannot be a blank, but can be a comment line.
35537  Without the 'restart' option only the innermost 'pop' 'push' pair would
35538  be eliminated, i.e.:
35539 \end_layout
35540
35541 \begin_layout Verse
35542
35543 \family typewriter
35544 pop ar1 
35545 \newline
35546 pop ar2 
35547 \newline
35548 push ar2 
35549 \newline
35550 push ar1
35551 \end_layout
35552
35553 \begin_layout Standard
35554 would result in:
35555 \end_layout
35556
35557 \begin_layout Verse
35558
35559 \family typewriter
35560 pop ar1 
35561 \newline
35562 ; nop 
35563 \newline
35564 push ar1
35565 \end_layout
35566
35567 \begin_layout Standard
35568
35569 \emph on
35570 with
35571 \emph default
35572  the restart option the rule will be applied again to the resulting code
35573  and then all the pop-push pairs will be eliminated to yield:
35574 \end_layout
35575
35576 \begin_layout Verse
35577
35578 \family typewriter
35579 ; nop 
35580 \newline
35581 ; nop
35582 \end_layout
35583
35584 \begin_layout Standard
35585 A conditional function can be attached to a rule.
35586  Attaching rules are somewhat more involved, let me illustrate this with
35587  an example.
35588 \end_layout
35589
35590 \begin_layout Verse
35591
35592 \family typewriter
35593 replace { 
35594 \newline
35595 \InsetSpace ~
35596  \InsetSpace ~
35597  \InsetSpace ~
35598 ljmp %5 
35599 \newline
35600 %2:
35601 \newline
35602 } by { 
35603 \newline
35604 \InsetSpace ~
35605  \InsetSpace ~
35606  \InsetSpace ~
35607 sjmp %5 
35608 \newline
35609 %2:
35610 \newline
35611 } if labelInRange
35612 \end_layout
35613
35614 \begin_layout Standard
35615 The optimizer does a look-up of a function name table defined in function
35616  
35617 \emph on
35618 callFuncByName
35619 \emph default
35620  in the source file SDCCpeeph.c, with the name 
35621 \emph on
35622 labelInRange
35623 \emph default
35624 .
35625  If it finds a corresponding entry the function is called.
35626  Note there can be no parameters specified for these functions, in this
35627  case the use of 
35628 \emph on
35629 %5
35630 \emph default
35631  is crucial, since the function 
35632 \emph on
35633 labelInRange
35634 \emph default
35635  expects to find the label in that particular variable (the hash table containin
35636 g the variable bindings is passed as a parameter).
35637  If you want to code more such functions, take a close look at the function
35638  labelInRange and the calling mechanism in source file SDCCpeeph.c.
35639  Currently implemented are 
35640 \emph on
35641 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
35642  24bitMode, portIsDS390, 24bitModeAndPortDS390 
35643 \emph default
35644 and
35645 \emph on
35646  notVolatile
35647 \emph default
35648 .
35649 \end_layout
35650
35651 \begin_layout Standard
35652 I know this whole thing is a little kludgey, but maybe some day we will
35653  have some better means.
35654  If you are looking at this file, you will see the default rules that are
35655  compiled into the compiler, you can add your own rules in the default set
35656  there if you get tired of specifying the -
35657 \begin_inset ERT
35658 status collapsed
35659
35660 \begin_layout Standard
35661
35662
35663 \backslash
35664 /
35665 \end_layout
35666
35667 \end_inset
35668
35669 -peep-file option.
35670 \end_layout
35671
35672 \begin_layout Section
35673 ANSI-Compliance
35674 \begin_inset LatexCommand \index{ANSI-compliance}
35675
35676 \end_inset
35677
35678
35679 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
35680
35681 \end_inset
35682
35683
35684 \end_layout
35685
35686 \begin_layout Standard
35687 The latest publically available version of the standard 
35688 \emph on
35689 ISO/IEC 9899 - Programming languages - C
35690 \emph default
35691  should be available at: 
35692 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
35693
35694 \end_inset
35695
35696 .
35697 \newline
35698
35699 \end_layout
35700
35701 \begin_layout Standard
35702 Deviations from the compliance:
35703 \end_layout
35704
35705 \begin_layout Itemize
35706 functions are not reentrant
35707 \begin_inset LatexCommand \index{reentrant}
35708
35709 \end_inset
35710
35711  unless explicitly declared as such or the 
35712 \series bold
35713 -
35714 \begin_inset ERT
35715 status collapsed
35716
35717 \begin_layout Standard
35718
35719
35720 \backslash
35721 /
35722 \end_layout
35723
35724 \end_inset
35725
35726 -stack-auto
35727 \begin_inset LatexCommand \index{-\/-stack-auto}
35728
35729 \end_inset
35730
35731
35732 \series default
35733  command line option is specified.
35734 \end_layout
35735
35736 \begin_layout Itemize
35737 structures
35738 \begin_inset LatexCommand \index{struct}
35739
35740 \end_inset
35741
35742  and unions
35743 \begin_inset LatexCommand \index{union}
35744
35745 \end_inset
35746
35747  cannot be assigned values directly, cannot be passed as function parameters
35748  or assigned to each other and cannot be a return value
35749 \begin_inset LatexCommand \index{return value}
35750
35751 \end_inset
35752
35753  from a function, e.g.:
35754 \end_layout
35755
35756 \begin_deeper
35757 \begin_layout Verse
35758
35759 \family typewriter
35760 struct s { ...
35761  }; 
35762 \newline
35763 struct s s1, s2; 
35764 \newline
35765 foo() 
35766 \newline
35767
35768 \newline
35769 \InsetSpace ~
35770 \InsetSpace ~
35771 \InsetSpace ~
35772 \InsetSpace ~
35773 ...
35774  
35775 \newline
35776 \InsetSpace ~
35777 \InsetSpace ~
35778 \InsetSpace ~
35779 \InsetSpace ~
35780 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
35781 \newline
35782 \InsetSpace ~
35783 \InsetSpace ~
35784 \InsetSpace ~
35785 \InsetSpace ~
35786 ...
35787  
35788 \newline
35789 }
35790 \newline
35791
35792 \series bold
35793 struct
35794 \series default
35795  s foo1 (
35796 \series bold
35797 struct
35798 \series default
35799  s parms) /* invalid in SDCC although allowed in ANSI */
35800 \newline
35801
35802 \newline
35803 \InsetSpace ~
35804 \InsetSpace ~
35805 \InsetSpace ~
35806 \InsetSpace ~
35807 struct s rets;
35808  
35809 \newline
35810 \InsetSpace ~
35811 \InsetSpace ~
35812 \InsetSpace ~
35813 \InsetSpace ~
35814 ...
35815  
35816 \newline
35817 \InsetSpace ~
35818 \InsetSpace ~
35819 \InsetSpace ~
35820 \InsetSpace ~
35821 return rets; /* is invalid in SDCC although allowed in ANSI */ 
35822 \newline
35823 }
35824 \end_layout
35825
35826 \end_deeper
35827 \begin_layout Itemize
35828 initialization of structure arrays must be fully braced.
35829 \end_layout
35830
35831 \begin_deeper
35832 \begin_layout Verse
35833
35834 \family typewriter
35835 struct s { char x } a[] = {1, 2};\InsetSpace ~
35836 \InsetSpace ~
35837 \InsetSpace ~
35838 \InsetSpace ~
35839 \InsetSpace ~
35840 /* invalid in SDCC */
35841 \newline
35842 struct s { char x
35843  } a[] = {{1}, {2}}; /* OK */
35844 \end_layout
35845
35846 \end_deeper
35847 \begin_layout Itemize
35848 'long long
35849 \begin_inset LatexCommand \index{long long (not supported)}
35850
35851 \end_inset
35852
35853 ' (64 bit integers
35854 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
35855
35856 \end_inset
35857
35858 ) not supported.
35859 \end_layout
35860
35861 \begin_layout Itemize
35862 'double
35863 \begin_inset LatexCommand \index{double (not supported)}
35864
35865 \end_inset
35866
35867 ' precision floating point 
35868 \begin_inset LatexCommand \index{Floating point support}
35869
35870 \end_inset
35871
35872 not supported.
35873 \end_layout
35874
35875 \begin_layout Itemize
35876 Old K&R style
35877 \begin_inset LatexCommand \index{K\&R style}
35878
35879 \end_inset
35880
35881  function declarations are NOT allowed.
35882 \end_layout
35883
35884 \begin_deeper
35885 \begin_layout Verse
35886
35887 \family typewriter
35888 foo(i,j) /* this old style of function declarations */ 
35889 \newline
35890 int i,j; /* are valid
35891  in ANSI but not valid in SDCC */ 
35892 \newline
35893
35894 \newline
35895 \InsetSpace ~
35896 \InsetSpace ~
35897 \InsetSpace ~
35898 \InsetSpace ~
35899 ...
35900  
35901 \newline
35902 }
35903 \end_layout
35904
35905 \end_deeper
35906 \begin_layout Itemize
35907 Most enhancements in C99 are not supported, f.e.:
35908 \end_layout
35909
35910 \begin_deeper
35911 \begin_layout Verse
35912
35913 \family typewriter
35914 \series bold
35915 inline
35916 \begin_inset LatexCommand \index{inline (not supported)}
35917
35918 \end_inset
35919
35920
35921 \series default
35922  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
35923  in C99.
35924  An empty define 
35925 \emph on
35926 #define inline
35927 \emph default
35928  can be used as a work around */
35929 \newline
35930
35931 \newline
35932 for (
35933 \series bold
35934 int
35935 \series default
35936  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
35937 \end_layout
35938
35939 \end_deeper
35940 \begin_layout Itemize
35941 Certain words that are valid identifiers in the standard may be reserved
35942  words in SDCC unless the 
35943 \series bold
35944 -
35945 \begin_inset ERT
35946 status collapsed
35947
35948 \begin_layout Standard
35949
35950
35951 \backslash
35952 /
35953 \end_layout
35954
35955 \end_inset
35956
35957 -std-c89
35958 \begin_inset LatexCommand \index{-\/-std-c89}
35959
35960 \end_inset
35961
35962  or -
35963 \begin_inset ERT
35964 status collapsed
35965
35966 \begin_layout Standard
35967
35968
35969 \backslash
35970 /
35971 \end_layout
35972
35973 \end_inset
35974
35975 -std-c99
35976 \begin_inset LatexCommand \index{-\/-std-c99}
35977
35978 \end_inset
35979
35980
35981 \series default
35982  command line options are used.
35983  These may include (depending on the selected processor): 'at', 'banked',
35984  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
35985 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
35986  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
35987  '_naked'.
35988  Compliant equivalents of these keywords are always available in a form
35989  that begin with two underscores
35990 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
35991
35992 \end_inset
35993
35994 , f.e.
35995  '__data' instead of 'data'.
35996 \end_layout
35997
35998 \begin_layout Section
35999 Cyclomatic Complexity
36000 \begin_inset LatexCommand \index{Cyclomatic complexity}
36001
36002 \end_inset
36003
36004
36005 \end_layout
36006
36007 \begin_layout Standard
36008 Cyclomatic complexity of a function is defined as the number of independent
36009  paths the program can take during execution of the function.
36010  This is an important number since it defines the number test cases you
36011  have to generate to validate the function.
36012  The accepted industry standard for complexity number is 10, if the cyclomatic
36013  complexity reported by SDCC exceeds 10 you should think about simplification
36014  of the function logic.
36015  Note that the complexity level is not related to the number of lines of
36016  code in a function.
36017  Large functions can have low complexity, and small functions can have large
36018  complexity levels.
36019  
36020 \newline
36021
36022 \newline
36023 SDCC uses the following formula to compute the complexity:
36024 \newline
36025
36026 \end_layout
36027
36028 \begin_layout Standard
36029 complexity = (number of edges in control flow graph) - (number of nodes
36030  in control flow graph) + 2;
36031 \newline
36032
36033 \newline
36034 Having said that the industry standard is 10,
36035  you should be aware that in some cases it be may unavoidable to have a
36036  complexity level of less than 10.
36037  For example if you have switch statement with more than 10 case labels,
36038  each case label adds one to the complexity level.
36039  The complexity level is by no means an absolute measure of the algorithmic
36040  complexity of the function, it does however provide a good starting point
36041  for which functions you might look at for further optimization.
36042 \end_layout
36043
36044 \begin_layout Section
36045 Retargetting for other Processors
36046 \end_layout
36047
36048 \begin_layout Standard
36049 The issues for retargetting the compiler are far too numerous to be covered
36050  by this document.
36051  What follows is a brief description of each of the seven phases of the
36052  compiler and its MCU dependency.
36053 \end_layout
36054
36055 \begin_layout Itemize
36056 Parsing the source and building the annotated parse tree.
36057  This phase is largely MCU independent (except for the language extensions).
36058  Syntax & semantic checks are also done in this phase, along with some initial
36059  optimizations like back patching labels and the pattern matching optimizations
36060  like bit-rotation etc.
36061 \end_layout
36062
36063 \begin_layout Itemize
36064 The second phase involves generating an intermediate code which can be easy
36065  manipulated during the later phases.
36066  This phase is entirely MCU independent.
36067  The intermediate code generation assumes the target machine has unlimited
36068  number of registers, and designates them with the name iTemp.
36069  The compiler can be made to dump a human readable form of the code generated
36070  by using the -
36071 \begin_inset ERT
36072 status collapsed
36073
36074 \begin_layout Standard
36075
36076
36077 \backslash
36078 /
36079 \end_layout
36080
36081 \end_inset
36082
36083 -dumpraw option.
36084 \end_layout
36085
36086 \begin_layout Itemize
36087 This phase does the bulk of the standard optimizations and is also MCU independe
36088 nt.
36089  This phase can be broken down into several sub-phases:
36090 \newline
36091
36092 \newline
36093 Break down intermediate
36094  code (iCode) into basic blocks.
36095 \newline
36096 Do control flow & data flow analysis on the
36097  basic blocks.
36098 \newline
36099 Do local common subexpression elimination, then global subexpressio
36100 n elimination
36101 \newline
36102 Dead code elimination
36103 \newline
36104 Loop optimizations
36105 \newline
36106 If loop optimizations
36107  caused any changes then do 'global subexpression elimination' and 'dead
36108  code elimination' again.
36109 \end_layout
36110
36111 \begin_layout Itemize
36112 This phase determines the live-ranges; by live range I mean those iTemp
36113  variables defined by the compiler that still survive after all the optimization
36114 s.
36115  Live range analysis
36116 \begin_inset LatexCommand \index{Live range analysis}
36117
36118 \end_inset
36119
36120  is essential for register allocation, since these computation determines
36121  which of these iTemps will be assigned to registers, and for how long.
36122 \end_layout
36123
36124 \begin_layout Itemize
36125 Phase five is register allocation.
36126  There are two parts to this process.
36127 \newline
36128
36129 \newline
36130 The first part I call 'register packing'
36131  (for lack of a better term).
36132  In this case several MCU specific expression folding is done to reduce
36133  register pressure.
36134 \newline
36135
36136 \newline
36137 The second part is more MCU independent and deals with
36138  allocating registers to the remaining live ranges.
36139  A lot of MCU specific code does creep into this phase because of the limited
36140  number of index registers available in the 8051.
36141 \end_layout
36142
36143 \begin_layout Itemize
36144 The Code generation phase is (unhappily), entirely MCU dependent and very
36145  little (if any at all) of this code can be reused for other MCU.
36146  However the scheme for allocating a homogenized assembler operand for each
36147  iCode operand may be reused.
36148 \end_layout
36149
36150 \begin_layout Itemize
36151 As mentioned in the optimization section the peep-hole optimizer is rule
36152  based system, which can reprogrammed for other MCUs.
36153 \end_layout
36154
36155 \begin_layout Standard
36156 More information is available in a wiki
36157 \begin_inset LatexCommand \index{wiki}
36158
36159 \end_inset
36160
36161  (preliminary link 
36162 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
36163
36164 \end_inset
36165
36166 ) and in the thread 
36167 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
36168
36169 \end_inset
36170
36171  .
36172 \end_layout
36173
36174 \begin_layout Chapter
36175 Compiler internals
36176 \begin_inset LatexCommand \index{Compiler internals}
36177
36178 \end_inset
36179
36180
36181 \end_layout
36182
36183 \begin_layout Section
36184 The anatomy of the compiler
36185 \begin_inset LatexCommand \label{sub:The-anatomy-of}
36186
36187 \end_inset
36188
36189
36190 \end_layout
36191
36192 \begin_layout Standard
36193
36194 \shape italic
36195 This is an excerpt from an article published in Circuit Cellar Magazine
36196  in 
36197 \series bold
36198 August 2000
36199 \series default
36200 .
36201  It's a little outdated (the compiler is much more efficient now and user/develo
36202 per friendly), but pretty well exposes the guts of it all.
36203 \shape default
36204
36205 \newline
36206
36207 \newline
36208 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
36209  It is fairly easy to retarget for other 8-bit MCU.
36210  Here we take a look at some of the internals of the compiler.
36211  
36212 \end_layout
36213
36214 \begin_layout Paragraph*
36215 Parsing
36216 \begin_inset LatexCommand \index{Parsing}
36217
36218 \end_inset
36219
36220  
36221 \end_layout
36222
36223 \begin_layout Standard
36224 Parsing the input source file and creating an AST (Annotated Syntax Tree
36225 \begin_inset LatexCommand \index{Annotated syntax tree}
36226
36227 \end_inset
36228
36229 ).
36230  This phase also involves propagating types (annotating each node of the
36231  parse tree with type information) and semantic analysis.
36232  There are some MCU specific parsing rules.
36233  For example the storage classes, the extended storage classes are MCU specific
36234  while there may be a xdata storage class for 8051 there is no such storage
36235  class for z80 or Atmel AVR.
36236  SDCC allows MCU specific storage class extensions, i.e.
36237  xdata will be treated as a storage class specifier when parsing 8051 C
36238  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
36239  C code.
36240 \end_layout
36241
36242 \begin_layout Paragraph*
36243 Generating iCode
36244 \begin_inset LatexCommand \index{iCode}
36245
36246 \end_inset
36247
36248
36249 \end_layout
36250
36251 \begin_layout Standard
36252 Intermediate code generation.
36253  In this phase the AST is broken down into three-operand form (iCode).
36254  These three operand forms are represented as doubly linked lists.
36255  ICode is the term given to the intermediate form generated by the compiler.
36256  ICode example section shows some examples of iCode generated for some simple
36257  C source functions.
36258 \end_layout
36259
36260 \begin_layout Paragraph*
36261 Optimizations
36262 \begin_inset LatexCommand \index{Optimizations}
36263
36264 \end_inset
36265
36266 .
36267 \end_layout
36268
36269 \begin_layout Standard
36270 Bulk of the target independent optimizations is performed in this phase.
36271  The optimizations include constant propagation, common sub-expression eliminati
36272 on, loop invariant code movement, strength reduction of loop induction variables
36273  and dead-code elimination.
36274 \end_layout
36275
36276 \begin_layout Paragraph*
36277 Live range analysis
36278 \begin_inset LatexCommand \index{Live range analysis}
36279
36280 \end_inset
36281
36282
36283 \end_layout
36284
36285 \begin_layout Standard
36286 During intermediate code generation phase, the compiler assumes the target
36287  machine has infinite number of registers and generates a lot of temporary
36288  variables.
36289  The live range computation determines the lifetime of each of these compiler-ge
36290 nerated temporaries.
36291  A picture speaks a thousand words.
36292  ICode example sections show the live range annotations for each of the
36293  operand.
36294  It is important to note here, each iCode is assigned a number in the order
36295  of its execution in the function.
36296  The live ranges are computed in terms of these numbers.
36297  The from number is the number of the iCode which first defines the operand
36298  and the to number signifies the iCode which uses this operand last.
36299 \end_layout
36300
36301 \begin_layout Paragraph*
36302 Register Allocation
36303 \begin_inset LatexCommand \index{Register allocation}
36304
36305 \end_inset
36306
36307
36308 \end_layout
36309
36310 \begin_layout Standard
36311 The register allocation determines the type and number of registers needed
36312  by each operand.
36313  In most MCUs only a few registers can be used for indirect addressing.
36314  In case of 8051 for example the registers R0 & R1 can be used to indirectly
36315  address the internal ram and DPTR to indirectly address the external ram.
36316  The compiler will try to allocate the appropriate register to pointer variables
36317  if it can.
36318  ICode example section shows the operands annotated with the registers assigned
36319  to them.
36320  The compiler will try to keep operands in registers as much as possible;
36321  there are several schemes the compiler uses to do achieve this.
36322  When the compiler runs out of registers the compiler will check to see
36323  if there are any live operands which is not used or defined in the current
36324  basic block being processed, if there are any found then it will push that
36325  operand and use the registers in this block, the operand will then be popped
36326  at the end of the basic block.
36327  
36328 \end_layout
36329
36330 \begin_layout Standard
36331 There are other MCU specific considerations in this phase.
36332  Some MCUs have an accumulator; very short-lived operands could be assigned
36333  to the accumulator instead of a general-purpose register.
36334 \end_layout
36335
36336 \begin_layout Paragraph*
36337 Code generation
36338 \end_layout
36339
36340 \begin_layout Standard
36341 Figure II gives a table of iCode
36342 \begin_inset LatexCommand \index{iCode}
36343
36344 \end_inset
36345
36346  operations supported by the compiler.
36347  The code generation involves translating these operations into corresponding
36348  assembly code for the processor.
36349  This sounds overly simple but that is the essence of code generation.
36350  Some of the iCode operations are generated on a MCU specific manner for
36351  example, the z80 port does not use registers to pass parameters so the
36352  SEND and RECV iCode operations will not be generated, and it also does
36353  not support JUMPTABLES.
36354  
36355 \newline
36356
36357 \end_layout
36358
36359 \begin_layout Standard
36360
36361 \size footnotesize
36362 Figure II 
36363 \begin_inset Tabular
36364 <lyxtabular version="3" rows="39" columns="4">
36365 <features islongtable="true" headBottomDL="true">
36366 <column alignment="block" valignment="top" leftline="true" width="13col%">
36367 <column alignment="left" valignment="top" leftline="true" width="13col%">
36368 <column alignment="block" valignment="top" leftline="true" width="22col%">
36369 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36370 <row topline="true" bottomline="true" endhead="true">
36371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36372 \begin_inset Text
36373
36374 \begin_layout Standard
36375
36376 \series bold
36377 iCode
36378 \series default
36379
36380 \begin_inset LatexCommand \index{iCode}
36381
36382 \end_inset
36383
36384
36385 \end_layout
36386
36387 \end_inset
36388 </cell>
36389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36390 \begin_inset Text
36391
36392 \begin_layout Standard
36393
36394 \series bold
36395 Operands
36396 \end_layout
36397
36398 \end_inset
36399 </cell>
36400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36401 \begin_inset Text
36402
36403 \begin_layout Standard
36404
36405 \series bold
36406 Description
36407 \end_layout
36408
36409 \end_inset
36410 </cell>
36411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36412 \begin_inset Text
36413
36414 \begin_layout Standard
36415
36416 \series bold
36417 C Equivalent
36418 \end_layout
36419
36420 \end_inset
36421 </cell>
36422 </row>
36423 <row topline="true">
36424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36425 \begin_inset Text
36426
36427 \begin_layout Standard
36428
36429 \size footnotesize
36430 '!'
36431 \end_layout
36432
36433 \end_inset
36434 </cell>
36435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36436 \begin_inset Text
36437
36438 \begin_layout Standard
36439
36440 \size footnotesize
36441 IC_LEFT() IC_RESULT()
36442 \end_layout
36443
36444 \end_inset
36445 </cell>
36446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36447 \begin_inset Text
36448
36449 \begin_layout Standard
36450
36451 \size footnotesize
36452 NOT operation 
36453 \end_layout
36454
36455 \end_inset
36456 </cell>
36457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36458 \begin_inset Text
36459
36460 \begin_layout Standard
36461
36462 \size footnotesize
36463 IC_RESULT = ! IC_LEFT;
36464 \end_layout
36465
36466 \end_inset
36467 </cell>
36468 </row>
36469 <row topline="true">
36470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36471 \begin_inset Text
36472
36473 \begin_layout Standard
36474
36475 \size footnotesize
36476 '~'
36477 \end_layout
36478
36479 \end_inset
36480 </cell>
36481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36482 \begin_inset Text
36483
36484 \begin_layout Standard
36485
36486 \size footnotesize
36487 IC_LEFT() IC_RESULT()
36488 \end_layout
36489
36490 \end_inset
36491 </cell>
36492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36493 \begin_inset Text
36494
36495 \begin_layout Standard
36496
36497 \size footnotesize
36498 Bitwise complement of 
36499 \end_layout
36500
36501 \end_inset
36502 </cell>
36503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36504 \begin_inset Text
36505
36506 \begin_layout Standard
36507
36508 \size footnotesize
36509 IC_RESULT = ~IC_LEFT;
36510 \end_layout
36511
36512 \end_inset
36513 </cell>
36514 </row>
36515 <row topline="true">
36516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36517 \begin_inset Text
36518
36519 \begin_layout Standard
36520
36521 \size footnotesize
36522 RRC
36523 \end_layout
36524
36525 \end_inset
36526 </cell>
36527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36528 \begin_inset Text
36529
36530 \begin_layout Standard
36531
36532 \size footnotesize
36533 IC_LEFT() IC_RESULT()
36534 \end_layout
36535
36536 \end_inset
36537 </cell>
36538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36539 \begin_inset Text
36540
36541 \begin_layout Standard
36542
36543 \size footnotesize
36544 Rotate right with carry
36545 \end_layout
36546
36547 \end_inset
36548 </cell>
36549 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36550 \begin_inset Text
36551
36552 \begin_layout Standard
36553
36554 \size footnotesize
36555 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
36556 \end_layout
36557
36558 \end_inset
36559 </cell>
36560 </row>
36561 <row topline="true">
36562 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36563 \begin_inset Text
36564
36565 \begin_layout Standard
36566
36567 \size footnotesize
36568 RLC
36569 \end_layout
36570
36571 \end_inset
36572 </cell>
36573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36574 \begin_inset Text
36575
36576 \begin_layout Standard
36577
36578 \size footnotesize
36579 IC_LEFT() IC_RESULT()
36580 \end_layout
36581
36582 \end_inset
36583 </cell>
36584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36585 \begin_inset Text
36586
36587 \begin_layout Standard
36588
36589 \size footnotesize
36590 Rotate left with carry
36591 \end_layout
36592
36593 \end_inset
36594 </cell>
36595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36596 \begin_inset Text
36597
36598 \begin_layout Standard
36599
36600 \size footnotesize
36601 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
36602 \end_layout
36603
36604 \end_inset
36605 </cell>
36606 </row>
36607 <row topline="true">
36608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36609 \begin_inset Text
36610
36611 \begin_layout Standard
36612
36613 \size footnotesize
36614 GETHBIT
36615 \end_layout
36616
36617 \end_inset
36618 </cell>
36619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36620 \begin_inset Text
36621
36622 \begin_layout Standard
36623
36624 \size footnotesize
36625 IC_LEFT() IC_RESULT()
36626 \end_layout
36627
36628 \end_inset
36629 </cell>
36630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36631 \begin_inset Text
36632
36633 \begin_layout Standard
36634
36635 \size footnotesize
36636 Get the highest order bit of IC_LEFT
36637 \end_layout
36638
36639 \end_inset
36640 </cell>
36641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36642 \begin_inset Text
36643
36644 \begin_layout Standard
36645
36646 \size footnotesize
36647 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
36648 \end_layout
36649
36650 \end_inset
36651 </cell>
36652 </row>
36653 <row topline="true">
36654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36655 \begin_inset Text
36656
36657 \begin_layout Standard
36658
36659 \size footnotesize
36660 UNARYMINUS
36661 \end_layout
36662
36663 \end_inset
36664 </cell>
36665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36666 \begin_inset Text
36667
36668 \begin_layout Standard
36669
36670 \size footnotesize
36671 IC_LEFT() IC_RESULT()
36672 \end_layout
36673
36674 \end_inset
36675 </cell>
36676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36677 \begin_inset Text
36678
36679 \begin_layout Standard
36680
36681 \size footnotesize
36682 Unary minus
36683 \end_layout
36684
36685 \end_inset
36686 </cell>
36687 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36688 \begin_inset Text
36689
36690 \begin_layout Standard
36691
36692 \size footnotesize
36693 IC_RESULT = - IC_LEFT;
36694 \end_layout
36695
36696 \end_inset
36697 </cell>
36698 </row>
36699 <row topline="true">
36700 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36701 \begin_inset Text
36702
36703 \begin_layout Standard
36704
36705 \size footnotesize
36706 IPUSH
36707 \end_layout
36708
36709 \end_inset
36710 </cell>
36711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36712 \begin_inset Text
36713
36714 \begin_layout Standard
36715
36716 \size footnotesize
36717 IC_LEFT()
36718 \end_layout
36719
36720 \end_inset
36721 </cell>
36722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36723 \begin_inset Text
36724
36725 \begin_layout Standard
36726
36727 \size footnotesize
36728 Push the operand into stack
36729 \end_layout
36730
36731 \end_inset
36732 </cell>
36733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36734 \begin_inset Text
36735
36736 \begin_layout Standard
36737
36738 \size footnotesize
36739 NONE
36740 \end_layout
36741
36742 \end_inset
36743 </cell>
36744 </row>
36745 <row topline="true">
36746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36747 \begin_inset Text
36748
36749 \begin_layout Standard
36750
36751 \size footnotesize
36752 IPOP
36753 \end_layout
36754
36755 \end_inset
36756 </cell>
36757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36758 \begin_inset Text
36759
36760 \begin_layout Standard
36761
36762 \size footnotesize
36763 IC_LEFT()
36764 \end_layout
36765
36766 \end_inset
36767 </cell>
36768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36769 \begin_inset Text
36770
36771 \begin_layout Standard
36772
36773 \size footnotesize
36774 Pop the operand from the stack 
36775 \end_layout
36776
36777 \end_inset
36778 </cell>
36779 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36780 \begin_inset Text
36781
36782 \begin_layout Standard
36783
36784 \size footnotesize
36785 NONE
36786 \end_layout
36787
36788 \end_inset
36789 </cell>
36790 </row>
36791 <row topline="true">
36792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36793 \begin_inset Text
36794
36795 \begin_layout Standard
36796
36797 \size footnotesize
36798 CALL
36799 \end_layout
36800
36801 \end_inset
36802 </cell>
36803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36804 \begin_inset Text
36805
36806 \begin_layout Standard
36807
36808 \size footnotesize
36809 IC_LEFT() IC_RESULT()
36810 \end_layout
36811
36812 \end_inset
36813 </cell>
36814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36815 \begin_inset Text
36816
36817 \begin_layout Standard
36818
36819 \size footnotesize
36820 Call the function represented by IC_LEFT 
36821 \end_layout
36822
36823 \end_inset
36824 </cell>
36825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36826 \begin_inset Text
36827
36828 \begin_layout Standard
36829
36830 \size footnotesize
36831 IC_RESULT = IC_LEFT();
36832 \end_layout
36833
36834 \end_inset
36835 </cell>
36836 </row>
36837 <row topline="true">
36838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36839 \begin_inset Text
36840
36841 \begin_layout Standard
36842
36843 \size footnotesize
36844 PCALL
36845 \end_layout
36846
36847 \end_inset
36848 </cell>
36849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36850 \begin_inset Text
36851
36852 \begin_layout Standard
36853
36854 \size footnotesize
36855 IC_LEFT() IC_RESULT()
36856 \end_layout
36857
36858 \end_inset
36859 </cell>
36860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36861 \begin_inset Text
36862
36863 \begin_layout Standard
36864
36865 \size footnotesize
36866 Call via function pointer
36867 \end_layout
36868
36869 \end_inset
36870 </cell>
36871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36872 \begin_inset Text
36873
36874 \begin_layout Standard
36875
36876 \size footnotesize
36877 IC_RESULT = (*IC_LEFT)();
36878 \end_layout
36879
36880 \end_inset
36881 </cell>
36882 </row>
36883 <row topline="true">
36884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36885 \begin_inset Text
36886
36887 \begin_layout Standard
36888
36889 \size footnotesize
36890 RETURN
36891 \end_layout
36892
36893 \end_inset
36894 </cell>
36895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36896 \begin_inset Text
36897
36898 \begin_layout Standard
36899
36900 \size footnotesize
36901 IC_LEFT()
36902 \end_layout
36903
36904 \end_inset
36905 </cell>
36906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36907 \begin_inset Text
36908
36909 \begin_layout Standard
36910
36911 \size footnotesize
36912 Return the value in operand IC_LEFT 
36913 \end_layout
36914
36915 \end_inset
36916 </cell>
36917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36918 \begin_inset Text
36919
36920 \begin_layout Standard
36921
36922 \size footnotesize
36923 return IC_LEFT;
36924 \end_layout
36925
36926 \end_inset
36927 </cell>
36928 </row>
36929 <row topline="true">
36930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36931 \begin_inset Text
36932
36933 \begin_layout Standard
36934
36935 \size footnotesize
36936 LABEL
36937 \end_layout
36938
36939 \end_inset
36940 </cell>
36941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36942 \begin_inset Text
36943
36944 \begin_layout Standard
36945
36946 \size footnotesize
36947 IC_LABEL() 
36948 \end_layout
36949
36950 \end_inset
36951 </cell>
36952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36953 \begin_inset Text
36954
36955 \begin_layout Standard
36956
36957 \size footnotesize
36958 Label
36959 \end_layout
36960
36961 \end_inset
36962 </cell>
36963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36964 \begin_inset Text
36965
36966 \begin_layout Standard
36967
36968 \size footnotesize
36969 IC_LABEL:
36970 \end_layout
36971
36972 \end_inset
36973 </cell>
36974 </row>
36975 <row topline="true">
36976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36977 \begin_inset Text
36978
36979 \begin_layout Standard
36980
36981 \size footnotesize
36982 GOTO
36983 \end_layout
36984
36985 \end_inset
36986 </cell>
36987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36988 \begin_inset Text
36989
36990 \begin_layout Standard
36991
36992 \size footnotesize
36993 IC_LABEL() 
36994 \end_layout
36995
36996 \end_inset
36997 </cell>
36998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36999 \begin_inset Text
37000
37001 \begin_layout Standard
37002
37003 \size footnotesize
37004 Goto label
37005 \end_layout
37006
37007 \end_inset
37008 </cell>
37009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37010 \begin_inset Text
37011
37012 \begin_layout Standard
37013
37014 \size footnotesize
37015 goto IC_LABEL();
37016 \end_layout
37017
37018 \end_inset
37019 </cell>
37020 </row>
37021 <row topline="true">
37022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37023 \begin_inset Text
37024
37025 \begin_layout Standard
37026
37027 \size footnotesize
37028 '+'
37029 \end_layout
37030
37031 \end_inset
37032 </cell>
37033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37034 \begin_inset Text
37035
37036 \begin_layout Standard
37037
37038 \size footnotesize
37039 IC_LEFT() IC_RIGHT() IC_RESULT()
37040 \end_layout
37041
37042 \end_inset
37043 </cell>
37044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37045 \begin_inset Text
37046
37047 \begin_layout Standard
37048
37049 \size footnotesize
37050 Addition
37051 \end_layout
37052
37053 \end_inset
37054 </cell>
37055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37056 \begin_inset Text
37057
37058 \begin_layout Standard
37059
37060 \size footnotesize
37061 IC_RESULT = IC_LEFT + IC_RIGHT
37062 \end_layout
37063
37064 \end_inset
37065 </cell>
37066 </row>
37067 <row topline="true">
37068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37069 \begin_inset Text
37070
37071 \begin_layout Standard
37072
37073 \size footnotesize
37074 '-'
37075 \end_layout
37076
37077 \end_inset
37078 </cell>
37079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37080 \begin_inset Text
37081
37082 \begin_layout Standard
37083
37084 \size footnotesize
37085 IC_LEFT() IC_RIGHT() IC_RESULT()
37086 \end_layout
37087
37088 \end_inset
37089 </cell>
37090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37091 \begin_inset Text
37092
37093 \begin_layout Standard
37094
37095 \size footnotesize
37096 Subtraction
37097 \end_layout
37098
37099 \end_inset
37100 </cell>
37101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37102 \begin_inset Text
37103
37104 \begin_layout Standard
37105
37106 \size footnotesize
37107 IC_RESULT = IC_LEFT - IC_RIGHT 
37108 \end_layout
37109
37110 \end_inset
37111 </cell>
37112 </row>
37113 <row topline="true">
37114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37115 \begin_inset Text
37116
37117 \begin_layout Standard
37118
37119 \size footnotesize
37120 '*'
37121 \end_layout
37122
37123 \end_inset
37124 </cell>
37125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37126 \begin_inset Text
37127
37128 \begin_layout Standard
37129
37130 \size footnotesize
37131 IC_LEFT() IC_RIGHT() IC_RESULT()
37132 \end_layout
37133
37134 \end_inset
37135 </cell>
37136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37137 \begin_inset Text
37138
37139 \begin_layout Standard
37140
37141 \size footnotesize
37142 Multiplication 
37143 \end_layout
37144
37145 \end_inset
37146 </cell>
37147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37148 \begin_inset Text
37149
37150 \begin_layout Standard
37151
37152 \size footnotesize
37153 IC_RESULT = IC_LEFT * IC_RIGHT;
37154 \end_layout
37155
37156 \end_inset
37157 </cell>
37158 </row>
37159 <row topline="true">
37160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37161 \begin_inset Text
37162
37163 \begin_layout Standard
37164
37165 \size footnotesize
37166 '/'
37167 \end_layout
37168
37169 \end_inset
37170 </cell>
37171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37172 \begin_inset Text
37173
37174 \begin_layout Standard
37175
37176 \size footnotesize
37177 IC_LEFT() IC_RIGHT() IC_RESULT()
37178 \end_layout
37179
37180 \end_inset
37181 </cell>
37182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37183 \begin_inset Text
37184
37185 \begin_layout Standard
37186
37187 \size footnotesize
37188 Division
37189 \end_layout
37190
37191 \end_inset
37192 </cell>
37193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37194 \begin_inset Text
37195
37196 \begin_layout Standard
37197
37198 \size footnotesize
37199 IC_RESULT = IC_LEFT / IC_RIGHT;
37200 \end_layout
37201
37202 \end_inset
37203 </cell>
37204 </row>
37205 <row topline="true">
37206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37207 \begin_inset Text
37208
37209 \begin_layout Standard
37210
37211 \size footnotesize
37212 '%'
37213 \end_layout
37214
37215 \end_inset
37216 </cell>
37217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37218 \begin_inset Text
37219
37220 \begin_layout Standard
37221
37222 \size footnotesize
37223 IC_LEFT() IC_RIGHT() IC_RESULT()
37224 \end_layout
37225
37226 \end_inset
37227 </cell>
37228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37229 \begin_inset Text
37230
37231 \begin_layout Standard
37232
37233 \size footnotesize
37234 Modulus
37235 \end_layout
37236
37237 \end_inset
37238 </cell>
37239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37240 \begin_inset Text
37241
37242 \begin_layout Standard
37243
37244 \size footnotesize
37245 IC_RESULT = IC_LEFT % IC_RIGHT;
37246 \end_layout
37247
37248 \end_inset
37249 </cell>
37250 </row>
37251 <row topline="true">
37252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37253 \begin_inset Text
37254
37255 \begin_layout Standard
37256
37257 \size footnotesize
37258 '<'
37259 \end_layout
37260
37261 \end_inset
37262 </cell>
37263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37264 \begin_inset Text
37265
37266 \begin_layout Standard
37267
37268 \size footnotesize
37269 IC_LEFT() IC_RIGHT() IC_RESULT()
37270 \end_layout
37271
37272 \end_inset
37273 </cell>
37274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37275 \begin_inset Text
37276
37277 \begin_layout Standard
37278
37279 \size footnotesize
37280 Less than
37281 \end_layout
37282
37283 \end_inset
37284 </cell>
37285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37286 \begin_inset Text
37287
37288 \begin_layout Standard
37289
37290 \size footnotesize
37291 IC_RESULT = IC_LEFT < IC_RIGHT;
37292 \end_layout
37293
37294 \end_inset
37295 </cell>
37296 </row>
37297 <row topline="true">
37298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37299 \begin_inset Text
37300
37301 \begin_layout Standard
37302
37303 \size footnotesize
37304 '>'
37305 \end_layout
37306
37307 \end_inset
37308 </cell>
37309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37310 \begin_inset Text
37311
37312 \begin_layout Standard
37313
37314 \size footnotesize
37315 IC_LEFT() IC_RIGHT() IC_RESULT()
37316 \end_layout
37317
37318 \end_inset
37319 </cell>
37320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37321 \begin_inset Text
37322
37323 \begin_layout Standard
37324
37325 \size footnotesize
37326 Greater than 
37327 \end_layout
37328
37329 \end_inset
37330 </cell>
37331 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37332 \begin_inset Text
37333
37334 \begin_layout Standard
37335
37336 \size footnotesize
37337 IC_RESULT = IC_LEFT > IC_RIGHT;
37338 \end_layout
37339
37340 \end_inset
37341 </cell>
37342 </row>
37343 <row topline="true">
37344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37345 \begin_inset Text
37346
37347 \begin_layout Standard
37348
37349 \size footnotesize
37350 EQ_OP
37351 \end_layout
37352
37353 \end_inset
37354 </cell>
37355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37356 \begin_inset Text
37357
37358 \begin_layout Standard
37359
37360 \size footnotesize
37361 IC_LEFT() IC_RIGHT() IC_RESULT()
37362 \end_layout
37363
37364 \end_inset
37365 </cell>
37366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37367 \begin_inset Text
37368
37369 \begin_layout Standard
37370
37371 \size footnotesize
37372 Equal to 
37373 \end_layout
37374
37375 \end_inset
37376 </cell>
37377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37378 \begin_inset Text
37379
37380 \begin_layout Standard
37381
37382 \size footnotesize
37383 IC_RESULT = IC_LEFT == IC_RIGHT;
37384 \end_layout
37385
37386 \end_inset
37387 </cell>
37388 </row>
37389 <row topline="true">
37390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37391 \begin_inset Text
37392
37393 \begin_layout Standard
37394
37395 \size footnotesize
37396 AND_OP
37397 \end_layout
37398
37399 \end_inset
37400 </cell>
37401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37402 \begin_inset Text
37403
37404 \begin_layout Standard
37405
37406 \size footnotesize
37407 IC_LEFT() IC_RIGHT() IC_RESULT() 
37408 \end_layout
37409
37410 \end_inset
37411 </cell>
37412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37413 \begin_inset Text
37414
37415 \begin_layout Standard
37416
37417 \size footnotesize
37418 Logical and operation
37419 \end_layout
37420
37421 \end_inset
37422 </cell>
37423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37424 \begin_inset Text
37425
37426 \begin_layout Standard
37427
37428 \size footnotesize
37429 IC_RESULT = IC_LEFT && IC_RIGHT; 
37430 \end_layout
37431
37432 \end_inset
37433 </cell>
37434 </row>
37435 <row topline="true">
37436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37437 \begin_inset Text
37438
37439 \begin_layout Standard
37440
37441 \size footnotesize
37442 OR_OP
37443 \end_layout
37444
37445 \end_inset
37446 </cell>
37447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37448 \begin_inset Text
37449
37450 \begin_layout Standard
37451
37452 \size footnotesize
37453 IC_LEFT() IC_RIGHT() IC_RESULT() 
37454 \end_layout
37455
37456 \end_inset
37457 </cell>
37458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37459 \begin_inset Text
37460
37461 \begin_layout Standard
37462
37463 \size footnotesize
37464 Logical or operation 
37465 \end_layout
37466
37467 \end_inset
37468 </cell>
37469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37470 \begin_inset Text
37471
37472 \begin_layout Standard
37473
37474 \size footnotesize
37475 IC_RESULT = IC_LEFT || IC_RIGHT; 
37476 \end_layout
37477
37478 \end_inset
37479 </cell>
37480 </row>
37481 <row topline="true">
37482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37483 \begin_inset Text
37484
37485 \begin_layout Standard
37486
37487 \size footnotesize
37488 '^'
37489 \end_layout
37490
37491 \end_inset
37492 </cell>
37493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37494 \begin_inset Text
37495
37496 \begin_layout Standard
37497
37498 \size footnotesize
37499 IC_LEFT() IC_RIGHT() IC_RESULT() 
37500 \end_layout
37501
37502 \end_inset
37503 </cell>
37504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37505 \begin_inset Text
37506
37507 \begin_layout Standard
37508
37509 \size footnotesize
37510 Exclusive OR
37511 \end_layout
37512
37513 \end_inset
37514 </cell>
37515 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37516 \begin_inset Text
37517
37518 \begin_layout Standard
37519
37520 \size footnotesize
37521 IC_RESULT = IC_LEFT ^ IC_RIGHT;
37522 \end_layout
37523
37524 \end_inset
37525 </cell>
37526 </row>
37527 <row topline="true">
37528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37529 \begin_inset Text
37530
37531 \begin_layout Standard
37532
37533 \size footnotesize
37534 '|'
37535 \end_layout
37536
37537 \end_inset
37538 </cell>
37539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37540 \begin_inset Text
37541
37542 \begin_layout Standard
37543
37544 \size footnotesize
37545 IC_LEFT() IC_RIGHT() IC_RESULT() 
37546 \end_layout
37547
37548 \end_inset
37549 </cell>
37550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37551 \begin_inset Text
37552
37553 \begin_layout Standard
37554
37555 \size footnotesize
37556 Bitwise OR 
37557 \end_layout
37558
37559 \end_inset
37560 </cell>
37561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37562 \begin_inset Text
37563
37564 \begin_layout Standard
37565
37566 \size footnotesize
37567 IC_RESULT = IC_LEFT | IC_RIGHT;
37568 \end_layout
37569
37570 \end_inset
37571 </cell>
37572 </row>
37573 <row topline="true">
37574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37575 \begin_inset Text
37576
37577 \begin_layout Standard
37578
37579 \size footnotesize
37580 BITWISEAND
37581 \end_layout
37582
37583 \end_inset
37584 </cell>
37585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37586 \begin_inset Text
37587
37588 \begin_layout Standard
37589
37590 \size footnotesize
37591 IC_LEFT() IC_RIGHT() IC_RESULT()
37592 \end_layout
37593
37594 \end_inset
37595 </cell>
37596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37597 \begin_inset Text
37598
37599 \begin_layout Standard
37600
37601 \size footnotesize
37602 Bitwise AND 
37603 \end_layout
37604
37605 \end_inset
37606 </cell>
37607 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37608 \begin_inset Text
37609
37610 \begin_layout Standard
37611
37612 \size footnotesize
37613 IC_RESULT = IC_LEFT & IC_RIGHT;
37614 \end_layout
37615
37616 \end_inset
37617 </cell>
37618 </row>
37619 <row topline="true">
37620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37621 \begin_inset Text
37622
37623 \begin_layout Standard
37624
37625 \size footnotesize
37626 LEFT_OP
37627 \end_layout
37628
37629 \end_inset
37630 </cell>
37631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37632 \begin_inset Text
37633
37634 \begin_layout Standard
37635
37636 \size footnotesize
37637 IC_LEFT() IC_RIGHT() IC_RESULT()
37638 \end_layout
37639
37640 \end_inset
37641 </cell>
37642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37643 \begin_inset Text
37644
37645 \begin_layout Standard
37646
37647 \size footnotesize
37648 Left shift 
37649 \end_layout
37650
37651 \end_inset
37652 </cell>
37653 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37654 \begin_inset Text
37655
37656 \begin_layout Standard
37657
37658 \size footnotesize
37659 IC_RESULT = IC_LEFT << IC_RIGHT 
37660 \end_layout
37661
37662 \end_inset
37663 </cell>
37664 </row>
37665 <row topline="true">
37666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37667 \begin_inset Text
37668
37669 \begin_layout Standard
37670
37671 \size footnotesize
37672 RIGHT_OP
37673 \end_layout
37674
37675 \end_inset
37676 </cell>
37677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37678 \begin_inset Text
37679
37680 \begin_layout Standard
37681
37682 \size footnotesize
37683 IC_LEFT() IC_RIGHT() IC_RESULT()
37684 \end_layout
37685
37686 \end_inset
37687 </cell>
37688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37689 \begin_inset Text
37690
37691 \begin_layout Standard
37692
37693 \size footnotesize
37694 Right shift
37695 \end_layout
37696
37697 \end_inset
37698 </cell>
37699 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37700 \begin_inset Text
37701
37702 \begin_layout Standard
37703
37704 \size footnotesize
37705 IC_RESULT = IC_LEFT >> IC_RIGHT 
37706 \end_layout
37707
37708 \end_inset
37709 </cell>
37710 </row>
37711 <row topline="true">
37712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37713 \begin_inset Text
37714
37715 \begin_layout Standard
37716
37717 \size footnotesize
37718 GET_VALUE_
37719 \newline
37720 AT_ ADDRESS
37721 \end_layout
37722
37723 \end_inset
37724 </cell>
37725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37726 \begin_inset Text
37727
37728 \begin_layout Standard
37729
37730 \size footnotesize
37731 IC_LEFT() IC_RESULT()
37732 \end_layout
37733
37734 \end_inset
37735 </cell>
37736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37737 \begin_inset Text
37738
37739 \begin_layout Standard
37740
37741 \size footnotesize
37742 Indirect fetch 
37743 \end_layout
37744
37745 \end_inset
37746 </cell>
37747 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37748 \begin_inset Text
37749
37750 \begin_layout Standard
37751
37752 \size footnotesize
37753 IC_RESULT = (*IC_LEFT);
37754 \end_layout
37755
37756 \end_inset
37757 </cell>
37758 </row>
37759 <row topline="true">
37760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37761 \begin_inset Text
37762
37763 \begin_layout Standard
37764
37765 \size footnotesize
37766 POINTER_SET
37767 \end_layout
37768
37769 \end_inset
37770 </cell>
37771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37772 \begin_inset Text
37773
37774 \begin_layout Standard
37775
37776 \size footnotesize
37777 IC_RIGHT() IC_RESULT() 
37778 \end_layout
37779
37780 \end_inset
37781 </cell>
37782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37783 \begin_inset Text
37784
37785 \begin_layout Standard
37786
37787 \size footnotesize
37788 Indirect set
37789 \end_layout
37790
37791 \end_inset
37792 </cell>
37793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37794 \begin_inset Text
37795
37796 \begin_layout Standard
37797
37798 \size footnotesize
37799 (*IC_RESULT) = IC_RIGHT;
37800 \end_layout
37801
37802 \end_inset
37803 </cell>
37804 </row>
37805 <row topline="true">
37806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37807 \begin_inset Text
37808
37809 \begin_layout Standard
37810
37811 \size footnotesize
37812 '='
37813 \end_layout
37814
37815 \end_inset
37816 </cell>
37817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37818 \begin_inset Text
37819
37820 \begin_layout Standard
37821
37822 \size footnotesize
37823 IC_RIGHT() IC_RESULT()
37824 \end_layout
37825
37826 \end_inset
37827 </cell>
37828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37829 \begin_inset Text
37830
37831 \begin_layout Standard
37832
37833 \size footnotesize
37834 Assignment
37835 \end_layout
37836
37837 \end_inset
37838 </cell>
37839 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37840 \begin_inset Text
37841
37842 \begin_layout Standard
37843
37844 \size footnotesize
37845 IC_RESULT = IC_RIGHT;
37846 \end_layout
37847
37848 \end_inset
37849 </cell>
37850 </row>
37851 <row topline="true">
37852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37853 \begin_inset Text
37854
37855 \begin_layout Standard
37856
37857 \size footnotesize
37858 IFX
37859 \end_layout
37860
37861 \end_inset
37862 </cell>
37863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37864 \begin_inset Text
37865
37866 \begin_layout Standard
37867
37868 \size footnotesize
37869 IC_COND IC_TRUE IC_LABEL
37870 \end_layout
37871
37872 \end_inset
37873 </cell>
37874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37875 \begin_inset Text
37876
37877 \begin_layout Standard
37878
37879 \size footnotesize
37880 Conditional jump.
37881  If true label is present then jump to true label if condition is true else
37882  jump to false label if condition is false 
37883 \end_layout
37884
37885 \end_inset
37886 </cell>
37887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37888 \begin_inset Text
37889
37890 \begin_layout Standard
37891
37892 \size footnotesize
37893 if (IC_COND) goto IC_TRUE; 
37894 \newline
37895 \InsetSpace ~
37896 \InsetSpace ~
37897 Or 
37898 \newline
37899 If (!IC_COND) goto IC_FALSE;
37900 \end_layout
37901
37902 \end_inset
37903 </cell>
37904 </row>
37905 <row topline="true">
37906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37907 \begin_inset Text
37908
37909 \begin_layout Standard
37910
37911 \size footnotesize
37912 ADDRESS_OF
37913 \end_layout
37914
37915 \end_inset
37916 </cell>
37917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37918 \begin_inset Text
37919
37920 \begin_layout Standard
37921
37922 \size footnotesize
37923 IC_LEFT() IC_RESULT()
37924 \end_layout
37925
37926 \end_inset
37927 </cell>
37928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37929 \begin_inset Text
37930
37931 \begin_layout Standard
37932
37933 \size footnotesize
37934 Address of 
37935 \end_layout
37936
37937 \end_inset
37938 </cell>
37939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37940 \begin_inset Text
37941
37942 \begin_layout Standard
37943
37944 \size footnotesize
37945 IC_RESULT = &IC_LEFT();
37946 \end_layout
37947
37948 \end_inset
37949 </cell>
37950 </row>
37951 <row topline="true">
37952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37953 \begin_inset Text
37954
37955 \begin_layout Standard
37956
37957 \size footnotesize
37958 JUMPTABLE
37959 \end_layout
37960
37961 \end_inset
37962 </cell>
37963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37964 \begin_inset Text
37965
37966 \begin_layout Standard
37967
37968 \size footnotesize
37969 IC_JTCOND IC_JTLABELS
37970 \end_layout
37971
37972 \end_inset
37973 </cell>
37974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37975 \begin_inset Text
37976
37977 \begin_layout Standard
37978
37979 \size footnotesize
37980 Jump to list of labels depending on the value of JTCOND
37981 \end_layout
37982
37983 \end_inset
37984 </cell>
37985 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37986 \begin_inset Text
37987
37988 \begin_layout Standard
37989
37990 \size footnotesize
37991 Switch statement
37992 \end_layout
37993
37994 \end_inset
37995 </cell>
37996 </row>
37997 <row topline="true">
37998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37999 \begin_inset Text
38000
38001 \begin_layout Standard
38002
38003 \size footnotesize
38004 CAST
38005 \end_layout
38006
38007 \end_inset
38008 </cell>
38009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38010 \begin_inset Text
38011
38012 \begin_layout Standard
38013
38014 \size footnotesize
38015 IC_RIGHT() IC_LEFT() IC_RESULT()
38016 \end_layout
38017
38018 \end_inset
38019 </cell>
38020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38021 \begin_inset Text
38022
38023 \begin_layout Standard
38024
38025 \size footnotesize
38026 Cast types 
38027 \end_layout
38028
38029 \end_inset
38030 </cell>
38031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38032 \begin_inset Text
38033
38034 \begin_layout Standard
38035
38036 \size footnotesize
38037 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
38038 \end_layout
38039
38040 \end_inset
38041 </cell>
38042 </row>
38043 <row topline="true">
38044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38045 \begin_inset Text
38046
38047 \begin_layout Standard
38048
38049 \size footnotesize
38050 SEND
38051 \end_layout
38052
38053 \end_inset
38054 </cell>
38055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38056 \begin_inset Text
38057
38058 \begin_layout Standard
38059
38060 \size footnotesize
38061 IC_LEFT()
38062 \end_layout
38063
38064 \end_inset
38065 </cell>
38066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38067 \begin_inset Text
38068
38069 \begin_layout Standard
38070
38071 \size footnotesize
38072 This is used for passing parameters in registers; 
38073 \newline
38074 move IC_LEFT to the next
38075  available parameter register.
38076 \end_layout
38077
38078 \end_inset
38079 </cell>
38080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38081 \begin_inset Text
38082
38083 \begin_layout Standard
38084
38085 \size footnotesize
38086 None
38087 \end_layout
38088
38089 \end_inset
38090 </cell>
38091 </row>
38092 <row topline="true">
38093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38094 \begin_inset Text
38095
38096 \begin_layout Standard
38097
38098 \size footnotesize
38099 RECV
38100 \end_layout
38101
38102 \end_inset
38103 </cell>
38104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38105 \begin_inset Text
38106
38107 \begin_layout Standard
38108
38109 \size footnotesize
38110 IC_RESULT()
38111 \end_layout
38112
38113 \end_inset
38114 </cell>
38115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38116 \begin_inset Text
38117
38118 \begin_layout Standard
38119
38120 \size footnotesize
38121 This is used for receiving parameters passed in registers;
38122 \newline
38123 Move the values
38124  in the next parameter register to IC_RESULT 
38125 \end_layout
38126
38127 \end_inset
38128 </cell>
38129 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38130 \begin_inset Text
38131
38132 \begin_layout Standard
38133
38134 \size footnotesize
38135 None
38136 \end_layout
38137
38138 \end_inset
38139 </cell>
38140 </row>
38141 <row topline="true" bottomline="true">
38142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38143 \begin_inset Text
38144
38145 \begin_layout Standard
38146
38147 \shape slanted
38148 \size footnotesize
38149 (some more have been added)
38150 \end_layout
38151
38152 \end_inset
38153 </cell>
38154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38155 \begin_inset Text
38156
38157 \begin_layout Standard
38158
38159 \end_layout
38160
38161 \end_inset
38162 </cell>
38163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
38164 \begin_inset Text
38165
38166 \begin_layout Standard
38167
38168 \end_layout
38169
38170 \end_inset
38171 </cell>
38172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
38173 \begin_inset Text
38174
38175 \begin_layout Standard
38176
38177 \shape slanted
38178 \size footnotesize
38179 see f.e.
38180  
38181 \family typewriter
38182 gen51Code()
38183 \family default
38184  in 
38185 \family typewriter
38186 src/mcs51/gen.c
38187 \end_layout
38188
38189 \end_inset
38190 </cell>
38191 </row>
38192 </lyxtabular>
38193
38194 \end_inset
38195
38196
38197 \end_layout
38198
38199 \begin_layout Standard
38200 \begin_inset Note Note
38201 status collapsed
38202
38203 \begin_layout Standard
38204 In the original article Figure II was announced to be downloadable on 
38205 \shape italic
38206 Circuit Cellar
38207 \shape default
38208 's web site.
38209  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
38210 \end_layout
38211
38212 \end_inset
38213
38214
38215 \end_layout
38216
38217 \begin_layout Paragraph*
38218 ICode Example
38219 \begin_inset LatexCommand \index{iCode}
38220
38221 \end_inset
38222
38223
38224 \end_layout
38225
38226 \begin_layout Standard
38227 This section shows some details of iCode.
38228  The example C code does not do anything useful; it is used as an example
38229  to illustrate the intermediate code generated by the compiler.
38230 \end_layout
38231
38232 \begin_layout Verse
38233
38234 \family typewriter
38235 1.\InsetSpace ~
38236 xdata int * p;
38237 \newline
38238 2.\InsetSpace ~
38239 int gint;
38240 \newline
38241 3.\InsetSpace ~
38242 /* This function does nothing useful.
38243  It is used
38244 \newline
38245 4.\InsetSpace ~
38246 \InsetSpace ~
38247 \InsetSpace ~
38248 \InsetSpace ~
38249 for the purpose of explaining iCode */
38250 \newline
38251 5.\InsetSpace ~
38252 short function (data
38253  int *x)
38254 \newline
38255 6.\InsetSpace ~
38256 {
38257 \newline
38258 7.\InsetSpace ~
38259 \InsetSpace ~
38260 \InsetSpace ~
38261 short i=10; \InsetSpace ~
38262 \InsetSpace ~
38263 /* dead initialization eliminated */
38264 \newline
38265 8.\InsetSpace ~
38266 \InsetSpace ~
38267 \InsetSpace ~
38268 short sum=10;
38269  /* dead initialization eliminated */
38270 \newline
38271 9.\InsetSpace ~
38272 \InsetSpace ~
38273 \InsetSpace ~
38274 short mul;
38275 \newline
38276 10.\InsetSpace ~
38277 \InsetSpace ~
38278 int j ;
38279 \newline
38280 11.\InsetSpace ~
38281 \InsetSpace ~
38282 while (*x) *x++
38283  = *p++; 
38284 \newline
38285 12.\InsetSpace ~
38286 \InsetSpace ~
38287 \InsetSpace ~
38288 \InsetSpace ~
38289 sum = 0 ; 
38290 \newline
38291 13.\InsetSpace ~
38292 \InsetSpace ~
38293 mul = 0;
38294 \newline
38295 14.\InsetSpace ~
38296 \InsetSpace ~
38297 /* compiler detects i,j to be induction
38298  variables */
38299 \newline
38300 15.\InsetSpace ~
38301 \InsetSpace ~
38302 for (i = 0, j = 10 ; i < 10 ; i++, j
38303 \family default
38304 -
38305 \begin_inset ERT
38306 status collapsed
38307
38308 \begin_layout Standard
38309
38310
38311 \backslash
38312 /
38313 \end_layout
38314
38315 \end_inset
38316
38317 -
38318 \family typewriter
38319 ) {
38320 \newline
38321 16.\InsetSpace ~
38322 \InsetSpace ~
38323 \InsetSpace ~
38324 \InsetSpace ~
38325 sum += i;
38326 \newline
38327 17.\InsetSpace ~
38328 \InsetSpace ~
38329 \InsetSpace ~
38330 \InsetSpace ~
38331 mul += i * 3; \InsetSpace ~
38332 \InsetSpace ~
38333 /* this multiplication remains */
38334 \newline
38335 18.\InsetSpace ~
38336 \InsetSpace ~
38337 \InsetSpace ~
38338 \InsetSpace ~
38339 gint +=
38340  j * 3;\InsetSpace ~
38341 \InsetSpace ~
38342 /* this multiplication changed to addition */
38343 \newline
38344 19.\InsetSpace ~
38345 \InsetSpace ~
38346 }
38347 \newline
38348 20.\InsetSpace ~
38349 \InsetSpace ~
38350 return sum+mul;
38351 \newline
38352 21.\InsetSpace ~
38353 }
38354 \end_layout
38355
38356 \begin_layout Standard
38357 In addition to the operands each iCode contains information about the filename
38358  and line it corresponds to in the source file.
38359  The first field in the listing should be interpreted as follows:
38360 \newline
38361
38362 \shape italic
38363 \size footnotesize
38364 Filename(linenumber: iCode Execution sequence number : ICode hash table
38365  key : loop depth of the iCode).
38366 \shape default
38367 \size default
38368
38369 \newline
38370 Then follows the human readable form of the ICode operation.
38371  Each operand of this triplet form can be of three basic types a) compiler
38372  generated temporary b) user defined variable c) a constant value.
38373  Note that local variables and parameters are replaced by compiler generated
38374  temporaries.
38375  Live ranges
38376 \begin_inset LatexCommand \index{Live range analysis}
38377
38378 \end_inset
38379
38380  are computed only for temporaries (i.e.
38381  live ranges are not computed for global variables).
38382  Registers
38383 \begin_inset LatexCommand \index{Register allocation}
38384
38385 \end_inset
38386
38387  are allocated for temporaries only.
38388  Operands are formatted in the following manner:
38389 \newline
38390
38391 \shape italic
38392 \size footnotesize
38393 Operand Name [lr live-from : live-to ] { type information } [ registers
38394  allocated ].
38395 \shape default
38396 \size default
38397
38398 \newline
38399 As mentioned earlier the live ranges are computed in terms of the execution
38400  sequence number of the iCodes, for example 
38401 \newline
38402 the iTemp0 is live from (i.e.
38403  first defined in iCode with execution sequence number 3, and is last used
38404  in the iCode with sequence number 5).
38405  For induction variables such as iTemp21 the live range computation extends
38406  the lifetime from the start to the end of the loop.
38407 \newline
38408 The register allocator
38409  used the live range information to allocate registers, the same registers
38410  may be used for different temporaries if their live ranges do not overlap,
38411  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38412  ranges do not overlap.
38413  In addition the allocator also takes into consideration the type and usage
38414  of a temporary, for example itemp6 is a pointer to near space and is used
38415  as to fetch data from (i.e.
38416  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38417  Some short lived temporaries are allocated to special registers which have
38418  meaning to the code generator e.g.
38419  iTemp13 is allocated to a pseudo register CC which tells the back end that
38420  the temporary is used only for a conditional jump the code generation makes
38421  use of this information to optimize a compare and jump ICode.
38422 \newline
38423 There are several
38424  loop optimizations
38425 \begin_inset LatexCommand \index{Loop optimization}
38426
38427 \end_inset
38428
38429  performed by the compiler.
38430  It can detect induction variables iTemp21(i) and iTemp23(j).
38431  Also note the compiler does selective strength reduction
38432 \begin_inset LatexCommand \index{Strength reduction}
38433
38434 \end_inset
38435
38436 , i.e.
38437  the multiplication of an induction variable in line 18 (gint = j * 3) is
38438  changed to addition, a new temporary iTemp17 is allocated and assigned
38439  a initial value, a constant 3 is then added for each iteration of the loop.
38440  The compiler does not change the multiplication
38441 \begin_inset LatexCommand \index{Multiplication}
38442
38443 \end_inset
38444
38445  in line 17 however since the processor does support an 8 * 8 bit multiplication.
38446 \newline
38447
38448 Note the dead code elimination
38449 \begin_inset LatexCommand \index{Dead-code elimination}
38450
38451 \end_inset
38452
38453  optimization eliminated the dead assignments in line 7 & 8 to I and sum
38454  respectively.
38455 \newline
38456
38457 \end_layout
38458
38459 \begin_layout Standard
38460
38461 \size footnotesize
38462 Sample.c (5:1:0:0) _entry($9) :
38463 \end_layout
38464
38465 \begin_layout Standard
38466
38467 \size footnotesize
38468 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38469 \end_layout
38470
38471 \begin_layout Standard
38472
38473 \size footnotesize
38474 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
38475 \end_layout
38476
38477 \begin_layout Standard
38478
38479 \size footnotesize
38480 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38481 \end_layout
38482
38483 \begin_layout Standard
38484
38485 \size footnotesize
38486 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38487  * int}[r2]
38488 \end_layout
38489
38490 \begin_layout Standard
38491
38492 \size footnotesize
38493 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38494 \end_layout
38495
38496 \begin_layout Standard
38497
38498 \size footnotesize
38499 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38500  int}[r0]]
38501 \end_layout
38502
38503 \begin_layout Standard
38504
38505 \size footnotesize
38506 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38507 \end_layout
38508
38509 \begin_layout Standard
38510
38511 \size footnotesize
38512 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
38513  * int}
38514 \end_layout
38515
38516 \begin_layout Standard
38517
38518 \size footnotesize
38519 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
38520  {short}
38521 \end_layout
38522
38523 \begin_layout Standard
38524
38525 \size footnotesize
38526 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
38527  * int}[DPTR]]
38528 \end_layout
38529
38530 \begin_layout Standard
38531
38532 \size footnotesize
38533 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
38534 }[r2 r3]
38535 \end_layout
38536
38537 \begin_layout Standard
38538
38539 \size footnotesize
38540 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
38541  * int}[r0] + 0x2 {short}
38542 \end_layout
38543
38544 \begin_layout Standard
38545
38546 \size footnotesize
38547 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
38548 \end_layout
38549
38550 \begin_layout Standard
38551
38552 \size footnotesize
38553 Sample.c(11:17:21:0)_whilebreak_0($3) :
38554 \end_layout
38555
38556 \begin_layout Standard
38557
38558 \size footnotesize
38559 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38560 \end_layout
38561
38562 \begin_layout Standard
38563
38564 \size footnotesize
38565 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38566 \end_layout
38567
38568 \begin_layout Standard
38569
38570 \size footnotesize
38571 Sample.c(15:20:54:0)preHeaderLbl1($13) :
38572 \end_layout
38573
38574 \begin_layout Standard
38575
38576 \size footnotesize
38577 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38578 \end_layout
38579
38580 \begin_layout Standard
38581
38582 \size footnotesize
38583 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38584 \end_layout
38585
38586 \begin_layout Standard
38587
38588 \size footnotesize
38589 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38590 \end_layout
38591
38592 \begin_layout Standard
38593
38594 \size footnotesize
38595 Sample.c(15:24:26:1)_forcond_0($4) :
38596 \end_layout
38597
38598 \begin_layout Standard
38599
38600 \size footnotesize
38601 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
38602  < 0xa {short}
38603 \end_layout
38604
38605 \begin_layout Standard
38606
38607 \size footnotesize
38608 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38609 \end_layout
38610
38611 \begin_layout Standard
38612
38613 \size footnotesize
38614 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
38615  + ITemp21 [lr21:38]{short}[r4]
38616 \end_layout
38617
38618 \begin_layout Standard
38619
38620 \size footnotesize
38621 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
38622  * 0x3 {short}
38623 \end_layout
38624
38625 \begin_layout Standard
38626
38627 \size footnotesize
38628 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
38629  + iTemp15 [lr29:30]{short}[r1]
38630 \end_layout
38631
38632 \begin_layout Standard
38633
38634 \size footnotesize
38635 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
38636  r0]- 0x3 {short}
38637 \end_layout
38638
38639 \begin_layout Standard
38640
38641 \size footnotesize
38642 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
38643 int}[r7 r0]
38644 \end_layout
38645
38646 \begin_layout Standard
38647
38648 \size footnotesize
38649 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
38650  + 0x1 {short}
38651 \end_layout
38652
38653 \begin_layout Standard
38654
38655 \size footnotesize
38656 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
38657  r6]- 0x1 {short}
38658 \end_layout
38659
38660 \begin_layout Standard
38661
38662 \size footnotesize
38663 Sample.c(19:38:47:1) goto _forcond_0($4)
38664 \end_layout
38665
38666 \begin_layout Standard
38667
38668 \size footnotesize
38669 Sample.c(19:39:48:0)_forbreak_0($7) :
38670 \end_layout
38671
38672 \begin_layout Standard
38673
38674 \size footnotesize
38675 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
38676  + ITemp11 [lr19:40]{short}[r3]
38677 \end_layout
38678
38679 \begin_layout Standard
38680
38681 \size footnotesize
38682 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
38683 \end_layout
38684
38685 \begin_layout Standard
38686
38687 \size footnotesize
38688 Sample.c(20:42:51:0)_return($8) :
38689 \end_layout
38690
38691 \begin_layout Standard
38692
38693 \size footnotesize
38694 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
38695 \size default
38696
38697 \newline
38698
38699 \newline
38700 Finally the code generated for this function:
38701 \newline
38702
38703 \end_layout
38704
38705 \begin_layout Standard
38706
38707 \size footnotesize
38708 .area DSEG (DATA)
38709 \end_layout
38710
38711 \begin_layout Standard
38712
38713 \size footnotesize
38714 _p::
38715 \end_layout
38716
38717 \begin_layout Standard
38718
38719 \size footnotesize
38720 \InsetSpace ~
38721 \InsetSpace ~
38722 .ds 2
38723 \end_layout
38724
38725 \begin_layout Standard
38726
38727 \size footnotesize
38728 _gint::
38729 \end_layout
38730
38731 \begin_layout Standard
38732
38733 \size footnotesize
38734 \InsetSpace ~
38735 \InsetSpace ~
38736 .ds 2
38737 \end_layout
38738
38739 \begin_layout Standard
38740
38741 \size footnotesize
38742 ; sample.c 5
38743 \end_layout
38744
38745 \begin_layout Standard
38746
38747 \size footnotesize
38748 ; ----------------------------------------------
38749 \end_layout
38750
38751 \begin_layout Standard
38752
38753 \size footnotesize
38754 ; function function
38755 \end_layout
38756
38757 \begin_layout Standard
38758
38759 \size footnotesize
38760 ; ----------------------------------------------
38761 \end_layout
38762
38763 \begin_layout Standard
38764
38765 \size footnotesize
38766 _function:
38767 \end_layout
38768
38769 \begin_layout Standard
38770
38771 \size footnotesize
38772 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
38773 \end_layout
38774
38775 \begin_layout Standard
38776
38777 \size footnotesize
38778 \InsetSpace ~
38779 \InsetSpace ~
38780 mov r2,dpl
38781 \end_layout
38782
38783 \begin_layout Standard
38784
38785 \size footnotesize
38786 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
38787 \end_layout
38788
38789 \begin_layout Standard
38790
38791 \size footnotesize
38792 \InsetSpace ~
38793 \InsetSpace ~
38794 mov ar0,r2
38795 \end_layout
38796
38797 \begin_layout Standard
38798
38799 \size footnotesize
38800 ;_whilecontinue_0($1) :
38801 \end_layout
38802
38803 \begin_layout Standard
38804
38805 \size footnotesize
38806 00101$:
38807 \end_layout
38808
38809 \begin_layout Standard
38810
38811 \size footnotesize
38812 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
38813 \end_layout
38814
38815 \begin_layout Standard
38816
38817 \size footnotesize
38818 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38819 \end_layout
38820
38821 \begin_layout Standard
38822
38823 \size footnotesize
38824 \InsetSpace ~
38825 \InsetSpace ~
38826 mov ar2,@r0
38827 \end_layout
38828
38829 \begin_layout Standard
38830
38831 \size footnotesize
38832 \InsetSpace ~
38833 \InsetSpace ~
38834 inc r0
38835 \end_layout
38836
38837 \begin_layout Standard
38838
38839 \size footnotesize
38840 \InsetSpace ~
38841 \InsetSpace ~
38842 mov ar3,@r0
38843 \end_layout
38844
38845 \begin_layout Standard
38846
38847 \size footnotesize
38848 \InsetSpace ~
38849 \InsetSpace ~
38850 dec r0
38851 \end_layout
38852
38853 \begin_layout Standard
38854
38855 \size footnotesize
38856 \InsetSpace ~
38857 \InsetSpace ~
38858 mov a,r2
38859 \end_layout
38860
38861 \begin_layout Standard
38862
38863 \size footnotesize
38864 \InsetSpace ~
38865 \InsetSpace ~
38866 orl a,r3
38867 \end_layout
38868
38869 \begin_layout Standard
38870
38871 \size footnotesize
38872 \InsetSpace ~
38873 \InsetSpace ~
38874 jz 00103$
38875 \end_layout
38876
38877 \begin_layout Standard
38878
38879 \size footnotesize
38880 00114$:
38881 \end_layout
38882
38883 \begin_layout Standard
38884
38885 \size footnotesize
38886 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
38887 \end_layout
38888
38889 \begin_layout Standard
38890
38891 \size footnotesize
38892 \InsetSpace ~
38893 \InsetSpace ~
38894 mov dpl,_p
38895 \end_layout
38896
38897 \begin_layout Standard
38898
38899 \size footnotesize
38900 \InsetSpace ~
38901 \InsetSpace ~
38902 mov dph,(_p + 1)
38903 \end_layout
38904
38905 \begin_layout Standard
38906
38907 \size footnotesize
38908 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
38909 \end_layout
38910
38911 \begin_layout Standard
38912
38913 \size footnotesize
38914 \InsetSpace ~
38915 \InsetSpace ~
38916 mov a,#0x02
38917 \end_layout
38918
38919 \begin_layout Standard
38920
38921 \size footnotesize
38922 \InsetSpace ~
38923 \InsetSpace ~
38924 add a,_p
38925 \end_layout
38926
38927 \begin_layout Standard
38928
38929 \size footnotesize
38930 \InsetSpace ~
38931 \InsetSpace ~
38932 mov _p,a
38933 \end_layout
38934
38935 \begin_layout Standard
38936
38937 \size footnotesize
38938 \InsetSpace ~
38939 \InsetSpace ~
38940 clr a
38941 \end_layout
38942
38943 \begin_layout Standard
38944
38945 \size footnotesize
38946 \InsetSpace ~
38947 \InsetSpace ~
38948 addc a,(_p + 1)
38949 \end_layout
38950
38951 \begin_layout Standard
38952
38953 \size footnotesize
38954 \InsetSpace ~
38955 \InsetSpace ~
38956 mov (_p + 1),a
38957 \end_layout
38958
38959 \begin_layout Standard
38960
38961 \size footnotesize
38962 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
38963 \end_layout
38964
38965 \begin_layout Standard
38966
38967 \size footnotesize
38968 \InsetSpace ~
38969 \InsetSpace ~
38970 movx a,@dptr
38971 \end_layout
38972
38973 \begin_layout Standard
38974
38975 \size footnotesize
38976 \InsetSpace ~
38977 \InsetSpace ~
38978 mov r2,a
38979 \end_layout
38980
38981 \begin_layout Standard
38982
38983 \size footnotesize
38984 \InsetSpace ~
38985 \InsetSpace ~
38986 inc dptr
38987 \end_layout
38988
38989 \begin_layout Standard
38990
38991 \size footnotesize
38992 \InsetSpace ~
38993 \InsetSpace ~
38994 movx a,@dptr
38995 \end_layout
38996
38997 \begin_layout Standard
38998
38999 \size footnotesize
39000 \InsetSpace ~
39001 \InsetSpace ~
39002 mov r3,a
39003 \end_layout
39004
39005 \begin_layout Standard
39006
39007 \size footnotesize
39008 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
39009 \end_layout
39010
39011 \begin_layout Standard
39012
39013 \size footnotesize
39014 \InsetSpace ~
39015 \InsetSpace ~
39016 mov @r0,ar2
39017 \end_layout
39018
39019 \begin_layout Standard
39020
39021 \size footnotesize
39022 \InsetSpace ~
39023 \InsetSpace ~
39024 inc r0
39025 \end_layout
39026
39027 \begin_layout Standard
39028
39029 \size footnotesize
39030 \InsetSpace ~
39031 \InsetSpace ~
39032 mov @r0,ar3
39033 \end_layout
39034
39035 \begin_layout Standard
39036
39037 \size footnotesize
39038 ; iTemp6 [lr5:16]{_near * int}[r0] = 
39039 \end_layout
39040
39041 \begin_layout Standard
39042
39043 \size footnotesize
39044 ; iTemp6 [lr5:16]{_near * int}[r0] + 
39045 \end_layout
39046
39047 \begin_layout Standard
39048
39049 \size footnotesize
39050 ; 0x2 {short}
39051 \end_layout
39052
39053 \begin_layout Standard
39054
39055 \size footnotesize
39056 \InsetSpace ~
39057 \InsetSpace ~
39058 inc r0
39059 \end_layout
39060
39061 \begin_layout Standard
39062
39063 \size footnotesize
39064 ; goto _whilecontinue_0($1)
39065 \end_layout
39066
39067 \begin_layout Standard
39068
39069 \size footnotesize
39070 \InsetSpace ~
39071 \InsetSpace ~
39072 sjmp 00101$
39073 \end_layout
39074
39075 \begin_layout Standard
39076
39077 \size footnotesize
39078 ; _whilebreak_0($3) :
39079 \end_layout
39080
39081 \begin_layout Standard
39082
39083 \size footnotesize
39084 00103$:
39085 \end_layout
39086
39087 \begin_layout Standard
39088
39089 \size footnotesize
39090 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
39091 \end_layout
39092
39093 \begin_layout Standard
39094
39095 \size footnotesize
39096 \InsetSpace ~
39097 \InsetSpace ~
39098 mov r2,#0x00
39099 \end_layout
39100
39101 \begin_layout Standard
39102
39103 \size footnotesize
39104 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
39105 \end_layout
39106
39107 \begin_layout Standard
39108
39109 \size footnotesize
39110 \InsetSpace ~
39111 \InsetSpace ~
39112 mov r3,#0x00
39113 \end_layout
39114
39115 \begin_layout Standard
39116
39117 \size footnotesize
39118 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
39119 \end_layout
39120
39121 \begin_layout Standard
39122
39123 \size footnotesize
39124 \InsetSpace ~
39125 \InsetSpace ~
39126 mov r4,#0x00
39127 \end_layout
39128
39129 \begin_layout Standard
39130
39131 \size footnotesize
39132 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
39133 \end_layout
39134
39135 \begin_layout Standard
39136
39137 \size footnotesize
39138 \InsetSpace ~
39139 \InsetSpace ~
39140 mov r5,#0x0A
39141 \end_layout
39142
39143 \begin_layout Standard
39144
39145 \size footnotesize
39146 \InsetSpace ~
39147 \InsetSpace ~
39148 mov r6,#0x00
39149 \end_layout
39150
39151 \begin_layout Standard
39152
39153 \size footnotesize
39154 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
39155 \end_layout
39156
39157 \begin_layout Standard
39158
39159 \size footnotesize
39160 \InsetSpace ~
39161 \InsetSpace ~
39162 mov r7,#0x1E
39163 \end_layout
39164
39165 \begin_layout Standard
39166
39167 \size footnotesize
39168 \InsetSpace ~
39169 \InsetSpace ~
39170 mov r0,#0x00
39171 \end_layout
39172
39173 \begin_layout Standard
39174
39175 \size footnotesize
39176 ; _forcond_0($4) :
39177 \end_layout
39178
39179 \begin_layout Standard
39180
39181 \size footnotesize
39182 00104$:
39183 \end_layout
39184
39185 \begin_layout Standard
39186
39187 \size footnotesize
39188 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
39189 \end_layout
39190
39191 \begin_layout Standard
39192
39193 \size footnotesize
39194 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
39195 \end_layout
39196
39197 \begin_layout Standard
39198
39199 \size footnotesize
39200 \InsetSpace ~
39201 \InsetSpace ~
39202 clr c
39203 \end_layout
39204
39205 \begin_layout Standard
39206
39207 \size footnotesize
39208 \InsetSpace ~
39209 \InsetSpace ~
39210 mov a,r4
39211 \end_layout
39212
39213 \begin_layout Standard
39214
39215 \size footnotesize
39216 \InsetSpace ~
39217 \InsetSpace ~
39218 xrl a,#0x80
39219 \end_layout
39220
39221 \begin_layout Standard
39222
39223 \size footnotesize
39224 \InsetSpace ~
39225 \InsetSpace ~
39226 subb a,#0x8a
39227 \end_layout
39228
39229 \begin_layout Standard
39230
39231 \size footnotesize
39232 \InsetSpace ~
39233 \InsetSpace ~
39234 jnc 00107$
39235 \end_layout
39236
39237 \begin_layout Standard
39238
39239 \size footnotesize
39240 00115$:
39241 \end_layout
39242
39243 \begin_layout Standard
39244
39245 \size footnotesize
39246 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
39247 \end_layout
39248
39249 \begin_layout Standard
39250
39251 \size footnotesize
39252 ; iTemp21 [lr21:38]{short}[r4]
39253 \end_layout
39254
39255 \begin_layout Standard
39256
39257 \size footnotesize
39258 \InsetSpace ~
39259 \InsetSpace ~
39260 mov a,r4
39261 \end_layout
39262
39263 \begin_layout Standard
39264
39265 \size footnotesize
39266 \InsetSpace ~
39267 \InsetSpace ~
39268 add a,r2
39269 \end_layout
39270
39271 \begin_layout Standard
39272
39273 \size footnotesize
39274 \InsetSpace ~
39275 \InsetSpace ~
39276 mov r2,a
39277 \end_layout
39278
39279 \begin_layout Standard
39280
39281 \size footnotesize
39282 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
39283 \end_layout
39284
39285 \begin_layout Standard
39286
39287 \size footnotesize
39288 \InsetSpace ~
39289 \InsetSpace ~
39290 mov b,#0x03
39291 \end_layout
39292
39293 \begin_layout Standard
39294
39295 \size footnotesize
39296 \InsetSpace ~
39297 \InsetSpace ~
39298 mov a,r4
39299 \end_layout
39300
39301 \begin_layout Standard
39302
39303 \size footnotesize
39304 \InsetSpace ~
39305 \InsetSpace ~
39306 mul ab
39307 \end_layout
39308
39309 \begin_layout Standard
39310
39311 \size footnotesize
39312 \InsetSpace ~
39313 \InsetSpace ~
39314 mov r1,a
39315 \end_layout
39316
39317 \begin_layout Standard
39318
39319 \size footnotesize
39320 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
39321 \end_layout
39322
39323 \begin_layout Standard
39324
39325 \size footnotesize
39326 ; iTemp15 [lr29:30]{short}[r1]
39327 \end_layout
39328
39329 \begin_layout Standard
39330
39331 \size footnotesize
39332 \InsetSpace ~
39333 \InsetSpace ~
39334 add a,r3
39335 \end_layout
39336
39337 \begin_layout Standard
39338
39339 \size footnotesize
39340 \InsetSpace ~
39341 \InsetSpace ~
39342 mov r3,a
39343 \end_layout
39344
39345 \begin_layout Standard
39346
39347 \size footnotesize
39348 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
39349 \end_layout
39350
39351 \begin_layout Standard
39352
39353 \size footnotesize
39354 \InsetSpace ~
39355 \InsetSpace ~
39356 mov a,r7
39357 \end_layout
39358
39359 \begin_layout Standard
39360
39361 \size footnotesize
39362 \InsetSpace ~
39363 \InsetSpace ~
39364 add a,#0xfd
39365 \end_layout
39366
39367 \begin_layout Standard
39368
39369 \size footnotesize
39370 \InsetSpace ~
39371 \InsetSpace ~
39372 mov r7,a
39373 \end_layout
39374
39375 \begin_layout Standard
39376
39377 \size footnotesize
39378 \InsetSpace ~
39379 \InsetSpace ~
39380 mov a,r0
39381 \end_layout
39382
39383 \begin_layout Standard
39384
39385 \size footnotesize
39386 \InsetSpace ~
39387 \InsetSpace ~
39388 addc a,#0xff
39389 \end_layout
39390
39391 \begin_layout Standard
39392
39393 \size footnotesize
39394 \InsetSpace ~
39395 \InsetSpace ~
39396 mov r0,a
39397 \end_layout
39398
39399 \begin_layout Standard
39400
39401 \size footnotesize
39402 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39403 \end_layout
39404
39405 \begin_layout Standard
39406
39407 \size footnotesize
39408 \InsetSpace ~
39409 \InsetSpace ~
39410 mov a,r7
39411 \end_layout
39412
39413 \begin_layout Standard
39414
39415 \size footnotesize
39416 \InsetSpace ~
39417 \InsetSpace ~
39418 add a,_gint
39419 \end_layout
39420
39421 \begin_layout Standard
39422
39423 \size footnotesize
39424 \InsetSpace ~
39425 \InsetSpace ~
39426 mov _gint,a
39427 \end_layout
39428
39429 \begin_layout Standard
39430
39431 \size footnotesize
39432 \InsetSpace ~
39433 \InsetSpace ~
39434 mov a,r0
39435 \end_layout
39436
39437 \begin_layout Standard
39438
39439 \size footnotesize
39440 \InsetSpace ~
39441 \InsetSpace ~
39442 addc a,(_gint + 1)
39443 \end_layout
39444
39445 \begin_layout Standard
39446
39447 \size footnotesize
39448 \InsetSpace ~
39449 \InsetSpace ~
39450 mov (_gint + 1),a
39451 \end_layout
39452
39453 \begin_layout Standard
39454
39455 \size footnotesize
39456 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39457 \end_layout
39458
39459 \begin_layout Standard
39460
39461 \size footnotesize
39462 \InsetSpace ~
39463 \InsetSpace ~
39464 inc r4
39465 \end_layout
39466
39467 \begin_layout Standard
39468
39469 \size footnotesize
39470 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39471 \end_layout
39472
39473 \begin_layout Standard
39474
39475 \size footnotesize
39476 \InsetSpace ~
39477 \InsetSpace ~
39478 dec r5
39479 \end_layout
39480
39481 \begin_layout Standard
39482
39483 \size footnotesize
39484 \InsetSpace ~
39485 \InsetSpace ~
39486 cjne r5,#0xff,00104$
39487 \end_layout
39488
39489 \begin_layout Standard
39490
39491 \size footnotesize
39492 \InsetSpace ~
39493 \InsetSpace ~
39494 dec r6
39495 \end_layout
39496
39497 \begin_layout Standard
39498
39499 \size footnotesize
39500 ; goto _forcond_0($4)
39501 \end_layout
39502
39503 \begin_layout Standard
39504
39505 \size footnotesize
39506 \InsetSpace ~
39507 \InsetSpace ~
39508 sjmp 00104$
39509 \end_layout
39510
39511 \begin_layout Standard
39512
39513 \size footnotesize
39514 ; _forbreak_0($7) :
39515 \end_layout
39516
39517 \begin_layout Standard
39518
39519 \size footnotesize
39520 00107$:
39521 \end_layout
39522
39523 \begin_layout Standard
39524
39525 \size footnotesize
39526 ; ret iTemp24 [lr40:41]{short}
39527 \end_layout
39528
39529 \begin_layout Standard
39530
39531 \size footnotesize
39532 \InsetSpace ~
39533 \InsetSpace ~
39534 mov a,r3
39535 \end_layout
39536
39537 \begin_layout Standard
39538
39539 \size footnotesize
39540 \InsetSpace ~
39541 \InsetSpace ~
39542 add a,r2
39543 \end_layout
39544
39545 \begin_layout Standard
39546
39547 \size footnotesize
39548 \InsetSpace ~
39549 \InsetSpace ~
39550 mov dpl,a
39551 \end_layout
39552
39553 \begin_layout Standard
39554
39555 \size footnotesize
39556 ; _return($8) :
39557 \end_layout
39558
39559 \begin_layout Standard
39560
39561 \size footnotesize
39562 00108$:
39563 \end_layout
39564
39565 \begin_layout Standard
39566
39567 \size footnotesize
39568 \InsetSpace ~
39569 \InsetSpace ~
39570 ret
39571 \newline
39572
39573 \end_layout
39574
39575 \begin_layout Section
39576 A few words about basic block successors, predecessors and dominators
39577 \end_layout
39578
39579 \begin_layout Standard
39580 Successors are basic blocks
39581 \begin_inset LatexCommand \index{Basic blocks}
39582
39583 \end_inset
39584
39585  that might execute after this basic block.
39586 \newline
39587 Predecessors are basic blocks
39588  that might execute before reaching this basic block.
39589 \newline
39590 Dominators are basic
39591  blocks that WILL execute before reaching this basic block.
39592 \newline
39593
39594 \end_layout
39595
39596 \begin_layout Standard
39597 [basic block 1]
39598 \end_layout
39599
39600 \begin_layout Standard
39601 if (something)
39602 \end_layout
39603
39604 \begin_layout Standard
39605 \InsetSpace ~
39606 \InsetSpace ~
39607 \InsetSpace ~
39608 \InsetSpace ~
39609 [basic block 2]
39610 \end_layout
39611
39612 \begin_layout Standard
39613 else
39614 \end_layout
39615
39616 \begin_layout Standard
39617 \InsetSpace ~
39618 \InsetSpace ~
39619 \InsetSpace ~
39620 \InsetSpace ~
39621 [basic block 3]
39622 \end_layout
39623
39624 \begin_layout Standard
39625 [basic block 4]
39626 \newline
39627
39628 \end_layout
39629
39630 \begin_layout Standard
39631 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
39632 \end_layout
39633
39634 \begin_layout Standard
39635 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
39636 \end_layout
39637
39638 \begin_layout Standard
39639 c) domVect of [BB4] = BB1 ...
39640  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
39641  was executed.
39642 \end_layout
39643
39644 \begin_layout Chapter
39645 Acknowledgments
39646 \end_layout
39647
39648 \begin_layout Standard
39649 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
39650
39651 \end_inset
39652
39653
39654 \newline
39655
39656 \newline
39657
39658 \emph on
39659 Thanks to all the other volunteer developers who have helped with coding,
39660  testing, web-page creation, distribution sets, etc.
39661  You know who you are :-)
39662 \emph default
39663
39664 \newline
39665
39666 \newline
39667
39668 \emph on
39669 Thanks to Sourceforge 
39670 \begin_inset LatexCommand \url{http://www.sf.net}
39671
39672 \end_inset
39673
39674  which has hosted the project since 1999 and donates significant download
39675  bandwidth.
39676 \emph default
39677
39678 \newline
39679
39680 \newline
39681
39682 \emph on
39683 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
39684  cycles and bandwidth for snapshot builds.
39685 \newline
39686
39687 \end_layout
39688
39689 \begin_layout Standard
39690 This document was initially written by Sandeep Dutta
39691 \end_layout
39692
39693 \begin_layout Standard
39694 All product names mentioned herein may be trademarks
39695 \begin_inset LatexCommand \index{Trademarks}
39696
39697 \end_inset
39698
39699  of their respective companies.
39700  
39701 \end_layout
39702
39703 \begin_layout Section*
39704 Alphabetical index
39705 \end_layout
39706
39707 \begin_layout Standard
39708 To avoid confusion, the installation and building options for SDCC itself
39709  (chapter 2) are not part of the index.
39710 \end_layout
39711
39712 \begin_layout Standard
39713 \begin_inset LatexCommand \printindex{}
39714
39715 \end_inset
39716
39717
39718 \end_layout
39719
39720 \end_body
39721 \end_document