4

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?

2 Answers 2

11

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:
Sign up to request clarification or add additional context in comments.

Comments

4

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

Check out the Intel x86 JUMP quick reference

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.