flame Posted April 23, 2020 Share Posted April 23, 2020 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 ? Quote Link to comment https://forums.atariage.com/topic/305866-this-or-this-and-other-comparisons/ Share on other sites More sharing options...
NoLand Posted April 23, 2020 Share Posted April 23, 2020 (edited) Maybe a helpful link: http://www.6502.org/tutorials/compare_instructions.html 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 April 23, 2020 by NoLand 1 Quote Link to comment https://forums.atariage.com/topic/305866-this-or-this-and-other-comparisons/#findComment-4518998 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.