Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arithmetic Overflow vs. Arithmetic Carry

Tags:

math

hex

One of my lecture slides gives an example of arithmetic overflow and carry in a topic for conditional branching flags on an ARM chip, quoted below:

  • V (overflow) -  7FFFFFFF+1
  • C (carry) -  FFFFFFFF+1

Presumably for the sake of the example, the address can only hold 8 bytes. So to me, it seems likes adding 1 to 7FFFFFFF gives 80000000. I thought 80000000 would still fit into an 8-byte address.

Why is this an arithmetic overflow? Is it the wrong way around on the slide? Or is my understanding flawed?

Thanks for any responses

like image 552
eggonlegs Avatar asked Jun 07 '11 13:06

eggonlegs


People also ask

What is the difference between overflow and carry flag with example?

Carry indicates the result isn't mathematically correct when interpreted as unsigned, overflow indicates the result isn't mathematically correct when interpreted as signed. So as examples for your 4-bit ALU: 1111 + 0001 = 0000 should set carry (15 + 1 = 0 is false) and clear overflow (-1 + 1 = 0 is true).

What is the difference between overflow flag and carry flag?

From a mechanistic point of view, the carry flag is set when there is a carry out of the most-significant bit. The overflow flag is set when the carry into the most significant bit is different from the carry out of it. With unsigned arithmetic you only have to worry about the carry flag.

What is meant by arithmetic overflow?

An arithmetic overflow is the result of a calculation that exceeds the memory space designated to hold it. For example, a divide-by-zero yields a much larger result. See arithmetic underflow.

What is carry out in binary arithmetic?

So when adding binary numbers, a carry out is generated when the “SUM” equals or is greater than two (1+1) and this becomes a “CARRY” bit for any subsequent addition being passed over to the next column for addition and so on.


1 Answers

  • Overflow flags get set when the register cannot properly represent the result as a signed value (you overflowed into the sign bit).
  • Carry flags are set when the register cannot properly represent the result as an unsigned value (no sign bit required).
like image 172
Seth Avatar answered Oct 08 '22 14:10

Seth