Did this DAT get defined as bytes ? ?
Don Pomplun
Posts: 116
Here was a hair puller! chkForCmd is supposed to cycle thru the cmdTable in the DAT block looking for a match. Worked in my old monolithic code, as in #2 below. In my new code I thought I had the same thing in #1 and added a comment so I could understand it in the future. But I was getting twice as many scans as I expected, and never got matches. When I put the label on the same line as the first definition, everything got fixed.
My guess is that by not defining data on the label line,it treated the whole thing as bytes. Correct?, or something more subtle/else?
TIA
Don
My guess is that by not defining data on the label line,it treated the whole thing as bytes. Correct?, or something more subtle/else?
TIA
Don
PRI chkForCmd( cmd ) | i i := 0 repeat if cmd == cmdTable[i] return cmdTable[i+1] i+=2 until cmdTable[i] == 0 ' end of table return 0 ' means command not found DAT ' #1 ' This table doesn't work right cmdTable ' format is cmd number, and number of pounds word 1, 2 ' OFF cmd, requires 2 #'s word 3, 2 ' ON cmd, requires 2 #'s word 0,0 ' *********** ALWAYS LAST IN LIST so loop can detect the end DAT ' #2 ' putting the label on the first data line fixes the problem ' format is cmd number, and number of pounds cmdTable word 1, 2 ' OFF cmd, requires 2 #'s word 3, 2 ' ON cmd, requires 2 #'s word 0,0 ' *********** ALWAYS LAST IN LIST so loop can detect the end
Comments
So, your reference cmdTable is just retrieving bytes, not words.
You could have just specified cmdTable to be a word like this:
cmdTable word 'this is a word table
Kye mentioned "a fix in Spin" -- a reference, please.
Interestingly, in the DAT section (p.208) it seems to say in:
<Symbol> Alignment <Size> <Data> that you could have a line like:
table byte word 12345 that would define "table" as byte aligned words. Is this a misprint, since I see no examples specifying both alignment & size?
You can also do stuff like this:
mytable byte word $1001, $2002, $3003
That will create words that aren't necessarily aligned, which can be useful if they are mixed in with bytes (such as a lookup table of keywords with embedded pointers).
Now if I can remember the Lessons Learned next time the issue comes up.
I still tend to use PICs because it's hard to find projects worthy of 8 processors. Aand, of course a PIC is only a couple bucks.
Don