[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Twos complement subtraction



On Mar 22, 4:17 am, roughana <andrew.roug...@writeme.com> wrote:
> I have a situation where I am modifying existing code that uses twos
> complement subtraction in 65816 assembly.
>
> Here's the original code:
>
> TYA ; Length in Y
> EOR #-1
> SEC
> ADC :PTRlength ;ZP address
> STA :PTRlength ;ZPaddress
>
> Now it turns out that we need to subtract one more than the length in
> Y.
> Here's one solution:
>
> TYA
> INC
> EOR #-1
> SEC
> ADC :PTRlength ;ZP address
> STA :PTRlength ;ZPaddress
>
> and a second solution which is less cycles. But will this do the trick
> in all cases?
>
> TYA
> EOR #-1
> CLC
> ADC :PTRlength ;ZP address
> STA :PTRlength ;ZPaddress
>
> I stepped through it and the second one worked with the case I tried.
> Both resulted in carry set at the end.
>


Here's another if you want the carry to be clear

TYA
SEC
SBC PTRlength
EOR #-1
STA PTRlength

Rob

Allowing Applesoft to play with the big boys