Code:
__inton proc
sti ;enables interrupts
ret ;return to caller
__inton endp
__intoff proc
pushf ;push flags onto stack
pop ax ;pop ax off stack
cli ;disable interrupts
ret ;return to caller
__intoff endp
__intrst proc flag:word
mov ax,flag ;place flag(passed value) in ax
push ax ;push ax(flag) onto stack
popf ;pop flags off of stack
ret ;return to caller
__intrst endp
__nop proc
ret ;return to caller
__nop endp
Some of this code does not look right but I will have to check my Intel manuals concerning the pushing and popping of the flags and when you need to do so. I cannot imagine why you would ever need to push any explicit return register onto the stack and I do not make it a practice to do so, but it can be done. AX is used for math operations (non-floating point) since it is the fastest register and is used for returning values back to C.
The __intrst function looks suspect. However it looks as though it is pushing previously stored flags back onto the stack. Again w/o looking at my manuals I'm sort of lost on the process.
The NOP function is useless.
Here is what I use the push and pop for most of the time.
Code:
__proc FastCopy32
ARGS source:DWORD,dest:DWORD,length:DWORD
push ds ;save ds so we don't crash later
mov eax,source
mov ds,ax
xor esi,esi
mov eax,dest
mov es,eax
xor edi,edi
mov ecx,length
rep movsd
pop ds ;restore ds
ret
__endp
This is 32-bit with TASM syntax. Push is used to save the ds register because programs - like the C compiler - use this register. So we save it on the stack, use it for our program, and then restore it when we are done with it so we don't crash the system.