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

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

View Full Document Right Arrow Icon
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.
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/08/2011 for the course CS 101 taught by Professor Jitenderkumarchhabra during the Summer '11 term at National Institute of Technology, Calicut.

Page1 / 20

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online