WEBVTT

1
00:00:00.160 --> 00:00:02.319
<v Speaker 1>Welcome to your deep dive. We're going to be looking

2
00:00:02.399 --> 00:00:08.480
<v Speaker 1>at Raspberry Pie assembly language programming, specifically excerpts from the

3
00:00:08.519 --> 00:00:12.240
<v Speaker 1>book Raspberry Pie Assembly Language Programming by Steven Smith. It's

4
00:00:12.240 --> 00:00:15.880
<v Speaker 1>a twenty nineteen book, awesome, And you know you want

5
00:00:15.880 --> 00:00:19.320
<v Speaker 1>to learn how to program your Raspberry Pie using assembly, right,

6
00:00:19.440 --> 00:00:21.000
<v Speaker 1>and we're going to help you get the most out

7
00:00:21.039 --> 00:00:21.600
<v Speaker 1>of this book.

8
00:00:21.719 --> 00:00:24.879
<v Speaker 2>Yeah, this deep dive is your shortcut to understanding all

9
00:00:24.920 --> 00:00:28.440
<v Speaker 2>the core concepts of assembly, Okay, and it'll give you

10
00:00:28.480 --> 00:00:32.280
<v Speaker 2>the knowledge to write more efficient code nice potentially even

11
00:00:32.320 --> 00:00:35.159
<v Speaker 2>create your own operating systems or programming languages.

12
00:00:35.240 --> 00:00:37.880
<v Speaker 1>Okay, so let's get into it. Yeah, why even learn

13
00:00:37.960 --> 00:00:42.079
<v Speaker 1>assembly in a world full of Python and JavaScript and

14
00:00:42.200 --> 00:00:45.399
<v Speaker 1>C plus plus and all these high level languages. Don't

15
00:00:45.399 --> 00:00:47.479
<v Speaker 1>they make assembly kind of Yeah, that's.

16
00:00:47.320 --> 00:00:49.840
<v Speaker 2>A great question. Obsolete, it is, and the book actually

17
00:00:49.840 --> 00:00:50.920
<v Speaker 2>addresses that right away.

18
00:00:51.079 --> 00:00:51.439
<v Speaker 1>Okay.

19
00:00:52.679 --> 00:00:55.880
<v Speaker 2>You know, while high level languages are great for lots

20
00:00:55.880 --> 00:00:59.240
<v Speaker 2>of tasks, assembly is still relevant for a bunch of

21
00:00:59.280 --> 00:01:02.280
<v Speaker 2>different reasons. So think about it this way. High level

22
00:01:02.320 --> 00:01:04.719
<v Speaker 2>languages let you drive a car without even knowing how

23
00:01:04.760 --> 00:01:07.840
<v Speaker 2>the engine works. Right. Assembly is like being a mechanic.

24
00:01:07.879 --> 00:01:09.799
<v Speaker 2>You can tinker with the engine directly.

25
00:01:09.519 --> 00:01:14.040
<v Speaker 1>Okay, so more control and power, but also more complexity exactly.

26
00:01:14.319 --> 00:01:16.959
<v Speaker 2>So learning assembly gives you that deeper understanding of how

27
00:01:16.959 --> 00:01:21.599
<v Speaker 2>the Raspberry Pies processor works. It's built on the ARM architecture, okay,

28
00:01:22.799 --> 00:01:26.640
<v Speaker 2>and this knowledge is really useful for like writing highly

29
00:01:26.680 --> 00:01:32.280
<v Speaker 2>optimized code, understanding computer architecture at a fundamental level, creating

30
00:01:32.840 --> 00:01:36.200
<v Speaker 2>low level software like operating systems, or even like reverse

31
00:01:36.239 --> 00:01:38.519
<v Speaker 2>engineering or security analysis.

32
00:01:38.599 --> 00:01:41.640
<v Speaker 1>Yeah, creating an operating system with assembly sounds intense, but

33
00:01:41.680 --> 00:01:44.120
<v Speaker 1>I guess that's that level of control we're talking about.

34
00:01:44.280 --> 00:01:44.840
<v Speaker 2>Yeah, that's right.

35
00:01:45.079 --> 00:01:47.719
<v Speaker 1>So to unlock the secrets of assembly, we need to

36
00:01:47.799 --> 00:01:50.000
<v Speaker 1>understand this ARM architecture first.

37
00:01:49.840 --> 00:01:52.560
<v Speaker 2>Right, absolutely, The airm architecture is like a blueprint for

38
00:01:52.640 --> 00:01:56.159
<v Speaker 2>your Raspberry Pies processor, okay. And one of the key

39
00:01:56.159 --> 00:01:59.319
<v Speaker 2>concepts here is that airm uses a load store architecture

40
00:02:00.200 --> 00:02:02.959
<v Speaker 2>that before any data can be processed, it has to

41
00:02:03.000 --> 00:02:06.840
<v Speaker 2>first be loaded from memory into registers. These registers are

42
00:02:06.920 --> 00:02:10.520
<v Speaker 2>like the processors workbenches, interesting, so the data needs to

43
00:02:10.520 --> 00:02:13.080
<v Speaker 2>be on the workbench before the processor can work with it.

44
00:02:13.159 --> 00:02:17.159
<v Speaker 1>So there's this constant movement of data between memory and registers.

45
00:02:17.199 --> 00:02:18.719
<v Speaker 1>That's right, isn't that inefficient.

46
00:02:18.879 --> 00:02:21.680
<v Speaker 2>You might think so, but it's actually a very efficient system.

47
00:02:21.759 --> 00:02:22.000
<v Speaker 1>Okay.

48
00:02:23.039 --> 00:02:25.919
<v Speaker 2>The book also explains how the thirty two bit ARM

49
00:02:26.080 --> 00:02:30.159
<v Speaker 2>architecture handles fitting both addresses and data, which are also

50
00:02:30.199 --> 00:02:33.719
<v Speaker 2>thirty two bits long, into instructions okay, and then, of course,

51
00:02:33.759 --> 00:02:36.719
<v Speaker 2>the program counter acts as a guide, always pointing to

52
00:02:36.719 --> 00:02:38.039
<v Speaker 2>the next instruction and memory.

53
00:02:38.319 --> 00:02:40.879
<v Speaker 1>Okay, I'm starting to get the picture, but you know me,

54
00:02:41.039 --> 00:02:44.120
<v Speaker 1>I always learn best by seeing code and action. The

55
00:02:44.159 --> 00:02:47.560
<v Speaker 1>book starts with the classic Hello World example, Right, yeah,

56
00:02:47.599 --> 00:02:48.560
<v Speaker 1>what can we learn from that?

57
00:02:49.000 --> 00:02:51.639
<v Speaker 2>The Hello World example is a great starting point.

58
00:02:51.800 --> 00:02:52.159
<v Speaker 1>Okay.

59
00:02:52.400 --> 00:02:56.000
<v Speaker 2>Even in this simple program we see fundamental concepts like

60
00:02:56.400 --> 00:02:59.960
<v Speaker 2>the dot data section for storing data, the MOV instruction

61
00:03:00.240 --> 00:03:03.680
<v Speaker 2>for moving data into registers, and the LDR instruction for

62
00:03:03.759 --> 00:03:05.000
<v Speaker 2>loading data from memory.

63
00:03:05.039 --> 00:03:07.719
<v Speaker 1>Okay, so, even with Hello World, we're already talking directly

64
00:03:07.800 --> 00:03:08.439
<v Speaker 1>to the hardware.

65
00:03:08.599 --> 00:03:08.800
<v Speaker 2>Got it?

66
00:03:08.879 --> 00:03:11.560
<v Speaker 1>What else makes the assembly version of this program special?

67
00:03:12.080 --> 00:03:15.400
<v Speaker 2>This example also introduces us to the idea of system calls.

68
00:03:15.560 --> 00:03:15.879
<v Speaker 1>Okay.

69
00:03:15.960 --> 00:03:19.719
<v Speaker 2>So to print Hello World to the console, the program

70
00:03:19.800 --> 00:03:23.680
<v Speaker 2>has to interact with the Linux operating system. It does

71
00:03:23.759 --> 00:03:27.080
<v Speaker 2>this through a system call using the SDC instruction. Okay,

72
00:03:27.919 --> 00:03:31.520
<v Speaker 2>and there's even a tool called obdump that lets us

73
00:03:31.599 --> 00:03:36.240
<v Speaker 2>disassemble the program, revealing the underlying binary code that the

74
00:03:36.280 --> 00:03:37.719
<v Speaker 2>processor actually executes.

75
00:03:37.840 --> 00:03:40.240
<v Speaker 1>Whoa, Okay, that's getting down to the nitty gritty right

76
00:03:40.240 --> 00:03:42.360
<v Speaker 1>Before we move on, though, can we talk about numbers

77
00:03:42.360 --> 00:03:45.599
<v Speaker 1>for a second. Sure, binary math has always intimated me

78
00:03:45.680 --> 00:03:47.800
<v Speaker 1>a little bit. How does assembly handle that?

79
00:03:48.039 --> 00:03:48.719
<v Speaker 2>You're not alone?

80
00:03:48.800 --> 00:03:49.280
<v Speaker 1>Okay? Good.

81
00:03:50.800 --> 00:03:53.719
<v Speaker 2>The book explains how computers use the system called two's

82
00:03:53.800 --> 00:03:57.759
<v Speaker 2>compliment to represent negative numbers. It might seem strange at first,

83
00:03:57.800 --> 00:04:00.759
<v Speaker 2>but it actually simplifies arithmetic operations for the processor.

84
00:04:00.919 --> 00:04:01.319
<v Speaker 1>Okay.

85
00:04:01.719 --> 00:04:05.000
<v Speaker 2>We also touch on the concept of indianness Danus. It's

86
00:04:05.000 --> 00:04:08.319
<v Speaker 2>the way multibyte data is ordered in memory, which varies

87
00:04:08.360 --> 00:04:12.560
<v Speaker 2>between computer architectures. The Raspberry Pi uses little endian format.

88
00:04:12.759 --> 00:04:15.680
<v Speaker 1>Okay. So we've got this whole system for handling negative

89
00:04:15.759 --> 00:04:18.680
<v Speaker 1>numbers and figuring out how data is arranged, right, What

90
00:04:18.759 --> 00:04:21.199
<v Speaker 1>about actually doing calculations with assembly?

91
00:04:21.800 --> 00:04:25.360
<v Speaker 2>So the book dives into instructions like mv and MVN

92
00:04:26.079 --> 00:04:29.560
<v Speaker 2>for moving data and calculating one's compliment okay, which is

93
00:04:29.600 --> 00:04:30.839
<v Speaker 2>related to two's complement.

94
00:04:31.000 --> 00:04:31.240
<v Speaker 1>Okay.

95
00:04:31.560 --> 00:04:37.360
<v Speaker 2>Then there are eightyds instructions for addition, where adds even

96
00:04:37.360 --> 00:04:40.360
<v Speaker 2>takes into account a potential carryover from the previous operation.

97
00:04:41.560 --> 00:04:43.800
<v Speaker 2>You also learn how to use shifting and rotating bits

98
00:04:43.839 --> 00:04:47.040
<v Speaker 2>to efficiently multiply or divide numbers by powers of two.

99
00:04:47.319 --> 00:04:49.839
<v Speaker 1>This is all fascinating, but I can imagine writing all

100
00:04:49.839 --> 00:04:52.519
<v Speaker 1>this code by hand could get pretty tedious.

101
00:04:52.879 --> 00:04:53.680
<v Speaker 2>Yeah, for sure.

102
00:04:53.800 --> 00:04:55.399
<v Speaker 1>Are there any tools that can help us out?

103
00:04:55.480 --> 00:04:55.800
<v Speaker 2>You bet?

104
00:04:55.959 --> 00:04:56.360
<v Speaker 1>Okay.

105
00:04:56.680 --> 00:05:00.199
<v Speaker 2>The book introduces the g and U Assembler okay, or AS,

106
00:05:00.240 --> 00:05:03.560
<v Speaker 2>which transforms your human readable assembly code into the machine

107
00:05:03.560 --> 00:05:06.439
<v Speaker 2>code that the Raspberry Pie understands. Right. Then there's the

108
00:05:06.480 --> 00:05:10.079
<v Speaker 2>g and U Debugger or GDB okay, a powerful tool

109
00:05:10.079 --> 00:05:13.079
<v Speaker 2>that lets you step through your code, examine variables, and

110
00:05:13.160 --> 00:05:14.000
<v Speaker 2>hunt down bugs.

111
00:05:14.040 --> 00:05:16.079
<v Speaker 1>So AS is like a translator in GDB is like

112
00:05:16.120 --> 00:05:17.319
<v Speaker 1>a detective for your code.

113
00:05:17.399 --> 00:05:18.000
<v Speaker 2>It's exactly.

114
00:05:18.079 --> 00:05:21.120
<v Speaker 1>That sounds way better than counting bits by hand, Yeah,

115
00:05:21.199 --> 00:05:21.519
<v Speaker 1>it is.

116
00:05:22.759 --> 00:05:26.519
<v Speaker 2>What about managing larger projects with lots of code?

117
00:05:26.720 --> 00:05:29.240
<v Speaker 1>For that, there's the Make utility okay. It's like a

118
00:05:29.279 --> 00:05:32.600
<v Speaker 1>project manager for your code. Interesting, automating the build process

119
00:05:32.639 --> 00:05:35.879
<v Speaker 1>and making sure everything's organized. Okay. The book even provides

120
00:05:35.920 --> 00:05:39.800
<v Speaker 1>examples of make files, which are like recipes for building

121
00:05:39.800 --> 00:05:40.920
<v Speaker 1>your assembly programs.

122
00:05:41.000 --> 00:05:42.720
<v Speaker 2>This is all starting to make sense, You got the

123
00:05:42.720 --> 00:05:45.000
<v Speaker 2>tools and the instructions right. But so far we've only

124
00:05:45.000 --> 00:05:48.480
<v Speaker 2>talked about simple programs. How do we create more complex

125
00:05:48.600 --> 00:05:52.279
<v Speaker 2>logic in assembly? How do we make decisions and create

126
00:05:52.319 --> 00:05:56.079
<v Speaker 2>programs that can do different things based on certain conditions.

127
00:05:56.160 --> 00:05:58.560
<v Speaker 1>So that's where program flow control comes in, and that's

128
00:05:58.600 --> 00:06:00.360
<v Speaker 1>what we'll be diving into in the next part of

129
00:06:00.399 --> 00:06:01.000
<v Speaker 1>our deep dive.

130
00:06:01.040 --> 00:06:04.240
<v Speaker 2>All right, let's do it. Welcome back to our deep

131
00:06:04.319 --> 00:06:08.279
<v Speaker 2>dive into Raspberry Pie assembly language programming. Last time, we explored,

132
00:06:08.519 --> 00:06:11.519
<v Speaker 2>you know, the fundamentals of ARM architecture and some basic

133
00:06:11.519 --> 00:06:15.000
<v Speaker 2>assembly instructions. We even learned about tools that make assembly

134
00:06:15.040 --> 00:06:18.240
<v Speaker 2>programming easier, and we ended on the topic of program

135
00:06:18.319 --> 00:06:21.759
<v Speaker 2>flow control, which is how we add decision making and

136
00:06:21.959 --> 00:06:23.800
<v Speaker 2>more complex logic to our programs.

137
00:06:23.920 --> 00:06:26.360
<v Speaker 1>Exactly, I'm really eager to learn how to make our

138
00:06:26.439 --> 00:06:30.600
<v Speaker 1>assembly programs, you know, smarter and more responsive to different situations.

139
00:06:30.920 --> 00:06:34.560
<v Speaker 2>Well, the key to understanding program flow control lies in

140
00:06:34.600 --> 00:06:39.519
<v Speaker 2>a special register called the current program Status Register or CPSR.

141
00:06:39.720 --> 00:06:42.480
<v Speaker 1>CPSR like a dashboard.

142
00:06:41.920 --> 00:06:45.199
<v Speaker 2>For your code, displaying important status flags that reflect the

143
00:06:45.240 --> 00:06:47.319
<v Speaker 2>outcome of the last instruction executed.

144
00:06:47.360 --> 00:06:49.920
<v Speaker 1>A dashboard, so it tells us what's happening inside.

145
00:06:49.639 --> 00:06:53.439
<v Speaker 2>The program precisely, The CPSR contains flags like the zero

146
00:06:53.519 --> 00:06:56.279
<v Speaker 2>flag or Z, which is set if the result of

147
00:06:56.319 --> 00:06:59.600
<v Speaker 2>an operation is zero, the negative flag or N if

148
00:06:59.639 --> 00:07:02.759
<v Speaker 2>there was a negative gotcha, the carry flag or see

149
00:07:02.879 --> 00:07:05.480
<v Speaker 2>if an addition results in a carry, and the overflow

150
00:07:05.600 --> 00:07:08.160
<v Speaker 2>flag or V if an arithmetic operation overflows.

151
00:07:08.240 --> 00:07:10.720
<v Speaker 1>So these flags are like signals that indicate the current

152
00:07:10.720 --> 00:07:11.839
<v Speaker 1>state of the program exactly.

153
00:07:11.879 --> 00:07:14.519
<v Speaker 2>And this is where it gets interesting. Okay, we use

154
00:07:14.560 --> 00:07:18.360
<v Speaker 2>the CMP instruction to compare values based on the comparison

155
00:07:18.560 --> 00:07:21.199
<v Speaker 2>these flags in the cps are are set. Then we

156
00:07:21.240 --> 00:07:25.279
<v Speaker 2>can use conditional branch instructions like b eq, bn, BLT

157
00:07:25.439 --> 00:07:29.519
<v Speaker 2>and others to change the flow of execution based on

158
00:07:29.560 --> 00:07:30.160
<v Speaker 2>those flags.

159
00:07:30.199 --> 00:07:33.360
<v Speaker 1>So cmp sets the stage and then the branch instructions

160
00:07:33.399 --> 00:07:35.800
<v Speaker 1>decide which path the code should take. It's like having

161
00:07:35.800 --> 00:07:38.040
<v Speaker 1>to choose your own adventure story for our program.

162
00:07:38.399 --> 00:07:41.360
<v Speaker 2>That's a great analogy. Awesome, And as your programs become

163
00:07:41.399 --> 00:07:46.079
<v Speaker 2>more complex, it's important to write structured, organized code to

164
00:07:46.160 --> 00:07:48.399
<v Speaker 2>avoid like a tangled mess of branches.

165
00:07:48.680 --> 00:07:48.800
<v Speaker 1>Right.

166
00:07:49.199 --> 00:07:51.639
<v Speaker 2>This is where the concept of structured programming comes in,

167
00:07:51.759 --> 00:07:55.480
<v Speaker 2>minimizing unnecessary jumps and keeping your code clean.

168
00:07:56.040 --> 00:07:59.000
<v Speaker 1>Okay, structured programming for the win. Yeah, but what about

169
00:07:59.000 --> 00:08:01.439
<v Speaker 1>when we want to break down our programs into smaller,

170
00:08:01.480 --> 00:08:03.839
<v Speaker 1>reusable chunks. Can we do that in assembly?

171
00:08:04.319 --> 00:08:07.279
<v Speaker 2>Absolutely, that's where functions come in. Functions are like many

172
00:08:07.319 --> 00:08:11.120
<v Speaker 2>programs within your main program, allowing you to group instructions,

173
00:08:11.199 --> 00:08:13.439
<v Speaker 2>reuse logic, and make your code more modular.

174
00:08:13.680 --> 00:08:16.959
<v Speaker 1>So it's like building with legos. We can create these

175
00:08:17.079 --> 00:08:19.480
<v Speaker 1>reusable modules that we can just put together to make

176
00:08:19.480 --> 00:08:21.079
<v Speaker 1>bigger programs exactly.

177
00:08:21.160 --> 00:08:24.480
<v Speaker 2>And to manage the flow of execution between functions, we

178
00:08:24.600 --> 00:08:26.000
<v Speaker 2>use this structure called the stack.

179
00:08:26.160 --> 00:08:26.920
<v Speaker 1>Okay, the stack.

180
00:08:27.160 --> 00:08:30.480
<v Speaker 2>The stack is a dedicated area of memory that operates

181
00:08:30.519 --> 00:08:31.439
<v Speaker 2>like a pile of plates.

182
00:08:31.480 --> 00:08:31.800
<v Speaker 1>Okay.

183
00:08:32.159 --> 00:08:36.200
<v Speaker 2>Use push to place data onto the stack and pop

184
00:08:36.360 --> 00:08:37.000
<v Speaker 2>to take it off.

185
00:08:37.240 --> 00:08:41.360
<v Speaker 1>So it's a last in, first out LIFO system.

186
00:08:41.440 --> 00:08:44.720
<v Speaker 2>Precisely, this is crucial for function calls. Okay. When a

187
00:08:44.759 --> 00:08:48.960
<v Speaker 2>function is called, it's parameters, local variables, and the address

188
00:08:49.000 --> 00:08:51.360
<v Speaker 2>to return to. After the function finishes, we call that

189
00:08:51.399 --> 00:08:54.600
<v Speaker 2>the return address are pushed onto the stack. The BL

190
00:08:54.679 --> 00:08:57.360
<v Speaker 2>instruction that stands for a branch with link handles this

191
00:08:57.440 --> 00:08:58.519
<v Speaker 2>function call process.

192
00:08:58.919 --> 00:09:00.600
<v Speaker 1>So when the function is done and it just pops

193
00:09:00.639 --> 00:09:02.639
<v Speaker 1>everything back off the stack and returns to where it

194
00:09:02.679 --> 00:09:03.639
<v Speaker 1>left off exactly.

195
00:09:03.679 --> 00:09:06.799
<v Speaker 2>The stack is like a temporary workspace for functions. The

196
00:09:06.840 --> 00:09:09.799
<v Speaker 2>book even goes into detail about the concept of stack frames,

197
00:09:10.600 --> 00:09:13.360
<v Speaker 2>which are like individual compartments on the stack for each

198
00:09:13.399 --> 00:09:17.360
<v Speaker 2>function call, keeping everything organized and preventing data from getting

199
00:09:17.360 --> 00:09:17.840
<v Speaker 2>mixed up.

200
00:09:18.000 --> 00:09:21.679
<v Speaker 1>That's pretty clever. It's amazing how assembly can be so structured,

201
00:09:21.759 --> 00:09:24.279
<v Speaker 1>even though it's such a low level language. It is,

202
00:09:24.559 --> 00:09:27.399
<v Speaker 1>but so far we've been mostly focused on the internal

203
00:09:27.440 --> 00:09:31.039
<v Speaker 1>workings of our programs. Can we use assembly to interact

204
00:09:31.080 --> 00:09:31.960
<v Speaker 1>with the outside world.

205
00:09:32.000 --> 00:09:34.919
<v Speaker 2>Absolutely, But the next part of the book dives into

206
00:09:35.360 --> 00:09:37.799
<v Speaker 2>how to communicate with the Linux operating system from our

207
00:09:37.799 --> 00:09:40.919
<v Speaker 2>assembly code, which opens up a world of possibilities.

208
00:09:41.639 --> 00:09:44.919
<v Speaker 1>Welcome back to our deep dive into Raspberry Pie assembly

209
00:09:45.039 --> 00:09:48.120
<v Speaker 1>language programming. We've talked about a lot, you know, ARM architecture,

210
00:09:48.159 --> 00:09:51.720
<v Speaker 1>program flow control, functions, the stack. Right last time, you

211
00:09:51.799 --> 00:09:54.919
<v Speaker 1>mentioned interacting with the Linux operating system from assembly. Yeah,

212
00:09:54.919 --> 00:09:56.759
<v Speaker 1>that sounds like a big step it is.

213
00:09:57.279 --> 00:10:01.960
<v Speaker 2>The ability to tap into the operating systems capabilities really

214
00:10:02.000 --> 00:10:04.360
<v Speaker 2>opens up a whole new level of functionality for your

215
00:10:04.399 --> 00:10:07.679
<v Speaker 2>assembly programs. Okay, the book explains how we can make

216
00:10:07.799 --> 00:10:10.799
<v Speaker 2>use of Linux system calls directly from our assembly code.

217
00:10:11.159 --> 00:10:13.440
<v Speaker 1>So what kind of things can we actually do with

218
00:10:13.519 --> 00:10:14.559
<v Speaker 1>these system calls?

219
00:10:14.799 --> 00:10:15.440
<v Speaker 2>Lots of things.

220
00:10:15.480 --> 00:10:15.759
<v Speaker 1>Okay.

221
00:10:15.960 --> 00:10:18.720
<v Speaker 2>System calls are like requests we make to the operating system.

222
00:10:18.799 --> 00:10:19.080
<v Speaker 1>Okay.

223
00:10:19.960 --> 00:10:23.600
<v Speaker 2>We can read and write files, mannix processes, work with

224
00:10:23.679 --> 00:10:27.320
<v Speaker 2>the network, even control hardware connected with the Raspberry Pie.

225
00:10:27.519 --> 00:10:31.240
<v Speaker 1>Controlling hardware with assembly sounds pretty powerful, it is. Can

226
00:10:31.240 --> 00:10:32.200
<v Speaker 1>you give me an example.

227
00:10:32.279 --> 00:10:35.360
<v Speaker 2>Sure. One chapter of the book focuses specifically on programming

228
00:10:35.399 --> 00:10:39.639
<v Speaker 2>the Raspberry pies gpio pins. GPIO that sounds for general

229
00:10:39.679 --> 00:10:41.159
<v Speaker 2>purpose input output.

230
00:10:41.320 --> 00:10:41.600
<v Speaker 1>Okay.

231
00:10:41.759 --> 00:10:46.240
<v Speaker 2>This lets you interface with external devices like LEDs, sensors, motors,

232
00:10:46.600 --> 00:10:47.120
<v Speaker 2>and more.

233
00:10:47.360 --> 00:10:50.159
<v Speaker 1>So we could write assembly code to make an LED blink.

234
00:10:50.440 --> 00:10:51.000
<v Speaker 2>You got it.

235
00:10:51.080 --> 00:10:54.080
<v Speaker 1>That's pretty cool. How do we actually control these gpio

236
00:10:54.200 --> 00:10:55.360
<v Speaker 1>pins from assembly though?

237
00:10:55.559 --> 00:10:59.080
<v Speaker 2>The book describes two methods. The first involves interacting with

238
00:10:59.120 --> 00:11:02.799
<v Speaker 2>the Linux GPI io device driver by reading and writing

239
00:11:02.840 --> 00:11:05.559
<v Speaker 2>special files in the cisclass GPO directory.

240
00:11:05.720 --> 00:11:06.000
<v Speaker 1>Okay.

241
00:11:06.440 --> 00:11:10.559
<v Speaker 2>The second method involves directly accessing the gpio controllers registers

242
00:11:11.039 --> 00:11:12.639
<v Speaker 2>using memory mapped IO.

243
00:11:12.960 --> 00:11:14.960
<v Speaker 1>Memory mapped IO what is that?

244
00:11:15.440 --> 00:11:18.399
<v Speaker 2>It's a technique where specific memory addresses are mapped to

245
00:11:18.440 --> 00:11:19.799
<v Speaker 2>physical hardware registers.

246
00:11:19.919 --> 00:11:20.320
<v Speaker 1>Okay?

247
00:11:20.399 --> 00:11:23.000
<v Speaker 2>By writing to these memory addresses, we can directly control

248
00:11:23.000 --> 00:11:23.519
<v Speaker 2>the hardware.

249
00:11:23.759 --> 00:11:24.080
<v Speaker 1>Okay.

250
00:11:24.200 --> 00:11:26.919
<v Speaker 2>The book explains this concept in detail, including the role

251
00:11:26.960 --> 00:11:29.360
<v Speaker 2>of virtual memory and how it allows us to access

252
00:11:29.399 --> 00:11:30.159
<v Speaker 2>physical memory.

253
00:11:30.320 --> 00:11:32.320
<v Speaker 1>It's amazing how we can get so close to the

254
00:11:32.399 --> 00:11:35.159
<v Speaker 1>hardware with assembly. It is so we can control the

255
00:11:35.159 --> 00:11:39.279
<v Speaker 1>operating system. We can even control hardware. Is there anything

256
00:11:39.320 --> 00:11:40.720
<v Speaker 1>assembly can't do well?

257
00:11:40.759 --> 00:11:44.240
<v Speaker 2>Assembly is fantastic for low level tasks where speed and

258
00:11:44.279 --> 00:11:48.639
<v Speaker 2>efficiency are crucial, okay, But for more complex applications, higher

259
00:11:48.720 --> 00:11:52.519
<v Speaker 2>level languages like C or Python are often more practical.

260
00:11:52.600 --> 00:11:52.879
<v Speaker 1>Okay.

261
00:11:53.000 --> 00:11:56.320
<v Speaker 2>However, the book shows us that assembly doesn't have to

262
00:11:56.320 --> 00:12:00.440
<v Speaker 2>live in isolation. It can work alongside these higher level languages.

263
00:12:00.120 --> 00:12:02.799
<v Speaker 1>So we can combine the power of assembly with the

264
00:12:02.840 --> 00:12:05.639
<v Speaker 1>flexibility of languages like C and Python.

265
00:12:05.960 --> 00:12:09.840
<v Speaker 2>Exactly. The book explains how to cool C functions from assembly,

266
00:12:10.200 --> 00:12:12.559
<v Speaker 2>and how to create assembly libraries that can be used

267
00:12:12.559 --> 00:12:16.120
<v Speaker 2>by C programs. Wow. You can even embed assembly code

268
00:12:16.159 --> 00:12:20.200
<v Speaker 2>directly within C code using gccs ASM statement, And for

269
00:12:20.240 --> 00:12:22.360
<v Speaker 2>Python you can use the c types module to call

270
00:12:22.360 --> 00:12:23.440
<v Speaker 2>assembly functions.

271
00:12:23.759 --> 00:12:25.399
<v Speaker 1>That opens up a lot of possibilities.

272
00:12:25.559 --> 00:12:26.200
<v Speaker 2>It does, Okay.

273
00:12:26.240 --> 00:12:28.360
<v Speaker 1>Before we wrap up, you mentioned earlier that the book

274
00:12:28.480 --> 00:12:32.960
<v Speaker 1>covers advanced arithmetic operations multiplication and division. Can you tell

275
00:12:33.000 --> 00:12:33.960
<v Speaker 1>me a little bit more about that?

276
00:12:34.279 --> 00:12:38.159
<v Speaker 2>Sure? Multiplication and ERM assembly can involve instructions like mool,

277
00:12:38.320 --> 00:12:40.919
<v Speaker 2>which gives you the lower thirty two bits of the results,

278
00:12:41.679 --> 00:12:45.320
<v Speaker 2>or instructions like symbol and umll, which calculate the full

279
00:12:45.399 --> 00:12:49.320
<v Speaker 2>sixty four bit product. Division is handled by instructions like

280
00:12:49.480 --> 00:12:53.840
<v Speaker 2>sdiv and UDIV on modern ARM and processors. Okay, but

281
00:12:54.320 --> 00:12:57.759
<v Speaker 2>earlier versions didn't have dedicated division instructions.

282
00:12:57.200 --> 00:12:59.759
<v Speaker 1>So they had to come up with clever workarounds exactly.

283
00:13:00.799 --> 00:13:04.120
<v Speaker 2>The book delves into the history of division algorithms on ARM,

284
00:13:04.279 --> 00:13:08.240
<v Speaker 2>which is fascinating interesting. It also covers multiply accumulating instructions

285
00:13:08.320 --> 00:13:13.120
<v Speaker 2>like MLA and smlal, which combine multiplication and addition into

286
00:13:13.159 --> 00:13:17.279
<v Speaker 2>a single operation, making them incredibly efficient for certain calculations.

287
00:13:17.440 --> 00:13:19.240
<v Speaker 1>Yeah, that sounds like it would be really useful for

288
00:13:19.279 --> 00:13:21.799
<v Speaker 1>tasks like image processing or machine learning.

289
00:13:22.000 --> 00:13:22.600
<v Speaker 2>Absolutely.

290
00:13:22.679 --> 00:13:23.399
<v Speaker 1>Yeah.

291
00:13:23.440 --> 00:13:26.480
<v Speaker 2>And speaking of powerful features, the book also introduces us

292
00:13:26.480 --> 00:13:30.840
<v Speaker 2>to the neon coprocessor neon, a specialized unit designed for

293
00:13:30.919 --> 00:13:35.120
<v Speaker 2>parallel processing of vectors and matrices. This coprocessor extends the

294
00:13:35.159 --> 00:13:39.480
<v Speaker 2>capabilities of the floating point unit, providing instructions for vector arithmetic,

295
00:13:39.519 --> 00:13:41.240
<v Speaker 2>data rearrangement, and more.

296
00:13:41.600 --> 00:13:45.159
<v Speaker 1>Neon sounds like it could really boost performance for certain applications.

297
00:13:45.279 --> 00:13:47.759
<v Speaker 2>It can awesome. And finally, the book touches on the

298
00:13:47.799 --> 00:13:51.440
<v Speaker 2>transition from thirty two bit to sixty four bit ARM

299
00:13:51.519 --> 00:13:55.120
<v Speaker 2>known as arch sixty four. Okay, this newer architecture brings

300
00:13:55.159 --> 00:13:58.879
<v Speaker 2>an expanded register set, changes to the function calling conventions,

301
00:13:59.240 --> 00:14:02.799
<v Speaker 2>and even the removed of conditional execution, relying instead on

302
00:14:02.879 --> 00:14:04.919
<v Speaker 2>sophisticated branch prediction techniques.

303
00:14:05.159 --> 00:14:07.919
<v Speaker 1>Wow, we've covered so much. This deep dive has taken

304
00:14:08.000 --> 00:14:11.039
<v Speaker 1>us from the very basics of AIRM assembly to advance

305
00:14:11.120 --> 00:14:14.519
<v Speaker 1>features like neon and sixty four bit architecture. Right, it's

306
00:14:14.559 --> 00:14:18.240
<v Speaker 1>incredible how much depth there is to this seemingly simple language.

307
00:14:18.440 --> 00:14:21.399
<v Speaker 2>Yeah, it really highlights how assembly, even in a world

308
00:14:21.440 --> 00:14:24.480
<v Speaker 2>of high level languages, continues to be relevant. It gives

309
00:14:24.480 --> 00:14:26.799
<v Speaker 2>you a level of control and understanding that's just not

310
00:14:26.919 --> 00:14:28.840
<v Speaker 2>possible with higher level abstractions.

311
00:14:28.960 --> 00:14:31.879
<v Speaker 1>I'm definitely feeling inspired to learn more. But before we go,

312
00:14:31.960 --> 00:14:34.799
<v Speaker 1>there's one thing I'm still a bit apprehensive about. Yeah,

313
00:14:34.960 --> 00:14:39.200
<v Speaker 1>reading and understanding existing assembly code. It seems so dense

314
00:14:39.279 --> 00:14:39.919
<v Speaker 1>and cryptic.

315
00:14:40.279 --> 00:14:43.000
<v Speaker 2>It can be challenging, but remember assembly code is built

316
00:14:43.039 --> 00:14:46.120
<v Speaker 2>on the same fundamental concepts we've been discussing. The book

317
00:14:46.159 --> 00:14:49.480
<v Speaker 2>provides some great strategies for tackling this challenge. Okay, the

318
00:14:49.559 --> 00:14:51.559
<v Speaker 2>key is to approach it methodically.

319
00:14:51.759 --> 00:14:53.919
<v Speaker 1>Methodically how so, first.

320
00:14:53.879 --> 00:14:57.720
<v Speaker 2>Understand the context of the code, what's its purpose, what

321
00:14:57.879 --> 00:15:00.799
<v Speaker 2>problem is it trying to solve. Then break the code

322
00:15:00.840 --> 00:15:05.399
<v Speaker 2>down into smaller, more manageable chunks. Look for familiar patterns,

323
00:15:05.960 --> 00:15:09.559
<v Speaker 2>data structures, arithmetic operations, control flow structures.

324
00:15:09.639 --> 00:15:12.519
<v Speaker 1>So it's like solving a puzzle piece by piece exactly.

325
00:15:13.080 --> 00:15:16.039
<v Speaker 2>And don't be afraid to use tools. A debugger is

326
00:15:16.080 --> 00:15:19.320
<v Speaker 2>invaluable for stepping through code, examining values, and seeing how

327
00:15:19.360 --> 00:15:23.879
<v Speaker 2>the instructions affect the program state. Okay, for really complex code,

328
00:15:23.879 --> 00:15:27.480
<v Speaker 2>there are even tools like Guidra which can help decompile

329
00:15:27.519 --> 00:15:31.320
<v Speaker 2>assembly code back into a higher level representation, making it

330
00:15:31.360 --> 00:15:32.960
<v Speaker 2>easier to analyze.

331
00:15:32.440 --> 00:15:35.639
<v Speaker 1>This Deep Dog has been an incredible journey. We've explored

332
00:15:35.679 --> 00:15:39.399
<v Speaker 1>the power and flexibility of Raspberry Pie assembly language programming,

333
00:15:39.480 --> 00:15:43.639
<v Speaker 1>going from basic concepts to advanced techniques it has.

334
00:15:44.159 --> 00:15:47.320
<v Speaker 2>It's been amazing, and most importantly, we've seen that assembly

335
00:15:47.399 --> 00:15:52.399
<v Speaker 2>is not some arcane forgotten language. It's a vital tool

336
00:15:52.440 --> 00:15:56.759
<v Speaker 2>for understanding how computers work at the most fundamental level, yeah,

337
00:15:56.919 --> 00:16:00.159
<v Speaker 2>giving you the ability to write highly efficient code and

338
00:16:00.240 --> 00:16:02.720
<v Speaker 2>even push the boundaries of what's possible with hardware.

339
00:16:03.320 --> 00:16:05.799
<v Speaker 1>A huge thanks to Steven Smith for writing Raspberry high

340
00:16:05.759 --> 00:16:08.759
<v Speaker 1>assembly language programming, and to you our listeners for joining

341
00:16:08.840 --> 00:16:11.799
<v Speaker 1>us on this deep dive. Until next time, keep exploring,

342
00:16:11.879 --> 00:16:13.879
<v Speaker 1>keep learning, and keep pushing the limits of what you

343
00:16:13.879 --> 00:16:14.440
<v Speaker 1>can create.
