13_Data_Structures_with_ink

13_Data_Structures_with_ink - Memory and Data Structures...

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

View Full Document Right Arrow Icon
CMPE12 Cyrus Bazeghi Memory and Data Structures Arrays, Stacks, Queues (Ch 10 & 16)
Background image of page 1

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

View Full DocumentRight Arrow Icon
CMPE12 Cyrus Bazeghi 2 Memory • This is the “RAM” in a system We have seen labels and addresses point to pieces of memory storing: words bytes strings numbers Memory is just a collection of bits We could use it to represent integers Or as an arbitrary set of bits
Background image of page 2
CMPE12 Cyrus Bazeghi 3 Memory Treat memory as a giant array Compiler or programmer decides what use to make of it. The element numbering starts at 0 The element number is an address •In “C” to allocate some memory: char m[size_of_array];
Background image of page 3

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

View Full DocumentRight Arrow Icon
CMPE12 Cyrus Bazeghi 4 Storage of Data LC- 3 architecture is “word addressable” meaning that all addresses are “word” addresses. This means the smallest unit of memory we can allocate is 16-bits, a word. • Use „LD‟ (load) and „ST‟ (store) to access this unit (or LDR & STR).
Background image of page 4
CMPE12 Cyrus Bazeghi 5 Example mychar .BLKW 1 newline .FILL xA LD R1, newline GETC ST R0, mychar JSR Sub ; R2=R1-R0 BRz found_newline found_newline Storage of bytes
Background image of page 5

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

View Full DocumentRight Arrow Icon
CMPE12 Cyrus Bazeghi 6 Storage of bytes The data is placed in memory like this at start up (assuming data section starts at address 1). The “mychar” variable will change to the value of the character entered by the user once stored. 0 1 00 00 2 00 0A 3 Memory newline variable mychar variable addresses
Background image of page 6
CMPE12 Cyrus Bazeghi 7 Pointers and Arrays We've seen examples of both of these in our LC-3 programs, lets see how these work in “C” Pointer Address of a variable in memory Allows us to indirectly access variables in other words, we can talk about its address rather than its value Array A list of values arranged sequentially in memory Example: a list of telephone numbers Expression a[4] refers to the 5th element of the array a
Background image of page 7

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

View Full DocumentRight Arrow Icon
CMPE12 Cyrus Bazeghi 8 Arrays Array implementation is very important Most assembly languages have only basic concept of arrays (BLKW) From an array, any other data structure we might want can be built
Background image of page 8
CMPE12 Cyrus Bazeghi 9 Properties of arrays: Each element is the same size Elements are stored contiguously First element at the smallest memory address In assembly language we must Allocate correct amount of space for an array Map array addresses to memory addresses Arrays
Background image of page 9

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

View Full DocumentRight Arrow Icon
CMPE12 Cyrus Bazeghi 10 Arrays LC-3 declarations of arrays within memory To allocate a portion of memory (more than a single variable‟s worth) variablename .BLKW numelements numelements is just that, numbering starts at 0 (as in C)
Background image of page 10
CMPE12 Cyrus Bazeghi 11 Array of Integers Calculating the address of an array element int myarray[7] /* C */ myarray .BLKW 7 ; LC-3 •If base address of “myarray” is 25 Address of myarray[4] = 25 + 4 = 29 Which is base address + distance from the first element 0 25 1 2 3 4 5 26 27 28 29 2A 6 2B Element index address myarray
Background image of page 11

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

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

Page1 / 40

13_Data_Structures_with_ink - Memory and Data Structures...

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

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