正在加载图片...
grows toward higher addresses; the stack goes in at the top of memory and grows down. The system is responsible to see that they never collide(a stack crash). When it all goes together, it looks like Fig. 87. 2 [Aho et al., 1986] There is one last tidbit that an assembly programmer must be aware of in looking at memory. Just as some human alphabets are written left to right and some right to left(not to mention top to bottom), computer manufacturers have chosen to disagree on how to arrange words in memory. The two schemes are called big-endian and little-endian(after which end of a number goes in the program lowest-numbered byte and also after a marvelous episode in Gulliver's Travels) The easiest way to perceive how it is done in the two systems is to think of all numbers as being written in conventional order(left to right), but for big-endian you start counting on the upper left of the page and on little-endian you start counting on the upy,l byte, thIs easy description makes big-endian text read er right(see Fig 87.1). Since each character in a text block is a number of length mal order(left to right)but little-endian text reads from right to left. Figure 87.3 shows the sentence This is a sentence " followed by the two hexadecimal HEX)numbers 01020304 and OAOBOCOD written to consecutive bytes in the two systems. Why must we bring this up? Because anyone working in assembly language must know how the bytes are arranged. Furthermore, two of the systems we are considering are big-endian and one(the VAX) is little-endian. which is the better system? Either one. It is having both of them that is a nuisance Onhs you look at Fig. 87.3, undoubtedly you will prefer big-endian, but that is because it appeals to your prejudices. In truth, either works well. what is FIGURE 87.2 Layout of a important is that you be able to direct your program to go fetch the item of dynamic storage in memory. choice. In both systems, you use the lowest-numbered byte to indicate the item of choice. Thus, for the number 01020304, the address will be 13. For the big-endian system, 13 will point to ne byte containing 04 and for the little-endian system, it will point at the byte containing o1 Figure 87.3 contains a problem for some computers which we alluded to in the discussion of Fig. 87.1.We have arranged the bytes to be four in a row as in Fig. 87. 1. That is the way that the memory is arranged in two of our three machines. (In the 68000, there are only two columns. )A good way to look at the fetch operation is that the memory always delivers a whole row and then the processor must acquire the parts that it wants and then properly arrange them. (This is the effect if not always the method. )Some processors--the VAX being a conspicuous example-are willing to undertake getting a longword by fetching two longwords and then iecing together the parts that it wants. Others(in our case, the 68000 and the SPARC) are not so accommo- dating. Those machines opt for simplicity and speed and require that the program keep its data aligned. To use one of those machines, you(or the compiler or assembler)must rearrange Fig 87.3 by inserting a null byt into Fig. 87. 2. This modification is shown in Fig. 87.4. With this modification, all three machines could fetch the two numbers in one operation without rearrangement. Look closely at the numbers 01020304 and OAOBOCOD in Fig. 87. 4. Notice that for both configurations, the numbers read from left to right and that(visually) they appear to be in the same place. Furthermore, as pointed out in the discussion of Fig. 87.3, the"beginning "or address of each of the numbers is identical. However, the byte that is pointed at by the address is not the same and the internal bytes do not have the same addresses. Getting big-endian and little-endian machines in a conversation is not easy. It proves to be even more muddled than these figures suggest a delightful and cogent discussion of the whole issue is found in Cohen [1981 The principal objective in this whole section has been accomplished if looking at Fig. 87. 4 and given the command to load a byte from location 0000 0019, you get the number OB in the big-endian machine and oC in the little-endian machine If you are not already familiar with storing structures in memory, look at the string(sentence)and ask how those letters get in memory. To begin with, every typeable symbol and all of the unprintable actions such as tabbing and carriage returns have been assigned a numerical value from the aSciI code. Each assignment is a byte-long number. What"This"really looks like(HEX, left to right) is 54 68 69 73. The spaces are HEX 20 the period 2E. With the alignment null byte at the end, this list of characters forms a proper C string. It is a structure of 20 bytes. A structure of any number of bytes can be stored, but from the assembly point of view, e 2000 by CRC Press LLC© 2000 by CRC Press LLC grows toward higher addresses; the stack goes in at the top of memory and grows down. The system is responsible to see that they never collide (a stack crash). When it all goes together, it looks like Fig. 87.2 [Aho et al., 1986]. There is one last tidbit that an assembly programmer must be aware of in looking at memory. Just as some human alphabets are written left to right and some right to left (not to mention top to bottom), computer manufacturers have chosen to disagree on how to arrange words in memory. The two schemes are called big-endian and little-endian (after which end of a number goes in the lowest-numbered byte and also after a marvelous episode in Gulliver’s Travels). The easiest way to perceive how it is done in the two systems is to think of all numbers as being written in conventional order (left to right), but for big-endian you start counting on the upper left of the page and on little-endian you start counting on the upper right (see Fig. 87.1). Since each character in a text block is a number of length 1 byte, this easy description makes big-endian text read in normal order (left to right) but little-endian text reads from right to left. Figure 87.3 shows the sentence “This is a sentence” followed by the two hexadecimal (HEX) numbers 01020304 and 0A0B0C0D written to consecutive bytes in the two systems. Why must we bring this up? Because anyone working in assembly language must know how the bytes are arranged. Furthermore, two of the systems we are considering are big-endian and one (the VAX) is little-endian. Which is the better system? Either one. It is having both of them that is a nuisance. As you look at Fig. 87.3, undoubtedly you will prefer big-endian, but that is only because it appeals to your prejudices. In truth, either works well. What is important is that you be able to direct your program to go fetch the item of choice. In both systems, you use the lowest-numbered byte to indicate the item of choice. Thus, for the number 01020304, the address will be 13. For the big-endian system, 13 will point to the byte containing 04 and for the little-endian system, it will point at the byte containing 01. Figure 87.3 contains a problem for some computers which we alluded to in the discussion of Fig. 87.1. We have arranged the bytes to be four in a row as in Fig. 87.1. That is the way that the memory is arranged in two of our three machines. (In the 68000, there are only two columns.) A good way to look at the fetch operation is that the memory always delivers a whole row and then the processor must acquire the parts that it wants and then properly arrange them. (This is the effect if not always the method.) Some processors—the VAX being a conspicuous example—are willing to undertake getting a longword by fetching two longwords and then piecing together the parts that it wants. Others (in our case, the 68000 and the SPARC) are not so accommo￾dating. Those machines opt for simplicity and speed and require that the program keep its data aligned. To use one of those machines, you (or the compiler or assembler) must rearrange Fig. 87.3 by inserting a null byte into Fig. 87.2. This modification is shown in Fig. 87.4. With this modification, all three machines could fetch the two numbers in one operation without rearrangement. Look closely at the numbers 01020304 and 0A0B0C0D in Fig. 87.4. Notice that for both configurations, the numbers read from left to right and that (visually) they appear to be in the same place. Furthermore, as pointed out in the discussion of Fig. 87.3, the “beginning” or address of each of the numbers is identical. However, the byte that is pointed at by the address is not the same and the internal bytes do not have the same addresses. Getting big-endian and little-endian machines in a conversation is not easy. It proves to be even more muddled than these figures suggest. A delightful and cogent discussion of the whole issue is found in Cohen [1981]. The principal objective in this whole section has been accomplished if looking at Fig. 87.4 and given the command to load a byte from location 0000 0019, you get the number 0B in the big-endian machine and 0C in the little-endian machine. If you are not already familiar with storing structures in memory, look at the string (sentence) and ask how those letters get in memory. To begin with, every typeable symbol and all of the unprintable actions such as tabbing and carriage returns have been assigned a numerical value from the ASCII code. Each assignment is a byte-long number. What “This” really looks like (HEX, left to right) is 54 68 69 73. The spaces are HEX 20; the period 2E. With the alignment null byte at the end, this list of characters forms a proper C string. It is a structure of 20 bytes. A structure of any number of bytes can be stored, but from the assembly point of view, FIGURE 87.2 Layout of a program, static storage, and dynamic storage in memory
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有