[resolved][puzzle] jumping counter
kuroneko
Posts: 3,623
Apologies if this is common knowledge but I just found out about it and share it anyway [noparse]:)[/noparse]
What's the result returned to the caller (through par) in the following code fragment and what label does it jump to (:_5, :_6 or :_7)?
For example, (%1000_0111 and :_7) would be a valid - but wrong - answer. Solution: label :_5, result $85. Who would have guessed [noparse]:)[/noparse]
Also, don't be scared about anything before jmp cnt. The reason for having this code in there is to make sure that the lower 9 bits of cnt are 0 or slightly higher but in a controlled range. A waitcnt vscl, #0 would have done the job just as well but depending on clock speed might take a while (therefore the imposed limit of 257..512).
Note: jmp cnt/phsx is confined to one of the jump targets :_5, :_6 or :_7, i.e. it doesn't go off into nowhere.
For people uncomfortable with waitcnt & Co here a version with ordinary counters. Functionality is the same.
Post Edited (kuroneko) : 12/9/2009 6:03:13 AM GMT
What's the result returned to the caller (through par) in the following code fragment and what label does it jump to (:_5, :_6 or :_7)?
For example, (%1000_0111 and :_7) would be a valid - but wrong - answer. Solution: label :_5, result $85. Who would have guessed [noparse]:)[/noparse]
Also, don't be scared about anything before jmp cnt. The reason for having this code in there is to make sure that the lower 9 bits of cnt are 0 or slightly higher but in a controlled range. A waitcnt vscl, #0 would have done the job just as well but depending on clock speed might take a while (therefore the imposed limit of 257..512).
Note: jmp cnt/phsx is confined to one of the jump targets :_5, :_6 or :_7, i.e. it doesn't go off into nowhere.
DAT org 0 start movd cnt, #2 ' get some room add cnt, cnt ' min 257 cycles andn cnt, #%111111111 ' max 512 cycles waitcnt cnt, #0 ' wait for $XXXXX(%xxx0)00 jmp cnt :_5 add outb, #%001 :_6 add outb, #%010 :_7 add outb, #%100 or outb, #%10000000 ' indicate result ready wrlong outb, par cogid cnt cogstop cnt fit
For people uncomfortable with waitcnt & Co here a version with ordinary counters. Functionality is the same.
DAT org 0 start movi ctra, #%0_11111_000 mov frqa, #1 mov phsa, #3 jmp phsa nop :_5 add outb, #%0001 :_6 add outb, #%0010 :_7 add outb, #%0100 or outb, #%10000000 wrlong outb, par cogid cnt cogstop cnt fit
Post Edited (kuroneko) : 12/9/2009 6:03:13 AM GMT
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)
· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
Once again, not to spoil it, answer attached.
So far, 2 views to my previous answer - one is kuroneko and one is me
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)
· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)
· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
Post Edited (kuroneko) : 12/7/2009 5:15:33 AM GMT
Then, Propfest tonight on the Gold Coast, Australia
But I do not want to know the answer. Only that it's wrong.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)
· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)
· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)
· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
Graham
There are some guesses here for the timing diagram.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)
· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
I think I just made a simple error (not really part of puzzle perhaps)
Graham
Graham
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)
· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
Bare in mind I was trying to do this from the datasheet without ever having seen the thread where this is a hot topic [noparse]:([/noparse] [noparse];)[/noparse]
Graham
Square one means learning boolean logic again? [noparse];)[/noparse] Nice teaser Kuroneko. Got any more?
The waitcnt (which means all waitxxx instructions) got me. Using the mov instructions was no problem to calculate since Chip disclosed how they work on the other thread.
However, I still need to get the waitxxx understood. I had thought that waitxxx took a minimum of 6 clocks because it causes a pipe flush but this just does not work as I expected. I will seek clarification from Chip.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)
· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
Anyway, there are only 7 possible answers left, any takers?
Post Edited (kuroneko) : 12/8/2009 12:50:56 PM GMT
Not to spoil it for anyone, But, even armed with all the info I would never have guessed the outcome.
I believe I have deduced the reason it works this way, together with the "unintended feature" and solution·· ·Remember, this example uses unintended functions/features of the prop.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)
· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)
· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
Whether you are using cnt, phsa, or whatever, the compiler sees this value as a constant... because cnt is always moving and your actually writing to a mask you must do a few strange things with the waitcnt before it syncs up to a value that works for you. ...And in the case with phsa... if you don't start ctra, the jump location becomes more predictable for you.
You could just as easily use a constant for the jump and just see how the jump really relates to where the PC (Program Counter) ends up executing the next instruction.
Example uses the Propeller DEMO board LEDs
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 12/9/2009 7:24:29 AM GMT