116 chapter 3 machine level representation of c

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: in which the stack grows toward lower addresses, i.e., the low-order bytes of the product will have lower addresses than the high-order bytes. 110 CHAPTER 3. MACHINE-LEVEL REPRESENTATION OF C PROGRAMS Our earlier table of arithmetic operations (Figure 3.6) does not list any division or modulus operations. These operations are provided by the single-operand divide instructions similar to the single-operand multiply instructions. The signed division instruction idivl takes as dividend the 64-bit quantity in registers %edx (high-order 32 bits) and %eax (low-order 32 bits). The divisor is given as the instruction operand. The instructions store the quotient in register %eax and the remainder in register %edx. The cltd1 instruction can be used to form the 64-bit dividend from a 32-bit value stored in register %eax. This instruction sign extends %eax into %edx. As an example, suppose we have signed numbers x and y stored in positions and ½¾ relative to %ebp, and we want to store values x/y and x%y on the stack. The code would proceed as follows: x at %ebp+8, y at %ebp+12 1 2 3 4 5 movl 8(%ebp),%eax cltd idivl 12(%ebp) pushl %eax pushl %edx Put x in %eax Sign extend into %edx Divide by y Push x / y Push x % y The divl instruction performs unsigned division. Typically...
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