I compile the code via DosBOX, later the following error pops up in the debugger: "Divide by zero" (Exception: division by zero)

Here is the actual code:

.model small .stack .data a dw 2 b dw 2 c dw 4 d dw 4 .code main: mov ax, @data mov ds, ax mov ax, d div b mov ax, 4c00h int 21h end main 
  • Once you have a debugger make sure that ds really points to your data segment. although I see no reason that this was not the case. - Mike
  • What happens if you try mov bx, b div bx ? - jfs
  • @jfs, still writes divide by zero, and by the way it happens when I read the code a second time, that is, the first time the whole code is read successfully, it writes the terminated exit code 0, then program already terminated, Reload?, and after that on the line with the div writes divide by zero - Anton Belsky

1 answer 1

There is a suspicion that the result depends on the contents of the register DX. During the first pass, the debugger resets it, but it is not known what value goes there after Reload. And Divide by zero can occur if the private does not fit in the AX. In any case, explicit resetting of DX before division (remember that with a double-byte divider, the pair AX: DX is divisible, and the programmer must explicitly initialize the whole pair) eliminates this error. And why such a diagnosis - FIG knows, have not held all these tasmas / masses in their hands for a long time :) In any case, something like "Arithmetic overflow" in TASM is generally a translation error, and not execution time.