⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mult_sw.c

📁 用impulse c编写的18x18位的乘法器。
💻 C
字号:
//////////////////////////////////////////////////////////////////
// Multiplier example. Demonstrates how to write a multiply that
// will result in an 18X18 multiplier macro being properly
// instantiated. Generates a 36-bit result.
// 
// Copyright(c) 2003-2005 Impulse Accelerated Technologies, Inc.
// 
// mult_sw.c: includes the software test bench processes and
// main() function.
//
#ifdef WIN32
#include <windows.h>
#include <sys/types.h>
#include <sys/stat.h>
#else  // ! WIN32
#include <sys/stat.h>
#include <unistd.h>
#endif
#include <stdio.h>
#include "co.h"
#include "co_math.h"
#include "cosim_log.h"
#include "mult.h"

extern co_architecture co_initialize(void *);

void test_producer(co_stream Operand, co_stream Result)
{
	int c;
	cosim_logwindow log = cosim_logwindow_create("test_producer");

	// Operands from a file
	const char * FileName = INPUT_FILE;   // See mult.h
	FILE * inFile;
	co_int18 nValue;
	co_int36 nResult;

	inFile = fopen(FileName, "r");
	if ( inFile == NULL ) {
		fprintf(stderr, "Error opening operands file %s\n", FileName);
		c = getc(stdin);
		exit(-1);
	}

	// Now read the data...
	co_stream_open(Operand, O_WRONLY, INT_TYPE(18));
	co_stream_open(Result, O_RDONLY, INT_TYPE(36));
	cosim_logwindow_write(log, "Sending Operands...\n");
	while (1) {
		if (fscanf(inFile,"%d",&nValue) < 1)
			break;
		co_stream_write(Operand, &nValue, sizeof(co_int18));
		cosim_logwindow_fwrite(log, "Value A: %d\n", nValue);
		printf("Value A: %d\n", nValue);

		if (fscanf(inFile,"%d",&nValue) < 1)
			break;
		co_stream_write(Operand, &nValue, sizeof(co_int18));
		cosim_logwindow_fwrite(log, "Value B: %d\n", nValue);
		printf("Value B: %d\n", nValue);

		if (co_stream_read_nb(Result, &nResult, sizeof(co_int36))) {
			cosim_logwindow_fwrite(log, "Result : %ld\n", nResult);
			printf("Result : %d\n", nResult);
		}
	}
	while (co_stream_read(Result, &nResult, sizeof(co_int36)) == co_err_none) {
		cosim_logwindow_fwrite(log, "Result : %ld\n", nResult);
		printf("Result : %d\n", nResult);
	}
	co_stream_close(Operand);
	co_stream_close(Result);
	fclose(inFile);
}

int main(int argc, char *argv[])
{
	co_architecture my_arch;
	void *param = NULL;
	int c;

	printf("Impulse C is Copyright 2003-2005 Impulse Accelerated Technologies, Inc.\n");
  
	my_arch = co_initialize(param);
	co_execute(my_arch);

	printf("\n\nApplication complete. Press the Enter key to continue.\n");
	c = getc(stdin);

	return(0);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -