Shop OBEX P1 Docs P2 Docs Learn Events
How to write LUT Exec assembly code? — Parallax Forums

How to write LUT Exec assembly code?

Maybe I forgot, but how does one write assembly code for LUT exec that PNut can load?

I've got one cog that is full and had to move code to HUB for hubexec.
That's all good and straightforward, but maybe LUT exec code would be faster...

Comments

  • cgraceycgracey Posts: 14,133
    Just ORG it at $200 and move it into the lut at runtime using SETQ2+RDLONG.
  • RaymanRayman Posts: 13,805
    edited 2017-01-21 18:06
    Thanks. That sounds simple enough...

    Can I still use "fit" for the cog code?
    I.e., can I put the org $200 after fit $1f5 ?
  • cgraceycgracey Posts: 14,133
    Rayman wrote: »
    Thanks. That sounds simple enough...

    Can I still use "fit" for the cog code?
    I.e., can I put the org $200 after fit $1f5 ?

    Yes. And you can put another fit, like $300, if you want to limit your code to the first half of the lut. Just do a JMP $200 (or, to your label) to execute it.
  • RaymanRayman Posts: 13,805
    Ok, I just got around to trying this...

    This loads LUT:
    'copy in LUT exec code
                  setq2     #512-1
                  rdlong    0,##@MainLutExecCode
    

    And the code goes here:
    DAT 'Main LUT exec code
    org     $200
    MainLutExecCode
    
    
                  fit       $3FF
    

    Interestingly, this appears to work even if LUT code is above or below $400.

    This is nice. I also like how I can copy this code to hubexec area like this:
    DAT 'Main Hubexec code
                  orgh
                  'org
    

    Not sure why, but using "org" here breaks it.

    I've also found that self-modifying code doesn't work in either LUT or HUB areas. Obvious, I suppose.




  • Yes, the self modify happens in COG registers.

    When in LUT and HUB, it's necessary to think of the COG memory as a bunch of registers.

    When in COG, the code is in the registers, which makes the self modify possible and practical.

    I personally shift gears, from a memory to memory model (COG), to a more traditional load, store model (HUB, LUT)

Sign In or Register to comment.