Write a program segment to do the following:
“If bit 3 of Accumulator A is 1 go to location $1234 and continue execution from that location
otherwise goto location $4321 and continue execution from that location”
Content of Accumulator A should remain unchanged. This program segment maybe in any place in the memory. Use at most five instructions.
This is my homework. But I don't know how to get to the desired location and continue .
bit a,#$08 ; Test bit 3 of acc A
bne bitwasset ; If it was set, the result is not equal to zero
; so BNE (branch if not equal) goes to the label in that case
jmp $4321 ; If here, the branch was not takes, so the bit was zero.
bitwasset jmp $1234 ; If here, the branch was taken as the bit was 1.
Alternatively you could use BEQ (branch if equal) and swap the two jump target addresses.
See the reference manual here for more info; the instruction set is given in appendix A.4
Do look up each instruction to see how they work and why they have the specific effect in the program - you are not learning if you just use things without understanding them..
bit a,#$08 ; Test bit 3 of acc A
bne bitwasset ; If it was set, the result is not equal to zero
; so BNE (branch if not equal) goes to the label in that case
jmp $4321 ; If here, the branch was not takes, so the bit was zero.
bitwasset jmp $1234 ; If here, the branch was taken as the bit was 1.
Alternatively you could use BEQ (branch if equal) and swap the two jump target addresses.
See the reference manual here for more info; the instruction set is given in appendix A.4
Do look up each instruction to see how they work and why they have the specific effect in the program - you are not learning if you just use things without understanding them..
It should work fine (with the proper AND value of 8).
The BIT A instruction just does the AND operation without needing another register, so is slightly more versatile.
The question said "at most five instructions", not "exactly five" - I was just minimising the code size.
Also be wary of using short labels that could be confused with mnemonics.