Look-up Tables and Jump Tables

Look-up tables (LUTs)

To make a look-up table (LUT), you must set the bounds. Look-up tables are often used in calculations which are not easy to find with arithmetic, such as the sine function. Lets model the sine function with a look-up table.

 LD H, 0
 LD L, A
 LD DE, sine_table
 ADD HL, DE
 LD A, (HL)
 INC HL
 LD H, (HL)
 LD L, A
 RET
sine_table:
 ; The lookup table
.DW 0000,ドル 0004,ドル 0009,ドル 000ドルD, 0012,ドル 0016,ドル 001ドルB, 001ドルF, 0024ドル
.DW 0028,ドル 002ドルC, 0031,ドル 0035,ドル 003ドルA, 003ドルE, 0042,ドル 0047,ドル 004ドルB
.DW 004ドルF, 0053,ドル 0058,ドル 005ドルC, 0060,ドル 0064,ドル 0068,ドル 006ドルC, 0070ドル
.DW 0074,ドル 0078,ドル 007ドルC, 0080,ドル 0084,ドル 0088,ドル 008ドルB, 008ドルF, 0093ドル
.DW 0096,ドル 009ドルA, 009ドルE, 00ドルA1, 00ドルA5, 00ドルA8, 00ドルAB, 00ドルAF, 00ドルB2
.DW 00ドルB5, 00ドルB8, 00ドルBB, 00ドルBE, 00ドルC1, 00ドルC4, 00ドルC7, 00ドルCA, 00ドルCC
.DW 00ドルCF, 00ドルD2, 00ドルD4, 00ドルD7, 00ドルD9, 00ドルDB, 00ドルDE, 00ドルE0, 00ドルE2
.DW 00ドルE4, 00ドルE6, 00ドルE8, 00ドルEA, 00ドルEC, 00ドルED, 00ドルEF, 00ドルF1, 00ドルF2
.DW 00ドルF3, 00ドルF5, 00ドルF6, 00ドルF7, 00ドルF8, 00ドルF9, 00ドルFA, 00ドルFB, 00ドルFC
.DW 00ドルFD, 00ドルFE, 00ドルFE, 00ドルFF, 00ドルFF, 00ドルFF, 0100,ドル 0100,ドル 0100ドル

The main disadvantage is the size, but we can't do much about it.

Jump Tables

These are just like LUTs, except that rather than values being returned, they return an area in memory.

A vector table holds only the addresses.
Here is an example:

VectTbl:
 .DW ClearScreen
 .DW PutSprite
 .DW DrawLine
 .DW EndPrgm
 .DW BlackScreen
 LD H, 0
 LD L, A
 ADD HL, HL
 LD DE, VectTbl
 ADD HL, DE;Just like a look-up table
 LD A, (HL)
 INC HL
 LD H, (HL)
 LD L, A
 JP (HL)

A Jump table is essentially a vector table, but rather than holding the address, it holds the entire jump instruction.

JumpTbl:
 JP ClearScreen
 JP PutSprite
 JP DrawLine
 JP EndPrgm
 JP BlackScreen

To call or jump to a routine in the jump table, you use an address of
JumpTbl + 3 * n
where n is the number of the routine you want. Supposing you wanted to run DrawLine, then you would use
CALL JumpTbl + 3 * 2

If you notice, the default B_CALLs have offsets of 3. For example, B_CALL(_ClrLCDFull) is EF4045 in machine code, and B_CALL(_ClrLCD) is EF4345 in machine code, and B_CALL(_ClrScreenFull) is EF4645. EF is BCALL(**). But why is the first byte of the address increasing? This is because the calculators use Little-Endian; the least-significant-byte and most-significant-byte are essentially swapped.

page revision: 3, last edited: 01 May 2017 12:40
Unless otherwise stated, the content of this page is licensed under GNU Free Documentation License.
Click here to edit contents of this page.
Click here to toggle editing of individual sections of the page (if possible). Watch headings for an "edit" link when available.
Append content without editing the whole page source.
Check out how this page has evolved in the past.
If you want to discuss contents of this page - this is the easiest way to do it.
View and manage file attachments for this page.
A few useful tools to manage this Site.
Change the name (also URL address, possibly the category) of the page.
View wiki source for this page without editing.
View/set parent page (used for creating breadcrumbs and structured layout).
Notify administrators if there is objectionable content in this page.
Something does not work as expected? Find out what you can do.
General Wikidot.com documentation and help section.
Wikidot.com Terms of Service - what you can, what you should not etc.
Wikidot.com Privacy Policy.

AltStyle によって変換されたページ (->オリジナル) /