The following example defines the BITBLT assembly function, which is a FAR and PUBLIC type function. When BITBLT is invoked, the SI and DI registers are automatically saved, and they are automatically restored upon exit. The BP register is always saved.
The BITBLT function is passed seven doubleword pointers on the stack. Space will be allocated on the stack for eight frame variables (one structure, five bytes, and two words).
The cBegin macro defines the start of the actual code. The pExt parameter is loaded, and some values are loaded into registers. The AX and BX registers are saved on execution of the subsequent cCall macro.
A C function, There, is called by the cCall macro. Four arguments are passed to There: pDestBitmap, the 32-bit pointer in the DS:SI registers, the value in the AX register, and the value in the BX register. The cCall macro places the arguments on the stack in the correct order.
When There returns, the arguments placed on the stack are automatically removed and the AX and BX registers are restored.
When the cEnd macro is reached, the frame variables are removed, any autosave registers are restored, and a return of the correct type (near or far) is performed.
The following example shows how the BITBLT function is defined:
cProc
BITBLT,<FAR,PUBLIC>,<si,di> parmD pDestBitmap ; --> to dest bitmap descriptor parmD pDestOrg ; --> to dest origin (a point) parmD pSrcBitmap ; --> to source bitmap descriptor parmD pSrcOrg ; --> to source origin parmD pExt ; --> to rectangle extent parmD pRop ; --> to rasterop descriptor parmD pBrush ; --> to a physical brush localV nOps,4 ; # of each operand used localB phaseH ; horizontal phase (rotate count) localB PatRow ; current row for patterns [0..7] localB direction ; increment/decrement flag localW startMask ; mask for first dest byte localW lastMask ; mask for last dest byte localB firstFetch ; number of first fetches needed localB stepDirection ; direction of move (left, right) cBegin lds si,pExt mov ax,extentX[si] mov bx,extentY[si] RegPtr dest,ds,si Save <ax,bx> cCall THERE,<pDestBitmap,dest,ax,bx> mov extentX[si],cx mov extentY[si],dx . . . cEnd