#!/usr/bin/perl -w
use IO::Socket::INET;

if($ARGV[0] eq "0")
{
  foreach(0 .. 2**16-1)
  {
    my $hex=sprintf("0x%04X",$_);
    my $res=`rasm2 -d -a arm -b 16 $hex`;
    print "thumb $hex $res";
  }
}

if($ARGV[0] eq "1")
{
  my $openocd=IO::Socket::INET->new(PeerAddr=>"localhost:4444");
  my $head=<$openocd>;
  foreach(0 .. 2**16-1)
  {
    my $hex=sprintf("0x%04X",$_);
    #print "mex1 mwh 0x40000000 $hex\n";
    $openocd->write("mex1 mwh 0x40000000 $hex\n");
    my $line=<$openocd>;
    $openocd->write("arm disassemble 0x40000000 1 thumb\n");
    $line=<$openocd>;
    $line=<$openocd>;
    $line=~s/0x40000000 //g;
    #$line=split("\r\n",$line)[0];
    print "thumb $line";
  }
}

