Guest User

Untitled

a guest
Nov 18th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. add $s2, $s1, $s1 # $s1 = y , $s2 = 2y
  2. j loop # test whether $s1 & $s0 is overflow or not
  3.  
  4. mul $s3, $s2, $s2 # (2y)^2
  5. jal loop2
  6.  
  7. mul $s4, $s3, $s2 # (2y)^3
  8. jal loop2
  9.  
  10. add $s5, $s0, $s1 # x + y
  11. jal loop # test whether $s5 is overflow or not
  12.  
  13. mul $s6, $s5, $s5 # (x+y)^2
  14. jal loop2
  15.  
  16. mul $s7, $s6, $s5 # (x+y)^3
  17. jal loop2
  18.  
  19. add $s7, $s7, $s4 # (x+y)^3 + (2y)^3
  20. jal loop # test whether $s7 is overflow or not
  21.  
  22. move $a0, $s7
  23.  
  24. loop:
  25.  
  26. slti $t0, $s1, 0 # examine the sign of x
  27. slti $t1, $s2, 0 # examine the sign of y
  28. xor $t0, $t0, $t1 # examine whether signs differ
  29. bne $s2, $zero, no_overflow # $s0 & $s1 signs not equal, so no
  30. overflow
  31.  
  32. Continue:
  33.  
  34. slti $t0, $s5, 0
  35. slti $t1, $s7, 0 # signs = sign of sum match
  36. xor $t0, $t1, $t0 # $t0 negative if sum sign different
  37. bne $t0, $zero, overflow # All 3 signs r not same, so goto overflow
  38.  
  39.  
  40. loop2:
  41. mult $s0, $s2, $s3 # multiply numbers stored in the .
  42. registers
  43. mfhi $t0 # load upper 32 bits from register
  44. mflo $t1 # load lower 32 bits from register
  45. beq $t0, $0, no_overflow # if $t0 = 0, then load no overflow
  46. beq $t1, $0, no_overflow # if $t1 = 0, then load no overflow
  47.  
  48.  
  49. no_overflow:
  50.  
  51. j Continue # return original address
  52.  
  53.  
  54. overflow:
  55.  
  56. la $a0, error_msg
  57. li $v0, 4
  58. syscall
  59. j exit
Add Comment
Please, Sign In to add comment