| |||
Views: 88,490,311 |
Main | FAQ | Uploader | IRC chat | Radio | Memberlist | Active users | Latest posts | Calendar | Stats | Online users | Search | 04-27-24 12:17 AM |
|
Guest: Register | Login |
0 users currently in ROM Hacking | 5 guests | 1 bot |
Main - ROM Hacking - Greater-Than or Less-Than ASM? | New thread | New reply |
RetroRain |
| ||
Fuzz Ball Level: 66 Posts: 655/994 EXP: 2438301 Next: 23550 Since: 09-30-07 Last post: 1935 days Last view: 958 days |
How do you do greater-than or less-than with 6502? I want to check a range of values. If the value is #$00 - #$11, it will jump to $8FC7, if it is #$12 to #$13, it will jump to $8FCD, and if it is #$14 - #$19, it will jump to $8FD3. Granted, I could simpy do a bunch of CMPs, but I don't want to waste the space. Is there a better way to do it? Thanks.
____________________ My YouTube Channel |
infidelity |
| ||
Fuzz Ball Level: 66 Posts: 408/968 EXP: 2368160 Next: 93691 Since: 05-24-07 Last post: 959 days Last view: 815 days |
First, dont do a cmp of 00, waste of code. If you want to do a cmp of 00, you simply load the register, than follow it with a bne/beq, or whatever branch opcode it is that you want. When comparing multiple values, have your 00 cmp first, then you can follow with c901, f0##, c902, f0##.
|
never-obsolete |
| ||
Rat Level: 24 Posts: 92/96 EXP: 74499 Next: 3626 Since: 02-22-07 From: Phoenix, AZ Last post: 2596 days Last view: 2596 days |
-Here's an explanation on how cmp/cpx/cpy work and there's a table showing which branch instructions to use.
http://www.6502.org/tutorials/compare_instructions.html -An alternate to a long list of compares is a jump table, but that might take up more space. |
RetroRain |
| ||
Fuzz Ball Level: 66 Posts: 656/994 EXP: 2438301 Next: 23550 Since: 09-30-07 Last post: 1935 days Last view: 958 days |
So, are you saying that there is no greater-than or less-than technique? I have no choice but to do a bunch of CMPs?
EDIT - Okay, never-obsolete posted at the same time I made my reply to infidelity's post. So I can use either BMI, BPL, BCC, or the BCS? ____________________ My YouTube Channel |
never-obsolete |
| ||
Rat Level: 24 Posts: 93/96 EXP: 74499 Next: 3626 Since: 02-22-07 From: Phoenix, AZ Last post: 2596 days Last view: 2596 days |
Yeah.
So to check if the accumulator is less then some value, n:
The above is an if-then-else. This can be shortened if you don't need the else by branching on the opposite case:
There are some tricky ones that require testing for equality first. BCS is one example, it branches when A >= n. So if you wanted to just branch on A > n, you'd first need a BEQ then the BCS. The link I posted covers this stuff. |
RetroRain |
| ||
Fuzz Ball Level: 66 Posts: 657/994 EXP: 2438301 Next: 23550 Since: 09-30-07 Last post: 1935 days Last view: 958 days |
Ah, I see. Yeah, sounds a little bit trickier, but I see what you are saying. Alright, I appreciate your help. Thanks for the help both of you. ____________________ My YouTube Channel |
Chaobomr |
| ||
Buster Beetle Banned: Spammer takeover? Level: 45 Posts: 145/467 EXP: 638839 Next: 21325 Since: 05-07-13 From: The dirty south Last post: 3480 days Last view: 3479 days |
The CMP statement is 6502's version of the infamous
____________________ Sorry for the stupidity. That jerk will be dealt with in the most insane way possible. |
RetroRain |
| ||
Fuzz Ball Level: 66 Posts: 658/994 EXP: 2438301 Next: 23550 Since: 09-30-07 Last post: 1935 days Last view: 958 days |
Not by itself. The CMP just checks a value. You have to use other opcodes like BCC (Branch on Carry Clear) or BCS (Branch on Carry Set) like never-obsolete gave in the example above. The 6502 has special "status" flags that can be set/un-set, and depending on if the flag is set, you can branch to another spot in the code.
I have used BCC and BCS in my hack MM Nemesis, but I don't personally care for using them though. That's just me. I think because I don't have a lot of experience using them, and I don't like dealing with "flags". I like to simply stay with LDA, STA, CMP, JSR, and JMP opcodes. Anyway, never-obsolete, after evaluating BCC/BCS, I have decided to use a table instead, because it actually suits my purposes later on down the road when it comes time to do some heavier hacking. It is a lot easier to read, and not all stages require long tables. It saves a lot of checking, and makes it easier to hack later on. But at least I know now how to do the greater-than/less-than stuff. It should come in handy for the future. Thanks again for the help though. ____________________ My YouTube Channel |
Chaobomr |
| ||
Buster Beetle Banned: Spammer takeover? Level: 45 Posts: 148/467 EXP: 638839 Next: 21325 Since: 05-07-13 From: The dirty south Last post: 3480 days Last view: 3479 days |
CMP BCC/BCS certainly sounds like those if/then statements that you see in many other languages ____________________ Sorry for the stupidity. That jerk will be dealt with in the most insane way possible. |
Main - ROM Hacking - Greater-Than or Less-Than ASM? | New thread | New reply |
© 2005-2023 Acmlm, blackhole89, Xkeeper et al. |
MySQL - queries: 77, rows: 106/106, time: 0.018 seconds. |