[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Twos complement subtraction
On Mar 25, 6:02 am, roughana <andrew.roug...@writeme.com> wrote:
> Thanks for all the responses.
>
> There was no comment on the length of string that would be supported
> by these solutions, so I assume that my hypothesis of 127 maximum
> length is correct even with the use of CLC as Michael Mahon
> encouraged.
>
> Regards,
> Andrew
The two's complement should not affect you in any way. You will still
get a value of 0-255 ($0-$FF) for your P-string length. Two's
complement is just a way to calculate negative numbers but only if you
need to use the value of your calculation as a negative number. In
line 305, a CLC is used instead of SEC for normal subtraction. But
this is needed to offset the use of Two's complement subtraction
2'S COMPLEMENT
300: A0 00 LDY #00
302: 98 TYA
303: 49 FF EOR #FF
305: 18 CLC
306: E5 08 SBC 08
308: 20 DA FD JSR FDDA
30B: A9 A0 LDA #A0
30D: 20 ED FD JSR FDED
310: 20 ED FD JSR FDED
313: C8 INY
314: D0 EC BNE 302
316: 60 RTS
RESULT:
FF FE FD FC FB FA F9 F8 F7 F6.... all the way down to 00
REGULAR SUBTRACTION
318: A0 00 LDY #00
31A: 84 08 STY 08
31C: 38 SEC
31D: A5 06 LDA 06
31F: E5 08 SBC 08
321: 20 DA FD JSR FDDA
324: A9 A0 LDA #A0
326: 20 ED FD JSR FDED
329: 20 ED FD JSR FDED
32C: C8 INY
32D: D0 EB BNE 314
32F: 60 RTS
RESULT:
FF FE FD FC FB FA F9 F8 F7 F6 .... all the way down to 00
It is just in the math, but the result is the same.
And the Two's complement saves the use of a zero page location.
In summation, the P-string ptr should be exactly the same length of
0-255
Rob