Difference between RTS and Branch in assembly

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Difference between RTS and Branch in assembly

ソリューションへジャンプ
5,910件の閲覧回数
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,384件の閲覧回数
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,384件の閲覧回数
Monica
Senior Contributor III

Hityou123, did this clarify your view on RTS?

Regards!

3,385件の閲覧回数
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 件の賞賛
返信