Question

What does "Carrey" do in a Math instruction?

Take the following as an example: summation of two binaries give birth to something extra call CY besides the result value. So, 1+ 2 = 3 + some Carry?

The documentation simply says: "If the addition results in a carry, the Carry Flag will turn O" given no explanation of what is a carry, and what is a Carry Flag. What are they and what are the difference if I perform an addition instruction with or without a Carry?

enter image description here

Was it helpful?

Solution

Carry is the extra bit that is needed to represent the full result of the addition.

If you for example add two 16 bit values, the result needs to be 17 bits to represent every possible outcome.

The carry flag is also used when you chain additions of values larger than the register size. If you have 32 bit values and you can only do 16 bit additions, you add the lower halves of the values first, then the higher halves with the carry from the first addition:

Rlo = Alo + Blo
Rhi = Ahi + Bhi + CY

The lower halves would be added as unsigned values, and the higher halves would be added as signed or unsigned values with an instruction that uses the carry flag.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top