I've run into a situation where knowing if I've wrapped from $ff to $00 or $00 to $ff would be convenient. I need to know this in both directions; in other words regardless of whether I add a positive or negative 8 bit number to another 8 bit number.
It seems I can test for whether a negative OR a carry was generated; however this can happen passing from 127 to -128 and vice versa---BUT, since that generates an overflow flag, I can test that first, and if no overflow was generated then I can test for negative or carry. So I came up with this:
;some arithmetic I'm interested in testing for wraparound
lda #$00
clc
adc #$ff
;the wraparound test
;if overflow is set, we passed the 127 to -128 boundary so we know ;wraparound did not occur
bvs skipWraparoundLogic
;get processor status
php
pla
;test for negative or carry bit at the same time
and #$81
;if neither happened wraparound did not occur
beq skipWraparoundLogic
;here is where I do something because wraparound happened
skipWraparoundLogic:
Is there a simpler way to do this?
It seems I can test for whether a negative OR a carry was generated; however this can happen passing from 127 to -128 and vice versa---BUT, since that generates an overflow flag, I can test that first, and if no overflow was generated then I can test for negative or carry. So I came up with this:
Code:
;some arithmetic I'm interested in testing for wraparound
lda #$00
clc
adc #$ff
;the wraparound test
;if overflow is set, we passed the 127 to -128 boundary so we know ;wraparound did not occur
bvs skipWraparoundLogic
;get processor status
php
pla
;test for negative or carry bit at the same time
and #$81
;if neither happened wraparound did not occur
beq skipWraparoundLogic
;here is where I do something because wraparound happened
skipWraparoundLogic:
Is there a simpler way to do this?