Page 1 of 1

jp (hl)

PostPosted: 23 Mar 2012, 19:11
by justine
Is there a way if i use JP (HL) in a routine to allow me to use RET in the routine that was jumped to ??

For example :

LD HL, TEST
JP (HL)
; Routine continues here


; This is the TEST routine

; Code to do stuff and then

RET ; Return to the line after the JP (HL)

Is this possible ???

Thanx

Re: jp (hl)

PostPosted: 23 Mar 2012, 19:30
by нолька

Re: jp (hl)

PostPosted: 23 Mar 2012, 19:41
by DimkaM
JP (HL) worked as LD PC,HL
Code: Select all
   LD HL, TEST
   JP (HL)      ;PC=HL
...      |
...      |
...      ↓
TEST   go code

Re: jp (hl)

PostPosted: 23 Mar 2012, 19:49
by justine
No what i need is a way to make a do the following with a command that doesnt exist. CALL (HL) now i know you can use that command but surely there is a way using JP (HL) so that when the called routine issues a RET it jumps back to the next command line after the JP (HL) was issued ??????

Re: jp (hl)

PostPosted: 23 Mar 2012, 19:57
by DimkaM
Code: Select all
   ld a,3
   call go_func
   ...
   ...   

go_func      ;a-number function
   add a,a
   ld hl,tabl_func
   add a,l
   ld l,a
   jr nc,l1
   inc h
l1   ld a,(hl)
   inc hl
   ld h,(hl)
   ld l,a
   jp (hl)

tabl_func
   dw func_1
   dw func_2
   ...
   dw func_n

func_1
   ret
func_2
   ret
...
...
func_n
   ret

Re: jp (hl)

PostPosted: 23 Mar 2012, 20:03
by lvd
Code: Select all

ld hl,RETURN_PLACE
push hl
ld hl,JUMP_PLACE
jp (hl)
RETURN_PLACE  ;here we will return by ret




Re: jp (hl)

PostPosted: 26 Mar 2012, 14:22
by lvd
TS-Labs wrote:
Code: Select all
call $+3
jp (hl)

You are stupid lamer. RET from a procedure will return to jp (hl).