Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use warnings;
- use strict;
- my $debug = 1;
- my $bytes = 32;
- my $url = 'http://www.edmundgriffiths.com/czero.html?hexdump=';
- my $codes = {
- 'nop' => 0,
- 'lda' => 32,
- 'sta' => 64,
- 'add' => 96,
- 'sub' => 128,
- 'brz' => 160,
- 'jmp' => 192,
- 'stp' => 224,
- };
- my $lines = ();
- my $variables = ();
- print "Parsing input...\n";
- while (<>) {
- chomp;
- next if /^\s*(#.*)?$/;
- if (/^\s*(\S+)\s+(\S+)\s*$/) {
- my ($code, $data) = (lc $1, lc $2);
- print "parsed code=$code, data=$data\n";
- push @$lines, {'code' => $code, 'data' => $data};
- unless (defined $codes->{$code}) {
- $variables->{$code} = {'address' => $. - 1, 'value' => $data};
- }
- }
- elsif (/^\s*(\d+)\s*$/) {
- my $data = $1;
- print "parsed data=$data\n";
- }
- }
- print "Generating URL...\n";
- foreach my $line (@$lines) {
- my $value = 0;
- if (defined $line->{code}) {
- if (defined $codes->{$line->{code}}) {
- print "processing code=$line->{code}, data=$line->{data}\n"
- if $debug;
- $value = $codes->{$line->{code}};
- if ($line->{data} =~ /^\d+$/) {
- $value += $line->{data};
- }
- elsif (defined $variables->{$line->{data}}) {
- $value += $variables->{$line->{data}}->{address};
- }
- else {
- die "Undefined variable: $line->{data}\n";
- }
- }
- elsif (defined $variables->{$line->{code}}) {
- $value = $variables->{$line->{code}}->{value};
- }
- else {
- die "Unknown operation: $line->{code}\n";
- }
- }
- else {
- $value = $line->{data};
- }
- print "value=$value\n" if $debug;
- $url .= sprintf "%02x", $value;
- }
- $url .= '00' x ($bytes - scalar @$lines);
- print $url, "\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement