Advertisement
Guest User

Untitled

a guest
May 31st, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. .text
  2. li $t0, 2147483647 $t0= 0111…111
  3. li $t1, 4 $t1= 000… 0100
  4. li $t2, -127 $t2= 111… 10000001
  5. addu $t3, $t0, $t1 $t3=100… 011 = -2^31 + 2+1
  6. add $a0, $t0,$t1 $a0= overflow in 2’s compliment . Two positives
  7. generated a negative.
  8. sra $t4, $t2, 2 $t4= 111… 100000 = -32
  9. sra inserts the sign $t2 bits which is one.
  10.  
  11. srl $t5, $t2, 2 $t5= 0011… 100000 = 2^29 + 2^28+…+2^5
  12.  
  13. sll $t6, $t0, 1 $t6= 111… 10 = -2
  14. srl and sll insert zeros
  15.  
  16. xor $t7, $t1, $t2 $t7= 11… 10000101 = -127 + 2^2
  17. Because the only difference from -127 is
  18. having one in the position 2^2
  19. rol $s1, $t2, 1 $s1= 111…100000011 = -127 + 2 - 128
  20. rotate to left Compare it with the binary
  21. representation of -127 It adds one to the right but
  22. remove one at location 27
  23.  
  24. mul $s2, $t1, $t2 $s2= 4*-127 = -508
  25.  
  26. mulo $t7, $t0, $t1 $t7= (2^31 -1)*4 will be more than 32bits so
  27. overflow will be generated because the
  28. operation is mulo
  29. divu $s3, $t2, $t1 $s3= 2^29+2^28+…+2^5
  30. $t2 as an unsigned integer = 2^31+2^30+…+2^7+2^0 dividing by 2^2 = 2^29+2^28+…+2^5 with the remainder 2^0 = 1
  31. div $s4, $t0, $t1 $s4 = 2^28 + 2^27 + 2^26 + ……..+ 1
  32. Remainder= 3
  33.  
  34.  
  35.  
  36. and $s5, $t1, $t2 $s5 = 0
  37.  
  38.  
  39. addi $s6, $t2, -4 $s6 = -131
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. 2. Determine the final contents in decimal of all registers used in the following program.
  48. li $t1, 1073741824 #it is 2^30 $t1 = 0100 0000 0000 0000 0000 0000 0000 0000 = 2^30
  49. li $t2, -1073741824 $t2 = 1100 0000 0000 0000 0000 0000 0000 0000 = -2^30
  50. li $t3, 16 $t3 = 0000 0000 0000 0000 0000 0000 0001 0000 = 16
  51. li $t4, 1073741824 $t4 = 2^30
  52. rem $t5, $t1, $t3 $t5 = 0
  53. addu $t6, $t1, $t4 $t6 = -2,147483648 = -2^31( addu does not generate overflow)
  54. sra $t7, $t1, 1 $t7 = 0010 0000 000 0000 0000 0000 0000 0000 = 2^29
  55. sra $s0, $t2, 2 $s0 = 1111 0000 0000 0000 00000 0000 0000 0000 = -2^28 Why?
  56. srl $s1, $t1, 2 $s1 = 0001 0000 0000 0000 0000 0000 0000 0000 = 2^28
  57. sll $s2, $t2, 2 $s2 = 0000 0000 0000 0000 0000 0000 0000 0000 = 0
  58. ror $s3, $t2, 2 $s3 = 0011 0000 0000 0000 0000 0000 0000 0000 = 2^29 + 2^28
  59. rol $s4, $t1, 1 $s4 = 1000 0000 0000 0000 0000 0000 0000 0000 = -2^31
  60. add $s5, $t1, $t4 $s5 = overflow exception
  61. xor $s6, $t1, $t3 $s6 = 0100 0000 0000 0000 0000 0000 0001 0000 = 2^30 + 2^4
  62. seq $s7, $t1, $t4 $s7 = 1
  63. sgt $a0, $t1, $t3 $a0 = 1
  64. move $a1, $t2 $a1 = -1073741824
  65. 3. Determine the contents in decimal of the registers indicated below after executing the following program. Assume the contents of registers $t0, $t1, and $t2 represent integers in two’s compliment representation.
  66. .text
  67. li $t0, 2 $t0 = 0000 0000 0000 0000 0000 0000 0000 0010 = 2
  68. li $t1, -2 $t1 = 1111 1111 1111 1111 1111 1111 1111 1110 = -2
  69. li $t2, -256 $t2 = 1111 1111 1111 1111 1111 1111 0000 0000 = -256
  70. addu $t3, $t0, $t1 $t3 = 0
  71. sra $t4, $t1, 2 $t4 = 1111 1111 1111 1111 1111 1111 1111 1111 = -1
  72. srl $t5, $t1, 2 $t5 = 0011 1111 1111 1111 1111 1111 1111 1111 = 2^29 + 2^28+ … +2^0
  73. sll $t6, $t0, 30 $t6 = 1000 0000 0000 0000 0000 0000 0000 0000 = -2^31
  74. xor $t7, $t1, $t0 $t7 = 1111 1111 1111 1111 1111 1111 1111 1100 = -4
  75. rol $s1, $t1, 1 $s1 = $s1 = 1111 1111 1111 1111 1111 1111 1111 1101 = -3
  76. mul $s2, $t1, $t2 $s2 = 512
  77. div $s3, $t2, $t1 $s3 = 128
  78. mult $t0, $t2
  79. mfhi $s4 $s4 = 1111 1111 1111 1111 1111 1111 1111 1111 1111 = -1
  80. div $t2, $t0
  81. mfhi $s5 $s5 = 0
  82. mflo $s6 $s6 = -128
  83. addi $s7, $t2, 4 $s7 = -252
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement