Hello and welcome back.
In this lesson, we are going to study the MUL instructions.
MUL stands for multiply.
The syntax of the instruction is MUL register.
Register would be any registers - - - - - - - - and whatever, and then the result
will be stored spread across two registers - and -.
So to get the result, you will concatenate the two registers together.
So sometimes the result will only occupy one register.
For example, if both the operands are small numbers, and if the operands are large numbers and the result
is too large for -, then it will also occupy -.
And to know whether or not it occupies -, you will look at the - itself.
Register after the operation.
If - is all zero, then it means that the result can fit into -.
So that's why - is zero.
If the - is nonzero, then it means that the result is too large to fit into -, and so you will
need to concatenate the result and - together with the result in - to get the full final result.
- means that the - and the - registers are concatenated together to produce the final
result.
Note that the size of the result is twice the size of the argument.
So now let us take a look at the practical example by opening our x64dbg and running some code in there.
First, we will try the operands small numbers, and then we will see what happens.
And then later on, we will try with larger operands to see what happens.
The differences.
So let's move a value into -.
So take note that in order for this instruction to work, you must first put one of the operands in
- register and then the second operand in a separate register.
Then when you call the MUL, it will take the operand in the - register and multiply it with the
second register to produce the final result, which should be inside the - and, if necessary,
- as well.
So let's take a look at how this works.
So for the first example, we are going to take two small numbers.
Maybe we multiply two times three.
So we'll move.
We'll move two into - and then we'll move three into -.
And then we will multiply the two.
So to multiply, we call MUL, followed by -.
So it is implicit that the first operand is -.
So you do not have to specify MUL -, you just specify MUL -.
So now let's run to our breakpoint and step over.
So it moves two to -.
Step over and it moves three to -.
Now it's going to multiply - with the value in -.
So we expect to get six.
Notice the - and - after the operation.
Step over.
And now you notice - is all zeros, meaning that the result is small enough to fit into -.
So that's why - is all zero.
And you notice now - has got the value six, just as we expected.
So in this example, we only need to look at - to get the result.
Now let's try to use bigger operands and see what happens.
This time will you move a very big number into -.
So we'll move 1122334455667788 into -.
And then we are going to move, uh, also a big number 11223344 5566.
And then now we will multiply the two and see what happens.
Okay.
So now we are going to move this into -.
So - has got this huge number.
And then now we're going to move this into -.
And - has got this number.
And now we are going to multiply this with -.
And notice what happens in -.
And you see - now is non-zero.
That means the result of the multiplication is too large to fit into -.
That is why it also uses -.
So to get the final result, you have to concatenate this with -.
So what the final result reads should be.
The final result should read 1258F6060B6060117820.
That is the final result.
So this is how we can use assembly code to do multiplication in the x64dbg.
And.
And you will also notice that the side effect of - and - flags are set to one whenever - is being used.
If the result is small enough to fit in -, the - and - will remain as zero, it will not
be set.
So that's all for this, uh, lesson.
Thank you for watching.