c variable in asm

need another help, iam not able compile the following code.
is my usage of c variable in asm correct ?
thanks

#include <stdio.h>
main()
{
    int y1=2;
    __asm
    ("
      dec   y1
    ");

}

Hi Sukesh,

In basic asm statements, you can only use global C variables. Also, ‘dec’ only works with registers. Example:

#include <stdio.h>
int y1=2;
main()
{
    printf("Before %d\n", y1);
    __asm("mov   y1, %eax");
    __asm("dec   %eax");
    __asm("mov   %eax, y1");
    printf("After %d\n", y1);

}



%pgCC tmp.c
% a.out
Before 2
After 1

Note that we will support extened asm in our next major release (6.1) which will allow you do more advanced assembly coding, such as using local variables. For now, however we’re stuck with basic asm.

Thanks,
Mat