PDA

View Full Version : Lookup2 & Lookdown2



saladlee
- 25th January 2008, 07:45
Can anyone please further elaborate the functions of lookdown2 and lookup2? i dont understand the code... and the explanation given from melabs.com is not sufficient for my understanding... thanks!

LOOKDOWN2

LOOKDOWN2 Search,{Test}[Value{,Value...}],Var

The LOOKDOWN2 statement searches a list of Values for the presence of the Search value. If found, the index of the matching constant is stored in Var. Thus, if the value is found first in the list, Var is set to zero. If second in the list, Var is set to one. And so on. If not found, no action is taken and Var remains unchanged.

The optional parameter Test can be used to perform a test for other than equal to (A=@) while searching the list. For example, the list could be searched for the first instance where the Search parameter is greater than the Value by using ">" as the Test parameter. If Test is left out, A=@ is assumed.

The Value list can be a mixture of 16-bit numeric and string constants and variables. Each character in a string is treated as a separate constant equal to the character's ASCII value. Expressions may not be used in the Value list, although they may be used as the Search value.

Array variables with a variable index may not be used in LOOKDOWN2 although array variables with a constant index are allowed. Up to 85 (256 for 18Cxxx) values are allowed in the list.

LOOKDOWN2 generates code that is about 3 times larger than LOOKDOWN. If the search list is made up only of 8-bit constants and strings, use LOOKDOWN.

LOOKDOWN2 W0,[512,W1,1024],B0

LOOKDOWN2 W0,>[1000,100,10],B0




LOOKUP2

LOOKUP2 Index,[Value{,Value...}],Var

The LOOKUP2 statement can be used to retrieve entries from a table of Values. If Index is zero, Var is set to the first Value. If Index is one, Var is set to the second Value. And so on. If Index is greater than or equal to the number of entries in the list, no action is taken and Var remains unchanged.

The Value list can be a mixture of 16-bit numeric and string constants and variables. Each character in a string is treated as a separate constant equal to the character's ASCII value. Expressions may not be used in the Value list, although they may be used as the Index value. Array variables with a variable index may not be used in LOOKUP2 although array variables with a constant index are allowed. Up to 85 (256 for 18Cxxx) values are allowed in the list.

LOOKUP2 generates code that is about 3 times larger than LOOKUP. If the Value list is made up of only 8-bit constants and strings, use LOOKUP.

LOOKUP2 B0,[256,512,1024],W1

iugmoh
- 4th February 2008, 21:41
lookup2 and lookdown2 are upgraded version of lookup and lookdown , which you can use variables with them inside the brackets but with the old version you can't

1) Lookdown2 is used to search for specific value between the brackets and return its index for example here is a sample to conver hexadecimal into decimal

lookdown2 hexadecimal,[0,1,2,3,4,5,6,7,8,9,$A,$B,$C,$D,$E,$F],decimal

so if hexadecimal = $A ==> decimal =10 ( the index in brackets begin from 0 for 0 to 15 for $F )

2) Lookup2 is used to get the data of specific index you determine

for example

lookup2 index,["hello",10,$A,"H"],char

------ so
if index=0 then char="h"
if index= 5 then char=10

and so on

I hope these information is clear