IGNORED

# subtraction problem

## Recommended Posts

i have a ram location (wchman_L) that holds the low byte of a pointer to a graphic

if that pointer is pointing to a certain graphic (#

this works fine:

```lda wchman_L

sec

sbc #<MAN4_L

beq reset```

but this does not:

```lda #<MAN4_L

sec

sbc wchman_L

beq reset```

why?

##### Share on other sites

the difference was the state that it left the carry in.

i got it.

##### Share on other sites

I don't understand...why not just use CMP?

```lda wchman_L

cmp #<MAN4_L

beq reset

```

...and you'll save a byte+2 cycles

##### Share on other sites

I don't understand...why not just use CMP?

```lda wchman_L

cmp #<MAN4_L

beq reset

```

...and you'll save a byte+2 cycles

Perhaps because the algorithm is something like this ...

```
lda wchman_L

sec

sbc #<MAN4_L

beq reset

asl

tay

lda Location,y

.

.

blah

```

You never know.

##### Share on other sites

• 2 weeks later...

in my case Nukey is right, thanks.

but i don't understand why my original two cases gave different behavior.

how could they leave the carry in different states?

Edited by antron
##### Share on other sites

basic math : subtraction isn't commutative.

##### Share on other sites

basic math : subtraction isn't commutative.
Yeah, but if you are testing for equality it doesn't matter.

If A==B, A-B==B-A==0

If A!=B, A-B!=0 and B-A!=0 even though A-B!=B-A

##### Share on other sites

in my case he is right' date=' thanks.

but i don't understand why my original two cases gave different behavior.

how could they leave the carry in different states?[/quote']

if #

This is because after a sbc the carry is cleared if the subtraction needed a borrow (i.e., if the result is negative, assuming unsigned numbers) and the carry will be set if the subtraction didn't need a borrow.

In other words,

If A > B, then A - B will leave the carry set, but B - A will clear the carry.

and here:http://www.geocities.com/oneelkruns/asm1step.html

##### Share on other sites

makes sense now.

it is the case when they were not equal that things went wrong.

thanks all.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.