emu8086 is bad, and presumably assembles your ambiguous DIV [07100h]
into DIV byte [07100h]
instead of the DIV word [07100h]
you were expecting, instead of giving you an error (ambiguous operand size) like most assemblers would.
Thus, you fault with #DE
because 07200h / 2
overflows AL
.
First of all, using div
for 2 (or a power of 2) is horrible compared to test al, 1
/ jnz odd
. That's non-destructive, and doesn't modify DX, so you need far fewer registers. And div
is much slower than test
, as well as being much worse code-size.
But second, storing the divisor to memory and then using a memory source operand is also weird. Use mov si, 13
outside the loop, then div si
inside the loop to test for divisibility by 13 or something. That will definitely make the operand-size 16-bit, so you get dx:ax / si
into AX and DX, instead of ah:al / 1_byte
into AL and AH.
Also, you don't need some extra static storage location, or the extra code-size to encode an address into the store and the div
, or the extra cost of loading it from cache every time div
runs. (Trivial on a modern CPU compared the cost of div
, but actual 8086 didn't have cache, and had to load from memory.)