I am new to assembly in C and I don't know how to fix this error. I am creating a function that means writing a file. I have:
ssize_t mywrite(int fd, const void *buf, size_t count) { // return write(fd, buf, count); ssize_t var; __asm__("movl $4,%%eax\n\t" // Write "movl %1,%%ebx\n\t" "movl %2,%%ecx\n\t" "movl %3,%%edx\n\t" "int $0x80\n\t" // System call "movl %%eax,%0" :"=r"(var) :"r"(fd),"r"(buf),"r"(count) :"%eax","%ebx","%ecx","%edx" ); return var; }
My asm should do the same thing as writing (fd, buf, count); When I compile it, I get that the "asm" operand has impossible restrictions. "However, if you do not name the variables and get the values ββdirectly from the stack, I get no errors. Here is the code
__asm__("movl $4,%%eax\n\t" "movl 8(%%ebp),%%ebx\n\t" "movl 12(%%ebp),%%ecx\n\t" "movl 16(%%ebp),%%edx\n\t" "int $0x80\n\t" "movl %%eax,%0" :"=r"(var) : :"%eax","%ebx","%ecx","%edx" );
I could use the second code, ofc, but I need to compile it with optimization 2. Then% ebp will not indicate where I need it. I tried using "a", "b", "c" and "d" instead of "r", but did not succeed. Can anybody help? Thanks: D