Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Need Help Asm in Delphi

Featured Replies

Posted

unit Unit1;
interface
uses
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 : begin
asm
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 : begin
asm
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 : begin
asm
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 : begin
asm
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 : begin
asm
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?...

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).

  • Author

Ok thx, Kao!

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.

  • Author

but that makes me wonder, if I apply the Console does not appear the message????...... :(


program ZN;{$APPTYPE CONSOLE}uses
SysUtils;//{$R ZN.Res}var
Inp1, 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' :
begin
ReadLN;
Write(' Input 1 : ');
Read(Inp1);
Write(' Input 2 : ');
Read(Inp2);
asm
Mov 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' :
begin
ReadLN;
Write(' Input 1 : ');
Read(Inp1);
Write(' Input 2 : ');
Read(Inp2);
asm
Mov 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' :
begin
ReadLN;
Write(' Input 1 : ');
Read(Inp1);
Write(' Input 2 : ');
Read(Inp2);
asm
Mov 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' :
begin
ReadLN;
Write(' Input 1 : ');
Read(Inp1);
Write(' Input 2 : ');
Read(Inp2);
asm
Mov 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' :
begin
ReadLN;
Write(' Input 1 : ');
Read(Inp1);
Write(' Input 2 : ');
Read(Inp2);
asm
Mov 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;
}
else
Exit;
end;
while true do
Sleep(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 by X-88

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 :"...

  • Author

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 by X-88

Both console and UI versions work fine on my PC, no overflow messages (Delphi 2007, most likely all default settings).

  • Author

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.

post-65081-0-96235300-1349922382_thumb.p

and I've turned it into EDX is the message will not appear again, but it did not yield the division also performed

Edited by X-88

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.

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.