-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvs-asm
executable file
·75 lines (66 loc) · 1.97 KB
/
vs-asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#! /usr/um/bin/perl
# $path = "."; # if you grab local copies of the 2 binaries
$path = "/usr/caen/generic/mentor_lib-D.1/public/eecs470/bin";
unless (-e "$path/gas-alpha") {
print "Missing '/gas-alpha' file, used by this script!\n";
exit 1;
}
unless (-e "$path/objdump-alpha") {
print "Missing './objdump-alpha' file, used by this script!\n";
exit 1;
}
$file = shift;
$tmpfile = "a.out.$$";
system("$path/gas-alpha -o $tmpfile $file"); # could try the -R option to combine text & data segments
unless (-e $tmpfile) {
exit 1;
}
open TEXTSEG, "$path/objdump-alpha -s $tmpfile -j .text |";
open DATASEG, "$path/objdump-alpha -s $tmpfile -j .data |";
$hdigit = '[\da-fA-F]';
# skip up to actual text segment output
while (<TEXTSEG>) {
chop;
last if ($_ eq 'Contents of section .text:');
}
for ($count = 0; <TEXTSEG>; $count++) {
($data) = /^ $hdigit{4,} (($hdigit{8} ){1,4})/;
@words = split(' ', $data);
while ($#words < 3) {
push @words, '00000000';
}
print byterev($words[1]), byterev($words[0]), "\n";
print byterev($words[3]), byterev($words[2]), "\n";
}
# skip up to actual data segment output
while (<DATASEG>) {
chop;
if ($_ eq 'Contents of section .data:') {
if ($count >= 256) {
print "More than 1024 instructions in the .text segment, runs into .data segment!";
}
for (; $count < 256; $count++) {
print '00000000', '00000000', "\n";
print '00000000', '00000000', "\n";
}
last;
}
}
while (<DATASEG>) {
($data) = /^ $hdigit{4,} (($hdigit{8} ){1,4})/;
@words = split(' ', $data);
while ($#words < 3) {
push @words, '00000000';
}
print byterev($words[1]), byterev($words[0]), "\n";
print byterev($words[3]), byterev($words[2]), "\n";
}
sub byterev
{
my $w = shift;
my @chars = split(//, $w);
return join('', @chars[6..7], @chars[4..5], @chars[2..3], @chars[0..1]);
}
close TEXTSEG;
close DATASEG;
unlink $tmpfile;