

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


CSCE 212: Example quiz questions
ADDI $2, $3, -
half-words :
i=0; sum=0; while (vals[i]!=0) { sum=sum+vals[i]; i++; }
Translate the following instruction into MIPS machine instructions:
MERG16 $2, $3, $
Do not change the values of any registers except $1 (use for intermediate values) and $2 (the destination).
Instruction type Encoding format Load and store instructions Branch instructions Arithmetic instructions having 2 register input operands Shift instructions J-type
bit immediate field before adding it to the contents of register rs. Assume for this question that the hardware designers saved costs by always zero-extending the immediate value instead. As a result, any ADDI instruction with a negative immediate value is treated as a pseudoinstruction by the assembler. When the pseudoinstruction is assembled, it is converted into a series of instructions that perform a software-based sign extension of the immediate. Assuming there have been no other architectural changes, how is the following pseudoinstruction translated:
ADDI $s0, $s1, -
Hint: the first instruction in the translation moves the 16-bit immediate into temporary register $1, which (in this case) results in register $1 having value 0000 FFF4. Three more instructions are needed:
1. ADDI $1, $0, -
li $s0, 0 lw $s2, 0($a1) loop: lw $s1, 0($a0) mult $s3, $s1, $s add $s0, $s0, $s addi $a0, $a0, 4 addi $a2, $a2, - bnez $a2, loop
for (i=0;i<n;i++) a[i]=i;
Before your translation begins, assume variable n is stored in register $s0 and that array a is an array of half-words.