* support/scripts/listerr.c: program to create the list of errors and
[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 -no-peep-comments
9634 \begin_inset LatexCommand \index{-\/-no-peep-comments}
9635
9636 \end_inset
9637
9638
9639 \series default
9640  Will not include peep-hole comments in the generated 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 -fverbose-asm
9661 \begin_inset LatexCommand \index{-\/-no-gen-comments}
9662
9663 \end_inset
9664
9665
9666 \series default
9667  Include code generator comments in the generated asm files.
9668 \end_layout
9669
9670 \begin_layout List
9671 \labelwidthstring 00.00.0000
9672
9673 \series bold
9674 -
9675 \begin_inset ERT
9676 status collapsed
9677
9678 \begin_layout Standard
9679
9680
9681 \backslash
9682 /
9683 \end_layout
9684
9685 \end_inset
9686
9687 -i-code-in-asm
9688 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
9689
9690 \end_inset
9691
9692
9693 \series default
9694  Include i-codes in the asm file.
9695  Sounds like noise but is most helpful for debugging the compiler itself.
9696 \end_layout
9697
9698 \begin_layout List
9699 \labelwidthstring 00.00.0000
9700
9701 \series bold
9702 -
9703 \begin_inset ERT
9704 status collapsed
9705
9706 \begin_layout Standard
9707
9708
9709 \backslash
9710 /
9711 \end_layout
9712
9713 \end_inset
9714
9715 -less-pedantic
9716 \begin_inset LatexCommand \index{pedantic}
9717
9718 \end_inset
9719
9720
9721 \begin_inset LatexCommand \index{-\/-less-pedantic}
9722
9723 \end_inset
9724
9725
9726 \series default
9727
9728 \begin_inset LatexCommand \label{lyx:--less-pedantic}
9729
9730 \end_inset
9731
9732  Disable some of the more pedantic warnings
9733 \begin_inset LatexCommand \index{Warnings}
9734
9735 \end_inset
9736
9737 .
9738  For more details, see the less_pedantic pragma 
9739 \begin_inset LatexCommand \vpageref{ite:less_pedantic}
9740
9741 \end_inset
9742
9743 .
9744 \end_layout
9745
9746 \begin_layout List
9747 \labelwidthstring 00.00.0000
9748
9749 \series bold
9750 -
9751 \begin_inset ERT
9752 status collapsed
9753
9754 \begin_layout Standard
9755
9756
9757 \backslash
9758 /
9759 \end_layout
9760
9761 \end_inset
9762
9763 -disable-warning\InsetSpace ~
9764 <nnnn>
9765 \begin_inset LatexCommand \index{-\/-disable-warning}
9766
9767 \end_inset
9768
9769
9770 \series default
9771  Disable specific warning with number <nnnn>.
9772 \end_layout
9773
9774 \begin_layout List
9775 \labelwidthstring 00.00.0000
9776
9777 \series bold
9778 -
9779 \begin_inset ERT
9780 status collapsed
9781
9782 \begin_layout Standard
9783
9784
9785 \backslash
9786 /
9787 \end_layout
9788
9789 \end_inset
9790
9791 -print-search-dirs
9792 \begin_inset LatexCommand \index{-\/-print-search-dirs}
9793
9794 \end_inset
9795
9796
9797 \series default
9798  Display the directories in the compiler's search path
9799 \end_layout
9800
9801 \begin_layout List
9802 \labelwidthstring 00.00.0000
9803
9804 \series bold
9805 -
9806 \begin_inset ERT
9807 status collapsed
9808
9809 \begin_layout Standard
9810
9811
9812 \backslash
9813 /
9814 \end_layout
9815
9816 \end_inset
9817
9818 -vc
9819 \begin_inset LatexCommand \index{-\/-vc}
9820
9821 \end_inset
9822
9823
9824 \series default
9825  Display errors and warnings using MSVC style, so you can use SDCC with
9826  the visual studio IDE
9827 \begin_inset LatexCommand \index{IDE}
9828
9829 \end_inset
9830
9831 .
9832  With SDCC both offering a GCC-like (the default) and a MSVC-like
9833 \begin_inset LatexCommand \index{MSVC output style}
9834
9835 \end_inset
9836
9837  output style, integration into most programming editors should be straightforwa
9838 rd.
9839 \end_layout
9840
9841 \begin_layout List
9842 \labelwidthstring 00.00.0000
9843
9844 \series bold
9845 -
9846 \begin_inset ERT
9847 status collapsed
9848
9849 \begin_layout Standard
9850
9851
9852 \backslash
9853 /
9854 \end_layout
9855
9856 \end_inset
9857
9858 -use-stdout
9859 \begin_inset LatexCommand \index{-\/-use-stdout}
9860
9861 \end_inset
9862
9863
9864 \series default
9865  Send errors and warnings to stdout instead of stderr.
9866 \end_layout
9867
9868 \begin_layout List
9869 \labelwidthstring 00.00.0000
9870
9871 \series bold
9872 -Wa\InsetSpace ~
9873 asmOption[,asmOption]
9874 \series default
9875
9876 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
9877
9878 \end_inset
9879
9880 ...
9881  Pass the asmOption to the assembler
9882 \begin_inset LatexCommand \index{Options assembler}
9883
9884 \end_inset
9885
9886
9887 \begin_inset LatexCommand \index{Assembler options}
9888
9889 \end_inset
9890
9891 .
9892  See file sdcc/as/doc/asxhtm.html for assembler options.cd
9893 \end_layout
9894
9895 \begin_layout List
9896 \labelwidthstring 00.00.0000
9897
9898 \series bold
9899 -
9900 \begin_inset ERT
9901 status collapsed
9902
9903 \begin_layout Standard
9904
9905
9906 \backslash
9907 /
9908 \end_layout
9909
9910 \end_inset
9911
9912 -std-sdcc89
9913 \begin_inset LatexCommand \index{-\/-std-sdcc89}
9914
9915 \end_inset
9916
9917
9918 \series default
9919  Generally follow the C89 standard, but allow SDCC features that conflict
9920  with the standard (default).
9921 \end_layout
9922
9923 \begin_layout List
9924 \labelwidthstring 00.00.0000
9925
9926 \series bold
9927 -
9928 \begin_inset ERT
9929 status collapsed
9930
9931 \begin_layout Standard
9932
9933
9934 \backslash
9935 /
9936 \end_layout
9937
9938 \end_inset
9939
9940 -std-c89
9941 \begin_inset LatexCommand \index{-\/-std-c89}
9942
9943 \end_inset
9944
9945
9946 \series default
9947  Follow the C89 standard and disable SDCC features that conflict with the
9948  standard.
9949 \end_layout
9950
9951 \begin_layout List
9952 \labelwidthstring 00.00.0000
9953
9954 \series bold
9955 -
9956 \begin_inset ERT
9957 status collapsed
9958
9959 \begin_layout Standard
9960
9961
9962 \backslash
9963 /
9964 \end_layout
9965
9966 \end_inset
9967
9968 -std-sdcc99
9969 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9970
9971 \end_inset
9972
9973
9974 \series default
9975  Generally follow the C99 standard, but allow SDCC features that conflict
9976  with the standard (incomplete support).
9977 \end_layout
9978
9979 \begin_layout List
9980 \labelwidthstring 00.00.0000
9981
9982 \series bold
9983 -
9984 \begin_inset ERT
9985 status collapsed
9986
9987 \begin_layout Standard
9988
9989
9990 \backslash
9991 /
9992 \end_layout
9993
9994 \end_inset
9995
9996 -std-c99
9997 \begin_inset LatexCommand \index{-\/-std-sdcc99}
9998
9999 \end_inset
10000
10001
10002 \series default
10003  Follow the C99 standard and disable SDCC features that conflict with the
10004  standard (incomplete support).
10005 \end_layout
10006
10007 \begin_layout List
10008 \labelwidthstring 00.00.0000
10009
10010 \series bold
10011 -
10012 \begin_inset ERT
10013 status collapsed
10014
10015 \begin_layout Standard
10016
10017
10018 \backslash
10019 /
10020 \end_layout
10021
10022 \end_inset
10023
10024 -codeseg
10025 \series default
10026
10027 \begin_inset LatexCommand \index{-\/-codeseg <Value>}
10028
10029 \end_inset
10030
10031 \InsetSpace ~
10032 <Name> The name to be used for the code
10033 \begin_inset LatexCommand \index{code}
10034
10035 \end_inset
10036
10037  segment, default CSEG.
10038  This is useful if you need to tell the compiler to put the code in a special
10039  segment so you can later on tell the linker to put this segment in a special
10040  place in memory.
10041  Can be used for instance when using bank switching to put the code in a
10042  bank.
10043 \end_layout
10044
10045 \begin_layout List
10046 \labelwidthstring 00.00.0000
10047
10048 \series bold
10049 -
10050 \begin_inset ERT
10051 status collapsed
10052
10053 \begin_layout Standard
10054
10055
10056 \backslash
10057 /
10058 \end_layout
10059
10060 \end_inset
10061
10062 -constseg
10063 \series default
10064
10065 \begin_inset LatexCommand \index{-\/-constseg <Value>}
10066
10067 \end_inset
10068
10069 \InsetSpace ~
10070 <Name> The name to be used for the const
10071 \begin_inset LatexCommand \index{code}
10072
10073 \end_inset
10074
10075  segment, default CONST.
10076  This is useful if you need to tell the compiler to put the const data in
10077  a special segment so you can later on tell the linker to put this segment
10078  in a special place in memory.
10079  Can be used for instance when using bank switching to put the const data
10080  in a bank.
10081 \end_layout
10082
10083 \begin_layout List
10084 \labelwidthstring 00.00.0000
10085
10086 \series bold
10087 -
10088 \begin_inset ERT
10089 status collapsed
10090
10091 \begin_layout Standard
10092
10093
10094 \backslash
10095 /
10096 \end_layout
10097
10098 \end_inset
10099
10100 -fdollars-in-identifiers
10101 \begin_inset LatexCommand \index{-\/-fdollars-in-identifiers}
10102
10103 \end_inset
10104
10105
10106 \series default
10107  Permit '$' as an identifier character.
10108 \end_layout
10109
10110 \begin_layout List
10111 \labelwidthstring 00.00.0000
10112
10113 \series bold
10114 -
10115 \begin_inset ERT
10116 status collapsed
10117
10118 \begin_layout Standard
10119
10120
10121 \backslash
10122 /
10123 \end_layout
10124
10125 \end_inset
10126
10127 -more-pedantic
10128 \series default
10129
10130 \begin_inset LatexCommand \index{-\/-more-pedantic}
10131
10132 \end_inset
10133
10134
10135 \begin_inset LatexCommand \index{pedantic}
10136
10137 \end_inset
10138
10139  Actually this is 
10140 \series bold
10141 \emph on
10142 not
10143 \series default
10144 \emph default
10145  a SDCC compiler option but if you want 
10146 \emph on
10147 more
10148 \emph default
10149  warnings you can use a separate tool dedicated to syntax checking like
10150  splint
10151 \begin_inset LatexCommand \label{lyx:more-pedantic-SPLINT}
10152
10153 \end_inset
10154
10155
10156 \begin_inset LatexCommand \index{lint (syntax checking tool)}
10157
10158 \end_inset
10159
10160  
10161 \begin_inset LatexCommand \url{http://www.splint.org}
10162
10163 \end_inset
10164
10165 .
10166  To make your source files parseable by splint you will have to include
10167  
10168 \family sans
10169 lint.h
10170 \family default
10171
10172 \begin_inset LatexCommand \index{splint (syntax checking tool)}
10173
10174 \end_inset
10175
10176  in your source file and add brackets around extended keywords (like 
10177 \family sans
10178
10179 \begin_inset Quotes sld
10180 \end_inset
10181
10182 __at\InsetSpace ~
10183
10184 \series bold
10185 (
10186 \series default
10187 0xab
10188 \series bold
10189 )
10190 \series default
10191
10192 \begin_inset Quotes srd
10193 \end_inset
10194
10195
10196 \family default
10197  and 
10198 \family sans
10199
10200 \begin_inset Quotes sld
10201 \end_inset
10202
10203 __interrupt\InsetSpace ~
10204 (2)
10205 \begin_inset Quotes srd
10206 \end_inset
10207
10208
10209 \family default
10210 ).
10211  
10212 \newline
10213 Splint has an excellent on line manual at 
10214 \begin_inset LatexCommand \url{http://www.splint.org/manual/}
10215
10216 \end_inset
10217
10218  and it's capabilities go beyond pure syntax checking.
10219  You'll need to tell splint the location of SDCC's include files so a typical
10220  command line could look like this: 
10221 \newline
10222
10223 \family sans
10224 splint\InsetSpace ~
10225 -I\InsetSpace ~
10226 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
10227 \InsetSpace ~
10228 myprogram.c
10229 \end_layout
10230
10231 \begin_layout List
10232 \labelwidthstring 00.00.0000
10233
10234 \series bold
10235 -
10236 \begin_inset ERT
10237 status collapsed
10238
10239 \begin_layout Standard
10240
10241
10242 \backslash
10243 /
10244 \end_layout
10245
10246 \end_inset
10247
10248 -short-is-8bits
10249 \series default
10250
10251 \begin_inset LatexCommand \index{-\/-short-is-8bits}
10252
10253 \end_inset
10254
10255
10256 \begin_inset LatexCommand \label{lyx:--short-is-8bits}
10257
10258 \end_inset
10259
10260  Treat short as 8-bit (for backward compatibility with older versions of
10261  compiler - see section 
10262 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
10263
10264 \end_inset
10265
10266 )
10267 \end_layout
10268
10269 \begin_layout Standard
10270 \begin_inset VSpace bigskip
10271 \end_inset
10272
10273
10274 \end_layout
10275
10276 \begin_layout Subsection
10277 Intermediate Dump Options
10278 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
10279
10280 \end_inset
10281
10282
10283 \begin_inset LatexCommand \index{Options intermediate dump}
10284
10285 \end_inset
10286
10287
10288 \begin_inset LatexCommand \index{Intermediate dump options}
10289
10290 \end_inset
10291
10292
10293 \end_layout
10294
10295 \begin_layout Standard
10296 The following options are provided for the purpose of retargetting and debugging
10297  the compiler.
10298  They provide a means to dump the intermediate code (iCode
10299 \begin_inset LatexCommand \index{iCode}
10300
10301 \end_inset
10302
10303 ) generated by the compiler in human readable form at various stages of
10304  the compilation process.
10305  More on iCodes see chapter 
10306 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
10307
10308 \end_inset
10309
10310  
10311 \begin_inset Quotes srd
10312 \end_inset
10313
10314 The anatomy of the compiler
10315 \begin_inset Quotes srd
10316 \end_inset
10317
10318 .
10319 \end_layout
10320
10321 \begin_layout List
10322 \labelwidthstring 00.00.0000
10323
10324 \series bold
10325 -
10326 \begin_inset ERT
10327 status collapsed
10328
10329 \begin_layout Standard
10330
10331
10332 \backslash
10333 /
10334 \end_layout
10335
10336 \end_inset
10337
10338 -dumpraw
10339 \begin_inset LatexCommand \index{-\/-dumpraw}
10340
10341 \end_inset
10342
10343
10344 \series default
10345  This option will cause the compiler to dump the intermediate code into
10346  a file of named 
10347 \emph on
10348 <source filename>.dumpraw
10349 \emph default
10350  just after the intermediate code has been generated for a function, i.e.
10351  before any optimizations are done.
10352  The basic blocks
10353 \begin_inset LatexCommand \index{Basic blocks}
10354
10355 \end_inset
10356
10357  at this stage ordered in the depth first number, so they may not be in
10358  sequence of execution.
10359 \end_layout
10360
10361 \begin_layout List
10362 \labelwidthstring 00.00.0000
10363
10364 \series bold
10365 -
10366 \begin_inset ERT
10367 status collapsed
10368
10369 \begin_layout Standard
10370
10371
10372 \backslash
10373 /
10374 \end_layout
10375
10376 \end_inset
10377
10378 -dumpgcse
10379 \begin_inset LatexCommand \index{-\/-dumpgcse}
10380
10381 \end_inset
10382
10383
10384 \series default
10385  Will create a dump of iCode's, after global subexpression elimination
10386 \begin_inset LatexCommand \index{Global subexpression elimination}
10387
10388 \end_inset
10389
10390 , into a file named 
10391 \emph on
10392 <source filename>.dumpgcse.
10393 \end_layout
10394
10395 \begin_layout List
10396 \labelwidthstring 00.00.0000
10397
10398 \series bold
10399 -
10400 \begin_inset ERT
10401 status collapsed
10402
10403 \begin_layout Standard
10404
10405
10406 \backslash
10407 /
10408 \end_layout
10409
10410 \end_inset
10411
10412 -dumpdeadcode
10413 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
10414
10415 \end_inset
10416
10417
10418 \series default
10419  Will create a dump of iCode's, after deadcode elimination
10420 \begin_inset LatexCommand \index{Dead-code elimination}
10421
10422 \end_inset
10423
10424 , into a file named 
10425 \emph on
10426 <source filename>.dumpdeadcode.
10427 \end_layout
10428
10429 \begin_layout List
10430 \labelwidthstring 00.00.0000
10431
10432 \series bold
10433 -
10434 \begin_inset ERT
10435 status collapsed
10436
10437 \begin_layout Standard
10438
10439
10440 \backslash
10441 /
10442 \end_layout
10443
10444 \end_inset
10445
10446 -dumploop
10447 \begin_inset LatexCommand \index{-\/-dumploop}
10448
10449 \end_inset
10450
10451
10452 \series default
10453 \size large
10454  
10455 \size default
10456 Will create a dump of iCode's, after loop optimizations
10457 \begin_inset LatexCommand \index{Loop optimization}
10458
10459 \end_inset
10460
10461 , into a file named 
10462 \emph on
10463 <source filename>.dumploop.
10464 \end_layout
10465
10466 \begin_layout List
10467 \labelwidthstring 00.00.0000
10468
10469 \series bold
10470 -
10471 \begin_inset ERT
10472 status collapsed
10473
10474 \begin_layout Standard
10475
10476
10477 \backslash
10478 /
10479 \end_layout
10480
10481 \end_inset
10482
10483 -dumprange
10484 \begin_inset LatexCommand \index{-\/-dumprange}
10485
10486 \end_inset
10487
10488
10489 \series default
10490 \size large
10491  
10492 \size default
10493 Will create a dump of iCode's, after live range analysis
10494 \begin_inset LatexCommand \index{Live range analysis}
10495
10496 \end_inset
10497
10498 , into a file named 
10499 \emph on
10500 <source filename>.dumprange.
10501 \end_layout
10502
10503 \begin_layout List
10504 \labelwidthstring 00.00.0000
10505
10506 \series bold
10507 -
10508 \begin_inset ERT
10509 status collapsed
10510
10511 \begin_layout Standard
10512
10513
10514 \backslash
10515 /
10516 \end_layout
10517
10518 \end_inset
10519
10520 -dumlrange
10521 \begin_inset LatexCommand \index{-\/-dumlrange}
10522
10523 \end_inset
10524
10525
10526 \series default
10527  Will dump the life ranges
10528 \begin_inset LatexCommand \index{Live range analysis}
10529
10530 \end_inset
10531
10532  for all symbols.
10533 \end_layout
10534
10535 \begin_layout List
10536 \labelwidthstring 00.00.0000
10537
10538 \series bold
10539 -
10540 \begin_inset ERT
10541 status collapsed
10542
10543 \begin_layout Standard
10544
10545
10546 \backslash
10547 /
10548 \end_layout
10549
10550 \end_inset
10551
10552 -dumpregassign
10553 \begin_inset LatexCommand \index{-\/-dumpregassign}
10554
10555 \end_inset
10556
10557
10558 \bar under
10559  
10560 \series default
10561 \bar default
10562 Will create a dump of iCode's, after register assignment
10563 \begin_inset LatexCommand \index{Register assignment}
10564
10565 \end_inset
10566
10567 , into a file named 
10568 \emph on
10569 <source filename>.dumprassgn.
10570 \end_layout
10571
10572 \begin_layout List
10573 \labelwidthstring 00.00.0000
10574
10575 \series bold
10576 -
10577 \begin_inset ERT
10578 status collapsed
10579
10580 \begin_layout Standard
10581
10582
10583 \backslash
10584 /
10585 \end_layout
10586
10587 \end_inset
10588
10589 -dumplrange
10590 \begin_inset LatexCommand \index{-\/-dumplrange}
10591
10592 \end_inset
10593
10594
10595 \series default
10596  Will create a dump of the live ranges of iTemp's
10597 \end_layout
10598
10599 \begin_layout List
10600 \labelwidthstring 00.00.0000
10601
10602 \series bold
10603 -
10604 \begin_inset ERT
10605 status collapsed
10606
10607 \begin_layout Standard
10608
10609
10610 \backslash
10611 /
10612 \end_layout
10613
10614 \end_inset
10615
10616 -dumpall
10617 \begin_inset LatexCommand \index{-\/-dumpall}
10618
10619 \end_inset
10620
10621
10622 \size large
10623 \bar under
10624  
10625 \series default
10626 \size default
10627 \bar default
10628 Will cause all the above mentioned dumps to be created.
10629 \end_layout
10630
10631 \begin_layout Standard
10632 \begin_inset VSpace bigskip
10633 \end_inset
10634
10635
10636 \end_layout
10637
10638 \begin_layout Subsection
10639 Redirecting output on Windows Shells
10640 \end_layout
10641
10642 \begin_layout Standard
10643 By default SDCC writes it's error messages to 
10644 \begin_inset Quotes sld
10645 \end_inset
10646
10647 standard error
10648 \begin_inset Quotes srd
10649 \end_inset
10650
10651 .
10652  To force all messages to 
10653 \begin_inset Quotes sld
10654 \end_inset
10655
10656 standard output
10657 \begin_inset Quotes srd
10658 \end_inset
10659
10660  use 
10661 \series bold
10662 -
10663 \series default
10664 \emph on
10665
10666 \begin_inset ERT
10667 status collapsed
10668
10669 \begin_layout Standard
10670
10671
10672 \backslash
10673 /
10674 \end_layout
10675
10676 \end_inset
10677
10678
10679 \series bold
10680 \emph default
10681 -
10682 \series default
10683 use-stdout
10684 \begin_inset LatexCommand \index{-\/-use-stdout}
10685
10686 \end_inset
10687
10688 .
10689  Additionally, if you happen to have visual studio installed in your windows
10690  machine, you can use it to compile your sources using a custom build and
10691  the SDCC -
10692 \emph on
10693
10694 \begin_inset ERT
10695 status collapsed
10696
10697 \begin_layout Standard
10698
10699
10700 \backslash
10701 /
10702 \end_layout
10703
10704 \end_inset
10705
10706
10707 \emph default
10708 -vc
10709 \begin_inset LatexCommand \index{-\/-vc}
10710
10711 \end_inset
10712
10713  option.
10714  Something like this should work:
10715 \newline
10716
10717 \newline
10718
10719 \series bold
10720 c:
10721 \backslash
10722 sdcc
10723 \backslash
10724 bin
10725 \backslash
10726 sdcc.exe -
10727 \series default
10728 \emph on
10729
10730 \begin_inset ERT
10731 status collapsed
10732
10733 \begin_layout Standard
10734
10735
10736 \backslash
10737 /
10738 \end_layout
10739
10740 \end_inset
10741
10742
10743 \series bold
10744 \emph default
10745 -vc -
10746 \series default
10747 \emph on
10748
10749 \begin_inset ERT
10750 status collapsed
10751
10752 \begin_layout Standard
10753
10754
10755 \backslash
10756 /
10757 \end_layout
10758
10759 \end_inset
10760
10761
10762 \series bold
10763 \emph default
10764 -model-large -c $(InputPath)
10765 \series default
10766
10767 \begin_inset VSpace bigskip
10768 \end_inset
10769
10770
10771 \end_layout
10772
10773 \begin_layout Section
10774 Environment variables
10775 \begin_inset LatexCommand \index{Environment variables}
10776
10777 \end_inset
10778
10779
10780 \end_layout
10781
10782 \begin_layout Standard
10783 SDCC recognizes the following environment variables:
10784 \end_layout
10785
10786 \begin_layout List
10787 \labelwidthstring 00.00.0000
10788
10789 \series bold
10790 SDCC_LEAVE_SIGNALS
10791 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
10792
10793 \end_inset
10794
10795
10796 \series default
10797  SDCC installs a signal handler
10798 \begin_inset LatexCommand \index{signal handler}
10799
10800 \end_inset
10801
10802  to be able to delete temporary files after an user break (^C) or an exception.
10803  If this environment variable is set, SDCC won't install the signal handler
10804  in order to be able to debug SDCC.
10805 \end_layout
10806
10807 \begin_layout List
10808 \labelwidthstring 00.00.0000
10809
10810 \series bold
10811 TMP,\InsetSpace ~
10812 TEMP,\InsetSpace ~
10813 TMPDIR
10814 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
10815
10816 \end_inset
10817
10818
10819 \series default
10820  Path, where temporary files will be created.
10821  The order of the variables is the search order.
10822  In a standard *nix environment these variables are not set, and there's
10823  no need to set them.
10824  On Windows it's recommended to set one of them.
10825 \end_layout
10826
10827 \begin_layout List
10828 \labelwidthstring 00.00.0000
10829
10830 \series bold
10831 SDCC_HOME
10832 \begin_inset LatexCommand \index{SDCC\_HOME}
10833
10834 \end_inset
10835
10836
10837 \series default
10838  Path, see section 
10839 \begin_inset LatexCommand \ref{sub:Install-paths}
10840
10841 \end_inset
10842
10843 \InsetSpace ~
10844
10845 \begin_inset Quotes sld
10846 \end_inset
10847
10848  Install Paths
10849 \begin_inset Quotes srd
10850 \end_inset
10851
10852 .
10853 \end_layout
10854
10855 \begin_layout List
10856 \labelwidthstring 00.00.0000
10857
10858 \series bold
10859 SDCC_INCLUDE
10860 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
10861
10862 \end_inset
10863
10864
10865 \series default
10866  Path, see section 
10867 \begin_inset LatexCommand \ref{sub:Search-Paths}
10868
10869 \end_inset
10870
10871 \InsetSpace ~
10872
10873 \begin_inset Quotes sld
10874 \end_inset
10875
10876 Search Paths
10877 \begin_inset Quotes srd
10878 \end_inset
10879
10880 .
10881 \end_layout
10882
10883 \begin_layout List
10884 \labelwidthstring 00.00.0000
10885
10886 \series bold
10887 SDCC_LIB
10888 \begin_inset LatexCommand \index{SDCC\_LIB}
10889
10890 \end_inset
10891
10892
10893 \series default
10894  Path, see section 
10895 \begin_inset LatexCommand \ref{sub:Search-Paths}
10896
10897 \end_inset
10898
10899 \InsetSpace ~
10900
10901 \begin_inset Quotes sld
10902 \end_inset
10903
10904 Search Paths
10905 \begin_inset Quotes srd
10906 \end_inset
10907
10908 ..
10909 \end_layout
10910
10911 \begin_layout Standard
10912 There are some more environment variables recognized by SDCC, but these
10913  are solely used for debugging purposes.
10914  They can change or disappear very quickly, and will never be documented.
10915 \begin_inset VSpace bigskip
10916 \end_inset
10917
10918
10919 \end_layout
10920
10921 \begin_layout Section
10922 Storage Class Language Extensions
10923 \end_layout
10924
10925 \begin_layout Subsection
10926 MCS51/DS390 Storage Class
10927 \begin_inset LatexCommand \index{Storage class}
10928
10929 \end_inset
10930
10931  Language Extensions
10932 \end_layout
10933
10934 \begin_layout Standard
10935 In addition to the ANSI storage classes SDCC allows the following MCS51
10936  specific storage classes:
10937 \end_layout
10938
10939 \begin_layout Subsubsection
10940 data
10941 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
10942
10943 \end_inset
10944
10945
10946 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
10947
10948 \end_inset
10949
10950  / near
10951 \begin_inset LatexCommand \index{near (storage class)}
10952
10953 \end_inset
10954
10955
10956 \begin_inset LatexCommand \index{\_\_near (storage class)}
10957
10958 \end_inset
10959
10960
10961 \end_layout
10962
10963 \begin_layout Standard
10964 This is the 
10965 \series bold
10966 default
10967 \series default
10968  storage class for the Small Memory model (
10969 \emph on
10970 data
10971 \emph default
10972  and 
10973 \emph on
10974 near
10975 \emph default
10976  or the more ANSI-C compliant forms 
10977 \emph on
10978 __data
10979 \emph default
10980  and 
10981 \emph on
10982 __near
10983 \emph default
10984  can be used synonymously).
10985  Variables declared with this storage class will be allocated in the directly
10986  addressable portion of the internal RAM of a 8051, e.g.:
10987 \end_layout
10988
10989 \begin_layout Verse
10990
10991 \family typewriter
10992 __data unsigned char test_data;
10993 \end_layout
10994
10995 \begin_layout Standard
10996 Writing 0x01 to this variable generates the assembly code:
10997 \end_layout
10998
10999 \begin_layout Verse
11000
11001 \family typewriter
11002 75*00 01\InsetSpace ~
11003 \InsetSpace ~
11004 \InsetSpace ~
11005 mov\InsetSpace ~
11006 \InsetSpace ~
11007 _test_data,#0x01
11008 \end_layout
11009
11010 \begin_layout Subsubsection
11011 xdata
11012 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11013
11014 \end_inset
11015
11016
11017 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11018
11019 \end_inset
11020
11021  / far
11022 \begin_inset LatexCommand \index{far (storage class)}
11023
11024 \end_inset
11025
11026
11027 \begin_inset LatexCommand \index{\_\_far (storage class)}
11028
11029 \end_inset
11030
11031
11032 \end_layout
11033
11034 \begin_layout Standard
11035 Variables declared with this storage class will be placed in the external
11036  RAM.
11037  This is the 
11038 \series bold
11039 default
11040 \series default
11041  storage class for the Large Memory model, e.g.:
11042 \end_layout
11043
11044 \begin_layout Verse
11045
11046 \family typewriter
11047 __xdata unsigned char test_xdata;
11048 \end_layout
11049
11050 \begin_layout Standard
11051 Writing 0x01 to this variable generates the assembly code:
11052 \end_layout
11053
11054 \begin_layout Verse
11055
11056 \family typewriter
11057 90s00r00\InsetSpace ~
11058 \InsetSpace ~
11059 \InsetSpace ~
11060 mov\InsetSpace ~
11061 \InsetSpace ~
11062 dptr,#_test_xdata 
11063 \newline
11064 74\InsetSpace ~
11065 01\InsetSpace ~
11066 \InsetSpace ~
11067 \InsetSpace ~
11068 \InsetSpace ~
11069 \InsetSpace ~
11070 \InsetSpace ~
11071 mov\InsetSpace ~
11072 \InsetSpace ~
11073 a,#0x01 
11074 \newline
11075 F0\InsetSpace ~
11076 \InsetSpace ~
11077 \InsetSpace ~
11078 \InsetSpace ~
11079 \InsetSpace ~
11080 \InsetSpace ~
11081 \InsetSpace ~
11082 \InsetSpace ~
11083 \InsetSpace ~
11084 movx\InsetSpace ~
11085 @dptr,a 
11086 \end_layout
11087
11088 \begin_layout Subsubsection
11089 idata
11090 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11091
11092 \end_inset
11093
11094
11095 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11096
11097 \end_inset
11098
11099
11100 \end_layout
11101
11102 \begin_layout Standard
11103 Variables declared with this storage class will be allocated into the indirectly
11104  addressable portion of the internal ram of a 8051, e.g.:
11105 \end_layout
11106
11107 \begin_layout Verse
11108
11109 \family typewriter
11110 __idata unsigned char test_idata;
11111 \end_layout
11112
11113 \begin_layout Standard
11114 Writing 0x01 to this variable generates the assembly code:
11115 \end_layout
11116
11117 \begin_layout Verse
11118
11119 \family typewriter
11120 78r00\InsetSpace ~
11121 \InsetSpace ~
11122 \InsetSpace ~
11123 \InsetSpace ~
11124 \InsetSpace ~
11125 \InsetSpace ~
11126 \InsetSpace ~
11127 mov\InsetSpace ~
11128 \InsetSpace ~
11129 r0,#_test_idata
11130 \newline
11131 76\InsetSpace ~
11132 01\InsetSpace ~
11133 \InsetSpace ~
11134 \InsetSpace ~
11135 \InsetSpace ~
11136 \InsetSpace ~
11137 \InsetSpace ~
11138 \InsetSpace ~
11139 mov\InsetSpace ~
11140 \InsetSpace ~
11141 @r0,#0x01
11142 \end_layout
11143
11144 \begin_layout Standard
11145 Please note, the first 128 byte of idata physically access the same RAM
11146  as the data memory.
11147  The original 8051 had 128 byte idata memory, nowadays most devices have
11148  256 byte idata memory.
11149  The stack
11150 \begin_inset LatexCommand \index{stack}
11151
11152 \end_inset
11153
11154  is located in idata memory.
11155 \end_layout
11156
11157 \begin_layout Subsubsection
11158 pdata
11159 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
11160
11161 \end_inset
11162
11163
11164 \begin_inset LatexCommand \index{\_\_pdata (mcs51, ds390 storage class)}
11165
11166 \end_inset
11167
11168
11169 \end_layout
11170
11171 \begin_layout Standard
11172 Paged xdata access is just as straightforward as using the other addressing
11173  modes of a 8051.
11174  It is typically located at the start of xdata and has a maximum size of
11175  256 bytes.
11176  The following example writes 0x01 to the pdata variable.
11177  Please note, pdata access physically accesses xdata memory.
11178  The high byte of the address is determined by port P2 
11179 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
11180
11181 \end_inset
11182
11183 (or in case of some 8051 variants by a separate Special Function Register,
11184  see section 
11185 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11186
11187 \end_inset
11188
11189 ).
11190  This is the 
11191 \series bold
11192 default
11193 \series default
11194  storage class for the Medium Memory model, e.g.:
11195 \end_layout
11196
11197 \begin_layout Verse
11198
11199 \family typewriter
11200 __pdata unsigned char test_pdata;
11201 \end_layout
11202
11203 \begin_layout Standard
11204 Writing 0x01 to this variable generates the assembly code:
11205 \end_layout
11206
11207 \begin_layout Verse
11208
11209 \family typewriter
11210 78r00\InsetSpace ~
11211 \InsetSpace ~
11212 \InsetSpace ~
11213 \InsetSpace ~
11214 \InsetSpace ~
11215 \InsetSpace ~
11216 mov r0,#_test_pdata
11217 \newline
11218 74 01\InsetSpace ~
11219 \InsetSpace ~
11220 \InsetSpace ~
11221 \InsetSpace ~
11222 \InsetSpace ~
11223 \InsetSpace ~
11224 mov a,#0x01 
11225 \newline
11226 F2\InsetSpace ~
11227 \InsetSpace ~
11228 \InsetSpace ~
11229 \InsetSpace ~
11230 \InsetSpace ~
11231 \InsetSpace ~
11232 \InsetSpace ~
11233 \InsetSpace ~
11234 \InsetSpace ~
11235 movx @r0,a
11236 \end_layout
11237
11238 \begin_layout Standard
11239 If the -
11240 \begin_inset ERT
11241 status collapsed
11242
11243 \begin_layout Standard
11244
11245
11246 \backslash
11247 /
11248 \end_layout
11249
11250 \end_inset
11251
11252 -xstack
11253 \begin_inset LatexCommand \index{-\/-xstack}
11254
11255 \end_inset
11256
11257  option is used the pdata memory area is followed by the xstack memory area
11258  and the sum of their sizes is limited to 256 bytes.
11259 \end_layout
11260
11261 \begin_layout Subsubsection
11262 code
11263 \begin_inset LatexCommand \index{code}
11264
11265 \end_inset
11266
11267
11268 \begin_inset LatexCommand \index{\_\_code}
11269
11270 \end_inset
11271
11272
11273 \end_layout
11274
11275 \begin_layout Standard
11276 'Variables' declared with this storage class will be placed in the code
11277  memory:
11278 \end_layout
11279
11280 \begin_layout Verse
11281
11282 \family typewriter
11283 __code unsigned char test_code;
11284 \end_layout
11285
11286 \begin_layout Standard
11287 Read access to this variable generates the assembly code:
11288 \end_layout
11289
11290 \begin_layout Verse
11291
11292 \family typewriter
11293 90s00r6F\InsetSpace ~
11294 \InsetSpace ~
11295 \InsetSpace ~
11296 mov dptr,#_test_code
11297 \newline
11298 E4\InsetSpace ~
11299 \InsetSpace ~
11300 \InsetSpace ~
11301 \InsetSpace ~
11302 \InsetSpace ~
11303 \InsetSpace ~
11304 \InsetSpace ~
11305 \InsetSpace ~
11306 \InsetSpace ~
11307 clr a
11308 \newline
11309 93\InsetSpace ~
11310 \InsetSpace ~
11311 \InsetSpace ~
11312 \InsetSpace ~
11313 \InsetSpace ~
11314 \InsetSpace ~
11315 \InsetSpace ~
11316 \InsetSpace ~
11317 \InsetSpace ~
11318 movc a,@a+dptr 
11319 \end_layout
11320
11321 \begin_layout Standard
11322
11323 \family typewriter
11324 char
11325 \family default
11326  indexed arrays of characters in code memory can be accessed efficiently:
11327 \end_layout
11328
11329 \begin_layout Verse
11330
11331 \family typewriter
11332 __code char test_array[] = {'c','h','e','a','p'}; 
11333 \end_layout
11334
11335 \begin_layout Standard
11336 Read access to this array using an 8-bit unsigned index generates the assembly
11337  code:
11338 \end_layout
11339
11340 \begin_layout Verse
11341
11342 \family typewriter
11343 E5*00\InsetSpace ~
11344 \InsetSpace ~
11345 \InsetSpace ~
11346 \InsetSpace ~
11347 \InsetSpace ~
11348 \InsetSpace ~
11349 mov a,_index 
11350 \end_layout
11351
11352 \begin_layout Verse
11353
11354 \family typewriter
11355 90s00r41\InsetSpace ~
11356 \InsetSpace ~
11357 \InsetSpace ~
11358 mov dptr,#_test_array
11359 \end_layout
11360
11361 \begin_layout Verse
11362
11363 \family typewriter
11364 93\InsetSpace ~
11365 \InsetSpace ~
11366 \InsetSpace ~
11367 \InsetSpace ~
11368 \InsetSpace ~
11369 \InsetSpace ~
11370 \InsetSpace ~
11371 \InsetSpace ~
11372 \InsetSpace ~
11373 movc a,@a+dptr 
11374 \end_layout
11375
11376 \begin_layout Subsubsection
11377 bit
11378 \begin_inset LatexCommand \index{bit}
11379
11380 \end_inset
11381
11382
11383 \begin_inset LatexCommand \index{\_\_bit}
11384
11385 \end_inset
11386
11387
11388 \end_layout
11389
11390 \begin_layout Standard
11391 This is a data-type and a storage class specifier.
11392  When a variable is declared as a bit, it is allocated into the bit addressable
11393  memory of 8051, e.g.:
11394 \end_layout
11395
11396 \begin_layout Verse
11397
11398 \family typewriter
11399 __bit test_bit;
11400 \end_layout
11401
11402 \begin_layout Standard
11403 Writing 1 to this variable generates the assembly code:
11404 \end_layout
11405
11406 \begin_layout Verse
11407
11408 \family typewriter
11409 D2*00\InsetSpace ~
11410 \InsetSpace ~
11411 \InsetSpace ~
11412 \InsetSpace ~
11413 \InsetSpace ~
11414 \InsetSpace ~
11415 \InsetSpace ~
11416 setb\InsetSpace ~
11417 _test_bit
11418 \end_layout
11419
11420 \begin_layout Standard
11421 The bit addressable memory consists of 128 bits which are located from 0x20
11422  to 0x2f in data memory.
11423  
11424 \newline
11425 Apart from this 8051 specific storage class most architectures support
11426  ANSI-C bitfields
11427 \begin_inset LatexCommand \index{bitfields}
11428
11429 \end_inset
11430
11431
11432 \begin_inset Foot
11433 status open
11434
11435 \begin_layout Standard
11436 Not really meant as examples, but nevertheless showing what bitfields are
11437  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
11438 \end_layout
11439
11440 \end_inset
11441
11442 .
11443  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
11444  signed modifier are implemented as unsigned.
11445 \end_layout
11446
11447 \begin_layout Subsubsection
11448 sfr
11449 \begin_inset LatexCommand \index{sfr}
11450
11451 \end_inset
11452
11453
11454 \begin_inset LatexCommand \index{\_\_sfr}
11455
11456 \end_inset
11457
11458  / sfr16
11459 \begin_inset LatexCommand \index{sfr16}
11460
11461 \end_inset
11462
11463
11464 \begin_inset LatexCommand \index{\_\_sfr16}
11465
11466 \end_inset
11467
11468  / sfr32
11469 \begin_inset LatexCommand \index{sfr32}
11470
11471 \end_inset
11472
11473
11474 \begin_inset LatexCommand \index{\_\_sfr32}
11475
11476 \end_inset
11477
11478  / sbit
11479 \begin_inset LatexCommand \index{\_\_sbit}
11480
11481 \end_inset
11482
11483
11484 \begin_inset LatexCommand \index{sbit}
11485
11486 \end_inset
11487
11488
11489 \end_layout
11490
11491 \begin_layout Standard
11492 Like the bit keyword, 
11493 \emph on
11494 sfr / sfr16 / sfr32 / sbit 
11495 \emph default
11496 signify both a data-type and storage class, they are used to describe the
11497  
11498 \emph on
11499 s
11500 \emph default
11501 pecial 
11502 \emph on
11503 f
11504 \emph default
11505 unction 
11506 \emph on
11507 r
11508 \emph default
11509 egisters and 
11510 \emph on
11511 s
11512 \emph default
11513 pecial 
11514 \emph on
11515 bit
11516 \emph default
11517  variables of a 8051, eg:
11518 \end_layout
11519
11520 \begin_layout Verse
11521
11522 \family typewriter
11523 __sfr __at
11524 \begin_inset LatexCommand \index{at}
11525
11526 \end_inset
11527
11528
11529 \begin_inset LatexCommand \index{\_\_at}
11530
11531 \end_inset
11532
11533  (0x80) P0;\InsetSpace ~
11534  /* special function register P0 at location 0x80 */
11535 \newline
11536
11537 \newline
11538 /* 16 bit
11539  special function register combination for timer 0
11540 \newline
11541 \InsetSpace ~
11542 \InsetSpace ~
11543  with the high byte at
11544  location 0x8C and the low byte at location 0x8A */
11545 \newline
11546 __sfr16 __at (0x8C8A)
11547  TMR0;
11548 \newline
11549
11550 \newline
11551 __sbit __at
11552 \begin_inset LatexCommand \index{at}
11553
11554 \end_inset
11555
11556
11557 \begin_inset LatexCommand \index{\_\_at}
11558
11559 \end_inset
11560
11561  (0xd7) CY;\InsetSpace ~
11562  /* CY (Carry Flag
11563 \begin_inset LatexCommand \index{Flags}
11564
11565 \end_inset
11566
11567
11568 \begin_inset LatexCommand \index{Carry flag}
11569
11570 \end_inset
11571
11572 ) */
11573 \end_layout
11574
11575 \begin_layout Standard
11576 Special function registers which are located on an address dividable by
11577  8 are bit-addressable, an
11578 \emph on
11579  sbit
11580 \emph default
11581  addresses a specific bit within these sfr.
11582 \newline
11583 16 Bit and 32 bit special function
11584  register combinations which require a certain access order are better not
11585  declared using 
11586 \emph on
11587 sfr16
11588 \emph default
11589  or 
11590 \emph on
11591 sfr32.
11592
11593 \emph default
11594  Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
11595  this is not guaranteed.
11596 \newline
11597
11598 \end_layout
11599
11600 \begin_layout Standard
11601 Please note, if you use a header file which was written for another compiler
11602  then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
11603  likely be 
11604 \emph on
11605 not 
11606 \emph default
11607 compatible.
11608  Specifically the syntax 
11609 \family typewriter
11610 \InsetSpace ~
11611 sfr P0 = 0x80;\InsetSpace ~
11612
11613 \family default
11614  is compiled 
11615 \emph on
11616 without warning
11617 \emph default
11618  by SDCC to an assignment of 0x80 to a variable called P0 
11619 \family typewriter
11620
11621 \begin_inset Marginal
11622 status collapsed
11623
11624 \begin_layout Standard
11625
11626 \series bold
11627 \InsetSpace ~
11628 !
11629 \end_layout
11630
11631 \end_inset
11632
11633 .
11634  
11635 \family default
11636 Nevertheless it is possible to write header files
11637 \begin_inset LatexCommand \index{Header files}
11638
11639 \end_inset
11640
11641
11642 \begin_inset LatexCommand \index{Include files}
11643
11644 \end_inset
11645
11646  which can be shared among different compilers (see section 
11647 \begin_inset LatexCommand \ref{sec:Porting-code-to-other-compilers}
11648
11649 \end_inset
11650
11651 ).
11652  
11653 \end_layout
11654
11655 \begin_layout Subsubsection
11656 Pointers
11657 \begin_inset LatexCommand \index{Pointer}
11658
11659 \end_inset
11660
11661  to MCS51/DS390 specific memory spaces
11662 \end_layout
11663
11664 \begin_layout Standard
11665 SDCC allows (via language extensions) pointers to explicitly point to any
11666  of the memory spaces
11667 \begin_inset LatexCommand \index{Memory model}
11668
11669 \end_inset
11670
11671  of the 8051.
11672  In addition to the explicit pointers, the compiler uses (by default) generic
11673  pointers which can be used to point to any of the memory spaces.
11674 \newline
11675
11676 \newline
11677 Pointer
11678  declaration examples:
11679 \end_layout
11680
11681 \begin_layout Verse
11682
11683 \family typewriter
11684 /* pointer physically in internal ram pointing to object in external ram
11685  */ 
11686 \newline
11687 __xdata unsigned char * __data p;
11688 \newline
11689
11690 \newline
11691 /* pointer physically in external ram
11692  pointing to object in internal ram */ 
11693 \newline
11694 __data unsigned char * __xdata p;
11695 \newline
11696
11697 \newline
11698 /*
11699  pointer physically in code rom pointing to data in xdata space */ 
11700 \newline
11701 __xdata
11702  unsigned char * __code p;
11703 \newline
11704
11705 \newline
11706 /* pointer physically in code space pointing to
11707  data in code space */ 
11708 \newline
11709 __code unsigned char * __code p;
11710 \newline
11711
11712 \newline
11713 /* generic pointer
11714  physically located in xdata space */
11715 \newline
11716 unsigned char * __xdata p;
11717 \newline
11718
11719 \newline
11720 /* generic
11721  pointer physically located in default memory space */
11722 \newline
11723 unsigned char * p;
11724 \newline
11725
11726 \newline
11727 /*
11728  the following is a function pointer
11729 \begin_inset LatexCommand \index{function pointer}
11730
11731 \end_inset
11732
11733  physically located in data space */
11734 \newline
11735 char (* __data fp)(void);
11736 \end_layout
11737
11738 \begin_layout Standard
11739 Well you get the idea.
11740  
11741 \newline
11742
11743 \newline
11744 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
11745 \emph on
11746 generic
11747 \emph default
11748  pointers.
11749  
11750 \size small
11751
11752 \newline
11753
11754 \newline
11755
11756 \size default
11757 The highest order byte of the 
11758 \emph on
11759 generic
11760 \emph default
11761  pointers contains the data space information.
11762  Assembler support routines are called whenever data is stored or retrieved
11763  using 
11764 \emph on
11765 generic
11766 \emph default
11767  pointers.
11768  These are useful for developing reusable library
11769 \begin_inset LatexCommand \index{Libraries}
11770
11771 \end_inset
11772
11773  routines.
11774  Explicitly specifying the pointer
11775 \begin_inset LatexCommand \index{pointer}
11776
11777 \end_inset
11778
11779  type will generate the most efficient code.
11780 \end_layout
11781
11782 \begin_layout Subsubsection
11783 Notes on MCS51 memory
11784 \begin_inset LatexCommand \index{MCS51 memory}
11785
11786 \end_inset
11787
11788  layout
11789 \end_layout
11790
11791 \begin_layout Standard
11792 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
11793  RAM memory which is structured as follows:
11794 \newline
11795
11796 \newline
11797 - Bytes 00-1F - 32 bytes to hold
11798  up to 4 banks of the registers R0 to R7, 
11799 \newline
11800 - Bytes 20-2F - 16 bytes to hold
11801  128 bit
11802 \begin_inset LatexCommand \index{bit}
11803
11804 \end_inset
11805
11806  variables and, 
11807 \newline
11808 - Bytes 30-7F - 80 bytes for general purpose use.
11809 \newline
11810
11811 \end_layout
11812
11813 \begin_layout Standard
11814 Additionally some members of the MCS51 family may have up to 128 bytes of
11815  additional, indirectly addressable, internal RAM memory (
11816 \emph on
11817 idata
11818 \emph default
11819
11820 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
11821
11822 \end_inset
11823
11824
11825 \begin_inset LatexCommand \index{\_\_idata (mcs51, ds390 storage class)}
11826
11827 \end_inset
11828
11829 ).
11830  Furthermore, some chips may have some built in external memory (
11831 \emph on
11832 xdata
11833 \emph default
11834
11835 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
11836
11837 \end_inset
11838
11839
11840 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
11841
11842 \end_inset
11843
11844 ) which should not be confused with the internal, directly addressable RAM
11845  memory (
11846 \emph on
11847 data
11848 \emph default
11849
11850 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
11851
11852 \end_inset
11853
11854
11855 \begin_inset LatexCommand \index{\_\_data (mcs51, ds390 storage class)}
11856
11857 \end_inset
11858
11859 ).
11860  Sometimes this built in 
11861 \emph on
11862 xdata
11863 \emph default
11864  memory has to be activated before using it (you can probably find this
11865  information on the datasheet of the microcontroller your are using, see
11866  also section 
11867 \begin_inset LatexCommand \ref{sub:Startup-Code}
11868
11869 \end_inset
11870
11871 \InsetSpace ~
11872 Startup-Code).
11873 \end_layout
11874
11875 \begin_layout Standard
11876 Normally SDCC will only use the first bank
11877 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
11878
11879 \end_inset
11880
11881  of registers (register bank 0), but it is possible to specify that other
11882  banks of registers (keyword 
11883 \emph on
11884 using
11885 \emph default
11886  
11887 \emph on
11888
11889 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
11890
11891 \end_inset
11892
11893
11894 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
11895
11896 \end_inset
11897
11898
11899 \emph default
11900 ) should be used for example in interrupt
11901 \begin_inset LatexCommand \index{interrupt}
11902
11903 \end_inset
11904
11905
11906 \begin_inset LatexCommand \index{\_\_interrupt}
11907
11908 \end_inset
11909
11910  routines.
11911  By default, the compiler will place the stack after the last byte of allocated
11912  memory for variables.
11913  For example, if the first 2 banks of registers are used, and only four
11914  bytes are used for 
11915 \emph on
11916 data
11917 \emph default
11918  variables, it will position the base of the internal stack at address 20
11919  (0x14).
11920  This implies that as the stack
11921 \begin_inset LatexCommand \index{stack}
11922
11923 \end_inset
11924
11925  grows, it will use up the remaining register banks, and the 16 bytes used
11926  by the 128 bit variables, and 80 bytes for general purpose use.
11927  If any bit variables are used, the data variables will be placed in unused
11928  register banks and after the byte holding the last bit variable.
11929  For example, if register banks 0 and 1 are used, and there are 9 bit variables
11930  (two bytes used), 
11931 \emph on
11932 data
11933 \emph default
11934  variables will be placed starting from address 0x10 to 0x20 and continue
11935  at address 0x22.
11936  You can also use -
11937 \begin_inset ERT
11938 status collapsed
11939
11940 \begin_layout Standard
11941
11942
11943 \backslash
11944 /
11945 \end_layout
11946
11947 \end_inset
11948
11949 -data-loc
11950 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
11951
11952 \end_inset
11953
11954  to specify the start address of the 
11955 \emph on
11956 data
11957 \emph default
11958  and -
11959 \begin_inset ERT
11960 status collapsed
11961
11962 \begin_layout Standard
11963
11964
11965 \backslash
11966 /
11967 \end_layout
11968
11969 \end_inset
11970
11971 -iram-size
11972 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
11973
11974 \end_inset
11975
11976  to specify the size of the total internal RAM (
11977 \emph on
11978 data
11979 \emph default
11980 +
11981 \emph on
11982 idata
11983 \emph default
11984 ).
11985  
11986 \newline
11987
11988 \end_layout
11989
11990 \begin_layout Standard
11991 By default the 8051 linker will place the stack after the last byte of (i)data
11992  variables.
11993  Option -
11994 \begin_inset ERT
11995 status collapsed
11996
11997 \begin_layout Standard
11998
11999
12000 \backslash
12001 /
12002 \end_layout
12003
12004 \end_inset
12005
12006 -stack-loc
12007 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
12008
12009 \end_inset
12010
12011  allows you to specify the start of the stack, i.e.
12012  you could start it after any data in the general purpose area.
12013  If your microcontroller has additional indirectly addressable internal
12014  RAM (
12015 \emph on
12016 idata
12017 \emph default
12018 ) you can place the stack on it.
12019  You may also need to use -
12020 \begin_inset ERT
12021 status collapsed
12022
12023 \begin_layout Standard
12024
12025
12026 \backslash
12027 /
12028 \end_layout
12029
12030 \end_inset
12031
12032 -xdata-loc
12033 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
12034
12035 \end_inset
12036
12037  to set the start address of the external RAM (
12038 \emph on
12039 xdata
12040 \emph default
12041 ) and -
12042 \begin_inset ERT
12043 status collapsed
12044
12045 \begin_layout Standard
12046
12047
12048 \backslash
12049 /
12050 \end_layout
12051
12052 \end_inset
12053
12054 -xram-size
12055 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
12056
12057 \end_inset
12058
12059  to specify its size.
12060  Same goes for the code memory, using -
12061 \begin_inset ERT
12062 status collapsed
12063
12064 \begin_layout Standard
12065
12066
12067 \backslash
12068 /
12069 \end_layout
12070
12071 \end_inset
12072
12073 -code-loc
12074 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
12075
12076 \end_inset
12077
12078  and -
12079 \begin_inset ERT
12080 status collapsed
12081
12082 \begin_layout Standard
12083
12084
12085 \backslash
12086 /
12087 \end_layout
12088
12089 \end_inset
12090
12091 -code-size
12092 \begin_inset LatexCommand \index{-\/-code-size <Value>}
12093
12094 \end_inset
12095
12096 .
12097  If in doubt, don't specify any options and see if the resulting memory
12098  layout is appropriate, then you can adjust it.
12099 \end_layout
12100
12101 \begin_layout Standard
12102 The linker generates two files with memory allocation information.
12103  The first, with extension .map
12104 \begin_inset LatexCommand \index{<file>.map}
12105
12106 \end_inset
12107
12108  shows all the variables and segments.
12109  The second with extension .mem
12110 \begin_inset LatexCommand \index{<file>.mem}
12111
12112 \end_inset
12113
12114  shows the final memory layout.
12115  The linker will complain either if memory segments overlap, there is not
12116  enough memory, or there is not enough space for stack.
12117  If you get any linking warnings and/or errors related to stack or segments
12118  allocation, take a look at either the .map or .mem files to find out what
12119  the problem is.
12120  The .mem file may even suggest a solution to the problem.
12121 \begin_inset VSpace bigskip
12122 \end_inset
12123
12124
12125 \end_layout
12126
12127 \begin_layout Subsection
12128 Z80/Z180 Storage Class
12129 \begin_inset LatexCommand \index{Z80!Storage class}
12130
12131 \end_inset
12132
12133  Language Extensions
12134 \end_layout
12135
12136 \begin_layout Subsubsection
12137 sfr
12138 \begin_inset LatexCommand \index{sfr}
12139
12140 \end_inset
12141
12142
12143 \begin_inset LatexCommand \index{\_\_sfr}
12144
12145 \end_inset
12146
12147  (in/out to 8-bit addresses)
12148 \end_layout
12149
12150 \begin_layout Standard
12151 The Z80
12152 \begin_inset LatexCommand \index{Z80}
12153
12154 \end_inset
12155
12156  family has separate address spaces for memory and 
12157 \emph on
12158 i
12159 \emph default
12160 nput/
12161 \emph on
12162 o
12163 \emph default
12164 utput memory.
12165  I/O memory
12166 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
12167
12168 \end_inset
12169
12170
12171 \begin_inset LatexCommand \index{Z80!I/O memory}
12172
12173 \end_inset
12174
12175
12176 \begin_inset LatexCommand \index{Z180!I/O memory}
12177
12178 \end_inset
12179
12180  is accessed with special instructions, e.g.:
12181 \end_layout
12182
12183 \begin_layout Verse
12184
12185 \family typewriter
12186 sfr at 0x78 IoPort;\InsetSpace ~
12187 \InsetSpace ~
12188 /* define a var in I/O space at 78h called IoPort */
12189  
12190 \end_layout
12191
12192 \begin_layout Standard
12193 Writing 0x01 to this variable generates the assembly code:
12194 \end_layout
12195
12196 \begin_layout Verse
12197
12198 \family typewriter
12199 3E 01\InsetSpace ~
12200 \InsetSpace ~
12201 \InsetSpace ~
12202 \InsetSpace ~
12203 \InsetSpace ~
12204 \InsetSpace ~
12205 ld a,#0x01
12206 \newline
12207 D3 78\InsetSpace ~
12208 \InsetSpace ~
12209 \InsetSpace ~
12210 \InsetSpace ~
12211 \InsetSpace ~
12212 \InsetSpace ~
12213 out (_IoPort),a 
12214 \end_layout
12215
12216 \begin_layout Subsubsection
12217 banked sfr
12218 \begin_inset LatexCommand \index{sfr}
12219
12220 \end_inset
12221
12222
12223 \begin_inset LatexCommand \index{\_\_sfr}
12224
12225 \end_inset
12226
12227  (in/out to 16-bit addresses)
12228 \end_layout
12229
12230 \begin_layout Standard
12231 The keyword 
12232 \emph on
12233 banked
12234 \emph default
12235  is used to support 16 bit addresses in I/O memory e.g.:
12236 \end_layout
12237
12238 \begin_layout Verse
12239
12240 \family typewriter
12241 sfr banked at
12242 \begin_inset LatexCommand \index{at}
12243
12244 \end_inset
12245
12246
12247 \begin_inset LatexCommand \index{\_\_at}
12248
12249 \end_inset
12250
12251  0x123 IoPort; 
12252 \end_layout
12253
12254 \begin_layout Standard
12255 Writing 0x01 to this variable generates the assembly code:
12256 \end_layout
12257
12258 \begin_layout Verse
12259
12260 \family typewriter
12261 01 23 01\InsetSpace ~
12262 \InsetSpace ~
12263 \InsetSpace ~
12264 ld bc,#_IoPort
12265 \newline
12266 3E 01\InsetSpace ~
12267 \InsetSpace ~
12268 \InsetSpace ~
12269 \InsetSpace ~
12270 \InsetSpace ~
12271 \InsetSpace ~
12272 ld a,#0x01 
12273 \newline
12274 ED 79\InsetSpace ~
12275 \InsetSpace ~
12276 \InsetSpace ~
12277 \InsetSpace ~
12278 \InsetSpace ~
12279 \InsetSpace ~
12280 out (c),a 
12281 \end_layout
12282
12283 \begin_layout Subsubsection
12284 sfr
12285 \begin_inset LatexCommand \index{sfr}
12286
12287 \end_inset
12288
12289
12290 \begin_inset LatexCommand \index{\_\_sfr}
12291
12292 \end_inset
12293
12294  (in0/out0 to 8 bit addresses on Z180
12295 \begin_inset LatexCommand \index{Z180}
12296
12297 \end_inset
12298
12299 /HD64180
12300 \begin_inset LatexCommand \index{HD64180 (see Z180)}
12301
12302 \end_inset
12303
12304 )
12305 \end_layout
12306
12307 \begin_layout Standard
12308 The compiler option -
12309 \begin_inset ERT
12310 status collapsed
12311
12312 \begin_layout Standard
12313
12314
12315 \backslash
12316 /
12317 \end_layout
12318
12319 \end_inset
12320
12321 -portmode
12322 \begin_inset LatexCommand \index{Z180!Options!-\/-portmode}
12323
12324 \end_inset
12325
12326 =180 (80) and a compiler #pragma\InsetSpace ~
12327 portmode
12328 \begin_inset LatexCommand \index{Z180!Pragmas!\#pragma portmode}
12329
12330 \end_inset
12331
12332  z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
12333 ns 
12334 \family typewriter
12335 in0/out0
12336 \family default
12337  instead of 
12338 \family typewriter
12339 in/out
12340 \family default
12341 .
12342  If you include the file z180.h this will be set automatically.
12343 \begin_inset VSpace bigskip
12344 \end_inset
12345
12346
12347 \end_layout
12348
12349 \begin_layout Subsection
12350 HC08 Storage Class
12351 \begin_inset LatexCommand \index{HC08!Storage class}
12352
12353 \end_inset
12354
12355  Language Extensions
12356 \end_layout
12357
12358 \begin_layout Subsubsection
12359 data
12360 \begin_inset LatexCommand \index{data (hc08 storage class)}
12361
12362 \end_inset
12363
12364
12365 \begin_inset LatexCommand \index{\_\_data (hc08 storage class)}
12366
12367 \end_inset
12368
12369  
12370 \end_layout
12371
12372 \begin_layout Standard
12373 The data storage class declares a variable that resides in the first 256
12374  bytes of memory (the direct page).
12375  The HC08
12376 \begin_inset LatexCommand \index{HC08}
12377
12378 \end_inset
12379
12380  is most efficient at accessing variables (especially pointers) stored here.
12381 \end_layout
12382
12383 \begin_layout Subsubsection
12384 xdata
12385 \begin_inset LatexCommand \index{xdata (hc08 storage class)}
12386
12387 \end_inset
12388
12389
12390 \begin_inset LatexCommand \index{\_\_xdata (hc08 storage class)}
12391
12392 \end_inset
12393
12394  
12395 \end_layout
12396
12397 \begin_layout Standard
12398 The xdata storage class declares a variable that can reside anywhere in
12399  memory.
12400  This is the default if no storage class is specified.
12401  
12402 \begin_inset VSpace bigskip
12403 \end_inset
12404
12405
12406 \end_layout
12407
12408 \begin_layout Section
12409 Absolute Addressing
12410 \begin_inset LatexCommand \index{Absolute addressing}
12411
12412 \end_inset
12413
12414
12415 \end_layout
12416
12417 \begin_layout Standard
12418 Data items can be assigned an absolute address with the 
12419 \emph on
12420 at
12421 \begin_inset LatexCommand \index{at}
12422
12423 \end_inset
12424
12425
12426 \begin_inset LatexCommand \index{\_\_at}
12427
12428 \end_inset
12429
12430  <address>
12431 \emph default
12432  keyword, in addition to a storage class, e.g.:
12433 \end_layout
12434
12435 \begin_layout Verse
12436
12437 \family typewriter
12438 xdata
12439 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12440
12441 \end_inset
12442
12443
12444 \begin_inset LatexCommand \index{\_\_xdata (mcs51, ds390 storage class)}
12445
12446 \end_inset
12447
12448  at
12449 \begin_inset LatexCommand \index{at}
12450
12451 \end_inset
12452
12453
12454 \begin_inset LatexCommand \index{\_\_at}
12455
12456 \end_inset
12457
12458  0x7ffe unsigned int chksum;
12459 \end_layout
12460
12461 \begin_layout Standard
12462 or, better conforming to ISO/IEC 9899 C:
12463 \end_layout
12464
12465 \begin_layout Verse
12466
12467 \family typewriter
12468 __xdata __at (0x7ffe) unsigned int chksum;
12469 \end_layout
12470
12471 \begin_layout Standard
12472 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
12473  of the external ram.
12474  The compiler does 
12475 \emph on
12476 not
12477 \emph default
12478  reserve any space for variables declared in this way
12479 \begin_inset Marginal
12480 status collapsed
12481
12482 \begin_layout Standard
12483
12484 \series bold
12485 \InsetSpace ~
12486 !
12487 \end_layout
12488
12489 \end_inset
12490
12491  (they are implemented with an equate in the assembler).
12492  Thus it is left to the programmer to make sure there are no overlaps with
12493  other variables that are declared without the absolute address.
12494  The assembler listing file (.lst
12495 \begin_inset LatexCommand \index{<file>.lst}
12496
12497 \end_inset
12498
12499 ) and the linker output files (.rst
12500 \begin_inset LatexCommand \index{<file>.rst}
12501
12502 \end_inset
12503
12504 ) and (.map
12505 \begin_inset LatexCommand \index{<file>.map}
12506
12507 \end_inset
12508
12509 ) are good places to look for such overlaps.
12510  Variables with an absolute address are 
12511 \emph on
12512 not
12513 \begin_inset Marginal
12514 status collapsed
12515
12516 \begin_layout Standard
12517
12518 \series bold
12519 \InsetSpace ~
12520 !
12521 \end_layout
12522
12523 \end_inset
12524
12525
12526 \emph default
12527  initialized
12528 \begin_inset LatexCommand \index{Variable initialization}
12529
12530 \end_inset
12531
12532 .
12533 \end_layout
12534
12535 \begin_layout Standard
12536 In case of memory mapped I/O devices the keyword 
12537 \emph on
12538 volatile
12539 \emph default
12540  has to be used to tell the compiler that accesses might not be removed:
12541 \end_layout
12542
12543 \begin_layout Verse
12544
12545 \family typewriter
12546 volatile
12547 \begin_inset LatexCommand \index{volatile}
12548
12549 \end_inset
12550
12551  __xdata
12552 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
12553
12554 \end_inset
12555
12556  __at
12557 \begin_inset LatexCommand \index{at}
12558
12559 \end_inset
12560
12561  (0x8000) unsigned char PORTA_8255;
12562 \end_layout
12563
12564 \begin_layout Standard
12565 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
12566 r) array
12567 \family typewriter
12568 \size footnotesize
12569
12570 \begin_inset LatexCommand \index{Aligned array}
12571
12572 \end_inset
12573
12574
12575 \family default
12576 \size default
12577  starts at a block (256 byte) boundary
12578 \begin_inset LatexCommand \index{block boundary}
12579
12580 \end_inset
12581
12582  (section 
12583 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
12584
12585 \end_inset
12586
12587  has an example).
12588 \newline
12589 Absolute addresses can be specified for variables in all
12590  storage classes, e.g.:
12591 \end_layout
12592
12593 \begin_layout Verse
12594
12595 \family typewriter
12596 __bit
12597 \begin_inset LatexCommand \index{bit}
12598
12599 \end_inset
12600
12601  __at
12602 \begin_inset LatexCommand \index{at}
12603
12604 \end_inset
12605
12606  (0x02) bvar;
12607 \end_layout
12608
12609 \begin_layout Standard
12610 The above example will allocate the variable at offset 0x02 in the bit-addressab
12611 le space.
12612  There is no real advantage to assigning absolute addresses to variables
12613  in this manner, unless you want strict control over all the variables allocated.
12614  One possible use would be to write hardware portable code.
12615  For example, if you have a routine that uses one or more of the microcontroller
12616  I/O pins, and such pins are different for two different hardwares, you
12617  can declare the I/O pins in your routine using:
12618 \end_layout
12619
12620 \begin_layout Verse
12621
12622 \family typewriter
12623 extern volatile
12624 \begin_inset LatexCommand \index{volatile}
12625
12626 \end_inset
12627
12628  __bit MOSI;\InsetSpace ~
12629 \InsetSpace ~
12630 \InsetSpace ~
12631 \InsetSpace ~
12632 /* master out, slave in */
12633 \newline
12634 extern volatile __bit MISO;\InsetSpace ~
12635 \InsetSpace ~
12636 \InsetSpace ~
12637 \InsetSpace ~
12638 /* master
12639  in, slave out */
12640 \newline
12641 extern volatile __bit MCLK;\InsetSpace ~
12642 \InsetSpace ~
12643 \InsetSpace ~
12644 \InsetSpace ~
12645 /* master clock */
12646 \newline
12647
12648 \newline
12649 /* Input and
12650  Output of a byte on a 3-wire serial bus.
12651 \newline
12652 \InsetSpace ~
12653 \InsetSpace ~
12654 \InsetSpace ~
12655 If needed adapt polarity of clock,
12656  polarity of data and bit order
12657 \newline
12658 \InsetSpace ~
12659 */
12660 \newline
12661 unsigned char spi_io(unsigned char out_byte)
12662  
12663 \newline
12664
12665 \newline
12666 \InsetSpace ~
12667 \InsetSpace ~
12668 \InsetSpace ~
12669 \InsetSpace ~
12670 unsigned char i=8;
12671 \newline
12672 \InsetSpace ~
12673 \InsetSpace ~
12674 \InsetSpace ~
12675 \InsetSpace ~
12676 do { 
12677 \newline
12678 \InsetSpace ~
12679 \InsetSpace ~
12680 \InsetSpace ~
12681 \InsetSpace ~
12682 \InsetSpace ~
12683 \InsetSpace ~
12684 \InsetSpace ~
12685 \InsetSpace ~
12686 MOSI = out_byte & 0x80; 
12687 \newline
12688 \InsetSpace ~
12689 \InsetSpace ~
12690 \InsetSpace ~
12691 \InsetSpace ~
12692 \InsetSpace ~
12693 \InsetSpace ~
12694 \InsetSpace ~
12695 \InsetSpace ~
12696 out_byte <<= 1;
12697 \newline
12698 \InsetSpace ~
12699 \InsetSpace ~
12700 \InsetSpace ~
12701 \InsetSpace ~
12702 \InsetSpace ~
12703 \InsetSpace ~
12704 \InsetSpace ~
12705 \InsetSpace ~
12706 MCLK =
12707  1; 
12708 \newline
12709 \InsetSpace ~
12710 \InsetSpace ~
12711 \InsetSpace ~
12712 \InsetSpace ~
12713 \InsetSpace ~
12714 \InsetSpace ~
12715 \InsetSpace ~
12716 \InsetSpace ~
12717 /* _asm nop _endasm; */\InsetSpace ~
12718 \InsetSpace ~
12719 \InsetSpace ~
12720 \InsetSpace ~
12721 \InsetSpace ~
12722 \InsetSpace ~
12723 \InsetSpace ~
12724 \InsetSpace ~
12725 /* for slow peripherals */
12726 \newline
12727 \InsetSpace ~
12728 \InsetSpace ~
12729 \InsetSpace ~
12730 \InsetSpace ~
12731 \InsetSpace ~
12732 \InsetSpace ~
12733 \InsetSpace ~
12734 \InsetSpace ~
12735 if(MISO) 
12736 \newline
12737 \InsetSpace ~
12738 \InsetSpace ~
12739 \InsetSpace ~
12740 \InsetSpace ~
12741 \InsetSpace ~
12742 \InsetSpace ~
12743 \InsetSpace ~
12744 \InsetSpace ~
12745 \InsetSpace ~
12746 \InsetSpace ~
12747 \InsetSpace ~
12748 \InsetSpace ~
12749 out_byte +=
12750  1; 
12751 \newline
12752 \InsetSpace ~
12753 \InsetSpace ~
12754 \InsetSpace ~
12755 \InsetSpace ~
12756 \InsetSpace ~
12757 \InsetSpace ~
12758 \InsetSpace ~
12759 \InsetSpace ~
12760 MCLK = 0; 
12761 \newline
12762 \InsetSpace ~
12763 \InsetSpace ~
12764 \InsetSpace ~
12765 \InsetSpace ~
12766 } while(--i);
12767 \newline
12768 \InsetSpace ~
12769 \InsetSpace ~
12770 \InsetSpace ~
12771 \InsetSpace ~
12772 return out_byte; 
12773 \newline
12774 }
12775 \end_layout
12776
12777 \begin_layout Standard
12778 Then, someplace in the code for the first hardware you would use
12779 \end_layout
12780
12781 \begin_layout Verse
12782
12783 \family typewriter
12784 __bit __at
12785 \begin_inset LatexCommand \index{at}
12786
12787 \end_inset
12788
12789
12790 \begin_inset LatexCommand \index{\_\_at}
12791
12792 \end_inset
12793
12794  (0x80) MOSI;\InsetSpace ~
12795 \InsetSpace ~
12796 \InsetSpace ~
12797 \InsetSpace ~
12798 /* I/O port 0, bit 0 */
12799 \newline
12800 __bit __at (0x81) MISO;\InsetSpace ~
12801 \InsetSpace ~
12802 \InsetSpace ~
12803 \InsetSpace ~
12804 /* I/O port 0,
12805  bit 1 */
12806 \newline
12807 __bit __at (0x82) MCLK;\InsetSpace ~
12808 \InsetSpace ~
12809 \InsetSpace ~
12810 \InsetSpace ~
12811 /* I/O port 0, bit 2 */
12812 \end_layout
12813
12814 \begin_layout Standard
12815 Similarly, for the second hardware you would use
12816 \end_layout
12817
12818 \begin_layout Verse
12819
12820 \family typewriter
12821 __bit __at (0x83) MOSI;\InsetSpace ~
12822 \InsetSpace ~
12823 \InsetSpace ~
12824 \InsetSpace ~
12825 /* I/O port 0, bit 3 */
12826 \newline
12827 __bit __at (0x91) MISO;\InsetSpace ~
12828 \InsetSpace ~
12829 \InsetSpace ~
12830 \InsetSpace ~
12831 /*
12832  I/O port 1, bit 1 */
12833 \newline
12834 __bit
12835 \begin_inset LatexCommand \index{bit}
12836
12837 \end_inset
12838
12839  __at (0x92) MCLK;\InsetSpace ~
12840 \InsetSpace ~
12841 \InsetSpace ~
12842 \InsetSpace ~
12843 /* I/O port 1, bit 2 */
12844 \end_layout
12845
12846 \begin_layout Standard
12847 and you can use the same hardware dependent routine without changes, as
12848  for example in a library.
12849  This is somehow similar to sbit, but only one absolute address has to be
12850  specified in the whole project.
12851 \begin_inset VSpace bigskip
12852 \end_inset
12853
12854
12855 \end_layout
12856
12857 \begin_layout Section
12858 Parameters
12859 \begin_inset LatexCommand \index{Parameters}
12860
12861 \end_inset
12862
12863
12864 \begin_inset LatexCommand \index{function parameter}
12865
12866 \end_inset
12867
12868  & Local Variables
12869 \begin_inset LatexCommand \index{local variables}
12870
12871 \end_inset
12872
12873
12874 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
12875
12876 \end_inset
12877
12878
12879 \end_layout
12880
12881 \begin_layout Standard
12882 Automatic (local) variables and parameters to functions can either be placed
12883  on the stack or in data-space.
12884  The default action of the compiler is to place these variables in the internal
12885  RAM (for small model) or external RAM (for large model).
12886  This in fact makes them similar to 
12887 \emph on
12888 static
12889 \begin_inset LatexCommand \index{static}
12890
12891 \end_inset
12892
12893
12894 \emph default
12895  so by default functions are non-reentrant
12896 \begin_inset LatexCommand \index{reentrant}
12897
12898 \end_inset
12899
12900 .
12901  
12902 \newline
12903
12904 \newline
12905 They can be placed on the stack
12906 \begin_inset LatexCommand \index{stack}
12907
12908 \end_inset
12909
12910  by using the
12911 \emph on
12912  -
12913 \begin_inset ERT
12914 status collapsed
12915
12916 \begin_layout Standard
12917
12918
12919 \backslash
12920 /
12921 \end_layout
12922
12923 \end_inset
12924
12925 -stack-auto
12926 \begin_inset LatexCommand \index{-\/-stack-auto}
12927
12928 \end_inset
12929
12930
12931 \emph default
12932  option, by using 
12933 \emph on
12934 #pragma\InsetSpace ~
12935 stackauto
12936 \emph default
12937
12938 \begin_inset LatexCommand \index{\#pragma stackauto}
12939
12940 \end_inset
12941
12942  or by using the 
12943 \emph on
12944 reentrant
12945 \begin_inset LatexCommand \index{reentrant}
12946
12947 \end_inset
12948
12949
12950 \emph default
12951  keyword in the function declaration, e.g.:
12952 \end_layout
12953
12954 \begin_layout Verse
12955
12956 \family typewriter
12957 unsigned char foo(char i) __reentrant 
12958 \newline
12959
12960 \newline
12961 \InsetSpace ~
12962 \InsetSpace ~
12963 \InsetSpace ~
12964 \InsetSpace ~
12965 ...
12966  
12967 \newline
12968 }
12969 \end_layout
12970
12971 \begin_layout Standard
12972 Since stack space on 8051 is limited, the 
12973 \emph on
12974 reentrant 
12975 \emph default
12976 keyword or the
12977 \emph on
12978  -
12979 \begin_inset ERT
12980 status collapsed
12981
12982 \begin_layout Standard
12983
12984
12985 \backslash
12986 /
12987 \end_layout
12988
12989 \end_inset
12990
12991 -stack-auto
12992 \emph default
12993  option should be used sparingly.
12994  Note that the reentrant keyword just means that the parameters & local
12995  variables will be allocated to the stack, it 
12996 \emph on
12997 does not
12998 \emph default
12999  mean that the function is register bank
13000 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
13001
13002 \end_inset
13003
13004  independent.
13005 \newline
13006
13007 \newline
13008 Local variables
13009 \begin_inset LatexCommand \index{local variables}
13010
13011 \end_inset
13012
13013  can be assigned storage classes and absolute
13014 \begin_inset LatexCommand \index{Absolute addressing}
13015
13016 \end_inset
13017
13018  addresses, e.g.: 
13019 \end_layout
13020
13021 \begin_layout Verse
13022
13023 \family typewriter
13024 unsigned char foo() 
13025 \newline
13026 {
13027 \newline
13028 \InsetSpace ~
13029 \InsetSpace ~
13030 \InsetSpace ~
13031 \InsetSpace ~
13032 __xdata unsigned char i;
13033 \newline
13034 \InsetSpace ~
13035 \InsetSpace ~
13036 \InsetSpace ~
13037 \InsetSpace ~
13038 __bit bvar;
13039 \newline
13040 \InsetSpace ~
13041 \InsetSpace ~
13042 \InsetSpace ~
13043 \InsetSpace ~
13044 __data __at
13045 \begin_inset LatexCommand \index{at}
13046
13047 \end_inset
13048
13049  (0x31) unsigned char j;
13050 \newline
13051 \InsetSpace ~
13052 \InsetSpace ~
13053 \InsetSpace ~
13054 \InsetSpace ~
13055 ...
13056  
13057 \newline
13058 }
13059 \end_layout
13060
13061 \begin_layout Standard
13062 In the above example the variable 
13063 \emph on
13064 i
13065 \emph default
13066  will be allocated in the external ram, 
13067 \emph on
13068 bvar
13069 \emph default
13070  in bit addressable space and
13071 \emph on
13072  j
13073 \emph default
13074  in internal ram.
13075  When compiled with 
13076 \emph on
13077 -
13078 \begin_inset ERT
13079 status collapsed
13080
13081 \begin_layout Standard
13082
13083
13084 \backslash
13085 /
13086 \end_layout
13087
13088 \end_inset
13089
13090 -stack-auto
13091 \emph default
13092  or when a function is declared as 
13093 \emph on
13094 reentrant
13095 \emph default
13096  this should only be done for static variables.
13097 \end_layout
13098
13099 \begin_layout Standard
13100 Parameters
13101 \begin_inset LatexCommand \index{function parameter}
13102
13103 \end_inset
13104
13105  however are not allowed any storage class
13106 \begin_inset LatexCommand \index{Storage class}
13107
13108 \end_inset
13109
13110 , (storage classes for parameters will be ignored), their allocation is
13111  governed by the memory model in use, and the reentrancy options.
13112 \end_layout
13113
13114 \begin_layout Standard
13115 It is however allowed to use bit parameters in reentrant functions and also
13116  non-static local bit variables are supported.
13117  Efficient use is limited to 8 semi-bitregisters in bit space.
13118  They are pushed and popped to stack
13119 \begin_inset LatexCommand \index{stack}
13120
13121 \end_inset
13122
13123  as a single byte just like the normal registers.
13124 \end_layout
13125
13126 \begin_layout Section
13127 Overlaying
13128 \begin_inset LatexCommand \label{sub:Overlaying}
13129
13130 \end_inset
13131
13132
13133 \begin_inset LatexCommand \index{Overlaying}
13134
13135 \end_inset
13136
13137
13138 \end_layout
13139
13140 \begin_layout Standard
13141 For non-reentrant
13142 \begin_inset LatexCommand \index{reentrant}
13143
13144 \end_inset
13145
13146  functions SDCC will try to reduce internal ram space usage by overlaying
13147  parameters and local variables of a function (if possible).
13148  Parameters and local variables
13149 \begin_inset LatexCommand \index{local variables}
13150
13151 \end_inset
13152
13153  of a function will be allocated to an overlayable segment if the function
13154  has 
13155 \emph on
13156 no other function calls and the function is non-reentrant and the memory
13157  model
13158 \begin_inset LatexCommand \index{Memory model}
13159
13160 \end_inset
13161
13162  is small.
13163
13164 \emph default
13165  If an explicit storage class
13166 \begin_inset LatexCommand \index{Storage class}
13167
13168 \end_inset
13169
13170  is specified for a local variable, it will NOT be overlayed.
13171 \end_layout
13172
13173 \begin_layout Standard
13174 Note that the compiler (not the linkage editor) makes the decision for overlayin
13175 g the data items.
13176  Functions that are called from an interrupt service routine
13177 \begin_inset Marginal
13178 status collapsed
13179
13180 \begin_layout Standard
13181
13182 \series bold
13183 !
13184 \end_layout
13185
13186 \end_inset
13187
13188  should be preceded by a #pragma\InsetSpace ~
13189 nooverlay
13190 \begin_inset LatexCommand \index{\#pragma nooverlay}
13191
13192 \end_inset
13193
13194  if they are not reentrant.
13195 \end_layout
13196
13197 \begin_layout Standard
13198 Also note that the compiler does not do any processing of inline assembler
13199  code, so the compiler might incorrectly assign local variables and parameters
13200  of a function into the overlay segment if the inline assembler code calls
13201  other c-functions that might use the overlay.
13202  In that case the #pragma\InsetSpace ~
13203 nooverlay should be used.
13204 \end_layout
13205
13206 \begin_layout Standard
13207 Parameters and local variables of functions that contain 16 or 32 bit multiplica
13208 tion
13209 \begin_inset LatexCommand \index{Multiplication}
13210
13211 \end_inset
13212
13213  or division
13214 \begin_inset LatexCommand \index{Division}
13215
13216 \end_inset
13217
13218  will NOT be overlayed since these are implemented using external functions,
13219  e.g.:
13220 \end_layout
13221
13222 \begin_layout Verse
13223
13224 \family typewriter
13225 #pragma save 
13226 \newline
13227 #pragma nooverlay
13228 \begin_inset LatexCommand \index{\#pragma nooverlay}
13229
13230 \end_inset
13231
13232  
13233 \newline
13234 void set_error(unsigned char errcd) 
13235 \newline
13236 {
13237 \newline
13238 \InsetSpace ~
13239 \InsetSpace ~
13240 \InsetSpace ~
13241 \InsetSpace ~
13242 P3 = errcd;
13243 \newline
13244
13245 \newline
13246 #pragma restore 
13247 \newline
13248
13249 \newline
13250 void
13251  some_isr () __interrupt
13252 \begin_inset LatexCommand \index{interrupt}
13253
13254 \end_inset
13255
13256  (2)
13257 \newline
13258 {
13259 \newline
13260 \InsetSpace ~
13261 \InsetSpace ~
13262 \InsetSpace ~
13263 \InsetSpace ~
13264 ...
13265 \newline
13266 \InsetSpace ~
13267 \InsetSpace ~
13268 \InsetSpace ~
13269 \InsetSpace ~
13270 set_error(10);
13271 \newline
13272 \InsetSpace ~
13273 \InsetSpace ~
13274 \InsetSpace ~
13275 \InsetSpace ~
13276 ...
13277  
13278 \newline
13279 }
13280 \end_layout
13281
13282 \begin_layout Standard
13283 In the above example the parameter 
13284 \emph on
13285 errcd
13286 \emph default
13287  for the function 
13288 \emph on
13289 set_error
13290 \emph default
13291  would be assigned to the overlayable segment if the #pragma\InsetSpace ~
13292 nooverlay was
13293  not present, this could cause unpredictable runtime behavior when called
13294  from an interrupt service routine.
13295  The #pragma\InsetSpace ~
13296 nooverlay ensures that the parameters and local variables for
13297  the function are NOT overlayed.
13298 \begin_inset VSpace bigskip
13299 \end_inset
13300
13301
13302 \end_layout
13303
13304 \begin_layout Section
13305 Interrupt Service Routines
13306 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
13307
13308 \end_inset
13309
13310
13311 \end_layout
13312
13313 \begin_layout Subsection
13314 General Information
13315 \end_layout
13316
13317 \begin_layout Standard
13318 SDCC allows 
13319 \emph on
13320 i
13321 \emph default
13322 nterrupt 
13323 \emph on
13324 s
13325 \emph default
13326 ervice 
13327 \emph on
13328 r
13329 \emph default
13330 outines to be coded in C, with some extended keywords.
13331 \end_layout
13332
13333 \begin_layout Verse
13334
13335 \family typewriter
13336 void timer_isr (void) __interrupt (1) __using (1) 
13337 \newline
13338
13339 \newline
13340 \InsetSpace ~
13341 \InsetSpace ~
13342 \InsetSpace ~
13343 \InsetSpace ~
13344 ...
13345  
13346 \newline
13347 }
13348 \end_layout
13349
13350 \begin_layout Standard
13351 The optional number following the 
13352 \emph on
13353 interrupt
13354 \begin_inset LatexCommand \index{interrupt}
13355
13356 \end_inset
13357
13358
13359 \begin_inset LatexCommand \index{\_\_interrupt}
13360
13361 \end_inset
13362
13363
13364 \emph default
13365  keyword is the interrupt number this routine will service.
13366  When present, the compiler will insert a call to this routine in the interrupt
13367  vector table
13368 \begin_inset LatexCommand \index{interrupt vector table}
13369
13370 \end_inset
13371
13372  for the interrupt number specified.
13373  If you have multiple source files in your project, interrupt service routines
13374  can be present in any of them, but a prototype of the isr MUST be present
13375  or included in the file that contains the function 
13376 \emph on
13377 main
13378 \emph default
13379 .
13380  The optional (8051 specific) keyword 
13381 \emph on
13382 using
13383 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
13384
13385 \end_inset
13386
13387
13388 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
13389
13390 \end_inset
13391
13392
13393 \emph default
13394  can be used to tell the compiler to use the specified register bank when
13395  generating code for this function.
13396  
13397 \newline
13398 Interrupt service routines open the door for some very interesting bugs:
13399 \end_layout
13400
13401 \begin_layout Subsubsection
13402 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-volatile}
13403
13404 \end_inset
13405
13406 Common interrupt pitfall: variable not declared 
13407 \emph on
13408 volatile
13409 \end_layout
13410
13411 \begin_layout Standard
13412 If an interrupt service routine changes variables which are accessed by
13413  other functions these variables have to be declared 
13414 \emph on
13415 volatile
13416 \emph default
13417
13418 \begin_inset LatexCommand \index{volatile}
13419
13420 \end_inset
13421
13422 .
13423  See 
13424 \begin_inset LatexCommand \url{http://en.wikipedia.org/wiki/Volatile_variable}
13425
13426 \end_inset
13427
13428  .
13429 \end_layout
13430
13431 \begin_layout Subsubsection
13432 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-atomic}
13433
13434 \end_inset
13435
13436 Common interrupt pitfall: 
13437 \emph on
13438 non-atomic access
13439 \end_layout
13440
13441 \begin_layout Standard
13442 If the access to these variables is not 
13443 \emph on
13444 atomic
13445 \begin_inset LatexCommand \index{atomic}
13446
13447 \end_inset
13448
13449
13450 \emph default
13451  (i.e.
13452  the processor needs more than one instruction for the access and could
13453  be interrupted while accessing the variable) the interrupt must be disabled
13454  during the access to avoid inconsistent data.
13455  
13456 \newline
13457 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
13458  and should be protected by disabling interrupts.
13459  You're not automatically on the safe side if you use 8 bit variables though.
13460  We need an example here: f.e.
13461  on the 8051 the harmless looking 
13462 \begin_inset Quotes srd
13463 \end_inset
13464
13465
13466 \family typewriter
13467 flags\InsetSpace ~
13468 |=\InsetSpace ~
13469 0x80;
13470 \family default
13471
13472 \begin_inset Quotes sld
13473 \end_inset
13474
13475  is not atomic if 
13476 \family typewriter
13477 flags
13478 \family default
13479  resides in xdata.
13480  Setting 
13481 \begin_inset Quotes srd
13482 \end_inset
13483
13484
13485 \family typewriter
13486 flags\InsetSpace ~
13487 |=\InsetSpace ~
13488 0x40;
13489 \family default
13490
13491 \begin_inset Quotes sld
13492 \end_inset
13493
13494  from within an interrupt routine might get lost if the interrupt occurs
13495  at the wrong time.
13496  
13497 \begin_inset Quotes sld
13498 \end_inset
13499
13500
13501 \family typewriter
13502 counter\InsetSpace ~
13503 +=\InsetSpace ~
13504 8;
13505 \family default
13506
13507 \begin_inset Quotes srd
13508 \end_inset
13509
13510  is not atomic on the 8051 even if 
13511 \family typewriter
13512 counter
13513 \family default
13514  is located in data memory.
13515 \newline
13516 Bugs like these are hard to reproduce and can
13517  cause a lot of trouble.
13518  
13519 \end_layout
13520
13521 \begin_layout Subsubsection
13522 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-stack-overflow}
13523
13524 \end_inset
13525
13526 Common interrupt pitfall: 
13527 \emph on
13528 stack overflow
13529 \end_layout
13530
13531 \begin_layout Standard
13532 The return address and the registers used in the interrupt service routine
13533  are saved on the stack
13534 \begin_inset LatexCommand \index{stack}
13535
13536 \end_inset
13537
13538  so there must be sufficient stack space.
13539  If there isn't variables or registers (or even the return address itself)
13540  will be corrupted.
13541  This 
13542 \emph on
13543 stack overflow
13544 \emph default
13545
13546 \begin_inset LatexCommand \index{stack overflow}
13547
13548 \end_inset
13549
13550  is most likely to happen if the interrupt occurs during the 
13551 \begin_inset Quotes sld
13552 \end_inset
13553
13554 deepest
13555 \begin_inset Quotes srd
13556 \end_inset
13557
13558  subroutine when the stack is already in use for f.e.
13559  many return addresses.
13560 \end_layout
13561
13562 \begin_layout Subsubsection
13563 \begin_inset LatexCommand \label{sub:Common-interrupt-pitfall-non-reentrant}
13564
13565 \end_inset
13566
13567 Common interrupt pitfall: 
13568 \emph on
13569 use of non-reentrant functions
13570 \end_layout
13571
13572 \begin_layout Standard
13573 A special note here, int (16 bit) and long (32 bit) integer division
13574 \begin_inset LatexCommand \index{Division}
13575
13576 \end_inset
13577
13578 , multiplication
13579 \begin_inset LatexCommand \index{Multiplication}
13580
13581 \end_inset
13582
13583  & modulus
13584 \begin_inset LatexCommand \index{Modulus}
13585
13586 \end_inset
13587
13588  and floating-point
13589 \begin_inset LatexCommand \index{Floating point support}
13590
13591 \end_inset
13592
13593  operations are implemented using external support routines.
13594  If an interrupt service routine needs to do any of these operations then
13595  the support routines (as mentioned in a following section) will have to
13596  be recompiled using the
13597 \emph on
13598  -
13599 \begin_inset ERT
13600 status collapsed
13601
13602 \begin_layout Standard
13603
13604
13605 \backslash
13606 /
13607 \end_layout
13608
13609 \end_inset
13610
13611 -stack-auto
13612 \begin_inset LatexCommand \index{-\/-stack-auto}
13613
13614 \end_inset
13615
13616
13617 \emph default
13618  option and the source file will need to be compiled using the 
13619 \emph on
13620 -
13621 \begin_inset ERT
13622 status collapsed
13623
13624 \begin_layout Standard
13625
13626
13627 \backslash
13628 /
13629 \end_layout
13630
13631 \end_inset
13632
13633 -int-long-reent
13634 \emph default
13635
13636 \begin_inset LatexCommand \index{-\/-int-long-reent}
13637
13638 \end_inset
13639
13640  compiler option.
13641  
13642 \newline
13643 Note, the type promotion
13644 \begin_inset LatexCommand \index{type promotion}
13645
13646 \end_inset
13647
13648  required by ANSI C can cause 16 bit routines to be used
13649 \begin_inset Marginal
13650 status collapsed
13651
13652 \begin_layout Standard
13653
13654 \series bold
13655 \InsetSpace ~
13656 !
13657 \end_layout
13658
13659 \end_inset
13660
13661  without the programmer being aware of it.
13662  See f.e.
13663  the cast 
13664 \family typewriter
13665 (unsigned char)(tail-1)
13666 \family default
13667  within the if clause in section 
13668 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
13669
13670 \end_inset
13671
13672 .
13673 \end_layout
13674
13675 \begin_layout Standard
13676 Calling other functions from an interrupt service routine is not recommended,
13677  avoid it if possible.
13678  Note that when some function is called from an interrupt service routine
13679  it should be preceded by a #pragma\InsetSpace ~
13680 nooverlay
13681 \begin_inset LatexCommand \index{\#pragma nooverlay}
13682
13683 \end_inset
13684
13685  if it is not reentrant.
13686  Furthermore nonreentrant functions should not be called from the main program
13687  while the interrupt service routine might be active.
13688  They also must not be called from low priority interrupt service routines
13689  while a high priority interrupt service routine might be active.
13690  You could use semaphores or make the function
13691 \emph on
13692  critical
13693 \emph default
13694  if all parameters are passed in registers.
13695 \newline
13696  Also see section 
13697 \begin_inset LatexCommand \ref{sub:Overlaying}
13698
13699 \end_inset
13700
13701 \InsetSpace ~
13702 about Overlaying and section 
13703 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
13704
13705 \end_inset
13706
13707 \InsetSpace ~
13708 about Functions using private register banks.
13709 \begin_inset VSpace bigskip
13710 \end_inset
13711
13712
13713 \end_layout
13714
13715 \begin_layout Subsection
13716 MCS51/DS390 Interrupt Service Routines
13717 \end_layout
13718
13719 \begin_layout Standard
13720 Interrupt
13721 \begin_inset LatexCommand \index{interrupt}
13722
13723 \end_inset
13724
13725  numbers and the corresponding address & descriptions for the Standard 8051/8052
13726  are listed below.
13727  SDCC will automatically adjust the 
13728 \begin_inset LatexCommand \index{interrupt vector table}
13729
13730 \end_inset
13731
13732  to the maximum interrupt number specified.
13733 \newline
13734
13735 \end_layout
13736
13737 \begin_layout Standard
13738 \align center
13739 \begin_inset Tabular
13740 <lyxtabular version="3" rows="9" columns="3">
13741 <features>
13742 <column alignment="center" valignment="top" leftline="true" width="0in">
13743 <column alignment="left" valignment="top" leftline="true" width="0in">
13744 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
13745 <row topline="true" bottomline="true">
13746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13747 \begin_inset Text
13748
13749 \begin_layout Standard
13750 Interrupt #
13751 \end_layout
13752
13753 \end_inset
13754 </cell>
13755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13756 \begin_inset Text
13757
13758 \begin_layout Standard
13759 Description
13760 \end_layout
13761
13762 \end_inset
13763 </cell>
13764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13765 \begin_inset Text
13766
13767 \begin_layout Standard
13768 Vector Address
13769 \end_layout
13770
13771 \end_inset
13772 </cell>
13773 </row>
13774 <row topline="true">
13775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13776 \begin_inset Text
13777
13778 \begin_layout Standard
13779 0
13780 \end_layout
13781
13782 \end_inset
13783 </cell>
13784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13785 \begin_inset Text
13786
13787 \begin_layout Standard
13788 External 0
13789 \end_layout
13790
13791 \end_inset
13792 </cell>
13793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13794 \begin_inset Text
13795
13796 \begin_layout Standard
13797 0x0003
13798 \end_layout
13799
13800 \end_inset
13801 </cell>
13802 </row>
13803 <row topline="true">
13804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13805 \begin_inset Text
13806
13807 \begin_layout Standard
13808 1
13809 \end_layout
13810
13811 \end_inset
13812 </cell>
13813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13814 \begin_inset Text
13815
13816 \begin_layout Standard
13817 Timer 0
13818 \end_layout
13819
13820 \end_inset
13821 </cell>
13822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13823 \begin_inset Text
13824
13825 \begin_layout Standard
13826 0x000b
13827 \end_layout
13828
13829 \end_inset
13830 </cell>
13831 </row>
13832 <row topline="true">
13833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13834 \begin_inset Text
13835
13836 \begin_layout Standard
13837 2
13838 \end_layout
13839
13840 \end_inset
13841 </cell>
13842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13843 \begin_inset Text
13844
13845 \begin_layout Standard
13846 External 1
13847 \end_layout
13848
13849 \end_inset
13850 </cell>
13851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13852 \begin_inset Text
13853
13854 \begin_layout Standard
13855 0x0013
13856 \end_layout
13857
13858 \end_inset
13859 </cell>
13860 </row>
13861 <row topline="true">
13862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13863 \begin_inset Text
13864
13865 \begin_layout Standard
13866 3
13867 \end_layout
13868
13869 \end_inset
13870 </cell>
13871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13872 \begin_inset Text
13873
13874 \begin_layout Standard
13875 Timer 1
13876 \end_layout
13877
13878 \end_inset
13879 </cell>
13880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13881 \begin_inset Text
13882
13883 \begin_layout Standard
13884 0x001b
13885 \end_layout
13886
13887 \end_inset
13888 </cell>
13889 </row>
13890 <row topline="true">
13891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13892 \begin_inset Text
13893
13894 \begin_layout Standard
13895 4
13896 \end_layout
13897
13898 \end_inset
13899 </cell>
13900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13901 \begin_inset Text
13902
13903 \begin_layout Standard
13904 Serial
13905 \end_layout
13906
13907 \end_inset
13908 </cell>
13909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13910 \begin_inset Text
13911
13912 \begin_layout Standard
13913 0x0023
13914 \end_layout
13915
13916 \end_inset
13917 </cell>
13918 </row>
13919 <row topline="true">
13920 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13921 \begin_inset Text
13922
13923 \begin_layout Standard
13924 5
13925 \end_layout
13926
13927 \end_inset
13928 </cell>
13929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13930 \begin_inset Text
13931
13932 \begin_layout Standard
13933 Timer 2 (8052)
13934 \end_layout
13935
13936 \end_inset
13937 </cell>
13938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13939 \begin_inset Text
13940
13941 \begin_layout Standard
13942 0x002b
13943 \end_layout
13944
13945 \end_inset
13946 </cell>
13947 </row>
13948 <row topline="true">
13949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13950 \begin_inset Text
13951
13952 \begin_layout Standard
13953 ...
13954 \end_layout
13955
13956 \end_inset
13957 </cell>
13958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13959 \begin_inset Text
13960
13961 \begin_layout Standard
13962
13963 \end_layout
13964
13965 \end_inset
13966 </cell>
13967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13968 \begin_inset Text
13969
13970 \begin_layout Standard
13971 ...
13972 \end_layout
13973
13974 \end_inset
13975 </cell>
13976 </row>
13977 <row topline="true" bottomline="true">
13978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13979 \begin_inset Text
13980
13981 \begin_layout Standard
13982 n
13983 \end_layout
13984
13985 \end_inset
13986 </cell>
13987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13988 \begin_inset Text
13989
13990 \begin_layout Standard
13991
13992 \end_layout
13993
13994 \end_inset
13995 </cell>
13996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13997 \begin_inset Text
13998
13999 \begin_layout Standard
14000 0x0003 + 8*n
14001 \end_layout
14002
14003 \end_inset
14004 </cell>
14005 </row>
14006 </lyxtabular>
14007
14008 \end_inset
14009
14010
14011 \newline
14012
14013 \end_layout
14014
14015 \begin_layout Standard
14016 If the interrupt service routine is defined without 
14017 \emph on
14018 using
14019 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14020
14021 \end_inset
14022
14023
14024 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14025
14026 \end_inset
14027
14028
14029 \emph default
14030  a register bank or with register bank 0 (
14031 \emph on
14032 using
14033 \emph default
14034  0), the compiler will save the registers used by itself on the stack upon
14035  entry and restore them at exit, however if such an interrupt service routine
14036  calls another function then the entire register bank will be saved on the
14037  stack.
14038  This scheme may be advantageous for small interrupt service routines which
14039  have low register usage.
14040 \end_layout
14041
14042 \begin_layout Standard
14043 If the interrupt service routine is defined to be using a specific register
14044  bank then only 
14045 \emph on
14046 a, b, dptr
14047 \emph default
14048  & psw are saved and restored, if such an interrupt service routine calls
14049  another function (using another register bank) then the entire register
14050  bank of the called function will be saved on the stack
14051 \begin_inset LatexCommand \index{stack}
14052
14053 \end_inset
14054
14055 .
14056  This scheme is recommended for larger interrupt service routines.
14057 \begin_inset VSpace bigskip
14058 \end_inset
14059
14060
14061 \end_layout
14062
14063 \begin_layout Subsection
14064 HC08
14065 \begin_inset LatexCommand \index{HC08}
14066
14067 \end_inset
14068
14069  Interrupt Service Routines
14070 \end_layout
14071
14072 \begin_layout Standard
14073 Since the number of interrupts
14074 \begin_inset LatexCommand \index{HC08!interrupt}
14075
14076 \end_inset
14077
14078  available is chip specific and the interrupt vector table always ends at
14079  the last byte of memory, the interrupt numbers corresponds to the interrupt
14080  vectors in reverse order of address.
14081  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
14082  2 will use the interrupt vector at 0xfffa, and so on.
14083  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
14084  this way; instead see section 
14085 \begin_inset LatexCommand \ref{sub:Startup-Code}
14086
14087 \end_inset
14088
14089  for details on customizing startup.
14090 \begin_inset VSpace bigskip
14091 \end_inset
14092
14093
14094 \end_layout
14095
14096 \begin_layout Subsection
14097 Z80 Interrupt Service Routines
14098 \end_layout
14099
14100 \begin_layout Standard
14101 The Z80
14102 \begin_inset LatexCommand \index{Z80}
14103
14104 \end_inset
14105
14106  uses several different methods for determining the correct interrupt
14107 \begin_inset LatexCommand \index{Z80!interrupt}
14108
14109 \end_inset
14110
14111  vector depending on the hardware implementation.
14112  Therefore, SDCC ignores the optional interrupt number and does not attempt
14113  to generate an interrupt vector table.
14114 \end_layout
14115
14116 \begin_layout Standard
14117 By default, SDCC generates code for a maskable interrupt, which uses a RETI
14118  instruction to return from the interrupt.
14119  To write an interrupt handler for the non-maskable interrupt, which needs
14120  a RETN instruction instead, add the 
14121 \emph on
14122 critical
14123 \emph default
14124  keyword:
14125 \end_layout
14126
14127 \begin_layout Verse
14128
14129 \family typewriter
14130 void nmi_isr (void) critical interrupt
14131 \newline
14132
14133 \newline
14134 \InsetSpace ~
14135 \InsetSpace ~
14136 \InsetSpace ~
14137 \InsetSpace ~
14138 ...
14139  
14140 \newline
14141 }
14142 \end_layout
14143
14144 \begin_layout Standard
14145 However if you need to create a non-interruptable interrupt service routine
14146  you would also require the 
14147 \emph on
14148 critical
14149 \emph default
14150  keyword.
14151  To distinguish between this and an nmi_isr you must provide an interrupt
14152  number.
14153 \begin_inset VSpace bigskip
14154 \end_inset
14155
14156
14157 \end_layout
14158
14159 \begin_layout Section
14160 Enabling and Disabling Interrupts
14161 \end_layout
14162
14163 \begin_layout Subsection
14164 Critical Functions and Critical Statements
14165 \end_layout
14166
14167 \begin_layout Standard
14168 A special keyword may be associated with a block or a function declaring
14169  it as 
14170 \emph on
14171 critical
14172 \emph default
14173 .
14174  SDCC will generate code to disable all interrupts
14175 \begin_inset LatexCommand \index{interrupt}
14176
14177 \end_inset
14178
14179  upon entry to a critical function and restore the interrupt enable to the
14180  previous state before returning.
14181  Nesting critical functions will need one additional byte on the stack
14182 \begin_inset LatexCommand \index{stack}
14183
14184 \end_inset
14185
14186  for each call.
14187 \end_layout
14188
14189 \begin_layout Verse
14190
14191 \family typewriter
14192 int foo () __critical
14193 \begin_inset LatexCommand \index{critical}
14194
14195 \end_inset
14196
14197
14198 \begin_inset LatexCommand \index{\_\_critical}
14199
14200 \end_inset
14201
14202  
14203 \newline
14204
14205 \newline
14206 \InsetSpace ~
14207 \InsetSpace ~
14208 \InsetSpace ~
14209 \InsetSpace ~
14210 ...
14211  
14212 \newline
14213 \InsetSpace ~
14214 \InsetSpace ~
14215 \InsetSpace ~
14216 \InsetSpace ~
14217 ...
14218  
14219 \newline
14220 }
14221 \end_layout
14222
14223 \begin_layout Standard
14224 The critical attribute maybe used with other attributes like 
14225 \emph on
14226 reentrant.
14227 \emph default
14228
14229 \newline
14230 The keyword 
14231 \emph on
14232 critical
14233 \emph default
14234  may also be used to disable interrupts more locally:
14235 \end_layout
14236
14237 \begin_layout Verse
14238
14239 \family typewriter
14240 __critical{ i++; }
14241 \end_layout
14242
14243 \begin_layout Standard
14244 More than one statement could have been included in the block.
14245 \end_layout
14246
14247 \begin_layout Subsection
14248 Enabling and Disabling Interrupts directly
14249 \end_layout
14250
14251 \begin_layout Standard
14252 Interrupts
14253 \begin_inset LatexCommand \index{interrupt}
14254
14255 \end_inset
14256
14257  can also be disabled and enabled directly (8051):
14258 \end_layout
14259
14260 \begin_layout Verse
14261
14262 \family typewriter
14263 EA = 0;\InsetSpace ~
14264 \InsetSpace ~
14265 \InsetSpace ~
14266 \InsetSpace ~
14267 \InsetSpace ~
14268 \InsetSpace ~
14269 \InsetSpace ~
14270 \InsetSpace ~
14271 \InsetSpace ~
14272 \InsetSpace ~
14273 \InsetSpace ~
14274 \InsetSpace ~
14275 or:\InsetSpace ~
14276 \InsetSpace ~
14277 \InsetSpace ~
14278 \InsetSpace ~
14279 \InsetSpace ~
14280 \InsetSpace ~
14281 \InsetSpace ~
14282 \InsetSpace ~
14283 \InsetSpace ~
14284 \InsetSpace ~
14285 \InsetSpace ~
14286 EA_SAVE = EA;
14287 \end_layout
14288
14289 \begin_layout Verse
14290
14291 \family typewriter
14292 ...\InsetSpace ~
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 EA = 0;
14323 \end_layout
14324
14325 \begin_layout Verse
14326
14327 \family typewriter
14328 EA = 1;\InsetSpace ~
14329 \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 ...
14355 \end_layout
14356
14357 \begin_layout Verse
14358
14359 \family typewriter
14360 \InsetSpace ~
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 EA = EA_SAVE;
14394 \end_layout
14395
14396 \begin_layout Standard
14397 On other architectures which have seperate opcodes for enabling and disabling
14398  interrupts you might want to make use of defines with inline assembly
14399 \begin_inset LatexCommand \index{Assembler routines}
14400
14401 \end_inset
14402
14403  (HC08
14404 \begin_inset LatexCommand \index{HC08!interrupt}
14405
14406 \end_inset
14407
14408 ):
14409 \end_layout
14410
14411 \begin_layout Verse
14412
14413 \family typewriter
14414 #define CLI _asm
14415 \begin_inset LatexCommand \index{\_asm}
14416
14417 \end_inset
14418
14419 \InsetSpace ~
14420 \InsetSpace ~
14421 cli\InsetSpace ~
14422 \InsetSpace ~
14423 _endasm
14424 \begin_inset LatexCommand \index{\_endasm}
14425
14426 \end_inset
14427
14428
14429 \end_layout
14430
14431 \begin_layout Verse
14432
14433 \family typewriter
14434 #define SEI _asm\InsetSpace ~
14435 \InsetSpace ~
14436 sei\InsetSpace ~
14437 \InsetSpace ~
14438 _endasm; 
14439 \end_layout
14440
14441 \begin_layout Verse
14442
14443 \family typewriter
14444 ...
14445 \end_layout
14446
14447 \begin_layout Standard
14448 Note: it is sometimes sufficient to disable only a specific interrupt source
14449  like f.e.
14450  a timer or serial interrupt by manipulating an 
14451 \emph on
14452 interrupt mask
14453 \begin_inset LatexCommand \index{interrupt mask}
14454
14455 \end_inset
14456
14457
14458 \emph default
14459  register.
14460  
14461 \end_layout
14462
14463 \begin_layout Standard
14464 Usually the time during which interrupts are disabled should be kept as
14465  short as possible.
14466  This minimizes both 
14467 \emph on
14468 interrupt latency
14469 \emph default
14470
14471 \begin_inset LatexCommand \index{interrupt latency}
14472
14473 \end_inset
14474
14475  (the time between the occurrence of the interrupt and the execution of
14476  the first code in the interrupt routine) and 
14477 \emph on
14478 interrupt jitter
14479 \emph default
14480
14481 \begin_inset LatexCommand \index{interrupt jitter}
14482
14483 \end_inset
14484
14485  (the difference between the shortest and the longest interrupt latency).
14486  These really are something different, f.e.
14487  a serial interrupt has to be served before its buffer overruns so it cares
14488  for the maximum interrupt latency, whereas it does not care about jitter.
14489  On a loudspeaker driven via a digital to analog converter which is fed
14490  by an interrupt a latency of a few milliseconds might be tolerable, whereas
14491  a much smaller jitter will be very audible.
14492 \end_layout
14493
14494 \begin_layout Standard
14495 You can reenable interrupts within an interrupt routine and on some architecture
14496 s you can make use of two (or more) levels of 
14497 \emph on
14498 interrupt priorities
14499 \emph default
14500
14501 \begin_inset LatexCommand \index{interrupt priority}
14502
14503 \end_inset
14504
14505 .
14506  On some architectures which don't support interrupt priorities these can
14507  be implemented by manipulating the interrupt mask and reenabling interrupts
14508  within the interrupt routine.
14509  Check there is sufficient space on the stack
14510 \begin_inset LatexCommand \index{stack}
14511
14512 \end_inset
14513
14514  and don't add complexity unless you have to.
14515  
14516 \end_layout
14517
14518 \begin_layout Subsection
14519 Semaphore
14520 \begin_inset LatexCommand \index{semaphore}
14521
14522 \end_inset
14523
14524  locking (mcs51/ds390)
14525 \end_layout
14526
14527 \begin_layout Standard
14528 Some architectures (mcs51/ds390) have an atomic
14529 \begin_inset LatexCommand \index{atomic}
14530
14531 \end_inset
14532
14533  bit test and
14534 \emph on
14535  
14536 \emph default
14537 clear
14538 \emph on
14539  
14540 \emph default
14541 instruction.
14542  These type of instructions are typically used in preemptive multitasking
14543  systems, where a routine f.e.
14544  claims the use of a data structure ('acquires a lock
14545 \begin_inset LatexCommand \index{lock}
14546
14547 \end_inset
14548
14549  on it'), makes some modifications and then releases the lock when the data
14550  structure is consistent again.
14551  The instruction may also be used if interrupt and non-interrupt code have
14552  to compete for a resource.
14553  With the atomic bit test and clear instruction interrupts
14554 \begin_inset LatexCommand \index{interrupt}
14555
14556 \end_inset
14557
14558  don't have to be disabled for the locking operation.
14559  
14560 \end_layout
14561
14562 \begin_layout Standard
14563 SDCC generates this instruction if the source follows this pattern:
14564 \end_layout
14565
14566 \begin_layout Verse
14567
14568 \family typewriter
14569 volatile
14570 \begin_inset LatexCommand \index{volatile}
14571
14572 \end_inset
14573
14574  bit resource_is_free; 
14575 \newline
14576
14577 \newline
14578 if (resource_is_free) 
14579 \newline
14580 \InsetSpace ~
14581 \InsetSpace ~
14582
14583 \newline
14584 \InsetSpace ~
14585 \InsetSpace ~
14586 \InsetSpace ~
14587 \InsetSpace ~
14588 resource_is_free=0; 
14589 \newline
14590 \InsetSpace ~
14591 \InsetSpace ~
14592 \InsetSpace ~
14593 \InsetSpace ~
14594 ...
14595  
14596 \newline
14597 \InsetSpace ~
14598 \InsetSpace ~
14599 \InsetSpace ~
14600 \InsetSpace ~
14601 resource_is_free=1;
14602 \newline
14603 \InsetSpace ~
14604 \InsetSpace ~
14605
14606 \end_layout
14607
14608 \begin_layout Standard
14609 Note, mcs51 and ds390 support only an atomic
14610 \begin_inset LatexCommand \index{atomic}
14611
14612 \end_inset
14613
14614  bit test and 
14615 \emph on
14616 clear
14617 \emph default
14618  instruction (as opposed to atomic bit test and 
14619 \emph on
14620 set).
14621 \end_layout
14622
14623 \begin_layout Section
14624 Functions using private register banks
14625 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
14626
14627 \end_inset
14628
14629  (mcs51/ds390)
14630 \end_layout
14631
14632 \begin_layout Standard
14633 Some architectures have support for quickly changing register sets.
14634  SDCC supports this feature with the 
14635 \emph on
14636 using
14637 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
14638
14639 \end_inset
14640
14641
14642 \begin_inset LatexCommand \index{\_\_using (mcs51, ds390 register bank)}
14643
14644 \end_inset
14645
14646
14647 \emph default
14648  attribute (which tells the compiler to use a register bank
14649 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
14650
14651 \end_inset
14652
14653  other than the default bank zero).
14654  It should only be applied to 
14655 \emph on
14656 interrupt
14657 \begin_inset LatexCommand \index{interrupt}
14658
14659 \end_inset
14660
14661
14662 \emph default
14663  functions (see footnote below).
14664  This will in most circumstances make the generated ISR code more efficient
14665  since it will not have to save registers on the stack.
14666 \end_layout
14667
14668 \begin_layout Standard
14669 The 
14670 \emph on
14671 using
14672 \emph default
14673  attribute will have no effect on the generated code for a 
14674 \emph on
14675 non-interrupt
14676 \emph default
14677  function (but may occasionally be useful anyway
14678 \begin_inset Foot
14679 status open
14680
14681 \begin_layout Standard
14682 possible exception: if a function is called ONLY from 'interrupt' functions
14683  using a particular bank, it can be declared with the same 'using' attribute
14684  as the calling 'interrupt' functions.
14685  For instance, if you have several ISRs using bank one, and all of them
14686  call memcpy(), it might make sense to create a specialized version of memcpy()
14687  'using 1', since this would prevent the ISR from having to save bank zero
14688  to the stack on entry and switch to bank zero before calling the function
14689 \end_layout
14690
14691 \end_inset
14692
14693 ).
14694 \newline
14695
14696 \emph on
14697 (pending: Note, nowadays the 
14698 \emph default
14699 using
14700 \emph on
14701  attribute has an effect on
14702 \emph default
14703  
14704 \emph on
14705 the generated code for a 
14706 \emph default
14707 non-interrupt
14708 \emph on
14709  function
14710 \emph default
14711 .
14712 \emph on
14713 )
14714 \end_layout
14715
14716 \begin_layout Standard
14717 An 
14718 \emph on
14719 interrupt
14720 \emph default
14721  function using a non-zero bank will assume that it can trash that register
14722  bank, and will not save it.
14723  Since high-priority interrupts
14724 \begin_inset LatexCommand \index{interrupts}
14725
14726 \end_inset
14727
14728
14729 \begin_inset LatexCommand \index{interrupt priority}
14730
14731 \end_inset
14732
14733  can interrupt low-priority ones on the 8051 and friends, this means that
14734  if a high-priority ISR 
14735 \emph on
14736 using
14737 \emph default
14738  a particular bank occurs while processing a low-priority ISR 
14739 \emph on
14740 using
14741 \emph default
14742  the same bank, terrible and bad things can happen.
14743  To prevent this, no single register bank should be 
14744 \emph on
14745 used
14746 \emph default
14747  by both a high priority and a low priority ISR.
14748  This is probably most easily done by having all high priority ISRs use
14749  one bank and all low priority ISRs use another.
14750  If you have an ISR which can change priority at runtime, you're on your
14751  own: I suggest using the default bank zero and taking the small performance
14752  hit.
14753 \end_layout
14754
14755 \begin_layout Standard
14756 It is most efficient if your ISR calls no other functions.
14757  If your ISR must call other functions, it is most efficient if those functions
14758  use the same bank as the ISR (see note 1 below); the next best is if the
14759  called functions use bank zero.
14760  It is very inefficient to call a function using a different, non-zero bank
14761  from an ISR.
14762  
14763 \begin_inset VSpace bigskip
14764 \end_inset
14765
14766
14767 \end_layout
14768
14769 \begin_layout Section
14770 Startup Code
14771 \begin_inset LatexCommand \label{sub:Startup-Code}
14772
14773 \end_inset
14774
14775
14776 \begin_inset LatexCommand \index{Startup code}
14777
14778 \end_inset
14779
14780
14781 \end_layout
14782
14783 \begin_layout Subsection
14784 MCS51/DS390 Startup Code
14785 \end_layout
14786
14787 \begin_layout Standard
14788 The compiler triggers the linker to link certain initialization modules
14789  from the runtime library
14790 \begin_inset LatexCommand \index{Runtime library}
14791
14792 \end_inset
14793
14794  called crt<something>.
14795  Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
14796  GSINIT5) is not linked unless the --xstack option is used.
14797  These modules are highly entangled by the use of special segments/areas,
14798  but a common layout is shown below:
14799 \end_layout
14800
14801 \begin_layout Verse
14802
14803 \family typewriter
14804 \series bold
14805 \size footnotesize
14806 (main.asm)
14807 \end_layout
14808
14809 \begin_layout Verse
14810
14811 \family typewriter
14812 \size footnotesize
14813 \InsetSpace ~
14814 \InsetSpace ~
14815 \InsetSpace ~
14816 \InsetSpace ~
14817 \InsetSpace ~
14818 \InsetSpace ~
14819 \InsetSpace ~
14820 \InsetSpace ~
14821 .area HOME (CODE)
14822 \newline
14823 __interrupt_vect:
14824 \newline
14825 \InsetSpace ~
14826 \InsetSpace ~
14827 \InsetSpace ~
14828 \InsetSpace ~
14829 \InsetSpace ~
14830 \InsetSpace ~
14831 \InsetSpace ~
14832 \InsetSpace ~
14833 ljmp __sdcc_gsinit_startup
14834 \end_layout
14835
14836 \begin_layout Verse
14837
14838 \family typewriter
14839 \series bold
14840 \size footnotesize
14841 (crtstart.asm)
14842 \end_layout
14843
14844 \begin_layout Verse
14845
14846 \family typewriter
14847 \size footnotesize
14848 \InsetSpace ~
14849 \InsetSpace ~
14850 \InsetSpace ~
14851 \InsetSpace ~
14852 \InsetSpace ~
14853 \InsetSpace ~
14854 \InsetSpace ~
14855 \InsetSpace ~
14856 .area GSINIT0 (CODE)
14857 \newline
14858 __sdcc_gsinit_startup::
14859 \newline
14860 \InsetSpace ~
14861 \InsetSpace ~
14862 \InsetSpace ~
14863 \InsetSpace ~
14864 \InsetSpace ~
14865 \InsetSpace ~
14866 \InsetSpace ~
14867 \InsetSpace ~
14868 mov sp,#__start__stack - 1
14869 \end_layout
14870
14871 \begin_layout Verse
14872
14873 \family typewriter
14874 \series bold
14875 \size footnotesize
14876 (crtxstack.asm)
14877 \end_layout
14878
14879 \begin_layout Verse
14880
14881 \family typewriter
14882 \size footnotesize
14883 \InsetSpace ~
14884 \InsetSpace ~
14885 \InsetSpace ~
14886 \InsetSpace ~
14887 \InsetSpace ~
14888 \InsetSpace ~
14889 \InsetSpace ~
14890 \InsetSpace ~
14891 .area GSINIT1 (CODE)
14892 \newline
14893 __sdcc_init_xstack::
14894 \newline
14895 ; Need to initialize in GSINIT1 in
14896  case the user's __sdcc_external_startup uses the xstack.
14897 \newline
14898 \InsetSpace ~
14899 \InsetSpace ~
14900 \InsetSpace ~
14901 \InsetSpace ~
14902 \InsetSpace ~
14903 \InsetSpace ~
14904 \InsetSpace ~
14905 \InsetSpace ~
14906 mov __XPAGE,#(__start__x
14907 stack >> 8)
14908 \newline
14909 \InsetSpace ~
14910 \InsetSpace ~
14911 \InsetSpace ~
14912 \InsetSpace ~
14913 \InsetSpace ~
14914 \InsetSpace ~
14915 \InsetSpace ~
14916 \InsetSpace ~
14917 mov _spx,#__start__xstack
14918 \end_layout
14919
14920 \begin_layout Verse
14921
14922 \family typewriter
14923 \series bold
14924 \size footnotesize
14925 (crtstart.asm)
14926 \end_layout
14927
14928 \begin_layout Verse
14929
14930 \family typewriter
14931 \size footnotesize
14932 \InsetSpace ~
14933 \InsetSpace ~
14934 \InsetSpace ~
14935 \InsetSpace ~
14936 \InsetSpace ~
14937 \InsetSpace ~
14938 \InsetSpace ~
14939 \InsetSpace ~
14940 .area GSINIT2 (CODE)
14941 \newline
14942 \InsetSpace ~
14943 \InsetSpace ~
14944 \InsetSpace ~
14945 \InsetSpace ~
14946 \InsetSpace ~
14947 \InsetSpace ~
14948 \InsetSpace ~
14949 \InsetSpace ~
14950 lcall __sdcc_external_startup
14951 \newline
14952 \InsetSpace ~
14953 \InsetSpace ~
14954 \InsetSpace ~
14955 \InsetSpace ~
14956 \InsetSpace ~
14957 \InsetSpace ~
14958 \InsetSpace ~
14959 \InsetSpace ~
14960 mov a,dpl
14961 \newline
14962 \InsetSpace ~
14963 \InsetSpace ~
14964 \InsetSpace ~
14965 \InsetSpace ~
14966 \InsetSpace ~
14967 \InsetSpace ~
14968 \InsetSpace ~
14969 \InsetSpace ~
14970 jz __sdcc_init_data
14971 \newline
14972 \InsetSpace ~
14973 \InsetSpace ~
14974 \InsetSpace ~
14975 \InsetSpace ~
14976 \InsetSpace ~
14977 \InsetSpace ~
14978 \InsetSpace ~
14979 \InsetSpace ~
14980 ljmp
14981  __sdcc_program_startup
14982 \newline
14983 __sdcc_init_data:
14984 \end_layout
14985
14986 \begin_layout Verse
14987
14988 \family typewriter
14989 \series bold
14990 \size footnotesize
14991 (crtxinit.asm)
14992 \end_layout
14993
14994 \begin_layout Verse
14995
14996 \family typewriter
14997 \size footnotesize
14998 \InsetSpace ~
14999 \InsetSpace ~
15000 \InsetSpace ~
15001 \InsetSpace ~
15002 \InsetSpace ~
15003 \InsetSpace ~
15004 \InsetSpace ~
15005 \InsetSpace ~
15006 .area GSINIT3 (CODE)
15007 \newline
15008 __mcs51_genXINIT::
15009 \newline
15010 \InsetSpace ~
15011 \InsetSpace ~
15012 \InsetSpace ~
15013 \InsetSpace ~
15014 \InsetSpace ~
15015 \InsetSpace ~
15016 \InsetSpace ~
15017 \InsetSpace ~
15018 mov r1,#l_XINIT
15019 \newline
15020 \InsetSpace ~
15021 \InsetSpace ~
15022 \InsetSpace ~
15023 \InsetSpace ~
15024 \InsetSpace ~
15025 \InsetSpace ~
15026 \InsetSpace ~
15027 \InsetSpace ~
15028 mov a,r1
15029 \newline
15030 \InsetSpace ~
15031 \InsetSpace ~
15032 \InsetSpace ~
15033 \InsetSpace ~
15034 \InsetSpace ~
15035 \InsetSpace ~
15036 \InsetSpace ~
15037 \InsetSpace ~
15038 orl a,#(l_XINIT
15039  >> 8)
15040 \newline
15041 \InsetSpace ~
15042 \InsetSpace ~
15043 \InsetSpace ~
15044 \InsetSpace ~
15045 \InsetSpace ~
15046 \InsetSpace ~
15047 \InsetSpace ~
15048 \InsetSpace ~
15049 jz 00003$
15050 \newline
15051 \InsetSpace ~
15052 \InsetSpace ~
15053 \InsetSpace ~
15054 \InsetSpace ~
15055 \InsetSpace ~
15056 \InsetSpace ~
15057 \InsetSpace ~
15058 \InsetSpace ~
15059 mov r2,#((l_XINIT+255) >> 8)
15060 \newline
15061 \InsetSpace ~
15062 \InsetSpace ~
15063 \InsetSpace ~
15064 \InsetSpace ~
15065 \InsetSpace ~
15066 \InsetSpace ~
15067 \InsetSpace ~
15068 \InsetSpace ~
15069 mov dptr,#s_XINIT
15070 \newline
15071 \InsetSpace ~
15072 \InsetSpace ~
15073 \InsetSpace ~
15074 \InsetSpace ~
15075 \InsetSpace ~
15076 \InsetSpace ~
15077 \InsetSpace ~
15078 \InsetSpace ~
15079 mov r0,#s_XISEG
15080 \newline
15081 \InsetSpace ~
15082 \InsetSpace ~
15083 \InsetSpace ~
15084 \InsetSpace ~
15085 \InsetSpace ~
15086 \InsetSpace ~
15087 \InsetSpace ~
15088 \InsetSpace ~
15089 mov
15090  __XPAGE,#(s_XISEG >> 8)
15091 \newline
15092 00001$:\InsetSpace ~
15093 clr a
15094 \newline
15095 \InsetSpace ~
15096 \InsetSpace ~
15097 \InsetSpace ~
15098 \InsetSpace ~
15099 \InsetSpace ~
15100 \InsetSpace ~
15101 \InsetSpace ~
15102 \InsetSpace ~
15103 movc a,@a+dptr
15104 \newline
15105 \InsetSpace ~
15106 \InsetSpace ~
15107 \InsetSpace ~
15108 \InsetSpace ~
15109 \InsetSpace ~
15110 \InsetSpace ~
15111 \InsetSpace ~
15112 \InsetSpace ~
15113 movx @r0,a
15114 \newline
15115 \InsetSpace ~
15116 \InsetSpace ~
15117 \InsetSpace ~
15118 \InsetSpace ~
15119 \InsetSpace ~
15120 \InsetSpace ~
15121 \InsetSpace ~
15122 \InsetSpace ~
15123 inc dptr
15124 \newline
15125 \InsetSpace ~
15126 \InsetSpace ~
15127 \InsetSpace ~
15128 \InsetSpace ~
15129 \InsetSpace ~
15130 \InsetSpace ~
15131 \InsetSpace ~
15132 \InsetSpace ~
15133 inc
15134  r0
15135 \newline
15136 \InsetSpace ~
15137 \InsetSpace ~
15138 \InsetSpace ~
15139 \InsetSpace ~
15140 \InsetSpace ~
15141 \InsetSpace ~
15142 \InsetSpace ~
15143 \InsetSpace ~
15144 cjne r0,#0,00002$
15145 \newline
15146 \InsetSpace ~
15147 \InsetSpace ~
15148 \InsetSpace ~
15149 \InsetSpace ~
15150 \InsetSpace ~
15151 \InsetSpace ~
15152 \InsetSpace ~
15153 \InsetSpace ~
15154 inc __XPAGE
15155 \newline
15156 00002$:\InsetSpace ~
15157 djnz r1,00001$
15158 \newline
15159 \InsetSpace ~
15160 \InsetSpace ~
15161 \InsetSpace ~
15162 \InsetSpace ~
15163 \InsetSpace ~
15164 \InsetSpace ~
15165 \InsetSpace ~
15166 \InsetSpace ~
15167 djnz r2,00001$
15168 \newline
15169 \InsetSpace ~
15170 \InsetSpace ~
15171 \InsetSpace ~
15172 \InsetSpace ~
15173 \InsetSpace ~
15174 \InsetSpace ~
15175 \InsetSpace ~
15176 \InsetSpace ~
15177 mov __XPAGE,#0
15178 xFF
15179 \newline
15180 00003$:
15181 \end_layout
15182
15183 \begin_layout Verse
15184
15185 \family typewriter
15186 \series bold
15187 \size footnotesize
15188 (crtclear.asm)
15189 \end_layout
15190
15191 \begin_layout Verse
15192
15193 \family typewriter
15194 \size footnotesize
15195 \InsetSpace ~
15196 \InsetSpace ~
15197 \InsetSpace ~
15198 \InsetSpace ~
15199 \InsetSpace ~
15200 \InsetSpace ~
15201 \InsetSpace ~
15202 \InsetSpace ~
15203 .area GSINIT4 (CODE)
15204 \newline
15205 __mcs51_genRAMCLEAR::
15206 \newline
15207 \InsetSpace ~
15208 \InsetSpace ~
15209 \InsetSpace ~
15210 \InsetSpace ~
15211 \InsetSpace ~
15212 \InsetSpace ~
15213 \InsetSpace ~
15214 \InsetSpace ~
15215 clr a
15216 \newline
15217 \InsetSpace ~
15218 \InsetSpace ~
15219 \InsetSpace ~
15220 \InsetSpace ~
15221 \InsetSpace ~
15222 \InsetSpace ~
15223 \InsetSpace ~
15224 \InsetSpace ~
15225 mov r0,#(l_IRAM-1)
15226 \newline
15227 00004$:\InsetSpace ~
15228 mov
15229  @r0,a
15230 \newline
15231 \InsetSpace ~
15232 \InsetSpace ~
15233 \InsetSpace ~
15234 \InsetSpace ~
15235 \InsetSpace ~
15236 \InsetSpace ~
15237 \InsetSpace ~
15238 \InsetSpace ~
15239 djnz r0,00004$
15240 \newline
15241 ; _mcs51_genRAMCLEAR() end
15242 \end_layout
15243
15244 \begin_layout Verse
15245
15246 \family typewriter
15247 \series bold
15248 \size footnotesize
15249 (crtxclear.asm)
15250 \end_layout
15251
15252 \begin_layout Verse
15253
15254 \family typewriter
15255 \size footnotesize
15256 \InsetSpace ~
15257 \InsetSpace ~
15258 \InsetSpace ~
15259 \InsetSpace ~
15260 \InsetSpace ~
15261 \InsetSpace ~
15262 \InsetSpace ~
15263 \InsetSpace ~
15264 .area GSINIT4 (CODE)
15265 \newline
15266 __mcs51_genXRAMCLEAR::
15267 \newline
15268 \InsetSpace ~
15269 \InsetSpace ~
15270 \InsetSpace ~
15271 \InsetSpace ~
15272 \InsetSpace ~
15273 \InsetSpace ~
15274 \InsetSpace ~
15275 \InsetSpace ~
15276 mov r0,#l_PSEG
15277 \newline
15278 \InsetSpace ~
15279 \InsetSpace ~
15280 \InsetSpace ~
15281 \InsetSpace ~
15282 \InsetSpace ~
15283 \InsetSpace ~
15284 \InsetSpace ~
15285 \InsetSpace ~
15286 mov a,r0
15287 \newline
15288 \InsetSpace ~
15289 \InsetSpace ~
15290 \InsetSpace ~
15291 \InsetSpace ~
15292 \InsetSpace ~
15293 \InsetSpace ~
15294 \InsetSpace ~
15295 \InsetSpace ~
15296 jz 00006$
15297 \newline
15298 \InsetSpace ~
15299 \InsetSpace ~
15300 \InsetSpace ~
15301 \InsetSpace ~
15302 \InsetSpace ~
15303 \InsetSpace ~
15304 \InsetSpace ~
15305 \InsetSpace ~
15306 mov
15307  r1,#s_PSEG
15308 \newline
15309 \InsetSpace ~
15310 \InsetSpace ~
15311 \InsetSpace ~
15312 \InsetSpace ~
15313 \InsetSpace ~
15314 \InsetSpace ~
15315 \InsetSpace ~
15316 \InsetSpace ~
15317 mov __XPAGE,#(s_PSEG >> 8)
15318 \newline
15319 \InsetSpace ~
15320 \InsetSpace ~
15321 \InsetSpace ~
15322 \InsetSpace ~
15323 \InsetSpace ~
15324 \InsetSpace ~
15325 \InsetSpace ~
15326 \InsetSpace ~
15327 clr a
15328 \newline
15329 00005$:\InsetSpace ~
15330 movx @r1,a
15331 \newline
15332 \InsetSpace ~
15333 \InsetSpace ~
15334 \InsetSpace ~
15335 \InsetSpace ~
15336 \InsetSpace ~
15337 \InsetSpace ~
15338 \InsetSpace ~
15339 \InsetSpace ~
15340 inc r1
15341 \newline
15342 \InsetSpace ~
15343 \InsetSpace ~
15344 \InsetSpace ~
15345 \InsetSpace ~
15346 \InsetSpace ~
15347 \InsetSpace ~
15348 \InsetSpace ~
15349 \InsetSpace ~
15350 djnz r0,00005$
15351 \newline
15352 0
15353 0006$:
15354 \newline
15355 \InsetSpace ~
15356 \InsetSpace ~
15357 \InsetSpace ~
15358 \InsetSpace ~
15359 \InsetSpace ~
15360 \InsetSpace ~
15361 \InsetSpace ~
15362 \InsetSpace ~
15363 mov r0,#l_XSEG
15364 \newline
15365 \InsetSpace ~
15366 \InsetSpace ~
15367 \InsetSpace ~
15368 \InsetSpace ~
15369 \InsetSpace ~
15370 \InsetSpace ~
15371 \InsetSpace ~
15372 \InsetSpace ~
15373 mov a,r0
15374 \newline
15375 \InsetSpace ~
15376 \InsetSpace ~
15377 \InsetSpace ~
15378 \InsetSpace ~
15379 \InsetSpace ~
15380 \InsetSpace ~
15381 \InsetSpace ~
15382 \InsetSpace ~
15383 orl a,#(l_XSEG >> 8)
15384 \newline
15385 \InsetSpace ~
15386 \InsetSpace ~
15387 \InsetSpace ~
15388 \InsetSpace ~
15389 \InsetSpace ~
15390 \InsetSpace ~
15391 \InsetSpace ~
15392 \InsetSpace ~
15393 jz 00008$
15394 \newline
15395 \InsetSpace ~
15396 \InsetSpace ~
15397 \InsetSpace ~
15398 \InsetSpace ~
15399 \InsetSpace ~
15400 \InsetSpace ~
15401 \InsetSpace ~
15402 \InsetSpace ~
15403 mov r1,#((l_XSEG
15404  + 255) >> 8)
15405 \newline
15406 \InsetSpace ~
15407 \InsetSpace ~
15408 \InsetSpace ~
15409 \InsetSpace ~
15410 \InsetSpace ~
15411 \InsetSpace ~
15412 \InsetSpace ~
15413 \InsetSpace ~
15414 mov dptr,#s_XSEG
15415 \newline
15416 \InsetSpace ~
15417 \InsetSpace ~
15418 \InsetSpace ~
15419 \InsetSpace ~
15420 \InsetSpace ~
15421 \InsetSpace ~
15422 \InsetSpace ~
15423 \InsetSpace ~
15424 clr a
15425 \newline
15426 00007$:\InsetSpace ~
15427 movx @dptr,a
15428 \newline
15429 \InsetSpace ~
15430 \InsetSpace ~
15431 \InsetSpace ~
15432 \InsetSpace ~
15433 \InsetSpace ~
15434 \InsetSpace ~
15435 \InsetSpace ~
15436 \InsetSpace ~
15437 inc dptr
15438 \newline
15439 \InsetSpace ~
15440 \InsetSpace ~
15441 \InsetSpace ~
15442 \InsetSpace ~
15443 \InsetSpace ~
15444 \InsetSpace ~
15445 \InsetSpace ~
15446 \InsetSpace ~
15447 djnz r0,00007$
15448 \newline
15449 \InsetSpace ~
15450 \InsetSpace ~
15451 \InsetSpace ~
15452 \InsetSpace ~
15453 \InsetSpace ~
15454 \InsetSpace ~
15455 \InsetSpace ~
15456 \InsetSpace ~
15457 djnz
15458  r1,00007$
15459 \newline
15460 00008$:
15461 \end_layout
15462
15463 \begin_layout Verse
15464
15465 \family typewriter
15466 \series bold
15467 \size footnotesize
15468 (crtxstack.asm)
15469 \end_layout
15470
15471 \begin_layout Verse
15472
15473 \family typewriter
15474 \size footnotesize
15475 \InsetSpace ~
15476 \InsetSpace ~
15477 \InsetSpace ~
15478 \InsetSpace ~
15479 \InsetSpace ~
15480 \InsetSpace ~
15481 \InsetSpace ~
15482 \InsetSpace ~
15483 .area GSINIT5 (CODE)
15484 \newline
15485 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
15486  modifies __XPAGE
15487 \newline
15488 ; and __mcs51_genRAMCLEAR modifies _spx.
15489 \newline
15490 \InsetSpace ~
15491 \InsetSpace ~
15492 \InsetSpace ~
15493 \InsetSpace ~
15494 \InsetSpace ~
15495 \InsetSpace ~
15496 \InsetSpace ~
15497 \InsetSpace ~
15498 mov __XPAGE,#(__start__x
15499 stack >> 8)
15500 \newline
15501 \InsetSpace ~
15502 \InsetSpace ~
15503 \InsetSpace ~
15504 \InsetSpace ~
15505 \InsetSpace ~
15506 \InsetSpace ~
15507 \InsetSpace ~
15508 \InsetSpace ~
15509 mov _spx,#__start__xstack
15510 \end_layout
15511
15512 \begin_layout Verse
15513
15514 \family typewriter
15515 \series bold
15516 \size footnotesize
15517 (application modules)
15518 \end_layout
15519
15520 \begin_layout Verse
15521
15522 \family typewriter
15523 \size footnotesize
15524 \InsetSpace ~
15525 \InsetSpace ~
15526 \InsetSpace ~
15527 \InsetSpace ~
15528 \InsetSpace ~
15529 \InsetSpace ~
15530 \InsetSpace ~
15531 \InsetSpace ~
15532 .area GSINIT (CODE)
15533 \end_layout
15534
15535 \begin_layout Verse
15536
15537 \family typewriter
15538 \series bold
15539 \size footnotesize
15540 (main.asm)
15541 \end_layout
15542
15543 \begin_layout Verse
15544
15545 \family typewriter
15546 \size footnotesize
15547 \InsetSpace ~
15548 \InsetSpace ~
15549 \InsetSpace ~
15550 \InsetSpace ~
15551 \InsetSpace ~
15552 \InsetSpace ~
15553 \InsetSpace ~
15554 \InsetSpace ~
15555 .area GSFINAL (CODE)
15556 \newline
15557 \InsetSpace ~
15558 \InsetSpace ~
15559 \InsetSpace ~
15560 \InsetSpace ~
15561 \InsetSpace ~
15562 \InsetSpace ~
15563 \InsetSpace ~
15564 \InsetSpace ~
15565 ljmp __sdcc_program_startup
15566 \newline
15567 ;---------------------------------
15568 -----------------------
15569 \newline
15570 ; Home
15571 \newline
15572 ;--------------------------------------------------
15573 ------
15574 \newline
15575 \InsetSpace ~
15576 \InsetSpace ~
15577 \InsetSpace ~
15578 \InsetSpace ~
15579 \InsetSpace ~
15580 \InsetSpace ~
15581 \InsetSpace ~
15582 \InsetSpace ~
15583 .area HOME (CODE)
15584 \newline
15585 \InsetSpace ~
15586 \InsetSpace ~
15587 \InsetSpace ~
15588 \InsetSpace ~
15589 \InsetSpace ~
15590 \InsetSpace ~
15591 \InsetSpace ~
15592 \InsetSpace ~
15593 .area CSEG (CODE)
15594 \newline
15595 __sdcc_program_startup:
15596 \newline
15597 \InsetSpace ~
15598 \InsetSpace ~
15599 \InsetSpace ~
15600 \InsetSpace ~
15601 \InsetSpace ~
15602 \InsetSpace ~
15603 \InsetSpace ~
15604 \InsetSpace ~
15605 lcall _main
15606 \newline
15607 ;
15608  return from main will lock up
15609 \newline
15610 \InsetSpace ~
15611 \InsetSpace ~
15612 \InsetSpace ~
15613 \InsetSpace ~
15614 \InsetSpace ~
15615 \InsetSpace ~
15616 \InsetSpace ~
15617 \InsetSpace ~
15618 sjmp .
15619 \end_layout
15620
15621 \begin_layout Standard
15622 One of these modules (crtstart.asm) contains a call to the C routine 
15623 \emph on
15624 _sdcc_external_startup()
15625 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
15626
15627 \end_inset
15628
15629
15630 \series bold
15631 \emph default
15632  
15633 \series default
15634 at the start of the CODE area.
15635  This routine is also in the runtime library
15636 \begin_inset LatexCommand \index{Runtime library}
15637
15638 \end_inset
15639
15640  and returns 0 by default.
15641  If this routine returns a non-zero value, the static & global variable
15642  initialization will be skipped and the function main will be invoked.
15643  Otherwise static & global variables will be initialized before the function
15644  main is invoked.
15645  You could add an 
15646 \emph on
15647 _sdcc_external_startup()
15648 \emph default
15649  routine to your program to override the default if you need to setup hardware
15650  or perform some other critical operation prior to static & global variable
15651  initialization
15652 \begin_inset LatexCommand \index{Variable initialization}
15653
15654 \end_inset
15655
15656 .
15657  On some mcs51 variants xdata
15658 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
15659
15660 \end_inset
15661
15662  memory has to be explicitly enabled before it can be accessed or if the
15663  watchdog
15664 \begin_inset LatexCommand \index{watchdog}
15665
15666 \end_inset
15667
15668  needs to be disabled, this is the place to do it.
15669  The startup code clears all internal data memory, 256 bytes by default,
15670  but from 0 to n-1 if 
15671 \emph on
15672 -
15673 \begin_inset ERT
15674 status collapsed
15675
15676 \begin_layout Standard
15677
15678
15679 \backslash
15680 /
15681 \end_layout
15682
15683 \end_inset
15684
15685 -iram-size
15686 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
15687
15688 \end_inset
15689
15690 n
15691 \emph default
15692  is used.
15693  (recommended for Chipcon CC1010).
15694 \end_layout
15695
15696 \begin_layout Standard
15697 See also the compiler options 
15698 \emph on
15699 -
15700 \begin_inset ERT
15701 status collapsed
15702
15703 \begin_layout Standard
15704
15705
15706 \backslash
15707 /
15708 \end_layout
15709
15710 \end_inset
15711
15712 -no-xinit
15713 \emph default
15714 -
15715 \emph on
15716 opt
15717 \emph default
15718
15719 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
15720
15721 \end_inset
15722
15723
15724 \emph on
15725 -
15726 \begin_inset ERT
15727 status collapsed
15728
15729 \begin_layout Standard
15730
15731
15732 \backslash
15733 /
15734 \end_layout
15735
15736 \end_inset
15737
15738 -main-return
15739 \emph default
15740
15741 \begin_inset LatexCommand \index{-\/-main-return}
15742
15743 \end_inset
15744
15745  and section 
15746 \begin_inset LatexCommand \ref{sub:MCS51-variants}
15747
15748 \end_inset
15749
15750  about MCS51-variants.
15751 \begin_inset VSpace bigskip
15752 \end_inset
15753
15754
15755 \end_layout
15756
15757 \begin_layout Subsection
15758 HC08 Startup Code
15759 \end_layout
15760
15761 \begin_layout Standard
15762 The HC08
15763 \begin_inset LatexCommand \index{HC08}
15764
15765 \end_inset
15766
15767  startup code follows the same scheme as the MCS51 startup code.
15768 \begin_inset VSpace bigskip
15769 \end_inset
15770
15771
15772 \end_layout
15773
15774 \begin_layout Subsection
15775 Z80 Startup Code
15776 \end_layout
15777
15778 \begin_layout Standard
15779 On the Z80
15780 \begin_inset LatexCommand \index{Z80}
15781
15782 \end_inset
15783
15784  the startup code is inserted by linking with crt0.o which is generated from
15785  sdcc/device/lib/z80/crt0.s.
15786  If you need a different startup code you can use the compiler option 
15787 \emph on
15788 -
15789 \series bold
15790 \emph default
15791
15792 \begin_inset ERT
15793 status collapsed
15794
15795 \begin_layout Standard
15796
15797
15798 \backslash
15799 /
15800 \end_layout
15801
15802 \end_inset
15803
15804
15805 \series default
15806 \emph on
15807 -no-std-crt0
15808 \emph default
15809
15810 \begin_inset LatexCommand \index{-\/-no-std-crt0}
15811
15812 \end_inset
15813
15814  and provide your own crt0.o.
15815  
15816 \begin_inset VSpace bigskip
15817 \end_inset
15818
15819
15820 \end_layout
15821
15822 \begin_layout Section
15823 Inline Assembler Code
15824 \begin_inset LatexCommand \index{Assembler routines}
15825
15826 \end_inset
15827
15828
15829 \end_layout
15830
15831 \begin_layout Subsection
15832 A Step by Step Introduction
15833 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
15834
15835 \end_inset
15836
15837
15838 \end_layout
15839
15840 \begin_layout Standard
15841 Starting from a small snippet of c-code this example shows for the MCS51
15842  how to use inline assembly, access variables, a function parameter and
15843  an array in xdata memory.
15844  The example uses an MCS51 here but is easily adapted for other architectures.
15845  This is a buffer routine which should be optimized:
15846 \end_layout
15847
15848 \begin_layout Verse
15849
15850 \family typewriter
15851 \size footnotesize
15852 unsigned char __far
15853 \begin_inset LatexCommand \index{far (storage class)}
15854
15855 \end_inset
15856
15857
15858 \begin_inset LatexCommand \index{\_\_far (storage class)}
15859
15860 \end_inset
15861
15862  __at
15863 \begin_inset LatexCommand \index{at}
15864
15865 \end_inset
15866
15867
15868 \begin_inset LatexCommand \index{\_\_at}
15869
15870 \end_inset
15871
15872 (0x7f00) buf[0x100];
15873 \begin_inset LatexCommand \index{Aligned array}
15874
15875 \end_inset
15876
15877
15878 \newline
15879 unsigned char head, tail;\InsetSpace ~
15880 \InsetSpace ~
15881 \InsetSpace ~
15882 \InsetSpace ~
15883 \InsetSpace ~
15884 \InsetSpace ~
15885 \InsetSpace ~
15886 \InsetSpace ~
15887 \InsetSpace ~
15888 \InsetSpace ~
15889 \InsetSpace ~
15890 \InsetSpace ~
15891 \InsetSpace ~
15892 \InsetSpace ~
15893 \InsetSpace ~
15894 \InsetSpace ~
15895 \InsetSpace ~
15896 /* if interrupts
15897 \begin_inset LatexCommand \index{interrupt}
15898
15899 \end_inset
15900
15901  are involved see
15902 \newline
15903 \InsetSpace ~
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 section 
15949 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
15950
15951 \end_inset
15952
15953  about
15954 \series bold
15955  volatile
15956 \series default
15957  */
15958 \newline
15959
15960 \newline
15961 void to_buffer( unsigned char c ) 
15962 \newline
15963 {
15964 \newline
15965 \InsetSpace ~
15966 \InsetSpace ~
15967 \InsetSpace ~
15968 \InsetSpace ~
15969 if( head != (unsigned char)(tail-1)
15970  )\InsetSpace ~
15971 /* cast 
15972 \series bold
15973 needed
15974 \series default
15975  to avoid promotion
15976 \begin_inset LatexCommand \index{promotion to signed int}
15977
15978 \end_inset
15979
15980
15981 \begin_inset LatexCommand \index{type promotion}
15982
15983 \end_inset
15984
15985  to integer */
15986 \begin_inset Marginal
15987 status collapsed
15988
15989 \begin_layout Standard
15990
15991 \series bold
15992 \InsetSpace ~
15993 !
15994 \end_layout
15995
15996 \end_inset
15997
15998
15999 \newline
16000 \InsetSpace ~
16001 \InsetSpace ~
16002 \InsetSpace ~
16003 \InsetSpace ~
16004 \InsetSpace ~
16005 \InsetSpace ~
16006 \InsetSpace ~
16007 \InsetSpace ~
16008 buf[ head++ ] = c;\InsetSpace ~
16009 \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 /* access to a 256 byte aligned array */
16025 \newline
16026
16027 \end_layout
16028
16029 \begin_layout Standard
16030 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
16031  then a corresponding buffer.asm file is generated.
16032  We define a new function 
16033 \family typewriter
16034 to_buffer_asm()
16035 \family default
16036  in file buffer.c in which we cut and paste the generated code, removing
16037  unwanted comments and some ':'.
16038  Then add 
16039 \begin_inset Quotes sld
16040 \end_inset
16041
16042
16043 \series bold
16044 _asm
16045 \series default
16046
16047 \begin_inset Quotes srd
16048 \end_inset
16049
16050  and 
16051 \begin_inset Quotes sld
16052 \end_inset
16053
16054
16055 \series bold
16056 _endasm;
16057 \series default
16058
16059 \begin_inset Quotes srd
16060 \end_inset
16061
16062
16063 \begin_inset Foot
16064 status open
16065
16066 \begin_layout Standard
16067 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
16068  and for C-99 compatibility, the double-underscore form (__asm and __endasm)
16069  has to be used.
16070  The latter is also used in the library functions.
16071 \end_layout
16072
16073 \end_inset
16074
16075  to the beginning and the end of the function body:
16076 \end_layout
16077
16078 \begin_layout Verse
16079
16080 \family typewriter
16081 \size footnotesize
16082 /* With a cut and paste from the .asm file, we have something to start with.
16083 \newline
16084 \InsetSpace ~
16085 \InsetSpace ~
16086 \InsetSpace ~
16087 The
16088  function is not yet OK! (registers aren't saved) */ 
16089 \newline
16090 void to_buffer_asm(
16091  unsigned char c ) 
16092 \newline
16093
16094 \newline
16095 \InsetSpace ~
16096 \InsetSpace ~
16097 \InsetSpace ~
16098 \InsetSpace ~
16099 _asm
16100 \begin_inset LatexCommand \index{\_asm}
16101
16102 \end_inset
16103
16104
16105 \begin_inset LatexCommand \index{\_\_asm}
16106
16107 \end_inset
16108
16109
16110 \newline
16111 \InsetSpace ~
16112 \InsetSpace ~
16113 \InsetSpace ~
16114 \InsetSpace ~
16115 mov\InsetSpace ~
16116 \InsetSpace ~
16117 r2,dpl 
16118 \newline
16119 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
16120 /* cast 
16121 \series bold
16122 needed
16123 \series default
16124  to avoid promotion
16125 \begin_inset LatexCommand \index{promotion to signed int}
16126
16127 \end_inset
16128
16129
16130 \begin_inset LatexCommand \index{type promotion}
16131
16132 \end_inset
16133
16134  to integer */
16135 \newline
16136 \InsetSpace ~
16137 \InsetSpace ~
16138 \InsetSpace ~
16139 \InsetSpace ~
16140 mov\InsetSpace ~
16141 \InsetSpace ~
16142 a,_tail 
16143 \newline
16144 \InsetSpace ~
16145 \InsetSpace ~
16146 \InsetSpace ~
16147 \InsetSpace ~
16148 dec\InsetSpace ~
16149 \InsetSpace ~
16150
16151 \newline
16152 \InsetSpace ~
16153 \InsetSpace ~
16154 \InsetSpace ~
16155 \InsetSpace ~
16156 mov\InsetSpace ~
16157 \InsetSpace ~
16158 r3,a 
16159 \newline
16160 \InsetSpace ~
16161 \InsetSpace ~
16162 \InsetSpace ~
16163 \InsetSpace ~
16164 mov\InsetSpace ~
16165 \InsetSpace ~
16166 a,_head 
16167 \newline
16168 \InsetSpace ~
16169 \InsetSpace ~
16170 \InsetSpace ~
16171 \InsetSpace ~
16172 cjne a,ar3,00106$ 
16173 \newline
16174 \InsetSpace ~
16175 \InsetSpace ~
16176 \InsetSpace ~
16177 \InsetSpace ~
16178 ret
16179 \newline
16180 00106$:
16181  
16182 \newline
16183 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
16184 \begin_inset LatexCommand \index{Aligned array}
16185
16186 \end_inset
16187
16188
16189 \newline
16190 \InsetSpace ~
16191 \InsetSpace ~
16192 \InsetSpace ~
16193 \InsetSpace ~
16194 mov\InsetSpace ~
16195 \InsetSpace ~
16196 r3,_head 
16197 \newline
16198 \InsetSpace ~
16199 \InsetSpace ~
16200 \InsetSpace ~
16201 \InsetSpace ~
16202 inc\InsetSpace ~
16203 \InsetSpace ~
16204 _head 
16205 \newline
16206 \InsetSpace ~
16207 \InsetSpace ~
16208 \InsetSpace ~
16209 \InsetSpace ~
16210 mov\InsetSpace ~
16211 \InsetSpace ~
16212 dpl,r3 
16213 \newline
16214 \InsetSpace ~
16215 \InsetSpace ~
16216 \InsetSpace ~
16217 \InsetSpace ~
16218 mov\InsetSpace ~
16219 \InsetSpace ~
16220 dph,#(_buf >> 8) 
16221 \newline
16222 \InsetSpace ~
16223 \InsetSpace ~
16224 \InsetSpace ~
16225 \InsetSpace ~
16226 mov\InsetSpace ~
16227 \InsetSpace ~
16228 a,r2 
16229 \newline
16230 \InsetSpace ~
16231 \InsetSpace ~
16232 \InsetSpace ~
16233 \InsetSpace ~
16234 movx @dptr,a
16235  
16236 \newline
16237 00103$: 
16238 \newline
16239 \InsetSpace ~
16240 \InsetSpace ~
16241 \InsetSpace ~
16242 \InsetSpace ~
16243 ret
16244 \newline
16245 \InsetSpace ~
16246 \InsetSpace ~
16247 \InsetSpace ~
16248 \InsetSpace ~
16249 _endasm
16250 \begin_inset LatexCommand \index{\_endasm}
16251
16252 \end_inset
16253
16254
16255 \begin_inset LatexCommand \index{\_\_endasm}
16256
16257 \end_inset
16258
16259 ;
16260 \newline
16261
16262 \end_layout
16263
16264 \begin_layout Standard
16265 The new file buffer.c should compile with only one warning about the unreferenced
16266  function argument 'c'.
16267  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
16268  (1) and finally have:
16269 \end_layout
16270
16271 \begin_layout Verse
16272
16273 \family typewriter
16274 \size footnotesize
16275 unsigned char __far __at(0x7f00) buf[0x100];
16276 \newline
16277 unsigned char head, tail;
16278 \newline
16279 #define
16280  USE_ASSEMBLY (1)
16281 \newline
16282
16283 \newline
16284 #if !USE_ASSEMBLY
16285 \newline
16286
16287 \newline
16288 void to_buffer( unsigned char c )
16289 \newline
16290 {
16291 \newline
16292 \InsetSpace ~
16293 \InsetSpace ~
16294 \InsetSpace ~
16295 \InsetSpace ~
16296 if(
16297  head != (unsigned char)(tail-1) )
16298 \newline
16299 \InsetSpace ~
16300 \InsetSpace ~
16301 \InsetSpace ~
16302 \InsetSpace ~
16303 \InsetSpace ~
16304 \InsetSpace ~
16305 \InsetSpace ~
16306 \InsetSpace ~
16307 buf[ head++ ] = c;
16308 \newline
16309 }
16310 \newline
16311
16312 \newline
16313 #else
16314 \newline
16315
16316 \newline
16317 void to_buffer(
16318  unsigned char c )
16319 \newline
16320 {
16321 \newline
16322 \InsetSpace ~
16323 \InsetSpace ~
16324 \InsetSpace ~
16325 \InsetSpace ~
16326 c; // to avoid warning: unreferenced function argument
16327 \newline
16328 \InsetSpace ~
16329 \InsetSpace ~
16330 \InsetSpace ~
16331 \InsetSpace ~
16332 _asm
16333 \begin_inset LatexCommand \index{\_asm}
16334
16335 \end_inset
16336
16337
16338 \begin_inset LatexCommand \index{\_\_asm}
16339
16340 \end_inset
16341
16342
16343 \newline
16344 \InsetSpace ~
16345 \InsetSpace ~
16346 \InsetSpace ~
16347 \InsetSpace ~
16348 \InsetSpace ~
16349 \InsetSpace ~
16350 \InsetSpace ~
16351 \InsetSpace ~
16352 ; save used registers here.
16353  
16354 \newline
16355 \InsetSpace ~
16356 \InsetSpace ~
16357 \InsetSpace ~
16358 \InsetSpace ~
16359 \InsetSpace ~
16360 \InsetSpace ~
16361 \InsetSpace ~
16362 \InsetSpace ~
16363 ; If we were still using r2,r3 we would have to push them here.
16364  
16365 \newline
16366 ; if( head != (unsigned char)(tail-1) )
16367 \newline
16368 \InsetSpace ~
16369 \InsetSpace ~
16370 \InsetSpace ~
16371 \InsetSpace ~
16372 \InsetSpace ~
16373 \InsetSpace ~
16374 \InsetSpace ~
16375 \InsetSpace ~
16376 mov\InsetSpace ~
16377  a,_tail
16378 \newline
16379 \InsetSpace ~
16380 \InsetSpace ~
16381 \InsetSpace ~
16382 \InsetSpace ~
16383 \InsetSpace ~
16384 \InsetSpace ~
16385 \InsetSpace ~
16386 \InsetSpace ~
16387 dec\InsetSpace ~
16388  a
16389 \newline
16390 \InsetSpace ~
16391 \InsetSpace ~
16392 \InsetSpace ~
16393 \InsetSpace ~
16394 \InsetSpace ~
16395 \InsetSpace ~
16396 \InsetSpace ~
16397 \InsetSpace ~
16398 xrl\InsetSpace ~
16399  a,_head
16400 \newline
16401 \InsetSpace ~
16402 \InsetSpace ~
16403 \InsetSpace ~
16404 \InsetSpace ~
16405 \InsetSpace ~
16406 \InsetSpace ~
16407 \InsetSpace ~
16408 \InsetSpace ~
16409 ; we
16410  could do an ANL a,#0x0f here to use a smaller buffer (see below)
16411 \newline
16412 \InsetSpace ~
16413 \InsetSpace ~
16414 \InsetSpace ~
16415 \InsetSpace ~
16416 \InsetSpace ~
16417 \InsetSpace ~
16418 \InsetSpace ~
16419 \InsetSpace ~
16420 jz\InsetSpace ~
16421 \InsetSpace ~
16422  t_b_end$
16423 \newline
16424 \InsetSpace ~
16425 \InsetSpace ~
16426 \InsetSpace ~
16427 \InsetSpace ~
16428 \InsetSpace ~
16429 \InsetSpace ~
16430 \InsetSpace ~
16431 \InsetSpace ~
16432 ;
16433 \newline
16434 ;
16435  buf[ head++ ] = c;
16436 \newline
16437 \InsetSpace ~
16438 \InsetSpace ~
16439 \InsetSpace ~
16440 \InsetSpace ~
16441 \InsetSpace ~
16442 \InsetSpace ~
16443 \InsetSpace ~
16444 \InsetSpace ~
16445 mov\InsetSpace ~
16446  a,dpl \InsetSpace ~
16447 \InsetSpace ~
16448 \InsetSpace ~
16449 \InsetSpace ~
16450 \InsetSpace ~
16451 \InsetSpace ~
16452 \InsetSpace ~
16453 ; dpl holds lower byte of function argument
16454 \newline
16455 \InsetSpace ~
16456 \InsetSpace ~
16457 \InsetSpace ~
16458 \InsetSpace ~
16459 \InsetSpace ~
16460 \InsetSpace ~
16461 \InsetSpace ~
16462 \InsetSpace ~
16463 mov\InsetSpace ~
16464
16465  dpl,_head \InsetSpace ~
16466 \InsetSpace ~
16467 \InsetSpace ~
16468 ; buf is 0x100 byte aligned so head can be used directly
16469 \newline
16470 \InsetSpace ~
16471 \InsetSpace ~
16472 \InsetSpace ~
16473 \InsetSpace ~
16474 \InsetSpace ~
16475 \InsetSpace ~
16476 \InsetSpace ~
16477 \InsetSpace ~
16478 mov\InsetSpace ~
16479  dph,#(_bu
16480 f>>8)
16481 \newline
16482 \InsetSpace ~
16483 \InsetSpace ~
16484 \InsetSpace ~
16485 \InsetSpace ~
16486 \InsetSpace ~
16487 \InsetSpace ~
16488 \InsetSpace ~
16489 \InsetSpace ~
16490 movx @dptr,a
16491 \newline
16492 \InsetSpace ~
16493 \InsetSpace ~
16494 \InsetSpace ~
16495 \InsetSpace ~
16496 \InsetSpace ~
16497 \InsetSpace ~
16498 \InsetSpace ~
16499 \InsetSpace ~
16500 inc \InsetSpace ~
16501 _head
16502 \newline
16503 \InsetSpace ~
16504 \InsetSpace ~
16505 \InsetSpace ~
16506 \InsetSpace ~
16507 \InsetSpace ~
16508 \InsetSpace ~
16509 \InsetSpace ~
16510 \InsetSpace ~
16511 ; we could do an ANL _head,#0x0f here to use a
16512  smaller buffer (see above)
16513 \newline
16514 t_b_end$:
16515 \newline
16516 \InsetSpace ~
16517 \InsetSpace ~
16518 \InsetSpace ~
16519 \InsetSpace ~
16520 \InsetSpace ~
16521 \InsetSpace ~
16522 \InsetSpace ~
16523 \InsetSpace ~
16524 ; restore used registers here 
16525 \newline
16526 \InsetSpace ~
16527 \InsetSpace ~
16528 \InsetSpace ~
16529 \InsetSpace ~
16530 _endasm
16531 \begin_inset LatexCommand \index{\_endasm}
16532
16533 \end_inset
16534
16535
16536 \begin_inset LatexCommand \index{\_\_endasm}
16537
16538 \end_inset
16539
16540 ;
16541 \newline
16542 }
16543 \newline
16544 #endif
16545 \end_layout
16546
16547 \begin_layout Standard
16548 The inline assembler code can contain any valid code understood by the assembler
16549 , this includes any assembler directives and comment lines.
16550  The assembler does not like some characters like ':' or ''' in comments.
16551  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
16552 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
16553
16554 \end_inset
16555
16556
16557 \begin_inset LatexCommand \index{Assembler documentation}
16558
16559 \end_inset
16560
16561  or online at 
16562 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
16563
16564 \end_inset
16565
16566 \InsetSpace ~
16567 .
16568 \end_layout
16569
16570 \begin_layout Standard
16571 The compiler does not do any validation of the code within the 
16572 \family typewriter
16573 _asm
16574 \begin_inset LatexCommand \index{\_asm}
16575
16576 \end_inset
16577
16578
16579 \begin_inset LatexCommand \index{\_\_asm}
16580
16581 \end_inset
16582
16583  ...
16584  _endasm
16585 \size footnotesize
16586
16587 \begin_inset LatexCommand \index{\_endasm}
16588
16589 \end_inset
16590
16591
16592 \begin_inset LatexCommand \index{\_\_endasm}
16593
16594 \end_inset
16595
16596
16597 \size default
16598 ;
16599 \family default
16600  keyword pair.
16601  Specifically it will not know which registers are used and thus register
16602  pushing/popping
16603 \begin_inset LatexCommand \index{push/pop}
16604
16605 \end_inset
16606
16607  has to be done manually.
16608  
16609 \end_layout
16610
16611 \begin_layout Standard
16612 It is recommended that each assembly instruction (including labels) be placed
16613  in a separate line (as the example shows).
16614  When the -
16615 \begin_inset ERT
16616 status collapsed
16617
16618 \begin_layout Standard
16619
16620
16621 \backslash
16622 /
16623 \end_layout
16624
16625 \end_inset
16626
16627 -
16628 \emph on
16629 peep-asm
16630 \begin_inset LatexCommand \index{-\/-peep-asm}
16631
16632 \end_inset
16633
16634
16635 \emph default
16636  command line option is used, the inline assembler code will be passed through
16637  the peephole optimizer
16638 \begin_inset LatexCommand \index{Peephole optimizer}
16639
16640 \end_inset
16641
16642 .
16643  There are only a few (if any) cases where this option makes sense, it might
16644  cause some unexpected changes in the inline assembler code.
16645  Please go through the peephole optimizer rules defined in file 
16646 \emph on
16647 SDCCpeeph.def
16648 \emph default
16649  before using this option.
16650 \end_layout
16651
16652 \begin_layout Subsection
16653 Naked Functions
16654 \begin_inset LatexCommand \label{sub:Naked-Functions}
16655
16656 \end_inset
16657
16658
16659 \begin_inset LatexCommand \index{Naked functions}
16660
16661 \end_inset
16662
16663
16664 \end_layout
16665
16666 \begin_layout Standard
16667 A special keyword may be associated with a function declaring it as 
16668 \emph on
16669 _naked
16670 \begin_inset LatexCommand \index{\_naked}
16671
16672 \end_inset
16673
16674
16675 \begin_inset LatexCommand \index{\_\_naked}
16676
16677 \end_inset
16678
16679 .
16680  
16681 \emph default
16682 The 
16683 \emph on
16684 _naked
16685 \emph default
16686  function modifier attribute prevents the compiler from generating prologue
16687 \begin_inset LatexCommand \index{function prologue}
16688
16689 \end_inset
16690
16691  and epilogue
16692 \begin_inset LatexCommand \index{function epilogue}
16693
16694 \end_inset
16695
16696  code for that function.
16697  This means that the user is entirely responsible for such things as saving
16698  any registers that may need to be preserved, selecting the proper register
16699  bank, generating the 
16700 \emph on
16701 return
16702 \emph default
16703  instruction at the end, etc.
16704  Practically, this means that the contents of the function must be written
16705  in inline assembler.
16706  This is particularly useful for interrupt functions, which can have a large
16707  (and often unnecessary) prologue/epilogue.
16708  For example, compare the code generated by these two functions:
16709 \end_layout
16710
16711 \begin_layout Verse
16712
16713 \family typewriter
16714 volatile
16715 \begin_inset LatexCommand \index{volatile}
16716
16717 \end_inset
16718
16719  data unsigned char counter;
16720 \newline
16721
16722 \newline
16723 void simpleInterrupt(void) __interrupt
16724 \begin_inset LatexCommand \index{interrupt}
16725
16726 \end_inset
16727
16728
16729 \begin_inset LatexCommand \index{\_\_interrupt}
16730
16731 \end_inset
16732
16733  (1)
16734 \newline
16735 {
16736 \newline
16737 \InsetSpace ~
16738 \InsetSpace ~
16739 \InsetSpace ~
16740 \InsetSpace ~
16741 counter++;
16742 \newline
16743 }
16744 \newline
16745
16746 \newline
16747 void nakedInterrupt(void) __interrupt (2) __naked
16748 \newline
16749 {
16750 \newline
16751 \InsetSpace ~
16752 \InsetSpace ~
16753 \InsetSpace ~
16754 \InsetSpace ~
16755 _asm
16756 \begin_inset LatexCommand \index{\_asm}
16757
16758 \end_inset
16759
16760
16761 \begin_inset LatexCommand \index{\_\_asm}
16762
16763 \end_inset
16764
16765
16766 \newline
16767 \InsetSpace ~
16768 \InsetSpace ~
16769 \InsetSpace ~
16770 \InsetSpace ~
16771 \InsetSpace ~
16772 \InsetSpace ~
16773 inc\InsetSpace ~
16774 \InsetSpace ~
16775 \InsetSpace ~
16776 \InsetSpace ~
16777 \InsetSpace ~
16778 _counter ; does not change flags, no need to save psw
16779 \newline
16780 \InsetSpace ~
16781 \InsetSpace ~
16782 \InsetSpace ~
16783 \InsetSpace ~
16784 \InsetSpace ~
16785 \InsetSpace ~
16786 reti\InsetSpace ~
16787 \InsetSpace ~
16788 \InsetSpace ~
16789 \InsetSpace ~
16790 ; MUST explicitly
16791  include ret or reti in _naked function.
16792 \newline
16793 \InsetSpace ~
16794 \InsetSpace ~
16795 \InsetSpace ~
16796 \InsetSpace ~
16797 _endasm
16798 \begin_inset LatexCommand \index{\_endasm}
16799
16800 \end_inset
16801
16802
16803 \begin_inset LatexCommand \index{\_\_endasm}
16804
16805 \end_inset
16806
16807 ;
16808 \newline
16809 }
16810 \end_layout
16811
16812 \begin_layout Standard
16813 For an 8051 target, the generated simpleInterrupt looks like:
16814 \end_layout
16815
16816 \begin_layout Verse
16817
16818 \family typewriter
16819 Note, this is an 
16820 \emph on
16821 outdated
16822 \emph default
16823  example, recent versions of SDCC generate
16824 \newline
16825 the 
16826 \emph on
16827 same
16828 \emph default
16829  code for simpleInterrupt() and nakedInterrupt()!
16830 \newline
16831
16832 \newline
16833 _simpleInterrupt:
16834 \newline
16835 \InsetSpace ~
16836 \InsetSpace ~
16837 \InsetSpace ~
16838 \InsetSpace ~
16839 push\InsetSpace ~
16840 \InsetSpace ~
16841 \InsetSpace ~
16842 \InsetSpace ~
16843 acc
16844 \newline
16845 \InsetSpace ~
16846 \InsetSpace ~
16847 \InsetSpace ~
16848 \InsetSpace ~
16849 push\InsetSpace ~
16850 \InsetSpace ~
16851 \InsetSpace ~
16852 \InsetSpace ~
16853 b
16854 \newline
16855 \InsetSpace ~
16856 \InsetSpace ~
16857 \InsetSpace ~
16858 \InsetSpace ~
16859 pu
16860 sh\InsetSpace ~
16861 \InsetSpace ~
16862 \InsetSpace ~
16863 \InsetSpace ~
16864 dpl
16865 \newline
16866 \InsetSpace ~
16867 \InsetSpace ~
16868 \InsetSpace ~
16869 \InsetSpace ~
16870 push\InsetSpace ~
16871 \InsetSpace ~
16872 \InsetSpace ~
16873 \InsetSpace ~
16874 dph
16875 \newline
16876 \InsetSpace ~
16877 \InsetSpace ~
16878 \InsetSpace ~
16879 \InsetSpace ~
16880 push\InsetSpace ~
16881 \InsetSpace ~
16882 \InsetSpace ~
16883 \InsetSpace ~
16884 psw
16885 \newline
16886 \InsetSpace ~
16887 \InsetSpace ~
16888 \InsetSpace ~
16889 \InsetSpace ~
16890 mov\InsetSpace ~
16891 \InsetSpace ~
16892 \InsetSpace ~
16893 \InsetSpace ~
16894 \InsetSpace ~
16895 psw,#0x00
16896 \newline
16897 \InsetSpace ~
16898 \InsetSpace ~
16899 \InsetSpace ~
16900 \InsetSpace ~
16901 inc\InsetSpace ~
16902 \InsetSpace ~
16903 \InsetSpace ~
16904 \InsetSpace ~
16905 \InsetSpace ~
16906 _counter
16907 \newline
16908 \InsetSpace ~
16909 \InsetSpace ~
16910 \InsetSpace ~
16911 \InsetSpace ~
16912 pop\InsetSpace ~
16913 \InsetSpace ~
16914 \InsetSpace ~
16915 \InsetSpace ~
16916 \InsetSpace ~
16917 psw
16918 \newline
16919 \InsetSpace ~
16920 \InsetSpace ~
16921 \InsetSpace ~
16922 \InsetSpace ~
16923 pop\InsetSpace ~
16924 \InsetSpace ~
16925 \InsetSpace ~
16926 \InsetSpace ~
16927 \InsetSpace ~
16928 dph
16929 \newline
16930 \InsetSpace ~
16931 \InsetSpace ~
16932 \InsetSpace ~
16933 \InsetSpace ~
16934 pop\InsetSpace ~
16935 \InsetSpace ~
16936 \InsetSpace ~
16937 \InsetSpace ~
16938 \InsetSpace ~
16939 dpl
16940 \newline
16941 \InsetSpace ~
16942 \InsetSpace ~
16943 \InsetSpace ~
16944 \InsetSpace ~
16945 pop\InsetSpace ~
16946 \InsetSpace ~
16947 \InsetSpace ~
16948 \InsetSpace ~
16949 \InsetSpace ~
16950 b
16951 \newline
16952 \InsetSpace ~
16953 \InsetSpace ~
16954 \InsetSpace ~
16955 \InsetSpace ~
16956 pop\InsetSpace ~
16957 \InsetSpace ~
16958 \InsetSpace ~
16959 \InsetSpace ~
16960 \InsetSpace ~
16961 acc
16962 \newline
16963 \InsetSpace ~
16964 \InsetSpace ~
16965 \InsetSpace ~
16966 \InsetSpace ~
16967 reti
16968 \end_layout
16969
16970 \begin_layout Standard
16971 whereas nakedInterrupt looks like:
16972 \end_layout
16973
16974 \begin_layout Verse
16975
16976 \family typewriter
16977 _nakedInterrupt:
16978 \newline
16979 \InsetSpace ~
16980 \InsetSpace ~
16981 \InsetSpace ~
16982 \InsetSpace ~
16983 inc\InsetSpace ~
16984 \InsetSpace ~
16985 \InsetSpace ~
16986 \InsetSpace ~
16987 _counter ; does not change flags, no need to save psw
16988 \newline
16989 \InsetSpace ~
16990 \InsetSpace ~
16991 \InsetSpace ~
16992 \InsetSpace ~
16993 reti\InsetSpace ~
16994 \InsetSpace ~
16995 \InsetSpace ~
16996 \InsetSpace ~
16997 \InsetSpace ~
16998 \InsetSpace ~
16999 \InsetSpace ~
17000 \InsetSpace ~
17001 \InsetSpace ~
17002 \InsetSpace ~
17003 \InsetSpace ~
17004 \InsetSpace ~
17005 ;
17006  MUST explicitly include ret or reti in _naked function
17007 \end_layout
17008
17009 \begin_layout Standard
17010 The related directive #pragma exclude
17011 \begin_inset LatexCommand \index{\#pragma exclude}
17012
17013 \end_inset
17014
17015  allows a more fine grained control over pushing & popping
17016 \begin_inset LatexCommand \index{push/pop}
17017
17018 \end_inset
17019
17020  the registers.
17021 \end_layout
17022
17023 \begin_layout Standard
17024 While there is nothing preventing you from writing C code inside a 
17025 \family typewriter
17026 _naked
17027 \family default
17028  function, there are many ways to shoot yourself in the foot doing this,
17029  and it is recommended that you stick to inline assembler.
17030 \end_layout
17031
17032 \begin_layout Subsection
17033 Use of Labels within Inline Assembler
17034 \end_layout
17035
17036 \begin_layout Standard
17037 SDCC allows the use of in-line assembler with a few restrictions regarding
17038  labels.
17039  In older versions of the compiler all labels defined within inline assembler
17040  code had to be of the form 
17041 \emph on
17042 nnnnn$
17043 \emph default
17044  where nnnnn is a number less than 100 (which implies a limit of utmost
17045  100 inline assembler labels 
17046 \emph on
17047 per function
17048 \emph default
17049 \noun on
17050 )
17051 \noun default
17052 .
17053  
17054 \end_layout
17055
17056 \begin_layout Verse
17057
17058 \family typewriter
17059 _asm
17060 \begin_inset LatexCommand \index{\_asm}
17061
17062 \end_inset
17063
17064
17065 \begin_inset LatexCommand \index{\_\_asm}
17066
17067 \end_inset
17068
17069  
17070 \newline
17071 \InsetSpace ~
17072 \InsetSpace ~
17073 \InsetSpace ~
17074 \InsetSpace ~
17075 mov\InsetSpace ~
17076 \InsetSpace ~
17077 \InsetSpace ~
17078 \InsetSpace ~
17079 \InsetSpace ~
17080 b,#10 
17081 \newline
17082 00001$: 
17083 \newline
17084 \InsetSpace ~
17085 \InsetSpace ~
17086 \InsetSpace ~
17087 \InsetSpace ~
17088 djnz\InsetSpace ~
17089 \InsetSpace ~
17090 \InsetSpace ~
17091 \InsetSpace ~
17092 b,00001$ 
17093 \newline
17094 _endasm
17095 \begin_inset LatexCommand \index{\_endasm}
17096
17097 \end_inset
17098
17099
17100 \begin_inset LatexCommand \index{\_\_endasm}
17101
17102 \end_inset
17103
17104  ;
17105 \end_layout
17106
17107 \begin_layout Standard
17108 Inline assembler code cannot reference any C-labels, however it can reference
17109  labels
17110 \begin_inset LatexCommand \index{Labels}
17111
17112 \end_inset
17113
17114  defined by the inline assembler, e.g.:
17115 \end_layout
17116
17117 \begin_layout Verse
17118
17119 \family typewriter
17120 foo() { 
17121 \newline
17122 \InsetSpace ~
17123 \InsetSpace ~
17124 \InsetSpace ~
17125 \InsetSpace ~
17126 /* some c code */ 
17127 \newline
17128 \InsetSpace ~
17129 \InsetSpace ~
17130 \InsetSpace ~
17131 \InsetSpace ~
17132 _asm 
17133 \newline
17134 \InsetSpace ~
17135 \InsetSpace ~
17136 \InsetSpace ~
17137 \InsetSpace ~
17138 \InsetSpace ~
17139 \InsetSpace ~
17140 ; some assembler code 
17141 \newline
17142 \InsetSpace ~
17143 \InsetSpace ~
17144 \InsetSpace ~
17145 \InsetSpace ~
17146 \InsetSpace ~
17147 \InsetSpace ~
17148 ljmp $0003 
17149 \newline
17150 \InsetSpace ~
17151 \InsetSpace ~
17152 \InsetSpace ~
17153 \InsetSpace ~
17154 _endasm;
17155  
17156 \newline
17157 \InsetSpace ~
17158 \InsetSpace ~
17159 \InsetSpace ~
17160 \InsetSpace ~
17161 /* some more c code */ 
17162 \newline
17163 clabel:\InsetSpace ~
17164 \InsetSpace ~
17165 /* inline assembler cannot reference this
17166  label */ 
17167 \newline
17168 \InsetSpace ~
17169 \InsetSpace ~
17170 \InsetSpace ~
17171 \InsetSpace ~
17172 _asm
17173 \newline
17174 \InsetSpace ~
17175 \InsetSpace ~
17176 \InsetSpace ~
17177 \InsetSpace ~
17178 $0003: ;label (can be referenced by inline assembler only)
17179  
17180 \newline
17181 \InsetSpace ~
17182 \InsetSpace ~
17183 \InsetSpace ~
17184 \InsetSpace ~
17185 _endasm
17186 \begin_inset LatexCommand \index{\_endasm}
17187
17188 \end_inset
17189
17190
17191 \begin_inset LatexCommand \index{\_\_endasm}
17192
17193 \end_inset
17194
17195  ; 
17196 \newline
17197 \InsetSpace ~
17198 \InsetSpace ~
17199 \InsetSpace ~
17200 \InsetSpace ~
17201 /* some more c code */
17202 \newline
17203 }
17204 \end_layout
17205
17206 \begin_layout Standard
17207 In other words inline assembly code can access labels defined in inline
17208  assembly within the scope of the function.
17209  The same goes the other way, i.e.
17210  labels defines in inline assembly can not be accessed by C statements.
17211 \end_layout
17212
17213 \begin_layout Section
17214 Interfacing with Assembler Code
17215 \begin_inset LatexCommand \index{Assembler routines}
17216
17217 \end_inset
17218
17219
17220 \end_layout
17221
17222 \begin_layout Subsection
17223 Global Registers used for Parameter Passing
17224 \begin_inset LatexCommand \index{Parameter passing}
17225
17226 \end_inset
17227
17228
17229 \end_layout
17230
17231 \begin_layout Standard
17232 The compiler always uses the global registers 
17233 \emph on
17234 DPL, DPH
17235 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17236
17237 \end_inset
17238
17239
17240 \begin_inset LatexCommand \index{DPTR}
17241
17242 \end_inset
17243
17244 , B
17245 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
17246
17247 \end_inset
17248
17249  
17250 \emph default
17251 and
17252 \emph on
17253  ACC
17254 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
17255
17256 \end_inset
17257
17258
17259 \emph default
17260  to pass the first parameter to a function, and also to pass the return
17261  value 
17262 \begin_inset LatexCommand \index{return value}
17263
17264 \end_inset
17265
17266 of function; according to the following scheme: one byte return value in
17267  
17268 \emph on
17269 DPL
17270 \emph default
17271 , two byte value in 
17272 \emph on
17273 DPL
17274 \emph default
17275  (LSB) and 
17276 \emph on
17277 DPH
17278 \emph default
17279  (MSB).
17280  three byte values (generic pointers) in 
17281 \emph on
17282 DPH
17283 \emph default
17284
17285 \emph on
17286 DPL
17287 \emph default
17288  and 
17289 \emph on
17290 B
17291 \emph default
17292 , and four byte values in 
17293 \emph on
17294 DPH
17295 \emph default
17296
17297 \emph on
17298 DPL
17299 \emph default
17300 ,
17301 \emph on
17302  B
17303 \emph default
17304  and 
17305 \emph on
17306 ACC
17307 \emph default
17308 .
17309  Generic pointers
17310 \begin_inset LatexCommand \index{generic pointer}
17311
17312 \end_inset
17313
17314  contain type of accessed memory in 
17315 \emph on
17316 B
17317 \emph default
17318
17319 \series bold
17320 0x00
17321 \series default
17322  -- xdata/far, 
17323 \series bold
17324 0x40
17325 \series default
17326  -- idata/near -- , 
17327 \series bold
17328 0x60
17329 \series default
17330  -- pdata, 
17331 \series bold
17332 0x80
17333 \series default
17334  -- code
17335 \begin_inset Note Note
17336 status collapsed
17337
17338 \begin_layout Standard
17339 This might not be the case of certain memory models (medium???)
17340 \end_layout
17341
17342 \end_inset
17343
17344 .
17345 \end_layout
17346
17347 \begin_layout Standard
17348 The second parameter onwards is either allocated on the stack (for reentrant
17349  routines or if -
17350 \begin_inset ERT
17351 status collapsed
17352
17353 \begin_layout Standard
17354
17355
17356 \backslash
17357 /
17358 \end_layout
17359
17360 \end_inset
17361
17362 -stack-auto is used) or in data/xdata memory (depending on the memory model).
17363  
17364 \end_layout
17365
17366 \begin_layout Subsection
17367 Registers usage
17368 \end_layout
17369
17370 \begin_layout Standard
17371 Unless the called function is declared as 
17372 \family typewriter
17373 _naked
17374 \family default
17375
17376 \begin_inset LatexCommand \index{naked}
17377
17378 \end_inset
17379
17380 , or the -
17381 \begin_inset ERT
17382 status collapsed
17383
17384 \begin_layout Standard
17385
17386
17387 \backslash
17388 /
17389 \end_layout
17390
17391 \end_inset
17392
17393 -callee-saves
17394 \begin_inset LatexCommand \index{-\/-callee-saves}
17395
17396 \end_inset
17397
17398 /-
17399 \begin_inset ERT
17400 status collapsed
17401
17402 \begin_layout Standard
17403
17404
17405 \backslash
17406 /
17407 \end_layout
17408
17409 \end_inset
17410
17411 -all-callee-saves command line option or the corresponding callee_saves
17412  pragma are used, the caller will save the registers (
17413 \emph on
17414 R0-R7
17415 \emph default
17416 ) around the call, so the called function can destroy they content freely.
17417 \end_layout
17418
17419 \begin_layout Standard
17420 If the called function is not declared as 
17421 \family typewriter
17422 _naked
17423 \family default
17424 , the caller will swap register banks around the call, if caller and callee
17425  use different register banks (having them defined by the 
17426 \family typewriter
17427 _using
17428 \family default
17429  modifier).
17430  
17431 \end_layout
17432
17433 \begin_layout Standard
17434 The called function can also use 
17435 \emph on
17436 DPL
17437 \emph default
17438
17439 \emph on
17440 DPH
17441 \emph default
17442
17443 \emph on
17444 B
17445 \emph default
17446  and 
17447 \emph on
17448 ACC
17449 \emph default
17450  observing that they are used for parameter/return value passing.
17451 \end_layout
17452
17453 \begin_layout Subsection
17454 Assembler Routine (non-reentrant)
17455 \end_layout
17456
17457 \begin_layout Standard
17458 In the following example
17459 \begin_inset LatexCommand \index{reentrant}
17460
17461 \end_inset
17462
17463
17464 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
17465
17466 \end_inset
17467
17468  the function c_func calls an assembler routine asm_func, which takes two
17469  parameters
17470 \begin_inset LatexCommand \index{function parameter}
17471
17472 \end_inset
17473
17474 .
17475 \end_layout
17476
17477 \begin_layout Verse
17478
17479 \family typewriter
17480 extern int asm_func(unsigned char, unsigned char);
17481 \newline
17482
17483 \newline
17484 int c_func (unsigned char
17485  i, unsigned char j)
17486 \newline
17487 {
17488 \newline
17489 \InsetSpace ~
17490 \InsetSpace ~
17491 \InsetSpace ~
17492 \InsetSpace ~
17493 return asm_func(i,j);
17494 \newline
17495 }
17496 \newline
17497
17498 \newline
17499 int main()
17500 \newline
17501 {
17502 \newline
17503 \InsetSpace ~
17504 \InsetSpace ~
17505 \InsetSpace ~
17506 \InsetSpace ~
17507 return c_func(10,9);
17508 \newline
17509 }
17510 \end_layout
17511
17512 \begin_layout Standard
17513 The corresponding assembler function is:
17514 \end_layout
17515
17516 \begin_layout Verse
17517
17518 \family typewriter
17519 .globl _asm_func_PARM_2 
17520 \newline
17521 \InsetSpace ~
17522 \InsetSpace ~
17523 \InsetSpace ~
17524 \InsetSpace ~
17525 \InsetSpace ~
17526 \InsetSpace ~
17527 \InsetSpace ~
17528 \InsetSpace ~
17529 .globl _asm_func 
17530 \newline
17531 \InsetSpace ~
17532 \InsetSpace ~
17533 \InsetSpace ~
17534 \InsetSpace ~
17535 \InsetSpace ~
17536 \InsetSpace ~
17537 \InsetSpace ~
17538 \InsetSpace ~
17539 .area OSEG 
17540 \newline
17541 _asm_func_PARM_2:
17542 \newline
17543 \InsetSpace ~
17544 \InsetSpace ~
17545 \InsetSpace ~
17546 \InsetSpace ~
17547 \InsetSpace ~
17548 \InsetSpace ~
17549 \InsetSpace ~
17550 \InsetSpace ~
17551 .ds   
17552  1 
17553 \newline
17554 \InsetSpace ~
17555 \InsetSpace ~
17556 \InsetSpace ~
17557 \InsetSpace ~
17558 \InsetSpace ~
17559 \InsetSpace ~
17560 \InsetSpace ~
17561 \InsetSpace ~
17562 .area CSEG 
17563 \newline
17564 _asm_func: 
17565 \newline
17566 \InsetSpace ~
17567 \InsetSpace ~
17568 \InsetSpace ~
17569 \InsetSpace ~
17570 \InsetSpace ~
17571 \InsetSpace ~
17572 \InsetSpace ~
17573 \InsetSpace ~
17574 mov\InsetSpace ~
17575 \InsetSpace ~
17576 \InsetSpace ~
17577 \InsetSpace ~
17578 a,dpl 
17579 \newline
17580 \InsetSpace ~
17581 \InsetSpace ~
17582 \InsetSpace ~
17583 \InsetSpace ~
17584 \InsetSpace ~
17585 \InsetSpace ~
17586 \InsetSpace ~
17587 \InsetSpace ~
17588 add\InsetSpace ~
17589 \InsetSpace ~
17590 \InsetSpace ~
17591 \InsetSpace ~
17592 a,_asm_func_PARM_2 
17593 \newline
17594 \InsetSpace ~
17595 \InsetSpace ~
17596 \InsetSpace ~
17597 \InsetSpace ~
17598 \InsetSpace ~
17599 \InsetSpace ~
17600 \InsetSpace ~
17601 \InsetSpace ~
17602 mov\InsetSpace ~
17603 \InsetSpace ~
17604 \InsetSpace ~
17605 \InsetSpace ~
17606 dpl,a 
17607 \newline
17608 \InsetSpace ~
17609 \InsetSpace ~
17610 \InsetSpace ~
17611 \InsetSpace ~
17612 \InsetSpace ~
17613 \InsetSpace ~
17614 \InsetSpace ~
17615 \InsetSpace ~
17616 mov\InsetSpace ~
17617 \InsetSpace ~
17618 \InsetSpace ~
17619 \InsetSpace ~
17620 dph
17621 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
17622
17623 \end_inset
17624
17625 ,#0x00 
17626 \newline
17627 \InsetSpace ~
17628 \InsetSpace ~
17629 \InsetSpace ~
17630 \InsetSpace ~
17631 \InsetSpace ~
17632 \InsetSpace ~
17633 \InsetSpace ~
17634 \InsetSpace ~
17635 ret
17636 \end_layout
17637
17638 \begin_layout Standard
17639 The parameter naming convention is _<function_name>_PARM_<n>, where n is
17640  the parameter number starting from 1, and counting from the left.
17641  The first parameter is passed in 
17642 \emph on
17643 DPH
17644 \emph default
17645
17646 \emph on
17647 DPL
17648 \emph default
17649
17650 \emph on
17651 B
17652 \emph default
17653  and 
17654 \emph on
17655 ACC
17656 \emph default
17657  according to the description above.
17658  The variable name for the second parameter will be _<function_name>_PARM_2.
17659 \newline
17660
17661 \newline
17662 Assem
17663 ble the assembler routine with the following command:
17664 \newline
17665
17666 \newline
17667
17668 \family sans
17669 \series bold
17670 asx8051 -losg asmfunc.asm
17671 \newline
17672
17673 \newline
17674
17675 \family default
17676 \series default
17677 Then compile and link the assembler routine to the C source file with the
17678  following command:
17679 \newline
17680
17681 \newline
17682
17683 \family sans
17684 \series bold
17685 sdcc cfunc.c asmfunc.rel
17686 \end_layout
17687
17688 \begin_layout Subsection
17689 Assembler Routine (reentrant)
17690 \end_layout
17691
17692 \begin_layout Standard
17693 In this case
17694 \begin_inset LatexCommand \index{reentrant}
17695
17696 \end_inset
17697
17698
17699 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
17700
17701 \end_inset
17702
17703  the second parameter
17704 \begin_inset LatexCommand \index{function parameter}
17705
17706 \end_inset
17707
17708  onwards will be passed on the stack, the parameters are pushed from right
17709  to left i.e.
17710  before the call the second leftmost parameter will be on the top of the
17711  stack (the leftmost parameter is passed in registers).
17712  Here is an example:
17713 \end_layout
17714
17715 \begin_layout Verse
17716
17717 \family typewriter
17718 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
17719 \newline
17720
17721 \newline
17722 int
17723  c_func (unsigned char i, unsigned char j, unsigned char k) reentrant 
17724 \newline
17725 {
17726  
17727 \newline
17728 \InsetSpace ~
17729 \InsetSpace ~
17730 \InsetSpace ~
17731 \InsetSpace ~
17732 return asm_func(i,j,k); 
17733 \newline
17734
17735 \newline
17736
17737 \newline
17738 int main() 
17739 \newline
17740
17741 \newline
17742 \InsetSpace ~
17743 \InsetSpace ~
17744 \InsetSpace ~
17745 \InsetSpace ~
17746 return c_func(10,9,8); 
17747 \newline
17748 }
17749 \end_layout
17750
17751 \begin_layout Standard
17752 The corresponding (unoptimized) assembler routine is:
17753 \end_layout
17754
17755 \begin_layout Verse
17756
17757 \family typewriter
17758 .globl _asm_func 
17759 \newline
17760 _asm_func: 
17761 \newline
17762 \InsetSpace ~
17763 \InsetSpace ~
17764 \InsetSpace ~
17765 \InsetSpace ~
17766 push\InsetSpace ~
17767 _bp 
17768 \newline
17769 \InsetSpace ~
17770 \InsetSpace ~
17771 \InsetSpace ~
17772 \InsetSpace ~
17773 mov\InsetSpace ~
17774 \InsetSpace ~
17775 _bp,sp\InsetSpace ~
17776 \InsetSpace ~
17777 \InsetSpace ~
17778 \InsetSpace ~
17779 \InsetSpace ~
17780 \InsetSpace ~
17781 ;stack contains: _bp, return
17782  address, second parameter, third parameter
17783 \newline
17784 \InsetSpace ~
17785 \InsetSpace ~
17786 \InsetSpace ~
17787 \InsetSpace ~
17788 mov\InsetSpace ~
17789 \InsetSpace ~
17790 r2,dpl
17791 \newline
17792 \InsetSpace ~
17793 \InsetSpace ~
17794 \InsetSpace ~
17795 \InsetSpace ~
17796 mov\InsetSpace ~
17797 \InsetSpace ~
17798 a,_bp
17799 \newline
17800 \InsetSpace ~
17801 \InsetSpace ~
17802 \InsetSpace ~
17803 \InsetSpace ~
17804 add\InsetSpace ~
17805 \InsetSpace ~
17806 a,#0xfd\InsetSpace ~
17807 \InsetSpace ~
17808 \InsetSpace ~
17809 \InsetSpace ~
17810 \InsetSpace ~
17811 ;calculate
17812  pointer to the second parameter
17813 \newline
17814 \InsetSpace ~
17815 \InsetSpace ~
17816 \InsetSpace ~
17817 \InsetSpace ~
17818 mov\InsetSpace ~
17819 \InsetSpace ~
17820 r0,a 
17821 \newline
17822 \InsetSpace ~
17823 \InsetSpace ~
17824 \InsetSpace ~
17825 \InsetSpace ~
17826 mov\InsetSpace ~
17827 \InsetSpace ~
17828 a,_bp 
17829 \newline
17830 \InsetSpace ~
17831 \InsetSpace ~
17832 \InsetSpace ~
17833 \InsetSpace ~
17834 add\InsetSpace ~
17835 \InsetSpace ~
17836 a,#0xfc\InsetSpace ~
17837 \InsetSpace ~
17838 \InsetSpace ~
17839 \InsetSpace ~
17840 \InsetSpace ~
17841 ;calculate pointer
17842  to the rightmost parameter
17843 \newline
17844 \InsetSpace ~
17845 \InsetSpace ~
17846 \InsetSpace ~
17847 \InsetSpace ~
17848 mov\InsetSpace ~
17849 \InsetSpace ~
17850 r1,a 
17851 \newline
17852 \InsetSpace ~
17853 \InsetSpace ~
17854 \InsetSpace ~
17855 \InsetSpace ~
17856 mov\InsetSpace ~
17857 \InsetSpace ~
17858 a,@r0
17859 \newline
17860 \InsetSpace ~
17861 \InsetSpace ~
17862 \InsetSpace ~
17863 \InsetSpace ~
17864 add\InsetSpace ~
17865 \InsetSpace ~
17866 a,@r1
17867 \newline
17868 \InsetSpace ~
17869 \InsetSpace ~
17870 \InsetSpace ~
17871 \InsetSpace ~
17872 add\InsetSpace ~
17873 \InsetSpace ~
17874 a,r2\InsetSpace ~
17875 \InsetSpace ~
17876 \InsetSpace ~
17877 \InsetSpace ~
17878 \InsetSpace ~
17879 \InsetSpace ~
17880 \InsetSpace ~
17881 \InsetSpace ~
17882 ;calculate the
17883  result (= sum of all three parameters)
17884 \newline
17885 \InsetSpace ~
17886 \InsetSpace ~
17887 \InsetSpace ~
17888 \InsetSpace ~
17889 mov\InsetSpace ~
17890 \InsetSpace ~
17891 dpl,a\InsetSpace ~
17892 \InsetSpace ~
17893 \InsetSpace ~
17894 \InsetSpace ~
17895 \InsetSpace ~
17896 \InsetSpace ~
17897 \InsetSpace ~
17898 ;return value goes into dptr
17899  (cast into int)
17900 \newline
17901 \InsetSpace ~
17902 \InsetSpace ~
17903 \InsetSpace ~
17904 \InsetSpace ~
17905 mov\InsetSpace ~
17906 \InsetSpace ~
17907 dph,#0x00 
17908 \newline
17909 \InsetSpace ~
17910 \InsetSpace ~
17911 \InsetSpace ~
17912 \InsetSpace ~
17913 mov\InsetSpace ~
17914 \InsetSpace ~
17915 sp,_bp 
17916 \newline
17917 \InsetSpace ~
17918 \InsetSpace ~
17919 \InsetSpace ~
17920 \InsetSpace ~
17921 pop\InsetSpace ~
17922 \InsetSpace ~
17923 _bp 
17924 \newline
17925 \InsetSpace ~
17926 \InsetSpace ~
17927 \InsetSpace ~
17928 \InsetSpace ~
17929 ret
17930 \end_layout
17931
17932 \begin_layout Standard
17933 The compiling and linking procedure remains the same, however note the extra
17934  entry & exit linkage required for the assembler code, _bp is the stack
17935  frame pointer and is used to compute the offset into the stack for parameters
17936  and local variables.
17937 \begin_inset VSpace bigskip
17938 \end_inset
17939
17940
17941 \end_layout
17942
17943 \begin_layout Section
17944 int (16 bit)
17945 \begin_inset LatexCommand \index{int (16 bit)}
17946
17947 \end_inset
17948
17949  and long (32 bit)
17950 \begin_inset LatexCommand \index{long (32 bit)}
17951
17952 \end_inset
17953
17954  Support
17955 \end_layout
17956
17957 \begin_layout Standard
17958 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
17959  multiplication and modulus operations are implemented by support routines.
17960  These support routines are all developed in ANSI-C to facilitate porting
17961  to other MCUs, although some model specific assembler optimizations are
17962  used.
17963  The following files contain the described routines, all of them can be
17964  found in <installdir>/share/sdcc/lib.
17965 \newline
17966
17967 \end_layout
17968
17969 \begin_layout Standard
17970 \align center
17971 \begin_inset Tabular
17972 <lyxtabular version="3" rows="11" columns="2">
17973 <features>
17974 <column alignment="left" valignment="top" leftline="true" width="0">
17975 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
17976 <row topline="true" bottomline="true">
17977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17978 \begin_inset Text
17979
17980 \begin_layout Standard
17981
17982 \series bold
17983 Function
17984 \end_layout
17985
17986 \end_inset
17987 </cell>
17988 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17989 \begin_inset Text
17990
17991 \begin_layout Standard
17992
17993 \series bold
17994 Description
17995 \end_layout
17996
17997 \end_inset
17998 </cell>
17999 </row>
18000 <row topline="true">
18001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18002 \begin_inset Text
18003
18004 \begin_layout Standard
18005 _mulint.c 
18006 \end_layout
18007
18008 \end_inset
18009 </cell>
18010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18011 \begin_inset Text
18012
18013 \begin_layout Standard
18014 16 bit multiplication
18015 \end_layout
18016
18017 \end_inset
18018 </cell>
18019 </row>
18020 <row topline="true">
18021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18022 \begin_inset Text
18023
18024 \begin_layout Standard
18025 _divsint.c 
18026 \end_layout
18027
18028 \end_inset
18029 </cell>
18030 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18031 \begin_inset Text
18032
18033 \begin_layout Standard
18034  signed 16 bit division (calls _divuint)
18035 \end_layout
18036
18037 \end_inset
18038 </cell>
18039 </row>
18040 <row topline="true">
18041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18042 \begin_inset Text
18043
18044 \begin_layout Standard
18045 _divuint.c 
18046 \end_layout
18047
18048 \end_inset
18049 </cell>
18050 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18051 \begin_inset Text
18052
18053 \begin_layout Standard
18054  unsigned 16 bit division
18055 \end_layout
18056
18057 \end_inset
18058 </cell>
18059 </row>
18060 <row topline="true">
18061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18062 \begin_inset Text
18063
18064 \begin_layout Standard
18065 _modsint.c
18066 \end_layout
18067
18068 \end_inset
18069 </cell>
18070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18071 \begin_inset Text
18072
18073 \begin_layout Standard
18074 signed 16 bit modulus (calls _moduint)
18075 \end_layout
18076
18077 \end_inset
18078 </cell>
18079 </row>
18080 <row topline="true">
18081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18082 \begin_inset Text
18083
18084 \begin_layout Standard
18085 _moduint.c
18086 \end_layout
18087
18088 \end_inset
18089 </cell>
18090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18091 \begin_inset Text
18092
18093 \begin_layout Standard
18094 unsigned 16 bit modulus
18095 \end_layout
18096
18097 \end_inset
18098 </cell>
18099 </row>
18100 <row topline="true">
18101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18102 \begin_inset Text
18103
18104 \begin_layout Standard
18105 _mullong.c
18106 \end_layout
18107
18108 \end_inset
18109 </cell>
18110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18111 \begin_inset Text
18112
18113 \begin_layout Standard
18114 32 bit multiplication
18115 \end_layout
18116
18117 \end_inset
18118 </cell>
18119 </row>
18120 <row topline="true">
18121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18122 \begin_inset Text
18123
18124 \begin_layout Standard
18125 _divslong.c 
18126 \end_layout
18127
18128 \end_inset
18129 </cell>
18130 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18131 \begin_inset Text
18132
18133 \begin_layout Standard
18134  signed 32 division (calls _divulong)
18135 \end_layout
18136
18137 \end_inset
18138 </cell>
18139 </row>
18140 <row topline="true">
18141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18142 \begin_inset Text
18143
18144 \begin_layout Standard
18145 _divulong.c 
18146 \end_layout
18147
18148 \end_inset
18149 </cell>
18150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18151 \begin_inset Text
18152
18153 \begin_layout Standard
18154 unsigned 32 division
18155 \end_layout
18156
18157 \end_inset
18158 </cell>
18159 </row>
18160 <row topline="true">
18161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18162 \begin_inset Text
18163
18164 \begin_layout Standard
18165 _modslong.c
18166 \end_layout
18167
18168 \end_inset
18169 </cell>
18170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18171 \begin_inset Text
18172
18173 \begin_layout Standard
18174  signed 32 bit modulus (calls _modulong)
18175 \end_layout
18176
18177 \end_inset
18178 </cell>
18179 </row>
18180 <row topline="true" bottomline="true">
18181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18182 \begin_inset Text
18183
18184 \begin_layout Standard
18185 _modulong.c
18186 \end_layout
18187
18188 \end_inset
18189 </cell>
18190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18191 \begin_inset Text
18192
18193 \begin_layout Standard
18194 unsigned 32 bit modulus
18195 \end_layout
18196
18197 \end_inset
18198 </cell>
18199 </row>
18200 </lyxtabular>
18201
18202 \end_inset
18203
18204
18205 \newline
18206
18207 \end_layout
18208
18209 \begin_layout Standard
18210 Since they are compiled as 
18211 \emph on
18212 non-reentrant
18213 \emph default
18214
18215 \begin_inset LatexCommand \index{reentrant}
18216
18217 \end_inset
18218
18219 , interrupt
18220 \begin_inset LatexCommand \index{interrupt}
18221
18222 \end_inset
18223
18224  service routines should not do any of the above operations.
18225  If this is unavoidable then the above routines will need to be compiled
18226  with the 
18227 \emph on
18228 -
18229 \begin_inset ERT
18230 status collapsed
18231
18232 \begin_layout Standard
18233
18234
18235 \backslash
18236 /
18237 \end_layout
18238
18239 \end_inset
18240
18241 -stack-auto
18242 \begin_inset LatexCommand \index{-\/-stack-auto}
18243
18244 \end_inset
18245
18246
18247 \emph default
18248  option, after which the source program will have to be compiled with 
18249 \emph on
18250 -
18251 \begin_inset ERT
18252 status collapsed
18253
18254 \begin_layout Standard
18255
18256
18257 \backslash
18258 /
18259 \end_layout
18260
18261 \end_inset
18262
18263 -int-long-reent
18264 \begin_inset LatexCommand \index{-\/-int-long-reent}
18265
18266 \end_inset
18267
18268
18269 \emph default
18270  option.
18271  Notice that you don't have to call these routines directly.
18272  The compiler will use them automatically every time an integer operation
18273  is required.
18274 \end_layout
18275
18276 \begin_layout Section
18277 Floating Point Support
18278 \begin_inset LatexCommand \index{Floating point support}
18279
18280 \end_inset
18281
18282
18283 \end_layout
18284
18285 \begin_layout Standard
18286 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
18287  The floating point support routines are derived from gcc's floatlib.c and
18288  consist of the following routines:
18289 \newline
18290
18291 \end_layout
18292
18293 \begin_layout Standard
18294 \align center
18295
18296 \size footnotesize
18297 \begin_inset Tabular
18298 <lyxtabular version="3" rows="17" columns="2">
18299 <features>
18300 <column alignment="left" valignment="top" leftline="true" width="0">
18301 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
18302 <row topline="true" bottomline="true">
18303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18304 \begin_inset Text
18305
18306 \begin_layout Standard
18307
18308 \family roman
18309 \series medium
18310 \shape up
18311 \size normal
18312 \emph off
18313 \bar no
18314 \noun off
18315 \color none
18316 Function 
18317 \end_layout
18318
18319 \end_inset
18320 </cell>
18321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18322 \begin_inset Text
18323
18324 \begin_layout Standard
18325 Description
18326 \end_layout
18327
18328 \end_inset
18329 </cell>
18330 </row>
18331 <row topline="true">
18332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18333 \begin_inset Text
18334
18335 \begin_layout Standard
18336
18337 \family roman
18338 \series medium
18339 \shape up
18340 \size normal
18341 \emph off
18342 \bar no
18343 \noun off
18344 \color none
18345 _fsadd.c
18346 \end_layout
18347
18348 \end_inset
18349 </cell>
18350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18351 \begin_inset Text
18352
18353 \begin_layout Standard
18354
18355 \family roman
18356 \series medium
18357 \shape up
18358 \size normal
18359 \emph off
18360 \bar no
18361 \noun off
18362 \color none
18363 add floating point numbers
18364 \end_layout
18365
18366 \end_inset
18367 </cell>
18368 </row>
18369 <row topline="true">
18370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18371 \begin_inset Text
18372
18373 \begin_layout Standard
18374
18375 \family roman
18376 \series medium
18377 \shape up
18378 \size normal
18379 \emph off
18380 \bar no
18381 \noun off
18382 \color none
18383 _fssub.c 
18384 \end_layout
18385
18386 \end_inset
18387 </cell>
18388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18389 \begin_inset Text
18390
18391 \begin_layout Standard
18392
18393 \family roman
18394 \series medium
18395 \shape up
18396 \size normal
18397 \emph off
18398 \bar no
18399 \noun off
18400 \color none
18401 subtract floating point numbers 
18402 \end_layout
18403
18404 \end_inset
18405 </cell>
18406 </row>
18407 <row topline="true">
18408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18409 \begin_inset Text
18410
18411 \begin_layout Standard
18412
18413 \family roman
18414 \series medium
18415 \shape up
18416 \size normal
18417 \emph off
18418 \bar no
18419 \noun off
18420 \color none
18421 _fsdiv.c 
18422 \end_layout
18423
18424 \end_inset
18425 </cell>
18426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18427 \begin_inset Text
18428
18429 \begin_layout Standard
18430
18431 \family roman
18432 \series medium
18433 \shape up
18434 \size normal
18435 \emph off
18436 \bar no
18437 \noun off
18438 \color none
18439 divide floating point numbers 
18440 \end_layout
18441
18442 \end_inset
18443 </cell>
18444 </row>
18445 <row topline="true">
18446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18447 \begin_inset Text
18448
18449 \begin_layout Standard
18450
18451 \family roman
18452 \series medium
18453 \shape up
18454 \size normal
18455 \emph off
18456 \bar no
18457 \noun off
18458 \color none
18459 _fsmul.c 
18460 \end_layout
18461
18462 \end_inset
18463 </cell>
18464 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18465 \begin_inset Text
18466
18467 \begin_layout Standard
18468
18469 \family roman
18470 \series medium
18471 \shape up
18472 \size normal
18473 \emph off
18474 \bar no
18475 \noun off
18476 \color none
18477 multiply floating point numbers 
18478 \end_layout
18479
18480 \end_inset
18481 </cell>
18482 </row>
18483 <row topline="true">
18484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18485 \begin_inset Text
18486
18487 \begin_layout Standard
18488
18489 \family roman
18490 \series medium
18491 \shape up
18492 \size normal
18493 \emph off
18494 \bar no
18495 \noun off
18496 \color none
18497 _fs2uchar.c
18498 \end_layout
18499
18500 \end_inset
18501 </cell>
18502 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18503 \begin_inset Text
18504
18505 \begin_layout Standard
18506
18507 \family roman
18508 \series medium
18509 \shape up
18510 \size normal
18511 \emph off
18512 \bar no
18513 \noun off
18514 \color none
18515 convert floating point to unsigned char
18516 \end_layout
18517
18518 \end_inset
18519 </cell>
18520 </row>
18521 <row topline="true">
18522 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18523 \begin_inset Text
18524
18525 \begin_layout Standard
18526
18527 \family roman
18528 \series medium
18529 \shape up
18530 \size normal
18531 \emph off
18532 \bar no
18533 \noun off
18534 \color none
18535 _fs2char.c
18536 \end_layout
18537
18538 \end_inset
18539 </cell>
18540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18541 \begin_inset Text
18542
18543 \begin_layout Standard
18544
18545 \family roman
18546 \series medium
18547 \shape up
18548 \size normal
18549 \emph off
18550 \bar no
18551 \noun off
18552 \color none
18553 convert floating point to signed char
18554 \end_layout
18555
18556 \end_inset
18557 </cell>
18558 </row>
18559 <row topline="true">
18560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18561 \begin_inset Text
18562
18563 \begin_layout Standard
18564
18565 \family roman
18566 \series medium
18567 \shape up
18568 \size normal
18569 \emph off
18570 \bar no
18571 \noun off
18572 \color none
18573 _fs2uint.c
18574 \end_layout
18575
18576 \end_inset
18577 </cell>
18578 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18579 \begin_inset Text
18580
18581 \begin_layout Standard
18582
18583 \family roman
18584 \series medium
18585 \shape up
18586 \size normal
18587 \emph off
18588 \bar no
18589 \noun off
18590 \color none
18591 convert floating point to unsigned int
18592 \end_layout
18593
18594 \end_inset
18595 </cell>
18596 </row>
18597 <row topline="true">
18598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18599 \begin_inset Text
18600
18601 \begin_layout Standard
18602
18603 \family roman
18604 \series medium
18605 \shape up
18606 \size normal
18607 \emph off
18608 \bar no
18609 \noun off
18610 \color none
18611 _fs2int.c
18612 \end_layout
18613
18614 \end_inset
18615 </cell>
18616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18617 \begin_inset Text
18618
18619 \begin_layout Standard
18620
18621 \family roman
18622 \series medium
18623 \shape up
18624 \size normal
18625 \emph off
18626 \bar no
18627 \noun off
18628 \color none
18629 convert floating point to signed int
18630 \end_layout
18631
18632 \end_inset
18633 </cell>
18634 </row>
18635 <row topline="true">
18636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18637 \begin_inset Text
18638
18639 \begin_layout Standard
18640
18641 \family roman
18642 \series medium
18643 \shape up
18644 \size normal
18645 \emph off
18646 \bar no
18647 \noun off
18648 \color none
18649 _fs2ulong.
18650 \family default
18651 \series default
18652 \shape default
18653 \size default
18654 \emph default
18655 \bar default
18656 \noun default
18657 c
18658 \end_layout
18659
18660 \end_inset
18661 </cell>
18662 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18663 \begin_inset Text
18664
18665 \begin_layout Standard
18666
18667 \family roman
18668 \series medium
18669 \shape up
18670 \size normal
18671 \emph off
18672 \bar no
18673 \noun off
18674 \color none
18675 convert floating point to unsigned long
18676 \end_layout
18677
18678 \end_inset
18679 </cell>
18680 </row>
18681 <row topline="true">
18682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18683 \begin_inset Text
18684
18685 \begin_layout Standard
18686
18687 \family roman
18688 \series medium
18689 \shape up
18690 \size normal
18691 \emph off
18692 \bar no
18693 \noun off
18694 \color none
18695 _fs2long.c
18696 \end_layout
18697
18698 \end_inset
18699 </cell>
18700 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18701 \begin_inset Text
18702
18703 \begin_layout Standard
18704
18705 \family roman
18706 \series medium
18707 \shape up
18708 \size normal
18709 \emph off
18710 \bar no
18711 \noun off
18712 \color none
18713 convert floating point to signed long
18714 \end_layout
18715
18716 \end_inset
18717 </cell>
18718 </row>
18719 <row topline="true">
18720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18721 \begin_inset Text
18722
18723 \begin_layout Standard
18724
18725 \family roman
18726 \series medium
18727 \shape up
18728 \size normal
18729 \emph off
18730 \bar no
18731 \noun off
18732 \color none
18733 _uchar2fs.c
18734 \end_layout
18735
18736 \end_inset
18737 </cell>
18738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18739 \begin_inset Text
18740
18741 \begin_layout Standard
18742
18743 \family roman
18744 \series medium
18745 \shape up
18746 \size normal
18747 \emph off
18748 \bar no
18749 \noun off
18750 \color none
18751 convert unsigned char to floating point
18752 \end_layout
18753
18754 \end_inset
18755 </cell>
18756 </row>
18757 <row topline="true">
18758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18759 \begin_inset Text
18760
18761 \begin_layout Standard
18762
18763 \family roman
18764 \series medium
18765 \shape up
18766 \size normal
18767 \emph off
18768 \bar no
18769 \noun off
18770 \color none
18771 _char2fs.c
18772 \end_layout
18773
18774 \end_inset
18775 </cell>
18776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18777 \begin_inset Text
18778
18779 \begin_layout Standard
18780
18781 \family roman
18782 \series medium
18783 \shape up
18784 \size normal
18785 \emph off
18786 \bar no
18787 \noun off
18788 \color none
18789 convert char to floating point number
18790 \end_layout
18791
18792 \end_inset
18793 </cell>
18794 </row>
18795 <row topline="true">
18796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18797 \begin_inset Text
18798
18799 \begin_layout Standard
18800
18801 \family roman
18802 \series medium
18803 \shape up
18804 \size normal
18805 \emph off
18806 \bar no
18807 \noun off
18808 \color none
18809 _uint2fs.c
18810 \end_layout
18811
18812 \end_inset
18813 </cell>
18814 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18815 \begin_inset Text
18816
18817 \begin_layout Standard
18818
18819 \family roman
18820 \series medium
18821 \shape up
18822 \size normal
18823 \emph off
18824 \bar no
18825 \noun off
18826 \color none
18827 convert unsigned int to floating point
18828 \end_layout
18829
18830 \end_inset
18831 </cell>
18832 </row>
18833 <row topline="true">
18834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18835 \begin_inset Text
18836
18837 \begin_layout Standard
18838
18839 \family roman
18840 \series medium
18841 \shape up
18842 \size normal
18843 \emph off
18844 \bar no
18845 \noun off
18846 \color none
18847 _int2fs.c
18848 \end_layout
18849
18850 \end_inset
18851 </cell>
18852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18853 \begin_inset Text
18854
18855 \begin_layout Standard
18856
18857 \family roman
18858 \series medium
18859 \shape up
18860 \size normal
18861 \emph off
18862 \bar no
18863 \noun off
18864 \color none
18865 convert int to floating point numbers
18866 \end_layout
18867
18868 \end_inset
18869 </cell>
18870 </row>
18871 <row topline="true">
18872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18873 \begin_inset Text
18874
18875 \begin_layout Standard
18876
18877 \family roman
18878 \series medium
18879 \shape up
18880 \size normal
18881 \emph off
18882 \bar no
18883 \noun off
18884 \color none
18885 _ulong2fs.c
18886 \end_layout
18887
18888 \end_inset
18889 </cell>
18890 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18891 \begin_inset Text
18892
18893 \begin_layout Standard
18894
18895 \family roman
18896 \series medium
18897 \shape up
18898 \size normal
18899 \emph off
18900 \bar no
18901 \noun off
18902 \color none
18903 convert unsigned long to floating point number
18904 \end_layout
18905
18906 \end_inset
18907 </cell>
18908 </row>
18909 <row topline="true" bottomline="true">
18910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18911 \begin_inset Text
18912
18913 \begin_layout Standard
18914
18915 \family roman
18916 \series medium
18917 \shape up
18918 \size normal
18919 \emph off
18920 \bar no
18921 \noun off
18922 \color none
18923 _long2fs.c
18924 \end_layout
18925
18926 \end_inset
18927 </cell>
18928 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18929 \begin_inset Text
18930
18931 \begin_layout Standard
18932
18933 \family roman
18934 \series medium
18935 \shape up
18936 \size normal
18937 \emph off
18938 \bar no
18939 \noun off
18940 \color none
18941 convert long to floating point number
18942 \end_layout
18943
18944 \end_inset
18945 </cell>
18946 </row>
18947 </lyxtabular>
18948
18949 \end_inset
18950
18951
18952 \newline
18953
18954 \end_layout
18955
18956 \begin_layout Standard
18957 These support routines are developed in ANSI-C so there is room for space
18958  and speed improvement
18959 \begin_inset Foot
18960 status open
18961
18962 \begin_layout Standard
18963 These floating point routines (
18964 \emph on
18965 not
18966 \emph default
18967  sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
18968  
18969 \end_layout
18970
18971 \end_inset
18972
18973 .
18974  Note if all these routines are used simultaneously the data space might
18975  overflow.
18976  For serious floating point usage the large model might be needed.
18977  Also notice that you don't have to call this routines directly.
18978  The compiler will use them automatically every time a floating point operation
18979  is required.
18980 \begin_inset VSpace bigskip
18981 \end_inset
18982
18983
18984 \end_layout
18985
18986 \begin_layout Section
18987 Library Routines
18988 \begin_inset LatexCommand \index{Libraries}
18989
18990 \end_inset
18991
18992
18993 \end_layout
18994
18995 \begin_layout Standard
18996
18997 \emph on
18998 <pending: this is messy and incomplete - a little more information is in
18999  sdcc/doc/libdoc.txt
19000 \emph default
19001  >
19002 \end_layout
19003
19004 \begin_layout Subsection
19005 Compiler support routines (_gptrget, _mulint etc.)
19006 \end_layout
19007
19008 \begin_layout Subsection
19009 Stdclib functions (puts, printf, strcat etc.)
19010 \end_layout
19011
19012 \begin_layout Subsubsection
19013 <stdio.h>
19014 \end_layout
19015
19016 \begin_layout Paragraph
19017 getchar(), putchar()
19018 \end_layout
19019
19020 \begin_layout Standard
19021 \begin_inset LatexCommand \index{<stdio.h>}
19022
19023 \end_inset
19024
19025 As usual on embedded systems you have to provide your own 
19026 \family typewriter
19027 getchar()
19028 \begin_inset LatexCommand \index{getchar()}
19029
19030 \end_inset
19031
19032  
19033 \family default
19034 and 
19035 \family typewriter
19036 putchar()
19037 \begin_inset LatexCommand \index{putchar()}
19038
19039 \end_inset
19040
19041
19042 \family default
19043  routines.
19044  SDCC does not know whether the system connects to a serial line with or
19045  without handshake, LCD, keyboard or other device.
19046  And whether a 
19047 \family typewriter
19048 lf
19049 \family default
19050  to 
19051 \family typewriter
19052 crlf
19053 \family default
19054  conversion within 
19055 \family typewriter
19056 putchar()
19057 \family default
19058  is intended.
19059  You'll find examples for serial routines f.e.
19060  in sdcc/device/lib.
19061  For the mcs51 this minimalistic polling 
19062 \family typewriter
19063 putchar()
19064 \family default
19065  routine might be a start:
19066 \end_layout
19067
19068 \begin_layout Verse
19069
19070 \family typewriter
19071 void putchar (char c) { 
19072 \newline
19073 \InsetSpace ~
19074 \InsetSpace ~
19075 \InsetSpace ~
19076 \InsetSpace ~
19077 while (!TI)\InsetSpace ~
19078 \InsetSpace ~
19079 \InsetSpace ~
19080  /* assumes UART is initialized */
19081 \newline
19082 \InsetSpace ~
19083 \InsetSpace ~
19084 \InsetSpace ~
19085 \InsetSpace ~
19086 \InsetSpace ~
19087 \InsetSpace ~
19088 \InsetSpace ~
19089 \InsetSpace ~
19090 ;
19091 \newline
19092 \InsetSpace ~
19093 \InsetSpace ~
19094 \InsetSpace ~
19095 \InsetSpace ~
19096 TI
19097  = 0;
19098 \newline
19099 \InsetSpace ~
19100 \InsetSpace ~
19101 \InsetSpace ~
19102 \InsetSpace ~
19103 SBUF = c;
19104 \newline
19105 }
19106 \end_layout
19107
19108 \begin_layout Paragraph
19109 printf()
19110 \end_layout
19111
19112 \begin_layout Standard
19113 The default
19114 \family typewriter
19115  printf()
19116 \begin_inset LatexCommand \index{printf()}
19117
19118 \end_inset
19119
19120
19121 \family default
19122  implementation in
19123 \family typewriter
19124  printf_large.c
19125 \family default
19126  does not support float (except on ds390).
19127  To enable this recompile it with the option 
19128 \emph on
19129 -
19130 \begin_inset ERT
19131 status collapsed
19132
19133 \begin_layout Standard
19134
19135
19136 \backslash
19137 /
19138 \end_layout
19139
19140 \end_inset
19141
19142 DUSE_FLOATS=1
19143 \begin_inset LatexCommand \index{USE\_FLOATS}
19144
19145 \end_inset
19146
19147
19148 \emph default
19149  on the command line.
19150  Use
19151 \emph on
19152  -
19153 \begin_inset ERT
19154 status collapsed
19155
19156 \begin_layout Standard
19157
19158
19159 \backslash
19160 /
19161 \end_layout
19162
19163 \end_inset
19164
19165 -model-large
19166 \begin_inset LatexCommand \index{-\/-model-large}
19167
19168 \end_inset
19169
19170
19171 \emph default
19172  for the mcs51 port, since this uses a lot of memory.
19173 \end_layout
19174
19175 \begin_layout Standard
19176 If you're short on code memory you might want to use 
19177 \family typewriter
19178 printf_small()
19179 \begin_inset LatexCommand \index{printf\_small()}
19180
19181 \end_inset
19182
19183
19184 \family default
19185  
19186 \emph on
19187 instead
19188 \emph default
19189  of
19190 \family typewriter
19191  printf().
19192
19193 \family default
19194  For the mcs51 there additionally are assembly versions 
19195 \family typewriter
19196 printf_tiny()
19197 \begin_inset LatexCommand \index{printf\_tiny() (mcs51)}
19198
19199 \end_inset
19200
19201
19202 \family default
19203  (subset of printf using less than 270 bytes) and 
19204 \family typewriter
19205 printf_fast()
19206 \begin_inset LatexCommand \index{printf\_fast() (mcs51)}
19207
19208 \end_inset
19209
19210  
19211 \family default
19212 and
19213 \family typewriter
19214  printf_fast_f()
19215 \begin_inset LatexCommand \index{printf\_fast\_f() (mcs51)}
19216
19217 \end_inset
19218
19219
19220 \family default
19221  (floating-point aware version of printf_fast) which should fit the requirements
19222  of many embedded systems (printf_fast() can be customized by unsetting
19223  #defines to 
19224 \emph on
19225 not
19226 \emph default
19227  support long variables and field widths).
19228  Be sure to use only one of these printf options within a project.
19229 \newline
19230
19231 \end_layout
19232
19233 \begin_layout Standard
19234 Feature matrix of different 
19235 \emph on
19236 printf
19237 \emph default
19238  options on mcs51.
19239 \end_layout
19240
19241 \begin_layout Standard
19242 \begin_inset Tabular
19243 <lyxtabular version="3" rows="14" columns="7">
19244 <features islongtable="true">
19245 <column alignment="left" valignment="middle" leftline="true" width="14col%">
19246 <column alignment="center" valignment="top" leftline="true" width="0">
19247 <column alignment="center" valignment="top" leftline="true" width="12col%">
19248 <column alignment="center" valignment="top" leftline="true" width="10col%">
19249 <column alignment="center" valignment="top" leftline="true" width="0">
19250 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
19251 <column alignment="center" valignment="top" rightline="true" width="0">
19252 <row topline="true" bottomline="true" endhead="true">
19253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19254 \begin_inset Text
19255
19256 \begin_layout Standard
19257
19258 \series bold
19259 \size large
19260 mcs51
19261 \end_layout
19262
19263 \end_inset
19264 </cell>
19265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19266 \begin_inset Text
19267
19268 \begin_layout Standard
19269 printf
19270 \begin_inset LatexCommand \index{printf}
19271
19272 \end_inset
19273
19274
19275 \end_layout
19276
19277 \end_inset
19278 </cell>
19279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19280 \begin_inset Text
19281
19282 \begin_layout Standard
19283 printf 
19284 \size scriptsize
19285 USE_FLOATS=1
19286 \end_layout
19287
19288 \end_inset
19289 </cell>
19290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19291 \begin_inset Text
19292
19293 \begin_layout Standard
19294 printf_small
19295 \end_layout
19296
19297 \end_inset
19298 </cell>
19299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19300 \begin_inset Text
19301
19302 \begin_layout Standard
19303 printf_fast
19304 \end_layout
19305
19306 \end_inset
19307 </cell>
19308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19309 \begin_inset Text
19310
19311 \begin_layout Standard
19312 printf_fast_f
19313 \end_layout
19314
19315 \end_inset
19316 </cell>
19317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19318 \begin_inset Text
19319
19320 \begin_layout Standard
19321 printf_tiny
19322 \end_layout
19323
19324 \end_inset
19325 </cell>
19326 </row>
19327 <row topline="true" endhead="true">
19328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19329 \begin_inset Text
19330
19331 \begin_layout Standard
19332 filename
19333 \end_layout
19334
19335 \end_inset
19336 </cell>
19337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19338 \begin_inset Text
19339
19340 \begin_layout Standard
19341
19342 \size scriptsize
19343 printf_large.c
19344 \end_layout
19345
19346 \end_inset
19347 </cell>
19348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19349 \begin_inset Text
19350
19351 \begin_layout Standard
19352
19353 \size scriptsize
19354 printf_large.c
19355 \end_layout
19356
19357 \end_inset
19358 </cell>
19359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19360 \begin_inset Text
19361
19362 \begin_layout Standard
19363
19364 \size scriptsize
19365 printfl.c
19366 \end_layout
19367
19368 \end_inset
19369 </cell>
19370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19371 \begin_inset Text
19372
19373 \begin_layout Standard
19374
19375 \size scriptsize
19376 printf_fast.c
19377 \end_layout
19378
19379 \end_inset
19380 </cell>
19381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19382 \begin_inset Text
19383
19384 \begin_layout Standard
19385
19386 \size scriptsize
19387 printf_fast_f.c
19388 \end_layout
19389
19390 \end_inset
19391 </cell>
19392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19393 \begin_inset Text
19394
19395 \begin_layout Standard
19396
19397 \size scriptsize
19398 printf_tiny.c
19399 \end_layout
19400
19401 \end_inset
19402 </cell>
19403 </row>
19404 <row topline="true" endhead="true">
19405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19406 \begin_inset Text
19407
19408 \begin_layout Standard
19409 \begin_inset Quotes sld
19410 \end_inset
19411
19412 Hello World
19413 \begin_inset Quotes srd
19414 \end_inset
19415
19416  size
19417 \end_layout
19418
19419 \begin_layout Standard
19420 small / large
19421 \end_layout
19422
19423 \end_inset
19424 </cell>
19425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19426 \begin_inset Text
19427
19428 \begin_layout Standard
19429 1.7k / 2.4k
19430 \end_layout
19431
19432 \end_inset
19433 </cell>
19434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19435 \begin_inset Text
19436
19437 \begin_layout Standard
19438 4.3k / 5.6k
19439 \end_layout
19440
19441 \end_inset
19442 </cell>
19443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19444 \begin_inset Text
19445
19446 \begin_layout Standard
19447 1.2k / 1.8k
19448 \end_layout
19449
19450 \end_inset
19451 </cell>
19452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19453 \begin_inset Text
19454
19455 \begin_layout Standard
19456 1.3k / 1.3k
19457 \end_layout
19458
19459 \end_inset
19460 </cell>
19461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19462 \begin_inset Text
19463
19464 \begin_layout Standard
19465 1.9k / 1.9k
19466 \end_layout
19467
19468 \end_inset
19469 </cell>
19470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19471 \begin_inset Text
19472
19473 \begin_layout Standard
19474 0.44k / 0.44k
19475 \end_layout
19476
19477 \end_inset
19478 </cell>
19479 </row>
19480 <row topline="true" endhead="true">
19481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19482 \begin_inset Text
19483
19484 \begin_layout Standard
19485 code size
19486 \end_layout
19487
19488 \begin_layout Standard
19489 small / large
19490 \end_layout
19491
19492 \end_inset
19493 </cell>
19494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19495 \begin_inset Text
19496
19497 \begin_layout Standard
19498 1.4k / 2.0k
19499 \end_layout
19500
19501 \end_inset
19502 </cell>
19503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19504 \begin_inset Text
19505
19506 \begin_layout Standard
19507 2.8k / 3.7k
19508 \end_layout
19509
19510 \end_inset
19511 </cell>
19512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19513 \begin_inset Text
19514
19515 \begin_layout Standard
19516 0.45k / 0.47k (+ _ltoa)
19517 \end_layout
19518
19519 \end_inset
19520 </cell>
19521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19522 \begin_inset Text
19523
19524 \begin_layout Standard
19525 1.2k / 1.2k
19526 \end_layout
19527
19528 \end_inset
19529 </cell>
19530 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19531 \begin_inset Text
19532
19533 \begin_layout Standard
19534 1.6k / 1.6k
19535 \end_layout
19536
19537 \end_inset
19538 </cell>
19539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19540 \begin_inset Text
19541
19542 \begin_layout Standard
19543 0.26k / 0.26k
19544 \end_layout
19545
19546 \end_inset
19547 </cell>
19548 </row>
19549 <row topline="true">
19550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19551 \begin_inset Text
19552
19553 \begin_layout Standard
19554 formats
19555 \end_layout
19556
19557 \end_inset
19558 </cell>
19559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19560 \begin_inset Text
19561
19562 \begin_layout Standard
19563 cdi
19564 \emph on
19565 o
19566 \emph default
19567 psux
19568 \end_layout
19569
19570 \end_inset
19571 </cell>
19572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19573 \begin_inset Text
19574
19575 \begin_layout Standard
19576
19577 \family roman
19578 \series medium
19579 \shape up
19580 \size normal
19581 \emph off
19582 \bar no
19583 \noun off
19584 \color none
19585 cd
19586 \family default
19587 \series default
19588 \shape default
19589 \size default
19590 \emph default
19591 \bar default
19592 \noun default
19593 f
19594 \family roman
19595 \series medium
19596 \shape up
19597 \size normal
19598 \emph off
19599 \bar no
19600 \noun off
19601 i
19602 \family default
19603 \series default
19604 \shape default
19605 \size default
19606 \emph on
19607 \bar default
19608 \noun default
19609 o
19610 \family roman
19611 \series medium
19612 \shape up
19613 \size normal
19614 \emph off
19615 \bar no
19616 \noun off
19617 psux
19618 \end_layout
19619
19620 \end_inset
19621 </cell>
19622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19623 \begin_inset Text
19624
19625 \begin_layout Standard
19626 c
19627 \family roman
19628 \series medium
19629 \shape up
19630 \size normal
19631 \emph off
19632 \bar no
19633 \noun off
19634 \color none
19635 d
19636 \family default
19637 \series default
19638 \shape default
19639 \size default
19640 \emph on
19641 \bar default
19642 \noun default
19643 o
19644 \family roman
19645 \series medium
19646 \shape up
19647 \size normal
19648 \emph off
19649 \bar no
19650 \noun off
19651 s
19652 \family default
19653 \series default
19654 \shape default
19655 \size default
19656 \emph default
19657 \bar default
19658 \noun default
19659 x
19660 \end_layout
19661
19662 \end_inset
19663 </cell>
19664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19665 \begin_inset Text
19666
19667 \begin_layout Standard
19668 cdsux
19669 \end_layout
19670
19671 \end_inset
19672 </cell>
19673 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19674 \begin_inset Text
19675
19676 \begin_layout Standard
19677 cdfsux
19678 \end_layout
19679
19680 \end_inset
19681 </cell>
19682 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19683 \begin_inset Text
19684
19685 \begin_layout Standard
19686 cdsux
19687 \end_layout
19688
19689 \end_inset
19690 </cell>
19691 </row>
19692 <row topline="true">
19693 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19694 \begin_inset Text
19695
19696 \begin_layout Standard
19697 long (32 bit) support
19698 \end_layout
19699
19700 \end_inset
19701 </cell>
19702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19703 \begin_inset Text
19704
19705 \begin_layout Standard
19706 x
19707 \end_layout
19708
19709 \end_inset
19710 </cell>
19711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19712 \begin_inset Text
19713
19714 \begin_layout Standard
19715 x
19716 \end_layout
19717
19718 \end_inset
19719 </cell>
19720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19721 \begin_inset Text
19722
19723 \begin_layout Standard
19724 x
19725 \end_layout
19726
19727 \end_inset
19728 </cell>
19729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19730 \begin_inset Text
19731
19732 \begin_layout Standard
19733 x
19734 \end_layout
19735
19736 \end_inset
19737 </cell>
19738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19739 \begin_inset Text
19740
19741 \begin_layout Standard
19742
19743 \family roman
19744 \series medium
19745 \shape up
19746 \size normal
19747 \emph off
19748 \bar no
19749 \noun off
19750 \color none
19751 x
19752 \end_layout
19753
19754 \end_inset
19755 </cell>
19756 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19757 \begin_inset Text
19758
19759 \begin_layout Standard
19760 -
19761 \end_layout
19762
19763 \end_inset
19764 </cell>
19765 </row>
19766 <row topline="true">
19767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19768 \begin_inset Text
19769
19770 \begin_layout Standard
19771 byte arguments on stack
19772 \end_layout
19773
19774 \end_inset
19775 </cell>
19776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19777 \begin_inset Text
19778
19779 \begin_layout Standard
19780 b
19781 \end_layout
19782
19783 \end_inset
19784 </cell>
19785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19786 \begin_inset Text
19787
19788 \begin_layout Standard
19789 b
19790 \end_layout
19791
19792 \end_inset
19793 </cell>
19794 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19795 \begin_inset Text
19796
19797 \begin_layout Standard
19798 -
19799 \end_layout
19800
19801 \end_inset
19802 </cell>
19803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19804 \begin_inset Text
19805
19806 \begin_layout Standard
19807 -
19808 \end_layout
19809
19810 \end_inset
19811 </cell>
19812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19813 \begin_inset Text
19814
19815 \begin_layout Standard
19816 -
19817 \end_layout
19818
19819 \end_inset
19820 </cell>
19821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19822 \begin_inset Text
19823
19824 \begin_layout Standard
19825 -
19826 \end_layout
19827
19828 \end_inset
19829 </cell>
19830 </row>
19831 <row topline="true">
19832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19833 \begin_inset Text
19834
19835 \begin_layout Standard
19836 float format
19837 \begin_inset LatexCommand \index{Floating point support}
19838
19839 \end_inset
19840
19841
19842 \end_layout
19843
19844 \end_inset
19845 </cell>
19846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19847 \begin_inset Text
19848
19849 \begin_layout Standard
19850 -
19851 \end_layout
19852
19853 \end_inset
19854 </cell>
19855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19856 \begin_inset Text
19857
19858 \begin_layout Standard
19859 %f
19860 \end_layout
19861
19862 \end_inset
19863 </cell>
19864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19865 \begin_inset Text
19866
19867 \begin_layout Standard
19868 -
19869 \end_layout
19870
19871 \end_inset
19872 </cell>
19873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19874 \begin_inset Text
19875
19876 \begin_layout Standard
19877 -
19878 \end_layout
19879
19880 \end_inset
19881 </cell>
19882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19883 \begin_inset Text
19884
19885 \begin_layout Standard
19886 %f
19887 \begin_inset Foot
19888 status collapsed
19889
19890 \begin_layout Standard
19891 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
19892 \end_layout
19893
19894 \end_inset
19895
19896
19897 \end_layout
19898
19899 \end_inset
19900 </cell>
19901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19902 \begin_inset Text
19903
19904 \begin_layout Standard
19905 -
19906 \end_layout
19907
19908 \end_inset
19909 </cell>
19910 </row>
19911 <row topline="true">
19912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19913 \begin_inset Text
19914
19915 \begin_layout Standard
19916 float formats %e %g
19917 \end_layout
19918
19919 \end_inset
19920 </cell>
19921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19922 \begin_inset Text
19923
19924 \begin_layout Standard
19925 -
19926 \end_layout
19927
19928 \end_inset
19929 </cell>
19930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19931 \begin_inset Text
19932
19933 \begin_layout Standard
19934 -
19935 \end_layout
19936
19937 \end_inset
19938 </cell>
19939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19940 \begin_inset Text
19941
19942 \begin_layout Standard
19943 -
19944 \end_layout
19945
19946 \end_inset
19947 </cell>
19948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19949 \begin_inset Text
19950
19951 \begin_layout Standard
19952 -
19953 \end_layout
19954
19955 \end_inset
19956 </cell>
19957 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19958 \begin_inset Text
19959
19960 \begin_layout Standard
19961 -
19962 \end_layout
19963
19964 \end_inset
19965 </cell>
19966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19967 \begin_inset Text
19968
19969 \begin_layout Standard
19970 -
19971 \end_layout
19972
19973 \end_inset
19974 </cell>
19975 </row>
19976 <row topline="true" bottomline="true">
19977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19978 \begin_inset Text
19979
19980 \begin_layout Standard
19981 field width
19982 \end_layout
19983
19984 \end_inset
19985 </cell>
19986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19987 \begin_inset Text
19988
19989 \begin_layout Standard
19990 x
19991 \end_layout
19992
19993 \end_inset
19994 </cell>
19995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19996 \begin_inset Text
19997
19998 \begin_layout Standard
19999 x
20000 \end_layout
20001
20002 \end_inset
20003 </cell>
20004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20005 \begin_inset Text
20006
20007 \begin_layout Standard
20008 -
20009 \end_layout
20010
20011 \end_inset
20012 </cell>
20013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20014 \begin_inset Text
20015
20016 \begin_layout Standard
20017 x
20018 \end_layout
20019
20020 \end_inset
20021 </cell>
20022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20023 \begin_inset Text
20024
20025 \begin_layout Standard
20026 x
20027 \end_layout
20028
20029 \end_inset
20030 </cell>
20031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20032 \begin_inset Text
20033
20034 \begin_layout Standard
20035 -
20036 \end_layout
20037
20038 \end_inset
20039 </cell>
20040 </row>
20041 <row bottomline="true">
20042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20043 \begin_inset Text
20044
20045 \begin_layout Standard
20046 string speed
20047 \begin_inset Foot
20048 status collapsed
20049
20050 \begin_layout Standard
20051 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
20052 \backslash
20053 r', '
20054 \backslash
20055 n'); standard 8051 @ 22.1184 MHz, empty putchar()
20056 \end_layout
20057
20058 \end_inset
20059
20060 ,
20061 \end_layout
20062
20063 \begin_layout Standard
20064 small / large
20065 \end_layout
20066
20067 \end_inset
20068 </cell>
20069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20070 \begin_inset Text
20071
20072 \begin_layout Standard
20073 1.52 / 2.59 ms
20074 \end_layout
20075
20076 \end_inset
20077 </cell>
20078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20079 \begin_inset Text
20080
20081 \begin_layout Standard
20082 1.53 / 2.62 ms
20083 \end_layout
20084
20085 \end_inset
20086 </cell>
20087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20088 \begin_inset Text
20089
20090 \begin_layout Standard
20091 0.92 / 0.93 ms
20092 \end_layout
20093
20094 \end_inset
20095 </cell>
20096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20097 \begin_inset Text
20098
20099 \begin_layout Standard
20100 0.45 / 0.45 ms
20101 \end_layout
20102
20103 \end_inset
20104 </cell>
20105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20106 \begin_inset Text
20107
20108 \begin_layout Standard
20109 0.46 / 0.46 ms
20110 \end_layout
20111
20112 \end_inset
20113 </cell>
20114 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20115 \begin_inset Text
20116
20117 \begin_layout Standard
20118 0.45 / 0.45 ms
20119 \end_layout
20120
20121 \end_inset
20122 </cell>
20123 </row>
20124 <row bottomline="true">
20125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20126 \begin_inset Text
20127
20128 \begin_layout Standard
20129 int speed
20130 \begin_inset Foot
20131 status collapsed
20132
20133 \begin_layout Standard
20134 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
20135  putchar()
20136 \end_layout
20137
20138 \end_inset
20139
20140 ,
20141 \end_layout
20142
20143 \begin_layout Standard
20144 small / large
20145 \end_layout
20146
20147 \end_inset
20148 </cell>
20149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20150 \begin_inset Text
20151
20152 \begin_layout Standard
20153 3.01 / 3.61 ms
20154 \end_layout
20155
20156 \end_inset
20157 </cell>
20158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20159 \begin_inset Text
20160
20161 \begin_layout Standard
20162 3.01 / 3.61 ms
20163 \end_layout
20164
20165 \end_inset
20166 </cell>
20167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20168 \begin_inset Text
20169
20170 \begin_layout Standard
20171 3.51 / 18.13 ms
20172 \end_layout
20173
20174 \end_inset
20175 </cell>
20176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20177 \begin_inset Text
20178
20179 \begin_layout Standard
20180 0.22 / 0.22 ms
20181 \end_layout
20182
20183 \end_inset
20184 </cell>
20185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20186 \begin_inset Text
20187
20188 \begin_layout Standard
20189 0.23 / 0.23 ms
20190 \end_layout
20191
20192 \end_inset
20193 </cell>
20194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20195 \begin_inset Text
20196
20197 \begin_layout Standard
20198 0.25 / 0.25 ms
20199 \begin_inset Foot
20200 status collapsed
20201
20202 \begin_layout Standard
20203 printf_tiny integer speed is data dependent, worst case is 0.33 ms
20204 \end_layout
20205
20206 \end_inset
20207
20208
20209 \end_layout
20210
20211 \end_inset
20212 </cell>
20213 </row>
20214 <row bottomline="true">
20215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20216 \begin_inset Text
20217
20218 \begin_layout Standard
20219 long speed
20220 \begin_inset Foot
20221 status collapsed
20222
20223 \begin_layout Standard
20224 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
20225  empty putchar()
20226 \end_layout
20227
20228 \end_inset
20229
20230 ,
20231 \end_layout
20232
20233 \begin_layout Standard
20234 small / large
20235 \end_layout
20236
20237 \end_inset
20238 </cell>
20239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20240 \begin_inset Text
20241
20242 \begin_layout Standard
20243 5.37 / 6.31 ms
20244 \end_layout
20245
20246 \end_inset
20247 </cell>
20248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20249 \begin_inset Text
20250
20251 \begin_layout Standard
20252 5.37 / 6.31 ms
20253 \end_layout
20254
20255 \end_inset
20256 </cell>
20257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20258 \begin_inset Text
20259
20260 \begin_layout Standard
20261 8.71 / 40.65 ms
20262 \end_layout
20263
20264 \end_inset
20265 </cell>
20266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20267 \begin_inset Text
20268
20269 \begin_layout Standard
20270 0.40 / 0.40 ms
20271 \end_layout
20272
20273 \end_inset
20274 </cell>
20275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20276 \begin_inset Text
20277
20278 \begin_layout Standard
20279 0.40 / 0.40 ms
20280 \end_layout
20281
20282 \end_inset
20283 </cell>
20284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20285 \begin_inset Text
20286
20287 \begin_layout Standard
20288 -
20289 \end_layout
20290
20291 \end_inset
20292 </cell>
20293 </row>
20294 <row bottomline="true">
20295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20296 \begin_inset Text
20297
20298 \begin_layout Standard
20299 float speed
20300 \begin_inset Foot
20301 status collapsed
20302
20303 \begin_layout Standard
20304 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
20305  empty putchar()
20306 \end_layout
20307
20308 \end_inset
20309
20310 ,
20311 \end_layout
20312
20313 \begin_layout Standard
20314 small / large
20315 \end_layout
20316
20317 \end_inset
20318 </cell>
20319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20320 \begin_inset Text
20321
20322 \begin_layout Standard
20323 -
20324 \end_layout
20325
20326 \end_inset
20327 </cell>
20328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20329 \begin_inset Text
20330
20331 \begin_layout Standard
20332 7.49 / 22.47 ms
20333 \end_layout
20334
20335 \end_inset
20336 </cell>
20337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20338 \begin_inset Text
20339
20340 \begin_layout Standard
20341 -
20342 \end_layout
20343
20344 \end_inset
20345 </cell>
20346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20347 \begin_inset Text
20348
20349 \begin_layout Standard
20350 -
20351 \end_layout
20352
20353 \end_inset
20354 </cell>
20355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20356 \begin_inset Text
20357
20358 \begin_layout Standard
20359 1.04 / 1.04 ms
20360 \end_layout
20361
20362 \end_inset
20363 </cell>
20364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20365 \begin_inset Text
20366
20367 \begin_layout Standard
20368 -
20369 \end_layout
20370
20371 \end_inset
20372 </cell>
20373 </row>
20374 </lyxtabular>
20375
20376 \end_inset
20377
20378
20379 \end_layout
20380
20381 \begin_layout Subsubsection
20382 <malloc.h>
20383 \begin_inset LatexCommand \index{malloc.h}
20384
20385 \end_inset
20386
20387
20388 \end_layout
20389
20390 \begin_layout Standard
20391 As of SDCC 2.6.2 you no longer need to call an initialization routine before
20392  using dynamic memory allocation
20393 \begin_inset LatexCommand \index{dynamic memory allocation (malloc)}
20394
20395 \end_inset
20396
20397  and a default heap
20398 \begin_inset LatexCommand \index{heap (malloc)}
20399
20400 \end_inset
20401
20402  space of 1024 bytes is provided for malloc to allocate memory from.
20403  If you need a different heap size you need to recompile _heap.c with the
20404  required size defined in HEAP_SIZE.
20405  It is recommended to make a copy of this file into your project directory
20406  and compile it there with:
20407 \end_layout
20408
20409 \begin_layout Verse
20410
20411 \family typewriter
20412 sdcc -c _heap.c -D HEAD_SIZE=2048
20413 \end_layout
20414
20415 \begin_layout Standard
20416 And then link it with:
20417 \end_layout
20418
20419 \begin_layout Verse
20420
20421 \family typewriter
20422 sdcc main.rel _heap.rel
20423 \end_layout
20424
20425 \begin_layout Subsection
20426 Math functions (sinf, powf, sqrtf etc.)
20427 \end_layout
20428
20429 \begin_layout Subsubsection
20430 <math.h>
20431 \end_layout
20432
20433 \begin_layout Standard
20434 See definitions in file <math.h>.
20435 \end_layout
20436
20437 \begin_layout Subsection
20438 Other libraries
20439 \end_layout
20440
20441 \begin_layout Standard
20442 Libraries
20443 \begin_inset LatexCommand \index{Libraries}
20444
20445 \end_inset
20446
20447  included in SDCC should have a license at least as liberal as the GNU Lesser
20448  General Public License
20449 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
20450
20451 \end_inset
20452
20453  
20454 \emph on
20455 LGPL
20456 \emph default
20457 .
20458 \end_layout
20459
20460 \begin_layout Standard
20461 \begin_inset Note Note
20462 status collapsed
20463
20464 \begin_layout Standard
20465 license statements for the libraries are missing.
20466  sdcc/device/lib/ser_ir.c
20467 \end_layout
20468
20469 \begin_layout Standard
20470 or _decdptr f.e.
20471  come with a GPL (as opposed to LGPL) License - this will not be liberal
20472  enough for many embedded programmers.
20473 \end_layout
20474
20475 \end_inset
20476
20477
20478 \end_layout
20479
20480 \begin_layout Standard
20481 If you have ported some library or want to share experience about some code
20482  which f.e.
20483  falls into any of these categories Busses (I
20484 \begin_inset Formula $^{\textrm{2}}$
20485 \end_inset
20486
20487 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
20488  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
20489  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
20490 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
20491
20492 \end_inset
20493
20494 \InsetSpace ~
20495 would certainly like to hear about it.
20496 \end_layout
20497
20498 \begin_layout Standard
20499 Programmers coding for embedded systems are not especially famous for being
20500  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
20501 e these references are very valuable.
20502  Let's help to create a climate where information is shared.
20503 \begin_inset VSpace bigskip
20504 \end_inset
20505
20506
20507 \end_layout
20508
20509 \begin_layout Section
20510 Memory Models
20511 \end_layout
20512
20513 \begin_layout Subsection
20514 MCS51 Memory Models
20515 \begin_inset LatexCommand \index{Memory model}
20516
20517 \end_inset
20518
20519
20520 \begin_inset LatexCommand \index{MCS51 memory model}
20521
20522 \end_inset
20523
20524
20525 \end_layout
20526
20527 \begin_layout Subsubsection
20528 Small, Medium and Large
20529 \end_layout
20530
20531 \begin_layout Standard
20532 SDCC allows three memory models for MCS51 code, 
20533 \shape slanted
20534 small, medium
20535 \shape default
20536  and 
20537 \shape slanted
20538 large
20539 \shape default
20540 .
20541  Modules compiled with different memory models should 
20542 \emph on
20543 never
20544 \emph default
20545  be combined together or the results would be unpredictable.
20546  The library routines supplied with the compiler are compiled as small,
20547  medium and large.
20548  The compiled library modules are contained in separate directories as small,
20549  medium and large so that you can link to the appropriate set.
20550 \end_layout
20551
20552 \begin_layout Standard
20553 When the medium or large model is used all variables declared without a
20554  storage class will be allocated into the external ram, this includes all
20555  parameters and local variables (for non-reentrant
20556 \begin_inset LatexCommand \index{reentrant}
20557
20558 \end_inset
20559
20560  functions).
20561  When the small model is used variables without storage class are allocated
20562  in the internal ram.
20563 \end_layout
20564
20565 \begin_layout Standard
20566 Judicious usage of the processor specific storage classes
20567 \begin_inset LatexCommand \index{Storage class}
20568
20569 \end_inset
20570
20571  and the 'reentrant' function type will yield much more efficient code,
20572  than using the large model.
20573  Several optimizations are disabled when the program is compiled using the
20574  large model, it is therefore recommended that the small model be used unless
20575  absolutely required.
20576 \end_layout
20577
20578 \begin_layout Subsubsection
20579 External Stack
20580 \begin_inset LatexCommand \label{sub:External-Stack}
20581
20582 \end_inset
20583
20584
20585 \begin_inset LatexCommand \index{stack}
20586
20587 \end_inset
20588
20589
20590 \begin_inset LatexCommand \index{External stack (mcs51)}
20591
20592 \end_inset
20593
20594
20595 \end_layout
20596
20597 \begin_layout Standard
20598 The external stack (-
20599 \begin_inset ERT
20600 status collapsed
20601
20602 \begin_layout Standard
20603
20604
20605 \backslash
20606 /
20607 \end_layout
20608
20609 \end_inset
20610
20611 -xstack option
20612 \begin_inset LatexCommand \index{-\/-xstack}
20613
20614 \end_inset
20615
20616 ) is located in pdata
20617 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
20618
20619 \end_inset
20620
20621  memory (usually at the start of the external ram segment) and uses all
20622  unused space in pdata (max.
20623  256 bytes).
20624  When -
20625 \begin_inset ERT
20626 status collapsed
20627
20628 \begin_layout Standard
20629
20630
20631 \backslash
20632 /
20633 \end_layout
20634
20635 \end_inset
20636
20637 -xstack option is used to compile the program, the parameters and local
20638  variables
20639 \begin_inset LatexCommand \index{local variables}
20640
20641 \end_inset
20642
20643  of all reentrant functions are allocated in this area.
20644  This option is provided for programs with large stack space requirements.
20645  When used with the -
20646 \begin_inset ERT
20647 status collapsed
20648
20649 \begin_layout Standard
20650
20651
20652 \backslash
20653 /
20654 \end_layout
20655
20656 \end_inset
20657
20658 -stack-auto
20659 \begin_inset LatexCommand \index{-\/-stack-auto}
20660
20661 \end_inset
20662
20663  option, all parameters and local variables are allocated on the external
20664  stack (note: support libraries will need to be recompiled with the same
20665  options.
20666  There is a predefined target in the library makefile).
20667 \end_layout
20668
20669 \begin_layout Standard
20670 The compiler outputs the higher order address byte of the external ram segment
20671  into port P2
20672 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
20673
20674 \end_inset
20675
20676  (see also section 
20677 \begin_inset LatexCommand \ref{sub:MCS51-variants}
20678
20679 \end_inset
20680
20681 ), therefore when using the External Stack option, this port 
20682 \emph on
20683 may not
20684 \emph default
20685  be used by the application program.
20686 \end_layout
20687
20688 \begin_layout Subsection
20689 DS390 Memory Model
20690 \begin_inset LatexCommand \index{Memory model}
20691
20692 \end_inset
20693
20694
20695 \begin_inset LatexCommand \index{DS390 memory model}
20696
20697 \end_inset
20698
20699
20700 \end_layout
20701
20702 \begin_layout Standard
20703 The only model supported is Flat 24
20704 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
20705
20706 \end_inset
20707
20708 .
20709  This generates code for the 24 bit contiguous addressing mode of the Dallas
20710  DS80C390 part.
20711  In this mode, up to four meg of external RAM or code space can be directly
20712  addressed.
20713  See the data sheets at www.dalsemi.com for further information on this part.
20714 \newline
20715
20716 \newline
20717 Note
20718  that the compiler does not generate any code to place the processor into
20719  24 bitmode (although 
20720 \emph on
20721 tinibios
20722 \emph default
20723  in the ds390 libraries will do that for you).
20724  If you don't use 
20725 \emph on
20726 tinibios
20727 \emph default
20728
20729 \begin_inset LatexCommand \index{Tinibios (DS390)}
20730
20731 \end_inset
20732
20733 , the boot loader or similar code must ensure that the processor is in 24
20734  bit contiguous addressing mode before calling the SDCC startup code.
20735 \newline
20736
20737 \newline
20738 Like
20739  the 
20740 \emph on
20741 -
20742 \begin_inset ERT
20743 status collapsed
20744
20745 \begin_layout Standard
20746
20747
20748 \backslash
20749 /
20750 \end_layout
20751
20752 \end_inset
20753
20754 -model-large
20755 \emph default
20756  option, variables will by default be placed into the XDATA segment.
20757  
20758 \newline
20759
20760 \newline
20761 Segments may be placed anywhere in the 4 meg address space using the usual
20762  -
20763 \begin_inset ERT
20764 status collapsed
20765
20766 \begin_layout Standard
20767
20768
20769 \backslash
20770 /
20771 \end_layout
20772
20773 \end_inset
20774
20775 -*-loc options.
20776  Note that if any segments are located above 64K, the -r flag must be passed
20777  to the linker to generate the proper segment relocations, and the Intel
20778  HEX output format must be used.
20779  The -r flag can be passed to the linker by using the option 
20780 \emph on
20781 -Wl-r
20782 \emph default
20783  on the SDCC command line.
20784  However, currently the linker can not handle code segments > 64k.
20785 \end_layout
20786
20787 \begin_layout Section
20788 Pragmas
20789 \begin_inset LatexCommand \label{sec:Pragmas}
20790
20791 \end_inset
20792
20793
20794 \begin_inset LatexCommand \index{Pragmas}
20795
20796 \end_inset
20797
20798
20799 \end_layout
20800
20801 \begin_layout Standard
20802 Pragmas are used to turn on and/or off certain compiler options.
20803  Some of them are closely related to corresponding command-line options
20804  (see section 
20805 \begin_inset LatexCommand \vref{sec:Command-Line-Options}
20806
20807 \end_inset
20808
20809 ).
20810 \newline
20811 Pragmas should be placed before and/or after a function, placing pragmas
20812  inside a function body could have unpredictable results.
20813 \newline
20814
20815 \newline
20816 SDCC supports the
20817  following #pragma directives:
20818 \end_layout
20819
20820 \begin_layout Itemize
20821
20822 \series bold
20823 save
20824 \series default
20825
20826 \begin_inset LatexCommand \index{\#pragma save}
20827
20828 \end_inset
20829
20830  - this will save most current options to the save/restore stack.
20831  See #pragma\InsetSpace ~
20832 restore.
20833 \end_layout
20834
20835 \begin_layout Itemize
20836
20837 \series bold
20838 restore
20839 \series default
20840
20841 \begin_inset LatexCommand \index{\#pragma restore}
20842
20843 \end_inset
20844
20845  - will restore saved options from the last save.
20846  saves & restores can be nested.
20847  SDCC uses a save/restore stack: save pushes current options to the stack,
20848  restore pulls current options from the stack.
20849  See #pragma\InsetSpace ~
20850 save.
20851 \newline
20852
20853 \end_layout
20854
20855 \begin_layout Itemize
20856
20857 \series bold
20858 callee_saves
20859 \series default
20860
20861 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20862
20863 \end_inset
20864
20865
20866 \begin_inset LatexCommand \index{function prologue}
20867
20868 \end_inset
20869
20870  function1[,function2[,function3...]] 
20871 \begin_inset LatexCommand \label{ite:callee_saves-function1[,function2[,function3...]]--}
20872
20873 \end_inset
20874
20875 - The compiler by default uses a caller saves convention for register saving
20876  across function calls, however this can cause unnecessary register pushing
20877  and popping
20878 \begin_inset LatexCommand \index{push/pop}
20879
20880 \end_inset
20881
20882  when calling small functions from larger functions.
20883  This option can be used to switch off the register saving convention for
20884  the function names specified.
20885  The compiler will not save registers when calling these functions, extra
20886  code need to be manually inserted at the entry and exit for these functions
20887  to save and restore the registers used by these functions, this can SUBSTANTIAL
20888 LY reduce code and improve run time performance of the generated code.
20889  In the future the compiler (with inter procedural analysis) may be able
20890  to determine the appropriate scheme to use for each function call.
20891  If -
20892 \begin_inset ERT
20893 status collapsed
20894
20895 \begin_layout Standard
20896
20897
20898 \backslash
20899 /
20900 \end_layout
20901
20902 \end_inset
20903
20904 -callee-saves command line option is used (see page 
20905 \begin_inset LatexCommand \vpageref{lyx:--callee-saves-function1[,function2][,function3]...}
20906
20907 \end_inset
20908
20909 ), the function names specified in #pragma\InsetSpace ~
20910 callee_saves
20911 \begin_inset LatexCommand \index{\#pragma callee\_saves}
20912
20913 \end_inset
20914
20915  is appended to the list of functions specified in the command line.
20916 \end_layout
20917
20918 \begin_layout Itemize
20919
20920 \series bold
20921 exclude
20922 \series default
20923
20924 \begin_inset LatexCommand \index{\#pragma exclude}
20925
20926 \end_inset
20927
20928  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
20929  of pairs of push/pop
20930 \begin_inset LatexCommand \index{push/pop}
20931
20932 \end_inset
20933
20934  instructions in 
20935 \emph on
20936 I
20937 \emph default
20938 nterrupt
20939 \begin_inset LatexCommand \index{interrupt}
20940
20941 \end_inset
20942
20943  
20944 \emph on
20945 S
20946 \emph default
20947 ervice 
20948 \emph on
20949 R
20950 \emph default
20951 outines.
20952  The directive should be placed immediately before the ISR function definition
20953  and it affects ALL ISR functions following it.
20954  To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
20955 exclude\InsetSpace ~
20956 none
20957 \begin_inset LatexCommand \index{\#pragma exclude}
20958
20959 \end_inset
20960
20961 .
20962  See also the related keyword _naked
20963 \begin_inset LatexCommand \index{\_naked}
20964
20965 \end_inset
20966
20967
20968 \begin_inset LatexCommand \index{\_\_naked}
20969
20970 \end_inset
20971
20972 .
20973 \end_layout
20974
20975 \begin_layout Itemize
20976
20977 \series bold
20978 less_pedantic
20979 \series default
20980
20981 \begin_inset LatexCommand \index{pedantic}
20982
20983 \end_inset
20984
20985
20986 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
20987
20988 \end_inset
20989
20990  
20991 \begin_inset LatexCommand \label{ite:less_pedantic}
20992
20993 \end_inset
20994
20995 - the compiler will not warn you anymore for obvious mistakes, you'r on
20996  your own now ;-( .
20997  See also the command line option -
20998 \begin_inset ERT
20999 status collapsed
21000
21001 \begin_layout Standard
21002
21003
21004 \backslash
21005 /
21006 \end_layout
21007
21008 \end_inset
21009
21010 -less-pedantic 
21011 \begin_inset LatexCommand \vpageref{lyx:--less-pedantic}
21012
21013 \end_inset
21014
21015 .
21016  
21017 \newline
21018 More specifically, the following warnings will be disabled: 
21019 \shape italic
21020 comparison is always [true/false] due to limited range of data type
21021 \shape default
21022  (94); 
21023 \shape italic
21024 overflow in implicit constant conversion
21025 \shape default
21026  (158); [the (in)famous] 
21027 \shape italic
21028 conditional flow changed by optimizer: so said EVELYN the modified DOG
21029 \shape default
21030  (110); 
21031 \shape italic
21032 function '[function name]' must return value
21033 \shape default
21034  (59).
21035  
21036 \newline
21037 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
21038  level) are disabled, too, namely: 
21039 \shape italic
21040 constant value '[
21041 \begin_inset Note Note
21042 status collapsed
21043
21044 \begin_layout Standard
21045 dunno what comes here - this warning appears to be unused altogether
21046 \end_layout
21047
21048 \end_inset
21049
21050 ]', out of range
21051 \shape default
21052  (81); 
21053 \shape italic
21054 [left/right] shifting more than size of object changed to zero
21055 \shape default
21056  (116); 
21057 \shape italic
21058 unreachable code
21059 \shape default
21060  (126); 
21061 \shape italic
21062 integer overflow in expression
21063 \shape default
21064  (165); 
21065 \shape italic
21066 unmatched #pragma save and #pragma restore
21067 \shape default
21068  (170); 
21069 \shape italic
21070 comparison of 'signed char' with 'unsigned char' requires promotion to int
21071 \shape default
21072  (185); 
21073 \shape italic
21074 ISO C90 does not support flexible array members
21075 \shape default
21076  (187); 
21077 \shape italic
21078 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
21079 nam
21080 e]':\InsetSpace ~
21081 [
21082 \begin_inset Note Note
21083 status collapsed
21084
21085 \begin_layout Standard
21086 appears to be always blank - what was supposed to be here?
21087 \end_layout
21088
21089 \end_inset
21090
21091 ]
21092 \shape default
21093  (114); 
21094 \shape italic
21095 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
21096  complexity [number]
21097 \shape default
21098  (121).
21099 \end_layout
21100
21101 \begin_layout Itemize
21102
21103 \series bold
21104 disable_warning
21105 \series default
21106  <nnnn>
21107 \begin_inset LatexCommand \index{\#pragma disable\_warning}
21108
21109 \end_inset
21110
21111  - the compiler will not warn you anymore about warning number <nnnn>.
21112 \end_layout
21113
21114 \begin_layout Itemize
21115
21116 \series bold
21117 nogcse
21118 \series default
21119
21120 \begin_inset LatexCommand \index{\#pragma nogcse}
21121
21122 \end_inset
21123
21124  - will stop global common subexpression elimination.
21125 \end_layout
21126
21127 \begin_layout Itemize
21128
21129 \series bold
21130 noinduction
21131 \series default
21132
21133 \begin_inset LatexCommand \index{\#pragma noinduction}
21134
21135 \end_inset
21136
21137  - will stop loop induction optimizations.
21138 \end_layout
21139
21140 \begin_layout Itemize
21141
21142 \series bold
21143 noinvariant
21144 \series default
21145
21146 \begin_inset LatexCommand \index{\#pragma noinvariant}
21147
21148 \end_inset
21149
21150  - will not do loop invariant optimizations.
21151  For more details see Loop Invariants in section
21152 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
21153
21154 \end_inset
21155
21156 .
21157 \end_layout
21158
21159 \begin_layout Itemize
21160
21161 \series bold
21162 noiv
21163 \series default
21164
21165 \begin_inset LatexCommand \index{\#pragma noiv}
21166
21167 \end_inset
21168
21169  - Do not generate interrupt
21170 \begin_inset LatexCommand \index{interrupt}
21171
21172 \end_inset
21173
21174  vector table
21175 \begin_inset LatexCommand \index{interrupt vector table}
21176
21177 \end_inset
21178
21179  entries for all ISR functions defined after the pragma.
21180  This is useful in cases where the interrupt vector table must be defined
21181  manually, or when there is a secondary, manually defined interrupt vector
21182  table (e.g.
21183  for the autovector feature of the Cypress EZ-USB FX2).
21184  More elegantly this can be achieved by obmitting the optional interrupt
21185  number after the interrupt keyword, see section 
21186 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
21187
21188 \end_inset
21189
21190 \InsetSpace ~
21191 about interrupts.
21192 \end_layout
21193
21194 \begin_layout Itemize
21195
21196 \series bold
21197 nojtbound
21198 \series default
21199
21200 \begin_inset LatexCommand \index{\#pragma nojtbound}
21201
21202 \end_inset
21203
21204  - will not generate code for boundary value checking, when switch statements
21205  are turned into jump-tables (dangerous).
21206  For more details see section 
21207 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
21208
21209 \end_inset
21210
21211 .
21212 \end_layout
21213
21214 \begin_layout Itemize
21215
21216 \series bold
21217 noloopreverse
21218 \series default
21219
21220 \begin_inset LatexCommand \index{\#pragma noloopreverse}
21221
21222 \end_inset
21223
21224  - Will not do loop reversal optimization
21225 \end_layout
21226
21227 \begin_layout Itemize
21228
21229 \series bold
21230 nooverlay
21231 \series default
21232
21233 \begin_inset LatexCommand \index{\#pragma nooverlay}
21234
21235 \end_inset
21236
21237  - the compiler will not overlay the parameters and local variables of a
21238  function.
21239 \end_layout
21240
21241 \begin_layout Itemize
21242
21243 \series bold
21244 stackauto
21245 \series default
21246
21247 \begin_inset LatexCommand \index{\#pragma stackauto}
21248
21249 \end_inset
21250
21251 - See option -
21252 \begin_inset ERT
21253 status collapsed
21254
21255 \begin_layout Standard
21256
21257
21258 \backslash
21259 /
21260 \end_layout
21261
21262 \end_inset
21263
21264 -stack-auto
21265 \begin_inset LatexCommand \index{-\/-stack-auto}
21266
21267 \end_inset
21268
21269  and section 
21270 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
21271
21272 \end_inset
21273
21274  Parameters and Local Variables.
21275 \end_layout
21276
21277 \begin_layout Itemize
21278
21279 \series bold
21280 opt_code_speed
21281 \series default
21282  
21283 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
21284
21285 \end_inset
21286
21287 - The compiler will optimize code generation towards fast code, possibly
21288  at the expense of code size.
21289  Currently this has little effect.
21290 \end_layout
21291
21292 \begin_layout Itemize
21293
21294 \series bold
21295 opt_code_size
21296 \series default
21297  
21298 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
21299
21300 \end_inset
21301
21302 - The compiler will optimize code generation towards compact code, possibly
21303  at the expense of code speed.
21304  Currently this has little effect.
21305 \end_layout
21306
21307 \begin_layout Itemize
21308
21309 \series bold
21310 opt_code_balanced
21311 \series default
21312  
21313 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
21314
21315 \end_inset
21316
21317 - The compiler will attempt to generate code that is both compact and fast,
21318  as long as meeting one goal is not a detriment to the other (this is the
21319  default).
21320  
21321 \end_layout
21322
21323 \begin_layout Itemize
21324
21325 \series bold
21326 std_sdcc89
21327 \series default
21328  
21329 \begin_inset LatexCommand \index{\#pragma std\_sdcc89}
21330
21331 \end_inset
21332
21333 - Generally follow the C89 standard, but allow SDCC features that conflict
21334  with the standard (default).
21335 \end_layout
21336
21337 \begin_layout Itemize
21338
21339 \series bold
21340 std_c89
21341 \series default
21342  
21343 \begin_inset LatexCommand \index{\#pragma std\_c89}
21344
21345 \end_inset
21346
21347 - Follow the C89 standard and disable SDCC features that conflict with the
21348  standard.
21349 \end_layout
21350
21351 \begin_layout Itemize
21352
21353 \series bold
21354 std_sdcc99
21355 \series default
21356  
21357 \begin_inset LatexCommand \index{\#pragma std\_sdcc99}
21358
21359 \end_inset
21360
21361 - Generally follow the C99 standard, but allow SDCC features that conflict
21362  with the standard (incomplete support).
21363 \end_layout
21364
21365 \begin_layout Itemize
21366
21367 \series bold
21368 std_c99
21369 \series default
21370  
21371 \begin_inset LatexCommand \index{\#pragma std\_c99}
21372
21373 \end_inset
21374
21375 - Follow the C99 standard and disable SDCC features that conflict with the
21376  standard (incomplete support).
21377 \end_layout
21378
21379 \begin_layout Itemize
21380
21381 \series bold
21382 codeseg
21383 \series default
21384  <name>
21385 \begin_inset LatexCommand \index{\#pragma codeseg}
21386
21387 \end_inset
21388
21389 - Use this name (max.
21390  8 characters) for the code segment.
21391  See option -
21392 \begin_inset ERT
21393 status collapsed
21394
21395 \begin_layout Standard
21396
21397
21398 \backslash
21399 /
21400 \end_layout
21401
21402 \end_inset
21403
21404 -codeseg.
21405 \end_layout
21406
21407 \begin_layout Itemize
21408
21409 \series bold
21410 constseg
21411 \series default
21412  <name>
21413 \begin_inset LatexCommand \index{\#pragma constseg}
21414
21415 \end_inset
21416
21417 - Use this name (max.
21418  8 characters) for the const segment.
21419  See option -
21420 \begin_inset ERT
21421 status collapsed
21422
21423 \begin_layout Standard
21424
21425
21426 \backslash
21427 /
21428 \end_layout
21429
21430 \end_inset
21431
21432 -constseg.
21433 \end_layout
21434
21435 \begin_layout Standard
21436 The preprocessor SDCPP
21437 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
21438
21439 \end_inset
21440
21441  supports the following #pragma directives:
21442 \end_layout
21443
21444 \begin_layout Itemize
21445
21446 \series bold
21447 pedantic_parse_number
21448 \series default
21449
21450 \begin_inset LatexCommand \index{pedantic}
21451
21452 \end_inset
21453
21454
21455 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21456
21457 \end_inset
21458
21459  (+ | -) 
21460 \begin_inset LatexCommand \label{ite:pedantic_parse_number}
21461
21462 \end_inset
21463
21464 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
21465  properly and the macro LO_B(3) gets expanded.
21466  Default is off.
21467  See also the -
21468 \begin_inset ERT
21469 status collapsed
21470
21471 \begin_layout Standard
21472
21473
21474 \backslash
21475 /
21476 \end_layout
21477
21478 \end_inset
21479
21480 -pedantic-parse-number command line option 
21481 \begin_inset LatexCommand \vpageref{lyx:-pedantic-parse-number}
21482
21483 \end_inset
21484
21485 .
21486  
21487 \newline
21488 Below is an example on how to use this pragma.
21489
21490 \emph on
21491  Note: this functionality is not in conformance with standard!
21492 \end_layout
21493
21494 \begin_layout Verse
21495
21496 \family typewriter
21497 #pragma pedantic_parse_number +
21498 \begin_inset LatexCommand \index{\#pragma pedantic\_parse\_number}
21499
21500 \end_inset
21501
21502
21503 \newline
21504
21505 \newline
21506 #define LO_B(x) ((x) & 0xff)
21507 \newline
21508
21509 \newline
21510 unsigned char foo(void)
21511 \newline
21512 {
21513 \newline
21514 \InsetSpace ~
21515 \InsetSpace ~
21516 \InsetSpace ~
21517 unsigned char c=0xfe-LO_B(3)
21518 ;
21519 \newline
21520
21521 \newline
21522 \InsetSpace ~
21523 \InsetSpace ~
21524 \InsetSpace ~
21525 return c;
21526 \newline
21527 }
21528 \newline
21529
21530 \end_layout
21531
21532 \begin_layout Itemize
21533
21534 \series bold
21535 preproc_asm
21536 \series default
21537
21538 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21539
21540 \end_inset
21541
21542  (+ | -) - switch _asm _endasm block preprocessing on / off.
21543  Default is on.
21544  You use this prama to define multilines of assembly code.
21545  This will prevent the preprocessor from changing the formating required
21546  by assembly code.
21547  Below is an example on how to use this pragma.
21548 \end_layout
21549
21550 \begin_layout Verse
21551
21552 \family typewriter
21553 #pragma preproc_asm -
21554 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
21555
21556 \end_inset
21557
21558
21559 \newline
21560 #define MYDELAY _asm
21561 \newline
21562 \InsetSpace ~
21563 \InsetSpace ~
21564 \InsetSpace ~
21565 nop ;my assembly comment...
21566 \newline
21567 \InsetSpace ~
21568 \InsetSpace ~
21569 \InsetSpace ~
21570 nop
21571 \newline
21572 \InsetSpace ~
21573 \InsetSpace ~
21574 \InsetSpace ~
21575 nop
21576 \newline
21577 _endasm
21578 \newline
21579 #pragma preproc_asm
21580  +
21581 \newline
21582
21583 \newline
21584 void foo (void) 
21585 \newline
21586
21587 \newline
21588 \InsetSpace ~
21589 \InsetSpace ~
21590 \InsetSpace ~
21591  ...
21592  
21593 \newline
21594 \InsetSpace ~
21595 \InsetSpace ~
21596 \InsetSpace ~
21597  MYDELAY;
21598 \newline
21599 \InsetSpace ~
21600 \InsetSpace ~
21601 \InsetSpace ~
21602  ...
21603  
21604 \newline
21605
21606 \newline
21607
21608 \end_layout
21609
21610 \begin_layout Itemize
21611
21612 \series bold
21613 sdcc_hash
21614 \series default
21615
21616 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21617
21618 \end_inset
21619
21620  (+ | -) - Allow "naked" hash in macro definition, for example:
21621 \newline
21622
21623 \family typewriter
21624 #define DIR_LO(x) #(x & 0xff)
21625 \family default
21626
21627 \newline
21628 Default is off.
21629  Below is an example on how to use this pragma.
21630 \end_layout
21631
21632 \begin_layout Verse
21633
21634 \family typewriter
21635 #pragma preproc_asm +
21636 \newline
21637 #pragma sdcc_hash +
21638 \begin_inset LatexCommand \index{\#pragma sdcc\_hash}
21639
21640 \end_inset
21641
21642
21643 \newline
21644
21645 \newline
21646 #define ROMCALL(x) 
21647 \backslash
21648
21649 \newline
21650 \InsetSpace ~
21651 \InsetSpace ~
21652 \InsetSpace ~
21653 mov R6_B3, #(x & 0xff) 
21654 \backslash
21655
21656 \newline
21657 \InsetSpace ~
21658 \InsetSpace ~
21659 \InsetSpace ~
21660 mov R7_B3, #((x >> 8) & 0xff) 
21661 \backslash
21662
21663 \newline
21664 \InsetSpace ~
21665 \InsetSpace ~
21666 \InsetSpace ~
21667 lcall __romcall
21668 \newline
21669
21670 \newline
21671 ...
21672 \newline
21673 _asm
21674 \newline
21675 ROMCALL(72)
21676 \newline
21677 _endasm;
21678 \newline
21679 ...
21680 \newline
21681
21682 \end_layout
21683
21684 \begin_layout Standard
21685 Some of the pragmas are intended to be used to turn-on or off certain optimizati
21686 ons which might cause the compiler to generate extra stack and/or data space
21687  to store compiler generated temporary variables.
21688  This usually happens in large functions.
21689  Pragma directives should be used as shown in the following example, they
21690  are used to control options and optimizations for a given function.
21691  
21692 \end_layout
21693
21694 \begin_layout Verse
21695
21696 \family typewriter
21697 #pragma save
21698 \begin_inset LatexCommand \index{\#pragma save}
21699
21700 \end_inset
21701
21702  \InsetSpace ~
21703 \InsetSpace ~
21704 \InsetSpace ~
21705 \InsetSpace ~
21706 \InsetSpace ~
21707 \InsetSpace ~
21708 \InsetSpace ~
21709 /* save the current settings */ 
21710 \newline
21711 #pragma nogcse
21712 \begin_inset LatexCommand \index{\#pragma nogcse}
21713
21714 \end_inset
21715
21716  \InsetSpace ~
21717 \InsetSpace ~
21718 \InsetSpace ~
21719 \InsetSpace ~
21720 \InsetSpace ~
21721 /* turnoff global subexpression elimination */ 
21722 \newline
21723 #pragma noinduction
21724 \begin_inset LatexCommand \index{\#pragma noinduction}
21725
21726 \end_inset
21727
21728  /* turn off induction optimizations */ 
21729 \newline
21730 int foo () 
21731 \newline
21732
21733 \newline
21734 \InsetSpace ~
21735  \InsetSpace ~
21736  ...
21737  
21738 \newline
21739 \InsetSpace ~
21740  \InsetSpace ~
21741  /* large code */ 
21742 \newline
21743 \InsetSpace ~
21744  \InsetSpace ~
21745  ...
21746  
21747 \newline
21748
21749 \newline
21750 #pragma restore
21751 \begin_inset LatexCommand \index{\#pragma restore}
21752
21753 \end_inset
21754
21755  /* turn the optimizations back on */
21756 \end_layout
21757
21758 \begin_layout Standard
21759 The compiler will generate a warning message when extra space is allocated.
21760  It is strongly recommended that the save and restore pragma's be used when
21761  changing options for a function.
21762 \newline
21763
21764 \newline
21765
21766 \newline
21767
21768 \end_layout
21769
21770 \begin_layout Section
21771 Defines Created by the Compiler
21772 \end_layout
21773
21774 \begin_layout Standard
21775 The compiler creates the following #defines
21776 \begin_inset LatexCommand \index{\#defines}
21777
21778 \end_inset
21779
21780
21781 \begin_inset LatexCommand \index{Defines created by the compiler}
21782
21783 \end_inset
21784
21785 :
21786 \newline
21787
21788 \end_layout
21789
21790 \begin_layout Standard
21791 \begin_inset Tabular
21792 <lyxtabular version="3" rows="11" columns="2">
21793 <features>
21794 <column alignment="left" valignment="top" leftline="true" width="3in">
21795 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
21796 <row topline="true" bottomline="true">
21797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21798 \begin_inset Text
21799
21800 \begin_layout Standard
21801
21802 \series bold
21803 #define
21804 \end_layout
21805
21806 \end_inset
21807 </cell>
21808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21809 \begin_inset Text
21810
21811 \begin_layout Standard
21812
21813 \series bold
21814 Description
21815 \end_layout
21816
21817 \end_inset
21818 </cell>
21819 </row>
21820 <row topline="true">
21821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21822 \begin_inset Text
21823
21824 \begin_layout Standard
21825 SDCC
21826 \begin_inset LatexCommand \index{SDCC}
21827
21828 \end_inset
21829
21830  
21831 \end_layout
21832
21833 \end_inset
21834 </cell>
21835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21836 \begin_inset Text
21837
21838 \begin_layout Standard
21839 Always defined.
21840  Since version 2.5.6 the version number as an int (ex.
21841  256)
21842 \end_layout
21843
21844 \end_inset
21845 </cell>
21846 </row>
21847 <row topline="true">
21848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21849 \begin_inset Text
21850
21851 \begin_layout Standard
21852 SDCC_mcs51
21853 \begin_inset LatexCommand \index{SDCC\_mcs51}
21854
21855 \end_inset
21856
21857  or SDCC_ds390
21858 \begin_inset LatexCommand \index{SDCC\_ds390}
21859
21860 \end_inset
21861
21862  or SDCC_z80
21863 \begin_inset LatexCommand \index{SDCC\_z80}
21864
21865 \end_inset
21866
21867 , etc.
21868 \end_layout
21869
21870 \end_inset
21871 </cell>
21872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21873 \begin_inset Text
21874
21875 \begin_layout Standard
21876 depending on the model used (e.g.: -mds390)
21877 \end_layout
21878
21879 \end_inset
21880 </cell>
21881 </row>
21882 <row topline="true">
21883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21884 \begin_inset Text
21885
21886 \begin_layout Standard
21887 __mcs51
21888 \begin_inset LatexCommand \index{\_\_mcs51}
21889
21890 \end_inset
21891
21892 , __ds390
21893 \begin_inset LatexCommand \index{\_\_ds390}
21894
21895 \end_inset
21896
21897 , __hc08
21898 \begin_inset LatexCommand \index{\_\_hc08}
21899
21900 \end_inset
21901
21902 , __z80
21903 \begin_inset LatexCommand \index{\_\_z80}
21904
21905 \end_inset
21906
21907 , etc
21908 \end_layout
21909
21910 \end_inset
21911 </cell>
21912 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21913 \begin_inset Text
21914
21915 \begin_layout Standard
21916 depending on the model used (e.g.
21917  -mz80)
21918 \end_layout
21919
21920 \end_inset
21921 </cell>
21922 </row>
21923 <row topline="true">
21924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21925 \begin_inset Text
21926
21927 \begin_layout Standard
21928 SDCC_STACK_AUTO
21929 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
21930
21931 \end_inset
21932
21933
21934 \end_layout
21935
21936 \end_inset
21937 </cell>
21938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21939 \begin_inset Text
21940
21941 \begin_layout Standard
21942 when 
21943 \emph on
21944 -
21945 \begin_inset ERT
21946 status collapsed
21947
21948 \begin_layout Standard
21949
21950
21951 \backslash
21952 /
21953 \end_layout
21954
21955 \end_inset
21956
21957 -stack-auto
21958 \emph default
21959  option is used
21960 \end_layout
21961
21962 \end_inset
21963 </cell>
21964 </row>
21965 <row topline="true">
21966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21967 \begin_inset Text
21968
21969 \begin_layout Standard
21970 SDCC_MODEL_SMALL
21971 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
21972
21973 \end_inset
21974
21975
21976 \end_layout
21977
21978 \end_inset
21979 </cell>
21980 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21981 \begin_inset Text
21982
21983 \begin_layout Standard
21984 when 
21985 \emph on
21986 -
21987 \begin_inset ERT
21988 status collapsed
21989
21990 \begin_layout Standard
21991
21992
21993 \backslash
21994 /
21995 \end_layout
21996
21997 \end_inset
21998
21999 -model-small
22000 \emph default
22001  is used
22002 \end_layout
22003
22004 \end_inset
22005 </cell>
22006 </row>
22007 <row topline="true">
22008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22009 \begin_inset Text
22010
22011 \begin_layout Standard
22012 SDCC_MODEL_MEDIUM
22013 \begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM}
22014
22015 \end_inset
22016
22017
22018 \end_layout
22019
22020 \end_inset
22021 </cell>
22022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22023 \begin_inset Text
22024
22025 \begin_layout Standard
22026 when 
22027 \emph on
22028 -
22029 \begin_inset ERT
22030 status collapsed
22031
22032 \begin_layout Standard
22033
22034
22035 \backslash
22036 /
22037 \end_layout
22038
22039 \end_inset
22040
22041 -model-medium
22042 \emph default
22043  is used
22044 \end_layout
22045
22046 \end_inset
22047 </cell>
22048 </row>
22049 <row topline="true">
22050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22051 \begin_inset Text
22052
22053 \begin_layout Standard
22054 SDCC_MODEL_LARGE
22055 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
22056
22057 \end_inset
22058
22059
22060 \end_layout
22061
22062 \end_inset
22063 </cell>
22064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22065 \begin_inset Text
22066
22067 \begin_layout Standard
22068 when 
22069 \emph on
22070 -
22071 \begin_inset ERT
22072 status collapsed
22073
22074 \begin_layout Standard
22075
22076
22077 \backslash
22078 /
22079 \end_layout
22080
22081 \end_inset
22082
22083 -model-large
22084 \emph default
22085  is used
22086 \end_layout
22087
22088 \end_inset
22089 </cell>
22090 </row>
22091 <row topline="true">
22092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22093 \begin_inset Text
22094
22095 \begin_layout Standard
22096 SDCC_USE_XSTACK
22097 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
22098
22099 \end_inset
22100
22101
22102 \end_layout
22103
22104 \end_inset
22105 </cell>
22106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22107 \begin_inset Text
22108
22109 \begin_layout Standard
22110 when 
22111 \emph on
22112 -
22113 \begin_inset ERT
22114 status collapsed
22115
22116 \begin_layout Standard
22117
22118
22119 \backslash
22120 /
22121 \end_layout
22122
22123 \end_inset
22124
22125 -xstack
22126 \emph default
22127  option is used
22128 \end_layout
22129
22130 \end_inset
22131 </cell>
22132 </row>
22133 <row topline="true">
22134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22135 \begin_inset Text
22136
22137 \begin_layout Standard
22138 SDCC_STACK_TENBIT
22139 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
22140
22141 \end_inset
22142
22143  
22144 \end_layout
22145
22146 \end_inset
22147 </cell>
22148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22149 \begin_inset Text
22150
22151 \begin_layout Standard
22152 when 
22153 \emph on
22154 -mds390
22155 \emph default
22156  is used
22157 \end_layout
22158
22159 \end_inset
22160 </cell>
22161 </row>
22162 <row topline="true" bottomline="true">
22163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22164 \begin_inset Text
22165
22166 \begin_layout Standard
22167 SDCC_MODEL_FLAT24
22168 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
22169
22170 \end_inset
22171
22172
22173 \end_layout
22174
22175 \end_inset
22176 </cell>
22177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22178 \begin_inset Text
22179
22180 \begin_layout Standard
22181 when 
22182 \emph on
22183 -mds390
22184 \emph default
22185  is used
22186 \end_layout
22187
22188 \end_inset
22189 </cell>
22190 </row>
22191 </lyxtabular>
22192
22193 \end_inset
22194
22195
22196 \end_layout
22197
22198 \begin_layout Chapter
22199 Notes on supported Processors
22200 \end_layout
22201
22202 \begin_layout Section
22203 MCS51 variants
22204 \begin_inset LatexCommand \label{sub:MCS51-variants}
22205
22206 \end_inset
22207
22208
22209 \begin_inset LatexCommand \index{MCS51 variants}
22210
22211 \end_inset
22212
22213
22214 \end_layout
22215
22216 \begin_layout Standard
22217 MCS51 processors are available from many vendors and come in many different
22218  flavours.
22219  While they might differ considerably in respect to Special Function Registers
22220  the core MCS51 is usually not modified or is kept compatible.
22221  
22222 \end_layout
22223
22224 \begin_layout Subsection
22225 pdata access by SFR 
22226 \end_layout
22227
22228 \begin_layout Standard
22229 With the upcome of devices with internal xdata and flash memory devices
22230  using port P2
22231 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
22232
22233 \end_inset
22234
22235  as dedicated I/O port is becoming more popular.
22236  Switching the high byte for pdata
22237 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
22238
22239 \end_inset
22240
22241  access which was formerly done by port P2 is then achieved by a Special
22242  Function Register
22243 \begin_inset LatexCommand \index{sfr}
22244
22245 \end_inset
22246
22247 .
22248  In well-established MCS51 tradition the address of this 
22249 \emph on
22250 sfr
22251 \emph default
22252  is where the chip designers decided to put it.
22253  Needless to say that they didn't agree on a common name either.
22254  So that the startup code can correctly initialize xdata variables, you
22255  should define an sfr with the name _XPAGE
22256 \family typewriter
22257
22258 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
22259
22260 \end_inset
22261
22262
22263 \family default
22264  at the appropriate location if the default, port P2, is not used for this.
22265  Some examples are:
22266 \end_layout
22267
22268 \begin_layout Verse
22269
22270 \family typewriter
22271 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
22272  MPAGE */
22273 \end_layout
22274
22275 \begin_layout Verse
22276
22277 \family typewriter
22278 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
22279  a.k.a.
22280  MPAGE */
22281 \end_layout
22282
22283 \begin_layout Verse
22284
22285 \family typewriter
22286 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
22287  XPAGE */
22288 \end_layout
22289
22290 \begin_layout Verse
22291
22292 \family typewriter
22293 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22294  EMI0CN */
22295 \end_layout
22296
22297 \begin_layout Verse
22298
22299 \family typewriter
22300 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
22301  EMI0CN */
22302 \end_layout
22303
22304 \begin_layout Standard
22305 For more exotic implementations further customizations may be needed.
22306  See section 
22307 \begin_inset LatexCommand \ref{sub:Startup-Code}
22308
22309 \end_inset
22310
22311  for other possibilities.
22312 \end_layout
22313
22314 \begin_layout Subsection
22315 Other Features available by SFR
22316 \end_layout
22317
22318 \begin_layout Standard
22319 Some MCS51 variants offer features like Double DPTR
22320 \begin_inset LatexCommand \index{DPTR}
22321
22322 \end_inset
22323
22324 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
22325  These are currently not used for the MCS51 port.
22326  If you absolutely need them you can fall back to inline assembly or submit
22327  a patch to SDCC.
22328 \begin_inset VSpace bigskip
22329 \end_inset
22330
22331
22332 \end_layout
22333
22334 \begin_layout Section
22335 DS400 port
22336 \end_layout
22337
22338 \begin_layout Standard
22339 The DS80C400
22340 \begin_inset LatexCommand \index{DS80C400}
22341
22342 \end_inset
22343
22344
22345 \begin_inset LatexCommand \index{DS400}
22346
22347 \end_inset
22348
22349  microcontroller has a rich set of peripherals.
22350  In its built-in ROM library it includes functions to access some of the
22351  features, among them is a TCP stack with IP4 and IP6 support.
22352  Library headers (currently in beta status) and other files are provided
22353  at 
22354 \size footnotesize
22355
22356 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
22357
22358 \end_inset
22359
22360 .
22361  
22362 \begin_inset VSpace bigskip
22363 \end_inset
22364
22365
22366 \end_layout
22367
22368 \begin_layout Section
22369 The Z80 and gbz80 port
22370 \end_layout
22371
22372 \begin_layout Standard
22373 SDCC can target both the Zilog Z80
22374 \begin_inset LatexCommand \index{Z80}
22375
22376 \end_inset
22377
22378  and the Nintendo Gameboy's Z80-like gbz80
22379 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
22380
22381 \end_inset
22382
22383 .
22384  The Z80 port is passed through the same 
22385 \emph on
22386 regressions tests
22387 \begin_inset LatexCommand \index{Regression test}
22388
22389 \end_inset
22390
22391
22392 \emph default
22393  (see section 
22394 \begin_inset LatexCommand \ref{sec:Quality-control}
22395
22396 \end_inset
22397
22398 ) as the MCS51 and DS390 ports, so floating point support, support for long
22399  variables and bitfield support is fine.
22400  See mailing lists and forums about interrupt routines.
22401 \end_layout
22402
22403 \begin_layout Standard
22404 As always, the code is the authoritative reference - see z80/ralloc.c and
22405  z80/gen.c.
22406  The stack
22407 \begin_inset LatexCommand \index{Z80!stack}
22408
22409 \end_inset
22410
22411  frame is similar to that generated by the IAR Z80 compiler.
22412  IX is used as the base pointer, HL and IY are used as a temporary registers,
22413  and BC and DE are available for holding variables.
22414  Return values
22415 \begin_inset LatexCommand \index{Z80!return value}
22416
22417 \end_inset
22418
22419  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
22420  bytes).
22421  The gbz80 port use the same set of registers for the return values, but
22422  in a different order of significance: E (one byte), DE (two bytes), or
22423  HLDE (four bytes).
22424 \begin_inset VSpace bigskip
22425 \end_inset
22426
22427
22428 \end_layout
22429
22430 \begin_layout Section
22431 The HC08 port
22432 \end_layout
22433
22434 \begin_layout Standard
22435 The port to the Freescale/Motorola HC08
22436 \begin_inset LatexCommand \index{HC08}
22437
22438 \end_inset
22439
22440  family has been added in October 2003, and is still undergoing some basic
22441  development.
22442  The code generator is complete, but the register allocation is still quite
22443  unoptimized.
22444  Some of the SDCC's standard C library functions have embedded non-HC08
22445  inline assembly and so are not yet usable.
22446 \end_layout
22447
22448 \begin_layout Standard
22449 The HC08 port passes the regression test suite (see section 
22450 \begin_inset LatexCommand \ref{sec:Quality-control}
22451
22452 \end_inset
22453
22454 ).
22455 \begin_inset VSpace bigskip
22456 \end_inset
22457
22458
22459 \newpage
22460
22461 \end_layout
22462
22463 \begin_layout Section
22464 The PIC14 port
22465 \end_layout
22466
22467 \begin_layout Standard
22468 The 14bit PIC
22469 \begin_inset LatexCommand \index{PIC14}
22470
22471 \end_inset
22472
22473  port still requires a major effort from the development community.
22474  However it can work for simple code.
22475  It passes its (smaller set of) regression tests
22476 \begin_inset LatexCommand \index{Regression test (PIC14)}
22477
22478 \end_inset
22479
22480  in the directory 
22481 \shape italic
22482 sdcc/src/regression
22483 \shape default
22484 .
22485 \end_layout
22486
22487 \begin_layout Subsection
22488 C code and 14bit PIC code page
22489 \begin_inset LatexCommand \index{code page (pic14)}
22490
22491 \end_inset
22492
22493  and RAM banks
22494 \begin_inset LatexCommand \index{RAM bank (pic14)}
22495
22496 \end_inset
22497
22498
22499 \end_layout
22500
22501 \begin_layout Standard
22502 The linker organizes allocation for the code page and RAM banks.
22503  It does not have intimate knowledge of the code flow.
22504  It will put all the code section of a single asm file into a single code
22505  page.
22506  In order to make use of multiple code pages, separate asm files must be
22507  used.
22508  The compiler treats all functions of a single C file as being in the same
22509  code page unless it is non static.
22510 \newline
22511
22512 \newline
22513 To get the best follow these guide lines:
22514 \end_layout
22515
22516 \begin_layout Enumerate
22517 Make local functions static, as non static functions require code page selection
22518  overhead.
22519 \end_layout
22520
22521 \begin_layout Enumerate
22522 For devices that have multiple code pages it is more efficient to use the
22523  same number of files as pages, i.e.
22524  for the 16F877 use 4 separate files and i.e.
22525  for the 16F874 use 2 separate files.
22526  This way the linker can put the code for each file into different code
22527  pages and there's less page selection overhead.
22528 \end_layout
22529
22530 \begin_layout Enumerate
22531 And as for any 8 bit micro (especially for PIC 14 as they have a very simple
22532  instruction set), use 'unsigned char' whereever possible instead of 'int'.
22533 \end_layout
22534
22535 \begin_layout Subsection
22536 Creating a device include file 
22537 \end_layout
22538
22539 \begin_layout Standard
22540 For generating a device include file
22541 \begin_inset LatexCommand \index{PIC14!Header files}
22542
22543 \end_inset
22544
22545  use the support perl script inc2h.pl kept in directory support/script.
22546 \end_layout
22547
22548 \begin_layout Subsection
22549 Interrupt code
22550 \end_layout
22551
22552 \begin_layout Standard
22553 For the interrupt function, use the keyword '__interrupt'
22554 \begin_inset LatexCommand \index{PIC14!interrupt}
22555
22556 \end_inset
22557
22558  with level number of 0 (PIC14 only has 1 interrupt so this number is only
22559  there to avoid a syntax error - it ought to be fixed).
22560  E.g.:
22561 \end_layout
22562
22563 \begin_layout Verse
22564
22565 \family typewriter
22566 void Intr(void) __interrupt 0
22567 \newline
22568 {
22569 \newline
22570 \InsetSpace ~
22571 \InsetSpace ~
22572 T0IF = 0; /* Clear timer interrupt */
22573 \newline
22574 }
22575 \end_layout
22576
22577 \begin_layout Subsection
22578 Linking and assembling
22579 \end_layout
22580
22581 \begin_layout Standard
22582 For assembling you can use either GPUTILS'
22583 \begin_inset LatexCommand \index{gputils (pic tools)}
22584
22585 \end_inset
22586
22587  gpasm.exe or MPLAB's mpasmwin.exe.
22588  GPUTILS is available from 
22589 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
22590
22591 \end_inset
22592
22593 .
22594  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
22595  If you use MPLAB and an interrupt function then the linker script file
22596  vectors section will need to be enlarged to link with mplink.
22597 \newline
22598
22599 \newline
22600 Here is a 
22601 \family typewriter
22602 Makefile
22603 \family default
22604  using GPUTILS:
22605 \end_layout
22606
22607 \begin_layout Verse
22608
22609 \family typewriter
22610 .c.o:
22611 \newline
22612 \InsetSpace ~
22613 \InsetSpace ~
22614 \InsetSpace ~
22615 \InsetSpace ~
22616 \InsetSpace ~
22617 \InsetSpace ~
22618 \InsetSpace ~
22619 \InsetSpace ~
22620 sdcc -S -V -mpic14 -p16F877 $< 
22621 \newline
22622 \InsetSpace ~
22623 \InsetSpace ~
22624 \InsetSpace ~
22625 \InsetSpace ~
22626 \InsetSpace ~
22627 \InsetSpace ~
22628 \InsetSpace ~
22629 \InsetSpace ~
22630 gpasm -c $*.asm
22631 \newline
22632
22633 \newline
22634 $(PRJ).hex: $(OBJS) 
22635 \newline
22636 \InsetSpace ~
22637 \InsetSpace ~
22638 \InsetSpace ~
22639 \InsetSpace ~
22640 \InsetSpace ~
22641 \InsetSpace ~
22642 \InsetSpace ~
22643 \InsetSpace ~
22644 gplink
22645  -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib
22646 \end_layout
22647
22648 \begin_layout Standard
22649 Here is a 
22650 \family typewriter
22651 Makefile
22652 \family default
22653  using MPLAB:
22654 \end_layout
22655
22656 \begin_layout Verse
22657
22658 \family typewriter
22659 .c.o: 
22660 \newline
22661 \InsetSpace ~
22662 \InsetSpace ~
22663 \InsetSpace ~
22664 \InsetSpace ~
22665 \InsetSpace ~
22666 \InsetSpace ~
22667 \InsetSpace ~
22668 \InsetSpace ~
22669 sdcc -S -V -mpic14 -p16F877 $< 
22670 \newline
22671 \InsetSpace ~
22672 \InsetSpace ~
22673 \InsetSpace ~
22674 \InsetSpace ~
22675 \InsetSpace ~
22676 \InsetSpace ~
22677 \InsetSpace ~
22678 \InsetSpace ~
22679 mpasmwin /q /o $*.asm
22680 \newline
22681
22682 \newline
22683 $(PRJ).hex: $(OBJS)
22684  
22685 \newline
22686 \InsetSpace ~
22687 \InsetSpace ~
22688 \InsetSpace ~
22689 \InsetSpace ~
22690 \InsetSpace ~
22691 \InsetSpace ~
22692 \InsetSpace ~
22693 \InsetSpace ~
22694 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
22695 \end_layout
22696
22697 \begin_layout Standard
22698 Please note that indentations within a
22699 \family typewriter
22700  Makefile
22701 \family default
22702  have to be done with a tabulator character.
22703 \end_layout
22704
22705 \begin_layout Subsection
22706 Command-line options
22707 \end_layout
22708
22709 \begin_layout Standard
22710 Besides the switches common to all SDCC backends, the PIC14 port accepts
22711  the following options (for an updated list see sdcc -
22712 \begin_inset ERT
22713 status collapsed
22714
22715 \begin_layout Standard
22716
22717
22718 \backslash
22719 /
22720 \end_layout
22721
22722 \end_inset
22723
22724 -help):
22725 \end_layout
22726
22727 \begin_layout List
22728 \labelwidthstring 00.00.0000
22729 -
22730 \begin_inset ERT
22731 status collapsed
22732
22733 \begin_layout Standard
22734
22735
22736 \backslash
22737 /
22738 \end_layout
22739
22740 \end_inset
22741
22742 -debug-xtra
22743 \begin_inset LatexCommand \index{PIC14!Options!-\/-debug-extra}
22744
22745 \end_inset
22746
22747  emit debug info in assembly output
22748 \end_layout
22749
22750 \begin_layout List
22751 \labelwidthstring 00.00.0000
22752 -
22753 \begin_inset ERT
22754 status collapsed
22755
22756 \begin_layout Standard
22757
22758
22759 \backslash
22760 /
22761 \end_layout
22762
22763 \end_inset
22764
22765 -no-pcode-opt
22766 \begin_inset LatexCommand \index{PIC14!Options!-\/-no-pcode-opt}
22767
22768 \end_inset
22769
22770  disable (slightly faulty) optimization on pCode
22771 \end_layout
22772
22773 \begin_layout List
22774 \labelwidthstring 00.00.0000
22775 -
22776 \begin_inset ERT
22777 status collapsed
22778
22779 \begin_layout Standard
22780
22781
22782 \backslash
22783 /
22784 \end_layout
22785
22786 \end_inset
22787
22788 -stack-loc
22789 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-loc}
22790
22791 \end_inset
22792
22793  sets the lowest address of the argument passing stack (defaults to a suitably
22794  large shared databank to reduce BANKSEL overhead)
22795 \end_layout
22796
22797 \begin_layout List
22798 \labelwidthstring 00.00.0000
22799 -
22800 \begin_inset ERT
22801 status collapsed
22802
22803 \begin_layout Standard
22804
22805
22806 \backslash
22807 /
22808 \end_layout
22809
22810 \end_inset
22811
22812 -stack-size
22813 \begin_inset LatexCommand \index{PIC14!Options!-\/-stack-size}
22814
22815 \end_inset
22816
22817  sets the size if the argument passing stack (default: 16, minimum: 4)
22818 \end_layout
22819
22820 \begin_layout Subsection
22821 The library
22822 \end_layout
22823
22824 \begin_layout Subsubsection
22825 error: missing definition for symbol 
22826 \begin_inset Quotes sld
22827 \end_inset
22828
22829 __gptrget1
22830 \begin_inset Quotes srd
22831 \end_inset
22832
22833
22834 \end_layout
22835
22836 \begin_layout Standard
22837 The PIC14 port uses library routines to provide more complex operations
22838  like multiplication, division/modulus and (generic) pointer dereferencing.
22839  In order to add these routines to your project, you must link with PIC14's
22840  
22841 \family typewriter
22842 libsdcc.lib
22843 \family default
22844 .
22845  For single source file projects this is done automatically, more complex
22846  projects must add 
22847 \family typewriter
22848 libsdcc.lib
22849 \family default
22850  to the linker's arguments.
22851  Make sure you also add an include path for the library (using the -I switch
22852  to the linker)!
22853 \end_layout
22854
22855 \begin_layout Subsubsection
22856 Processor mismatch in file 
22857 \begin_inset Quotes sld
22858 \end_inset
22859
22860 XXX
22861 \begin_inset Quotes srd
22862 \end_inset
22863
22864 .
22865 \end_layout
22866
22867 \begin_layout Standard
22868 This warning can usually be ignored due to the very good compatibility amongst
22869  14 bit PIC
22870 \begin_inset LatexCommand \index{PIC14}
22871
22872 \end_inset
22873
22874  devices.
22875 \end_layout
22876
22877 \begin_layout Standard
22878 You might also consider recompiling the library for your specific device
22879  by changing the ARCH=p16f877 (default target) entry in 
22880 \family typewriter
22881 device/lib/pic/Makefile.in
22882 \family default
22883  and 
22884 \family typewriter
22885 device/lib/pic/Makefile
22886 \family default
22887  to reflect your device.
22888  This might even improve performance for smaller devices as unneccesary
22889  BANKSELs migth be removed.
22890 \end_layout
22891
22892 \begin_layout Subsection
22893 Known bugs
22894 \end_layout
22895
22896 \begin_layout Subsubsection
22897 initialized data
22898 \end_layout
22899
22900 \begin_layout Standard
22901 Currently, data can only be initialized if it resides in the source file
22902  together with 
22903 \emph on
22904 main()
22905 \emph default
22906 .
22907  Data in other source files will silently 
22908 \series bold
22909 not
22910 \series default
22911  be initialized.
22912 \family typewriter
22913 \size footnotesize
22914
22915 \begin_inset Marginal
22916 status collapsed
22917
22918 \begin_layout Standard
22919
22920 \series bold
22921 \InsetSpace ~
22922 !
22923 \end_layout
22924
22925 \end_inset
22926
22927
22928 \family default
22929
22930 \newpage
22931
22932 \end_layout
22933
22934 \begin_layout Section
22935 The PIC16
22936 \begin_inset LatexCommand \index{PIC16}
22937
22938 \end_inset
22939
22940  port
22941 \end_layout
22942
22943 \begin_layout Standard
22944 The PIC16
22945 \begin_inset LatexCommand \index{PIC16}
22946
22947 \end_inset
22948
22949  port is the portion of SDCC that is responsible to produce code for the
22950  Microchip
22951 \begin_inset LatexCommand \index{Microchip}
22952
22953 \end_inset
22954
22955 (TM) microcontrollers with 16 bit core.
22956  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
22957  Currently supported devices are:
22958 \end_layout
22959
22960 \begin_layout Standard
22961 \align center
22962 \begin_inset Tabular
22963 <lyxtabular version="3" rows="4" columns="6">
22964 <features>
22965 <column alignment="center" valignment="top" leftline="true" width="0">
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" rightline="true" width="0">
22971 <row topline="true">
22972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22973 \begin_inset Text
22974
22975 \begin_layout Standard
22976 18F242
22977 \end_layout
22978
22979 \end_inset
22980 </cell>
22981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22982 \begin_inset Text
22983
22984 \begin_layout Standard
22985 18F248
22986 \end_layout
22987
22988 \end_inset
22989 </cell>
22990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22991 \begin_inset Text
22992
22993 \begin_layout Standard
22994 18F252
22995 \end_layout
22996
22997 \end_inset
22998 </cell>
22999 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23000 \begin_inset Text
23001
23002 \begin_layout Standard
23003 18F258
23004 \end_layout
23005
23006 \end_inset
23007 </cell>
23008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23009 \begin_inset Text
23010
23011 \begin_layout Standard
23012 18F442
23013 \end_layout
23014
23015 \end_inset
23016 </cell>
23017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23018 \begin_inset Text
23019
23020 \begin_layout Standard
23021 18F448
23022 \end_layout
23023
23024 \end_inset
23025 </cell>
23026 </row>
23027 <row topline="true">
23028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23029 \begin_inset Text
23030
23031 \begin_layout Standard
23032 18F452
23033 \end_layout
23034
23035 \end_inset
23036 </cell>
23037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23038 \begin_inset Text
23039
23040 \begin_layout Standard
23041 18F458
23042 \end_layout
23043
23044 \end_inset
23045 </cell>
23046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23047 \begin_inset Text
23048
23049 \begin_layout Standard
23050 18F1220
23051 \end_layout
23052
23053 \end_inset
23054 </cell>
23055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23056 \begin_inset Text
23057
23058 \begin_layout Standard
23059 18F2220
23060 \end_layout
23061
23062 \end_inset
23063 </cell>
23064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23065 \begin_inset Text
23066
23067 \begin_layout Standard
23068 18F2550
23069 \end_layout
23070
23071 \end_inset
23072 </cell>
23073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23074 \begin_inset Text
23075
23076 \begin_layout Standard
23077 18F4331
23078 \end_layout
23079
23080 \end_inset
23081 </cell>
23082 </row>
23083 <row topline="true">
23084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23085 \begin_inset Text
23086
23087 \begin_layout Standard
23088 18F4455
23089 \end_layout
23090
23091 \end_inset
23092 </cell>
23093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23094 \begin_inset Text
23095
23096 \begin_layout Standard
23097 18F6520
23098 \end_layout
23099
23100 \end_inset
23101 </cell>
23102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23103 \begin_inset Text
23104
23105 \begin_layout Standard
23106 18F6620
23107 \end_layout
23108
23109 \end_inset
23110 </cell>
23111 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23112 \begin_inset Text
23113
23114 \begin_layout Standard
23115 18F6680
23116 \end_layout
23117
23118 \end_inset
23119 </cell>
23120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23121 \begin_inset Text
23122
23123 \begin_layout Standard
23124 18F6720
23125 \end_layout
23126
23127 \end_inset
23128 </cell>
23129 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23130 \begin_inset Text
23131
23132 \begin_layout Standard
23133 18F8520
23134 \end_layout
23135
23136 \end_inset
23137 </cell>
23138 </row>
23139 <row topline="true" bottomline="true">
23140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23141 \begin_inset Text
23142
23143 \begin_layout Standard
23144 18F8620
23145 \end_layout
23146
23147 \end_inset
23148 </cell>
23149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23150 \begin_inset Text
23151
23152 \begin_layout Standard
23153 18F8680
23154 \end_layout
23155
23156 \end_inset
23157 </cell>
23158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23159 \begin_inset Text
23160
23161 \begin_layout Standard
23162 18F8720
23163 \end_layout
23164
23165 \end_inset
23166 </cell>
23167 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23168 \begin_inset Text
23169
23170 \begin_layout Standard
23171
23172 \end_layout
23173
23174 \end_inset
23175 </cell>
23176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23177 \begin_inset Text
23178
23179 \begin_layout Standard
23180
23181 \end_layout
23182
23183 \end_inset
23184 </cell>
23185 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23186 \begin_inset Text
23187
23188 \begin_layout Standard
23189
23190 \end_layout
23191
23192 \end_inset
23193 </cell>
23194 </row>
23195 </lyxtabular>
23196
23197 \end_inset
23198
23199
23200 \end_layout
23201
23202 \begin_layout Subsection
23203 Global Options
23204 \end_layout
23205
23206 \begin_layout Standard
23207 PIC16 port supports the standard command line arguments as supposed, with
23208  the exception of certain cases that will be mentioned in the following
23209  list:
23210 \end_layout
23211
23212 \begin_layout List
23213 \labelwidthstring 00.00.0000
23214 -
23215 \begin_inset ERT
23216 status collapsed
23217
23218 \begin_layout Standard
23219
23220
23221 \backslash
23222 /
23223 \end_layout
23224
23225 \end_inset
23226
23227 -callee-saves
23228 \begin_inset LatexCommand \index{PIC16!Options!-\/-callee-saves}
23229
23230 \end_inset
23231
23232  See -
23233 \begin_inset ERT
23234 status collapsed
23235
23236 \begin_layout Standard
23237
23238
23239 \backslash
23240 /
23241 \end_layout
23242
23243 \end_inset
23244
23245 -all-callee-saves
23246 \end_layout
23247
23248 \begin_layout List
23249 \labelwidthstring 00.00.0000
23250 -
23251 \begin_inset ERT
23252 status collapsed
23253
23254 \begin_layout Standard
23255
23256
23257 \backslash
23258 /
23259 \end_layout
23260
23261 \end_inset
23262
23263 -fommit-frame-pointer
23264 \begin_inset LatexCommand \index{PIC16!Options!-\/-fommit-frame-pointer}
23265
23266 \end_inset
23267
23268  Frame pointer will be omitted when the function uses no local variables.
23269 \end_layout
23270
23271 \begin_layout Subsection
23272 Port Specific Options
23273 \begin_inset LatexCommand \index{Options PIC16}
23274
23275 \end_inset
23276
23277
23278 \end_layout
23279
23280 \begin_layout Standard
23281 The port specific options appear after the global options in the sdcc --help
23282  output.
23283 \end_layout
23284
23285 \begin_layout Subsubsection
23286 General Options
23287 \end_layout
23288
23289 \begin_layout Standard
23290 General options enable certain port features and optimizations.
23291 \end_layout
23292
23293 \begin_layout List
23294 \labelwidthstring 00.00.0000
23295 -
23296 \begin_inset ERT
23297 status collapsed
23298
23299 \begin_layout Standard
23300
23301
23302 \backslash
23303 /
23304 \end_layout
23305
23306 \end_inset
23307
23308 -pstack-model=[model] Used in conjuction with the command above.
23309  Defines the stack model to be used, valid stack models are : 
23310 \end_layout
23311
23312 \begin_deeper
23313 \begin_layout List
23314 \labelwidthstring 00.00.0000
23315
23316 \emph on
23317 small
23318 \emph default
23319  Selects small stack model.
23320  8 bit stack and frame pointers.
23321  Supports 256 bytes stack size.
23322 \end_layout
23323
23324 \begin_layout List
23325 \labelwidthstring 00.00.0000
23326
23327 \emph on
23328 large
23329 \emph default
23330  Selects large stack model.
23331  16 bit stack and frame pointers.
23332  Supports 65536 bytes stack size.
23333 \end_layout
23334
23335 \end_deeper
23336 \begin_layout List
23337 \labelwidthstring 00.00.0000
23338 -
23339 \begin_inset ERT
23340 status collapsed
23341
23342 \begin_layout Standard
23343
23344
23345 \backslash
23346 /
23347 \end_layout
23348
23349 \end_inset
23350
23351 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
23352  unitialized data variables with [kword].
23353  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
23354 \end_layout
23355
23356 \begin_layout List
23357 \labelwidthstring 00.00.0000
23358 -
23359 \begin_inset ERT
23360 status collapsed
23361
23362 \begin_layout Standard
23363
23364
23365 \backslash
23366 /
23367 \end_layout
23368
23369 \end_inset
23370
23371 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
23372  Useful for bootloaders.
23373 \end_layout
23374
23375 \begin_layout List
23376 \labelwidthstring 00.00.0000
23377 -
23378 \begin_inset ERT
23379 status collapsed
23380
23381 \begin_layout Standard
23382
23383
23384 \backslash
23385 /
23386 \end_layout
23387
23388 \end_inset
23389
23390 -asm= sets the full path and name of an external assembler to call.
23391 \end_layout
23392
23393 \begin_layout List
23394 \labelwidthstring 00.00.0000
23395 -
23396 \begin_inset ERT
23397 status collapsed
23398
23399 \begin_layout Standard
23400
23401
23402 \backslash
23403 /
23404 \end_layout
23405
23406 \end_inset
23407
23408 -link= sets the full path and name of an external linker to call.
23409 \end_layout
23410
23411 \begin_layout List
23412 \labelwidthstring 00.00.0000
23413 -
23414 \begin_inset ERT
23415 status collapsed
23416
23417 \begin_layout Standard
23418
23419
23420 \backslash
23421 /
23422 \end_layout
23423
23424 \end_inset
23425
23426 -mplab-comp MPLAB
23427 \begin_inset LatexCommand \index{PIC16!MPLAB}
23428
23429 \end_inset
23430
23431  compatibility option.
23432  Currently only suppresses special gpasm directives.
23433 \end_layout
23434
23435 \begin_layout Subsubsection
23436 Optimization Options
23437 \end_layout
23438
23439 \begin_layout List
23440 \labelwidthstring 00.00.0000
23441 -
23442 \begin_inset ERT
23443 status collapsed
23444
23445 \begin_layout Standard
23446
23447
23448 \backslash
23449 /
23450 \end_layout
23451
23452 \end_inset
23453
23454 -optimize-goto Try to use (conditional) BRA instead of GOTO
23455 \end_layout
23456
23457 \begin_layout List
23458 \labelwidthstring 00.00.0000
23459 -
23460 \begin_inset ERT
23461 status collapsed
23462
23463 \begin_layout Standard
23464
23465
23466 \backslash
23467 /
23468 \end_layout
23469
23470 \end_inset
23471
23472 -optimize-cmp Try to optimize some compares.
23473 \end_layout
23474
23475 \begin_layout List
23476 \labelwidthstring 00.00.0000
23477 -
23478 \begin_inset ERT
23479 status collapsed
23480
23481 \begin_layout Standard
23482
23483
23484 \backslash
23485 /
23486 \end_layout
23487
23488 \end_inset
23489
23490 -optimize-df Analyze the dataflow of the generated code and improve it.
23491 \end_layout
23492
23493 \begin_layout List
23494 \labelwidthstring 00.00.0000
23495 -
23496 \begin_inset ERT
23497 status collapsed
23498
23499 \begin_layout Standard
23500
23501
23502 \backslash
23503 /
23504 \end_layout
23505
23506 \end_inset
23507
23508 -obanksel=nn Set optimization level for inserting BANKSELs.
23509 \newline
23510
23511 \end_layout
23512
23513 \begin_deeper
23514 \begin_layout List
23515 \labelwidthstring 00.00.0000
23516 0 no optimization
23517 \end_layout
23518
23519 \begin_layout List
23520 \labelwidthstring 00.00.0000
23521 1 checks previous used register and if it is the same then does not emit
23522  BANKSEL, accounts only for labels.
23523 \end_layout
23524
23525 \begin_layout List
23526 \labelwidthstring 00.00.0000
23527 2 tries to check the location of (even different) symbols and removes BANKSELs
23528  if they are in the same bank.
23529  
23530 \newline
23531
23532 \emph on
23533 Important: There might be problems if the linker script has data sections
23534  across bank borders!
23535 \end_layout
23536
23537 \end_deeper
23538 \begin_layout Subsubsection
23539 Linking Options
23540 \end_layout
23541
23542 \begin_layout List
23543 \labelwidthstring 00.00.0000
23544 -
23545 \begin_inset ERT
23546 status collapsed
23547
23548 \begin_layout Standard
23549
23550
23551 \backslash
23552 /
23553 \end_layout
23554
23555 \end_inset
23556
23557 -nodefaultlibs do not link default libraries when linking
23558 \end_layout
23559
23560 \begin_layout List
23561 \labelwidthstring 00.00.0000
23562 -
23563 \begin_inset ERT
23564 status collapsed
23565
23566 \begin_layout Standard
23567
23568
23569 \backslash
23570 /
23571 \end_layout
23572
23573 \end_inset
23574
23575 -no-crt Don't link the default run-time modules
23576 \end_layout
23577
23578 \begin_layout List
23579 \labelwidthstring 00.00.0000
23580 -
23581 \begin_inset ERT
23582 status collapsed
23583
23584 \begin_layout Standard
23585
23586
23587 \backslash
23588 /
23589 \end_layout
23590
23591 \end_inset
23592
23593 -use-crt= Use a custom run-time module instead of the defaults.
23594 \end_layout
23595
23596 \begin_layout Subsubsection
23597 Debugging Options
23598 \end_layout
23599
23600 \begin_layout Standard
23601 Debugging options enable extra debugging information in the output files.
23602 \end_layout
23603
23604 \begin_layout List
23605 \labelwidthstring 00.00.0000
23606 -
23607 \begin_inset ERT
23608 status collapsed
23609
23610 \begin_layout Standard
23611
23612
23613 \backslash
23614 /
23615 \end_layout
23616
23617 \end_inset
23618
23619 -debug-xtra Similar to -
23620 \begin_inset ERT
23621 status collapsed
23622
23623 \begin_layout Standard
23624
23625
23626 \backslash
23627 /
23628 \end_layout
23629
23630 \end_inset
23631
23632 -debug
23633 \begin_inset LatexCommand \index{-\/-debug}
23634
23635 \end_inset
23636
23637 , but dumps more information.
23638 \end_layout
23639
23640 \begin_layout List
23641 \labelwidthstring 00.00.0000
23642 -
23643 \begin_inset ERT
23644 status collapsed
23645
23646 \begin_layout Standard
23647
23648
23649 \backslash
23650 /
23651 \end_layout
23652
23653 \end_inset
23654
23655 -debug-ralloc Force register allocator to dump <source>.d file with debugging
23656  information.
23657  <source> is the name of the file compiled.
23658 \end_layout
23659
23660 \begin_layout List
23661 \labelwidthstring 00.00.0000
23662 -
23663 \begin_inset ERT
23664 status collapsed
23665
23666 \begin_layout Standard
23667
23668
23669 \backslash
23670 /
23671 \end_layout
23672
23673 \end_inset
23674
23675 -pcode-verbose Enable pcode debugging information in translation.
23676 \end_layout
23677
23678 \begin_layout List
23679 \labelwidthstring 00.00.0000
23680 -
23681 \begin_inset ERT
23682 status collapsed
23683
23684 \begin_layout Standard
23685
23686
23687 \backslash
23688 /
23689 \end_layout
23690
23691 \end_inset
23692
23693 -denable-peeps Force the usage of peepholes.
23694  Use with care.
23695 \end_layout
23696
23697 \begin_layout List
23698 \labelwidthstring 00.00.0000
23699 -
23700 \begin_inset ERT
23701 status collapsed
23702
23703 \begin_layout Standard
23704
23705
23706 \backslash
23707 /
23708 \end_layout
23709
23710 \end_inset
23711
23712 -gstack Trace push/pops for stack pointer overflow
23713 \end_layout
23714
23715 \begin_layout List
23716 \labelwidthstring 00.00.0000
23717 -
23718 \begin_inset ERT
23719 status collapsed
23720
23721 \begin_layout Standard
23722
23723
23724 \backslash
23725 /
23726 \end_layout
23727
23728 \end_inset
23729
23730 -call-tree dump call tree in .calltree file
23731 \end_layout
23732
23733 \begin_layout Subsection
23734 Enviromental Variables
23735 \end_layout
23736
23737 \begin_layout Standard
23738 There is a number of enviromental variables that can be used when running
23739  SDCC to enable certain optimizations or force a specific program behaviour.
23740  these variables are primarily for debugging purposes so they can be enabled/dis
23741 abled at will.
23742 \end_layout
23743
23744 \begin_layout Standard
23745 Currently there is only two such variables available:
23746 \end_layout
23747
23748 \begin_layout List
23749 \labelwidthstring 00.00.0000
23750 OPTIMIZE_BITFIELD_POINTER_GET when this variable exists reading of structure
23751  bitfields is optimized by directly loading FSR0 with the address of the
23752  bitfield structure.
23753  Normally SDCC will cast the bitfield structure to a bitfield pointer and
23754  then load FSR0.
23755  This step saves data ram and code space for functions that perform heavy
23756  use of bitfields.
23757  (ie.
23758  80 bytes of code space are saved when compiling malloc.c with this option).
23759  
23760 \end_layout
23761
23762 \begin_layout List
23763 \labelwidthstring 00.00.0000
23764 NO_REG_OPT do not perform pCode registers optimization.
23765  This should be used for debugging purposes.
23766  In some where bugs in the pcode optimizer are found, users can benefit
23767  from temporarily disabling the optimizer until the bug is fixed.
23768 \end_layout
23769
23770 \begin_layout Subsection
23771 Preprocessor Macros
23772 \end_layout
23773
23774 \begin_layout Standard
23775 PIC16
23776 \begin_inset LatexCommand \index{PIC16}
23777
23778 \end_inset
23779
23780  port defines the following preprocessor macros while translating a source.
23781 \end_layout
23782
23783 \begin_layout Standard
23784 \align center
23785 \begin_inset Tabular
23786 <lyxtabular version="3" rows="6" columns="2">
23787 <features>
23788 <column alignment="center" valignment="top" leftline="true" width="0">
23789 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23790 <row topline="true" bottomline="true">
23791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23792 \begin_inset Text
23793
23794 \begin_layout Standard
23795 Macro
23796 \end_layout
23797
23798 \end_inset
23799 </cell>
23800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23801 \begin_inset Text
23802
23803 \begin_layout Standard
23804 Description
23805 \end_layout
23806
23807 \end_inset
23808 </cell>
23809 </row>
23810 <row topline="true">
23811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23812 \begin_inset Text
23813
23814 \begin_layout Standard
23815 SDCC_pic16
23816 \end_layout
23817
23818 \end_inset
23819 </cell>
23820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23821 \begin_inset Text
23822
23823 \begin_layout Standard
23824 Port identification
23825 \end_layout
23826
23827 \end_inset
23828 </cell>
23829 </row>
23830 <row topline="true">
23831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23832 \begin_inset Text
23833
23834 \begin_layout Standard
23835 _
23836 \begin_inset ERT
23837 status collapsed
23838
23839 \begin_layout Standard
23840
23841
23842 \backslash
23843 /
23844 \end_layout
23845
23846 \end_inset
23847
23848 _pic16
23849 \end_layout
23850
23851 \end_inset
23852 </cell>
23853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23854 \begin_inset Text
23855
23856 \begin_layout Standard
23857 Port identification (same as above)
23858 \end_layout
23859
23860 \end_inset
23861 </cell>
23862 </row>
23863 <row topline="true">
23864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23865 \begin_inset Text
23866
23867 \begin_layout Standard
23868 pic18fxxxx
23869 \end_layout
23870
23871 \end_inset
23872 </cell>
23873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23874 \begin_inset Text
23875
23876 \begin_layout Standard
23877 MCU Identification.
23878  
23879 \emph on
23880 xxxx
23881 \emph default
23882  is the microcontrol identification number, i.e.
23883  452, 6620, etc
23884 \end_layout
23885
23886 \end_inset
23887 </cell>
23888 </row>
23889 <row topline="true">
23890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23891 \begin_inset Text
23892
23893 \begin_layout Standard
23894 _
23895 \begin_inset ERT
23896 status collapsed
23897
23898 \begin_layout Standard
23899
23900
23901 \backslash
23902 /
23903 \end_layout
23904
23905 \end_inset
23906
23907 _18Fxxxx
23908 \end_layout
23909
23910 \end_inset
23911 </cell>
23912 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23913 \begin_inset Text
23914
23915 \begin_layout Standard
23916 MCU Identification (same as above)
23917 \end_layout
23918
23919 \end_inset
23920 </cell>
23921 </row>
23922 <row topline="true" bottomline="true">
23923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23924 \begin_inset Text
23925
23926 \begin_layout Standard
23927 STACK_MODEL_nnn
23928 \end_layout
23929
23930 \end_inset
23931 </cell>
23932 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23933 \begin_inset Text
23934
23935 \begin_layout Standard
23936 nnn = SMALL or LARGE respectively according to the stack model used
23937 \end_layout
23938
23939 \end_inset
23940 </cell>
23941 </row>
23942 </lyxtabular>
23943
23944 \end_inset
23945
23946
23947 \end_layout
23948
23949 \begin_layout Standard
23950 In addition the following macros are defined when calling assembler:
23951 \end_layout
23952
23953 \begin_layout Standard
23954 \align center
23955 \begin_inset Tabular
23956 <lyxtabular version="3" rows="4" columns="2">
23957 <features>
23958 <column alignment="center" valignment="top" leftline="true" width="0">
23959 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
23960 <row topline="true" bottomline="true">
23961 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23962 \begin_inset Text
23963
23964 \begin_layout Standard
23965 Macro
23966 \end_layout
23967
23968 \end_inset
23969 </cell>
23970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23971 \begin_inset Text
23972
23973 \begin_layout Standard
23974 Description
23975 \end_layout
23976
23977 \end_inset
23978 </cell>
23979 </row>
23980 <row topline="true">
23981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23982 \begin_inset Text
23983
23984 \begin_layout Standard
23985 __18Fxxxx
23986 \end_layout
23987
23988 \end_inset
23989 </cell>
23990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23991 \begin_inset Text
23992
23993 \begin_layout Standard
23994 MCU Identification.
23995  
23996 \emph on
23997 xxxx
23998 \emph default
23999  is the microcontrol identification number, i.e.
24000  452, 6620, etc
24001 \end_layout
24002
24003 \end_inset
24004 </cell>
24005 </row>
24006 <row topline="true">
24007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24008 \begin_inset Text
24009
24010 \begin_layout Standard
24011 SDCC_MODEL_nnn
24012 \end_layout
24013
24014 \end_inset
24015 </cell>
24016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24017 \begin_inset Text
24018
24019 \begin_layout Standard
24020 nnn = SMALL or LARGE respectively according to the memory model used for
24021  SDCC
24022 \end_layout
24023
24024 \end_inset
24025 </cell>
24026 </row>
24027 <row topline="true" bottomline="true">
24028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24029 \begin_inset Text
24030
24031 \begin_layout Standard
24032 STACK_MODEL_nnn
24033 \end_layout
24034
24035 \end_inset
24036 </cell>
24037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24038 \begin_inset Text
24039
24040 \begin_layout Standard
24041 nnn = SMALL or LARGE respectively according to the stack model used
24042 \end_layout
24043
24044 \end_inset
24045 </cell>
24046 </row>
24047 </lyxtabular>
24048
24049 \end_inset
24050
24051
24052 \end_layout
24053
24054 \begin_layout Subsection
24055 Directories
24056 \end_layout
24057
24058 \begin_layout Standard
24059 PIC16
24060 \begin_inset LatexCommand \index{PIC16}
24061
24062 \end_inset
24063
24064  port uses the following directories for searching header files and libraries.
24065 \end_layout
24066
24067 \begin_layout Standard
24068 \align center
24069 \begin_inset Tabular
24070 <lyxtabular version="3" rows="3" columns="4">
24071 <features>
24072 <column alignment="center" valignment="top" leftline="true" width="0">
24073 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24074 <column alignment="center" valignment="top" width="0">
24075 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24076 <row topline="true" bottomline="true">
24077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24078 \begin_inset Text
24079
24080 \begin_layout Standard
24081 Directory
24082 \end_layout
24083
24084 \end_inset
24085 </cell>
24086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24087 \begin_inset Text
24088
24089 \begin_layout Standard
24090 Description
24091 \end_layout
24092
24093 \end_inset
24094 </cell>
24095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24096 \begin_inset Text
24097
24098 \begin_layout Standard
24099 Target
24100 \end_layout
24101
24102 \end_inset
24103 </cell>
24104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24105 \begin_inset Text
24106
24107 \begin_layout Standard
24108 Command prefix
24109 \end_layout
24110
24111 \end_inset
24112 </cell>
24113 </row>
24114 <row topline="true">
24115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24116 \begin_inset Text
24117
24118 \begin_layout Standard
24119 PREFIX/sdcc/include/pic16
24120 \end_layout
24121
24122 \end_inset
24123 </cell>
24124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24125 \begin_inset Text
24126
24127 \begin_layout Standard
24128 PIC16 specific headers
24129 \end_layout
24130
24131 \end_inset
24132 </cell>
24133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24134 \begin_inset Text
24135
24136 \begin_layout Standard
24137 Compiler
24138 \end_layout
24139
24140 \end_inset
24141 </cell>
24142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24143 \begin_inset Text
24144
24145 \begin_layout Standard
24146 -I
24147 \end_layout
24148
24149 \end_inset
24150 </cell>
24151 </row>
24152 <row topline="true" bottomline="true">
24153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24154 \begin_inset Text
24155
24156 \begin_layout Standard
24157 PREFIX/sdcc/lib/pic16
24158 \end_layout
24159
24160 \end_inset
24161 </cell>
24162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24163 \begin_inset Text
24164
24165 \begin_layout Standard
24166 PIC16 specific libraries
24167 \end_layout
24168
24169 \end_inset
24170 </cell>
24171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24172 \begin_inset Text
24173
24174 \begin_layout Standard
24175 Linker
24176 \end_layout
24177
24178 \end_inset
24179 </cell>
24180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24181 \begin_inset Text
24182
24183 \begin_layout Standard
24184 -L
24185 \end_layout
24186
24187 \end_inset
24188 </cell>
24189 </row>
24190 </lyxtabular>
24191
24192 \end_inset
24193
24194
24195 \end_layout
24196
24197 \begin_layout Subsection
24198 Pragmas
24199 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
24200
24201 \end_inset
24202
24203
24204 \end_layout
24205
24206 \begin_layout Standard
24207 PIC16
24208 \begin_inset LatexCommand \index{PIC16}
24209
24210 \end_inset
24211
24212  port currently supports the following pragmas:
24213 \end_layout
24214
24215 \begin_layout List
24216 \labelwidthstring 00.00.0000
24217 stack
24218 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma stack}
24219
24220 \end_inset
24221
24222  pragma stack
24223 \begin_inset LatexCommand \index{PIC16!stack}
24224
24225 \end_inset
24226
24227  forces the code generator to initialize the stack & frame pointers at a
24228  specific address.
24229  This is an adhoc solution for cases where no STACK directive is available
24230  in the linker script or gplink is not instructed to create a stack section.
24231 \newline
24232 The
24233  stack pragma should be used only once in a project.
24234  Multiple pragmas may result in indeterminate behaviour of the program.
24235 \begin_inset Foot
24236 status open
24237
24238 \begin_layout Standard
24239 The old format (ie.
24240  #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
24241  cross page boundaries (or even exceed the available data RAM) and crash
24242  the program.
24243  Make sure that stack does not cross page boundaries when using the SMALL
24244  stack model.
24245 \end_layout
24246
24247 \end_inset
24248
24249
24250 \newline
24251 The format is as follows:
24252 \end_layout
24253
24254 \begin_layout LyX-Code
24255 #pragma stack bottom_address [stack_size]
24256 \end_layout
24257
24258 \begin_layout Standard
24259
24260 \emph on
24261 bottom_address
24262 \emph default
24263  is the lower bound of the stack section.
24264  The stack pointer initially will point at address (bottom_address+stack_size-1).
24265 \end_layout
24266
24267 \begin_layout LyX-Code
24268 Example:
24269 \end_layout
24270
24271 \begin_layout LyX-Code
24272
24273 \end_layout
24274
24275 \begin_layout LyX-Code
24276 /* initializes stack of 100 bytes at RAM address 0x200 */
24277 \end_layout
24278
24279 \begin_layout LyX-Code
24280 #pragma stack 0x200 100
24281 \end_layout
24282
24283 \begin_layout Standard
24284 If the stack_size field is omitted then a stack is created with the default
24285  size of 64.
24286  This size might be enough for most programs, but its not enough for operations
24287  with deep function nesting or excessive stack usage.
24288 \end_layout
24289
24290 \begin_layout List
24291 \labelwidthstring 00.00.0000
24292 code
24293 \begin_inset LatexCommand \index{PIC16!Pragmas!\#pragma code}
24294
24295 \end_inset
24296
24297  place a function symbol at static FLASH address
24298 \end_layout
24299
24300 \begin_layout LyX-Code
24301 Example:
24302 \end_layout
24303
24304 \begin_layout LyX-Code
24305
24306 \end_layout
24307
24308 \begin_layout LyX-Code
24309 /* place function test_func at 0x4000 */
24310 \end_layout
24311
24312 \begin_layout LyX-Code
24313 #pragma code test_func 0x4000
24314 \end_layout
24315
24316 \begin_layout LyX-Code
24317
24318 \end_layout
24319
24320 \begin_layout List
24321 \labelwidthstring 00.00.0000
24322 library instructs the linker to use a library module.
24323 \newline
24324 Usage:
24325 \end_layout
24326
24327 \begin_layout LyX-Code
24328 #pragma library module_name
24329 \end_layout
24330
24331 \begin_layout Standard
24332
24333 \emph on
24334 module_name
24335 \emph default
24336  can be any library or object file (including its path).
24337  Note that there are four reserved keywords which have special meaning.
24338  These are:
24339 \end_layout
24340
24341 \begin_layout Standard
24342 \align center
24343 \begin_inset Tabular
24344 <lyxtabular version="3" rows="6" columns="3">
24345 <features>
24346 <column alignment="center" valignment="top" leftline="true" width="0">
24347 <column alignment="block" valignment="top" leftline="true" width="20page%">
24348 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
24349 <row topline="true" bottomline="true">
24350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24351 \begin_inset Text
24352
24353 \begin_layout Standard
24354 Keyword
24355 \end_layout
24356
24357 \end_inset
24358 </cell>
24359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24360 \begin_inset Text
24361
24362 \begin_layout Standard
24363 Description
24364 \end_layout
24365
24366 \end_inset
24367 </cell>
24368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24369 \begin_inset Text
24370
24371 \begin_layout Standard
24372 Module to link
24373 \end_layout
24374
24375 \end_inset
24376 </cell>
24377 </row>
24378 <row topline="true">
24379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24380 \begin_inset Text
24381
24382 \begin_layout Standard
24383
24384 \series bold
24385 ignore
24386 \end_layout
24387
24388 \end_inset
24389 </cell>
24390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24391 \begin_inset Text
24392
24393 \begin_layout Standard
24394 ignore all library pragmas
24395 \end_layout
24396
24397 \end_inset
24398 </cell>
24399 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24400 \begin_inset Text
24401
24402 \begin_layout Standard
24403
24404 \emph on
24405 (none)
24406 \end_layout
24407
24408 \end_inset
24409 </cell>
24410 </row>
24411 <row topline="true">
24412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24413 \begin_inset Text
24414
24415 \begin_layout Standard
24416
24417 \series bold
24418 c
24419 \end_layout
24420
24421 \end_inset
24422 </cell>
24423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24424 \begin_inset Text
24425
24426 \begin_layout Standard
24427 link the C library
24428 \end_layout
24429
24430 \end_inset
24431 </cell>
24432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24433 \begin_inset Text
24434
24435 \begin_layout Standard
24436
24437 \emph on
24438 libc18f
24439 \emph default
24440 .lib
24441 \end_layout
24442
24443 \end_inset
24444 </cell>
24445 </row>
24446 <row topline="true">
24447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24448 \begin_inset Text
24449
24450 \begin_layout Standard
24451
24452 \series bold
24453 math
24454 \end_layout
24455
24456 \end_inset
24457 </cell>
24458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24459 \begin_inset Text
24460
24461 \begin_layout Standard
24462 link the Math libarary
24463 \end_layout
24464
24465 \end_inset
24466 </cell>
24467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24468 \begin_inset Text
24469
24470 \begin_layout Standard
24471
24472 \emph on
24473 libm18f
24474 \emph default
24475 .lib
24476 \end_layout
24477
24478 \end_inset
24479 </cell>
24480 </row>
24481 <row topline="true">
24482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24483 \begin_inset Text
24484
24485 \begin_layout Standard
24486
24487 \series bold
24488 io
24489 \end_layout
24490
24491 \end_inset
24492 </cell>
24493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24494 \begin_inset Text
24495
24496 \begin_layout Standard
24497 link the I/O library
24498 \end_layout
24499
24500 \end_inset
24501 </cell>
24502 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24503 \begin_inset Text
24504
24505 \begin_layout Standard
24506
24507 \emph on
24508 libio18f*
24509 \emph default
24510 .lib
24511 \end_layout
24512
24513 \end_inset
24514 </cell>
24515 </row>
24516 <row topline="true" bottomline="true">
24517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24518 \begin_inset Text
24519
24520 \begin_layout Standard
24521
24522 \series bold
24523 debug
24524 \end_layout
24525
24526 \end_inset
24527 </cell>
24528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24529 \begin_inset Text
24530
24531 \begin_layout Standard
24532 link the debug library
24533 \end_layout
24534
24535 \end_inset
24536 </cell>
24537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24538 \begin_inset Text
24539
24540 \begin_layout Standard
24541
24542 \emph on
24543 libdebug
24544 \emph default
24545 .lib
24546 \end_layout
24547
24548 \end_inset
24549 </cell>
24550 </row>
24551 </lyxtabular>
24552
24553 \end_inset
24554
24555
24556 \newline
24557 * is the device number, i.e.
24558  452 for PIC18F452 MCU.
24559 \end_layout
24560
24561 \begin_layout Standard
24562 This feature allows for linking with specific libraries withoug having to
24563  explicit name them in the command line.
24564  Note that the 
24565 \noun on
24566 ignore
24567 \noun default
24568  keyword will reject all modules specified by the library pragma.
24569 \end_layout
24570
24571 \begin_layout List
24572 \labelwidthstring 00.00.0000
24573 udata pragma udata instructs the compiler to emit code so that linker will
24574  place a variable at a specific memory bank
24575 \end_layout
24576
24577 \begin_layout LyX-Code
24578 Example:
24579 \end_layout
24580
24581 \begin_layout LyX-Code
24582
24583 \end_layout
24584
24585 \begin_layout LyX-Code
24586 /* places variable foo at bank2 */
24587 \end_layout
24588
24589 \begin_layout LyX-Code
24590 #pragma udata bank2 foo
24591 \end_layout
24592
24593 \begin_layout LyX-Code
24594 char foo;
24595 \end_layout
24596
24597 \begin_layout Standard
24598 In order for this pragma to work extra SECTION directives should be added
24599  in the .lkr script.
24600  In the following example a sample .lkr file is shown:
24601 \end_layout
24602
24603 \begin_layout LyX-Code
24604
24605 \end_layout
24606
24607 \begin_layout LyX-Code
24608 // Sample linker script for the PIC18F452 processor
24609 \end_layout
24610
24611 \begin_layout LyX-Code
24612 LIBPATH .
24613 \end_layout
24614
24615 \begin_layout LyX-Code
24616 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
24617 \end_layout
24618
24619 \begin_layout LyX-Code
24620 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
24621 \end_layout
24622
24623 \begin_layout LyX-Code
24624 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
24625 \end_layout
24626
24627 \begin_layout LyX-Code
24628 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
24629 \end_layout
24630
24631 \begin_layout LyX-Code
24632 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
24633 \end_layout
24634
24635 \begin_layout LyX-Code
24636 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
24637 \end_layout
24638
24639 \begin_layout LyX-Code
24640 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
24641 \end_layout
24642
24643 \begin_layout LyX-Code
24644
24645 \end_layout
24646
24647 \begin_layout LyX-Code
24648 DATABANK   NAME=gpr0       START=0x80           END=0xFF
24649 \end_layout
24650
24651 \begin_layout LyX-Code
24652 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
24653 \end_layout
24654
24655 \begin_layout LyX-Code
24656 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
24657 \end_layout
24658
24659 \begin_layout LyX-Code
24660 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
24661 \end_layout
24662
24663 \begin_layout LyX-Code
24664 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
24665 \end_layout
24666
24667 \begin_layout LyX-Code
24668 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
24669 \end_layout
24670
24671 \begin_layout LyX-Code
24672 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
24673 \end_layout
24674
24675 \begin_layout LyX-Code
24676
24677 \end_layout
24678
24679 \begin_layout LyX-Code
24680 SECTION    NAME=CONFIG     ROM=config
24681 \end_layout
24682
24683 \begin_layout LyX-Code
24684
24685 \end_layout
24686
24687 \begin_layout LyX-Code
24688 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
24689 \end_layout
24690
24691 \begin_layout LyX-Code
24692 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
24693 \end_layout
24694
24695 \begin_layout LyX-Code
24696 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
24697 \end_layout
24698
24699 \begin_layout LyX-Code
24700 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
24701 \end_layout
24702
24703 \begin_layout LyX-Code
24704 SECTION    NAME=bank4      RAM=gpr4
24705 \end_layout
24706
24707 \begin_layout LyX-Code
24708 SECTION    NAME=bank5      RAM=gpr5
24709 \end_layout
24710
24711 \begin_layout Standard
24712 The linker will recognise the section name set in the pragma statement and
24713  will position the variable at the memory bank set with the RAM field at
24714  the SECTION line in the linker script file.
24715 \end_layout
24716
24717 \begin_layout Subsection
24718 Header Files
24719 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
24720
24721 \end_inset
24722
24723
24724 \end_layout
24725
24726 \begin_layout Standard
24727 There is one main header file
24728 \begin_inset LatexCommand \index{PIC16!Header files}
24729
24730 \end_inset
24731
24732  that can be included to the source files using the pic16
24733 \begin_inset LatexCommand \index{PIC16}
24734
24735 \end_inset
24736
24737  port.
24738  That file is the 
24739 \series bold
24740 pic18fregs.h
24741 \series default
24742 .
24743  This header file contains the definitions for the processor special registers,
24744  so it is necessary if the source accesses them.
24745  It can be included by adding the following line in the beginning of the
24746  file:
24747 \end_layout
24748
24749 \begin_layout LyX-Code
24750 #include <pic18fregs.h>
24751 \end_layout
24752
24753 \begin_layout Standard
24754 The specific microcontroller is selected within the pic18fregs.h automatically,
24755  so the same source can be used with a variety of devices.
24756 \end_layout
24757
24758 \begin_layout Subsection
24759 Libraries
24760 \end_layout
24761
24762 \begin_layout Standard
24763 The libraries
24764 \begin_inset LatexCommand \index{PIC16!Libraries}
24765
24766 \end_inset
24767
24768  that PIC16
24769 \begin_inset LatexCommand \index{PIC16}
24770
24771 \end_inset
24772
24773  port depends on are the microcontroller device libraries which contain
24774  the symbol definitions for the microcontroller special function registers.
24775  These libraries have the format pic18fxxxx.lib, where 
24776 \emph on
24777 xxxx
24778 \emph default
24779  is the microcontroller identification number.
24780  The specific library is selected automatically by the compiler at link
24781  stage according to the selected device.
24782 \end_layout
24783
24784 \begin_layout Standard
24785 Libraries are created with gplib which is part of the gputils package 
24786 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
24787
24788 \end_inset
24789
24790 .
24791 \end_layout
24792
24793 \begin_layout Subsubsection*
24794 Building the libraries
24795 \end_layout
24796
24797 \begin_layout Standard
24798 Before using SDCC/pic16 there are some libraries that need to be compiled.
24799  This process is not done automatically by SDCC since not all users use
24800  SDCC for pic16 projects.
24801  So each user should compile the libraries separately.
24802 \end_layout
24803
24804 \begin_layout Standard
24805 The steps to compile the pic16 libraries under Linux and Mac OS X are:
24806 \end_layout
24807
24808 \begin_layout LyX-Code
24809 cd device/lib/pic16
24810 \end_layout
24811
24812 \begin_layout LyX-Code
24813 ./configure
24814 \end_layout
24815
24816 \begin_layout LyX-Code
24817 make
24818 \end_layout
24819
24820 \begin_layout LyX-Code
24821 cd ..
24822 \end_layout
24823
24824 \begin_layout LyX-Code
24825 make model-pic16
24826 \end_layout
24827
24828 \begin_layout LyX-Code
24829 su -c 'make install'     # install the libraries, you need the root password
24830 \end_layout
24831
24832 \begin_layout Standard
24833 If you need to install the headers too, do:
24834 \end_layout
24835
24836 \begin_layout LyX-Code
24837 cd device/include
24838 \end_layout
24839
24840 \begin_layout LyX-Code
24841 su -c 'make install'     # install the headers, you need the root password
24842 \end_layout
24843
24844 \begin_layout Standard
24845 There exist a special target to build the I/O libraries.
24846  This target is not automatically build because it will build the I/O library
24847  for 
24848 \emph on
24849 every
24850 \emph default
24851  supported device.
24852  This way building will take quite a lot of time.
24853  Users are advised to edit the 
24854 \series bold
24855 device/lib/pic16/pics.build
24856 \series default
24857  file and then execute:
24858 \end_layout
24859
24860 \begin_layout LyX-Code
24861 make lib-io
24862 \end_layout
24863
24864 \begin_layout Subsection
24865 Memory Models
24866 \end_layout
24867
24868 \begin_layout Standard
24869 The following memory models are supported by the PIC16 port:
24870 \end_layout
24871
24872 \begin_layout Itemize
24873 small model
24874 \end_layout
24875
24876 \begin_layout Itemize
24877 large model
24878 \end_layout
24879
24880 \begin_layout Standard
24881 Memory model affects the default size of pointers within the source.
24882  The sizes are shown in the next table:
24883 \end_layout
24884
24885 \begin_layout Standard
24886 \align center
24887 \begin_inset Tabular
24888 <lyxtabular version="3" rows="3" columns="3">
24889 <features>
24890 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24891 <column alignment="center" valignment="top" leftline="true" width="0">
24892 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24893 <row topline="true" bottomline="true">
24894 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24895 \begin_inset Text
24896
24897 \begin_layout Standard
24898 Pointer sizes according to memory model
24899 \end_layout
24900
24901 \end_inset
24902 </cell>
24903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24904 \begin_inset Text
24905
24906 \begin_layout Standard
24907 small model
24908 \end_layout
24909
24910 \end_inset
24911 </cell>
24912 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24913 \begin_inset Text
24914
24915 \begin_layout Standard
24916 large model
24917 \end_layout
24918
24919 \end_inset
24920 </cell>
24921 </row>
24922 <row topline="true" bottomline="true">
24923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24924 \begin_inset Text
24925
24926 \begin_layout Standard
24927 code pointers
24928 \end_layout
24929
24930 \end_inset
24931 </cell>
24932 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24933 \begin_inset Text
24934
24935 \begin_layout Standard
24936 16-bits
24937 \end_layout
24938
24939 \end_inset
24940 </cell>
24941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24942 \begin_inset Text
24943
24944 \begin_layout Standard
24945 24-bits
24946 \end_layout
24947
24948 \end_inset
24949 </cell>
24950 </row>
24951 <row topline="true" bottomline="true">
24952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24953 \begin_inset Text
24954
24955 \begin_layout Standard
24956 data pointers
24957 \end_layout
24958
24959 \end_inset
24960 </cell>
24961 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
24962 \begin_inset Text
24963
24964 \begin_layout Standard
24965 16-bits
24966 \end_layout
24967
24968 \end_inset
24969 </cell>
24970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24971 \begin_inset Text
24972
24973 \begin_layout Standard
24974 16-bits
24975 \end_layout
24976
24977 \end_inset
24978 </cell>
24979 </row>
24980 </lyxtabular>
24981
24982 \end_inset
24983
24984
24985 \end_layout
24986
24987 \begin_layout Standard
24988 It is advisable that all sources within a project are compiled with the
24989  same memory model.
24990  If one wants to override the default memory model, this can be done by
24991  declaring a pointer as 
24992 \series bold
24993 far
24994 \series default
24995  or 
24996 \series bold
24997 near
24998 \series default
24999 .
25000  Far selects large memory model's pointers, while near selects small memory
25001  model's pointers.
25002 \end_layout
25003
25004 \begin_layout Standard
25005 The standard device libraries (see 
25006 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
25007
25008 \end_inset
25009
25010 ) contain no reference to pointers, so they can be used with both memory
25011  models.
25012 \end_layout
25013
25014 \begin_layout Subsection
25015 Stack
25016 \end_layout
25017
25018 \begin_layout Standard
25019 The stack
25020 \begin_inset LatexCommand \index{PIC16!stack}
25021
25022 \end_inset
25023
25024  implementation for the PIC16 port uses two indirect registers, FSR1 and
25025  FSR2.
25026 \end_layout
25027
25028 \begin_layout List
25029 \labelwidthstring 00.00.0000
25030 FSR1 is assigned as stack pointer
25031 \end_layout
25032
25033 \begin_layout List
25034 \labelwidthstring 00.00.0000
25035 FSR2 is assigned as frame pointer
25036 \end_layout
25037
25038 \begin_layout Standard
25039 The following stack models are supported by the PIC16 port
25040 \end_layout
25041
25042 \begin_layout Itemize
25043
25044 \noun on
25045 small
25046 \noun default
25047  model
25048 \end_layout
25049
25050 \begin_layout Itemize
25051
25052 \noun on
25053 large
25054 \noun default
25055  model
25056 \end_layout
25057
25058 \begin_layout Standard
25059
25060 \noun on
25061 Small
25062 \noun default
25063  model means that only the FSRxL byte is used to access stack and frame,
25064  while 
25065 \emph on
25066 \noun on
25067 large
25068 \emph default
25069 \noun default
25070  uses both FSRxL and FSRxH registers.
25071  The following table shows the stack/frame pointers sizes according to stack
25072  model and the maximum space they can address:
25073 \end_layout
25074
25075 \begin_layout Standard
25076 \align center
25077 \begin_inset Tabular
25078 <lyxtabular version="3" rows="3" columns="3">
25079 <features>
25080 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25081 <column alignment="center" valignment="top" leftline="true" width="0">
25082 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25083 <row topline="true" bottomline="true">
25084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25085 \begin_inset Text
25086
25087 \begin_layout Standard
25088 Stack & Frame pointer sizes according to stack model
25089 \end_layout
25090
25091 \end_inset
25092 </cell>
25093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25094 \begin_inset Text
25095
25096 \begin_layout Standard
25097 small
25098 \end_layout
25099
25100 \end_inset
25101 </cell>
25102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25103 \begin_inset Text
25104
25105 \begin_layout Standard
25106 large
25107 \end_layout
25108
25109 \end_inset
25110 </cell>
25111 </row>
25112 <row topline="true">
25113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25114 \begin_inset Text
25115
25116 \begin_layout Standard
25117 Stack pointer FSR1
25118 \end_layout
25119
25120 \end_inset
25121 </cell>
25122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25123 \begin_inset Text
25124
25125 \begin_layout Standard
25126 8-bits
25127 \end_layout
25128
25129 \end_inset
25130 </cell>
25131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25132 \begin_inset Text
25133
25134 \begin_layout Standard
25135 16-bits
25136 \end_layout
25137
25138 \end_inset
25139 </cell>
25140 </row>
25141 <row topline="true" bottomline="true">
25142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25143 \begin_inset Text
25144
25145 \begin_layout Standard
25146 Frame pointer FSR2
25147 \end_layout
25148
25149 \end_inset
25150 </cell>
25151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25152 \begin_inset Text
25153
25154 \begin_layout Standard
25155 8-bits
25156 \end_layout
25157
25158 \end_inset
25159 </cell>
25160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25161 \begin_inset Text
25162
25163 \begin_layout Standard
25164 16-bits
25165 \end_layout
25166
25167 \end_inset
25168 </cell>
25169 </row>
25170 </lyxtabular>
25171
25172 \end_inset
25173
25174
25175 \end_layout
25176
25177 \begin_layout Standard
25178
25179 \noun on
25180 Large 
25181 \noun default
25182 stack model is currently not working properly throughout the code generator.
25183  So its use is not advised.
25184  Also there are some other points that need special care:
25185 \newline
25186
25187 \end_layout
25188
25189 \begin_layout Enumerate
25190 Do not create stack sections with size more than one physical bank (that
25191  is 256 bytes)
25192 \end_layout
25193
25194 \begin_layout Enumerate
25195 Stack sections should no cross physical bank limits (i.e.
25196  #pragma stack 0x50 0x100)
25197 \end_layout
25198
25199 \begin_layout Standard
25200 These limitations are caused by the fact that only FSRxL is modified when
25201  using SMALL stack model, so no more than 256 bytes of stack can be used.
25202  This problem will disappear after LARGE model is fully implemented.
25203 \end_layout
25204
25205 \begin_layout Subsection
25206 Functions
25207 \end_layout
25208
25209 \begin_layout Standard
25210 In addition to the standard SDCC function keywords, PIC16
25211 \begin_inset LatexCommand \index{PIC16}
25212
25213 \end_inset
25214
25215  port makes available two more:
25216 \end_layout
25217
25218 \begin_layout List
25219 \labelwidthstring 00.00.0000
25220 wparam
25221 \begin_inset LatexCommand \index{PIC16!wparam}
25222
25223 \end_inset
25224
25225  Use the WREG to pass one byte of the first function argument.
25226  This improves speed but you may not use this for functions with arguments
25227  that are called via function pointers, otherwise the first byte of the
25228  first parameter will get lost.
25229  Usage:
25230 \end_layout
25231
25232 \begin_layout LyX-Code
25233 void func_wparam(int a) wparam
25234 \end_layout
25235
25236 \begin_layout LyX-Code
25237 {
25238 \end_layout
25239
25240 \begin_layout LyX-Code
25241     /* WREG hold the lower part of a */
25242 \end_layout
25243
25244 \begin_layout LyX-Code
25245     /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
25246  */
25247 \end_layout
25248
25249 \begin_layout LyX-Code
25250 ...
25251 \end_layout
25252
25253 \begin_layout LyX-Code
25254 }
25255 \end_layout
25256
25257 \begin_layout List
25258 \labelwidthstring 00.00.0000
25259 shadowregs
25260 \begin_inset LatexCommand \index{PIC16!shadowregs}
25261
25262 \end_inset
25263
25264  When entering/exiting an ISR, it is possible to take advantage of the PIC18F
25265  hardware shadow registers which hold the values of WREG, STATUS and BSR
25266  registers.
25267  This can be done by adding the keyword 
25268 \emph on
25269 shadowregs
25270 \emph default
25271  before the 
25272 \emph on
25273 interrupt
25274 \emph default
25275  keyword in the function's header.
25276 \end_layout
25277
25278 \begin_layout LyX-Code
25279 void isr_shadow(void) shadowregs interrupt 1
25280 \end_layout
25281
25282 \begin_layout LyX-Code
25283 {
25284 \end_layout
25285
25286 \begin_layout LyX-Code
25287 ...
25288 \end_layout
25289
25290 \begin_layout LyX-Code
25291 }
25292 \end_layout
25293
25294 \begin_layout Standard
25295
25296 \emph on
25297 shadowregs
25298 \emph default
25299  instructs the code generator not to store/restore WREG, STATUS, BSR when
25300  entering/exiting the ISR.
25301 \end_layout
25302
25303 \begin_layout Subsection
25304 Function return values
25305 \end_layout
25306
25307 \begin_layout Standard
25308 Return values from functions are placed to the appropriate registers following
25309  a modified Microchip policy optimized for SDCC.
25310  The following table shows these registers:
25311 \end_layout
25312
25313 \begin_layout Standard
25314 \align center
25315 \begin_inset Tabular
25316 <lyxtabular version="3" rows="6" columns="2">
25317 <features>
25318 <column alignment="center" valignment="top" leftline="true" width="0">
25319 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25320 <row topline="true" bottomline="true">
25321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25322 \begin_inset Text
25323
25324 \begin_layout Standard
25325 size
25326 \end_layout
25327
25328 \end_inset
25329 </cell>
25330 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25331 \begin_inset Text
25332
25333 \begin_layout Standard
25334 destination register
25335 \end_layout
25336
25337 \end_inset
25338 </cell>
25339 </row>
25340 <row topline="true">
25341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25342 \begin_inset Text
25343
25344 \begin_layout Standard
25345 8 bits
25346 \end_layout
25347
25348 \end_inset
25349 </cell>
25350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25351 \begin_inset Text
25352
25353 \begin_layout Standard
25354 WREG
25355 \end_layout
25356
25357 \end_inset
25358 </cell>
25359 </row>
25360 <row topline="true">
25361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25362 \begin_inset Text
25363
25364 \begin_layout Standard
25365 16 bits
25366 \end_layout
25367
25368 \end_inset
25369 </cell>
25370 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25371 \begin_inset Text
25372
25373 \begin_layout Standard
25374 PRODL:WREG
25375 \end_layout
25376
25377 \end_inset
25378 </cell>
25379 </row>
25380 <row topline="true">
25381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25382 \begin_inset Text
25383
25384 \begin_layout Standard
25385 24 bits
25386 \end_layout
25387
25388 \end_inset
25389 </cell>
25390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25391 \begin_inset Text
25392
25393 \begin_layout Standard
25394 PRODH:PRODL:WREG
25395 \end_layout
25396
25397 \end_inset
25398 </cell>
25399 </row>
25400 <row topline="true">
25401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25402 \begin_inset Text
25403
25404 \begin_layout Standard
25405 32 bits
25406 \end_layout
25407
25408 \end_inset
25409 </cell>
25410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25411 \begin_inset Text
25412
25413 \begin_layout Standard
25414 FSR0L:PRODH:PRODL:WREG
25415 \end_layout
25416
25417 \end_inset
25418 </cell>
25419 </row>
25420 <row topline="true" bottomline="true">
25421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25422 \begin_inset Text
25423
25424 \begin_layout Standard
25425 >32 bits
25426 \end_layout
25427
25428 \end_inset
25429 </cell>
25430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25431 \begin_inset Text
25432
25433 \begin_layout Standard
25434 on stack, FSR0 points to the beginning
25435 \end_layout
25436
25437 \end_inset
25438 </cell>
25439 </row>
25440 </lyxtabular>
25441
25442 \end_inset
25443
25444
25445 \end_layout
25446
25447 \begin_layout Subsection
25448 Interrupts
25449 \end_layout
25450
25451 \begin_layout Standard
25452 An interrupt
25453 \begin_inset LatexCommand \index{PIC16!interrupt}
25454
25455 \end_inset
25456
25457  service routine (ISR) is declared using the 
25458 \emph on
25459 interrupt
25460 \emph default
25461  keyword.
25462 \end_layout
25463
25464 \begin_layout LyX-Code
25465 void isr(void) interrupt 
25466 \emph on
25467 n
25468 \end_layout
25469
25470 \begin_layout LyX-Code
25471 {
25472 \end_layout
25473
25474 \begin_layout LyX-Code
25475 ...
25476 \end_layout
25477
25478 \begin_layout LyX-Code
25479 }
25480 \end_layout
25481
25482 \begin_layout Standard
25483
25484 \emph on
25485 n
25486 \emph default
25487  is the interrupt number, which for PIC18F devices can be:
25488 \end_layout
25489
25490 \begin_layout Standard
25491 \align center
25492 \begin_inset Tabular
25493 <lyxtabular version="3" rows="4" columns="3">
25494 <features>
25495 <column alignment="center" valignment="top" leftline="true" width="0">
25496 <column alignment="center" valignment="top" leftline="true" width="0">
25497 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25498 <row topline="true" bottomline="true">
25499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25500 \begin_inset Text
25501
25502 \begin_layout Standard
25503
25504 \emph on
25505 n
25506 \end_layout
25507
25508 \end_inset
25509 </cell>
25510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25511 \begin_inset Text
25512
25513 \begin_layout Standard
25514 Interrupt Vector
25515 \end_layout
25516
25517 \end_inset
25518 </cell>
25519 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25520 \begin_inset Text
25521
25522 \begin_layout Standard
25523 Interrupt Vector Address
25524 \end_layout
25525
25526 \end_inset
25527 </cell>
25528 </row>
25529 <row topline="true">
25530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25531 \begin_inset Text
25532
25533 \begin_layout Standard
25534 0
25535 \end_layout
25536
25537 \end_inset
25538 </cell>
25539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25540 \begin_inset Text
25541
25542 \begin_layout Standard
25543 RESET vector
25544 \end_layout
25545
25546 \end_inset
25547 </cell>
25548 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25549 \begin_inset Text
25550
25551 \begin_layout Standard
25552 0x000000
25553 \end_layout
25554
25555 \end_inset
25556 </cell>
25557 </row>
25558 <row topline="true">
25559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25560 \begin_inset Text
25561
25562 \begin_layout Standard
25563
25564 \family roman
25565 \series medium
25566 \shape up
25567 \size normal
25568 \emph off
25569 \bar no
25570 \noun off
25571 \color none
25572 1
25573 \end_layout
25574
25575 \end_inset
25576 </cell>
25577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25578 \begin_inset Text
25579
25580 \begin_layout Standard
25581
25582 \family roman
25583 \series medium
25584 \shape up
25585 \size normal
25586 \emph off
25587 \bar no
25588 \noun off
25589 \color none
25590 HIGH priority interrupts
25591 \end_layout
25592
25593 \end_inset
25594 </cell>
25595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25596 \begin_inset Text
25597
25598 \begin_layout Standard
25599 0x000008
25600 \end_layout
25601
25602 \end_inset
25603 </cell>
25604 </row>
25605 <row topline="true" bottomline="true">
25606 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25607 \begin_inset Text
25608
25609 \begin_layout Standard
25610 2
25611 \end_layout
25612
25613 \end_inset
25614 </cell>
25615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25616 \begin_inset Text
25617
25618 \begin_layout Standard
25619 LOW priority interrupts
25620 \end_layout
25621
25622 \end_inset
25623 </cell>
25624 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25625 \begin_inset Text
25626
25627 \begin_layout Standard
25628 0x000018
25629 \end_layout
25630
25631 \end_inset
25632 </cell>
25633 </row>
25634 </lyxtabular>
25635
25636 \end_inset
25637
25638
25639 \end_layout
25640
25641 \begin_layout Standard
25642 When generating assembly code for ISR the code generator places a 
25643 \noun on
25644 goto 
25645 \noun default
25646 instruction at the 
25647 \emph on
25648 Interrupt Vector Address
25649 \emph default
25650  which points at the genetated ISR.
25651  This single GOTO instruction is part of an automatically generated 
25652 \emph on
25653 interrupt entry point
25654 \emph default
25655  function.
25656  The actuall ISR code is placed as normally would in the code space.
25657  Upon interrupt request, the GOTO instruction is executed which jumps to
25658  the ISR code.
25659  When declaring interrupt functions as _naked this GOTO instruction is 
25660 \series bold
25661 not
25662 \series default
25663  generated.
25664  The whole interrupt functions is therefore placed at the Interrupt Vector
25665  Address of the specific interrupt.
25666  This is not a problem for the LOW priority interrupts, but it is a problem
25667  for the RESET and the HIGH priority interrupts because code may be written
25668  at the next interrupt´s vector address and cause undeterminate program
25669  behaviour if that interrupt is raised.
25670 \begin_inset Foot
25671 status open
25672
25673 \begin_layout Standard
25674 This is not a problem when
25675 \end_layout
25676
25677 \begin_layout Enumerate
25678 this is a HIGH interrupt ISR and LOW interrupts are 
25679 \emph on
25680 disabled
25681 \emph default
25682  or not used.
25683 \end_layout
25684
25685 \begin_layout Enumerate
25686 when the ISR is small enough not to reach the next interrupt´s vector address.
25687 \end_layout
25688
25689 \end_inset
25690
25691
25692 \end_layout
25693
25694 \begin_layout Standard
25695
25696 \emph on
25697 n
25698 \emph default
25699  is possible to be omitted.
25700  This way a function is generated similar to an ISR, but it is not assigned
25701  to any interrupt.
25702 \end_layout
25703
25704 \begin_layout Standard
25705 When entering an interrupt, currently the PIC16
25706 \begin_inset LatexCommand \index{PIC16}
25707
25708 \end_inset
25709
25710  port automatically saves the following registers:
25711 \end_layout
25712
25713 \begin_layout Itemize
25714 WREG
25715 \end_layout
25716
25717 \begin_layout Itemize
25718 STATUS
25719 \end_layout
25720
25721 \begin_layout Itemize
25722 BSR
25723 \end_layout
25724
25725 \begin_layout Itemize
25726 PROD (PRODL and PRODH)
25727 \end_layout
25728
25729 \begin_layout Itemize
25730 FSR0 (FSR0L and FSR0H)
25731 \end_layout
25732
25733 \begin_layout Standard
25734 These registers are restored upon return from the interrupt routine.
25735 \begin_inset Foot
25736 status open
25737
25738 \begin_layout Standard
25739 NOTE that when the _naked attribute is specified for an interrupt routine,
25740  then NO registers are stored or restored.
25741 \end_layout
25742
25743 \end_inset
25744
25745
25746 \end_layout
25747
25748 \begin_layout Subsection
25749 Generic Pointers
25750 \end_layout
25751
25752 \begin_layout Standard
25753 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
25754  There are 3 types of generic pointers currently implemented data, code
25755  and eeprom pointers.
25756  They are differentiated by the value of the 7th and 6th bits of the upper
25757  byte:
25758 \end_layout
25759
25760 \begin_layout Standard
25761 \align center
25762 \begin_inset Tabular
25763 <lyxtabular version="3" rows="5" columns="5">
25764 <features>
25765 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25766 <column alignment="center" valignment="top" width="0">
25767 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
25768 <column alignment="center" valignment="top" width="0">
25769 <column alignment="left" valignment="top" rightline="true" width="0">
25770 <row topline="true" bottomline="true">
25771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25772 \begin_inset Text
25773
25774 \begin_layout Standard
25775 pointer type
25776 \end_layout
25777
25778 \end_inset
25779 </cell>
25780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25781 \begin_inset Text
25782
25783 \begin_layout Standard
25784 7th bit
25785 \end_layout
25786
25787 \end_inset
25788 </cell>
25789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25790 \begin_inset Text
25791
25792 \begin_layout Standard
25793 6th bit
25794 \end_layout
25795
25796 \end_inset
25797 </cell>
25798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25799 \begin_inset Text
25800
25801 \begin_layout Standard
25802 rest of the pointer
25803 \end_layout
25804
25805 \end_inset
25806 </cell>
25807 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25808 \begin_inset Text
25809
25810 \begin_layout Standard
25811 description
25812 \end_layout
25813
25814 \end_inset
25815 </cell>
25816 </row>
25817 <row topline="true" bottomline="true">
25818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25819 \begin_inset Text
25820
25821 \begin_layout Standard
25822 data 
25823 \end_layout
25824
25825 \end_inset
25826 </cell>
25827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25828 \begin_inset Text
25829
25830 \begin_layout Standard
25831 1
25832 \end_layout
25833
25834 \end_inset
25835 </cell>
25836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25837 \begin_inset Text
25838
25839 \begin_layout Standard
25840 0
25841 \end_layout
25842
25843 \end_inset
25844 </cell>
25845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25846 \begin_inset Text
25847
25848 \begin_layout Standard
25849
25850 \family typewriter
25851 \shape slanted
25852 \emph on
25853 uuuuuu uuuuxxxx xxxxxxxx
25854 \end_layout
25855
25856 \end_inset
25857 </cell>
25858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25859 \begin_inset Text
25860
25861 \begin_layout Standard
25862 a 12-bit data pointer in data RAM memory
25863 \end_layout
25864
25865 \end_inset
25866 </cell>
25867 </row>
25868 <row bottomline="true">
25869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25870 \begin_inset Text
25871
25872 \begin_layout Standard
25873 code
25874 \end_layout
25875
25876 \end_inset
25877 </cell>
25878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25879 \begin_inset Text
25880
25881 \begin_layout Standard
25882 0
25883 \end_layout
25884
25885 \end_inset
25886 </cell>
25887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25888 \begin_inset Text
25889
25890 \begin_layout Standard
25891 0
25892 \end_layout
25893
25894 \end_inset
25895 </cell>
25896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25897 \begin_inset Text
25898
25899 \begin_layout Standard
25900
25901 \family typewriter
25902 \shape slanted
25903 \emph on
25904 uxxxxx xxxxxxxx xxxxxxxx
25905 \end_layout
25906
25907 \end_inset
25908 </cell>
25909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25910 \begin_inset Text
25911
25912 \begin_layout Standard
25913 a 21-bit code pointer in FLASH memory
25914 \end_layout
25915
25916 \end_inset
25917 </cell>
25918 </row>
25919 <row bottomline="true">
25920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25921 \begin_inset Text
25922
25923 \begin_layout Standard
25924 eeprom
25925 \end_layout
25926
25927 \end_inset
25928 </cell>
25929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25930 \begin_inset Text
25931
25932 \begin_layout Standard
25933 0
25934 \end_layout
25935
25936 \end_inset
25937 </cell>
25938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25939 \begin_inset Text
25940
25941 \begin_layout Standard
25942 1
25943 \end_layout
25944
25945 \end_inset
25946 </cell>
25947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25948 \begin_inset Text
25949
25950 \begin_layout Standard
25951
25952 \family typewriter
25953 \shape slanted
25954 \emph on
25955 uuuuuu uuuuuuxx xxxxxxxx
25956 \end_layout
25957
25958 \end_inset
25959 </cell>
25960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25961 \begin_inset Text
25962
25963 \begin_layout Standard
25964 a 10-bit eeprom pointer in EEPROM memory
25965 \end_layout
25966
25967 \end_inset
25968 </cell>
25969 </row>
25970 <row bottomline="true">
25971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25972 \begin_inset Text
25973
25974 \begin_layout Standard
25975 (unimplemented)
25976 \end_layout
25977
25978 \end_inset
25979 </cell>
25980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
25981 \begin_inset Text
25982
25983 \begin_layout Standard
25984 1
25985 \end_layout
25986
25987 \end_inset
25988 </cell>
25989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25990 \begin_inset Text
25991
25992 \begin_layout Standard
25993 1
25994 \end_layout
25995
25996 \end_inset
25997 </cell>
25998 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
25999 \begin_inset Text
26000
26001 \begin_layout Standard
26002
26003 \family typewriter
26004 \shape slanted
26005 \emph on
26006 xxxxxx xxxxxxxx xxxxxxxx
26007 \end_layout
26008
26009 \end_inset
26010 </cell>
26011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26012 \begin_inset Text
26013
26014 \begin_layout Standard
26015 unimplemented pointer type
26016 \end_layout
26017
26018 \end_inset
26019 </cell>
26020 </row>
26021 </lyxtabular>
26022
26023 \end_inset
26024
26025
26026 \end_layout
26027
26028 \begin_layout Standard
26029 Generic pointer are read and written with a set of library functions which
26030  read/write 1, 2, 3, 4 bytes.
26031 \end_layout
26032
26033 \begin_layout Subsection
26034 PIC16 C Libraries
26035 \end_layout
26036
26037 \begin_layout Subsubsection
26038 Standard I/O Streams
26039 \end_layout
26040
26041 \begin_layout Standard
26042 In the 
26043 \emph on
26044 stdio.h
26045 \emph default
26046  the type FILE is defined as:
26047 \end_layout
26048
26049 \begin_layout LyX-Code
26050 typedef char * FILE;
26051 \end_layout
26052
26053 \begin_layout Standard
26054 This type is the stream type implemented I/O in the PIC18F devices.
26055  Also the standard input and output streams are declared in stdio.h:
26056 \end_layout
26057
26058 \begin_layout LyX-Code
26059 extern FILE * stdin;
26060 \end_layout
26061
26062 \begin_layout LyX-Code
26063 extern FILE * stdout;
26064 \end_layout
26065
26066 \begin_layout Standard
26067 The FILE type is actually a generic pointer which defines one more type
26068  of generic pointers, the 
26069 \emph on
26070 stream 
26071 \emph default
26072 pointer.
26073  This new type has the format:
26074 \end_layout
26075
26076 \begin_layout Standard
26077 \align center
26078 \begin_inset Tabular
26079 <lyxtabular version="3" rows="2" columns="7">
26080 <features>
26081 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26082 <column alignment="center" valignment="top" width="0">
26083 <column alignment="center" valignment="top" leftline="true" width="0">
26084 <column alignment="center" valignment="top" leftline="true" width="0">
26085 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26086 <column alignment="center" valignment="top" width="0">
26087 <column alignment="left" valignment="top" rightline="true" width="0">
26088 <row topline="true" bottomline="true">
26089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26090 \begin_inset Text
26091
26092 \begin_layout Standard
26093 pointer type
26094 \end_layout
26095
26096 \end_inset
26097 </cell>
26098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26099 \begin_inset Text
26100
26101 \begin_layout Standard
26102 <7:6>
26103 \end_layout
26104
26105 \end_inset
26106 </cell>
26107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26108 \begin_inset Text
26109
26110 \begin_layout Standard
26111 <5>
26112 \end_layout
26113
26114 \end_inset
26115 </cell>
26116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26117 \begin_inset Text
26118
26119 \begin_layout Standard
26120 <4>
26121 \end_layout
26122
26123 \end_inset
26124 </cell>
26125 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26126 \begin_inset Text
26127
26128 \begin_layout Standard
26129 <3:0>
26130 \end_layout
26131
26132 \end_inset
26133 </cell>
26134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26135 \begin_inset Text
26136
26137 \begin_layout Standard
26138 rest of the pointer
26139 \end_layout
26140
26141 \end_inset
26142 </cell>
26143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26144 \begin_inset Text
26145
26146 \begin_layout Standard
26147 descrption
26148 \end_layout
26149
26150 \end_inset
26151 </cell>
26152 </row>
26153 <row topline="true" bottomline="true">
26154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26155 \begin_inset Text
26156
26157 \begin_layout Standard
26158 stream
26159 \end_layout
26160
26161 \end_inset
26162 </cell>
26163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26164 \begin_inset Text
26165
26166 \begin_layout Standard
26167 00
26168 \end_layout
26169
26170 \end_inset
26171 </cell>
26172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26173 \begin_inset Text
26174
26175 \begin_layout Standard
26176 1
26177 \end_layout
26178
26179 \end_inset
26180 </cell>
26181 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26182 \begin_inset Text
26183
26184 \begin_layout Standard
26185 0
26186 \end_layout
26187
26188 \end_inset
26189 </cell>
26190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26191 \begin_inset Text
26192
26193 \begin_layout Standard
26194 nnnn
26195 \end_layout
26196
26197 \end_inset
26198 </cell>
26199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26200 \begin_inset Text
26201
26202 \begin_layout Standard
26203
26204 \family typewriter
26205 \shape slanted
26206 \emph on
26207 uuuuuuuu uuuuuuuu
26208 \end_layout
26209
26210 \end_inset
26211 </cell>
26212 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26213 \begin_inset Text
26214
26215 \begin_layout Standard
26216 upper byte high nubble is 0x2n, the rest are zeroes
26217 \end_layout
26218
26219 \end_inset
26220 </cell>
26221 </row>
26222 </lyxtabular>
26223
26224 \end_inset
26225
26226
26227 \end_layout
26228
26229 \begin_layout Standard
26230 Currently implemented there are 3 types of streams defined:
26231 \end_layout
26232
26233 \begin_layout Standard
26234 \align center
26235 \begin_inset Tabular
26236 <lyxtabular version="3" rows="4" columns="4">
26237 <features>
26238 <column alignment="center" valignment="top" leftline="true" width="0">
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" rightline="true" width="0">
26242 <row topline="true" bottomline="true">
26243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26244 \begin_inset Text
26245
26246 \begin_layout Standard
26247 stream type
26248 \end_layout
26249
26250 \end_inset
26251 </cell>
26252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26253 \begin_inset Text
26254
26255 \begin_layout Standard
26256 value
26257 \end_layout
26258
26259 \end_inset
26260 </cell>
26261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26262 \begin_inset Text
26263
26264 \begin_layout Standard
26265 module
26266 \end_layout
26267
26268 \end_inset
26269 </cell>
26270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26271 \begin_inset Text
26272
26273 \begin_layout Standard
26274 description
26275 \end_layout
26276
26277 \end_inset
26278 </cell>
26279 </row>
26280 <row topline="true">
26281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26282 \begin_inset Text
26283
26284 \begin_layout Standard
26285 STREAM_USART
26286 \end_layout
26287
26288 \end_inset
26289 </cell>
26290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26291 \begin_inset Text
26292
26293 \begin_layout Standard
26294
26295 \family typewriter
26296 0x200000UL
26297 \end_layout
26298
26299 \end_inset
26300 </cell>
26301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26302 \begin_inset Text
26303
26304 \begin_layout Standard
26305 USART
26306 \end_layout
26307
26308 \end_inset
26309 </cell>
26310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26311 \begin_inset Text
26312
26313 \begin_layout Standard
26314 Writes/Reads characters via the USART peripheral
26315 \end_layout
26316
26317 \end_inset
26318 </cell>
26319 </row>
26320 <row topline="true">
26321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26322 \begin_inset Text
26323
26324 \begin_layout Standard
26325 STREAM_MSSP
26326 \end_layout
26327
26328 \end_inset
26329 </cell>
26330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26331 \begin_inset Text
26332
26333 \begin_layout Standard
26334
26335 \family typewriter
26336 0x210000UL
26337 \end_layout
26338
26339 \end_inset
26340 </cell>
26341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26342 \begin_inset Text
26343
26344 \begin_layout Standard
26345 MSSP
26346 \end_layout
26347
26348 \end_inset
26349 </cell>
26350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26351 \begin_inset Text
26352
26353 \begin_layout Standard
26354 Writes/Reads characters via the MSSP peripheral
26355 \end_layout
26356
26357 \end_inset
26358 </cell>
26359 </row>
26360 <row topline="true" bottomline="true">
26361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26362 \begin_inset Text
26363
26364 \begin_layout Standard
26365 STREAM_USER
26366 \end_layout
26367
26368 \end_inset
26369 </cell>
26370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26371 \begin_inset Text
26372
26373 \begin_layout Standard
26374
26375 \family typewriter
26376 0x2f0000UL
26377 \end_layout
26378
26379 \end_inset
26380 </cell>
26381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26382 \begin_inset Text
26383
26384 \begin_layout Standard
26385 (none)
26386 \end_layout
26387
26388 \end_inset
26389 </cell>
26390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26391 \begin_inset Text
26392
26393 \begin_layout Standard
26394 Writes/Reads characters via used defined functions
26395 \end_layout
26396
26397 \end_inset
26398 </cell>
26399 </row>
26400 </lyxtabular>
26401
26402 \end_inset
26403
26404
26405 \end_layout
26406
26407 \begin_layout Standard
26408 The stream identifiers are declared as macros in the stdio.h header.
26409 \end_layout
26410
26411 \begin_layout Standard
26412 In the libc library there exist the functions that are used to write to
26413  each of the above streams.
26414  These are
26415 \end_layout
26416
26417 \begin_layout List
26418 \labelwidthstring 00.00.0000
26419 _
26420 \begin_inset ERT
26421 status collapsed
26422
26423 \begin_layout Standard
26424
26425
26426 \backslash
26427 /
26428 \end_layout
26429
26430 \end_inset
26431
26432 _stream_usart_putchar writes a character at the USART stream
26433 \end_layout
26434
26435 \begin_layout List
26436 \labelwidthstring 00.00.0000
26437 _
26438 \begin_inset ERT
26439 status collapsed
26440
26441 \begin_layout Standard
26442
26443
26444 \backslash
26445 /
26446 \end_layout
26447
26448 \end_inset
26449
26450 _stream_mssp_putchar writes a character at the MSSP stream
26451 \end_layout
26452
26453 \begin_layout List
26454 \labelwidthstring 00.00.0000
26455 putchar dummy function.
26456  This writes a character to a user specified manner.
26457 \end_layout
26458
26459 \begin_layout Standard
26460 In order to increase performance 
26461 \emph on
26462 putchar 
26463 \emph default
26464 is declared in stdio.h as having its parameter in WREG (it has the wparam
26465  keyword).
26466  In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
26467  in a user-friendly way.
26468  
26469 \emph on
26470 arg
26471 \emph default
26472  is the name of the variable that holds the character to print.
26473  An example follows:
26474 \end_layout
26475
26476 \begin_layout LyX-Code
26477 #include <pic18fregs.h>
26478 \newline
26479 #include <stdio.h>
26480 \newline
26481
26482 \newline
26483 PUTCHAR( c )
26484 \end_layout
26485
26486 \begin_layout LyX-Code
26487 {
26488 \end_layout
26489
26490 \begin_layout LyX-Code
26491     PORTA = c;    /* dump character c to PORTA */
26492 \end_layout
26493
26494 \begin_layout LyX-Code
26495
26496 \newline
26497
26498 \newline
26499 void main(void)
26500 \end_layout
26501
26502 \begin_layout LyX-Code
26503 {
26504 \end_layout
26505
26506 \begin_layout LyX-Code
26507     stdout = STREAM_USER;    /* this is not necessary, since stdout points
26508 \end_layout
26509
26510 \begin_layout LyX-Code
26511                               * by default to STREAM_USER */
26512 \end_layout
26513
26514 \begin_layout LyX-Code
26515     printf (¨This is a printf test
26516 \backslash
26517 n¨);
26518 \end_layout
26519
26520 \begin_layout LyX-Code
26521 }
26522 \end_layout
26523
26524 \begin_layout LyX-Code
26525
26526 \end_layout
26527
26528 \begin_layout Subsubsection
26529 Printing functions
26530 \end_layout
26531
26532 \begin_layout Standard
26533 PIC16 contains an implementation of the printf-family of functions.
26534  There exist the following functions:
26535 \end_layout
26536
26537 \begin_layout LyX-Code
26538 extern unsigned int sprintf(char *buf, char *fmt, ...);
26539 \end_layout
26540
26541 \begin_layout LyX-Code
26542 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
26543 \end_layout
26544
26545 \begin_layout LyX-Code
26546
26547 \end_layout
26548
26549 \begin_layout LyX-Code
26550 extern unsigned int printf(char *fmt, ...);
26551 \end_layout
26552
26553 \begin_layout LyX-Code
26554 extern unsigned int vprintf(char *fmt, va_lista ap);
26555 \end_layout
26556
26557 \begin_layout LyX-Code
26558
26559 \end_layout
26560
26561 \begin_layout LyX-Code
26562 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
26563 \end_layout
26564
26565 \begin_layout LyX-Code
26566 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
26567 \end_layout
26568
26569 \begin_layout Standard
26570 For sprintf and vsprintf 
26571 \emph on
26572 buf 
26573 \emph default
26574 should normally be a data pointer where the resulting string will be placed.
26575  No range checking is done so the user should allocate the necessery buffer.
26576  For fprintf and vfprintf 
26577 \emph on
26578 fp
26579 \emph default
26580  should be a stream pointer (i.e.
26581  stdout, STREAM_MSSP, etc...).
26582 \end_layout
26583
26584 \begin_layout Subsubsection
26585 Signals
26586 \end_layout
26587
26588 \begin_layout Standard
26589 The PIC18F family of microcontrollers supports a number of interrupt sources.
26590  A list of these interrupts is shown in the following table:
26591 \end_layout
26592
26593 \begin_layout Standard
26594 \align center
26595 \begin_inset Tabular
26596 <lyxtabular version="3" rows="11" columns="4">
26597 <features>
26598 <column alignment="left" valignment="top" leftline="true" width="0">
26599 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26600 <column alignment="left" valignment="top" leftline="true" width="0">
26601 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26602 <row topline="true" bottomline="true">
26603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26604 \begin_inset Text
26605
26606 \begin_layout Standard
26607 signal name
26608 \end_layout
26609
26610 \end_inset
26611 </cell>
26612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26613 \begin_inset Text
26614
26615 \begin_layout Standard
26616 description
26617 \end_layout
26618
26619 \end_inset
26620 </cell>
26621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26622 \begin_inset Text
26623
26624 \begin_layout Standard
26625 signal name
26626 \end_layout
26627
26628 \end_inset
26629 </cell>
26630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26631 \begin_inset Text
26632
26633 \begin_layout Standard
26634 descritpion
26635 \end_layout
26636
26637 \end_inset
26638 </cell>
26639 </row>
26640 <row topline="true">
26641 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26642 \begin_inset Text
26643
26644 \begin_layout Standard
26645 SIG_RB
26646 \end_layout
26647
26648 \end_inset
26649 </cell>
26650 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26651 \begin_inset Text
26652
26653 \begin_layout Standard
26654 PORTB change interrupt
26655 \end_layout
26656
26657 \end_inset
26658 </cell>
26659 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26660 \begin_inset Text
26661
26662 \begin_layout Standard
26663 SIG_EE
26664 \end_layout
26665
26666 \end_inset
26667 </cell>
26668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26669 \begin_inset Text
26670
26671 \begin_layout Standard
26672 EEPROM/FLASH write complete interrupt
26673 \end_layout
26674
26675 \end_inset
26676 </cell>
26677 </row>
26678 <row topline="true">
26679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26680 \begin_inset Text
26681
26682 \begin_layout Standard
26683 SIG_INT0
26684 \end_layout
26685
26686 \end_inset
26687 </cell>
26688 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26689 \begin_inset Text
26690
26691 \begin_layout Standard
26692 INT0 external interrupt
26693 \end_layout
26694
26695 \end_inset
26696 </cell>
26697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26698 \begin_inset Text
26699
26700 \begin_layout Standard
26701 SIG_BCOL
26702 \end_layout
26703
26704 \end_inset
26705 </cell>
26706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26707 \begin_inset Text
26708
26709 \begin_layout Standard
26710 Bus collision interrupt
26711 \end_layout
26712
26713 \end_inset
26714 </cell>
26715 </row>
26716 <row topline="true">
26717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26718 \begin_inset Text
26719
26720 \begin_layout Standard
26721 SIG_INT1
26722 \end_layout
26723
26724 \end_inset
26725 </cell>
26726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26727 \begin_inset Text
26728
26729 \begin_layout Standard
26730 INT1 external interrupt
26731 \end_layout
26732
26733 \end_inset
26734 </cell>
26735 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26736 \begin_inset Text
26737
26738 \begin_layout Standard
26739 SIG_LVD
26740 \end_layout
26741
26742 \end_inset
26743 </cell>
26744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26745 \begin_inset Text
26746
26747 \begin_layout Standard
26748 Low voltage detect interrupt
26749 \end_layout
26750
26751 \end_inset
26752 </cell>
26753 </row>
26754 <row topline="true">
26755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26756 \begin_inset Text
26757
26758 \begin_layout Standard
26759 SIG_INT2
26760 \end_layout
26761
26762 \end_inset
26763 </cell>
26764 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26765 \begin_inset Text
26766
26767 \begin_layout Standard
26768 INT2 external interrupt
26769 \end_layout
26770
26771 \end_inset
26772 </cell>
26773 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26774 \begin_inset Text
26775
26776 \begin_layout Standard
26777 SIG_PSP
26778 \end_layout
26779
26780 \end_inset
26781 </cell>
26782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26783 \begin_inset Text
26784
26785 \begin_layout Standard
26786 Parallel slave port interrupt
26787 \end_layout
26788
26789 \end_inset
26790 </cell>
26791 </row>
26792 <row topline="true">
26793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26794 \begin_inset Text
26795
26796 \begin_layout Standard
26797 SIG_CCP1
26798 \end_layout
26799
26800 \end_inset
26801 </cell>
26802 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26803 \begin_inset Text
26804
26805 \begin_layout Standard
26806 CCP1 module interrupt
26807 \end_layout
26808
26809 \end_inset
26810 </cell>
26811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26812 \begin_inset Text
26813
26814 \begin_layout Standard
26815 SIG_AD
26816 \end_layout
26817
26818 \end_inset
26819 </cell>
26820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26821 \begin_inset Text
26822
26823 \begin_layout Standard
26824 AD convertion complete interrupt
26825 \end_layout
26826
26827 \end_inset
26828 </cell>
26829 </row>
26830 <row topline="true">
26831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26832 \begin_inset Text
26833
26834 \begin_layout Standard
26835 SIG_CCP2
26836 \end_layout
26837
26838 \end_inset
26839 </cell>
26840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26841 \begin_inset Text
26842
26843 \begin_layout Standard
26844 CCP2 module interrupt
26845 \end_layout
26846
26847 \end_inset
26848 </cell>
26849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26850 \begin_inset Text
26851
26852 \begin_layout Standard
26853 SIG_RC
26854 \end_layout
26855
26856 \end_inset
26857 </cell>
26858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26859 \begin_inset Text
26860
26861 \begin_layout Standard
26862 USART receive interrupt
26863 \end_layout
26864
26865 \end_inset
26866 </cell>
26867 </row>
26868 <row topline="true">
26869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26870 \begin_inset Text
26871
26872 \begin_layout Standard
26873 SIG_TMR0
26874 \end_layout
26875
26876 \end_inset
26877 </cell>
26878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26879 \begin_inset Text
26880
26881 \begin_layout Standard
26882 TMR0 overflow interrupt
26883 \end_layout
26884
26885 \end_inset
26886 </cell>
26887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26888 \begin_inset Text
26889
26890 \begin_layout Standard
26891 SIG_TX
26892 \end_layout
26893
26894 \end_inset
26895 </cell>
26896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26897 \begin_inset Text
26898
26899 \begin_layout Standard
26900 USART transmit interrupt
26901 \end_layout
26902
26903 \end_inset
26904 </cell>
26905 </row>
26906 <row topline="true">
26907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26908 \begin_inset Text
26909
26910 \begin_layout Standard
26911 SIG_TMR1
26912 \end_layout
26913
26914 \end_inset
26915 </cell>
26916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26917 \begin_inset Text
26918
26919 \begin_layout Standard
26920 TMR1 overflow interrupt
26921 \end_layout
26922
26923 \end_inset
26924 </cell>
26925 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26926 \begin_inset Text
26927
26928 \begin_layout Standard
26929 SIG_MSSP
26930 \end_layout
26931
26932 \end_inset
26933 </cell>
26934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26935 \begin_inset Text
26936
26937 \begin_layout Standard
26938 SSP receive/transmit interrupt
26939 \end_layout
26940
26941 \end_inset
26942 </cell>
26943 </row>
26944 <row topline="true">
26945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26946 \begin_inset Text
26947
26948 \begin_layout Standard
26949 SIG_TMR2
26950 \end_layout
26951
26952 \end_inset
26953 </cell>
26954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26955 \begin_inset Text
26956
26957 \begin_layout Standard
26958 TMR2 matches PR2 interrupt
26959 \end_layout
26960
26961 \end_inset
26962 </cell>
26963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26964 \begin_inset Text
26965
26966 \begin_layout Standard
26967
26968 \end_layout
26969
26970 \end_inset
26971 </cell>
26972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26973 \begin_inset Text
26974
26975 \begin_layout Standard
26976
26977 \end_layout
26978
26979 \end_inset
26980 </cell>
26981 </row>
26982 <row topline="true" bottomline="true">
26983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26984 \begin_inset Text
26985
26986 \begin_layout Standard
26987 SIG_TMR3
26988 \end_layout
26989
26990 \end_inset
26991 </cell>
26992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26993 \begin_inset Text
26994
26995 \begin_layout Standard
26996 TMR3 overflow interrupt
26997 \end_layout
26998
26999 \end_inset
27000 </cell>
27001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27002 \begin_inset Text
27003
27004 \begin_layout Standard
27005
27006 \end_layout
27007
27008 \end_inset
27009 </cell>
27010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27011 \begin_inset Text
27012
27013 \begin_layout Standard
27014
27015 \end_layout
27016
27017 \end_inset
27018 </cell>
27019 </row>
27020 </lyxtabular>
27021
27022 \end_inset
27023
27024
27025 \end_layout
27026
27027 \begin_layout Standard
27028 The prototypes for these names are defined in the header file 
27029 \emph on
27030 signal.h
27031 \emph default
27032  .
27033 \end_layout
27034
27035 \begin_layout Standard
27036 In order to simplify signal handling, a number of macros is provided:
27037 \end_layout
27038
27039 \begin_layout List
27040 \labelwidthstring 00.00.0000
27041 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
27042  high priority interrupts.
27043  
27044 \emph on
27045 name
27046 \emph default
27047  is the function name to use.
27048 \end_layout
27049
27050 \begin_layout List
27051 \labelwidthstring 00.00.0000
27052 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
27053  low priority interrupt.
27054  
27055 \emph on
27056 name
27057 \emph default
27058  is the function name to use.
27059 \end_layout
27060
27061 \begin_layout List
27062 \labelwidthstring 00.00.0000
27063 DEF_HANDLER(sig,handler) define a handler for signal 
27064 \emph on
27065 sig.
27066 \end_layout
27067
27068 \begin_layout List
27069 \labelwidthstring 00.00.0000
27070 END_DEF end the declaration of the dispatch table.
27071 \end_layout
27072
27073 \begin_layout Standard
27074 Additionally there are two more macros to simplify the declaration of the
27075  signal handler:
27076 \end_layout
27077
27078 \begin_layout List
27079 \labelwidthstring 00.00.0000
27080
27081 \series medium
27082 SIGHANDLER(handler) 
27083 \series default
27084 this declares the function prototype for the 
27085 \emph on
27086 handler
27087 \emph default
27088  function.
27089 \end_layout
27090
27091 \begin_layout List
27092 \labelwidthstring 00.00.0000
27093 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
27094 \end_layout
27095
27096 \begin_layout Standard
27097 An example of using the macros above is shown below:
27098 \end_layout
27099
27100 \begin_layout LyX-Code
27101 #include <pic18fregs.h>
27102 \end_layout
27103
27104 \begin_layout LyX-Code
27105 #include <signal.h>
27106 \newline
27107
27108 \newline
27109 DEF_INTHIGH(high_int)
27110 \end_layout
27111
27112 \begin_layout LyX-Code
27113 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
27114 \end_layout
27115
27116 \begin_layout LyX-Code
27117 DEF_HANDLER(SIG_BCOL, _bcol_handler)
27118 \end_layout
27119
27120 \begin_layout LyX-Code
27121 END_DEF
27122 \newline
27123
27124 \newline
27125 SIGHANDLER(_tmr0_handler)
27126 \end_layout
27127
27128 \begin_layout LyX-Code
27129 {
27130 \end_layout
27131
27132 \begin_layout LyX-Code
27133   /* action to be taken when timer 0 overflows */
27134 \end_layout
27135
27136 \begin_layout LyX-Code
27137 }
27138 \newline
27139
27140 \newline
27141 SIGHANDLERNAKED(_bcol_handler)
27142 \end_layout
27143
27144 \begin_layout LyX-Code
27145 {
27146 \end_layout
27147
27148 \begin_layout LyX-Code
27149   _asm
27150 \end_layout
27151
27152 \begin_layout LyX-Code
27153     /* action to be taken when bus collision occurs */
27154 \end_layout
27155
27156 \begin_layout LyX-Code
27157     retfie
27158 \end_layout
27159
27160 \begin_layout LyX-Code
27161  _endasm;
27162 \end_layout
27163
27164 \begin_layout LyX-Code
27165 }
27166 \end_layout
27167
27168 \begin_layout Standard
27169
27170 \series bold
27171 NOTES:
27172 \series default
27173  Special care should be taken when using the above scheme:
27174 \end_layout
27175
27176 \begin_layout Itemize
27177 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
27178 \end_layout
27179
27180 \begin_layout Itemize
27181 when declaring SIGHANDLERNAKED handler never forget to use 
27182 \emph on
27183 retfie
27184 \emph default
27185  for proper returning.
27186 \end_layout
27187
27188 \begin_layout Subsection
27189 PIC16 Port -- Tips
27190 \end_layout
27191
27192 \begin_layout Standard
27193 Here you can find some general tips for compiling programs with SDCC/pic16.
27194 \end_layout
27195
27196 \begin_layout Subsubsection
27197 Stack size
27198 \end_layout
27199
27200 \begin_layout Standard
27201 The default stack
27202 \begin_inset LatexCommand \index{PIC16!stack}
27203
27204 \end_inset
27205
27206  size (that is 64 bytes) probably is enough for many programs.
27207  One must take care that when there are many levels of function nesting,
27208  or there is excessive usage of stack, its size should be extended.
27209  An example of such a case is the printf/sprintf family of functions.
27210  If you encounter problems like not being able to print integers, then you
27211  need to set the stack size around the maximum (256 for small stack model).
27212  The following diagram shows what happens when calling printf to print an
27213  integer:
27214 \end_layout
27215
27216 \begin_layout LyX-Code
27217 printf () --> ltoa () --> ultoa () --> divschar ()
27218 \end_layout
27219
27220 \begin_layout Standard
27221 It is should be understood that stack is easily consumed when calling complicate
27222 d functions.
27223  Using command line arguments like -
27224 \begin_inset ERT
27225 status collapsed
27226
27227 \begin_layout Standard
27228
27229
27230 \backslash
27231 /
27232 \end_layout
27233
27234 \end_inset
27235
27236 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
27237  stack frames.
27238  Other ways to reduce stack usage may exist.
27239 \end_layout
27240
27241 \begin_layout Subsection
27242 Known bugs
27243 \end_layout
27244
27245 \begin_layout Standard
27246 The PIC16 Port currently does not pass SDCC's regression test
27247 \begin_inset LatexCommand \index{Regression test (PIC16)}
27248
27249 \end_inset
27250
27251  suite (see section 
27252 \begin_inset LatexCommand \ref{sec:Quality-control}
27253
27254 \end_inset
27255
27256 ) and thus the snapshot build regression tests for the PIC16 target are
27257  currently disabled for all hosts
27258 \emph on
27259 .
27260 \end_layout
27261
27262 \begin_layout Chapter
27263 Debugging
27264 \end_layout
27265
27266 \begin_layout Standard
27267 There are several approaches to debugging your code.
27268  This chapter is meant to show your options and to give detail on some of
27269  them:
27270 \newline
27271
27272 \newline
27273 When writing your code:
27274 \end_layout
27275
27276 \begin_layout Itemize
27277 write your code with debugging in mind (avoid duplicating code, put conceptually
27278  similar variables into structs, use structured code, have strategic points
27279  within your code where all variables are consistent, ...)
27280 \end_layout
27281
27282 \begin_layout Itemize
27283 run a syntax-checking tool like splint
27284 \begin_inset LatexCommand \index{splint (syntax checking tool)}
27285
27286 \end_inset
27287
27288
27289 \begin_inset LatexCommand \index{lint (syntax checking tool)}
27290
27291 \end_inset
27292
27293  (see -
27294 \begin_inset ERT
27295 status collapsed
27296
27297 \begin_layout Standard
27298
27299
27300 \backslash
27301 /
27302 \end_layout
27303
27304 \end_inset
27305
27306 -more-pedantic 
27307 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27308
27309 \end_inset
27310
27311 ) over the code.
27312 \end_layout
27313
27314 \begin_layout Itemize
27315 for the high level code use a C-compiler (like f.e.
27316  GCC) to compile run and debug the code on your host.
27317  See (see -
27318 \begin_inset ERT
27319 status collapsed
27320
27321 \begin_layout Standard
27322
27323
27324 \backslash
27325 /
27326 \end_layout
27327
27328 \end_inset
27329
27330 -more-pedantic 
27331 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
27332
27333 \end_inset
27334
27335 ) on how to handle syntax extensions like __xdata, __at(), ...
27336  
27337 \end_layout
27338
27339 \begin_layout Itemize
27340 use another C-compiler to compile code for your target.
27341  Always an option but not recommended:) And not very likely to help you.
27342  If you seriously consider walking this path you should at least occasionally
27343  check portability of your code.
27344  Most commercial compiler vendors will offer an evaluation version so you
27345  can test compile your code or snippets of your code.
27346 \end_layout
27347
27348 \begin_layout Standard
27349 Debugging on a simulator:
27350 \end_layout
27351
27352 \begin_layout Itemize
27353 there is a separate section about SDCDB (section 
27354 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
27355
27356 \end_inset
27357
27358 ) below.
27359 \end_layout
27360
27361 \begin_layout Itemize
27362 or (8051 specific) use a freeware/commercial simulator which interfaces
27363  to the AOMF
27364 \begin_inset LatexCommand \index{AOMF, AOMF51}
27365
27366 \end_inset
27367
27368  file (see 
27369 \begin_inset LatexCommand \ref{OMF file}
27370
27371 \end_inset
27372
27373 ) optionally generated by SDCC.
27374 \end_layout
27375
27376 \begin_layout Standard
27377 Debugging On-target: 
27378 \end_layout
27379
27380 \begin_layout Itemize
27381 use a MCU port pin to serially output debug data to the RS232 port of your
27382  host.
27383  You'll probably want some level shifting device typically involving a MAX232
27384  or similar IC.
27385  If the hardware serial port of the MCU is not available search for 'Software
27386  UART' in your favourite search machine.
27387 \end_layout
27388
27389 \begin_layout Itemize
27390 use an on-target monitor.
27391  In this context a monitor is a small program which usually accepts commands
27392  via a serial line and allows to set program counter, to single step through
27393  a program and read/write memory locations.
27394  For the 8051 good examples of monitors are paulmon and cmon51 (see section
27395  
27396 \begin_inset LatexCommand \ref{sec:Related-open-source-tools}
27397
27398 \end_inset
27399
27400 ).
27401 \end_layout
27402
27403 \begin_layout Itemize
27404 toggle MCU port pins at strategic points within your code and use an oscilloscop
27405 e.
27406  A 
27407 \emph on
27408 digital oscilloscope
27409 \emph default
27410
27411 \begin_inset LatexCommand \index{Oscilloscope}
27412
27413 \end_inset
27414
27415  with deep trace memory is really helpful especially if you have to debug
27416  a realtime application.
27417  If you need to monitor more pins than your oscilloscope provides you can
27418  sometimes get away with a small R-2R network.
27419  On a single channel oscilloscope you could f.e.
27420  monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
27421 k
27422 \begin_inset Formula $\Omega$
27423 \end_inset
27424
27425  resistor and the other one by a 5\InsetSpace ~
27426 k
27427 \begin_inset Formula $\Omega$
27428 \end_inset
27429
27430  resistor to the oscilloscope probe (check output drive capability of the
27431  pins you want to monitor).
27432  If you need to monitor many more pins a 
27433 \emph on
27434 logic analyzer
27435 \emph default
27436  will be handy.
27437 \end_layout
27438
27439 \begin_layout Itemize
27440 use an ICE (
27441 \emph on
27442 i
27443 \emph default
27444
27445 \emph on
27446 c
27447 \emph default
27448 ircuit 
27449 \emph on
27450 e
27451 \emph default
27452 mulator
27453 \begin_inset LatexCommand \index{ICE (in circuit emulator)}
27454
27455 \end_inset
27456
27457 ).
27458  Usually very expensive.
27459  And very nice to have too.
27460  And usually locks you (for years...) to the devices the ICE can emulate.
27461  
27462 \end_layout
27463
27464 \begin_layout Itemize
27465 use a remote debugger.
27466  In most 8-bit systems the symbol information is not available on the target,
27467  and a complete debugger is too bulky for the target system.
27468  Therefore usually a debugger on the host system connects to an on-target
27469  debugging stub which accepts only primitive commands.
27470  
27471 \newline
27472 Terms to enter into your favourite search engine could be 'remote debugging',
27473  'gdb stub' or 'inferior debugger'.
27474  (is there one?)
27475 \end_layout
27476
27477 \begin_layout Itemize
27478 use an on target hardware debugger.
27479  Some of the more modern MCUs include hardware support for setting break
27480  points and monitoring/changing variables by using dedicated hardware pins.
27481  This facility doesn't require additional code to run on the target and
27482  
27483 \emph on
27484 usually
27485 \emph default
27486  doesn't affect runtime behaviour until a breakpoint is hit.
27487  For the mcs51 most hardware debuggers use the AOMF
27488 \begin_inset LatexCommand \index{AOMF, AOMF51}
27489
27490 \end_inset
27491
27492  file (see 
27493 \begin_inset LatexCommand \ref{OMF file}
27494
27495 \end_inset
27496
27497 ) as input file.
27498  
27499 \end_layout
27500
27501 \begin_layout Standard
27502 Last not least:
27503 \end_layout
27504
27505 \begin_layout Itemize
27506 if you are not familiar with any of the following terms you're likely to
27507  run into problems rather sooner than later: 
27508 \emph on
27509 volatile
27510 \emph default
27511
27512 \emph on
27513 atomic
27514 \emph default
27515
27516 \emph on
27517 memory map
27518 \emph default
27519
27520 \emph on
27521 overlay
27522 \emph default
27523 .
27524  As an embedded programmer you 
27525 \emph on
27526 have
27527 \emph default
27528  to know them so why not look them up 
27529 \emph on
27530 before
27531 \emph default
27532  you have problems?)
27533 \end_layout
27534
27535 \begin_layout Itemize
27536 tell someone else about your problem (actually this is a surprisingly effective
27537  means to hunt down the bug even if the listener is not familiar with your
27538  environment).
27539  As 'failure to communicate' is probably one of the job-induced deformations
27540  of an embedded programmer this is highly encouraged.
27541 \end_layout
27542
27543 \begin_layout Section
27544 Debugging with SDCDB
27545 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
27546
27547 \end_inset
27548
27549
27550 \begin_inset LatexCommand \index{SDCDB (debugger)}
27551
27552 \end_inset
27553
27554  
27555 \end_layout
27556
27557 \begin_layout Standard
27558 SDCC is distributed with a source level debugger
27559 \begin_inset LatexCommand \index{Debugger}
27560
27561 \end_inset
27562
27563 .
27564  The debugger uses a command line interface, the command repertoire of the
27565  debugger has been kept as close to gdb
27566 \begin_inset LatexCommand \index{gdb}
27567
27568 \end_inset
27569
27570  (the GNU debugger) as possible.
27571  The configuration and build process is part of the standard compiler installati
27572 on, which also builds and installs the debugger in the target directory
27573  specified during configuration.
27574  The debugger allows you debug BOTH at the C source and at the ASM source
27575  level.
27576 \end_layout
27577
27578 \begin_layout Subsection
27579 Compiling for Debugging
27580 \end_layout
27581
27582 \begin_layout Standard
27583 The -
27584 \begin_inset ERT
27585 status collapsed
27586
27587 \begin_layout Standard
27588
27589
27590 \backslash
27591 /
27592 \end_layout
27593
27594 \end_inset
27595
27596 -debug
27597 \begin_inset LatexCommand \index{-\/-debug}
27598
27599 \end_inset
27600
27601  option must be specified for all files for which debug information is to
27602  be generated.
27603  The compiler generates a .adb file for each of these files.
27604  The linker creates the .cdb
27605 \begin_inset LatexCommand \index{<file>.cdb}
27606
27607 \end_inset
27608
27609  file from the .adb
27610 \begin_inset LatexCommand \index{<file>.adb}
27611
27612 \end_inset
27613
27614  files and the address information.
27615  This .cdb is used by the debugger.
27616 \end_layout
27617
27618 \begin_layout Subsection
27619 How the Debugger Works
27620 \end_layout
27621
27622 \begin_layout Standard
27623 When the -
27624 \begin_inset ERT
27625 status collapsed
27626
27627 \begin_layout Standard
27628
27629
27630 \backslash
27631 /
27632 \end_layout
27633
27634 \end_inset
27635
27636 -debug option is specified the compiler generates extra symbol information
27637  some of which are put into the assembler source and some are put into the
27638  .adb file.
27639  Then the linker creates the .cdb file from the individual .adb files with
27640  the address information for the symbols.
27641  The debugger reads the symbolic information generated by the compiler &
27642  the address information generated by the linker.
27643  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
27644  execution is controlled by the debugger.
27645  When a command is issued for the debugger, it translates it into appropriate
27646  commands for the simulator.
27647  (Currently SDCDM only connects to the simulator but 
27648 \emph on
27649 newcdb
27650 \emph default
27651  at 
27652 \begin_inset LatexCommand \url{http://ec2drv.sf.net/}
27653
27654 \end_inset
27655
27656  is an effort to connect directly to the hardware.) 
27657 \end_layout
27658
27659 \begin_layout Subsection
27660 Starting the Debugger SDCDB
27661 \end_layout
27662
27663 \begin_layout Standard
27664 The debugger can be started using the following command line.
27665  (Assume the file you are debugging has the file name foo).
27666 \newline
27667
27668 \newline
27669
27670 \family sans
27671 \series bold
27672 sdcdb foo
27673 \newline
27674
27675 \family default
27676 \series default
27677
27678 \newline
27679 The debugger will look for the following files.
27680 \end_layout
27681
27682 \begin_layout Itemize
27683 foo.c - the source file.
27684 \end_layout
27685
27686 \begin_layout Itemize
27687 foo.cdb - the debugger symbol information file.
27688 \end_layout
27689
27690 \begin_layout Itemize
27691 foo.ihx - the Intel hex format
27692 \begin_inset LatexCommand \index{Intel hex format}
27693
27694 \end_inset
27695
27696  object file.
27697 \end_layout
27698
27699 \begin_layout Subsection
27700 SDCDB Command Line Options
27701 \end_layout
27702
27703 \begin_layout Itemize
27704 -
27705 \begin_inset ERT
27706 status collapsed
27707
27708 \begin_layout Standard
27709
27710
27711 \backslash
27712 /
27713 \end_layout
27714
27715 \end_inset
27716
27717 -directory=<source file directory> this option can used to specify the directory
27718  search list.
27719  The debugger will look into the directory list specified for source, cdb
27720  & ihx files.
27721  The items in the directory list must be separated by ':', e.g.
27722  if the source files can be in the directories /home/src1 and /home/src2,
27723  the -
27724 \begin_inset ERT
27725 status collapsed
27726
27727 \begin_layout Standard
27728
27729
27730 \backslash
27731 /
27732 \end_layout
27733
27734 \end_inset
27735
27736 -directory option should be -
27737 \begin_inset ERT
27738 status collapsed
27739
27740 \begin_layout Standard
27741
27742
27743 \backslash
27744 /
27745 \end_layout
27746
27747 \end_inset
27748
27749 -directory=/home/src1:/home/src2.
27750  Note there can be no spaces in the option.
27751  
27752 \end_layout
27753
27754 \begin_layout Itemize
27755 -cd <directory> - change to the <directory>.
27756 \end_layout
27757
27758 \begin_layout Itemize
27759 -fullname - used by GUI front ends.
27760 \end_layout
27761
27762 \begin_layout Itemize
27763 -cpu <cpu-type> - this argument is passed to the simulator please see the
27764  simulator docs for details.
27765 \end_layout
27766
27767 \begin_layout Itemize
27768 -X <Clock frequency > this options is passed to the simulator please see
27769  the simulator docs for details.
27770 \end_layout
27771
27772 \begin_layout Itemize
27773 -s <serial port file> passed to simulator see the simulator docs for details.
27774 \end_layout
27775
27776 \begin_layout Itemize
27777 -S <serial in,out> passed to simulator see the simulator docs for details.
27778 \end_layout
27779
27780 \begin_layout Itemize
27781 -k <port number> passed to simulator see the simulator docs for details.
27782 \end_layout
27783
27784 \begin_layout Subsection
27785 SDCDB Debugger Commands
27786 \end_layout
27787
27788 \begin_layout Standard
27789 As mentioned earlier the command interface for the debugger has been deliberatel
27790 y kept as close the GNU debugger gdb, as possible.
27791  This will help the integration with existing graphical user interfaces
27792  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
27793  If you use a graphical user interface for the debugger you can skip this
27794  section.
27795 \end_layout
27796
27797 \begin_layout Subsubsection*
27798 break [line | file:line | function | file:function]
27799 \end_layout
27800
27801 \begin_layout Standard
27802 Set breakpoint at specified line or function:
27803 \newline
27804
27805 \newline
27806
27807 \family sans
27808 \series bold
27809 sdcdb>break 100 
27810 \newline
27811 sdcdb>break foo.c:100
27812 \newline
27813 sdcdb>break funcfoo
27814 \newline
27815 sdcdb>break foo.c:funcfoo
27816 \end_layout
27817
27818 \begin_layout Subsubsection*
27819 clear [line | file:line | function | file:function ]
27820 \end_layout
27821
27822 \begin_layout Standard
27823 Clear breakpoint at specified line or function:
27824 \newline
27825
27826 \newline
27827
27828 \family sans
27829 \series bold
27830 sdcdb>clear 100
27831 \newline
27832 sdcdb>clear foo.c:100
27833 \newline
27834 sdcdb>clear funcfoo
27835 \newline
27836 sdcdb>clear foo.c:funcfoo
27837 \end_layout
27838
27839 \begin_layout Subsubsection*
27840 continue
27841 \end_layout
27842
27843 \begin_layout Standard
27844 Continue program being debugged, after breakpoint.
27845 \end_layout
27846
27847 \begin_layout Subsubsection*
27848 finish
27849 \end_layout
27850
27851 \begin_layout Standard
27852 Execute till the end of the current function.
27853 \end_layout
27854
27855 \begin_layout Subsubsection*
27856 delete [n]
27857 \end_layout
27858
27859 \begin_layout Standard
27860 Delete breakpoint number 'n'.
27861  If used without any option clear ALL user defined break points.
27862 \end_layout
27863
27864 \begin_layout Subsubsection*
27865 info [break | stack | frame | registers ]
27866 \end_layout
27867
27868 \begin_layout Itemize
27869 info break - list all breakpoints
27870 \end_layout
27871
27872 \begin_layout Itemize
27873 info stack - show the function call stack.
27874 \end_layout
27875
27876 \begin_layout Itemize
27877 info frame - show information about the current execution frame.
27878 \end_layout
27879
27880 \begin_layout Itemize
27881 info registers - show content of all registers.
27882 \end_layout
27883
27884 \begin_layout Subsubsection*
27885 step
27886 \end_layout
27887
27888 \begin_layout Standard
27889 Step program until it reaches a different source line.
27890  Note: pressing <return> repeats the last command.
27891 \end_layout
27892
27893 \begin_layout Subsubsection*
27894 next
27895 \end_layout
27896
27897 \begin_layout Standard
27898 Step program, proceeding through subroutine calls.
27899 \end_layout
27900
27901 \begin_layout Subsubsection*
27902 run
27903 \end_layout
27904
27905 \begin_layout Standard
27906 Start debugged program.
27907 \end_layout
27908
27909 \begin_layout Subsubsection*
27910 ptype variable 
27911 \end_layout
27912
27913 \begin_layout Standard
27914 Print type information of the variable.
27915 \end_layout
27916
27917 \begin_layout Subsubsection*
27918 print variable
27919 \end_layout
27920
27921 \begin_layout Standard
27922 print value of variable.
27923 \end_layout
27924
27925 \begin_layout Subsubsection*
27926 file filename
27927 \end_layout
27928
27929 \begin_layout Standard
27930 load the given file name.
27931  Note this is an alternate method of loading file for debugging.
27932 \end_layout
27933
27934 \begin_layout Subsubsection*
27935 frame
27936 \end_layout
27937
27938 \begin_layout Standard
27939 print information about current frame.
27940 \end_layout
27941
27942 \begin_layout Subsubsection*
27943 set srcmode
27944 \end_layout
27945
27946 \begin_layout Standard
27947 Toggle between C source & assembly source.
27948 \end_layout
27949
27950 \begin_layout Subsubsection*
27951 ! simulator command
27952 \end_layout
27953
27954 \begin_layout Standard
27955 Send the string following '!' to the simulator, the simulator response is
27956  displayed.
27957  Note the debugger does not interpret the command being sent to the simulator,
27958  so if a command like 'go' is sent the debugger can loose its execution
27959  context and may display incorrect values.
27960 \end_layout
27961
27962 \begin_layout Subsubsection*
27963 quit
27964 \end_layout
27965
27966 \begin_layout Standard
27967 "Watch me now.
27968  Iam going Down.
27969  My name is Bobby Brown"
27970 \end_layout
27971
27972 \begin_layout Subsection
27973 Interfacing SDCDB with DDD
27974 \end_layout
27975
27976 \begin_layout Standard
27977 \begin_inset Note Note
27978 status collapsed
27979
27980 \begin_layout Standard
27981 The screenshot was converted from png to eps with: 
27982 \begin_inset Quotes sld
27983 \end_inset
27984
27985 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
27986 \begin_inset Quotes srd
27987 \end_inset
27988
27989  which produces a pretty compact eps file which is free from compression
27990  artifacts.
27991 \end_layout
27992
27993 \begin_layout Standard
27994 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
27995  as this broke the build system on Sourceforge (pdf-file was broken.
27996  pdflatex does not accept eps files).
27997 \end_layout
27998
27999 \end_inset
28000
28001
28002 \end_layout
28003
28004 \begin_layout Standard
28005 The 
28006 \emph on
28007 p
28008 \emph default
28009 ortable 
28010 \emph on
28011 n
28012 \emph default
28013 etwork 
28014 \emph on
28015 g
28016 \emph default
28017 raphics File 
28018 \size footnotesize
28019
28020 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png}
28021
28022 \end_inset
28023
28024
28025 \size default
28026  shows a screenshot of a debugging session with DDD
28027 \begin_inset LatexCommand \index{DDD (debugger)}
28028
28029 \end_inset
28030
28031  (Unix only) on a simulated 8032.
28032  The debugging session might not run as smoothly as the screenshot suggests.
28033  The debugger allows setting of breakpoints, displaying and changing variables,
28034  single stepping through C and assembler code.
28035  
28036 \newline
28037 The source was compiled with 
28038 \family sans
28039 \series bold
28040
28041 \newline
28042
28043 \newline
28044 sdcc -
28045 \family default
28046 \series default
28047
28048 \begin_inset ERT
28049 status collapsed
28050
28051 \begin_layout Standard
28052
28053
28054 \backslash
28055 /
28056 \end_layout
28057
28058 \end_inset
28059
28060
28061 \family sans
28062 \series bold
28063 -debug ddd_example.c
28064 \family default
28065 \series default
28066  
28067 \family sans
28068 \series bold
28069
28070 \newline
28071
28072 \family default
28073 \series default
28074
28075 \newline
28076 and DDD was invoked with 
28077 \family sans
28078 \series bold
28079
28080 \newline
28081
28082 \newline
28083 ddd -debugger "sdcdb -cpu 8032 ddd_example"
28084 \end_layout
28085
28086 \begin_layout Standard
28087 \begin_inset Note Note
28088 status open
28089
28090 \begin_layout Standard
28091 Check that the double quotes or an apostroph within the command line survive
28092  the LyX tool chain.
28093  Previously the apostrophs got slanted in the PDF output so a cut and paste
28094  did not work.
28095 \end_layout
28096
28097 \end_inset
28098
28099
28100 \end_layout
28101
28102 \begin_layout Subsection
28103 Interfacing SDCDB with XEmacs
28104 \begin_inset LatexCommand \index{XEmacs}
28105
28106 \end_inset
28107
28108
28109 \begin_inset LatexCommand \index{Emacs}
28110
28111 \end_inset
28112
28113
28114 \end_layout
28115
28116 \begin_layout Standard
28117 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
28118  sdcdb.el and sdcdbsrc.el.
28119  These two files can be found in the $(prefix)/bin directory after the installat
28120 ion is complete.
28121  These files need to be loaded into XEmacs for the interface to work.
28122  This can be done at XEmacs startup time by inserting the following into
28123  your '.xemacs' file (which can be found in your HOME directory): 
28124 \newline
28125
28126 \newline
28127
28128 \family typewriter
28129 (load-file sdcdbsrc.el) 
28130 \family default
28131
28132 \newline
28133
28134 \newline
28135 .xemacs is a lisp file so the () around the command is REQUIRED.
28136  The files can also be loaded dynamically while XEmacs is running, set the
28137  environment variable 'EMACSLOADPATH' to the installation bin directory
28138  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
28139  To start the interface enter the following command: 
28140 \newline
28141
28142 \newline
28143
28144 \family sans
28145 \series bold
28146 ESC-x sdcdbsrc
28147 \family default
28148 \series default
28149
28150 \newline
28151
28152 \newline
28153 You will prompted to enter the file name to be debugged.
28154  
28155 \newline
28156
28157 \newline
28158 The command line options that are passed to the simulator directly are
28159  bound to default values in the file sdcdbsrc.el.
28160  The variables are listed below, these values maybe changed as required.
28161 \end_layout
28162
28163 \begin_layout Itemize
28164 sdcdbsrc-cpu-type '51
28165 \end_layout
28166
28167 \begin_layout Itemize
28168 sdcdbsrc-frequency '11059200
28169 \end_layout
28170
28171 \begin_layout Itemize
28172 sdcdbsrc-serial nil
28173 \end_layout
28174
28175 \begin_layout Standard
28176 The following is a list of key mapping for the debugger interface.
28177 \end_layout
28178
28179 \begin_layout Standard
28180 \InsetSpace ~
28181
28182 \family typewriter
28183
28184 \newline
28185 ;;\InsetSpace ~
28186 Current Listing :: 
28187 \newline
28188 ;;key\InsetSpace ~
28189 \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 binding\InsetSpace ~
28203 \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 Comment 
28225 \newline
28226 ;;---\InsetSpace ~
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 -------
28263 \newline
28264 ;; 
28265 \newline
28266 ;;\InsetSpace ~
28267 n\InsetSpace ~
28268 \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 sdcdb-next-fro
28283 m-src\InsetSpace ~
28284 \InsetSpace ~
28285 \InsetSpace ~
28286 \InsetSpace ~
28287 \InsetSpace ~
28288 \InsetSpace ~
28289 \InsetSpace ~
28290 \InsetSpace ~
28291 \InsetSpace ~
28292 \InsetSpace ~
28293 SDCDB next command 
28294 \newline
28295 ;;\InsetSpace ~
28296 b\InsetSpace ~
28297 \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 sdcdb-back-from-src\InsetSpace ~
28312 \InsetSpace ~
28313 \InsetSpace ~
28314 \InsetSpace ~
28315 \InsetSpace ~
28316 \InsetSpace ~
28317 \InsetSpace ~
28318 \InsetSpace ~
28319 \InsetSpace ~
28320 \InsetSpace ~
28321 SDCDB back command 
28322 \newline
28323 ;;\InsetSpace ~
28324 c\InsetSpace ~
28325 \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 sdcdb-cont-f
28340 rom-src\InsetSpace ~
28341 \InsetSpace ~
28342 \InsetSpace ~
28343 \InsetSpace ~
28344 \InsetSpace ~
28345 \InsetSpace ~
28346 \InsetSpace ~
28347 \InsetSpace ~
28348 \InsetSpace ~
28349 \InsetSpace ~
28350 SDCDB continue command
28351 \newline
28352 ;;\InsetSpace ~
28353 s\InsetSpace ~
28354 \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 sdcdb-step-from-src\InsetSpace ~
28369 \InsetSpace ~
28370 \InsetSpace ~
28371 \InsetSpace ~
28372 \InsetSpace ~
28373 \InsetSpace ~
28374 \InsetSpace ~
28375 \InsetSpace ~
28376 \InsetSpace ~
28377 \InsetSpace ~
28378 SDCDB step command 
28379 \newline
28380 ;;\InsetSpace ~
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 sdcdb-w
28397 hatis-c-sexp\InsetSpace ~
28398 \InsetSpace ~
28399 \InsetSpace ~
28400 \InsetSpace ~
28401 \InsetSpace ~
28402 \InsetSpace ~
28403 \InsetSpace ~
28404 \InsetSpace ~
28405 \InsetSpace ~
28406 \InsetSpace ~
28407 SDCDB ptypecommand for data at 
28408 \newline
28409 ;;\InsetSpace ~
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 buffer point 
28457 \newline
28458 ;;\InsetSpace ~
28459 x\InsetSpace ~
28460 \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 sdcdbsrc-delete\InsetSpace ~
28475 \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 SDCD
28489 B Delete all breakpoints if no arg 
28490 \newline
28491 ;;\InsetSpace ~
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 given or delete arg (C-u arg x) 
28539 \newline
28540 ;;\InsetSpace ~
28541 m\InsetSpace ~
28542 \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 sdcdbsrc
28557 -frame\InsetSpace ~
28558 \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 SDCDB Display current frame if no arg, 
28573 \newline
28574 ;;\InsetSpace ~
28575 \InsetSpace ~
28576 \InsetSpace ~
28577 \InsetSpace ~
28578 \InsetSpace ~
28579 \InsetSpace ~
28580 \InsetSpace ~
28581 \InsetSpace ~
28582 \InsetSpace ~
28583 \InsetSpace ~
28584 \InsetSpace ~
28585 \InsetSpace ~
28586 \InsetSpace ~
28587 \InsetSpace ~
28588 \InsetSpace ~
28589 \InsetSpace ~
28590 \InsetSpace ~
28591 \InsetSpace ~
28592 \InsetSpace ~
28593 \InsetSpace ~
28594 \InsetSpace ~
28595 \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 given or display frame arg
28622  
28623 \newline
28624 ;;\InsetSpace ~
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 buffer point 
28672 \newline
28673 ;;\InsetSpace ~
28674 !\InsetSpace ~
28675 \InsetSpace ~
28676 \InsetSpace ~
28677 \InsetSpace ~
28678 \InsetSpace ~
28679 \InsetSpace ~
28680 \InsetSpace ~
28681 \InsetSpace ~
28682 \InsetSpace ~
28683 \InsetSpace ~
28684 \InsetSpace ~
28685 \InsetSpace ~
28686 \InsetSpace ~
28687 \InsetSpace ~
28688 \InsetSpace ~
28689 sdcdbsrc-goto-sdcdb\InsetSpace ~
28690 \InsetSpace ~
28691 \InsetSpace ~
28692 \InsetSpace ~
28693 \InsetSpace ~
28694 \InsetSpace ~
28695 \InsetSpace ~
28696 \InsetSpace ~
28697 \InsetSpace ~
28698 \InsetSpace ~
28699 Goto the SDCDB output buffer 
28700 \newline
28701 ;;\InsetSpace ~
28702 p\InsetSpace ~
28703 \InsetSpace ~
28704 \InsetSpace ~
28705 \InsetSpace ~
28706 \InsetSpace ~
28707 \InsetSpace ~
28708 \InsetSpace ~
28709 \InsetSpace ~
28710 \InsetSpace ~
28711 \InsetSpace ~
28712 \InsetSpace ~
28713 \InsetSpace ~
28714 \InsetSpace ~
28715 \InsetSpace ~
28716 \InsetSpace ~
28717 sdcdb-prin
28718 t-c-sexp\InsetSpace ~
28719 \InsetSpace ~
28720 \InsetSpace ~
28721 \InsetSpace ~
28722 \InsetSpace ~
28723 \InsetSpace ~
28724 \InsetSpace ~
28725 \InsetSpace ~
28726 \InsetSpace ~
28727 \InsetSpace ~
28728 \InsetSpace ~
28729 SDCDB print command for data at 
28730 \newline
28731 ;;\InsetSpace ~
28732 \InsetSpace ~
28733 \InsetSpace ~
28734 \InsetSpace ~
28735 \InsetSpace ~
28736 \InsetSpace ~
28737 \InsetSpace ~
28738 \InsetSpace ~
28739 \InsetSpace ~
28740 \InsetSpace ~
28741 \InsetSpace ~
28742 \InsetSpace ~
28743 \InsetSpace ~
28744 \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 buffer point 
28779 \newline
28780 ;;\InsetSpace ~
28781 g\InsetSpace ~
28782 \InsetSpace ~
28783 \InsetSpace ~
28784 \InsetSpace ~
28785 \InsetSpace ~
28786 \InsetSpace ~
28787 \InsetSpace ~
28788 \InsetSpace ~
28789 \InsetSpace ~
28790 \InsetSpace ~
28791 \InsetSpace ~
28792 \InsetSpace ~
28793 \InsetSpace ~
28794 \InsetSpace ~
28795 \InsetSpace ~
28796 sdcdbsrc-goto-sdcdb\InsetSpace ~
28797 \InsetSpace ~
28798 \InsetSpace ~
28799 \InsetSpace ~
28800 \InsetSpace ~
28801 \InsetSpace ~
28802 \InsetSpace ~
28803 \InsetSpace ~
28804 \InsetSpace ~
28805 \InsetSpace ~
28806 Got
28807 o the SDCDB output buffer 
28808 \newline
28809 ;;\InsetSpace ~
28810 t\InsetSpace ~
28811 \InsetSpace ~
28812 \InsetSpace ~
28813 \InsetSpace ~
28814 \InsetSpace ~
28815 \InsetSpace ~
28816 \InsetSpace ~
28817 \InsetSpace ~
28818 \InsetSpace ~
28819 \InsetSpace ~
28820 \InsetSpace ~
28821 \InsetSpace ~
28822 \InsetSpace ~
28823 \InsetSpace ~
28824 \InsetSpace ~
28825 sdcdbsrc-mode\InsetSpace ~
28826 \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 Toggles Sdcdbsrc mode (turns it
28842  off) 
28843 \newline
28844 ;; 
28845 \newline
28846 ;;\InsetSpace ~
28847 C-c\InsetSpace ~
28848 C-f\InsetSpace ~
28849 \InsetSpace ~
28850 \InsetSpace ~
28851 \InsetSpace ~
28852 \InsetSpace ~
28853 \InsetSpace ~
28854 \InsetSpace ~
28855 \InsetSpace ~
28856 \InsetSpace ~
28857 sdcdb-finish-from-src\InsetSpace ~
28858 \InsetSpace ~
28859 \InsetSpace ~
28860 \InsetSpace ~
28861 \InsetSpace ~
28862 \InsetSpace ~
28863 \InsetSpace ~
28864 \InsetSpace ~
28865 SDCDB finish command 
28866 \newline
28867 ;; 
28868 \newline
28869 ;;\InsetSpace ~
28870 C-x\InsetSpace ~
28871 SPC\InsetSpace ~
28872 \InsetSpace ~
28873 \InsetSpace ~
28874 \InsetSpace ~
28875 \InsetSpace ~
28876 \InsetSpace ~
28877 \InsetSpace ~
28878 \InsetSpace ~
28879 \InsetSpace ~
28880 sdcdb-brea
28881 k\InsetSpace ~
28882 \InsetSpace ~
28883 \InsetSpace ~
28884 \InsetSpace ~
28885 \InsetSpace ~
28886 \InsetSpace ~
28887 \InsetSpace ~
28888 \InsetSpace ~
28889 \InsetSpace ~
28890 \InsetSpace ~
28891 \InsetSpace ~
28892 \InsetSpace ~
28893 \InsetSpace ~
28894 \InsetSpace ~
28895 \InsetSpace ~
28896 \InsetSpace ~
28897 \InsetSpace ~
28898 \InsetSpace ~
28899 Set break for line with point 
28900 \newline
28901 ;;\InsetSpace ~
28902 ESC\InsetSpace ~
28903 t\InsetSpace ~
28904 \InsetSpace ~
28905 \InsetSpace ~
28906 \InsetSpace ~
28907 \InsetSpace ~
28908 \InsetSpace ~
28909 \InsetSpace ~
28910 \InsetSpace ~
28911 \InsetSpace ~
28912 \InsetSpace ~
28913 \InsetSpace ~
28914 sdcdbsrc-mode\InsetSpace ~
28915 \InsetSpace ~
28916 \InsetSpace ~
28917 \InsetSpace ~
28918 \InsetSpace ~
28919 \InsetSpace ~
28920 \InsetSpace ~
28921 \InsetSpace ~
28922 \InsetSpace ~
28923 \InsetSpace ~
28924 \InsetSpace ~
28925 \InsetSpace ~
28926 \InsetSpace ~
28927 \InsetSpace ~
28928 \InsetSpace ~
28929 \InsetSpace ~
28930 Toggle Sdcdbsrc mode 
28931 \newline
28932 ;;\InsetSpace ~
28933 ESC\InsetSpace ~
28934 m\InsetSpace ~
28935 \InsetSpace ~
28936 \InsetSpace ~
28937 \InsetSpace ~
28938 \InsetSpace ~
28939 \InsetSpace ~
28940 \InsetSpace ~
28941 \InsetSpace ~
28942 \InsetSpace ~
28943 \InsetSpace ~
28944 \InsetSpace ~
28945 sdc
28946 dbsrc-srcmode\InsetSpace ~
28947 \InsetSpace ~
28948 \InsetSpace ~
28949 \InsetSpace ~
28950 \InsetSpace ~
28951 \InsetSpace ~
28952 \InsetSpace ~
28953 \InsetSpace ~
28954 \InsetSpace ~
28955 \InsetSpace ~
28956 \InsetSpace ~
28957 \InsetSpace ~
28958 \InsetSpace ~
28959 Toggle list mode 
28960 \newline
28961 ;; 
28962 \newline
28963
28964 \family default
28965
28966 \newpage
28967
28968 \end_layout
28969
28970 \begin_layout Chapter
28971 TIPS
28972 \end_layout
28973
28974 \begin_layout Standard
28975 Here are a few guidelines that will help the compiler generate more efficient
28976  code, some of the tips are specific to this compiler others are generally
28977  good programming practice.
28978 \end_layout
28979
28980 \begin_layout Itemize
28981 Use the smallest data type to represent your data-value.
28982  If it is known in advance that the value is going to be less than 256 then
28983  use an 'unsigned char' instead of a 'short' or 'int'.
28984  Please note, that ANSI C requires both signed and unsigned chars to be
28985  promoted to 'signed int'
28986 \begin_inset LatexCommand \index{promotion to signed int}
28987
28988 \end_inset
28989
28990
28991 \begin_inset Marginal
28992 status collapsed
28993
28994 \begin_layout Standard
28995
28996 \series bold
28997 \InsetSpace ~
28998 !
28999 \end_layout
29000
29001 \end_inset
29002
29003  before doing any operation.
29004  This promotion
29005 \begin_inset LatexCommand \index{type promotion}
29006
29007 \end_inset
29008
29009
29010 \begin_inset LatexCommand \label{type promotion}
29011
29012 \end_inset
29013
29014  can be omitted, if the result is the same.
29015  The effect of the promotion rules together with the sign-extension is often
29016  surprising:
29017 \end_layout
29018
29019 \begin_deeper
29020 \begin_layout Verse
29021
29022 \family typewriter
29023 unsigned char uc = 0xfe;
29024 \newline
29025 if (uc * uc < 0) /* this is true! */
29026 \newline
29027 {
29028 \newline
29029 \InsetSpace ~
29030 \InsetSpace ~
29031 \InsetSpace ~
29032 \InsetSpace ~
29033 ....
29034 \newline
29035 }
29036 \end_layout
29037
29038 \begin_layout Standard
29039
29040 \family typewriter
29041 uc * uc
29042 \family default
29043  is evaluated as 
29044 \family typewriter
29045 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
29046 \family default
29047 .
29048  
29049 \newline
29050 Another one:
29051 \end_layout
29052
29053 \begin_layout Verse
29054
29055 \family typewriter
29056 (unsigned char) -12 / (signed char) -3 = ...
29057 \end_layout
29058
29059 \begin_layout Standard
29060 No, the result is not 4:
29061 \end_layout
29062
29063 \begin_layout Verse
29064
29065 \family typewriter
29066 (int) (unsigned char) -12 / (int) (signed char) -3 =
29067 \newline
29068 (int) (unsigned char)
29069  0xf4 / (int) (signed char) 0xfd =
29070 \newline
29071 (int) 0x00f4 / (int) 0xfffd =
29072 \newline
29073 (int) 0x00f4
29074  / (int) 0xfffd =
29075 \newline
29076 (int) 244 / (int) -3 =
29077 \newline
29078 (int) -81 = (int) 0xffaf;
29079 \end_layout
29080
29081 \begin_layout Standard
29082 Don't complain, that gcc gives you a different result.
29083  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
29084  Therefore the results are different.
29085 \newline
29086 From 
29087 \begin_inset Quotes sld
29088 \end_inset
29089
29090 comp.lang.c FAQ
29091 \begin_inset Quotes srd
29092 \end_inset
29093
29094 :
29095 \end_layout
29096
29097 \begin_layout Quote
29098
29099 \emph on
29100 If well-defined overflow characteristics are important and negative values
29101  are not, or if you want to steer clear of sign-extension problems when
29102  manipulating bits or bytes, use one of the corresponding unsigned types.
29103  (Beware when mixing signed and unsigned values in expressions, though.)
29104 \newline
29105 Although
29106  character types (especially unsigned char) can be used as "tiny" integers,
29107  doing so is sometimes more trouble than it's worth, due to unpredictable
29108  sign extension and increased code size.
29109 \end_layout
29110
29111 \end_deeper
29112 \begin_layout Itemize
29113 Use unsigned when it is known in advance that the value is not going to
29114  be negative.
29115  This helps especially if you are doing division or multiplication, bit-shifting
29116  or are using an array index.
29117 \end_layout
29118
29119 \begin_layout Itemize
29120 NEVER jump into a LOOP.
29121 \end_layout
29122
29123 \begin_layout Itemize
29124 Declare the variables to be local
29125 \begin_inset LatexCommand \index{local variables}
29126
29127 \end_inset
29128
29129  whenever possible, especially loop control variables (induction).
29130 \end_layout
29131
29132 \begin_layout Itemize
29133 Have a look at the assembly listing to get a 
29134 \begin_inset Quotes sld
29135 \end_inset
29136
29137 feeling
29138 \begin_inset Quotes srd
29139 \end_inset
29140
29141  for the code generation.
29142 \end_layout
29143
29144 \begin_layout Section
29145 Porting code from or to other compilers
29146 \begin_inset LatexCommand \label{sec:Porting-code-to-other-compilers}
29147
29148 \end_inset
29149
29150
29151 \end_layout
29152
29153 \begin_layout Itemize
29154 check whether endianness of the compilers differs and adapt where needed.
29155 \end_layout
29156
29157 \begin_layout Itemize
29158 check the device specific header files
29159 \begin_inset LatexCommand \index{Header files}
29160
29161 \end_inset
29162
29163
29164 \begin_inset LatexCommand \index{Include files}
29165
29166 \end_inset
29167
29168  for compiler specific syntax.
29169  Eventually include the file <compiler.h
29170 \begin_inset LatexCommand \index{compiler.h (include file)}
29171
29172 \end_inset
29173
29174
29175 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup}
29176
29177 \end_inset
29178
29179  to allow using common header files.
29180  (see f.e.
29181  cc2510fx.h 
29182 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup}
29183
29184 \end_inset
29185
29186 ).
29187 \end_layout
29188
29189 \begin_layout Itemize
29190 check whether the startup code contains the correct initialization (watchdog,
29191  peripherals).
29192 \end_layout
29193
29194 \begin_layout Itemize
29195 check whether the sizes of short, int, long match.
29196 \end_layout
29197
29198 \begin_layout Itemize
29199 check if some 16 or 32 bit hardware registers require a specific addressing
29200  order (least significant or most significant byte first) and adapt if needed
29201  (
29202 \emph on
29203 first
29204 \emph default
29205  and 
29206 \emph on
29207 last
29208 \emph default
29209  relate to time and not to lower/upper memory location here, so this is
29210  
29211 \emph on
29212 not
29213 \emph default
29214  the same as endianness).
29215 \end_layout
29216
29217 \begin_layout Itemize
29218 check whether the keyword 
29219 \emph on
29220 volatile
29221 \emph default
29222  is used where needed.
29223  The compilers might differ in their optimization characteristics (as different
29224  versions of the same compiler might also use more clever optimizations
29225  this is good idea anyway).
29226  See section 
29227 \begin_inset LatexCommand \ref{sub:Common-interrupt-pitfall-volatile}
29228
29229 \end_inset
29230
29231 .
29232 \end_layout
29233
29234 \begin_layout Itemize
29235 check that the compilers are not told to supress warnings.
29236 \end_layout
29237
29238 \begin_layout Itemize
29239 check and convert compiler specific extensions (interrupts, memory areas,
29240  pragmas etc.).
29241 \end_layout
29242
29243 \begin_layout Itemize
29244 check for differences in type promotion.
29245  Especially check for math operations on 
29246 \family typewriter
29247 char
29248 \family default
29249  or 
29250 \family typewriter
29251 unsigned char
29252 \family default
29253  variables.
29254  For the sake of C99 compatibility SDCC will probably promote these to 
29255 \family typewriter
29256 int
29257 \family default
29258  more often than other compilers.
29259  Eventually insert explicit casts to 
29260 \family typewriter
29261 (char) 
29262 \family default
29263 or
29264 \family typewriter
29265  (unsigned char)
29266 \family default
29267 .
29268  Also check that the ~\InsetSpace ~
29269 operator
29270 \begin_inset LatexCommand \index{\~\/ Operator}
29271
29272 \end_inset
29273
29274  is not used on 
29275 \family typewriter
29276 bit
29277 \begin_inset LatexCommand \index{bit}
29278
29279 \end_inset
29280
29281
29282 \family default
29283  variables, use the !\InsetSpace ~
29284 operator instead.
29285  See sections 
29286 \begin_inset LatexCommand \ref{type promotion}
29287
29288 \end_inset
29289
29290  and 
29291 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29292
29293 \end_inset
29294
29295 .
29296 \end_layout
29297
29298 \begin_layout Itemize
29299 check the assembly code generated for interrupt routines (f.e.
29300  for calls to possibly non-reentrant library functions).
29301 \end_layout
29302
29303 \begin_layout Itemize
29304 check whether timing loops result in proper timing (or preferably consider
29305  a rewrite of the code with timer based delays instead).
29306 \end_layout
29307
29308 \begin_layout Itemize
29309 check for differences in printf parameters (some compilers push (va_arg
29310 \begin_inset LatexCommand \index{vararg, va\_arg}
29311
29312 \end_inset
29313
29314 ) char variables as 
29315 \family typewriter
29316 int
29317 \family default
29318  others push them as 
29319 \family typewriter
29320 char
29321 \family default
29322 .
29323  See section 
29324 \begin_inset LatexCommand \ref{sec:Compatibility-with-previous}
29325
29326 \end_inset
29327
29328 ).
29329 \end_layout
29330
29331 \begin_layout Itemize
29332 check the resulting memory map
29333 \begin_inset LatexCommand \index{Memory map}
29334
29335 \end_inset
29336
29337 .
29338  Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
29339 ly idata, pdata, xdata).
29340  Eventually check if unexpected library functions are included.
29341 \end_layout
29342
29343 \begin_layout Section
29344 Tools
29345 \begin_inset LatexCommand \index{Tools}
29346
29347 \end_inset
29348
29349  included in the distribution
29350 \end_layout
29351
29352 \begin_layout Standard
29353 \align left
29354 \begin_inset Tabular
29355 <lyxtabular version="3" rows="12" columns="3">
29356 <features>
29357 <column alignment="left" valignment="top" leftline="true" width="0pt">
29358 <column alignment="left" valignment="top" leftline="true" width="0pt">
29359 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
29360 <row topline="true" bottomline="true">
29361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29362 \begin_inset Text
29363
29364 \begin_layout Standard
29365
29366 \series bold
29367 Name
29368 \end_layout
29369
29370 \end_inset
29371 </cell>
29372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29373 \begin_inset Text
29374
29375 \begin_layout Standard
29376
29377 \series bold
29378 Purpose
29379 \end_layout
29380
29381 \end_inset
29382 </cell>
29383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29384 \begin_inset Text
29385
29386 \begin_layout Standard
29387
29388 \series bold
29389 Directory
29390 \end_layout
29391
29392 \end_inset
29393 </cell>
29394 </row>
29395 <row topline="true">
29396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29397 \begin_inset Text
29398
29399 \begin_layout Standard
29400 uCsim
29401 \begin_inset LatexCommand \index{uCsim}
29402
29403 \end_inset
29404
29405
29406 \end_layout
29407
29408 \end_inset
29409 </cell>
29410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29411 \begin_inset Text
29412
29413 \begin_layout Standard
29414 Simulator for various architectures
29415 \end_layout
29416
29417 \end_inset
29418 </cell>
29419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29420 \begin_inset Text
29421
29422 \begin_layout Standard
29423 sdcc/sim/ucsim
29424 \end_layout
29425
29426 \end_inset
29427 </cell>
29428 </row>
29429 <row topline="true">
29430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29431 \begin_inset Text
29432
29433 \begin_layout Standard
29434 keil2sdcc.pl
29435 \end_layout
29436
29437 \end_inset
29438 </cell>
29439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29440 \begin_inset Text
29441
29442 \begin_layout Standard
29443 header file
29444 \begin_inset LatexCommand \index{Header files}
29445
29446 \end_inset
29447
29448
29449 \begin_inset LatexCommand \index{Include files}
29450
29451 \end_inset
29452
29453  conversion
29454 \end_layout
29455
29456 \end_inset
29457 </cell>
29458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29459 \begin_inset Text
29460
29461 \begin_layout Standard
29462 sdcc/support/scripts
29463 \end_layout
29464
29465 \end_inset
29466 </cell>
29467 </row>
29468 <row topline="true">
29469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29470 \begin_inset Text
29471
29472 \begin_layout Standard
29473 mh2h.c
29474 \end_layout
29475
29476 \end_inset
29477 </cell>
29478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29479 \begin_inset Text
29480
29481 \begin_layout Standard
29482 header file conversion
29483 \end_layout
29484
29485 \end_inset
29486 </cell>
29487 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29488 \begin_inset Text
29489
29490 \begin_layout Standard
29491 sdcc/support/scripts
29492 \end_layout
29493
29494 \end_inset
29495 </cell>
29496 </row>
29497 <row topline="true">
29498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29499 \begin_inset Text
29500
29501 \begin_layout Standard
29502 as-gbz80
29503 \end_layout
29504
29505 \end_inset
29506 </cell>
29507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29508 \begin_inset Text
29509
29510 \begin_layout Standard
29511 Assembler
29512 \end_layout
29513
29514 \end_inset
29515 </cell>
29516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29517 \begin_inset Text
29518
29519 \begin_layout Standard
29520
29521 \family roman
29522 \series medium
29523 \shape up
29524 \size normal
29525 \emph off
29526 \bar no
29527 \noun off
29528 \color none
29529 sdcc/bin
29530 \end_layout
29531
29532 \end_inset
29533 </cell>
29534 </row>
29535 <row topline="true">
29536 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29537 \begin_inset Text
29538
29539 \begin_layout Standard
29540 as-z80
29541 \end_layout
29542
29543 \end_inset
29544 </cell>
29545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29546 \begin_inset Text
29547
29548 \begin_layout Standard
29549 Assembler
29550 \end_layout
29551
29552 \end_inset
29553 </cell>
29554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29555 \begin_inset Text
29556
29557 \begin_layout Standard
29558
29559 \family roman
29560 \series medium
29561 \shape up
29562 \size normal
29563 \emph off
29564 \bar no
29565 \noun off
29566 \color none
29567 sdcc/bin
29568 \end_layout
29569
29570 \end_inset
29571 </cell>
29572 </row>
29573 <row topline="true">
29574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29575 \begin_inset Text
29576
29577 \begin_layout Standard
29578 asx8051
29579 \end_layout
29580
29581 \end_inset
29582 </cell>
29583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29584 \begin_inset Text
29585
29586 \begin_layout Standard
29587 Assembler
29588 \end_layout
29589
29590 \end_inset
29591 </cell>
29592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29593 \begin_inset Text
29594
29595 \begin_layout Standard
29596
29597 \family roman
29598 \series medium
29599 \shape up
29600 \size normal
29601 \emph off
29602 \bar no
29603 \noun off
29604 \color none
29605 sdcc/bin
29606 \end_layout
29607
29608 \end_inset
29609 </cell>
29610 </row>
29611 <row topline="true">
29612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29613 \begin_inset Text
29614
29615 \begin_layout Standard
29616 SDCDB
29617 \end_layout
29618
29619 \end_inset
29620 </cell>
29621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29622 \begin_inset Text
29623
29624 \begin_layout Standard
29625 Simulator
29626 \end_layout
29627
29628 \end_inset
29629 </cell>
29630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29631 \begin_inset Text
29632
29633 \begin_layout Standard
29634
29635 \family roman
29636 \series medium
29637 \shape up
29638 \size normal
29639 \emph off
29640 \bar no
29641 \noun off
29642 \color none
29643 sdcc/bin
29644 \end_layout
29645
29646 \end_inset
29647 </cell>
29648 </row>
29649 <row topline="true">
29650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29651 \begin_inset Text
29652
29653 \begin_layout Standard
29654 aslink
29655 \end_layout
29656
29657 \end_inset
29658 </cell>
29659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29660 \begin_inset Text
29661
29662 \begin_layout Standard
29663 Linker
29664 \end_layout
29665
29666 \end_inset
29667 </cell>
29668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29669 \begin_inset Text
29670
29671 \begin_layout Standard
29672
29673 \family roman
29674 \series medium
29675 \shape up
29676 \size normal
29677 \emph off
29678 \bar no
29679 \noun off
29680 \color none
29681 sdcc/bin
29682 \end_layout
29683
29684 \end_inset
29685 </cell>
29686 </row>
29687 <row topline="true">
29688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29689 \begin_inset Text
29690
29691 \begin_layout Standard
29692 link-z80
29693 \end_layout
29694
29695 \end_inset
29696 </cell>
29697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29698 \begin_inset Text
29699
29700 \begin_layout Standard
29701 Linker
29702 \end_layout
29703
29704 \end_inset
29705 </cell>
29706 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29707 \begin_inset Text
29708
29709 \begin_layout Standard
29710
29711 \family roman
29712 \series medium
29713 \shape up
29714 \size normal
29715 \emph off
29716 \bar no
29717 \noun off
29718 \color none
29719 sdcc/bin
29720 \end_layout
29721
29722 \end_inset
29723 </cell>
29724 </row>
29725 <row topline="true">
29726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29727 \begin_inset Text
29728
29729 \begin_layout Standard
29730 link-gbz80
29731 \end_layout
29732
29733 \end_inset
29734 </cell>
29735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29736 \begin_inset Text
29737
29738 \begin_layout Standard
29739 Linker
29740 \end_layout
29741
29742 \end_inset
29743 </cell>
29744 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29745 \begin_inset Text
29746
29747 \begin_layout Standard
29748
29749 \family roman
29750 \series medium
29751 \shape up
29752 \size normal
29753 \emph off
29754 \bar no
29755 \noun off
29756 \color none
29757 sdcc/bin
29758 \end_layout
29759
29760 \end_inset
29761 </cell>
29762 </row>
29763 <row topline="true" bottomline="true">
29764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29765 \begin_inset Text
29766
29767 \begin_layout Standard
29768 packihx
29769 \end_layout
29770
29771 \end_inset
29772 </cell>
29773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29774 \begin_inset Text
29775
29776 \begin_layout Standard
29777 Intel Hex packer 
29778 \begin_inset LatexCommand \index{packihx (tool)}
29779
29780 \end_inset
29781
29782
29783 \end_layout
29784
29785 \end_inset
29786 </cell>
29787 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29788 \begin_inset Text
29789
29790 \begin_layout Standard
29791
29792 \family roman
29793 \series medium
29794 \shape up
29795 \size normal
29796 \emph off
29797 \bar no
29798 \noun off
29799 \color none
29800 sdcc/bin
29801 \end_layout
29802
29803 \end_inset
29804 </cell>
29805 </row>
29806 </lyxtabular>
29807
29808 \end_inset
29809
29810
29811 \newline
29812
29813 \end_layout
29814
29815 \begin_layout Section
29816 Documentation
29817 \begin_inset LatexCommand \index{Documentation}
29818
29819 \end_inset
29820
29821  included in the distribution
29822 \end_layout
29823
29824 \begin_layout Standard
29825 \align left
29826 \begin_inset Tabular
29827 <lyxtabular version="3" rows="10" columns="2">
29828 <features>
29829 <column alignment="block" valignment="top" leftline="true" width="40col%">
29830 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
29831 <row topline="true" bottomline="true" endhead="true">
29832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29833 \begin_inset Text
29834
29835 \begin_layout Standard
29836
29837 \series bold
29838 Subject / Title
29839 \end_layout
29840
29841 \end_inset
29842 </cell>
29843 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29844 \begin_inset Text
29845
29846 \begin_layout Standard
29847
29848 \series bold
29849 Filename / Where to get
29850 \end_layout
29851
29852 \end_inset
29853 </cell>
29854 </row>
29855 <row topline="true">
29856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29857 \begin_inset Text
29858
29859 \begin_layout Standard
29860 SDCC Compiler User Guide
29861 \end_layout
29862
29863 \end_inset
29864 </cell>
29865 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29866 \begin_inset Text
29867
29868 \begin_layout Standard
29869 You're reading it right now
29870 \emph on
29871  \InsetSpace ~
29872 \InsetSpace ~
29873 \InsetSpace ~
29874
29875 \hfill
29876 online at:
29877 \emph default
29878
29879 \newline
29880
29881 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
29882
29883 \end_inset
29884
29885
29886 \end_layout
29887
29888 \end_inset
29889 </cell>
29890 </row>
29891 <row topline="true">
29892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29893 \begin_inset Text
29894
29895 \begin_layout Standard
29896 Changelog of SDCC
29897 \end_layout
29898
29899 \end_inset
29900 </cell>
29901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29902 \begin_inset Text
29903
29904 \begin_layout Standard
29905 sdcc/Changelog
29906 \emph on
29907  \InsetSpace ~
29908 \InsetSpace ~
29909 \InsetSpace ~
29910
29911 \hfill
29912 online at:
29913 \emph default
29914
29915 \newline
29916
29917 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog}
29918
29919 \end_inset
29920
29921
29922 \end_layout
29923
29924 \end_inset
29925 </cell>
29926 </row>
29927 <row topline="true">
29928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29929 \begin_inset Text
29930
29931 \begin_layout Standard
29932 ASXXXX
29933 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
29934
29935 \end_inset
29936
29937
29938 \begin_inset LatexCommand \index{Assembler documentation}
29939
29940 \end_inset
29941
29942  Assemblers and
29943 \newline
29944 ASLINK
29945 \begin_inset LatexCommand \index{aslink}
29946
29947 \end_inset
29948
29949
29950 \begin_inset LatexCommand \index{Linker documentation}
29951
29952 \end_inset
29953
29954  Relocating Linker
29955 \end_layout
29956
29957 \end_inset
29958 </cell>
29959 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29960 \begin_inset Text
29961
29962 \begin_layout Standard
29963 sdcc/as/doc/asxhtm.html 
29964 \emph on
29965 \InsetSpace ~
29966 \InsetSpace ~
29967 \InsetSpace ~
29968
29969 \hfill
29970 online at:
29971 \emph default
29972
29973 \newline
29974
29975 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html}
29976
29977 \end_inset
29978
29979
29980 \end_layout
29981
29982 \end_inset
29983 </cell>
29984 </row>
29985 <row topline="true">
29986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29987 \begin_inset Text
29988
29989 \begin_layout Standard
29990 SDCC regression test
29991 \begin_inset LatexCommand \index{Regression test}
29992
29993 \end_inset
29994
29995
29996 \end_layout
29997
29998 \end_inset
29999 </cell>
30000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30001 \begin_inset Text
30002
30003 \begin_layout Standard
30004 sdcc/doc/test_suite_spec.pdf 
30005 \emph on
30006 \InsetSpace ~
30007 \InsetSpace ~
30008 \InsetSpace ~
30009
30010 \hfill
30011 online at:
30012 \emph default
30013
30014 \newline
30015
30016 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
30017
30018 \end_inset
30019
30020
30021 \end_layout
30022
30023 \end_inset
30024 </cell>
30025 </row>
30026 <row topline="true">
30027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30028 \begin_inset Text
30029
30030 \begin_layout Standard
30031 Various notes
30032 \end_layout
30033
30034 \end_inset
30035 </cell>
30036 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30037 \begin_inset Text
30038
30039 \begin_layout Standard
30040 sdcc/doc/* 
30041 \emph on
30042 \InsetSpace ~
30043 \InsetSpace ~
30044 \InsetSpace ~
30045
30046 \hfill
30047 online at:
30048 \emph default
30049
30050 \newline
30051
30052 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/}
30053
30054 \end_inset
30055
30056
30057 \end_layout
30058
30059 \end_inset
30060 </cell>
30061 </row>
30062 <row topline="true">
30063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30064 \begin_inset Text
30065
30066 \begin_layout Standard
30067 Notes on debugging with SDCDB
30068 \begin_inset LatexCommand \index{SDCDB (debugger)}
30069
30070 \end_inset
30071
30072
30073 \end_layout
30074
30075 \end_inset
30076 </cell>
30077 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30078 \begin_inset Text
30079
30080 \begin_layout Standard
30081 sdcc/debugger/README 
30082 \emph on
30083 \InsetSpace ~
30084 \InsetSpace ~
30085 \InsetSpace ~
30086
30087 \hfill
30088 online at
30089 \emph default
30090 :
30091 \newline
30092
30093 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README}
30094
30095 \end_inset
30096
30097
30098 \end_layout
30099
30100 \end_inset
30101 </cell>
30102 </row>
30103 <row topline="true">
30104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30105 \begin_inset Text
30106
30107 \begin_layout Standard
30108 uCsim
30109 \begin_inset LatexCommand \index{uCsim}
30110
30111 \end_inset
30112
30113  Software simulator for microcontrollers
30114 \end_layout
30115
30116 \end_inset
30117 </cell>
30118 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30119 \begin_inset Text
30120
30121 \begin_layout Standard
30122
30123 \family roman
30124 \series medium
30125 \shape up
30126 \size normal
30127 \emph off
30128 \bar no
30129 \noun off
30130 \color none
30131 sdcc/sim/ucsim/doc
30132 \family default
30133 \series default
30134 \shape default
30135 \size default
30136 \emph default
30137 \bar default
30138 \noun default
30139 /index.html 
30140 \emph on
30141 \InsetSpace ~
30142 \InsetSpace ~
30143 \InsetSpace ~
30144
30145 \hfill
30146 online at:
30147 \emph default
30148
30149 \newline
30150
30151 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html}
30152
30153 \end_inset
30154
30155
30156 \end_layout
30157
30158 \end_inset
30159 </cell>
30160 </row>
30161 <row topline="true">
30162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30163 \begin_inset Text
30164
30165 \begin_layout Standard
30166 Temporary notes on the pic16
30167 \begin_inset LatexCommand \index{PIC16}
30168
30169 \end_inset
30170
30171  port
30172 \end_layout
30173
30174 \end_inset
30175 </cell>
30176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30177 \begin_inset Text
30178
30179 \begin_layout Standard
30180 sdcc/src/pic16/NOTES 
30181 \emph on
30182 \InsetSpace ~
30183 \InsetSpace ~
30184 \InsetSpace ~
30185
30186 \hfill
30187 online at:
30188 \newline
30189
30190 \emph default
30191
30192 \begin_inset LatexCommand \url{http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES}
30193
30194 \end_inset
30195
30196
30197 \end_layout
30198
30199 \end_inset
30200 </cell>
30201 </row>
30202 <row topline="true" bottomline="true">
30203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30204 \begin_inset Text
30205
30206 \begin_layout Standard
30207 SDCC internal documentation (debugging file format)
30208 \end_layout
30209
30210 \end_inset
30211 </cell>
30212 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30213 \begin_inset Text
30214
30215 \begin_layout Standard
30216 sdcc/doc/
30217 \family roman
30218 \series medium
30219 \shape up
30220 \size normal
30221 \emph off
30222 \bar no
30223 \noun off
30224 \color none
30225 cdbfileformat.pd
30226 \family default
30227 \series default
30228 \shape default
30229 \size default
30230 \emph default
30231 \bar default
30232 \noun default
30233 f
30234 \emph on
30235  \InsetSpace ~
30236 \InsetSpace ~
30237 \InsetSpace ~
30238
30239 \hfill
30240 online at:
30241 \emph default
30242
30243 \newline
30244
30245 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/cdbfileformat.pdf}
30246
30247 \end_inset
30248
30249
30250 \end_layout
30251
30252 \end_inset
30253 </cell>
30254 </row>
30255 </lyxtabular>
30256
30257 \end_inset
30258
30259
30260 \newline
30261
30262 \end_layout
30263
30264 \begin_layout Section
30265 Related open source tools
30266 \begin_inset LatexCommand \label{sec:Related-open-source-tools}
30267
30268 \end_inset
30269
30270
30271 \begin_inset LatexCommand \index{Related tools}
30272
30273 \end_inset
30274
30275
30276 \end_layout
30277
30278 \begin_layout Standard
30279 \align left
30280 \begin_inset Tabular
30281 <lyxtabular version="3" rows="14" columns="3">
30282 <features>
30283 <column alignment="left" valignment="top" leftline="true" width="0pt">
30284 <column alignment="block" valignment="top" leftline="true" width="30line%">
30285 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30286 <row topline="true" bottomline="true">
30287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30288 \begin_inset Text
30289
30290 \begin_layout Standard
30291
30292 \series bold
30293 Name
30294 \end_layout
30295
30296 \end_inset
30297 </cell>
30298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30299 \begin_inset Text
30300
30301 \begin_layout Standard
30302
30303 \series bold
30304 Purpose
30305 \end_layout
30306
30307 \end_inset
30308 </cell>
30309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30310 \begin_inset Text
30311
30312 \begin_layout Standard
30313
30314 \series bold
30315 Where to get
30316 \end_layout
30317
30318 \end_inset
30319 </cell>
30320 </row>
30321 <row topline="true">
30322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30323 \begin_inset Text
30324
30325 \begin_layout Standard
30326 gpsim
30327 \begin_inset LatexCommand \index{gpsim (pic simulator)}
30328
30329 \end_inset
30330
30331
30332 \end_layout
30333
30334 \end_inset
30335 </cell>
30336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30337 \begin_inset Text
30338
30339 \begin_layout Standard
30340 PIC simulator
30341 \end_layout
30342
30343 \end_inset
30344 </cell>
30345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30346 \begin_inset Text
30347
30348 \begin_layout Standard
30349 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
30350
30351 \end_inset
30352
30353
30354 \end_layout
30355
30356 \end_inset
30357 </cell>
30358 </row>
30359 <row topline="true">
30360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30361 \begin_inset Text
30362
30363 \begin_layout Standard
30364 gputils
30365 \begin_inset LatexCommand \index{gputils (pic tools)}
30366
30367 \end_inset
30368
30369
30370 \end_layout
30371
30372 \end_inset
30373 </cell>
30374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30375 \begin_inset Text
30376
30377 \begin_layout Standard
30378 GNU PIC utilities
30379 \end_layout
30380
30381 \end_inset
30382 </cell>
30383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30384 \begin_inset Text
30385
30386 \begin_layout Standard
30387 \begin_inset LatexCommand \url{http://sourceforge.net/projects/gputils}
30388
30389 \end_inset
30390
30391
30392 \end_layout
30393
30394 \end_inset
30395 </cell>
30396 </row>
30397 <row topline="true">
30398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30399 \begin_inset Text
30400
30401 \begin_layout Standard
30402 flP5
30403 \end_layout
30404
30405 \end_inset
30406 </cell>
30407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30408 \begin_inset Text
30409
30410 \begin_layout Standard
30411 PIC programmer
30412 \end_layout
30413
30414 \end_inset
30415 </cell>
30416 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30417 \begin_inset Text
30418
30419 \begin_layout Standard
30420 \begin_inset LatexCommand \url{http://freshmeat.net/projects/flp5/}
30421
30422 \end_inset
30423
30424
30425 \end_layout
30426
30427 \end_inset
30428 </cell>
30429 </row>
30430 <row topline="true">
30431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30432 \begin_inset Text
30433
30434 \begin_layout Standard
30435 ec2drv/newcdb
30436 \end_layout
30437
30438 \end_inset
30439 </cell>
30440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30441 \begin_inset Text
30442
30443 \begin_layout Standard
30444 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
30445  (Unix only)
30446 \end_layout
30447
30448 \end_inset
30449 </cell>
30450 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30451 \begin_inset Text
30452
30453 \begin_layout Standard
30454 \begin_inset LatexCommand \url{http://sourceforge.net/projects/ec2drv}
30455
30456 \end_inset
30457
30458
30459 \end_layout
30460
30461 \end_inset
30462 </cell>
30463 </row>
30464 <row topline="true">
30465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30466 \begin_inset Text
30467
30468 \begin_layout Standard
30469 indent
30470 \begin_inset LatexCommand \index{indent (source formatting tool)}
30471
30472 \end_inset
30473
30474
30475 \end_layout
30476
30477 \end_inset
30478 </cell>
30479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30480 \begin_inset Text
30481
30482 \begin_layout Standard
30483 Formats C source - Master of the white spaces
30484 \end_layout
30485
30486 \end_inset
30487 </cell>
30488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30489 \begin_inset Text
30490
30491 \begin_layout Standard
30492 \begin_inset LatexCommand \url{http://directory.fsf.org/GNU/indent.html}
30493
30494 \end_inset
30495
30496
30497 \end_layout
30498
30499 \end_inset
30500 </cell>
30501 </row>
30502 <row topline="true">
30503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30504 \begin_inset Text
30505
30506 \begin_layout Standard
30507 srecord
30508 \begin_inset LatexCommand \index{srecord (bin, hex, ... tool)}
30509
30510 \end_inset
30511
30512
30513 \end_layout
30514
30515 \end_inset
30516 </cell>
30517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30518 \begin_inset Text
30519
30520 \begin_layout Standard
30521 Object file conversion, checksumming, ...
30522 \end_layout
30523
30524 \end_inset
30525 </cell>
30526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30527 \begin_inset Text
30528
30529 \begin_layout Standard
30530 \begin_inset LatexCommand \url{http://sourceforge.net/projects/srecord}
30531
30532 \end_inset
30533
30534
30535 \end_layout
30536
30537 \end_inset
30538 </cell>
30539 </row>
30540 <row topline="true">
30541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30542 \begin_inset Text
30543
30544 \begin_layout Standard
30545 objdump
30546 \begin_inset LatexCommand \index{objdump (tool)}
30547
30548 \end_inset
30549
30550
30551 \end_layout
30552
30553 \end_inset
30554 </cell>
30555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30556 \begin_inset Text
30557
30558 \begin_layout Standard
30559 Object file conversion, ...
30560 \end_layout
30561
30562 \end_inset
30563 </cell>
30564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30565 \begin_inset Text
30566
30567 \begin_layout Standard
30568 Part of binutils (should be there anyway)
30569 \end_layout
30570
30571 \end_inset
30572 </cell>
30573 </row>
30574 <row topline="true">
30575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30576 \begin_inset Text
30577
30578 \begin_layout Standard
30579 cmon51
30580 \end_layout
30581
30582 \end_inset
30583 </cell>
30584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30585 \begin_inset Text
30586
30587 \begin_layout Standard
30588 8051 monitor (hex up-/download, single step, disassemble)
30589 \end_layout
30590
30591 \end_inset
30592 </cell>
30593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30594 \begin_inset Text
30595
30596 \begin_layout Standard
30597 \begin_inset LatexCommand \url{http://sourceforge.net/projects/cmon51}
30598
30599 \end_inset
30600
30601
30602 \end_layout
30603
30604 \end_inset
30605 </cell>
30606 </row>
30607 <row topline="true">
30608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30609 \begin_inset Text
30610
30611 \begin_layout Standard
30612 doxygen
30613 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
30614
30615 \end_inset
30616
30617
30618 \end_layout
30619
30620 \end_inset
30621 </cell>
30622 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30623 \begin_inset Text
30624
30625 \begin_layout Standard
30626 Source code documentation system
30627 \end_layout
30628
30629 \end_inset
30630 </cell>
30631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30632 \begin_inset Text
30633
30634 \begin_layout Standard
30635 \begin_inset LatexCommand \url{http://www.doxygen.org}
30636
30637 \end_inset
30638
30639
30640 \end_layout
30641
30642 \end_inset
30643 </cell>
30644 </row>
30645 <row topline="true">
30646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30647 \begin_inset Text
30648
30649 \begin_layout Standard
30650 kdevelop
30651 \end_layout
30652
30653 \end_inset
30654 </cell>
30655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30656 \begin_inset Text
30657
30658 \begin_layout Standard
30659 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
30660 \end_layout
30661
30662 \end_inset
30663 </cell>
30664 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30665 \begin_inset Text
30666
30667 \begin_layout Standard
30668 \begin_inset LatexCommand \url{http://www.kdevelop.org}
30669
30670 \end_inset
30671
30672
30673 \end_layout
30674
30675 \end_inset
30676 </cell>
30677 </row>
30678 <row topline="true">
30679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30680 \begin_inset Text
30681
30682 \begin_layout Standard
30683 paulmon
30684 \end_layout
30685
30686 \end_inset
30687 </cell>
30688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30689 \begin_inset Text
30690
30691 \begin_layout Standard
30692 8051 monitor (hex up-/download, single step, disassemble)
30693 \end_layout
30694
30695 \end_inset
30696 </cell>
30697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30698 \begin_inset Text
30699
30700 \begin_layout Standard
30701 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/paulmon2.html}
30702
30703 \end_inset
30704
30705
30706 \end_layout
30707
30708 \end_inset
30709 </cell>
30710 </row>
30711 <row topline="true">
30712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30713 \begin_inset Text
30714
30715 \begin_layout Standard
30716 splint
30717 \begin_inset LatexCommand \index{splint (syntax checking tool)}
30718
30719 \end_inset
30720
30721
30722 \end_layout
30723
30724 \end_inset
30725 </cell>
30726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30727 \begin_inset Text
30728
30729 \begin_layout Standard
30730 Statically checks c sources (see 
30731 \begin_inset LatexCommand \ref{lyx:more-pedantic-SPLINT}
30732
30733 \end_inset
30734
30735 )
30736 \end_layout
30737
30738 \end_inset
30739 </cell>
30740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30741 \begin_inset Text
30742
30743 \begin_layout Standard
30744 \begin_inset LatexCommand \url{http://www.splint.org}
30745
30746 \end_inset
30747
30748
30749 \end_layout
30750
30751 \end_inset
30752 </cell>
30753 </row>
30754 <row topline="true" bottomline="true">
30755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30756 \begin_inset Text
30757
30758 \begin_layout Standard
30759 ddd
30760 \begin_inset LatexCommand \index{DDD (debugger)}
30761
30762 \end_inset
30763
30764
30765 \end_layout
30766
30767 \end_inset
30768 </cell>
30769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30770 \begin_inset Text
30771
30772 \begin_layout Standard
30773 Debugger, serves nicely as GUI to SDCDB
30774 \begin_inset LatexCommand \index{SDCDB (debugger)}
30775
30776 \end_inset
30777
30778  (Unix only)
30779 \end_layout
30780
30781 \end_inset
30782 </cell>
30783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30784 \begin_inset Text
30785
30786 \begin_layout Standard
30787 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
30788
30789 \end_inset
30790
30791
30792 \end_layout
30793
30794 \end_inset
30795 </cell>
30796 </row>
30797 </lyxtabular>
30798
30799 \end_inset
30800
30801
30802 \newline
30803
30804 \end_layout
30805
30806 \begin_layout Section
30807 Related documentation / recommended reading
30808 \end_layout
30809
30810 \begin_layout Standard
30811 \align left
30812 \begin_inset Tabular
30813 <lyxtabular version="3" rows="7" columns="3">
30814 <features>
30815 <column alignment="left" valignment="top" leftline="true" width="0pt">
30816 <column alignment="left" valignment="top" leftline="true" width="0">
30817 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
30818 <row topline="true" bottomline="true">
30819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30820 \begin_inset Text
30821
30822 \begin_layout Standard
30823
30824 \series bold
30825 Name
30826 \end_layout
30827
30828 \end_inset
30829 </cell>
30830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30831 \begin_inset Text
30832
30833 \begin_layout Standard
30834
30835 \series bold
30836 Subject / Title
30837 \end_layout
30838
30839 \end_inset
30840 </cell>
30841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30842 \begin_inset Text
30843
30844 \begin_layout Standard
30845
30846 \series bold
30847 Where to get
30848 \end_layout
30849
30850 \end_inset
30851 </cell>
30852 </row>
30853 <row topline="true">
30854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30855 \begin_inset Text
30856
30857 \begin_layout Standard
30858
30859 \family roman
30860 \series medium
30861 \shape up
30862 \size normal
30863 \emph off
30864 \bar no
30865 \noun off
30866 \color none
30867 c-refcard.pdf
30868 \end_layout
30869
30870 \end_inset
30871 </cell>
30872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30873 \begin_inset Text
30874
30875 \begin_layout Standard
30876 C Reference Card
30877 \begin_inset LatexCommand \index{C Reference card}
30878
30879 \end_inset
30880
30881 , 2 pages
30882 \end_layout
30883
30884 \end_inset
30885 </cell>
30886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30887 \begin_inset Text
30888
30889 \begin_layout Standard
30890 \begin_inset LatexCommand \url{http://refcards.com/refcards/c/index.html}
30891
30892 \end_inset
30893
30894
30895 \end_layout
30896
30897 \end_inset
30898 </cell>
30899 </row>
30900 <row topline="true">
30901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30902 \begin_inset Text
30903
30904 \begin_layout Standard
30905 c-faq
30906 \end_layout
30907
30908 \end_inset
30909 </cell>
30910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30911 \begin_inset Text
30912
30913 \begin_layout Standard
30914 C-FAQ
30915 \begin_inset LatexCommand \index{C FAQ}
30916
30917 \end_inset
30918
30919
30920 \end_layout
30921
30922 \end_inset
30923 </cell>
30924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30925 \begin_inset Text
30926
30927 \begin_layout Standard
30928 \begin_inset LatexCommand \url{http://www.c-faq.com}
30929
30930 \end_inset
30931
30932
30933 \end_layout
30934
30935 \end_inset
30936 </cell>
30937 </row>
30938 <row topline="true">
30939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30940 \begin_inset Text
30941
30942 \begin_layout Standard
30943 ISO/IEC 9899:TC2
30944 \end_layout
30945
30946 \end_inset
30947 </cell>
30948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30949 \begin_inset Text
30950
30951 \begin_layout Standard
30952 \begin_inset Quotes sld
30953 \end_inset
30954
30955 C-Standard
30956 \begin_inset Quotes srd
30957 \end_inset
30958
30959
30960 \end_layout
30961
30962 \end_inset
30963 </cell>
30964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
30965 \begin_inset Text
30966
30967 \begin_layout Standard
30968
30969 \size footnotesize
30970 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
30971
30972 \end_inset
30973
30974
30975 \end_layout
30976
30977 \end_inset
30978 </cell>
30979 </row>
30980 <row topline="true">
30981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30982 \begin_inset Text
30983
30984 \begin_layout Standard
30985 ISO/IEC DTR 18037
30986 \end_layout
30987
30988 \end_inset
30989 </cell>
30990 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
30991 \begin_inset Text
30992
30993 \begin_layout Standard
30994 \begin_inset Quotes sld
30995 \end_inset
30996
30997 Extensions for Embedded C
30998 \begin_inset Quotes srd
30999 \end_inset
31000
31001
31002 \end_layout
31003
31004 \end_inset
31005 </cell>
31006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31007 \begin_inset Text
31008
31009 \begin_layout Standard
31010
31011 \size footnotesize
31012 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf}
31013
31014 \end_inset
31015
31016
31017 \end_layout
31018
31019 \end_inset
31020 </cell>
31021 </row>
31022 <row topline="true">
31023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31024 \begin_inset Text
31025
31026 \begin_layout Standard
31027
31028 \end_layout
31029
31030 \end_inset
31031 </cell>
31032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31033 \begin_inset Text
31034
31035 \begin_layout Standard
31036 Latest datasheet of target CPU
31037 \end_layout
31038
31039 \end_inset
31040 </cell>
31041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31042 \begin_inset Text
31043
31044 \begin_layout Standard
31045 vendor
31046 \end_layout
31047
31048 \end_inset
31049 </cell>
31050 </row>
31051 <row topline="true" bottomline="true">
31052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31053 \begin_inset Text
31054
31055 \begin_layout Standard
31056
31057 \end_layout
31058
31059 \end_inset
31060 </cell>
31061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31062 \begin_inset Text
31063
31064 \begin_layout Standard
31065 Revision history of datasheet
31066 \end_layout
31067
31068 \end_inset
31069 </cell>
31070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31071 \begin_inset Text
31072
31073 \begin_layout Standard
31074 vendor
31075 \end_layout
31076
31077 \end_inset
31078 </cell>
31079 </row>
31080 </lyxtabular>
31081
31082 \end_inset
31083
31084
31085 \newline
31086
31087 \end_layout
31088
31089 \begin_layout Section
31090 Application notes specifically for SDCC
31091 \end_layout
31092
31093 \begin_layout Standard
31094 SDCC makes no claims about the completeness of this list and about up-to-datenes
31095 s or correctness of the application notes
31096 \begin_inset LatexCommand \index{Application notes}
31097
31098 \end_inset
31099
31100 .
31101 \end_layout
31102
31103 \begin_layout Standard
31104 \align left
31105
31106 \size footnotesize
31107 \begin_inset Tabular
31108 <lyxtabular version="3" rows="7" columns="3">
31109 <features>
31110 <column alignment="block" valignment="top" leftline="true" width="17col%">
31111 <column alignment="block" valignment="top" leftline="true" width="27col%">
31112 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
31113 <row topline="true" bottomline="true">
31114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31115 \begin_inset Text
31116
31117 \begin_layout Standard
31118
31119 \series bold
31120 \size footnotesize
31121 Vendor
31122 \end_layout
31123
31124 \end_inset
31125 </cell>
31126 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
31127 \begin_inset Text
31128
31129 \begin_layout Standard
31130
31131 \series bold
31132 \size footnotesize
31133 Subject / Title
31134 \end_layout
31135
31136 \end_inset
31137 </cell>
31138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31139 \begin_inset Text
31140
31141 \begin_layout Standard
31142
31143 \series bold
31144 \size footnotesize
31145 Where to get
31146 \end_layout
31147
31148 \end_inset
31149 </cell>
31150 </row>
31151 <row topline="true">
31152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31153 \begin_inset Text
31154
31155 \begin_layout Standard
31156
31157 \size footnotesize
31158 Maxim / Dallas
31159 \end_layout
31160
31161 \end_inset
31162 </cell>
31163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31164 \begin_inset Text
31165
31166 \begin_layout Standard
31167
31168 \size footnotesize
31169 Using the SDCC Compiler for the DS80C400
31170 \begin_inset LatexCommand \index{DS80C400}
31171
31172 \end_inset
31173
31174
31175 \end_layout
31176
31177 \end_inset
31178 </cell>
31179 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31180 \begin_inset Text
31181
31182 \begin_layout Standard
31183
31184 \size footnotesize
31185 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3346.pdf}
31186
31187 \end_inset
31188
31189
31190 \end_layout
31191
31192 \end_inset
31193 </cell>
31194 </row>
31195 <row topline="true">
31196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31197 \begin_inset Text
31198
31199 \begin_layout Standard
31200
31201 \size footnotesize
31202 Maxim / Dallas
31203 \end_layout
31204
31205 \end_inset
31206 </cell>
31207 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
31208 \begin_inset Text
31209
31210 \begin_layout Standard
31211
31212 \size footnotesize
31213 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
31214 \begin_inset LatexCommand \index{DS89C4x0}
31215
31216 \end_inset
31217
31218  Family of Microcontrollers
31219 \end_layout
31220
31221 \end_inset
31222 </cell>
31223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31224 \begin_inset Text
31225
31226 \begin_layout Standard
31227
31228 \size footnotesize
31229 \begin_inset LatexCommand \url{http://pdfserv.maxim-ic.com/en/an/AN3477.pdf}
31230
31231 \end_inset
31232
31233
31234 \end_layout
31235
31236 \end_inset
31237 </cell>
31238 </row>
31239 <row topline="true">
31240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31241 \begin_inset Text
31242
31243 \begin_layout Standard
31244
31245 \size footnotesize
31246 Silicon Laboratories / Cygnal
31247 \end_layout
31248
31249 \end_inset
31250 </cell>
31251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31252 \begin_inset Text
31253
31254 \begin_layout Standard
31255
31256 \size footnotesize
31257 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
31258 \begin_inset LatexCommand \index{IDE}
31259
31260 \end_inset
31261
31262
31263 \end_layout
31264
31265 \end_inset
31266 </cell>
31267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31268 \begin_inset Text
31269
31270 \begin_layout Standard
31271
31272 \size footnotesize
31273 \begin_inset LatexCommand \url{http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf}
31274
31275 \end_inset
31276
31277
31278 \end_layout
31279
31280 \end_inset
31281 </cell>
31282 </row>
31283 <row topline="true">
31284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31285 \begin_inset Text
31286
31287 \begin_layout Standard
31288
31289 \size footnotesize
31290 Ramtron / Goal Semiconductor
31291 \end_layout
31292
31293 \end_inset
31294 </cell>
31295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31296 \begin_inset Text
31297
31298 \begin_layout Standard
31299
31300 \size footnotesize
31301 Interfacing SDCC to Syn and Textpad
31302 \end_layout
31303
31304 \end_inset
31305 </cell>
31306 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31307 \begin_inset Text
31308
31309 \begin_layout Standard
31310
31311 \size footnotesize
31312 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31313
31314 \end_inset
31315
31316
31317 \end_layout
31318
31319 \end_inset
31320 </cell>
31321 </row>
31322 <row topline="true">
31323 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31324 \begin_inset Text
31325
31326 \begin_layout Standard
31327
31328 \size footnotesize
31329 Ramtron / Goal Semiconductor
31330 \end_layout
31331
31332 \end_inset
31333 </cell>
31334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31335 \begin_inset Text
31336
31337 \begin_layout Standard
31338
31339 \size footnotesize
31340 Installing and Configuring SDCC and Crimson Editor 
31341 \end_layout
31342
31343 \end_inset
31344 </cell>
31345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31346 \begin_inset Text
31347
31348 \begin_layout Standard
31349
31350 \size footnotesize
31351 \begin_inset LatexCommand \url{http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp}
31352
31353 \end_inset
31354
31355
31356 \end_layout
31357
31358 \end_inset
31359 </cell>
31360 </row>
31361 <row topline="true" bottomline="true">
31362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31363 \begin_inset Text
31364
31365 \begin_layout Standard
31366
31367 \size footnotesize
31368 Texas Instruments
31369 \end_layout
31370
31371 \end_inset
31372 </cell>
31373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
31374 \begin_inset Text
31375
31376 \begin_layout Standard
31377
31378 \size footnotesize
31379 MSC12xx Programming with SDCC
31380 \end_layout
31381
31382 \end_inset
31383 </cell>
31384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
31385 \begin_inset Text
31386
31387 \begin_layout Standard
31388
31389 \size footnotesize
31390 \begin_inset LatexCommand \url{http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf}
31391
31392 \end_inset
31393
31394
31395 \end_layout
31396
31397 \end_inset
31398 </cell>
31399 </row>
31400 </lyxtabular>
31401
31402 \end_inset
31403
31404
31405 \end_layout
31406
31407 \begin_layout Section
31408 Some Questions
31409 \end_layout
31410
31411 \begin_layout Standard
31412 Some questions answered, some pointers given - it might be time to in turn
31413  ask 
31414 \emph on
31415 you
31416 \emph default
31417  some questions: 
31418 \end_layout
31419
31420 \begin_layout Itemize
31421 can you solve your project with the selected microcontroller? Would you
31422  find out early or rather late that your target is too small/slow/whatever?
31423  Can you switch to a slightly better device if it doesn't fit?
31424 \end_layout
31425
31426 \begin_layout Itemize
31427 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
31428  and/or another programming language be more adequate? Would an operating
31429  system on the target device help?
31430 \end_layout
31431
31432 \begin_layout Itemize
31433 if you solved the problem, will the marketing department be happy?
31434 \end_layout
31435
31436 \begin_layout Itemize
31437 if the marketing department is happy, will customers be happy?
31438 \end_layout
31439
31440 \begin_layout Itemize
31441 if you're the project manager, marketing department and maybe even the customer
31442  in one person, have you tried to see the project from the outside?
31443 \end_layout
31444
31445 \begin_layout Itemize
31446 is the project done if you think it is done? Or is just that other interface/pro
31447 tocol/feature/configuration/option missing? How about website, manual(s),
31448  internationali(z|s)ation, packaging, labels, 2nd source for components,
31449  electromagnetic compatability/interference, documentation for production,
31450  production test software, update mechanism, patent issues?
31451 \end_layout
31452
31453 \begin_layout Itemize
31454 is your project adequately positioned in that magic triangle: fame, fortune,
31455  fun?
31456 \end_layout
31457
31458 \begin_layout Standard
31459 Maybe not all answers to these questions are known and some answers may
31460  even be 
31461 \emph on
31462 no
31463 \emph default
31464 , nevertheless knowing these questions may help you to avoid burnout
31465 \begin_inset Foot
31466 status open
31467
31468 \begin_layout Standard
31469 burnout is bad for electronic devices, programmers and motorcycle tyres
31470 \end_layout
31471
31472 \end_inset
31473
31474 .
31475  Chances are you didn't want to hear some of them...
31476 \end_layout
31477
31478 \begin_layout Chapter
31479 Support
31480 \begin_inset LatexCommand \index{Support}
31481
31482 \end_inset
31483
31484
31485 \end_layout
31486
31487 \begin_layout Standard
31488 SDCC has grown to be a large project.
31489  The compiler alone (without the preprocessor, assembler and linker) is
31490  well over 150,000 lines of code (blank stripped).
31491  The open source nature of this project is a key to its continued growth
31492  and support.
31493  You gain the benefit and support of many active software developers and
31494  end users.
31495  Is SDCC perfect? No, that's why we need your help.
31496  The developers take pride in fixing reported bugs.
31497  You can help by reporting the bugs and helping other SDCC users.
31498  There are lots of ways to contribute, and we encourage you to take part
31499  in making SDCC a great software package.
31500  
31501 \end_layout
31502
31503 \begin_layout Standard
31504 The SDCC project is hosted on the SDCC sourceforge site at 
31505 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
31506
31507 \end_inset
31508
31509 .
31510  You'll find the complete set of mailing lists
31511 \begin_inset LatexCommand \index{Mailing list(s)}
31512
31513 \end_inset
31514
31515 , forums, bug reporting system, patch submission
31516 \begin_inset LatexCommand \index{Patch submission}
31517
31518 \end_inset
31519
31520  system, download
31521 \begin_inset LatexCommand \index{download}
31522
31523 \end_inset
31524
31525  area and Subversion code repository
31526 \begin_inset LatexCommand \index{Subversion code repository}
31527
31528 \end_inset
31529
31530  there.
31531 \end_layout
31532
31533 \begin_layout Section
31534 Reporting Bugs
31535 \begin_inset LatexCommand \index{Bug reporting}
31536
31537 \end_inset
31538
31539
31540 \begin_inset LatexCommand \index{Reporting bugs}
31541
31542 \end_inset
31543
31544
31545 \end_layout
31546
31547 \begin_layout Standard
31548 The recommended way of reporting bugs is using the infrastructure of the
31549  sourceforge site.
31550  You can follow the status of bug reports there and have an overview about
31551  the known bugs.
31552 \end_layout
31553
31554 \begin_layout Standard
31555 Bug reports are automatically forwarded to the developer mailing list and
31556  will be fixed ASAP.
31557  When reporting a bug, it is very useful to include a small test program
31558  (the smaller the better) which reproduces the problem.
31559  If you can isolate the problem by looking at the generated assembly code,
31560  this can be very helpful.
31561  Compiling your program with the -
31562 \begin_inset ERT
31563 status collapsed
31564
31565 \begin_layout Standard
31566
31567
31568 \backslash
31569 /
31570 \end_layout
31571
31572 \end_inset
31573
31574 -dumpall
31575 \begin_inset LatexCommand \index{-\/-dumpall}
31576
31577 \end_inset
31578
31579  option can sometimes be useful in locating optimization problems.
31580  When reporting a bug please make sure you:
31581 \end_layout
31582
31583 \begin_layout Enumerate
31584 Attach the code you are compiling with SDCC.
31585  
31586 \end_layout
31587
31588 \begin_layout Enumerate
31589 Specify the exact command you use to run SDCC, or attach your Makefile.
31590  
31591 \end_layout
31592
31593 \begin_layout Enumerate
31594 Specify the SDCC version (type "
31595 \family sans
31596 \series bold
31597 sdcc -v
31598 \family default
31599 \series default
31600 "), your platform, and operating system.
31601  
31602 \end_layout
31603
31604 \begin_layout Enumerate
31605 Provide an exact copy of any error message or incorrect output.
31606  
31607 \end_layout
31608
31609 \begin_layout Enumerate
31610 Put something meaningful in the subject of your message.
31611 \end_layout
31612
31613 \begin_layout Standard
31614 Please attempt to include these 5 important parts, as applicable, in all
31615  requests for support or when reporting any problems or bugs with SDCC.
31616  Though this will make your message lengthy, it will greatly improve your
31617  chance that SDCC users and developers will be able to help you.
31618  Some SDCC developers are frustrated by bug reports without code provided
31619  that they can use to reproduce and ultimately fix the problem, so please
31620  be sure to provide sample code if you are reporting a bug! 
31621 \end_layout
31622
31623 \begin_layout Standard
31624 Please have a short check that you are using a recent version of SDCC and
31625  the bug is not yet known.
31626  This is the link for reporting bugs: 
31627 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
31628
31629 \end_inset
31630
31631 .
31632  With SDCC on average having more than 200 downloads
31633 \begin_inset LatexCommand \index{download}
31634
31635 \end_inset
31636
31637  on sourceforge per day
31638 \begin_inset Foot
31639 status open
31640
31641 \begin_layout Standard
31642 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
31643  between 2002 and 2005.
31644  This does not include other methods of distribution.
31645 \end_layout
31646
31647 \end_inset
31648
31649  there must be some users.
31650  So it's not exactly easy to find a new bug.
31651  If you find one we need it: 
31652 \emph on
31653 reporting bugs is good
31654 \emph default
31655 .
31656 \end_layout
31657
31658 \begin_layout Section
31659 Requesting Features
31660 \begin_inset LatexCommand \label{sub:Requesting-Features}
31661
31662 \end_inset
31663
31664
31665 \begin_inset LatexCommand \index{Feature request}
31666
31667 \end_inset
31668
31669
31670 \begin_inset LatexCommand \index{Requesting features}
31671
31672 \end_inset
31673
31674
31675 \end_layout
31676
31677 \begin_layout Standard
31678 Like bug reports feature requests are forwarded to the developer mailing
31679  list.
31680  This is the link for requesting features: 
31681 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
31682
31683 \end_inset
31684
31685 .
31686 \end_layout
31687
31688 \begin_layout Section
31689 Submitting patches
31690 \end_layout
31691
31692 \begin_layout Standard
31693 Like bug reports contributed patches are forwarded to the developer mailing
31694  list.
31695  This is the link for submitting patches
31696 \begin_inset LatexCommand \index{Patch submission}
31697
31698 \end_inset
31699
31700
31701 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
31702
31703 \end_inset
31704
31705 .
31706 \end_layout
31707
31708 \begin_layout Standard
31709 You need to specify some parameters to the 
31710 \family typewriter
31711 diff
31712 \family default
31713  command for the patches to be useful.
31714  If you modified more than one file a patch created f.e.
31715  with 
31716 \family sans
31717 \series bold
31718
31719 \begin_inset Quotes sld
31720 \end_inset
31721
31722 diff -Naur unmodified_directory modified_directory >my_changes.patch
31723 \begin_inset Quotes srd
31724 \end_inset
31725
31726
31727 \family default
31728 \series default
31729  will be fine, otherwise 
31730 \family sans
31731 \series bold
31732
31733 \begin_inset Quotes sld
31734 \end_inset
31735
31736 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
31737 \begin_inset Quotes srd
31738 \end_inset
31739
31740
31741 \series default
31742  
31743 \family default
31744 will do.
31745 \end_layout
31746
31747 \begin_layout Section
31748 Getting Help
31749 \end_layout
31750
31751 \begin_layout Standard
31752 These links should take you directly to the 
31753 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
31754
31755 \end_inset
31756
31757
31758 \begin_inset Foot
31759 status open
31760
31761 \begin_layout Standard
31762 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
31763  automated messages (mid 2003)
31764 \end_layout
31765
31766 \end_inset
31767
31768  and the 
31769 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
31770
31771 \end_inset
31772
31773 , lists
31774 \begin_inset LatexCommand \index{Mailing list(s)}
31775
31776 \end_inset
31777
31778  and forums are archived and searchable so if you are lucky someone already
31779  had a similar problem.
31780  While mails to the lists themselves are delivered promptly their web front
31781  end on sourceforge sometimes shows a severe time lag (up to several weeks),
31782  if you're seriously using SDCC please consider subscribing to the lists.
31783 \end_layout
31784
31785 \begin_layout Section
31786 ChangeLog
31787 \end_layout
31788
31789 \begin_layout Standard
31790 You can follow the status of the Subversion version
31791 \begin_inset LatexCommand \index{version}
31792
31793 \end_inset
31794
31795  of SDCC by watching the Changelog
31796 \begin_inset LatexCommand \index{Changelog}
31797
31798 \end_inset
31799
31800  in the Subversion repository
31801 \size footnotesize
31802  
31803 \begin_inset LatexCommand \htmlurl{http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog}
31804
31805 \end_inset
31806
31807 .
31808 \end_layout
31809
31810 \begin_layout Section
31811 Subversion Source Code Repository
31812 \end_layout
31813
31814 \begin_layout Standard
31815 The output of 
31816 \family sans
31817 \series bold
31818 sdcc --version
31819 \family default
31820 \series default
31821  or the filenames of the snapshot versions of SDCC include date and its
31822  Subversion
31823 \begin_inset LatexCommand \index{Subversion code repository}
31824
31825 \end_inset
31826
31827  number.
31828  Subversion allows to download the source of recent or previous versions
31829  
31830 \begin_inset LatexCommand \url{http://sourceforge.net/svn/?group_id=599}
31831
31832 \end_inset
31833
31834  (by number or by date).
31835  An on-line source code browser and detailled instructions are also available
31836  there.
31837  SDCC versions starting from 1999 up to now are available (currently the
31838  versions prior to the conversion from cvs
31839 \begin_inset LatexCommand \index{cvs|see{Subversion}}
31840
31841 \end_inset
31842
31843  to Subversion (April 2006) are either by accessible by Subversion or by
31844  cvs).
31845 \end_layout
31846
31847 \begin_layout Section
31848 Release policy
31849 \begin_inset LatexCommand \index{Release policy}
31850
31851 \end_inset
31852
31853
31854 \end_layout
31855
31856 \begin_layout Standard
31857 Historically there often were long delays between official releases and
31858  the sourceforge download area tends to get not updated at all.
31859  Excuses in the past might have referred to problems with live range analysis,
31860  but as this was fixed a while ago, the current problem is that another
31861  excuse has to be found.
31862  Kidding aside, we have to get better there! On the other hand there are
31863  daily snapshots available at 
31864 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
31865
31866 \end_inset
31867
31868 , and you can always build the very last version (hopefully with many bugs
31869  fixed, and features added) from the source code available at 
31870 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
31871
31872 \end_inset
31873
31874 .
31875  A release wiki
31876 \begin_inset LatexCommand \index{wiki}
31877
31878 \end_inset
31879
31880
31881 \begin_inset LatexCommand \index{Release wiki}
31882
31883 \end_inset
31884
31885  at 
31886 \begin_inset LatexCommand \url{http://sdcc.sf.net/release_wiki/}
31887
31888 \end_inset
31889
31890  also holds some information about past and future releases.
31891 \end_layout
31892
31893 \begin_layout Section
31894 Examples
31895 \begin_inset LatexCommand \index{Examples}
31896
31897 \end_inset
31898
31899
31900 \end_layout
31901
31902 \begin_layout Standard
31903 You'll find some small examples in the directory 
31904 \emph on
31905 sdcc/device/examples/.
31906  
31907 \emph default
31908 More examples and libraries are available at
31909 \emph on
31910  The SDCC Open Knowledge Resource 
31911 \begin_inset LatexCommand \url{http://sdccokr.dl9sec.de/}
31912
31913 \end_inset
31914
31915  
31916 \emph default
31917 web site or at 
31918 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
31919
31920 \end_inset
31921
31922 .
31923 \end_layout
31924
31925 \begin_layout Standard
31926 \begin_inset Note Note
31927 status collapsed
31928
31929 \begin_layout Standard
31930 I did insert a reference to Paul's web site here although it seems rather
31931  dedicated to a specific 8032 board (I think it's okay because it f.e.
31932  shows LCD/Harddisc interface and has a free 8051 monitor.
31933  Independent 8032 board vendors face hard competition of heavily subsidized
31934  development boards anyway).
31935 \end_layout
31936
31937 \begin_layout Standard
31938 Maybe we should include some links to real world applications.
31939  Preferably pointer to pointers (one for each architecture) so this stays
31940  manageable here?
31941 \end_layout
31942
31943 \end_inset
31944
31945
31946 \end_layout
31947
31948 \begin_layout Section
31949 Quality control
31950 \begin_inset LatexCommand \label{sec:Quality-control}
31951
31952 \end_inset
31953
31954
31955 \begin_inset LatexCommand \index{Quality control}
31956
31957 \end_inset
31958
31959
31960 \end_layout
31961
31962 \begin_layout Standard
31963 The compiler is passed through snaphot build compile and build checks.
31964  The so called 
31965 \shape italic
31966 regression tests
31967 \shape default
31968
31969 \begin_inset LatexCommand \index{Regression test}
31970
31971 \end_inset
31972
31973  check that SDCC itself compiles flawlessly on several host platforms (i386,
31974  Opteron, 64 bit Alpha, ppc64, Mac OS X on PPC, Solaris on Sparc) and checks
31975  the quality of the code generated by SDCC by running the code for several
31976  target platforms through simulators.
31977  The regression test suite comprises more than 100 files which expand to
31978  more than 500 test cases which include more than 4500 tests.
31979  The results of these tests are published daily on SDCC's snapshot page
31980  (click on the red or green symbols on the right side of 
31981 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
31982
31983 \end_inset
31984
31985 ).
31986 \end_layout
31987
31988 \begin_layout Standard
31989 There is a separate document 
31990 \shape italic
31991 test_suite.pdf 
31992 \begin_inset LatexCommand \index{Test suite}
31993
31994 \end_inset
31995
31996
31997 \shape default
31998  
31999 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/test_suite_spec.pdf}
32000
32001 \end_inset
32002
32003  about the regression test suite.
32004 \end_layout
32005
32006 \begin_layout Standard
32007 You'll find the test code in the directory 
32008 \shape italic
32009 sdcc/support/regression
32010 \shape default
32011 .
32012  You can run these tests manually by running 
32013 \family sans
32014 make
32015 \family default
32016  in this directory (or f.e.
32017  
32018 \family sans
32019 \series bold
32020
32021 \begin_inset Quotes sld
32022 \end_inset
32023
32024 make test-mcs51
32025 \begin_inset Quotes srd
32026 \end_inset
32027
32028
32029 \family default
32030 \series default
32031  if you don't want to run the complete tests).
32032  The test code might also be interesting if you want to look for examples
32033 \begin_inset LatexCommand \index{Examples}
32034
32035 \end_inset
32036
32037  checking corner cases of SDCC or if you plan to submit patches
32038 \begin_inset LatexCommand \index{Patch submission}
32039
32040 \end_inset
32041
32042 .
32043 \end_layout
32044
32045 \begin_layout Standard
32046 The 14bit pic port uses a different set of regression tests 
32047 \begin_inset LatexCommand \index{Regression test (PIC14)}
32048
32049 \end_inset
32050
32051 , you'll find them in the directory 
32052 \shape italic
32053 sdcc/src/regression
32054 \shape default
32055 .
32056 \end_layout
32057
32058 \begin_layout Section
32059 Use of SDCC in Education
32060 \end_layout
32061
32062 \begin_layout Standard
32063 In short: 
32064 \emph on
32065 highly
32066 \emph default
32067  encouraged
32068 \begin_inset Foot
32069 status open
32070
32071 \begin_layout Standard
32072 the phrase "use in education" might evoke the association "
32073 \emph on
32074 only
32075 \emph default
32076  fit for use in education".
32077  This connotation is not intended but nevertheless risked as the licensing
32078  of SDCC makes it difficult to offer educational discounts
32079 \end_layout
32080
32081 \end_inset
32082
32083 .
32084  If your rationales are to:
32085 \end_layout
32086
32087 \begin_layout Enumerate
32088 give students a chance to understand the 
32089 \emph on
32090 complete
32091 \emph default
32092  steps of code generation
32093 \end_layout
32094
32095 \begin_layout Enumerate
32096 have a curriculum that can be extended for years.
32097  Then you could use an fpga board as target and your curriculum will seamlessly
32098  extend from logic synthesis (
32099 \begin_inset LatexCommand \url[http://www.opencores.org]{opencores.org}
32100
32101 \end_inset
32102
32103
32104 \begin_inset LatexCommand \url[Oregano]{http://www.oregano.at/ip/ip01.htm}
32105
32106 \end_inset
32107
32108 ), over assembly programming, to C to FPGA compilers (
32109 \begin_inset LatexCommand \url[FPGAC]{http://sf.net/projects/fpgac}
32110
32111 \end_inset
32112
32113 ) and to C.
32114 \end_layout
32115
32116 \begin_layout Enumerate
32117 be able to insert excursions about skills like using a revision control
32118  system, submitting/applying patches, using a type-setting (as opposed to
32119  word-processing) engine LyX/LaTeX, using 
32120 \begin_inset LatexCommand \url[SourceForge]{http://www.sf.net}
32121
32122 \end_inset
32123
32124 , following some 
32125 \begin_inset LatexCommand \url[netiquette]{http://en.wikipedia.org/wiki/Netiquette}
32126
32127 \end_inset
32128
32129 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
32130  Source Software, CPU simulation, compiler regression tests
32131 \begin_inset LatexCommand \index{Regression test}
32132
32133 \end_inset
32134
32135 .
32136  
32137 \newline
32138 And if there should be a shortage of ideas then you can always point students
32139  to the ever-growing feature request list 
32140 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
32141
32142 \end_inset
32143
32144 .
32145 \end_layout
32146
32147 \begin_layout Enumerate
32148 not tie students to a specific host platform and instead allow them to use
32149  a host platform of 
32150 \emph on
32151 their
32152 \emph default
32153  choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
32154  and eventually 
32155 \begin_inset LatexCommand \url[OLPC]{http://www.laptop.org}
32156
32157 \end_inset
32158
32159 )
32160 \end_layout
32161
32162 \begin_layout Enumerate
32163 not encourage students to use illegal copies of educational software
32164 \end_layout
32165
32166 \begin_layout Enumerate
32167 be immune to licensing/availability/price changes of the chosen tool chain
32168 \end_layout
32169
32170 \begin_layout Enumerate
32171 be able to change to a new target platform without having to adopt a new
32172  tool chain
32173 \end_layout
32174
32175 \begin_layout Enumerate
32176 have complete control over and insight into the tool chain
32177 \end_layout
32178
32179 \begin_layout Enumerate
32180 make your students aware about the pros and cons of open source software
32181  development
32182 \end_layout
32183
32184 \begin_layout Enumerate
32185 give back to the public as you are probably at least partially publically
32186  funded
32187 \end_layout
32188
32189 \begin_layout Enumerate
32190 give students a chance to publically prove their skills and to possibly
32191  see a world wide impact
32192 \end_layout
32193
32194 \begin_layout Standard
32195 then SDCC is probably among the first choices.
32196  Well, probably SDCC might be the only choice.
32197 \newpage
32198
32199 \end_layout
32200
32201 \begin_layout Chapter
32202 SDCC Technical Data
32203 \end_layout
32204
32205 \begin_layout Section
32206 Optimizations
32207 \begin_inset LatexCommand \index{Optimizations}
32208
32209 \end_inset
32210
32211
32212 \end_layout
32213
32214 \begin_layout Standard
32215 SDCC performs a host of standard optimizations in addition to some MCU specific
32216  optimizations.
32217  
32218 \end_layout
32219
32220 \begin_layout Subsection
32221 Sub-expression Elimination
32222 \begin_inset LatexCommand \index{Subexpression elimination}
32223
32224 \end_inset
32225
32226
32227 \end_layout
32228
32229 \begin_layout Standard
32230 The compiler does local and 
32231 \emph on
32232 g
32233 \emph default
32234 lobal 
32235 \emph on
32236 c
32237 \emph default
32238 ommon 
32239 \emph on
32240 s
32241 \emph default
32242 ubexpression 
32243 \emph on
32244 e
32245 \emph default
32246 limination, e.g.: 
32247 \end_layout
32248
32249 \begin_layout Verse
32250
32251 \family typewriter
32252 i = x + y + 1; 
32253 \newline
32254 j = x + y;
32255 \end_layout
32256
32257 \begin_layout Standard
32258 will be translated to
32259 \end_layout
32260
32261 \begin_layout Verse
32262
32263 \family typewriter
32264 iTemp = x + y; 
32265 \newline
32266 i = iTemp + 1; 
32267 \newline
32268 j = iTemp;
32269 \end_layout
32270
32271 \begin_layout Standard
32272 Some subexpressions are not as obvious as the above example, e.g.:
32273 \end_layout
32274
32275 \begin_layout Verse
32276
32277 \family typewriter
32278 a->b[i].c = 10; 
32279 \newline
32280 a->b[i].d = 11;
32281 \end_layout
32282
32283 \begin_layout Standard
32284 In this case the address arithmetic a->b[i] will be computed only once;
32285  the equivalent code in C would be.
32286 \end_layout
32287
32288 \begin_layout Verse
32289
32290 \family typewriter
32291 iTemp = a->b[i]; 
32292 \newline
32293 iTemp.c = 10; 
32294 \newline
32295 iTemp.d = 11;
32296 \end_layout
32297
32298 \begin_layout Standard
32299 The compiler will try to keep these temporary variables in registers.
32300 \end_layout
32301
32302 \begin_layout Subsection
32303 Dead-Code Elimination
32304 \begin_inset LatexCommand \index{Dead-code elimination}
32305
32306 \end_inset
32307
32308
32309 \end_layout
32310
32311 \begin_layout Verse
32312
32313 \family typewriter
32314 int global;
32315 \newline
32316
32317 \newline
32318 void f () { 
32319 \newline
32320 \InsetSpace ~
32321 \InsetSpace ~
32322 int i; 
32323 \newline
32324 \InsetSpace ~
32325 \InsetSpace ~
32326 i = 1; \InsetSpace ~
32327 \InsetSpace ~
32328 \InsetSpace ~
32329 \InsetSpace ~
32330 \InsetSpace ~
32331 /* dead store */ 
32332 \newline
32333 \InsetSpace ~
32334 \InsetSpace ~
32335 global = 1;\InsetSpace ~
32336 /* dead
32337  store */ 
32338 \newline
32339 \InsetSpace ~
32340 \InsetSpace ~
32341 global = 2; 
32342 \newline
32343 \InsetSpace ~
32344 \InsetSpace ~
32345 return; 
32346 \newline
32347 \InsetSpace ~
32348 \InsetSpace ~
32349 global = 3;\InsetSpace ~
32350 /* unreachable */ 
32351 \newline
32352 }
32353 \end_layout
32354
32355 \begin_layout Standard
32356 will be changed to
32357 \end_layout
32358
32359 \begin_layout Verse
32360
32361 \family typewriter
32362 int global;
32363 \newline
32364
32365 \newline
32366 void f () {
32367 \newline
32368 \InsetSpace ~
32369 \InsetSpace ~
32370 global = 2; 
32371 \newline
32372 }
32373 \end_layout
32374
32375 \begin_layout Subsection
32376 Copy-Propagation
32377 \begin_inset LatexCommand \index{Copy propagation}
32378
32379 \end_inset
32380
32381
32382 \end_layout
32383
32384 \begin_layout Verse
32385
32386 \family typewriter
32387 int f() { 
32388 \newline
32389 \InsetSpace ~
32390 \InsetSpace ~
32391 int i, j; 
32392 \newline
32393 \InsetSpace ~
32394 \InsetSpace ~
32395 i = 10; 
32396 \newline
32397 \InsetSpace ~
32398 \InsetSpace ~
32399 j = i; 
32400 \newline
32401 \InsetSpace ~
32402 \InsetSpace ~
32403 return j; 
32404 \newline
32405 }
32406 \end_layout
32407
32408 \begin_layout Standard
32409 will be changed to 
32410 \end_layout
32411
32412 \begin_layout Verse
32413
32414 \family typewriter
32415 int f() { 
32416 \newline
32417 \InsetSpace ~
32418 \InsetSpace ~
32419 int i, j; 
32420 \newline
32421 \InsetSpace ~
32422 \InsetSpace ~
32423 i = 10; 
32424 \newline
32425 \InsetSpace ~
32426 \InsetSpace ~
32427 j = 10; 
32428 \newline
32429 \InsetSpace ~
32430 \InsetSpace ~
32431 return 10; 
32432 \newline
32433 }
32434 \end_layout
32435
32436 \begin_layout Standard
32437 Note: the dead stores created by this copy propagation will be eliminated
32438  by dead-code elimination.
32439 \end_layout
32440
32441 \begin_layout Subsection
32442 Loop Optimizations
32443 \begin_inset LatexCommand \index{Loop optimization}
32444
32445 \end_inset
32446
32447
32448 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
32449
32450 \end_inset
32451
32452
32453 \end_layout
32454
32455 \begin_layout Standard
32456 Two types of loop optimizations are done by SDCC 
32457 \emph on
32458 loop invariant
32459 \emph default
32460  lifting and
32461 \emph on
32462  strength reduction
32463 \emph default
32464  of loop induction variables.
32465  In addition to the strength reduction the optimizer marks the induction
32466  variables and the register allocator tries to keep the induction variables
32467  in registers for the duration of the loop.
32468  Because of this preference of the register allocator
32469 \begin_inset LatexCommand \index{Register allocation}
32470
32471 \end_inset
32472
32473 , loop induction optimization causes an increase in register pressure, which
32474  may cause unwanted spilling of other temporary variables into the stack
32475 \begin_inset LatexCommand \index{stack}
32476
32477 \end_inset
32478
32479  / data space.
32480  The compiler will generate a warning message when it is forced to allocate
32481  extra space either on the stack or data space.
32482  If this extra space allocation is undesirable then induction optimization
32483  can be eliminated either for the entire source file (with -
32484 \begin_inset ERT
32485 status collapsed
32486
32487 \begin_layout Standard
32488
32489
32490 \backslash
32491 /
32492 \end_layout
32493
32494 \end_inset
32495
32496 -noinduction option) or for a given function only using #pragma\InsetSpace ~
32497 noinduction
32498 \begin_inset LatexCommand \index{\#pragma noinduction}
32499
32500 \end_inset
32501
32502 .
32503 \newline
32504
32505 \newline
32506 Loop Invariant:
32507 \end_layout
32508
32509 \begin_layout Verse
32510
32511 \family typewriter
32512 for (i = 0 ; i < 100 ; i ++) 
32513 \newline
32514 \InsetSpace ~
32515 \InsetSpace ~
32516 \InsetSpace ~
32517 \InsetSpace ~
32518 f += k + l;
32519 \end_layout
32520
32521 \begin_layout Standard
32522 changed to
32523 \end_layout
32524
32525 \begin_layout Verse
32526
32527 \family typewriter
32528 itemp = k + l; 
32529 \newline
32530 for (i = 0; i < 100; i++) 
32531 \newline
32532 \InsetSpace ~
32533 \InsetSpace ~
32534 \InsetSpace ~
32535 \InsetSpace ~
32536 f += itemp;
32537 \end_layout
32538
32539 \begin_layout Standard
32540 As mentioned previously some loop invariants are not as apparent, all static
32541  address computations are also moved out of the loop.
32542 \newline
32543
32544 \newline
32545 Strength Reduction
32546 \begin_inset LatexCommand \index{Strength reduction}
32547
32548 \end_inset
32549
32550 , this optimization substitutes an expression by a cheaper expression:
32551 \end_layout
32552
32553 \begin_layout Verse
32554
32555 \family typewriter
32556 for (i=0;i < 100; i++)
32557 \newline
32558 \InsetSpace ~
32559 \InsetSpace ~
32560 \InsetSpace ~
32561 \InsetSpace ~
32562 ar[i*5] = i*3;
32563 \end_layout
32564
32565 \begin_layout Standard
32566 changed to
32567 \end_layout
32568
32569 \begin_layout Verse
32570
32571 \family typewriter
32572 itemp1 = 0; 
32573 \newline
32574 itemp2 = 0; 
32575 \newline
32576 for (i=0;i< 100;i++) { 
32577 \newline
32578 \InsetSpace ~
32579 \InsetSpace ~
32580 \InsetSpace ~
32581 \InsetSpace ~
32582 ar[itemp1] = itemp2; 
32583 \newline
32584 \InsetSpace ~
32585 \InsetSpace ~
32586 \InsetSpace ~
32587 \InsetSpace ~
32588 itemp1
32589  += 5; 
32590 \newline
32591 \InsetSpace ~
32592 \InsetSpace ~
32593 \InsetSpace ~
32594 \InsetSpace ~
32595 itemp2 += 3; 
32596 \newline
32597 }
32598 \end_layout
32599
32600 \begin_layout Standard
32601 The more expensive multiplication
32602 \begin_inset LatexCommand \index{Multiplication}
32603
32604 \end_inset
32605
32606  is changed to a less expensive addition.
32607 \end_layout
32608
32609 \begin_layout Subsection
32610 Loop Reversing
32611 \begin_inset LatexCommand \index{Loop reversing}
32612
32613 \end_inset
32614
32615
32616 \end_layout
32617
32618 \begin_layout Standard
32619 This optimization is done to reduce the overhead of checking loop boundaries
32620  for every iteration.
32621  Some simple loops can be reversed and implemented using a 
32622 \begin_inset Quotes eld
32623 \end_inset
32624
32625 decrement and jump if not zero
32626 \begin_inset Quotes erd
32627 \end_inset
32628
32629  instruction.
32630  SDCC checks for the following criterion to determine if a loop is reversible
32631  (note: more sophisticated compilers use data-dependency analysis to make
32632  this determination, SDCC uses a more simple minded analysis).
32633 \end_layout
32634
32635 \begin_layout Itemize
32636 The 'for' loop is of the form 
32637 \newline
32638
32639 \newline
32640
32641 \family typewriter
32642 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
32643  += 1])
32644 \newline
32645 \InsetSpace ~
32646 \InsetSpace ~
32647 \InsetSpace ~
32648 \InsetSpace ~
32649 <for body>
32650 \end_layout
32651
32652 \begin_layout Itemize
32653 The <for body> does not contain 
32654 \begin_inset Quotes eld
32655 \end_inset
32656
32657 continue
32658 \begin_inset Quotes erd
32659 \end_inset
32660
32661  or 'break
32662 \begin_inset Quotes erd
32663 \end_inset
32664
32665 .
32666 \end_layout
32667
32668 \begin_layout Itemize
32669 All goto's are contained within the loop.
32670 \end_layout
32671
32672 \begin_layout Itemize
32673 No function calls within the loop.
32674 \end_layout
32675
32676 \begin_layout Itemize
32677 The loop control variable <sym> is not assigned any value within the loop
32678 \end_layout
32679
32680 \begin_layout Itemize
32681 The loop control variable does NOT participate in any arithmetic operation
32682  within the loop.
32683 \end_layout
32684
32685 \begin_layout Itemize
32686 There are NO switch statements in the loop.
32687 \end_layout
32688
32689 \begin_layout Subsection
32690 Algebraic Simplifications
32691 \end_layout
32692
32693 \begin_layout Standard
32694 SDCC does numerous algebraic simplifications, the following is a small sub-set
32695  of these optimizations.
32696 \end_layout
32697
32698 \begin_layout Verse
32699
32700 \family typewriter
32701 i = j + 0;\InsetSpace ~
32702 \InsetSpace ~
32703 \InsetSpace ~
32704 \InsetSpace ~
32705  /* changed to: */\InsetSpace ~
32706 \InsetSpace ~
32707 \InsetSpace ~
32708 \InsetSpace ~
32709  i = j; 
32710 \newline
32711 i /= 2;\InsetSpace ~
32712 \InsetSpace ~
32713 \InsetSpace ~
32714 \InsetSpace ~
32715 \InsetSpace ~
32716 \InsetSpace ~
32717 \InsetSpace ~
32718  /* changed to: */\InsetSpace ~
32719 \InsetSpace ~
32720 \InsetSpace ~
32721 \InsetSpace ~
32722  i >>= 1; 
32723 \newline
32724 i
32725  = j - j;\InsetSpace ~
32726 \InsetSpace ~
32727 \InsetSpace ~
32728 \InsetSpace ~
32729  /* changed to: */\InsetSpace ~
32730 \InsetSpace ~
32731 \InsetSpace ~
32732 \InsetSpace ~
32733  i = 0; 
32734 \newline
32735 i = j / 1;\InsetSpace ~
32736 \InsetSpace ~
32737 \InsetSpace ~
32738 \InsetSpace ~
32739  /* changed to: */\InsetSpace ~
32740 \InsetSpace ~
32741 \InsetSpace ~
32742 \InsetSpace ~
32743  i = j;
32744 \end_layout
32745
32746 \begin_layout Standard
32747 Note the subexpressions
32748 \begin_inset LatexCommand \index{Subexpression}
32749
32750 \end_inset
32751
32752  given above are generally introduced by macro expansions or as a result
32753  of copy/constant propagation.
32754 \end_layout
32755
32756 \begin_layout Subsection
32757 'switch' Statements
32758 \begin_inset LatexCommand \label{sub:'switch'-Statements}
32759
32760 \end_inset
32761
32762
32763 \begin_inset LatexCommand \index{switch statement}
32764
32765 \end_inset
32766
32767
32768 \end_layout
32769
32770 \begin_layout Standard
32771 SDCC can optimize switch statements to jump tables
32772 \begin_inset LatexCommand \index{jump tables}
32773
32774 \end_inset
32775
32776 .
32777  It makes the decision based on an estimate of the generated code size.
32778  SDCC is quite liberal in the requirements for jump table generation: 
32779 \end_layout
32780
32781 \begin_layout Itemize
32782 The labels need not be in order, and the starting number need not be one
32783  or zero, the case labels are in numerical sequence or not too many case
32784  labels are missing.
32785 \end_layout
32786
32787 \begin_deeper
32788 \begin_layout Verse
32789
32790 \family typewriter
32791 switch(i) {\InsetSpace ~
32792 \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 switch (i) { 
32818 \newline
32819 \InsetSpace ~
32820 \InsetSpace ~
32821 \InsetSpace ~
32822 case 4: ...\InsetSpace ~
32823 \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 case 0: ...
32849  
32850 \newline
32851 \InsetSpace ~
32852 \InsetSpace ~
32853 \InsetSpace ~
32854 case 5: ...\InsetSpace ~
32855 \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 case 1: ...
32881  
32882 \newline
32883 \InsetSpace ~
32884 \InsetSpace ~
32885 \InsetSpace ~
32886 case 3: ...\InsetSpace ~
32887 \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
32913 \newline
32914 \InsetSpace ~
32915 \InsetSpace ~
32916 \InsetSpace ~
32917 case 6: ...\InsetSpace ~
32918 \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 case 3: ...
32944  
32945 \newline
32946 \InsetSpace ~
32947 \InsetSpace ~
32948 \InsetSpace ~
32949 case 7: ...\InsetSpace ~
32950 \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 case 4: ...
32976  
32977 \newline
32978 \InsetSpace ~
32979 \InsetSpace ~
32980 \InsetSpace ~
32981 case 8: ...\InsetSpace ~
32982 \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 case 5: ...
33008  
33009 \newline
33010 \InsetSpace ~
33011 \InsetSpace ~
33012 \InsetSpace ~
33013 case 9: ...\InsetSpace ~
33014 \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 case 6: ...
33040  
33041 \newline
33042 \InsetSpace ~
33043 \InsetSpace ~
33044 \InsetSpace ~
33045 case 10: ...\InsetSpace ~
33046 \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 case 7: ...
33071  
33072 \newline
33073 \InsetSpace ~
33074 \InsetSpace ~
33075 \InsetSpace ~
33076 case 11: ...\InsetSpace ~
33077 \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 case 8: ...
33102  
33103 \newline
33104 }\InsetSpace ~
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 }
33141 \end_layout
33142
33143 \begin_layout Standard
33144 Both the above switch statements will be implemented using a jump-table.
33145  The example to the right side is slightly more efficient as the check for
33146  the lower boundary of the jump-table is not needed.
33147 \end_layout
33148
33149 \end_deeper
33150 \begin_layout Itemize
33151 The number of case labels is not larger than supported by the target architectur
33152 e.
33153 \end_layout
33154
33155 \begin_layout Itemize
33156 If the case labels are not in numerical sequence ('gaps' between cases)
33157  SDCC checks whether a jump table with additionally inserted dummy cases
33158  is still attractive.
33159  
33160 \end_layout
33161
33162 \begin_layout Itemize
33163 If the starting number is not zero and a check for the lower boundary of
33164  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
33165  ...
33166  .
33167 \end_layout
33168
33169 \begin_layout Standard
33170 Switch statements which have large gaps in the numeric sequence or those
33171  that have too many case labels can be split into more than one switch statement
33172  for efficient code generation, e.g.:
33173 \end_layout
33174
33175 \begin_layout Verse
33176
33177 \family typewriter
33178 switch (i) { 
33179 \newline
33180 \InsetSpace ~
33181 \InsetSpace ~
33182 case 1: ...
33183  
33184 \newline
33185 \InsetSpace ~
33186 \InsetSpace ~
33187 case 2: ...
33188  
33189 \newline
33190 \InsetSpace ~
33191 \InsetSpace ~
33192 case 3: ...
33193  
33194 \newline
33195 \InsetSpace ~
33196 \InsetSpace ~
33197 case 4: ...
33198  
33199 \newline
33200 \InsetSpace ~
33201 \InsetSpace ~
33202 case 5: ...
33203  
33204 \newline
33205 \InsetSpace ~
33206 \InsetSpace ~
33207 case 6: ...
33208  
33209 \newline
33210 \InsetSpace ~
33211 \InsetSpace ~
33212 case 7: ...
33213  
33214 \newline
33215 \InsetSpace ~
33216 \InsetSpace ~
33217 case 101: ...
33218  
33219 \newline
33220 \InsetSpace ~
33221 \InsetSpace ~
33222 case 102: ...
33223  
33224 \newline
33225 \InsetSpace ~
33226 \InsetSpace ~
33227 case 103: ...
33228  
33229 \newline
33230 \InsetSpace ~
33231 \InsetSpace ~
33232 case 104: ...
33233  
33234 \newline
33235 \InsetSpace ~
33236 \InsetSpace ~
33237 case 105: ...
33238  
33239 \newline
33240 \InsetSpace ~
33241 \InsetSpace ~
33242 case 106: ...
33243  
33244 \newline
33245 \InsetSpace ~
33246 \InsetSpace ~
33247 case 107: ...
33248  
33249 \newline
33250 }
33251 \end_layout
33252
33253 \begin_layout Standard
33254 If the above switch statement is broken down into two switch statements
33255 \end_layout
33256
33257 \begin_layout Verse
33258
33259 \family typewriter
33260 switch (i) { 
33261 \newline
33262 \InsetSpace ~
33263 \InsetSpace ~
33264 case 1: ...
33265  
33266 \newline
33267 \InsetSpace ~
33268 \InsetSpace ~
33269 case 2: ...
33270  
33271 \newline
33272 \InsetSpace ~
33273 \InsetSpace ~
33274 case 3: ...
33275  
33276 \newline
33277 \InsetSpace ~
33278 \InsetSpace ~
33279 case 4: ...
33280  
33281 \newline
33282 \InsetSpace ~
33283 \InsetSpace ~
33284 case 5: ...
33285  
33286 \newline
33287 \InsetSpace ~
33288 \InsetSpace ~
33289 case 6: ...
33290  
33291 \newline
33292 \InsetSpace ~
33293 \InsetSpace ~
33294 case 7: ...
33295  
33296 \newline
33297 }
33298 \end_layout
33299
33300 \begin_layout Standard
33301 and
33302 \end_layout
33303
33304 \begin_layout Verse
33305
33306 \family typewriter
33307 switch (i) { 
33308 \newline
33309 \InsetSpace ~
33310 \InsetSpace ~
33311 case 101: ...
33312  
33313 \newline
33314 \InsetSpace ~
33315 \InsetSpace ~
33316 case 102: ...
33317  
33318 \newline
33319 \InsetSpace ~
33320 \InsetSpace ~
33321 case 103: ...
33322  
33323 \newline
33324 \InsetSpace ~
33325 \InsetSpace ~
33326 case 104: ...
33327  
33328 \newline
33329 \InsetSpace ~
33330 \InsetSpace ~
33331 case 105: ...
33332  
33333 \newline
33334 \InsetSpace ~
33335 \InsetSpace ~
33336 case 106: ...
33337  
33338 \newline
33339 \InsetSpace ~
33340 \InsetSpace ~
33341 case 107: ...
33342  
33343 \newline
33344 }
33345 \end_layout
33346
33347 \begin_layout Standard
33348 then both the switch statements will be implemented using jump-tables whereas
33349  the unmodified switch statement will not be.
33350 \end_layout
33351
33352 \begin_layout Standard
33353 \begin_inset Note Note
33354 status collapsed
33355
33356 \begin_layout Standard
33357 There might be reasons which SDCC cannot know about to either favour or
33358  not favour jump tables.
33359  If the target system has to be as quick for the last switch case as for
33360  the first (pro jump table), or if the switch argument is known to be zero
33361  in the majority of the cases (contra jump table).
33362 \end_layout
33363
33364 \end_inset
33365
33366
33367 \end_layout
33368
33369 \begin_layout Standard
33370 The pragma nojtbound
33371 \begin_inset LatexCommand \index{\#pragma nojtbound}
33372
33373 \end_inset
33374
33375  can be used to turn off checking the 
33376 \emph on
33377 j
33378 \emph default
33379 ump 
33380 \emph on
33381 t
33382 \emph default
33383 able 
33384 \emph on
33385 bound
33386 \emph default
33387 aries.
33388  It has no effect if a default label is supplied.
33389  Use of this pragma is dangerous: if the switch
33390 \begin_inset LatexCommand \index{switch statement}
33391
33392 \end_inset
33393
33394  argument is not matched by a case statement the processor will happily
33395  jump into Nirvana.
33396 \end_layout
33397
33398 \begin_layout Subsection
33399 Bit-shifting Operations
33400 \begin_inset LatexCommand \index{Bit shifting}
33401
33402 \end_inset
33403
33404 .
33405 \end_layout
33406
33407 \begin_layout Standard
33408 Bit shifting is one of the most frequently used operation in embedded programmin
33409 g.
33410  SDCC tries to implement bit-shift operations in the most efficient way
33411  possible, e.g.:
33412 \end_layout
33413
33414 \begin_layout Verse
33415
33416 \family typewriter
33417 unsigned char i;
33418 \newline
33419 ...
33420  
33421 \newline
33422 i >>= 4; 
33423 \newline
33424 ...
33425 \end_layout
33426
33427 \begin_layout Standard
33428 generates the following code:
33429 \end_layout
33430
33431 \begin_layout Verse
33432
33433 \family typewriter
33434 mov\InsetSpace ~
33435  a,_i 
33436 \newline
33437 swap a 
33438 \newline
33439 anl\InsetSpace ~
33440  a,#0x0f 
33441 \newline
33442 mov\InsetSpace ~
33443  _i,a
33444 \end_layout
33445
33446 \begin_layout Standard
33447 In general SDCC will never setup a loop if the shift count is known.
33448  Another example:
33449 \end_layout
33450
33451 \begin_layout Verse
33452
33453 \family typewriter
33454 unsigned int i; 
33455 \newline
33456 ...
33457  
33458 \newline
33459 i >>= 9; 
33460 \newline
33461 ...
33462 \end_layout
33463
33464 \begin_layout Standard
33465 will generate:
33466 \end_layout
33467
33468 \begin_layout Verse
33469
33470 \family typewriter
33471 mov\InsetSpace ~
33472 \InsetSpace ~
33473 a,(_i + 1) 
33474 \newline
33475 mov\InsetSpace ~
33476 \InsetSpace ~
33477 (_i + 1),#0x00 
33478 \newline
33479 clr\InsetSpace ~
33480 \InsetSpace ~
33481
33482 \newline
33483 rrc\InsetSpace ~
33484 \InsetSpace ~
33485
33486 \newline
33487 mov\InsetSpace ~
33488 \InsetSpace ~
33489 _i,a
33490 \end_layout
33491
33492 \begin_layout Subsection
33493 Bit-rotation
33494 \begin_inset LatexCommand \index{Bit rotation}
33495
33496 \end_inset
33497
33498
33499 \end_layout
33500
33501 \begin_layout Standard
33502 A special case of the bit-shift operation is bit rotation
33503 \begin_inset LatexCommand \index{rotating bits}
33504
33505 \end_inset
33506
33507 , SDCC recognizes the following expression to be a left bit-rotation:
33508 \end_layout
33509
33510 \begin_layout Verse
33511
33512 \family typewriter
33513 \series bold
33514 unsigned
33515 \series default
33516 \InsetSpace ~
33517 \InsetSpace ~
33518 char i;\InsetSpace ~
33519 \InsetSpace ~
33520 \InsetSpace ~
33521 \InsetSpace ~
33522 \InsetSpace ~
33523 \InsetSpace ~
33524 \InsetSpace ~
33525 \InsetSpace ~
33526 \InsetSpace ~
33527 \InsetSpace ~
33528 \InsetSpace ~
33529 /* unsigned is needed for rotation */ 
33530 \newline
33531 ...
33532  
33533 \newline
33534 i = ((i << 1) | (i >> 7)); 
33535 \family default
33536
33537 \newline
33538
33539 \family typewriter
33540 ...
33541 \end_layout
33542
33543 \begin_layout Standard
33544 will generate the following code:
33545 \end_layout
33546
33547 \begin_layout Verse
33548
33549 \family typewriter
33550 mov\InsetSpace ~
33551 \InsetSpace ~
33552 a,_i 
33553 \newline
33554 rl\InsetSpace ~
33555 \InsetSpace ~
33556 \InsetSpace ~
33557
33558 \newline
33559 mov\InsetSpace ~
33560 \InsetSpace ~
33561 _i,a
33562 \end_layout
33563
33564 \begin_layout Standard
33565 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
33566 ns of this case will also be recognized as bit-rotation, i.e.: 
33567 \end_layout
33568
33569 \begin_layout Verse
33570
33571 \family typewriter
33572 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
33573 \end_layout
33574
33575 \begin_layout Subsection
33576 Nibble and Byte Swapping
33577 \end_layout
33578
33579 \begin_layout Standard
33580 Other special cases of the bit-shift operations are nibble or byte swapping
33581 \begin_inset LatexCommand \index{swapping nibbles/bytes}
33582
33583 \end_inset
33584
33585 , SDCC recognizes the following expressions:
33586 \end_layout
33587
33588 \begin_layout Verse
33589
33590 \family typewriter
33591 \series bold
33592 unsigned
33593 \series default
33594 \InsetSpace ~
33595 \InsetSpace ~
33596 char i; 
33597 \newline
33598
33599 \series bold
33600 unsigned
33601 \series default
33602 \InsetSpace ~
33603 \InsetSpace ~
33604 int j; 
33605 \newline
33606 ...
33607  
33608 \newline
33609 i = ((i << 4) | (i >> 4)); 
33610 \family default
33611
33612 \newline
33613
33614 \family typewriter
33615 j = ((j << 8) | (j >> 8)); 
33616 \end_layout
33617
33618 \begin_layout Standard
33619 and generates a swap instruction for the nibble swapping
33620 \begin_inset LatexCommand \index{Nibble swapping}
33621
33622 \end_inset
33623
33624  or move instructions for the byte swapping
33625 \begin_inset LatexCommand \index{Byte swapping}
33626
33627 \end_inset
33628
33629 .
33630  The 
33631 \begin_inset Quotes sld
33632 \end_inset
33633
33634 j
33635 \begin_inset Quotes srd
33636 \end_inset
33637
33638  example can be used to convert from little to big-endian or vice versa.
33639  If you want to change the endianness of a 
33640 \emph on
33641 signed
33642 \emph default
33643  integer you have to cast to 
33644 \family typewriter
33645 (unsigned int)
33646 \family default
33647  first.
33648 \end_layout
33649
33650 \begin_layout Standard
33651 Note that SDCC stores numbers in little-endian
33652 \begin_inset Foot
33653 status open
33654
33655 \begin_layout Standard
33656 Usually 8-bit processors don't care much about endianness.
33657  This is not the case for the standard 8051 which only has an instruction
33658  to increment its 
33659 \emph on
33660 dptr
33661 \emph default
33662
33663 \begin_inset LatexCommand \index{DPTR}
33664
33665 \end_inset
33666
33667 -datapointer
33668 \emph on
33669  
33670 \emph default
33671 so little-endian is the more efficient byte order.
33672 \end_layout
33673
33674 \end_inset
33675
33676
33677 \begin_inset LatexCommand \index{little-endian}
33678
33679 \end_inset
33680
33681
33682 \begin_inset LatexCommand \index{Endianness}
33683
33684 \end_inset
33685
33686  format (i.e.
33687  lowest order first).
33688 \end_layout
33689
33690 \begin_layout Subsection
33691 Highest Order Bit
33692 \begin_inset LatexCommand \index{Highest Order Bit}
33693
33694 \end_inset
33695
33696  / Any Order Bit
33697 \begin_inset LatexCommand \index{Any Order Bit}
33698
33699 \end_inset
33700
33701
33702 \end_layout
33703
33704 \begin_layout Standard
33705 It is frequently required to obtain the highest order bit of an integral
33706  type (long, int, short or char types).
33707  Also obtaining any other order bit is not uncommon.
33708  SDCC recognizes the following expressions to yield the highest order bit
33709  and generates optimized code for it, e.g.:
33710 \end_layout
33711
33712 \begin_layout Verse
33713
33714 \family typewriter
33715 unsigned int gint; 
33716 \newline
33717
33718 \newline
33719 foo () { 
33720 \newline
33721 \InsetSpace ~
33722 \InsetSpace ~
33723 unsigned char hob1, aob1; 
33724 \newline
33725 \InsetSpace ~
33726 \InsetSpace ~
33727 bit hob2, hob3, aob2,
33728  aob3; 
33729 \newline
33730 \InsetSpace ~
33731 \InsetSpace ~
33732 ...
33733  
33734 \newline
33735 \InsetSpace ~
33736 \InsetSpace ~
33737 hob1 = (gint >> 15) & 1; 
33738 \newline
33739 \InsetSpace ~
33740 \InsetSpace ~
33741 hob2 = (gint >> 15) & 1; 
33742 \newline
33743 \InsetSpace ~
33744 \InsetSpace ~
33745 hob3 = gint & 0x8000;
33746  
33747 \newline
33748 \InsetSpace ~
33749 \InsetSpace ~
33750 aob1 = (gint >> 9) & 1; 
33751 \newline
33752 \InsetSpace ~
33753 \InsetSpace ~
33754 aob2 = (gint >> 8) & 1; 
33755 \newline
33756 \InsetSpace ~
33757 \InsetSpace ~
33758 aob3 = gint & 0x0800; 
33759 \newline
33760 \InsetSpace ~
33761 \InsetSpace ~
33762 ..
33763  
33764 \newline
33765 }
33766 \end_layout
33767
33768 \begin_layout Standard
33769 will generate the following code:
33770 \end_layout
33771
33772 \begin_layout Verse
33773
33774 \family typewriter
33775 \InsetSpace ~
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  61 ;\InsetSpace ~
33801  hob.c 7 
33802 \newline
33803 000A E5*01\InsetSpace ~
33804 \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  62\InsetSpace ~
33819 \InsetSpace ~
33820 \InsetSpace ~
33821 \InsetSpace ~
33822 \InsetSpace ~
33823 \InsetSpace ~
33824 \InsetSpace ~
33825 \InsetSpace ~
33826  mov\InsetSpace ~
33827 \InsetSpace ~
33828  a,(_gint + 1) 
33829 \newline
33830 000C 23\InsetSpace ~
33831 \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  63\InsetSpace ~
33849 \InsetSpace ~
33850 \InsetSpace ~
33851 \InsetSpace ~
33852 \InsetSpace ~
33853 \InsetSpace ~
33854 \InsetSpace ~
33855 \InsetSpace ~
33856  rl\InsetSpace ~
33857 \InsetSpace ~
33858 \InsetSpace ~
33859  a 
33860 \newline
33861 000D 54 01\InsetSpace ~
33862 \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
33877  64\InsetSpace ~
33878 \InsetSpace ~
33879 \InsetSpace ~
33880 \InsetSpace ~
33881 \InsetSpace ~
33882 \InsetSpace ~
33883 \InsetSpace ~
33884 \InsetSpace ~
33885  anl\InsetSpace ~
33886 \InsetSpace ~
33887  a,#0x01 
33888 \newline
33889 000F F5*02\InsetSpace ~
33890 \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  65\InsetSpace ~
33905 \InsetSpace ~
33906 \InsetSpace ~
33907 \InsetSpace ~
33908 \InsetSpace ~
33909 \InsetSpace ~
33910 \InsetSpace ~
33911 \InsetSpace ~
33912  mov\InsetSpace ~
33913 \InsetSpace ~
33914  _foo_hob1_1_1,a 
33915 \newline
33916 \InsetSpace ~
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  66 ;\InsetSpace ~
33942  hob.c 8 
33943 \newline
33944 0011 E5*01\InsetSpace ~
33945 \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
33960  67\InsetSpace ~
33961 \InsetSpace ~
33962 \InsetSpace ~
33963 \InsetSpace ~
33964 \InsetSpace ~
33965 \InsetSpace ~
33966 \InsetSpace ~
33967 \InsetSpace ~
33968  mov\InsetSpace ~
33969 \InsetSpace ~
33970  a,(_gint + 1) 
33971 \newline
33972 0013 33\InsetSpace ~
33973 \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  68\InsetSpace ~
33991 \InsetSpace ~
33992 \InsetSpace ~
33993 \InsetSpace ~
33994 \InsetSpace ~
33995 \InsetSpace ~
33996 \InsetSpace ~
33997 \InsetSpace ~
33998  rlc\InsetSpace ~
33999 \InsetSpace ~
34000  a 
34001 \newline
34002 0014 92*00\InsetSpace ~
34003 \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  69\InsetSpace ~
34018 \InsetSpace ~
34019 \InsetSpace ~
34020 \InsetSpace ~
34021 \InsetSpace ~
34022 \InsetSpace ~
34023 \InsetSpace ~
34024 \InsetSpace ~
34025  mov\InsetSpace ~
34026 \InsetSpace ~
34027  _foo_hob2_1_1,c
34028  
34029 \newline
34030 \InsetSpace ~
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  66 ;\InsetSpace ~
34056  hob.c 9 
34057 \newline
34058 0016 E5*01\InsetSpace ~
34059 \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  67\InsetSpace ~
34074 \InsetSpace ~
34075 \InsetSpace ~
34076 \InsetSpace ~
34077 \InsetSpace ~
34078 \InsetSpace ~
34079 \InsetSpace ~
34080 \InsetSpace ~
34081  mov\InsetSpace ~
34082 \InsetSpace ~
34083  a,(_gint + 1) 
34084 \newline
34085 0018 33\InsetSpace ~
34086 \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  68\InsetSpace ~
34104 \InsetSpace ~
34105 \InsetSpace ~
34106 \InsetSpace ~
34107 \InsetSpace ~
34108 \InsetSpace ~
34109 \InsetSpace ~
34110 \InsetSpace ~
34111  rlc\InsetSpace ~
34112 \InsetSpace ~
34113  a 
34114 \newline
34115 0019 92*01\InsetSpace ~
34116 \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
34131  69\InsetSpace ~
34132 \InsetSpace ~
34133 \InsetSpace ~
34134 \InsetSpace ~
34135 \InsetSpace ~
34136 \InsetSpace ~
34137 \InsetSpace ~
34138 \InsetSpace ~
34139  mov\InsetSpace ~
34140 \InsetSpace ~
34141  _foo_hob3_1_1,c 
34142 \newline
34143 \InsetSpace ~
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  70 ;\InsetSpace ~
34169  hob.c 10 
34170 \newline
34171 001B E5*01\InsetSpace ~
34172 \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  71\InsetSpace ~
34187 \InsetSpace ~
34188 \InsetSpace ~
34189 \InsetSpace ~
34190 \InsetSpace ~
34191 \InsetSpace ~
34192 \InsetSpace ~
34193 \InsetSpace ~
34194  mov\InsetSpace ~
34195 \InsetSpace ~
34196  a,(_gint + 1) 
34197 \newline
34198 001D
34199  03\InsetSpace ~
34200 \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  72\InsetSpace ~
34218 \InsetSpace ~
34219 \InsetSpace ~
34220 \InsetSpace ~
34221 \InsetSpace ~
34222 \InsetSpace ~
34223 \InsetSpace ~
34224 \InsetSpace ~
34225  rr\InsetSpace ~
34226 \InsetSpace ~
34227 \InsetSpace ~
34228  a 
34229 \newline
34230 001E 54 01\InsetSpace ~
34231 \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  73\InsetSpace ~
34246 \InsetSpace ~
34247 \InsetSpace ~
34248 \InsetSpace ~
34249 \InsetSpace ~
34250 \InsetSpace ~
34251 \InsetSpace ~
34252 \InsetSpace ~
34253  anl\InsetSpace ~
34254 \InsetSpace ~
34255  a,#0x01 
34256 \newline
34257 0020 F5*03\InsetSpace ~
34258 \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  74\InsetSpace ~
34273 \InsetSpace ~
34274 \InsetSpace ~
34275 \InsetSpace ~
34276 \InsetSpace ~
34277 \InsetSpace ~
34278 \InsetSpace ~
34279 \InsetSpace ~
34280  mov\InsetSpace ~
34281 \InsetSpace ~
34282  _foo_aob1_1_1,a
34283  
34284 \newline
34285 \InsetSpace ~
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  75 ;\InsetSpace ~
34311  hob.c 11 
34312 \newline
34313 0022 E5*01\InsetSpace ~
34314 \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  76\InsetSpace ~
34329 \InsetSpace ~
34330 \InsetSpace ~
34331 \InsetSpace ~
34332 \InsetSpace ~
34333 \InsetSpace ~
34334 \InsetSpace ~
34335 \InsetSpace ~
34336  mov\InsetSpace ~
34337 \InsetSpace ~
34338  a,(_gint + 1) 
34339 \newline
34340 0024 13\InsetSpace ~
34341 \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  77\InsetSpace ~
34359 \InsetSpace ~
34360 \InsetSpace ~
34361 \InsetSpace ~
34362 \InsetSpace ~
34363 \InsetSpace ~
34364 \InsetSpace ~
34365 \InsetSpace ~
34366  rrc\InsetSpace ~
34367 \InsetSpace ~
34368  a 
34369 \newline
34370 0025 92*02\InsetSpace ~
34371 \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
34386  78\InsetSpace ~
34387 \InsetSpace ~
34388 \InsetSpace ~
34389 \InsetSpace ~
34390 \InsetSpace ~
34391 \InsetSpace ~
34392 \InsetSpace ~
34393 \InsetSpace ~
34394  mov\InsetSpace ~
34395 \InsetSpace ~
34396  _foo_aob2_1_1,c 
34397 \newline
34398 \InsetSpace ~
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  79 ;\InsetSpace ~
34424  hob.c 12 
34425 \newline
34426 0027 E5*01\InsetSpace ~
34427 \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  80\InsetSpace ~
34442 \InsetSpace ~
34443 \InsetSpace ~
34444 \InsetSpace ~
34445 \InsetSpace ~
34446 \InsetSpace ~
34447 \InsetSpace ~
34448 \InsetSpace ~
34449  mov\InsetSpace ~
34450 \InsetSpace ~
34451  a,(_gint + 1) 
34452 \newline
34453 0029
34454  A2 E3\InsetSpace ~
34455 \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  81\InsetSpace ~
34470 \InsetSpace ~
34471 \InsetSpace ~
34472 \InsetSpace ~
34473 \InsetSpace ~
34474 \InsetSpace ~
34475 \InsetSpace ~
34476 \InsetSpace ~
34477  mov\InsetSpace ~
34478 \InsetSpace ~
34479  c,acc[3] 
34480 \newline
34481 002B 92*03\InsetSpace ~
34482 \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  82\InsetSpace ~
34497 \InsetSpace ~
34498 \InsetSpace ~
34499 \InsetSpace ~
34500 \InsetSpace ~
34501 \InsetSpace ~
34502 \InsetSpace ~
34503 \InsetSpace ~
34504  mov\InsetSpace ~
34505 \InsetSpace ~
34506  _foo_aob3_1_1,c 
34507 \end_layout
34508
34509 \begin_layout Standard
34510 Other variations of these cases however will 
34511 \emph on
34512 not
34513 \emph default
34514  be recognized.
34515  They are standard C expressions, so I heartily recommend these be the only
34516  way to get the highest order bit, (it is portable).
34517  Of course it will be recognized even if it is embedded in other expressions,
34518  e.g.:
34519 \end_layout
34520
34521 \begin_layout Verse
34522
34523 \family typewriter
34524 xyz = gint + ((gint >> 15) & 1);
34525 \end_layout
34526
34527 \begin_layout Standard
34528 will still be recognized.
34529 \end_layout
34530
34531 \begin_layout Subsection
34532 Higher Order Byte
34533 \begin_inset LatexCommand \index{Higher Order Byte}
34534
34535 \end_inset
34536
34537  / Higher Order Word
34538 \begin_inset LatexCommand \index{Higher Order Word}
34539
34540 \end_inset
34541
34542
34543 \end_layout
34544
34545 \begin_layout Standard
34546 It is also frequently required to obtain a higher order byte or word of
34547  a larger integral type (long, int or short types).
34548  SDCC recognizes the following expressions to yield the higher order byte
34549  or word and generates optimized code for it, e.g.:
34550 \end_layout
34551
34552 \begin_layout Verse
34553
34554 \family typewriter
34555 unsigned int gint; 
34556 \newline
34557 unsigned long int glong; 
34558 \newline
34559
34560 \newline
34561 foo () { 
34562 \newline
34563 \InsetSpace ~
34564 \InsetSpace ~
34565 unsigned char hob1,
34566  hob2; 
34567 \newline
34568 \InsetSpace ~
34569 \InsetSpace ~
34570 unsigned int how1, how2; 
34571 \newline
34572 \InsetSpace ~
34573 \InsetSpace ~
34574 ...
34575  
34576 \newline
34577 \InsetSpace ~
34578 \InsetSpace ~
34579 hob1 = (gint >> 8) & 0xFF; 
34580 \newline
34581 \InsetSpace ~
34582 \InsetSpace ~
34583 hob2 = glong >> 24; 
34584 \newline
34585 \InsetSpace ~
34586 \InsetSpace ~
34587 how1 = (glong >> 16) & 0xFFFF;
34588  
34589 \newline
34590 \InsetSpace ~
34591 \InsetSpace ~
34592 how2 = glong >> 8; 
34593 \newline
34594 \InsetSpace ~
34595 \InsetSpace ~
34596 ..
34597  
34598 \newline
34599 }
34600 \end_layout
34601
34602 \begin_layout Standard
34603 will generate the following code:
34604 \end_layout
34605
34606 \begin_layout Verse
34607
34608 \family typewriter
34609 \InsetSpace ~
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  91 ;\InsetSpace ~
34635  hob.c 15 
34636 \newline
34637 0037 85*01*06\InsetSpace ~
34638 \InsetSpace ~
34639 \InsetSpace ~
34640 \InsetSpace ~
34641 \InsetSpace ~
34642 \InsetSpace ~
34643 \InsetSpace ~
34644 \InsetSpace ~
34645 \InsetSpace ~
34646 \InsetSpace ~
34647 \InsetSpace ~
34648 \InsetSpace ~
34649  92\InsetSpace ~
34650 \InsetSpace ~
34651 \InsetSpace ~
34652 \InsetSpace ~
34653 \InsetSpace ~
34654 \InsetSpace ~
34655 \InsetSpace ~
34656 \InsetSpace ~
34657  mov\InsetSpace ~
34658 \InsetSpace ~
34659  _foo_hob1_1_1,(_gint + 1) 
34660 \newline
34661 \InsetSpace ~
34662 \InsetSpace ~
34663 \InsetSpace ~
34664 \InsetSpace ~
34665 \InsetSpace ~
34666 \InsetSpace ~
34667 \InsetSpace ~
34668 \InsetSpace ~
34669 \InsetSpace ~
34670 \InsetSpace ~
34671 \InsetSpace ~
34672 \InsetSpace ~
34673 \InsetSpace ~
34674 \InsetSpace ~
34675 \InsetSpace ~
34676 \InsetSpace ~
34677 \InsetSpace ~
34678 \InsetSpace ~
34679 \InsetSpace ~
34680 \InsetSpace ~
34681 \InsetSpace ~
34682 \InsetSpace ~
34683 \InsetSpace ~
34684 \InsetSpace ~
34685 \InsetSpace ~
34686  93 ;\InsetSpace ~
34687  hob.c
34688  16 
34689 \newline
34690 003A 85*05*07\InsetSpace ~
34691 \InsetSpace ~
34692 \InsetSpace ~
34693 \InsetSpace ~
34694 \InsetSpace ~
34695 \InsetSpace ~
34696 \InsetSpace ~
34697 \InsetSpace ~
34698 \InsetSpace ~
34699 \InsetSpace ~
34700 \InsetSpace ~
34701 \InsetSpace ~
34702  94\InsetSpace ~
34703 \InsetSpace ~
34704 \InsetSpace ~
34705 \InsetSpace ~
34706 \InsetSpace ~
34707 \InsetSpace ~
34708 \InsetSpace ~
34709 \InsetSpace ~
34710  mov\InsetSpace ~
34711 \InsetSpace ~
34712  _foo_hob2_1_1,(_glong + 3) 
34713 \newline
34714 \InsetSpace ~
34715 \InsetSpace ~
34716 \InsetSpace ~
34717 \InsetSpace ~
34718 \InsetSpace ~
34719 \InsetSpace ~
34720 \InsetSpace ~
34721 \InsetSpace ~
34722 \InsetSpace ~
34723 \InsetSpace ~
34724 \InsetSpace ~
34725 \InsetSpace ~
34726 \InsetSpace ~
34727 \InsetSpace ~
34728 \InsetSpace ~
34729 \InsetSpace ~
34730 \InsetSpace ~
34731 \InsetSpace ~
34732 \InsetSpace ~
34733 \InsetSpace ~
34734 \InsetSpace ~
34735 \InsetSpace ~
34736 \InsetSpace ~
34737 \InsetSpace ~
34738 \InsetSpace ~
34739  95 ;\InsetSpace ~
34740  hob.c 17 
34741 \newline
34742 003D 85*04*08\InsetSpace ~
34743 \InsetSpace ~
34744 \InsetSpace ~
34745 \InsetSpace ~
34746 \InsetSpace ~
34747 \InsetSpace ~
34748 \InsetSpace ~
34749 \InsetSpace ~
34750 \InsetSpace ~
34751 \InsetSpace ~
34752 \InsetSpace ~
34753 \InsetSpace ~
34754
34755  96\InsetSpace ~
34756 \InsetSpace ~
34757 \InsetSpace ~
34758 \InsetSpace ~
34759 \InsetSpace ~
34760 \InsetSpace ~
34761 \InsetSpace ~
34762 \InsetSpace ~
34763  mov\InsetSpace ~
34764 \InsetSpace ~
34765  _foo_how1_1_1,(_glong + 2) 
34766 \newline
34767 0040 85*05*09\InsetSpace ~
34768 \InsetSpace ~
34769 \InsetSpace ~
34770 \InsetSpace ~
34771 \InsetSpace ~
34772 \InsetSpace ~
34773 \InsetSpace ~
34774 \InsetSpace ~
34775 \InsetSpace ~
34776 \InsetSpace ~
34777 \InsetSpace ~
34778 \InsetSpace ~
34779  97\InsetSpace ~
34780 \InsetSpace ~
34781 \InsetSpace ~
34782 \InsetSpace ~
34783 \InsetSpace ~
34784 \InsetSpace ~
34785 \InsetSpace ~
34786 \InsetSpace ~
34787  mov\InsetSpace ~
34788 \InsetSpace ~
34789  (_foo_how1_1_1 +
34790  1),(_glong + 3) 
34791 \newline
34792 0043 85*03*0A\InsetSpace ~
34793 \InsetSpace ~
34794 \InsetSpace ~
34795 \InsetSpace ~
34796 \InsetSpace ~
34797 \InsetSpace ~
34798 \InsetSpace ~
34799 \InsetSpace ~
34800 \InsetSpace ~
34801 \InsetSpace ~
34802 \InsetSpace ~
34803 \InsetSpace ~
34804  98\InsetSpace ~
34805 \InsetSpace ~
34806 \InsetSpace ~
34807 \InsetSpace ~
34808 \InsetSpace ~
34809 \InsetSpace ~
34810 \InsetSpace ~
34811 \InsetSpace ~
34812  mov\InsetSpace ~
34813 \InsetSpace ~
34814  _foo_how2_1_1,(_glong + 1) 
34815 \newline
34816 0046 85*04*0B\InsetSpace ~
34817 \InsetSpace ~
34818 \InsetSpace ~
34819 \InsetSpace ~
34820 \InsetSpace ~
34821 \InsetSpace ~
34822 \InsetSpace ~
34823 \InsetSpace ~
34824 \InsetSpace ~
34825 \InsetSpace ~
34826 \InsetSpace ~
34827 \InsetSpace ~
34828
34829  99\InsetSpace ~
34830 \InsetSpace ~
34831 \InsetSpace ~
34832 \InsetSpace ~
34833 \InsetSpace ~
34834 \InsetSpace ~
34835 \InsetSpace ~
34836 \InsetSpace ~
34837  mov\InsetSpace ~
34838 \InsetSpace ~
34839  (_foo_how2_1_1 + 1),(_glong + 2) 
34840 \end_layout
34841
34842 \begin_layout Standard
34843 Again, variations of these cases may 
34844 \emph on
34845 not
34846 \emph default
34847  be recognized.
34848  They are standard C expressions, so I heartily recommend these be the only
34849  way to get the higher order byte/word, (it is portable).
34850  Of course it will be recognized even if it is embedded in other expressions,
34851  e.g.:
34852 \end_layout
34853
34854 \begin_layout Verse
34855
34856 \family typewriter
34857 xyz = gint + ((gint >> 8) & 0xFF);
34858 \end_layout
34859
34860 \begin_layout Standard
34861 will still be recognized.
34862 \end_layout
34863
34864 \begin_layout Subsection
34865 Peephole Optimizer
34866 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
34867
34868 \end_inset
34869
34870
34871 \begin_inset LatexCommand \index{Peephole optimizer}
34872
34873 \end_inset
34874
34875
34876 \end_layout
34877
34878 \begin_layout Standard
34879 The compiler uses a rule based, pattern matching and re-writing mechanism
34880  for peep-hole optimization.
34881  It is inspired by 
34882 \emph on
34883 copt
34884 \emph default
34885  a peep-hole optimizer by Christopher W.
34886  Fraser (cwfraser\InsetSpace ~
34887 @\InsetSpace ~
34888 microsoft.com).
34889  A default set of rules are compiled into the compiler, additional rules
34890  may be added with the 
34891 \emph on
34892 -
34893 \begin_inset ERT
34894 status collapsed
34895
34896 \begin_layout Standard
34897
34898
34899 \backslash
34900 /
34901 \end_layout
34902
34903 \end_inset
34904
34905 -peep-file
34906 \begin_inset LatexCommand \index{-\/-peep-file}
34907
34908 \end_inset
34909
34910  <filename>
34911 \emph default
34912  option.
34913  The rule language is best illustrated with examples.
34914 \end_layout
34915
34916 \begin_layout Verse
34917
34918 \family typewriter
34919 replace { 
34920 \newline
34921 \InsetSpace ~
34922 \InsetSpace ~
34923 mov %1,a 
34924 \newline
34925 \InsetSpace ~
34926 \InsetSpace ~
34927 mov a,%1
34928 \newline
34929 } by {
34930 \newline
34931 \InsetSpace ~
34932 \InsetSpace ~
34933 mov %1,a
34934 \newline
34935 }
34936 \end_layout
34937
34938 \begin_layout Standard
34939 The above rule will change the following assembly
34940 \begin_inset LatexCommand \index{Assembler routines}
34941
34942 \end_inset
34943
34944  sequence:
34945 \end_layout
34946
34947 \begin_layout Verse
34948
34949 \family typewriter
34950 mov r1,a 
34951 \newline
34952 mov a,r1
34953 \end_layout
34954
34955 \begin_layout Standard
34956 to
34957 \end_layout
34958
34959 \begin_layout Verse
34960
34961 \family typewriter
34962 mov r1,a
34963 \end_layout
34964
34965 \begin_layout Standard
34966 Note: All occurrences of a 
34967 \emph on
34968 %n
34969 \emph default
34970  (pattern variable) must denote the same string.
34971  With the above rule, the assembly sequence:
34972 \end_layout
34973
34974 \begin_layout Verse
34975
34976 \family typewriter
34977 mov r1,a 
34978 \newline
34979 mov a,r2
34980 \end_layout
34981
34982 \begin_layout Standard
34983 will remain unmodified.
34984 \newline
34985
34986 \newline
34987 Other special case optimizations may be added by the
34988  user (via 
34989 \emph on
34990 -
34991 \begin_inset ERT
34992 status collapsed
34993
34994 \begin_layout Standard
34995
34996
34997 \backslash
34998 /
34999 \end_layout
35000
35001 \end_inset
35002
35003 -peep-file option
35004 \emph default
35005 ).
35006  E.g.
35007  some variants of the 8051 MCU
35008 \begin_inset LatexCommand \index{MCS51 variants}
35009
35010 \end_inset
35011
35012  allow only 
35013 \family typewriter
35014 ajmp
35015 \family default
35016  and 
35017 \family typewriter
35018 acall
35019 \family default
35020 .
35021  The following two rules will change all 
35022 \family typewriter
35023 ljmp
35024 \family default
35025  and 
35026 \family typewriter
35027 lcall
35028 \family default
35029  to 
35030 \family typewriter
35031 ajmp
35032 \family default
35033  and 
35034 \family typewriter
35035 acall
35036 \end_layout
35037
35038 \begin_layout Verse
35039
35040 \family typewriter
35041 replace { lcall %1 } by { acall %1 } 
35042 \newline
35043 replace { ljmp %1 } by { ajmp %1 }
35044 \end_layout
35045
35046 \begin_layout Standard
35047 The 
35048 \emph on
35049 inline-assembler code
35050 \emph default
35051  is also passed through the peep hole optimizer, thus the peephole optimizer
35052  can also be used as an assembly level macro expander.
35053  The rules themselves are MCU dependent whereas the rule language infra-structur
35054 e is MCU independent.
35055  Peephole optimization rules for other MCU can be easily programmed using
35056  the rule language.
35057 \newline
35058
35059 \newline
35060 The syntax for a rule is as follows:
35061 \end_layout
35062
35063 \begin_layout Verse
35064
35065 \family typewriter
35066 rule := replace [ restart ] '{' <assembly sequence> '
35067 \backslash
35068 n' 
35069 \newline
35070 \InsetSpace ~
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  '}' by '{' '
35085 \backslash
35086 n' 
35087 \newline
35088 \InsetSpace ~
35089  \InsetSpace ~
35090  \InsetSpace ~
35091  \InsetSpace ~
35092  \InsetSpace ~
35093  \InsetSpace ~
35094  \InsetSpace ~
35095  \InsetSpace ~
35096  \InsetSpace ~
35097  \InsetSpace ~
35098  \InsetSpace ~
35099  \InsetSpace ~
35100  \InsetSpace ~
35101  \InsetSpace ~
35102  \InsetSpace ~
35103  \InsetSpace ~
35104  <assembly sequence> '
35105 \backslash
35106 n' 
35107 \newline
35108 \InsetSpace ~
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  '}' [if <functionName> ] '
35123 \backslash
35124 n' 
35125 \end_layout
35126
35127 \begin_layout Standard
35128 <assembly sequence> := assembly instruction (each instruction including
35129  labels must be on a separate line).
35130 \newline
35131
35132 \newline
35133 The optimizer will apply to the rules
35134  one by one from the top in the sequence of their appearance, it will terminate
35135  when all rules are exhausted.
35136  If the 'restart' option is specified, then the optimizer will start matching
35137  the rules again from the top, this option for a rule is expensive (performance)
35138 , it is intended to be used in situations where a transformation will trigger
35139  the same rule again.
35140  An example of this (not a good one, it has side effects) is the following
35141  rule:
35142 \end_layout
35143
35144 \begin_layout Verse
35145
35146 \family typewriter
35147 replace restart { 
35148 \newline
35149 \InsetSpace ~
35150 \InsetSpace ~
35151 pop %1 
35152 \newline
35153 \InsetSpace ~
35154 \InsetSpace ~
35155 push %1 } by { 
35156 \newline
35157 \InsetSpace ~
35158 \InsetSpace ~
35159 ; nop 
35160 \newline
35161 }
35162 \end_layout
35163
35164 \begin_layout Standard
35165 Note that the replace pattern cannot be a blank, but can be a comment line.
35166  Without the 'restart' option only the innermost 'pop' 'push' pair would
35167  be eliminated, i.e.:
35168 \end_layout
35169
35170 \begin_layout Verse
35171
35172 \family typewriter
35173 pop ar1 
35174 \newline
35175 pop ar2 
35176 \newline
35177 push ar2 
35178 \newline
35179 push ar1
35180 \end_layout
35181
35182 \begin_layout Standard
35183 would result in:
35184 \end_layout
35185
35186 \begin_layout Verse
35187
35188 \family typewriter
35189 pop ar1 
35190 \newline
35191 ; nop 
35192 \newline
35193 push ar1
35194 \end_layout
35195
35196 \begin_layout Standard
35197
35198 \emph on
35199 with
35200 \emph default
35201  the restart option the rule will be applied again to the resulting code
35202  and then all the pop-push pairs will be eliminated to yield:
35203 \end_layout
35204
35205 \begin_layout Verse
35206
35207 \family typewriter
35208 ; nop 
35209 \newline
35210 ; nop
35211 \end_layout
35212
35213 \begin_layout Standard
35214 A conditional function can be attached to a rule.
35215  Attaching rules are somewhat more involved, let me illustrate this with
35216  an example.
35217 \end_layout
35218
35219 \begin_layout Verse
35220
35221 \family typewriter
35222 replace { 
35223 \newline
35224 \InsetSpace ~
35225  \InsetSpace ~
35226  \InsetSpace ~
35227 ljmp %5 
35228 \newline
35229 %2:
35230 \newline
35231 } by { 
35232 \newline
35233 \InsetSpace ~
35234  \InsetSpace ~
35235  \InsetSpace ~
35236 sjmp %5 
35237 \newline
35238 %2:
35239 \newline
35240 } if labelInRange
35241 \end_layout
35242
35243 \begin_layout Standard
35244 The optimizer does a look-up of a function name table defined in function
35245  
35246 \emph on
35247 callFuncByName
35248 \emph default
35249  in the source file SDCCpeeph.c, with the name 
35250 \emph on
35251 labelInRange
35252 \emph default
35253 .
35254  If it finds a corresponding entry the function is called.
35255  Note there can be no parameters specified for these functions, in this
35256  case the use of 
35257 \emph on
35258 %5
35259 \emph default
35260  is crucial, since the function 
35261 \emph on
35262 labelInRange
35263 \emph default
35264  expects to find the label in that particular variable (the hash table containin
35265 g the variable bindings is passed as a parameter).
35266  If you want to code more such functions, take a close look at the function
35267  labelInRange and the calling mechanism in source file SDCCpeeph.c.
35268  Currently implemented are 
35269 \emph on
35270 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
35271  24bitMode, portIsDS390, 24bitModeAndPortDS390 
35272 \emph default
35273 and
35274 \emph on
35275  notVolatile
35276 \emph default
35277 .
35278 \end_layout
35279
35280 \begin_layout Standard
35281 I know this whole thing is a little kludgey, but maybe some day we will
35282  have some better means.
35283  If you are looking at this file, you will see the default rules that are
35284  compiled into the compiler, you can add your own rules in the default set
35285  there if you get tired of specifying the -
35286 \begin_inset ERT
35287 status collapsed
35288
35289 \begin_layout Standard
35290
35291
35292 \backslash
35293 /
35294 \end_layout
35295
35296 \end_inset
35297
35298 -peep-file option.
35299 \end_layout
35300
35301 \begin_layout Section
35302 ANSI-Compliance
35303 \begin_inset LatexCommand \index{ANSI-compliance}
35304
35305 \end_inset
35306
35307
35308 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
35309
35310 \end_inset
35311
35312
35313 \end_layout
35314
35315 \begin_layout Standard
35316 The latest publically available version of the standard 
35317 \emph on
35318 ISO/IEC 9899 - Programming languages - C
35319 \emph default
35320  should be available at: 
35321 \begin_inset LatexCommand \url{http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899}
35322
35323 \end_inset
35324
35325 .
35326 \newline
35327
35328 \end_layout
35329
35330 \begin_layout Standard
35331 Deviations from the compliance:
35332 \end_layout
35333
35334 \begin_layout Itemize
35335 functions are not reentrant
35336 \begin_inset LatexCommand \index{reentrant}
35337
35338 \end_inset
35339
35340  unless explicitly declared as such or the 
35341 \series bold
35342 -
35343 \begin_inset ERT
35344 status collapsed
35345
35346 \begin_layout Standard
35347
35348
35349 \backslash
35350 /
35351 \end_layout
35352
35353 \end_inset
35354
35355 -stack-auto
35356 \begin_inset LatexCommand \index{-\/-stack-auto}
35357
35358 \end_inset
35359
35360
35361 \series default
35362  command line option is specified.
35363 \end_layout
35364
35365 \begin_layout Itemize
35366 structures
35367 \begin_inset LatexCommand \index{struct}
35368
35369 \end_inset
35370
35371  and unions
35372 \begin_inset LatexCommand \index{union}
35373
35374 \end_inset
35375
35376  cannot be assigned values directly, cannot be passed as function parameters
35377  or assigned to each other and cannot be a return value
35378 \begin_inset LatexCommand \index{return value}
35379
35380 \end_inset
35381
35382  from a function, e.g.:
35383 \end_layout
35384
35385 \begin_deeper
35386 \begin_layout Verse
35387
35388 \family typewriter
35389 struct s { ...
35390  }; 
35391 \newline
35392 struct s s1, s2; 
35393 \newline
35394 foo() 
35395 \newline
35396
35397 \newline
35398 \InsetSpace ~
35399 \InsetSpace ~
35400 \InsetSpace ~
35401 \InsetSpace ~
35402 ...
35403  
35404 \newline
35405 \InsetSpace ~
35406 \InsetSpace ~
35407 \InsetSpace ~
35408 \InsetSpace ~
35409 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
35410 \newline
35411 \InsetSpace ~
35412 \InsetSpace ~
35413 \InsetSpace ~
35414 \InsetSpace ~
35415 ...
35416  
35417 \newline
35418 }
35419 \newline
35420
35421 \series bold
35422 struct
35423 \series default
35424  s foo1 (
35425 \series bold
35426 struct
35427 \series default
35428  s parms) /* invalid in SDCC although allowed in ANSI */
35429 \newline
35430
35431 \newline
35432 \InsetSpace ~
35433 \InsetSpace ~
35434 \InsetSpace ~
35435 \InsetSpace ~
35436 struct s rets;
35437  
35438 \newline
35439 \InsetSpace ~
35440 \InsetSpace ~
35441 \InsetSpace ~
35442 \InsetSpace ~
35443 ...
35444  
35445 \newline
35446 \InsetSpace ~
35447 \InsetSpace ~
35448 \InsetSpace ~
35449 \InsetSpace ~
35450 return rets; /* is invalid in SDCC although allowed in ANSI */ 
35451 \newline
35452 }
35453 \end_layout
35454
35455 \end_deeper
35456 \begin_layout Itemize
35457 initialization of structure arrays must be fully braced.
35458 \end_layout
35459
35460 \begin_deeper
35461 \begin_layout Verse
35462
35463 \family typewriter
35464 struct s { char x } a[] = {1, 2};\InsetSpace ~
35465 \InsetSpace ~
35466 \InsetSpace ~
35467 \InsetSpace ~
35468 \InsetSpace ~
35469 /* invalid in SDCC */
35470 \newline
35471 struct s { char x
35472  } a[] = {{1}, {2}}; /* OK */
35473 \end_layout
35474
35475 \end_deeper
35476 \begin_layout Itemize
35477 'long long
35478 \begin_inset LatexCommand \index{long long (not supported)}
35479
35480 \end_inset
35481
35482 ' (64 bit integers
35483 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
35484
35485 \end_inset
35486
35487 ) not supported.
35488 \end_layout
35489
35490 \begin_layout Itemize
35491 'double
35492 \begin_inset LatexCommand \index{double (not supported)}
35493
35494 \end_inset
35495
35496 ' precision floating point 
35497 \begin_inset LatexCommand \index{Floating point support}
35498
35499 \end_inset
35500
35501 not supported.
35502 \end_layout
35503
35504 \begin_layout Itemize
35505 Old K&R style
35506 \begin_inset LatexCommand \index{K\&R style}
35507
35508 \end_inset
35509
35510  function declarations are NOT allowed.
35511 \end_layout
35512
35513 \begin_deeper
35514 \begin_layout Verse
35515
35516 \family typewriter
35517 foo(i,j) /* this old style of function declarations */ 
35518 \newline
35519 int i,j; /* are valid
35520  in ANSI but not valid in SDCC */ 
35521 \newline
35522
35523 \newline
35524 \InsetSpace ~
35525 \InsetSpace ~
35526 \InsetSpace ~
35527 \InsetSpace ~
35528 ...
35529  
35530 \newline
35531 }
35532 \end_layout
35533
35534 \end_deeper
35535 \begin_layout Itemize
35536 Most enhancements in C99 are not supported, f.e.:
35537 \end_layout
35538
35539 \begin_deeper
35540 \begin_layout Verse
35541
35542 \family typewriter
35543 \series bold
35544 inline
35545 \begin_inset LatexCommand \index{inline (not supported)}
35546
35547 \end_inset
35548
35549
35550 \series default
35551  int increment (int a) { return a+1; } /* is invalid in SDCC although allowed
35552  in C99.
35553  An empty define 
35554 \emph on
35555 #define inline
35556 \emph default
35557  can be used as a work around */
35558 \newline
35559
35560 \newline
35561 for (
35562 \series bold
35563 int
35564 \series default
35565  i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
35566 \end_layout
35567
35568 \end_deeper
35569 \begin_layout Itemize
35570 Certain words that are valid identifiers in the standard may be reserved
35571  words in SDCC unless the 
35572 \series bold
35573 -
35574 \begin_inset ERT
35575 status collapsed
35576
35577 \begin_layout Standard
35578
35579
35580 \backslash
35581 /
35582 \end_layout
35583
35584 \end_inset
35585
35586 -std-c89
35587 \begin_inset LatexCommand \index{-\/-std-c89}
35588
35589 \end_inset
35590
35591  or -
35592 \begin_inset ERT
35593 status collapsed
35594
35595 \begin_layout Standard
35596
35597
35598 \backslash
35599 /
35600 \end_layout
35601
35602 \end_inset
35603
35604 -std-c99
35605 \begin_inset LatexCommand \index{-\/-std-c99}
35606
35607 \end_inset
35608
35609
35610 \series default
35611  command line options are used.
35612  These may include (depending on the selected processor): 'at', 'banked',
35613  'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
35614 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
35615  'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
35616  '_naked'.
35617  Compliant equivalents of these keywords are always available in a form
35618  that begin with two underscores
35619 \begin_inset LatexCommand \index{\_\_ (prefix for extended keywords)}
35620
35621 \end_inset
35622
35623 , f.e.
35624  '__data' instead of 'data'.
35625 \end_layout
35626
35627 \begin_layout Section
35628 Cyclomatic Complexity
35629 \begin_inset LatexCommand \index{Cyclomatic complexity}
35630
35631 \end_inset
35632
35633
35634 \end_layout
35635
35636 \begin_layout Standard
35637 Cyclomatic complexity of a function is defined as the number of independent
35638  paths the program can take during execution of the function.
35639  This is an important number since it defines the number test cases you
35640  have to generate to validate the function.
35641  The accepted industry standard for complexity number is 10, if the cyclomatic
35642  complexity reported by SDCC exceeds 10 you should think about simplification
35643  of the function logic.
35644  Note that the complexity level is not related to the number of lines of
35645  code in a function.
35646  Large functions can have low complexity, and small functions can have large
35647  complexity levels.
35648  
35649 \newline
35650
35651 \newline
35652 SDCC uses the following formula to compute the complexity:
35653 \newline
35654
35655 \end_layout
35656
35657 \begin_layout Standard
35658 complexity = (number of edges in control flow graph) - (number of nodes
35659  in control flow graph) + 2;
35660 \newline
35661
35662 \newline
35663 Having said that the industry standard is 10,
35664  you should be aware that in some cases it be may unavoidable to have a
35665  complexity level of less than 10.
35666  For example if you have switch statement with more than 10 case labels,
35667  each case label adds one to the complexity level.
35668  The complexity level is by no means an absolute measure of the algorithmic
35669  complexity of the function, it does however provide a good starting point
35670  for which functions you might look at for further optimization.
35671 \end_layout
35672
35673 \begin_layout Section
35674 Retargetting for other Processors
35675 \end_layout
35676
35677 \begin_layout Standard
35678 The issues for retargetting the compiler are far too numerous to be covered
35679  by this document.
35680  What follows is a brief description of each of the seven phases of the
35681  compiler and its MCU dependency.
35682 \end_layout
35683
35684 \begin_layout Itemize
35685 Parsing the source and building the annotated parse tree.
35686  This phase is largely MCU independent (except for the language extensions).
35687  Syntax & semantic checks are also done in this phase, along with some initial
35688  optimizations like back patching labels and the pattern matching optimizations
35689  like bit-rotation etc.
35690 \end_layout
35691
35692 \begin_layout Itemize
35693 The second phase involves generating an intermediate code which can be easy
35694  manipulated during the later phases.
35695  This phase is entirely MCU independent.
35696  The intermediate code generation assumes the target machine has unlimited
35697  number of registers, and designates them with the name iTemp.
35698  The compiler can be made to dump a human readable form of the code generated
35699  by using the -
35700 \begin_inset ERT
35701 status collapsed
35702
35703 \begin_layout Standard
35704
35705
35706 \backslash
35707 /
35708 \end_layout
35709
35710 \end_inset
35711
35712 -dumpraw option.
35713 \end_layout
35714
35715 \begin_layout Itemize
35716 This phase does the bulk of the standard optimizations and is also MCU independe
35717 nt.
35718  This phase can be broken down into several sub-phases:
35719 \newline
35720
35721 \newline
35722 Break down intermediate
35723  code (iCode) into basic blocks.
35724 \newline
35725 Do control flow & data flow analysis on the
35726  basic blocks.
35727 \newline
35728 Do local common subexpression elimination, then global subexpressio
35729 n elimination
35730 \newline
35731 Dead code elimination
35732 \newline
35733 Loop optimizations
35734 \newline
35735 If loop optimizations
35736  caused any changes then do 'global subexpression elimination' and 'dead
35737  code elimination' again.
35738 \end_layout
35739
35740 \begin_layout Itemize
35741 This phase determines the live-ranges; by live range I mean those iTemp
35742  variables defined by the compiler that still survive after all the optimization
35743 s.
35744  Live range analysis
35745 \begin_inset LatexCommand \index{Live range analysis}
35746
35747 \end_inset
35748
35749  is essential for register allocation, since these computation determines
35750  which of these iTemps will be assigned to registers, and for how long.
35751 \end_layout
35752
35753 \begin_layout Itemize
35754 Phase five is register allocation.
35755  There are two parts to this process.
35756 \newline
35757
35758 \newline
35759 The first part I call 'register packing'
35760  (for lack of a better term).
35761  In this case several MCU specific expression folding is done to reduce
35762  register pressure.
35763 \newline
35764
35765 \newline
35766 The second part is more MCU independent and deals with
35767  allocating registers to the remaining live ranges.
35768  A lot of MCU specific code does creep into this phase because of the limited
35769  number of index registers available in the 8051.
35770 \end_layout
35771
35772 \begin_layout Itemize
35773 The Code generation phase is (unhappily), entirely MCU dependent and very
35774  little (if any at all) of this code can be reused for other MCU.
35775  However the scheme for allocating a homogenized assembler operand for each
35776  iCode operand may be reused.
35777 \end_layout
35778
35779 \begin_layout Itemize
35780 As mentioned in the optimization section the peep-hole optimizer is rule
35781  based system, which can reprogrammed for other MCUs.
35782 \end_layout
35783
35784 \begin_layout Standard
35785 More information is available in a wiki
35786 \begin_inset LatexCommand \index{wiki}
35787
35788 \end_inset
35789
35790  (preliminary link 
35791 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/release_wiki/index.php?page=SDCC+internals+and+porting}
35792
35793 \end_inset
35794
35795 ) and in the thread 
35796 \begin_inset LatexCommand \url{http://sf.net/mailarchive/message.php?msg_id=13954144}
35797
35798 \end_inset
35799
35800  .
35801 \end_layout
35802
35803 \begin_layout Chapter
35804 Compiler internals
35805 \begin_inset LatexCommand \index{Compiler internals}
35806
35807 \end_inset
35808
35809
35810 \end_layout
35811
35812 \begin_layout Section
35813 The anatomy of the compiler
35814 \begin_inset LatexCommand \label{sub:The-anatomy-of}
35815
35816 \end_inset
35817
35818
35819 \end_layout
35820
35821 \begin_layout Standard
35822
35823 \shape italic
35824 This is an excerpt from an article published in Circuit Cellar Magazine
35825  in 
35826 \series bold
35827 August 2000
35828 \series default
35829 .
35830  It's a little outdated (the compiler is much more efficient now and user/develo
35831 per friendly), but pretty well exposes the guts of it all.
35832 \shape default
35833
35834 \newline
35835
35836 \newline
35837 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
35838  It is fairly easy to retarget for other 8-bit MCU.
35839  Here we take a look at some of the internals of the compiler.
35840  
35841 \end_layout
35842
35843 \begin_layout Paragraph*
35844 Parsing
35845 \begin_inset LatexCommand \index{Parsing}
35846
35847 \end_inset
35848
35849  
35850 \end_layout
35851
35852 \begin_layout Standard
35853 Parsing the input source file and creating an AST (Annotated Syntax Tree
35854 \begin_inset LatexCommand \index{Annotated syntax tree}
35855
35856 \end_inset
35857
35858 ).
35859  This phase also involves propagating types (annotating each node of the
35860  parse tree with type information) and semantic analysis.
35861  There are some MCU specific parsing rules.
35862  For example the storage classes, the extended storage classes are MCU specific
35863  while there may be a xdata storage class for 8051 there is no such storage
35864  class for z80 or Atmel AVR.
35865  SDCC allows MCU specific storage class extensions, i.e.
35866  xdata will be treated as a storage class specifier when parsing 8051 C
35867  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
35868  C code.
35869 \end_layout
35870
35871 \begin_layout Paragraph*
35872 Generating iCode
35873 \begin_inset LatexCommand \index{iCode}
35874
35875 \end_inset
35876
35877
35878 \end_layout
35879
35880 \begin_layout Standard
35881 Intermediate code generation.
35882  In this phase the AST is broken down into three-operand form (iCode).
35883  These three operand forms are represented as doubly linked lists.
35884  ICode is the term given to the intermediate form generated by the compiler.
35885  ICode example section shows some examples of iCode generated for some simple
35886  C source functions.
35887 \end_layout
35888
35889 \begin_layout Paragraph*
35890 Optimizations
35891 \begin_inset LatexCommand \index{Optimizations}
35892
35893 \end_inset
35894
35895 .
35896 \end_layout
35897
35898 \begin_layout Standard
35899 Bulk of the target independent optimizations is performed in this phase.
35900  The optimizations include constant propagation, common sub-expression eliminati
35901 on, loop invariant code movement, strength reduction of loop induction variables
35902  and dead-code elimination.
35903 \end_layout
35904
35905 \begin_layout Paragraph*
35906 Live range analysis
35907 \begin_inset LatexCommand \index{Live range analysis}
35908
35909 \end_inset
35910
35911
35912 \end_layout
35913
35914 \begin_layout Standard
35915 During intermediate code generation phase, the compiler assumes the target
35916  machine has infinite number of registers and generates a lot of temporary
35917  variables.
35918  The live range computation determines the lifetime of each of these compiler-ge
35919 nerated temporaries.
35920  A picture speaks a thousand words.
35921  ICode example sections show the live range annotations for each of the
35922  operand.
35923  It is important to note here, each iCode is assigned a number in the order
35924  of its execution in the function.
35925  The live ranges are computed in terms of these numbers.
35926  The from number is the number of the iCode which first defines the operand
35927  and the to number signifies the iCode which uses this operand last.
35928 \end_layout
35929
35930 \begin_layout Paragraph*
35931 Register Allocation
35932 \begin_inset LatexCommand \index{Register allocation}
35933
35934 \end_inset
35935
35936
35937 \end_layout
35938
35939 \begin_layout Standard
35940 The register allocation determines the type and number of registers needed
35941  by each operand.
35942  In most MCUs only a few registers can be used for indirect addressing.
35943  In case of 8051 for example the registers R0 & R1 can be used to indirectly
35944  address the internal ram and DPTR to indirectly address the external ram.
35945  The compiler will try to allocate the appropriate register to pointer variables
35946  if it can.
35947  ICode example section shows the operands annotated with the registers assigned
35948  to them.
35949  The compiler will try to keep operands in registers as much as possible;
35950  there are several schemes the compiler uses to do achieve this.
35951  When the compiler runs out of registers the compiler will check to see
35952  if there are any live operands which is not used or defined in the current
35953  basic block being processed, if there are any found then it will push that
35954  operand and use the registers in this block, the operand will then be popped
35955  at the end of the basic block.
35956  
35957 \end_layout
35958
35959 \begin_layout Standard
35960 There are other MCU specific considerations in this phase.
35961  Some MCUs have an accumulator; very short-lived operands could be assigned
35962  to the accumulator instead of a general-purpose register.
35963 \end_layout
35964
35965 \begin_layout Paragraph*
35966 Code generation
35967 \end_layout
35968
35969 \begin_layout Standard
35970 Figure II gives a table of iCode
35971 \begin_inset LatexCommand \index{iCode}
35972
35973 \end_inset
35974
35975  operations supported by the compiler.
35976  The code generation involves translating these operations into corresponding
35977  assembly code for the processor.
35978  This sounds overly simple but that is the essence of code generation.
35979  Some of the iCode operations are generated on a MCU specific manner for
35980  example, the z80 port does not use registers to pass parameters so the
35981  SEND and RECV iCode operations will not be generated, and it also does
35982  not support JUMPTABLES.
35983  
35984 \newline
35985
35986 \end_layout
35987
35988 \begin_layout Standard
35989
35990 \size footnotesize
35991 Figure II 
35992 \begin_inset Tabular
35993 <lyxtabular version="3" rows="39" columns="4">
35994 <features islongtable="true" headBottomDL="true">
35995 <column alignment="block" valignment="top" leftline="true" width="13col%">
35996 <column alignment="left" valignment="top" leftline="true" width="13col%">
35997 <column alignment="block" valignment="top" leftline="true" width="22col%">
35998 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
35999 <row topline="true" bottomline="true" endhead="true">
36000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36001 \begin_inset Text
36002
36003 \begin_layout Standard
36004
36005 \series bold
36006 iCode
36007 \series default
36008
36009 \begin_inset LatexCommand \index{iCode}
36010
36011 \end_inset
36012
36013
36014 \end_layout
36015
36016 \end_inset
36017 </cell>
36018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36019 \begin_inset Text
36020
36021 \begin_layout Standard
36022
36023 \series bold
36024 Operands
36025 \end_layout
36026
36027 \end_inset
36028 </cell>
36029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36030 \begin_inset Text
36031
36032 \begin_layout Standard
36033
36034 \series bold
36035 Description
36036 \end_layout
36037
36038 \end_inset
36039 </cell>
36040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36041 \begin_inset Text
36042
36043 \begin_layout Standard
36044
36045 \series bold
36046 C Equivalent
36047 \end_layout
36048
36049 \end_inset
36050 </cell>
36051 </row>
36052 <row topline="true">
36053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36054 \begin_inset Text
36055
36056 \begin_layout Standard
36057
36058 \size footnotesize
36059 '!'
36060 \end_layout
36061
36062 \end_inset
36063 </cell>
36064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36065 \begin_inset Text
36066
36067 \begin_layout Standard
36068
36069 \size footnotesize
36070 IC_LEFT() IC_RESULT()
36071 \end_layout
36072
36073 \end_inset
36074 </cell>
36075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36076 \begin_inset Text
36077
36078 \begin_layout Standard
36079
36080 \size footnotesize
36081 NOT operation 
36082 \end_layout
36083
36084 \end_inset
36085 </cell>
36086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36087 \begin_inset Text
36088
36089 \begin_layout Standard
36090
36091 \size footnotesize
36092 IC_RESULT = ! IC_LEFT;
36093 \end_layout
36094
36095 \end_inset
36096 </cell>
36097 </row>
36098 <row topline="true">
36099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36100 \begin_inset Text
36101
36102 \begin_layout Standard
36103
36104 \size footnotesize
36105 '~'
36106 \end_layout
36107
36108 \end_inset
36109 </cell>
36110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36111 \begin_inset Text
36112
36113 \begin_layout Standard
36114
36115 \size footnotesize
36116 IC_LEFT() IC_RESULT()
36117 \end_layout
36118
36119 \end_inset
36120 </cell>
36121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36122 \begin_inset Text
36123
36124 \begin_layout Standard
36125
36126 \size footnotesize
36127 Bitwise complement of 
36128 \end_layout
36129
36130 \end_inset
36131 </cell>
36132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36133 \begin_inset Text
36134
36135 \begin_layout Standard
36136
36137 \size footnotesize
36138 IC_RESULT = ~IC_LEFT;
36139 \end_layout
36140
36141 \end_inset
36142 </cell>
36143 </row>
36144 <row topline="true">
36145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36146 \begin_inset Text
36147
36148 \begin_layout Standard
36149
36150 \size footnotesize
36151 RRC
36152 \end_layout
36153
36154 \end_inset
36155 </cell>
36156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36157 \begin_inset Text
36158
36159 \begin_layout Standard
36160
36161 \size footnotesize
36162 IC_LEFT() IC_RESULT()
36163 \end_layout
36164
36165 \end_inset
36166 </cell>
36167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36168 \begin_inset Text
36169
36170 \begin_layout Standard
36171
36172 \size footnotesize
36173 Rotate right with carry
36174 \end_layout
36175
36176 \end_inset
36177 </cell>
36178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36179 \begin_inset Text
36180
36181 \begin_layout Standard
36182
36183 \size footnotesize
36184 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
36185 \end_layout
36186
36187 \end_inset
36188 </cell>
36189 </row>
36190 <row topline="true">
36191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36192 \begin_inset Text
36193
36194 \begin_layout Standard
36195
36196 \size footnotesize
36197 RLC
36198 \end_layout
36199
36200 \end_inset
36201 </cell>
36202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36203 \begin_inset Text
36204
36205 \begin_layout Standard
36206
36207 \size footnotesize
36208 IC_LEFT() IC_RESULT()
36209 \end_layout
36210
36211 \end_inset
36212 </cell>
36213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36214 \begin_inset Text
36215
36216 \begin_layout Standard
36217
36218 \size footnotesize
36219 Rotate left with carry
36220 \end_layout
36221
36222 \end_inset
36223 </cell>
36224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36225 \begin_inset Text
36226
36227 \begin_layout Standard
36228
36229 \size footnotesize
36230 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
36231 \end_layout
36232
36233 \end_inset
36234 </cell>
36235 </row>
36236 <row topline="true">
36237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36238 \begin_inset Text
36239
36240 \begin_layout Standard
36241
36242 \size footnotesize
36243 GETHBIT
36244 \end_layout
36245
36246 \end_inset
36247 </cell>
36248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36249 \begin_inset Text
36250
36251 \begin_layout Standard
36252
36253 \size footnotesize
36254 IC_LEFT() IC_RESULT()
36255 \end_layout
36256
36257 \end_inset
36258 </cell>
36259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36260 \begin_inset Text
36261
36262 \begin_layout Standard
36263
36264 \size footnotesize
36265 Get the highest order bit of IC_LEFT
36266 \end_layout
36267
36268 \end_inset
36269 </cell>
36270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36271 \begin_inset Text
36272
36273 \begin_layout Standard
36274
36275 \size footnotesize
36276 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
36277 \end_layout
36278
36279 \end_inset
36280 </cell>
36281 </row>
36282 <row topline="true">
36283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36284 \begin_inset Text
36285
36286 \begin_layout Standard
36287
36288 \size footnotesize
36289 UNARYMINUS
36290 \end_layout
36291
36292 \end_inset
36293 </cell>
36294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36295 \begin_inset Text
36296
36297 \begin_layout Standard
36298
36299 \size footnotesize
36300 IC_LEFT() IC_RESULT()
36301 \end_layout
36302
36303 \end_inset
36304 </cell>
36305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36306 \begin_inset Text
36307
36308 \begin_layout Standard
36309
36310 \size footnotesize
36311 Unary minus
36312 \end_layout
36313
36314 \end_inset
36315 </cell>
36316 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36317 \begin_inset Text
36318
36319 \begin_layout Standard
36320
36321 \size footnotesize
36322 IC_RESULT = - IC_LEFT;
36323 \end_layout
36324
36325 \end_inset
36326 </cell>
36327 </row>
36328 <row topline="true">
36329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36330 \begin_inset Text
36331
36332 \begin_layout Standard
36333
36334 \size footnotesize
36335 IPUSH
36336 \end_layout
36337
36338 \end_inset
36339 </cell>
36340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36341 \begin_inset Text
36342
36343 \begin_layout Standard
36344
36345 \size footnotesize
36346 IC_LEFT()
36347 \end_layout
36348
36349 \end_inset
36350 </cell>
36351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36352 \begin_inset Text
36353
36354 \begin_layout Standard
36355
36356 \size footnotesize
36357 Push the operand into stack
36358 \end_layout
36359
36360 \end_inset
36361 </cell>
36362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36363 \begin_inset Text
36364
36365 \begin_layout Standard
36366
36367 \size footnotesize
36368 NONE
36369 \end_layout
36370
36371 \end_inset
36372 </cell>
36373 </row>
36374 <row topline="true">
36375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36376 \begin_inset Text
36377
36378 \begin_layout Standard
36379
36380 \size footnotesize
36381 IPOP
36382 \end_layout
36383
36384 \end_inset
36385 </cell>
36386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36387 \begin_inset Text
36388
36389 \begin_layout Standard
36390
36391 \size footnotesize
36392 IC_LEFT()
36393 \end_layout
36394
36395 \end_inset
36396 </cell>
36397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36398 \begin_inset Text
36399
36400 \begin_layout Standard
36401
36402 \size footnotesize
36403 Pop the operand from the stack 
36404 \end_layout
36405
36406 \end_inset
36407 </cell>
36408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36409 \begin_inset Text
36410
36411 \begin_layout Standard
36412
36413 \size footnotesize
36414 NONE
36415 \end_layout
36416
36417 \end_inset
36418 </cell>
36419 </row>
36420 <row topline="true">
36421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36422 \begin_inset Text
36423
36424 \begin_layout Standard
36425
36426 \size footnotesize
36427 CALL
36428 \end_layout
36429
36430 \end_inset
36431 </cell>
36432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36433 \begin_inset Text
36434
36435 \begin_layout Standard
36436
36437 \size footnotesize
36438 IC_LEFT() IC_RESULT()
36439 \end_layout
36440
36441 \end_inset
36442 </cell>
36443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36444 \begin_inset Text
36445
36446 \begin_layout Standard
36447
36448 \size footnotesize
36449 Call the function represented by IC_LEFT 
36450 \end_layout
36451
36452 \end_inset
36453 </cell>
36454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36455 \begin_inset Text
36456
36457 \begin_layout Standard
36458
36459 \size footnotesize
36460 IC_RESULT = IC_LEFT();
36461 \end_layout
36462
36463 \end_inset
36464 </cell>
36465 </row>
36466 <row topline="true">
36467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36468 \begin_inset Text
36469
36470 \begin_layout Standard
36471
36472 \size footnotesize
36473 PCALL
36474 \end_layout
36475
36476 \end_inset
36477 </cell>
36478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36479 \begin_inset Text
36480
36481 \begin_layout Standard
36482
36483 \size footnotesize
36484 IC_LEFT() IC_RESULT()
36485 \end_layout
36486
36487 \end_inset
36488 </cell>
36489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36490 \begin_inset Text
36491
36492 \begin_layout Standard
36493
36494 \size footnotesize
36495 Call via function pointer
36496 \end_layout
36497
36498 \end_inset
36499 </cell>
36500 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36501 \begin_inset Text
36502
36503 \begin_layout Standard
36504
36505 \size footnotesize
36506 IC_RESULT = (*IC_LEFT)();
36507 \end_layout
36508
36509 \end_inset
36510 </cell>
36511 </row>
36512 <row topline="true">
36513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36514 \begin_inset Text
36515
36516 \begin_layout Standard
36517
36518 \size footnotesize
36519 RETURN
36520 \end_layout
36521
36522 \end_inset
36523 </cell>
36524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36525 \begin_inset Text
36526
36527 \begin_layout Standard
36528
36529 \size footnotesize
36530 IC_LEFT()
36531 \end_layout
36532
36533 \end_inset
36534 </cell>
36535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36536 \begin_inset Text
36537
36538 \begin_layout Standard
36539
36540 \size footnotesize
36541 Return the value in operand IC_LEFT 
36542 \end_layout
36543
36544 \end_inset
36545 </cell>
36546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36547 \begin_inset Text
36548
36549 \begin_layout Standard
36550
36551 \size footnotesize
36552 return IC_LEFT;
36553 \end_layout
36554
36555 \end_inset
36556 </cell>
36557 </row>
36558 <row topline="true">
36559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36560 \begin_inset Text
36561
36562 \begin_layout Standard
36563
36564 \size footnotesize
36565 LABEL
36566 \end_layout
36567
36568 \end_inset
36569 </cell>
36570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36571 \begin_inset Text
36572
36573 \begin_layout Standard
36574
36575 \size footnotesize
36576 IC_LABEL() 
36577 \end_layout
36578
36579 \end_inset
36580 </cell>
36581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36582 \begin_inset Text
36583
36584 \begin_layout Standard
36585
36586 \size footnotesize
36587 Label
36588 \end_layout
36589
36590 \end_inset
36591 </cell>
36592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36593 \begin_inset Text
36594
36595 \begin_layout Standard
36596
36597 \size footnotesize
36598 IC_LABEL:
36599 \end_layout
36600
36601 \end_inset
36602 </cell>
36603 </row>
36604 <row topline="true">
36605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36606 \begin_inset Text
36607
36608 \begin_layout Standard
36609
36610 \size footnotesize
36611 GOTO
36612 \end_layout
36613
36614 \end_inset
36615 </cell>
36616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36617 \begin_inset Text
36618
36619 \begin_layout Standard
36620
36621 \size footnotesize
36622 IC_LABEL() 
36623 \end_layout
36624
36625 \end_inset
36626 </cell>
36627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36628 \begin_inset Text
36629
36630 \begin_layout Standard
36631
36632 \size footnotesize
36633 Goto label
36634 \end_layout
36635
36636 \end_inset
36637 </cell>
36638 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36639 \begin_inset Text
36640
36641 \begin_layout Standard
36642
36643 \size footnotesize
36644 goto IC_LABEL();
36645 \end_layout
36646
36647 \end_inset
36648 </cell>
36649 </row>
36650 <row topline="true">
36651 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36652 \begin_inset Text
36653
36654 \begin_layout Standard
36655
36656 \size footnotesize
36657 '+'
36658 \end_layout
36659
36660 \end_inset
36661 </cell>
36662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36663 \begin_inset Text
36664
36665 \begin_layout Standard
36666
36667 \size footnotesize
36668 IC_LEFT() IC_RIGHT() IC_RESULT()
36669 \end_layout
36670
36671 \end_inset
36672 </cell>
36673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36674 \begin_inset Text
36675
36676 \begin_layout Standard
36677
36678 \size footnotesize
36679 Addition
36680 \end_layout
36681
36682 \end_inset
36683 </cell>
36684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36685 \begin_inset Text
36686
36687 \begin_layout Standard
36688
36689 \size footnotesize
36690 IC_RESULT = IC_LEFT + IC_RIGHT
36691 \end_layout
36692
36693 \end_inset
36694 </cell>
36695 </row>
36696 <row topline="true">
36697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36698 \begin_inset Text
36699
36700 \begin_layout Standard
36701
36702 \size footnotesize
36703 '-'
36704 \end_layout
36705
36706 \end_inset
36707 </cell>
36708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36709 \begin_inset Text
36710
36711 \begin_layout Standard
36712
36713 \size footnotesize
36714 IC_LEFT() IC_RIGHT() IC_RESULT()
36715 \end_layout
36716
36717 \end_inset
36718 </cell>
36719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36720 \begin_inset Text
36721
36722 \begin_layout Standard
36723
36724 \size footnotesize
36725 Subtraction
36726 \end_layout
36727
36728 \end_inset
36729 </cell>
36730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36731 \begin_inset Text
36732
36733 \begin_layout Standard
36734
36735 \size footnotesize
36736 IC_RESULT = IC_LEFT - IC_RIGHT 
36737 \end_layout
36738
36739 \end_inset
36740 </cell>
36741 </row>
36742 <row topline="true">
36743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36744 \begin_inset Text
36745
36746 \begin_layout Standard
36747
36748 \size footnotesize
36749 '*'
36750 \end_layout
36751
36752 \end_inset
36753 </cell>
36754 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36755 \begin_inset Text
36756
36757 \begin_layout Standard
36758
36759 \size footnotesize
36760 IC_LEFT() IC_RIGHT() IC_RESULT()
36761 \end_layout
36762
36763 \end_inset
36764 </cell>
36765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36766 \begin_inset Text
36767
36768 \begin_layout Standard
36769
36770 \size footnotesize
36771 Multiplication 
36772 \end_layout
36773
36774 \end_inset
36775 </cell>
36776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36777 \begin_inset Text
36778
36779 \begin_layout Standard
36780
36781 \size footnotesize
36782 IC_RESULT = IC_LEFT * IC_RIGHT;
36783 \end_layout
36784
36785 \end_inset
36786 </cell>
36787 </row>
36788 <row topline="true">
36789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36790 \begin_inset Text
36791
36792 \begin_layout Standard
36793
36794 \size footnotesize
36795 '/'
36796 \end_layout
36797
36798 \end_inset
36799 </cell>
36800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36801 \begin_inset Text
36802
36803 \begin_layout Standard
36804
36805 \size footnotesize
36806 IC_LEFT() IC_RIGHT() IC_RESULT()
36807 \end_layout
36808
36809 \end_inset
36810 </cell>
36811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36812 \begin_inset Text
36813
36814 \begin_layout Standard
36815
36816 \size footnotesize
36817 Division
36818 \end_layout
36819
36820 \end_inset
36821 </cell>
36822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36823 \begin_inset Text
36824
36825 \begin_layout Standard
36826
36827 \size footnotesize
36828 IC_RESULT = IC_LEFT / IC_RIGHT;
36829 \end_layout
36830
36831 \end_inset
36832 </cell>
36833 </row>
36834 <row topline="true">
36835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36836 \begin_inset Text
36837
36838 \begin_layout Standard
36839
36840 \size footnotesize
36841 '%'
36842 \end_layout
36843
36844 \end_inset
36845 </cell>
36846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36847 \begin_inset Text
36848
36849 \begin_layout Standard
36850
36851 \size footnotesize
36852 IC_LEFT() IC_RIGHT() IC_RESULT()
36853 \end_layout
36854
36855 \end_inset
36856 </cell>
36857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36858 \begin_inset Text
36859
36860 \begin_layout Standard
36861
36862 \size footnotesize
36863 Modulus
36864 \end_layout
36865
36866 \end_inset
36867 </cell>
36868 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36869 \begin_inset Text
36870
36871 \begin_layout Standard
36872
36873 \size footnotesize
36874 IC_RESULT = IC_LEFT % IC_RIGHT;
36875 \end_layout
36876
36877 \end_inset
36878 </cell>
36879 </row>
36880 <row topline="true">
36881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36882 \begin_inset Text
36883
36884 \begin_layout Standard
36885
36886 \size footnotesize
36887 '<'
36888 \end_layout
36889
36890 \end_inset
36891 </cell>
36892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36893 \begin_inset Text
36894
36895 \begin_layout Standard
36896
36897 \size footnotesize
36898 IC_LEFT() IC_RIGHT() IC_RESULT()
36899 \end_layout
36900
36901 \end_inset
36902 </cell>
36903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36904 \begin_inset Text
36905
36906 \begin_layout Standard
36907
36908 \size footnotesize
36909 Less than
36910 \end_layout
36911
36912 \end_inset
36913 </cell>
36914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36915 \begin_inset Text
36916
36917 \begin_layout Standard
36918
36919 \size footnotesize
36920 IC_RESULT = IC_LEFT < IC_RIGHT;
36921 \end_layout
36922
36923 \end_inset
36924 </cell>
36925 </row>
36926 <row topline="true">
36927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36928 \begin_inset Text
36929
36930 \begin_layout Standard
36931
36932 \size footnotesize
36933 '>'
36934 \end_layout
36935
36936 \end_inset
36937 </cell>
36938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36939 \begin_inset Text
36940
36941 \begin_layout Standard
36942
36943 \size footnotesize
36944 IC_LEFT() IC_RIGHT() IC_RESULT()
36945 \end_layout
36946
36947 \end_inset
36948 </cell>
36949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36950 \begin_inset Text
36951
36952 \begin_layout Standard
36953
36954 \size footnotesize
36955 Greater than 
36956 \end_layout
36957
36958 \end_inset
36959 </cell>
36960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
36961 \begin_inset Text
36962
36963 \begin_layout Standard
36964
36965 \size footnotesize
36966 IC_RESULT = IC_LEFT > IC_RIGHT;
36967 \end_layout
36968
36969 \end_inset
36970 </cell>
36971 </row>
36972 <row topline="true">
36973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36974 \begin_inset Text
36975
36976 \begin_layout Standard
36977
36978 \size footnotesize
36979 EQ_OP
36980 \end_layout
36981
36982 \end_inset
36983 </cell>
36984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36985 \begin_inset Text
36986
36987 \begin_layout Standard
36988
36989 \size footnotesize
36990 IC_LEFT() IC_RIGHT() IC_RESULT()
36991 \end_layout
36992
36993 \end_inset
36994 </cell>
36995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
36996 \begin_inset Text
36997
36998 \begin_layout Standard
36999
37000 \size footnotesize
37001 Equal to 
37002 \end_layout
37003
37004 \end_inset
37005 </cell>
37006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37007 \begin_inset Text
37008
37009 \begin_layout Standard
37010
37011 \size footnotesize
37012 IC_RESULT = IC_LEFT == IC_RIGHT;
37013 \end_layout
37014
37015 \end_inset
37016 </cell>
37017 </row>
37018 <row topline="true">
37019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37020 \begin_inset Text
37021
37022 \begin_layout Standard
37023
37024 \size footnotesize
37025 AND_OP
37026 \end_layout
37027
37028 \end_inset
37029 </cell>
37030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37031 \begin_inset Text
37032
37033 \begin_layout Standard
37034
37035 \size footnotesize
37036 IC_LEFT() IC_RIGHT() IC_RESULT() 
37037 \end_layout
37038
37039 \end_inset
37040 </cell>
37041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37042 \begin_inset Text
37043
37044 \begin_layout Standard
37045
37046 \size footnotesize
37047 Logical and operation
37048 \end_layout
37049
37050 \end_inset
37051 </cell>
37052 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37053 \begin_inset Text
37054
37055 \begin_layout Standard
37056
37057 \size footnotesize
37058 IC_RESULT = IC_LEFT && IC_RIGHT; 
37059 \end_layout
37060
37061 \end_inset
37062 </cell>
37063 </row>
37064 <row topline="true">
37065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37066 \begin_inset Text
37067
37068 \begin_layout Standard
37069
37070 \size footnotesize
37071 OR_OP
37072 \end_layout
37073
37074 \end_inset
37075 </cell>
37076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37077 \begin_inset Text
37078
37079 \begin_layout Standard
37080
37081 \size footnotesize
37082 IC_LEFT() IC_RIGHT() IC_RESULT() 
37083 \end_layout
37084
37085 \end_inset
37086 </cell>
37087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37088 \begin_inset Text
37089
37090 \begin_layout Standard
37091
37092 \size footnotesize
37093 Logical or operation 
37094 \end_layout
37095
37096 \end_inset
37097 </cell>
37098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37099 \begin_inset Text
37100
37101 \begin_layout Standard
37102
37103 \size footnotesize
37104 IC_RESULT = IC_LEFT || IC_RIGHT; 
37105 \end_layout
37106
37107 \end_inset
37108 </cell>
37109 </row>
37110 <row topline="true">
37111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37112 \begin_inset Text
37113
37114 \begin_layout Standard
37115
37116 \size footnotesize
37117 '^'
37118 \end_layout
37119
37120 \end_inset
37121 </cell>
37122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37123 \begin_inset Text
37124
37125 \begin_layout Standard
37126
37127 \size footnotesize
37128 IC_LEFT() IC_RIGHT() IC_RESULT() 
37129 \end_layout
37130
37131 \end_inset
37132 </cell>
37133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37134 \begin_inset Text
37135
37136 \begin_layout Standard
37137
37138 \size footnotesize
37139 Exclusive OR
37140 \end_layout
37141
37142 \end_inset
37143 </cell>
37144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37145 \begin_inset Text
37146
37147 \begin_layout Standard
37148
37149 \size footnotesize
37150 IC_RESULT = IC_LEFT ^ IC_RIGHT;
37151 \end_layout
37152
37153 \end_inset
37154 </cell>
37155 </row>
37156 <row topline="true">
37157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37158 \begin_inset Text
37159
37160 \begin_layout Standard
37161
37162 \size footnotesize
37163 '|'
37164 \end_layout
37165
37166 \end_inset
37167 </cell>
37168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37169 \begin_inset Text
37170
37171 \begin_layout Standard
37172
37173 \size footnotesize
37174 IC_LEFT() IC_RIGHT() IC_RESULT() 
37175 \end_layout
37176
37177 \end_inset
37178 </cell>
37179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37180 \begin_inset Text
37181
37182 \begin_layout Standard
37183
37184 \size footnotesize
37185 Bitwise OR 
37186 \end_layout
37187
37188 \end_inset
37189 </cell>
37190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37191 \begin_inset Text
37192
37193 \begin_layout Standard
37194
37195 \size footnotesize
37196 IC_RESULT = IC_LEFT | IC_RIGHT;
37197 \end_layout
37198
37199 \end_inset
37200 </cell>
37201 </row>
37202 <row topline="true">
37203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37204 \begin_inset Text
37205
37206 \begin_layout Standard
37207
37208 \size footnotesize
37209 BITWISEAND
37210 \end_layout
37211
37212 \end_inset
37213 </cell>
37214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37215 \begin_inset Text
37216
37217 \begin_layout Standard
37218
37219 \size footnotesize
37220 IC_LEFT() IC_RIGHT() IC_RESULT()
37221 \end_layout
37222
37223 \end_inset
37224 </cell>
37225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37226 \begin_inset Text
37227
37228 \begin_layout Standard
37229
37230 \size footnotesize
37231 Bitwise AND 
37232 \end_layout
37233
37234 \end_inset
37235 </cell>
37236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37237 \begin_inset Text
37238
37239 \begin_layout Standard
37240
37241 \size footnotesize
37242 IC_RESULT = IC_LEFT & IC_RIGHT;
37243 \end_layout
37244
37245 \end_inset
37246 </cell>
37247 </row>
37248 <row topline="true">
37249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37250 \begin_inset Text
37251
37252 \begin_layout Standard
37253
37254 \size footnotesize
37255 LEFT_OP
37256 \end_layout
37257
37258 \end_inset
37259 </cell>
37260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37261 \begin_inset Text
37262
37263 \begin_layout Standard
37264
37265 \size footnotesize
37266 IC_LEFT() IC_RIGHT() IC_RESULT()
37267 \end_layout
37268
37269 \end_inset
37270 </cell>
37271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37272 \begin_inset Text
37273
37274 \begin_layout Standard
37275
37276 \size footnotesize
37277 Left shift 
37278 \end_layout
37279
37280 \end_inset
37281 </cell>
37282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37283 \begin_inset Text
37284
37285 \begin_layout Standard
37286
37287 \size footnotesize
37288 IC_RESULT = IC_LEFT << IC_RIGHT 
37289 \end_layout
37290
37291 \end_inset
37292 </cell>
37293 </row>
37294 <row topline="true">
37295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37296 \begin_inset Text
37297
37298 \begin_layout Standard
37299
37300 \size footnotesize
37301 RIGHT_OP
37302 \end_layout
37303
37304 \end_inset
37305 </cell>
37306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37307 \begin_inset Text
37308
37309 \begin_layout Standard
37310
37311 \size footnotesize
37312 IC_LEFT() IC_RIGHT() IC_RESULT()
37313 \end_layout
37314
37315 \end_inset
37316 </cell>
37317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37318 \begin_inset Text
37319
37320 \begin_layout Standard
37321
37322 \size footnotesize
37323 Right shift
37324 \end_layout
37325
37326 \end_inset
37327 </cell>
37328 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37329 \begin_inset Text
37330
37331 \begin_layout Standard
37332
37333 \size footnotesize
37334 IC_RESULT = IC_LEFT >> IC_RIGHT 
37335 \end_layout
37336
37337 \end_inset
37338 </cell>
37339 </row>
37340 <row topline="true">
37341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37342 \begin_inset Text
37343
37344 \begin_layout Standard
37345
37346 \size footnotesize
37347 GET_VALUE_
37348 \newline
37349 AT_ ADDRESS
37350 \end_layout
37351
37352 \end_inset
37353 </cell>
37354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37355 \begin_inset Text
37356
37357 \begin_layout Standard
37358
37359 \size footnotesize
37360 IC_LEFT() IC_RESULT()
37361 \end_layout
37362
37363 \end_inset
37364 </cell>
37365 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37366 \begin_inset Text
37367
37368 \begin_layout Standard
37369
37370 \size footnotesize
37371 Indirect fetch 
37372 \end_layout
37373
37374 \end_inset
37375 </cell>
37376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37377 \begin_inset Text
37378
37379 \begin_layout Standard
37380
37381 \size footnotesize
37382 IC_RESULT = (*IC_LEFT);
37383 \end_layout
37384
37385 \end_inset
37386 </cell>
37387 </row>
37388 <row topline="true">
37389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37390 \begin_inset Text
37391
37392 \begin_layout Standard
37393
37394 \size footnotesize
37395 POINTER_SET
37396 \end_layout
37397
37398 \end_inset
37399 </cell>
37400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37401 \begin_inset Text
37402
37403 \begin_layout Standard
37404
37405 \size footnotesize
37406 IC_RIGHT() IC_RESULT() 
37407 \end_layout
37408
37409 \end_inset
37410 </cell>
37411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37412 \begin_inset Text
37413
37414 \begin_layout Standard
37415
37416 \size footnotesize
37417 Indirect set
37418 \end_layout
37419
37420 \end_inset
37421 </cell>
37422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37423 \begin_inset Text
37424
37425 \begin_layout Standard
37426
37427 \size footnotesize
37428 (*IC_RESULT) = IC_RIGHT;
37429 \end_layout
37430
37431 \end_inset
37432 </cell>
37433 </row>
37434 <row topline="true">
37435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37436 \begin_inset Text
37437
37438 \begin_layout Standard
37439
37440 \size footnotesize
37441 '='
37442 \end_layout
37443
37444 \end_inset
37445 </cell>
37446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37447 \begin_inset Text
37448
37449 \begin_layout Standard
37450
37451 \size footnotesize
37452 IC_RIGHT() IC_RESULT()
37453 \end_layout
37454
37455 \end_inset
37456 </cell>
37457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37458 \begin_inset Text
37459
37460 \begin_layout Standard
37461
37462 \size footnotesize
37463 Assignment
37464 \end_layout
37465
37466 \end_inset
37467 </cell>
37468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37469 \begin_inset Text
37470
37471 \begin_layout Standard
37472
37473 \size footnotesize
37474 IC_RESULT = IC_RIGHT;
37475 \end_layout
37476
37477 \end_inset
37478 </cell>
37479 </row>
37480 <row topline="true">
37481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37482 \begin_inset Text
37483
37484 \begin_layout Standard
37485
37486 \size footnotesize
37487 IFX
37488 \end_layout
37489
37490 \end_inset
37491 </cell>
37492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37493 \begin_inset Text
37494
37495 \begin_layout Standard
37496
37497 \size footnotesize
37498 IC_COND IC_TRUE IC_LABEL
37499 \end_layout
37500
37501 \end_inset
37502 </cell>
37503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37504 \begin_inset Text
37505
37506 \begin_layout Standard
37507
37508 \size footnotesize
37509 Conditional jump.
37510  If true label is present then jump to true label if condition is true else
37511  jump to false label if condition is false 
37512 \end_layout
37513
37514 \end_inset
37515 </cell>
37516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37517 \begin_inset Text
37518
37519 \begin_layout Standard
37520
37521 \size footnotesize
37522 if (IC_COND) goto IC_TRUE; 
37523 \newline
37524 \InsetSpace ~
37525 \InsetSpace ~
37526 Or 
37527 \newline
37528 If (!IC_COND) goto IC_FALSE;
37529 \end_layout
37530
37531 \end_inset
37532 </cell>
37533 </row>
37534 <row topline="true">
37535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37536 \begin_inset Text
37537
37538 \begin_layout Standard
37539
37540 \size footnotesize
37541 ADDRESS_OF
37542 \end_layout
37543
37544 \end_inset
37545 </cell>
37546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37547 \begin_inset Text
37548
37549 \begin_layout Standard
37550
37551 \size footnotesize
37552 IC_LEFT() IC_RESULT()
37553 \end_layout
37554
37555 \end_inset
37556 </cell>
37557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37558 \begin_inset Text
37559
37560 \begin_layout Standard
37561
37562 \size footnotesize
37563 Address of 
37564 \end_layout
37565
37566 \end_inset
37567 </cell>
37568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37569 \begin_inset Text
37570
37571 \begin_layout Standard
37572
37573 \size footnotesize
37574 IC_RESULT = &IC_LEFT();
37575 \end_layout
37576
37577 \end_inset
37578 </cell>
37579 </row>
37580 <row topline="true">
37581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37582 \begin_inset Text
37583
37584 \begin_layout Standard
37585
37586 \size footnotesize
37587 JUMPTABLE
37588 \end_layout
37589
37590 \end_inset
37591 </cell>
37592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37593 \begin_inset Text
37594
37595 \begin_layout Standard
37596
37597 \size footnotesize
37598 IC_JTCOND IC_JTLABELS
37599 \end_layout
37600
37601 \end_inset
37602 </cell>
37603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37604 \begin_inset Text
37605
37606 \begin_layout Standard
37607
37608 \size footnotesize
37609 Jump to list of labels depending on the value of JTCOND
37610 \end_layout
37611
37612 \end_inset
37613 </cell>
37614 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37615 \begin_inset Text
37616
37617 \begin_layout Standard
37618
37619 \size footnotesize
37620 Switch statement
37621 \end_layout
37622
37623 \end_inset
37624 </cell>
37625 </row>
37626 <row topline="true">
37627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37628 \begin_inset Text
37629
37630 \begin_layout Standard
37631
37632 \size footnotesize
37633 CAST
37634 \end_layout
37635
37636 \end_inset
37637 </cell>
37638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37639 \begin_inset Text
37640
37641 \begin_layout Standard
37642
37643 \size footnotesize
37644 IC_RIGHT() IC_LEFT() IC_RESULT()
37645 \end_layout
37646
37647 \end_inset
37648 </cell>
37649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37650 \begin_inset Text
37651
37652 \begin_layout Standard
37653
37654 \size footnotesize
37655 Cast types 
37656 \end_layout
37657
37658 \end_inset
37659 </cell>
37660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37661 \begin_inset Text
37662
37663 \begin_layout Standard
37664
37665 \size footnotesize
37666 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
37667 \end_layout
37668
37669 \end_inset
37670 </cell>
37671 </row>
37672 <row topline="true">
37673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37674 \begin_inset Text
37675
37676 \begin_layout Standard
37677
37678 \size footnotesize
37679 SEND
37680 \end_layout
37681
37682 \end_inset
37683 </cell>
37684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37685 \begin_inset Text
37686
37687 \begin_layout Standard
37688
37689 \size footnotesize
37690 IC_LEFT()
37691 \end_layout
37692
37693 \end_inset
37694 </cell>
37695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37696 \begin_inset Text
37697
37698 \begin_layout Standard
37699
37700 \size footnotesize
37701 This is used for passing parameters in registers; 
37702 \newline
37703 move IC_LEFT to the next
37704  available parameter register.
37705 \end_layout
37706
37707 \end_inset
37708 </cell>
37709 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37710 \begin_inset Text
37711
37712 \begin_layout Standard
37713
37714 \size footnotesize
37715 None
37716 \end_layout
37717
37718 \end_inset
37719 </cell>
37720 </row>
37721 <row topline="true">
37722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37723 \begin_inset Text
37724
37725 \begin_layout Standard
37726
37727 \size footnotesize
37728 RECV
37729 \end_layout
37730
37731 \end_inset
37732 </cell>
37733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37734 \begin_inset Text
37735
37736 \begin_layout Standard
37737
37738 \size footnotesize
37739 IC_RESULT()
37740 \end_layout
37741
37742 \end_inset
37743 </cell>
37744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37745 \begin_inset Text
37746
37747 \begin_layout Standard
37748
37749 \size footnotesize
37750 This is used for receiving parameters passed in registers;
37751 \newline
37752 Move the values
37753  in the next parameter register to IC_RESULT 
37754 \end_layout
37755
37756 \end_inset
37757 </cell>
37758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37759 \begin_inset Text
37760
37761 \begin_layout Standard
37762
37763 \size footnotesize
37764 None
37765 \end_layout
37766
37767 \end_inset
37768 </cell>
37769 </row>
37770 <row topline="true" bottomline="true">
37771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37772 \begin_inset Text
37773
37774 \begin_layout Standard
37775
37776 \shape slanted
37777 \size footnotesize
37778 (some more have been added)
37779 \end_layout
37780
37781 \end_inset
37782 </cell>
37783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37784 \begin_inset Text
37785
37786 \begin_layout Standard
37787
37788 \end_layout
37789
37790 \end_inset
37791 </cell>
37792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
37793 \begin_inset Text
37794
37795 \begin_layout Standard
37796
37797 \end_layout
37798
37799 \end_inset
37800 </cell>
37801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
37802 \begin_inset Text
37803
37804 \begin_layout Standard
37805
37806 \shape slanted
37807 \size footnotesize
37808 see f.e.
37809  
37810 \family typewriter
37811 gen51Code()
37812 \family default
37813  in 
37814 \family typewriter
37815 src/mcs51/gen.c
37816 \end_layout
37817
37818 \end_inset
37819 </cell>
37820 </row>
37821 </lyxtabular>
37822
37823 \end_inset
37824
37825
37826 \end_layout
37827
37828 \begin_layout Standard
37829 \begin_inset Note Note
37830 status collapsed
37831
37832 \begin_layout Standard
37833 In the original article Figure II was announced to be downloadable on 
37834 \shape italic
37835 Circuit Cellar
37836 \shape default
37837 's web site.
37838  ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
37839 \end_layout
37840
37841 \end_inset
37842
37843
37844 \end_layout
37845
37846 \begin_layout Paragraph*
37847 ICode Example
37848 \begin_inset LatexCommand \index{iCode}
37849
37850 \end_inset
37851
37852
37853 \end_layout
37854
37855 \begin_layout Standard
37856 This section shows some details of iCode.
37857  The example C code does not do anything useful; it is used as an example
37858  to illustrate the intermediate code generated by the compiler.
37859 \end_layout
37860
37861 \begin_layout Verse
37862
37863 \family typewriter
37864 1.\InsetSpace ~
37865 xdata int * p;
37866 \newline
37867 2.\InsetSpace ~
37868 int gint;
37869 \newline
37870 3.\InsetSpace ~
37871 /* This function does nothing useful.
37872  It is used
37873 \newline
37874 4.\InsetSpace ~
37875 \InsetSpace ~
37876 \InsetSpace ~
37877 \InsetSpace ~
37878 for the purpose of explaining iCode */
37879 \newline
37880 5.\InsetSpace ~
37881 short function (data
37882  int *x)
37883 \newline
37884 6.\InsetSpace ~
37885 {
37886 \newline
37887 7.\InsetSpace ~
37888 \InsetSpace ~
37889 \InsetSpace ~
37890 short i=10; \InsetSpace ~
37891 \InsetSpace ~
37892 /* dead initialization eliminated */
37893 \newline
37894 8.\InsetSpace ~
37895 \InsetSpace ~
37896 \InsetSpace ~
37897 short sum=10;
37898  /* dead initialization eliminated */
37899 \newline
37900 9.\InsetSpace ~
37901 \InsetSpace ~
37902 \InsetSpace ~
37903 short mul;
37904 \newline
37905 10.\InsetSpace ~
37906 \InsetSpace ~
37907 int j ;
37908 \newline
37909 11.\InsetSpace ~
37910 \InsetSpace ~
37911 while (*x) *x++
37912  = *p++; 
37913 \newline
37914 12.\InsetSpace ~
37915 \InsetSpace ~
37916 \InsetSpace ~
37917 \InsetSpace ~
37918 sum = 0 ; 
37919 \newline
37920 13.\InsetSpace ~
37921 \InsetSpace ~
37922 mul = 0;
37923 \newline
37924 14.\InsetSpace ~
37925 \InsetSpace ~
37926 /* compiler detects i,j to be induction
37927  variables */
37928 \newline
37929 15.\InsetSpace ~
37930 \InsetSpace ~
37931 for (i = 0, j = 10 ; i < 10 ; i++, j
37932 \family default
37933 -
37934 \begin_inset ERT
37935 status collapsed
37936
37937 \begin_layout Standard
37938
37939
37940 \backslash
37941 /
37942 \end_layout
37943
37944 \end_inset
37945
37946 -
37947 \family typewriter
37948 ) {
37949 \newline
37950 16.\InsetSpace ~
37951 \InsetSpace ~
37952 \InsetSpace ~
37953 \InsetSpace ~
37954 sum += i;
37955 \newline
37956 17.\InsetSpace ~
37957 \InsetSpace ~
37958 \InsetSpace ~
37959 \InsetSpace ~
37960 mul += i * 3; \InsetSpace ~
37961 \InsetSpace ~
37962 /* this multiplication remains */
37963 \newline
37964 18.\InsetSpace ~
37965 \InsetSpace ~
37966 \InsetSpace ~
37967 \InsetSpace ~
37968 gint +=
37969  j * 3;\InsetSpace ~
37970 \InsetSpace ~
37971 /* this multiplication changed to addition */
37972 \newline
37973 19.\InsetSpace ~
37974 \InsetSpace ~
37975 }
37976 \newline
37977 20.\InsetSpace ~
37978 \InsetSpace ~
37979 return sum+mul;
37980 \newline
37981 21.\InsetSpace ~
37982 }
37983 \end_layout
37984
37985 \begin_layout Standard
37986 In addition to the operands each iCode contains information about the filename
37987  and line it corresponds to in the source file.
37988  The first field in the listing should be interpreted as follows:
37989 \newline
37990
37991 \shape italic
37992 \size footnotesize
37993 Filename(linenumber: iCode Execution sequence number : ICode hash table
37994  key : loop depth of the iCode).
37995 \shape default
37996 \size default
37997
37998 \newline
37999 Then follows the human readable form of the ICode operation.
38000  Each operand of this triplet form can be of three basic types a) compiler
38001  generated temporary b) user defined variable c) a constant value.
38002  Note that local variables and parameters are replaced by compiler generated
38003  temporaries.
38004  Live ranges
38005 \begin_inset LatexCommand \index{Live range analysis}
38006
38007 \end_inset
38008
38009  are computed only for temporaries (i.e.
38010  live ranges are not computed for global variables).
38011  Registers
38012 \begin_inset LatexCommand \index{Register allocation}
38013
38014 \end_inset
38015
38016  are allocated for temporaries only.
38017  Operands are formatted in the following manner:
38018 \newline
38019
38020 \shape italic
38021 \size footnotesize
38022 Operand Name [lr live-from : live-to ] { type information } [ registers
38023  allocated ].
38024 \shape default
38025 \size default
38026
38027 \newline
38028 As mentioned earlier the live ranges are computed in terms of the execution
38029  sequence number of the iCodes, for example 
38030 \newline
38031 the iTemp0 is live from (i.e.
38032  first defined in iCode with execution sequence number 3, and is last used
38033  in the iCode with sequence number 5).
38034  For induction variables such as iTemp21 the live range computation extends
38035  the lifetime from the start to the end of the loop.
38036 \newline
38037 The register allocator
38038  used the live range information to allocate registers, the same registers
38039  may be used for different temporaries if their live ranges do not overlap,
38040  for example r0 is allocated to both iTemp6 and to iTemp17 since their live
38041  ranges do not overlap.
38042  In addition the allocator also takes into consideration the type and usage
38043  of a temporary, for example itemp6 is a pointer to near space and is used
38044  as to fetch data from (i.e.
38045  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
38046  Some short lived temporaries are allocated to special registers which have
38047  meaning to the code generator e.g.
38048  iTemp13 is allocated to a pseudo register CC which tells the back end that
38049  the temporary is used only for a conditional jump the code generation makes
38050  use of this information to optimize a compare and jump ICode.
38051 \newline
38052 There are several
38053  loop optimizations
38054 \begin_inset LatexCommand \index{Loop optimization}
38055
38056 \end_inset
38057
38058  performed by the compiler.
38059  It can detect induction variables iTemp21(i) and iTemp23(j).
38060  Also note the compiler does selective strength reduction
38061 \begin_inset LatexCommand \index{Strength reduction}
38062
38063 \end_inset
38064
38065 , i.e.
38066  the multiplication of an induction variable in line 18 (gint = j * 3) is
38067  changed to addition, a new temporary iTemp17 is allocated and assigned
38068  a initial value, a constant 3 is then added for each iteration of the loop.
38069  The compiler does not change the multiplication
38070 \begin_inset LatexCommand \index{Multiplication}
38071
38072 \end_inset
38073
38074  in line 17 however since the processor does support an 8 * 8 bit multiplication.
38075 \newline
38076
38077 Note the dead code elimination
38078 \begin_inset LatexCommand \index{Dead-code elimination}
38079
38080 \end_inset
38081
38082  optimization eliminated the dead assignments in line 7 & 8 to I and sum
38083  respectively.
38084 \newline
38085
38086 \end_layout
38087
38088 \begin_layout Standard
38089
38090 \size footnotesize
38091 Sample.c (5:1:0:0) _entry($9) :
38092 \end_layout
38093
38094 \begin_layout Standard
38095
38096 \size footnotesize
38097 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
38098 \end_layout
38099
38100 \begin_layout Standard
38101
38102 \size footnotesize
38103 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
38104 \end_layout
38105
38106 \begin_layout Standard
38107
38108 \size footnotesize
38109 Sample.c(11:4:53:0) preHeaderLbl0($11) :
38110 \end_layout
38111
38112 \begin_layout Standard
38113
38114 \size footnotesize
38115 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
38116  * int}[r2]
38117 \end_layout
38118
38119 \begin_layout Standard
38120
38121 \size footnotesize
38122 Sample.c(11:6:5:1) _whilecontinue_0($1) :
38123 \end_layout
38124
38125 \begin_layout Standard
38126
38127 \size footnotesize
38128 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
38129  int}[r0]]
38130 \end_layout
38131
38132 \begin_layout Standard
38133
38134 \size footnotesize
38135 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38136 \end_layout
38137
38138 \begin_layout Standard
38139
38140 \size footnotesize
38141 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
38142  * int}
38143 \end_layout
38144
38145 \begin_layout Standard
38146
38147 \size footnotesize
38148 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
38149  {short}
38150 \end_layout
38151
38152 \begin_layout Standard
38153
38154 \size footnotesize
38155 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
38156  * int}[DPTR]]
38157 \end_layout
38158
38159 \begin_layout Standard
38160
38161 \size footnotesize
38162 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
38163 }[r2 r3]
38164 \end_layout
38165
38166 \begin_layout Standard
38167
38168 \size footnotesize
38169 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
38170  * int}[r0] + 0x2 {short}
38171 \end_layout
38172
38173 \begin_layout Standard
38174
38175 \size footnotesize
38176 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
38177 \end_layout
38178
38179 \begin_layout Standard
38180
38181 \size footnotesize
38182 Sample.c(11:17:21:0)_whilebreak_0($3) :
38183 \end_layout
38184
38185 \begin_layout Standard
38186
38187 \size footnotesize
38188 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38189 \end_layout
38190
38191 \begin_layout Standard
38192
38193 \size footnotesize
38194 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38195 \end_layout
38196
38197 \begin_layout Standard
38198
38199 \size footnotesize
38200 Sample.c(15:20:54:0)preHeaderLbl1($13) :
38201 \end_layout
38202
38203 \begin_layout Standard
38204
38205 \size footnotesize
38206 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38207 \end_layout
38208
38209 \begin_layout Standard
38210
38211 \size footnotesize
38212 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38213 \end_layout
38214
38215 \begin_layout Standard
38216
38217 \size footnotesize
38218 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38219 \end_layout
38220
38221 \begin_layout Standard
38222
38223 \size footnotesize
38224 Sample.c(15:24:26:1)_forcond_0($4) :
38225 \end_layout
38226
38227 \begin_layout Standard
38228
38229 \size footnotesize
38230 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
38231  < 0xa {short}
38232 \end_layout
38233
38234 \begin_layout Standard
38235
38236 \size footnotesize
38237 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38238 \end_layout
38239
38240 \begin_layout Standard
38241
38242 \size footnotesize
38243 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
38244  + ITemp21 [lr21:38]{short}[r4]
38245 \end_layout
38246
38247 \begin_layout Standard
38248
38249 \size footnotesize
38250 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
38251  * 0x3 {short}
38252 \end_layout
38253
38254 \begin_layout Standard
38255
38256 \size footnotesize
38257 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
38258  + iTemp15 [lr29:30]{short}[r1]
38259 \end_layout
38260
38261 \begin_layout Standard
38262
38263 \size footnotesize
38264 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
38265  r0]- 0x3 {short}
38266 \end_layout
38267
38268 \begin_layout Standard
38269
38270 \size footnotesize
38271 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
38272 int}[r7 r0]
38273 \end_layout
38274
38275 \begin_layout Standard
38276
38277 \size footnotesize
38278 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
38279  + 0x1 {short}
38280 \end_layout
38281
38282 \begin_layout Standard
38283
38284 \size footnotesize
38285 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
38286  r6]- 0x1 {short}
38287 \end_layout
38288
38289 \begin_layout Standard
38290
38291 \size footnotesize
38292 Sample.c(19:38:47:1) goto _forcond_0($4)
38293 \end_layout
38294
38295 \begin_layout Standard
38296
38297 \size footnotesize
38298 Sample.c(19:39:48:0)_forbreak_0($7) :
38299 \end_layout
38300
38301 \begin_layout Standard
38302
38303 \size footnotesize
38304 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
38305  + ITemp11 [lr19:40]{short}[r3]
38306 \end_layout
38307
38308 \begin_layout Standard
38309
38310 \size footnotesize
38311 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
38312 \end_layout
38313
38314 \begin_layout Standard
38315
38316 \size footnotesize
38317 Sample.c(20:42:51:0)_return($8) :
38318 \end_layout
38319
38320 \begin_layout Standard
38321
38322 \size footnotesize
38323 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
38324 \size default
38325
38326 \newline
38327
38328 \newline
38329 Finally the code generated for this function:
38330 \newline
38331
38332 \end_layout
38333
38334 \begin_layout Standard
38335
38336 \size footnotesize
38337 .area DSEG (DATA)
38338 \end_layout
38339
38340 \begin_layout Standard
38341
38342 \size footnotesize
38343 _p::
38344 \end_layout
38345
38346 \begin_layout Standard
38347
38348 \size footnotesize
38349 \InsetSpace ~
38350 \InsetSpace ~
38351 .ds 2
38352 \end_layout
38353
38354 \begin_layout Standard
38355
38356 \size footnotesize
38357 _gint::
38358 \end_layout
38359
38360 \begin_layout Standard
38361
38362 \size footnotesize
38363 \InsetSpace ~
38364 \InsetSpace ~
38365 .ds 2
38366 \end_layout
38367
38368 \begin_layout Standard
38369
38370 \size footnotesize
38371 ; sample.c 5
38372 \end_layout
38373
38374 \begin_layout Standard
38375
38376 \size footnotesize
38377 ; ----------------------------------------------
38378 \end_layout
38379
38380 \begin_layout Standard
38381
38382 \size footnotesize
38383 ; function function
38384 \end_layout
38385
38386 \begin_layout Standard
38387
38388 \size footnotesize
38389 ; ----------------------------------------------
38390 \end_layout
38391
38392 \begin_layout Standard
38393
38394 \size footnotesize
38395 _function:
38396 \end_layout
38397
38398 \begin_layout Standard
38399
38400 \size footnotesize
38401 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
38402 \end_layout
38403
38404 \begin_layout Standard
38405
38406 \size footnotesize
38407 \InsetSpace ~
38408 \InsetSpace ~
38409 mov r2,dpl
38410 \end_layout
38411
38412 \begin_layout Standard
38413
38414 \size footnotesize
38415 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
38416 \end_layout
38417
38418 \begin_layout Standard
38419
38420 \size footnotesize
38421 \InsetSpace ~
38422 \InsetSpace ~
38423 mov ar0,r2
38424 \end_layout
38425
38426 \begin_layout Standard
38427
38428 \size footnotesize
38429 ;_whilecontinue_0($1) :
38430 \end_layout
38431
38432 \begin_layout Standard
38433
38434 \size footnotesize
38435 00101$:
38436 \end_layout
38437
38438 \begin_layout Standard
38439
38440 \size footnotesize
38441 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
38442 \end_layout
38443
38444 \begin_layout Standard
38445
38446 \size footnotesize
38447 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
38448 \end_layout
38449
38450 \begin_layout Standard
38451
38452 \size footnotesize
38453 \InsetSpace ~
38454 \InsetSpace ~
38455 mov ar2,@r0
38456 \end_layout
38457
38458 \begin_layout Standard
38459
38460 \size footnotesize
38461 \InsetSpace ~
38462 \InsetSpace ~
38463 inc r0
38464 \end_layout
38465
38466 \begin_layout Standard
38467
38468 \size footnotesize
38469 \InsetSpace ~
38470 \InsetSpace ~
38471 mov ar3,@r0
38472 \end_layout
38473
38474 \begin_layout Standard
38475
38476 \size footnotesize
38477 \InsetSpace ~
38478 \InsetSpace ~
38479 dec r0
38480 \end_layout
38481
38482 \begin_layout Standard
38483
38484 \size footnotesize
38485 \InsetSpace ~
38486 \InsetSpace ~
38487 mov a,r2
38488 \end_layout
38489
38490 \begin_layout Standard
38491
38492 \size footnotesize
38493 \InsetSpace ~
38494 \InsetSpace ~
38495 orl a,r3
38496 \end_layout
38497
38498 \begin_layout Standard
38499
38500 \size footnotesize
38501 \InsetSpace ~
38502 \InsetSpace ~
38503 jz 00103$
38504 \end_layout
38505
38506 \begin_layout Standard
38507
38508 \size footnotesize
38509 00114$:
38510 \end_layout
38511
38512 \begin_layout Standard
38513
38514 \size footnotesize
38515 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
38516 \end_layout
38517
38518 \begin_layout Standard
38519
38520 \size footnotesize
38521 \InsetSpace ~
38522 \InsetSpace ~
38523 mov dpl,_p
38524 \end_layout
38525
38526 \begin_layout Standard
38527
38528 \size footnotesize
38529 \InsetSpace ~
38530 \InsetSpace ~
38531 mov dph,(_p + 1)
38532 \end_layout
38533
38534 \begin_layout Standard
38535
38536 \size footnotesize
38537 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
38538 \end_layout
38539
38540 \begin_layout Standard
38541
38542 \size footnotesize
38543 \InsetSpace ~
38544 \InsetSpace ~
38545 mov a,#0x02
38546 \end_layout
38547
38548 \begin_layout Standard
38549
38550 \size footnotesize
38551 \InsetSpace ~
38552 \InsetSpace ~
38553 add a,_p
38554 \end_layout
38555
38556 \begin_layout Standard
38557
38558 \size footnotesize
38559 \InsetSpace ~
38560 \InsetSpace ~
38561 mov _p,a
38562 \end_layout
38563
38564 \begin_layout Standard
38565
38566 \size footnotesize
38567 \InsetSpace ~
38568 \InsetSpace ~
38569 clr a
38570 \end_layout
38571
38572 \begin_layout Standard
38573
38574 \size footnotesize
38575 \InsetSpace ~
38576 \InsetSpace ~
38577 addc a,(_p + 1)
38578 \end_layout
38579
38580 \begin_layout Standard
38581
38582 \size footnotesize
38583 \InsetSpace ~
38584 \InsetSpace ~
38585 mov (_p + 1),a
38586 \end_layout
38587
38588 \begin_layout Standard
38589
38590 \size footnotesize
38591 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
38592 \end_layout
38593
38594 \begin_layout Standard
38595
38596 \size footnotesize
38597 \InsetSpace ~
38598 \InsetSpace ~
38599 movx a,@dptr
38600 \end_layout
38601
38602 \begin_layout Standard
38603
38604 \size footnotesize
38605 \InsetSpace ~
38606 \InsetSpace ~
38607 mov r2,a
38608 \end_layout
38609
38610 \begin_layout Standard
38611
38612 \size footnotesize
38613 \InsetSpace ~
38614 \InsetSpace ~
38615 inc dptr
38616 \end_layout
38617
38618 \begin_layout Standard
38619
38620 \size footnotesize
38621 \InsetSpace ~
38622 \InsetSpace ~
38623 movx a,@dptr
38624 \end_layout
38625
38626 \begin_layout Standard
38627
38628 \size footnotesize
38629 \InsetSpace ~
38630 \InsetSpace ~
38631 mov r3,a
38632 \end_layout
38633
38634 \begin_layout Standard
38635
38636 \size footnotesize
38637 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
38638 \end_layout
38639
38640 \begin_layout Standard
38641
38642 \size footnotesize
38643 \InsetSpace ~
38644 \InsetSpace ~
38645 mov @r0,ar2
38646 \end_layout
38647
38648 \begin_layout Standard
38649
38650 \size footnotesize
38651 \InsetSpace ~
38652 \InsetSpace ~
38653 inc r0
38654 \end_layout
38655
38656 \begin_layout Standard
38657
38658 \size footnotesize
38659 \InsetSpace ~
38660 \InsetSpace ~
38661 mov @r0,ar3
38662 \end_layout
38663
38664 \begin_layout Standard
38665
38666 \size footnotesize
38667 ; iTemp6 [lr5:16]{_near * int}[r0] = 
38668 \end_layout
38669
38670 \begin_layout Standard
38671
38672 \size footnotesize
38673 ; iTemp6 [lr5:16]{_near * int}[r0] + 
38674 \end_layout
38675
38676 \begin_layout Standard
38677
38678 \size footnotesize
38679 ; 0x2 {short}
38680 \end_layout
38681
38682 \begin_layout Standard
38683
38684 \size footnotesize
38685 \InsetSpace ~
38686 \InsetSpace ~
38687 inc r0
38688 \end_layout
38689
38690 \begin_layout Standard
38691
38692 \size footnotesize
38693 ; goto _whilecontinue_0($1)
38694 \end_layout
38695
38696 \begin_layout Standard
38697
38698 \size footnotesize
38699 \InsetSpace ~
38700 \InsetSpace ~
38701 sjmp 00101$
38702 \end_layout
38703
38704 \begin_layout Standard
38705
38706 \size footnotesize
38707 ; _whilebreak_0($3) :
38708 \end_layout
38709
38710 \begin_layout Standard
38711
38712 \size footnotesize
38713 00103$:
38714 \end_layout
38715
38716 \begin_layout Standard
38717
38718 \size footnotesize
38719 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
38720 \end_layout
38721
38722 \begin_layout Standard
38723
38724 \size footnotesize
38725 \InsetSpace ~
38726 \InsetSpace ~
38727 mov r2,#0x00
38728 \end_layout
38729
38730 \begin_layout Standard
38731
38732 \size footnotesize
38733 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
38734 \end_layout
38735
38736 \begin_layout Standard
38737
38738 \size footnotesize
38739 \InsetSpace ~
38740 \InsetSpace ~
38741 mov r3,#0x00
38742 \end_layout
38743
38744 \begin_layout Standard
38745
38746 \size footnotesize
38747 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
38748 \end_layout
38749
38750 \begin_layout Standard
38751
38752 \size footnotesize
38753 \InsetSpace ~
38754 \InsetSpace ~
38755 mov r4,#0x00
38756 \end_layout
38757
38758 \begin_layout Standard
38759
38760 \size footnotesize
38761 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
38762 \end_layout
38763
38764 \begin_layout Standard
38765
38766 \size footnotesize
38767 \InsetSpace ~
38768 \InsetSpace ~
38769 mov r5,#0x0A
38770 \end_layout
38771
38772 \begin_layout Standard
38773
38774 \size footnotesize
38775 \InsetSpace ~
38776 \InsetSpace ~
38777 mov r6,#0x00
38778 \end_layout
38779
38780 \begin_layout Standard
38781
38782 \size footnotesize
38783 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
38784 \end_layout
38785
38786 \begin_layout Standard
38787
38788 \size footnotesize
38789 \InsetSpace ~
38790 \InsetSpace ~
38791 mov r7,#0x1E
38792 \end_layout
38793
38794 \begin_layout Standard
38795
38796 \size footnotesize
38797 \InsetSpace ~
38798 \InsetSpace ~
38799 mov r0,#0x00
38800 \end_layout
38801
38802 \begin_layout Standard
38803
38804 \size footnotesize
38805 ; _forcond_0($4) :
38806 \end_layout
38807
38808 \begin_layout Standard
38809
38810 \size footnotesize
38811 00104$:
38812 \end_layout
38813
38814 \begin_layout Standard
38815
38816 \size footnotesize
38817 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
38818 \end_layout
38819
38820 \begin_layout Standard
38821
38822 \size footnotesize
38823 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
38824 \end_layout
38825
38826 \begin_layout Standard
38827
38828 \size footnotesize
38829 \InsetSpace ~
38830 \InsetSpace ~
38831 clr c
38832 \end_layout
38833
38834 \begin_layout Standard
38835
38836 \size footnotesize
38837 \InsetSpace ~
38838 \InsetSpace ~
38839 mov a,r4
38840 \end_layout
38841
38842 \begin_layout Standard
38843
38844 \size footnotesize
38845 \InsetSpace ~
38846 \InsetSpace ~
38847 xrl a,#0x80
38848 \end_layout
38849
38850 \begin_layout Standard
38851
38852 \size footnotesize
38853 \InsetSpace ~
38854 \InsetSpace ~
38855 subb a,#0x8a
38856 \end_layout
38857
38858 \begin_layout Standard
38859
38860 \size footnotesize
38861 \InsetSpace ~
38862 \InsetSpace ~
38863 jnc 00107$
38864 \end_layout
38865
38866 \begin_layout Standard
38867
38868 \size footnotesize
38869 00115$:
38870 \end_layout
38871
38872 \begin_layout Standard
38873
38874 \size footnotesize
38875 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
38876 \end_layout
38877
38878 \begin_layout Standard
38879
38880 \size footnotesize
38881 ; iTemp21 [lr21:38]{short}[r4]
38882 \end_layout
38883
38884 \begin_layout Standard
38885
38886 \size footnotesize
38887 \InsetSpace ~
38888 \InsetSpace ~
38889 mov a,r4
38890 \end_layout
38891
38892 \begin_layout Standard
38893
38894 \size footnotesize
38895 \InsetSpace ~
38896 \InsetSpace ~
38897 add a,r2
38898 \end_layout
38899
38900 \begin_layout Standard
38901
38902 \size footnotesize
38903 \InsetSpace ~
38904 \InsetSpace ~
38905 mov r2,a
38906 \end_layout
38907
38908 \begin_layout Standard
38909
38910 \size footnotesize
38911 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
38912 \end_layout
38913
38914 \begin_layout Standard
38915
38916 \size footnotesize
38917 \InsetSpace ~
38918 \InsetSpace ~
38919 mov b,#0x03
38920 \end_layout
38921
38922 \begin_layout Standard
38923
38924 \size footnotesize
38925 \InsetSpace ~
38926 \InsetSpace ~
38927 mov a,r4
38928 \end_layout
38929
38930 \begin_layout Standard
38931
38932 \size footnotesize
38933 \InsetSpace ~
38934 \InsetSpace ~
38935 mul ab
38936 \end_layout
38937
38938 \begin_layout Standard
38939
38940 \size footnotesize
38941 \InsetSpace ~
38942 \InsetSpace ~
38943 mov r1,a
38944 \end_layout
38945
38946 \begin_layout Standard
38947
38948 \size footnotesize
38949 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
38950 \end_layout
38951
38952 \begin_layout Standard
38953
38954 \size footnotesize
38955 ; iTemp15 [lr29:30]{short}[r1]
38956 \end_layout
38957
38958 \begin_layout Standard
38959
38960 \size footnotesize
38961 \InsetSpace ~
38962 \InsetSpace ~
38963 add a,r3
38964 \end_layout
38965
38966 \begin_layout Standard
38967
38968 \size footnotesize
38969 \InsetSpace ~
38970 \InsetSpace ~
38971 mov r3,a
38972 \end_layout
38973
38974 \begin_layout Standard
38975
38976 \size footnotesize
38977 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
38978 \end_layout
38979
38980 \begin_layout Standard
38981
38982 \size footnotesize
38983 \InsetSpace ~
38984 \InsetSpace ~
38985 mov a,r7
38986 \end_layout
38987
38988 \begin_layout Standard
38989
38990 \size footnotesize
38991 \InsetSpace ~
38992 \InsetSpace ~
38993 add a,#0xfd
38994 \end_layout
38995
38996 \begin_layout Standard
38997
38998 \size footnotesize
38999 \InsetSpace ~
39000 \InsetSpace ~
39001 mov r7,a
39002 \end_layout
39003
39004 \begin_layout Standard
39005
39006 \size footnotesize
39007 \InsetSpace ~
39008 \InsetSpace ~
39009 mov a,r0
39010 \end_layout
39011
39012 \begin_layout Standard
39013
39014 \size footnotesize
39015 \InsetSpace ~
39016 \InsetSpace ~
39017 addc a,#0xff
39018 \end_layout
39019
39020 \begin_layout Standard
39021
39022 \size footnotesize
39023 \InsetSpace ~
39024 \InsetSpace ~
39025 mov r0,a
39026 \end_layout
39027
39028 \begin_layout Standard
39029
39030 \size footnotesize
39031 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
39032 \end_layout
39033
39034 \begin_layout Standard
39035
39036 \size footnotesize
39037 \InsetSpace ~
39038 \InsetSpace ~
39039 mov a,r7
39040 \end_layout
39041
39042 \begin_layout Standard
39043
39044 \size footnotesize
39045 \InsetSpace ~
39046 \InsetSpace ~
39047 add a,_gint
39048 \end_layout
39049
39050 \begin_layout Standard
39051
39052 \size footnotesize
39053 \InsetSpace ~
39054 \InsetSpace ~
39055 mov _gint,a
39056 \end_layout
39057
39058 \begin_layout Standard
39059
39060 \size footnotesize
39061 \InsetSpace ~
39062 \InsetSpace ~
39063 mov a,r0
39064 \end_layout
39065
39066 \begin_layout Standard
39067
39068 \size footnotesize
39069 \InsetSpace ~
39070 \InsetSpace ~
39071 addc a,(_gint + 1)
39072 \end_layout
39073
39074 \begin_layout Standard
39075
39076 \size footnotesize
39077 \InsetSpace ~
39078 \InsetSpace ~
39079 mov (_gint + 1),a
39080 \end_layout
39081
39082 \begin_layout Standard
39083
39084 \size footnotesize
39085 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
39086 \end_layout
39087
39088 \begin_layout Standard
39089
39090 \size footnotesize
39091 \InsetSpace ~
39092 \InsetSpace ~
39093 inc r4
39094 \end_layout
39095
39096 \begin_layout Standard
39097
39098 \size footnotesize
39099 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
39100 \end_layout
39101
39102 \begin_layout Standard
39103
39104 \size footnotesize
39105 \InsetSpace ~
39106 \InsetSpace ~
39107 dec r5
39108 \end_layout
39109
39110 \begin_layout Standard
39111
39112 \size footnotesize
39113 \InsetSpace ~
39114 \InsetSpace ~
39115 cjne r5,#0xff,00104$
39116 \end_layout
39117
39118 \begin_layout Standard
39119
39120 \size footnotesize
39121 \InsetSpace ~
39122 \InsetSpace ~
39123 dec r6
39124 \end_layout
39125
39126 \begin_layout Standard
39127
39128 \size footnotesize
39129 ; goto _forcond_0($4)
39130 \end_layout
39131
39132 \begin_layout Standard
39133
39134 \size footnotesize
39135 \InsetSpace ~
39136 \InsetSpace ~
39137 sjmp 00104$
39138 \end_layout
39139
39140 \begin_layout Standard
39141
39142 \size footnotesize
39143 ; _forbreak_0($7) :
39144 \end_layout
39145
39146 \begin_layout Standard
39147
39148 \size footnotesize
39149 00107$:
39150 \end_layout
39151
39152 \begin_layout Standard
39153
39154 \size footnotesize
39155 ; ret iTemp24 [lr40:41]{short}
39156 \end_layout
39157
39158 \begin_layout Standard
39159
39160 \size footnotesize
39161 \InsetSpace ~
39162 \InsetSpace ~
39163 mov a,r3
39164 \end_layout
39165
39166 \begin_layout Standard
39167
39168 \size footnotesize
39169 \InsetSpace ~
39170 \InsetSpace ~
39171 add a,r2
39172 \end_layout
39173
39174 \begin_layout Standard
39175
39176 \size footnotesize
39177 \InsetSpace ~
39178 \InsetSpace ~
39179 mov dpl,a
39180 \end_layout
39181
39182 \begin_layout Standard
39183
39184 \size footnotesize
39185 ; _return($8) :
39186 \end_layout
39187
39188 \begin_layout Standard
39189
39190 \size footnotesize
39191 00108$:
39192 \end_layout
39193
39194 \begin_layout Standard
39195
39196 \size footnotesize
39197 \InsetSpace ~
39198 \InsetSpace ~
39199 ret
39200 \newline
39201
39202 \end_layout
39203
39204 \begin_layout Section
39205 A few words about basic block successors, predecessors and dominators
39206 \end_layout
39207
39208 \begin_layout Standard
39209 Successors are basic blocks
39210 \begin_inset LatexCommand \index{Basic blocks}
39211
39212 \end_inset
39213
39214  that might execute after this basic block.
39215 \newline
39216 Predecessors are basic blocks
39217  that might execute before reaching this basic block.
39218 \newline
39219 Dominators are basic
39220  blocks that WILL execute before reaching this basic block.
39221 \newline
39222
39223 \end_layout
39224
39225 \begin_layout Standard
39226 [basic block 1]
39227 \end_layout
39228
39229 \begin_layout Standard
39230 if (something)
39231 \end_layout
39232
39233 \begin_layout Standard
39234 \InsetSpace ~
39235 \InsetSpace ~
39236 \InsetSpace ~
39237 \InsetSpace ~
39238 [basic block 2]
39239 \end_layout
39240
39241 \begin_layout Standard
39242 else
39243 \end_layout
39244
39245 \begin_layout Standard
39246 \InsetSpace ~
39247 \InsetSpace ~
39248 \InsetSpace ~
39249 \InsetSpace ~
39250 [basic block 3]
39251 \end_layout
39252
39253 \begin_layout Standard
39254 [basic block 4]
39255 \newline
39256
39257 \end_layout
39258
39259 \begin_layout Standard
39260 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
39261 \end_layout
39262
39263 \begin_layout Standard
39264 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
39265 \end_layout
39266
39267 \begin_layout Standard
39268 c) domVect of [BB4] = BB1 ...
39269  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
39270  was executed.
39271 \end_layout
39272
39273 \begin_layout Chapter
39274 Acknowledgments
39275 \end_layout
39276
39277 \begin_layout Standard
39278 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
39279
39280 \end_inset
39281
39282
39283 \newline
39284
39285 \newline
39286
39287 \emph on
39288 Thanks to all the other volunteer developers who have helped with coding,
39289  testing, web-page creation, distribution sets, etc.
39290  You know who you are :-)
39291 \emph default
39292
39293 \newline
39294
39295 \newline
39296
39297 \emph on
39298 Also thanks to Sourceforge 
39299 \begin_inset LatexCommand \url{http://www.sf.net}
39300
39301 \end_inset
39302
39303  which has hosted the project since 1999 and donates significant download
39304  bandwidth and probably more than 
39305 \begin_inset ERT
39306 status collapsed
39307
39308 \begin_layout Standard
39309
39310 $10^{13}$
39311 \end_layout
39312
39313 \end_inset
39314
39315 CPU cycles per day.
39316 \newline
39317  
39318 \begin_inset Note Note
39319 status open
39320
39321 \begin_layout Standard
39322 more than 10^13 is an estimate: on my Athlon 2800+ it takes about (0.5+6.5+20)
39323  minutes for (configure+make+regression test), and there is (i386, amd64,
39324  alpha, ppc64, (mingw32), sparc, Mac OS X).
39325  
39326 \end_layout
39327
39328 \end_inset
39329
39330
39331 \end_layout
39332
39333 \begin_layout Standard
39334 This document was initially written by Sandeep Dutta
39335 \end_layout
39336
39337 \begin_layout Standard
39338 All product names mentioned herein may be trademarks
39339 \begin_inset LatexCommand \index{Trademarks}
39340
39341 \end_inset
39342
39343  of their respective companies.
39344  
39345 \end_layout
39346
39347 \begin_layout Section*
39348 Alphabetical index
39349 \end_layout
39350
39351 \begin_layout Standard
39352 To avoid confusion, the installation and building options for SDCC itself
39353  (chapter 2) are not part of the index.
39354 \end_layout
39355
39356 \begin_layout Standard
39357 \begin_inset LatexCommand \printindex{}
39358
39359 \end_inset
39360
39361
39362 \end_layout
39363
39364 \end_body
39365 \end_document