From e211dc5e884a9a4b1ebd050dcfcdc761d290ae8c Mon Sep 17 00:00:00 2001 From: adam Date: Fri, 16 Feb 2007 15:58:07 +0100 Subject: [PATCH] fixed sign-extend bug --- src/edu/berkeley/fleet/ies44/InstructionEncoder.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/edu/berkeley/fleet/ies44/InstructionEncoder.java b/src/edu/berkeley/fleet/ies44/InstructionEncoder.java index 72e7839..e8f38a3 100644 --- a/src/edu/berkeley/fleet/ies44/InstructionEncoder.java +++ b/src/edu/berkeley/fleet/ies44/InstructionEncoder.java @@ -64,6 +64,7 @@ public abstract class InstructionEncoder { case 2: { BenkoBox name = getBoxByInstAddr((inst >> 24) & 0x7ff); int val = ((int)(instr )) & ~(0xffffffff << 24); + val = signExtend24(val); return new Instruction.Literal.Absolute(name, val); } @@ -123,7 +124,7 @@ public abstract class InstructionEncoder { instr |= (getBoxAddr(ld.dest)) << 24; if (ld.value >= (1<<25)) throw new RuntimeException("literals must be less than 2^24"); - instr |= ((long)ld.value); + instr |= ((long)ld.value) & ~(0xffffffff << 24); } else if (d instanceof Instruction.Literal.Relative) { Instruction.Literal.Relative lr = (Instruction.Literal.Relative)d; @@ -147,4 +148,10 @@ public abstract class InstructionEncoder { os.write((int)((instr >> (0*8)) & 0xff)); } + public static int signExtend24(int val) { + if ((val & (1 << 23)) != 0) + val = val | (0xffffffff << 24); + return val; + } + } \ No newline at end of file -- 1.7.10.4