Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Translates the MAL instruction to 1-3 TAL instructions * and returns the TAL

ID: 3886604 • Letter: 1

Question

1. 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 or longer than input list).

public static List mal_to_tal(List mals)

2. Returns a list of copies of the Instructions with the * immediate field of the instruction filled in * with the address calculated from the branch_label. * * The instruction should not be changed if it is not a branch instruction. * * unresolved: list of instructions without resolved addresses * first_pc: address where the first instruction will eventually be placed in memory.

public static List resolve_addresses(List unresolved, int first_pc)

3. Translate each Instruction object into * a 32-bit number. * * tals: list of Instructions to translate * * returns a list of instructions in their 32-bit binary representation.

public static List translate_instructions(List tals) { return null; } }

Explanation / Answer

MAL is a programming language abstraction which hides details of the MIPS RISC architecture. Many MAL instructions are identical to TAL, but some MAL instructions require 2 or 3 TAL instructions.

TAL is the true assembly language of the MIPS RISC processor. Each TAL instruction corresponds to a single machine code instruction. The TAL instruction set defines the MIPS RISC architecture using symbolic notation. The machine code instructions are 32 bit binary words.

The process of translating MAL into machine code is called assembly. The first step in assembling a MAL program is translation to TAL. The program which performs the assembly language translation is the assembler. A smart assembler is required to synthesize MAL instructions from 2 or more TAL instructions.

The Translation of MAL to TAL

There are lots of MAL instructions that have no direct TAL equivalent. They will be translated (composed, synthesized) into one or more TAL instructions.

The assembler takes (non MIPS) MAL instructions and synthesizes them with 1 or more MIPS instructions.

Multiplication and Division Instructions

becomes

32-bit multiplication produces a 64-bit result. To deal with this larger result, the MIPS architecture has 2 registers that hold results for integer multiplication and division. They are called HI and LO. Each is a 32 bit register.

mult places the least significant 32 bits of its result into LO, and the most significant into HI.

Then, more TAL instructions are needed to move data into or out of registers HI and LO:

Data is moved into or out of register HI or LO.

One operand is needed to tell where the data is coming from or going to.

Integer division also uses register HI and LO, since it generates both a quotient and remainder as a result.

becomes

and

becomes

Load and Store Instructions

becomes

which becomes

or

Instructions with Immediates

Instructions with immediates are synthesized with instructions that must have an immediate value as the last operand.

becomes

An add instruction requires 3 operands in registers. addi has one operand that must be an immediate.

These instructions are classified as immediate instructions. On the MIPS, they include: addi, addiu, andi, lui, ori, xori.

Instructions with Too Few Operands

is expanded back out to be

I/O Instructions

becomes

which becomes

becomes

which becomes

becomes

which becomes

becomes

which becomes