i am pretty new to assembly language and i wonder what is difference between the final binary output of the same program written in c and written in an assembly if they do exactly the same thing. if the binary output is the same then why use assembly language? if they are not same then how the programs function the same?

thanks

Recommended Answers

All 4 Replies

Define "doing the same thing".

I can drive to the store on my bike and in my car, doing 2 different things. Or I can say that I'm going to the store, doing one thing, in 2 ways.

C compilers will probably never output exactly the same output as when you would hand-code it.

Apart from that, it often takes a lot more effort to write assembly code to achieve X than it does to do X in a higher level language like C. C also has a library .... which means it is not necessary to code everything from scratch.

As an exercise, try getting to the stage where you have some level of familiarity with both assembler (on your target machine) and with C. Then pick a reasonably non-trivial programming task that seeks to read data from files, do some processing, and write data back to files. First implement it in assembler, and track how long it takes. Take a week off to clear your head. Then implement it in C, (without looking at any of the design or code from your assembler work) and track how long that takes.

When you've done that, report back here (I'll look forward to seeing your post in a couple of months).

Odds are, you will find things take you a lot longer with assembler.

>what is difference between the final binary output of the same program
>written in c and written in an assembly if they do exactly the same thing.
Hand-crafted assembly written by a skilled assembly programmer will probably be more optimized than the object code produced by a compiler.

>if they are not same then how the programs function the same?
You can do things very differently in a program and still end at the same result. That's why you can ask ten programmers to write the same program to the same specification and get ten completely different solutions.

you can ask ten programmers to write the same program to the same specification and get ten completely different solutions.

But only one correct solution -- mine :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.