324_Book

# When there is negative overow because a b is a small

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: ddress 0x100 0x104 0x108 0x10C Value 0xFF 0xAB 0x13 0x11 Register %eax %ecx %edx Value 0x100 0x1 0x3 3.5. ARITHMETIC AND LOGICAL OPERATIONS Fill in the following table showing the effects of the following instructions, both in terms of the register or memory location that will be updated and the resulting value. Instruction addl %ecx,(%eax) subl %edx,4(%eax) imull \$16,(%eax,%edx,4) incl 8(%eax) decl %ecx subl %edx,%eax Destination Value 107 3.5.3 Shift Operations The ﬁnal group consists of shift operations, where the shift amount is given ﬁrst, and the value to shift is given second. Both arithmetic and logical right shifts are possible. The shift amount is encoded as a single byte, since only shifts amounts between 0 and 31 are allowed. The shift amount is given either as an immediate or in the single-byte register element %cl. As Figure 3.6 indicates, there are two names for the left shift instruction: sall and shll. Both have the same effect, ﬁlling from the right with 0s. The right shift instructions differ in that sarl performs an arithmetic shift (ﬁll with copies of the sign bit), whereas shrl performs a logical shift (ﬁll with 0s). Practice Problem 3.5: Suppose we want to generate assembly code for the following C function: int shift_left2_rightn(int x, int n) { x <<= 2; x >>= n; return x; } The following is a portion of the assembly code that performs the actual shifts and leaves the ﬁnal value in register %eax. Two key instructions have been...
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