Difference between RTS and Branch in assembly

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Difference between RTS and Branch in assembly

Jump to solution
4,510 Views
hityou123
Contributor II

I am bit confused on when to use rts.

 

For example, when I jump to a subroutine - jsr, it is clear that rts has to be used.

But when I branch, say bra xxxx or bhi xxxx, can i still use rts?

Labels (1)
0 Kudos
1 Solution
1,984 Views
eckhard
Contributor V

Hello,

you can only use RTS when you've called a subroutine, because RTS pulls the return adress from the stack ang continues execution on that adress..

The only branch that calls a subroutine is BSR. Every other branch is just like a jump. So if you use RTS,without a JSR or BSR, you pull two bytes from the stack and return to that adress. This will make your program go crazy.

Of course you can branch and push a return adress on the stack and then use RTS but this is more a theoretical approach.

Eckhard

View solution in original post

0 Kudos
2 Replies
1,984 Views
Monica
Senior Contributor III

Hityou123, did this clarify your view on RTS?

Regards!

1,985 Views
eckhard
Contributor V

Hello,

you can only use RTS when you've called a subroutine, because RTS pulls the return adress from the stack ang continues execution on that adress..

The only branch that calls a subroutine is BSR. Every other branch is just like a jump. So if you use RTS,without a JSR or BSR, you pull two bytes from the stack and return to that adress. This will make your program go crazy.

Of course you can branch and push a return adress on the stack and then use RTS but this is more a theoretical approach.

Eckhard

0 Kudos