Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assembly, detecting overflow register

I have this very simple assembly code:

start:
add ax, 100    
; if ax overflow add to bx 1
jmp start

but i don't know how to detect ax register overflow, can anyone help me?

like image 208
Michal Avatar asked Oct 16 '25 13:10

Michal


2 Answers

ADD instruction sets appropriate FLAGS reflecting the overflow condition. There are two kinds of overflow: signed and unsigned. You have to decide what's appropriate and use jc/jnc for unsigned and jo/jno for signed.

add ax, 100
jnc noUnsignedOverflow
...
noUnsignedOverflow:

add ax, 100
jno noSignedOverflow
...
noSignedOverflow:
like image 131
Anton Kovalenko Avatar answered Oct 18 '25 04:10

Anton Kovalenko


Use jo (jump if overflow) or jno (jump if no overflow)

Check out the Intel x86 JUMP quick reference

like image 20
rickythefox Avatar answered Oct 18 '25 02:10

rickythefox



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!