Sub-routines in PDP-11 assembly -
so i'm writing program assembly , , i'm trying use sub-routines, have problem. i'v written routine resembles switch case . reads input , , based on it's value , writes reserved address in stack address of following sub-routine.
it looks this:
1000    jsr r5,switchcase     // let return address 1004 1004    jsr r5,@0(sp) the first jsr goes switch case, writes first address in stack. second 1 jumps address.
i'm using simulator , , every time reaches line stops. don't know goes wrong :/
any appreciated.
the instruction jsr r5,@0(sp) pushes old r5 onto stack , puts current r7 (pc) r5. therefore program not jump address on stack, address stored in r5, wharever is.
 in example 1st jsr instruction writes r5 onto stack, , assigns 1004 r5.
 edit:  when program returns rts, restores old value of r5 stack.
 2nd jsr instruction pushes again value onto stack, , jumps address, since on top of stack (distance 0).
 if subroutine called 1st jsr indeed leaves subroutine address on top of stack, , 2nd jsr should jump there, 1 had use jsr r5,@2(sp) instead. consider else programming style.
 hope got right time...
Comments
Post a Comment