home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / intel / 2993 < prev    next >
Encoding:
Internet Message Format  |  1993-01-11  |  5.0 KB

  1. Path: sparky!uunet!gatech!udel!wupost!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!ira.uka.de!uka!uka!news
  2. From: S_JUFFA@IRAV1.ira.uka.de (|S| Norbert Juffa)
  3. Newsgroups: comp.sys.intel
  4. Subject: Re: Setting of flags by "Shr" on different processors.
  5. Date: 11 Jan 1993 13:06:40 GMT
  6. Organization: University of Karlsruhe, FRG
  7. Lines: 152
  8. Distribution: world
  9. Message-ID: <1irrd0INNdv0@iraul1.ira.uka.de>
  10. References: <1993Jan7.154426.3421@odin.diku.dk> <1993Jan8.143630.14931@bilver.uucp>
  11. NNTP-Posting-Host: irav1.ira.uka.de
  12. X-News-Reader: VMS NEWS 1.25
  13. In-Reply-To: wbeebe@bilver.uucp's message of Fri, 8 Jan 1993 14:36:30 GMT
  14.  
  15. In <1993Jan8.143630.14931@bilver.uucp> wbeebe@bilver.uucp writes:
  16.  
  17. > In article <1993Jan7.154426.3421@odin.diku.dk> terra@diku.dk (Morten Welinder) writes:
  18. > >    Mov    Ax,0
  19. > >    Mov    Cl,0
  20. > >    Cmp    Ax,-1        ; Clear zero flag
  21. > >    Shr    Ax,Cl        ; Result is zero.
  22. > If I'm not mistaken, shift instructions with CL=0 will not execute, but
  23. > will be handled as NOPs. I'm not sure what you complaining about.
  24. > -- 
  25. > William H. Beebe, Jr. - wbeebe@bilver.UUCP
  26. >                  UUCP - {ucf-cs,peora,uunet}!tarpit!bilver!wbeebe
  27. >                       - bilver Public Access Unix, Orlando FL
  28. >                       - (407)644-8327  2400/9600  24 hours  8N1
  29.  
  30.  
  31. There has been a discussion here recently about the operation of the shift
  32. instructions on Intel's 80x86 processors in the case that the shift count
  33. is zero. The descriptions of the shift instructions in Intel's programmer's
  34. manuals seem to be incomplete with respect to this problem. Only the 286
  35. programmer's manual mentions that the flags are unaffected by the shift
  36. instructions if the shift count is zero. Note that, starting with the Intel
  37. 80186, shift counts are masked off to the range 0..31. If the count is zero
  38. after the masking operation, the shift instructions will not affect the flags
  39. either. I tested the shift instructions on the 8086 and the 80386 and found
  40. that indeed the flags are unaffected if the shift count is zero. Obviously,
  41. shift instructions with a shift count of zero are executed as NOPs on all
  42. 80x86 CPUs. This includes the shift double instructions SHLD and SHRD, for
  43. which the 386 and 486 programmer's manuals explicitly state that a shift
  44. count of zero transforms the instructions into NOPs.
  45.  
  46. Norbert Juffa   (s_juffa@iravcl.ira.uka.de)
  47.  
  48.  
  49. The relevant parts of the description of the shift instructions from Intel's
  50. manuals follow:
  51.  
  52.  
  53. Description of shift instructions in Intel 386 and 486 programmer's manuals
  54. ---------------------------------------------------------------------------
  55.  
  56. Operation
  57.  
  58. (* COUNT is the second parameter *)
  59. (temp) <- COUNT;
  60. WHILE (temp <> 0)
  61. DO
  62.   IF instruction is SAL or SHL
  63.   THEN CF <- high-order bit of r/m;
  64.   FI;
  65.   IF instruction is SAR or SHR
  66.   THEN CF <- low-order bit of r/m;
  67.   FI;
  68.   IF instruction = SAL or SHL
  69.   THEN r/m <- r/m*2;
  70.   FI;
  71.   IF instruction = SAR
  72.   THEN r/m <- r/m /2 (*Signed divide, rounding toward negative infinity*);
  73.   FI;
  74.   IF instruction = SHR
  75.   THEN r/m <- r/m /2; (*Unsigned divide*);
  76.   FI;
  77.   temp <- temp - 1;
  78. OD;
  79. (* Determine overflow for the various instructions *)
  80. IF COUNT = 1
  81. THEN
  82.   IF instruction is SAL or SHL
  83.   THEN OF <- high-order bit of r/m <> (CF);
  84.   FI;
  85.   IF instruction is SAR
  86.   THEN OF <- 0;
  87.   FI;
  88.   IF instruction is SHR
  89.   THEN OF <- high-order bit of operand;
  90.   FI;
  91. ELSE OF <- undefined;
  92. FI;
  93.  
  94.  
  95. Description
  96.  
  97. [...]
  98.  
  99.  
  100. Flags Affected
  101.  
  102. The OF flag is affected for single shifts; the OF flag is undefined for
  103. multiple shifts; the CF, ZF, PF, and SF flags are set according to the result.
  104.  
  105.  
  106.  
  107. Description of shift instructions in Intel 286 programmer's manual
  108. ------------------------------------------------------------------
  109.  
  110. Flags modified
  111.  
  112. Overflow (only for single-shift form), carry, zero, parity, sign
  113.  
  114.  
  115. Flags undefined
  116.  
  117. Auxiliary carry; also overflow for multibit shifts (only).
  118.  
  119.  
  120. Operation
  121.  
  122. [...]
  123. The overflow flag is set only if the single-shift forms of the instructions are
  124. used. For left shifts, it is set to 0 if the high bit of the answer is the same
  125. as the result carry flag (i.e., the top two bits of the original operand were
  126. the same); it is set to 1 if they are different. For SAR it is set to 0 for all
  127. single shifts. For SHR, it is set to the high-order bit of the original operand.
  128. Neither flag bit is modified when the count value is zero.
  129.  
  130.  
  131.  
  132. Description of shift left instruction in Intel 8086 programmer's manual
  133. -----------------------------------------------------------------------
  134.  
  135. Operation
  136.  
  137. (temp) <- COUNT
  138. do while (temp) != 0
  139.   (CF) <- high-order bit of (EA)
  140.   (EA) <- (EA) * 2
  141.   (temp) <- (temp) - 1
  142. if COUNT = 1 then
  143.   if high-order bit of (EA) != (CE)
  144.      then (OF) <- 1
  145.   else (OF) <- 0
  146. else (OF) undefined
  147.  
  148.  
  149. Flags affected
  150.  
  151. CF, OF, PF, SF, ZF
  152. AF undefined
  153.  
  154.  
  155. Description
  156.  
  157. SHL/SAL destination,count
  158.  
  159. SHL and SAL (Shift Logical Left and Shift Arithmetic Left) perform the same
  160. operation and are physically the same instruction. The destination byte or
  161. word is shifted left by the number of bits specified in the count operand.
  162. Zeros are shifted in on the right. If the sign bit retains its original value,
  163. then OF is cleared.
  164.