Code: Select all
lda #$68
cmp #$F0
bmi +
(Blah code)
+
Moderator: Moderators
Code: Select all
lda #$68
cmp #$F0
bmi +
(Blah code)
+
Same here. I don't really know too much about signed numbers, so I pretty much only use BMI/BPL to check bit 7.Memblers wrote:BCC and BCS were the last instructions I learned how to use properly, and they turned out to be insanely useful. Though I must admit I never used signed numbers so haven't used BMI/BPL except for checking bit 7.
Yeah, this works nicely. It's especially fast if you can store one or both of the values in biased form to begin with (such as when comparing to a constant.)Celius wrote:Okay, sorry, I found some info with google (I know, I know, just f-ing google it XD). It seems like you could do signed comparisons with BVC and BVS, but another way, though it may be time wasting, is to just convert signed numbers to unsigned numbers to compare them. You can do:
lda Num1
eor #$80
sta TempVar
lda Num2
eor #$80
cmp TempVar
It's at least less thinking.
Code: Select all
lda a
sec
sbc b
bvc *+4
eor #$80
bmi less
Code: Select all
; Avoiding overflow flag:
; If A >= n, branch to GE, where n < 0
cmp #0 ; can eliminate if you last operation was on A
bpl GE
cmp #n
bcc GE
...
; If A < n, branch to LT, where n >= 0
cmp #0 ; can eliminate if you last operation was on A
bmi LT
cmp #n
bcc LT
...
; Using overflow flag:
; If A >= n, branch to GE, where n < 0
sec
sbc #n - -128
bvc GE
...
; If A < n, branch to GE, where n > 0
clc
adc #128 - n
bvs GE
...
; ca65 macros:
; If A >= n, branches to label. A and n are 8-bit signed.
; Preserved: X, Y
.macro scmp_bge n,label
.if (n) < 0
sec
sbc #(n) - -128
bvc label
.elseif (n) = 0
cmp #0
bpl label
.else
clc
adc #128 - (n)
bvs label
.endif
.endmacro
; If A < n, branches to label. A and n are 8-bit signed.
; Preserved: X, Y
.macro scmp_blt n,label
.if (n) < 0
sec
sbc #(n) - -128
bvs label
.elseif (n) = 0
cmp #0
bmi label
.else
clc
adc #128 - (n)
bvc label
.endif
.endmacro