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.
相关问题
- Index of single bit in long integer (in C) [duplic
- Null-terminated string, opening file for reading
- What's the difference between 0 and dword 0?
- Translate the following machine language code (0x2
- Where can the code be more efficient for checking
相关文章
- Is it possible to run 16 bit code in an operating
- How to generate assembly code with gcc that can be
- Select unique/deduplication in SSE/AVX
- Optimising this C (AVR) code
- Why does the latency of the sqrtsd instruction cha
- Difference in ABI between x86_64 Linux functions a
- x86 instruction encoding tables
- Rounded division by power of 2
<<
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 theshl
orshr
instructions. 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
ax
left 4 bits, which is the same as multiplying it by 16. The second line shifts the value inbx
right by 2 bits, which is the same as integer division by 4.You can also use
cl
to indicate the number of bits to shift, instead of a constant. For more information on these and related instructions, see this page.Piggy-backing on ughoavgfhw's answer... to use
<<
and>>
, use them directly on constants: