-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdisassembler.js
More file actions
56 lines (48 loc) · 1.39 KB
/
disassembler.js
File metadata and controls
56 lines (48 loc) · 1.39 KB
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
function Disassembler()
{
this.instructionset = new InstructionSet();
}
Disassembler.prototype.disassemble = function(code)
{
var source = "";
for (var i = 0; i < code.length; i+=8)
{
var instruction = this.instructionset.getByOpcode(code[i]);
var condition = this.instructionset.getConditionByCode((code[i+2]>>2)&15);
if (condition == null) condition = "??"; else condition=condition.condition;
linenum = (i.toString(16));
var missing = 8-linenum.length;
for (var p = 0; p<(missing);p++) linenum = "0"+linenum;
source += linenum + ": "+instruction.mnemonic+"."+condition+"\t";
var ops = (code[i+1]|(code[i+2]<<8));
var op1 = ops&31;
var op2 = (ops>>5)&31;
var number = ((code[i+4])|(code[i+5]<<8)|(code[i+6]<<16)|(code[i+7]<<24)) >>> 0;
if (op1 == 31)
{
source+="0x"+number.toString(16);
}
else if (op1==30)
{
// it means no op1 is defined, so no ops at all.
}
else
{
source+="r"+op1;
}
if (op2 == 31)
{
source+=",0x"+number.toString(16);
}
else if (op2==30)
{
// it means no op1 is defined, so no ops at all.
}
else
{
source+=",r"+op2;
}
source+="\r\n";
}
return source;
}