static List<CStatement> Add_C(uint pc, uint instruction) { Instruction i = new Instruction(instruction); /* op1 + op2 */ CStatement stat = new CStatement(CStatement.Kinds.Addition, RegName(i.RA()), RegName(i.RB())); /* dest = expr */ CStatement ass = new CStatement(CStatement.Kinds.Assignment, RegName(i.RD()), stat); List<CStatement> stats = new List<CStatement>(); stats.Add(ass); if (i.OE()) MessageBox.Show("This instruction sets the O bit. I don't know how to translate it! Ignoring."); if (i.RC()) stats.Add(new CStatement(CStatement.Kinds.Assignment, "cr0", RegName(i.RD()))); return stats; }
static List<CStatement> Addi_C(uint pc, uint instruction) { Instruction i = new Instruction(instruction); CStatement stat = new CStatement(CStatement.Kinds.Assignment, RegName(i.RD())); if (i.RA() == 0) stat.Op2 = new CStatement.COperand((ulong)(long)i.SIMM()); else if (i.SIMM() == 0) stat.Op2 = new CStatement.COperand(RegName(i.RA())); else { CStatement add = new CStatement(CStatement.Kinds.Addition, RegName(i.RA()), (ulong)(long)i.SIMM()); long val = (long)add.Op2.Value; if (val < 0) { add.Kind = CStatement.Kinds.Subtraction; add.Op2.Value = (ulong)-val; } stat.Op2 = new CStatement.COperand(add); } List<CStatement> stats = new List<CStatement>(); stats.Add(stat); return stats; }
static List<CStatement> Lwz_C(uint pc, uint instruction) { Instruction i = new Instruction(instruction); CStatement stat = new CStatement(CStatement.Kinds.Assignment, RegName(i.RD())); stat.OperandSizes = CStatement.Sizes.Int; int ds = (int)i.SIMM(); if (i.RA() != 0) stat.Op2 = new CStatement.COperand(RegName(i.RA()), ds); else { stat.Op2 = new CStatement.COperand(); stat.Op2.Kind = CStatement.OperandKinds.AddressPointer; stat.Op2.Offset = ds; } List<CStatement> stats = new List<CStatement>(); stats.Add(stat); return stats; }
static List<CStatement> Mfspr_C(uint pc, uint instruction) { Instruction i = new Instruction(instruction); CStatement stat = new CStatement(CStatement.Kinds.Assignment, RegName(i.RD())); stat.OperandSizes = CStatement.Sizes.Long; stat.Op2 = new CStatement.COperand(); stat.Op2.Kind = CStatement.OperandKinds.Variable; switch (i.SPR()) { case 32: stat.Op2.Name = "xer"; break; case 256: stat.Op2.Name = "lr"; break; case 288: stat.Op2.Name = "ctr"; break; default: stat.Op2.Name = "spr" + i.SPR(); break; } List<CStatement> stats = new List<CStatement>(); stats.Add(stat); return stats; }
static List<CStatement> Lbzx_C(uint pc, uint instruction) { Instruction i = new Instruction(instruction); CStatement stat = new CStatement(CStatement.Kinds.Assignment, RegName(i.RD())); stat.OperandSizes = CStatement.Sizes.Byte; if (i.RA() != 0) { if (i.RB() != 0) stat.Op2 = new CStatement.COperand(RegName(i.RA()), RegName(i.RB())); else stat.Op2 = new CStatement.COperand(RegName(i.RA()), 0); } else stat.Op2 = new CStatement.COperand(RegName(i.RB()), 0); List<CStatement> stats = new List<CStatement>(); stats.Add(stat); return stats; }