Microprocessor Assembly Language Conversion Instructions Conversion Instructions MOVZX

Microprocessor & Assembly Language Conversion Instructions

Conversion Instructions • MOVZX, MOVSX, CBW, CWDE, and CDQ • Most of these instructions sign or zero extend values movzx dest, src ; Dest must be twice the size of src. movsx dest, src ; Dest must be twice the size of src. cbw cwde cdq bswap reg 32 xlat ; Special form allows an operand

MOVZX Instruction • MOVZX (move and zero-extend) – Fills (extends) the upper part of the destination with zeros – Used to copy a small source into a larger destination – Destination must be a register – movzx ax, cl

MOVSX Instruction • MOVSX (move and sign-extend) – Fills (extends) the upper part of the destination register with a copy of the source operand's sign bit – Used to copy a small source into a larger destination – movsx ax, bl

Cbw, cwde and cdq Instructions • The cbw (convert byte to word) instruction sign extends the eight bit value in AL to AX • The cwd (convert word to double word) instruction sign extends the 16 bit value in AX to 32 bits and places the result in DX: AX • The cwde instruction sign extends the 16 bit value in AX to 32 bits and places the result in EAX by copying bit 15 of AX throughout bits 16. . 31 of EAX • The cdq (Convert Double to Quad) instruction sign extends the 32 bit value in eax to 64 bits and places the result in edx: eax by copying bit 31 of eax throughout bits 0. . 31 of edx.

BSWAP Instruction • The BSWAP (byte swap) instruction is available only in the 80486–Pentium 4 microprocessors. • This instruction takes the contents of any 32 -bit register and swaps the first byte with the fourth, and the second with the third • The general form: BSWAP reg 32 • For example, the BSWAP EAX instruction with EAX = 00112233 H swaps bytes in EAX, resulting in EAX = 33221100 H • This instruction is used to convert data between the big and little endian forms.

XLAT Instruction • The XLAT instruction translates the value in the al register based on a lookup table in memory. It does the following: temp = AL+BX ; This is the only instruction that adds an 8 -bit number to a l 6 - bit number AL = DS: [temp] • If AL contains four, XLAT replaces the value in al with the fifth item (offset four) within the table pointed at by DS: BX • The XLAT instruction takes the form: XLAT

XLAT Example • Suppose that a 7 -segment LED display lookup table is stored in memory at address TABLE. The XLAT instruction then uses the lookup table to translate the BCD number in AL to a 7 segment code in AL. If the TABLE = 1000 H, DS = 1000 H and the initial value of AL = 05 H (5 BCD) what the content of AL after this program?
- Slides: 8