C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 23rd, 2007, 12:19 PM
PsY_ PsY_ is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2007
Posts: 1 PsY_ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #2  
Old September 23rd, 2007, 12:32 PM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 7 h 49 m 32 sec
Reputation Power: 11
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
  1. ; Listing generated by Microsoft (R) Optimizing Compiler Version 14.00.50727.42
  2.  
  3.     TITLE   C:\temp\bla.cpp
  4.     .686P
  5.     .XMM
  6.     include listing.inc
  7.     .model  flat
  8.  
  9. INCLUDELIB LIBCMT
  10. INCLUDELIB OLDNAMES
  11.  
  12. PUBLIC  _main
  13. ; Function compile flags: /Odtp
  14. _TEXT   SEGMENT
  15. _array$ = -48                  ; size = 40
  16. _i$ = -8                        ; size = 4
  17. _accumulate$ = -4               ; size = 4
  18. _main   PROC
  19. ; File c:\temp\bla.cpp
  20. ; Line 5
  21.     push    ebp
  22.     mov ebp, esp
  23.     sub esp, 48          ; 00000030H
  24. ; Line 7
  25.     mov DWORD PTR _array$[ebp], 2
  26.     mov DWORD PTR _array$[ebp+4], 7
  27.     mov DWORD PTR _array$[ebp+8], 8
  28.     mov DWORD PTR _array$[ebp+12], 14        ; 0000000eH
  29.     mov DWORD PTR _array$[ebp+16], 5
  30.     mov DWORD PTR _array$[ebp+20], 13        ; 0000000dH
  31.     mov DWORD PTR _array$[ebp+24], 23        ; 00000017H
  32.     xor eax, eax
  33.     mov DWORD PTR _array$[ebp+28], eax
  34.     mov DWORD PTR _array$[ebp+32], eax
  35.     mov DWORD PTR _array$[ebp+36], eax
  36. ; Line 8
  37.     mov DWORD PTR _accumulate$[ebp], 0
  38. ; Line 9
  39.     mov DWORD PTR _i$[ebp], 9
  40.     jmp SHORT $LN3@main
  41. $LN2@main:
  42.     mov ecx, DWORD PTR _i$[ebp]
  43.     sub ecx, 1
  44.     mov DWORD PTR _i$[ebp], ecx
  45. $LN3@main:
  46.     cmp DWORD PTR _i$[ebp], 0
  47.     jl  SHORT $LN1@main
  48. ; Line 11
  49.     mov edx, DWORD PTR _i$[ebp]
  50.     mov eax, DWORD PTR _accumulate$[ebp]
  51.     add eax, DWORD PTR _array$[ebp+edx*4]
  52.     mov DWORD PTR _accumulate$[ebp], eax
  53. ; Line 12
  54.     jmp SHORT $LN2@main
  55. $LN1@main:
  56. ; Line 15
  57.     xor eax, eax
  58. ; Line 16
  59.     mov esp, ebp
  60.     pop ebp
  61.     ret 0
  62. _main   ENDP
  63. _TEXT   ENDS
  64. 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++

Reply With Quote
  #3  
Old October 20th, 2008, 06:38 AM
mihafiz mihafiz is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2008
Posts: 3 mihafiz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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
  1. ; Listing generated by Microsoft (R) Optimizing Compiler Version 14.00.50727.42
  2.  
  3.     TITLE   C:\temp\bla.cpp
  4.     .686P
  5.     .XMM
  6.     include listing.inc
  7.     .model  flat
  8.  
  9. INCLUDELIB LIBCMT
  10. INCLUDELIB OLDNAMES
  11.  
  12. PUBLIC  _main
  13. ; Function compile flags: /Odtp
  14. _TEXT   SEGMENT
  15. _array$ = -48                  ; size = 40
  16. _i$ = -8                        ; size = 4
  17. _accumulate$ = -4               ; size = 4
  18. _main   PROC
  19. ; File c:\temp\bla.cpp
  20. ; Line 5
  21.     push    ebp
  22.     mov ebp, esp
  23.     sub esp, 48          ; 00000030H
  24. ; Line 7
  25.     mov DWORD PTR _array$[ebp], 2
  26.     mov DWORD PTR _array$[ebp+4], 7
  27.     mov DWORD PTR _array$[ebp+8], 8
  28.     mov DWORD PTR _array$[ebp+12], 14        ; 0000000eH
  29.     mov DWORD PTR _array$[ebp+16], 5
  30.     mov DWORD PTR _array$[ebp+20], 13        ; 0000000dH
  31.     mov DWORD PTR _array$[ebp+24], 23        ; 00000017H
  32.     xor eax, eax
  33.     mov DWORD PTR _array$[ebp+28], eax
  34.     mov DWORD PTR _array$[ebp+32], eax
  35.     mov DWORD PTR _array$[ebp+36], eax
  36. ; Line 8
  37.     mov DWORD PTR _accumulate$[ebp], 0
  38. ; Line 9
  39.     mov DWORD PTR _i$[ebp], 9
  40.     jmp SHORT $LN3@main
  41. $LN2@main:
  42.     mov ecx, DWORD PTR _i$[ebp]
  43.     sub ecx, 1
  44.     mov DWORD PTR _i$[ebp], ecx
  45. $LN3@main:
  46.     cmp DWORD PTR _i$[ebp], 0
  47.     jl  SHORT $LN1@main
  48. ; Line 11
  49.     mov edx, DWORD PTR _i$[ebp]
  50.     mov eax, DWORD PTR _accumulate$[ebp]
  51.     add eax, DWORD PTR _array$[ebp+edx*4]
  52.     mov DWORD PTR _accumulate$[ebp], eax
  53. ; Line 12
  54.     jmp SHORT $LN2@main
  55. $LN1@main:
  56. ; Line 15
  57.     xor eax, eax
  58. ; Line 16
  59.     mov esp, ebp
  60.     pop ebp
  61.     ret 0
  62. _main   ENDP
  63. _TEXT   ENDS
  64. 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

Reply With Quote
  #4  
Old October 20th, 2008, 07:58 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 7 h 49 m 32 sec
Reputation Power: 11
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.

Reply With Quote
  #5  
Old October 20th, 2008, 08:45 AM
mihafiz mihafiz is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2008
Posts: 3 mihafiz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #6  
Old October 20th, 2008, 08:57 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 7 h 49 m 32 sec
Reputation Power: 11
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.

Reply With Quote
  #7  
Old October 20th, 2008, 01:15 PM
mihafiz mihafiz is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2008
Posts: 3 mihafiz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Assembly to c++ converter


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap