Question
Write this in Scala. Create a worksheet called accumulator. Implement Accumulator and any other classes, objects, or traits you may need. Test your implementation with
Write this in Scala. Create a worksheet called accumulator.
Implement Accumulator and any other classes, objects, or traits you may need.
Test your implementation with these samples:
// computing ((3 * 5) + 1) * 2 Accumulator.program = List(Add(3), Mul(5), Add(1), Mul(2)) Accumulator.run() Accumulator.register //> res6: Int = 32 // computing (((10 * 2) + 3) * 5) Accumulator.register = 0 Accumulator.program = List(Add(10), Mul(2), Add(3), Mul(5)) Accumulator.run() Accumulator.register //> res7: Int = 115
Add a Halt instruction to the accumulator in instruction set. When executed, this instruction sets the HALT flag. The HALT flag is a new variable. When set to true program execution immediately stops.
Add a Goto(arg) instruction to the accumulator in instruction set. When executed, this instruction sets the instruction pointer (IP) to arg. IP is a new variable that contains the index of the next instruction in the program to be executed.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started