By reading this assembly code we can understand the

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: t determines the form of shifts used for unsigned int’s. Homework Problem 2.36 [Category 2]: You are given the task of writing a procedure int_size_is_32() that yields 1 when run on a machine for which an int is 32 bits, and yields 0 otherwise. Here is a first attempt: 1 2 3 4 5 6 7 8 9 10 11 12 /* The following code does not run properly on some machines */ int bad_int_size_is_32() { /* Set most significant bit (msb) of 32-bit machine */ int set_msb = 1 << 31; /* Shift past msb of 32-bit word */ int beyond_msb = 1 << 32; /* set_msb is nonzero when word size >= 32 beyond_msb is zero when word size <= 32 return set_msb && !beyond_msb; } */ 82 CHAPTER 2. REPRESENTING AND MANIPULATING INFORMATION When compiled and run on a 32-bit SUN SPARC, however, this procedure returns 0. The following compiler message gives us an indication of the problem: warning: left shift count >= width of type A. In what way does our code fail to comply with the C standard? B. Modify the code to run properly on any machine for which int’s are at least 32 bit...
View Full Document

Ask a homework question - tutors are online