commit c305b6f188a2d59e8ba7e87b6ee6761922d09447
parent 9d132dc59173787dd773ce0e82b55bc4e1c1dffc
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Mon, 16 Mar 2015 09:56:34 +0000
Add LDI instruction
This instruction is used for immediate loads.
Diffstat:
3 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/cc2/cc2.h b/cc2/cc2.h
@@ -112,7 +112,17 @@ enum nerrors {
enum {
- LDW, LDL, LDH, MOV, ADD, PUSH, POP, RET, NOP, INC
+ LDW,
+ LDL,
+ LDH,
+ MOV,
+ LDI,
+ ADD,
+ PUSH,
+ POP,
+ RET,
+ NOP,
+ INC
};
enum {
diff --git a/cc2/cgen.c b/cc2/cgen.c
@@ -122,8 +122,17 @@ moveto(Node *np, uint8_t reg)
Symbol *sym;
switch (np->op) {
- case AUTO:
case CONST:
+ switch (np->type.size) {
+ case 1:
+ case 2:
+ code(LDI, regs[reg], np);
+ break;
+ default:
+ abort();
+ }
+ break;
+ case AUTO:
sym = np->u.sym;
switch (np->type.size) {
case 1:
diff --git a/cc2/code.c b/cc2/code.c
@@ -24,6 +24,7 @@ static void (*instcode[])(void) = {
[LDW] = inst2,
[LDL] = inst2,
[LDH] = inst2,
+ [LDI] = inst2,
[MOV] = inst2,
[ADD] = inst2,
[PUSH] = inst1,
@@ -37,6 +38,7 @@ static char *insttext[] = {
[LDW] = "LD",
[LDL] = "LD",
[LDH] = "LD",
+ [LDI] = "LD",
[MOV] = "LD",
[ADD] = "ADD",
[PUSH] = "PUSH",