Download Lab_1

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Elementary arithmetic wikipedia , lookup

Elementary mathematics wikipedia , lookup

Addition wikipedia , lookup

Approximations of π wikipedia , lookup

Location arithmetic wikipedia , lookup

Arithmetic wikipedia , lookup

Positional notation wikipedia , lookup

Transcript
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 10000 RPM?
Prob 1.51
• Cost per wafer: $6000
• 1 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 =
(3x103) + (2x102) + (7x101) + (1x100)
The following 8 slides are from UCB CS61C
Numbers: positional notation
• Number Base B  B symbols per digit:
–Base 10 (Decimal):
Base 2 (Binary):
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
0, 1
• Number representation:
–d31d30 ... d1d0 is a 32 digit number
–value = d31  B31 + d30  B30 + ... + d1  B1 + d0  B0
• Binary:
0,1 (In binary digits called “bits”)
–0b11010 = 124 + 123 + 022 + 121 + 020
= 16 + 8 + 2
#s often written = 26
0b… –Here 5 digit binary # turns into a 2 digit decimal #
–Can we find a base that converts to binary easily?
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:
–1010 1100 0011 (binary) = 0x_____ ?
Decimal vs. Hexadecimal vs. Binary
00
01
02
03
04
05
06
07
08
09
10
11
How do we convert between hex and 12
Decimal?
13
14
15
Examples:
1010 1100 0011 (binary)
= 0xAC3
10111 (binary)
= 0001 0111 (binary)
= 0x17
0x3F9
= 11 1111 1001 (binary)
MEMORIZE!
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
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:
32ten == 3210 == 0x20 == 1000002 == 0b100000
– Use subscripts “ten”, “hex”, “two” in book, slides
when might be confusing
BIG IDEA: Bits can represent anything!!
• Characters?
– 26 letters  5 bits (25 = 32)
– upper/lower case + punctuation
 7 bits (in 8) (“ASCII”)
– standard code to cover all the world’s languages 
8,16,32 bits (“Unicode”)
www.unicode.com
• Logical values?
– 0  False, 1  True
• colors ? Ex:
Red (100) Green (010)
Blue (001)
• locations / addresses? commands?
• MEMORIZE: N bits  at most 2N things
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. +1ten would be:
0000 0000 0000 0000 0000 0000 0000 0001
• And - 1ten in sign and magnitude would be:
1000 0000 0000 0000 0000 0000 0000 0001
Shortcomings of sign and magnitude?
• Arithmetic circuit complicated
– Special steps depending whether signs are the
same or not
• Also, two zeros
– 0x00000000 = +0ten
– 0x80000000 = -0ten
– 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
– 000000...xxx is ≥ 0, 111111...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
00000 00001
11111
11110
00010
-1 0 1
11101
2
-2
-3
11100
-4
.
.
.
.
.
.
• 2N-1 nonnegatives
• 2N-1 negatives
• one zero
• how many
positives?
-15 -16 15
10001 10000 01111
00000
10000 ... 11110 11111
00001 ...
01111
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 0s) 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
00000000 00000000 00000100 00000001
Address
Big-Endian
representation
of 1025
Little-Endian
representation of
1025
00
01
02
03
00000000
00000000
00000100
00000001
00000001
00000100
00000000
00000000
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.
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, 0x40044005
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 Class
CPI
Freq
Load Word
8
31%
Store Word
7
21%
ALU (R format)
6
41%
Branch
5
5%
Jump
2
2%
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 0 .. 100 is "