Assembly

Course
Time
13 hours 15 minutes
Difficulty
Beginner
CEU/CPE
14

Video Transcription

00:01
Hello. This is Dr Miller, and this is Episode 12.1 of Assembly.
00:06
Today we're gonna talk about vector registers and then neon
00:10
it's a vector registers.
00:12
So the vector registers and the vector floating point co processor is allows us to do floating point operations. It in traditionally was a separate co processor. So it performed these floating point operations that the regular processor didn't have the ability to dio
00:29
and then going forward it. This has been deprecate id in favor of the neon architecture, which uses larger registers.
00:38
And then there's a difference between scaler and vector. So when you're talking about the V f. P, we have different registers. For example, we have the floating point status and control register, which has information about the different flags.
00:51
We also have additional registers, so we have ones that start with s and then some registered numbers. Those are 32 bits.
00:58
The D ones start with 60 have 64 bits, and the Cubans have 100 28 bits.
01:03
And then we have a set of what are called scaler registers that conduce scaler operations. So that's s zero through a seven
01:11
and then D zero through D three and these end up representing the same sets of bits and we'll see that in a diagram here in a little bit.
01:19
We also have vector registers.
01:21
So those are S a through S 31 d four through d 31 then Q zero through Q 15.
01:29
And then when you're doing vector operations using the F p, you have this wrap around, if the stride in the bit links, they're set, and so that allows it to do wrapping operations. And this is in older versions of arm and it's deprecate ID.
01:45
So, for example, you'll see some of these, but they won't work on devices like a raspberry pi, which I've been using in this class.
01:53
So here's a typical layout of the scaler and vector registers, and this will be the same for neon as we go forward.
02:00
So we have registers s zero on s one, and those composed together would be registered D zero.
02:06
So it's similar to X 86 where we have smaller registers, which then look like they're composed, is a larger register.
02:13
And then, for example, Q zero is all of these registers put together So it's all of a D zero and D one, which in turn, is is s zero s one s two and s three.
02:24
Same thing for each one of these que registers. And then you have the notion that we have these different scaler operations weaken dio and we can take a scaler and multiply it by a vector. And so these, in that parlance, are the vector registers and confused for vector operations.
02:43
When we get to neon, we will not have is many of these restrictions, and so
02:49
you'll just be able to use any of the registers for that. And so I was, Ah, change in the architecture.
02:54
But here, this just shows D zero through de que zeroth u Q seven or registers s one through s 31. So we have 32 s registers.
03:05
We have 16 d registers, and then we have eight key registers in this diagram.
03:12
But we have, um, the ability to do debugging
03:15
and so you can do info float, and that will show the status register status in control register. It also will just show registers s zero through s 31.
03:24
And so, if you're looking at it and you want to see the floating point or a manager in S zero to s 31? This is a good way to do it. You can also do info vector, which will print all of the registers, which can be a little bit overloading.
03:38
Um, but then also in GDP, you can just print a single register so you can say print dollar sign F zero D zero accuser or whatever number that you want to print.
03:49
So that's probably the easiest way to look at those registers and make sure that they have the values that they think that they should have.
03:57
So neon
03:58
so neon is is arms advanced s i m d or a single instruction multiple data for arm. And so they took the V f p, and they basically scaled it up and allowed it to do more things. So in floating point,
04:14
the VFW, we could just do floating point operations. But with neon, we can also
04:18
do operations on imagers.
04:20
It also has some ability to do some parallel processing. So when we looked at the V f p,
04:27
it only had the ability to basically go off and run in separate mode and then come back with the result. Whereas neon, we can just put the all the instructions together.
04:39
And then neon started with the cortex A eight and some of the newer ones.
04:44
But you can add it to sort of any of the newer types of architectures that that arm is producing.
04:49
And then neon will allow us to do either 6428 bit s I m d,
04:56
um, operations. And you can use those for things like GPS or empathy MP three, decoding.
05:01
And so when we talk about S I m. D, we will look at those types of operations we can do and sort of get appreciation for the power that it has.
05:13
So here's some example Neon instructions.
05:16
So we can do so. The V stands for Vector, and that's what
05:20
almost all the neon instructions will have in front of them.
05:25
So we have things like absolute value. We can add some registers, weaken, do a comparison. We can do a duplications. You can copy a bunch of data to all lanes of the vector.
05:35
We can load a value. We can figure out what the men and the maxes of different numbers weaken do movement and multiplication.
05:45
And so these are some examples. You can go to the developer pages and see the full specifications of all of these and more that I didn't include.
05:55
So, um, the vector load. So here's an example of an instruction. So we got defector load register, so V l d r
06:02
we'll talk about conditional programming later,
06:05
and then we can basically do a data type. So the data type,
06:10
um,
06:11
is
06:13
one of these. So we got I and then a number or s. So I stands for Imager s stands for Signed you stands for unsigned F stands for floating point.
06:24
And then these can be either 8 16 32 or 64. So I can loden imager. That's eight bites or 16 or 32 or 64
06:32
and it could be signed could be unsigned. And then we got the two floating point. So we got either 32 bit floating point or a 64 bit floating point.
06:41
And then here we can just load a direct constant in, um for that,
06:46
and then we can either load it into a de register Oren s register. So remember, D is going to be,
06:51
um 64 bits s is going to be 32 bits.
06:57
We can also do a vector move on so we can do
07:00
ah, either move or moving. Invert. So this is a movie, and this is moving in, Bert, and then you again, we can have conditional execution. We can add any of these data types, so typically it's gonna load them in. I'm in a similar way so you can load imagers or floating point,
07:19
and then you can either load it into a quad register or a,
07:24
which is 100 28 or de register, which is 64.
07:30
So here is some examples, so we can do a regular move into register are nine of the value zero xff,
07:39
and then we can copy from our nine into s three. So we have to use the V move operation in order copy data into that register.
07:46
Um, you could load an immediate into a queue register, right? So it's gonna put the number zero in that key register.
07:53
Remember again that for these right, we can only do so many bits because each of these instructions takes up
07:59
some number of bits and we can only put for
08:03
all the instructions in arm are four bites. And so
08:07
there are some limitations to what you can do with some of these V move operations.
08:11
But you can do things like using the vector load. So, for example, I can load a,
08:16
um, variable into our zero, and then I can use this
08:22
El de are de eso that is double wide.
08:26
And so what it's gonna do is when I say that if I give it the register are too. It's gonna load the data from our zero into R two and r three because I added this D So I basically put two registers where 64 bits 32 in this register, 32 in this register.
08:43
And then if I do a V move, I can copy basically R two and R three into s for so little copy both of them, because it's going to read,
08:52
um,
08:54
all of the bits into their.
08:56
So we have additional examples, so the vector move long. So one of the things when when they're doing this is they have the ability to basically do sign extension,
09:07
so either you can do sign extension. So if it's a negative number, you keep that sign bit and you fill it up. Or zero extension, which would allow you to have imagers, and they just get into a bigger register. So we'll get twice their length and ever get put into a larger register. We have moving narrow, so we're going the opposite way.
09:28
So you're copying the smallest half of the register, and then basically some bits are gonna get thrown away so you'd have toe understand that this end is going to stand for the narrow part.
09:39
And we also have, um, additional moving narrow with with saturation or sort of the very complicated neuve que word. It's gotta saturating narrow
09:50
into an unsigned result.
09:52
So you won't need these most of the time. But the armed documentation will tell you exactly what they do, and then you can always create examples and see
10:00
if you understand how they work.
10:03
So here is the from the armed documentation.
10:05
So, for example, we got move l. So we're going to move it, move and extend from a 30 or 64 bit register into ah 128 bit register.
10:18
And again we got the other ones, which I won't go over in a sailor here,
10:22
right? If it's if it's got a que behind it, that means that we're going to go to a Q word we get. We additionally have conditions.
10:31
Um, And then we got the destination register and, um,
10:35
in some of these rates, So cute Ian and GM or here, these have a different destination register for the further narrowing operation.
10:45
And then here we can give the types we got signed unsigned integers, um, for all of these different operations and there's different combinations of them.
10:56
So let's look at an example here. So,
10:58
for example, we can load s zero with this number, so I got 12345678 Remember, these are each going to be into bite pairs, so 78 is one bite, and we can see that down here.
11:09
Um, I also move a one b one c one D one into s one,
11:13
and then we do a move and extend into, um que nine from d zero. So remember, at zero and s one are the parts of d zero. And so when I move that as a ZA eight byte,
11:28
eight bit imager, right, so unsigned eight bits, we can see that when it goes here, we add some extra zeros in here, right?
11:37
So those extra zeros are making it so that we go from an eight bit an eight, an eight bit imager to a 16 bit imager. So when I look at the 16 bit imager, there's actually
11:50
bite here of zero right 0000 so you can see it interspersed zeros in between all of those.
11:58
And then here we have another example. So into Q 10 we move 16
12:03
um, bit imagers into into it so we can see here that the 78 and 56 remain the same. And then we had two pairs of zeros and the 34 and 12 remained the same. And we had two zeros
12:16
so that when you go from, we have a, um the 16 bit here, right, which is what we started with.
12:24
We have 16 bits here, and then we had another 16 bits of zeros on the top for each one.
12:30
And so
12:31
your 16 bit imager here became a 32 bit register,
12:35
so the value got bigger so that we can use that. And so in these we have basically four imagers that just all of a sudden went from
12:46
16 bits to 32 bits each.
12:52
We can also do operations like the vector multiply so we can say mole, which has a key register or V mole in there and so
13:01
we can have any of these data types. So we got some imagers and we got some floating points, and so then you can do multiplication on these. So basically the elements of the vector are multiplied together. So we have an example here.
13:15
So, for example, if I move to and four into zero and this one
13:20
and then three and seven into S two and s three
13:24
when I try and multiple I d zero and D one together, the result is going to get stored in D one,
13:30
so we'll take d zero the first element and multiply by D won the first element because we're doing 32 bit multiplication, right? And these air 64 bit registers.
13:39
So I have two times three, and that gives me six and then I have seven times four. And so that gives me 28 which in hexes onesie.
13:50
So we can kind of get an idea of the multiple processing because I was able to just multiply
13:56
two numbers,
13:58
two sets of numbers together and get the result in one instruction, and we'll see more examples of that in the future.
14:07
So the benefit of the vector operations is it allows us to do wider math operations, so we have the normal 32 bit on the S registers, but it can overflow into those 64 bits,
14:18
and then we can do 64 bit operations that go into 128 bits.
14:22
And as we saw in that last example, we could do multiple operations in one instruction which will help with efficiency of the processor.
14:31
So today we talked about some of the vector registers, the history and kind of how they're laid out. And then we talked about the neon architecture in some examples of that.
14:41
So in the future, we're going to talk about some or examples of vector instructions. So we'll give an example of how toe do Cem imager multiplication
14:50
also then look at floating point operations. So we didn't go into many floating point. We'll do some examples with that,
14:56
and then we'll also look at the Newman S I M D operations.
15:03
So here's our quiz. How big or each of the vector registers?
15:07
So that s registers are 32 bit
15:11
the D registers of 64 bit, and the Q registers 128 bits.
15:16
If you have questions, you can email me Miller MJ at you and Kate I e. To you, and you can find me on Twitter at Mail House 30.

Up Next

Assembly

This course will provide background and information related to programming in assembly. Assembly is the lowest level programming language which is useful in reverse engineering and malware analysis.

Instructed By

Instructor Profile Image
Matthew Miller
Assistant Professor at the University of Nebraska at Kearney
Instructor