0

So there was a problem with a program of mine, which led me to write the following code snippet and test it:

        .MODEL   TINY
        .386p
        Kod     SEGMENT USE32
        ORG      100h
        ASSUME   CS:Kod,DS:Kod,SS:Kod
Def:    JMP      Start
        ;        space for data declaration
Start:  MOV      eax,00000010h
        MOV      ecx,0000000Ah
        DIV      ecx
        MOV      eax, 00004C00h
        INT      21h
        Kod      ENDS
        END      Def

Suppose I name a file with the above code as test.asm. The compilation under DOSBox Portable using tasm test.asm and tlink /t test.obj is successful. And then comes the weird problem. Running the COM executable in debug mode using td test.com (Turbo Debugger) proceeds succesfully. But then, I ask the Turbo Debugger to reload the program (after pressing F8 one more time) and when reaching the DIV instruction, the program jumps to a different set of instructions which eventualy leads to "Divide by zero". The beginning of this set of instructions is shown below: [view the screenshot]. What is the reason of this quirky phenomenon, and how to make the DIV instruction do its work as in the first debugging cycle? (running test.com directly results in DOS freezing). Is this maybe a DOSBox emulator issue?

  • `DIV ECX` divides the register pair `EDX:EAX` by `ECX`. In this code, `EDX` does not seem to be initialized. What happens once the missing initialization of `EDX` is added to the code? – njuffa May 31 '22 at 18:10
  • @njuffa Thank you very much. This is at the same time the reason why after reloading the program in Turbo Debugger the behaviour is different (non-zero EDX register value) – Regulama May 31 '22 at 18:14
  • Adding `MOV edx,00000000h` before the DIV instruction solved the problem – Regulama May 31 '22 at 18:16
  • 1
    If you want to zero `edx`, `xor edx, edx` is never worse than `mov edx, 0`. `cdq` can save a byte from the code size if you know `eax` is positive. – xiver77 May 31 '22 at 18:18

0 Answers0