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
5,078 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
Reply
1 Solution
2,552 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
Reply
2 Replies
2,552 Views
Monica
Senior Contributor III

Hityou123, did this clarify your view on RTS?

Regards!

2,553 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
Reply