commit b9efffd12e23c09cf75e6cc6021137c38c2ea4a1
parent aafa5fa1979a25539a3057f7b4c89fdb11137ccf
Author: Gabriel G. de Brito <me@gboncoffee.dev.br>
Date: Thu, 23 Jul 2026 11:14:46 -0300
Fixed PIÁ J instructions encoding.
Diffstat:
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/pia/pia.go b/pia/pia.go
@@ -687,7 +687,7 @@ func encodeB32(rd uint8, rs uint8, func_ uint8, imm uint32) uint32 {
// Format: imm[15:1] | imm[16] | imm[27:17] | opcode[3:0]
func encodeJ32(imm uint32, bit16 uint8, opcode uint8) uint32 {
immLow := (imm >> 1) & 0xFFFF
- immMid := (imm >> 17) & 0x7FF
+ immMid := (imm >> 17) & 0xFFF
return (immLow << 17) | (uint32(bit16) << 16) | (immMid << 4) | uint32(opcode)
}
@@ -1008,15 +1008,11 @@ func assembleJ32Instruction(mnemonic string, t assembler.ResolvedToken, addr uin
bit16 = 1
return encodeJ32(imm, bit16, 0xD), nil
case "lrj":
- offset := target - int32(addr)
- offset = offset >> 1
- imm := uint32(offset) & 0xFFFFFFF
+ imm := uint32(target - int32(addr))
bit16 = 0
return encodeJ32(imm, bit16, 0xE), nil
case "lrjl":
- offset := target - int32(addr)
- offset = offset >> 1
- imm := uint32(offset) & 0xFFFFFFF
+ imm := uint32(target - int32(addr))
bit16 = 1
return encodeJ32(imm, bit16, 0xE), nil
default: