From 64d440c94ba4f4d4341805078786514d9e9710ec Mon Sep 17 00:00:00 2001 From: Paul Mathieu Date: Mon, 22 Feb 2021 20:33:05 -0800 Subject: [PATCH] Word-precise imm for BEQ and BNEQ --- first/cpu.vhdl | 4 ++-- tools/as.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/first/cpu.vhdl b/first/cpu.vhdl index 7ab2b57..84c64cb 100644 --- a/first/cpu.vhdl +++ b/first/cpu.vhdl @@ -167,14 +167,14 @@ begin when "1101" => -- BEQ [rn, imm] (jump to [rn, imm] if flag is set, imm is signed 8 bits) if reg_q(15)(0) = '1' then - reg_d(14) <= std_logic_vector(signed(reg_q(regn_0)) + signed(inst(7 downto 0))); + reg_d(14) <= std_logic_vector(signed(reg_q(regn_0)) + signed(inst(7 downto 0) & '0')); cpu_state_next <= BRANCH; end if; when "1110" => -- SET rd, imm (rd := imm, imm is 8 bit) reg_d(regn_0) <= x"00" & inst(7 downto 0); when "1111" => -- BNEQ [rn, imm] if reg_q(15)(0) = '0' then - reg_d(14) <= std_logic_vector(signed(reg_q(regn_0)) + signed(inst(7 downto 0))); + reg_d(14) <= std_logic_vector(signed(reg_q(regn_0)) + signed(inst(7 downto 0) & '0')); cpu_state_next <= BRANCH; end if; diff --git a/tools/as.py b/tools/as.py index e89418a..b07c769 100644 --- a/tools/as.py +++ b/tools/as.py @@ -22,9 +22,9 @@ opcodes = { 'shr' : lambda p0, p1, p2: f'a{p0:x}{p1:x}{p2:x}', 'mul' : lambda p0, p1, p2: f'b{p0:x}{p1:x}{p2:x}', 'cmp' : lambda p0, p1: f'c{p0:x}{p1:x}0', - 'beq' : lambda p0, p1: f'd{p0:x}{p1&0xff:02x}', + 'beq' : lambda p0, p1: f'd{p0:x}{(p1 >> 1)&0xff:02x}', 'set' : lambda p0, p1: f'e{p0:x}{p1&0xff:02x}', - 'bneq' : lambda p0, p1: f'f{p0:x}{p1&0xff:02x}', + 'bneq' : lambda p0, p1: f'f{p0:x}{(p1 >> 1)&0xff:02x}', '.word': lambda p0: f'{p0:04x}', }