| |||
Views: 88,320,217 |
Main | FAQ | Uploader | IRC chat | Radio | Memberlist | Active users | Latest posts | Calendar | Stats | Online users | Search | 03-29-24 04:22 PM |
|
Guest: Register | Login |
0 users currently in ROM Hacking | 1 guest |
Main - ROM Hacking - What Does BNE Do? | New thread | New reply |
GameGenie81 |
| ||
Koopa Level: 24 Posts: 74/100 EXP: 77918 Next: 207 Since: 08-15-07 From: Milwaukie, OR Last post: 5406 days Last view: 5359 days |
Please accept my apologies for writing this, but I would like to what exactly the BNE instruction (read: branch if zero flag clear) does. OK?
If the byte following the BNE instruction byte ($D0) is $00, would that mean to branch to whatever flag has its default instruction set at anything but $00 for now? ~Ben ____________________ We are a nation with no geographic boundaries, bound together through our beliefs. We are like-minded individuals, sharing a common vision, pushing toward a world rid of color lines. |
interdpth |
| ||
Buzzy Beetle Level: 44 Posts: 256/383 EXP: 592352 Next: 18933 Since: 02-22-07 Last post: 4071 days Last view: 4044 days |
its 'like
if(blah) so if blah is not zero then it does somehing cmp r0, r1 if it's true tehn go Branch if not equal to zero ____________________ lawl blog http://interdpths.blogspot.com/ |
Matrixz |
| ||
Ninji Level: 35 Posts: 14/225 EXP: 265781 Next: 14155 Since: 04-07-07 From: Norway Last post: 3078 days Last view: 1756 days |
(assuming this is 6502..)
the byte after BNE decides where the program jumps. Its a 8-bit signed value making a relative pointer to the current position of the Program Counter. A value from $00 to $7F jumps forward, $80 to $FF jumps backwards. This only happens if the branch happens, otherwise it just continues after the instruction. BNE is also affected by LDA, LDX and LDY, and any other instructions that changes one of the three registers, becouse those affect the Zero flag. For example: lda #$00 bne $08 ;a branch does not happen lda #$01 bne $08 ;a branch does happen as long as a register is modified to $00, a BNE right after it will not branch. |
MathOnNapkins |
| ||
Super Koopa Level: 62 Posts: 492/842 EXP: 1931228 Next: 53458 Since: 02-19-07 From: durff Last post: 4460 days Last view: 3983 days |
I should point out that the mnemonic BNE stands for Branch if Not Equal. It might be better to call it "Branch if not Zero" in some situations, b/c the only thing that affects whether the branch occurs is whether the Z (zero) flag is set in the P register. So if Z is not set, the branch will occur. ____________________ Zelda Hacking Forum hobbies: delectatio morosa |
frantik |
| ||
Red Koopa Level: 28 Posts: 84/139 EXP: 127112 Next: 4226 Since: 10-09-07 Last post: 4461 days Last view: 4455 days |
BNE $00 would have no effect because it is branching $00 bytes ahead (or not branching)
|
Trax |
| ||
Yellow Stalfos Level: 71 Posts: 433/1145 EXP: 3028932 Next: 138182 Since: 07-06-07 From: Québec Last post: 3599 days Last view: 2851 days |
The Zero flag is set either when the last command's result value was zero (load, transfer, decrease, increase, etc.), or when an equality test succeeds (compare). But as Frantik pointed out, the command "D0 00" has no effect, except wasting a few clock cycles. Although clock cycles timing may be important in some specific cases, my guess is that you're confounding an opcode with a data table containing the values D0 00...
However, I've seen such command in actual code once. It could be a byproduct of code conversion from the Famicon to the NES... |
MathOnNapkins |
| ||
Super Koopa Level: 62 Posts: 493/842 EXP: 1931228 Next: 53458 Since: 02-19-07 From: durff Last post: 4460 days Last view: 3983 days |
I've seen plenty of "null" branches. I imagine it is the byproduct of using an assembler and deleting code that was once there. For example:
But later on the coder decides to eliminate the LDA #$80, maybe b/c the requirements of the game changed, but they forget to delete the branch too. ____________________ Zelda Hacking Forum hobbies: delectatio morosa |
frantik |
| ||
Red Koopa Level: 28 Posts: 85/139 EXP: 127112 Next: 4226 Since: 10-09-07 Last post: 4461 days Last view: 4455 days |
maybe the programmer hates NOP? |
GreyMaria |
| ||
>implying even the Japanese understand the Japanese Level: 105 Posts: 1231/2851 EXP: 11893825 Next: 368435 Since: 07-13-07 Last post: 4469 days Last view: 4439 days |
NOP is one extra byte wasted that could be used as the start of another script. ____________________ we're currently experiencing some technical difficulties |
Trax |
| ||
Yellow Stalfos Level: 71 Posts: 434/1145 EXP: 3028932 Next: 138182 Since: 07-06-07 From: Québec Last post: 3599 days Last view: 2851 days |
Loops with nothing else than their own branching condition are used very often to synchronize VBlank interrupts precisely, or when waiting for a hit on Sprite #0. Example:
1C003: AD 0220 LDA $2002 |
NetSplit |
| ||
Level: 32 Posts: 103/178 EXP: 187615 Next: 18827 Since: 02-26-07 Last post: 2189 days Last view: 2114 days |
Posted by GameGenie81 The instruction's been pretty well explained by now, but I've gotta ask...what does your erroneous explanation of BNE actually mean? I'm pretty fluent in 6502, but I can't make sense of it. If it's indicative of your understanding of 6502, then I recommend you read some documents on the basics of assembly so that you can understand it better. There are also documents that walk you through simple assembly hacks or general uses of a debugger. Additionally, I strongly recommend this document. I use it whenever I program in machine code, since I can't remember all 56 opcodes' hex values or every version of various operations. |
Main - ROM Hacking - What Does BNE Do? | New thread | New reply |
© 2005-2023 Acmlm, blackhole89, Xkeeper et al. |
MySQL - queries: 77, rows: 107/108, time: 0.016 seconds. |