Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

...

Status
Not open for further replies.

erkanz55

New Member
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 .
 
Something like:

Code:
            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..
 
Something like:

Code:
            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..

TAB
ANDB #$04
BNE set
JMP $4321
set JMP $1234

how about this, does works?
 
That should work. I'm assuming TAB is transfer A to B. However, bits are normally counted from zero so bit 3 is the 4th bit and needs ANDing with #8.

Mike.
 
how about this, does works?

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.
 
Missed the bita instruction. A more elegant and shorter solution.

Mike.
P.S. it looks like a really nice processor, is there a modern equivalent?
 
Looks like someone has thrown his toys out of the cot.

Thread closed.

JimB
 
Status
Not open for further replies.

Similar threads

New Articles From Microcontroller Tips

Back
Top