+ alu_in0_2a = op0_2a;
+ alu_in1_2a = op1_2a;
+ alu_op_2a = insn_2a[24:21];
+ alu_setflags_2a = insn_2a[20] /* S */;
+ end
+
+ /* Register outputs */
+ always @(*)
+ begin
+ next_outcpsr = cpsr_2a;
+ next_outspsr = spsr_2a;
+ next_outcpsrup = 0;
+ next_write_reg_3a = 0;
+ next_write_num_3a = 4'hx;
+ next_write_data_3a = 32'hxxxxxxxx;
+
+ casez(insn_2a)
+ `DECODE_ALU_MULT: /* Multiply -- must come before ALU, because it pattern matches a specific case of ALU */
+ begin
+ next_outcpsr = insn_2a[20] /* S */ ? {mult_result[31] /* N */, mult_result == 0 /* Z */, 1'b0 /* C */, cpsr_2a[28] /* V */, cpsr_2a[27:0]} : cpsr_2a;
+ next_outcpsrup = insn_2a[20] /* S */;
+ next_write_reg_3a = 1;
+ next_write_num_3a = insn_2a[19:16] /* Rd -- why the fuck isn't this the same place as ALU */;
+ next_write_data_3a = mult_result;
+ end
+ `DECODE_ALU_MRS: /* MRS (Transfer PSR to register) */
+ begin
+ next_write_reg_3a = 1;
+ next_write_num_3a = insn_2a[15:12];
+ if (insn_2a[22] /* Ps */)
+ next_write_data_3a = spsr_2a;
+ else
+ next_write_data_3a = cpsr_2a;
+ end
+ `DECODE_ALU_MSR, /* MSR (Transfer register to PSR) */
+ `DECODE_ALU_MSR_FLAGS: /* MSR (Transfer register or immediate to PSR, flag bits only) */
+ begin
+ if ((cpsr_2a[4:0] == `MODE_USR) || (insn_2a[16] /* that random bit */ == 1'b0)) /* flags only */
+ begin
+ if (insn_2a[22] /* Ps */)
+ next_outspsr = {op0_2a[31:29], spsr_2a[28:0]};
+ else
+ next_outcpsr = {op0_2a[31:29], cpsr_2a[28:0]};
+ end else begin
+ if (insn_2a[22] /* Ps */)
+ next_outspsr = op0_2a;
+ else
+ next_outcpsr = op0_2a;
+ end
+ next_outcpsrup = 1;
+ end
+ `DECODE_ALU_SWP, /* Atomic swap */
+ `DECODE_ALU_BX, /* Branch */
+ `DECODE_ALU_HDATA_REG, /* Halfword transfer - register offset */
+ `DECODE_ALU_HDATA_IMM: /* Halfword transfer - immediate offset */
+ begin end
+ `DECODE_ALU: /* ALU */
+ begin
+ if (alu_setres_2a) begin
+ next_write_reg_3a = 1;
+ next_write_num_3a = insn_2a[15:12] /* Rd */;
+ next_write_data_3a = alu_result_2a;
+ end
+
+ if (insn_2a[20] /* S */) begin
+ next_outcpsrup = 1;
+ next_outcpsr = ((insn_2a[15:12] == 4'b1111) && insn_2a[20]) ? spsr_2a : alu_outcpsr_2a;
+ end
+ end
+ `DECODE_LDRSTR_UNDEFINED, /* Undefined. I hate ARM */
+ `DECODE_LDRSTR, /* Single data transfer */
+ `DECODE_LDMSTM: /* Block data transfer */
+ begin end
+ `DECODE_BRANCH: /* Branch */
+ begin
+ if(insn_2a[24] /* L */) begin
+ next_write_reg_3a = 1;
+ next_write_num_3a = 4'hE; /* link register */
+ next_write_data_3a = pc_2a + 32'h4;
+ end
+ end
+ endcase
+ end