CSCI 136 Lab 1
Outline Go through the CD attached to the textbook. Homework Hints 135 Review
Prob 1.46 Magnetic disk: –On average, needs ½ revolution time for the disk to spin under the read/write head. For 7200 RPM, what is 1 revolution time? How about RPM?
Prob 1.51 Cost per wafer: $ wafer produces 1500 dies, where 50% are valid dies. –How many valid dies per wafer? –Cost per valid die? Chip = 1 die + package + test Cost for package + test : $10 Test yield: 90% –Cost per valid chip? Retail Price = Cost per valid chip * (1 + 40%). Invest: $500,000 –How many valid chips have to be sold to break even?
Prob 1.52 CISC vs. RISC –CISC needs fewer instructions to perform a task compared with RISC. –RISC instructions take less time. For a certain task –P CISC instructions vs. 2P RISC instructions –8T ns per CISC instr. vs. 2T ns per RISC instr. Which one is better?
Prob 1.54 Multiplication operation: 10 ns Subtraction operation: 1 ns d = a*b – a*c –How long time? How to optimize the equation to take less time?
Some Requirements Make the homework solutions clear –Handwriting & Content Prepare before coming the lab –Read the homework problems To be added…
Decimal Numbers: Base 10 Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Example: 3271 = (3x10 3 ) + (2x10 2 ) + (7x10 1 ) + (1x10 0 ) The following 8 slides are from UCB CS61C
Numbers: positional notation Number Base B B symbols per digit: –Base 10 (Decimal):0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Base 2 (Binary):0, 1 Number representation: –d 31 d d 1 d 0 is a 32 digit number –value = d 31 B 31 + d 30 B d 1 B 1 + d 0 B 0 Binary:0,1 (In binary digits called “bits”) –0b11010 = 1 2 0 = = 26 –Here 5 digit binary # turns into a 2 digit decimal # –Can we find a base that converts to binary easily? #s often written 0b…
Hexadecimal Numbers: Base 16 Hexadecimal: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F –Normal digits + 6 more from the alphabet –In C, written as 0x… (e.g., 0xFAB5) Conversion: Binary Hex –1 hex digit represents 16 decimal values –4 binary digits represent 16 decimal values 1 hex digit replaces 4 binary digits One hex digit is a “nibble”. Two is a “byte” Example: – (binary) = 0x_____ ?
Decimal vs. Hexadecimal vs. Binary A B C D E F1111 MEMORIZE! Examples: (binary) = 0xAC (binary) = (binary) = 0x17 0x3F9 = (binary) How do we convert between hex and Decimal?
Which base do we use? Decimal: great for humans, especially when doing arithmetic Hex: if human looking at long strings of binary numbers, its much easier to convert to hex and look 4 bits/symbol –Terrible for arithmetic on paper Binary: what computers use; you will learn how computers do +, -, *, / –To a computer, numbers always binary –Regardless of how number is written: 32 ten == == 0x20 == == 0b –Use subscripts “ten”, “hex”, “two” in book, slides when might be confusing
BIG IDEA: Bits can represent anything!! Characters? –26 letters 5 bits (2 5 = 32) –upper/lower case + punctuation 7 bits (in 8) (“ASCII”) –standard code to cover all the world’s languages 8,16,32 bits (“Unicode”) Logical values? –0 False, 1 True colors ? Ex: locations / addresses? commands? MEMORIZE: N bits at most 2 N things Red (100)Green (010)Blue (001)
How to Represent Negative Numbers? So far, unsigned numbers Obvious solution: define leftmost bit to be sign! –0 +, 1 - –Rest of bits can be numerical value of number Representation called sign and magnitude MIPS uses 32-bit integers. +1 ten would be: And - 1 ten in sign and magnitude would be:
Shortcomings of sign and magnitude? Arithmetic circuit complicated –Special steps depending whether signs are the same or not Also, two zeros – 0x = +0 ten – 0x = -0 ten –What would two 0s mean for programming? Therefore sign and magnitude abandoned
2’s Complement Numbers As with sign and magnitude, leading 0s positive, leading 1s negative – xxx is ≥ 0, xxx is < 0 –except 1…1111 is -1, not -0 (as in sign & mag.) To get negative number from a positive.. Invert all digits and add 1. To get a positive number from a negative… Invert all digits and add 1. Assume 8 bit word. What is -57 in 2’s complement notation?
2’s Complement Number “line”: N = 5 2 N-1 non- negatives 2 N-1 negatives one zero how many positives?
Sign Extension Sign extension can be used when you shift a register right… the sign bit is repeated to keep a negative number negative… This is referred to as “Arithmetic” variety of shift If the sign bit isn’t extended.. (i.e. empty spots filled with 0 s) then the shift is called “Logical” variety of shift
Assume 8 bit words… What is result of logical right shifting -12 by 2? assembly: srl (shift right logical) srlv (shift right logical variable) What is result of arithmetic right shift -12 by 2? assembly: sra (shift right arithmetic) srav (shift right arithmetic variable) What is result of rotate right -12 by 2? assembly: ror (rotate right) What is the assembly code to do this?
What is result of rotating left -12 by 2? assembly: rol (rotate left) What is the result of logical shift left -12 by 2? assembly: sll (shift left logical) sllv (shift left logical variable) What is the assembly code to do this? Why isn’t there a sla (shift left arithmetic) assembly instruction?
Byte Ordering Assume 32 bit word: Big Endian vs. Little Endian In a big-endian system, the most significant value in the sequence is stored at the lowest storage address (i.e., first). In a little-endian system, the least significant value in the sequence is stored first Address Big-Endian representation of 1025 Little-Endian representation of
Byte Ordering Computer designers can’t seem to agree on whether to use Big Endian or Little Endian. Neither design is really superior to the other. What kind of Endian are Intel PCs? What kind of Endian are Macs? Sun SPARC Stations can be set in either mode… (but Solaris OS requires Big Endian). Most of the time.. you probably won’t notice Endianness. But SPIM simulator uses the “Endianness” of the machine you run it on!
Load Immediate (li) What does the following instruction do? li $t0, 0x What does the following sequence of instructions do? lui $t0, 4004 ori $t0, $t0, 4005
li (load immediate) instruction is really “pseudocode” When the assembler sees an li instruction it substitutes: lui (load upper immediate) followed by an ori (or immediate) In the place of the li (load immediate)
Time Units How long is a microsecond? How long is a nanosecond? How long is a picosecond? If a clock runs at 450MHZ how long is a clock cycle? If a clock runs at 1.2GHZ how long is clock cycle?
Cycles Per Instruction Different Instructions may take different numbers of clock cycles to execute. CPI (Cycles Per Instruction) refers to number of clock cycles an instruction takes in a design What is average CPI of the following 600 MHZ machine? What is the MIPS rating? Instruction ClassCPIFreq Load Word831% Store Word721% ALU (R format)641% Branch55% Jump22%
PCSPIM A software simulator for the MIPS32 architecture. Load assembly file. Run in the software.
.text.globl main main: move $t6, $0 move $t7, $0 loop: addu $t7, $t7, $t6 addu $t6, $t6, 1 ble $t6, 100, loop li $v0, 4 la $a0, str syscall li $v0, 1 move $a0, $t7 syscall.data str:.asciiz "The sum from is "