Format issue, system not printing variable from nested if loop

0

I'm assuming its a simple formating issue, however i cannt see it at the moment as I have been staring at this code for a few dozen hours now. The intended ouput should show a string i.e. "add" or "or" instead of "null". The string in question is functionR.

all input will be taken as helpful input.

package src;

import java.util.Arrays;
import java.util.Scanner;


public class Decoder {
public static int Instructions [] = new int [] {0x022Da822, 0x8ef30018, 0x12a70004, 
0x02689820, 0xad930018, 0x02697824, 0xAD8ffff4,
0x018c6020, 0x02a4a825, 0x158ffff6, 0x8E59fff0};


public int address = 0x7A060;
public int startaddress=0x7A060;
public int opcode;
public int srcReg1;
public int srcReg2;
public int destreg;
public int sdReg;
public static int functcode;
public short offset;
int offaddress;
public int masks1 = 0x03e00000;
public int masks2dst= 0x001f0000;
public int masksDst = 0x0000f800;
public static int maskFunc = 0x0000003f;
public static int maskOpCode = 0xfc000000;
public int maskSDIform = 0x001f0000;
public int maskoffset=0x0000ffff;
Scanner input = new Scanner(System.in);	
public static int opcodetest = (Instructions[3]&maskOpCode)>>>26;
public static int test = Instructions[0]>>>26;
public int srcReg1test = (Instructions[1]&masks1)>>>21;
public static int functcode0=(Instructions[0]&maskFunc);
public static int functcode3=(Instructions[3]&maskFunc);
public static int functcode5=(Instructions[5]&maskFunc);
public static int functcode7=(Instructions[7]&maskFunc);
public static int functcode8=(Instructions[8]&maskFunc);
public String functionR;

//not really a get method, just testing implementation of variables
/*
public int testingopcode()
{
	
	for(int x=0;x<Instructions.length;x++)
	{  
	opcode = Instructions[x]>>>26;
	//Just a little formal check
	System.out.println("Instructions in binary:"+(Integer.toBinaryString(Instructions[x]))+"\tOpCode:\t:::"+opcode+"\tsrc1:\t"+srcReg1test);
	}
	return opcode;	
}
*/

public void testrun()
{
	for(int x=0;x<Instructions.length;x++)

	{  
address = startaddress+(4*x);
opcode = Instructions[x]>>>26;
destreg = (Instructions[x]&masksDst)>>>11;
srcReg1=(Instructions[x]&masks1)>>>21;
srcReg2 =(Instructions[x]&masks2dst)>>>16;
sdReg=(Instructions[x]&masks2dst)>>>16;
functcode=(Instructions[x]&maskFunc);
offset=(short) (Instructions[x]&maskoffset);
offaddress=startaddress+offset;
String functionL = null;


if(opcode==0)

{	
	{
		if(Integer.toHexString(functcode)=="20"){
	
	functionR = "add";	
	continue;
		}
		else if(Integer.toHexString(functcode)=="22")
			{
				functionR = "sub";
				continue;
			}
		else if(Integer.toHexString(functcode)=="24")
		{
			functionR = "and";
			continue;
		}
		
		else if(Integer.toHexString(functcode)=="25")
		{
			functionR = "or";
			continue;
		}
		System.out.println(Integer.toHexString(address)+"\t"+functionR+"$"+destreg+", $"+srcReg1+", $"+srcReg2);
	}
	}	
else 
	{
	if(opcode == 35){
		functionL = "lw";
		System.out.println(Integer.toHexString(address)+"\t"+functionL+" $"+sdReg+", "+offset+", "+"("+srcReg1+")");
		continue;
		}
	
	else if(opcode == 4){
		functionL = "beq";
		System.out.println(Integer.toHexString(address)+"\t"+functionL+" $"+sdReg+", $"+srcReg1+", address "+Integer.toHexString(offaddress));
		 continue;
	}
	
	else if (opcode == 43){
		functionL = "sw";
		System.out.println(Integer.toHexString(address)+"\t"+functionL+" $"+sdReg+", "+offset+", "+"("+srcReg1+")");
		continue;
	}
	
	
	else if (opcode == 5){
		functionL = "bne";
	System.out.println(Integer.toHexString(address)+"\t"+functionL+" $"+sdReg+", $"+srcReg1+", address "+Integer.toHexString(offaddress));
	continue;}
	}
}
	}




public static void main(String[] args) {
		// TODO Auto-generated method stub
	Decoder Assemble = new Decoder();
	System.out.println(Decoder.test);
	System.out.println();
	System.out.println(Integer.toHexString(functcode0));
	System.out.println();
	System.out.println(Integer.toHexString(functcode3));
	System.out.println();
	System.out.println(Integer.toHexString(functcode5));
	System.out.println();
	System.out.println(Integer.toHexString(functcode7));
	System.out.println();	
	System.out.println(Integer.toHexString(functcode8));
	System.out.println();
	Assemble.testrun();
	}

}

Actual output:

22

20

24

20

25

7a060	null$21, $17, $13
7a064	lw $19, 24, (23)
7a068	beq $7, $21, address 7a064
7a06c	null$19, $19, $8
7a070	sw $19, 24, (12)
7a074	null$15, $19, $9
7a078	sw $15, -12, (12)
7a07c	null$12, $12, $12
7a080	null$21, $21, $4
7a084	bne $15, $12, address 7a056
7a088	lw $25, -16, (18)

intended:

22

20

24

20

25

7a060	sub$21, $17, $13
7a064	lw $19, 24, (23)
7a068	beq $7, $21, address 7a064
7a06c	add$19, $19, $8
7a070	sw $19, 24, (12)
7a074	and$15, $19, $9
7a078	sw $15, -12, (12)
7a07c	add$12, $12, $12
7a080	null$21, $21, $4
7a084	or $15, $12, address 7a056
7a088	lw $25, -16, (18)

Thanks in advance.

java
loops
nested-loops

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0