TranslateJun.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package targets.mips;
  7. import common.Instruction;
  8. /**
  9. * MipS tranSlation
  10. *
  11. * @author EUGENIO CARVALHO
  12. */
  13. public class TranslateJun extends Translate {
  14. public void TranslateBranch(Instruction inst) throws Exception {
  15. //BEQ
  16. //BNE
  17. //BGTZ
  18. //BGEZ
  19. //BLTZ
  20. //BNEZ
  21. // "<" "bltz"
  22. // ">" "bgtz"
  23. // "<=" "blez"
  24. // ">=" "bgez"
  25. // "==" "beq"
  26. // "!=" "bne"
  27. String instruction = Descriprion.InstructionByOperator(inst);
  28. LoadParam(inst, "p1,p2", true);
  29. String rs = inst.Get("reg.p1"),
  30. rt = inst.Get("reg.p2");
  31. Instruction branch = Descriprion.Instruction(instruction);
  32. switch (instruction) {
  33. case "beq": // == {[inst]}' ' {[rt]},{[rs]},{immediate}
  34. case "bne": // !=
  35. branch.Set("rs", rs).Set("rt", rt);
  36. break;
  37. case "blez": // <= 0{[inst]}' ' {[rs]},{immediate}
  38. Add(Descriprion.Instruction("slt"))
  39. .Set("rs", rs)
  40. .Set("rt", rt)
  41. .Set("rd", "v0")
  42. .Set("comment", "");
  43. // Atualiza o tipo de branch
  44. instruction = "bne";
  45. branch = Descriprion.Instruction(instruction)
  46. .Set("rs", "v0")
  47. .Set("rt", "zero");
  48. break;
  49. case "bltz": // < 0
  50. case "bgez": // >= 0
  51. case "bgtz": // > 0
  52. Add(Descriprion.Instruction("subu"))
  53. .Set("rs", rs)
  54. .Set("rt", rt)
  55. .Set("rd", "v0")
  56. .Set("comment", "");
  57. branch.Set("rs", "v0");
  58. break;
  59. }
  60. Add(branch)
  61. .Set("label", inst.Get("label"))
  62. .Set("comment", comments.get(instruction));
  63. Nop(false);
  64. }
  65. }