And another question for Bean..reference PROPBASIC

2»

Comments

  • Boy o boy, you did a good job of getting that across to me. Thank you...makes perfect sense now.
    'tvar1 still holds the original clock value and now we need the units so we logical AND the tvar1 with $0F  (0000_1111) leaving just the units'
    tvar1=tvar1 and $0f       'tvar1 now equals 0000_0010  (2)
    

    It was the "AND"ING" that was throwing me for a loop...easy to understand now...





  • Been doing good on the code writing using PROPBASIC. However, now, I keep getting this error, or failure, and I do not know what it means...any ideas from your propbasic coders...I do not know what the "Unresolved Symbol" means, as I am not using that symbol...__InitDirA

    Thank you..
    PropBasic Version 00.01.48 Aug 9, 2018
    Finished Compile. 612 Lines Read, 2340 Lines Generated,  0 Warnings, 0 Errors.
    
    Brads Spin Tool Compiler v0.15.3 - Copyright 2008,2009 All rights reserved
    Compiled for i386 Win32 at 08:17:48 on 2009/07/20
    Loading Object TEMPERATURE_TEST
    Loading Object LCD_1.spin
    
    LCD_1.spin(10,38) Error : Unresolved Symbol - __InitDirA
    
  • Never mind, everyone...found the issue. I accidently removed the "ENDTASK" at the end of the LCD_1 COG...
    Thank you, never the less...
  • JonnyMacJonnyMac Posts: 7,118
    edited 2020-11-01 - 22:14:42
    I haven't used PropBASIC in ages, so do test this before deploying it. With the P1, I try to avoid * and / when I can -- which, of course, is not always possible. That said, when you understand the internal mechanics of PropBASIC you can help yourself write really efficient code. What I always appreciated about PropBASIC is that the Spin listing shows you the conversion of BASIC to PASM and you can learn from it (this is not the case with all compilers).

    As has been pointed out, converting BCD to Decimal is pretty easy: Take the upper nibble, multiply that by 10, then add to the lower nibble. Here's an attempt to do that without using * which is slow and takes a lot of code. We can always do this, but when we can it's worth doing.

    Fixed: Needs to be a FUNC to return a value
    ' Use: d = BCD2DEC bcdval
    
    FUNC BCD2DEC
    
      __param2 = __param1                           ' make a copy bcd
      __param2 = __param2 >> 4                      ' get upper nibble (10s)
      __param3 = __param2                           ' make copy of upper nibble               
      __param3 = __param3 << 3                      ' x  8
      __param2 = __param2 << 1                      ' x  2
      __param2 = __param2 + __param3                ' x 10
      __param1 = __param1 & $0F                     ' isolate lower nibble (1s)
      __param1 = __param1 + param2                  ' decimal return value
      
      ENDFUNC
    
  • Jon, thank you for your input. Silly question, I guess, but what does "param" stand for.

    And, then another question for anyone..how many "LONGS" are totally available to use in the propeller...see below
    PropBasic Version 00.01.48 Aug 9, 2018
    
    Finished Compile. 723 Lines Read, 3019 Lines Generated,  0 Warnings, 0 Errors.
    
    Brads Spin Tool Compiler v0.15.3 - Copyright 2008,2009 All rights reserved
    Compiled for i386 Win32 at 08:17:48 on 2009/07/20
    Loading Object TEMPERATURE_TEST
    Loading Object LCD_1.spin
    Loading Object temperature_measure.spin
    Loading Object push_button.s
    pin
    Loading Object time_date.spin
    Program size is 11052 longs
    Compiled 3337 Lines of Code in 0.328 Seconds
    




  • denno wrote: »
    Jon, thank you for your input. Silly question, I guess, but what does "param" stand for.

    And, then another question for anyone..how many "LONGS" are totally available to use in the propeller...see below

    32768 bytes / 4 = 8192 longs.

    It must be noted that BSTC actually reports used bytes instead of longs for some reason. So you're only really using 2763 longs.
  • JonnyMacJonnyMac Posts: 7,118
    edited 2020-11-01 - 23:15:24
    Jon, thank you for your input. Silly question, I guess, but what does "param" stand for.
    Parameter. If you look at the Spin code created by PropBASIC you'll see a section like this (note, this is from an old listing).
    __remainder
    __temp1          RES 1
    __temp2          RES 1
    __temp3          RES 1
    __temp4          RES 1
    __temp5          RES 1
    __param1         RES 1
    __param2         RES 1
    __param3         RES 1
    __param4         RES 1
    __paramcnt       RES 1
    delay            RES 1
    
    The __temp variables are what the compiler uses for intermediate calculations, and the __param variables are for passing things to and from subroutines and functions. Since the BCD value is being passed to the function in __param1, I just used the __param variables, making sure that the final result lands in __param1 which is the variable used for returning values.

    What I appreciate about PropBASIC is that you can look into the generated Spin file and see how the BASIC code is translated to PASM. You can learn from that, and then create your own PASM functions like I did here. When Terry and I work on SX/B I was able to make after-test tweak to the SX assembly and then test. When things worked better I would feed them back to Terry for incorporation into the compiler. While I never used PropBASIC for anything but play, I created several commercial projects with SX/B.

    Long term, you can write PASM directly when needed for critical code. Obviously, this code isn't tricky, which makes it easy to learn from. Using PropBASIC's internal variables you could do something like this:
    FUNC BCD2DEC
    
      ASM
                    mov       __temp1, __param1                     ' make a copy of bcd
                    shr       __temp1, #4                           ' get upper nibble (10s)
                    mov       __temp2, __temp1                      ' copy upper nibble
                    shl       __temp2, #3                           ' x  8
                    shl       __temp1, #1                           ' x  2                       
                    add       __temp1, __temp2                      ' x 10                       
                    and       __param1, #$0F                        ' isolate lower nibble (1s)  
                    add       __param1, __temp1                     ' decimal return value       
      ENDASM
      ENDFUNC
    
    As long as your code works and you're happy, that's all that matters. I really like adding little snippets of PASM to code. You can do that with PropBASIC if you want, and I do it all the time with Spin2. In fact, I tested the above assembly code in Spin2 since I could do it inline without launching a cog.

  • Once again Jon, and all, thank you for your guide and help.

    I have said in past forums, I have been using the Basic Stamp, and PBASIC since they first came out. Yes even the BS1. I still have a dozen BS2sx's running in various duties on the boat. With the advent of the PROPELLER with 8 cogs, that has made a big difference in home programming and hobby. The development of the FLIP and now the PROPMINI, for embedded use, is by far better then anything from Arduino....my thoughts....especially with Beans PROPBASIC.

    Thanks Parallax...keep up the good work..!

  • :+1:

    Fellow PropBasic fan here but I refer to it as HLP (high-level PASM)

    Exciting times in the Propeller world and now we have FlexBASIC as well :smile:
Sign In or Register to comment.