Continue to Site

Welcome to

Welcome to our site! 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.

Assembly programming in C language

Not open for further replies.


Newbie level 6
Jan 10, 2003
Reaction score
Trophy points
Activity points
Assembly programming

I want to know how to write a program in C which utilises less instruction cycle ie in keeping assembly programming in mind.

Do anybody have any notes related to this.

Thanx in advance.


As I know, exists only to ways to do this:

1. Inline assembler


// C function
void MyCfunction()
// ASM inline snip
// ASM code

2. Compile fully ASM source, which exports
some functions and link obtained object
file with C compiled modules.

programming for performance

Thank you stain,

Can anyone provide me notes regarding ,

the various programming techniques when performance comes into consideration,

For Example : switch statement executes faster than if statements.So when speed comes into consideration its better to use switch than if.

Thanx in Advance,


Re: programming for performance

madmax said:
For Example : switch statement executes faster than if statements.So when speed comes into consideration its better to use switch than if.

Do not count on that. It depends upon compiler, processor, optimization level, .... and is not specified by C standard which means it is implementation dependant.

If you want to see what is going on inside your code use IDA Pro to disassemble it and check. Or just give C compiler command switch to generate assembly listing of C source code.


There are many technics like:
Handling Scalared Arrays rather than Vectored Arrays....
Small Loops Unroling....
Jump tables...

This area is wide and must be dealt with by reading books on Embedded Programming.

Hi Max,

that depends of compiler. Optimizing compilers have options that allow to optimize for memory usage, optimize for speed, compromise, etc. Someones allow to specify more precisely how to treat different situations.

A switch can be compiled in different ways by the same compiler depending of the cases. For example, if the cases of a switch are "random" numbers, the resulting code can be the same as if you used if-elseif statements. But if the cases are correlative numbers, the resulting code can use a look-up table adresses for jumping, what is better both in speed and memory usage.

A typical situation I use is a finite-state machine constructed with a switch. I define the states with enum; this assures that they are correlative numbers starting from zero, and the compiler (if it is smart) can take profit of this.
In many cases it is useful to examine the assembly code generated by the compiler, and evetually optimize it "at hand" in one of the ways mentioned by stainwood (if your code don't need to be portable to other processors) once you have debugged tour program (tested that your algorithm is correct).

I have not at hand any document to send you (sorry); at less i hope this helps.


In order to achieve what you want:

- You must master assembler. The Art of Assembly is a really good
book. I'm sure you can grab it in e-book form by here.
- Compile test programs to assembler code in order to see how your
compiler behaves. Each compiler and each optimization is a world.

Look for that book. Really good for what you want.

I've found it.


Thanx for all.

I got the concept of the programming techniques.
Also Deep I read part of the PDF and it really helps me more.Thanx a lot !


some one help me
I need MIPS asm ebook

suwanpech, this is MIPSpro Assembly Language Programmer's Guide,
it is public and made by Silicon Graphics !
Enjoy Vol 1 and Vol 2

[reposted upload due to recent elektroda hacking and attachment deletion]

I also add for your mips assembly pleasure, the free public domain:

MIPS R4000 Microprocessor User's Manual
2nd ed.

Not open for further replies.

Part and Inventory Search

Welcome to