100 likes | 333 Views
1. Integer to ASCII string. For example, if $a0 = 0000002A, which is 101010 two =42 ten , then $a1 = 00003234 addi $t0, $zero, 10 div $a0, $t0 # $a0/10 mflo $a1 # $a1 = quotient addi $a1, $a1, 0x30 # convert to ASCII mfhi $t0 # $t0 = remainder
E N D
1. Integer to ASCII string For example, if $a0 = 0000002A, which is 101010two=42ten, then $a1 = 00003234 addi $t0, $zero, 10 div $a0, $t0 # $a0/10 mflo $a1 # $a1 = quotient addi $a1, $a1, 0x30 # convert to ASCII mfhi $t0 # $t0 = remainder addi $t0, $t0, 0x30 # convert to ASCII sll $t0, $t0, 8 or $a1, $a1, $t0
2. Integer Division See 3.27 solution
3. MIPS Instruction addi $a1, $zero, 32 loop: addi $a1, $a1, -4 lw $a0, 8($a1) beq $a1, $zero, exit j loop exit 70000000 70000004 70000008 7000000C 70000010 70000014
4. Floating-Point (0.3)oct=3/8 • 110000000010 1100 0000 0000 0000 0000 • 1*8513-511*0.011=64*(1/4+1/8)=24 • Smallest number > 8-512*2-22 >10-600 • Why no hidden bit? • For base 2, we can always normalize to 1.M*2e. For example, (0.1)two = (1.0)two*21, (0.01)two= (1.0)two*22, (0.001)two = (1.0)two*23 • For base 8, it is not always possible to normalize to 1.M*8e. For example, (0.1)two=(0.1)two*80=(100.0)two*8, (0.01)two=(0.01)two*80=(10.0)two*81 • For any base other than 2, there can not be any hidden bit.
5. Questions • Booths algorithm: • See 00, 11 do nothing • See 01, addition • See 10, subtraction • Best if 11111111111…, 1 add, 1 sub • Worst if 101010101…, 16 add, 16 sub
Speedup • 2 hours from CLL to AUS • 4 hours from AUS to LAX, 1200 miles • Total 6 hours • Speedup 2, meaning 3 hours • Alternative answer (assume perm between AUS and LAX) • 1 hour from AUS to LAX => 1200/hour • Total 4 hours • 2 hours from AUS to LAX => 600/hour
b) MIPS • Convert beq $a0, 0x1234abcd, exit • Answer: • lui $at, 0x1234 • ori $at, $at, 0xabcd • beq $a0, $at, exit
e) Floating-Point Associative • Operation ? is associative if a?(b?c) = (a?b)?c • For example, + and * is associate • What about division? 3/(4/5)=(3/4)/5? No! • FP addition: a+(b+c)=(a+b)+c? 10^1000+(-10^1000+1)=0 (10^1000-10^1000)+1=1
Example: Avoid FP error • To compute the average age for all people in USA • Method 1: • Add age of all people into total • Compute total/295,000,000 • Method 2: • Compute average age for each group of 1,000 people • Compute the average of every 1,000 groups • Compute the average of the 295 averages • Which method produces more accurate result?