You are on page 1of 4

/*

void vectorparimpar_rez(int *, int)


{
_asm
{
mov eax, [ebp + 12];
mov ebx, [ebp + 8];
mov ecx, 0;

mov edx, 0;
mov edi, 0;
mov esi, 0;

_loop:
cmp ecx, eax;
je _final;

mov edx, 0;
push eax;
push ecx;
mov eax, [ebx + ecx * 4];
mov ecx, 2;
div ecx;
pop ecx;
pop eax;

cmp edx, 0;
je _sumpar;
jne _sumimpar;

_sumpar:
add edi, [ebx + ecx * 4];
inc ecx;

jmp _loop;

_sumimpar:
add esi, [ebx + ecx * 4];
inc ecx;

jmp _loop;

_final:
mov eax, esi;
}
}

void vectorparimpar()
{
int v[] = { 15, 22, 28, 33, 11 };
int dimensiune = 5;

_asm
{
mov eax, dimensiune;
push eax;
lea eax, v;
push eax;
call vectorparimpar_rez;
mov dimensiune, eax;
add esp, 8;
}
cout << dimensiune<<'\n';
}
*/

/*
void numarvocale_implementare(char *,char *)
{
_asm
{
mov ebx, [ebp + 8];
mov edi, [ebp + 16];
push 0; //count
push 0; //j
push 0; //i

_loop1:
mov ecx, [esp];
inc [esp];
mov[esp + 4], 0;
movzx eax, byte ptr[ebx+ecx];
cmp eax, NULL;
je _final;
jne _loop2;

_loop2:
mov ecx, [esp+4];
movzx esi, byte ptr[edi + ecx];

inc[esp + 4];
cmp eax, esi;
je _add;

cmp esi, NULL;


je _loop1;
jne _loop2;

_add:
inc [esp+8];
jmp _loop2;

_final:
mov eax, [esp + 8];
add esp, 12;
}
}

void numarvocale()
{
char sir[] = "Numarul de vocale";
char vocale[] = "aeiouAEIOU";
int l=16;

_asm {
lea eax, vocale;
push eax;
lea eax, sir;
push eax;
call numarvocale_implementare;
add esp, 8;
mov l, eax;
}

cout << l << '\n';


}
*/

/*
void sumamatrice_implementare(int *, int *, int)
{
_asm {
mov ebx, [ebp + 8]; //iau prima matrice
mov ecx, [ebp + 12]; //iau a doua matrice
mov esi, [ebp + 16]; //iau nr lin si col
push 4; //sizeof(int)
push 0; //initializez contor 2 cu 0 j
push 0; //initializez contor 1 cu 0 i
//atentie, stiva!

_for1:
cmp[esp], esi; //comparam i cu nrmax
jge _outside_for_1; //stop
mov[esp + 4], 0; //fac j-ul 0
_for2:
cmp[esp + 4], esi; //comparam j cu nrmax
jge _outside_for_2;

//elementul A[i][j] se va afla la A + i * numarul de coloane *


sizeof(int) + j * sizeof(int)
mov eax, [esp];
mul[esp + 8];
mul esi;
mov edi, eax; //salvez in eax i * numarul de coloane * sizeof(int)
mov eax, [esp + 4];
mul[esp + 8];
add edi, eax; //obtin in edi: i * numarul de coloane * sizeof(int) + j
* sizeof(int);

mov eax, [ebx + edi]; // punem inapoi in eax, elementul curent


add eax, [ecx + edi]; // A[i][j] += B[i][j]
mov[ebx + edi], eax;

inc[esp + 4]; //incrementez j-ul


jmp _for2;

_outside_for_2:
inc[esp]; //incrementez i
jmp _for1;
_outside_for_1:
add esp, 12; //am avut 3 variabile locale
}
}

void sumamatrice()
{
int n = 3;
int A[3][3] = { { 1,0,1 },{ 0,1,0 },{ 1,0,1 } };
int B[3][3] = { { 2,1,2 },{ 1,2,1 },{ 2,1,2 } };

_asm
{
mov eax, n;
push eax;
lea eax, B;
push eax;
lea eax, A;
push eax;
call sumamatrice_implementare;
add esp, 12;
}

cout << "Matricea finala A: \n";


for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
cout << A[i][j] << " ";
cout << "\n";
}
cout << "\n";
}
*/

You might also like