power.asm
global power section .text power: ; initialize eax to 1 mov eax, 1 ; esp+8 is the exponent mov ebx, [esp+8] loop: ; esp+4 is the base imul eax, [esp+4] dec ebx cmp ebx, 0 jnz loop ret
math.c
#include <stdio.h>
int power(int a, int b);
int main()
{
int p = power(32,3);
printf("%i\n", p);
}
https://github.com/randcode-generator/assembly_and_c
To compile and run:
nasm -f elf power.asm && gcc math.c power.o -o math && ./math