JonB
Veteran Member
Would any CP/M programmers out there care to comment on this scheme for implementing "call relative" functionality under CP/M? Is it safe? I can't see anything in the RST 28h vector prior to doing this on the CP/M implementation I'm doing it on, but I wanted to check...
So, first I copy a short subroutine to one of the RST vector addresses, 28h:
Now, when I issue the instruction RST 28h I get the value of the address immediately following the RST instruction in HL. From there I can calculate and push a return address onto the stack, then use JR to take me to the subroutine. When it hits the RET, I am back where I expect to be. This seems to work fine under ZSID and I expect it will be fine in any other code. Unless 28h is in use, which I think it isn't...
Code:
.org 100h
; setup the RST 28 code ;
ld a,0e1h ; pop hl
ld (028h),a ;
ld a,0e5h ; push hl
ld (029h),a ;
ld a,0c9h ; ret
ld (02ah),a ;
; relative call to testfn
ld de,0004
rst 28h ; PC into HL
add hl,de
push hl ; to stack
jr testfn
; exit program (in CP/M, to CCP)
jp 0
testfn: ld a,0ffh ; do something
ret ; and return
.end
; EOF
So, first I copy a short subroutine to one of the RST vector addresses, 28h:
Code:
; RST 28h routine
0028 pop hl ; get return address into HL
0029 push hl ; restore return address to stack
002A ret ; ..and return
Now, when I issue the instruction RST 28h I get the value of the address immediately following the RST instruction in HL. From there I can calculate and push a return address onto the stack, then use JR to take me to the subroutine. When it hits the RET, I am back where I expect to be. This seems to work fine under ZSID and I expect it will be fine in any other code. Unless 28h is in use, which I think it isn't...