Mmix NEG和NEGU操作码

时间:2013-06-06 16:16:57

标签: mmix

根据NEG和NEGU的定义,

NEG $X,Y,$Z (negate signed): s($X) := Y - s($Z).
NEGU $X,Y,$Z (negate unsigned): u($X) := (Y - u($Z)) mod 2^64.

我们假设$Z = s(-1)u(2^64 - 1)。然后第一个操作码会在$X时将值1放入Y = 0寄存器,而最近的操作码会因u(-(2^64 - 1)) mod 2^64 = 1而得到相同的结果。我对么? NEG时,$Z = -2^63指令是否会引发溢出异常?

1 个答案:

答案 0 :(得分:1)

简短回答“当$ Z = -2 ^ 63时,NEG指令是否应该引发溢出异常?”

yes, but you probably already suspected that.

逻辑上,NEG $ X,0,-2 ^ 63应该给出2 ^ 63,这超出了有符号正整数的范围,因而溢出。但是,如果你像我一样,你需要证明实际上发生了整数溢出。这是:

t       IS      $255

    LOC     #20          //handle the integer overflow event
    PUSHJ   255,Err
    PUT     rJ,$255
    GET     $255,rB
    RESUME

        LOC     #100
Main    SET     t,#4000
        PUT     rA,t        //set the integer overflow event bit
        SETH    $0,#8000
        NEG     $1,0,$0
        GETA    t,End
        TRAP    0,Fputs,StdOut
        TRAP    0,Halt,0
End     BYTE    "End of program",#a,0

Err     SET     $0,$255           //overflow subroutine, prints out message
        GETA    t,Emes
        TRAP    0,Fputs,StdOut
        GET     t,rW
        INCL    t,4
        PUT     rW,t
        SET     $255,$0
        POP     0,0
Emes    BYTE    "Error: integer overflow",#a,0