Please help with this MIPS Assembly Langauge Program Write a

Please help with this MIPS Assembly Langauge Program.

Write a program which, given two nonnegative integers x and y, computes the value of x*y. You must accomplish this task using the branching, comparison, shifting and addition in particular, you may not employ the use of functions. Don\'t implement the multiplication problem as a loop that adds the number x to itself y times. You must implement the problem using shifting and addition. You are also not permitted to use mult, mul, or similar instructions. Prompt the user for the two integers, each in turn. If the user enters a negative number, remind them that they must provide a nonnegative integer, and ask again. Here are some sample executions: x*y calculator Please enter x: 5 Please enter y: 5*7 = 35 x*y calculator Please enter x: theta Please enter y: 4 theta*4 = theta x*y calculator Please enter x: 6 Please enter y: theta 6*theta = theta x*y calculator Please enter x: -3 Integer must be nonnegative. Please enter x: 2 Please enter y: -4 Integer must be nonnegative. Please enter y: 2 theta 2*2 theta = 4 theta To implement multiply in terms of adding and shifting, you need to decompose one of the numbers by powers of 2, for example: 7 * 5 = 111_2 * 101_2 = 111_2 * (1 * 2^2 + 0 * 2^1 + 1 * 2^0) = 111_2 * 2^+ 111_2 * 2^2 = 111_2

Solution

.data msgXY: .asciiz \"x*y calculator\ \" msg1: .asciiz \"Please enter x: \" msg2: .asciiz \"Please enter y: \" multiply: .asciiz \"*\" equalSign: .asciiz \" = \" error: .asciiz \"Integer must be nonnegative.\ \" .text addi $v0, $zero, 4 #syscall 4: print string la $a0, msgXY #store string in $a0 syscall #print string LoopX: addi $v0, $zero, 4 la $a0, msg1 syscall addi $v0, $zero, 5 #syscall 5: read integer syscall #read integer srl $v1, $v0, 31 and $v1, $v1, 1 bne $v1, 1, NotNegativeX #if integer entered is negative, go to the loop addi $v0, $zero, 4 la $a0, error syscall j LoopX NotNegativeX: add $t0, $zero, $v0 #store integer A in $t0 add $t6, $zero, $t0 #make copy of A into $t6 LoopY: addi $v0, $zero, 4 la $a0, msg2 syscall addi $v0, $zero, 5 #syscall 5: read integer syscall #read integer srl $v1, $v0, 31 and $v1, $v1, 1 bne $v1, 1, NotNegativeY #if integer entered is negative, go to the loop addi $v0, $zero, 4 la $a0, error syscall j LoopY NotNegativeY: add $t1, $zero, $v0 #store integer B in $t1 add $t7, $zero, $t1 #make copy of B add $t2, $zero, $zero #set shifting counter to zero, store in $t2 add $t3, $zero, $zero #set result to zero, store in $t3 bne $t1, $zero, increment #go to loop if B != 0 increment: beq $t1, $zero, leaveLoop #leave loop if B == 0 andi $a1, $t1, 1 #check first bit in B beq $a1, 1, ifOne #if first bit == 1, then go to ifOne bne $a1, 1, notOne j increment notOne: addi $t2, $t2, 1 #shifting counter++ srl $t1, $t1, 1 #shift B to right one time j increment ifOne: sllv $t4, $t0, $t2 #shift A left by shifting counter, put it in register $t4 add $t3, $t3, $t4 #Result = Result + (A << shiftin counter) addi $t2, $t2, 1 #shifting counter++ srl $t1, $t1, 1 #shift B to right one time j increment leaveLoop: addi $v0, $zero, 1 #syscall 1: print integer add $a0, $zero, $t6 #set integer A to be printed syscall #print integer addi $v0, $zero, 4 la $a0, multiply syscall addi $v0, $zero, 1 #syscall 1: print integer add $a0, $zero, $t7 #set integer B to be printed syscall #print integer addi $v0, $zero, 4 la $a0, equalSign syscall addi $v0, $zero, 1 add $a0, $zero, $t3 syscall
Please help with this MIPS Assembly Langauge Program. Write a program which, given two nonnegative integers x and y, computes the value of x*y. You must accompl

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site