Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help to write a java code for this lab: (Thanks) CS 13 Virtual Machine Proi

ID: 3601759 • Letter: N

Question

Need help to write a java code for this lab:

(Thanks)

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.

Explanation / Answer

class JavaClass: public JavaClassFileFormat { public: JavaClass(void); virtual ~JavaClass(void); public: virtual BOOL LoadClassFromFile(CString lpszFilePath); void SetByteCode(void* pByteCode); BOOL ParseClass(void); BOOL ParseInterfaces(char* &p); BOOL ParseFields(char* &p); BOOL ParseMethods(char* &p); BOOL ParseAttributes(char* &p); BOOL GetConstantPool(u2 nIndex, cp_info& const_pool); BOOL GetStringFromConstPool(int nIndex,CString& strValue); CString GetName(void); CString GetSuperClassName(void); BOOL ParseMethodCodeAttribute(int nMethodIndex, Code_attribute* pCode_attr); int GetMethodIndex(CString strMethodName, CString strMethodDesc, JavaClass* &pClass); int GetFieldIndex(CString strName, CString& strDesc); void SetClassHeap(ClassHeap *pClassHeap){this->m_pClassHeap=pClassHeap;} virtual u4 GetObjectSize(void); virtual u4 GetObjectFieldCount(void); JavaClass* GetSuperClass(void); BOOL CreateObject(u2 index, ObjectHeap *pObjectHeap, Object& object); BOOL CreateObjectArray(u2 index, u4 count, ObjectHeap *pObjectHeap, Object& object); private: size_t m_nByteCodeLength; void *m_pByteCode; u2 m_nObjectFieldsCount; BOOL ParseConstantPool(char* &p); int GetConstantPoolSize(char* p); ClassHeap *m_pClassHeap; };

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote