Calling assembly code in C

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

Palindrome in C

Solution to Project Euler problem 4

#include<stdio.h>
#include<string.h>
#include<math.h>

int isPalindrome(char* x);

int main()
{
	char prodStr[100];
	int max = 0;
	int i, j, prod;
	for (i = 100; i < 1000; i++)
	{
		for (j = 100; j < 1000; j++)
		{
			prod = i * j;
			sprintf_s(prodStr, 100, "%i", prod);
			if(isPalindrome(prodStr) == 1)
			{
				if(prod > max)
					max = prod;
			}
		}
	}
	printf("%i\n", max);
	return 0;
}

int isPalindrome(char* x)
{
	int i = 0;
	int j = strlen(x) - 1;

	while (i <= j)
	{
		if (x[i] != x[j])
			return 0;
		i++;
		j--;
	}

	return 1;
}