Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 724303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:12:25+00:00 2026-05-14T06:12:25+00:00

So for my programming class we have had a project to create a virtual

  • 0

So for my programming class we have had a project to create a virtual machine including a memory unit, cpu, Input, Output, Instruction Register, Program Counter, MAR, MDR and so on. Now we need to create a compiler using Java Code that will take a .exe file written in some txt editor and convert it to java byte code and run the code. The code we will be writing in the .exe file is machine code along the lines of:

IN X
IN Y
ADD X
STO Y
OUT Y
STOP
DC X 0
DC Y 0

I am just a beginner and only have 2 days to write this and am very lost and have no idea where to start….Any Help will be much appreciated. Thanks

Ok seeing no one really understands I will clarify……I am in my first year programming course and my teacher had us make a Virtual Machine which I have done and I will post the code for the CPU and Computer Classes but my teacher is very unorganized and we have run out of time for the last project which is the compiler…..The code above is just an example of the code that will be turned into byte code…here is the code for CPU and Computer in my Virtual Machine Package…

class Cpu{
    private MemEl acc;
    private InstReg ir;
    private ProgCount pc;
    private Input in;
    private OutPut out;
    private MemEl mdr;
    private MemEl mar;
    public Cpu()
    {
        pc = new ProgCount();
        ir = new InstReg();
        acc = new MemEl();
    }
    public Boolean stop()
    {
        return ir.getOpcode() == 0;
    }
    public int getMAR()
    {
        return ir.getOpcode();
    }
    public int getMDR()
    {
        return mdr.read();
    }
    public void setMDR(int n)
    {
        mdr.write(n);
    }
    public boolean OutFlag()
    {
        return ir.getOpcode() == 8;
    }
    public boolean InFlag()
    {
        return ir.getOpcode() == 7;
    }
    public boolean StoreFlag()
    {
        return ir.getOpcode() == 2;
    }
 public void fetch()
    {
        mar.write(pc.getValue());
        pc.plus();
    }
    public void reset()
    {
        mar.write(0);
        pc.write(0);
        pc.write(1);
    }
    public void fetch2()
    {
        ir.write(mdr.read());
    }
    public void decode()
    {
        mar.write(ir.getOperand());
        mdr.write(acc.read());
    }
 public void execute()
    {

        switch(ir.getOpcode()){
        case 0:
            System.out.println("Complete");
            break;
        case 1:
            acc.write(mdr.read());
            break;
        case 2:
            acc.write(ir.getOperand());
            break;
        case 3:
            acc.write(acc.read() + mdr.read());
            break;
        case 4:
            acc.write(acc.read() - mdr.read());
            break;
 case 5:
            acc.write(acc.read() * mdr.read());
            break;
        case 6:
            acc.write(acc.read() / mdr.read());
            break;
        case 7:
            mar.write(ir.getOperand());
            break;
        case 8:
            System.out.println(getMDR());
            break;
        case 9:
            pc.write(getMDR());
            break;
        case 10:
            if(0 == acc.read())
                pc.write(getMDR());
            else
                fetch();
            break;
        case 11:
            if(0 < acc.read())
                pc.write(getMDR());
            else
                fetch();
            break;
        }

    }

Here is my Computer Class

import java.io.*;
class Computer{
    private Cpu cpu;
    private Input in;
    private OutPut out;
    private Memory mem;
    public Computer() throws IOException
    {
        Memory mem = new Memory(100);
        Input in = new Input();
        OutPut out = new OutPut();
        Cpu cpu = new Cpu();
        System.out.println(in.getInt());
    }
    public void run() throws IOException
    {
        cpu.reset();
        cpu.setMDR(mem.read(cpu.getMAR()));
        cpu.fetch2();
        while (!cpu.stop())
            {
                cpu.decode();
                if (cpu.OutFlag())
                    OutPut.display(mem.read(cpu.getMAR()));
                if (cpu.InFlag())
                    mem.write(cpu.getMDR(),in.getInt());
                if (cpu.StoreFlag())
                    {
                        mem.write(cpu.getMAR(),in.getInt());
                        cpu.getMDR();
                    }
                else
                    {
                        cpu.setMDR(mem.read(cpu.getMAR()));
                        cpu.execute();
                        cpu.fetch();
                        cpu.setMDR(mem.read(cpu.getMAR()));
                        cpu.fetch2();
                    }
            }
    }
public void load()
    {
        mem.write(0,799);
        mem.write(1,199);
        mem.write(2,1009);
        mem.write(3,398);
        mem.write(4,298);
        mem.write(5,199);
        mem.write(6,497);
        mem.write(7,299);
        mem.write(8,902);
        mem.write(9,898);
        mem.write(97,0);
        mem.write(98,0);
        mem.write(99,1);
    }

}

The Load method is just a temporary method, just to see if the machine works…what it will load is bytecode formed by the compiler.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T06:12:25+00:00Added an answer on May 14, 2026 at 6:12 am

    This seems pretty ambitious based on your question and the time you have to do it, but I’ll try to put you on the right track. Obviously, since it’s homework no one will just give you the answer 😉

    The code in your example would more accurately be termed “assembly code”. Look at it this way; you have to:

    • Read in each line
    • Look at the first “word” (instruction or operator) and equate that to a Java bytecode. Look here.
    • Figure out how many arguments (operands) should be read in for the operator.
    • Make sure the rest of the line contains the appropriate number of operands.
    • Write out the bytecode in the proper order according to the Java spec.
    • Load the bytecode into the VM and run it

    The assembly code in your example looks like it has some explicit rules that the instructor probably gave to you. For instance, “ADD X” means add the contents of location X to — what? Does “IN” mean “input” or “increment”? “STO Y” means store something to location Y — what? It seems like maybe there’s an implicit register that holds results. That should be part of the instructor’s specification, too. Good luck! Get hacking!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.