Re: ASM code problem


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

Re: ASM code problem



 Thomas J. Hruska wrote in article <3.0.1.16.19970707180255.267f61e8@mail.ti
r.com>...
>As you all have been noticing lately, I have been pretty active on this
>mailing list.  Remember, I am the writer of the ASH <-> OShell-82
>Development Kit.  I am also adding two major improvements in the next two
>versions.  I need a little help with some code.
>
>  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
>  add hl,de
>  ld (FINAL_ADDR),hl
>  pop de                   ; Retrieve de from the stack
>  pop hl                   ; Retrieve hl from the stack
>  call (FINAL_ADDR)
>
>Could someone please go through and tell me what each of the uncommented
>lines does (in terms of $38 and $FA).  Also, I need to know how the call
>statement works (how it reads the value located in FINAL_ADDR).

ld hl,$38FA puts $38 in the H register and $FA in the L register
add hl,de adds the contents of the DE register to the contents of the HL
register and leaves the sum in the HL register
ld (FINAL_ADDR),hl loads the contents of the HL register into the memory
location pointed to by the value of FINAL_ADDR.  In other words, if you
have a statement such as  FINAL_ADDR .equ $3D1A then after the ld, memory
location $3D1A will have the byte that's in L and $3D1B will have the byte
that's in H.
call (FINAL_ADDR) will push the two-byte contents of the PC onto the stack
(low byte first) and then transfer control to the the address stored at
FINAL_ADDR. In effect, it puts the memory contents stored at $3D1A and
$3D1B into the PC register.  ($3D1A is my example) which transfers control
there.

Tom Lake


References: