CS485G Spring 2015 17
11. Result of compilation
pushl %ebp # save base pointer
movl %esp,%ebp # new base pointer
movl 12(%ebp),%eax # $a = y
xorl 8(%ebp),%eax # $a = y ˆ x [t1]
sarl $17,%eax # $a = (y ˆ x) >> 17 [t2]
andl $8185,%eax # $a = t2 & mask [rval]
popl %ebp # retore base pointer
ret # return
20 Control based on condition codes
1. The four condition codes, each Boolean
(a) CF: Carry flag
(b) ZF: Zero flag
(c) SF: Sign flag
(d) OF: Overflow flag (for signed integers)
2. Arithmetic operations implicitly set these flags, but the lea instruc-
tion does not set them.
3. Example: addition t = a + b
(a) sets CF if there is a carry from most significant bit
(b) sets ZF if the t is zero
(c) sets SF if the top bit of t is set (t < 0)
(d) sets OF if there is a two’s complement overflow:
(a > 0 ∧ b > 0 ∧ t < 0) ∨ (a < 0 ∧ b < 0 ∧ t > 0)
4. The compare instruction (cmpl b, a) also sets the flags; it’s like
computing a − b without modifying the destination.
(a) sets CF if there is a carry from most significant bit
(b) sets ZF if a = b
(c) sets SF if a − b < 0
(d) sets OF if there is a two’s complement overflow:
(a > 0 ∧ b < 0 ∧ (a − b) < 0) ∨ (a < 0 ∧ b > 0 ∧ (a − b) > 0)
Kommentare zu diesen Handbüchern