Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy the ror op in this inline assembly not working properly?
    primarykey
    data
    text
    <p>I have written a program to process some data written to disk in big-endian format, so the program needs to swap bytes in order to do anything else. After profiling the code I found that my byte swapping function was taking 30% of the execution time. So I thought to myself, how can I speed this up? So I decided to write a little piece inline assembly.</p> <p>I would up replacing this:</p> <pre><code>void swapTwoByte(char* array, int numChunks) { for(int i= (2*numChunks-1); i&gt;=0; i-=2) { char temp=array[i]; array[i]=array[i-1]; array[i-1]=temp; } } </code></pre> <p>with this:</p> <pre><code>void swapTwoByte(int16* array, int numChunks) { for(int i= (numChunks-1); i&gt;=0; --i) { asm("movw %1, %%ax;" "rorw %%ax;" "rorw %%ax;" "rorw %%ax;" "rorw %%ax;" "rorw %%ax;" "rorw %%ax;" "rorw %%ax;" "rorw %%ax;" "movw %%ax, %0;" : "=r" ( array[i] ) : "r" (array[i]) :"%ax" ); } } </code></pre> <p>Which does the intended job, but that is a lot of rotate operations.</p> <p>So here is my question: According to <a href="http://en.wikibooks.org/wiki/X86_Assembly/Shift_and_Rotate" rel="nofollow">this source</a> rorw can take two operands, and in the gas sytax the source operand should be the number of bits to rotate by, but every time I try to replace that list of 8 rotate rights with something like</p> <pre><code>".set rotate, 0x0008" "rorw rotate, %%ax" </code></pre> <p>I get an assembler error stating:</p> <pre><code>"Error: number of operands mismatch for `ror'" </code></pre> <p>Why is this? What am I missing?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload