Question

In: Computer Science

using MIPs assembly, ask the user to enter two numbers. Then multiply the two numbers using...

using MIPs assembly, ask the user to enter two numbers. Then multiply the two numbers using bit shifting (not 'mul'). This should work multiplying 2 positive numbers, 2 negative numbers, and a positive/negative number.

Then output the result and ask user if he/she has more calculations to complete.

Solutions

Expert Solution

product.asm:

.data
textout:.asciiz "please enter 2 numbers \n"
textout1:.asciiz "please enter 1st number: "
textout2:.asciiz "please enter 2nd number: "
textout3:.asciiz "The product of the numbers is: "
.text
main:
   li $s2,0 #result initialized too zero
  
   la $a0 textout #print prompt string
   li $v0 4
   syscall
  
   la $a0 textout1 #print prompt string
   li $v0 4
   syscall
  
   li $v0 5
   syscall
   move $s0,$v0
  
   la $a0 textout2 #print prompt string
   li $v0 4
   syscall
  
   li $v0 5
   syscall
   move $s1,$v0
  
   bltz $s0,a   #check if 1st number is negative if negative jump to a
   bltz $s1,b   #check if 2nd number is negative if negative jump to b
   j multiply

a:   bltz $s1,both #check if 2nd number is negative if both are negative jump to both
   li $t0,1   #flag = 1
   sub $s0,$zero,$s0 # make the 1st number positive
   j multiply
b: li $t0,1   #flag = 1
   sub $s1,$zero,$s1 # make the 2nd number positive
   j multiply

both:   li $t0,2   #if both numbers are negative
   sub $s0,$zero,$s0 # make the 1st number positive
   sub $s1,$zero,$s1 # make the 2nd number positive
   j multiply
  
multiply: beqz $s1,res
   andi $t1,$s1,1
   beqz $t1,add_s
   add $s2,$s2,$s0
add_s:   sll $s0,$s0,1
   srl $s1,$s1,1
   j multiply
  
res:   beq $t0,1,neg #if flag = 1 make result negative
   j end
neg:   sub $s2,$zero,$s2
   j end
  
end:   la $a0 textout3
   li $v0 4
   syscall
  
   move $a0,$s2   #print result
   li $v0,1
   syscall  
  
  
Output:


Related Solutions

in MIPS assembly, ask a user for two numbers and to either enter a '1' for...
in MIPS assembly, ask a user for two numbers and to either enter a '1' for addition or '2' for subtraction. using jal, jump to the appropriate procedure for additing or subtracting. then print out result and ask if there is another calculation (terminate program if 'no').
Write a MIPS program that will ask the user to enter two numbers at the console...
Write a MIPS program that will ask the user to enter two numbers at the console and pass the values to a function that does multiplication
Write a mips assembly language program to ask the user to enter two integers A and...
Write a mips assembly language program to ask the user to enter two integers A and B and then display the result of computing the expression: A + 2B - 5.
Write a mips assembly code program that ask the user to enter an integer value, and...
Write a mips assembly code program that ask the user to enter an integer value, and then print the result of doubling that number.
This is to be done using MIPS assembly language. Display the following menus, ask user to...
This is to be done using MIPS assembly language. Display the following menus, ask user to select one item. If 1-3 is selected, display message “item x is selected”, (x is the number of a menu item), display menus again; if 0 is selected, quit from the program. 1. Menu item 1 2. Menu item 2 3. Menu item 3 0. Quit Please select from above menu (1-3) to execute one function. Select 0 to quit
MIPS Assembly program: Accept N numbers from the user and sort the N numbers using any...
MIPS Assembly program: Accept N numbers from the user and sort the N numbers using any sorting algorithm. Print both the sorted array and unsorted array. N should be greater than or equal to 10.
Write a mips assembly language program that asks the user to enter an unsigned number and...
Write a mips assembly language program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6.
I need to ask a user what numbers they want to enter. They can enter as...
I need to ask a user what numbers they want to enter. They can enter as many as they like. Then inside I need to use conditionals to determine if the numbers are <=20, <=323 && > 30, >200. I can't figure out how to let the user enter as many inputs as they want. I know I need to use a loop to check each number entered and determine if it is small middle or greater but I can't...
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user toinput an...
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user to input an integer and then prints out a string that shows how that integer should be encoded using 16 bits. Your program should handle both positive and negative valued inputs. Your program should also print out an error message if the given input cannot be expressed as a 16 bit signed integer.As an example, if the input is 12, your program should output “0000000000001100”. If the input...
Write a mips assembly language program that asks the user to enter an alphabetic character (either...
Write a mips assembly language program that asks the user to enter an alphabetic character (either lower or upper case)and change the case of the character from lower to upper and from upper to lower and display it.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT