Data Structures - Part I CS 215 Lecture 7. Motivation  Real programs use abstractions like lists, trees, stacks, and queues.  The data associated with.

Slides:



Advertisements
Similar presentations
E LEMENTARY D ATA STRUCTURES. A RRAYS Sequence of elements of similar type. Elements are selected by integer subscripts. For example, signs: array[37:239]
Advertisements

Chapter 21 Implementing lists: array implementation.
Pointers.
Lecture 13: 10/8/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
EC-211 DATA STRUCTURES LECTURE 2. EXISTING DATA STRUCTURES IN C/C++ ARRAYS – A 1-D array is a finite, ordered set of homogeneous elements – E.g. int a[100]
Programming and Data Structure
Lecture 20 Arrays and Strings
The Assembly Language Level
Arrays and Matrices CSE, POSTECH. 2 2 Introduction Data is often available in tabular form Tabular data is often represented in arrays Matrix is an example.
Arrays. INTRODUCTION TO ARRAYS Just as with loops and conditions, arrays are a common programming construct and an important concept Arrays can be found.
Arrays.
Arrays. 1D Array Representation In C 1-dimensional array x = [a, b, c, d] map into contiguous memory locations Memory abcd start location(x[i]) = start.
Lecture # 02 07/02/2013Dr. Muhammad Umair 1. 07/02/2013Dr. Muhammad Umair 2  Numeric  Integer Numbers  0,10,15,4563 etc.  Fractional Number  10.5,
Arrays. Memory organization Table at right shows 16 bytes, each consisting of 8 bits Each byte has an address, shown in the column to the left
Pointer. Warning! Dangerous Curves C (and C++) have just about the most powerful, flexible and dangerous pointers in the world. –Most other languages.
Slides prepared by Rose Williams, Binghamton University Chapter 5 Defining Classes II.
CS1061 C Programming Lecture 4: Indentifiers and Integers A.O’Riordan, 2004.
Basic Definitions Data Structures: Data Structures: A data structure is a systematic way of organizing and accessing data. Or, It’s the logical relationship.
Arrays Data Structures - structured data are data organized to show the relationship among the individual elements. It usually requires a collecting mechanism.
Arrays. The array data structure An array is an indexed sequence of components –Typically, the array occupies sequential storage locations –The length.
Introduction of Arrays. Arrays Array form an important part of almost all programming language. It provides a powerful feature and can be used as such.
© The McGraw-Hill Companies, 2006 Chapter 16 Two-dimensional arrays.
Lecture 18 Last Lecture Today’s Topic Instruction formats
Addressing Modes Chapter 11 S. Dandamudi To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S.
CSC – Java Programming II Lecture 9 January 30, 2002.
Data Structures Winter What is a Data Structure? A data structure is a method of organizing data. The study of data structures is particularly important.
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MCA, MSc[IT], MTech[IT],MPhil (Comp.Sci), PGDCA, ADCA, Dc. Sc. & Engg.
Implementation of a Stored Program Computer ITCS 3181 Logic and Computer Systems 2014 B. Wilkinson Slides2.ppt Modification date: Oct 16,
Arrays- Part 2 Spring 2013Programming and Data Structure1.
19/10/20151 Data Structures Arrays. 219/10/2015 Learning Objectives Explain initialising arrays and reading data into arrays. Design and write routine/s.
Registers and MAL Lecture 12. The MAL Architecture MAL is a load/store architecture. MAL supports only those addressing modes supported by the MIPS RISC.
Problem Solving for Programming Session 8 Static Data Structures.
Data Structure & File Systems Hun Myoung Park, Ph.D., Public Management and Policy Analysis Program Graduate School of International Relations International.
Pointers. The structure of memory Computer memory is a linear sequence of addressable locations Addresses are numbered starting at zero In personal computers,
CPSC 252 Concrete Data Types Page 1 Overview of Concrete Data Types There are two kinds of data types: Simple (or atomic) – represents a single data item.
Overview of Course Java Review 1. This Course Covers, using Java Abstract data types Design, what you want them to do (OOD) Techniques, used in implementation.
5. Arrays, Pointers and Strings 7 th September IIT Kanpur C Course, Programming club, Fall
Chapter 19 Number Systems. Irvine, Kip R. Assembly Language for Intel-Based Computers, Translating Languages English: Display the sum of A times.
Data Structures and Algorithms Lecture 3 Instructor: Quratulain Date: 8 th September, 2009.
ECE 103 Engineering Programming Chapter 47 Dynamic Memory Alocation Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103.
Execution of an instruction
Memory organization and usage A computer’s memory is, at its lowest level, composed of binary digits (bits). The memory is organized into bytes, which.
Computer Organization and ASSEMBLY LANGUAGE
Pointers. What is pointer l Everything stored in a computer program has a memory address. This is especially true of variables. char c=‘y’; int i=2; According.
1 Data Structures - Part II CS215 Lecture #8. Stacks  Last-In-First-Out (LIFO)  Stacks are often used in programming when data will need to be used.
Homework Finishing up K&R Chapter 6 today Also, K&R 5.7 – 5.9 (skipped earlier)
Addressing Modes Chapter 6 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
C Programming – Part 3 Arrays and Strings.  Collection of variables of the same type  Individual array elements are identified by an integer index 
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
Instruction Sets: Addressing modes and Formats Group #4  Eloy Reyes  Rafael Arevalo  Julio Hernandez  Humood Aljassar Computer Design EEL 4709c Prof:
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 – August 23, 2001.
Assembly - Arrays תרגול 7 מערכים.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Arrays in MIPS Assembly Computer Organization and Assembly Language: Module 6.
Data Handling in Algorithms. Activity 1 Starter Task: Quickly complete the sheet 5mins!
REEM ALMOTIRI Information Technology Department Majmaah University.
ECE 103 Engineering Programming Chapter 23 Multi-Dimensional Arrays Herbert G. Mayer, PSU CS Status 6/24/2014 Initial content copied verbatim from ECE.
1 ENERGY 211 / CME 211 Lecture 4 September 29, 2008.
Arrays. C++ Style Data Structures: Arrays(1) An ordered set (sequence) with a fixed number of elements, all of the same type, where the basic operation.
Arrays. 1D Array Representation In C++ 1-dimensional array x = [a, b, c, d] map into contiguous memory locations Memory abcd start location(x[i]) = start.
1 2-d Arrays. 2 Two Dimensional Arrays We have seen that an array variable can store a list of values Many applications require us to store a table of.
CSI 3125, Data Types, page 1 Data types Outline Primitive data types Structured data types Strings Enumerated types Arrays Records Pointers Reading assignment.
Pointers as arrays C++ Programming Technologies. Pointers vs. Arrays Pointers and arrays are strongly related. In fact, pointers and arrays are interchangeable.
C Programming Lecture 15 Two Dimensional Arrays. Two-Dimensional Arrays b The C language allows arrays of any type, including arrays of arrays. With two.
Strings C supports strings using one-dimensional character arrays. A string is defined as a null-terminated character array. In C, a null is 0. You must.
Data Structure and Algorithms
Arrays in C.
5. Arrays, Pointers and Strings
Lecture 8 Data structures
Introduction to Micro Controllers & Embedded System Design
Presentation transcript:

Data Structures - Part I CS 215 Lecture 7

Motivation  Real programs use abstractions like lists, trees, stacks, and queues.  The data associated with these abstractions must be ordered within memory.  Assembly language does not provide convenient ways to access data in memory like high-level languages do.  It therefore necessary to calculate explicitly the locations of data within the structure.

Memory  A memory cell is a unit of memory with a unique address.  The entire memory is a collection of memory cells.  Each memory cell holds eight bits, or 1 byte.  A word designates the amount of memory used to store an integer, e.g., 1 word = 4 bytes

Byte Addressing  A method of addressing where each byte has a unique address  The ordering of the bytes within the word can either be little-endian or big-endian.  Little-endian numbers the bytes from the least significant to the most signifcant.  Big-endian numbers the bytes from the most significant to the least signifcant.

Storing an integer  Assume a 32-bit word. The number of bits used to store an integer is 32 or 4 bytes. It can also be thought of as an array of 4 bytes.  By convention, the smallest of the four byte addresses is used to indicate the address of the word.  The smallest of the byte addresses in a word must be a multiple of four -- words are aligned

Array  The array is the most important and most general data structure.  All other data structures can be implemented using an array.  The computer memory itself is organized as a large, one- dimensional array.  All uses of the memory are simply allocations of part of this gigantic array.

Allocating Space for Arrays  SAL does not have a facility for declaring arrays.  To allocate space for an array of char {variable:}.byte {value:numelement}  An array of integers or real numbers can be allocated space using {variable:}.word {value:numelement} {variable:}.float {value:numelement}

 If we know how many bytes (given by value ) to allocate to a variable we can directly allocate space by using the.space directive variable:.space value

Example 15.1 ar:.byte 0:7 we can also allocate 7 bytes using ar:.space 7 7 bytes of memory space is allocated to the variable ar. The memory cells are initialized to 0. In the ASCII table 0 is the null character.

Example 15.2 Suppose we want to declare an array of integers that can hold 10 elements. We can declare the array in one the following ways: ar:.word 0:10 ar:.byte 0:40 ar:.space 40 Note: We only need to allocate the total amount of memory space. Each memory cell has the same size of 1 byte. Recall that an integer is 4 bytes. Also the label ar is bound to the first byte of the allocated 40 bytes.

Accessing array elements  To access element i of the array, we must add an offset to the array’s starting address, also called the base address. This is where the label of the array declaration is bound.  We can access the i th element via m[i]  We must make sure that the value of i is the correct displacement between the i th element and the base address.

 m[i] is used to access memory in a byte fashion.  If we want to access.word spaces from memory, we need to use M[i].  In the case of M[i], you must be sure that i is a multiple of 4.

Example ar:.byte 0:20 #20-element array i:.word #holds the array’s base address tmp:.byte... la i, ar #get the base address add i,i,5 #distance to target is 5 bytes move tmp,m[i] #access the target element target element base address address of target element

Finding the element address The formula for finding the address of an element in an array can be generalized to i = b + s*n where b = base address s = size of each element n = the number of elements between the target element and the base address char = 1 byte integer = 4 bytes can be viewed as offset from the base address

Two-dimensional Arrays  The number of bytes needed for the array is found by multiplying the size of each element times the number of elements 2 x 7 array

Example 15.4 To declare a 2 x 7 array of integers, we can do one of the following: ar:.word 0:14 ar:.space 56 7 x 2 x (4 bytes) 14 elements of type integer

Storage Order Row-major order: the array is stored as a sequence of arrays consisting of rows (0,0) (0,1) (0,2)

Storage Order Column-major order: The array is stored as a sequence of arrays consisting of columns instead of rows (0,0) (1,0) (0,1)

Accessing elements in 2D arrays We know that the formula for finding the address of an element is i = b + s*n s*n = s*e*k + s*n’ = s*(e*k + n’) e = number of elements in a row or column k = number of rows or columns to be skipped n’ = the number of elements between the target element and the beginning of a row or column

Example 15.5 Row-major order: e = 4, k = 1, n’ = 2 Column-major order: e = 3, k =2, n’ = target element e*k + n’ = 6 skip 6 elements e*k + n’ = 7 skip 7 elements