sdm wrote:
Is this method also works with other branches? As BEQ, BMI, BPL, etc.?
Or maybe there are some limitations and can not always be used?
The "method" isn't magical or mystical in some manner -- no CPU should be "magical". This is a computer, it has definitive behaviour. Your question implies that you don't understand branches (vs. jumps), so let's put that to rest:
Branch instructions on the 6502 are opcodes
bpl, bmi, bvc, bvs, bcc (blt), bcs (bge), bne, beq. These instructions consist of
2 bytes: 1 byte for the opcode, and 1 byte for the operand. The operand being 1 byte in size is the key to understanding branches. The operand represents an "offset" from the active PC (the address of the operand, not the opcode!) -- this is also known as a "relative address" or "PC relative".
The operand is therefore a signed 8-bit number (more precisely: its twos complement), which means that the range it's limited to is +127 bytes (up to 127 bytes "forward", i.e. values $01 to $7F) and -128 (up to 128 bytes "backwards", i.e. value $80 to $FF) from the address of the operand. Thus, the branch range "from the branch opcode itself" is effectively +129 and -126. A little-mentioned quirk/feature is how an operand value of $00 on a branch instruction just continues on with the next instruction regardless of the conditional results (think of it as a 2-byte
nop with a variable cycle count dependant on the result of the conditional).
The reason branch instructions are 2 bytes (rather than 3 (see below)) is to save space/memory.
In contrast, jump instructions on the 6502 are opcode
jmp, jsr. This instruction consists of
3 bytes: 1 byte for the opcode, and 2 bytes for the location to jump to -- this is known as an "absolute address" (the same type of addressing used in something like
sta $2100). The operand specifies a literal value from $0000 to $FFFF, which the CPU loads directly into PC. I won't explain the difference between
jmp and
jsr here -- it's not relevant to what is being discussed (relative vs. absolute addressing). And as should be obvious, jump instructions are unconditional.
The way people work around the relative addressing range on the 65xx is by doing exactly what tokumaru described -- the most common being to reverse the branch logic and use a
jmp.
Edit: clarification on branches with an operand of $00.