Mightor

09-10-2007, 01:35 AM

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:

http://forums.parallax.com/images/smilies/tongue.gifwmloop 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

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:

http://forums.parallax.com/images/smilies/tongue.gifwmloop 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