

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


To use different shift and rotate instructions To use IMUL instruction for multiplication operations
In last lab you learned how to m anipulate individual bits in an integer, using Boolean operators. In this lab you will learn how to m ove bits around in a num ber, using shift and rotate operations. Operations such as these are particularly useful when controlling various types of hardware devices. Assembly language programmers are experts with bits.
2.1. The Shift operations
The shift operations are used to multiply or divide a number by another number that is a power of 2 (i.e., 2n or 2-n). Multiplication by 2 is achieved by a one-bit lef t shift, while division by 2 is achieved by a one-bit right shif t. The Shif t Arithmetic Right (SAR) instruction is used to manipulate signed num bers. The regular Right Shift (SHR) of a signed num bers effects the sign bit, which could cause numbers to change their sign. The SAR preserves the sign bit by filling the vacated bits with the sign of the num ber. Shift Arithmetic Left (SAL) is identical in operation to SAR.
2.2. Rotate Operations
The rotate operations are very sim ilar to the shift operations, but the bits are shifted out from one end of a num ber and fed back into the other endto fill the vacated bits. They are provided to facilitate the shift of long num bers (i.e., num bers ofm ore than 16 bits). They are also used to reposition a certain bit of a num ber into a desired bit location. The rotate right or left instructions through the carry flag (RCL and RCR) are sim ilarto the regular rotate instructions (ROL and ROR), but the carry flag is considered as a part of the num ber. Hence before the rotate operatin, the carry f lag bit is appended to the num ber as the least signif icant bit in the case of RCL, or as most significant bit in case of RCR.
2.3. Multiplication instructions
2.3.1 MUL Instruction
The MUL (unsigned m ultiply) instruction m ultiplies an 8-, 16-, or 32-bit operand by either AL, AX, and EAX. The single operand is the m lier. The f ollowing table shows the defultip ault multiplicand table shows the default m ultiplicand and product, depending on the size of the multiplier:
Multiplicand Multiplier Product AL r/m8 AX AX r/m16 DX:AX EAX r/m32 EDX:EAX
The register(s) holding the product are twice the size of m ultiplicand and multiplier, guaranteeing that overflow will never occur.
2.3.2 IMUL Instruction
The IMUL (signed m ultiply) instruction m ultiplies an 8-, 16-, or 32-bit operand by either AL, AX, EAX. It has the sam e syntax and uses thesame operands as the MUL instruction. W hat is different is that it preserves the sign of the product.