Hello and welcome back.
We are now going to study the ADD and SUB instructions.
So let's get started.
So these are the few variations we have: ADD and SUB for immediate and register.
We have ADD and SUB for register and register.
We have ADD and SUB for memory and immediate.
We also have ADD and SUB for register and memory.
So open up your x64dbg.
And then run to this point.
Open your template two first, of course, and then put your breakpoint here and run to that location.
Step over until you come to this blank line.
And now we are going to put this instruction in there.
So before that, let us modify the register we are going to use. Let's say - register.
So you right-click on our register and modify it.
And we put in 20.
In there, click okay.
So now we are ready to do this instruction.
So click on this blank line here, spacebar, and type ADD -.
And maybe we put a one. Click okay.
So now we are going to execute this line and watch the register. Execute this line by stepping over it.
And now - becomes 21 because we add one to -.
So now - becomes 21.
Next, we are going to try this: subtract register and immediate.
So let's do that now. Subtract.
And then maybe we can put two, two.
Click okay.
And now we are going to execute this line.
What it does is it will minus two from the value in -.
So let's step over, and we see now - becomes 1F.
Let's open up our calculator.
So open our calculator here.
And then we change this calculator into the programmer calculator.
So now we select the hex here and select the keyboard here.
All right.
Keyboard.
So now we key in 21 because the previous value of - was 21 in hex.
And then we are going to minus two, minus two equals.
So we get 1F.
So that is what we expected.
It is correct, 1F.
All right.
So now we go to the next one.
We are going to add register to register.
So now we are going to do that.
We are going to add - to - and see what happens.
So we could add -, -. Click ADD.
Then we step over it, and we see.
Now - becomes 20 because we take one and add to 1F.
So it becomes 20.
We can also confirm that by doing this. If we add one plus 1F, we get 20 in hex.
Correct.
Next one is we are going to subtract register and register.
So we can do that here.
SUB.
We take maybe -, -.
So what this will do is it will minus - from -.
So - is one, - is one.
So when you minus one from -, - will become zero.
So let's step over that.
And we see now - is zero.
Now next, we are going to try this: memory and immediate.
So we select Dump 1.
We put a value in the memory first.
So we go to memory.
Select the BSS segment.
Double-click on it.
We choose a blank location here.
This one. Right-click to copy this address.
And then here, maybe we put binary edit first. Binary edit.
And then maybe here we put the value 20.
Okay, okay.
So now we got 20 there.
So we are going to add immediate to this 20.
So let's try that.
So that memory location is BYTE PTR. Paste the memory.
And then here we're going to add three. Click okay.
So three, so immediate.
So let's step over this and watch what happens to this value.
Step over.
And we see now it becomes 23.
So exactly as we expected.
Next, we are going to subtract immediate from memory.
So let's go to this location. SUB, BYTE PTR, paste memory.
And we're going to subtract one from there.
Click okay.
So we're going to minus one from this 23 here and see what happens.
Step over, and now becomes 22.
That's correct.
And then the last one is ADD and subtract register and memory.
So for that, we will use the register memory.
So let's just change this register.
Let's try to use a different register.
Now maybe we try -.
So we modify the value in -.
Maybe we put here 42. Let's say 42.
So let's do that.
Now we are doing this one.
So we are going to add first. ADD -.
So this one will be -, -, and then BYTE PTR.
And then here we put your memory.
So it's going to take 22 plus 42.
So let's step over, and we see it gets 64.
So it's correct.
Yeah, 22 plus 42 is indeed 64.
Now next one, last one, is to minus register from memory.
So let's try that now.
SUB, memory will be your BYTE PTR.
Paste your memory there and minus from register.
So your register should.
Maybe we put, maybe we take - or we take -.
Okay.
- is fine.
Okay.
So now it's going to minus - from here.
So - is 20, here is 22 memory.
So this one should become two because you're going to minus 20 from 22.
Step over that.
And you see now this becomes two.
This is how you do your ADD and SUB using all these combinations.
So that's all for this video.
Thank you for watching.