Скачиваний:
8
Добавлен:
09.05.2014
Размер:
4.07 Кб
Скачать
#include <stdafx.h>
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <time.h>
#include <iostream> 
#include <stdlib.h>
#include <assert.h>

#define MAXLEN 80
//#using <mscorlib.dll> 
//using namespace System;

char OutFileMMX[] = "ResultMMX.bmp";
char OutFileC[] = "ResultC.bmp";
char OutFileA[] = "ResultA.bmp";
BITMAPFILEHEADER bitmapFileHeader;
BITMAPINFOHEADER bitmapInfoHeader;


////////////////////////////////////////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])
{
	//Имя входного файла передается в командной строке
	char fname[40];
	char header[54];
	FILE *f; //файл bmp
	FILE *f2; //файл bmp
	FILE *f3; //файл bmp
	FILE *f4; //файл bmp
	puts("Enter the name of the file:");
	scanf("%s",&fname);

	//Чтение заголовка BMP файла
	if((f = fopen(fname, "rb")) == NULL)
	{
		printf("File is not exist!");
		getch();
		return -1;
	}
	//Если заголовок не прочитался - выйти (ошибка!)
	fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER),1,f);
	fread(&bitmapInfoHeader, sizeof(BITMAPINFOHEADER),1,f);
	
	if (bitmapFileHeader.bfType != 0x4D42)
	{
		printf("File is not a bmp!");
		getch();
		fclose(f);
		return NULL;
	}

	unsigned long height = bitmapInfoHeader.biHeight;
	unsigned long def = bitmapInfoHeader.biWidth;
	unsigned long nb = height*def*3;

	char *bitmapImage;
	char *bitmapC;
	char *bitmapA;
	char *bitmapMMX;
	unsigned long imageIdx=0;
	unsigned long i=0;
	unsigned long j=0;
	unsigned long cW=def*3/4;

	bitmapImage = new char[bitmapInfoHeader.biSizeImage];
	bitmapC = new char[bitmapInfoHeader.biSizeImage];
	bitmapA = new char[bitmapInfoHeader.biSizeImage];
	bitmapMMX = new char[bitmapInfoHeader.biSizeImage];
	char temp; //Буфер для пересылки
	fseek(f, 0L, SEEK_SET);
	fread(header, 54, 1, f);
	fseek(f, bitmapFileHeader.bfOffBits, SEEK_SET);//устанавливаем позицию для чтения
	fread(bitmapImage, bitmapInfoHeader.biSizeImage,1,f);
	
	for(i = 0; i < nb; i=i+1)// Создаем копию bitmapImage
	{
		bitmapC[i] = bitmapImage[i];
	}
	
	for(i = 0; i < nb; i=i+1)// Создаем копию bitmapImage
	{
		bitmapA[i] = bitmapImage[i];
	}
	
	for(i = 0; i < nb; i=i+1)// Создаем копию bitmapImage
	{
		bitmapMMX[i] = bitmapImage[i];
	}
	
	fclose(f);

	// C++

	for(i = 0; i < height/2; i=i+1)
	{
		for(j = 0; j < cW*4; j=j+1)
		{
			temp=bitmapC[cW*i*4+j];
			bitmapC[cW*4*i+j]=bitmapC[cW*4*(height-i-1)+j];
			bitmapC[cW*4*(height-i-1)+j]=temp;
		}
	}
	

	f2 = fopen(OutFileC, "wb");
	if (!f2) { printf("Error%s", OutFileC); exit(1); }

	fwrite(header, 1, 54, f2);

	fwrite(bitmapC, 1, nb, f2);
	fclose(f2);
	

	// Assembler
	
	long hei = height/2;
	int tmp_str_sub = def*3;

	char *ptA;
	ptA = &bitmapA[0];
	
	char *ptA2;
	ptA2 = &bitmapA[nb];
	
	_asm
	{
		mov esi, ptA
		mov edi, ptA2

		mov ecx, hei

		first:
			
			mov edx, tmp_str_sub
			sub edi, tmp_str_sub

			second:
				
				mov eax, [esi+edx]
				mov ebx, [edi+edx]
				mov [edi+edx], eax
				mov [esi+edx], ebx
				sub edx, 4
				cmp edx, 0
			
			jne second
			

			add esi, tmp_str_sub

		loop first
	}
	
	f3 = fopen(OutFileA, "wb");
	if (!f3) { printf("Error%s", OutFileA); exit(1); }

	fwrite(header, 1, 54, f3);

	fwrite(bitmapA, 1, nb, f3);
	fclose(f3);


	// MMX

	char *ptMMX;
	ptMMX = &bitmapMMX[0];
	
	char *ptMMX2;
	ptMMX2 = &bitmapMMX[nb];

	_asm
	{
		mov esi, ptMMX
		mov edi, ptMMX2

		mov ecx, hei

		firstMMX:
			
			mov edx, tmp_str_sub
			sub edi, tmp_str_sub

			secondMMX:
				
				movq mm0, [esi+edx]
				movq mm1, [edi+edx]
				movq [edi+edx], mm0
				movq [esi+edx], mm1
				sub edx, 8
				cmp edx, 0
			
			jne secondMMX
			
			
			add esi, tmp_str_sub

		loop firstMMX

		emms
	}
	
	f4 = fopen(OutFileMMX, "wb");
	if (!f4) { printf("Error%s", OutFileMMX); exit(1); }

	
    fwrite(header, 1, 54, f4);

	fwrite(bitmapMMX, 1, nb, f4);
	fclose(f4);

	

	printf("The end!");
	getch();
	return 0;
	
}
Соседние файлы в папке asm lab # 4