EmbeddedRelated.com
Forums

AVR Beginner Questions - Ports and Speed

Started by Al Borowski February 8, 2004
"David Brown" <david@no.westcontrol.spam.com> schreef in bericht
news:c0a40a$t43$1@news.netpower.no...
> > "Frank Bemelman" <fbemelx@euronet.invalid.nl> wrote in message > news:40288a05$0$93686$cd19a363@news.wanadoo.nl... > > > > There are always exceptions to the rule. Rule of thumb is that > > assembler is dead. > > > > If there are exceptions, then it is not a rule. The common opinion among > PHBs is that C is "easier" than assembly, and therefore every embedded > project should be written in C and not assembly. The reality is that C is > much better than assembly for many types of tasks, but writing in assembly > is much better for other tasks. And even when you are writing in C, an > *understanding* of the assembly is essential - you can't understand a cpu > architecture without understanding its assembly language, and you can't > write small, fast and reliable code (in any language) for a cpu without > understanding it properly. How good the code must be depends on various > factors, such as the balance between time spent in development and the
size
> and speed of the required microcontroller, but writing top-quality code in
C
> requires that you examine the generated assembly code and have enough > understanding to know how the generated code works, and how it can be > improved upon. Whenever I start working with a new microcontroller, I
write
> my first few programs (often just test programs) in assembly - even if all > the rest of the development will be in C.
Rule as in 'rule'. We know where speed counts, and those are the places to know the difference between using a uchar8 or a int32 for a loop counter, or to know the caveats of switch statement of a bunch of if-then-else constructions. Do you really need that 32 bit integer on on 8 bit processor. Things like that. If you have a loop that eats 90% of available ticks, okay, some assembly to bring it down to 30%. So, as a 'rule' assembly is dead. Exceptions to the rule aside ;) Die-hard assembly coders can come from under their rocks now. Modern compilers also implement a *7 multiplication as a left shift by 3 followd by a subtraction. And even a lot more 'clever' things like that. Assembly is dead, spread the word! ;) -- Thanks, Frank. (remove 'x' and 'invalid' when replying by email)
"David Brown" <david@no.westcontrol.spam.com> wrote in message
news:c0a40a$t43$1@news.netpower.no...
> If there are exceptions, then it is not a rule. The common opinion among > PHBs is that C is "easier" than assembly, and therefore every embedded > project should be written in C and not assembly. The reality is that C is > much better than assembly for many types of tasks, but writing in assembly > is much better for other tasks. And even when you are writing in C, an > *understanding* of the assembly is essential - you can't understand a cpu > architecture without understanding its assembly language, and you can't > write small, fast and reliable code (in any language) for a cpu without > understanding it properly. How good the code must be depends on various > factors, such as the balance between time spent in development and the
size
> and speed of the required microcontroller, but writing top-quality code in
C
> requires that you examine the generated assembly code and have enough > understanding to know how the generated code works, and how it can be > improved upon. Whenever I start working with a new microcontroller, I
write
> my first few programs (often just test programs) in assembly - even if all > the rest of the development will be in C.
AMEN! Meindert
"Frank Bemelman" <fbemelx@euronet.invalid.nl> wrote in message
news:40288a05$0$93686$cd19a363@news.wanadoo.nl...

> There are always exceptions to the rule. Rule of thumb is that > assembler is dead.
Maybe in your (limited) world... Meindert
"Meindert Sprang" <mhsprang@NOcustomSPAMware.nl> schreef in bericht
news:40289dbb@news.nb.nu...
> "Frank Bemelman" <fbemelx@euronet.invalid.nl> wrote in message > news:40288a05$0$93686$cd19a363@news.wanadoo.nl... > > > There are always exceptions to the rule. Rule of thumb is that > > assembler is dead. > > Maybe in your (limited) world...
In my limited world, at least, there is no such thing as, quote:
> NONSENSE!!!!!!
-- Thanks, Frank. (remove 'x' and 'invalid' when replying by email)
"Al Borowski" <aj.borowski@erasethis.student.qut.edu.au> schreef in bericht
news:40289ebc$0$1725$5a62ac22@freenews.iinet.net.au...
> <snip> > > I can see where this is going... > > This is going to turn into yet another "C vs ASM" threads. > > To head this off, I'll repeat the conclusions of all the other threads: > > 1) Programming in C will get most jobs done faster > > 2) Programming in ASM will take longer, but will produce smaller/faster
code
> > 3) One of the most productive strategies is to code in C, but optimise > the time critical parts in ASM.
That's a good summing up, assuming that all assembler programmers are as good as.... oh well, let's not start again ;) -- Thanks, Frank. (remove 'x' and 'invalid' when replying by email)
Dan wrote:

> On Mon, 09 Feb 2004 08:41:42 +1000, Al Borowski > <aj.borowski@erasethis.student.qut.edu.au> wrote: > > >>ClrMem: ; writes zeros to memory, 100h to 3ffh >> >>clr R0 ; clear R0 >>ldi ZH, 1 ; setup Z to point to the start of memory >>ldi ZL, 0 > > Just as a suggestion, there's almost no need to write in assembly > language. You can accomplish more, and accomplish it more quickly, if > you use a higher level programming language like C or C++. It's an > excellent skill to know assembly language, it gives to a handle on to > what's really going on. And it can also be very useful to look at the > assembly code generated by the C compiler in order to aid debugging. > But you'll end up writting better code if you start doing it in C or > C++.
Let's not get into the C vs assembler debate but there is no reason why you will write *better* code in C, whatever that is. Ian
David Brown wrote:

> If there are exceptions, then it is not a rule. The common opinion among > PHBs is that C is "easier" than assembly, and therefore every embedded > project should be written in C and not assembly.
Forgive my ignorance but what is a PHB?? Ian
"Ian Bell" <ian@ruffrecordsDOTworldonline.co.uk> wrote in message
news:4028b295_1@mk-nntp-1.news.uk.worldonline.com...
> David Brown wrote: > > > If there are exceptions, then it is not a rule. The common opinion
among
> > PHBs is that C is "easier" than assembly, and therefore every embedded > > project should be written in C and not assembly. > > Forgive my ignorance but what is a PHB?? > > Ian >
Pointy Haired Boss! Let's face it, C is superior for most applications, but I like assembly coding because it's more fun. I don't need any more justification. Peter --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.572 / Virus Database: 362 - Release Date: 27/01/04
"Ian Bell" <ian@ruffrecordsDOTworldonline.co.uk> schreef in bericht
news:4028b1f6_1@mk-nntp-1.news.uk.worldonline.com...
> Dan wrote: > > > On Mon, 09 Feb 2004 08:41:42 +1000, Al Borowski > > <aj.borowski@erasethis.student.qut.edu.au> wrote: > > > > > >>ClrMem: ; writes zeros to memory, 100h to 3ffh > >> > >>clr R0 ; clear R0 > >>ldi ZH, 1 ; setup Z to point to the start of memory > >>ldi ZL, 0 > > > > Just as a suggestion, there's almost no need to write in assembly > > language. You can accomplish more, and accomplish it more quickly, if > > you use a higher level programming language like C or C++. It's an > > excellent skill to know assembly language, it gives to a handle on to > > what's really going on. And it can also be very useful to look at the > > assembly code generated by the C compiler in order to aid debugging. > > But you'll end up writting better code if you start doing it in C or > > C++. > > Let's not get into the C vs assembler debate but there is no reason why
you
> will write *better* code in C, whatever that is.
It's about time to settle once and for all that C is better than assembler. Time has diminished all arguments that favour assembler, in general, and there is no reason to continue to live under a pile of rocks. -- Thanks, Frank. (remove 'x' and 'invalid' when replying by email)
"moocowmoo" <meltyb@hotmail.com> schreef in bericht
news:c0acep$h3f$1$8300dec7@news.demon.co.uk...
> > "Ian Bell" <ian@ruffrecordsDOTworldonline.co.uk> wrote in message > news:4028b295_1@mk-nntp-1.news.uk.worldonline.com... > > David Brown wrote: > > > > > If there are exceptions, then it is not a rule. The common opinion > among > > > PHBs is that C is "easier" than assembly, and therefore every embedded > > > project should be written in C and not assembly. > > > > Forgive my ignorance but what is a PHB?? > > > > Ian > > > > Pointy Haired Boss! > > Let's face it, C is superior for most applications, but I like assembly > coding because it's more fun. I don't need any more justification.
That's the spirit ;) -- Thanks, Frank. (remove 'x' and 'invalid' when replying by email)