-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathgalistingnasm.cpp
More file actions
95 lines (77 loc) · 2.82 KB
/
galistingnasm.cpp
File metadata and controls
95 lines (77 loc) · 2.82 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "galistingnasm.h"
#include "goodasm.h"
#include "gainstruction.h"
GAListingNasm::GAListingNasm() {
name="nasm";
}
QString GAListingNasm::renderSymbols(GoodASM *goodasm){
return ";; No symbol table yet.";
}
QString GAListingNasm::render(GoodASM *goodasm){
GAInstruction ins=goodasm->at(0);
QString src="";
//Assembly comes from source, must match data.
foreach(auto ins, goodasm->instructions){
src+=render(&ins);
}
return src;
}
QString GAListingNasm::render(GAInstruction *instruction){
// label, instruction, comments
QString label="";
QString ins="";
GoodASM *gasm=instruction->gasm;
switch(instruction->type){
case GAInstruction::DIRECTIVE:
if(instruction->override!="")
return instruction->override;
else
return ";;; Unknown directive.\n";
break;
case GAInstruction::COMMENT:
return ";"+instruction->comment+"\n";
case GAInstruction::NONE:
return ";;; No instruction type.\n";
break;
case GAInstruction::DATA:
//Address comes first, if we show it.
if(gasm->listadr)
label=QString::asprintf("%04x: ",
(int) gasm->lang->nativeAdr(instruction->adr));
//Then the data bytes. We always print these when they aren't
//a known instruction.
assert(instruction->len==instruction->data.length());
ins="";
ins="db ";
for(int i=0; i<instruction->data.length(); i++){
ins+=QString::asprintf("0x%02x, ", instruction->data[i] & 0xFF);
}
//Finally the instruction and parameters.
ins+=instruction->override;
//if(gasm->autocomment && instruction->comment.length()==0)
// instruction->comment="; illegal";
return gasm->formatSource("", ins, "; "+label+instruction->comment);
break;
case GAInstruction::MNEMONIC:
//Bad things happen if the length and the data disagree.
assert(instruction->len==instruction->data.length());
assert(instruction->len);
//Address comes first, if we show it.
if(gasm->listadr)
label+=QString::asprintf("%04x: ",
(int) gasm->lang->nativeAdr(instruction->adr));
//Then the data bytes, if we show them.
ins="db ";
for(int i=0; i<gasm->lang->maxbytes && i<instruction->len; i++){
ins+=QString::asprintf("0x%02x, ",
instruction->data[i] & 0xFF);
}
//Finally the instruction and parameters.
return formatSource("",
ins,
"; "+label+""+instruction->verb+" "+instruction->params,
instruction->comment);
break;
}
return ";;; unimplemented\n";
}