This is quicker than the AMD or Intel manuals. See Exception 0Dh here:
http://support.microsoft.com/kb/117389
You can probably confirm or eliminate your code as the problem by
trying different EMS memory managers, e.g., MS-DOS EMM386, FreeDOS
EMM386. If they don't fail, your code is likely correct.
If they don't fail and the code is not correct (unknowable at this point),
it's almost correct. E.g., I found that many DPMI hosts would work with
some of my DPMI code, but one wouldn't. I was missing one step which
that DPMI host required.
I tend to use the print statement method of debugging. It usually
leads directly to the exact spot of failure in C for normal C. But,
when dealing with DOS, BIOS, XMS, EMS, DPMI, or VCPI etc, it could be
something else in your code causing code other than yours to fail.
In that case, your code should still fail if the port loop is commented
out. If it still fails, comment out or "#if 0" "#endif" out more and
more code until you only have only the code causing the failure. If
commenting out the port loop eliminates the failure, it's something to
do with the loop. It could be the code, or it could be through an
interrupt that is being triggered. You can also try adding a CLI and
STI instruction around the loop code. In C, these will sometimes be
available as "enable" or "disable" perhaps with underscores.
Rod Pemberton