Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

Assembly programming in C language

Status
Not open for further replies.

madmax

Newbie level 6
Joined
Jan 10, 2003
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
120
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.

Max
 

stainwood

Newbie level 6
Joined
May 3, 2002
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
18
As I know, exists only to ways to do this:

1. Inline assembler

eg.

// C function
void MyCfunction()
{
// ASM inline snip
asm
{
// ASM code
}
}

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

madmax

Newbie level 6
Joined
Jan 10, 2003
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
120
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,

Max
[/i]
 

tom324

Full Member level 1
Joined
Jun 26, 2001
Messages
98
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Location
Croatia
Activity points
672
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.
[/i]
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.

Tom
 

roli

Full Member level 5
Joined
Apr 29, 2001
Messages
246
Helped
9
Reputation
20
Reaction score
9
Trophy points
1,298
Location
'SiliconWafer' Island
Activity points
1,824
There are many technics like:
Handling Scalared Arrays rather than Vectored Arrays....
Small Loops Unroling....
Jump tables...
LUTs...
etc...

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

zorro

Advanced Member level 4
Joined
Sep 6, 2001
Messages
1,131
Helped
356
Reputation
710
Reaction score
298
Trophy points
1,363
Location
Argentina
Activity points
8,902
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.
regards

Z
 

Darkseed

Member level 2
Joined
Nov 30, 2002
Messages
50
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
410
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.
 

Darkseed

Member level 2
Joined
Nov 30, 2002
Messages
50
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
410
I've found it.
 

madmax

Newbie level 6
Joined
Jan 10, 2003
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
120
Thanks

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 !


Max
 

suwanpech

Newbie level 1
Joined
Jan 4, 2003
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
6
some one help me
I need MIPS asm ebook
thank
 

sgrudu

Member level 2
Joined
Dec 14, 2002
Messages
44
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
ITALY
Activity points
359
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]
 

sgrudu

Member level 2
Joined
Dec 14, 2002
Messages
44
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
ITALY
Activity points
359
I also add for your mips assembly pleasure, the free public domain:

MIPS R4000 Microprocessor User's Manual
2nd ed.
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top