egg

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit a6eab3f6c8bb335569e3196132ca5cd94e0c7a2d
parent 410a5c9fd6833e92ede4a75f4d7a1dce6c5c8279
Author: Gabriel G. de Brito <gabrielgbrito@icloud.com>
Date:   Sun, 30 Mar 2025 12:19:29 -0300

Fixed immediate sign extension in REDUX-V

Diffstat:
Mmain.go | 2+-
Mreduxv/reduxv.go | 6+++---
Mreduxv/reduxv_test.go | 12++++++------
3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/main.go b/main.go @@ -16,7 +16,7 @@ import ( "github.com/gboncoffee/egg/sagui" ) -const VERSION = "3.3.0" +const VERSION = "3.3.1" // Put new architetures here... (main.go:/switch architeture) func listArchs() { diff --git a/reduxv/reduxv.go b/reduxv/reduxv.go @@ -15,7 +15,7 @@ import ( type ReduxV struct { registers [4]uint8 - mem [math.MaxUint8]uint8 + mem [math.MaxUint8 + 1]uint8 pc uint8 } @@ -126,14 +126,14 @@ func (m *ReduxV) NextInstruction() (*machine.Call, error) { m.pc = uint8(rbv) - 1 } case 0x1: - m.pc += uint8(imm) - 1 + m.pc += signExtend8(uint8(imm)) - 1 case 0x2: mem, _ := m.GetMemory(rbv) m.SetRegister(uint64(ra), uint64(mem)) case 0x3: m.SetMemory(rbv, uint8(rav)) case 0x4: - m.SetRegister(0, uint64(uint8(r0v)+imm)) + m.SetRegister(0, uint64(uint8(r0v)+signExtend8(imm))) case 0x5: m.pc++ return &machine.Call{ diff --git a/reduxv/reduxv_test.go b/reduxv/reduxv_test.go @@ -101,20 +101,20 @@ func TestReduxV(t *testing.T) { assertRegister(1, 0, "sub r1 for load/store") m.NextInstruction() - assertRegister(0, 0x0f, "addi address") + assertRegister(0, 0xff, "addi address") m.NextInstruction() - assertRegister(1, 0x0f, "add r1, r0 address") + assertRegister(1, 0xff, "add r1, r0 address") m.NextInstruction() assertRegister(0, 0, "zero r0 for value") m.NextInstruction() - assertRegister(0, 0x0e, "addi value") + assertRegister(0, 0xfe, "addi value") m.NextInstruction() - mem, _ := m.GetMemory(0x0f) - if mem != 0x0e { + mem, _ := m.GetMemory(0xff) + if mem != 0xfe { t.Fatalf("st failed") } @@ -122,7 +122,7 @@ func TestReduxV(t *testing.T) { assertRegister(0, 0, "sub for load test") m.NextInstruction() - assertRegister(0, 0x0e, "ld") + assertRegister(0, 0xfe, "ld") call, _ := m.NextInstruction() if call == nil || call.Number != machine.SYS_BREAK {