Browse Source

Implement ADDU/ADDIU

master
Forest Belton 3 years ago
parent
commit
58055d81b1
1 changed files with 21 additions and 1 deletions
  1. +21
    -1
      src/insn.c

+ 21
- 1
src/insn.c View File

@ -54,7 +54,7 @@ void insn_lw(cpu_t *cpu, uint32_t insn) {
}
void insn_srl(cpu_t *cpu, uint32_t insn) {
const uint8_t rd = RT(insn);
const uint8_t rd = RD(insn);
const uint8_t rt = RT(insn);
const uint8_t imm5 = IMM5(insn);
@ -62,10 +62,30 @@ void insn_srl(cpu_t *cpu, uint32_t insn) {
cpu->regs[rd] = cpu->regs[rt] >> imm5;
}
void insn_addu(cpu_t *cpu, uint32_t insn) {
const uint8_t rd = RD(insn);
const uint8_t rs = RS(insn);
const uint8_t rt = RT(insn);
debug("ADDU %s, %s, %s", REG_NAMES[rd], REG_NAMES[rs], REG_NAMES[rt]);
cpu->regs[rd] = cpu->regs[rs] + cpu->regs[rt];
}
void insn_addiu(cpu_t *cpu, uint32_t insn) {
const uint8_t rt = RT(insn);
const uint8_t rs = RS(insn);
const int16_t imm = (int16_t)IMM(insn);
debug("ADDIU %s, %s, %x", REG_NAMES[rt], REG_NAMES[rs], imm);
cpu->regs[rt] = cpu->regs[rs] + imm;
}
static cpu_insn_handler primary_insn_handler[TABLE_SIZE] = {
[LW] = insn_lw,
[ADDIU] = insn_addiu,
};
static cpu_insn_handler secondary_insn_handler[TABLE_SIZE] = {
[ADDU] = insn_addu,
[SRL] = insn_srl,
};

Loading…
Cancel
Save