Скачиваний:
34
Добавлен:
15.09.2014
Размер:
1.91 Кб
Скачать
// labMMX.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

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

int main()
{
setlocale(LC_ALL, "Russian");
char str1[N], str2[N], MMX[N];
char *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;
	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);
			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");
			return 0;

		default: break;
	}
}
return 0;
}

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

	char* test = new char[32];

    for (i=0; i<32; i++)
    {
        a = str1[i];
		b = str2[i];
        _asm{
			movd mm0,a
			pand mm0,b
			movd 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
       }	
}