This preview shows page 1. Sign up to view the full content.
Unformatted text preview: mbler. We illustrate the use of asm by an example where having access to the condition codes can be useful. Consider functions with the following prototypes:
int ok_smul(int x, int y, int *dest); int ok_umul(unsigned x, unsigned y, unsigned *dest); Each is supposed to compute the product of arguments x and y and store the result in the memory location speciﬁed by argument dest. As return values, they should return 0 when the multiplication overﬂows and 1 when it does not. We have separate functions for signed and unsigned multiplication, since they overﬂow under different circumstances. Examining the documentation for the IA32 multiply instructions mul and imul, we see that both set the carry ﬂag CF when they overﬂow. Examining Figure 3.9, we see that the instruction setae can be used to set the low-order byte of a register to 0 when this ﬂag is set and to 1 otherwise. Thus, we wish to insert this instruction into the sequence generated by the compiler. In an attempt to use the least amount of both assembly code and detailed analysis, we attempt to implement ok_smul with the following code:
View Full Document
- Spring '10
- The American