324_Book

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: ed to include an assembly-code sequence that explicitly performs unsigned multiplication using the mull instruction as documented in Figure 3.8, as follows: code/asm/okmul.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 /* Uses the extended assembly statement */ int ok_umul(unsigned x, unsigned y, unsigned *dest) { int result; /* Insert the following assembly code: movl x,%eax # Get x mull y # Unsigned multiply by y movl %eax, *dest # Store low-order 4 bytes at dest setae %dl # Set low-order byte movzbl %dl, result # Zero extend to be result */ asm("movl %2,%%eax; mull %3; movl %%eax,%0; setae %%dl; movzbl %%dl,%1" : "=r" (*dest), "=r" (result) /* Outputs */ : "r" (x), "r" (y) /* Inputs */ : "%eax", "%edx" /* Overwrites */ ); return result; } 192 CHAPTER 3. MACHINE-LEVEL REPRESENTATION OF C PROGRAMS code/asm/okmul.c Recall that the mull instruction requires one of its arguments to be in register %eax and is given the second argument as an operand. We indicate this in the asm statement by using a movl to move program value x to %eax and indicating that program value y should be the argument for the mull instruction. The instruction then stores the 8-byte product in two registers with %eax holding the low-order 4 bytes a...
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