|
 |
|
Dev Articles Community Forums
> Programming
> C/C++ Help
|
Assembly to c++ converter
Discuss Assembly to c++ converter in the C/C++ Help forum on Dev Articles. Assembly to c++ converter C/C++ Help forum discussing building and maintaining applications in C/C++. Find out why these languages are the foundation on which other languages are built.
|
|
 |
|
|
|
|

Dev Articles Community Forums Sponsor:
|
|
|

September 23rd, 2007, 12:19 PM
|
|
Registered User
|
|
Join Date: Sep 2007
Posts: 1
Time spent in forums: 6 m 37 sec
Reputation Power: 0
|
|
|
Assembly to c++ converter
Hi i need a assembly to c++ converter, but i only found a c++ to assembly converter. Can anyone reverse this c++ to assembly script so it will be c++ output here is the script
#define N10
main()
{
int i;
int array[N]={2.4,7,8,14,5,13 ,23};
int accumulate =0;
for(i=N-1;i>=0;i--
{
accumulate += array[i];
}
cout<<"the result is"<<accumulate<<endl;
}
really need your help.
|

September 23rd, 2007, 12:32 PM
|
 |
Command Line Warrior
|
|
Join Date: Sep 2005
Posts: 1,021

Time spent in forums: 2 Weeks 7 h 49 m 32 sec
Reputation Power: 9
|
|
AFAIK an assembly to c++ converter does not exist. There is a lot lost in translation when compiling.
Any c++ compiler can give you assembly code though (or at least the ones I've used). I generated some assembly for your code, I just removed the line with 'cout', because it means including iostream and the listing would become _a lot_ bigger.
asm Code:
Original
- asm Code |
|
|
|
; Listing generated by Microsoft (R) Optimizing Compiler Version 14.00.50727.42 TITLE C:\temp\bla.cpp .686P .XMM include listing.inc .model flat INCLUDELIB LIBCMT INCLUDELIB OLDNAMES PUBLIC _main ; Function compile flags: /Odtp _TEXT SEGMENT _array$ = -48 ; size = 40 _i$ = -8 ; size = 4 _accumulate$ = -4 ; size = 4 _main PROC ; File c:\temp\bla.cpp ; Line 5 push ebp mov ebp, esp sub esp, 48 ; 00000030H ; Line 7 mov DWORD PTR _array$[ebp], 2 mov DWORD PTR _array$[ebp+4], 7 mov DWORD PTR _array$[ebp+8], 8 mov DWORD PTR _array$[ebp+12], 14 ; 0000000eH mov DWORD PTR _array$[ebp+16], 5 mov DWORD PTR _array$[ebp+20], 13 ; 0000000dH mov DWORD PTR _array$[ebp+24], 23 ; 00000017H xor eax, eax mov DWORD PTR _array$[ebp+28], eax mov DWORD PTR _array$[ebp+32], eax mov DWORD PTR _array$[ebp+36], eax ; Line 8 mov DWORD PTR _accumulate$[ebp], 0 ; Line 9 mov DWORD PTR _i$[ebp], 9 jmp SHORT $LN3@main $LN2@main: mov ecx, DWORD PTR _i$[ebp] sub ecx, 1 mov DWORD PTR _i$[ebp], ecx $LN3@main: cmp DWORD PTR _i$[ebp], 0 jl SHORT $LN1@main ; Line 11 mov edx, DWORD PTR _i$[ebp] mov eax, DWORD PTR _accumulate$[ebp] add eax, DWORD PTR _array$[ebp+edx*4] mov DWORD PTR _accumulate$[ebp], eax ; Line 12 jmp SHORT $LN2@main $LN1@main: ; Line 15 xor eax, eax ; Line 16 mov esp, ebp pop ebp ret 0 _main ENDP _TEXT ENDS END
I am not sure what you can do with this though.. The only reason I see for looking at assembly code is to learn about assembly and compiling or about how your compiler optimizes things.. Anyway, good luck
__________________
There is no such thing as C/C++, you either program C or C++
|

October 20th, 2008, 06:38 AM
|
|
Registered User
|
|
Join Date: Oct 2008
Posts: 3
Time spent in forums: 10 m 9 sec
Reputation Power: 0
|
|
Hi, I need a C++ to assembly converter. You seem to have one. Please can you send it to me or give a link from where I can download?
Thanks in advance
--
M I Hafiz
Quote: | Originally Posted by Icon AFAIK an assembly to c++ converter does not exist. There is a lot lost in translation when compiling.
Any c++ compiler can give you assembly code though (or at least the ones I've used). I generated some assembly for your code, I just removed the line with 'cout', because it means including iostream and the listing would become _a lot_ bigger.
asm Code:
Original
- asm Code |
|
|
|
; Listing generated by Microsoft (R) Optimizing Compiler Version 14.00.50727.42 TITLE C:\temp\bla.cpp .686P .XMM include listing.inc .model flat INCLUDELIB LIBCMT INCLUDELIB OLDNAMES PUBLIC _main ; Function compile flags: /Odtp _TEXT SEGMENT _array$ = -48 ; size = 40 _i$ = -8 ; size = 4 _accumulate$ = -4 ; size = 4 _main PROC ; File c:\temp\bla.cpp ; Line 5 push ebp mov ebp, esp sub esp, 48 ; 00000030H ; Line 7 mov DWORD PTR _array$[ebp], 2 mov DWORD PTR _array$[ebp+4], 7 mov DWORD PTR _array$[ebp+8], 8 mov DWORD PTR _array$[ebp+12], 14 ; 0000000eH mov DWORD PTR _array$[ebp+16], 5 mov DWORD PTR _array$[ebp+20], 13 ; 0000000dH mov DWORD PTR _array$[ebp+24], 23 ; 00000017H xor eax, eax mov DWORD PTR _array$[ebp+28], eax mov DWORD PTR _array$[ebp+32], eax mov DWORD PTR _array$[ebp+36], eax ; Line 8 mov DWORD PTR _accumulate$[ebp], 0 ; Line 9 mov DWORD PTR _i$[ebp], 9 jmp SHORT $LN3@main $LN2@main: mov ecx, DWORD PTR _i$[ebp] sub ecx, 1 mov DWORD PTR _i$[ebp], ecx $LN3@main: cmp DWORD PTR _i$[ebp], 0 jl SHORT $LN1@main ; Line 11 mov edx, DWORD PTR _i$[ebp] mov eax, DWORD PTR _accumulate$[ebp] add eax, DWORD PTR _array$[ebp+edx*4] mov DWORD PTR _accumulate$[ebp], eax ; Line 12 jmp SHORT $LN2@main $LN1@main: ; Line 15 xor eax, eax ; Line 16 mov esp, ebp pop ebp ret 0 _main ENDP _TEXT ENDS END
I am not sure what you can do with this though.. The only reason I see for looking at assembly code is to learn about assembly and compiling or about how your compiler optimizes things.. Anyway, good luck |
|

October 20th, 2008, 07:58 AM
|
 |
Command Line Warrior
|
|
Join Date: Sep 2005
Posts: 1,021

Time spent in forums: 2 Weeks 7 h 49 m 32 sec
Reputation Power: 9
|
|
|
Well I guess every compiler is a C++ to assembly converter.. In visual studio 2005 there is an option under configuration properties|C/C++|output files. For gcc and bcc32 you can specify the -S option on the command line to make the compiler output assembly.
|

October 20th, 2008, 08:45 AM
|
|
Registered User
|
|
Join Date: Oct 2008
Posts: 3
Time spent in forums: 10 m 9 sec
Reputation Power: 0
|
|
Thanks a lot. I did not know about that feature.
Now the problem is that I want an assembly code generated for micro-controller 80C51 and PIC16F84
Do you know if there is any compiler that helps convert into chip specific assembly code? Can it be done with visual C++ 2008 express edition?
Thanks again.
--
M I Hafiz
Quote: | Originally Posted by Icon Well I guess every compiler is a C++ to assembly converter.. In visual studio 2005 there is an option under configuration properties|C/C++|output files. For gcc and bcc32 you can specify the -S option on the command line to make the compiler output assembly. |
|

October 20th, 2008, 08:57 AM
|
 |
Command Line Warrior
|
|
Join Date: Sep 2005
Posts: 1,021

Time spent in forums: 2 Weeks 7 h 49 m 32 sec
Reputation Power: 9
|
|
|
I guess you need a specific compiler to compile to those micro-controller. I doubt visual studio express can do that. But I am really not into embedded stuff so I might very well be wrong.
|

October 20th, 2008, 01:15 PM
|
|
Registered User
|
|
Join Date: Oct 2008
Posts: 3
Time spent in forums: 10 m 9 sec
Reputation Power: 0
|
|
Thanks for your prompt reply. You were very helpful. Thank you again.
Quote: | Originally Posted by Icon I guess you need a specific compiler to compile to those micro-controller. I doubt visual studio express can do that. But I am really not into embedded stuff so I might very well be wrong. |
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|