Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add $s2, $s1, $s1 # $s1 = y , $s2 = 2y
- j loop # test whether $s1 & $s0 is overflow or not
- mul $s3, $s2, $s2 # (2y)^2
- jal loop2
- mul $s4, $s3, $s2 # (2y)^3
- jal loop2
- add $s5, $s0, $s1 # x + y
- jal loop # test whether $s5 is overflow or not
- mul $s6, $s5, $s5 # (x+y)^2
- jal loop2
- mul $s7, $s6, $s5 # (x+y)^3
- jal loop2
- add $s7, $s7, $s4 # (x+y)^3 + (2y)^3
- jal loop # test whether $s7 is overflow or not
- move $a0, $s7
- loop:
- slti $t0, $s1, 0 # examine the sign of x
- slti $t1, $s2, 0 # examine the sign of y
- xor $t0, $t0, $t1 # examine whether signs differ
- bne $s2, $zero, no_overflow # $s0 & $s1 signs not equal, so no
- overflow
- Continue:
- slti $t0, $s5, 0
- slti $t1, $s7, 0 # signs = sign of sum match
- xor $t0, $t1, $t0 # $t0 negative if sum sign different
- bne $t0, $zero, overflow # All 3 signs r not same, so goto overflow
- loop2:
- mult $s0, $s2, $s3 # multiply numbers stored in the .
- registers
- mfhi $t0 # load upper 32 bits from register
- mflo $t1 # load lower 32 bits from register
- beq $t0, $0, no_overflow # if $t0 = 0, then load no overflow
- beq $t1, $0, no_overflow # if $t1 = 0, then load no overflow
- no_overflow:
- j Continue # return original address
- overflow:
- la $a0, error_msg
- li $v0, 4
- syscall
- j exit
Add Comment
Please, Sign In to add comment