Please register or login. There are 0 registered and 1099 anonymous users currently online. Current bandwidth usage: 326.30 kbit/s December 11 - 11:39pm EST 
Hardware Analysis
      
Forums Product Prices
  Contents 
 
 

  Latest Topics 
 

More >>
 

    
 
 

  You Are Here: 
 
/ Forums / Programming /
 

  Convert a Small High Level Program to Assembly Language? 
 
 Author 
 Date Written 
 Tools 
Damon Mac Jul 16, 2010, 01:10pm EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List Replies: 2 - Views: 2618
I want to know if there is a program which can convert a block of high level language code to x86 Assembly Program, im fine with any High level language like c++ , c, ruby, python etc thats not a problem.

I am experimenting with programs at assembly level via disassembler, and to write some complex logic , like multiple nested loops etc in assembly seems to be a pain really. so i thought if i can be helped by a converter of such kind.

I know Compilers convert the code into opcode form and create a exe, and the assembly can be viewed with a disassembler but with that option i have to deal with other code, it increases time considerably.

i would be very happy if someone can suggest such a application.


Want to enjoy fewer advertisements and more features? Click here to become a Hardware Analysis registered user.
Beavis Khan Jul 16, 2010, 01:36pm EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List  
>> Re: Convert a Small High Level Program to Assembly Language?
gcc -S ?

____
"For every complex problem, there is a solution that is simple, neat, and wrong."

- H.L. Mencken
Damon Mac Jul 23, 2010, 12:38am EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List  
>> Re: Convert a Small High Level Program to Assembly Language?
Thanks Beavis, i tried the Gcc compiler and after studying its manual i was able to convert high level code to asm file.

I wrote 3 nested loops for which it produced this output..

'**************
.file "main.c"
.def ___main; .scl 2; .type 32; .endef
.section .rdata,"dr"
LC0:
.ascii "Hello world!\0"
.text
.globl _main
.def _main; .scl 2; .type 32; .endef
_main:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl $48, %esp
call ___main
movl $LC0, (%esp)
call _puts
movl $0, 36(%esp)
jmp L2
L8:
movl $0, 40(%esp)
jmp L3
L7:
movl $0, 44(%esp)
jmp L4
L6:
cmpl $9, 36(%esp)
jne L5
movl $1801680211, 30(%esp)
movw $115, 34(%esp)
L5:
incl 44(%esp)
L4:
cmpl $9, 44(%esp)
jle L6
incl 40(%esp)
L3:
cmpl $9, 40(%esp)
jle L7
incl 36(%esp)
L2:
cmpl $9, 36(%esp)
jle L8
movl $0, %eax
leave
ret
.def _puts; .scl 2; .type 32; .endef
'**************

The problem is it is using a sort of general assembly which cannot be directly used with olly debugger which shows me the original assemblly where instructions are very specific, ie no comments, pointer addresses are absolute etc etc.

Is there any way to make the Gcc generate code like that ?

here is the same code from olly while debugging it

'*************************
PUSH EBP
MOV EBP, ESP
AND ESP, FFFFFFF0
SUB ESP, 20
CALL Asm_Test.00401790
MOV DWORD PTR SS:[ESP], Asm_Test.00403024 ; |ASCII "Hello world!"
CALL <JMP.&msvcrt.puts> ; \puts
MOV DWORD PTR SS:[ESP+14], 0
JMP SHORT Asm_Test.0040138B
/MOV DWORD PTR SS:[ESP+18], 0
|JMP SHORT Asm_Test.00401380
|/MOV DWORD PTR SS:[ESP+1C], 0
||JMP SHORT Asm_Test.00401375
||/CMP DWORD PTR SS:[ESP+14], 5 ; |
|||JNZ SHORT Asm_Test.00401371 ; |
|||CMP DWORD PTR SS:[ESP+18], 6 ; |
|||JNZ SHORT Asm_Test.00401371 ; |
|||CMP DWORD PTR SS:[ESP+1C], 7 ; |
|||JNZ SHORT Asm_Test.00401371 ; |
|||MOV DWORD PTR SS:[ESP], Asm_Test.00403031 ; |ASCII "Match Found 591"
|||CALL <JMP.&msvcrt.printf> ; \printf
|||INC DWORD PTR SS:[ESP+1C]
|| CMP DWORD PTR SS:[ESP+1C], 9
||\JLE SHORT Asm_Test.00401350
||INC DWORD PTR SS:[ESP+18]
| CMP DWORD PTR SS:[ESP+18], 9
|\JLE SHORT Asm_Test.00401346
|INC DWORD PTR SS:[ESP+14]
CMP DWORD PTR SS:[ESP+14], 9
\JLE SHORT Asm_Test.0040133C
MOV EAX, 0
LEAVE
RETN

'************************




Write a Reply >>


 

    
 
 

  Topic Tools 
 
RSS UpdatesRSS Updates
 

  Related Articles 
 
 

  Newsletter 
 
A weekly newsletter featuring an editorial and a roundup of the latest articles, news and other interesting topics.

Please enter your email address below and click Subscribe.