Solved

BASM question

Posted on 2006-11-20
5
256 Views
Last Modified: 2010-04-05
Hopefully Rlibby wont want to rip my head off for this one, he explained it and well i still don't get it..

var
 s: String;
begin
 s:='hello world';
asm
  lea eax,s;
  call uniquestring;  //fine

  mov eax,s;
  call showmessage;  //fine
end;

//example works.

procedure UniqueString(var S: string);

Following a call to SetString, S is guaranteed to reference a unique string; that is, a string with a reference count of one. For normal string handling, there is no need to ever call UniqueString. Only in cases where an application casts a string to a PChar and then modifies the contents of the string must UniqueString be used.

procedure ShowMessage(const Msg: string);

Description

Call ShowMessage to display a simple message box with an OK button. The Msg parameter is the message string that appears in the message box. The name of the application's executable file appears as the caption of the message box.



So, unique string requires a POINTER to the data where as show message requires the data....


now here's

  lea eax,s;
  call uniquestring;  //fine

http://ymlitechat.com/leabasm.gif


  mov eax,s;
  call showmessage;  //fine

http://ymlitechat.com/movbasm.gif


Now this is where i'm confused, I look up the address of Lea Eax,s; I was expecting to see the String but instead i  don't see the String..

but now when i look up the address of Mov Eax,S; and i actually pin point it in memory, i actually find the data i'm looking for..

So if lea does not pass in the address, what exactly is it passing? look at the screenshots and you'll see my confusion..

is Lea Eax,Str;
the same as saying Eax:=@Str; ?

0
Comment
Question by:tobjectpascal
[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
  • 3
  • 2
5 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 50 total points
ID: 17984989
>> Now this is where i'm confused, I look up the address of Lea Eax,s; I was expecting to see the String but instead i  don't see
>> the String..

Of course, your seeing the address of the variable, not the contents. Keep in mind that a String variable contents are a pointer to the memory allocated for a string.

For example, given the following memory location and the follwing 16 bytes of memory starting at that location:

$00004000 [0001000000000000]

If variable X (integer, pointer, string, etc) is located at address $00004000, then
calling:

MOV EAX, X

will move the 4 byte content (in this case [0001]) into EAX, making EAX = 1. If we are talking about a string, then it would move the string pointer (which is the address where the string exists) into EAX.

But calling:

LEA EAX, X

will move the address of X into EAX, in this case $00004000. As to this question:

>> Is Lea Eax,Str;
>> the same as saying Eax:=@Str; ?

Yes, or better put, it would be like:

MOV EAX, @Str

But of course this won't compile, again the reason LEA is used instead of MOV for
var paramters.

---

Russell

0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17985022
Or another way to see it...

var  S:       String;
begin

  S:='Hello world';
  ShowMessage(Format('Contents of string S are at: %p', [Pointer(s)]));
  ShowMessage(Format('Address of string S is: %p', [Addr(s)]));

end;
0
 
LVL 4

Author Comment

by:tobjectpascal
ID: 17987346
You know them plastic dogs with a stick and then a weighted head which when you press on it, it starts nodding.....

I'm similar to one of them right now... I get the jist of it, and i certainly understand what your saying, thank you again :)
0
 
LVL 4

Author Comment

by:tobjectpascal
ID: 17987376
OMG!!!!!

something just clicked, i understand perfectly..

ah, you end up passing the pointer of a pointer or a pointer address of where the pointer is sitting....

0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17987478

Sounds like you have it now, as I just heard the "click"... ;-)

Russell




0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of 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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Suggested Courses
Course of the Month7 days, 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