Improve company productivity with a Business Account.Sign Up

x
?
Solved

Built-in assembler problem

Posted on 2002-06-28
6
Medium Priority
?
255 Views
Last Modified: 2010-04-04
I'm writing a little graphical effect, and to speed things up a bit, I tried to replace some code by assembler. The problem is: how do you call another function using assembler. I already tried using "call @myFunction" but it says "@myFunction undeclared" or something. I only know the basics of assembler, so keep that in mind :)
0
Comment
Question by:herr_apfelschnitt
6 Comments
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 7115790
A simple trick:
Debug your application and have a look at the CPU window.
0
 
LVL 7

Accepted Solution

by:
Cynna earned 800 total points
ID: 7115812
herr_apfelschnitt,

> ... I already tried using "call @myFunction"...
Did you try "call myFunction"   ?:)

If your function has arguments, they are stored
in EAX, EDX and ECX in that order.
Function result is stored in EAX.

Simple demonstration:
-------------------------------


function bla(a,b: Integer): Integer;
begin
  Result:=a+b;
end;

function Assem: Integer;
asm
  mov EAX, 8;
  mov EDX, 3;
  call bla;
  mov Result, EAX;
end;

//---------------------------------------

procedure TForm1.Button11Click(Sender: TObject);
begin
  Label1.Caption:=IntToStr(Assem);
end;


0
 
LVL 1

Author Comment

by:herr_apfelschnitt
ID: 7115928
wow! This is the first time something is easier than I thought it would be :)

You wouldn't mind me asking an additional question (or two) would you :) (since 200 pts is quite a lot, and I haven't got too many of them left)
(if you don't know the answer to these, don't worry, you get the points anyway)

1. How do you access the coprocessor's stack (ST(x))?
2. If the function has more than three arguments, are the remaining arguments simply put on the stack?

Thanks


0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:herr_apfelschnitt
ID: 7115931
And to Robert:

I 've never seen a CPU window in Delphi. Could this be because i'm still running Delphi 3?
0
 
LVL 2

Expert Comment

by:bugroger
ID: 7116069
Hi,

how to Enable the CPU window in delphi 3?
-----------------------------------------
Simply go in the registry at:
HKCU\Software\Borland\Delphii\3.0\Debugging
then create a string key named "EnableCPU" and set the value to "1".
It's all.

it's from
http://www.delphipages.com/tips/thread.cfm?ID=10

0
 
LVL 7

Expert Comment

by:Cynna
ID: 7116249
herr_apfelschnitt,

> 1. How do you access the coprocessor's stack (ST(x))?


Example (uses st(0) for floating point operations)
----------------------------------------------------------------

function FloatSubtract(a,b: Double): Double;
asm
 // Load first argument(memory) on top of stack, in st(0):
    fld a;
 // Subtract b(memory) from st(0) and place the result back in st(0):
    fsub b;
 // Pop st(0) to Result(memory)
    fstp Result;
end;

procedure TForm1.Button11Click(Sender: TObject);
begin
  Label1.Caption:=FloatToStr(FloatSubtract(4.5, 2.2));
end;


You can find further info in "Art Of Assembly Language":

* http://webster.cs.ucr.edu/Page_AoAWin/0_AoAHLA.html

The best thing would be to download the whole book.
Then go to  Chapter 11, "Real Arithmetic" (page 595).
Read up, you'll find quite detailed info on what you
seem to be interested in...





> 2. If the function has more than three arguments, are the remaining arguments simply put on the stack?

Generally, yes.
Here is what Delphi Help ("Program control" -> "Parameter passing") has to say about this:

"Under the register convention, up to three parameters are passed in CPU registers, and the rest (if any) are passed on the stack. The parameters are passed in order of declaration (as with the pascal convention), and the first three parameters that qualify are passed in the EAX, EDX, and ECX registers, in that order. Real and method-pointer types do not qualify as register parameters, but all other parameters do. If more than three parameters qualify as register parameters, the first three are passed in EAX, EDX, and ECX, and the remaining parameters are pushed onto the stack in order of declaration. For example, given the declaration

procedure Test(A: Integer; var B: Char; C: Double; const D: string; E: Pointer);

a call to Test passes A in EAX as a 32-bit integer, B in EDX as a pointer to a Char, and D in ECX as a pointer to a long-string memory block; C and E are pushed onto the stack as two double-words and a 32-bit pointer, in that order."




But, you can directly access your arguments and not worry
about this:

Example:
----------------

function MassSum(a,b,c,d,e: Integer): Integer;
asm
  mov EAX, a;
  mov EDX, b;
  add EAX, EDX;
  mov EDX, c;
  add EAX, EDX;
  mov EDX, d;
  add EAX, EDX;
  mov EDX, e;
  add EAX, EDX;
  mov Result, EAX;
end;

procedure TForm1.Button11Click(Sender: TObject);
begin
  Label1.Caption:=IntToStr(MassSum(1,2,3,4,5));
end;

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
If you are looking for an automated tool which can generate reports for Outlook emails and other items from PST file, then you can go for Kernel PST Reporter tool. The reports which are created by this tool are helpful to analyze and understand PST …
Watch the software video of Kernel Import PST to Office 365 tools which can easily import PST and OST files to Office 365 for bulk mailboxes. The process of migration is simple and user can map source and destination mailboxes and easily import data…

595 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question