[resolved][puzzle] tight spot
kuroneko
Posts: 3,623
The (broken) code fragment below is from a VGA renderer, the first N-1 back porch lines need carry clear while the last one requires carry to be set (as an extra parameter so to speak).
'----------------------------------------------- [COLOR="orange"]mov ecnt, #29 -1[/COLOR] [COLOR="orange"]call #blank[/COLOR] ' back porch [COLOR="orange"]djnz ecnt, #$-1[/COLOR] [COLOR="blue"]call #blank[/COLOR] ' last blank line done manually '----------------------------------------------- blank ... blank_ret retThe entry condition for the fragment is carry clear, the blank subroutine returns with carry clear. How can the objective be achieved by only changing code between the lines but not adding extra instructions and/or data? Extra points for keeping the total runtime to a minimum.
Comments
But I can't quite get it to work... preventing the final jmp from happening more than once is the issue.
-Phil
-Phil
-Phil
Yeah, I know that. The question is what gets compared with the contents of the return statement in the case of a non-immediate jmpret: the 9-bit literal in the jmpret instruction or the value fetched from the address it points to? I'm betting the latter, since that's the "source" value, not the 9-bit value encoded in the instruction itself.
-Phil
@kwinn, that won't work because the C flag is set only if the count is -1.
BTW, kwinn, if there were an ijnz instruction, your method would work, since incrementing from -1 to zero would cause an unsigned carry.
-Phil
Strictly speaking that's incorrect. The comparison is between destination and source operand. The latter is not always the same as the jump target.
-Phil
Nice one! I like it!
-Phil
After shifting out the first 1 (into carry flag, thus calling with carry) the next shift leaves register zero, terminating loop