Shop OBEX P1 Docs P2 Docs Learn Events
Yet Another LMM Loop — Parallax Forums

Yet Another LMM Loop

lonesocklonesock Posts: 917
edited 2010-12-09 16:40 in Propeller 1
EDIT: Phil's been here, done this! Please ignore this thread.

Hi, All.

I was looking at Phil's reverse LMM loop, and trying to do something similar, but forward...can I get some eyes on this proposed solution?
                        ' get started by reading the 2nd long
                        rdlong  ptr, par
                        add     ptr, #4
                        jmp     #StartHere

                        ' my main LMM loop
LMM_fwd                 rdlong  Inst0, ptr
                        add     ptr, #9
Inst0                   nop
StartHere               rdlong  Inst1, ptr
Inst1                   nop
                        djnz    ptr, #LMM_fwd
In theory (or at least, "what I want"), if you pass in address 0 as the start address, the load sequence will be:
* load 4 into Inst1, but don't execute (self-modified code isn't changed till after the next instruction)
* load 3 (masked as 0) into Inst0, then execute
* load 12 into Inst 1, but execute the 4 that was stored there previously
* load 11 (masked as 8) into Inst0, and execute it
* load 20 into Inst1, but execute the 12 that was stored previously
* etc.

For jumps (changing ptr), you'd probably need to wipe Inst1 to a nop (set to #0), then resume at #StartHere.

What am I missing?

thanks,
Jonathan

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2010-12-09 16:02
                            ' get started by reading the 2nd long
                            rdlong  ptr, par
                            add     ptr, #4
                            jmp     #StartHere
    
                            ' my main LMM loop
    LMM_fwd                 rdlong  Inst0, ptr
                            add     ptr, #9
    Inst0                   nop
    StartHere               rdlong  Inst1, ptr
    Inst1                   nop
                            djnz    ptr, Inst0
    
    lonesock wrote: »
    What am I missing?

    This looks familiar, I've definitely seen this one before. Anyway, you probably also want
    djnz    ptr, [COLOR="red"]#LMM_fwd[/COLOR]
    
  • lonesocklonesock Posts: 917
    edited 2010-12-09 16:16
    Thanks, fixed the final djnz! If you can point me to the original, I'd love to look at it. I had only seen Phil's reversed version (which required the LMM code to be in a backwards order, if I understand it correctly). Of course, it certainly wouldn't be the first time I've "rediscovered" something (as with your counter-driven SPI in and out [8^)

    thanks,
    Jonathan
  • kuronekokuroneko Posts: 3,623
    edited 2010-12-09 16:27
    [thread=114938]Faster-LMM-Code-Not-reversed-this-time. (IMPORTANT-Addendum-in-Top-Post)[/thread]
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-12-09 16:28
    This is probably the post that Kuroneko remembered:

    -Phil

    Edit: Well, okay, he beat me to it. Here's a perfect example of where it would be nice to be able to delete a post.
  • lonesocklonesock Posts: 917
    edited 2010-12-09 16:40
    Got it, thanks, guys! (I kinda wish I could search for 3-letter acronyms in the forum, and delete threads!)

    OK, please disregard this post, except as a pointer to Phil's original ("Two thou shalt not count, except by way of counting three").

    thanks,
    Jonathan
Sign In or Register to comment.