More Delphi Answers
Question Library
Ask a question about Delphi
Volunteer
Experts of the Month
Expert Login
Awards
About Us
Tell friends
Link to Us
Disclaimer
|
| |
|
|
| |
| | | |
About Brian Sill
Expertise Turbo Pascal and Delphi developer since 1986. Proficient in web design incuding XHTML, CSS, and Javascript. Fluent in C, C++, Visual Basic (especially VBA), and Modula-2.
Experience Turbo Pascal and Delphi developer since 1986. Strengths - Windows VCL, Custom Controls, Runtime UI design, Windows API, Database, SQL, Threading, Btrieve, Pervasive.SQL, Advantage Database, ADO to MDB, ADO to MS SQL, MDI Apps, MS Office Integration, barcode generation, Document imaging application development, TIFF file structure, some IFF file experience.
Education/Credentials Over 20 years designing and implementing DOS, DPMI, and Windows apps in TP, BP, and Delphi.
| | |
| |
You are here: Experts > Computing/Technology > Delphi Programming > Delphi > Max min from array
Delphi - Max min from array
Expert: Brian Sill - 11/2/2009
Question Plz help me write a program in Assembly Language to find the maximum number and the minimum number from an array of ten positive numbers. Store the minimum number in AX and maximum number in DX.
[Hint: Use the conditional jumps]
Answer Lily,
Delphi creates very fast native code, so creating this in assembly seems like overkill. If you were searching for the min and max in an array of 1,000, or 10,000 then perhaps you may be able to gain some speed from Assembly. Also, the Assembly code can be gleaned from similar Delphi code. For example:
procedure MinMax(Input: Array of LongInt; var Min, Max: LongInt);
var
I: LongInt;
begin
Min:=Input[Low(Input)];
Max:=Min;
for I:=Low(Input)+1 to High(Input) do
begin
if (Input[I]<Min) then Min:=Input[I];
if (Input[I]>Max) then Max:=Input[I];
end;
end;
Now if you create a program that uses this procedure, and set a breakpoint on the first line above, and then run it, and check the CPU window when it stops, you'll see the Assembly code that Delphi created, and then if you see somewhere that the speed could be improved, you can copy that code, and re-implement it in assembly.
Sincerely,
Brian
PS. You'll have to change the types to WORD in order to get the compiler to create numbers that will fit in the registers you've listed above.
Add to this Answer Ask a Question
|
|