2020-10-31 21:53:11 -04:00
|
|
|
#ifndef templates
|
|
|
|
#define templates
|
|
|
|
|
2020-11-17 12:12:39 -05:00
|
|
|
#define TPUSHN 11
|
2020-10-31 21:53:11 -04:00
|
|
|
char* tpush[TPUSHN] = {
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"A=D+A",
|
|
|
|
"D=M",
|
|
|
|
"@SP",
|
2020-11-17 12:12:39 -05:00
|
|
|
"A=M",
|
|
|
|
"M=D",
|
|
|
|
"@SP",
|
2020-11-01 10:40:43 -05:00
|
|
|
"M=M+1",
|
2020-10-31 21:53:11 -04:00
|
|
|
};
|
|
|
|
|
2020-11-17 12:12:39 -05:00
|
|
|
#define TPUSHCONSN 8
|
2020-10-31 21:53:11 -04:00
|
|
|
char* tpushcons[TPUSHCONSN] = {
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"D=A",
|
|
|
|
"@SP",
|
2020-11-17 12:12:39 -05:00
|
|
|
"A=M",
|
|
|
|
"M=D",
|
|
|
|
"@SP",
|
2020-11-01 10:40:43 -05:00
|
|
|
"M=M+1",
|
2020-10-31 21:53:11 -04:00
|
|
|
};
|
|
|
|
|
2020-11-17 12:12:39 -05:00
|
|
|
#define TPUSHSTATN 8
|
2020-10-31 21:53:11 -04:00
|
|
|
char* tpushstat[TPUSHSTATN] = {
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"D=M",
|
|
|
|
"@SP",
|
2020-11-17 12:12:39 -05:00
|
|
|
"A=M",
|
|
|
|
"M=D",
|
|
|
|
"@SP",
|
2020-11-01 10:40:43 -05:00
|
|
|
"M=M+1",
|
2020-10-31 21:53:11 -04:00
|
|
|
};
|
|
|
|
|
2020-11-01 10:40:43 -05:00
|
|
|
#define TPUSHTEMPN TPUSHSTATN
|
|
|
|
char** tpushtemp = tpushstat;
|
|
|
|
|
|
|
|
#define TPUSHPOINTERN TPUSHSTATN
|
|
|
|
char** tpushpointer = tpushstat;
|
2020-10-31 21:53:11 -04:00
|
|
|
|
2020-11-17 12:12:39 -05:00
|
|
|
#define TPOPN 13
|
2020-10-31 21:53:11 -04:00
|
|
|
char* tpop[TPOPN] = {
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"D=D+A",
|
|
|
|
"@R13",
|
|
|
|
"M=D",
|
|
|
|
"@SP",
|
2020-11-17 12:12:39 -05:00
|
|
|
"AM=M-1",
|
2020-10-31 21:53:11 -04:00
|
|
|
"D=M",
|
|
|
|
"@R13",
|
|
|
|
"A=M",
|
|
|
|
"M=D"
|
|
|
|
};
|
|
|
|
|
2020-11-17 12:12:39 -05:00
|
|
|
#define TPOPSTATN 6
|
2020-10-31 21:53:11 -04:00
|
|
|
char* tpopstat[TPOPSTATN] = {
|
|
|
|
"",
|
|
|
|
"@SP",
|
2020-11-17 12:12:39 -05:00
|
|
|
"AM=M-1",
|
2020-10-31 21:53:11 -04:00
|
|
|
"D=M",
|
|
|
|
"",
|
|
|
|
""
|
|
|
|
};
|
|
|
|
|
2020-11-01 17:39:27 -05:00
|
|
|
#define TPOPTEMPN TPOPSTATN
|
|
|
|
char** tpoptemp = tpopstat;
|
|
|
|
|
|
|
|
#define TPOPPOINTERN TPOPSTATN
|
|
|
|
char** tpoppointer = tpopstat;
|
2020-11-01 10:40:43 -05:00
|
|
|
|
2020-11-17 12:12:39 -05:00
|
|
|
#define TARITHN 6
|
2020-11-01 16:57:56 -05:00
|
|
|
char* tarith[TARITHN] = {
|
|
|
|
"",
|
|
|
|
"@SP",
|
2020-11-17 12:12:39 -05:00
|
|
|
"AM=M-1",
|
2020-11-01 16:57:56 -05:00
|
|
|
"D=M",
|
|
|
|
"A=A-1",
|
|
|
|
""
|
|
|
|
};
|
|
|
|
|
2020-11-01 17:11:11 -05:00
|
|
|
#define TNEGN 4
|
2020-11-01 16:57:56 -05:00
|
|
|
char* tneg[TNEGN] = {
|
|
|
|
"",
|
|
|
|
"@SP",
|
2020-11-01 17:11:11 -05:00
|
|
|
"A=M-1",
|
2020-11-01 16:57:56 -05:00
|
|
|
"M=-M",
|
|
|
|
};
|
|
|
|
|
2020-11-01 17:11:11 -05:00
|
|
|
#define TNOTN 4
|
2020-11-01 16:57:56 -05:00
|
|
|
char* tnot[TNOTN] = {
|
|
|
|
"",
|
|
|
|
"@SP",
|
2020-11-01 17:11:11 -05:00
|
|
|
"A=M-1",
|
2020-11-01 16:57:56 -05:00
|
|
|
"M=!M",
|
|
|
|
};
|
|
|
|
|
2020-11-17 12:12:39 -05:00
|
|
|
#define TCOMPN 13
|
2020-11-01 16:57:56 -05:00
|
|
|
char* tcomp[TCOMPN] = {
|
|
|
|
"",
|
|
|
|
"@SP",
|
2020-11-17 12:12:39 -05:00
|
|
|
"AM=M-1",
|
2020-11-01 16:57:56 -05:00
|
|
|
"D=M",
|
|
|
|
"A=A-1",
|
|
|
|
"D=D-M",
|
2020-11-01 17:39:27 -05:00
|
|
|
"M=-1",
|
2020-11-01 16:57:56 -05:00
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"@SP",
|
|
|
|
"A=M-1",
|
|
|
|
"M=0",
|
|
|
|
""
|
|
|
|
};
|
2020-11-14 10:31:57 -05:00
|
|
|
|
|
|
|
#define TLABELN 2
|
|
|
|
char* tlabel[TLABELN] = {
|
|
|
|
"",
|
|
|
|
""
|
|
|
|
};
|
|
|
|
|
|
|
|
#define TGOTON 3
|
|
|
|
char* tgoto[TGOTON] = {
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"0;JMP"
|
|
|
|
};
|
|
|
|
|
2020-11-17 12:12:39 -05:00
|
|
|
#define TIFGOTON 6
|
2020-11-14 10:31:57 -05:00
|
|
|
char* tifgoto[TIFGOTON] = {
|
|
|
|
"",
|
|
|
|
"@SP",
|
2020-11-17 12:12:39 -05:00
|
|
|
"AM=M-1",
|
2020-11-14 10:31:57 -05:00
|
|
|
"D=M",
|
|
|
|
"",
|
|
|
|
"D;JNE"
|
|
|
|
};
|
|
|
|
|
2020-11-17 12:12:39 -05:00
|
|
|
#define TCALLSTARTN 8
|
|
|
|
char* tcallstart[TCALLSTARTN] = {
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"D=A",
|
|
|
|
"@SP",
|
|
|
|
"A=M",
|
|
|
|
"M=D",
|
|
|
|
"@SP",
|
|
|
|
"M=M+1",
|
|
|
|
};
|
|
|
|
|
|
|
|
#define TCALLPUSHN 7
|
|
|
|
char* tcallpush[TCALLPUSHN] = {
|
|
|
|
"",
|
|
|
|
"D=M",
|
|
|
|
"@SP",
|
|
|
|
"A=M",
|
|
|
|
"M=D",
|
|
|
|
"@SP",
|
|
|
|
"M=M+1",
|
|
|
|
};
|
|
|
|
|
|
|
|
#define TCALLSETARGN 8
|
|
|
|
char* tcallsetarg[TCALLSETARGN] = {
|
|
|
|
"@SP",
|
|
|
|
"D=M",
|
|
|
|
"@LCL",
|
|
|
|
"M=D",
|
|
|
|
"",
|
|
|
|
"D=D-A",
|
|
|
|
"@ARG",
|
|
|
|
"M=D"
|
|
|
|
};
|
|
|
|
|
|
|
|
#define TCALLJMPN 3
|
|
|
|
char* tcalljmp[TCALLJMPN] = {
|
|
|
|
"",
|
|
|
|
"0;JMP",
|
|
|
|
""
|
|
|
|
};
|
|
|
|
|
|
|
|
#define TFRAMEVARSN 4
|
|
|
|
char* tframevars[TFRAMEVARSN] = {
|
|
|
|
"@LCL",
|
|
|
|
"@ARG",
|
|
|
|
"@THIS",
|
|
|
|
"@THAT"
|
|
|
|
};
|
|
|
|
|
|
|
|
#define TFUNCTIONN 2
|
|
|
|
char* tfunction[TFUNCTIONN] = {
|
|
|
|
"",
|
|
|
|
""
|
|
|
|
};
|
|
|
|
|
|
|
|
#define TFUNCTIONPUSHN 5
|
|
|
|
char* tfunctionpush[TFUNCTIONPUSHN] = {
|
|
|
|
"@SP",
|
|
|
|
"A=M",
|
|
|
|
"M=0",
|
|
|
|
"@SP",
|
|
|
|
"M=M+1"
|
|
|
|
};
|
|
|
|
|
|
|
|
#define TSTARTRETURNN 18
|
|
|
|
char* tstartreturn[TSTARTRETURNN] = {
|
|
|
|
"",
|
|
|
|
"@LCL",
|
|
|
|
"D=M",
|
|
|
|
"@5",
|
|
|
|
"A=D-A",
|
|
|
|
"D=M",
|
|
|
|
"@R13",
|
|
|
|
"M=D",
|
|
|
|
"@SP",
|
|
|
|
"A=M-1",
|
|
|
|
"D=M",
|
|
|
|
"@ARG",
|
|
|
|
"A=M",
|
|
|
|
"M=D",
|
|
|
|
"@ARG",
|
|
|
|
"D=M+1",
|
|
|
|
"@SP",
|
|
|
|
"M=D"
|
|
|
|
};
|
|
|
|
|
|
|
|
#define TRETPOPN 5
|
|
|
|
char* tretpop[TRETPOPN] = {
|
|
|
|
"@LCL",
|
|
|
|
"AM=M-1",
|
|
|
|
"D=M",
|
|
|
|
"",
|
|
|
|
"M=D",
|
|
|
|
};
|
|
|
|
|
|
|
|
#define TENDRETURNN 3
|
|
|
|
char* tendreturn[TENDRETURNN] = {
|
|
|
|
"@R13",
|
|
|
|
"A=M",
|
|
|
|
"0;JMP"
|
|
|
|
};
|
|
|
|
|
2020-10-31 21:53:11 -04:00
|
|
|
#endif
|