ExampleSoln1

# ExampleSoln1 - Review Problem 0 As you wait for class to...

This preview shows pages 1–11. 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? OS Hz MHz Pentium vs. Athlon Main memory (DRAM) h ( S R A M ) Caches (SRAM) Peripherals 59 Slide 0: No Background required!

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? Logical: and, or, etc. Control flow: if-then-else, goto, procedure call Iteration: for, while, do-until Librarys: file I/O, graphics Storage: new, malloc, class methods, arrays, structs robably others Probably others… 60 Slide 9: Assembly Language
Review Problem 1a ± In assembly, copy the value of register \$a0 to register \$t0 add \$t0, \$a0, \$0 61 Slide 13: Registers

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

View Full Document
Review Problem 2 ± In assembly, compute the average of \$a0, \$a1, \$a2, \$a3, and put into \$v0 add \$v0, \$a0, \$a1 add \$v0, \$v0, \$a2 add \$v0, \$v0, \$a3 # v0 = sum(a0,a1,a2,a3) sra \$v0, \$v0, 2# v0 = sum(a0,a1,a2,a3)/4 62 Slide 14: Basic Operations
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 0 0 3 ‘y’ obj: obj->b[0] . . truct { char *a, *b; } foo; 1003 1004 1005 1006 1019 1020 1021 1022 236 0 0 3 obj->a . . . . bj b[7] 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 244 0 0 3 obj->b obj->b[7] obj->a[1] = ‘x’; obj->b[2] = ‘y’; 1011 1012 014 1013 1027 1028 030 1029 248 ‘x’ obj->a[0]: . 63 1014 1015 1030 1031 Slide 18: Data Storage . obj->a[3]:

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

View Full Document
Review Problem 4 ± In assembly, replace the value in \$a0 with its absolute value. (bgtz) bgez \$a0, WAS_POSITIVE sub \$a0, \$zero, \$a0 WAS_POSITIVE: 64 Slide 23: Control Flow
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. w \$t0 0(\$a0) / array[0] Lw \$t0, 0(\$a0) // array[0] Lw \$t1, 4(\$a0) // array[1] Lw \$t2, 8(\$a0) // array[2] Add \$v0, \$0, \$0 // set to 0 initially Slt \$t4, \$t1, \$t2 // is [0] < [1]? Beq \$t4, \$0, UNSORTED Slt \$t4, \$t2, \$t3 // is [1] < [2]? Beq \$t4, \$0, UNSORTED eq \$t , \$0, U SO Addi \$v0, \$0, 1 // set to 1 – sorted! UNSORTED: 65 Slide 25: Comparison Operators

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

View Full Document
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: A2 = 4. If lbu at 4<<2 (addr 16) then A1 == A2. Start code at 8 slt \$t6, \$t3, \$t5 A3: add \$t5, \$t5, \$t4 sb \$t5, 0(\$t0) ddi t0 \$t0 1 A3 = 1, smallest A1 can be is 2, n’tdoit addi \$t0, \$t0, 1 j A1 can t do it A4 = -1, which is 16x1’s, or 2^16-1. an do Start code at (2^16 )*4 66 Slide 29: Labels Example Can do. Start code at (2^16-1)*4-8
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 00100 0111 11111111111111 OP RS RT 16 bit Address/Immediate 000100 00111 BEQ Opcode is 04 1111111111111111 Qp RS and RT are \$7 Branch goes to PC + 4 + Offset*4. To stay the same, offset=-1 = all ones 67 Slide 33: I-Type -1 = all ones

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

View Full Document
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?
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 11/11/2010 for the course ECE 125 taught by Professor Chang during the Spring '10 term at Eastern.

### Page1 / 37

ExampleSoln1 - Review Problem 0 As you wait for class to...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online