Page 1 of 1

关于 ULP 的 SUB 指令产生 ALU overflow 的问题

Posted: Wed Dec 26, 2018 1:11 pm
by Irving
[中文]
在 ULP 中使用 SUB 指令进行一个正数减去一个负数的操作,会产生 ALU overflow,按理 SUB 指令进行的是有符号的运算,应该不会产生
ALU overflow.
在 ULP 中添加如下代码即可复现:

Code: Select all

    move r2, 1
    sub r2, r2, -1
    jump wake_up, ov
说明:使用 SUB 指令完成 1-(-1) 运算,发现会跳转到 wake_up 运行。

[EN]
When I use the ULP, I found a problem as below:
When I use `SUB` instruction to do the caculation that a positive number minus a negtive number, it seems that ALU will set overflow flag. And the `SUB` instruction can do sighed value caculation, so I think the ALU will not set overflow.
Add the code below can reproduce the issue:

Code: Select all

    move r2, 1
    sub r2, r2, -1
    jump wake_up, ov
Note: use `SUB` instruction to do the caculation that `1-(-1)`, and the system will jump to `wake_up`

Re: 关于 ULP 的 SUB 指令产生 ALU overflow 的问题

Posted: Tue Jan 08, 2019 8:54 am
by ESP_HengYC
减法运算中,正数减负数也可能产生溢出,正溢出; 同理,负数减正数产生的溢出为负溢出
当进行加(减)法计算的时候,进(借)位是常见的现象。当出现了补码后,溢出,也是常见的. :lol: