You can call a function two ways. In a far call, the function is called using both the segment and the offset of the function. This allows a program to call a routine outside a 64K segment. In a near call, both the calling statement and the function must be located in the same segment. Only the offset is used to access the function; the segment address is implicit. You can only use near calls to routines located in the same segment.
Because of the architecture of the processor, near function calls execute faster than far calls. The decision to declare functions as near or far is often made when selecting a memory model. As it is difficult to determine where the linker will place a given function in memory, it is impractical for the programmer to choose the way a function is called.
The /FARCALLTRANSLATION option enables far call optimization. When you use this option, any function calls within the same segment as the function being called are converted to near calls. This optimization has no effect if you have selected the tiny, small, or compact model, because all calls are already near calls.
The abbreviation for the /FARCALLTRANSLATION option is /F.
How /FARCALLTRANSLATION Affects Your Code
The linker can perform a form of post-optimization (an optimization that occurs after most of the actual code generation is complete) that translates far calls into near calls when possible. This optimization allows a given function to be called with both near and far calls in the same program. To perform this translation, the linker takes a section of object code such as
CALL FAR _func
where func is defined in the current segment, and replaces it with the following code:
PUSH CS
CALL NEAR _func
NOP
This substitution works because the linker has inserted PUSH CS to place a far return address on the stack.
Summary: Use /FARCALLTRANSLATION with /PACKCODE.
The /FARCALLTRANSLATION option is most effective when used in conjunction with the /PACKCODE option discussed in “Packing Code (/PACKCODE)” on this page. Using the /PACKCODE option causes far calls that were intersegment to become intrasegment calls. The /FARCALLTRANSLATION feature can then take advantage of the new grouping to translate all intrasegment far calls into near calls.