How would you go about doing a bit shift in NASM on a register? I read the manual and it only seems to mention these operators >>, <<. When I try to use them NASM complains about the shift operator working on scalar values. Can you explain what a scalar value is and give an example of how to use >> and <<. Also, I thought there were a shr or shl operators. If they do exist can you give an example of how to use them? Thank you for your time.
Share
<<and>>are for use with integer constants only. This is what it means by “scalar value”. You can shift the value in a register using theshlorshrinstructions. They are used to shift the value in a register left or right, respectively, a given number of bits.The first line in this example shifts the value in
axleft 4 bits, which is the same as multiplying it by 16. The second line shifts the value inbxright by 2 bits, which is the same as integer division by 4.You can also use
clto indicate the number of bits to shift, instead of a constant. For more information on these and related instructions, see this page.