#include <stdio.h>

#include <stdlib.h>

#include <Windows.h>

typedef struct _primeNumber

{

int number; // 4byte

char* ptrString; // 4byte

char* ptrScanf; // 4byte

}primeNumber;


void __init__(primeNumber** param)

{

char* strValue  = "Integer input :   ";

char* strValue2 = "%d";

if ((*param) == NULL)

{

__asm PUSH 0;

__asm CALL dword ptr[exit];

}

else

{ // (*param) != NULL 

__asm LEA edi, param;

__asm MOV edi, dword ptr[edi];

__asm MOV dword ptr[edi + 0], 0;

__asm LEA esi, dword ptr[strValue]; // esi = address(strValue)

__asm MOV esi, [esi];

__asm MOV dword ptr[edi + 4], esi;


__asm LEA esi, dword ptr[strValue2]; // esi = address(strValue)

__asm MOV esi, [esi];

__asm MOV dword ptr[edi + 8], esi;

}

} // end of __init__ function 

void __integerWrite__(primeNumber** param)

{

__asm lea edi, param;

__asm mov edi, [edi];

__asm mov eax, dword ptr[edi + 4]; // eax = "Integer input :   "

__asm push eax;

__asm call dword ptr[printf];

__asm pop ebx;

/////////////////////////////////////////////////////

__asm lea edi, param;

__asm mov edi, [edi];

__asm lea eax, dword ptr[edi + 0];

__asm push eax; // ( ,&number);

/////////////////////////////////////////////////////

__asm push dword ptr[edi + 8]

__asm call dword ptr[scanf];

__asm pop ebx;

__asm pop ebx;

} // end of __integerWrite__ function 

void __primeResult__(primeNumber** param)

{

DWORD count = 0;

char* pYES = "%d is prime number \n";

char* pNO  = "%d is not prime number \n";

__asm

{

lea edi, param;

mov edi, [edi];

mov ecx, dword ptr[edi + 0];

L:

mov eax, dword ptr[edi + 0];

xor edx, edx; // edx = 0

div ecx;

cmp edx, 0;

je jumpEqual;

jne jumpNotEqual;

jumpEqual:

inc count;

jmp TheEnd;

jumpNotEqual:

jmp TheEnd;

TheEnd:

loop L;

cmp count, 2;

je sameJump;

jne sameNotJump;

sameJump:

push dword ptr[edi + 0];

push pYES;

call dword ptr[printf];

pop ebx;

pop ebx;

jmp theEnd1;

sameNotJump:

push dword ptr[edi + 0];

push pNO;

call dword ptr[printf];

pop ebx;

pop ebx;

jmp theEnd1;

theEnd1:

}

} // end of __primeResult__ function 

int main(void)

{

primeNumber pNum;

printf("address(pNum) => %p \n", &pNum);

printf("address(pNum->ptrString) => %p \n", &(pNum.ptrString));

printf("address(pNum->ptrScanf) => %p \n", &(pNum.ptrScanf));

__asm LEA edi, pNum;

__asm PUSH edi;

__asm CALL  dword ptr[__init__];

__asm POP ebx;


printf("pNum->number    => %d\n", pNum.number);

printf("pNum->ptrString => %s\n", pNum.ptrString);

printf("pNum->ptrScanf  => %s\n", pNum.ptrScanf);


__asm LEA edi, pNum;

__asm PUSH edi;

__asm CALL  dword ptr[__integerWrite__];

__asm POP ebx;


__asm LEA edi, pNum;

__asm PUSH edi;

__asm CALL  dword ptr[__primeResult__];

__asm POP ebx;

/*

char* t_string = "integer input :  ";

__asm lea edi, [pNum]; // edi = &pNum

__asm mov dword ptr[edi], 10;

__asm mov dword ptr[edi + 3], [t_string];

printf("%d \n", pNum.number);

*/

return 0;

}