Moving left shift at 68k / x86?

I heard that the Motorola 68000 and Intel x86 architectures handle left-shift overflow differently. In particular, 68k LSL and Intel SAL / SHL assembly instructions.

Does anyone know the features of this? Do they set different flags or set them differently? I tried to look at this in the reference manuals, but I don't see any difference. Why do you need to handle this situation differently?

Thanks!

+3
source share
3 answers

X bit is not used. The confusion over the 68000 flags is due to the presence of two left shift commands:

LSL, , . ASL, , V, MSB .

x86 . = 1, OF, , = (MSB XOR CF), , MSB 1- , OF = 1, OF = 0.

> 1, OF undefined.

, ECEE, Univ. . .

+4

:

Motorola 68K:

X — Set according to the last bit shifted out of the operand; 
    unaffected for a shift count of zero. 
N — Set if the result is negative; cleared otherwise. 
Z  — Set if the result is zero; cleared otherwise. 
V — Always cleared. 
C — Set according to the last bit shifted out of the operand; 
    cleared for a shift count of zero. 

Intel x86:

  • CF , ; undefined SHL SHR, ( ) .
  • OF 1- (. "" ); undefined.
  • SF, ZF PF . 0, .
  • AF undefined.

, -. x86, 2 ( ) . , 1 . ( ), OF "" - , , Intel "undefined".

+3

(, Motorola 68000 Reference 1979 .)

It is possible that you are thinking of 68,000 rather strange X bits. The eXtend bit is essentially a copy of the C bit (carry), but it is not affected by non-arithmetic instructions. Suppose, for example, that you add 12-word integers. In x86, you can see something like:

  .
  .
loop:
  ADC AX,[SI]
  ADD SI,2
  INC BX         ; BX is loop index
  CMP BX, 12     ; doh, changes carry (BUG)
  JB  loop

This code does not work because the comparison command resets the carry flag. But in 68000:

  .
  .
loop:
  ADDX.W (A0)+, D0   ; both C and X set the same
  INC.W  D7          ; D7 is loop index
  CMP.W  #12, D7     ; harms C, but X left intact
  BCC  loop

Motorola thought they preferred programmers, but the X business bit turned out to be a bit confusing than it cost.

+2
source

Source: https://habr.com/ru/post/1722534/


All Articles