{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# Arrays - Arrays Arrays 4.1 Chapter Four Chapter Overview...

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

Arrays Beta Draft - Do not distribute © 2001, By Randall Hyde Page 463 Arra ys Chapter Four 4.1 Chapter Overview This chapter discusses ho w to declare and use arrays in your assembly language programs. This is prob - ably the most important chapter on composite data structures in this te xt. Ev en if you elect to skip the chap - ters on Strings, Character Sets, Records, and Dates and T imes, be sure you read and understand the material in this chapter . Much of the rest of the te xt depends on your understanding of this material. 4.2 Arrays Along with strings, arrays are probably the most commonly used composite data type. Y et most be gin - ning programmers ha v e a v ery weak understanding of ho w arrays operate and their associated ef fi cienc y trade-of fs. It’ s surprising ho w man y no vice (and e v en adv anced!) programmers vie w arrays from a com - pletely dif ferent perspecti v e once the y learn ho w to deal with arrays at the machine le v el. Abstractly , an array is an aggre g ate data type whose members (elements) are all the same type. Selec - tion of a member from the array is by an inte ger inde x 1 . Dif ferent indices select unique elements of the array . This te xt assumes that the inte ger indices are contiguous (though this is by no means required). That is, if the number x is a v alid inde x into the array and y is also a v alid inde x, with x < y , then all i such that x < i < y are v alid indices into the array . Whene v er you apply the inde xing operator to an array , the result is the specifi c array element chosen by that inde x. F or e xample, A[i] chooses the i th element from array A . Note that there is no formal requirement that element i be an ywhere near element i+1 in memory . As long as A[i] al w ays refers to the same memory location and A[i+1] al w ays refers to its corresponding location (and the tw o are dif ferent), the defi nition of an array is satisfi ed. In this te xt, we will assume that array elements occup y contiguous locations in memory . An array with fi v e elements will appear in memory as sho wn in Figure 4.1 Figure 4.1 Array Layout in Memory The base addr ess of an array is the address of the fi rst element on the array and al w ays appears in the lo west memory location. The second array element directly follo ws the fi rst in memory , the third element follo ws the second, etc. Note that there is no requirement that the indices start at zero. The y may start with an y number as long as the y are contiguous. Ho we v er , for the purposes of discussion, it’ s easier to discuss accessing array elements if the fi rst inde x is zero. This te xt generally be gins most arrays at inde x zero unless 1. Or some value whose underlying representation is integer, such as character, enumerated, and boolean types.

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 ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern