Shop OBEX P1 Docs P2 Docs Learn Events
Count My SPIN — Parallax Forums

Count My SPIN

HumanoidoHumanoido Posts: 5,770
edited 2010-09-19 10:52 in Propeller 1
How to make a tiny spin program (at the top of the code) count the number of spin instructions automatically between two points in the middle of the code?

Comments

  • Heater.Heater. Posts: 21,230
    edited 2010-09-19 03:49
    Easy:

    1) Put some "special" markers at the beginning and end of the Spin code sequence you want to measure the length of.

    2) Then put a loop at the top of your Spin that searches all of HUB RAM for those special markers.

    3) Take the difference between the found addresses of the markers and you have your Spin byte code sequence length.

    No time to make a working example for you but here is how the markers might look:
    PUB start | begin, end, a, b, c, d, e, f
     'Put loop here to search HUB RAM for
     'the location of LONGS containing $DEADBEEF and $BEEFDEAD
     'in HUB RAM and the the byte code length is the difference
    'between the addresses found minus a little bit.
    
     a := 1
     b := 2
     begin := $DEADBEEF
     c := 3   'Measure size of code btween begine and end
     d := 4
     end := $BEEFDEAD
     e := 5
     f := 6
    
    When compiled this looks like:
    7                       a := 1
    Addr : 0018:             36  : Constant 2 $00000001
    Addr : 0019:             6D  : Variable Operation Local Offset - 3 Write
    8                       b := 2
    Addr : 001A:          37 00  : Constant Mask Y=0 00000002 2
    Addr : 001C:             71  : Variable Operation Local Offset - 4 Write
    9                       begin := $DEADBEEF
    Addr : 001D: 3B DE AD BE EF  : Constant 4 Bytes - DE AD BE EF - $DEADBEEF 3735928559
    Addr : 0022:             65  : Variable Operation Local Offset - 1 Write
    10                       c := 3   'Measeure size of code btween begine and end
    Addr : 0023:          37 21  : Constant Mask Y=33 Decrement 00000003 3
    Addr : 0025:             75  : Variable Operation Local Offset - 5 Write
    11                       d := 4
    Addr : 0026:          37 01  : Constant Mask Y=1 00000004 4
    Addr : 0028:             79  : Variable Operation Local Offset - 6 Write
    12                       end := $BEEFDEAD
    Addr : 0029: 3B BE EF DE AD  : Constant 4 Bytes - BE EF DE AD - $BEEFDEAD 3203391149
    Addr : 002E:             69  : Variable Operation Local Offset - 2 Write
    13                       e := 5
    Addr : 002F:          38 05  : Constant 1 Bytes - 05 - $00000005 5
    Addr : 0031:             7D  : Variable Operation Local Offset - 7 Write
    14                       f := 6
    Addr : 0032:          38 06  : Constant 1 Bytes - 06 - $00000006 6
    Addr : 0034:          CD 20  : Memory Op Long DBASE + WRITE Address = 0020
    Addr : 0036:             32  : Return        
    
    
    In the BST listing. You can see how those "marker" vlues are siting the code waiting to be found.

    Of course this might fail if your code uses the marker values as well.
  • Heater.Heater. Posts: 21,230
    edited 2010-09-19 04:04
    In case anyone is wondering:

    No, I did not put five starts on this thread. I don't consider my byte code counting technique that clever.

    I doubt anyone else has voted on this thread yet either.

    There is a bug in the star rating system that apparently is known about and will be fixed at some point. See the support forum.
  • HumanoidoHumanoido Posts: 5,770
    edited 2010-09-19 05:33
    I read that Spin uses tokens, somewhat like the Stamp. Can we just count the instruction tokens to get the total number?
  • Heater.Heater. Posts: 21,230
    edited 2010-09-19 06:03
    If you know where the tokens (byte codes) are.
    That's what my sugestion does, it finds the tokens and counts them.
  • HumanoidoHumanoido Posts: 5,770
    edited 2010-09-19 08:33
    Heater. wrote: »
    If you know where the tokens (byte codes) are.
    That's what my sugestion does, it finds the tokens and counts them.
    Heater, any idea on how to invoke it automatically as part of a program without the human intervention part? Thanks sincerely.
  • Heater.Heater. Posts: 21,230
    edited 2010-09-19 08:56
    That code that i sugest looks for your start and end markers is sitting in yor program. Why would it not run automatically? It just needs haccess to a serial output to show the results.
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-09-19 10:52
    Humanoido: Just use bst or homespun and use the listing option and you can count them.

    However, if you want to count actual instructions (spin or pasm) used, you can use my zero-footprint debugger. It does not have breakpoints but it does count both.
Sign In or Register to comment.