switch ($opcode)
{
'add' { print "\n The opcode reported was add with hex value 4"; }
'sub' { print "\n The opcode reported was sub with hex value 5"; }
}
####
syntax error at ./assembly2hex.pl line 21, near "'add' { "
syntax error at ./assembly2hex.pl line 22, near "'sub' { "
####
#!/usr/bin/perl
use warnings;
use diagnostics;
use strict;
use Switch;
print ("Provide a file name to be used for source assembly code: ");
my $assemblyFile = ;
print ("\n You provided a file : $assemblyFile ");
open ASMFILE, $assemblyFile or die $!;
while (my $instruction = )
{
print ("\n Current instruction is : $instruction ");
my ($opcode, $operands) = split (/\s+/, $instruction, 2);
print ("\n Instrction parts right now are $opcode \t $operands ");
switch ($opcode)
{
'add' { print "\n The opcode reported was add with hex value 4"; }
'sub' { print "\n The opcode reported was sub with hex value 5"; }
}
}