You can see code to check for an 8087 using NDP instructions (FSTSW returns the status word, for example)--including in my own code.
Yep. Here is the code I use in my Xi 8088 BIOS to detect FPU presence (and later on set the equipment flags):
fninit ; initialize coprocessor
mov cx,3
.wait:
loop .wait ; wait for coprocessor to initialize
; (can't use fwait, since it could
; be no coprocessor at all)
mov cx,word [test_word] ; save test_word to CX
mov word [test_word],0000h ; clear space for control word
fnstcw word [test_word] ; store control word
cmp word [test_word],03FFh ; 8087 sets control word to 03FFh
jne .no_fpu ; after finit
.fpu:
Note that this code basically relies on the assumption that FPU commands will do NOP if FPU is not installed (not hang or crash the system
).