4.28 Large Arrays and MASM (Windows Programmers Only)


4.28 Large Arrays and MASM (Windows Programmers Only)

There is a defect in later versions of MASM 6.x that creates some problems when you declare large static arrays in your programs. Now you may be wondering what this has to do with you because we're using HLA, but don't forget that HLA 1.x under Windows compiles to MASM assembly code and then runs MASM to assemble this output. Therefore, any defect in MASM is going to be a problem for HLA users writing Windows code (obviously, this doesn't affect Linux users where HLA generates Gas code).

The problem occurs when the total number of array elements you declare in a static section (static, readonly, or storage) starts to get large. Large in this case is CPU dependent, but it falls somewhere between 128,000 and one million elements for most systems. MASM, for whatever reason, uses a very slow algorithm to emit array code to the object file; by the time you declare 64K array elements, MASM starts to produce a noticeable delay while assembling your code. After that point, the delay grows linearly with the number of array elements (i.e., as you double the number of array elements you double the assembly time) until the data saturates MASM's internal buffers and the cache. Then there is a big jump in execution time. For example, on a 300 MHz Pentium II processor, compiling a program with an array with 256,000 elements takes about 30 seconds; compiling a program with an array having 512,000 element takes several minutes. Compiling a program with a one-megabyte array seems to take forever.

There are a couple of ways to solve this problem. First, of course, you can limit the size of your arrays in your program. Unfortunately, this isn't always an option available to you. The second possibility is to use MASM 6.11; the defect was introduced in MASM after this version. The problem with MASM 6.11 is that it doesn't support the MMX instruction set, so if you're going to compile MMX instructions (or other instructions that MASM 6.11 doesn't support) with HLA you will not be able to use this option. A third option is to put your arrays in a var section rather than a static declaration section; HLA processes arrays you declare in the var section so MASM never sees them. Hence, arrays you declare in the var section don't suffer from this problem.




The Art of Assembly Language
The Art of Assembly Language
ISBN: 1593272073
EAN: 2147483647
Year: 2005
Pages: 246
Authors: Randall Hyde

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net