Skip to content

Commit

Permalink
Add DECY instruction.
Browse files Browse the repository at this point in the history
  • Loading branch information
aleury committed Jan 15, 2024
1 parent 7d14568 commit 0c372d8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions gmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
OpINCA
OpDECA
OpDECX
OpDECY
OpADDA
OpMULA
OpMOVA
Expand Down Expand Up @@ -68,6 +69,7 @@ var opcodes = map[string]Word{
"INCA": OpINCA,
"DECA": OpDECA,
"DECX": OpDECX,
"DECY": OpDECY,
"ADDA": OpADDA,
"MULA": OpMULA,
"MOVA": OpMOVA,
Expand Down Expand Up @@ -134,6 +136,8 @@ func (g *Machine) Run() {
g.A--
case OpDECX:
g.X--
case OpDECY:
g.Y--
case OpADDA:
switch g.Next() {
case RegX:
Expand Down
14 changes: 14 additions & 0 deletions gmachine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ func TestDECX(t *testing.T) {
}
}

func TestDECY(t *testing.T) {
t.Parallel()
g := gmachine.New(nil)
g.Y = 1
var wantY gmachine.Word = 0
err := assembleAndRunFromString(g, "DECY")
if err != nil {
t.Fatal("didn't expect an error", err)
}
if wantY != g.Y {
t.Errorf("want Y value %d, got %d", wantY, g.Y)
}
}

func TestSETA(t *testing.T) {
t.Parallel()
g := gmachine.New(nil)
Expand Down
2 changes: 1 addition & 1 deletion testdata/gc.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ SETA 42
OUTA

-- want --
0000000 0000 0000 0000 0a00 0000 0000 0000 2a00
0000000 0000 0000 0000 0b00 0000 0000 0000 2a00
0000010 0000 0000 0000 0300
0000018
1 change: 1 addition & 0 deletions token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var opcodes = map[string]TokenType{
"INCA": OPCODE,
"DECA": OPCODE,
"DECX": OPCODE,
"DECY": OPCODE,
"ADDA": OPCODE,
"MULA": OPCODE,
"MOVA": OPCODE,
Expand Down
1 change: 1 addition & 0 deletions token/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func TestLookupIdent(t *testing.T) {
{"INCA", token.OPCODE},
{"DECA", token.OPCODE},
{"DECX", token.OPCODE},
{"DECY", token.OPCODE},
{"ADDA", token.OPCODE},
{"MULA", token.OPCODE},
{"MOVA", token.OPCODE},
Expand Down

0 comments on commit 0c372d8

Please sign in to comment.