TheRealJimShady
TheRealJimShady

Reputation: 4293

AVR Assembly: How to continue from branch instruction?

say you have a branch instruction that takes you to some other subroutine, is it possible to then return to the calling subroutine and continue?.. Something like this:

prog:
cp r16,r17
breq true
...

true:
out PORTA,r16
HOW DO I RETURN TO EXECUTE THE REST OF prog?

I hope that this illustrates the problem.

Thanks!

Upvotes: 0

Views: 2679

Answers (3)

Micropop
Micropop

Reputation: 21

prog:
 cp r16,r17
 breq true  ;branch if equal
 brne false ;branch in not equal
 Rest of the program
 .
 .
 .
rjmp prog

false:
 Do something
 .
 .
ret

true:
 out PORTA,r16
 ;HOW DO I RETURN TO EXECUTE THE REST OF prog?
 ;Add a return statement, that will continue where you left
ret

Upvotes: 0

Egor Skriptunoff
Egor Skriptunoff

Reputation: 23727

prog:
    cpse r16,r17
    rjmp continue
    out PORTA,r16
continue:
    ...

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798456

Either branch back with an unconditional branch (rjmp), or convert your bit of code at true to a subroutine and convert your breq to a brne to jump over the rcall true that you place after it.

prog:
    cp r16,r17
    brne false
    rcall true
false:
    ...

 ...

true:
    out PORTA,r16
    ret

Upvotes: 1

Related Questions