Shop OBEX P1 Docs P2 Docs Learn Events
Collecting parameter values from functions — Parallax Forums

Collecting parameter values from functions

edgellmhedgellmh Posts: 85
edited 2008-05-14 12:28 in General Discussion
Is there a simple way to step through and collect the parameter values from a function without calling each parameter by name?

Post Edited By Moderator (Bean (Hitt Consulting)) : 5/13/2008 3:17:15 PM GMT

Comments

  • BeanBean Posts: 8,129
    edited 2008-05-13 15:14
    I'm not sure what you are asking.
    Could you post some code showing what you are doing now ?

    P.S. I added a subject to your post for you.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Did you know that 111,111,111 multiplied by 111,111,111 equals 12345678987654321 ?

    www.iElectronicDesigns.com

    ·
  • edgellmhedgellmh Posts: 85
    edited 2008-05-13 15:24
    Inside a function I would like to increment thru the __PARAMs.
  • BeanBean Posts: 8,129
    edited 2008-05-13 15:27
    What is it you want to do with each __PARAM as you go through them ?

    Show us an example...

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Did you know that 111,111,111 multiplied by 111,111,111 equals 12345678987654321 ?

    www.iElectronicDesigns.com

    ·
  • edgellmhedgellmh Posts: 85
    edited 2008-05-13 18:37
    CHECK_NEED_FOR_DOME_CLOSURE state1, state2, state3
    ‘incrementing through parameters
    For Index = 0 TO 2
    tmp1 = parameterinterator(Index)
    IF tmp1 = ON
    ‘close dome
    ENDIF
    ENDFOR

    ‘I appreciate that if the three function parameters had been assigned to variables outside ‘the function call that I would not need any parameters and could reach outside the ‘function to get their values. Of course then they would need to be in an array or some ‘other device to allow iteration.

    ‘I suppose this answers my question of how to proceed
  • VelocitVelocit Posts: 119
    edited 2008-05-13 20:05
    It sounds like you need an array of bits... as far as I know, that's not available in SX/B and there's no direct way to do it in ASM either (though I'm by no means an ASM expert). I would use a byte as an array, and each bit as a separate iteration. Something like this:

    CHK_DM_CLS     SUB    1
    
    



    CHK_DM_CLS  state           '"state" is a byte variable...
    
    



    SUB CHK_DM_CLS               'Where state.0, state.1, and state.2 are the parameters
                            'You can also clone the state of a set of input pins to state by 
                            'doing this: state  = RB, or you can substitute RB for state altogether
    tmp1 = __PARAM1
    FOR index = 0 TO 2
        IF tmp1.0 = 1 THEN
            'Close dome
        ENDIF
        tmp1 >> 1    
    NEXT
    
    ENDSUB
    
    



    This subroutine closes the dome if any of the lower three state bits are "on." It shifts through each bit since you can't use a variable as a bitIndex.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Paul
  • BeanBean Posts: 8,129
    edited 2008-05-13 21:17
    Okay, yes that can be done using the __RAM array.

    CHECK_NEED_FOR_DOME_CLOSURE state1, state2, state3
    ‘incrementing through parameters
    For Index = @__PARAM1 TO @__PARAM3
      tmp1 = __RAM(Index)
      IF tmp1 = ON
      ‘close dome
      ENDIF
    NEXT
    
    


    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Did you know that 111,111,111 multiplied by 111,111,111 equals 12345678987654321 ?

    www.iElectronicDesigns.com

    ·
  • edgellmhedgellmh Posts: 85
    edited 2008-05-14 01:52
    Paul

    I thought you could use a variable as a bitIndex as:
    state byte
    tmp1 byte

    FUNCTION_CALL state
    FOR bitIndex = 0 TO 2
    tmp1 = state.bitIndex
    IF tmp1 = 1 THEN CLOSE_DOME
    NEXT
  • VelocitVelocit Posts: 119
    edited 2008-05-14 02:00
    It doesn't work when I tried it... it won't even compile. When I examined the list file, it appears as though it's a restraint imposed by SASM.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Paul
  • BeanBean Posts: 8,129
    edited 2008-05-14 02:56
    No you cannot use a variable for the bitindex.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Did you know that 111,111,111 multiplied by 111,111,111 equals 12345678987654321 ?

    www.iElectronicDesigns.com

    ·
  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2008-05-14 12:28
    JonnyMac wrote this BITVAL function that may do what you are asking. Take a look at it in my example sniplet:
    data1   VAR Word
    tmpW1  VAR Word
    tmpW2  VAR Word
     
    tmpB1  VAR Byte
    tmpB2  VAR Byte
    I  VAR Byte
    J  VAR Byte
    value  VAR Byte
     
    Check  SUB
    BITVAL FUNC    1, 2, 3  'Thanks to JonnyMac for these cool functions!
     
     
     
    ' Use: value = BITVAL someVal, position
    ' -- "someVal" can be a byte or word
    FUNC BITVAL
      IF __PARAMCNT = 2 THEN                        ' byte passed?
        tmpW1 = __PARAM1                            ' get byte value
        tmpB1 = __PARAM2                            ' get bit position 
      ELSE                                          ' word passed
        tmpW1 = __WPARAM12                          ' word was passed
        tmpB1 = __PARAM3                            ' get bit position
      ENDIF
      tmpB2 = 0                                     ' assume cleared
      IF tmpB1 >= 0 THEN                            ' position value legal?
        IF tmpB1 <= 15 THEN
          tmpW2 = 1 << tmpB1                        ' create bit mask
          tmpW2 = tmpW2 & tmpW1                     ' clear other bits
          IF tmpW2 > 0 THEN                         ' if not zero
            tmpB2 = 1                               '   bit was 1
          ENDIF
        ENDIF  
      ENDIF
      RETURN tmpB2
      ENDFUNC
    
    Check:
     For I = 0 to 15
     value = BITVAL data1, I
     IF value = 1 THEN
        'Do something here
     ELSE
        'Do something different here
     ENDIF
     NEXT 
    
    
Sign In or Register to comment.