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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!