#!/usr/local/bin/perl
# Brian Hay
# ECE 474 Oregon State University
# 1/25/2007

$filename = "./vectors/golden_vectors";
$filename_results = "./vectors/golden_result_vectors";
open(FOUT,">$filename"); #golden_vectors
open(FOUTR, ">$filename_results"); #golden_result_vectors
$count = 100;  #how many tests to run
print "Perl Script running\n";

#While loop that creates vectors and outputs them to the files
while($count>0){
	$count = $count - 1;

	$val_a = int(rand(65536));
	$val_b = int(rand(65536));

	print FOUT dec2bin($val_a,16);
	print FOUT "	";
	print FOUT dec2bin($val_b,16);	
	print FOUT  "	";
	print FOUT dec2bin(($val_a*$val_b),32);
	print FOUT "\n";

	print FOUTR dec2bin(($val_a*$val_b),32);
	print FOUTR "\n";
}

close(FOUT);
close(FOUTR);


# dec2bin
#
# Converts integer number into binary, by using integer division and remainders
#


sub dec2bin{


	$val = $_[0];
	$size = $_[1];


	$temp = $val%2;
	$val = int($val/2);
	$bits_assigned = 1;

	while($val>0){
		$bits_assigned = $bits_assigned + 1;
		$temp = ($val%2).$temp;
		$val = int($val/2);
	}

	while($bits_assigned < $size){ # Pads binary number with zeros upto $size parameter (passed to func)
		$temp = '0'.$temp;
		$bits_assigned = $bits_assigned + 1;
	}

	return $temp;

}





