Docsity

Example Quiz Questions - Computer Architecture | CSCE 212, Quizzes of Computer Science

Toggle sidebar
bg1
CSCE 212: Example quiz questions
1. Assemble the following instruction into hexadecimal representation:
ADDI $2, $3, -8762
2. Translate the following high-level code to MIPS assembly. vals is an array of
half-words:
i=0;
sum=0;
while (vals[i]!=0) {
sum=sum+vals[i];
i++;
}
3. Assume there is a MIPS pseudoinstruction named MERG16 rd, rs, rt that
merges two register values by:
1. moving the low-order 16 bits of rs into the low-order 16 bits of rd, and
2. moving the low-order 16 bits of rt into the high-order 16 bits of rd.
Translate the following instruction into MIPS machine instructions:
MERG16 $2, $3, $4
Do not change the values of any registers except $1 (use for intermediate
values) and $2 (the destination).
4. Complete the following table by filling in the empty cells to connect MIPS
instruction types with their corresponding encoding format.
Instruction type Encoding format
Load and store instructions
Branch instructions
Arithmetic instructions having 2
register input operands
Shift instructions
J-type
5. Describe three different functions of the immediate field in the MIPS instruction
set.
pf3

Partial preview of the text

Download Example Quiz Questions - Computer Architecture | CSCE 212 and more Quizzes Computer Science in PDF only on Docsity!

CSCE 212: Example quiz questions

  1. Assemble the following instruction into hexadecimal representation:

ADDI $2, $3, -

  1. Translate the following high-level code to MIPS assembly. vals is an array of

half-words :

i=0; sum=0; while (vals[i]!=0) { sum=sum+vals[i]; i++; }

  1. Assume there is a MIPS pseudoinstruction named MERG16 rd, rs, rt that merges two register values by:
    1. moving the low-order 16 bits of rs into the low-order 16 bits of rd , and
    2. moving the low-order 16 bits of rt into the high-order 16 bits of rd.

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).

  1. Complete the following table by filling in the empty cells to connect MIPS instruction types with their corresponding encoding format.

Instruction type Encoding format Load and store instructions Branch instructions Arithmetic instructions having 2 register input operands Shift instructions J-type

  1. Describe three different functions of the immediate field in the MIPS instruction set.
  1. When executing the ADDI instruction, the MIPS architecture sign-extends its 16-

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, -

2. ____________________

3. ____________________

4. ____________________

  1. Describe what computation the following segment of assembly code is performing. List what registers need to be initialized before the code begins and how these registers are used.

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

  1. Translate the following high-level code to MIPS assembly:

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.