Presentation is loading. Please wait.

Presentation is loading. Please wait.

1. Integer to ASCII string

Similar presentations


Presentation on theme: "1. Integer to ASCII string"— Presentation transcript:

1 1. Integer to ASCII string
For example, if $a0 = A, which is two=42ten, then $a1 = 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 2. Integer Division See 3.27 solution

3 3. MIPS Instruction addi $a1, $zero, 32 loop: addi $a1, $a1, -4
lw $a0, 8($a1) beq $a1, $zero, exit j loop exit C 001000 00000 00101 100011 00100 000100 000010

4 4. Floating-Point (0.3)oct=3/8 1100 0000 0010 1100 0000 0000 0000 0000
1* *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*21, (0.01)two= (1.0)two*22, (0.001)two = (1.0)two*23 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*81 For any base other than 2, there can not be any hidden bit.

5 5. Questions Booths algorithm: See 00, 11 do nothing See 01, addition
See 10, subtraction Best if …, 1 add, 1 sub Worst if …, 16 add, 16 sub

6 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

7 b) MIPS Convert beq $a0, 0x1234abcd, exit Answer: lui $at, 0x1234
ori $at, $at, 0xabcd beq $a0, $at, exit

8 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)+1=1

9 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?


Download ppt "1. Integer to ASCII string"

Similar presentations


Ads by Google