Qbasicnews.com

Full Version: ROR instruction in AT&T Assembly (also relates to C)?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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?
Move it into a register.
Confusedhifty:
I...should have thought of that...
Thanks. Smile
¡¡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. Sad
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. Sad
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.
Better look at for the syntax of using inline assembler in GCC. It's very different from any compiler i previously used.

http://www-106.ibm.com/developerworks/li.../l-ia.html

or

http://www.delorie.com/djgpp/doc/brennan...djgpp.html

Or better google "inline gcc assembler".
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?
Pages: 1 2