X-88 Posted October 10, 2012 Posted October 10, 2012 unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;type TForm1 = class(TForm) E1: TEdit; E2: TEdit; Button1: TButton; RG: TRadioGroup; Label1: TLabel; Label2: TLabel; E3: TEdit; Label3: TLabel; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);var Inp1 , Inp2, Res : Integer;begin Inp1 := StrToInt(E1.Text); Inp2 := StrToInt(E2.Text);case RG.ItemIndex of 0 : beginasm Mov Eax, Inp1 // Tmp Inp 1 ??? Add Eax, Inp2 // Eax = Inp 1 + Inp 2??? Mov Res, Eax // Result = Eax???end; E3.Text := IntToStr(Res);end; 1 : beginasm Mov Eax, Inp1 // Tmp Inp 1 ??? Sub Eax, Inp2 // Eax = Inp 1 - Inp 2??? Mov Res, Eax // Result = Eax???end; E3.Text := IntToStr(Res);end; 2 : beginasm Mov Eax, Inp1 // Tmp Inp 1 ??? Mul Eax, Inp2 // Eax = Inp 1 x Inp 2??? Mov Res, Eax // Result = Eax???end; E3.Text := IntToStr(Res);end; 3 : beginasm Mov Eax, Inp1 // Tmp Inp 1 ??? Div Eax, Inp2 // Eax = Inp 1 : Inp 2???[color=#ff0000]//Is there something wrong with this section?[/color] Mov Res, Eax // Result = Eax???end; E3.Text := IntToStr(Res);end;{ 4 : beginasm Mov Eax, Inp1 // Tmp Inp 1 ??? Mod Eax, Inp2 // Eax = Inp 1 Mod Inp 2???[color=#ff0000] //Is there something wrong with this section?[/color] Mov Res, Eax // Result = Eax???end; E3.Text := IntToStr(Res);end; }end;end;end.but if I apply to the console mode is not an error, but the GUI is always the message "Integer Overflow" why?...
kao Posted October 10, 2012 Posted October 10, 2012 1) There is no "mod" instruction in x86 asm.. 2) Div and mul instructions will modify EDX register and Delphi doesn't save it automatically. Try adding push edx/pop edx (or better - pushad/popad).
kao Posted October 10, 2012 Posted October 10, 2012 Another idea - maybe for some reasons GUI version has enabled overflow checks. In that case try placing "{$Q-}" directive in the beginning of the unit.
X-88 Posted October 10, 2012 Author Posted October 10, 2012 (edited) but that makes me wonder, if I apply the Console does not appear the message????...... program ZN;{$APPTYPE CONSOLE}usesSysUtils;//{$R ZN.Res}varInp1, Inp2, Res : Integer;VK : Char;begin//WriteLN(' Path = ',CmdLine);WriteLN('~~~~~~~~~~~~~~~~~~~~');WriteLN('|[ZN - Calculator] |');WriteLN('~~~~~~~~~~~~~~~~~~~~');WriteLN(' 1 = Add [+]');WriteLN(' 2 = Sub [-]');WriteLN(' 3 = Mul [X]');WriteLN(' 4 = Div [:]');WriteLN(' 5 = Mod [?]');WriteLN(' Else Exit');WriteLN('~~~~~~~~~~~~~~~~~~~~');Write(' Please Select 1 : ');Read(VK);case VK of'1' :beginReadLN;Write(' Input 1 : ');Read(Inp1);Write(' Input 2 : ');Read(Inp2);asmMov Eax, Inp1 // Tmp Inp 1 ???Add Eax, Inp2 // Eax = Inp 1 + Inp 2???Mov Res, Eax // Result = Eax???end;WriteLN(' Result : ', Res);ReadLN;end;'2' :beginReadLN;Write(' Input 1 : ');Read(Inp1);Write(' Input 2 : ');Read(Inp2);asmMov Eax, Inp1 // Tmp Inp 1 ???Sub Eax, Inp2 // Eax = Inp 1 - Inp 2???Mov Res, Eax // Result = Eax???end;WriteLN(' Result : ', Res);ReadLN;end;'3' :beginReadLN;Write(' Input 1 : ');Read(Inp1);Write(' Input 2 : ');Read(Inp2);asmMov Eax, Inp1 // Tmp Inp 1 ???Mul Eax, Inp2 // Eax = Inp 1 x Inp 2???Mov Res, Eax // Result = Eax???end;WriteLN(' Result : ', Ord(Res));ReadLN;end;'4' :beginReadLN;Write(' Input 1 : ');Read(Inp1);Write(' Input 2 : ');Read(Inp2);asmMov Eax, Inp1 // Tmp Inp 1 ???Div Eax, Inp2 // Eax = Inp 1 : Inp 2???Mov Res, Eax // Result = Eax???end;WriteLN(' Result : ', Res);ReadLN;end;{'5' :beginReadLN;Write(' Input 1 : ');Read(Inp1);Write(' Input 2 : ');Read(Inp2);asmMov Eax, Inp1 // Tmp Inp 1 ???Mod Eax, Inp2 // Eax = Inp 1 + Inp 2???Mov Res, Eax // Result = Eax???end;WriteLN(' Result : ', Ord(Res));ReadLN;end;}elseExit;end;while true doSleep(1000);end. Another idea - maybe for some reasons GUI version has enabled overflow checks. In that case try placing "{$Q-}" directive in the beginning of the unit. What is not required termination {$ Q-} I had already tried to insert it {$ Q-}, but nonetheless Edited October 10, 2012 by X-88
Nacho_dj Posted October 10, 2012 Posted October 10, 2012 I have created a new console application and pasted your code. When running it, compiler complains about a missing ZN.Res file. If I remove this line:{$R ZN.Res}Then I'm getting all lines of your menu as a console mode asking "Please Select 1 :"...
X-88 Posted October 10, 2012 Author Posted October 10, 2012 (edited) it is a resource section that refers to the source of the icon to be included into the resource, I forgot to remove it it was a choice between 1 .. 5 of operator: 1 = Add [+] 2 = Sub [-] 3 = Mul [X] 4 = Div [:] 5 = Mod [?] else Terminate Edited October 10, 2012 by X-88
kao Posted October 10, 2012 Posted October 10, 2012 Both console and UI versions work fine on my PC, no overflow messages (Delphi 2007, most likely all default settings).
X-88 Posted October 11, 2012 Author Posted October 11, 2012 (edited) Both console and UI versions work fine on my PC, no overflow messages (Delphi 2007, most likely all default settings). I made it and run it with D7 & D 2010 on OS: win 7 but both are showing the same thing. and I've turned it into EDX is the message will not appear again, but it did not yield the division also performed Edited October 11, 2012 by X-88
Nacho_dj Posted October 11, 2012 Posted October 11, 2012 Try to debug it in ollydbg to find where it reaches that error.Probably it is due to any of CPU registers being modified in the inside of your asm routines and not being restored when exiting.You'd rather use PUSHAD as the first asm instruction and POPAD as the last asm instruction for every set of asm instructions as kao suggested.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now