It is currently Thu Apr 09, 2020 7:32 am

All times are UTC

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Lookup FUnction Tables
PostPosted: Thu Jul 02, 2015 3:56 am 

Joined: Thu Jul 02, 2015 3:46 am
Posts: 1

I am really interested in knowing how the lookup function table works.

How do I convert a specific number into an X location on the table

For instance...

I have this "defined" table:
0,400,800,1200,1600,2000,2400,2800,3200,3600,4000,4400,4800,5200,5600,6000,6400,6800,7200,7600,8000 for X axis

if i have an independent variable of 4000, the result should be 11 on the lookup, but how do I perform this function? Or how do I create this table with those Xs or labels?

The code I am looking at looks like this
move #4000,d2
cmpi.w #$A000,d2
lsr.w #3,d2

in theory it should result in 11, but it results in 500 for D2 ($1F4).

Any help is REALLY appreciated.


PostPosted: Tue Jul 07, 2015 1:16 pm 
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1118
Here is a quick example.
* Title      : Table search example
* Written by : Charles Kelly
* Date       : July 7th, 2015
* Description: Read comments for description. No user interaction.
    OPT     SEX         ; Expand structured code
    ORG     $1000
START:                  ; first instruction of program

* Put program code here
* Search table of word values pointed to by A0 for value contained in D2.
    lea TABLE,A0        ; A0 is pointer to Table
    move.w  #4000,D2    ; Search value in D2
    bsr     SEARCH      ; Call SEARCH subroutine
    SIMHALT             ; halt simulator

* Search table of word values pointed to by A0 for value contained in D2.
* Pre:  A0 contains adddress of Table
*       D2.W contains search value
* Post: D3 contains index to value or -1 if not found
    clr.l D3            ; Index in D3
    while.w (A0) <lo> #TABLE_END do
        if.w D2 <eq> (A0)+ then ; if found
            add #1,d3   ; Increment index
    move.l  #-1,d3      ; Value not found

* Put variables and constants here

* Table array
TABLE   DC.W       0
        DC.W     400
        DC.W     800
        DC.W    1200
        DC.W    1600
        DC.W    2000
        DC.W    2400
        DC.W    2800
        DC.W    3200
        DC.W    3600
        DC.W    4000
        DC.W    4400
        DC.W    4800
        DC.W    5200
        DC.W    5600
        DC.W    6000
        DC.W    6400
        DC.W    6800
        DC.W    7200
        DC.W    7600
        DC.W    8000

    END    START        ; last line of source

Prof. Kelly

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 5 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group