In this video, we'll be looking into how actually the machine instruction or opcode works.
All ARM instruction code or opcodes are 32 bit in Armv5 architecture.
They have a 32 bit armv7.
And when ARM eight came into picture armv8 it is 64 bit.
Uh, so for example, uh, if you see this as an opcode example of an opcode which actually writes value
four in R0 register.
So as we said in the previous video, an opcode can have an operand.
Think of this as an opcode E three a0 which actually writes value but it needs operand.
It needs to know what value I need to write and where I need to write.
And if if you see this, it has a value of operand as four four is like it is need to, it is informing
the CPU like this opcode is informing CPU.
I need to write value four in register r0.
And this if you see this opcode and this values are same.
So the CPU will get this value.
Then it will look into the operand.
It says I need to write a value five in register R1.
So now let's see practically how I can demonstrate this one.
We have installed chemo and we will be emulating the Konex Board.
And the Konex Board has a address space where the flash is located at the starting 16 MB of the uh dislocated
like I don't know how to display.
Yeah, it is located 16 MB of the starting address space, and then you have a Ram of 64 MB, which
is like starting it at a of a three zeros and four zeros.
So whenever you perform a reset the CPU will start executing instructions.
Whatever is present at this particular 0000 it will start executing this instructions.
So for this, uh, we need to create a flash of 16 MB b and if we create a file using DD command and
pass it as a input, it should be fine.
So flash file format for chemo is very simple if I want to if chemo wants to get the byte from address
X, the flash chemo will be reading the byte from.
Offset x in the file.
So this is how Kim was emulating a flash memory of this particular board.
So yeah.
Now okay, so I need to create this flash.
Uh.
Of.
I'm using Dev zero to create a 16 MB of flash.
I'll create this one.
Now I have a file of flash dot bin which is of size 16 MB, and if I do a hex dump on this.
It's all zeros.
Now how to run this flash thing?
I have key move which I have installed qemu system arm m convex.
Convex is the board.
And then I need to provide the flash.
I'm providing p flash flash dot bin.
And then I say serial is I do not need any serial port.
And I do not need any GI.
If I do not pass this it will open me a GUI window.
I do not need this guy window, so I'll say no graphic and it will give me a monitor mode where I can
check what all the resistors values of the board.
So the next board currently it is not having any particular resistors.
Uh R 15 is the program counter and R 14 is a link resistor.
Okay.
Now what I'll do is uh, now we need to write our actual values.
Right.
We need to write this values in the, uh flash.
So we have a tool known as hex edit, which actually sorry, I need to say and it is a man hex edit
hex.
It is a tool which we use and edits the file in hexadecimal or Ascii.
So I'll say edit flash dot bin and you can see all are zeros.
All are 16 MB of zeros.
So now we need to write a value of which actually writes the value uh for in our zero resistor.
For that we need to write this in the file flash dot bin.
So I'll say zero zero and 0004.
Then A3A0.
And I need to say for if you go into the man page of hex edit, it says to save this file I can say
f2, I'll say f2 and this is saved.
But if I want to exit from this one I need to say control X or control C.
If I do not want to exit, I'll say control C.
Now if I say hexdump flash dot bin, uh, it is having in a different order 400A is 0E3.
But this if I run this one, this will not work.
So if I run this, I don't see.
Actual values.
I see something known as a all F's, which is not correct, so I need to convert this into the same
format as this one, right?
When I do an hexdump, it should show me this one.
This is because of the Indians.
Okay, so I need to write in a reverse one.
So I will say hex edit and instead of saying 00040400 and instead of saying three zero, I say A0E3F2
and control C.
If I say hex dump, I can see it is now 0004E30, which is the same format.
And now I'll run this command and I'll say info registers.
And now the value of r zero is four.
Correct.
So this is what we want to achieve right.
We wanted CPU to write the value for in R zero register.
And we are able to do it by writing f op code which is being executed by this particular CPU or this
particular board which is having arm, CPU and we are able to get the value of four by writing just
f 32 bit number.
So this is what I wanted to convey you that CPU does not understand any high level language.
It only understands the machine code or OP code, which is a binary ones and zeros.
If you convert this hexadecimal into ones and zeros, then CPU can execute those instructions.
So CPU only knows it does not know Elf.
It does not know X, it only knows ones and zeros.
Now if I want to change this, I want to write A1005E3A0.
Okay.
Now what I'll do is I'll open hex editor again.
Now I'll say one zero.
Uh zero five.
Sorry.
Zero five.
This will not work because again, we are writing in a different order.
So I'll just show you if you write this one, this will not work.
So F2 will save this one.
I'll say control x f1.
I do not know.
If control X save.
Yes.
This is too strange to say.
Control x.
Yes x tum.
Is having 0510 and it needs 1005.
So again Indians need to do in a different way.
Uh, you need to write zero five first and one zero next.
So control x.
And this is having this one now.
Now I can run the command and I say info resistors.
R1 is having five right.
So again what we did was we wrote this one.
And this is opcode for writing value five and it changed to R1.
Updated the value I can also show you like if I say instead of I say here.
One zero.
Let's see what will be happening.
What happens?
One zero and R one sign one zero.
Okay.
And now I also I can, uh, update hex edit and I can do, I can do multiple instructions as well.
So I can say one zero.
Uh, uh, for this, this one zero, it is zero zero.
Sorry.
And zero zero.
So first need to write I think for, for zero zero.
So I'm writing again uh both r one and r zero and E30 and e to write A0E3.
Sorry e three.
So e two will have a different value.
Save this one.
Now run info resistors R zero is having no four and R one is having one zero value which is hexadecimal.
So we try.
Now we have using hex -- hex edit we wrote two opcodes I mean two instructions.
One instruction is to write value one zero in R one register, and one more instruction is to write
the value for in R zero resistor and got updated.
And we have used a chemo emulator to display this in a practical format.
So what I wanted to convey in this video is like a processor only understands machine instruction.
It does not understand assembly language or C language, it only understands machine instructions.
And finally, all our code which we are writing is converting into this machine instructions.