324_Book

# With the examples and exercises in this book we

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: , the code generated for this procedure is identical to that for the procedure: 1 2 3 4 unsigned copy(unsigned u) { return u; } The body of both procedures is just a single instruction: 1 movl 8(%ebp),%eax This demonstrates the lack of type information in assembly code. The argument will be at offset 8 relative to %ebp regardless of whether it is a float or an unsigned. The procedure simply copies its argument as the return value without modifying any bits. When using unions combining data types of different sizes, byte ordering issues can become important. For example suppose we write a procedure that will create an 8-byte double using the bit patterns given by two 4-byte unsigned’s: 1 2 3 4 5 6 7 8 9 10 11 double bit2double(unsigned word0, unsigned word1) { union { double d; unsigned u[2]; } temp; temp.u[0] = word0; temp.u[1] = word1; return temp.d; } 3.9. HETEROGENEOUS DATA STRUCTURES 159 On a little-endian machine such as IA32, argument word0 will become the low-order four bytes of d, while word1 will become the high-order four bytes. On a big-endian machine, the role of the two arguments will be reversed. Practice Problem 3.22: Consider the following union declaration. union ele { struct { int *p; int y; } e1; struct { int x; union ele *next; } e2; }; This declaration illustrates that structures can be embedded within unions. The following procedure (with some expressions omitted) operates on link list having these unions as list elements: void proc (union ele *up...
View Full Document

## This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online