0

how can I convert this kind of code block to MIPS?

gap = (int)(gap / 1.3);

djot
  • 2,952
  • 4
  • 19
  • 28
Mustafa
  • 592
  • 8
  • 17
  • See the instruction set reference: http://vhouten.home.xs4all.nl/mipsel/r3000-isa.html and http://www.doc.ic.ac.uk/lab/secondyear/spim/node20.html – Michael Mar 27 '13 at 16:27

1 Answers1

1

first load 1.3 to a f reg. ref: MIPS (or SPIM): Loading floating point numbers

.data

number: .double 1.3

.text

l.s $f2, number

now load f1 to (double)gap

mtc1 $a0, $f1
cvt.d.w $f1, $f1

then set $f3 = (double)(gap / 1.3)

div.d $f3, $f1, $f2

now convert it to int

cvt.w.d $f3, $f3    
mfc1 $s2, $f3

thats all

Community
  • 1
  • 1
Mustafa
  • 592
  • 8
  • 17
  • I think you meant to say `.d` in every place where you have `.s`. The former means `double` and the latter means `float`, or single precision. – markgz Mar 29 '13 at 18:25
  • @markgz yeah you're right. forgot to update this post after realizing – Mustafa Mar 29 '13 at 21:43