summaryrefslogtreecommitdiffstats
path: root/tpu.c
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2023-07-26 07:54:02 +0200
committerLouis Burda <quent.burda@gmail.com>2023-07-26 07:54:02 +0200
commit756e5b07f45852fcda14b58822ca66e1c0f05d0c (patch)
treeb4b570b0eff20a7cf0007dc52392ccf7bd120d73 /tpu.c
parent565355c91601043b5e599bc7e79ee7f1d3140e21 (diff)
downloadtis100-756e5b07f45852fcda14b58822ca66e1c0f05d0c.tar.gz
tis100-756e5b07f45852fcda14b58822ca66e1c0f05d0c.zip
Remove jgz/jlz and add not/and instructions
Diffstat (limited to 'tpu.c')
-rw-r--r--tpu.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/tpu.c b/tpu.c
index 8981cf2..2e91784 100644
--- 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", "JMP", "JEZ", "JNZ", "JGZ", "JLZ", "JRO"
+ "NOP", "MOV", "SWP", "SAV", "ADD", "SUB", "NEG",
+ "NOT", "AND", "JMP", "JEZ", "JNZ", "JGZ", "JLZ", "JRO"
};
const char *op_reprs[] = {
@@ -272,19 +272,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_NOP: case INST_SAV: case INST_SWP:
+ case INST_NEG: case INST_NOT:
if (inst->opcnt != 0) return false;
break;
- case INST_ADD: case INST_SUB:
+ case INST_ADD: case INST_SUB: case INST_AND:
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;
@@ -483,6 +483,16 @@ 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;
@@ -498,18 +508,6 @@ 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;