[RESOLVED] IF_NZ pickle
Mightor
Posts: 338
Hey peeps,
I'm in a bit of a pickle but I am pretty sure this has happened to some of you before. I have the following bit of code:
If you look at the last line you'll see that is also preceded by an IF_NZ, however, I cannot guarantee that the multiply routine does not set the Z flag. In fact, there's a really good chance it is. So.... how do I allow the last mov command to be conditional like the rest?
Gr,
Mightor
Here's the multiply routine for clarity:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
| To know recursion, you must first know recursion.
| I'm afraid I might be phobophobic.
Post Edited (Mightor) : 9/9/2007 7:45:20 PM GMT
I'm in a bit of a pickle but I am pretty sure this has happened to some of you before. I have the following bit of code:
[img]http://forums.parallax.com/images/smilies/tongue.gif[/img]wmloop mov dutyold, duty1 rdlong duty1, dc1Addr ' get an up to date duty cycle % for motor 1 cmp dutyold, duty1 wz ' If Z is set then they're different, so recalculate IF_NZ mov multiplicand, pwmfbase IF_NZ mov multiplier, duty1 IF_NZ jmpret multiply_ret, #multiply IF_NZ mov pulsewidth1, product
If you look at the last line you'll see that is also preceded by an IF_NZ, however, I cannot guarantee that the multiply routine does not set the Z flag. In fact, there's a really good chance it is. So.... how do I allow the last mov command to be conditional like the rest?
Gr,
Mightor
Here's the multiply routine for clarity:
'********************************************************** ' ' Multiply two factors, product may not exceed 32 bit ' multiply ' Check if multiplier > multiplicand, if so, switch them around cmp multiplier, multiplicand wc, wz IF_A mov product, multiplier IF_A mov multiplier, multiplicand IF_A mov multiplicand, product mov product, #0 ' Always clear product in case we run this twice :multiply_loop shr multiplier , #1 wc, wz ' Shift multiplier right by one if_c add product, multiplicand ' If C =1, add multiplicand to product shl multiplicand, #1 ' Shift multiplicand left by 1 if_nz jmp #:multiply_loop ' Loop, but only if there are digits left in multiplier :multiply_ret jmp multiply_ret
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
| To know recursion, you must first know recursion.
| I'm afraid I might be phobophobic.
Post Edited (Mightor) : 9/9/2007 7:45:20 PM GMT
Comments
If 'multiply' is only called here ( or Z on return doesn't matter other times it's called ), you could always have it clear the Z flag before return.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness!
I think the save and restore is going to make my code more complicated than it has to be. I'm only just starting out with ASM, so I want to keep it as simple as I can. Thanks for the suggestion though [noparse]:)[/noparse]
Gr,
Mightor
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
| To know recursion, you must first know recursion.
| I'm afraid I might be phobophobic.
It shows to me again:
There are different coding styles with different kinds of processors.
The answers given by Hippy and Potatohead are the "classical" answers from other processors:
- jump over the code
- push/pop flags
Interestingly both techniques are in many cases not the best ones for the Prop:
It has no push/pop but conditional instructions need no extra space (though time!)
I think Mightor's decision is not only the most conservative, but also the clearest one in this situation