Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/core/Intel386AssemblyGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ void Intel386AssemblyGenerator::parseVariable(

} else if (type == "val") { // 变量

bool isOffset = false;
if (name.find('+') != string::npos) {
isOffset = true;
name.pop_back();
}

int valId = -1;
try {
valId = stoi(name);
Expand All @@ -277,15 +283,17 @@ void Intel386AssemblyGenerator::parseVariable(
// 因此,栈内存位置应该比 esp 的值大。

auto offset = this->variableStackOffsetMap[valId] - 4;
out << "[ebp ";
out << "[ebp";
if (offset > 0) {
out << "+ ";
out << " + ";
out << offset;
} else if (offset == 0) {
// do nothing
} else { // offset < 0

out << offset;
out << " - " << -offset;
}
if (isOffset) {
out << ", edx * 4";
}
out << "]";
}
Expand Down Expand Up @@ -456,7 +464,9 @@ void Intel386AssemblyGenerator::parseCode(
out << endl;

} else if (code[0] == "neg") {
// todo
out << " neg ";
parseVariable(code[1], code[2], out);
out << endl;
} else if (code[0] == "mul") {

out << " imul dword ";
Expand Down Expand Up @@ -498,7 +508,7 @@ void Intel386AssemblyGenerator::buildVariableOffsetMap() {

for (auto it : curr->symbols) {
this->variableStackOffsetMap[it->id] = memoryUsed;
memoryUsed += 4; // todo: should be it->bytes;
memoryUsed += it->bytes; // todo: should be it->bytes;
}

for (auto it : curr->children) {
Expand Down
Loading