Unformatted text preview: ves you a chance to test your understanding of operands and the arithmetic instructions. Instruction addl %ecx,(%eax) subl %edx,4(%eax) imull $16,(%eax,%edx,4) incl 8(%eax) decl %ecx subl %edx,%eax Problem 3.5 Solution: [Pg. 107] This exercise gives you a chance to generate a little bit of assembly code. The solution code was generated by GCC. By loading parameter n in register %ecx, it can then use byte register %cl to specify the shift amount for the sarl instruction.
1 2 3 4
·Ü Ü·Ý Ü· Ý ·Ü ½¼ · Ý · Ü · ¾Ý Result Destination 0x100 0x104 0x10C 0x108 %ecx %eax Value 0x100 0xA8 0x110 0x14 0x0 0xFD movl movl sall sarl 12(%ebp),%ecx 8(%ebp),%eax $2,%eax %cl,%eax Get x Get n x <<= 2 x >>= n Problem 3.6 Solution: [Pg. 108] This instruction is used to set register %edx to 0, exploiting the property that corresponds to the C statement i = 0. ÜˆÜ ¼ for any Ü. It This is an example of an assembly language idiom—a fragment of code that is often generated to fulﬁll a special purpose. Recognizing such idioms is one step in becoming proﬁcient at read...
View Full Document