Exported far functions in DLLs also require a prolog. The prolog code in a DLL must generate a reference to the DGROUP data segment. The SS register can-not be used because execution occurs on the calling function's stack. Exported far functions cannot use this method because fixups to DGROUP are illegal for a multiple instance application.
The prolog and epilog for exported far functions in a DLL has the following form:
mov ax, DGROUP ; get DGROUP value
push bp ; set up stack frame (optional)
mov bp, sp
push ds ; save calling function's DS
mov ds, ax ; move DGROUP to DS
...
pop ds ; restore registers
pop bp
retf
Following is an alternative form of the prolog for exported far functions in a DLL:
mov ax, DGROUP ; get DGROUP value
push bp ; set up stack frame (optional)
mov bp, sp
push ds ; save calling function's DS
mov ds, ax ; move DGROUP to DS
sub sp, const ; allocate local storage (optional)
...
mov ds, [bp-2] ; restore registers
leave
Windows inserts the current data segment address as the second operand (DGROUP) of the initial mov instruction.