Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc Intel XENIX 286 Programmers Guide (86) - Tenox.tc

09.06.2013 Views

XENIX Programming cc: C Compiler The following example is from a middle model compilation: int near foo(); This does a near call in an otherwise far (calling) program. Since there is no type checking between items in separate source files, the near and far keywords should be used with great care. The pascal and fortran Keywords The pascal and fortran keywords may be considered synonymous as they both invoke the PL/M protocol. The Pascal keyword can be used to either call routines compiled with the PL/M protocol or compile subroutines with the PL/M protocol. The assembly language programm ing differences between C and Pascal are as follows: • Any external Pascal identifiers are mapped to uppercase; underscores (_) are used. This is true for both global variables and function/procedure names. • In C, the programmer must readjust the stack pointer after making a call to a routine. In Pascal, this is not necessary since all calls to routines readjust the stack before they return a value. • Conventions for returning floating-point numbers and structured items differ between C and Pascal. In C, the return value is stored in a static buffer (AX if the point er is 16 bits, AX-DX if the pointer is far or huge) and the address of this buffer is passed to the calling routine. In Pascal, space is reserved on the stack for this return value and a near pointer is passed to the called routine as a hidden parameter. Finally, the protocol for passing parameters differs between C and Pascal. In C the number of parameters is not fixed; the C compiler pushes the parameters from right to left. In Pascal, since the number of parameters is fixed, the PL/M protocol dictates that the parameters are pushed from left to right. The pascal keyword is used in the following form: int pascal addcol(); where addcol is a function that is to be compiled using the PL/M protocol. Creating Programs from Assembly Language Source Files Use the cc command to create executable programs from a combination of C source files (files ending in .c) and 8086/286 assembly language source files (files ending in .s). Refer to Chapter 7, "as: Assembler." 2-17

cc: C Compiler XENIX Programming When assembly language source files are given, the cc command invokes as to assemble the instructions and create an object file that can then be linked with object files created by the compiler. For example, cc main.c add.s compiles the C source file main.c, but assembles the assembly language source file add.s. The resulting object files, main.o and add.o, are linked to form a single program. When coding assembly language routines with C programs, be sure to refer to "Assembly Language Interface" in the XENIX 286 C Library Guide. Changing Word Order in Programs The C compiler automatically uses the standard 8086/286 word order for long type values. This order may cause problems when programs access data files generated by programs created by other C compilers. You can change the word order for a given program by using the -Mb configuration option. This option causes the compiler to generate all long values in reverse word order, making the program compatible with programs created by other XENIX compilers. Other portability issues must be considered when creating C programs intended for different computer systems. For an explanation of these issues, see Appendix A, "C Language Portability." Setting the Stack Size You can set the size of the program stack by using the -F option. This option has the form -F num where num is the size (in bytes) of the program stack. The program stack is used for storage of function parameters and automatic variables. If the option is not used, a default stack size {4,096 bytes) is set. You can determine the stack requirements of a given program by using the stackuse command, described in Appendix B. This command analyzes C source files and computes the minimum stack requirement for all functions in the program. The command displays a warning if recursive functions are encountered; stack use requirements for recursive functions must be determined by the programmer. Note that all programs linked by cc have fixed stacks. This means the stack size fixhdr cannot be increased during execution of the program. Therefore, a sufficient stack size must be given when compiling the program. 2-18

cc: C Compiler <strong>XENIX</strong> Programming<br />

When assembly language source files are given, the cc command invokes as to assemble<br />

the instructions and create an object file that can then be linked with object files<br />

created by the compiler. For example,<br />

cc main.c add.s<br />

compiles the C source file main.c, but assembles the assembly language source file<br />

add.s. The resulting object files, main.o and add.o, are linked to form a single program.<br />

When coding assembly language routines with C programs, be sure to refer to "Assembly<br />

Language Interface" in the <strong>XENIX</strong> <strong>2<strong>86</strong></strong> C Library <strong>Guide</strong>.<br />

Changing Word Order in Programs<br />

The C compiler automatically uses the standard 80<strong>86</strong>/<strong>2<strong>86</strong></strong> word order for long type<br />

values. This order may cause problems when programs access data files generated by<br />

programs created by other C compilers. You can change the word order for a given<br />

program by using the -Mb configuration option. This option causes the compiler to<br />

generate all long values in reverse word order, making the program compatible with<br />

programs created by other <strong>XENIX</strong> compilers.<br />

Other portability issues must be considered when creating C programs intended for<br />

different computer systems. For an explanation of these issues, see Appendix A, "C<br />

Language Portability."<br />

Setting the Stack Size<br />

You can set the size of the program stack by using the -F option. This option has the<br />

form<br />

-F num<br />

where num is the size (in bytes) of the program stack. The program stack is used for<br />

storage of function parameters and automatic variables. If the option is not used, a<br />

default stack size {4,096 bytes) is set.<br />

You can determine the stack requirements of a given program by using the stackuse<br />

command, described in Appendix B. This command analyzes C source files and<br />

computes the minimum stack requirement for all functions in the program. The<br />

command displays a warning if recursive functions are encountered; stack use<br />

requirements for recursive functions must be determined by the programmer.<br />

Note that all programs linked by cc have fixed stacks. This means the stack size fixhdr<br />

cannot be increased during execution of the program. Therefore, a sufficient stack size<br />

must be given when compiling the program.<br />

2-18

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!