1. Integer to ASCII string - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

1. Integer to ASCII string

Description:

1. Integer to ASCII string – PowerPoint PPT presentation

Number of Views:72
Avg rating:3.0/5.0
Slides: 10
Provided by: Weipi2
Category:
Tags: ascii | ascii | integer | string

less

Transcript and Presenter's Notes

Title: 1. Integer to ASCII string


1
1. Integer to ASCII string
  • For example, if a0 0000002A, which is
    101010two42ten, 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
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

70000000 70000004 70000008 7000000C 70000010 70000
014
4
4. Floating-Point
(0.3)oct3/8
  • 1100 0000 0010 1100 0000 0000 0000 0000
  • ?18513-5110.011?64(1/41/8)?24
  • Smallest number gt 8-5122-22 gt10-600
  • Why no hidden bit?
  • For base 2, we can always normalize to 1.M2e.
    For example, (0.1)two (1.0)two2?1, (0.01)two
    (1.0)two2?2, (0.001)two (1.0)two2?3
  • For base 8, it is not always possible to
    normalize to 1.M8e. For example,
    (0.1)two(0.1)two80(100.0)two8,
    (0.01)two(0.01)two80(10.0)two8?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 11111111111, 1 add, 1 sub
  • Worst if 101010101, 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 gt 1200/hour
  • Total 4 hours
  • 2 hours from AUS to LAX gt 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(bc)(ab)c?
  • 101000(-1010001)0
  • (101000-101000)11

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?
Write a Comment
User Comments (0)
About PowerShow.com