“当 $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