程序代写代做代考 mips 6016h4

6016h4

Spring 2016 March 29, 2016

1

CS2630:
 Computer
 Organization
 
Homework
 4
 
Total
 points
 =
 50
 

Due
 April
 5,
 2016,
 11:59
 PM
 

 

1.
 Do
 not
 consult
 others.
 You
 must
 solve
 the
 problems
 on
 your
 own.
 

2.
 Be
 generous
 about
 using
 comments
 to
 improve
 readability.
 Always
 include
 a
 comment
 at
 

the
 beginning
 specifying
 the
 purpose
 of
 the
 program.
 

3.
 To
 submit
 the
 program,
 zip
 (or
 tar)
 them
 into
 a
 single
 file
 that
 has
 your
 last
 name
 as
 the
 

prefix.
 Use
 ICON
 drop
 box
 to
 submit
 your
 assignment.
 
 

 

 

Question
 1.
 (5+5
 =
 10
 points)
 

A,
 B
 are
 two
 floating-­‐point
 numbers.
 Their
 representations
 in
 the
 IEEE
 754
 single
 

precision
 floating-­‐point
 format
 (that
 uses
 a
 biased
 exponent)
 are
 as
 follows:
 

  A=
 0xC0A0
 0000,
  B=
 0x3EB0
 0000
 
  [Representation
 in
 hex]
 

(a)
 Compute
 the
 decimal
 equivalents
 of
 these
 two
 numbers.
 Show
 the
 steps.
 
 

(b)
 Represent
 P
 =
 A
 X
 B
 in
 the
 IEEE
 floating
 point
 format,
 and
 write
 it
 down
 in
 hex.
 

Show
 the
 steps
 

 

 

 

Question
 2.
 
 Create
 an
 exponent
 function:
 float
 exp
 (float
 x)
 that
 accepts
 an
 input
 x
 

from
  the
 user,
  and
  returns
  ex,
  (using
  the
 MIPS
  floating
 point
  co-­‐processor).
 Recall
 

that
  e
  =
  2.71828183…
  Use
  Taylor
  Series
  expansion
  to
  compute
  the
  exponential
 

function:
 

 

 
 
 
  ex !1+ x +
x2

2!
+
x3

3!
+ … +

x9

9!
+
x10

10!

 

 

(It
 is
 an
 infinite
 series,
 but
 you
 can
 stop
 after
 computing
 up
 to
 the
 10th
 power
 of
 x)
 

 

Spring 2016 March 29, 2016

2

Part
 1.
 (10+10
 =
 20
 points)
 To
 facilitate
 this,
 create
 two
 functions:
 
 

 

(1)
 float
 power
 (float
 x,
 int
 n)
 and
 
 

(2)
 int
 factorial
 (int
 n).
 
 

 

Here,
 power
 (x,
 n)
 will
 return
 xn
 and
 factorial
 n
 will
 return
 n!
 You
 may
 assume
 0
 ≤
 

x
 ≤10
 and
 0
 ≤
 n
 ≤10,
 so
 that
 overflow
 will
 never
 be
 an
 issue
 either
 with
 the
 single
 

precision
  floating
  point
  format
  or
  the
  32-­‐bit
  integer
  format.
 
  For
  computing
  the
 

factorial,
 write
 a
 simple
 iterative
 program,
 don’t
 use
 the
 recursive
 version.
 

 

Part
 2
 (20
 points)
 Use
 the
 two
 functions
 as
 subroutines
 (i.e.
 create
 two
 subroutines
 

using
 your
 solution
 in
 Part
 1)
 to
 compute
 ex
 from
 a
 value
 of
 x
 within
 the
 given
 range.
 

The
  user
  should
  type
  in
  an
  input
  value
  of
  x,
  and
  your
  program
 will
  generate
  the
 

value
 of
 ex.
 
 Print
 the
 values
 of
 e,
 e2,
 and
 e3.
 

 
 
 
 
 
 
 
 
 A
 helpful
 MIPS
  instruction
  is
 cvt.s.w
 fd
 fs
  that
  converts
 an
  integer
  in
  the
 

source
 register
 fs
  into
 a
 single
 precision
 floating
 format
  in
 the
 destination
 register
 

fd.
 Here
 is
 an
 example
 of
 its
 usage:
 

 
mtc1
 $v0,
 $f1
 
 
 
 
 
 
 
 #
 move
 to
 register
 $f1
 (in
 coprocessor
 C1)
 from
 register
 $v0
 
 

cvt.s.w
 $f1,$f1
 
 
 
 #
 convert
 the
 integer
 in
 $f1
 to
 single
 precision
 floating
 point
 format
 

div.s
 $f0,$f0,$f1
 
 #
 divide
 $f0
 by
 $f1
 and
 store
 the
 result
 in
 $f0
 

 

A
 summary
 of
 some
 useful
 floating-­‐point
 instructions
 is
 available
 in
 Appendix
 A
 of
 

your
 textbook.
 
 A
 sample
 program
 dealing
 with
 floating
 point
 numbers
 is
 given
 in
 

the
 next
 page.
 

 

Spring 2016 March 29, 2016

3

Appendix
 

 

Here
 is
 a
 program
 that
 computes
 the
 polynomial
 ax2
 +
 bx
 +
 c
 

 
## float1.s — compute ax^2 + bx + c for user-input x
.text
.globl main
##
# Register Use Chart
# $f0 — x
# $f2 — sum of terms

main: # read input
la $a0,prompt # prompt user for x
li $v0,4 # print string
syscall
li $v0,6 # read single
syscall # $f0 <-- x # evaluate the quadratic l.s $f2,a # sum = a mul.s $f2,$f2,$f0 # sum = ax l.s $f4,b # get b add.s $f2,$f2,$f4 # sum = ax + b mul.s $f2,$f2,$f0 # sum = (ax+b)x = ax^2 +bx l.s $f4,c # get c add.s $f2,$f2,$f4 # sum = ax^2 + bx + c # print the result mov.s $f12,$f2 # $f12 = argument li $v0,2 # print single syscall la $a0,newl # new line li $v0,4 # print string syscall li $v0,10 # code 10 == exit syscall # end the program ## Data Segment ## .data a: .float 1.0 b: .float 1.0 c: .float 1.0 prompt: .asciiz "Enter x: " blank: .asciiz " " newl: .asciiz " "

Posted in Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *