I know what the instructions do, just can't see a practical use, any examples where these instruction are useful?
note, just rol and ror and not the carry variants
One of the uses is to get the mouse coordinates from lParam in response to a WM_LBUTTONUP message.
mov eax, lParam ; The x parameter is in ax, the low word of eax.
; You need to either ror 16 or shr 16 to get the high word (y) into ax
mov mousex, ax
ror eax, 16 ; shr has the same affect for this purpose, and is more commonly used
mov mousey, ax
I'm on iPad right now, but that's the gist of one usage.
From MSDM re WM_LBUTTON and lParam
WM_LBUTTON
lParam
The low-order word specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.
The high-order word specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.
It is also (ror and rol as well as shr and shl) used in encryption/decryption algorithms, and compression algos as well.
Jack,
ROL and ROR allow you to move bit patterns around in either direction by an arbitrary amount. Now if you wanted to write 2 x byte values to al and ah, thats easy but to write to the last two bytes in a DWORD, you need to rotate that DWORD by 16 bits so you can write again to al - ah and in this manner you can set all 4 bytes in a DWORD.
Quote from: swordfish on September 05, 2022, 02:04:58 PM
One of the uses is to get the mouse coordinates from lParam in response to a WM_LBUTTONUP message.
You can do that, and I've done that, but you can also get both coordinates (packed into lparam) in fewer instructions:
MOVZX EAX, WORD PTR lParam
MOV MouseX, EAX
MOVZX EAX, WORD PTR lParam + 2
MOV MouseY, EAX
NoCforMe, he had asked about practical uses of ror and rol.
I gave him an example of one usage of ror (and shr as well)
So, I believe the answer that I gave was well within the bounds of his query.
I didn't post that to make a debate about a better method.
You're right. Very easy to veer off-topic here.
I've never, ever used RCR or RCL. Anyone here ever used them?
Hi guys, the usual trick with Intel mnemonics is pick what you need out of an Intel manual and use it if it does the job. Keep an eye on how and where you use shifts and rotates as they tend to be slow instructions on many CPUs.
My statistics: 4 x rol, 5 x ror in 44,000 lines of code. One lonely rol in another 22k source. So yes, it's a rarely used instruction, but handy for checking a DWORD for bits set, using the Carry? flag.
Or swap between little and big endian.
Used those instructions a lot when porting some of my old amiga code to pc code.
Ah yes, the good old 68000. Always wanted to program for that, never did. (I had an Amiga, too; great computer for its time.)
Old few bits/ pixel bitmap data convert to new 24 bit bitmap
Most older computers had fewer colors displays far from true color screens
Old few bits / vector format to draw vector data
Apple II had such format 3 vectors /byte
I have posted some vector draw code somewhere in 16bit dos forum
thanks guys :smiley:
Hi,
Quote from: NoCforMe on September 05, 2022, 04:02:00 PM
I've never, ever used RCR or RCL. Anyone here ever used them?
Well yes. Rather old code though. 16-bit code multiplying and dividing larger
data types. Monochrome (mode 06) graphics, line drawing and state machines.
Data reformatting, such as base64 encoding and decoding. Flag testing for the
FPU (and probably other cases). Random number seed generator. Moving pixels
around in some graphics programs. So mostly moving bit patterns across byte
boundaries.
Cheers,
Steve N.
Some usage with ip-numbers.
In the dos days I used them to scroll sprites across the screen.
Reversing the bits in a qword or dword.
I found the example on the old masm32 archives.
Start by using byteswap...
Simple example. (its in PowerBASIC)
! mov ax, 6 ' right side
! rol eax, 16
! mov ax, 10 ' left side
! mov var, eax
SendMessage hEdit,%EM_SETMARGINS,%EC_LEFTMARGIN or %EC_RIGHTMARGIN,var
Quote from: jack on September 05, 2022, 01:00:11 PM
I know what the instructions do, just can't see a practical use, any examples where these instruction are useful?
note, just rol and ror and not the carry variants
Hi Jack,
Solomon W. Golomb - Shift Register Sequences. Secure and Limited-Access Code Generators, Efficiency Code Generators, Prescribed Property Generators, Mathematical Models 3rd ed.-World Scientific (2017)
Computing the Parity of a Word
Counting Leading 0's
Generalized Bit Reversal
Counting 1-Bits
Reversing bits