-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathZ80DOC.TXT
11351 lines (5596 loc) · 294 KB
/
Z80DOC.TXT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
HI-TECH C USER'S MANUAL i
CONTENTS
1. Introduction 1
1.1. Features 1
1.2. System Requirements 2
1.3. Using this Manual 2
2. Getting Started 3
3. Compiler Structure 5
4. Operating Details 7
5. Specific Features 13
5.1. ANSI C Standard Compatibility 13
5.2. Type Checking 13
5.3. Member Names 13
5.4. Unsigned Types 14
5.5. Arithmetic Operations 14
5.6. Structure Operations 15
5.7. Enumerated Types 16
5.8. Initialization Syntax 16
5.9. Function Prototypes 17
5.10. Void and Pointer to Void 18
5.11. Type qualifiers 19
5.12. 20
5.13. Pragma Directives 20
6. Machine Dependencies 21
6.1. Predefined Macros 21
7. Error Checking and Reporting 23
8. Standard Libraries 25
8.1. Standard I/O 25
8.2. Compatibility 25
8.3. Libraries for Embedded Systems 25
8.4. Binary I/O 26
8.5. Floating Point Library 27
9. Stylistic Considerations 29
9.1. Member Names 29
9.2. Use of Int 30
9.3. Extern Declarations 30
10. Memory Models 31
11. What Went Wrong 33
12. Z80 Assembler Reference Manual 35
12.1. Introduction 35
12.2. Usage 35
12.3. The Assembly Language 36
12.3.1. Symbols 36
12.3.1.1. Temporary Labels 37
12.3.2. Constants 37
12.3.2.1. Character Constants 38
ii HI-TECH C USER'S MANUAL
12.3.2.2. Floating Constants 38
12.3.2.3. Opcode Constants 38
12.3.3. Expressions 38
12.3.3.1. Operators 38
12.3.3.2. Relocatability 39
12.3.4. Pseudo-ops 40
12.3.4.1. DEFB, DB 40
12.3.4.2. DEFF 41
12.3.4.3. DEFW 41
12.3.4.4. DEFS 41
12.3.4.5. EQU 41
12.3.4.6. DEFL 41
12.3.4.7. DEFM 42
12.3.4.8. END 42
12.3.4.9. COND, IF, ELSE, ENDC 42
12.3.4.10. ELSE 42
12.3.4.11. ENDC 42
12.3.4.12. ENDM 43
12.3.4.13. PSECT 43
12.3.4.14. GLOBAL 43
12.3.4.15. ORG 44
12.3.4.16. MACRO 44
12.3.4.17. LOCAL 45
12.3.4.18. REPT 46
12.3.5. IRP and IRPC 47
12.3.6. Extended Condition Codes 48
12.4. Assembler Directives 48
12.5. Diagnostics 49
12.6. Z80/Z180/64180 Instruction Set 50
13. Linker Reference Manual 69
13.1. Relocation and Psects 69
13.1.1. Program Sections 69
13.1.2. Local Psects and the Large Model 70
13.2. Global Symbols 70
13.3. Operation 71
13.4. Examples 74
13.5. Invoking the Linker 74
14. Librarian 75
14.1. The Library Format 75
14.2. Using 75
14.3. Examples 76
14.4. Supplying Arguments 77
14.5. Listing Format 77
14.6. Ordering of Libraries 77
14.7. Error Messages 78
15. Objtohex 79
16. Cref 83
APPENDIX 1 Error Messages 85
APPENDIX 2 Standard Library Functions 99
INDEX 165
HI-TECH C COMPILER
User's Manual
March 1989
1. Introduction
The HI-TECH C Compiler is a set of software which
translates programs written in the C language to executable
machine code programs. Versions are available which compile
programs for operation under the host operating system, or
which produce programs for execution in embedded systems
without an operating system.
1.1. Features
Some of HI-TECH C's features are:
A single command will compile, assemble and link entire
programs.
The compiler performs strong type checking and issues
warnings about various constructs which may represent
programming errors.
The generated code is extremely small and fast in exe-
cution.
A full run-time library is provided implementing all
standard C input/output and other functions.
The source code for all run-time routines is provided.
A powerful general purpose macro assembler is included.
Programs may be generated to execute under the host
operating system, or customized for installation in
ROM.
PC-DOS/MS-DOS
CP/M-86
Concurrent DOS
Atari ST
Xenix
Unix
CP/M-80
Table 1. Supported Hosts
Page 2 HI-TECH C USER'S MANUAL
1.2. System Requirements
The HI-TECH C Compilers operate under the operating
sytems listed in table 1. Ensure that the version of the
compiler you have matches the system you have. Note that in
general you must have a hard disk or two floppy disks on
your system (it is possible to use one floppy disk of 800K
or more). A hard disk is strongly recommended. Note that
the CP/M-80 native compiler does not have all the features
described in this manual, as it has not been upgraded past
V3.09 due to memory limitations. The Z80 cross compiler
does support all of the features described here and can be
used to generate programs to execute under CP/M-80.
1.3. Using this Manual
The documentation supplied with the HI-TECH C compiler
comprises two separate manuals within the one binder. The
manual you are reading now covers all versions of the com-
piler (reflecting the portable nature of the compiler). A
separate manual covers machine dependent aspects of your
compiler, e.g. installation.
This manual assumes you are familiar with the C
language already. If you are not, you should have at least
one reference book covering C, of which a large number are
available from most computer bookstores, e.g. "A Book on C"
by Kelley and Pohl. Other suitable texts are "Programming in
ANSI C" by S. Kochan and "The C Programming Language", by
Kernighan and Ritchie. You should read the "Getting Started"
chapter in this manual, and the "Installation" chapter in
the machine-specific manual. This will provide you with
sufficient information to work through the introductory
examples in the C reference you are using.
Once you have a basic grasp of the C language, the
remainder of this manual will provide you with information
to enable you to explore the more advanced aspects of C.
Most of the manual covers all implementations of the
HI-TECH C compiler. A separate manual is provided for the
macro assembler for your particular machine, and other
machine-dependent information.
HI-TECH C USER'S MANUAL Page 3
2. Getting Started
If using the compiler on a hard disk system you will
need to install the compiler before using it. See the
"Installation" chapter for more details. If using a floppy
disk based system, in general you should have a copy of the
distribution disk #1 in drive A: and maintain your files on
a disk in the B: drive. Again see the "Installation" chapter
for more information.
main()
{
printf("Hello, world\n");
}
Fig. 1. Sample C Program
Before compiling your program it must be contained in a
file with an extension (or file type, i.e. that part of the
name after the '.') of .C. For example you may type the
program shown in fig. 1 into a file called HELLO.C. You will
need a text editor to do this. Generally any text editor
that can create a straight ASCII file (i.e. not a "word pro-
cessor" type file) will be suitable. If using editors such
as Wordstar, you should use the "non-document mode". Once
you have the program in such a file all that is required to
compile it is to issue the C command, e.g. to compile
HELLO.C simply type the command
C -V HELLO.C
Cross compilers (i.e. compilers that operate on one system
but produce code for a separate target system) will have a
compiler driver named slightly differently, e.g. the 68HC11
cross compiler driver is called C68.
If you are using a floppy disk based system (or a CP/M
system) it may be necessary to specify where to find the C
command, e.g. if the C command is on a disk in drive A: and
you are working on B:, type the command
A:C -V HELLO.C
The compiler will issue a sign on message, then proceed
to execute the various passes of the compiler in sequence to
compile the program. If you are using a floppy disk based
system where the compiler will not fit on a single disk you
will be prompted to change disks whenever the compiler can-
not find a pass. In this case you should insert a copy of
the next distribution disk in drive A: and press RETURN.
As each pass of the compiler is about to be executed, a
command line to that pass will be displayed on the screen.
Page 4 HI-TECH C USER'S MANUAL
This is because the -V option has been used. This stands for
Verbose, and had it not been given the compilation would
have been silent except for the sign on message. Error mes-
sages can be redirected to a file by using the standard out-
put redirection notation, e.g. > _s_o_m_e_f_i_l_e.
After completion of compilation, the compiler will exit
to command level. You will notice that several temporary
files created during compilation will have been deleted, and
all that will be left on the disk (apart from the original
source file HELLO.C) will be an executable file. The name of
this executable file will be HELLO.EXE for MS-DOS, HELLO.PRG
for the Atari ST, HELLO.COM for CP/M-80 and HELLO.CMD for
CP/M-86. For cross compilers it will be called HELLO.HEX or
HELLO.BIN depending on the default output format for the
particular compiler. To execute this program, simply type
HELLO
and you should be rewarded with the message "Hello, world!"
on your screen. If you are using a cross compiler you will
need to put the program into EPROM or download to the target
system to execute it. Cross compilers do not produce pro-
grams executable on the host system.
There are other options that may be used with the C
command, but you will not need to use them unless you wish
to do so. If you are new to the C language it will be advis-
able to enter and compile a few simple programs (e.g. drawn
from one of the C reference texts mentioned above) before
exploring other capabilities of the HI-TECH C compiler.
There is one exception to the above; if you compile a
program which uses floating point arithmetic (i.e. real
numbers) you MUST specify to the compiler that the floating
point library should be searched. This is done with a -LF
option at the END of the command line, e.g.
C -V FLOAT.C -LF
HI-TECH C USER'S MANUAL Page 5
3. Compiler Structure
The compiler is made up of several passes; each pass is
implemented as a separate program. Note that it is not
necessary for the user to invoke each pass individually, as
the C command runs each pass automatically. Note that the
machine dependent passes are named differently for each pro-
cessor, for example those with 86 in their name are for the
8086 and those with 68K in their name are for the 68000.
The passes are:
CPP The pre-processor - handles macros and conditional com-
pilation
P1 The syntax and semantic analysis pass. This writes
intermediate code for the code generator to read.
CGEN, CG86 etc.
The code generator - produces assembler code.
OPTIM, OPT86 etc.
The code improver - may optionally be omitted, reducing
compilation time at a cost of larger, slower code pro-
duced.
ZAS, AS86 etc.
The assembler - in fact a general purpose macro assem-
bler.
LINK
The link editor - links object files with libraries.
OBJTOHEX
This utility converts the output of LINK into the
appropriate executable file format (e.g. .EXE or .PRG
or .HEX).
The passes are invoked in the order given. Each pass
reads a file and writes a file for its successor to read.
Each intermediate file has a particular format; CPP produces
C code without the macro definitions and with uses of macros
expanded; P1 writes a file containing a program in an inter-
mediate code; CGEN translates this to assembly code; AS pro-
duces object code, a binary format containing code bytes
along with relocation and symbol information. LINK accepts
object files and libraries of object files and writes
another object file; this may be in absolute form or it may
preserve relocation information and be input to another LINK
command.
There are also other utility programs:
LIBR
Creates and maintains libraries of object modules
Page 6 HI-TECH C USER'S MANUAL
CREF
Produces cross-reference listings of C or assembler
programs.
HI-TECH C USER'S MANUAL Page 7
4. Operating Details
HI-TECH C was designed for ease of use; a single com-
mand will compile, assemble and link a C program. The syntax
of the C command is as follows:
C [ options ] files [ libraries ]
The options are zero or more options, each consisting
of a dash ('-'), a single key letter, and possibly an argu-
ment following the key letter with no intervening space. The
files are one or more C source files, assembler source
files, or object files. Libraries may be zero or more
library names, or the abbreviated form -lname which will be
expanded to the library name libname.lib.
The C command will, as determined by the specified
options, compile any C source files given, assemble them
into object code unless requested otherwise, assemble any
assembler source files specified, then link the results of
the assemblies with any object or library files specified.
If the C command is invoked without arguments, then it
will prompt for a command line to be entered. This command
line may be extended by typing a backslash ('\') on the end
of the line. Another line will then be requested. If the
standard input of the command is from a file (e.g. by typing
C < afile) then the command lines will be read from that
file. Within the file more than one line may be given if
each line but the last ends with a backslash. Note that this
mechanism does not work in MS-DOS batch file, i.e. the com-
mand file for the C command must be a separate file. MS-DOS
has no mechanism for providing long command lines or stan-
dard input from inside a batch file.
The options recognized by the C command are as follows:
-S Leave the results of compilation of any C files as
assembler output. C source code will be interspersed as
comments in the assembler code.
-C Leave the results of all compiles and assemblies as
object files; do not invoke the linker. This allows the
linker to be invoked separately, or via the C command
at a later stage.
-CR Produce a cross reference listing. -CR on its own will
leave the raw cross-reference information in a tem-
porary file, allowing the user to run CREF explicitly,
while supplying a file name, e.g. -CR_F_R_E_D._C_R_F will
cause CREF to be invoked to process the raw information
into the specified file, in this case _F_R_E_D._C_R_F.
-CPM
For the Z80 cross compiler only, produce CP/M-80 COM
files. Unless the -CPM option is given, the Z80 cross
Page 8 HI-TECH C USER'S MANUAL
compiler uses the ROM runtime startoff module and pro-
duces hex or binary images. If the -CPM option is
given, CP/M-80 runtime startoff code is linked used and
a CP/M-80 COM file is produced.
-O Invoke the optimizer on all compiled code; also
requests the assembler to perform jump optimization.
-O_O_U_T_F_I_L_E
Specify a name for the executable file to be created.
By default the name for the executable file is derived
from the name of the first source or object file speci-
fied to the compiler. This option allows the default to
be overridden. If no dot ('.') appears in the given
file name, an extension appropriate for the particular
operating system will be added, e.g. -O_F_R_E_D will gen-
erate a file _F_R_E_D._E_X_E on MS-DOS or _F_R_E_D._C_M_D on CP/M-86.
For cross compilers this also provides a means for
specifying the output format, e.g. specifying an output
file _P_R_O_G._B_I_N will make the compiler generate a binary
file, while specifying _P_R_O_G._H_E_X will make it generate a
hexadecimal file.
-V Verbose: each step of the compilation will be echoed as
it is executed.
-I Specify an additional filename prefix to use in search-
ing for #include files. For CP/M the default prefix is
0:A: (user number 0, disk drive A). For MS-DOS the
default prefix is A:\HITECH\. Under Unix and Xenix the
default prefix is /usr/hitech/include/. Note that on
MS-DOS a trailing backslash must be appended to any
directory name given as an argument to -I; e.g.
-I\FRED\ not -I\FRED. Under Unix a trailing slash
should be added.
-D Define a symbol to the preprocessor: e.g. -DCPM will
define the symbol CPM as though via #define CPM 1.
-U Undefine a pre-defined symbol. The complement of -D.
-F Request the linker to produce a symbol file, for use
with the debugger.
-R For the Z80 CP/M compiler only this option will link in
code to perform command line I/O redirection and wild
card expansion in file names. See the description of
_getargs() in appendix 5 for details of the syntax of
the redirections.
-X Strip local symbols from any files compiled, assembled
or linked. Only global symbols will remain.
-M Request the linker to produce a link map.
-A This option, for the Z80 only, will cause the compiler
to produce an executable program that will, on execu-
tion, self-relocate itself to the top of the TPA
HI-TECH C USER'S MANUAL Page 9
(Transient Program Area). This allows the writing of
programs which may execute other programs under them-
selves. Note that a program compiled in such a manner
will not automatically reset the bdos address at loca-
tion 6 in order to protect itself. This must be done by
the program itself.
For cross compilers this provides a way of specifying
to the linker the addresses that the compiled program
is to be linked at. The format of the option is
-A_R_O_M_A_D_R,_R_A_M_A_D_R,_R_A_M_S_I_Z_E. _R_O_M_A_D_R is the address of the
ROM in the system, and is where the executable code and
initialized data will be placed. _R_A_M_A_D_R is the start
address of RAM, and is where the bss psect will be
placed, i.e. uninitialized data. _R_A_M_S_I_Z_E is the size
of RAM available to the program, and is used to set the
top of the stack.
For the 6801/6301/68HC11 compiler, the -A option takes
a fourth value which is the address of a four byte
direct page area called ctemp which the compiled code
uses as a scratch pad. If the ctemp address is omitted
from the -A option, it defaults to address 0. Normally
this will be acceptable, however some 6801 variants
(like the 6303) have memory mapped I/O ports at address
0 and start their direct page RAM at address $80.
For the large memory model of the 8051 compiler, the -A
option takes the form -A_R_O_M_A_D_R,_I_N_T_R_A_M,_E_X_T_R_A_M,_E_X_T_S_I_Z_E.
_R_O_M_A_D_R is the address of ROM in the system. _I_N_T_R_A_M is
the start address of internal RAM, and is where the
rbss psect will be placed. The 8051 internal stack
will start after the end of the rbss psect. _E_X_T_R_A_M is
the start address of external RAM, and is where the bss
psect will be placed. _E_X_T_S_I_Z_E is the size of external
RAM available to the program, and is used to set the
top of the external stack.
-B For compilers which support more than one "memory
model", this option is used to select which memory
model code is to be generated for. The format of this
option is -Bx where x is one or more letters specifying
which memory model to use. For the 8086, this option
is used to select which one of five memory models
(Tiny, Small, Medium, Compact or Large) is to be used.
For the 8051 compiler this this option is used to
select which one of the three memory models (Small,
Medium or Large) is to be used. For the 8051 compiler
only, this option can also be used to select static
allocation of _a_u_t_o variables by appending an A to the
end of the -B option. For example, -Bsa would select
small model with static allocation of all variables,
while -Bm would select medium model with _a_u_t_o variables
dynamically allocated on the stack.
Page 10 HI-TECH C USER'S MANUAL
-E By default the 8086 compiler will initialize the exe-
cutable file header to request a 64K data segment at
run time. This may be overridden by the -E option. It
takes an argument (usually in hexadecimal representa-
tion) which is the number of BYTES (not paragraphs) to
be allocated to the program at run time. For example
-E0ffff0h will request a megabyte. Since this much will
not be available, the operating system will allocate as
much as it can.
-W This options sets the warning level, i.e. it determines
how picky the compiler is about legal but dubious type
conversions etc. -W0 will allow all warning messages
(default), -W1 will suppress the message "Func()
declared implicit int". -W3 is recommended for compil-
ing code originally written with other, less strict,
compilers. -W9 will suppress all warning messages.
-H This option generates a symbol file for use with
debuggers. The format of the symbol file is described
elsewhere. The default name of the symbol file is
_l._s_y_m. An alternate name may be specfied with the
option, e.g. -H_s_y_m_f_i_l_e._a_b_c.
-G Like -H, -G also generates a symbol file, but one that
contains line and file number information for a source
level debugger. Like -H a file name may be specified.
When used in conjunction with -O, only partial optimi-
zation will be performed to avoid confusing the
debugger.
-P Execution profiling is available on native compilers
running under DOS, CP/M-86 and on the Atari ST. This
option generates code to turn on execution profiling
when the program is run. A -H option should also be
specified to provide a symbol table for the profiler
EPROF.
-Z For version 5.xx compilers only, the -Z option is used
to select global optimization of the code generated.
For the 8086 and 6801/6301/68HC11 compilers the only
valid -Z option is -Zg. For the 8051 compiler, the
valid -Z options are -Zg which invokes global optimiza-
tion, -Zs which optimizes for space, and -Zf which
optimizes for speed. The s and f options may be used
with the g option, thus the options -Zgf and -Zgs are
valid. Speed and space optimization are mutually
exclusive, i.e. the s and f options cannot be used
together.
-1 For the 8086 compiler only, request the generation of
code which takes advantage of the extra instructions of
the 80186 processor. A program compiled with -1 will
not execute on an 8086 or 8088 processor. For the 68000
compiler, generate instructions for the 68010 proces-
sor.
HI-TECH C USER'S MANUAL Page 11
-2 Like -1 but for the 80286 and 68020.
-11 For the 6801/HC11 compiler, this option will request
generation of instructions specific to the 68HC11 pro-
cessor.
-6301
For the 6801/HC11 compiler, this option will request
generation of instructions specific to the 6301/6303
processors.
Some examples of the use of the C command are:
c prog.c
c -mlink.map prog.c x.obj -lx
c -S prog.c
c -O -C -CRprog.crf prog.c prog2.c
c -v -Oxfile.exe afile.obj anfile.c -lf
Upper and lower case has been used in the above exam-
ples for emphasis: the compiler does not distinguish between
cases, although arguments specifying names, e.g. -D, are
inherently case sensitive.
Taking the above examples in order; the first compiles
and links the C source file prog.c with the standard C
library. The second example will compile the file prog.c and
link it with the object file x.obj and the library libx.lib;
a link map will be written to the file link.map.
The third example compiles the file prog.c, leaving the
assembler output in a file prog.as. It does not assemble
this file or invoke the linker. The next example compiles
both prog.c and prog2.c, invoking the optimizer on both
files, but does not perform any linking. A cross reference
listing will be left in the file _p_r_o_g._c_r_f.
The last example pertains to the 8086 version of the
compiler, It runs the compiler with the verbose option, and
will cause anfile.c to be compiled without optimization to
object code, yielding anfile.obj, then afile.obj and
anfile.obj will be linked together with the floating point
library (from the -LF option) and the standard library to
yield the executable program xfile.exe (assuming this is
performed on an MS-DOS system). One would expect this pro-
gram to use floating point, if it did not then the -LF
option would have been required.
If more than one C or assembler source file is given to
the C command, the name of each file will be printed on the
console as it is processed. If any fatal errors occur dur-
ing the compilation or assembly of source files, further
source files will be processed, but the linker will not be
Page 12 HI-TECH C USER'S MANUAL
invoked.
Other commands which may be issued by the user, rather
than automatically by the C command, are:
ZAS The Z80 assembler.
AS86
The 8086 assembler.
LINK
The linker
LIBR
The library maintainer
OBJTOHEX
Object to hex converter
CREF
Cross reference generator.
In general, these commands accept the same type of com-
mand line as the C command, i.e. zero or more options (indi-
cated by a leading '-') followed by one or more file argu-
ments. If the linker or the librarian is invoked with no
arguments, it wll prompt for a command line. This allows
command lines of more than 128 bytes to be entered. Input
may also be taken from a file by using the redirection capa-
blities (see _getargs() in the library function listing).
See the discussion above of the C command. These commands
are described in further detail in their respective manuals.
HI-TECH C USER'S MANUAL Page 13
5. Specific Features
The HI-TECH C compiler has a number of features, which
while largely compatible with other C compilers, contribute
to more reliable programming methods.
5.1. ANSI C Standard Compatibility
At the time of writing the Draft ANSI Standard for the
C Language was at an advanced stage, though not yet an offi-
cial standard. Accordingly it is not possible to claim com-
pliance with that standard, however HI-TECH C includes the
majority of the new and altered features in the draft ANSI
standard. Thus it is in the sense that most people under-
stand it "ANSI compatible".
5.2. Type Checking
Previous C compilers have adopted a lax approach to
type checking. This is typified by the Unix C compiler,
which allows almost arbritary mixing of types in expres-
sions. The HI-TECH C compiler performs much more strict type
checking, although in most cases only warning messages are
issued, allowing compilation to proceed if the user knows
that the errors are harmless. This would occur, for example,
when an integer value was assigned to a pointer variable.
The generated code would almost certainly be what the user
intended, however if in fact it represented an error in the
source code, the user is prompted to check and correct it
where necessary.
5.3. Member Names
In early C compilers member names in different struc-
tures were required to be distinct except under certain cir-
cumstances. HI-TECH C, like most recent implementations of
C, allows member names in different structures and unions to
overlap. A member name is recognized only in the context of
an expression whose type is that of the structure in which
the member is defined. In practice this means that a member
name will be recognized only to the right of a '.' or '->'
operator, where the expression to the left of the operator
is of type structure or pointer to structure the same as
that in which the member name was declared. This not only
allows structure names to be re-used without conflict in
more than one structure, it permits strict checking of the
usage of members; a common error with other C compilers is
the use of a member name with a structure pointer of the
wrong type, or worse with a variable which is a pointer to a
simple type.
There is however an escape from this, where the user
desires to use as a structure pointer something which is not
declared as such. This is via the use of a typecast. For
example, suppose it is desired to access a memory-mapped i/o
device, consisting of several registers. The declarations
Page 14 HI-TECH C USER'S MANUAL
and use may look something like the code fragment in fig. 2.
struct io_dev
{
short io_status; /* status */
char io_rxdata; /* rx data */
char io_txdata; /* tx data */
};