* doc/sdccman.lyx, src/SDCCmain.c:
[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.6.5
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  
8440 \end_layout
8441
8442 \begin_layout Standard
8443 \begin_inset VSpace bigskip
8444 \end_inset
8445
8446
8447 \end_layout
8448
8449 \begin_layout Subsection
8450 Optimization Options
8451 \begin_inset LatexCommand \index{Options optimization}
8452
8453 \end_inset
8454
8455
8456 \begin_inset LatexCommand \index{Optimization options}
8457
8458 \end_inset
8459
8460
8461 \end_layout
8462
8463 \begin_layout List
8464 \labelwidthstring 00.00.0000
8465
8466 \series bold
8467 -
8468 \begin_inset ERT
8469 status collapsed
8470
8471 \begin_layout Standard
8472
8473
8474 \backslash
8475 /
8476 \end_layout
8477
8478 \end_inset
8479
8480 -nogcse
8481 \begin_inset LatexCommand \index{-\/-nogcse}
8482
8483 \end_inset
8484
8485
8486 \series default
8487  Will not do global subexpression elimination, this option may be used when
8488  the compiler creates undesirably large stack/data spaces to store compiler
8489  temporaries (
8490 \emph on
8491 s
8492 \emph default
8493 pill 
8494 \emph on
8495 loc
8496 \emph default
8497 ations, sloc
8498 \begin_inset LatexCommand \index{sloc (spill location)}
8499
8500 \end_inset
8501
8502 ).
8503  A warning message will be generated when this happens and the compiler
8504  will indicate the number of extra bytes it allocated.
8505  It is recommended that this option NOT be used, #pragma\InsetSpace ~
8506 nogcse
8507 \begin_inset LatexCommand \index{\#pragma nogcse}
8508
8509 \end_inset
8510
8511  can be used to turn off global subexpression elimination
8512 \begin_inset LatexCommand \index{Subexpression elimination}
8513
8514 \end_inset
8515
8516  for a given function only.
8517 \end_layout
8518
8519 \begin_layout List
8520 \labelwidthstring 00.00.0000
8521
8522 \series bold
8523 -
8524 \begin_inset ERT
8525 status collapsed
8526
8527 \begin_layout Standard
8528
8529
8530 \backslash
8531 /
8532 \end_layout
8533
8534 \end_inset
8535
8536 -noinvariant
8537 \begin_inset LatexCommand \index{-\/-noinvariant}
8538
8539 \end_inset
8540
8541
8542 \series default
8543  Will not do loop invariant optimizations, this may be turned off for reasons
8544  explained for the previous option.
8545  For more details of loop optimizations performed see Loop Invariants in
8546  section 
8547 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
8548
8549 \end_inset
8550
8551 .
8552  It is recommended that this option NOT be used, #pragma\InsetSpace ~
8553 noinvariant
8554 \begin_inset LatexCommand \index{\#pragma noinvariant}
8555
8556 \end_inset
8557
8558  can be used to turn off invariant optimizations for a given function only.
8559 \end_layout
8560
8561 \begin_layout List
8562 \labelwidthstring 00.00.0000
8563
8564 \series bold
8565 -
8566 \begin_inset ERT
8567 status collapsed
8568
8569 \begin_layout Standard
8570
8571
8572 \backslash
8573 /
8574 \end_layout
8575
8576 \end_inset
8577
8578 -noinduction
8579 \begin_inset LatexCommand \index{-\/-noinduction}
8580
8581 \end_inset
8582
8583
8584 \series default
8585  Will not do loop induction optimizations, see section strength reduction
8586  for more details.
8587  It is recommended that this option is NOT used, #pragma\InsetSpace ~
8588 noinduction
8589 \begin_inset LatexCommand \index{\#pragma noinduction}
8590
8591 \end_inset
8592
8593  can be used to turn off induction optimizations for a given function only.
8594 \end_layout
8595
8596 \begin_layout List
8597 \labelwidthstring 00.00.0000
8598
8599 \series bold
8600 -
8601 \begin_inset ERT
8602 status collapsed
8603
8604 \begin_layout Standard
8605
8606
8607 \backslash
8608 /
8609 \end_layout
8610
8611 \end_inset
8612
8613 -nojtbound
8614 \begin_inset LatexCommand \index{-\/-nojtbound}
8615
8616 \end_inset
8617
8618
8619 \size large
8620 \bar under
8621  
8622 \series default
8623 \size default
8624 \bar default
8625  Will not generate boundary condition check when switch statements
8626 \begin_inset LatexCommand \index{switch statement}
8627
8628 \end_inset
8629
8630  are implemented using jump-tables.
8631  See section 
8632 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
8633
8634 \end_inset
8635
8636 \InsetSpace ~
8637 Switch Statements for more details.
8638  It is recommended that this option is NOT used, #pragma\InsetSpace ~
8639 nojtbound
8640 \begin_inset LatexCommand \index{\#pragma nojtbound}
8641
8642 \end_inset
8643
8644  can be used to turn off boundary checking for jump tables for a given function
8645  only.
8646 \end_layout
8647
8648 \begin_layout List
8649 \labelwidthstring 00.00.0000
8650
8651 \series bold
8652 -
8653 \begin_inset ERT
8654 status collapsed
8655
8656 \begin_layout Standard
8657
8658
8659 \backslash
8660 /
8661 \end_layout
8662
8663 \end_inset
8664
8665 -noloopreverse
8666 \begin_inset LatexCommand \index{-\/-noloopreverse}
8667
8668 \end_inset
8669
8670
8671 \series default
8672 \size large
8673  
8674 \size default
8675 Will not do loop reversal 
8676 \begin_inset LatexCommand \index{Loop reversing}
8677
8678 \end_inset
8679
8680 optimization.
8681 \end_layout
8682
8683 \begin_layout List
8684 \labelwidthstring 00.00.0000
8685 -
8686 \begin_inset ERT
8687 status collapsed
8688
8689 \begin_layout Standard
8690
8691
8692 \backslash
8693 /
8694 \end_layout
8695
8696 \end_inset
8697
8698 -
8699 \series bold
8700 nolabelopt
8701 \series default
8702  
8703 \begin_inset LatexCommand \index{-\/-nolabelopt }
8704
8705 \end_inset
8706
8707 Will not optimize labels (makes the dumpfiles more readable).
8708 \end_layout
8709
8710 \begin_layout List
8711 \labelwidthstring 00.00.0000
8712
8713 \series bold
8714 -
8715 \begin_inset ERT
8716 status collapsed
8717
8718 \begin_layout Standard
8719
8720
8721 \backslash
8722 /
8723 \end_layout
8724
8725 \end_inset
8726
8727 -no-xinit-opt
8728 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8729
8730 \end_inset
8731
8732
8733 \series default
8734  Will not memcpy initialized data from code space into xdata space.
8735  This saves a few bytes in code space if you don't have initialized data
8736 \begin_inset LatexCommand \index{Variable initialization}
8737
8738 \end_inset
8739
8740 .
8741 \end_layout
8742
8743 \begin_layout List
8744 \labelwidthstring 00.00.0000
8745
8746 \series bold
8747 -
8748 \begin_inset ERT
8749 status collapsed
8750
8751 \begin_layout Standard
8752
8753
8754 \backslash
8755 /
8756 \end_layout
8757
8758 \end_inset
8759
8760 -nooverlay
8761 \begin_inset LatexCommand \index{-\/-nooverlay}
8762
8763 \end_inset
8764
8765
8766 \series default
8767   The compiler will not overlay parameters and local variables of any function,
8768  see section Parameters and local variables for more details.
8769 \end_layout
8770
8771 \begin_layout List
8772 \labelwidthstring 00.00.0000
8773
8774 \series bold
8775 -
8776 \begin_inset ERT
8777 status collapsed
8778
8779 \begin_layout Standard
8780
8781
8782 \backslash
8783 /
8784 \end_layout
8785
8786 \end_inset
8787
8788 -no-peep
8789 \begin_inset LatexCommand \index{-\/-no-peep}
8790
8791 \end_inset
8792
8793
8794 \series default
8795  Disable peep-hole optimization with built-in rules.
8796 \end_layout
8797
8798 \begin_layout List
8799 \labelwidthstring 00.00.0000
8800
8801 \series bold
8802 -
8803 \begin_inset ERT
8804 status collapsed
8805
8806 \begin_layout Standard
8807
8808
8809 \backslash
8810 /
8811 \end_layout
8812
8813 \end_inset
8814
8815 -peep-file
8816 \series default
8817
8818 \begin_inset LatexCommand \index{-\/-peep-file}
8819
8820 \end_inset
8821
8822 \InsetSpace ~
8823 <filename> This option can be used to use additional rules to be used by
8824  the peep hole optimizer.
8825  See section 
8826 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
8827
8828 \end_inset
8829
8830 \InsetSpace ~
8831 Peep Hole optimizations for details on how to write these rules.
8832 \end_layout
8833
8834 \begin_layout List
8835 \labelwidthstring 00.00.0000
8836
8837 \series bold
8838 -
8839 \begin_inset ERT
8840 status collapsed
8841
8842 \begin_layout Standard
8843
8844
8845 \backslash
8846 /
8847 \end_layout
8848
8849 \end_inset
8850
8851 -peep-asm
8852 \begin_inset LatexCommand \index{-\/-peep-asm}
8853
8854 \end_inset
8855
8856
8857 \series default
8858  Pass the inline assembler code through the peep hole optimizer.
8859  This can cause unexpected changes to inline assembler code, please go through
8860  the peephole optimizer
8861 \begin_inset LatexCommand \index{Peephole optimizer}
8862
8863 \end_inset
8864
8865  rules defined in the source file tree '<target>/peeph.def' before using
8866  this option.
8867 \end_layout
8868
8869 \begin_layout List
8870 \labelwidthstring 00.00.0000
8871
8872 \series bold
8873 -
8874 \begin_inset ERT
8875 status collapsed
8876
8877 \begin_layout Standard
8878
8879
8880 \backslash
8881 /
8882 \end_layout
8883
8884 \end_inset
8885
8886 -opt-code-speed
8887 \begin_inset LatexCommand \index{-\/-opt-code-speed}
8888
8889 \end_inset
8890
8891
8892 \series default
8893  The compiler will optimize code generation towards fast code, possibly
8894  at the expense of code size.
8895 \end_layout
8896
8897 \begin_layout List
8898 \labelwidthstring 00.00.0000
8899
8900 \series bold
8901 -
8902 \begin_inset ERT
8903 status collapsed
8904
8905 \begin_layout Standard
8906
8907
8908 \backslash
8909 /
8910 \end_layout
8911
8912 \end_inset
8913
8914 -opt-code-size
8915 \begin_inset LatexCommand \index{-\/-opt-code-size}
8916
8917 \end_inset
8918
8919
8920 \series default
8921  The compiler will optimize code generation towards compact code, possibly
8922  at the expense of code speed.
8923 \end_layout
8924
8925 \begin_layout Standard
8926 \begin_inset VSpace bigskip
8927 \end_inset
8928
8929
8930 \end_layout
8931
8932 \begin_layout Subsection
8933 Other Options
8934 \begin_inset LatexCommand \index{Options other}
8935
8936 \end_inset
8937
8938
8939 \end_layout
8940
8941 \begin_layout List
8942 \labelwidthstring 00.00.0000
8943
8944 \series bold
8945 -c\InsetSpace ~
8946 -
8947 \begin_inset ERT
8948 status collapsed
8949
8950 \begin_layout Standard
8951
8952
8953 \backslash
8954 /
8955 \end_layout
8956
8957 \end_inset
8958
8959 -compile-only
8960 \begin_inset LatexCommand \index{-\/-compile-only}
8961
8962 \end_inset
8963
8964
8965 \begin_inset LatexCommand \index{-c -\/-compile-only}
8966
8967 \end_inset
8968
8969
8970 \series default
8971  will compile and assemble the source, but will not call the linkage editor.
8972 \end_layout
8973
8974 \begin_layout List
8975 \labelwidthstring 00.00.0000
8976
8977 \series bold
8978 -
8979 \series default
8980
8981 \begin_inset ERT
8982 status collapsed
8983
8984 \begin_layout Standard
8985
8986
8987 \backslash
8988 /
8989 \end_layout
8990
8991 \end_inset
8992
8993
8994 \series bold
8995 -c1mode
8996 \begin_inset LatexCommand \index{-\/-c1mode}
8997
8998 \end_inset
8999
9000
9001 \series default
9002  reads the preprocessed source from standard input and compiles it.
9003  The file name for the assembler output must be specified using the -o option.
9004 \end_layout
9005
9006 \begin_layout List
9007 \labelwidthstring 00.00.0000
9008
9009 \series bold
9010 -E
9011 \begin_inset LatexCommand \index{-E}
9012
9013 \end_inset
9014
9015
9016 \series default
9017  Run only the C preprocessor.
9018  Preprocess all the C source files specified and output the results to standard
9019  output.
9020 \end_layout
9021
9022 \begin_layout List
9023 \labelwidthstring 00.00.0000
9024
9025 \series bold
9026 -o\InsetSpace ~
9027 <path/file>
9028 \begin_inset LatexCommand \index{-o <path/file>}
9029
9030 \end_inset
9031
9032  
9033 \series default
9034 The output path resp.
9035  file where everything will be placed.
9036  If the parameter is a path, it must have a trailing slash (or backslash
9037  for the Windows binaries) to be recognized as a path.
9038  
9039 \end_layout
9040
9041 \begin_layout List
9042 \labelwidthstring 00.00.0000
9043
9044 \series bold
9045 -
9046 \begin_inset ERT
9047 status collapsed
9048
9049 \begin_layout Standard
9050
9051
9052 \backslash
9053 /
9054 \end_layout
9055
9056 \end_inset
9057
9058 -stack-auto
9059 \begin_inset LatexCommand \index{-\/-stack-auto}
9060
9061 \end_inset
9062
9063
9064 \series default
9065 \size large
9066 \emph on
9067  
9068 \size default
9069 \emph default
9070 All functions in the source file will be compiled as 
9071 \emph on
9072 reentrant
9073 \emph default
9074
9075 \begin_inset LatexCommand \index{reentrant}
9076
9077 \end_inset
9078
9079 , i.e.
9080  the parameters and local variables will be allocated on the stack
9081 \begin_inset LatexCommand \index{stack}
9082
9083 \end_inset
9084
9085 .
9086  See section 
9087 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
9088
9089 \end_inset
9090
9091  Parameters and Local Variables for more details.
9092  If this option is used all source files in the project should be compiled
9093  with this option.
9094  It automatically implies --int-long-reent and --float-reent.
9095  
9096 \end_layout
9097
9098 \begin_layout List
9099 \labelwidthstring 00.00.0000
9100
9101 \series bold
9102 -
9103 \begin_inset ERT
9104 status collapsed
9105
9106 \begin_layout Standard
9107
9108
9109 \backslash
9110 /
9111 \end_layout
9112
9113 \end_inset
9114
9115 -callee-saves
9116 \begin_inset LatexCommand \index{-\/-callee-saves}
9117
9118 \end_inset
9119
9120  
9121 \begin_inset LatexCommand \label{lyx:--callee-saves-function1[,function2][,function3]...}
9122
9123 \end_inset
9124
9125 function1[,function2][,function3]....
9126
9127 \series default
9128  The compiler by default uses a caller saves convention for register saving
9129  across function calls, however this can cause unnecessary register pushing
9130  and popping when calling small functions from larger functions.
9131  This option can be used to switch the register saving convention for the
9132  function names specified.
9133  The compiler will not save registers when calling these functions, no extra
9134  code will be generated at the entry and exit (function prologue
9135 \series bold
9136
9137 \begin_inset LatexCommand \index{function prologue}
9138
9139 \end_inset
9140
9141
9142 \series default
9143  and epilogue
9144 \series bold
9145
9146 \begin_inset LatexCommand \index{function epilogue}
9147
9148 \end_inset
9149
9150
9151 \series default
9152 ) for these functions to save and restore the registers used by these functions,
9153  this can SUBSTANTIALLY reduce code and improve run time performance of
9154  the generated code.
9155  In the future the compiler (with inter procedural analysis) will be able
9156  to determine the appropriate scheme to use for each function call.
9157  DO NOT use this option for built-in functions such as _mulint..., if this
9158  option is used for a library function the appropriate library function
9159  needs to be recompiled with the same option.
9160  If the project consists of multiple source files then all the source file
9161  should be compiled with the same -
9162 \begin_inset ERT
9163 status collapsed
9164
9165 \begin_layout Standard
9166
9167
9168 \backslash
9169 /
9170 \end_layout
9171
9172 \end_inset
9173
9174 -callee-saves option string.
9175  Also see #pragma\InsetSpace ~
9176 callee_saves 
9177 \begin_inset LatexCommand \index{\#pragma callee\_saves}
9178
9179 \end_inset
9180
9181  
9182 \begin_inset LatexCommand \vpageref{ite:callee_saves-function1[,function2[,function3...]]--}
9183
9184 \end_inset
9185
9186 .
9187 \end_layout
9188
9189 \begin_layout List
9190 \labelwidthstring 00.00.0000
9191
9192 \series bold
9193 -
9194 \begin_inset ERT
9195 status collapsed
9196
9197 \begin_layout Standard
9198
9199
9200 \backslash
9201 /
9202 \end_layout
9203
9204 \end_inset
9205
9206 -all-callee-saves
9207 \begin_inset LatexCommand \index{-\/-all-callee-saves}
9208
9209 \end_inset
9210
9211  
9212 \series default
9213 Function of
9214 \series bold
9215  
9216 \series default
9217 -
9218 \begin_inset ERT
9219 status collapsed
9220
9221 \begin_layout Standard
9222
9223
9224 \backslash
9225 /
9226 \end_layout
9227
9228 \end_inset
9229
9230 -callee-saves will be applied to all functions by default.
9231 \end_layout
9232
9233 \begin_layout List
9234 \labelwidthstring 00.00.0000
9235
9236 \series bold
9237 -
9238 \begin_inset ERT
9239 status collapsed
9240
9241 \begin_layout Standard
9242
9243
9244 \backslash
9245 /
9246 \end_layout
9247
9248 \end_inset
9249
9250 -debug
9251 \begin_inset LatexCommand \index{-\/-debug}
9252
9253 \end_inset
9254
9255
9256 \bar under
9257  
9258 \series default
9259 \bar default
9260 When this option is used the compiler will generate debug information.
9261  The debug information collected in a file with .cdb extension can be used
9262  with the SDCDB.
9263  For more information see documentation for SDCDB.
9264  Another file with no extension contains debug information in AOMF or AOMF51
9265 \begin_inset LatexCommand \index{AOMF, AOMF51}
9266
9267 \end_inset
9268
9269  format which is commonly used by third party tools.
9270 \end_layout
9271
9272 \begin_layout List
9273 \labelwidthstring 00.00.0000
9274
9275 \series bold
9276 -S
9277 \begin_inset LatexCommand \index{-S}
9278
9279 \end_inset
9280
9281
9282 \size large
9283 \bar under
9284  
9285 \series default
9286 \size default
9287 \bar default
9288 Stop after the stage of compilation proper; do not assemble.
9289  The output is an assembler code file for the input file specified.
9290 \end_layout
9291
9292 \begin_layout List
9293 \labelwidthstring 00.00.0000
9294
9295 \series bold
9296 -
9297 \begin_inset ERT
9298 status collapsed
9299
9300 \begin_layout Standard
9301
9302
9303 \backslash
9304 /
9305 \end_layout
9306
9307 \end_inset
9308
9309 -int-long-reent
9310 \begin_inset LatexCommand \index{-\/-int-long-reent}
9311
9312 \end_inset
9313
9314
9315 \series default
9316  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
9317  Note by default these libraries are compiled as non-reentrant.
9318  See section Installation for more details.
9319 \end_layout
9320
9321 \begin_layout List
9322 \labelwidthstring 00.00.0000
9323
9324 \series bold
9325 -
9326 \begin_inset ERT
9327 status collapsed
9328
9329 \begin_layout Standard
9330
9331
9332 \backslash
9333 /
9334 \end_layout
9335
9336 \end_inset
9337
9338 -cyclomatic
9339 \begin_inset LatexCommand \index{-\/-cyclomatic}
9340
9341 \end_inset
9342
9343
9344 \bar under
9345  
9346 \series default
9347 \bar default
9348 This option will cause the compiler to generate an information message for
9349  each function in the source file.
9350  The message contains some 
9351 \emph on
9352 important
9353 \emph default
9354  information about the function.
9355  The number of edges and nodes the compiler detected in the control flow
9356  graph of the function, and most importantly the 
9357 \emph on
9358 cyclomatic complexity
9359 \begin_inset LatexCommand \index{Cyclomatic complexity}
9360
9361 \end_inset
9362
9363
9364 \emph default
9365  see section on Cyclomatic Complexity for more details.
9366 \end_layout
9367
9368 \begin_layout List
9369 \labelwidthstring 00.00.0000
9370
9371 \series bold
9372 -
9373 \begin_inset ERT
9374 status collapsed
9375
9376 \begin_layout Standard
9377
9378
9379 \backslash
9380 /
9381 \end_layout
9382
9383 \end_inset
9384
9385 -float-reent
9386 \begin_inset LatexCommand \index{-\/-float-reent}
9387
9388 \end_inset
9389
9390
9391 \series default
9392  Floating point library is compiled as reentrant
9393 \begin_inset LatexCommand \index{reentrant}
9394
9395 \end_inset
9396
9397 .
9398  See section Installation for more details.
9399 \end_layout
9400
9401 \begin_layout List
9402 \labelwidthstring 00.00.0000
9403
9404 \series bold
9405 -
9406 \begin_inset ERT
9407 status collapsed
9408
9409 \begin_layout Standard
9410
9411
9412 \backslash
9413 /
9414 \end_layout
9415
9416 \end_inset
9417
9418 -funsigned-char
9419 \begin_inset LatexCommand \index{-\/-funsigned-char}
9420
9421 \end_inset
9422
9423
9424 \series default
9425  The default signedness for every type is
9426 \family typewriter
9427  signed
9428 \family default
9429 .
9430  In some embedded environments the default signedness of
9431 \family typewriter
9432  char
9433 \family default
9434  is
9435 \family typewriter
9436  unsigned
9437 \family default
9438 .
9439  To set the signess for characters to unsigned, use the option --funsigned-char.
9440  If this option is set and no signedness keyword (unsigned/signed) is given,
9441  a char will be signed.
9442  All other types are unaffected.
9443 \end_layout
9444
9445 \begin_layout List
9446 \labelwidthstring 00.00.0000
9447
9448 \series bold
9449 -
9450 \begin_inset ERT
9451 status collapsed
9452
9453 \begin_layout Standard
9454
9455
9456 \backslash
9457 /
9458 \end_layout
9459
9460 \end_inset
9461
9462 -main-return
9463 \begin_inset LatexCommand \index{-\/-main-return}
9464
9465 \end_inset
9466
9467
9468 \series default
9469  This option can be used if the code generated is called by a monitor program
9470  or if the main routine includes an endless loop.
9471  This option results in slightly smaller code and saves two bytes of stack
9472  space.
9473  The return from the 'main'
9474 \begin_inset LatexCommand \index{main return}
9475
9476 \end_inset
9477
9478  function will return to the function calling main.
9479  The default setting is to lock up i.e.
9480  generate a '
9481 \family typewriter
9482 sjmp .
9483 \family default
9484 '.
9485 \end_layout
9486
9487 \begin_layout List
9488 \labelwidthstring 00.00.0000
9489
9490 \series bold
9491 -
9492 \begin_inset ERT
9493 status collapsed
9494
9495 \begin_layout Standard
9496
9497
9498 \backslash
9499 /
9500 \end_layout
9501
9502 \end_inset
9503
9504 -nostdinc
9505 \begin_inset LatexCommand \index{-\/-nostdinc}
9506
9507 \end_inset
9508
9509
9510 \series default
9511  This will prevent the compiler from passing on the default include path
9512  to the preprocessor.
9513 \end_layout
9514
9515 \begin_layout List
9516 \labelwidthstring 00.00.0000
9517
9518 \series bold
9519 -
9520 \begin_inset ERT
9521 status collapsed
9522
9523 \begin_layout Standard
9524
9525
9526 \backslash
9527 /
9528 \end_layout
9529
9530 \end_inset
9531
9532 -nostdlib
9533 \begin_inset LatexCommand \index{-\/-nostdlib}
9534
9535 \end_inset
9536
9537
9538 \series default
9539  This will prevent the compiler from passing on the default library
9540 \begin_inset LatexCommand \index{Libraries}
9541
9542 \end_inset
9543
9544  path to the linker.
9545 \end_layout
9546
9547 \begin_layout List
9548 \labelwidthstring 00.00.0000
9549
9550 \series bold
9551 -
9552 \begin_inset ERT
9553 status collapsed
9554
9555 \begin_layout Standard
9556
9557
9558 \backslash
9559 /
9560 \end_layout
9561
9562 \end_inset
9563
9564 -verbose
9565 \begin_inset LatexCommand \index{-\/-verbose}
9566
9567 \end_inset
9568
9569
9570 \series default
9571  Shows the various actions the compiler is performing.
9572 \end_layout
9573
9574 \begin_layout List
9575 \labelwidthstring 00.00.0000
9576
9577 \series bold
9578 -V
9579 \begin_inset LatexCommand \index{-V}
9580
9581 \end_inset
9582
9583
9584 \series default
9585  Shows the actual commands the compiler is executing.
9586 \end_layout
9587
9588 \begin_layout List
9589 \labelwidthstring 00.00.0000
9590
9591 \series bold
9592 -
9593 \begin_inset ERT
9594 status collapsed
9595
9596 \begin_layout Standard
9597
9598
9599 \backslash
9600 /
9601 \end_layout
9602
9603 \end_inset
9604
9605 -no-c-code-in-asm
9606 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
9607
9608 \end_inset
9609
9610
9611 \series default
9612  Hides your ugly and inefficient c-code from the asm file, so you can always
9613  blame the compiler :)
9614 \end_layout
9615
9616 \begin_layout List
9617 \labelwidthstring 00.00.0000
9618
9619 \series bold
9620 -
9621 \begin_inset ERT
9622 status collapsed
9623
9624 \begin_layout Standard
9625
9626
9627 \backslash
9628 /
9629 \end_layout
9630
9631 \end_inset
9632
9633 -fverbose-asm
9634 \begin_inset LatexCommand \index{-\/-no-gen-comments}
9635
9636 \end_inset
9637
9638
9639 \series default
9640  Include code generator and peep-hole comments in the generated asm files.
9641 \end_layout
9642
9643 \begin_layout List
9644 \labelwidthstring 00.00.0000
9645
9646 \series bold
9647 -
9648 \begin_inset ERT
9649 status collapsed
9650
9651 \begin_layout Standard
9652
9653
9654 \backslash
9655 /
9656 \end_layout
9657
9658 \end_inset
9659
9660 -no-peep-comments
9661 \begin_inset LatexCommand \index{-\/-no-peep-comments}
9662
9663 \end_inset
9664
9665
9666 \series default
9667  Don't include peep-hole comments in the generated asm files even if --fverbose-
9668 asm option is specified.
9669 \end_layout
9670
9671 \begin_layout List
9672 \labelwidthstring 00.00.0000
9673
9674 \series bold
9675 -
9676 \begin_inset ERT
9677 status collapsed
9678
9679 \begin_layout Standard
9680
9681
9682 \backslash
9683 /
9684 \end_layout
9685
9686 \end_inset
9687
9688 -i-code-in-asm
9689 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
9690
9691 \end_inset
9692
9693
9694 \series default
9695  Include i-codes in the asm file.
9696  Sounds like noise but is most helpful for debugging the compiler itself.
9697 \end_layout
9698
9699 \begin_layout List
9700 \labelwidthstring 00.00.0000
9701
9702 \series bold
9703 -
9704 \begin_inset ERT
9705 status collapsed
9706
9707 \begin_layout Standard
9708
9709
9710 \backslash
9711 /
9712 \end_layout
9713
9714 \end_inset
9715
9716 -less-pedantic
9717 \begin_inset LatexCommand \index{pedantic}
9718
9719 \end_inset
9720
9721
9722 \begin_inset LatexCommand \index{-\/-less-pedantic}
9723
9724 \end_inset
9725
9726
9727 \series default
9728
9729 \begin_inset LatexCommand \label{lyx:--less-pedantic}
9730
9731 \end_inset
9732
9733  Disable some of the more pedantic warnings
9734 \begin_inset LatexCommand \index{Warnings}
9735
9736 \end_inset
9737
9738 .
9739  For more details, see the less_pedantic pragma 
9740 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
9741
9742 \end_inset
9743
9744 .
9745 \end_layout
9746
9747 \begin_layout List
9748 \labelwidthstring 00.00.0000
9749
9750 \series bold
9751 -
9752 \begin_inset ERT
9753 status collapsed
9754
9755 \begin_layout Standard
9756
9757
9758 \backslash
9759 /
9760 \end_layout
9761
9762 \end_inset
9763
9764 -disable-warning\InsetSpace ~
9765 <nnnn>
9766 \begin_inset LatexCommand \index{-\/-disable-warning}
9767
9768 \end_inset
9769
9770
9771 \series default
9772  Disable specific warning with number <nnnn>.
9773 \end_layout
9774
9775 \begin_layout List
9776 \labelwidthstring 00.00.0000
9777
9778 \series bold
9779 -
9780 \begin_inset ERT
9781 status collapsed
9782
9783 \begin_layout Standard
9784
9785
9786 \backslash
9787 /
9788 \end_layout
9789
9790 \end_inset
9791
9792 -print-search-dirs
9793 \begin_inset LatexCommand \index{-\/-print-search-dirs}
9794
9795 \end_inset
9796
9797
9798 \series default
9799  Display the directories in the compiler's search path
9800 \end_layout
9801
9802 \begin_layout List
9803 \labelwidthstring 00.00.0000
9804
9805 \series bold
9806 -
9807 \begin_inset ERT
9808 status collapsed
9809
9810 \begin_layout Standard
9811
9812
9813 \backslash
9814 /
9815 \end_layout
9816
9817 \end_inset
9818
9819 -vc
9820 \begin_inset LatexCommand \index{-\/-vc}
9821
9822 \end_inset
9823
9824
9825 \series default
9826  Display errors and warnings using MSVC style, so you can use SDCC with
9827  the visual studio IDE
9828 \begin_inset LatexCommand \index{IDE}
9829
9830 \end_inset
9831
9832 .
9833  With SDCC both offering a GCC-like (the default) and a MSVC-like
9834 \begin_inset LatexCommand \index{MSVC output style}
9835
9836 \end_inset
9837
9838  output style, integration into most programming editors should be straightforwa
9839 rd.
9840 \end_layout
9841
9842 \begin_layout List
9843 \labelwidthstring 00.00.0000
9844
9845 \series bold
9846 -
9847 \begin_inset ERT
9848 status collapsed
9849
9850 \begin_layout Standard
9851
9852
9853 \backslash
9854 /
9855 \end_layout
9856
9857 \end_inset
9858
9859 -use-stdout
9860 \begin_inset LatexCommand \index{-\/-use-stdout}
9861
9862 \end_inset
9863
9864
9865 \series default
9866  Send errors and warnings to stdout instead of stderr.
9867 \end_layout
9868
9869 \begin_layout List
9870 \labelwidthstring 00.00.0000
9871
9872 \series bold
9873 -Wa\InsetSpace ~
9874 asmOption[,asmOption]
9875 \series default
9876
9877 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
9878
9879 \end_inset
9880
9881 ...
9882  Pass the asmOption to the assembler
9883 \begin_inset LatexCommand \index{Options assembler}
9884
9885 \end_inset
9886
9887
9888 \begin_inset LatexCommand \index{Assembler options}
9889
9890 \end_inset
9891
9892 .
9893  See file sdcc/as/doc/asxhtm.html for assembler options.cd
9894 \end_layout
9895
9896 \begin_layout List
9897 \labelwidthstring 00.00.0000
9898
9899 \series bold
9900 -
9901 \begin_inset ERT
9902 status collapsed
9903
9904 \begin_layout Standard
9905
9906
9907 \backslash
9908 /
9909 \end_layout
9910
9911 \end_inset
9912
9913 -std-sdcc89
9914 \begin_inset LatexCommand \index{-\/-std-sdcc89}
9915
9916 \end_inset
9917
9918
9919 \series default
9920  Generally follow the C89 standard, but allow SDCC features that conflict
9921  with the standard (default).
9922 \end_layout
9923
9924 \begin_layout List
9925 \labelwidthstring 00.00.0000
9926
9927 \series bold
9928 -
9929 \begin_inset ERT
9930 status collapsed
9931
9932 \begin_layout Standard
9933
9934
9935 \backslash
9936 /
9937 \end_layout
9938
9939 \end_inset
9940
9941 -std-c89
9942 \begin_inset LatexCommand \index{-\/-std-c89}
9943
9944 \end_inset
9945
9946
9947 \series default
9948  Follow the C89 standard and disable SDCC features that conflict with the
9949  standard.
9950 \end_layout
9951
9952 \begin_layout List
9953 \labelwidthstring 00.00.0000
9954
9955 \series bold
9956 -
9957 \begin_inset ERT
9958 status collapsed
9959
9960 \begin_layout Standard
9961
9962
9963 \backslash
9964 /
9965 \end_layout
9966
9967 \end_inset
9968
9969 -std-sdcc99
9970 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9971
9972 \end_inset
9973
9974
9975 \series default
9976  Generally follow the C99 standard, but allow SDCC features that conflict
9977  with the standard (incomplete support).
9978 \end_layout
9979
9980 \begin_layout List
9981 \labelwidthstring 00.00.0000
9982
9983 \series bold
9984 -
9985 \begin_inset ERT
9986 status collapsed
9987
9988 \begin_layout Standard
9989
9990
9991 \backslash
9992 /
9993 \end_layout
9994
9995 \end_inset
9996
9997 -std-c99
9998 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9999
10000 \end_inset
10001
10002
10003 \series default
10004  Follow the C99 standard and disable SDCC features that conflict with the
10005  standard (incomplete support).
10006 \end_layout
10007
10008 \begin_layout List
10009 \labelwidthstring 00.00.0000
10010
10011 \series bold
10012 -
10013 \begin_inset ERT
10014 status collapsed
10015
10016 \begin_layout Standard
10017
10018
10019 \backslash
10020 /
10021 \end_layout
10022
10023 \end_inset
10024
10025 -codeseg
10026 \series default
10027
10028 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10029
10030 \end_inset
10031
10032 \InsetSpace ~
10033 <Name> The name to be used for the code
10034 \begin_inset LatexCommand \index{code}
10035
10036 \end_inset
10037
10038  segment, default CSEG.
10039  This is useful if you need to tell the compiler to put the code in a special
10040  segment so you can later on tell the linker to put this segment in a special
10041  place in memory.
10042  Can be used for instance when using bank switching to put the code in a
10043  bank.
10044 \end_layout
10045
10046 \begin_layout List
10047 \labelwidthstring 00.00.0000
10048
10049 \series bold
10050 -
10051 \begin_inset ERT
10052 status collapsed
10053
10054 \begin_layout Standard
10055
10056
10057 \backslash
10058 /
10059 \end_layout
10060
10061 \end_inset
10062
10063 -constseg
10064 \series default
10065
10066 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10067
10068 \end_inset
10069
10070 \InsetSpace ~
10071 <Name> The name to be used for the const
10072 \begin_inset LatexCommand \index{const}
10073
10074 \end_inset
10075
10076  segment, default CONST.
10077  This is useful if you need to tell the compiler to put the const data in
10078  a special segment so you can later on tell the linker to put this segment
10079  in a special place in memory.
10080  Can be used for instance when using bank switching to put the const data
10081  in a bank.
10082 \end_layout
10083
10084 \begin_layout List
10085 \labelwidthstring 00.00.0000
10086
10087 \series bold
10088 -
10089 \begin_inset ERT
10090 status collapsed
10091
10092 \begin_layout Standard
10093
10094
10095 \backslash
10096 /
10097 \end_layout
10098
10099 \end_inset
10100
10101 -fdollars-in-identifiers
10102 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10103
10104 \end_inset
10105
10106
10107 \series default
10108  Permit '$' as an identifier character.
10109 \end_layout
10110
10111 \begin_layout List
10112 \labelwidthstring 00.00.0000
10113
10114 \series bold
10115 -
10116 \begin_inset ERT
10117 status collapsed
10118
10119 \begin_layout Standard
10120
10121
10122 \backslash
10123 /
10124 \end_layout
10125
10126 \end_inset
10127
10128 -more-pedantic
10129 \series default
10130
10131 \begin_inset LatexCommand \index{-\/-more-pedantic}
10132
10133 \end_inset
10134
10135
10136 \begin_inset LatexCommand \index{pedantic}
10137
10138 \end_inset
10139
10140  Actually this is 
10141 \series bold
10142 \emph on
10143 not
10144 \series default
10145 \emph default
10146  a SDCC compiler option but if you want 
10147 \emph on
10148 more
10149 \emph default
10150  warnings you can use a separate tool dedicated to syntax checking like
10151  splint
10152 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10153
10154 \end_inset
10155
10156
10157 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10158
10159 \end_inset
10160
10161  
10162 \begin_inset LatexCommand \url{http://www.splint.org}
10163
10164 \end_inset
10165
10166 .
10167  To make your source files parseable by splint you will have to include
10168  
10169 \family sans
10170 lint.h
10171 \family default
10172
10173 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10174
10175 \end_inset
10176
10177  in your source file and add brackets around extended keywords (like 
10178 \family sans
10179
10180 \begin_inset Quotes sld
10181 \end_inset
10182
10183 __at\InsetSpace ~
10184
10185 \series bold
10186 (
10187 \series default
10188 0xab
10189 \series bold
10190 )
10191 \series default
10192
10193 \begin_inset Quotes srd
10194 \end_inset
10195
10196
10197 \family default
10198  and 
10199 \family sans
10200
10201 \begin_inset Quotes sld
10202 \end_inset
10203
10204 __interrupt\InsetSpace ~
10205 (2)
10206 \begin_inset Quotes srd
10207 \end_inset
10208
10209
10210 \family default
10211 ).
10212  
10213 \newline
10214 Splint has an excellent on line manual at 
10215 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10216
10217 \end_inset
10218
10219  and it's capabilities go beyond pure syntax checking.
10220  You'll need to tell splint the location of SDCC's include files so a typical
10221  command line could look like this: 
10222 \newline
10223
10224 \family sans
10225 splint\InsetSpace ~
10226 -I\InsetSpace ~
10227 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10228 \InsetSpace ~
10229 myprogram.c
10230 \end_layout
10231
10232 \begin_layout List
10233 \labelwidthstring 00.00.0000
10234
10235 \series bold
10236 -
10237 \begin_inset ERT
10238 status collapsed
10239
10240 \begin_layout Standard
10241
10242
10243 \backslash
10244 /
10245 \end_layout
10246
10247 \end_inset
10248
10249 -short-is-8bits
10250 \series default
10251
10252 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10253
10254 \end_inset
10255
10256
10257 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10258
10259 \end_inset
10260
10261  Treat short as 8-bit (for backward compatibility with older versions of
10262  compiler - see section 
10263 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10264
10265 \end_inset
10266
10267 )
10268 \end_layout
10269
10270 \begin_layout Standard
10271 \begin_inset VSpace bigskip
10272 \end_inset
10273
10274
10275 \end_layout
10276
10277 \begin_layout Subsection
10278 Intermediate Dump Options
10279 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10280
10281 \end_inset
10282
10283
10284 \begin_inset LatexCommand \index{Options intermediate dump}
10285
10286 \end_inset
10287
10288
10289 \begin_inset LatexCommand \index{Intermediate dump options}
10290
10291 \end_inset
10292
10293
10294 \end_layout
10295
10296 \begin_layout Standard
10297 The following options are provided for the purpose of retargetting and debugging
10298  the compiler.
10299  They provide a means to dump the intermediate code (iCode
10300 \begin_inset LatexCommand \index{iCode}
10301
10302 \end_inset
10303
10304 ) generated by the compiler in human readable form at various stages of
10305  the compilation process.
10306  More on iCodes see chapter 
10307 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10308
10309 \end_inset
10310
10311  
10312 \begin_inset Quotes srd
10313 \end_inset
10314
10315 The anatomy of the compiler
10316 \begin_inset Quotes srd
10317 \end_inset
10318
10319 .
10320 \end_layout
10321
10322 \begin_layout List
10323 \labelwidthstring 00.00.0000
10324
10325 \series bold
10326 -
10327 \begin_inset ERT
10328 status collapsed
10329
10330 \begin_layout Standard
10331
10332
10333 \backslash
10334 /
10335 \end_layout
10336
10337 \end_inset
10338
10339 -dumpraw
10340 \begin_inset LatexCommand \index{-\/-dumpraw}
10341
10342 \end_inset
10343
10344
10345 \series default
10346  This option will cause the compiler to dump the intermediate code into
10347  a file of named 
10348 \emph on
10349 <source filename>.dumpraw
10350 \emph default
10351  just after the intermediate code has been generated for a function, i.e.
10352  before any optimizations are done.
10353  The basic blocks
10354 \begin_inset LatexCommand \index{Basic blocks}
10355
10356 \end_inset
10357
10358  at this stage ordered in the depth first number, so they may not be in
10359  sequence of execution.
10360 \end_layout
10361
10362 \begin_layout List
10363 \labelwidthstring 00.00.0000
10364
10365 \series bold
10366 -
10367 \begin_inset ERT
10368 status collapsed
10369
10370 \begin_layout Standard
10371
10372
10373 \backslash
10374 /
10375 \end_layout
10376
10377 \end_inset
10378
10379 -dumpgcse
10380 \begin_inset LatexCommand \index{-\/-dumpgcse}
10381
10382 \end_inset
10383
10384
10385 \series default
10386  Will create a dump of iCode's, after global subexpression elimination
10387 \begin_inset LatexCommand \index{Global subexpression elimination}
10388
10389 \end_inset
10390
10391 , into a file named 
10392 \emph on
10393 <source filename>.dumpgcse.
10394 \end_layout
10395
10396 \begin_layout List
10397 \labelwidthstring 00.00.0000
10398
10399 \series bold
10400 -
10401 \begin_inset ERT
10402 status collapsed
10403
10404 \begin_layout Standard
10405
10406
10407 \backslash
10408 /
10409 \end_layout
10410
10411 \end_inset
10412
10413 -dumpdeadcode
10414 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
10415
10416 \end_inset
10417
10418
10419 \series default
10420  Will create a dump of iCode's, after deadcode elimination
10421 \begin_inset LatexCommand \index{Dead-code elimination}
10422
10423 \end_inset
10424
10425 , into a file named 
10426 \emph on
10427 <source filename>.dumpdeadcode.
10428 \end_layout
10429
10430 \begin_layout List
10431 \labelwidthstring 00.00.0000
10432
10433 \series bold
10434 -
10435 \begin_inset ERT
10436 status collapsed
10437
10438 \begin_layout Standard
10439
10440
10441 \backslash
10442 /
10443 \end_layout
10444
10445 \end_inset
10446
10447 -dumploop
10448 \begin_inset LatexCommand \index{-\/-dumploop}
10449
10450 \end_inset
10451
10452
10453 \series default
10454 \size large
10455  
10456 \size default
10457 Will create a dump of iCode's, after loop optimizations
10458 \begin_inset LatexCommand \index{Loop optimization}
10459
10460 \end_inset
10461
10462 , into a file named 
10463 \emph on
10464 <source filename>.dumploop.
10465 \end_layout
10466
10467 \begin_layout List
10468 \labelwidthstring 00.00.0000
10469
10470 \series bold
10471 -
10472 \begin_inset ERT
10473 status collapsed
10474
10475 \begin_layout Standard
10476
10477
10478 \backslash
10479 /
10480 \end_layout
10481
10482 \end_inset
10483
10484 -dumprange
10485 \begin_inset LatexCommand \index{-\/-dumprange}
10486
10487 \end_inset
10488
10489
10490 \series default
10491 \size large
10492  
10493 \size default
10494 Will create a dump of iCode's, after live range analysis
10495 \begin_inset LatexCommand \index{Live range analysis}
10496
10497 \end_inset
10498
10499 , into a file named 
10500 \emph on
10501 <source filename>.dumprange.
10502 \end_layout
10503
10504 \begin_layout List
10505 \labelwidthstring 00.00.0000
10506
10507 \series bold
10508 -
10509 \begin_inset ERT
10510 status collapsed
10511
10512 \begin_layout Standard
10513
10514
10515 \backslash
10516 /
10517 \end_layout
10518
10519 \end_inset
10520
10521 -dumlrange
10522 \begin_inset LatexCommand \index{-\/-dumlrange}
10523
10524 \end_inset
10525
10526
10527 \series default
10528  Will dump the life ranges
10529 \begin_inset LatexCommand \index{Live range analysis}
10530
10531 \end_inset
10532
10533  for all symbols.
10534 \end_layout
10535
10536 \begin_layout List
10537 \labelwidthstring 00.00.0000
10538
10539 \series bold
10540 -
10541 \begin_inset ERT
10542 status collapsed
10543
10544 \begin_layout Standard
10545
10546
10547 \backslash
10548 /
10549 \end_layout
10550
10551 \end_inset
10552
10553 -dumpregassign
10554 \begin_inset LatexCommand \index{-\/-dumpregassign}
10555
10556 \end_inset
10557
10558
10559 \bar under
10560  
10561 \series default
10562 \bar default
10563 Will create a dump of iCode's, after register assignment
10564 \begin_inset LatexCommand \index{Register assignment}
10565
10566 \end_inset
10567
10568 , into a file named 
10569 \emph on
10570 <source filename>.dumprassgn.
10571 \end_layout
10572
10573 \begin_layout List
10574 \labelwidthstring 00.00.0000
10575
10576 \series bold
10577 -
10578 \begin_inset ERT
10579 status collapsed
10580
10581 \begin_layout Standard
10582
10583
10584 \backslash
10585 /
10586 \end_layout
10587
10588 \end_inset
10589
10590 -dumplrange
10591 \begin_inset LatexCommand \index{-\/-dumplrange}
10592
10593 \end_inset
10594
10595
10596 \series default
10597  Will create a dump of the live ranges of iTemp's
10598 \end_layout
10599
10600 \begin_layout List
10601 \labelwidthstring 00.00.0000
10602
10603 \series bold
10604 -
10605 \begin_inset ERT
10606 status collapsed
10607
10608 \begin_layout Standard
10609
10610
10611 \backslash
10612 /
10613 \end_layout
10614
10615 \end_inset
10616
10617 -dumpall
10618 \begin_inset LatexCommand \index{-\/-dumpall}
10619
10620 \end_inset
10621
10622
10623 \size large
10624 \bar under
10625  
10626 \series default
10627 \size default
10628 \bar default
10629 Will cause all the above mentioned dumps to be created.
10630 \end_layout
10631
10632 \begin_layout Standard
10633 \begin_inset VSpace bigskip
10634 \end_inset
10635
10636
10637 \end_layout
10638
10639 \begin_layout Subsection
10640 Redirecting output on Windows Shells
10641 \end_layout
10642
10643 \begin_layout Standard
10644 By default SDCC writes it's error messages to 
10645 \begin_inset Quotes sld
10646 \end_inset
10647
10648 standard error
10649 \begin_inset Quotes srd
10650 \end_inset
10651
10652 .
10653  To force all messages to 
10654 \begin_inset Quotes sld
10655 \end_inset
10656
10657 standard output
10658 \begin_inset Quotes srd
10659 \end_inset
10660
10661  use 
10662 \series bold
10663 -
10664 \series default
10665 \emph on
10666
10667 \begin_inset ERT
10668 status collapsed
10669
10670 \begin_layout Standard
10671
10672
10673 \backslash
10674 /
10675 \end_layout
10676
10677 \end_inset
10678
10679
10680 \series bold
10681 \emph default
10682 -
10683 \series default
10684 use-stdout
10685 \begin_inset LatexCommand \index{-\/-use-stdout}
10686
10687 \end_inset
10688
10689 .
10690  Additionally, if you happen to have visual studio installed in your windows
10691  machine, you can use it to compile your sources using a custom build and
10692  the SDCC -
10693 \emph on
10694
10695 \begin_inset ERT
10696 status collapsed
10697
10698 \begin_layout Standard
10699
10700
10701 \backslash
10702 /
10703 \end_layout
10704
10705 \end_inset
10706
10707
10708 \emph default
10709 -vc
10710 \begin_inset LatexCommand \index{-\/-vc}
10711
10712 \end_inset
10713
10714  option.
10715  Something like this should work:
10716 \newline
10717
10718 \newline
10719
10720 \series bold
10721 c:
10722 \backslash
10723 sdcc
10724 \backslash
10725 bin
10726 \backslash
10727 sdcc.exe -
10728 \series default
10729 \emph on
10730
10731 \begin_inset ERT
10732 status collapsed
10733
10734 \begin_layout Standard
10735
10736
10737 \backslash
10738 /
10739 \end_layout
10740
10741 \end_inset
10742
10743
10744 \series bold
10745 \emph default
10746 -vc -
10747 \series default
10748 \emph on
10749
10750 \begin_inset ERT
10751 status collapsed
10752
10753 \begin_layout Standard
10754
10755
10756 \backslash
10757 /
10758 \end_layout
10759
10760 \end_inset
10761
10762
10763 \series bold
10764 \emph default
10765 -model-large -c $(InputPath)
10766 \series default
10767
10768 \begin_inset VSpace bigskip
10769 \end_inset
10770
10771
10772 \end_layout
10773
10774 \begin_layout Section
10775 Environment variables
10776 \begin_inset LatexCommand \index{Environment variables}
10777
10778 \end_inset
10779
10780
10781 \end_layout
10782
10783 \begin_layout Standard
10784 SDCC recognizes the following environment variables:
10785 \end_layout
10786
10787 \begin_layout List
10788 \labelwidthstring 00.00.0000
10789
10790 \series bold
10791 SDCC_LEAVE_SIGNALS
10792 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
10793
10794 \end_inset
10795
10796
10797 \series default
10798  SDCC installs a signal handler
10799 \begin_inset LatexCommand \index{signal handler}
10800
10801 \end_inset
10802
10803  to be able to delete temporary files after an user break (^C) or an exception.
10804  If this environment variable is set, SDCC won't install the signal handler
10805  in order to be able to debug SDCC.
10806 \end_layout
10807
10808 \begin_layout List
10809 \labelwidthstring 00.00.0000
10810
10811 \series bold
10812 TMP,\InsetSpace ~
10813 TEMP,\InsetSpace ~
10814 TMPDIR
10815 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
10816
10817 \end_inset
10818
10819
10820 \series default
10821  Path, where temporary files will be created.
10822  The order of the variables is the search order.
10823  In a standard *nix environment these variables are not set, and there's
10824  no need to set them.
10825  On Windows it's recommended to set one of them.
10826 \end_layout
10827
10828 \begin_layout List
10829 \labelwidthstring 00.00.0000
10830
10831 \series bold
10832 SDCC_HOME
10833 \begin_inset LatexCommand \index{SDCC\_HOME}
10834
10835 \end_inset
10836
10837
10838 \series default
10839  Path, see section 
10840 \begin_inset LatexCommand \ref{sub:Install-paths}
10841
10842 \end_inset
10843
10844 \InsetSpace ~
10845
10846 \begin_inset Quotes sld
10847 \end_inset
10848
10849  Install Paths
10850 \begin_inset Quotes srd
10851 \end_inset
10852
10853 .
10854 \end_layout
10855
10856 \begin_layout List
10857 \labelwidthstring 00.00.0000
10858
10859 \series bold
10860 SDCC_INCLUDE
10861 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
10862
10863 \end_inset
10864
10865
10866 \series default
10867  Path, see section 
10868 \begin_inset LatexCommand \ref{sub:Search-Paths}
10869
10870 \end_inset
10871
10872 \InsetSpace ~
10873
10874 \begin_inset Quotes sld
10875 \end_inset
10876
10877 Search Paths
10878 \begin_inset Quotes srd
10879 \end_inset
10880
10881 .
10882 \end_layout
10883
10884 \begin_layout List
10885 \labelwidthstring 00.00.0000
10886
10887 \series bold
10888 SDCC_LIB
10889 \begin_inset LatexCommand \index{SDCC\_LIB}
10890
10891 \end_inset
10892
10893
10894 \series default
10895  Path, see section 
10896 \begin_inset LatexCommand \ref{sub:Search-Paths}
10897
10898 \end_inset
10899
10900 \InsetSpace ~
10901
10902 \begin_inset Quotes sld
10903 \end_inset
10904
10905 Search Paths
10906 \begin_inset Quotes srd
10907 \end_inset
10908
10909 ..
10910 \end_layout
10911
10912 \begin_layout Standard
10913 There are some more environment variables recognized by SDCC, but these
10914  are solely used for debugging purposes.
10915  They can change or disappear very quickly, and will never be documented.
10916 \begin_inset VSpace bigskip
10917 \end_inset
10918
10919
10920 \end_layout
10921
10922 \begin_layout Section
10923 Storage Class Language Extensions
10924 \end_layout
10925
10926 \begin_layout Subsection
10927 MCS51/DS390 Storage Class
10928 \begin_inset LatexCommand \index{Storage class}
10929
10930 \end_inset
10931
10932  Language Extensions
10933 \end_layout
10934
10935 \begin_layout Standard
10936 In addition to the ANSI storage classes SDCC allows the following MCS51
10937  specific storage classes:
10938 \end_layout
10939
10940 \begin_layout Subsubsection
10941 data
10942 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10943
10944 \end_inset
10945
10946
10947 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10948
10949 \end_inset
10950
10951  / near
10952 \begin_inset LatexCommand \index{near (storage class)}
10953
10954 \end_inset
10955
10956
10957 \begin_inset LatexCommand \index{\_\_near (storage class)}
10958
10959 \end_inset
10960
10961
10962 \end_layout
10963
10964 \begin_layout Standard
10965 This is the 
10966 \series bold
10967 default
10968 \series default
10969  storage class for the Small Memory model (
10970 \emph on
10971 data
10972 \emph default
10973  and 
10974 \emph on
10975 near
10976 \emph default
10977  or the more ANSI-C compliant forms 
10978 \emph on
10979 __data
10980 \emph default
10981  and 
10982 \emph on
10983 __near
10984 \emph default
10985  can be used synonymously).
10986  Variables declared with this storage class will be allocated in the directly
10987  addressable portion of the internal RAM of a 8051, e.g.:
10988 \end_layout
10989
10990 \begin_layout Verse
10991
10992 \family typewriter
10993 __data unsigned char test_data;
10994 \end_layout
10995
10996 \begin_layout Standard
10997 Writing 0x01 to this variable generates the assembly code:
10998 \end_layout
10999
11000 \begin_layout Verse
11001
11002 \family typewriter
11003 75*00 01\InsetSpace ~
11004 \InsetSpace ~
11005 \InsetSpace ~
11006 mov\InsetSpace ~
11007 \InsetSpace ~
11008 _test_data,#0x01
11009 \end_layout
11010
11011 \begin_layout Subsubsection
11012 xdata
11013 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11014
11015 \end_inset
11016
11017
11018 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11019
11020 \end_inset
11021
11022  / far
11023 \begin_inset LatexCommand \index{far (storage class)}
11024
11025 \end_inset
11026
11027
11028 \begin_inset LatexCommand \index{\_\_far (storage class)}
11029
11030 \end_inset
11031
11032
11033 \end_layout
11034
11035 \begin_layout Standard
11036 Variables declared with this storage class will be placed in the external
11037  RAM.
11038  This is the 
11039 \series bold
11040 default
11041 \series default
11042  storage class for the Large Memory model, e.g.:
11043 \end_layout
11044
11045 \begin_layout Verse
11046
11047 \family typewriter
11048 __xdata unsigned char test_xdata;
11049 \end_layout
11050
11051 \begin_layout Standard
11052 Writing 0x01 to this variable generates the assembly code:
11053 \end_layout
11054
11055 \begin_layout Verse
11056
11057 \family typewriter
11058 90s00r00\InsetSpace ~
11059 \InsetSpace ~
11060 \InsetSpace ~
11061 mov\InsetSpace ~
11062 \InsetSpace ~
11063 dptr,#_test_xdata 
11064 \newline
11065 74\InsetSpace ~
11066 01\InsetSpace ~
11067 \InsetSpace ~
11068 \InsetSpace ~
11069 \InsetSpace ~
11070 \InsetSpace ~
11071 \InsetSpace ~
11072 mov\InsetSpace ~
11073 \InsetSpace ~
11074 a,#0x01 
11075 \newline
11076 F0\InsetSpace ~
11077 \InsetSpace ~
11078 \InsetSpace ~
11079 \InsetSpace ~
11080 \InsetSpace ~
11081 \InsetSpace ~
11082 \InsetSpace ~
11083 \InsetSpace ~
11084 \InsetSpace ~
11085 movx\InsetSpace ~
11086 @dptr,a 
11087 \end_layout
11088
11089 \begin_layout Subsubsection
11090 idata
11091 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11092
11093 \end_inset
11094
11095
11096 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11097
11098 \end_inset
11099
11100
11101 \end_layout
11102
11103 \begin_layout Standard
11104 Variables declared with this storage class will be allocated into the indirectly
11105  addressable portion of the internal ram of a 8051, e.g.:
11106 \end_layout
11107
11108 \begin_layout Verse
11109
11110 \family typewriter
11111 __idata unsigned char test_idata;
11112 \end_layout
11113
11114 \begin_layout Standard
11115 Writing 0x01 to this variable generates the assembly code:
11116 \end_layout
11117
11118 \begin_layout Verse
11119
11120 \family typewriter
11121 78r00\InsetSpace ~
11122 \InsetSpace ~
11123 \InsetSpace ~
11124 \InsetSpace ~
11125 \InsetSpace ~
11126 \InsetSpace ~
11127 \InsetSpace ~
11128 mov\InsetSpace ~
11129 \InsetSpace ~
11130 r0,#_test_idata
11131 \newline
11132 76\InsetSpace ~
11133 01\InsetSpace ~
11134 \InsetSpace ~
11135 \InsetSpace ~
11136 \InsetSpace ~
11137 \InsetSpace ~
11138 \InsetSpace ~
11139 \InsetSpace ~
11140 mov\InsetSpace ~
11141 \InsetSpace ~
11142 @r0,#0x01
11143 \end_layout
11144
11145 \begin_layout Standard
11146 Please note, the first 128 byte of idata physically access the same RAM
11147  as the data memory.
11148  The original 8051 had 128 byte idata memory, nowadays most devices have
11149  256 byte idata memory.
11150  The stack
11151 \begin_inset LatexCommand \index{stack}
11152
11153 \end_inset
11154
11155  is located in idata memory.
11156 \end_layout
11157
11158 \begin_layout Subsubsection
11159 pdata
11160 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11161
11162 \end_inset
11163
11164
11165 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11166
11167 \end_inset
11168
11169
11170 \end_layout
11171
11172 \begin_layout Standard
11173 Paged xdata access is just as straightforward as using the other addressing
11174  modes of a 8051.
11175  It is typically located at the start of xdata and has a maximum size of
11176  256 bytes.
11177  The following example writes 0x01 to the pdata variable.
11178  Please note, pdata access physically accesses xdata memory.
11179  The high byte of the address is determined by port P2 
11180 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11181
11182 \end_inset
11183
11184 (or in case of some 8051 variants by a separate Special Function Register,
11185  see section 
11186 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11187
11188 \end_inset
11189
11190 ).
11191  This is the 
11192 \series bold
11193 default
11194 \series default
11195  storage class for the Medium Memory model, e.g.:
11196 \end_layout
11197
11198 \begin_layout Verse
11199
11200 \family typewriter
11201 __pdata unsigned char test_pdata;
11202 \end_layout
11203
11204 \begin_layout Standard
11205 Writing 0x01 to this variable generates the assembly code:
11206 \end_layout
11207
11208 \begin_layout Verse
11209
11210 \family typewriter
11211 78r00\InsetSpace ~
11212 \InsetSpace ~
11213 \InsetSpace ~
11214 \InsetSpace ~
11215 \InsetSpace ~
11216 \InsetSpace ~
11217 mov r0,#_test_pdata
11218 \newline
11219 74 01\InsetSpace ~
11220 \InsetSpace ~
11221 \InsetSpace ~
11222 \InsetSpace ~
11223 \InsetSpace ~
11224 \InsetSpace ~
11225 mov a,#0x01 
11226 \newline
11227 F2\InsetSpace ~
11228 \InsetSpace ~
11229 \InsetSpace ~
11230 \InsetSpace ~
11231 \InsetSpace ~
11232 \InsetSpace ~
11233 \InsetSpace ~
11234 \InsetSpace ~
11235 \InsetSpace ~
11236 movx @r0,a
11237 \end_layout
11238
11239 \begin_layout Standard
11240 If the -
11241 \begin_inset ERT
11242 status collapsed
11243
11244 \begin_layout Standard
11245
11246
11247 \backslash
11248 /
11249 \end_layout
11250
11251 \end_inset
11252
11253 -xstack
11254 \begin_inset LatexCommand \index{-\/-xstack}
11255
11256 \end_inset
11257
11258  option is used the pdata memory area is followed by the xstack memory area
11259  and the sum of their sizes is limited to 256 bytes.
11260 \end_layout
11261
11262 \begin_layout Subsubsection
11263 code
11264 \begin_inset LatexCommand \index{code}
11265
11266 \end_inset
11267
11268
11269 \begin_inset LatexCommand \index{\_\_code}
11270
11271 \end_inset
11272
11273
11274 \end_layout
11275
11276 \begin_layout Standard
11277 'Variables' declared with this storage class will be placed in the code
11278  memory:
11279 \end_layout
11280
11281 \begin_layout Verse
11282
11283 \family typewriter
11284 __code unsigned char test_code;
11285 \end_layout
11286
11287 \begin_layout Standard
11288 Read access to this variable generates the assembly code:
11289 \end_layout
11290
11291 \begin_layout Verse
11292
11293 \family typewriter
11294 90s00r6F\InsetSpace ~
11295 \InsetSpace ~
11296 \InsetSpace ~
11297 mov dptr,#_test_code
11298 \newline
11299 E4\InsetSpace ~
11300 \InsetSpace ~
11301 \InsetSpace ~
11302 \InsetSpace ~
11303 \InsetSpace ~
11304 \InsetSpace ~
11305 \InsetSpace ~
11306 \InsetSpace ~
11307 \InsetSpace ~
11308 clr a
11309 \newline
11310 93\InsetSpace ~
11311 \InsetSpace ~
11312 \InsetSpace ~
11313 \InsetSpace ~
11314 \InsetSpace ~
11315 \InsetSpace ~
11316 \InsetSpace ~
11317 \InsetSpace ~
11318 \InsetSpace ~
11319 movc a,@a+dptr 
11320 \end_layout
11321
11322 \begin_layout Standard
11323
11324 \family typewriter
11325 char
11326 \family default
11327  indexed arrays of characters in code memory can be accessed efficiently:
11328 \end_layout
11329
11330 \begin_layout Verse
11331
11332 \family typewriter
11333 __code char test_array[] = {'c','h','e','a','p'}; 
11334 \end_layout
11335
11336 \begin_layout Standard
11337 Read access to this array using an 8-bit unsigned index generates the assembly
11338  code:
11339 \end_layout
11340
11341 \begin_layout Verse
11342
11343 \family typewriter
11344 E5*00\InsetSpace ~
11345 \InsetSpace ~
11346 \InsetSpace ~
11347 \InsetSpace ~
11348 \InsetSpace ~
11349 \InsetSpace ~
11350 mov a,_index 
11351 \end_layout
11352
11353 \begin_layout Verse
11354
11355 \family typewriter
11356 90s00r41\InsetSpace ~
11357 \InsetSpace ~
11358 \InsetSpace ~
11359 mov dptr,#_test_array
11360 \end_layout
11361
11362 \begin_layout Verse
11363
11364 \family typewriter
11365 93\InsetSpace ~
11366 \InsetSpace ~
11367 \InsetSpace ~
11368 \InsetSpace ~
11369 \InsetSpace ~
11370 \InsetSpace ~
11371 \InsetSpace ~
11372 \InsetSpace ~
11373 \InsetSpace ~
11374 movc a,@a+dptr 
11375 \end_layout
11376
11377 \begin_layout Subsubsection
11378 bit
11379 \begin_inset LatexCommand \index{bit}
11380
11381 \end_inset
11382
11383
11384 \begin_inset LatexCommand \index{\_\_bit}
11385
11386 \end_inset
11387
11388
11389 \end_layout
11390
11391 \begin_layout Standard
11392 This is a data-type and a storage class specifier.
11393  When a variable is declared as a bit, it is allocated into the bit addressable
11394  memory of 8051, e.g.:
11395 \end_layout
11396
11397 \begin_layout Verse
11398
11399 \family typewriter
11400 __bit test_bit;
11401 \end_layout
11402
11403 \begin_layout Standard
11404 Writing 1 to this variable generates the assembly code:
11405 \end_layout
11406
11407 \begin_layout Verse
11408
11409 \family typewriter
11410 D2*00\InsetSpace ~
11411 \InsetSpace ~
11412 \InsetSpace ~
11413 \InsetSpace ~
11414 \InsetSpace ~
11415 \InsetSpace ~
11416 \InsetSpace ~
11417 setb\InsetSpace ~
11418 _test_bit
11419 \end_layout
11420
11421 \begin_layout Standard
11422 The bit addressable memory consists of 128 bits which are located from 0x20
11423  to 0x2f in data memory.
11424  
11425 \newline
11426 Apart from this 8051 specific storage class most architectures support
11427  ANSI-C bitfields
11428 \begin_inset LatexCommand \index{bitfields}
11429
11430 \end_inset
11431
11432
11433 \begin_inset Foot
11434 status open
11435
11436 \begin_layout Standard
11437 Not really meant as examples, but nevertheless showing what bitfields are
11438  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
11439 \end_layout
11440
11441 \end_inset
11442
11443 .
11444  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
11445  signed modifier are implemented as unsigned.
11446 \end_layout
11447
11448 \begin_layout Subsubsection
11449 sfr
11450 \begin_inset LatexCommand \index{sfr}
11451
11452 \end_inset
11453
11454
11455 \begin_inset LatexCommand \index{\_\_sfr}
11456
11457 \end_inset
11458
11459  / sfr16
11460 \begin_inset LatexCommand \index{sfr16}
11461
11462 \end_inset
11463
11464
11465 \begin_inset LatexCommand \index{\_\_sfr16}
11466
11467 \end_inset
11468
11469  / sfr32
11470 \begin_inset LatexCommand \index{sfr32}
11471
11472 \end_inset
11473
11474
11475 \begin_inset LatexCommand \index{\_\_sfr32}
11476
11477 \end_inset
11478
11479  / sbit
11480 \begin_inset LatexCommand \index{\_\_sbit}
11481
11482 \end_inset
11483
11484
11485 \begin_inset LatexCommand \index{sbit}
11486
11487 \end_inset
11488
11489
11490 \end_layout
11491
11492 \begin_layout Standard
11493 Like the bit keyword, 
11494 \emph on
11495 sfr / sfr16 / sfr32 / sbit 
11496 \emph default
11497 signify both a data-type and storage class, they are used to describe the
11498  
11499 \emph on
11500 s
11501 \emph default
11502 pecial 
11503 \emph on
11504 f
11505 \emph default
11506 unction 
11507 \emph on
11508 r
11509 \emph default
11510 egisters and 
11511 \emph on
11512 s
11513 \emph default
11514 pecial 
11515 \emph on
11516 bit
11517 \emph default
11518  variables of a 8051, eg:
11519 \end_layout
11520
11521 \begin_layout Verse
11522
11523 \family typewriter
11524 __sfr __at
11525 \begin_inset LatexCommand \index{at}
11526
11527 \end_inset
11528
11529
11530 \begin_inset LatexCommand \index{\_\_at}
11531
11532 \end_inset
11533
11534  (0x80) P0;\InsetSpace ~
11535  /* special function register P0 at location 0x80 */
11536 \newline
11537
11538 \newline
11539 /* 16 bit
11540  special function register combination for timer 0
11541 \newline
11542 \InsetSpace ~
11543 \InsetSpace ~
11544  with the high byte at
11545  location 0x8C and the low byte at location 0x8A */
11546 \newline
11547 __sfr16 __at (0x8C8A)
11548  TMR0;
11549 \newline
11550
11551 \newline
11552 __sbit __at
11553 \begin_inset LatexCommand \index{at}
11554
11555 \end_inset
11556
11557
11558 \begin_inset LatexCommand \index{\_\_at}
11559
11560 \end_inset
11561
11562  (0xd7) CY;\InsetSpace ~
11563  /* CY (Carry Flag
11564 \begin_inset LatexCommand \index{Flags}
11565
11566 \end_inset
11567
11568
11569 \begin_inset LatexCommand \index{Carry flag}
11570
11571 \end_inset
11572
11573 ) */
11574 \end_layout
11575
11576 \begin_layout Standard
11577 Special function registers which are located on an address dividable by
11578  8 are bit-addressable, an
11579 \emph on
11580  sbit
11581 \emph default
11582  addresses a specific bit within these sfr.
11583 \newline
11584 16 Bit and 32 bit special function
11585  register combinations which require a certain access order are better not
11586  declared using 
11587 \emph on
11588 sfr16
11589 \emph default
11590  or 
11591 \emph on
11592 sfr32.
11593
11594 \emph default
11595  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
11596  this is not guaranteed.
11597 \newline
11598
11599 \end_layout
11600
11601 \begin_layout Standard
11602 Please note, if you use a header file which was written for another compiler
11603  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
11604  likely be 
11605 \emph on
11606 not 
11607 \emph default
11608 compatible.
11609  Specifically the syntax 
11610 \family typewriter
11611 \InsetSpace ~
11612 sfr P0 = 0x80;\InsetSpace ~
11613
11614 \family default
11615  is compiled 
11616 \emph on
11617 without warning
11618 \emph default
11619  by SDCC to an assignment of 0x80 to a variable called P0 
11620 \family typewriter
11621
11622 \begin_inset Marginal
11623 status collapsed
11624
11625 \begin_layout Standard
11626
11627 \series bold
11628 \InsetSpace ~
11629 !
11630 \end_layout
11631
11632 \end_inset
11633
11634 .
11635  
11636 \family default
11637 Nevertheless it is possible to write header files
11638 \begin_inset LatexCommand \index{Header files}
11639
11640 \end_inset
11641
11642
11643 \begin_inset LatexCommand \index{Include files}
11644
11645 \end_inset
11646
11647  which can be shared among different compilers (see section 
11648 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
11649
11650 \end_inset
11651
11652 ).
11653  
11654 \end_layout
11655
11656 \begin_layout Subsubsection
11657 Pointers
11658 \begin_inset LatexCommand \index{Pointer}
11659
11660 \end_inset
11661
11662  to MCS51/DS390 specific memory spaces
11663 \end_layout
11664
11665 \begin_layout Standard
11666 SDCC allows (via language extensions) pointers to explicitly point to any
11667  of the memory spaces
11668 \begin_inset LatexCommand \index{Memory model}
11669
11670 \end_inset
11671
11672  of the 8051.
11673  In addition to the explicit pointers, the compiler uses (by default) generic
11674  pointers which can be used to point to any of the memory spaces.
11675 \newline
11676
11677 \newline
11678 Pointer
11679  declaration examples:
11680 \end_layout
11681
11682 \begin_layout Verse
11683
11684 \family typewriter
11685 /* pointer physically in internal ram pointing to object in external ram
11686  */ 
11687 \newline
11688 __xdata unsigned char * __data p;
11689 \newline
11690
11691 \newline
11692 /* pointer physically in external ram
11693  pointing to object in internal ram */ 
11694 \newline
11695 __data unsigned char * __xdata p;
11696 \newline
11697
11698 \newline
11699 /*
11700  pointer physically in code rom pointing to data in xdata space */ 
11701 \newline
11702 __xdata
11703  unsigned char * __code p;
11704 \newline
11705
11706 \newline
11707 /* pointer physically in code space pointing to
11708  data in code space */ 
11709 \newline
11710 __code unsigned char * __code p;
11711 \newline
11712
11713 \newline
11714 /* generic pointer
11715  physically located in xdata space */
11716 \newline
11717 unsigned char * __xdata p;
11718 \newline
11719
11720 \newline
11721 /* generic
11722  pointer physically located in default memory space */
11723 \newline
11724 unsigned char * p;
11725 \newline
11726
11727 \newline
11728 /*
11729  the following is a function pointer
11730 \begin_inset LatexCommand \index{function pointer}
11731
11732 \end_inset
11733
11734  physically located in data space */
11735 \newline
11736 char (* __data fp)(void);
11737 \end_layout
11738
11739 \begin_layout Standard
11740 Well you get the idea.
11741  
11742 \newline
11743
11744 \newline
11745 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
11746 \emph on
11747 generic
11748 \emph default
11749  pointers.
11750  
11751 \size small
11752
11753 \newline
11754
11755 \newline
11756
11757 \size default
11758 The highest order byte of the 
11759 \emph on
11760 generic
11761 \emph default
11762  pointers contains the data space information.
11763  Assembler support routines are called whenever data is stored or retrieved
11764  using 
11765 \emph on
11766 generic
11767 \emph default
11768  pointers.
11769  These are useful for developing reusable library
11770 \begin_inset LatexCommand \index{Libraries}
11771
11772 \end_inset
11773
11774  routines.
11775  Explicitly specifying the pointer
11776 \begin_inset LatexCommand \index{pointer}
11777
11778 \end_inset
11779
11780  type will generate the most efficient code.
11781 \end_layout
11782
11783 \begin_layout Subsubsection
11784 Notes on MCS51 memory
11785 \begin_inset LatexCommand \index{MCS51 memory}
11786
11787 \end_inset
11788
11789  layout
11790 \end_layout
11791
11792 \begin_layout Standard
11793 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
11794  RAM memory which is structured as follows:
11795 \newline
11796
11797 \newline
11798 - Bytes 00-1F - 32 bytes to hold
11799  up to 4 banks of the registers R0 to R7, 
11800 \newline
11801 - Bytes 20-2F - 16 bytes to hold
11802  128 bit
11803 \begin_inset LatexCommand \index{bit}
11804
11805 \end_inset
11806
11807  variables and, 
11808 \newline
11809 - Bytes 30-7F - 80 bytes for general purpose use.
11810 \newline
11811
11812 \end_layout
11813
11814 \begin_layout Standard
11815 Additionally some members of the MCS51 family may have up to 128 bytes of
11816  additional, indirectly addressable, internal RAM memory (
11817 \emph on
11818 idata
11819 \emph default
11820
11821 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11822
11823 \end_inset
11824
11825
11826 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11827
11828 \end_inset
11829
11830 ).
11831  Furthermore, some chips may have some built in external memory (
11832 \emph on
11833 xdata
11834 \emph default
11835
11836 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11837
11838 \end_inset
11839
11840
11841 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11842
11843 \end_inset
11844
11845 ) which should not be confused with the internal, directly addressable RAM
11846  memory (
11847 \emph on
11848 data
11849 \emph default
11850
11851 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11852
11853 \end_inset
11854
11855
11856 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11857
11858 \end_inset
11859
11860 ).
11861  Sometimes this built in 
11862 \emph on
11863 xdata
11864 \emph default
11865  memory has to be activated before using it (you can probably find this
11866  information on the datasheet of the microcontroller your are using, see
11867  also section 
11868 \begin_inset LatexCommand \ref{sub:Startup-Code}
11869
11870 \end_inset
11871
11872 \InsetSpace ~
11873 Startup-Code).
11874 \end_layout
11875
11876 \begin_layout Standard
11877 Normally SDCC will only use the first bank
11878 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11879
11880 \end_inset
11881
11882  of registers (register bank 0), but it is possible to specify that other
11883  banks of registers (keyword 
11884 \emph on
11885 using
11886 \emph default
11887  
11888 \emph on
11889
11890 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11891
11892 \end_inset
11893
11894
11895 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11896
11897 \end_inset
11898
11899
11900 \emph default
11901 ) should be used for example in interrupt
11902 \begin_inset LatexCommand \index{interrupt}
11903
11904 \end_inset
11905
11906
11907 \begin_inset LatexCommand \index{\_\_interrupt}
11908
11909 \end_inset
11910
11911  routines.
11912  By default, the compiler will place the stack after the last byte of allocated
11913  memory for variables.
11914  For example, if the first 2 banks of registers are used, and only four
11915  bytes are used for 
11916 \emph on
11917 data
11918 \emph default
11919  variables, it will position the base of the internal stack at address 20
11920  (0x14).
11921  This implies that as the stack
11922 \begin_inset LatexCommand \index{stack}
11923
11924 \end_inset
11925
11926  grows, it will use up the remaining register banks, and the 16 bytes used
11927  by the 128 bit variables, and 80 bytes for general purpose use.
11928  If any bit variables are used, the data variables will be placed in unused
11929  register banks and after the byte holding the last bit variable.
11930  For example, if register banks 0 and 1 are used, and there are 9 bit variables
11931  (two bytes used), 
11932 \emph on
11933 data
11934 \emph default
11935  variables will be placed starting from address 0x10 to 0x20 and continue
11936  at address 0x22.
11937  You can also use -
11938 \begin_inset ERT
11939 status collapsed
11940
11941 \begin_layout Standard
11942
11943
11944 \backslash
11945 /
11946 \end_layout
11947
11948 \end_inset
11949
11950 -data-loc
11951 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
11952
11953 \end_inset
11954
11955  to specify the start address of the 
11956 \emph on
11957 data
11958 \emph default
11959  and -
11960 \begin_inset ERT
11961 status collapsed
11962
11963 \begin_layout Standard
11964
11965
11966 \backslash
11967 /
11968 \end_layout
11969
11970 \end_inset
11971
11972 -iram-size
11973 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
11974
11975 \end_inset
11976
11977  to specify the size of the total internal RAM (
11978 \emph on
11979 data
11980 \emph default
11981 +
11982 \emph on
11983 idata
11984 \emph default
11985 ).
11986  
11987 \newline
11988
11989 \end_layout
11990
11991 \begin_layout Standard
11992 By default the 8051 linker will place the stack after the last byte of (i)data
11993  variables.
11994  Option -
11995 \begin_inset ERT
11996 status collapsed
11997
11998 \begin_layout Standard
11999
12000
12001 \backslash
12002 /
12003 \end_layout
12004
12005 \end_inset
12006
12007 -stack-loc
12008 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12009
12010 \end_inset
12011
12012  allows you to specify the start of the stack, i.e.
12013  you could start it after any data in the general purpose area.
12014  If your microcontroller has additional indirectly addressable internal
12015  RAM (
12016 \emph on
12017 idata
12018 \emph default
12019 ) you can place the stack on it.
12020  You may also need to use -
12021 \begin_inset ERT
12022 status collapsed
12023
12024 \begin_layout Standard
12025
12026
12027 \backslash
12028 /
12029 \end_layout
12030
12031 \end_inset
12032
12033 -xdata-loc
12034 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12035
12036 \end_inset
12037
12038  to set the start address of the external RAM (
12039 \emph on
12040 xdata
12041 \emph default
12042 ) and -
12043 \begin_inset ERT
12044 status collapsed
12045
12046 \begin_layout Standard
12047
12048
12049 \backslash
12050 /
12051 \end_layout
12052
12053 \end_inset
12054
12055 -xram-size
12056 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12057
12058 \end_inset
12059
12060  to specify its size.
12061  Same goes for the code memory, using -
12062 \begin_inset ERT
12063 status collapsed
12064
12065 \begin_layout Standard
12066
12067
12068 \backslash
12069 /
12070 \end_layout
12071
12072 \end_inset
12073
12074 -code-loc
12075 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12076
12077 \end_inset
12078
12079  and -
12080 \begin_inset ERT
12081 status collapsed
12082
12083 \begin_layout Standard
12084
12085
12086 \backslash
12087 /
12088 \end_layout
12089
12090 \end_inset
12091
12092 -code-size
12093 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12094
12095 \end_inset
12096
12097 .
12098  If in doubt, don't specify any options and see if the resulting memory
12099  layout is appropriate, then you can adjust it.
12100 \end_layout
12101
12102 \begin_layout Standard
12103 The linker generates two files with memory allocation information.
12104  The first, with extension .map
12105 \begin_inset LatexCommand \index{<file>.map}
12106
12107 \end_inset
12108
12109  shows all the variables and segments.
12110  The second with extension .mem
12111 \begin_inset LatexCommand \index{<file>.mem}
12112
12113 \end_inset
12114
12115  shows the final memory layout.
12116  The linker will complain either if memory segments overlap, there is not
12117  enough memory, or there is not enough space for stack.
12118  If you get any linking warnings and/or errors related to stack or segments
12119  allocation, take a look at either the .map or .mem files to find out what
12120  the problem is.
12121  The .mem file may even suggest a solution to the problem.
12122 \begin_inset VSpace bigskip
12123 \end_inset
12124
12125
12126 \end_layout
12127
12128 \begin_layout Subsection
12129 Z80/Z180 Storage Class
12130 \begin_inset LatexCommand \index{Z80!Storage class}
12131
12132 \end_inset
12133
12134  Language Extensions
12135 \end_layout
12136
12137 \begin_layout Subsubsection
12138 sfr
12139 \begin_inset LatexCommand \index{sfr}
12140
12141 \end_inset
12142
12143
12144 \begin_inset LatexCommand \index{\_\_sfr}
12145
12146 \end_inset
12147
12148  (in/out to 8-bit addresses)
12149 \end_layout
12150
12151 \begin_layout Standard
12152 The Z80
12153 \begin_inset LatexCommand \index{Z80}
12154
12155 \end_inset
12156
12157  family has separate address spaces for memory and 
12158 \emph on
12159 i
12160 \emph default
12161 nput/
12162 \emph on
12163 o
12164 \emph default
12165 utput memory.
12166  I/O memory
12167 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12168
12169 \end_inset
12170
12171
12172 \begin_inset LatexCommand \index{Z80!I/O memory}
12173
12174 \end_inset
12175
12176
12177 \begin_inset LatexCommand \index{Z180!I/O memory}
12178
12179 \end_inset
12180
12181  is accessed with special instructions, e.g.:
12182 \end_layout
12183
12184 \begin_layout Verse
12185
12186 \family typewriter
12187 sfr at 0x78 IoPort;\InsetSpace ~
12188 \InsetSpace ~
12189 /* define a var in I/O space at 78h called IoPort */
12190  
12191 \end_layout
12192
12193 \begin_layout Standard
12194 Writing 0x01 to this variable generates the assembly code:
12195 \end_layout
12196
12197 \begin_layout Verse
12198
12199 \family typewriter
12200 3E 01\InsetSpace ~
12201 \InsetSpace ~
12202 \InsetSpace ~
12203 \InsetSpace ~
12204 \InsetSpace ~
12205 \InsetSpace ~
12206 ld a,#0x01
12207 \newline
12208 D3 78\InsetSpace ~
12209 \InsetSpace ~
12210 \InsetSpace ~
12211 \InsetSpace ~
12212 \InsetSpace ~
12213 \InsetSpace ~
12214 out (_IoPort),a 
12215 \end_layout
12216
12217 \begin_layout Subsubsection
12218 banked sfr
12219 \begin_inset LatexCommand \index{sfr}
12220
12221 \end_inset
12222
12223
12224 \begin_inset LatexCommand \index{\_\_sfr}
12225
12226 \end_inset
12227
12228  (in/out to 16-bit addresses)
12229 \end_layout
12230
12231 \begin_layout Standard
12232 The keyword 
12233 \emph on
12234 banked
12235 \emph default
12236  is used to support 16 bit addresses in I/O memory e.g.:
12237 \end_layout
12238
12239 \begin_layout Verse
12240
12241 \family typewriter
12242 sfr banked at
12243 \begin_inset LatexCommand \index{at}
12244
12245 \end_inset
12246
12247
12248 \begin_inset LatexCommand \index{\_\_at}
12249
12250 \end_inset
12251
12252  0x123 IoPort; 
12253 \end_layout
12254
12255 \begin_layout Standard
12256 Writing 0x01 to this variable generates the assembly code:
12257 \end_layout
12258
12259 \begin_layout Verse
12260
12261 \family typewriter
12262 01 23 01\InsetSpace ~
12263 \InsetSpace ~
12264 \InsetSpace ~
12265 ld bc,#_IoPort
12266 \newline
12267 3E 01\InsetSpace ~
12268 \InsetSpace ~
12269 \InsetSpace ~
12270 \InsetSpace ~
12271 \InsetSpace ~
12272 \InsetSpace ~
12273 ld a,#0x01 
12274 \newline
12275 ED 79\InsetSpace ~
12276 \InsetSpace ~
12277 \InsetSpace ~
12278 \InsetSpace ~
12279 \InsetSpace ~
12280 \InsetSpace ~
12281 out (c),a 
12282 \end_layout
12283
12284 \begin_layout Subsubsection
12285 sfr
12286 \begin_inset LatexCommand \index{sfr}
12287
12288 \end_inset
12289
12290
12291 \begin_inset LatexCommand \index{\_\_sfr}
12292
12293 \end_inset
12294
12295  (in0/out0 to 8 bit addresses on Z180
12296 \begin_inset LatexCommand \index{Z180}
12297
12298 \end_inset
12299
12300 /HD64180
12301 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12302
12303 \end_inset
12304
12305 )
12306 \end_layout
12307
12308 \begin_layout Standard
12309 The compiler option -
12310 \begin_inset ERT
12311 status collapsed
12312
12313 \begin_layout Standard
12314
12315
12316 \backslash
12317 /
12318 \end_layout
12319
12320 \end_inset
12321
12322 -portmode
12323 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12324
12325 \end_inset
12326
12327 =180 (80) and a compiler #pragma\InsetSpace ~
12328 portmode
12329 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12330
12331 \end_inset
12332
12333  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12334 ns 
12335 \family typewriter
12336 in0/out0
12337 \family default
12338  instead of 
12339 \family typewriter
12340 in/out
12341 \family default
12342 .
12343  If you include the file z180.h this will be set automatically.
12344 \begin_inset VSpace bigskip
12345 \end_inset
12346
12347
12348 \end_layout
12349
12350 \begin_layout Subsection
12351 HC08 Storage Class
12352 \begin_inset LatexCommand \index{HC08!Storage class}
12353
12354 \end_inset
12355
12356  Language Extensions
12357 \end_layout
12358
12359 \begin_layout Subsubsection
12360 data
12361 \begin_inset LatexCommand \index{data (hc08 storage class)}
12362
12363 \end_inset
12364
12365
12366 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12367
12368 \end_inset
12369
12370  
12371 \end_layout
12372
12373 \begin_layout Standard
12374 The data storage class declares a variable that resides in the first 256
12375  bytes of memory (the direct page).
12376  The HC08
12377 \begin_inset LatexCommand \index{HC08}
12378
12379 \end_inset
12380
12381  is most efficient at accessing variables (especially pointers) stored here.
12382 \end_layout
12383
12384 \begin_layout Subsubsection
12385 xdata
12386 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12387
12388 \end_inset
12389
12390
12391 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12392
12393 \end_inset
12394
12395  
12396 \end_layout
12397
12398 \begin_layout Standard
12399 The xdata storage class declares a variable that can reside anywhere in
12400  memory.
12401  This is the default if no storage class is specified.
12402  
12403 \begin_inset VSpace bigskip
12404 \end_inset
12405
12406
12407 \end_layout
12408
12409 \begin_layout Section
12410 Absolute Addressing
12411 \begin_inset LatexCommand \index{Absolute addressing}
12412
12413 \end_inset
12414
12415
12416 \end_layout
12417
12418 \begin_layout Standard
12419 Data items can be assigned an absolute address with the 
12420 \emph on
12421 at
12422 \begin_inset LatexCommand \index{at}
12423
12424 \end_inset
12425
12426
12427 \begin_inset LatexCommand \index{\_\_at}
12428
12429 \end_inset
12430
12431  <address>
12432 \emph default
12433  keyword, in addition to a storage class, e.g.:
12434 \end_layout
12435
12436 \begin_layout Verse
12437
12438 \family typewriter
12439 xdata
12440 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12441
12442 \end_inset
12443
12444
12445 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12446
12447 \end_inset
12448
12449  at
12450 \begin_inset LatexCommand \index{at}
12451
12452 \end_inset
12453
12454
12455 \begin_inset LatexCommand \index{\_\_at}
12456
12457 \end_inset
12458
12459  0x7ffe unsigned int chksum;
12460 \end_layout
12461
12462 \begin_layout Standard
12463 or, better conforming to ISO/IEC 9899 C:
12464 \end_layout
12465
12466 \begin_layout Verse
12467
12468 \family typewriter
12469 __xdata __at (0x7ffe) unsigned int chksum;
12470 \end_layout
12471
12472 \begin_layout Standard
12473 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
12474  of the external ram.
12475  The compiler does 
12476 \emph on
12477 not
12478 \emph default
12479  reserve any space for variables declared in this way
12480 \begin_inset Marginal
12481 status collapsed
12482
12483 \begin_layout Standard
12484
12485 \series bold
12486 \InsetSpace ~
12487 !
12488 \end_layout
12489
12490 \end_inset
12491
12492  (they are implemented with an equate in the assembler).
12493  Thus it is left to the programmer to make sure there are no overlaps with
12494  other variables that are declared without the absolute address.
12495  The assembler listing file (.lst
12496 \begin_inset LatexCommand \index{<file>.lst}
12497
12498 \end_inset
12499
12500 ) and the linker output files (.rst
12501 \begin_inset LatexCommand \index{<file>.rst}
12502
12503 \end_inset
12504
12505 ) and (.map
12506 \begin_inset LatexCommand \index{<file>.map}
12507
12508 \end_inset
12509
12510 ) are good places to look for such overlaps.
12511  Variables with an absolute address are 
12512 \emph on
12513 not
12514 \begin_inset Marginal
12515 status collapsed
12516
12517 \begin_layout Standard
12518
12519 \series bold
12520 \InsetSpace ~
12521 !
12522 \end_layout
12523
12524 \end_inset
12525
12526
12527 \emph default
12528  initialized
12529 \begin_inset LatexCommand \index{Variable initialization}
12530
12531 \end_inset
12532
12533 .
12534 \end_layout
12535
12536 \begin_layout Standard
12537 In case of memory mapped I/O devices the keyword 
12538 \emph on
12539 volatile
12540 \emph default
12541  has to be used to tell the compiler that accesses might not be removed:
12542 \end_layout
12543
12544 \begin_layout Verse
12545
12546 \family typewriter
12547 volatile
12548 \begin_inset LatexCommand \index{volatile}
12549
12550 \end_inset
12551
12552  __xdata
12553 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12554
12555 \end_inset
12556
12557  __at
12558 \begin_inset LatexCommand \index{at}
12559
12560 \end_inset
12561
12562  (0x8000) unsigned char PORTA_8255;
12563 \end_layout
12564
12565 \begin_layout Standard
12566 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
12567 r) array
12568 \family typewriter
12569 \size footnotesize
12570
12571 \begin_inset LatexCommand \index{Aligned array}
12572
12573 \end_inset
12574
12575
12576 \family default
12577 \size default
12578  starts at a block (256 byte) boundary
12579 \begin_inset LatexCommand \index{block boundary}
12580
12581 \end_inset
12582
12583  (section 
12584 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12585
12586 \end_inset
12587
12588  has an example).
12589 \newline
12590 Absolute addresses can be specified for variables in all
12591  storage classes, e.g.:
12592 \end_layout
12593
12594 \begin_layout Verse
12595
12596 \family typewriter
12597 __bit
12598 \begin_inset LatexCommand \index{bit}
12599
12600 \end_inset
12601
12602  __at
12603 \begin_inset LatexCommand \index{at}
12604
12605 \end_inset
12606
12607  (0x02) bvar;
12608 \end_layout
12609
12610 \begin_layout Standard
12611 The above example will allocate the variable at offset 0x02 in the bit-addressab
12612 le space.
12613  There is no real advantage to assigning absolute addresses to variables
12614  in this manner, unless you want strict control over all the variables allocated.
12615  One possible use would be to write hardware portable code.
12616  For example, if you have a routine that uses one or more of the microcontroller
12617  I/O pins, and such pins are different for two different hardwares, you
12618  can declare the I/O pins in your routine using:
12619 \end_layout
12620
12621 \begin_layout Verse
12622
12623 \family typewriter
12624 extern volatile
12625 \begin_inset LatexCommand \index{volatile}
12626
12627 \end_inset
12628
12629  __bit MOSI;\InsetSpace ~
12630 \InsetSpace ~
12631 \InsetSpace ~
12632 \InsetSpace ~
12633 /* master out, slave in */
12634 \newline
12635 extern volatile __bit MISO;\InsetSpace ~
12636 \InsetSpace ~
12637 \InsetSpace ~
12638 \InsetSpace ~
12639 /* master
12640  in, slave out */
12641 \newline
12642 extern volatile __bit MCLK;\InsetSpace ~
12643 \InsetSpace ~
12644 \InsetSpace ~
12645 \InsetSpace ~
12646 /* master clock */
12647 \newline
12648
12649 \newline
12650 /* Input and
12651  Output of a byte on a 3-wire serial bus.
12652 \newline
12653 \InsetSpace ~
12654 \InsetSpace ~
12655 \InsetSpace ~
12656 If needed adapt polarity of clock,
12657  polarity of data and bit order
12658 \newline
12659 \InsetSpace ~
12660 */
12661 \newline
12662 unsigned char spi_io(unsigned char out_byte)
12663  
12664 \newline
12665
12666 \newline
12667 \InsetSpace ~
12668 \InsetSpace ~
12669 \InsetSpace ~
12670 \InsetSpace ~
12671 unsigned char i=8;
12672 \newline
12673 \InsetSpace ~
12674 \InsetSpace ~
12675 \InsetSpace ~
12676 \InsetSpace ~
12677 do { 
12678 \newline
12679 \InsetSpace ~
12680 \InsetSpace ~
12681 \InsetSpace ~
12682 \InsetSpace ~
12683 \InsetSpace ~
12684 \InsetSpace ~
12685 \InsetSpace ~
12686 \InsetSpace ~
12687 MOSI = out_byte & 0x80; 
12688 \newline
12689 \InsetSpace ~
12690 \InsetSpace ~
12691 \InsetSpace ~
12692 \InsetSpace ~
12693 \InsetSpace ~
12694 \InsetSpace ~
12695 \InsetSpace ~
12696 \InsetSpace ~
12697 out_byte <<= 1;
12698 \newline
12699 \InsetSpace ~
12700 \InsetSpace ~
12701 \InsetSpace ~
12702 \InsetSpace ~
12703 \InsetSpace ~
12704 \InsetSpace ~
12705 \InsetSpace ~
12706 \InsetSpace ~
12707 MCLK =
12708  1; 
12709 \newline
12710 \InsetSpace ~
12711 \InsetSpace ~
12712 \InsetSpace ~
12713 \InsetSpace ~
12714 \InsetSpace ~
12715 \InsetSpace ~
12716 \InsetSpace ~
12717 \InsetSpace ~
12718 /* _asm nop _endasm; */\InsetSpace ~
12719 \InsetSpace ~
12720 \InsetSpace ~
12721 \InsetSpace ~
12722 \InsetSpace ~
12723 \InsetSpace ~
12724 \InsetSpace ~
12725 \InsetSpace ~
12726 /* for slow peripherals */
12727 \newline
12728 \InsetSpace ~
12729 \InsetSpace ~
12730 \InsetSpace ~
12731 \InsetSpace ~
12732 \InsetSpace ~
12733 \InsetSpace ~
12734 \InsetSpace ~
12735 \InsetSpace ~
12736 if(MISO) 
12737 \newline
12738 \InsetSpace ~
12739 \InsetSpace ~
12740 \InsetSpace ~
12741 \InsetSpace ~
12742 \InsetSpace ~
12743 \InsetSpace ~
12744 \InsetSpace ~
12745 \InsetSpace ~
12746 \InsetSpace ~
12747 \InsetSpace ~
12748 \InsetSpace ~
12749 \InsetSpace ~
12750 out_byte +=
12751  1; 
12752 \newline
12753 \InsetSpace ~
12754 \InsetSpace ~
12755 \InsetSpace ~
12756 \InsetSpace ~
12757 \InsetSpace ~
12758 \InsetSpace ~
12759 \InsetSpace ~
12760 \InsetSpace ~
12761 MCLK = 0; 
12762 \newline
12763 \InsetSpace ~
12764 \InsetSpace ~
12765 \InsetSpace ~
12766 \InsetSpace ~
12767 } while(--i);
12768 \newline
12769 \InsetSpace ~
12770 \InsetSpace ~
12771 \InsetSpace ~
12772 \InsetSpace ~
12773 return out_byte; 
12774 \newline
12775 }
12776 \end_layout
12777
12778 \begin_layout Standard
12779 Then, someplace in the code for the first hardware you would use
12780 \end_layout
12781
12782 \begin_layout Verse
12783
12784 \family typewriter
12785 __bit __at
12786 \begin_inset LatexCommand \index{at}
12787
12788 \end_inset
12789
12790
12791 \begin_inset LatexCommand \index{\_\_at}
12792
12793 \end_inset
12794
12795  (0x80) MOSI;\InsetSpace ~
12796 \InsetSpace ~
12797 \InsetSpace ~
12798 \InsetSpace ~
12799 /* I/O port 0, bit 0 */
12800 \newline
12801 __bit __at (0x81) MISO;\InsetSpace ~
12802 \InsetSpace ~
12803 \InsetSpace ~
12804 \InsetSpace ~
12805 /* I/O port 0,
12806  bit 1 */
12807 \newline
12808 __bit __at (0x82) MCLK;\InsetSpace ~
12809 \InsetSpace ~
12810 \InsetSpace ~
12811 \InsetSpace ~
12812 /* I/O port 0, bit 2 */
12813 \end_layout
12814
12815 \begin_layout Standard
12816 Similarly, for the second hardware you would use
12817 \end_layout
12818
12819 \begin_layout Verse
12820
12821 \family typewriter
12822 __bit __at (0x83) MOSI;\InsetSpace ~
12823 \InsetSpace ~
12824 \InsetSpace ~
12825 \InsetSpace ~
12826 /* I/O port 0, bit 3 */
12827 \newline
12828 __bit __at (0x91) MISO;\InsetSpace ~
12829 \InsetSpace ~
12830 \InsetSpace ~
12831 \InsetSpace ~
12832 /*
12833  I/O port 1, bit 1 */
12834 \newline
12835 __bit
12836 \begin_inset LatexCommand \index{bit}
12837
12838 \end_inset
12839
12840  __at (0x92) MCLK;\InsetSpace ~
12841 \InsetSpace ~
12842 \InsetSpace ~
12843 \InsetSpace ~
12844 /* I/O port 1, bit 2 */
12845 \end_layout
12846
12847 \begin_layout Standard
12848 and you can use the same hardware dependent routine without changes, as
12849  for example in a library.
12850  This is somehow similar to sbit, but only one absolute address has to be
12851  specified in the whole project.
12852 \begin_inset VSpace bigskip
12853 \end_inset
12854
12855
12856 \end_layout
12857
12858 \begin_layout Section
12859 Parameters
12860 \begin_inset LatexCommand \index{Parameters}
12861
12862 \end_inset
12863
12864
12865 \begin_inset LatexCommand \index{function parameter}
12866
12867 \end_inset
12868
12869  & Local Variables
12870 \begin_inset LatexCommand \index{local variables}
12871
12872 \end_inset
12873
12874
12875 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
12876
12877 \end_inset
12878
12879
12880 \end_layout
12881
12882 \begin_layout Standard
12883 Automatic (local) variables and parameters to functions can either be placed
12884  on the stack or in data-space.
12885  The default action of the compiler is to place these variables in the internal
12886  RAM (for small model) or external RAM (for large model).
12887  This in fact makes them similar to 
12888 \emph on
12889 static
12890 \begin_inset LatexCommand \index{static}
12891
12892 \end_inset
12893
12894
12895 \emph default
12896  so by default functions are non-reentrant
12897 \begin_inset LatexCommand \index{reentrant}
12898
12899 \end_inset
12900
12901 .
12902  
12903 \newline
12904
12905 \newline
12906 They can be placed on the stack
12907 \begin_inset LatexCommand \index{stack}
12908
12909 \end_inset
12910
12911  by using the
12912 \emph on
12913  -
12914 \begin_inset ERT
12915 status collapsed
12916
12917 \begin_layout Standard
12918
12919
12920 \backslash
12921 /
12922 \end_layout
12923
12924 \end_inset
12925
12926 -stack-auto
12927 \begin_inset LatexCommand \index{-\/-stack-auto}
12928
12929 \end_inset
12930
12931
12932 \emph default
12933  option, by using 
12934 \emph on
12935 #pragma\InsetSpace ~
12936 stackauto
12937 \emph default
12938
12939 \begin_inset LatexCommand \index{\#pragma stackauto}
12940
12941 \end_inset
12942
12943  or by using the 
12944 \emph on
12945 reentrant
12946 \begin_inset LatexCommand \index{reentrant}
12947
12948 \end_inset
12949
12950
12951 \emph default
12952  keyword in the function declaration, e.g.:
12953 \end_layout
12954
12955 \begin_layout Verse
12956
12957 \family typewriter
12958 unsigned char foo(char i) __reentrant 
12959 \newline
12960
12961 \newline
12962 \InsetSpace ~
12963 \InsetSpace ~
12964 \InsetSpace ~
12965 \InsetSpace ~
12966 ...
12967  
12968 \newline
12969 }
12970 \end_layout
12971
12972 \begin_layout Standard
12973 Since stack space on 8051 is limited, the 
12974 \emph on
12975 reentrant 
12976 \emph default
12977 keyword or the
12978 \emph on
12979  -
12980 \begin_inset ERT
12981 status collapsed
12982
12983 \begin_layout Standard
12984
12985
12986 \backslash
12987 /
12988 \end_layout
12989
12990 \end_inset
12991
12992 -stack-auto
12993 \emph default
12994  option should be used sparingly.
12995  Note that the reentrant keyword just means that the parameters & local
12996  variables will be allocated to the stack, it 
12997 \emph on
12998 does not
12999 \emph default
13000  mean that the function is register bank
13001 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13002
13003 \end_inset
13004
13005  independent.
13006 \newline
13007
13008 \newline
13009 Local variables
13010 \begin_inset LatexCommand \index{local variables}
13011
13012 \end_inset
13013
13014  can be assigned storage classes and absolute
13015 \begin_inset LatexCommand \index{Absolute addressing}
13016
13017 \end_inset
13018
13019  addresses, e.g.: 
13020 \end_layout
13021
13022 \begin_layout Verse
13023
13024 \family typewriter
13025 unsigned char foo() 
13026 \newline
13027 {
13028 \newline
13029 \InsetSpace ~
13030 \InsetSpace ~
13031 \InsetSpace ~
13032 \InsetSpace ~
13033 __xdata unsigned char i;
13034 \newline
13035 \InsetSpace ~
13036 \InsetSpace ~
13037 \InsetSpace ~
13038 \InsetSpace ~
13039 __bit bvar;
13040 \newline
13041 \InsetSpace ~
13042 \InsetSpace ~
13043 \InsetSpace ~
13044 \InsetSpace ~
13045 __data __at
13046 \begin_inset LatexCommand \index{at}
13047
13048 \end_inset
13049
13050  (0x31) unsigned char j;
13051 \newline
13052 \InsetSpace ~
13053 \InsetSpace ~
13054 \InsetSpace ~
13055 \InsetSpace ~
13056 ...
13057  
13058 \newline
13059 }
13060 \end_layout
13061
13062 \begin_layout Standard
13063 In the above example the variable 
13064 \emph on
13065 i
13066 \emph default
13067  will be allocated in the external ram, 
13068 \emph on
13069 bvar
13070 \emph default
13071  in bit addressable space and
13072 \emph on
13073  j
13074 \emph default
13075  in internal ram.
13076  When compiled with 
13077 \emph on
13078 -
13079 \begin_inset ERT
13080 status collapsed
13081
13082 \begin_layout Standard
13083
13084
13085 \backslash
13086 /
13087 \end_layout
13088
13089 \end_inset
13090
13091 -stack-auto
13092 \emph default
13093  or when a function is declared as 
13094 \emph on
13095 reentrant
13096 \emph default
13097  this should only be done for static variables.
13098 \end_layout
13099
13100 \begin_layout Standard
13101 Parameters
13102 \begin_inset LatexCommand \index{function parameter}
13103
13104 \end_inset
13105
13106  however are not allowed any storage class
13107 \begin_inset LatexCommand \index{Storage class}
13108
13109 \end_inset
13110
13111 , (storage classes for parameters will be ignored), their allocation is
13112  governed by the memory model in use, and the reentrancy options.
13113 \end_layout
13114
13115 \begin_layout Standard
13116 It is however allowed to use bit parameters in reentrant functions and also
13117  non-static local bit variables are supported.
13118  Efficient use is limited to 8 semi-bitregisters in bit space.
13119  They are pushed and popped to stack
13120 \begin_inset LatexCommand \index{stack}
13121
13122 \end_inset
13123
13124  as a single byte just like the normal registers.
13125 \end_layout
13126
13127 \begin_layout Section
13128 Overlaying
13129 \begin_inset LatexCommand \label{sub:Overlaying}
13130
13131 \end_inset
13132
13133
13134 \begin_inset LatexCommand \index{Overlaying}
13135
13136 \end_inset
13137
13138
13139 \end_layout
13140
13141 \begin_layout Standard
13142 For non-reentrant
13143 \begin_inset LatexCommand \index{reentrant}
13144
13145 \end_inset
13146
13147  functions SDCC will try to reduce internal ram space usage by overlaying
13148  parameters and local variables of a function (if possible).
13149  Parameters and local variables
13150 \begin_inset LatexCommand \index{local variables}
13151
13152 \end_inset
13153
13154  of a function will be allocated to an overlayable segment if the function
13155  has 
13156 \emph on
13157 no other function calls and the function is non-reentrant and the memory
13158  model
13159 \begin_inset LatexCommand \index{Memory model}
13160
13161 \end_inset
13162
13163  is small.
13164
13165 \emph default
13166  If an explicit storage class
13167 \begin_inset LatexCommand \index{Storage class}
13168
13169 \end_inset
13170
13171  is specified for a local variable, it will NOT be overlayed.
13172 \end_layout
13173
13174 \begin_layout Standard
13175 Note that the compiler (not the linkage editor) makes the decision for overlayin
13176 g the data items.
13177  Functions that are called from an interrupt service routine
13178 \begin_inset Marginal
13179 status collapsed
13180
13181 \begin_layout Standard
13182
13183 \series bold
13184 !
13185 \end_layout
13186
13187 \end_inset
13188
13189  should be preceded by a #pragma\InsetSpace ~
13190 nooverlay
13191 \begin_inset LatexCommand \index{\#pragma nooverlay}
13192
13193 \end_inset
13194
13195  if they are not reentrant.
13196 \end_layout
13197
13198 \begin_layout Standard
13199 Also note that the compiler does not do any processing of inline assembler
13200  code, so the compiler might incorrectly assign local variables and parameters
13201  of a function into the overlay segment if the inline assembler code calls
13202  other c-functions that might use the overlay.
13203  In that case the #pragma\InsetSpace ~
13204 nooverlay should be used.
13205 \end_layout
13206
13207 \begin_layout Standard
13208 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13209 tion
13210 \begin_inset LatexCommand \index{Multiplication}
13211
13212 \end_inset
13213
13214  or division
13215 \begin_inset LatexCommand \index{Division}
13216
13217 \end_inset
13218
13219  will NOT be overlayed since these are implemented using external functions,
13220  e.g.:
13221 \end_layout
13222
13223 \begin_layout Verse
13224
13225 \family typewriter
13226 #pragma save 
13227 \newline
13228 #pragma nooverlay
13229 \begin_inset LatexCommand \index{\#pragma nooverlay}
13230
13231 \end_inset
13232
13233  
13234 \newline
13235 void set_error(unsigned char errcd) 
13236 \newline
13237 {
13238 \newline
13239 \InsetSpace ~
13240 \InsetSpace ~
13241 \InsetSpace ~
13242 \InsetSpace ~
13243 P3 = errcd;
13244 \newline
13245
13246 \newline
13247 #pragma restore 
13248 \newline
13249
13250 \newline
13251 void
13252  some_isr () __interrupt
13253 \begin_inset LatexCommand \index{interrupt}
13254
13255 \end_inset
13256
13257  (2)
13258 \newline
13259 {
13260 \newline
13261 \InsetSpace ~
13262 \InsetSpace ~
13263 \InsetSpace ~
13264 \InsetSpace ~
13265 ...
13266 \newline
13267 \InsetSpace ~
13268 \InsetSpace ~
13269 \InsetSpace ~
13270 \InsetSpace ~
13271 set_error(10);
13272 \newline
13273 \InsetSpace ~
13274 \InsetSpace ~
13275 \InsetSpace ~
13276 \InsetSpace ~
13277 ...
13278  
13279 \newline
13280 }
13281 \end_layout
13282
13283 \begin_layout Standard
13284 In the above example the parameter 
13285 \emph on
13286 errcd
13287 \emph default
13288  for the function 
13289 \emph on
13290 set_error
13291 \emph default
13292  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13293 nooverlay was
13294  not present, this could cause unpredictable runtime behavior when called
13295  from an interrupt service routine.
13296  The #pragma\InsetSpace ~
13297 nooverlay ensures that the parameters and local variables for
13298  the function are NOT overlayed.
13299 \begin_inset VSpace bigskip
13300 \end_inset
13301
13302
13303 \end_layout
13304
13305 \begin_layout Section
13306 Interrupt Service Routines
13307 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13308
13309 \end_inset
13310
13311
13312 \end_layout
13313
13314 \begin_layout Subsection
13315 General Information
13316 \end_layout
13317
13318 \begin_layout Standard
13319 SDCC allows 
13320 \emph on
13321 i
13322 \emph default
13323 nterrupt 
13324 \emph on
13325 s
13326 \emph default
13327 ervice 
13328 \emph on
13329 r
13330 \emph default
13331 outines to be coded in C, with some extended keywords.
13332 \end_layout
13333
13334 \begin_layout Verse
13335
13336 \family typewriter
13337 void timer_isr (void) __interrupt (1) __using (1) 
13338 \newline
13339
13340 \newline
13341 \InsetSpace ~
13342 \InsetSpace ~
13343 \InsetSpace ~
13344 \InsetSpace ~
13345 ...
13346  
13347 \newline
13348 }
13349 \end_layout
13350
13351 \begin_layout Standard
13352 The optional number following the 
13353 \emph on
13354 interrupt
13355 \begin_inset LatexCommand \index{interrupt}
13356
13357 \end_inset
13358
13359
13360 \begin_inset LatexCommand \index{\_\_interrupt}
13361
13362 \end_inset
13363
13364
13365 \emph default
13366  keyword is the interrupt number this routine will service.
13367  When present, the compiler will insert a call to this routine in the interrupt
13368  vector table
13369 \begin_inset LatexCommand \index{interrupt vector table}
13370
13371 \end_inset
13372
13373  for the interrupt number specified.
13374  If you have multiple source files in your project, interrupt service routines
13375  can be present in any of them, but a prototype of the isr MUST be present
13376  or included in the file that contains the function 
13377 \emph on
13378 main
13379 \emph default
13380 .
13381  The optional (8051 specific) keyword 
13382 \emph on
13383 using
13384 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13385
13386 \end_inset
13387
13388
13389 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13390
13391 \end_inset
13392
13393
13394 \emph default
13395  can be used to tell the compiler to use the specified register bank when
13396  generating code for this function.
13397  
13398 \newline
13399 Interrupt service routines open the door for some very interesting bugs:
13400 \end_layout
13401
13402 \begin_layout Subsubsection
13403 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13404
13405 \end_inset
13406
13407 Common interrupt pitfall: variable not declared 
13408 \emph on
13409 volatile
13410 \end_layout
13411
13412 \begin_layout Standard
13413 If an interrupt service routine changes variables which are accessed by
13414  other functions these variables have to be declared 
13415 \emph on
13416 volatile
13417 \emph default
13418
13419 \begin_inset LatexCommand \index{volatile}
13420
13421 \end_inset
13422
13423 .
13424  See 
13425 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
13426
13427 \end_inset
13428
13429  .
13430 \end_layout
13431
13432 \begin_layout Subsubsection
13433 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
13434
13435 \end_inset
13436
13437 Common interrupt pitfall: 
13438 \emph on
13439 non-atomic access
13440 \end_layout
13441
13442 \begin_layout Standard
13443 If the access to these variables is not 
13444 \emph on
13445 atomic
13446 \begin_inset LatexCommand \index{atomic}
13447
13448 \end_inset
13449
13450
13451 \emph default
13452  (i.e.
13453  the processor needs more than one instruction for the access and could
13454  be interrupted while accessing the variable) the interrupt must be disabled
13455  during the access to avoid inconsistent data.
13456  
13457 \newline
13458 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
13459  and should be protected by disabling interrupts.
13460  You're not automatically on the safe side if you use 8 bit variables though.
13461  We need an example here: f.e.
13462  on the 8051 the harmless looking 
13463 \begin_inset Quotes srd
13464 \end_inset
13465
13466
13467 \family typewriter
13468 flags\InsetSpace ~
13469 |=\InsetSpace ~
13470 0x80;
13471 \family default
13472
13473 \begin_inset Quotes sld
13474 \end_inset
13475
13476  is not atomic if 
13477 \family typewriter
13478 flags
13479 \family default
13480  resides in xdata.
13481  Setting 
13482 \begin_inset Quotes srd
13483 \end_inset
13484
13485
13486 \family typewriter
13487 flags\InsetSpace ~
13488 |=\InsetSpace ~
13489 0x40;
13490 \family default
13491
13492 \begin_inset Quotes sld
13493 \end_inset
13494
13495  from within an interrupt routine might get lost if the interrupt occurs
13496  at the wrong time.
13497  
13498 \begin_inset Quotes sld
13499 \end_inset
13500
13501
13502 \family typewriter
13503 counter\InsetSpace ~
13504 +=\InsetSpace ~
13505 8;
13506 \family default
13507
13508 \begin_inset Quotes srd
13509 \end_inset
13510
13511  is not atomic on the 8051 even if 
13512 \family typewriter
13513 counter
13514 \family default
13515  is located in data memory.
13516 \newline
13517 Bugs like these are hard to reproduce and can
13518  cause a lot of trouble.
13519  
13520 \end_layout
13521
13522 \begin_layout Subsubsection
13523 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
13524
13525 \end_inset
13526
13527 Common interrupt pitfall: 
13528 \emph on
13529 stack overflow
13530 \end_layout
13531
13532 \begin_layout Standard
13533 The return address and the registers used in the interrupt service routine
13534  are saved on the stack
13535 \begin_inset LatexCommand \index{stack}
13536
13537 \end_inset
13538
13539  so there must be sufficient stack space.
13540  If there isn't variables or registers (or even the return address itself)
13541  will be corrupted.
13542  This 
13543 \emph on
13544 stack overflow
13545 \emph default
13546
13547 \begin_inset LatexCommand \index{stack overflow}
13548
13549 \end_inset
13550
13551  is most likely to happen if the interrupt occurs during the 
13552 \begin_inset Quotes sld
13553 \end_inset
13554
13555 deepest
13556 \begin_inset Quotes srd
13557 \end_inset
13558
13559  subroutine when the stack is already in use for f.e.
13560  many return addresses.
13561 \end_layout
13562
13563 \begin_layout Subsubsection
13564 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
13565
13566 \end_inset
13567
13568 Common interrupt pitfall: 
13569 \emph on
13570 use of non-reentrant functions
13571 \end_layout
13572
13573 \begin_layout Standard
13574 A special note here, int (16 bit) and long (32 bit) integer division
13575 \begin_inset LatexCommand \index{Division}
13576
13577 \end_inset
13578
13579 , multiplication
13580 \begin_inset LatexCommand \index{Multiplication}
13581
13582 \end_inset
13583
13584  & modulus
13585 \begin_inset LatexCommand \index{Modulus}
13586
13587 \end_inset
13588
13589  and floating-point
13590 \begin_inset LatexCommand \index{Floating point support}
13591
13592 \end_inset
13593
13594  operations are implemented using external support routines.
13595  If an interrupt service routine needs to do any of these operations then
13596  the support routines (as mentioned in a following section) will have to
13597  be recompiled using the
13598 \emph on
13599  -
13600 \begin_inset ERT
13601 status collapsed
13602
13603 \begin_layout Standard
13604
13605
13606 \backslash
13607 /
13608 \end_layout
13609
13610 \end_inset
13611
13612 -stack-auto
13613 \begin_inset LatexCommand \index{-\/-stack-auto}
13614
13615 \end_inset
13616
13617
13618 \emph default
13619  option and the source file will need to be compiled using the 
13620 \emph on
13621 -
13622 \begin_inset ERT
13623 status collapsed
13624
13625 \begin_layout Standard
13626
13627
13628 \backslash
13629 /
13630 \end_layout
13631
13632 \end_inset
13633
13634 -int-long-reent
13635 \emph default
13636
13637 \begin_inset LatexCommand \index{-\/-int-long-reent}
13638
13639 \end_inset
13640
13641  compiler option.
13642  
13643 \newline
13644 Note, the type promotion
13645 \begin_inset LatexCommand \index{type promotion}
13646
13647 \end_inset
13648
13649  required by ANSI C can cause 16 bit routines to be used
13650 \begin_inset Marginal
13651 status collapsed
13652
13653 \begin_layout Standard
13654
13655 \series bold
13656 \InsetSpace ~
13657 !
13658 \end_layout
13659
13660 \end_inset
13661
13662  without the programmer being aware of it.
13663  See f.e.
13664  the cast 
13665 \family typewriter
13666 (unsigned char)(tail-1)
13667 \family default
13668  within the if clause in section 
13669 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13670
13671 \end_inset
13672
13673 .
13674 \end_layout
13675
13676 \begin_layout Standard
13677 Calling other functions from an interrupt service routine is not recommended,
13678  avoid it if possible.
13679  Note that when some function is called from an interrupt service routine
13680  it should be preceded by a #pragma\InsetSpace ~
13681 nooverlay
13682 \begin_inset LatexCommand \index{\#pragma nooverlay}
13683
13684 \end_inset
13685
13686  if it is not reentrant.
13687  Furthermore nonreentrant functions should not be called from the main program
13688  while the interrupt service routine might be active.
13689  They also must not be called from low priority interrupt service routines
13690  while a high priority interrupt service routine might be active.
13691  You could use semaphores or make the function
13692 \emph on
13693  critical
13694 \emph default
13695  if all parameters are passed in registers.
13696 \newline
13697  Also see section 
13698 \begin_inset LatexCommand \ref{sub:Overlaying}
13699
13700 \end_inset
13701
13702 \InsetSpace ~
13703 about Overlaying and section 
13704 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
13705
13706 \end_inset
13707
13708 \InsetSpace ~
13709 about Functions using private register banks.
13710 \begin_inset VSpace bigskip
13711 \end_inset
13712
13713
13714 \end_layout
13715
13716 \begin_layout Subsection
13717 MCS51/DS390 Interrupt Service Routines
13718 \end_layout
13719
13720 \begin_layout Standard
13721 Interrupt
13722 \begin_inset LatexCommand \index{interrupt}
13723
13724 \end_inset
13725
13726  numbers and the corresponding address & descriptions for the Standard 8051/8052
13727  are listed below.
13728  SDCC will automatically adjust the 
13729 \begin_inset LatexCommand \index{interrupt vector table}
13730
13731 \end_inset
13732
13733  to the maximum interrupt number specified.
13734 \newline
13735
13736 \end_layout
13737
13738 \begin_layout Standard
13739 \align center
13740 \begin_inset Tabular
13741 <lyxtabular version="3" rows="9" columns="3">
13742 <features>
13743 <column alignment="center" valignment="top" leftline="true" width="0in">
13744 <column alignment="left" valignment="top" leftline="true" width="0in">
13745 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
13746 <row topline="true" bottomline="true">
13747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13748 \begin_inset Text
13749
13750 \begin_layout Standard
13751 Interrupt #
13752 \end_layout
13753
13754 \end_inset
13755 </cell>
13756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13757 \begin_inset Text
13758
13759 \begin_layout Standard
13760 Description
13761 \end_layout
13762
13763 \end_inset
13764 </cell>
13765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13766 \begin_inset Text
13767
13768 \begin_layout Standard
13769 Vector Address
13770 \end_layout
13771
13772 \end_inset
13773 </cell>
13774 </row>
13775 <row topline="true">
13776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13777 \begin_inset Text
13778
13779 \begin_layout Standard
13780 0
13781 \end_layout
13782
13783 \end_inset
13784 </cell>
13785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13786 \begin_inset Text
13787
13788 \begin_layout Standard
13789 External 0
13790 \end_layout
13791
13792 \end_inset
13793 </cell>
13794 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13795 \begin_inset Text
13796
13797 \begin_layout Standard
13798 0x0003
13799 \end_layout
13800
13801 \end_inset
13802 </cell>
13803 </row>
13804 <row topline="true">
13805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13806 \begin_inset Text
13807
13808 \begin_layout Standard
13809 1
13810 \end_layout
13811
13812 \end_inset
13813 </cell>
13814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13815 \begin_inset Text
13816
13817 \begin_layout Standard
13818 Timer 0
13819 \end_layout
13820
13821 \end_inset
13822 </cell>
13823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13824 \begin_inset Text
13825
13826 \begin_layout Standard
13827 0x000b
13828 \end_layout
13829
13830 \end_inset
13831 </cell>
13832 </row>
13833 <row topline="true">
13834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13835 \begin_inset Text
13836
13837 \begin_layout Standard
13838 2
13839 \end_layout
13840
13841 \end_inset
13842 </cell>
13843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13844 \begin_inset Text
13845
13846 \begin_layout Standard
13847 External 1
13848 \end_layout
13849
13850 \end_inset
13851 </cell>
13852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13853 \begin_inset Text
13854
13855 \begin_layout Standard
13856 0x0013
13857 \end_layout
13858
13859 \end_inset
13860 </cell>
13861 </row>
13862 <row topline="true">
13863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13864 \begin_inset Text
13865
13866 \begin_layout Standard
13867 3
13868 \end_layout
13869
13870 \end_inset
13871 </cell>
13872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13873 \begin_inset Text
13874
13875 \begin_layout Standard
13876 Timer 1
13877 \end_layout
13878
13879 \end_inset
13880 </cell>
13881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13882 \begin_inset Text
13883
13884 \begin_layout Standard
13885 0x001b
13886 \end_layout
13887
13888 \end_inset
13889 </cell>
13890 </row>
13891 <row topline="true">
13892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13893 \begin_inset Text
13894
13895 \begin_layout Standard
13896 4
13897 \end_layout
13898
13899 \end_inset
13900 </cell>
13901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13902 \begin_inset Text
13903
13904 \begin_layout Standard
13905 Serial
13906 \end_layout
13907
13908 \end_inset
13909 </cell>
13910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13911 \begin_inset Text
13912
13913 \begin_layout Standard
13914 0x0023
13915 \end_layout
13916
13917 \end_inset
13918 </cell>
13919 </row>
13920 <row topline="true">
13921 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13922 \begin_inset Text
13923
13924 \begin_layout Standard
13925 5
13926 \end_layout
13927
13928 \end_inset
13929 </cell>
13930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13931 \begin_inset Text
13932
13933 \begin_layout Standard
13934 Timer 2 (8052)
13935 \end_layout
13936
13937 \end_inset
13938 </cell>
13939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13940 \begin_inset Text
13941
13942 \begin_layout Standard
13943 0x002b
13944 \end_layout
13945
13946 \end_inset
13947 </cell>
13948 </row>
13949 <row topline="true">
13950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13951 \begin_inset Text
13952
13953 \begin_layout Standard
13954 ...
13955 \end_layout
13956
13957 \end_inset
13958 </cell>
13959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13960 \begin_inset Text
13961
13962 \begin_layout Standard
13963
13964 \end_layout
13965
13966 \end_inset
13967 </cell>
13968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13969 \begin_inset Text
13970
13971 \begin_layout Standard
13972 ...
13973 \end_layout
13974
13975 \end_inset
13976 </cell>
13977 </row>
13978 <row topline="true" bottomline="true">
13979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13980 \begin_inset Text
13981
13982 \begin_layout Standard
13983 n
13984 \end_layout
13985
13986 \end_inset
13987 </cell>
13988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13989 \begin_inset Text
13990
13991 \begin_layout Standard
13992
13993 \end_layout
13994
13995 \end_inset
13996 </cell>
13997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13998 \begin_inset Text
13999
14000 \begin_layout Standard
14001 0x0003 + 8*n
14002 \end_layout
14003
14004 \end_inset
14005 </cell>
14006 </row>
14007 </lyxtabular>
14008
14009 \end_inset
14010
14011
14012 \newline
14013
14014 \end_layout
14015
14016 \begin_layout Standard
14017 If the interrupt service routine is defined without 
14018 \emph on
14019 using
14020 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14021
14022 \end_inset
14023
14024
14025 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14026
14027 \end_inset
14028
14029
14030 \emph default
14031  a register bank or with register bank 0 (
14032 \emph on
14033 using
14034 \emph default
14035  0), the compiler will save the registers used by itself on the stack upon
14036  entry and restore them at exit, however if such an interrupt service routine
14037  calls another function then the entire register bank will be saved on the
14038  stack.
14039  This scheme may be advantageous for small interrupt service routines which
14040  have low register usage.
14041 \end_layout
14042
14043 \begin_layout Standard
14044 If the interrupt service routine is defined to be using a specific register
14045  bank then only 
14046 \emph on
14047 a, b, dptr
14048 \emph default
14049  & psw are saved and restored, if such an interrupt service routine calls
14050  another function (using another register bank) then the entire register
14051  bank of the called function will be saved on the stack
14052 \begin_inset LatexCommand \index{stack}
14053
14054 \end_inset
14055
14056 .
14057  This scheme is recommended for larger interrupt service routines.
14058 \begin_inset VSpace bigskip
14059 \end_inset
14060
14061
14062 \end_layout
14063
14064 \begin_layout Subsection
14065 HC08
14066 \begin_inset LatexCommand \index{HC08}
14067
14068 \end_inset
14069
14070  Interrupt Service Routines
14071 \end_layout
14072
14073 \begin_layout Standard
14074 Since the number of interrupts
14075 \begin_inset LatexCommand \index{HC08!interrupt}
14076
14077 \end_inset
14078
14079  available is chip specific and the interrupt vector table always ends at
14080  the last byte of memory, the interrupt numbers corresponds to the interrupt
14081  vectors in reverse order of address.
14082  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14083  2 will use the interrupt vector at 0xfffa, and so on.
14084  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14085  this way; instead see section 
14086 \begin_inset LatexCommand \ref{sub:Startup-Code}
14087
14088 \end_inset
14089
14090  for details on customizing startup.
14091 \begin_inset VSpace bigskip
14092 \end_inset
14093
14094
14095 \end_layout
14096
14097 \begin_layout Subsection
14098 Z80 Interrupt Service Routines
14099 \end_layout
14100
14101 \begin_layout Standard
14102 The Z80
14103 \begin_inset LatexCommand \index{Z80}
14104
14105 \end_inset
14106
14107  uses several different methods for determining the correct interrupt
14108 \begin_inset LatexCommand \index{Z80!interrupt}
14109
14110 \end_inset
14111
14112  vector depending on the hardware implementation.
14113  Therefore, SDCC ignores the optional interrupt number and does not attempt
14114  to generate an interrupt vector table.
14115 \end_layout
14116
14117 \begin_layout Standard
14118 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14119  instruction to return from the interrupt.
14120  To write an interrupt handler for the non-maskable interrupt, which needs
14121  a RETN instruction instead, add the 
14122 \emph on
14123 critical
14124 \emph default
14125  keyword:
14126 \end_layout
14127
14128 \begin_layout Verse
14129
14130 \family typewriter
14131 void nmi_isr (void) critical interrupt
14132 \newline
14133
14134 \newline
14135 \InsetSpace ~
14136 \InsetSpace ~
14137 \InsetSpace ~
14138 \InsetSpace ~
14139 ...
14140  
14141 \newline
14142 }
14143 \end_layout
14144
14145 \begin_layout Standard
14146 However if you need to create a non-interruptable interrupt service routine
14147  you would also require the 
14148 \emph on
14149 critical
14150 \emph default
14151  keyword.
14152  To distinguish between this and an nmi_isr you must provide an interrupt
14153  number.
14154 \begin_inset VSpace bigskip
14155 \end_inset
14156
14157
14158 \end_layout
14159
14160 \begin_layout Section
14161 Enabling and Disabling Interrupts
14162 \end_layout
14163
14164 \begin_layout Subsection
14165 Critical Functions and Critical Statements
14166 \end_layout
14167
14168 \begin_layout Standard
14169 A special keyword may be associated with a block or a function declaring
14170  it as 
14171 \emph on
14172 critical
14173 \emph default
14174 .
14175  SDCC will generate code to disable all interrupts
14176 \begin_inset LatexCommand \index{interrupt}
14177
14178 \end_inset
14179
14180  upon entry to a critical function and restore the interrupt enable to the
14181  previous state before returning.
14182  Nesting critical functions will need one additional byte on the stack
14183 \begin_inset LatexCommand \index{stack}
14184
14185 \end_inset
14186
14187  for each call.
14188 \end_layout
14189
14190 \begin_layout Verse
14191
14192 \family typewriter
14193 int foo () __critical
14194 \begin_inset LatexCommand \index{critical}
14195
14196 \end_inset
14197
14198
14199 \begin_inset LatexCommand \index{\_\_critical}
14200
14201 \end_inset
14202
14203  
14204 \newline
14205
14206 \newline
14207 \InsetSpace ~
14208 \InsetSpace ~
14209 \InsetSpace ~
14210 \InsetSpace ~
14211 ...
14212  
14213 \newline
14214 \InsetSpace ~
14215 \InsetSpace ~
14216 \InsetSpace ~
14217 \InsetSpace ~
14218 ...
14219  
14220 \newline
14221 }
14222 \end_layout
14223
14224 \begin_layout Standard
14225 The critical attribute maybe used with other attributes like 
14226 \emph on
14227 reentrant.
14228 \emph default
14229
14230 \newline
14231 The keyword 
14232 \emph on
14233 critical
14234 \emph default
14235  may also be used to disable interrupts more locally:
14236 \end_layout
14237
14238 \begin_layout Verse
14239
14240 \family typewriter
14241 __critical{ i++; }
14242 \end_layout
14243
14244 \begin_layout Standard
14245 More than one statement could have been included in the block.
14246 \end_layout
14247
14248 \begin_layout Subsection
14249 Enabling and Disabling Interrupts directly
14250 \end_layout
14251
14252 \begin_layout Standard
14253 Interrupts
14254 \begin_inset LatexCommand \index{interrupt}
14255
14256 \end_inset
14257
14258  can also be disabled and enabled directly (8051):
14259 \end_layout
14260
14261 \begin_layout Verse
14262
14263 \family typewriter
14264 EA = 0;\InsetSpace ~
14265 \InsetSpace ~
14266 \InsetSpace ~
14267 \InsetSpace ~
14268 \InsetSpace ~
14269 \InsetSpace ~
14270 \InsetSpace ~
14271 \InsetSpace ~
14272 \InsetSpace ~
14273 \InsetSpace ~
14274 \InsetSpace ~
14275 \InsetSpace ~
14276 or:\InsetSpace ~
14277 \InsetSpace ~
14278 \InsetSpace ~
14279 \InsetSpace ~
14280 \InsetSpace ~
14281 \InsetSpace ~
14282 \InsetSpace ~
14283 \InsetSpace ~
14284 \InsetSpace ~
14285 \InsetSpace ~
14286 \InsetSpace ~
14287 EA_SAVE = EA;
14288 \end_layout
14289
14290 \begin_layout Verse
14291
14292 \family typewriter
14293 ...\InsetSpace ~
14294 \InsetSpace ~
14295 \InsetSpace ~
14296 \InsetSpace ~
14297 \InsetSpace ~
14298 \InsetSpace ~
14299 \InsetSpace ~
14300 \InsetSpace ~
14301 \InsetSpace ~
14302 \InsetSpace ~
14303 \InsetSpace ~
14304 \InsetSpace ~
14305 \InsetSpace ~
14306 \InsetSpace ~
14307 \InsetSpace ~
14308 \InsetSpace ~
14309 \InsetSpace ~
14310 \InsetSpace ~
14311 \InsetSpace ~
14312 \InsetSpace ~
14313 \InsetSpace ~
14314 \InsetSpace ~
14315 \InsetSpace ~
14316 \InsetSpace ~
14317 \InsetSpace ~
14318 \InsetSpace ~
14319 \InsetSpace ~
14320 \InsetSpace ~
14321 \InsetSpace ~
14322 \InsetSpace ~
14323 EA = 0;
14324 \end_layout
14325
14326 \begin_layout Verse
14327
14328 \family typewriter
14329 EA = 1;\InsetSpace ~
14330 \InsetSpace ~
14331 \InsetSpace ~
14332 \InsetSpace ~
14333 \InsetSpace ~
14334 \InsetSpace ~
14335 \InsetSpace ~
14336 \InsetSpace ~
14337 \InsetSpace ~
14338 \InsetSpace ~
14339 \InsetSpace ~
14340 \InsetSpace ~
14341 \InsetSpace ~
14342 \InsetSpace ~
14343 \InsetSpace ~
14344 \InsetSpace ~
14345 \InsetSpace ~
14346 \InsetSpace ~
14347 \InsetSpace ~
14348 \InsetSpace ~
14349 \InsetSpace ~
14350 \InsetSpace ~
14351 \InsetSpace ~
14352 \InsetSpace ~
14353 \InsetSpace ~
14354 \InsetSpace ~
14355 ...
14356 \end_layout
14357
14358 \begin_layout Verse
14359
14360 \family typewriter
14361 \InsetSpace ~
14362 \InsetSpace ~
14363 \InsetSpace ~
14364 \InsetSpace ~
14365 \InsetSpace ~
14366 \InsetSpace ~
14367 \InsetSpace ~
14368 \InsetSpace ~
14369 \InsetSpace ~
14370 \InsetSpace ~
14371 \InsetSpace ~
14372 \InsetSpace ~
14373 \InsetSpace ~
14374 \InsetSpace ~
14375 \InsetSpace ~
14376 \InsetSpace ~
14377 \InsetSpace ~
14378 \InsetSpace ~
14379 \InsetSpace ~
14380 \InsetSpace ~
14381 \InsetSpace ~
14382 \InsetSpace ~
14383 \InsetSpace ~
14384 \InsetSpace ~
14385 \InsetSpace ~
14386 \InsetSpace ~
14387 \InsetSpace ~
14388 \InsetSpace ~
14389 \InsetSpace ~
14390 \InsetSpace ~
14391 \InsetSpace ~
14392 \InsetSpace ~
14393 \InsetSpace ~
14394 EA = EA_SAVE;
14395 \end_layout
14396
14397 \begin_layout Standard
14398 On other architectures which have seperate opcodes for enabling and disabling
14399  interrupts you might want to make use of defines with inline assembly
14400 \begin_inset LatexCommand \index{Assembler routines}
14401
14402 \end_inset
14403
14404  (HC08
14405 \begin_inset LatexCommand \index{HC08!interrupt}
14406
14407 \end_inset
14408
14409 ):
14410 \end_layout
14411
14412 \begin_layout Verse
14413
14414 \family typewriter
14415 #define CLI _asm
14416 \begin_inset LatexCommand \index{\_asm}
14417
14418 \end_inset
14419
14420 \InsetSpace ~
14421 \InsetSpace ~
14422 cli\InsetSpace ~
14423 \InsetSpace ~
14424 _endasm
14425 \begin_inset LatexCommand \index{\_endasm}
14426
14427 \end_inset
14428
14429
14430 \end_layout
14431
14432 \begin_layout Verse
14433
14434 \family typewriter
14435 #define SEI _asm\InsetSpace ~
14436 \InsetSpace ~
14437 sei\InsetSpace ~
14438 \InsetSpace ~
14439 _endasm; 
14440 \end_layout
14441
14442 \begin_layout Verse
14443
14444 \family typewriter
14445 ...
14446 \end_layout
14447
14448 \begin_layout Standard
14449 Note: it is sometimes sufficient to disable only a specific interrupt source
14450  like f.e.
14451  a timer or serial interrupt by manipulating an 
14452 \emph on
14453 interrupt mask
14454 \begin_inset LatexCommand \index{interrupt mask}
14455
14456 \end_inset
14457
14458
14459 \emph default
14460  register.
14461  
14462 \end_layout
14463
14464 \begin_layout Standard
14465 Usually the time during which interrupts are disabled should be kept as
14466  short as possible.
14467  This minimizes both 
14468 \emph on
14469 interrupt latency
14470 \emph default
14471
14472 \begin_inset LatexCommand \index{interrupt latency}
14473
14474 \end_inset
14475
14476  (the time between the occurrence of the interrupt and the execution of
14477  the first code in the interrupt routine) and 
14478 \emph on
14479 interrupt jitter
14480 \emph default
14481
14482 \begin_inset LatexCommand \index{interrupt jitter}
14483
14484 \end_inset
14485
14486  (the difference between the shortest and the longest interrupt latency).
14487  These really are something different, f.e.
14488  a serial interrupt has to be served before its buffer overruns so it cares
14489  for the maximum interrupt latency, whereas it does not care about jitter.
14490  On a loudspeaker driven via a digital to analog converter which is fed
14491  by an interrupt a latency of a few milliseconds might be tolerable, whereas
14492  a much smaller jitter will be very audible.
14493 \end_layout
14494
14495 \begin_layout Standard
14496 You can reenable interrupts within an interrupt routine and on some architecture
14497 s you can make use of two (or more) levels of 
14498 \emph on
14499 interrupt priorities
14500 \emph default
14501
14502 \begin_inset LatexCommand \index{interrupt priority}
14503
14504 \end_inset
14505
14506 .
14507  On some architectures which don't support interrupt priorities these can
14508  be implemented by manipulating the interrupt mask and reenabling interrupts
14509  within the interrupt routine.
14510  Check there is sufficient space on the stack
14511 \begin_inset LatexCommand \index{stack}
14512
14513 \end_inset
14514
14515  and don't add complexity unless you have to.
14516  
14517 \end_layout
14518
14519 \begin_layout Subsection
14520 Semaphore
14521 \begin_inset LatexCommand \index{semaphore}
14522
14523 \end_inset
14524
14525  locking (mcs51/ds390)
14526 \end_layout
14527
14528 \begin_layout Standard
14529 Some architectures (mcs51/ds390) have an atomic
14530 \begin_inset LatexCommand \index{atomic}
14531
14532 \end_inset
14533
14534  bit test and
14535 \emph on
14536  
14537 \emph default
14538 clear
14539 \emph on
14540  
14541 \emph default
14542 instruction.
14543  These type of instructions are typically used in preemptive multitasking
14544  systems, where a routine f.e.
14545  claims the use of a data structure ('acquires a lock
14546 \begin_inset LatexCommand \index{lock}
14547
14548 \end_inset
14549
14550  on it'), makes some modifications and then releases the lock when the data
14551  structure is consistent again.
14552  The instruction may also be used if interrupt and non-interrupt code have
14553  to compete for a resource.
14554  With the atomic bit test and clear instruction interrupts
14555 \begin_inset LatexCommand \index{interrupt}
14556
14557 \end_inset
14558
14559  don't have to be disabled for the locking operation.
14560  
14561 \end_layout
14562
14563 \begin_layout Standard
14564 SDCC generates this instruction if the source follows this pattern:
14565 \end_layout
14566
14567 \begin_layout Verse
14568
14569 \family typewriter
14570 volatile
14571 \begin_inset LatexCommand \index{volatile}
14572
14573 \end_inset
14574
14575  bit resource_is_free; 
14576 \newline
14577
14578 \newline
14579 if (resource_is_free) 
14580 \newline
14581 \InsetSpace ~
14582 \InsetSpace ~
14583
14584 \newline
14585 \InsetSpace ~
14586 \InsetSpace ~
14587 \InsetSpace ~
14588 \InsetSpace ~
14589 resource_is_free=0; 
14590 \newline
14591 \InsetSpace ~
14592 \InsetSpace ~
14593 \InsetSpace ~
14594 \InsetSpace ~
14595 ...
14596  
14597 \newline
14598 \InsetSpace ~
14599 \InsetSpace ~
14600 \InsetSpace ~
14601 \InsetSpace ~
14602 resource_is_free=1;
14603 \newline
14604 \InsetSpace ~
14605 \InsetSpace ~
14606
14607 \end_layout
14608
14609 \begin_layout Standard
14610 Note, mcs51 and ds390 support only an atomic
14611 \begin_inset LatexCommand \index{atomic}
14612
14613 \end_inset
14614
14615  bit test and 
14616 \emph on
14617 clear
14618 \emph default
14619  instruction (as opposed to atomic bit test and 
14620 \emph on
14621 set).
14622 \end_layout
14623
14624 \begin_layout Section
14625 Functions using private register banks
14626 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
14627
14628 \end_inset
14629
14630  (mcs51/ds390)
14631 \end_layout
14632
14633 \begin_layout Standard
14634 Some architectures have support for quickly changing register sets.
14635  SDCC supports this feature with the 
14636 \emph on
14637 using
14638 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14639
14640 \end_inset
14641
14642
14643 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14644
14645 \end_inset
14646
14647
14648 \emph default
14649  attribute (which tells the compiler to use a register bank
14650 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
14651
14652 \end_inset
14653
14654  other than the default bank zero).
14655  It should only be applied to 
14656 \emph on
14657 interrupt
14658 \begin_inset LatexCommand \index{interrupt}
14659
14660 \end_inset
14661
14662
14663 \emph default
14664  functions (see footnote below).
14665  This will in most circumstances make the generated ISR code more efficient
14666  since it will not have to save registers on the stack.
14667 \end_layout
14668
14669 \begin_layout Standard
14670 The 
14671 \emph on
14672 using
14673 \emph default
14674  attribute will have no effect on the generated code for a 
14675 \emph on
14676 non-interrupt
14677 \emph default
14678  function (but may occasionally be useful anyway
14679 \begin_inset Foot
14680 status open
14681
14682 \begin_layout Standard
14683 possible exception: if a function is called ONLY from 'interrupt' functions
14684  using a particular bank, it can be declared with the same 'using' attribute
14685  as the calling 'interrupt' functions.
14686  For instance, if you have several ISRs using bank one, and all of them
14687  call memcpy(), it might make sense to create a specialized version of memcpy()
14688  'using 1', since this would prevent the ISR from having to save bank zero
14689  to the stack on entry and switch to bank zero before calling the function
14690 \end_layout
14691
14692 \end_inset
14693
14694 ).
14695 \newline
14696
14697 \emph on
14698 (pending: Note, nowadays the 
14699 \emph default
14700 using
14701 \emph on
14702  attribute has an effect on
14703 \emph default
14704  
14705 \emph on
14706 the generated code for a 
14707 \emph default
14708 non-interrupt
14709 \emph on
14710  function
14711 \emph default
14712 .
14713 \emph on
14714 )
14715 \end_layout
14716
14717 \begin_layout Standard
14718 An 
14719 \emph on
14720 interrupt
14721 \emph default
14722  function using a non-zero bank will assume that it can trash that register
14723  bank, and will not save it.
14724  Since high-priority interrupts
14725 \begin_inset LatexCommand \index{interrupts}
14726
14727 \end_inset
14728
14729
14730 \begin_inset LatexCommand \index{interrupt priority}
14731
14732 \end_inset
14733
14734  can interrupt low-priority ones on the 8051 and friends, this means that
14735  if a high-priority ISR 
14736 \emph on
14737 using
14738 \emph default
14739  a particular bank occurs while processing a low-priority ISR 
14740 \emph on
14741 using
14742 \emph default
14743  the same bank, terrible and bad things can happen.
14744  To prevent this, no single register bank should be 
14745 \emph on
14746 used
14747 \emph default
14748  by both a high priority and a low priority ISR.
14749  This is probably most easily done by having all high priority ISRs use
14750  one bank and all low priority ISRs use another.
14751  If you have an ISR which can change priority at runtime, you're on your
14752  own: I suggest using the default bank zero and taking the small performance
14753  hit.
14754 \end_layout
14755
14756 \begin_layout Standard
14757 It is most efficient if your ISR calls no other functions.
14758  If your ISR must call other functions, it is most efficient if those functions
14759  use the same bank as the ISR (see note 1 below); the next best is if the
14760  called functions use bank zero.
14761  It is very inefficient to call a function using a different, non-zero bank
14762  from an ISR.
14763  
14764 \begin_inset VSpace bigskip
14765 \end_inset
14766
14767
14768 \end_layout
14769
14770 \begin_layout Section
14771 Startup Code
14772 \begin_inset LatexCommand \label{sub:Startup-Code}
14773
14774 \end_inset
14775
14776
14777 \begin_inset LatexCommand \index{Startup code}
14778
14779 \end_inset
14780
14781
14782 \end_layout
14783
14784 \begin_layout Subsection
14785 MCS51/DS390 Startup Code
14786 \end_layout
14787
14788 \begin_layout Standard
14789 The compiler triggers the linker to link certain initialization modules
14790  from the runtime library
14791 \begin_inset LatexCommand \index{Runtime library}
14792
14793 \end_inset
14794
14795  called crt<something>.
14796  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
14797  GSINIT5) is not linked unless the --xstack option is used.
14798  These modules are highly entangled by the use of special segments/areas,
14799  but a common layout is shown below:
14800 \end_layout
14801
14802 \begin_layout Verse
14803
14804 \family typewriter
14805 \series bold
14806 \size footnotesize
14807 (main.asm)
14808 \end_layout
14809
14810 \begin_layout Verse
14811
14812 \family typewriter
14813 \size footnotesize
14814 \InsetSpace ~
14815 \InsetSpace ~
14816 \InsetSpace ~
14817 \InsetSpace ~
14818 \InsetSpace ~
14819 \InsetSpace ~
14820 \InsetSpace ~
14821 \InsetSpace ~
14822 .area HOME (CODE)
14823 \newline
14824 __interrupt_vect:
14825 \newline
14826 \InsetSpace ~
14827 \InsetSpace ~
14828 \InsetSpace ~
14829 \InsetSpace ~
14830 \InsetSpace ~
14831 \InsetSpace ~
14832 \InsetSpace ~
14833 \InsetSpace ~
14834 ljmp __sdcc_gsinit_startup
14835 \end_layout
14836
14837 \begin_layout Verse
14838
14839 \family typewriter
14840 \series bold
14841 \size footnotesize
14842 (crtstart.asm)
14843 \end_layout
14844
14845 \begin_layout Verse
14846
14847 \family typewriter
14848 \size footnotesize
14849 \InsetSpace ~
14850 \InsetSpace ~
14851 \InsetSpace ~
14852 \InsetSpace ~
14853 \InsetSpace ~
14854 \InsetSpace ~
14855 \InsetSpace ~
14856 \InsetSpace ~
14857 .area GSINIT0 (CODE)
14858 \newline
14859 __sdcc_gsinit_startup::
14860 \newline
14861 \InsetSpace ~
14862 \InsetSpace ~
14863 \InsetSpace ~
14864 \InsetSpace ~
14865 \InsetSpace ~
14866 \InsetSpace ~
14867 \InsetSpace ~
14868 \InsetSpace ~
14869 mov sp,#__start__stack - 1
14870 \end_layout
14871
14872 \begin_layout Verse
14873
14874 \family typewriter
14875 \series bold
14876 \size footnotesize
14877 (crtxstack.asm)
14878 \end_layout
14879
14880 \begin_layout Verse
14881
14882 \family typewriter
14883 \size footnotesize
14884 \InsetSpace ~
14885 \InsetSpace ~
14886 \InsetSpace ~
14887 \InsetSpace ~
14888 \InsetSpace ~
14889 \InsetSpace ~
14890 \InsetSpace ~
14891 \InsetSpace ~
14892 .area GSINIT1 (CODE)
14893 \newline
14894 __sdcc_init_xstack::
14895 \newline
14896 ; Need to initialize in GSINIT1 in
14897  case the user's __sdcc_external_startup uses the xstack.
14898 \newline
14899 \InsetSpace ~
14900 \InsetSpace ~
14901 \InsetSpace ~
14902 \InsetSpace ~
14903 \InsetSpace ~
14904 \InsetSpace ~
14905 \InsetSpace ~
14906 \InsetSpace ~
14907 mov __XPAGE,#(__start__x
14908 stack >> 8)
14909 \newline
14910 \InsetSpace ~
14911 \InsetSpace ~
14912 \InsetSpace ~
14913 \InsetSpace ~
14914 \InsetSpace ~
14915 \InsetSpace ~
14916 \InsetSpace ~
14917 \InsetSpace ~
14918 mov _spx,#__start__xstack
14919 \end_layout
14920
14921 \begin_layout Verse
14922
14923 \family typewriter
14924 \series bold
14925 \size footnotesize
14926 (crtstart.asm)
14927 \end_layout
14928
14929 \begin_layout Verse
14930
14931 \family typewriter
14932 \size footnotesize
14933 \InsetSpace ~
14934 \InsetSpace ~
14935 \InsetSpace ~
14936 \InsetSpace ~
14937 \InsetSpace ~
14938 \InsetSpace ~
14939 \InsetSpace ~
14940 \InsetSpace ~
14941 .area GSINIT2 (CODE)
14942 \newline
14943 \InsetSpace ~
14944 \InsetSpace ~
14945 \InsetSpace ~
14946 \InsetSpace ~
14947 \InsetSpace ~
14948 \InsetSpace ~
14949 \InsetSpace ~
14950 \InsetSpace ~
14951 lcall __sdcc_external_startup
14952 \newline
14953 \InsetSpace ~
14954 \InsetSpace ~
14955 \InsetSpace ~
14956 \InsetSpace ~
14957 \InsetSpace ~
14958 \InsetSpace ~
14959 \InsetSpace ~
14960 \InsetSpace ~
14961 mov a,dpl
14962 \newline
14963 \InsetSpace ~
14964 \InsetSpace ~
14965 \InsetSpace ~
14966 \InsetSpace ~
14967 \InsetSpace ~
14968 \InsetSpace ~
14969 \InsetSpace ~
14970 \InsetSpace ~
14971 jz __sdcc_init_data
14972 \newline
14973 \InsetSpace ~
14974 \InsetSpace ~
14975 \InsetSpace ~
14976 \InsetSpace ~
14977 \InsetSpace ~
14978 \InsetSpace ~
14979 \InsetSpace ~
14980 \InsetSpace ~
14981 ljmp
14982  __sdcc_program_startup
14983 \newline
14984 __sdcc_init_data:
14985 \end_layout
14986
14987 \begin_layout Verse
14988
14989 \family typewriter
14990 \series bold
14991 \size footnotesize
14992 (crtxinit.asm)
14993 \end_layout
14994
14995 \begin_layout Verse
14996
14997 \family typewriter
14998 \size footnotesize
14999 \InsetSpace ~
15000 \InsetSpace ~
15001 \InsetSpace ~
15002 \InsetSpace ~
15003 \InsetSpace ~
15004 \InsetSpace ~
15005 \InsetSpace ~
15006 \InsetSpace ~
15007 .area GSINIT3 (CODE)
15008 \newline
15009 __mcs51_genXINIT::
15010 \newline
15011 \InsetSpace ~
15012 \InsetSpace ~
15013 \InsetSpace ~
15014 \InsetSpace ~
15015 \InsetSpace ~
15016 \InsetSpace ~
15017 \InsetSpace ~
15018 \InsetSpace ~
15019 mov r1,#l_XINIT
15020 \newline
15021 \InsetSpace ~
15022 \InsetSpace ~
15023 \InsetSpace ~
15024 \InsetSpace ~
15025 \InsetSpace ~
15026 \InsetSpace ~
15027 \InsetSpace ~
15028 \InsetSpace ~
15029 mov a,r1
15030 \newline
15031 \InsetSpace ~
15032 \InsetSpace ~
15033 \InsetSpace ~
15034 \InsetSpace ~
15035 \InsetSpace ~
15036 \InsetSpace ~
15037 \InsetSpace ~
15038 \InsetSpace ~
15039 orl a,#(l_XINIT
15040  >> 8)
15041 \newline
15042 \InsetSpace ~
15043 \InsetSpace ~
15044 \InsetSpace ~
15045 \InsetSpace ~
15046 \InsetSpace ~
15047 \InsetSpace ~
15048 \InsetSpace ~
15049 \InsetSpace ~
15050 jz 00003$
15051 \newline
15052 \InsetSpace ~
15053 \InsetSpace ~
15054 \InsetSpace ~
15055 \InsetSpace ~
15056 \InsetSpace ~
15057 \InsetSpace ~
15058 \InsetSpace ~
15059 \InsetSpace ~
15060 mov r2,#((l_XINIT+255) >> 8)
15061 \newline
15062 \InsetSpace ~
15063 \InsetSpace ~
15064 \InsetSpace ~
15065 \InsetSpace ~
15066 \InsetSpace ~
15067 \InsetSpace ~
15068 \InsetSpace ~
15069 \InsetSpace ~
15070 mov dptr,#s_XINIT
15071 \newline
15072 \InsetSpace ~
15073 \InsetSpace ~
15074 \InsetSpace ~
15075 \InsetSpace ~
15076 \InsetSpace ~
15077 \InsetSpace ~
15078 \InsetSpace ~
15079 \InsetSpace ~
15080 mov r0,#s_XISEG
15081 \newline
15082 \InsetSpace ~
15083 \InsetSpace ~
15084 \InsetSpace ~
15085 \InsetSpace ~
15086 \InsetSpace ~
15087 \InsetSpace ~
15088 \InsetSpace ~
15089 \InsetSpace ~
15090 mov
15091  __XPAGE,#(s_XISEG >> 8)
15092 \newline
15093 00001$:\InsetSpace ~
15094 clr a
15095 \newline
15096 \InsetSpace ~
15097 \InsetSpace ~
15098 \InsetSpace ~
15099 \InsetSpace ~
15100 \InsetSpace ~
15101 \InsetSpace ~
15102 \InsetSpace ~
15103 \InsetSpace ~
15104 movc a,@a+dptr
15105 \newline
15106 \InsetSpace ~
15107 \InsetSpace ~
15108 \InsetSpace ~
15109 \InsetSpace ~
15110 \InsetSpace ~
15111 \InsetSpace ~
15112 \InsetSpace ~
15113 \InsetSpace ~
15114 movx @r0,a
15115 \newline
15116 \InsetSpace ~
15117 \InsetSpace ~
15118 \InsetSpace ~
15119 \InsetSpace ~
15120 \InsetSpace ~
15121 \InsetSpace ~
15122 \InsetSpace ~
15123 \InsetSpace ~
15124 inc dptr
15125 \newline
15126 \InsetSpace ~
15127 \InsetSpace ~
15128 \InsetSpace ~
15129 \InsetSpace ~
15130 \InsetSpace ~
15131 \InsetSpace ~
15132 \InsetSpace ~
15133 \InsetSpace ~
15134 inc
15135  r0
15136 \newline
15137 \InsetSpace ~
15138 \InsetSpace ~
15139 \InsetSpace ~
15140 \InsetSpace ~
15141 \InsetSpace ~
15142 \InsetSpace ~
15143 \InsetSpace ~
15144 \InsetSpace ~
15145 cjne r0,#0,00002$
15146 \newline
15147 \InsetSpace ~
15148 \InsetSpace ~
15149 \InsetSpace ~
15150 \InsetSpace ~
15151 \InsetSpace ~
15152 \InsetSpace ~
15153 \InsetSpace ~
15154 \InsetSpace ~
15155 inc __XPAGE
15156 \newline
15157 00002$:\InsetSpace ~
15158 djnz r1,00001$
15159 \newline
15160 \InsetSpace ~
15161 \InsetSpace ~
15162 \InsetSpace ~
15163 \InsetSpace ~
15164 \InsetSpace ~
15165 \InsetSpace ~
15166 \InsetSpace ~
15167 \InsetSpace ~
15168 djnz r2,00001$
15169 \newline
15170 \InsetSpace ~
15171 \InsetSpace ~
15172 \InsetSpace ~
15173 \InsetSpace ~
15174 \InsetSpace ~
15175 \InsetSpace ~
15176 \InsetSpace ~
15177 \InsetSpace ~
15178 mov __XPAGE,#0
15179 xFF
15180 \newline
15181 00003$:
15182 \end_layout
15183
15184 \begin_layout Verse
15185
15186 \family typewriter
15187 \series bold
15188 \size footnotesize
15189 (crtclear.asm)
15190 \end_layout
15191
15192 \begin_layout Verse
15193
15194 \family typewriter
15195 \size footnotesize
15196 \InsetSpace ~
15197 \InsetSpace ~
15198 \InsetSpace ~
15199 \InsetSpace ~
15200 \InsetSpace ~
15201 \InsetSpace ~
15202 \InsetSpace ~
15203 \InsetSpace ~
15204 .area GSINIT4 (CODE)
15205 \newline
15206 __mcs51_genRAMCLEAR::
15207 \newline
15208 \InsetSpace ~
15209 \InsetSpace ~
15210 \InsetSpace ~
15211 \InsetSpace ~
15212 \InsetSpace ~
15213 \InsetSpace ~
15214 \InsetSpace ~
15215 \InsetSpace ~
15216 clr a
15217 \newline
15218 \InsetSpace ~
15219 \InsetSpace ~
15220 \InsetSpace ~
15221 \InsetSpace ~
15222 \InsetSpace ~
15223 \InsetSpace ~
15224 \InsetSpace ~
15225 \InsetSpace ~
15226 mov r0,#(l_IRAM-1)
15227 \newline
15228 00004$:\InsetSpace ~
15229 mov
15230  @r0,a
15231 \newline
15232 \InsetSpace ~
15233 \InsetSpace ~
15234 \InsetSpace ~
15235 \InsetSpace ~
15236 \InsetSpace ~
15237 \InsetSpace ~
15238 \InsetSpace ~
15239 \InsetSpace ~
15240 djnz r0,00004$
15241 \newline
15242 ; _mcs51_genRAMCLEAR() end
15243 \end_layout
15244
15245 \begin_layout Verse
15246
15247 \family typewriter
15248 \series bold
15249 \size footnotesize
15250 (crtxclear.asm)
15251 \end_layout
15252
15253 \begin_layout Verse
15254
15255 \family typewriter
15256 \size footnotesize
15257 \InsetSpace ~
15258 \InsetSpace ~
15259 \InsetSpace ~
15260 \InsetSpace ~
15261 \InsetSpace ~
15262 \InsetSpace ~
15263 \InsetSpace ~
15264 \InsetSpace ~
15265 .area GSINIT4 (CODE)
15266 \newline
15267 __mcs51_genXRAMCLEAR::
15268 \newline
15269 \InsetSpace ~
15270 \InsetSpace ~
15271 \InsetSpace ~
15272 \InsetSpace ~
15273 \InsetSpace ~
15274 \InsetSpace ~
15275 \InsetSpace ~
15276 \InsetSpace ~
15277 mov r0,#l_PSEG
15278 \newline
15279 \InsetSpace ~
15280 \InsetSpace ~
15281 \InsetSpace ~
15282 \InsetSpace ~
15283 \InsetSpace ~
15284 \InsetSpace ~
15285 \InsetSpace ~
15286 \InsetSpace ~
15287 mov a,r0
15288 \newline
15289 \InsetSpace ~
15290 \InsetSpace ~
15291 \InsetSpace ~
15292 \InsetSpace ~
15293 \InsetSpace ~
15294 \InsetSpace ~
15295 \InsetSpace ~
15296 \InsetSpace ~
15297 jz 00006$
15298 \newline
15299 \InsetSpace ~
15300 \InsetSpace ~
15301 \InsetSpace ~
15302 \InsetSpace ~
15303 \InsetSpace ~
15304 \InsetSpace ~
15305 \InsetSpace ~
15306 \InsetSpace ~
15307 mov
15308  r1,#s_PSEG
15309 \newline
15310 \InsetSpace ~
15311 \InsetSpace ~
15312 \InsetSpace ~
15313 \InsetSpace ~
15314 \InsetSpace ~
15315 \InsetSpace ~
15316 \InsetSpace ~
15317 \InsetSpace ~
15318 mov __XPAGE,#(s_PSEG >> 8)
15319 \newline
15320 \InsetSpace ~
15321 \InsetSpace ~
15322 \InsetSpace ~
15323 \InsetSpace ~
15324 \InsetSpace ~
15325 \InsetSpace ~
15326 \InsetSpace ~
15327 \InsetSpace ~
15328 clr a
15329 \newline
15330 00005$:\InsetSpace ~
15331 movx @r1,a
15332 \newline
15333 \InsetSpace ~
15334 \InsetSpace ~
15335 \InsetSpace ~
15336 \InsetSpace ~
15337 \InsetSpace ~
15338 \InsetSpace ~
15339 \InsetSpace ~
15340 \InsetSpace ~
15341 inc r1
15342 \newline
15343 \InsetSpace ~
15344 \InsetSpace ~
15345 \InsetSpace ~
15346 \InsetSpace ~
15347 \InsetSpace ~
15348 \InsetSpace ~
15349 \InsetSpace ~
15350 \InsetSpace ~
15351 djnz r0,00005$
15352 \newline
15353 0
15354 0006$:
15355 \newline
15356 \InsetSpace ~
15357 \InsetSpace ~
15358 \InsetSpace ~
15359 \InsetSpace ~
15360 \InsetSpace ~
15361 \InsetSpace ~
15362 \InsetSpace ~
15363 \InsetSpace ~
15364 mov r0,#l_XSEG
15365 \newline
15366 \InsetSpace ~
15367 \InsetSpace ~
15368 \InsetSpace ~
15369 \InsetSpace ~
15370 \InsetSpace ~
15371 \InsetSpace ~
15372 \InsetSpace ~
15373 \InsetSpace ~
15374 mov a,r0
15375 \newline
15376 \InsetSpace ~
15377 \InsetSpace ~
15378 \InsetSpace ~
15379 \InsetSpace ~
15380 \InsetSpace ~
15381 \InsetSpace ~
15382 \InsetSpace ~
15383 \InsetSpace ~
15384 orl a,#(l_XSEG >> 8)
15385 \newline
15386 \InsetSpace ~
15387 \InsetSpace ~
15388 \InsetSpace ~
15389 \InsetSpace ~
15390 \InsetSpace ~
15391 \InsetSpace ~
15392 \InsetSpace ~
15393 \InsetSpace ~
15394 jz 00008$
15395 \newline
15396 \InsetSpace ~
15397 \InsetSpace ~
15398 \InsetSpace ~
15399 \InsetSpace ~
15400 \InsetSpace ~
15401 \InsetSpace ~
15402 \InsetSpace ~
15403 \InsetSpace ~
15404 mov r1,#((l_XSEG
15405  + 255) >> 8)
15406 \newline
15407 \InsetSpace ~
15408 \InsetSpace ~
15409 \InsetSpace ~
15410 \InsetSpace ~
15411 \InsetSpace ~
15412 \InsetSpace ~
15413 \InsetSpace ~
15414 \InsetSpace ~
15415 mov dptr,#s_XSEG
15416 \newline
15417 \InsetSpace ~
15418 \InsetSpace ~
15419 \InsetSpace ~
15420 \InsetSpace ~
15421 \InsetSpace ~
15422 \InsetSpace ~
15423 \InsetSpace ~
15424 \InsetSpace ~
15425 clr a
15426 \newline
15427 00007$:\InsetSpace ~
15428 movx @dptr,a
15429 \newline
15430 \InsetSpace ~
15431 \InsetSpace ~
15432 \InsetSpace ~
15433 \InsetSpace ~
15434 \InsetSpace ~
15435 \InsetSpace ~
15436 \InsetSpace ~
15437 \InsetSpace ~
15438 inc dptr
15439 \newline
15440 \InsetSpace ~
15441 \InsetSpace ~
15442 \InsetSpace ~
15443 \InsetSpace ~
15444 \InsetSpace ~
15445 \InsetSpace ~
15446 \InsetSpace ~
15447 \InsetSpace ~
15448 djnz r0,00007$
15449 \newline
15450 \InsetSpace ~
15451 \InsetSpace ~
15452 \InsetSpace ~
15453 \InsetSpace ~
15454 \InsetSpace ~
15455 \InsetSpace ~
15456 \InsetSpace ~
15457 \InsetSpace ~
15458 djnz
15459  r1,00007$
15460 \newline
15461 00008$:
15462 \end_layout
15463
15464 \begin_layout Verse
15465
15466 \family typewriter
15467 \series bold
15468 \size footnotesize
15469 (crtxstack.asm)
15470 \end_layout
15471
15472 \begin_layout Verse
15473
15474 \family typewriter
15475 \size footnotesize
15476 \InsetSpace ~
15477 \InsetSpace ~
15478 \InsetSpace ~
15479 \InsetSpace ~
15480 \InsetSpace ~
15481 \InsetSpace ~
15482 \InsetSpace ~
15483 \InsetSpace ~
15484 .area GSINIT5 (CODE)
15485 \newline
15486 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
15487  modifies __XPAGE
15488 \newline
15489 ; and __mcs51_genRAMCLEAR modifies _spx.
15490 \newline
15491 \InsetSpace ~
15492 \InsetSpace ~
15493 \InsetSpace ~
15494 \InsetSpace ~
15495 \InsetSpace ~
15496 \InsetSpace ~
15497 \InsetSpace ~
15498 \InsetSpace ~
15499 mov __XPAGE,#(__start__x
15500 stack >> 8)
15501 \newline
15502 \InsetSpace ~
15503 \InsetSpace ~
15504 \InsetSpace ~
15505 \InsetSpace ~
15506 \InsetSpace ~
15507 \InsetSpace ~
15508 \InsetSpace ~
15509 \InsetSpace ~
15510 mov _spx,#__start__xstack
15511 \end_layout
15512
15513 \begin_layout Verse
15514
15515 \family typewriter
15516 \series bold
15517 \size footnotesize
15518 (application modules)
15519 \end_layout
15520
15521 \begin_layout Verse
15522
15523 \family typewriter
15524 \size footnotesize
15525 \InsetSpace ~
15526 \InsetSpace ~
15527 \InsetSpace ~
15528 \InsetSpace ~
15529 \InsetSpace ~
15530 \InsetSpace ~
15531 \InsetSpace ~
15532 \InsetSpace ~
15533 .area GSINIT (CODE)
15534 \end_layout
15535
15536 \begin_layout Verse
15537
15538 \family typewriter
15539 \series bold
15540 \size footnotesize
15541 (main.asm)
15542 \end_layout
15543
15544 \begin_layout Verse
15545
15546 \family typewriter
15547 \size footnotesize
15548 \InsetSpace ~
15549 \InsetSpace ~
15550 \InsetSpace ~
15551 \InsetSpace ~
15552 \InsetSpace ~
15553 \InsetSpace ~
15554 \InsetSpace ~
15555 \InsetSpace ~
15556 .area GSFINAL (CODE)
15557 \newline
15558 \InsetSpace ~
15559 \InsetSpace ~
15560 \InsetSpace ~
15561 \InsetSpace ~
15562 \InsetSpace ~
15563 \InsetSpace ~
15564 \InsetSpace ~
15565 \InsetSpace ~
15566 ljmp __sdcc_program_startup
15567 \newline
15568 ;---------------------------------
15569 -----------------------
15570 \newline
15571 ; Home
15572 \newline
15573 ;--------------------------------------------------
15574 ------
15575 \newline
15576 \InsetSpace ~
15577 \InsetSpace ~
15578 \InsetSpace ~
15579 \InsetSpace ~
15580 \InsetSpace ~
15581 \InsetSpace ~
15582 \InsetSpace ~
15583 \InsetSpace ~
15584 .area HOME (CODE)
15585 \newline
15586 \InsetSpace ~
15587 \InsetSpace ~
15588 \InsetSpace ~
15589 \InsetSpace ~
15590 \InsetSpace ~
15591 \InsetSpace ~
15592 \InsetSpace ~
15593 \InsetSpace ~
15594 .area CSEG (CODE)
15595 \newline
15596 __sdcc_program_startup:
15597 \newline
15598 \InsetSpace ~
15599 \InsetSpace ~
15600 \InsetSpace ~
15601 \InsetSpace ~
15602 \InsetSpace ~
15603 \InsetSpace ~
15604 \InsetSpace ~
15605 \InsetSpace ~
15606 lcall _main
15607 \newline
15608 ;
15609  return from main will lock up
15610 \newline
15611 \InsetSpace ~
15612 \InsetSpace ~
15613 \InsetSpace ~
15614 \InsetSpace ~
15615 \InsetSpace ~
15616 \InsetSpace ~
15617 \InsetSpace ~
15618 \InsetSpace ~
15619 sjmp .
15620 \end_layout
15621
15622 \begin_layout Standard
15623 One of these modules (crtstart.asm) contains a call to the C routine 
15624 \emph on
15625 _sdcc_external_startup()
15626 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
15627
15628 \end_inset
15629
15630
15631 \series bold
15632 \emph default
15633  
15634 \series default
15635 at the start of the CODE area.
15636  This routine is also in the runtime library
15637 \begin_inset LatexCommand \index{Runtime library}
15638
15639 \end_inset
15640
15641  and returns 0 by default.
15642  If this routine returns a non-zero value, the static & global variable
15643  initialization will be skipped and the function main will be invoked.
15644  Otherwise static & global variables will be initialized before the function
15645  main is invoked.
15646  You could add an 
15647 \emph on
15648 _sdcc_external_startup()
15649 \emph default
15650  routine to your program to override the default if you need to setup hardware
15651  or perform some other critical operation prior to static & global variable
15652  initialization
15653 \begin_inset LatexCommand \index{Variable initialization}
15654
15655 \end_inset
15656
15657 .
15658  On some mcs51 variants xdata
15659 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
15660
15661 \end_inset
15662
15663  memory has to be explicitly enabled before it can be accessed or if the
15664  watchdog
15665 \begin_inset LatexCommand \index{watchdog}
15666
15667 \end_inset
15668
15669  needs to be disabled, this is the place to do it.
15670  The startup code clears all internal data memory, 256 bytes by default,
15671  but from 0 to n-1 if 
15672 \emph on
15673 -
15674 \begin_inset ERT
15675 status collapsed
15676
15677 \begin_layout Standard
15678
15679
15680 \backslash
15681 /
15682 \end_layout
15683
15684 \end_inset
15685
15686 -iram-size
15687 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
15688
15689 \end_inset
15690
15691 n
15692 \emph default
15693  is used.
15694  (recommended for Chipcon CC1010).
15695 \end_layout
15696
15697 \begin_layout Standard
15698 See also the compiler options 
15699 \emph on
15700 -
15701 \begin_inset ERT
15702 status collapsed
15703
15704 \begin_layout Standard
15705
15706
15707 \backslash
15708 /
15709 \end_layout
15710
15711 \end_inset
15712
15713 -no-xinit
15714 \emph default
15715 -
15716 \emph on
15717 opt
15718 \emph default
15719
15720 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
15721
15722 \end_inset
15723
15724
15725 \emph on
15726 -
15727 \begin_inset ERT
15728 status collapsed
15729
15730 \begin_layout Standard
15731
15732
15733 \backslash
15734 /
15735 \end_layout
15736
15737 \end_inset
15738
15739 -main-return
15740 \emph default
15741
15742 \begin_inset LatexCommand \index{-\/-main-return}
15743
15744 \end_inset
15745
15746  and section 
15747 \begin_inset LatexCommand \ref{sub:MCS51-variants}
15748
15749 \end_inset
15750
15751  about MCS51-variants.
15752 \begin_inset VSpace bigskip
15753 \end_inset
15754
15755
15756 \end_layout
15757
15758 \begin_layout Subsection
15759 HC08 Startup Code
15760 \end_layout
15761
15762 \begin_layout Standard
15763 The HC08
15764 \begin_inset LatexCommand \index{HC08}
15765
15766 \end_inset
15767
15768  startup code follows the same scheme as the MCS51 startup code.
15769 \begin_inset VSpace bigskip
15770 \end_inset
15771
15772
15773 \end_layout
15774
15775 \begin_layout Subsection
15776 Z80 Startup Code
15777 \end_layout
15778
15779 \begin_layout Standard
15780 On the Z80
15781 \begin_inset LatexCommand \index{Z80}
15782
15783 \end_inset
15784
15785  the startup code is inserted by linking with crt0.o which is generated from
15786  sdcc/device/lib/z80/crt0.s.
15787  If you need a different startup code you can use the compiler option 
15788 \emph on
15789 -
15790 \series bold
15791 \emph default
15792
15793 \begin_inset ERT
15794 status collapsed
15795
15796 \begin_layout Standard
15797
15798
15799 \backslash
15800 /
15801 \end_layout
15802
15803 \end_inset
15804
15805
15806 \series default
15807 \emph on
15808 -no-std-crt0
15809 \emph default
15810
15811 \begin_inset LatexCommand \index{-\/-no-std-crt0}
15812
15813 \end_inset
15814
15815  and provide your own crt0.o.
15816  
15817 \begin_inset VSpace bigskip
15818 \end_inset
15819
15820
15821 \end_layout
15822
15823 \begin_layout Section
15824 Inline Assembler Code
15825 \begin_inset LatexCommand \index{Assembler routines}
15826
15827 \end_inset
15828
15829
15830 \end_layout
15831
15832 \begin_layout Subsection
15833 A Step by Step Introduction
15834 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
15835
15836 \end_inset
15837
15838
15839 \end_layout
15840
15841 \begin_layout Standard
15842 Starting from a small snippet of c-code this example shows for the MCS51
15843  how to use inline assembly, access variables, a function parameter and
15844  an array in xdata memory.
15845  The example uses an MCS51 here but is easily adapted for other architectures.
15846  This is a buffer routine which should be optimized:
15847 \end_layout
15848
15849 \begin_layout Verse
15850
15851 \family typewriter
15852 \size footnotesize
15853 unsigned char __far
15854 \begin_inset LatexCommand \index{far (storage class)}
15855
15856 \end_inset
15857
15858
15859 \begin_inset LatexCommand \index{\_\_far (storage class)}
15860
15861 \end_inset
15862
15863  __at
15864 \begin_inset LatexCommand \index{at}
15865
15866 \end_inset
15867
15868
15869 \begin_inset LatexCommand \index{\_\_at}
15870
15871 \end_inset
15872
15873 (0x7f00) buf[0x100];
15874 \begin_inset LatexCommand \index{Aligned array}
15875
15876 \end_inset
15877
15878
15879 \newline
15880 unsigned char head, tail;\InsetSpace ~
15881 \InsetSpace ~
15882 \InsetSpace ~
15883 \InsetSpace ~
15884 \InsetSpace ~
15885 \InsetSpace ~
15886 \InsetSpace ~
15887 \InsetSpace ~
15888 \InsetSpace ~
15889 \InsetSpace ~
15890 \InsetSpace ~
15891 \InsetSpace ~
15892 \InsetSpace ~
15893 \InsetSpace ~
15894 \InsetSpace ~
15895 \InsetSpace ~
15896 \InsetSpace ~
15897 /* if interrupts
15898 \begin_inset LatexCommand \index{interrupt}
15899
15900 \end_inset
15901
15902  are involved see
15903 \newline
15904 \InsetSpace ~
15905 \InsetSpace ~
15906 \InsetSpace ~
15907 \InsetSpace ~
15908 \InsetSpace ~
15909 \InsetSpace ~
15910 \InsetSpace ~
15911 \InsetSpace ~
15912 \InsetSpace ~
15913 \InsetSpace ~
15914 \InsetSpace ~
15915 \InsetSpace ~
15916 \InsetSpace ~
15917 \InsetSpace ~
15918 \InsetSpace ~
15919 \InsetSpace ~
15920 \InsetSpace ~
15921 \InsetSpace ~
15922 \InsetSpace ~
15923 \InsetSpace ~
15924 \InsetSpace ~
15925 \InsetSpace ~
15926 \InsetSpace ~
15927 \InsetSpace ~
15928 \InsetSpace ~
15929 \InsetSpace ~
15930 \InsetSpace ~
15931 \InsetSpace ~
15932 \InsetSpace ~
15933 \InsetSpace ~
15934 \InsetSpace ~
15935 \InsetSpace ~
15936 \InsetSpace ~
15937 \InsetSpace ~
15938 \InsetSpace ~
15939 \InsetSpace ~
15940 \InsetSpace ~
15941 \InsetSpace ~
15942 \InsetSpace ~
15943 \InsetSpace ~
15944 \InsetSpace ~
15945 \InsetSpace ~
15946 \InsetSpace ~
15947 \InsetSpace ~
15948 \InsetSpace ~
15949 section 
15950 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
15951
15952 \end_inset
15953
15954  about
15955 \series bold
15956  volatile
15957 \series default
15958  */
15959 \newline
15960
15961 \newline
15962 void to_buffer( unsigned char c ) 
15963 \newline
15964 {
15965 \newline
15966 \InsetSpace ~
15967 \InsetSpace ~
15968 \InsetSpace ~
15969 \InsetSpace ~
15970 if( head != (unsigned char)(tail-1)
15971  )\InsetSpace ~
15972 /* cast 
15973 \series bold
15974 needed
15975 \series default
15976  to avoid promotion
15977 \begin_inset LatexCommand \index{promotion to signed int}
15978
15979 \end_inset
15980
15981
15982 \begin_inset LatexCommand \index{type promotion}
15983
15984 \end_inset
15985
15986  to integer */
15987 \begin_inset Marginal
15988 status collapsed
15989
15990 \begin_layout Standard
15991
15992 \series bold
15993 \InsetSpace ~
15994 !
15995 \end_layout
15996
15997 \end_inset
15998
15999
16000 \newline
16001 \InsetSpace ~
16002 \InsetSpace ~
16003 \InsetSpace ~
16004 \InsetSpace ~
16005 \InsetSpace ~
16006 \InsetSpace ~
16007 \InsetSpace ~
16008 \InsetSpace ~
16009 buf[ head++ ] = c;\InsetSpace ~
16010 \InsetSpace ~
16011 \InsetSpace ~
16012 \InsetSpace ~
16013 \InsetSpace ~
16014 \InsetSpace ~
16015 \InsetSpace ~
16016 \InsetSpace ~
16017 \InsetSpace ~
16018 \InsetSpace ~
16019 \InsetSpace ~
16020 \InsetSpace ~
16021 \InsetSpace ~
16022 \InsetSpace ~
16023 \InsetSpace ~
16024 \InsetSpace ~
16025 /* access to a 256 byte aligned array */
16026 \newline
16027
16028 \end_layout
16029
16030 \begin_layout Standard
16031 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16032  then a corresponding buffer.asm file is generated.
16033  We define a new function 
16034 \family typewriter
16035 to_buffer_asm()
16036 \family default
16037  in file buffer.c in which we cut and paste the generated code, removing
16038  unwanted comments and some ':'.
16039  Then add 
16040 \begin_inset Quotes sld
16041 \end_inset
16042
16043
16044 \series bold
16045 _asm
16046 \series default
16047
16048 \begin_inset Quotes srd
16049 \end_inset
16050
16051  and 
16052 \begin_inset Quotes sld
16053 \end_inset
16054
16055
16056 \series bold
16057 _endasm;
16058 \series default
16059
16060 \begin_inset Quotes srd
16061 \end_inset
16062
16063
16064 \begin_inset Foot
16065 status open
16066
16067 \begin_layout Standard
16068 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16069  and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16070  has to be used.
16071  The latter is also used in the library functions.
16072 \end_layout
16073
16074 \end_inset
16075
16076  to the beginning and the end of the function body:
16077 \end_layout
16078
16079 \begin_layout Verse
16080
16081 \family typewriter
16082 \size footnotesize
16083 /* With a cut and paste from the .asm file, we have something to start with.
16084 \newline
16085 \InsetSpace ~
16086 \InsetSpace ~
16087 \InsetSpace ~
16088 The
16089  function is not yet OK! (registers aren't saved) */ 
16090 \newline
16091 void to_buffer_asm(
16092  unsigned char c ) 
16093 \newline
16094
16095 \newline
16096 \InsetSpace ~
16097 \InsetSpace ~
16098 \InsetSpace ~
16099 \InsetSpace ~
16100 _asm
16101 \begin_inset LatexCommand \index{\_asm}
16102
16103 \end_inset
16104
16105
16106 \begin_inset LatexCommand \index{\_\_asm}
16107
16108 \end_inset
16109
16110
16111 \newline
16112 \InsetSpace ~
16113 \InsetSpace ~
16114 \InsetSpace ~
16115 \InsetSpace ~
16116 mov\InsetSpace ~
16117 \InsetSpace ~
16118 r2,dpl 
16119 \newline
16120 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16121 /* cast 
16122 \series bold
16123 needed
16124 \series default
16125  to avoid promotion
16126 \begin_inset LatexCommand \index{promotion to signed int}
16127
16128 \end_inset
16129
16130
16131 \begin_inset LatexCommand \index{type promotion}
16132
16133 \end_inset
16134
16135  to integer */
16136 \newline
16137 \InsetSpace ~
16138 \InsetSpace ~
16139 \InsetSpace ~
16140 \InsetSpace ~
16141 mov\InsetSpace ~
16142 \InsetSpace ~
16143 a,_tail 
16144 \newline
16145 \InsetSpace ~
16146 \InsetSpace ~
16147 \InsetSpace ~
16148 \InsetSpace ~
16149 dec\InsetSpace ~
16150 \InsetSpace ~
16151
16152 \newline
16153 \InsetSpace ~
16154 \InsetSpace ~
16155 \InsetSpace ~
16156 \InsetSpace ~
16157 mov\InsetSpace ~
16158 \InsetSpace ~
16159 r3,a 
16160 \newline
16161 \InsetSpace ~
16162 \InsetSpace ~
16163 \InsetSpace ~
16164 \InsetSpace ~
16165 mov\InsetSpace ~
16166 \InsetSpace ~
16167 a,_head 
16168 \newline
16169 \InsetSpace ~
16170 \InsetSpace ~
16171 \InsetSpace ~
16172 \InsetSpace ~
16173 cjne a,ar3,00106$ 
16174 \newline
16175 \InsetSpace ~
16176 \InsetSpace ~
16177 \InsetSpace ~
16178 \InsetSpace ~
16179 ret
16180 \newline
16181 00106$:
16182  
16183 \newline
16184 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16185 \begin_inset LatexCommand \index{Aligned array}
16186
16187 \end_inset
16188
16189
16190 \newline
16191 \InsetSpace ~
16192 \InsetSpace ~
16193 \InsetSpace ~
16194 \InsetSpace ~
16195 mov\InsetSpace ~
16196 \InsetSpace ~
16197 r3,_head 
16198 \newline
16199 \InsetSpace ~
16200 \InsetSpace ~
16201 \InsetSpace ~
16202 \InsetSpace ~
16203 inc\InsetSpace ~
16204 \InsetSpace ~
16205 _head 
16206 \newline
16207 \InsetSpace ~
16208 \InsetSpace ~
16209 \InsetSpace ~
16210 \InsetSpace ~
16211 mov\InsetSpace ~
16212 \InsetSpace ~
16213 dpl,r3 
16214 \newline
16215 \InsetSpace ~
16216 \InsetSpace ~
16217 \InsetSpace ~
16218 \InsetSpace ~
16219 mov\InsetSpace ~
16220 \InsetSpace ~
16221 dph,#(_buf >> 8) 
16222 \newline
16223 \InsetSpace ~
16224 \InsetSpace ~
16225 \InsetSpace ~
16226 \InsetSpace ~
16227 mov\InsetSpace ~
16228 \InsetSpace ~
16229 a,r2 
16230 \newline
16231 \InsetSpace ~
16232 \InsetSpace ~
16233 \InsetSpace ~
16234 \InsetSpace ~
16235 movx @dptr,a
16236  
16237 \newline
16238 00103$: 
16239 \newline
16240 \InsetSpace ~
16241 \InsetSpace ~
16242 \InsetSpace ~
16243 \InsetSpace ~
16244 ret
16245 \newline
16246 \InsetSpace ~
16247 \InsetSpace ~
16248 \InsetSpace ~
16249 \InsetSpace ~
16250 _endasm
16251 \begin_inset LatexCommand \index{\_endasm}
16252
16253 \end_inset
16254
16255
16256 \begin_inset LatexCommand \index{\_\_endasm}
16257
16258 \end_inset
16259
16260 ;
16261 \newline
16262
16263 \end_layout
16264
16265 \begin_layout Standard
16266 The new file buffer.c should compile with only one warning about the unreferenced
16267  function argument 'c'.
16268  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16269  (1) and finally have:
16270 \end_layout
16271
16272 \begin_layout Verse
16273
16274 \family typewriter
16275 \size footnotesize
16276 unsigned char __far __at(0x7f00) buf[0x100];
16277 \newline
16278 unsigned char head, tail;
16279 \newline
16280 #define
16281  USE_ASSEMBLY (1)
16282 \newline
16283
16284 \newline
16285 #if !USE_ASSEMBLY
16286 \newline
16287
16288 \newline
16289 void to_buffer( unsigned char c )
16290 \newline
16291 {
16292 \newline
16293 \InsetSpace ~
16294 \InsetSpace ~
16295 \InsetSpace ~
16296 \InsetSpace ~
16297 if(
16298  head != (unsigned char)(tail-1) )
16299 \newline
16300 \InsetSpace ~
16301 \InsetSpace ~
16302 \InsetSpace ~
16303 \InsetSpace ~
16304 \InsetSpace ~
16305 \InsetSpace ~
16306 \InsetSpace ~
16307 \InsetSpace ~
16308 buf[ head++ ] = c;
16309 \newline
16310 }
16311 \newline
16312
16313 \newline
16314 #else
16315 \newline
16316
16317 \newline
16318 void to_buffer(
16319  unsigned char c )
16320 \newline
16321 {
16322 \newline
16323 \InsetSpace ~
16324 \InsetSpace ~
16325 \InsetSpace ~
16326 \InsetSpace ~
16327 c; // to avoid warning: unreferenced function argument
16328 \newline
16329 \InsetSpace ~
16330 \InsetSpace ~
16331 \InsetSpace ~
16332 \InsetSpace ~
16333 _asm
16334 \begin_inset LatexCommand \index{\_asm}
16335
16336 \end_inset
16337
16338
16339 \begin_inset LatexCommand \index{\_\_asm}
16340
16341 \end_inset
16342
16343
16344 \newline
16345 \InsetSpace ~
16346 \InsetSpace ~
16347 \InsetSpace ~
16348 \InsetSpace ~
16349 \InsetSpace ~
16350 \InsetSpace ~
16351 \InsetSpace ~
16352 \InsetSpace ~
16353 ; save used registers here.
16354  
16355 \newline
16356 \InsetSpace ~
16357 \InsetSpace ~
16358 \InsetSpace ~
16359 \InsetSpace ~
16360 \InsetSpace ~
16361 \InsetSpace ~
16362 \InsetSpace ~
16363 \InsetSpace ~
16364 ; If we were still using r2,r3 we would have to push them here.
16365  
16366 \newline
16367 ; if( head != (unsigned char)(tail-1) )
16368 \newline
16369 \InsetSpace ~
16370 \InsetSpace ~
16371 \InsetSpace ~
16372 \InsetSpace ~
16373 \InsetSpace ~
16374 \InsetSpace ~
16375 \InsetSpace ~
16376 \InsetSpace ~
16377 mov\InsetSpace ~
16378  a,_tail
16379 \newline
16380 \InsetSpace ~
16381 \InsetSpace ~
16382 \InsetSpace ~
16383 \InsetSpace ~
16384 \InsetSpace ~
16385 \InsetSpace ~
16386 \InsetSpace ~
16387 \InsetSpace ~
16388 dec\InsetSpace ~
16389  a
16390 \newline
16391 \InsetSpace ~
16392 \InsetSpace ~
16393 \InsetSpace ~
16394 \InsetSpace ~
16395 \InsetSpace ~
16396 \InsetSpace ~
16397 \InsetSpace ~
16398 \InsetSpace ~
16399 xrl\InsetSpace ~
16400  a,_head
16401 \newline
16402 \InsetSpace ~
16403 \InsetSpace ~
16404 \InsetSpace ~
16405 \InsetSpace ~
16406 \InsetSpace ~
16407 \InsetSpace ~
16408 \InsetSpace ~
16409 \InsetSpace ~
16410 ; we
16411  could do an ANL a,#0x0f here to use a smaller buffer (see below)
16412 \newline
16413 \InsetSpace ~
16414 \InsetSpace ~
16415 \InsetSpace ~
16416 \InsetSpace ~
16417 \InsetSpace ~
16418 \InsetSpace ~
16419 \InsetSpace ~
16420 \InsetSpace ~
16421 jz\InsetSpace ~
16422 \InsetSpace ~
16423  t_b_end$
16424 \newline
16425 \InsetSpace ~
16426 \InsetSpace ~
16427 \InsetSpace ~
16428 \InsetSpace ~
16429 \InsetSpace ~
16430 \InsetSpace ~
16431 \InsetSpace ~
16432 \InsetSpace ~
16433 ;
16434 \newline
16435 ;
16436  buf[ head++ ] = c;
16437 \newline
16438 \InsetSpace ~
16439 \InsetSpace ~
16440 \InsetSpace ~
16441 \InsetSpace ~
16442 \InsetSpace ~
16443 \InsetSpace ~
16444 \InsetSpace ~
16445 \InsetSpace ~
16446 mov\InsetSpace ~
16447  a,dpl \InsetSpace ~
16448 \InsetSpace ~
16449 \InsetSpace ~
16450 \InsetSpace ~
16451 \InsetSpace ~
16452 \InsetSpace ~
16453 \InsetSpace ~
16454 ; dpl holds lower byte of function argument
16455 \newline
16456 \InsetSpace ~
16457 \InsetSpace ~
16458 \InsetSpace ~
16459 \InsetSpace ~
16460 \InsetSpace ~
16461 \InsetSpace ~
16462 \InsetSpace ~
16463 \InsetSpace ~
16464 mov\InsetSpace ~
16465
16466  dpl,_head \InsetSpace ~
16467 \InsetSpace ~
16468 \InsetSpace ~
16469 ; buf is 0x100 byte aligned so head can be used directly
16470 \newline
16471 \InsetSpace ~
16472 \InsetSpace ~
16473 \InsetSpace ~
16474 \InsetSpace ~
16475 \InsetSpace ~
16476 \InsetSpace ~
16477 \InsetSpace ~
16478 \InsetSpace ~
16479 mov\InsetSpace ~
16480  dph,#(_bu
16481 f>>8)
16482 \newline
16483 \InsetSpace ~
16484 \InsetSpace ~
16485 \InsetSpace ~
16486 \InsetSpace ~
16487 \InsetSpace ~
16488 \InsetSpace ~
16489 \InsetSpace ~
16490 \InsetSpace ~
16491 movx @dptr,a
16492 \newline
16493 \InsetSpace ~
16494 \InsetSpace ~
16495 \InsetSpace ~
16496 \InsetSpace ~
16497 \InsetSpace ~
16498 \InsetSpace ~
16499 \InsetSpace ~
16500 \InsetSpace ~
16501 inc \InsetSpace ~
16502 _head
16503 \newline
16504 \InsetSpace ~
16505 \InsetSpace ~
16506 \InsetSpace ~
16507 \InsetSpace ~
16508 \InsetSpace ~
16509 \InsetSpace ~
16510 \InsetSpace ~
16511 \InsetSpace ~
16512 ; we could do an ANL _head,#0x0f here to use a
16513  smaller buffer (see above)
16514 \newline
16515 t_b_end$:
16516 \newline
16517 \InsetSpace ~
16518 \InsetSpace ~
16519 \InsetSpace ~
16520 \InsetSpace ~
16521 \InsetSpace ~
16522 \InsetSpace ~
16523 \InsetSpace ~
16524 \InsetSpace ~
16525 ; restore used registers here 
16526 \newline
16527 \InsetSpace ~
16528 \InsetSpace ~
16529 \InsetSpace ~
16530 \InsetSpace ~
16531 _endasm
16532 \begin_inset LatexCommand \index{\_endasm}
16533
16534 \end_inset
16535
16536
16537 \begin_inset LatexCommand \index{\_\_endasm}
16538
16539 \end_inset
16540
16541 ;
16542 \newline
16543 }
16544 \newline
16545 #endif
16546 \end_layout
16547
16548 \begin_layout Standard
16549 The inline assembler code can contain any valid code understood by the assembler
16550 , this includes any assembler directives and comment lines.
16551  The assembler does not like some characters like ':' or ''' in comments.
16552  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
16553 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
16554
16555 \end_inset
16556
16557
16558 \begin_inset LatexCommand \index{Assembler documentation}
16559
16560 \end_inset
16561
16562  or online at 
16563 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
16564
16565 \end_inset
16566
16567 \InsetSpace ~
16568 .
16569 \end_layout
16570
16571 \begin_layout Standard
16572 The compiler does not do any validation of the code within the 
16573 \family typewriter
16574 _asm
16575 \begin_inset LatexCommand \index{\_asm}
16576
16577 \end_inset
16578
16579
16580 \begin_inset LatexCommand \index{\_\_asm}
16581
16582 \end_inset
16583
16584  ...
16585  _endasm
16586 \size footnotesize
16587
16588 \begin_inset LatexCommand \index{\_endasm}
16589
16590 \end_inset
16591
16592
16593 \begin_inset LatexCommand \index{\_\_endasm}
16594
16595 \end_inset
16596
16597
16598 \size default
16599 ;
16600 \family default
16601  keyword pair.
16602  Specifically it will not know which registers are used and thus register
16603  pushing/popping
16604 \begin_inset LatexCommand \index{push/pop}
16605
16606 \end_inset
16607
16608  has to be done manually.
16609  
16610 \end_layout
16611
16612 \begin_layout Standard
16613 It is recommended that each assembly instruction (including labels) be placed
16614  in a separate line (as the example shows).
16615  When the -
16616 \begin_inset ERT
16617 status collapsed
16618
16619 \begin_layout Standard
16620
16621
16622 \backslash
16623 /
16624 \end_layout
16625
16626 \end_inset
16627
16628 -
16629 \emph on
16630 peep-asm
16631 \begin_inset LatexCommand \index{-\/-peep-asm}
16632
16633 \end_inset
16634
16635
16636 \emph default
16637  command line option is used, the inline assembler code will be passed through
16638  the peephole optimizer
16639 \begin_inset LatexCommand \index{Peephole optimizer}
16640
16641 \end_inset
16642
16643 .
16644  There are only a few (if any) cases where this option makes sense, it might
16645  cause some unexpected changes in the inline assembler code.
16646  Please go through the peephole optimizer rules defined in file 
16647 \emph on
16648 SDCCpeeph.def
16649 \emph default
16650  before using this option.
16651 \end_layout
16652
16653 \begin_layout Subsection
16654 Naked Functions
16655 \begin_inset LatexCommand \label{sub:Naked-Functions}
16656
16657 \end_inset
16658
16659
16660 \begin_inset LatexCommand \index{Naked functions}
16661
16662 \end_inset
16663
16664
16665 \end_layout
16666
16667 \begin_layout Standard
16668 A special keyword may be associated with a function declaring it as 
16669 \emph on
16670 _naked
16671 \begin_inset LatexCommand \index{\_naked}
16672
16673 \end_inset
16674
16675
16676 \begin_inset LatexCommand \index{\_\_naked}
16677
16678 \end_inset
16679
16680 .
16681  
16682 \emph default
16683 The 
16684 \emph on
16685 _naked
16686 \emph default
16687  function modifier attribute prevents the compiler from generating prologue
16688 \begin_inset LatexCommand \index{function prologue}
16689
16690 \end_inset
16691
16692  and epilogue
16693 \begin_inset LatexCommand \index{function epilogue}
16694
16695 \end_inset
16696
16697  code for that function.
16698  This means that the user is entirely responsible for such things as saving
16699  any registers that may need to be preserved, selecting the proper register
16700  bank, generating the 
16701 \emph on
16702 return
16703 \emph default
16704  instruction at the end, etc.
16705  Practically, this means that the contents of the function must be written
16706  in inline assembler.
16707  This is particularly useful for interrupt functions, which can have a large
16708  (and often unnecessary) prologue/epilogue.
16709  For example, compare the code generated by these two functions:
16710 \end_layout
16711
16712 \begin_layout Verse
16713
16714 \family typewriter
16715 volatile
16716 \begin_inset LatexCommand \index{volatile}
16717
16718 \end_inset
16719
16720  data unsigned char counter;
16721 \newline
16722
16723 \newline
16724 void simpleInterrupt(void) __interrupt
16725 \begin_inset LatexCommand \index{interrupt}
16726
16727 \end_inset
16728
16729
16730 \begin_inset LatexCommand \index{\_\_interrupt}
16731
16732 \end_inset
16733
16734  (1)
16735 \newline
16736 {
16737 \newline
16738 \InsetSpace ~
16739 \InsetSpace ~
16740 \InsetSpace ~
16741 \InsetSpace ~
16742 counter++;
16743 \newline
16744 }
16745 \newline
16746
16747 \newline
16748 void nakedInterrupt(void) __interrupt (2) __naked
16749 \newline
16750 {
16751 \newline
16752 \InsetSpace ~
16753 \InsetSpace ~
16754 \InsetSpace ~
16755 \InsetSpace ~
16756 _asm
16757 \begin_inset LatexCommand \index{\_asm}
16758
16759 \end_inset
16760
16761
16762 \begin_inset LatexCommand \index{\_\_asm}
16763
16764 \end_inset
16765
16766
16767 \newline
16768 \InsetSpace ~
16769 \InsetSpace ~
16770 \InsetSpace ~
16771 \InsetSpace ~
16772 \InsetSpace ~
16773 \InsetSpace ~
16774 inc\InsetSpace ~
16775 \InsetSpace ~
16776 \InsetSpace ~
16777 \InsetSpace ~
16778 \InsetSpace ~
16779 _counter ; does not change flags, no need to save psw
16780 \newline
16781 \InsetSpace ~
16782 \InsetSpace ~
16783 \InsetSpace ~
16784 \InsetSpace ~
16785 \InsetSpace ~
16786 \InsetSpace ~
16787 reti\InsetSpace ~
16788 \InsetSpace ~
16789 \InsetSpace ~
16790 \InsetSpace ~
16791 ; MUST explicitly
16792  include ret or reti in _naked function.
16793 \newline
16794 \InsetSpace ~
16795 \InsetSpace ~
16796 \InsetSpace ~
16797 \InsetSpace ~
16798 _endasm
16799 \begin_inset LatexCommand \index{\_endasm}
16800
16801 \end_inset
16802
16803
16804 \begin_inset LatexCommand \index{\_\_endasm}
16805
16806 \end_inset
16807
16808 ;
16809 \newline
16810 }
16811 \end_layout
16812
16813 \begin_layout Standard
16814 For an 8051 target, the generated simpleInterrupt looks like:
16815 \end_layout
16816
16817 \begin_layout Verse
16818
16819 \family typewriter
16820 Note, this is an 
16821 \emph on
16822 outdated
16823 \emph default
16824  example, recent versions of SDCC generate
16825 \newline
16826 the 
16827 \emph on
16828 same
16829 \emph default
16830  code for simpleInterrupt() and nakedInterrupt()!
16831 \newline
16832
16833 \newline
16834 _simpleInterrupt:
16835 \newline
16836 \InsetSpace ~
16837 \InsetSpace ~
16838 \InsetSpace ~
16839 \InsetSpace ~
16840 push\InsetSpace ~
16841 \InsetSpace ~
16842 \InsetSpace ~
16843 \InsetSpace ~
16844 acc
16845 \newline
16846 \InsetSpace ~
16847 \InsetSpace ~
16848 \InsetSpace ~
16849 \InsetSpace ~
16850 push\InsetSpace ~
16851 \InsetSpace ~
16852 \InsetSpace ~
16853 \InsetSpace ~
16854 b
16855 \newline
16856 \InsetSpace ~
16857 \InsetSpace ~
16858 \InsetSpace ~
16859 \InsetSpace ~
16860 pu
16861 sh\InsetSpace ~
16862 \InsetSpace ~
16863 \InsetSpace ~
16864 \InsetSpace ~
16865 dpl
16866 \newline
16867 \InsetSpace ~
16868 \InsetSpace ~
16869 \InsetSpace ~
16870 \InsetSpace ~
16871 push\InsetSpace ~
16872 \InsetSpace ~
16873 \InsetSpace ~
16874 \InsetSpace ~
16875 dph
16876 \newline
16877 \InsetSpace ~
16878 \InsetSpace ~
16879 \InsetSpace ~
16880 \InsetSpace ~
16881 push\InsetSpace ~
16882 \InsetSpace ~
16883 \InsetSpace ~
16884 \InsetSpace ~
16885 psw
16886 \newline
16887 \InsetSpace ~
16888 \InsetSpace ~
16889 \InsetSpace ~
16890 \InsetSpace ~
16891 mov\InsetSpace ~
16892 \InsetSpace ~
16893 \InsetSpace ~
16894 \InsetSpace ~
16895 \InsetSpace ~
16896 psw,#0x00
16897 \newline
16898 \InsetSpace ~
16899 \InsetSpace ~
16900 \InsetSpace ~
16901 \InsetSpace ~
16902 inc\InsetSpace ~
16903 \InsetSpace ~
16904 \InsetSpace ~
16905 \InsetSpace ~
16906 \InsetSpace ~
16907 _counter
16908 \newline
16909 \InsetSpace ~
16910 \InsetSpace ~
16911 \InsetSpace ~
16912 \InsetSpace ~
16913 pop\InsetSpace ~
16914 \InsetSpace ~
16915 \InsetSpace ~
16916 \InsetSpace ~
16917 \InsetSpace ~
16918 psw
16919 \newline
16920 \InsetSpace ~
16921 \InsetSpace ~
16922 \InsetSpace ~
16923 \InsetSpace ~
16924 pop\InsetSpace ~
16925 \InsetSpace ~
16926 \InsetSpace ~
16927 \InsetSpace ~
16928 \InsetSpace ~
16929 dph
16930 \newline
16931 \InsetSpace ~
16932 \InsetSpace ~
16933 \InsetSpace ~
16934 \InsetSpace ~
16935 pop\InsetSpace ~
16936 \InsetSpace ~
16937 \InsetSpace ~
16938 \InsetSpace ~
16939 \InsetSpace ~
16940 dpl
16941 \newline
16942 \InsetSpace ~
16943 \InsetSpace ~
16944 \InsetSpace ~
16945 \InsetSpace ~
16946 pop\InsetSpace ~
16947 \InsetSpace ~
16948 \InsetSpace ~
16949 \InsetSpace ~
16950 \InsetSpace ~
16951 b
16952 \newline
16953 \InsetSpace ~
16954 \InsetSpace ~
16955 \InsetSpace ~
16956 \InsetSpace ~
16957 pop\InsetSpace ~
16958 \InsetSpace ~
16959 \InsetSpace ~
16960 \InsetSpace ~
16961 \InsetSpace ~
16962 acc
16963 \newline
16964 \InsetSpace ~
16965 \InsetSpace ~
16966 \InsetSpace ~
16967 \InsetSpace ~
16968 reti
16969 \end_layout
16970
16971 \begin_layout Standard
16972 whereas nakedInterrupt looks like:
16973 \end_layout
16974
16975 \begin_layout Verse
16976
16977 \family typewriter
16978 _nakedInterrupt:
16979 \newline
16980 \InsetSpace ~
16981 \InsetSpace ~
16982 \InsetSpace ~
16983 \InsetSpace ~
16984 inc\InsetSpace ~
16985 \InsetSpace ~
16986 \InsetSpace ~
16987 \InsetSpace ~
16988 _counter ; does not change flags, no need to save psw
16989 \newline
16990 \InsetSpace ~
16991 \InsetSpace ~
16992 \InsetSpace ~
16993 \InsetSpace ~
16994 reti\InsetSpace ~
16995 \InsetSpace ~
16996 \InsetSpace ~
16997 \InsetSpace ~
16998 \InsetSpace ~
16999 \InsetSpace ~
17000 \InsetSpace ~
17001 \InsetSpace ~
17002 \InsetSpace ~
17003 \InsetSpace ~
17004 \InsetSpace ~
17005 \InsetSpace ~
17006 ;
17007  MUST explicitly include ret or reti in _naked function
17008 \end_layout
17009
17010 \begin_layout Standard
17011 The related directive #pragma exclude
17012 \begin_inset LatexCommand \index{\#pragma exclude}
17013
17014 \end_inset
17015
17016  allows a more fine grained control over pushing & popping
17017 \begin_inset LatexCommand \index{push/pop}
17018
17019 \end_inset
17020
17021  the registers.
17022 \end_layout
17023
17024 \begin_layout Standard
17025 While there is nothing preventing you from writing C code inside a 
17026 \family typewriter
17027 _naked
17028 \family default
17029  function, there are many ways to shoot yourself in the foot doing this,
17030  and it is recommended that you stick to inline assembler.
17031 \end_layout
17032
17033 \begin_layout Subsection
17034 Use of Labels within Inline Assembler
17035 \end_layout
17036
17037 \begin_layout Standard
17038 SDCC allows the use of in-line assembler with a few restrictions regarding
17039  labels.
17040  In older versions of the compiler all labels defined within inline assembler
17041  code had to be of the form 
17042 \emph on
17043 nnnnn$
17044 \emph default
17045  where nnnnn is a number less than 100 (which implies a limit of utmost
17046  100 inline assembler labels 
17047 \emph on
17048 per function
17049 \emph default
17050 \noun on
17051 )
17052 \noun default
17053 .
17054  
17055 \end_layout
17056
17057 \begin_layout Verse
17058
17059 \family typewriter
17060 _asm
17061 \begin_inset LatexCommand \index{\_asm}
17062
17063 \end_inset
17064
17065
17066 \begin_inset LatexCommand \index{\_\_asm}
17067
17068 \end_inset
17069
17070  
17071 \newline
17072 \InsetSpace ~
17073 \InsetSpace ~
17074 \InsetSpace ~
17075 \InsetSpace ~
17076 mov\InsetSpace ~
17077 \InsetSpace ~
17078 \InsetSpace ~
17079 \InsetSpace ~
17080 \InsetSpace ~
17081 b,#10 
17082 \newline
17083 00001$: 
17084 \newline
17085 \InsetSpace ~
17086 \InsetSpace ~
17087 \InsetSpace ~
17088 \InsetSpace ~
17089 djnz\InsetSpace ~
17090 \InsetSpace ~
17091 \InsetSpace ~
17092 \InsetSpace ~
17093 b,00001$ 
17094 \newline
17095 _endasm
17096 \begin_inset LatexCommand \index{\_endasm}
17097
17098 \end_inset
17099
17100
17101 \begin_inset LatexCommand \index{\_\_endasm}
17102
17103 \end_inset
17104
17105  ;
17106 \end_layout
17107
17108 \begin_layout Standard
17109 Inline assembler code cannot reference any C-labels, however it can reference
17110  labels
17111 \begin_inset LatexCommand \index{Labels}
17112
17113 \end_inset
17114
17115  defined by the inline assembler, e.g.:
17116 \end_layout
17117
17118 \begin_layout Verse
17119
17120 \family typewriter
17121 foo() { 
17122 \newline
17123 \InsetSpace ~
17124 \InsetSpace ~
17125 \InsetSpace ~
17126 \InsetSpace ~
17127 /* some c code */ 
17128 \newline
17129 \InsetSpace ~
17130 \InsetSpace ~
17131 \InsetSpace ~
17132 \InsetSpace ~
17133 _asm 
17134 \newline
17135 \InsetSpace ~
17136 \InsetSpace ~
17137 \InsetSpace ~
17138 \InsetSpace ~
17139 \InsetSpace ~
17140 \InsetSpace ~
17141 ; some assembler code 
17142 \newline
17143 \InsetSpace ~
17144 \InsetSpace ~
17145 \InsetSpace ~
17146 \InsetSpace ~
17147 \InsetSpace ~
17148 \InsetSpace ~
17149 ljmp $0003 
17150 \newline
17151 \InsetSpace ~
17152 \InsetSpace ~
17153 \InsetSpace ~
17154 \InsetSpace ~
17155 _endasm;
17156  
17157 \newline
17158 \InsetSpace ~
17159 \InsetSpace ~
17160 \InsetSpace ~
17161 \InsetSpace ~
17162 /* some more c code */ 
17163 \newline
17164 clabel:\InsetSpace ~
17165 \InsetSpace ~
17166 /* inline assembler cannot reference this
17167  label */ 
17168 \newline
17169 \InsetSpace ~
17170 \InsetSpace ~
17171 \InsetSpace ~
17172 \InsetSpace ~
17173 _asm
17174 \newline
17175 \InsetSpace ~
17176 \InsetSpace ~
17177 \InsetSpace ~
17178 \InsetSpace ~
17179 $0003: ;label (can be referenced by inline assembler only)
17180  
17181 \newline
17182 \InsetSpace ~
17183 \InsetSpace ~
17184 \InsetSpace ~
17185 \InsetSpace ~
17186 _endasm
17187 \begin_inset LatexCommand \index{\_endasm}
17188
17189 \end_inset
17190
17191
17192 \begin_inset LatexCommand \index{\_\_endasm}
17193
17194 \end_inset
17195
17196  ; 
17197 \newline
17198 \InsetSpace ~
17199 \InsetSpace ~
17200 \InsetSpace ~
17201 \InsetSpace ~
17202 /* some more c code */
17203 \newline
17204 }
17205 \end_layout
17206
17207 \begin_layout Standard
17208 In other words inline assembly code can access labels defined in inline
17209  assembly within the scope of the function.
17210  The same goes the other way, i.e.
17211  labels defines in inline assembly can not be accessed by C statements.
17212 \end_layout
17213
17214 \begin_layout Section
17215 Interfacing with Assembler Code
17216 \begin_inset LatexCommand \index{Assembler routines}
17217
17218 \end_inset
17219
17220
17221 \end_layout
17222
17223 \begin_layout Subsection
17224 Global Registers used for Parameter Passing
17225 \begin_inset LatexCommand \index{Parameter passing}
17226
17227 \end_inset
17228
17229
17230 \end_layout
17231
17232 \begin_layout Standard
17233 The compiler always uses the global registers 
17234 \emph on
17235 DPL, DPH
17236 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17237
17238 \end_inset
17239
17240
17241 \begin_inset LatexCommand \index{DPTR}
17242
17243 \end_inset
17244
17245 , B
17246 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17247
17248 \end_inset
17249
17250  
17251 \emph default
17252 and
17253 \emph on
17254  ACC
17255 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17256
17257 \end_inset
17258
17259
17260 \emph default
17261  to pass the first parameter to a function, and also to pass the return
17262  value 
17263 \begin_inset LatexCommand \index{return value}
17264
17265 \end_inset
17266
17267 of function; according to the following scheme: one byte return value in
17268  
17269 \emph on
17270 DPL
17271 \emph default
17272 , two byte value in 
17273 \emph on
17274 DPL
17275 \emph default
17276  (LSB) and 
17277 \emph on
17278 DPH
17279 \emph default
17280  (MSB).
17281  three byte values (generic pointers) in 
17282 \emph on
17283 DPH
17284 \emph default
17285
17286 \emph on
17287 DPL
17288 \emph default
17289  and 
17290 \emph on
17291 B
17292 \emph default
17293 , and four byte values in 
17294 \emph on
17295 DPH
17296 \emph default
17297
17298 \emph on
17299 DPL
17300 \emph default
17301 ,
17302 \emph on
17303  B
17304 \emph default
17305  and 
17306 \emph on
17307 ACC
17308 \emph default
17309 .
17310  Generic pointers
17311 \begin_inset LatexCommand \index{generic pointer}
17312
17313 \end_inset
17314
17315  contain type of accessed memory in 
17316 \emph on
17317 B
17318 \emph default
17319
17320 \series bold
17321 0x00
17322 \series default
17323  -- xdata/far, 
17324 \series bold
17325 0x40
17326 \series default
17327  -- idata/near -- , 
17328 \series bold
17329 0x60
17330 \series default
17331  -- pdata, 
17332 \series bold
17333 0x80
17334 \series default
17335  -- code
17336 \begin_inset Note Note
17337 status collapsed
17338
17339 \begin_layout Standard
17340 This might not be the case of certain memory models (medium???)
17341 \end_layout
17342
17343 \end_inset
17344
17345 .
17346 \end_layout
17347
17348 \begin_layout Standard
17349 The second parameter onwards is either allocated on the stack (for reentrant
17350  routines or if -
17351 \begin_inset ERT
17352 status collapsed
17353
17354 \begin_layout Standard
17355
17356
17357 \backslash
17358 /
17359 \end_layout
17360
17361 \end_inset
17362
17363 -stack-auto is used) or in data/xdata memory (depending on the memory model).
17364  
17365 \end_layout
17366
17367 \begin_layout Subsection
17368 Registers usage
17369 \end_layout
17370
17371 \begin_layout Standard
17372 Unless the called function is declared as 
17373 \family typewriter
17374 _naked
17375 \family default
17376
17377 \begin_inset LatexCommand \index{naked}
17378
17379 \end_inset
17380
17381 , or the -
17382 \begin_inset ERT
17383 status collapsed
17384
17385 \begin_layout Standard
17386
17387
17388 \backslash
17389 /
17390 \end_layout
17391
17392 \end_inset
17393
17394 -callee-saves
17395 \begin_inset LatexCommand \index{-\/-callee-saves}
17396
17397 \end_inset
17398
17399 /-
17400 \begin_inset ERT
17401 status collapsed
17402
17403 \begin_layout Standard
17404
17405
17406 \backslash
17407 /
17408 \end_layout
17409
17410 \end_inset
17411
17412 -all-callee-saves command line option or the corresponding callee_saves
17413  pragma are used, the caller will save the registers (
17414 \emph on
17415 R0-R7
17416 \emph default
17417 ) around the call, so the called function can destroy they content freely.
17418 \end_layout
17419
17420 \begin_layout Standard
17421 If the called function is not declared as 
17422 \family typewriter
17423 _naked
17424 \family default
17425 , the caller will swap register banks around the call, if caller and callee
17426  use different register banks (having them defined by the 
17427 \family typewriter
17428 _using
17429 \family default
17430  modifier).
17431  
17432 \end_layout
17433
17434 \begin_layout Standard
17435 The called function can also use 
17436 \emph on
17437 DPL
17438 \emph default
17439
17440 \emph on
17441 DPH
17442 \emph default
17443
17444 \emph on
17445 B
17446 \emph default
17447  and 
17448 \emph on
17449 ACC
17450 \emph default
17451  observing that they are used for parameter/return value passing.
17452 \end_layout
17453
17454 \begin_layout Subsection
17455 Assembler Routine (non-reentrant)
17456 \end_layout
17457
17458 \begin_layout Standard
17459 In the following example
17460 \begin_inset LatexCommand \index{reentrant}
17461
17462 \end_inset
17463
17464
17465 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
17466
17467 \end_inset
17468
17469  the function c_func calls an assembler routine asm_func, which takes two
17470  parameters
17471 \begin_inset LatexCommand \index{function parameter}
17472
17473 \end_inset
17474
17475 .
17476 \end_layout
17477
17478 \begin_layout Verse
17479
17480 \family typewriter
17481 extern int asm_func(unsigned char, unsigned char);
17482 \newline
17483
17484 \newline
17485 int c_func (unsigned char
17486  i, unsigned char j)
17487 \newline
17488 {
17489 \newline
17490 \InsetSpace ~
17491 \InsetSpace ~
17492 \InsetSpace ~
17493 \InsetSpace ~
17494 return asm_func(i,j);
17495 \newline
17496 }
17497 \newline
17498
17499 \newline
17500 int main()
17501 \newline
17502 {
17503 \newline
17504 \InsetSpace ~
17505 \InsetSpace ~
17506 \InsetSpace ~
17507 \InsetSpace ~
17508 return c_func(10,9);
17509 \newline
17510 }
17511 \end_layout
17512
17513 \begin_layout Standard
17514 The corresponding assembler function is:
17515 \end_layout
17516
17517 \begin_layout Verse
17518
17519 \family typewriter
17520 .globl _asm_func_PARM_2 
17521 \newline
17522 \InsetSpace ~
17523 \InsetSpace ~
17524 \InsetSpace ~
17525 \InsetSpace ~
17526 \InsetSpace ~
17527 \InsetSpace ~
17528 \InsetSpace ~
17529 \InsetSpace ~
17530 .globl _asm_func 
17531 \newline
17532 \InsetSpace ~
17533 \InsetSpace ~
17534 \InsetSpace ~
17535 \InsetSpace ~
17536 \InsetSpace ~
17537 \InsetSpace ~
17538 \InsetSpace ~
17539 \InsetSpace ~
17540 .area OSEG 
17541 \newline
17542 _asm_func_PARM_2:
17543 \newline
17544 \InsetSpace ~
17545 \InsetSpace ~
17546 \InsetSpace ~
17547 \InsetSpace ~
17548 \InsetSpace ~
17549 \InsetSpace ~
17550 \InsetSpace ~
17551 \InsetSpace ~
17552 .ds   
17553  1 
17554 \newline
17555 \InsetSpace ~
17556 \InsetSpace ~
17557 \InsetSpace ~
17558 \InsetSpace ~
17559 \InsetSpace ~
17560 \InsetSpace ~
17561 \InsetSpace ~
17562 \InsetSpace ~
17563 .area CSEG 
17564 \newline
17565 _asm_func: 
17566 \newline
17567 \InsetSpace ~
17568 \InsetSpace ~
17569 \InsetSpace ~
17570 \InsetSpace ~
17571 \InsetSpace ~
17572 \InsetSpace ~
17573 \InsetSpace ~
17574 \InsetSpace ~
17575 mov\InsetSpace ~
17576 \InsetSpace ~
17577 \InsetSpace ~
17578 \InsetSpace ~
17579 a,dpl 
17580 \newline
17581 \InsetSpace ~
17582 \InsetSpace ~
17583 \InsetSpace ~
17584 \InsetSpace ~
17585 \InsetSpace ~
17586 \InsetSpace ~
17587 \InsetSpace ~
17588 \InsetSpace ~
17589 add\InsetSpace ~
17590 \InsetSpace ~
17591 \InsetSpace ~
17592 \InsetSpace ~
17593 a,_asm_func_PARM_2 
17594 \newline
17595 \InsetSpace ~
17596 \InsetSpace ~
17597 \InsetSpace ~
17598 \InsetSpace ~
17599 \InsetSpace ~
17600 \InsetSpace ~
17601 \InsetSpace ~
17602 \InsetSpace ~
17603 mov\InsetSpace ~
17604 \InsetSpace ~
17605 \InsetSpace ~
17606 \InsetSpace ~
17607 dpl,a 
17608 \newline
17609 \InsetSpace ~
17610 \InsetSpace ~
17611 \InsetSpace ~
17612 \InsetSpace ~
17613 \InsetSpace ~
17614 \InsetSpace ~
17615 \InsetSpace ~
17616 \InsetSpace ~
17617 mov\InsetSpace ~
17618 \InsetSpace ~
17619 \InsetSpace ~
17620 \InsetSpace ~
17621 dph
17622 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17623
17624 \end_inset
17625
17626 ,#0x00 
17627 \newline
17628 \InsetSpace ~
17629 \InsetSpace ~
17630 \InsetSpace ~
17631 \InsetSpace ~
17632 \InsetSpace ~
17633 \InsetSpace ~
17634 \InsetSpace ~
17635 \InsetSpace ~
17636 ret
17637 \end_layout
17638
17639 \begin_layout Standard
17640 The parameter naming convention is _<function_name>_PARM_<n>, where n is
17641  the parameter number starting from 1, and counting from the left.
17642  The first parameter is passed in 
17643 \emph on
17644 DPH
17645 \emph default
17646
17647 \emph on
17648 DPL
17649 \emph default
17650
17651 \emph on
17652 B
17653 \emph default
17654  and 
17655 \emph on
17656 ACC
17657 \emph default
17658  according to the description above.
17659  The variable name for the second parameter will be _<function_name>_PARM_2.
17660 \newline
17661
17662 \newline
17663 Assem
17664 ble the assembler routine with the following command:
17665 \newline
17666
17667 \newline
17668
17669 \family sans
17670 \series bold
17671 asx8051 -losg asmfunc.asm
17672 \newline
17673
17674 \newline
17675
17676 \family default
17677 \series default
17678 Then compile and link the assembler routine to the C source file with the
17679  following command:
17680 \newline
17681
17682 \newline
17683
17684 \family sans
17685 \series bold
17686 sdcc cfunc.c asmfunc.rel
17687 \end_layout
17688
17689 \begin_layout Subsection
17690 Assembler Routine (reentrant)
17691 \end_layout
17692
17693 \begin_layout Standard
17694 In this case
17695 \begin_inset LatexCommand \index{reentrant}
17696
17697 \end_inset
17698
17699
17700 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
17701
17702 \end_inset
17703
17704  the second parameter
17705 \begin_inset LatexCommand \index{function parameter}
17706
17707 \end_inset
17708
17709  onwards will be passed on the stack, the parameters are pushed from right
17710  to left i.e.
17711  before the call the second leftmost parameter will be on the top of the
17712  stack (the leftmost parameter is passed in registers).
17713  Here is an example:
17714 \end_layout
17715
17716 \begin_layout Verse
17717
17718 \family typewriter
17719 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
17720 \newline
17721
17722 \newline
17723 int
17724  c_func (unsigned char i, unsigned char j, unsigned char k) reentrant 
17725 \newline
17726 {
17727  
17728 \newline
17729 \InsetSpace ~
17730 \InsetSpace ~
17731 \InsetSpace ~
17732 \InsetSpace ~
17733 return asm_func(i,j,k); 
17734 \newline
17735
17736 \newline
17737
17738 \newline
17739 int main() 
17740 \newline
17741
17742 \newline
17743 \InsetSpace ~
17744 \InsetSpace ~
17745 \InsetSpace ~
17746 \InsetSpace ~
17747 return c_func(10,9,8); 
17748 \newline
17749 }
17750 \end_layout
17751
17752 \begin_layout Standard
17753 The corresponding (unoptimized) assembler routine is:
17754 \end_layout
17755
17756 \begin_layout Verse
17757
17758 \family typewriter
17759 .globl _asm_func 
17760 \newline
17761 _asm_func: 
17762 \newline
17763 \InsetSpace ~
17764 \InsetSpace ~
17765 \InsetSpace ~
17766 \InsetSpace ~
17767 push\InsetSpace ~
17768 _bp 
17769 \newline
17770 \InsetSpace ~
17771 \InsetSpace ~
17772 \InsetSpace ~
17773 \InsetSpace ~
17774 mov\InsetSpace ~
17775 \InsetSpace ~
17776 _bp,sp\InsetSpace ~
17777 \InsetSpace ~
17778 \InsetSpace ~
17779 \InsetSpace ~
17780 \InsetSpace ~
17781 \InsetSpace ~
17782 ;stack contains: _bp, return
17783  address, second parameter, third parameter
17784 \newline
17785 \InsetSpace ~
17786 \InsetSpace ~
17787 \InsetSpace ~
17788 \InsetSpace ~
17789 mov\InsetSpace ~
17790 \InsetSpace ~
17791 r2,dpl
17792 \newline
17793 \InsetSpace ~
17794 \InsetSpace ~
17795 \InsetSpace ~
17796 \InsetSpace ~
17797 mov\InsetSpace ~
17798 \InsetSpace ~
17799 a,_bp
17800 \newline
17801 \InsetSpace ~
17802 \InsetSpace ~
17803 \InsetSpace ~
17804 \InsetSpace ~
17805 add\InsetSpace ~
17806 \InsetSpace ~
17807 a,#0xfd\InsetSpace ~
17808 \InsetSpace ~
17809 \InsetSpace ~
17810 \InsetSpace ~
17811 \InsetSpace ~
17812 ;calculate
17813  pointer to the second parameter
17814 \newline
17815 \InsetSpace ~
17816 \InsetSpace ~
17817 \InsetSpace ~
17818 \InsetSpace ~
17819 mov\InsetSpace ~
17820 \InsetSpace ~
17821 r0,a 
17822 \newline
17823 \InsetSpace ~
17824 \InsetSpace ~
17825 \InsetSpace ~
17826 \InsetSpace ~
17827 mov\InsetSpace ~
17828 \InsetSpace ~
17829 a,_bp 
17830 \newline
17831 \InsetSpace ~
17832 \InsetSpace ~
17833 \InsetSpace ~
17834 \InsetSpace ~
17835 add\InsetSpace ~
17836 \InsetSpace ~
17837 a,#0xfc\InsetSpace ~
17838 \InsetSpace ~
17839 \InsetSpace ~
17840 \InsetSpace ~
17841 \InsetSpace ~
17842 ;calculate pointer
17843  to the rightmost parameter
17844 \newline
17845 \InsetSpace ~
17846 \InsetSpace ~
17847 \InsetSpace ~
17848 \InsetSpace ~
17849 mov\InsetSpace ~
17850 \InsetSpace ~
17851 r1,a 
17852 \newline
17853 \InsetSpace ~
17854 \InsetSpace ~
17855 \InsetSpace ~
17856 \InsetSpace ~
17857 mov\InsetSpace ~
17858 \InsetSpace ~
17859 a,@r0
17860 \newline
17861 \InsetSpace ~
17862 \InsetSpace ~
17863 \InsetSpace ~
17864 \InsetSpace ~
17865 add\InsetSpace ~
17866 \InsetSpace ~
17867 a,@r1
17868 \newline
17869 \InsetSpace ~
17870 \InsetSpace ~
17871 \InsetSpace ~
17872 \InsetSpace ~
17873 add\InsetSpace ~
17874 \InsetSpace ~
17875 a,r2\InsetSpace ~
17876 \InsetSpace ~
17877 \InsetSpace ~
17878 \InsetSpace ~
17879 \InsetSpace ~
17880 \InsetSpace ~
17881 \InsetSpace ~
17882 \InsetSpace ~
17883 ;calculate the
17884  result (= sum of all three parameters)
17885 \newline
17886 \InsetSpace ~
17887 \InsetSpace ~
17888 \InsetSpace ~
17889 \InsetSpace ~
17890 mov\InsetSpace ~
17891 \InsetSpace ~
17892 dpl,a\InsetSpace ~
17893 \InsetSpace ~
17894 \InsetSpace ~
17895 \InsetSpace ~
17896 \InsetSpace ~
17897 \InsetSpace ~
17898 \InsetSpace ~
17899 ;return value goes into dptr
17900  (cast into int)
17901 \newline
17902 \InsetSpace ~
17903 \InsetSpace ~
17904 \InsetSpace ~
17905 \InsetSpace ~
17906 mov\InsetSpace ~
17907 \InsetSpace ~
17908 dph,#0x00 
17909 \newline
17910 \InsetSpace ~
17911 \InsetSpace ~
17912 \InsetSpace ~
17913 \InsetSpace ~
17914 mov\InsetSpace ~
17915 \InsetSpace ~
17916 sp,_bp 
17917 \newline
17918 \InsetSpace ~
17919 \InsetSpace ~
17920 \InsetSpace ~
17921 \InsetSpace ~
17922 pop\InsetSpace ~
17923 \InsetSpace ~
17924 _bp 
17925 \newline
17926 \InsetSpace ~
17927 \InsetSpace ~
17928 \InsetSpace ~
17929 \InsetSpace ~
17930 ret
17931 \end_layout
17932
17933 \begin_layout Standard
17934 The compiling and linking procedure remains the same, however note the extra
17935  entry & exit linkage required for the assembler code, _bp is the stack
17936  frame pointer and is used to compute the offset into the stack for parameters
17937  and local variables.
17938 \begin_inset VSpace bigskip
17939 \end_inset
17940
17941
17942 \end_layout
17943
17944 \begin_layout Section
17945 int (16 bit)
17946 \begin_inset LatexCommand \index{int (16 bit)}
17947
17948 \end_inset
17949
17950  and long (32 bit)
17951 \begin_inset LatexCommand \index{long (32 bit)}
17952
17953 \end_inset
17954
17955  Support
17956 \end_layout
17957
17958 \begin_layout Standard
17959 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
17960  multiplication and modulus operations are implemented by support routines.
17961  These support routines are all developed in ANSI-C to facilitate porting
17962  to other MCUs, although some model specific assembler optimizations are
17963  used.
17964  The following files contain the described routines, all of them can be
17965  found in <installdir>/share/sdcc/lib.
17966 \newline
17967
17968 \end_layout
17969
17970 \begin_layout Standard
17971 \align center
17972 \begin_inset Tabular
17973 <lyxtabular version="3" rows="11" columns="2">
17974 <features>
17975 <column alignment="left" valignment="top" leftline="true" width="0">
17976 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
17977 <row topline="true" bottomline="true">
17978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17979 \begin_inset Text
17980
17981 \begin_layout Standard
17982
17983 \series bold
17984 Function
17985 \end_layout
17986
17987 \end_inset
17988 </cell>
17989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17990 \begin_inset Text
17991
17992 \begin_layout Standard
17993
17994 \series bold
17995 Description
17996 \end_layout
17997
17998 \end_inset
17999 </cell>
18000 </row>
18001 <row topline="true">
18002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18003 \begin_inset Text
18004
18005 \begin_layout Standard
18006 _mulint.c 
18007 \end_layout
18008
18009 \end_inset
18010 </cell>
18011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18012 \begin_inset Text
18013
18014 \begin_layout Standard
18015 16 bit multiplication
18016 \end_layout
18017
18018 \end_inset
18019 </cell>
18020 </row>
18021 <row topline="true">
18022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18023 \begin_inset Text
18024
18025 \begin_layout Standard
18026 _divsint.c 
18027 \end_layout
18028
18029 \end_inset
18030 </cell>
18031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18032 \begin_inset Text
18033
18034 \begin_layout Standard
18035  signed 16 bit division (calls _divuint)
18036 \end_layout
18037
18038 \end_inset
18039 </cell>
18040 </row>
18041 <row topline="true">
18042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18043 \begin_inset Text
18044
18045 \begin_layout Standard
18046 _divuint.c 
18047 \end_layout
18048
18049 \end_inset
18050 </cell>
18051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18052 \begin_inset Text
18053
18054 \begin_layout Standard
18055  unsigned 16 bit division
18056 \end_layout
18057
18058 \end_inset
18059 </cell>
18060 </row>
18061 <row topline="true">
18062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18063 \begin_inset Text
18064
18065 \begin_layout Standard
18066 _modsint.c
18067 \end_layout
18068
18069 \end_inset
18070 </cell>
18071 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18072 \begin_inset Text
18073
18074 \begin_layout Standard
18075 signed 16 bit modulus (calls _moduint)
18076 \end_layout
18077
18078 \end_inset
18079 </cell>
18080 </row>
18081 <row topline="true">
18082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18083 \begin_inset Text
18084
18085 \begin_layout Standard
18086 _moduint.c
18087 \end_layout
18088
18089 \end_inset
18090 </cell>
18091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18092 \begin_inset Text
18093
18094 \begin_layout Standard
18095 unsigned 16 bit modulus
18096 \end_layout
18097
18098 \end_inset
18099 </cell>
18100 </row>
18101 <row topline="true">
18102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18103 \begin_inset Text
18104
18105 \begin_layout Standard
18106 _mullong.c
18107 \end_layout
18108
18109 \end_inset
18110 </cell>
18111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18112 \begin_inset Text
18113
18114 \begin_layout Standard
18115 32 bit multiplication
18116 \end_layout
18117
18118 \end_inset
18119 </cell>
18120 </row>
18121 <row topline="true">
18122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18123 \begin_inset Text
18124
18125 \begin_layout Standard
18126 _divslong.c 
18127 \end_layout
18128
18129 \end_inset
18130 </cell>
18131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18132 \begin_inset Text
18133
18134 \begin_layout Standard
18135  signed 32 division (calls _divulong)
18136 \end_layout
18137
18138 \end_inset
18139 </cell>
18140 </row>
18141 <row topline="true">
18142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18143 \begin_inset Text
18144
18145 \begin_layout Standard
18146 _divulong.c 
18147 \end_layout
18148
18149 \end_inset
18150 </cell>
18151 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18152 \begin_inset Text
18153
18154 \begin_layout Standard
18155 unsigned 32 division
18156 \end_layout
18157
18158 \end_inset
18159 </cell>
18160 </row>
18161 <row topline="true">
18162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18163 \begin_inset Text
18164
18165 \begin_layout Standard
18166 _modslong.c
18167 \end_layout
18168
18169 \end_inset
18170 </cell>
18171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18172 \begin_inset Text
18173
18174 \begin_layout Standard
18175  signed 32 bit modulus (calls _modulong)
18176 \end_layout
18177
18178 \end_inset
18179 </cell>
18180 </row>
18181 <row topline="true" bottomline="true">
18182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18183 \begin_inset Text
18184
18185 \begin_layout Standard
18186 _modulong.c
18187 \end_layout
18188
18189 \end_inset
18190 </cell>
18191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18192 \begin_inset Text
18193
18194 \begin_layout Standard
18195 unsigned 32 bit modulus
18196 \end_layout
18197
18198 \end_inset
18199 </cell>
18200 </row>
18201 </lyxtabular>
18202
18203 \end_inset
18204
18205
18206 \newline
18207
18208 \end_layout
18209
18210 \begin_layout Standard
18211 Since they are compiled as 
18212 \emph on
18213 non-reentrant
18214 \emph default
18215
18216 \begin_inset LatexCommand \index{reentrant}
18217
18218 \end_inset
18219
18220 , interrupt
18221 \begin_inset LatexCommand \index{interrupt}
18222
18223 \end_inset
18224
18225  service routines should not do any of the above operations.
18226  If this is unavoidable then the above routines will need to be compiled
18227  with the 
18228 \emph on
18229 -
18230 \begin_inset ERT
18231 status collapsed
18232
18233 \begin_layout Standard
18234
18235
18236 \backslash
18237 /
18238 \end_layout
18239
18240 \end_inset
18241
18242 -stack-auto
18243 \begin_inset LatexCommand \index{-\/-stack-auto}
18244
18245 \end_inset
18246
18247
18248 \emph default
18249  option, after which the source program will have to be compiled with 
18250 \emph on
18251 -
18252 \begin_inset ERT
18253 status collapsed
18254
18255 \begin_layout Standard
18256
18257
18258 \backslash
18259 /
18260 \end_layout
18261
18262 \end_inset
18263
18264 -int-long-reent
18265 \begin_inset LatexCommand \index{-\/-int-long-reent}
18266
18267 \end_inset
18268
18269
18270 \emph default
18271  option.
18272  Notice that you don't have to call these routines directly.
18273  The compiler will use them automatically every time an integer operation
18274  is required.
18275 \end_layout
18276
18277 \begin_layout Section
18278 Floating Point Support
18279 \begin_inset LatexCommand \index{Floating point support}
18280
18281 \end_inset
18282
18283
18284 \end_layout
18285
18286 \begin_layout Standard
18287 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
18288  The floating point support routines are derived from gcc's floatlib.c and
18289  consist of the following routines:
18290 \newline
18291
18292 \end_layout
18293
18294 \begin_layout Standard
18295 \align center
18296
18297 \size footnotesize
18298 \begin_inset Tabular
18299 <lyxtabular version="3" rows="17" columns="2">
18300 <features>
18301 <column alignment="left" valignment="top" leftline="true" width="0">
18302 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18303 <row topline="true" bottomline="true">
18304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18305 \begin_inset Text
18306
18307 \begin_layout Standard
18308
18309 \family roman
18310 \series medium
18311 \shape up
18312 \size normal
18313 \emph off
18314 \bar no
18315 \noun off
18316 \color none
18317 Function 
18318 \end_layout
18319
18320 \end_inset
18321 </cell>
18322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18323 \begin_inset Text
18324
18325 \begin_layout Standard
18326 Description
18327 \end_layout
18328
18329 \end_inset
18330 </cell>
18331 </row>
18332 <row topline="true">
18333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18334 \begin_inset Text
18335
18336 \begin_layout Standard
18337
18338 \family roman
18339 \series medium
18340 \shape up
18341 \size normal
18342 \emph off
18343 \bar no
18344 \noun off
18345 \color none
18346 _fsadd.c
18347 \end_layout
18348
18349 \end_inset
18350 </cell>
18351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18352 \begin_inset Text
18353
18354 \begin_layout Standard
18355
18356 \family roman
18357 \series medium
18358 \shape up
18359 \size normal
18360 \emph off
18361 \bar no
18362 \noun off
18363 \color none
18364 add floating point numbers
18365 \end_layout
18366
18367 \end_inset
18368 </cell>
18369 </row>
18370 <row topline="true">
18371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18372 \begin_inset Text
18373
18374 \begin_layout Standard
18375
18376 \family roman
18377 \series medium
18378 \shape up
18379 \size normal
18380 \emph off
18381 \bar no
18382 \noun off
18383 \color none
18384 _fssub.c 
18385 \end_layout
18386
18387 \end_inset
18388 </cell>
18389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18390 \begin_inset Text
18391
18392 \begin_layout Standard
18393
18394 \family roman
18395 \series medium
18396 \shape up
18397 \size normal
18398 \emph off
18399 \bar no
18400 \noun off
18401 \color none
18402 subtract floating point numbers 
18403 \end_layout
18404
18405 \end_inset
18406 </cell>
18407 </row>
18408 <row topline="true">
18409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18410 \begin_inset Text
18411
18412 \begin_layout Standard
18413
18414 \family roman
18415 \series medium
18416 \shape up
18417 \size normal
18418 \emph off
18419 \bar no
18420 \noun off
18421 \color none
18422 _fsdiv.c 
18423 \end_layout
18424
18425 \end_inset
18426 </cell>
18427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18428 \begin_inset Text
18429
18430 \begin_layout Standard
18431
18432 \family roman
18433 \series medium
18434 \shape up
18435 \size normal
18436 \emph off
18437 \bar no
18438 \noun off
18439 \color none
18440 divide floating point numbers 
18441 \end_layout
18442
18443 \end_inset
18444 </cell>
18445 </row>
18446 <row topline="true">
18447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18448 \begin_inset Text
18449
18450 \begin_layout Standard
18451
18452 \family roman
18453 \series medium
18454 \shape up
18455 \size normal
18456 \emph off
18457 \bar no
18458 \noun off
18459 \color none
18460 _fsmul.c 
18461 \end_layout
18462
18463 \end_inset
18464 </cell>
18465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18466 \begin_inset Text
18467
18468 \begin_layout Standard
18469
18470 \family roman
18471 \series medium
18472 \shape up
18473 \size normal
18474 \emph off
18475 \bar no
18476 \noun off
18477 \color none
18478 multiply floating point numbers 
18479 \end_layout
18480
18481 \end_inset
18482 </cell>
18483 </row>
18484 <row topline="true">
18485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18486 \begin_inset Text
18487
18488 \begin_layout Standard
18489
18490 \family roman
18491 \series medium
18492 \shape up
18493 \size normal
18494 \emph off
18495 \bar no
18496 \noun off
18497 \color none
18498 _fs2uchar.c
18499 \end_layout
18500
18501 \end_inset
18502 </cell>
18503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18504 \begin_inset Text
18505
18506 \begin_layout Standard
18507
18508 \family roman
18509 \series medium
18510 \shape up
18511 \size normal
18512 \emph off
18513 \bar no
18514 \noun off
18515 \color none
18516 convert floating point to unsigned char
18517 \end_layout
18518
18519 \end_inset
18520 </cell>
18521 </row>
18522 <row topline="true">
18523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18524 \begin_inset Text
18525
18526 \begin_layout Standard
18527
18528 \family roman
18529 \series medium
18530 \shape up
18531 \size normal
18532 \emph off
18533 \bar no
18534 \noun off
18535 \color none
18536 _fs2char.c
18537 \end_layout
18538
18539 \end_inset
18540 </cell>
18541 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18542 \begin_inset Text
18543
18544 \begin_layout Standard
18545
18546 \family roman
18547 \series medium
18548 \shape up
18549 \size normal
18550 \emph off
18551 \bar no
18552 \noun off
18553 \color none
18554 convert floating point to signed char
18555 \end_layout
18556
18557 \end_inset
18558 </cell>
18559 </row>
18560 <row topline="true">
18561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18562 \begin_inset Text
18563
18564 \begin_layout Standard
18565
18566 \family roman
18567 \series medium
18568 \shape up
18569 \size normal
18570 \emph off
18571 \bar no
18572 \noun off
18573 \color none
18574 _fs2uint.c
18575 \end_layout
18576
18577 \end_inset
18578 </cell>
18579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18580 \begin_inset Text
18581
18582 \begin_layout Standard
18583
18584 \family roman
18585 \series medium
18586 \shape up
18587 \size normal
18588 \emph off
18589 \bar no
18590 \noun off
18591 \color none
18592 convert floating point to unsigned int
18593 \end_layout
18594
18595 \end_inset
18596 </cell>
18597 </row>
18598 <row topline="true">
18599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18600 \begin_inset Text
18601
18602 \begin_layout Standard
18603
18604 \family roman
18605 \series medium
18606 \shape up
18607 \size normal
18608 \emph off
18609 \bar no
18610 \noun off
18611 \color none
18612 _fs2int.c
18613 \end_layout
18614
18615 \end_inset
18616 </cell>
18617 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="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 convert floating point to signed int
18631 \end_layout
18632
18633 \end_inset
18634 </cell>
18635 </row>
18636 <row topline="true">
18637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18638 \begin_inset Text
18639
18640 \begin_layout Standard
18641
18642 \family roman
18643 \series medium
18644 \shape up
18645 \size normal
18646 \emph off
18647 \bar no
18648 \noun off
18649 \color none
18650 _fs2ulong.
18651 \family default
18652 \series default
18653 \shape default
18654 \size default
18655 \emph default
18656 \bar default
18657 \noun default
18658 c
18659 \end_layout
18660
18661 \end_inset
18662 </cell>
18663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18664 \begin_inset Text
18665
18666 \begin_layout Standard
18667
18668 \family roman
18669 \series medium
18670 \shape up
18671 \size normal
18672 \emph off
18673 \bar no
18674 \noun off
18675 \color none
18676 convert floating point to unsigned long
18677 \end_layout
18678
18679 \end_inset
18680 </cell>
18681 </row>
18682 <row topline="true">
18683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18684 \begin_inset Text
18685
18686 \begin_layout Standard
18687
18688 \family roman
18689 \series medium
18690 \shape up
18691 \size normal
18692 \emph off
18693 \bar no
18694 \noun off
18695 \color none
18696 _fs2long.c
18697 \end_layout
18698
18699 \end_inset
18700 </cell>
18701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18702 \begin_inset Text
18703
18704 \begin_layout Standard
18705
18706 \family roman
18707 \series medium
18708 \shape up
18709 \size normal
18710 \emph off
18711 \bar no
18712 \noun off
18713 \color none
18714 convert floating point to signed long
18715 \end_layout
18716
18717 \end_inset
18718 </cell>
18719 </row>
18720 <row topline="true">
18721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18722 \begin_inset Text
18723
18724 \begin_layout Standard
18725
18726 \family roman
18727 \series medium
18728 \shape up
18729 \size normal
18730 \emph off
18731 \bar no
18732 \noun off
18733 \color none
18734 _uchar2fs.c
18735 \end_layout
18736
18737 \end_inset
18738 </cell>
18739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18740 \begin_inset Text
18741
18742 \begin_layout Standard
18743
18744 \family roman
18745 \series medium
18746 \shape up
18747 \size normal
18748 \emph off
18749 \bar no
18750 \noun off
18751 \color none
18752 convert unsigned char to floating point
18753 \end_layout
18754
18755 \end_inset
18756 </cell>
18757 </row>
18758 <row topline="true">
18759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18760 \begin_inset Text
18761
18762 \begin_layout Standard
18763
18764 \family roman
18765 \series medium
18766 \shape up
18767 \size normal
18768 \emph off
18769 \bar no
18770 \noun off
18771 \color none
18772 _char2fs.c
18773 \end_layout
18774
18775 \end_inset
18776 </cell>
18777 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18778 \begin_inset Text
18779
18780 \begin_layout Standard
18781
18782 \family roman
18783 \series medium
18784 \shape up
18785 \size normal
18786 \emph off
18787 \bar no
18788 \noun off
18789 \color none
18790 convert char to floating point number
18791 \end_layout
18792
18793 \end_inset
18794 </cell>
18795 </row>
18796 <row topline="true">
18797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18798 \begin_inset Text
18799
18800 \begin_layout Standard
18801
18802 \family roman
18803 \series medium
18804 \shape up
18805 \size normal
18806 \emph off
18807 \bar no
18808 \noun off
18809 \color none
18810 _uint2fs.c
18811 \end_layout
18812
18813 \end_inset
18814 </cell>
18815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18816 \begin_inset Text
18817
18818 \begin_layout Standard
18819
18820 \family roman
18821 \series medium
18822 \shape up
18823 \size normal
18824 \emph off
18825 \bar no
18826 \noun off
18827 \color none
18828 convert unsigned int to floating point
18829 \end_layout
18830
18831 \end_inset
18832 </cell>
18833 </row>
18834 <row topline="true">
18835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18836 \begin_inset Text
18837
18838 \begin_layout Standard
18839
18840 \family roman
18841 \series medium
18842 \shape up
18843 \size normal
18844 \emph off
18845 \bar no
18846 \noun off
18847 \color none
18848 _int2fs.c
18849 \end_layout
18850
18851 \end_inset
18852 </cell>
18853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18854 \begin_inset Text
18855
18856 \begin_layout Standard
18857
18858 \family roman
18859 \series medium
18860 \shape up
18861 \size normal
18862 \emph off
18863 \bar no
18864 \noun off
18865 \color none
18866 convert int to floating point numbers
18867 \end_layout
18868
18869 \end_inset
18870 </cell>
18871 </row>
18872 <row topline="true">
18873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18874 \begin_inset Text
18875
18876 \begin_layout Standard
18877
18878 \family roman
18879 \series medium
18880 \shape up
18881 \size normal
18882 \emph off
18883 \bar no
18884 \noun off
18885 \color none
18886 _ulong2fs.c
18887 \end_layout
18888
18889 \end_inset
18890 </cell>
18891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18892 \begin_inset Text
18893
18894 \begin_layout Standard
18895
18896 \family roman
18897 \series medium
18898 \shape up
18899 \size normal
18900 \emph off
18901 \bar no
18902 \noun off
18903 \color none
18904 convert unsigned long to floating point number
18905 \end_layout
18906
18907 \end_inset
18908 </cell>
18909 </row>
18910 <row topline="true" bottomline="true">
18911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18912 \begin_inset Text
18913
18914 \begin_layout Standard
18915
18916 \family roman
18917 \series medium
18918 \shape up
18919 \size normal
18920 \emph off
18921 \bar no
18922 \noun off
18923 \color none
18924 _long2fs.c
18925 \end_layout
18926
18927 \end_inset
18928 </cell>
18929 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18930 \begin_inset Text
18931
18932 \begin_layout Standard
18933
18934 \family roman
18935 \series medium
18936 \shape up
18937 \size normal
18938 \emph off
18939 \bar no
18940 \noun off
18941 \color none
18942 convert long to floating point number
18943 \end_layout
18944
18945 \end_inset
18946 </cell>
18947 </row>
18948 </lyxtabular>
18949
18950 \end_inset
18951
18952
18953 \newline
18954
18955 \end_layout
18956
18957 \begin_layout Standard
18958 These support routines are developed in ANSI-C so there is room for space
18959  and speed improvement
18960 \begin_inset Foot
18961 status open
18962
18963 \begin_layout Standard
18964 These floating point routines (
18965 \emph on
18966 not
18967 \emph default
18968  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
18969  
18970 \end_layout
18971
18972 \end_inset
18973
18974 .
18975  Note if all these routines are used simultaneously the data space might
18976  overflow.
18977  For serious floating point usage the large model might be needed.
18978  Also notice that you don't have to call this routines directly.
18979  The compiler will use them automatically every time a floating point operation
18980  is required.
18981 \begin_inset VSpace bigskip
18982 \end_inset
18983
18984
18985 \end_layout
18986
18987 \begin_layout Section
18988 Library Routines
18989 \begin_inset LatexCommand \index{Libraries}
18990
18991 \end_inset
18992
18993
18994 \end_layout
18995
18996 \begin_layout Standard
18997
18998 \emph on
18999 <pending: this is messy and incomplete - a little more information is in
19000  sdcc/doc/libdoc.txt
19001 \emph default
19002  >
19003 \end_layout
19004
19005 \begin_layout Subsection
19006 Compiler support routines (_gptrget, _mulint etc.)
19007 \end_layout
19008
19009 \begin_layout Subsection
19010 Stdclib functions (puts, printf, strcat etc.)
19011 \end_layout
19012
19013 \begin_layout Subsubsection
19014 <stdio.h>
19015 \end_layout
19016
19017 \begin_layout Paragraph
19018 getchar(), putchar()
19019 \end_layout
19020
19021 \begin_layout Standard
19022 \begin_inset LatexCommand \index{<stdio.h>}
19023
19024 \end_inset
19025
19026 As usual on embedded systems you have to provide your own 
19027 \family typewriter
19028 getchar()
19029 \begin_inset LatexCommand \index{getchar()}
19030
19031 \end_inset
19032
19033  
19034 \family default
19035 and 
19036 \family typewriter
19037 putchar()
19038 \begin_inset LatexCommand \index{putchar()}
19039
19040 \end_inset
19041
19042
19043 \family default
19044  routines.
19045  SDCC does not know whether the system connects to a serial line with or
19046  without handshake, LCD, keyboard or other device.
19047  And whether a 
19048 \family typewriter
19049 lf
19050 \family default
19051  to 
19052 \family typewriter
19053 crlf
19054 \family default
19055  conversion within 
19056 \family typewriter
19057 putchar()
19058 \family default
19059  is intended.
19060  You'll find examples for serial routines f.e.
19061  in sdcc/device/lib.
19062  For the mcs51 this minimalistic polling 
19063 \family typewriter
19064 putchar()
19065 \family default
19066  routine might be a start:
19067 \end_layout
19068
19069 \begin_layout Verse
19070
19071 \family typewriter
19072 void putchar (char c) { 
19073 \newline
19074 \InsetSpace ~
19075 \InsetSpace ~
19076 \InsetSpace ~
19077 \InsetSpace ~
19078 while (!TI)\InsetSpace ~
19079 \InsetSpace ~
19080 \InsetSpace ~
19081  /* assumes UART is initialized */
19082 \newline
19083 \InsetSpace ~
19084 \InsetSpace ~
19085 \InsetSpace ~
19086 \InsetSpace ~
19087 \InsetSpace ~
19088 \InsetSpace ~
19089 \InsetSpace ~
19090 \InsetSpace ~
19091 ;
19092 \newline
19093 \InsetSpace ~
19094 \InsetSpace ~
19095 \InsetSpace ~
19096 \InsetSpace ~
19097 TI
19098  = 0;
19099 \newline
19100 \InsetSpace ~
19101 \InsetSpace ~
19102 \InsetSpace ~
19103 \InsetSpace ~
19104 SBUF = c;
19105 \newline
19106 }
19107 \end_layout
19108
19109 \begin_layout Paragraph
19110 printf()
19111 \end_layout
19112
19113 \begin_layout Standard
19114 The default
19115 \family typewriter
19116  printf()
19117 \begin_inset LatexCommand \index{printf()}
19118
19119 \end_inset
19120
19121
19122 \family default
19123  implementation in
19124 \family typewriter
19125  printf_large.c
19126 \family default
19127  does not support float (except on ds390).
19128  To enable this recompile it with the option 
19129 \emph on
19130 -
19131 \begin_inset ERT
19132 status collapsed
19133
19134 \begin_layout Standard
19135
19136
19137 \backslash
19138 /
19139 \end_layout
19140
19141 \end_inset
19142
19143 DUSE_FLOATS=1
19144 \begin_inset LatexCommand \index{USE\_FLOATS}
19145
19146 \end_inset
19147
19148
19149 \emph default
19150  on the command line.
19151  Use
19152 \emph on
19153  -
19154 \begin_inset ERT
19155 status collapsed
19156
19157 \begin_layout Standard
19158
19159
19160 \backslash
19161 /
19162 \end_layout
19163
19164 \end_inset
19165
19166 -model-large
19167 \begin_inset LatexCommand \index{-\/-model-large}
19168
19169 \end_inset
19170
19171
19172 \emph default
19173  for the mcs51 port, since this uses a lot of memory.
19174 \end_layout
19175
19176 \begin_layout Standard
19177 If you're short on code memory you might want to use 
19178 \family typewriter
19179 printf_small()
19180 \begin_inset LatexCommand \index{printf\_small()}
19181
19182 \end_inset
19183
19184
19185 \family default
19186  
19187 \emph on
19188 instead
19189 \emph default
19190  of
19191 \family typewriter
19192  printf().
19193
19194 \family default
19195  For the mcs51 there additionally are assembly versions 
19196 \family typewriter
19197 printf_tiny()
19198 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19199
19200 \end_inset
19201
19202
19203 \family default
19204  (subset of printf using less than 270 bytes) and 
19205 \family typewriter
19206 printf_fast()
19207 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19208
19209 \end_inset
19210
19211  
19212 \family default
19213 and
19214 \family typewriter
19215  printf_fast_f()
19216 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19217
19218 \end_inset
19219
19220
19221 \family default
19222  (floating-point aware version of printf_fast) which should fit the requirements
19223  of many embedded systems (printf_fast() can be customized by unsetting
19224  #defines to 
19225 \emph on
19226 not
19227 \emph default
19228  support long variables and field widths).
19229  Be sure to use only one of these printf options within a project.
19230 \newline
19231
19232 \end_layout
19233
19234 \begin_layout Standard
19235 Feature matrix of different 
19236 \emph on
19237 printf
19238 \emph default
19239  options on mcs51.
19240 \end_layout
19241
19242 \begin_layout Standard
19243 \begin_inset Tabular
19244 <lyxtabular version="3" rows="14" columns="7">
19245 <features islongtable="true">
19246 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19247 <column alignment="center" valignment="top" leftline="true" width="0">
19248 <column alignment="center" valignment="top" leftline="true" width="12col%">
19249 <column alignment="center" valignment="top" leftline="true" width="10col%">
19250 <column alignment="center" valignment="top" leftline="true" width="0">
19251 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19252 <column alignment="center" valignment="top" rightline="true" width="0">
19253 <row topline="true" bottomline="true" endhead="true">
19254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19255 \begin_inset Text
19256
19257 \begin_layout Standard
19258
19259 \series bold
19260 \size large
19261 mcs51
19262 \end_layout
19263
19264 \end_inset
19265 </cell>
19266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19267 \begin_inset Text
19268
19269 \begin_layout Standard
19270 printf
19271 \begin_inset LatexCommand \index{printf}
19272
19273 \end_inset
19274
19275
19276 \end_layout
19277
19278 \end_inset
19279 </cell>
19280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19281 \begin_inset Text
19282
19283 \begin_layout Standard
19284 printf 
19285 \size scriptsize
19286 USE_FLOATS=1
19287 \end_layout
19288
19289 \end_inset
19290 </cell>
19291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19292 \begin_inset Text
19293
19294 \begin_layout Standard
19295 printf_small
19296 \end_layout
19297
19298 \end_inset
19299 </cell>
19300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19301 \begin_inset Text
19302
19303 \begin_layout Standard
19304 printf_fast
19305 \end_layout
19306
19307 \end_inset
19308 </cell>
19309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19310 \begin_inset Text
19311
19312 \begin_layout Standard
19313 printf_fast_f
19314 \end_layout
19315
19316 \end_inset
19317 </cell>
19318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19319 \begin_inset Text
19320
19321 \begin_layout Standard
19322 printf_tiny
19323 \end_layout
19324
19325 \end_inset
19326 </cell>
19327 </row>
19328 <row topline="true" endhead="true">
19329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19330 \begin_inset Text
19331
19332 \begin_layout Standard
19333 filename
19334 \end_layout
19335
19336 \end_inset
19337 </cell>
19338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19339 \begin_inset Text
19340
19341 \begin_layout Standard
19342
19343 \size scriptsize
19344 printf_large.c
19345 \end_layout
19346
19347 \end_inset
19348 </cell>
19349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19350 \begin_inset Text
19351
19352 \begin_layout Standard
19353
19354 \size scriptsize
19355 printf_large.c
19356 \end_layout
19357
19358 \end_inset
19359 </cell>
19360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19361 \begin_inset Text
19362
19363 \begin_layout Standard
19364
19365 \size scriptsize
19366 printfl.c
19367 \end_layout
19368
19369 \end_inset
19370 </cell>
19371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19372 \begin_inset Text
19373
19374 \begin_layout Standard
19375
19376 \size scriptsize
19377 printf_fast.c
19378 \end_layout
19379
19380 \end_inset
19381 </cell>
19382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19383 \begin_inset Text
19384
19385 \begin_layout Standard
19386
19387 \size scriptsize
19388 printf_fast_f.c
19389 \end_layout
19390
19391 \end_inset
19392 </cell>
19393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19394 \begin_inset Text
19395
19396 \begin_layout Standard
19397
19398 \size scriptsize
19399 printf_tiny.c
19400 \end_layout
19401
19402 \end_inset
19403 </cell>
19404 </row>
19405 <row topline="true" endhead="true">
19406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19407 \begin_inset Text
19408
19409 \begin_layout Standard
19410 \begin_inset Quotes sld
19411 \end_inset
19412
19413 Hello World
19414 \begin_inset Quotes srd
19415 \end_inset
19416
19417  size
19418 \end_layout
19419
19420 \begin_layout Standard
19421 small / large
19422 \end_layout
19423
19424 \end_inset
19425 </cell>
19426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19427 \begin_inset Text
19428
19429 \begin_layout Standard
19430 1.7k / 2.4k
19431 \end_layout
19432
19433 \end_inset
19434 </cell>
19435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19436 \begin_inset Text
19437
19438 \begin_layout Standard
19439 4.3k / 5.6k
19440 \end_layout
19441
19442 \end_inset
19443 </cell>
19444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19445 \begin_inset Text
19446
19447 \begin_layout Standard
19448 1.2k / 1.8k
19449 \end_layout
19450
19451 \end_inset
19452 </cell>
19453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19454 \begin_inset Text
19455
19456 \begin_layout Standard
19457 1.3k / 1.3k
19458 \end_layout
19459
19460 \end_inset
19461 </cell>
19462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19463 \begin_inset Text
19464
19465 \begin_layout Standard
19466 1.9k / 1.9k
19467 \end_layout
19468
19469 \end_inset
19470 </cell>
19471 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19472 \begin_inset Text
19473
19474 \begin_layout Standard
19475 0.44k / 0.44k
19476 \end_layout
19477
19478 \end_inset
19479 </cell>
19480 </row>
19481 <row topline="true" endhead="true">
19482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19483 \begin_inset Text
19484
19485 \begin_layout Standard
19486 code size
19487 \end_layout
19488
19489 \begin_layout Standard
19490 small / large
19491 \end_layout
19492
19493 \end_inset
19494 </cell>
19495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19496 \begin_inset Text
19497
19498 \begin_layout Standard
19499 1.4k / 2.0k
19500 \end_layout
19501
19502 \end_inset
19503 </cell>
19504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19505 \begin_inset Text
19506
19507 \begin_layout Standard
19508 2.8k / 3.7k
19509 \end_layout
19510
19511 \end_inset
19512 </cell>
19513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19514 \begin_inset Text
19515
19516 \begin_layout Standard
19517 0.45k / 0.47k (+ _ltoa)
19518 \end_layout
19519
19520 \end_inset
19521 </cell>
19522 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19523 \begin_inset Text
19524
19525 \begin_layout Standard
19526 1.2k / 1.2k
19527 \end_layout
19528
19529 \end_inset
19530 </cell>
19531 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19532 \begin_inset Text
19533
19534 \begin_layout Standard
19535 1.6k / 1.6k
19536 \end_layout
19537
19538 \end_inset
19539 </cell>
19540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19541 \begin_inset Text
19542
19543 \begin_layout Standard
19544 0.26k / 0.26k
19545 \end_layout
19546
19547 \end_inset
19548 </cell>
19549 </row>
19550 <row topline="true">
19551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19552 \begin_inset Text
19553
19554 \begin_layout Standard
19555 formats
19556 \end_layout
19557
19558 \end_inset
19559 </cell>
19560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19561 \begin_inset Text
19562
19563 \begin_layout Standard
19564 cdi
19565 \emph on
19566 o
19567 \emph default
19568 psux
19569 \end_layout
19570
19571 \end_inset
19572 </cell>
19573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19574 \begin_inset Text
19575
19576 \begin_layout Standard
19577
19578 \family roman
19579 \series medium
19580 \shape up
19581 \size normal
19582 \emph off
19583 \bar no
19584 \noun off
19585 \color none
19586 cd
19587 \family default
19588 \series default
19589 \shape default
19590 \size default
19591 \emph default
19592 \bar default
19593 \noun default
19594 f
19595 \family roman
19596 \series medium
19597 \shape up
19598 \size normal
19599 \emph off
19600 \bar no
19601 \noun off
19602 i
19603 \family default
19604 \series default
19605 \shape default
19606 \size default
19607 \emph on
19608 \bar default
19609 \noun default
19610 o
19611 \family roman
19612 \series medium
19613 \shape up
19614 \size normal
19615 \emph off
19616 \bar no
19617 \noun off
19618 psux
19619 \end_layout
19620
19621 \end_inset
19622 </cell>
19623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19624 \begin_inset Text
19625
19626 \begin_layout Standard
19627 c
19628 \family roman
19629 \series medium
19630 \shape up
19631 \size normal
19632 \emph off
19633 \bar no
19634 \noun off
19635 \color none
19636 d
19637 \family default
19638 \series default
19639 \shape default
19640 \size default
19641 \emph on
19642 \bar default
19643 \noun default
19644 o
19645 \family roman
19646 \series medium
19647 \shape up
19648 \size normal
19649 \emph off
19650 \bar no
19651 \noun off
19652 s
19653 \family default
19654 \series default
19655 \shape default
19656 \size default
19657 \emph default
19658 \bar default
19659 \noun default
19660 x
19661 \end_layout
19662
19663 \end_inset
19664 </cell>
19665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19666 \begin_inset Text
19667
19668 \begin_layout Standard
19669 cdsux
19670 \end_layout
19671
19672 \end_inset
19673 </cell>
19674 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19675 \begin_inset Text
19676
19677 \begin_layout Standard
19678 cdfsux
19679 \end_layout
19680
19681 \end_inset
19682 </cell>
19683 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19684 \begin_inset Text
19685
19686 \begin_layout Standard
19687 cdsux
19688 \end_layout
19689
19690 \end_inset
19691 </cell>
19692 </row>
19693 <row topline="true">
19694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19695 \begin_inset Text
19696
19697 \begin_layout Standard
19698 long (32 bit) support
19699 \end_layout
19700
19701 \end_inset
19702 </cell>
19703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19704 \begin_inset Text
19705
19706 \begin_layout Standard
19707 x
19708 \end_layout
19709
19710 \end_inset
19711 </cell>
19712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19713 \begin_inset Text
19714
19715 \begin_layout Standard
19716 x
19717 \end_layout
19718
19719 \end_inset
19720 </cell>
19721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19722 \begin_inset Text
19723
19724 \begin_layout Standard
19725 x
19726 \end_layout
19727
19728 \end_inset
19729 </cell>
19730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19731 \begin_inset Text
19732
19733 \begin_layout Standard
19734 x
19735 \end_layout
19736
19737 \end_inset
19738 </cell>
19739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19740 \begin_inset Text
19741
19742 \begin_layout Standard
19743
19744 \family roman
19745 \series medium
19746 \shape up
19747 \size normal
19748 \emph off
19749 \bar no
19750 \noun off
19751 \color none
19752 x
19753 \end_layout
19754
19755 \end_inset
19756 </cell>
19757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19758 \begin_inset Text
19759
19760 \begin_layout Standard
19761 -
19762 \end_layout
19763
19764 \end_inset
19765 </cell>
19766 </row>
19767 <row topline="true">
19768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19769 \begin_inset Text
19770
19771 \begin_layout Standard
19772 byte arguments on stack
19773 \end_layout
19774
19775 \end_inset
19776 </cell>
19777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19778 \begin_inset Text
19779
19780 \begin_layout Standard
19781 b
19782 \end_layout
19783
19784 \end_inset
19785 </cell>
19786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19787 \begin_inset Text
19788
19789 \begin_layout Standard
19790 b
19791 \end_layout
19792
19793 \end_inset
19794 </cell>
19795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19796 \begin_inset Text
19797
19798 \begin_layout Standard
19799 -
19800 \end_layout
19801
19802 \end_inset
19803 </cell>
19804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19805 \begin_inset Text
19806
19807 \begin_layout Standard
19808 -
19809 \end_layout
19810
19811 \end_inset
19812 </cell>
19813 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19814 \begin_inset Text
19815
19816 \begin_layout Standard
19817 -
19818 \end_layout
19819
19820 \end_inset
19821 </cell>
19822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19823 \begin_inset Text
19824
19825 \begin_layout Standard
19826 -
19827 \end_layout
19828
19829 \end_inset
19830 </cell>
19831 </row>
19832 <row topline="true">
19833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19834 \begin_inset Text
19835
19836 \begin_layout Standard
19837 float format
19838 \begin_inset LatexCommand \index{Floating point support}
19839
19840 \end_inset
19841
19842
19843 \end_layout
19844
19845 \end_inset
19846 </cell>
19847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19848 \begin_inset Text
19849
19850 \begin_layout Standard
19851 -
19852 \end_layout
19853
19854 \end_inset
19855 </cell>
19856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19857 \begin_inset Text
19858
19859 \begin_layout Standard
19860 %f
19861 \end_layout
19862
19863 \end_inset
19864 </cell>
19865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19866 \begin_inset Text
19867
19868 \begin_layout Standard
19869 -
19870 \end_layout
19871
19872 \end_inset
19873 </cell>
19874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19875 \begin_inset Text
19876
19877 \begin_layout Standard
19878 -
19879 \end_layout
19880
19881 \end_inset
19882 </cell>
19883 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19884 \begin_inset Text
19885
19886 \begin_layout Standard
19887 %f
19888 \begin_inset Foot
19889 status collapsed
19890
19891 \begin_layout Standard
19892 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
19893 \end_layout
19894
19895 \end_inset
19896
19897
19898 \end_layout
19899
19900 \end_inset
19901 </cell>
19902 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19903 \begin_inset Text
19904
19905 \begin_layout Standard
19906 -
19907 \end_layout
19908
19909 \end_inset
19910 </cell>
19911 </row>
19912 <row topline="true">
19913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19914 \begin_inset Text
19915
19916 \begin_layout Standard
19917 float formats %e %g
19918 \end_layout
19919
19920 \end_inset
19921 </cell>
19922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19923 \begin_inset Text
19924
19925 \begin_layout Standard
19926 -
19927 \end_layout
19928
19929 \end_inset
19930 </cell>
19931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19932 \begin_inset Text
19933
19934 \begin_layout Standard
19935 -
19936 \end_layout
19937
19938 \end_inset
19939 </cell>
19940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19941 \begin_inset Text
19942
19943 \begin_layout Standard
19944 -
19945 \end_layout
19946
19947 \end_inset
19948 </cell>
19949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19950 \begin_inset Text
19951
19952 \begin_layout Standard
19953 -
19954 \end_layout
19955
19956 \end_inset
19957 </cell>
19958 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19959 \begin_inset Text
19960
19961 \begin_layout Standard
19962 -
19963 \end_layout
19964
19965 \end_inset
19966 </cell>
19967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19968 \begin_inset Text
19969
19970 \begin_layout Standard
19971 -
19972 \end_layout
19973
19974 \end_inset
19975 </cell>
19976 </row>
19977 <row topline="true" bottomline="true">
19978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19979 \begin_inset Text
19980
19981 \begin_layout Standard
19982 field width
19983 \end_layout
19984
19985 \end_inset
19986 </cell>
19987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19988 \begin_inset Text
19989
19990 \begin_layout Standard
19991 x
19992 \end_layout
19993
19994 \end_inset
19995 </cell>
19996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19997 \begin_inset Text
19998
19999 \begin_layout Standard
20000 x
20001 \end_layout
20002
20003 \end_inset
20004 </cell>
20005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20006 \begin_inset Text
20007
20008 \begin_layout Standard
20009 -
20010 \end_layout
20011
20012 \end_inset
20013 </cell>
20014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20015 \begin_inset Text
20016
20017 \begin_layout Standard
20018 x
20019 \end_layout
20020
20021 \end_inset
20022 </cell>
20023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20024 \begin_inset Text
20025
20026 \begin_layout Standard
20027 x
20028 \end_layout
20029
20030 \end_inset
20031 </cell>
20032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20033 \begin_inset Text
20034
20035 \begin_layout Standard
20036 -
20037 \end_layout
20038
20039 \end_inset
20040 </cell>
20041 </row>
20042 <row bottomline="true">
20043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20044 \begin_inset Text
20045
20046 \begin_layout Standard
20047 string speed
20048 \begin_inset Foot
20049 status collapsed
20050
20051 \begin_layout Standard
20052 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20053 \backslash
20054 r', '
20055 \backslash
20056 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20057 \end_layout
20058
20059 \end_inset
20060
20061 ,
20062 \end_layout
20063
20064 \begin_layout Standard
20065 small / large
20066 \end_layout
20067
20068 \end_inset
20069 </cell>
20070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20071 \begin_inset Text
20072
20073 \begin_layout Standard
20074 1.52 / 2.59 ms
20075 \end_layout
20076
20077 \end_inset
20078 </cell>
20079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20080 \begin_inset Text
20081
20082 \begin_layout Standard
20083 1.53 / 2.62 ms
20084 \end_layout
20085
20086 \end_inset
20087 </cell>
20088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20089 \begin_inset Text
20090
20091 \begin_layout Standard
20092 0.92 / 0.93 ms
20093 \end_layout
20094
20095 \end_inset
20096 </cell>
20097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20098 \begin_inset Text
20099
20100 \begin_layout Standard
20101 0.45 / 0.45 ms
20102 \end_layout
20103
20104 \end_inset
20105 </cell>
20106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20107 \begin_inset Text
20108
20109 \begin_layout Standard
20110 0.46 / 0.46 ms
20111 \end_layout
20112
20113 \end_inset
20114 </cell>
20115 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20116 \begin_inset Text
20117
20118 \begin_layout Standard
20119 0.45 / 0.45 ms
20120 \end_layout
20121
20122 \end_inset
20123 </cell>
20124 </row>
20125 <row bottomline="true">
20126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20127 \begin_inset Text
20128
20129 \begin_layout Standard
20130 int speed
20131 \begin_inset Foot
20132 status collapsed
20133
20134 \begin_layout Standard
20135 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20136  putchar()
20137 \end_layout
20138
20139 \end_inset
20140
20141 ,
20142 \end_layout
20143
20144 \begin_layout Standard
20145 small / large
20146 \end_layout
20147
20148 \end_inset
20149 </cell>
20150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20151 \begin_inset Text
20152
20153 \begin_layout Standard
20154 3.01 / 3.61 ms
20155 \end_layout
20156
20157 \end_inset
20158 </cell>
20159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20160 \begin_inset Text
20161
20162 \begin_layout Standard
20163 3.01 / 3.61 ms
20164 \end_layout
20165
20166 \end_inset
20167 </cell>
20168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20169 \begin_inset Text
20170
20171 \begin_layout Standard
20172 3.51 / 18.13 ms
20173 \end_layout
20174
20175 \end_inset
20176 </cell>
20177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20178 \begin_inset Text
20179
20180 \begin_layout Standard
20181 0.22 / 0.22 ms
20182 \end_layout
20183
20184 \end_inset
20185 </cell>
20186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20187 \begin_inset Text
20188
20189 \begin_layout Standard
20190 0.23 / 0.23 ms
20191 \end_layout
20192
20193 \end_inset
20194 </cell>
20195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20196 \begin_inset Text
20197
20198 \begin_layout Standard
20199 0.25 / 0.25 ms
20200 \begin_inset Foot
20201 status collapsed
20202
20203 \begin_layout Standard
20204 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20205 \end_layout
20206
20207 \end_inset
20208
20209
20210 \end_layout
20211
20212 \end_inset
20213 </cell>
20214 </row>
20215 <row bottomline="true">
20216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20217 \begin_inset Text
20218
20219 \begin_layout Standard
20220 long speed
20221 \begin_inset Foot
20222 status collapsed
20223
20224 \begin_layout Standard
20225 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20226  empty putchar()
20227 \end_layout
20228
20229 \end_inset
20230
20231 ,
20232 \end_layout
20233
20234 \begin_layout Standard
20235 small / large
20236 \end_layout
20237
20238 \end_inset
20239 </cell>
20240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20241 \begin_inset Text
20242
20243 \begin_layout Standard
20244 5.37 / 6.31 ms
20245 \end_layout
20246
20247 \end_inset
20248 </cell>
20249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20250 \begin_inset Text
20251
20252 \begin_layout Standard
20253 5.37 / 6.31 ms
20254 \end_layout
20255
20256 \end_inset
20257 </cell>
20258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20259 \begin_inset Text
20260
20261 \begin_layout Standard
20262 8.71 / 40.65 ms
20263 \end_layout
20264
20265 \end_inset
20266 </cell>
20267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20268 \begin_inset Text
20269
20270 \begin_layout Standard
20271 0.40 / 0.40 ms
20272 \end_layout
20273
20274 \end_inset
20275 </cell>
20276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20277 \begin_inset Text
20278
20279 \begin_layout Standard
20280 0.40 / 0.40 ms
20281 \end_layout
20282
20283 \end_inset
20284 </cell>
20285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20286 \begin_inset Text
20287
20288 \begin_layout Standard
20289 -
20290 \end_layout
20291
20292 \end_inset
20293 </cell>
20294 </row>
20295 <row bottomline="true">
20296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20297 \begin_inset Text
20298
20299 \begin_layout Standard
20300 float speed
20301 \begin_inset Foot
20302 status collapsed
20303
20304 \begin_layout Standard
20305 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
20306  empty putchar()
20307 \end_layout
20308
20309 \end_inset
20310
20311 ,
20312 \end_layout
20313
20314 \begin_layout Standard
20315 small / large
20316 \end_layout
20317
20318 \end_inset
20319 </cell>
20320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20321 \begin_inset Text
20322
20323 \begin_layout Standard
20324 -
20325 \end_layout
20326
20327 \end_inset
20328 </cell>
20329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20330 \begin_inset Text
20331
20332 \begin_layout Standard
20333 7.49 / 22.47 ms
20334 \end_layout
20335
20336 \end_inset
20337 </cell>
20338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20339 \begin_inset Text
20340
20341 \begin_layout Standard
20342 -
20343 \end_layout
20344
20345 \end_inset
20346 </cell>
20347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20348 \begin_inset Text
20349
20350 \begin_layout Standard
20351 -
20352 \end_layout
20353
20354 \end_inset
20355 </cell>
20356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20357 \begin_inset Text
20358
20359 \begin_layout Standard
20360 1.04 / 1.04 ms
20361 \end_layout
20362
20363 \end_inset
20364 </cell>
20365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20366 \begin_inset Text
20367
20368 \begin_layout Standard
20369 -
20370 \end_layout
20371
20372 \end_inset
20373 </cell>
20374 </row>
20375 </lyxtabular>
20376
20377 \end_inset
20378
20379
20380 \end_layout
20381
20382 \begin_layout Subsubsection
20383 <malloc.h>
20384 \begin_inset LatexCommand \index{malloc.h}
20385
20386 \end_inset
20387
20388
20389 \end_layout
20390
20391 \begin_layout Standard
20392 As of SDCC 2.6.2 you no longer need to call an initialization routine before
20393  using dynamic memory allocation
20394 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
20395
20396 \end_inset
20397
20398  and a default heap
20399 \begin_inset LatexCommand \index{heap (malloc)}
20400
20401 \end_inset
20402
20403  space of 1024 bytes is provided for malloc to allocate memory from.
20404  If you need a different heap size you need to recompile _heap.c with the
20405  required size defined in HEAP_SIZE.
20406  It is recommended to make a copy of this file into your project directory
20407  and compile it there with:
20408 \end_layout
20409
20410 \begin_layout Verse
20411
20412 \family typewriter
20413 sdcc -c _heap.c -D HEAD_SIZE=2048
20414 \end_layout
20415
20416 \begin_layout Standard
20417 And then link it with:
20418 \end_layout
20419
20420 \begin_layout Verse
20421
20422 \family typewriter
20423 sdcc main.rel _heap.rel
20424 \end_layout
20425
20426 \begin_layout Subsection
20427 Math functions (sinf, powf, sqrtf etc.)
20428 \end_layout
20429
20430 \begin_layout Subsubsection
20431 <math.h>
20432 \end_layout
20433
20434 \begin_layout Standard
20435 See definitions in file <math.h>.
20436 \end_layout
20437
20438 \begin_layout Subsection
20439 Other libraries
20440 \end_layout
20441
20442 \begin_layout Standard
20443 Libraries
20444 \begin_inset LatexCommand \index{Libraries}
20445
20446 \end_inset
20447
20448  included in SDCC should have a license at least as liberal as the GNU Lesser
20449  General Public License
20450 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
20451
20452 \end_inset
20453
20454  
20455 \emph on
20456 LGPL
20457 \emph default
20458 .
20459 \end_layout
20460
20461 \begin_layout Standard
20462 \begin_inset Note Note
20463 status collapsed
20464
20465 \begin_layout Standard
20466 license statements for the libraries are missing.
20467  sdcc/device/lib/ser_ir.c
20468 \end_layout
20469
20470 \begin_layout Standard
20471 or _decdptr f.e.
20472  come with a GPL (as opposed to LGPL) License - this will not be liberal
20473  enough for many embedded programmers.
20474 \end_layout
20475
20476 \end_inset
20477
20478
20479 \end_layout
20480
20481 \begin_layout Standard
20482 If you have ported some library or want to share experience about some code
20483  which f.e.
20484  falls into any of these categories Busses (I
20485 \begin_inset Formula $^{\textrm{2}}$
20486 \end_inset
20487
20488 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
20489  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
20490  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
20491 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
20492
20493 \end_inset
20494
20495 \InsetSpace ~
20496 would certainly like to hear about it.
20497 \end_layout
20498
20499 \begin_layout Standard
20500 Programmers coding for embedded systems are not especially famous for being
20501  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
20502 e these references are very valuable.
20503  Let's help to create a climate where information is shared.
20504 \begin_inset VSpace bigskip
20505 \end_inset
20506
20507
20508 \end_layout
20509
20510 \begin_layout Section
20511 Memory Models
20512 \end_layout
20513
20514 \begin_layout Subsection
20515 MCS51 Memory Models
20516 \begin_inset LatexCommand \index{Memory model}
20517
20518 \end_inset
20519
20520
20521 \begin_inset LatexCommand \index{MCS51 memory model}
20522
20523 \end_inset
20524
20525
20526 \end_layout
20527
20528 \begin_layout Subsubsection
20529 Small, Medium and Large
20530 \end_layout
20531
20532 \begin_layout Standard
20533 SDCC allows three memory models for MCS51 code, 
20534 \shape slanted
20535 small, medium
20536 \shape default
20537  and 
20538 \shape slanted
20539 large
20540 \shape default
20541 .
20542  Modules compiled with different memory models should 
20543 \emph on
20544 never
20545 \emph default
20546  be combined together or the results would be unpredictable.
20547  The library routines supplied with the compiler are compiled as small,
20548  medium and large.
20549  The compiled library modules are contained in separate directories as small,
20550  medium and large so that you can link to the appropriate set.
20551 \end_layout
20552
20553 \begin_layout Standard
20554 When the medium or large model is used all variables declared without a
20555  storage class will be allocated into the external ram, this includes all
20556  parameters and local variables (for non-reentrant
20557 \begin_inset LatexCommand \index{reentrant}
20558
20559 \end_inset
20560
20561  functions).
20562  When the small model is used variables without storage class are allocated
20563  in the internal ram.
20564 \end_layout
20565
20566 \begin_layout Standard
20567 Judicious usage of the processor specific storage classes
20568 \begin_inset LatexCommand \index{Storage class}
20569
20570 \end_inset
20571
20572  and the 'reentrant' function type will yield much more efficient code,
20573  than using the large model.
20574  Several optimizations are disabled when the program is compiled using the
20575  large model, it is therefore recommended that the small model be used unless
20576  absolutely required.
20577 \end_layout
20578
20579 \begin_layout Subsubsection
20580 External Stack
20581 \begin_inset LatexCommand \label{sub:External-Stack}
20582
20583 \end_inset
20584
20585
20586 \begin_inset LatexCommand \index{stack}
20587
20588 \end_inset
20589
20590
20591 \begin_inset LatexCommand \index{External stack (mcs51)}
20592
20593 \end_inset
20594
20595
20596 \end_layout
20597
20598 \begin_layout Standard
20599 The external stack (-
20600 \begin_inset ERT
20601 status collapsed
20602
20603 \begin_layout Standard
20604
20605
20606 \backslash
20607 /
20608 \end_layout
20609
20610 \end_inset
20611
20612 -xstack option
20613 \begin_inset LatexCommand \index{-\/-xstack}
20614
20615 \end_inset
20616
20617 ) is located in pdata
20618 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20619
20620 \end_inset
20621
20622  memory (usually at the start of the external ram segment) and uses all
20623  unused space in pdata (max.
20624  256 bytes).
20625  When -
20626 \begin_inset ERT
20627 status collapsed
20628
20629 \begin_layout Standard
20630
20631
20632 \backslash
20633 /
20634 \end_layout
20635
20636 \end_inset
20637
20638 -xstack option is used to compile the program, the parameters and local
20639  variables
20640 \begin_inset LatexCommand \index{local variables}
20641
20642 \end_inset
20643
20644  of all reentrant functions are allocated in this area.
20645  This option is provided for programs with large stack space requirements.
20646  When used with the -
20647 \begin_inset ERT
20648 status collapsed
20649
20650 \begin_layout Standard
20651
20652
20653 \backslash
20654 /
20655 \end_layout
20656
20657 \end_inset
20658
20659 -stack-auto
20660 \begin_inset LatexCommand \index{-\/-stack-auto}
20661
20662 \end_inset
20663
20664  option, all parameters and local variables are allocated on the external
20665  stack (note: support libraries will need to be recompiled with the same
20666  options.
20667  There is a predefined target in the library makefile).
20668 \end_layout
20669
20670 \begin_layout Standard
20671 The compiler outputs the higher order address byte of the external ram segment
20672  into port P2
20673 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
20674
20675 \end_inset
20676
20677  (see also section 
20678 \begin_inset LatexCommand \ref{sub:MCS51-variants}
20679
20680 \end_inset
20681
20682 ), therefore when using the External Stack option, this port 
20683 \emph on
20684 may not
20685 \emph default
20686  be used by the application program.
20687 \end_layout
20688
20689 \begin_layout Subsection
20690 DS390 Memory Model
20691 \begin_inset LatexCommand \index{Memory model}
20692
20693 \end_inset
20694
20695
20696 \begin_inset LatexCommand \index{DS390 memory model}
20697
20698 \end_inset
20699
20700
20701 \end_layout
20702
20703 \begin_layout Standard
20704 The only model supported is Flat 24
20705 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
20706
20707 \end_inset
20708
20709 .
20710  This generates code for the 24 bit contiguous addressing mode of the Dallas
20711  DS80C390 part.
20712  In this mode, up to four meg of external RAM or code space can be directly
20713  addressed.
20714  See the data sheets at www.dalsemi.com for further information on this part.
20715 \newline
20716
20717 \newline
20718 Note
20719  that the compiler does not generate any code to place the processor into
20720  24 bitmode (although 
20721 \emph on
20722 tinibios
20723 \emph default
20724  in the ds390 libraries will do that for you).
20725  If you don't use 
20726 \emph on
20727 tinibios
20728 \emph default
20729
20730 \begin_inset LatexCommand \index{Tinibios (DS390)}
20731
20732 \end_inset
20733
20734 , the boot loader or similar code must ensure that the processor is in 24
20735  bit contiguous addressing mode before calling the SDCC startup code.
20736 \newline
20737
20738 \newline
20739 Like
20740  the 
20741 \emph on
20742 -
20743 \begin_inset ERT
20744 status collapsed
20745
20746 \begin_layout Standard
20747
20748
20749 \backslash
20750 /
20751 \end_layout
20752
20753 \end_inset
20754
20755 -model-large
20756 \emph default
20757  option, variables will by default be placed into the XDATA segment.
20758  
20759 \newline
20760
20761 \newline
20762 Segments may be placed anywhere in the 4 meg address space using the usual
20763  -
20764 \begin_inset ERT
20765 status collapsed
20766
20767 \begin_layout Standard
20768
20769
20770 \backslash
20771 /
20772 \end_layout
20773
20774 \end_inset
20775
20776 -*-loc options.
20777  Note that if any segments are located above 64K, the -r flag must be passed
20778  to the linker to generate the proper segment relocations, and the Intel
20779  HEX output format must be used.
20780  The -r flag can be passed to the linker by using the option 
20781 \emph on
20782 -Wl-r
20783 \emph default
20784  on the SDCC command line.
20785  However, currently the linker can not handle code segments > 64k.
20786 \end_layout
20787
20788 \begin_layout Section
20789 Pragmas
20790 \begin_inset LatexCommand \label{sec:Pragmas}
20791
20792 \end_inset
20793
20794
20795 \begin_inset LatexCommand \index{Pragmas}
20796
20797 \end_inset
20798
20799
20800 \end_layout
20801
20802 \begin_layout Standard
20803 Pragmas are used to turn on and/or off certain compiler options.
20804  Some of them are closely related to corresponding command-line options
20805  (see section 
20806 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
20807
20808 \end_inset
20809
20810 ).
20811 \newline
20812 Pragmas should be placed before and/or after a function, placing pragmas
20813  inside a function body could have unpredictable results.
20814 \newline
20815
20816 \newline
20817 SDCC supports the
20818  following #pragma directives:
20819 \end_layout
20820
20821 \begin_layout Itemize
20822
20823 \series bold
20824 save
20825 \series default
20826
20827 \begin_inset LatexCommand \index{\#pragma save}
20828
20829 \end_inset
20830
20831  - this will save most current options to the save/restore stack.
20832  See #pragma\InsetSpace ~
20833 restore.
20834 \end_layout
20835
20836 \begin_layout Itemize
20837
20838 \series bold
20839 restore
20840 \series default
20841
20842 \begin_inset LatexCommand \index{\#pragma restore}
20843
20844 \end_inset
20845
20846  - will restore saved options from the last save.
20847  saves & restores can be nested.
20848  SDCC uses a save/restore stack: save pushes current options to the stack,
20849  restore pulls current options from the stack.
20850  See #pragma\InsetSpace ~
20851 save.
20852 \newline
20853
20854 \end_layout
20855
20856 \begin_layout Itemize
20857
20858 \series bold
20859 callee_saves
20860 \series default
20861
20862 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20863
20864 \end_inset
20865
20866
20867 \begin_inset LatexCommand \index{function prologue}
20868
20869 \end_inset
20870
20871  function1[,function2[,function3...]] 
20872 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
20873
20874 \end_inset
20875
20876 - The compiler by default uses a caller saves convention for register saving
20877  across function calls, however this can cause unnecessary register pushing
20878  and popping
20879 \begin_inset LatexCommand \index{push/pop}
20880
20881 \end_inset
20882
20883  when calling small functions from larger functions.
20884  This option can be used to switch off the register saving convention for
20885  the function names specified.
20886  The compiler will not save registers when calling these functions, extra
20887  code need to be manually inserted at the entry and exit for these functions
20888  to save and restore the registers used by these functions, this can SUBSTANTIAL
20889 LY reduce code and improve run time performance of the generated code.
20890  In the future the compiler (with inter procedural analysis) may be able
20891  to determine the appropriate scheme to use for each function call.
20892  If -
20893 \begin_inset ERT
20894 status collapsed
20895
20896 \begin_layout Standard
20897
20898
20899 \backslash
20900 /
20901 \end_layout
20902
20903 \end_inset
20904
20905 -callee-saves command line option is used (see page 
20906 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
20907
20908 \end_inset
20909
20910 ), the function names specified in #pragma\InsetSpace ~
20911 callee_saves
20912 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20913
20914 \end_inset
20915
20916  is appended to the list of functions specified in the command line.
20917 \end_layout
20918
20919 \begin_layout Itemize
20920
20921 \series bold
20922 exclude
20923 \series default
20924
20925 \begin_inset LatexCommand \index{\#pragma exclude}
20926
20927 \end_inset
20928
20929  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
20930  of pairs of push/pop
20931 \begin_inset LatexCommand \index{push/pop}
20932
20933 \end_inset
20934
20935  instructions in 
20936 \emph on
20937 I
20938 \emph default
20939 nterrupt
20940 \begin_inset LatexCommand \index{interrupt}
20941
20942 \end_inset
20943
20944  
20945 \emph on
20946 S
20947 \emph default
20948 ervice 
20949 \emph on
20950 R
20951 \emph default
20952 outines.
20953  The directive should be placed immediately before the ISR function definition
20954  and it affects ALL ISR functions following it.
20955  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
20956 exclude\InsetSpace ~
20957 none
20958 \begin_inset LatexCommand \index{\#pragma exclude}
20959
20960 \end_inset
20961
20962 .
20963  See also the related keyword _naked
20964 \begin_inset LatexCommand \index{\_naked}
20965
20966 \end_inset
20967
20968
20969 \begin_inset LatexCommand \index{\_\_naked}
20970
20971 \end_inset
20972
20973 .
20974 \end_layout
20975
20976 \begin_layout Itemize
20977
20978 \series bold
20979 less_pedantic
20980 \series default
20981
20982 \begin_inset LatexCommand \index{pedantic}
20983
20984 \end_inset
20985
20986
20987 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
20988
20989 \end_inset
20990
20991  
20992 \begin_inset LatexCommand \label{ite:less_pedantic}
20993
20994 \end_inset
20995
20996 - the compiler will not warn you anymore for obvious mistakes, you'r on
20997  your own now ;-( .
20998  See also the command line option -
20999 \begin_inset ERT
21000 status collapsed
21001
21002 \begin_layout Standard
21003
21004
21005 \backslash
21006 /
21007 \end_layout
21008
21009 \end_inset
21010
21011 -less-pedantic 
21012 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21013
21014 \end_inset
21015
21016 .
21017  
21018 \newline
21019 More specifically, the following warnings will be disabled: 
21020 \shape italic
21021 comparison is always [true/false] due to limited range of data type
21022 \shape default
21023  (94); 
21024 \shape italic
21025 overflow in implicit constant conversion
21026 \shape default
21027  (158); [the (in)famous] 
21028 \shape italic
21029 conditional flow changed by optimizer: so said EVELYN the modified DOG
21030 \shape default
21031  (110); 
21032 \shape italic
21033 function '[function name]' must return value
21034 \shape default
21035  (59).
21036  
21037 \newline
21038 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21039  level) are disabled, too, namely: 
21040 \shape italic
21041 constant value '[
21042 \begin_inset Note Note
21043 status collapsed
21044
21045 \begin_layout Standard
21046 dunno what comes here - this warning appears to be unused altogether
21047 \end_layout
21048
21049 \end_inset
21050
21051 ]', out of range
21052 \shape default
21053  (81); 
21054 \shape italic
21055 [left/right] shifting more than size of object changed to zero
21056 \shape default
21057  (116); 
21058 \shape italic
21059 unreachable code
21060 \shape default
21061  (126); 
21062 \shape italic
21063 integer overflow in expression
21064 \shape default
21065  (165); 
21066 \shape italic
21067 unmatched #pragma save and #pragma restore
21068 \shape default
21069  (170); 
21070 \shape italic
21071 comparison of 'signed char' with 'unsigned char' requires promotion to int
21072 \shape default
21073  (185); 
21074 \shape italic
21075 ISO C90 does not support flexible array members
21076 \shape default
21077  (187); 
21078 \shape italic
21079 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21080 nam
21081 e]':\InsetSpace ~
21082 [
21083 \begin_inset Note Note
21084 status collapsed
21085
21086 \begin_layout Standard
21087 appears to be always blank - what was supposed to be here?
21088 \end_layout
21089
21090 \end_inset
21091
21092 ]
21093 \shape default
21094  (114); 
21095 \shape italic
21096 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21097  complexity [number]
21098 \shape default
21099  (121).
21100 \end_layout
21101
21102 \begin_layout Itemize
21103
21104 \series bold
21105 disable_warning
21106 \series default
21107  <nnnn>
21108 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21109
21110 \end_inset
21111
21112  - the compiler will not warn you anymore about warning number <nnnn>.
21113 \end_layout
21114
21115 \begin_layout Itemize
21116
21117 \series bold
21118 nogcse
21119 \series default
21120
21121 \begin_inset LatexCommand \index{\#pragma nogcse}
21122
21123 \end_inset
21124
21125  - will stop global common subexpression elimination.
21126 \end_layout
21127
21128 \begin_layout Itemize
21129
21130 \series bold
21131 noinduction
21132 \series default
21133
21134 \begin_inset LatexCommand \index{\#pragma noinduction}
21135
21136 \end_inset
21137
21138  - will stop loop induction optimizations.
21139 \end_layout
21140
21141 \begin_layout Itemize
21142
21143 \series bold
21144 noinvariant
21145 \series default
21146
21147 \begin_inset LatexCommand \index{\#pragma noinvariant}
21148
21149 \end_inset
21150
21151  - will not do loop invariant optimizations.
21152  For more details see Loop Invariants in section
21153 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21154
21155 \end_inset
21156
21157 .
21158 \end_layout
21159
21160 \begin_layout Itemize
21161
21162 \series bold
21163 noiv
21164 \series default
21165
21166 \begin_inset LatexCommand \index{\#pragma noiv}
21167
21168 \end_inset
21169
21170  - Do not generate interrupt
21171 \begin_inset LatexCommand \index{interrupt}
21172
21173 \end_inset
21174
21175  vector table
21176 \begin_inset LatexCommand \index{interrupt vector table}
21177
21178 \end_inset
21179
21180  entries for all ISR functions defined after the pragma.
21181  This is useful in cases where the interrupt vector table must be defined
21182  manually, or when there is a secondary, manually defined interrupt vector
21183  table (e.g.
21184  for the autovector feature of the Cypress EZ-USB FX2).
21185  More elegantly this can be achieved by obmitting the optional interrupt
21186  number after the interrupt keyword, see section 
21187 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21188
21189 \end_inset
21190
21191 \InsetSpace ~
21192 about interrupts.
21193 \end_layout
21194
21195 \begin_layout Itemize
21196
21197 \series bold
21198 nojtbound
21199 \series default
21200
21201 \begin_inset LatexCommand \index{\#pragma nojtbound}
21202
21203 \end_inset
21204
21205  - will not generate code for boundary value checking, when switch statements
21206  are turned into jump-tables (dangerous).
21207  For more details see section 
21208 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21209
21210 \end_inset
21211
21212 .
21213 \end_layout
21214
21215 \begin_layout Itemize
21216
21217 \series bold
21218 noloopreverse
21219 \series default
21220
21221 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21222
21223 \end_inset
21224
21225  - Will not do loop reversal optimization
21226 \end_layout
21227
21228 \begin_layout Itemize
21229
21230 \series bold
21231 nooverlay
21232 \series default
21233
21234 \begin_inset LatexCommand \index{\#pragma nooverlay}
21235
21236 \end_inset
21237
21238  - the compiler will not overlay the parameters and local variables of a
21239  function.
21240 \end_layout
21241
21242 \begin_layout Itemize
21243
21244 \series bold
21245 stackauto
21246 \series default
21247
21248 \begin_inset LatexCommand \index{\#pragma stackauto}
21249
21250 \end_inset
21251
21252 - See option -
21253 \begin_inset ERT
21254 status collapsed
21255
21256 \begin_layout Standard
21257
21258
21259 \backslash
21260 /
21261 \end_layout
21262
21263 \end_inset
21264
21265 -stack-auto
21266 \begin_inset LatexCommand \index{-\/-stack-auto}
21267
21268 \end_inset
21269
21270  and section 
21271 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
21272
21273 \end_inset
21274
21275  Parameters and Local Variables.
21276 \end_layout
21277
21278 \begin_layout Itemize
21279
21280 \series bold
21281 opt_code_speed
21282 \series default
21283  
21284 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
21285
21286 \end_inset
21287
21288 - The compiler will optimize code generation towards fast code, possibly
21289  at the expense of code size.
21290  Currently this has little effect.
21291 \end_layout
21292
21293 \begin_layout Itemize
21294
21295 \series bold
21296 opt_code_size
21297 \series default
21298  
21299 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
21300
21301 \end_inset
21302
21303 - The compiler will optimize code generation towards compact code, possibly
21304  at the expense of code speed.
21305  Currently this has little effect.
21306 \end_layout
21307
21308 \begin_layout Itemize
21309
21310 \series bold
21311 opt_code_balanced
21312 \series default
21313  
21314 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
21315
21316 \end_inset
21317
21318 - The compiler will attempt to generate code that is both compact and fast,
21319  as long as meeting one goal is not a detriment to the other (this is the
21320  default).
21321  
21322 \end_layout
21323
21324 \begin_layout Itemize
21325
21326 \series bold
21327 std_sdcc89
21328 \series default
21329  
21330 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
21331
21332 \end_inset
21333
21334 - Generally follow the C89 standard, but allow SDCC features that conflict
21335  with the standard (default).
21336 \end_layout
21337
21338 \begin_layout Itemize
21339
21340 \series bold
21341 std_c89
21342 \series default
21343  
21344 \begin_inset LatexCommand \index{\#pragma std\_c89}
21345
21346 \end_inset
21347
21348 - Follow the C89 standard and disable SDCC features that conflict with the
21349  standard.
21350 \end_layout
21351
21352 \begin_layout Itemize
21353
21354 \series bold
21355 std_sdcc99
21356 \series default
21357  
21358 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
21359
21360 \end_inset
21361
21362 - Generally follow the C99 standard, but allow SDCC features that conflict
21363  with the standard (incomplete support).
21364 \end_layout
21365
21366 \begin_layout Itemize
21367
21368 \series bold
21369 std_c99
21370 \series default
21371  
21372 \begin_inset LatexCommand \index{\#pragma std\_c99}
21373
21374 \end_inset
21375
21376 - Follow the C99 standard and disable SDCC features that conflict with the
21377  standard (incomplete support).
21378 \end_layout
21379
21380 \begin_layout Itemize
21381
21382 \series bold
21383 codeseg
21384 \series default
21385  <name>
21386 \begin_inset LatexCommand \index{\#pragma codeseg}
21387
21388 \end_inset
21389
21390 - Use this name (max.
21391  8 characters) for the code segment.
21392  See option -
21393 \begin_inset ERT
21394 status collapsed
21395
21396 \begin_layout Standard
21397
21398
21399 \backslash
21400 /
21401 \end_layout
21402
21403 \end_inset
21404
21405 -codeseg.
21406 \end_layout
21407
21408 \begin_layout Itemize
21409
21410 \series bold
21411 constseg
21412 \series default
21413  <name>
21414 \begin_inset LatexCommand \index{\#pragma constseg}
21415
21416 \end_inset
21417
21418 - Use this name (max.
21419  8 characters) for the const segment.
21420  See option -
21421 \begin_inset ERT
21422 status collapsed
21423
21424 \begin_layout Standard
21425
21426
21427 \backslash
21428 /
21429 \end_layout
21430
21431 \end_inset
21432
21433 -constseg.
21434 \end_layout
21435
21436 \begin_layout Standard
21437 The preprocessor SDCPP
21438 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
21439
21440 \end_inset
21441
21442  supports the following #pragma directives:
21443 \end_layout
21444
21445 \begin_layout Itemize
21446
21447 \series bold
21448 pedantic_parse_number
21449 \series default
21450
21451 \begin_inset LatexCommand \index{pedantic}
21452
21453 \end_inset
21454
21455
21456 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21457
21458 \end_inset
21459
21460  (+ | -) 
21461 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
21462
21463 \end_inset
21464
21465 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
21466  properly and the macro LO_B(3) gets expanded.
21467  Default is off.
21468  See also the -
21469 \begin_inset ERT
21470 status collapsed
21471
21472 \begin_layout Standard
21473
21474
21475 \backslash
21476 /
21477 \end_layout
21478
21479 \end_inset
21480
21481 -pedantic-parse-number command line option 
21482 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
21483
21484 \end_inset
21485
21486 .
21487  
21488 \newline
21489 Below is an example on how to use this pragma.
21490
21491 \emph on
21492  Note: this functionality is not in conformance with standard!
21493 \end_layout
21494
21495 \begin_layout Verse
21496
21497 \family typewriter
21498 #pragma pedantic_parse_number +
21499 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21500
21501 \end_inset
21502
21503
21504 \newline
21505
21506 \newline
21507 #define LO_B(x) ((x) & 0xff)
21508 \newline
21509
21510 \newline
21511 unsigned char foo(void)
21512 \newline
21513 {
21514 \newline
21515 \InsetSpace ~
21516 \InsetSpace ~
21517 \InsetSpace ~
21518 unsigned char c=0xfe-LO_B(3)
21519 ;
21520 \newline
21521
21522 \newline
21523 \InsetSpace ~
21524 \InsetSpace ~
21525 \InsetSpace ~
21526 return c;
21527 \newline
21528 }
21529 \newline
21530
21531 \end_layout
21532
21533 \begin_layout Itemize
21534
21535 \series bold
21536 preproc_asm
21537 \series default
21538
21539 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21540
21541 \end_inset
21542
21543  (+ | -) - switch _asm _endasm block preprocessing on / off.
21544  Default is on.
21545  You use this prama to define multilines of assembly code.
21546  This will prevent the preprocessor from changing the formating required
21547  by assembly code.
21548  Below is an example on how to use this pragma.
21549 \end_layout
21550
21551 \begin_layout Verse
21552
21553 \family typewriter
21554 #pragma preproc_asm -
21555 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21556
21557 \end_inset
21558
21559
21560 \newline
21561 #define MYDELAY _asm
21562 \newline
21563 \InsetSpace ~
21564 \InsetSpace ~
21565 \InsetSpace ~
21566 nop ;my assembly comment...
21567 \newline
21568 \InsetSpace ~
21569 \InsetSpace ~
21570 \InsetSpace ~
21571 nop
21572 \newline
21573 \InsetSpace ~
21574 \InsetSpace ~
21575 \InsetSpace ~
21576 nop
21577 \newline
21578 _endasm
21579 \newline
21580 #pragma preproc_asm
21581  +
21582 \newline
21583
21584 \newline
21585 void foo (void) 
21586 \newline
21587
21588 \newline
21589 \InsetSpace ~
21590 \InsetSpace ~
21591 \InsetSpace ~
21592  ...
21593  
21594 \newline
21595 \InsetSpace ~
21596 \InsetSpace ~
21597 \InsetSpace ~
21598  MYDELAY;
21599 \newline
21600 \InsetSpace ~
21601 \InsetSpace ~
21602 \InsetSpace ~
21603  ...
21604  
21605 \newline
21606
21607 \newline
21608
21609 \end_layout
21610
21611 \begin_layout Itemize
21612
21613 \series bold
21614 sdcc_hash
21615 \series default
21616
21617 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21618
21619 \end_inset
21620
21621  (+ | -) - Allow "naked" hash in macro definition, for example:
21622 \newline
21623
21624 \family typewriter
21625 #define DIR_LO(x) #(x & 0xff)
21626 \family default
21627
21628 \newline
21629 Default is off.
21630  Below is an example on how to use this pragma.
21631 \end_layout
21632
21633 \begin_layout Verse
21634
21635 \family typewriter
21636 #pragma preproc_asm +
21637 \newline
21638 #pragma sdcc_hash +
21639 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21640
21641 \end_inset
21642
21643
21644 \newline
21645
21646 \newline
21647 #define ROMCALL(x) 
21648 \backslash
21649
21650 \newline
21651 \InsetSpace ~
21652 \InsetSpace ~
21653 \InsetSpace ~
21654 mov R6_B3, #(x & 0xff) 
21655 \backslash
21656
21657 \newline
21658 \InsetSpace ~
21659 \InsetSpace ~
21660 \InsetSpace ~
21661 mov R7_B3, #((x >> 8) & 0xff) 
21662 \backslash
21663
21664 \newline
21665 \InsetSpace ~
21666 \InsetSpace ~
21667 \InsetSpace ~
21668 lcall __romcall
21669 \newline
21670
21671 \newline
21672 ...
21673 \newline
21674 _asm
21675 \newline
21676 ROMCALL(72)
21677 \newline
21678 _endasm;
21679 \newline
21680 ...
21681 \newline
21682
21683 \end_layout
21684
21685 \begin_layout Standard
21686 Some of the pragmas are intended to be used to turn-on or off certain optimizati
21687 ons which might cause the compiler to generate extra stack and/or data space
21688  to store compiler generated temporary variables.
21689  This usually happens in large functions.
21690  Pragma directives should be used as shown in the following example, they
21691  are used to control options and optimizations for a given function.
21692  
21693 \end_layout
21694
21695 \begin_layout Verse
21696
21697 \family typewriter
21698 #pragma save
21699 \begin_inset LatexCommand \index{\#pragma save}
21700
21701 \end_inset
21702
21703  \InsetSpace ~
21704 \InsetSpace ~
21705 \InsetSpace ~
21706 \InsetSpace ~
21707 \InsetSpace ~
21708 \InsetSpace ~
21709 \InsetSpace ~
21710 /* save the current settings */ 
21711 \newline
21712 #pragma nogcse
21713 \begin_inset LatexCommand \index{\#pragma nogcse}
21714
21715 \end_inset
21716
21717  \InsetSpace ~
21718 \InsetSpace ~
21719 \InsetSpace ~
21720 \InsetSpace ~
21721 \InsetSpace ~
21722 /* turnoff global subexpression elimination */ 
21723 \newline
21724 #pragma noinduction
21725 \begin_inset LatexCommand \index{\#pragma noinduction}
21726
21727 \end_inset
21728
21729  /* turn off induction optimizations */ 
21730 \newline
21731 int foo () 
21732 \newline
21733
21734 \newline
21735 \InsetSpace ~
21736  \InsetSpace ~
21737  ...
21738  
21739 \newline
21740 \InsetSpace ~
21741  \InsetSpace ~
21742  /* large code */ 
21743 \newline
21744 \InsetSpace ~
21745  \InsetSpace ~
21746  ...
21747  
21748 \newline
21749
21750 \newline
21751 #pragma restore
21752 \begin_inset LatexCommand \index{\#pragma restore}
21753
21754 \end_inset
21755
21756  /* turn the optimizations back on */
21757 \end_layout
21758
21759 \begin_layout Standard
21760 The compiler will generate a warning message when extra space is allocated.
21761  It is strongly recommended that the save and restore pragma's be used when
21762  changing options for a function.
21763 \newline
21764
21765 \newline
21766
21767 \newline
21768
21769 \end_layout
21770
21771 \begin_layout Section
21772 Defines Created by the Compiler
21773 \end_layout
21774
21775 \begin_layout Standard
21776 The compiler creates the following #defines
21777 \begin_inset LatexCommand \index{\#defines}
21778
21779 \end_inset
21780
21781
21782 \begin_inset LatexCommand \index{Defines created by the compiler}
21783
21784 \end_inset
21785
21786 :
21787 \newline
21788
21789 \end_layout
21790
21791 \begin_layout Standard
21792 \begin_inset Tabular
21793 <lyxtabular version="3" rows="11" columns="2">
21794 <features>
21795 <column alignment="left" valignment="top" leftline="true" width="3in">
21796 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
21797 <row topline="true" bottomline="true">
21798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21799 \begin_inset Text
21800
21801 \begin_layout Standard
21802
21803 \series bold
21804 #define
21805 \end_layout
21806
21807 \end_inset
21808 </cell>
21809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21810 \begin_inset Text
21811
21812 \begin_layout Standard
21813
21814 \series bold
21815 Description
21816 \end_layout
21817
21818 \end_inset
21819 </cell>
21820 </row>
21821 <row topline="true">
21822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21823 \begin_inset Text
21824
21825 \begin_layout Standard
21826 SDCC
21827 \begin_inset LatexCommand \index{SDCC}
21828
21829 \end_inset
21830
21831  
21832 \end_layout
21833
21834 \end_inset
21835 </cell>
21836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21837 \begin_inset Text
21838
21839 \begin_layout Standard
21840 Always defined.
21841  Since version 2.5.6 the version number as an int (ex.
21842  256)
21843 \end_layout
21844
21845 \end_inset
21846 </cell>
21847 </row>
21848 <row topline="true">
21849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21850 \begin_inset Text
21851
21852 \begin_layout Standard
21853 SDCC_mcs51
21854 \begin_inset LatexCommand \index{SDCC\_mcs51}
21855
21856 \end_inset
21857
21858  or SDCC_ds390
21859 \begin_inset LatexCommand \index{SDCC\_ds390}
21860
21861 \end_inset
21862
21863  or SDCC_z80
21864 \begin_inset LatexCommand \index{SDCC\_z80}
21865
21866 \end_inset
21867
21868 , etc.
21869 \end_layout
21870
21871 \end_inset
21872 </cell>
21873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21874 \begin_inset Text
21875
21876 \begin_layout Standard
21877 depending on the model used (e.g.: -mds390)
21878 \end_layout
21879
21880 \end_inset
21881 </cell>
21882 </row>
21883 <row topline="true">
21884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21885 \begin_inset Text
21886
21887 \begin_layout Standard
21888 __mcs51
21889 \begin_inset LatexCommand \index{\_\_mcs51}
21890
21891 \end_inset
21892
21893 , __ds390
21894 \begin_inset LatexCommand \index{\_\_ds390}
21895
21896 \end_inset
21897
21898 , __hc08
21899 \begin_inset LatexCommand \index{\_\_hc08}
21900
21901 \end_inset
21902
21903 , __z80
21904 \begin_inset LatexCommand \index{\_\_z80}
21905
21906 \end_inset
21907
21908 , etc
21909 \end_layout
21910
21911 \end_inset
21912 </cell>
21913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21914 \begin_inset Text
21915
21916 \begin_layout Standard
21917 depending on the model used (e.g.
21918  -mz80)
21919 \end_layout
21920
21921 \end_inset
21922 </cell>
21923 </row>
21924 <row topline="true">
21925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21926 \begin_inset Text
21927
21928 \begin_layout Standard
21929 SDCC_STACK_AUTO
21930 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
21931
21932 \end_inset
21933
21934
21935 \end_layout
21936
21937 \end_inset
21938 </cell>
21939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21940 \begin_inset Text
21941
21942 \begin_layout Standard
21943 when 
21944 \emph on
21945 -
21946 \begin_inset ERT
21947 status collapsed
21948
21949 \begin_layout Standard
21950
21951
21952 \backslash
21953 /
21954 \end_layout
21955
21956 \end_inset
21957
21958 -stack-auto
21959 \emph default
21960  option is used
21961 \end_layout
21962
21963 \end_inset
21964 </cell>
21965 </row>
21966 <row topline="true">
21967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21968 \begin_inset Text
21969
21970 \begin_layout Standard
21971 SDCC_MODEL_SMALL
21972 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
21973
21974 \end_inset
21975
21976
21977 \end_layout
21978
21979 \end_inset
21980 </cell>
21981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21982 \begin_inset Text
21983
21984 \begin_layout Standard
21985 when 
21986 \emph on
21987 -
21988 \begin_inset ERT
21989 status collapsed
21990
21991 \begin_layout Standard
21992
21993
21994 \backslash
21995 /
21996 \end_layout
21997
21998 \end_inset
21999
22000 -model-small
22001 \emph default
22002  is used
22003 \end_layout
22004
22005 \end_inset
22006 </cell>
22007 </row>
22008 <row topline="true">
22009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22010 \begin_inset Text
22011
22012 \begin_layout Standard
22013 SDCC_MODEL_MEDIUM
22014 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22015
22016 \end_inset
22017
22018
22019 \end_layout
22020
22021 \end_inset
22022 </cell>
22023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22024 \begin_inset Text
22025
22026 \begin_layout Standard
22027 when 
22028 \emph on
22029 -
22030 \begin_inset ERT
22031 status collapsed
22032
22033 \begin_layout Standard
22034
22035
22036 \backslash
22037 /
22038 \end_layout
22039
22040 \end_inset
22041
22042 -model-medium
22043 \emph default
22044  is used
22045 \end_layout
22046
22047 \end_inset
22048 </cell>
22049 </row>
22050 <row topline="true">
22051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22052 \begin_inset Text
22053
22054 \begin_layout Standard
22055 SDCC_MODEL_LARGE
22056 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22057
22058 \end_inset
22059
22060
22061 \end_layout
22062
22063 \end_inset
22064 </cell>
22065 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22066 \begin_inset Text
22067
22068 \begin_layout Standard
22069 when 
22070 \emph on
22071 -
22072 \begin_inset ERT
22073 status collapsed
22074
22075 \begin_layout Standard
22076
22077
22078 \backslash
22079 /
22080 \end_layout
22081
22082 \end_inset
22083
22084 -model-large
22085 \emph default
22086  is used
22087 \end_layout
22088
22089 \end_inset
22090 </cell>
22091 </row>
22092 <row topline="true">
22093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22094 \begin_inset Text
22095
22096 \begin_layout Standard
22097 SDCC_USE_XSTACK
22098 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22099
22100 \end_inset
22101
22102
22103 \end_layout
22104
22105 \end_inset
22106 </cell>
22107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22108 \begin_inset Text
22109
22110 \begin_layout Standard
22111 when 
22112 \emph on
22113 -
22114 \begin_inset ERT
22115 status collapsed
22116
22117 \begin_layout Standard
22118
22119
22120 \backslash
22121 /
22122 \end_layout
22123
22124 \end_inset
22125
22126 -xstack
22127 \emph default
22128  option is used
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_STACK_TENBIT
22140 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
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 when 
22154 \emph on
22155 -mds390
22156 \emph default
22157  is used
22158 \end_layout
22159
22160 \end_inset
22161 </cell>
22162 </row>
22163 <row topline="true" bottomline="true">
22164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22165 \begin_inset Text
22166
22167 \begin_layout Standard
22168 SDCC_MODEL_FLAT24
22169 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22170
22171 \end_inset
22172
22173
22174 \end_layout
22175
22176 \end_inset
22177 </cell>
22178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22179 \begin_inset Text
22180
22181 \begin_layout Standard
22182 when 
22183 \emph on
22184 -mds390
22185 \emph default
22186  is used
22187 \end_layout
22188
22189 \end_inset
22190 </cell>
22191 </row>
22192 </lyxtabular>
22193
22194 \end_inset
22195
22196
22197 \end_layout
22198
22199 \begin_layout Chapter
22200 Notes on supported Processors
22201 \end_layout
22202
22203 \begin_layout Section
22204 MCS51 variants
22205 \begin_inset LatexCommand \label{sub:MCS51-variants}
22206
22207 \end_inset
22208
22209
22210 \begin_inset LatexCommand \index{MCS51 variants}
22211
22212 \end_inset
22213
22214
22215 \end_layout
22216
22217 \begin_layout Standard
22218 MCS51 processors are available from many vendors and come in many different
22219  flavours.
22220  While they might differ considerably in respect to Special Function Registers
22221  the core MCS51 is usually not modified or is kept compatible.
22222  
22223 \end_layout
22224
22225 \begin_layout Subsection
22226 pdata access by SFR 
22227 \end_layout
22228
22229 \begin_layout Standard
22230 With the upcome of devices with internal xdata and flash memory devices
22231  using port P2
22232 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22233
22234 \end_inset
22235
22236  as dedicated I/O port is becoming more popular.
22237  Switching the high byte for pdata
22238 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22239
22240 \end_inset
22241
22242  access which was formerly done by port P2 is then achieved by a Special
22243  Function Register
22244 \begin_inset LatexCommand \index{sfr}
22245
22246 \end_inset
22247
22248 .
22249  In well-established MCS51 tradition the address of this 
22250 \emph on
22251 sfr
22252 \emph default
22253  is where the chip designers decided to put it.
22254  Needless to say that they didn't agree on a common name either.
22255  So that the startup code can correctly initialize xdata variables, you
22256  should define an sfr with the name _XPAGE
22257 \family typewriter
22258
22259 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
22260
22261 \end_inset
22262
22263
22264 \family default
22265  at the appropriate location if the default, port P2, is not used for this.
22266  Some examples are:
22267 \end_layout
22268
22269 \begin_layout Verse
22270
22271 \family typewriter
22272 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
22273  MPAGE */
22274 \end_layout
22275
22276 \begin_layout Verse
22277
22278 \family typewriter
22279 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
22280  a.k.a.
22281  MPAGE */
22282 \end_layout
22283
22284 \begin_layout Verse
22285
22286 \family typewriter
22287 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
22288  XPAGE */
22289 \end_layout
22290
22291 \begin_layout Verse
22292
22293 \family typewriter
22294 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22295  EMI0CN */
22296 \end_layout
22297
22298 \begin_layout Verse
22299
22300 \family typewriter
22301 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22302  EMI0CN */
22303 \end_layout
22304
22305 \begin_layout Standard
22306 For more exotic implementations further customizations may be needed.
22307  See section 
22308 \begin_inset LatexCommand \ref{sub:Startup-Code}
22309
22310 \end_inset
22311
22312  for other possibilities.
22313 \end_layout
22314
22315 \begin_layout Subsection
22316 Other Features available by SFR
22317 \end_layout
22318
22319 \begin_layout Standard
22320 Some MCS51 variants offer features like Double DPTR
22321 \begin_inset LatexCommand \index{DPTR}
22322
22323 \end_inset
22324
22325 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
22326  These are currently not used for the MCS51 port.
22327  If you absolutely need them you can fall back to inline assembly or submit
22328  a patch to SDCC.
22329 \begin_inset VSpace bigskip
22330 \end_inset
22331
22332
22333 \end_layout
22334
22335 \begin_layout Section
22336 DS400 port
22337 \end_layout
22338
22339 \begin_layout Standard
22340 The DS80C400
22341 \begin_inset LatexCommand \index{DS80C400}
22342
22343 \end_inset
22344
22345
22346 \begin_inset LatexCommand \index{DS400}
22347
22348 \end_inset
22349
22350  microcontroller has a rich set of peripherals.
22351  In its built-in ROM library it includes functions to access some of the
22352  features, among them is a TCP stack with IP4 and IP6 support.
22353  Library headers (currently in beta status) and other files are provided
22354  at 
22355 \size footnotesize
22356
22357 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
22358
22359 \end_inset
22360
22361 .
22362  
22363 \begin_inset VSpace bigskip
22364 \end_inset
22365
22366
22367 \end_layout
22368
22369 \begin_layout Section
22370 The Z80 and gbz80 port
22371 \end_layout
22372
22373 \begin_layout Standard
22374 SDCC can target both the Zilog Z80
22375 \begin_inset LatexCommand \index{Z80}
22376
22377 \end_inset
22378
22379  and the Nintendo Gameboy's Z80-like gbz80
22380 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
22381
22382 \end_inset
22383
22384 .
22385  The Z80 port is passed through the same 
22386 \emph on
22387 regressions tests
22388 \begin_inset LatexCommand \index{Regression test}
22389
22390 \end_inset
22391
22392
22393 \emph default
22394  (see section 
22395 \begin_inset LatexCommand \ref{sec:Quality-control}
22396
22397 \end_inset
22398
22399 ) as the MCS51 and DS390 ports, so floating point support, support for long
22400  variables and bitfield support is fine.
22401  See mailing lists and forums about interrupt routines.
22402 \end_layout
22403
22404 \begin_layout Standard
22405 As always, the code is the authoritative reference - see z80/ralloc.c and
22406  z80/gen.c.
22407  The stack
22408 \begin_inset LatexCommand \index{Z80!stack}
22409
22410 \end_inset
22411
22412  frame is similar to that generated by the IAR Z80 compiler.
22413  IX is used as the base pointer, HL and IY are used as a temporary registers,
22414  and BC and DE are available for holding variables.
22415  Return values
22416 \begin_inset LatexCommand \index{Z80!return value}
22417
22418 \end_inset
22419
22420  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
22421  bytes).
22422  The gbz80 port use the same set of registers for the return values, but
22423  in a different order of significance: E (one byte), DE (two bytes), or
22424  HLDE (four bytes).
22425 \begin_inset VSpace bigskip
22426 \end_inset
22427
22428
22429 \end_layout
22430
22431 \begin_layout Section
22432 The HC08 port
22433 \end_layout
22434
22435 \begin_layout Standard
22436 The port to the Freescale/Motorola HC08
22437 \begin_inset LatexCommand \index{HC08}
22438
22439 \end_inset
22440
22441  family has been added in October 2003, and is still undergoing some basic
22442  development.
22443  The code generator is complete, but the register allocation is still quite
22444  unoptimized.
22445  Some of the SDCC's standard C library functions have embedded non-HC08
22446  inline assembly and so are not yet usable.
22447 \end_layout
22448
22449 \begin_layout Standard
22450 The HC08 port passes the regression test suite (see section 
22451 \begin_inset LatexCommand \ref{sec:Quality-control}
22452
22453 \end_inset
22454
22455 ).
22456 \begin_inset VSpace bigskip
22457 \end_inset
22458
22459
22460 \newpage
22461
22462 \end_layout
22463
22464 \begin_layout Section
22465 The PIC14 port
22466 \end_layout
22467
22468 \begin_layout Standard
22469 The 14bit PIC
22470 \begin_inset LatexCommand \index{PIC14}
22471
22472 \end_inset
22473
22474  port still requires a major effort from the development community.
22475  However it can work for simple code.
22476  It passes its (smaller set of) regression tests
22477 \begin_inset LatexCommand \index{Regression test (PIC14)}
22478
22479 \end_inset
22480
22481  in the directory 
22482 \shape italic
22483 sdcc/src/regression
22484 \shape default
22485 .
22486 \end_layout
22487
22488 \begin_layout Subsection
22489 C code and 14bit PIC code page
22490 \begin_inset LatexCommand \index{code page (pic14)}
22491
22492 \end_inset
22493
22494  and RAM banks
22495 \begin_inset LatexCommand \index{RAM bank (pic14)}
22496
22497 \end_inset
22498
22499
22500 \end_layout
22501
22502 \begin_layout Standard
22503 The linker organizes allocation for the code page and RAM banks.
22504  It does not have intimate knowledge of the code flow.
22505  It will put all the code section of a single asm file into a single code
22506  page.
22507  In order to make use of multiple code pages, separate asm files must be
22508  used.
22509  The compiler treats all functions of a single C file as being in the same
22510  code page unless it is non static.
22511 \newline
22512
22513 \newline
22514 To get the best follow these guide lines:
22515 \end_layout
22516
22517 \begin_layout Enumerate
22518 Make local functions static, as non static functions require code page selection
22519  overhead.
22520 \end_layout
22521
22522 \begin_layout Enumerate
22523 For devices that have multiple code pages it is more efficient to use the
22524  same number of files as pages, i.e.
22525  for the 16F877 use 4 separate files and i.e.
22526  for the 16F874 use 2 separate files.
22527  This way the linker can put the code for each file into different code
22528  pages and there's less page selection overhead.
22529 \end_layout
22530
22531 \begin_layout Enumerate
22532 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
22533  instruction set), use 'unsigned char' whereever possible instead of 'int'.
22534 \end_layout
22535
22536 \begin_layout Subsection
22537 Creating a device include file 
22538 \end_layout
22539
22540 \begin_layout Standard
22541 For generating a device include file
22542 \begin_inset LatexCommand \index{PIC14!Header files}
22543
22544 \end_inset
22545
22546  use the support perl script inc2h.pl kept in directory support/script.
22547 \end_layout
22548
22549 \begin_layout Subsection
22550 Interrupt code
22551 \end_layout
22552
22553 \begin_layout Standard
22554 For the interrupt function, use the keyword '__interrupt'
22555 \begin_inset LatexCommand \index{PIC14!interrupt}
22556
22557 \end_inset
22558
22559  with level number of 0 (PIC14 only has 1 interrupt so this number is only
22560  there to avoid a syntax error - it ought to be fixed).
22561  E.g.:
22562 \end_layout
22563
22564 \begin_layout Verse
22565
22566 \family typewriter
22567 void Intr(void) __interrupt 0
22568 \newline
22569 {
22570 \newline
22571 \InsetSpace ~
22572 \InsetSpace ~
22573 T0IF = 0; /* Clear timer interrupt */
22574 \newline
22575 }
22576 \end_layout
22577
22578 \begin_layout Subsection
22579 Linking and assembling
22580 \end_layout
22581
22582 \begin_layout Standard
22583 For assembling you can use either GPUTILS'
22584 \begin_inset LatexCommand \index{gputils (pic tools)}
22585
22586 \end_inset
22587
22588  gpasm.exe or MPLAB's mpasmwin.exe.
22589  GPUTILS is available from 
22590 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
22591
22592 \end_inset
22593
22594 .
22595  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
22596  If you use MPLAB and an interrupt function then the linker script file
22597  vectors section will need to be enlarged to link with mplink.
22598 \newline
22599
22600 \newline
22601 Here is a 
22602 \family typewriter
22603 Makefile
22604 \family default
22605  using GPUTILS:
22606 \end_layout
22607
22608 \begin_layout Verse
22609
22610 \family typewriter
22611 .c.o:
22612 \newline
22613 \InsetSpace ~
22614 \InsetSpace ~
22615 \InsetSpace ~
22616 \InsetSpace ~
22617 \InsetSpace ~
22618 \InsetSpace ~
22619 \InsetSpace ~
22620 \InsetSpace ~
22621 sdcc -S -V -mpic14 -p16F877 $< 
22622 \newline
22623 \InsetSpace ~
22624 \InsetSpace ~
22625 \InsetSpace ~
22626 \InsetSpace ~
22627 \InsetSpace ~
22628 \InsetSpace ~
22629 \InsetSpace ~
22630 \InsetSpace ~
22631 gpasm -c $*.asm
22632 \newline
22633
22634 \newline
22635 $(PRJ).hex: $(OBJS) 
22636 \newline
22637 \InsetSpace ~
22638 \InsetSpace ~
22639 \InsetSpace ~
22640 \InsetSpace ~
22641 \InsetSpace ~
22642 \InsetSpace ~
22643 \InsetSpace ~
22644 \InsetSpace ~
22645 gplink
22646  -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
22647 \end_layout
22648
22649 \begin_layout Standard
22650 Here is a 
22651 \family typewriter
22652 Makefile
22653 \family default
22654  using MPLAB:
22655 \end_layout
22656
22657 \begin_layout Verse
22658
22659 \family typewriter
22660 .c.o: 
22661 \newline
22662 \InsetSpace ~
22663 \InsetSpace ~
22664 \InsetSpace ~
22665 \InsetSpace ~
22666 \InsetSpace ~
22667 \InsetSpace ~
22668 \InsetSpace ~
22669 \InsetSpace ~
22670 sdcc -S -V -mpic14 -p16F877 $< 
22671 \newline
22672 \InsetSpace ~
22673 \InsetSpace ~
22674 \InsetSpace ~
22675 \InsetSpace ~
22676 \InsetSpace ~
22677 \InsetSpace ~
22678 \InsetSpace ~
22679 \InsetSpace ~
22680 mpasmwin /q /o $*.asm
22681 \newline
22682
22683 \newline
22684 $(PRJ).hex: $(OBJS)
22685  
22686 \newline
22687 \InsetSpace ~
22688 \InsetSpace ~
22689 \InsetSpace ~
22690 \InsetSpace ~
22691 \InsetSpace ~
22692 \InsetSpace ~
22693 \InsetSpace ~
22694 \InsetSpace ~
22695 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
22696 \end_layout
22697
22698 \begin_layout Standard
22699 Please note that indentations within a
22700 \family typewriter
22701  Makefile
22702 \family default
22703  have to be done with a tabulator character.
22704 \end_layout
22705
22706 \begin_layout Subsection
22707 Command-line options
22708 \end_layout
22709
22710 \begin_layout Standard
22711 Besides the switches common to all SDCC backends, the PIC14 port accepts
22712  the following options (for an updated list see sdcc -
22713 \begin_inset ERT
22714 status collapsed
22715
22716 \begin_layout Standard
22717
22718
22719 \backslash
22720 /
22721 \end_layout
22722
22723 \end_inset
22724
22725 -help):
22726 \end_layout
22727
22728 \begin_layout List
22729 \labelwidthstring 00.00.0000
22730 -
22731 \begin_inset ERT
22732 status collapsed
22733
22734 \begin_layout Standard
22735
22736
22737 \backslash
22738 /
22739 \end_layout
22740
22741 \end_inset
22742
22743 -debug-xtra
22744 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
22745
22746 \end_inset
22747
22748  emit debug info in assembly output
22749 \end_layout
22750
22751 \begin_layout List
22752 \labelwidthstring 00.00.0000
22753 -
22754 \begin_inset ERT
22755 status collapsed
22756
22757 \begin_layout Standard
22758
22759
22760 \backslash
22761 /
22762 \end_layout
22763
22764 \end_inset
22765
22766 -no-pcode-opt
22767 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
22768
22769 \end_inset
22770
22771  disable (slightly faulty) optimization on pCode
22772 \end_layout
22773
22774 \begin_layout List
22775 \labelwidthstring 00.00.0000
22776 -
22777 \begin_inset ERT
22778 status collapsed
22779
22780 \begin_layout Standard
22781
22782
22783 \backslash
22784 /
22785 \end_layout
22786
22787 \end_inset
22788
22789 -stack-loc
22790 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
22791
22792 \end_inset
22793
22794  sets the lowest address of the argument passing stack (defaults to a suitably
22795  large shared databank to reduce BANKSEL overhead)
22796 \end_layout
22797
22798 \begin_layout List
22799 \labelwidthstring 00.00.0000
22800 -
22801 \begin_inset ERT
22802 status collapsed
22803
22804 \begin_layout Standard
22805
22806
22807 \backslash
22808 /
22809 \end_layout
22810
22811 \end_inset
22812
22813 -stack-size
22814 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
22815
22816 \end_inset
22817
22818  sets the size if the argument passing stack (default: 16, minimum: 4)
22819 \end_layout
22820
22821 \begin_layout Subsection
22822 The library
22823 \end_layout
22824
22825 \begin_layout Subsubsection
22826 error: missing definition for symbol 
22827 \begin_inset Quotes sld
22828 \end_inset
22829
22830 __gptrget1
22831 \begin_inset Quotes srd
22832 \end_inset
22833
22834
22835 \end_layout
22836
22837 \begin_layout Standard
22838 The PIC14 port uses library routines to provide more complex operations
22839  like multiplication, division/modulus and (generic) pointer dereferencing.
22840  In order to add these routines to your project, you must link with PIC14's
22841  
22842 \family typewriter
22843 libsdcc.lib
22844 \family default
22845 .
22846  For single source file projects this is done automatically, more complex
22847  projects must add 
22848 \family typewriter
22849 libsdcc.lib
22850 \family default
22851  to the linker's arguments.
22852  Make sure you also add an include path for the library (using the -I switch
22853  to the linker)!
22854 \end_layout
22855
22856 \begin_layout Subsubsection
22857 Processor mismatch in file 
22858 \begin_inset Quotes sld
22859 \end_inset
22860
22861 XXX
22862 \begin_inset Quotes srd
22863 \end_inset
22864
22865 .
22866 \end_layout
22867
22868 \begin_layout Standard
22869 This warning can usually be ignored due to the very good compatibility amongst
22870  14 bit PIC
22871 \begin_inset LatexCommand \index{PIC14}
22872
22873 \end_inset
22874
22875  devices.
22876 \end_layout
22877
22878 \begin_layout Standard
22879 You might also consider recompiling the library for your specific device
22880  by changing the ARCH=p16f877 (default target) entry in 
22881 \family typewriter
22882 device/lib/pic/Makefile.in
22883 \family default
22884  and 
22885 \family typewriter
22886 device/lib/pic/Makefile
22887 \family default
22888  to reflect your device.
22889  This might even improve performance for smaller devices as unneccesary
22890  BANKSELs migth be removed.
22891 \end_layout
22892
22893 \begin_layout Subsection
22894 Known bugs
22895 \end_layout
22896
22897 \begin_layout Subsubsection
22898 initialized data
22899 \end_layout
22900
22901 \begin_layout Standard
22902 Currently, data can only be initialized if it resides in the source file
22903  together with 
22904 \emph on
22905 main()
22906 \emph default
22907 .
22908  Data in other source files will silently 
22909 \series bold
22910 not
22911 \series default
22912  be initialized.
22913 \family typewriter
22914 \size footnotesize
22915
22916 \begin_inset Marginal
22917 status collapsed
22918
22919 \begin_layout Standard
22920
22921 \series bold
22922 \InsetSpace ~
22923 !
22924 \end_layout
22925
22926 \end_inset
22927
22928
22929 \family default
22930
22931 \newpage
22932
22933 \end_layout
22934
22935 \begin_layout Section
22936 The PIC16
22937 \begin_inset LatexCommand \index{PIC16}
22938
22939 \end_inset
22940
22941  port
22942 \end_layout
22943
22944 \begin_layout Standard
22945 The PIC16
22946 \begin_inset LatexCommand \index{PIC16}
22947
22948 \end_inset
22949
22950  port is the portion of SDCC that is responsible to produce code for the
22951  Microchip
22952 \begin_inset LatexCommand \index{Microchip}
22953
22954 \end_inset
22955
22956 (TM) microcontrollers with 16 bit core.
22957  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
22958  Currently supported devices are:
22959 \end_layout
22960
22961 \begin_layout Standard
22962 \align center
22963 \begin_inset Tabular
22964 <lyxtabular version="3" rows="4" columns="6">
22965 <features>
22966 <column alignment="center" valignment="top" leftline="true" width="0">
22967 <column alignment="center" valignment="top" leftline="true" width="0">
22968 <column alignment="center" valignment="top" leftline="true" width="0">
22969 <column alignment="center" valignment="top" leftline="true" width="0">
22970 <column alignment="center" valignment="top" leftline="true" width="0">
22971 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
22972 <row topline="true">
22973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22974 \begin_inset Text
22975
22976 \begin_layout Standard
22977 18F242
22978 \end_layout
22979
22980 \end_inset
22981 </cell>
22982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22983 \begin_inset Text
22984
22985 \begin_layout Standard
22986 18F248
22987 \end_layout
22988
22989 \end_inset
22990 </cell>
22991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22992 \begin_inset Text
22993
22994 \begin_layout Standard
22995 18F252
22996 \end_layout
22997
22998 \end_inset
22999 </cell>
23000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23001 \begin_inset Text
23002
23003 \begin_layout Standard
23004 18F258
23005 \end_layout
23006
23007 \end_inset
23008 </cell>
23009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23010 \begin_inset Text
23011
23012 \begin_layout Standard
23013 18F442
23014 \end_layout
23015
23016 \end_inset
23017 </cell>
23018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23019 \begin_inset Text
23020
23021 \begin_layout Standard
23022 18F448
23023 \end_layout
23024
23025 \end_inset
23026 </cell>
23027 </row>
23028 <row topline="true">
23029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23030 \begin_inset Text
23031
23032 \begin_layout Standard
23033 18F452
23034 \end_layout
23035
23036 \end_inset
23037 </cell>
23038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23039 \begin_inset Text
23040
23041 \begin_layout Standard
23042 18F458
23043 \end_layout
23044
23045 \end_inset
23046 </cell>
23047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23048 \begin_inset Text
23049
23050 \begin_layout Standard
23051 18F1220
23052 \end_layout
23053
23054 \end_inset
23055 </cell>
23056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23057 \begin_inset Text
23058
23059 \begin_layout Standard
23060 18F2220
23061 \end_layout
23062
23063 \end_inset
23064 </cell>
23065 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23066 \begin_inset Text
23067
23068 \begin_layout Standard
23069 18F2550
23070 \end_layout
23071
23072 \end_inset
23073 </cell>
23074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23075 \begin_inset Text
23076
23077 \begin_layout Standard
23078 18F4331
23079 \end_layout
23080
23081 \end_inset
23082 </cell>
23083 </row>
23084 <row topline="true">
23085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23086 \begin_inset Text
23087
23088 \begin_layout Standard
23089 18F4455
23090 \end_layout
23091
23092 \end_inset
23093 </cell>
23094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23095 \begin_inset Text
23096
23097 \begin_layout Standard
23098 18F6520
23099 \end_layout
23100
23101 \end_inset
23102 </cell>
23103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23104 \begin_inset Text
23105
23106 \begin_layout Standard
23107 18F6620
23108 \end_layout
23109
23110 \end_inset
23111 </cell>
23112 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23113 \begin_inset Text
23114
23115 \begin_layout Standard
23116 18F6680
23117 \end_layout
23118
23119 \end_inset
23120 </cell>
23121 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23122 \begin_inset Text
23123
23124 \begin_layout Standard
23125 18F6720
23126 \end_layout
23127
23128 \end_inset
23129 </cell>
23130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23131 \begin_inset Text
23132
23133 \begin_layout Standard
23134 18F8520
23135 \end_layout
23136
23137 \end_inset
23138 </cell>
23139 </row>
23140 <row topline="true" bottomline="true">
23141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23142 \begin_inset Text
23143
23144 \begin_layout Standard
23145 18F8620
23146 \end_layout
23147
23148 \end_inset
23149 </cell>
23150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23151 \begin_inset Text
23152
23153 \begin_layout Standard
23154 18F8680
23155 \end_layout
23156
23157 \end_inset
23158 </cell>
23159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23160 \begin_inset Text
23161
23162 \begin_layout Standard
23163 18F8720
23164 \end_layout
23165
23166 \end_inset
23167 </cell>
23168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23169 \begin_inset Text
23170
23171 \begin_layout Standard
23172
23173 \end_layout
23174
23175 \end_inset
23176 </cell>
23177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23178 \begin_inset Text
23179
23180 \begin_layout Standard
23181
23182 \end_layout
23183
23184 \end_inset
23185 </cell>
23186 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23187 \begin_inset Text
23188
23189 \begin_layout Standard
23190
23191 \end_layout
23192
23193 \end_inset
23194 </cell>
23195 </row>
23196 </lyxtabular>
23197
23198 \end_inset
23199
23200
23201 \end_layout
23202
23203 \begin_layout Subsection
23204 Global Options
23205 \end_layout
23206
23207 \begin_layout Standard
23208 PIC16 port supports the standard command line arguments as supposed, with
23209  the exception of certain cases that will be mentioned in the following
23210  list:
23211 \end_layout
23212
23213 \begin_layout List
23214 \labelwidthstring 00.00.0000
23215 -
23216 \begin_inset ERT
23217 status collapsed
23218
23219 \begin_layout Standard
23220
23221
23222 \backslash
23223 /
23224 \end_layout
23225
23226 \end_inset
23227
23228 -callee-saves
23229 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23230
23231 \end_inset
23232
23233  See -
23234 \begin_inset ERT
23235 status collapsed
23236
23237 \begin_layout Standard
23238
23239
23240 \backslash
23241 /
23242 \end_layout
23243
23244 \end_inset
23245
23246 -all-callee-saves
23247 \end_layout
23248
23249 \begin_layout List
23250 \labelwidthstring 00.00.0000
23251 -
23252 \begin_inset ERT
23253 status collapsed
23254
23255 \begin_layout Standard
23256
23257
23258 \backslash
23259 /
23260 \end_layout
23261
23262 \end_inset
23263
23264 -fommit-frame-pointer
23265 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23266
23267 \end_inset
23268
23269  Frame pointer will be omitted when the function uses no local variables.
23270 \end_layout
23271
23272 \begin_layout Subsection
23273 Port Specific Options
23274 \begin_inset LatexCommand \index{Options PIC16}
23275
23276 \end_inset
23277
23278
23279 \end_layout
23280
23281 \begin_layout Standard
23282 The port specific options appear after the global options in the sdcc --help
23283  output.
23284 \end_layout
23285
23286 \begin_layout Subsubsection
23287 General Options
23288 \end_layout
23289
23290 \begin_layout Standard
23291 General options enable certain port features and optimizations.
23292 \end_layout
23293
23294 \begin_layout List
23295 \labelwidthstring 00.00.0000
23296 -
23297 \begin_inset ERT
23298 status collapsed
23299
23300 \begin_layout Standard
23301
23302
23303 \backslash
23304 /
23305 \end_layout
23306
23307 \end_inset
23308
23309 -pstack-model=[model] Used in conjuction with the command above.
23310  Defines the stack model to be used, valid stack models are : 
23311 \end_layout
23312
23313 \begin_deeper
23314 \begin_layout List
23315 \labelwidthstring 00.00.0000
23316
23317 \emph on
23318 small
23319 \emph default
23320  Selects small stack model.
23321  8 bit stack and frame pointers.
23322  Supports 256 bytes stack size.
23323 \end_layout
23324
23325 \begin_layout List
23326 \labelwidthstring 00.00.0000
23327
23328 \emph on
23329 large
23330 \emph default
23331  Selects large stack model.
23332  16 bit stack and frame pointers.
23333  Supports 65536 bytes stack size.
23334 \end_layout
23335
23336 \end_deeper
23337 \begin_layout List
23338 \labelwidthstring 00.00.0000
23339 -
23340 \begin_inset ERT
23341 status collapsed
23342
23343 \begin_layout Standard
23344
23345
23346 \backslash
23347 /
23348 \end_layout
23349
23350 \end_inset
23351
23352 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
23353  unitialized data variables with [kword].
23354  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
23355 \end_layout
23356
23357 \begin_layout List
23358 \labelwidthstring 00.00.0000
23359 -
23360 \begin_inset ERT
23361 status collapsed
23362
23363 \begin_layout Standard
23364
23365
23366 \backslash
23367 /
23368 \end_layout
23369
23370 \end_inset
23371
23372 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
23373  Useful for bootloaders.
23374 \end_layout
23375
23376 \begin_layout List
23377 \labelwidthstring 00.00.0000
23378 -
23379 \begin_inset ERT
23380 status collapsed
23381
23382 \begin_layout Standard
23383
23384
23385 \backslash
23386 /
23387 \end_layout
23388
23389 \end_inset
23390
23391 -asm= sets the full path and name of an external assembler to call.
23392 \end_layout
23393
23394 \begin_layout List
23395 \labelwidthstring 00.00.0000
23396 -
23397 \begin_inset ERT
23398 status collapsed
23399
23400 \begin_layout Standard
23401
23402
23403 \backslash
23404 /
23405 \end_layout
23406
23407 \end_inset
23408
23409 -link= sets the full path and name of an external linker to call.
23410 \end_layout
23411
23412 \begin_layout List
23413 \labelwidthstring 00.00.0000
23414 -
23415 \begin_inset ERT
23416 status collapsed
23417
23418 \begin_layout Standard
23419
23420
23421 \backslash
23422 /
23423 \end_layout
23424
23425 \end_inset
23426
23427 -mplab-comp MPLAB
23428 \begin_inset LatexCommand \index{PIC16!MPLAB}
23429
23430 \end_inset
23431
23432  compatibility option.
23433  Currently only suppresses special gpasm directives.
23434 \end_layout
23435
23436 \begin_layout Subsubsection
23437 Optimization Options
23438 \end_layout
23439
23440 \begin_layout List
23441 \labelwidthstring 00.00.0000
23442 -
23443 \begin_inset ERT
23444 status collapsed
23445
23446 \begin_layout Standard
23447
23448
23449 \backslash
23450 /
23451 \end_layout
23452
23453 \end_inset
23454
23455 -optimize-goto Try to use (conditional) BRA instead of GOTO
23456 \end_layout
23457
23458 \begin_layout List
23459 \labelwidthstring 00.00.0000
23460 -
23461 \begin_inset ERT
23462 status collapsed
23463
23464 \begin_layout Standard
23465
23466
23467 \backslash
23468 /
23469 \end_layout
23470
23471 \end_inset
23472
23473 -optimize-cmp Try to optimize some compares.
23474 \end_layout
23475
23476 \begin_layout List
23477 \labelwidthstring 00.00.0000
23478 -
23479 \begin_inset ERT
23480 status collapsed
23481
23482 \begin_layout Standard
23483
23484
23485 \backslash
23486 /
23487 \end_layout
23488
23489 \end_inset
23490
23491 -optimize-df Analyze the dataflow of the generated code and improve it.
23492 \end_layout
23493
23494 \begin_layout List
23495 \labelwidthstring 00.00.0000
23496 -
23497 \begin_inset ERT
23498 status collapsed
23499
23500 \begin_layout Standard
23501
23502
23503 \backslash
23504 /
23505 \end_layout
23506
23507 \end_inset
23508
23509 -obanksel=nn Set optimization level for inserting BANKSELs.
23510 \newline
23511
23512 \end_layout
23513
23514 \begin_deeper
23515 \begin_layout List
23516 \labelwidthstring 00.00.0000
23517 0 no optimization
23518 \end_layout
23519
23520 \begin_layout List
23521 \labelwidthstring 00.00.0000
23522 1 checks previous used register and if it is the same then does not emit
23523  BANKSEL, accounts only for labels.
23524 \end_layout
23525
23526 \begin_layout List
23527 \labelwidthstring 00.00.0000
23528 2 tries to check the location of (even different) symbols and removes BANKSELs
23529  if they are in the same bank.
23530  
23531 \newline
23532
23533 \emph on
23534 Important: There might be problems if the linker script has data sections
23535  across bank borders!
23536 \end_layout
23537
23538 \end_deeper
23539 \begin_layout Subsubsection
23540 Linking Options
23541 \end_layout
23542
23543 \begin_layout List
23544 \labelwidthstring 00.00.0000
23545 -
23546 \begin_inset ERT
23547 status collapsed
23548
23549 \begin_layout Standard
23550
23551
23552 \backslash
23553 /
23554 \end_layout
23555
23556 \end_inset
23557
23558 -nodefaultlibs do not link default libraries when linking
23559 \end_layout
23560
23561 \begin_layout List
23562 \labelwidthstring 00.00.0000
23563 -
23564 \begin_inset ERT
23565 status collapsed
23566
23567 \begin_layout Standard
23568
23569
23570 \backslash
23571 /
23572 \end_layout
23573
23574 \end_inset
23575
23576 -no-crt Don't link the default run-time modules
23577 \end_layout
23578
23579 \begin_layout List
23580 \labelwidthstring 00.00.0000
23581 -
23582 \begin_inset ERT
23583 status collapsed
23584
23585 \begin_layout Standard
23586
23587
23588 \backslash
23589 /
23590 \end_layout
23591
23592 \end_inset
23593
23594 -use-crt= Use a custom run-time module instead of the defaults.
23595 \end_layout
23596
23597 \begin_layout Subsubsection
23598 Debugging Options
23599 \end_layout
23600
23601 \begin_layout Standard
23602 Debugging options enable extra debugging information in the output files.
23603 \end_layout
23604
23605 \begin_layout List
23606 \labelwidthstring 00.00.0000
23607 -
23608 \begin_inset ERT
23609 status collapsed
23610
23611 \begin_layout Standard
23612
23613
23614 \backslash
23615 /
23616 \end_layout
23617
23618 \end_inset
23619
23620 -debug-xtra Similar to -
23621 \begin_inset ERT
23622 status collapsed
23623
23624 \begin_layout Standard
23625
23626
23627 \backslash
23628 /
23629 \end_layout
23630
23631 \end_inset
23632
23633 -debug
23634 \begin_inset LatexCommand \index{-\/-debug}
23635
23636 \end_inset
23637
23638 , but dumps more information.
23639 \end_layout
23640
23641 \begin_layout List
23642 \labelwidthstring 00.00.0000
23643 -
23644 \begin_inset ERT
23645 status collapsed
23646
23647 \begin_layout Standard
23648
23649
23650 \backslash
23651 /
23652 \end_layout
23653
23654 \end_inset
23655
23656 -debug-ralloc Force register allocator to dump <source>.d file with debugging
23657  information.
23658  <source> is the name of the file compiled.
23659 \end_layout
23660
23661 \begin_layout List
23662 \labelwidthstring 00.00.0000
23663 -
23664 \begin_inset ERT
23665 status collapsed
23666
23667 \begin_layout Standard
23668
23669
23670 \backslash
23671 /
23672 \end_layout
23673
23674 \end_inset
23675
23676 -pcode-verbose Enable pcode debugging information in translation.
23677 \end_layout
23678
23679 \begin_layout List
23680 \labelwidthstring 00.00.0000
23681 -
23682 \begin_inset ERT
23683 status collapsed
23684
23685 \begin_layout Standard
23686
23687
23688 \backslash
23689 /
23690 \end_layout
23691
23692 \end_inset
23693
23694 -denable-peeps Force the usage of peepholes.
23695  Use with care.
23696 \end_layout
23697
23698 \begin_layout List
23699 \labelwidthstring 00.00.0000
23700 -
23701 \begin_inset ERT
23702 status collapsed
23703
23704 \begin_layout Standard
23705
23706
23707 \backslash
23708 /
23709 \end_layout
23710
23711 \end_inset
23712
23713 -gstack Trace push/pops for stack pointer overflow
23714 \end_layout
23715
23716 \begin_layout List
23717 \labelwidthstring 00.00.0000
23718 -
23719 \begin_inset ERT
23720 status collapsed
23721
23722 \begin_layout Standard
23723
23724
23725 \backslash
23726 /
23727 \end_layout
23728
23729 \end_inset
23730
23731 -call-tree dump call tree in .calltree file
23732 \end_layout
23733
23734 \begin_layout Subsection
23735 Enviromental Variables
23736 \end_layout
23737
23738 \begin_layout Standard
23739 There is a number of enviromental variables that can be used when running
23740  SDCC to enable certain optimizations or force a specific program behaviour.
23741  these variables are primarily for debugging purposes so they can be enabled/dis
23742 abled at will.
23743 \end_layout
23744
23745 \begin_layout Standard
23746 Currently there is only two such variables available:
23747 \end_layout
23748
23749 \begin_layout List
23750 \labelwidthstring 00.00.0000
23751 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
23752  bitfields is optimized by directly loading FSR0 with the address of the
23753  bitfield structure.
23754  Normally SDCC will cast the bitfield structure to a bitfield pointer and
23755  then load FSR0.
23756  This step saves data ram and code space for functions that perform heavy
23757  use of bitfields.
23758  (ie.
23759  80 bytes of code space are saved when compiling malloc.c with this option).
23760  
23761 \end_layout
23762
23763 \begin_layout List
23764 \labelwidthstring 00.00.0000
23765 NO_REG_OPT do not perform pCode registers optimization.
23766  This should be used for debugging purposes.
23767  In some where bugs in the pcode optimizer are found, users can benefit
23768  from temporarily disabling the optimizer until the bug is fixed.
23769 \end_layout
23770
23771 \begin_layout Subsection
23772 Preprocessor Macros
23773 \end_layout
23774
23775 \begin_layout Standard
23776 PIC16
23777 \begin_inset LatexCommand \index{PIC16}
23778
23779 \end_inset
23780
23781  port defines the following preprocessor macros while translating a source.
23782 \end_layout
23783
23784 \begin_layout Standard
23785 \align center
23786 \begin_inset Tabular
23787 <lyxtabular version="3" rows="6" columns="2">
23788 <features>
23789 <column alignment="center" valignment="top" leftline="true" width="0">
23790 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23791 <row topline="true" bottomline="true">
23792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23793 \begin_inset Text
23794
23795 \begin_layout Standard
23796 Macro
23797 \end_layout
23798
23799 \end_inset
23800 </cell>
23801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23802 \begin_inset Text
23803
23804 \begin_layout Standard
23805 Description
23806 \end_layout
23807
23808 \end_inset
23809 </cell>
23810 </row>
23811 <row topline="true">
23812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23813 \begin_inset Text
23814
23815 \begin_layout Standard
23816 SDCC_pic16
23817 \end_layout
23818
23819 \end_inset
23820 </cell>
23821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23822 \begin_inset Text
23823
23824 \begin_layout Standard
23825 Port identification
23826 \end_layout
23827
23828 \end_inset
23829 </cell>
23830 </row>
23831 <row topline="true">
23832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23833 \begin_inset Text
23834
23835 \begin_layout Standard
23836 _
23837 \begin_inset ERT
23838 status collapsed
23839
23840 \begin_layout Standard
23841
23842
23843 \backslash
23844 /
23845 \end_layout
23846
23847 \end_inset
23848
23849 _pic16
23850 \end_layout
23851
23852 \end_inset
23853 </cell>
23854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23855 \begin_inset Text
23856
23857 \begin_layout Standard
23858 Port identification (same as above)
23859 \end_layout
23860
23861 \end_inset
23862 </cell>
23863 </row>
23864 <row topline="true">
23865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23866 \begin_inset Text
23867
23868 \begin_layout Standard
23869 pic18fxxxx
23870 \end_layout
23871
23872 \end_inset
23873 </cell>
23874 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23875 \begin_inset Text
23876
23877 \begin_layout Standard
23878 MCU Identification.
23879  
23880 \emph on
23881 xxxx
23882 \emph default
23883  is the microcontrol identification number, i.e.
23884  452, 6620, etc
23885 \end_layout
23886
23887 \end_inset
23888 </cell>
23889 </row>
23890 <row topline="true">
23891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23892 \begin_inset Text
23893
23894 \begin_layout Standard
23895 _
23896 \begin_inset ERT
23897 status collapsed
23898
23899 \begin_layout Standard
23900
23901
23902 \backslash
23903 /
23904 \end_layout
23905
23906 \end_inset
23907
23908 _18Fxxxx
23909 \end_layout
23910
23911 \end_inset
23912 </cell>
23913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23914 \begin_inset Text
23915
23916 \begin_layout Standard
23917 MCU Identification (same as above)
23918 \end_layout
23919
23920 \end_inset
23921 </cell>
23922 </row>
23923 <row topline="true" bottomline="true">
23924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23925 \begin_inset Text
23926
23927 \begin_layout Standard
23928 STACK_MODEL_nnn
23929 \end_layout
23930
23931 \end_inset
23932 </cell>
23933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23934 \begin_inset Text
23935
23936 \begin_layout Standard
23937 nnn = SMALL or LARGE respectively according to the stack model used
23938 \end_layout
23939
23940 \end_inset
23941 </cell>
23942 </row>
23943 </lyxtabular>
23944
23945 \end_inset
23946
23947
23948 \end_layout
23949
23950 \begin_layout Standard
23951 In addition the following macros are defined when calling assembler:
23952 \end_layout
23953
23954 \begin_layout Standard
23955 \align center
23956 \begin_inset Tabular
23957 <lyxtabular version="3" rows="4" columns="2">
23958 <features>
23959 <column alignment="center" valignment="top" leftline="true" width="0">
23960 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23961 <row topline="true" bottomline="true">
23962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23963 \begin_inset Text
23964
23965 \begin_layout Standard
23966 Macro
23967 \end_layout
23968
23969 \end_inset
23970 </cell>
23971 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23972 \begin_inset Text
23973
23974 \begin_layout Standard
23975 Description
23976 \end_layout
23977
23978 \end_inset
23979 </cell>
23980 </row>
23981 <row topline="true">
23982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23983 \begin_inset Text
23984
23985 \begin_layout Standard
23986 __18Fxxxx
23987 \end_layout
23988
23989 \end_inset
23990 </cell>
23991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23992 \begin_inset Text
23993
23994 \begin_layout Standard
23995 MCU Identification.
23996  
23997 \emph on
23998 xxxx
23999 \emph default
24000  is the microcontrol identification number, i.e.
24001  452, 6620, etc
24002 \end_layout
24003
24004 \end_inset
24005 </cell>
24006 </row>
24007 <row topline="true">
24008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24009 \begin_inset Text
24010
24011 \begin_layout Standard
24012 SDCC_MODEL_nnn
24013 \end_layout
24014
24015 \end_inset
24016 </cell>
24017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24018 \begin_inset Text
24019
24020 \begin_layout Standard
24021 nnn = SMALL or LARGE respectively according to the memory model used for
24022  SDCC
24023 \end_layout
24024
24025 \end_inset
24026 </cell>
24027 </row>
24028 <row topline="true" bottomline="true">
24029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24030 \begin_inset Text
24031
24032 \begin_layout Standard
24033 STACK_MODEL_nnn
24034 \end_layout
24035
24036 \end_inset
24037 </cell>
24038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24039 \begin_inset Text
24040
24041 \begin_layout Standard
24042 nnn = SMALL or LARGE respectively according to the stack model used
24043 \end_layout
24044
24045 \end_inset
24046 </cell>
24047 </row>
24048 </lyxtabular>
24049
24050 \end_inset
24051
24052
24053 \end_layout
24054
24055 \begin_layout Subsection
24056 Directories
24057 \end_layout
24058
24059 \begin_layout Standard
24060 PIC16
24061 \begin_inset LatexCommand \index{PIC16}
24062
24063 \end_inset
24064
24065  port uses the following directories for searching header files and libraries.
24066 \end_layout
24067
24068 \begin_layout Standard
24069 \align center
24070 \begin_inset Tabular
24071 <lyxtabular version="3" rows="3" columns="4">
24072 <features>
24073 <column alignment="center" valignment="top" leftline="true" width="0">
24074 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24075 <column alignment="center" valignment="top" width="0">
24076 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24077 <row topline="true" bottomline="true">
24078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24079 \begin_inset Text
24080
24081 \begin_layout Standard
24082 Directory
24083 \end_layout
24084
24085 \end_inset
24086 </cell>
24087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24088 \begin_inset Text
24089
24090 \begin_layout Standard
24091 Description
24092 \end_layout
24093
24094 \end_inset
24095 </cell>
24096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24097 \begin_inset Text
24098
24099 \begin_layout Standard
24100 Target
24101 \end_layout
24102
24103 \end_inset
24104 </cell>
24105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24106 \begin_inset Text
24107
24108 \begin_layout Standard
24109 Command prefix
24110 \end_layout
24111
24112 \end_inset
24113 </cell>
24114 </row>
24115 <row topline="true">
24116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24117 \begin_inset Text
24118
24119 \begin_layout Standard
24120 PREFIX/sdcc/include/pic16
24121 \end_layout
24122
24123 \end_inset
24124 </cell>
24125 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24126 \begin_inset Text
24127
24128 \begin_layout Standard
24129 PIC16 specific headers
24130 \end_layout
24131
24132 \end_inset
24133 </cell>
24134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24135 \begin_inset Text
24136
24137 \begin_layout Standard
24138 Compiler
24139 \end_layout
24140
24141 \end_inset
24142 </cell>
24143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24144 \begin_inset Text
24145
24146 \begin_layout Standard
24147 -I
24148 \end_layout
24149
24150 \end_inset
24151 </cell>
24152 </row>
24153 <row topline="true" bottomline="true">
24154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24155 \begin_inset Text
24156
24157 \begin_layout Standard
24158 PREFIX/sdcc/lib/pic16
24159 \end_layout
24160
24161 \end_inset
24162 </cell>
24163 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24164 \begin_inset Text
24165
24166 \begin_layout Standard
24167 PIC16 specific libraries
24168 \end_layout
24169
24170 \end_inset
24171 </cell>
24172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24173 \begin_inset Text
24174
24175 \begin_layout Standard
24176 Linker
24177 \end_layout
24178
24179 \end_inset
24180 </cell>
24181 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24182 \begin_inset Text
24183
24184 \begin_layout Standard
24185 -L
24186 \end_layout
24187
24188 \end_inset
24189 </cell>
24190 </row>
24191 </lyxtabular>
24192
24193 \end_inset
24194
24195
24196 \end_layout
24197
24198 \begin_layout Subsection
24199 Pragmas
24200 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24201
24202 \end_inset
24203
24204
24205 \end_layout
24206
24207 \begin_layout Standard
24208 PIC16
24209 \begin_inset LatexCommand \index{PIC16}
24210
24211 \end_inset
24212
24213  port currently supports the following pragmas:
24214 \end_layout
24215
24216 \begin_layout List
24217 \labelwidthstring 00.00.0000
24218 stack
24219 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24220
24221 \end_inset
24222
24223  pragma stack
24224 \begin_inset LatexCommand \index{PIC16!stack}
24225
24226 \end_inset
24227
24228  forces the code generator to initialize the stack & frame pointers at a
24229  specific address.
24230  This is an adhoc solution for cases where no STACK directive is available
24231  in the linker script or gplink is not instructed to create a stack section.
24232 \newline
24233 The
24234  stack pragma should be used only once in a project.
24235  Multiple pragmas may result in indeterminate behaviour of the program.
24236 \begin_inset Foot
24237 status open
24238
24239 \begin_layout Standard
24240 The old format (ie.
24241  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24242  cross page boundaries (or even exceed the available data RAM) and crash
24243  the program.
24244  Make sure that stack does not cross page boundaries when using the SMALL
24245  stack model.
24246 \end_layout
24247
24248 \end_inset
24249
24250
24251 \newline
24252 The format is as follows:
24253 \end_layout
24254
24255 \begin_layout LyX-Code
24256 #pragma stack bottom_address [stack_size]
24257 \end_layout
24258
24259 \begin_layout Standard
24260
24261 \emph on
24262 bottom_address
24263 \emph default
24264  is the lower bound of the stack section.
24265  The stack pointer initially will point at address (bottom_address+stack_size-1).
24266 \end_layout
24267
24268 \begin_layout LyX-Code
24269 Example:
24270 \end_layout
24271
24272 \begin_layout LyX-Code
24273
24274 \end_layout
24275
24276 \begin_layout LyX-Code
24277 /* initializes stack of 100 bytes at RAM address 0x200 */
24278 \end_layout
24279
24280 \begin_layout LyX-Code
24281 #pragma stack 0x200 100
24282 \end_layout
24283
24284 \begin_layout Standard
24285 If the stack_size field is omitted then a stack is created with the default
24286  size of 64.
24287  This size might be enough for most programs, but its not enough for operations
24288  with deep function nesting or excessive stack usage.
24289 \end_layout
24290
24291 \begin_layout List
24292 \labelwidthstring 00.00.0000
24293 code
24294 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24295
24296 \end_inset
24297
24298  place a function symbol at static FLASH address
24299 \end_layout
24300
24301 \begin_layout LyX-Code
24302 Example:
24303 \end_layout
24304
24305 \begin_layout LyX-Code
24306
24307 \end_layout
24308
24309 \begin_layout LyX-Code
24310 /* place function test_func at 0x4000 */
24311 \end_layout
24312
24313 \begin_layout LyX-Code
24314 #pragma code test_func 0x4000
24315 \end_layout
24316
24317 \begin_layout LyX-Code
24318
24319 \end_layout
24320
24321 \begin_layout List
24322 \labelwidthstring 00.00.0000
24323 library instructs the linker to use a library module.
24324 \newline
24325 Usage:
24326 \end_layout
24327
24328 \begin_layout LyX-Code
24329 #pragma library module_name
24330 \end_layout
24331
24332 \begin_layout Standard
24333
24334 \emph on
24335 module_name
24336 \emph default
24337  can be any library or object file (including its path).
24338  Note that there are four reserved keywords which have special meaning.
24339  These are:
24340 \end_layout
24341
24342 \begin_layout Standard
24343 \align center
24344 \begin_inset Tabular
24345 <lyxtabular version="3" rows="6" columns="3">
24346 <features>
24347 <column alignment="center" valignment="top" leftline="true" width="0">
24348 <column alignment="block" valignment="top" leftline="true" width="20page%">
24349 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24350 <row topline="true" bottomline="true">
24351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24352 \begin_inset Text
24353
24354 \begin_layout Standard
24355 Keyword
24356 \end_layout
24357
24358 \end_inset
24359 </cell>
24360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24361 \begin_inset Text
24362
24363 \begin_layout Standard
24364 Description
24365 \end_layout
24366
24367 \end_inset
24368 </cell>
24369 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24370 \begin_inset Text
24371
24372 \begin_layout Standard
24373 Module to link
24374 \end_layout
24375
24376 \end_inset
24377 </cell>
24378 </row>
24379 <row topline="true">
24380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24381 \begin_inset Text
24382
24383 \begin_layout Standard
24384
24385 \series bold
24386 ignore
24387 \end_layout
24388
24389 \end_inset
24390 </cell>
24391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24392 \begin_inset Text
24393
24394 \begin_layout Standard
24395 ignore all library pragmas
24396 \end_layout
24397
24398 \end_inset
24399 </cell>
24400 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24401 \begin_inset Text
24402
24403 \begin_layout Standard
24404
24405 \emph on
24406 (none)
24407 \end_layout
24408
24409 \end_inset
24410 </cell>
24411 </row>
24412 <row topline="true">
24413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24414 \begin_inset Text
24415
24416 \begin_layout Standard
24417
24418 \series bold
24419 c
24420 \end_layout
24421
24422 \end_inset
24423 </cell>
24424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24425 \begin_inset Text
24426
24427 \begin_layout Standard
24428 link the C library
24429 \end_layout
24430
24431 \end_inset
24432 </cell>
24433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24434 \begin_inset Text
24435
24436 \begin_layout Standard
24437
24438 \emph on
24439 libc18f
24440 \emph default
24441 .lib
24442 \end_layout
24443
24444 \end_inset
24445 </cell>
24446 </row>
24447 <row topline="true">
24448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24449 \begin_inset Text
24450
24451 \begin_layout Standard
24452
24453 \series bold
24454 math
24455 \end_layout
24456
24457 \end_inset
24458 </cell>
24459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24460 \begin_inset Text
24461
24462 \begin_layout Standard
24463 link the Math libarary
24464 \end_layout
24465
24466 \end_inset
24467 </cell>
24468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24469 \begin_inset Text
24470
24471 \begin_layout Standard
24472
24473 \emph on
24474 libm18f
24475 \emph default
24476 .lib
24477 \end_layout
24478
24479 \end_inset
24480 </cell>
24481 </row>
24482 <row topline="true">
24483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24484 \begin_inset Text
24485
24486 \begin_layout Standard
24487
24488 \series bold
24489 io
24490 \end_layout
24491
24492 \end_inset
24493 </cell>
24494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24495 \begin_inset Text
24496
24497 \begin_layout Standard
24498 link the I/O library
24499 \end_layout
24500
24501 \end_inset
24502 </cell>
24503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24504 \begin_inset Text
24505
24506 \begin_layout Standard
24507
24508 \emph on
24509 libio18f*
24510 \emph default
24511 .lib
24512 \end_layout
24513
24514 \end_inset
24515 </cell>
24516 </row>
24517 <row topline="true" bottomline="true">
24518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24519 \begin_inset Text
24520
24521 \begin_layout Standard
24522
24523 \series bold
24524 debug
24525 \end_layout
24526
24527 \end_inset
24528 </cell>
24529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24530 \begin_inset Text
24531
24532 \begin_layout Standard
24533 link the debug library
24534 \end_layout
24535
24536 \end_inset
24537 </cell>
24538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24539 \begin_inset Text
24540
24541 \begin_layout Standard
24542
24543 \emph on
24544 libdebug
24545 \emph default
24546 .lib
24547 \end_layout
24548
24549 \end_inset
24550 </cell>
24551 </row>
24552 </lyxtabular>
24553
24554 \end_inset
24555
24556
24557 \newline
24558 * is the device number, i.e.
24559  452 for PIC18F452 MCU.
24560 \end_layout
24561
24562 \begin_layout Standard
24563 This feature allows for linking with specific libraries withoug having to
24564  explicit name them in the command line.
24565  Note that the 
24566 \noun on
24567 ignore
24568 \noun default
24569  keyword will reject all modules specified by the library pragma.
24570 \end_layout
24571
24572 \begin_layout List
24573 \labelwidthstring 00.00.0000
24574 udata pragma udata instructs the compiler to emit code so that linker will
24575  place a variable at a specific memory bank
24576 \end_layout
24577
24578 \begin_layout LyX-Code
24579 Example:
24580 \end_layout
24581
24582 \begin_layout LyX-Code
24583
24584 \end_layout
24585
24586 \begin_layout LyX-Code
24587 /* places variable foo at bank2 */
24588 \end_layout
24589
24590 \begin_layout LyX-Code
24591 #pragma udata bank2 foo
24592 \end_layout
24593
24594 \begin_layout LyX-Code
24595 char foo;
24596 \end_layout
24597
24598 \begin_layout Standard
24599 In order for this pragma to work extra SECTION directives should be added
24600  in the .lkr script.
24601  In the following example a sample .lkr file is shown:
24602 \end_layout
24603
24604 \begin_layout LyX-Code
24605
24606 \end_layout
24607
24608 \begin_layout LyX-Code
24609 // Sample linker script for the PIC18F452 processor
24610 \end_layout
24611
24612 \begin_layout LyX-Code
24613 LIBPATH .
24614 \end_layout
24615
24616 \begin_layout LyX-Code
24617 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
24618 \end_layout
24619
24620 \begin_layout LyX-Code
24621 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
24622 \end_layout
24623
24624 \begin_layout LyX-Code
24625 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
24626 \end_layout
24627
24628 \begin_layout LyX-Code
24629 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
24630 \end_layout
24631
24632 \begin_layout LyX-Code
24633 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
24634 \end_layout
24635
24636 \begin_layout LyX-Code
24637 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
24638 \end_layout
24639
24640 \begin_layout LyX-Code
24641 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
24642 \end_layout
24643
24644 \begin_layout LyX-Code
24645
24646 \end_layout
24647
24648 \begin_layout LyX-Code
24649 DATABANK   NAME=gpr0       START=0x80           END=0xFF
24650 \end_layout
24651
24652 \begin_layout LyX-Code
24653 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
24654 \end_layout
24655
24656 \begin_layout LyX-Code
24657 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
24658 \end_layout
24659
24660 \begin_layout LyX-Code
24661 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
24662 \end_layout
24663
24664 \begin_layout LyX-Code
24665 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
24666 \end_layout
24667
24668 \begin_layout LyX-Code
24669 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
24670 \end_layout
24671
24672 \begin_layout LyX-Code
24673 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
24674 \end_layout
24675
24676 \begin_layout LyX-Code
24677
24678 \end_layout
24679
24680 \begin_layout LyX-Code
24681 SECTION    NAME=CONFIG     ROM=config
24682 \end_layout
24683
24684 \begin_layout LyX-Code
24685
24686 \end_layout
24687
24688 \begin_layout LyX-Code
24689 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
24690 \end_layout
24691
24692 \begin_layout LyX-Code
24693 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
24694 \end_layout
24695
24696 \begin_layout LyX-Code
24697 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
24698 \end_layout
24699
24700 \begin_layout LyX-Code
24701 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
24702 \end_layout
24703
24704 \begin_layout LyX-Code
24705 SECTION    NAME=bank4      RAM=gpr4
24706 \end_layout
24707
24708 \begin_layout LyX-Code
24709 SECTION    NAME=bank5      RAM=gpr5
24710 \end_layout
24711
24712 \begin_layout Standard
24713 The linker will recognise the section name set in the pragma statement and
24714  will position the variable at the memory bank set with the RAM field at
24715  the SECTION line in the linker script file.
24716 \end_layout
24717
24718 \begin_layout Subsection
24719 Header Files
24720 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
24721
24722 \end_inset
24723
24724
24725 \end_layout
24726
24727 \begin_layout Standard
24728 There is one main header file
24729 \begin_inset LatexCommand \index{PIC16!Header files}
24730
24731 \end_inset
24732
24733  that can be included to the source files using the pic16
24734 \begin_inset LatexCommand \index{PIC16}
24735
24736 \end_inset
24737
24738  port.
24739  That file is the 
24740 \series bold
24741 pic18fregs.h
24742 \series default
24743 .
24744  This header file contains the definitions for the processor special registers,
24745  so it is necessary if the source accesses them.
24746  It can be included by adding the following line in the beginning of the
24747  file:
24748 \end_layout
24749
24750 \begin_layout LyX-Code
24751 #include <pic18fregs.h>
24752 \end_layout
24753
24754 \begin_layout Standard
24755 The specific microcontroller is selected within the pic18fregs.h automatically,
24756  so the same source can be used with a variety of devices.
24757 \end_layout
24758
24759 \begin_layout Subsection
24760 Libraries
24761 \end_layout
24762
24763 \begin_layout Standard
24764 The libraries
24765 \begin_inset LatexCommand \index{PIC16!Libraries}
24766
24767 \end_inset
24768
24769  that PIC16
24770 \begin_inset LatexCommand \index{PIC16}
24771
24772 \end_inset
24773
24774  port depends on are the microcontroller device libraries which contain
24775  the symbol definitions for the microcontroller special function registers.
24776  These libraries have the format pic18fxxxx.lib, where 
24777 \emph on
24778 xxxx
24779 \emph default
24780  is the microcontroller identification number.
24781  The specific library is selected automatically by the compiler at link
24782  stage according to the selected device.
24783 \end_layout
24784
24785 \begin_layout Standard
24786 Libraries are created with gplib which is part of the gputils package 
24787 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24788
24789 \end_inset
24790
24791 .
24792 \end_layout
24793
24794 \begin_layout Subsubsection*
24795 Building the libraries
24796 \end_layout
24797
24798 \begin_layout Standard
24799 Before using SDCC/pic16 there are some libraries that need to be compiled.
24800  This process is not done automatically by SDCC since not all users use
24801  SDCC for pic16 projects.
24802  So each user should compile the libraries separately.
24803 \end_layout
24804
24805 \begin_layout Standard
24806 The steps to compile the pic16 libraries under Linux and Mac OS X are:
24807 \end_layout
24808
24809 \begin_layout LyX-Code
24810 cd device/lib/pic16
24811 \end_layout
24812
24813 \begin_layout LyX-Code
24814 ./configure
24815 \end_layout
24816
24817 \begin_layout LyX-Code
24818 make
24819 \end_layout
24820
24821 \begin_layout LyX-Code
24822 cd ..
24823 \end_layout
24824
24825 \begin_layout LyX-Code
24826 make model-pic16
24827 \end_layout
24828
24829 \begin_layout LyX-Code
24830 su -c 'make install'     # install the libraries, you need the root password
24831 \end_layout
24832
24833 \begin_layout Standard
24834 If you need to install the headers too, do:
24835 \end_layout
24836
24837 \begin_layout LyX-Code
24838 cd device/include
24839 \end_layout
24840
24841 \begin_layout LyX-Code
24842 su -c 'make install'     # install the headers, you need the root password
24843 \end_layout
24844
24845 \begin_layout Standard
24846 There exist a special target to build the I/O libraries.
24847  This target is not automatically build because it will build the I/O library
24848  for 
24849 \emph on
24850 every
24851 \emph default
24852  supported device.
24853  This way building will take quite a lot of time.
24854  Users are advised to edit the 
24855 \series bold
24856 device/lib/pic16/pics.build
24857 \series default
24858  file and then execute:
24859 \end_layout
24860
24861 \begin_layout LyX-Code
24862 make lib-io
24863 \end_layout
24864
24865 \begin_layout Subsection
24866 Memory Models
24867 \end_layout
24868
24869 \begin_layout Standard
24870 The following memory models are supported by the PIC16 port:
24871 \end_layout
24872
24873 \begin_layout Itemize
24874 small model
24875 \end_layout
24876
24877 \begin_layout Itemize
24878 large model
24879 \end_layout
24880
24881 \begin_layout Standard
24882 Memory model affects the default size of pointers within the source.
24883  The sizes are shown in the next table:
24884 \end_layout
24885
24886 \begin_layout Standard
24887 \align center
24888 \begin_inset Tabular
24889 <lyxtabular version="3" rows="3" columns="3">
24890 <features>
24891 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24892 <column alignment="center" valignment="top" leftline="true" width="0">
24893 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24894 <row topline="true" bottomline="true">
24895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24896 \begin_inset Text
24897
24898 \begin_layout Standard
24899 Pointer sizes according to memory model
24900 \end_layout
24901
24902 \end_inset
24903 </cell>
24904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24905 \begin_inset Text
24906
24907 \begin_layout Standard
24908 small model
24909 \end_layout
24910
24911 \end_inset
24912 </cell>
24913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24914 \begin_inset Text
24915
24916 \begin_layout Standard
24917 large model
24918 \end_layout
24919
24920 \end_inset
24921 </cell>
24922 </row>
24923 <row topline="true" bottomline="true">
24924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24925 \begin_inset Text
24926
24927 \begin_layout Standard
24928 code pointers
24929 \end_layout
24930
24931 \end_inset
24932 </cell>
24933 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24934 \begin_inset Text
24935
24936 \begin_layout Standard
24937 16-bits
24938 \end_layout
24939
24940 \end_inset
24941 </cell>
24942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24943 \begin_inset Text
24944
24945 \begin_layout Standard
24946 24-bits
24947 \end_layout
24948
24949 \end_inset
24950 </cell>
24951 </row>
24952 <row topline="true" bottomline="true">
24953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24954 \begin_inset Text
24955
24956 \begin_layout Standard
24957 data pointers
24958 \end_layout
24959
24960 \end_inset
24961 </cell>
24962 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
24963 \begin_inset Text
24964
24965 \begin_layout Standard
24966 16-bits
24967 \end_layout
24968
24969 \end_inset
24970 </cell>
24971 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24972 \begin_inset Text
24973
24974 \begin_layout Standard
24975 16-bits
24976 \end_layout
24977
24978 \end_inset
24979 </cell>
24980 </row>
24981 </lyxtabular>
24982
24983 \end_inset
24984
24985
24986 \end_layout
24987
24988 \begin_layout Standard
24989 It is advisable that all sources within a project are compiled with the
24990  same memory model.
24991  If one wants to override the default memory model, this can be done by
24992  declaring a pointer as 
24993 \series bold
24994 far
24995 \series default
24996  or 
24997 \series bold
24998 near
24999 \series default
25000 .
25001  Far selects large memory model's pointers, while near selects small memory
25002  model's pointers.
25003 \end_layout
25004
25005 \begin_layout Standard
25006 The standard device libraries (see 
25007 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25008
25009 \end_inset
25010
25011 ) contain no reference to pointers, so they can be used with both memory
25012  models.
25013 \end_layout
25014
25015 \begin_layout Subsection
25016 Stack
25017 \end_layout
25018
25019 \begin_layout Standard
25020 The stack
25021 \begin_inset LatexCommand \index{PIC16!stack}
25022
25023 \end_inset
25024
25025  implementation for the PIC16 port uses two indirect registers, FSR1 and
25026  FSR2.
25027 \end_layout
25028
25029 \begin_layout List
25030 \labelwidthstring 00.00.0000
25031 FSR1 is assigned as stack pointer
25032 \end_layout
25033
25034 \begin_layout List
25035 \labelwidthstring 00.00.0000
25036 FSR2 is assigned as frame pointer
25037 \end_layout
25038
25039 \begin_layout Standard
25040 The following stack models are supported by the PIC16 port
25041 \end_layout
25042
25043 \begin_layout Itemize
25044
25045 \noun on
25046 small
25047 \noun default
25048  model
25049 \end_layout
25050
25051 \begin_layout Itemize
25052
25053 \noun on
25054 large
25055 \noun default
25056  model
25057 \end_layout
25058
25059 \begin_layout Standard
25060
25061 \noun on
25062 Small
25063 \noun default
25064  model means that only the FSRxL byte is used to access stack and frame,
25065  while 
25066 \emph on
25067 \noun on
25068 large
25069 \emph default
25070 \noun default
25071  uses both FSRxL and FSRxH registers.
25072  The following table shows the stack/frame pointers sizes according to stack
25073  model and the maximum space they can address:
25074 \end_layout
25075
25076 \begin_layout Standard
25077 \align center
25078 \begin_inset Tabular
25079 <lyxtabular version="3" rows="3" columns="3">
25080 <features>
25081 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25082 <column alignment="center" valignment="top" leftline="true" width="0">
25083 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25084 <row topline="true" bottomline="true">
25085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25086 \begin_inset Text
25087
25088 \begin_layout Standard
25089 Stack & Frame pointer sizes according to stack model
25090 \end_layout
25091
25092 \end_inset
25093 </cell>
25094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25095 \begin_inset Text
25096
25097 \begin_layout Standard
25098 small
25099 \end_layout
25100
25101 \end_inset
25102 </cell>
25103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25104 \begin_inset Text
25105
25106 \begin_layout Standard
25107 large
25108 \end_layout
25109
25110 \end_inset
25111 </cell>
25112 </row>
25113 <row topline="true">
25114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25115 \begin_inset Text
25116
25117 \begin_layout Standard
25118 Stack pointer FSR1
25119 \end_layout
25120
25121 \end_inset
25122 </cell>
25123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25124 \begin_inset Text
25125
25126 \begin_layout Standard
25127 8-bits
25128 \end_layout
25129
25130 \end_inset
25131 </cell>
25132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25133 \begin_inset Text
25134
25135 \begin_layout Standard
25136 16-bits
25137 \end_layout
25138
25139 \end_inset
25140 </cell>
25141 </row>
25142 <row topline="true" bottomline="true">
25143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25144 \begin_inset Text
25145
25146 \begin_layout Standard
25147 Frame pointer FSR2
25148 \end_layout
25149
25150 \end_inset
25151 </cell>
25152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25153 \begin_inset Text
25154
25155 \begin_layout Standard
25156 8-bits
25157 \end_layout
25158
25159 \end_inset
25160 </cell>
25161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25162 \begin_inset Text
25163
25164 \begin_layout Standard
25165 16-bits
25166 \end_layout
25167
25168 \end_inset
25169 </cell>
25170 </row>
25171 </lyxtabular>
25172
25173 \end_inset
25174
25175
25176 \end_layout
25177
25178 \begin_layout Standard
25179
25180 \noun on
25181 Large 
25182 \noun default
25183 stack model is currently not working properly throughout the code generator.
25184  So its use is not advised.
25185  Also there are some other points that need special care:
25186 \newline
25187
25188 \end_layout
25189
25190 \begin_layout Enumerate
25191 Do not create stack sections with size more than one physical bank (that
25192  is 256 bytes)
25193 \end_layout
25194
25195 \begin_layout Enumerate
25196 Stack sections should no cross physical bank limits (i.e.
25197  #pragma stack 0x50 0x100)
25198 \end_layout
25199
25200 \begin_layout Standard
25201 These limitations are caused by the fact that only FSRxL is modified when
25202  using SMALL stack model, so no more than 256 bytes of stack can be used.
25203  This problem will disappear after LARGE model is fully implemented.
25204 \end_layout
25205
25206 \begin_layout Subsection
25207 Functions
25208 \end_layout
25209
25210 \begin_layout Standard
25211 In addition to the standard SDCC function keywords, PIC16
25212 \begin_inset LatexCommand \index{PIC16}
25213
25214 \end_inset
25215
25216  port makes available two more:
25217 \end_layout
25218
25219 \begin_layout List
25220 \labelwidthstring 00.00.0000
25221 wparam
25222 \begin_inset LatexCommand \index{PIC16!wparam}
25223
25224 \end_inset
25225
25226  Use the WREG to pass one byte of the first function argument.
25227  This improves speed but you may not use this for functions with arguments
25228  that are called via function pointers, otherwise the first byte of the
25229  first parameter will get lost.
25230  Usage:
25231 \end_layout
25232
25233 \begin_layout LyX-Code
25234 void func_wparam(int a) wparam
25235 \end_layout
25236
25237 \begin_layout LyX-Code
25238 {
25239 \end_layout
25240
25241 \begin_layout LyX-Code
25242     /* WREG hold the lower part of a */
25243 \end_layout
25244
25245 \begin_layout LyX-Code
25246     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25247  */
25248 \end_layout
25249
25250 \begin_layout LyX-Code
25251 ...
25252 \end_layout
25253
25254 \begin_layout LyX-Code
25255 }
25256 \end_layout
25257
25258 \begin_layout List
25259 \labelwidthstring 00.00.0000
25260 shadowregs
25261 \begin_inset LatexCommand \index{PIC16!shadowregs}
25262
25263 \end_inset
25264
25265  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25266  hardware shadow registers which hold the values of WREG, STATUS and BSR
25267  registers.
25268  This can be done by adding the keyword 
25269 \emph on
25270 shadowregs
25271 \emph default
25272  before the 
25273 \emph on
25274 interrupt
25275 \emph default
25276  keyword in the function's header.
25277 \end_layout
25278
25279 \begin_layout LyX-Code
25280 void isr_shadow(void) shadowregs interrupt 1
25281 \end_layout
25282
25283 \begin_layout LyX-Code
25284 {
25285 \end_layout
25286
25287 \begin_layout LyX-Code
25288 ...
25289 \end_layout
25290
25291 \begin_layout LyX-Code
25292 }
25293 \end_layout
25294
25295 \begin_layout Standard
25296
25297 \emph on
25298 shadowregs
25299 \emph default
25300  instructs the code generator not to store/restore WREG, STATUS, BSR when
25301  entering/exiting the ISR.
25302 \end_layout
25303
25304 \begin_layout Subsection
25305 Function return values
25306 \end_layout
25307
25308 \begin_layout Standard
25309 Return values from functions are placed to the appropriate registers following
25310  a modified Microchip policy optimized for SDCC.
25311  The following table shows these registers:
25312 \end_layout
25313
25314 \begin_layout Standard
25315 \align center
25316 \begin_inset Tabular
25317 <lyxtabular version="3" rows="6" columns="2">
25318 <features>
25319 <column alignment="center" valignment="top" leftline="true" width="0">
25320 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
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 size
25327 \end_layout
25328
25329 \end_inset
25330 </cell>
25331 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25332 \begin_inset Text
25333
25334 \begin_layout Standard
25335 destination register
25336 \end_layout
25337
25338 \end_inset
25339 </cell>
25340 </row>
25341 <row topline="true">
25342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25343 \begin_inset Text
25344
25345 \begin_layout Standard
25346 8 bits
25347 \end_layout
25348
25349 \end_inset
25350 </cell>
25351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25352 \begin_inset Text
25353
25354 \begin_layout Standard
25355 WREG
25356 \end_layout
25357
25358 \end_inset
25359 </cell>
25360 </row>
25361 <row topline="true">
25362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25363 \begin_inset Text
25364
25365 \begin_layout Standard
25366 16 bits
25367 \end_layout
25368
25369 \end_inset
25370 </cell>
25371 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25372 \begin_inset Text
25373
25374 \begin_layout Standard
25375 PRODL:WREG
25376 \end_layout
25377
25378 \end_inset
25379 </cell>
25380 </row>
25381 <row topline="true">
25382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25383 \begin_inset Text
25384
25385 \begin_layout Standard
25386 24 bits
25387 \end_layout
25388
25389 \end_inset
25390 </cell>
25391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25392 \begin_inset Text
25393
25394 \begin_layout Standard
25395 PRODH:PRODL:WREG
25396 \end_layout
25397
25398 \end_inset
25399 </cell>
25400 </row>
25401 <row topline="true">
25402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25403 \begin_inset Text
25404
25405 \begin_layout Standard
25406 32 bits
25407 \end_layout
25408
25409 \end_inset
25410 </cell>
25411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25412 \begin_inset Text
25413
25414 \begin_layout Standard
25415 FSR0L:PRODH:PRODL:WREG
25416 \end_layout
25417
25418 \end_inset
25419 </cell>
25420 </row>
25421 <row topline="true" bottomline="true">
25422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25423 \begin_inset Text
25424
25425 \begin_layout Standard
25426 >32 bits
25427 \end_layout
25428
25429 \end_inset
25430 </cell>
25431 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25432 \begin_inset Text
25433
25434 \begin_layout Standard
25435 on stack, FSR0 points to the beginning
25436 \end_layout
25437
25438 \end_inset
25439 </cell>
25440 </row>
25441 </lyxtabular>
25442
25443 \end_inset
25444
25445
25446 \end_layout
25447
25448 \begin_layout Subsection
25449 Interrupts
25450 \end_layout
25451
25452 \begin_layout Standard
25453 An interrupt
25454 \begin_inset LatexCommand \index{PIC16!interrupt}
25455
25456 \end_inset
25457
25458  service routine (ISR) is declared using the 
25459 \emph on
25460 interrupt
25461 \emph default
25462  keyword.
25463 \end_layout
25464
25465 \begin_layout LyX-Code
25466 void isr(void) interrupt 
25467 \emph on
25468 n
25469 \end_layout
25470
25471 \begin_layout LyX-Code
25472 {
25473 \end_layout
25474
25475 \begin_layout LyX-Code
25476 ...
25477 \end_layout
25478
25479 \begin_layout LyX-Code
25480 }
25481 \end_layout
25482
25483 \begin_layout Standard
25484
25485 \emph on
25486 n
25487 \emph default
25488  is the interrupt number, which for PIC18F devices can be:
25489 \end_layout
25490
25491 \begin_layout Standard
25492 \align center
25493 \begin_inset Tabular
25494 <lyxtabular version="3" rows="4" columns="3">
25495 <features>
25496 <column alignment="center" valignment="top" leftline="true" width="0">
25497 <column alignment="center" valignment="top" leftline="true" width="0">
25498 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25499 <row topline="true" bottomline="true">
25500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25501 \begin_inset Text
25502
25503 \begin_layout Standard
25504
25505 \emph on
25506 n
25507 \end_layout
25508
25509 \end_inset
25510 </cell>
25511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25512 \begin_inset Text
25513
25514 \begin_layout Standard
25515 Interrupt Vector
25516 \end_layout
25517
25518 \end_inset
25519 </cell>
25520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25521 \begin_inset Text
25522
25523 \begin_layout Standard
25524 Interrupt Vector Address
25525 \end_layout
25526
25527 \end_inset
25528 </cell>
25529 </row>
25530 <row topline="true">
25531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25532 \begin_inset Text
25533
25534 \begin_layout Standard
25535 0
25536 \end_layout
25537
25538 \end_inset
25539 </cell>
25540 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25541 \begin_inset Text
25542
25543 \begin_layout Standard
25544 RESET vector
25545 \end_layout
25546
25547 \end_inset
25548 </cell>
25549 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25550 \begin_inset Text
25551
25552 \begin_layout Standard
25553 0x000000
25554 \end_layout
25555
25556 \end_inset
25557 </cell>
25558 </row>
25559 <row topline="true">
25560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25561 \begin_inset Text
25562
25563 \begin_layout Standard
25564
25565 \family roman
25566 \series medium
25567 \shape up
25568 \size normal
25569 \emph off
25570 \bar no
25571 \noun off
25572 \color none
25573 1
25574 \end_layout
25575
25576 \end_inset
25577 </cell>
25578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25579 \begin_inset Text
25580
25581 \begin_layout Standard
25582
25583 \family roman
25584 \series medium
25585 \shape up
25586 \size normal
25587 \emph off
25588 \bar no
25589 \noun off
25590 \color none
25591 HIGH priority interrupts
25592 \end_layout
25593
25594 \end_inset
25595 </cell>
25596 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25597 \begin_inset Text
25598
25599 \begin_layout Standard
25600 0x000008
25601 \end_layout
25602
25603 \end_inset
25604 </cell>
25605 </row>
25606 <row topline="true" bottomline="true">
25607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25608 \begin_inset Text
25609
25610 \begin_layout Standard
25611 2
25612 \end_layout
25613
25614 \end_inset
25615 </cell>
25616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25617 \begin_inset Text
25618
25619 \begin_layout Standard
25620 LOW priority interrupts
25621 \end_layout
25622
25623 \end_inset
25624 </cell>
25625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25626 \begin_inset Text
25627
25628 \begin_layout Standard
25629 0x000018
25630 \end_layout
25631
25632 \end_inset
25633 </cell>
25634 </row>
25635 </lyxtabular>
25636
25637 \end_inset
25638
25639
25640 \end_layout
25641
25642 \begin_layout Standard
25643 When generating assembly code for ISR the code generator places a 
25644 \noun on
25645 goto 
25646 \noun default
25647 instruction at the 
25648 \emph on
25649 Interrupt Vector Address
25650 \emph default
25651  which points at the genetated ISR.
25652  This single GOTO instruction is part of an automatically generated 
25653 \emph on
25654 interrupt entry point
25655 \emph default
25656  function.
25657  The actuall ISR code is placed as normally would in the code space.
25658  Upon interrupt request, the GOTO instruction is executed which jumps to
25659  the ISR code.
25660  When declaring interrupt functions as _naked this GOTO instruction is 
25661 \series bold
25662 not
25663 \series default
25664  generated.
25665  The whole interrupt functions is therefore placed at the Interrupt Vector
25666  Address of the specific interrupt.
25667  This is not a problem for the LOW priority interrupts, but it is a problem
25668  for the RESET and the HIGH priority interrupts because code may be written
25669  at the next interrupt´s vector address and cause undeterminate program
25670  behaviour if that interrupt is raised.
25671 \begin_inset Foot
25672 status open
25673
25674 \begin_layout Standard
25675 This is not a problem when
25676 \end_layout
25677
25678 \begin_layout Enumerate
25679 this is a HIGH interrupt ISR and LOW interrupts are 
25680 \emph on
25681 disabled
25682 \emph default
25683  or not used.
25684 \end_layout
25685
25686 \begin_layout Enumerate
25687 when the ISR is small enough not to reach the next interrupt´s vector address.
25688 \end_layout
25689
25690 \end_inset
25691
25692
25693 \end_layout
25694
25695 \begin_layout Standard
25696
25697 \emph on
25698 n
25699 \emph default
25700  is possible to be omitted.
25701  This way a function is generated similar to an ISR, but it is not assigned
25702  to any interrupt.
25703 \end_layout
25704
25705 \begin_layout Standard
25706 When entering an interrupt, currently the PIC16
25707 \begin_inset LatexCommand \index{PIC16}
25708
25709 \end_inset
25710
25711  port automatically saves the following registers:
25712 \end_layout
25713
25714 \begin_layout Itemize
25715 WREG
25716 \end_layout
25717
25718 \begin_layout Itemize
25719 STATUS
25720 \end_layout
25721
25722 \begin_layout Itemize
25723 BSR
25724 \end_layout
25725
25726 \begin_layout Itemize
25727 PROD (PRODL and PRODH)
25728 \end_layout
25729
25730 \begin_layout Itemize
25731 FSR0 (FSR0L and FSR0H)
25732 \end_layout
25733
25734 \begin_layout Standard
25735 These registers are restored upon return from the interrupt routine.
25736 \begin_inset Foot
25737 status open
25738
25739 \begin_layout Standard
25740 NOTE that when the _naked attribute is specified for an interrupt routine,
25741  then NO registers are stored or restored.
25742 \end_layout
25743
25744 \end_inset
25745
25746
25747 \end_layout
25748
25749 \begin_layout Subsection
25750 Generic Pointers
25751 \end_layout
25752
25753 \begin_layout Standard
25754 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
25755  There are 3 types of generic pointers currently implemented data, code
25756  and eeprom pointers.
25757  They are differentiated by the value of the 7th and 6th bits of the upper
25758  byte:
25759 \end_layout
25760
25761 \begin_layout Standard
25762 \align center
25763 \begin_inset Tabular
25764 <lyxtabular version="3" rows="5" columns="5">
25765 <features>
25766 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25767 <column alignment="center" valignment="top" width="0">
25768 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25769 <column alignment="center" valignment="top" width="0">
25770 <column alignment="left" valignment="top" rightline="true" width="0">
25771 <row topline="true" bottomline="true">
25772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25773 \begin_inset Text
25774
25775 \begin_layout Standard
25776 pointer type
25777 \end_layout
25778
25779 \end_inset
25780 </cell>
25781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25782 \begin_inset Text
25783
25784 \begin_layout Standard
25785 7th bit
25786 \end_layout
25787
25788 \end_inset
25789 </cell>
25790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25791 \begin_inset Text
25792
25793 \begin_layout Standard
25794 6th bit
25795 \end_layout
25796
25797 \end_inset
25798 </cell>
25799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25800 \begin_inset Text
25801
25802 \begin_layout Standard
25803 rest of the pointer
25804 \end_layout
25805
25806 \end_inset
25807 </cell>
25808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25809 \begin_inset Text
25810
25811 \begin_layout Standard
25812 description
25813 \end_layout
25814
25815 \end_inset
25816 </cell>
25817 </row>
25818 <row topline="true" bottomline="true">
25819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25820 \begin_inset Text
25821
25822 \begin_layout Standard
25823 data 
25824 \end_layout
25825
25826 \end_inset
25827 </cell>
25828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25829 \begin_inset Text
25830
25831 \begin_layout Standard
25832 1
25833 \end_layout
25834
25835 \end_inset
25836 </cell>
25837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25838 \begin_inset Text
25839
25840 \begin_layout Standard
25841 0
25842 \end_layout
25843
25844 \end_inset
25845 </cell>
25846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25847 \begin_inset Text
25848
25849 \begin_layout Standard
25850
25851 \family typewriter
25852 \shape slanted
25853 \emph on
25854 uuuuuu uuuuxxxx xxxxxxxx
25855 \end_layout
25856
25857 \end_inset
25858 </cell>
25859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25860 \begin_inset Text
25861
25862 \begin_layout Standard
25863 a 12-bit data pointer in data RAM memory
25864 \end_layout
25865
25866 \end_inset
25867 </cell>
25868 </row>
25869 <row bottomline="true">
25870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25871 \begin_inset Text
25872
25873 \begin_layout Standard
25874 code
25875 \end_layout
25876
25877 \end_inset
25878 </cell>
25879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25880 \begin_inset Text
25881
25882 \begin_layout Standard
25883 0
25884 \end_layout
25885
25886 \end_inset
25887 </cell>
25888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25889 \begin_inset Text
25890
25891 \begin_layout Standard
25892 0
25893 \end_layout
25894
25895 \end_inset
25896 </cell>
25897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25898 \begin_inset Text
25899
25900 \begin_layout Standard
25901
25902 \family typewriter
25903 \shape slanted
25904 \emph on
25905 uxxxxx xxxxxxxx xxxxxxxx
25906 \end_layout
25907
25908 \end_inset
25909 </cell>
25910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25911 \begin_inset Text
25912
25913 \begin_layout Standard
25914 a 21-bit code pointer in FLASH memory
25915 \end_layout
25916
25917 \end_inset
25918 </cell>
25919 </row>
25920 <row bottomline="true">
25921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25922 \begin_inset Text
25923
25924 \begin_layout Standard
25925 eeprom
25926 \end_layout
25927
25928 \end_inset
25929 </cell>
25930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25931 \begin_inset Text
25932
25933 \begin_layout Standard
25934 0
25935 \end_layout
25936
25937 \end_inset
25938 </cell>
25939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25940 \begin_inset Text
25941
25942 \begin_layout Standard
25943 1
25944 \end_layout
25945
25946 \end_inset
25947 </cell>
25948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25949 \begin_inset Text
25950
25951 \begin_layout Standard
25952
25953 \family typewriter
25954 \shape slanted
25955 \emph on
25956 uuuuuu uuuuuuxx xxxxxxxx
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 a 10-bit eeprom pointer in EEPROM memory
25966 \end_layout
25967
25968 \end_inset
25969 </cell>
25970 </row>
25971 <row bottomline="true">
25972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25973 \begin_inset Text
25974
25975 \begin_layout Standard
25976 (unimplemented)
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 1
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 1
25995 \end_layout
25996
25997 \end_inset
25998 </cell>
25999 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26000 \begin_inset Text
26001
26002 \begin_layout Standard
26003
26004 \family typewriter
26005 \shape slanted
26006 \emph on
26007 xxxxxx xxxxxxxx xxxxxxxx
26008 \end_layout
26009
26010 \end_inset
26011 </cell>
26012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26013 \begin_inset Text
26014
26015 \begin_layout Standard
26016 unimplemented pointer type
26017 \end_layout
26018
26019 \end_inset
26020 </cell>
26021 </row>
26022 </lyxtabular>
26023
26024 \end_inset
26025
26026
26027 \end_layout
26028
26029 \begin_layout Standard
26030 Generic pointer are read and written with a set of library functions which
26031  read/write 1, 2, 3, 4 bytes.
26032 \end_layout
26033
26034 \begin_layout Subsection
26035 PIC16 C Libraries
26036 \end_layout
26037
26038 \begin_layout Subsubsection
26039 Standard I/O Streams
26040 \end_layout
26041
26042 \begin_layout Standard
26043 In the 
26044 \emph on
26045 stdio.h
26046 \emph default
26047  the type FILE is defined as:
26048 \end_layout
26049
26050 \begin_layout LyX-Code
26051 typedef char * FILE;
26052 \end_layout
26053
26054 \begin_layout Standard
26055 This type is the stream type implemented I/O in the PIC18F devices.
26056  Also the standard input and output streams are declared in stdio.h:
26057 \end_layout
26058
26059 \begin_layout LyX-Code
26060 extern FILE * stdin;
26061 \end_layout
26062
26063 \begin_layout LyX-Code
26064 extern FILE * stdout;
26065 \end_layout
26066
26067 \begin_layout Standard
26068 The FILE type is actually a generic pointer which defines one more type
26069  of generic pointers, the 
26070 \emph on
26071 stream 
26072 \emph default
26073 pointer.
26074  This new type has the format:
26075 \end_layout
26076
26077 \begin_layout Standard
26078 \align center
26079 \begin_inset Tabular
26080 <lyxtabular version="3" rows="2" columns="7">
26081 <features>
26082 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26083 <column alignment="center" valignment="top" width="0">
26084 <column alignment="center" valignment="top" leftline="true" width="0">
26085 <column alignment="center" valignment="top" leftline="true" width="0">
26086 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26087 <column alignment="center" valignment="top" width="0">
26088 <column alignment="left" valignment="top" rightline="true" width="0">
26089 <row topline="true" bottomline="true">
26090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26091 \begin_inset Text
26092
26093 \begin_layout Standard
26094 pointer type
26095 \end_layout
26096
26097 \end_inset
26098 </cell>
26099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26100 \begin_inset Text
26101
26102 \begin_layout Standard
26103 <7:6>
26104 \end_layout
26105
26106 \end_inset
26107 </cell>
26108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26109 \begin_inset Text
26110
26111 \begin_layout Standard
26112 <5>
26113 \end_layout
26114
26115 \end_inset
26116 </cell>
26117 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26118 \begin_inset Text
26119
26120 \begin_layout Standard
26121 <4>
26122 \end_layout
26123
26124 \end_inset
26125 </cell>
26126 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26127 \begin_inset Text
26128
26129 \begin_layout Standard
26130 <3:0>
26131 \end_layout
26132
26133 \end_inset
26134 </cell>
26135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26136 \begin_inset Text
26137
26138 \begin_layout Standard
26139 rest of the pointer
26140 \end_layout
26141
26142 \end_inset
26143 </cell>
26144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26145 \begin_inset Text
26146
26147 \begin_layout Standard
26148 descrption
26149 \end_layout
26150
26151 \end_inset
26152 </cell>
26153 </row>
26154 <row topline="true" bottomline="true">
26155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26156 \begin_inset Text
26157
26158 \begin_layout Standard
26159 stream
26160 \end_layout
26161
26162 \end_inset
26163 </cell>
26164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26165 \begin_inset Text
26166
26167 \begin_layout Standard
26168 00
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 1
26178 \end_layout
26179
26180 \end_inset
26181 </cell>
26182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26183 \begin_inset Text
26184
26185 \begin_layout Standard
26186 0
26187 \end_layout
26188
26189 \end_inset
26190 </cell>
26191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26192 \begin_inset Text
26193
26194 \begin_layout Standard
26195 nnnn
26196 \end_layout
26197
26198 \end_inset
26199 </cell>
26200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26201 \begin_inset Text
26202
26203 \begin_layout Standard
26204
26205 \family typewriter
26206 \shape slanted
26207 \emph on
26208 uuuuuuuu uuuuuuuu
26209 \end_layout
26210
26211 \end_inset
26212 </cell>
26213 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26214 \begin_inset Text
26215
26216 \begin_layout Standard
26217 upper byte high nubble is 0x2n, the rest are zeroes
26218 \end_layout
26219
26220 \end_inset
26221 </cell>
26222 </row>
26223 </lyxtabular>
26224
26225 \end_inset
26226
26227
26228 \end_layout
26229
26230 \begin_layout Standard
26231 Currently implemented there are 3 types of streams defined:
26232 \end_layout
26233
26234 \begin_layout Standard
26235 \align center
26236 \begin_inset Tabular
26237 <lyxtabular version="3" rows="4" columns="4">
26238 <features>
26239 <column alignment="center" valignment="top" leftline="true" width="0">
26240 <column alignment="center" valignment="top" leftline="true" width="0">
26241 <column alignment="center" valignment="top" leftline="true" width="0">
26242 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26243 <row topline="true" bottomline="true">
26244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26245 \begin_inset Text
26246
26247 \begin_layout Standard
26248 stream type
26249 \end_layout
26250
26251 \end_inset
26252 </cell>
26253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26254 \begin_inset Text
26255
26256 \begin_layout Standard
26257 value
26258 \end_layout
26259
26260 \end_inset
26261 </cell>
26262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26263 \begin_inset Text
26264
26265 \begin_layout Standard
26266 module
26267 \end_layout
26268
26269 \end_inset
26270 </cell>
26271 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26272 \begin_inset Text
26273
26274 \begin_layout Standard
26275 description
26276 \end_layout
26277
26278 \end_inset
26279 </cell>
26280 </row>
26281 <row topline="true">
26282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26283 \begin_inset Text
26284
26285 \begin_layout Standard
26286 STREAM_USART
26287 \end_layout
26288
26289 \end_inset
26290 </cell>
26291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26292 \begin_inset Text
26293
26294 \begin_layout Standard
26295
26296 \family typewriter
26297 0x200000UL
26298 \end_layout
26299
26300 \end_inset
26301 </cell>
26302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26303 \begin_inset Text
26304
26305 \begin_layout Standard
26306 USART
26307 \end_layout
26308
26309 \end_inset
26310 </cell>
26311 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26312 \begin_inset Text
26313
26314 \begin_layout Standard
26315 Writes/Reads characters via the USART peripheral
26316 \end_layout
26317
26318 \end_inset
26319 </cell>
26320 </row>
26321 <row topline="true">
26322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26323 \begin_inset Text
26324
26325 \begin_layout Standard
26326 STREAM_MSSP
26327 \end_layout
26328
26329 \end_inset
26330 </cell>
26331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26332 \begin_inset Text
26333
26334 \begin_layout Standard
26335
26336 \family typewriter
26337 0x210000UL
26338 \end_layout
26339
26340 \end_inset
26341 </cell>
26342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26343 \begin_inset Text
26344
26345 \begin_layout Standard
26346 MSSP
26347 \end_layout
26348
26349 \end_inset
26350 </cell>
26351 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26352 \begin_inset Text
26353
26354 \begin_layout Standard
26355 Writes/Reads characters via the MSSP peripheral
26356 \end_layout
26357
26358 \end_inset
26359 </cell>
26360 </row>
26361 <row topline="true" bottomline="true">
26362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26363 \begin_inset Text
26364
26365 \begin_layout Standard
26366 STREAM_USER
26367 \end_layout
26368
26369 \end_inset
26370 </cell>
26371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26372 \begin_inset Text
26373
26374 \begin_layout Standard
26375
26376 \family typewriter
26377 0x2f0000UL
26378 \end_layout
26379
26380 \end_inset
26381 </cell>
26382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26383 \begin_inset Text
26384
26385 \begin_layout Standard
26386 (none)
26387 \end_layout
26388
26389 \end_inset
26390 </cell>
26391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26392 \begin_inset Text
26393
26394 \begin_layout Standard
26395 Writes/Reads characters via used defined functions
26396 \end_layout
26397
26398 \end_inset
26399 </cell>
26400 </row>
26401 </lyxtabular>
26402
26403 \end_inset
26404
26405
26406 \end_layout
26407
26408 \begin_layout Standard
26409 The stream identifiers are declared as macros in the stdio.h header.
26410 \end_layout
26411
26412 \begin_layout Standard
26413 In the libc library there exist the functions that are used to write to
26414  each of the above streams.
26415  These are
26416 \end_layout
26417
26418 \begin_layout List
26419 \labelwidthstring 00.00.0000
26420 _
26421 \begin_inset ERT
26422 status collapsed
26423
26424 \begin_layout Standard
26425
26426
26427 \backslash
26428 /
26429 \end_layout
26430
26431 \end_inset
26432
26433 _stream_usart_putchar writes a character at the USART stream
26434 \end_layout
26435
26436 \begin_layout List
26437 \labelwidthstring 00.00.0000
26438 _
26439 \begin_inset ERT
26440 status collapsed
26441
26442 \begin_layout Standard
26443
26444
26445 \backslash
26446 /
26447 \end_layout
26448
26449 \end_inset
26450
26451 _stream_mssp_putchar writes a character at the MSSP stream
26452 \end_layout
26453
26454 \begin_layout List
26455 \labelwidthstring 00.00.0000
26456 putchar dummy function.
26457  This writes a character to a user specified manner.
26458 \end_layout
26459
26460 \begin_layout Standard
26461 In order to increase performance 
26462 \emph on
26463 putchar 
26464 \emph default
26465 is declared in stdio.h as having its parameter in WREG (it has the wparam
26466  keyword).
26467  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
26468  in a user-friendly way.
26469  
26470 \emph on
26471 arg
26472 \emph default
26473  is the name of the variable that holds the character to print.
26474  An example follows:
26475 \end_layout
26476
26477 \begin_layout LyX-Code
26478 #include <pic18fregs.h>
26479 \newline
26480 #include <stdio.h>
26481 \newline
26482
26483 \newline
26484 PUTCHAR( c )
26485 \end_layout
26486
26487 \begin_layout LyX-Code
26488 {
26489 \end_layout
26490
26491 \begin_layout LyX-Code
26492     PORTA = c;    /* dump character c to PORTA */
26493 \end_layout
26494
26495 \begin_layout LyX-Code
26496
26497 \newline
26498
26499 \newline
26500 void main(void)
26501 \end_layout
26502
26503 \begin_layout LyX-Code
26504 {
26505 \end_layout
26506
26507 \begin_layout LyX-Code
26508     stdout = STREAM_USER;    /* this is not necessary, since stdout points
26509 \end_layout
26510
26511 \begin_layout LyX-Code
26512                               * by default to STREAM_USER */
26513 \end_layout
26514
26515 \begin_layout LyX-Code
26516     printf (¨This is a printf test
26517 \backslash
26518 n¨);
26519 \end_layout
26520
26521 \begin_layout LyX-Code
26522 }
26523 \end_layout
26524
26525 \begin_layout LyX-Code
26526
26527 \end_layout
26528
26529 \begin_layout Subsubsection
26530 Printing functions
26531 \end_layout
26532
26533 \begin_layout Standard
26534 PIC16 contains an implementation of the printf-family of functions.
26535  There exist the following functions:
26536 \end_layout
26537
26538 \begin_layout LyX-Code
26539 extern unsigned int sprintf(char *buf, char *fmt, ...);
26540 \end_layout
26541
26542 \begin_layout LyX-Code
26543 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
26544 \end_layout
26545
26546 \begin_layout LyX-Code
26547
26548 \end_layout
26549
26550 \begin_layout LyX-Code
26551 extern unsigned int printf(char *fmt, ...);
26552 \end_layout
26553
26554 \begin_layout LyX-Code
26555 extern unsigned int vprintf(char *fmt, va_lista ap);
26556 \end_layout
26557
26558 \begin_layout LyX-Code
26559
26560 \end_layout
26561
26562 \begin_layout LyX-Code
26563 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
26564 \end_layout
26565
26566 \begin_layout LyX-Code
26567 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
26568 \end_layout
26569
26570 \begin_layout Standard
26571 For sprintf and vsprintf 
26572 \emph on
26573 buf 
26574 \emph default
26575 should normally be a data pointer where the resulting string will be placed.
26576  No range checking is done so the user should allocate the necessery buffer.
26577  For fprintf and vfprintf 
26578 \emph on
26579 fp
26580 \emph default
26581  should be a stream pointer (i.e.
26582  stdout, STREAM_MSSP, etc...).
26583 \end_layout
26584
26585 \begin_layout Subsubsection
26586 Signals
26587 \end_layout
26588
26589 \begin_layout Standard
26590 The PIC18F family of microcontrollers supports a number of interrupt sources.
26591  A list of these interrupts is shown in the following table:
26592 \end_layout
26593
26594 \begin_layout Standard
26595 \align center
26596 \begin_inset Tabular
26597 <lyxtabular version="3" rows="11" columns="4">
26598 <features>
26599 <column alignment="left" valignment="top" leftline="true" width="0">
26600 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26601 <column alignment="left" valignment="top" leftline="true" width="0">
26602 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26603 <row topline="true" bottomline="true">
26604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26605 \begin_inset Text
26606
26607 \begin_layout Standard
26608 signal name
26609 \end_layout
26610
26611 \end_inset
26612 </cell>
26613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26614 \begin_inset Text
26615
26616 \begin_layout Standard
26617 description
26618 \end_layout
26619
26620 \end_inset
26621 </cell>
26622 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26623 \begin_inset Text
26624
26625 \begin_layout Standard
26626 signal name
26627 \end_layout
26628
26629 \end_inset
26630 </cell>
26631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26632 \begin_inset Text
26633
26634 \begin_layout Standard
26635 descritpion
26636 \end_layout
26637
26638 \end_inset
26639 </cell>
26640 </row>
26641 <row topline="true">
26642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26643 \begin_inset Text
26644
26645 \begin_layout Standard
26646 SIG_RB
26647 \end_layout
26648
26649 \end_inset
26650 </cell>
26651 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26652 \begin_inset Text
26653
26654 \begin_layout Standard
26655 PORTB change interrupt
26656 \end_layout
26657
26658 \end_inset
26659 </cell>
26660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26661 \begin_inset Text
26662
26663 \begin_layout Standard
26664 SIG_EE
26665 \end_layout
26666
26667 \end_inset
26668 </cell>
26669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26670 \begin_inset Text
26671
26672 \begin_layout Standard
26673 EEPROM/FLASH write complete interrupt
26674 \end_layout
26675
26676 \end_inset
26677 </cell>
26678 </row>
26679 <row topline="true">
26680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26681 \begin_inset Text
26682
26683 \begin_layout Standard
26684 SIG_INT0
26685 \end_layout
26686
26687 \end_inset
26688 </cell>
26689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26690 \begin_inset Text
26691
26692 \begin_layout Standard
26693 INT0 external interrupt
26694 \end_layout
26695
26696 \end_inset
26697 </cell>
26698 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26699 \begin_inset Text
26700
26701 \begin_layout Standard
26702 SIG_BCOL
26703 \end_layout
26704
26705 \end_inset
26706 </cell>
26707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26708 \begin_inset Text
26709
26710 \begin_layout Standard
26711 Bus collision interrupt
26712 \end_layout
26713
26714 \end_inset
26715 </cell>
26716 </row>
26717 <row topline="true">
26718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26719 \begin_inset Text
26720
26721 \begin_layout Standard
26722 SIG_INT1
26723 \end_layout
26724
26725 \end_inset
26726 </cell>
26727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26728 \begin_inset Text
26729
26730 \begin_layout Standard
26731 INT1 external interrupt
26732 \end_layout
26733
26734 \end_inset
26735 </cell>
26736 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26737 \begin_inset Text
26738
26739 \begin_layout Standard
26740 SIG_LVD
26741 \end_layout
26742
26743 \end_inset
26744 </cell>
26745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26746 \begin_inset Text
26747
26748 \begin_layout Standard
26749 Low voltage detect interrupt
26750 \end_layout
26751
26752 \end_inset
26753 </cell>
26754 </row>
26755 <row topline="true">
26756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26757 \begin_inset Text
26758
26759 \begin_layout Standard
26760 SIG_INT2
26761 \end_layout
26762
26763 \end_inset
26764 </cell>
26765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26766 \begin_inset Text
26767
26768 \begin_layout Standard
26769 INT2 external interrupt
26770 \end_layout
26771
26772 \end_inset
26773 </cell>
26774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26775 \begin_inset Text
26776
26777 \begin_layout Standard
26778 SIG_PSP
26779 \end_layout
26780
26781 \end_inset
26782 </cell>
26783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26784 \begin_inset Text
26785
26786 \begin_layout Standard
26787 Parallel slave port interrupt
26788 \end_layout
26789
26790 \end_inset
26791 </cell>
26792 </row>
26793 <row topline="true">
26794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26795 \begin_inset Text
26796
26797 \begin_layout Standard
26798 SIG_CCP1
26799 \end_layout
26800
26801 \end_inset
26802 </cell>
26803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26804 \begin_inset Text
26805
26806 \begin_layout Standard
26807 CCP1 module interrupt
26808 \end_layout
26809
26810 \end_inset
26811 </cell>
26812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26813 \begin_inset Text
26814
26815 \begin_layout Standard
26816 SIG_AD
26817 \end_layout
26818
26819 \end_inset
26820 </cell>
26821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26822 \begin_inset Text
26823
26824 \begin_layout Standard
26825 AD convertion complete interrupt
26826 \end_layout
26827
26828 \end_inset
26829 </cell>
26830 </row>
26831 <row topline="true">
26832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26833 \begin_inset Text
26834
26835 \begin_layout Standard
26836 SIG_CCP2
26837 \end_layout
26838
26839 \end_inset
26840 </cell>
26841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26842 \begin_inset Text
26843
26844 \begin_layout Standard
26845 CCP2 module interrupt
26846 \end_layout
26847
26848 \end_inset
26849 </cell>
26850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26851 \begin_inset Text
26852
26853 \begin_layout Standard
26854 SIG_RC
26855 \end_layout
26856
26857 \end_inset
26858 </cell>
26859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26860 \begin_inset Text
26861
26862 \begin_layout Standard
26863 USART receive interrupt
26864 \end_layout
26865
26866 \end_inset
26867 </cell>
26868 </row>
26869 <row topline="true">
26870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26871 \begin_inset Text
26872
26873 \begin_layout Standard
26874 SIG_TMR0
26875 \end_layout
26876
26877 \end_inset
26878 </cell>
26879 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26880 \begin_inset Text
26881
26882 \begin_layout Standard
26883 TMR0 overflow interrupt
26884 \end_layout
26885
26886 \end_inset
26887 </cell>
26888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26889 \begin_inset Text
26890
26891 \begin_layout Standard
26892 SIG_TX
26893 \end_layout
26894
26895 \end_inset
26896 </cell>
26897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26898 \begin_inset Text
26899
26900 \begin_layout Standard
26901 USART transmit interrupt
26902 \end_layout
26903
26904 \end_inset
26905 </cell>
26906 </row>
26907 <row topline="true">
26908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26909 \begin_inset Text
26910
26911 \begin_layout Standard
26912 SIG_TMR1
26913 \end_layout
26914
26915 \end_inset
26916 </cell>
26917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26918 \begin_inset Text
26919
26920 \begin_layout Standard
26921 TMR1 overflow interrupt
26922 \end_layout
26923
26924 \end_inset
26925 </cell>
26926 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26927 \begin_inset Text
26928
26929 \begin_layout Standard
26930 SIG_MSSP
26931 \end_layout
26932
26933 \end_inset
26934 </cell>
26935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26936 \begin_inset Text
26937
26938 \begin_layout Standard
26939 SSP receive/transmit interrupt
26940 \end_layout
26941
26942 \end_inset
26943 </cell>
26944 </row>
26945 <row topline="true">
26946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26947 \begin_inset Text
26948
26949 \begin_layout Standard
26950 SIG_TMR2
26951 \end_layout
26952
26953 \end_inset
26954 </cell>
26955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26956 \begin_inset Text
26957
26958 \begin_layout Standard
26959 TMR2 matches PR2 interrupt
26960 \end_layout
26961
26962 \end_inset
26963 </cell>
26964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26965 \begin_inset Text
26966
26967 \begin_layout Standard
26968
26969 \end_layout
26970
26971 \end_inset
26972 </cell>
26973 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26974 \begin_inset Text
26975
26976 \begin_layout Standard
26977
26978 \end_layout
26979
26980 \end_inset
26981 </cell>
26982 </row>
26983 <row topline="true" bottomline="true">
26984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26985 \begin_inset Text
26986
26987 \begin_layout Standard
26988 SIG_TMR3
26989 \end_layout
26990
26991 \end_inset
26992 </cell>
26993 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26994 \begin_inset Text
26995
26996 \begin_layout Standard
26997 TMR3 overflow interrupt
26998 \end_layout
26999
27000 \end_inset
27001 </cell>
27002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27003 \begin_inset Text
27004
27005 \begin_layout Standard
27006
27007 \end_layout
27008
27009 \end_inset
27010 </cell>
27011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27012 \begin_inset Text
27013
27014 \begin_layout Standard
27015
27016 \end_layout
27017
27018 \end_inset
27019 </cell>
27020 </row>
27021 </lyxtabular>
27022
27023 \end_inset
27024
27025
27026 \end_layout
27027
27028 \begin_layout Standard
27029 The prototypes for these names are defined in the header file 
27030 \emph on
27031 signal.h
27032 \emph default
27033  .
27034 \end_layout
27035
27036 \begin_layout Standard
27037 In order to simplify signal handling, a number of macros is provided:
27038 \end_layout
27039
27040 \begin_layout List
27041 \labelwidthstring 00.00.0000
27042 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27043  high priority interrupts.
27044  
27045 \emph on
27046 name
27047 \emph default
27048  is the function name to use.
27049 \end_layout
27050
27051 \begin_layout List
27052 \labelwidthstring 00.00.0000
27053 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27054  low priority interrupt.
27055  
27056 \emph on
27057 name
27058 \emph default
27059  is the function name to use.
27060 \end_layout
27061
27062 \begin_layout List
27063 \labelwidthstring 00.00.0000
27064 DEF_HANDLER(sig,handler) define a handler for signal 
27065 \emph on
27066 sig.
27067 \end_layout
27068
27069 \begin_layout List
27070 \labelwidthstring 00.00.0000
27071 END_DEF end the declaration of the dispatch table.
27072 \end_layout
27073
27074 \begin_layout Standard
27075 Additionally there are two more macros to simplify the declaration of the
27076  signal handler:
27077 \end_layout
27078
27079 \begin_layout List
27080 \labelwidthstring 00.00.0000
27081
27082 \series medium
27083 SIGHANDLER(handler) 
27084 \series default
27085 this declares the function prototype for the 
27086 \emph on
27087 handler
27088 \emph default
27089  function.
27090 \end_layout
27091
27092 \begin_layout List
27093 \labelwidthstring 00.00.0000
27094 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27095 \end_layout
27096
27097 \begin_layout Standard
27098 An example of using the macros above is shown below:
27099 \end_layout
27100
27101 \begin_layout LyX-Code
27102 #include <pic18fregs.h>
27103 \end_layout
27104
27105 \begin_layout LyX-Code
27106 #include <signal.h>
27107 \newline
27108
27109 \newline
27110 DEF_INTHIGH(high_int)
27111 \end_layout
27112
27113 \begin_layout LyX-Code
27114 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27115 \end_layout
27116
27117 \begin_layout LyX-Code
27118 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27119 \end_layout
27120
27121 \begin_layout LyX-Code
27122 END_DEF
27123 \newline
27124
27125 \newline
27126 SIGHANDLER(_tmr0_handler)
27127 \end_layout
27128
27129 \begin_layout LyX-Code
27130 {
27131 \end_layout
27132
27133 \begin_layout LyX-Code
27134   /* action to be taken when timer 0 overflows */
27135 \end_layout
27136
27137 \begin_layout LyX-Code
27138 }
27139 \newline
27140
27141 \newline
27142 SIGHANDLERNAKED(_bcol_handler)
27143 \end_layout
27144
27145 \begin_layout LyX-Code
27146 {
27147 \end_layout
27148
27149 \begin_layout LyX-Code
27150   _asm
27151 \end_layout
27152
27153 \begin_layout LyX-Code
27154     /* action to be taken when bus collision occurs */
27155 \end_layout
27156
27157 \begin_layout LyX-Code
27158     retfie
27159 \end_layout
27160
27161 \begin_layout LyX-Code
27162  _endasm;
27163 \end_layout
27164
27165 \begin_layout LyX-Code
27166 }
27167 \end_layout
27168
27169 \begin_layout Standard
27170
27171 \series bold
27172 NOTES:
27173 \series default
27174  Special care should be taken when using the above scheme:
27175 \end_layout
27176
27177 \begin_layout Itemize
27178 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27179 \end_layout
27180
27181 \begin_layout Itemize
27182 when declaring SIGHANDLERNAKED handler never forget to use 
27183 \emph on
27184 retfie
27185 \emph default
27186  for proper returning.
27187 \end_layout
27188
27189 \begin_layout Subsection
27190 PIC16 Port -- Tips
27191 \end_layout
27192
27193 \begin_layout Standard
27194 Here you can find some general tips for compiling programs with SDCC/pic16.
27195 \end_layout
27196
27197 \begin_layout Subsubsection
27198 Stack size
27199 \end_layout
27200
27201 \begin_layout Standard
27202 The default stack
27203 \begin_inset LatexCommand \index{PIC16!stack}
27204
27205 \end_inset
27206
27207  size (that is 64 bytes) probably is enough for many programs.
27208  One must take care that when there are many levels of function nesting,
27209  or there is excessive usage of stack, its size should be extended.
27210  An example of such a case is the printf/sprintf family of functions.
27211  If you encounter problems like not being able to print integers, then you
27212  need to set the stack size around the maximum (256 for small stack model).
27213  The following diagram shows what happens when calling printf to print an
27214  integer:
27215 \end_layout
27216
27217 \begin_layout LyX-Code
27218 printf () --> ltoa () --> ultoa () --> divschar ()
27219 \end_layout
27220
27221 \begin_layout Standard
27222 It is should be understood that stack is easily consumed when calling complicate
27223 d functions.
27224  Using command line arguments like -
27225 \begin_inset ERT
27226 status collapsed
27227
27228 \begin_layout Standard
27229
27230
27231 \backslash
27232 /
27233 \end_layout
27234
27235 \end_inset
27236
27237 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27238  stack frames.
27239  Other ways to reduce stack usage may exist.
27240 \end_layout
27241
27242 \begin_layout Subsection
27243 Known bugs
27244 \end_layout
27245
27246 \begin_layout Standard
27247 The PIC16 Port currently does not pass SDCC's regression test
27248 \begin_inset LatexCommand \index{Regression test (PIC16)}
27249
27250 \end_inset
27251
27252  suite (see section 
27253 \begin_inset LatexCommand \ref{sec:Quality-control}
27254
27255 \end_inset
27256
27257 ) and thus the snapshot build regression tests for the PIC16 target are
27258  currently disabled for all hosts
27259 \emph on
27260 .
27261 \end_layout
27262
27263 \begin_layout Chapter
27264 Debugging
27265 \end_layout
27266
27267 \begin_layout Standard
27268 There are several approaches to debugging your code.
27269  This chapter is meant to show your options and to give detail on some of
27270  them:
27271 \newline
27272
27273 \newline
27274 When writing your code:
27275 \end_layout
27276
27277 \begin_layout Itemize
27278 write your code with debugging in mind (avoid duplicating code, put conceptually
27279  similar variables into structs, use structured code, have strategic points
27280  within your code where all variables are consistent, ...)
27281 \end_layout
27282
27283 \begin_layout Itemize
27284 run a syntax-checking tool like splint
27285 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27286
27287 \end_inset
27288
27289
27290 \begin_inset LatexCommand \index{lint (syntax checking tool)}
27291
27292 \end_inset
27293
27294  (see -
27295 \begin_inset ERT
27296 status collapsed
27297
27298 \begin_layout Standard
27299
27300
27301 \backslash
27302 /
27303 \end_layout
27304
27305 \end_inset
27306
27307 -more-pedantic 
27308 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27309
27310 \end_inset
27311
27312 ) over the code.
27313 \end_layout
27314
27315 \begin_layout Itemize
27316 for the high level code use a C-compiler (like f.e.
27317  GCC) to compile run and debug the code on your host.
27318  See (see -
27319 \begin_inset ERT
27320 status collapsed
27321
27322 \begin_layout Standard
27323
27324
27325 \backslash
27326 /
27327 \end_layout
27328
27329 \end_inset
27330
27331 -more-pedantic 
27332 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27333
27334 \end_inset
27335
27336 ) on how to handle syntax extensions like __xdata, __at(), ...
27337  
27338 \end_layout
27339
27340 \begin_layout Itemize
27341 use another C-compiler to compile code for your target.
27342  Always an option but not recommended:) And not very likely to help you.
27343  If you seriously consider walking this path you should at least occasionally
27344  check portability of your code.
27345  Most commercial compiler vendors will offer an evaluation version so you
27346  can test compile your code or snippets of your code.
27347 \end_layout
27348
27349 \begin_layout Standard
27350 Debugging on a simulator:
27351 \end_layout
27352
27353 \begin_layout Itemize
27354 there is a separate section about SDCDB (section 
27355 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
27356
27357 \end_inset
27358
27359 ) below.
27360 \end_layout
27361
27362 \begin_layout Itemize
27363 or (8051 specific) use a freeware/commercial simulator which interfaces
27364  to the AOMF
27365 \begin_inset LatexCommand \index{AOMF, AOMF51}
27366
27367 \end_inset
27368
27369  file (see 
27370 \begin_inset LatexCommand \ref{OMF file}
27371
27372 \end_inset
27373
27374 ) optionally generated by SDCC.
27375 \end_layout
27376
27377 \begin_layout Standard
27378 Debugging On-target: 
27379 \end_layout
27380
27381 \begin_layout Itemize
27382 use a MCU port pin to serially output debug data to the RS232 port of your
27383  host.
27384  You'll probably want some level shifting device typically involving a MAX232
27385  or similar IC.
27386  If the hardware serial port of the MCU is not available search for 'Software
27387  UART' in your favourite search machine.
27388 \end_layout
27389
27390 \begin_layout Itemize
27391 use an on-target monitor.
27392  In this context a monitor is a small program which usually accepts commands
27393  via a serial line and allows to set program counter, to single step through
27394  a program and read/write memory locations.
27395  For the 8051 good examples of monitors are paulmon and cmon51 (see section
27396  
27397 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
27398
27399 \end_inset
27400
27401 ).
27402 \end_layout
27403
27404 \begin_layout Itemize
27405 toggle MCU port pins at strategic points within your code and use an oscilloscop
27406 e.
27407  A 
27408 \emph on
27409 digital oscilloscope
27410 \emph default
27411
27412 \begin_inset LatexCommand \index{Oscilloscope}
27413
27414 \end_inset
27415
27416  with deep trace memory is really helpful especially if you have to debug
27417  a realtime application.
27418  If you need to monitor more pins than your oscilloscope provides you can
27419  sometimes get away with a small R-2R network.
27420  On a single channel oscilloscope you could f.e.
27421  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
27422 k
27423 \begin_inset Formula $\Omega$
27424 \end_inset
27425
27426  resistor and the other one by a 5\InsetSpace ~
27427 k
27428 \begin_inset Formula $\Omega$
27429 \end_inset
27430
27431  resistor to the oscilloscope probe (check output drive capability of the
27432  pins you want to monitor).
27433  If you need to monitor many more pins a 
27434 \emph on
27435 logic analyzer
27436 \emph default
27437  will be handy.
27438 \end_layout
27439
27440 \begin_layout Itemize
27441 use an ICE (
27442 \emph on
27443 i
27444 \emph default
27445
27446 \emph on
27447 c
27448 \emph default
27449 ircuit 
27450 \emph on
27451 e
27452 \emph default
27453 mulator
27454 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
27455
27456 \end_inset
27457
27458 ).
27459  Usually very expensive.
27460  And very nice to have too.
27461  And usually locks you (for years...) to the devices the ICE can emulate.
27462  
27463 \end_layout
27464
27465 \begin_layout Itemize
27466 use a remote debugger.
27467  In most 8-bit systems the symbol information is not available on the target,
27468  and a complete debugger is too bulky for the target system.
27469  Therefore usually a debugger on the host system connects to an on-target
27470  debugging stub which accepts only primitive commands.
27471  
27472 \newline
27473 Terms to enter into your favourite search engine could be 'remote debugging',
27474  'gdb stub' or 'inferior debugger'.
27475  (is there one?)
27476 \end_layout
27477
27478 \begin_layout Itemize
27479 use an on target hardware debugger.
27480  Some of the more modern MCUs include hardware support for setting break
27481  points and monitoring/changing variables by using dedicated hardware pins.
27482  This facility doesn't require additional code to run on the target and
27483  
27484 \emph on
27485 usually
27486 \emph default
27487  doesn't affect runtime behaviour until a breakpoint is hit.
27488  For the mcs51 most hardware debuggers use the AOMF
27489 \begin_inset LatexCommand \index{AOMF, AOMF51}
27490
27491 \end_inset
27492
27493  file (see 
27494 \begin_inset LatexCommand \ref{OMF file}
27495
27496 \end_inset
27497
27498 ) as input file.
27499  
27500 \end_layout
27501
27502 \begin_layout Standard
27503 Last not least:
27504 \end_layout
27505
27506 \begin_layout Itemize
27507 if you are not familiar with any of the following terms you're likely to
27508  run into problems rather sooner than later: 
27509 \emph on
27510 volatile
27511 \emph default
27512
27513 \emph on
27514 atomic
27515 \emph default
27516
27517 \emph on
27518 memory map
27519 \emph default
27520
27521 \emph on
27522 overlay
27523 \emph default
27524 .
27525  As an embedded programmer you 
27526 \emph on
27527 have
27528 \emph default
27529  to know them so why not look them up 
27530 \emph on
27531 before
27532 \emph default
27533  you have problems?)
27534 \end_layout
27535
27536 \begin_layout Itemize
27537 tell someone else about your problem (actually this is a surprisingly effective
27538  means to hunt down the bug even if the listener is not familiar with your
27539  environment).
27540  As 'failure to communicate' is probably one of the job-induced deformations
27541  of an embedded programmer this is highly encouraged.
27542 \end_layout
27543
27544 \begin_layout Section
27545 Debugging with SDCDB
27546 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
27547
27548 \end_inset
27549
27550
27551 \begin_inset LatexCommand \index{SDCDB (debugger)}
27552
27553 \end_inset
27554
27555  
27556 \end_layout
27557
27558 \begin_layout Standard
27559 SDCC is distributed with a source level debugger
27560 \begin_inset LatexCommand \index{Debugger}
27561
27562 \end_inset
27563
27564 .
27565  The debugger uses a command line interface, the command repertoire of the
27566  debugger has been kept as close to gdb
27567 \begin_inset LatexCommand \index{gdb}
27568
27569 \end_inset
27570
27571  (the GNU debugger) as possible.
27572  The configuration and build process is part of the standard compiler installati
27573 on, which also builds and installs the debugger in the target directory
27574  specified during configuration.
27575  The debugger allows you debug BOTH at the C source and at the ASM source
27576  level.
27577 \end_layout
27578
27579 \begin_layout Subsection
27580 Compiling for Debugging
27581 \end_layout
27582
27583 \begin_layout Standard
27584 The -
27585 \begin_inset ERT
27586 status collapsed
27587
27588 \begin_layout Standard
27589
27590
27591 \backslash
27592 /
27593 \end_layout
27594
27595 \end_inset
27596
27597 -debug
27598 \begin_inset LatexCommand \index{-\/-debug}
27599
27600 \end_inset
27601
27602  option must be specified for all files for which debug information is to
27603  be generated.
27604  The compiler generates a .adb file for each of these files.
27605  The linker creates the .cdb
27606 \begin_inset LatexCommand \index{<file>.cdb}
27607
27608 \end_inset
27609
27610  file from the .adb
27611 \begin_inset LatexCommand \index{<file>.adb}
27612
27613 \end_inset
27614
27615  files and the address information.
27616  This .cdb is used by the debugger.
27617 \end_layout
27618
27619 \begin_layout Subsection
27620 How the Debugger Works
27621 \end_layout
27622
27623 \begin_layout Standard
27624 When the -
27625 \begin_inset ERT
27626 status collapsed
27627
27628 \begin_layout Standard
27629
27630
27631 \backslash
27632 /
27633 \end_layout
27634
27635 \end_inset
27636
27637 -debug option is specified the compiler generates extra symbol information
27638  some of which are put into the assembler source and some are put into the
27639  .adb file.
27640  Then the linker creates the .cdb file from the individual .adb files with
27641  the address information for the symbols.
27642  The debugger reads the symbolic information generated by the compiler &
27643  the address information generated by the linker.
27644  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
27645  execution is controlled by the debugger.
27646  When a command is issued for the debugger, it translates it into appropriate
27647  commands for the simulator.
27648  (Currently SDCDM only connects to the simulator but 
27649 \emph on
27650 newcdb
27651 \emph default
27652  at 
27653 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
27654
27655 \end_inset
27656
27657  is an effort to connect directly to the hardware.) 
27658 \end_layout
27659
27660 \begin_layout Subsection
27661 Starting the Debugger SDCDB
27662 \end_layout
27663
27664 \begin_layout Standard
27665 The debugger can be started using the following command line.
27666  (Assume the file you are debugging has the file name foo).
27667 \newline
27668
27669 \newline
27670
27671 \family sans
27672 \series bold
27673 sdcdb foo
27674 \newline
27675
27676 \family default
27677 \series default
27678
27679 \newline
27680 The debugger will look for the following files.
27681 \end_layout
27682
27683 \begin_layout Itemize
27684 foo.c - the source file.
27685 \end_layout
27686
27687 \begin_layout Itemize
27688 foo.cdb - the debugger symbol information file.
27689 \end_layout
27690
27691 \begin_layout Itemize
27692 foo.ihx - the Intel hex format
27693 \begin_inset LatexCommand \index{Intel hex format}
27694
27695 \end_inset
27696
27697  object file.
27698 \end_layout
27699
27700 \begin_layout Subsection
27701 SDCDB Command Line Options
27702 \end_layout
27703
27704 \begin_layout Itemize
27705 -
27706 \begin_inset ERT
27707 status collapsed
27708
27709 \begin_layout Standard
27710
27711
27712 \backslash
27713 /
27714 \end_layout
27715
27716 \end_inset
27717
27718 -directory=<source file directory> this option can used to specify the directory
27719  search list.
27720  The debugger will look into the directory list specified for source, cdb
27721  & ihx files.
27722  The items in the directory list must be separated by ':', e.g.
27723  if the source files can be in the directories /home/src1 and /home/src2,
27724  the -
27725 \begin_inset ERT
27726 status collapsed
27727
27728 \begin_layout Standard
27729
27730
27731 \backslash
27732 /
27733 \end_layout
27734
27735 \end_inset
27736
27737 -directory option should be -
27738 \begin_inset ERT
27739 status collapsed
27740
27741 \begin_layout Standard
27742
27743
27744 \backslash
27745 /
27746 \end_layout
27747
27748 \end_inset
27749
27750 -directory=/home/src1:/home/src2.
27751  Note there can be no spaces in the option.
27752  
27753 \end_layout
27754
27755 \begin_layout Itemize
27756 -cd <directory> - change to the <directory>.
27757 \end_layout
27758
27759 \begin_layout Itemize
27760 -fullname - used by GUI front ends.
27761 \end_layout
27762
27763 \begin_layout Itemize
27764 -cpu <cpu-type> - this argument is passed to the simulator please see the
27765  simulator docs for details.
27766 \end_layout
27767
27768 \begin_layout Itemize
27769 -X <Clock frequency > this options is passed to the simulator please see
27770  the simulator docs for details.
27771 \end_layout
27772
27773 \begin_layout Itemize
27774 -s <serial port file> passed to simulator see the simulator docs for details.
27775 \end_layout
27776
27777 \begin_layout Itemize
27778 -S <serial in,out> passed to simulator see the simulator docs for details.
27779 \end_layout
27780
27781 \begin_layout Itemize
27782 -k <port number> passed to simulator see the simulator docs for details.
27783 \end_layout
27784
27785 \begin_layout Subsection
27786 SDCDB Debugger Commands
27787 \end_layout
27788
27789 \begin_layout Standard
27790 As mentioned earlier the command interface for the debugger has been deliberatel
27791 y kept as close the GNU debugger gdb, as possible.
27792  This will help the integration with existing graphical user interfaces
27793  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
27794  If you use a graphical user interface for the debugger you can skip this
27795  section.
27796 \end_layout
27797
27798 \begin_layout Subsubsection*
27799 break [line | file:line | function | file:function]
27800 \end_layout
27801
27802 \begin_layout Standard
27803 Set breakpoint at specified line or function:
27804 \newline
27805
27806 \newline
27807
27808 \family sans
27809 \series bold
27810 sdcdb>break 100 
27811 \newline
27812 sdcdb>break foo.c:100
27813 \newline
27814 sdcdb>break funcfoo
27815 \newline
27816 sdcdb>break foo.c:funcfoo
27817 \end_layout
27818
27819 \begin_layout Subsubsection*
27820 clear [line | file:line | function | file:function ]
27821 \end_layout
27822
27823 \begin_layout Standard
27824 Clear breakpoint at specified line or function:
27825 \newline
27826
27827 \newline
27828
27829 \family sans
27830 \series bold
27831 sdcdb>clear 100
27832 \newline
27833 sdcdb>clear foo.c:100
27834 \newline
27835 sdcdb>clear funcfoo
27836 \newline
27837 sdcdb>clear foo.c:funcfoo
27838 \end_layout
27839
27840 \begin_layout Subsubsection*
27841 continue
27842 \end_layout
27843
27844 \begin_layout Standard
27845 Continue program being debugged, after breakpoint.
27846 \end_layout
27847
27848 \begin_layout Subsubsection*
27849 finish
27850 \end_layout
27851
27852 \begin_layout Standard
27853 Execute till the end of the current function.
27854 \end_layout
27855
27856 \begin_layout Subsubsection*
27857 delete [n]
27858 \end_layout
27859
27860 \begin_layout Standard
27861 Delete breakpoint number 'n'.
27862  If used without any option clear ALL user defined break points.
27863 \end_layout
27864
27865 \begin_layout Subsubsection*
27866 info [break | stack | frame | registers ]
27867 \end_layout
27868
27869 \begin_layout Itemize
27870 info break - list all breakpoints
27871 \end_layout
27872
27873 \begin_layout Itemize
27874 info stack - show the function call stack.
27875 \end_layout
27876
27877 \begin_layout Itemize
27878 info frame - show information about the current execution frame.
27879 \end_layout
27880
27881 \begin_layout Itemize
27882 info registers - show content of all registers.
27883 \end_layout
27884
27885 \begin_layout Subsubsection*
27886 step
27887 \end_layout
27888
27889 \begin_layout Standard
27890 Step program until it reaches a different source line.
27891  Note: pressing <return> repeats the last command.
27892 \end_layout
27893
27894 \begin_layout Subsubsection*
27895 next
27896 \end_layout
27897
27898 \begin_layout Standard
27899 Step program, proceeding through subroutine calls.
27900 \end_layout
27901
27902 \begin_layout Subsubsection*
27903 run
27904 \end_layout
27905
27906 \begin_layout Standard
27907 Start debugged program.
27908 \end_layout
27909
27910 \begin_layout Subsubsection*
27911 ptype variable 
27912 \end_layout
27913
27914 \begin_layout Standard
27915 Print type information of the variable.
27916 \end_layout
27917
27918 \begin_layout Subsubsection*
27919 print variable
27920 \end_layout
27921
27922 \begin_layout Standard
27923 print value of variable.
27924 \end_layout
27925
27926 \begin_layout Subsubsection*
27927 file filename
27928 \end_layout
27929
27930 \begin_layout Standard
27931 load the given file name.
27932  Note this is an alternate method of loading file for debugging.
27933 \end_layout
27934
27935 \begin_layout Subsubsection*
27936 frame
27937 \end_layout
27938
27939 \begin_layout Standard
27940 print information about current frame.
27941 \end_layout
27942
27943 \begin_layout Subsubsection*
27944 set srcmode
27945 \end_layout
27946
27947 \begin_layout Standard
27948 Toggle between C source & assembly source.
27949 \end_layout
27950
27951 \begin_layout Subsubsection*
27952 ! simulator command
27953 \end_layout
27954
27955 \begin_layout Standard
27956 Send the string following '!' to the simulator, the simulator response is
27957  displayed.
27958  Note the debugger does not interpret the command being sent to the simulator,
27959  so if a command like 'go' is sent the debugger can loose its execution
27960  context and may display incorrect values.
27961 \end_layout
27962
27963 \begin_layout Subsubsection*
27964 quit
27965 \end_layout
27966
27967 \begin_layout Standard
27968 "Watch me now.
27969  Iam going Down.
27970  My name is Bobby Brown"
27971 \end_layout
27972
27973 \begin_layout Subsection
27974 Interfacing SDCDB with DDD
27975 \end_layout
27976
27977 \begin_layout Standard
27978 \begin_inset Note Note
27979 status collapsed
27980
27981 \begin_layout Standard
27982 The screenshot was converted from png to eps with: 
27983 \begin_inset Quotes sld
27984 \end_inset
27985
27986 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
27987 \begin_inset Quotes srd
27988 \end_inset
27989
27990  which produces a pretty compact eps file which is free from compression
27991  artifacts.
27992 \end_layout
27993
27994 \begin_layout Standard
27995 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
27996  as this broke the build system on Sourceforge (pdf-file was broken.
27997  pdflatex does not accept eps files).
27998 \end_layout
27999
28000 \end_inset
28001
28002
28003 \end_layout
28004
28005 \begin_layout Standard
28006 The 
28007 \emph on
28008 p
28009 \emph default
28010 ortable 
28011 \emph on
28012 n
28013 \emph default
28014 etwork 
28015 \emph on
28016 g
28017 \emph default
28018 raphics File 
28019 \size footnotesize
28020
28021 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28022
28023 \end_inset
28024
28025
28026 \size default
28027  shows a screenshot of a debugging session with DDD
28028 \begin_inset LatexCommand \index{DDD (debugger)}
28029
28030 \end_inset
28031
28032  (Unix only) on a simulated 8032.
28033  The debugging session might not run as smoothly as the screenshot suggests.
28034  The debugger allows setting of breakpoints, displaying and changing variables,
28035  single stepping through C and assembler code.
28036  
28037 \newline
28038 The source was compiled with 
28039 \family sans
28040 \series bold
28041
28042 \newline
28043
28044 \newline
28045 sdcc -
28046 \family default
28047 \series default
28048
28049 \begin_inset ERT
28050 status collapsed
28051
28052 \begin_layout Standard
28053
28054
28055 \backslash
28056 /
28057 \end_layout
28058
28059 \end_inset
28060
28061
28062 \family sans
28063 \series bold
28064 -debug ddd_example.c
28065 \family default
28066 \series default
28067  
28068 \family sans
28069 \series bold
28070
28071 \newline
28072
28073 \family default
28074 \series default
28075
28076 \newline
28077 and DDD was invoked with 
28078 \family sans
28079 \series bold
28080
28081 \newline
28082
28083 \newline
28084 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28085 \end_layout
28086
28087 \begin_layout Standard
28088 \begin_inset Note Note
28089 status open
28090
28091 \begin_layout Standard
28092 Check that the double quotes or an apostroph within the command line survive
28093  the LyX tool chain.
28094  Previously the apostrophs got slanted in the PDF output so a cut and paste
28095  did not work.
28096 \end_layout
28097
28098 \end_inset
28099
28100
28101 \end_layout
28102
28103 \begin_layout Subsection
28104 Interfacing SDCDB with XEmacs
28105 \begin_inset LatexCommand \index{XEmacs}
28106
28107 \end_inset
28108
28109
28110 \begin_inset LatexCommand \index{Emacs}
28111
28112 \end_inset
28113
28114
28115 \end_layout
28116
28117 \begin_layout Standard
28118 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28119  sdcdb.el and sdcdbsrc.el.
28120  These two files can be found in the $(prefix)/bin directory after the installat
28121 ion is complete.
28122  These files need to be loaded into XEmacs for the interface to work.
28123  This can be done at XEmacs startup time by inserting the following into
28124  your '.xemacs' file (which can be found in your HOME directory): 
28125 \newline
28126
28127 \newline
28128
28129 \family typewriter
28130 (load-file sdcdbsrc.el) 
28131 \family default
28132
28133 \newline
28134
28135 \newline
28136 .xemacs is a lisp file so the () around the command is REQUIRED.
28137  The files can also be loaded dynamically while XEmacs is running, set the
28138  environment variable 'EMACSLOADPATH' to the installation bin directory
28139  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28140  To start the interface enter the following command: 
28141 \newline
28142
28143 \newline
28144
28145 \family sans
28146 \series bold
28147 ESC-x sdcdbsrc
28148 \family default
28149 \series default
28150
28151 \newline
28152
28153 \newline
28154 You will prompted to enter the file name to be debugged.
28155  
28156 \newline
28157
28158 \newline
28159 The command line options that are passed to the simulator directly are
28160  bound to default values in the file sdcdbsrc.el.
28161  The variables are listed below, these values maybe changed as required.
28162 \end_layout
28163
28164 \begin_layout Itemize
28165 sdcdbsrc-cpu-type '51
28166 \end_layout
28167
28168 \begin_layout Itemize
28169 sdcdbsrc-frequency '11059200
28170 \end_layout
28171
28172 \begin_layout Itemize
28173 sdcdbsrc-serial nil
28174 \end_layout
28175
28176 \begin_layout Standard
28177 The following is a list of key mapping for the debugger interface.
28178 \end_layout
28179
28180 \begin_layout Standard
28181 \InsetSpace ~
28182
28183 \family typewriter
28184
28185 \newline
28186 ;;\InsetSpace ~
28187 Current Listing :: 
28188 \newline
28189 ;;key\InsetSpace ~
28190 \InsetSpace ~
28191 \InsetSpace ~
28192 \InsetSpace ~
28193 \InsetSpace ~
28194 \InsetSpace ~
28195 \InsetSpace ~
28196 \InsetSpace ~
28197 \InsetSpace ~
28198 \InsetSpace ~
28199 \InsetSpace ~
28200 \InsetSpace ~
28201 \InsetSpace ~
28202 \InsetSpace ~
28203 binding\InsetSpace ~
28204 \InsetSpace ~
28205 \InsetSpace ~
28206 \InsetSpace ~
28207 \InsetSpace ~
28208 \InsetSpace ~
28209 \InsetSpace ~
28210 \InsetSpace ~
28211 \InsetSpace ~
28212 \InsetSpace ~
28213 \InsetSpace ~
28214 \InsetSpace ~
28215 \InsetSpace ~
28216 \InsetSpace ~
28217 \InsetSpace ~
28218 \InsetSpace ~
28219 \InsetSpace ~
28220 \InsetSpace ~
28221 \InsetSpace ~
28222 \InsetSpace ~
28223 \InsetSpace ~
28224 \InsetSpace ~
28225 Comment 
28226 \newline
28227 ;;---\InsetSpace ~
28228 \InsetSpace ~
28229 \InsetSpace ~
28230 \InsetSpace ~
28231 \InsetSpace ~
28232 \InsetSpace ~
28233 \InsetSpace ~
28234 \InsetSpace ~
28235 \InsetSpace ~
28236 \InsetSpace ~
28237 \InsetSpace ~
28238 \InsetSpace ~
28239 \InsetSpace ~
28240 \InsetSpace ~
28241 -------\InsetSpace ~
28242 \InsetSpace ~
28243 \InsetSpace ~
28244 \InsetSpace ~
28245 \InsetSpace ~
28246 \InsetSpace ~
28247 \InsetSpace ~
28248 \InsetSpace ~
28249 \InsetSpace ~
28250 \InsetSpace ~
28251 \InsetSpace ~
28252 \InsetSpace ~
28253 \InsetSpace ~
28254 \InsetSpace ~
28255 \InsetSpace ~
28256 \InsetSpace ~
28257 \InsetSpace ~
28258 \InsetSpace ~
28259 \InsetSpace ~
28260 \InsetSpace ~
28261 \InsetSpace ~
28262 \InsetSpace ~
28263 -------
28264 \newline
28265 ;; 
28266 \newline
28267 ;;\InsetSpace ~
28268 n\InsetSpace ~
28269 \InsetSpace ~
28270 \InsetSpace ~
28271 \InsetSpace ~
28272 \InsetSpace ~
28273 \InsetSpace ~
28274 \InsetSpace ~
28275 \InsetSpace ~
28276 \InsetSpace ~
28277 \InsetSpace ~
28278 \InsetSpace ~
28279 \InsetSpace ~
28280 \InsetSpace ~
28281 \InsetSpace ~
28282 \InsetSpace ~
28283 sdcdb-next-fro
28284 m-src\InsetSpace ~
28285 \InsetSpace ~
28286 \InsetSpace ~
28287 \InsetSpace ~
28288 \InsetSpace ~
28289 \InsetSpace ~
28290 \InsetSpace ~
28291 \InsetSpace ~
28292 \InsetSpace ~
28293 \InsetSpace ~
28294 SDCDB next command 
28295 \newline
28296 ;;\InsetSpace ~
28297 b\InsetSpace ~
28298 \InsetSpace ~
28299 \InsetSpace ~
28300 \InsetSpace ~
28301 \InsetSpace ~
28302 \InsetSpace ~
28303 \InsetSpace ~
28304 \InsetSpace ~
28305 \InsetSpace ~
28306 \InsetSpace ~
28307 \InsetSpace ~
28308 \InsetSpace ~
28309 \InsetSpace ~
28310 \InsetSpace ~
28311 \InsetSpace ~
28312 sdcdb-back-from-src\InsetSpace ~
28313 \InsetSpace ~
28314 \InsetSpace ~
28315 \InsetSpace ~
28316 \InsetSpace ~
28317 \InsetSpace ~
28318 \InsetSpace ~
28319 \InsetSpace ~
28320 \InsetSpace ~
28321 \InsetSpace ~
28322 SDCDB back command 
28323 \newline
28324 ;;\InsetSpace ~
28325 c\InsetSpace ~
28326 \InsetSpace ~
28327 \InsetSpace ~
28328 \InsetSpace ~
28329 \InsetSpace ~
28330 \InsetSpace ~
28331 \InsetSpace ~
28332 \InsetSpace ~
28333 \InsetSpace ~
28334 \InsetSpace ~
28335 \InsetSpace ~
28336 \InsetSpace ~
28337 \InsetSpace ~
28338 \InsetSpace ~
28339 \InsetSpace ~
28340 sdcdb-cont-f
28341 rom-src\InsetSpace ~
28342 \InsetSpace ~
28343 \InsetSpace ~
28344 \InsetSpace ~
28345 \InsetSpace ~
28346 \InsetSpace ~
28347 \InsetSpace ~
28348 \InsetSpace ~
28349 \InsetSpace ~
28350 \InsetSpace ~
28351 SDCDB continue command
28352 \newline
28353 ;;\InsetSpace ~
28354 s\InsetSpace ~
28355 \InsetSpace ~
28356 \InsetSpace ~
28357 \InsetSpace ~
28358 \InsetSpace ~
28359 \InsetSpace ~
28360 \InsetSpace ~
28361 \InsetSpace ~
28362 \InsetSpace ~
28363 \InsetSpace ~
28364 \InsetSpace ~
28365 \InsetSpace ~
28366 \InsetSpace ~
28367 \InsetSpace ~
28368 \InsetSpace ~
28369 sdcdb-step-from-src\InsetSpace ~
28370 \InsetSpace ~
28371 \InsetSpace ~
28372 \InsetSpace ~
28373 \InsetSpace ~
28374 \InsetSpace ~
28375 \InsetSpace ~
28376 \InsetSpace ~
28377 \InsetSpace ~
28378 \InsetSpace ~
28379 SDCDB step command 
28380 \newline
28381 ;;\InsetSpace ~
28382 ?\InsetSpace ~
28383 \InsetSpace ~
28384 \InsetSpace ~
28385 \InsetSpace ~
28386 \InsetSpace ~
28387 \InsetSpace ~
28388 \InsetSpace ~
28389 \InsetSpace ~
28390 \InsetSpace ~
28391 \InsetSpace ~
28392 \InsetSpace ~
28393 \InsetSpace ~
28394 \InsetSpace ~
28395 \InsetSpace ~
28396 \InsetSpace ~
28397 sdcdb-w
28398 hatis-c-sexp\InsetSpace ~
28399 \InsetSpace ~
28400 \InsetSpace ~
28401 \InsetSpace ~
28402 \InsetSpace ~
28403 \InsetSpace ~
28404 \InsetSpace ~
28405 \InsetSpace ~
28406 \InsetSpace ~
28407 \InsetSpace ~
28408 SDCDB ptypecommand for data at 
28409 \newline
28410 ;;\InsetSpace ~
28411 \InsetSpace ~
28412 \InsetSpace ~
28413 \InsetSpace ~
28414 \InsetSpace ~
28415 \InsetSpace ~
28416 \InsetSpace ~
28417 \InsetSpace ~
28418 \InsetSpace ~
28419 \InsetSpace ~
28420 \InsetSpace ~
28421 \InsetSpace ~
28422 \InsetSpace ~
28423 \InsetSpace ~
28424 \InsetSpace ~
28425 \InsetSpace ~
28426 \InsetSpace ~
28427 \InsetSpace ~
28428 \InsetSpace ~
28429 \InsetSpace ~
28430 \InsetSpace ~
28431 \InsetSpace ~
28432 \InsetSpace ~
28433 \InsetSpace ~
28434 \InsetSpace ~
28435 \InsetSpace ~
28436 \InsetSpace ~
28437 \InsetSpace ~
28438 \InsetSpace ~
28439 \InsetSpace ~
28440 \InsetSpace ~
28441 \InsetSpace ~
28442 \InsetSpace ~
28443 \InsetSpace ~
28444 \InsetSpace ~
28445 \InsetSpace ~
28446 \InsetSpace ~
28447 \InsetSpace ~
28448 \InsetSpace ~
28449 \InsetSpace ~
28450 \InsetSpace ~
28451 \InsetSpace ~
28452 \InsetSpace ~
28453 \InsetSpace ~
28454 \InsetSpace ~
28455 \InsetSpace ~
28456 \InsetSpace ~
28457 buffer point 
28458 \newline
28459 ;;\InsetSpace ~
28460 x\InsetSpace ~
28461 \InsetSpace ~
28462 \InsetSpace ~
28463 \InsetSpace ~
28464 \InsetSpace ~
28465 \InsetSpace ~
28466 \InsetSpace ~
28467 \InsetSpace ~
28468 \InsetSpace ~
28469 \InsetSpace ~
28470 \InsetSpace ~
28471 \InsetSpace ~
28472 \InsetSpace ~
28473 \InsetSpace ~
28474 \InsetSpace ~
28475 sdcdbsrc-delete\InsetSpace ~
28476 \InsetSpace ~
28477 \InsetSpace ~
28478 \InsetSpace ~
28479 \InsetSpace ~
28480 \InsetSpace ~
28481 \InsetSpace ~
28482 \InsetSpace ~
28483 \InsetSpace ~
28484 \InsetSpace ~
28485 \InsetSpace ~
28486 \InsetSpace ~
28487 \InsetSpace ~
28488 \InsetSpace ~
28489 SDCD
28490 B Delete all breakpoints if no arg 
28491 \newline
28492 ;;\InsetSpace ~
28493 \InsetSpace ~
28494 \InsetSpace ~
28495 \InsetSpace ~
28496 \InsetSpace ~
28497 \InsetSpace ~
28498 \InsetSpace ~
28499 \InsetSpace ~
28500 \InsetSpace ~
28501 \InsetSpace ~
28502 \InsetSpace ~
28503 \InsetSpace ~
28504 \InsetSpace ~
28505 \InsetSpace ~
28506 \InsetSpace ~
28507 \InsetSpace ~
28508 \InsetSpace ~
28509 \InsetSpace ~
28510 \InsetSpace ~
28511 \InsetSpace ~
28512 \InsetSpace ~
28513 \InsetSpace ~
28514 \InsetSpace ~
28515 \InsetSpace ~
28516 \InsetSpace ~
28517 \InsetSpace ~
28518 \InsetSpace ~
28519 \InsetSpace ~
28520 \InsetSpace ~
28521 \InsetSpace ~
28522 \InsetSpace ~
28523 \InsetSpace ~
28524 \InsetSpace ~
28525 \InsetSpace ~
28526 \InsetSpace ~
28527 \InsetSpace ~
28528 \InsetSpace ~
28529 \InsetSpace ~
28530 \InsetSpace ~
28531 \InsetSpace ~
28532 \InsetSpace ~
28533 \InsetSpace ~
28534 \InsetSpace ~
28535 \InsetSpace ~
28536 \InsetSpace ~
28537 \InsetSpace ~
28538 \InsetSpace ~
28539 given or delete arg (C-u arg x) 
28540 \newline
28541 ;;\InsetSpace ~
28542 m\InsetSpace ~
28543 \InsetSpace ~
28544 \InsetSpace ~
28545 \InsetSpace ~
28546 \InsetSpace ~
28547 \InsetSpace ~
28548 \InsetSpace ~
28549 \InsetSpace ~
28550 \InsetSpace ~
28551 \InsetSpace ~
28552 \InsetSpace ~
28553 \InsetSpace ~
28554 \InsetSpace ~
28555 \InsetSpace ~
28556 \InsetSpace ~
28557 sdcdbsrc
28558 -frame\InsetSpace ~
28559 \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 SDCDB Display current frame if no arg, 
28574 \newline
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 \InsetSpace ~
28596 \InsetSpace ~
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 given or display frame arg
28623  
28624 \newline
28625 ;;\InsetSpace ~
28626 \InsetSpace ~
28627 \InsetSpace ~
28628 \InsetSpace ~
28629 \InsetSpace ~
28630 \InsetSpace ~
28631 \InsetSpace ~
28632 \InsetSpace ~
28633 \InsetSpace ~
28634 \InsetSpace ~
28635 \InsetSpace ~
28636 \InsetSpace ~
28637 \InsetSpace ~
28638 \InsetSpace ~
28639 \InsetSpace ~
28640 \InsetSpace ~
28641 \InsetSpace ~
28642 \InsetSpace ~
28643 \InsetSpace ~
28644 \InsetSpace ~
28645 \InsetSpace ~
28646 \InsetSpace ~
28647 \InsetSpace ~
28648 \InsetSpace ~
28649 \InsetSpace ~
28650 \InsetSpace ~
28651 \InsetSpace ~
28652 \InsetSpace ~
28653 \InsetSpace ~
28654 \InsetSpace ~
28655 \InsetSpace ~
28656 \InsetSpace ~
28657 \InsetSpace ~
28658 \InsetSpace ~
28659 \InsetSpace ~
28660 \InsetSpace ~
28661 \InsetSpace ~
28662 \InsetSpace ~
28663 \InsetSpace ~
28664 \InsetSpace ~
28665 \InsetSpace ~
28666 \InsetSpace ~
28667 \InsetSpace ~
28668 \InsetSpace ~
28669 \InsetSpace ~
28670 \InsetSpace ~
28671 \InsetSpace ~
28672 buffer point 
28673 \newline
28674 ;;\InsetSpace ~
28675 !\InsetSpace ~
28676 \InsetSpace ~
28677 \InsetSpace ~
28678 \InsetSpace ~
28679 \InsetSpace ~
28680 \InsetSpace ~
28681 \InsetSpace ~
28682 \InsetSpace ~
28683 \InsetSpace ~
28684 \InsetSpace ~
28685 \InsetSpace ~
28686 \InsetSpace ~
28687 \InsetSpace ~
28688 \InsetSpace ~
28689 \InsetSpace ~
28690 sdcdbsrc-goto-sdcdb\InsetSpace ~
28691 \InsetSpace ~
28692 \InsetSpace ~
28693 \InsetSpace ~
28694 \InsetSpace ~
28695 \InsetSpace ~
28696 \InsetSpace ~
28697 \InsetSpace ~
28698 \InsetSpace ~
28699 \InsetSpace ~
28700 Goto the SDCDB output buffer 
28701 \newline
28702 ;;\InsetSpace ~
28703 p\InsetSpace ~
28704 \InsetSpace ~
28705 \InsetSpace ~
28706 \InsetSpace ~
28707 \InsetSpace ~
28708 \InsetSpace ~
28709 \InsetSpace ~
28710 \InsetSpace ~
28711 \InsetSpace ~
28712 \InsetSpace ~
28713 \InsetSpace ~
28714 \InsetSpace ~
28715 \InsetSpace ~
28716 \InsetSpace ~
28717 \InsetSpace ~
28718 sdcdb-prin
28719 t-c-sexp\InsetSpace ~
28720 \InsetSpace ~
28721 \InsetSpace ~
28722 \InsetSpace ~
28723 \InsetSpace ~
28724 \InsetSpace ~
28725 \InsetSpace ~
28726 \InsetSpace ~
28727 \InsetSpace ~
28728 \InsetSpace ~
28729 \InsetSpace ~
28730 SDCDB print command for data at 
28731 \newline
28732 ;;\InsetSpace ~
28733 \InsetSpace ~
28734 \InsetSpace ~
28735 \InsetSpace ~
28736 \InsetSpace ~
28737 \InsetSpace ~
28738 \InsetSpace ~
28739 \InsetSpace ~
28740 \InsetSpace ~
28741 \InsetSpace ~
28742 \InsetSpace ~
28743 \InsetSpace ~
28744 \InsetSpace ~
28745 \InsetSpace ~
28746 \InsetSpace ~
28747 \InsetSpace ~
28748 \InsetSpace ~
28749 \InsetSpace ~
28750 \InsetSpace ~
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 \InsetSpace ~
28768 \InsetSpace ~
28769 \InsetSpace ~
28770 \InsetSpace ~
28771 \InsetSpace ~
28772 \InsetSpace ~
28773 \InsetSpace ~
28774 \InsetSpace ~
28775 \InsetSpace ~
28776 \InsetSpace ~
28777 \InsetSpace ~
28778 \InsetSpace ~
28779 buffer point 
28780 \newline
28781 ;;\InsetSpace ~
28782 g\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 sdcdbsrc-goto-sdcdb\InsetSpace ~
28798 \InsetSpace ~
28799 \InsetSpace ~
28800 \InsetSpace ~
28801 \InsetSpace ~
28802 \InsetSpace ~
28803 \InsetSpace ~
28804 \InsetSpace ~
28805 \InsetSpace ~
28806 \InsetSpace ~
28807 Got
28808 o the SDCDB output buffer 
28809 \newline
28810 ;;\InsetSpace ~
28811 t\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 sdcdbsrc-mode\InsetSpace ~
28827 \InsetSpace ~
28828 \InsetSpace ~
28829 \InsetSpace ~
28830 \InsetSpace ~
28831 \InsetSpace ~
28832 \InsetSpace ~
28833 \InsetSpace ~
28834 \InsetSpace ~
28835 \InsetSpace ~
28836 \InsetSpace ~
28837 \InsetSpace ~
28838 \InsetSpace ~
28839 \InsetSpace ~
28840 \InsetSpace ~
28841 \InsetSpace ~
28842 Toggles Sdcdbsrc mode (turns it
28843  off) 
28844 \newline
28845 ;; 
28846 \newline
28847 ;;\InsetSpace ~
28848 C-c\InsetSpace ~
28849 C-f\InsetSpace ~
28850 \InsetSpace ~
28851 \InsetSpace ~
28852 \InsetSpace ~
28853 \InsetSpace ~
28854 \InsetSpace ~
28855 \InsetSpace ~
28856 \InsetSpace ~
28857 \InsetSpace ~
28858 sdcdb-finish-from-src\InsetSpace ~
28859 \InsetSpace ~
28860 \InsetSpace ~
28861 \InsetSpace ~
28862 \InsetSpace ~
28863 \InsetSpace ~
28864 \InsetSpace ~
28865 \InsetSpace ~
28866 SDCDB finish command 
28867 \newline
28868 ;; 
28869 \newline
28870 ;;\InsetSpace ~
28871 C-x\InsetSpace ~
28872 SPC\InsetSpace ~
28873 \InsetSpace ~
28874 \InsetSpace ~
28875 \InsetSpace ~
28876 \InsetSpace ~
28877 \InsetSpace ~
28878 \InsetSpace ~
28879 \InsetSpace ~
28880 \InsetSpace ~
28881 sdcdb-brea
28882 k\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 Set break for line with point 
28901 \newline
28902 ;;\InsetSpace ~
28903 ESC\InsetSpace ~
28904 t\InsetSpace ~
28905 \InsetSpace ~
28906 \InsetSpace ~
28907 \InsetSpace ~
28908 \InsetSpace ~
28909 \InsetSpace ~
28910 \InsetSpace ~
28911 \InsetSpace ~
28912 \InsetSpace ~
28913 \InsetSpace ~
28914 \InsetSpace ~
28915 sdcdbsrc-mode\InsetSpace ~
28916 \InsetSpace ~
28917 \InsetSpace ~
28918 \InsetSpace ~
28919 \InsetSpace ~
28920 \InsetSpace ~
28921 \InsetSpace ~
28922 \InsetSpace ~
28923 \InsetSpace ~
28924 \InsetSpace ~
28925 \InsetSpace ~
28926 \InsetSpace ~
28927 \InsetSpace ~
28928 \InsetSpace ~
28929 \InsetSpace ~
28930 \InsetSpace ~
28931 Toggle Sdcdbsrc mode 
28932 \newline
28933 ;;\InsetSpace ~
28934 ESC\InsetSpace ~
28935 m\InsetSpace ~
28936 \InsetSpace ~
28937 \InsetSpace ~
28938 \InsetSpace ~
28939 \InsetSpace ~
28940 \InsetSpace ~
28941 \InsetSpace ~
28942 \InsetSpace ~
28943 \InsetSpace ~
28944 \InsetSpace ~
28945 \InsetSpace ~
28946 sdc
28947 dbsrc-srcmode\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 Toggle list mode 
28961 \newline
28962 ;; 
28963 \newline
28964
28965 \family default
28966
28967 \newpage
28968
28969 \end_layout
28970
28971 \begin_layout Chapter
28972 TIPS
28973 \end_layout
28974
28975 \begin_layout Standard
28976 Here are a few guidelines that will help the compiler generate more efficient
28977  code, some of the tips are specific to this compiler others are generally
28978  good programming practice.
28979 \end_layout
28980
28981 \begin_layout Itemize
28982 Use the smallest data type to represent your data-value.
28983  If it is known in advance that the value is going to be less than 256 then
28984  use an 'unsigned char' instead of a 'short' or 'int'.
28985  Please note, that ANSI C requires both signed and unsigned chars to be
28986  promoted to 'signed int'
28987 \begin_inset LatexCommand \index{promotion to signed int}
28988
28989 \end_inset
28990
28991
28992 \begin_inset Marginal
28993 status collapsed
28994
28995 \begin_layout Standard
28996
28997 \series bold
28998 \InsetSpace ~
28999 !
29000 \end_layout
29001
29002 \end_inset
29003
29004  before doing any operation.
29005  This promotion
29006 \begin_inset LatexCommand \index{type promotion}
29007
29008 \end_inset
29009
29010
29011 \begin_inset LatexCommand \label{type promotion}
29012
29013 \end_inset
29014
29015  can be omitted, if the result is the same.
29016  The effect of the promotion rules together with the sign-extension is often
29017  surprising:
29018 \end_layout
29019
29020 \begin_deeper
29021 \begin_layout Verse
29022
29023 \family typewriter
29024 unsigned char uc = 0xfe;
29025 \newline
29026 if (uc * uc < 0) /* this is true! */
29027 \newline
29028 {
29029 \newline
29030 \InsetSpace ~
29031 \InsetSpace ~
29032 \InsetSpace ~
29033 \InsetSpace ~
29034 ....
29035 \newline
29036 }
29037 \end_layout
29038
29039 \begin_layout Standard
29040
29041 \family typewriter
29042 uc * uc
29043 \family default
29044  is evaluated as 
29045 \family typewriter
29046 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29047 \family default
29048 .
29049  
29050 \newline
29051 Another one:
29052 \end_layout
29053
29054 \begin_layout Verse
29055
29056 \family typewriter
29057 (unsigned char) -12 / (signed char) -3 = ...
29058 \end_layout
29059
29060 \begin_layout Standard
29061 No, the result is not 4:
29062 \end_layout
29063
29064 \begin_layout Verse
29065
29066 \family typewriter
29067 (int) (unsigned char) -12 / (int) (signed char) -3 =
29068 \newline
29069 (int) (unsigned char)
29070  0xf4 / (int) (signed char) 0xfd =
29071 \newline
29072 (int) 0x00f4 / (int) 0xfffd =
29073 \newline
29074 (int) 0x00f4
29075  / (int) 0xfffd =
29076 \newline
29077 (int) 244 / (int) -3 =
29078 \newline
29079 (int) -81 = (int) 0xffaf;
29080 \end_layout
29081
29082 \begin_layout Standard
29083 Don't complain, that gcc gives you a different result.
29084  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29085  Therefore the results are different.
29086 \newline
29087 From 
29088 \begin_inset Quotes sld
29089 \end_inset
29090
29091 comp.lang.c FAQ
29092 \begin_inset Quotes srd
29093 \end_inset
29094
29095 :
29096 \end_layout
29097
29098 \begin_layout Quote
29099
29100 \emph on
29101 If well-defined overflow characteristics are important and negative values
29102  are not, or if you want to steer clear of sign-extension problems when
29103  manipulating bits or bytes, use one of the corresponding unsigned types.
29104  (Beware when mixing signed and unsigned values in expressions, though.)
29105 \newline
29106 Although
29107  character types (especially unsigned char) can be used as "tiny" integers,
29108  doing so is sometimes more trouble than it's worth, due to unpredictable
29109  sign extension and increased code size.
29110 \end_layout
29111
29112 \end_deeper
29113 \begin_layout Itemize
29114 Use unsigned when it is known in advance that the value is not going to
29115  be negative.
29116  This helps especially if you are doing division or multiplication, bit-shifting
29117  or are using an array index.
29118 \end_layout
29119
29120 \begin_layout Itemize
29121 NEVER jump into a LOOP.
29122 \end_layout
29123
29124 \begin_layout Itemize
29125 Declare the variables to be local
29126 \begin_inset LatexCommand \index{local variables}
29127
29128 \end_inset
29129
29130  whenever possible, especially loop control variables (induction).
29131 \end_layout
29132
29133 \begin_layout Itemize
29134 Have a look at the assembly listing to get a 
29135 \begin_inset Quotes sld
29136 \end_inset
29137
29138 feeling
29139 \begin_inset Quotes srd
29140 \end_inset
29141
29142  for the code generation.
29143 \end_layout
29144
29145 \begin_layout Section
29146 Porting code from or to other compilers
29147 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29148
29149 \end_inset
29150
29151
29152 \end_layout
29153
29154 \begin_layout Itemize
29155 check whether endianness of the compilers differs and adapt where needed.
29156 \end_layout
29157
29158 \begin_layout Itemize
29159 check the device specific header files
29160 \begin_inset LatexCommand \index{Header files}
29161
29162 \end_inset
29163
29164
29165 \begin_inset LatexCommand \index{Include files}
29166
29167 \end_inset
29168
29169  for compiler specific syntax.
29170  Eventually include the file <compiler.h
29171 \begin_inset LatexCommand \index{compiler.h (include file)}
29172
29173 \end_inset
29174
29175
29176 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29177
29178 \end_inset
29179
29180  to allow using common header files.
29181  (see f.e.
29182  cc2510fx.h 
29183 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29184
29185 \end_inset
29186
29187 ).
29188 \end_layout
29189
29190 \begin_layout Itemize
29191 check whether the startup code contains the correct initialization (watchdog,
29192  peripherals).
29193 \end_layout
29194
29195 \begin_layout Itemize
29196 check whether the sizes of short, int, long match.
29197 \end_layout
29198
29199 \begin_layout Itemize
29200 check if some 16 or 32 bit hardware registers require a specific addressing
29201  order (least significant or most significant byte first) and adapt if needed
29202  (
29203 \emph on
29204 first
29205 \emph default
29206  and 
29207 \emph on
29208 last
29209 \emph default
29210  relate to time and not to lower/upper memory location here, so this is
29211  
29212 \emph on
29213 not
29214 \emph default
29215  the same as endianness).
29216 \end_layout
29217
29218 \begin_layout Itemize
29219 check whether the keyword 
29220 \emph on
29221 volatile
29222 \emph default
29223  is used where needed.
29224  The compilers might differ in their optimization characteristics (as different
29225  versions of the same compiler might also use more clever optimizations
29226  this is good idea anyway).
29227  See section 
29228 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29229
29230 \end_inset
29231
29232 .
29233 \end_layout
29234
29235 \begin_layout Itemize
29236 check that the compilers are not told to supress warnings.
29237 \end_layout
29238
29239 \begin_layout Itemize
29240 check and convert compiler specific extensions (interrupts, memory areas,
29241  pragmas etc.).
29242 \end_layout
29243
29244 \begin_layout Itemize
29245 check for differences in type promotion.
29246  Especially check for math operations on 
29247 \family typewriter
29248 char
29249 \family default
29250  or 
29251 \family typewriter
29252 unsigned char
29253 \family default
29254  variables.
29255  For the sake of C99 compatibility SDCC will probably promote these to 
29256 \family typewriter
29257 int
29258 \family default
29259  more often than other compilers.
29260  Eventually insert explicit casts to 
29261 \family typewriter
29262 (char) 
29263 \family default
29264 or
29265 \family typewriter
29266  (unsigned char)
29267 \family default
29268 .
29269  Also check that the ~\InsetSpace ~
29270 operator
29271 \begin_inset LatexCommand \index{\~\/ Operator}
29272
29273 \end_inset
29274
29275  is not used on 
29276 \family typewriter
29277 bit
29278 \begin_inset LatexCommand \index{bit}
29279
29280 \end_inset
29281
29282
29283 \family default
29284  variables, use the !\InsetSpace ~
29285 operator instead.
29286  See sections 
29287 \begin_inset LatexCommand \ref{type promotion}
29288
29289 \end_inset
29290
29291  and 
29292 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29293
29294 \end_inset
29295
29296 .
29297 \end_layout
29298
29299 \begin_layout Itemize
29300 check the assembly code generated for interrupt routines (f.e.
29301  for calls to possibly non-reentrant library functions).
29302 \end_layout
29303
29304 \begin_layout Itemize
29305 check whether timing loops result in proper timing (or preferably consider
29306  a rewrite of the code with timer based delays instead).
29307 \end_layout
29308
29309 \begin_layout Itemize
29310 check for differences in printf parameters (some compilers push (va_arg
29311 \begin_inset LatexCommand \index{vararg, va\_arg}
29312
29313 \end_inset
29314
29315 ) char variables as 
29316 \family typewriter
29317 int
29318 \family default
29319  others push them as 
29320 \family typewriter
29321 char
29322 \family default
29323 .
29324  See section 
29325 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29326
29327 \end_inset
29328
29329 ).
29330 \end_layout
29331
29332 \begin_layout Itemize
29333 check the resulting memory map
29334 \begin_inset LatexCommand \index{Memory map}
29335
29336 \end_inset
29337
29338 .
29339  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
29340 ly idata, pdata, xdata).
29341  Eventually check if unexpected library functions are included.
29342 \end_layout
29343
29344 \begin_layout Section
29345 Tools
29346 \begin_inset LatexCommand \index{Tools}
29347
29348 \end_inset
29349
29350  included in the distribution
29351 \end_layout
29352
29353 \begin_layout Standard
29354 \align left
29355 \begin_inset Tabular
29356 <lyxtabular version="3" rows="12" columns="3">
29357 <features>
29358 <column alignment="left" valignment="top" leftline="true" width="0pt">
29359 <column alignment="left" valignment="top" leftline="true" width="0pt">
29360 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29361 <row topline="true" bottomline="true">
29362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29363 \begin_inset Text
29364
29365 \begin_layout Standard
29366
29367 \series bold
29368 Name
29369 \end_layout
29370
29371 \end_inset
29372 </cell>
29373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29374 \begin_inset Text
29375
29376 \begin_layout Standard
29377
29378 \series bold
29379 Purpose
29380 \end_layout
29381
29382 \end_inset
29383 </cell>
29384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29385 \begin_inset Text
29386
29387 \begin_layout Standard
29388
29389 \series bold
29390 Directory
29391 \end_layout
29392
29393 \end_inset
29394 </cell>
29395 </row>
29396 <row topline="true">
29397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29398 \begin_inset Text
29399
29400 \begin_layout Standard
29401 uCsim
29402 \begin_inset LatexCommand \index{uCsim}
29403
29404 \end_inset
29405
29406
29407 \end_layout
29408
29409 \end_inset
29410 </cell>
29411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29412 \begin_inset Text
29413
29414 \begin_layout Standard
29415 Simulator for various architectures
29416 \end_layout
29417
29418 \end_inset
29419 </cell>
29420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29421 \begin_inset Text
29422
29423 \begin_layout Standard
29424 sdcc/sim/ucsim
29425 \end_layout
29426
29427 \end_inset
29428 </cell>
29429 </row>
29430 <row topline="true">
29431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29432 \begin_inset Text
29433
29434 \begin_layout Standard
29435 keil2sdcc.pl
29436 \end_layout
29437
29438 \end_inset
29439 </cell>
29440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29441 \begin_inset Text
29442
29443 \begin_layout Standard
29444 header file
29445 \begin_inset LatexCommand \index{Header files}
29446
29447 \end_inset
29448
29449
29450 \begin_inset LatexCommand \index{Include files}
29451
29452 \end_inset
29453
29454  conversion
29455 \end_layout
29456
29457 \end_inset
29458 </cell>
29459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29460 \begin_inset Text
29461
29462 \begin_layout Standard
29463 sdcc/support/scripts
29464 \end_layout
29465
29466 \end_inset
29467 </cell>
29468 </row>
29469 <row topline="true">
29470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29471 \begin_inset Text
29472
29473 \begin_layout Standard
29474 mh2h.c
29475 \end_layout
29476
29477 \end_inset
29478 </cell>
29479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29480 \begin_inset Text
29481
29482 \begin_layout Standard
29483 header file conversion
29484 \end_layout
29485
29486 \end_inset
29487 </cell>
29488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29489 \begin_inset Text
29490
29491 \begin_layout Standard
29492 sdcc/support/scripts
29493 \end_layout
29494
29495 \end_inset
29496 </cell>
29497 </row>
29498 <row topline="true">
29499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29500 \begin_inset Text
29501
29502 \begin_layout Standard
29503 as-gbz80
29504 \end_layout
29505
29506 \end_inset
29507 </cell>
29508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29509 \begin_inset Text
29510
29511 \begin_layout Standard
29512 Assembler
29513 \end_layout
29514
29515 \end_inset
29516 </cell>
29517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29518 \begin_inset Text
29519
29520 \begin_layout Standard
29521
29522 \family roman
29523 \series medium
29524 \shape up
29525 \size normal
29526 \emph off
29527 \bar no
29528 \noun off
29529 \color none
29530 sdcc/bin
29531 \end_layout
29532
29533 \end_inset
29534 </cell>
29535 </row>
29536 <row topline="true">
29537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29538 \begin_inset Text
29539
29540 \begin_layout Standard
29541 as-z80
29542 \end_layout
29543
29544 \end_inset
29545 </cell>
29546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29547 \begin_inset Text
29548
29549 \begin_layout Standard
29550 Assembler
29551 \end_layout
29552
29553 \end_inset
29554 </cell>
29555 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29556 \begin_inset Text
29557
29558 \begin_layout Standard
29559
29560 \family roman
29561 \series medium
29562 \shape up
29563 \size normal
29564 \emph off
29565 \bar no
29566 \noun off
29567 \color none
29568 sdcc/bin
29569 \end_layout
29570
29571 \end_inset
29572 </cell>
29573 </row>
29574 <row topline="true">
29575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29576 \begin_inset Text
29577
29578 \begin_layout Standard
29579 asx8051
29580 \end_layout
29581
29582 \end_inset
29583 </cell>
29584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29585 \begin_inset Text
29586
29587 \begin_layout Standard
29588 Assembler
29589 \end_layout
29590
29591 \end_inset
29592 </cell>
29593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29594 \begin_inset Text
29595
29596 \begin_layout Standard
29597
29598 \family roman
29599 \series medium
29600 \shape up
29601 \size normal
29602 \emph off
29603 \bar no
29604 \noun off
29605 \color none
29606 sdcc/bin
29607 \end_layout
29608
29609 \end_inset
29610 </cell>
29611 </row>
29612 <row topline="true">
29613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29614 \begin_inset Text
29615
29616 \begin_layout Standard
29617 SDCDB
29618 \end_layout
29619
29620 \end_inset
29621 </cell>
29622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29623 \begin_inset Text
29624
29625 \begin_layout Standard
29626 Simulator
29627 \end_layout
29628
29629 \end_inset
29630 </cell>
29631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29632 \begin_inset Text
29633
29634 \begin_layout Standard
29635
29636 \family roman
29637 \series medium
29638 \shape up
29639 \size normal
29640 \emph off
29641 \bar no
29642 \noun off
29643 \color none
29644 sdcc/bin
29645 \end_layout
29646
29647 \end_inset
29648 </cell>
29649 </row>
29650 <row topline="true">
29651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29652 \begin_inset Text
29653
29654 \begin_layout Standard
29655 aslink
29656 \end_layout
29657
29658 \end_inset
29659 </cell>
29660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29661 \begin_inset Text
29662
29663 \begin_layout Standard
29664 Linker
29665 \end_layout
29666
29667 \end_inset
29668 </cell>
29669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29670 \begin_inset Text
29671
29672 \begin_layout Standard
29673
29674 \family roman
29675 \series medium
29676 \shape up
29677 \size normal
29678 \emph off
29679 \bar no
29680 \noun off
29681 \color none
29682 sdcc/bin
29683 \end_layout
29684
29685 \end_inset
29686 </cell>
29687 </row>
29688 <row topline="true">
29689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29690 \begin_inset Text
29691
29692 \begin_layout Standard
29693 link-z80
29694 \end_layout
29695
29696 \end_inset
29697 </cell>
29698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29699 \begin_inset Text
29700
29701 \begin_layout Standard
29702 Linker
29703 \end_layout
29704
29705 \end_inset
29706 </cell>
29707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29708 \begin_inset Text
29709
29710 \begin_layout Standard
29711
29712 \family roman
29713 \series medium
29714 \shape up
29715 \size normal
29716 \emph off
29717 \bar no
29718 \noun off
29719 \color none
29720 sdcc/bin
29721 \end_layout
29722
29723 \end_inset
29724 </cell>
29725 </row>
29726 <row topline="true">
29727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29728 \begin_inset Text
29729
29730 \begin_layout Standard
29731 link-gbz80
29732 \end_layout
29733
29734 \end_inset
29735 </cell>
29736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29737 \begin_inset Text
29738
29739 \begin_layout Standard
29740 Linker
29741 \end_layout
29742
29743 \end_inset
29744 </cell>
29745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29746 \begin_inset Text
29747
29748 \begin_layout Standard
29749
29750 \family roman
29751 \series medium
29752 \shape up
29753 \size normal
29754 \emph off
29755 \bar no
29756 \noun off
29757 \color none
29758 sdcc/bin
29759 \end_layout
29760
29761 \end_inset
29762 </cell>
29763 </row>
29764 <row topline="true" bottomline="true">
29765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29766 \begin_inset Text
29767
29768 \begin_layout Standard
29769 packihx
29770 \end_layout
29771
29772 \end_inset
29773 </cell>
29774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29775 \begin_inset Text
29776
29777 \begin_layout Standard
29778 Intel Hex packer 
29779 \begin_inset LatexCommand \index{packihx (tool)}
29780
29781 \end_inset
29782
29783
29784 \end_layout
29785
29786 \end_inset
29787 </cell>
29788 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29789 \begin_inset Text
29790
29791 \begin_layout Standard
29792
29793 \family roman
29794 \series medium
29795 \shape up
29796 \size normal
29797 \emph off
29798 \bar no
29799 \noun off
29800 \color none
29801 sdcc/bin
29802 \end_layout
29803
29804 \end_inset
29805 </cell>
29806 </row>
29807 </lyxtabular>
29808
29809 \end_inset
29810
29811
29812 \newline
29813
29814 \end_layout
29815
29816 \begin_layout Section
29817 Documentation
29818 \begin_inset LatexCommand \index{Documentation}
29819
29820 \end_inset
29821
29822  included in the distribution
29823 \end_layout
29824
29825 \begin_layout Standard
29826 \align left
29827 \begin_inset Tabular
29828 <lyxtabular version="3" rows="10" columns="2">
29829 <features>
29830 <column alignment="block" valignment="top" leftline="true" width="40col%">
29831 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
29832 <row topline="true" bottomline="true" endhead="true">
29833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29834 \begin_inset Text
29835
29836 \begin_layout Standard
29837
29838 \series bold
29839 Subject / Title
29840 \end_layout
29841
29842 \end_inset
29843 </cell>
29844 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29845 \begin_inset Text
29846
29847 \begin_layout Standard
29848
29849 \series bold
29850 Filename / Where to get
29851 \end_layout
29852
29853 \end_inset
29854 </cell>
29855 </row>
29856 <row topline="true">
29857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29858 \begin_inset Text
29859
29860 \begin_layout Standard
29861 SDCC Compiler User Guide
29862 \end_layout
29863
29864 \end_inset
29865 </cell>
29866 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29867 \begin_inset Text
29868
29869 \begin_layout Standard
29870 You're reading it right now
29871 \emph on
29872  \InsetSpace ~
29873 \InsetSpace ~
29874 \InsetSpace ~
29875
29876 \hfill
29877 online at:
29878 \emph default
29879
29880 \newline
29881
29882 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
29883
29884 \end_inset
29885
29886
29887 \end_layout
29888
29889 \end_inset
29890 </cell>
29891 </row>
29892 <row topline="true">
29893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29894 \begin_inset Text
29895
29896 \begin_layout Standard
29897 Changelog of SDCC
29898 \end_layout
29899
29900 \end_inset
29901 </cell>
29902 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29903 \begin_inset Text
29904
29905 \begin_layout Standard
29906 sdcc/Changelog
29907 \emph on
29908  \InsetSpace ~
29909 \InsetSpace ~
29910 \InsetSpace ~
29911
29912 \hfill
29913 online at:
29914 \emph default
29915
29916 \newline
29917
29918 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
29919
29920 \end_inset
29921
29922
29923 \end_layout
29924
29925 \end_inset
29926 </cell>
29927 </row>
29928 <row topline="true">
29929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29930 \begin_inset Text
29931
29932 \begin_layout Standard
29933 ASXXXX
29934 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
29935
29936 \end_inset
29937
29938
29939 \begin_inset LatexCommand \index{Assembler documentation}
29940
29941 \end_inset
29942
29943  Assemblers and
29944 \newline
29945 ASLINK
29946 \begin_inset LatexCommand \index{aslink}
29947
29948 \end_inset
29949
29950
29951 \begin_inset LatexCommand \index{Linker documentation}
29952
29953 \end_inset
29954
29955  Relocating Linker
29956 \end_layout
29957
29958 \end_inset
29959 </cell>
29960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29961 \begin_inset Text
29962
29963 \begin_layout Standard
29964 sdcc/as/doc/asxhtm.html 
29965 \emph on
29966 \InsetSpace ~
29967 \InsetSpace ~
29968 \InsetSpace ~
29969
29970 \hfill
29971 online at:
29972 \emph default
29973
29974 \newline
29975
29976 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
29977
29978 \end_inset
29979
29980
29981 \end_layout
29982
29983 \end_inset
29984 </cell>
29985 </row>
29986 <row topline="true">
29987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29988 \begin_inset Text
29989
29990 \begin_layout Standard
29991 SDCC regression test
29992 \begin_inset LatexCommand \index{Regression test}
29993
29994 \end_inset
29995
29996
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 sdcc/doc/test_suite_spec.pdf 
30006 \emph on
30007 \InsetSpace ~
30008 \InsetSpace ~
30009 \InsetSpace ~
30010
30011 \hfill
30012 online at:
30013 \emph default
30014
30015 \newline
30016
30017 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30018
30019 \end_inset
30020
30021
30022 \end_layout
30023
30024 \end_inset
30025 </cell>
30026 </row>
30027 <row topline="true">
30028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30029 \begin_inset Text
30030
30031 \begin_layout Standard
30032 Various notes
30033 \end_layout
30034
30035 \end_inset
30036 </cell>
30037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30038 \begin_inset Text
30039
30040 \begin_layout Standard
30041 sdcc/doc/* 
30042 \emph on
30043 \InsetSpace ~
30044 \InsetSpace ~
30045 \InsetSpace ~
30046
30047 \hfill
30048 online at:
30049 \emph default
30050
30051 \newline
30052
30053 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30054
30055 \end_inset
30056
30057
30058 \end_layout
30059
30060 \end_inset
30061 </cell>
30062 </row>
30063 <row topline="true">
30064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30065 \begin_inset Text
30066
30067 \begin_layout Standard
30068 Notes on debugging with SDCDB
30069 \begin_inset LatexCommand \index{SDCDB (debugger)}
30070
30071 \end_inset
30072
30073
30074 \end_layout
30075
30076 \end_inset
30077 </cell>
30078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30079 \begin_inset Text
30080
30081 \begin_layout Standard
30082 sdcc/debugger/README 
30083 \emph on
30084 \InsetSpace ~
30085 \InsetSpace ~
30086 \InsetSpace ~
30087
30088 \hfill
30089 online at
30090 \emph default
30091 :
30092 \newline
30093
30094 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30095
30096 \end_inset
30097
30098
30099 \end_layout
30100
30101 \end_inset
30102 </cell>
30103 </row>
30104 <row topline="true">
30105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30106 \begin_inset Text
30107
30108 \begin_layout Standard
30109 uCsim
30110 \begin_inset LatexCommand \index{uCsim}
30111
30112 \end_inset
30113
30114  Software simulator for microcontrollers
30115 \end_layout
30116
30117 \end_inset
30118 </cell>
30119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30120 \begin_inset Text
30121
30122 \begin_layout Standard
30123
30124 \family roman
30125 \series medium
30126 \shape up
30127 \size normal
30128 \emph off
30129 \bar no
30130 \noun off
30131 \color none
30132 sdcc/sim/ucsim/doc
30133 \family default
30134 \series default
30135 \shape default
30136 \size default
30137 \emph default
30138 \bar default
30139 \noun default
30140 /index.html 
30141 \emph on
30142 \InsetSpace ~
30143 \InsetSpace ~
30144 \InsetSpace ~
30145
30146 \hfill
30147 online at:
30148 \emph default
30149
30150 \newline
30151
30152 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30153
30154 \end_inset
30155
30156
30157 \end_layout
30158
30159 \end_inset
30160 </cell>
30161 </row>
30162 <row topline="true">
30163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30164 \begin_inset Text
30165
30166 \begin_layout Standard
30167 Temporary notes on the pic16
30168 \begin_inset LatexCommand \index{PIC16}
30169
30170 \end_inset
30171
30172  port
30173 \end_layout
30174
30175 \end_inset
30176 </cell>
30177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30178 \begin_inset Text
30179
30180 \begin_layout Standard
30181 sdcc/src/pic16/NOTES 
30182 \emph on
30183 \InsetSpace ~
30184 \InsetSpace ~
30185 \InsetSpace ~
30186
30187 \hfill
30188 online at:
30189 \newline
30190
30191 \emph default
30192
30193 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30194
30195 \end_inset
30196
30197
30198 \end_layout
30199
30200 \end_inset
30201 </cell>
30202 </row>
30203 <row topline="true" bottomline="true">
30204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30205 \begin_inset Text
30206
30207 \begin_layout Standard
30208 SDCC internal documentation (debugging file format)
30209 \end_layout
30210
30211 \end_inset
30212 </cell>
30213 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30214 \begin_inset Text
30215
30216 \begin_layout Standard
30217 sdcc/doc/
30218 \family roman
30219 \series medium
30220 \shape up
30221 \size normal
30222 \emph off
30223 \bar no
30224 \noun off
30225 \color none
30226 cdbfileformat.pd
30227 \family default
30228 \series default
30229 \shape default
30230 \size default
30231 \emph default
30232 \bar default
30233 \noun default
30234 f
30235 \emph on
30236  \InsetSpace ~
30237 \InsetSpace ~
30238 \InsetSpace ~
30239
30240 \hfill
30241 online at:
30242 \emph default
30243
30244 \newline
30245
30246 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30247
30248 \end_inset
30249
30250
30251 \end_layout
30252
30253 \end_inset
30254 </cell>
30255 </row>
30256 </lyxtabular>
30257
30258 \end_inset
30259
30260
30261 \newline
30262
30263 \end_layout
30264
30265 \begin_layout Section
30266 Related open source tools
30267 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
30268
30269 \end_inset
30270
30271
30272 \begin_inset LatexCommand \index{Related tools}
30273
30274 \end_inset
30275
30276
30277 \end_layout
30278
30279 \begin_layout Standard
30280 \align left
30281 \begin_inset Tabular
30282 <lyxtabular version="3" rows="14" columns="3">
30283 <features>
30284 <column alignment="left" valignment="top" leftline="true" width="0pt">
30285 <column alignment="block" valignment="top" leftline="true" width="30line%">
30286 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30287 <row topline="true" bottomline="true">
30288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30289 \begin_inset Text
30290
30291 \begin_layout Standard
30292
30293 \series bold
30294 Name
30295 \end_layout
30296
30297 \end_inset
30298 </cell>
30299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30300 \begin_inset Text
30301
30302 \begin_layout Standard
30303
30304 \series bold
30305 Purpose
30306 \end_layout
30307
30308 \end_inset
30309 </cell>
30310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30311 \begin_inset Text
30312
30313 \begin_layout Standard
30314
30315 \series bold
30316 Where to get
30317 \end_layout
30318
30319 \end_inset
30320 </cell>
30321 </row>
30322 <row topline="true">
30323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30324 \begin_inset Text
30325
30326 \begin_layout Standard
30327 gpsim
30328 \begin_inset LatexCommand \index{gpsim (pic simulator)}
30329
30330 \end_inset
30331
30332
30333 \end_layout
30334
30335 \end_inset
30336 </cell>
30337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30338 \begin_inset Text
30339
30340 \begin_layout Standard
30341 PIC simulator
30342 \end_layout
30343
30344 \end_inset
30345 </cell>
30346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30347 \begin_inset Text
30348
30349 \begin_layout Standard
30350 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
30351
30352 \end_inset
30353
30354
30355 \end_layout
30356
30357 \end_inset
30358 </cell>
30359 </row>
30360 <row topline="true">
30361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30362 \begin_inset Text
30363
30364 \begin_layout Standard
30365 gputils
30366 \begin_inset LatexCommand \index{gputils (pic tools)}
30367
30368 \end_inset
30369
30370
30371 \end_layout
30372
30373 \end_inset
30374 </cell>
30375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30376 \begin_inset Text
30377
30378 \begin_layout Standard
30379 GNU PIC utilities
30380 \end_layout
30381
30382 \end_inset
30383 </cell>
30384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30385 \begin_inset Text
30386
30387 \begin_layout Standard
30388 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
30389
30390 \end_inset
30391
30392
30393 \end_layout
30394
30395 \end_inset
30396 </cell>
30397 </row>
30398 <row topline="true">
30399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30400 \begin_inset Text
30401
30402 \begin_layout Standard
30403 flP5
30404 \end_layout
30405
30406 \end_inset
30407 </cell>
30408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30409 \begin_inset Text
30410
30411 \begin_layout Standard
30412 PIC programmer
30413 \end_layout
30414
30415 \end_inset
30416 </cell>
30417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30418 \begin_inset Text
30419
30420 \begin_layout Standard
30421 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
30422
30423 \end_inset
30424
30425
30426 \end_layout
30427
30428 \end_inset
30429 </cell>
30430 </row>
30431 <row topline="true">
30432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30433 \begin_inset Text
30434
30435 \begin_layout Standard
30436 ec2drv/newcdb
30437 \end_layout
30438
30439 \end_inset
30440 </cell>
30441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30442 \begin_inset Text
30443
30444 \begin_layout Standard
30445 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
30446  (Unix only)
30447 \end_layout
30448
30449 \end_inset
30450 </cell>
30451 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30452 \begin_inset Text
30453
30454 \begin_layout Standard
30455 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
30456
30457 \end_inset
30458
30459
30460 \end_layout
30461
30462 \end_inset
30463 </cell>
30464 </row>
30465 <row topline="true">
30466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30467 \begin_inset Text
30468
30469 \begin_layout Standard
30470 indent
30471 \begin_inset LatexCommand \index{indent (source formatting tool)}
30472
30473 \end_inset
30474
30475
30476 \end_layout
30477
30478 \end_inset
30479 </cell>
30480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30481 \begin_inset Text
30482
30483 \begin_layout Standard
30484 Formats C source - Master of the white spaces
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 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
30494
30495 \end_inset
30496
30497
30498 \end_layout
30499
30500 \end_inset
30501 </cell>
30502 </row>
30503 <row topline="true">
30504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30505 \begin_inset Text
30506
30507 \begin_layout Standard
30508 srecord
30509 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
30510
30511 \end_inset
30512
30513
30514 \end_layout
30515
30516 \end_inset
30517 </cell>
30518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30519 \begin_inset Text
30520
30521 \begin_layout Standard
30522 Object file conversion, checksumming, ...
30523 \end_layout
30524
30525 \end_inset
30526 </cell>
30527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30528 \begin_inset Text
30529
30530 \begin_layout Standard
30531 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
30532
30533 \end_inset
30534
30535
30536 \end_layout
30537
30538 \end_inset
30539 </cell>
30540 </row>
30541 <row topline="true">
30542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30543 \begin_inset Text
30544
30545 \begin_layout Standard
30546 objdump
30547 \begin_inset LatexCommand \index{objdump (tool)}
30548
30549 \end_inset
30550
30551
30552 \end_layout
30553
30554 \end_inset
30555 </cell>
30556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30557 \begin_inset Text
30558
30559 \begin_layout Standard
30560 Object file conversion, ...
30561 \end_layout
30562
30563 \end_inset
30564 </cell>
30565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30566 \begin_inset Text
30567
30568 \begin_layout Standard
30569 Part of binutils (should be there anyway)
30570 \end_layout
30571
30572 \end_inset
30573 </cell>
30574 </row>
30575 <row topline="true">
30576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30577 \begin_inset Text
30578
30579 \begin_layout Standard
30580 cmon51
30581 \end_layout
30582
30583 \end_inset
30584 </cell>
30585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30586 \begin_inset Text
30587
30588 \begin_layout Standard
30589 8051 monitor (hex up-/download, single step, disassemble)
30590 \end_layout
30591
30592 \end_inset
30593 </cell>
30594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30595 \begin_inset Text
30596
30597 \begin_layout Standard
30598 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
30599
30600 \end_inset
30601
30602
30603 \end_layout
30604
30605 \end_inset
30606 </cell>
30607 </row>
30608 <row topline="true">
30609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30610 \begin_inset Text
30611
30612 \begin_layout Standard
30613 doxygen
30614 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
30615
30616 \end_inset
30617
30618
30619 \end_layout
30620
30621 \end_inset
30622 </cell>
30623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30624 \begin_inset Text
30625
30626 \begin_layout Standard
30627 Source code documentation system
30628 \end_layout
30629
30630 \end_inset
30631 </cell>
30632 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30633 \begin_inset Text
30634
30635 \begin_layout Standard
30636 \begin_inset LatexCommand \url{http://www.doxygen.org}
30637
30638 \end_inset
30639
30640
30641 \end_layout
30642
30643 \end_inset
30644 </cell>
30645 </row>
30646 <row topline="true">
30647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30648 \begin_inset Text
30649
30650 \begin_layout Standard
30651 kdevelop
30652 \end_layout
30653
30654 \end_inset
30655 </cell>
30656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30657 \begin_inset Text
30658
30659 \begin_layout Standard
30660 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
30661 \end_layout
30662
30663 \end_inset
30664 </cell>
30665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30666 \begin_inset Text
30667
30668 \begin_layout Standard
30669 \begin_inset LatexCommand \url{http://www.kdevelop.org}
30670
30671 \end_inset
30672
30673
30674 \end_layout
30675
30676 \end_inset
30677 </cell>
30678 </row>
30679 <row topline="true">
30680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30681 \begin_inset Text
30682
30683 \begin_layout Standard
30684 paulmon
30685 \end_layout
30686
30687 \end_inset
30688 </cell>
30689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30690 \begin_inset Text
30691
30692 \begin_layout Standard
30693 8051 monitor (hex up-/download, single step, disassemble)
30694 \end_layout
30695
30696 \end_inset
30697 </cell>
30698 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30699 \begin_inset Text
30700
30701 \begin_layout Standard
30702 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
30703
30704 \end_inset
30705
30706
30707 \end_layout
30708
30709 \end_inset
30710 </cell>
30711 </row>
30712 <row topline="true">
30713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30714 \begin_inset Text
30715
30716 \begin_layout Standard
30717 splint
30718 \begin_inset LatexCommand \index{splint (syntax checking tool)}
30719
30720 \end_inset
30721
30722
30723 \end_layout
30724
30725 \end_inset
30726 </cell>
30727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30728 \begin_inset Text
30729
30730 \begin_layout Standard
30731 Statically checks c sources (see 
30732 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
30733
30734 \end_inset
30735
30736 )
30737 \end_layout
30738
30739 \end_inset
30740 </cell>
30741 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30742 \begin_inset Text
30743
30744 \begin_layout Standard
30745 \begin_inset LatexCommand \url{http://www.splint.org}
30746
30747 \end_inset
30748
30749
30750 \end_layout
30751
30752 \end_inset
30753 </cell>
30754 </row>
30755 <row topline="true" bottomline="true">
30756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30757 \begin_inset Text
30758
30759 \begin_layout Standard
30760 ddd
30761 \begin_inset LatexCommand \index{DDD (debugger)}
30762
30763 \end_inset
30764
30765
30766 \end_layout
30767
30768 \end_inset
30769 </cell>
30770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30771 \begin_inset Text
30772
30773 \begin_layout Standard
30774 Debugger, serves nicely as GUI to SDCDB
30775 \begin_inset LatexCommand \index{SDCDB (debugger)}
30776
30777 \end_inset
30778
30779  (Unix only)
30780 \end_layout
30781
30782 \end_inset
30783 </cell>
30784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30785 \begin_inset Text
30786
30787 \begin_layout Standard
30788 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
30789
30790 \end_inset
30791
30792
30793 \end_layout
30794
30795 \end_inset
30796 </cell>
30797 </row>
30798 </lyxtabular>
30799
30800 \end_inset
30801
30802
30803 \newline
30804
30805 \end_layout
30806
30807 \begin_layout Section
30808 Related documentation / recommended reading
30809 \end_layout
30810
30811 \begin_layout Standard
30812 \align left
30813 \begin_inset Tabular
30814 <lyxtabular version="3" rows="7" columns="3">
30815 <features>
30816 <column alignment="left" valignment="top" leftline="true" width="0pt">
30817 <column alignment="left" valignment="top" leftline="true" width="0">
30818 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30819 <row topline="true" bottomline="true">
30820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30821 \begin_inset Text
30822
30823 \begin_layout Standard
30824
30825 \series bold
30826 Name
30827 \end_layout
30828
30829 \end_inset
30830 </cell>
30831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30832 \begin_inset Text
30833
30834 \begin_layout Standard
30835
30836 \series bold
30837 Subject / Title
30838 \end_layout
30839
30840 \end_inset
30841 </cell>
30842 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30843 \begin_inset Text
30844
30845 \begin_layout Standard
30846
30847 \series bold
30848 Where to get
30849 \end_layout
30850
30851 \end_inset
30852 </cell>
30853 </row>
30854 <row topline="true">
30855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30856 \begin_inset Text
30857
30858 \begin_layout Standard
30859
30860 \family roman
30861 \series medium
30862 \shape up
30863 \size normal
30864 \emph off
30865 \bar no
30866 \noun off
30867 \color none
30868 c-refcard.pdf
30869 \end_layout
30870
30871 \end_inset
30872 </cell>
30873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30874 \begin_inset Text
30875
30876 \begin_layout Standard
30877 C Reference Card
30878 \begin_inset LatexCommand \index{C Reference card}
30879
30880 \end_inset
30881
30882 , 2 pages
30883 \end_layout
30884
30885 \end_inset
30886 </cell>
30887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30888 \begin_inset Text
30889
30890 \begin_layout Standard
30891 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
30892
30893 \end_inset
30894
30895
30896 \end_layout
30897
30898 \end_inset
30899 </cell>
30900 </row>
30901 <row topline="true">
30902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30903 \begin_inset Text
30904
30905 \begin_layout Standard
30906 c-faq
30907 \end_layout
30908
30909 \end_inset
30910 </cell>
30911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30912 \begin_inset Text
30913
30914 \begin_layout Standard
30915 C-FAQ
30916 \begin_inset LatexCommand \index{C FAQ}
30917
30918 \end_inset
30919
30920
30921 \end_layout
30922
30923 \end_inset
30924 </cell>
30925 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30926 \begin_inset Text
30927
30928 \begin_layout Standard
30929 \begin_inset LatexCommand \url{http://www.c-faq.com}
30930
30931 \end_inset
30932
30933
30934 \end_layout
30935
30936 \end_inset
30937 </cell>
30938 </row>
30939 <row topline="true">
30940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30941 \begin_inset Text
30942
30943 \begin_layout Standard
30944 ISO/IEC 9899:TC2
30945 \end_layout
30946
30947 \end_inset
30948 </cell>
30949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30950 \begin_inset Text
30951
30952 \begin_layout Standard
30953 \begin_inset Quotes sld
30954 \end_inset
30955
30956 C-Standard
30957 \begin_inset Quotes srd
30958 \end_inset
30959
30960
30961 \end_layout
30962
30963 \end_inset
30964 </cell>
30965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30966 \begin_inset Text
30967
30968 \begin_layout Standard
30969
30970 \size footnotesize
30971 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
30972
30973 \end_inset
30974
30975
30976 \end_layout
30977
30978 \end_inset
30979 </cell>
30980 </row>
30981 <row topline="true">
30982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30983 \begin_inset Text
30984
30985 \begin_layout Standard
30986 ISO/IEC DTR 18037
30987 \end_layout
30988
30989 \end_inset
30990 </cell>
30991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30992 \begin_inset Text
30993
30994 \begin_layout Standard
30995 \begin_inset Quotes sld
30996 \end_inset
30997
30998 Extensions for Embedded C
30999 \begin_inset Quotes srd
31000 \end_inset
31001
31002
31003 \end_layout
31004
31005 \end_inset
31006 </cell>
31007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31008 \begin_inset Text
31009
31010 \begin_layout Standard
31011
31012 \size footnotesize
31013 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31014
31015 \end_inset
31016
31017
31018 \end_layout
31019
31020 \end_inset
31021 </cell>
31022 </row>
31023 <row topline="true">
31024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31025 \begin_inset Text
31026
31027 \begin_layout Standard
31028
31029 \end_layout
31030
31031 \end_inset
31032 </cell>
31033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31034 \begin_inset Text
31035
31036 \begin_layout Standard
31037 Latest datasheet of target CPU
31038 \end_layout
31039
31040 \end_inset
31041 </cell>
31042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31043 \begin_inset Text
31044
31045 \begin_layout Standard
31046 vendor
31047 \end_layout
31048
31049 \end_inset
31050 </cell>
31051 </row>
31052 <row topline="true" bottomline="true">
31053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31054 \begin_inset Text
31055
31056 \begin_layout Standard
31057
31058 \end_layout
31059
31060 \end_inset
31061 </cell>
31062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31063 \begin_inset Text
31064
31065 \begin_layout Standard
31066 Revision history of datasheet
31067 \end_layout
31068
31069 \end_inset
31070 </cell>
31071 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31072 \begin_inset Text
31073
31074 \begin_layout Standard
31075 vendor
31076 \end_layout
31077
31078 \end_inset
31079 </cell>
31080 </row>
31081 </lyxtabular>
31082
31083 \end_inset
31084
31085
31086 \newline
31087
31088 \end_layout
31089
31090 \begin_layout Section
31091 Application notes specifically for SDCC
31092 \end_layout
31093
31094 \begin_layout Standard
31095 SDCC makes no claims about the completeness of this list and about up-to-datenes
31096 s or correctness of the application notes
31097 \begin_inset LatexCommand \index{Application notes}
31098
31099 \end_inset
31100
31101 .
31102 \end_layout
31103
31104 \begin_layout Standard
31105 \align left
31106
31107 \size footnotesize
31108 \begin_inset Tabular
31109 <lyxtabular version="3" rows="7" columns="3">
31110 <features>
31111 <column alignment="block" valignment="top" leftline="true" width="17col%">
31112 <column alignment="block" valignment="top" leftline="true" width="27col%">
31113 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
31114 <row topline="true" bottomline="true">
31115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31116 \begin_inset Text
31117
31118 \begin_layout Standard
31119
31120 \series bold
31121 \size footnotesize
31122 Vendor
31123 \end_layout
31124
31125 \end_inset
31126 </cell>
31127 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31128 \begin_inset Text
31129
31130 \begin_layout Standard
31131
31132 \series bold
31133 \size footnotesize
31134 Subject / Title
31135 \end_layout
31136
31137 \end_inset
31138 </cell>
31139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31140 \begin_inset Text
31141
31142 \begin_layout Standard
31143
31144 \series bold
31145 \size footnotesize
31146 Where to get
31147 \end_layout
31148
31149 \end_inset
31150 </cell>
31151 </row>
31152 <row topline="true">
31153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31154 \begin_inset Text
31155
31156 \begin_layout Standard
31157
31158 \size footnotesize
31159 Maxim / Dallas
31160 \end_layout
31161
31162 \end_inset
31163 </cell>
31164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31165 \begin_inset Text
31166
31167 \begin_layout Standard
31168
31169 \size footnotesize
31170 Using the SDCC Compiler for the DS80C400
31171 \begin_inset LatexCommand \index{DS80C400}
31172
31173 \end_inset
31174
31175
31176 \end_layout
31177
31178 \end_inset
31179 </cell>
31180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31181 \begin_inset Text
31182
31183 \begin_layout Standard
31184
31185 \size footnotesize
31186 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31187
31188 \end_inset
31189
31190
31191 \end_layout
31192
31193 \end_inset
31194 </cell>
31195 </row>
31196 <row topline="true">
31197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31198 \begin_inset Text
31199
31200 \begin_layout Standard
31201
31202 \size footnotesize
31203 Maxim / Dallas
31204 \end_layout
31205
31206 \end_inset
31207 </cell>
31208 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31209 \begin_inset Text
31210
31211 \begin_layout Standard
31212
31213 \size footnotesize
31214 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31215 \begin_inset LatexCommand \index{DS89C4x0}
31216
31217 \end_inset
31218
31219  Family of Microcontrollers
31220 \end_layout
31221
31222 \end_inset
31223 </cell>
31224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31225 \begin_inset Text
31226
31227 \begin_layout Standard
31228
31229 \size footnotesize
31230 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31231
31232 \end_inset
31233
31234
31235 \end_layout
31236
31237 \end_inset
31238 </cell>
31239 </row>
31240 <row topline="true">
31241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31242 \begin_inset Text
31243
31244 \begin_layout Standard
31245
31246 \size footnotesize
31247 Silicon Laboratories / Cygnal
31248 \end_layout
31249
31250 \end_inset
31251 </cell>
31252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31253 \begin_inset Text
31254
31255 \begin_layout Standard
31256
31257 \size footnotesize
31258 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31259 \begin_inset LatexCommand \index{IDE}
31260
31261 \end_inset
31262
31263
31264 \end_layout
31265
31266 \end_inset
31267 </cell>
31268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31269 \begin_inset Text
31270
31271 \begin_layout Standard
31272
31273 \size footnotesize
31274 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
31275
31276 \end_inset
31277
31278
31279 \end_layout
31280
31281 \end_inset
31282 </cell>
31283 </row>
31284 <row topline="true">
31285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31286 \begin_inset Text
31287
31288 \begin_layout Standard
31289
31290 \size footnotesize
31291 Ramtron / Goal Semiconductor
31292 \end_layout
31293
31294 \end_inset
31295 </cell>
31296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31297 \begin_inset Text
31298
31299 \begin_layout Standard
31300
31301 \size footnotesize
31302 Interfacing SDCC to Syn and Textpad
31303 \end_layout
31304
31305 \end_inset
31306 </cell>
31307 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31308 \begin_inset Text
31309
31310 \begin_layout Standard
31311
31312 \size footnotesize
31313 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31314
31315 \end_inset
31316
31317
31318 \end_layout
31319
31320 \end_inset
31321 </cell>
31322 </row>
31323 <row topline="true">
31324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31325 \begin_inset Text
31326
31327 \begin_layout Standard
31328
31329 \size footnotesize
31330 Ramtron / Goal Semiconductor
31331 \end_layout
31332
31333 \end_inset
31334 </cell>
31335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31336 \begin_inset Text
31337
31338 \begin_layout Standard
31339
31340 \size footnotesize
31341 Installing and Configuring SDCC and Crimson Editor 
31342 \end_layout
31343
31344 \end_inset
31345 </cell>
31346 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31347 \begin_inset Text
31348
31349 \begin_layout Standard
31350
31351 \size footnotesize
31352 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31353
31354 \end_inset
31355
31356
31357 \end_layout
31358
31359 \end_inset
31360 </cell>
31361 </row>
31362 <row topline="true" bottomline="true">
31363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31364 \begin_inset Text
31365
31366 \begin_layout Standard
31367
31368 \size footnotesize
31369 Texas Instruments
31370 \end_layout
31371
31372 \end_inset
31373 </cell>
31374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31375 \begin_inset Text
31376
31377 \begin_layout Standard
31378
31379 \size footnotesize
31380 MSC12xx Programming with SDCC
31381 \end_layout
31382
31383 \end_inset
31384 </cell>
31385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31386 \begin_inset Text
31387
31388 \begin_layout Standard
31389
31390 \size footnotesize
31391 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
31392
31393 \end_inset
31394
31395
31396 \end_layout
31397
31398 \end_inset
31399 </cell>
31400 </row>
31401 </lyxtabular>
31402
31403 \end_inset
31404
31405
31406 \end_layout
31407
31408 \begin_layout Section
31409 Some Questions
31410 \end_layout
31411
31412 \begin_layout Standard
31413 Some questions answered, some pointers given - it might be time to in turn
31414  ask 
31415 \emph on
31416 you
31417 \emph default
31418  some questions: 
31419 \end_layout
31420
31421 \begin_layout Itemize
31422 can you solve your project with the selected microcontroller? Would you
31423  find out early or rather late that your target is too small/slow/whatever?
31424  Can you switch to a slightly better device if it doesn't fit?
31425 \end_layout
31426
31427 \begin_layout Itemize
31428 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
31429  and/or another programming language be more adequate? Would an operating
31430  system on the target device help?
31431 \end_layout
31432
31433 \begin_layout Itemize
31434 if you solved the problem, will the marketing department be happy?
31435 \end_layout
31436
31437 \begin_layout Itemize
31438 if the marketing department is happy, will customers be happy?
31439 \end_layout
31440
31441 \begin_layout Itemize
31442 if you're the project manager, marketing department and maybe even the customer
31443  in one person, have you tried to see the project from the outside?
31444 \end_layout
31445
31446 \begin_layout Itemize
31447 is the project done if you think it is done? Or is just that other interface/pro
31448 tocol/feature/configuration/option missing? How about website, manual(s),
31449  internationali(z|s)ation, packaging, labels, 2nd source for components,
31450  electromagnetic compatability/interference, documentation for production,
31451  production test software, update mechanism, patent issues?
31452 \end_layout
31453
31454 \begin_layout Itemize
31455 is your project adequately positioned in that magic triangle: fame, fortune,
31456  fun?
31457 \end_layout
31458
31459 \begin_layout Standard
31460 Maybe not all answers to these questions are known and some answers may
31461  even be 
31462 \emph on
31463 no
31464 \emph default
31465 , nevertheless knowing these questions may help you to avoid burnout
31466 \begin_inset Foot
31467 status open
31468
31469 \begin_layout Standard
31470 burnout is bad for electronic devices, programmers and motorcycle tyres
31471 \end_layout
31472
31473 \end_inset
31474
31475 .
31476  Chances are you didn't want to hear some of them...
31477 \end_layout
31478
31479 \begin_layout Chapter
31480 Support
31481 \begin_inset LatexCommand \index{Support}
31482
31483 \end_inset
31484
31485
31486 \end_layout
31487
31488 \begin_layout Standard
31489 SDCC has grown to be a large project.
31490  The compiler alone (without the preprocessor, assembler and linker) is
31491  well over 150,000 lines of code (blank stripped).
31492  The open source nature of this project is a key to its continued growth
31493  and support.
31494  You gain the benefit and support of many active software developers and
31495  end users.
31496  Is SDCC perfect? No, that's why we need your help.
31497  The developers take pride in fixing reported bugs.
31498  You can help by reporting the bugs and helping other SDCC users.
31499  There are lots of ways to contribute, and we encourage you to take part
31500  in making SDCC a great software package.
31501  
31502 \end_layout
31503
31504 \begin_layout Standard
31505 The SDCC project is hosted on the SDCC sourceforge site at 
31506 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
31507
31508 \end_inset
31509
31510 .
31511  You'll find the complete set of mailing lists
31512 \begin_inset LatexCommand \index{Mailing list(s)}
31513
31514 \end_inset
31515
31516 , forums, bug reporting system, patch submission
31517 \begin_inset LatexCommand \index{Patch submission}
31518
31519 \end_inset
31520
31521  system, download
31522 \begin_inset LatexCommand \index{download}
31523
31524 \end_inset
31525
31526  area and Subversion code repository
31527 \begin_inset LatexCommand \index{Subversion code repository}
31528
31529 \end_inset
31530
31531  there.
31532 \end_layout
31533
31534 \begin_layout Section
31535 Reporting Bugs
31536 \begin_inset LatexCommand \index{Bug reporting}
31537
31538 \end_inset
31539
31540
31541 \begin_inset LatexCommand \index{Reporting bugs}
31542
31543 \end_inset
31544
31545
31546 \end_layout
31547
31548 \begin_layout Standard
31549 The recommended way of reporting bugs is using the infrastructure of the
31550  sourceforge site.
31551  You can follow the status of bug reports there and have an overview about
31552  the known bugs.
31553 \end_layout
31554
31555 \begin_layout Standard
31556 Bug reports are automatically forwarded to the developer mailing list and
31557  will be fixed ASAP.
31558  When reporting a bug, it is very useful to include a small test program
31559  (the smaller the better) which reproduces the problem.
31560  If you can isolate the problem by looking at the generated assembly code,
31561  this can be very helpful.
31562  Compiling your program with the -
31563 \begin_inset ERT
31564 status collapsed
31565
31566 \begin_layout Standard
31567
31568
31569 \backslash
31570 /
31571 \end_layout
31572
31573 \end_inset
31574
31575 -dumpall
31576 \begin_inset LatexCommand \index{-\/-dumpall}
31577
31578 \end_inset
31579
31580  option can sometimes be useful in locating optimization problems.
31581  When reporting a bug please make sure you:
31582 \end_layout
31583
31584 \begin_layout Enumerate
31585 Attach the code you are compiling with SDCC.
31586  
31587 \end_layout
31588
31589 \begin_layout Enumerate
31590 Specify the exact command you use to run SDCC, or attach your Makefile.
31591  
31592 \end_layout
31593
31594 \begin_layout Enumerate
31595 Specify the SDCC version (type "
31596 \family sans
31597 \series bold
31598 sdcc -v
31599 \family default
31600 \series default
31601 "), your platform, and operating system.
31602  
31603 \end_layout
31604
31605 \begin_layout Enumerate
31606 Provide an exact copy of any error message or incorrect output.
31607  
31608 \end_layout
31609
31610 \begin_layout Enumerate
31611 Put something meaningful in the subject of your message.
31612 \end_layout
31613
31614 \begin_layout Standard
31615 Please attempt to include these 5 important parts, as applicable, in all
31616  requests for support or when reporting any problems or bugs with SDCC.
31617  Though this will make your message lengthy, it will greatly improve your
31618  chance that SDCC users and developers will be able to help you.
31619  Some SDCC developers are frustrated by bug reports without code provided
31620  that they can use to reproduce and ultimately fix the problem, so please
31621  be sure to provide sample code if you are reporting a bug! 
31622 \end_layout
31623
31624 \begin_layout Standard
31625 Please have a short check that you are using a recent version of SDCC and
31626  the bug is not yet known.
31627  This is the link for reporting bugs: 
31628 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
31629
31630 \end_inset
31631
31632 .
31633  With SDCC on average having more than 200 downloads
31634 \begin_inset LatexCommand \index{download}
31635
31636 \end_inset
31637
31638  on sourceforge per day
31639 \begin_inset Foot
31640 status open
31641
31642 \begin_layout Standard
31643 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
31644  between 2002 and 2005.
31645  This does not include other methods of distribution.
31646 \end_layout
31647
31648 \end_inset
31649
31650  there must be some users.
31651  So it's not exactly easy to find a new bug.
31652  If you find one we need it: 
31653 \emph on
31654 reporting bugs is good
31655 \emph default
31656 .
31657 \end_layout
31658
31659 \begin_layout Section
31660 Requesting Features
31661 \begin_inset LatexCommand \label{sub:Requesting-Features}
31662
31663 \end_inset
31664
31665
31666 \begin_inset LatexCommand \index{Feature request}
31667
31668 \end_inset
31669
31670
31671 \begin_inset LatexCommand \index{Requesting features}
31672
31673 \end_inset
31674
31675
31676 \end_layout
31677
31678 \begin_layout Standard
31679 Like bug reports feature requests are forwarded to the developer mailing
31680  list.
31681  This is the link for requesting features: 
31682 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
31683
31684 \end_inset
31685
31686 .
31687 \end_layout
31688
31689 \begin_layout Section
31690 Submitting patches
31691 \end_layout
31692
31693 \begin_layout Standard
31694 Like bug reports contributed patches are forwarded to the developer mailing
31695  list.
31696  This is the link for submitting patches
31697 \begin_inset LatexCommand \index{Patch submission}
31698
31699 \end_inset
31700
31701
31702 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
31703
31704 \end_inset
31705
31706 .
31707 \end_layout
31708
31709 \begin_layout Standard
31710 You need to specify some parameters to the 
31711 \family typewriter
31712 diff
31713 \family default
31714  command for the patches to be useful.
31715  If you modified more than one file a patch created f.e.
31716  with 
31717 \family sans
31718 \series bold
31719
31720 \begin_inset Quotes sld
31721 \end_inset
31722
31723 diff -Naur unmodified_directory modified_directory >my_changes.patch
31724 \begin_inset Quotes srd
31725 \end_inset
31726
31727
31728 \family default
31729 \series default
31730  will be fine, otherwise 
31731 \family sans
31732 \series bold
31733
31734 \begin_inset Quotes sld
31735 \end_inset
31736
31737 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
31738 \begin_inset Quotes srd
31739 \end_inset
31740
31741
31742 \series default
31743  
31744 \family default
31745 will do.
31746 \end_layout
31747
31748 \begin_layout Section
31749 Getting Help
31750 \end_layout
31751
31752 \begin_layout Standard
31753 These links should take you directly to the 
31754 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
31755
31756 \end_inset
31757
31758
31759 \begin_inset Foot
31760 status open
31761
31762 \begin_layout Standard
31763 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
31764  automated messages (mid 2003)
31765 \end_layout
31766
31767 \end_inset
31768
31769  and the 
31770 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
31771
31772 \end_inset
31773
31774 , lists
31775 \begin_inset LatexCommand \index{Mailing list(s)}
31776
31777 \end_inset
31778
31779  and forums are archived and searchable so if you are lucky someone already
31780  had a similar problem.
31781  While mails to the lists themselves are delivered promptly their web front
31782  end on sourceforge sometimes shows a severe time lag (up to several weeks),
31783  if you're seriously using SDCC please consider subscribing to the lists.
31784 \end_layout
31785
31786 \begin_layout Section
31787 ChangeLog
31788 \end_layout
31789
31790 \begin_layout Standard
31791 You can follow the status of the Subversion version
31792 \begin_inset LatexCommand \index{version}
31793
31794 \end_inset
31795
31796  of SDCC by watching the Changelog
31797 \begin_inset LatexCommand \index{Changelog}
31798
31799 \end_inset
31800
31801  in the Subversion repository
31802 \size footnotesize
31803  
31804 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31805
31806 \end_inset
31807
31808 .
31809 \end_layout
31810
31811 \begin_layout Section
31812 Subversion Source Code Repository
31813 \end_layout
31814
31815 \begin_layout Standard
31816 The output of 
31817 \family sans
31818 \series bold
31819 sdcc --version
31820 \family default
31821 \series default
31822  or the filenames of the snapshot versions of SDCC include date and its
31823  Subversion
31824 \begin_inset LatexCommand \index{Subversion code repository}
31825
31826 \end_inset
31827
31828  number.
31829  Subversion allows to download the source of recent or previous versions
31830  
31831 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
31832
31833 \end_inset
31834
31835  (by number or by date).
31836  An on-line source code browser and detailled instructions are also available
31837  there.
31838  SDCC versions starting from 1999 up to now are available (currently the
31839  versions prior to the conversion from cvs
31840 \begin_inset LatexCommand \index{cvs|see{Subversion}}
31841
31842 \end_inset
31843
31844  to Subversion (April 2006) are either by accessible by Subversion or by
31845  cvs).
31846 \end_layout
31847
31848 \begin_layout Section
31849 Release policy
31850 \begin_inset LatexCommand \index{Release policy}
31851
31852 \end_inset
31853
31854
31855 \end_layout
31856
31857 \begin_layout Standard
31858 Historically there often were long delays between official releases and
31859  the sourceforge download area tends to get not updated at all.
31860  Excuses in the past might have referred to problems with live range analysis,
31861  but as this was fixed a while ago, the current problem is that another
31862  excuse has to be found.
31863  Kidding aside, we have to get better there! On the other hand there are
31864  daily snapshots available at 
31865 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
31866
31867 \end_inset
31868
31869 , and you can always build the very last version (hopefully with many bugs
31870  fixed, and features added) from the source code available at 
31871 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
31872
31873 \end_inset
31874
31875 .
31876  A release wiki
31877 \begin_inset LatexCommand \index{wiki}
31878
31879 \end_inset
31880
31881
31882 \begin_inset LatexCommand \index{Release wiki}
31883
31884 \end_inset
31885
31886  at 
31887 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
31888
31889 \end_inset
31890
31891  also holds some information about past and future releases.
31892 \end_layout
31893
31894 \begin_layout Section
31895 Examples
31896 \begin_inset LatexCommand \index{Examples}
31897
31898 \end_inset
31899
31900
31901 \end_layout
31902
31903 \begin_layout Standard
31904 You'll find some small examples in the directory 
31905 \emph on
31906 sdcc/device/examples/.
31907  
31908 \emph default
31909 More examples and libraries are available at
31910 \emph on
31911  The SDCC Open Knowledge Resource 
31912 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
31913
31914 \end_inset
31915
31916  
31917 \emph default
31918 web site or at 
31919 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
31920
31921 \end_inset
31922
31923 .
31924 \end_layout
31925
31926 \begin_layout Standard
31927 \begin_inset Note Note
31928 status collapsed
31929
31930 \begin_layout Standard
31931 I did insert a reference to Paul's web site here although it seems rather
31932  dedicated to a specific 8032 board (I think it's okay because it f.e.
31933  shows LCD/Harddisc interface and has a free 8051 monitor.
31934  Independent 8032 board vendors face hard competition of heavily subsidized
31935  development boards anyway).
31936 \end_layout
31937
31938 \begin_layout Standard
31939 Maybe we should include some links to real world applications.
31940  Preferably pointer to pointers (one for each architecture) so this stays
31941  manageable here?
31942 \end_layout
31943
31944 \end_inset
31945
31946
31947 \end_layout
31948
31949 \begin_layout Section
31950 Quality control
31951 \begin_inset LatexCommand \label{sec:Quality-control}
31952
31953 \end_inset
31954
31955
31956 \begin_inset LatexCommand \index{Quality control}
31957
31958 \end_inset
31959
31960
31961 \end_layout
31962
31963 \begin_layout Standard
31964 The compiler is passed through snaphot build compile and build checks.
31965  The so called 
31966 \shape italic
31967 regression tests
31968 \shape default
31969
31970 \begin_inset LatexCommand \index{Regression test}
31971
31972 \end_inset
31973
31974  check that SDCC itself compiles flawlessly on several host platforms (i386,
31975  Opteron, 64 bit Alpha, ppc64, Mac OS X on PPC, Solaris on Sparc) and checks
31976  the quality of the code generated by SDCC by running the code for several
31977  target platforms through simulators.
31978  The regression test suite comprises more than 100 files which expand to
31979  more than 500 test cases which include more than 4500 tests.
31980  The results of these tests are published daily on SDCC's snapshot page
31981  (click on the red or green symbols on the right side of 
31982 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
31983
31984 \end_inset
31985
31986 ).
31987 \end_layout
31988
31989 \begin_layout Standard
31990 There is a separate document 
31991 \shape italic
31992 test_suite.pdf 
31993 \begin_inset LatexCommand \index{Test suite}
31994
31995 \end_inset
31996
31997
31998 \shape default
31999  
32000 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32001
32002 \end_inset
32003
32004  about the regression test suite.
32005 \end_layout
32006
32007 \begin_layout Standard
32008 You'll find the test code in the directory 
32009 \shape italic
32010 sdcc/support/regression
32011 \shape default
32012 .
32013  You can run these tests manually by running 
32014 \family sans
32015 make
32016 \family default
32017  in this directory (or f.e.
32018  
32019 \family sans
32020 \series bold
32021
32022 \begin_inset Quotes sld
32023 \end_inset
32024
32025 make test-mcs51
32026 \begin_inset Quotes srd
32027 \end_inset
32028
32029
32030 \family default
32031 \series default
32032  if you don't want to run the complete tests).
32033  The test code might also be interesting if you want to look for examples
32034 \begin_inset LatexCommand \index{Examples}
32035
32036 \end_inset
32037
32038  checking corner cases of SDCC or if you plan to submit patches
32039 \begin_inset LatexCommand \index{Patch submission}
32040
32041 \end_inset
32042
32043 .
32044 \end_layout
32045
32046 \begin_layout Standard
32047 The 14bit pic port uses a different set of regression tests 
32048 \begin_inset LatexCommand \index{Regression test (PIC14)}
32049
32050 \end_inset
32051
32052 , you'll find them in the directory 
32053 \shape italic
32054 sdcc/src/regression
32055 \shape default
32056 .
32057 \end_layout
32058
32059 \begin_layout Section
32060 Use of SDCC in Education
32061 \end_layout
32062
32063 \begin_layout Standard
32064 In short: 
32065 \emph on
32066 highly
32067 \emph default
32068  encouraged
32069 \begin_inset Foot
32070 status open
32071
32072 \begin_layout Standard
32073 the phrase "use in education" might evoke the association "
32074 \emph on
32075 only
32076 \emph default
32077  fit for use in education".
32078  This connotation is not intended but nevertheless risked as the licensing
32079  of SDCC makes it difficult to offer educational discounts
32080 \end_layout
32081
32082 \end_inset
32083
32084 .
32085  If your rationales are to:
32086 \end_layout
32087
32088 \begin_layout Enumerate
32089 give students a chance to understand the 
32090 \emph on
32091 complete
32092 \emph default
32093  steps of code generation
32094 \end_layout
32095
32096 \begin_layout Enumerate
32097 have a curriculum that can be extended for years.
32098  Then you could use an fpga board as target and your curriculum will seamlessly
32099  extend from logic synthesis (
32100 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32101
32102 \end_inset
32103
32104
32105 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32106
32107 \end_inset
32108
32109 ), over assembly programming, to C to FPGA compilers (
32110 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32111
32112 \end_inset
32113
32114 ) and to C.
32115 \end_layout
32116
32117 \begin_layout Enumerate
32118 be able to insert excursions about skills like using a revision control
32119  system, submitting/applying patches, using a type-setting (as opposed to
32120  word-processing) engine LyX/LaTeX, using 
32121 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32122
32123 \end_inset
32124
32125 , following some 
32126 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32127
32128 \end_inset
32129
32130 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32131  Source Software, CPU simulation, compiler regression tests
32132 \begin_inset LatexCommand \index{Regression test}
32133
32134 \end_inset
32135
32136 .
32137  
32138 \newline
32139 And if there should be a shortage of ideas then you can always point students
32140  to the ever-growing feature request list 
32141 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32142
32143 \end_inset
32144
32145 .
32146 \end_layout
32147
32148 \begin_layout Enumerate
32149 not tie students to a specific host platform and instead allow them to use
32150  a host platform of 
32151 \emph on
32152 their
32153 \emph default
32154  choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
32155  and eventually 
32156 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32157
32158 \end_inset
32159
32160 )
32161 \end_layout
32162
32163 \begin_layout Enumerate
32164 not encourage students to use illegal copies of educational software
32165 \end_layout
32166
32167 \begin_layout Enumerate
32168 be immune to licensing/availability/price changes of the chosen tool chain
32169 \end_layout
32170
32171 \begin_layout Enumerate
32172 be able to change to a new target platform without having to adopt a new
32173  tool chain
32174 \end_layout
32175
32176 \begin_layout Enumerate
32177 have complete control over and insight into the tool chain
32178 \end_layout
32179
32180 \begin_layout Enumerate
32181 make your students aware about the pros and cons of open source software
32182  development
32183 \end_layout
32184
32185 \begin_layout Enumerate
32186 give back to the public as you are probably at least partially publically
32187  funded
32188 \end_layout
32189
32190 \begin_layout Enumerate
32191 give students a chance to publically prove their skills and to possibly
32192  see a world wide impact
32193 \end_layout
32194
32195 \begin_layout Standard
32196 then SDCC is probably among the first choices.
32197  Well, probably SDCC might be the only choice.
32198 \newpage
32199
32200 \end_layout
32201
32202 \begin_layout Chapter
32203 SDCC Technical Data
32204 \end_layout
32205
32206 \begin_layout Section
32207 Optimizations
32208 \begin_inset LatexCommand \index{Optimizations}
32209
32210 \end_inset
32211
32212
32213 \end_layout
32214
32215 \begin_layout Standard
32216 SDCC performs a host of standard optimizations in addition to some MCU specific
32217  optimizations.
32218  
32219 \end_layout
32220
32221 \begin_layout Subsection
32222 Sub-expression Elimination
32223 \begin_inset LatexCommand \index{Subexpression elimination}
32224
32225 \end_inset
32226
32227
32228 \end_layout
32229
32230 \begin_layout Standard
32231 The compiler does local and 
32232 \emph on
32233 g
32234 \emph default
32235 lobal 
32236 \emph on
32237 c
32238 \emph default
32239 ommon 
32240 \emph on
32241 s
32242 \emph default
32243 ubexpression 
32244 \emph on
32245 e
32246 \emph default
32247 limination, e.g.: 
32248 \end_layout
32249
32250 \begin_layout Verse
32251
32252 \family typewriter
32253 i = x + y + 1; 
32254 \newline
32255 j = x + y;
32256 \end_layout
32257
32258 \begin_layout Standard
32259 will be translated to
32260 \end_layout
32261
32262 \begin_layout Verse
32263
32264 \family typewriter
32265 iTemp = x + y; 
32266 \newline
32267 i = iTemp + 1; 
32268 \newline
32269 j = iTemp;
32270 \end_layout
32271
32272 \begin_layout Standard
32273 Some subexpressions are not as obvious as the above example, e.g.:
32274 \end_layout
32275
32276 \begin_layout Verse
32277
32278 \family typewriter
32279 a->b[i].c = 10; 
32280 \newline
32281 a->b[i].d = 11;
32282 \end_layout
32283
32284 \begin_layout Standard
32285 In this case the address arithmetic a->b[i] will be computed only once;
32286  the equivalent code in C would be.
32287 \end_layout
32288
32289 \begin_layout Verse
32290
32291 \family typewriter
32292 iTemp = a->b[i]; 
32293 \newline
32294 iTemp.c = 10; 
32295 \newline
32296 iTemp.d = 11;
32297 \end_layout
32298
32299 \begin_layout Standard
32300 The compiler will try to keep these temporary variables in registers.
32301 \end_layout
32302
32303 \begin_layout Subsection
32304 Dead-Code Elimination
32305 \begin_inset LatexCommand \index{Dead-code elimination}
32306
32307 \end_inset
32308
32309
32310 \end_layout
32311
32312 \begin_layout Verse
32313
32314 \family typewriter
32315 int global;
32316 \newline
32317
32318 \newline
32319 void f () { 
32320 \newline
32321 \InsetSpace ~
32322 \InsetSpace ~
32323 int i; 
32324 \newline
32325 \InsetSpace ~
32326 \InsetSpace ~
32327 i = 1; \InsetSpace ~
32328 \InsetSpace ~
32329 \InsetSpace ~
32330 \InsetSpace ~
32331 \InsetSpace ~
32332 /* dead store */ 
32333 \newline
32334 \InsetSpace ~
32335 \InsetSpace ~
32336 global = 1;\InsetSpace ~
32337 /* dead
32338  store */ 
32339 \newline
32340 \InsetSpace ~
32341 \InsetSpace ~
32342 global = 2; 
32343 \newline
32344 \InsetSpace ~
32345 \InsetSpace ~
32346 return; 
32347 \newline
32348 \InsetSpace ~
32349 \InsetSpace ~
32350 global = 3;\InsetSpace ~
32351 /* unreachable */ 
32352 \newline
32353 }
32354 \end_layout
32355
32356 \begin_layout Standard
32357 will be changed to
32358 \end_layout
32359
32360 \begin_layout Verse
32361
32362 \family typewriter
32363 int global;
32364 \newline
32365
32366 \newline
32367 void f () {
32368 \newline
32369 \InsetSpace ~
32370 \InsetSpace ~
32371 global = 2; 
32372 \newline
32373 }
32374 \end_layout
32375
32376 \begin_layout Subsection
32377 Copy-Propagation
32378 \begin_inset LatexCommand \index{Copy propagation}
32379
32380 \end_inset
32381
32382
32383 \end_layout
32384
32385 \begin_layout Verse
32386
32387 \family typewriter
32388 int f() { 
32389 \newline
32390 \InsetSpace ~
32391 \InsetSpace ~
32392 int i, j; 
32393 \newline
32394 \InsetSpace ~
32395 \InsetSpace ~
32396 i = 10; 
32397 \newline
32398 \InsetSpace ~
32399 \InsetSpace ~
32400 j = i; 
32401 \newline
32402 \InsetSpace ~
32403 \InsetSpace ~
32404 return j; 
32405 \newline
32406 }
32407 \end_layout
32408
32409 \begin_layout Standard
32410 will be changed to 
32411 \end_layout
32412
32413 \begin_layout Verse
32414
32415 \family typewriter
32416 int f() { 
32417 \newline
32418 \InsetSpace ~
32419 \InsetSpace ~
32420 int i, j; 
32421 \newline
32422 \InsetSpace ~
32423 \InsetSpace ~
32424 i = 10; 
32425 \newline
32426 \InsetSpace ~
32427 \InsetSpace ~
32428 j = 10; 
32429 \newline
32430 \InsetSpace ~
32431 \InsetSpace ~
32432 return 10; 
32433 \newline
32434 }
32435 \end_layout
32436
32437 \begin_layout Standard
32438 Note: the dead stores created by this copy propagation will be eliminated
32439  by dead-code elimination.
32440 \end_layout
32441
32442 \begin_layout Subsection
32443 Loop Optimizations
32444 \begin_inset LatexCommand \index{Loop optimization}
32445
32446 \end_inset
32447
32448
32449 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
32450
32451 \end_inset
32452
32453
32454 \end_layout
32455
32456 \begin_layout Standard
32457 Two types of loop optimizations are done by SDCC 
32458 \emph on
32459 loop invariant
32460 \emph default
32461  lifting and
32462 \emph on
32463  strength reduction
32464 \emph default
32465  of loop induction variables.
32466  In addition to the strength reduction the optimizer marks the induction
32467  variables and the register allocator tries to keep the induction variables
32468  in registers for the duration of the loop.
32469  Because of this preference of the register allocator
32470 \begin_inset LatexCommand \index{Register allocation}
32471
32472 \end_inset
32473
32474 , loop induction optimization causes an increase in register pressure, which
32475  may cause unwanted spilling of other temporary variables into the stack
32476 \begin_inset LatexCommand \index{stack}
32477
32478 \end_inset
32479
32480  / data space.
32481  The compiler will generate a warning message when it is forced to allocate
32482  extra space either on the stack or data space.
32483  If this extra space allocation is undesirable then induction optimization
32484  can be eliminated either for the entire source file (with -
32485 \begin_inset ERT
32486 status collapsed
32487
32488 \begin_layout Standard
32489
32490
32491 \backslash
32492 /
32493 \end_layout
32494
32495 \end_inset
32496
32497 -noinduction option) or for a given function only using #pragma\InsetSpace ~
32498 noinduction
32499 \begin_inset LatexCommand \index{\#pragma noinduction}
32500
32501 \end_inset
32502
32503 .
32504 \newline
32505
32506 \newline
32507 Loop Invariant:
32508 \end_layout
32509
32510 \begin_layout Verse
32511
32512 \family typewriter
32513 for (i = 0 ; i < 100 ; i ++) 
32514 \newline
32515 \InsetSpace ~
32516 \InsetSpace ~
32517 \InsetSpace ~
32518 \InsetSpace ~
32519 f += k + l;
32520 \end_layout
32521
32522 \begin_layout Standard
32523 changed to
32524 \end_layout
32525
32526 \begin_layout Verse
32527
32528 \family typewriter
32529 itemp = k + l; 
32530 \newline
32531 for (i = 0; i < 100; i++) 
32532 \newline
32533 \InsetSpace ~
32534 \InsetSpace ~
32535 \InsetSpace ~
32536 \InsetSpace ~
32537 f += itemp;
32538 \end_layout
32539
32540 \begin_layout Standard
32541 As mentioned previously some loop invariants are not as apparent, all static
32542  address computations are also moved out of the loop.
32543 \newline
32544
32545 \newline
32546 Strength Reduction
32547 \begin_inset LatexCommand \index{Strength reduction}
32548
32549 \end_inset
32550
32551 , this optimization substitutes an expression by a cheaper expression:
32552 \end_layout
32553
32554 \begin_layout Verse
32555
32556 \family typewriter
32557 for (i=0;i < 100; i++)
32558 \newline
32559 \InsetSpace ~
32560 \InsetSpace ~
32561 \InsetSpace ~
32562 \InsetSpace ~
32563 ar[i*5] = i*3;
32564 \end_layout
32565
32566 \begin_layout Standard
32567 changed to
32568 \end_layout
32569
32570 \begin_layout Verse
32571
32572 \family typewriter
32573 itemp1 = 0; 
32574 \newline
32575 itemp2 = 0; 
32576 \newline
32577 for (i=0;i< 100;i++) { 
32578 \newline
32579 \InsetSpace ~
32580 \InsetSpace ~
32581 \InsetSpace ~
32582 \InsetSpace ~
32583 ar[itemp1] = itemp2; 
32584 \newline
32585 \InsetSpace ~
32586 \InsetSpace ~
32587 \InsetSpace ~
32588 \InsetSpace ~
32589 itemp1
32590  += 5; 
32591 \newline
32592 \InsetSpace ~
32593 \InsetSpace ~
32594 \InsetSpace ~
32595 \InsetSpace ~
32596 itemp2 += 3; 
32597 \newline
32598 }
32599 \end_layout
32600
32601 \begin_layout Standard
32602 The more expensive multiplication
32603 \begin_inset LatexCommand \index{Multiplication}
32604
32605 \end_inset
32606
32607  is changed to a less expensive addition.
32608 \end_layout
32609
32610 \begin_layout Subsection
32611 Loop Reversing
32612 \begin_inset LatexCommand \index{Loop reversing}
32613
32614 \end_inset
32615
32616
32617 \end_layout
32618
32619 \begin_layout Standard
32620 This optimization is done to reduce the overhead of checking loop boundaries
32621  for every iteration.
32622  Some simple loops can be reversed and implemented using a 
32623 \begin_inset Quotes eld
32624 \end_inset
32625
32626 decrement and jump if not zero
32627 \begin_inset Quotes erd
32628 \end_inset
32629
32630  instruction.
32631  SDCC checks for the following criterion to determine if a loop is reversible
32632  (note: more sophisticated compilers use data-dependency analysis to make
32633  this determination, SDCC uses a more simple minded analysis).
32634 \end_layout
32635
32636 \begin_layout Itemize
32637 The 'for' loop is of the form 
32638 \newline
32639
32640 \newline
32641
32642 \family typewriter
32643 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
32644  += 1])
32645 \newline
32646 \InsetSpace ~
32647 \InsetSpace ~
32648 \InsetSpace ~
32649 \InsetSpace ~
32650 <for body>
32651 \end_layout
32652
32653 \begin_layout Itemize
32654 The <for body> does not contain 
32655 \begin_inset Quotes eld
32656 \end_inset
32657
32658 continue
32659 \begin_inset Quotes erd
32660 \end_inset
32661
32662  or 'break
32663 \begin_inset Quotes erd
32664 \end_inset
32665
32666 .
32667 \end_layout
32668
32669 \begin_layout Itemize
32670 All goto's are contained within the loop.
32671 \end_layout
32672
32673 \begin_layout Itemize
32674 No function calls within the loop.
32675 \end_layout
32676
32677 \begin_layout Itemize
32678 The loop control variable <sym> is not assigned any value within the loop
32679 \end_layout
32680
32681 \begin_layout Itemize
32682 The loop control variable does NOT participate in any arithmetic operation
32683  within the loop.
32684 \end_layout
32685
32686 \begin_layout Itemize
32687 There are NO switch statements in the loop.
32688 \end_layout
32689
32690 \begin_layout Subsection
32691 Algebraic Simplifications
32692 \end_layout
32693
32694 \begin_layout Standard
32695 SDCC does numerous algebraic simplifications, the following is a small sub-set
32696  of these optimizations.
32697 \end_layout
32698
32699 \begin_layout Verse
32700
32701 \family typewriter
32702 i = j + 0;\InsetSpace ~
32703 \InsetSpace ~
32704 \InsetSpace ~
32705 \InsetSpace ~
32706  /* changed to: */\InsetSpace ~
32707 \InsetSpace ~
32708 \InsetSpace ~
32709 \InsetSpace ~
32710  i = j; 
32711 \newline
32712 i /= 2;\InsetSpace ~
32713 \InsetSpace ~
32714 \InsetSpace ~
32715 \InsetSpace ~
32716 \InsetSpace ~
32717 \InsetSpace ~
32718 \InsetSpace ~
32719  /* changed to: */\InsetSpace ~
32720 \InsetSpace ~
32721 \InsetSpace ~
32722 \InsetSpace ~
32723  i >>= 1; 
32724 \newline
32725 i
32726  = j - j;\InsetSpace ~
32727 \InsetSpace ~
32728 \InsetSpace ~
32729 \InsetSpace ~
32730  /* changed to: */\InsetSpace ~
32731 \InsetSpace ~
32732 \InsetSpace ~
32733 \InsetSpace ~
32734  i = 0; 
32735 \newline
32736 i = j / 1;\InsetSpace ~
32737 \InsetSpace ~
32738 \InsetSpace ~
32739 \InsetSpace ~
32740  /* changed to: */\InsetSpace ~
32741 \InsetSpace ~
32742 \InsetSpace ~
32743 \InsetSpace ~
32744  i = j;
32745 \end_layout
32746
32747 \begin_layout Standard
32748 Note the subexpressions
32749 \begin_inset LatexCommand \index{Subexpression}
32750
32751 \end_inset
32752
32753  given above are generally introduced by macro expansions or as a result
32754  of copy/constant propagation.
32755 \end_layout
32756
32757 \begin_layout Subsection
32758 'switch' Statements
32759 \begin_inset LatexCommand \label{sub:'switch'-Statements}
32760
32761 \end_inset
32762
32763
32764 \begin_inset LatexCommand \index{switch statement}
32765
32766 \end_inset
32767
32768
32769 \end_layout
32770
32771 \begin_layout Standard
32772 SDCC can optimize switch statements to jump tables
32773 \begin_inset LatexCommand \index{jump tables}
32774
32775 \end_inset
32776
32777 .
32778  It makes the decision based on an estimate of the generated code size.
32779  SDCC is quite liberal in the requirements for jump table generation: 
32780 \end_layout
32781
32782 \begin_layout Itemize
32783 The labels need not be in order, and the starting number need not be one
32784  or zero, the case labels are in numerical sequence or not too many case
32785  labels are missing.
32786 \end_layout
32787
32788 \begin_deeper
32789 \begin_layout Verse
32790
32791 \family typewriter
32792 switch(i) {\InsetSpace ~
32793 \InsetSpace ~
32794 \InsetSpace ~
32795 \InsetSpace ~
32796 \InsetSpace ~
32797 \InsetSpace ~
32798 \InsetSpace ~
32799 \InsetSpace ~
32800 \InsetSpace ~
32801 \InsetSpace ~
32802 \InsetSpace ~
32803 \InsetSpace ~
32804 \InsetSpace ~
32805 \InsetSpace ~
32806 \InsetSpace ~
32807 \InsetSpace ~
32808 \InsetSpace ~
32809 \InsetSpace ~
32810 \InsetSpace ~
32811 \InsetSpace ~
32812 \InsetSpace ~
32813 \InsetSpace ~
32814 \InsetSpace ~
32815 \InsetSpace ~
32816 \InsetSpace ~
32817 \InsetSpace ~
32818 switch (i) { 
32819 \newline
32820 \InsetSpace ~
32821 \InsetSpace ~
32822 \InsetSpace ~
32823 case 4: ...\InsetSpace ~
32824 \InsetSpace ~
32825 \InsetSpace ~
32826 \InsetSpace ~
32827 \InsetSpace ~
32828 \InsetSpace ~
32829 \InsetSpace ~
32830 \InsetSpace ~
32831 \InsetSpace ~
32832 \InsetSpace ~
32833 \InsetSpace ~
32834 \InsetSpace ~
32835 \InsetSpace ~
32836 \InsetSpace ~
32837 \InsetSpace ~
32838 \InsetSpace ~
32839 \InsetSpace ~
32840 \InsetSpace ~
32841 \InsetSpace ~
32842 \InsetSpace ~
32843 \InsetSpace ~
32844 \InsetSpace ~
32845 \InsetSpace ~
32846 \InsetSpace ~
32847 \InsetSpace ~
32848 \InsetSpace ~
32849 case 0: ...
32850  
32851 \newline
32852 \InsetSpace ~
32853 \InsetSpace ~
32854 \InsetSpace ~
32855 case 5: ...\InsetSpace ~
32856 \InsetSpace ~
32857 \InsetSpace ~
32858 \InsetSpace ~
32859 \InsetSpace ~
32860 \InsetSpace ~
32861 \InsetSpace ~
32862 \InsetSpace ~
32863 \InsetSpace ~
32864 \InsetSpace ~
32865 \InsetSpace ~
32866 \InsetSpace ~
32867 \InsetSpace ~
32868 \InsetSpace ~
32869 \InsetSpace ~
32870 \InsetSpace ~
32871 \InsetSpace ~
32872 \InsetSpace ~
32873 \InsetSpace ~
32874 \InsetSpace ~
32875 \InsetSpace ~
32876 \InsetSpace ~
32877 \InsetSpace ~
32878 \InsetSpace ~
32879 \InsetSpace ~
32880 \InsetSpace ~
32881 case 1: ...
32882  
32883 \newline
32884 \InsetSpace ~
32885 \InsetSpace ~
32886 \InsetSpace ~
32887 case 3: ...\InsetSpace ~
32888 \InsetSpace ~
32889 \InsetSpace ~
32890 \InsetSpace ~
32891 \InsetSpace ~
32892 \InsetSpace ~
32893 \InsetSpace ~
32894 \InsetSpace ~
32895 \InsetSpace ~
32896 \InsetSpace ~
32897 \InsetSpace ~
32898 \InsetSpace ~
32899 \InsetSpace ~
32900 \InsetSpace ~
32901 \InsetSpace ~
32902 \InsetSpace ~
32903 \InsetSpace ~
32904 \InsetSpace ~
32905 \InsetSpace ~
32906 \InsetSpace ~
32907 \InsetSpace ~
32908 \InsetSpace ~
32909 \InsetSpace ~
32910 \InsetSpace ~
32911 \InsetSpace ~
32912 \InsetSpace ~
32913
32914 \newline
32915 \InsetSpace ~
32916 \InsetSpace ~
32917 \InsetSpace ~
32918 case 6: ...\InsetSpace ~
32919 \InsetSpace ~
32920 \InsetSpace ~
32921 \InsetSpace ~
32922 \InsetSpace ~
32923 \InsetSpace ~
32924 \InsetSpace ~
32925 \InsetSpace ~
32926 \InsetSpace ~
32927 \InsetSpace ~
32928 \InsetSpace ~
32929 \InsetSpace ~
32930 \InsetSpace ~
32931 \InsetSpace ~
32932 \InsetSpace ~
32933 \InsetSpace ~
32934 \InsetSpace ~
32935 \InsetSpace ~
32936 \InsetSpace ~
32937 \InsetSpace ~
32938 \InsetSpace ~
32939 \InsetSpace ~
32940 \InsetSpace ~
32941 \InsetSpace ~
32942 \InsetSpace ~
32943 \InsetSpace ~
32944 case 3: ...
32945  
32946 \newline
32947 \InsetSpace ~
32948 \InsetSpace ~
32949 \InsetSpace ~
32950 case 7: ...\InsetSpace ~
32951 \InsetSpace ~
32952 \InsetSpace ~
32953 \InsetSpace ~
32954 \InsetSpace ~
32955 \InsetSpace ~
32956 \InsetSpace ~
32957 \InsetSpace ~
32958 \InsetSpace ~
32959 \InsetSpace ~
32960 \InsetSpace ~
32961 \InsetSpace ~
32962 \InsetSpace ~
32963 \InsetSpace ~
32964 \InsetSpace ~
32965 \InsetSpace ~
32966 \InsetSpace ~
32967 \InsetSpace ~
32968 \InsetSpace ~
32969 \InsetSpace ~
32970 \InsetSpace ~
32971 \InsetSpace ~
32972 \InsetSpace ~
32973 \InsetSpace ~
32974 \InsetSpace ~
32975 \InsetSpace ~
32976 case 4: ...
32977  
32978 \newline
32979 \InsetSpace ~
32980 \InsetSpace ~
32981 \InsetSpace ~
32982 case 8: ...\InsetSpace ~
32983 \InsetSpace ~
32984 \InsetSpace ~
32985 \InsetSpace ~
32986 \InsetSpace ~
32987 \InsetSpace ~
32988 \InsetSpace ~
32989 \InsetSpace ~
32990 \InsetSpace ~
32991 \InsetSpace ~
32992 \InsetSpace ~
32993 \InsetSpace ~
32994 \InsetSpace ~
32995 \InsetSpace ~
32996 \InsetSpace ~
32997 \InsetSpace ~
32998 \InsetSpace ~
32999 \InsetSpace ~
33000 \InsetSpace ~
33001 \InsetSpace ~
33002 \InsetSpace ~
33003 \InsetSpace ~
33004 \InsetSpace ~
33005 \InsetSpace ~
33006 \InsetSpace ~
33007 \InsetSpace ~
33008 case 5: ...
33009  
33010 \newline
33011 \InsetSpace ~
33012 \InsetSpace ~
33013 \InsetSpace ~
33014 case 9: ...\InsetSpace ~
33015 \InsetSpace ~
33016 \InsetSpace ~
33017 \InsetSpace ~
33018 \InsetSpace ~
33019 \InsetSpace ~
33020 \InsetSpace ~
33021 \InsetSpace ~
33022 \InsetSpace ~
33023 \InsetSpace ~
33024 \InsetSpace ~
33025 \InsetSpace ~
33026 \InsetSpace ~
33027 \InsetSpace ~
33028 \InsetSpace ~
33029 \InsetSpace ~
33030 \InsetSpace ~
33031 \InsetSpace ~
33032 \InsetSpace ~
33033 \InsetSpace ~
33034 \InsetSpace ~
33035 \InsetSpace ~
33036 \InsetSpace ~
33037 \InsetSpace ~
33038 \InsetSpace ~
33039 \InsetSpace ~
33040 case 6: ...
33041  
33042 \newline
33043 \InsetSpace ~
33044 \InsetSpace ~
33045 \InsetSpace ~
33046 case 10: ...\InsetSpace ~
33047 \InsetSpace ~
33048 \InsetSpace ~
33049 \InsetSpace ~
33050 \InsetSpace ~
33051 \InsetSpace ~
33052 \InsetSpace ~
33053 \InsetSpace ~
33054 \InsetSpace ~
33055 \InsetSpace ~
33056 \InsetSpace ~
33057 \InsetSpace ~
33058 \InsetSpace ~
33059 \InsetSpace ~
33060 \InsetSpace ~
33061 \InsetSpace ~
33062 \InsetSpace ~
33063 \InsetSpace ~
33064 \InsetSpace ~
33065 \InsetSpace ~
33066 \InsetSpace ~
33067 \InsetSpace ~
33068 \InsetSpace ~
33069 \InsetSpace ~
33070 \InsetSpace ~
33071 case 7: ...
33072  
33073 \newline
33074 \InsetSpace ~
33075 \InsetSpace ~
33076 \InsetSpace ~
33077 case 11: ...\InsetSpace ~
33078 \InsetSpace ~
33079 \InsetSpace ~
33080 \InsetSpace ~
33081 \InsetSpace ~
33082 \InsetSpace ~
33083 \InsetSpace ~
33084 \InsetSpace ~
33085 \InsetSpace ~
33086 \InsetSpace ~
33087 \InsetSpace ~
33088 \InsetSpace ~
33089 \InsetSpace ~
33090 \InsetSpace ~
33091 \InsetSpace ~
33092 \InsetSpace ~
33093 \InsetSpace ~
33094 \InsetSpace ~
33095 \InsetSpace ~
33096 \InsetSpace ~
33097 \InsetSpace ~
33098 \InsetSpace ~
33099 \InsetSpace ~
33100 \InsetSpace ~
33101 \InsetSpace ~
33102 case 8: ...
33103  
33104 \newline
33105 }\InsetSpace ~
33106 \InsetSpace ~
33107 \InsetSpace ~
33108 \InsetSpace ~
33109 \InsetSpace ~
33110 \InsetSpace ~
33111 \InsetSpace ~
33112 \InsetSpace ~
33113 \InsetSpace ~
33114 \InsetSpace ~
33115 \InsetSpace ~
33116 \InsetSpace ~
33117 \InsetSpace ~
33118 \InsetSpace ~
33119 \InsetSpace ~
33120 \InsetSpace ~
33121 \InsetSpace ~
33122 \InsetSpace ~
33123 \InsetSpace ~
33124 \InsetSpace ~
33125 \InsetSpace ~
33126 \InsetSpace ~
33127 \InsetSpace ~
33128 \InsetSpace ~
33129 \InsetSpace ~
33130 \InsetSpace ~
33131 \InsetSpace ~
33132 \InsetSpace ~
33133 \InsetSpace ~
33134 \InsetSpace ~
33135 \InsetSpace ~
33136 \InsetSpace ~
33137 \InsetSpace ~
33138 \InsetSpace ~
33139 \InsetSpace ~
33140 \InsetSpace ~
33141 }
33142 \end_layout
33143
33144 \begin_layout Standard
33145 Both the above switch statements will be implemented using a jump-table.
33146  The example to the right side is slightly more efficient as the check for
33147  the lower boundary of the jump-table is not needed.
33148 \end_layout
33149
33150 \end_deeper
33151 \begin_layout Itemize
33152 The number of case labels is not larger than supported by the target architectur
33153 e.
33154 \end_layout
33155
33156 \begin_layout Itemize
33157 If the case labels are not in numerical sequence ('gaps' between cases)
33158  SDCC checks whether a jump table with additionally inserted dummy cases
33159  is still attractive.
33160  
33161 \end_layout
33162
33163 \begin_layout Itemize
33164 If the starting number is not zero and a check for the lower boundary of
33165  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33166  ...
33167  .
33168 \end_layout
33169
33170 \begin_layout Standard
33171 Switch statements which have large gaps in the numeric sequence or those
33172  that have too many case labels can be split into more than one switch statement
33173  for efficient code generation, e.g.:
33174 \end_layout
33175
33176 \begin_layout Verse
33177
33178 \family typewriter
33179 switch (i) { 
33180 \newline
33181 \InsetSpace ~
33182 \InsetSpace ~
33183 case 1: ...
33184  
33185 \newline
33186 \InsetSpace ~
33187 \InsetSpace ~
33188 case 2: ...
33189  
33190 \newline
33191 \InsetSpace ~
33192 \InsetSpace ~
33193 case 3: ...
33194  
33195 \newline
33196 \InsetSpace ~
33197 \InsetSpace ~
33198 case 4: ...
33199  
33200 \newline
33201 \InsetSpace ~
33202 \InsetSpace ~
33203 case 5: ...
33204  
33205 \newline
33206 \InsetSpace ~
33207 \InsetSpace ~
33208 case 6: ...
33209  
33210 \newline
33211 \InsetSpace ~
33212 \InsetSpace ~
33213 case 7: ...
33214  
33215 \newline
33216 \InsetSpace ~
33217 \InsetSpace ~
33218 case 101: ...
33219  
33220 \newline
33221 \InsetSpace ~
33222 \InsetSpace ~
33223 case 102: ...
33224  
33225 \newline
33226 \InsetSpace ~
33227 \InsetSpace ~
33228 case 103: ...
33229  
33230 \newline
33231 \InsetSpace ~
33232 \InsetSpace ~
33233 case 104: ...
33234  
33235 \newline
33236 \InsetSpace ~
33237 \InsetSpace ~
33238 case 105: ...
33239  
33240 \newline
33241 \InsetSpace ~
33242 \InsetSpace ~
33243 case 106: ...
33244  
33245 \newline
33246 \InsetSpace ~
33247 \InsetSpace ~
33248 case 107: ...
33249  
33250 \newline
33251 }
33252 \end_layout
33253
33254 \begin_layout Standard
33255 If the above switch statement is broken down into two switch statements
33256 \end_layout
33257
33258 \begin_layout Verse
33259
33260 \family typewriter
33261 switch (i) { 
33262 \newline
33263 \InsetSpace ~
33264 \InsetSpace ~
33265 case 1: ...
33266  
33267 \newline
33268 \InsetSpace ~
33269 \InsetSpace ~
33270 case 2: ...
33271  
33272 \newline
33273 \InsetSpace ~
33274 \InsetSpace ~
33275 case 3: ...
33276  
33277 \newline
33278 \InsetSpace ~
33279 \InsetSpace ~
33280 case 4: ...
33281  
33282 \newline
33283 \InsetSpace ~
33284 \InsetSpace ~
33285 case 5: ...
33286  
33287 \newline
33288 \InsetSpace ~
33289 \InsetSpace ~
33290 case 6: ...
33291  
33292 \newline
33293 \InsetSpace ~
33294 \InsetSpace ~
33295 case 7: ...
33296  
33297 \newline
33298 }
33299 \end_layout
33300
33301 \begin_layout Standard
33302 and
33303 \end_layout
33304
33305 \begin_layout Verse
33306
33307 \family typewriter
33308 switch (i) { 
33309 \newline
33310 \InsetSpace ~
33311 \InsetSpace ~
33312 case 101: ...
33313  
33314 \newline
33315 \InsetSpace ~
33316 \InsetSpace ~
33317 case 102: ...
33318  
33319 \newline
33320 \InsetSpace ~
33321 \InsetSpace ~
33322 case 103: ...
33323  
33324 \newline
33325 \InsetSpace ~
33326 \InsetSpace ~
33327 case 104: ...
33328  
33329 \newline
33330 \InsetSpace ~
33331 \InsetSpace ~
33332 case 105: ...
33333  
33334 \newline
33335 \InsetSpace ~
33336 \InsetSpace ~
33337 case 106: ...
33338  
33339 \newline
33340 \InsetSpace ~
33341 \InsetSpace ~
33342 case 107: ...
33343  
33344 \newline
33345 }
33346 \end_layout
33347
33348 \begin_layout Standard
33349 then both the switch statements will be implemented using jump-tables whereas
33350  the unmodified switch statement will not be.
33351 \end_layout
33352
33353 \begin_layout Standard
33354 \begin_inset Note Note
33355 status collapsed
33356
33357 \begin_layout Standard
33358 There might be reasons which SDCC cannot know about to either favour or
33359  not favour jump tables.
33360  If the target system has to be as quick for the last switch case as for
33361  the first (pro jump table), or if the switch argument is known to be zero
33362  in the majority of the cases (contra jump table).
33363 \end_layout
33364
33365 \end_inset
33366
33367
33368 \end_layout
33369
33370 \begin_layout Standard
33371 The pragma nojtbound
33372 \begin_inset LatexCommand \index{\#pragma nojtbound}
33373
33374 \end_inset
33375
33376  can be used to turn off checking the 
33377 \emph on
33378 j
33379 \emph default
33380 ump 
33381 \emph on
33382 t
33383 \emph default
33384 able 
33385 \emph on
33386 bound
33387 \emph default
33388 aries.
33389  It has no effect if a default label is supplied.
33390  Use of this pragma is dangerous: if the switch
33391 \begin_inset LatexCommand \index{switch statement}
33392
33393 \end_inset
33394
33395  argument is not matched by a case statement the processor will happily
33396  jump into Nirvana.
33397 \end_layout
33398
33399 \begin_layout Subsection
33400 Bit-shifting Operations
33401 \begin_inset LatexCommand \index{Bit shifting}
33402
33403 \end_inset
33404
33405 .
33406 \end_layout
33407
33408 \begin_layout Standard
33409 Bit shifting is one of the most frequently used operation in embedded programmin
33410 g.
33411  SDCC tries to implement bit-shift operations in the most efficient way
33412  possible, e.g.:
33413 \end_layout
33414
33415 \begin_layout Verse
33416
33417 \family typewriter
33418 unsigned char i;
33419 \newline
33420 ...
33421  
33422 \newline
33423 i >>= 4; 
33424 \newline
33425 ...
33426 \end_layout
33427
33428 \begin_layout Standard
33429 generates the following code:
33430 \end_layout
33431
33432 \begin_layout Verse
33433
33434 \family typewriter
33435 mov\InsetSpace ~
33436  a,_i 
33437 \newline
33438 swap a 
33439 \newline
33440 anl\InsetSpace ~
33441  a,#0x0f 
33442 \newline
33443 mov\InsetSpace ~
33444  _i,a
33445 \end_layout
33446
33447 \begin_layout Standard
33448 In general SDCC will never setup a loop if the shift count is known.
33449  Another example:
33450 \end_layout
33451
33452 \begin_layout Verse
33453
33454 \family typewriter
33455 unsigned int i; 
33456 \newline
33457 ...
33458  
33459 \newline
33460 i >>= 9; 
33461 \newline
33462 ...
33463 \end_layout
33464
33465 \begin_layout Standard
33466 will generate:
33467 \end_layout
33468
33469 \begin_layout Verse
33470
33471 \family typewriter
33472 mov\InsetSpace ~
33473 \InsetSpace ~
33474 a,(_i + 1) 
33475 \newline
33476 mov\InsetSpace ~
33477 \InsetSpace ~
33478 (_i + 1),#0x00 
33479 \newline
33480 clr\InsetSpace ~
33481 \InsetSpace ~
33482
33483 \newline
33484 rrc\InsetSpace ~
33485 \InsetSpace ~
33486
33487 \newline
33488 mov\InsetSpace ~
33489 \InsetSpace ~
33490 _i,a
33491 \end_layout
33492
33493 \begin_layout Subsection
33494 Bit-rotation
33495 \begin_inset LatexCommand \index{Bit rotation}
33496
33497 \end_inset
33498
33499
33500 \end_layout
33501
33502 \begin_layout Standard
33503 A special case of the bit-shift operation is bit rotation
33504 \begin_inset LatexCommand \index{rotating bits}
33505
33506 \end_inset
33507
33508 , SDCC recognizes the following expression to be a left bit-rotation:
33509 \end_layout
33510
33511 \begin_layout Verse
33512
33513 \family typewriter
33514 \series bold
33515 unsigned
33516 \series default
33517 \InsetSpace ~
33518 \InsetSpace ~
33519 char i;\InsetSpace ~
33520 \InsetSpace ~
33521 \InsetSpace ~
33522 \InsetSpace ~
33523 \InsetSpace ~
33524 \InsetSpace ~
33525 \InsetSpace ~
33526 \InsetSpace ~
33527 \InsetSpace ~
33528 \InsetSpace ~
33529 \InsetSpace ~
33530 /* unsigned is needed for rotation */ 
33531 \newline
33532 ...
33533  
33534 \newline
33535 i = ((i << 1) | (i >> 7)); 
33536 \family default
33537
33538 \newline
33539
33540 \family typewriter
33541 ...
33542 \end_layout
33543
33544 \begin_layout Standard
33545 will generate the following code:
33546 \end_layout
33547
33548 \begin_layout Verse
33549
33550 \family typewriter
33551 mov\InsetSpace ~
33552 \InsetSpace ~
33553 a,_i 
33554 \newline
33555 rl\InsetSpace ~
33556 \InsetSpace ~
33557 \InsetSpace ~
33558
33559 \newline
33560 mov\InsetSpace ~
33561 \InsetSpace ~
33562 _i,a
33563 \end_layout
33564
33565 \begin_layout Standard
33566 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
33567 ns of this case will also be recognized as bit-rotation, i.e.: 
33568 \end_layout
33569
33570 \begin_layout Verse
33571
33572 \family typewriter
33573 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
33574 \end_layout
33575
33576 \begin_layout Subsection
33577 Nibble and Byte Swapping
33578 \end_layout
33579
33580 \begin_layout Standard
33581 Other special cases of the bit-shift operations are nibble or byte swapping
33582 \begin_inset LatexCommand \index{swapping nibbles/bytes}
33583
33584 \end_inset
33585
33586 , SDCC recognizes the following expressions:
33587 \end_layout
33588
33589 \begin_layout Verse
33590
33591 \family typewriter
33592 \series bold
33593 unsigned
33594 \series default
33595 \InsetSpace ~
33596 \InsetSpace ~
33597 char i; 
33598 \newline
33599
33600 \series bold
33601 unsigned
33602 \series default
33603 \InsetSpace ~
33604 \InsetSpace ~
33605 int j; 
33606 \newline
33607 ...
33608  
33609 \newline
33610 i = ((i << 4) | (i >> 4)); 
33611 \family default
33612
33613 \newline
33614
33615 \family typewriter
33616 j = ((j << 8) | (j >> 8)); 
33617 \end_layout
33618
33619 \begin_layout Standard
33620 and generates a swap instruction for the nibble swapping
33621 \begin_inset LatexCommand \index{Nibble swapping}
33622
33623 \end_inset
33624
33625  or move instructions for the byte swapping
33626 \begin_inset LatexCommand \index{Byte swapping}
33627
33628 \end_inset
33629
33630 .
33631  The 
33632 \begin_inset Quotes sld
33633 \end_inset
33634
33635 j
33636 \begin_inset Quotes srd
33637 \end_inset
33638
33639  example can be used to convert from little to big-endian or vice versa.
33640  If you want to change the endianness of a 
33641 \emph on
33642 signed
33643 \emph default
33644  integer you have to cast to 
33645 \family typewriter
33646 (unsigned int)
33647 \family default
33648  first.
33649 \end_layout
33650
33651 \begin_layout Standard
33652 Note that SDCC stores numbers in little-endian
33653 \begin_inset Foot
33654 status open
33655
33656 \begin_layout Standard
33657 Usually 8-bit processors don't care much about endianness.
33658  This is not the case for the standard 8051 which only has an instruction
33659  to increment its 
33660 \emph on
33661 dptr
33662 \emph default
33663
33664 \begin_inset LatexCommand \index{DPTR}
33665
33666 \end_inset
33667
33668 -datapointer
33669 \emph on
33670  
33671 \emph default
33672 so little-endian is the more efficient byte order.
33673 \end_layout
33674
33675 \end_inset
33676
33677
33678 \begin_inset LatexCommand \index{little-endian}
33679
33680 \end_inset
33681
33682
33683 \begin_inset LatexCommand \index{Endianness}
33684
33685 \end_inset
33686
33687  format (i.e.
33688  lowest order first).
33689 \end_layout
33690
33691 \begin_layout Subsection
33692 Highest Order Bit
33693 \begin_inset LatexCommand \index{Highest Order Bit}
33694
33695 \end_inset
33696
33697  / Any Order Bit
33698 \begin_inset LatexCommand \index{Any Order Bit}
33699
33700 \end_inset
33701
33702
33703 \end_layout
33704
33705 \begin_layout Standard
33706 It is frequently required to obtain the highest order bit of an integral
33707  type (long, int, short or char types).
33708  Also obtaining any other order bit is not uncommon.
33709  SDCC recognizes the following expressions to yield the highest order bit
33710  and generates optimized code for it, e.g.:
33711 \end_layout
33712
33713 \begin_layout Verse
33714
33715 \family typewriter
33716 unsigned int gint; 
33717 \newline
33718
33719 \newline
33720 foo () { 
33721 \newline
33722 \InsetSpace ~
33723 \InsetSpace ~
33724 unsigned char hob1, aob1; 
33725 \newline
33726 \InsetSpace ~
33727 \InsetSpace ~
33728 bit hob2, hob3, aob2,
33729  aob3; 
33730 \newline
33731 \InsetSpace ~
33732 \InsetSpace ~
33733 ...
33734  
33735 \newline
33736 \InsetSpace ~
33737 \InsetSpace ~
33738 hob1 = (gint >> 15) & 1; 
33739 \newline
33740 \InsetSpace ~
33741 \InsetSpace ~
33742 hob2 = (gint >> 15) & 1; 
33743 \newline
33744 \InsetSpace ~
33745 \InsetSpace ~
33746 hob3 = gint & 0x8000;
33747  
33748 \newline
33749 \InsetSpace ~
33750 \InsetSpace ~
33751 aob1 = (gint >> 9) & 1; 
33752 \newline
33753 \InsetSpace ~
33754 \InsetSpace ~
33755 aob2 = (gint >> 8) & 1; 
33756 \newline
33757 \InsetSpace ~
33758 \InsetSpace ~
33759 aob3 = gint & 0x0800; 
33760 \newline
33761 \InsetSpace ~
33762 \InsetSpace ~
33763 ..
33764  
33765 \newline
33766 }
33767 \end_layout
33768
33769 \begin_layout Standard
33770 will generate the following code:
33771 \end_layout
33772
33773 \begin_layout Verse
33774
33775 \family typewriter
33776 \InsetSpace ~
33777 \InsetSpace ~
33778 \InsetSpace ~
33779 \InsetSpace ~
33780 \InsetSpace ~
33781 \InsetSpace ~
33782 \InsetSpace ~
33783 \InsetSpace ~
33784 \InsetSpace ~
33785 \InsetSpace ~
33786 \InsetSpace ~
33787 \InsetSpace ~
33788 \InsetSpace ~
33789 \InsetSpace ~
33790 \InsetSpace ~
33791 \InsetSpace ~
33792 \InsetSpace ~
33793 \InsetSpace ~
33794 \InsetSpace ~
33795 \InsetSpace ~
33796 \InsetSpace ~
33797 \InsetSpace ~
33798 \InsetSpace ~
33799 \InsetSpace ~
33800 \InsetSpace ~
33801  61 ;\InsetSpace ~
33802  hob.c 7 
33803 \newline
33804 000A E5*01\InsetSpace ~
33805 \InsetSpace ~
33806 \InsetSpace ~
33807 \InsetSpace ~
33808 \InsetSpace ~
33809 \InsetSpace ~
33810 \InsetSpace ~
33811 \InsetSpace ~
33812 \InsetSpace ~
33813 \InsetSpace ~
33814 \InsetSpace ~
33815 \InsetSpace ~
33816 \InsetSpace ~
33817 \InsetSpace ~
33818 \InsetSpace ~
33819  62\InsetSpace ~
33820 \InsetSpace ~
33821 \InsetSpace ~
33822 \InsetSpace ~
33823 \InsetSpace ~
33824 \InsetSpace ~
33825 \InsetSpace ~
33826 \InsetSpace ~
33827  mov\InsetSpace ~
33828 \InsetSpace ~
33829  a,(_gint + 1) 
33830 \newline
33831 000C 23\InsetSpace ~
33832 \InsetSpace ~
33833 \InsetSpace ~
33834 \InsetSpace ~
33835 \InsetSpace ~
33836 \InsetSpace ~
33837 \InsetSpace ~
33838 \InsetSpace ~
33839 \InsetSpace ~
33840 \InsetSpace ~
33841 \InsetSpace ~
33842 \InsetSpace ~
33843 \InsetSpace ~
33844 \InsetSpace ~
33845 \InsetSpace ~
33846 \InsetSpace ~
33847 \InsetSpace ~
33848 \InsetSpace ~
33849  63\InsetSpace ~
33850 \InsetSpace ~
33851 \InsetSpace ~
33852 \InsetSpace ~
33853 \InsetSpace ~
33854 \InsetSpace ~
33855 \InsetSpace ~
33856 \InsetSpace ~
33857  rl\InsetSpace ~
33858 \InsetSpace ~
33859 \InsetSpace ~
33860  a 
33861 \newline
33862 000D 54 01\InsetSpace ~
33863 \InsetSpace ~
33864 \InsetSpace ~
33865 \InsetSpace ~
33866 \InsetSpace ~
33867 \InsetSpace ~
33868 \InsetSpace ~
33869 \InsetSpace ~
33870 \InsetSpace ~
33871 \InsetSpace ~
33872 \InsetSpace ~
33873 \InsetSpace ~
33874 \InsetSpace ~
33875 \InsetSpace ~
33876 \InsetSpace ~
33877
33878  64\InsetSpace ~
33879 \InsetSpace ~
33880 \InsetSpace ~
33881 \InsetSpace ~
33882 \InsetSpace ~
33883 \InsetSpace ~
33884 \InsetSpace ~
33885 \InsetSpace ~
33886  anl\InsetSpace ~
33887 \InsetSpace ~
33888  a,#0x01 
33889 \newline
33890 000F F5*02\InsetSpace ~
33891 \InsetSpace ~
33892 \InsetSpace ~
33893 \InsetSpace ~
33894 \InsetSpace ~
33895 \InsetSpace ~
33896 \InsetSpace ~
33897 \InsetSpace ~
33898 \InsetSpace ~
33899 \InsetSpace ~
33900 \InsetSpace ~
33901 \InsetSpace ~
33902 \InsetSpace ~
33903 \InsetSpace ~
33904 \InsetSpace ~
33905  65\InsetSpace ~
33906 \InsetSpace ~
33907 \InsetSpace ~
33908 \InsetSpace ~
33909 \InsetSpace ~
33910 \InsetSpace ~
33911 \InsetSpace ~
33912 \InsetSpace ~
33913  mov\InsetSpace ~
33914 \InsetSpace ~
33915  _foo_hob1_1_1,a 
33916 \newline
33917 \InsetSpace ~
33918 \InsetSpace ~
33919 \InsetSpace ~
33920 \InsetSpace ~
33921 \InsetSpace ~
33922 \InsetSpace ~
33923 \InsetSpace ~
33924 \InsetSpace ~
33925 \InsetSpace ~
33926 \InsetSpace ~
33927 \InsetSpace ~
33928 \InsetSpace ~
33929 \InsetSpace ~
33930 \InsetSpace ~
33931 \InsetSpace ~
33932 \InsetSpace ~
33933 \InsetSpace ~
33934 \InsetSpace ~
33935 \InsetSpace ~
33936 \InsetSpace ~
33937 \InsetSpace ~
33938 \InsetSpace ~
33939 \InsetSpace ~
33940 \InsetSpace ~
33941 \InsetSpace ~
33942  66 ;\InsetSpace ~
33943  hob.c 8 
33944 \newline
33945 0011 E5*01\InsetSpace ~
33946 \InsetSpace ~
33947 \InsetSpace ~
33948 \InsetSpace ~
33949 \InsetSpace ~
33950 \InsetSpace ~
33951 \InsetSpace ~
33952 \InsetSpace ~
33953 \InsetSpace ~
33954 \InsetSpace ~
33955 \InsetSpace ~
33956 \InsetSpace ~
33957 \InsetSpace ~
33958 \InsetSpace ~
33959 \InsetSpace ~
33960
33961  67\InsetSpace ~
33962 \InsetSpace ~
33963 \InsetSpace ~
33964 \InsetSpace ~
33965 \InsetSpace ~
33966 \InsetSpace ~
33967 \InsetSpace ~
33968 \InsetSpace ~
33969  mov\InsetSpace ~
33970 \InsetSpace ~
33971  a,(_gint + 1) 
33972 \newline
33973 0013 33\InsetSpace ~
33974 \InsetSpace ~
33975 \InsetSpace ~
33976 \InsetSpace ~
33977 \InsetSpace ~
33978 \InsetSpace ~
33979 \InsetSpace ~
33980 \InsetSpace ~
33981 \InsetSpace ~
33982 \InsetSpace ~
33983 \InsetSpace ~
33984 \InsetSpace ~
33985 \InsetSpace ~
33986 \InsetSpace ~
33987 \InsetSpace ~
33988 \InsetSpace ~
33989 \InsetSpace ~
33990 \InsetSpace ~
33991  68\InsetSpace ~
33992 \InsetSpace ~
33993 \InsetSpace ~
33994 \InsetSpace ~
33995 \InsetSpace ~
33996 \InsetSpace ~
33997 \InsetSpace ~
33998 \InsetSpace ~
33999  rlc\InsetSpace ~
34000 \InsetSpace ~
34001  a 
34002 \newline
34003 0014 92*00\InsetSpace ~
34004 \InsetSpace ~
34005 \InsetSpace ~
34006 \InsetSpace ~
34007 \InsetSpace ~
34008 \InsetSpace ~
34009 \InsetSpace ~
34010 \InsetSpace ~
34011 \InsetSpace ~
34012 \InsetSpace ~
34013 \InsetSpace ~
34014 \InsetSpace ~
34015 \InsetSpace ~
34016 \InsetSpace ~
34017 \InsetSpace ~
34018  69\InsetSpace ~
34019 \InsetSpace ~
34020 \InsetSpace ~
34021 \InsetSpace ~
34022 \InsetSpace ~
34023 \InsetSpace ~
34024 \InsetSpace ~
34025 \InsetSpace ~
34026  mov\InsetSpace ~
34027 \InsetSpace ~
34028  _foo_hob2_1_1,c
34029  
34030 \newline
34031 \InsetSpace ~
34032 \InsetSpace ~
34033 \InsetSpace ~
34034 \InsetSpace ~
34035 \InsetSpace ~
34036 \InsetSpace ~
34037 \InsetSpace ~
34038 \InsetSpace ~
34039 \InsetSpace ~
34040 \InsetSpace ~
34041 \InsetSpace ~
34042 \InsetSpace ~
34043 \InsetSpace ~
34044 \InsetSpace ~
34045 \InsetSpace ~
34046 \InsetSpace ~
34047 \InsetSpace ~
34048 \InsetSpace ~
34049 \InsetSpace ~
34050 \InsetSpace ~
34051 \InsetSpace ~
34052 \InsetSpace ~
34053 \InsetSpace ~
34054 \InsetSpace ~
34055 \InsetSpace ~
34056  66 ;\InsetSpace ~
34057  hob.c 9 
34058 \newline
34059 0016 E5*01\InsetSpace ~
34060 \InsetSpace ~
34061 \InsetSpace ~
34062 \InsetSpace ~
34063 \InsetSpace ~
34064 \InsetSpace ~
34065 \InsetSpace ~
34066 \InsetSpace ~
34067 \InsetSpace ~
34068 \InsetSpace ~
34069 \InsetSpace ~
34070 \InsetSpace ~
34071 \InsetSpace ~
34072 \InsetSpace ~
34073 \InsetSpace ~
34074  67\InsetSpace ~
34075 \InsetSpace ~
34076 \InsetSpace ~
34077 \InsetSpace ~
34078 \InsetSpace ~
34079 \InsetSpace ~
34080 \InsetSpace ~
34081 \InsetSpace ~
34082  mov\InsetSpace ~
34083 \InsetSpace ~
34084  a,(_gint + 1) 
34085 \newline
34086 0018 33\InsetSpace ~
34087 \InsetSpace ~
34088 \InsetSpace ~
34089 \InsetSpace ~
34090 \InsetSpace ~
34091 \InsetSpace ~
34092 \InsetSpace ~
34093 \InsetSpace ~
34094 \InsetSpace ~
34095 \InsetSpace ~
34096 \InsetSpace ~
34097 \InsetSpace ~
34098 \InsetSpace ~
34099 \InsetSpace ~
34100 \InsetSpace ~
34101 \InsetSpace ~
34102 \InsetSpace ~
34103 \InsetSpace ~
34104  68\InsetSpace ~
34105 \InsetSpace ~
34106 \InsetSpace ~
34107 \InsetSpace ~
34108 \InsetSpace ~
34109 \InsetSpace ~
34110 \InsetSpace ~
34111 \InsetSpace ~
34112  rlc\InsetSpace ~
34113 \InsetSpace ~
34114  a 
34115 \newline
34116 0019 92*01\InsetSpace ~
34117 \InsetSpace ~
34118 \InsetSpace ~
34119 \InsetSpace ~
34120 \InsetSpace ~
34121 \InsetSpace ~
34122 \InsetSpace ~
34123 \InsetSpace ~
34124 \InsetSpace ~
34125 \InsetSpace ~
34126 \InsetSpace ~
34127 \InsetSpace ~
34128 \InsetSpace ~
34129 \InsetSpace ~
34130 \InsetSpace ~
34131
34132  69\InsetSpace ~
34133 \InsetSpace ~
34134 \InsetSpace ~
34135 \InsetSpace ~
34136 \InsetSpace ~
34137 \InsetSpace ~
34138 \InsetSpace ~
34139 \InsetSpace ~
34140  mov\InsetSpace ~
34141 \InsetSpace ~
34142  _foo_hob3_1_1,c 
34143 \newline
34144 \InsetSpace ~
34145 \InsetSpace ~
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  70 ;\InsetSpace ~
34170  hob.c 10 
34171 \newline
34172 001B E5*01\InsetSpace ~
34173 \InsetSpace ~
34174 \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  71\InsetSpace ~
34188 \InsetSpace ~
34189 \InsetSpace ~
34190 \InsetSpace ~
34191 \InsetSpace ~
34192 \InsetSpace ~
34193 \InsetSpace ~
34194 \InsetSpace ~
34195  mov\InsetSpace ~
34196 \InsetSpace ~
34197  a,(_gint + 1) 
34198 \newline
34199 001D
34200  03\InsetSpace ~
34201 \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  72\InsetSpace ~
34219 \InsetSpace ~
34220 \InsetSpace ~
34221 \InsetSpace ~
34222 \InsetSpace ~
34223 \InsetSpace ~
34224 \InsetSpace ~
34225 \InsetSpace ~
34226  rr\InsetSpace ~
34227 \InsetSpace ~
34228 \InsetSpace ~
34229  a 
34230 \newline
34231 001E 54 01\InsetSpace ~
34232 \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  73\InsetSpace ~
34247 \InsetSpace ~
34248 \InsetSpace ~
34249 \InsetSpace ~
34250 \InsetSpace ~
34251 \InsetSpace ~
34252 \InsetSpace ~
34253 \InsetSpace ~
34254  anl\InsetSpace ~
34255 \InsetSpace ~
34256  a,#0x01 
34257 \newline
34258 0020 F5*03\InsetSpace ~
34259 \InsetSpace ~
34260 \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  74\InsetSpace ~
34274 \InsetSpace ~
34275 \InsetSpace ~
34276 \InsetSpace ~
34277 \InsetSpace ~
34278 \InsetSpace ~
34279 \InsetSpace ~
34280 \InsetSpace ~
34281  mov\InsetSpace ~
34282 \InsetSpace ~
34283  _foo_aob1_1_1,a
34284  
34285 \newline
34286 \InsetSpace ~
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  75 ;\InsetSpace ~
34312  hob.c 11 
34313 \newline
34314 0022 E5*01\InsetSpace ~
34315 \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  76\InsetSpace ~
34330 \InsetSpace ~
34331 \InsetSpace ~
34332 \InsetSpace ~
34333 \InsetSpace ~
34334 \InsetSpace ~
34335 \InsetSpace ~
34336 \InsetSpace ~
34337  mov\InsetSpace ~
34338 \InsetSpace ~
34339  a,(_gint + 1) 
34340 \newline
34341 0024 13\InsetSpace ~
34342 \InsetSpace ~
34343 \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  77\InsetSpace ~
34360 \InsetSpace ~
34361 \InsetSpace ~
34362 \InsetSpace ~
34363 \InsetSpace ~
34364 \InsetSpace ~
34365 \InsetSpace ~
34366 \InsetSpace ~
34367  rrc\InsetSpace ~
34368 \InsetSpace ~
34369  a 
34370 \newline
34371 0025 92*02\InsetSpace ~
34372 \InsetSpace ~
34373 \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
34387  78\InsetSpace ~
34388 \InsetSpace ~
34389 \InsetSpace ~
34390 \InsetSpace ~
34391 \InsetSpace ~
34392 \InsetSpace ~
34393 \InsetSpace ~
34394 \InsetSpace ~
34395  mov\InsetSpace ~
34396 \InsetSpace ~
34397  _foo_aob2_1_1,c 
34398 \newline
34399 \InsetSpace ~
34400 \InsetSpace ~
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  79 ;\InsetSpace ~
34425  hob.c 12 
34426 \newline
34427 0027 E5*01\InsetSpace ~
34428 \InsetSpace ~
34429 \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  80\InsetSpace ~
34443 \InsetSpace ~
34444 \InsetSpace ~
34445 \InsetSpace ~
34446 \InsetSpace ~
34447 \InsetSpace ~
34448 \InsetSpace ~
34449 \InsetSpace ~
34450  mov\InsetSpace ~
34451 \InsetSpace ~
34452  a,(_gint + 1) 
34453 \newline
34454 0029
34455  A2 E3\InsetSpace ~
34456 \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  81\InsetSpace ~
34471 \InsetSpace ~
34472 \InsetSpace ~
34473 \InsetSpace ~
34474 \InsetSpace ~
34475 \InsetSpace ~
34476 \InsetSpace ~
34477 \InsetSpace ~
34478  mov\InsetSpace ~
34479 \InsetSpace ~
34480  c,acc[3] 
34481 \newline
34482 002B 92*03\InsetSpace ~
34483 \InsetSpace ~
34484 \InsetSpace ~
34485 \InsetSpace ~
34486 \InsetSpace ~
34487 \InsetSpace ~
34488 \InsetSpace ~
34489 \InsetSpace ~
34490 \InsetSpace ~
34491 \InsetSpace ~
34492 \InsetSpace ~
34493 \InsetSpace ~
34494 \InsetSpace ~
34495 \InsetSpace ~
34496 \InsetSpace ~
34497  82\InsetSpace ~
34498 \InsetSpace ~
34499 \InsetSpace ~
34500 \InsetSpace ~
34501 \InsetSpace ~
34502 \InsetSpace ~
34503 \InsetSpace ~
34504 \InsetSpace ~
34505  mov\InsetSpace ~
34506 \InsetSpace ~
34507  _foo_aob3_1_1,c 
34508 \end_layout
34509
34510 \begin_layout Standard
34511 Other variations of these cases however will 
34512 \emph on
34513 not
34514 \emph default
34515  be recognized.
34516  They are standard C expressions, so I heartily recommend these be the only
34517  way to get the highest order bit, (it is portable).
34518  Of course it will be recognized even if it is embedded in other expressions,
34519  e.g.:
34520 \end_layout
34521
34522 \begin_layout Verse
34523
34524 \family typewriter
34525 xyz = gint + ((gint >> 15) & 1);
34526 \end_layout
34527
34528 \begin_layout Standard
34529 will still be recognized.
34530 \end_layout
34531
34532 \begin_layout Subsection
34533 Higher Order Byte
34534 \begin_inset LatexCommand \index{Higher Order Byte}
34535
34536 \end_inset
34537
34538  / Higher Order Word
34539 \begin_inset LatexCommand \index{Higher Order Word}
34540
34541 \end_inset
34542
34543
34544 \end_layout
34545
34546 \begin_layout Standard
34547 It is also frequently required to obtain a higher order byte or word of
34548  a larger integral type (long, int or short types).
34549  SDCC recognizes the following expressions to yield the higher order byte
34550  or word and generates optimized code for it, e.g.:
34551 \end_layout
34552
34553 \begin_layout Verse
34554
34555 \family typewriter
34556 unsigned int gint; 
34557 \newline
34558 unsigned long int glong; 
34559 \newline
34560
34561 \newline
34562 foo () { 
34563 \newline
34564 \InsetSpace ~
34565 \InsetSpace ~
34566 unsigned char hob1,
34567  hob2; 
34568 \newline
34569 \InsetSpace ~
34570 \InsetSpace ~
34571 unsigned int how1, how2; 
34572 \newline
34573 \InsetSpace ~
34574 \InsetSpace ~
34575 ...
34576  
34577 \newline
34578 \InsetSpace ~
34579 \InsetSpace ~
34580 hob1 = (gint >> 8) & 0xFF; 
34581 \newline
34582 \InsetSpace ~
34583 \InsetSpace ~
34584 hob2 = glong >> 24; 
34585 \newline
34586 \InsetSpace ~
34587 \InsetSpace ~
34588 how1 = (glong >> 16) & 0xFFFF;
34589  
34590 \newline
34591 \InsetSpace ~
34592 \InsetSpace ~
34593 how2 = glong >> 8; 
34594 \newline
34595 \InsetSpace ~
34596 \InsetSpace ~
34597 ..
34598  
34599 \newline
34600 }
34601 \end_layout
34602
34603 \begin_layout Standard
34604 will generate the following code:
34605 \end_layout
34606
34607 \begin_layout Verse
34608
34609 \family typewriter
34610 \InsetSpace ~
34611 \InsetSpace ~
34612 \InsetSpace ~
34613 \InsetSpace ~
34614 \InsetSpace ~
34615 \InsetSpace ~
34616 \InsetSpace ~
34617 \InsetSpace ~
34618 \InsetSpace ~
34619 \InsetSpace ~
34620 \InsetSpace ~
34621 \InsetSpace ~
34622 \InsetSpace ~
34623 \InsetSpace ~
34624 \InsetSpace ~
34625 \InsetSpace ~
34626 \InsetSpace ~
34627 \InsetSpace ~
34628 \InsetSpace ~
34629 \InsetSpace ~
34630 \InsetSpace ~
34631 \InsetSpace ~
34632 \InsetSpace ~
34633 \InsetSpace ~
34634 \InsetSpace ~
34635  91 ;\InsetSpace ~
34636  hob.c 15 
34637 \newline
34638 0037 85*01*06\InsetSpace ~
34639 \InsetSpace ~
34640 \InsetSpace ~
34641 \InsetSpace ~
34642 \InsetSpace ~
34643 \InsetSpace ~
34644 \InsetSpace ~
34645 \InsetSpace ~
34646 \InsetSpace ~
34647 \InsetSpace ~
34648 \InsetSpace ~
34649 \InsetSpace ~
34650  92\InsetSpace ~
34651 \InsetSpace ~
34652 \InsetSpace ~
34653 \InsetSpace ~
34654 \InsetSpace ~
34655 \InsetSpace ~
34656 \InsetSpace ~
34657 \InsetSpace ~
34658  mov\InsetSpace ~
34659 \InsetSpace ~
34660  _foo_hob1_1_1,(_gint + 1) 
34661 \newline
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 \InsetSpace ~
34682 \InsetSpace ~
34683 \InsetSpace ~
34684 \InsetSpace ~
34685 \InsetSpace ~
34686 \InsetSpace ~
34687  93 ;\InsetSpace ~
34688  hob.c
34689  16 
34690 \newline
34691 003A 85*05*07\InsetSpace ~
34692 \InsetSpace ~
34693 \InsetSpace ~
34694 \InsetSpace ~
34695 \InsetSpace ~
34696 \InsetSpace ~
34697 \InsetSpace ~
34698 \InsetSpace ~
34699 \InsetSpace ~
34700 \InsetSpace ~
34701 \InsetSpace ~
34702 \InsetSpace ~
34703  94\InsetSpace ~
34704 \InsetSpace ~
34705 \InsetSpace ~
34706 \InsetSpace ~
34707 \InsetSpace ~
34708 \InsetSpace ~
34709 \InsetSpace ~
34710 \InsetSpace ~
34711  mov\InsetSpace ~
34712 \InsetSpace ~
34713  _foo_hob2_1_1,(_glong + 3) 
34714 \newline
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 \InsetSpace ~
34730 \InsetSpace ~
34731 \InsetSpace ~
34732 \InsetSpace ~
34733 \InsetSpace ~
34734 \InsetSpace ~
34735 \InsetSpace ~
34736 \InsetSpace ~
34737 \InsetSpace ~
34738 \InsetSpace ~
34739 \InsetSpace ~
34740  95 ;\InsetSpace ~
34741  hob.c 17 
34742 \newline
34743 003D 85*04*08\InsetSpace ~
34744 \InsetSpace ~
34745 \InsetSpace ~
34746 \InsetSpace ~
34747 \InsetSpace ~
34748 \InsetSpace ~
34749 \InsetSpace ~
34750 \InsetSpace ~
34751 \InsetSpace ~
34752 \InsetSpace ~
34753 \InsetSpace ~
34754 \InsetSpace ~
34755
34756  96\InsetSpace ~
34757 \InsetSpace ~
34758 \InsetSpace ~
34759 \InsetSpace ~
34760 \InsetSpace ~
34761 \InsetSpace ~
34762 \InsetSpace ~
34763 \InsetSpace ~
34764  mov\InsetSpace ~
34765 \InsetSpace ~
34766  _foo_how1_1_1,(_glong + 2) 
34767 \newline
34768 0040 85*05*09\InsetSpace ~
34769 \InsetSpace ~
34770 \InsetSpace ~
34771 \InsetSpace ~
34772 \InsetSpace ~
34773 \InsetSpace ~
34774 \InsetSpace ~
34775 \InsetSpace ~
34776 \InsetSpace ~
34777 \InsetSpace ~
34778 \InsetSpace ~
34779 \InsetSpace ~
34780  97\InsetSpace ~
34781 \InsetSpace ~
34782 \InsetSpace ~
34783 \InsetSpace ~
34784 \InsetSpace ~
34785 \InsetSpace ~
34786 \InsetSpace ~
34787 \InsetSpace ~
34788  mov\InsetSpace ~
34789 \InsetSpace ~
34790  (_foo_how1_1_1 +
34791  1),(_glong + 3) 
34792 \newline
34793 0043 85*03*0A\InsetSpace ~
34794 \InsetSpace ~
34795 \InsetSpace ~
34796 \InsetSpace ~
34797 \InsetSpace ~
34798 \InsetSpace ~
34799 \InsetSpace ~
34800 \InsetSpace ~
34801 \InsetSpace ~
34802 \InsetSpace ~
34803 \InsetSpace ~
34804 \InsetSpace ~
34805  98\InsetSpace ~
34806 \InsetSpace ~
34807 \InsetSpace ~
34808 \InsetSpace ~
34809 \InsetSpace ~
34810 \InsetSpace ~
34811 \InsetSpace ~
34812 \InsetSpace ~
34813  mov\InsetSpace ~
34814 \InsetSpace ~
34815  _foo_how2_1_1,(_glong + 1) 
34816 \newline
34817 0046 85*04*0B\InsetSpace ~
34818 \InsetSpace ~
34819 \InsetSpace ~
34820 \InsetSpace ~
34821 \InsetSpace ~
34822 \InsetSpace ~
34823 \InsetSpace ~
34824 \InsetSpace ~
34825 \InsetSpace ~
34826 \InsetSpace ~
34827 \InsetSpace ~
34828 \InsetSpace ~
34829
34830  99\InsetSpace ~
34831 \InsetSpace ~
34832 \InsetSpace ~
34833 \InsetSpace ~
34834 \InsetSpace ~
34835 \InsetSpace ~
34836 \InsetSpace ~
34837 \InsetSpace ~
34838  mov\InsetSpace ~
34839 \InsetSpace ~
34840  (_foo_how2_1_1 + 1),(_glong + 2) 
34841 \end_layout
34842
34843 \begin_layout Standard
34844 Again, variations of these cases may 
34845 \emph on
34846 not
34847 \emph default
34848  be recognized.
34849  They are standard C expressions, so I heartily recommend these be the only
34850  way to get the higher order byte/word, (it is portable).
34851  Of course it will be recognized even if it is embedded in other expressions,
34852  e.g.:
34853 \end_layout
34854
34855 \begin_layout Verse
34856
34857 \family typewriter
34858 xyz = gint + ((gint >> 8) & 0xFF);
34859 \end_layout
34860
34861 \begin_layout Standard
34862 will still be recognized.
34863 \end_layout
34864
34865 \begin_layout Subsection
34866 Peephole Optimizer
34867 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
34868
34869 \end_inset
34870
34871
34872 \begin_inset LatexCommand \index{Peephole optimizer}
34873
34874 \end_inset
34875
34876
34877 \end_layout
34878
34879 \begin_layout Standard
34880 The compiler uses a rule based, pattern matching and re-writing mechanism
34881  for peep-hole optimization.
34882  It is inspired by 
34883 \emph on
34884 copt
34885 \emph default
34886  a peep-hole optimizer by Christopher W.
34887  Fraser (cwfraser\InsetSpace ~
34888 @\InsetSpace ~
34889 microsoft.com).
34890  A default set of rules are compiled into the compiler, additional rules
34891  may be added with the 
34892 \emph on
34893 -
34894 \begin_inset ERT
34895 status collapsed
34896
34897 \begin_layout Standard
34898
34899
34900 \backslash
34901 /
34902 \end_layout
34903
34904 \end_inset
34905
34906 -peep-file
34907 \begin_inset LatexCommand \index{-\/-peep-file}
34908
34909 \end_inset
34910
34911  <filename>
34912 \emph default
34913  option.
34914  The rule language is best illustrated with examples.
34915 \end_layout
34916
34917 \begin_layout Verse
34918
34919 \family typewriter
34920 replace { 
34921 \newline
34922 \InsetSpace ~
34923 \InsetSpace ~
34924 mov %1,a 
34925 \newline
34926 \InsetSpace ~
34927 \InsetSpace ~
34928 mov a,%1
34929 \newline
34930 } by {
34931 \newline
34932 \InsetSpace ~
34933 \InsetSpace ~
34934 mov %1,a
34935 \newline
34936 }
34937 \end_layout
34938
34939 \begin_layout Standard
34940 The above rule will change the following assembly
34941 \begin_inset LatexCommand \index{Assembler routines}
34942
34943 \end_inset
34944
34945  sequence:
34946 \end_layout
34947
34948 \begin_layout Verse
34949
34950 \family typewriter
34951 mov r1,a 
34952 \newline
34953 mov a,r1
34954 \end_layout
34955
34956 \begin_layout Standard
34957 to
34958 \end_layout
34959
34960 \begin_layout Verse
34961
34962 \family typewriter
34963 mov r1,a
34964 \end_layout
34965
34966 \begin_layout Standard
34967 Note: All occurrences of a 
34968 \emph on
34969 %n
34970 \emph default
34971  (pattern variable) must denote the same string.
34972  With the above rule, the assembly sequence:
34973 \end_layout
34974
34975 \begin_layout Verse
34976
34977 \family typewriter
34978 mov r1,a 
34979 \newline
34980 mov a,r2
34981 \end_layout
34982
34983 \begin_layout Standard
34984 will remain unmodified.
34985 \newline
34986
34987 \newline
34988 Other special case optimizations may be added by the
34989  user (via 
34990 \emph on
34991 -
34992 \begin_inset ERT
34993 status collapsed
34994
34995 \begin_layout Standard
34996
34997
34998 \backslash
34999 /
35000 \end_layout
35001
35002 \end_inset
35003
35004 -peep-file option
35005 \emph default
35006 ).
35007  E.g.
35008  some variants of the 8051 MCU
35009 \begin_inset LatexCommand \index{MCS51 variants}
35010
35011 \end_inset
35012
35013  allow only 
35014 \family typewriter
35015 ajmp
35016 \family default
35017  and 
35018 \family typewriter
35019 acall
35020 \family default
35021 .
35022  The following two rules will change all 
35023 \family typewriter
35024 ljmp
35025 \family default
35026  and 
35027 \family typewriter
35028 lcall
35029 \family default
35030  to 
35031 \family typewriter
35032 ajmp
35033 \family default
35034  and 
35035 \family typewriter
35036 acall
35037 \end_layout
35038
35039 \begin_layout Verse
35040
35041 \family typewriter
35042 replace { lcall %1 } by { acall %1 } 
35043 \newline
35044 replace { ljmp %1 } by { ajmp %1 }
35045 \end_layout
35046
35047 \begin_layout Standard
35048 The 
35049 \emph on
35050 inline-assembler code
35051 \emph default
35052  is also passed through the peep hole optimizer, thus the peephole optimizer
35053  can also be used as an assembly level macro expander.
35054  The rules themselves are MCU dependent whereas the rule language infra-structur
35055 e is MCU independent.
35056  Peephole optimization rules for other MCU can be easily programmed using
35057  the rule language.
35058 \newline
35059
35060 \newline
35061 The syntax for a rule is as follows:
35062 \end_layout
35063
35064 \begin_layout Verse
35065
35066 \family typewriter
35067 rule := replace [ restart ] '{' <assembly sequence> '
35068 \backslash
35069 n' 
35070 \newline
35071 \InsetSpace ~
35072  \InsetSpace ~
35073  \InsetSpace ~
35074  \InsetSpace ~
35075  \InsetSpace ~
35076  \InsetSpace ~
35077  \InsetSpace ~
35078  \InsetSpace ~
35079  \InsetSpace ~
35080  \InsetSpace ~
35081  \InsetSpace ~
35082  \InsetSpace ~
35083  \InsetSpace ~
35084  \InsetSpace ~
35085  '}' by '{' '
35086 \backslash
35087 n' 
35088 \newline
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  <assembly sequence> '
35106 \backslash
35107 n' 
35108 \newline
35109 \InsetSpace ~
35110  \InsetSpace ~
35111  \InsetSpace ~
35112  \InsetSpace ~
35113  \InsetSpace ~
35114  \InsetSpace ~
35115  \InsetSpace ~
35116  \InsetSpace ~
35117  \InsetSpace ~
35118  \InsetSpace ~
35119  \InsetSpace ~
35120  \InsetSpace ~
35121  \InsetSpace ~
35122  \InsetSpace ~
35123  '}' [if <functionName> ] '
35124 \backslash
35125 n' 
35126 \end_layout
35127
35128 \begin_layout Standard
35129 <assembly sequence> := assembly instruction (each instruction including
35130  labels must be on a separate line).
35131 \newline
35132
35133 \newline
35134 The optimizer will apply to the rules
35135  one by one from the top in the sequence of their appearance, it will terminate
35136  when all rules are exhausted.
35137  If the 'restart' option is specified, then the optimizer will start matching
35138  the rules again from the top, this option for a rule is expensive (performance)
35139 , it is intended to be used in situations where a transformation will trigger
35140  the same rule again.
35141  An example of this (not a good one, it has side effects) is the following
35142  rule:
35143 \end_layout
35144
35145 \begin_layout Verse
35146
35147 \family typewriter
35148 replace restart { 
35149 \newline
35150 \InsetSpace ~
35151 \InsetSpace ~
35152 pop %1 
35153 \newline
35154 \InsetSpace ~
35155 \InsetSpace ~
35156 push %1 } by { 
35157 \newline
35158 \InsetSpace ~
35159 \InsetSpace ~
35160 ; nop 
35161 \newline
35162 }
35163 \end_layout
35164
35165 \begin_layout Standard
35166 Note that the replace pattern cannot be a blank, but can be a comment line.
35167  Without the 'restart' option only the innermost 'pop' 'push' pair would
35168  be eliminated, i.e.:
35169 \end_layout
35170
35171 \begin_layout Verse
35172
35173 \family typewriter
35174 pop ar1 
35175 \newline
35176 pop ar2 
35177 \newline
35178 push ar2 
35179 \newline
35180 push ar1
35181 \end_layout
35182
35183 \begin_layout Standard
35184 would result in:
35185 \end_layout
35186
35187 \begin_layout Verse
35188
35189 \family typewriter
35190 pop ar1 
35191 \newline
35192 ; nop 
35193 \newline
35194 push ar1
35195 \end_layout
35196
35197 \begin_layout Standard
35198
35199 \emph on
35200 with
35201 \emph default
35202  the restart option the rule will be applied again to the resulting code
35203  and then all the pop-push pairs will be eliminated to yield:
35204 \end_layout
35205
35206 \begin_layout Verse
35207
35208 \family typewriter
35209 ; nop 
35210 \newline
35211 ; nop
35212 \end_layout
35213
35214 \begin_layout Standard
35215 A conditional function can be attached to a rule.
35216  Attaching rules are somewhat more involved, let me illustrate this with
35217  an example.
35218 \end_layout
35219
35220 \begin_layout Verse
35221
35222 \family typewriter
35223 replace { 
35224 \newline
35225 \InsetSpace ~
35226  \InsetSpace ~
35227  \InsetSpace ~
35228 ljmp %5 
35229 \newline
35230 %2:
35231 \newline
35232 } by { 
35233 \newline
35234 \InsetSpace ~
35235  \InsetSpace ~
35236  \InsetSpace ~
35237 sjmp %5 
35238 \newline
35239 %2:
35240 \newline
35241 } if labelInRange
35242 \end_layout
35243
35244 \begin_layout Standard
35245 The optimizer does a look-up of a function name table defined in function
35246  
35247 \emph on
35248 callFuncByName
35249 \emph default
35250  in the source file SDCCpeeph.c, with the name 
35251 \emph on
35252 labelInRange
35253 \emph default
35254 .
35255  If it finds a corresponding entry the function is called.
35256  Note there can be no parameters specified for these functions, in this
35257  case the use of 
35258 \emph on
35259 %5
35260 \emph default
35261  is crucial, since the function 
35262 \emph on
35263 labelInRange
35264 \emph default
35265  expects to find the label in that particular variable (the hash table containin
35266 g the variable bindings is passed as a parameter).
35267  If you want to code more such functions, take a close look at the function
35268  labelInRange and the calling mechanism in source file SDCCpeeph.c.
35269  Currently implemented are 
35270 \emph on
35271 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
35272  24bitMode, portIsDS390, 24bitModeAndPortDS390 
35273 \emph default
35274 and
35275 \emph on
35276  notVolatile
35277 \emph default
35278 .
35279 \end_layout
35280
35281 \begin_layout Standard
35282 I know this whole thing is a little kludgey, but maybe some day we will
35283  have some better means.
35284  If you are looking at this file, you will see the default rules that are
35285  compiled into the compiler, you can add your own rules in the default set
35286  there if you get tired of specifying the -
35287 \begin_inset ERT
35288 status collapsed
35289
35290 \begin_layout Standard
35291
35292
35293 \backslash
35294 /
35295 \end_layout
35296
35297 \end_inset
35298
35299 -peep-file option.
35300 \end_layout
35301
35302 \begin_layout Section
35303 ANSI-Compliance
35304 \begin_inset LatexCommand \index{ANSI-compliance}
35305
35306 \end_inset
35307
35308
35309 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
35310
35311 \end_inset
35312
35313
35314 \end_layout
35315
35316 \begin_layout Standard
35317 The latest publically available version of the standard 
35318 \emph on
35319 ISO/IEC 9899 - Programming languages - C
35320 \emph default
35321  should be available at: 
35322 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
35323
35324 \end_inset
35325
35326 .
35327 \newline
35328
35329 \end_layout
35330
35331 \begin_layout Standard
35332 Deviations from the compliance:
35333 \end_layout
35334
35335 \begin_layout Itemize
35336 functions are not reentrant
35337 \begin_inset LatexCommand \index{reentrant}
35338
35339 \end_inset
35340
35341  unless explicitly declared as such or the 
35342 \series bold
35343 -
35344 \begin_inset ERT
35345 status collapsed
35346
35347 \begin_layout Standard
35348
35349
35350 \backslash
35351 /
35352 \end_layout
35353
35354 \end_inset
35355
35356 -stack-auto
35357 \begin_inset LatexCommand \index{-\/-stack-auto}
35358
35359 \end_inset
35360
35361
35362 \series default
35363  command line option is specified.
35364 \end_layout
35365
35366 \begin_layout Itemize
35367 structures
35368 \begin_inset LatexCommand \index{struct}
35369
35370 \end_inset
35371
35372  and unions
35373 \begin_inset LatexCommand \index{union}
35374
35375 \end_inset
35376
35377  cannot be assigned values directly, cannot be passed as function parameters
35378  or assigned to each other and cannot be a return value
35379 \begin_inset LatexCommand \index{return value}
35380
35381 \end_inset
35382
35383  from a function, e.g.:
35384 \end_layout
35385
35386 \begin_deeper
35387 \begin_layout Verse
35388
35389 \family typewriter
35390 struct s { ...
35391  }; 
35392 \newline
35393 struct s s1, s2; 
35394 \newline
35395 foo() 
35396 \newline
35397
35398 \newline
35399 \InsetSpace ~
35400 \InsetSpace ~
35401 \InsetSpace ~
35402 \InsetSpace ~
35403 ...
35404  
35405 \newline
35406 \InsetSpace ~
35407 \InsetSpace ~
35408 \InsetSpace ~
35409 \InsetSpace ~
35410 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
35411 \newline
35412 \InsetSpace ~
35413 \InsetSpace ~
35414 \InsetSpace ~
35415 \InsetSpace ~
35416 ...
35417  
35418 \newline
35419 }
35420 \newline
35421
35422 \series bold
35423 struct
35424 \series default
35425  s foo1 (
35426 \series bold
35427 struct
35428 \series default
35429  s parms) /* invalid in SDCC although allowed in ANSI */
35430 \newline
35431
35432 \newline
35433 \InsetSpace ~
35434 \InsetSpace ~
35435 \InsetSpace ~
35436 \InsetSpace ~
35437 struct s rets;
35438  
35439 \newline
35440 \InsetSpace ~
35441 \InsetSpace ~
35442 \InsetSpace ~
35443 \InsetSpace ~
35444 ...
35445  
35446 \newline
35447 \InsetSpace ~
35448 \InsetSpace ~
35449 \InsetSpace ~
35450 \InsetSpace ~
35451 return rets; /* is invalid in SDCC although allowed in ANSI */ 
35452 \newline
35453 }
35454 \end_layout
35455
35456 \end_deeper
35457 \begin_layout Itemize
35458 initialization of structure arrays must be fully braced.
35459 \end_layout
35460
35461 \begin_deeper
35462 \begin_layout Verse
35463
35464 \family typewriter
35465 struct s { char x } a[] = {1, 2};\InsetSpace ~
35466 \InsetSpace ~
35467 \InsetSpace ~
35468 \InsetSpace ~
35469 \InsetSpace ~
35470 /* invalid in SDCC */
35471 \newline
35472 struct s { char x
35473  } a[] = {{1}, {2}}; /* OK */
35474 \end_layout
35475
35476 \end_deeper
35477 \begin_layout Itemize
35478 'long long
35479 \begin_inset LatexCommand \index{long long (not supported)}
35480
35481 \end_inset
35482
35483 ' (64 bit integers
35484 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
35485
35486 \end_inset
35487
35488 ) not supported.
35489 \end_layout
35490
35491 \begin_layout Itemize
35492 'double
35493 \begin_inset LatexCommand \index{double (not supported)}
35494
35495 \end_inset
35496
35497 ' precision floating point 
35498 \begin_inset LatexCommand \index{Floating point support}
35499
35500 \end_inset
35501
35502 not supported.
35503 \end_layout
35504
35505 \begin_layout Itemize
35506 Old K&R style
35507 \begin_inset LatexCommand \index{K\&R style}
35508
35509 \end_inset
35510
35511  function declarations are NOT allowed.
35512 \end_layout
35513
35514 \begin_deeper
35515 \begin_layout Verse
35516
35517 \family typewriter
35518 foo(i,j) /* this old style of function declarations */ 
35519 \newline
35520 int i,j; /* are valid
35521  in ANSI but not valid in SDCC */ 
35522 \newline
35523
35524 \newline
35525 \InsetSpace ~
35526 \InsetSpace ~
35527 \InsetSpace ~
35528 \InsetSpace ~
35529 ...
35530  
35531 \newline
35532 }
35533 \end_layout
35534
35535 \end_deeper
35536 \begin_layout Itemize
35537 Most enhancements in C99 are not supported, f.e.:
35538 \end_layout
35539
35540 \begin_deeper
35541 \begin_layout Verse
35542
35543 \family typewriter
35544 \series bold
35545 inline
35546 \begin_inset LatexCommand \index{inline (not supported)}
35547
35548 \end_inset
35549
35550
35551 \series default
35552  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
35553  in C99.
35554  An empty define 
35555 \emph on
35556 #define inline
35557 \emph default
35558  can be used as a work around */
35559 \newline
35560
35561 \newline
35562 for (
35563 \series bold
35564 int
35565 \series default
35566  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
35567 \end_layout
35568
35569 \end_deeper
35570 \begin_layout Itemize
35571 Certain words that are valid identifiers in the standard may be reserved
35572  words in SDCC unless the 
35573 \series bold
35574 -
35575 \begin_inset ERT
35576 status collapsed
35577
35578 \begin_layout Standard
35579
35580
35581 \backslash
35582 /
35583 \end_layout
35584
35585 \end_inset
35586
35587 -std-c89
35588 \begin_inset LatexCommand \index{-\/-std-c89}
35589
35590 \end_inset
35591
35592  or -
35593 \begin_inset ERT
35594 status collapsed
35595
35596 \begin_layout Standard
35597
35598
35599 \backslash
35600 /
35601 \end_layout
35602
35603 \end_inset
35604
35605 -std-c99
35606 \begin_inset LatexCommand \index{-\/-std-c99}
35607
35608 \end_inset
35609
35610
35611 \series default
35612  command line options are used.
35613  These may include (depending on the selected processor): 'at', 'banked',
35614  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
35615 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
35616  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
35617  '_naked'.
35618  Compliant equivalents of these keywords are always available in a form
35619  that begin with two underscores
35620 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
35621
35622 \end_inset
35623
35624 , f.e.
35625  '__data' instead of 'data'.
35626 \end_layout
35627
35628 \begin_layout Section
35629 Cyclomatic Complexity
35630 \begin_inset LatexCommand \index{Cyclomatic complexity}
35631
35632 \end_inset
35633
35634
35635 \end_layout
35636
35637 \begin_layout Standard
35638 Cyclomatic complexity of a function is defined as the number of independent
35639  paths the program can take during execution of the function.
35640  This is an important number since it defines the number test cases you
35641  have to generate to validate the function.
35642  The accepted industry standard for complexity number is 10, if the cyclomatic
35643  complexity reported by SDCC exceeds 10 you should think about simplification
35644  of the function logic.
35645  Note that the complexity level is not related to the number of lines of
35646  code in a function.
35647  Large functions can have low complexity, and small functions can have large
35648  complexity levels.
35649  
35650 \newline
35651
35652 \newline
35653 SDCC uses the following formula to compute the complexity:
35654 \newline
35655
35656 \end_layout
35657
35658 \begin_layout Standard
35659 complexity = (number of edges in control flow graph) - (number of nodes
35660  in control flow graph) + 2;
35661 \newline
35662
35663 \newline
35664 Having said that the industry standard is 10,
35665  you should be aware that in some cases it be may unavoidable to have a
35666  complexity level of less than 10.
35667  For example if you have switch statement with more than 10 case labels,
35668  each case label adds one to the complexity level.
35669  The complexity level is by no means an absolute measure of the algorithmic
35670  complexity of the function, it does however provide a good starting point
35671  for which functions you might look at for further optimization.
35672 \end_layout
35673
35674 \begin_layout Section
35675 Retargetting for other Processors
35676 \end_layout
35677
35678 \begin_layout Standard
35679 The issues for retargetting the compiler are far too numerous to be covered
35680  by this document.
35681  What follows is a brief description of each of the seven phases of the
35682  compiler and its MCU dependency.
35683 \end_layout
35684
35685 \begin_layout Itemize
35686 Parsing the source and building the annotated parse tree.
35687  This phase is largely MCU independent (except for the language extensions).
35688  Syntax & semantic checks are also done in this phase, along with some initial
35689  optimizations like back patching labels and the pattern matching optimizations
35690  like bit-rotation etc.
35691 \end_layout
35692
35693 \begin_layout Itemize
35694 The second phase involves generating an intermediate code which can be easy
35695  manipulated during the later phases.
35696  This phase is entirely MCU independent.
35697  The intermediate code generation assumes the target machine has unlimited
35698  number of registers, and designates them with the name iTemp.
35699  The compiler can be made to dump a human readable form of the code generated
35700  by using the -
35701 \begin_inset ERT
35702 status collapsed
35703
35704 \begin_layout Standard
35705
35706
35707 \backslash
35708 /
35709 \end_layout
35710
35711 \end_inset
35712
35713 -dumpraw option.
35714 \end_layout
35715
35716 \begin_layout Itemize
35717 This phase does the bulk of the standard optimizations and is also MCU independe
35718 nt.
35719  This phase can be broken down into several sub-phases:
35720 \newline
35721
35722 \newline
35723 Break down intermediate
35724  code (iCode) into basic blocks.
35725 \newline
35726 Do control flow & data flow analysis on the
35727  basic blocks.
35728 \newline
35729 Do local common subexpression elimination, then global subexpressio
35730 n elimination
35731 \newline
35732 Dead code elimination
35733 \newline
35734 Loop optimizations
35735 \newline
35736 If loop optimizations
35737  caused any changes then do 'global subexpression elimination' and 'dead
35738  code elimination' again.
35739 \end_layout
35740
35741 \begin_layout Itemize
35742 This phase determines the live-ranges; by live range I mean those iTemp
35743  variables defined by the compiler that still survive after all the optimization
35744 s.
35745  Live range analysis
35746 \begin_inset LatexCommand \index{Live range analysis}
35747
35748 \end_inset
35749
35750  is essential for register allocation, since these computation determines
35751  which of these iTemps will be assigned to registers, and for how long.
35752 \end_layout
35753
35754 \begin_layout Itemize
35755 Phase five is register allocation.
35756  There are two parts to this process.
35757 \newline
35758
35759 \newline
35760 The first part I call 'register packing'
35761  (for lack of a better term).
35762  In this case several MCU specific expression folding is done to reduce
35763  register pressure.
35764 \newline
35765
35766 \newline
35767 The second part is more MCU independent and deals with
35768  allocating registers to the remaining live ranges.
35769  A lot of MCU specific code does creep into this phase because of the limited
35770  number of index registers available in the 8051.
35771 \end_layout
35772
35773 \begin_layout Itemize
35774 The Code generation phase is (unhappily), entirely MCU dependent and very
35775  little (if any at all) of this code can be reused for other MCU.
35776  However the scheme for allocating a homogenized assembler operand for each
35777  iCode operand may be reused.
35778 \end_layout
35779
35780 \begin_layout Itemize
35781 As mentioned in the optimization section the peep-hole optimizer is rule
35782  based system, which can reprogrammed for other MCUs.
35783 \end_layout
35784
35785 \begin_layout Standard
35786 More information is available in a wiki
35787 \begin_inset LatexCommand \index{wiki}
35788
35789 \end_inset
35790
35791  (preliminary link 
35792 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
35793
35794 \end_inset
35795
35796 ) and in the thread 
35797 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
35798
35799 \end_inset
35800
35801  .
35802 \end_layout
35803
35804 \begin_layout Chapter
35805 Compiler internals
35806 \begin_inset LatexCommand \index{Compiler internals}
35807
35808 \end_inset
35809
35810
35811 \end_layout
35812
35813 \begin_layout Section
35814 The anatomy of the compiler
35815 \begin_inset LatexCommand \label{sub:The-anatomy-of}
35816
35817 \end_inset
35818
35819
35820 \end_layout
35821
35822 \begin_layout Standard
35823
35824 \shape italic
35825 This is an excerpt from an article published in Circuit Cellar Magazine
35826  in 
35827 \series bold
35828 August 2000
35829 \series default
35830 .
35831  It's a little outdated (the compiler is much more efficient now and user/develo
35832 per friendly), but pretty well exposes the guts of it all.
35833 \shape default
35834
35835 \newline
35836
35837 \newline
35838 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
35839  It is fairly easy to retarget for other 8-bit MCU.
35840  Here we take a look at some of the internals of the compiler.
35841  
35842 \end_layout
35843
35844 \begin_layout Paragraph*
35845 Parsing
35846 \begin_inset LatexCommand \index{Parsing}
35847
35848 \end_inset
35849
35850  
35851 \end_layout
35852
35853 \begin_layout Standard
35854 Parsing the input source file and creating an AST (Annotated Syntax Tree
35855 \begin_inset LatexCommand \index{Annotated syntax tree}
35856
35857 \end_inset
35858
35859 ).
35860  This phase also involves propagating types (annotating each node of the
35861  parse tree with type information) and semantic analysis.
35862  There are some MCU specific parsing rules.
35863  For example the storage classes, the extended storage classes are MCU specific
35864  while there may be a xdata storage class for 8051 there is no such storage
35865  class for z80 or Atmel AVR.
35866  SDCC allows MCU specific storage class extensions, i.e.
35867  xdata will be treated as a storage class specifier when parsing 8051 C
35868  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
35869  C code.
35870 \end_layout
35871
35872 \begin_layout Paragraph*
35873 Generating iCode
35874 \begin_inset LatexCommand \index{iCode}
35875
35876 \end_inset
35877
35878
35879 \end_layout
35880
35881 \begin_layout Standard
35882 Intermediate code generation.
35883  In this phase the AST is broken down into three-operand form (iCode).
35884  These three operand forms are represented as doubly linked lists.
35885  ICode is the term given to the intermediate form generated by the compiler.
35886  ICode example section shows some examples of iCode generated for some simple
35887  C source functions.
35888 \end_layout
35889
35890 \begin_layout Paragraph*
35891 Optimizations
35892 \begin_inset LatexCommand \index{Optimizations}
35893
35894 \end_inset
35895
35896 .
35897 \end_layout
35898
35899 \begin_layout Standard
35900 Bulk of the target independent optimizations is performed in this phase.
35901  The optimizations include constant propagation, common sub-expression eliminati
35902 on, loop invariant code movement, strength reduction of loop induction variables
35903  and dead-code elimination.
35904 \end_layout
35905
35906 \begin_layout Paragraph*
35907 Live range analysis
35908 \begin_inset LatexCommand \index{Live range analysis}
35909
35910 \end_inset
35911
35912
35913 \end_layout
35914
35915 \begin_layout Standard
35916 During intermediate code generation phase, the compiler assumes the target
35917  machine has infinite number of registers and generates a lot of temporary
35918  variables.
35919  The live range computation determines the lifetime of each of these compiler-ge
35920 nerated temporaries.
35921  A picture speaks a thousand words.
35922  ICode example sections show the live range annotations for each of the
35923  operand.
35924  It is important to note here, each iCode is assigned a number in the order
35925  of its execution in the function.
35926  The live ranges are computed in terms of these numbers.
35927  The from number is the number of the iCode which first defines the operand
35928  and the to number signifies the iCode which uses this operand last.
35929 \end_layout
35930
35931 \begin_layout Paragraph*
35932 Register Allocation
35933 \begin_inset LatexCommand \index{Register allocation}
35934
35935 \end_inset
35936
35937
35938 \end_layout
35939
35940 \begin_layout Standard
35941 The register allocation determines the type and number of registers needed
35942  by each operand.
35943  In most MCUs only a few registers can be used for indirect addressing.
35944  In case of 8051 for example the registers R0 & R1 can be used to indirectly
35945  address the internal ram and DPTR to indirectly address the external ram.
35946  The compiler will try to allocate the appropriate register to pointer variables
35947  if it can.
35948  ICode example section shows the operands annotated with the registers assigned
35949  to them.
35950  The compiler will try to keep operands in registers as much as possible;
35951  there are several schemes the compiler uses to do achieve this.
35952  When the compiler runs out of registers the compiler will check to see
35953  if there are any live operands which is not used or defined in the current
35954  basic block being processed, if there are any found then it will push that
35955  operand and use the registers in this block, the operand will then be popped
35956  at the end of the basic block.
35957  
35958 \end_layout
35959
35960 \begin_layout Standard
35961 There are other MCU specific considerations in this phase.
35962  Some MCUs have an accumulator; very short-lived operands could be assigned
35963  to the accumulator instead of a general-purpose register.
35964 \end_layout
35965
35966 \begin_layout Paragraph*
35967 Code generation
35968 \end_layout
35969
35970 \begin_layout Standard
35971 Figure II gives a table of iCode
35972 \begin_inset LatexCommand \index{iCode}
35973
35974 \end_inset
35975
35976  operations supported by the compiler.
35977  The code generation involves translating these operations into corresponding
35978  assembly code for the processor.
35979  This sounds overly simple but that is the essence of code generation.
35980  Some of the iCode operations are generated on a MCU specific manner for
35981  example, the z80 port does not use registers to pass parameters so the
35982  SEND and RECV iCode operations will not be generated, and it also does
35983  not support JUMPTABLES.
35984  
35985 \newline
35986
35987 \end_layout
35988
35989 \begin_layout Standard
35990
35991 \size footnotesize
35992 Figure II 
35993 \begin_inset Tabular
35994 <lyxtabular version="3" rows="39" columns="4">
35995 <features islongtable="true" headBottomDL="true">
35996 <column alignment="block" valignment="top" leftline="true" width="13col%">
35997 <column alignment="left" valignment="top" leftline="true" width="13col%">
35998 <column alignment="block" valignment="top" leftline="true" width="22col%">
35999 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
36000 <row topline="true" bottomline="true" endhead="true">
36001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36002 \begin_inset Text
36003
36004 \begin_layout Standard
36005
36006 \series bold
36007 iCode
36008 \series default
36009
36010 \begin_inset LatexCommand \index{iCode}
36011
36012 \end_inset
36013
36014
36015 \end_layout
36016
36017 \end_inset
36018 </cell>
36019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36020 \begin_inset Text
36021
36022 \begin_layout Standard
36023
36024 \series bold
36025 Operands
36026 \end_layout
36027
36028 \end_inset
36029 </cell>
36030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36031 \begin_inset Text
36032
36033 \begin_layout Standard
36034
36035 \series bold
36036 Description
36037 \end_layout
36038
36039 \end_inset
36040 </cell>
36041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36042 \begin_inset Text
36043
36044 \begin_layout Standard
36045
36046 \series bold
36047 C Equivalent
36048 \end_layout
36049
36050 \end_inset
36051 </cell>
36052 </row>
36053 <row topline="true">
36054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36055 \begin_inset Text
36056
36057 \begin_layout Standard
36058
36059 \size footnotesize
36060 '!'
36061 \end_layout
36062
36063 \end_inset
36064 </cell>
36065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36066 \begin_inset Text
36067
36068 \begin_layout Standard
36069
36070 \size footnotesize
36071 IC_LEFT() IC_RESULT()
36072 \end_layout
36073
36074 \end_inset
36075 </cell>
36076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36077 \begin_inset Text
36078
36079 \begin_layout Standard
36080
36081 \size footnotesize
36082 NOT operation 
36083 \end_layout
36084
36085 \end_inset
36086 </cell>
36087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36088 \begin_inset Text
36089
36090 \begin_layout Standard
36091
36092 \size footnotesize
36093 IC_RESULT = ! IC_LEFT;
36094 \end_layout
36095
36096 \end_inset
36097 </cell>
36098 </row>
36099 <row topline="true">
36100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36101 \begin_inset Text
36102
36103 \begin_layout Standard
36104
36105 \size footnotesize
36106 '~'
36107 \end_layout
36108
36109 \end_inset
36110 </cell>
36111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36112 \begin_inset Text
36113
36114 \begin_layout Standard
36115
36116 \size footnotesize
36117 IC_LEFT() IC_RESULT()
36118 \end_layout
36119
36120 \end_inset
36121 </cell>
36122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36123 \begin_inset Text
36124
36125 \begin_layout Standard
36126
36127 \size footnotesize
36128 Bitwise complement of 
36129 \end_layout
36130
36131 \end_inset
36132 </cell>
36133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36134 \begin_inset Text
36135
36136 \begin_layout Standard
36137
36138 \size footnotesize
36139 IC_RESULT = ~IC_LEFT;
36140 \end_layout
36141
36142 \end_inset
36143 </cell>
36144 </row>
36145 <row topline="true">
36146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36147 \begin_inset Text
36148
36149 \begin_layout Standard
36150
36151 \size footnotesize
36152 RRC
36153 \end_layout
36154
36155 \end_inset
36156 </cell>
36157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36158 \begin_inset Text
36159
36160 \begin_layout Standard
36161
36162 \size footnotesize
36163 IC_LEFT() IC_RESULT()
36164 \end_layout
36165
36166 \end_inset
36167 </cell>
36168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36169 \begin_inset Text
36170
36171 \begin_layout Standard
36172
36173 \size footnotesize
36174 Rotate right with carry
36175 \end_layout
36176
36177 \end_inset
36178 </cell>
36179 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36180 \begin_inset Text
36181
36182 \begin_layout Standard
36183
36184 \size footnotesize
36185 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
36186 \end_layout
36187
36188 \end_inset
36189 </cell>
36190 </row>
36191 <row topline="true">
36192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36193 \begin_inset Text
36194
36195 \begin_layout Standard
36196
36197 \size footnotesize
36198 RLC
36199 \end_layout
36200
36201 \end_inset
36202 </cell>
36203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36204 \begin_inset Text
36205
36206 \begin_layout Standard
36207
36208 \size footnotesize
36209 IC_LEFT() IC_RESULT()
36210 \end_layout
36211
36212 \end_inset
36213 </cell>
36214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36215 \begin_inset Text
36216
36217 \begin_layout Standard
36218
36219 \size footnotesize
36220 Rotate left with carry
36221 \end_layout
36222
36223 \end_inset
36224 </cell>
36225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36226 \begin_inset Text
36227
36228 \begin_layout Standard
36229
36230 \size footnotesize
36231 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
36232 \end_layout
36233
36234 \end_inset
36235 </cell>
36236 </row>
36237 <row topline="true">
36238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36239 \begin_inset Text
36240
36241 \begin_layout Standard
36242
36243 \size footnotesize
36244 GETHBIT
36245 \end_layout
36246
36247 \end_inset
36248 </cell>
36249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36250 \begin_inset Text
36251
36252 \begin_layout Standard
36253
36254 \size footnotesize
36255 IC_LEFT() IC_RESULT()
36256 \end_layout
36257
36258 \end_inset
36259 </cell>
36260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36261 \begin_inset Text
36262
36263 \begin_layout Standard
36264
36265 \size footnotesize
36266 Get the highest order bit of IC_LEFT
36267 \end_layout
36268
36269 \end_inset
36270 </cell>
36271 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36272 \begin_inset Text
36273
36274 \begin_layout Standard
36275
36276 \size footnotesize
36277 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
36278 \end_layout
36279
36280 \end_inset
36281 </cell>
36282 </row>
36283 <row topline="true">
36284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36285 \begin_inset Text
36286
36287 \begin_layout Standard
36288
36289 \size footnotesize
36290 UNARYMINUS
36291 \end_layout
36292
36293 \end_inset
36294 </cell>
36295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36296 \begin_inset Text
36297
36298 \begin_layout Standard
36299
36300 \size footnotesize
36301 IC_LEFT() IC_RESULT()
36302 \end_layout
36303
36304 \end_inset
36305 </cell>
36306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36307 \begin_inset Text
36308
36309 \begin_layout Standard
36310
36311 \size footnotesize
36312 Unary minus
36313 \end_layout
36314
36315 \end_inset
36316 </cell>
36317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36318 \begin_inset Text
36319
36320 \begin_layout Standard
36321
36322 \size footnotesize
36323 IC_RESULT = - IC_LEFT;
36324 \end_layout
36325
36326 \end_inset
36327 </cell>
36328 </row>
36329 <row topline="true">
36330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36331 \begin_inset Text
36332
36333 \begin_layout Standard
36334
36335 \size footnotesize
36336 IPUSH
36337 \end_layout
36338
36339 \end_inset
36340 </cell>
36341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36342 \begin_inset Text
36343
36344 \begin_layout Standard
36345
36346 \size footnotesize
36347 IC_LEFT()
36348 \end_layout
36349
36350 \end_inset
36351 </cell>
36352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36353 \begin_inset Text
36354
36355 \begin_layout Standard
36356
36357 \size footnotesize
36358 Push the operand into stack
36359 \end_layout
36360
36361 \end_inset
36362 </cell>
36363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36364 \begin_inset Text
36365
36366 \begin_layout Standard
36367
36368 \size footnotesize
36369 NONE
36370 \end_layout
36371
36372 \end_inset
36373 </cell>
36374 </row>
36375 <row topline="true">
36376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36377 \begin_inset Text
36378
36379 \begin_layout Standard
36380
36381 \size footnotesize
36382 IPOP
36383 \end_layout
36384
36385 \end_inset
36386 </cell>
36387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36388 \begin_inset Text
36389
36390 \begin_layout Standard
36391
36392 \size footnotesize
36393 IC_LEFT()
36394 \end_layout
36395
36396 \end_inset
36397 </cell>
36398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36399 \begin_inset Text
36400
36401 \begin_layout Standard
36402
36403 \size footnotesize
36404 Pop the operand from the stack 
36405 \end_layout
36406
36407 \end_inset
36408 </cell>
36409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36410 \begin_inset Text
36411
36412 \begin_layout Standard
36413
36414 \size footnotesize
36415 NONE
36416 \end_layout
36417
36418 \end_inset
36419 </cell>
36420 </row>
36421 <row topline="true">
36422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36423 \begin_inset Text
36424
36425 \begin_layout Standard
36426
36427 \size footnotesize
36428 CALL
36429 \end_layout
36430
36431 \end_inset
36432 </cell>
36433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36434 \begin_inset Text
36435
36436 \begin_layout Standard
36437
36438 \size footnotesize
36439 IC_LEFT() IC_RESULT()
36440 \end_layout
36441
36442 \end_inset
36443 </cell>
36444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36445 \begin_inset Text
36446
36447 \begin_layout Standard
36448
36449 \size footnotesize
36450 Call the function represented by IC_LEFT 
36451 \end_layout
36452
36453 \end_inset
36454 </cell>
36455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36456 \begin_inset Text
36457
36458 \begin_layout Standard
36459
36460 \size footnotesize
36461 IC_RESULT = IC_LEFT();
36462 \end_layout
36463
36464 \end_inset
36465 </cell>
36466 </row>
36467 <row topline="true">
36468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36469 \begin_inset Text
36470
36471 \begin_layout Standard
36472
36473 \size footnotesize
36474 PCALL
36475 \end_layout
36476
36477 \end_inset
36478 </cell>
36479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36480 \begin_inset Text
36481
36482 \begin_layout Standard
36483
36484 \size footnotesize
36485 IC_LEFT() IC_RESULT()
36486 \end_layout
36487
36488 \end_inset
36489 </cell>
36490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36491 \begin_inset Text
36492
36493 \begin_layout Standard
36494
36495 \size footnotesize
36496 Call via function pointer
36497 \end_layout
36498
36499 \end_inset
36500 </cell>
36501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36502 \begin_inset Text
36503
36504 \begin_layout Standard
36505
36506 \size footnotesize
36507 IC_RESULT = (*IC_LEFT)();
36508 \end_layout
36509
36510 \end_inset
36511 </cell>
36512 </row>
36513 <row topline="true">
36514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36515 \begin_inset Text
36516
36517 \begin_layout Standard
36518
36519 \size footnotesize
36520 RETURN
36521 \end_layout
36522
36523 \end_inset
36524 </cell>
36525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36526 \begin_inset Text
36527
36528 \begin_layout Standard
36529
36530 \size footnotesize
36531 IC_LEFT()
36532 \end_layout
36533
36534 \end_inset
36535 </cell>
36536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36537 \begin_inset Text
36538
36539 \begin_layout Standard
36540
36541 \size footnotesize
36542 Return the value in operand IC_LEFT 
36543 \end_layout
36544
36545 \end_inset
36546 </cell>
36547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36548 \begin_inset Text
36549
36550 \begin_layout Standard
36551
36552 \size footnotesize
36553 return IC_LEFT;
36554 \end_layout
36555
36556 \end_inset
36557 </cell>
36558 </row>
36559 <row topline="true">
36560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36561 \begin_inset Text
36562
36563 \begin_layout Standard
36564
36565 \size footnotesize
36566 LABEL
36567 \end_layout
36568
36569 \end_inset
36570 </cell>
36571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36572 \begin_inset Text
36573
36574 \begin_layout Standard
36575
36576 \size footnotesize
36577 IC_LABEL() 
36578 \end_layout
36579
36580 \end_inset
36581 </cell>
36582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36583 \begin_inset Text
36584
36585 \begin_layout Standard
36586
36587 \size footnotesize
36588 Label
36589 \end_layout
36590
36591 \end_inset
36592 </cell>
36593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36594 \begin_inset Text
36595
36596 \begin_layout Standard
36597
36598 \size footnotesize
36599 IC_LABEL:
36600 \end_layout
36601
36602 \end_inset
36603 </cell>
36604 </row>
36605 <row topline="true">
36606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36607 \begin_inset Text
36608
36609 \begin_layout Standard
36610
36611 \size footnotesize
36612 GOTO
36613 \end_layout
36614
36615 \end_inset
36616 </cell>
36617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36618 \begin_inset Text
36619
36620 \begin_layout Standard
36621
36622 \size footnotesize
36623 IC_LABEL() 
36624 \end_layout
36625
36626 \end_inset
36627 </cell>
36628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36629 \begin_inset Text
36630
36631 \begin_layout Standard
36632
36633 \size footnotesize
36634 Goto label
36635 \end_layout
36636
36637 \end_inset
36638 </cell>
36639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36640 \begin_inset Text
36641
36642 \begin_layout Standard
36643
36644 \size footnotesize
36645 goto IC_LABEL();
36646 \end_layout
36647
36648 \end_inset
36649 </cell>
36650 </row>
36651 <row topline="true">
36652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36653 \begin_inset Text
36654
36655 \begin_layout Standard
36656
36657 \size footnotesize
36658 '+'
36659 \end_layout
36660
36661 \end_inset
36662 </cell>
36663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36664 \begin_inset Text
36665
36666 \begin_layout Standard
36667
36668 \size footnotesize
36669 IC_LEFT() IC_RIGHT() IC_RESULT()
36670 \end_layout
36671
36672 \end_inset
36673 </cell>
36674 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36675 \begin_inset Text
36676
36677 \begin_layout Standard
36678
36679 \size footnotesize
36680 Addition
36681 \end_layout
36682
36683 \end_inset
36684 </cell>
36685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36686 \begin_inset Text
36687
36688 \begin_layout Standard
36689
36690 \size footnotesize
36691 IC_RESULT = IC_LEFT + IC_RIGHT
36692 \end_layout
36693
36694 \end_inset
36695 </cell>
36696 </row>
36697 <row topline="true">
36698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36699 \begin_inset Text
36700
36701 \begin_layout Standard
36702
36703 \size footnotesize
36704 '-'
36705 \end_layout
36706
36707 \end_inset
36708 </cell>
36709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36710 \begin_inset Text
36711
36712 \begin_layout Standard
36713
36714 \size footnotesize
36715 IC_LEFT() IC_RIGHT() IC_RESULT()
36716 \end_layout
36717
36718 \end_inset
36719 </cell>
36720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36721 \begin_inset Text
36722
36723 \begin_layout Standard
36724
36725 \size footnotesize
36726 Subtraction
36727 \end_layout
36728
36729 \end_inset
36730 </cell>
36731 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36732 \begin_inset Text
36733
36734 \begin_layout Standard
36735
36736 \size footnotesize
36737 IC_RESULT = IC_LEFT - IC_RIGHT 
36738 \end_layout
36739
36740 \end_inset
36741 </cell>
36742 </row>
36743 <row topline="true">
36744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36745 \begin_inset Text
36746
36747 \begin_layout Standard
36748
36749 \size footnotesize
36750 '*'
36751 \end_layout
36752
36753 \end_inset
36754 </cell>
36755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36756 \begin_inset Text
36757
36758 \begin_layout Standard
36759
36760 \size footnotesize
36761 IC_LEFT() IC_RIGHT() IC_RESULT()
36762 \end_layout
36763
36764 \end_inset
36765 </cell>
36766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36767 \begin_inset Text
36768
36769 \begin_layout Standard
36770
36771 \size footnotesize
36772 Multiplication 
36773 \end_layout
36774
36775 \end_inset
36776 </cell>
36777 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36778 \begin_inset Text
36779
36780 \begin_layout Standard
36781
36782 \size footnotesize
36783 IC_RESULT = IC_LEFT * IC_RIGHT;
36784 \end_layout
36785
36786 \end_inset
36787 </cell>
36788 </row>
36789 <row topline="true">
36790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36791 \begin_inset Text
36792
36793 \begin_layout Standard
36794
36795 \size footnotesize
36796 '/'
36797 \end_layout
36798
36799 \end_inset
36800 </cell>
36801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36802 \begin_inset Text
36803
36804 \begin_layout Standard
36805
36806 \size footnotesize
36807 IC_LEFT() IC_RIGHT() IC_RESULT()
36808 \end_layout
36809
36810 \end_inset
36811 </cell>
36812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36813 \begin_inset Text
36814
36815 \begin_layout Standard
36816
36817 \size footnotesize
36818 Division
36819 \end_layout
36820
36821 \end_inset
36822 </cell>
36823 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36824 \begin_inset Text
36825
36826 \begin_layout Standard
36827
36828 \size footnotesize
36829 IC_RESULT = IC_LEFT / IC_RIGHT;
36830 \end_layout
36831
36832 \end_inset
36833 </cell>
36834 </row>
36835 <row topline="true">
36836 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36837 \begin_inset Text
36838
36839 \begin_layout Standard
36840
36841 \size footnotesize
36842 '%'
36843 \end_layout
36844
36845 \end_inset
36846 </cell>
36847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36848 \begin_inset Text
36849
36850 \begin_layout Standard
36851
36852 \size footnotesize
36853 IC_LEFT() IC_RIGHT() IC_RESULT()
36854 \end_layout
36855
36856 \end_inset
36857 </cell>
36858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36859 \begin_inset Text
36860
36861 \begin_layout Standard
36862
36863 \size footnotesize
36864 Modulus
36865 \end_layout
36866
36867 \end_inset
36868 </cell>
36869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36870 \begin_inset Text
36871
36872 \begin_layout Standard
36873
36874 \size footnotesize
36875 IC_RESULT = IC_LEFT % IC_RIGHT;
36876 \end_layout
36877
36878 \end_inset
36879 </cell>
36880 </row>
36881 <row topline="true">
36882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36883 \begin_inset Text
36884
36885 \begin_layout Standard
36886
36887 \size footnotesize
36888 '<'
36889 \end_layout
36890
36891 \end_inset
36892 </cell>
36893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36894 \begin_inset Text
36895
36896 \begin_layout Standard
36897
36898 \size footnotesize
36899 IC_LEFT() IC_RIGHT() IC_RESULT()
36900 \end_layout
36901
36902 \end_inset
36903 </cell>
36904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36905 \begin_inset Text
36906
36907 \begin_layout Standard
36908
36909 \size footnotesize
36910 Less than
36911 \end_layout
36912
36913 \end_inset
36914 </cell>
36915 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36916 \begin_inset Text
36917
36918 \begin_layout Standard
36919
36920 \size footnotesize
36921 IC_RESULT = IC_LEFT < IC_RIGHT;
36922 \end_layout
36923
36924 \end_inset
36925 </cell>
36926 </row>
36927 <row topline="true">
36928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36929 \begin_inset Text
36930
36931 \begin_layout Standard
36932
36933 \size footnotesize
36934 '>'
36935 \end_layout
36936
36937 \end_inset
36938 </cell>
36939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36940 \begin_inset Text
36941
36942 \begin_layout Standard
36943
36944 \size footnotesize
36945 IC_LEFT() IC_RIGHT() IC_RESULT()
36946 \end_layout
36947
36948 \end_inset
36949 </cell>
36950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36951 \begin_inset Text
36952
36953 \begin_layout Standard
36954
36955 \size footnotesize
36956 Greater than 
36957 \end_layout
36958
36959 \end_inset
36960 </cell>
36961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36962 \begin_inset Text
36963
36964 \begin_layout Standard
36965
36966 \size footnotesize
36967 IC_RESULT = IC_LEFT > IC_RIGHT;
36968 \end_layout
36969
36970 \end_inset
36971 </cell>
36972 </row>
36973 <row topline="true">
36974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36975 \begin_inset Text
36976
36977 \begin_layout Standard
36978
36979 \size footnotesize
36980 EQ_OP
36981 \end_layout
36982
36983 \end_inset
36984 </cell>
36985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36986 \begin_inset Text
36987
36988 \begin_layout Standard
36989
36990 \size footnotesize
36991 IC_LEFT() IC_RIGHT() IC_RESULT()
36992 \end_layout
36993
36994 \end_inset
36995 </cell>
36996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36997 \begin_inset Text
36998
36999 \begin_layout Standard
37000
37001 \size footnotesize
37002 Equal to 
37003 \end_layout
37004
37005 \end_inset
37006 </cell>
37007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37008 \begin_inset Text
37009
37010 \begin_layout Standard
37011
37012 \size footnotesize
37013 IC_RESULT = IC_LEFT == IC_RIGHT;
37014 \end_layout
37015
37016 \end_inset
37017 </cell>
37018 </row>
37019 <row topline="true">
37020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37021 \begin_inset Text
37022
37023 \begin_layout Standard
37024
37025 \size footnotesize
37026 AND_OP
37027 \end_layout
37028
37029 \end_inset
37030 </cell>
37031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37032 \begin_inset Text
37033
37034 \begin_layout Standard
37035
37036 \size footnotesize
37037 IC_LEFT() IC_RIGHT() IC_RESULT() 
37038 \end_layout
37039
37040 \end_inset
37041 </cell>
37042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37043 \begin_inset Text
37044
37045 \begin_layout Standard
37046
37047 \size footnotesize
37048 Logical and operation
37049 \end_layout
37050
37051 \end_inset
37052 </cell>
37053 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37054 \begin_inset Text
37055
37056 \begin_layout Standard
37057
37058 \size footnotesize
37059 IC_RESULT = IC_LEFT && IC_RIGHT; 
37060 \end_layout
37061
37062 \end_inset
37063 </cell>
37064 </row>
37065 <row topline="true">
37066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37067 \begin_inset Text
37068
37069 \begin_layout Standard
37070
37071 \size footnotesize
37072 OR_OP
37073 \end_layout
37074
37075 \end_inset
37076 </cell>
37077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37078 \begin_inset Text
37079
37080 \begin_layout Standard
37081
37082 \size footnotesize
37083 IC_LEFT() IC_RIGHT() IC_RESULT() 
37084 \end_layout
37085
37086 \end_inset
37087 </cell>
37088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37089 \begin_inset Text
37090
37091 \begin_layout Standard
37092
37093 \size footnotesize
37094 Logical or operation 
37095 \end_layout
37096
37097 \end_inset
37098 </cell>
37099 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37100 \begin_inset Text
37101
37102 \begin_layout Standard
37103
37104 \size footnotesize
37105 IC_RESULT = IC_LEFT || IC_RIGHT; 
37106 \end_layout
37107
37108 \end_inset
37109 </cell>
37110 </row>
37111 <row topline="true">
37112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37113 \begin_inset Text
37114
37115 \begin_layout Standard
37116
37117 \size footnotesize
37118 '^'
37119 \end_layout
37120
37121 \end_inset
37122 </cell>
37123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37124 \begin_inset Text
37125
37126 \begin_layout Standard
37127
37128 \size footnotesize
37129 IC_LEFT() IC_RIGHT() IC_RESULT() 
37130 \end_layout
37131
37132 \end_inset
37133 </cell>
37134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37135 \begin_inset Text
37136
37137 \begin_layout Standard
37138
37139 \size footnotesize
37140 Exclusive OR
37141 \end_layout
37142
37143 \end_inset
37144 </cell>
37145 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37146 \begin_inset Text
37147
37148 \begin_layout Standard
37149
37150 \size footnotesize
37151 IC_RESULT = IC_LEFT ^ IC_RIGHT;
37152 \end_layout
37153
37154 \end_inset
37155 </cell>
37156 </row>
37157 <row topline="true">
37158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37159 \begin_inset Text
37160
37161 \begin_layout Standard
37162
37163 \size footnotesize
37164 '|'
37165 \end_layout
37166
37167 \end_inset
37168 </cell>
37169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37170 \begin_inset Text
37171
37172 \begin_layout Standard
37173
37174 \size footnotesize
37175 IC_LEFT() IC_RIGHT() IC_RESULT() 
37176 \end_layout
37177
37178 \end_inset
37179 </cell>
37180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37181 \begin_inset Text
37182
37183 \begin_layout Standard
37184
37185 \size footnotesize
37186 Bitwise OR 
37187 \end_layout
37188
37189 \end_inset
37190 </cell>
37191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37192 \begin_inset Text
37193
37194 \begin_layout Standard
37195
37196 \size footnotesize
37197 IC_RESULT = IC_LEFT | IC_RIGHT;
37198 \end_layout
37199
37200 \end_inset
37201 </cell>
37202 </row>
37203 <row topline="true">
37204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37205 \begin_inset Text
37206
37207 \begin_layout Standard
37208
37209 \size footnotesize
37210 BITWISEAND
37211 \end_layout
37212
37213 \end_inset
37214 </cell>
37215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37216 \begin_inset Text
37217
37218 \begin_layout Standard
37219
37220 \size footnotesize
37221 IC_LEFT() IC_RIGHT() IC_RESULT()
37222 \end_layout
37223
37224 \end_inset
37225 </cell>
37226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37227 \begin_inset Text
37228
37229 \begin_layout Standard
37230
37231 \size footnotesize
37232 Bitwise AND 
37233 \end_layout
37234
37235 \end_inset
37236 </cell>
37237 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37238 \begin_inset Text
37239
37240 \begin_layout Standard
37241
37242 \size footnotesize
37243 IC_RESULT = IC_LEFT & IC_RIGHT;
37244 \end_layout
37245
37246 \end_inset
37247 </cell>
37248 </row>
37249 <row topline="true">
37250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37251 \begin_inset Text
37252
37253 \begin_layout Standard
37254
37255 \size footnotesize
37256 LEFT_OP
37257 \end_layout
37258
37259 \end_inset
37260 </cell>
37261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37262 \begin_inset Text
37263
37264 \begin_layout Standard
37265
37266 \size footnotesize
37267 IC_LEFT() IC_RIGHT() IC_RESULT()
37268 \end_layout
37269
37270 \end_inset
37271 </cell>
37272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37273 \begin_inset Text
37274
37275 \begin_layout Standard
37276
37277 \size footnotesize
37278 Left shift 
37279 \end_layout
37280
37281 \end_inset
37282 </cell>
37283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37284 \begin_inset Text
37285
37286 \begin_layout Standard
37287
37288 \size footnotesize
37289 IC_RESULT = IC_LEFT << IC_RIGHT 
37290 \end_layout
37291
37292 \end_inset
37293 </cell>
37294 </row>
37295 <row topline="true">
37296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37297 \begin_inset Text
37298
37299 \begin_layout Standard
37300
37301 \size footnotesize
37302 RIGHT_OP
37303 \end_layout
37304
37305 \end_inset
37306 </cell>
37307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37308 \begin_inset Text
37309
37310 \begin_layout Standard
37311
37312 \size footnotesize
37313 IC_LEFT() IC_RIGHT() IC_RESULT()
37314 \end_layout
37315
37316 \end_inset
37317 </cell>
37318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37319 \begin_inset Text
37320
37321 \begin_layout Standard
37322
37323 \size footnotesize
37324 Right shift
37325 \end_layout
37326
37327 \end_inset
37328 </cell>
37329 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37330 \begin_inset Text
37331
37332 \begin_layout Standard
37333
37334 \size footnotesize
37335 IC_RESULT = IC_LEFT >> IC_RIGHT 
37336 \end_layout
37337
37338 \end_inset
37339 </cell>
37340 </row>
37341 <row topline="true">
37342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37343 \begin_inset Text
37344
37345 \begin_layout Standard
37346
37347 \size footnotesize
37348 GET_VALUE_
37349 \newline
37350 AT_ ADDRESS
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_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 Indirect fetch 
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);
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 POINTER_SET
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_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 Indirect set
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_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 '='
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_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 Assignment
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_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 IFX
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_COND IC_TRUE IC_LABEL
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 Conditional jump.
37511  If true label is present then jump to true label if condition is true else
37512  jump to false label if condition is false 
37513 \end_layout
37514
37515 \end_inset
37516 </cell>
37517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37518 \begin_inset Text
37519
37520 \begin_layout Standard
37521
37522 \size footnotesize
37523 if (IC_COND) goto IC_TRUE; 
37524 \newline
37525 \InsetSpace ~
37526 \InsetSpace ~
37527 Or 
37528 \newline
37529 If (!IC_COND) goto IC_FALSE;
37530 \end_layout
37531
37532 \end_inset
37533 </cell>
37534 </row>
37535 <row topline="true">
37536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37537 \begin_inset Text
37538
37539 \begin_layout Standard
37540
37541 \size footnotesize
37542 ADDRESS_OF
37543 \end_layout
37544
37545 \end_inset
37546 </cell>
37547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37548 \begin_inset Text
37549
37550 \begin_layout Standard
37551
37552 \size footnotesize
37553 IC_LEFT() IC_RESULT()
37554 \end_layout
37555
37556 \end_inset
37557 </cell>
37558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37559 \begin_inset Text
37560
37561 \begin_layout Standard
37562
37563 \size footnotesize
37564 Address of 
37565 \end_layout
37566
37567 \end_inset
37568 </cell>
37569 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37570 \begin_inset Text
37571
37572 \begin_layout Standard
37573
37574 \size footnotesize
37575 IC_RESULT = &IC_LEFT();
37576 \end_layout
37577
37578 \end_inset
37579 </cell>
37580 </row>
37581 <row topline="true">
37582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37583 \begin_inset Text
37584
37585 \begin_layout Standard
37586
37587 \size footnotesize
37588 JUMPTABLE
37589 \end_layout
37590
37591 \end_inset
37592 </cell>
37593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37594 \begin_inset Text
37595
37596 \begin_layout Standard
37597
37598 \size footnotesize
37599 IC_JTCOND IC_JTLABELS
37600 \end_layout
37601
37602 \end_inset
37603 </cell>
37604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37605 \begin_inset Text
37606
37607 \begin_layout Standard
37608
37609 \size footnotesize
37610 Jump to list of labels depending on the value of JTCOND
37611 \end_layout
37612
37613 \end_inset
37614 </cell>
37615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37616 \begin_inset Text
37617
37618 \begin_layout Standard
37619
37620 \size footnotesize
37621 Switch statement
37622 \end_layout
37623
37624 \end_inset
37625 </cell>
37626 </row>
37627 <row topline="true">
37628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37629 \begin_inset Text
37630
37631 \begin_layout Standard
37632
37633 \size footnotesize
37634 CAST
37635 \end_layout
37636
37637 \end_inset
37638 </cell>
37639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37640 \begin_inset Text
37641
37642 \begin_layout Standard
37643
37644 \size footnotesize
37645 IC_RIGHT() IC_LEFT() IC_RESULT()
37646 \end_layout
37647
37648 \end_inset
37649 </cell>
37650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37651 \begin_inset Text
37652
37653 \begin_layout Standard
37654
37655 \size footnotesize
37656 Cast types 
37657 \end_layout
37658
37659 \end_inset
37660 </cell>
37661 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37662 \begin_inset Text
37663
37664 \begin_layout Standard
37665
37666 \size footnotesize
37667 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
37668 \end_layout
37669
37670 \end_inset
37671 </cell>
37672 </row>
37673 <row topline="true">
37674 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37675 \begin_inset Text
37676
37677 \begin_layout Standard
37678
37679 \size footnotesize
37680 SEND
37681 \end_layout
37682
37683 \end_inset
37684 </cell>
37685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37686 \begin_inset Text
37687
37688 \begin_layout Standard
37689
37690 \size footnotesize
37691 IC_LEFT()
37692 \end_layout
37693
37694 \end_inset
37695 </cell>
37696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37697 \begin_inset Text
37698
37699 \begin_layout Standard
37700
37701 \size footnotesize
37702 This is used for passing parameters in registers; 
37703 \newline
37704 move IC_LEFT to the next
37705  available parameter register.
37706 \end_layout
37707
37708 \end_inset
37709 </cell>
37710 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37711 \begin_inset Text
37712
37713 \begin_layout Standard
37714
37715 \size footnotesize
37716 None
37717 \end_layout
37718
37719 \end_inset
37720 </cell>
37721 </row>
37722 <row topline="true">
37723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37724 \begin_inset Text
37725
37726 \begin_layout Standard
37727
37728 \size footnotesize
37729 RECV
37730 \end_layout
37731
37732 \end_inset
37733 </cell>
37734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37735 \begin_inset Text
37736
37737 \begin_layout Standard
37738
37739 \size footnotesize
37740 IC_RESULT()
37741 \end_layout
37742
37743 \end_inset
37744 </cell>
37745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37746 \begin_inset Text
37747
37748 \begin_layout Standard
37749
37750 \size footnotesize
37751 This is used for receiving parameters passed in registers;
37752 \newline
37753 Move the values
37754  in the next parameter register to IC_RESULT 
37755 \end_layout
37756
37757 \end_inset
37758 </cell>
37759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37760 \begin_inset Text
37761
37762 \begin_layout Standard
37763
37764 \size footnotesize
37765 None
37766 \end_layout
37767
37768 \end_inset
37769 </cell>
37770 </row>
37771 <row topline="true" bottomline="true">
37772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37773 \begin_inset Text
37774
37775 \begin_layout Standard
37776
37777 \shape slanted
37778 \size footnotesize
37779 (some more have been added)
37780 \end_layout
37781
37782 \end_inset
37783 </cell>
37784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37785 \begin_inset Text
37786
37787 \begin_layout Standard
37788
37789 \end_layout
37790
37791 \end_inset
37792 </cell>
37793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37794 \begin_inset Text
37795
37796 \begin_layout Standard
37797
37798 \end_layout
37799
37800 \end_inset
37801 </cell>
37802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37803 \begin_inset Text
37804
37805 \begin_layout Standard
37806
37807 \shape slanted
37808 \size footnotesize
37809 see f.e.
37810  
37811 \family typewriter
37812 gen51Code()
37813 \family default
37814  in 
37815 \family typewriter
37816 src/mcs51/gen.c
37817 \end_layout
37818
37819 \end_inset
37820 </cell>
37821 </row>
37822 </lyxtabular>
37823
37824 \end_inset
37825
37826
37827 \end_layout
37828
37829 \begin_layout Standard
37830 \begin_inset Note Note
37831 status collapsed
37832
37833 \begin_layout Standard
37834 In the original article Figure II was announced to be downloadable on 
37835 \shape italic
37836 Circuit Cellar
37837 \shape default
37838 's web site.
37839  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
37840 \end_layout
37841
37842 \end_inset
37843
37844
37845 \end_layout
37846
37847 \begin_layout Paragraph*
37848 ICode Example
37849 \begin_inset LatexCommand \index{iCode}
37850
37851 \end_inset
37852
37853
37854 \end_layout
37855
37856 \begin_layout Standard
37857 This section shows some details of iCode.
37858  The example C code does not do anything useful; it is used as an example
37859  to illustrate the intermediate code generated by the compiler.
37860 \end_layout
37861
37862 \begin_layout Verse
37863
37864 \family typewriter
37865 1.\InsetSpace ~
37866 xdata int * p;
37867 \newline
37868 2.\InsetSpace ~
37869 int gint;
37870 \newline
37871 3.\InsetSpace ~
37872 /* This function does nothing useful.
37873  It is used
37874 \newline
37875 4.\InsetSpace ~
37876 \InsetSpace ~
37877 \InsetSpace ~
37878 \InsetSpace ~
37879 for the purpose of explaining iCode */
37880 \newline
37881 5.\InsetSpace ~
37882 short function (data
37883  int *x)
37884 \newline
37885 6.\InsetSpace ~
37886 {
37887 \newline
37888 7.\InsetSpace ~
37889 \InsetSpace ~
37890 \InsetSpace ~
37891 short i=10; \InsetSpace ~
37892 \InsetSpace ~
37893 /* dead initialization eliminated */
37894 \newline
37895 8.\InsetSpace ~
37896 \InsetSpace ~
37897 \InsetSpace ~
37898 short sum=10;
37899  /* dead initialization eliminated */
37900 \newline
37901 9.\InsetSpace ~
37902 \InsetSpace ~
37903 \InsetSpace ~
37904 short mul;
37905 \newline
37906 10.\InsetSpace ~
37907 \InsetSpace ~
37908 int j ;
37909 \newline
37910 11.\InsetSpace ~
37911 \InsetSpace ~
37912 while (*x) *x++
37913  = *p++; 
37914 \newline
37915 12.\InsetSpace ~
37916 \InsetSpace ~
37917 \InsetSpace ~
37918 \InsetSpace ~
37919 sum = 0 ; 
37920 \newline
37921 13.\InsetSpace ~
37922 \InsetSpace ~
37923 mul = 0;
37924 \newline
37925 14.\InsetSpace ~
37926 \InsetSpace ~
37927 /* compiler detects i,j to be induction
37928  variables */
37929 \newline
37930 15.\InsetSpace ~
37931 \InsetSpace ~
37932 for (i = 0, j = 10 ; i < 10 ; i++, j
37933 \family default
37934 -
37935 \begin_inset ERT
37936 status collapsed
37937
37938 \begin_layout Standard
37939
37940
37941 \backslash
37942 /
37943 \end_layout
37944
37945 \end_inset
37946
37947 -
37948 \family typewriter
37949 ) {
37950 \newline
37951 16.\InsetSpace ~
37952 \InsetSpace ~
37953 \InsetSpace ~
37954 \InsetSpace ~
37955 sum += i;
37956 \newline
37957 17.\InsetSpace ~
37958 \InsetSpace ~
37959 \InsetSpace ~
37960 \InsetSpace ~
37961 mul += i * 3; \InsetSpace ~
37962 \InsetSpace ~
37963 /* this multiplication remains */
37964 \newline
37965 18.\InsetSpace ~
37966 \InsetSpace ~
37967 \InsetSpace ~
37968 \InsetSpace ~
37969 gint +=
37970  j * 3;\InsetSpace ~
37971 \InsetSpace ~
37972 /* this multiplication changed to addition */
37973 \newline
37974 19.\InsetSpace ~
37975 \InsetSpace ~
37976 }
37977 \newline
37978 20.\InsetSpace ~
37979 \InsetSpace ~
37980 return sum+mul;
37981 \newline
37982 21.\InsetSpace ~
37983 }
37984 \end_layout
37985
37986 \begin_layout Standard
37987 In addition to the operands each iCode contains information about the filename
37988  and line it corresponds to in the source file.
37989  The first field in the listing should be interpreted as follows:
37990 \newline
37991
37992 \shape italic
37993 \size footnotesize
37994 Filename(linenumber: iCode Execution sequence number : ICode hash table
37995  key : loop depth of the iCode).
37996 \shape default
37997 \size default
37998
37999 \newline
38000 Then follows the human readable form of the ICode operation.
38001  Each operand of this triplet form can be of three basic types a) compiler
38002  generated temporary b) user defined variable c) a constant value.
38003  Note that local variables and parameters are replaced by compiler generated
38004  temporaries.
38005  Live ranges
38006 \begin_inset LatexCommand \index{Live range analysis}
38007
38008 \end_inset
38009
38010  are computed only for temporaries (i.e.
38011  live ranges are not computed for global variables).
38012  Registers
38013 \begin_inset LatexCommand \index{Register allocation}
38014
38015 \end_inset
38016
38017  are allocated for temporaries only.
38018  Operands are formatted in the following manner:
38019 \newline
38020
38021 \shape italic
38022 \size footnotesize
38023 Operand Name [lr live-from : live-to ] { type information } [ registers
38024  allocated ].
38025 \shape default
38026 \size default
38027
38028 \newline
38029 As mentioned earlier the live ranges are computed in terms of the execution
38030  sequence number of the iCodes, for example 
38031 \newline
38032 the iTemp0 is live from (i.e.
38033  first defined in iCode with execution sequence number 3, and is last used
38034  in the iCode with sequence number 5).
38035  For induction variables such as iTemp21 the live range computation extends
38036  the lifetime from the start to the end of the loop.
38037 \newline
38038 The register allocator
38039  used the live range information to allocate registers, the same registers
38040  may be used for different temporaries if their live ranges do not overlap,
38041  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38042  ranges do not overlap.
38043  In addition the allocator also takes into consideration the type and usage
38044  of a temporary, for example itemp6 is a pointer to near space and is used
38045  as to fetch data from (i.e.
38046  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38047  Some short lived temporaries are allocated to special registers which have
38048  meaning to the code generator e.g.
38049  iTemp13 is allocated to a pseudo register CC which tells the back end that
38050  the temporary is used only for a conditional jump the code generation makes
38051  use of this information to optimize a compare and jump ICode.
38052 \newline
38053 There are several
38054  loop optimizations
38055 \begin_inset LatexCommand \index{Loop optimization}
38056
38057 \end_inset
38058
38059  performed by the compiler.
38060  It can detect induction variables iTemp21(i) and iTemp23(j).
38061  Also note the compiler does selective strength reduction
38062 \begin_inset LatexCommand \index{Strength reduction}
38063
38064 \end_inset
38065
38066 , i.e.
38067  the multiplication of an induction variable in line 18 (gint = j * 3) is
38068  changed to addition, a new temporary iTemp17 is allocated and assigned
38069  a initial value, a constant 3 is then added for each iteration of the loop.
38070  The compiler does not change the multiplication
38071 \begin_inset LatexCommand \index{Multiplication}
38072
38073 \end_inset
38074
38075  in line 17 however since the processor does support an 8 * 8 bit multiplication.
38076 \newline
38077
38078 Note the dead code elimination
38079 \begin_inset LatexCommand \index{Dead-code elimination}
38080
38081 \end_inset
38082
38083  optimization eliminated the dead assignments in line 7 & 8 to I and sum
38084  respectively.
38085 \newline
38086
38087 \end_layout
38088
38089 \begin_layout Standard
38090
38091 \size footnotesize
38092 Sample.c (5:1:0:0) _entry($9) :
38093 \end_layout
38094
38095 \begin_layout Standard
38096
38097 \size footnotesize
38098 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38099 \end_layout
38100
38101 \begin_layout Standard
38102
38103 \size footnotesize
38104 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
38105 \end_layout
38106
38107 \begin_layout Standard
38108
38109 \size footnotesize
38110 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38111 \end_layout
38112
38113 \begin_layout Standard
38114
38115 \size footnotesize
38116 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38117  * int}[r2]
38118 \end_layout
38119
38120 \begin_layout Standard
38121
38122 \size footnotesize
38123 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38124 \end_layout
38125
38126 \begin_layout Standard
38127
38128 \size footnotesize
38129 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38130  int}[r0]]
38131 \end_layout
38132
38133 \begin_layout Standard
38134
38135 \size footnotesize
38136 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38137 \end_layout
38138
38139 \begin_layout Standard
38140
38141 \size footnotesize
38142 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
38143  * int}
38144 \end_layout
38145
38146 \begin_layout Standard
38147
38148 \size footnotesize
38149 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
38150  {short}
38151 \end_layout
38152
38153 \begin_layout Standard
38154
38155 \size footnotesize
38156 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
38157  * int}[DPTR]]
38158 \end_layout
38159
38160 \begin_layout Standard
38161
38162 \size footnotesize
38163 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
38164 }[r2 r3]
38165 \end_layout
38166
38167 \begin_layout Standard
38168
38169 \size footnotesize
38170 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
38171  * int}[r0] + 0x2 {short}
38172 \end_layout
38173
38174 \begin_layout Standard
38175
38176 \size footnotesize
38177 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
38178 \end_layout
38179
38180 \begin_layout Standard
38181
38182 \size footnotesize
38183 Sample.c(11:17:21:0)_whilebreak_0($3) :
38184 \end_layout
38185
38186 \begin_layout Standard
38187
38188 \size footnotesize
38189 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38190 \end_layout
38191
38192 \begin_layout Standard
38193
38194 \size footnotesize
38195 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38196 \end_layout
38197
38198 \begin_layout Standard
38199
38200 \size footnotesize
38201 Sample.c(15:20:54:0)preHeaderLbl1($13) :
38202 \end_layout
38203
38204 \begin_layout Standard
38205
38206 \size footnotesize
38207 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38208 \end_layout
38209
38210 \begin_layout Standard
38211
38212 \size footnotesize
38213 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38214 \end_layout
38215
38216 \begin_layout Standard
38217
38218 \size footnotesize
38219 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38220 \end_layout
38221
38222 \begin_layout Standard
38223
38224 \size footnotesize
38225 Sample.c(15:24:26:1)_forcond_0($4) :
38226 \end_layout
38227
38228 \begin_layout Standard
38229
38230 \size footnotesize
38231 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
38232  < 0xa {short}
38233 \end_layout
38234
38235 \begin_layout Standard
38236
38237 \size footnotesize
38238 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38239 \end_layout
38240
38241 \begin_layout Standard
38242
38243 \size footnotesize
38244 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
38245  + ITemp21 [lr21:38]{short}[r4]
38246 \end_layout
38247
38248 \begin_layout Standard
38249
38250 \size footnotesize
38251 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
38252  * 0x3 {short}
38253 \end_layout
38254
38255 \begin_layout Standard
38256
38257 \size footnotesize
38258 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
38259  + iTemp15 [lr29:30]{short}[r1]
38260 \end_layout
38261
38262 \begin_layout Standard
38263
38264 \size footnotesize
38265 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
38266  r0]- 0x3 {short}
38267 \end_layout
38268
38269 \begin_layout Standard
38270
38271 \size footnotesize
38272 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
38273 int}[r7 r0]
38274 \end_layout
38275
38276 \begin_layout Standard
38277
38278 \size footnotesize
38279 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
38280  + 0x1 {short}
38281 \end_layout
38282
38283 \begin_layout Standard
38284
38285 \size footnotesize
38286 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
38287  r6]- 0x1 {short}
38288 \end_layout
38289
38290 \begin_layout Standard
38291
38292 \size footnotesize
38293 Sample.c(19:38:47:1) goto _forcond_0($4)
38294 \end_layout
38295
38296 \begin_layout Standard
38297
38298 \size footnotesize
38299 Sample.c(19:39:48:0)_forbreak_0($7) :
38300 \end_layout
38301
38302 \begin_layout Standard
38303
38304 \size footnotesize
38305 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
38306  + ITemp11 [lr19:40]{short}[r3]
38307 \end_layout
38308
38309 \begin_layout Standard
38310
38311 \size footnotesize
38312 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
38313 \end_layout
38314
38315 \begin_layout Standard
38316
38317 \size footnotesize
38318 Sample.c(20:42:51:0)_return($8) :
38319 \end_layout
38320
38321 \begin_layout Standard
38322
38323 \size footnotesize
38324 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
38325 \size default
38326
38327 \newline
38328
38329 \newline
38330 Finally the code generated for this function:
38331 \newline
38332
38333 \end_layout
38334
38335 \begin_layout Standard
38336
38337 \size footnotesize
38338 .area DSEG (DATA)
38339 \end_layout
38340
38341 \begin_layout Standard
38342
38343 \size footnotesize
38344 _p::
38345 \end_layout
38346
38347 \begin_layout Standard
38348
38349 \size footnotesize
38350 \InsetSpace ~
38351 \InsetSpace ~
38352 .ds 2
38353 \end_layout
38354
38355 \begin_layout Standard
38356
38357 \size footnotesize
38358 _gint::
38359 \end_layout
38360
38361 \begin_layout Standard
38362
38363 \size footnotesize
38364 \InsetSpace ~
38365 \InsetSpace ~
38366 .ds 2
38367 \end_layout
38368
38369 \begin_layout Standard
38370
38371 \size footnotesize
38372 ; sample.c 5
38373 \end_layout
38374
38375 \begin_layout Standard
38376
38377 \size footnotesize
38378 ; ----------------------------------------------
38379 \end_layout
38380
38381 \begin_layout Standard
38382
38383 \size footnotesize
38384 ; function function
38385 \end_layout
38386
38387 \begin_layout Standard
38388
38389 \size footnotesize
38390 ; ----------------------------------------------
38391 \end_layout
38392
38393 \begin_layout Standard
38394
38395 \size footnotesize
38396 _function:
38397 \end_layout
38398
38399 \begin_layout Standard
38400
38401 \size footnotesize
38402 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
38403 \end_layout
38404
38405 \begin_layout Standard
38406
38407 \size footnotesize
38408 \InsetSpace ~
38409 \InsetSpace ~
38410 mov r2,dpl
38411 \end_layout
38412
38413 \begin_layout Standard
38414
38415 \size footnotesize
38416 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
38417 \end_layout
38418
38419 \begin_layout Standard
38420
38421 \size footnotesize
38422 \InsetSpace ~
38423 \InsetSpace ~
38424 mov ar0,r2
38425 \end_layout
38426
38427 \begin_layout Standard
38428
38429 \size footnotesize
38430 ;_whilecontinue_0($1) :
38431 \end_layout
38432
38433 \begin_layout Standard
38434
38435 \size footnotesize
38436 00101$:
38437 \end_layout
38438
38439 \begin_layout Standard
38440
38441 \size footnotesize
38442 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
38443 \end_layout
38444
38445 \begin_layout Standard
38446
38447 \size footnotesize
38448 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38449 \end_layout
38450
38451 \begin_layout Standard
38452
38453 \size footnotesize
38454 \InsetSpace ~
38455 \InsetSpace ~
38456 mov ar2,@r0
38457 \end_layout
38458
38459 \begin_layout Standard
38460
38461 \size footnotesize
38462 \InsetSpace ~
38463 \InsetSpace ~
38464 inc r0
38465 \end_layout
38466
38467 \begin_layout Standard
38468
38469 \size footnotesize
38470 \InsetSpace ~
38471 \InsetSpace ~
38472 mov ar3,@r0
38473 \end_layout
38474
38475 \begin_layout Standard
38476
38477 \size footnotesize
38478 \InsetSpace ~
38479 \InsetSpace ~
38480 dec r0
38481 \end_layout
38482
38483 \begin_layout Standard
38484
38485 \size footnotesize
38486 \InsetSpace ~
38487 \InsetSpace ~
38488 mov a,r2
38489 \end_layout
38490
38491 \begin_layout Standard
38492
38493 \size footnotesize
38494 \InsetSpace ~
38495 \InsetSpace ~
38496 orl a,r3
38497 \end_layout
38498
38499 \begin_layout Standard
38500
38501 \size footnotesize
38502 \InsetSpace ~
38503 \InsetSpace ~
38504 jz 00103$
38505 \end_layout
38506
38507 \begin_layout Standard
38508
38509 \size footnotesize
38510 00114$:
38511 \end_layout
38512
38513 \begin_layout Standard
38514
38515 \size footnotesize
38516 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
38517 \end_layout
38518
38519 \begin_layout Standard
38520
38521 \size footnotesize
38522 \InsetSpace ~
38523 \InsetSpace ~
38524 mov dpl,_p
38525 \end_layout
38526
38527 \begin_layout Standard
38528
38529 \size footnotesize
38530 \InsetSpace ~
38531 \InsetSpace ~
38532 mov dph,(_p + 1)
38533 \end_layout
38534
38535 \begin_layout Standard
38536
38537 \size footnotesize
38538 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
38539 \end_layout
38540
38541 \begin_layout Standard
38542
38543 \size footnotesize
38544 \InsetSpace ~
38545 \InsetSpace ~
38546 mov a,#0x02
38547 \end_layout
38548
38549 \begin_layout Standard
38550
38551 \size footnotesize
38552 \InsetSpace ~
38553 \InsetSpace ~
38554 add a,_p
38555 \end_layout
38556
38557 \begin_layout Standard
38558
38559 \size footnotesize
38560 \InsetSpace ~
38561 \InsetSpace ~
38562 mov _p,a
38563 \end_layout
38564
38565 \begin_layout Standard
38566
38567 \size footnotesize
38568 \InsetSpace ~
38569 \InsetSpace ~
38570 clr a
38571 \end_layout
38572
38573 \begin_layout Standard
38574
38575 \size footnotesize
38576 \InsetSpace ~
38577 \InsetSpace ~
38578 addc a,(_p + 1)
38579 \end_layout
38580
38581 \begin_layout Standard
38582
38583 \size footnotesize
38584 \InsetSpace ~
38585 \InsetSpace ~
38586 mov (_p + 1),a
38587 \end_layout
38588
38589 \begin_layout Standard
38590
38591 \size footnotesize
38592 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
38593 \end_layout
38594
38595 \begin_layout Standard
38596
38597 \size footnotesize
38598 \InsetSpace ~
38599 \InsetSpace ~
38600 movx a,@dptr
38601 \end_layout
38602
38603 \begin_layout Standard
38604
38605 \size footnotesize
38606 \InsetSpace ~
38607 \InsetSpace ~
38608 mov r2,a
38609 \end_layout
38610
38611 \begin_layout Standard
38612
38613 \size footnotesize
38614 \InsetSpace ~
38615 \InsetSpace ~
38616 inc dptr
38617 \end_layout
38618
38619 \begin_layout Standard
38620
38621 \size footnotesize
38622 \InsetSpace ~
38623 \InsetSpace ~
38624 movx a,@dptr
38625 \end_layout
38626
38627 \begin_layout Standard
38628
38629 \size footnotesize
38630 \InsetSpace ~
38631 \InsetSpace ~
38632 mov r3,a
38633 \end_layout
38634
38635 \begin_layout Standard
38636
38637 \size footnotesize
38638 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
38639 \end_layout
38640
38641 \begin_layout Standard
38642
38643 \size footnotesize
38644 \InsetSpace ~
38645 \InsetSpace ~
38646 mov @r0,ar2
38647 \end_layout
38648
38649 \begin_layout Standard
38650
38651 \size footnotesize
38652 \InsetSpace ~
38653 \InsetSpace ~
38654 inc r0
38655 \end_layout
38656
38657 \begin_layout Standard
38658
38659 \size footnotesize
38660 \InsetSpace ~
38661 \InsetSpace ~
38662 mov @r0,ar3
38663 \end_layout
38664
38665 \begin_layout Standard
38666
38667 \size footnotesize
38668 ; iTemp6 [lr5:16]{_near * int}[r0] = 
38669 \end_layout
38670
38671 \begin_layout Standard
38672
38673 \size footnotesize
38674 ; iTemp6 [lr5:16]{_near * int}[r0] + 
38675 \end_layout
38676
38677 \begin_layout Standard
38678
38679 \size footnotesize
38680 ; 0x2 {short}
38681 \end_layout
38682
38683 \begin_layout Standard
38684
38685 \size footnotesize
38686 \InsetSpace ~
38687 \InsetSpace ~
38688 inc r0
38689 \end_layout
38690
38691 \begin_layout Standard
38692
38693 \size footnotesize
38694 ; goto _whilecontinue_0($1)
38695 \end_layout
38696
38697 \begin_layout Standard
38698
38699 \size footnotesize
38700 \InsetSpace ~
38701 \InsetSpace ~
38702 sjmp 00101$
38703 \end_layout
38704
38705 \begin_layout Standard
38706
38707 \size footnotesize
38708 ; _whilebreak_0($3) :
38709 \end_layout
38710
38711 \begin_layout Standard
38712
38713 \size footnotesize
38714 00103$:
38715 \end_layout
38716
38717 \begin_layout Standard
38718
38719 \size footnotesize
38720 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38721 \end_layout
38722
38723 \begin_layout Standard
38724
38725 \size footnotesize
38726 \InsetSpace ~
38727 \InsetSpace ~
38728 mov r2,#0x00
38729 \end_layout
38730
38731 \begin_layout Standard
38732
38733 \size footnotesize
38734 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38735 \end_layout
38736
38737 \begin_layout Standard
38738
38739 \size footnotesize
38740 \InsetSpace ~
38741 \InsetSpace ~
38742 mov r3,#0x00
38743 \end_layout
38744
38745 \begin_layout Standard
38746
38747 \size footnotesize
38748 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38749 \end_layout
38750
38751 \begin_layout Standard
38752
38753 \size footnotesize
38754 \InsetSpace ~
38755 \InsetSpace ~
38756 mov r4,#0x00
38757 \end_layout
38758
38759 \begin_layout Standard
38760
38761 \size footnotesize
38762 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38763 \end_layout
38764
38765 \begin_layout Standard
38766
38767 \size footnotesize
38768 \InsetSpace ~
38769 \InsetSpace ~
38770 mov r5,#0x0A
38771 \end_layout
38772
38773 \begin_layout Standard
38774
38775 \size footnotesize
38776 \InsetSpace ~
38777 \InsetSpace ~
38778 mov r6,#0x00
38779 \end_layout
38780
38781 \begin_layout Standard
38782
38783 \size footnotesize
38784 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38785 \end_layout
38786
38787 \begin_layout Standard
38788
38789 \size footnotesize
38790 \InsetSpace ~
38791 \InsetSpace ~
38792 mov r7,#0x1E
38793 \end_layout
38794
38795 \begin_layout Standard
38796
38797 \size footnotesize
38798 \InsetSpace ~
38799 \InsetSpace ~
38800 mov r0,#0x00
38801 \end_layout
38802
38803 \begin_layout Standard
38804
38805 \size footnotesize
38806 ; _forcond_0($4) :
38807 \end_layout
38808
38809 \begin_layout Standard
38810
38811 \size footnotesize
38812 00104$:
38813 \end_layout
38814
38815 \begin_layout Standard
38816
38817 \size footnotesize
38818 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
38819 \end_layout
38820
38821 \begin_layout Standard
38822
38823 \size footnotesize
38824 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38825 \end_layout
38826
38827 \begin_layout Standard
38828
38829 \size footnotesize
38830 \InsetSpace ~
38831 \InsetSpace ~
38832 clr c
38833 \end_layout
38834
38835 \begin_layout Standard
38836
38837 \size footnotesize
38838 \InsetSpace ~
38839 \InsetSpace ~
38840 mov a,r4
38841 \end_layout
38842
38843 \begin_layout Standard
38844
38845 \size footnotesize
38846 \InsetSpace ~
38847 \InsetSpace ~
38848 xrl a,#0x80
38849 \end_layout
38850
38851 \begin_layout Standard
38852
38853 \size footnotesize
38854 \InsetSpace ~
38855 \InsetSpace ~
38856 subb a,#0x8a
38857 \end_layout
38858
38859 \begin_layout Standard
38860
38861 \size footnotesize
38862 \InsetSpace ~
38863 \InsetSpace ~
38864 jnc 00107$
38865 \end_layout
38866
38867 \begin_layout Standard
38868
38869 \size footnotesize
38870 00115$:
38871 \end_layout
38872
38873 \begin_layout Standard
38874
38875 \size footnotesize
38876 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
38877 \end_layout
38878
38879 \begin_layout Standard
38880
38881 \size footnotesize
38882 ; iTemp21 [lr21:38]{short}[r4]
38883 \end_layout
38884
38885 \begin_layout Standard
38886
38887 \size footnotesize
38888 \InsetSpace ~
38889 \InsetSpace ~
38890 mov a,r4
38891 \end_layout
38892
38893 \begin_layout Standard
38894
38895 \size footnotesize
38896 \InsetSpace ~
38897 \InsetSpace ~
38898 add a,r2
38899 \end_layout
38900
38901 \begin_layout Standard
38902
38903 \size footnotesize
38904 \InsetSpace ~
38905 \InsetSpace ~
38906 mov r2,a
38907 \end_layout
38908
38909 \begin_layout Standard
38910
38911 \size footnotesize
38912 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
38913 \end_layout
38914
38915 \begin_layout Standard
38916
38917 \size footnotesize
38918 \InsetSpace ~
38919 \InsetSpace ~
38920 mov b,#0x03
38921 \end_layout
38922
38923 \begin_layout Standard
38924
38925 \size footnotesize
38926 \InsetSpace ~
38927 \InsetSpace ~
38928 mov a,r4
38929 \end_layout
38930
38931 \begin_layout Standard
38932
38933 \size footnotesize
38934 \InsetSpace ~
38935 \InsetSpace ~
38936 mul ab
38937 \end_layout
38938
38939 \begin_layout Standard
38940
38941 \size footnotesize
38942 \InsetSpace ~
38943 \InsetSpace ~
38944 mov r1,a
38945 \end_layout
38946
38947 \begin_layout Standard
38948
38949 \size footnotesize
38950 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
38951 \end_layout
38952
38953 \begin_layout Standard
38954
38955 \size footnotesize
38956 ; iTemp15 [lr29:30]{short}[r1]
38957 \end_layout
38958
38959 \begin_layout Standard
38960
38961 \size footnotesize
38962 \InsetSpace ~
38963 \InsetSpace ~
38964 add a,r3
38965 \end_layout
38966
38967 \begin_layout Standard
38968
38969 \size footnotesize
38970 \InsetSpace ~
38971 \InsetSpace ~
38972 mov r3,a
38973 \end_layout
38974
38975 \begin_layout Standard
38976
38977 \size footnotesize
38978 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
38979 \end_layout
38980
38981 \begin_layout Standard
38982
38983 \size footnotesize
38984 \InsetSpace ~
38985 \InsetSpace ~
38986 mov a,r7
38987 \end_layout
38988
38989 \begin_layout Standard
38990
38991 \size footnotesize
38992 \InsetSpace ~
38993 \InsetSpace ~
38994 add a,#0xfd
38995 \end_layout
38996
38997 \begin_layout Standard
38998
38999 \size footnotesize
39000 \InsetSpace ~
39001 \InsetSpace ~
39002 mov r7,a
39003 \end_layout
39004
39005 \begin_layout Standard
39006
39007 \size footnotesize
39008 \InsetSpace ~
39009 \InsetSpace ~
39010 mov a,r0
39011 \end_layout
39012
39013 \begin_layout Standard
39014
39015 \size footnotesize
39016 \InsetSpace ~
39017 \InsetSpace ~
39018 addc a,#0xff
39019 \end_layout
39020
39021 \begin_layout Standard
39022
39023 \size footnotesize
39024 \InsetSpace ~
39025 \InsetSpace ~
39026 mov r0,a
39027 \end_layout
39028
39029 \begin_layout Standard
39030
39031 \size footnotesize
39032 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39033 \end_layout
39034
39035 \begin_layout Standard
39036
39037 \size footnotesize
39038 \InsetSpace ~
39039 \InsetSpace ~
39040 mov a,r7
39041 \end_layout
39042
39043 \begin_layout Standard
39044
39045 \size footnotesize
39046 \InsetSpace ~
39047 \InsetSpace ~
39048 add a,_gint
39049 \end_layout
39050
39051 \begin_layout Standard
39052
39053 \size footnotesize
39054 \InsetSpace ~
39055 \InsetSpace ~
39056 mov _gint,a
39057 \end_layout
39058
39059 \begin_layout Standard
39060
39061 \size footnotesize
39062 \InsetSpace ~
39063 \InsetSpace ~
39064 mov a,r0
39065 \end_layout
39066
39067 \begin_layout Standard
39068
39069 \size footnotesize
39070 \InsetSpace ~
39071 \InsetSpace ~
39072 addc a,(_gint + 1)
39073 \end_layout
39074
39075 \begin_layout Standard
39076
39077 \size footnotesize
39078 \InsetSpace ~
39079 \InsetSpace ~
39080 mov (_gint + 1),a
39081 \end_layout
39082
39083 \begin_layout Standard
39084
39085 \size footnotesize
39086 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39087 \end_layout
39088
39089 \begin_layout Standard
39090
39091 \size footnotesize
39092 \InsetSpace ~
39093 \InsetSpace ~
39094 inc r4
39095 \end_layout
39096
39097 \begin_layout Standard
39098
39099 \size footnotesize
39100 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39101 \end_layout
39102
39103 \begin_layout Standard
39104
39105 \size footnotesize
39106 \InsetSpace ~
39107 \InsetSpace ~
39108 dec r5
39109 \end_layout
39110
39111 \begin_layout Standard
39112
39113 \size footnotesize
39114 \InsetSpace ~
39115 \InsetSpace ~
39116 cjne r5,#0xff,00104$
39117 \end_layout
39118
39119 \begin_layout Standard
39120
39121 \size footnotesize
39122 \InsetSpace ~
39123 \InsetSpace ~
39124 dec r6
39125 \end_layout
39126
39127 \begin_layout Standard
39128
39129 \size footnotesize
39130 ; goto _forcond_0($4)
39131 \end_layout
39132
39133 \begin_layout Standard
39134
39135 \size footnotesize
39136 \InsetSpace ~
39137 \InsetSpace ~
39138 sjmp 00104$
39139 \end_layout
39140
39141 \begin_layout Standard
39142
39143 \size footnotesize
39144 ; _forbreak_0($7) :
39145 \end_layout
39146
39147 \begin_layout Standard
39148
39149 \size footnotesize
39150 00107$:
39151 \end_layout
39152
39153 \begin_layout Standard
39154
39155 \size footnotesize
39156 ; ret iTemp24 [lr40:41]{short}
39157 \end_layout
39158
39159 \begin_layout Standard
39160
39161 \size footnotesize
39162 \InsetSpace ~
39163 \InsetSpace ~
39164 mov a,r3
39165 \end_layout
39166
39167 \begin_layout Standard
39168
39169 \size footnotesize
39170 \InsetSpace ~
39171 \InsetSpace ~
39172 add a,r2
39173 \end_layout
39174
39175 \begin_layout Standard
39176
39177 \size footnotesize
39178 \InsetSpace ~
39179 \InsetSpace ~
39180 mov dpl,a
39181 \end_layout
39182
39183 \begin_layout Standard
39184
39185 \size footnotesize
39186 ; _return($8) :
39187 \end_layout
39188
39189 \begin_layout Standard
39190
39191 \size footnotesize
39192 00108$:
39193 \end_layout
39194
39195 \begin_layout Standard
39196
39197 \size footnotesize
39198 \InsetSpace ~
39199 \InsetSpace ~
39200 ret
39201 \newline
39202
39203 \end_layout
39204
39205 \begin_layout Section
39206 A few words about basic block successors, predecessors and dominators
39207 \end_layout
39208
39209 \begin_layout Standard
39210 Successors are basic blocks
39211 \begin_inset LatexCommand \index{Basic blocks}
39212
39213 \end_inset
39214
39215  that might execute after this basic block.
39216 \newline
39217 Predecessors are basic blocks
39218  that might execute before reaching this basic block.
39219 \newline
39220 Dominators are basic
39221  blocks that WILL execute before reaching this basic block.
39222 \newline
39223
39224 \end_layout
39225
39226 \begin_layout Standard
39227 [basic block 1]
39228 \end_layout
39229
39230 \begin_layout Standard
39231 if (something)
39232 \end_layout
39233
39234 \begin_layout Standard
39235 \InsetSpace ~
39236 \InsetSpace ~
39237 \InsetSpace ~
39238 \InsetSpace ~
39239 [basic block 2]
39240 \end_layout
39241
39242 \begin_layout Standard
39243 else
39244 \end_layout
39245
39246 \begin_layout Standard
39247 \InsetSpace ~
39248 \InsetSpace ~
39249 \InsetSpace ~
39250 \InsetSpace ~
39251 [basic block 3]
39252 \end_layout
39253
39254 \begin_layout Standard
39255 [basic block 4]
39256 \newline
39257
39258 \end_layout
39259
39260 \begin_layout Standard
39261 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
39262 \end_layout
39263
39264 \begin_layout Standard
39265 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
39266 \end_layout
39267
39268 \begin_layout Standard
39269 c) domVect of [BB4] = BB1 ...
39270  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
39271  was executed.
39272 \end_layout
39273
39274 \begin_layout Chapter
39275 Acknowledgments
39276 \end_layout
39277
39278 \begin_layout Standard
39279 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
39280
39281 \end_inset
39282
39283
39284 \newline
39285
39286 \newline
39287
39288 \emph on
39289 Thanks to all the other volunteer developers who have helped with coding,
39290  testing, web-page creation, distribution sets, etc.
39291  You know who you are :-)
39292 \emph default
39293
39294 \newline
39295
39296 \newline
39297
39298 \emph on
39299 Also thanks to Sourceforge 
39300 \begin_inset LatexCommand \url{http://www.sf.net}
39301
39302 \end_inset
39303
39304  which has hosted the project since 1999 and donates significant download
39305  bandwidth and probably more than 
39306 \begin_inset ERT
39307 status collapsed
39308
39309 \begin_layout Standard
39310
39311 $10^{13}$
39312 \end_layout
39313
39314 \end_inset
39315
39316 CPU cycles per day.
39317 \newline
39318  
39319 \begin_inset Note Note
39320 status open
39321
39322 \begin_layout Standard
39323 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
39324  minutes for (configure+make+regression test), and there is (i386, amd64,
39325  alpha, ppc64, (mingw32), sparc, Mac OS X).
39326  
39327 \end_layout
39328
39329 \end_inset
39330
39331
39332 \end_layout
39333
39334 \begin_layout Standard
39335 This document was initially written by Sandeep Dutta
39336 \end_layout
39337
39338 \begin_layout Standard
39339 All product names mentioned herein may be trademarks
39340 \begin_inset LatexCommand \index{Trademarks}
39341
39342 \end_inset
39343
39344  of their respective companies.
39345  
39346 \end_layout
39347
39348 \begin_layout Section*
39349 Alphabetical index
39350 \end_layout
39351
39352 \begin_layout Standard
39353 To avoid confusion, the installation and building options for SDCC itself
39354  (chapter 2) are not part of the index.
39355 \end_layout
39356
39357 \begin_layout Standard
39358 \begin_inset LatexCommand \printindex{}
39359
39360 \end_inset
39361
39362
39363 \end_layout
39364
39365 \end_body
39366 \end_document