Jump to content

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 ?

Link to comment
Share on other sites

Maybe a helpful link: http://www.6502.org/tutorials/compare_instructions.html




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
  • Like 1
Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...