Jump to content
  • Advertisement

Archived

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

Please help changin c++ code to asm syntax

This topic is 5398 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi im new to asm and as practice I wanted to write asm code wich call''s a function wich takes a string(type) as parameter. To learn how to do this I''ve made so that VS outputs an asm file whit c/c++ source in it. But im still unsure how to deal calls whit strings becose the allocator function and maybe others(well ya it''s a nested class structure all the way from basic_string) are needed before the string can be pushed.
// heres the simble code what im trying to turn in asm

void printstr(string str)
{
cout<<str<<endl;
}

int main()
{

string stri = "test string";
printstr(stri);

return 0;
}


// visual studio generated asm code starts here


; string stri = "test string";

lea	eax, DWORD PTR $T8697[ebp]
push	eax
push	OFFSET FLAT:??_C@_0M@MDMJ@test?5string?$AA@ ; `string''
lea	ecx, DWORD PTR _stri$[ebp]
call	??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBDABV?$allocator@D@1@@Z ; std::basic_string<char,std::char_traits<char>,std::allocator<char> >::basic_string<char,std::char_traits<char>,std::allocator<char> >
mov	DWORD PTR __$EHRec$[ebp+8], 0

; printstr(stri);

sub	esp, 16					; 00000010H
mov	ecx, esp
mov	DWORD PTR $T8698[ebp], esp
lea	edx, DWORD PTR _stri$[ebp]
push	edx
call	??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z ; std::basic_string<char,std::char_traits<char>,std::allocator<char> >::basic_string<char,std::char_traits<char>,std::allocator<char> >
mov	DWORD PTR -44+[ebp], eax
call	?printstr@@YAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z ; printstr
add	esp, 16	

// and ends here


// what I''ve done so far is is:

sub	esp, 16			; ok
mov	ecx, esp                ; ok
mov	DWORD PTR $T8698[ebp], esp  ; huh T ?
lea	edx, DWORD PTR stri     ; ok
push	edx                     ; ok
call	??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z ; std::basic_string<char,std::char_traits<char>,std::allocator<char> >::basic_string<char,std::char_traits<char>,std::allocator<char> >
mov	DWORD PTR -44+[ebp], eax ; 44 ?
call	printstr ; ok
add	esp, 16	 ; and done

As you can see I can''t figure whats the correct syntax for first call becose of 
that messy line full of symbols and other detail like that T... something to do 
whit templates I asume?

It would be great if some one could show how to code that c++ code to a asm!

Share this post


Link to post
Share on other sites
Advertisement
This ASM code is highly dirty.Find some program that deassembles an .EXE or type in the command like "-debug file.exe" and start debuggin''


"Tonight we strike,there is thunder in the sky,together we''ll fight,some of us will die,but they''ll always remember that we''ve made a stand and many will die by hand!" - ManOwaR

Share this post


Link to post
Share on other sites
Problem is in C++, it will be very, very... VERY hard to translate this simple c++ into ASM. Class''es arent something natural for ASM... IMHO it is a suecide
About suecide...
If i was you and i would be realy in need to have this small pice of code in assembly i would first write in C functions that do exacly what string class do but using only structures and other "tools" supported on clean C. Porting C to ASM is much simpler than C++, but simpler not simple anyway

"Woman be my slave !!!" - ManOwaR

Share this post


Link to post
Share on other sites
quote:
Original post by Estor
Problem is in C++, it will be very, very... VERY hard to translate this simple c++ into ASM. Class''es arent something natural for ASM... IMHO it is a suecide
About suecide...
If i was you and i would be realy in need to have this small pice of code in assembly i would first write in C functions that do exacly what string class do but using only structures and other "tools" supported on clean C. Porting C to ASM is much simpler than C++, but simpler not simple anyway

"Woman be my slave !!!" - ManOwaR


Hey Estor,nice going with the "Pleasure Slave"!Hail and Kill!

"Tonight we strike,there is thunder in the sky,together we''ll fight,some of us will die,but they''ll always remember that we''ve made a stand and many will die by hand!" - ManOwaR

Share this post


Link to post
Share on other sites
To Estor:
That is my first and last solution. :/

Well is there an alternative way to call function like call address in asm?

Or could I some way have pointer to the allocator function?
Then calling would be easy!

Share this post


Link to post
Share on other sites
Try getting a free compiler (GCC and MinGW come to mind) and use some of the compile options to compile to assembly which pretty much all of them should have (MinGW does so GCC definatly should msvc should but Im not sure.)

Share this post


Link to post
Share on other sites
quote:
Original post by Craazer
You say that get disassempler. Well I hapend to have one. But what im suposed to do whit, hack the exe?


Please look at the assembly listing in your disassembler.
The good dasms even show you automatically where your procedures start.

_Or_, compile with some good IDE (i recommend VS.net 2003) and request assembly listings at compiler settings. Usually, you get the symbolic info as well (var&func names) when using this method.

EDIT:
I think all compilers support assembly listings, not just the ones with IDE

EDIT 2: Yohumbus already offered this option, sorry!

[edited by - Nik02 on August 9, 2003 12:21:08 PM]

[edited by - Nik02 on August 9, 2003 12:23:35 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!