Shop OBEX P1 Docs P2 Docs Learn Events
[puzzle] Escape — Parallax Forums

[puzzle] Escape

kuronekokuroneko Posts: 3,623
edited 2010-09-14 16:53 in Propeller 1
Given the listed code fragment, you have 4 longs (code, no data) to execute the instructions at pick and exit. After executing exit the task is done so you can safely execute the cogstop. Further limitations:
  • the red coloured instructions are read-only and can't be changed
  • cnt's shadow register is read-only (add cnt, #n|reg & Co are therefore invalid)
  • the blue instructions are an example, they are unknown to you for the purpose of this exercise
Once a solution is found, reduce the code space to 3 longs and do it again. If that's too easy, consider pick and exit non-relocatable.
DAT             org     0

escape          [COLOR="Red"]cogid   cnt[/COLOR]

                nop                             ' |
                [COLOR="DarkOrange"]nop[/COLOR]                             ' |
                [COLOR="DarkOrange"]nop[/COLOR]                             ' |
                [COLOR="DarkOrange"]nop[/COLOR]                             ' | your code here
                
                [COLOR="Red"]cogstop cnt[/COLOR]

pick            [COLOR="Blue"]mov     par, #42[/COLOR]

                [COLOR="Red"]cogstop cnt[/COLOR]

exit            [COLOR="Blue"]wrlong  par, par[/COLOR]

                [COLOR="Red"]cogstop cnt[/COLOR]

                fit

Comments

  • Andrey DemenevAndrey Demenev Posts: 377
    edited 2010-09-14 01:53
    DAT             org     0
    
    escape          cogid   cnt
                    mov     :i1, pick
    :i1             movs    :i2, #exit
    :i2             jmp     #:i1
                    cogstop cnt
    pick            mov     par, #42
                    cogstop cnt
    exit            wrlong  par, par
                    cogstop cnt
                    fit
    

    OR
    DAT             org     0
    
    escape          cogid   cnt
                    mov     :i1, pick
    :i1             mov     :i2, exit
    :i2             jmp     #:i1
                    cogstop cnt
    pick            mov     par, #42
                    cogstop cnt
    exit            wrlong  par, par
                    cogstop cnt
                    fit
    
  • tonyp12tonyp12 Posts: 1,951
    edited 2010-09-14 06:27
    DAT             org     0
    
    escape          cogid   cnt
    
                    mov newcode, pick
                    nop
    newcode         nop
                    jmp #exit
                    cogstop cnt
    
    pick            mov     par, #42
                    cogstop cnt
    exit            wrlong  par, par
                    cogstop cnt
                    fit
    
  • kuronekokuroneko Posts: 3,623
    edited 2010-09-14 16:53
    • A further - third party - restriction for the 3 long case: only use one mov[dis] instruction.
    • And don't forget the non-relocatable case I added to the OP.
Sign In or Register to comment.