#!/usr/bin/perl
if(open(file,">$ARGV[0]") == 0)
{ print "UNABLE TO OPEN THE FILE ...\n"; exit;}
$count = 15;
$y = 0;
print file"sto 0 0\n";
print file"sto 1 0\n";
print file"sto 2 0\n";
print file"sto 3 0\n";
print file"sto 4 0\n";
print file"sto 5 0\n";
print file"sto 6 0\n";
print file"sto 7 0\n";
print file"sto 8 0\n";
print file"sto 9 0\n";
print file"sto a 0\n";
print file"sto b 0\n";
print file"sto c 0\n";
print file"sto d 0\n";
print file"sto e 0\n";
print file"sto f 0\n";
print file"nop 0 0\n";
print file"nop 1 1\n";
$o_1 = 0;
$o_2 = 0;
while(1)
{

$i = rand(1000);
$i1 = rand(1000);
$i2 = rand(1000);

$oper2 = $i2 % 16;
$o1 = &tohex($oper2);

$oper1 = $i1 % 16;
$o2 = &tohex($oper1);

$code = $i % 15;

if($code == 0)
{ $code1 = "sto"; }
elsif($code == 1)
{ $code1 = "add"; }
elsif($code == 2)
{ $code1 = "sub"; }
elsif($code == 3)
{ $code1 = "nop"; }
elsif($code == 4)
{ $code1 = "or"; }
elsif($code == 5)
{ $code1 = "xor"; }
elsif($code == 6)
{ $code1 = "and"; }
elsif($code == 7)
{ $code1 = "not"; }
elsif($code == 8)
{ $code1 = "nand"; }
elsif($code == 9)
{ $code1 = "xnor"; }
elsif($code == 10)
{ $code1 = "nor"; }
elsif($code == 11)
{ $code1 = "neg"; }
elsif($code == 12)
{ $code1 = "dec"; }
elsif($code == 13)
{ $code1 = "inc"; }
elsif($code == 14)
{ 
last;
}
print (file"$code1 $o1 $o2\n"); 
}

print file"nop a 4\n";
print file"nop c e\n";
print(file"dump\n");
print file"hlt\n";
close(file);

sub tohex {
($dec) = @_;
if($dec == 0)
{ $hex = "0"; }
elsif($dec == 1)
{ $hex ="1"; }
elsif($dec == 2)
{ $hex ="2"; }
elsif($dec == 3)
{ $hex ="3"; }
elsif($dec == 4)
{ $hex ="4"; }
elsif($dec == 5)
{ $hex ="5"; }
elsif($dec == 6)
{ $hex ="6"; }
elsif($dec == 7)
{ $hex ="7"; }
elsif($dec == 8)
{ $hex ="8"; }
elsif($dec == 9)
{ $hex ="9"; }
elsif($dec == 10)
{ $hex ="a"; }
elsif($dec == 11)
{ $hex ="b"; }
elsif($dec == 12)
{ $hex ="c"; }
elsif($dec == 13)
{ $hex ="d"; }
elsif($dec == 14)
{ $hex ="e"; }
elsif($dec == 15)
{ $hex ="f"; }

return $hex;
} 
