//********************************Decode an - TopicsExpress



          

//********************************Decode an operation******************************** function Decode(Data) { value=Data[Pos]; type=OpcodeOperandType[value]; //****************************************************************************************************************************** //note1 the value of type in the OpcodeOperand array is an sectional value that defines what to use to decode the operation //0,0,0,0,0=operand types and decode op type,0000=reg,0000=rm,00=IMM,00=op1,00=op2,00=op3,00=op4 //section bit position note //0=Bit22,0=Bit21,0=Bit20,0=Bit19,0=Bit18, 0000=Bit14,0000=Bit10,00=Bit8, 00=Bit6,00=Bit4,00=Bit2,00=Bit0 //****************************************************************************************************************************** //note2 the 0,0,0,0,0,0 specifies how to decode the operation //0=The Operation code Has an Register Selection Operand //0=does the last three bit of the opcode have an register selection //0=does the operation have an ModR/M byte //0=is the ModR/M Register an small opcode selection //0=are bytes read after the operation for straight input //****************************************************************************************************************************** //note3 reg is in the format 0=64,0=32,0=16,0=8 the digits that are set one in value for reg is the allowed size for the register //the four bit reg value works the same as RM for decoding the Ram Address operand //the value of IMM goes as follows IMM8=00 then IMM16=01 then IMM32=10 then IMM64=11 //****************************************************************************************************************************** //note4 00=op1,00=op2,00=op3,00=op4 these four values define the order the operands go in for this operation //op1 is used for first operand input the value of this defines what part of the decoded operands goes into input one //01=rm or 10=reg or 11=imm if 00 operand is not used //****************************************************************************************************************************** //break apart the binary settings of type for how to decode the instructions operands var HasReg=(type>>22)&0x01; //binary bit for if operand has an Register Operand var HasOpReg=(type>>21)&0x01; //binary bit for if the opcodes last 3 bits is register selection var HasModRM=(type>>20)&0x01; //binary bit for if there is an ModRM operand var IsModRMOpCode=(type>>19)&0x01; //binary bit for if the Register selection is changed to an Opcode in ModR/M byte var HasIMM=(type>>18)&0x01; //binary bit for if the operation has an IMM input operand //get the size settings for ModRM and Reg and IMM Var RMSize=(type>>14)&0x0x0F; var RegSize=(type>>10)&0x0F; var IMMSize=(type>>8)&0x03; //this time just grab the Reg value then decode it because this operand can be in tow places depending on operand type var RegV=0; //operation code name var OpCodeName=; //the separate operands var OperandReg=,OperandRM=,OperandIMM=; //check if OpReg else normal opcode if(OpReg) { RegV=value&0x07; OpCodeName=opcodes[value&F8]; } //check if ModR/M if(HasModRM) { //decode the ModRM byte and SIB var temp=DecodeModRM(Data,RMSize); RM=temp[0]; //check if Opcode select if(IsModRMOpCode) { OpCodeName=opcodes[value][temp[1]]; } //else Set Reg value else{RegV=temp[1];} } //only decode Reg Value if opcode has an Reg Select operand if(HasOpReg) { OperandReg=DecodeRegValue(RegV,RegSize); } //Decode IMM input if there is an IMM input if(HasIMM) { OperandIMM=ReadInput(IMMSize+1); } //put operands into an numerical selection array var Operands=[.,OperandRM,OperandReg,OperandIMM]; //let the opcode values select which operands to use in the decode output allows the order of operands to be selected in an simple format op1=(type>>6)&0x03; op2=(type>>4)&0x03; op3=(type>>2)&0x03; op4=type&0x03; //though the select operands together var output=OpCodeName+Operands[op1]+,+Operands[op2]+,+Operands[op3]+,+Operands[op4]+; //replace comma separation of zeroed out operands output=output.replace(/.,/g,); //give back the decoded instruction return(output); }
Posted on: Sat, 25 Oct 2014 08:46:10 +0000

Trending Topics



Recently Viewed Topics




© 2015