Hi all, Just wondered if anyone has an example bit of assembler code that shows how to use the TBL or ETBL commands to do an interpolated lookup ? I read the command descriptions in the Referance guide, but they didn't make much sense to me. Many Thanks Andy |
|
Table Lookups on HCS12
Started by ●January 4, 2004
Reply by ●January 5, 20042004-01-05
----- Original Message ----- From: "Andrew Leech" <> To: <> Sent: Monday, January 05, 2004 5:16 AM Subject: [68HC12] Table Lookups on HCS12 > Hi all, > > Just wondered if anyone has an example bit of assembler code that > shows how to use the TBL or ETBL commands to do an interpolated > lookup ? > > I read the command descriptions in the Referance guide, but they > didn't make much sense to me. Here example. regD=_CalcDelay(_X) . _X is unsigned and should be lower than last element of Xtab. .text Xtab: .byte 1, 2, 4, 6, 8, 12, 16, 20, 30, 40, 50, 70, 80, 90, 94, 97,99 ; ascending order Ytab: .word 7720,3272,2632,2288,2048,1718,1504,1280,1000,780,600,360,256,168,128,80,0 exact: LSLA LDD A,y PULX RTS _CalcDelay:: pshx LDX #Xtab CLRA LDAB _X LDY #Ytab loop: CMPB A,x BEQ exact BLO found INCA BRA loop found: DECA SUBB A,x ; XL-X1 LEAY A,y LEAY A,y ; pointer to Y1 LEAX A,x ; pointer to X1 LDAA 1,x SUBA 0,x ; X2-X1 TFR A,X CLRA FDIV ; set up reg B B=int(256*(_X-x1)/(x2-x1) ) EXG D,X TAB ETBL 0,y PULX RTS Edward > > Many Thanks > > Andy |