Re: A89: recursion question


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

Re: A89: recursion question




In a message dated 98-11-29 00:33:32 EST, you write:

so does that mean that you don't even need the rts at the end of this?:
because the program will never actually reach that instruction...because at
the begining 1 is always placed in d0 :)

> main_stuff_tests:
 > cmp          stuff,d0
 > beq           yes_stuff
 > cmp          stuff2,d0
 > beq           yes_stuff2
 > rts*********can be omitted**********


>> Not correct..
>> you cant 'rts' from just a branch..
>> what bsr (branch to subrutine) does, is that it pushes the adress of the
next
>> instruction onto the stack and then jumps to the position stated (in this
case
>> main_stuff_tests) the rts (return from subrutine) is then just taking the
>> address stored on top of the stack and jumps to this adress..
 
>> the beq, bne and such does _not_ push the address of the next instruction
onto
>> the stack so rts will not return to the intstruction after the beq, it will
just
>> take whatever stored on the stack and jump there.. straight out in
psyberspaze
>> :)


 
 //Olle
 
 BLoWh0Le@aol.com wrote:
 > 
 > 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?
  >>