I'm thinking something like:
Code:
if branch = true then pc = pc + operand + 256 * (operand > 127)
This example assumes that
pc is your program counter, and that it's already pointing to the op-code of the instruction immediately following the branch instruction, which is where it should point if the branch is not taken. It also assumes that the conditional expression
(operand > 127) is
0 if false and
-1 if true.
The
branch = true part prevents updating of pc if the branch is not taken.
The
pc = pc + operand part adjusts the pc correctly for positive displacements.
The
+ 256 * (operand > 127) part corrects the adjustment for negative displacements only. It could be rewritten as
- 2 * (operand AND 128) if that floats your boat.
Mike B.