Examples

Examples - Review Problem 0 As you wait for class to start,...

This preview shows pages 1–18. Sign up to view the full content.

Review Problem 0 ± As you wait for class to start, answer the following question: ± What is important in a computer? What features do you look for when buying one? 0

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Review Problem 1 ± Programming languages have many instructions, but they fall under a few basic types. One is arithmetic (+, -, *, /, etc). What are the others? 1
Review Problem 2 ± In assembly, compute the average of \$a0, \$a1, \$a2, \$a3, and put into \$v0 2

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Review Problem 3 ± What would the results of this C++ code be in memory? Assume we start using memory at 1000. 1000 1001 1002 1016 1017 1018 truct { char *a, *b; } foo; 1003 1004 1005 1006 1019 1020 1021 1022 Struct { char a, b; } foo; foo *obj; obj = new foo; obj->a = new char[4]; obj->b = new char[8]; 1007 1008 1009 1010 1023 1024 1025 1026 obj->a[1] = ‘x’; obj->b[2] = ‘y’; 1011 1012 014 1013 1027 1028 030 1029 3 1014 1015 1030 1031
Review Problem 4 ± In assembly, replace the value in \$a0 with its absolute value. 4

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Review Problem 5 ± Register \$a0 has the address of a 3 integer array. Set \$v0 to 1 if the array is sorted (smallest to largest), 0 otherwise. 5
Review Problem 6 ± For the following code, can you ever have labels A1 == A2? A1 == A3? A1 == A4? lw \$t0, 100(\$zero) beq \$t0, \$0, A2 A1: lbu \$t5, 0(\$t0) A4: beq \$t5, \$zero, A4 slt \$t6, \$t5, \$t2 bne \$t6, \$zero, A3 A2: slt \$t6, \$t3, \$t5 A3: add \$t5, \$t5, \$t4 sb \$t5, 0(\$t0) ddi t0 \$t0 1 addi \$t0, \$t0, 1 j A1 6

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Review Problem 7 ± Sometimes it can be useful to have a program loop infinitely. We can do that, regardless of location, by the instruction: ± LOOP: BEQ \$7, \$7, LOOP ± Convert this instruction to machine code 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 7
Review Problem 8 ± We goofed, and wrote code with: add \$t0, \$t1, \$t4, when we meant to write sub \$t0, \$t1, \$t4. The instruction is at location Mem[0]. What’s the simplest program to fix this? 8

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Review Problem 9 ± What does the number 100011 2 represent? 9
Review Problem 10 ± Perform the following binary computations. 1 0 1 1 0 + 0 0 1 1 1 1 0 0 1 - 0 0 1 1 10

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Review Problem 11 ± For the buggy majority circuit below, the expected and the measured results are shown in the table. What gate is broken in this circuit? Signal Expected Measured A0 0 B1 1 A B B M D E C1 1 D0 0 C A F G E 0 1 F1 1 C 11 G 1 0 M1 0
Review Problem 12 ± How would the ALU be used to help with each of the following branches? The first is filled in for you: ± beq (\$rs == \$rt) subtract \$rt from \$rs, use zero flag ± bne (\$rs != \$rt) ± bgez (\$rs 0) gtz (\$rs > 0) ± bgtz (\$rs > 0) ± blez (\$rs 0) ± bltz (\$rs < 0) 12

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Review Problem 13 ± Write MIPS assembly to compute \$t1 = \$t0*5 without using a multiply or divide instruction. 13
Review Problem 14 ± What aspects of a microprocessor can affect performance? 14

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Review Problem 15 ± Orange runs at 1GHz, and provides a unit making all floating point operations take 1 cycle. Grape runs at 1.2 GHz by deleting the unit, meaning floating point operations take 20 cycles. Which achine is better? machine is better? 15