A89: Re: ASM questions


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

A89: Re: ASM questions




TurboSoft@aol.com wrote:
> Now: let's say that d0 equals 00000001 (which in my SimTown game l might
want
> to be the code for a road tile).  l know that my label for the sprite
can't
> start with a number, but l don't want to:
> cmp d0,00000001
> beq road_tile
> cmp d0,00000002
> beq clear_land
> lnstead, l want to somehow jump to what d0 equals.  so when d0 equals
00000001
> l want to somehow convert that value into a label it can jump to.

First, if d0 is a word then it's either %0000000000000001 (binary) or $0001
(hex).
Then, you do it this way:

  lsl.l   #2,d0       ;d0=d0*4 (Every address entry is 4 bytes)
  lea    jumptable,a0 ;let a0 point to the jumptable
  move.l (a0.d0),a0   ;move the address to the correct routine to a0
  jsr    (a0)        ;jump to the routine as a subroutine

tile_zero:
  <do something>
  rts
road_tile:
  <do something>
  rts
clear_land:
  <do something>
  rts

jumptable:
dc.l tile_zero,road_tile,clear_land

-- 
  /Johan Rönnblom, Team Amiga


References: