# TableLookups - Calculation Via Table Lookups Calculation...

This preview shows pages 1–2. Sign up to view the full content.

Calculation Via Table Lookups Beta Draft - Do not distribute © 2001, By Randall Hyde Page 647 Calculation Via Table Lookups Chapter Twelve 12.1 Chapter Overview This chapter discusses arithmetic computation via table lookup. By the conclusion of this chapter you should be able to use table lookups to quickly compute comple x functions. Y ou will also learn ho w to con - struct these tables programmatically . 12.2 Tables The term “table” has dif ferent meanings to dif ferent programmers. T o most assembly language pro - grammers, a table is nothing more than an array that is initialized with some data. The assembly language programmer often uses tables to compute comple x or otherwise slo w functions. Man y v ery high le v el lan - guages (e.g., SNOBOL4 and Icon) directly support a table data type. T ables in these languages are essen - tially arrays whose elements you can access with a non-inte ger inde x (e.g., ﬂ oating point, string, or an y other data type). HLA pro vides a table module that lets you inde x an array using a string. Ho we v er , in this chapter we will adopt the assembly language programmer’ s vie w of tables. A table is an array containing preinitialized v alues that do not change during the e x ecution of the pro - gram. A table can be compared to an array in the same w ay an inte ger constant can be compared to an inte ger v ariable. In assembly language, you can use tables for a v ariety of purposes: computing functions, control - ling program ﬂ o w , or simply “looking things up”. In general, tables pro vide a f ast mechanism for performing some operation at the e xpense of some space in your program (the e xtra space holds the tab ular data). In the follo wing sections we’ ll e xplore some of the man y possible uses of tables in an assembly language program. Note: since tables typically contain preinitialized data that does not change during program e x ecution, the READONL Y section is a good place to declare your table objects. 12.2.1 Function Computation via Table Look-up T ables can do all kinds of things in assembly language. In HLLs, lik e P ascal, it’ s real easy to create a formula which computes some v alue. A simple looking arithmetic e xpression can be equi v alent to a consid - erable amount of 80x86 assembly language code. Assembly language programmers tend to compute man y v alues via table look up rather than through the e x ecution of some function. This has the adv antage of being easier , and often more ef fi cient as well. Consider the follo wing P ascal statement: if (character >= ‘a’) and (character <= ‘z’) then character := chr(ord(character) - 32); This P ascal if statement con v erts the character v ariable character from lo wer case to upper case if char - acter is in the range ‘a’. . ’z’. The HLA code that does the same thing is mov( character, al ); if( al in ‘a’. .’z’ ) then and( \$5f, al ); // Same as SUB( 32, al ) in this code. endif; mov( al, character ); Note that HLA ’s high level IF statement translates into four machine instructions in this particular example.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 16

TableLookups - Calculation Via Table Lookups Calculation...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online