#include <stdio.h>

int mypow(int x,int n)
{
	int t;
	_asm
	{
		mov eax,1;
		mov ecx,n;
     lp:
		imul eax,x;
		sub ecx,1;
		cmp ecx,0;
		jle ex;
		jmp lp;
     ex:
		mov t,eax;
	}
	return t;
}

void split(int s,int* a1,int* a2,int* a3,int* a4,int* a5)
{
	_asm
	{
		mov eax,dword ptr [s];
		cdq;
		mov ecx,10;
		idiv ecx;
		mov dword ptr [s],eax;
		mov eax,dword ptr a5;
		mov dword ptr [eax],edx;
		//
		mov eax,dword ptr [s];
		cdq;
		mov ecx,10;
		idiv ecx;
	    mov dword ptr [s],eax;
		mov eax,dword ptr a4;
		mov dword ptr [eax],edx;
		//
		mov eax,dword ptr [s];
		cdq;
		mov ecx,10;
		idiv ecx;
	    mov dword ptr [s],eax;
		mov eax,dword ptr a3;
		mov dword ptr [eax],edx;
		//
		mov eax,dword ptr [s];
		cdq;
		mov ecx,10;
		idiv ecx;
	    mov dword ptr [s],eax;
		mov eax,dword ptr a2;
		mov dword ptr [eax],edx;
		//
		mov eax,dword ptr [s];
		cdq;
		mov ecx,10;
		idiv ecx;
	    mov dword ptr [s],eax;
		mov eax,dword ptr a1;
		mov dword ptr [eax],edx;
	}
}

int main()
{
	int s,a1,a2,a3,a4,a5;
	int t;
	char* fmt="%5d\n";
	_asm
	{
		mov eax,10000;
beg:
		mov dword ptr [t],eax;   // t 用来保存循环变量
		cmp eax,99999;
		jg end;  //大于则跳转至循环结束
		//以上循环头
		mov s,eax;
		lea ecx,dword ptr [a5];
		push ecx;
		lea ecx,dword ptr [a4];
		push ecx;
		lea ecx,dword ptr [a3];
		push ecx;
		lea ecx,dword ptr [a2];
		push ecx;
		lea ecx,dword ptr [a1];
		push ecx;
		mov ecx,dword ptr [s];
		push ecx;
		call split;    //对五位数进行分割
		add esp,24;
		//
		xor esi,esi;
		push 5;
		mov ecx,dword ptr [a5];
		push ecx;
		call mypow;
		add esi,eax;    //调用幂函数并对结果进行累加
		add esp,8;     

		push 5;
		mov ecx,dword ptr [a4];
		push ecx;
		call mypow;
		add esi,eax;    //调用幂函数并对结果进行累加
		add esp,8;

		push 5;
		mov ecx,dword ptr [a3];
		push ecx;
		call mypow;
		add esi,eax;    //调用幂函数并对结果进行累加
		add esp,8;

		push 5;
		mov ecx,dword ptr [a2];
		push ecx;
		call mypow;     //调用幂函数并对结果进行累加
		add esi,eax;
		add esp,8;

		push 5;
		mov ecx,dword ptr [a1];
		push ecx;
		call mypow;
		add esi,eax;     //调用幂函数并对结果进行累加
		add esp,8;
	
		cmp esi,dword ptr [t];
		jnz exit0;  //不相等则跳至下一次循环

		//如果相等则打印输出
		mov ecx,dword ptr [t];
		push ecx;
		mov ecx,dword ptr fmt;
		push ecx;
		call dword ptr printf;
		add esp,8;
		
exit0:
		mov eax,dword ptr [t];  //进行下一次循环
		add eax,1;
		jmp beg;

end:
	}
	return 0;
}