CSE230: Exam 1 Practice

¡Supera tus tareas y exámenes ahora con Quizwiz!

Assume $t0 holds the value 0x00101000. What is the value of $t2 after the following instructions? slt $t2, $0, $t0 bne $t2, $0, ELSE j DONE ELSE: addi $t2, $t2, 2 DONE:

$t2 = 3

Assume 151 and 214 are signed 8-bit decimal integers stored in two's complement format. Calculate 151 - 214 using saturating arithmetic. The result should be written in decimal. Show your work.

-63

As discussed in the text, one possible performance enhancement is to do a shift and add instead of an actual multiplication. Since 9 X 6, for example, can be written (2 X 2 X 2 + 1) X 6, we can calculate 9 X 6 by shifting 6 to the left 3 times and then adding 6 to that result. Show the best way to calculate 0X33 X 0X55 using shifts and adds/subtracts. Assume both inputs are 8-bit unsigned integers.

0 10000100 111 1101 0000 0000 0000 0000

Convert 5ED4 into a binary number. What makes base 16 (hexadecimal) an attractive numbering system for representing values in computers?

0101 1110 1101 0100

Implement the following C code in MIPS assembly. What is the total number of MIPS instructions needed to execute the function? int fib( int n ) { if ( n == 0 ) return 0; else if ( n == 1 ) return 1; else return fib ( n - 1) + fib ( n - 2 );

28

Calculate the time necessary to perform a multiply using the approach described in the text (31 adders stacked vertically) if an integer is 8 bits wide and an adder takes 4 time units.

28 time units.

Write down the binary representation of the decimal number 63.25 assuming it was stored using the single precision IBM format (base 16, instead of base 2, with 7 bits of exponent).

4FA0000

What is 5ED4 - 07A4 when these values represent unsigned 16- bit hexadecimal numbers? The result should be written in hexadecimal. Show your work.

5730

Assume 185 and 122 are unsigned 8-bit decimal integers. Calculate 185 - 122. Is there overflow, underflow, or neither?

63, Neither.

Assume 185 and 122 are signed 8-bit decimal integers stored in sign-magnitude format. Calculate 185 + 122. Is there overflow, underflow, or neither?

65, Neither.

Implement the following C code in MIPS assembly. What is the total number of MIPS instructions needed to execute the function? int fib(int n){ if (n==0) return 0; else if (n == 1) return 1; else return fib(n−1) + fib(n−2);

73

What is 4365 - 3412 when these values represent unsigned 12-bit octal numbers? The result should be written in octal. Show your work.

7777 = 111 111 111 111

For the register values shown above, what is the value of $t2 for the following sequence of instructions? sll $t2, $t0, 4 andi $t2, $t2, −1

AAAAAAA0

For the MIPS assembly instructions below, what is the corresponding C statement? Assume that the variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3, and $s4, respectively. Assume that the base address of the arrays A and B are in registers $s6 and $s7, respectively. sll $t0, $s0, 2 # $t0 = f * 4 add $t0, $s6, $t0 # $t0 = &A[f] sll $t1, $s1, 2 # $t1 = g * 4 add $t1, $s7, $t1 # $t1 = &B[g] lw $s0, 0($t0) # f = A[f] addi $t2, $t0, 4 lw $t0, 0($t2) add $t0, $t0, $s0 sw $t0, 0($t1)

B[g] = A[f] + A[1+f];

Convert the following C code into MIPS. short Sum(short *pt) { short result = 0; while(*pt != -32768) {result = result + (*pt); pt++; } return result; }

Sum: add $v0,$zero,$zero li $s0, -32768 loop: bne $a0 , $s0 , exit lw $t0, 0($a0) add $v0,$v0,$t0 addi $a0,$a0,4 j loop exit: jr $ra

Translate the following C code to MIPS assembly code. Use a minimum number of instructions. Assume that the values of a, b, i, and j are in registers $S0, $S1, $t0, and $t1, respectively. Also, assume that register $S2 holds the base address of the array D.

add $t0 , $zero , $zero loop1: add $t1 , $zero, $zero loop2: add $t7 , $t0 , $t1 addi $s2 , $s2 , 4 sw $t7, 0($s2) slt $t5, $t1 , $s1 beq $t5, $zero, loop2 addi $t0,$t0,1 slt $t5, $t0,$s0 beq $t5,$zero , loop1

For the following MIPS assembly instructions above, what is a corresponding C statement? add f, g, h add f, i, f

add f,g,h add f,i,f

For the following C statement, what is the corresponding MIPS assembly code? Assume that the variables f, g, h, and i are given and could be considered 32-bit integers as declared in a C program. Use a minimal number of MIPS assembly instructions. f = g + (h − 5);

addi i ,h, -5 add f, g, i

For the following C statement, write a minimal sequence of MIPS assembly instructions that does the identical operation. Assume $t1 = A, $t2 = B, and $s1 is the base address of C. A = C[0] << 4;

lw $t3, 0($s1) sll $t1, $t3, 4

For the following C statement, what is the corresponding MIPS assembly code? Assume that the variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3, and $s4, respectively. Assume that the base address of the arrays A and B are in registers $s6 and $s7, respectively. B[8] = A[i−j];

sub $s5, $s2, $s3 sll $s5,$s5,2 add $s5,$s6,$s5 lw $s6, 0($s5) św $s6, 32 $(s7)


Conjuntos de estudio relacionados

Which bone articulates with what?

View Set

Chapter 11 - Inflammation and Wound Healing

View Set

key business functions: operations

View Set

Nursing: Ethical Decision Making

View Set