09.06.2013 Views

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

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

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

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

The following example is from a middle model compilation:<br />

int near foo();<br />

This does a near call in an otherwise far (calling) program.<br />

Since there is no type checking between items in separate source files, the near and far<br />

keywords should be used with great care.<br />

The pascal and fortran Keywords<br />

The pascal and fortran keywords may be considered synonymous as they both invoke the<br />

PL/M protocol. The Pascal keyword can be used to either call routines compiled with<br />

the PL/M protocol or compile subroutines with the PL/M protocol.<br />

The assembly language programm ing differences between C and Pascal are as follows:<br />

• Any external Pascal identifiers are mapped to uppercase; underscores (_) are used.<br />

This is true for both global variables and function/procedure names.<br />

• In C, the programmer must readjust the stack pointer after making a call to a<br />

routine. In Pascal, this is not necessary since all calls to routines readjust the<br />

stack before they return a value.<br />

• Conventions for returning floating-point numbers and structured items differ<br />

between C and Pascal. In C, the return value is stored in a static buffer (AX if<br />

the point er is 16 bits, AX-DX if the pointer is far or huge) and the address of this<br />

buffer is passed to the calling routine. In Pascal, space is reserved on the stack<br />

for this return value and a near pointer is passed to the called routine as a hidden<br />

parameter.<br />

Finally, the protocol for passing parameters differs between C and Pascal. In C the<br />

number of parameters is not fixed; the C compiler pushes the parameters from right to<br />

left. In Pascal, since the number of parameters is fixed, the PL/M protocol dictates<br />

that the parameters are pushed from left to right.<br />

The pascal keyword is used in the following form:<br />

int pascal addcol();<br />

where addcol is a function that is to be compiled using the PL/M protocol.<br />

Creating Programs from Assembly Language Source Files<br />

Use the cc command to create executable programs from a combination of C source<br />

files (files ending in .c) and 80<strong>86</strong>/<strong>2<strong>86</strong></strong> assembly language source files (files ending in .s).<br />

Refer to Chapter 7, "as: Assembler."<br />

2-17

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

Saved successfully!

Ooh no, something went wrong!