Question: Need help to write a java code for this lab. It's a tough one... Part 1 of this assignment: ________________________ import java.io.*; interface StackIntADT {

Need help to write a java code for this lab. It's a tough one...

Need help to write a java code for this lab. It's a

tough one... Part 1 of this assignment: ________________________ import java.io.*; interface StackIntADT

{ public void push(int element); public int pop(); public int peek(); public

boolean isEmpty(); public boolean isFull(); public int size(); } public class IntStack

Part 1 of this assignment: ________________________

import java.io.*;

interface StackIntADT { public void push(int element); public int pop(); public int peek(); public boolean isEmpty(); public boolean isFull(); public int size(); } public class IntStack implements StackIntADT { int stk_size; int stk_arr[]; int top = -1; IntStack() //Default Construtor to set the stack size to 10; { stk_size = 10; stk_arr = new int[stk_size]; } IntStack(int size) //Parameterized Construtor to set the stack size to the value passed at driver ; { stk_size = size; stk_arr = new int[stk_size]; } public void push(int element) { //if (top == stk_arr.length - 1) if(isFull()) //Checking for stack full or not { System.out.println("Stack is Full"); } else { top++; stk_arr[top] = element; System.out.println(stk_arr[top] + " IS PUSHED."); } } public int pop() { //if (top

public boolean isFull() { if(top == stk_size - 1) return true; else return false; } public void display() { System.out.println("THE ELEMENTS IS STACK ARE: "); for(int i=0;i

CS 13 Virtual Machine Proiect Implement the a virtual machine for the instructions listed in the chart on page two Your VM class should have the following fields: Field Description Function Program Counter; type int Array of type int Operand and CPU stack Contains the address of the next instruction to fetch memory Contains instructions (a program) and stack Used for processing arithmetic instructions and storing return address The pc should be initialized to 0 so the first instruction is fetched from memory location zero. The memory should contain a sample machine language program. This program could be loaded from a text file, or you can directly initialize the memory array when it is created. The stack is the integer stack discussed in part 1 of this assignment. The stack should be properly initialized by its constructor. To execute the program in memory you will need a method that: 1. Fetches the instruction at the address contained in the pc 2. Increments the pc 3. Decodes the instruction. This is done with a switch statement. 4. Executes the instruction 5. Repeats this process until a HALT is 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!