This program takes two input integers and produces x^y and prints in the main; the actual computation is inline x86 asm (at&t). Can any of you say why garbage is getting loaded in the registers and junk printed? Any help is appreciated. i used gcc -m32 compile options
#include <stdio.h>#include <string.h>#include <stdlib.h>short power(short x, short y){ short z; __asm__ __volatile__("pusha \n""mov %[x], %%eax \n" //x argument"mov %[y], %%ebx \n" //y argument"mov %%eax, %%ecx\n""mul_loop:\n""imul %%ecx, %%eax \n" //loop multiply x by x until y goes to 0"dec %%ebx\n""jnz mul_loop\n""mov %%eax, %[z] \n""popa \n" :[z] "=m" (z) :[x] "m" (x), [y] "m" (y) : "eax", "ebx", "ecx" ); return z;}int main (void){ short x, y, res =0; char line[32]; printf("enter numbers \n"); fgets (line, sizeof(line), stdin); x = (short) atoi (strtok(line, "")); y = (short) atoi (strtok(NULL, "")); res = power(x, y); printf ("%d\n", res); return 0;}