Question: Can someone please help me with this code? import java.io.*; import jimport java.io.*; import java.util.*; public class Lab7 { public static String pad(int n, int

Can someone please help me with this code?

import java.io.*; import jimport java.io.*; import java.util.*;

public class Lab7 { public static String pad(int n, int w) { n = String.valueOf(n).length(); int ZEROS=4; int intArray[] = new int[ZEROS]; String str= String.valueOf(n);

for (int i=0; i { intArray[ZEROS - n + i] = Integer.parseInt(str.substring(i, i+1)); }

}

//determine length of 'n'.

// calculate number of leading 0's to pad with

//create and return string of leading 0's and 'n'

static void readSrc(String fname) throws IOException { //for each line of assembly code: { //skip any lines of length zero or starting with '#' // tokenize string. 1st token is operator, 2nd is operand // If operand is invalid, display error and abort. // If operator is invalid, display error and abort. // convert string operator to numeric form. // output opcode and operand, each padded to two characters. }

}

public static void main(String argv[]) throws IOException { if (argv.length !=1) { System.out.println("usage: java Assemble INPUTFILE"); System.exit(0);

} readSrc(argv[0]); } }

The operator string in this program has to be the following:

String operator = { "HALT", "ADD", "SUB", "MLT", "DIV", "ILOAD","LOAD","STOR","READ","WRITE","BR","BZ","BN","DUMP"}

# HALT = 0; stop program

# ADD = 1; GPREG is updated with itself + MEMORY[arg]

# SUB = 2; GPREG is updated with itself - MEMORY[arg]

# MLT = 3; GPREG is updated with itself * MEMORY[arg]

# DIV = 4; GPREG is updated with itself / MEMORY[arg]

# ILOAD = 5; arg to GPREG # LOAD = 6; MEMORY[arg] to GPREG

# STOR = 7; GPREG to MEMORY[arg]

# READ = 8; keyboard to MEMORY[arg]

# WRITE = 9; MEMORY[arg] to screen

# BR = 10; unconditional branch to instruction at MEMORY[arg]

# BZ = 11; branch if GPREG is zero

# BN = 12; branch if GPREG is nonzero

# DUMP = 13; dump memory/register contents

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!