www.pudn.com > x86.rar > Alu.v, change:2007-12-05,size:77949b


`define CF    0
`define PF    2
`define AF    4
`define ZF    6
`define SF    7
`define TF    8
`define IF    9
`define DF   10
`define OF   11
`define IOPL 12
`define NT   14
`define RF   16
`define VM   17
`define AC   18
`define VIF  19
`define VIP  20
`define ID   21

module Alu(enablealu,Operation, Operand1, Operand2, Operand3, EflagsIn, OPSize, adSize, Result, EflagsOut,flush,oldPC,newPC);
input enablealu;
input [10:0] Operation;
input [31:0] Operand1, Operand2, Operand3;
input [1:0]  OPSize;
input adSize;
input [31:0] EflagsIn;
input [31:0] oldPC;
output [63:0] Result;
output [31:0] EflagsOut;
output [31:0] newPC;
output flush;
reg   [63:0] Result;
reg   [31:0] EflagsOut,newPC;
wire [31:0] cla1Out, cla2Out;
wire [32:1] carryOut1;
wire [32:1]carryOut2;
reg [31:0] cla1Op1, cla1Op2;
reg [31:0] cla2Op1, cla2Op2;
reg [31:0] twosCompIn1, twosCompIn2;
reg [31:0] onesCompIn;
reg [31:0] andIn1, andIn2;
reg [31:0] orIn1, orIn2;
reg [31:0] zfIn;
reg [7:0] pfIn;
reg ofCin, ofCout;
reg [31:0] exorIn1, exorIn2;
reg [63:0] dividend;
reg [31:0] divisor;
reg [31:0] multiplicand, multiplier;
reg [31:0] scanInFwd, scanInRev;
reg [31:0] rotateIn;
reg shiftBitIn1,shiftBitIn2,rotateBitIn;
reg [31:0] shiftIn,shrdin1,shrdin2;
reg [31:0] shldin1,shldin2;
reg direction,flush;
reg [4:0] count,shrdcount,shldcount;
reg direction1, direction2;
reg sign,signed1;
reg cIn1;
reg cIn2;

wire [31:0] twosCompOut1, twosCompOut2;
wire [31:0] onesCompOut;
wire [31:0] andOut;
wire [31:0] orOut;
wire [31:0] exorOut;
wire [4:0]  indexOutFwd, indexOutRev;
wire pfOut;
wire zfOut;
wire ofOut;
wire [31:0] shiftOut1, shiftOut2;
wire [63:0] divOut;
wire [63:0] product;
wire [31:0] rotateOut1, rotateOut2;
wire [31:0] shrdout,shldout;
wire rotateBitOut1, rotateBitOut2;
wire shiftBitOut1, shiftBitOut2;
wire shrdoutbit,shldoutbit;

shiftLogical shifterLogInst(shiftOut1, shiftBitOut1, shiftBitIn1, shiftIn, count, direction);
shiftArith shiftArithInst(shiftOut2, shiftBitOut2, shiftBitIn2, shiftIn, count);
bitScanFwd bsfInst(indexOutFwd, scanInFwd);
bitScanRev bsrInst(indexOutRev, scanInRev);
multiply32 multiplyInst(product, multiplicand, multiplier, sign);
cla32Bit claInst01( cla1Out, carryOut1, cla1Op1, cla1Op2, cIn1);
cla32Bit claInst02( cla2Out, carryOut2, cla2Op1, cla2Op2, cIn2);
twosComp twosCompInst1(twosCompOut1, twosCompIn1);
twosComp twosCompInst2(twosCompOut2, twosCompIn2);
division divInst(dividend, divisor, divOut, signed1);
rotate rotateInst1(rotateOut1, rotateBitOut1, rotateBitIn, rotateIn, count, direction1);
rotateWithCarry rotateInst2(rotateOut2, rotateBitOut2, rotateBitIn, rotateIn, count, direction2);
shrd shrdinst(shrdout,shrdoutbit,shrdin1,shrdin2,shrdcount);
shld shldinst(shldout,shldoutbit,shldin1,shldin2,shldcount);

assign zfOut = !(|(zfIn));
assign pfOut = !(^(pfIn));
assign exorOut = exorIn1 ^ exorIn2;
assign orOut = orIn1 | orIn2;
assign andOut = andIn1 & andIn2;
assign onesCompOut = ~onesCompIn;
assign ofOut = ofCin ^ ofCout;


always @(enablealu or Operation  or Operand1 or Operand2 or OPSize or Operand3 or  adSize or
         cla1Out or cla2Out or carryOut1 or carryOut2 or twosCompOut1 or twosCompOut2 or andOut or
         orOut or shiftOut1 or shiftOut2 or shiftBitOut1 or shiftBitOut2 or
         divOut or product or shrdout or shrdoutbit or shldout or shldoutbit or zfOut or pfOut or ofOut or indexOutFwd or indexOutRev or
         onesCompOut or rotateBitOut1 or rotateBitOut2 or rotateOut1 or rotateOut2 or exorOut or oldPC)
 begin
  if(enablealu)
    begin
  Result[63:0] = {Operand2,Operand1};
  /*cla1Op1 = 32'd0; cla1Op2 = 32'd0;
  cla2Op1 = 32'd0; cla2Op2 = 32'd0; twosCompIn1 = 32'd0; twosCompIn2 = 32'd0;
    sign = 1'b0;  signed1 = 1'b0;
  direction1 = 1'b0; direction2 = 1'b0; direction = 1'b0;
  count = 5'd0;  // flush = 1'b0;
  shiftIn = 32'd0; shiftBitIn1 = 1'b0; shiftBitIn2 = 1'b0; rotateBitIn = 1'b0;
  onesCompIn = 32'd0;
  andIn1 = 32'd0; andIn2 = 32'd0;
  orIn1 = 32'd0; orIn2 = 32'd0;
    ofCin = 1'b0; ofCout = 1'b0;
  exorIn1 = 32'd0; exorIn2 = 32'd0;
  dividend = 64'd0;
  divisor = 32'd0;
  multiplicand = 32'd0; multiplier = 32'd0;
  scanInFwd = 32'd0; scanInRev = 32'd0;
  rotateIn = 32'd0;*/
  cIn1 = 1'b0; cIn2 = 1'b0;
  zfIn = 32'd0;
  pfIn =8'd0;

  newPC = oldPC;
  EflagsOut = EflagsIn;
  case(Operation)
/* ************************************* */
  11'd1: // AAA - ASCII Adjust After Addition
   begin
    if((Operand1[3:0]>9) | EflagsIn[`AF])
     begin
      cla1Op1 = Operand1[3:0];
      cla1Op2 = 4'd6;
      cIn1 = 1'b0;
      Result[7:0] = {4'd0, cla1Out[3:0]};
      cla2Op1 = {24'd0,Operand1[15:8]};
      cla2Op2 = 32'd1;
      cIn2 = 1'b0;
      Result[15:8] = cla2Out[7:0];
      Result[31:16] = Operand1[31:16];
      Result[63:32] = Operand2;
      EflagsOut[`CF] = 1'b1;
      EflagsOut[`AF] = 1'b1;
     end
    else
     begin
      cla1Op1 = 32'd0;
      cla1Op2 = 32'd0;
      cla2Op1 = 32'd0;
      cla2Op2 = 32'd0;
      cIn1 = 1'b0;
      cIn2 = 1'b0;
      Result[7:0] = {4'd0, Operand1[3:0]};
      Result[15:8] = Operand1[15:8];
      Result[31:16] = Operand1[31:16];
      Result[63:32] = Operand2;

      EflagsOut[`CF] = 1'b0;
      EflagsOut[`AF] = 1'b0;
     end
     flush = 1'b0;
   end
/* ************************************* */
   11'd2: // AAD - ASCII Adjust AX Before Division
    begin
     cla1Op1 = Operand1[7:0];
     multiplicand = Operand1[15:8];
     multiplier = 32'ha;
     sign = 1'b0;
     cla1Op2 = product[31:0];
     cIn1 = 1'b0;
     Result[7:0] = cla1Out[7:0];
     Result[15:8] = 8'd0;
     Result[31:16] = Operand1[31:16];
     EflagsOut[`SF] = Result[7];
     pfIn = cla1Out[7:0];
     EflagsOut[`PF] = pfOut;

     zfIn = cla1Out[7:0];
     EflagsOut[`ZF] = zfOut;
     flush = 1'b0;
          end
/* ************************************* */
   11'd3: // AAM - ASCII Adjust AX After Multiply
    begin
     dividend = Operand1[7:0];
     divisor = 32'ha;
     Result[7:0] = divOut[7:0];
     Result[15:8] = divOut[39:32];
     Result[31:16] = Operand1[31:16];

     //modFlags = {divOut[39:32], divOut[7:0]};
     pfIn = divOut[7:0];
     EflagsOut[`PF] = pfOut;

     zfIn = divOut[7:0];
     EflagsOut[`ZF] = zfOut;

     EflagsOut[`SF] = divOut[7]; // Doubt
     flush = 1'b0;
          end
/* ************************************* */
  11'd4: // AAS - ASCII Adjust AL After Subtraction
   begin
    if((Operand1[3:0]>9) | EflagsIn[`AF])
     begin
      cla1Op1 = Operand1[7:0];
      twosCompIn1 = 8'd6;
      cla1Op2 = twosCompOut1;
      cIn1 = 1'b0;
      Result[7:0] = {4'b0,cla1Out[3:0]};
      cla2Op1 = Operand1[15:8];
      twosCompIn2 = (Operand1[7:0]<8'h06)? 8'd2:8'd1;
      cla2Op2 = twosCompOut2;
      cIn2 = 1'b0;
      Result[15:8] = cla2Out[7:0];
      Result[31:16] = Operand1[31:16];
      Result[63:32] = Operand2;
      EflagsOut[`CF] = 1'b1;
      EflagsOut[`AF] = 1'b1;
     end
    else
     begin
      cla1Op1 = 32'd0;
      cla1Op2 = 32'd0;
      cla2Op1 = 32'd0;
      cla2Op2 = 32'd0;
      cIn1 = 1'b0;
      cIn2 = 1'b0;
      twosCompIn1 = 32'd0;
      twosCompIn2 = 32'd0;
      Result[7:0] = {4'b0,Operand1[3:0]};
      Result[15:8] = Operand1[15:8];
      Result[31:16] = Operand1[31:16];
      Result[63:32] =  Operand2;
      EflagsOut[`CF] = 1'b0;
      EflagsOut[`AF] = 1'b0;
     end
     flush = 1'b0;
   end
/* ************************************* */
   11'd5: // ADC - Add with Carry
    begin
     cla1Op1 = Operand1;
     cla1Op2 = Operand2;
     cIn1 = EflagsIn[0];
     case(OPSize)
      2'b00:
       begin
        Result[7:0] = cla1Out[7:0];
        Result[31:8] = Operand1[31:8];
        Result[63:32] = Operand2;
        zfIn = cla1Out[7:0];
        EflagsOut[`ZF] = zfOut;
        EflagsOut[`SF] = cla1Out[7];
        EflagsOut[`CF] = carryOut1[8];
        ofCin = carryOut1[7];
        ofCout = carryOut1[8];
        EflagsOut[`OF] = ofOut;
       end
      2'b01:
       begin
        Result[15:0] = cla1Out[15:0];
        Result[31:16] = Operand1[31:16];
        Result[63:32] = Operand2;
        zfIn = cla1Out[15:0];
        EflagsOut[`ZF] = zfOut;
        EflagsOut[`SF] = cla1Out[15];
        EflagsOut[`CF] = carryOut1[16];
        ofCin = carryOut1[15];
        ofCout = carryOut1[16];
        EflagsOut[`OF] = ofOut;
       end
      default:
       begin
        Result[31:0] = cla1Out;
        Result[63:32] =  Operand2;
        zfIn = cla1Out[31:0];
        EflagsOut[`ZF] = zfOut;
        EflagsOut[`SF] = cla1Out[31];
        EflagsOut[`CF] = carryOut1[32];
        ofCin = carryOut1[31];
        ofCout = carryOut1[32];
        EflagsOut[`OF] = ofOut;
       end
     endcase
     pfIn = cla1Out[7:0];
     EflagsOut[`PF] = pfOut;
     EflagsOut[`AF] = carryOut1[4];
     flush = 1'b0;
    end
/* ************************************* */
   11'd6: // ADD - Add
    begin


                cla1Op1 = Operand1;
     cla1Op2 = Operand2;
     cIn1 = 1'b0;
     case(OPSize)
      2'b00:
       begin
        Result[7:0] = cla1Out[7:0];
        Result[31:8] = Operand1[31:8];
        Result[63:32] = Operand2;
        zfIn = cla1Out[7:0];
        EflagsOut[`ZF] = zfOut;
        EflagsOut[`SF] = cla1Out[7];
        EflagsOut[`CF] = carryOut1[8];
        ofCin = carryOut1[7];
        ofCout = carryOut1[8];
        EflagsOut[`OF] = ofOut;
       end
      2'b01:
       begin
        Result[15:0] = cla1Out[15:0];
        Result[31:16] = Operand1[31:16];
        Result[63:32] =  Operand2;
        zfIn = cla1Out[15:0];
        EflagsOut[`ZF] = zfOut;
        EflagsOut[`SF] = cla1Out[15];
        EflagsOut[`CF] = carryOut1[16];
        ofCin = carryOut1[15];
        ofCout = carryOut1[16];
        EflagsOut[`OF] = ofOut;
       end
      default:
       begin
        Result[31:0] = cla1Out;
        Result[63:32] =  Operand2;
        zfIn = cla1Out[31:0];
        EflagsOut[`ZF] = zfOut;
        EflagsOut[`SF] = cla1Out[31];
        EflagsOut[`CF] = carryOut1[32];
        ofCin = carryOut1[31];
        ofCout = carryOut1[32];
        EflagsOut[`OF] = ofOut;
       end
     endcase
     pfIn = cla1Out[7:0];
     EflagsOut[`PF] = pfOut;
     EflagsOut[`AF] = carryOut1[4];
     flush = 1'b0;

    end
/* ************************************* */
   11'd11: // AND - LOGICAL AND
    begin
     andIn1 = Operand1;
     andIn2 = Operand2;
     case(OPSize)
      2'b00:
       begin
        Result[7:0] = andOut[7:0];
        Result[31:8] = Operand1[31:8];
        zfIn = andOut[7:0];
        EflagsOut[`ZF] = zfOut;
        EflagsOut[`SF] = andOut[7];
       end
      2'b01:
       begin
        Result[15:0] = andOut[15:0];
        Result[31:16] = Operand1[31:16];
        zfIn = andOut[15:0];
        EflagsOut[`ZF] = zfOut;
        EflagsOut[`SF] = andOut[15];
       end
      default:
       begin
        Result[31:0] = andOut;
        zfIn = andOut;
        EflagsOut[`ZF] = zfOut;
        EflagsOut[`SF] = andOut[31];
       end
     endcase
     Result[63:32]=Operand2;
     pfIn = andOut[7:0];
     EflagsOut[`PF] = pfOut;
     EflagsOut[`CF] = 1'b0;
     EflagsOut[`OF] = 1'b0;
     EflagsOut[`AF] = 1'b0;
     flush = 1'b0;
    end
/* ************************************* */
   11'd16: // Adjust RPL Field of Segment Selector
    begin
     if(Operand2[1:0]>Operand1[1:0])
      begin
       Result[31:0]  = {Operand1[31:2], Operand2[1:0]};
       Result[63:32] = Operand2;
       EflagsOut[`ZF] = 1'b1;
      end
     else
      begin
       Result[31:0] = Operand1;
       Result[63:32] =  Operand2;
       EflagsOut[`ZF] = 1'b0;
      end
     flush = 1'b0;
   end
/* ************************************* */
   11'd18: // BSF - Bit Scan Forward
    begin
     case(OPSize)
      2'b01:
       begin
        scanInFwd = Operand2[15:0];
        if(Operand2[15:0] == 16'd0)
         begin
          Result[63:0] = {Operand2,32'hx};
          EflagsOut[`ZF] = 1'b1;
         end
        else
         begin
          Result[63:0] = {Operand2,27'd0,indexOutFwd};
          EflagsOut[`ZF] = 1'b0;
         end
       end
      default:
       begin
        scanInFwd = Operand2[31:0];
        if(Operand2[31:0] == 32'd0)
         begin
          Result[63:0] = {Operand2,32'hx};
          EflagsOut[`ZF] = 1'b1;
         end
        else
         begin
          Result[63:0] ={Operand2,27'd0, indexOutFwd};
          EflagsOut[`ZF] = 1'b0;
         end
       end
     endcase
     flush = 1'b0;
    end
/* ************************************* */
   11'd19: // BSR - Bit Scan Reverse
    begin
     case(OPSize)
      2'b01:
       begin
        scanInRev = Operand2[15:0];
        if(Operand2[15:0] == 16'd0)
         begin
          Result[63:0] ={Operand2,32'hx};
          EflagsOut[`ZF] = 1'b1;
         end
        else
         begin
          Result[63:0] ={Operand2,27'd0,indexOutRev};
          EflagsOut[`ZF] = 1'b0;
         end
       end
      default:
       begin
        scanInRev = Operand2[31:0];
        if(Operand2[31:0] == 32'd0)
         begin
          Result[63:0] ={Operand2,32'hx};
          EflagsOut[`ZF] = 1'b1;
         end
        else
         begin
          Result[63:0] ={Operand2,27'd0,indexOutRev};
          EflagsOut[`ZF] = 1'b0;
         end
       end
     endcase
     flush = 1'b0;
    end
/* ************************************* */
   11'd20: // BSWAP - Byte Swap
    begin
     Result[7:0] = Operand1[31:24];
     Result[15:8] = Operand1[23:16];
     Result[23:16] = Operand1[15:8];
     Result[31:24] = Operand1[7:0];
     Result[63:32] = Operand2;
     flush = 1'b0;
    end
/* ************************************* */
   11'd21: // BT - Bit Test
    begin
     case(OPSize)
      2'b01:
       begin
        dividend = Operand2[15:0];
        divisor = 16'd16;
        EflagsOut[`CF] = Operand1[divOut[3:0]];
       end
      default:
       begin
        dividend = Operand2[31:0];
        divisor = 16'd32;
        EflagsOut[`CF] = Operand1[divOut[4:0]];
       end
     endcase
     Result[31:0] = Operand1;
     Result[63:32] = Operand2;
     flush = 1'b0;


    end
/* ************************************* */
   11'd22: // BTC - Bit Test and Complement
    begin
     Result[31:0] = Operand1;
     case(OPSize)
      2'b01:
       begin
        dividend = Operand2[15:0];
        divisor = 16'd16;
        EflagsOut[`CF] = Operand1[divOut[3:0]];
        Result[divOut[3:0]] = !Operand1[divOut[3:0]];
       end
      default:
       begin
        dividend = Operand2[31:0];
        divisor = 16'd32;
        EflagsOut[`CF] = Operand1[divOut[4:0]];
        Result[divOut[4:0]] = !Operand1[divOut[4:0]];
       end
     endcase
        Result[63:32]=Operand2;
     flush = 1'b0;
    end
/* ************************************* */
   11'd23: // BTR - Bit Test and Reset
    begin
     Result = Operand1;
     case(OPSize)
      2'b01:
       begin
        dividend = Operand2[15:0];
        divisor = 16'd16;
        EflagsOut[`CF] = Operand1[divOut[3:0]];
        Result[divOut[3:0]] = 1'b0;
       end
      default:
       begin
        dividend = Operand2[31:0];
        divisor = 16'd32;
        EflagsOut[`CF] = Operand1[divOut[4:0]];
        Result[divOut[4:0]] = 1'b0;
       end
     endcase
       Result[63:32]=Operand2;
     flush = 1'b0;
    end
/* ************************************* */
   11'd24: // BTS - Bit Test and Set
    begin
     Result = Operand1;
     case(OPSize)
      2'b01:
       begin
        dividend = Operand2[15:0];
        divisor = 16'd16;
        EflagsOut[`CF] = Operand1[divOut[3:0]];
        Result[divOut[3:0]] = 1'b1;
       end
      default:
       begin
        dividend = Operand2[31:0];
        divisor = 16'd32;
        EflagsOut[`CF] = Operand1[divOut[4:0]];
        Result[divOut[4:0]] = 1'b1;
       end
     endcase
       Result[63:32]=Operand2;
     flush = 1'b0;
    end
/* ************************************* */
   11'd27: // CBW/CWDE - Convert Byte to Word /Convert Word to Doubleword
    begin
     case(OPSize)
      2'b00:
       begin
        Result[15:0] = {{8{Operand1[7]}}, Operand1[7:0]};
        Result[31:16] = Operand1[31:16];
        Result[63:32] = Operand2;
       end
      default:
       begin
        Result[31:0] = {{16{Operand1[15]}}, Operand1[15:0]};
        Result[63:32] =  Operand2;
       end
     endcase
     flush = 1'b0;
    end
/* ************************************* */
   11'd28: // CWD/CDQ - Convert Word to Doubleword/Convert Doubleword tO Quadword
    begin
     case(OPSize)
      2'd1:
       begin
        Result[31:0] = {Operand1[31:16],{16{Operand2[15]}}};
        Result[63:32] =  Operand2;
       end
      2'd2:
       begin
        Result[31:0] = {32{Operand2[31]}};
        Result[63:32]= Operand2;
       end
     endcase
     flush = 1'b0;
    end
/* ************************************* */
   11'd29: // CLC - Clear Carry Flag
    begin
     EflagsOut[`CF] = 1'b0;
     flush = 1'b0;
    end
/* ************************************* */
   11'd30: // CLD - Clear Direction Flag
    begin
     EflagsOut[`DF] = 1'b0;
     flush = 1'b0;
    end
/* ************************************* */
   11'd34: // CMC - Comlement Carry Flag
    begin
     EflagsOut[`CF] = !EflagsIn[`CF];
     flush = 1'b0;
    end
/* ************************************* */
        11'd35: // CMOVO - Move if Overflow(OF==1)
   begin
    if(EflagsIn[`OF]==1'b1)
     Result[31:0] = Operand2;
    else
     Result[31:0] = Operand1;
   Result[63:32] = Operand2;
     flush = 1'b0;
   end
/* ************************************* */
        11'd36: // CMOVNO - Move if not overflow(OF==0)
                begin
                 if(EflagsIn[`OF]==1'b0)
                        Result[31:0] = Operand2;
                 else
                        Result[31:0] = Operand1;
                Result[63:32] = Operand2;
     flush = 1'b0;

                end
/* ************************************* */
         11'd37: // CMOVB, CMOVNAE, CMOVC - Move if Below (CF=1), Move if not below or equal, Move if carry
                begin
                 if(EflagsIn[`CF])
                        Result[31:0] = Operand2;
      else
       Result[31:0] = Operand1;
  Result[63:32] = Operand2;
     flush = 1'b0;
    end
/* ************************************* */
         11'd38: // CMOVNB, CMOVAE, CMOVNC - Move if not below (CF=0), Move if not above or equal, Move if not carry
    begin
     if(EflagsIn[`CF]==1'b0)
      Result[31:0] = Operand2;
     else
      Result[31:0] = Operand1;
  Result[63:32] = Operand2;
     flush = 1'b0;
    end
/* ************************************* */
         11'd39: //CMOVZ - Move if Zero (ZF=1)
    begin
     if(EflagsIn[`ZF]==1'b1)
      Result[31:0] = Operand2;
     else
      Result[31:0] = Operand1;
  Result[63:32] = Operand2;
     flush = 1'b0;
    end
/* ************************************* */
         11'd40: // CMOVNZ - Move if not Zero (ZF=0)
     begin
      if(EflagsIn[`ZF]==1'b0)
       Result[31:0] = Operand2;
      else
       Result[31:0] = Operand1;
  Result[63:32] = Operand2;
     flush = 1'b0;
     end
/* ************************************* */
   11'd41: // CMOVBE - Move if below or equal (CF = 1 or ZF = 1)
          begin
     if(EflagsIn[`CF] | EflagsIn[`ZF])
      Result[31:0] = Operand2;
     else
      Result[31:0] = Operand1;
  Result[63:32] = Operand2;
     flush = 1'b0;
    end
/* ************************************* */
   11'd42: // CMOVNBE - Move if not below or equal (CF = 0 or ZF = 0)
          begin
     if(!EflagsIn[`CF] & !EflagsIn[`ZF])
      Result[31:0] = Operand2;
     else
      Result[31:0] = Operand1;
  Result[63:32] = Operand2;
     flush = 1'b0;
    end
/* ************************************* */
         11'd43: // CMOVS - Move if sign (SF=1)
     begin
      if(EflagsIn[`SF]==1'b1)
       Result[31:0] = Operand2;
      else
       Result[31:0] = Operand1;
  Result[63:32] = Operand2;
     flush = 1'b0;
     end
/* ************************************* */
         11'd44: // CMOVNS - Move if not sign (SF=0)
     begin
      if(EflagsIn[`SF]==1'b0)
       Result[31:0] = Operand2;
      else
       Result[31:0] = Operand1;
  Result[63:32] = Operand2;
     flush = 1'b0;
     end
/* ************************************* */
         11'd45: // CMOVP - Move if parity sign (PF=1)
     begin
      if(EflagsIn[`PF]==1'b1)
       Result[31:0] = Operand2;
      else
       Result[31:0] = Operand1;
   Result[63:32] = Operand2;
     flush = 1'b0;
     end
/* ************************************* */
         11'd46: // CMOVNP - Move if not parity (PF=0)
     begin
      if(EflagsIn[`PF]==1'b0)
       Result[31:0] = Operand2;
      else
       Result[31:0] = Operand1;
  Result[63:32] = Operand2;
     flush = 1'b0;
     end
/* ************************************* */
   11'd47: //CMOVL - Move if less (SF!=OF)
    begin
     if((EflagsIn[`SF]!=EflagsIn[`OF]))
      Result[31:0] = Operand2;
     else
      Result[31:0] = Operand1;
  Result[63:32] = Operand2;
     flush = 1'b0;
    end
/* ************************************* */
   11'd48: //CMOVNL - Move if not less (SF==OF)
    begin
     if((EflagsIn[`SF] == EflagsIn[`OF]))
      Result[31:0] = Operand2;
     else
      Result[31:0] = Operand1;
 Result[63:32] = Operand2;
     flush = 1'b0;
    end
/* ************************************* */
   11'd49: // CMOVLE - Move if less or equal (ZF==1) or (SF!=OF)
        begin
        if((EflagsIn[`ZF]==1'b1) | (EflagsIn[`SF]!=EflagsIn[`OF]))
      Result[31:0] = Operand2;
     else
      Result[31:0] = Operand1;
        Result[63:32] = Operand2;
     flush = 1'b0;
    end
/* ************************************* */
   11'd50: // CMOVNLE - Move if not less or equal (ZF==1) and (SF==OF)
          begin
     if((EflagsIn[`ZF]==1'b0) & (EflagsIn[`SF]==EflagsIn[`OF]))
      Result[31:0] = Operand2;
     else
      Result[31:0] = Operand1;
  Result[63:32] = Operand2;
     flush = 1'b0;
    end
/* ************************************* */
   11'd51: // CMP - Compare Two Operands
    begin
     case(OPSize)
      2'b00:
       begin
        cla1Op1 = Operand1[7:0];
        twosCompIn1 = Operand2[7:0];
        cla1Op2 = twosCompOut1[7:0];
        EflagsOut[`SF] = cla1Out[7];
        EflagsOut[`CF] = (Operand2[7:0]==8'd0)?1'b0:!carryOut1[8];
        ofCin = carryOut1[7];
        ofCout = carryOut1[8];
        zfIn = cla1Out[7:0];
       end
      2'b01:
       begin
        cla1Op1 = Operand1[15:0];
        twosCompIn1 = Operand2[15:0];
        cla1Op2 = twosCompOut1[15:0];
        EflagsOut[`SF] = cla1Out[15];
        EflagsOut[`CF] = (Operand2[15:0]==16'd0)?1'b0:!carryOut1[16];
        ofCin = carryOut1[15];
        ofCout = carryOut1[16];
        zfIn = cla1Out[15:0];
       end
      default:
       begin
        cla1Op1 = Operand1[31:0];
        twosCompIn1 = Operand2[31:0];
        cla1Op2 = twosCompOut1[31:0];
        Result[31:0] = cla1Out[31:0];
        Result[63:32] = Operand2;
        EflagsOut[`SF] = cla1Out[31];
        EflagsOut[`CF] =(Operand2==32'd0)?1'b0: !carryOut1[32];
        ofCin = carryOut1[31];
        ofCout = carryOut1[32];
        zfIn = cla1Out;
       end
     endcase
     pfIn = cla1Out[7:0];
     EflagsOut[`ZF] = zfOut;
     EflagsOut[`PF] = pfOut;
     EflagsOut[`OF] = ofOut;
     EflagsOut[`AF] = (Operand2[3:0]==4'd0)?1'b0:!carryOut1[4];
     Result[31:0] = Operand1;
     Result[63:32] = Operand2;
     flush = 1'b0;

    end
/* ************************************* */
   11'd57: // Compare and Exchange
    begin
     cIn1 = 1'b0;
     case(OPSize)
      2'd0:
       begin
        cla1Op1 = Operand3[7:0];
        twosCompIn1 = Operand1[7:0];
        cla1Op2 = twosCompOut1[7:0];
        zfIn = cla1Out[7:0];
        //pfIn = cla1Out[7:0];
        EflagsOut[`ZF] = zfOut;
        EflagsOut[`SF] = cla1Out[7];
        EflagsOut[`CF] = (Operand1[7:0]==8'd0)?1'b0:!carryOut1[8];
        ofCin = carryOut1[7];
        ofCout = carryOut1[8];
       end
      2'd1:
       begin
        cla1Op1 = Operand3[15:0];
        twosCompIn1 = Operand1[15:0];
        cla1Op2 = twosCompOut1[15:0];
        zfIn = cla1Out[15:0];
        //pfIn = cla1Out[7:0];
        EflagsOut[`ZF] = zfOut;
        EflagsOut[`SF] = cla1Out[15];
        EflagsOut[`CF] = (Operand1[15:0]==16'd0)?1'b0:!carryOut1[16];
        ofCin = carryOut1[15];
        ofCout = carryOut1[16];
       end
      default:
       begin
        cla1Op1 = Operand3;
        twosCompIn1 = Operand1;
        cla1Op2 = twosCompOut1;
        zfIn = cla1Out;
        //pfIn = cla1Out[7:0];
        EflagsOut[`ZF] = zfOut;
        EflagsOut[`SF] = cla1Out[31];
        EflagsOut[`CF] =(Operand1==32'd0)?1'b0: !carryOut1[32];
        ofCin = carryOut1[31];
        ofCout = carryOut1[32];
       end
     endcase
     EflagsOut[`OF] = ofOut;
     EflagsOut[`AF] = (Operand1[3:0]==4'd0)?1'b0:!carryOut1[4];
     EflagsOut[`PF] = pfOut;
     if(zfOut)
      Result[31:0] = Operand2;
     else
      Result[31:0] = Operand1;
     pfIn = cla1Out[7:0];
     Result[63:32] = Operand2;
     flush = 1'b0;
    end

/* ************************************* */
  11'd83: // DAA - Decimal Adjust AL After Addition
   begin
    if((Operand1[3:0]>9) | EflagsIn[`AF])
     begin
      cla1Op1 = {24'd0,Operand1[7:0]};
      cla1Op2 = 32'd6;
      cIn1 = 1'b0;
      Result[3:0] = cla1Out[3:0];
      EflagsOut[`CF] = EflagsIn[`CF] | carryOut1[8];
      EflagsOut[`AF] = 1'b1;
//      zfIn = cla1Out[3:0];
//      pfIn = Operand1;
     end
    else
     begin
      cla1Op1 = {24'd0,Operand1[7:0]};
      cla1Op2 = 32'd0;
      cIn1 = 1'b0;
      Result[3:0] = Operand1[3:0];
      EflagsOut[`CF] = EflagsIn[`CF];
      EflagsOut[`AF] = 1'b0;
//      zfIn = Operand1[3:0];
//      pfIn = Operand1[3:0];
     end

    if((cla1Out[7:4]>9) | EflagsOut[`CF] ) //cla1Out[8])
     begin
      cla2Op1 = {28'd0,cla1Out[7:4]};
      cla2Op2 = 32'd6;
      cIn2 = cla1Out[8];
      Result[7:4] = cla2Out[3:0];
      EflagsOut[`CF] = 1'b1;
      EflagsOut[`SF] = cla2Out[3];
//      zfIn[7:4] = cla2Out[3:0];
//      pfIn[7:4] = cla2Out[3:0];
     end
    else
     begin
      cla2Op1 = 32'd0;
      cla2Op2 = 32'd0;
      cIn2 = 1'b0;
      Result[7:4] = cla1Out[7:4];
      EflagsOut[`CF] = 1'b0;
      EflagsOut[`SF] = cla1Out[7];
//      zfIn[7:4] = Operand1[7:4];
//      pfIn[7:4] = cla1Out[7:4];
     end
      zfIn = {24'd0,Result[7:0]};
      pfIn = Result[7:0];
      Result[15:8] = Operand1[15:8];
      Result[31:16] = Operand1[31:16];
      Result[63:32] = Operand2;
      EflagsOut[`ZF] = zfOut;
      EflagsOut[`PF] = pfOut;
     flush = 1'b0;
   end
/* ************************************* */
  11'd84: // DAS - Decimal Adjust AL After Subtraction
   begin
    if((Operand1[3:0]>9) | EflagsIn[`AF])
     begin
      cla1Op1 = {Operand1[7:0],24'b0 };
      cla1Op2 = {4'hf,4'ha,24'b0};
      cIn1 = 1'b0;
      Result[7:0] = cla1Out[31:24];
      EflagsOut[`CF] = EflagsIn[`CF] | carryOut1[32];
      EflagsOut[`AF] = 1'b1;
     end
    else
     begin
      cla1Op1 = 32'd0;
      cla1Op2 = 32'd0;
      cIn1 = 1'b0;
      Result[7:0] = Operand1[7:0];
//      EflagsOut[`CF] = EflagsIn[`CF];
      EflagsOut[`AF] = 1'b0;
     end

    if((Operand1[7:4]>9) | EflagsIn[`CF])
     begin
      cla2Op1 = Result[7:4];
      cla2Op2 = 4'ha;
      cIn2 = 1'b0;
      Result[7:4] = cla2Out[3:0];
      EflagsOut[`CF] = 1'b1;
     end
    else
     begin
      cla2Op1 = 32'd0;
      cla2Op2 = 32'd0;
      cIn2 = 1'b0;
//      Result[7:4] = Operand1[7:4];
      EflagsOut[`CF] = 1'b0;
     end
      Result[15:8] = Operand1[15:8];
      Result[31:16] = Operand1[31:16];
  Result[63:32] = Operand2;
      pfIn = Result[7:0];
      zfIn = Result[31:0];
      EflagsOut[`PF] = pfOut;
      EflagsOut[`ZF] = zfOut;
      EflagsOut[`SF] = Result[7];
     flush = 1'b0;
   end
/* ************************************* */
  11'd85: // DEC - Decrement by 1
   begin
    cla1Op2 = 32'hffff_ffff;
    cIn1 = 0;
    Result[63:32] =  Operand2;
    case(OPSize)
     2'b00:
      begin
       cla1Op1 = Operand1[7:0];
       Result[31:0] = {Operand1[31:8],cla1Out[7:0]};
       EflagsOut[`SF] = cla1Out[7];
       zfIn = cla1Out[7:0];
       EflagsOut[`ZF] = zfOut;
       ofCin = carryOut1[7];
       ofCout = carryOut1[8];
       EflagsOut[`OF] = ofOut;
      end
     2'b01:
      begin
       cla1Op1 = Operand1[15:0];
       Result[31:0] = {Operand1[31:16],cla1Out[15:0]};
       EflagsOut[`SF] = cla1Out[15];
       zfIn = cla1Out[15:0];
       EflagsOut[`ZF] = zfOut;
       ofCin = carryOut1[15];
       ofCout = carryOut1[16];
       EflagsOut[`OF] = ofOut;
      end
     default:
      begin
       cla1Op1 = Operand1;
       Result[31:0] = cla1Out[31:0];
       EflagsOut[`SF] = cla1Out[31];
       zfIn = cla1Out[31:0];
       EflagsOut[`ZF] = zfOut;
       ofCin = carryOut1[31];
       ofCout = carryOut1[32];
       EflagsOut[`OF] = ofOut;
      end
    endcase
    pfIn = cla1Out[7:0];
    EflagsOut[`PF] = pfOut;
    EflagsOut[`AF] = !carryOut1[4];
     flush = 1'b0;


   end
/* ************************************* */
  11'd86: // DIV - Unsigned divide
   begin
    signed1 = 1'b0;

    case(OPSize)
     2'b00:
      begin 
       dividend = Operand3[15:0];
       divisor  =  Operand2[7:0];  
       Result[39:32] = divOut[39:32];
       Result[47:40] = divOut[7:0];
       Result[63:48] = Operand3[31:16];
       Result[31:0] = Operand1;
      end
     2'b01:
      begin 
       dividend = {Operand1[15:0],Operand3[15:0]};
       divisor  =  Operand2[15:0];
       Result[15:0] = divOut[15:0];
       Result[31:16] = Operand1[31:16]; 
       Result[47:32] = divOut[47:32];
       Result[63:48] = Operand3[31:16];  
      end
     default:
      begin 
       dividend = {Operand1[31:0], Operand3[31:0]};       
       divisor  = Operand2[31:0];
       Result[63:0] = divOut[63:0];
      end
    endcase
     flush = 1'b0;
   end
/* ************************************* */
  11'd154: // IDIV - Signed divide
   begin
    signed1 = 1'b1;
    case(OPSize)
     2'b00:
      begin 
       dividend = {{48{Operand3[15]}},Operand3[15:0]};
       divisor  =  {{24{Operand2[7]}},Operand2[7:0]};
       Result[39:32] = divOut[39:32];
       Result[47:40] = divOut[7:0];
       Result[63:48] = Operand3[31:16];
       Result[31:0] = Operand1;
      end
     2'b01:
      begin 
       dividend = {{32{Operand1[15]}},{Operand1[15:0],Operand3[15:0]}};
       divisor  =  {{16{Operand2[15]}},Operand2[15:0]};
       Result[15:0] = divOut[15:0];
       Result[31:16] = Operand1[31:16];
       Result[47:32] = divOut[47:32];
       Result[63:48] =  Operand3[31:16];
      end
     default:
      begin 
       dividend = {Operand1[31:0], Operand3[31:0]};
       divisor  = Operand2[31:0];    
       Result[63:0] = divOut[63:0];
      end
    endcase
     flush = 1'b0;
   end
/* ************************************* */
  11'd155, 11'd411, 11'd443: // IMUL - Signed multiplication
   begin
    sign = 1'b1;
    case(OPSize)
     2'b00:
      begin
       multiplicand ={{24{Operand1[7]}},Operand1[7:0]};
       multiplier = {{24{Operand2[7]}},Operand2[7:0]};
       Result[15:0] = product[15:0];
       Result[31:16] = Operand1[31:16];
       Result[63:32] = (Operation[8]==1'b1 && Operation[5]!=1'b1)?Operand3:Operand2;
       EflagsOut[`CF] = (Operation[8]==1'b0 || Operation[5]==1'b1)?(product[63:16]!=48'd0 ? 1'b1: 1'b0):((product[15:8]!=8'd0 && product[15:7]!=9'h1ff)? 1'b1 : 1'b0);
       EflagsOut[`OF] = (Operation[8]==1'b0 || Operation[5]==1'b1)?(product[63:16]!=48'd0 ? 1'b1: 1'b0):((product[15:8]!=8'd0 && product[15:7]!=9'h1ff)? 1'b1 : 1'b0);
      end
     2'b01:
      begin
       multiplicand = (Operation[8] == 1'b0)? {{16{Operand2[15]}},Operand2[15:0]} : {{16{Operand1[15]}},Operand1[15:0]};
       multiplier = (Operation[8]== 1'b0)?{{16{Operand3[15]}},Operand3[15:0]}:{{16{Operand2[15]}},Operand2[15:0]};
       Result[15:0] = product[15:0];
       Result[31:16] = Operand1[31:16];
       Result[63:32] = (Operation[8]==1'b1 && Operation[5]!=1'b1)?{Operand3[31:16],product[31:16]}:Operand2;
       EflagsOut[`CF] = (Operation[8]==1'b0 || Operation[5]==1'b1)?(product[63:16]==48'd0 ? (product[15] == 1'b1 ? 1'b1 : 1'b0):(product[63:15]==49'h1ffffffffffff ? 1'b0 : 1'b1)):((product[31:16]!=16'd0 && product[31:15]!=17'h1ffff)? 1'b1 : 1'b0);
       EflagsOut[`OF] = (Operation[8]==1'b0 || Operation[5]==1'b1)?(product[63:16]==48'd0 ? (product[15] == 1'b1 ? 1'b1 : 1'b0):(product[63:15]==49'h1ffffffffffff ? 1'b0 : 1'b1)):((product[31:16]!=16'd0 && product[31:15]!=17'h1ffff)? 1'b1 : 1'b0);     
      end
     default:
      begin
       multiplicand = (Operation[8] == 1'b1) ? Operand1 : Operand2;
       multiplier = (Operation[8] == 1'b1) ? Operand2 : Operand3;
       Result[31:0] = product[31:0];
       Result[63:32] = (Operation[8]==1'b1 && Operation[5]!=1'b1)?product[63:32]:Operand2;
       EflagsOut[`CF] = (Operation[8]==1'b0 || Operation[5]==1'b1)?(product[63:32]==32'd0 ? (product[31]== 1'b1 ? 1'b1 : 1'b0):(product[63:31]==33'h1ffffffff ?1'b0 : 1'b1)) : ((product[63:32]!=32'd0 && product[63:31]!=33'h1ffffffff)? 1'b1 : 1'b0);
       EflagsOut[`OF] = (Operation[8]==1'b0 || Operation[5]==1'b1)?(product[63:32]==32'd0 ? (product[31]== 1'b1 ? 1'b1 : 1'b0):(product[63:31]==33'h1ffffffff ?1'b0 : 1'b1)) : ((product[63:32]!=32'd0 && product[63:31]!=33'h1ffffffff)? 1'b1 : 1'b0);
      end
    endcase
     flush = 1'b0;
   end
/* ************************************* */
  11'd157: // INC - Increment by 1
   begin
    case(OPSize)
     2'b00:
      begin
       cla1Op1 = Operand1[7:0];
       cla1Op2 = 8'd1;
       cIn1 = 0;
       Result[7:0] = cla1Out[7:0];
       Result[15:8] =  Operand1[15:8];
       Result[31:16] = Operand1[31:16];
       Result[63:32] = Operand2;
       EflagsOut[`SF] = cla1Out[7];
       zfIn = cla1Out[7:0];
       EflagsOut[`ZF] = zfOut;
       ofCin = carryOut1[7];
       ofCout = carryOut1[8];
       EflagsOut[`OF] = ofOut;
      end
     2'b01:
      begin
       cla1Op1 = Operand1[15:0];
       cla1Op2 = 16'd1;
       cIn1 = 0;
       Result[15:0] = cla1Out[15:0];
       Result[31:16] = Operand1[31:16];
       Result[63:32] = Operand2;
       EflagsOut[`SF] = cla1Out[15];
       zfIn = cla1Out[15:0];
       EflagsOut[`ZF] = zfOut;
       ofCin = carryOut1[15];
       ofCout = carryOut1[16];
       EflagsOut[`OF] = ofOut;
      end
     default:
      begin
       cla1Op1 = Operand1[31:0];
       cla1Op2 = 32'd1;
       cIn1 = 0;
       Result[31:0] = cla1Out[31:0];
       Result[63:32] = Operand2;
       EflagsOut[`SF] = cla1Out[31];
       zfIn = cla1Out[31:0];
       EflagsOut[`ZF] = zfOut;
       ofCin = carryOut1[31];
       ofCout = carryOut1[32];
       EflagsOut[`OF] = ofOut;
      end
    endcase
    pfIn = cla1Out[7:0];
    EflagsOut[`PF] = pfOut;
    EflagsOut[`AF] = carryOut1[4];
     flush = 1'b0;
   end
/* ************************************* */
   11'd165:    // jump if OVERflow ( JO )
      begin
        if(EflagsIn[`OF])
          begin
	     cla1Op1 = Operand2; 
             cla1Op2 = oldPC;
             cIn1 = 1'b0;
             newPC = (OPSize == 2'b01)?{16'd0,cla1Out[15:0]}:cla1Out;  
             flush = 1'b1;
          end
         else
           begin newPC = oldPC; flush = 1'b0; end    
         Result[31:0] = Operand1;    
      end   
/* ************************************* */
   11'd166:    // jump if not OVERflow ( JNO )
      begin
        if(!EflagsIn[`OF])
          begin
	     cla1Op1 = Operand2; 
             cla1Op2 = oldPC;
             cIn1 = 1'b0;
             newPC = (OPSize == 2'b01)?{16'd0,cla1Out[15:0]}:cla1Out;  
             flush = 1'b1;
          end
         else
           begin newPC = oldPC; flush = 1'b0; end   
         Result[31:0] = Operand1;
      end  
/* ************************************* */
   11'd167:    // jump if not above or equal ( JNAE or JB or JC )
      begin
        if(EflagsIn[`CF])
          begin
	     cla1Op1 = Operand2; 
             cla1Op2 = oldPC;
             cIn1 = 1'b0;
             newPC = (OPSize == 2'b01)?{16'd0,cla1Out[15:0]}:cla1Out;  
             flush = 1'b1;
          end
         else
           begin newPC = oldPC; flush = 1'b0; end    
         Result[31:0] = Operand1; 
      end  
/* ************************************* */
   11'd168:    // jump if not below or if no carry ( JAE or JNB or JNC )
      begin
        if(!EflagsIn[`CF])
          begin
	     cla1Op1 = Operand2; 
             cla1Op2 = oldPC;
             cIn1 = 1'b0;
             newPC = (OPSize == 2'b01)?{16'd0,cla1Out[15:0]}:cla1Out;  
             flush = 1'b1;
          end
         else
           begin newPC = oldPC; flush = 1'b0; end   
         Result[31:0] = Operand1; 
      end  
/* ************************************* */
   11'd169:    // jump if Zero ( JZ or JE )
      begin
        if(EflagsIn[`ZF])
          begin

	     cla1Op1 = Operand2; 
             cla1Op2 = oldPC;
             cIn1 = 1'b0;
             newPC = (OPSize == 2'b01)?{16'd0,cla1Out[15:0]}:cla1Out;  
             flush = 1'b1;
          end
         else
           begin newPC = oldPC; flush = 1'b0; end    
         Result[31:0] = Operand1;


      end  
/* ************************************* */
   11'd170:    // jump if not zero or if not equal ( JNE or JNZ )
      begin
        if(!EflagsIn[`ZF])
          begin
	     cla1Op1 = Operand2; 
             cla1Op2 = oldPC;
             cIn1 = 1'b0;
             newPC = (OPSize == 2'b01)?{16'd0,cla1Out[15:0]}:cla1Out;  
             flush = 1'b1;
          end
         else
           begin newPC = oldPC; flush = 1'b0; end    
         Result[31:0] = Operand1;
      end  
/* ************************************* */
   11'd171:    // jump if not above ( JNA or JBE )
      begin
        if(EflagsIn[`CF] || EflagsIn[`ZF])
          begin
	     cla1Op1 = Operand2; 
             cla1Op2 = oldPC;
             cIn1 = 1'b0;
             newPC = (OPSize == 2'b01)?{16'd0,cla1Out[15:0]}:cla1Out;  
             flush = 1'b1;
          end
         else
           begin newPC = oldPC; flush = 1'b0; end    
         Result[31:0] = Operand1;
      end  
/* ************************************* */
   11'd172:    // jump if not below or equal ( JNBE or JA )
      begin
        if(!EflagsIn[`CF] && !EflagsIn[`ZF])
          begin
	     cla1Op1 = Operand2; 
             cla1Op2 = oldPC;
             cIn1 = 1'b0;
             newPC = (OPSize == 2'b01)?{16'd0,cla1Out[15:0]}:cla1Out;  
             flush = 1'b1;
          end
         else
           begin newPC = oldPC; flush = 1'b0; end    
         Result[31:0] = Operand1;
      end  
/* ************************************* */
   11'd173:    // jump if sign ( JS )
      begin
        if(EflagsIn[`SF])
          begin
	     cla1Op1 = Operand2; 
             cla1Op2 = oldPC;
             cIn1 = 1'b0;
             newPC = (OPSize == 2'b01)?{16'd0,cla1Out[15:0]}:cla1Out;  
             flush = 1'b1;
          end
         else
           begin newPC = oldPC; flush = 1'b0; end    
         Result[31:0] = Operand1;
      end  
/* ************************************* */
   11'd174:    // jump if not sign ( JNS )
      begin
        if(!EflagsIn[`SF])
          begin
	     cla1Op1 = Operand2; 
             cla1Op2 = oldPC;
             cIn1 = 1'b0;
             newPC = (OPSize == 2'b01)?{16'd0,cla1Out[15:0]}:cla1Out;  
             flush = 1'b1;
          end
         else
           begin newPC = oldPC; flush = 1'b0; end    
         Result[31:0] = Operand1;
      end  
/* ************************************* */
   11'd175:    // jump if parity ( JP or JPE )
      begin
        if(EflagsIn[`PF])
          begin
	     cla1Op1 = Operand2; 
             cla1Op2 = oldPC;
             cIn1 = 1'b0;
             newPC = (OPSize == 2'b01)?{16'd0,cla1Out[15:0]}:cla1Out;  
             flush = 1'b1;
          end
         else
           begin newPC = oldPC; flush = 1'b0; end    
         Result[31:0] = Operand1;
      end  
/* ************************************* */
   11'd176:    // jump if not parity ( JNP or JPO )
      begin
        if(!EflagsIn[`PF])
          begin
	     cla1Op1 = Operand2; 
             cla1Op2 = oldPC;
             cIn1 = 1'b0;
             newPC = (OPSize == 2'b01)?{16'd0,cla1Out[15:0]}:cla1Out;  
             flush = 1'b1;
          end
         else
           begin newPC = oldPC; flush = 1'b0; end   
         Result[31:0] = Operand1;  
      end  
/* ************************************* */
   11'd177:    // jump if less or not greater and equal ( JL or JNGE )
      begin
        if(EflagsIn[`SF]!=EflagsIn[`OF])
          begin
	     cla1Op1 = Operand2; 
             cla1Op2 = oldPC;
             cIn1 = 1'b0;
             newPC = (OPSize == 2'b01)?{16'd0,cla1Out[15:0]}:cla1Out;  
             flush = 1'b1;
          end
         else
           begin newPC = oldPC; flush = 1'b0; end    
         Result[31:0] = Operand1;
      end  
/* ************************************* */
   11'd178:    // jump if greater or equal and not less ( JGE or JNL )
      begin
        if(EflagsIn[`SF]==EflagsIn[`OF])
          begin
	     cla1Op1 = Operand2; 
             cla1Op2 = oldPC;
             cIn1 = 1'b0;
             newPC = (OPSize == 2'b01)?{16'd0,cla1Out[15:0]}:cla1Out;  
             flush = 1'b1;
          end
         else
           begin newPC = oldPC; flush = 1'b0; end    
         Result[31:0] = Operand1;
      end  
/* ************************************* */
   11'd179:    // jump if less or equal and not greater ( JLE or JNG )
      begin
        if(EflagsIn[`ZF] || EflagsIn[`SF]!=EflagsIn[`OF])
          begin
	     cla1Op1 = Operand2; 
             cla1Op2 = oldPC;
             cIn1 = 1'b0;
             newPC = (OPSize == 2'b01)?{16'd0,cla1Out[15:0]}:cla1Out;  
             flush = 1'b1;
          end
         else
           begin newPC = oldPC; flush = 1'b0; end    
         Result[31:0] = Operand1;
      end  
/* ************************************* */
   11'd180:    // jump if not less or equal ( JNLE or JG )
      begin
        if(!EflagsIn[`ZF] && EflagsIn[`SF]==EflagsIn[`OF])
          begin
	     cla1Op1 = Operand2; 
             cla1Op2 = oldPC;
             cIn1 = 1'b0;
             newPC = (OPSize == 2'b01)?{16'd0,cla1Out[15:0]}:cla1Out;  
             flush = 1'b1;
          end
         else
           begin newPC = oldPC; flush = 1'b0; end    
         Result[31:0] = Operand1;
      end
/* ************************************* */
   11'd181:   // LOOPNZ / LOOPNE
      begin
        if(adSize == 1'b1)
            cla1Op1 =  Operand1;
        else
            cla1Op1 = {16'd0,Operand1[15:0]};
        cla1Op2 = 32'hffffffff;
        zfIn = cla1Out;
        if(!EflagsIn[`ZF] && !zfOut)
          begin
            cla2Op1 = oldPC;
            cla2Op2 = Operand2;
            newPC = (OPSize == 2'b01) ? {16'd0,cla2Out[15:0]} : cla2Out;
            flush = 1'b1;
          end
        else
          begin newPC = oldPC; flush = 1'b0; end 
        Result[31:0] = cla1Out;
      end  
/*****************************************/
   11'd184: // Load Status flags into the AH register
    begin
     Result[15:8] = Operand1[7:0];
     Result[7:0] = {EflagsIn[`SF], EflagsIn[`ZF], 1'b0, EflagsIn[`AF], 1'b0, EflagsIn[`PF], 1'b1, EflagsIn[`CF]}; 
     Result[31:16] = 16'd0;
     Result[63:32] = Operand2;
     flush = 1'b0;
    end
/* ************************************* */
   11'd200:   // jump depending on ecxz value ( JCXZ or JECXZ )
     begin
       zfIn = Operand1;
       cla1Op1 = Operand2;
       cla1Op2 = oldPC; 
       if(zfOut)
        begin
         newPC = (OPSize == 2'b01)?{16'd0,cla1Out[15:0]}:cla1Out;    
         flush = 1'b1;
        end
       else
         begin newPC = oldPC; flush = 1'b0; end   
       Result[31:0] = Operand1;
     end 
/* *************************************************** */
   11'd201:    // LOOP
     begin
       if(adSize == 1'b1)
          cla1Op1 = Operand1;
       else
          cla1Op1 = {16'd0,Operand1[15:0]};
       cla1Op2 = 32'hffffffff;
       zfIn = cla1Out;
       if(!zfOut)
         begin
           cla2Op1 = oldPC;
           cla2Op2 = Operand2;
           newPC = (OPSize == 2'b01)? {16'd0,cla2Out[15:0]} : cla2Out;
           flush = 1'b1;
         end       
       else
         begin newPC = oldPC; flush = 1'b0; end 
       Result[31:0] = cla1Out;  
     end  
/* *************************************************** */
   11'd202:  // LOOPE / LOOPZ
     begin
       if(adSize == 1'b1)
          cla1Op1 = Operand1;
       else
          cla1Op1 = {16'd0, Operand1[15:0]};  
       cla1Op2 = 32'hffffffff;
       zfIn = cla1Out;
       if(EflagsIn[`ZF] && !zfOut)  
         begin
           cla2Op1 = oldPC;
           cla2Op2 = Operand2;
           newPC = (OPSize == 2'b01)? {16'd0,cla2Out[15:0]} : cla2Out;
           flush = 1'b1;           
         end
       else
         begin newPC = oldPC; flush = 1'b0; end  
       Result[31:0] = cla1Out;
     end    
/* *************************************************** */ 
   11'd217: // MOV TO/FROM CONTROL REGISTERS
    begin
     Result[31:0] = Operand2;
     Result[63:32] = Operand2;
     flush = 1'b0;
    end
/* *************************************************** */
   11'd241: //MOVSX  Move with Sign-Extension
   begin
     case(OPSize)
      2'b00: Result[31:0] = {{24{Operand2[7]}},Operand2[7:0]};
      2'b01: Result[31:0] = {{16{Operand2[15]}},Operand2[15:0]};
      default: Result[31:0] = Operand2;
     endcase
     Result[63:32] = Operand2;
     flush = 1'b0;
   end
/* *************************************************** */
   11'd244: //MOVZX Move eith Zero-Extend
   begin

     case(OPSize)
      2'b00: Result[31:0] = {24'd0,Operand2[7:0]};
      2'b01: Result[31:0] = {16'd0,Operand2[15:0]};
      default: Result[31:0] = Operand2;
     endcase
     Result[63:32] = Operand2;
     flush = 1'b0;
   end

/* *************************************************** */

  11'd245: // MUL - unsigned multiplication
   begin
    sign = 1'b0;
    case(OPSize)
     2'b00:
      begin
       multiplicand = Operand1[7:0];
       multiplier = Operand2[7:0];
       Result[15:0] = product[15:0];
       Result[31:16] = product[31:16];
       Result[63:32] = Operand2;
       zfIn = product[15:8];
       EflagsOut[`OF] = !zfOut;
       EflagsOut[`CF] = !zfOut;
      end
     2'b01:
      begin
       multiplicand = Operand1[15:0];
       multiplier = Operand2[15:0];
       Result[31:0] = product[31:0];
       Result[63:32] = product[47:16];
       zfIn = product[31:16];
       EflagsOut[`OF] = !zfOut;
       EflagsOut[`CF] = !zfOut;
      end
     default:
      begin
       multiplicand = Operand1[31:0];
       multiplier = Operand2[31:0];
       Result[63:0] = product[63:0];
       zfIn = product[63:32];
       EflagsOut[`OF] = !zfOut;
       EflagsOut[`CF] = !zfOut;
      end
    endcase
    flush = 1'b0;
   end
/* ************************************* */
  11'd250: // NEG - Two's Complement Negation 
   begin // Check it once
    twosCompIn1 = Operand1[31:0];
    
    case(OPSize)
     2'b00:
      begin
       Result[7:0] = twosCompOut1[7:0];
       Result[15:8] = Operand1[15:8];
       Result[31:16] = Operand1[31:16];
       Result[63:32] =  Operand2;
       if(Operand1[7:0] == 8'd0)
         EflagsOut[`CF] = 1'b0;
       else
         EflagsOut[`CF] = 1'b1;
       EflagsOut[`SF] = twosCompOut1[7];
       zfIn = Result[7:0];
       EflagsOut[`OF] = ( Operand1[7] && Result[7] ) ? 1'b1: 1'b0;
      end
     2'b01:
      begin
       Result[15:0] = twosCompOut1[15:0];
       Result[31:16] = Operand1[31:16];
       Result[63:32] = Operand2;
       if(Operand1[15:0] == 16'd0)
        EflagsOut[`CF] = 1'b0;
       else
        EflagsOut[`CF] = 1'b1;
       EflagsOut[`SF] = twosCompOut1[15];
       zfIn = Result[15:0];
       EflagsOut[`OF] = ( Operand1[15] && Result[15] ) ? 1'b1: 1'b0;
      end
     default:
      begin
       Result[31:0] = twosCompOut1[31:0];
       Result[63:32] = Operand2;
       if(Operand1[31:0] == 32'd0)
        EflagsOut[`CF] = 1'b0;
       else
        EflagsOut[`CF] = 1'b1;
       EflagsOut[`SF] = twosCompOut1[31];
       zfIn = Result[31:0]; 
       EflagsOut[`OF] = ( Operand1[31] && Result[31] ) ? 1'b1: 1'b0;
      end
    endcase
    pfIn = twosCompOut1[7:0];
    EflagsOut[`PF] = pfOut;
    EflagsOut[`ZF] = zfOut;
    EflagsOut[`AF] = Operand1[3:0] != 0 ? 1'b1 : 1'b0; 
    flush = 1'b0;

   end
/* ************************************* */
   11'd251: // NOP - No Operation. Exchanges EAX with EAX register.
    begin
     Result[31:0] = Operand2[31:0];
     Result[63:32] = Operand1[31:0];
    flush = 1'b0;
    end
/* ************************************* */
   11'd252: // NOT - One's Complement Negation
    begin
     onesCompIn = Operand1[31:0];
     case(OPSize)
      2'b00:
       begin
        Result[7:0] = onesCompOut[7:0];
        Result[15:8] = Operand1[15:8];
        Result[31:16] = Operand1[31:16];
        Result[63:32] = Operand2;
       end
      2'b01:
       begin
        Result[15:0] = onesCompOut[15:0];
        Result[31:16] = Operand1[31:16];
        Result[63:32] = Operand2;
       end
      default:
       begin
        Result[31:0] = onesCompOut[31:0];
        Result[63:32] = Operand2;
       end
     endcase
    flush = 1'b0;
    end
/* ************************************* */
   11'd253: // OR - Logical Inclusive OR
    begin
     orIn1 = Operand1;
     orIn2 = Operand2;
     case(OPSize)
      2'b00:
       begin
        Result[7:0] = orOut[7:0];
        Result[15:8] = Operand1[15:8];
        Result[31:16] = Operand1[31:16];
        Result[63:32] =  Operand2;
        EflagsOut[`SF] = orOut[7];
        zfIn = orOut[7:0];
        EflagsOut[`ZF] = zfOut;
       end
      2'b01:
       begin
        Result[15:0] = orOut[15:0];
        Result[31:16] = Operand1[31:16];
        Result[63:32] = Operand2;
        EflagsOut[`SF] = orOut[15];
        zfIn = orOut[15:0];
        EflagsOut[`ZF] = zfOut;
       end
      default:
       begin
        Result[31:0] = orOut[31:0];
        Result[63:32] = Operand2;
        EflagsOut[`SF] = orOut[31];
        zfIn = orOut[31:0];
        EflagsOut[`ZF] = zfOut;
       end
     endcase
     EflagsOut[`CF] = 1'b0;
     EflagsOut[`OF] = 1'b0;
     pfIn = orOut[7:0];
     EflagsOut[`PF] = pfOut;
    flush = 1'b0;
    end
/*****************************************/
   11'd282:    // POPFD
     begin
       cla1Op1 = Operand1;
       cla1Op2 = 32'd4;
       Result[31:0] = cla1Out; 
       EflagsOut = 32'd2; 
       flush = 1'b0;
     end
/* ***************************************/
   11'd301:     //PUSH
     begin
       Result[31:0] = Operand1;
       if(adSize == 1'b1)
         begin 
           if(OPSize == 1'b1)
             begin
               cla1Op1 = Operand2;
               cla1Op2 = 32'd4; 
             end
           else
             begin
               cla1Op1 = Operand2;
               cla1Op2 = 32'd2;
             end
         end
       else
         begin
           if(OPSize == 1'b1)
             begin
               cla1Op1 = {16'd0,Operand2[15:0]};
               cla1Op2 = 32'd4;
             end
           else
             begin
               cla1Op1 = {16'd0,Operand2[15:0]};
               cla1Op2 = 32'd2;
             end    
         end        
       Result[63:32] = cla1Out;
     end
/* ************************************* */
   11'd305: //  - Rotate Left Through Carry
    begin
     rotateBitIn = EflagsIn[`CF];
     direction2 = 1'b0;
     case(OPSize)
      2'b00:
       begin
        dividend = {27'd0,Operand2[4:0]};
        divisor = 32'd9;
        count = divOut[4:0];
        rotateIn = {4{Operand1[7:0]}};
        Result[7:0] = rotateOut2[7:0];
        Result[15:8] = Operand1[15:8];
        Result[31:16] = Operand1[31:16];
        Result[63:32] = Operand2;
          ofCin = rotateOut2[7];
          ofCout = rotateBitOut2;
          EflagsOut[`OF] = (|count == 1'b1) ? ofOut : EflagsIn[`OF];
       end
      2'b01:
       begin
        dividend = {27'd0,Operand2[4:0]};
        divisor = 32'd17;
        count = divOut[4:0];
        rotateIn = {2{Operand1[15:0]}};
        Result[15:0] = rotateOut2[15:0];
        Result[31:16] = Operand1[31:16];
        Result[63:32] = Operand2;
          ofCin = rotateOut2[15];
          ofCout = rotateBitOut2;
          EflagsOut[`OF] = (|count == 1'b1) ? ofOut : EflagsIn[`OF];
       end
      default:
       begin
        dividend = 4;
        divisor = 2;
        count = Operand2[4:0];
        rotateIn = Operand1[31:0];
        Result[31:0] = rotateOut2[31:0];
        Result[63:32] = Operand2;
          ofCin = rotateOut2[31];
          ofCout = rotateBitOut2;
          EflagsOut[`OF] = (|count == 1'b1) ? ofOut : EflagsIn[`OF];
       end
     endcase
     EflagsOut[`CF] = rotateBitOut2;
    flush = 1'b0;
    end
/* ************************************* */
   11'd306: //  - Rotate Right Through Carry
    begin
     rotateBitIn = EflagsIn[`CF];
     direction2 = 1'b1;
     case(OPSize)
      2'b00:
       begin
        dividend = Operand2[4:0];
        divisor = 32'd9;
        count = divOut[4:0];
        rotateIn = {4{Operand1[7:0]}};
        Result[7:0] = rotateOut2[31:24];
        Result[15:8] = Operand1[15:8];
        Result[31:16] = Operand1[31:16];
        Result[63:32] =  Operand2;
          ofCin = Result[7];
          ofCout = Result[6];
          EflagsOut[`OF] = (|count == 1'b1) ? ofOut : EflagsIn[`OF]; 
       end
      2'b01:
       begin
        dividend = Operand2[4:0];
        divisor = 32'd17;
        count = divOut[4:0];
        rotateIn = {2{Operand1[15:0]}};
        Result[15:0] = rotateOut2[31:16];
        Result[31:16] = Operand1[31:16];
        Result[63:32] = Operand2;
          ofCin = Result[15];
          ofCout = Result[14];
          EflagsOut[`OF] =  (|count == 1'b1) ? ofOut : EflagsIn[`OF];
       end
      default:
       begin
        dividend = 4;
        divisor = 2;
        count = Operand2[4:0];
        rotateIn = Operand1[31:0];
        Result[31:0] = rotateOut2[31:0];
        Result[63:32] = Operand2;
          ofCin = Result[31];
          ofCout = Result[30]; 
          EflagsOut[`OF] =  (|count == 1'b1) ? ofOut : EflagsIn[`OF];
       end
     endcase
     EflagsOut[`CF] = rotateBitOut2;
    flush = 1'b0;
    end
/* ************************************* */
   11'd323:   // Rotate left 
     begin
     rotateBitIn = Operand1[31];
     direction1 = 1'b0;
     case(OPSize)
      2'b00:
       begin
        count = {2'b00,Operand2[2:0]};
        rotateIn = {4{Operand1[7:0]}};
        Result[7:0] = rotateOut1[31:24];
        Result[15:8] = Operand1[15:8];
        Result[31:16] = Operand1[31:16];
        Result[63:32] =  Operand2;
          ofCin = rotateOut1[31];
          ofCout = rotateOut1[0];
        if(|Operand2[4:0] == 1'b1)
          EflagsOut[`OF] = ofOut;
       end
      2'b01:
       begin
        count = {1'b0,Operand2[3:0]};      
        rotateIn = {2{Operand1[15:0]}};
        Result[15:0] = rotateOut1[31:16];
        Result[31:16] = Operand1[31:16];
        Result[63:32] = Operand2;
          ofCin = rotateOut1[31];
          ofCout = rotateOut1[0];
        if(|Operand2[4:0] == 1'b1)
          EflagsOut[`OF] = ofOut;
       end
      default:
       begin
        count = Operand2[4:0];
        rotateIn = Operand1[31:0];
        Result[31:0] = rotateOut1[31:0];
        Result[63:32] = Operand2;
          ofCin = rotateOut1[31];
          ofCout = rotateOut1[0];
        if(|Operand2[4:0] == 1'b1)
          EflagsOut[`OF] = ofOut;
       end
     endcase
     EflagsOut[`CF] = (|Operand2[4:0] == 1'b1) ? Result[0] : EflagsIn[`CF];
    flush = 1'b0;
  
     end
/* ************************************* */
   11'd324:   // Rotate right 
     begin
     rotateBitIn = Operand1[31];
     direction1 = 1'b1;
     case(OPSize)
      2'b00:
       begin
        count = {2'b00,Operand2[2:0]};
        rotateIn = {4{Operand1[7:0]}};
        Result[7:0] = rotateOut1[31:24];
        Result[15:8] = Operand1[15:8];
        Result[31:16] = Operand1[31:16];
        Result[63:32] =  Operand2;
        EflagsOut[`CF] = rotateOut1[31];
          ofCin = rotateOut1[7];
          ofCout = rotateOut1[6];
        if(|Operand2[4:0] == 1'b1)
          EflagsOut[`OF] =  ofOut;
       end
      2'b01:
       begin
        count = {1'b0,Operand2[3:0]};      
        rotateIn = {2{Operand1[15:0]}};
        Result[15:0] = rotateOut1[15:0];
        Result[31:16] = Operand1[31:16];
        Result[63:32] = Operand2;
        EflagsOut[`CF] = rotateOut1[15];
          ofCin = rotateOut1[15];
          ofCout = rotateOut1[14];
        if(|Operand2[4:0] == 1'b1)
          EflagsOut[`OF] =  ofOut;
       end
      default:
       begin
        count = Operand2[4:0];
        rotateIn = Operand1[31:0];
        Result[31:0] = rotateOut1[31:0];
        Result[63:32] = Operand2;
          ofCin = rotateOut1[31];
          ofCout = rotateOut1[30];
        if(|Operand2[4:0] == 1'b1)
          EflagsOut[`OF] =  ofOut;
       end
     endcase
     EflagsOut[`CF] = (|count == 1'b1) ? rotateOut1[31] : EflagsIn[`CF];
    flush = 1'b0;
  
     end

/*****************************************/
   11'd328: // SAHF - Store AH into Flags
    begin
     EflagsOut[`CF] = Operand1[8];
     EflagsOut[1] = 1'b1;
     EflagsOut[`PF] = Operand1[10];
     EflagsOut[3] = 1'b0;
     EflagsOut[`AF] = Operand1[12];
     EflagsOut[5] = 1'b0;
     EflagsOut[`ZF] = Operand1[14];
     EflagsOut[`SF] = Operand1[15];
     Result[31:0] = Operand1;
    flush = 1'b0; 
    end
/* ************************************* */
   11'd329 : //  - SHL/SAL ... Shift Logical Left/ Shift Arithmetic Left
    begin
    count = Operand2[4:0];
    direction = 1'b0;
    shiftBitIn1 = EflagsIn[`CF];
     case(OPSize)
      2'b00:
       begin
        shiftIn = {Operand1[7:0],24'd0};
        Result[7:0] = shiftOut1[31:24];
        Result[15:8] = Operand1[15:8];
        Result[31:16] = Operand1[31:16];
        Result[63:32] =  Operand2;
 if(count == 5'd1)
         begin
          ofCin = Operand1[7];
          ofCout = Operand1[6];
          EflagsOut[`OF] = ofOut;
         end
        else
         EflagsOut[`OF] = EflagsIn[`OF];
        zfIn = shiftOut1[31:24];
        EflagsOut[`SF] = (|Operand2[4:0] == 1'b0) ? EflagsIn[`SF] :shiftOut1[7];
        EflagsOut[`CF] = shiftBitOut1;
       end
      2'b01:
       begin
        shiftIn = {Operand1[15:0],16'd0};
        Result[15:0] = shiftOut1[31:16];
        Result[31:16] = Operand1[31:16];
        Result[63:32] =  Operand2;
        if(count == 5'd1)
         begin
          ofCin = Operand1[15];
          ofCout = Operand1[14];
          EflagsOut[`OF] = ofOut;
         end
        else
         EflagsOut[`OF] = EflagsIn[`OF];
        zfIn = shiftOut1[31:16];
        EflagsOut[`SF] = (|Operand2[4:0] == 1'b0) ? EflagsIn[`SF] : shiftOut1[15];
        EflagsOut[`CF] = shiftBitOut1;
       end
      default:
       begin
        shiftIn = Operand1[31:0];
        Result[31:0] = shiftOut1[31:0];
        Result[63:32] =  Operand2;
       if(count == 5'd1)
         begin
          ofCin = Operand1[31];
          ofCout = Operand1[30];
          EflagsOut[`OF] = ofOut;
         end
        else
         EflagsOut[`OF] = EflagsIn[`OF];
        zfIn = shiftOut1[31:0];
        EflagsOut[`SF] = (Operand2[4:0] == 5'd0) ? EflagsIn[`SF] : shiftOut1[31];
        EflagsOut[`CF] = shiftBitOut1;
       end
    endcase
     pfIn = Result[7:0];
     EflagsOut[`ZF] = (|Operand2[4:0] == 1'b0) ? EflagsIn[`ZF] : zfOut;
     EflagsOut[`PF] = (|Operand2[4:0] == 1'b0) ? EflagsIn[`PF] : pfOut;
    flush = 1'b0;
    end
 
/* ************************************* */
   11'd330: //  - SAR ... Shift Arithmetic Right
    begin
    count = Operand2[4:0];
    shiftBitIn2 = EflagsIn[`CF];
     case(OPSize)
      2'b00:
       begin
        shiftIn = {{24{Operand1[7]}},Operand1[7:0]};
        Result[7:0] = shiftOut2[7:0];
        Result[15:8] = Operand1[15:8];
        Result[31:16] = Operand1[31:16];
        Result[63:32] =  Operand2;
        zfIn = shiftOut2[31:24];
        pfIn = shiftOut2[31:24];
       end
      2'b01:
       begin
        shiftIn = {{16{Operand1[15]}},Operand1[15:0]};
        Result[15:0] = shiftOut2[15:0];
        Result[31:16] = Operand1[31:16];
        Result[63:32] = Operand2;
        zfIn = shiftOut2[31:16];
        pfIn = shiftOut2[23:16];
       end
      default:
       begin
        shiftIn = Operand1[31:0];
        Result[31:0] = shiftOut2[31:0];
        Result[63:32] = Operand2;
        zfIn = shiftOut2[31:0];
        pfIn = shiftOut2[7:0];
       end
     endcase
     if(count == 5'd1)
      EflagsOut[`OF] = 1'b0;
     else
      EflagsOut[`OF] = EflagsIn[`OF];
     EflagsOut[`CF] = shiftBitOut2;
     EflagsOut[`SF] =  (Operand2 == 32'd0) ? EflagsIn[`SF] :shiftOut2[31];
     EflagsOut[`ZF] =  (Operand2 == 32'd0) ? EflagsIn[`ZF] :zfOut;
     EflagsOut[`PF] =  (Operand2 == 32'd0) ? EflagsIn[`PF] :pfOut;
    flush = 1'b0;
    end
/* ************************************* */
   11'd325: //  - SHR ... Shift Logical Right
    begin
    count = Operand2[4:0];
    direction = 1'b1;
    shiftBitIn1 = EflagsIn[`CF];
     case(OPSize)
      2'b00:
       begin
        shiftIn = {24'd0,Operand1[7:0]};
        Result[7:0] = shiftOut1[7:0];
        Result[15:8] = Operand1[15:8];
        Result[31:16] = Operand1[31:16];
        Result[63:32] =  Operand2;
        if(count == 5'd1)
         EflagsOut[`OF] = Operand1[7];
        else
         EflagsOut[`OF] = EflagsIn[`OF];
        zfIn = shiftOut1[7:0];
        pfIn = shiftOut1[7:0];
        EflagsOut[`SF] =  (Operand2 == 32'd0) ? EflagsIn[`SF] :shiftOut1[7]; 
        EflagsOut[`CF] =(|Operand2[4:3] == 1'b1 ) ? EflagsIn[`CF] : shiftBitOut1;
       end
      2'b01:
       begin
        shiftIn = {16'd0,Operand1[15:0]};
        Result[15:0] = shiftOut1[15:0];
        Result[31:16] = Operand1[31:16];
        Result[63:32] = Operand2;
        if(count == 5'd1)
         EflagsOut[`OF] = shiftOut1[15];//Operand1[15];
        else
         EflagsOut[`OF] = EflagsIn[`OF];
        zfIn = shiftOut1[15:0];
        pfIn = shiftOut1[7:0];
        EflagsOut[`SF] =  (Operand2 == 32'd0) ? EflagsIn[`SF] :shiftOut1[15]; 
        EflagsOut[`CF] =(Operand2[4] == 1'b1) ? EflagsIn[`CF] : shiftBitOut1;

       end
      default:
       begin
        shiftIn = Operand1[31:0];
        Result[31:0] = shiftOut1[31:0];
        Result[63:32] =  Operand2;
        if(count == 5'd1)
         EflagsOut[`OF] = Operand1[31];
        else
         EflagsOut[`OF] = EflagsIn[`OF];
        zfIn = shiftOut1[31:0];
        pfIn = shiftOut1[7:0];
        EflagsOut[`SF] =  (Operand2 == 32'd0) ? EflagsIn[`SF] :shiftOut1[31]; 
        EflagsOut[`CF] = shiftBitOut1;
       end
     endcase
     EflagsOut[`ZF] =  (Operand2 == 32'd0) ? EflagsIn[`ZF] :zfOut;
     EflagsOut[`PF] =  (Operand2 == 32'd0) ? EflagsIn[`PF] :pfOut;
    flush = 1'b0;
    end
/*****************************************/
   11'd351, 11'd352:   // SHLD
     begin
       shldcount = Operand3[4:0];
       case(OPSize)
	  2'b01:
            begin
              if((Operand3[4]== 1'b1 && |Operand3[3:0] == 1'b0) || Operand3[4] == 1'b0)
                begin
                  shldin1 = {2{Operand1[15:0]}};
                  shldin2 = {2{Operand2[15:0]}};
            	  Result[31:0] = {Operand1[31:16],shldout[15:0]};  
                  zfIn = {16'd0,shldout[15:0]};
                  pfIn = shldout[7:0];
                  EflagsOut[`OF] = (Operand3[3:0] == 4'd1) ?(Operand1[15]^Operand2[0]) : EflagsIn[`OF];
                  if(|shldcount)
                    begin
                      EflagsOut[`CF] = shldoutbit;
                      EflagsOut[`SF] = shldout[15];
                      EflagsOut[`ZF] = zfOut;
                      EflagsOut[`PF] = pfOut;
                    end
                end
              else
                begin
                  Result[31:0] = Operand1;
                end 
            end 
          default:
            begin
                  shldin1 = Operand1;
                  shldin2 = Operand2;
            	  Result[31:0] = shldout;  
                  zfIn = shldout;
                  pfIn = shldout[7:0];
                  EflagsOut[`OF] = (Operand3[4:0] == 5'd1) ?(Operand1[31]^Operand2[0])  : EflagsIn[`OF];
                  if(|shldcount)
                    begin
                      EflagsOut[`CF] = shldoutbit;
                      EflagsOut[`SF] = shldout[31];
                      EflagsOut[`ZF] = zfOut;
                      EflagsOut[`PF] = pfOut;
                    end
            end
       endcase 
       Result[63:32] = Operand2;

     end
/*****************************************/
   11'd353, 11'd354:      // SHRD 
     begin
       shrdcount = Operand3[4:0];
       case(OPSize)
	  2'b01:
            begin
              if((Operand3[4]== 1'b1 && |Operand3[3:0] == 1'b0) || Operand3[4] == 1'b0)
                begin
                  shrdin1 = {2{Operand1[15:0]}};
                  shrdin2 = {2{Operand2[15:0]}};
            	  Result[31:0] = {Operand1[31:16],shrdout[31:16]};  
                  zfIn = {16'd0,shrdout[31:16]};
                  pfIn = shrdout[23:16];
                  EflagsOut[`OF] = (Operand3[3:0] == 4'd1) ?(Operand1[15]^Operand2[0]) : EflagsIn[`OF];
                  EflagsOut[`CF] = |Operand3 == 1'b0 ? EflagsIn[`CF] : shrdoutbit;


                  if(|shrdcount)
                    begin
                      EflagsOut[`SF] = shrdout[31];
                      EflagsOut[`ZF] = zfOut;
                      EflagsOut[`PF] = pfOut;
                    end
                end
              else
                begin
                  Result[31:0] = Operand1;
                end 
            end 
          default:
            begin
              if((Operand3[5]== 1'b1 && |Operand3[4:0] == 1'b0) || Operand3[5] == 1'b0)
                begin
                  shrdin1 = Operand1;
                  shrdin2 = Operand2;
            	  Result[31:0] = shrdout;  
                  zfIn = shrdout;
                  pfIn = shrdout[7:0];
                  EflagsOut[`OF] = (Operand3[4:0] == 5'd1) ?(Operand1[31]^Operand2[0])  : EflagsIn[`OF];
                  EflagsOut[`CF] = |Operand3 == 1'b0 ? EflagsIn[`CF] : shrdoutbit;

                  if(|shrdcount)
                    begin
                      EflagsOut[`SF] = shrdout[31];
                      EflagsOut[`ZF] = zfOut;
                      EflagsOut[`PF] = pfOut;
                    end
                end
              else
                begin
                  Result[31:0] = Operand1;
                end
            end
       endcase 




       Result[63:32] = Operand2;
     end
/* ************************************* */
   11'd331: // SBB - Subtraction with Borrow
    begin
     case(OPSize)
      2'b00:
       begin
        cla1Op1 = Operand1[7:0];
        cla2Op1 = Operand2[7:0];
        cla2Op2 = EflagsIn[`CF];
        twosCompIn1 = cla2Out;
        cla1Op2 = twosCompOut1[7:0];
        Result[7:0] = cla1Out[7:0];
        Result[31:8] = Operand1[31:8];
        Result[63:32] = Operand2;
        EflagsOut[`SF] = Result[7];    
        EflagsOut[`CF] = (Operand2[7:0]==8'd0)?1'b0:!carryOut1[8];
        ofCin = carryOut1[7];
        ofCout = carryOut1[8];
       end
      2'b01:
       begin
        cla1Op1 = Operand1[15:0];
        cla2Op1 = Operand2[15:0];
        cla2Op2 = EflagsIn[`CF];
        twosCompIn1 = cla2Out;
        cla1Op2 = twosCompOut1[15:0];
        Result[15:0] = cla1Out[15:0];
        Result[31:16] = Operand1[31:16];
        Result[63:32] = Operand2;
        EflagsOut[`SF] = Result[15];
        EflagsOut[`CF] =(Operand2[15:0]==16'd0)?1'b0:!carryOut1[16];
        ofCin = carryOut1[15];
        ofCout = carryOut1[16];
    end
      default:
       begin
        cla1Op1 = Operand1[31:0];
        cla2Op1 = Operand2[31:0];
        cla2Op2 = EflagsIn[`CF];
        twosCompIn1 = cla2Out;
        cla1Op2 = twosCompOut1[31:0];
        Result[31:0] = cla1Out[31:0];
        Result[63:32] = Operand2;
        EflagsOut[`SF] = Result[31];
        EflagsOut[`CF] = (Operand2==32'd0)?1'b0:!carryOut1[32];
        ofCin = carryOut1[31];
        ofCout = carryOut1[32];
       end
     endcase
     zfIn = Result[31:0];
     pfIn = Result[7:0];
     EflagsOut[`ZF] = zfOut;
     EflagsOut[`PF] = pfOut; 
     EflagsOut[`OF] = ofOut;  
     EflagsOut[`AF] = (Operand2[3:0]==4'd0)?1'b0:!carryOut1[4];
    flush = 1'b0;
    end
/* *************************************************** */
   11'd333: //SETO set byte if overflow
   begin
     if(EflagsIn[`OF])
       Result[31:0]=32'd1;
     else
       Result[31:0]=32'd0;
   flush = 1'b0;
   end
/* *************************************************** */
   11'd334: //SETNO set byte if not overflow
   begin
     if(!EflagsIn[`OF])
       Result[31:0]=32'd1;
     else
       Result[31:0]=32'd0;
     flush = 1'b0;
   end
/* *************************************************** */
   11'd335: //SETNAE,SETB 
   begin
     if(EflagsIn[`CF])
       Result[31:0]=32'd1;
     else
       Result[31:0]=32'd0;
   flush = 1'b0; 
   end
/* *************************************************** */
   11'd336: //SETNB,SETAE,SETNC
   begin
     if(!EflagsIn[`CF])
       Result[31:0]=32'd1;
     else
       Result[31:0]=32'd0;
     flush = 1'b0;
   end
/* *************************************************** */
   11'd337: //SETE
   begin
     if(EflagsIn[`ZF])
       Result[31:0]=32'd1;
     else
       Result[31:0]=32'd0;
   flush = 1'b0; 
   end
/* *************************************************** */
   11'd338: //SETNE
   begin
     if(!EflagsIn[`ZF])
       Result[31:0]=32'd1;
     else
       Result[31:0]=32'd0;
     flush = 1'b0;
   end
/* *************************************************** */
   11'd339: //SETBE
   begin
     if(EflagsIn[`CF] || EflagsIn[`ZF])
       Result[31:0]=32'd1;
     else
       Result[31:0]=32'd0;
   flush = 1'b0; 
   end
/* *************************************************** */
   11'd340: //SETNBE
   begin
     if(!EflagsIn[`CF] && !EflagsIn[`ZF])
       Result[31:0]=32'd1;
     else
       Result[31:0]=32'd0;
     flush = 1'b0;
   end
/* *************************************************** */
   11'd341: //SETS
   begin
     if(EflagsIn[`SF])
       Result[31:0]=32'd1;
     else
       Result[31:0]=32'd0;
   flush = 1'b0; 
   end
/* *************************************************** */
   11'd342: //SETNS
   begin
     if(!EflagsIn[`SF])
       Result[31:0]=32'd1;
     else
       Result[31:0]=32'd0;
     flush = 1'b0;
   end
/* *************************************************** */
   11'd343: //SETP,SETPE
   begin
     if(EflagsIn[`PF])
       Result[31:0]=32'd1;
     else
       Result[31:0]=32'd0;
   flush = 1'b0; 
   end
/* *************************************************** */
   11'd344: //SETNP,SETPO
   begin
     if(!EflagsIn[`PF])
       Result[31:0]=32'd1;
     else
       Result[31:0]=32'd0;
   flush = 1'b0; 
   end
/* *************************************************** */
   11'd345: //SETNGE,SETL
   begin
     if(EflagsIn[`SF] != EflagsIn[`OF])
       Result[31:0]=32'd1;
     else
       Result[31:0]=32'd0;
   flush = 1'b0; 
   end
/* *************************************************** */
   11'd346: //SETGE,SETNL
   begin
     if(EflagsIn[`SF] == EflagsIn[`OF])
       Result[31:0]=32'd1;
     else
       Result[31:0]=32'd0;
   flush = 1'b0; 
   end
/* *************************************************** */
   11'd347: //SETLE,SETNG
   begin
     if(EflagsIn[`ZF] || (EflagsIn[`SF] != EflagsIn[`OF]))
       Result[31:0]=32'd1;
     else
       Result[31:0]=32'd0;
   flush = 1'b0; 
   end
/* *************************************************** */
   11'd348: //SETNLE,SETG
   begin
     if(!EflagsIn[`ZF] && (EflagsIn[`SF] == EflagsIn[`OF]))
       Result[31:0]=32'd1;
     else
       Result[31:0]=32'd0;
   flush = 1'b0; 
   end

/* *************************************************** */
   11'd363:	// Set Carry Flag
    begin
     EflagsOut[0] = 1'b1;
    flush = 1'b0; 
    end
/* *************************************************** */
   11'd131:	// Set Direction Flag
    begin
     EflagsOut[10] = 1'b1;
    flush = 1'b0; 
    end
/* *************************************************** */
   11'd365:	// Set Interrupt Flag
    begin
     EflagsOut[9] = 1'b1;
    flush = 1'b0; 
    end
/* *************************************************** */
   11'd366://STMXCSR: STORE STMXCSR REGISTER STATE
    begin
     Result[31:0] = Operand2;
    flush = 1'b0; 
    end
/* ************************************* */
   11'd370: // SUB - Subtraction
    begin
     case(OPSize)
      2'b00:
       begin
        cla1Op1 = Operand1[7:0];
        twosCompIn1 = Operand2[7:0];
        cla1Op2 = twosCompOut1[7:0];
        Result[7:0] = cla1Out[7:0];
        Result[31:8] = Operand1[31:8];
        Result[63:32] = Operand2;
        EflagsOut[`SF] = Result[7];    
        EflagsOut[`CF] = (Operand2[7:0]==8'd0)?1'b0:!carryOut1[8];
        ofCin = carryOut1[7];
        ofCout = carryOut1[8];
       end
      2'b01:
       begin
        cla1Op1 = Operand1[15:0];
        twosCompIn1 = Operand2[15:0];
        cla1Op2 = twosCompOut1[15:0];
        Result[15:0] = cla1Out[15:0];
        Result[31:16] = Operand1[31:16];
        Result[63:32] = Operand2;
        EflagsOut[`SF] = Result[15];
        EflagsOut[`CF] = (Operand2[15:0]==16'd0)?1'b0:!carryOut1[16];
        ofCin = carryOut1[15];
        ofCout = carryOut1[16];
       end
      default:
       begin
        cla1Op1 = Operand1[31:0];
        twosCompIn1 = Operand2[31:0];
        cla1Op2 = twosCompOut1[31:0];
        Result[31:0] = cla1Out[31:0];
        Result[63:32] = Operand2;
        EflagsOut[`SF] = Result[31];
        EflagsOut[`CF] =(Operand2==32'd0)?1'b0: !carryOut1[32];
        ofCin = carryOut1[31];
        ofCout = carryOut1[32];
       end
     endcase
     zfIn = Result[31:0];
     pfIn = Result[7:0];
     EflagsOut[`ZF] = zfOut;
     EflagsOut[`PF] = pfOut; 
     EflagsOut[`OF] = ofOut;  
     EflagsOut[`AF] = (Operand2[3:0]==4'd0)?1'b0:!carryOut1[4];
    flush = 1'b0;
    end
/* ************************************* */
   11'd376: // Test - Logical Compare
    begin
     andIn1 = Operand1;
     andIn2 = Operand2;
     Result[31:0] = Operand1;
     Result[63:32] = Operand2;
     pfIn = andOut[7:0];
     case(OPSize)
      2'b00:
       begin
        EflagsOut[`SF] = andOut[7];
        zfIn = {24'd0,andOut[7:0]};
        EflagsOut[`ZF] = zfOut;
        EflagsOut[`PF] = pfOut;
        EflagsOut[`CF] = 1'b0; 
        EflagsOut[`OF] = 1'b0; 
       end
      2'b01:
       begin
        EflagsOut[`SF] = andOut[15];
        zfIn = {16'd0,andOut[15:0]};
        EflagsOut[`ZF] = zfOut;
        EflagsOut[`PF] = pfOut;
        EflagsOut[`CF] = 1'b0; 
        EflagsOut[`OF] = 1'b0; 
       end
      default:
       begin
        EflagsOut[`SF] = andOut[31];
        zfIn = andOut[31:0];
        EflagsOut[`ZF] = zfOut;
        EflagsOut[`PF] = pfOut;
        EflagsOut[`CF] = 1'b0; 
        EflagsOut[`OF] = 1'b0; 
       end
     endcase
    flush = 1'b0;
    end
/* ************************************* */
   11'd389: // XADD - Exchange and ADD
    begin
     cla1Op1 = Operand1;
     cla1Op2 = Operand2;
     cIn1 = 0;
     Result[63:32] = Operand1;
     case(OPSize)
      2'b00:
       begin
        Result[7:0] = cla1Out[7:0];
        Result[31:8] = Operand1[31:8];
        zfIn = Result[7:0];
        EflagsOut[`SF] = cla1Out[7];
        EflagsOut[`OF] = carryOut1[7] ^ carryOut1[8];
        EflagsOut[`CF] = carryOut1[8];
       end
      2'b01:
       begin
        Result[15:0] = cla1Out[15:0];
        Result[31:16] = Operand1[31:16];
        zfIn = Result[15:0];
        EflagsOut[`SF] = cla1Out[15];
        EflagsOut[`OF] = carryOut1[15] ^ carryOut1[16]; 
        EflagsOut[`CF] = carryOut1[16];      
       end
      default:
       begin
        Result[31:0] = cla1Out[31:0];
        zfIn = Result[31:0];
        EflagsOut[`SF] = cla1Out[31];
        EflagsOut[`OF] = carryOut1[32] ^ carryOut1[31];
        EflagsOut[`CF] = carryOut1[32]; 
       end
     endcase
     pfIn = cla1Out[7:0];
     EflagsOut[`ZF] = zfOut;
     EflagsOut[`PF] = pfOut;
     EflagsOut[`AF] = carryOut1[4];
    flush = 1'b0;
    end
/* ************************************* */
   11'd390: // XCHG - Exchange Register/Memory with register
    begin
     case(OPSize)
      2'b00:
       begin
        Result[7:0] = Operand2[7:0];
        Result[31:8] = Operand1[31:8];
        Result[39:32] = Operand1[7:0];
        Result[63:40] = Operand2[31:8];
       end
      2'b01:
       begin
        Result[15:0] = Operand2[15:0];
        Result[31:16] = Operand1[31:16];
        Result[47:32] = Operand1[15:0];
        Result[63:48] = Operand2[31:16];
       end
      default:
       begin
        Result[31:0] = Operand2[31:0];
        Result[63:32] = Operand1[31:0];
       end
     endcase
    flush = 1'b0;
    end
/* ************************************* */
   11'd393: // XOR - Logical Exclusive OR
    begin
     exorIn1 = Operand1;
     exorIn2 = Operand2;
     Result[31:0] = exorOut;
     Result[63:32] = Operand2;  
     case(OPSize)
      2'b00:
      begin
       EflagsOut[`CF] = 1'b0;
       EflagsOut[`OF] = 1'b0;
       EflagsOut[`SF] = exorOut[7];
       zfIn = exorOut[7:0];
       EflagsOut[`ZF] = zfOut;
       pfIn = exorOut[7:0];
       EflagsOut[`PF] = pfOut;
      end
      2'b01:
      begin
       EflagsOut[`CF] = 1'b0;
       EflagsOut[`OF] = 1'b0;
       EflagsOut[`SF] = exorOut[15];
       zfIn = exorOut[15:0];
       EflagsOut[`ZF] = zfOut;
       pfIn = exorOut[7:0];
       EflagsOut[`PF] = pfOut;
      end
      default:
      begin
       EflagsOut[`CF] = 1'b0;
       EflagsOut[`OF] = 1'b0;
       EflagsOut[`SF] = exorOut[31];
       zfIn = exorOut[31:0];
       EflagsOut[`ZF] = zfOut;
       pfIn = exorOut[7:0];
       EflagsOut[`PF] = pfOut;
      end
     endcase
    flush = 1'b0;
    end  
/* ************************************* */
  endcase



end
 else
      flush = 1'b0; 
 end
endmodule