Shop OBEX P1 Docs P2 Docs Learn Events
Assembly - deSilva examples — Parallax Forums

Assembly - deSilva examples

Brian_BBrian_B Posts: 842
edited 2010-03-26 23:19 in Propeller 1
I know this question has probaly been asked ,maybe even by me. In this example code does does the value of pattern stop and reset at 255 or does it fill the whole 32 bits. If it does keep counting how would you stop it at 255 and restart at 0.




Brian


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔





"Imagination is more important than knowledge..." Albert Einstein

Comments

  • Graham StablerGraham Stabler Posts: 2,510
    edited 2010-03-26 13:34
    Pattern would go all the way up to FFFF_FFFF and then loop around again but you would only see the first 8 bits on OUTA because of the way DIRA was set up. To make it only go up to 255 you could replace the jmp with a djnz command using another variable initialized with 255 as a counter. Or you could do a cmp with pattern and make the jmp conditional based on the flags set.

            cmp  pattern,#255  wc
    if_c   jmp   #loop                         ' if pattern < 255
            mov  pattern,#0                ' Else reset pattern
            jmp   #loop
    
    



    Something like that
  • kuronekokuroneko Posts: 3,623
    edited 2010-03-26 14:15
    Alternatively you could perform the equivalent of outa := $FF & count++ (in an endless loop).

    Post Edited (kuroneko) : 3/26/2010 2:20:32 PM GMT
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2010-03-26 22:45
    I guess that was a subtle point of the example, although the counter might go to 32 bits the 8 bit pattern would still repeat as it did so. A simpler example: if we imagine the prop was only 4 bit then the pattern would do this:

    0000
    0001
    0010
    0011
    0100
    0101
    0110
    0111
    1000
    1001
    1010
    1011
    1100
    1101
    1110
    1111
    and repeat

    But notice that if only the first two bits were output you would still get 0 1 2 3 0 1 2 3 0 1 2 3 .... output on the pins

    If you wanted to use other pins at the same time then you could not use desilva or kurenko's methods (which are equivalent I think because the dira register acts like the & $FF).

    You could do outa ^= ((outa & $FF) ^ ($FF & pattern++))

    The xor in the brackets acts to indicate which bits in the first byte of outa need to be toggled, the ^= does the toggling.

    Graham

    Post Edited (Graham Stabler) : 3/26/2010 10:53:54 PM GMT
  • Brian_BBrian_B Posts: 842
    edited 2010-03-26 22:58
    ok,
    So this is the part that always gets me, by moving pattern to outa (without the start over after 255) you are making all of outa's part of the 32 bit counting program (even thought anything above pin7 has not been set to a output in the dira register).

    If you have another part of the program that uses pin 31-24 to count down how do you make sure that at some point that pattern is not interfering with pattern1.

    I know that you would never write a program this way ,but I'm try to wrap my brain around how to not get one part of the program interfering with another part.

    Brian

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔





    "Imagination is more important than knowledge..." Albert Einstein
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2010-03-26 23:03
    Brian_B said...

    If you have another part of the program that uses pin 31-24 to count down how do you make sure that at some point that pattern is not interfering with pattern1.


    That is what this does:

    outa ^= ((outa & $FF) ^ ($FF & pattern++))

    (outa & $FF) gives you the current state of the lowest 8 bits of outa
    ($FF & pattern) gives you the lowest 8 bits of pattern

    XORing them (^) gives you ones in the bits where they are different (but only in the low 8 bits)

    Then when you do outa ^= you toggle the bits of outa that you found to be different from the lowest 8 bits of pattern while not changing anything else. Write out your xor truth table if it is confusing.

    Graham
  • Brian_BBrian_B Posts: 842
    edited 2010-03-26 23:19
    Cool,
    That one has been bugging me for awhile now.

    Thanks everyone

    Brian

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔





    "Imagination is more important than knowledge..." Albert Einstein
Sign In or Register to comment.