WEBVTT

00:00.400 --> 00:01.160
Hello, everyone.

00:01.600 --> 00:01.840
Here.

00:01.840 --> 00:04.320
Welcome to our lecture on binary subtraction operations.

00:04.800 --> 00:10.640
In this lecture we will explore subtraction in computers, specifically focusing on binary arithmetic.

00:10.680 --> 00:15.680
The concept of borrowing the role of flags in indicating certain conditions to run computations.

00:16.120 --> 00:18.080
And yeah let's dive right in.

00:18.520 --> 00:22.560
We'll begin with a simple yet essential example to grasp binary subtraction.

00:22.600 --> 00:29.120
Now let's subtract 14 from four using four bit binary numbers here.

00:29.800 --> 00:35.000
So decimal four in binary is 100.

00:35.400 --> 00:40.800
So 0100 and decimal 14.

00:40.840 --> 00:41.880
In binary is

00:42.040 --> 00:47.960
11101110.

00:49.400 --> 00:56.040
Now let's perform the subtraction and you will see why we can't represent negative numbers in unsigned

00:56.080 --> 00:56.760
integers.

00:57.520 --> 01:00.600
Zero zero is 001.

01:00.600 --> 01:02.200
We will borrow from here.

01:02.880 --> 01:05.480
So also we will write the borrowing here.

01:05.480 --> 01:06.480
So zero.

01:07.320 --> 01:10.130
Here we will have one, one, one.

01:10.970 --> 01:14.370
We have zero, one and zero.

01:15.130 --> 01:16.890
The borrowing is zero.

01:17.930 --> 01:23.730
So this is weird because it is what?

01:23.770 --> 01:26.730
01100110.

01:27.410 --> 01:30.970
It says that it equals to six, but it's not.

01:31.650 --> 01:35.810
Initially, the result appears as 0110.

01:35.850 --> 01:38.290
In binary, which equals six in decimal.

01:38.330 --> 01:42.410
However, we know subtracting 14 from four yields what?

01:42.890 --> 01:44.570
Minus ten.

01:45.370 --> 01:47.890
But we do not have minus ten here.

01:48.610 --> 01:50.130
So why does this happen?

01:50.210 --> 01:53.010
Because we are limited to four bits.

01:53.210 --> 01:55.770
We can accurately represent the negative result.

01:55.770 --> 02:04.450
The computer uses a special indicator called the carry flag to recognize and and handle such situations.

02:04.930 --> 02:09.530
And since we are using unsigned, we cannot use negative numbers with unsigned here.

02:10.250 --> 02:11.250
And you will see why.

02:11.930 --> 02:18.580
In computer processors, especially indicator known as the carry flag See is abbreviated as.

02:18.620 --> 02:21.580
Carry flag in computer processor.

02:22.340 --> 02:28.420
So this is kind of signal whether a subtraction operation has needed borrowing from beyond the available

02:28.460 --> 02:28.940
bits.

02:29.340 --> 02:39.540
And in this case carry flag was one since which indicates the borrowing was necessary, suggesting the

02:39.540 --> 02:49.100
calculated result isn't fully accurate due to the bit limitations here and carry flag zero.

02:49.140 --> 02:52.580
Of course, indicates no borrowing was required here.

02:52.900 --> 02:59.420
In our example, the carry flag would set to one like this, clearly indicating that our computed result

02:59.420 --> 03:03.860
exceeded the bit limitations and borrowing was involved.

03:03.900 --> 03:09.460
Now let's briefly see how this concept translates into assembly language instructions which processor

03:09.860 --> 03:14.900
use directly and assembly language typically includes specific instructions for addition and subtraction

03:14.940 --> 03:17.780
operations, often updating flags.

03:18.260 --> 03:25.860
In assembly we have the flag adds, so sets the carry flag to zero if there's a no final carry and sets

03:25.900 --> 03:30.620
carry like to one if the overflow occurs, right?

03:31.580 --> 03:39.860
In this case, we have nothing to do with ads here since as you know, ads is what ads the number.

03:40.540 --> 03:43.060
In this case we are using subtraction.

03:43.060 --> 03:45.980
So let's explain the subs here.

03:46.420 --> 03:50.020
We explained ads in previous lecture subs.

03:50.740 --> 03:54.900
So subs here sets the carry flag zero.

03:54.940 --> 04:02.380
If nobody borrowing is necessary and it sets the carry flag to one if borrowing occurs here.

04:03.060 --> 04:16.260
So example for the generic subtraction instructions assembly we have sub the destination sub destination

04:17.100 --> 04:19.380
source is source one and source two.

04:20.180 --> 04:30.780
So which basically means subtract source two from source one and save the result in destination and

04:30.940 --> 04:33.180
flags will update accordingly.
