Results 1 to 9 of 9

Thread: machine code

  1. #1
    Junior Member
    Join Date
    Feb 2005
    Posts
    14

    machine code

    suppose we want to write a console app that outputs the string "hello world" to the screen using c++,c, assembly or any other languages.will the machine code generated by these languages be the same?

    thanks

  2. #2
    Errrrr... JAVA uses bytecode.

  3. #3
    Senior Member
    Join Date
    Mar 2004
    Posts
    557
    Hi

    Some aspects of your question, and an explanation of TheSpecialists comment,
    can be found in this thread[1] (read the whole thing).

    In short: No.

    More lengthy: What do you mean by "same" machine code?
    Let us consider "c" only. There are lots of compilers available.
    Each compiler has its own flavour of producing/optimising/aligning code/data.
    If you do a "printf" only, you will possibly find similarities, but never exactly the
    same machine code (exception might be the simplest arithmetical operations).
    Even using the same compiler, while changing some flags you will have a
    bunch of different outputs.
    However: A call to a fixed API function will always be a call to a fixed API function.
    In such a sense, they will (partly) produce the same code.

    Example:
    Code:
    x=0;
    could look like
    Code:
    mov         dword ptr [ebp-4],0
    or
    Code:
    	  mov  eax,dword ptr [ebp-4]
    	  xor  eax,eax
    	  mov  dword ptr [ebp-4],eax
    
    ; although, very unlikely
    etc.



    Cheers.

    [1] http://www.antionline.com/showthread...hreadid=265616
    If the only tool you have is a hammer, you tend to see every problem as a nail.
    (Abraham Maslow, Psychologist, 1908-70)

  4. #4
    Junior Member
    Join Date
    Feb 2005
    Posts
    14
    after reading the thread i have another question.

    since all compiled language gets turn to machine code and assembly mnemonics are machine code,would'nt it be possible to read the machine code and assign the right mnemonic to it?

  5. #5
    Why did you edit your post so that JAVA is no longer listed with those languages... I thought it was pretty funny.

  6. #6
    Junior Member
    Join Date
    Feb 2005
    Posts
    14
    it won't be funny if u were a newbie now would it?

    EDIT:u want to know what's even funnier?after reading ur post i immediately posted "how'd u know?" then when i realise the poster was the same person i quickly deleted my post and posted this one.hahaha.anyway back to the question

  7. #7
    it won't be funny if u were a newbie now would it?
    Im worse than that... im an AO senior member. Once you've got to that stage you can just spurt out something randomly and a few people will always assume your right and you know something.

    The think its the processor and if we go deeper the ALU, all need to understand the compiled program. The compiled program is just a series of opcodes, that can be easily converted back to ASM, with no major hassle.
    ^ already linked

  8. #8
    Junior Member
    Join Date
    Feb 2005
    Posts
    14
    so any program written for any language specifically for the x86 processor can be diaasembled into assembly language for the x86 processor,right?

  9. #9
    Senior Member
    Join Date
    Mar 2004
    Posts
    557
    Hi

    Disassembling of compiled code into assembly language is nothing mysterious.
    Assembler opcodes (text editor) are representatives of machine code (hex-editor),
    eg
    Code:
    0F84h (a sequence of 0 and 1's) is jz  // "do     jump if "
    0F85h (a sequence of 0 and 1's) is jnz // "do not jump if "
    There is only one difficulty, namely when the executable is packed
    and selfmodifying (besides a few tricks to hinder disassemblers).

    Cheers.
    If the only tool you have is a hammer, you tend to see every problem as a nail.
    (Abraham Maslow, Psychologist, 1908-70)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •