1
00:00:06,020 --> 00:00:11,060
Everybody what's going on this is Caleb with Debb slopes dot com and in this video we're going to be

2
00:00:11,060 --> 00:00:17,290
talking about how does code work and not how does like a programming language work.

3
00:00:17,300 --> 00:00:20,980
I mean how does code work from the code we write.

4
00:00:20,990 --> 00:00:23,360
How does that actually do what it does.

5
00:00:23,360 --> 00:00:25,160
How does it get down into the computer.

6
00:00:25,160 --> 00:00:31,220
How does it get down into the C.P. you and to actually be processed and perform certain actions or behaviors.

7
00:00:31,220 --> 00:00:32,390
How does code work.

8
00:00:32,390 --> 00:00:36,690
So let's dive right into it with something we'll understand really well.

9
00:00:36,860 --> 00:00:42,080
If you have any experience with programming at all actually so let's begin with source code.

10
00:00:42,080 --> 00:00:48,560
So imagine you've written a source code file a very simple program even hello world that can print out

11
00:00:48,710 --> 00:00:49,370
Hello world.

12
00:00:49,370 --> 00:00:49,600
Right.

13
00:00:49,610 --> 00:00:52,570
That's a program that you yourself wrote.

14
00:00:52,730 --> 00:01:01,100
Now the language that you used whether it's Python javascript swift Objective C C Sharp whatever you

15
00:01:01,110 --> 00:01:08,270
used that's a human readable programming language and we call these high level languages because they

16
00:01:08,270 --> 00:01:11,630
are so easily interacted with by humans.

17
00:01:11,630 --> 00:01:17,600
And they've been they've been abstracted very far away from what a computer processor can actually understand

18
00:01:17,870 --> 00:01:22,200
because obviously a computer processor thinks very differently than a human.

19
00:01:22,490 --> 00:01:28,640
So that's in contrast to low level languages which we'll get to in a moment but high level languages

20
00:01:28,820 --> 00:01:34,100
easy for humans to work with and abstracted far away from the processor.

21
00:01:34,100 --> 00:01:36,220
Low level languages will talk about soon.

22
00:01:36,230 --> 00:01:42,160
So basically you write your source code and then when it comes time to actually run your code and to

23
00:01:42,170 --> 00:01:49,010
build it and to use it we send it into something called a compiler and compilation is basically the

24
00:01:49,010 --> 00:01:57,040
process of taking source code passing it to the compiler and the compiler acts sort of like a translator.

25
00:01:57,050 --> 00:01:57,600
OK.

26
00:01:57,860 --> 00:02:06,230
And what it's going to do is it's going to translate our source code into a lower level language like

27
00:02:06,230 --> 00:02:07,700
machine code or assembly.

28
00:02:07,700 --> 00:02:10,900
Those are two examples of low level languages.

29
00:02:11,000 --> 00:02:16,270
Now I always have this picture of like the United Nations with all those translators with their earpieces

30
00:02:16,340 --> 00:02:22,580
and everything and I think of the compiler as one of those people sitting in the chair helping our source

31
00:02:22,580 --> 00:02:27,000
code be understood by another party right by this CPQ.

32
00:02:27,200 --> 00:02:32,950
And so we need to talk about machine code and assembly what the heck even is that ok.

33
00:02:33,020 --> 00:02:35,270
If you were to look at it you would probably say the same thing.

34
00:02:35,270 --> 00:02:36,640
What the heck is this.

35
00:02:36,650 --> 00:02:43,960
There are different machine code and assembly but they're similar in that they're both low level languages.

36
00:02:44,090 --> 00:02:44,860
OK.

37
00:02:44,930 --> 00:02:50,090
Now basically they both deal with programming the processor directly.

38
00:02:50,090 --> 00:02:54,010
Machine code is usually a stream of binary data.

39
00:02:54,130 --> 00:02:54,410
OK.

40
00:02:54,420 --> 00:03:00,650
Telling the processor to turn on and turn off certain transistors in order to control certain aspects

41
00:03:00,740 --> 00:03:06,590
of the computer or the program that you're using assembly is a low level language.

42
00:03:06,680 --> 00:03:10,430
It's slightly higher the machine code it's not exactly binary.

43
00:03:10,520 --> 00:03:10,850
OK.

44
00:03:10,850 --> 00:03:17,420
There is a layer of abstraction above machine code called assembly but basically assembly utilizes what

45
00:03:17,420 --> 00:03:20,750
are called registers and we'll talk about that more in a second.

46
00:03:20,750 --> 00:03:26,340
But basically they store instructions that control hardware features on the processor directly.

47
00:03:26,350 --> 00:03:33,650
OK so it's like a layer above machine code but it's also not very easily readable and understandable

48
00:03:33,650 --> 00:03:34,510
by humans.

49
00:03:34,570 --> 00:03:40,360
OK thankfully the compiler does a lot of the heavy lifting for us as developers now.

50
00:03:40,460 --> 00:03:46,490
Assembly does have a particular syntax to enable the running of an assembly program so that it knows

51
00:03:46,490 --> 00:03:52,880
when to begin when to and when to jump to a different register pass data perform calculations just like

52
00:03:52,910 --> 00:03:59,990
you would in an ordinary program with no swifter javascript or whatever machine code doesn't have that

53
00:03:59,990 --> 00:04:02,740
machine code literally is binary.

54
00:04:02,750 --> 00:04:07,600
I mean a can be hexadecimal but for the most part it's binary ones and zeros.

55
00:04:07,680 --> 00:04:14,480
OK so thankfully our source code gets translated into assembly language then into machine code and then

56
00:04:14,480 --> 00:04:19,500
finally at the very end it's compiled into an executable code or an app.

57
00:04:19,550 --> 00:04:23,690
If you're building you know apps for the iPhone or even apps for the Mac.

58
00:04:23,750 --> 00:04:30,170
Now I said that we were going to talk about registers and we are this is a really important foundational

59
00:04:30,170 --> 00:04:32,450
piece of the assembly language.

60
00:04:32,660 --> 00:04:40,650
Now basically in assembly you're given between 8 and 32 global variables of a fixed size.

61
00:04:40,800 --> 00:04:46,610
OK so they're global variables they're accessible from wherever and they have a fixed size.

62
00:04:46,760 --> 00:04:48,360
Those are registers OK.

63
00:04:48,380 --> 00:04:54,370
They're simple variables that can hold bits of information and shift them around in the in memory.

64
00:04:54,380 --> 00:05:02,090
Ok now we can work with these to basically store information perform calculations.

65
00:05:02,270 --> 00:05:07,280
We can store particular instructions on how we want the react and respond.

66
00:05:07,330 --> 00:05:13,120
But a real program is going to need a lot more than 30 to one byte variables right.

67
00:05:13,120 --> 00:05:15,790
That's not a lot of data not a lot of information.

68
00:05:15,790 --> 00:05:22,850
So whatever actually does not fit in the registers is stored in memory K or RAM on your computer it's

69
00:05:22,860 --> 00:05:29,470
sort of like like a temporary placeholder in order to put something while you're doing other work.

70
00:05:29,470 --> 00:05:35,230
I kind of like to think of it like you know if you're cooking on on your countertop and you're out of

71
00:05:35,230 --> 00:05:38,910
space you might set some things over on the other counter while you're working.

72
00:05:39,040 --> 00:05:42,640
And then when you're ready for it you might bring it in and use it and then bring other things back

73
00:05:42,640 --> 00:05:43,700
and set them.

74
00:05:43,780 --> 00:05:47,460
You know you want to be able to have extra space to store things.

75
00:05:47,620 --> 00:05:49,030
And that's what RAM is.

76
00:05:49,030 --> 00:05:49,300
Right.

77
00:05:49,300 --> 00:05:54,190
And obviously if you have a little bit of RAM your computer tends to be slower because it runs out of

78
00:05:54,190 --> 00:06:00,760
space and then has to basically handle removing things and putting things in with less space the more

79
00:06:00,760 --> 00:06:04,660
space the less less clogged your system becomes.

80
00:06:04,660 --> 00:06:10,540
So basically what doesn't fit in the registers fits in memory and things and memory are accessed that

81
00:06:10,540 --> 00:06:17,530
particular addresses sort of like we have like a digital neighborhood in our computer that you can access

82
00:06:17,530 --> 00:06:20,760
and machine code basically tells it where to store it where to put it.

83
00:06:20,890 --> 00:06:21,740
And yeah.

84
00:06:21,910 --> 00:06:28,600
So after the compiler does all the heavy lifting and converts our source code into assembly or machine

85
00:06:28,600 --> 00:06:31,630
code it's then compiled into an executable.

86
00:06:31,630 --> 00:06:35,060
Or if you're developing for iOS or Mac an app.

87
00:06:35,100 --> 00:06:41,750
Ok now this executable or this app actually lives on disk on your computer on your hard drive.

88
00:06:41,790 --> 00:06:43,010
K so it's not in memory.

89
00:06:43,060 --> 00:06:44,620
It's stored on your hard drive.

90
00:06:44,710 --> 00:06:50,260
Now it's basically just a box full of machine code and assembly language that's been converted down

91
00:06:50,260 --> 00:06:51,620
from your source code.

92
00:06:51,640 --> 00:06:56,470
So when we run the application the computer is directly told using that machine code what it should

93
00:06:56,470 --> 00:06:56,990
do.

94
00:06:57,160 --> 00:07:01,630
But the cool thing is that we can interact with it physically like we can click a button we can push

95
00:07:01,630 --> 00:07:03,550
a keyboard key.

96
00:07:03,940 --> 00:07:12,160
And that basically can use our input in order to actually tell the C.P. what to do how to display certain

97
00:07:12,160 --> 00:07:15,590
information how to move this here make this noise.

98
00:07:15,610 --> 00:07:19,180
It all boils down to assembly or machine code.

99
00:07:19,180 --> 00:07:21,100
Very very cool stuff.

100
00:07:21,170 --> 00:07:26,830
Now not every application is an app you can click on and interact with sometimes we have to interact

101
00:07:26,830 --> 00:07:28,280
with it through the terminal.

102
00:07:28,390 --> 00:07:32,180
And that's where an executable can be run in a shell.

103
00:07:32,200 --> 00:07:32,800
OK.

104
00:07:32,980 --> 00:07:39,670
Now a shell is just basically a program written by humans that can run other programs and you know you

105
00:07:39,670 --> 00:07:45,280
see your terminal there command line you can type in commands and when I push enter on the keyboard

106
00:07:45,640 --> 00:07:51,370
the cool thing is the operating system is going to basically say hey we need to switch from the shell

107
00:07:51,370 --> 00:07:54,660
program to this computer program that we built.

108
00:07:54,670 --> 00:07:54,910
Right.

109
00:07:54,910 --> 00:08:01,990
Our source code file and it automatically does that for us which is what makes operating system so powerful

110
00:08:01,990 --> 00:08:09,120
and so smart is that they can automatically determine the context for a particular application.

111
00:08:09,160 --> 00:08:13,330
Create new processes and switch them back and forth based on our input.

112
00:08:13,330 --> 00:08:15,550
This is called context switching.

113
00:08:15,790 --> 00:08:21,150
And it's a really powerful feature of an operating system working together with the CPQ.

114
00:08:21,250 --> 00:08:25,760
And so basically from source code we pass it into a compiler.

115
00:08:25,960 --> 00:08:29,830
It's turned into assembly machine code which is basically binary.

116
00:08:29,830 --> 00:08:30,420
OK.

117
00:08:30,640 --> 00:08:36,220
And that then is then compressed down into an executable file which can either be run with direct interaction

118
00:08:36,220 --> 00:08:43,780
from a user like an application or through the terminal in a shell and RCP who is basically going to

119
00:08:43,780 --> 00:08:49,870
take that code and it's going to interact with it and switch back and forth intelligently between all

120
00:08:49,870 --> 00:08:52,360
of the different inputs and everything.

121
00:08:52,360 --> 00:08:55,700
Thanks to our operating system which is a really really cool thing.

122
00:08:55,810 --> 00:09:03,160
So this in essence is how code works are our code gets converted down into binary through multiple layers

123
00:09:03,430 --> 00:09:09,800
of abstraction and that basically allows you to make a program and that's how code works.

124
00:09:09,910 --> 00:09:13,260
It's converted down thanks to compilers and we can run it.

125
00:09:13,420 --> 00:09:18,100
And then the operating system works together with you in order to display what our code is supposed

126
00:09:18,100 --> 00:09:18,820
to do.

127
00:09:18,820 --> 00:09:23,400
Now of course you can write assembly code yourself and do that directly.

128
00:09:23,410 --> 00:09:24,830
Not many people do that though.

129
00:09:25,000 --> 00:09:27,030
And you also can do that with machine code.

130
00:09:27,040 --> 00:09:32,800
But again not one not many people do that because a lot of the things that machine code and assembly

131
00:09:32,800 --> 00:09:37,600
language do can really easily be done with human created programming languages.

132
00:09:37,600 --> 00:09:42,850
It might just be a little less memory efficient and little more resource intensive but very very cool

133
00:09:42,850 --> 00:09:43,530
stuff.

134
00:09:43,540 --> 00:09:48,160
We have a lot to be grateful for as developers that we don't have to write in assembly code or machine

135
00:09:48,160 --> 00:09:49,440
code anymore.

136
00:09:49,450 --> 00:09:50,440
Very very cool stuff.

137
00:09:50,440 --> 00:09:53,550
So let's head over to the next video and let's continue learning.

138
00:09:53,560 --> 00:09:55,350
This is Caleb with devah slopes dot com.
