Fix several bugs

This commit is contained in:
Augusto Gunsch 2020-11-01 19:39:27 -03:00
parent ae2e7f7362
commit 3fdf4c1281
No known key found for this signature in database
GPG Key ID: F7EEFE29825C72DC
2 changed files with 11 additions and 24 deletions

View File

@ -63,17 +63,6 @@ char* tpop[TPOPN] = {
#define TPOPSTATN 7
char* tpopstat[TPOPSTATN] = {
"",
"@SP",
"M=M-1",
"A=M+1",
"D=M",
"",
""
};
#define TPOPTEMPN 7
char* tpoptemp[TPOPTEMPN] = {
"",
"@SP",
"M=M-1",
@ -83,16 +72,11 @@ char* tpoptemp[TPOPTEMPN] = {
""
};
#define TPOPPOINTERN 7
char* tpoppointer[TPOPPOINTERN] = {
"",
"@SP",
"M=M-1",
"A=M",
"D=M",
"",
"M=D"
};
#define TPOPTEMPN TPOPSTATN
char** tpoptemp = tpopstat;
#define TPOPPOINTERN TPOPSTATN
char** tpoppointer = tpopstat;
#define TARITHN 7
char* tarith[TARITHN] = {
@ -131,7 +115,7 @@ char* tcomp[TCOMPN] = {
"D=M",
"A=A-1",
"D=D-M",
"M=1",
"M=-1",
"",
"",
"@SP",

View File

@ -297,6 +297,9 @@ void poppointer(struct Translator* t, struct line* ln, int indlen) {
// @THIS/@THAT
tpoppointer[TPOPPOINTERN-2] = mkpointerind(t, ln, indlen);
// M=D
tpoppointer[TPOPPOINTERN-1] = heapstr(t, "M=D");
addasmlns(t, ln, tpoppointer, TPOPPOINTERN);
}
@ -380,9 +383,9 @@ void switchop(struct Translator* t, struct line* ln) {
else if(!strcmp(op, "eq"))
comp(t, ln, "EQ");
else if(!strcmp(op, "gt"))
comp(t, ln, "GT");
else if(!strcmp(op, "lt"))
comp(t, ln, "LT");
else if(!strcmp(op, "lt"))
comp(t, ln, "GT");
else if(!strcmp(op, "and"))
arith(t, ln, "M=M&D");
else if(!strcmp(op, "or"))