Can someone please convert this java code to C code? import java.util.LinkedList; import java.util.List; public class Phase1 { /*...

90.2K

Verified Solution

Question

Programming

Can someone please convert this java code to C code?

import java.util.LinkedList;
import java.util.List;
public class Phase1 {
/* Translates the MAL instruction to 1-3 TAL instructions
* and returns the TAL instructions in a list
*
* mals: input program as a list of Instruction objects
*
* returns a list of TAL instructions (should be same size orlonger than input list)
*/
public static List temp = newLinkedList<>();
public static Listmal_to_tal(List mals) {
for (int i = 0; i < mals.size(); i++) {
Instruction current = mals.get(i);
int rs = current.rs;
int rd = current.rd;
int rt = current.rt;
int imm = current.immediate;
int jumpAddress = current.jump_address;
int shiftAmount = current.shift_amount;
String label = current.label;
String branchLabel = current.branch_label;
int upperImm = imm >>> 16;
int lowerImm = imm & 0xFFFF;
int t1 = 0;
int t2 = 0;
int t3 = 0;
int at = 0;
if ((current.instruction_id == Instruction.ID.addiu
|| current.instruction_id == Instruction.ID.ori) &&(imm > 65535)) {
at = 1;
temp.add(InstructionFactory.CreateLui(at, upperImm,label));
temp.add(InstructionFactory.CreateOri(at, at, lowerImm));
if (current.instruction_id == Instruction.ID.addiu)temp.add(InstructionFactory.CreateAddu(rt, rs, at));
else temp.add(InstructionFactory.CreateOr(rt, rs, at));
}
else if (current.instruction_id == Instruction.ID.blt) {
//t1 = rt, t2 = rs
if (rt > rs) {
at = 1;
}
temp.add(InstructionFactory.CreateSlt(at, rt, rs));
temp.add(InstructionFactory.CreateBne(at, 0,branchLabel));
}
else if (current.instruction_id == Instruction.ID.bge) {
at = 1;
temp.add(InstructionFactory.CreateSlt(at, rt, rs));
temp.add(InstructionFactory.CreateBeq(at,0, branchLabel));
}
else temp.add(current);
}
return temp;
}

}

to C code:

void mal_to_tal(structArrayList *mals, structArrayList *tals){

}

Answer & Explanation Solved by verified expert
4.4 Ratings (686 Votes)
Working code implemented in C and appropriate comments provided for better understanding Note I am not able to paste all the code here Thats why I am sharing whole project through a link Link httpsgofileiodNvyckR Mirror Link httpsanonymousfilesiooUDFfGmV Sample Codes Source Code for Phase1c include Phase1h void maltotalstruct ArrayList mals struct ArrayList tals for int i 0 i malssize i enum ID id getmalsiinstructionid get the id number at the start of the loop    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students