Re: Hey, what is all this 'off topic' posting?
- From: langwadt@xxxxxxxx
- Date: 5 Sep 2005 12:55:37 -0700
John Fields skrev:
>
snip
I'm not what all the fuzz is about use ASM when it makes sense, use C
when
that makes sense.
C code is only as bloated as you make it, depending on how you write
your
code the compiler can be a little more than a some what intelligent
assembler
with a portable language.
So ASM usually gains very little except in a few cases
>
> I showed you how to do it with 16 instructions (counting the vector
> into the ISR as an instruction in 69 cycles with handwritten code,
> now you show me the code your compiler came up with and the number
> of cycles it takes to execute it, OK?
>
> Actually, for a no compare on the low byte, the code can tighten up
> to:
>
> cmplo: lda lobytea 3 ;get low byte of word a
> sta temp 4 ;store it
> lda lobyteb 3 ;get low byte of word b
> cmp temp 3 ;compare it with what's in temp
> beq cmphi 3 ;branch if they're equal
> bclr 0,status 5 ;if they're not, clear status bit 0
> rti 9 ;and return
> cmphi: bset 0,status 5 ;set status bit 0 (lobyeta = lobyteb)
> lda hibytea 3 ;get high byte of word a
> sta temp 4 ;store it
> lda hibyteb 3 ;get high byte of word b
> cmp temp 3 ;compare it with what's in temp
> beq out 3 ;return if they're equal
> bclr 0,status 5 ;else clear status bit 0
> out: rti 9 ;and return
>
> which saves three cycles (from 40 to 37) if there's not a valid
> compare on the low byte. A good compare on the high byte stays at
> 64 cycles, and a non-compare stays at 69 cycles.
>
I downloaded a demo version of cosmics 6805 compiler, compiling
unsigned char result;
unsigned short a;
unsigned short b;
@interrupt void _Isr(void)
{
if(a==b) result = 1;
else result = 0;
}
Produced:
b603 lda _a+1
b101 cmp _b+1
260b bne L52
be02 ldx _a
b300 cpx _b
2605 bne L52
a601 lda #1
b704 sta _result
80 rti
L52:
3f04 clr _result
80 rti
Not too bad ....
-Lasse
.
- Follow-Ups:
- Re: Hey, what is all this 'off topic' posting?
- From: Frank Bemelman
- Re: Hey, what is all this 'off topic' posting? / asm vs c
- From: James Waldby
- Re: Hey, what is all this 'off topic' posting?
- References:
- Hey, what is all this 'off topic' posting?
- From: Bob Monsen
- Re: Hey, what is all this 'off topic' posting?
- From: John Larkin
- Re: Hey, what is all this 'off topic' posting?
- From: Pooh Bear
- Re: Hey, what is all this 'off topic' posting?
- From: SioL
- Re: Hey, what is all this 'off topic' posting?
- From: Frank Bemelman
- Re: Hey, what is all this 'off topic' posting?
- From: Pooh Bear
- Re: Hey, what is all this 'off topic' posting?
- From: John Fields
- Re: Hey, what is all this 'off topic' posting?
- From: Pooh Bear
- Re: Hey, what is all this 'off topic' posting?
- From: John Fields
- Hey, what is all this 'off topic' posting?
- Prev by Date: Re: Maria is the 13th named storm of the Atlantic hurricane season
- Next by Date: Re: Bush is either a liar, or an idiot, or both.
- Previous by thread: Re: Hey, what is all this 'off topic' posting?
- Next by thread: Re: Hey, what is all this 'off topic' posting? / asm vs c
- Index(es):
Relevant Pages
|