In MASM64, if I write the instruction push 0, it will push a 64-bit immediate on the stack (i.e. RSP = RSP - 8).
So if I just want to push a 16-bit immediate to set FLAGS, I have no idea but write the machine code, such as:
.code
FlagFunction PROC
dd 00006866h; push a 16-bit immediate 0
popf
ret
FlagFunction ENDP
END
The program works but I wonder if there is an actual instruction for this in MASM64.
According to the Intel manual here: https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.html
PUSH imm16 in 64-bit mode is allowed. When you push a 16-bit immediate value onto the stack using the
push imm16instruction in x86-64 assembly, it will not be zero-extended. Thepush imm16instruction adjusts RSP by 2 instead of 8 and only pushes the 16-bit value onto the stack. This is the algorithm the CPU uses: