Given the following program segment LDAA 03 A DECA TSTA BNE
Given the following program segment:
LDAA #$03
A DECA
TSTA
BNE XX
What should be the relative address XX following the BNE opcode to repeat the DECA instruction until the accumulator A value is zero?
Solution
Initially compute the number of bytes for each instruction. Both DESC and TSTA instructions are made of one byte opcode and the bNE instruction is made of one byte opcode and aone byte operand. The BNE instruction is used to check Z bit of the CCR and modifies the program counter (PC) value when Z bit is zero according to the equation given below:
New PC = Current PC + relevant offset
Hence the four bytes are moved back and the offset should be $FC. It is an eight bit, 2\'s complement expression for \'-4.\'
