0

I've learnt that compiler produces object code as an output or an assembly language program.

So can I see assembly language program produced as an output of high level language program?

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
  • Yes, you can, but the specific way to do that depends on the language /platform/IDE/OS/compiler you're using. You haven't tagged a specific language, would you give more details? – Stanislav Nedelchev Mar 29 '15 at 07:40
  • Any C or C++ compiler has an option to produce an assembly listing. Any decent debugger lets you look at the machine code while you debug. Do keep in mind that this is a humbling experience, modern C compilers are rather good at producing fast code. In a way that doesn't always look very intuitive, you'd never do something like unrolling a loop by hand when you write your own assembly. – Hans Passant Mar 29 '15 at 09:52
  • Here's a specific example: http://stackoverflow.com/q/28706850/120163 – Ira Baxter Mar 29 '15 at 09:53

3 Answers3

1

Since you didn't state which language you're using, I'll assume it's a native one (i.e. a language that translates into assembly, like C not bytecode, like java).
In that case, you can use objdump -D to produce the assembly output:

objdump -D [yourfile]

Ishay Peled
  • 2,783
  • 1
  • 23
  • 37
0

I wrote a tutorial on this, http://www.staerk.de/thorsten/Assembler_Tutorial#translate_C_to_assembler has a C program

#include <stdio.h>

int main()
{
  int i=0x23;
  printf("hello world");
}

And translates it under Linux with the command

gcc -o hello.asm -S assembler_file.S

To assembler-code that looks like:

movl    $.LC0, %edi                      
movl    $0, %eax                         
call    printf 

Note that this way is gcc-specific. The other way to obtain the assembler code is of course to build the executable program and then disassemble it with objdump -d. This will work with any compiler.

Thorsten Staerk
  • 1,114
  • 9
  • 21
-3

Datei: Q4_ASEM.BAS Stand: 05.06.88 Microsoft Quick Basic 4.0

DEFINT A-Z

DECLARE FUNCTION Addieren (A AS INTEGER, B AS INTEGER)
' Assembler-Funktion --^

PRINT " QuickBASIC ruft Assembler"
INPUT " A = "; A
INPUT " B = "; B
Ergebnis = Addieren(A, B)
PRINT "Ergebnis ="; Ergebnis
'------------------------------
' Objektdatei mit BC erstellen
' C>bc a:q4_asem

Datei: BASIC.ASM Stand: 05.06.88 Microsoft Macro Assembler 5.0

.MODEL medium
     .CODE 
     PUBLIC Addieren

Addieren PROC

     push    bp
     mov     bp,sp
     mov     bx,[bp+8]
     mov     ax,[bx]
     mov     bx,[bp+6]
     mov     cx,[bx]
     shl     ax,1
     shl     ax,1
     add     ax,cx
     pop     bp
     ret     4

Addieren ENDP
     END
;---------------------------------------
; C>masm basic
; C>link
; Object Modules [.OBJ]: q4_asem+basic
;---------------------------------------