예제 #1
0
파일: main.c 프로젝트: DerrickChanCS/COEN20
int main(void)
	{
	static struct {int a[8], b[8], sum ; } testcase[] =
		{
		{{0,0,0,0,0,0,0,1},{0,0,0,0,0,0,0,1},0},
		{{1,1,1,1,1,1,1,1},{1,0,0,0,0,0,0,0},0},
		{{1,0,1,0,1,0,1,0},{1,0,1,0,1,0,1,0},-86},
		{{1,1,0,1,0,0,0,0},{0,1,1,0,1,1,1,1},1},
		{{1,0,1,0,1,0,1,0},{0,1,0,1,0,1,0,1},-1}
		} ;
	int k ;

	InitializeHardware(HEADER, PROJECT_NAME) ;

	for (;;)
		{
		for (k = 0; k < ENTRIES(testcase); k++)
			{
			int *a = testcase[k].a ;
			int *b = testcase[k].b ;
			int sum[8] ;
			uint32_t before, after, cycles ;

			printf(" Test Case %d: ", k+1) ;
			PrintBits(a) ;
			printf("+") ;
			PrintBits(b) ;
			printf("\n") ;

			printf("   Correct Sum: ") ;
			PrintByte(testcase[k].sum) ;
			printf("\n") ;

            before = GetClockCycleCount() ;
			AddBinary(a, b, sum) ;
            after  = GetClockCycleCount() ;
            cycles = after - before ;

			printf("      Your Sum: ") ;
			if (PrintBits(sum) != (uint8_t) testcase[k].sum) printf(" %s", ERROR_FLAG) ;
			printf("\n") ;
			printf("  Clock Cycles: %lu\n", cycles) ;

			printf("\n") ;

			WaitForPushButton() ;
			}

		printf("Press button to start over.\n") ;
		WaitForPushButton() ;
		ClearDisplay() ;
		}
	}
int main(void)
	{
	static struct
		{
		uint32_t	word ;
		int			lsb ;
		int			width ;
		uint32_t	value ;
		} testcase[] =
		{
		{0xFFFFFFFF,  5, 7,  0},
		{0x00000000, 22, 5, -1}
		} ;
	int k ;

	InitializeHardware(HEADER, PROJECT_NAME) ;

	for (;;)
		{
		for (k = 0; k < ENTRIES(testcase); k++)
			{
			uint32_t	word	= testcase[k].word ;
			int			lsb		= testcase[k].lsb ;
			int			width	= testcase[k].width ;
			uint32_t	value	= testcase[k].value ;
			uint32_t	result, answer	= BFI(word, lsb, width, value) ;
			uint32_t    before, after, cycles ;

            before = GetClockCycleCount() ;
			result = BitFieldInsert(word, lsb, width, value) ;
            after  = GetClockCycleCount() ;
            cycles = after - before ;

			printf("   Test Case %d: %08X,%d,%d,%d\n", k+1,
				(unsigned) word, lsb, width, (int) value) ;

			printf("Correct Result: %08X\n", (unsigned) answer) ;

			printf("   Your Result: %08X", (unsigned) result) ;
			if (result != answer) printf(" %s", ERROR_FLAG) ;
			printf("\n") ;

			printf("  Clock Cycles: %lu\n\n", cycles) ;

			WaitForPushButton() ;
			}

		printf("Press button to start over.\n") ;
		WaitForPushButton() ;
		ClearDisplay() ;
		}
	}
int main(void)
    {
	static uint32_t testcase[] =
		{
		0x12345678,	0x0000FFFF,	0x00FF00FF
		} ;

	InitializeHardware(HEADER, PROJECT_NAME) ;

	for (;;)
		{
		int k ;

		for (k = 0; k < ENTRIES(testcase); k++)
			{
			uint32_t word = testcase[k] ;
			uint32_t result, answer = REV(word) ;
			uint32_t before, after, cycles ;

            before = GetClockCycleCount() ;
			result = ReverseByteOrder(word) ;
            after  = GetClockCycleCount() ;
            cycles = after - before ;

			printf("   Test Case %d: %08X (hex)\n", k+1, (unsigned) word) ;

			printf("Correct Result: %08X\n", (unsigned) answer) ;

			printf("   Your Result: %08X", (unsigned) result) ;
			if (result != answer) printf(" %s", ERROR_FLAG) ;
			printf("\n") ;

			printf("  Clock Cycles: %lu\n\n", cycles) ;

			WaitForPushButton() ;
			}

		printf("Press button to start over.\n") ;
		WaitForPushButton() ;
		ClearDisplay() ;
		}
    }