commit d9dd10cd6a69f6da102814ebefe1d7ad2a32a020
parent ed666b4fd98ad168f735b814cf74e77ef5c52794
Author: Louis Burda <quent.burda@gmail.com>
Date: Wed, 26 Jul 2023 18:02:50 +0200
Revert adding AND/NOT
Diffstat:
M | asm.c | | | 16 | ++++++++-------- |
M | tpu.c | | | 34 | ++++++++++++++++++---------------- |
M | tpu.h | | | 6 | ++++-- |
3 files changed, 30 insertions(+), 26 deletions(-)
diff --git a/asm.c b/asm.c
@@ -21,8 +21,8 @@ enum asm_tok {
TOK_ANY, TOK_LAST, TOK_LIT, TOK_NAME,
/* Instructions (order like INST_*) */
- TOK_NOP, TOK_MOV, TOK_SWP, TOK_SAV, TOK_ADD, TOK_SUB, TOK_NEG,
- TOK_NOT, TOK_AND, TOK_JMP, TOK_JEZ, TOK_JNZ, TOK_JRO,
+ TOK_NOP, TOK_MOV, TOK_SWP, TOK_SAV, TOK_ADD, TOK_SUB,
+ TOK_NEG, TOK_JMP, TOK_JEZ, TOK_JNZ, TOK_JGZ, TOK_JLZ, TOK_JRO,
/* Misc */
TOK_COMMENT, TOK_LABEL, TOK_XPOS, TOK_YPOS, TOK_NL, TOK_EOF
@@ -46,8 +46,8 @@ static const char *tok_strs[] = {
"any", "last", NULL, NULL,
/* Instructions (order like INST_*) */
- "nop", "mov", "swp", "sav", "add", "sub", "neg",
- "not", "and", "jmp", "jez", "jnz", "jro",
+ "nop", "mov", "swp", "sav", "add", "sub",
+ "neg", "jmp", "jez", "jnz", "jgz", "jlz", "jro",
/* Misc */
NULL, NULL, NULL, NULL, NULL, NULL
@@ -62,8 +62,8 @@ static const char *tok_reprs[] = {
"'ANY'", "'LAST'", "<LIT>", "<NAME>",
/* Instructions (order like INST_*) */
- "'NOP'", "'MOV'", "'SWP'", "'SAV'", "'ADD'", "'SUB'", "'NEG'",
- "'NOT'", "'AND'", "'JMP'", "'JEZ'", "'JNZ'", "'JRO'",
+ "'NOP'", "'MOV'", "'SWP'", "'SAV'", "'ADD'", "'SUB'",
+ "'NEG'", "'JMP'", "'JEZ'", "'JNZ'", "'JGZ'", "'JLZ'", "'JRO'",
/* Misc */
"#<COMMENT>", "<LABEL>:", "X<INT>", "Y<INT>", "<NL>", "<EOF>"
@@ -348,8 +348,8 @@ tis_load(struct tis *tis, const char *filepath)
tok_next_in(&tokenizer, TOK_NL, -1);
break;
case TOK_NOP: case TOK_MOV: case TOK_SWP: case TOK_SAV:
- case TOK_ADD: case TOK_SUB: case TOK_NEG: case TOK_NOT:
- case TOK_AND: case TOK_JMP: case TOK_JEZ: case TOK_JNZ:
+ case TOK_ADD: case TOK_SUB: case TOK_NEG: case TOK_JMP:
+ case TOK_JEZ: case TOK_JNZ: case TOK_JGZ: case TOK_JLZ:
case TOK_JRO:
if (!tpu) goto disallowed;
inst = tok_to_inst(tok);
diff --git a/tpu.c b/tpu.c
@@ -16,8 +16,8 @@ const char *status_reprs[] = {
};
const char *inst_reprs[] = {
- "NOP", "MOV", "SWP", "SAV", "ADD", "SUB", "NEG",
- "NOT", "AND", "JMP", "JEZ", "JNZ", "JGZ", "JLZ", "JRO"
+ "NOP", "MOV", "SWP", "SAV", "ADD", "SUB",
+ "NEG", "JMP", "JEZ", "JNZ", "JGZ", "JLZ", "JRO"
};
const char *op_reprs[] = {
@@ -277,19 +277,19 @@ tpu_set_inst(struct tpu *tpu, uint8_t pc, enum tpu_inst_type inst_type,
inst->ops[1] = op2;
switch (inst->type) {
- case INST_NOP: case INST_SAV: case INST_SWP:
- case INST_NEG: case INST_NOT:
+ case INST_NOP: case INST_SAV:
+ case INST_SWP: case INST_NEG:
if (inst->opcnt != 0) return false;
break;
- case INST_ADD: case INST_SUB: case INST_AND:
+ case INST_ADD: case INST_SUB:
if (inst->opcnt != 1) return false;
- if (inst->opcnt == OP_LABEL) return false;
break;
case INST_JRO:
if (inst->opcnt != 1) return false;
if (inst->ops[0].type != OP_LIT) return false;
break;
case INST_JMP: case INST_JEZ: case INST_JNZ:
+ case INST_JGZ: case INST_JLZ:
if (inst->opcnt != 1) return false;
if (inst->ops[0].type != OP_LABEL) return false;
break;
@@ -477,16 +477,6 @@ tpu_exec(struct tpu *tpu, struct tpu_inst *inst)
tpu->acc = -tpu->acc;
tpu->pc += 1;
return STATUS_RUN;
- case INST_NOT:
- tpu->acc = ~tpu->acc;
- tpu->pc += 1;
- return STATUS_RUN;
- case INST_AND:
- val = tpu_exec_get(tpu, &inst->ops[0]);
- if (val < 0) return STATUS_READ;
- tpu->acc &= (uint8_t) val;
- tpu->pc += 1;
- return STATUS_RUN;
case INST_JMP:
tpu_jmp_label(tpu, inst->ops[0].val.label);
return STATUS_RUN;
@@ -502,6 +492,18 @@ tpu_exec(struct tpu *tpu, struct tpu_inst *inst)
else
tpu->pc += 1;
return STATUS_RUN;
+ case INST_JGZ:
+ if (tpu->acc > 0)
+ tpu_jmp_label(tpu, inst->ops[0].val.label);
+ else
+ tpu->pc += 1;
+ return STATUS_RUN;
+ case INST_JLZ:
+ if (tpu->acc < 0)
+ tpu_jmp_label(tpu, inst->ops[0].val.label);
+ else
+ tpu->pc += 1;
+ return STATUS_RUN;
case INST_JRO:
tpu->pc += inst->ops[0].val.lit;
if (tpu->pc >= tpu->inst_cnt) tpu->pc = 0;
diff --git a/tpu.h b/tpu.h
@@ -15,8 +15,10 @@ enum tpu_status {
};
enum tpu_inst_type {
- INST_NOP, INST_MOV, INST_SWP, INST_SAV, INST_ADD, INST_SUB, INST_NEG,
- INST_NOT, INST_AND, INST_JMP, INST_JEZ, INST_JNZ, INST_JRO
+ INST_NOP, INST_MOV, INST_SWP, INST_SAV,
+ INST_ADD, INST_SUB, INST_NEG, INST_JMP,
+ INST_JEZ, INST_JNZ, INST_JGZ, INST_JLZ,
+ INST_JRO
};
enum tpu_inst_op_type {