cc06d7415373e23e6da4b952b356795894447f54
[fw/sdcc] / doc / SDCCUdoc.lyx
1 #This file was created by <kvigor> Wed Oct  4 16:57:26 2000
2 #LyX 1.0 (C) 1995-1999 Matthias Ettrich and the LyX Team
3 \lyxformat 2.15
4 \textclass article
5 \language english
6 \inputencoding default
7 \fontscheme default
8 \graphics default
9 \paperfontsize default
10 \spacing single 
11 \papersize Default
12 \paperpackage a4
13 \use_geometry 0
14 \use_amsmath 0
15 \paperorientation portrait
16 \secnumdepth 3
17 \tocdepth 3
18 \paragraph_separation indent
19 \defskip medskip
20 \quotes_language english
21 \quotes_times 2
22 \papercolumns 1
23 \papersides 1
24 \paperpagestyle default
25
26 \layout Title
27
28 SDCC Compiler User Guide
29 \layout Author
30
31 Sandeep Dutta (sandeep.dutta@usa.net)
32 \layout Section
33
34 Introduction
35 \layout Standard
36
37 SDCC is a Free ware , retargettable, optimizing ANSI-C compiler.
38  The current version targets Intel 8051 based MCUs, including the Dallas
39  80C390 variant, as well as the Zilog Z80 family.
40  It can be retargetted for other 8 bit MCUs or PICs.
41  The entire source code for the compiler is distributed under GPL.
42  SDCC uses ASXXXX & ASLINK, a Freeware, retargettable assembler & linker.
43  SDCC has extensive MCU (8051) specific language extensions, which lets
44  it utilize the underlying hardware effectively.
45  The front-end (parser) will be enhanced to handle language extensions for
46  other MCUs as and when they are targetted.
47  In addition to the MCU Specific optimizations SDCC also does a host of
48  standard optimizations like
49 \emph on 
50  global sub expression elimination, loop optimizations (loop invariant,
51  strength reduction of induction variables and loop reversing), constant
52  folding & propagation, copy propagation, dead code elimination and jumptables
53  for 'switch' statements.
54  
55 \emph default 
56 For the back-end SDCC uses a global register allocation scheme which should
57  be well suited for other 8 bit MCUs , the peep hole optimizer uses a rule
58  based substitution mechanism which is MCU independent.
59  Supported data-types are 
60 \emph on 
61 short (8 bits, 1 byte), char (8 bits, 1 byte), int (16 bits, 2 bytes ),
62  long (32 bit, 4 bytes) & float (4 byte IEEE).
63  
64 \emph default 
65 The compiler also allows 
66 \emph on 
67 inline assembler code
68 \emph default 
69  to be embedded anywhere in a function.
70  In addition routines developed in assembly can also be called.
71  SDCC also provides an option to report the relative complexity of a function,
72  these functions can then be further optimized , or hand coded in assembly
73  if need be.
74  SDCC also comes with a companion source level debugger SDCDB, the debugger
75  currently uses S51 a freeware simulator for 8051, it can be easily modified
76  to use other simulators.
77  The latest version can be downloaded from 
78 \series bold 
79 http://sdcc.sourceforge.net
80 \layout Standard
81
82 All packages used in this compiler system are 
83 \emph on 
84 opensource
85 \emph default 
86  (freeware); source code for all the sub-packages ( asxxxx assembler/linker
87  , pre-processor and
88 \emph on 
89  gc
90 \emph default 
91  a conservative garbage collector) are distributed with the package.
92  Documentation was created using a freeware word processor (LyX).
93  
94 \layout Standard
95
96 This program is free software; you can redistribute it and/or modify it
97  under the terms of the GNU General Public License as published by the Free
98  Software Foundation; either version 2, or (at your option) any later version.
99  This program is distributed in the hope that it will be useful, but WITHOUT
100  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
101  FOR A PARTICULAR PURPOSE.
102  See the GNU General Public License for more details.
103  You should have received a copy of the GNU General Public License along
104  with this program; if not, write to the Free Software Foundation, 59 Temple
105  Place - Suite 330, Boston, MA 02111-1307, USA.
106  In other words, you are welcome to use, share and improve this program.
107  You are forbidden to forbid anyone else to use, share and improve what
108  you give them.
109  Help stamp out software-hoarding! 
110 \layout Section
111
112 Installation 
113 \begin_inset LatexCommand \label{Installation}
114
115 \end_inset 
116
117
118 \layout Standard
119
120 What you need before you start installation of SDCC ? A C Compiler, not
121  just any C Compiler, gcc to be exact, you can get adventurous and try another
122  compiler , I HAVEN'T tried it.
123  GCC is free , and is available for almost all major platforms.
124  If you are using 
125 \emph on 
126 linux
127 \emph default 
128  you probably already have it, if you are using 
129 \emph on 
130 Windows 9x/NT
131 \emph default 
132  go to 
133 \emph on 
134 http://sources.redhat.com/
135 \emph default 
136  and download 
137 \emph on 
138 Cygwin.
139
140 \emph default 
141  
142 \layout Standard
143
144 After you have installed 
145 \emph on 
146 gcc
147 \emph default 
148  you are ready to build the compiler (sorry no binary distributions yet).
149  SDCC is native to Linux but can be ported to any platform on which GCC
150  is available .
151  Extract the source file package (
152 \emph on 
153 .zip
154 \emph default 
155  or 
156 \emph on 
157 .tar.gz
158 \emph default 
159 ) into some directory , which we shall refer to as 
160 \emph on 
161 SDCCDIR
162 \emph default 
163  from now on.
164 \layout Subsection
165
166 Components of SDCC
167 \begin_inset LatexCommand \label{Components}
168
169 \end_inset 
170
171
172 \layout Subsubsection
173
174 gc ( a conservative garbage collector)
175 \layout Standard
176
177 SDCC relies on this component to do all the memory management, this excellent
178  package is copyrighted by 
179 \emph on 
180 Jans J Boehm(boehm@sgi.com) and Alan J Demers
181 \emph default 
182  but can be used with minimum restrictions.
183  The GC source will be extracted into the directory 
184 \emph on 
185 SDCCDIR/gc.
186
187 \emph default 
188  
189 \layout Subsubsection
190
191 cpp ( C-Preprocessor)
192 \layout Standard
193
194 The preprocessor is extracted into the directory 
195 \emph on 
196 SDCCDIR/cpp
197 \emph default 
198 , it is a modified version of the GNU preprocessor.
199 \layout Subsubsection
200
201 asxxxx & aslink ( The assembler and Linkage Editor)
202 \layout Standard
203
204 This is retargettable assembler & linkage editor, it was developed by Alan
205  Baldwin, John Hartman created the version for 8051, and I (Sandeep) have
206  some enhancements and bug fixes for it to work properly with the SDCC.
207  This component is extracted into the directory 
208 \emph on 
209 SDCCDIR/asxxxx.
210 \layout Subsubsection
211
212 SDCC - The compiler.
213 \layout Standard
214
215 This is the actual compiler, it uses 
216 \emph on 
217 gc
218 \emph default 
219  and invokes the assembler and linkage editor.
220  All files with the prefix 
221 \emph on 
222 SDCC 
223 \emph default 
224 are part of the compiler and is extracted into the the directory 
225 \emph on 
226 SDCCDIR.
227 \layout Subsubsection
228
229 S51 - Simulator
230 \layout Standard
231
232 Version 2.1.8 onwards contains s51 a freeware , opensource simulator developed
233  by Daniel Drotos <drdani@mazsola.iit.uni-miskolc.hu>.
234  The executable is built as part of build process, for more information
235  visit Daniel's website at <http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51/
236 >.
237 \layout Subsubsection
238
239 SDCDB - Source level Debugger.
240 \layout Standard
241
242 SDCDB is the companion source level debugger .
243  The current version of the debugger uses Daniel's Simulator S51, but can
244  be easily changed to use other simulators.
245 \layout Subsection
246
247 Installation for Version <= 2.1.7
248 \layout Standard
249
250 After the package is extracted (
251 \emph on 
252 Windows 95/NT
253 \emph default 
254  users start 
255 \emph on 
256 CYGWIN shell)
257 \emph default 
258 , change to the directory where you extracted the package and give the command.
259 \layout Standard
260
261 ./sdccbuild.sh
262 \layout Standard
263
264 This is a 
265 \emph on 
266 bash
267 \emph default 
268  shell script, it will compile all the above mentioned components and install
269  the executables into the directory 
270 \emph on 
271 SDCCDIR/bin
272 \emph default 
273  make sure you add this directory to your 
274 \emph on 
275 PATH
276 \emph default 
277  environment variable.
278  This script will also compile all the support routines ( library routines
279  ) using SDCC.
280  The support routines are all developed in C and need to be compiled.
281 \layout Subsection
282
283 Installation for Version >= 2.1.8a
284 \layout Standard
285
286 The distribution method from Version 2.1.8a has been changed to be conforment
287  with the 
288 \begin_inset Quotes eld
289 \end_inset 
290
291 autoconf
292 \begin_inset Quotes erd
293 \end_inset 
294
295  utility.
296  The source is now distributed as 
297 \series bold 
298 \size large 
299 \emph on 
300 sdcc-<version number>.tar.gz format
301 \series default 
302 \size default 
303 \emph default 
304  , instead of the older .zip format.
305  The steps for installation are as follows.
306 \layout Subsubsection
307
308 Unpack the sources.
309 \layout Standard
310
311 This is usually done by the following command 
312 \begin_inset Quotes eld
313 \end_inset 
314
315
316 \series bold 
317 \size large 
318 \emph on 
319 gunzip -c sdcc-<version number>.tar.gz | tar -xv -
320 \series default 
321 \size default 
322 \emph default 
323
324 \begin_inset Quotes eld
325 \end_inset 
326
327
328 \layout Subsubsection
329
330 Change to the main source directory (usually sdcc or sdcc-<version number>)
331 \layout Subsubsection
332
333 Issue command to configure your system
334 \layout Standard
335
336 The configure command has several options the most commonly used option
337  is --prefix=<directory name>, where <directory name> is the final location
338  for the sdcc executables and libraries, (default location is /usr/local).
339  The installation process will create the following directory structure
340  under the <directory name> specified.
341  
342 \layout Standard
343
344 bin/ - binary exectables (add to PATH environment variable) 
345 \newline 
346 share/ 
347 \newline 
348
349 \protected_separator 
350
351 \protected_separator 
352
353 \protected_separator 
354
355 \protected_separator 
356
357 \protected_separator 
358
359 \protected_separator 
360 sdcc51inc/ - include header files 
361 \newline 
362
363 \protected_separator 
364
365 \protected_separator 
366
367 \protected_separator 
368
369 \protected_separator 
370
371 \protected_separator 
372
373 \protected_separator 
374 sdcc51lib/ - 
375 \newline 
376
377 \protected_separator 
378
379 \protected_separator 
380
381 \protected_separator 
382
383 \protected_separator 
384
385 \protected_separator 
386
387 \protected_separator 
388
389 \protected_separator 
390
391 \protected_separator 
392
393 \protected_separator 
394
395 \protected_separator 
396
397 \protected_separator 
398
399 \protected_separator 
400
401 \protected_separator 
402 small/ - Object & Library files for small model library 
403 \newline 
404
405 \protected_separator 
406
407 \protected_separator 
408
409 \protected_separator 
410
411 \protected_separator 
412
413 \protected_separator 
414
415 \protected_separator 
416
417 \protected_separator 
418
419 \protected_separator 
420
421 \protected_separator 
422
423 \protected_separator 
424
425 \protected_separator 
426
427 \protected_separator 
428
429 \protected_separator 
430 large/ - Object & library files for large model library 
431 \newline 
432
433 \protected_separator 
434
435 \protected_separator 
436
437 \protected_separator 
438
439 \protected_separator 
440
441 \protected_separator 
442
443 \protected_separator 
444
445 \protected_separator 
446
447 \protected_separator 
448
449 \protected_separator 
450
451 \protected_separator 
452
453 \protected_separator 
454
455 \protected_separator 
456
457 \protected_separator 
458 ds390/ - Object & library files forDS80C390 library
459 \newline 
460
461 \layout Standard
462
463 The command 
464 \layout Standard
465
466
467 \series bold 
468 \size large 
469 \bar under 
470 './configure --prefix=/usr/local
471 \begin_inset Quotes erd
472 \end_inset 
473
474  
475 \layout Standard
476
477 will create configure the compiler to be installed in directory /usr/local/bin.
478 \layout Subsubsection
479
480 make
481 \layout Standard
482
483 After configuration step issue the command 
484 \layout Standard
485
486
487 \series bold 
488 \size large 
489 \bar under 
490
491 \begin_inset Quotes eld
492 \end_inset 
493
494 make
495 \begin_inset Quotes erd
496 \end_inset 
497
498
499 \layout Standard
500
501 This will compile the compiler
502 \layout Subsubsection
503
504
505 \begin_inset Quotes eld
506 \end_inset 
507
508 make install
509 \begin_inset Quotes erd
510 \end_inset 
511
512
513 \layout Standard
514
515 Will install the compiler and libraries in the appropriate directories.
516 \layout Subsubsection
517
518 Special Notes for Windows Users.
519  Provided by Michael Jamet[ mjamet@computer.org] 
520 \layout Standard
521
522 Please note: these instructions are valid for Cygwin versions prior to 1.0.
523  If you have Cygwin 1.0 or later, the generic 
524 \begin_inset Quotes eld
525 \end_inset 
526
527 configure/make/make install
528 \begin_inset Quotes erd
529 \end_inset 
530
531  procedure described above should work as expected from the Cygwin shell.
532  If you have an earlier version of Cygwin, I strongly recommend upgrading.
533  If, however, you insist on using an earlier version, the following instructions
534  should prove helpful.
535 \layout Standard
536
537
538 \protected_separator 
539
540 \layout Standard
541
542
543 \protected_separator 
544  How to install SDCC from source on a Windows 95 or Windows NT 4 system
545  
546 \layout Standard
547
548
549 \protected_separator 
550
551 \layout Standard
552
553
554 \protected_separator 
555  This document describes how to install SDCC on a Win 95 or Win NT 4 system.
556  
557 \layout Standard
558
559
560 \protected_separator 
561  These instructions probably work for Win 98 as well, but have not been
562  
563 \layout Standard
564
565
566 \protected_separator 
567  tested on that platform.
568  
569 \layout Standard
570
571
572 \protected_separator 
573
574 \layout Standard
575
576
577 \protected_separator 
578  There are lots of little differences between UNIX and the Win32 Cygnus
579  
580 \layout Standard
581
582
583 \protected_separator 
584  environment which make porting more difficult than it should be.
585 \protected_separator 
586  If 
587 \layout Standard
588
589
590 \protected_separator 
591  you want the details, please contact me.
592 \protected_separator 
593  Otherwise just follow these 
594 \layout Standard
595
596
597 \protected_separator 
598  instructions.
599  
600 \layout Standard
601
602
603 \protected_separator 
604
605 \layout Standard
606
607
608 \protected_separator 
609  1.
610  Install the Cygnus Software 
611 \layout Standard
612
613
614 \protected_separator 
615  Go to http://sourceware.cygnus.com/cygwin.
616 \protected_separator 
617  Cygnus provides a UNIX like 
618 \layout Standard
619
620
621 \protected_separator 
622  environment for Win 32 systems.
623 \protected_separator 
624  Download "full.exe" and install.
625 \protected_separator 
626  You 
627 \layout Standard
628
629
630 \protected_separator 
631  MUST install it on your C drive.
632 \protected_separator 
633  "full.exe" contains a shell AND many 
634 \layout Standard
635
636
637 \protected_separator 
638  common UNIX utilities.
639  
640 \layout Standard
641
642
643 \protected_separator 
644
645 \layout Standard
646
647
648 \protected_separator 
649  2.
650  Download and Extract the Latest SDCC 
651 \layout Standard
652
653
654 \protected_separator 
655  The latest version can be found at 
656 \layout Standard
657
658
659 \protected_separator 
660
661 \protected_separator 
662  www.geocities.com/ResearchTriange/Forum/1353.
663  
664 \layout Standard
665
666
667 \protected_separator 
668  It can be uncompressed with winzip.
669  
670 \layout Standard
671
672
673 \protected_separator 
674
675 \layout Standard
676
677
678 \protected_separator 
679  3.
680 \protected_separator 
681  Start a Cygnus Shell 
682 \layout Standard
683
684
685 \protected_separator 
686  There should be an entry in the Start Menu for Cygnus.
687 \protected_separator 
688  Invoke the shell.
689  
690 \layout Standard
691
692
693 \protected_separator 
694  This gives you a UNIX like environment.
695 \protected_separator 
696  FROM THIS POINT ON, DIRECTORIES 
697 \layout Standard
698
699
700 \protected_separator 
701  MUST BE SPECIFIED WITH FORWARD SLASHES (/) NOT THE DOS STYLE BACK 
702 \layout Standard
703
704
705 \protected_separator 
706  SLASHES (
707 \backslash 
708 ) BECAUSE THIS IS WHAT UNIX EXPECTS.
709 \protected_separator 
710  - 
711 \layout Standard
712
713
714 \protected_separator 
715
716 \protected_separator 
717  ex.
718  "
719 \backslash 
720 winnt" would be "/winnt" under the shell.
721  
722 \layout Standard
723
724
725 \protected_separator 
726
727 \layout Standard
728
729
730 \protected_separator 
731  4.
732  Change Directory to Where SDCC was extracted (referred to as INSTALLDIR)
733  
734 \layout Standard
735
736
737 \protected_separator 
738
739 \layout Standard
740
741
742 \protected_separator 
743  ex.
744  cd /sdcc218Da.
745 \protected_separator 
746  If you extracted to a drive OTHER THAN C, the drive 
747 \layout Standard
748
749
750 \protected_separator 
751  must be specified as part of the path.
752  For example, if you extracted to 
753 \layout Standard
754
755
756 \protected_separator 
757  your "g drive", type the following: "cd //g/mydir".
758 \protected_separator 
759  You must use "//" 
760 \layout Standard
761
762
763 \protected_separator 
764  to specify the drive.
765  
766 \layout Standard
767
768
769 \protected_separator 
770
771 \layout Standard
772
773
774 \protected_separator 
775  5.
776  Make Dirs Which are Automatically Made During the UNIX Installation 
777 \layout Standard
778
779
780 \protected_separator 
781  From the INSTALLDIR, 
782 \layout Standard
783
784
785 \protected_separator 
786
787 \layout Standard
788
789
790 \protected_separator 
791
792 \protected_separator 
793  mkdir -p bin
794 \protected_separator 
795
796 \protected_separator 
797  (not a typo, just "bin") 
798 \layout Standard
799
800
801 \protected_separator 
802
803 \protected_separator 
804  mkdir -p /bin 
805 \layout Standard
806
807
808 \protected_separator 
809
810 \protected_separator 
811  mkdir -p /usr/local/bin 
812 \layout Standard
813
814
815 \protected_separator 
816
817 \protected_separator 
818  mkdir -p /usr/local/share 
819 \layout Standard
820
821
822 \protected_separator 
823
824 \protected_separator 
825  mkdir -p /usr/local/share/sdcc51lib 
826 \layout Standard
827
828
829 \protected_separator 
830
831 \protected_separator 
832  mkdir -p /usr/local/share/sdcc51inc 
833 \layout Standard
834
835
836 \protected_separator 
837
838 \protected_separator 
839  mkdir -p /tmp 
840 \layout Standard
841
842
843 \protected_separator 
844
845 \layout Standard
846
847
848 \protected_separator 
849  (When a path from the root directory is specified WITHOUT a drive, the
850  
851 \layout Standard
852
853
854 \protected_separator 
855  drive defaults to c.
856 \protected_separator 
857  For example /michael/newuser => c:
858 \backslash 
859 michael
860 \backslash 
861 newuser) 
862 \layout Standard
863
864
865 \protected_separator 
866
867 \layout Standard
868
869
870 \protected_separator 
871  6.
872 \protected_separator 
873  Add Programs to /bin Expected by the Installation Process 
874 \layout Standard
875
876
877 \protected_separator 
878
879 \protected_separator 
880  - Look at your path: echo $PATH 
881 \layout Standard
882
883
884 \protected_separator 
885
886 \protected_separator 
887
888 \protected_separator 
889
890 \protected_separator 
891  One of the fields is the diretory with the CYGNUS programs.
892  
893 \layout Standard
894
895
896 \protected_separator 
897
898 \protected_separator 
899
900 \protected_separator 
901  ex.
902  /CYGNUS/CYGWIN~1/H-I586/BIN 
903 \layout Standard
904
905
906 \protected_separator 
907
908 \layout Standard
909
910
911 \protected_separator 
912
913 \protected_separator 
914  - cd to the directory found above.
915 \protected_separator 
916  You may have to fiddle with the 
917 \layout Standard
918
919
920 \protected_separator 
921
922 \protected_separator 
923
924 \protected_separator 
925
926 \protected_separator 
927  case (upper or lower) here because the PATH is SHOWN as all upper 
928 \layout Standard
929
930
931 \protected_separator 
932
933 \protected_separator 
934
935 \protected_separator 
936
937 \protected_separator 
938  case, but is actually mixed.
939 \protected_separator 
940  To help you along, you may type 
941 \layout Standard
942
943
944 \protected_separator 
945
946 \protected_separator 
947
948 \protected_separator 
949
950 \protected_separator 
951  a letter or 2 followed by the escape key.
952 \protected_separator 
953  The shell will fill 
954 \layout Standard
955
956
957 \protected_separator 
958
959 \protected_separator 
960
961 \protected_separator 
962
963 \protected_separator 
964  out the remaining letters IF THEY describe a unique directory.
965  
966 \layout Standard
967
968
969 \protected_separator 
970
971 \protected_separator 
972
973 \protected_separator 
974
975 \protected_separator 
976  If you have problems here, cd one directory and type "ls".
977 \protected_separator 
978  "ls" 
979 \layout Standard
980
981
982 \protected_separator 
983
984 \protected_separator 
985
986 \protected_separator 
987
988 \protected_separator 
989  is the equivalent of "dir/w".
990  
991 \layout Standard
992
993
994 \protected_separator 
995
996 \layout Standard
997
998
999 \protected_separator 
1000
1001 \protected_separator 
1002  - Copy the following: 
1003 \layout Standard
1004
1005
1006 \protected_separator 
1007
1008 \protected_separator 
1009
1010 \protected_separator 
1011  cp sh.exe /bin 
1012 \layout Standard
1013
1014
1015 \protected_separator 
1016
1017 \protected_separator 
1018
1019 \protected_separator 
1020  cp pwd.exe /bin 
1021 \layout Standard
1022
1023
1024 \protected_separator 
1025
1026 \protected_separator 
1027
1028 \protected_separator 
1029  cp echo.exe /bin 
1030 \layout Standard
1031
1032
1033 \protected_separator 
1034
1035 \layout Standard
1036
1037
1038 \protected_separator 
1039  7.
1040  Go back to the INSTALLDIR 
1041 \layout Standard
1042
1043
1044 \protected_separator 
1045
1046 \protected_separator 
1047  cd INSTALLDIR 
1048 \layout Standard
1049
1050
1051 \protected_separator 
1052  ex.
1053  cd //d/sdcc218Da 
1054 \layout Standard
1055
1056
1057 \protected_separator 
1058
1059 \layout Standard
1060
1061
1062 \protected_separator 
1063  8.
1064  Run the configure Program 
1065 \layout Standard
1066
1067
1068 \protected_separator 
1069
1070 \protected_separator 
1071  ./configure 
1072 \layout Standard
1073
1074
1075 \protected_separator 
1076  The "./" is important because your current directory is NOT in your path.
1077  
1078 \layout Standard
1079
1080
1081 \protected_separator 
1082  Under DOS, your current directory was implicitly always the first entry
1083  
1084 \layout Standard
1085
1086
1087 \protected_separator 
1088  in your path.
1089  
1090 \layout Standard
1091
1092
1093 \protected_separator 
1094
1095 \layout Standard
1096
1097
1098 \protected_separator 
1099  9.
1100  Run make 
1101 \layout Standard
1102
1103
1104 \protected_separator 
1105
1106 \protected_separator 
1107  make 
1108 \layout Standard
1109
1110
1111 \protected_separator 
1112
1113 \layout Standard
1114
1115
1116 \protected_separator 
1117  This process takes quite some time under Win 32.
1118  
1119 \layout Standard
1120
1121
1122 \protected_separator 
1123
1124 \layout Standard
1125
1126
1127 \protected_separator 
1128  10.
1129  Install the Newly Built Software 
1130 \layout Standard
1131
1132
1133 \protected_separator 
1134
1135 \protected_separator 
1136  make install 
1137 \layout Standard
1138
1139
1140 \protected_separator 
1141
1142 \layout Standard
1143
1144
1145 \protected_separator 
1146  This will partially install the software into the /usr/local directories
1147  
1148 \layout Standard
1149
1150
1151 \protected_separator 
1152  created in step 5.
1153 \protected_separator 
1154  What it actually doing is copying the .c, .h and 
1155 \layout Standard
1156
1157
1158 \protected_separator 
1159  library files to directories under /usr/local/share.
1160  
1161 \layout Standard
1162
1163
1164 \protected_separator 
1165
1166 \layout Standard
1167
1168
1169 \protected_separator 
1170  It will NOT be able to install the actual programs (binaries) because 
1171 \layout Standard
1172
1173
1174 \protected_separator 
1175  it does not know programs on Win32 systems have ".exe" extensions.
1176  
1177 \layout Standard
1178
1179
1180 \protected_separator 
1181  For example, it tries to install sdcc instead of sdcc.exe.
1182  
1183 \layout Standard
1184
1185
1186 \protected_separator 
1187
1188 \layout Standard
1189
1190
1191 \protected_separator 
1192  After the automated part is finished, you must manually copy the binaries:
1193  
1194 \layout Standard
1195
1196
1197 \protected_separator 
1198
1199 \protected_separator 
1200  cd bin
1201 \protected_separator 
1202  (This is the bin directory in your INSTALLDIR) 
1203 \layout Standard
1204
1205
1206 \protected_separator 
1207
1208 \protected_separator 
1209  cp * /usr/local/bin 
1210 \layout Standard
1211
1212
1213 \protected_separator 
1214
1215 \layout Standard
1216
1217
1218 \protected_separator 
1219  11.
1220  Make sure /usr/local/bin is in Your PATH 
1221 \layout Standard
1222
1223
1224 \protected_separator 
1225  You may add c:
1226 \backslash 
1227 usr
1228 \backslash 
1229 local
1230 \backslash 
1231 bin to your path however your Win32 system allows.
1232 \protected_separator 
1233  For 
1234 \layout Standard
1235
1236
1237 \protected_separator 
1238  example you may add it to the PATH statement in autoexec.bat.
1239  
1240 \layout Standard
1241
1242
1243 \protected_separator 
1244
1245 \layout Standard
1246
1247
1248 \protected_separator 
1249  Good luck.
1250 \protected_separator 
1251  If you have any questions send them to me or post them 
1252 \layout Standard
1253
1254
1255 \protected_separator 
1256  to the list.
1257 \layout Subsubsection
1258
1259 FreeBSD and other non-GNU unixes
1260 \layout Standard
1261
1262 Note that the SDCC build environment uses Gnu make.
1263  If this is not the default 'make' on your system, you may need to install
1264  it.
1265  On many systems, Gnu make is installed as 'gmake'.
1266 \layout Section
1267
1268 Compiling.
1269 \begin_inset LatexCommand \label{Compiling}
1270
1271 \end_inset 
1272
1273
1274 \layout Subsection
1275
1276 Single Source file projects.
1277 \begin_inset LatexCommand \label{One Source File}
1278
1279 \end_inset 
1280
1281
1282 \layout Standard
1283
1284 For single source file projects the process is very simple.
1285  Compile your programs with the following command
1286 \layout Standard
1287
1288
1289 \size footnotesize 
1290 sdcc sourcefile.c
1291 \layout Standard
1292
1293 The above command will compile ,assemble and link your source file.
1294  Output files are as follows.
1295 \layout Itemize
1296
1297
1298 \size footnotesize 
1299 sourcefile.asm - Assembler source file created by the compiler
1300 \layout Itemize
1301
1302
1303 \size footnotesize 
1304 sourcefile.lst - Assembler listing file created by the Assembler
1305 \layout Itemize
1306
1307
1308 \size footnotesize 
1309 sourcefile.rst - Assembler listing file updated with linkedit information
1310  , created by linkage editor
1311 \layout Itemize
1312
1313
1314 \size footnotesize 
1315 sourcefile.sym - symbol listing for the sourcefile, created by the assembler.
1316 \layout Itemize
1317
1318
1319 \size footnotesize 
1320 sourcefile.rel - Object file created by the assembler, input to Linkage editor.
1321 \layout Itemize
1322
1323
1324 \size footnotesize 
1325 sourcefile.map - The memory map for the load module, created by the Linker.
1326 \layout Itemize
1327
1328
1329 \size footnotesize 
1330 sourcefile.<ihx | s19> - The load module : ihx - Intel hex format (default
1331  ), s19 - Motorola S19 format when compiler option --out-fmt-s19 is used.
1332 \layout Subsection
1333
1334 Projects with multiple source files.
1335 \layout Standard
1336
1337 SDCC can compile only ONE file at a time.
1338  Let us for example assume that you have a project containing the following
1339  files.
1340 \layout Standard
1341
1342
1343 \size footnotesize 
1344 foo1.c ( contains some functions )
1345 \layout Standard
1346
1347
1348 \size footnotesize 
1349 foo2.c (contains some more functions)
1350 \layout Standard
1351
1352
1353 \size footnotesize 
1354 foomain.c (contains more functions and the function main)
1355 \layout Standard
1356
1357 The first two files will need to be compiled separately with the commands
1358 \layout Standard
1359
1360
1361 \size footnotesize 
1362 sdcc -c foo1.c
1363 \layout Standard
1364
1365
1366 \size footnotesize 
1367 sdcc -c foo2.c
1368 \layout Standard
1369
1370 Then compile the source file containing main and link the other files together
1371  with the following command.
1372 \layout Standard
1373
1374
1375 \size footnotesize 
1376 sdcc foomain.c foo1.rel foo2.rel
1377 \layout Standard
1378
1379 Alternatively 
1380 \emph on 
1381 foomain.c
1382 \emph default 
1383  can be separately compiled as well
1384 \layout Standard
1385
1386
1387 \size footnotesize 
1388 sdcc -c foomain.c 
1389 \layout Standard
1390
1391
1392 \size footnotesize 
1393 sdcc foomain.rel foo1.rel foo2.rel
1394 \layout Standard
1395
1396 The file containing the main function MUST be the FIRST file specified in
1397  the command line , since the linkage editor processes file in the order
1398  they are presented to it.
1399 \layout Subsection
1400
1401 Projects with additional libraries.
1402 \layout Standard
1403
1404 Some reusable routines may be compiled into a library, see the documentation
1405  for the assembler and linkage editor in the directory 
1406 \emph on 
1407 SDCCDIR/asxxxx/asxhtm.htm 
1408 \emph default 
1409 this describes how to create a 
1410 \emph on 
1411 .lib
1412 \emph default 
1413  library file, the libraries created in this manner may be included using
1414  the command line, make sure you include the -L <library-path> option to
1415  tell the linker where to look for these files.
1416  Here is an example, assuming you have the source file 
1417 \emph on 
1418 'foomain.c
1419 \emph default 
1420 ' and a library
1421 \emph on 
1422  'foolib.lib'
1423 \emph default 
1424  in the directory 
1425 \emph on 
1426 'mylib'
1427 \emph default 
1428 .
1429 \layout Standard
1430
1431
1432 \size footnotesize 
1433 sdcc foomain.c foolib.lib -L mylib
1434 \layout Standard
1435
1436 Note here that 
1437 \emph on 
1438 'mylib
1439 \emph default 
1440 ' must be an absolute path name.
1441 \layout Standard
1442
1443 The view of the way the linkage editor processes the library files, it is
1444  recommended that you put each source routine in a separate file and combine
1445  them using the .lib file.
1446  For an example see the standard library file 'libsdcc.lib' in the directory
1447  SDCCDIR/sdcc51lib.
1448 \layout Section
1449
1450 Command Line options
1451 \begin_inset LatexCommand \label{Command Line Options}
1452
1453 \end_inset 
1454
1455
1456 \layout Itemize
1457
1458 -mmcs51
1459 \begin_inset LatexCommand \label{-mmcs51}
1460
1461 \end_inset 
1462
1463 Generate code for the MCS51 (8051) family of processors.
1464  This is the default processor target.
1465 \layout Itemize
1466
1467 -mz80
1468 \begin_inset LatexCommand \label{-mz80}
1469
1470 \end_inset 
1471
1472 Generate code for the Z80 family of processors.
1473  Various other options may not be applicable in this mode.
1474  
1475 \layout Itemize
1476
1477
1478 \series bold 
1479 -mds390
1480 \series default 
1481
1482 \begin_inset LatexCommand \label{-mds390}
1483
1484 \end_inset 
1485
1486 Generate code for the DS80C390 processor.
1487  Various other options may not be applicable in this mode.
1488 \layout Itemize
1489
1490
1491 \series bold 
1492 \size large 
1493 --model-large
1494 \emph on 
1495
1496 \begin_inset LatexCommand \label{--model-large}
1497
1498 \end_inset 
1499
1500
1501 \series default 
1502 \size default 
1503 \emph default 
1504  Generate code for Large model programs see section Memory Models for more
1505  details.
1506  If this option is used all source files in the project should be compiled
1507  with this option.
1508  In addition the standard library routines are compiled with small model
1509  , they will need to be recompiled.
1510 \layout Itemize
1511
1512
1513 \series bold 
1514 \size large 
1515 \bar under 
1516 --model-small
1517 \series default 
1518 \emph on 
1519 \bar default 
1520  
1521 \size default 
1522 \emph default 
1523
1524 \begin_inset LatexCommand \label{--model-small}
1525
1526 \end_inset 
1527
1528 Generate code for Small Model programs see section Memory Models for more
1529  details.
1530  This is the default model.
1531 \layout Itemize
1532
1533
1534 \series bold 
1535 \size large 
1536 \bar under 
1537 --model-flat24
1538 \series default 
1539 \emph on 
1540 \bar default 
1541  
1542 \size default 
1543 \emph default 
1544
1545 \begin_inset LatexCommand \ref[--model-flat24]{--model-flat24}
1546
1547 \end_inset 
1548
1549 Generate code forDS80C390 24-bit flat mode.
1550  See section Memory Models for more details.
1551 \layout Itemize
1552
1553
1554 \series bold 
1555 \size large 
1556 \bar under 
1557 --stack-
1558 \emph on 
1559 auto
1560 \series default 
1561 \bar default 
1562  
1563 \size default 
1564 \emph default 
1565
1566 \begin_inset LatexCommand \label{--stack-auto}
1567
1568 \end_inset 
1569
1570 All functions in the source file will be compiled as 
1571 \emph on 
1572 reentrant
1573 \emph default 
1574 , i.e.
1575  the parameters and local variables will be allocated on the stack.
1576  see section Parameters and Local Variables for more details.
1577  If this option is used all source files in the project should be compiled
1578  with this option.
1579  
1580 \layout Itemize
1581
1582
1583 \series bold 
1584 \size large 
1585 \bar under 
1586 --xstack
1587 \series default 
1588 \size default 
1589 \bar default 
1590
1591 \begin_inset LatexCommand \label{--xstack}
1592
1593 \end_inset 
1594
1595  Uses a pseudo stack in the first 256 bytes in the external ram for allocating
1596  variables and passing parameters.
1597  See section on external stack for more details.
1598 \layout Itemize
1599
1600
1601 \series bold 
1602 \size large 
1603 \bar under 
1604 --nogcse
1605 \series default 
1606 \size default 
1607 \bar default 
1608
1609 \begin_inset LatexCommand \label{--nogcse}
1610
1611 \end_inset 
1612
1613  Will not do global subexpression elimination, this option may be used when
1614  the compiler creates undesirably large stack/data spaces to store compiler
1615  temporaries.
1616  A warning message will be generated when this happens and the compiler
1617  will indicate the number of extra bytes it allocated.
1618  It recommended that this option NOT be used , #pragma NOGCSE can be used
1619  to turn off global subexpression elimination for a given function only.
1620 \layout Itemize
1621
1622
1623 \series bold 
1624 \size large 
1625 \bar under 
1626 --noinvariant
1627 \series default 
1628 \size default 
1629 \bar default 
1630
1631 \begin_inset LatexCommand \label{--noinvariant}
1632
1633 \end_inset 
1634
1635  Will not do loop invariant optimizations, this may be turned off for reasons
1636  explained for the previous option .
1637  For more details of loop optimizations performed see section Loop Invariants.It
1638  recommended that this option NOT be used , #pragma NOINVARIANT can be used
1639  to turn off invariant optimizations for a given function only.
1640 \layout Itemize
1641
1642
1643 \series bold 
1644 \size large 
1645 \bar under 
1646 --noinduction
1647 \series default 
1648 \size default 
1649 \bar default 
1650
1651 \begin_inset LatexCommand \label{--noinduction}
1652
1653 \end_inset 
1654
1655  Will not do loop induction optimizations, see section Strength reduction
1656  for more details.It recommended that this option NOT be used , #pragma NOINDUCTI
1657 ON can be used to turn off induction optimizations for given function only.
1658 \layout Itemize
1659
1660
1661 \series bold 
1662 \size large 
1663 \bar under 
1664 --nojtbound 
1665 \series default 
1666 \size default 
1667 \bar default 
1668
1669 \begin_inset LatexCommand \label{--nojtbound}
1670
1671 \end_inset 
1672
1673  Will not generate boundary condition check when switch statements are implement
1674 ed using jump-tables.
1675  See section Switch Statements for more details.It recommended that this
1676  option NOT be used , #pragma NOJTBOUND can be used to turn off boundary
1677  checking for jump tables for a given function only.
1678 \layout Itemize
1679
1680
1681 \series bold 
1682 \size large 
1683 \bar under 
1684 --noloopreverse
1685 \series default 
1686 \bar default 
1687  
1688 \size default 
1689
1690 \begin_inset LatexCommand \label{--noloopreverse}
1691
1692 \end_inset 
1693
1694 Will not do loop reversal optimization
1695 \layout Itemize
1696
1697
1698 \series bold 
1699 \size large 
1700 \bar under 
1701 --noregparms
1702 \series default 
1703 \size default 
1704 \bar default 
1705
1706 \begin_inset LatexCommand \label{--noregparms}
1707
1708 \end_inset 
1709
1710  By default the first parameter is passed using global registers (DPL,DPH,B,ACC).
1711  This option will disable parameter passing using registers.
1712  NOTE: if your program uses the 16/32 bit support routines (for multiplication/d
1713 ivision) these library routines will need to be recompiled with the --noregparms
1714  option as well.
1715 \layout Itemize
1716
1717
1718 \series bold 
1719 \size large 
1720 \bar under 
1721 --callee-saves function1[,function2][,function3]....
1722
1723 \series default 
1724 \size default 
1725 \bar default 
1726  
1727 \begin_inset LatexCommand \label{--callee-saves}
1728
1729 \end_inset 
1730
1731 The compiler by default uses a caller saves convention for register saving
1732  across function calls, however this can cause unneccessary register pushing
1733  & popping when calling small functions from larger functions.
1734  This option can be used to switch the register saving convention for the
1735  function names specified.
1736  The compiler will not save registers when calling these functions, extra
1737  code will be generated at the entry & exit for these functions to save
1738  & restore the registers used by these functions, this can SUBSTANTIALLY
1739  reduce code & improve run time performance of the generated code.
1740  In future the compiler (with interprocedural analysis) will be able to
1741  determine the appropriate scheme to use for each function call.
1742  DO NOT use this option for built-in functions such as _muluint..., if this
1743  option is used for a library function the appropriate library function
1744  needs to be recompiled with the same option.
1745  If the project consists of multiple source files then all the source file
1746  should be compiled with the same --callee-saves option string.
1747  Also see Pragma Directive
1748 \begin_inset LatexCommand \ref{Pragmaa}
1749
1750 \end_inset 
1751
1752  CALLEE-SAVES.
1753 \begin_inset LatexCommand \ref{pragma callee-saves}
1754
1755 \end_inset 
1756
1757  .
1758 \layout Itemize
1759
1760
1761 \series bold 
1762 \bar under 
1763 --debug 
1764 \series default 
1765 \bar default 
1766
1767 \begin_inset LatexCommand \label{--debug}
1768
1769 \end_inset 
1770
1771 When this option is used the compiler will generate debug information ,
1772  that can be used with the SDCDB.
1773  The debug information is collected in a file with .cdb extension.
1774  For more information see documentation for SDCDB.
1775 \layout Itemize
1776
1777
1778 \series bold 
1779 \size large 
1780 \bar under 
1781 --regextend
1782 \size default 
1783  
1784 \series default 
1785 \bar default 
1786
1787 \begin_inset LatexCommand \label{--regextend}
1788
1789 \end_inset 
1790
1791  This option will cause the compiler to define pseudo registers , if this
1792  option is used, all source files in the project should be compiled with
1793  this option.
1794  See section Register Extension for more details.
1795 \layout Itemize
1796
1797
1798 \series bold 
1799 \size large 
1800 \bar under 
1801 --compile-only
1802 \series default 
1803 \bar default 
1804 (-c) 
1805 \size default 
1806
1807 \begin_inset LatexCommand \label{--compile-only}
1808
1809 \end_inset 
1810
1811  will compile and assemble the source only, will not call the linkage editor.
1812 \layout Itemize
1813
1814
1815 \series bold 
1816 \size large 
1817 \bar under 
1818 --xram-loc 
1819 \series default 
1820 \size default 
1821 \bar default 
1822
1823 \begin_inset LatexCommand \label{--xram-loc}
1824
1825 \end_inset 
1826
1827 <Value> The start location of the external ram, default value is 0.
1828  The value entered can be in Hexadecimal or Decimal format .eg.
1829  --xram-loc 0x8000 or --xram-loc 32768.
1830 \layout Itemize
1831
1832
1833 \series bold 
1834 \size large 
1835 \bar under 
1836 --code-loc
1837 \size default 
1838  
1839 \series default 
1840 \bar default 
1841
1842 \begin_inset LatexCommand \label{--code-loc}
1843
1844 \end_inset 
1845
1846 <Value> The start location of the code segment , default value 0.
1847  Note when this option is used the interrupt vector table is also relocated
1848  to the given address.
1849  The value entered can be in Hexadecimal or Decimal format .eg.
1850  --code-loc 0x8000 or --code-loc 32768.
1851 \layout Itemize
1852
1853
1854 \series bold 
1855 \size large 
1856 \bar under 
1857 --stack-loc
1858 \series default 
1859 \size default 
1860 \bar default 
1861
1862 \begin_inset LatexCommand \label{--stack-loc}
1863
1864 \end_inset 
1865
1866 <Value> The initial value of the stack pointer.
1867  The default value of the stack pointer is 0x07 if only register bank 0
1868  is used, if other register banks are used then the stack pointer is initialized
1869  to the location above the highest register bank used.
1870  eg.
1871  if register banks 1 & 2 are used the stack pointer will default to location
1872  0x18.
1873  The value entered can be in Hexadecimal or Decimal format .eg.
1874  --stack-loc 0x20 or --stack-loc 32.
1875  If all four register banks are used the stack will be placed after the
1876  data segment (equivalent to --stack-after-data)
1877 \layout Itemize
1878
1879
1880 \series bold 
1881 \size large 
1882 \bar under 
1883 --stack-after-data
1884 \series default 
1885 \size default 
1886 \bar default 
1887
1888 \begin_inset LatexCommand \label{--stack-after-data}
1889
1890 \end_inset 
1891
1892 This option will cause the stack to be located in the internal ram after
1893  the data segment.
1894 \layout Itemize
1895
1896
1897 \series bold 
1898 \size large 
1899 \bar under 
1900 --data-loc
1901 \series default 
1902 \bar default 
1903  
1904 \size default 
1905
1906 \begin_inset LatexCommand \label{--data-loc}
1907
1908 \end_inset 
1909
1910 <Value> The start location of the internal ram data segment, the default
1911  value is 0x30.The value entered can be in Hexadecimal or Decimal format
1912  .eg.
1913  --data-loc 0x20 or --data-loc 32.
1914 \layout Itemize
1915
1916
1917 \series bold 
1918 \size large 
1919 \bar under 
1920 --idata-loc
1921 \series default 
1922 \size default 
1923 \bar default 
1924
1925 \begin_inset LatexCommand \label{--idata-loc}
1926
1927 \end_inset 
1928
1929 <Value> The start location of the indirectly addressable internal ram, default
1930  value is 0x80.
1931  The value entered can be in Hexadecimal or Decimal format .eg.
1932  --idata-loc 0x88 or --idata-loc 136.
1933 \layout Itemize
1934
1935
1936 \series bold 
1937 \size large 
1938 \bar under 
1939 --peep-file
1940 \size default 
1941
1942 \begin_inset LatexCommand \label{--peep-file}
1943
1944 \end_inset 
1945
1946  
1947 \series default 
1948 \bar default 
1949 <filename> This option can be used to use additional rules to be used by
1950  the peep hole optimizer.
1951  See section Peep Hole optimizations for details on how to write these rules.
1952 \layout Itemize
1953
1954
1955 \series bold 
1956 \size large 
1957 \bar under 
1958 --lib-path (-L)
1959 \size default 
1960  
1961 \series default 
1962 \bar default 
1963
1964 \begin_inset LatexCommand \label{--lib-path}
1965
1966 \end_inset 
1967
1968 <absolute path to additional libraries> This option is passed to the linkage
1969  editor, additional libraries search path.
1970  The path name must be absolute.
1971  Additional library files may be specified in the command line .
1972  See section Compiling programs for more details.
1973 \layout Itemize
1974
1975
1976 \series bold 
1977 \bar under 
1978 -I <path>
1979 \begin_inset LatexCommand \label{-I}
1980
1981 \end_inset 
1982
1983
1984 \series default 
1985 \bar default 
1986  The additional location where the pre processor will look for <..h> or 
1987 \begin_inset Quotes eld
1988 \end_inset 
1989
1990 ..h
1991 \begin_inset Quotes erd
1992 \end_inset 
1993
1994  files.
1995 \layout Itemize
1996
1997
1998 \series bold 
1999 \size large 
2000 \bar under 
2001 -D<macro[=value]>
2002 \series default 
2003 \size default 
2004 \bar default 
2005  
2006 \begin_inset LatexCommand \label{-D}
2007
2008 \end_inset 
2009
2010 Command line definition of macros.
2011  Passed to the pre processor.
2012 \layout Itemize
2013
2014
2015 \series bold 
2016 \size large 
2017 \bar under 
2018 -E
2019 \series default 
2020 \size default 
2021 \bar default 
2022
2023 \begin_inset LatexCommand \label{-E}
2024
2025 \end_inset 
2026
2027  Run only the C preprocessor.
2028  Preprocess all the C source files specified and output the results to standard
2029  output.
2030 \layout Itemize
2031
2032
2033 \series bold 
2034 \size large 
2035 \bar under 
2036 -M
2037 \bar default 
2038
2039 \begin_inset LatexCommand \label{-M}
2040
2041 \end_inset 
2042
2043
2044 \series default 
2045 \size default 
2046  Tell the preprocessor to output a rule suitable for make describing the
2047  dependencies of each object file.
2048  For each source file, the preprocessor outputs one make-rule whose target
2049  is the object file name for that source file and whose dependencies are
2050  all the files `#include'd in it.
2051  This rule may be a single line or may be continued with `
2052 \backslash 
2053 '-newline if it is long.
2054  The list of rules is printed on standard output instead of the preprocessed
2055  C program.
2056  `-M' implies `-E'.
2057 \layout Itemize
2058
2059
2060 \series bold 
2061 \size large 
2062 \bar under 
2063 -C
2064 \series default 
2065 \size default 
2066 \bar default 
2067  
2068 \begin_inset LatexCommand \label{-C}
2069
2070 \end_inset 
2071
2072 Tell the preprocessor not to discard comments.
2073  Used with the `-E' option.
2074 \layout Itemize
2075
2076
2077 \series bold 
2078 \size large 
2079 \bar under 
2080 -MM 
2081 \series default 
2082 \size default 
2083 \bar default 
2084
2085 \begin_inset LatexCommand \label{-MM}
2086
2087 \end_inset 
2088
2089 Like `-M' but the output mentions only the user header files included with
2090  `#include file"'.
2091  System header files included with `#include <file>' are omitted.
2092 \layout Itemize
2093
2094
2095 \series bold 
2096 \size large 
2097 \bar under 
2098 -Aquestion(answer)
2099 \series default 
2100 \size default 
2101 \bar default 
2102
2103 \begin_inset LatexCommand \label{-Aquestion(answer)}
2104
2105 \end_inset 
2106
2107  Assert the answer answer for question, in case it is tested with a preprocessor
2108  conditional such as `#if #question(answer)'.
2109  `-A-' disables the standard asser- tions that normally describe the target
2110  machine.
2111 \layout Itemize
2112
2113
2114 \series bold 
2115 \size large 
2116 \bar under 
2117 -Aquestion
2118 \series default 
2119 \size default 
2120 \bar default 
2121
2122 \begin_inset LatexCommand \label{-Aquestion}
2123
2124 \end_inset 
2125
2126  (answer) Assert the answer answer for question, in case it is tested with
2127  a preprocessor conditional such as `#if #question(answer)'.
2128  `-A-' disables the standard assertions that normally describe the target
2129  machine.
2130 \layout Itemize
2131
2132
2133 \series bold 
2134 \size large 
2135 \bar under 
2136 -Umacro
2137 \series default 
2138 \size default 
2139 \bar default 
2140
2141 \begin_inset LatexCommand \label{-Umacro}
2142
2143 \end_inset 
2144
2145  Undefine macro macro.
2146  `-U' options are evaluated after all `-D' options, but before any `-include'
2147  and `-imac- ros' options.
2148 \layout Itemize
2149
2150
2151 \series bold 
2152 \size large 
2153 \bar under 
2154 -dM
2155 \series default 
2156 \size default 
2157 \bar default 
2158
2159 \begin_inset LatexCommand \label{-dM}
2160
2161 \end_inset 
2162
2163  Tell the preprocessor to output only a list of the mac- ro definitions
2164  that are in effect at the end of prepro- cessing.
2165  Used with the `-E' option.
2166 \layout Itemize
2167
2168
2169 \series bold 
2170 \size large 
2171 \bar under 
2172 -dD
2173 \series default 
2174 \size default 
2175 \bar default 
2176  
2177 \begin_inset LatexCommand \label{-dD}
2178
2179 \end_inset 
2180
2181 Tell the preprocessor to pass all macro definitions into the output, in
2182  their proper sequence in the rest of the output.
2183 \layout Itemize
2184
2185
2186 \series bold 
2187 \size large 
2188 \bar under 
2189 -dN 
2190 \series default 
2191 \size default 
2192 \bar default 
2193
2194 \begin_inset LatexCommand \label{-dN}
2195
2196 \end_inset 
2197
2198 Like `-dD' except that the macro arguments and contents are omitted.
2199  Only `#define name' is included in the output.
2200 \layout Itemize
2201
2202
2203 \series bold 
2204 \size large 
2205 \bar under 
2206 -S 
2207 \series default 
2208 \size default 
2209 \bar default 
2210
2211 \begin_inset LatexCommand \label{-S}
2212
2213 \end_inset 
2214
2215 Stop after the stage of compilation proper; do not as- semble.
2216  The output is an assembler code file for the input file specified.
2217 \layout Itemize
2218
2219
2220 \series bold 
2221 \bar under 
2222 -Wa asmOption[,asmOption]
2223 \series default 
2224 \bar default 
2225 ...
2226  Pass the asmOption to the assembler
2227 \layout Itemize
2228
2229
2230 \series bold 
2231 \bar under 
2232 -Wl linkOption[,linkOption]
2233 \series default 
2234 \bar default 
2235  ..
2236  Pass the linkOption to the linker.
2237 \layout Itemize
2238
2239
2240 \series bold 
2241 \size large 
2242 \bar under 
2243 --int-long-reent
2244 \series default 
2245 \bar default 
2246  
2247 \size default 
2248
2249 \begin_inset LatexCommand \label{--int-long-rent}
2250
2251 \end_inset 
2252
2253  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
2254  Note by default these libraries are compiled as non-reentrant.
2255  See section Installation for more details.
2256 \layout Itemize
2257
2258
2259 \series bold 
2260 \size large 
2261 \bar under 
2262 --cyclomatic
2263 \size default 
2264  
2265 \series default 
2266 \bar default 
2267
2268 \begin_inset LatexCommand \label{--cyclomatic}
2269
2270 \end_inset 
2271
2272 This option will cause the compiler to generate an information message for
2273  each function in the source file.
2274  The message contains some 
2275 \emph on 
2276 important
2277 \emph default 
2278  information about the function.
2279  The number of edges and nodes the compiler detected in the control flow
2280  graph of the function, and most importantly the 
2281 \emph on 
2282 cyclomatic complexity
2283 \emph default 
2284  see section on Cyclomatic Complexity for more details.
2285 \layout Itemize
2286
2287
2288 \series bold 
2289 \size large 
2290 \bar under 
2291 --float-reent
2292 \size default 
2293  
2294 \series default 
2295 \bar default 
2296
2297 \begin_inset LatexCommand \label{--float-reent}
2298
2299 \end_inset 
2300
2301  Floating point library is compiled as reentrant.See section Installation
2302  for more details.
2303 \layout Itemize
2304
2305
2306 \series bold 
2307 \size large 
2308 \bar under 
2309 --out-fmt-ihx
2310 \size default 
2311
2312 \begin_inset LatexCommand \label{--out-fmt-ihx}
2313
2314 \end_inset 
2315
2316  
2317 \series default 
2318 \bar default 
2319 The linker output (final object code) is in Intel Hex format.
2320  (This is the default option).
2321 \layout Itemize
2322
2323
2324 \series bold 
2325 \size large 
2326 \bar under 
2327 --out-fmt-s19
2328 \size default 
2329  
2330 \series default 
2331 \bar default 
2332
2333 \begin_inset LatexCommand \label{--out-fmt-s19}
2334
2335 \end_inset 
2336
2337 The linker output (final object code) is in Motorola S19 format.
2338 \layout Itemize
2339
2340
2341 \series bold 
2342 \size large 
2343 \bar under 
2344 --nooverlay
2345 \series default 
2346 \size default 
2347 \bar default 
2348  
2349 \begin_inset LatexCommand \label{--nooverlay}
2350
2351 \end_inset 
2352
2353  The compiler will not overlay parameters and local variables of any function,
2354  see section Parameters and local variables for more details.
2355 \layout Itemize
2356
2357
2358 \series bold 
2359 \size large 
2360 \bar under 
2361 --main-return
2362 \series default 
2363 \size default 
2364 \bar default 
2365
2366 \begin_inset LatexCommand \label{--main-return}
2367
2368 \end_inset 
2369
2370  This option can be used when the code generated is called by a monitor
2371  program.
2372  The compiler will generate a 'ret' upon return from the 'main' function.
2373  The default option is to lock up i.e.
2374  generate a 'ljmp .' .
2375 \layout Itemize
2376
2377
2378 \series bold 
2379 \size large 
2380 \bar under 
2381 --no-peep
2382 \series default 
2383 \size default 
2384 \bar default 
2385  
2386 \begin_inset LatexCommand \label{--no-peep}
2387
2388 \end_inset 
2389
2390  Disable peep-hole optimization.
2391 \layout Itemize
2392
2393
2394 \series bold 
2395 \size large 
2396 \bar under 
2397 --peep-asm
2398 \series default 
2399 \size default 
2400 \bar default 
2401  
2402 \begin_inset LatexCommand \label{--peep-asm}
2403
2404 \end_inset 
2405
2406  Pass the inline assembler code through the peep hole optimizer.
2407  Can cause unexpected changes to inline assembler code , please go through
2408  the peephole optimizer rules defnied in file 'SDCCpeeph.def' before using
2409  this option.
2410 \layout Itemize
2411
2412
2413 \series bold 
2414 \size large 
2415 \bar under 
2416 --iram-size
2417 \series default 
2418 \size default 
2419 \bar default 
2420
2421 \begin_inset LatexCommand \label{--iram-size}
2422
2423 \end_inset 
2424
2425  <Value> Causes the linker to check if the interal ram usage is within limits
2426  of the given value.
2427 \layout Standard
2428
2429 The following options are provided for the purpose of retargetting and debugging
2430  the compiler .
2431  These provided a means to dump the intermediate code (iCode) generated
2432  by the compiler in human readable form at various stages of the compilation
2433  process.
2434  
2435 \layout Itemize
2436
2437
2438 \series bold 
2439 \size large 
2440 \bar under 
2441 --dumpraw 
2442 \series default 
2443 \size default 
2444 \bar default 
2445
2446 \begin_inset LatexCommand \label{--dumpraw}
2447
2448 \end_inset 
2449
2450 .
2451  This option will cause the compiler to dump the intermediate code into
2452  a file of named 
2453 \emph on 
2454 <source filename>.dumpraw
2455 \emph default 
2456  just after the intermediate code has been generated for a function , i.e.
2457  before any optimizations are done.
2458  The basic blocks at this stage ordered in the depth first number, so they
2459  may not be in sequence of execution.
2460 \layout Itemize
2461
2462
2463 \series bold 
2464 \size large 
2465 \bar under 
2466 --dumpgcse
2467 \series default 
2468 \bar default 
2469 .
2470 \size default 
2471
2472 \begin_inset LatexCommand \label{--dumpgcse}
2473
2474 \end_inset 
2475
2476  Will create a dump if iCode, after global subexpression elimination, into
2477  a file named 
2478 \emph on 
2479 <source filename>.dumpgcse.
2480 \layout Itemize
2481
2482
2483 \series bold 
2484 \size large 
2485 \bar under 
2486 --dumpdeadcode 
2487 \series default 
2488 \size default 
2489 \bar default 
2490
2491 \begin_inset LatexCommand \label{--dumpdeadcode}
2492
2493 \end_inset 
2494
2495 .Will create a dump if iCode, after deadcode elimination, into a file named
2496  
2497 \emph on 
2498 <source filename>.dumpdeadcode.
2499 \layout Itemize
2500
2501
2502 \series bold 
2503 \size large 
2504 \bar under 
2505 --dumploop.
2506
2507 \series default 
2508 \bar default 
2509  
2510 \size default 
2511
2512 \begin_inset LatexCommand \label{--dumploop}
2513
2514 \end_inset 
2515
2516 Will create a dump if iCode, after loop optimizations, into a file named
2517  
2518 \emph on 
2519 <source filename>.dumploop.
2520 \layout Itemize
2521
2522
2523 \series bold 
2524 \size large 
2525 \bar under 
2526 --dumprange.
2527
2528 \series default 
2529 \bar default 
2530  
2531 \size default 
2532
2533 \begin_inset LatexCommand \label{--dump-range}
2534
2535 \end_inset 
2536
2537 Will create a dump if iCode, after live range analysis, into a file named
2538  
2539 \emph on 
2540 <source filename>.dumprange.
2541 \layout Itemize
2542
2543
2544 \series bold 
2545 \size large 
2546 \bar under 
2547 --dumpregassign.
2548
2549 \size default 
2550  
2551 \series default 
2552 \bar default 
2553
2554 \begin_inset LatexCommand \label{--dumpregassign}
2555
2556 \end_inset 
2557
2558 Will create a dump if iCode, after register assignment , into a file named
2559  
2560 \emph on 
2561 <source filename>.dumprassgn.
2562 \layout Itemize
2563
2564
2565 \series bold 
2566 \size large 
2567 \bar under 
2568 --dumpall.
2569  
2570 \series default 
2571 \size default 
2572 \bar default 
2573
2574 \begin_inset LatexCommand \label{--dumpall}
2575
2576 \end_inset 
2577
2578 Will cause all the above mentioned dumps to be created.
2579 \layout Standard
2580
2581 Note that the files created for the dump are appended to each time.
2582  So the files should be deleted manually , before each dump is created.
2583  
2584 \layout Standard
2585
2586 When reporting bugs, it will be very helpful if you could include these
2587  dumps along with the portion of the code that is causing the problem.
2588 \layout Section
2589
2590 Language Extensions
2591 \begin_inset LatexCommand \label{Language Extension}
2592
2593 \end_inset 
2594
2595
2596 \layout Subsection
2597
2598 Storage Classes.
2599 \begin_inset LatexCommand \label{Storage Classes}
2600
2601 \end_inset 
2602
2603
2604 \layout Standard
2605
2606 In addition to the ANSI storage classes SDCC allows the following 8051 specific
2607  storage classes.
2608 \layout Subsubsection
2609
2610 xdata.
2611 \begin_inset LatexCommand \label{xdata}
2612
2613 \end_inset 
2614
2615
2616 \layout Standard
2617
2618 Variables declared with this storage class will be placed in the extern
2619  RAM.
2620  This is the 
2621 \series bold 
2622 default
2623 \series default 
2624  storage class for Large Memory model .
2625 \layout Standard
2626
2627
2628 \size footnotesize 
2629 eg.
2630  
2631 \emph on 
2632 xdata unsigned char xduc;
2633 \layout Subsubsection
2634
2635 data
2636 \begin_inset LatexCommand \label{data}
2637
2638 \end_inset 
2639
2640
2641 \layout Standard
2642
2643 This is the 
2644 \series bold 
2645 default
2646 \series default 
2647  storage class for Small Memory model.
2648  Variables declared with this storage class will be allocated in the internal
2649  RAM.
2650 \layout Standard
2651
2652
2653 \size footnotesize 
2654 eg.
2655
2656 \emph on 
2657  data int iramdata;
2658 \layout Subsubsection
2659
2660 idata
2661 \begin_inset LatexCommand \label{idata}
2662
2663 \end_inset 
2664
2665
2666 \layout Standard
2667
2668 Variables declared with this storage class will be allocated into the indirectly
2669  addressable portion of the internal ram of a 8051 .
2670 \layout Standard
2671
2672
2673 \size footnotesize 
2674 eg.
2675 \emph on 
2676 idata int idi;
2677 \layout Subsubsection
2678
2679 bit
2680 \begin_inset LatexCommand \label{bit}
2681
2682 \end_inset 
2683
2684
2685 \layout Standard
2686
2687 This is a data-type and a storage class specifier.
2688  When a variable is declared as a bit , it is allocated into the bit addressable
2689  memory of 8051.
2690 \layout Standard
2691
2692 eg.
2693 \emph on 
2694 bit iFlag;
2695 \layout Subsubsection
2696
2697 sfr / sbit
2698 \begin_inset LatexCommand \label{sfr / sbit}
2699
2700 \end_inset 
2701
2702
2703 \layout Standard
2704
2705 Like the bit keyword, 
2706 \emph on 
2707 sfr / sbit 
2708 \emph default 
2709 signifies both a data-type and storage class, they are used to describe
2710  the special function registers and special bit variables of a 8051.
2711  
2712 \layout Standard
2713
2714 eg.
2715
2716 \emph on 
2717  
2718 \layout Standard
2719
2720
2721 \emph on 
2722 sfr at 0x80 P0; 
2723 \emph default 
2724 \noun on 
2725 /* special function register P0 at location 0x80 */
2726 \layout Standard
2727
2728
2729 \emph on 
2730 sbit at 0xd7 CY; /* 
2731 \noun on 
2732 CY (Carry Flag) */
2733 \layout Section
2734
2735 Optimizations
2736 \begin_inset LatexCommand \label{Optimizations}
2737
2738 \end_inset 
2739
2740
2741 \layout Standard
2742
2743 SDCC performs a a host of standard optimizations in addition to some MCU
2744  specific optimizations.
2745  
2746 \layout Subsection
2747
2748 Sub-expression elimination
2749 \begin_inset LatexCommand \label{Sub-expression Elimination}
2750
2751 \end_inset 
2752
2753
2754 \layout Standard
2755
2756 The compiler does 
2757 \emph on 
2758 local and global 
2759 \emph default 
2760 common subexpression elimination.
2761 \layout Standard
2762
2763
2764 \family typewriter 
2765 \size scriptsize 
2766 eg.
2767  
2768 \layout Standard
2769
2770
2771 \size small 
2772 i = x + y + 1; 
2773 \size default 
2774
2775 \newline 
2776
2777 \size small 
2778 = x + y;
2779 \layout Standard
2780
2781 will be translated to
2782 \layout Standard
2783
2784
2785 \size small 
2786 iTemp = x + y 
2787 \newline 
2788 i = iTemp + 1 
2789 \newline 
2790 j = iTemp
2791 \layout Standard
2792
2793 Some subexpressions are not as obvious as the above example.
2794 \layout Standard
2795
2796 eg.
2797 \layout Standard
2798
2799
2800 \size small 
2801 a->b[i].c = 10; 
2802 \newline 
2803 a->b[i].d = 11;
2804 \layout Standard
2805
2806 In this case the address arithmetic 
2807 \emph on 
2808 a->b[i] 
2809 \emph default 
2810 will be computed only once; the equivalent code in C would be.
2811 \layout Standard
2812
2813
2814 \size small 
2815 iTemp = a->b[i]; 
2816 \newline 
2817 iTemp.c = 10; 
2818 \newline 
2819 iTemp.d = 11;
2820 \layout Standard
2821
2822 The compiler will try to keep these temporary variables in registers.
2823 \layout Subsection
2824
2825 Dead-Code elimination.
2826 \begin_inset LatexCommand \label{Dead-code elimination}
2827
2828 \end_inset 
2829
2830
2831 \layout Standard
2832
2833 eg.
2834 \layout Standard
2835
2836
2837 \size small 
2838 int global; 
2839 \newline 
2840 void f () { 
2841 \newline 
2842
2843 \protected_separator 
2844
2845 \protected_separator 
2846 int i; 
2847 \newline 
2848
2849 \protected_separator 
2850
2851 \protected_separator 
2852 i = 1; 
2853 \protected_separator 
2854
2855 \protected_separator 
2856
2857 \protected_separator 
2858 /* dead store */ 
2859 \newline 
2860
2861 \protected_separator 
2862
2863 \protected_separator 
2864 global = 1; /* dead store */ 
2865 \newline 
2866
2867 \protected_separator 
2868
2869 \protected_separator 
2870 global = 2; 
2871 \newline 
2872
2873 \protected_separator 
2874
2875 \protected_separator 
2876 return; 
2877 \newline 
2878
2879 \protected_separator 
2880
2881 \protected_separator 
2882 global = 3; /* unreachable */ 
2883 \newline 
2884 }
2885 \layout Standard
2886
2887 will be changed to
2888 \layout Standard
2889
2890
2891 \size footnotesize 
2892 int global; void f () 
2893 \newline 
2894
2895 \protected_separator 
2896  
2897 \protected_separator 
2898  
2899 \newline 
2900
2901 \protected_separator 
2902 global = 2; 
2903 \protected_separator 
2904  
2905 \protected_separator 
2906  
2907 \newline 
2908
2909 \protected_separator 
2910 return; 
2911 \newline 
2912 }
2913 \layout Subsection
2914
2915 Copy-Propagation:
2916 \begin_inset LatexCommand \label{Copy-Propagation}
2917
2918 \end_inset 
2919
2920
2921 \layout Standard
2922
2923 eg.
2924 \layout Standard
2925
2926
2927 \size footnotesize 
2928 int f() { 
2929 \newline 
2930
2931 \protected_separator 
2932
2933 \protected_separator 
2934
2935 \protected_separator 
2936 int i, j; 
2937 \newline 
2938
2939 \protected_separator 
2940
2941 \protected_separator 
2942
2943 \protected_separator 
2944 i = 10; 
2945 \newline 
2946
2947 \protected_separator 
2948
2949 \protected_separator 
2950
2951 \protected_separator 
2952 j = i; 
2953 \newline 
2954
2955 \protected_separator 
2956
2957 \protected_separator 
2958
2959 \protected_separator 
2960 return j; 
2961 \newline 
2962 }
2963 \layout Standard
2964
2965 will be changed to 
2966 \layout Standard
2967
2968
2969 \size small 
2970 int f() { 
2971 \newline 
2972
2973 \protected_separator 
2974  
2975 \protected_separator 
2976  int i,j; 
2977 \newline 
2978
2979 \protected_separator 
2980  
2981 \protected_separator 
2982  i = 10; 
2983 \newline 
2984
2985 \protected_separator 
2986  
2987 \protected_separator 
2988  j = 10; 
2989 \newline 
2990
2991 \protected_separator 
2992  
2993 \protected_separator 
2994  return 10; 
2995 \newline 
2996 }
2997 \layout Standard
2998
2999 Note: the dead stores created by this copy propagation will be eliminated
3000  by dead-code elimination .
3001 \layout Subsection
3002
3003 Loop optimizations
3004 \begin_inset LatexCommand \label{Loop Optimizations}
3005
3006 \end_inset 
3007
3008
3009 \layout Standard
3010
3011 Two types of loop optimizations are done by SDCC loop invariant lifting
3012  and strength reduction of loop induction variables.In addition to the strength
3013  reduction the optimizer marks the induction variables and the register
3014  allocator tries to keep the induction variables in registers for the duration
3015  of the loop.
3016  Because of this preference of the register allocator , loop induction optimizat
3017 ion causes an increase in register pressure, which may cause unwanted spilling
3018  of other temporary variables into the stack / data space .
3019  The compiler will generate a warning message when it is forced to allocate
3020  extra space either on the stack or data space.
3021  If this extra space allocation is undesirable then induction optimization
3022  can be eliminated either for the entire source file ( with --noinduction
3023  option) or for a given function only (#pragma NOINDUCTION).
3024 \layout Subsubsection
3025
3026 Loop Invariant:
3027 \begin_inset LatexCommand \label{Loop Invariant}
3028
3029 \end_inset 
3030
3031
3032 \layout Standard
3033
3034 eg
3035 \layout Standard
3036
3037
3038 \size small 
3039 for (i = 0 ; i < 100 ; i ++) 
3040 \newline 
3041
3042 \protected_separator 
3043  
3044 \protected_separator 
3045  
3046 \protected_separator 
3047 f += k + l;
3048 \layout Standard
3049
3050 changed to
3051 \layout Standard
3052
3053
3054 \size small 
3055 itemp = k + l; 
3056 \newline 
3057 for ( i = 0; i < 100; i++ ) f += itemp;
3058 \layout Standard
3059
3060 As mentioned previously some loop invariants are not as apparent, all static
3061  address computations are also moved out of the loop.
3062 \layout Subsubsection
3063
3064 Strength reduction :
3065 \begin_inset LatexCommand \label{Strength Reduction}
3066
3067 \end_inset 
3068
3069
3070 \layout Standard
3071
3072 This optimization substitutes an expression by a cheaper expression.
3073 \layout Standard
3074
3075 eg.
3076 \layout Standard
3077
3078
3079 \size small 
3080 for (i=0;i < 100; i++) ar[i*5] = i*3;
3081 \layout Standard
3082
3083 changed to
3084 \layout Standard
3085
3086
3087 \size small 
3088 itemp1 = 0; 
3089 \newline 
3090 itemp2 = 0; 
3091 \newline 
3092 for (i=0;i< 100;i++) { 
3093 \newline 
3094
3095 \protected_separator 
3096  
3097 \protected_separator 
3098  
3099 \protected_separator 
3100 ar[itemp1] = itemp2; 
3101 \newline 
3102
3103 \protected_separator 
3104  
3105 \protected_separator 
3106  
3107 \protected_separator 
3108 itemp1 += 5; 
3109 \newline 
3110
3111 \protected_separator 
3112  
3113 \protected_separator 
3114  
3115 \protected_separator 
3116 itemp2 += 3; 
3117 \newline 
3118 }
3119 \layout Standard
3120
3121 The more expensive multiplication is changed to a less expensive addition.
3122 \layout Subsubsection
3123
3124 Loop reversing:
3125 \begin_inset LatexCommand \label{Loop reversing}
3126
3127 \end_inset 
3128
3129
3130 \layout Standard
3131
3132 This optimization is done to reduce the overhead of checking loop boundaries
3133  for every iteration.
3134  Some simple loops can be reversed and implemented using a 
3135 \begin_inset Quotes eld
3136 \end_inset 
3137
3138 decrement and jump if not zero
3139 \begin_inset Quotes erd
3140 \end_inset 
3141
3142  instruction.
3143  SDCC checks for the following criterion to determine if a loop is reversible
3144  (note: more sophisticated compiers use data-dependency analysis to make
3145  this determination, SDCC uses a more simple minded analysis).
3146 \layout Itemize
3147
3148 The 'for' loop is of the form 
3149 \newline 
3150
3151 \begin_inset Quotes eld
3152 \end_inset 
3153
3154 for ( <symbol> = <expression> ; <sym> [< | <=] <expression> ; [<sym>++ |
3155  <sym> += 1])
3156 \newline 
3157
3158 \protected_separator 
3159
3160 \protected_separator 
3161
3162 \protected_separator 
3163
3164 \protected_separator 
3165
3166 \protected_separator 
3167
3168 \protected_separator 
3169
3170 \protected_separator 
3171 <for body>
3172 \begin_inset Quotes erd
3173 \end_inset 
3174
3175
3176 \layout Itemize
3177
3178 The <for body> does not contain 
3179 \begin_inset Quotes eld
3180 \end_inset 
3181
3182 continue
3183 \begin_inset Quotes erd
3184 \end_inset 
3185
3186  or 'break
3187 \begin_inset Quotes erd
3188 \end_inset 
3189
3190 .
3191 \layout Itemize
3192
3193 All goto's are contained within the loop.
3194 \layout Itemize
3195
3196 No function calls within the loop.
3197 \layout Itemize
3198
3199 The loop control variable <sym> is not assigned any value within the loop
3200 \layout Itemize
3201
3202 The loop control variable does NOT participate in any arithmetic operation
3203  within the loop.
3204 \layout Itemize
3205
3206 There are NO switch statements in the loop.
3207 \layout Standard
3208
3209 Note djnz instruction can be used for 8-bit values ONLY, therefore it is
3210  advantageous to declare loop control symbols as either 'char' or 'short',
3211  ofcourse this may not be possible on all situations.
3212 \layout Subsection
3213
3214 Algebraic simplifications:
3215 \begin_inset LatexCommand \label{Algebraic Simplifications}
3216
3217 \end_inset 
3218
3219
3220 \layout Standard
3221
3222 SDCC does numerous algebraic simplifications, the following is a small sub-set
3223  of these optimizations.
3224 \layout Standard
3225
3226
3227 \size small 
3228 eg
3229 \emph on 
3230  
3231 \emph default 
3232
3233 \newline 
3234 i = j + 0 ; /* changed to */ i = j; 
3235 \newline 
3236 i /= 2; /* changed to */ i >>= 1; 
3237 \newline 
3238 i = j - j ; /* changed to */ i = 0; 
3239 \newline 
3240 i = j / 1 ; /* changed to */ i = j;
3241 \layout Standard
3242
3243 Note the subexpressions given above are generally introduced by macro expansions
3244  or as a result of copy/constant propagation.
3245 \layout Subsection
3246
3247 'switch' statements.
3248 \begin_inset LatexCommand \label{Switch Statement}
3249
3250 \end_inset 
3251
3252
3253 \layout Standard
3254
3255 SDCC changes switch statements to jump tables when the following conditions
3256  are true.
3257  
3258 \layout Itemize
3259
3260 The case labels are in numerical sequence , the labels need not be in order,
3261  and the starting number need not be one or zero.
3262 \layout Standard
3263
3264 eg 
3265 \layout Standard
3266
3267
3268 \size small 
3269 switch(i) {
3270 \protected_separator 
3271  
3272 \protected_separator 
3273  
3274 \protected_separator 
3275  
3276 \protected_separator 
3277  
3278 \protected_separator 
3279  
3280 \protected_separator 
3281  
3282 \protected_separator 
3283  
3284 \protected_separator 
3285  
3286 \protected_separator 
3287  
3288 \protected_separator 
3289  
3290 \protected_separator 
3291  
3292 \protected_separator 
3293  
3294 \protected_separator 
3295 switch (i) { 
3296 \newline 
3297 case 4:...
3298  
3299 \protected_separator 
3300  
3301 \protected_separator 
3302  
3303 \protected_separator 
3304  
3305 \protected_separator 
3306  
3307 \protected_separator 
3308  
3309 \protected_separator 
3310  
3311 \protected_separator 
3312  
3313 \protected_separator 
3314  
3315 \protected_separator 
3316  
3317 \protected_separator 
3318  
3319 \protected_separator 
3320  
3321 \protected_separator 
3322  
3323 \protected_separator 
3324 case 1: ...
3325  
3326 \newline 
3327 case 5:...
3328  
3329 \protected_separator 
3330  
3331 \protected_separator 
3332  
3333 \protected_separator 
3334  
3335 \protected_separator 
3336  
3337 \protected_separator 
3338  
3339 \protected_separator 
3340  
3341 \protected_separator 
3342  
3343 \protected_separator 
3344  
3345 \protected_separator 
3346  
3347 \protected_separator 
3348  
3349 \protected_separator 
3350  
3351 \protected_separator 
3352  
3353 \protected_separator 
3354 case 2: ...
3355  
3356 \newline 
3357 case 3:...
3358  
3359 \protected_separator 
3360  
3361 \protected_separator 
3362  
3363 \protected_separator 
3364  
3365 \protected_separator 
3366  
3367 \protected_separator 
3368  
3369 \protected_separator 
3370  
3371 \protected_separator 
3372  
3373 \protected_separator 
3374  
3375 \protected_separator 
3376  
3377 \protected_separator 
3378  
3379 \protected_separator 
3380  
3381 \protected_separator 
3382  
3383 \protected_separator 
3384 case 3: ...
3385  
3386 \newline 
3387 case 6:...
3388  
3389 \protected_separator 
3390  
3391 \protected_separator 
3392  
3393 \protected_separator 
3394  
3395 \protected_separator 
3396  
3397 \protected_separator 
3398  
3399 \protected_separator 
3400  
3401 \protected_separator 
3402  
3403 \protected_separator 
3404  
3405 \protected_separator 
3406  
3407 \protected_separator 
3408  
3409 \protected_separator 
3410  
3411 \protected_separator 
3412  
3413 \protected_separator 
3414 case 4: ...
3415  
3416 \newline 
3417 }
3418 \protected_separator 
3419  
3420 \protected_separator 
3421  
3422 \protected_separator 
3423  
3424 \protected_separator 
3425  
3426 \protected_separator 
3427  
3428 \protected_separator 
3429  
3430 \protected_separator 
3431  
3432 \protected_separator 
3433  
3434 \protected_separator 
3435  
3436 \protected_separator 
3437  
3438 \protected_separator 
3439  
3440 \protected_separator 
3441  
3442 \protected_separator 
3443  
3444 \protected_separator 
3445  
3446 \protected_separator 
3447  
3448 \protected_separator 
3449  
3450 \protected_separator 
3451  
3452 \protected_separator 
3453 }
3454 \layout Standard
3455
3456 Both the above switch statements will be implemented using a jump-table.
3457 \layout Itemize
3458
3459 The number of case labels is at least three, since it takes two conditional
3460  statements to handle the boundary conditions.
3461 \layout Itemize
3462
3463 The number of case labels is less than 84, since each label takes 3 bytes
3464  and a jump-table can be utmost 256 bytes long.
3465  
3466 \layout Standard
3467
3468 Switch statements which have gaps in the numeric sequence or those that
3469  have more that 84 case labels can be split into more than one switch statement
3470  for efficient code generation.
3471 \layout Standard
3472
3473 eg
3474 \layout Standard
3475
3476
3477 \size small 
3478 switch (i) { 
3479 \newline 
3480 case 1: ...
3481  
3482 \newline 
3483 case 2: ...
3484  
3485 \newline 
3486 case 3: ...
3487  
3488 \newline 
3489 case 4: ...
3490  
3491 \newline 
3492 case 9: ...
3493  
3494 \newline 
3495 case 10: ...
3496  
3497 \newline 
3498 case 11: ...
3499  
3500 \newline 
3501 case 12: ...
3502  
3503 \newline 
3504 }
3505 \layout Standard
3506
3507 If the above switch statement is broken down into two switch statements
3508 \layout Standard
3509
3510
3511 \size small 
3512 switch (i) { 
3513 \newline 
3514 case 1: ...
3515  
3516 \newline 
3517 case 2: ...
3518  
3519 \newline 
3520 case 3: ...
3521  
3522 \newline 
3523 case 4: ...
3524  
3525 \newline 
3526 }
3527 \layout Standard
3528
3529
3530 \size small 
3531 switch (i) { 
3532 \newline 
3533 case 9: ...
3534  
3535 \newline 
3536 case 10: ...
3537  
3538 \newline 
3539 case 11: ...
3540  
3541 \newline 
3542 case 12:...
3543  
3544 \newline 
3545 }
3546 \layout Standard
3547
3548 then both the switch statements will be implemented using jump-tables whereas
3549  the unmodified switch statement will not be .
3550 \layout Subsection
3551
3552 bit-shifting operations.
3553 \begin_inset LatexCommand \label{bit shifting}
3554
3555 \end_inset 
3556
3557
3558 \layout Standard
3559
3560 Bit shifting is one of the most frequently used operation in embedded programmin
3561 g .
3562  SDCC tries to implement bit-shift operations in the most efficient way
3563  possible.
3564 \layout Standard
3565
3566 eg.
3567 \layout Standard
3568
3569
3570 \size small 
3571 unsigned short i;
3572 \layout Standard
3573
3574
3575 \size small 
3576 ...
3577  
3578 \newline 
3579 i>>= 4; 
3580 \newline 
3581 ..
3582 \layout Standard
3583
3584 generates the following code.
3585 \layout Standard
3586
3587
3588 \size small 
3589 mov a,_i 
3590 \newline 
3591 swap a 
3592 \newline 
3593 anl a,#0x0f 
3594 \newline 
3595 mov _i,a
3596 \layout Standard
3597
3598 In general SDCC will never setup a loop if the shift count is known.
3599  Another example
3600 \layout Standard
3601
3602
3603 \size small 
3604 unsigned int i; 
3605 \newline 
3606 ...
3607  
3608 \newline 
3609 i >>= 9; 
3610 \newline 
3611 ...
3612 \layout Standard
3613
3614 will generate
3615 \layout Standard
3616
3617
3618 \size small 
3619 mov a,(_i + 1) 
3620 \newline 
3621 mov (_i + 1),#0x00 
3622 \newline 
3623 clr c 
3624 \newline 
3625 rrc a 
3626 \newline 
3627 mov _i,a
3628 \layout Standard
3629
3630 Note that SDCC stores numbers in 
3631 \noun on 
3632 little-endian 
3633 \noun default 
3634 format (i.e.
3635  lowest order first)
3636 \layout Subsubsection
3637
3638 Bit-rotation:
3639 \begin_inset LatexCommand \label{bit rotation}
3640
3641 \end_inset 
3642
3643
3644 \layout Standard
3645
3646 A special case of the bit-shift operation is bit rotation, SDCC recognizes
3647  the following expression to be a left bit-rotation.
3648 \layout Standard
3649
3650
3651 \size small 
3652 unsigned char i; 
3653 \newline 
3654 ...
3655  
3656 \newline 
3657 i = ( ( i << 1) | ( i >> 7)); 
3658 \newline 
3659 ...
3660 \layout Standard
3661
3662 will generate the following code.
3663 \layout Standard
3664
3665
3666 \size small 
3667 mov a,_i 
3668 \newline 
3669 rl a 
3670 \newline 
3671 mov _i,a
3672 \layout Standard
3673
3674 SDCC uses pattern matching on the parse tree to determine this operation
3675  .Variations of this case will also be recognized as bit-rotation i.e
3676 \emph on 
3677  i = ((i >> 7) | (i << 1)); 
3678 \emph default 
3679 /* left-bit rotation */
3680 \layout Subsection
3681
3682 Highest Order Bit.
3683 \begin_inset LatexCommand \label{Highest Order Bit}
3684
3685 \end_inset 
3686
3687
3688 \layout Standard
3689
3690 It is frequently required to obtain the highest order bit of an integral
3691  type (int,long,short or char types).
3692  SDCC recognizes the following expression to yield the highest order bit
3693  and generates optimized code for it.
3694 \layout Standard
3695
3696
3697 \size small 
3698 eg 
3699 \newline 
3700 unsigned int gint; 
3701 \newline 
3702 foo () { 
3703 \newline 
3704 unsigned char hob; 
3705 \newline 
3706
3707 \protected_separator 
3708
3709 \protected_separator 
3710
3711 \protected_separator 
3712 ...
3713  
3714 \newline 
3715
3716 \protected_separator 
3717
3718 \protected_separator 
3719
3720 \protected_separator 
3721 hob = (gint >> 15) & 1; 
3722 \newline 
3723
3724 \protected_separator 
3725
3726 \protected_separator 
3727
3728 \protected_separator 
3729 ..
3730  
3731 \newline 
3732 }
3733 \layout Standard
3734
3735 Will generate the following code.
3736 \layout Standard
3737
3738
3739 \size small 
3740
3741 \protected_separator 
3742
3743 \protected_separator 
3744
3745 \protected_separator 
3746
3747 \protected_separator 
3748
3749 \protected_separator 
3750
3751 \protected_separator 
3752
3753 \protected_separator 
3754
3755 \protected_separator 
3756
3757 \protected_separator 
3758
3759 \protected_separator 
3760
3761 \protected_separator 
3762
3763 \protected_separator 
3764
3765 \protected_separator 
3766
3767 \protected_separator 
3768
3769 \protected_separator 
3770
3771 \protected_separator 
3772
3773 \protected_separator 
3774
3775 \protected_separator 
3776
3777 \protected_separator 
3778
3779 \protected_separator 
3780
3781 \protected_separator 
3782
3783 \protected_separator 
3784
3785 \protected_separator 
3786
3787 \protected_separator 
3788
3789 \protected_separator 
3790
3791 \protected_separator 
3792
3793 \protected_separator 
3794
3795 \protected_separator 
3796  61 ;
3797 \protected_separator 
3798  hob.c 7 
3799 \newline 
3800
3801 \protected_separator 
3802
3803 \protected_separator 
3804  000A E5*01
3805 \protected_separator 
3806
3807 \protected_separator 
3808
3809 \protected_separator 
3810
3811 \protected_separator 
3812
3813 \protected_separator 
3814
3815 \protected_separator 
3816
3817 \protected_separator 
3818
3819 \protected_separator 
3820
3821 \protected_separator 
3822
3823 \protected_separator 
3824
3825 \protected_separator 
3826
3827 \protected_separator 
3828
3829 \protected_separator 
3830
3831 \protected_separator 
3832
3833 \protected_separator 
3834  62
3835 \protected_separator 
3836
3837 \protected_separator 
3838
3839 \protected_separator 
3840
3841 \protected_separator 
3842
3843 \protected_separator 
3844
3845 \protected_separator 
3846
3847 \protected_separator 
3848
3849 \protected_separator 
3850  mov
3851 \protected_separator 
3852  a,(_gint + 1) 
3853 \newline 
3854
3855 \protected_separator 
3856
3857 \protected_separator 
3858  000C 33
3859 \protected_separator 
3860
3861 \protected_separator 
3862
3863 \protected_separator 
3864
3865 \protected_separator 
3866
3867 \protected_separator 
3868
3869 \protected_separator 
3870
3871 \protected_separator 
3872
3873 \protected_separator 
3874
3875 \protected_separator 
3876
3877 \protected_separator 
3878
3879 \protected_separator 
3880
3881 \protected_separator 
3882
3883 \protected_separator 
3884
3885 \protected_separator 
3886
3887 \protected_separator 
3888
3889 \protected_separator 
3890
3891 \protected_separator 
3892
3893 \protected_separator 
3894  63
3895 \protected_separator 
3896
3897 \protected_separator 
3898
3899 \protected_separator 
3900
3901 \protected_separator 
3902
3903 \protected_separator 
3904
3905 \protected_separator 
3906
3907 \protected_separator 
3908
3909 \protected_separator 
3910  rlc
3911 \protected_separator 
3912  a 
3913 \newline 
3914
3915 \protected_separator 
3916
3917 \protected_separator 
3918  000D E4
3919 \protected_separator 
3920
3921 \protected_separator 
3922
3923 \protected_separator 
3924
3925 \protected_separator 
3926
3927 \protected_separator 
3928
3929 \protected_separator 
3930
3931 \protected_separator 
3932
3933 \protected_separator 
3934
3935 \protected_separator 
3936
3937 \protected_separator 
3938
3939 \protected_separator 
3940
3941 \protected_separator 
3942
3943 \protected_separator 
3944
3945 \protected_separator 
3946
3947 \protected_separator 
3948
3949 \protected_separator 
3950
3951 \protected_separator 
3952
3953 \protected_separator 
3954  64
3955 \protected_separator 
3956
3957 \protected_separator 
3958
3959 \protected_separator 
3960
3961 \protected_separator 
3962
3963 \protected_separator 
3964
3965 \protected_separator 
3966
3967 \protected_separator 
3968
3969 \protected_separator 
3970  clr
3971 \protected_separator 
3972  a 
3973 \newline 
3974
3975 \protected_separator 
3976
3977 \protected_separator 
3978  000E 13
3979 \protected_separator 
3980
3981 \protected_separator 
3982
3983 \protected_separator 
3984
3985 \protected_separator 
3986
3987 \protected_separator 
3988
3989 \protected_separator 
3990
3991 \protected_separator 
3992
3993 \protected_separator 
3994
3995 \protected_separator 
3996
3997 \protected_separator 
3998
3999 \protected_separator 
4000
4001 \protected_separator 
4002
4003 \protected_separator 
4004
4005 \protected_separator 
4006
4007 \protected_separator 
4008
4009 \protected_separator 
4010
4011 \protected_separator 
4012
4013 \protected_separator 
4014  65
4015 \protected_separator 
4016
4017 \protected_separator 
4018
4019 \protected_separator 
4020
4021 \protected_separator 
4022
4023 \protected_separator 
4024
4025 \protected_separator 
4026
4027 \protected_separator 
4028
4029 \protected_separator 
4030  rrc
4031 \protected_separator 
4032  a 
4033 \newline 
4034
4035 \protected_separator 
4036
4037 \protected_separator 
4038  000F F5*02
4039 \protected_separator 
4040
4041 \protected_separator 
4042
4043 \protected_separator 
4044
4045 \protected_separator 
4046
4047 \protected_separator 
4048
4049 \protected_separator 
4050
4051 \protected_separator 
4052
4053 \protected_separator 
4054
4055 \protected_separator 
4056
4057 \protected_separator 
4058
4059 \protected_separator 
4060
4061 \protected_separator 
4062
4063 \protected_separator 
4064
4065 \protected_separator 
4066
4067 \protected_separator 
4068  66
4069 \protected_separator 
4070
4071 \protected_separator 
4072
4073 \protected_separator 
4074
4075 \protected_separator 
4076
4077 \protected_separator 
4078
4079 \protected_separator 
4080
4081 \protected_separator 
4082
4083 \protected_separator 
4084  mov
4085 \protected_separator 
4086  _foo_hob_1_1,a
4087 \layout Standard
4088
4089 Variations of this case however will NOT be recognized .
4090  It is a standard C expression , so I heartily recommend this be the only
4091  way to get the highest order bit, (it is portable).
4092  Of course it will be recognized even if it is embedded in other expressions.
4093 \layout Standard
4094
4095
4096 \size small 
4097 eg.
4098 \layout Standard
4099
4100
4101 \size small 
4102 xyz = gint + ((gint >> 15) & 1);
4103 \layout Standard
4104
4105 will still be recognized.
4106 \layout Subsection
4107
4108 Peep-hole optimizer.
4109 \begin_inset LatexCommand \label{Peep-Hole}
4110
4111 \end_inset 
4112
4113
4114 \layout Standard
4115
4116 The compiler uses a rule based , pattern matching and re-writing mechanism
4117  for peep-hole optimization .
4118  It is inspired by '
4119 \emph on 
4120 copt'
4121 \emph default 
4122  a peep-hole optimizer by Christopher W.
4123  Fraser (cwfraser@microsoft.com).
4124  A default set of rules are compiled into the compiler, additional rules
4125  may be added with the --peep-file <filename> option.
4126  The rule language is best illustrated with examples.
4127 \layout Standard
4128
4129
4130 \size small 
4131 replace { 
4132 \newline 
4133 mov %1,a 
4134 \newline 
4135 mov a,%1 } by { mov %1,a }
4136 \layout Standard
4137
4138 The above rule will the following assembly sequence
4139 \layout Standard
4140
4141
4142 \size small 
4143 mov r1,a 
4144 \newline 
4145 mov a,r1
4146 \layout Standard
4147
4148 to
4149 \layout Standard
4150
4151
4152 \size small 
4153 mov r1,a
4154 \layout Standard
4155
4156 Note: All occurrences of a '%n' ( pattern variable ) must denote the same
4157  string.
4158  With the above rule, the assembly sequence
4159 \layout Standard
4160
4161
4162 \size small 
4163 mov r1,a 
4164 \newline 
4165 mov a,r2
4166 \layout Standard
4167
4168 will remain unmodified.
4169  Other special case optimizations may be added by the user (via --peep-file
4170  option), eg.
4171  some variants of the 8051 MCU allow only 'AJMP' and 'ACALL' , the following
4172  two rules will change all 'LJMP' & 'LCALL' to 'AJMP' & 'ACALL'.
4173 \layout Standard
4174
4175
4176 \size small 
4177 replace { lcall %1 } by { acall %1 } 
4178 \newline 
4179 replace { ljmp %1 } by { ajmp %1 }
4180 \layout Standard
4181
4182 The inline-assembler' code is also passed through the peep hole optimizer,
4183  thus the peephole optimizer can also be used as an assembly level macro
4184  expander.
4185  The rules themselves are MCU dependent whereas the rule language infra-structur
4186 e is MCU independent.
4187  Peephole optimization rules for other MCU can be easily programmed using
4188  the rule language.
4189 \layout Standard
4190
4191 The syntax for a rule is as follows ,
4192 \layout Standard
4193
4194
4195 \size small 
4196 rule := replace [ restart ] '{' <assembly sequence> '
4197 \backslash 
4198 n' 
4199 \newline 
4200
4201 \protected_separator 
4202  
4203 \protected_separator 
4204  
4205 \protected_separator 
4206  
4207 \protected_separator 
4208  
4209 \protected_separator 
4210  
4211 \protected_separator 
4212  
4213 \protected_separator 
4214  
4215 \protected_separator 
4216  
4217 \protected_separator 
4218  
4219 \protected_separator 
4220  
4221 \protected_separator 
4222  
4223 \protected_separator 
4224  
4225 \protected_separator 
4226  
4227 \protected_separator 
4228  '}' by '{' '
4229 \backslash 
4230 n' 
4231 \newline 
4232
4233 \protected_separator 
4234  
4235 \protected_separator 
4236  
4237 \protected_separator 
4238  
4239 \protected_separator 
4240  
4241 \protected_separator 
4242  
4243 \protected_separator 
4244  
4245 \protected_separator 
4246  
4247 \protected_separator 
4248  
4249 \protected_separator 
4250  
4251 \protected_separator 
4252  
4253 \protected_separator 
4254  
4255 \protected_separator 
4256  
4257 \protected_separator 
4258  
4259 \protected_separator 
4260  
4261 \protected_separator 
4262  
4263 \protected_separator 
4264  <assembly sequence> '
4265 \backslash 
4266 n' 
4267 \newline 
4268
4269 \protected_separator 
4270  
4271 \protected_separator 
4272  
4273 \protected_separator 
4274  
4275 \protected_separator 
4276  
4277 \protected_separator 
4278  
4279 \protected_separator 
4280  
4281 \protected_separator 
4282  
4283 \protected_separator 
4284  
4285 \protected_separator 
4286  
4287 \protected_separator 
4288  
4289 \protected_separator 
4290  
4291 \protected_separator 
4292  
4293 \protected_separator 
4294  
4295 \protected_separator 
4296  '}' [if <functionName> ] '
4297 \backslash 
4298 n' 
4299 \newline 
4300 <assembly sequence> := assembly instruction (each instruction including
4301  labels must be on a separate line).
4302 \protected_separator 
4303  
4304 \protected_separator 
4305
4306 \layout Standard
4307
4308 The optimizer will apply to the rules one by one from the top in the sequence
4309  of their appearance, it will terminate when all rules are exhausted.
4310  If the '
4311 \emph on 
4312 restart
4313 \emph default 
4314 ' option is specified, then the optimizer will start matching the rules
4315  again from the top, this option for a rule is expensive (performance),
4316  it is intended to be used in situations where a transformation will trigger
4317  the same rule again.
4318  A good example of this the following rule.
4319 \layout Standard
4320
4321
4322 \size small 
4323 replace restart { 
4324 \newline 
4325 pop %1 
4326 \newline 
4327 push %1 } by { 
4328 \newline 
4329 ; nop 
4330 \newline 
4331 }
4332 \layout Standard
4333
4334 Note that the replace pattern cannot be a blank, but can be a comment line.
4335  Without the '
4336 \emph on 
4337 restart
4338 \emph default 
4339 ' option only the inner most 'pop' 'push' pair would be eliminated.
4340  i.e.
4341 \layout Standard
4342
4343
4344 \size small 
4345 pop ar1 
4346 \newline 
4347 pop ar2 
4348 \newline 
4349 push ar2 
4350 \newline 
4351 push ar1
4352 \layout Standard
4353
4354 would result in
4355 \layout Standard
4356
4357
4358 \size small 
4359 pop ar1 
4360 \newline 
4361 ; nop 
4362 \newline 
4363 push ar1
4364 \layout Standard
4365
4366 with the '
4367 \emph on 
4368 restart
4369 \emph default 
4370 ' option the rule will be applied again to the resulting code and the all
4371  the '
4372 \emph on 
4373 pop' 'push'
4374 \emph default 
4375  pairs will be eliminated to yield
4376 \layout Standard
4377
4378
4379 \size small 
4380 ; nop 
4381 \newline 
4382 ; nop
4383 \layout Standard
4384
4385 A conditional function can be attached to a rule.
4386  Attaching rules are somewhat more involved, let me illustrate this with
4387  an example.
4388 \layout Standard
4389
4390
4391 \size small 
4392 replace { 
4393 \newline 
4394
4395 \protected_separator 
4396  
4397 \protected_separator 
4398  
4399 \protected_separator 
4400 ljmp %5 
4401 \newline 
4402 %2:} by { 
4403 \newline 
4404
4405 \protected_separator 
4406  
4407 \protected_separator 
4408  
4409 \protected_separator 
4410 sjmp %5 
4411 \newline 
4412 %2:} if labelInRange
4413 \layout Standard
4414
4415 The optimizer does a look-up of a function name table defined in function
4416  '
4417 \emph on 
4418 callFuncByName'
4419 \emph default 
4420  in the source file 
4421 \emph on 
4422 SDCCpeeph.c
4423 \emph default 
4424  , with the name 
4425 \emph on 
4426 'labelInRange
4427 \emph default 
4428 ', if it finds a corresponding entry the function is called.
4429  Note there can be no parameters specified for these functions, in this
4430  case the use of 
4431 \emph on 
4432 '%5
4433 \emph default 
4434 ' is crucial, since the function 
4435 \emph on 
4436 labelInRange
4437 \emph default 
4438  expects to find the label in that particular variable (the hash table containin
4439 g the variable bindings is passed as a parameter).
4440  If you want to code more such functions , take a close look at the function
4441  
4442 \emph on 
4443 labelInRange
4444 \emph default 
4445  and the calling mechanism in source file 
4446 \emph on 
4447 SDCCpeeph.c
4448 \emph default 
4449 .
4450  I know this whole thing is a little kludgey , may be some day we will have
4451  some better means.
4452  If you are looking at this file, you will also see the default rules that
4453  are compiled into the compiler, you can your own rules in the default set
4454  there if you get tired of specifying the 
4455 \emph on 
4456 --peep-file
4457 \emph default 
4458  option.
4459 \layout Section
4460
4461 Pointers
4462 \begin_inset LatexCommand \label{Pointers}
4463
4464 \end_inset 
4465
4466
4467 \layout Standard
4468
4469 SDCC allows (via language extensions) pointers to explicitly point to any
4470  of the memory spaces of the 8051.
4471  In addition to the explicit pointers, the compiler also allows a 
4472 \emph on 
4473 _generic
4474 \emph default 
4475  class of pointers which can be used to point to any of the memory spaces.
4476  
4477 \layout Standard
4478
4479 Pointer declaration examples.
4480 \layout Standard
4481
4482
4483 \size small 
4484 /* pointer physically in xternal ram pointing to object in internal ram
4485  */ 
4486 \newline 
4487 data unsigned char * xdata p;
4488 \newline 
4489
4490 \layout Standard
4491
4492
4493 \size small 
4494 /* pointer physically in code rom pointing to data in xdata space */ 
4495 \newline 
4496 xdata unsigned char * code p;
4497 \newline 
4498
4499 \layout Standard
4500
4501
4502 \size small 
4503 /* pointer physically in code space pointing to data in code space */ 
4504 \newline 
4505 code unsigned char * code p;
4506 \newline 
4507
4508 \newline 
4509 /* the folowing is a generic pointer physically located in xdata space */
4510 \newline 
4511 char * xdata p;
4512 \layout Standard
4513
4514 Well you get the idea.
4515  For compatibility with the previous version of the compiler, the following
4516  syntax for pointer declaration is also supported.
4517  Note the above examples will be portable to other commercially available
4518  compilers.
4519 \layout Standard
4520
4521
4522 \size small 
4523 unsigned char _xdata *ucxdp; /* pointer to data in external ram */ 
4524 \newline 
4525 unsigned char _data 
4526 \protected_separator 
4527 *ucdp ; /* pointer to data in internal ram */ 
4528 \newline 
4529 unsigned char _code 
4530 \protected_separator 
4531 *uccp ; /* pointer to data in R/O code space */
4532 \newline 
4533 unsigned char _idata *uccp; 
4534 \protected_separator 
4535 /* pointer to upper 128 bytes of ram */
4536 \layout Standard
4537
4538 All unqualified pointers are treated as 3 - byte '_generic' pointers.
4539  These type of pointers can also to be explicitly declared.
4540 \layout Standard
4541
4542
4543 \size small 
4544 unsigned char _generic *ucgp;
4545 \layout Standard
4546
4547 The highest order byte of the generic pointers contains the data space informati
4548 on.
4549  Assembler support routines are called whenever data is stored or retrieved
4550  using _generic pointers.
4551  These are useful for developing reusable library routines.
4552  Explicitly specifying the pointer type will generate the most efficient
4553  code.
4554  Pointers declared using a mixture of OLD/NEW style could have unpredictable
4555  results.
4556 \layout Section
4557
4558 Parameters & Local Variables
4559 \begin_inset LatexCommand \label{Auto Variables}
4560
4561 \end_inset 
4562
4563
4564 \layout Standard
4565
4566 Automatic (local) variables and parameters to functions can either be placed
4567  on the stack or in data-space.
4568  The default action of the compiler is to place these variables in the internal
4569  RAM ( for small model) or external RAM (for Large model).
4570  They can be placed on the stack either by using the
4571 \emph on 
4572  --stack-auto
4573 \emph default 
4574  compiler option or by using the 'reentrant' keyword in the function declaration.
4575 \layout Standard
4576
4577
4578 \family typewriter 
4579 \size scriptsize 
4580 eg
4581 \layout Standard
4582
4583
4584 \size small 
4585 unsigned short foo( short i) reentrant { 
4586 \newline 
4587 ...
4588  
4589 \newline 
4590 }
4591 \layout Standard
4592
4593 Note that when the parameters & local variables are declared in the internal/ext
4594 ernal ram the functions are non-reentrant.
4595  Since stack space on 8051 is limited the 
4596 \emph on 
4597 'reentrant' 
4598 \emph default 
4599 keyword or the
4600 \emph on 
4601  --stack-auto
4602 \emph default 
4603  option should be used sparingly.
4604  Note the reentrant keyword just means that the parameters & local variables
4605  will be allocated to the stack, it DOES NOT mean that the function is register
4606  bank independent.
4607 \layout Standard
4608
4609 When compiled with the default option (i.e.
4610  non-reentrant ), local variables can be assigned storage classes and absolute
4611  addresses.
4612  
4613 \layout Standard
4614
4615
4616 \family typewriter 
4617 \size scriptsize 
4618 eg
4619 \layout Standard
4620
4621
4622 \size small 
4623 unsigned short foo() { 
4624 \newline 
4625
4626 \protected_separator 
4627  
4628 \protected_separator 
4629 xdata unsigned short i; 
4630 \newline 
4631
4632 \protected_separator 
4633  
4634 \protected_separator 
4635 bit bvar; 
4636 \newline 
4637
4638 \protected_separator 
4639  
4640 \protected_separator 
4641 data at 0x31 unsiged short j; 
4642 \newline 
4643 ...
4644  
4645 \newline 
4646 }
4647 \layout Standard
4648
4649 In the above example the variable 
4650 \emph on 
4651 i
4652 \emph default 
4653  will be allocated in the external ram, 
4654 \emph on 
4655 bvar
4656 \emph default 
4657  in bit addressable space and
4658 \emph on 
4659  j
4660 \emph default 
4661  in internal ram.
4662  When compiled with the 
4663 \emph on 
4664 --stack-auto
4665 \emph default 
4666  or when a function is declared as 
4667 \emph on 
4668 'reentrant'
4669 \emph default 
4670  local variables cannot be assigned storage classes or absolute addresses.
4671 \layout Standard
4672
4673 Parameters however are not allowed any storage class, (storage classes for
4674  parameters will be ignored), their allocation is governed by the memory
4675  model in use , and the reentrancy options.
4676 \layout Subsection
4677
4678 Overlaying
4679 \begin_inset LatexCommand \label{Overlaying}
4680
4681 \end_inset 
4682
4683
4684 \layout Standard
4685
4686 For non-reentrant functions SDCC will try to reduce internal ram space usage
4687  by overlaying parameters and local variables of a function (if possible).
4688  Parameters and local variables of a function will be allocated to an overlayabl
4689 e segment if the function has 
4690 \emph on 
4691 no other function calls and the function is non-reentrant and the memory
4692  model is small.
4693
4694 \emph default 
4695  If an explicit storage class is specified for a local variable , it will
4696  NOT be overplayed.
4697 \layout Standard
4698
4699 Note that the compiler (not the linkage editor) makes the decision for overlayin
4700 g the data items.
4701  Functions that are called from an interrupt service routine should be preceded
4702  by a #pragma NOOVERLAY if they are not reentrant Along the same lines the
4703  compiler does not do any processing with the inline assembler code so the
4704  compiler might incorrectly assign local variables and parameters of a function
4705  into the overlay segment if the only function call from a function is from
4706  inline assembler code, it is safe to use the #pragma NOOVERLAY for functions
4707  which call other functions using inline assembler code.
4708 \layout Standard
4709
4710 Parameters and Local variables of functions that contain 16 or 32 bit multiplica
4711 tion or division will NOT be overlayed since these are implemented using
4712  external functions.
4713 \layout Standard
4714
4715 eg.
4716 \layout Standard
4717
4718
4719 \size small 
4720 #pragma SAVE 
4721 \newline 
4722 #pragma NOOVERLAY 
4723 \newline 
4724 void set_error( unsigned short errcd) 
4725 \newline 
4726
4727 \newline 
4728
4729 \protected_separator 
4730  
4731 \protected_separator 
4732  P3 = errcd; 
4733 \newline 
4734
4735 \newline 
4736 #pragma RESTORE 
4737 \newline 
4738 void some_isr () interrupt 2 using 1 
4739 \newline 
4740
4741 \newline 
4742
4743 \protected_separator 
4744  
4745 \protected_separator 
4746  ...
4747  
4748 \newline 
4749
4750 \protected_separator 
4751  
4752 \protected_separator 
4753  set_error(10); 
4754 \newline 
4755
4756 \protected_separator 
4757  
4758 \protected_separator 
4759  ...
4760  
4761 \newline 
4762 }
4763 \layout Standard
4764
4765 In the above example the parameter 
4766 \emph on 
4767 errcd
4768 \emph default 
4769  for the function 
4770 \emph on 
4771 set_error
4772 \emph default 
4773  would be assigned to the overlayable segment (if the #pragma NOOVERLAY
4774  was not present) , this could cause unpredictable runtime behavior.
4775  The pragma NOOVERLAY ensures that the parameters and local variables for
4776  the function are NOT overlayed.
4777 \layout Section
4778
4779 critical Functions.
4780 \begin_inset LatexCommand \label{Critical}
4781
4782 \end_inset 
4783
4784
4785 \layout Standard
4786
4787 A special keyword may be associated with a function declaring it as '
4788 \emph on 
4789 critical
4790 \emph default 
4791 '.
4792  SDCC will generate code to disable all interrupts upon entry to a critical
4793  function and enable them back before returning .
4794  Note that nesting critical functions may cause unpredictable results.
4795 \layout Standard
4796
4797 eg
4798 \layout Standard
4799
4800
4801 \size small 
4802 int foo () critical 
4803 \newline 
4804
4805 \newline 
4806 ...
4807  
4808 \newline 
4809 ...
4810  
4811 \newline 
4812 }
4813 \layout Standard
4814
4815 The critical attribute maybe used with other attributes like 
4816 \emph on 
4817 reentrant.
4818 \layout Section
4819
4820 Absolute addressing.
4821 \begin_inset LatexCommand \label{Absolute Addressing}
4822
4823 \end_inset 
4824
4825
4826 \layout Standard
4827
4828 Data items can be assigned an absolute address with the 
4829 \emph on 
4830 at <address>
4831 \emph default 
4832  keyword, in addition to a storage class.
4833 \layout Standard
4834
4835 eg.
4836  
4837 \layout Standard
4838
4839
4840 \size small 
4841 xdata at 0x8000 unsigned char PORTA_8255 ;
4842 \layout Standard
4843
4844 In the above example the 
4845 \emph on 
4846 PORTA_8255
4847 \emph default 
4848  will be allocated to the location 0x8000 of the external ram.
4849  
4850 \layout Standard
4851
4852 Note that is this feature is provided to give the programmer access to 
4853 \emph on 
4854 memory mapped
4855 \emph default 
4856  devices attached to the controller.
4857  The compiler does not actually reserve any space for variables declared
4858  in this way (they are implemented with an equate in the assembler), thus
4859  it is left to the programmer to make sure there are no overlaps with other
4860  variables that are declared without the absolute address, the assembler
4861  listing file (.lst) and the linker output files (<filename>.rst) and (<filename>.m
4862 ap) are a good places to look for such overlaps.
4863 \layout Standard
4864
4865 Absolute address can be specified for variables in all storage classes.
4866 \layout Standard
4867
4868
4869 \size small 
4870 eg.
4871 \layout Standard
4872
4873
4874 \size small 
4875 bit at 0x02 bvar;
4876 \layout Standard
4877
4878 The above example will allocate the variable at offset 0x02 in the bit-addressab
4879 le space.
4880  There is no real advantage to assigning absolute addresses to variables
4881  in this manner , unless you want strict control over all the variables
4882  allocated.
4883 \layout Section
4884
4885 Interrupt Service Routines
4886 \begin_inset LatexCommand \label{Interrupt Service Rouines}
4887
4888 \end_inset 
4889
4890
4891 \layout Standard
4892
4893 SDCC allows interrupt service routines to be coded in C, with some extended
4894  keywords.
4895 \layout Standard
4896
4897
4898 \size small 
4899 void timer_isr (void) interrupt 2 using 1 
4900 \newline 
4901
4902 \newline 
4903 ..
4904  
4905 \newline 
4906 }
4907 \layout Standard
4908
4909 The number following the 'interrupt' keyword is the interrupt number this
4910  routine will service.
4911  The compiler will insert a call to this routine in the interrupt vector
4912  table for the interrupt number specified.
4913  The 'using' keyword is used to tell the compiler to use the specified register
4914  bank (8051 specific) when generating code for this function.
4915  Note that when some function is called from an interrupt service routine
4916  it should be preceded by a #pragma NOOVERLAY (if it is not reentrant) .
4917  A special note here, int (16 bit) and long (32 bit) integer division, multiplic
4918 ation & modulus operations are implemented using external support routines
4919  developed in ANSI-C, if an interrupt service routine needs to do any of
4920  these operations then the support routines (as mentioned in a following
4921  section) will have to recompiled using the --stack-auto option and the
4922  source file will need to be compiled using the --int-long-rent compiler
4923  option.
4924 \layout Standard
4925
4926 If you have multiple source files in your project, interrupt service routines
4927  can be present in any of them, but a prototype of the isr MUST be present
4928  in the file that contains the function 
4929 \emph on 
4930 'main'
4931 \emph default 
4932 .
4933 \layout Standard
4934
4935 Interrupt Numbers and the corresponding address & descriptions for the Standard
4936  8051 are listed below.
4937  SDCC will automatically adjust the interrupt vector table to the maximum
4938  interrupt number specified.
4939 \layout Standard
4940
4941 Interrupt # 
4942 \protected_separator 
4943
4944 \protected_separator 
4945
4946 \protected_separator 
4947
4948 \protected_separator 
4949
4950 \protected_separator 
4951
4952 \protected_separator 
4953
4954 \protected_separator 
4955
4956 \protected_separator 
4957 Description 
4958 \protected_separator 
4959
4960 \protected_separator 
4961
4962 \protected_separator 
4963
4964 \protected_separator 
4965
4966 \protected_separator 
4967
4968 \protected_separator 
4969
4970 \protected_separator 
4971
4972 \protected_separator 
4973
4974 \protected_separator 
4975
4976 \protected_separator 
4977 Vector Address 
4978 \newline 
4979
4980 \protected_separator 
4981
4982 \protected_separator 
4983
4984 \protected_separator 
4985
4986 \protected_separator 
4987
4988 \protected_separator 
4989
4990 \protected_separator 
4991
4992 \protected_separator 
4993
4994 \protected_separator 
4995
4996 \protected_separator 
4997
4998 \protected_separator 
4999
5000 \protected_separator 
5001
5002 \protected_separator 
5003
5004 \protected_separator 
5005
5006 \protected_separator 
5007
5008 \protected_separator 
5009
5010 \protected_separator 
5011
5012 \protected_separator 
5013
5014 \protected_separator 
5015 External 0
5016 \protected_separator 
5017
5018 \protected_separator 
5019
5020 \protected_separator 
5021
5022 \protected_separator 
5023
5024 \protected_separator 
5025
5026 \protected_separator 
5027
5028 \protected_separator 
5029
5030 \protected_separator 
5031
5032 \protected_separator 
5033
5034 \protected_separator 
5035
5036 \protected_separator 
5037
5038 \protected_separator 
5039 0x0003 
5040 \newline 
5041
5042 \protected_separator 
5043
5044 \protected_separator 
5045
5046 \protected_separator 
5047
5048 \protected_separator 
5049
5050 \protected_separator 
5051
5052 \protected_separator 
5053
5054 \protected_separator 
5055
5056 \protected_separator 
5057
5058 \protected_separator 
5059
5060 \protected_separator 
5061
5062 \protected_separator 
5063
5064 \protected_separator 
5065
5066 \protected_separator 
5067
5068 \protected_separator 
5069
5070 \protected_separator 
5071
5072 \protected_separator 
5073
5074 \protected_separator 
5075
5076 \protected_separator 
5077 Timer 0
5078 \protected_separator 
5079
5080 \protected_separator 
5081
5082 \protected_separator 
5083
5084 \protected_separator 
5085
5086 \protected_separator 
5087
5088 \protected_separator 
5089
5090 \protected_separator 
5091
5092 \protected_separator 
5093
5094 \protected_separator 
5095
5096 \protected_separator 
5097
5098 \protected_separator 
5099
5100 \protected_separator 
5101
5102 \protected_separator 
5103
5104 \protected_separator 
5105
5106 \protected_separator 
5107 0x000B 
5108 \newline 
5109
5110 \protected_separator 
5111
5112 \protected_separator 
5113
5114 \protected_separator 
5115
5116 \protected_separator 
5117
5118 \protected_separator 
5119
5120 \protected_separator 
5121
5122 \protected_separator 
5123
5124 \protected_separator 
5125
5126 \protected_separator 
5127
5128 \protected_separator 
5129
5130 \protected_separator 
5131
5132 \protected_separator 
5133
5134 \protected_separator 
5135
5136 \protected_separator 
5137
5138 \protected_separator 
5139
5140 \protected_separator 
5141
5142 \protected_separator 
5143
5144 \protected_separator 
5145 External 1
5146 \protected_separator 
5147
5148 \protected_separator 
5149
5150 \protected_separator 
5151
5152 \protected_separator 
5153
5154 \protected_separator 
5155
5156 \protected_separator 
5157
5158 \protected_separator 
5159
5160 \protected_separator 
5161
5162 \protected_separator 
5163
5164 \protected_separator 
5165
5166 \protected_separator 
5167
5168 \protected_separator 
5169 0x0013 
5170 \newline 
5171
5172 \protected_separator 
5173
5174 \protected_separator 
5175
5176 \protected_separator 
5177
5178 \protected_separator 
5179
5180 \protected_separator 
5181
5182 \protected_separator 
5183
5184 \protected_separator 
5185
5186 \protected_separator 
5187
5188 \protected_separator 
5189
5190 \protected_separator 
5191
5192 \protected_separator 
5193
5194 \protected_separator 
5195
5196 \protected_separator 
5197
5198 \protected_separator 
5199
5200 \protected_separator 
5201
5202 \protected_separator 
5203
5204 \protected_separator 
5205
5206 \protected_separator 
5207 Timer 1 
5208 \protected_separator 
5209
5210 \protected_separator 
5211
5212 \protected_separator 
5213
5214 \protected_separator 
5215
5216 \protected_separator 
5217
5218 \protected_separator 
5219
5220 \protected_separator 
5221
5222 \protected_separator 
5223
5224 \protected_separator 
5225
5226 \protected_separator 
5227
5228 \protected_separator 
5229
5230 \protected_separator 
5231
5232 \protected_separator 
5233
5234 \protected_separator 
5235 0x001B 
5236 \newline 
5237
5238 \protected_separator 
5239
5240 \protected_separator 
5241
5242 \protected_separator 
5243
5244 \protected_separator 
5245
5246 \protected_separator 
5247
5248 \protected_separator 
5249
5250 \protected_separator 
5251
5252 \protected_separator 
5253
5254 \protected_separator 
5255
5256 \protected_separator 
5257
5258 \protected_separator 
5259
5260 \protected_separator 
5261
5262 \protected_separator 
5263
5264 \protected_separator 
5265
5266 \protected_separator 
5267
5268 \protected_separator 
5269
5270 \protected_separator 
5271
5272 \protected_separator 
5273 Serial 
5274 \protected_separator 
5275
5276 \protected_separator 
5277
5278 \protected_separator 
5279
5280 \protected_separator 
5281
5282 \protected_separator 
5283
5284 \protected_separator 
5285
5286 \protected_separator 
5287
5288 \protected_separator 
5289
5290 \protected_separator 
5291
5292 \protected_separator 
5293
5294 \protected_separator 
5295
5296 \protected_separator 
5297
5298 \protected_separator 
5299
5300 \protected_separator 
5301
5302 \protected_separator 
5303 0x0023
5304 \layout Standard
5305
5306 If the interrupt service routine is defined without a register bank or with
5307  register bank 0 (using 0), the compiler will save the registers used by
5308  itself on the stack (upon entry and restore them at exit), however if such
5309  an interrupt service routine calls another function then the entire register
5310  bank will be saved on the stack.
5311  This scheme may be advantageous for small interrupt service routines which
5312  have low register usage.
5313 \layout Standard
5314
5315 If the interrupt service routine is defined to be using a specific register
5316  bank then only 
5317 \begin_inset Quotes eld
5318 \end_inset 
5319
5320 a
5321 \begin_inset Quotes erd
5322 \end_inset 
5323
5324 ,
5325 \begin_inset Quotes erd
5326 \end_inset 
5327
5328 b
5329 \begin_inset Quotes erd
5330 \end_inset 
5331
5332  & 
5333 \begin_inset Quotes eld
5334 \end_inset 
5335
5336 dptr
5337 \begin_inset Quotes erd
5338 \end_inset 
5339
5340  are save and restored, if such an interrupt service routine calls another
5341  function (using another register bank) then the entire register bank of
5342  the called function will be saved on the stack.
5343  This scheme is recommended for larger interrupt service routines.
5344 \layout Standard
5345
5346 Calling other functions from an interrupt service routine is not recommended
5347  avoid it if possible.
5348 \layout Section
5349
5350 Startup Code
5351 \begin_inset LatexCommand \label{Startup}
5352
5353 \end_inset 
5354
5355
5356 \layout Standard
5357
5358 The compiler inserts a jump to the C routine 
5359 \series bold 
5360 _sdcc__external__startup() 
5361 \series default 
5362 at the start of the CODE area.
5363  This routine can be found in the file 
5364 \series bold 
5365 SDCCDIR/sdcc51lib/_startup.c
5366 \series default 
5367  , by default this routine returns 0, if this routine returns a non-zero
5368  value , the static & global variable initialization will be skipped and
5369  the function main will be invoked, other wise static & global variables
5370  will be initialized before the function main is invoked.
5371 \layout Section
5372
5373 Inline assembler code.
5374 \begin_inset LatexCommand \label{Inline}
5375
5376 \end_inset 
5377
5378
5379 \layout Standard
5380
5381 SDCC allows the use of in-line assembler with a few restriction as regards
5382  labels.
5383  All labels defined within inline assembler code HAS TO BE of the 
5384 \emph on 
5385 form nnnnn$
5386 \emph default 
5387  where nnnn is a number less than 100 (which implies a limit of utmost 100
5388  inline assembler labels 
5389 \noun on 
5390 per function)
5391 \noun default 
5392 .
5393  It is strongly recommended that each assembly instruction (including labels)
5394  be placed in a separate line ( as the example shows).
5395  When the 
5396 \series bold 
5397 \bar under 
5398 --peep-asm
5399 \series default 
5400 \bar default 
5401  command line option is used, the inline assembler code will be passed through
5402  the peephole optimizer, this might cause some unexpected changes in the
5403  inline assembler code, please go throught the peephole optimizer rules
5404  defined in file 'SDCCpeeph.def' carefully before using this option.
5405 \layout Standard
5406
5407
5408 \size small 
5409 eg
5410 \layout Standard
5411
5412
5413 \size small 
5414 _asm 
5415 \newline 
5416
5417 \protected_separator 
5418  
5419 \protected_separator 
5420  
5421 \protected_separator 
5422  
5423 \protected_separator 
5424  
5425 \protected_separator 
5426 mov b,#10 
5427 \newline 
5428 00001$: 
5429 \newline 
5430
5431 \protected_separator 
5432  
5433 \protected_separator 
5434  
5435 \protected_separator 
5436  
5437 \protected_separator 
5438  
5439 \protected_separator 
5440 djnz b,00001$ 
5441 \newline 
5442 _endasm ;
5443 \layout Standard
5444
5445 The inline assembler code can contain any valid code understood by the assembler
5446  (this includes any assembler directives and comment lines ) .
5447  The compiler does not do any validation of the code within the 
5448 \emph on 
5449 _asm ...
5450  _endasm;
5451 \emph default 
5452  keyword pair.
5453  
5454 \layout Standard
5455
5456 Inline assembler code cannot reference any C-Labels however it can reference
5457  labels defined by the inline assembler.
5458 \layout Standard
5459
5460
5461 \size small 
5462 eg
5463 \layout Standard
5464
5465
5466 \size small 
5467 foo() { 
5468 \newline 
5469 ...
5470  /* some c code */ 
5471 \newline 
5472 _asm 
5473 \newline 
5474
5475 \protected_separator 
5476  
5477 \protected_separator 
5478  
5479 \protected_separator 
5480 ; some assembler code 
5481 \newline 
5482
5483 \protected_separator 
5484  
5485 \protected_separator 
5486  ljmp $0003 
5487 \newline 
5488 _endasm ; 
5489 \newline 
5490 ...
5491  /* some more c code */ 
5492 \newline 
5493 clabel: 
5494 \protected_separator 
5495  /* inline assembler cannot reference this label */ 
5496 \newline 
5497 _asm 
5498 \newline 
5499
5500 \protected_separator 
5501  
5502 \protected_separator 
5503 $0003: ;label (can be reference by inline assembler only) 
5504 \newline 
5505 _endasm ; 
5506 \newline 
5507 ...
5508  
5509 \newline 
5510 }
5511 \layout Standard
5512
5513 In other words inline assembly code can access labels defined in inline
5514  assembly.
5515  The same goes the other way, ie.
5516  labels defines in inline assembly CANNOT be accessed by C statements.
5517 \layout Section
5518
5519 int (16 bit) and long (32 bit ) support.
5520 \begin_inset LatexCommand \label{int and long}
5521
5522 \end_inset 
5523
5524
5525 \layout Standard
5526
5527 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
5528  multiplication and modulus operations are implemented by support routines.
5529  These support routines are all developed in ANSI-C to facilitate porting
5530  to other MCUs.
5531  The following files contain the described routine, all of them can be found
5532  in the directory SDCCDIR/sdcc51lib
5533 \layout Itemize
5534
5535
5536 \size footnotesize 
5537 _mulsint.c - signed 16 bit multiplication (calls _muluint)
5538 \layout Itemize
5539
5540
5541 \size footnotesize 
5542 _muluint.c - unsigned 16 bit multiplication
5543 \layout Itemize
5544
5545
5546 \size footnotesize 
5547 _divsint.c - signed 16 bit division (calls _divuint)
5548 \layout Itemize
5549
5550
5551 \size footnotesize 
5552 _divuint.c - unsigned 16 bit division.
5553 \layout Itemize
5554
5555
5556 \size footnotesize 
5557 _modsint.c - signed 16 bit modulus (call _moduint)
5558 \layout Itemize
5559
5560
5561 \size footnotesize 
5562 _moduint.c - unsigned 16 bit modulus.
5563 \layout Itemize
5564
5565
5566 \size footnotesize 
5567 _mulslong.c - signed 32 bit multiplication (calls _mululong)
5568 \layout Itemize
5569
5570
5571 \size footnotesize 
5572 _mululong.c - unsigned32 bit multiplication.
5573 \layout Itemize
5574
5575
5576 \size footnotesize 
5577 _divslong.c - signed 32 division (calls _divulong)
5578 \layout Itemize
5579
5580
5581 \size footnotesize 
5582 _divulong.c - unsigned 32 division.
5583 \layout Itemize
5584
5585
5586 \size footnotesize 
5587 _modslong.c - signed 32 bit modulus (calls _modulong).
5588 \layout Itemize
5589
5590
5591 \size footnotesize 
5592 _modulong.c - unsigned 32 bit modulus.
5593 \layout Standard
5594
5595 All these routines are compiled as non-reentrant and small model.
5596  Since they are compiled as non-reentrant, interrupt service routines should
5597  not do any of the above operations, if this unavoidable then the above
5598  routines will need to ne compiled with the --stack-auto option, after which
5599  the source program will have to be compiled with --int-long-rent option.
5600 \layout Section
5601
5602 Floating point support
5603 \begin_inset LatexCommand \label{Float}
5604
5605 \end_inset 
5606
5607
5608 \layout Standard
5609
5610 SDCC supports IEEE (single precision 4bytes) floating point numbers.The floating
5611  point support routines are derived from gcc's floatlib.c and consists of
5612  the following routines.
5613  
5614 \layout Itemize
5615
5616
5617 \size footnotesize 
5618 _fsadd.c - add floating point numbers.
5619 \layout Itemize
5620
5621
5622 \size footnotesize 
5623 _fssub.c - subtract floating point numbers
5624 \layout Itemize
5625
5626
5627 \size footnotesize 
5628 _fsdiv.c - divide floating point numbers
5629 \layout Itemize
5630
5631
5632 \size footnotesize 
5633 _fsmul.c - multiply floating point numbers
5634 \layout Itemize
5635
5636
5637 \size footnotesize 
5638 _fs2uchar.c - convert floating point to unsigned char
5639 \layout Itemize
5640
5641
5642 \size footnotesize 
5643 _fs2char.c - convert floating point to signed char.
5644 \layout Itemize
5645
5646
5647 \size footnotesize 
5648 _fs2uint.c - convert floating point to unsigned int.
5649 \layout Itemize
5650
5651
5652 \size footnotesize 
5653 _fs2int.c - convert floating point to signed int.
5654 \layout Itemize
5655
5656
5657 \size footnotesize 
5658 _fs2ulong.c - convert floating point to unsigned long.
5659 \layout Itemize
5660
5661
5662 \size footnotesize 
5663 _fs2long.c - convert floating point to signed long.
5664 \layout Itemize
5665
5666
5667 \size footnotesize 
5668 _uchar2fs.c - convert unsigned char to floating point
5669 \layout Itemize
5670
5671
5672 \size footnotesize 
5673 _char2fs.c - convert char to floating point number
5674 \layout Itemize
5675
5676
5677 \size footnotesize 
5678 _uint2fs.c - convert unsigned int to floating point
5679 \layout Itemize
5680
5681
5682 \size footnotesize 
5683 _int2fs.c - convert int to floating point numbers
5684 \layout Itemize
5685
5686
5687 \size footnotesize 
5688 _ulong2fs.c - convert unsigned long to floating point number
5689 \layout Itemize
5690
5691
5692 \size footnotesize 
5693 _long2fs.c - convert long to floating point number.
5694 \layout Standard
5695
5696 Note if all these routines are used simultaneously the data space might
5697  overflow.
5698  For serious floating point usage it is strongly recommended that the Large
5699  model be used (in which case the floating point routines mentioned above
5700  will need to recompiled with the --model-Large option)
5701 \layout Section
5702
5703 Memory Models
5704 \begin_inset LatexCommand \label{Memory Models}
5705
5706 \end_inset 
5707
5708
5709 \layout Standard
5710
5711 SDCC allows two memory models for MCS51 code.
5712  Modules compiled with different memory models should be combined together,
5713  the results would be unpredictable.
5714  The support routines supplied with the compiler are compiled in small-model
5715  by default, and will need to be recompiled using the large model if the
5716  large model is used.
5717  In general the use of the large model is discouraged.
5718 \layout Standard
5719
5720 When the large model is used all variables declared without a storage class
5721  will be allocated into the external ram, this includes all parameters and
5722  local variables (for non-reentrant functions).
5723  When the small model is used variables without storage class are allocated
5724  in the internal ram.
5725 \layout Standard
5726
5727 Judicious usage of the processor specific storage classes and the 'reentrant'
5728  function type will yield much more efficient code, than using the large-model.
5729  Several optimizations are disabled when the program is compiled using the
5730  large model, it is therefore strongly recommdended that the small model
5731  be used unless absolutely required.
5732 \layout Section
5733
5734 Flat 24 bit addressing model.
5735 \begin_inset LatexCommand \label{--model-flat24}
5736
5737 \end_inset 
5738
5739
5740 \layout Standard
5741
5742 This option generates code for the 24 bit contiguous addressing mode of
5743  the Dallas DS80C390 part.
5744  In this mode, up to four meg of external RAM or code space can be directly
5745  addressed.
5746  See the data sheets at www.dalsemi.com for further information on this part.
5747 \layout Standard
5748
5749 In older versions of the compiler, this option was used with the MCS51 code
5750  generator (-mmcs51).
5751  Now, however, the '390 has it's own code generator, selected by the -mds390
5752  switch.
5753  This code generator currently supports only the flat24 model, but the --model-f
5754 lat24 switch is still required, in case later versions of the code generator
5755  support other models (such as the paged mode of the '390).
5756  The combination of -mmcs51 and --model-flat24 is now depracated.
5757 \layout Standard
5758
5759 Note that the compiler does not generate any code to place the processor
5760  into24 bitmode (it defaults to 8051 compatible mode).
5761  Boot loader or similar code must ensure that the processor is in 24 bit
5762  contiguous addressing mode before calling the SDCC startup code.
5763 \layout Standard
5764
5765 Like the --model-large option, variables will by default be placed into
5766  the XDATA segment.
5767  
5768 \layout Standard
5769
5770 Segments may be placed anywhere in the 4 meg address space using the usual
5771  --*-loc options.
5772  Note that if any segments are located above 64K, the -r flag must be passed
5773  to the linker to generate the proper segment relocations, and the Intel
5774  HEX output format must be used.
5775  The -r flag can be passed to the linker by using the option -Wl-r on the
5776  sdcc command line.
5777 \layout Standard
5778
5779 --stack-10bit:
5780 \layout Standard
5781
5782 This option generates code for the 10 bit stack mode of the Dallas DS80C390
5783  part.
5784  In this mode, the stack is located in the lower 1K of the internal RAM,
5785  which is mapped to 0x400000.
5786 \layout Standard
5787
5788 With this option, sdcc will generate the proper addressing for stack variables.
5789 \layout Standard
5790
5791 Note that the support is incomplete, since it still uses a single byte as
5792  the stack pointer.
5793  This means that only the lower 256 bytes of the potential 1K stack space
5794  can actually be used.
5795  However, this does allow you to reclaim the precious 256 bytes of low RAM
5796  for use for the DATA and IDATA segments.
5797 \layout Standard
5798
5799 The compiler will not generate any code to put the processor into 10 bit
5800  stack mode.
5801  It is important to ensure that the processor is in this mode before calling
5802  any re-entrant functions compiled with this option.
5803 \layout Standard
5804
5805 In principle, this should work with the --stack-auto option, but that has
5806  not been tested.
5807  It is incompatible with the --xstack option.
5808  It also only makes sense if the processor is in 24 bit contiguous addressing
5809  mode (see the --model-flat24 option).
5810 \layout Section
5811
5812 Defines created by the compiler.
5813 \begin_inset LatexCommand \label{Defines.}
5814
5815 \end_inset 
5816
5817
5818 \layout Standard
5819
5820 The compiler creates the following #defines .
5821 \layout Itemize
5822
5823 SDCC - this Symbol is always defined.
5824 \layout Itemize
5825
5826 SDCC_STACK_AUTO - this symbol is defined when --stack-auto option is used.
5827 \layout Itemize
5828
5829 SDCC_MODEL_SMALL - when small model is used.
5830 \layout Itemize
5831
5832 SDCC_MODEL_LARGE - when --model-large is used.
5833 \layout Itemize
5834
5835 SDCC_USE_XSTACK - when --xstack option is used.
5836 \layout Section
5837
5838 Pragmas
5839 \begin_inset LatexCommand \label{Pragmaa}
5840
5841 \end_inset 
5842
5843
5844 \layout Standard
5845
5846 SDCC supports the following 
5847 \emph on 
5848 #pragma 
5849 \emph default 
5850 directives.
5851  This directives are applicable only at a function level.
5852 \layout Itemize
5853
5854
5855 \series bold 
5856 SAVE
5857 \series default 
5858
5859 \begin_inset LatexCommand \label{pragma save}
5860
5861 \end_inset 
5862
5863  - this will save all the current options .
5864 \layout Itemize
5865
5866
5867 \series bold 
5868 RESTORE 
5869 \series default 
5870
5871 \begin_inset LatexCommand \label{pragma restore}
5872
5873 \end_inset 
5874
5875 - will restore the saved options from the last save.
5876  Note that SAVES & RESTOREs cannot be nested.
5877  SDCC uses the same buffer to save the options each time a SAVE is called.
5878 \layout Itemize
5879
5880
5881 \series bold 
5882 NOGCSE
5883 \series default 
5884
5885 \begin_inset LatexCommand \label{pragma nogcse}
5886
5887 \end_inset 
5888
5889  - will stop global subexpression elimination.
5890 \layout Itemize
5891
5892
5893 \series bold 
5894 NOINDUCTION
5895 \series default 
5896  
5897 \begin_inset LatexCommand \label{pragma noinduction}
5898
5899 \end_inset 
5900
5901 - will stop loop induction optimizations .
5902 \layout Itemize
5903
5904
5905 \series bold 
5906 NOJTBOUND
5907 \series default 
5908  
5909 \begin_inset LatexCommand \label{pragma nojtbound}
5910
5911 \end_inset 
5912
5913 - will not generate code for boundary value checking , when switch statements
5914  are turned into jump-tables.
5915 \layout Itemize
5916
5917
5918 \series bold 
5919 NOOVERLAY 
5920 \series default 
5921
5922 \begin_inset LatexCommand \label{pragma nooverlay}
5923
5924 \end_inset 
5925
5926 - the compiler will not overlay the parameters and local variables of a
5927  function.
5928 \layout Itemize
5929
5930
5931 \series bold 
5932 NOLOOPREVERSE
5933 \series default 
5934  
5935 \begin_inset LatexCommand \label{pragma noloopreverse}
5936
5937 \end_inset 
5938
5939 - Will not do loop reversal optimization
5940 \layout Itemize
5941
5942
5943 \series bold 
5944 EXCLUDE NONE | {acc[,b[,dpl[,dph]]]
5945 \series default 
5946
5947 \begin_inset LatexCommand \label{pragma exclude}
5948
5949 \end_inset 
5950
5951  - The exclude pragma disables generation of pair of push/pop instruction
5952  in ISR function (using interrupt keyword).
5953  The directive should be placed immediately before the ISR function definition
5954  and it affects ALL ISR functions following it.
5955  To enable the normal register saving for ISR functions use 
5956 \begin_inset Quotes eld
5957 \end_inset 
5958
5959 #pragma EXCLUDE none
5960 \begin_inset Quotes erd
5961 \end_inset 
5962
5963
5964 \layout Itemize
5965
5966
5967 \series bold 
5968 CALLEE-SAVES function1[,function2[,function3...]]
5969 \series default 
5970
5971 \begin_inset LatexCommand \label{pragma callee-saves}
5972
5973 \end_inset 
5974
5975  - The compiler by default uses a caller saves convention for register saving
5976  across function calls, however this can cause unneccessary register pushing
5977  & popping when calling small functions from larger functions.
5978  This option can be used to switch the register saving convention for the
5979  function names specified.
5980  The compiler will not save registers when calling these functions, extra
5981  code will be generated at the entry & exit for these functions to save
5982  & restore the registers used by these functions, this can SUBSTANTIALLY
5983  reduce code & improve run time performance of the generated code.
5984  In future the compiler (with interprocedural analysis) will be able to
5985  determine the appropriate scheme to use for each function call.
5986  If --callee-saves
5987 \begin_inset LatexCommand \ref{--callee-saves}
5988
5989 \end_inset 
5990
5991  command line option is used, the function names specified in #pragma CALLEE-SAV
5992 ES is appended to the list of functions specified inthe command line.
5993 \layout Standard
5994
5995 The pragma's are intended to be used to turn-off certain optimizations which
5996  might cause the compiler to generate extra stack / data space to store
5997  compiler generated temporary variables.
5998  This usually happens in large functions.
5999  Pragma directives should be used as shown in the following example, they
6000  are used to control options & optimizations for a given function; pragmas
6001  should be placed 
6002 \noun on 
6003 before
6004 \noun default 
6005  and/or 
6006 \noun on 
6007 after
6008 \noun default 
6009  a function, placing pragma's inside a function body could have unpredictable
6010  results.
6011 \layout Standard
6012
6013
6014 \size scriptsize 
6015 eg
6016 \layout Standard
6017
6018
6019 \size scriptsize 
6020 #pragma SAVE 
6021 \protected_separator 
6022  /* save the current settings */ 
6023 \newline 
6024 #pragma NOGCSE /* turnoff global subexpression elimination */ 
6025 \newline 
6026 #pragma NOINDUCTION /* turn off induction optimizations */ 
6027 \newline 
6028 int foo () 
6029 \newline 
6030
6031 \newline 
6032
6033 \protected_separator 
6034  
6035 \protected_separator 
6036  ...
6037  
6038 \newline 
6039
6040 \protected_separator 
6041  
6042 \protected_separator 
6043  /* large code */ 
6044 \newline 
6045
6046 \protected_separator 
6047  
6048 \protected_separator 
6049  ...
6050  
6051 \newline 
6052
6053 \newline 
6054 #pragma RESTORE /* turn the optimizations back on */
6055 \layout Standard
6056
6057 The compiler will generate a warning message when extra space is allocated.
6058  It is strongly recommended that the SAVE and RESTORE pragma's be used when
6059  changing options for a function.
6060 \layout Section
6061
6062 Library routines.
6063 \begin_inset LatexCommand \label{Library}
6064
6065 \end_inset 
6066
6067
6068 \layout Standard
6069
6070 The following library routines are provided for your convenience.
6071 \layout Standard
6072
6073
6074 \series bold 
6075 \size large 
6076 stdio.h 
6077 \series default 
6078 \size default 
6079 - Contains the following functions printf & sprintf these routines are developed
6080  by 
6081 \emph on 
6082 Martijn van Balen <balen@natlab.research.philips.com>.
6083  
6084 \layout Standard
6085
6086
6087 \size scriptsize 
6088 %[flags][width][b|B|l|L]type
6089 \layout Standard
6090
6091
6092 \size scriptsize 
6093
6094 \protected_separator 
6095
6096 \protected_separator 
6097
6098 \protected_separator 
6099
6100 \protected_separator 
6101
6102 \protected_separator 
6103
6104 \protected_separator 
6105
6106 \protected_separator 
6107
6108 \protected_separator 
6109
6110 \protected_separator 
6111
6112 \protected_separator 
6113  flags: -
6114 \protected_separator 
6115
6116 \protected_separator 
6117
6118 \protected_separator 
6119
6120 \protected_separator 
6121
6122 \protected_separator 
6123
6124 \protected_separator 
6125
6126 \protected_separator 
6127  left justify output in specified field width 
6128 \newline 
6129
6130 \protected_separator 
6131
6132 \protected_separator 
6133
6134 \protected_separator 
6135
6136 \protected_separator 
6137
6138 \protected_separator 
6139
6140 \protected_separator 
6141
6142 \protected_separator 
6143
6144 \protected_separator 
6145
6146 \protected_separator 
6147
6148 \protected_separator 
6149
6150 \protected_separator 
6151
6152 \protected_separator 
6153
6154 \protected_separator 
6155
6156 \protected_separator 
6157
6158 \protected_separator 
6159
6160 \protected_separator 
6161  +
6162 \protected_separator 
6163
6164 \protected_separator 
6165
6166 \protected_separator 
6167
6168 \protected_separator 
6169
6170 \protected_separator 
6171
6172 \protected_separator 
6173
6174 \protected_separator 
6175  prefix output with +/- sign if output is signed type 
6176 \newline 
6177
6178 \protected_separator 
6179
6180 \protected_separator 
6181
6182 \protected_separator 
6183
6184 \protected_separator 
6185
6186 \protected_separator 
6187
6188 \protected_separator 
6189
6190 \protected_separator 
6191
6192 \protected_separator 
6193
6194 \protected_separator 
6195
6196 \protected_separator 
6197
6198 \protected_separator 
6199
6200 \protected_separator 
6201
6202 \protected_separator 
6203
6204 \protected_separator 
6205
6206 \protected_separator 
6207
6208 \protected_separator 
6209  space
6210 \protected_separator 
6211
6212 \protected_separator 
6213
6214 \protected_separator 
6215  prefix output with a blank if it's a signed positive value 
6216 \newline 
6217
6218 \protected_separator 
6219
6220 \protected_separator 
6221
6222 \protected_separator 
6223
6224 \protected_separator 
6225
6226 \protected_separator 
6227
6228 \protected_separator 
6229
6230 \protected_separator 
6231
6232 \protected_separator 
6233
6234 \protected_separator 
6235  width:
6236 \protected_separator 
6237
6238 \protected_separator 
6239
6240 \protected_separator 
6241
6242 \protected_separator 
6243
6244 \protected_separator 
6245
6246 \protected_separator 
6247
6248 \protected_separator 
6249
6250 \protected_separator 
6251
6252 \protected_separator 
6253  specifies minimum number of characters outputted for numbers 
6254 \newline 
6255
6256 \protected_separator 
6257
6258 \protected_separator 
6259
6260 \protected_separator 
6261
6262 \protected_separator 
6263
6264 \protected_separator 
6265
6266 \protected_separator 
6267
6268 \protected_separator 
6269
6270 \protected_separator 
6271
6272 \protected_separator 
6273
6274 \protected_separator 
6275
6276 \protected_separator 
6277
6278 \protected_separator 
6279
6280 \protected_separator 
6281
6282 \protected_separator 
6283
6284 \protected_separator 
6285
6286 \protected_separator 
6287
6288 \protected_separator 
6289
6290 \protected_separator 
6291
6292 \protected_separator 
6293
6294 \protected_separator 
6295
6296 \protected_separator 
6297
6298 \protected_separator 
6299
6300 \protected_separator 
6301
6302 \protected_separator 
6303
6304 \protected_separator 
6305  or strings.
6306  
6307 \newline 
6308
6309 \protected_separator 
6310
6311 \protected_separator 
6312
6313 \protected_separator 
6314
6315 \protected_separator 
6316
6317 \protected_separator 
6318
6319 \protected_separator 
6320
6321 \protected_separator 
6322
6323 \protected_separator 
6324
6325 \protected_separator 
6326
6327 \protected_separator 
6328
6329 \protected_separator 
6330
6331 \protected_separator 
6332
6333 \protected_separator 
6334
6335 \protected_separator 
6336
6337 \protected_separator 
6338
6339 \protected_separator 
6340
6341 \protected_separator 
6342
6343 \protected_separator 
6344
6345 \protected_separator 
6346
6347 \protected_separator 
6348
6349 \protected_separator 
6350
6351 \protected_separator 
6352
6353 \protected_separator 
6354
6355 \protected_separator 
6356
6357 \protected_separator 
6358  - For numbers, spaces are added on the left when needed.
6359  
6360 \newline 
6361
6362 \protected_separator 
6363
6364 \protected_separator 
6365
6366 \protected_separator 
6367
6368 \protected_separator 
6369
6370 \protected_separator 
6371
6372 \protected_separator 
6373
6374 \protected_separator 
6375
6376 \protected_separator 
6377
6378 \protected_separator 
6379
6380 \protected_separator 
6381
6382 \protected_separator 
6383
6384 \protected_separator 
6385
6386 \protected_separator 
6387
6388 \protected_separator 
6389
6390 \protected_separator 
6391
6392 \protected_separator 
6393
6394 \protected_separator 
6395
6396 \protected_separator 
6397
6398 \protected_separator 
6399
6400 \protected_separator 
6401
6402 \protected_separator 
6403
6404 \protected_separator 
6405
6406 \protected_separator 
6407
6408 \protected_separator 
6409
6410 \protected_separator 
6411
6412 \protected_separator 
6413
6414 \protected_separator 
6415  If width starts with a zero character, zeroes and used 
6416 \newline 
6417
6418 \protected_separator 
6419
6420 \protected_separator 
6421
6422 \protected_separator 
6423
6424 \protected_separator 
6425
6426 \protected_separator 
6427
6428 \protected_separator 
6429
6430 \protected_separator 
6431
6432 \protected_separator 
6433
6434 \protected_separator 
6435
6436 \protected_separator 
6437
6438 \protected_separator 
6439
6440 \protected_separator 
6441
6442 \protected_separator 
6443
6444 \protected_separator 
6445
6446 \protected_separator 
6447
6448 \protected_separator 
6449
6450 \protected_separator 
6451
6452 \protected_separator 
6453
6454 \protected_separator 
6455
6456 \protected_separator 
6457
6458 \protected_separator 
6459
6460 \protected_separator 
6461
6462 \protected_separator 
6463
6464 \protected_separator 
6465
6466 \protected_separator 
6467
6468 \protected_separator 
6469
6470 \protected_separator 
6471  instead of spaces.
6472  
6473 \newline 
6474
6475 \protected_separator 
6476
6477 \protected_separator 
6478
6479 \protected_separator 
6480
6481 \protected_separator 
6482
6483 \protected_separator 
6484
6485 \protected_separator 
6486
6487 \protected_separator 
6488
6489 \protected_separator 
6490
6491 \protected_separator 
6492
6493 \protected_separator 
6494
6495 \protected_separator 
6496
6497 \protected_separator 
6498
6499 \protected_separator 
6500
6501 \protected_separator 
6502
6503 \protected_separator 
6504
6505 \protected_separator 
6506
6507 \protected_separator 
6508
6509 \protected_separator 
6510
6511 \protected_separator 
6512
6513 \protected_separator 
6514
6515 \protected_separator 
6516
6517 \protected_separator 
6518
6519 \protected_separator 
6520
6521 \protected_separator 
6522
6523 \protected_separator 
6524  - For strings, spaces are are added on the left or right (when 
6525 \newline 
6526
6527 \protected_separator 
6528
6529 \protected_separator 
6530
6531 \protected_separator 
6532
6533 \protected_separator 
6534
6535 \protected_separator 
6536
6537 \protected_separator 
6538
6539 \protected_separator 
6540
6541 \protected_separator 
6542
6543 \protected_separator 
6544
6545 \protected_separator 
6546
6547 \protected_separator 
6548
6549 \protected_separator 
6550
6551 \protected_separator 
6552
6553 \protected_separator 
6554
6555 \protected_separator 
6556
6557 \protected_separator 
6558
6559 \protected_separator 
6560
6561 \protected_separator 
6562
6563 \protected_separator 
6564
6565 \protected_separator 
6566
6567 \protected_separator 
6568
6569 \protected_separator 
6570
6571 \protected_separator 
6572
6573 \protected_separator 
6574
6575 \protected_separator 
6576
6577 \protected_separator 
6578
6579 \protected_separator 
6580  flag '-' is used) when needed.
6581  
6582 \newline 
6583
6584 \protected_separator 
6585
6586 \protected_separator 
6587
6588 \protected_separator 
6589
6590 \protected_separator 
6591
6592 \protected_separator 
6593
6594 \protected_separator 
6595
6596 \protected_separator 
6597
6598 \protected_separator 
6599
6600 \protected_separator 
6601
6602 \protected_separator 
6603
6604 \protected_separator 
6605
6606 \protected_separator 
6607
6608 \protected_separator 
6609
6610 \protected_separator 
6611
6612 \protected_separator 
6613
6614 \protected_separator 
6615
6616 \protected_separator 
6617
6618 \protected_separator 
6619
6620 \protected_separator 
6621
6622 \protected_separator 
6623
6624 \protected_separator 
6625
6626 \protected_separator 
6627
6628 \protected_separator 
6629
6630 \protected_separator 
6631
6632 \protected_separator 
6633  
6634 \newline 
6635
6636 \protected_separator 
6637
6638 \protected_separator 
6639
6640 \protected_separator 
6641
6642 \protected_separator 
6643
6644 \protected_separator 
6645
6646 \protected_separator 
6647
6648 \protected_separator 
6649
6650 \protected_separator 
6651
6652 \protected_separator 
6653  b/B:
6654 \protected_separator 
6655
6656 \protected_separator 
6657
6658 \protected_separator 
6659
6660 \protected_separator 
6661
6662 \protected_separator 
6663
6664 \protected_separator 
6665
6666 \protected_separator 
6667
6668 \protected_separator 
6669
6670 \protected_separator 
6671
6672 \protected_separator 
6673
6674 \protected_separator 
6675  byte argument (used by d, u, o, x, X) 
6676 \newline 
6677
6678 \protected_separator 
6679
6680 \protected_separator 
6681
6682 \protected_separator 
6683
6684 \protected_separator 
6685
6686 \protected_separator 
6687
6688 \protected_separator 
6689
6690 \protected_separator 
6691
6692 \protected_separator 
6693
6694 \protected_separator 
6695  l/L:
6696 \protected_separator 
6697
6698 \protected_separator 
6699
6700 \protected_separator 
6701
6702 \protected_separator 
6703
6704 \protected_separator 
6705
6706 \protected_separator 
6707
6708 \protected_separator 
6709
6710 \protected_separator 
6711
6712 \protected_separator 
6713
6714 \protected_separator 
6715
6716 \protected_separator 
6717  long argument (used by d, u, o, x, X)
6718 \newline 
6719
6720 \protected_separator 
6721
6722 \protected_separator 
6723
6724 \protected_separator 
6725
6726 \protected_separator 
6727
6728 \protected_separator 
6729
6730 \protected_separator 
6731
6732 \protected_separator 
6733
6734 \protected_separator 
6735
6736 \protected_separator 
6737  type:
6738 \protected_separator 
6739  d
6740 \protected_separator 
6741
6742 \protected_separator 
6743
6744 \protected_separator 
6745
6746 \protected_separator 
6747
6748 \protected_separator 
6749
6750 \protected_separator 
6751
6752 \protected_separator 
6753  decimal number 
6754 \newline 
6755
6756 \protected_separator 
6757
6758 \protected_separator 
6759
6760 \protected_separator 
6761
6762 \protected_separator 
6763
6764 \protected_separator 
6765
6766 \protected_separator 
6767
6768 \protected_separator 
6769
6770 \protected_separator 
6771
6772 \protected_separator 
6773
6774 \protected_separator 
6775
6776 \protected_separator 
6777
6778 \protected_separator 
6779
6780 \protected_separator 
6781
6782 \protected_separator 
6783
6784 \protected_separator 
6785
6786 \protected_separator 
6787  u
6788 \protected_separator 
6789
6790 \protected_separator 
6791
6792 \protected_separator 
6793
6794 \protected_separator 
6795
6796 \protected_separator 
6797
6798 \protected_separator 
6799
6800 \protected_separator 
6801  unsigned decimal number 
6802 \newline 
6803
6804 \protected_separator 
6805
6806 \protected_separator 
6807
6808 \protected_separator 
6809
6810 \protected_separator 
6811
6812 \protected_separator 
6813
6814 \protected_separator 
6815
6816 \protected_separator 
6817
6818 \protected_separator 
6819
6820 \protected_separator 
6821
6822 \protected_separator 
6823
6824 \protected_separator 
6825
6826 \protected_separator 
6827
6828 \protected_separator 
6829
6830 \protected_separator 
6831
6832 \protected_separator 
6833
6834 \protected_separator 
6835  o
6836 \protected_separator 
6837
6838 \protected_separator 
6839
6840 \protected_separator 
6841
6842 \protected_separator 
6843
6844 \protected_separator 
6845
6846 \protected_separator 
6847
6848 \protected_separator 
6849  unsigned octal number 
6850 \newline 
6851
6852 \protected_separator 
6853
6854 \protected_separator 
6855
6856 \protected_separator 
6857
6858 \protected_separator 
6859
6860 \protected_separator 
6861
6862 \protected_separator 
6863
6864 \protected_separator 
6865
6866 \protected_separator 
6867
6868 \protected_separator 
6869
6870 \protected_separator 
6871
6872 \protected_separator 
6873
6874 \protected_separator 
6875
6876 \protected_separator 
6877
6878 \protected_separator 
6879
6880 \protected_separator 
6881
6882 \protected_separator 
6883  x
6884 \protected_separator 
6885
6886 \protected_separator 
6887
6888 \protected_separator 
6889
6890 \protected_separator 
6891
6892 \protected_separator 
6893
6894 \protected_separator 
6895
6896 \protected_separator 
6897  unsigned hexadecimal number (0-9, a-f) 
6898 \newline 
6899
6900 \protected_separator 
6901
6902 \protected_separator 
6903
6904 \protected_separator 
6905
6906 \protected_separator 
6907
6908 \protected_separator 
6909
6910 \protected_separator 
6911
6912 \protected_separator 
6913
6914 \protected_separator 
6915
6916 \protected_separator 
6917
6918 \protected_separator 
6919
6920 \protected_separator 
6921
6922 \protected_separator 
6923
6924 \protected_separator 
6925
6926 \protected_separator 
6927
6928 \protected_separator 
6929
6930 \protected_separator 
6931  X
6932 \protected_separator 
6933
6934 \protected_separator 
6935
6936 \protected_separator 
6937
6938 \protected_separator 
6939
6940 \protected_separator 
6941
6942 \protected_separator 
6943
6944 \protected_separator 
6945  unsigned hexadecimal number (0-9, A-F) 
6946 \newline 
6947
6948 \protected_separator 
6949
6950 \protected_separator 
6951
6952 \protected_separator 
6953
6954 \protected_separator 
6955
6956 \protected_separator 
6957
6958 \protected_separator 
6959
6960 \protected_separator 
6961
6962 \protected_separator 
6963
6964 \protected_separator 
6965
6966 \protected_separator 
6967
6968 \protected_separator 
6969
6970 \protected_separator 
6971
6972 \protected_separator 
6973
6974 \protected_separator 
6975
6976 \protected_separator 
6977
6978 \protected_separator 
6979  c
6980 \protected_separator 
6981
6982 \protected_separator 
6983
6984 \protected_separator 
6985
6986 \protected_separator 
6987
6988 \protected_separator 
6989
6990 \protected_separator 
6991
6992 \protected_separator 
6993  character 
6994 \newline 
6995
6996 \protected_separator 
6997
6998 \protected_separator 
6999
7000 \protected_separator 
7001
7002 \protected_separator 
7003
7004 \protected_separator 
7005
7006 \protected_separator 
7007
7008 \protected_separator 
7009
7010 \protected_separator 
7011
7012 \protected_separator 
7013
7014 \protected_separator 
7015
7016 \protected_separator 
7017
7018 \protected_separator 
7019
7020 \protected_separator 
7021
7022 \protected_separator 
7023
7024 \protected_separator 
7025
7026 \protected_separator 
7027  s
7028 \protected_separator 
7029
7030 \protected_separator 
7031
7032 \protected_separator 
7033
7034 \protected_separator 
7035
7036 \protected_separator 
7037
7038 \protected_separator 
7039
7040 \protected_separator 
7041  string (generic pointer) 
7042 \newline 
7043
7044 \protected_separator 
7045
7046 \protected_separator 
7047
7048 \protected_separator 
7049
7050 \protected_separator 
7051
7052 \protected_separator 
7053
7054 \protected_separator 
7055
7056 \protected_separator 
7057
7058 \protected_separator 
7059
7060 \protected_separator 
7061
7062 \protected_separator 
7063
7064 \protected_separator 
7065
7066 \protected_separator 
7067
7068 \protected_separator 
7069
7070 \protected_separator 
7071
7072 \protected_separator 
7073
7074 \protected_separator 
7075  p
7076 \protected_separator 
7077
7078 \protected_separator 
7079
7080 \protected_separator 
7081
7082 \protected_separator 
7083
7084 \protected_separator 
7085
7086 \protected_separator 
7087
7088 \protected_separator 
7089  generic pointer (I:data/idata, C:code, X:xdata, P:paged) 
7090 \newline 
7091
7092 \protected_separator 
7093
7094 \protected_separator 
7095
7096 \protected_separator 
7097
7098 \protected_separator 
7099
7100 \protected_separator 
7101
7102 \protected_separator 
7103
7104 \protected_separator 
7105
7106 \protected_separator 
7107
7108 \protected_separator 
7109
7110 \protected_separator 
7111
7112 \protected_separator 
7113
7114 \protected_separator 
7115
7116 \protected_separator 
7117
7118 \protected_separator 
7119
7120 \protected_separator 
7121
7122 \protected_separator 
7123  f
7124 \protected_separator 
7125
7126 \protected_separator 
7127
7128 \protected_separator 
7129
7130 \protected_separator 
7131
7132 \protected_separator 
7133
7134 \protected_separator 
7135
7136 \protected_separator 
7137  float (still to be implemented)
7138 \layout Standard
7139
7140 Also contains a very simple version of printf (
7141 \series bold 
7142 printf_small
7143 \series default 
7144 ).
7145  This simplified version of printf supports only the following formats.
7146 \layout Standard
7147
7148
7149 \size scriptsize 
7150 \bar under 
7151 format
7152 \protected_separator 
7153
7154 \protected_separator 
7155
7156 \protected_separator 
7157
7158 \protected_separator 
7159
7160 \protected_separator 
7161 output
7162 \protected_separator 
7163 type
7164 \protected_separator 
7165
7166 \protected_separator 
7167
7168 \protected_separator 
7169
7170 \protected_separator 
7171
7172 \protected_separator 
7173 argument-type
7174 \bar default 
7175  
7176 \series bold 
7177 \size default 
7178
7179 \newline 
7180
7181 \series default 
7182 \size scriptsize 
7183 %d 
7184 \protected_separator 
7185
7186 \protected_separator 
7187
7188 \protected_separator 
7189
7190 \protected_separator 
7191
7192 \protected_separator 
7193
7194 \protected_separator 
7195
7196 \protected_separator 
7197
7198 \protected_separator 
7199 decimal 
7200 \protected_separator 
7201
7202 \protected_separator 
7203
7204 \protected_separator 
7205
7206 \protected_separator 
7207
7208 \protected_separator 
7209  int 
7210 \newline 
7211 %ld
7212 \protected_separator 
7213
7214 \protected_separator 
7215
7216 \protected_separator 
7217
7218 \protected_separator 
7219
7220 \protected_separator 
7221
7222 \protected_separator 
7223
7224 \protected_separator 
7225
7226 \protected_separator 
7227 decimal
7228 \protected_separator 
7229
7230 \protected_separator 
7231
7232 \protected_separator 
7233
7234 \protected_separator 
7235
7236 \protected_separator 
7237
7238 \protected_separator 
7239
7240 \protected_separator 
7241 long 
7242 \newline 
7243 %hd
7244 \protected_separator 
7245
7246 \protected_separator 
7247
7248 \protected_separator 
7249
7250 \protected_separator 
7251
7252 \protected_separator 
7253
7254 \protected_separator 
7255
7256 \protected_separator 
7257
7258 \protected_separator 
7259 decimal
7260 \protected_separator 
7261
7262 \protected_separator 
7263
7264 \protected_separator 
7265
7266 \protected_separator 
7267
7268 \protected_separator 
7269
7270 \protected_separator 
7271
7272 \protected_separator 
7273 short/char 
7274 \newline 
7275 %x
7276 \protected_separator 
7277
7278 \protected_separator 
7279
7280 \protected_separator 
7281
7282 \protected_separator 
7283
7284 \protected_separator 
7285
7286 \protected_separator 
7287
7288 \protected_separator 
7289
7290 \protected_separator 
7291 hexadecimal
7292 \protected_separator 
7293
7294 \protected_separator 
7295
7296 \protected_separator 
7297
7298 \protected_separator 
7299 int 
7300 \newline 
7301 %lx
7302 \protected_separator 
7303
7304 \protected_separator 
7305
7306 \protected_separator 
7307
7308 \protected_separator 
7309
7310 \protected_separator 
7311
7312 \protected_separator 
7313
7314 \protected_separator 
7315 hexadecimal
7316 \protected_separator 
7317
7318 \protected_separator 
7319
7320 \protected_separator 
7321
7322 \protected_separator 
7323 long 
7324 \newline 
7325 %hx
7326 \protected_separator 
7327
7328 \protected_separator 
7329
7330 \protected_separator 
7331
7332 \protected_separator 
7333
7334 \protected_separator 
7335
7336 \protected_separator 
7337
7338 \protected_separator 
7339 hexadecimal
7340 \protected_separator 
7341
7342 \protected_separator 
7343
7344 \protected_separator 
7345
7346 \protected_separator 
7347 short/char 
7348 \newline 
7349 %o
7350 \protected_separator 
7351
7352 \protected_separator 
7353
7354 \protected_separator 
7355
7356 \protected_separator 
7357
7358 \protected_separator 
7359
7360 \protected_separator 
7361
7362 \protected_separator 
7363
7364 \protected_separator 
7365
7366 \protected_separator 
7367 octal
7368 \protected_separator 
7369
7370 \protected_separator 
7371
7372 \protected_separator 
7373
7374 \protected_separator 
7375
7376 \protected_separator 
7377
7378 \protected_separator 
7379
7380 \protected_separator 
7381
7382 \protected_separator 
7383
7384 \protected_separator 
7385 int 
7386 \newline 
7387 %lo
7388 \protected_separator 
7389
7390 \protected_separator 
7391
7392 \protected_separator 
7393
7394 \protected_separator 
7395
7396 \protected_separator 
7397
7398 \protected_separator 
7399
7400 \protected_separator 
7401
7402 \protected_separator 
7403 octal
7404 \protected_separator 
7405
7406 \protected_separator 
7407
7408 \protected_separator 
7409
7410 \protected_separator 
7411
7412 \protected_separator 
7413
7414 \protected_separator 
7415
7416 \protected_separator 
7417
7418 \protected_separator 
7419
7420 \protected_separator 
7421 long 
7422 \newline 
7423 %ho
7424 \protected_separator 
7425
7426 \protected_separator 
7427
7428 \protected_separator 
7429
7430 \protected_separator 
7431
7432 \protected_separator 
7433
7434 \protected_separator 
7435
7436 \protected_separator 
7437
7438 \protected_separator 
7439 octal
7440 \protected_separator 
7441
7442 \protected_separator 
7443
7444 \protected_separator 
7445
7446 \protected_separator 
7447
7448 \protected_separator 
7449
7450 \protected_separator 
7451
7452 \protected_separator 
7453
7454 \protected_separator 
7455
7456 \protected_separator 
7457 short/char 
7458 \newline 
7459 %c
7460 \protected_separator 
7461
7462 \protected_separator 
7463
7464 \protected_separator 
7465
7466 \protected_separator 
7467
7468 \protected_separator 
7469
7470 \protected_separator 
7471
7472 \protected_separator 
7473
7474 \protected_separator 
7475 character
7476 \protected_separator 
7477
7478 \protected_separator 
7479
7480 \protected_separator 
7481
7482 \protected_separator 
7483
7484 \protected_separator 
7485
7486 \protected_separator 
7487 char/short 
7488 \newline 
7489 %s
7490 \protected_separator 
7491
7492 \protected_separator 
7493
7494 \protected_separator 
7495
7496 \protected_separator 
7497
7498 \protected_separator 
7499
7500 \protected_separator 
7501
7502 \protected_separator 
7503
7504 \protected_separator 
7505 character
7506 \protected_separator 
7507
7508 \protected_separator 
7509
7510 \protected_separator 
7511
7512 \protected_separator 
7513
7514 \protected_separator 
7515 _generic pointer
7516 \layout Standard
7517
7518 The routine is 
7519 \series bold 
7520 very stack intesive 
7521 \series default 
7522 , --stack-after-data parameter should be used when using this routine, the
7523  routine also takes about 1K of code space .It also expects an external function
7524  named 
7525 \emph on 
7526 putchar(char )
7527 \emph default 
7528  to be present (this can be changed).
7529  When using the %s format the string / pointer should be cast to a generic
7530  pointer.
7531  eg.
7532 \layout Standard
7533
7534
7535 \size scriptsize 
7536 printf_small(
7537 \begin_inset Quotes eld
7538 \end_inset 
7539
7540 my str %s, my int %d
7541 \backslash 
7542 n
7543 \begin_inset Quotes erd
7544 \end_inset 
7545
7546 ,(char _generic *)mystr,myint);
7547 \layout Itemize
7548
7549
7550 \series bold 
7551 \size large 
7552 stdarg.h 
7553 \series default 
7554 \size default 
7555 - contains definition for the following macros to be used for variable parameter
7556  list, note that a function can have a variable parameter list if and only
7557  if it is 'reentrant'
7558 \begin_deeper 
7559 \layout Standard
7560
7561
7562 \size small 
7563 va_list, va_start, va_arg, va_end.
7564 \end_deeper 
7565 \layout Itemize
7566
7567
7568 \series bold 
7569 \size large 
7570 setjmp.h 
7571 \series default 
7572 \size default 
7573 - contains defintion for ANSI
7574 \series bold 
7575  setjmp 
7576 \series default 
7577
7578 \series bold 
7579 longjmp
7580 \series default 
7581  routines.
7582  Note in this case setjmp & longjmp can be used between functions executing
7583  within the same register bank, if long jmp is executed from a function
7584  that is using a different register bank from the function issuing the setjmp
7585  function, the results may be unpredictable.
7586  The jump buffer requires 3 bytes of data (the stack pointer & a 16 byte
7587  return address), and can be placed in any address space.
7588 \layout Itemize
7589
7590
7591 \series bold 
7592 \size large 
7593 stdlib.h
7594 \series default 
7595 \size default 
7596  - contains the following functions.
7597 \begin_deeper 
7598 \layout Standard
7599
7600
7601 \size footnotesize 
7602 atoi, atol.
7603 \end_deeper 
7604 \layout Itemize
7605
7606
7607 \series bold 
7608 \size large 
7609 string.h 
7610 \series default 
7611 \size default 
7612 - contains the following functions.
7613 \begin_deeper 
7614 \layout Standard
7615
7616
7617 \size footnotesize 
7618 strcpy, strncpy, strcat, strncat, strcmp, strncmp, strchr, strrchr, strspn,
7619  strcspn, strpbrk, strstr, strlen, strtok, memcpy, memcmp, memset.
7620 \end_deeper 
7621 \layout Itemize
7622
7623
7624 \series bold 
7625 \size large 
7626 ctype.h
7627 \series default 
7628 \size default 
7629  - contains the following routines.
7630 \begin_deeper 
7631 \layout Standard
7632
7633
7634 \size footnotesize 
7635 iscntrl, isdigit, isgraph, islower, isupper, isprint, ispunct, isspace,
7636  isxdigit, isalnum, isalpha.
7637 \end_deeper 
7638 \layout Itemize
7639
7640
7641 \series bold 
7642 \size large 
7643 malloc.h
7644 \series default 
7645 \size default 
7646  - The malloc routines are developed by Dmitry S.
7647  Obukhov (dso@usa.net).
7648  These routines will allocate memory from the external ram.
7649  Here is a description on how to use them (as described by the author).
7650 \begin_deeper 
7651 \layout Standard
7652
7653
7654 \size scriptsize 
7655 //Example: 
7656 \newline 
7657
7658 \protected_separator 
7659
7660 \protected_separator 
7661
7662 \protected_separator 
7663
7664 \protected_separator 
7665  //
7666 \protected_separator 
7667
7668 \protected_separator 
7669
7670 \protected_separator 
7671
7672 \protected_separator 
7673  #define DYNAMIC_MEMORY_SIZE 0x2000 
7674 \newline 
7675
7676 \protected_separator 
7677
7678 \protected_separator 
7679
7680 \protected_separator 
7681
7682 \protected_separator 
7683  //
7684 \protected_separator 
7685
7686 \protected_separator 
7687
7688 \protected_separator 
7689
7690 \protected_separator 
7691  .....
7692  
7693 \newline 
7694
7695 \protected_separator 
7696
7697 \protected_separator 
7698
7699 \protected_separator 
7700
7701 \protected_separator 
7702  //
7703 \protected_separator 
7704
7705 \protected_separator 
7706
7707 \protected_separator 
7708
7709 \protected_separator 
7710  unsigned char xdata dynamic_memory_pool[DYNAMIC_MEMORY_SIZE]; 
7711 \newline 
7712
7713 \protected_separator 
7714
7715 \protected_separator 
7716
7717 \protected_separator 
7718
7719 \protected_separator 
7720  //
7721 \protected_separator 
7722
7723 \protected_separator 
7724
7725 \protected_separator 
7726
7727 \protected_separator 
7728  unsigned char xdata * current_buffer; 
7729 \newline 
7730
7731 \protected_separator 
7732
7733 \protected_separator 
7734
7735 \protected_separator 
7736
7737 \protected_separator 
7738  //
7739 \protected_separator 
7740
7741 \protected_separator 
7742
7743 \protected_separator 
7744
7745 \protected_separator 
7746  .....
7747  
7748 \newline 
7749
7750 \protected_separator 
7751
7752 \protected_separator 
7753
7754 \protected_separator 
7755
7756 \protected_separator 
7757  //
7758 \protected_separator 
7759
7760 \protected_separator 
7761
7762 \protected_separator 
7763
7764 \protected_separator 
7765  void main(void) 
7766 \newline 
7767
7768 \protected_separator 
7769
7770 \protected_separator 
7771
7772 \protected_separator 
7773
7774 \protected_separator 
7775  //
7776 \protected_separator 
7777
7778 \protected_separator 
7779
7780 \protected_separator 
7781
7782 \protected_separator 
7783  { 
7784 \newline 
7785
7786 \protected_separator 
7787
7788 \protected_separator 
7789
7790 \protected_separator 
7791
7792 \protected_separator 
7793  //
7794 \protected_separator 
7795
7796 \protected_separator 
7797
7798 \protected_separator 
7799
7800 \protected_separator 
7801
7802 \protected_separator 
7803
7804 \protected_separator 
7805
7806 \protected_separator 
7807
7808 \protected_separator 
7809  ...
7810  
7811 \newline 
7812
7813 \protected_separator 
7814
7815 \protected_separator 
7816
7817 \protected_separator 
7818
7819 \protected_separator 
7820
7821 \protected_separator 
7822 //
7823 \protected_separator 
7824
7825 \protected_separator 
7826
7827 \protected_separator 
7828
7829 \protected_separator 
7830
7831 \protected_separator 
7832
7833 \protected_separator 
7834
7835 \protected_separator 
7836
7837 \protected_separator 
7838  init_dynamic_memory(dynamic_memory_pool,DYNAMIC_MEMORY_SIZE); 
7839 \newline 
7840
7841 \protected_separator 
7842
7843 \protected_separator 
7844
7845 \protected_separator 
7846
7847 \protected_separator 
7848  //
7849 \protected_separator 
7850
7851 \protected_separator 
7852
7853 \protected_separator 
7854
7855 \protected_separator 
7856
7857 \protected_separator 
7858
7859 \protected_separator 
7860
7861 \protected_separator 
7862
7863 \protected_separator 
7864  //Now it's possible to use malloc.
7865  
7866 \newline 
7867
7868 \protected_separator 
7869
7870 \protected_separator 
7871
7872 \protected_separator 
7873
7874 \protected_separator 
7875  //
7876 \protected_separator 
7877
7878 \protected_separator 
7879
7880 \protected_separator 
7881
7882 \protected_separator 
7883
7884 \protected_separator 
7885
7886 \protected_separator 
7887
7888 \protected_separator 
7889
7890 \protected_separator 
7891  ...
7892  
7893 \newline 
7894
7895 \protected_separator 
7896
7897 \protected_separator 
7898
7899 \protected_separator 
7900
7901 \protected_separator 
7902  //
7903 \protected_separator 
7904
7905 \protected_separator 
7906
7907 \protected_separator 
7908
7909 \protected_separator 
7910
7911 \protected_separator 
7912
7913 \protected_separator 
7914
7915 \protected_separator 
7916
7917 \protected_separator 
7918  current_buffer = malloc(0x100); 
7919 \newline 
7920
7921 \protected_separator 
7922
7923 \protected_separator 
7924
7925 \protected_separator 
7926
7927 \protected_separator 
7928  //
7929 \end_deeper 
7930 \layout Itemize
7931
7932
7933 \series bold 
7934 \size large 
7935 serial.h
7936 \series default 
7937 \size default 
7938  - Serial IO routines are also developed by Dmitry S.
7939  Obukhov (dso@usa.net).
7940  These routines are interrupt driven with a 256 byte circular buffer, they
7941  also expect external ram to be present.
7942  Please see documentation in file SDCCDIR/sdcc51lib/serial.c .
7943  Note the header file 
7944 \begin_inset Quotes eld
7945 \end_inset 
7946
7947 serial.h
7948 \begin_inset Quotes erd
7949 \end_inset 
7950
7951  MUST be included in the file containing the 'main' function.
7952 \layout Itemize
7953
7954
7955 \series bold 
7956 \size large 
7957 ser.h 
7958 \series default 
7959 \size default 
7960 - Alternate serial routine provided by Wolfgang Esslinger <wolfgang@WiredMinds.co
7961 m> these routines are more compact and faster.
7962  Please see documentation in file SDCCDIR/sdcc51lib/ser.c
7963 \layout Itemize
7964
7965
7966 \series bold 
7967 \size large 
7968 ser_ir.h 
7969 \series default 
7970 \size default 
7971 - Another alternate set of serial routines provided by Josef Wolf <jw@raven.inka.d
7972 e> , these routines do not use the external ram.
7973 \layout Itemize
7974
7975
7976 \series bold 
7977 \size large 
7978 reg51.h
7979 \series default 
7980 \size default 
7981  - contains register definitions for a standard 8051
7982 \layout Itemize
7983
7984
7985 \series bold 
7986 \size large 
7987 reg552.h 
7988 \series default 
7989 \size default 
7990 - contains register definitions for 80C552.
7991 \layout Itemize
7992
7993
7994 \series bold 
7995 \size large 
7996 float.h
7997 \series default 
7998 \size default 
7999  - contains min, max and other floating point related stuff.
8000 \layout Standard
8001
8002 All library routines are compiled as --model-small , they are all non-reentrant,
8003  if you plan to use the large model or want to make these routines reentrant,
8004  then they will have to be recompiled with the appropriate compiler option.
8005 \layout Standard
8006
8007 Have not had time to do the more involved routines like printf, will get
8008  to them shortly.
8009 \layout Section
8010
8011 Interfacing with assembly routines.
8012 \begin_inset LatexCommand \label{Interface_asm}
8013
8014 \end_inset 
8015
8016
8017 \layout Subsection
8018
8019 Global registers used for parameter passing.
8020 \layout Standard
8021
8022 By default the compiler uses the global registers 
8023 \begin_inset Quotes eld
8024 \end_inset 
8025
8026 DPL,DPH,B,ACC
8027 \begin_inset Quotes erd
8028 \end_inset 
8029
8030  to pass the first parameter to a routine, the second parameter onwards
8031  is either allocated on the stack (for reentrant routines or --stack-auto
8032  is used) or in the internal / external ram (depending on the memory model).
8033  
8034 \layout Subsubsection
8035
8036 Assembler routine non-reentrant
8037 \layout Standard
8038
8039 In the following example the function
8040 \series bold 
8041  cfunc
8042 \series default 
8043  calls an assembler routine 
8044 \series bold 
8045 asm_func
8046 \series default 
8047 , which takes two parameters.
8048 \layout Standard
8049
8050
8051 \size footnotesize 
8052 extern int asm_func( unsigned short, unsigned short);
8053 \layout Standard
8054
8055
8056 \size footnotesize 
8057
8058 \protected_separator 
8059
8060 \newline 
8061 int c_func (unsigned short i, unsigned short j) 
8062 \newline 
8063
8064 \newline 
8065
8066 \protected_separator 
8067
8068 \protected_separator 
8069
8070 \protected_separator 
8071
8072 \protected_separator 
8073
8074 \protected_separator 
8075
8076 \protected_separator 
8077
8078 \protected_separator 
8079  return asm_func(i,j); 
8080 \newline 
8081 }
8082 \size default 
8083  
8084 \size scriptsize 
8085
8086 \newline 
8087 int main() 
8088 \newline 
8089
8090 \newline 
8091
8092 \protected_separator 
8093
8094 \protected_separator 
8095
8096 \protected_separator 
8097 return c_func(10,9); 
8098 \newline 
8099 }
8100 \layout Standard
8101
8102 The corresponding assembler function is:-
8103 \layout Standard
8104
8105
8106 \size scriptsize 
8107
8108 \protected_separator 
8109
8110 \protected_separator 
8111
8112 \protected_separator 
8113
8114 \protected_separator 
8115
8116 \protected_separator 
8117
8118 \protected_separator 
8119
8120 \protected_separator 
8121  .globl _asm_func_PARM_2 
8122 \newline 
8123
8124 \protected_separator 
8125
8126 \protected_separator 
8127
8128 \protected_separator 
8129
8130 \protected_separator 
8131
8132 \protected_separator 
8133
8134 \protected_separator 
8135
8136 \protected_separator 
8137  .globl _asm_func 
8138 \newline 
8139
8140 \protected_separator 
8141
8142 \protected_separator 
8143
8144 \protected_separator 
8145
8146 \protected_separator 
8147
8148 \protected_separator 
8149
8150 \protected_separator 
8151
8152 \protected_separator 
8153  .area OSEG 
8154 \newline 
8155 _asm_func_PARM_2:
8156 \protected_separator 
8157
8158 \protected_separator 
8159
8160 \protected_separator 
8161
8162 \protected_separator 
8163
8164 \protected_separator 
8165
8166 \protected_separator 
8167  .ds
8168 \protected_separator 
8169
8170 \protected_separator 
8171
8172 \protected_separator 
8173
8174 \protected_separator 
8175
8176 \protected_separator 
8177  1 
8178 \newline 
8179
8180 \protected_separator 
8181
8182 \protected_separator 
8183
8184 \protected_separator 
8185
8186 \protected_separator 
8187
8188 \protected_separator 
8189
8190 \protected_separator 
8191
8192 \protected_separator 
8193  .area CSEG 
8194 \newline 
8195 _asm_func: 
8196 \newline 
8197
8198 \protected_separator 
8199
8200 \protected_separator 
8201
8202 \protected_separator 
8203
8204 \protected_separator 
8205
8206 \protected_separator 
8207
8208 \protected_separator 
8209
8210 \protected_separator 
8211  mov
8212 \protected_separator 
8213
8214 \protected_separator 
8215
8216 \protected_separator 
8217
8218 \protected_separator 
8219  a,dpl 
8220 \newline 
8221
8222 \protected_separator 
8223
8224 \protected_separator 
8225
8226 \protected_separator 
8227
8228 \protected_separator 
8229
8230 \protected_separator 
8231
8232 \protected_separator 
8233
8234 \protected_separator 
8235  add
8236 \protected_separator 
8237
8238 \protected_separator 
8239
8240 \protected_separator 
8241
8242 \protected_separator 
8243  a,_asm_func_PARM_2 
8244 \newline 
8245
8246 \protected_separator 
8247
8248 \protected_separator 
8249
8250 \protected_separator 
8251
8252 \protected_separator 
8253
8254 \protected_separator 
8255
8256 \protected_separator 
8257
8258 \protected_separator 
8259  mov
8260 \protected_separator 
8261
8262 \protected_separator 
8263
8264 \protected_separator 
8265
8266 \protected_separator 
8267  dpl,a 
8268 \newline 
8269
8270 \protected_separator 
8271
8272 \protected_separator 
8273
8274 \protected_separator 
8275
8276 \protected_separator 
8277
8278 \protected_separator 
8279
8280 \protected_separator 
8281
8282 \protected_separator 
8283  mov
8284 \protected_separator 
8285
8286 \protected_separator 
8287
8288 \protected_separator 
8289
8290 \protected_separator 
8291  dpl,#0x00 
8292 \newline 
8293
8294 \protected_separator 
8295
8296 \protected_separator 
8297
8298 \protected_separator 
8299
8300 \protected_separator 
8301
8302 \protected_separator 
8303
8304 \protected_separator 
8305
8306 \protected_separator 
8307  ret
8308 \layout Standard
8309
8310 Note here that the return values are placed in 'dpl' - One byte return value,
8311  'dpl' LSB & 'dph' MSB for two byte values.
8312  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
8313 b' & 'acc' for four byte values.
8314 \layout Standard
8315
8316 The parameter naming convention is 
8317 \series bold 
8318 _<function_name>_PARM_<n>,
8319 \series default 
8320  where n is the parameter number starting from 1, and counting from the
8321  left.
8322  The first parameter is passed in 
8323 \begin_inset Quotes eld
8324 \end_inset 
8325
8326 dpl
8327 \begin_inset Quotes erd
8328 \end_inset 
8329
8330  for One bye parameter, 
8331 \begin_inset Quotes eld
8332 \end_inset 
8333
8334 dptr
8335 \begin_inset Quotes erd
8336 \end_inset 
8337
8338  if two bytes, 
8339 \begin_inset Quotes eld
8340 \end_inset 
8341
8342 b,dptr
8343 \begin_inset Quotes erd
8344 \end_inset 
8345
8346  for three bytes and 
8347 \begin_inset Quotes eld
8348 \end_inset 
8349
8350 acc,b,dptr
8351 \begin_inset Quotes erd
8352 \end_inset 
8353
8354  for four bytes, the 
8355 \family typewriter 
8356 \series bold 
8357 \size footnotesize 
8358 varaible name for the second parameter will be _<function_name>_PARM_2.
8359 \layout Standard
8360
8361 Assemble the assembler routine with the following command.
8362 \layout Standard
8363
8364 asx8051 -losg asmfunc.asm
8365 \layout Standard
8366
8367 Then compile and link the assembler routine to the C source file with the
8368  following command,
8369 \layout Standard
8370
8371 sdcc cfunc.c asmfunc.rel
8372 \layout Subsubsection
8373
8374 Assembler routine is reentrant
8375 \layout Standard
8376
8377 In this case the second parameter onwards will be passed on the stack ,
8378  the parameters are pushed from right to left i.e.
8379  after the call the left most parameter will be on the top of the stack.
8380  Here is an example.
8381 \layout Standard
8382
8383
8384 \size footnotesize 
8385 extern int asm_func( unsigned short, unsigned short);
8386 \layout Standard
8387
8388
8389 \size footnotesize 
8390
8391 \protected_separator 
8392
8393 \layout Standard
8394
8395
8396 \size footnotesize 
8397 int c_func (unsigned short i, unsigned short j) reentrant 
8398 \newline 
8399
8400 \newline 
8401
8402 \protected_separator 
8403
8404 \protected_separator 
8405
8406 \protected_separator 
8407
8408 \protected_separator 
8409
8410 \protected_separator 
8411
8412 \protected_separator 
8413
8414 \protected_separator 
8415  return asm_func(i,j); 
8416 \newline 
8417 }
8418 \size default 
8419  
8420 \size scriptsize 
8421
8422 \newline 
8423 int main() 
8424 \newline 
8425
8426 \newline 
8427
8428 \protected_separator 
8429
8430 \protected_separator 
8431
8432 \protected_separator 
8433 return c_func(10,9); 
8434 \newline 
8435 }
8436 \layout Standard
8437
8438 The corresponding assembler routine is.
8439 \layout Standard
8440
8441
8442 \size scriptsize 
8443
8444 \protected_separator 
8445
8446 \protected_separator 
8447
8448 \protected_separator 
8449
8450 \protected_separator 
8451
8452 \protected_separator 
8453
8454 \protected_separator 
8455
8456 \protected_separator 
8457  .globl _asm_func 
8458 \newline 
8459 _asm_func: 
8460 \newline 
8461
8462 \protected_separator 
8463
8464 \protected_separator 
8465
8466 \protected_separator 
8467
8468 \protected_separator 
8469
8470 \protected_separator 
8471
8472 \protected_separator 
8473
8474 \protected_separator 
8475  push
8476 \protected_separator 
8477  _bp 
8478 \newline 
8479
8480 \protected_separator 
8481
8482 \protected_separator 
8483
8484 \protected_separator 
8485
8486 \protected_separator 
8487
8488 \protected_separator 
8489
8490 \protected_separator 
8491
8492 \protected_separator 
8493  mov
8494 \protected_separator 
8495  _bp,sp 
8496 \newline 
8497
8498 \protected_separator 
8499
8500 \protected_separator 
8501
8502 \protected_separator 
8503
8504 \protected_separator 
8505
8506 \protected_separator 
8507
8508 \protected_separator 
8509
8510 \protected_separator 
8511
8512 \protected_separator 
8513 mov
8514 \protected_separator 
8515  r2,dpl
8516 \newline 
8517
8518 \protected_separator 
8519
8520 \protected_separator 
8521
8522 \protected_separator 
8523
8524 \protected_separator 
8525
8526 \protected_separator 
8527
8528 \protected_separator 
8529
8530 \protected_separator 
8531  mov
8532 \protected_separator 
8533  a,_bp 
8534 \newline 
8535
8536 \protected_separator 
8537
8538 \protected_separator 
8539
8540 \protected_separator 
8541
8542 \protected_separator 
8543
8544 \protected_separator 
8545
8546 \protected_separator 
8547
8548 \protected_separator 
8549  clr
8550 \protected_separator 
8551  c 
8552 \newline 
8553
8554 \protected_separator 
8555
8556 \protected_separator 
8557
8558 \protected_separator 
8559
8560 \protected_separator 
8561
8562 \protected_separator 
8563
8564 \protected_separator 
8565
8566 \protected_separator 
8567  add
8568 \protected_separator 
8569  a,#0xfd 
8570 \newline 
8571
8572 \protected_separator 
8573
8574 \protected_separator 
8575
8576 \protected_separator 
8577
8578 \protected_separator 
8579
8580 \protected_separator 
8581
8582 \protected_separator 
8583
8584 \protected_separator 
8585  mov
8586 \protected_separator 
8587  r0,a 
8588 \newline 
8589
8590 \protected_separator 
8591
8592 \protected_separator 
8593
8594 \protected_separator 
8595
8596 \protected_separator 
8597
8598 \protected_separator 
8599
8600 \protected_separator 
8601
8602 \protected_separator 
8603  add
8604 \protected_separator 
8605  a,#0xfc
8606 \newline 
8607
8608 \protected_separator 
8609
8610 \protected_separator 
8611
8612 \protected_separator 
8613
8614 \protected_separator 
8615
8616 \protected_separator 
8617
8618 \protected_separator 
8619
8620 \protected_separator 
8621  mov
8622 \protected_separator 
8623  r1,a 
8624 \newline 
8625
8626 \protected_separator 
8627
8628 \protected_separator 
8629
8630 \protected_separator 
8631
8632 \protected_separator 
8633
8634 \protected_separator 
8635
8636 \protected_separator 
8637
8638 \protected_separator 
8639  mov
8640 \protected_separator 
8641  a,@r0 
8642 \newline 
8643
8644 \protected_separator 
8645
8646 \protected_separator 
8647
8648 \protected_separator 
8649
8650 \protected_separator 
8651
8652 \protected_separator 
8653
8654 \protected_separator 
8655
8656 \protected_separator 
8657  add
8658 \protected_separator 
8659  a,r2
8660 \newline 
8661
8662 \protected_separator 
8663
8664 \protected_separator 
8665
8666 \protected_separator 
8667
8668 \protected_separator 
8669
8670 \protected_separator 
8671
8672 \protected_separator 
8673
8674 \protected_separator 
8675  mov
8676 \protected_separator 
8677  dpl,a 
8678 \newline 
8679
8680 \protected_separator 
8681
8682 \protected_separator 
8683
8684 \protected_separator 
8685
8686 \protected_separator 
8687
8688 \protected_separator 
8689
8690 \protected_separator 
8691
8692 \protected_separator 
8693  mov
8694 \protected_separator 
8695  dph,#0x00 
8696 \newline 
8697
8698 \protected_separator 
8699
8700 \protected_separator 
8701
8702 \protected_separator 
8703
8704 \protected_separator 
8705
8706 \protected_separator 
8707
8708 \protected_separator 
8709
8710 \protected_separator 
8711  mov
8712 \protected_separator 
8713  sp,_bp 
8714 \newline 
8715
8716 \protected_separator 
8717
8718 \protected_separator 
8719
8720 \protected_separator 
8721
8722 \protected_separator 
8723
8724 \protected_separator 
8725
8726 \protected_separator 
8727
8728 \protected_separator 
8729  pop
8730 \protected_separator 
8731  _bp 
8732 \newline 
8733
8734 \protected_separator 
8735
8736 \protected_separator 
8737
8738 \protected_separator 
8739
8740 \protected_separator 
8741
8742 \protected_separator 
8743
8744 \protected_separator 
8745
8746 \protected_separator 
8747  ret
8748 \layout Standard
8749
8750 The compiling and linking procedure remains the same, however note the extra
8751  entry & exit linkage required for the assembler code, _bp is the stack
8752  frame pointer and is used to compute the offset into the stack for parameters
8753  and local variables.
8754 \layout Subsection
8755
8756 With --noregparms option.
8757 \layout Standard
8758
8759 When the source is compiled with --noregparms option , space is allocated
8760  for each of the parameters passed to a routine.
8761 \layout Subsubsection
8762
8763 Assembler routine non-reentrant.
8764 \layout Standard
8765
8766 In the following example the function
8767 \series bold 
8768  cfunc
8769 \series default 
8770  calls an assembler routine 
8771 \series bold 
8772 asm_func
8773 \series default 
8774 , which takes two parameters.
8775 \layout Standard
8776
8777
8778 \size footnotesize 
8779 extern int asm_func( unsigned short, unsigned short);
8780 \layout Standard
8781
8782
8783 \size footnotesize 
8784
8785 \protected_separator 
8786
8787 \newline 
8788 int c_func (unsigned short i, unsigned short j) 
8789 \newline 
8790
8791 \newline 
8792
8793 \protected_separator 
8794
8795 \protected_separator 
8796
8797 \protected_separator 
8798
8799 \protected_separator 
8800
8801 \protected_separator 
8802
8803 \protected_separator 
8804
8805 \protected_separator 
8806  return asm_func(i,j); 
8807 \newline 
8808 }
8809 \size default 
8810  
8811 \size scriptsize 
8812
8813 \newline 
8814 int main() 
8815 \newline 
8816
8817 \newline 
8818
8819 \protected_separator 
8820
8821 \protected_separator 
8822
8823 \protected_separator 
8824 return c_func(10,9); 
8825 \newline 
8826 }
8827 \layout Standard
8828
8829 The corresponding assembler function is:-
8830 \layout Standard
8831
8832
8833 \size scriptsize 
8834
8835 \protected_separator 
8836
8837 \protected_separator 
8838
8839 \protected_separator 
8840
8841 \protected_separator 
8842
8843 \protected_separator 
8844
8845 \protected_separator 
8846
8847 \protected_separator 
8848  .globl _asm_func_PARM_1 
8849 \newline 
8850
8851 \protected_separator 
8852
8853 \protected_separator 
8854
8855 \protected_separator 
8856
8857 \protected_separator 
8858
8859 \protected_separator 
8860
8861 \protected_separator 
8862
8863 \protected_separator 
8864  .globl _asm_func_PARM_2 
8865 \newline 
8866
8867 \protected_separator 
8868
8869 \protected_separator 
8870
8871 \protected_separator 
8872
8873 \protected_separator 
8874
8875 \protected_separator 
8876
8877 \protected_separator 
8878
8879 \protected_separator 
8880  .globl _asm_func 
8881 \newline 
8882
8883 \protected_separator 
8884
8885 \protected_separator 
8886
8887 \protected_separator 
8888
8889 \protected_separator 
8890
8891 \protected_separator 
8892
8893 \protected_separator 
8894
8895 \protected_separator 
8896  .area OSEG 
8897 \newline 
8898 _asm_func_PARM_1:
8899 \protected_separator 
8900
8901 \protected_separator 
8902
8903 \protected_separator 
8904
8905 \protected_separator 
8906
8907 \protected_separator 
8908
8909 \protected_separator 
8910  .ds
8911 \protected_separator 
8912
8913 \protected_separator 
8914
8915 \protected_separator 
8916
8917 \protected_separator 
8918  1 
8919 \newline 
8920 _asm_func_PARM_2:
8921 \protected_separator 
8922
8923 \protected_separator 
8924
8925 \protected_separator 
8926
8927 \protected_separator 
8928
8929 \protected_separator 
8930
8931 \protected_separator 
8932  .ds
8933 \protected_separator 
8934
8935 \protected_separator 
8936
8937 \protected_separator 
8938
8939 \protected_separator 
8940
8941 \protected_separator 
8942  1 
8943 \newline 
8944
8945 \protected_separator 
8946
8947 \protected_separator 
8948
8949 \protected_separator 
8950
8951 \protected_separator 
8952
8953 \protected_separator 
8954
8955 \protected_separator 
8956
8957 \protected_separator 
8958  .area CSEG 
8959 \newline 
8960 _asm_func: 
8961 \newline 
8962
8963 \protected_separator 
8964
8965 \protected_separator 
8966
8967 \protected_separator 
8968
8969 \protected_separator 
8970
8971 \protected_separator 
8972
8973 \protected_separator 
8974
8975 \protected_separator 
8976  mov
8977 \protected_separator 
8978
8979 \protected_separator 
8980
8981 \protected_separator 
8982
8983 \protected_separator 
8984  a,_asm_func_PARM_1 
8985 \newline 
8986
8987 \protected_separator 
8988
8989 \protected_separator 
8990
8991 \protected_separator 
8992
8993 \protected_separator 
8994
8995 \protected_separator 
8996
8997 \protected_separator 
8998
8999 \protected_separator 
9000  add
9001 \protected_separator 
9002
9003 \protected_separator 
9004
9005 \protected_separator 
9006
9007 \protected_separator 
9008  a,_asm_func_PARM_2 
9009 \newline 
9010
9011 \protected_separator 
9012
9013 \protected_separator 
9014
9015 \protected_separator 
9016
9017 \protected_separator 
9018
9019 \protected_separator 
9020
9021 \protected_separator 
9022
9023 \protected_separator 
9024  mov
9025 \protected_separator 
9026
9027 \protected_separator 
9028
9029 \protected_separator 
9030
9031 \protected_separator 
9032  dpl,a 
9033 \newline 
9034
9035 \protected_separator 
9036
9037 \protected_separator 
9038
9039 \protected_separator 
9040
9041 \protected_separator 
9042
9043 \protected_separator 
9044
9045 \protected_separator 
9046
9047 \protected_separator 
9048  mov
9049 \protected_separator 
9050
9051 \protected_separator 
9052
9053 \protected_separator 
9054
9055 \protected_separator 
9056  dpl,#0x00 
9057 \newline 
9058
9059 \protected_separator 
9060
9061 \protected_separator 
9062
9063 \protected_separator 
9064
9065 \protected_separator 
9066
9067 \protected_separator 
9068
9069 \protected_separator 
9070
9071 \protected_separator 
9072  ret
9073 \layout Standard
9074
9075 Note here that the return values are placed in 'dpl' - One byte return value,
9076  'dpl' LSB & 'dph' MSB for two byte values.
9077  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
9078 b' & 'acc' for four byte values.
9079 \layout Standard
9080
9081 The parameter naming convention is 
9082 \series bold 
9083 _<function_name>_PARM_<n>,
9084 \series default 
9085  where n is the parameter number starting from 1, and counting from the
9086  left.
9087  i.e.
9088  the 
9089 \family typewriter 
9090 \series bold 
9091 \size footnotesize 
9092 left-most parameter name will be _<function_name>_PARM_1.
9093 \layout Standard
9094
9095 Assemble the assembler routine with the following command.
9096 \layout Standard
9097
9098 asx8051 -losg asmfunc.asm
9099 \layout Standard
9100
9101 Then compile and link the assembler routine to the C source file with the
9102  following command,
9103 \layout Standard
9104
9105 sdcc cfunc.c asmfunc.rel
9106 \layout Subsubsection
9107
9108 Assembler routine is reentrant.
9109 \layout Standard
9110
9111 In this case the parameters will be passed on the stack , the parameters
9112  are pushed from right to left i.e.
9113  after the call the left most parameter will be on the top of the stack.
9114  Here is an example.
9115 \layout Standard
9116
9117
9118 \size footnotesize 
9119 extern int asm_func( unsigned short, unsigned short);
9120 \layout Standard
9121
9122
9123 \size footnotesize 
9124
9125 \protected_separator 
9126
9127 \layout Standard
9128
9129
9130 \size footnotesize 
9131 int c_func (unsigned short i, unsigned short j) reentrant 
9132 \newline 
9133
9134 \newline 
9135
9136 \protected_separator 
9137
9138 \protected_separator 
9139
9140 \protected_separator 
9141
9142 \protected_separator 
9143
9144 \protected_separator 
9145
9146 \protected_separator 
9147
9148 \protected_separator 
9149  return asm_func(i,j); 
9150 \newline 
9151 }
9152 \size default 
9153  
9154 \size scriptsize 
9155
9156 \newline 
9157 int main() 
9158 \newline 
9159
9160 \newline 
9161
9162 \protected_separator 
9163
9164 \protected_separator 
9165
9166 \protected_separator 
9167 return c_func(10,9); 
9168 \newline 
9169 }
9170 \layout Standard
9171
9172 The corresponding assembler routine is.
9173 \layout Standard
9174
9175
9176 \size scriptsize 
9177
9178 \protected_separator 
9179
9180 \protected_separator 
9181
9182 \protected_separator 
9183
9184 \protected_separator 
9185
9186 \protected_separator 
9187
9188 \protected_separator 
9189
9190 \protected_separator 
9191  .globl _asm_func 
9192 \newline 
9193 _asm_func: 
9194 \newline 
9195
9196 \protected_separator 
9197
9198 \protected_separator 
9199
9200 \protected_separator 
9201
9202 \protected_separator 
9203
9204 \protected_separator 
9205
9206 \protected_separator 
9207
9208 \protected_separator 
9209  push
9210 \protected_separator 
9211  _bp 
9212 \newline 
9213
9214 \protected_separator 
9215
9216 \protected_separator 
9217
9218 \protected_separator 
9219
9220 \protected_separator 
9221
9222 \protected_separator 
9223
9224 \protected_separator 
9225
9226 \protected_separator 
9227  mov
9228 \protected_separator 
9229  _bp,sp 
9230 \newline 
9231
9232 \protected_separator 
9233
9234 \protected_separator 
9235
9236 \protected_separator 
9237
9238 \protected_separator 
9239
9240 \protected_separator 
9241
9242 \protected_separator 
9243
9244 \protected_separator 
9245  mov
9246 \protected_separator 
9247  a,_bp 
9248 \newline 
9249
9250 \protected_separator 
9251
9252 \protected_separator 
9253
9254 \protected_separator 
9255
9256 \protected_separator 
9257
9258 \protected_separator 
9259
9260 \protected_separator 
9261
9262 \protected_separator 
9263  clr
9264 \protected_separator 
9265  c 
9266 \newline 
9267
9268 \protected_separator 
9269
9270 \protected_separator 
9271
9272 \protected_separator 
9273
9274 \protected_separator 
9275
9276 \protected_separator 
9277
9278 \protected_separator 
9279
9280 \protected_separator 
9281  add
9282 \protected_separator 
9283  a,#0xfd 
9284 \newline 
9285
9286 \protected_separator 
9287
9288 \protected_separator 
9289
9290 \protected_separator 
9291
9292 \protected_separator 
9293
9294 \protected_separator 
9295
9296 \protected_separator 
9297
9298 \protected_separator 
9299  mov
9300 \protected_separator 
9301  r0,a 
9302 \newline 
9303
9304 \protected_separator 
9305
9306 \protected_separator 
9307
9308 \protected_separator 
9309
9310 \protected_separator 
9311
9312 \protected_separator 
9313
9314 \protected_separator 
9315
9316 \protected_separator 
9317  mov
9318 \protected_separator 
9319  a,_bp 
9320 \newline 
9321
9322 \protected_separator 
9323
9324 \protected_separator 
9325
9326 \protected_separator 
9327
9328 \protected_separator 
9329
9330 \protected_separator 
9331
9332 \protected_separator 
9333
9334 \protected_separator 
9335  clr
9336 \protected_separator 
9337  c 
9338 \newline 
9339
9340 \protected_separator 
9341
9342 \protected_separator 
9343
9344 \protected_separator 
9345
9346 \protected_separator 
9347
9348 \protected_separator 
9349
9350 \protected_separator 
9351
9352 \protected_separator 
9353  add
9354 \protected_separator 
9355  a,#0xfc 
9356 \newline 
9357
9358 \protected_separator 
9359
9360 \protected_separator 
9361
9362 \protected_separator 
9363
9364 \protected_separator 
9365
9366 \protected_separator 
9367
9368 \protected_separator 
9369
9370 \protected_separator 
9371  mov
9372 \protected_separator 
9373  r1,a 
9374 \newline 
9375
9376 \protected_separator 
9377
9378 \protected_separator 
9379
9380 \protected_separator 
9381
9382 \protected_separator 
9383
9384 \protected_separator 
9385
9386 \protected_separator 
9387
9388 \protected_separator 
9389  mov
9390 \protected_separator 
9391  a,@r0 
9392 \newline 
9393
9394 \protected_separator 
9395
9396 \protected_separator 
9397
9398 \protected_separator 
9399
9400 \protected_separator 
9401
9402 \protected_separator 
9403
9404 \protected_separator 
9405
9406 \protected_separator 
9407  add
9408 \protected_separator 
9409  a,@r1 
9410 \newline 
9411
9412 \protected_separator 
9413
9414 \protected_separator 
9415
9416 \protected_separator 
9417
9418 \protected_separator 
9419
9420 \protected_separator 
9421
9422 \protected_separator 
9423
9424 \protected_separator 
9425  mov
9426 \protected_separator 
9427  dpl,a 
9428 \newline 
9429
9430 \protected_separator 
9431
9432 \protected_separator 
9433
9434 \protected_separator 
9435
9436 \protected_separator 
9437
9438 \protected_separator 
9439
9440 \protected_separator 
9441
9442 \protected_separator 
9443  mov
9444 \protected_separator 
9445  dph,#0x00 
9446 \newline 
9447
9448 \protected_separator 
9449
9450 \protected_separator 
9451
9452 \protected_separator 
9453
9454 \protected_separator 
9455
9456 \protected_separator 
9457
9458 \protected_separator 
9459
9460 \protected_separator 
9461  mov
9462 \protected_separator 
9463  sp,_bp 
9464 \newline 
9465
9466 \protected_separator 
9467
9468 \protected_separator 
9469
9470 \protected_separator 
9471
9472 \protected_separator 
9473
9474 \protected_separator 
9475
9476 \protected_separator 
9477
9478 \protected_separator 
9479  pop
9480 \protected_separator 
9481  _bp 
9482 \newline 
9483
9484 \protected_separator 
9485
9486 \protected_separator 
9487
9488 \protected_separator 
9489
9490 \protected_separator 
9491
9492 \protected_separator 
9493
9494 \protected_separator 
9495
9496 \protected_separator 
9497  ret
9498 \layout Standard
9499
9500 The compiling and linking procedure remains the same, however note the extra
9501  entry & exit linkage required for the assembler code, _bp is the stack
9502  frame pointer and is used to compute the offset into the stack for parameters
9503  and local variables.
9504 \layout Section
9505
9506 External Stack.
9507 \begin_inset LatexCommand \label{xstack}
9508
9509 \end_inset 
9510
9511
9512 \layout Standard
9513
9514 The external stack is located at the start of the external ram segment ,
9515  and is 256 bytes in size.
9516  When --xstack option is used to compile the program , the parameters and
9517  local variables of all reentrant functions are allocated in this area.
9518  This option is provided for programs with large stack space requirements.
9519  When used with the --stack-auto option, all parameters and local variables
9520  are allocated on the external stack (note support libraries will need to
9521  be recompiled with the same options).
9522 \layout Standard
9523
9524 The compiler outputs the higher order address byte of the external ram segment
9525  into PORT P2, therefore when using the External Stack option, this port
9526  MAY NOT be used by the application program.
9527 \layout Section
9528
9529 ANSI-Compliance.
9530 \begin_inset LatexCommand \label{ANSI_Compliance}
9531
9532 \end_inset 
9533
9534
9535 \layout Standard
9536
9537 Deviations from the compliancy.
9538 \layout Enumerate
9539
9540 functions are not always reentrant.
9541 \layout Enumerate
9542
9543 structures cannot be assigned values directly, cannot be passed as function
9544  parameters or assigned to each other and cannot be a return value from
9545  a function.
9546 \begin_deeper 
9547 \layout Standard
9548
9549
9550 \size small 
9551 eg
9552 \end_deeper 
9553 \layout Standard
9554
9555
9556 \size small 
9557 struct s { ...
9558  }; 
9559 \newline 
9560 struct s s1, s2; 
9561 \newline 
9562 foo() 
9563 \newline 
9564
9565 \newline 
9566 ...
9567  
9568 \newline 
9569 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
9570 \newline 
9571 ...
9572  
9573 \newline 
9574 }
9575 \layout Standard
9576
9577
9578 \size small 
9579 struct s foo1 (struct s parms) /* is invalid in SDCC although allowed in
9580  ANSI */ 
9581 \newline 
9582
9583 \newline 
9584 struct s rets; 
9585 \newline 
9586 ...
9587  
9588 \newline 
9589 return rets;/* is invalid in SDCC although allowed in ANSI */ 
9590 \newline 
9591 }
9592 \layout Enumerate
9593
9594 'long long' (64 bit integers) not supported.
9595 \layout Enumerate
9596
9597 'double' precision floating point not supported.
9598 \layout Enumerate
9599
9600 integral promotions are suppressed.
9601  What does this mean ? The compiler will not implicitly promote an integer
9602  expression to a higher order integer, exception is an assignment or parameter
9603  passing.
9604  
9605 \layout Enumerate
9606
9607 No support for 
9608 \emph on 
9609 setjmp
9610 \emph default 
9611  and 
9612 \emph on 
9613 longjmp
9614 \emph default 
9615  (for now).
9616 \layout Enumerate
9617
9618 Old K&R style function declarations are NOT allowed.
9619 \layout Standard
9620
9621
9622 \size footnotesize 
9623 foo( i,j) /* this old style of function declarations */ 
9624 \newline 
9625 int i,j; /* are valid in ANSI ..
9626  not valid in SDCC */ 
9627 \newline 
9628
9629 \newline 
9630 ...
9631  
9632 \newline 
9633 }
9634 \layout Enumerate
9635
9636 functions declared as pointers must be dereferenced during the call.
9637 \begin_deeper 
9638 \layout Standard
9639
9640
9641 \size small 
9642 int (*foo)();
9643 \end_deeper 
9644 \layout Standard
9645
9646
9647 \size small 
9648
9649 \protected_separator 
9650  
9651 \protected_separator 
9652 ...
9653  
9654 \newline 
9655
9656 \protected_separator 
9657  
9658 \protected_separator 
9659 /* has to be called like this */ 
9660 \newline 
9661
9662 \protected_separator 
9663  
9664 \protected_separator 
9665 (*foo)();/* ansi standard allows calls to be made like 'foo()' */
9666 \layout Section
9667
9668 Cyclomatic Complexity
9669 \begin_inset LatexCommand \label{Cyclomatic}
9670
9671 \end_inset 
9672
9673
9674 \layout Standard
9675
9676 Cyclomatic complexity of a function is defined as the number of independent
9677  paths the program can take during execution of the function.
9678  This is an important number since it defines the number test cases you
9679  have to generate to validate the function .
9680  The accepted industry standard for complexity number is 10, if the cyclomatic
9681  complexity reported by SDCC exceeds 10 you should think about simplification
9682  of the function logic.
9683 \layout Standard
9684
9685 Note that the complexity level is not related to the number of lines of
9686  code in a function.
9687  Large functions can have low complexity, and small functions can have large
9688  complexity levels.
9689  SDCC uses the following formula to compute the complexity.
9690 \layout Standard
9691
9692
9693 \size small 
9694 complexity = (number of edges in control flow graph) - 
9695 \newline 
9696
9697 \protected_separator 
9698  
9699 \protected_separator 
9700  
9701 \protected_separator 
9702  
9703 \protected_separator 
9704  
9705 \protected_separator 
9706  
9707 \protected_separator 
9708  
9709 \protected_separator 
9710 (number of nodes in control flow graph) + 2;
9711 \layout Standard
9712
9713 Having said that the industry standard is 10, you should be aware that in
9714  some cases it may unavoidable to have a complexity level of less than 10.
9715  For example if you have switch statement with more than 10 case labels,
9716  each case label adds one to the complexity level.
9717  The complexity level is by no means an absolute measure of the algorithmic
9718  complexity of the function, it does however provide a good starting point
9719  for which functions you might look at for further optimization.
9720 \layout Section
9721
9722 TIPS
9723 \begin_inset LatexCommand \label{Tips}
9724
9725 \end_inset 
9726
9727
9728 \layout Standard
9729
9730 Here are a few guide-lines that will help the compiler generate more efficient
9731  code, some of the tips are specific to this compiler others are generally
9732  good programming practice.
9733 \layout Itemize
9734
9735 Use the smallest data type to represent your data-value.
9736  If it is known in advance that the value is going to be less than 256 then
9737  use a 'short' or 'char' instead of an 'int'.
9738 \layout Itemize
9739
9740 Use unsigned when it is known in advance that the value is not going to
9741  be negative.
9742  This helps especially if you are doing division or multiplication.
9743 \layout Itemize
9744
9745 NEVER jump into a LOOP.
9746 \layout Itemize
9747
9748 Declare the variables to be local whenever possible, especially loop control
9749  variables (induction).
9750 \layout Itemize
9751
9752 Since the compiler does not do implicit integral promotion, the programmer
9753  should do an explicit cast when integral promotion is required.
9754 \layout Itemize
9755
9756 Reducing the size of division , multiplication & modulus operations can
9757  reduce code size substantially.
9758  Take the following code for example.
9759 \begin_deeper 
9760 \layout Standard
9761
9762
9763 \size footnotesize 
9764 foobar( unsigned int p1, unsigned char ch)
9765 \newline 
9766 {
9767 \newline 
9768
9769 \protected_separator 
9770
9771 \protected_separator 
9772
9773 \protected_separator 
9774
9775 \protected_separator 
9776 unsigned char ch1 = p1 % ch ;
9777 \newline 
9778
9779 \protected_separator 
9780
9781 \protected_separator 
9782
9783 \protected_separator 
9784
9785 \protected_separator 
9786 ....
9787 \protected_separator 
9788
9789 \protected_separator 
9790
9791 \protected_separator 
9792
9793 \protected_separator 
9794
9795 \newline 
9796 }
9797 \layout Standard
9798
9799 For the modulus operation the variable ch will be promoted to unsigned int
9800  first then the modulus operation will be performed (this will lead to a
9801  call to a support routine).
9802  If the code is changed to 
9803 \layout Standard
9804
9805
9806 \size footnotesize 
9807 foobar( unsigned int p1, unsigned char ch)
9808 \newline 
9809 {
9810 \newline 
9811
9812 \protected_separator 
9813
9814 \protected_separator 
9815
9816 \protected_separator 
9817
9818 \protected_separator 
9819 unsigned char ch1 = (unsigned char)p1 % ch ;
9820 \newline 
9821
9822 \protected_separator 
9823
9824 \protected_separator 
9825
9826 \protected_separator 
9827
9828 \protected_separator 
9829 ....
9830 \protected_separator 
9831
9832 \protected_separator 
9833
9834 \protected_separator 
9835
9836 \protected_separator 
9837
9838 \newline 
9839 }
9840 \layout Standard
9841
9842 It would substantially reduce the code generated (future versions of the
9843  compiler will be smart enough to detect such optimization oppurtunities).
9844 \end_deeper 
9845 \layout Standard
9846
9847
9848 \series bold 
9849 Notes from an USER ( Trefor@magera.freeserve.co.uk )
9850 \layout Standard
9851
9852 The 8051 family of micro controller have a minimum of 128 bytes of internal
9853  memory which is structured as follows
9854 \layout Standard
9855
9856 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R7 to R7
9857  
9858 \layout Standard
9859
9860 - Bytes 20-2F - 16 bytes to hold 128 bit variables and 
9861 \layout Standard
9862
9863 - Bytes 30-7F - 60 bytes for general purpose use.
9864 \layout Standard
9865
9866 Normally the SDCC compiler will only utilise the first bank of registers,
9867  but it is possible to specify that other banks of registers should be used
9868  in interrupt routines.
9869  By default, the compiler will place the stack after the last bank of used
9870  registers, i.e.
9871  if the first 2 banks of registers are used, it will position the base of
9872  the internal stack at address 16 (0X10).
9873  This implies that as the stack grows, it will use up the remaining register
9874  banks, and the 16 bytes used by the 128 bit variables, and 60 bytes for
9875  general purpose use.
9876 \layout Standard
9877
9878 By default, the compiler uses the 60 general purpose bytes to hold "near
9879  data".
9880  The compiler/optimiser may also declare some Local Variables in this area
9881  to hold local data.
9882  
9883 \layout Standard
9884
9885 If any of the 128 bit variables are used, or near data is being used then
9886  care needs to be taken to ensure that the stack does not grow so much that
9887  it starts to over write either your bit variables or "near data".
9888  There is no runtime checking to prevent this from happening.
9889 \layout Standard
9890
9891 The amount of stack being used is affected by the use of the "internal stack"
9892  to save registers before a subroutine call is made, - --stack-auto will
9893  declare parameters and local variables on the stack - the number of nested
9894  subroutines.
9895 \layout Standard
9896
9897 If you detect that the stack is over writing you data, then the following
9898  can be done.
9899  --xstack will cause an external stack to be used for saving registers and
9900  (if --stack-auto is being used) storing parameters and local variables.
9901  However this will produce more and code which will be slower to execute.
9902  
9903 \layout Standard
9904
9905 --stack-loc will allow you specify the start of the stack, i.e.
9906  you could start it after any data in the general purpose area.
9907  However this may waste the memory not used by the register banks and if
9908  the size of the "near data" increases, it may creep into the bottom of
9909  the stack.
9910 \layout Standard
9911
9912 --stack-after-data, similar to the --stack-loc, but it automatically places
9913  the stack after the end of the "near data".
9914  Again this could waste any spare register space.
9915 \layout Standard
9916
9917 --data-loc allows you to specify the start address of the near data.
9918  This could be used to move the "near data" further away from the stack
9919  giving it more room to grow.
9920  This will only work if no bit variables are being used and the stack can
9921  grow to use the bit variable space.
9922 \layout Standard
9923
9924 Conclusion.
9925 \layout Standard
9926
9927 If you find that the stack is over writing your bit variables or "near data"
9928  then the approach which best utilised the internal memory is to position
9929  the "near data" after the last bank of used registers or, if you use bit
9930  variables, after the last bit variable by using the --data-loc, e.g.
9931  if two register banks are being used and no data variables, --data-loc
9932  16, and - use the --stack-after-data option.
9933 \layout Standard
9934
9935 If bit variables are being used, another method would be to try and squeeze
9936  the data area in the unused register banks if it will fit, and start the
9937  stack after the last bit variable.
9938 \layout Section
9939
9940 Retargetting for other MCUs.
9941 \begin_inset LatexCommand \label{Retargetting}
9942
9943 \end_inset 
9944
9945
9946 \layout Standard
9947
9948 The issues for retargetting the compiler are far too numerous to be covered
9949  by this document.
9950  What follows is a brief description of each of the seven phases of the
9951  compiler and its MCU dependency.
9952 \layout Enumerate
9953
9954 Parsing the source and building the annotated parse tree.
9955  This phase is largely MCU independent (except for the language extensions).
9956  Syntax & semantic checks are also done in this phase , along with some
9957  initial optimizations like back patching labels and the pattern matching
9958  optimizations like bit-rotation etc.
9959 \layout Enumerate
9960
9961 The second phase involves generating an intermediate code which can be easy
9962  manipulated during the later phases.
9963  This phase is entirely MCU independent.
9964  The intermediate code generation assumes the target machine has unlimited
9965  number of registers, and designates them with the name iTemp.
9966  The compiler can be made to dump a human readable form of the code generated
9967  by using the --dumpraw option.
9968 \layout Enumerate
9969
9970 This phase does the bulk of the standard optimizations and is also MCU independe
9971 nt.
9972  This phase can be broken down into several sub-phases.
9973 \begin_deeper 
9974 \layout Itemize
9975
9976 Break down intermediate code (iCode) into basic blocks.
9977 \layout Itemize
9978
9979 Do control flow & data flow analysis on the basic blocks.
9980 \layout Itemize
9981
9982 Do local common subexpression elimination, then global subexpression elimination
9983 \layout Itemize
9984
9985 dead code elimination
9986 \layout Itemize
9987
9988 loop optimizations
9989 \layout Itemize
9990
9991 if loop optimizations caused any changes then do 'global subexpression eliminati
9992 on' and 'dead code elimination' again.
9993 \end_deeper 
9994 \layout Enumerate
9995
9996 This phase determines the live-ranges; by live range I mean those iTemp
9997  variables defined by the compiler that still survive after all the optimization
9998 s.
9999  Live range analysis is essential for register allocation, since these computati
10000 on determines which of these iTemps will be assigned to registers, and for
10001  how long.
10002 \layout Enumerate
10003
10004 Phase five is register allocation.
10005  There are two parts to this process .
10006 \begin_deeper 
10007 \layout Enumerate
10008
10009 The first part I call 'register packing' (for lack of a better term) .
10010  In this case several MCU specific expression folding is done to reduce
10011  register pressure.
10012 \layout Enumerate
10013
10014 The second part is more MCU independent and deals with allocating registers
10015  to the remaining live ranges.
10016  A lot of MCU specific code does creep into this phase because of the limited
10017  number of index registers available in the 8051.
10018 \end_deeper 
10019 \layout Enumerate
10020
10021 The Code generation phase is (unhappily), entirely MCU dependent and very
10022  little (if any at all) of this code can be reused for other MCU.
10023  However the scheme for allocating a homogenized assembler operand for each
10024  iCode operand may be reused.
10025 \layout Enumerate
10026
10027 As mentioned in the optimization section the peep-hole optimizer is rule
10028  based system, which can reprogrammed for other MCUs.
10029 \layout Section
10030
10031 Reporting Bugs
10032 \begin_inset LatexCommand \label{Bugs}
10033
10034 \end_inset 
10035
10036
10037 \layout Standard
10038
10039 Shoot of an email to 'sandeep.dutta@usa.net', as a matter of principle I always
10040  reply to all email's sent to me.
10041  Bugs will be fixed ASAP.
10042  When reporting a bug , it is useful to include a small snippet of code
10043  that is causing the problem, if possible compile your program with the
10044  --dumpall option and send the dump files along with the bug report.
10045 \layout Section
10046
10047 SDCDB - Source level debugger.
10048 \layout Standard
10049
10050 SDCC is distributed with a source level debugger.
10051  The debugger uses a command line interface, the command repertoire of the
10052  debugger has been kept as close to gdb ( the GNU debugger) as possible.
10053  The configuration and build process of the compiler see Installation 
10054 \begin_inset LatexCommand \ref{Installation}
10055
10056 \end_inset 
10057
10058  also builds and installs the debugger in the target directory specified
10059  during configuration.
10060  The debugger allows you debug BOTH at the C source and at the ASM source
10061  level.
10062 \layout Subsection
10063
10064 Compiling for debugging.
10065 \layout Standard
10066
10067 The 
10068 \emph on 
10069 --debug
10070 \emph default 
10071  option must be specified for all files for which debug information is to
10072  be generated.
10073  The complier generates a 
10074 \emph on 
10075 .cdb
10076 \emph default 
10077  file for each of these files.
10078  The linker updates the 
10079 \emph on 
10080 .cdb
10081 \emph default 
10082  file with the address information.
10083  This .cdb is used by the debugger .
10084 \layout Subsection
10085
10086 How the debugger works.
10087 \layout Standard
10088
10089 When the 
10090 \emph on 
10091 --debug
10092 \emph default 
10093  option is specified the compiler generates extra symbol information some
10094  of which are put into the the assembler source and some are put into the
10095  .cdb file, the linker updates the .cdb file with the address information
10096  for the symbols.
10097  The debugger reads the symbolic information generated by the compiler &
10098  the address information generated by the linker.
10099  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
10100  execution is controlled by the debugger.
10101  When a command is issued for the debugger, it translates it into appropriate
10102  commands for the simulator .
10103 \layout Subsection
10104
10105 Starting the debugger.
10106 \layout Standard
10107
10108 The debugger can be started using the following command line.
10109  (Assume the file you are debugging has
10110 \layout Standard
10111
10112 the file name foo).
10113 \layout Standard
10114
10115 >sdcdb foo
10116 \layout Standard
10117
10118 The debugger will look for the following files.
10119 \layout Enumerate
10120
10121 foo.c - the source file.
10122 \layout Enumerate
10123
10124 foo.cdb - the debugger symbol information file.
10125 \layout Enumerate
10126
10127 foo.ihx - the intel hex format object file.
10128 \layout Subsection
10129
10130 Command line options.
10131 \layout Itemize
10132
10133 --directory=<source file directory> this option can used to specify the
10134  directory search list.
10135  The debugger will look into the directory list specified for source , cdb
10136  & ihx files.
10137  The items in the directory list must be separated by ':' , e.g.
10138  if the source files can be in the directories /home/src1 and /home/src2,
10139  the --directory option should be --directory=/home/src1:/home/src2 .
10140  Note there can be no spaces in the option.
10141  
10142 \layout Itemize
10143
10144 -cd <directory> - change to the <directory>.
10145 \layout Itemize
10146
10147 -fullname - used by GUI front ends.
10148 \layout Itemize
10149
10150 -cpu <cpu-type> - this argument is passed to the simulator please see the
10151  simulator docs for details.
10152 \layout Itemize
10153
10154 -X <Clock frequency > this options is passed to the simulator please see
10155  simulator docs for details.
10156 \layout Itemize
10157
10158 -s <serial port file> passed to simulator see simulator docs for details.
10159 \layout Itemize
10160
10161 -S <serial in,out> passed to simulator see simulator docs for details.
10162 \layout Subsection
10163
10164 Debugger Commands.
10165 \layout Standard
10166
10167 As mention earlier the command interface for the debugger has been deliberately
10168  kept as close the GNU debugger gdb , as possible, this will help int integratio
10169 n with existing graphical user interfaces (like ddd, xxgdb or xemacs) existing
10170  for the GNU debugger.
10171 \layout Subsubsection
10172
10173 break [line | file:line | function | file:function]
10174 \layout Standard
10175
10176 Set breakpoint at specified line or function.
10177 \layout Standard
10178
10179 sdcdb>break 100 
10180 \newline 
10181 sdcdb>break foo.c:100
10182 \newline 
10183 sdcdb>break funcfoo
10184 \newline 
10185 sdcdb>break foo.c:funcfoo
10186 \layout Subsubsection
10187
10188 clear [line | file:line | function | file:function ]
10189 \layout Standard
10190
10191 Clear breakpoint at specified line or function.
10192 \layout Standard
10193
10194 sdcdb>clear 100
10195 \newline 
10196 sdcdb>clear foo.c:100
10197 \newline 
10198 sdcdb>clear funcfoo
10199 \newline 
10200 sdcdb>clear foo.c:funcfoo
10201 \layout Subsubsection
10202
10203 continue
10204 \layout Standard
10205
10206 Continue program being debugged, after breakpoint.
10207 \layout Subsubsection
10208
10209 finish
10210 \layout Standard
10211
10212 Execute till the end of the current function.
10213 \layout Subsubsection
10214
10215 delete [n]
10216 \layout Standard
10217
10218 Delete breakpoint number 'n'.
10219  If used without any option clear ALL user defined break points.
10220 \layout Subsubsection
10221
10222 info [break | stack | frame | registers ]
10223 \layout Itemize
10224
10225 info break - list all breakpoints
10226 \layout Itemize
10227
10228 info stack - show the function call stack.
10229 \layout Itemize
10230
10231 info frame - show information about the current execution frame.
10232 \layout Itemize
10233
10234 info registers - show content of all registers.
10235 \layout Subsubsection
10236
10237 step
10238 \layout Standard
10239
10240 Step program until it reaches a different source line.
10241 \layout Subsubsection
10242
10243 next
10244 \layout Standard
10245
10246 Step program, proceeding through subroutine calls.
10247 \layout Subsubsection
10248
10249 run
10250 \layout Standard
10251
10252 Start debugged program.
10253 \layout Subsubsection
10254
10255 ptype variable 
10256 \layout Standard
10257
10258 Print type information of the variable.
10259 \layout Subsubsection
10260
10261 print variable
10262 \layout Standard
10263
10264 print value of variable.
10265 \layout Subsubsection
10266
10267 file filename
10268 \layout Standard
10269
10270 load the given file name.
10271  Note this is an alternate method of loading file for debugging.
10272 \layout Subsubsection
10273
10274 frame
10275 \layout Standard
10276
10277 print information about current frame.
10278 \layout Subsubsection
10279
10280 set srcmode
10281 \layout Standard
10282
10283 Toggle between C source & assembly source.
10284 \layout Subsubsection
10285
10286 ! simulator command
10287 \layout Standard
10288
10289 Send the string following '!' to the simulator, the simulator response is
10290  displayed.
10291  Note the debugger does not interpret the command being sent to the simulator,
10292  so if a command like 'go' is sent the debugger can loose its execution
10293  context and may display incorrect values.
10294 \layout Subsubsection
10295
10296 quit.
10297 \layout Standard
10298
10299 "Watch me now.
10300  Iam going Down.
10301  My name is Bobby Brown"
10302 \layout Subsection
10303
10304 Interfacing with XEmacs.
10305 \layout Standard
10306
10307 Two files are (in emacs lisp) are provided for the interfacing with XEmacs,
10308 \emph on 
10309  sdcdb.el
10310 \emph default 
10311  and 
10312 \emph on 
10313 sdcdbsrc.el
10314 \emph default 
10315 .
10316  These two files can be found in the $(prefix)/bin directory after the installat
10317 ion is complete.
10318  These files need to be loaded into XEmacs for the interface to work, this
10319  can be done at XEmacs startup time by inserting the following into your
10320  
10321 \emph on 
10322 '.xemacs'
10323 \emph default 
10324  file (which can be found in your HOME directory) 
10325 \emph on 
10326 (load-file sdcdbsrc.el) 
10327 \emph default 
10328 [ .xemacs is a lisp file so the () around the command is REQUIRED), the files
10329  can also be loaded dynamically while XEmacs is running, set the environment
10330  variable 
10331 \emph on 
10332 'EMACSLOADPATH' 
10333 \emph default 
10334 to the installation bin directory [$(prefix)/bin], then enter the following
10335  command 
10336 \emph on 
10337 ESC-x load-file sdcdbsrc .
10338  
10339 \emph default 
10340 To start the interface enter the following command 
10341 \emph on 
10342 ESC-x sdcdbsrc
10343 \emph default 
10344  , you will prompted to enter the file name to be debugged.
10345  
10346 \layout Standard
10347
10348 The command line options that are passed to the simulator directly are bound
10349  to default values in the file 
10350 \emph on 
10351 sdcdbsrc.el 
10352 \emph default 
10353 the variables are listed below these values maybe changed as required.
10354 \layout Itemize
10355
10356 sdcdbsrc-cpu-type '51
10357 \layout Itemize
10358
10359 sdcdbsrc-frequency '11059200
10360 \layout Itemize
10361
10362 sdcdbsrc-serial nil
10363 \layout Standard
10364
10365 The following is a list of key mapping for the debugger interface.
10366 \layout Standard
10367
10368
10369 \protected_separator 
10370
10371 \size scriptsize 
10372
10373 \newline 
10374 ;; Current Listing :: 
10375 \newline 
10376 ;;key
10377 \protected_separator 
10378
10379 \protected_separator 
10380
10381 \protected_separator 
10382
10383 \protected_separator 
10384
10385 \protected_separator 
10386
10387 \protected_separator 
10388
10389 \protected_separator 
10390
10391 \protected_separator 
10392
10393 \protected_separator 
10394
10395 \protected_separator 
10396
10397 \protected_separator 
10398
10399 \protected_separator 
10400
10401 \protected_separator 
10402
10403 \protected_separator 
10404
10405 \protected_separator 
10406 binding
10407 \protected_separator 
10408
10409 \protected_separator 
10410
10411 \protected_separator 
10412
10413 \protected_separator 
10414
10415 \protected_separator 
10416
10417 \protected_separator 
10418
10419 \protected_separator 
10420
10421 \protected_separator 
10422
10423 \protected_separator 
10424
10425 \protected_separator 
10426
10427 \protected_separator 
10428
10429 \protected_separator 
10430
10431 \protected_separator 
10432
10433 \protected_separator 
10434
10435 \protected_separator 
10436
10437 \protected_separator 
10438
10439 \protected_separator 
10440
10441 \protected_separator 
10442
10443 \protected_separator 
10444
10445 \protected_separator 
10446
10447 \protected_separator 
10448
10449 \protected_separator 
10450 Comment 
10451 \newline 
10452 ;;---
10453 \protected_separator 
10454
10455 \protected_separator 
10456
10457 \protected_separator 
10458
10459 \protected_separator 
10460
10461 \protected_separator 
10462
10463 \protected_separator 
10464
10465 \protected_separator 
10466
10467 \protected_separator 
10468
10469 \protected_separator 
10470
10471 \protected_separator 
10472
10473 \protected_separator 
10474
10475 \protected_separator 
10476
10477 \protected_separator 
10478
10479 \protected_separator 
10480
10481 \protected_separator 
10482 -------
10483 \protected_separator 
10484
10485 \protected_separator 
10486
10487 \protected_separator 
10488
10489 \protected_separator 
10490
10491 \protected_separator 
10492
10493 \protected_separator 
10494
10495 \protected_separator 
10496
10497 \protected_separator 
10498
10499 \protected_separator 
10500
10501 \protected_separator 
10502
10503 \protected_separator 
10504
10505 \protected_separator 
10506
10507 \protected_separator 
10508
10509 \protected_separator 
10510
10511 \protected_separator 
10512
10513 \protected_separator 
10514
10515 \protected_separator 
10516
10517 \protected_separator 
10518
10519 \protected_separator 
10520
10521 \protected_separator 
10522
10523 \protected_separator 
10524
10525 \protected_separator 
10526 ------- 
10527 \newline 
10528 ;; 
10529 \newline 
10530 ;; n
10531 \protected_separator 
10532
10533 \protected_separator 
10534
10535 \protected_separator 
10536
10537 \protected_separator 
10538
10539 \protected_separator 
10540
10541 \protected_separator 
10542
10543 \protected_separator 
10544
10545 \protected_separator 
10546
10547 \protected_separator 
10548
10549 \protected_separator 
10550
10551 \protected_separator 
10552
10553 \protected_separator 
10554
10555 \protected_separator 
10556
10557 \protected_separator 
10558  sdcdb-next-from-src
10559 \protected_separator 
10560
10561 \protected_separator 
10562
10563 \protected_separator 
10564
10565 \protected_separator 
10566
10567 \protected_separator 
10568
10569 \protected_separator 
10570
10571 \protected_separator 
10572
10573 \protected_separator 
10574
10575 \protected_separator 
10576
10577 \protected_separator 
10578 SDCDB next command 
10579 \newline 
10580 ;; b
10581 \protected_separator 
10582
10583 \protected_separator 
10584
10585 \protected_separator 
10586
10587 \protected_separator 
10588
10589 \protected_separator 
10590
10591 \protected_separator 
10592
10593 \protected_separator 
10594
10595 \protected_separator 
10596
10597 \protected_separator 
10598
10599 \protected_separator 
10600
10601 \protected_separator 
10602
10603 \protected_separator 
10604
10605 \protected_separator 
10606
10607 \protected_separator 
10608  sdcdb-back-from-src
10609 \protected_separator 
10610
10611 \protected_separator 
10612
10613 \protected_separator 
10614
10615 \protected_separator 
10616
10617 \protected_separator 
10618
10619 \protected_separator 
10620
10621 \protected_separator 
10622
10623 \protected_separator 
10624
10625 \protected_separator 
10626
10627 \protected_separator 
10628 SDCDB back command 
10629 \newline 
10630 ;; c
10631 \protected_separator 
10632
10633 \protected_separator 
10634
10635 \protected_separator 
10636
10637 \protected_separator 
10638
10639 \protected_separator 
10640
10641 \protected_separator 
10642
10643 \protected_separator 
10644
10645 \protected_separator 
10646
10647 \protected_separator 
10648
10649 \protected_separator 
10650
10651 \protected_separator 
10652
10653 \protected_separator 
10654
10655 \protected_separator 
10656
10657 \protected_separator 
10658  sdcdb-cont-from-src
10659 \protected_separator 
10660
10661 \protected_separator 
10662
10663 \protected_separator 
10664
10665 \protected_separator 
10666
10667 \protected_separator 
10668
10669 \protected_separator 
10670
10671 \protected_separator 
10672
10673 \protected_separator 
10674
10675 \protected_separator 
10676
10677 \protected_separator 
10678 SDCDB continue command
10679 \newline 
10680 ;; s
10681 \protected_separator 
10682
10683 \protected_separator 
10684
10685 \protected_separator 
10686
10687 \protected_separator 
10688
10689 \protected_separator 
10690
10691 \protected_separator 
10692
10693 \protected_separator 
10694
10695 \protected_separator 
10696
10697 \protected_separator 
10698
10699 \protected_separator 
10700
10701 \protected_separator 
10702
10703 \protected_separator 
10704
10705 \protected_separator 
10706
10707 \protected_separator 
10708  sdcdb-step-from-src
10709 \protected_separator 
10710
10711 \protected_separator 
10712
10713 \protected_separator 
10714
10715 \protected_separator 
10716
10717 \protected_separator 
10718
10719 \protected_separator 
10720
10721 \protected_separator 
10722
10723 \protected_separator 
10724
10725 \protected_separator 
10726
10727 \protected_separator 
10728 SDCDB step command 
10729 \newline 
10730 ;; ?
10731 \protected_separator 
10732
10733 \protected_separator 
10734
10735 \protected_separator 
10736
10737 \protected_separator 
10738
10739 \protected_separator 
10740
10741 \protected_separator 
10742
10743 \protected_separator 
10744
10745 \protected_separator 
10746
10747 \protected_separator 
10748
10749 \protected_separator 
10750
10751 \protected_separator 
10752
10753 \protected_separator 
10754
10755 \protected_separator 
10756
10757 \protected_separator 
10758  sdcdb-whatis-c-sexp
10759 \protected_separator 
10760
10761 \protected_separator 
10762
10763 \protected_separator 
10764
10765 \protected_separator 
10766
10767 \protected_separator 
10768
10769 \protected_separator 
10770
10771 \protected_separator 
10772
10773 \protected_separator 
10774
10775 \protected_separator 
10776
10777 \protected_separator 
10778 SDCDB ptypecommand for data at 
10779 \newline 
10780 ;;
10781 \protected_separator 
10782
10783 \protected_separator 
10784
10785 \protected_separator 
10786
10787 \protected_separator 
10788
10789 \protected_separator 
10790
10791 \protected_separator 
10792
10793 \protected_separator 
10794
10795 \protected_separator 
10796
10797 \protected_separator 
10798
10799 \protected_separator 
10800
10801 \protected_separator 
10802
10803 \protected_separator 
10804
10805 \protected_separator 
10806
10807 \protected_separator 
10808
10809 \protected_separator 
10810
10811 \protected_separator 
10812
10813 \protected_separator 
10814
10815 \protected_separator 
10816
10817 \protected_separator 
10818
10819 \protected_separator 
10820
10821 \protected_separator 
10822
10823 \protected_separator 
10824
10825 \protected_separator 
10826
10827 \protected_separator 
10828
10829 \protected_separator 
10830
10831 \protected_separator 
10832
10833 \protected_separator 
10834
10835 \protected_separator 
10836
10837 \protected_separator 
10838
10839 \protected_separator 
10840
10841 \protected_separator 
10842
10843 \protected_separator 
10844
10845 \protected_separator 
10846
10847 \protected_separator 
10848
10849 \protected_separator 
10850
10851 \protected_separator 
10852
10853 \protected_separator 
10854
10855 \protected_separator 
10856
10857 \protected_separator 
10858
10859 \protected_separator 
10860
10861 \protected_separator 
10862
10863 \protected_separator 
10864  buffer point 
10865 \newline 
10866 ;; x
10867 \protected_separator 
10868
10869 \protected_separator 
10870
10871 \protected_separator 
10872
10873 \protected_separator 
10874
10875 \protected_separator 
10876
10877 \protected_separator 
10878
10879 \protected_separator 
10880
10881 \protected_separator 
10882
10883 \protected_separator 
10884
10885 \protected_separator 
10886
10887 \protected_separator 
10888
10889 \protected_separator 
10890
10891 \protected_separator 
10892
10893 \protected_separator 
10894  sdcdbsrc-delete
10895 \protected_separator 
10896
10897 \protected_separator 
10898
10899 \protected_separator 
10900
10901 \protected_separator 
10902
10903 \protected_separator 
10904
10905 \protected_separator 
10906
10907 \protected_separator 
10908
10909 \protected_separator 
10910
10911 \protected_separator 
10912
10913 \protected_separator 
10914
10915 \protected_separator 
10916
10917 \protected_separator 
10918
10919 \protected_separator 
10920
10921 \protected_separator 
10922 SDCDB Delete all breakpoints if no arg 
10923 \newline 
10924 ;;
10925 \protected_separator 
10926
10927 \protected_separator 
10928
10929 \protected_separator 
10930
10931 \protected_separator 
10932
10933 \protected_separator 
10934
10935 \protected_separator 
10936
10937 \protected_separator 
10938
10939 \protected_separator 
10940
10941 \protected_separator 
10942
10943 \protected_separator 
10944
10945 \protected_separator 
10946
10947 \protected_separator 
10948
10949 \protected_separator 
10950
10951 \protected_separator 
10952
10953 \protected_separator 
10954
10955 \protected_separator 
10956
10957 \protected_separator 
10958
10959 \protected_separator 
10960
10961 \protected_separator 
10962
10963 \protected_separator 
10964
10965 \protected_separator 
10966
10967 \protected_separator 
10968
10969 \protected_separator 
10970
10971 \protected_separator 
10972
10973 \protected_separator 
10974
10975 \protected_separator 
10976
10977 \protected_separator 
10978
10979 \protected_separator 
10980
10981 \protected_separator 
10982
10983 \protected_separator 
10984
10985 \protected_separator 
10986
10987 \protected_separator 
10988
10989 \protected_separator 
10990
10991 \protected_separator 
10992
10993 \protected_separator 
10994
10995 \protected_separator 
10996
10997 \protected_separator 
10998
10999 \protected_separator 
11000
11001 \protected_separator 
11002
11003 \protected_separator 
11004
11005 \protected_separator 
11006
11007 \protected_separator 
11008
11009 \protected_separator 
11010
11011 \protected_separator 
11012
11013 \protected_separator 
11014
11015 \protected_separator 
11016 given or delete arg (C-u arg x) 
11017 \newline 
11018 ;; m
11019 \protected_separator 
11020
11021 \protected_separator 
11022
11023 \protected_separator 
11024
11025 \protected_separator 
11026
11027 \protected_separator 
11028
11029 \protected_separator 
11030
11031 \protected_separator 
11032
11033 \protected_separator 
11034
11035 \protected_separator 
11036
11037 \protected_separator 
11038
11039 \protected_separator 
11040
11041 \protected_separator 
11042
11043 \protected_separator 
11044
11045 \protected_separator 
11046  sdcdbsrc-frame
11047 \protected_separator 
11048
11049 \protected_separator 
11050
11051 \protected_separator 
11052
11053 \protected_separator 
11054
11055 \protected_separator 
11056
11057 \protected_separator 
11058
11059 \protected_separator 
11060
11061 \protected_separator 
11062
11063 \protected_separator 
11064
11065 \protected_separator 
11066
11067 \protected_separator 
11068
11069 \protected_separator 
11070
11071 \protected_separator 
11072
11073 \protected_separator 
11074
11075 \protected_separator 
11076 SDCDB Display current frame if no arg, 
11077 \newline 
11078 ;;
11079 \protected_separator 
11080
11081 \protected_separator 
11082
11083 \protected_separator 
11084
11085 \protected_separator 
11086
11087 \protected_separator 
11088
11089 \protected_separator 
11090
11091 \protected_separator 
11092
11093 \protected_separator 
11094
11095 \protected_separator 
11096
11097 \protected_separator 
11098
11099 \protected_separator 
11100
11101 \protected_separator 
11102
11103 \protected_separator 
11104
11105 \protected_separator 
11106
11107 \protected_separator 
11108
11109 \protected_separator 
11110
11111 \protected_separator 
11112
11113 \protected_separator 
11114
11115 \protected_separator 
11116
11117 \protected_separator 
11118
11119 \protected_separator 
11120
11121 \protected_separator 
11122
11123 \protected_separator 
11124
11125 \protected_separator 
11126
11127 \protected_separator 
11128
11129 \protected_separator 
11130
11131 \protected_separator 
11132
11133 \protected_separator 
11134
11135 \protected_separator 
11136
11137 \protected_separator 
11138
11139 \protected_separator 
11140
11141 \protected_separator 
11142
11143 \protected_separator 
11144
11145 \protected_separator 
11146
11147 \protected_separator 
11148
11149 \protected_separator 
11150
11151 \protected_separator 
11152
11153 \protected_separator 
11154
11155 \protected_separator 
11156
11157 \protected_separator 
11158
11159 \protected_separator 
11160
11161 \protected_separator 
11162
11163 \protected_separator 
11164
11165 \protected_separator 
11166
11167 \protected_separator 
11168
11169 \protected_separator 
11170 given or display frame arg 
11171 \newline 
11172 ;;
11173 \protected_separator 
11174
11175 \protected_separator 
11176
11177 \protected_separator 
11178
11179 \protected_separator 
11180
11181 \protected_separator 
11182
11183 \protected_separator 
11184
11185 \protected_separator 
11186
11187 \protected_separator 
11188
11189 \protected_separator 
11190
11191 \protected_separator 
11192
11193 \protected_separator 
11194
11195 \protected_separator 
11196
11197 \protected_separator 
11198
11199 \protected_separator 
11200
11201 \protected_separator 
11202
11203 \protected_separator 
11204
11205 \protected_separator 
11206
11207 \protected_separator 
11208
11209 \protected_separator 
11210
11211 \protected_separator 
11212
11213 \protected_separator 
11214
11215 \protected_separator 
11216
11217 \protected_separator 
11218
11219 \protected_separator 
11220
11221 \protected_separator 
11222
11223 \protected_separator 
11224
11225 \protected_separator 
11226
11227 \protected_separator 
11228
11229 \protected_separator 
11230
11231 \protected_separator 
11232
11233 \protected_separator 
11234
11235 \protected_separator 
11236
11237 \protected_separator 
11238
11239 \protected_separator 
11240
11241 \protected_separator 
11242
11243 \protected_separator 
11244
11245 \protected_separator 
11246
11247 \protected_separator 
11248
11249 \protected_separator 
11250
11251 \protected_separator 
11252
11253 \protected_separator 
11254
11255 \protected_separator 
11256
11257 \protected_separator 
11258
11259 \protected_separator 
11260
11261 \protected_separator 
11262 buffer point 
11263 \newline 
11264 ;; !
11265 \protected_separator 
11266
11267 \protected_separator 
11268
11269 \protected_separator 
11270
11271 \protected_separator 
11272
11273 \protected_separator 
11274
11275 \protected_separator 
11276
11277 \protected_separator 
11278
11279 \protected_separator 
11280
11281 \protected_separator 
11282
11283 \protected_separator 
11284
11285 \protected_separator 
11286
11287 \protected_separator 
11288
11289 \protected_separator 
11290
11291 \protected_separator 
11292  sdcdbsrc-goto-sdcdb
11293 \protected_separator 
11294
11295 \protected_separator 
11296
11297 \protected_separator 
11298
11299 \protected_separator 
11300
11301 \protected_separator 
11302
11303 \protected_separator 
11304
11305 \protected_separator 
11306
11307 \protected_separator 
11308
11309 \protected_separator 
11310
11311 \protected_separator 
11312 Goto the SDCDB output buffer 
11313 \newline 
11314 ;; p
11315 \protected_separator 
11316
11317 \protected_separator 
11318
11319 \protected_separator 
11320
11321 \protected_separator 
11322
11323 \protected_separator 
11324
11325 \protected_separator 
11326
11327 \protected_separator 
11328
11329 \protected_separator 
11330
11331 \protected_separator 
11332
11333 \protected_separator 
11334
11335 \protected_separator 
11336
11337 \protected_separator 
11338
11339 \protected_separator 
11340
11341 \protected_separator 
11342  sdcdb-print-c-sexp
11343 \protected_separator 
11344
11345 \protected_separator 
11346
11347 \protected_separator 
11348
11349 \protected_separator 
11350
11351 \protected_separator 
11352
11353 \protected_separator 
11354
11355 \protected_separator 
11356
11357 \protected_separator 
11358
11359 \protected_separator 
11360
11361 \protected_separator 
11362
11363 \protected_separator 
11364 SDCDB print command for data at 
11365 \newline 
11366 ;;
11367 \protected_separator 
11368
11369 \protected_separator 
11370
11371 \protected_separator 
11372
11373 \protected_separator 
11374
11375 \protected_separator 
11376
11377 \protected_separator 
11378
11379 \protected_separator 
11380
11381 \protected_separator 
11382
11383 \protected_separator 
11384
11385 \protected_separator 
11386
11387 \protected_separator 
11388
11389 \protected_separator 
11390
11391 \protected_separator 
11392
11393 \protected_separator 
11394
11395 \protected_separator 
11396
11397 \protected_separator 
11398
11399 \protected_separator 
11400
11401 \protected_separator 
11402
11403 \protected_separator 
11404
11405 \protected_separator 
11406
11407 \protected_separator 
11408
11409 \protected_separator 
11410
11411 \protected_separator 
11412
11413 \protected_separator 
11414
11415 \protected_separator 
11416
11417 \protected_separator 
11418
11419 \protected_separator 
11420
11421 \protected_separator 
11422
11423 \protected_separator 
11424
11425 \protected_separator 
11426
11427 \protected_separator 
11428
11429 \protected_separator 
11430
11431 \protected_separator 
11432
11433 \protected_separator 
11434
11435 \protected_separator 
11436
11437 \protected_separator 
11438
11439 \protected_separator 
11440
11441 \protected_separator 
11442
11443 \protected_separator 
11444
11445 \protected_separator 
11446
11447 \protected_separator 
11448
11449 \protected_separator 
11450  buffer point 
11451 \newline 
11452 ;; g
11453 \protected_separator 
11454
11455 \protected_separator 
11456
11457 \protected_separator 
11458
11459 \protected_separator 
11460
11461 \protected_separator 
11462
11463 \protected_separator 
11464
11465 \protected_separator 
11466
11467 \protected_separator 
11468
11469 \protected_separator 
11470
11471 \protected_separator 
11472
11473 \protected_separator 
11474
11475 \protected_separator 
11476
11477 \protected_separator 
11478
11479 \protected_separator 
11480  sdcdbsrc-goto-sdcdb
11481 \protected_separator 
11482
11483 \protected_separator 
11484
11485 \protected_separator 
11486
11487 \protected_separator 
11488
11489 \protected_separator 
11490
11491 \protected_separator 
11492
11493 \protected_separator 
11494
11495 \protected_separator 
11496
11497 \protected_separator 
11498
11499 \protected_separator 
11500 Goto the SDCDB output buffer 
11501 \newline 
11502 ;; t
11503 \protected_separator 
11504
11505 \protected_separator 
11506
11507 \protected_separator 
11508
11509 \protected_separator 
11510
11511 \protected_separator 
11512
11513 \protected_separator 
11514
11515 \protected_separator 
11516
11517 \protected_separator 
11518
11519 \protected_separator 
11520
11521 \protected_separator 
11522
11523 \protected_separator 
11524
11525 \protected_separator 
11526
11527 \protected_separator 
11528
11529 \protected_separator 
11530  sdcdbsrc-mode
11531 \protected_separator 
11532
11533 \protected_separator 
11534
11535 \protected_separator 
11536
11537 \protected_separator 
11538
11539 \protected_separator 
11540
11541 \protected_separator 
11542
11543 \protected_separator 
11544
11545 \protected_separator 
11546
11547 \protected_separator 
11548
11549 \protected_separator 
11550
11551 \protected_separator 
11552
11553 \protected_separator 
11554
11555 \protected_separator 
11556
11557 \protected_separator 
11558
11559 \protected_separator 
11560
11561 \protected_separator 
11562 Toggles Sdcdbsrc mode (turns it off) 
11563 \newline 
11564 ;; 
11565 \newline 
11566 ;; C-c C-f
11567 \protected_separator 
11568
11569 \protected_separator 
11570
11571 \protected_separator 
11572
11573 \protected_separator 
11574
11575 \protected_separator 
11576
11577 \protected_separator 
11578
11579 \protected_separator 
11580
11581 \protected_separator 
11582  sdcdb-finish-from-src
11583 \protected_separator 
11584
11585 \protected_separator 
11586
11587 \protected_separator 
11588
11589 \protected_separator 
11590
11591 \protected_separator 
11592
11593 \protected_separator 
11594
11595 \protected_separator 
11596
11597 \protected_separator 
11598 SDCDB finish command 
11599 \newline 
11600 ;; 
11601 \newline 
11602 ;; C-x SPC
11603 \protected_separator 
11604
11605 \protected_separator 
11606
11607 \protected_separator 
11608
11609 \protected_separator 
11610
11611 \protected_separator 
11612
11613 \protected_separator 
11614
11615 \protected_separator 
11616
11617 \protected_separator 
11618  sdcdb-break
11619 \protected_separator 
11620
11621 \protected_separator 
11622
11623 \protected_separator 
11624
11625 \protected_separator 
11626
11627 \protected_separator 
11628
11629 \protected_separator 
11630
11631 \protected_separator 
11632
11633 \protected_separator 
11634
11635 \protected_separator 
11636
11637 \protected_separator 
11638
11639 \protected_separator 
11640
11641 \protected_separator 
11642
11643 \protected_separator 
11644
11645 \protected_separator 
11646
11647 \protected_separator 
11648
11649 \protected_separator 
11650
11651 \protected_separator 
11652
11653 \protected_separator 
11654 Set break for line with point 
11655 \newline 
11656 ;; ESC t
11657 \protected_separator 
11658
11659 \protected_separator 
11660
11661 \protected_separator 
11662
11663 \protected_separator 
11664
11665 \protected_separator 
11666
11667 \protected_separator 
11668
11669 \protected_separator 
11670
11671 \protected_separator 
11672
11673 \protected_separator 
11674
11675 \protected_separator 
11676  sdcdbsrc-mode
11677 \protected_separator 
11678
11679 \protected_separator 
11680
11681 \protected_separator 
11682
11683 \protected_separator 
11684
11685 \protected_separator 
11686
11687 \protected_separator 
11688
11689 \protected_separator 
11690
11691 \protected_separator 
11692
11693 \protected_separator 
11694
11695 \protected_separator 
11696
11697 \protected_separator 
11698
11699 \protected_separator 
11700
11701 \protected_separator 
11702
11703 \protected_separator 
11704
11705 \protected_separator 
11706
11707 \protected_separator 
11708 Toggle Sdcdbsrc mode 
11709 \newline 
11710 ;; ESC m
11711 \protected_separator 
11712
11713 \protected_separator 
11714
11715 \protected_separator 
11716
11717 \protected_separator 
11718
11719 \protected_separator 
11720
11721 \protected_separator 
11722
11723 \protected_separator 
11724
11725 \protected_separator 
11726
11727 \protected_separator 
11728
11729 \protected_separator 
11730  sdcdbsrc-srcmode
11731 \protected_separator 
11732
11733 \protected_separator 
11734
11735 \protected_separator 
11736
11737 \protected_separator 
11738
11739 \protected_separator 
11740
11741 \protected_separator 
11742
11743 \protected_separator 
11744
11745 \protected_separator 
11746
11747 \protected_separator 
11748
11749 \protected_separator 
11750
11751 \protected_separator 
11752
11753 \protected_separator 
11754  Toggle list mode 
11755 \newline 
11756 ;; 
11757 \newline 
11758
11759 \layout Section
11760
11761 Conclusion
11762 \begin_inset LatexCommand \label{Conclusion}
11763
11764 \end_inset 
11765
11766
11767 \layout Standard
11768
11769 SDCC is a large project , the compiler alone (without the Assembler Package
11770  , Preprocessor & garbage collector) is about 40,000 lines of code (blank
11771  stripped).
11772  As with any project of this size there are bound to be bugs, I am more
11773  than willing to work to fix these bugs , of course all the source code
11774  is included with the package.
11775  
11776 \layout Standard
11777
11778 Where does it go from here ? I am planning to target the Atmel AVR 8-bit
11779  MCUs which seems to have a lot of users.
11780  I am also planning to include an alias analysis system with this compiler
11781  (it does not currently have one).
11782 \layout Section
11783
11784 Acknowledgments
11785 \begin_inset LatexCommand \label{Acknowledgements}
11786
11787 \end_inset 
11788
11789
11790 \layout Standard
11791
11792 Alan Baldwin (baldwin@shop-pdp.kent.edu) - Initial version of ASXXXX & ASLINK.
11793  
11794 \layout Standard
11795
11796 John Hartman (jhartman@compuserve.com) - Porting ASXXX & ASLINK for 8051
11797 \layout Standard
11798
11799 Dmitry S.
11800  Obukhov (dso@usa.net) - malloc & serial i/o routines.
11801  
11802 \layout Standard
11803
11804 Daniel Drotos <drdani@mazsola.iit.uni-miskolc.hu> - for his Freeware simulator
11805 \layout Standard
11806
11807 Jans J Boehm(boehm@sgi.com) and Alan J Demers - Conservative garbage collector
11808  for C & C++.
11809 \layout Standard
11810
11811 Malini Dutta(malini_dutta@hotmail.com) - my wife for her patience and support.
11812 \layout Standard
11813
11814 Unknown - for the GNU C - preprocessor.
11815 \layout Section
11816
11817 Appendix A: The Z80 and gbz80 port
11818 \layout Standard
11819
11820 2.2.0 can target both the Zilog Z80 and the Nintendo Gameboy's Z80-like gbz80.
11821  The port is incomplete - long support is incomplete (mul, div and mod are
11822  unimplimented), and both float and bitfield support is missing, but apart
11823  from that the code generated is correct.
11824 \layout Standard
11825
11826 As always, the code is the authoritave reference - see z80/ralloc.c and z80/gen.c.
11827  The stack frame is similar to that generated by the IAR Z80 compiler.
11828  IX is used as the base pointer, HL is used as a temporary register, and
11829  BC and DE are available for holding varibles.
11830  IY is currently unusued.
11831  Return values are stored in HL.
11832  One bad side effect of using IX as the base pointer is that a functions
11833  stack frame is limited to 127 bytes - this will be fixed in a later version.bc
11834 \layout Standard
11835
11836 9
11837 \layout Standard
11838
11839
11840 \begin_inset LatexCommand \index{}
11841
11842 \end_inset 
11843
11844
11845 \the_end