Are You Looking For Simulate Operation of SIMMAC Assignment Help Service – Visit Expertsminds!!

Home   Course   Nova Southeastern University Assignment Help
Previous << || >> Next

CISC640 Operating Systems Assignment - OS Problem Set, Nova Southeastern University, USA

Introduction - Create a virtual machine/operating system for the machine described below that will accept programs in the target machine language.

Project Description - Design and implement a program to simulate the operation of the SIMMAC. You will design and implement the ability for each running process to participate in a system level job switch.

ARE YOU LOOKING FOR RELIABLE CISC640 OPERATING SYSTEMS ASSIGNMENT HELP SERVICES? EXPERTSMINDS.COM IS RIGHT CHOICE AS YOUR STUDY PARTNER!

Answer -

Instruction.java

package simmac;

public class Instruction {

public static final int DW = 0x0000;

public static final int ADD = 0x0001;

public static final int SUB = 0x0002;

public static final int LDA = 0x0003;

public static final int LDI = 0x0004;

public static final int STR = 0x0005;

public static final int BRH = 0x0006;

public static final int CBR = 0x0007;

public static final int HLT = 0x0008;

/* if the given word corresponds to a valid opcode returns the numerical opcode, if it is not a valid opcode returns -1*/

public static int getOpcode(String word){

String opcode=word.toUpperCase();

switch (opcode) {

case "DW":

return DW;

case "ADD":

return ADD;

case "SUB":

return SUB;

case "LDA":

return LDA;

case "LDI":

return LDI;

case "STR":

return STR;

case "BRH":

return BRH;

case "CBR":

return CBR;

case "HALT":

return HLT;

default:

return -1;

}

}

/* if the string operand corresponds to a valid operand for the opcode it returns the numerical value, otherwise it returns null */

private static Integer parseOperand(int opcode,String operand,String filename,int nline) {

switch(opcode) {

case ADD:

case SUB:

case LDA:

case STR:

case BRH:

case CBR:

if (operand.matches("\\d+")) { // if it's a valid unsigned number

int val=Integer.parseInt(operand);

if(val>=0 && val<32767) // if it's at most 16 bits

return val;

else {

System.out.println("Error ["+filename+"("+nline+ ")]: the number: "+operand+" is longer than 16 bits.");

return null;

}

}

else {

System.out.println("Error ["+filename+"("+nline+ ")]: invalid number: "+operand+".");

return null;

}

case DW:

if (operand.matches("[+-]?\\d+")) {

int val=Integer.parseInt(operand);

return val;

}

else {

System.out.println("Error ["+filename+"("+nline+ ")]: invalid integer number: "+operand+".");

return null;

}

case LDI:

if (operand.matches("[+-]?\\d+")) {

int val=Integer.parseInt(operand);

if(val>=-32768 && val<32767)

return val;

else {

System.out.println("Error ["+filename+"("+nline+ ")]: the number: "+operand+" is longer than 16 bits.");

return null;

}

}

else {

System.out.println("Error ["+filename+"("+nline+ ")]: invalid integer number: "+operand+".");

return null;

}

default:

return null;

}

}

/* parses the given line and determines if it corressponds to a valid SIMMAC instruction */

public static Integer parseInstruction(String line,String filename,int nline) {

String [] parts= line.split("\\s+");

if(parts.length>2) {

System.out.println("Error ["+filename+"("+nline+ ")]: a SIMMAC instruction can only contain one opcode and one operand.");

return null;

}

if(parts[0].length()==0) {

System.out.println("Error ["+filename+"("+nline+ ")]: a SIMMAC instruction can only contain one opcode and one operand.");

return null;

}

int opc= getOpcode(parts[0]);

if (opc==-1) {

System.out.println("Error ["+filename+"("+nline+ ")]: invalid instruction opcode: "+parts[0]+".");

return null;

}

if(opc==HLT) {

if(parts.length>1) {

System.out.println("Error ["+filename+"("+nline+ ")]: invalid operand for HALT instruction. HALT requires no operands.");

return null;

}

return (opc << 16);

}

else {

if(parts.length!=2) {

System.out.println("Error ["+filename+"("+nline+ ")]: SIMMAC instructions other than HALT must contain an opcode and an operand.");

return null;

}

Integer op=parseOperand(opc,parts[1],filename,nline);

if(op==null)

return null;

return ((opc << 16)| op);

}

}

}

ORDER NEW SIMULATE OPERATION OF SIMMAC ASSIGNMENT & GET 100% ORIGINAL SOLUTION AND QUALITY WRITTEN CONTENTS IN WELL FORMATS AND PROPER REFERENCING.

MAIN.JAVA

package simmac;

import java.io.File;

import java.io.FileNotFoundException;

import java.util.ArrayList;

import java.util.Scanner;

public class Instruction {

public static final int DW = 0x0000;

public static final int ADD = 0x0001;

public static final int SUB = 0x0002;

public static final int LDA = 0x0003;

public static final int LDI = 0x0004;

public static final int STR = 0x0005;

public static final int BRH = 0x0006;

public static final int CBR = 0x0007;

public static final int HLT = 0x0008;

/* if the given word corresponds to a valid opcode returns the numerical opcode, if it is not a valid opcode returns -1*/

public static int getOpcode(String word){

String opcode=word.toUpperCase();

switch (opcode) {

case "DW":

return DW;

case "ADD":

return ADD;

case "SUB":

return SUB;

case "LDA":

return LDA;

case "LDI":

return LDI;

case "STR":

return STR;

case "BRH":

return BRH;

case "CBR":

return CBR;

case "HALT":

return HLT;

default:

return -1;

}

}

/* if the string operand corresponds to a valid operand for the opcode it returns the numerical value, otherwise it returns null*/

private static Integer parseOperand(int opcode,String operand,String filename,int nline) {

switch(opcode) {

case ADD:

case SUB:

case LDA:

case STR:

case BRH:

case CBR:

if (operand.matches("\\d+")) { // if it's a valid unsigned number

int val=Integer.parseInt(operand);

if(val>=0 && val<32767) // if it's at most 16 bits

return val;

else {

System.out.println("Error ["+filename+"("+nline+ ")]: the number: "+operand+" is longer than 16 bits.");

return null;

}

}

else {

System.out.println("Error ["+filename+"("+nline+ ")]: invalid number: "+operand+".");

return null;

}

case DW:

if (operand.matches("[+-]?\\d+")) {

int val=Integer.parseInt(operand);

return val;

}

else {

System.out.println("Error ["+filename+"("+nline+ ")]: invalid integer number: "+operand+".");

return null;

}

case LDI:

if (operand.matches("[+-]?\\d+")) {

int val=Integer.parseInt(operand);

if(val>=-32768 && val<32767)

return val;

else {

System.out.println("Error ["+filename+"("+nline+ ")]: the number: "+operand+" is longer than 16 bits.");

return null;

}

}

else {

System.out.println("Error ["+filename+"("+nline+ ")]: invalid integer number: "+operand+".");

return null;

}

default:

return null;

}

}

/* parses the given line and determines if it corressponds to a valid SIMMAC instruction */

public static Integer parseInstruction(String line,String filename,int nline) {

String [] parts= line.split("\\s+");

if(parts.length>2) {

System.out.println("Error ["+filename+"("+nline+ ")]: a SIMMAC instruction can only contain one opcode and one operand.");

return null;

}

if(parts[0].length()==0) {

System.out.println("Error ["+filename+"("+nline+ ")]: a SIMMAC instruction can only contain one opcode and one operand.");

return null;

}

int opc= getOpcode(parts[0]);

if (opc==-1) {

System.out.println("Error ["+filename+"("+nline+ ")]: invalid instruction opcode: "+parts[0]+".");

return null;

}

if(opc==HLT) {

if(parts.length>1) {

System.out.println("Error ["+filename+"("+nline+ ")]: invalid operand for HALT instruction. HALT requires no operands.");

return null;

}

return (opc << 16);

}

else {

if(parts.length!=2) {

System.out.println("Error ["+filename+"("+nline+ ")]: SIMMAC instructions other than HALT must contain an opcode and an operand.");

return null;

}

Integer op=parseOperand(opc,parts[1],filename,nline);

if(op==null)

return null;

return ((opc << 16)| op);

}

}

}

public class Main {

/* open a SIMMAC program file and parse its contents, if everything is fine returns an array with all the instructions */

public static int [] readProgramFile(String filename) {

try {

Scanner s = new Scanner(new File(filename));

ArrayList<Integer> instructions = new ArrayList();

int nline = 1;

while (s.hasNext()){

String line=s.nextLine().trim();

if(line.length()>0)

{

Integer inst=Instruction.parseInstruction(line,filename,nline); // parse the instruction contained in the current line

if (inst != null) { // if the instruction was valid

instructions.add(inst);

}

else

System.exit(0);

}

nline++;

}

s.close();

int [] instr = new int[instructions.size()];

for(int i=0; i<instructions.size(); i++)

instr[i]=instructions.get(i);

return instr; // success, return the instruction list

} catch (FileNotFoundException e) {

System.out.println("Error: program file " + filename + " could not be opened.");

System.exit(0); //failure

}

return null;

}

/**

* @param args the command line arguments */

public static void main(String[] args) {

System.out.print("Please enter the time quantum value: "); // ask for the filename to use

Scanner s = new Scanner(System.in);

int quantum = s.nextInt();

SIMMAC cpu = new SIMMAC();

OperatingSystem os = new OperatingSystem(cpu,quantum);

if(args.length==0) {

boolean done=false;

ArrayList<String> filenames=new ArrayList();

while(!done) {

System.out.print("Please enter a program filename to load: "); // ask for the filename to use

filenames.add(s.next());

System.out.print("Do you want to load another file? (Y/N): ");

String c=s.next();

if(c.toUpperCase().equals("N") || !c.toUpperCase().equals("Y"))

done=true;

}

for(int i=0; i<filenames.size(); i++) {

int [] program = readProgramFile(filenames.get(i));

os.loadProgram(program);

}

}

else {

for(int i=0; i<args.length; i++)

{

int [] program = readProgramFile(args[i]);

os.loadProgram(program);

}

}

os.run(); // run the processes

}

}

//OperatingSystem.java

class OperatingSystem {

ArrayList<Process> readyQueue; // queue of processes ready to run

Process currentProcess; // process currently being executed

SIMMAC cpu; // cpu used to execute the processes

int quantum; // value of the time quantum

int lastLoadAddress; // address to load a program

int clock;

public OperatingSystem(SIMMAC cpu,int quantum) {

this.cpu=cpu;

this.quantum=quantum;

lastLoadAddress=0;

readyQueue=new ArrayList();

currentProcess=null;

clock=0;

}

/* prints the ready process queue */

public void printProcesses() {

System.out.print("Process queue: ");

System.out.print("[ ");

for(int i=0; i<readyQueue.size(); i++)

{

if(i>0)

System.out.print(", ");

System.out.print(readyQueue.get(i).procid);

}

System.out.println(" ]");

}

/* Switch the current process for another from the ready queue */

public void switchProcess() {

if(currentProcess!=null) {

currentProcess.ACC = cpu.ACC; // save current register state

currentProcess.PSIAR = cpu.PSIAR;

readyQueue.add(currentProcess);

}

currentProcess=readyQueue.remove(0); // get process from queue

cpu.ACC=currentProcess.ACC; // load register state

cpu.PSIAR=currentProcess.PSIAR;

cpu.memoryLimit = currentProcess.memoryLimit; // load memory limits

cpu.memoryBase = currentProcess.memoryBase;

clock = 0; // restart clock count

System.out.println("\nSwitching process.");

System.out.println("Next process ID: "+currentProcess.procid);

printProcesses();

System.out.println();

}

/* Run the loaded processes in an loop until all are executed or an error happens*/

public void run() {

boolean terminate = false;

currentProcess=null;

switchProcess(); // load first process

while(!terminate)

{

boolean exitStatus = cpu.executeInstruction();

clock++;

if(exitStatus==true) { // it the process was terminated

if(readyQueue.size()>0)

{

currentProcess=null; // invalidate current process

switchProcess(); // forced swap to a different process

}

else

terminate=true; // no more processes, exit the program

}

if(clock>=quantum && !terminate) {

switchProcess();

}

}

}

/* load a SIMMAC program to memory */

void loadProgram(int [] program) {

int startAddress=lastLoadAddress;

if (lastLoadAddress + program.length >= cpu.MEMORY_SIZE) {

System.out.println("Error: cannot load program, program size exceeds memory size.");

System.exit(0);

}

for (int i=0; i<program.length; i++)

cpu.Memory[lastLoadAddress+i] = program[i];

lastLoadAddress+=program.length;

Process process= new Process(startAddress,program.length,readyQueue.size());

readyQueue.add(process);

}

}

// Definition of a process control block

class Process {

public int procid;

public int ACC;

public int PSIAR;

public int memoryBase;

public int memoryLimit;

public Process(int address,int size,int procid) {

this. procid=procid;

ACC = 0;

PSIAR = 0;

memoryBase = address;

memoryLimit=address+size;

}

}

class SIMMAC {

public final int MEMORY_SIZE = 512;

public int Memory[];

public int memoryBase; // starting address for current process

public int memoryLimit; // maximum address allowed for current process

// registers

public int ACC; // accumulator

public int PSIAR; // Primary Storage Instruction Address Register

int SAR; // Storage Address Register

int SDR; // Storage Data Register

int TMPR; // Temporary Register

int CSIAR; // Control Storage Instruction Address Register

int IR; // Instruction Register

int MIR; // Micro-instruction Register

public SIMMAC() {

Memory=new int [MEMORY_SIZE];

CSIAR = 0;

PSIAR = 0;

ACC = 0;

memoryLimit=MEMORY_SIZE;

memoryBase=0;

}

/* read from memory using the SAR register, if an error was found returns true */

boolean read() {

if(SAR+memoryBase>=0 && SAR+memoryBase<memoryLimit) {

SDR=Memory[memoryBase+SAR];

return false;

}

else

return true;

}

/* write to memory using the SAR register, if an error was found returns true */

boolean write() {

if(SAR+memoryBase>=0 && SAR+memoryBase<memoryLimit) {

Memory[memoryBase+SAR]=SDR;

return false;

}

else

return true;

}

boolean fetch() {

SAR = PSIAR;

if(read())

return true;

IR = SDR;

SDR = IR & 0xFFFF;

CSIAR = IR >> 16;

return false;

}

boolean add() {

TMPR = ACC;

ACC = PSIAR + 1;

PSIAR = ACC;

ACC = TMPR;

TMPR = SDR;

SAR = TMPR;

if(read())

return true;

TMPR = SDR;

ACC = ACC + TMPR;

CSIAR = 0;

return false;

}

boolean sub() {

TMPR = ACC;

ACC = PSIAR + 1;

PSIAR = ACC;

ACC = TMPR;

TMPR = SDR;

SAR = TMPR;

if(read())

return true;

TMPR = SDR;

ACC = ACC - TMPR;

CSIAR = 0;

return false;

}

boolean load() {

TMPR = ACC;

ACC = PSIAR + 1;

PSIAR = ACC;

ACC = TMPR;

TMPR = SDR;

SAR = TMPR;

if(read())

return true;

ACC = SDR;

CSIAR = 0;

return false;

}

boolean store() {

TMPR = ACC;

ACC = PSIAR + 1;

PSIAR = ACC;

ACC = TMPR;

TMPR = SDR;

SAR = TMPR;

SDR = ACC;

if(write())

return true;

CSIAR = 0;

return false;

}

boolean branch() {

PSIAR = SDR;

CSIAR = 0;

return false;

}

boolean conditionalBranch() {

if (ACC==0) {

PSIAR = SDR;

CSIAR = 0;

}

else {

TMPR = ACC;

ACC = PSIAR + 1;

PSIAR = ACC;

ACC = TMPR;

CSIAR = 0;

}

return false;

}

boolean loadImmediate() {

ACC = PSIAR + 1;

PSIAR = ACC;

ACC = SDR;

CSIAR = 0;

return false;

}

/* print the contents of all the registers and all memory */

public void dump() {

System.out.printf("Register contents:\n");

System.out.printf("ACC = %08X\tPSIAR = %04X\tSAR = %04X\tSDR = %08X\n",ACC,PSIAR,SAR,SDR);

System.out.printf("TMPR = %08X\tCSIAR = %04X\tIR = %04X\tMIR = %04X\n",TMPR,CSIAR,IR,MIR);

System.out.printf("\nMemory contents:\n%03d: ",0);

for (int i=0; i<MEMORY_SIZE; i++) {

if(i!=0 && i%8==0)

System.out.printf("\n%03d: ",i);

System.out.printf("%08X ",Memory[i]);

}

System.out.println();

}

public boolean executeInstruction() {

boolean halt = false;

boolean error = false;

fetch();

switch(CSIAR) {

case Instruction.ADD:

error=add();

break;

case Instruction.SUB:

error=sub();

break;

case Instruction.LDA:

error=load();

break;

case Instruction.STR:

error=store();

break;

case Instruction.BRH:

error=branch();

break;

case Instruction.CBR:

error=conditionalBranch();

break;

case Instruction.LDI:

error=loadImmediate();

break;

case Instruction.HLT:

dump();

System.out.println("End of job.");

halt=true;

break;

default:

dump();

System.out.printf("Error: invalid instruction %04X.\nProgram terminated.\n",IR);

halt =true;

}

if(error) {

dump();

System.out.printf("Error: invalid memory address %04X.\nProgram terminated.\n",SAR);

}

return (halt || error); // return true if there was an error, false otherwise

}

}

SAVE YOUR HIGHER GRADE WITH ACQUIRING CISC640 OPERATING SYSTEMS ASSIGNMENT HELP & QUALITY HOMEWORK WRITING SERVICES OF EXPERTSMINDS.COM

MAIN1.JAVA

Main.java

package simmac;

import java.io.File;

import java.io.FileNotFoundException;

import java.util.ArrayList;

import java.util.Scanner;

public class Main {

/* open a SIMMAC program file and parse its contents, if everything is fine returns an array with all the instructions */

public static int [] readProgramFile(String filename) {

try {

Scanner s = new Scanner(new File(filename));

ArrayList<Integer> instructions = new ArrayList();

int nline = 1;

while (s.hasNext()){

String line=s.nextLine().trim();

if(line.length()>0)

{

Integer inst=Instruction.parseInstruction(line,filename,nline); // parse the instruction contained in the current line

if (inst != null) { // if the instruction was valid

instructions.add(inst);

}

else

System.exit(0);

}

nline++;

}

s.close();

int [] instr = new int[instructions.size()];

for(int i=0; i<instructions.size(); i++)

instr[i]=instructions.get(i);

return instr; // success, return the instruction list

} catch (FileNotFoundException e) {

System.out.println("Error: program file " + filename + " could not be opened.");

System.exit(0); //failure

}

return null;

}

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

System.out.print("Please enter the time quantum value: "); // ask for the filename to use

Scanner s = new Scanner(System.in);

int quantum = s.nextInt();

SIMMAC cpu = new SIMMAC();

OperatingSystem os = new OperatingSystem(cpu,quantum);

if(args.length==0) {

boolean done=false;

ArrayList<String> filenames=new ArrayList();

while(!done) {

System.out.print("Please enter a program filename to load: "); // ask for the filename to use

filenames.add(s.next());

System.out.print("Do you want to load another file? (Y/N): ");

String c=s.next();

if(c.toUpperCase().equals("N") || !c.toUpperCase().equals("Y"))

done=true;

}

for(int i=0; i<filenames.size(); i++) {

int [] program = readProgramFile(filenames.get(i));

os.loadProgram(program);

}

}

else {

for(int i=0; i<args.length; i++)

{

int [] program = readProgramFile(args[i]);

os.loadProgram(program);

}

}

os.run(); // run the processes

}

}

OperatingSystem.java

package simmac;

import java.util.ArrayList;

public class OperatingSystem {

ArrayList<Process> readyQueue; // queue of processes ready to run

Process currentProcess; // process currently being executed

SIMMAC cpu; // cpu used to execute the processes

int quantum; // value of the time quantum

int lastLoadAddress; // address to load a program

int clock;

public OperatingSystem(SIMMAC cpu,int quantum) {

this.cpu=cpu;

this.quantum=quantum;

lastLoadAddress=0;

readyQueue=new ArrayList();

currentProcess=null;

clock=0;

}

/* prints the ready process queue */

public void printProcesses() {

System.out.print("Process queue: ");

System.out.print("[ ");

for(int i=0; i<readyQueue.size(); i++)

{

if(i>0)

System.out.print(", ");

System.out.print(readyQueue.get(i).procid);

}

System.out.println(" ]");

}

/* Switch the current process for another from the ready queue */

public void switchProcess() {

if(currentProcess!=null) {

currentProcess.ACC = cpu.ACC; // save current register state

currentProcess.PSIAR = cpu.PSIAR;

readyQueue.add(currentProcess);

}

currentProcess=readyQueue.remove(0); // get process from queue

cpu.ACC=currentProcess.ACC; // load register state

cpu.PSIAR=currentProcess.PSIAR;

cpu.memoryLimit = currentProcess.memoryLimit; // load memory limits

cpu.memoryBase = currentProcess.memoryBase;

clock = 0; // restart clock count

System.out.println("\nSwitching process.");

System.out.println("Next process ID: "+currentProcess.procid);

printProcesses();

System.out.println();

}

/* Run the loaded processes in an loop until all are executed or an error happens*/

public void run() {

boolean terminate = false;

currentProcess=null;

switchProcess(); // load first process

while(!terminate)

{

boolean exitStatus = cpu.executeInstruction();

clock++;

if(exitStatus==true) { // it the process was terminated

if(readyQueue.size()>0)

{

currentProcess=null; // invalidate current process

switchProcess(); // forced swap to a different process

}

else

terminate=true; // no more processes, exit the program

}

if(clock>=quantum && !terminate) {

switchProcess();

}

}

}

/* load a SIMMAC program to memory */

void loadProgram(int [] program) {

int startAddress=lastLoadAddress;

if (lastLoadAddress + program.length >= cpu.MEMORY_SIZE) {

System.out.println("Error: cannot load program, program size exceeds memory size.");

System.exit(0);

}

for (int i=0; i<program.length; i++)

cpu.Memory[lastLoadAddress+i] = program[i];

lastLoadAddress+=program.length;

Process process= new Process(startAddress,program.length,readyQueue.size());

readyQueue.add(process);

}

}

NEVER LOSE YOUR CHANCE TO EXCEL IN SIMULATE OPERATION OF SIMMAC ASSIGNMENT - HIRE BEST QUALITY TUTOR FOR ASSIGNMENT HELP!

Process.java

Process.java

package simmac;

// Definition of a process control block

public class Process {

public int procid;

public int ACC;

public int PSIAR;

public int memoryBase;

public int memoryLimit;

public Process(int address,int size,int procid) {

this. procid=procid;

ACC = 0;

PSIAR = 0;

memoryBase = address;

memoryLimit=address+size;

}

}

DO YOU WANT TO EXCEL IN CISC640 OPERATING SYSTEMS ASSIGNMENT? HIRE TRUSTED TUTORS FROM EXPERTSMINDS AND ACHIEVE SUCCESS!

SIMMAC.JAVA

SIMMAC.java

package simmac;

public class SIMMAC {

public final int MEMORY_SIZE = 512;

public int Memory[];

public int memoryBase; // starting address for current process

public int memoryLimit; // maximum address allowed for current process

// registers

public int ACC; // accumulator

public int PSIAR; // Primary Storage Instruction Address Register

int SAR; // Storage Address Register

int SDR; // Storage Data Register

int TMPR; // Temporary Register

int CSIAR; // Control Storage Instruction Address Register

int IR; // Instruction Register

int MIR; // Micro-instruction Register

public SIMMAC() {

Memory=new int [MEMORY_SIZE];

CSIAR = 0;

PSIAR = 0;

ACC = 0;

memoryLimit=MEMORY_SIZE;

memoryBase=0;

}

/* read from memory using the SAR register, if an error was found returns true */

boolean read() {

if(SAR+memoryBase>=0 && SAR+memoryBase<memoryLimit) {

SDR=Memory[memoryBase+SAR];

return false;

}

else

return true;

}

/* write to memory using the SAR register, if an error was found returns true */

boolean write() {

if(SAR+memoryBase>=0 && SAR+memoryBase<memoryLimit) {

Memory[memoryBase+SAR]=SDR;

return false;

}

else

return true;

}

boolean fetch() {

SAR = PSIAR;

if(read())

return true;

IR = SDR;

SDR = IR & 0xFFFF;

CSIAR = IR >> 16;

return false;

}

boolean add() {

TMPR = ACC;

ACC = PSIAR + 1;

PSIAR = ACC;

ACC = TMPR;

TMPR = SDR;

SAR = TMPR;

if(read())

return true;

TMPR = SDR;

ACC = ACC + TMPR;

CSIAR = 0;

return false;

}

boolean sub() {

TMPR = ACC;

ACC = PSIAR + 1;

PSIAR = ACC;

ACC = TMPR;

TMPR = SDR;

SAR = TMPR;

if(read())

return true;

TMPR = SDR;

ACC = ACC - TMPR;

CSIAR = 0;

return false;

}

boolean load() {

TMPR = ACC;

ACC = PSIAR + 1;

PSIAR = ACC;

ACC = TMPR;

TMPR = SDR;

SAR = TMPR;

if(read())

return true;

ACC = SDR;

CSIAR = 0;

return false;

}

boolean store() {

TMPR = ACC;

ACC = PSIAR + 1;

PSIAR = ACC;

ACC = TMPR;

TMPR = SDR;

SAR = TMPR;

SDR = ACC;

if(write())

return true;

CSIAR = 0;

return false;

}

boolean branch() {

PSIAR = SDR;

CSIAR = 0;

return false;

}

boolean conditionalBranch() {

if (ACC==0) {

PSIAR = SDR;

CSIAR = 0;

}

else {

TMPR = ACC;

ACC = PSIAR + 1;

PSIAR = ACC;

ACC = TMPR;

CSIAR = 0;

}

return false;

}

boolean loadImmediate() {

ACC = PSIAR + 1;

PSIAR = ACC;

ACC = SDR;

CSIAR = 0;

return false;

}

/* print the contents of all the registers and all memory */

public void dump() {

System.out.printf("Register contents:\n");

System.out.printf("ACC = %08X\tPSIAR = %04X\tSAR = %04X\tSDR = %08X\n",ACC,PSIAR,SAR,SDR);

System.out.printf("TMPR = %08X\tCSIAR = %04X\tIR = %04X\tMIR = %04X\n",TMPR,CSIAR,IR,MIR);

System.out.printf("\nMemory contents:\n%03d: ",0);

for (int i=0; i<MEMORY_SIZE; i++) {

if(i!=0 && i%8==0)

System.out.printf("\n%03d: ",i);

System.out.printf("%08X ",Memory[i]);

}

System.out.println();

}

public boolean executeInstruction() {

boolean halt = false;

boolean error = false;

fetch();

switch(CSIAR) {

case Instruction.ADD:

error=add();

break;

case Instruction.SUB:

error=sub();

break;

case Instruction.LDA:

error=load();

break;

case Instruction.STR:

error=store();

break;

case Instruction.BRH:

error=branch();

break;

case Instruction.CBR:

error=conditionalBranch();

break;

case Instruction.LDI:

error=loadImmediate();

break;

case Instruction.HLT:

dump();

System.out.println("End of job.");

halt=true;

break;

default:

dump();

System.out.printf("Error: invalid instruction %04X.\nProgram terminated.\n",IR);

halt =true;

}

if(error) {

dump();

System.out.printf("Error: invalid memory address %04X.\nProgram terminated.\n",SAR);

}

return (halt || error); // return true if there was an error, false otherwise

}

}

EXPERTSMINDS.COM ACCEPTS INSTANT AND SHORT DEADLINES ORDER FOR SIMULATE OPERATION OF SIMMAC ASSIGNMENT - ORDER TODAY FOR EXCELLENCE!

We at Expertsminds offer best Nova Southeastern University, USA Assignment Help service for different units, such as -

  • CISC 500 Java Programming Language Assignment Help
  • CISC 502 Mathematics in Computing Assignment Help
  • CISC 501 Computer Organization and Architecture Assignment Help
  • CISC 503 Data Structures and Algorithms Assignment Help
  • CISC 610 Programming Languages Assignment Help
  • CISC 615 Design and Analysis of Algorithms Assignment Help
  • CISC 660 Database Management Systems Assignment Help
  • CISC 680 Software Engineering Assignment Help
  • CISC 647 Computer Architecture Assignment Help
  • CISC 650 Computer Networks Assignment Help
  • CISC 665 Distributed Systems Assignment Help
  • CISC 682 Software Requirements Engineering Assignment Help
  • CISC 684 Software Testing and Verification Assignment Help
  • CISC 683 Object-Oriented Design Assignment Help
  • CISC 685 Interaction Design Assignment Help
Tag This :- EM201959SOL527JAVA Simulate Operation of SIMMAC Assignment Help

get assignment Quote

Assignment Samples

Get Academic Excellence with Best Skilled Tutor! Order Assignment Now! Submit Assignment