Q43810: C: PUSH CS Caused by Far Call Translation

Article: Q43810
Product(s): See article
Version(s): 5.00 5.10 | 5.10
Operating System(s): MS-DOS | OS/2
Keyword(s): ENDUSER | | mspl13_c
Last Modified: 22-MAY-1989

Question:

When I look at an assembly listing generated by the Microsoft C
Version 5.10 Optimizing Compiler, I notice that the compiler produced
PUSH CS instructions. Should the compiler be generating PUSH CS
instructions?

Response:

One of the optimizations made by the Microsoft C 5.10 compiler is Far
Call Translation. Far Call Translation optimization results in
slightly faster code and smaller executable files.

The compiler normally generates far calls and corresponding far
returns for large and medium-memory-model programs. Far Call
Translation is performed if optimizations are enabled and a call is
being made from one function to another in the same source file. The
usual CALL FAR LABEL is replaced with the following instruction
sequence:

        PUSH CS
        CALL NEAR LABEL

The called function is in the same code segment because it is located
in the same source file, so a near call is possible in this case. The
PUSH CS instruction allows the far return from the called function to
retrieve CS from the stack and return to the correct location.