Solved

Fill an array with assembler

Posted on 2002-06-10
11
476 Views
Last Modified: 2010-04-04
I would like to fill an dynamic array of
arbitrary size with a value:

procedure FillWithValue(arr:pointer;n:longint;fval:double);assembler;
begin
  asm
    // ???    
  end;
end;


type tArr = array[0..0] of double;
     pArr = ^tArr;

procedure Process;
var i:longint;
    arr:pArr;
    count:longint;
begin
  count:=3000; // arbirary value
  getmem(arr,count*sizeof(double));
  for i:=0 to count-1
  do begin
    arr^[i]:=2*i;  // arbitrary start value
  end;
  i:=200;
  ShowMessage(floattostr(arr^[i]));
  // now fill with the whole array with 0.0
  FillWithValue(arr,count,0.0);
  freemem(arr);
end;

Can someone help me with the assembler code
to put fval into all elements of arr?

Thanks for help,

Gamba

0
Comment
Question by:Gamba
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7068836
why don't you simply use FillChar
I'm sure it's highly optimized :)

you could also write some code with FillChar and check the asm procedure it creates :)
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 7068858
I think it's becoz he's trying to fill the array with double and not char :)
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7068872
umm yes ...
well filling the array with all 0.0 is the same as filling it with 0 chars :)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:DragonSlayer
ID: 7068893
Umm... true... I didn't see that part of filling with 0.0... lol

So Gamba, just use

FillChar(YourArray, 0, SizeOf(YourArray));
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 7068895
PS: If it works, please give the points to Lee and not to me :)
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7069050
hehe tnx :)

anyway it should be like :
FillChar(YourArray, Length(YourArray) * SizeOf(Double), 0)
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 7069116
Oops... here I go again... must be getting old ;)
0
 
LVL 9

Expert Comment

by:ITugay
ID: 7069162

hi gamba,
why do you need assembler code? It is difficult to write assembler code for short operations that works faster then Delphi build. Delphi does excellent optimization and in some cases writing fastest code inside one procedure in assembler will slow down whole process. It is due to Delphi can't optimize procedure that calls procedure writen in assembler.

Just use this way to work with array of doubles:

var
  A: Array of Double;
  I: Integer;
begin

  SetLength(A, 12);
  for I := Low(A) to High(A) do
    A[I] := I * 2;
end;

-------
Igor.
0
 

Author Comment

by:Gamba
ID: 7069264
Thanks for all comments!

You're right in that FillChar would be an alternative
for filling with zeros. But this was meant only as an
example for accessing the array via assembler.
What I want to do in the end is processing a huge
array of floating point values with assembler, thereby
accessing the FPU direct to do mathematical operations
on the array.
So I need the assembler code for getting started at all.

Gamba

0
 
LVL 1

Expert Comment

by:pnh73
ID: 9010497
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ and No Refund

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Paul (pnh73)
EE Cleanup Volunteer
0
 
LVL 6

Accepted Solution

by:
Mindphaser earned 0 total points
ID: 9101905
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month6 days, 18 hours left to enroll

622 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