Shop OBEX P1 Docs P2 Docs Learn Events
Using DJNZ with Array Element — Parallax Forums

Using DJNZ with Array Element

JDOhioJDOhio Posts: 72
edited 2007-03-28 02:06 in General Discussion
When I use DJNZ with an array element, the compiler throws an error.

MyArray  VAR  BYTE(2)
First    VAR  MyArray(0)
Second   VAR  MyArray(1)

DJNZ First,ALabel
INC Second
ALabel:





The compiler error is BYTE VARIABLE EXPECTED, and it is on the DJNZ line.

Any ideas?

Thanks,

Joe

Comments

  • JonnyMacJonnyMac Posts: 9,289
    edited 2007-03-27 02:17
    DNJZ expands directly to its Assembly counterpart so it's expecting a byte, not an array element that actually exists in another page. I think can get there from here by doing this:

      DEC first
      IF Z = 0 THEN A_Label
      INC second
    
    
    



    This allows the compiler to point to the array and your variable to be decremented. The Z flag is tested manually.
  • JDOhioJDOhio Posts: 72
    edited 2007-03-27 23:55
    Thanks! I was thinking the same thing. I asked the forum because the help file indicated that DJNZ would operate on byte array elements.

    Joe
  • JonnyMacJonnyMac Posts: 9,289
    edited 2007-03-28 00:24
    You're right -- it says that. I'll check with the compiler engineer to see if we need to fix the help file or update the compiler!
  • JDOhioJDOhio Posts: 72
    edited 2007-03-28 02:06
    Cool. Either way is good with me. If you update the compiler, it will probably compile to your previous post which may not have much benefit except the S/X BASIC looks cleaner.

    Joe
Sign In or Register to comment.