Assembler advice

Started by upand_at_them May 7, 2005
I'm still getting used to programming in assembly and I wonder if
someone could critique a short routine I have for a 16F628.

I have three bytes (r2, r3, r4) as follows:
|xxxxxxBA| |98765432| |10xxxxxx|

and I need the middle 12 bits so that I end up with this:
|----BA98| |76543210|

Is this the best way to do it?...

movlw H'03' ; mask off the garbage
andwf r2, f
clrc
rlf r2, f
rlf r2, f
rlf r3, f
btfsc status, 0
bsf r2, 1
clrc
rlf r3, f
btfsc status, 0
bsf r2, 0
clrc
rlf r4, f
btfsc status, 0
bsf r3, 1
clrc
rlf r4, f
btfsc status, 0
bsf r3, 0
clrc

Thanks,
Mike


At 11:15 AM 5/7/2005, upand_at_them wrote:
>I'm still getting used to programming in assembly and I wonder if
>someone could critique a short routine I have for a 16F628.
>
>I have three bytes (r2, r3, r4) as follows:
>|xxxxxxBA| |98765432| |10xxxxxx|
>
>and I need the middle 12 bits so that I end up with this:
>|----BA98| |76543210|

rlf r2,f ;rotate left, MSB ends up in C
rlf r3,f ;rotate left, C winds up in LSB
rlf r2,f
rlf r3,f
rlf r2,f
rlf r3,f
movlw b'00001111' ;clear unwanted bits
andwf r3,f

Untested but should work.

dwayne

--
Dwayne Reid <dwayner@dway...>
Trinity Electronics Systems Ltd Edmonton, AB, CANADA
(780) 489-3199 voice (780) 487-6397 fax

Celebrating 21 years of Engineering Innovation (1984 - 2005)
.-. .-. .-. .-. .-. .-. .-. .-. .-. .-
`-' `-' `-' `-' `-' `-' `-' `-' `-'
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.


Oops - missed dealing with LS register. And I messed up the register order.

Lets try this again:

At 11:15 AM 5/7/2005, upand_at_them wrote:
>I'm still getting used to programming in assembly and I wonder if
>someone could critique a short routine I have for a 16F628.
>
>I have three bytes (r2, r3, r4) as follows:
>|xxxxxxBA| |98765432| |10xxxxxx|
>
>and I need the middle 12 bits so that I end up with this:
>|----BA98| |76543210|

rlf r4,f ;rotate left, MSB ends up in C
rlf r3,f ;rotate left, C winds up in LSB, MSB winds up in C
rlf r2,f ;same as above, C winds up in LSB

rlf r4,f
rlf r3,f
rlf r2,f
movlw b'00001111' ;clear unwanted bits
andwf r2,f

Untested but should work.

dwayne

--
Dwayne Reid <dwayner@dway...>
Trinity Electronics Systems Ltd Edmonton, AB, CANADA
(780) 489-3199 voice (780) 487-6397 fax

Celebrating 21 years of Engineering Innovation (1984 - 2005)
.-. .-. .-. .-. .-. .-. .-. .-. .-. .-
`-' `-' `-' `-' `-' `-' `-' `-' `-'
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.


Very cool. That uses the Carry much more efficiently. Thanks.

Mike --- In piclist@picl..., Dwayne Reid <dwayner@p...> wrote:
> Oops - missed dealing with LS register. And I messed up the
register order.
>
> Lets try this again:
>
> At 11:15 AM 5/7/2005, upand_at_them wrote:
> >I'm still getting used to programming in assembly and I wonder if
> >someone could critique a short routine I have for a 16F628.
> >
> >I have three bytes (r2, r3, r4) as follows:
> >|xxxxxxBA| |98765432| |10xxxxxx|
> >
> >and I need the middle 12 bits so that I end up with this:
> >|----BA98| |76543210|
>
> rlf r4,f ;rotate left, MSB ends up in C
> rlf r3,f ;rotate left, C winds up in LSB, MSB winds up in C
> rlf r2,f ;same as above, C winds up in LSB
>
> rlf r4,f
> rlf r3,f
> rlf r2,f
> movlw b'00001111' ;clear unwanted bits
> andwf r2,f
>
> Untested but should work.
>
> dwayne
>
> --
> Dwayne Reid <dwayner@p...>
> Trinity Electronics Systems Ltd Edmonton, AB, CANADA
> (780) 489-3199 voice (780) 487-6397 fax
>
> Celebrating 21 years of Engineering Innovation (1984 - 2005)
> .-. .-. .-. .-. .-. .-. .-. .-. .-. .-
> `-' `-' `-' `-' `-' `-' `-' `-' `-'
> Do NOT send unsolicited commercial email to this email address.
> This message neither grants consent to receive unsolicited
> commercial email nor is intended to solicit commercial email.


--- In piclist@picl..., "upand_at_them" <upand_at_them@y...>
wrote:
> Very cool. That uses the Carry much more efficiently. Thanks.
>
> Mike


One thing you might think about with something like this, and
which might be related to Dwayne getting crossed the first go
....

It might be better to align your labels with the significance
ordering of the data .... that is ....

have three bytes (r4, r3, r2) as follows:
|xxxxxxBA| |98765432| |10xxxxxx|

When your highest-order label ID corresponds to your lowest-order
databyte byte, this can only lead to confusion down the road, it
seems to me. - dan michaels
www.oricomtech.com
========================= >
> --- In piclist@picl..., Dwayne Reid <dwayner@p...> wrote:
> > Oops - missed dealing with LS register. And I messed up the
> register order.
> >
> > Lets try this again:
> >
> > At 11:15 AM 5/7/2005, upand_at_them wrote:
> > >I'm still getting used to programming in assembly and I wonder if
> > >someone could critique a short routine I have for a 16F628.
> > >
> > >I have three bytes (r2, r3, r4) as follows:
> > >|xxxxxxBA| |98765432| |10xxxxxx|
> > >
> > >and I need the middle 12 bits so that I end up with this:
> > >|----BA98| |76543210|
> >
> > rlf r4,f ;rotate left, MSB ends up in C
> > rlf r3,f ;rotate left, C winds up in LSB, MSB winds up
in C
> > rlf r2,f ;same as above, C winds up in LSB
> >
> > rlf r4,f
> > rlf r3,f
> > rlf r2,f
> > movlw b'00001111' ;clear unwanted bits
> > andwf r2,f
> >
> > Untested but should work.
> >
> > dwayne