Binary subtraction, carry bit not set?

2

I've encountered a situation that seems a bit unintuitive when dealing with binary subtraction and the NZCV flag bits.

Consider the following values

0xF7      0b 1111 0111
0xFF      0b 1111 1111

If these are both considered to be 8B values where

0x000000F7      0b 0000 .... 0000 1111 0111
0x000000FF      0b 0000 .... 0000 1111 1111

When subtracted the end result is

0x FF FF FF F8    0b 1111 .... 1000

I understand how this result is found but I don't understand why the carry bit is not set for this operation.

To my knowledge, the carry bit is set when the MSB is borrowed from, is that not the case here?

assembly
binary
flags
asked on Stack Overflow Nov 13, 2018 by MKUltra

1 Answer

3

The ARM subtraction instructions with carry (SBC, RSC) interpret the carry flag (C) as:

0: means borrow

1: means no borrow

So in your calculation the MSB is borrowed and the carry ist NOT set!

answered on Stack Overflow Nov 13, 2018 by Mike • edited Jun 20, 2020 by Community

User contributions licensed under CC BY-SA 3.0