Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

ASM vs. C

ASM vs. C

2009-01-15 by Brian

When I started in AVR's I used ASM then I learned C and found it much 
easier, faster, powerful.

What do you like most? Why would someone like ASM over C? C is so much 
easier I think.

I ask this because I hear people that like to program in ASM and I 
don't know why.

Brian

Re: [AVR-Chat] ASM vs. C

2009-01-15 by Jim Wagner

Well, some of us like asm because of speed and because things are not  
hidden in the depths of inscrutable libraries. A lot of this has to do  
with control, determinism, and predictability. Also some of us grew up  
on assembler and just don't want to change.

Jim Wagner
Oregon Research Electronics

On Jan 14, 2009, at 7:45 PM, Brian wrote:

> When I started in AVR's I used ASM then I learned C and found it much
> easier, faster, powerful.
>
> What do you like most? Why would someone like ASM over C? C is so much
> easier I think.
>
> I ask this because I hear people that like to program in ASM and I
> don't know why.
>
> Brian
>
>
> 



[Non-text portions of this message have been removed]

Re: [AVR-Chat] ASM vs. C

2009-01-15 by dlc

Noooooooooooooooo............

Brian wrote:
> When I started in AVR's I used ASM then I learned C and found it much 
> easier, faster, powerful.
> 
> What do you like most? Why would someone like ASM over C? C is so much 
> easier I think.
> 
> I ask this because I hear people that like to program in ASM and I 
> don't know why.
> 
> Brian
> 
> 
> ------------------------------------
> 
> Yahoo! Groups Links
> 
> 
> 

-- 
-------------------------------------------------
Dennis Clark          TTT Enterprises
www.techtoystoday.com
-------------------------------------------------

Re: [AVR-Chat] ASM vs. C

2009-01-15 by Dave Hylands

Hi Brian,

On Wed, Jan 14, 2009 at 7:45 PM, Brian <blue_eagle74@yahoo.com> wrote:
> When I started in AVR's I used ASM then I learned C and found it much
> easier, faster, powerful.
>
> What do you like most? Why would someone like ASM over C? C is so much
> easier I think.
>
> I ask this because I hear people that like to program in ASM and I
> don't know why.

I like C because I can write code that works the same on AVR, ARM, PC,
whatever. I still dabble in assembler when its needed, but I work with
too many different processors to keep all of the different assembly
languages straight in my head. Maybe this is just a sign of old age...

I've been using C for over 20 years, and I've probably used it on over
a dozen different architectures. I've probably handcoded assembly code
for all of those platforms too.

For people who are willing to put in the effort, you can get tighter
faster code by developing everything in assembler. Although on some
architectures the compiler will often do a much better job, unless
you're really really good at the assembler stuff. This is especially
true with the more advanced processors which have big pipelines, and
parallel execution units, etc.

Personally, I don't think C is better than assembler, nor do I think
that assembler is better than C. They're different. They have
different advantages and disadvantages. You have to make the trade
offs and decide which one is best for you and your particular
application.

-- 
Dave Hylands
Shuswap, BC, Canada
http://www.DaveHylands.com/

Re: ASM vs. C

2009-01-15 by brewski922

Ditto Dave.
I am sure most C devoties would argue that to get down and dirty or 
write the smallest and/or fast code assemble is the way to go.

And most assemble folks would say to get the program completed in the 
least amount time and/or most cost effective do it in C.

So both of them have their strong and weak points. When it comes down 
to billable income to meet overhead and/or payroll C is still your 
best bit. For hobbiest, like myself, I can go either way... 

My son works for a major US newspaper doing their web pages. For him 
you have to get the story out fast. Twenty minutes or less is good, 
all day is bad. He doesn't care that his employees uses a PC or Mac, 
nor what programming software. They just need to know how to use it.

Mike

>
> Hi Brian,
> 
> On Wed, Jan 14, 2009 at 7:45 PM, Brian <blue_eagle74@...> wrote:
> > When I started in AVR's I used ASM then I learned C and found it 
much
> > easier, faster, powerful.
> >
> > What do you like most? Why would someone like ASM over C? C is so 
much
> > easier I think.
> >
> > I ask this because I hear people that like to program in ASM and I
> > don't know why.
> 
> I like C because I can write code that works the same on AVR, ARM, 
PC,
> whatever. I still dabble in assembler when its needed, but I work 
with
> too many different processors to keep all of the different assembly
> languages straight in my head. Maybe this is just a sign of old 
age...
> 
> I've been using C for over 20 years, and I've probably used it on 
over
> a dozen different architectures. I've probably handcoded assembly 
code
Show quoted textHide quoted text
> for all of those platforms too.
> 
> For people who are willing to put in the effort, you can get tighter
> faster code by developing everything in assembler. Although on some
> architectures the compiler will often do a much better job, unless
> you're really really good at the assembler stuff. This is especially
> true with the more advanced processors which have big pipelines, and
> parallel execution units, etc.
> 
> Personally, I don't think C is better than assembler, nor do I think
> that assembler is better than C. They're different. They have
> different advantages and disadvantages. You have to make the trade
> offs and decide which one is best for you and your particular
> application.
> 
> -- 
> Dave Hylands
> Shuswap, BC, Canada
> http://www.DaveHylands.com/
>

Re: [AVR-Chat] Re: ASM vs. C

2009-01-15 by Zack Widup

Since I am mainly in the "hobbyist" class, I am not concerned about the time
it takes to write a program. I'm more concerned about program efficiency
when it's actually runing in the microcontroller.

I write in assembler because the programs come out much smaller and faster
than when written in C. Considering I'm often trying to load a program into
a device with limited flash memory anyway, this is important. I did try
writing some of the programs I'd already written in assembler in C and found
the C compiler generated code that was as much as one and a half times the
size of the assembler code. Lots of redundundundancy.

Plus, you get to learn to "think" like the particular microcontroller when
you write in its assembler.  And you sometimes learn little tricks and
shortcuts that make the code even smaller and faster.

Just my tuppence worth.

Zack


On 1/15/09, brewski922 <Brewskister@gmail.com> wrote:
>
>   Ditto Dave.
> I am sure most C devoties would argue that to get down and dirty or
> write the smallest and/or fast code assemble is the way to go.
>
> And most assemble folks would say to get the program completed in the
> least amount time and/or most cost effective do it in C.
>
> So both of them have their strong and weak points. When it comes down
> to billable income to meet overhead and/or payroll C is still your
> best bit. For hobbiest, like myself, I can go either way...
>
> My son works for a major US newspaper doing their web pages. For him
> you have to get the story out fast. Twenty minutes or less is good,
> all day is bad. He doesn't care that his employees uses a PC or Mac,
> nor what programming software. They just need to know how to use it.
>
> Mike
>
> >
> > Hi Brian,
> >
> > On Wed, Jan 14, 2009 at 7:45 PM, Brian <blue_eagle74@...> wrote:
> > > When I started in AVR's I used ASM then I learned C and found it
> much
> > > easier, faster, powerful.
> > >
> > > What do you like most? Why would someone like ASM over C? C is so
> much
> > > easier I think.
> > >
> > > I ask this because I hear people that like to program in ASM and I
> > > don't know why.
> >
> > I like C because I can write code that works the same on AVR, ARM,
> PC,
> > whatever. I still dabble in assembler when its needed, but I work
> with
> > too many different processors to keep all of the different assembly
> > languages straight in my head. Maybe this is just a sign of old
> age...
> >
> > I've been using C for over 20 years, and I've probably used it on
> over
> > a dozen different architectures. I've probably handcoded assembly
> code
> > for all of those platforms too.
> >
> > For people who are willing to put in the effort, you can get tighter
> > faster code by developing everything in assembler. Although on some
> > architectures the compiler will often do a much better job, unless
> > you're really really good at the assembler stuff. This is especially
> > true with the more advanced processors which have big pipelines, and
> > parallel execution units, etc.
> >
> > Personally, I don't think C is better than assembler, nor do I think
> > that assembler is better than C. They're different. They have
> > different advantages and disadvantages. You have to make the trade
> > offs and decide which one is best for you and your particular
> > application.
> >
> > --
> > Dave Hylands
> > Shuswap, BC, Canada
> > http://www.DaveHylands.com/ <http://www.davehylands.com/>
> >
>
> 
>


[Non-text portions of this message have been removed]

Re: [AVR-Chat] Re: ASM vs. C

2009-01-15 by David Kelly

On Thu, Jan 15, 2009 at 01:06:01PM -0000, brewski922 wrote:
> Ditto Dave.
> I am sure most C devoties would argue that to get down and dirty or 
> write the smallest and/or fast code assemble is the way to go.

I do not consider myself to be a "C devotee", altho C is among my
preferred tools. There is a big question as to just how small and how
fast is small and fast enough? On AVR, HC11, and HC12, on examination of
assembly code I have found C and assembly to be roughly equal in speed
and code density.

> And most assemble folks would say to get the program completed in the 
> least amount time and/or most cost effective do it in C.

The larger the project the more important it is to abstract parts of it,
then put it aside and forget it while working on other parts. That is
something that C does very well, and is exactly what C++ is about taking
to the next level.

When projects get big, C often generates smaller code because one was
abstracting concepts and often finds ways to reuse more portions than
the assembly programmer.

> So both of them have their strong and weak points.

There really isn't any weak point to C. The only gripes I have at times
is when a compiler calls an intrinsic function for something relatively
simple like uint32_t i++. Or for a 32 bit comparison (HCS12,
CodeWarrior). Have found there that I can put the 32 bit variable in a
union and separately compare uint16_t's in the same space and time as
the compiler can setup the intrinsic function call. But guess what? This
is exactly the sort of thing one would have to do in assembly.

-- 
David Kelly N4HHE, dkelly@HiWAAY.net
========================================================================
Whom computers would destroy, they must first drive mad.

Re: [AVR-Chat] Re: ASM vs. C

2009-01-15 by Russell Shaw

David Kelly wrote:
> On Thu, Jan 15, 2009 at 01:06:01PM -0000, brewski922 wrote:
>> Ditto Dave.
>> I am sure most C devoties would argue that to get down and dirty or 
>> write the smallest and/or fast code assemble is the way to go.
> 
> I do not consider myself to be a "C devotee", altho C is among my
> preferred tools. There is a big question as to just how small and how
> fast is small and fast enough? On AVR, HC11, and HC12, on examination of
> assembly code I have found C and assembly to be roughly equal in speed
> and code density.
> 
>> And most assemble folks would say to get the program completed in the 
>> least amount time and/or most cost effective do it in C.
> 
> The larger the project the more important it is to abstract parts of it,
> then put it aside and forget it while working on other parts. That is
> something that C does very well, and is exactly what C++ is about taking
> to the next level.
> 
> When projects get big, C often generates smaller code because one was
> abstracting concepts and often finds ways to reuse more portions than
> the assembly programmer.
> 
>> So both of them have their strong and weak points.
> 
> There really isn't any weak point to C. The only gripes I have at times
> is when a compiler calls an intrinsic function for something relatively
> simple like uint32_t i++. Or for a 32 bit comparison (HCS12,
> CodeWarrior). Have found there that I can put the 32 bit variable in a
> union and separately compare uint16_t's in the same space and time as
> the compiler can setup the intrinsic function call. But guess what? This
> is exactly the sort of thing one would have to do in assembly.

The best thing about most HLLs compared to assembler is that you can chop
and change great stretches of code and see what you're doing and have the
system running again easily.

With asm, you have to tediously study one great column of code before and
after you do any chopping and pasting. HLLs have a 2D visual aspect to it.

Re: [AVR-Chat] Re: ASM vs. C

2009-01-15 by David VanHorn

> With asm, you have to tediously study one great column of code before and
> after you do any chopping and pasting. HLLs have a 2D visual aspect to it.

It's certainly possible to write ASM as one huge tarball of cruft, but
that's not how I do it.

Here's an ISR that I just compiled with optimization set for smallest
code, in GCC:

// Timer 0 overflow ISR
ISR(TIMER0_OVF_vect)
{
     498:	1f 92       	push	r1
     49a:	0f 92       	push	r0
     49c:	0f b6       	in	r0, 0x3f	; 63
     49e:	0f 92       	push	r0
     4a0:	11 24       	eor	r1, r1
	ADCSRA |= (1<<ADSC);					// Start the next ADC conversion
     4a2:	36 9a       	sbi	0x06, 6	; 6
     4a4:	0f 90       	pop	r0
     4a6:	0f be       	out	0x3f, r0	; 63
     4a8:	0f 90       	pop	r0
     4aa:	1f 90       	pop	r1
     4ac:	18 95       	reti


Only TWO of those instructions are actually needed!
If it were me writing, it would look like this:

T0_OVF_ISR:
          sbi ADCSRA,(1<<ADSC)
          reti

Since SBI and CBI don't affect flags, and no registers are used,
nothing needs to be pushed or popped at all!
I'm still astounded that at this late date, this kind of thing happens.

Re: [AVR-Chat] ASM vs. C

2009-01-17 by Muhammad Amiruddin

because with asm , we can directly access the bit of certain registry that we need to use, and with this asm is more powerfull than c.


--- On Thu, 1/15/09, Brian <blue_eagle74@yahoo.com> wrote:
Show quoted textHide quoted text
From: Brian <blue_eagle74@yahoo.com>
Subject: [AVR-Chat] ASM vs. C
To: AVR-Chat@yahoogroups.com
Date: Thursday, January 15, 2009, 3:45 AM






When I started in AVR's I used ASM then I learned C and found it much 
easier, faster, powerful.

What do you like most? Why would someone like ASM over C? C is so much 
easier I think.

I ask this because I hear people that like to program in ASM and I 
don't know why.

Brian

 














      

[Non-text portions of this message have been removed]

Re: [AVR-Chat] ASM vs. C

2009-01-18 by David Kelly

On Jan 17, 2009, at 8:13 AM, Muhammad Amiruddin wrote:

> because with asm , we can directly access the bit of certain  
> registry that we need to use, and with this asm is more powerfull  
> than c.

Do it all the time in C. Usually compiles down to exactly the same  
single assembly instruction one would have written by hand.

--
David Kelly N4HHE, dkelly@HiWAAY.net
========================================================================
Whom computers would destroy, they must first drive mad.

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.