basic difference between compiler and assembler

Status
Not open for further replies.

vead

Full Member level 5
Joined
Nov 27, 2011
Messages
285
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
india
Visit site
Activity points
3,815
hi,
i have just started read about embedded system. i know, to make project i need microcontroller and software and other things.
in software terms i am confused i don't know actually when and where they used in embedded project?
i am using mc 8051 , c compiler and assembler
do i need to compiler or assembler or we can make project with combination of compiler and assembler
please explain with suitable example.......?
 

Final goal is to make HEX or BIN file, which goes to uC memory.

You can combine Hi-Level code with assembly without problem.




Best regards,
Peter
 

can you explain why we are using both software(compiler assembler) to complete one project when their work is same
 

Compiler is used to write programs in high level languages like C, C++ and Assemblers are used to write code in assembly language. If your question is regarding microcontroller programming then AVr, PIC, 8051, etc... have their own instruction set for assembly language. If you write code for 8051 in assembly language then you cannot use it for PIC or AVR uCs but if you write code using C then code can be ported with minimal changes.
 
Reactions: vead

    V

    Points: 2
    Helpful Answer Positive Rating

    vead

    Points: 2
    Helpful Answer Positive Rating
can you explain why we are using both software(compiler assembler) to complete one project when their work is same

First its not appropriate to say "both software - compiler & assembler", assembler is also compiler.

Your question is not quite true. Programmer dont have need to use assembler compiler to make code, he can use only hi-level compiler such as C, Pascal, Basic. There is Hi-Level language tool compilers and Assembler Compilers. Assembler compilers are low level language and this code is very small and fast, but its not easy for learning. Hi-level languages make programming easier and faster.


eBook: PIC Microcontrollers - Programming in C
Chapter 2 : PROGRAMMING LANGUAGES
**broken link removed**



Best regards,
Peter
 

    V

    Points: 2
    Helpful Answer Positive Rating
If you write your code in assembly language you will need an assembler to convert the code to a .hex or .bin that the uC understand.if you write your code in language like c,basic, or pascal you will need a compiler to convert the code into a .hex or .bin format.
 

Hello!

Assembler compilers are low level language and this code is very small and fast, but its not easy for learning.

I agree that it's not easy for learning.
As for the "very small and fast", it very much depends on what compiler you are using.
Modern compilers are so efficient that it's usually not worth bothering with assembler.
And beside this, C is so close to assembler that there is nothing you can do in assembler
and not in C.
A good way to verify this. When using your favorits C compiler, try to open the disassembly
window. You will notice that there is usually no way to optimize further.
Another point: if you write a function that will be used zillions of times, then yes, it might
be worth to write it in assembler (example: an FFT butterfly).
Now if you are writing initializations (that are performed once at boot time), then who cares
if it's inefficient?

Dora.
 

well said dora
 


I have one question sir.
Why it is inefficient if we call a function so many times which is written in C? and what difference the asm language will going to make for the same case?
explanation with the example will be great help to me.
Thanks
 

I have one question sir.
Why it is inefficient if we call a function so many times which is written in C? and what difference the asm language will going to make for the same case?
explanation with the example will be great help to me.
Thanks

because a compiler is compiling each statement in same manner

if you write

Code C - [expand]
1
2
3
a = x; // 5 instructions in assembly
b = y; // 5 instructions in assembly
c = a * b;



but when writing in assembly you may not need that much assembly instructions (It was efficient in writing assembly)...

So if you conserve a small timing in a loop which executes much times then it will give you a considerable time saving....

and also if a function executes much times you can write it as a macro function or inline function, that will avoid the time or calling the function.....
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…