Assembly floating point

Reply

Join Date: May 2008
Posts: 1
Reputation: serendipity. is an unknown quantity at this point 
Solved Threads: 0
serendipity. serendipity. is offline Offline
Newbie Poster

Assembly floating point

 
0
  #1
May 23rd, 2008
Hey there!

I had to write a programme for MIPS/SPIM, which reads floating point numbers and returns them bit by bit at the shell. So this is, what I managed to write:

  1. .data
  2. var1: .float 0.00
  3. var2: .float 2.0
  4. var3: .float -0.123
  5. txt2: .asciiz "\n"
  6.  
  7. .text
  8.  
  9. main:
  10. addi $sp, $sp, -20 # decrement stack pointer
  11. l.s $f0, var3 # load var3 in $f0
  12. s.s $f0, 20($sp) # push $f0 on stack
  13. addi $sp, $sp, -20 # decrement stack pointer
  14. l.s $f1, var2 # load var2 in $f1
  15. s.s $f1, 20($sp) # push $f1 on stack
  16. addi $sp, $sp, -20 # decrement stack pointer
  17. l.s $f2, var1 # load var1 in $f2
  18. s.s $f2, 20($sp) # push $f2 on stack
  19.  
  20.  
  21. li $t3, 3 # $t3 = 3: number of floats
  22.  
  23. for1:
  24. sub $t3, $t3, 1 # decrement $t3
  25. l.s $f0, 4($sp) # load first byte from stack in $f0
  26. addi $sp, $sp, 4 # increment stack pointer
  27. li $t7, 1 # preparation: $t7 = 1
  28. li $t6, 0 # preparation: $t6 = 0
  29. li $t0, 1 # preparation: $t0 = 1
  30. mfc1 $t2, $f0 # move from coprocessor: $t2 = $f0
  31.  
  32. for2:
  33. and $t1, $t2, $t0 # logical and: $t1 = $t2 AND $t0
  34. sll $t0, $t0, 1 # shift left logical: $t0 = $t0 * 2^1
  35. bne $zero, $t1, case_1 # if $t1 /= 0 branch to case_1
  36. addi $sp, -4 # decrement stack pointer
  37. sw $zero, 4($sp) # push $zero (=0) on stack
  38. b go_on # branch to go_on
  39.  
  40. case_1:
  41. addi $sp, -4 # decrement stack pointer
  42. sw $t7, 4($sp) # push $t7 (=1) on stack
  43.  
  44. go_on:
  45. addi $t6, $t6, 1 # increment $t6
  46. bne $zero, $t0, for2 # if $t0 /= 0 branch to for2
  47.  
  48. li $v0, 1 # print_int
  49.  
  50. for3:
  51. lw $a0, 4($sp) # load in $a0 value from stack on address 4($sp)
  52. addi $sp, 4 # increment stack pointer
  53. syscall # print
  54. sub $t6, $t6, 1 # decrement $t6
  55. bne $zero, $t6, for3 # if $t6 /= 0 branch to for3
  56. li $v0, 4 # print_string
  57. la $a0, txt2 # load in $a0 address txt2
  58. syscall # print "\n"
  59.  
  60. bne $zero, $t3, for1 # if $t3 /= 0 branch to for1
  61.  
  62. li $v0, 10 # exit
  63. syscall

It works, but somehow I've got the impression, that it always returns the same numbers (even if I've changed the floating point numbers in the .data-section).
I've got no idea, where the problem could be... Maybe someones got a hint for me?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC