Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[General] Assembly language and C

Status
Not open for further replies.

djc

Advanced Member level 1
Joined
Jan 27, 2013
Messages
402
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
India
Activity points
4,554
Can we use assembly language code in c language. If yes how to do that, where can i get information about it.
 

It depends on the C compiler you are using. Read the compiler manual and find out how it is implemented.
 

It depends on the C compiler you are using. Read the compiler manual and find out how it is implemented.

It is not a recomended procedure to mix C/ASM commands at same code, unless stricly necessary, due you will waste the hardware platform portability achievable on C language.


+++
 

Usually, when mixing C and assembly, you are trying to accomplish a specific task in a specific way for a specific application or uP. Just be aware that if you ever need to port the code to another device, the assembly code will probably need to be changed (or can be eliminated because what you are trying to accomplish can be done without the assembly code).
 

I asked this because i heard that DTMF generation for phone and sine wave generation code for inverter works best with assembly code. But writing whole code in assembly could be tedious. So if some of the part could be written n C and some in assembly.
 

What you have heard is probably wrong. Always start a design with C and go to assembly only for a very specific reason. One exception. If you have existing, working, assembly code for your signal generation, then maybe it is best to retain the assembly code and embed it in the C code. The C compiler manual will have instructions on mixing in the assembly. In the "old days", it was more common to "drop into" assembly from C. However, modern compilers are so good and flexible that doing so should be rare.
 

use of assembly code increase the code time efficient means code become small and time required to execute the code is very less compare to C code. So, use of assembly in C code is required where control over time is required.
this process is called in line assembly and it depends on your compiler also.
which compiler you are using??


Regards,
embpic
 

Hello!

I asked this because i heard that DTMF generation for phone and sine wave generation code for
inverter works best with assembly code. But writing whole code in assembly could be tedious. So
if some of the part could be written n C and some in assembly.

One basic rule: never believe what your hear "as is". If somebody tells you something like that,
ask him for a convincing demonstration of what he says. And don't believe until you're 100%
convinced (i.e. in this case until you fully understand why assembly would be more efficient).

My experience is that today's compilers are so efficient that its usually very difficult to do anything
better "by hand" in assembly language. Beside this, there is nothing you can do in assembly and
cannot do in C. I'm not sure about addressing a specific CPU register in C, that would be the only
exception, but anyway if you do a+b, usually you don't care about which register is used.

A good thing to try: write some code in C, and look at the disassembly window in the debugger.
If you think you can do better, if you see obvious improvements, then do that by hand. Otherwise,
use the C compiler.

Dora.
 

The C vs Assembly argument was really over some time ago. However, stubborn holdouts which depend on assembly language are waveform synthesis and tightly controlled timing which require exact instruction cycle counts to be maintained. Often leading to ugly nop instructions placed in-line or in loops. Assemblers have Fill directives to add some number of instructions which can expand a routine for correct timing. However, I have never seen a compiler optimization or control which can instruct an Assembler to pad out the number of instruction cycles in a routine. This capability would be awesome.
 

Assembly language is still very important and necessary, though in a smaller number of instances than it used to be. Compilers are very efficient these days, but they generally still don't allow you to handle direct register manipulation in a processor for handling things like processor exceptions (invalid instruction, alignment fault, etc.) I have to write things like exception handlers in assembly for ARM processors, but everything else (save for maybe some nested ISR code) is in C. In embedded systems, one always has some processor specific code, whether it is in assembly or in some compiler-vendor supplied C-pragmas or macros. The goal is to minimize the amount of hardware specific code you'd need to port if you had to switch processors.
 

Thanks all the guys for guiding me. As embpic mentioned i am using Code Vision AVR. As analog ground mentioned waveform synthesis and tight timing measurement are the main issues. I realy dont know if they are possible in C. I haven't really started yet.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top