Find Jobs
Hire Freelancers

MiniJava..

€8-30 EUR

Închis
Data postării: peste 4 ani în urmă

€8-30 EUR

Plata la predare
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.
ID-ul proiectului: 22690778

Despre proiect

3 propuneri
Proiect la distanță
Activ: 4 ani în urmă

Vrei să câștigi bani?

Avantajele de a licita pe platforma Freelancer

Stabilește bugetul și intervalul temporal
Îți primești plata pentru serviciile prestate
Evidențiază-ți propunerea
Te înregistrezi și licitezi gratuit pentru proiecte
3 freelanceri plasează o ofertă medie de €42 EUR pentru proiect
Avatarul utilizatorului
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 în 3 zile
0,0 (0 recenzii)
0,0
0,0
Avatarul utilizatorului
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 în 1 zi
0,0 (0 recenzii)
0,0
0,0

Despre client

Steagul GERMANY
Munich, Germany
3,9
4
Metoda de plată a fost confirmată
Membru din nov. 22, 2019

Verificarea clientului

Mulțumim! Ți-am trimis prin e-mail linkul pe care trebuie să-l accesezi pentru a revendica creditul gratuit.
A apărut o eroare la trimiterea e-mailului. Încearcă din nou.
Utilizatori înregistrați Totalul proiectelor postate
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Se încarcă previzualizarea
S-a oferit permisiunea de depistare a locației.
Ți-a expirat sesiunea pentru conectare sau te-ai deconectat. Conectează-te din nou.