Archived

This topic is now archived and is closed to further replies.

Ciner

disassembled a simple program

Recommended Posts

Ciner    122
Can someone please explain to me why this same code in asm is equal to around 12000 lines? Compiled in release mode in VC++ 6 and disassembled w32dsm. #include <iostream.h> main() { cout << "test\n"; return 0; }

Share this post


Link to post
Share on other sites
Valderman    513
There''s a lot of startup and shutdown code involved, as well as code from various statically linked libraries.


"For crying out loud, she has fishes coming out of her head on either side. How can you find this hot?!"

"If anyone sees a suspicious, camouflaged factory being carried across the desert, they should report it immediately."

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
When I try <iostream> I get:
error C2065: ''cout'' : undeclared identifier
error C2297: ''<<'' : illegal, right operand has type ''char [6]''

Share this post


Link to post
Share on other sites
Colin Jeanne    1114
quote:
Original post by Anonymous Poster
When I try I get:
error C2065: ''cout'' : undeclared identifier
error C2297: ''<<'' : illegal, right operand has type ''char [6]''


That is because the book/tutorial you are using is old and useless. Get something new.

Try reading tutorials from this site



Qui fut tout, et qui ne fut rien
Invader''s Realm

Share this post


Link to post
Share on other sites
Ademan    100
invader X..i actually think its the originaly problem..those were the exact problems i was getting when i tried to run my console programs as win 32 apps...so i think if he just made it a console application...he should be fine (now...thats assuming hes using visual studio..i have no clue how the otehr ones work)

Share this post


Link to post
Share on other sites
dwarfsoft    1229
Just wrote an equivalent program without all the includes, and it is still 16KB of compiled windows console code.

Using the techniques that were learned in those articles I got the compiled size down to 521 bytes. It isn''t exactly the same program, but has the same concept.

#include <stdio.h>

void mainCRTStartup(void)
{
char*p = "test\n\0";
while((*p) != 0)_fputchar(*(p++));
_fgetchar();
}

There are variously nasty coding habbits in that source, like losing the pointer to the start of the line (originally pointed to by "p")

Noted that the required Library to use for _fputchar and _fgetchar is MSVCRT.LIB. This must be linked with the program (after we have checked the "Ignore all default libraries").

For most people this excercise is completely useless, as we want proper coding techniques. But this post is just a point about how much unnecessary crap is actually included in compiled programs MSVC for recent versions of Windows. Our code is getting majorly bloated.

Share this post


Link to post
Share on other sites
dwarfsoft    1229
quote:
Original post by Ademan
invader X..i actually think its the originaly problem..those were the exact problems i was getting when i tried to run my console programs as win 32 apps...so i think if he just made it a console application...he should be fine (now...thats assuming hes using visual studio..i have no clue how the otehr ones work)

Actually, under MSVC console I get the same errors.

Share this post


Link to post
Share on other sites
MichaelBartman    122
To fix the thing about cout not being defined, do this


#include <iostream>

using namespace std;

int main()
{
cout << "test" << endl;
return 0;
}


or


#include <iostream>

int main()
{
std::cout << "test" << std::endl;
return 0;
}


Michael Bartman
CEO, Lead Programmer
Dark Omen Studios
http://www.darkomenstudios.com/

Share this post


Link to post
Share on other sites