x:=StrToInt(Edit1.Caption); y:=StrToInt(Edit2.Caption); z:=StrToInt(Edit3.Caption); {$asmmode intel} asm xor edx,edx mov eax,y mov ecx,z div ecx mov Test,eax mov eax,x mov ecx,Test div ecx mov Test,eax end; ShowMessage(IntToStr(Test)); 

There is such a code, Stop the program on "div ecx". How do I understand the problem in "mov Test, eax" How to fix the error?

  • Variables x, y, z, Test Integer - BigTows
  • Are y or z not 0 equal by chance? - Albert Fomin
  • @BigTows In addition to the lack of checks for division by zero, you seem to have forgotten to reset edx before the second division operation. I advise you first to write code on pascal, and then see how it will be transformed into an assembler of Delphi itself (View - Debug Windows - CPU Windows - Disassembly). - zed Nov.

2 answers 2

  1. In Delphi there is no $ASMMODE directive, it is in Lazarus. Accordingly, your code, which you give as an example, is simply not compiled.
  2. The name of the variable Test selected unsuccessfully, because it matches the assembler command. It is better to rename, but this is not the cause of the error.
  3. I have your code with some input parameters working fine, and with some of the message falls out: integer divide by zero at XXXX just on the penultimate instruction of the assembler insert div ecx . Under the debugger you can see that ecx really 0 . Test data for which an error occurs: x := 1; y := 2; z := 3 x := 1; y := 2; z := 3 x := 1; y := 2; z := 3 . To eliminate the error of division by zero, you need to rewrite your algorithm. And with the mov command there are no problems.

    You need to change the name of the variable Test , because test is a built-in assembler command .