From b5300d5ac415c8db67eaad86cb2624f192d7dd15 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Mon, 31 Oct 2022 15:54:09 -0400 Subject: [PATCH] I forgot what exactly I changed --- marcie.go | 10 ++++++++++ masm/main.go | 1 + 2 files changed, 11 insertions(+) diff --git a/marcie.go b/marcie.go index 4a177a8..ba6ebb7 100644 --- a/marcie.go +++ b/marcie.go @@ -31,6 +31,7 @@ const ( JUMPI Opcode = 0xC LOADI Opcode = 0xD STOREI Opcode = 0xE + MOD Opcode = 0xF ) // Instruction provides a convenient way to create an instruction word @@ -158,6 +159,15 @@ func (machine *Machine) Execute (offset int16) (err error) { // Store indirect: Use X the value at X as the address // of where to store the value machine.memory[memoryValue] = machine.accumulator + + case MOD: + // Set AC to the remainder of AC divided by the value at + // X + if memoryValue == 0 { + machine.accumulator = 0 + } else { + machine.accumulator %= memoryValue + } default: err = ErrorUnknownInstruction diff --git a/masm/main.go b/masm/main.go index 1e09fca..225a11d 100644 --- a/masm/main.go +++ b/masm/main.go @@ -38,6 +38,7 @@ var mnemonics = map[string] marcie.Opcode { "jumpi": marcie.JUMPI, "loadi": marcie.LOADI, "storei": marcie.STOREI, + "mod": marcie.MOD, "org": ORG, }