I am outputing 32 numbers. I have a proc that gets two numbers at a time. I would like to be able to have another proc store those numbers in a BYTE variable called outBuffer. I was thinking about:
``````
mov eax, outBuffer
ROL eax, 4
mov eax, <next number>
mov outBuffer, eax
``````

I am not really familar with ROL. I only used it for outputing numbers in binary and the like. Nothing more than getting a 0 or 1 from it. Can it handle other numbers, two digit numbers? Is there another way to store the numbers in outBuffer?
Posted on 2004-11-07 01:00:58 by sjaguar13
sjaguar13,

I think you need to get the swing of what bit rotation is about. In the very crude sense it works like this,
``````
00000000000000001000000000000000 = binary number
00000000000000000100000000000000 = rotated by ONE bit
``````

Try this type of code to handle two numbers at once.
``````
xor eax, eax  ; zero the register
mov ax, 16
rol eax, 16
mov ax, 32
``````

The first MOV loads the low word with a 16 bit value.
Then it is shifted 16 bits so that the high word is now the low word.
Then it write another 16 bit value to the new low word.
Posted on 2004-11-07 01:46:12 by hutch--
Do I have to ROL 16? Can I just do it 8, so I can stick more than 2 numbers. I am beginning to think ROL is a bad idea.

``````
lea ebx, outBuffer
mov [ebx], <first double digit number>
inc ebx
mov [ebx], <second double digit number>
inc ebx
mov [ebx], <third double digit number>
inc ebx
.
.
.
mov [ebx], <16th double digit number>
``````

The only questions I have with that way is, can a double digit go into , or would I need to div ebx by 10 and store eax in and edx in ?

Second, I would only need to inc by 1 because outBuffer is a byte, right?
Posted on 2004-11-07 02:37:01 by sjaguar13
Does OutBuffer contain text (human-readable) or binary (internal machine) data?

If it's binary, then how many bits do you want to add each time?

I normally use shifts instead of rotates for binary.

AND ebx,01Fh ; ensure only the rightmost 5 bits are significant
SHL eax,5 ; move bits left, fill vacated space with zeroes
OR eax,ebx ; combine
Posted on 2004-11-07 21:28:57 by tenkey
``````
; ROL - rotate left (for a 32 bit value).
; input = original value
; shift = shift size (0..31 are valid)
;
; Note that numbers are treated as arrays of bits

result[31          .. shift] = input[(31 - shift) ..            0]
result[(shift - 1) ..     0] = input[31           .. (32 - shift)]

CarryFlag = input[shift]
``````

In essence, it is a shift operation, with the bits that "fall off" being put back on the other end.

``````