Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .text
- li $t0, 2147483647 $t0= 0111…111
- li $t1, 4 $t1= 000… 0100
- li $t2, -127 $t2= 111… 10000001
- addu $t3, $t0, $t1 $t3=100… 011 = -2^31 + 2+1
- add $a0, $t0,$t1 $a0= overflow in 2’s compliment . Two positives
- generated a negative.
- sra $t4, $t2, 2 $t4= 111… 100000 = -32
- sra inserts the sign $t2 bits which is one.
- srl $t5, $t2, 2 $t5= 0011… 100000 = 2^29 + 2^28+…+2^5
- sll $t6, $t0, 1 $t6= 111… 10 = -2
- srl and sll insert zeros
- xor $t7, $t1, $t2 $t7= 11… 10000101 = -127 + 2^2
- Because the only difference from -127 is
- having one in the position 2^2
- rol $s1, $t2, 1 $s1= 111…100000011 = -127 + 2 - 128
- rotate to left Compare it with the binary
- representation of -127 It adds one to the right but
- remove one at location 27
- mul $s2, $t1, $t2 $s2= 4*-127 = -508
- mulo $t7, $t0, $t1 $t7= (2^31 -1)*4 will be more than 32bits so
- overflow will be generated because the
- operation is mulo
- divu $s3, $t2, $t1 $s3= 2^29+2^28+…+2^5
- $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
- div $s4, $t0, $t1 $s4 = 2^28 + 2^27 + 2^26 + ……..+ 1
- Remainder= 3
- and $s5, $t1, $t2 $s5 = 0
- addi $s6, $t2, -4 $s6 = -131
- 2. Determine the final contents in decimal of all registers used in the following program.
- li $t1, 1073741824 #it is 2^30 $t1 = 0100 0000 0000 0000 0000 0000 0000 0000 = 2^30
- li $t2, -1073741824 $t2 = 1100 0000 0000 0000 0000 0000 0000 0000 = -2^30
- li $t3, 16 $t3 = 0000 0000 0000 0000 0000 0000 0001 0000 = 16
- li $t4, 1073741824 $t4 = 2^30
- rem $t5, $t1, $t3 $t5 = 0
- addu $t6, $t1, $t4 $t6 = -2,147483648 = -2^31( addu does not generate overflow)
- sra $t7, $t1, 1 $t7 = 0010 0000 000 0000 0000 0000 0000 0000 = 2^29
- sra $s0, $t2, 2 $s0 = 1111 0000 0000 0000 00000 0000 0000 0000 = -2^28 Why?
- srl $s1, $t1, 2 $s1 = 0001 0000 0000 0000 0000 0000 0000 0000 = 2^28
- sll $s2, $t2, 2 $s2 = 0000 0000 0000 0000 0000 0000 0000 0000 = 0
- ror $s3, $t2, 2 $s3 = 0011 0000 0000 0000 0000 0000 0000 0000 = 2^29 + 2^28
- rol $s4, $t1, 1 $s4 = 1000 0000 0000 0000 0000 0000 0000 0000 = -2^31
- add $s5, $t1, $t4 $s5 = overflow exception
- xor $s6, $t1, $t3 $s6 = 0100 0000 0000 0000 0000 0000 0001 0000 = 2^30 + 2^4
- seq $s7, $t1, $t4 $s7 = 1
- sgt $a0, $t1, $t3 $a0 = 1
- move $a1, $t2 $a1 = -1073741824
- 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.
- .text
- li $t0, 2 $t0 = 0000 0000 0000 0000 0000 0000 0000 0010 = 2
- li $t1, -2 $t1 = 1111 1111 1111 1111 1111 1111 1111 1110 = -2
- li $t2, -256 $t2 = 1111 1111 1111 1111 1111 1111 0000 0000 = -256
- addu $t3, $t0, $t1 $t3 = 0
- sra $t4, $t1, 2 $t4 = 1111 1111 1111 1111 1111 1111 1111 1111 = -1
- srl $t5, $t1, 2 $t5 = 0011 1111 1111 1111 1111 1111 1111 1111 = 2^29 + 2^28+ … +2^0
- sll $t6, $t0, 30 $t6 = 1000 0000 0000 0000 0000 0000 0000 0000 = -2^31
- xor $t7, $t1, $t0 $t7 = 1111 1111 1111 1111 1111 1111 1111 1100 = -4
- rol $s1, $t1, 1 $s1 = $s1 = 1111 1111 1111 1111 1111 1111 1111 1101 = -3
- mul $s2, $t1, $t2 $s2 = 512
- div $s3, $t2, $t1 $s3 = 128
- mult $t0, $t2
- mfhi $s4 $s4 = 1111 1111 1111 1111 1111 1111 1111 1111 1111 = -1
- div $t2, $t0
- mfhi $s5 $s5 = 0
- mflo $s6 $s6 = -128
- addi $s7, $t2, 4 $s7 = -252
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement