Shop OBEX P1 Docs P2 Docs Learn Events
inline asm get pin states pin 0 to 7 — Parallax Forums

inline asm get pin states pin 0 to 7

Mart1970Mart1970 Posts: 23
edited 2014-09-09 08:34 in General Discussion
Hello

How to get pin states from pin 0 to 7 ,
in simple ide c inline asm.

I found this on the net
Is this for one pin or can i also use it for mutliple pin's.
static __inline__ int getpin(int pin)
{
 uint32_t value[COLOR=#666600];
[/COLOR]__asm__ [COLOR=#000088]volatile[/COLOR] [COLOR=#666600](
[/COLOR]                         "getp %[_pin] wc\n\t"
                         "mov %[_value], #0\n\t"
                         "rcl %[_value], #1"
                         : /* outputs */
                          [_value] "=r" (value)
                         : /* inputs */
                          [_pin] "r" (pin)
                         : /* no clobbered registers */
                          );
 return value;
}



kind regards.

Comments

  • ElectrodudeElectrodude Posts: 1,658
    edited 2014-09-07 16:17
    attachment.php?attachmentid=78421&d=1297987572
  • Mart1970Mart1970 Posts: 23
    edited 2014-09-07 16:38
    Hello

    I wrote a new code.
    i don't know it works.
    __asm__(
                 "mov r8, #0xff\n\t"
                 "shl r20, #0xff\n\t"
                 "andn outa, r20\n\t"
                 "mov %[_value], ina wc\n\t"
                 : /* outputs */
                 [_value] "=r" (value)
                 : /* inputs */
                 : /* no clobbered registers */
                 );
    

    Hope this wil work
    I try it out in the morning it's past midnight over here.
    good night.
  • kuronekokuroneko Posts: 3,623
    edited 2014-09-07 16:55
    What's wrong with doing it in C (boils down to 2 PASM insns):
    result = INA & 0xFF;
    
  • msrobotsmsrobots Posts: 3,709
    edited 2014-09-07 20:11
    DIe schwarze Katze wieder... (@kuroneko again...)

    As usual down to the point. I love it.

    If life ever brings me down to Japan - I hope I can meet you.

    Enjoy!

    Mike
  • Mart1970Mart1970 Posts: 23
    edited 2014-09-07 22:13
    Kuroneko.

    I try it, but i am very critical in time.

    Thanks

    Mart
  • kuronekokuroneko Posts: 3,623
    edited 2014-09-08 21:14
    Mart1970 wrote: »
    I try it, but i am very critical in time.
    If critical doesn't refer to code speed please ignore this post.

    In PASM you'd do the following:
    mov state, ina
    and state, #$FF
    
    with the mask insn being optional when you write the byte to hub anyway (wrbyte does that for you). The C example I gave compiles down to the same sequence. IOW there is no need to go near inline assembly (for something as simple as this).
  • David BetzDavid Betz Posts: 14,516
    edited 2014-09-09 02:52
    Mart1970 wrote: »
    Hello

    How to get pin states from pin 0 to 7 ,
    in simple ide c inline asm.

    I found this on the net
    Is this for one pin or can i also use it for mutliple pin's.
    static __inline__ int getpin(int pin)
    {
     uint32_t value[COLOR=#666600];
    [/COLOR]__asm__ [COLOR=#000088]volatile[/COLOR] [COLOR=#666600](
    [/COLOR]                         "getp %[_pin] wc\n\t"
                             "mov %[_value], #0\n\t"
                             "rcl %[_value], #1"
                             : /* outputs */
                              [_value] "=r" (value)
                             : /* inputs */
                              [_pin] "r" (pin)
                             : /* no clobbered registers */
                              );
     return value;
    }
    
    


    kind regards.
    This looks like code for the Propeller 2. There is no GETP instruction in P1. Also, it would only get the state of a single pin. As others have already pointed out, getting the states of P0-P7 can be done in C directly just as efficiently and more readably then any inline assembly could do. Take the easy approach and let GCC do your work for you! :-)
  • Mart1970Mart1970 Posts: 23
    edited 2014-09-09 08:34
    Thanks to all.


    result = INA & 0xFF;
    Works for me
Sign In or Register to comment.