MKUltra
MKUltra

Reputation: 374

Binary subtraction, carry bit not set?

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?

Upvotes: 2

Views: 404

Answers (1)

Mike
Mike

Reputation: 4288

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!

Upvotes: 3

Related Questions