A89: recursion question


[Prev][Next][Index][Thread]

A89: recursion question




When you make a jump to a subroutine (using bsr and bxx commands), does
control return to the exact spot where you left when the program runs into an
rts command?

_main:
move.w      #1,d0
move.w      d0,stuff
move.w      d0,stuff2
bsr            main_stuff_tests
rts

main_stuff_tests:
cmp          stuff,d0
beq           yes_stuff
cmp          stuff2,d0
beq           yes_stuff2
rts

yes_stuff:
add.w       #1,stuff
rts
yes_stuff2:
add.w       #1,stuff2
rts

here's how i think it goes with my current knowledge of asm:
in _main: we move 1 to d0. then the value of d0 to stuff and stuff2. we jump
to main_stuff_tests. we compare d0 with stuff.  it checks out so we jump to
yes_stuff. there, we add 1 to stuff and jump back.  (FROM HERE I'M NOT 100%
SURE) we then compare d0 with stuff2 and it checks out so we jump to
yes_stuff2 and add 1 to stuff2.  then we jump back to main_stuff_tests.
there, we reach the last command, rts, which returns us to _main.  there we
run into another rts command, which ends the program.  am i correct?


Follow-Ups: