I was using a disassembler when I came across MOVZ and was a bit confused, since I had only used MOV before.
The ARMv8 ISA manual explains of course all the details, and that MOV is an alias for the other three depending on the context, but maybe someone can provide some rationale here, and give concrete examples to speedup the learning process.
MOV
This instruction can take many forms, depending on the value needed to be moved. And it changes if the value is a register or if it is an immediate. If it is in a register, then it produces an
ORRinstruction (ORR <Xd>, XZR, <Wm>)*. If it is using theSP(Stack Pointer) it produces anADDinstruction (ADD <Xd|XSP>, <Xn|XSP>, #0)*. If moving an immediate, then it is one of the MOVZ, MOVK or MOVN instructions.MOVZ and MOVK
These two instructions are sometimes used one after the other. And they are used to move immediate values.
MOVZmoves an immediate value (16-bit value) to a register, and all the other bits outside the immediate value are set to Zero. The immediate can be shifted to the left0,16,32or48.MOVKmoves an immediate value but leaves the other bits of the register untouched (theKis for keep). For example, let's say you need to move this value0x7fb7fb1f88to registerx0. First, you will move the first 16 bits (bits 0 to 15) with aMOVZinstruction, so the rest bits of the register are set to zero. And then you will move the second 16 bits (bits 16 to 31) with aMOVKinstruction, so the value moved before (the first 16 bits) remains in the register, and you do the same with the other resting bits.MOVN
MOVNis usually used for moving bitmasks, here theNstands for negated. Let's say you want to move the bitmask0xffffffff0000ffffto x0. Then you will move0xffffshifted to the left 16, that will make the value0x00000000ffff0000. Negating this values becomes 0xffffffff0000ffff.Here is an example: