Solved

What is this assembly language doing?

Posted on 2009-03-30
11
390 Views
Last Modified: 2012-05-06
Hi.

This seems to take a lot of time. Is the assembly below from the creation of Buf?
void XPControl::process_xp_buffer_event()

{

  uint32 CurrentTimeOut = 10;  // Milliseconds willing to wait for new message in GetXPMessage

  int32 retLen;   // Value Returned from GetXPMessage

  TF_TRANS *pTFTrans;

  uint8 Buf[0x4000];
 

}

lea      edi, DWORD PTR [ebp-16744]

mov      ecx, 0x105ah  

mov      eax, -0x33333334

rep stosd

Open in new window

0
Comment
Question by:nanderEire
  • 7
  • 4
11 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 24019396
>> lea      edi, DWORD PTR [ebp-16744]
>> mov      ecx, 0x105ah  
>> mov      eax, -0x33333334
>> rep stosd

It stores the value -0x33333334 at memory location [ebp-16744]
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24019403
>> Is the assembly below from the creation of Buf?

So, no - it does something else.
0
 

Author Comment

by:nanderEire
ID: 24019459
More specifically what does the command rep stosd do here?
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24019477
>> what does the command rep stosd do here?

What I said : it stores the (32bit) value from register eax (-0x33333334) into the memory location specified by the register edi ([ebp-16744]).
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24019545
Oops, I missed the "rep" part (I must not be fully awake yet lol).

Here's my revised reply :

>> what does the command rep stosd do here?

It stores the (32bit) value from register eax (-0x33333334) into the memory location specified by the register edi ([ebp-16744]), and repeats that ecx times (0x105ah = 4186) for consecutive memory locations.

Basically, it initializes a block of 16744 = 4186*4 bytes starting at address [ebp-16744] to the value -0x33333334 (repeated 4186 times)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 53

Expert Comment

by:Infinity08
ID: 24019569
Note that -0x33333334 is the same as 0xCCCCCCCC, so this might be some kind of default memory initialization of the stack.
Is this in debug mode ?
0
 

Author Comment

by:nanderEire
ID: 24023570
Yes it is in Debug. So is it likely to be the initialization of the Buf[0x4000]?
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24023757
>> So is it likely to be the initialization of the Buf[0x4000]?

It looks like it's the initialization of that buffer, and the other local data in the function.

If you compile/run the code in release mode, it should be faster, as that initialization won't happen.

Note also, that a statically allocated buffer of size 0x4000 is quite big ... Can't you allocate it dynamically ?
0
 

Author Comment

by:nanderEire
ID: 24026349
I'm trying to optimise this program and pointed out that the buffer was huge and is being created repeatedly but they indicated that it wasn't a performance hit in release mode. Is that true?
0
 
LVL 53

Accepted Solution

by:
Infinity08 earned 250 total points
ID: 24026712
>> but they indicated that it wasn't a performance hit in release mode. Is that true?

Yes. See my previous comment (http:#24023757) where I already pointed that out.

It's only in debug mode that the buffer is initialized to the pattern 0xCCCCCCCC (for reasons of detecting buffer overflows and similar errors). Due to the size of the buffer, that takes a long time.
In release mode, this kind of initialization is not done, and the allocation of the buffer is very fast (a simple increment of the stack pointer).
0
 

Author Closing Comment

by:nanderEire
ID: 31564338
Great help. Thank you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Statment to match two tables in c# 6 78
Grammars for C C++ and java 1 114
Why isn't object file created? 6 43
outlook office 365 8 85
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now