03 Addresses and Data Representations


[MUSIC]. There's a lot more to talk about in how we organize and address data in memory. Let's start with a very important distinction between addresses and pointers. You'll notice that I've drawn a memory on this slide, that has bytes grouped into four byte units. That, that are 32 byte words. You'll also notice that the first word is shown at address 0. The second word at address four then eight. And then c. This is now in hexadecimal notation. So c corresponds to the decimal 12. Hexadecimal one zero corresponds to the decimal 16. So here we're adding four for each address as we move down our memory, since we're takling about words. In this particular case, I've shown you the detail of one word that happens to have the value 00001015F in hexadecimal. That corresponds to the decimal number 351. Now, an address is a location in memory, as we've said. So we have these different addresses here from 00 hex to down to 24 hex, for all these various locations in memory. A pointer, unlike an address, is a data object that contains an address. So, let me give you an example. I can put a pointer to that address of 0004, at a different memory location, let's say at the address 001C. So now you'll see that what I've shown in the memory is that at that location, 001C, I have a value that happens to be the address of another location in memory. That's what makes it a pointer, the fact that I interpret it that way. I could have just as easily have interpreted that number as just the number 4. That would have been a beta value stored at that location but I am now choosing to interpret it as an address in which case it is a pointer to a different location. Let's take a look at another example I can have a pointer to that location in the address 0024 by placing the value 0000001C at the location 0024 in memory. Again, I am choosing to interpret this as a, as an address, therefore, it is a pointer to another memory location. If I had interpreted as just a number, what number would it be? It would be the, the hex number 1C, which is 16 plus 12, or 28 decimal. And not an address. Okay. So, it's purely a an interpretation question. Will I interpret this value as a pointer and therefore an address to another location. Or will I interpret it as a value. That's the distinction between addresses and pointers. Another example is if in that memory location zero zero one four I had put the value zero c. Well is that an address? Well it could be an address. It's part of our memory certainly, there is a, a, word with that address but am I interpreting it as an address. Well I maybe, or it maybe just a number 12 corresponding to that hexidecimal c. In in C, in C and in Java we have many different data types. And how we represent them in our machines varies because of the amount of bits that we need to represent them. So, this table just gives you a quick comparison of how that's done. In both the 32-bit machine, and a 64-bit machine. So, you'll see that a boolean data type requires just one byte. Now, in reality, we can probably do it in one bit, but it's since we address things in terms of bytes It's going to take up eight bits to do that. a byte, of course, requires one byte. In C, a byte is also a character in a character string. Java has a more complex structure for characters we'll, that we'll get to a little bit later on. That takes up two bytes per character. a, a short integer or a 16-bit integer takes up two bytes in both. While a regular integer takes up four. This is, based on the fact that we have a lot of programs that were written for 32-bit machines. A floating point number also takes up four bytes. We'll discuss. How we represent floaty point numbers later. On 64-bit machines, we also have a long-end data type, an integer that takes up 64 bits or 8 bytes. we also have double floats and long longs and long doubles that can be particularly Large range of numbers taking up 16 bytes. And then we have addresses or references or pointers which in a 32 bit machine can be up to four bytes by definition. And in 64 bit machine can be up to eight bytes by definition. Alright the next question is how do we order the bytes within a word, there's actually two ways to do that one way is what's called big endian and the other is little endian. Yeah. And these two different conventions come from the names for them come from Gulliver's Travels. You can read about this in the in the textbook by Bryant and O'Halloran that we're using as a reference text for this class. but basically the idea is that in in a big endian notation, the most significant byte of the number goes to the lowest address. and in the little endian notation, the least significant byte goes to the lowest address. So let's do a quick little example to demonstrate that. Suppose I have the following eight digit hexadecimal number. 01234567, okay. And I want to store that at a word at address 100 hex. Now, in a big Endian computer system, it would be stored as follows. Okay, the most significant byte In other words the highest ordered digit go to the first byte. Then the next two go to the next byte. The and so on until the lowest significant digits go in the last one at 103. And little in the end notation well it's in the opposite order. The lowest order digits come in first, at address 100. And the highest order digits end up going at 103. These are two, these are the two natural choices to do, and you notice that the little endian one looks a little backwards from our original number. but that is in fact, the one that the x86 architecture uses. So, that's what we'll be seeing a lot in the memory maps that we'll be looking at, and when we look at memory values and memory, they will be arranged this way. Just a quick another example. looking at the decimal value 12345. in binary that's represented right below as those binary digits which are the hex three zero three nine. Okay so you'll see that in a 32 bit architecture. We put the least significant digits at the lowest address. And the most significant digits at the highest address. While it's in the opposite order on a Big Endian Architecture. for negative number, and don't worry about the, this right now, but this is the number minus 1, 2, 3, 4, 5 represented in two's complement notation that we will get to a bit later. But again, the lowest significant digits are represented first while in the big end, it's the other way around. Now, here you'll see why little end might be somehow, somewhat advantageous in a 32-bit architecture to a 64-bit architecture, you'll notice that the correspondence of those locations is the same. When then there's a lot more zeros, of course, in the 64-bit notation to pad things out. While in the big NDN notation we can't just simply extend in this direction with zeros. We have to actually go in the other direction, and move this down, which is a bit more complex.

Wyszukiwarka

Podobne podstrony:
Psychuszki, czyli medycyna represyjna w ZSRR
02 Representation of Integers
GUŁag w radzieckim systemie represji do 1941 r
representing graphical user interfaces64834
risk list informal representation?44CAAA
representing interfaces to external systems?6D84D3
What Makes Anthropomorphism Natural Intuitive Ontology and Cultural Representations
Fraassen; The Representation of Nature in Physics A Reflection On Adolf Grünbaum s Early Writings
GUŁag w systemie represji w ZSRR w latach 1945 1953 r
Pirenne Delforge V , Pausanias Cults of the Gods and Representation of the Divine
Layered Perceptual Representation
Represje stosowane wobec osób zatrzymanych 1976

więcej podobnych podstron