diff --git a/gmachine.go b/gmachine.go index 083b536..69b0c52 100644 --- a/gmachine.go +++ b/gmachine.go @@ -24,6 +24,8 @@ const ( OpNOOP OpOUTA OpINCA + OpINCX + OpINCY OpDECA OpDECX OpDECY @@ -68,6 +70,8 @@ var opcodes = map[string]Word{ "NOOP": OpNOOP, "OUTA": OpOUTA, "INCA": OpINCA, + "INCX": OpINCX, + "INCY": OpINCY, "DECA": OpDECA, "DECX": OpDECX, "DECY": OpDECY, @@ -134,6 +138,10 @@ func (g *Machine) Run() { binary.Write(g.Out, binary.BigEndian, g.A) case OpINCA: g.A++ + case OpINCX: + g.X++ + case OpINCY: + g.Y++ case OpDECA: g.A-- case OpDECX: diff --git a/gmachine_test.go b/gmachine_test.go index 6b16497..f912f2c 100644 --- a/gmachine_test.go +++ b/gmachine_test.go @@ -104,6 +104,32 @@ func TestINCA(t *testing.T) { } } +func TestINCX(t *testing.T) { + t.Parallel() + g := gmachine.New(nil) + err := assembleAndRunFromString(g, "INCX") + if err != nil { + t.Fatal("didn't expect an error:", err) + } + var wantX gmachine.Word = 1 + if wantX != g.X { + t.Errorf("want X value %d, got %d", wantX, g.X) + } +} + +func TestINCY(t *testing.T) { + t.Parallel() + g := gmachine.New(nil) + err := assembleAndRunFromString(g, "INCY") + if err != nil { + t.Fatal("didn't expect an error:", err) + } + var wantY gmachine.Word = 1 + if wantY != g.Y { + t.Errorf("want Y value %d, got %d", wantY, g.Y) + } +} + func TestIllegalInstruction(t *testing.T) { t.Parallel() g := gmachine.New(nil) diff --git a/testdata/gc.txtar b/testdata/gc.txtar index e6fb34d..992755a 100644 --- a/testdata/gc.txtar +++ b/testdata/gc.txtar @@ -9,6 +9,6 @@ SETA 42 OUTA -- want -- -0000000 0000 0000 0000 0b00 0000 0000 0000 2a00 +0000000 0000 0000 0000 0d00 0000 0000 0000 2a00 0000010 0000 0000 0000 0300 0000018 diff --git a/token/token.go b/token/token.go index b773ae2..8ca1ea2 100644 --- a/token/token.go +++ b/token/token.go @@ -23,6 +23,8 @@ var opcodes = map[string]TokenType{ "NOOP": OPCODE, "OUTA": OPCODE, "INCA": OPCODE, + "INCX": OPCODE, + "INCY": OPCODE, "DECA": OPCODE, "DECX": OPCODE, "DECY": OPCODE, diff --git a/token/token_test.go b/token/token_test.go index 4412d14..f4248cb 100644 --- a/token/token_test.go +++ b/token/token_test.go @@ -15,6 +15,8 @@ func TestLookupIdent(t *testing.T) { {"NOOP", token.OPCODE}, {"OUTA", token.OPCODE}, {"INCA", token.OPCODE}, + {"INCX", token.OPCODE}, + {"INCY", token.OPCODE}, {"DECA", token.OPCODE}, {"DECX", token.OPCODE}, {"DECY", token.OPCODE}, @@ -29,6 +31,7 @@ func TestLookupIdent(t *testing.T) { {"JUMP", token.OPCODE}, {"JXNZ", token.OPCODE}, {"X", token.REGISTER}, + {"Y", token.REGISTER}, {"test", token.IDENT}, {".test", token.IDENT}, }