IGNORED

THIS or THIS (and other comparisons)

Recommended Posts

Hae everyone

I know that when it comes to branch instructions we have equal/not and greater/less than equivalents but is there such a way of determining one value or another (that is not already binary), or between 2 values such as a min/max ?

Are there any other such comparison tricks ?

Share on other sites

Especially:

```Compare Result       N  Z  C
A, X, or Y < Memory  *  0  0
A, X, or Y = Memory  0  1  1
A, X, or Y > Memory  *  0  1

* The N flag will be bit 7 of A, X, or Y - Memory```

Meaning, you can do greater or equal than (>=) and less or equal than (<=) by checking two flags. Sometimes, it's even easier than that:

Provided that a comparison is much like a subtraction but without putting a result into that register, you can do min/max by two consecutive comparisons, since, if a > 2  and a < 4, a - 2 will be positive (carry set, zero flag clear), but a - 4 will be negative (carry and zero flag clear/unset).

```cmp #min
bcc skipToLess      ; a < min (carry is only unset, if register is less than the reference value)
cmp #max
bcs skipToGreater   ; a >= max (if greater or equal, carry is set)
; #min <= a < #max, if we arrive here```

Edited by NoLand

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.