Скачиваний:
36
Добавлен:
15.09.2014
Размер:
2.1 Кб
Скачать
// mmxregistr.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


#include <windows.h>
#include <conio.h>
#include <iostream>
using namespace std;

#define N 32

long* AND(char str1[], char str2[]);
void _declspec() registers(char *MMX);

int main()
{
setlocale(LC_ALL, "Russian");
char str1[N], str2[N], MMX[N];
long *arr;
int t, i;

while(1)
{
	system("cls");
	cout << "                   Реализация операции 'И'!" << endl;
	cout << "Меню:" << endl;
	cout << "1. Ввести строки" << endl;
	cout << "2. Показать содержимое регистров" << endl;
	cout << "3. Выполнить операцию 'И'" << endl;
	cout << "0. Выход из программы" << endl << endl;
	cout << "Выберите действие!!!" << endl;
	t=_getch();
	switch(t)
	{
		case '1': system("cls");
			cout << "Введите строку №1!" << endl;
			cin >> str1;
			cout << "Введите строку №2!" << endl;
			cin >> str2;
			break;

		case '2': system("cls");
			cout <<  "Содержание регистров:" << endl;
			registers(MMX);
			for (i = 0; i < N; i++)
				printf("%d  ", MMX[i]);
			_getch();
			break;

		case '3': system("cls");
			cout << "Результат:" << endl;
			arr = AND(str1, str2);
			cout << "Результат:" << endl;
			for (i=0; i<32; i++)
			{
				printf("%3d(%c) ",arr[i],arr[i]);
				if (i % 16 == 7 || i % 16 == 15 || i % 16 == 23) printf("\n");
			}
			_getch();
			break;

		case '0': system("cls");
			cout << "Спасибо за работу!" << endl;
			_getch();
			return 0;

		default: break;
	}
}
return 0;
}

long* AND(char str1[], char str2[])
{
	long d = 0;
	int a, b;
	int c = 0xff, i;

	long* test = new long[32];
    for (i=0; i<32; i++)
    {
        a = str1[i];
		b = str2[i];
        _asm{
			movd mm0,a
			movd mm1,b
			pand mm0,mm1
			movq d,mm0
        }
		test[i] = d;
	};
	return test;
}

void _declspec(naked) registers(char *MMX)
{
	_asm{
		push ebp
		mov ebp, esp
		mov esi, [ ebp + 8 ]
		
		movq	[esi] + 0, mm0 
		movq	[esi] + 8, mm1 
		movq	[esi] + 16, mm2
		movq	[esi] + 24, mm3
	
		pop ebp
	ret
	}	
}