Shop OBEX P1 Docs P2 Docs Learn Events
SX memory page issue — Parallax Forums

SX memory page issue

matrixoperatormatrixoperator Posts: 8
edited 2007-11-26 23:23 in General Discussion
I'm trying to implement a 256 element lookup table in assembly on an SX28.
The subroutine starts on the send page of memory $200. The main program that calls the routine is on the first page of memory. Everything works fine until the subroutine is called with a value in the 'w' register that has the routine jump to the table element stored at $300 or greater. I thought that the range of the second page is from $200-$3ff so I should not expect any problems with page references. Is there something inherently wrong with this approach. Attached is the code below.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
reality is still analog
130B

Comments

  • BeanBean Posts: 8,129
    edited 2007-11-26 20:36
    Bit 9 of PC is cleared by the "JMP PC+W" instruction. So the destination must be within the first 256 words of any 512 word page.

    This is noted in the "SX Instruction Set" tables in the manual.

    If you locate the "JMP PC+W" at a page boundary ($200, $400, etc), you can have at most 255 RETW #xx entries.

    You might want to use the IREAD instruction instead.

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com

    ·
  • matrixoperatormatrixoperator Posts: 8
    edited 2007-11-26 21:17
    I figured that problem would be obvious to someone, ... I just didn't know that it would be obvious to me if I had opened a book.

    Thanks for the help.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    reality is still analog
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2007-11-26 23:23
    You actually can build a lookup-table with 256 items. The trick is to get the "jmp pc+w" instruction out of the page with the table as it "steals" you the one word for the 256th item:

    Place a subroutine code like

    ReadTable
    page Table
    jmp w

    into any code page, and place 256 RETIW n instructions into another page, (called "Table" here), and - voila - you may call ReadTable with w holding any value from 0 to 255, i.e. with 256 different values.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Greetings from Germany,

    G
Sign In or Register to comment.