Re: LZ: zshell programming


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

Re: LZ: zshell programming



Will Stokes (3D Diamond productions) wrote:
> 
>         my second problem has to do with those "if-like" thingies in
> assembly. lets say depending on what register a is I want to load
> different strings to de, say if a=1 string p1, if a=2 string p2, if a=3
> string p3 and so on for values of a 1, 2, 3, 4, and so on up to and
> including 9. how exactly would i test a and then load the correct string
> to de? this is what I have come up with so far:
> 
>         ld b, 1
>         cp b
>         ld de, p1
> 
>         ld b, 2
>         cp b
>         ld de, p2
> 
>         ld b, 3
>         cp b
>         ld de, p3
> 
>         ld b, 4
>         cp b
>         ld de, p4
> 
> ..and so on, get the idea? can anybody help me?
>                         Will Stokes


That doesn't work... You must do relative jumps and add (PROGRAM_ADDR) to de. Anyway, this is the 
smartest way to do it I think:


  .
  .
  .
  ld h,0
  ld l,a
  dec l            ; The lowest value is 1, not 0
  sla l
  ld de,LookupTable
  add hl,de
  ld de,(PROGRAM_ADDR)
  add hl,de
  call LD_HL_MHL   ; Push af if you want to keep the a reg.
  add hl,de        ; HL points to p1 or p2 or ... or p9 :)
  .
  .
  .


LookupTable:
  .dw p1,p2,p3,p4,p5,p6,p7,p8,p9


That should work I think.


<pre>
--
 ----------------------------------------------------------------------------
| Real name: Jimmy M†rdell    | "The concept of God it makes no sense        |
| Email....: <mja@algonet.se> |  An out-of-life experience                   |
| IRC-name.: Yarin            |  Free at last to do what I please            |
| WWW......: -                |  In heaven there are no TVs" - Cat rapes Dog |
|----------------------------------------------------------------------------|
|          "I'm the operator with my pocket calculator" - Kraftwerk          |
 ----------------------------------------------------------------------------
</pre>


References: