Difference between RTS and Branch in assembly

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Difference between RTS and Branch in assembly

跳至解决方案
5,913 次查看
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?

标签 (1)
0 项奖励
回复
1 解答
3,387 次查看
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 项奖励
回复
2 回复数
3,387 次查看
Monica
Senior Contributor III

Hityou123, did this clarify your view on RTS?

Regards!

3,388 次查看
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 项奖励
回复