CSCI341 Lecture 11, Logical Operations
Image courtesy of http://debsbookbag.blogspot.com/
vs PERFORMANCE CPU Time = (Instruction Count x CPI) / Clock Rate Clock Rate CPI class A CPI class B CPI class C CPI class D Watermelon 1.5 GHz 1 2 3 4 Sour Apple 2 GHz 2 2 2 2 Given a program with 100 instructions, with 10% as class A, 20% class B, 50% class C and 20% class D, which implementation is faster ?
WHERE WE’VE BEEN • Understanding & Calculating Computer Performance • The Power Wall • Amdahl’s Law • Fallacies / Pitfalls • Heat, Costs and the Rise of Parallelism
WHERE WE’VE BEEN • Binary numbers • Two’s complement (signed) binary numbers • Addition & Subtraction of signed/unsigned binary numbers • Binary to decimal to hex representations • Shortcuts & tricks (negation, sign extension)
WHERE WE’VE BEEN • Fundamental MIPS operations • Operands and registers $zero, $t*, $s* • add, sub, addi, lw, sw • Base addresses and offsets (x4)
INSTRUCTIONS (REVIEW) R-type R egister operations eg, add, sub (no, not this) I-type I mmediate operations eg, addi, and data transfer
INSTRUCTION FORMATS add $t0, $s2, $t0 op rs rt rd shamt funct 0 18 8 8 0 32 R $s2 $t0 $t0 0 add lw $t0, 1200($t1) op rs rt constant / address 35 9 8 1200 I lw $t1 $t0 1200
R-TYPE VS. I-TYPE
LOGICAL OPERATIONS
LOGICAL SHIFT ING 0000 1001 1011 0000 << >> 1001 0000 0000 1011
LOGICAL SHIFT ING $s0 $s0 $s0 $s0 0000 1001 1011 0000 sll $t2, $s0, 4 srl $t2, $s0, 4 $t2 $t2 1001 0000 0000 1011
sll, srl Instructions sll $t2, $s0, 4 op rs rt rd shamt funct 0 0 16 10 4 0 What is shamt for srl ?
WHY GIVE A SHIFT? optimized version of multiplying or dividing by powers of two! (among other things)
AND and OR and $t0, $t1, $t2 perform bitwise AND operation on values in $t1 and $t2 or $t0, $t1, $t2 perform bitwise OR operation on values in $t1 and $t2
MASKING 32-bit words.... But what if I want just part of that word?
MASKING Given a byte 1011 0100 How might you ‘extract’ or ‘isolate’ the second nibble?
MASKING WITH AND 1011 0100 AND 0000 1111 0000 0100 “bit masking”
HOMEWORK • Reading 9: section 2.6 • Problem Set 6 (Instruction formats) • Project 2 (a simple program)
Recommend
More recommend