Dev-C++ support only the AT&T syntax for inline assembly.
Anyway, I need ROR a unsigned-char with. I tried this, but it didn't work. Spewed an error about too many memory operands.
Code:
int main()
{
unsigned char c;
__asm { ror c,2 };
return 0;
}
As far as I know, in 8086 assembly, there is not an opcode for things like "ror ax,2".
1.- Ror just rotates 1 place. ROR AX ROR AX is the way to go (at least if you inline assembler doesn't support ROR AX,2 kind of macros, TASM and MASM support it).
2.- You can't ror a memory address, as far as I know. You have to move the var to a register and rotate the register.
My ASM knowledge is very limited, so don't take this assertions by heart.
Hmm, I didn't realize that rotating by more than one bit wasn't built into the instruction set.
Now my question is really about AT&T inline assembly: how do I rotate a variable? I can't just do this:
Code:
unsigned char c;
__asm ("ror c");
Because I obviously need to tell the assembler that "c" is a variable. How?
hifty:
I...should have thought of that...
Thanks.
¡¡GRRR!! That's what I told you !!! :lol: :rotfl:
Meh...I have this annoying habit to scan things too quickly. I didn't read your post carefully enough.
Sorry. I'll try to kick the bad habit.
Code:
#include <stdio.h>
unsigned char c;
int main()
{
c=1;
__asm ("
mov %ax,_c
ror %ax
mov _c,%ax
");
printf ("%d",c);
return 0;
}
It prints out the value in the variable "c" as being 0. That shouldn't be true.
You are doing it in the wrong direction. AT&T and Intel syntax use the opposite order for source and destination operands. Intel `add eax, 4' is `addl $4, %eax'. The `source, dest' convention is maintained for compatibility with previous Unix assemblers.
Quote:You are doing it in the wrong direction. AT&T and Intel syntax use the opposite order for source and destination operands. Intel `add eax, 4' is `addl $4, %eax'. The `source, dest' convention is maintained for compatibility with previous Unix assemblers.
So I should just swap all the operands?