Assembly Variable Unable to Increment
Jamesx
Posts: 132
Assembly Experts:
I am stumped again. This time by why I cannot properly increment a variable except in very special circumstances. It the code below, there is a variable "t2" that is incremented and tested. When it gets to 5 the program goes into an endless loop. (Along the way t2 is printed out so I can see what is happening.) The code below works as expected: it loops through Main_Loop 5 times and stops.
BUT, if the "mov t2, #0" line is put back in at the top of the program, t2 never gets past 1, and the program stays in Main_loop instead of falling out into the test_5 loop.
My question is: Why does it make a difference whether or not the "mov t2, #0" is used???
For reference, I also tried it with t2 declared with the "res" command, and get the same thing. Also for reference in the code below, DVALID is a signal line from an A-D part, that goes high at 512 Hz.
Thanks,
Jim C
I am stumped again. This time by why I cannot properly increment a variable except in very special circumstances. It the code below, there is a variable "t2" that is incremented and tested. When it gets to 5 the program goes into an endless loop. (Along the way t2 is printed out so I can see what is happening.) The code below works as expected: it loops through Main_Loop 5 times and stops.
BUT, if the "mov t2, #0" line is put back in at the top of the program, t2 never gets past 1, and the program stays in Main_loop instead of falling out into the test_5 loop.
My question is: Why does it make a difference whether or not the "mov t2, #0" is used???
For reference, I also tried it with t2 declared with the "res" command, and get the same thing. Also for reference in the code below, DVALID is a signal line from an A-D part, that goes high at 512 Hz.
Thanks,
Jim C
DAT 'Initialize entry org '... ' mov t2, #0 '... Main_Loop test DVALID, ina wz if_nz jmp Main_Loop ' if Test zero, keep looping '... add t2, #1 '... cmp t2, #5 wc if_c jmp #Main_Loop test_5 nop jmp #test_5 '... t2 long 0 't2 res 1
Comments
you did "entry org"
where you should be doing
The weird org causes your jumps to be offset in an unforunate manner, which causes the JMP mainloop thing to branch back to the mov
instruction rather than the test one.
Thanks for your idea. I made the change you suggested, but unfortunately, the problem persists. Below is code that does not work unless the "mov t2, #0" line is commented out. (See the first post in this thread for full explanation of problem)
Any other possibilities you can think of?
Jim C
Attached is the whole file. It may be a little confusing because it fits into a larger program that calls it.
There is really no way for another cog to be stepping on t2 as far as I can tell. But there may be something in the attached program that I am missing.
Thanks,
Jim C
Thanks
OK. After much work, I have condensed the problem into something easier to digest. It's the same question as noted above, only the code has been shrunken greatly.
Start in the object Test_2. In that, you will notice a variable t22. This variable is correctly incremented only you do not include the "MOV T22, #0" statement at the top of the object. In that case, the output is 1 2 3 4 . If this statement is included, the output shows 0 1 2 0 1 2 0 1 2 0 1 2........... So the question is, how does including the MOV statement screw up the incrementing of T22?
There is a "clocks" object also required to create this wierd behavior. It creates a signal of approx 1 Khz, and the Test_2 object waits for this signal before it increments T22.
Any ideas are welcome.
Jim C