-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasm.pl
executable file
·59 lines (56 loc) · 1.6 KB
/
asm.pl
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
#!/usr/bin/perl
print "v2.0 raw\n";
while (<>){
printInstruction($_);
}
sub printInstruction(){
my ($inst) = @_;
$num = 0;
if ($inst =~m/^\s*or\s+\$r([01])(,)?\s+\$r([01])/i){
#$num = ((opcode | $1) << 4) | ($3 << 3) | funct;
$num = ($1 << 4) | ($3 << 3) | 0;
}
elsif ($inst =~m/^\s*xor\s+\$r([01])(,)?\s+\$r([01])/i){
$num = ($1 << 4) | ($3 << 3) | 1;
}
elsif ($inst =~m/^\s*and\s+\$r([01])(,)?\s+\$r([01])/i){
$num = ( $1 << 4) | ($3 << 3) | 2;
}
elsif ($inst =~m/^\s*add\s+\$r([01])(,)?\s+\$r([01])/i){
$num = ($1 << 4) | ($3 << 3) | 3;
}
elsif ($inst =~m/^\s*srl\s+\$r([01])(,)?\s+\$r([01])/i){
$num = ($1 << 4) | ($3 << 3) | 4;
}
elsif ($inst =~m/^\s*sra\s+\$r([01])(,)?\s+\$r([01])/i){
$num = ($1 << 4) | ($3 << 3) | 5;
}
elsif ($inst =~m/^\s*not\s+\$r([01])(,)?\s+\$r([01])/i){
$num = ($1 << 4) | ($3 << 3) | 6;
}
elsif ($inst =~m/^\s*neg\s+\$r([01])(,)?\s+\$r([01])/i){
$num = ($1 << 4) | ($3 << 3) | 7;
}
elsif ($inst =~m/^\s*disp\s+\$r([01])(,)?\s+(\d+)/i){
$num = (1 << 5) | ($1 << 4) | ($3 & 15);
}
elsif ($inst =~m/^\s*lui\s+\$r([01])(,)?\s+(\d+)/i){
$num = (2 << 5) | ($1 << 4) | ($3 & 15);
}
elsif ($inst =~m/^\s*ori\s+\$r([01])(,)?\s+(\d+)/i){
$num = (3 << 5) | ($1 << 4) | ($3 & 15);
}
elsif ($inst =~m/^\s*lw\s+\$r([01])(,)?\s+(\d+)/i){
$num = (4 << 5) | ($1 << 4) | ($3 & 15);
}
elsif ($inst =~m/^\s*sw\s+\$r([01])(,)?\s+(\d+)/i){
$num = (5 << 5) | ($1 << 4) | ($3 & 15);
}
elsif ($inst =~m/^\s*j(ump)?\s+(\d+)/i){
$num = (6 << 5) | ($2 & 31);
}
elsif ($inst =~m/^\s*beq\s+(-?\d+)/i){
$num = (7 << 5) | ($1 & 31);
}
printf("%x\n", $num);
}