Hello, everyone.
Here.
Welcome to our lecture on binary subtraction operations.
In this lecture we will explore subtraction in computers, specifically focusing on binary arithmetic.
The concept of borrowing the role of flags in indicating certain conditions to run computations.
And yeah let's dive right in.
We'll begin with a simple yet essential example to grasp binary subtraction.
Now let's subtract 14 from four using four bit binary numbers here.
So decimal four in binary is 100.
So 0100 and decimal 14.
In binary is
11101110.
Now let's perform the subtraction and you will see why we can't represent negative numbers in unsigned
integers.
Zero zero is 001.
We will borrow from here.
So also we will write the borrowing here.
So zero.
Here we will have one, one, one.
We have zero, one and zero.
The borrowing is zero.
So this is weird because it is what?
01100110.
It says that it equals to six, but it's not.
Initially, the result appears as 0110.
In binary, which equals six in decimal.
However, we know subtracting 14 from four yields what?
Minus ten.
But we do not have minus ten here.
So why does this happen?
Because we are limited to four bits.
We can accurately represent the negative result.
The computer uses a special indicator called the carry flag to recognize and and handle such situations.
And since we are using unsigned, we cannot use negative numbers with unsigned here.
And you will see why.
In computer processors, especially indicator known as the carry flag See is abbreviated as.
Carry flag in computer processor.
So this is kind of signal whether a subtraction operation has needed borrowing from beyond the available
bits.
And in this case carry flag was one since which indicates the borrowing was necessary, suggesting the
calculated result isn't fully accurate due to the bit limitations here and carry flag zero.
Of course, indicates no borrowing was required here.
In our example, the carry flag would set to one like this, clearly indicating that our computed result
exceeded the bit limitations and borrowing was involved.
Now let's briefly see how this concept translates into assembly language instructions which processor
use directly and assembly language typically includes specific instructions for addition and subtraction
operations, often updating flags.
In assembly we have the flag adds, so sets the carry flag to zero if there's a no final carry and sets
carry like to one if the overflow occurs, right?
In this case, we have nothing to do with ads here since as you know, ads is what ads the number.
In this case we are using subtraction.
So let's explain the subs here.
We explained ads in previous lecture subs.
So subs here sets the carry flag zero.
If nobody borrowing is necessary and it sets the carry flag to one if borrowing occurs here.
So example for the generic subtraction instructions assembly we have sub the destination sub destination
source is source one and source two.
So which basically means subtract source two from source one and save the result in destination and
flags will update accordingly.