EmbeddedRelated.com
Forums

rotate in C

Started by hal_lex_1 January 15, 2007
hi,

the msp430 has assembler commands for rotating registers:

RLA(.B) dst Rotate left arithmetically * * * *
RLC(.B) dst Rotate left through C * * * *
RRA(.B) dst Rotate right arithmetically 0 * * *
RRC(.B) dst Rotate right through C * * * *
but how do i access those commands in C ?? (crossworks!)

shift is still easy with operators >> and <<.

thx

Beginning Microcontrollers with the MSP430

C has no knowledge of the Carry flag in a CPU.
If it did, it wouldnt be a high level language would it ? :-)
It depends on what you need the Carry/rotate for.

If it's eg. to sample 8 bits within a byte, then there's other ways of doing this.
Worst case scenario, you can always create an ASM function and call it from C.

Best Regards,
Kris

-----Original Message-----
From: m... [mailto:m...] On Behalf Of hal_lex_1
Sent: Monday, 15 January 2007 8:38 PM
To: m...
Subject: [msp430] rotate in C

hi,

the msp430 has assembler commands for rotating registers:

RLA(.B) dst Rotate left arithmetically * * * *
RLC(.B) dst Rotate left through C * * * *
RRA(.B) dst Rotate right arithmetically 0 * * *
RRC(.B) dst Rotate right through C * * * *
but how do i access those commands in C ?? (crossworks!)

shift is still easy with operators >> and <<.

thx



There is none. This one thing that inline assembly is all about.

Steve
hal_lex_1 wrote:
> hi,
>
> the msp430 has assembler commands for rotating registers:
>
> RLA(.B) dst Rotate left arithmetically * * * *
> RLC(.B) dst Rotate left through C * * * *
> RRA(.B) dst Rotate right arithmetically 0 * * *
> RRC(.B) dst Rotate right through C * * * *
> but how do i access those commands in C ?? (crossworks!)
>
> shift is still easy with operators >> and <<.
>
> thx
>
>
>
unsigned char rotate_byte_left(unsigned char x)
{
return (x << 1) | (x >> 7);
}

> -----Original Message-----
> From: m... [mailto:m...]
> On Behalf Of Steve Sabram
> Sent: 15 January 2007 18:24
> To: m...
> Subject: Re: [msp430] rotate in C
>
> There is none. This one thing that inline assembly is all about.
>
> Steve
>
>
> hal_lex_1 wrote:
> > hi,
> >
> > the msp430 has assembler commands for rotating registers:
> >
> > RLA(.B) dst Rotate left arithmetically * * * * RLC(.B) dst Rotate
> > left through C * * * *
> > RRA(.B) dst Rotate right arithmetically 0 * * *
> > RRC(.B) dst Rotate right through C * * * *
> >
> >
> > but how do i access those commands in C ?? (crossworks!)
> >
> > shift is still easy with operators >> and <<.
> >
> > thx
> >
> >
> >
> >
> >
> >
> >
You could define 51 Macros correspond to the 51 MSP430 instructions
and use these Macros in C whenever and wherever you want. This way
you can eat half of a cake and still have the other half.
Unfortunately, you cannot eat the half that you kept and cannot still
have the half that you ate.

--- In m..., "hal_lex_1" wrote:
>
> hi,
>
> the msp430 has assembler commands for rotating registers:
>
> RLA(.B) dst Rotate left arithmetically * * * *
> RLC(.B) dst Rotate left through C * * * *
> RRA(.B) dst Rotate right arithmetically 0 * * *
> RRC(.B) dst Rotate right through C * * * *
> but how do i access those commands in C ?? (crossworks!)
>
> shift is still easy with operators >> and <<.
>
> thx
>
Heh, reminds me of one the key sentences in his manifest on how they caught Unabomber...
(Or should I say, got dobbed in:-)
"You cannot eat your cake and have it too".

Best Regards,
Kris


-----Original Message-----
From: m... [mailto:m...] On Behalf Of old_cow_yellow
Sent: Tuesday, 16 January 2007 7:42 AM
To: m...
Subject: [msp430] Re: rotate in C

You could define 51 Macros correspond to the 51 MSP430 instructions
and use these Macros in C whenever and wherever you want. This way
you can eat half of a cake and still have the other half.
Unfortunately, you cannot eat the half that you kept and cannot still
have the half that you ate.

--- In m..., "hal_lex_1" wrote:
>
> hi,
>
> the msp430 has assembler commands for rotating registers:
>
> RLA(.B) dst Rotate left arithmetically * * * *
> RLC(.B) dst Rotate left through C * * * *
> RRA(.B) dst Rotate right arithmetically 0 * * *
> RRC(.B) dst Rotate right through C * * * *
>
>
> but how do i access those commands in C ?? (crossworks!)
>
> shift is still easy with operators >> and <<.
>
> thx
>



that sounds interesting! i will dig into it, however i never made
macros myself ... do you have an example for crossworks?

--- In m..., "old_cow_yellow"
wrote:
>
> You could define 51 Macros correspond to the 51 MSP430 instructions
> and use these Macros in C whenever and wherever you want. This way
> you can eat half of a cake and still have the other half.
> Unfortunately, you cannot eat the half that you kept and cannot still
> have the half that you ate.
>
> --- In m..., "hal_lex_1" wrote:
> >
> > hi,
> >
> > the msp430 has assembler commands for rotating registers:
> >
> > RLA(.B) dst Rotate left arithmetically * * * *
> > RLC(.B) dst Rotate left through C * * * *
> > RRA(.B) dst Rotate right arithmetically 0 * * *
> > RRC(.B) dst Rotate right through C * * * *
> >
> >
> > but how do i access those commands in C ?? (crossworks!)
> >
> > shift is still easy with operators >> and <<.
> >
> > thx
>
On Mon, 15 Jan 2007 19:55:56 -0000, Paul wrote:

>unsigned char rotate_byte_left(unsigned char x)
>{
> return (x << 1) | (x >> 7);
>}

You just convinced me to use assembly from now on! ;)

Jon
Have a look at the intrinsic files of the
Crosswork-Compiler:

'In430.h' <-- does include "inmsp.h"
'inmsp.h'

there is an intrinsic function already defined:

// Reverse order of bits in a char
#pragma intrinsic(__bit_reverse_char)
unsigned char __bit_reverse_char(unsigned char);

Is this what you are looking for?

--- hal_lex_1 schrieb:

> that sounds interesting! i will dig into it, however
> i never made
> macros myself ... do you have an example for
> crossworks?
>
> --- In m..., "old_cow_yellow"
>
> wrote:
> >
> > You could define 51 Macros correspond to the 51
> MSP430 instructions
> > and use these Macros in C whenever and wherever
> you want. This way
> > you can eat half of a cake and still have the
> other half.
> > Unfortunately, you cannot eat the half that you
> kept and cannot still
> > have the half that you ate.
> >
> > --- In m..., "hal_lex_1"
> wrote:
> > >
> > > hi,
> > >
> > > the msp430 has assembler commands for rotating
> registers:
> > >
> > > RLA(.B) dst Rotate left arithmetically * * * *
> > > RLC(.B) dst Rotate left through C * * * *
> > > RRA(.B) dst Rotate right arithmetically 0 * * *
> > > RRC(.B) dst Rotate right through C * * * *
> > >
> > >
> > > but how do i access those commands in C ??
> (crossworks!)
> > >
> > > shift is still easy with operators >> and <<.
> > >
> > > thx
> > >
> >

___________________________________________________________
Der fre Vogel fgt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de