Link to home
Start Free TrialLog in
Avatar of hengck23
hengck23

asked on

How to implement look up table in assembly?

Hi all,

I have a lookup table:

Table:
[-inf,0.3]  -->  100.0
[0.3,0.4]  -->  200.0
[0.4,0.5]  -->  300.0
[0.5,0.6]  -->  400.0
[0.6,+inf] -->  500.0


i.e,
FuncLookUp(-1.0 ) returns 100.0
FuncLookUp(0.35 ) returns 200.0
FuncLookUp(0.51 ) returns 400.0
FuncLookUp(11.0 ) returns 500.0 , etc

in C code, it would look like:

static float table[]={
100.0f, 200.0f, 300.0f, 400.0f, 500.0f
};

static float minValue=0.3;
static float step=0.1;
static float maxValue=0.6;
static float maxRange=maxValue-minValue;
static int tableSize=5;

inline FuncLookUp(float x){

x-=minValue;
if (x<0) return table[0];
if (x>maxRange) return table[tableSize-1];

int idx= fastRound(x/maxRange*tableSize);
return table[idx];
}


How can I write FuncLookUp in assembly?
thank you!


Avatar of RHenningsgard
RHenningsgard
Flag of United States of America image

Just out of curiosity, what's it for?
One great tip, and always an intstructive starting point for the beginning assembly-language writer, is to compile the code in C or Pascal, then debug it in assembly to see what a compiler did with it.  That gets you over lots of little stumbling blocks like how to address the variables and so on.

The main thing with which you'll have to contend, if you are unfamiliar with assembly, is the way the floating-point numbers are represented in binary.  That is a lesson in itself (or actually several lessons, as there are several common, distinctly different floating point representations in common use).

Rob---
ASKER CERTIFIED SOLUTION
Avatar of BeyondWu
BeyondWu
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial