Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Overflow in subtraction

Status
Not open for further replies.

Binome

Full Member level 3
Joined
Nov 16, 2009
Messages
152
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Location
Lyon, France
Activity points
2,405
Hi,
my problem is the overflow detection when subtracting:
There are two unsigned integer 4-bit numbers (a and b), so we have 0≦a,b≦15.
I want to subtract a-b, then -15≦a-b≦15.
This result is a signed integer 4-bit number then -8≦s≦7.
I want the operator to be able to detect an overflow. How should I build my circuit? (I have to use adders knowing a-b=a+not(b)+1).
Thanks.
 

BradtheRad

Super Moderator
Staff member
Joined
Apr 1, 2011
Messages
14,059
Helped
2,796
Reputation
5,592
Reaction score
2,705
Trophy points
1,393
Location
Minneapolis, Minnesota, USA
Activity points
104,875
When I worked with assembly language, I seem to remember I had to set the carry bit every time before doing a subtraction. If the carry bit is zero afterward, then a borrow occurs.
 

Ratch

Advanced Member level 1
Joined
Mar 20, 2012
Messages
408
Helped
76
Reputation
152
Reaction score
73
Trophy points
1,308
Activity points
4,258
Binome,

The CF will be set if there is a carry out or a borrow in of the most significant bit (MSB). Use a "full-subtractor" to implement this. Any good logic book should tell you how to build one.

Ratch
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top