Re: A82: ASM code problem


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

Re: A82: ASM code problem



  push hl                  ; Temporarily store hl on the stack
  push de                  ; Temporarily store de on the stack
  ld hl,$38FA              ; $38 -> l, $FA -> h
  ld de,(ROM_LOCATION)     ; $00 -> e, $00 -> d  (I think ROM_LOCATION
might hold something other than $0000?)
  add hl,de			; add hl and de, put the result in hl
  ld (FINAL_ADDR),hl	; put the address that was in hl into the temporary
variable FINAL_ADDR
  pop de                   ; Retrieve de from the stack
  pop hl                   ; Retrieve hl from the stack
  call (FINAL_ADDR)		; calls the subroutine at the address in FINAL_ADDR

The call instruction pushes the current pc onto the stack and then puts the
address that is found after it into the pc (program counter) making the
calculator  jump to that address and execute the code found there. In this
case, it jumps to the address in FINAL_ADDR, the () signs signify
indirection, meaning that it jumps to what is in the variable rather than
the address of the actual variable. So all this code does is get the
address as ROM_LOCATION, add $38FA to it and then call the subroutine at
this new address.

	-Andrew


References: