Re: Hey, what is all this 'off topic' posting?




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

.



Relevant Pages

  • Re: Hey, what is all this off topic posting?
    ... > I showed you how to do it with 16 instructions (counting the vector ... > now you show me the code your compiler came up with and the number ... > of cycles it takes to execute it, ... > compare on the low byte. ...
    (sci.electronics.design)
  • Re: code optimization in embedded systems
    ... outperform even a shite C compiler _in order of magnitude_. ... It wasnt a speed critical app so the speed ... C to see how you compare, the rest can join in as well, I'm quite ... A real test is to recode the 1.5k asm in C so it is algorithmically identical ...
    (comp.arch.embedded)
  • Re: Hey, what is all this off topic posting?
    ... >> I showed you how to do it with 16 instructions (counting the vector ... >> now you show me the code your compiler came up with and the number ... >> of cycles it takes to execute it, ... >> compare on the low byte. ...
    (sci.electronics.design)
  • optimizers are overrated
    ... I started learning ASM not long ago to improve my understanding of the ... The first function uses a typical C style loop to ... which one is more efficient all you guys would reply "the compiler will most ... so my "write C like ASM" optimization worked. ...
    (comp.lang.c)
  • XML-based object orientated pre-Assembler
    ... I have been promising an object orientated ASM IDE for a while now. ... Trying to make the best of what is already here, I have made a compiler, ... that will parse XML code and output ASM files. ...
    (alt.lang.asm)

Quantcast