Machine Code?

I read that compilers convert the high level language source code into machine code written in 1s and 0s.

I want to know how a whats the machine code equivalent of a hello world program i have written in c++.

I am not a just starting to learn cpp now(because you might get the idea from the hello world reference.) I have reached the standard template library now. Still Studying...

Is there any way to have a look at the machine code? Can you give my any simple high level source code and its machine lang. equivalent.



Learn binary.
Is there any way to have a look at the machine code?
Your compiler probably has options to output a list file with the source code listing and possibly with assembly language interspersed. For your early reading, you may want to reduce your compiler's optimization settings.

Assuming your microprocessor is from the Intel family, the following link will direct you at enough reading to keep you reading for a long time: http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html
These are the manuals with details about the microprocessors that are directed at programmers.

The point of languages like C++ is so you can ignore these details.
Most compilers have a command line option to output the assembly code for what they generate. Assembly code is still an ASCII text file but the instructions correspond one-to-one with the machine code. With g++, the option is -S.

You will need to learn about the architecture of the CPU you're using. You can probably get some of this from wikipedia.
Thanks for the help. All responses were great.
dhayden helped me the most.

I got the human readable assembly of hello world by using the g++ -S main.cpp command.
The following program:
1
2
3
4
5
6
7
#include <iostream>

int main(void)
{
	std::cout << "Hello World\n" << std::endl;
	return 0;
}

generated an output listing of 1651 lines when the source, assembly, and machine code are all selected for output when using Microsoft Visual Studio C++ 2010.

I have cut the following listing from the output log file. It is concentrated on the lines of the main() function.
;	COMDAT _main
_TEXT	SEGMENT
_main	PROC						; COMDAT

; 4    : {

  00000	55		 push	 ebp
  00001	8b ec		 mov	 ebp, esp
  00003	81 ec c0 00 00
	00		 sub	 esp, 192		; 000000c0H
  00009	53		 push	 ebx
  0000a	56		 push	 esi
  0000b	57		 push	 edi
  0000c	8d bd 40 ff ff
	ff		 lea	 edi, DWORD PTR [ebp-192]
  00012	b9 30 00 00 00	 mov	 ecx, 48			; 00000030H
  00017	b8 cc cc cc cc	 mov	 eax, -858993460		; ccccccccH
  0001c	f3 ab		 rep stosd

; 5    : 	std::cout << "Hello World\n" << std::endl;

  0001e	8b f4		 mov	 esi, esp
  00020	a1 00 00 00 00	 mov	 eax, DWORD PTR __imp_?endl@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@1@AAV21@@Z
  00025	50		 push	 eax
  00026	68 00 00 00 00	 push	 OFFSET ??_C@_0N@BEEODGFF@Hello?5World?6?$AA@
  0002b	8b 0d 00 00 00
	00		 mov	 ecx, DWORD PTR __imp_?cout@std@@3V?$basic_ostream@DU?$char_traits@D@std@@@1@A
  00031	51		 push	 ecx
  00032	e8 00 00 00 00	 call	 ??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z ; std::operator<<<std::char_traits<char> >
  00037	83 c4 08	 add	 esp, 8
  0003a	8b c8		 mov	 ecx, eax
  0003c	ff 15 00 00 00
	00		 call	 DWORD PTR __imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@P6AAAV01@AAV01@@Z@Z
  00042	3b f4		 cmp	 esi, esp
  00044	e8 00 00 00 00	 call	 __RTC_CheckEsp

; 6    : 	return 0;

  00049	33 c0		 xor	 eax, eax

; 7    : }

  0004b	5f		 pop	 edi
  0004c	5e		 pop	 esi
  0004d	5b		 pop	 ebx
  0004e	81 c4 c0 00 00
	00		 add	 esp, 192		; 000000c0H
  00054	3b ec		 cmp	 ebp, esp
  00056	e8 00 00 00 00	 call	 __RTC_CheckEsp
  0005b	8b e5		 mov	 esp, ebp
  0005d	5d		 pop	 ebp
  0005e	c3		 ret	 0
_main	ENDP
_TEXT	ENDS
Registered users can post here. Sign in or register to post.