12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package targets.mips;
- import common.Instruction;
- /**
- * MipS tranSlation
- *
- * @author EUGENIO CARVALHO
- */
- public class TranslateJun extends Translate {
- public void TranslateBranch(Instruction inst) throws Exception {
- //BEQ
- //BNE
- //BGTZ
- //BGEZ
- //BLTZ
- //BNEZ
- // "<" "bltz"
- // ">" "bgtz"
- // "<=" "blez"
- // ">=" "bgez"
- // "==" "beq"
- // "!=" "bne"
- String instruction = Descriprion.InstructionByOperator(inst);
- LoadParam(inst, "p1,p2", true);
- String rs = inst.Get("reg.p1"),
- rt = inst.Get("reg.p2");
- Instruction branch = Descriprion.Instruction(instruction);
- switch (instruction) {
- case "beq": // == {[inst]}' ' {[rt]},{[rs]},{immediate}
- case "bne": // !=
- branch.Set("rs", rs).Set("rt", rt);
- break;
- case "blez": // <= 0{[inst]}' ' {[rs]},{immediate}
- Add(Descriprion.Instruction("slt"))
- .Set("rs", rs)
- .Set("rt", rt)
- .Set("rd", "v0")
- .Set("comment", "");
- // Atualiza o tipo de branch
- instruction = "bne";
- branch = Descriprion.Instruction(instruction)
- .Set("rs", "v0")
- .Set("rt", "zero");
- break;
- case "bltz": // < 0
- case "bgez": // >= 0
- case "bgtz": // > 0
- Add(Descriprion.Instruction("subu"))
- .Set("rs", rs)
- .Set("rt", rt)
- .Set("rd", "v0")
- .Set("comment", "");
- branch.Set("rs", "v0");
- break;
- }
- Add(branch)
- .Set("label", inst.Get("label"))
- .Set("comment", comments.get(instruction));
- Nop(false);
- }
- }
|