Using bison to generate assembly code for a simple calculator, but I can't figure out exactly what my bug is here, all the answers seem to be one multiplication off...
global intpow
intpow:
push ebp
mov ebp,esp
mov ecx,[ebp+8]
mov eax,[ebp+12]
loop:
cmp eax,1
jle finish
dec eax
imul ecx,ecx
jmp loop
finish:
mov eax,ecx
mov esp,ebp
pop ebp
ret
Here's the code in my .y file when I identify an exponent call:
exp '^' exp { $$ = pow ($1, $3);
printf("call\tintpow\n");
printf("push\tDWORD eax\n");
}
Is the assembly wrong? The .y? Both?