Đã Đóng

MiniJava..

We want to develop a simulator for a subset of the MiniJVM code. The following commands are to be implemented:

arithmetic operations: ADD, SUB

Loading constants: CONST i

Allocate storage space ALLOC i

Load/Store: LOAD i, STORE i

Comparison operators: LESS

Jump instructions: JUMP i, FJUMP i

End of program: STOP

Each operation is to be implemented in its own class, which inherits from the abstract class Instruction. A simulator has an array of instructions code and a stack. The stack stores int-values. For the sake of simplicity, this task uses ints as an internal representation of truth values. The stack of the simulators has a fixed capacity, which is defined during instantiation. The stackPointer of the stack points to the uppermost occupied cell. In addition, an instance of Simulator has a programCounter that stores the index of the next command to be executed and holds an attribute that stores whether a HALT was executed.

The files are already present in the template. The abstract class Instruction is already defined like the classes Simulator and Stack. Edit the following tasks:

Create the classes for the instructions in the predefined files. Select the class names so that they match the predefined file name. The classes should inherit from the abstract class Instruction.

The objects of the classes that represent the instructions for CONST i, ALLOC i, LOAD i, STORE i, JUMP i, FJump i should each have an int attribute that stores the parameter i of the command. In the classes for each of these commands, create a public constructor that expects an int parameter and initializes the respective attribute with it.

For each concrete class of instructions, implement the method public void execute(Simulator simulator), which changes the stack according to the command. The behavior of execute(...) for the different instructions is as follows:

ADD: Takes the two top elements from the stack and sets the result of the addition on the stack.

SUB: Takes the two top elements a, b from the stack and sets the result of b - a to the stack.

CONST i: Loads the constant i to the stack.

ALLOC i: Increases the stack pointer by i. You can use Stack's alloc method to do this.

LOAD i: Reads the value from the index i of the stack and places it on the stack.

STORE i: Takes the top value from the stack and stores it at index i of the stack.

LESS: Takes the two uppermost elements a, b from the stack and places the result of the comparison b < a as int coded on the stack. The truth value true should be coded by a 1, the truth value false by a 0.

JUMP i is to implement a jump to the command at index i.

FJump i Takes the top element of the stack. If the value of this element is 0, a jump to the command at index i is to be executed. Otherwise no jump is executed and the program flow continues normally.

HALT is to terminate the program. The halted attribute of the simulator should be set to true.

Hints:

To access the stack of the simulator instance, use the getStack() object method.

In particular, a stack instance has the following methods that you can use during implementation:

pop() : Returns the element at the stack pointer and decrements the stack pointer.

push(int value): Increments the stack pointer by one and stores value at the new index of the stack pointer.

alloc(int count): Increases the stack pointer by count.

setValueAtIndex(int index, int value): Sets the value at index to value.

The program counter of the simulator can be set with setProgrammCounter(...).

You can assume that the stack sizes and instruction sequences of the MiniJVM code that are tested with will not produce stack overflow or stack underflow when correctly implemented.

Do not change the code of instruction, stack and simulator.

Kĩ năng: Java

Xem nhiều hơn: comparison shopping use, constant scroll script, joomla price comparison, book price comparison, constant contact custom template guidelines, odds comparison webmasters, truck loads biding, hi i am looking for someone to craft our pdf documents in word we will send you 200 k version of documents hi i am looking for s, we are going to build a web based application for tesla model s browser, we need website development with complete responsive designing please open this url : http://collegeduniacom/ we need same to s, are you a freelancer we re looking for you st john s jobs graphic web design, freelance writers are you needing articles we have loads for you to write inner city cbd&bruma, how many p's do we have in marketer, we want you template, We are looking for an Animation studio who can create awesome 3D animation for Children\ s Show., We need advertising images (.jpg) for a new product we are offering. It\ s a box of dog, We are looking for an Cisco Engineer to rebuild UC650 from grand up we hae all the tools and S/W asvialable, We have a site that\ s in the alpha stage that we would like to enhance and design some new views on. Goals are:, We need a website built preferably on Wordpress with shopify add to cart buttons, but if you know how to implement a design on S, We need a website built preferably on Wordpress with s

Về Bên Thuê:
( 2 nhận xét ) Munich, Germany

ID dự án: #22690778

4 freelancer đang chào giá trung bình €37 cho công việc này

RushService

Feel fee to contact me for .Shoot me message to discuss further more details .We provide the comments,images,videos,demos and live sessions in order to help the [login to view URL] payment only after the work [login to view URL] y Thêm

€30 EUR trong 3 ngày
(63 Nhận xét)
6.1
liujianmin

Great! How are you,sir? Thank you for visiting my proposal. I've just read your job post carefully and much interested in your project and I am sure I can complete this in time perfectly as you want. I'm full stack pro Thêm

€20 EUR trong 7 ngày
(11 Nhận xét)
3.6
ysc2011

Hello sir, i can help you working on your JVM simulator, i have experience in java, and i read the description of your problem

€67 EUR trong 3 ngày
(0 Nhận xét)
0.0
niwdoogleoj4

I'll complete your project satisfactorily. You will get quality work at an affordable price. I can start work right away. I will be looking forward to hearing from you. Thank you.

€30 EUR trong 1 ngày
(0 Nhận xét)
0.0