var i:longint;begini:=$90123456;
i:=i shr 31;endi  的结果居然不是 1

解决方案 »

  1.   

    在Delphi中运行是1。
    longint是32位的,i shr 31如果结果不是1,那么就是0了。另,$90123456已经超出longint的最大范围,你使用Int64看看。—————————————————————————————————
    宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
    —————————————————————————————————
      

  2.   

    我用Turbo Debugger 调试得到了如下汇编指令shrd   ax,dx,cl
    shr    dx,cl调用前寄存器的值
     ax 3456    dx 9012  cx 001F调用后
     ax 685D    dx 0000
      

  3.   

    http://www.emsps.com/oldtools/borpasv.htm
    Borland Pascal with Objects 7.01 - ... The only severe bug which was eliminated was the shift bug (SHL and SHR) for _longint_ operands with shift values between 16 and 31, which are unreliable if the code is executed on a 386+. On some processors they produce garbage -- on some processors they work. The implementors of 7.0 used a 386 opcode which would produce an undefined result under these circumstances. A solution to avoid this bug with 7.0 is to introduce a global variable. Save8086:byte; and surround parts of code using these SHIFT types (SHL or SHR) by Save8086:=Test8086; Test8086:=0; { Your code } Test8086:=Save8086; This will slow down the SHIFTs but they are correct because they will be executed using 16-bit registers with the correct TP 4.0-6.0 implementation. 谢谢 我已经找到答案了