CS301 Fall 2003

Prof. Hartman

Homework #7

Due Wednesday, November 12th by 5:00 pm

 

The program below contains a commented out C function. Write an assembly routing that uses MMX instructions to quickly perform its equivalent. (The point of the function is to add the elements from arrays a and b together into array c. This kind of thing would be useful if the arrays are holding pixel data for two images that you want to combine. Unsigned char is used as the data type to represent unsigned bytes. You can test your program by making sure you get the same results with your assembly language function that you get if you uncomment the C function.) Turn in sample output and your listing file.

 

#include <stdio.h>

 

int asm_main( void );

 

void addemup(unsigned char a[], unsigned char b[], unsigned char c[], int n); //n will always be divisible by 8

 

/*

void addemup(unsigned char a[], unsigned char b[], unsigned char c[], int n) //n will always be divisible by 8

{

int ii;

for(ii=0;ii<n;++ii)

{

int sum;

sum = a[ii] + b[ii];

if(sum>255) sum=255;

c[ii]=sum;

}

}

*/

 

int main()

{

int ii;

unsigned char a[16]={0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1};

unsigned char b[16]={0,0,2,2,0,0,2,2,0,0,2,2,0,0,2,2};

unsigned char c[16]={0,0,0,0,4,4,4,4,0,0,0,0,4,4,4,4};

unsigned char d[16]={0,0,0,0,0,0,0,0,8,8,8,8,8,8,8,8};

unsigned char e[16]={250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250};

unsigned char temp1[16],temp2[16];

 

addemup(a,b,temp1,16);

addemup(c,temp1,temp2,16);

addemup(d,temp2,temp1,16);

for(ii=0;ii<16;ii++) printf("%d ",temp1[ii]);

printf("\n");

addemup(e,temp1,temp2,16);

for(ii=0;ii<16;ii++) printf("%d ",temp2[ii]);

printf("\n");

}