antron Posted January 14, 2005 Share Posted January 14, 2005 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? Quote Link to comment Share on other sites More sharing options...
antron Posted January 14, 2005 Author Share Posted January 14, 2005 my bad the difference was the state that it left the carry in. i got it. Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted January 15, 2005 Share Posted January 15, 2005 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 Quote Link to comment Share on other sites More sharing options...
CPUWIZ Posted January 15, 2005 Share Posted January 15, 2005 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. Quote Link to comment Share on other sites More sharing options...
antron Posted January 28, 2005 Author Share Posted January 28, 2005 (edited) 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 May 11, 2005 by antron Quote Link to comment Share on other sites More sharing options...
Tom Posted January 28, 2005 Share Posted January 28, 2005 basic math : subtraction isn't commutative. Quote Link to comment Share on other sites More sharing options...
vdub_bobby Posted January 28, 2005 Share Posted January 28, 2005 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 Quote Link to comment Share on other sites More sharing options...
vdub_bobby Posted January 28, 2005 Share Posted January 28, 2005 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. See here: http://www.6502.org/tutorials/6502opcodes.htm#SBC and here:http://www.geocities.com/oneelkruns/asm1step.html Quote Link to comment Share on other sites More sharing options...
antron Posted January 28, 2005 Author Share Posted January 28, 2005 makes sense now. it is the case when they were not equal that things went wrong. thanks all. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.