Volume 3: General-Purpose and System Instructions - Stanford ...

Volume 3: General-Purpose and System Instructions - Stanford ... Volume 3: General-Purpose and System Instructions - Stanford ...

scs.stanford.edu
from scs.stanford.edu More from this publisher
13.07.2015 Views

AMD64 Technology 24594 Rev. 3.10 February 2005rFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsM M M U M M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.General protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe destination operand was in a non-writable segment.X A null data segment was used to reference memory.Page fault, #PF X X A page fault resulted from the execution of the instruction.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.258 SAL, SHL

24594 Rev. 3.10 February 2005 AMD64 TechnologySARShift Arithmetic RightShifts the bits of a register or memory location (first operand) to the right through theCF bit by the number of bit positions in an unsigned immediate value or the CLregister (second operand). The instruction discards bits shifted out of the CF flag. Atthe end of the shift operation, the CF flag contains the last bit shifted out of the firstoperand.The SAR instruction does not change the sign bit of the target operand. For each bitshift, it copies the sign bit to the next bit, preserving the sign of the result.The processor masks the upper three bits of the count operand, thus restricting thecount to a number between 0 and 31. When the destination is 64 bits wide, theprocessor masks the upper two bits of the count, providing a count in the range of 0 to63.For 1-bit shifts, the instruction clears the OF flag to 0. When the shift count is greaterthan 1, the OF flag is undefined.If the shift count is 0, no flags are modified.Although the SAR instruction effectively divides the operand by a power of 2, thebehavior is different from the IDIV instruction. For example, shifting –11(FFFFFFF5h) by two bits to the right (that is, divide –11 by 4), gives a result ofFFFFFFFDh, or –3, whereas the IDIV instruction for dividing –11 by 4 gives a result of–2. This is because the IDIV instruction rounds off the quotient to zero, whereas theSAR instruction rounds off the remainder to zero for positive dividends and tonegative infinity for negative dividends. So, for positive operands, SAR behaves likethe corresponding IDIV instruction. For negative operands, it gives the same result ifand only if all the shifted-out bits are zeroes; otherwise, the result is smaller by 1.Mnemonic Opcode DescriptionSAR reg/mem8, 1 D0 /7 Shift a signed 8-bit register or memory operand right 1 bit.SAR reg/mem8, CL D2 /7SAR reg/mem8, imm8C0 /7 ibShift a signed 8-bit register or memory operand right the numberof bits specified in the CL register.Shift a signed 8-bit register or memory operand right the numberof bits specified by an 8-bit immediate value.SAR reg/mem16, 1 D1 /7 Shift a signed 16-bit register or memory operand right 1 bit.SAR 259

AMD64 Technology 24594 Rev. 3.10 February 2005rFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsM M M U M M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe destination oper<strong>and</strong> was in a non-writable segment.X A null data segment was used to reference memory.Page fault, #PF X X A page fault resulted from the execution of the instruction.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.258 SAL, SHL

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!