1
00:00:08,610 --> 00:00:17,150
welcome to the chapter on the a r m assembly
language ah a r m assembly language are some
2
00:00:17,150 --> 00:00:21,599
of the most popular and most exiting assembly
language as to learn so in this chapter will
3
00:00:21,599 --> 00:00:26,640
have a lot of fun so this chapter is the part
of the book computer organization and architecture
4
00:00:26,640 --> 00:00:34,150
publish by myself doctor smruthi sarangi ah
it was publish by mc graw hill in the year
5
00:00:34,150 --> 00:00:40,250
two thousand fifteen and should be available
in almost all book store and online ah in
6
00:00:40,250 --> 00:00:45,460
a both normal book stores and online book
stores so ah why study the a r m instruction
7
00:00:45,460 --> 00:00:55,170
set and so so lets first look at why study
and then whats the background required so
8
00:00:55,170 --> 00:00:58,650
a r m is very very popular instruction set
so almost all the phones today as of two thousand
9
00:00:58,650 --> 00:01:05,920
sixteen ah tablets and all kinds of small
computing devices ah which are not desktop
10
00:01:05,920 --> 00:01:16,110
are laptops run on a r m processors so they
use the a r m instruction set
11
00:01:16,110 --> 00:01:24,040
so a r m is company located in ah cambridge
u k so they actually licensed their designs
12
00:01:24,040 --> 00:01:33,409
and then the designs are used by other manufacturers
ah to you know incorporate them in silicon
13
00:01:33,409 --> 00:01:43,960
chips so ah before actually we start this
chapter i would like to make a point that
14
00:01:43,960 --> 00:01:51,270
readers should already have a good understanding
assembly language in the sense that they should
15
00:01:51,270 --> 00:01:55,830
have read the previous chapter which is chapter
three and understood ah lot of things about
16
00:01:55,830 --> 00:01:58,840
how assembly programs are written how they
instructions how assembly instructions work
17
00:01:58,840 --> 00:02:04,220
are the notion of function no [no\notion]
notion of the stack the notion of encoding
18
00:02:04,220 --> 00:02:09,470
so all of this needs to be there and the reason
that the book has been designed in such a
19
00:02:09,470 --> 00:02:15,410
way is basically that is you you know it is
not possible at list in my view to give an
20
00:02:15,410 --> 00:02:21,650
introduction to assembly language and teach
an advanced assembly language at the same
21
00:02:21,650 --> 00:02:26,260
time it is better to separate the concerns
so it is better to first teach what an assembly
22
00:02:26,260 --> 00:02:31,260
language is like a very simple one and then
move to ah teaching in advanced assembly language
23
00:02:31,260 --> 00:02:35,790
which is used in commercial processors ah
because than a student would have the right
24
00:02:35,790 --> 00:02:38,520
amount of understanding to actually ah understand
what state of the art ah assembly instruction
25
00:02:38,520 --> 00:02:39,520
set looks like
26
00:02:39,520 --> 00:02:42,050
so ah keeping this in mind i will actually
start this chapter at a slightly higher level
27
00:02:42,050 --> 00:02:46,390
because my assumption is that readers are
already ah coming ah after at chapter three
28
00:02:46,390 --> 00:02:51,720
so they understand the basics of assembly
languages and they also understand how to
29
00:02:51,720 --> 00:02:57,790
write simple programs with assembly languages
and have a basic understanding of ah how to
30
00:02:57,790 --> 00:03:04,400
implement ah is statements loops ah functions
using stacks using assembly language so so
31
00:03:04,400 --> 00:03:06,920
these are some other concepts will take for
given in this particular chapter so coming
32
00:03:06,920 --> 00:03:14,170
back to a r m so a r m has a lot of licensees
all over the world so what a r m produces
33
00:03:14,170 --> 00:03:22,349
as they pra pra they create the design of
a processor and then the sell the design the
34
00:03:22,349 --> 00:03:27,740
design can be incorporated by a third party
with other component so for example if a r
35
00:03:27,740 --> 00:03:29,900
m sells a processor to a phone company then
they can incorporate the a r m processor and
36
00:03:29,900 --> 00:03:33,010
also have other ah smaller circuit surround
it for is ah for example a circuit to process
37
00:03:33,010 --> 00:03:39,270
inputs on the camera or a circuit ah to inter
face with the accelerometer in the phone so
38
00:03:39,270 --> 00:03:40,830
all of these additional circuits can be added
39
00:03:40,830 --> 00:03:47,370
so the a r m instruction set as such is very
very versatile ah so along with lot of integer
40
00:03:47,370 --> 00:03:54,250
instructions is suppose floating point instructions
and it has ah what are called vector extensions
41
00:03:54,250 --> 00:03:59,900
so will discuss more about vector instructions
in chapter eleven ah but vector ah instructions
42
00:03:59,900 --> 00:04:08,260
allow was to do multiple additions ah at the
same time in the same cycle so will not be
43
00:04:08,260 --> 00:04:14,970
discussing these extensions also a r m has
a very popular ah i was say in assembly sub
44
00:04:14,970 --> 00:04:21,120
language or in a extension is called the thumb
instruction set and a lot of a r m programs
45
00:04:21,120 --> 00:04:26,669
actually use the thumb instruction set which
is the slightly simpler set off instructions
46
00:04:26,669 --> 00:04:34,520
and what we present here in you know in this
chapter cycle referred to it has the thumb
47
00:04:34,520 --> 00:04:40,669
i s a are the thumb assembly languages ah
so so basically the thumb instruction set
48
00:04:40,669 --> 00:04:46,419
ah is similar to this its slightly simpler
will not discuss this ah in this chapter ah
49
00:04:46,419 --> 00:04:52,080
will discuss the generic a r m instruction
set [fo/for] for integer only in this chapter
50
00:04:52,080 --> 00:04:59,430
so will have five separate ah sections here
will first start with basic instructions move
51
00:04:59,430 --> 00:05:06,520
to advanced instructions then look at branch
instructions memory instructions low store
52
00:05:06,520 --> 00:05:11,669
kind of instructions and finally considered
instruction encoding so similar to simple
53
00:05:11,669 --> 00:05:20,259
risk a r m has sixteen registered their number
from r zero to r fifteen and unlike simple
54
00:05:20,259 --> 00:05:23,430
risk can many many other assembly languages
the problem counted the explicitly visible
55
00:05:23,430 --> 00:05:29,340
and the program counted can be use two effect
branches and so on
56
00:05:29,340 --> 00:05:34,460
so so this is expose to software is a expose
to the assembly language the memory is standard
57
00:05:34,460 --> 00:05:41,259
von neumann architecture what this mean is
the instruction memory and the data memory
58
00:05:41,259 --> 00:05:47,259
is fuse to one ah so this is you know typical
facet of the von neumann architecture [the/there]
59
00:05:47,259 --> 00:05:52,129
there is von view of memory its not separate
so out of the sixteen register at a r m has
60
00:05:52,129 --> 00:05:58,080
ah some of them a reserve for special purposes
so lets take a look at them so r fifteen is
61
00:05:58,080 --> 00:06:02,569
the program counter so i am starting ah in
a back words ah a r m fif r fifteen is the
62
00:06:02,569 --> 00:06:12,349
program counter its refers to was either r
fifteen or the p c r fourteen is the link
63
00:06:12,349 --> 00:06:18,460
registered ah its you can also think of it
does the return address registered r thirteen
64
00:06:18,460 --> 00:06:26,149
is ah reserved for keeping the stack pointer
or s p ah r eleven and r twelve ah have will
65
00:06:26,149 --> 00:06:36,520
r eleven and r twelve can be assigned a special
connotation on times ah so r twelve is an
66
00:06:36,520 --> 00:06:40,629
intra procedure calls scratch register n which
basically means ah it can explicitly be use
67
00:06:40,629 --> 00:06:45,649
to ah safe temporary values inside a function
call but other registered can be use as well
68
00:06:45,649 --> 00:06:50,080
and r eleven is called a frame pointers will
discuss what is a frame pointer ah actually
69
00:06:50,080 --> 00:06:54,559
towards the end of these chapter and but will
discuss more about a frame pointer and an
70
00:06:54,559 --> 00:06:57,650
next chapter ah on x eighty six assembly
71
00:06:57,650 --> 00:07:01,864
so we will be using a slightly different kind
of semantics in this chapter so we will ah
72
00:07:01,864 --> 00:07:05,300
every single instruction will be explained
with the help of a table so in the table the
73
00:07:05,300 --> 00:07:11,559
first column will look at the semantics which
is something that we introduced towards the
74
00:07:11,559 --> 00:07:19,349
end of the last chapter so it will basically
show ah what are the different modes of the
75
00:07:19,349 --> 00:07:25,139
instructions then will given a example and
then will talk about the explanation and the
76
00:07:25,139 --> 00:07:28,990
registered transfer notation that we have
introduced so the simplest of simple instructions
77
00:07:28,990 --> 00:07:37,439
in the a r m i s a is the move instruction
so what does the move instruction do the move
78
00:07:37,439 --> 00:07:43,629
instruction transfers the value into a registered
so lets say may be move r one r two so it
79
00:07:43,629 --> 00:07:49,339
essentially transfers the valley of r two
to r one alternatively the move instructions
80
00:07:49,339 --> 00:07:54,629
can transfer the valley of a immediate into
a registered so the first operand is always
81
00:07:54,629 --> 00:08:00,849
register the second operand can either be
a registered or an immediate so lets considered
82
00:08:00,849 --> 00:08:11,219
the second example move r one so so here is
is the you know idiosyncrasy of the a r m
83
00:08:11,219 --> 00:08:16,229
i s a they are all immediate are preceded
with the hash
84
00:08:16,229 --> 00:08:21,219
so the moment we add this hash characters
over here so you can see the hash character
85
00:08:21,219 --> 00:08:31,210
will be above three on your keyboard so all
immediate and a r m need to be preceded or
86
00:08:31,210 --> 00:08:41,390
prefix to the hash so when we say move r one
hash three what this essentially moves is
87
00:08:41,390 --> 00:08:50,079
that i take register r one and i move three
to wood so so this is the simplest ah instruction
88
00:08:50,079 --> 00:09:02,310
in the a r m i s a so move has ah variant
its called m v n m v n is move not so this
89
00:09:02,310 --> 00:09:11,680
is similar to the not instruction in simple
risk so what we do is that the ah when we
90
00:09:11,680 --> 00:09:19,339
do m v n r one comma r two essentially the
ones complement or every single bit flipped
91
00:09:19,339 --> 00:09:26,680
ah is transferred from r two to r one so this
tilde sign is a once complement so just to
92
00:09:26,680 --> 00:09:31,470
[re/recapitulate] recapitulate the ones complement
of one zero zero zero in boolean is zero one
93
00:09:31,470 --> 00:09:36,319
one one so every single bit is replaced with
its complement one is replaced with zero and
94
00:09:36,319 --> 00:09:41,910
zero is replaced with one so the m v n instruction
is essentially the same as a move instruction
95
00:09:41,910 --> 00:09:45,770
but instead of moving ah the register all
the immediate it moves in the complement of
96
00:09:45,770 --> 00:09:47,610
the register or immediate
97
00:09:47,610 --> 00:09:51,400
so now lets take a look at arithmetic instructions
the arithmetic instructions are almost you
98
00:09:51,400 --> 00:09:57,579
know the add and sub are exactly the same
as simple risk ah so in this case the add
99
00:09:57,579 --> 00:10:03,459
and sub instructions similar to simple risk
the first operand is the destination the second
100
00:10:03,459 --> 00:10:09,490
operand ah is the first [re/registered] registered
source which is r s one ah recall chapter
101
00:10:09,490 --> 00:10:13,819
three and the second operand can either be
a register or an immediate so ah an examples
102
00:10:13,819 --> 00:10:20,949
would be art r one r two r three so in this
case we add r two plus r three and save the
103
00:10:20,949 --> 00:10:24,699
result in r one so a again you know i would
like to mention that i am deliberately going
104
00:10:24,699 --> 00:10:27,779
slightly fast because my assumption is that
students have already picked up a certain
105
00:10:27,779 --> 00:10:30,939
amount of background in the previous chapter
so they will find covering this chapter slightly
106
00:10:30,939 --> 00:10:36,660
easier right ah but if you lets a take a look
at this chapter from scratch you will find
107
00:10:36,660 --> 00:10:41,470
a slightly difficults i would then ask you
to look at the lectures or read the book for
108
00:10:41,470 --> 00:10:43,529
the previous chapter which is chapter three
109
00:10:43,529 --> 00:10:49,189
so ah coming back to the add instruction i
can alternatively right add r one r two and
110
00:10:49,189 --> 00:10:53,680
hash three so what this would do is that in
r one it would save r two plus three ah similarly
111
00:10:53,680 --> 00:10:59,949
we are the subtract instruction which is exactly
the same as it was in the simple risk instruction
112
00:10:59,949 --> 00:11:06,250
set so we have the register destination first
so the first operand over here is the register
113
00:11:06,250 --> 00:11:10,920
destination then ah we have to source operands
one of them is registered source and the other
114
00:11:10,920 --> 00:11:20,269
is the source slash ah immediate source or
an immediate so when i write sub r one r two
115
00:11:20,269 --> 00:11:33,140
r three essentially inside r one we are having
a placing r two minus r three so similar to
116
00:11:33,140 --> 00:11:37,449
subtract there is another instruction is called
r s b or reverse subtract so in reverse subtract
117
00:11:37,449 --> 00:11:40,570
instead of subtracting r two and r three ah
instead of doing r two minus r three we actually
118
00:11:40,570 --> 00:11:44,769
do r three minus r two so ah here reader can
ask you know if you have the sub instruction
119
00:11:44,769 --> 00:11:48,550
why you need a reverse subtract instruction
right well the answer is simple in the sense
120
00:11:48,550 --> 00:11:54,560
lets say that you want to compute three minus
r one not r one minus three three minus r
121
00:11:54,560 --> 00:11:56,510
one we cannot write an instruction of the
form so lets say you want to set these two
122
00:11:56,510 --> 00:12:05,350
r two we cannot write an instruction are the
form r two right so this is not allowed because
123
00:12:05,350 --> 00:12:13,850
the second operand has to be a register so
this is not allowed but what we can write
124
00:12:13,850 --> 00:12:25,060
is r s b a reverse subtract ah oops sorry
comma here r two r one and three so what this
125
00:12:25,060 --> 00:12:35,499
would do is this would set r two to three
minus r one which is exactly what we needed
126
00:12:35,499 --> 00:12:42,470
since simple risk this doing this would actually
required two instructions because we would
127
00:12:42,470 --> 00:12:48,439
first subtract are we would first subtract
three from r one so compute r one minus three
128
00:12:48,439 --> 00:12:55,320
and then multiplied with minus one so the
designers in a r m a very smart instead of
129
00:12:55,320 --> 00:13:01,589
you know having this two instruction solution
they created a new instruction call r s p
130
00:13:01,589 --> 00:13:06,529
reverse subtract which allows us to compute
three minus r one in a single instruction
131
00:13:06,529 --> 00:13:08,129
all right
so now lets take a look at some examples so
132
00:13:08,129 --> 00:13:12,709
the first example is write an a r m assembly
program to compute four plus five minus nineteen
133
00:13:12,709 --> 00:13:21,920
and save the result in r one so here is the
simple solution which is simple but its not
134
00:13:21,920 --> 00:13:31,329
optimal but nevertheless less to call lets
take a look at it so we first say four in
135
00:13:31,329 --> 00:13:39,000
r one which save five in r two using the move
instruction then we add r one plus r two save
136
00:13:39,000 --> 00:13:43,980
at an r three we move nineteen to r four then
we subtract nineteen from r three which is
137
00:13:43,980 --> 00:13:51,879
r one plus r two save the result in r one
ah slightly modes are there better solution
138
00:13:51,879 --> 00:13:57,850
which is optimal we put four in r one then
we do r one equals r one plus five in the
139
00:13:57,850 --> 00:14:05,100
sense r one will become nine then we do r
one we set r one to r one minus nineteen and
140
00:14:05,100 --> 00:14:13,430
a previous value of r one is four plus five
nine so we compute nine minus nineteen has
141
00:14:13,430 --> 00:14:20,230
minus ten which is the final answer so this
was a slower solution easy to understand this
142
00:14:20,230 --> 00:14:23,850
is slightly difficult to understand but not
very difficult because in the first line we
143
00:14:23,850 --> 00:14:33,999
set r one to four in a second line we do r
one is r one plus five which ah all of you
144
00:14:33,999 --> 00:14:39,720
can verify is what is exactly ah in the mentioned
in the statement of the problem then we subtract
145
00:14:39,720 --> 00:14:43,120
a nineteen from the sum and we get the right
answer
146
00:14:43,120 --> 00:14:47,820
now lets take a look at logical instructions
so logical instructions are also very similar
147
00:14:47,820 --> 00:14:51,120
to the arithmetic instructions so the first
three instructions are somewhat easy the fourth
148
00:14:51,120 --> 00:14:57,699
instruction its slightly difficult so the
first instruction is the and instruction which
149
00:14:57,699 --> 00:15:03,019
is very similar to what we had ah with simple
risk ah so ah in the and instruction is the
150
00:15:03,019 --> 00:15:07,519
same idea that the first so in all of these
instructions the first operand is the destination
151
00:15:07,519 --> 00:15:12,050
then we are the first source and the second
source the second source operand can either
152
00:15:12,050 --> 00:15:16,860
be [restired/ registered] ah can either be
a register or an immediate so one example
153
00:15:16,860 --> 00:15:22,649
would be and r one r two r three so we set
r one has r two and r three so e o r is actually
154
00:15:22,649 --> 00:15:30,050
exclusive or x o r z o r as we call it so
in e o r r one r two r three we have r one
155
00:15:30,050 --> 00:15:36,999
which is being set to r two x or r three o
r r is logical or so in a logical or what
156
00:15:36,999 --> 00:15:42,519
we do is that this is similar to the or instruction
in simple risk so we just compute a logical
157
00:15:42,519 --> 00:15:46,529
or a r two and r three
so the important point to note is that in
158
00:15:46,529 --> 00:15:51,850
all of these instructions the instruction
per say is only three letters since simple
159
00:15:51,850 --> 00:15:58,060
risk we had some to letter instructions like
or an so one so thats on the case and l d
160
00:15:58,060 --> 00:16:07,139
and s t so that is not the case in a r m so
in a r m ah they have tried to ah maintain
161
00:16:07,139 --> 00:16:14,939
the length of the instruction the same so
thats the reason or they have replaced with
162
00:16:14,939 --> 00:16:20,369
o r r so the b i c the bit clear instruction
is ah slightly unclear at the moment so what
163
00:16:20,369 --> 00:16:31,829
this is this is basically r one is r two and
not of r three so lets may be consider ah
164
00:16:31,829 --> 00:16:38,230
simple example and see a what is these is
so so lets considered r two being ah lets
165
00:16:38,230 --> 00:16:44,990
may be just considered four bits to make are
like easy and rest of the bits are also easy
166
00:16:44,990 --> 00:16:49,329
and similarly let r three b so not of this
quantity would be one one zero one the this
167
00:16:49,329 --> 00:16:54,110
number and this number is equal to one and
zero is zero one and one is one one and zero
168
00:16:54,110 --> 00:16:59,629
is zero one and one is one see if you see
what is happening over here is that all the
169
00:16:59,629 --> 00:17:08,380
bits that are set in r three ah so all the
bits that r one in r three in knot of r three
170
00:17:08,380 --> 00:17:12,110
those bits become zero and when that is added
with some other quantity all the bits are
171
00:17:12,110 --> 00:17:17,589
those bit positions become zero so these thats
why the name bit clear comes from so or alternatively
172
00:17:17,589 --> 00:17:21,990
if i want to explain if this is let says the
first operand ah
173
00:17:21,990 --> 00:17:29,610
which in this example is r two and is the
second operand which is r three all the bits
174
00:17:29,610 --> 00:17:33,690
that are set at different points at similar
bit positions in a final result if we have
175
00:17:33,690 --> 00:17:36,851
zeros so its like those bits are [tho/those]
those bits positions are getting cleared so
176
00:17:36,851 --> 00:17:42,610
this is called a bit clear instruction or
a b i c a instruction so lets again considered
177
00:17:42,610 --> 00:17:48,080
an example this time with boolean variables
so write an a r m assembly program to compute
178
00:17:48,080 --> 00:17:55,370
a naught b ah sorry a or b ah the entire thing
not ah where a and b are one bit boolean values
179
00:17:55,370 --> 00:18:04,330
assume that a is zero and b is one save the
result in r zero so to compute the knot of
180
00:18:04,330 --> 00:18:15,760
a or b what we do is that so basically a r
m ah accept hexadecimal numbers as well so
181
00:18:15,760 --> 00:18:26,590
the format is a same first have a hash to
signify in immediate and then you write zero
182
00:18:26,590 --> 00:18:35,970
x to signify that its an hex so what we do
is that we load the value of zero into r zero
183
00:18:35,970 --> 00:18:45,940
and we load so i am sorry we or this with
one so the value of a or b at the moment is
184
00:18:45,940 --> 00:18:54,549
saved in r zero subsequently what we do is
we compute the knot of r zero using the m
185
00:18:54,549 --> 00:18:58,480
v n instruction so we set r zero as the knot
of r zero
186
00:18:58,480 --> 00:19:03,770
so ah in this case ah what we are doing ah
is that we are loading to boolean variables
187
00:19:03,770 --> 00:19:08,260
a with constant were computing their or and
then finally taking the logical compliment
188
00:19:08,260 --> 00:19:11,190
let us now look at the multiplication instructions
that are there in the a r m i s a so the simplest
189
00:19:11,190 --> 00:19:15,830
variant of the multiplication instruction
that we have in a r m is mul m u l ah so the
190
00:19:15,830 --> 00:19:20,740
mul instruction is very similar to the add
and subtract instructions where the first
191
00:19:20,740 --> 00:19:22,890
operand is a destination register henceforth
we have two operands the first source operand
192
00:19:22,890 --> 00:19:26,309
is always a registered and the second one
can be unregister immediate so this is straight
193
00:19:26,309 --> 00:19:33,450
forward r one is r two times r three so even
the a r m is a risk instruction set it has
194
00:19:33,450 --> 00:19:37,330
some slightly complicated instructions and
so you know there is a basic trade off the
195
00:19:37,330 --> 00:19:40,380
trade office is do we always preferred simplicity
or occasionally can we make are instruction
196
00:19:40,380 --> 00:19:43,250
set slightly complicated such that you know
some commonly executing patterns and programs
197
00:19:43,250 --> 00:19:46,390
can be accommodated so once has commonly executing
pattern which is there in a lot of programs
198
00:19:46,390 --> 00:19:56,000
in a particularly coach that use linear algebra
and matrix operations is the m l a operation
199
00:19:56,000 --> 00:20:01,440
[mul/multiplied] multiply an accumulate
so this actually takes four registers as operands
200
00:20:01,440 --> 00:20:10,960
the other first register is the destination
in this example r one is the is the destination
201
00:20:10,960 --> 00:20:20,669
ah so out of the three source operand that
we have what we compute is r two times r three
202
00:20:20,669 --> 00:20:27,100
plus r four so we have a multiplication operation
where the first and second source operand
203
00:20:27,100 --> 00:20:35,660
have been multiplied and we adding this this
with r four so this is a typically required
204
00:20:35,660 --> 00:20:39,270
in the lot of linear algebra kind of competition
thats a reason this instruction is supported
205
00:20:39,270 --> 00:20:46,980
the other interesting aspect of multiplying
two numbers is like this consider a thirty
206
00:20:46,980 --> 00:20:51,720
two bit instruction set so the range of the
number system is pretty much between minus
207
00:20:51,720 --> 00:20:56,919
two to the power thirty one to two raise to
the power thirty one minus one so lets say
208
00:20:56,919 --> 00:21:03,300
we multiply minus two to the power thirty
one with minus two to the power thirty one
209
00:21:03,300 --> 00:21:09,649
the answer will be two to the power sixty
two which is well outside the range of a thirty
210
00:21:09,649 --> 00:21:14,730
two bit number system answer as a result will
have an overflow but lets say we dont want
211
00:21:14,730 --> 00:21:20,899
to have an overflow and we want to have some
mechanism by which we can store ah the ah
212
00:21:20,899 --> 00:21:26,320
store the product without an overflow
so for this lets do a little bit of math here
213
00:21:26,320 --> 00:21:33,980
so ah as as you see the largest number that
we can get by multiplying two sign numbers
214
00:21:33,980 --> 00:21:42,390
ah two thirty two bit sign numbers two [rate/raise]
two raise to the power sixty two if i considered
215
00:21:42,390 --> 00:21:46,390
to unsigned number so basically the largest
number ah that i can get ah so so in a in
216
00:21:46,390 --> 00:21:50,299
a unsigned number system with thirty two bits
ah the largest number is two raise power thirty
217
00:21:50,299 --> 00:21:58,279
two minus one if i sort of squared these then
this will be two to the power sixty four minus
218
00:21:58,279 --> 00:22:04,100
two times plus one so we shall see that in
both these cases so this is sign this is sign
219
00:22:04,100 --> 00:22:07,850
multiplication will be consider them to be
sign number this is unsigned so in any case
220
00:22:07,850 --> 00:22:09,390
beat either signed or unsigned sixty four
bits are sufficient to keep the product sixty
221
00:22:09,390 --> 00:22:15,169
four bits in the sensor sufficient so for
this purpose a r m is two instructions smull
222
00:22:15,169 --> 00:22:19,679
and umull so smull is a sign multiplication
where we actually multiply ah the third and
223
00:22:19,679 --> 00:22:25,690
fourth operand you multiply r two times r
three we do a sign multiplication we assume
224
00:22:25,690 --> 00:22:30,040
that r two and r three are sign and the final
result is a sign so the sixty four bit product
225
00:22:30,040 --> 00:22:32,750
is actually it cant be saved in one register
because its a thirty two bit register but
226
00:22:32,750 --> 00:22:37,500
can saved in two register so the lower thirty
two bits can be saved in r zero and the more
227
00:22:37,500 --> 00:22:42,799
significant thirty two bits can be saved in
r one so together will have a sixty four bit
228
00:22:42,799 --> 00:22:46,350
quantity
so this is the the smull instruction ah does
229
00:22:46,350 --> 00:22:52,320
this with four operands where we multiply
the third and fourth operand and the first
230
00:22:52,320 --> 00:22:58,399
and second operand together store one number
where ah r zero stores the lower thirty two
231
00:22:58,399 --> 00:23:03,570
bits and r one stores the upper thirty two
bits so we have a similar instruction called
232
00:23:03,570 --> 00:23:10,570
umull which is an unsigned multiplication
so this is if you would see this instruction
233
00:23:10,570 --> 00:23:14,590
and the the ah upper instructional lower instruction
are exactly the same only difference is inside
234
00:23:14,590 --> 00:23:16,380
of a signed multiplication its an unsigned
multiplication so we treat r two and r three
235
00:23:16,380 --> 00:23:23,200
also an unsigned quantities and you perform
in unsigned multiplication so the final result
236
00:23:23,200 --> 00:23:28,990
will fit within sixty four bits so lower thirty
two bits can be saved in r zero and the upper
237
00:23:28,990 --> 00:23:34,940
thirty two bits can be saved it r one so the
only difference between smull and umull is
238
00:23:34,940 --> 00:23:41,600
smull does a sign multiplication and umull
does than unsigned multiplication now let
239
00:23:41,600 --> 00:23:47,670
us consider an examples so let as compute
twelve cube plus one and save the result in
240
00:23:47,670 --> 00:23:56,830
r three so lets do one thing lets load the
values so load the values basically means
241
00:23:56,830 --> 00:24:05,570
transfer the values ah so lets transfer twelve
to r zero and lets transfer one to r one so
242
00:24:05,570 --> 00:24:08,220
now lets perform the logical competition in
a r m i s a ah the at symbol ah is used to
243
00:24:08,220 --> 00:24:14,430
specify that what lies after it is a comment
so lets first multiply r zero with r zero
244
00:24:14,430 --> 00:24:21,299
which is lets compute twelve square and save
it an r four so r four will contain twelve
245
00:24:21,299 --> 00:24:26,740
square now here is the greatness of the m
l a instruction multiply and accumulate so
246
00:24:26,740 --> 00:24:30,500
here we compute r three is r four times r
zero plus r one r four is already twelve squares
247
00:24:30,500 --> 00:24:39,799
and r zero is twelve so this is twelve cube
plus the value in r one is one so we get twelve
248
00:24:39,799 --> 00:24:43,580
cube plus one so what we can see is that using
the m l a instruction ah computing twelve
249
00:24:43,580 --> 00:24:45,390
cube plus one actually became very simple
and we could actually do it in two assembly
250
00:24:45,390 --> 00:24:50,309
instructions after we had the values in there
in the registers loaded so this is actually
251
00:24:50,309 --> 00:24:55,559
you know very cheap and very fast so the user
should keep this in mind that occasionally
252
00:24:55,559 --> 00:25:00,200
ah you should take a look at some of the advance
instructions that a r m provide such as m
253
00:25:00,200 --> 00:25:06,020
l a smull and umull to make the competition
easier and also reduce the lines of code because
254
00:25:06,020 --> 00:25:09,820
in assembly language lower is the lines of
code more efficient is the program
255
00:25:09,820 --> 00:25:14,299
now lets take a look at some of a r m s advanced
instructions so a r m has a notation of a
256
00:25:14,299 --> 00:25:18,399
shifter operand so ah lets see what it is
so considered ah a register so we can optionally
257
00:25:18,399 --> 00:25:24,110
specify after a register i d a shift amount
so there are four ways that we can actually
258
00:25:24,110 --> 00:25:31,560
shift a register in a r m so its [le/less]
so l s l so let me first explain what is there
259
00:25:31,560 --> 00:25:36,860
in this table so l s l means logical shift
left so let me just write or maybe i can write
260
00:25:36,860 --> 00:25:41,870
here l s l sorry l s l is shift left l s r
is logical shift right so this is similar
261
00:25:41,870 --> 00:25:48,380
to simple risk a s r is arithmetic shift right
so there is no arithmetic shift left so thats
262
00:25:48,380 --> 00:25:55,649
the reason we have not defined it so l s l
is the same as the l s l in simple risk a
263
00:25:55,649 --> 00:26:01,710
logical shift left and so then there are two
kinds of right shift so in the logical shift
264
00:26:01,710 --> 00:26:06,559
right we add zeros to the m s b and in the
arithmetic shift right we replicate the sign
265
00:26:06,559 --> 00:26:11,500
bit so given a register ah we can ah add these
three kinds of shifts to it and also we have
266
00:26:11,500 --> 00:26:17,780
this r o r kind of shift
so so will discuss what an r o r is ah when
267
00:26:17,780 --> 00:26:26,890
we come to this part of the figure the lower
part of the figure and then we can shift a
268
00:26:26,890 --> 00:26:33,580
register either by a certain shift amount
which can be between in anywhere between zero
269
00:26:33,580 --> 00:26:40,290
one thirty one or we can shift it by the amount
written in a register return in a another
270
00:26:40,290 --> 00:26:45,270
register so basically we can put in a registered
over here or we can consider this immediate
271
00:26:45,270 --> 00:26:50,030
which encroach the shift amount how much we
should shifted by so let us consider a simple
272
00:26:50,030 --> 00:26:55,559
five bit example and let see we want to logically
shifted left by one position so in this case
273
00:26:55,559 --> 00:26:58,460
zero will come here so will have zero one
one zero which is essentially you know this
274
00:26:58,460 --> 00:27:09,550
part has come over here zero one one zero
and we shift in a zero in a l s b position
275
00:27:09,550 --> 00:27:17,149
so this a logical shift left so ah in a r
m ah we ah [w/we] will see in the next few
276
00:27:17,149 --> 00:27:24,059
slide that it is possible to ah actually fold
in the shift information as a part of the
277
00:27:24,059 --> 00:27:27,440
operand specification so we dont need a separate
shift instruction but lets first appreciate
278
00:27:27,440 --> 00:27:36,510
the types of shifts in a r m first ah subsequently
we have an l s r so in l s r if u have [ze/zero]
279
00:27:36,510 --> 00:27:43,730
one zero one one so one zero one one will
again get replicated over here in one zero
280
00:27:43,730 --> 00:27:50,990
one one and in the m s p position we will
shift in a zero similarly for the arithmetic
281
00:27:50,990 --> 00:27:55,409
shift right the bits one zero one one will
get shifted to the right and in the m s p
282
00:27:55,409 --> 00:28:00,100
position will shift in a one ah the reason
being that we are replicating the sign bit
283
00:28:00,100 --> 00:28:08,330
the sign bit here is one so we are just replicating
it is arithmetic shift right
284
00:28:08,330 --> 00:28:13,450
now lets [incantive/introduce] introduce the
rotate right instructions so r o r is rotate
285
00:28:13,450 --> 00:28:20,151
right so what we do in this case you want
to rotated right by one position so ah so
286
00:28:20,151 --> 00:28:25,590
rotate right is basically a right shift with
the values that is falling off the least significant
287
00:28:25,590 --> 00:28:29,860
position they come and sit in the most significant
position so lets see lets consider one zero
288
00:28:29,860 --> 00:28:36,269
one one if you rotated right the first thing
that we do is we shifted to the right by one
289
00:28:36,269 --> 00:28:39,230
position so one zero one one over here gets
reflected over here subsequently what do we
290
00:28:39,230 --> 00:28:43,340
write in the m s p we write in the m s p whatever
was shifted out of the least significant positions
291
00:28:43,340 --> 00:28:49,690
in this case zero were shifted out these are
the felt to the right so essential zero comes
292
00:28:49,690 --> 00:28:52,389
and it is put in the m s p so essentially
we are taking a set of bits and we are just
293
00:28:52,389 --> 00:28:57,039
is rotating them so another important point
is that in the shifting operations in l s
294
00:28:57,039 --> 00:29:03,940
l l s r and a s r we are actually introducing
new bits which were not originally there in
295
00:29:03,940 --> 00:29:05,090
the set of bits right at either the left position
or the right position ah in comparison in
296
00:29:05,090 --> 00:29:10,100
the case of a rotate ah instruction ah we
are not doing that so whatever bits fall out
297
00:29:10,100 --> 00:29:14,820
of the least significant position are added
to the most significant position so now the
298
00:29:14,820 --> 00:29:16,120
given that these four shift operations are
clear lets actually take a look at ah an example
299
00:29:16,120 --> 00:29:18,419
of these so let us without an example it wont
have been cleared
300
00:29:18,419 --> 00:29:23,809
so lets consider the following example so
right ah a r m assembly code to compute r
301
00:29:23,809 --> 00:29:28,760
one equals r two by four so ah essentially
dividing a number by four as was discussed
302
00:29:28,760 --> 00:29:33,840
in chapter two as same as right shifting it
by two positions ah by this not a logical
303
00:29:33,840 --> 00:29:41,960
right shift this is an arithmetic right shift
will call it an a s r and we shifted by two
304
00:29:41,960 --> 00:29:45,929
positions so in the case of the a r m i s
a we actually dont have ah we actually dont
305
00:29:45,929 --> 00:29:49,600
have shift instructions so so basically in
the previous slide what we have seen l s l
306
00:29:49,600 --> 00:29:55,590
l s r a s a r o r their essentially shift
directives but they are not ah so the important
307
00:29:55,590 --> 00:29:58,370
distinction that needs to be made is a these
are not you know separate instructions in
308
00:29:58,370 --> 00:30:00,012
their own right
so what we essentially do is that we use the
309
00:30:00,012 --> 00:30:06,380
move instruction and we are treating this
entire new expression that you are not seen
310
00:30:06,380 --> 00:30:14,019
before as actually one operand it is true
that there is a comma in the middle but this
311
00:30:14,019 --> 00:30:18,529
is actually being treated as one operand and
this is being moved over here so what is this
312
00:30:18,529 --> 00:30:23,070
doing what this is doing is that this expression
is taking the value of r two and right shifting
313
00:30:23,070 --> 00:30:24,550
it so maybe i can write the right shift right
shifting it by two positions so these ah i
314
00:30:24,550 --> 00:30:25,550
am using the standard right shift operator
so we are right shifting it by two positions
315
00:30:25,550 --> 00:30:27,509
which is tantamount to equivalent to dividing
the number by four and then this ah entire
316
00:30:27,509 --> 00:30:30,960
the result of this is being transferred to
r one
317
00:30:30,960 --> 00:30:35,870
so as i said let me just you know reemphasis
that a r m in the most variant so of a r m
318
00:30:35,870 --> 00:30:38,399
assembly at least most of the simple variance
dont have dedicated shift instructions rather
319
00:30:38,399 --> 00:30:41,460
the shift is folded into the definition of
the source operand itself so in the source
320
00:30:41,460 --> 00:30:44,929
operand we can specify the source operand
as a register and you you know this is not
321
00:30:44,929 --> 00:30:46,590
possible to do with an immediate but as a
registered we can specify the source operand
322
00:30:46,590 --> 00:30:47,940
and optionally specify a shift amount and
the type of shift so ah there will be a comma
323
00:30:47,940 --> 00:30:52,400
between ah the source register and the type
of shift in the shift amount by the entire
324
00:30:52,400 --> 00:30:53,400
ensemble is treated as a single operand and
what the hardware would do is it would first
325
00:30:53,400 --> 00:30:54,400
evaluate the value of this expression which
basically mean shift r two by two positions
326
00:30:54,400 --> 00:30:55,400
to the right and then transfer it to r one
so lets now take a look at a slightly more
327
00:30:55,400 --> 00:30:56,400
complicated example so lets compute r one
equals r two plus r three times four so multiplying
328
00:30:56,400 --> 00:30:57,400
a number by four is a same as shifting it
to the left by ah sorry ah by two position
329
00:30:57,400 --> 00:30:58,400
so what we will do is will write add r one
so since the first operand is the destination
330
00:30:58,400 --> 00:30:59,400
ah so we will have r one is being set two
so here the entire operand is actually just
331
00:30:59,400 --> 00:31:00,400
one source operand right so we can treat this
as a single source operand so will add r one
332
00:31:00,400 --> 00:31:01,400
as r two plus r three left shift it by two
positions or multiplied by four its a same
333
00:31:01,400 --> 00:31:02,400
thing ah so will have r one is r two plus
four times r three which has been folded into
334
00:31:02,400 --> 00:31:03,400
one single assembly statement and this will
make the execution of the assembly statement
335
00:31:03,400 --> 00:31:04,400
extremely efficient so the important point
to note is that a r m does not have separate
336
00:31:04,400 --> 00:31:05,400
shift instructions rather a shift is folded
in to the definition of the operand itself
337
00:31:05,400 --> 00:31:06,400
to the specification of the operand itself
now lets take a look at compare instruction
338
00:31:06,400 --> 00:31:07,400
so they worked very you know you know very
similar fashion as simple risk so compare
339
00:31:07,400 --> 00:31:08,400
instruction at does the job of comparing and
then its sets the flags so lets first take
340
00:31:08,400 --> 00:31:09,400
a look at a simple compare instruction c m
p instruction we are a c m p simple risk as
341
00:31:09,400 --> 00:31:10,400
well and the format was the same the first
operand was the register the second operand
342
00:31:10,400 --> 00:31:11,400
was either a registered or an immediate so
we are comparing r one and r two and after
343
00:31:11,400 --> 00:31:12,400
this so [wh/what] what is comparing r one
and r two mean it essentially means that we
344
00:31:12,400 --> 00:31:13,400
subtract r two from r one so we compute r
one minus r two and we set the flags after
345
00:31:13,400 --> 00:31:14,400
computing r one minus r two so in simple risk
we are a flags register ah in a r m it is
346
00:31:14,400 --> 00:31:15,400
called the c p s c p s r register is the same
as what was flag sensible risk ah so this
347
00:31:15,400 --> 00:31:16,400
is c p s r register c p s r register is called
the current program status register which
348
00:31:16,400 --> 00:31:17,400
does not a one flag it has four flags so the
first flag is negative so negative indicate
349
00:31:17,400 --> 00:31:18,400
that when i did r one minus r two r one was
less than r two (Refer Time: 43:00)
350
00:31:18,400 --> 00:31:20,193
so in this case the negative flag will be
equal to one then we are the zero flag which
351
00:31:20,193 --> 00:31:21,193
means if r one was equal to equal to you know
same as r two in a zero flag will be equal
352
00:31:21,193 --> 00:31:22,193
to one and the negative flag will be equal
to zero in the [car/carry] carry flag is basically
353
00:31:22,193 --> 00:31:23,193
done to indicate that i didnt addition and
after that i carry was generated and similarly
354
00:31:23,193 --> 00:31:24,193
the overflow flag is set to indicate that
the result acceded the range of the number
355
00:31:24,193 --> 00:31:25,193
system as a result it cannot be saved and
so the programmer should be told that look
356
00:31:25,193 --> 00:31:26,193
the addition or multiplication that you are
trying to do acceded the range other number
357
00:31:26,193 --> 00:31:27,193
system and as a result there has been an overflow
so here is an important point that we should
358
00:31:27,193 --> 00:31:28,193
need to note it is slightly known intuitive
so thats the reason i am putting a big arrow
359
00:31:28,193 --> 00:31:29,193
to its left if we need to borrow a bit in
a subtraction so carry is mainly ah used in
360
00:31:29,193 --> 00:31:30,193
the context of addition but we need to borrow
a bit ah as is in the case of subtraction
361
00:31:30,193 --> 00:31:31,193
then we set the carry flag to zero rights
so the moment we need to borrow we said the
362
00:31:31,193 --> 00:31:32,193
carry flag to zero and if you do not need
to borrow a bit we set it to one
363
00:31:32,193 --> 00:31:33,193
so so this is slightly tricky and non intuitive
let me repeat it once again what i just said
364
00:31:33,193 --> 00:31:34,193
what i said is that if we need to borrow a
bit in a subtraction so a subtract two numbers
365
00:31:34,193 --> 00:31:35,193
as necessary to borrow we will set the carry
flag to zero for example if we or subtracting
366
00:31:35,193 --> 00:31:36,193
ah zero minus five so this in if i write in
binary it is the since zero minus right so
367
00:31:36,193 --> 00:31:37,193
in this case when i am actually subtracting
there is a need to actually borrow bits so
368
00:31:37,193 --> 00:31:38,193
in this case the carry flag will be set to
zero otherwise it will be set to one so similar
369
00:31:38,193 --> 00:31:39,193
to the compare instruction we have a c m n
which is actually called compare negative
370
00:31:39,193 --> 00:31:40,193
format is the same but instead of actually
ga setting the flags after computing r one
371
00:31:40,193 --> 00:31:41,193
minus r two we compute r one plus r two or
this is the same as we can think of this c
372
00:31:41,193 --> 00:31:42,193
m n r one r two is essentially equivalent
to compare r one with minus one times r two
373
00:31:42,193 --> 00:31:43,193
right so so these so thats a reason its called
compare negative were instead of comparing
374
00:31:43,193 --> 00:31:44,193
r one with r two we are comparing r one with
minus one times r two similarly we have the
375
00:31:44,193 --> 00:31:45,193
test t s t instructions so we ah set the flags
after computing r one and r two so if r one
376
00:31:45,193 --> 00:31:46,193
and r two ah give the final result is zero
will set the zero flag or will essentially
377
00:31:46,193 --> 00:31:47,193
take a look at the final result and based
on that will set the flags ah
378
00:31:47,193 --> 00:31:48,193
so lets say the final result m s b is one
will set the negative plans and so on so t
379
00:31:48,193 --> 00:31:49,193
q basically tests if ah so so what we do is
we compute and x o r or of r one and r two
380
00:31:49,193 --> 00:31:50,193
so we ah set the flags after computing r one
x o r or r two and we take a look at the result
381
00:31:50,193 --> 00:31:51,193
is a result is all zeros will set the zero
flag otherwise ah if the if the result has
382
00:31:51,193 --> 00:31:52,193
[pos/positive] has a positive sign bit will
set the negative flag so ah so t s p t q n
383
00:31:52,193 --> 00:31:53,193
c m n that typically not very commonly use
even the you can use them whether situation
384
00:31:53,193 --> 00:31:54,193
for demands and if you feel let we can reduce
the number of instructions by using these
385
00:31:54,193 --> 00:31:55,193
flags so so the ultimate reference for any
kind of a r m instruction is the a r m instruction
386
00:31:55,193 --> 00:31:56,193
reference manual which we can get on a r m
s website so ah so they are will find the
387
00:31:56,193 --> 00:31:57,193
lot of these concepts explain in great detail
so the reason that i am not going into more
388
00:31:57,193 --> 00:31:58,193
dept is basically because some of them have
many many cases and sub cases
389
00:31:58,193 --> 00:31:59,193
so this is better delt with in a manual which
describes all the cases in great detail so
390
00:31:59,193 --> 00:32:00,193
v for most of our work will only strict to
the compare flag ah i am sorry the compare
391
00:32:00,193 --> 00:32:01,193
instructions and the compare instructions
will tell as using the negative and zero flags
392
00:32:01,193 --> 00:32:02,193
which is very similar to what we had in simple
risk ah to basically the zero flag was the
393
00:32:02,193 --> 00:32:03,193
equality flag and ah if r one is greater than
r two were setting the g t flag so in this
394
00:32:03,193 --> 00:32:04,193
case ah the flags are different with a connotations
is similar so will use mainly the compare
395
00:32:04,193 --> 00:32:05,193
instructions to do our job so [instr/instruction]
so know ah a r m has some more interesting
396
00:32:05,193 --> 00:32:06,193
instructions so the compare instruction are
not the only instructions that set the flags
397
00:32:06,193 --> 00:32:07,193
rights in simple risk c m p was the only instruction
that was setting the flags per in a r m that
398
00:32:07,193 --> 00:32:08,193
is not the case you can add an s suffix to
regular alu instructions such that they will
399
00:32:08,193 --> 00:32:09,193
set the flag
so in the instructions with the s suffix will
400
00:32:09,193 --> 00:32:10,193
set the flags in the c p s r register for
example if i lets the add two numbers so i
401
00:32:10,193 --> 00:32:11,193
can ah replace the add instructions with the
add s instructions so the add s or the sub
402
00:32:11,193 --> 00:32:12,193
s instructions will actually set the flags
so they will perform the addition or the subtraction
403
00:32:12,193 --> 00:32:13,193
subsequently based on the result they will
set the flags whether number is negative or
404
00:32:13,193 --> 00:32:14,193
zero or if the addition let to an over flow
so all of this condition can be set
405
00:32:14,193 --> 00:32:15,193
now lets take look at set of very very interesting
instructions and actually use the flags so
406
00:32:15,193 --> 00:32:16,193
ah the first instructions that will look at
is a d c ah the a d c is an add with carry
407
00:32:16,193 --> 00:32:17,193
ah instruction so in this case we do add with
carry is r one equals r two plus r three plus
408
00:32:17,193 --> 00:32:18,193
the carry flag rights if there is some previous
carries so this a d c instruction ah we shall
409
00:32:18,193 --> 00:32:19,193
will find an example in the book that uses
it but essentially the idea is that if previously
410
00:32:19,193 --> 00:32:20,193
a carry was generated then we can sort of
use the carry so basically we will add ah
411
00:32:20,193 --> 00:32:21,193
r two and r three similar to the add instruction
and also add the carry similarly we have s
412
00:32:21,193 --> 00:32:22,193
p c instruction subtract with carry which
first subtract r two minus r three and then
413
00:32:22,193 --> 00:32:23,193
it subtract it with the knot of the carry
flag so this is slightly tricky so what did
414
00:32:23,193 --> 00:32:24,193
we say lets go back to the the slide that
talked about the borrow bit so if a need to
415
00:32:24,193 --> 00:32:25,193
borrow a bit in a subtraction reset carry
to zero otherwise we set it to one so in this
416
00:32:25,193 --> 00:32:26,193
case in the previous subtraction effect let
to a borrow the carry flag is zero so knot
417
00:32:26,193 --> 00:32:27,193
of the carry flag is actually one
so we what we do is that this is sort of giving
418
00:32:27,193 --> 00:32:28,193
ah effect to a borrower implementing a borrow
if do the regular subtraction and then we
419
00:32:28,193 --> 00:32:29,193
subtract a knot of the carry flag and knot
of the carry bit can be considered the borrow
420
00:32:29,193 --> 00:32:30,193
bit because their connotation are exactly
rewards so ah you will find an example in
421
00:32:30,193 --> 00:32:31,193
the book for we use the a d c and s b c instructions
to actually subtract large ah sixty four bit
422
00:32:31,193 --> 00:32:32,193
or even larger quantities the r s c instruction
is similar to r s b were we do a reverse subtract
423
00:32:32,193 --> 00:32:33,193
but in this case we do a reverse subtract
which is r three minus r two r three minus
424
00:32:33,193 --> 00:32:34,193
r two ah but we also subtract the borrow bit
which is the knot of the carry flag from this
425
00:32:34,193 --> 00:32:35,193
so here is one example that will show you
the power of ah what the carry flag and the
426
00:32:35,193 --> 00:32:36,193
add s and a d c instructions to so this typically
i used to set as an exam question ah and i
427
00:32:36,193 --> 00:32:37,193
ask to use students to do this is simple risk
so this was very difficult and is used to
428
00:32:37,193 --> 00:32:38,193
take a lot of lines because ah you know simple
risk didnt have the support to do it so what
429
00:32:38,193 --> 00:32:39,193
do you want to do you want to do sixty four
bit addition using thirty two bit integers
430
00:32:39,193 --> 00:32:40,193
so consider the smull and the umull instructions
so they save the result in a pair of registers
431
00:32:40,193 --> 00:32:41,193
so lets assume the this is the case lets assume
that is sixty four bit value which is called
432
00:32:41,193 --> 00:32:42,193
also called a long value is stored in registers
r two and r one so r one contains the lower
433
00:32:42,193 --> 00:32:43,193
thirty two bits and r two contains the upper
thirty two bits similarly we have another
434
00:32:43,193 --> 00:32:44,193
register pair r four and r three were r three
contains the lower thirty two bits an r fore
435
00:32:44,193 --> 00:32:45,193
contains the upper thirty two bits and together
they make a large sixty four bit number so
436
00:32:45,193 --> 00:32:46,193
we we want to add this pair of numbers this
long numbers and also save them in two registers
437
00:32:46,193 --> 00:32:47,193
r five and r six so what we do is first
438
00:32:47,193 --> 00:32:48,193
so lets say the number are of this form r
two r one and r four r three you want to add
439
00:32:48,193 --> 00:32:49,193
them so the first thing that can be done is
we can add r one and r three and save the
440
00:32:49,193 --> 00:32:50,193
result in r five this is exactly being done
over here but note the s suffix with the add
441
00:32:50,193 --> 00:32:51,193
instruction the s suffix is basically telling
the add instruction that look you go and set
442
00:32:51,193 --> 00:32:52,193
the flags so here which flag are interested
in we are interested in only a single flag
443
00:32:52,193 --> 00:32:53,193
which is actually the carry flag ah so what
is happening is that if the carry bit is set
444
00:32:53,193 --> 00:32:54,193
we need to record this fact in this is being
recorded in the flags that if there is a one
445
00:32:54,193 --> 00:32:55,193
bit carry this needs to be recorded subsequently
we add r two and r four but we use the a d
446
00:32:55,193 --> 00:32:56,193
c instruction because this add r two and r
four plus the carry so thats a very important
447
00:32:56,193 --> 00:32:57,193
thing is also takes the carry into account
which might have been generated it adds r
448
00:32:57,193 --> 00:32:58,193
two r four and they carry carry and saves
the result in r six right so what is written
449
00:32:58,193 --> 00:32:59,193
is the add s instruction as the values in
r one r three a d c add with carry as r two
450
00:32:59,193 --> 00:33:00,193
r four and the value of the carry flag which
is exactly the same as normal addition had
451
00:33:00,193 --> 00:33:01,193
add s and a d c not been there it would have
been fairly difficult for us to achieve this
452
00:33:01,193 --> 00:33:02,193
task and so so considered a program that has
a lot of you know smull or umull instructions
453
00:33:02,193 --> 00:33:03,193
and they produce sixty four bit outputs to
manage the sixty four bit outputs with ah
454
00:33:03,193 --> 00:33:04,193
you ah you know to manage them and add and
subtract them would have been very difficult
455
00:33:04,193 --> 00:33:05,193
had we not had this particular mechanism so
given the fact that we have seen this actually
456
00:33:05,193 --> 00:33:06,193
let me go back to the previous slide given
the fact that you have taken a look at sixty
457
00:33:06,193 --> 00:33:07,193
four bit addition i would request the readers
to also look at sixty four bit subtraction
458
00:33:07,193 --> 00:33:08,193
so in the case of sixty four bit subtraction
idea is very simple we do exactly this so
459
00:33:08,193 --> 00:33:09,193
so we will have exactly the same thing and
instead of addition will have a subtraction
460
00:33:09,193 --> 00:33:10,193
so first instead of an add s let me just give
a hint but i will not tell you the entire
461
00:33:10,193 --> 00:33:11,193
solution so we can instead of an add s we
can have a sub as you can write something
462
00:33:11,193 --> 00:33:12,193
and subsequently we need to go back to a set
of instructions and use the s b c instruction
463
00:33:12,193 --> 00:33:13,193
the s b c instruction will subtract with carry
which will take the borrow into account and
464
00:33:13,193 --> 00:33:14,193
we can do something and achieve also achieve
subtraction in sixty four bit subtraction
465
00:33:14,193 --> 00:33:14,196
in two instructions