public string ConvertToBinary(string instruction) { StringBuilder binary = new StringBuilder("1101"); //binary.Append(ConvertInstructionToBinary(instruction)); bool isSourceDataReigster = false; //SOurce is a data register //append register string[] instructionParts = instruction.Split(' '); if (instructionParts[SOURCE][0] == 'd') { isSourceDataReigster = true; } StringBuilder effectiveAddressAsBinary = new StringBuilder(); StringBuilder dataRegisterAsBinary = new StringBuilder(); if (isSourceDataReigster) { EffectiveAddress dataRegister = AddressingModes.GetAddressingMode(instructionParts[SOURCE]); dataRegisterAsBinary.Append(dataRegister.GetRegister()); EffectiveAddress effectiveAddress = AddressingModes.GetAddressingMode(instructionParts[DESTINATION]); effectiveAddressAsBinary.Append(effectiveAddress.GetRegister()); effectiveAddressAsBinary.Append(effectiveAddress.GetMode()); } else { } //if(isSourceDataReigster) //{ // binary.Append(ConvertDestinationEA()); //} //else //{ // binary.Append(ConvertImmediateOrSourceEA(instructionParts)); //} return(binary.ToString()); }
public string ConvertImmediateOrSourceEA(string[] instructionParts) { StringBuilder binary = new StringBuilder(); //If source is immediate if (instructionParts[2][0] == '#') { string immediateNumber = instructionParts[2].Substring(1); Int16 number = Convert.ToInt16(immediateNumber); binary.Append(Convert.ToString(number, 2)); } else { AddressingModes addressingModes = new AddressingModes(); EffectiveAddress effectiveAddress = addressingModes.GetAddressingMode(instructionParts[2]); } return(binary.ToString()); }