Assembly - deSilva examples
Brian_B
Posts: 842
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
Brian
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"Imagination is more important than knowledge..." Albert Einstein
bmp
384K
Comments
Something like that
Post Edited (kuroneko) : 3/26/2010 2:20:32 PM GMT
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
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
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
That one has been bugging me for awhile now.
Thanks everyone
Brian
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"Imagination is more important than knowledge..." Albert Einstein